Skip to content

Commit

Permalink
fix(cardano): Return pubkey
Browse files Browse the repository at this point in the history
This ends up being useful for software wallets.
  • Loading branch information
jaskp committed Feb 27, 2024
1 parent e22653a commit 8ceefbf
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 44 deletions.
5 changes: 3 additions & 2 deletions common/protob/messages-cardano.proto
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ message CardanoMessageItemHostAck {
* @end
*/
message CardanoSignMessageFinished {
required bytes signature = 1;
required bytes address = 2;
required bytes signature = 1; // signature for structure containing payload and protected headers
required bytes address = 2; // value of the address field in protected headers
required bytes pub_key = 3; // public key given by signing path
}
34 changes: 22 additions & 12 deletions common/tests/fixtures/cardano/sign_message.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"result": {
"signature": "5ad6ba670e65353b2c1ad4053a1ed4a9348a73fe965ffa0afafa24bad06e3eb3e325d49029604c09bf665c3c43a750ec81a43b1f8b746b07e999b913b980d006",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -34,7 +35,8 @@
},
"result": {
"signature": "9efaff0b74c0beb2cadd727d8bafe13b31107235c5fc46c6c33e596e024d391c9fbe37072e43965add6ee0a4788562382031486b74fd59d636aa1ca3b1ddfe06",
"address": "0180f9e2c88e6c817008f3a812ed889b4a4da8e0bd103f86e7335422aa122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277"
"address": "0180f9e2c88e6c817008f3a812ed889b4a4da8e0bd103f86e7335422aa122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -47,10 +49,11 @@
},
"result": {
"signature": "2c325e542fa78d76d916e50f50b85e770354a44e071f08fdb8ec5d0bcbf844cf70dcf5c87b7a51cd7f0269a59eec8d438c3c27eb42b971e7ccb7f864714c4b06",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
{
"description": "Sign short ASCII payload",
"parameters": {
"signing_path": "m/1852'/1815'/4'/0/0",
Expand All @@ -60,10 +63,11 @@
},
"result": {
"signature": "2201b8e7fa9ea919935e06ecc3e845433855066acaaf61cb8e624a2eb7139b73a9d126e7ee04548fff06ac933bd5419fc78c5aebee9b536cbee1481b52ec3e03",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
{
"description": "Sign short ASCII payload rendered as hex",
"parameters": {
"signing_path": "m/1852'/1815'/4'/0/0",
Expand All @@ -73,7 +77,8 @@
},
"result": {
"signature": "2201b8e7fa9ea919935e06ecc3e845433855066acaaf61cb8e624a2eb7139b73a9d126e7ee04548fff06ac933bd5419fc78c5aebee9b536cbee1481b52ec3e03",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -86,7 +91,8 @@
},
"result": {
"signature": "b09177a06cb2deba7ada89fec96fc4380e746f67c6b16a9ef9ae6b7cbbe941fdad8a8a573b809cd88db296b91b476c436033a29d86a63959e270047e47cd5d0d",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -99,7 +105,8 @@
},
"result": {
"signature": "a2503039a8ec620e05d9e4345339d61cd11480fbfcc75ea1a10789751a7c5f46ba06786eb1719da62db76c20313ad3445839b8117abac206cc4bd63ea623fc07",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -112,7 +119,8 @@
},
"result": {
"signature": "92331e75bb4c3208317ac422f2fc9d8b9b09d3f81cc487edaa7028d262553e5691532fb166a40e45eb2e4addd4280ff7e07bd4249e964d969e91555317b05f08",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -127,7 +135,8 @@
},
"result": {
"signature": "eb7e48bb2de912b24ea4e295cfbf338e95e2a2d9c5eb41d72ddd8ebf96ca6128696e91e65e20a755821781b8ea0b4aa7ffcfa6ab0c7da2c67ecaf33fcd596509",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
},
{
Expand All @@ -142,7 +151,8 @@
},
"result": {
"signature": "1cd79c511e58e0d00bc402c24631a982c0f596e13cad38447d4f31213d085b23b9990b45023450f5ab4d47987993af662702b07bfc8195feb80b2c9e1c1dc10f",
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba"
"address": "d9553a4de9c7ad8532abdb1d0a7f425b8007d25c9f1edcf0b5f5c3ba",
"pub_key": "67e3d14e1e0db2a6ff68832994451f63d3e92a4ee85c3681d72634ccfe889f2c"
}
}
]
Expand Down
7 changes: 6 additions & 1 deletion core/src/apps/cardano/sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from apps.cardano.helpers.chunks import MAX_CHUNK_SIZE, ChunkIterator
from apps.cardano.helpers.credential import Credential
from apps.cardano.helpers.paths import SCHEMA_MINT, SCHEMA_PUBKEY
from apps.cardano.helpers.utils import derive_public_key
from apps.common import cbor

from . import addresses, seed
Expand Down Expand Up @@ -182,4 +183,8 @@ async def sign_message(
_cborize_sig_structure(payload=payload, protected_headers=headers),
)

return CardanoSignMessageFinished(signature=signature, address=address)
return CardanoSignMessageFinished(
signature=signature,
address=address,
pub_key=derive_public_key(keychain, msg.signing_path),
)
2 changes: 2 additions & 0 deletions core/src/trezor/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,12 +1924,14 @@ def is_type_of(cls, msg: Any) -> TypeGuard["CardanoMessageItemHostAck"]:
class CardanoSignMessageFinished(protobuf.MessageType):
signature: "bytes"
address: "bytes"
pub_key: "bytes"

def __init__(
self,
*,
signature: "bytes",
address: "bytes",
pub_key: "bytes",
) -> None:
pass

Expand Down
3 changes: 3 additions & 0 deletions python/src/trezorlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2983,16 +2983,19 @@ class CardanoSignMessageFinished(protobuf.MessageType):
FIELDS = {
1: protobuf.Field("signature", "bytes", repeated=False, required=True),
2: protobuf.Field("address", "bytes", repeated=False, required=True),
3: protobuf.Field("pub_key", "bytes", repeated=False, required=True),
}

def __init__(
self,
*,
signature: "bytes",
address: "bytes",
pub_key: "bytes",
) -> None:
self.signature = signature
self.address = address
self.pub_key = pub_key


class CipherKeyValue(protobuf.MessageType):
Expand Down
116 changes: 87 additions & 29 deletions rust/trezor-client/src/protos/generated/messages_cardano.rs

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

1 change: 1 addition & 0 deletions tests/device_tests/cardano/test_sign_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def _transform_expected_result(result: dict) -> messages.CardanoSignMessageFinis
return messages.CardanoSignMessageFinished(
signature=bytes.fromhex(result["signature"]),
address=bytes.fromhex(result["address"]),
pub_key=bytes.fromhex(result["pub_key"]),
)

0 comments on commit 8ceefbf

Please sign in to comment.