mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 23:40:58 +00:00
cardano: add low-level support for passhrase
This commit is contained in:
parent
a15eb933e1
commit
c8ad355032
@ -504,15 +504,17 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed, mp_obj_t curve_n
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj, mod_trezorcrypto_bip32_from_seed);
|
||||
|
||||
/// def from_mnemonic_cardano(mnemonic: str) -> bytes:
|
||||
/// def from_mnemonic_cardano(mnemonic: str, passphrase: str) -> bytes:
|
||||
/// '''
|
||||
/// Convert mnemonic to hdnode
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(mp_obj_t mnemonic) {
|
||||
mp_buffer_info_t mnemo;
|
||||
STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(mp_obj_t mnemonic, mp_obj_t passphrase) {
|
||||
mp_buffer_info_t mnemo, phrase;
|
||||
mp_get_buffer_raise(mnemonic, &mnemo, MP_BUFFER_READ);
|
||||
mp_get_buffer_raise(passphrase, &phrase, MP_BUFFER_READ);
|
||||
HDNode hdnode;
|
||||
const char *pmnemonic = mnemo.len > 0 ? mnemo.buf : "";
|
||||
const char *ppassphrase = phrase.len > 0 ? phrase.buf : "";
|
||||
|
||||
uint8_t entropy[64];
|
||||
int entropy_len = mnemonic_to_entropy(pmnemonic, entropy);
|
||||
@ -521,7 +523,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(mp_obj_t mnemonic)
|
||||
mp_raise_ValueError("Invalid mnemonic");
|
||||
}
|
||||
|
||||
const 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 *)ppassphrase, phrase.len, entropy, entropy_len / 8, &hdnode);
|
||||
|
||||
if (!res) {
|
||||
mp_raise_ValueError("Secret key generation from mnemonic is looping forever");
|
||||
@ -536,7 +538,7 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_mnemonic_cardano(mp_obj_t mnemonic)
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_bip32_from_mnemonic_cardano_obj,
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_mnemonic_cardano_obj,
|
||||
mod_trezorcrypto_bip32_from_mnemonic_cardano);
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ from apps.common import storage
|
||||
|
||||
async def get_address(ctx, msg):
|
||||
mnemonic = storage.get_mnemonic()
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic, "")
|
||||
|
||||
try:
|
||||
address, _ = derive_address_and_node(root_node, msg.address_n)
|
||||
|
@ -12,7 +12,7 @@ from apps.common import layout, seed, storage
|
||||
|
||||
async def get_public_key(ctx, msg):
|
||||
mnemonic = storage.get_mnemonic()
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic, "")
|
||||
|
||||
try:
|
||||
key = _get_public_key(root_node, msg.address_n)
|
||||
|
@ -80,7 +80,7 @@ async def request_transaction(ctx, tx_req: CardanoTxRequest, index: int):
|
||||
|
||||
async def sign_tx(ctx, msg):
|
||||
mnemonic = storage.get_mnemonic()
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic, "")
|
||||
|
||||
progress.init(msg.transactions_count, "Loading data")
|
||||
|
||||
|
@ -14,7 +14,8 @@ from trezor.crypto import bip32
|
||||
class TestCardanoAddress(unittest.TestCase):
|
||||
def test_hardened_address_derivation_scheme(self):
|
||||
mnemonic = "all all all all all all all all all all all all"
|
||||
node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
passphrase = ""
|
||||
node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
|
||||
|
||||
addresses = [
|
||||
"Ae2tdPwUPEZ98eHFwxSsPBDz73amioKpr58Vw85mP1tMkzq8siaftiejJ3j",
|
||||
@ -57,7 +58,8 @@ class TestCardanoAddress(unittest.TestCase):
|
||||
|
||||
def test_non_hardened_address_derivation_scheme(self):
|
||||
mnemonic = "all all all all all all all all all all all all"
|
||||
node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
passphrase = ""
|
||||
node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
|
||||
|
||||
addresses = [
|
||||
"Ae2tdPwUPEZ5YUb8sM3eS8JqKgrRLzhiu71crfuH2MFtqaYr5ACNRdsswsZ",
|
||||
@ -101,7 +103,8 @@ class TestCardanoAddress(unittest.TestCase):
|
||||
|
||||
def test_root_address_derivation_scheme(self):
|
||||
mnemonic = "all all all all all all all all all all all all"
|
||||
node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
passphrase = ""
|
||||
node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
|
||||
|
||||
# 44'/1815'
|
||||
address, _ = derive_address_and_node(node, [0x80000000 | 44, 0x80000000 | 1815])
|
||||
@ -152,7 +155,8 @@ class TestCardanoAddress(unittest.TestCase):
|
||||
|
||||
def test_get_address_root_scheme(self):
|
||||
mnemonic = "all all all all all all all all all all all all"
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
passphrase = ""
|
||||
root_node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
|
||||
|
||||
address_root = _get_address_root(root_node, {1: b'X\x1cr,zu\x81?\xaf\xde\x9f\xf9\xe4\xd4\x90\xadH$\xe9\xf3\x88\x16\xcb\xd2)\x02M\x0c#\xde'})
|
||||
self.assertEqual(address_root, b'\xb3\xbbS\xa8;uN:E=\xe8\xe5\x9c\x18\xbcn\xcf\xd0c\xba\x0e\xba\xaelL}\xba\xbb')
|
||||
|
@ -8,7 +8,8 @@ from ubinascii import hexlify
|
||||
class TestCardanoGetPublicKey(unittest.TestCase):
|
||||
def test_get_public_key_scheme(self):
|
||||
mnemonic = "all all all all all all all all all all all all"
|
||||
node = bip32.from_mnemonic_cardano(mnemonic)
|
||||
passphrase = ""
|
||||
node = bip32.from_mnemonic_cardano(mnemonic, passphrase)
|
||||
|
||||
derivation_paths = [
|
||||
[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0x80000000],
|
||||
|
Loading…
Reference in New Issue
Block a user