Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in mnemonic.py, include all bip39 wordlists, improve mnemonic performance, Bip32 utilities #141

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions bitcoin/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,39 @@ def coinvault_priv_to_bip32(*args):
return bip32_serialize((MAINNET_PRIVATE, 0, b'\x00'*4, 0, I2, I3+b'\x01'))


def bip32_descend(*args):
def bip32_path(*args):
if len(args) == 2 and isinstance(args[1], list):
key, path = args
else:
key, path = args[0], map(int, args[1:])
for p in path:
key = bip32_ckd(key, p)
return bip32_extract_key(key)

return reduce(bip32_ckd,path,key)

def bip32_descend(*args):
return bip32_extract_key(bip32_path(*args))

#explicit harden method.
def bip32_harden(x):
return (1 << 31) + x

def bip32_path_from_string(pathstring): #can only handle private key style paths not others.
def process(x):
nhx=x.strip("'")
return bip32_harden(int(nhx)) if nhx != x else int(nhx)
pe=pathstring.split("/")
return [process(x) for x in pe[1:]]


def hd_lookup(root,account=None,index=None,change=0,coin=0):
depth=bip32_deserialize(root)[1]
if(depth==0): #if root is master (has a depth=0)
if(index):
return bip32_path(root,bip32_harden(44),bip32_harden(coin),bip32_harden(account),change,index)
else:
return bip32_path(root,bip32_harden(44),bip32_harden(coin),bip32_harden(account))
elif(depth==3):
return bip32_path(root,change,index)
else:
raise Exception("%s does not appear to be a bip44-compatible xpubkey!" % (root))


Loading