funga-eth

Ethereum implementation of the funga keystore and signer
Log | Files | Refs | README | LICENSE

commit 45c7538528ec11e79a9f05440803ee284cad2f2e
parent e5cd1cad58fb2d9e39f37817843ad7f2fc5004d3
Author: williamluke <williamluke4@gmail.com>
Date:   Tue,  1 Mar 2022 10:43:24 +0000

feat: add message signer cli, pbkdf2 support, -0 flag (#3)

Reviewed-on: https://git.grassecon.net/chaintool/funga-eth/pulls/3

Diffstat:
MCHANGELOG | 5+++++
Mfunga/eth/runnable/keyfile.py | 7+++++--
Afunga/eth/runnable/msg.py | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mrequirements.txt | 6+++---
Msetup.py | 5+++--
5 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,8 @@ +* 0.5.4 + - 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/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 @@ -0,0 +1,54 @@ +# 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('-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() + +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) + + r = sig.hex() + if not args.nonl: + r += "\n" + sys.stdout.write(r) + + +if __name__ == '__main__': + main() diff --git 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 @@ -33,7 +33,7 @@ f.close() setup( name="funga-eth", - version="0.5.3", + version="0.5.6", description="Ethereum implementation of the funga keystore and signer", author="Louis Holbrook", author_email="dev@holbrook.no", @@ -55,8 +55,9 @@ 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', + url='https://git.grassecon.net/chaintool/funga-eth', include_package_data=True, )