commit 25c56eb8901479e58abd86c761016222dea7825f
parent 108a60b87c104fee3cfaf4d0177afd9bbaef6d2d
Author: lash <dev@holbrook.no>
Date: Fri, 16 Jun 2023 15:42:07 +0100
Enable public key output from keyfile cli decrypt
Diffstat:
5 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+* 0.7.3
+ - Enable public key as output from keyfile decrypt
* 0.7.2
- Replace pysha3 with safe-pysha3
* 0.7.1
diff --git a/funga/eth/encoding.py b/funga/eth/encoding.py
@@ -39,6 +39,14 @@ def private_key_to_address(pk, result_format='hex'):
return public_key_to_address(pubk, result_format)
+def private_key_to_public_key(pk, result_format='hex'):
+ pubk = coincurve.PublicKey.from_secret(pk.secret)
+ r = pubk.format(compressed=False)
+ if result_format=='hex':
+ r = r.hex()
+ return r
+
+
def is_address(address_hex):
try:
address_hex = strip_0x(address_hex, pad=False)
diff --git a/funga/eth/message.py b/funga/eth/message.py
@@ -10,7 +10,8 @@ logg = logging.getLogger(__name__)
def to_digest(data):
h = sha3.keccak_256()
h.update(data)
- return h.digest()
+ z = h.digest()
+ return z
# ERC191 - version 0x00
def to_validator_message(data, validator, digest=False):
@@ -20,6 +21,7 @@ def to_validator_message(data, validator, digest=False):
logg.debug('raw message data: ' + r.hex())
if digest:
r = to_digest(r)
+ logg.debug('sign validator message digest: {}'.format(r.hex()))
return r
@@ -31,6 +33,7 @@ def to_typed_message(data, domain, digest=False):
logg.debug('raw message data: ' + r.hex())
if digest:
r = to_digest(r)
+ logg.debug('sign typed message digest: {}'.format(r.hex()))
return r
@@ -41,7 +44,5 @@ def to_personal_message(data, digest=False):
logg.debug('raw message data: ' + r.hex())
if digest:
r = to_digest(r)
+ logg.debug('sign personal message digest: {}'.format(r.hex()))
return r
-
-
-
diff --git a/funga/eth/runnable/keyfile.py b/funga/eth/runnable/keyfile.py
@@ -21,6 +21,7 @@ from funga.eth.keystore.keyfile import (
from funga.eth.encoding import (
private_key_to_address,
+ private_key_to_public_key,
private_key_from_bytes,
)
@@ -34,7 +35,8 @@ argparser.add_argument('--private-key', dest='private_key', action='store_true',
argparser.add_argument('--passphrase-file', dest='passphrase_file', type=str, help='Keystore file to use for signing or 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('-k', type=str, help='load private key from file')
+argparser.add_argument('-p', '--public-key', dest='p', action='store_true', help='return public key instead of address')
argparser.add_argument('-v', action='store_true', help='be verbose')
args = argparser.parse_args()
@@ -82,7 +84,11 @@ def main():
sys.exit(1)
if not secret:
pk = private_key_from_bytes(bytes.fromhex(r))
- r = private_key_to_address(pk)
+ r = None
+ if args.p:
+ r = private_key_to_public_key(pk)
+ else:
+ r = private_key_to_address(pk)
elif mode == 'create':
if passphrase == None:
passphrase = getpass.getpass('encryption phrase: ')
diff --git a/setup.py b/setup.py
@@ -33,7 +33,7 @@ f.close()
setup(
name="funga-eth",
- version="0.7.2",
+ version="0.7.3",
description="Ethereum implementation of the funga keystore and signer",
author="Louis Holbrook",
author_email="dev@holbrook.no",