Skip to content

Commit

Permalink
fixup! core: refactor keychain to only support one curve at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
matejcik committed Jul 24, 2020
1 parent 6a55bf6 commit 7289d84
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions core/src/apps/common/keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@ def __init__(
curve: str,
namespaces: Sequence[paths.Bip32Path],
slip21_namespaces: Sequence[paths.Slip21Path] = (),
restrict: bool = True,
) -> None:
# if `restrict` is False, namespaces will not be checked
self.seed = seed
self.curve = curve
self.namespaces = namespaces
self.slip21_namespaces = slip21_namespaces
self.restrict = restrict

self._cache = LRUCache(10)

Expand All @@ -108,7 +105,7 @@ def verify_path(self, path: paths.Bip32Path) -> None:
if "ed25519" in self.curve and not paths.path_is_hardened(path):
raise wire.DataError("Non-hardened paths unsupported on Ed25519")

if not self.restrict:
if device.unsafe_prompts_allowed():
return

if any(ns == path[: len(ns)] for ns in self.namespaces):
Expand Down Expand Up @@ -139,7 +136,7 @@ def derive(self, path: paths.Bip32Path) -> bip32.HDNode:
)

def derive_slip21(self, path: paths.Slip21Path) -> Slip21Node:
if self.restrict and not any(
if not device.unsafe_prompts_allowed() and not any(
ns == path[: len(ns)] for ns in self.slip21_namespaces
):
raise FORBIDDEN_KEY_PATH
Expand All @@ -162,13 +159,7 @@ async def get_keychain(
slip21_namespaces: Sequence[paths.Slip21Path] = (),
) -> Keychain:
seed = await get_seed(ctx)
keychain = Keychain(
seed,
curve,
namespaces,
slip21_namespaces,
restrict=not device.unsafe_prompts_allowed(),
)
keychain = Keychain(seed, curve, namespaces, slip21_namespaces)
return keychain


Expand Down

0 comments on commit 7289d84

Please sign in to comment.