Use keyapi for address generation in import key in dictkeystore

This commit is contained in:
nolash
2021-01-09 20:25:47 +01:00
parent 0afacff6c6
commit e1e585776d
11 changed files with 93 additions and 7 deletions

View File

@@ -47,7 +47,7 @@ class ReferenceSigner(Signer):
z = None
if type(message).__name__ == 'str':
logg.debug('signing message in "str" format: {}'.format(message))
z = k.sign_msg(message.encode('utf-8'))
z = k.sign_msg(bytes.fromhex(message))
elif type(message).__name__ == 'bytes':
logg.debug('signing message in "bytes" format: {}'.format(message.hex()))
z = k.sign_msg(message)

View File

@@ -99,7 +99,7 @@ class PlatformMiddleware:
s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0)
ipc_provider_workaround = s.connect(self.ipcaddr)
logg.info('redirecting method {} params {} original params {}'.format(method, params, suspect_params))
o = jsonrpc_request(method, params[0], params[1])
o = jsonrpc_request(method, params)
j = json.dumps(o)
logg.debug('send {}'.format(j))
s.send(j.encode('utf-8'))

View File

@@ -5,3 +5,4 @@ from eth_keys.backends import NativeECCBackend
keyapi = KeyAPI(NativeECCBackend)
from .postgres import ReferenceKeystore
from .dict import DictKeystore

View File

@@ -1,6 +1,9 @@
# standard imports
import os
# third-party imports
import eth_keyfile
# local imports
from . import keyapi
@@ -25,6 +28,11 @@ class Keystore:
raise NotImplementedError
def insert_key(self, pk, password=None):
raise NotImplementedError
def import_keystore_data(self, keystore_content, password=''):
#private_key = w3.eth.account.decrypt(keystore_content, password)
private_key = eth_keyfile.decode_keyfile_json(keystore_content, password.encode('utf-8'))
return self.import_raw_key(private_key, password)
def import_keystore_file(self, keystore_file, password=''):
keystore_content = eth_keyfile.load_keyfile(keystore_file)
return self.import_keystore_data(keystore_content, password)

View File

@@ -120,7 +120,8 @@ def eth_sign(p):
message_type = type(p[1]).__name__
if message_type != 'str':
raise ValueError('invalid message format, must be {}, not {}'.format(message_type))
return signer.signEthereumMessage(p[0], p[1].encode('utf-8'))
z = signer.signEthereumMessage(p[0], p[1][2:])
return str(z)
methods = {