enable bip32

This commit is contained in:
ThomasV 2014-01-29 17:12:08 +01:00
parent 1c35e15de7
commit 9218175301
3 changed files with 22 additions and 28 deletions

View File

@ -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()
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

View File

@ -1,5 +1,4 @@
ELECTRUM_VERSION = "2.0" # version of the client package
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

View File

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