2018-03-09 10:37:06 +00:00
|
|
|
from micropython import const
|
|
|
|
|
2018-08-30 11:45:09 +00:00
|
|
|
from apps.common import HARDENED
|
|
|
|
|
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
|
|
|
|
2018-03-16 12:55:37 +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)
|
|
|
|
|
2018-03-26 13:03:57 +00:00
|
|
|
NEM_MAX_DIVISIBILITY = const(6)
|
|
|
|
NEM_MAX_SUPPLY = const(9000000000)
|
|
|
|
|
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"
|
2018-03-26 13:03:57 +00:00
|
|
|
NEM_PUBLIC_KEY_SIZE = const(32) # ed25519 public key
|
2018-04-24 16:17:40 +00:00
|
|
|
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE = const(10000)
|
2018-04-27 15:28:56 +00:00
|
|
|
NEM_MOSAIC_AMOUNT_DIVISOR = const(1000000)
|
2018-04-04 14:23:44 +00:00
|
|
|
|
|
|
|
NEM_MAX_PLAIN_PAYLOAD_SIZE = const(1024)
|
|
|
|
NEM_MAX_ENCRYPTED_PAYLOAD_SIZE = const(960)
|
2018-06-06 12:04:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_network_str(network: int) -> str:
|
|
|
|
if network == NEM_NETWORK_MAINNET:
|
2018-07-03 14:20:58 +00:00
|
|
|
return "Mainnet"
|
2018-06-06 12:04:56 +00:00
|
|
|
elif network == NEM_NETWORK_TESTNET:
|
2018-07-03 14:20:58 +00:00
|
|
|
return "Testnet"
|
2018-06-06 12:04:56 +00:00
|
|
|
elif network == NEM_NETWORK_MIJIN:
|
2018-07-03 14:20:58 +00:00
|
|
|
return "Mijin"
|
2018-08-30 11:45:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_path(path: list, network=None) -> bool:
|
|
|
|
"""
|
|
|
|
Validates derivation path to fit 44'/43'/a' or 44'/43'/a'/0'/0',
|
|
|
|
where `a` is an account number. We believe the path should be
|
|
|
|
44'/43'/a', but for compatibility reasons with NEM's NanoWallet
|
|
|
|
we allow 44'/43'/a'/0'/0' as well.
|
|
|
|
Testnet is also allowed: 44'/1'/a'{/0'/0'}
|
|
|
|
"""
|
|
|
|
length = len(path)
|
|
|
|
if length != 3 and length != 5:
|
|
|
|
return False
|
|
|
|
if path[0] != 44 | HARDENED:
|
|
|
|
return False
|
|
|
|
if not (
|
|
|
|
path[1] == 43 | HARDENED
|
|
|
|
or (network == NEM_NETWORK_TESTNET and path[1] == 1 | HARDENED)
|
|
|
|
):
|
|
|
|
return False
|
|
|
|
if path[2] < HARDENED or path[2] > 1000000 | HARDENED:
|
|
|
|
return False
|
|
|
|
if length == 5 and (path[3] != 0 | HARDENED or path[4] != 0 | HARDENED):
|
|
|
|
return False
|
|
|
|
return True
|