How to use the trezor.messages.MessageType 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 / cardano / layout / __init__.py View on Github external
async def confirm_with_pagination(
    ctx, content, title: str, icon=ui.ICON_RESET, icon_color=ui.ORANGE
):
    first_page = const(0)
    lines_per_page = const(4)

    if isinstance(content, (list, tuple)):
        lines = content
    else:
        lines = list(chunks(content, 17))
    pages = list(chunks(lines, lines_per_page))

    await ctx.call(ButtonRequest(code=ButtonRequestType.Address), MessageType.ButtonAck)

    paginator = paginate(
        show_text_page, len(pages), first_page, pages, title, icon, icon_color
    )
    return await ctx.wait(paginator) == CONFIRMED
github trezor / trezor-core / src / apps / common / request_passphrase.py View on Github external
async def request_passphrase_ack(ctx, on_device):
    if not on_device:
        text = Text("Passphrase entry", ui.ICON_CONFIG)
        text.normal("Please, type passphrase", "on connected host.")
        text.render()

    req = PassphraseRequest(on_device=on_device)
    ack = await ctx.call(req, MessageType.PassphraseAck, MessageType.Cancel)
    if ack.MESSAGE_WIRE_TYPE == MessageType.Cancel:
        raise wire.ActionCancelled("Passphrase cancelled")

    if on_device:
        if ack.passphrase is not None:
            raise wire.ProcessError("Passphrase provided when it should not be")
        keyboard = PassphraseKeyboard("Enter passphrase")
        passphrase = await ctx.wait(keyboard)
        if passphrase == CANCELLED:
            raise wire.ActionCancelled("Passphrase cancelled")
    else:
        if ack.passphrase is None:
            raise wire.ProcessError("Passphrase not provided")
        passphrase = ack.passphrase

    req = PassphraseStateRequest(
github trezor / trezor-core / src / trezor / messages / __init__.py View on Github external
def get_type(wire_type):
    """Get message class for handling given wire_type."""
    if wire_type in registered:
        # message class is explicitly registered
        msg_type = registered[wire_type]
    else:
        # import message class from trezor.messages dynamically
        name = type_to_name[wire_type]
        module = __import__("trezor.messages.%s" % name, None, None, (name,), 0)
        msg_type = getattr(module, name)
    return msg_type


# build reverse table of wire types
for msg_name in dir(MessageType):
    # Modules contain internal variables that may cause exception here.
    # No Message begins with underscore so it's safe to skip those.
    if (msg_name[0] == '_'):
        continue
    type_to_name[getattr(MessageType, msg_name)] = msg_name
github trezor / trezor-firmware / core / src / apps / lisk / __init__.py View on Github external
def boot() -> None:
    ns = [[CURVE, HARDENED | 44, HARDENED | 134]]
    wire.add(MessageType.LiskGetPublicKey, __name__, "get_public_key", ns)
    wire.add(MessageType.LiskGetAddress, __name__, "get_address", ns)
    wire.add(MessageType.LiskSignTx, __name__, "sign_tx", ns)
    wire.add(MessageType.LiskSignMessage, __name__, "sign_message", ns)
    wire.add(MessageType.LiskVerifyMessage, __name__, "verify_message")
github trezor / trezor-firmware / core / src / apps / ripple / __init__.py View on Github external
def boot() -> None:
    ns = [[CURVE, HARDENED | 44, HARDENED | 144]]
    wire.add(MessageType.RippleGetAddress, __name__, "get_address", ns)
    wire.add(MessageType.RippleSignTx, __name__, "sign_tx", ns)
github trezor / trezor-firmware / core / src / apps / stellar / consts.py View on Github external
op_codes = {
    "StellarAccountMergeOp": const(8),
    "StellarAllowTrustOp": const(7),
    "StellarBumpSequenceOp": const(11),
    "StellarChangeTrustOp": const(6),
    "StellarCreateAccountOp": const(0),
    "StellarCreatePassiveOfferOp": const(4),
    "StellarManageDataOp": const(10),
    "StellarManageOfferOp": const(3),
    "StellarPathPaymentOp": const(2),
    "StellarPaymentOp": const(1),
    "StellarSetOptionsOp": const(5),
}

op_wire_types = [
    MessageType.StellarAccountMergeOp,
    MessageType.StellarAllowTrustOp,
    MessageType.StellarBumpSequenceOp,
    MessageType.StellarChangeTrustOp,
    MessageType.StellarCreateAccountOp,
    MessageType.StellarCreatePassiveOfferOp,
    MessageType.StellarManageDataOp,
    MessageType.StellarManageOfferOp,
    MessageType.StellarPathPaymentOp,
    MessageType.StellarPaymentOp,
    MessageType.StellarSetOptionsOp,
]

# https://github.com/stellar/go/blob/e0ffe19f58879d3c31e2976b97a5bf10e13a337b/xdr/xdr_generated.go#L584
ASSET_TYPE_NATIVE = const(0)
ASSET_TYPE_ALPHANUM4 = const(1)
ASSET_TYPE_ALPHANUM12 = const(2)
github trezor / trezor-core / src / apps / management / __init__.py View on Github external
def boot():
    # only enable LoadDevice in debug builds
    if __debug__:
        wire.add(MessageType.LoadDevice, __name__, "load_device")
    wire.add(MessageType.ResetDevice, __name__, "reset_device")
    wire.add(MessageType.BackupDevice, __name__, "backup_device")
    wire.add(MessageType.WipeDevice, __name__, "wipe_device")
    wire.add(MessageType.RecoveryDevice, __name__, "recovery_device")
    wire.add(MessageType.ApplySettings, __name__, "apply_settings")
    wire.add(MessageType.ApplyFlags, __name__, "apply_flags")
    wire.add(MessageType.ChangePin, __name__, "change_pin")
    wire.add(MessageType.SetU2FCounter, __name__, "set_u2f_counter")
github trezor / trezor-firmware / core / src / apps / cardano / __init__.py View on Github external
def boot() -> None:
    wire.add(MessageType.CardanoGetAddress, __name__, "get_address")
    wire.add(MessageType.CardanoGetPublicKey, __name__, "get_public_key")
    wire.add(MessageType.CardanoSignTx, __name__, "sign_tx")
github trezor / trezor-firmware / core / src / apps / binance / sign_tx.py View on Github external
tx_req,
            MessageType.BinanceCancelMsg,
            MessageType.BinanceOrderMsg,
            MessageType.BinanceTransferMsg,
        )

        msgs.append(msg)
        i += 1

    node = keychain.derive(envelope.address_n)

    msg_json = helpers.produce_json_for_signing(envelope, msgs)
    signature_bytes = generate_content_signature(msg_json.encode(), node.private_key())
    encoded_message = encode(envelope, msgs, signature_bytes, node.public_key())

    if msg.MESSAGE_WIRE_TYPE == MessageType.BinanceTransferMsg:
        for txinput in msg.inputs:
            for coin in txinput.coins:
                await layout.require_confirm_transfer(
                    ctx, txinput.address, coin.amount, coin.denom
                )
        for output in msg.outputs:
            for coin in output.coins:
                await layout.require_confirm_transfer(
                    ctx, output.address, coin.amount, coin.denom
                )
    elif msg.MESSAGE_WIRE_TYPE == MessageType.BinanceOrderMsg:
        await layout.require_confirm_order_side(ctx, msg.side)
        await layout.require_confirm_order_address(ctx, msg.sender)
        await layout.require_confirm_order_details(ctx, msg.quantity, msg.price)
    elif msg.MESSAGE_WIRE_TYPE == MessageType.BinanceCancelMsg:
        await layout.require_confirm_cancel(ctx, msg.refid)
github trezor / trezor-core / src / apps / ripple / __init__.py View on Github external
def boot():
    ns = [[CURVE, HARDENED | 44, HARDENED | 144]]
    wire.add(MessageType.RippleGetAddress, __name__, "get_address", ns)
    wire.add(MessageType.RippleSignTx, __name__, "sign_tx", ns)