fix: apdu_as_bytes() into bytes.fromhex()
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import string
|
||||
from typing import Union
|
||||
|
||||
from ethereum_client.utils import apdu_as_string, write_varint
|
||||
from ethereum_client.utils import write_varint
|
||||
|
||||
class ERC20Information:
|
||||
def __init__(self, erc20_ticker: string , addr: Union[str, bytes], nb_decimals: int, chainID: int, sign: str) -> None:
|
||||
self.erc20_ticker: bytes = apdu_as_string(erc20_ticker)
|
||||
self.erc20_ticker: bytes = bytes.fromhex(erc20_ticker)
|
||||
self.addr: bytes = bytes.fromhex(addr[2:]) if isinstance(addr, str) else addr
|
||||
self.nb_decimals: int = nb_decimals
|
||||
self.chainID: int = chainID
|
||||
self.sign: bytes = apdu_as_string(sign)
|
||||
self.sign: bytes = bytes.fromhex(sign)
|
||||
|
||||
def serialize(self) -> bytes:
|
||||
return b"".join([
|
||||
@@ -43,7 +43,7 @@ class Plugin:
|
||||
self.chainID: int = chainID
|
||||
self.keyID: int = keyID
|
||||
self.algorithm: int = algorithm
|
||||
self.sign: bytes = apdu_as_string(sign)
|
||||
self.sign: bytes = bytes.fromhex(sign)
|
||||
|
||||
def serialize(self) -> bytes:
|
||||
return b"".join([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Union
|
||||
|
||||
from ethereum_client.utils import apdu_as_string, write_varint, UINT64_MAX
|
||||
from ethereum_client.utils import write_varint, UINT64_MAX
|
||||
|
||||
|
||||
class TransactionError(Exception):
|
||||
@@ -86,8 +86,8 @@ class Transaction:
|
||||
|
||||
class EIP712:
|
||||
def __init__(self, domain_hash: str, msg_hash: str) -> None:
|
||||
self.domain_hash = apdu_as_string(domain_hash)
|
||||
self.msg_hash = apdu_as_string(msg_hash)
|
||||
self.domain_hash = bytes.fromhex(domain_hash)
|
||||
self.msg_hash = bytes.fromhex(msg_hash)
|
||||
|
||||
def serialize(self) -> bytes:
|
||||
return b"".join([
|
||||
|
||||
@@ -11,17 +11,6 @@ UINT16_MAX: int = 65535
|
||||
# Association tableau si écran nanos ou nanox
|
||||
PATH_IMG = {"nanos": "nanos", "nanox": "nanox", "nanosp": "nanox"}
|
||||
|
||||
def apdu_as_string(apdu: str) -> bytes:
|
||||
buffer: bytearray = bytearray(len(apdu) // 2)
|
||||
|
||||
for i in range(0, len(apdu), 2):
|
||||
str_extract: str = apdu[i: i + 2]
|
||||
buffer[i // 2] = int(str_extract, 16)
|
||||
|
||||
return bytes(buffer)
|
||||
|
||||
|
||||
|
||||
def save_screenshot(cmd, path: str):
|
||||
screenshot = cmd.client.get_screenshot()
|
||||
img = Image.open(BytesIO(screenshot))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from time import sleep
|
||||
|
||||
from ethereum_client.utils import apdu_as_string, compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
|
||||
def test_sign_eip_1559(cmd):
|
||||
result: list = []
|
||||
# with bip32_path "44'/60'/0'/0/0"
|
||||
apdu_sign_eip_1559 = apdu_as_string("e004000088058000002c8000003c80000000000000000000000002f87001018502540be4008502540be40086246139ca800094cccccccccccccccccccccccccccccccccccccccc8000c001a0e07fb8a64ea3786c9a6649e54429e2786af3ea31c6d06165346678cf8ce44f9ba00e4a0526db1e905b7164a858fd5ebd2f1759e22e6955499448bd276a6aa62830")
|
||||
apdu_sign_eip_1559 = bytes.fromhex("e004000088058000002c8000003c80000000000000000000000002f87001018502540be4008502540be40086246139ca800094cccccccccccccccccccccccccccccccccccccccc8000c001a0e07fb8a64ea3786c9a6649e54429e2786af3ea31c6d06165346678cf8ce44f9ba00e4a0526db1e905b7164a858fd5ebd2f1759e22e6955499448bd276a6aa62830")
|
||||
|
||||
with cmd.send_apdu_context(apdu_sign_eip_1559, result) as ex:
|
||||
sleep(0.5)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from time import sleep
|
||||
|
||||
import ethereum_client
|
||||
from ethereum_client.utils import apdu_as_string, compare_screenshot, compare_screenshot, parse_sign_response, save_screenshot, PATH_IMG
|
||||
from ethereum_client.utils import compare_screenshot, compare_screenshot, parse_sign_response, save_screenshot, PATH_IMG
|
||||
from ethereum_client.transaction import PersonalTransaction
|
||||
|
||||
def test_personal_sign_metamask(cmd):
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from time import sleep
|
||||
|
||||
from ethereum_client.utils import apdu_as_string, compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
|
||||
def test_sign_eip_2930(cmd):
|
||||
result: list = []
|
||||
apdu_sign_eip_2930 = apdu_as_string("e004000096058000002c8000003c80000000000000000000000001f886030685012a05f20082520894b2bb2b958afa2e96dab3f3ce7162b87daea39017872386f26fc1000080f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000007")
|
||||
apdu_sign_eip_2930 = bytes.fromhex("e004000096058000002c8000003c80000000000000000000000001f886030685012a05f20082520894b2bb2b958afa2e96dab3f3ce7162b87daea39017872386f26fc1000080f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000007")
|
||||
|
||||
with cmd.send_apdu_context(apdu_sign_eip_2930, result) as ex:
|
||||
sleep(0.5)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from time import sleep
|
||||
|
||||
import ethereum_client
|
||||
from ethereum_client.utils import apdu_as_string, compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
from ethereum_client.plugin import Plugin
|
||||
|
||||
SIGN_FIRST = apdu_as_string("e004000096058000002c8000003c800000000000000000000000f901090b8520b673dd0082bcb394495f947276749ce646f68ac8c248420045cb7b5e80b8e4f242432a0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596cabf06640f8ca8fc5e0ed471b10befcdf65a33e4300000000")
|
||||
SIGN_MORE = apdu_as_string("e00480008b00006a0000000064000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000018080")
|
||||
SIGN_FIRST = bytes.fromhex("e004000096058000002c8000003c800000000000000000000000f901090b8520b673dd0082bcb394495f947276749ce646f68ac8c248420045cb7b5e80b8e4f242432a0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596cabf06640f8ca8fc5e0ed471b10befcdf65a33e4300000000")
|
||||
SIGN_MORE = bytes.fromhex("e00480008b00006a0000000064000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000018080")
|
||||
|
||||
PLUGIN = Plugin(
|
||||
type=1,
|
||||
@@ -125,10 +125,10 @@ def test_transfer_erc1155_without_set_plugin(cmd):
|
||||
# Batch
|
||||
# ===========================
|
||||
|
||||
SIGN_FIRST_BATCH = apdu_as_string("e004000096058000002c8000003c800000000000000000000000f9020b0e850d8cfd86008301617d94495f947276749ce646f68ac8c248420045cb7b5e80b901e42eb2c2d60000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596c00000000000000000000000000000000000000000000")
|
||||
SIGN_MORE_1_BATCH = apdu_as_string("e004800096000000000000000000a0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000003abf06640f8ca8fc5e0ed471b10befcdf65a33e430000000000006a0000000064def9d99ff495856496c028c0")
|
||||
SIGN_MORE_2_BATCH = apdu_as_string("e00480009689732473fcd0bbbe000000000000a30000000001abf06640f8ca8fc5e0ed471b10befcdf65a33e430000000000006a00000000640000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000010000")
|
||||
SIGN_MORE_3_BATCH = apdu_as_string("e00480006100000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000018080")
|
||||
SIGN_FIRST_BATCH = bytes.fromhex("e004000096058000002c8000003c800000000000000000000000f9020b0e850d8cfd86008301617d94495f947276749ce646f68ac8c248420045cb7b5e80b901e42eb2c2d60000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596c00000000000000000000000000000000000000000000")
|
||||
SIGN_MORE_1_BATCH = bytes.fromhex("e004800096000000000000000000a0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000003abf06640f8ca8fc5e0ed471b10befcdf65a33e430000000000006a0000000064def9d99ff495856496c028c0")
|
||||
SIGN_MORE_2_BATCH = bytes.fromhex("e00480009689732473fcd0bbbe000000000000a30000000001abf06640f8ca8fc5e0ed471b10befcdf65a33e430000000000006a00000000640000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000010000")
|
||||
SIGN_MORE_3_BATCH = bytes.fromhex("e00480006100000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000018080")
|
||||
|
||||
PLUGIN_BATCH = Plugin(
|
||||
type=1,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from time import sleep
|
||||
|
||||
import ethereum_client
|
||||
from ethereum_client.utils import apdu_as_string, compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
|
||||
from ethereum_client.plugin import Plugin
|
||||
|
||||
SIGN_FIRST = apdu_as_string("e004000096058000002c8000003c800000000000000000000000f88a0a852c3ce1ec008301f5679460f80121c31a0d46b5279700f9df786054aa5ee580b86442842e0e0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596c000000000000000000000000000000000000000000000000")
|
||||
SIGN_MORE = apdu_as_string("e00480000b0000000000112999018080")
|
||||
SIGN_FIRST = bytes.fromhex("e004000096058000002c8000003c800000000000000000000000f88a0a852c3ce1ec008301f5679460f80121c31a0d46b5279700f9df786054aa5ee580b86442842e0e0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596c000000000000000000000000000000000000000000000000")
|
||||
SIGN_MORE = bytes.fromhex("e00480000b0000000000112999018080")
|
||||
|
||||
PLUGIN = Plugin(
|
||||
type=1,
|
||||
|
||||
Reference in New Issue
Block a user