def check_list(language, vectors, verbose=False): for v in vectors: bip39 = BIP39(entropy=unhexlify(v[0])) code = bip39.to_mnemonic() seed = hexlify(bip39.to_seed(mnemonic=code, passphrase="TREZOR")) if sys.version >= "3": seed = seed.decode("utf8") assert BIP39.check(v[1]) is True assert v[1] == code assert v[2] == seed print(code, "Ok")
def __init__(self, entropy: bytes = None, seed: bytes = None): if seed is None: # reconstruct seed from entropy via BIP39 assert entropy is not None bip39 = BIP39(entropy) self.seed = bip39.to_seed() else: self.seed = seed
def get_from_path(cls, mnemonic: str, path: str) -> "DerivableKey": """Gets the derived key in one go from address/motion path string""" # address, motion = path.split("/") # No: motion txid can contain "/" => coud use same limit param from split as above. elements = path.split("/") address = elements.pop(0) motion = "/".join(elements) bip39 = BIP39.from_mnemonic(mnemonic) master_key = DerivableKey(seed=bip39.to_seed()) address_key = master_key.derive(address) motion_key = address_key.derive(motion) return motion_key
async def about(self, params=None): voting = { "masterkey": MASTER_KEY, "masterkey_file": KEYFILE, "key_check": BIP39.check(MASTER_KEY), } await fill_motions() voting["bgvp_motions"] = BGVP_MOTIONS self.render("about.html", bismuth=self.bismuth_vars, version=__version__, voting=voting)
async def set_key(self, params=None): masterkey = self.get_argument("masterkey", None) # print("key", masterkey) if not masterkey: # Generate a new one entropy = token_bytes(16) print(entropy) bip39 = BIP39(entropy) masterkey = bip39.to_mnemonic() with open(KEYFILE, "w") as fp: fp.write(masterkey) global MASTER_KEY MASTER_KEY = masterkey self.redirect("/crystal/bismuthvote/")
def test_seed(verbose=False): bip39 = BIP39.from_mnemonic(TEST_MNEMONIC) if verbose: print("Entropy", bip39.entropy.hex()) assert bip39.entropy.hex() == "80808080808080808080808080808080" seed = bip39.to_seed() if verbose: print("Seed", seed.hex()) assert seed.hex() == TEST_SEED_HEX key = DerivableKey(seed=seed) if verbose: print("Pubkey", key.to_pubkey().hex()) print("AES key", key.to_aes_key().hex()) assert ( key.to_pubkey().hex() == "0418b9908d43f503ae8ed3128c35edd8e0b9350c01a389bf5d83aece4822722b6223dbfaec15801253d658356836802a43c401fed1415a312f1a09f52d96a52ae4" ) assert (key.to_aes_key().hex() == "3b49e2c776a2a8c3a1b5666ab19e3b1103bb4a435efc70eadf829bfd59c06e20")