Add sign msg method

This commit is contained in:
nolash 2020-12-19 08:47:21 +01:00
parent e4efc53b31
commit 793c1d9367
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 45 additions and 4 deletions

View File

@ -1,3 +1,7 @@
* 0.4.6
- Add sign message
* 0.4.5
- Upgrade dependencies
* 0.4.4 * 0.4.4
- Upgrade dependencies - Upgrade dependencies
* 0.4.3 * 0.4.3

View File

@ -38,3 +38,12 @@ class ReferenceSigner(Signer):
tx.r = z[:32] tx.r = z[:32]
tx.s = z[32:64] tx.s = z[32:64]
return z return z
def signEthereumMessage(self, address, message, password=None):
#msg = b'\x19Ethereum Signed Message:\n{}{}'.format(len(message), message)
k = keys.PrivateKey(self.keyGetter.get(address, password))
#z = keys.ecdsa_sign(message_hash=g, private_key=k)
z = k.sign_msg(message.encode('utf-8'))
return z

View File

@ -50,6 +50,7 @@ class PlatformMiddleware:
return params return params
# TODO: DRY
def __call__(self, method, suspect_params): def __call__(self, method, suspect_params):
self.id_seq += 1 self.id_seq += 1
@ -76,12 +77,11 @@ class PlatformMiddleware:
#return str(json.dumps(jr)) #return str(json.dumps(jr))
return jr return jr
# TODO: DRY
elif method == 'eth_signTransaction': elif method == 'eth_signTransaction':
params = PlatformMiddleware._translate_params(suspect_params) params = PlatformMiddleware._translate_params(suspect_params)
s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0) s = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_STREAM, proto=0)
ipc_provider_workaround = s.connect(self.ipcaddr) ipc_provider_workaround = s.connect(self.ipcaddr)
logg.info('redirecting methodd {} params {} original params {}'.format(method, params, suspect_params)) logg.info('redirecting method {} params {} original params {}'.format(method, params, suspect_params))
o = jsonrpc_request(method, params[0]) o = jsonrpc_request(method, params[0])
j = json.dumps(o) j = json.dumps(o)
logg.debug('send {}'.format(j)) logg.debug('send {}'.format(j))
@ -94,6 +94,23 @@ class PlatformMiddleware:
#return str(json.dumps(jr)) #return str(json.dumps(jr))
return jr return jr
elif method == 'eth_sign':
params = PlatformMiddleware._translate_params(suspect_params)
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])
j = json.dumps(o)
logg.debug('send {}'.format(j))
s.send(j.encode('utf-8'))
r = s.recv(4096)
s.close()
logg.debug('got recv {}'.format(str(r)))
jr = json.loads(r)
jr['id'] = self.id_seq
return jr
r = self.make_request(method, suspect_params) r = self.make_request(method, suspect_params)
return r return r

View File

@ -118,9 +118,15 @@ methods = {
'personal_newAccount': personal_new_account, 'personal_newAccount': personal_new_account,
'personal_signTransaction': personal_sign_transaction, 'personal_signTransaction': personal_sign_transaction,
'eth_signTransaction': eth_signTransaction, 'eth_signTransaction': eth_signTransaction,
'eth_sign': eth_sign,
} }
def eth_sign(address, message):
logg.debug('got message {} to sign'.format(p[0]))
return signer.signEthereumMessage(address, message)
def jsonrpc_error(rpc_id, err): def jsonrpc_error(rpc_id, err):
return { return {
'json-rpc': '2.0', 'json-rpc': '2.0',

View File

@ -5,5 +5,5 @@ eth-keys==0.3.3
pysha3==1.0.2 pysha3==1.0.2
rlp==2.0.0a1 rlp==2.0.0a1
json-rpc==1.13.0 json-rpc==1.13.0
confini==0.3.3 confini==0.3.4
sqlalchemy==1.3.20 sqlalchemy==1.3.20

View File

@ -24,7 +24,7 @@ f.close()
setup( setup(
name="crypto-dev-signer", name="crypto-dev-signer",
version="0.4.4", version="0.4.6",
description="A signer and keystore daemon and library for cryptocurrency software development", description="A signer and keystore daemon and library for cryptocurrency software development",
author="Louis Holbrook", author="Louis Holbrook",
author_email="dev@holbrook.no", author_email="dev@holbrook.no",

View File

@ -87,5 +87,10 @@ class TestSign(unittest.TestCase):
z = s.signTransaction(t) z = s.signTransaction(t)
def test_sign_message(self):
s = ReferenceSigner(self.pk_getter)
z = s.signEthereumMessage(tx_ints['from'], 'foo')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()