Compare commits

..

10 Commits

Author SHA1 Message Date
lash
c402163f63 Merge branch 'dev-0.6.2' 2022-10-13 07:37:03 +00:00
lash
05435268bf
Allow binary msg sign in cli tool 2022-05-24 13:17:30 +00:00
lash
a534f8ca1e
Avoid padding of missing nibble in address 2022-05-04 18:09:01 +00:00
lash
d9531c33cb
Upgrade confini 2022-03-06 19:31:17 +00:00
45c7538528 feat: add message signer cli, pbkdf2 support, -0 flag (#3)
Reviewed-on: chaintool/funga-eth#3
2022-03-01 10:43:24 +00:00
lash
385578e582
Change url, revert rlp, update deps 2022-02-20 16:40:55 +00:00
lash
c3033e9572
Add no-newline option for output 2022-01-25 11:11:55 +00:00
lash
d50489f0ba Merge remote-tracking branch 'origin/master' into lash/message-signer 2022-01-25 09:02:00 +00:00
lash
e5cd1cad58
Implement PBKDF2 support in keyfile
---

Squashed commit of the following:

commit 4a4f76b19c
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 20:12:34 2022 +0300

    remove unused import and renaming pbkdf2 default params

commit 23a94c3ba1
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 20:07:22 2022 +0300

    defaulting to scrypt in to_dict fun

commit 1c0047398a
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 15:12:38 2022 +0300

    making final review  changes

commit 0a4f3eaa98
Merge: b208533 903f659
Author: Mohamed Sohail <kamikazechaser@noreply.localhost>
Date:   Mon Jan 24 11:10:35 2022 +0000

    Merge branch 'master' into Ida/pbkdf2

commit b20853312d
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 13:23:12 2022 +0300

    review changes with tests

commit b9c6db414b
Author: idaapayo <idaapayo@gmail.com>
Date:   Fri Jan 21 11:13:35 2022 +0300

    making review changes

commit 1f5d057a9a
Author: idaapayo <idaapayo@gmail.com>
Date:   Wed Jan 19 14:37:22 2022 +0300

    second pbkdf2 implementation

commit 01598a8c59
Author: idaapayo <idaapayo@gmail.com>
Date:   Wed Jan 19 13:49:29 2022 +0300

    pkdf2 implementation
2022-01-24 17:54:59 +00:00
lash
30c82b9cd1
Add message signer cli 2022-01-24 12:04:44 +00:00
6 changed files with 89 additions and 12 deletions

View File

@ -1,3 +1,14 @@
* 0.6.2
- Enable signing of binary message
* 0.6.1
- Avoid padding of addresses missing one nibble
* 0.6.0
- Upgrade confini
* 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 * 0.5.3
- Upgrade RLP to 3.0.0 (eliminates really annoying cytoolz warning on stdout) - Upgrade RLP to 3.0.0 (eliminates really annoying cytoolz warning on stdout)
--- ---

View File

@ -41,7 +41,7 @@ def private_key_to_address(pk, result_format='hex'):
def is_address(address_hex): def is_address(address_hex):
try: try:
address_hex = strip_0x(address_hex) address_hex = strip_0x(address_hex, pad=False)
except ValueError: except ValueError:
return False return False
return len(address_hex) == 40 return len(address_hex) == 40
@ -57,10 +57,10 @@ def is_checksum_address(address_hex):
def to_checksum_address(address_hex): def to_checksum_address(address_hex):
address_hex = strip_0x(address_hex) address_hex = strip_0x(address_hex, pad=False)
address_hex = uniform(address_hex)
if len(address_hex) != 40: if len(address_hex) != 40:
raise ValueError('Invalid address length') raise ValueError('Invalid address length')
address_hex = uniform(address_hex)
h = sha3.keccak_256() h = sha3.keccak_256()
h.update(address_hex.encode('utf-8')) h.update(address_hex.encode('utf-8'))
z = h.digest() z = h.digest()

View File

@ -30,6 +30,7 @@ logg = logging.getLogger()
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument('-d', '--decrypt', dest='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('--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('-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 key from file')
argparser.add_argument('-v', action='store_true', help='be verbose') argparser.add_argument('-v', action='store_true', help='be verbose')
@ -79,10 +80,12 @@ def main():
else: else:
pk_bytes = os.urandom(32) pk_bytes = os.urandom(32)
pk = coincurve.PrivateKey(secret=pk_bytes) pk = coincurve.PrivateKey(secret=pk_bytes)
o = to_dict(pk_bytes, passphrase) o = to_dict(pk_bytes, passphrase=passphrase)
r = json.dumps(o) r = json.dumps(o)
print(r) if not args.nonl:
r += "\n"
sys.stdout.write(r)
if __name__ == '__main__': if __name__ == '__main__':

62
funga/eth/runnable/msg.py Normal file
View File

@ -0,0 +1,62 @@
# 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('-b', '--binary', dest='binary', action='store_true', help='parse input as binary hex')
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)
msg = None
if args.binary:
hx = strip_0x(args.msg, pad=True)
msg = bytes.fromhex(hx)
else:
msg = args.msg.encode('utf-8').hex()
sig = signer.sign_ethereum_message(address, msg, password=passphrase)
r = sig.hex()
if not args.nonl:
r += "\n"
sys.stdout.write(r)
if __name__ == '__main__':
main()

View File

@ -1,10 +1,10 @@
cryptography==3.2.1 cryptography==3.2.1
pysha3==1.0.2 pysha3==1.0.2
#rlp==2.0.1 rlp==2.0.1
rlp==3.0.0 #rlp==3.0.0
json-rpc==1.13.0 json-rpc==1.13.0
confini~=0.5.1 confini~=0.6.0
coincurve==15.0.0 coincurve==15.0.0
hexathon~=0.1.0 hexathon~=0.1.6
pycryptodome==3.10.1 pycryptodome==3.10.1
funga==0.5.1 funga==0.5.2

View File

@ -33,7 +33,7 @@ f.close()
setup( setup(
name="funga-eth", name="funga-eth",
version="0.5.3", version="0.6.2",
description="Ethereum implementation of the funga keystore and signer", description="Ethereum implementation of the funga keystore and signer",
author="Louis Holbrook", author="Louis Holbrook",
author_email="dev@holbrook.no", author_email="dev@holbrook.no",
@ -55,8 +55,9 @@ setup(
'console_scripts': [ 'console_scripts': [
'funga-ethd=funga.eth.runnable.signer:main', 'funga-ethd=funga.eth.runnable.signer:main',
'eth-keyfile=funga.eth.runnable.keyfile: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, include_package_data=True,
) )