Add readme, changelog...
This commit is contained in:
@@ -1 +1 @@
|
||||
from keystore.postgres import ReferenceDatabase
|
||||
from keystore.postgres import ReferenceKeystore
|
||||
|
||||
@@ -10,6 +10,7 @@ from eth_keys.backends import NativeECCBackend
|
||||
import sha3
|
||||
|
||||
from common import strip_hex_prefix
|
||||
from keystore.interface import Keystore
|
||||
|
||||
keyapi = KeyAPI(NativeECCBackend)
|
||||
|
||||
@@ -21,10 +22,24 @@ logg = logging.getLogger(__file__)
|
||||
def to_bytes(x):
|
||||
return x.encode('utf-8')
|
||||
|
||||
|
||||
class ReferenceDatabase:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ReferenceKeystore(Keystore):
|
||||
|
||||
schema = [
|
||||
"""CREATE TABLE ethereum (
|
||||
id SERIAL NOT NULL PRIMARY KEY,
|
||||
key_ciphertext VARCHAR(256) NOT NULL,
|
||||
wallet_address_hex CHAR(40) NOT NULL
|
||||
);
|
||||
""",
|
||||
"""CREATE UNIQUE INDEX ethereum_address_idx ON ethereum ( wallet_address_hex );
|
||||
""",
|
||||
]
|
||||
|
||||
def __init__(self, dbname, **kwargs):
|
||||
self.conn = psycopg2.connect('dbname=' + dbname)
|
||||
self.cur = self.conn.cursor()
|
||||
@@ -32,8 +47,9 @@ class ReferenceDatabase:
|
||||
|
||||
|
||||
def get(self, address, password=None):
|
||||
safe_address = strip_hex_prefix(address)
|
||||
s = sql.SQL('SELECT key_ciphertext FROM ethereum WHERE wallet_address_hex = %s')
|
||||
self.cur.execute(s, [ address ] )
|
||||
self.cur.execute(s, [ safe_address ] )
|
||||
k = self.cur.fetchone()[0]
|
||||
return self._decrypt(k, password)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class Signer:
|
||||
self.keyGetter = keyGetter
|
||||
|
||||
|
||||
def signTransaction(self, tx):
|
||||
def signTransaction(self, tx, password=None):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class ReferenceSigner(Signer):
|
||||
h = sha3.keccak_256()
|
||||
h.update(s)
|
||||
g = h.digest()
|
||||
k = keys.PrivateKey(self.keyGetter(tx.sender, password))
|
||||
k = keys.PrivateKey(self.keyGetter.get(tx.sender, password))
|
||||
z = keys.ecdsa_sign(message_hash=g, private_key=k)
|
||||
tx.v = (tx.v * 2) + 35 + z[64]
|
||||
tx.r = z[:32]
|
||||
|
||||
@@ -8,6 +8,15 @@ from common import strip_hex_prefix
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
class Transaction:
|
||||
|
||||
def rlp_serialize(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def serialize(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class EIP155Transaction:
|
||||
|
||||
def __init__(self, tx, nonce, chainId=1):
|
||||
|
||||
@@ -21,8 +30,8 @@ class Transaction:
|
||||
self.value = int(tx['value'])
|
||||
self.data = data
|
||||
self.v = chainId
|
||||
self.r = 0
|
||||
self.s = 0
|
||||
self.r = b''
|
||||
self.s = b''
|
||||
self.sender = strip_hex_prefix(tx['from'])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user