|
|
|
@ -16,21 +16,14 @@ class Keychain:
|
|
|
|
|
"""Cardano keychain hard-coded to Byron and Shelley seed namespaces."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, root: bip32.HDNode) -> None:
|
|
|
|
|
self.root = root
|
|
|
|
|
self.byron_root = self._create_namespace_root(seed_namespaces.BYRON)
|
|
|
|
|
self.shelley_root = self._create_namespace_root(seed_namespaces.SHELLEY)
|
|
|
|
|
self.byron_root = derive_path_cardano(root, seed_namespaces.BYRON)
|
|
|
|
|
self.shelley_root = derive_path_cardano(root, seed_namespaces.SHELLEY)
|
|
|
|
|
root.__del__()
|
|
|
|
|
|
|
|
|
|
def verify_path(self, path: Bip32Path) -> None:
|
|
|
|
|
if not is_byron_path(path) and not is_shelley_path(path):
|
|
|
|
|
raise wire.DataError("Forbidden key path")
|
|
|
|
|
|
|
|
|
|
def _create_namespace_root(self, namespace: list):
|
|
|
|
|
new_root = self.root.clone()
|
|
|
|
|
for i in namespace:
|
|
|
|
|
new_root.derive_cardano(i)
|
|
|
|
|
|
|
|
|
|
return new_root
|
|
|
|
|
|
|
|
|
|
def _get_path_root(self, path: list):
|
|
|
|
|
if is_byron_path(path):
|
|
|
|
|
return self.byron_root
|
|
|
|
@ -48,10 +41,7 @@ class Keychain:
|
|
|
|
|
suffix = node_path[len(seed_namespaces.SHELLEY) :]
|
|
|
|
|
|
|
|
|
|
# derive child node from the root
|
|
|
|
|
node = path_root.clone()
|
|
|
|
|
for i in suffix:
|
|
|
|
|
node.derive_cardano(i)
|
|
|
|
|
return node
|
|
|
|
|
return derive_path_cardano(path_root, suffix)
|
|
|
|
|
|
|
|
|
|
# XXX the root node remains in session cache so we should not delete it
|
|
|
|
|
# def __del__(self) -> None:
|
|
|
|
@ -66,6 +56,13 @@ def is_shelley_path(path: Bip32Path):
|
|
|
|
|
return path[: len(seed_namespaces.SHELLEY)] == seed_namespaces.SHELLEY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def derive_path_cardano(root: bip32.HDNode, path: Bip32Path) -> bip32.HDNode:
|
|
|
|
|
node = root.clone()
|
|
|
|
|
for i in path:
|
|
|
|
|
node.derive_cardano(i)
|
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache.stored_async(cache.APP_CARDANO_ROOT)
|
|
|
|
|
async def get_keychain(ctx: wire.Context) -> Keychain:
|
|
|
|
|
if not device.is_initialized():
|
|
|
|
|