From ce59bd31a78146e4521d01b1c2cbf5f9095105c3 Mon Sep 17 00:00:00 2001 From: Alexey Karyabkin Date: Mon, 4 Jun 2018 17:29:04 +0400 Subject: [PATCH] added function create seed bip0039 --- pybtc/hdwallet.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pybtc/hdwallet.py b/pybtc/hdwallet.py index e356189..fc622d5 100644 --- a/pybtc/hdwallet.py +++ b/pybtc/hdwallet.py @@ -15,7 +15,8 @@ def create_passphrase(bits=256, language='english'): entropy = os.urandom(bits // 8) mnemonic = create_mnemonic(entropy, language) return ' '.join(mnemonic[::-1]) - raise ValueError('Strength should be one of the following [128, 160, 192, 224, 256], but it is not (%d).' % bits) + else: + raise ValueError('Strength should be one of the following [128, 160, 192, 224, 256], but it is not (%d).' % bits) def create_mnemonic(entropy, language='english'): @@ -77,6 +78,11 @@ def mnemonic2bytes(passphrase, language): fb = unhexlify(ent_hash)[0] assert (fb >> (8 - chk_sum_bit_len)) & chk_sum return entropy - raise ValueError('Number of words must be one of the following: [12, 15, 18, 21, 24], but it is not (%d).' % len(mnemonic)) + else: + raise ValueError('Number of words must be one of the following: [12, 15, 18, 21, 24], but it is not (%d).' % len(mnemonic)) + + +def create_seed(passphrase, password=''): + return hashlib.pbkdf2_hmac('sha512', password.encode(), passphrase.encode(), 2048)