From d2e31e24ee424f6288d0e134e6d2ee4b8451724c Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Mon, 12 Dec 2016 15:18:46 +0100 Subject: [PATCH] apps.common.seed: simplify, remove root caching --- src/apps/common/seed.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/apps/common/seed.py b/src/apps/common/seed.py index 46a4c1b1..8e9e950f 100644 --- a/src/apps/common/seed.py +++ b/src/apps/common/seed.py @@ -1,29 +1,16 @@ from trezor import wire +from trezor.crypto import bip32 +from trezor.crypto import bip39 -# FIXME: this is a stub +_DEFAULT_CURVE = 'secp256k1' _cached_seed = None -_cached_root_node = None -async def get_node(session_id: int, path: list): - root = await get_root_node(session_id) - node = root.clone() - node.derive_path(path) - return node - - -async def get_root_node(session_id: int): - global _cached_root_node - if _cached_root_node is None: - _cached_root_node = await compute_root_node(session_id) - return _cached_root_node - - -async def compute_root_node(session_id: int): - from trezor.crypto import bip32 +async def get_root(session_id: int, curve_name=_DEFAULT_CURVE): seed = await get_seed(session_id) - return bip32.from_seed(seed, 'secp256k1') + root = bip32.from_seed(seed, curve_name) + return root async def get_seed(session_id: int) -> bytes: @@ -33,8 +20,7 @@ async def get_seed(session_id: int) -> bytes: return _cached_seed -async def compute_seed(session_id): - from trezor.crypto import bip39 +async def compute_seed(session_id: int) -> bytes: from trezor.messages.FailureType import Other from .request_passphrase import request_passphrase from .request_pin import protect_by_pin