Skip to content

Commit 0170f1f

Browse files
author
neocogent
committed
add direct mode for entropy
1 parent cb962ed commit 0170f1f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

scripts/bip39chk

+9-3
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ if len(sys.argv) < 2:
5050
print( "-a\tNumber of addresses to generate, default none\n-i\tAddress start index, default 0\n-c\tOutput \"change\" addresses" )
5151
print( "-k\tInclude pubkey or script hash" )
5252
print( "-e\tUse input data as entropy to create word list of given word count.\n-x\tInput is xpub/ypub, only output addresses" )
53+
print( "-d\tUse input data directly to create word list of given word count." )
5354
print( "Seed words can be in quotes or not, but must follow options. Use -- to read from stdin." )
5455
sys.exit(1)
5556

5657
passphrase = ''
5758
derivation = "m/44'/0'/0'"
5859
wordlist = 'english.txt'
5960
addrcfg = { 'cnt':0, 'start':0, 'chg':0 }
60-
wordcount = 0
61-
js,addr_only,pkh = False,False,False
61+
wordcount,orgdata = 0,0
62+
js,addr_only,pkh,direct = False,False,False,False
6263

6364
seedargs = 1
6465
seed_data = None
@@ -74,6 +75,8 @@ while(seedargs < len(sys.argv)):
7475
js = True
7576
elif opt == 'k':
7677
pkh = True
78+
elif opt == 'd':
79+
direct = True
7780
elif opt == 'c':
7881
addrcfg['chg'] = 1
7982
elif opt == 'x':
@@ -162,7 +165,8 @@ if addr_only:
162165

163166
else:
164167
if wordcount in [12,15,18,21,24]:
165-
seed_data = hex_to_bip39(binascii.hexlify(hashlib.sha512(seed_data[0].encode()).digest()), wordlist, wordcount)
168+
orgdata = seed_data[0]
169+
seed_data = hex_to_bip39(binascii.hexlify(hashlib.sha512(seed_data[0].encode()).digest()) if not direct else seed_data[0]+"00", wordlist, wordcount)
166170

167171
last_word = bip39_validate(' '.join(seed_data), wordlist)
168172
if seed_data[-1] != last_word:
@@ -175,6 +179,8 @@ else:
175179
out['seedhex'] = str(binascii.hexlify(bip32_seed), 'ascii')
176180
xtype = 'p2wpkh-p2sh' if derivation.startswith("m/49'") else 'standard'
177181
out['type'] = 'p2pkh' if xtype == 'standard' else xtype
182+
if orgdata != 0:
183+
out['entropy'] = orgdata
178184

179185
#from electrum.bitcoin import bip32_root, bip32_private_derivation
180186
#prv,pub = bip32_root(bip32_seed, xtype)

0 commit comments

Comments
 (0)