1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-02 12:38:43 +00:00
trezor-firmware/core/src/apps/nem/helpers.py

60 lines
1.7 KiB
Python
Raw Normal View History

2018-03-09 10:37:06 +00:00
from micropython import const
from apps.common import paths
from . import SLIP44_ID
2018-03-14 13:53:11 +00:00
NEM_NETWORK_MAINNET = const(0x68)
NEM_NETWORK_TESTNET = const(0x98)
NEM_NETWORK_MIJIN = const(0x60)
2018-03-09 10:37:06 +00:00
NEM_TRANSACTION_TYPE_TRANSFER = const(0x0101)
NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER = const(0x0801)
NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION = const(0x1001)
NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE = const(0x1002)
NEM_TRANSACTION_TYPE_MULTISIG = const(0x1004)
NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE = const(0x2001)
NEM_TRANSACTION_TYPE_MOSAIC_CREATION = const(0x4001)
NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE = const(0x4002)
NEM_MAX_DIVISIBILITY = const(6)
NEM_MAX_SUPPLY = const(9_000_000_000)
2018-03-21 13:30:28 +00:00
NEM_SALT_SIZE = const(32)
AES_BLOCK_SIZE = const(16)
2018-07-03 14:20:58 +00:00
NEM_HASH_ALG = "keccak"
NEM_PUBLIC_KEY_SIZE = const(32) # ed25519 public key
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE = const(10_000)
NEM_MOSAIC_AMOUNT_DIVISOR = const(1_000_000)
2018-04-04 14:23:44 +00:00
NEM_MAX_PLAIN_PAYLOAD_SIZE = const(1024)
NEM_MAX_ENCRYPTED_PAYLOAD_SIZE = const(960)
def get_network_str(network: int) -> str:
if network == NEM_NETWORK_MAINNET:
2018-07-03 14:20:58 +00:00
return "Mainnet"
elif network == NEM_NETWORK_TESTNET:
2018-07-03 14:20:58 +00:00
return "Testnet"
elif network == NEM_NETWORK_MIJIN:
2018-07-03 14:20:58 +00:00
return "Mijin"
raise RuntimeError # network should be one of the NEM_NETWORK_* constants
def check_path(path: paths.Bip32Path, network: int) -> bool:
"""Validates that the appropriate coin_type is set for the given network."""
if len(path) < 2:
return False
coin_type = path[1] - paths.HARDENED
if network == NEM_NETWORK_TESTNET:
return coin_type == 1
if network in (NEM_NETWORK_MAINNET, NEM_NETWORK_MIJIN):
return coin_type == SLIP44_ID
# unknown network
return False