From 51f076ba2aa51643df6efd4f19692dcc75f398c0 Mon Sep 17 00:00:00 2001 From: nolash Date: Sat, 8 Aug 2020 10:45:37 +0200 Subject: [PATCH] Add setup.py, rename server script --- scripts/crypto-dev-daemon | 1 + scripts/{server.py => crypto-dev-daemon.py} | 39 +++++++++++---------- setup.py | 14 ++++++++ src/keystore/postgres.py | 8 ++--- src/transaction.py | 4 +++ src/web3ext/middleware.py | 1 + 6 files changed, 43 insertions(+), 24 deletions(-) create mode 120000 scripts/crypto-dev-daemon rename scripts/{server.py => crypto-dev-daemon.py} (81%) mode change 100644 => 100755 create mode 100644 setup.py diff --git a/scripts/crypto-dev-daemon b/scripts/crypto-dev-daemon new file mode 120000 index 0000000..bb57e37 --- /dev/null +++ b/scripts/crypto-dev-daemon @@ -0,0 +1 @@ +scripts/crypto-dev-daemon.py \ No newline at end of file diff --git a/scripts/server.py b/scripts/crypto-dev-daemon.py old mode 100644 new mode 100755 similarity index 81% rename from scripts/server.py rename to scripts/crypto-dev-daemon.py index 10ac4cb..eae8590 --- a/scripts/server.py +++ b/scripts/crypto-dev-daemon.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + import socket import json import logging @@ -19,20 +21,24 @@ chainId = 8995 def personal_new_account(p): - if p.__class__.__name__ != 'list': - e = JSONRPCInvalidParams() - e.data = 'parameter must be list containing one string' - raise ValueError(e) - if len(p) != 1: - e = JSONRPCInvalidParams() - e.data = 'parameter must be list containing one string' - raise ValueError(e) - if p[0].__class__.__name__ != 'str': - e = JSONRPCInvalidParams() - e.data = 'parameter must be list containing one string' - raise ValueError(e) + password = p + if p.__class__.__name__ != 'str': + if p.__class__.__name__ != 'list': + e = JSONRPCInvalidParams() + e.data = 'parameter must be list containing one string' + raise ValueError(e) + logg.error('foo {}'.format(p)) + if len(p) != 1: + e = JSONRPCInvalidParams() + e.data = 'parameter must be list containing one string' + raise ValueError(e) + if p[0].__class__.__name__ != 'str': + e = JSONRPCInvalidParams() + e.data = 'parameter must be list containing one string' + raise ValueError(e) + password = p[0] - r = db.new(p[0]) + r = db.new(password) return r @@ -50,10 +56,7 @@ def personal_sign_transaction(p): # TODO: temporary workaround for platform, since personal_signTransaction is missing from web3.py def eth_signTransaction(tx): - password = tx['password'] - del tx['password'] - tx_signed = personal_sign_transaction([tx, password]) - return tx_signed + return personal_sign_transaction([tx, '']) methods = { @@ -89,9 +92,7 @@ def is_valid_json(j): def process_input(j): - rpc_id = j['id'] - m = j['method'] p = j['params'] return (rpc_id, methods[m](p)) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..39e0c52 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup + +setup( + name="crypto-dev-signer", + version="0.1.0", + description="A signer and keystore daemon and library for cryptocurrency software development", + author="Louis Holbrook", + author_email="dev@holbrook.no", + packages=['crypto-dev-signer'], + install_requires=['web3', 'psycopg2', 'cryptography', 'eth-keys', 'pysha3', 'rlp'], + scripts = [ + 'scripts/crypto-dev-daemon.py', + ], + ) diff --git a/src/keystore/postgres.py b/src/keystore/postgres.py index 2cc7ade..dc52513 100644 --- a/src/keystore/postgres.py +++ b/src/keystore/postgres.py @@ -1,7 +1,9 @@ +# standard imports import logging import base64 import os +# third-party imports from cryptography.fernet import Fernet import psycopg2 from psycopg2 import sql @@ -9,6 +11,7 @@ from eth_keys import KeyAPI from eth_keys.backends import NativeECCBackend import sha3 +# local imports from common import strip_hex_prefix from keystore.interface import Keystore @@ -18,15 +21,10 @@ logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger(__file__) - def to_bytes(x): return x.encode('utf-8') - - - - class ReferenceKeystore(Keystore): schema = [ diff --git a/src/transaction.py b/src/transaction.py index d975dd7..a6dccd7 100644 --- a/src/transaction.py +++ b/src/transaction.py @@ -1,12 +1,16 @@ +# standard imports import logging import binascii +# third-party imports from rlp import encode as rlp_encode +# local imports from common import strip_hex_prefix, add_hex_prefix logg = logging.getLogger(__name__) + class Transaction: def rlp_serialize(self): diff --git a/src/web3ext/middleware.py b/src/web3ext/middleware.py index 421f52c..a58f3e6 100644 --- a/src/web3ext/middleware.py +++ b/src/web3ext/middleware.py @@ -1,3 +1,4 @@ +# standard imports import logging import re import socket