Esempio n. 1
0
async def handle_Initialize(ctx: wire.Context, msg: Initialize) -> Features:
    if msg.state is None or msg.state != cache.get_state(
            prev_state=bytes(msg.state)):
        cache.clear()
        if msg.skip_passphrase:
            cache.set_passphrase("")
    return get_features()
Esempio n. 2
0
async def _get_passphrase(ctx: wire.Context) -> bytes:
    passphrase = cache.get_passphrase()
    if passphrase is None:
        passphrase = await protect_by_passphrase(ctx)
        cache.set_passphrase(passphrase)

    return passphrase
Esempio n. 3
0
async def _compute_seed(ctx: wire.Context) -> bytes:
    passphrase = cache.get_passphrase()
    if passphrase is None:
        passphrase = await protect_by_passphrase(ctx)
        cache.set_passphrase(passphrase)
    seed = mnemonic.get_seed(passphrase)
    cache.set_seed(seed)
    return seed
Esempio n. 4
0
async def _compute_seed(ctx: wire.Context) -> bytes:
    passphrase = cache.get_passphrase()
    if passphrase is None:
        passphrase = await protect_by_passphrase(ctx)
        cache.set_passphrase(passphrase)
    _start_bip39_progress()
    seed = bip39.seed(storage.get_mnemonic(), passphrase, _render_bip39_progress)
    cache.set_seed(seed)
    return seed
Esempio n. 5
0
async def get_keychain(ctx: wire.Context, namespaces: list) -> Keychain:
    if not storage.is_initialized():
        raise wire.ProcessError("Device is not initialized")
    seed = cache.get_seed()
    if seed is None:
        passphrase = cache.get_passphrase()
        if passphrase is None:
            passphrase = await protect_by_passphrase(ctx)
            cache.set_passphrase(passphrase)
        seed = mnemonic.get_seed(passphrase)
        cache.set_seed(seed)
    keychain = Keychain(seed, namespaces)
    return keychain
Esempio n. 6
0
async def get_keychain(ctx: wire.Context) -> Keychain:
    if not storage.is_initialized():
        raise wire.ProcessError("Device is not initialized")

    # derive the root node from mnemonic and passphrase
    passphrase = cache.get_passphrase()
    if passphrase is None:
        passphrase = await protect_by_passphrase(ctx)
        cache.set_passphrase(passphrase)
    root = bip32.from_mnemonic_cardano(mnemonic.restore(), passphrase)

    # derive the namespaced root node
    for i in SEED_NAMESPACE[0]:
        root.derive_cardano(i)

    keychain = Keychain(SEED_NAMESPACE[0], root)
    return keychain
Esempio n. 7
0
async def get_keychain(ctx: wire.Context, namespaces: list) -> Keychain:
    if not storage.is_initialized():
        raise wire.ProcessError("Device is not initialized")

    seed = cache.get_seed()
    if seed is None:
        # derive seed from mnemonic and passphrase
        passphrase = cache.get_passphrase()
        if passphrase is None:
            passphrase = await protect_by_passphrase(ctx)
            cache.set_passphrase(passphrase)
        _start_bip39_progress()
        seed = bip39.seed(storage.get_mnemonic(), passphrase,
                          _render_bip39_progress)
        cache.set_seed(seed)

    keychain = Keychain(seed, namespaces)
    return keychain
Esempio n. 8
0
async def get_keychain(ctx: wire.Context) -> Keychain:
    if not storage.is_initialized():
        raise wire.ProcessError("Device is not initialized")

    # derive the root node from mnemonic and passphrase
    passphrase = cache.get_passphrase()
    if passphrase is None:
        passphrase = await protect_by_passphrase(ctx)
        cache.set_passphrase(passphrase)
    # TODO fix for SLIP-39!
    mnemonic_secret, mnemonic_module = mnemonic.get()
    if mnemonic_module == mnemonic.slip39:
        # TODO: we need to modify bip32.from_mnemonic_cardano to accept entropy directly
        raise NotImplementedError("SLIP-39 currently does not support Cardano")
    else:
        root = bip32.from_mnemonic_cardano(mnemonic_secret.decode(),
                                           passphrase)

    # derive the namespaced root node
    for i in SEED_NAMESPACE:
        root.derive_cardano(i)

    keychain = Keychain(SEED_NAMESPACE, root)
    return keychain
Esempio n. 9
0
async def _get_cached_passphrase(ctx: wire.Context) -> str:
    if cache.get_passphrase() is None:
        passphrase = await protect_by_passphrase(ctx)
        cache.set_passphrase(passphrase)
    return cache.get_passphrase()