Add private key bytes to private key converter, address default on keyfile decode

This commit is contained in:
nolash 2021-07-20 17:46:19 +02:00
parent fe83a048ce
commit 8571447ce7
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
10 changed files with 21 additions and 6 deletions

View File

@ -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()))

View File

@ -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)

View File

@ -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: ')

View File

@ -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

View File

@ -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",

View File

@ -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}