Exemplo n.º 1
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)
Exemplo n.º 2
0
 async def save_mnemonic(self):
     await self.check_card(check_pin=True)
     d = self.serialize_data({
         "enc":
         self.enc_secret,
         "entropy":
         bip39.mnemonic_to_bytes(self.mnemonic)
     })
     self.applet.save_secret(d)
     self._is_key_saved = True
     # check it's ok
     await self.load_mnemonic()
Exemplo n.º 3
0
 async def save_mnemonic(self):
     await self.check_card(check_pin=True)
     encrypt = await self.show(
         Prompt("Encrypt the secret?",
                "\nIf you encrypt the secret on the card "
                "it will only work with this device.\n\n"
                "Otherwise it will be readable on any device "
                "after you enter the PIN code.\n\n"
                "Keep in mind that with encryption enabled "
                "wiping the device makes the secret unusable!",
                confirm_text="Yes, encrypt",
                cancel_text="Keep as plain text"))
     self.show_loader("Saving secret to the card...")
     d = self.serialize_data(
         {"entropy": bip39.mnemonic_to_bytes(self.mnemonic)},
         encrypt=encrypt,
     )
     self.applet.save_secret(d)
     self._is_key_saved = True
     # check it's ok
     await self.load_mnemonic()
Exemplo n.º 4
0
 def test_fix_checksum(self):
     invalid_mnemonic = ("ghost " * 12).strip()
     self.assertRaises(ValueError, mnemonic_to_bytes, invalid_mnemonic)
     entropy = mnemonic_to_bytes(invalid_mnemonic, ignore_checksum=True)
     valid_mnemonic = mnemonic_from_bytes(entropy)
     self.assertEqual(valid_mnemonic, "ghost " * 11 + "gentle")
Exemplo n.º 5
0
 def fix_mnemonic(phrase):
     entropy = bip39.mnemonic_to_bytes(phrase, ignore_checksum=True)
     return bip39.mnemonic_from_bytes(entropy)
Exemplo n.º 6
0
def fix_mnemonic(phrase):
    """Fixes checksum of invalid mnemonic"""
    entropy = bip39.mnemonic_to_bytes(phrase, ignore_checksum=True)
    return bip39.mnemonic_from_bytes(entropy)
Exemplo n.º 7
0
def mnemonic_entered(mnemonic):
    global entropy
    entropy = bip39.mnemonic_to_bytes(mnemonic.strip())
    ask_for_password()