funga

Signer and keystore daemon and library for cryptocurrency software development
Log | Files | Refs | README | LICENSE

commit 793c1d9367dd205c07a116cd11a44de8ebca53b6
parent e4efc53b3128320120165ed05d06ebcdf6ec9902
Author: nolash <dev@holbrook.no>
Date:   Sat, 19 Dec 2020 08:47:21 +0100

Add sign msg method

Diffstat:
MCHANGELOG | 4++++
Mcrypto_dev_signer/eth/signer/defaultsigner.py | 9+++++++++
Mcrypto_dev_signer/eth/web3ext/middleware.py | 21+++++++++++++++++++--
Mcrypto_dev_signer/runnable/signer.py | 6++++++
Mrequirements.txt | 2+-
Msetup.py | 2+-
Mtest/test_sign.py | 5+++++
7 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,7 @@ +* 0.4.6 + - Add sign message +* 0.4.5 + - Upgrade dependencies * 0.4.4 - Upgrade dependencies * 0.4.3 diff --git a/crypto_dev_signer/eth/signer/defaultsigner.py b/crypto_dev_signer/eth/signer/defaultsigner.py @@ -38,3 +38,12 @@ class ReferenceSigner(Signer): tx.r = z[:32] tx.s = z[32:64] 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 + diff --git a/crypto_dev_signer/eth/web3ext/middleware.py b/crypto_dev_signer/eth/web3ext/middleware.py @@ -50,6 +50,7 @@ class PlatformMiddleware: return params + # TODO: DRY def __call__(self, method, suspect_params): self.id_seq += 1 @@ -76,12 +77,11 @@ class PlatformMiddleware: #return str(json.dumps(jr)) return jr - # TODO: DRY elif method == 'eth_signTransaction': 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 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]) j = json.dumps(o) logg.debug('send {}'.format(j)) @@ -94,6 +94,23 @@ class PlatformMiddleware: #return str(json.dumps(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) return r diff --git a/crypto_dev_signer/runnable/signer.py b/crypto_dev_signer/runnable/signer.py @@ -118,9 +118,15 @@ methods = { 'personal_newAccount': personal_new_account, 'personal_signTransaction': personal_sign_transaction, '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): return { 'json-rpc': '2.0', diff --git a/requirements.txt b/requirements.txt @@ -5,5 +5,5 @@ eth-keys==0.3.3 pysha3==1.0.2 rlp==2.0.0a1 json-rpc==1.13.0 -confini==0.3.3 +confini==0.3.4 sqlalchemy==1.3.20 diff --git a/setup.py b/setup.py @@ -24,7 +24,7 @@ f.close() setup( name="crypto-dev-signer", - version="0.4.4", + version="0.4.6", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no", diff --git a/test/test_sign.py b/test/test_sign.py @@ -87,5 +87,10 @@ class TestSign(unittest.TestCase): z = s.signTransaction(t) + def test_sign_message(self): + s = ReferenceSigner(self.pk_getter) + z = s.signEthereumMessage(tx_ints['from'], 'foo') + + if __name__ == '__main__': unittest.main()