Compare commits
1 Commits
master
...
lash/rpc-c
Author | SHA1 | Date | |
---|---|---|---|
|
9a995dbd2f |
@ -1,9 +1,3 @@
|
|||||||
* 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
|
* 0.5.4
|
||||||
- Add message signer cli
|
- Add message signer cli
|
||||||
- Add pbkdf2 support
|
- Add pbkdf2 support
|
||||||
|
27
funga/eth/cli/client.py
Normal file
27
funga/eth/cli/client.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# standard imports
|
||||||
|
import urllib.request
|
||||||
|
import json
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
import jsonrpc_std.interface
|
||||||
|
|
||||||
|
|
||||||
|
class RPCHTTPClient:
|
||||||
|
|
||||||
|
def __init__(self, host='localhost', port=8000):
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
|
self.url = 'http://{}:{}'.format(host, port)
|
||||||
|
|
||||||
|
|
||||||
|
def rpc_sign_tx(self, tx, request_id=None, passphrase=''):
|
||||||
|
data_src = jsonrpc_std.interface.jsonrpc_request('personal_signTransaction', request_id=request_id)
|
||||||
|
data_src['params'].append(tx)
|
||||||
|
data_src['params'].append(passphrase)
|
||||||
|
data = json.dumps(data_src)
|
||||||
|
req = urllib.request.Request(self.url, data=data.encode('utf-8'))
|
||||||
|
req.add_header('Accept', 'application/json')
|
||||||
|
req.add_header('Content-Type', 'application/json')
|
||||||
|
r = urllib.request.urlopen(req)
|
||||||
|
v = r.read()
|
||||||
|
return v.decode('utf-8')
|
@ -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, pad=False)
|
address_hex = strip_0x(address_hex)
|
||||||
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, pad=False)
|
address_hex = strip_0x(address_hex)
|
||||||
|
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()
|
||||||
|
@ -24,7 +24,6 @@ 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('-z', action='store_true', help='zero-length password')
|
||||||
argparser.add_argument('-v', action='store_true', help='be verbose')
|
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('-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')
|
argparser.add_argument('msg', type=str, help='Message to sign')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
@ -43,14 +42,7 @@ def main():
|
|||||||
address = keystore.import_keystore_file(args.f, password=passphrase)
|
address = keystore.import_keystore_file(args.f, password=passphrase)
|
||||||
|
|
||||||
signer = EIP155Signer(keystore)
|
signer = EIP155Signer(keystore)
|
||||||
|
sig = signer.sign_ethereum_message(address, args.msg.encode('utf-8').hex(), password=passphrase)
|
||||||
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()
|
r = sig.hex()
|
||||||
if not args.nonl:
|
if not args.nonl:
|
||||||
|
77
funga/eth/runnable/tx.py
Normal file
77
funga/eth/runnable/tx.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# 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
|
||||||
|
#from funga.eth.transaction import EIP155Transaction
|
||||||
|
from funga.eth.cli.client import RPCHTTPClient
|
||||||
|
|
||||||
|
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('-a', '--signer-address', dest='signer_address', type=str, help='Ethereum address of signer')
|
||||||
|
argparser.add_argument('-i', '--chain-id', dest='chain_id', type=int, default=1, help='Ethereum address of signer')
|
||||||
|
argparser.add_argument('--value', type=int, default=0, help='Gas token unit value of transaction')
|
||||||
|
argparser.add_argument('--nonce', type=int, default=0, help='Transaction nonce')
|
||||||
|
argparser.add_argument('--fee-price', dest='fee_price', default=1, type=int, help='Gas price')
|
||||||
|
argparser.add_argument('--fee-limit', dest='fee_limit', default=21000, type=int, help='Gas limit')
|
||||||
|
argparser.add_argument('recipient_address', type=str, help='Recipient of transaction')
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
if args.v:
|
||||||
|
logg.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
rpc_signer = RPCHTTPClient()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
tx = {
|
||||||
|
'from': args.signer_address,
|
||||||
|
'to': args.recipient_address,
|
||||||
|
'value': args.value,
|
||||||
|
'data': '0x',
|
||||||
|
'gasPrice': args.fee_price,
|
||||||
|
'gas': args.fee_limit,
|
||||||
|
'chainId': args.chain_id,
|
||||||
|
'nonce': args.nonce,
|
||||||
|
}
|
||||||
|
r = rpc_signer.rpc_sign_tx(tx)
|
||||||
|
|
||||||
|
#tx = EIP155Transaction(tx_src, tx_src['nonce'], tx_src['chainId'])
|
||||||
|
#print(tx)
|
||||||
|
|
||||||
|
#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()
|
34
man/eth-keyfile.1.groff
Normal file
34
man/eth-keyfile.1.groff
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
.TH eth-keyfile 1
|
||||||
|
.SH NAME
|
||||||
|
eth-keyfile /- Generate and parse Ethereum keyfiles
|
||||||
|
.SH SYNOPSIS
|
||||||
|
\fBeth-keyfile\fP [ -z ] [ -v ] [ -k \fIprivatekeyfile\fP ]
|
||||||
|
.P
|
||||||
|
\fBeth-keyfile\fP [ --private-key ] [ -z ] [ -v ] -d \fIkeyfile\fP
|
||||||
|
.SH DESCRIPTION
|
||||||
|
\fBeth-keyfile\fP lets you create and parse Ethereum keyfiles.
|
||||||
|
.SS OPTIONS
|
||||||
|
.TP
|
||||||
|
\fB-d \fIkeyfile\fP
|
||||||
|
Parse the given keyfile, outputting the Ethereum address.
|
||||||
|
.TP
|
||||||
|
\fB--private-key\fP
|
||||||
|
When parsing a keyfile, output the private key instead of the Ethereum address.
|
||||||
|
.TP
|
||||||
|
\fB-k \fIprivatekeyfile\fP\fP
|
||||||
|
When creating a keyfile, load private key from the filename given as argument.
|
||||||
|
.TP
|
||||||
|
\fB-v\fP
|
||||||
|
Turn on verbose logging.
|
||||||
|
.TP
|
||||||
|
\fB-z\fP
|
||||||
|
Do not use a passphrase.
|
||||||
|
.SS ENVIRONMENT VARIABLES
|
||||||
|
.TP
|
||||||
|
\fBPRIVATE_KEY\fP
|
||||||
|
Create a keyfile for the given private key.
|
||||||
|
.TP
|
||||||
|
\fBPASSPHRASE\fP
|
||||||
|
Create or parse a keyfile using the given passphrase.
|
||||||
|
.SS NOTES
|
||||||
|
The current implementation will only create and parse keyfiles encrypted with aes-128-ctr, and with the scrypt KDF.
|
@ -1,10 +1,10 @@
|
|||||||
cryptography==3.2.1
|
cryptography==3.3
|
||||||
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.6.0
|
confini~=0.6.0
|
||||||
coincurve==15.0.0
|
coincurve==15.0.0
|
||||||
hexathon~=0.1.6
|
hexathon~=0.1.5
|
||||||
pycryptodome==3.10.1
|
pycryptodome==3.10.1
|
||||||
funga==0.5.2
|
funga==0.5.2
|
||||||
|
2
setup.py
2
setup.py
@ -33,7 +33,7 @@ f.close()
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="funga-eth",
|
name="funga-eth",
|
||||||
version="0.6.2",
|
version="0.6.0",
|
||||||
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",
|
||||||
|
Loading…
Reference in New Issue
Block a user