How to use the trezor.utils function in trezor

To help you get started, we’ve selected a few trezor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trezor / trezor-core / src / apps / monero / protocol / signing / step_05_all_inputs_set.py View on Github external
state.assrt(
            crypto.sc_eq(state.sumout, state.sumpouts_alphas), "Invalid masks sum"
        )  # sum check
    state.sumout = crypto.sc_init(0)

    rsig_data = MoneroTransactionRsigData()
    resp = MoneroTransactionAllInputsSetAck(rsig_data=rsig_data)

    # If range proofs are being offloaded, we send the masks to the host, which uses them
    # to create the range proof. If not, we do not send any and we use them in the following step.
    if state.rsig_offload:
        tmp_buff = bytearray(32)
        rsig_data.mask = bytearray(32 * state.output_count)
        for i in range(state.output_count):
            crypto.encodeint_into(tmp_buff, state.output_masks[i])
            utils.memcpy(rsig_data.mask, 32 * i, tmp_buff, 0, 32)

    return resp
github trezor / trezor-firmware / core / src / apps / monero / signing / offloading_keys.py View on Github external
def _build_key(
    secret, discriminator=None, index: int = None, out: bytes = None
) -> bytes:
    """
    Creates an unique-purpose key
    """
    key_buff = BUILD_KEY_BUFFER  # bytearray(32 + 12 + 4)  # key + disc + index
    utils.ensure(len(secret) == 32, "Invalid key length")
    utils.ensure(len(discriminator) <= 12, "Disc too long")

    offset = 32
    utils.memcpy(key_buff, 0, secret, 0, 32)

    for i in range(32, len(key_buff)):
        key_buff[i] = 0

    if discriminator is not None:
        utils.memcpy(key_buff, offset, discriminator, 0, len(discriminator))
        offset += len(discriminator)

    if index is not None:
        # dump_uvarint_b_into, saving import
        shifted = True
        while shifted:
            shifted = index >> 7
            key_buff[offset] = (index & 0x7F) | (0x80 if shifted else 0x00)
            offset += 1
            index = shifted
github trezor / trezor-core / src / apps / stellar / layout.py View on Github external
def format_amount(amount: int, ticker=True) -> str:
    t = ""
    if ticker:
        t = " XLM"
    return utils.format_amount(amount, consts.AMOUNT_DIVISIBILITY) + t
github trezor / trezor-firmware / core / src / main.py View on Github external
import apps.stellar
        import apps.ripple
        import apps.cardano
        import apps.tezos
        import apps.eos
        import apps.binance
        import apps.webauthn

    if __debug__:
        import apps.debug

    # boot applications
    apps.homescreen.boot()
    apps.management.boot()
    apps.wallet.boot()
    if not utils.BITCOIN_ONLY:
        apps.ethereum.boot()
        apps.lisk.boot()
        apps.monero.boot()
        apps.nem.boot()
        apps.stellar.boot()
        apps.ripple.boot()
        apps.cardano.boot()
        apps.tezos.boot()
        apps.eos.boot()
        apps.binance.boot()
        apps.webauthn.boot()
    if __debug__:
        apps.debug.boot()

    # run main event loop and specify which screen is the default
    if storage.recovery.is_in_progress():
github trezor / trezor-firmware / core / src / apps / monero / layout / common.py View on Github external
def split_address(address):
    return utils.chunks(address, 16)
github trezor / trezor-firmware / core / src / apps / homescreen / __init__.py View on Github external
def get_features() -> Features:
    f = Features()
    f.vendor = "trezor.io"
    f.language = "english"
    f.major_version = utils.VERSION_MAJOR
    f.minor_version = utils.VERSION_MINOR
    f.patch_version = utils.VERSION_PATCH
    f.revision = utils.GITREV
    f.model = utils.MODEL
    f.device_id = storage.device.get_device_id()
    f.label = storage.device.get_label()
    f.initialized = storage.is_initialized()
    f.pin_protection = config.has_pin()
    f.pin_cached = config.has_pin()
    f.passphrase_protection = storage.device.has_passphrase()
    f.passphrase_cached = cache.has_passphrase()
    f.needs_backup = storage.device.needs_backup()
    f.unfinished_backup = storage.device.unfinished_backup()
    f.no_backup = storage.device.no_backup()
    f.flags = storage.device.get_flags()
    f.recovery_mode = storage.recovery.is_in_progress()
github trezor / trezor-firmware / core / src / apps / monero / signing / step_09_sign_input.py View on Github external
:return: Generated signature MGs[i]
    """
    await confirms.transaction_step(
        state, state.STEP_SIGN, state.current_input_index + 1
    )

    state.current_input_index += 1
    if state.current_input_index >= state.input_count:
        raise ValueError("Invalid inputs count")
    if pseudo_out is None:
        raise ValueError("SimpleRCT requires pseudo_out but none provided")
    if pseudo_out_alpha_enc is None:
        raise ValueError("SimpleRCT requires pseudo_out's mask but none provided")

    input_position = state.source_permutation[state.current_input_index]
    mods = utils.unimport_begin()

    # Check input's HMAC
    from apps.monero.signing import offloading_keys

    vini_hmac_comp = await offloading_keys.gen_hmac_vini(
        state.key_hmac, src_entr, vini_bin, input_position
    )
    if not crypto.ct_equals(vini_hmac_comp, vini_hmac):
        raise ValueError("HMAC is not correct")

    gc.collect()
    state.mem_trace(1, True)

    from apps.monero.xmr.crypto import chacha_poly

    pseudo_out_alpha = crypto.decodeint(
github trezor / trezor-firmware / core / src / usb.py View on Github external
from storage.device import get_device_id
from trezor import io, utils

# interface used for trezor wire protocol
iface_wire = io.WebUSB(iface_num=0, ep_in=0x81, ep_out=0x01)

if __debug__:
    # interface used for debug messages with trezor wire protocol
    iface_debug = io.WebUSB(iface_num=1, ep_in=0x82, ep_out=0x02)

if not utils.BITCOIN_ONLY:
    # interface used for FIDO/U2F and FIDO2/WebAuthn HID transport
    iface_webauthn = io.HID(
        iface_num=2 if __debug__ else 1,
        ep_in=0x83 if __debug__ else 0x82,
        ep_out=0x03 if __debug__ else 0x02,
        # fmt: off
        report_desc=bytes([
            0x06, 0xd0, 0xf1,  # USAGE_PAGE (FIDO Alliance)
            0x09, 0x01,        # USAGE (U2F HID Authenticator Device)
            0xa1, 0x01,        # COLLECTION (Application)
            0x09, 0x20,        # USAGE (Input Report Data)
            0x15, 0x00,        # LOGICAL_MINIMUM (0)
            0x26, 0xff, 0x00,  # LOGICAL_MAXIMUM (255)
            0x75, 0x08,        # REPORT_SIZE (8)
            0x95, 0x40,        # REPORT_COUNT (64)
            0x81, 0x02,        # INPUT (Data,Var,Abs)
github trezor / trezor-firmware / core / src / trezor / messages / Capability.py View on Github external
# Automatically generated by pb2py
# fmt: off
from trezor import utils

if False:
    from typing_extensions import Literal

Bitcoin = 1  # type: Literal[1]
if not utils.BITCOIN_ONLY:
    Bitcoin_like = 2  # type: Literal[2]
    Binance = 3  # type: Literal[3]
    Cardano = 4  # type: Literal[4]
Crypto = 5  # type: Literal[5]
if not utils.BITCOIN_ONLY:
    EOS = 6  # type: Literal[6]
    Ethereum = 7  # type: Literal[7]
    Lisk = 8  # type: Literal[8]
    Monero = 9  # type: Literal[9]
    NEM = 10  # type: Literal[10]
    Ripple = 11  # type: Literal[11]
    Stellar = 12  # type: Literal[12]
    Tezos = 13  # type: Literal[13]
    U2F = 14  # type: Literal[14]
Shamir = 15  # type: Literal[15]
ShamirGroups = 16  # type: Literal[16]
github trezor / trezor-firmware / core / src / trezor / messages / Capability.py View on Github external
# Automatically generated by pb2py
# fmt: off
from trezor import utils

if False:
    from typing_extensions import Literal

Bitcoin = 1  # type: Literal[1]
if not utils.BITCOIN_ONLY:
    Bitcoin_like = 2  # type: Literal[2]
    Binance = 3  # type: Literal[3]
    Cardano = 4  # type: Literal[4]
Crypto = 5  # type: Literal[5]
if not utils.BITCOIN_ONLY:
    EOS = 6  # type: Literal[6]
    Ethereum = 7  # type: Literal[7]
    Lisk = 8  # type: Literal[8]
    Monero = 9  # type: Literal[9]
    NEM = 10  # type: Literal[10]
    Ripple = 11  # type: Literal[11]
    Stellar = 12  # type: Literal[12]
    Tezos = 13  # type: Literal[13]
    U2F = 14  # type: Literal[14]
Shamir = 15  # type: Literal[15]
ShamirGroups = 16  # type: Literal[16]