Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
title, body = cap_story()
assert pw in body
need_keypress('y')
done = None
while done == None:
time.sleep(0.050)
done = dev.send_recv(CCProtocolPacker.get_passphrase_done(), timeout=None)
xpub = done
assert xpub[1:4] == 'pub'
got = BIP32Node.from_wallet_key(xpub)
# what it should be
seed = Mnemonic.to_seed(words, passphrase=pw)
expect = BIP32Node.from_master_secret(seed)
assert got.public_pair() == expect.public_pair()
xfp, = struct.unpack('I', expect.fingerprint())
return xfp
def process(data, lst):
code = mnemo.to_mnemonic(unhexlify(data))
seed = Mnemonic.to_seed(code, passphrase="TREZOR")
xprv = BIP32Key.fromEntropy(seed).ExtendedKey()
seed = b2h(seed)
print("input : %s (%d bits)" % (data, len(data) * 4))
print("mnemonic : %s (%d words)" % (code, len(code.split(" "))))
print("seed : %s (%d bits)" % (seed, len(seed) * 4))
print("xprv : %s" % xprv)
print()
lst.append((data, code, seed, xprv))
def setup_device(self, mnemonic, passphrase, wallet_manager, testnet):
seed = Mnemonic.to_seed(mnemonic)
xprv = seed_to_hd_master_key(seed, testnet=testnet)
wallet_name = os.path.join(wallet_manager.cli_path + '_hotstorage', self.alias)
wallet_manager.cli.createwallet(wallet_name, False, True)
cli = wallet_manager.cli.wallet(wallet_name)
# TODO: Maybe more than 1000? Maybe add mechanism to add more later.
## NOTE: This will work only on the network the device was added, so hot devices should be filtered out by network.
coin = int(testnet)
cli.importmulti([
{ 'desc': AddChecksum('sh(wpkh({}/49h/{}h/0h/0/*))'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('sh(wpkh({}/49h/{}h/0h/1/*))'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('wpkh({}/84h/{}h/0h/0/*)'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('wpkh({}/84h/{}h/0h/1/*)'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('sh(wpkh({}/48h/{}h/0h/1h/0/*))'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('sh(wpkh({}/48h/{}h/0h/1h/1/*))'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('wpkh({}/48h/{}h/0h/2h/0/*)'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
{ 'desc': AddChecksum('wpkh({}/48h/{}h/0h/2h/1/*)'.format(xprv, coin)), 'range': 1000, 'timestamp': 'now'},
def master_key_from_mnemonic(mnemonic: str, passphrase: str = ''):
"""Generates a master key from a mnemonic.
The mnemonic sentence representing the seed from which to generate the master key.
The passphrase representing the password if one was used.
"""
seed = Mnemonic.to_seed(mnemonic, passphrase)
return HDPrivateKey.master_key_from_seed(seed)
def seed_to_privkey(seed: str, path: str = DEFAULT_DERIVATION_PATH) -> bytes:
"""Get a private key from a mnemonic seed and a derivation path.
Assumes a BIP39 mnemonic seed with no passphrase. Raises
`cosmospy.BIP32DerivationError` if the resulting private key is
invalid.
"""
seed_bytes = mnemonic.Mnemonic.to_seed(seed, passphrase="")
hd_wallet = hdwallets.BIP32.from_seed(seed_bytes)
# This can raise a `hdwallets.BIP32DerivationError` (which we alias so
# that the same exception type is also in the `cosmospy` namespace).
derived_privkey = hd_wallet.get_privkey_from_path(path)
return derived_privkey