From 5efab07b2385768d7f78c8e950da10651d92a144 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 7 Sep 2018 19:35:57 +0200 Subject: [PATCH] cardano: remove GetPublicKey.root_hd_passphrase, style changes --- .../modtrezorcrypto/modtrezorcrypto-bip32.h | 5 ++-- src/apps/cardano/get_public_key.py | 7 +---- src/apps/cardano/sign_tx.py | 26 ++++++------------- src/trezor/messages/CardanoPublicKey.py | 3 --- tests/test_apps.cardano.get_public_key.py | 23 +++++++--------- vendor/trezor-common | 2 +- 6 files changed, 23 insertions(+), 43 deletions(-) diff --git a/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h b/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h index 5ccb08868f..663f0e441b 100644 --- a/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h +++ b/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h @@ -519,11 +519,12 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(mp_obj_t mnemonic) mp_raise_ValueError("Invalid mnemonic"); } - int res = hdnode_from_seed_cardano((const uint8_t *)"", 0, entropy, entropy_len / 8, &hdnode); + const int res = hdnode_from_seed_cardano((const uint8_t *)"", 0, entropy, entropy_len / 8, &hdnode); if (!res) { mp_raise_ValueError("Secret key generation from mnemonic is looping forever"); - }else if(res == -1){ + } else + if (res == -1) { mp_raise_ValueError("Invalid mnemonic"); } diff --git a/src/apps/cardano/get_public_key.py b/src/apps/cardano/get_public_key.py index c7a6a6d75d..813e0ac852 100644 --- a/src/apps/cardano/get_public_key.py +++ b/src/apps/cardano/get_public_key.py @@ -35,9 +35,6 @@ def _get_public_key(root_node, derivation_path: list): chain_code = hexlify(node.chain_code()).decode() xpub_key = public_key + chain_code - # In derivation scheme v2 the passphrase is not used - root_hd_passphrase = None - node_type = HDNodeType( depth=node.depth(), child_num=node.child_num(), @@ -46,6 +43,4 @@ def _get_public_key(root_node, derivation_path: list): public_key=seed.remove_ed25519_prefix(node.public_key()), ) - return CardanoPublicKey( - node=node_type, xpub=xpub_key, root_hd_passphrase=root_hd_passphrase - ) + return CardanoPublicKey(node=node_type, xpub=xpub_key) diff --git a/src/apps/cardano/sign_tx.py b/src/apps/cardano/sign_tx.py index 219e77d0b3..c0abebd59e 100644 --- a/src/apps/cardano/sign_tx.py +++ b/src/apps/cardano/sign_tx.py @@ -116,7 +116,7 @@ async def sign_tx(ctx, msg): transaction.change_coins, transaction.fee, len(tx_body), - transaction.network.get("name"), + transaction.network_name, ): raise wire.ActionCancelled("Signing cancelled") @@ -129,32 +129,22 @@ def _micro_ada_to_ada(amount: float) -> float: class Transaction: def __init__( - self, inputs: list, outputs: list, transactions: list, root_node, network + self, inputs: list, outputs: list, transactions: list, root_node, network: int ): self.inputs = inputs self.outputs = outputs self.transactions = transactions self.root_node = root_node - self.network = None - - self._set_network(network) - # attributes have to be always empty in current Cardano self.attributes = {} - - def _set_network(self, network): if network == 1: - self.network = { - "name": "Testnet", - "magic_prefix": b"\x01\x1a\x41\x70\xcb\x17\x58\x20", - } + self.network_name = "Testnet" + self.network_magic = b"\x01\x1a\x41\x70\xcb\x17\x58\x20" elif network == 2: - self.network = { - "name": "Mainnet", - "magic_prefix": b"\x01\x1a\x2d\x96\x4a\x09\x58\x20", - } + self.network_name = "Mainnet" + self.network_magic = b"\x01\x1a\x2d\x96\x4a\x09\x58\x20" else: - raise wire.ProcessError("Unknown network index " + str(network)) + raise wire.ProcessError("Unknown network index %d" % network) def _process_inputs(self): input_coins = [] @@ -224,7 +214,7 @@ class Transaction: def _build_witnesses(self, tx_aux_hash: str): witnesses = [] for index, node in enumerate(self.nodes): - message = self.network.get("magic_prefix") + tx_aux_hash + message = self.network_magic + tx_aux_hash signature = ed25519.sign_ext( node.private_key(), node.private_key_ext(), message ) diff --git a/src/trezor/messages/CardanoPublicKey.py b/src/trezor/messages/CardanoPublicKey.py index ddacc256b0..f73717c32f 100644 --- a/src/trezor/messages/CardanoPublicKey.py +++ b/src/trezor/messages/CardanoPublicKey.py @@ -10,15 +10,12 @@ class CardanoPublicKey(p.MessageType): FIELDS = { 1: ('xpub', p.UnicodeType, 0), 2: ('node', HDNodeType, 0), - 3: ('root_hd_passphrase', p.UnicodeType, 0), } def __init__( self, xpub: str = None, node: HDNodeType = None, - root_hd_passphrase: str = None, ) -> None: self.xpub = xpub self.node = node - self.root_hd_passphrase = root_hd_passphrase diff --git a/tests/test_apps.cardano.get_public_key.py b/tests/test_apps.cardano.get_public_key.py index fa1aa4ac13..4021688d11 100644 --- a/tests/test_apps.cardano.get_public_key.py +++ b/tests/test_apps.cardano.get_public_key.py @@ -17,20 +17,18 @@ class TestCardanoGetPublicKey(unittest.TestCase): [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0], ] - root_hd_passphrase = None - public_keys = [ - 'a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408', - '8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce', - '17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791', - 'b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5', + b'a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408', + b'8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce', + b'17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791', + b'b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5', ] chain_codes = [ - 'cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0', - '02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a', - '646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d', - 'fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7', + b'cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0', + b'02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a', + b'646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d', + b'fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7', ] xpub_keys = [ @@ -43,10 +41,9 @@ class TestCardanoGetPublicKey(unittest.TestCase): for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(node, derivation_path) - self.assertEqual(hexlify(key.node.public_key).decode('utf8'), public_keys[index]) - self.assertEqual(hexlify(key.node.chain_code).decode('utf8'), chain_codes[index]) + self.assertEqual(hexlify(key.node.public_key), public_keys[index]) + self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) - self.assertEqual(key.root_hd_passphrase, root_hd_passphrase) if __name__ == '__main__': diff --git a/vendor/trezor-common b/vendor/trezor-common index ab58324dc0..4e7df217d3 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit ab58324dc034328dc00cd14691d6bb86fe8ecec5 +Subproject commit 4e7df217d337c8800fc91bac61038918bf3773e4