mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-25 07:48:10 +00:00
core/ethereum: add support for wanchain slip44 id (#440)
This commit is contained in:
parent
c307d9f14b
commit
2022c39ef9
@ -1,8 +1,13 @@
|
|||||||
# generated from networks.py.mako
|
# generated from networks.py.mako
|
||||||
# do not edit manually!
|
# do not edit manually!
|
||||||
|
|
||||||
|
from micropython import const
|
||||||
|
|
||||||
from apps.common import HARDENED
|
from apps.common import HARDENED
|
||||||
|
|
||||||
|
SLIP44_WANCHAIN = const(5718350)
|
||||||
|
SLIP44_ETHEREUM = const(60)
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Iterator, Optional
|
from typing import Iterator, Optional
|
||||||
|
|
||||||
@ -23,6 +28,9 @@ def by_chain_id(chain_id: int) -> Optional["NetworkInfo"]:
|
|||||||
|
|
||||||
|
|
||||||
def by_slip44(slip44: int) -> Optional["NetworkInfo"]:
|
def by_slip44(slip44: int) -> Optional["NetworkInfo"]:
|
||||||
|
if slip44 == SLIP44_WANCHAIN:
|
||||||
|
# Coerce to Ethereum
|
||||||
|
slip44 == SLIP44_ETHEREUM
|
||||||
for n in NETWORKS:
|
for n in NETWORKS:
|
||||||
if n.slip44 == slip44:
|
if n.slip44 == slip44:
|
||||||
return n
|
return n
|
||||||
@ -32,6 +40,7 @@ def by_slip44(slip44: int) -> Optional["NetworkInfo"]:
|
|||||||
def all_slip44_ids_hardened() -> Iterator[int]:
|
def all_slip44_ids_hardened() -> Iterator[int]:
|
||||||
for n in NETWORKS:
|
for n in NETWORKS:
|
||||||
yield n.slip44 | HARDENED
|
yield n.slip44 | HARDENED
|
||||||
|
yield SLIP44_WANCHAIN | HARDENED
|
||||||
|
|
||||||
|
|
||||||
class NetworkInfo:
|
class NetworkInfo:
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
# generated from networks.py.mako
|
# generated from networks.py.mako
|
||||||
# do not edit manually!
|
# do not edit manually!
|
||||||
|
|
||||||
|
from micropython import const
|
||||||
|
|
||||||
from apps.common import HARDENED
|
from apps.common import HARDENED
|
||||||
|
|
||||||
|
SLIP44_WANCHAIN = const(5718350)
|
||||||
|
SLIP44_ETHEREUM = const(60)
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Iterator, Optional
|
from typing import Iterator, Optional
|
||||||
|
|
||||||
@ -23,6 +28,9 @@ def by_chain_id(chain_id: int) -> Optional["NetworkInfo"]:
|
|||||||
|
|
||||||
|
|
||||||
def by_slip44(slip44: int) -> Optional["NetworkInfo"]:
|
def by_slip44(slip44: int) -> Optional["NetworkInfo"]:
|
||||||
|
if slip44 == SLIP44_WANCHAIN:
|
||||||
|
# Coerce to Ethereum
|
||||||
|
slip44 == SLIP44_ETHEREUM
|
||||||
for n in NETWORKS:
|
for n in NETWORKS:
|
||||||
if n.slip44 == slip44:
|
if n.slip44 == slip44:
|
||||||
return n
|
return n
|
||||||
@ -32,6 +40,7 @@ def by_slip44(slip44: int) -> Optional["NetworkInfo"]:
|
|||||||
def all_slip44_ids_hardened() -> Iterator[int]:
|
def all_slip44_ids_hardened() -> Iterator[int]:
|
||||||
for n in NETWORKS:
|
for n in NETWORKS:
|
||||||
yield n.slip44 | HARDENED
|
yield n.slip44 | HARDENED
|
||||||
|
yield SLIP44_WANCHAIN | HARDENED
|
||||||
|
|
||||||
|
|
||||||
class NetworkInfo:
|
class NetworkInfo:
|
||||||
|
@ -70,6 +70,7 @@ class TestEthereumGetAddress(unittest.TestCase):
|
|||||||
[44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 9999],
|
[44 | HARDENED, 60 | HARDENED, 0 | HARDENED, 0, 9999],
|
||||||
[44 | HARDENED, 6060 | HARDENED, 0 | HARDENED, 0, 0],
|
[44 | HARDENED, 6060 | HARDENED, 0 | HARDENED, 0, 0],
|
||||||
[44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0, 0],
|
[44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0, 0],
|
||||||
|
[44 | HARDENED, 5718350 | HARDENED, 0 | HARDENED, 0, 0],
|
||||||
]
|
]
|
||||||
|
|
||||||
for path in incorrect_paths:
|
for path in incorrect_paths:
|
||||||
|
@ -51,3 +51,8 @@ class TestMsgEthereumGetaddress(TrezorTest):
|
|||||||
ethereum.get_address(self.client, [H_(44), H_(6060), 0, 9999999])
|
ethereum.get_address(self.client, [H_(44), H_(6060), 0, 9999999])
|
||||||
== "0x98b8e926bd224764De2A0E4f4CBe1521474050AF"
|
== "0x98b8e926bd224764De2A0E4f4CBe1521474050AF"
|
||||||
)
|
)
|
||||||
|
# Wanchain SLIP44 id
|
||||||
|
assert (
|
||||||
|
ethereum.get_address(self.client, [H_(44), H_(5718350), H_(0)])
|
||||||
|
== "0x4d643B1b556E14A27143a38bcE61230FFf5AFca8"
|
||||||
|
)
|
||||||
|
@ -80,6 +80,41 @@ class TestMsgEthereumSigntx(TrezorTest):
|
|||||||
== "7001bfe3ba357e4a9f9e0d3a3f8a8962257615a4cf215db93e48b98999fc51b7"
|
== "7001bfe3ba357e4a9f9e0d3a3f8a8962257615a4cf215db93e48b98999fc51b7"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_ethereum_signtx_wanchain(self):
|
||||||
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
|
|
||||||
|
with self.client:
|
||||||
|
self.client.set_expected_responses(
|
||||||
|
[
|
||||||
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
||||||
|
proto.ButtonRequest(code=proto.ButtonRequestType.SignTx),
|
||||||
|
proto.EthereumTxRequest(data_length=None),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
||||||
|
self.client,
|
||||||
|
n=parse_path("44'/5718350'/0'/0/0"),
|
||||||
|
nonce=0,
|
||||||
|
gas_price=20,
|
||||||
|
gas_limit=20,
|
||||||
|
# ADT token address
|
||||||
|
to="0xd0d6d6c5fe4a677d343cc433536bb717bae167dd",
|
||||||
|
chain_id=1,
|
||||||
|
tx_type=1,
|
||||||
|
# value needs to be 0, token value is set in the contract (data)
|
||||||
|
value=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ad-hoc generated signature. might not be valid.
|
||||||
|
assert (
|
||||||
|
sig_r.hex()
|
||||||
|
== "d6e197029031ec90b53ed14e8233aa78b592400513ac0386d2d55cdedc3d796f"
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
sig_s.hex()
|
||||||
|
== "326e0d600dd1b7ee606eb531b998a6a3b3293d4995fb8cfe0677962e8a43cff6"
|
||||||
|
)
|
||||||
|
|
||||||
def test_ethereum_signtx_unknown_erc20_token(self):
|
def test_ethereum_signtx_unknown_erc20_token(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user