commit 8571447ce76d2fb15f7bfce2293eab12b83eac00 parent fe83a048ce394c30fbc35423200fb517b4cea62e Author: nolash <dev@holbrook.no> Date: Tue, 20 Jul 2021 17:46:19 +0200 Add private key bytes to private key converter, address default on keyfile decode Diffstat:
10 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/crypto_dev_signer/encoding.py b/crypto_dev_signer/encoding.py @@ -12,6 +12,10 @@ from hexathon import ( logg = logging.getLogger(__name__) +def private_key_from_bytes(b): + return coincurve.PrivateKey(secret=b) + + def public_key_bytes_to_address(pubk_bytes, result_format='hex'): h = sha3.keccak_256() logg.debug('public key bytes {}'.format(pubk_bytes.hex())) diff --git a/crypto_dev_signer/keystore/interface.py b/crypto_dev_signer/keystore/interface.py @@ -5,7 +5,7 @@ import logging # local imports from crypto_dev_signer.keystore import keyfile -import coincurve +from crypto_dev_signer.encoding import private_key_from_bytes logg = logging.getLogger(__name__) @@ -25,7 +25,7 @@ class Keystore: def import_raw_key(self, b, password=None): - pk = coincurve.PrivateKey(secret=b) + pk = private_key_from_bytes(b) return self.import_key(pk, password) diff --git a/crypto_dev_signer/runnable/keyfile.py b/crypto_dev_signer/runnable/keyfile.py @@ -15,13 +15,18 @@ from crypto_dev_signer.keystore.keyfile import ( from_file, to_dict, ) +from crypto_dev_signer.encoding import ( + private_key_to_address, + private_key_from_bytes, + ) logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() argparser = argparse.ArgumentParser() -argparser.add_argument('-d', type=str, help='decrypt file') +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('-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') @@ -31,8 +36,11 @@ if args.v: logg.setLevel(logging.DEBUG) mode = 'create' +secret = False if args.d: mode = 'decrypt' + if args.private_key: + secret = True pk_hex = os.environ.get('PRIVATE_KEY') if args.k != None: @@ -55,6 +63,9 @@ def main(): except AssertionError: sys.stderr.write('Invalid passphrase\n') sys.exit(1) + if not secret: + pk = private_key_from_bytes(bytes.fromhex(r)) + r = private_key_to_address(pk) elif mode == 'create': if passphrase == None: passphrase = getpass.getpass('encryption phrase: ') diff --git a/requirements.txt b/requirements.txt @@ -2,6 +2,7 @@ cryptography==3.2.1 pysha3==1.0.2 rlp==2.0.1 json-rpc==1.13.0 -confini~=0.3.6rc3 +confini>=0.3.6rc3,<0.5.0 coincurve==15.0.0 hexathon~=0.0.1a7 +pycryptodome==3.10.1 diff --git a/setup.py b/setup.py @@ -33,7 +33,7 @@ f.close() setup( name="crypto-dev-signer", - version="0.4.14b7", + version="0.4.14rc1", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no", diff --git a/test/testdata/UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72 b/test/testdata/UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72 @@ -1 +0,0 @@ -{"address":"00a329c0648769a73afac7f9381e08fb43dbea72","crypto":{"cipher":"aes-128-ctr","ciphertext":"e06ab0b0c96e9b4b1f04259ec49d6c8c865bf6363b38b030ab4852fa471269b4","cipherparams":{"iv":"36d3d7781750d12d3802cfe74aed4434"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"94e82d24c10e2af9987b926b5e1a36ce8d03595535a96359ca6648485872d5ba"},"mac":"6cac102b8d4c25203ea52505fea7e0d0b1a70929a1561e2143df88a6b45784da"},"id":"0225f31c-36da-4dd7-95d8-c463bba04387","version":3} -\ No newline at end of file diff --git a/test/test_helper.py b/tests/test_helper.py diff --git a/test/test_keystore_dict.py b/tests/test_keystore_dict.py diff --git a/test/test_keystore_reference.py b/tests/test_keystore_reference.py diff --git a/test/test_sign.py b/tests/test_sign.py