1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-22 12:32:02 +00:00

fixup! feat(core): add Zcash shielded transactions

This commit is contained in:
Tomas Krnak 2022-11-18 12:48:29 +07:00
parent ca89b1e645
commit 34cb96db4a

View File

@ -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