Implement external signer

This commit is contained in:
nolash
2021-01-10 22:03:26 +01:00
parent d1f2b2cbdc
commit 8f9834105d
17 changed files with 222 additions and 138 deletions

View File

@@ -1,3 +1,6 @@
- 0.1.0-unreleased
* Implement external signer
* Standardize cli arg flags
- 0.0.3
* Add viewer cli
- 0.0.2

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,9 @@ import logging
# third-party imports
import web3
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
from crypto_dev_signer.keystore import DictKeystore
from crypto_dev_signer.eth.helper import EthTxExecutor
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -26,33 +28,62 @@ data_dir = os.path.join(script_dir, '..', 'data')
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('-r', '--contract-address', dest='r', type=str, help='Address declaration contract address')
argparser.add_argument('-o', '--declarator-address', dest='o', type=str, help='Signing address for the declaration')
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Accounts declarator owner')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
argparser.add_argument('address', type=str, help='Ethereum address to add declaration to')
argparser.add_argument('declaration', type=str, help='SHA256 sum of endorsement data to add')
args = argparser.parse_args()
if args.v:
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
block_last = args.w
block_all = args.ww
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
chain_pair = args.i.split(':')
chain_id = int(chain_pair[1])
helper = EthTxExecutor(
w3,
signer_address,
signer,
chain_id,
block=args.ww,
)
def main():
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
f = open(os.path.join(args.abi_dir, 'AddressDeclarator.json'), 'r')
abi = json.load(f)
f.close()
w3.eth.defaultAccount = w3.eth.accounts[0]
if args.o != None:
w3.eth.defaultAccount = args.o
logg.debug('endorser address {}'.format(w3.eth.defaultAccount))
c = w3.eth.contract(abi=abi, address=args.r)
tx_hash = c.functions.addDeclaration(args.address, args.declaration).transact()
print(tx_hash.hex())
(tx_hash, rcpt) = helper.sign_and_send(
[
c.functions.addDeclaration(args.address, args.declaration).buildTransaction,
],
)
print(tx_hash)
if __name__ == '__main__':

View File

@@ -13,7 +13,9 @@ import logging
# third-party imports
import web3
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
from crypto_dev_signer.keystore import DictKeystore
from crypto_dev_signer.eth.helper import EthTxExecutor
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -26,18 +28,48 @@ data_dir = os.path.join(script_dir, '..', 'data')
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-o', '--owner', dest='o', type=str, help='Accounts declarator owner')
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Accounts declarator owner')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
argparser.add_argument('owner_description_digest', type=str, help='SHA256 of description metadata of contract deployer')
args = argparser.parse_args()
if args.v:
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
block_last = args.w
block_all = args.ww
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
chain_pair = args.i.split(':')
chain_id = int(chain_pair[1])
helper = EthTxExecutor(
w3,
signer_address,
signer,
chain_id,
block=args.ww,
)
def main():
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
f = open(os.path.join(args.abi_dir, 'AddressDeclarator.json'), 'r')
abi = json.load(f)
f.close()
@@ -46,15 +78,15 @@ def main():
bytecode = f.read()
f.close()
w3.eth.defaultAccount = w3.eth.accounts[0]
if args.o != None:
w3.eth.defaultAccount = args.o
logg.debug('owner address {}'.format(w3.eth.defaultAccount))
c = w3.eth.contract(abi=abi, bytecode=bytecode)
logg.info('digest {}'.format(args.owner_description_digest))
tx_hash = c.constructor(args.owner_description_digest).transact()
(tx_hash, rcpt) = helper.sign_and_send(
[
c.constructor(args.owner_description_digest).buildTransaction,
],
force_wait=True,
)
rcpt = w3.eth.getTransactionReceipt(tx_hash)
print(rcpt.contractAddress)

View File

@@ -14,7 +14,7 @@ import logging
# third-party imports
import web3
from crypto_dev_signer.keystore import DictKeystore
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -28,17 +28,23 @@ data_dir = os.path.join(script_dir, '..', 'data')
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-r', '--contract-address', dest='r', type=str, help='Address declaration contract address')
argparser.add_argument('-o', '--declarator-address', dest='o', type=str, help='Signing address for the declaration')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('-a', '-declarator-address', dest='a', type=str, help='Signing address for the declaration')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('--resolve', action='store_true', help='Attempt to resolve the hashes to actual content')
argparser.add_argument('--resolve-http', dest='resolve_http', type=str, help='Base url to look up content hashes')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
argparser.add_argument('address', type=str, help='Ethereum declaration address to look up')
args = argparser.parse_args()
if args.v:
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
def try_sha256(s):
r = urllib.request.urlopen(os.path.join(args.resolve_http, s.hex()))
@@ -47,22 +53,32 @@ def try_sha256(s):
def try_utf8(s):
return s.decode('utf-8')
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
def main():
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
f = open(os.path.join(args.abi_dir, 'AddressDeclarator.json'), 'r')
abi = json.load(f)
f.close()
w3.eth.defaultAccount = w3.eth.accounts[0]
if args.o != None:
w3.eth.defaultAccount = args.o
logg.debug('endorser address {}'.format(w3.eth.defaultAccount))
declarator_address = signer_address
if declarator_address == None:
declarator_address = args.a
if declarator_address == None:
sys.stderr.write('missing declarator address, specify -y or -a\n')
sys.exit(1)
logg.debug('declarator address {}'.format(declarator_address))
c = w3.eth.contract(abi=abi, address=args.r)
declarations = c.functions.declaration(w3.eth.defaultAccount, args.address).call()
declarations = c.functions.declaration(declarator_address, args.address).call()
for d in declarations:
if not args.resolve:

File diff suppressed because one or more lines are too long

View File

@@ -14,7 +14,9 @@ import hashlib
# third-party imports
import web3
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
from crypto_dev_signer.keystore import DictKeystore
from crypto_dev_signer.eth.helper import EthTxExecutor
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -27,19 +29,49 @@ data_dir = os.path.join(script_dir, '..', 'data')
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('-r', '--contract-address', dest='r', type=str, help='Token endorsement contract address')
argparser.add_argument('-o', '--owner-address', dest='o', type=str, help='Address to use to sign endorsement transaction')
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Accounts declarator owner')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
argparser.add_argument('address', type=str, help='Ethereum address to add declaration to')
args = argparser.parse_args()
if args.v:
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
block_last = args.w
block_all = args.ww
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
chain_pair = args.i.split(':')
chain_id = int(chain_pair[1])
helper = EthTxExecutor(
w3,
signer_address,
signer,
chain_id,
block=args.ww,
)
def main():
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
abi = json.load(f)
f.close()
@@ -51,11 +83,6 @@ def main():
t = w3.eth.contract(abi=erc20_abi, address=args.address)
token_symbol = t.functions.symbol().call()
w3.eth.defaultAccount = w3.eth.accounts[0]
if args.o != None:
w3.eth.defaultAccount = args.o
logg.debug('owner address {}'.format(w3.eth.defaultAccount))
c = w3.eth.contract(abi=abi, address=args.r)
h = hashlib.new('sha256')
@@ -63,8 +90,13 @@ def main():
z = h.digest()
logg.info('token symbol {} => {}'.format(token_symbol, z.hex()))
tx_hash = c.functions.register('0x' + z.hex(), args.address).transact()
print(tx_hash.hex())
(tx_hash, rcpt) = helper.sign_and_send(
[
c.functions.register('0x' + z.hex(), args.address).buildTransaction,
],
)
print(tx_hash)
if __name__ == '__main__':

View File

@@ -13,7 +13,9 @@ import logging
# third-party imports
import web3
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
from crypto_dev_signer.keystore import DictKeystore
from crypto_dev_signer.eth.helper import EthTxExecutor
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
@@ -26,17 +28,47 @@ data_dir = os.path.join(script_dir, '..', 'data')
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
argparser.add_argument('-o', '--owner', dest='o', type=str, help='Accounts declarator owner')
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Accounts declarator owner')
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
args = argparser.parse_args()
if args.v:
if args.vv:
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
block_last = args.w
block_all = args.ww
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
signer_address = keystore.import_keystore_file(args.y)
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
chain_pair = args.i.split(':')
chain_id = int(chain_pair[1])
helper = EthTxExecutor(
w3,
signer_address,
signer,
chain_id,
block=args.ww,
)
def main():
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
abi = json.load(f)
f.close()
@@ -45,16 +77,14 @@ def main():
bytecode = f.read()
f.close()
w3.eth.defaultAccount = w3.eth.accounts[0]
if args.o != None:
w3.eth.defaultAccount = args.o
logg.debug('owner address {}'.format(w3.eth.defaultAccount))
c = w3.eth.contract(abi=abi, bytecode=bytecode)
tx_hash = c.constructor().transact()
rcpt = w3.eth.getTransactionReceipt(tx_hash)
(tx_hash, rcpt) = helper.sign_and_send(
[
c.constructor().buildTransaction,
],
force_wait=True,
)
print(rcpt.contractAddress)

View File

@@ -1,6 +1,6 @@
[metadata]
name = eth-address-index
version = 0.0.3
version = 0.1.0a1
description = Signed metadata declarations for ethereum addresses
author = Louis Holbrook
author_email = dev@holbrook.no
@@ -30,6 +30,7 @@ packages =
eth_token_index.runnable
install_requires =
web3==5.12.2
crypto-dev-signer~=0.4.13b2
tests_require =
eth-tester==0.5.0b2
py-evm==0.3.0a20