pjkundert / python-slip39

Generate Ethereum, Bitcoin, etc. account seed and backup Mnemonics in SLIP-39 format (Trezor & Ledger compatible), with details in printable PDF format. Optionally, also print encrypted JSON and BIP-38 paper wallets.
https://slip39.com
Other
50 stars 17 forks source link

API does not support single-share slip39 menmonic #21

Open onvej-sl opened 4 weeks ago

onvej-sl commented 4 weeks ago

This function incorrectly assumes that slip39 backups consists of at least two shares.

This can lead to "Invalid mnemonic words." exception. You can test it using the following test:

def test_slip39_compatibility():
    """Test that SLIP-39 backup of a wallet generated by Trezor can be recevered"""
    # The 1th vector from https://github.com/trezor/python-shamir-mnemonic/blob/master/vectors.json
    mnemonics = [
        "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision keyboard"
    ]
    account = Account( crypto="Bitcoin", format="legacy" )
    account.from_mnemonic( "\n".join(mnemonics), passphrase = 'TREZOR', path="m/" )
    assert account.xprvkey == "xprv9s21ZrQH143K4QViKpwKCpS2zVbz8GrZgpEchMDg6KME9HZtjfL7iThE9w5muQA4YPHKN1u5VM1w8D4pvnjxa2BmpGMfXr7hnRrRHZ93awZ"

Interestingly enough, the slip39.recovery module works correctly:

python3 -m slip39.recovery -p TREZOR -m "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision keyboard" 
bb54aac4b89dc868ba37d9cc21b2cece