1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00

src: move HashWriter to trezor.utils

This commit is contained in:
Jan Pochyla 2018-02-27 14:45:11 +01:00
parent d4038cc03a
commit a4081bab72
8 changed files with 23 additions and 23 deletions

View File

@ -1,16 +0,0 @@
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 get_digest(self, *args) -> bytes:
return self.ctx.digest(*args)

View File

@ -2,8 +2,7 @@ from ubinascii import hexlify
from trezor.crypto.hashlib import sha256 from trezor.crypto.hashlib import sha256
from trezor import ui from trezor import ui
from trezor.ui.text import TEXT_MARGIN_LEFT from trezor.ui.text import TEXT_MARGIN_LEFT
from trezor.utils import chunks, split_words from trezor.utils import chunks, split_words, HashWriter
from apps.common.hash_writer import HashWriter
from apps.wallet.sign_tx.signing import write_varint from apps.wallet.sign_tx.signing import write_varint

View File

@ -2,7 +2,7 @@
def message_digest(message): def message_digest(message):
from apps.wallet.sign_tx.signing import write_varint from apps.wallet.sign_tx.signing import write_varint
from trezor.crypto.hashlib import sha3_256 from trezor.crypto.hashlib import sha3_256
from apps.common.hash_writer import HashWriter from trezor.utils import HashWriter
h = HashWriter(sha3_256) h = HashWriter(sha3_256)
signed_message_header = 'Ethereum Signed Message:\n' signed_message_header = 'Ethereum Signed Message:\n'

View File

@ -1,7 +1,7 @@
from trezor.messages.EthereumSignTx import EthereumSignTx from trezor.messages.EthereumSignTx import EthereumSignTx
from trezor.messages.EthereumTxRequest import EthereumTxRequest from trezor.messages.EthereumTxRequest import EthereumTxRequest
from trezor.messages import FailureType from trezor.messages import FailureType
from apps.common.hash_writer import HashWriter from trezor.utils import HashWriter
from trezor.crypto import rlp from trezor.crypto import rlp
from apps.ethereum import tokens, layout from apps.ethereum import tokens, layout

View File

@ -1,12 +1,12 @@
from trezor.crypto.hashlib import sha256 from trezor.crypto.hashlib import sha256
from trezor.crypto import bip32 from trezor.crypto import bip32
from trezor.utils import HashWriter
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from trezor.messages.HDNodePathType import HDNodePathType from trezor.messages.HDNodePathType import HDNodePathType
from trezor.messages import FailureType from trezor.messages import FailureType
from apps.wallet.sign_tx.writers import * from apps.wallet.sign_tx.writers import *
from apps.common.hash_writer import *
class MultisigError(ValueError): class MultisigError(ValueError):

View File

@ -1,11 +1,11 @@
from trezor.crypto.hashlib import sha256 from trezor.crypto.hashlib import sha256
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages import InputScriptType, FailureType from trezor.messages import InputScriptType, FailureType
from trezor.utils import HashWriter
from apps.wallet.sign_tx.writers import * from apps.wallet.sign_tx.writers import *
from apps.wallet.sign_tx.scripts import output_script_p2pkh, output_script_multisig from apps.wallet.sign_tx.scripts import output_script_p2pkh, output_script_multisig
from apps.wallet.sign_tx.multisig import multisig_get_pubkeys from apps.wallet.sign_tx.multisig import multisig_get_pubkeys
from apps.common.hash_writer import HashWriter
class Bip143Error(ValueError): class Bip143Error(ValueError):

View File

@ -3,13 +3,13 @@ from micropython import const
from trezor.crypto import base58, bip32, der from trezor.crypto import base58, bip32, der
from trezor.crypto.curve import secp256k1 from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha256 from trezor.crypto.hashlib import sha256
from trezor.utils import HashWriter
from trezor.messages import OutputScriptType from trezor.messages import OutputScriptType
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
from apps.common import address_type, coins from apps.common import address_type, coins
from apps.common.hash_writer import HashWriter
from apps.wallet.sign_tx.addresses import * from apps.wallet.sign_tx.addresses import *
from apps.wallet.sign_tx.helpers import * from apps.wallet.sign_tx.helpers import *
from apps.wallet.sign_tx.scripts import * from apps.wallet.sign_tx.scripts import *

View File

@ -59,3 +59,20 @@ def format_amount(amount, decimals):
def format_ordinal(number): def format_ordinal(number):
return str(number) + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= number % 100 < 20 else number % 10, 'th') return str(number) + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= number % 100 < 20 else number % 10, 'th')
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 get_digest(self, *args) -> bytes:
return self.ctx.digest(*args)