mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
cardano: remove GetPublicKey.root_hd_passphrase, style changes
This commit is contained in:
parent
060a8cbdfd
commit
5efab07b23
@ -519,11 +519,12 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(mp_obj_t mnemonic)
|
|||||||
mp_raise_ValueError("Invalid 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) {
|
if (!res) {
|
||||||
mp_raise_ValueError("Secret key generation from mnemonic is looping forever");
|
mp_raise_ValueError("Secret key generation from mnemonic is looping forever");
|
||||||
}else if(res == -1){
|
} else
|
||||||
|
if (res == -1) {
|
||||||
mp_raise_ValueError("Invalid mnemonic");
|
mp_raise_ValueError("Invalid mnemonic");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +35,6 @@ def _get_public_key(root_node, derivation_path: list):
|
|||||||
chain_code = hexlify(node.chain_code()).decode()
|
chain_code = hexlify(node.chain_code()).decode()
|
||||||
xpub_key = public_key + chain_code
|
xpub_key = public_key + chain_code
|
||||||
|
|
||||||
# In derivation scheme v2 the passphrase is not used
|
|
||||||
root_hd_passphrase = None
|
|
||||||
|
|
||||||
node_type = HDNodeType(
|
node_type = HDNodeType(
|
||||||
depth=node.depth(),
|
depth=node.depth(),
|
||||||
child_num=node.child_num(),
|
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()),
|
public_key=seed.remove_ed25519_prefix(node.public_key()),
|
||||||
)
|
)
|
||||||
|
|
||||||
return CardanoPublicKey(
|
return CardanoPublicKey(node=node_type, xpub=xpub_key)
|
||||||
node=node_type, xpub=xpub_key, root_hd_passphrase=root_hd_passphrase
|
|
||||||
)
|
|
||||||
|
@ -116,7 +116,7 @@ async def sign_tx(ctx, msg):
|
|||||||
transaction.change_coins,
|
transaction.change_coins,
|
||||||
transaction.fee,
|
transaction.fee,
|
||||||
len(tx_body),
|
len(tx_body),
|
||||||
transaction.network.get("name"),
|
transaction.network_name,
|
||||||
):
|
):
|
||||||
raise wire.ActionCancelled("Signing cancelled")
|
raise wire.ActionCancelled("Signing cancelled")
|
||||||
|
|
||||||
@ -129,32 +129,22 @@ def _micro_ada_to_ada(amount: float) -> float:
|
|||||||
|
|
||||||
class Transaction:
|
class Transaction:
|
||||||
def __init__(
|
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.inputs = inputs
|
||||||
self.outputs = outputs
|
self.outputs = outputs
|
||||||
self.transactions = transactions
|
self.transactions = transactions
|
||||||
self.root_node = root_node
|
self.root_node = root_node
|
||||||
self.network = None
|
|
||||||
|
|
||||||
self._set_network(network)
|
|
||||||
|
|
||||||
# attributes have to be always empty in current Cardano
|
# attributes have to be always empty in current Cardano
|
||||||
self.attributes = {}
|
self.attributes = {}
|
||||||
|
|
||||||
def _set_network(self, network):
|
|
||||||
if network == 1:
|
if network == 1:
|
||||||
self.network = {
|
self.network_name = "Testnet"
|
||||||
"name": "Testnet",
|
self.network_magic = b"\x01\x1a\x41\x70\xcb\x17\x58\x20"
|
||||||
"magic_prefix": b"\x01\x1a\x41\x70\xcb\x17\x58\x20",
|
|
||||||
}
|
|
||||||
elif network == 2:
|
elif network == 2:
|
||||||
self.network = {
|
self.network_name = "Mainnet"
|
||||||
"name": "Mainnet",
|
self.network_magic = b"\x01\x1a\x2d\x96\x4a\x09\x58\x20"
|
||||||
"magic_prefix": b"\x01\x1a\x2d\x96\x4a\x09\x58\x20",
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
raise wire.ProcessError("Unknown network index " + str(network))
|
raise wire.ProcessError("Unknown network index %d" % network)
|
||||||
|
|
||||||
def _process_inputs(self):
|
def _process_inputs(self):
|
||||||
input_coins = []
|
input_coins = []
|
||||||
@ -224,7 +214,7 @@ class Transaction:
|
|||||||
def _build_witnesses(self, tx_aux_hash: str):
|
def _build_witnesses(self, tx_aux_hash: str):
|
||||||
witnesses = []
|
witnesses = []
|
||||||
for index, node in enumerate(self.nodes):
|
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(
|
signature = ed25519.sign_ext(
|
||||||
node.private_key(), node.private_key_ext(), message
|
node.private_key(), node.private_key_ext(), message
|
||||||
)
|
)
|
||||||
|
@ -10,15 +10,12 @@ class CardanoPublicKey(p.MessageType):
|
|||||||
FIELDS = {
|
FIELDS = {
|
||||||
1: ('xpub', p.UnicodeType, 0),
|
1: ('xpub', p.UnicodeType, 0),
|
||||||
2: ('node', HDNodeType, 0),
|
2: ('node', HDNodeType, 0),
|
||||||
3: ('root_hd_passphrase', p.UnicodeType, 0),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
xpub: str = None,
|
xpub: str = None,
|
||||||
node: HDNodeType = None,
|
node: HDNodeType = None,
|
||||||
root_hd_passphrase: str = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.xpub = xpub
|
self.xpub = xpub
|
||||||
self.node = node
|
self.node = node
|
||||||
self.root_hd_passphrase = root_hd_passphrase
|
|
||||||
|
@ -17,20 +17,18 @@ class TestCardanoGetPublicKey(unittest.TestCase):
|
|||||||
[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0],
|
[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0],
|
||||||
]
|
]
|
||||||
|
|
||||||
root_hd_passphrase = None
|
|
||||||
|
|
||||||
public_keys = [
|
public_keys = [
|
||||||
'a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408',
|
b'a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408',
|
||||||
'8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce',
|
b'8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce',
|
||||||
'17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791',
|
b'17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791',
|
||||||
'b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5',
|
b'b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5',
|
||||||
]
|
]
|
||||||
|
|
||||||
chain_codes = [
|
chain_codes = [
|
||||||
'cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0',
|
b'cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0',
|
||||||
'02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a',
|
b'02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a',
|
||||||
'646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d',
|
b'646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d',
|
||||||
'fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7',
|
b'fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7',
|
||||||
]
|
]
|
||||||
|
|
||||||
xpub_keys = [
|
xpub_keys = [
|
||||||
@ -43,10 +41,9 @@ class TestCardanoGetPublicKey(unittest.TestCase):
|
|||||||
for index, derivation_path in enumerate(derivation_paths):
|
for index, derivation_path in enumerate(derivation_paths):
|
||||||
key = _get_public_key(node, derivation_path)
|
key = _get_public_key(node, derivation_path)
|
||||||
|
|
||||||
self.assertEqual(hexlify(key.node.public_key).decode('utf8'), public_keys[index])
|
self.assertEqual(hexlify(key.node.public_key), public_keys[index])
|
||||||
self.assertEqual(hexlify(key.node.chain_code).decode('utf8'), chain_codes[index])
|
self.assertEqual(hexlify(key.node.chain_code), chain_codes[index])
|
||||||
self.assertEqual(key.xpub, xpub_keys[index])
|
self.assertEqual(key.xpub, xpub_keys[index])
|
||||||
self.assertEqual(key.root_hd_passphrase, root_hd_passphrase)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
|||||||
Subproject commit ab58324dc034328dc00cd14691d6bb86fe8ecec5
|
Subproject commit 4e7df217d337c8800fc91bac61038918bf3773e4
|
Loading…
Reference in New Issue
Block a user