mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-15 19:08:07 +00:00
common: HashWriter move to common
This commit is contained in:
parent
1f677306a1
commit
19ef1480d8
16
src/apps/common/hash_writer.py
Normal file
16
src/apps/common/hash_writer.py
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
class HashWriter:
|
||||
|
||||
def __init__(self, hashfunc):
|
||||
self.ctx = hashfunc()
|
||||
self.buf = bytearray(1) # used in append()
|
||||
|
||||
def extend(self, buf: bytearray):
|
||||
self.ctx.update(buf)
|
||||
|
||||
def append(self, b: int):
|
||||
self.buf[0] = b
|
||||
self.ctx.update(self.buf)
|
||||
|
||||
def getvalue(self) -> bytes:
|
||||
return self.ctx.digest()
|
@ -3,6 +3,7 @@ from trezor.messages.SignTx import SignTx
|
||||
from trezor.messages import InputScriptType, FailureType
|
||||
|
||||
from apps.wallet.sign_tx.writers import *
|
||||
from apps.common.hash_writer import HashWriter
|
||||
|
||||
|
||||
class Bip143Error(ValueError):
|
||||
|
@ -16,6 +16,7 @@ from apps.wallet.sign_tx.segwit_bip143 import *
|
||||
from apps.wallet.sign_tx.scripts import *
|
||||
from apps.wallet.sign_tx.writers import *
|
||||
from apps.wallet.sign_tx.tx_weight_calculator import *
|
||||
from apps.common.hash_writer import HashWriter
|
||||
|
||||
# the number of bip32 levels used in a wallet (chain and address)
|
||||
_BIP32_WALLET_DEPTH = const(2)
|
||||
|
@ -112,20 +112,3 @@ def get_tx_hash(w, double: bool, reverse: bool=False) -> bytes:
|
||||
if reverse:
|
||||
d = bytes(reversed(d))
|
||||
return d
|
||||
|
||||
|
||||
class HashWriter:
|
||||
|
||||
def __init__(self, hashfunc):
|
||||
self.ctx = hashfunc()
|
||||
self.buf = bytearray(1) # used in append()
|
||||
|
||||
def extend(self, buf: bytearray):
|
||||
self.ctx.update(buf)
|
||||
|
||||
def append(self, b: int):
|
||||
self.buf[0] = b
|
||||
self.ctx.update(self.buf)
|
||||
|
||||
def getvalue(self) -> bytes:
|
||||
return self.ctx.digest()
|
||||
|
Loading…
Reference in New Issue
Block a user