Skip to content

Commit 2b6200f

Browse files
mflaxmanMichael Flaxman
and
Michael Flaxman
authored
add missing import, improve shamir testing in multiwallet (#56)
* add missing import, improve shamir testing in multiwallet * simplify logic * black * flake8 Co-authored-by: Michael Flaxman <[email protected]>
1 parent bb5879b commit 2b6200f

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

buidl/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
from .pbkdf2 import *
1515
from .psbt import *
1616
from .script import *
17+
from .shamir import *
1718
from .tx import *
1819
from .witness import *

multiwallet.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -587,26 +587,43 @@ def do_split_seed(self, arg):
587587
maximum=16,
588588
)
589589
passphrase = b""
590+
# Max possible combos is 12,870 (with 8-of-16)
591+
testing_limit = 12870
590592
if self.ADVANCED_MODE:
591593
add_passphrase = _get_bool(
592594
"Do you want to add a passphrase?", default=False
593595
)
594596
if add_passphrase:
595597
passphrase = _get_confirmed_pw().encode("ascii")
598+
if _get_bool(
599+
"Do you want to limit how many of these shares you test (for faster results)?",
600+
default=False,
601+
):
602+
testing_limit = _get_int(
603+
"How many combinations would you like to test?",
604+
default=1000,
605+
minimum=k,
606+
maximum=testing_limit,
607+
)
596608
shares = ShareSet.generate_shares(mnemonic, k, n, passphrase=passphrase)
597609
# test the shares (cap at 1000 combinations)
598-
print("testing combinations...")
599-
iterations = 0
600-
for combo in combinations(shares, k):
601-
iterations += 1
602-
if iterations > 1000:
610+
print_yellow(
611+
"Testing share combinations to be certain they will recover your seed phrase"
612+
)
613+
for cnt, combo in enumerate(combinations(shares, k)):
614+
if cnt > testing_limit:
603615
break
604-
elif iterations % 10:
605-
print(".", end="", flush=True)
606616
calculated = ShareSet.recover_mnemonic(combo, passphrase)
607617
if calculated != mnemonic:
608618
# we should never reach this line
609619
raise RuntimeError(f"Bad shares {calculated} for mnemonic {mnemonic}")
620+
if cnt % 10 == 0:
621+
print(".", end="", flush=True)
622+
623+
print_yellow(
624+
f"\nSuccesfully tested {'ALL ' if testing_limit == 12870 else ''}{cnt} combinations"
625+
)
626+
610627
print("\n")
611628
share_mnemonics = "\n\n".join(shares)
612629
if passphrase:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="buidl",
8-
version="0.2.12",
8+
version="0.2.13",
99
author="Example Author",
1010
author_email="[email protected]",
1111
description="An easy-to-use and fully featured bitcoin library written in pure python (no dependencies).",

0 commit comments

Comments
 (0)