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