funga/crypto_dev_signer/keystore/interface.py

39 lines
1.0 KiB
Python
Raw Normal View History

2020-09-21 19:10:20 +02:00
# standard imports
import os
# third-party imports
import eth_keyfile
2020-09-21 19:10:20 +02:00
# local imports
from . import keyapi
class Keystore:
def get(self, address, password=None):
raise NotImplementedError
2020-09-21 19:10:20 +02:00
def new(self, password=None):
2020-09-21 19:10:20 +02:00
b = os.urandom(32)
return self.import_raw_key(b, password)
def import_raw_key(self, b, password=None):
pk = keyapi.PrivateKey(b)
return self.import_key(pk, password)
2020-09-20 10:00:59 +02:00
def import_key(self, pk, password=None):
raise NotImplementedError
2020-09-21 19:10:20 +02:00
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)
2020-09-21 19:10:20 +02:00
def import_keystore_file(self, keystore_file, password=''):
keystore_content = eth_keyfile.load_keyfile(keystore_file)
return self.import_keystore_data(keystore_content, password)