Skip to content
Snippets Groups Projects
Commit 4b17febf authored by inso's avatar inso
Browse files

Merge branch 'refactor' of https://github.com/ucoin-io/ucoin-python-api into dev

Conflicts:
	lib/ucoinpy/documents/ucoinpy/key/__init__.py
parents 8cdf2914 e1be2c2e
No related branches found
No related tags found
No related merge requests found
'''
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)
...@@ -25,8 +25,8 @@ class SigningKey(NaclSigningKey): ...@@ -25,8 +25,8 @@ class SigningKey(NaclSigningKey):
SCRYPT_PARAMS['N'], SCRYPT_PARAMS['r'], SCRYPT_PARAMS['p'], SCRYPT_PARAMS['N'], SCRYPT_PARAMS['r'], SCRYPT_PARAMS['p'],
SEED_LENGTH) SEED_LENGTH)
seedb64 = base64.b64encode(seed) seedb64 = base64.b64encode(seed)
super.__init__(seedb64, Base64Encoder) super().__init__(seedb64, Base64Encoder)
self.pubkey = Base58Encoder.encode(self.verify_key.key) self.pubkey = self.verify_key.encode(encoder=Base58Encoder)
class Base58Encoder(object): class Base58Encoder(object):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment