From 34cb96db4a31bc2431827a03e9fb2a3b15d88f16 Mon Sep 17 00:00:00 2001 From: Tomas Krnak Date: Fri, 18 Nov 2022 12:48:29 +0700 Subject: [PATCH] fixup! feat(core): add Zcash shielded transactions --- core/src/apps/zcash/orchard/crypto/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/apps/zcash/orchard/crypto/utils.py b/core/src/apps/zcash/orchard/crypto/utils.py index 92eddea77e..2d79deed43 100644 --- a/core/src/apps/zcash/orchard/crypto/utils.py +++ b/core/src/apps/zcash/orchard/crypto/utils.py @@ -1,8 +1,12 @@ -from typing import Iterable +from typing import TYPE_CHECKING from trezor.crypto.hashlib import blake2b from trezor.crypto.pallas import Fp, Scalar +if TYPE_CHECKING: + from typing import TypeVar, Iterable, Iterator + A = TypeVar("A") + def xor(a: bytes, b: bytes) -> bytes: return bytes(x ^ y for x, y in zip(a, b)) @@ -22,7 +26,7 @@ def cldiv(n, divisor): # integer to little-endian bits -def i2lebsp(l: int, x: Fp | Scalar | int) -> Iterable[int]: +def i2lebsp(l: int, x: Fp | Scalar | int) -> Iterator[int]: if isinstance(x, Fp) or isinstance(x, Scalar): gen = leos2bsp(x.to_bytes()) for _ in range(l): @@ -49,15 +53,15 @@ def lebs2ip(bits: Iterable[int]) -> int: return acc -# little-endian bytes to little endian- bits -def leos2bsp(buf): +# little-endian bytes to little-endian bits +def leos2bsp(buf: bytes) -> Iterator[int]: for byte in buf: for i in range(8): yield (byte >> i) & 1 return -def take(i, gen): +def take(i: int, gen: Iterator[A] | list[A]) -> Iterator[A]: """Creates a new generator, which returns `i` elements of the original generator.""" if isinstance(gen, list): @@ -67,7 +71,7 @@ def take(i, gen): return -def chain(gen_a, gen_b): +def chain(gen_a: Iterable[A], gen_b: Iterable[A]) -> Iterable[A]: """Chains two generators into one.""" yield from gen_a yield from gen_b