Skip to content

Commit

Permalink
add Mintlayer chain type to proto messages
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Feb 9, 2025
1 parent 9ce2cfa commit 4c5d084
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 414 deletions.
28 changes: 19 additions & 9 deletions common/protob/messages-mintlayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ package hw.trezor.messages.mintlayer;
option java_package = "com.satoshilabs.trezor.lib.protobuf";
option java_outer_classname = "TrezorMessageMintlayer";

/**
* Chain Type used to determine the coin name and bech32 prefixes
*/
enum MintlayerChainType {
Mainnet = 1;
Testnet = 2;
Regtest = 3;
Signet = 4;
}

/**
* Request: Ask the device for a Mintlayer address.
* @start
* @next MintlayerAddress
* @next Failure
*/
message MintlayerGetAddress {
repeated uint32 address_n = 1; // BIP-32-style path to derive the key from master node
required string coin_name = 2; // Coin to use Testnet or Mainnet
optional bool show_display = 3; // optionally prompt for confirmation on trezor display
optional bool chunkify = 4; // display the address in chunks of 4 characters
repeated uint32 address_n = 1; // BIP-32-style path to derive the key from master node
required MintlayerChainType chain_type = 2; // Chain type to use
optional bool show_display = 3; // optionally prompt for confirmation on trezor display
optional bool chunkify = 4; // display the address in chunks of 4 characters
}

/**
Expand All @@ -32,9 +42,9 @@ message MintlayerAddress {
* @next MintlayerPublicKey
*/
message MintlayerGetPublicKey {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required string coin_name = 2; // Coin to use Testnet or Mainnet
optional bool show_display = 3; // optionally show on display before sending the result
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required MintlayerChainType chain_type = 2; // Chain type to use
optional bool show_display = 3; // optionally show on display before sending the result
}

/**
Expand Down Expand Up @@ -62,7 +72,7 @@ enum MintlayerAddressType {
*/
message MintlayerSignMessage {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required string coin_name = 2; // Coin to use Testnet or Mainnet
required MintlayerChainType chain_type = 2; // Chain type to use
required MintlayerAddressType address_type = 3; // destination address in bech32 encoding
required bytes message = 4; // message to sign
}
Expand All @@ -76,7 +86,7 @@ message MintlayerSignMessage {
message MintlayerSignTx {
required uint32 outputs_count = 1; // number of transaction outputs
required uint32 inputs_count = 2; // number of transaction inputs
required string coin_name = 3; // Coin to use Testnet or Mainnet
required MintlayerChainType chain_type = 3; // Chain type to use
optional uint32 version = 4 [default=1]; // transaction version
optional bool serialize = 5 [default=true]; // serialize the full transaction, as opposed to only outputting the signatures
optional bool chunkify = 6; // display the address in chunks of 4 characters
Expand Down
2 changes: 2 additions & 0 deletions core/src/all_modules.py

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

32 changes: 26 additions & 6 deletions core/src/apps/mintlayer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from trezor.enums import MintlayerChainType

from apps.common.coininfo import CoinInfo
from apps.common.paths import PATTERN_BIP44, PATTERN_BIP44_PUBKEY

Expand Down Expand Up @@ -109,15 +111,33 @@ def __init__(
),
)

SIGNET_COIN = MLCoinInfo(
slip44_id=1,
coin_name="signet",
coin_shortcut="TML",
decimals=11,
prefixes=Prefixes(
public_key_hash="smt",
public_key="spmt",
token="smltk",
delegation="sdelg",
pool="spool",
order="sordr",
),
)

def find_coin_by_name(name: str) -> MLCoinInfo:
if name == TESTNET_COIN.coin_name:
return TESTNET_COIN

if name == MAINNET_COIN.coin_name:
def find_coin_by_chain_type(chain_type: MintlayerChainType) -> MLCoinInfo:
if chain_type == MintlayerChainType.Mainnet:
return MAINNET_COIN

if name == REGTEST_COIN.coin_name:
if chain_type == MintlayerChainType.Testnet:
return TESTNET_COIN

if chain_type == MintlayerChainType.Regtest:
return REGTEST_COIN

raise ValueError(f"unknown coin type {name}")
if chain_type == MintlayerChainType.Signet:
return SIGNET_COIN

raise ValueError(f"unknown coin type {chain_type}")
4 changes: 2 additions & 2 deletions core/src/apps/mintlayer/get_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from apps.common.keychain import with_slip44_keychain

from ..bitcoin.keychain import validate_path_against_script_type
from . import CURVE, PATTERNS, SLIP44_ID, find_coin_by_name
from . import CURVE, PATTERNS, SLIP44_ID, find_coin_by_chain_type

if TYPE_CHECKING:
from trezor.messages import MintlayerAddress, MintlayerGetAddress
Expand All @@ -22,7 +22,7 @@ async def get_address(msg: MintlayerGetAddress, keychain: Keychain) -> Mintlayer

from apps.common import paths

coin_info = find_coin_by_name(msg.coin_name)
coin_info = find_coin_by_chain_type(msg.chain_type)
address_n = msg.address_n # local_cache_attribute

await paths.validate_path(
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/mintlayer/get_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from apps.common.keychain import with_slip44_keychain

from . import CURVE, PATTERNS, SLIP44_ID, find_coin_by_name
from . import CURVE, PATTERNS, SLIP44_ID, find_coin_by_chain_type

if TYPE_CHECKING:
from trezor.messages import MintlayerGetPublicKey, MintlayerPublicKey
Expand All @@ -21,7 +21,7 @@ async def get_public_key(

from apps.common import paths

coin_info = find_coin_by_name(msg.coin_name)
coin_info = find_coin_by_chain_type(msg.chain_type)
await paths.validate_path(
keychain,
msg.address_n,
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/mintlayer/sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from apps.common.keychain import with_slip44_keychain

from . import CURVE, PATTERNS, SLIP44_ID, find_coin_by_name
from . import CURVE, PATTERNS, SLIP44_ID, find_coin_by_chain_type

if TYPE_CHECKING:
from trezor.messages import MessageSignature, MintlayerSignMessage
Expand All @@ -25,7 +25,7 @@ async def sign_message(
from apps.common import paths
from apps.common.signverify import decode_message

coin_info = find_coin_by_name(msg.coin_name)
coin_info = find_coin_by_chain_type(msg.chain_type)
message = msg.message
address_n = msg.address_n
MESSAGE_MAGIC_PREFIX = b"===MINTLAYER MESSAGE BEGIN===\n"
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/mintlayer/sign_tx/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from trezor.wire.errors import DataError

from .. import find_coin_by_name
from .. import find_coin_by_chain_type
from . import helpers
from .helpers import mintlayer_decode
from .progress import Progress
Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(
from trezor.messages import MintlayerTxRequest, MintlayerTxRequestDetailsType

self.progress = Progress()
self.coininfo = find_coin_by_name(tx.coin_name)
self.coininfo = find_coin_by_chain_type(tx.chain_type)
self.tx_info = TxInfo(tx=tx, inputs=[], outputs=[])
self.keychain = keychain

Expand Down
8 changes: 8 additions & 0 deletions core/src/trezor/enums/MintlayerChainType.py

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

6 changes: 6 additions & 0 deletions core/src/trezor/enums/__init__.py

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

17 changes: 9 additions & 8 deletions core/src/trezor/messages.py

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

Loading

0 comments on commit 4c5d084

Please sign in to comment.