From 5728f54b78cdc09e8aa979e0bf264b9017fcadb1 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 5 Jan 2021 15:41:26 +0100 Subject: [PATCH] core: return root_fingerprint in PublicKey --- core/src/apps/bitcoin/get_public_key.py | 6 +++++- core/src/apps/common/keychain.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/apps/bitcoin/get_public_key.py b/core/src/apps/bitcoin/get_public_key.py index 9bbf7fe88..ba60b0ecb 100644 --- a/core/src/apps/bitcoin/get_public_key.py +++ b/core/src/apps/bitcoin/get_public_key.py @@ -60,4 +60,8 @@ async def get_public_key(ctx: wire.Context, msg: GetPublicKey) -> PublicKey: if msg.show_display: await layout.show_xpub(ctx, node_xpub, "XPUB", "Cancel") - return PublicKey(node=node_type, xpub=node_xpub) + return PublicKey( + node=node_type, + xpub=node_xpub, + root_fingerprint=keychain.root_fingerprint(), + ) diff --git a/core/src/apps/common/keychain.py b/core/src/apps/common/keychain.py index 835130c23..a5e1e7672 100644 --- a/core/src/apps/common/keychain.py +++ b/core/src/apps/common/keychain.py @@ -98,6 +98,7 @@ class Keychain: self.slip21_namespaces = tuple(slip21_namespaces) self._cache = LRUCache(10) + self._root_fingerprint: Optional[int] = None def __del__(self) -> None: self._cache.__del__() @@ -136,6 +137,17 @@ class Keychain: node.derive_path(path[prefix_len:]) return node + def root_fingerprint(self) -> int: + if self._root_fingerprint is None: + # derive m/0' to obtain root_fingerprint + n = self._derive_with_cache( + prefix_len=0, + path=[0 | paths.HARDENED], + new_root=lambda: bip32.from_seed(self.seed, self.curve), + ) + self._root_fingerprint = n.fingerprint() + return self._root_fingerprint + def derive(self, path: paths.Bip32Path) -> bip32.HDNode: self.verify_path(path) return self._derive_with_cache(