From 83686d1be2f3973ece08604e92cab8bb3cc44bbf Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Mon, 17 Jan 2022 18:31:17 +0100 Subject: [PATCH] chore(core): Add HashContextInitable protocol class. --- core/src/apps/common/coininfo.py | 2 +- core/src/apps/common/coininfo.py.mako | 2 +- core/src/trezor/utils.py | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/src/apps/common/coininfo.py b/core/src/apps/common/coininfo.py index a752fd531..4ced81a93 100644 --- a/core/src/apps/common/coininfo.py +++ b/core/src/apps/common/coininfo.py @@ -68,7 +68,7 @@ class CoinInfo: if curve_name == "secp256k1-groestl": self.b58_hash = groestl512d_32 self.sign_hash_double = False - self.script_hash: type[utils.HashContext] = sha256_ripemd160 + self.script_hash: type[utils.HashContextInitable] = sha256_ripemd160 elif curve_name == "secp256k1-decred": self.b58_hash = blake256d_32 self.sign_hash_double = False diff --git a/core/src/apps/common/coininfo.py.mako b/core/src/apps/common/coininfo.py.mako index d18adb017..03b761f00 100644 --- a/core/src/apps/common/coininfo.py.mako +++ b/core/src/apps/common/coininfo.py.mako @@ -68,7 +68,7 @@ class CoinInfo: if curve_name == "secp256k1-groestl": self.b58_hash = groestl512d_32 self.sign_hash_double = False - self.script_hash: type[utils.HashContext] = sha256_ripemd160 + self.script_hash: type[utils.HashContextInitable] = sha256_ripemd160 elif curve_name == "secp256k1-decred": self.b58_hash = blake256d_32 self.sign_hash_double = False diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py index df091bdde..168f29de7 100644 --- a/core/src/trezor/utils.py +++ b/core/src/trezor/utils.py @@ -145,17 +145,18 @@ def chunks_intersperse(items: str, size: int, sep: str = "\n") -> Iterator[str]: if TYPE_CHECKING: class HashContext(Protocol): - def __init__( # pylint: disable=super-init-not-called - self, __data: bytes = None - ) -> None: - ... - def update(self, __buf: bytes) -> None: ... def digest(self) -> bytes: ... + class HashContextInitable(HashContext, Protocol): + def __init__( # pylint: disable=super-init-not-called + self, __data: bytes = None + ) -> None: + ... + class Writer(Protocol): def append(self, __b: int) -> None: ...