Skip to content

Commit

Permalink
Regenerate with proto 3.19.6
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Sep 10, 2024
1 parent 016c3db commit bdc40aa
Show file tree
Hide file tree
Showing 27 changed files with 33 additions and 60 deletions.
2 changes: 0 additions & 2 deletions core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "embed/extmod/trezorobj.h"
#include "hdnode.h"

#include "embed/rust/rust_ui_common.h"

#include "bip32.h"
#include "bip39.h"
#include "curves.h"
Expand Down
1 change: 0 additions & 1 deletion core/src/apps/mintlayer/get_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async def get_public_key(
from trezor.ui.layouts import show_pubkey

from apps.common import paths
print("inside get pk of mintlayer")

await paths.validate_path(keychain, msg.address_n)
node = keychain.derive(msg.address_n)
Expand Down
21 changes: 3 additions & 18 deletions core/src/apps/mintlayer/sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
from trezor.crypto import hashlib

if TYPE_CHECKING:
from trezor.enums import InputScriptType
from trezor.messages import MessageSignature, MintlayerSignMessage

from apps.common.keychain import Keychain


@with_slip44_keychain(*PATTERNS, curve=CURVE, slip44_id=SLIP44_ID)
async def sign_message(msg: MintlayerSignMessage, keychain: Keychain) -> MessageSignature:
from trezor import TR, utils
from trezor.crypto.curve import bip340
from trezor.enums import InputScriptType
from trezor.messages import Success
from trezor.ui.layouts import confirm_signverify, show_success
from trezor.wire import ProcessError
from trezor.ui.layouts import confirm_signverify
from trezor.messages import MessageSignature

from apps.common import coins
from apps.common.signverify import decode_message, message_digest
from apps.common.signverify import decode_message

message = msg.message
address_n = msg.address_n
Expand All @@ -38,21 +32,12 @@ async def sign_message(msg: MintlayerSignMessage, keychain: Keychain) -> Message
chunkify=False,
)
node = keychain.derive(address_n)
pubkey = bip340.publickey(node.private_key())

msg2 = MESSAGE_MAGIC_PREFIX + message + MESSAGE_MAGIC_SUFFIX
digest = hashlib.blake2b(msg2).digest()[:32]
digest = hashlib.blake2b(digest).digest()[:32]
print(f"digest {digest}")

other_sig = bip340.sign(node.private_key(), digest)
print(f"other sig: {len(other_sig)} {other_sig}")

correct = bip340.verify(pubkey, other_sig, digest)
print(f"verify self: {correct}")

correct = bip340.verify_publickey(pubkey)
print(f"verify pk: {correct}")

return MessageSignature(signature=other_sig, address="")
return MessageSignature(signature=other_sig, address=msg.address)

1 change: 0 additions & 1 deletion core/src/apps/mintlayer/sign_tx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,5 @@ async def sign_tx(
progress.progress.report_init()
else:

print("invalid instruction", req, isinstance(req, helpers.UiConfirmTotal), isinstance(req, helpers.UiConfirm))
raise TypeError("Invalid signing instruction")

17 changes: 6 additions & 11 deletions core/src/apps/mintlayer/sign_tx/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from micropython import const
from typing import TYPE_CHECKING

from trezor import workflow
from trezor import workflow, log
from trezor.crypto.hashlib import blake2b
from trezor.crypto import mintlayer_utils
from trezor.enums import AmountUnit
Expand Down Expand Up @@ -97,12 +97,14 @@ async def signer(self) -> None:

# Check that inputs are unchanged. Serialize inputs and sign the non-segwit ones.
encoded_inputs, encoded_input_utxos = await self.step4_serialize_inputs()
print("encoded inputs", encoded_inputs)
print("encoded utxos", encoded_input_utxos)
if __debug__:
log.debug(__name__, f"encoded inputs: {encoded_inputs}")
log.debug(__name__, f"encoded utxos: {encoded_input_utxos}")

# Serialize outputs.
encoded_outputs = await self.step5_serialize_outputs()
print("encoded outputs", encoded_outputs)
if __debug__:
log.debug(__name__, f"encoded outputs: {encoded_outputs}")

# Sign segwit inputs and serialize witness data.
signatures = await self.step6_sign_inputs(encoded_inputs, encoded_input_utxos, encoded_outputs)
Expand Down Expand Up @@ -271,7 +273,6 @@ def serialize_output(self, out: MintlayerTxOutput) -> bytes:
if out.transfer:
x = out.transfer
data = mintlayer_decode_address_to_bytes(x.address)
print(f'addr: {x.address} bytes: {data}')
token_id = b'' if not x.value.token else x.value.token.token_id
encoded_out = mintlayer_utils.encode_transfer_output(x.value.amount, token_id, data)
elif out.lock_then_transfer:
Expand Down Expand Up @@ -352,29 +353,23 @@ async def step6_sign_inputs(self, encoded_inputs: List[bytes], encoded_input_utx


writer.extend(len(encoded_inputs).to_bytes(4, 'little'))
print(f'encoded inputs {encoded_inputs}')
for inp in encoded_inputs:
writer.extend(inp)

writer.extend(len(encoded_input_utxos).to_bytes(4, 'little'))
print(encoded_input_utxos)
for utxo in encoded_input_utxos:
writer.extend(utxo)

encoded_len = mintlayer_utils.encode_compact_length(len(encoded_outputs))
print(f'compact len {encoded_len}')
print(f'encoded outputs {encoded_outputs}')
writer.extend(encoded_len)
for out in encoded_outputs:
writer.extend(out)

hash = writer.get_digest()[:32]
private_key = node.private_key()
digest = blake2b(hash).digest()[:32]
print(f"hash {list(hash)}, digest {list(digest)}")

sig = bip340.sign(private_key, digest)
print("got a signature", sig)
sigs.append((sig, multisig_idx))
signatures.append(sigs)

Expand Down
9 changes: 3 additions & 6 deletions core/src/apps/workflow_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _find_message_handler_module(msg_type: int) -> str:
- collecting everything as strings instead of importing directly means that we don't
need to load any of the modules into memory until we actually need them
"""
from trezor import utils
from trezor import utils, log
from trezor.enums import MessageType

# debug
Expand Down Expand Up @@ -204,29 +204,26 @@ def _find_message_handler_module(msg_type: int) -> str:
if msg_type == MessageType.MintlayerGetAddress:
return "apps.mintlayer.get_address"
if msg_type == MessageType.MintlayerGetPublicKey:
print("returning app mintlayer get public key")
return "apps.mintlayer.get_public_key"
if msg_type == MessageType.MintlayerSignMessage:
return "apps.mintlayer.sign_message"
if msg_type == MessageType.MintlayerSignTx:
return "apps.mintlayer.sign_tx"

print(f"msg type not found {msg_type}, {MessageType.MintlayerGetPublicKey}")
if __debug__:
log.debug(__name__, f"msg type not found {msg_type}, {MessageType.MintlayerGetPublicKey}")
raise ValueError


def find_registered_handler(iface: WireInterface, msg_type: int) -> Handler | None:
if msg_type in workflow_handlers:
print("in workflow handlers")
# Message has a handler available, return it directly.
return workflow_handlers[msg_type]

try:
print("not in workflow handlers")
modname = _find_message_handler_module(msg_type)
handler_name = modname[modname.rfind(".") + 1 :]
module = __import__(modname, None, None, (handler_name,), 0)
return getattr(module, handler_name)
except ValueError:
print("error??")
return None
2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_common.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_crypto.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_debug.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_eos.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_monero.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_nem.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_ripple.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_solana.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/trezor-client/src/protos/generated/messages_tezos.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bdc40aa

Please sign in to comment.