From 30c82b9cd1ea912ff872e699509a8fcac094405a Mon Sep 17 00:00:00 2001 From: lash Date: Mon, 24 Jan 2022 12:04:21 +0000 Subject: [PATCH 1/3] Add message signer cli --- CHANGELOG | 2 ++ funga/eth/runnable/msg.py | 49 +++++++++++++++++++++++++++++++++++++++ setup.py | 3 ++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 funga/eth/runnable/msg.py diff --git a/CHANGELOG b/CHANGELOG index ff8c227..efdc355 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* 0.5.4 + - Add message signer cli * 0.5.3 - Upgrade RLP to 3.0.0 (eliminates really annoying cytoolz warning on stdout) --- diff --git a/funga/eth/runnable/msg.py b/funga/eth/runnable/msg.py new file mode 100644 index 0000000..753bf2b --- /dev/null +++ b/funga/eth/runnable/msg.py @@ -0,0 +1,49 @@ +# standard imports +import os +import logging +import sys +import json +import argparse +import getpass + +# external impors +import coincurve +from hexathon import strip_0x + +# local imports +from funga.error import DecryptError +from funga.eth.keystore.dict import DictKeystore +from funga.eth.signer import EIP155Signer + + +logging.basicConfig(level=logging.WARNING) +logg = logging.getLogger() + +argparser = argparse.ArgumentParser() +argparser.add_argument('-f', type=str, help='Keyfile to use for signing') +argparser.add_argument('-z', action='store_true', help='zero-length password') +argparser.add_argument('-v', action='store_true', help='be verbose') +argparser.add_argument('msg', type=str, help='Message to sign') +args = argparser.parse_args() + +if args.v: + logg.setLevel(logging.DEBUG) + + +def main(): + passphrase = os.environ.get('WALLET_PASSPHRASE', os.environ.get('PASSPHRASE')) + if args.z: + passphrase = '' + if passphrase == None: + passphrase = getpass.getpass('decryption phrase: ') + + keystore = DictKeystore() + address = keystore.import_keystore_file(args.f, password=passphrase) + + signer = EIP155Signer(keystore) + sig = signer.sign_ethereum_message(address, args.msg.encode('utf-8').hex(), password=passphrase) + sys.stdout.write(sig.hex()) + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 6ca3ce9..cde1560 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ f.close() setup( name="funga-eth", - version="0.5.3", + version="0.5.4b1", description="Ethereum implementation of the funga keystore and signer", author="Louis Holbrook", author_email="dev@holbrook.no", @@ -55,6 +55,7 @@ setup( 'console_scripts': [ 'funga-ethd=funga.eth.runnable.signer:main', 'eth-keyfile=funga.eth.runnable.keyfile:main', + 'eth-sign-msg=funga.eth.runnable.msg:main', ], }, url='https://gitlab.com/chaintool/funga-eth', From c3033e9572fa8fbfe4220ecff448394ccab16b09 Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 25 Jan 2022 11:11:55 +0000 Subject: [PATCH 2/3] Add no-newline option for output --- CHANGELOG | 2 ++ funga/eth/runnable/keyfile.py | 7 +++++-- funga/eth/runnable/msg.py | 7 ++++++- setup.py | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index efdc355..88bf704 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ * 0.5.4 - Add message signer cli + - Add pbkdf2 support + - Add -0 flag for omitting newline on output * 0.5.3 - Upgrade RLP to 3.0.0 (eliminates really annoying cytoolz warning on stdout) --- diff --git a/funga/eth/runnable/keyfile.py b/funga/eth/runnable/keyfile.py index 738524e..467311b 100644 --- a/funga/eth/runnable/keyfile.py +++ b/funga/eth/runnable/keyfile.py @@ -30,6 +30,7 @@ logg = logging.getLogger() argparser = argparse.ArgumentParser() argparser.add_argument('-d', '--decrypt', dest='d', type=str, help='decrypt file') argparser.add_argument('--private-key', dest='private_key', action='store_true', help='output private key instead of address') +argparser.add_argument('-0', dest='nonl', action='store_true', help='no newline at end of output') argparser.add_argument('-z', action='store_true', help='zero-length password') argparser.add_argument('-k', type=str, help='load key from file') argparser.add_argument('-v', action='store_true', help='be verbose') @@ -79,10 +80,12 @@ def main(): else: pk_bytes = os.urandom(32) pk = coincurve.PrivateKey(secret=pk_bytes) - o = to_dict(pk_bytes, passphrase) + o = to_dict(pk_bytes, passphrase=passphrase) r = json.dumps(o) - print(r) + if not args.nonl: + r += "\n" + sys.stdout.write(r) if __name__ == '__main__': diff --git a/funga/eth/runnable/msg.py b/funga/eth/runnable/msg.py index 753bf2b..279a9be 100644 --- a/funga/eth/runnable/msg.py +++ b/funga/eth/runnable/msg.py @@ -23,6 +23,7 @@ argparser = argparse.ArgumentParser() argparser.add_argument('-f', type=str, help='Keyfile to use for signing') argparser.add_argument('-z', action='store_true', help='zero-length password') argparser.add_argument('-v', action='store_true', help='be verbose') +argparser.add_argument('-0', dest='nonl', action='store_true', help='no newline at end of output') argparser.add_argument('msg', type=str, help='Message to sign') args = argparser.parse_args() @@ -42,7 +43,11 @@ def main(): signer = EIP155Signer(keystore) sig = signer.sign_ethereum_message(address, args.msg.encode('utf-8').hex(), password=passphrase) - sys.stdout.write(sig.hex()) + + r = sig.hex() + if not args.nonl: + r += "\n" + sys.stdout.write(r) if __name__ == '__main__': diff --git a/setup.py b/setup.py index cde1560..695f3e8 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ f.close() setup( name="funga-eth", - version="0.5.4b1", + version="0.5.4b2", description="Ethereum implementation of the funga keystore and signer", author="Louis Holbrook", author_email="dev@holbrook.no", From 385578e58227b25108d2c9cea9efa58cc96c1986 Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 20 Feb 2022 16:40:55 +0000 Subject: [PATCH 3/3] Change url, revert rlp, update deps --- CHANGELOG | 1 + requirements.txt | 6 +++--- setup.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 88bf704..289faa6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Add message signer cli - Add pbkdf2 support - Add -0 flag for omitting newline on output + - Revert RLP to 2.0.1, to not break eth-tester in dependents * 0.5.3 - Upgrade RLP to 3.0.0 (eliminates really annoying cytoolz warning on stdout) --- diff --git a/requirements.txt b/requirements.txt index 9522511..a3088d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ cryptography==3.2.1 pysha3==1.0.2 -#rlp==2.0.1 -rlp==3.0.0 +rlp==2.0.1 +#rlp==3.0.0 json-rpc==1.13.0 confini~=0.5.1 coincurve==15.0.0 hexathon~=0.1.0 pycryptodome==3.10.1 -funga==0.5.1 +funga==0.5.2 diff --git a/setup.py b/setup.py index 695f3e8..f2f917d 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ f.close() setup( name="funga-eth", - version="0.5.4b2", + version="0.5.6", description="Ethereum implementation of the funga keystore and signer", author="Louis Holbrook", author_email="dev@holbrook.no", @@ -58,6 +58,6 @@ setup( 'eth-sign-msg=funga.eth.runnable.msg:main', ], }, - url='https://gitlab.com/chaintool/funga-eth', + url='https://git.grassecon.net/chaintool/funga-eth', include_package_data=True, )