forked from keepkey/python-keepkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_msg_binance_sign_tx.py
More file actions
137 lines (119 loc) · 5.24 KB
/
Copy pathtest_msg_binance_sign_tx.py
File metadata and controls
137 lines (119 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import unittest
import common
from base64 import b64encode
import binascii
from keepkeylib.tools import parse_path
import keepkeylib.binance as binance
from keepkeylib import messages_binance_pb2 as proto_binance
from keepkeylib import messages_pb2 as proto
from keepkeylib import types_pb2 as proto_types
class TestMsgBinanceSignTx(common.KeepKeyTest):
def test_retired_handlers_stay_unregistered(self):
"""Current full firmware must not revive the retired signing surface."""
self.requires_fullFeature()
self.requires_firmware("7.16.0")
retired_messages = (
proto_binance.BinanceGetAddress(),
proto_binance.BinanceGetPublicKey(),
proto_binance.BinanceSignTx(),
proto_binance.BinanceTransferMsg(),
proto_binance.BinanceOrderMsg(),
proto_binance.BinanceCancelMsg(),
)
for message in retired_messages:
response = self.client.call_raw(message)
self.assertIsInstance(response, proto.Failure)
self.assertEqual(
response.code,
proto_types.Failure_UnexpectedMessage,
)
def setup_binance(self):
# Native Binance Beacon Chain signing was deliberately removed from
# firmware (#541). Keep these vectors useful for older firmware, but
# do not treat an unregistered message on current builds as a signing
# regression.
self.requires_message("BinanceSignTx")
self.client.load_device_by_mnemonic(
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin",
pin=self.pin4,
passphrase_protection=False,
label='test',
language='english')
def test_transfer(self):
self.requires_fullFeature()
self.setup_binance()
message = {
"account_number": "34",
"chain_id": "Binance-Chain-Nile",
"data": "null",
"memo": "test",
"msgs": [
{
"inputs": [
{
"address": "tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd",
"coins": [{"amount": 1000000000, "denom": "BNB"}],
}
],
"outputs": [
{
"address": "tbnb1ss57e8sa7xnwq030k2ctr775uac9gjzglqhvpy",
"coins": [{"amount": 1000000000, "denom": "BNB"}],
}
],
}
],
"sequence": "31",
"source": "1",
}
response = binance.sign_tx(self.client, parse_path("m/44'/714'/0'/0/0"), message)
self.assertEqual(binascii.hexlify(response.public_key), b"029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e")
self.assertEqual(binascii.hexlify(response.signature), b"faf5b908d6c4ec0c7e2e7d8f7e1b9ca56ac8b1a22b01655813c62ce89bf84a4c7b14f58ce51e85d64c13f47e67d6a9187b8f79f09e0a9b82019f47ae190a4db3")
def test_transfer_bep2(self):
self.requires_fullFeature()
self.requires_firmware("6.6.0")
self.setup_binance()
message = {
"account_number": "34",
"chain_id": "Binance-Chain-Nile",
"data": "null",
"memo": "test",
"msgs": [
{
"inputs": [
{
"address": "tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd",
"coins": [{"amount": 1000000000, "denom": "RUNE-B1A"}],
}
],
"outputs": [
{
"address": "tbnb1ss57e8sa7xnwq030k2ctr775uac9gjzglqhvpy",
"coins": [{"amount": 1000000000, "denom": "RUNE-B1A"}],
}
],
}
],
"sequence": "31",
"source": "1",
}
response = binance.sign_tx(self.client, parse_path("m/44'/714'/0'/0/0"), message)
self.assertEqual(binascii.hexlify(response.public_key), b"029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e")
self.assertEqual(binascii.hexlify(response.signature), b"dd79d81887a7e66b90016e92855dd717136ec84da10dba46bf6ef831f11593dc3d07909e74a9f1517f1c710a036f2a72ca2cb152ad9f679f39e390297055cce3")
if __name__ == '__main__':
unittest.main()