Esempio n. 1
0
async def _get_cached_seed(ctx: wire.Context) -> bytes:
    if not storage.is_initialized():
        raise wire.ProcessError('Device is not initialized')
    if cache.get_seed() is None:
        passphrase = await _get_cached_passphrase(ctx)
        seed = bip39.seed(storage.get_mnemonic(), passphrase)
        cache.set_seed(seed)
    return cache.get_seed()
Esempio n. 2
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:
        seed = await _compute_seed(ctx)
    keychain = Keychain(seed, namespaces)
    return keychain
Esempio n. 3
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. 4
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. 5
0
async def get_keychain(ctx: wire.Context) -> Keychain:
    if not storage.is_initialized():
        raise wire.ProcessError("Device is not initialized")

    if mnemonic.is_bip39():
        # derive the root node from mnemonic and passphrase
        passphrase = await _get_passphrase(ctx)
        root = bip32.from_mnemonic_cardano(mnemonic.get_secret().decode(),
                                           passphrase)
    else:
        seed = cache.get_seed()
        if seed is None:
            passphrase = await _get_passphrase(ctx)
            seed = mnemonic.get_seed(passphrase)
            cache.set_seed(seed)
        root = bip32.from_seed(seed, "ed25519 cardano seed")

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

    keychain = Keychain(SEED_NAMESPACE, root)
    return keychain
Esempio n. 6
0
async def _get_seed(ctx: wire.Context) -> bytes:
    if cache.get_seed() is None:
        seed, passphrase = await _compute_seed(ctx)
        cache.set_seed(seed, passphrase)
    return cache.get_seed()