Browse Source

enable bip32

283
ThomasV 11 years ago
parent
commit
9218175301
  1. 2
      lib/bitcoin.py
  2. 3
      lib/version.py
  3. 45
      lib/wallet.py

2
lib/bitcoin.py

@ -61,6 +61,8 @@ hash_decode = lambda x: x.decode('hex')[::-1]
hmac_sha_512 = lambda x,y: hmac.new(x, y, hashlib.sha512).digest() hmac_sha_512 = lambda x,y: hmac.new(x, y, hashlib.sha512).digest()
mnemonic_hash = lambda x: hmac_sha_512("Bitcoin mnemonic", x).encode('hex') mnemonic_hash = lambda x: hmac_sha_512("Bitcoin mnemonic", x).encode('hex')
from version import SEED_PREFIX
is_seed = lambda x: hmac_sha_512("Seed version", x).encode('hex')[0:2].startswith(SEED_PREFIX)
# pywallet openssl private key implementation # pywallet openssl private key implementation

3
lib/version.py

@ -1,5 +1,4 @@
ELECTRUM_VERSION = "2.0" # version of the client package ELECTRUM_VERSION = "2.0" # version of the client package
PROTOCOL_VERSION = '0.9' # protocol version requested PROTOCOL_VERSION = '0.9' # protocol version requested
SEED_VERSION = 4 # bump this every time the seed generation is modified SEED_VERSION = 6 # bump this every time the seed generation is modified
SEED_PREFIX = '01' # the hash of the mnemonic seed must begin with this SEED_PREFIX = '01' # the hash of the mnemonic seed must begin with this

45
lib/wallet.py

@ -289,8 +289,8 @@ class Wallet:
# we keep only 13 words, that's approximately 139 bits of entropy # we keep only 13 words, that's approximately 139 bits of entropy
words = mnemonic.mn_encode(s)[0:13] words = mnemonic.mn_encode(s)[0:13]
seed = ' '.join(words) seed = ' '.join(words)
if mnemonic_hash(seed).startswith(SEED_PREFIX): if is_seed(seed):
break # this removes 12 bits of entropy break # this will remove 8 bits of entropy
nonce += 1 nonce += 1
return seed return seed
@ -303,15 +303,10 @@ class Wallet:
raise Exception("a seed exists") raise Exception("a seed exists")
if not seed: if not seed:
self.seed = random_seed(128) self.seed = self.make_seed()
self.seed_version = 4 self.seed_version = SEED_VERSION
return return
#if not seed:
# self.seed = self.make_seed()
# self.seed_version = SEED_VERSION
# return
# find out what kind of wallet we are # find out what kind of wallet we are
try: try:
seed.strip().decode('hex') seed.strip().decode('hex')
@ -322,22 +317,19 @@ class Wallet:
pass pass
words = seed.split() words = seed.split()
self.seed_version = 4 try:
self.seed = mnemonic.mn_decode(words) mnemonic.mn_decode(words)
uses_electrum_words = True
except Exception:
uses_electrum_words = False
#try: if uses_electrum_words and len(words) != 13:
# mnemonic.mn_decode(words) self.seed_version = 4
# uses_electrum_words = True self.seed = mnemonic.mn_decode(words)
#except Exception: else:
# uses_electrum_words = False #assert is_seed(seed)
# self.seed_version = SEED_VERSION
#if uses_electrum_words and len(words) != 13: self.seed = seed
# self.seed_version = 4
# self.seed = mnemonic.mn_decode(words)
#else:
# assert mnemonic_hash(seed).startswith(SEED_PREFIX)
# self.seed_version = SEED_VERSION
# self.seed = seed
def save_seed(self, password): def save_seed(self, password):
@ -433,9 +425,10 @@ class Wallet:
def deseed_branch(self, k): def deseed_branch(self, k):
# check that parent has no seed # check that parent has no seed
assert self.seed == '' # assert self.seed == ''
self.master_private_keys.pop(k) k = self.master_private_keys.pop(k)
self.storage.put('master_private_keys', self.master_private_keys, True) self.storage.put('master_private_keys', self.master_private_keys, True)
return k
def is_watching_only(self): def is_watching_only(self):
return (self.seed == '') and (self.master_private_keys == {}) return (self.seed == '') and (self.master_private_keys == {})

Loading…
Cancel
Save