Skip to content

Commit 0f4d0cf

Browse files
committed
feat(core): add TestNet support for Cardano sign-message
1 parent 636274c commit 0f4d0cf

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

common/protob/messages-cardano.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ message CardanoSignMessage {
536536
required CardanoDerivationType derivation_type = 3;
537537
required uint32 network_id = 4; // network id - mainnet or testnet
538538
optional CardanoAddressType address_type = 5; // one of the CardanoAddressType
539+
optional uint32 protocol_magic = 6; // network's protocol magic - needed for Byron addresses on testnets
540+
539541
}
540542

541543
/**

core/src/apps/cardano/sign_message.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from . import seed
1010
from .addresses import assert_params_cond
11-
from .helpers.paths import SCHEMA_STAKING_ANY_ACCOUNT
1211

1312
if TYPE_CHECKING:
1413
from trezor.wire import Context
@@ -22,7 +21,8 @@ async def sign_message(
2221
from trezor.messages import CardanoMessageSignature, CardanoAddressParametersType
2322
from trezor.enums import CardanoAddressType
2423
from apps.common import paths
25-
from .helpers.paths import SCHEMA_MINT, SCHEMA_PAYMENT
24+
from .helpers.paths import SCHEMA_PAYMENT, SCHEMA_STAKING_ANY_ACCOUNT
25+
2626
from trezor.crypto.curve import ed25519
2727
from trezor import wire
2828
from .helpers import network_ids, protocol_magics
@@ -38,10 +38,10 @@ async def sign_message(
3838
msg.address_n,
3939
True,
4040
# path must match the PUBKEY schema
41-
(SCHEMA_PAYMENT.match(msg.address_n) or SCHEMA_MINT.match(msg.address_n)),
41+
SCHEMA_PAYMENT.match(msg.address_n),
4242
)
43-
if msg.network_id != network_ids.MAINNET:
44-
raise wire.ProcessError("Invalid Networ ID")
43+
if msg.protocol_magic is None and (msg.network_id != network_ids.MAINNET):
44+
raise wire.ProcessError("Invalid Network id, need protocol magic provide")
4545

4646
address_type = msg.address_type if msg.address_type else CardanoAddressType.BASE
4747
address_n = msg.address_n
@@ -70,7 +70,7 @@ async def sign_message(
7070
script_payment_hash=None,
7171
script_staking_hash=None,
7272
),
73-
protocol_magics.MAINNET,
73+
protocol_magics.MAINNET if msg.protocol_magic is None else msg.protocol_magic,
7474
msg.network_id,
7575
)
7676
address = addresses.encode_human_readable(address_bytes)

core/src/trezor/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,6 +2431,7 @@ class CardanoSignMessage(protobuf.MessageType):
24312431
derivation_type: "CardanoDerivationType"
24322432
network_id: "int"
24332433
address_type: "CardanoAddressType | None"
2434+
protocol_magic: "int | None"
24342435

24352436
def __init__(
24362437
self,
@@ -2440,6 +2441,7 @@ def __init__(
24402441
network_id: "int",
24412442
address_n: "list[int] | None" = None,
24422443
address_type: "CardanoAddressType | None" = None,
2444+
protocol_magic: "int | None" = None,
24432445
) -> None:
24442446
pass
24452447

0 commit comments

Comments
 (0)