def test_known_dice_rolls():
    """ Given 99 known dice rolls, the resulting mnemonic should be valid and match the expected. """
    dice_rolls = "522222222222222222222222222222222222222222222555555555555555555555555555555555555555555555555555555"
    expected = "resource timber firm banner horror pupil frozen main pear direct pioneer broken grid core insane begin sister pony end debate task silk empty curious"

    mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
    actual = " ".join(mnemonic)
    assert bip39.mnemonic_is_valid(actual)
    assert actual == expected

    dice_rolls = "222222222222222222222222222222222222222222222555555555555555555555555555555555555555555555555555555"
    expected = "garden uphold level clog sword globe armor issue two cute scorpion improve verb artwork blind tail raw butter combine move produce foil feature wave"

    mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
    actual = " ".join(mnemonic)
    assert bip39.mnemonic_is_valid(actual)
    assert actual == expected

    dice_rolls = "222222222222222222222222222222222222222222222555555555555555555555555555555555555555555555555555556"
    expected = "lizard broken love tired depend eyebrow excess lonely advance father various cram ignore panic feed plunge miss regret boring unique galaxy fan detail fly"

    mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
    actual = " ".join(mnemonic)
    assert bip39.mnemonic_is_valid(actual)
    assert actual == expected
def test_calculate_checksum():
    """ Given an 11-word or 23-word mnemonic, the calculated checksum should yield a
        valid complete mnemonic.
    """
    # Test mnemonics from https://iancoleman.io/bip39/
    partial_mnemonic = "crawl focus rescue cable view pledge rather dinner cousin unfair day"
    mnemonic = mnemonic_generation.calculate_checksum(
        partial_mnemonic.split(" "), wordlist=bip39.WORDLIST)
    assert bip39.mnemonic_is_valid(" ".join(mnemonic))

    partial_mnemonic = "bubble father debate ankle injury fence mesh evolve section wet coyote violin pyramid flower rent arrow round clutch myth safe base skin mobile"
    mnemonic = mnemonic_generation.calculate_checksum(
        partial_mnemonic.split(" "), wordlist=bip39.WORDLIST)
    assert bip39.mnemonic_is_valid(" ".join(mnemonic))
def test_dice_rolls():
    """ Given 99 random dice rolls, the resulting mnemonic should be valid. """
    dice_rolls = ""
    for i in range(0, 99):
        # Do not need truly rigorous random for this test
        dice_rolls += str(random.randint(0, 5))

    mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
    assert bip39.mnemonic_is_valid(" ".join(mnemonic))
def test_verify_against_coldcard_sample():
    """ https://coldcard.com/docs/verifying-dice-roll-math """
    dice_rolls = "123456"
    expected = "mirror reject rookie talk pudding throw happy era myth already payment own sentence push head sting video explain letter bomb casual hotel rather garment"

    mnemonic = mnemonic_generation.generate_mnemonic_from_dice(dice_rolls)
    actual = " ".join(mnemonic)
    assert bip39.mnemonic_is_valid(actual)
    assert actual == expected
Beispiel #5
0
 def test_bip39(self):
     for [seed, exp_mnemonic, hex_seed, xprv] in VECTORS:
         act_mnemonic = mnemonic_from_bytes(unhexlify(seed))
         act_xkey = HDKey.from_seed(
             mnemonic_to_seed(act_mnemonic, password="******"))
         self.assertEqual(act_mnemonic, exp_mnemonic)
         self.assertTrue(mnemonic_is_valid(act_mnemonic))
         self.assertEqual(
             hexlify(mnemonic_to_bytes(act_mnemonic)).decode(), seed)
         self.assertEqual(act_xkey.to_base58(), xprv)
Beispiel #6
0
    def test_alternate_wordlist(self):
        # Spanish mnemonics validated via https://iancoleman.io/bip39/#spanish
        mnemonics = [
            ("título paso humano cañón enfado ropero hueco cromo blusa turno fideo glaciar verano baba gordo fila trance íntimo rotar gustar sombra revés laguna jardín",
             "bb0c5656117fd52d995dafca2d692974e74cb7c713c35871a0915d7bda6122694b2b67664113b198d2c1dd828195587c7dec8d6179f93d2157d6a11d8d0a949d"
             ),
            ("natural tóxico choque regreso norte tarta uña prisión bulto ángulo fervor nariz",
             "30affe746f3a81816739c2dacc3de426084482b729c7b592cee0ff2bdf73315943a5da8d8da4afd767f905d5ded4b0ab3a948d7eff9834fca5e8691a186fee20"
             ),
        ]
        from .data.bip39_es import WORDLIST as ES_WORDLIST

        for mnemonic, expected_seed in mnemonics:
            self.assertTrue(mnemonic_is_valid(mnemonic, wordlist=ES_WORDLIST))

            self.assertEqual(
                hexlify(mnemonic_to_seed(mnemonic,
                                         wordlist=ES_WORDLIST)).decode(),
                expected_seed)

            self.assertEqual(
                mnemonic_from_bytes(mnemonic_to_bytes(mnemonic,
                                                      wordlist=ES_WORDLIST),
                                    wordlist=ES_WORDLIST), mnemonic)
Beispiel #7
0
 def test_invalid_checksum(self):
     words = (
         "ivory canyon lend simple system regret test cool clip foam answer abandon"
     )
     self.assertFalse(mnemonic_is_valid(words))
Beispiel #8
0
 def test_invalid_word(self):
     words = "fljsafk minute glow ride mask ceiling old limb rookie discover cotton biology"
     self.assertFalse(mnemonic_is_valid(words))
Beispiel #9
0
 def test_invalid_length(self):
     words = "panel trumpet seek bridge income piano history car flower aim loan accident embark canoe"
     self.assertFalse(mnemonic_is_valid(words))