Skip to content
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fpdf2 >=2.7.6,<3
hdwallet >=2.2.1,<3
mnemonic >=0.2, <1
qrcode >=7.3
shamir-mnemonic >=0.2.2,<1
shamir-mnemonic >=0.3.0,<1
6 changes: 5 additions & 1 deletion slip39/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ def create(
iteration_exponent: int = 1,
cryptopaths: Optional[Sequence[Union[str,Tuple[str,str],Tuple[str,str,str]]]] = None, # default: ETH, BTC at default path, format
strength: Optional[int] = None, # Default: 128
extendable: bool = True,
) -> Tuple[str,int,Dict[str,Tuple[int,List[str]]], Sequence[Sequence[Account]], bool]:
"""Creates a SLIP-39 encoding for supplied master_secret Entropy, and 1 or more Cryptocurrency
accounts. Returns the Details, in a form directly compatible with the layout.produce_pdf API.
Expand Down Expand Up @@ -1108,7 +1109,8 @@ def create(
groups = g_dims,
master_secret = master_secret,
passphrase = passphrase,
iteration_exponent= iteration_exponent
iteration_exponent= iteration_exponent,
extendable = extendable
)

groups = {
Expand Down Expand Up @@ -1136,6 +1138,7 @@ def mnemonics(
passphrase: Optional[Union[bytes,str]] = None,
iteration_exponent: int = 1,
strength: int = BITS_DEFAULT,
extendable: bool = True,
) -> List[List[str]]:
"""Generate SLIP39 mnemonics for the supplied group_threshold of the given groups. Will generate a
random master_secret, if necessary.
Expand Down Expand Up @@ -1166,6 +1169,7 @@ def mnemonics(
master_secret = master_secret,
passphrase = passphrase or b"", # python-shamir-mnemonic requires bytes
iteration_exponent = iteration_exponent,
extendable = extendable,
)


Expand Down
34 changes: 29 additions & 5 deletions slip39/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,30 @@ def test_account_format():
assert acct.address == 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu'


def test_slip39_non_extendable_compatibility():
"""Test that SLIP-39 non-extendable backup of a wallet generated by Trezor can be recevered"""
# The 4th vector from https://github.com/trezor/python-shamir-mnemonic/blob/master/vectors.json
mnemonics = [
"shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed",
"shadow pistol academic acid actress prayer class unknown daughter sweater depict flip twice unkind craft early superior advocate guest smoking"
]
account = Account( crypto="Bitcoin", format="legacy" )
account.from_mnemonic( "\n".join(mnemonics), passphrase = 'TREZOR', path="m/" )
assert account.xprvkey == "xprv9s21ZrQH143K2nNuAbfWPHBtfiSCS14XQgb3otW4pX655q58EEZeC8zmjEUwucBu9dPnxdpbZLCn57yx45RBkwJHnwHFjZK4XPJ8SyeYjYg"


def test_slip39_extendable_trezor_compatibility():
"""Test that SLIP-39 extendable backup of a wallet generated by Trezor can be recevered"""
# The 43th vector from https://github.com/trezor/python-shamir-mnemonic/blob/master/vectors.json
mnemonics = [
"enemy favorite academic acid cowboy phrase havoc level response walnut budget painting inside trash adjust froth kitchen learn tidy punish",
"enemy favorite academic always academic sniff script carpet romp kind promise scatter center unfair training emphasis evening belong fake enforce"
]
account = Account( crypto="Bitcoin", format="legacy" )
account.from_mnemonic( "\n".join(mnemonics), passphrase = 'TREZOR', path="m/" )
assert account.xprvkey == "xprv9s21ZrQH143K4FS1qQdXYAFVAHiSAnjj21YAKGh2CqUPJ2yQhMmYGT4e5a2tyGLiVsRgTEvajXkxhg92zJ8zmWZas9LguQWz7WZShfJg6RS"


def test_account_from_mnemonic():
"""Test all the ways the entropy 0xffff...ffff can be encoded and HD Wallets derived."""
# Raw 0xffff...ffff entropy as Seed. Not BIP-39 decoded (hashed) via mnemonic to produce Seed.
Expand Down Expand Up @@ -399,11 +423,11 @@ def test_create():

assert details_xmas.groups == {
"fren": ( 3, [
"academic acid academic acne academic academic academic academic academic academic academic academic academic academic academic academic academic carpet making building",
"academic acid academic agree depart dance galaxy acrobat mayor disaster quick justice ordinary agency plunge should pupal emphasis security obtain",
"academic acid academic amazing crush royal faint spit briefing craft floral negative work depend prune adapt merit romp home elevator",
"academic acid academic arcade cargo unfold aunt spider muscle bedroom triumph theory gather dilemma building similar chemical object cinema salon",
"academic acid academic axle crush swing purple violence teacher curly total equation clock mailman display husband tendency smug laundry disaster"
"academic agency academic acne academic academic academic academic academic academic academic academic academic academic academic academic academic arena diet involve",
"academic agency academic agree closet maximum rumor beyond organize taught game helpful fishing brother bumpy nervous presence document buyer reject",
"academic agency academic amazing arena meaning advocate hearing hunting pecan lilac device oasis teacher traffic retailer criminal scene flip true",
"academic agency academic arcade cover acne safari item vanish else superior focus skin webcam venture clay loan various impact client",
"academic agency academic axle carpet blimp stilt intend august racism webcam replace gather rich sweater mandate maximum rumor drink scene"
] ),
}

Expand Down
Loading