1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

cardano: remove GetPublicKey.root_hd_passphrase, style changes

This commit is contained in:
Pavol Rusnak 2018-09-07 19:35:57 +02:00
parent 060a8cbdfd
commit 5efab07b23
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 23 additions and 43 deletions

View File

@ -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");
}

View File

@ -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)

View File

@ -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
)

View File

@ -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

View File

@ -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__':

@ -1 +1 @@
Subproject commit ab58324dc034328dc00cd14691d6bb86fe8ecec5
Subproject commit 4e7df217d337c8800fc91bac61038918bf3773e4