Groups credential properties together

This commit is contained in:
Carl Beekhuizen 2020-07-21 10:25:33 +02:00
parent ef0ad43216
commit c6401c8e7b
No known key found for this signature in database
GPG Key ID: 8F29E54F49E7AAB5

View File

@ -51,21 +51,6 @@ class Credential:
withdrawal_credentials += SHA256(self.withdrawal_pk)[1:]
return withdrawal_credentials
def signing_keystore(self, password: str) -> Keystore:
secret = self.signing_sk.to_bytes(32, 'big')
return ScryptKeystore.encrypt(secret=secret, password=password, path=self.signing_key_path)
def save_signing_keystore(self, password: str, folder: str) -> str:
keystore = self.signing_keystore(password)
filefolder = os.path.join(folder, 'keystore-%s-%i.json' % (keystore.path.replace('/', '_'), time.time()))
keystore.save(filefolder)
return filefolder
def verify_keystore(self, keystore_filefolder: str, password: str) -> bool:
saved_keystore = Keystore.from_json(keystore_filefolder)
secret_bytes = saved_keystore.decrypt(password)
return self.signing_sk == int.from_bytes(secret_bytes, 'big')
@property
def deposit_message(self) -> DepositMessage:
return DepositMessage(
@ -93,6 +78,22 @@ class Credential:
datum_dict.update({'fork_version': self.fork_version})
return datum_dict
def signing_keystore(self, password: str) -> Keystore:
secret = self.signing_sk.to_bytes(32, 'big')
return ScryptKeystore.encrypt(secret=secret, password=password, path=self.signing_key_path)
def save_signing_keystore(self, password: str, folder: str) -> str:
keystore = self.signing_keystore(password)
filefolder = os.path.join(folder, 'keystore-%s-%i.json' % (keystore.path.replace('/', '_'), time.time()))
keystore.save(filefolder)
return filefolder
def verify_keystore(self, keystore_filefolder: str, password: str) -> bool:
saved_keystore = Keystore.from_json(keystore_filefolder)
secret_bytes = saved_keystore.decrypt(password)
return self.signing_sk == int.from_bytes(secret_bytes, 'big')
class CredentialList:
def __init__(self, credentials: List[Credential]):