Skip to content
Snippets Groups Projects

[feat] #150 Add DUBP Mnemonic SigningKey feature

Merged [feat] #150 Add DUBP Mnemonic SigningKey feature
All threads resolved!
Merged Vincent Texier requested to merge dubp_mnemonic into dev
All threads resolved!
Files
2
@@ -22,7 +22,7 @@ from typing import Optional, Union, TypeVar, Type
import libnacl.sign
import pyaes
from libnacl.utils import load_key
from hashlib import scrypt
from hashlib import scrypt, sha256
from .scrypt_params import ScryptParams
from .base58 import Base58Encoder
@@ -509,3 +509,31 @@ Data: {data}""".format(
seed = bytes(base64.b64decode(secret)[0:32])
return cls(seed)
@classmethod
def from_dubp_mnemonic(
cls, mnemonic: str, scrypt_params: ScryptParams = None
) -> SigningKeyType:
"""
Generate key pair instance from a DUBP mnemonic passphrase
See https://git.duniter.org/documents/rfcs/blob/dubp-mnemonic/rfc/0014_Dubp_Mnemonic.md
+3
:param mnemonic: Passphrase generated from a mnemonic algorithm
:param scrypt_params: ScryptParams instance (default=None)
:return:
"""
if scrypt_params is None:
scrypt_params = ScryptParams()
_password = mnemonic.encode("utf-8") # type: bytes
_salt = sha256(b"dubp" + _password).digest() # type: bytes
_seed = scrypt(
password=_password,
salt=_salt,
n=scrypt_params.N, # 4096
r=scrypt_params.r, # 16
p=scrypt_params.p, # 1
dklen=scrypt_params.seed_length, # 32
) # type: bytes
return cls(_seed)
Loading