diff --git a/lib/ucoinpy/documents/ucoinpy/key/__init__.py b/lib/ucoinpy/documents/ucoinpy/key/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..6318ea75765fc5d8963881f502429662f26da68f --- /dev/null +++ b/lib/ucoinpy/documents/ucoinpy/key/__init__.py @@ -0,0 +1,39 @@ +''' +Ucoin public and private keys + +@author: inso +''' + +import base58 +import base64 +import scrypt +from nacl.signing import SigningKey as NaclSigningKey +from nacl.encoding import Base64Encoder + + +SEED_LENGTH = 32 # Length of the key +crypto_sign_BYTES = 64 +SCRYPT_PARAMS = {'N': 4096, + 'r': 16, + 'p': 1 + } + + +class SigningKey(NaclSigningKey): + def __init__(self, password, salt): + seed = scrypt.hash(password, salt, + SCRYPT_PARAMS['N'], SCRYPT_PARAMS['r'], SCRYPT_PARAMS['p'], + SEED_LENGTH) + seedb64 = base64.b64encode(seed) + super().__init__(seedb64, Base64Encoder) + self.pubkey = self.verify_key.encode(encoder=Base58Encoder) + + +class Base58Encoder(object): + @staticmethod + def encode(data): + return base58.b58encode(data) + + @staticmethod + def decode(data): + return base58.b58decode(data) diff --git a/lib/ucoinpy/key/__init__.py b/lib/ucoinpy/key/__init__.py index d28d328fef2302e087fdadd983dc190abd3fe44a..6318ea75765fc5d8963881f502429662f26da68f 100644 --- a/lib/ucoinpy/key/__init__.py +++ b/lib/ucoinpy/key/__init__.py @@ -25,8 +25,8 @@ class SigningKey(NaclSigningKey): SCRYPT_PARAMS['N'], SCRYPT_PARAMS['r'], SCRYPT_PARAMS['p'], SEED_LENGTH) seedb64 = base64.b64encode(seed) - super.__init__(seedb64, Base64Encoder) - self.pubkey = Base58Encoder.encode(self.verify_key.key) + super().__init__(seedb64, Base64Encoder) + self.pubkey = self.verify_key.encode(encoder=Base58Encoder) class Base58Encoder(object):