WIP add tx signer, rpc client option for cli signing

This commit is contained in:
lash 2022-03-08 12:09:48 +00:00
parent d9531c33cb
commit 9a995dbd2f
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 139 additions and 1 deletions

27
funga/eth/cli/client.py Normal file
View 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')

77
funga/eth/runnable/tx.py Normal file
View 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
View 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.

View File

@ -1,4 +1,4 @@
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