style: use flake8

This commit is contained in:
Pavol Rusnak 2017-06-23 21:31:42 +02:00
parent 71996c1e43
commit 33f274d145
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
62 changed files with 1200 additions and 881 deletions

16
.flake8 Normal file
View File

@ -0,0 +1,16 @@
[flake8]
exclude =
.tox/,
build/,
dist/,
tools/signtest.py,
trezorlib/*_pb2.py
ignore =
# F821 undefined name 'unicode',
F821,
# F401: module imported but unused
F401,
# E402: module level import not at top of file
E402,
# E501: line too long
E501

View File

@ -25,9 +25,11 @@ install:
- pip install "pip>=7.0" wheel
- pip install "setuptools>=19.0"
- pip install tox-travis
- pip install flake8
script:
- python setup.py install
- flake8
- tox
notifications:

View File

@ -45,7 +45,8 @@ except Exception as e:
def pipe_exists(path):
import os, stat
import os
import stat
try:
return stat.S_ISFIFO(os.stat(path).st_mode)
except:

View File

@ -21,6 +21,7 @@ import common
from trezorlib import messages_pb2 as messages
class TestBasic(common.TrezorTest):
def test_features(self):
@ -50,5 +51,6 @@ class TestBasic(common.TrezorTest):
# Device ID must be fresh after every reset
self.assertNotEqual(id1, id2)
if __name__ == '__main__':
unittest.main()

View File

@ -21,7 +21,7 @@ from __future__ import print_function
import unittest
import common
import time
from trezorlib import tools
class TestBip32Speed(common.TrezorTest):
@ -70,5 +70,6 @@ class TestBip32Speed(common.TrezorTest):
# Cached time expected to be at least 2x faster
self.assertLessEqual(cache_time, nocache_time / 2.)
if __name__ == '__main__':
unittest.main()

View File

@ -16,14 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import time
import unittest
import common
import binascii
from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as types
from trezorlib.client import PinException
class TestDebugLink(common.TrezorTest):
@ -56,5 +53,6 @@ class TestDebugLink(common.TrezorTest):
resp = self.client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
self.assertIsInstance(resp, proto.Success)
if __name__ == '__main__':
unittest.main()

View File

@ -16,12 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import time
import unittest
import common
from trezorlib import messages_pb2 as proto
class TestMsgApplysettings(common.TrezorTest):
def test_apply_settings(self):
@ -92,5 +92,6 @@ class TestMsgApplysettings(common.TrezorTest):
proto.Features()])
self.client.apply_settings(homescreen=img)
if __name__ == '__main__':
unittest.main()

View File

@ -16,12 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import time
import unittest
import common
from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as proto_types
class TestMsgChangepin(common.TrezorTest):
@ -218,5 +217,6 @@ class TestMsgChangepin(common.TrezorTest):
self.assertTrue(features.pin_protection)
self.assertEqual(self.client.debug.read_pin()[0], self.pin4)
if __name__ == '__main__':
unittest.main()

View File

@ -20,7 +20,6 @@ import unittest
import common
import binascii
from trezorlib.client import CallException
class TestMsgCipherkeyvalue(common.TrezorTest):
@ -88,5 +87,6 @@ class TestMsgCipherkeyvalue(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
self.assertRaises(Exception, self.client.decrypt_keyvalue, [0, 1, 2], b"test", b"testing")
if __name__ == '__main__':
unittest.main()

View File

@ -16,13 +16,13 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import time
import unittest
import common
from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as proto_types
class TestMsgClearsession(common.TrezorTest):
def test_clearsession(self):
@ -53,5 +53,6 @@ class TestMsgClearsession(common.TrezorTest):
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
self.assertEqual(res, 'random data')
if __name__ == '__main__':
unittest.main()

View File

@ -17,29 +17,29 @@
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import unittest
import common
import binascii
import common
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
from trezorlib.client import CallException
class TestMsgEstimatetxsize(common.TrezorTest):
def test_estimate_size(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
est_size = self.client.estimate_tx_size('Bitcoin', [inp1, ], [out1, ])
self.assertEqual(est_size, 194)
@ -48,5 +48,6 @@ class TestMsgEstimatetxsize(common.TrezorTest):
self.assertGreaterEqual(est_size, real_size)
if __name__ == '__main__':
unittest.main()

View File

@ -18,9 +18,9 @@
import unittest
import common
import trezorlib.ckd_public as bip32
import binascii
class TestMsgEthereumGetaddress(common.TrezorTest):
def test_ethereum_getaddress(self):
@ -31,5 +31,6 @@ class TestMsgEthereumGetaddress(common.TrezorTest):
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([-9, 0])), b'f68804ac9eca9483ab4241d3e4751590d2c05102')
self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, 9999999])), b'7a6366ecfcaf0d5dcc1539c171696c6cdd1eb8ed')
if __name__ == '__main__':
unittest.main()

View File

@ -20,10 +20,6 @@ import unittest
import common
import binascii
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
from rlp.utils import int_to_big_endian
class TestMsgEthereumSigntx(common.TrezorTest):
@ -94,18 +90,20 @@ class TestMsgEthereumSigntx(common.TrezorTest):
self.assertEqual(binascii.hexlify(sig_r), '070e9dafda4d9e733fa7b6747a75f8a4916459560efb85e3e73cd39f31aa160d')
self.assertEqual(binascii.hexlify(sig_s), '7842db33ef15c27049ed52741db41fe3238a6fa3a6a0888fcfb74d6917600e41')
def test_ethereum_signtx_newcontract(self):
self.setup_mnemonic_nopin_nopassphrase()
# contract creation without data should fail.
self.assertRaises(Exception, self.client.ethereum_sign_tx,
self.assertRaises(
Exception,
self.client.ethereum_sign_tx,
n=[0, 0],
nonce=123456,
gas_price=20000,
gas_limit=20000,
to='',
value=12345678901234567890)
value=12345678901234567890
)
sig_v, sig_r, sig_s = self.client.ethereum_sign_tx(
n=[0, 0],
@ -121,37 +119,49 @@ class TestMsgEthereumSigntx(common.TrezorTest):
def test_ethereum_sanity_checks(self):
# gas overflow
self.assertRaises(Exception, self.client.ethereum_sign_tx,
self.assertRaises(
Exception,
self.client.ethereum_sign_tx,
n=[0, 0],
nonce=123456,
gas_price=0xffffffffffffffffffffffffffffffff,
gas_limit=0xffffffffffffffffffffffffffffff,
to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'),
value=12345678901234567890)
value=12345678901234567890
)
# no gas price
self.assertRaises(Exception, self.client.ethereum_sign_tx,
self.assertRaises(
Exception,
self.client.ethereum_sign_tx,
n=[0, 0],
nonce=123456,
gas_limit=10000,
to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'),
value=12345678901234567890)
value=12345678901234567890
)
# no gas limit
self.assertRaises(Exception, self.client.ethereum_sign_tx,
self.assertRaises(
Exception,
self.client.ethereum_sign_tx,
n=[0, 0],
nonce=123456,
gas_price=10000,
to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'),
value=12345678901234567890)
value=12345678901234567890
)
# no nonce
self.assertRaises(Exception, self.client.ethereum_sign_tx,
self.assertRaises(
Exception,
self.client.ethereum_sign_tx,
n=[0, 0],
gas_price=10000,
gas_limit=123456,
to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'),
value=12345678901234567890)
value=12345678901234567890
)
def test_ethereum_signtx_nodata_eip155(self):
self.setup_mnemonic_allallall()
@ -235,5 +245,6 @@ class TestMsgEthereumSigntx(common.TrezorTest):
self.assertEqual(binascii.hexlify(sig_r), 'f7505f709d5999343aea3c384034c62d0514336ff6c6af65582006f708f81503')
self.assertEqual(binascii.hexlify(sig_s), '44e09e29a4b6247000b46ddc94fe391e94deb2b39ad6ac6398e6db5bec095ba9')
if __name__ == '__main__':
unittest.main()

View File

@ -20,6 +20,7 @@ import unittest
import common
import trezorlib.ckd_public as bip32
class TestMsgGetaddress(common.TrezorTest):
def test_btc(self):
@ -58,5 +59,6 @@ class TestMsgGetaddress(common.TrezorTest):
self.assertEqual(address2, '1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb')
self.assertEqual(address1, address2)
if __name__ == '__main__':
unittest.main()

View File

@ -2,7 +2,7 @@ import unittest
import common
import trezorlib.ckd_public as bip32
import trezorlib.types_pb2 as proto_types
import binascii
class TestMsgGetaddressSegwit(common.TrezorTest):
@ -29,15 +29,15 @@ class TestMsgGetaddressSegwit(common.TrezorTest):
signatures=[b'', b'', b''],
m=2,
)
multisig2 = proto_types.MultisigRedeemScriptType(
pubkeys=map(lambda n : proto_types.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2,1]), nodes),
signatures=[b'', b'', b''],
m=2,
)
# multisig2 = proto_types.MultisigRedeemScriptType(
# pubkeys=map(lambda n: proto_types.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 1]), nodes),
# signatures=[b'', b'', b''],
# m=2,
# )
for i in [1, 2, 3]:
self.assertEqual(self.client.get_address("Testnet", self.client.expand_path("999'/1'/%d'/2/0" % i),
False, multisig1, script_type=proto_types.SPENDP2SHWITNESS),
'2N2MxyAfifVhb3AMagisxaj3uij8bfXqf4Y');
'2N2MxyAfifVhb3AMagisxaj3uij8bfXqf4Y')
if __name__ == '__main__':

View File

@ -2,7 +2,7 @@ import unittest
import common
import trezorlib.ckd_public as bip32
import trezorlib.types_pb2 as proto_types
import binascii
class TestMsgGetaddressSegwitNative(common.TrezorTest):

View File

@ -20,7 +20,7 @@ import unittest
import common
import trezorlib.ckd_public as bip32
import trezorlib.types_pb2 as proto_types
import binascii
class TestMsgGetaddress(common.TrezorTest):
@ -35,9 +35,11 @@ class TestMsgGetaddress(common.TrezorTest):
node = bip32.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node, address_n=[1]),
proto_types.HDNodePathType(node=node, address_n=[2]),
proto_types.HDNodePathType(node=node, address_n=[3])],
proto_types.HDNodePathType(node=node, address_n=[3])
],
signatures=[b'', b'', b''],
m=2,
)
@ -63,5 +65,6 @@ class TestMsgGetaddress(common.TrezorTest):
for i in range(15):
self.assertEqual(self.client.get_address('Bitcoin', [i], show_display=True, multisig=multisig), '3QaKF8zobqcqY8aS6nxCD5ZYdiRfL3RCmU')
if __name__ == '__main__':
unittest.main()

View File

@ -19,12 +19,13 @@
from __future__ import print_function
import unittest
import common
import math
import common
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
def entropy(data):
counts = {}
for c in data:
@ -38,6 +39,7 @@ def entropy(data):
e -= p * math.log(p, 256)
return e
class TestMsgGetentropy(common.TrezorTest):
def test_entropy(self):
@ -48,5 +50,6 @@ class TestMsgGetentropy(common.TrezorTest):
self.assertTrue(len(ent) == l)
print('entropy = ', entropy(ent))
if __name__ == '__main__':
unittest.main()

View File

@ -20,6 +20,7 @@ import unittest
import common
import trezorlib.ckd_public as bip32
class TestMsgGetpublic_key(common.TrezorTest):
def test_btc(self):
@ -42,5 +43,6 @@ class TestMsgGetpublic_key(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
self.assertEqual(bip32.serialize(self.client.get_public_node([111, 42]).node, 0x043587CF), 'tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz')
if __name__ == '__main__':
unittest.main()

View File

@ -19,7 +19,6 @@
import unittest
import common
from trezorlib import messages_pb2 as messages
class TestDeviceLoad(common.TrezorTest):
@ -89,5 +88,6 @@ class TestDeviceLoad(common.TrezorTest):
self.assertEqual(address_nfkd, address_nfkc)
self.assertEqual(address_nfkd, address_nfd)
if __name__ == '__main__':
unittest.main()

View File

@ -19,7 +19,6 @@
import unittest
import common
from trezorlib import messages_pb2 as messages
class TestDeviceLoadXprv(common.TrezorTest):
@ -43,5 +42,6 @@ class TestDeviceLoadXprv(common.TrezorTest):
address = self.client.get_address('Bitcoin', [])
self.assertEqual(address, '1CHUbFa4wTTPYgkYaw2LHSd5D4qJjMU8ri')
if __name__ == '__main__':
unittest.main()

View File

@ -16,13 +16,13 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import time
import unittest
import common
from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as proto_types
class TestPing(common.TrezorTest):
def test_ping(self):
@ -62,5 +62,6 @@ class TestPing(common.TrezorTest):
res = self.client.ping('random data', button_protection=True, pin_protection=True, passphrase_protection=True)
self.assertEqual(res, 'random data')
if __name__ == '__main__':
unittest.main()

View File

@ -23,6 +23,7 @@ import common
from trezorlib import messages_pb2 as proto
class TestDeviceRecovery(common.TrezorTest):
def test_pin_passphrase(self):
mnemonic = self.mnemonic12.split(' ')
@ -171,5 +172,6 @@ class TestDeviceRecovery(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
self.assertRaises(Exception, self.client.recovery_device, 12, False, False, 'label', 'english')
if __name__ == '__main__':
unittest.main()

View File

@ -17,12 +17,13 @@
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import unittest
import common
import hashlib
import common
from trezorlib import messages_pb2 as proto
from mnemonic import Mnemonic
def generate_entropy(strength, internal_entropy, external_entropy):
'''
strength - length of produced seed. One of 128, 192, 256
@ -51,18 +52,21 @@ def generate_entropy(strength, internal_entropy, external_entropy):
return entropy_stripped
class TestDeviceReset(common.TrezorTest):
def test_reset_device(self):
# No PIN, no passphrase
external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128
ret = self.client.call_raw(proto.ResetDevice(display_random=False,
ret = self.client.call_raw(proto.ResetDevice(
display_random=False,
strength=strength,
passphrase_protection=False,
pin_protection=False,
language='english',
label='test'))
label='test'
))
# Provide entropy
self.assertIsInstance(ret, proto.EntropyRequest)
@ -116,12 +120,14 @@ class TestDeviceReset(common.TrezorTest):
external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128
ret = self.client.call_raw(proto.ResetDevice(display_random=True,
ret = self.client.call_raw(proto.ResetDevice(
display_random=True,
strength=strength,
passphrase_protection=True,
pin_protection=True,
language='english',
label='test'))
label='test'
))
self.assertIsInstance(ret, proto.ButtonRequest)
self.client.debug.press_yes()
@ -189,15 +195,17 @@ class TestDeviceReset(common.TrezorTest):
self.client.call_raw(proto.Cancel())
def test_failed_pin(self):
external_entropy = b'zlutoucky kun upel divoke ody' * 2
# external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128
ret = self.client.call_raw(proto.ResetDevice(display_random=True,
ret = self.client.call_raw(proto.ResetDevice(
display_random=True,
strength=strength,
passphrase_protection=True,
pin_protection=True,
language='english',
label='test'))
label='test'
))
self.assertIsInstance(ret, proto.ButtonRequest)
self.client.debug.press_yes()
@ -220,5 +228,6 @@ class TestDeviceReset(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
self.assertRaises(Exception, self.client.reset_device, False, 128, True, True, 'label', 'english')
if __name__ == '__main__':
unittest.main()

View File

@ -19,29 +19,35 @@
from __future__ import print_function
import unittest
import common
import binascii
import hashlib
import struct
import common
from trezorlib.client import CallException
import trezorlib.types_pb2 as proto_types
def check_path(identity):
m = hashlib.sha256()
m.update(struct.pack("<I", identity.index))
uri = ''
if identity.proto: uri += identity.proto + '://'
if identity.user: uri += identity.user + '@'
if identity.host: uri += identity.host
if identity.port: uri += ':' + identity.port
if identity.path: uri += identity.path
if identity.proto:
uri += identity.proto + '://'
if identity.user:
uri += identity.user + '@'
if identity.host:
uri += identity.host
if identity.port:
uri += ':' + identity.port
if identity.path:
uri += identity.path
m.update(uri)
print('hash:', m.hexdigest())
(a, b, c, d, _, _, _, _) = struct.unpack('<8I', m.digest())
address_n = [0x80000000 | 13, 0x80000000 | a, 0x80000000 | b, 0x80000000 | c, 0x80000000 | d]
print('path:', 'm/' + '/'.join([str(x) for x in address_n]))
class TestMsgSignidentity(common.TrezorTest):
def test_sign(self):

View File

@ -20,7 +20,6 @@ import unittest
import common
import binascii
from trezorlib.client import CallException
class TestMsgSignmessage(common.TrezorTest):
@ -57,5 +56,6 @@ class TestMsgSignmessage(common.TrezorTest):
self.assertEqual(sig_nfc.address, '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e')
self.assertEqual(binascii.hexlify(sig_nfc.signature), b'20d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6')
if __name__ == '__main__':
unittest.main()

View File

@ -45,13 +45,15 @@ class TestMsgSigntx(common.TrezorTest):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
@ -82,18 +84,21 @@ class TestMsgSigntx(common.TrezorTest):
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
# input 1: 10.00000000 BTC
inp1 = proto_types.TxInputType(address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
inp1 = proto_types.TxInputType(
address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
# amount=1000000000,
prev_hash=TXHASH_6f90f3,
prev_index=1,
)
out1 = proto_types.TxOutputType(address='mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV',
out1 = proto_types.TxOutputType(
address='mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV',
amount=1000000000 - 500000000 - 10000000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(address_n=[2],
out2 = proto_types.TxOutputType(
address_n=[2],
amount=500000000,
script_type=proto_types.PAYTOADDRESS,
)
@ -127,18 +132,21 @@ class TestMsgSigntx(common.TrezorTest):
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
# input 1: 10.00000000 BTC
inp1 = proto_types.TxInputType(address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
inp1 = proto_types.TxInputType(
address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
# amount=1000000000,
prev_hash=TXHASH_6f90f3,
prev_index=1,
)
out1 = proto_types.TxOutputType(address='mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV',
out1 = proto_types.TxOutputType(
address='mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV',
amount=1000000000 - 500000000 - 100000000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(address_n=[2],
out2 = proto_types.TxOutputType(
address_n=[2],
amount=500000000,
script_type=proto_types.PAYTOADDRESS,
)
@ -174,18 +182,21 @@ class TestMsgSigntx(common.TrezorTest):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 80000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(address_n=[1],
out2 = proto_types.TxOutputType(
address_n=[1],
amount=80000,
script_type=proto_types.PAYTOADDRESS,
)
@ -218,23 +229,27 @@ class TestMsgSigntx(common.TrezorTest):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 80000 - 12000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(address='13uaUYn6XAooo88QvAqAVsiVvr2mAXutqP',
out2 = proto_types.TxOutputType(
address='13uaUYn6XAooo88QvAqAVsiVvr2mAXutqP',
amount=12000,
script_type=proto_types.PAYTOADDRESS,
)
out3 = proto_types.TxOutputType(address_n=[1],
out3 = proto_types.TxOutputType(
address_n=[1],
amount=80000,
script_type=proto_types.PAYTOADDRESS,
)
@ -273,24 +288,28 @@ class TestMsgSigntx(common.TrezorTest):
# tx: 58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e
# input 1: 0.0011 BTC
inp1 = proto_types.TxInputType(address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
inp1 = proto_types.TxInputType(
address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
# amount=100000,
prev_hash=TXHASH_c6be22,
prev_index=1,
)
inp2 = proto_types.TxInputType(address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG
inp2 = proto_types.TxInputType(
address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG
# amount=110000,
prev_hash=TXHASH_58497a,
prev_index=1,
)
out1 = proto_types.TxOutputType(address='15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B',
out1 = proto_types.TxOutputType(
address='15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B',
amount=210000 - 100000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
out2 = proto_types.TxOutputType(
address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
amount=100000,
script_type=proto_types.PAYTOADDRESS,
)
@ -358,13 +377,15 @@ class TestMsgSigntx(common.TrezorTest):
# tx: 39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5
# index 1: 0.0254 BTC
inp1 = proto_types.TxInputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
inp1 = proto_types.TxInputType(
address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
# amount=100000,
prev_hash=TXHASH_c63e24,
prev_index=1,
)
inp2 = proto_types.TxInputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
inp2 = proto_types.TxInputType(
address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
# amount=2540000,
prev_hash=TXHASH_39a29e,
prev_index=1,
@ -373,7 +394,8 @@ class TestMsgSigntx(common.TrezorTest):
outputs = []
cnt = 255
for _ in range(cnt):
out = proto_types.TxOutputType(address='1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h',
out = proto_types.TxOutputType(
address='1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h',
amount=(100000 + 2540000 - 39000) // cnt,
script_type=proto_types.PAYTOADDRESS,
)
@ -424,13 +446,15 @@ class TestMsgSigntx(common.TrezorTest):
# tx: 1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6
# input 0: 1.0 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 1HWDaLTpTCTtRWyWqZkzWx1wex5NKyncLW
inp1 = proto_types.TxInputType(
address_n=[0], # 1HWDaLTpTCTtRWyWqZkzWx1wex5NKyncLW
# amount=100000000,
prev_hash=TXHASH_157041,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=100000000 - 510000,
script_type=proto_types.PAYTOADDRESS,
)
@ -461,13 +485,15 @@ class TestMsgSigntx(common.TrezorTest):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=400000,
script_type=proto_types.PAYTOADDRESS,
)
@ -494,13 +520,15 @@ class TestMsgSigntx(common.TrezorTest):
def test_p2sh(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=400000,
prev_hash=TXHASH_54aa56,
prev_index=1,
)
out1 = proto_types.TxOutputType(address='3DKGE1pvPpBAgZj94MbCinwmksewUNNYVR', # p2sh
out1 = proto_types.TxOutputType(
address='3DKGE1pvPpBAgZj94MbCinwmksewUNNYVR', # p2sh
amount=400000 - 10000,
script_type=proto_types.PAYTOSCRIPTHASH,
)
@ -536,24 +564,28 @@ class TestMsgSigntx(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
inp1 = proto_types.TxInputType(
address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
# amount=100000,
prev_hash=TXHASH_c6be22,
prev_index=1,
)
inp2 = proto_types.TxInputType(address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG
inp2 = proto_types.TxInputType(
address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG
# amount=110000,
prev_hash=TXHASH_58497a,
prev_index=1,
)
out1 = proto_types.TxOutputType(address='15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B',
out1 = proto_types.TxOutputType(
address='15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B',
amount=210000 - 100000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
out2 = proto_types.TxOutputType(
address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
amount=100000,
script_type=proto_types.PAYTOADDRESS,
)
@ -593,13 +625,15 @@ class TestMsgSigntx(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV
inp1 = proto_types.TxInputType(
address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV
# amount=390000,
prev_hash=TXHASH_d6da21,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='mm6FM31rM5Vc3sw5D7kztiBg3jHUzyqF1g',
out1 = proto_types.TxOutputType(
address='mm6FM31rM5Vc3sw5D7kztiBg3jHUzyqF1g',
amount=2500278230 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
@ -624,5 +658,6 @@ class TestMsgSigntx(common.TrezorTest):
# Accepted by network: tx
self.assertEqual(binascii.hexlify(serialized_tx), b'010000000136825bfdb78c8ede226c7c4f25a018e99a2c061d63c7fb425fca7c7d6721dad6000000006a473044022047845c366eb24f40be315c7815a154513c444c7989eb80f7ce7ff6aeb703d26a022007c1f5efadf67c5889634fd7ac39a7ce78bffac291673e8772ecd8389c901d9f01210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff01c6100795000000001976a9143d2496e67f5f57a924353da42d4725b318e7a8ea88ac00000000')
if __name__ == '__main__':
unittest.main()

View File

@ -21,23 +21,25 @@ import binascii
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
from trezorlib.client import CallException
from trezorlib.tx_api import TxApiTestnet
from trezorlib.ckd_public import deserialize
class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_p2sh(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/1/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
prev_hash=binascii.unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0,
script_type=proto_types.SPENDP2SHWITNESS,
)
out1 = proto_types.TxOutputType(address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
out1 = proto_types.TxOutputType(
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000,
script_type=proto_types.PAYTOADDRESS,
)
@ -67,14 +69,16 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_p2sh_change(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/1/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
prev_hash=binascii.unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0,
script_type=proto_types.SPENDP2SHWITNESS,
)
out1 = proto_types.TxOutputType(address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
out1 = proto_types.TxOutputType(
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000,
script_type=proto_types.PAYTOADDRESS,
)
@ -110,7 +114,8 @@ class TestMsgSigntxSegwit(common.TrezorTest):
m=2,
)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("999'/1'/1'/2/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("999'/1'/1'/2/0"),
prev_hash=binascii.unhexlify('9c31922be756c06d02167656465c8dc83bb553bf386a3f478ae65b5c021002be'),
prev_index=1,
script_type=proto_types.SPENDP2SHWITNESS,
@ -152,5 +157,6 @@ class TestMsgSigntxSegwit(common.TrezorTest):
self.assertEqual(binascii.hexlify(serialized_tx), b'01000000000101be0210025c5be68a473f6a38bf53b53bc88d5c46567616026dc056e72b92319c01000000232200201e8dda334f11171190b3da72e526d441491464769679a319a2f011da5ad312a1ffffffff01887d1800000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac040047304402205b44c20cf2681690edaaf7cd2e30d4704124dd8b7eb1fb7f459d3906c3c374a602205ca359b6544ce2c101c979899c782f7d141c3b0454ea69202b1fb4c09d3b715701473044022052fafa64022554ae436dbf781e550bf0d326fef31eea1438350b3ff1940a180102202851bd19203b7fe8582a9ef52e82aa9f61cd52d4bcedfe6dcc0cf782468e6a8e01695221038e81669c085a5846e68e03875113ddb339ecbb7cb11376d4163bca5dc2e2a0c1210348c5c3be9f0e6cf1954ded1c0475beccc4d26aaa9d0cce2dd902538ff1018a112103931140ebe0fbbb7df0be04ed032a54e9589e30339ba7bbb8b0b71b15df1294da53ae00000000')
if __name__ == '__main__':
unittest.main()

View File

@ -21,22 +21,24 @@ import binascii
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
from trezorlib.client import CallException
from trezorlib.tx_api import TxApiTestnet
from trezorlib.ckd_public import deserialize
class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_p2sh(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/1/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
prev_hash=binascii.unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0,
script_type=proto_types.SPENDP2SHWITNESS,
)
out1 = proto_types.TxOutputType(address='QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i',
out1 = proto_types.TxOutputType(
address='QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i',
amount=12300000,
script_type=proto_types.PAYTOADDRESS,
)
@ -66,14 +68,16 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_p2sh_change(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/1/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
prev_hash=binascii.unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0,
script_type=proto_types.SPENDP2SHWITNESS,
)
out1 = proto_types.TxOutputType(address='QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i',
out1 = proto_types.TxOutputType(
address='QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i',
amount=12300000,
script_type=proto_types.PAYTOADDRESS,
)
@ -102,14 +106,16 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_native(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/0/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/0/0"),
# QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i
amount=12300000,
prev_hash=binascii.unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'),
prev_index=0,
script_type=proto_types.SPENDWITNESS,
)
out1 = proto_types.TxOutputType(address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
out1 = proto_types.TxOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000,
script_type=proto_types.PAYTOADDRESS,
)
@ -139,14 +145,16 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_native_change(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/0/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/0/0"),
# QWywnqNMsMNavbCgMYiQLa91ApvsVRoaqt1i
amount=12300000,
prev_hash=binascii.unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'),
prev_index=0,
script_type=proto_types.SPENDWITNESS,
)
out1 = proto_types.TxOutputType(address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
out1 = proto_types.TxOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000,
script_type=proto_types.PAYTOADDRESS,
)
@ -175,21 +183,24 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_both(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/1/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=111145789,
prev_hash=binascii.unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'),
prev_index=1,
script_type=proto_types.SPENDP2SHWITNESS,
)
inp2 = proto_types.TxInputType(address_n=self.client.expand_path("49'/1'/0'/1/0"),
inp2 = proto_types.TxInputType(
address_n=self.client.expand_path("49'/1'/0'/1/0"),
# QWzGpyMkAEvmkSVprBzRRVQMP6UPp17q4kQn
amount=7289000,
prev_hash=binascii.unhexlify('65b811d3eca0fe6915d9f2d77c86c5a7f19bf66b1b1253c2c51cb4ae5f0c017b'),
prev_index=1,
script_type=proto_types.SPENDWITNESS,
)
out1 = proto_types.TxOutputType(address='QWzCpc1NeTN7hNDzK9sQQ9yrTQP8zh5Hef5J',
out1 = proto_types.TxOutputType(
address='QWzCpc1NeTN7hNDzK9sQQ9yrTQP8zh5Hef5J',
amount=12300000,
script_type=proto_types.PAYTOADDRESS,
)
@ -200,10 +211,12 @@ class TestMsgSigntxSegwit(common.TrezorTest):
script_type=proto_types.PAYTOADDRESS,
amount=45600000,
)
out3 = proto_types.TxOutputType(address='mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q',
out3 = proto_types.TxOutputType(
address='mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q',
amount=111145789 + 7289000 - 11000 - 12300000 - 45600000,
script_type=proto_types.PAYTOADDRESS,
)
with self.client:
self.client.set_expected_responses([
proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
@ -232,14 +245,15 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_multisig_1(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
nodes = map(lambda index : self.client.get_public_node(self.client.expand_path("999'/1'/"+str(index)+"'")), range(1,4))
nodes = map(lambda index: self.client.get_public_node(self.client.expand_path("999'/1'/%d'" % index)), range(1, 4))
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=map(lambda n: proto_types.HDNodePathType(node=deserialize(n.xpub), address_n=[2, 0]), nodes),
signatures=[b'', b'', b''],
m=2,
)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("999'/1'/1'/2/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("999'/1'/1'/2/0"),
prev_hash=binascii.unhexlify('9c31922be756c06d02167656465c8dc83bb553bf386a3f478ae65b5c021002be'),
prev_index=1,
script_type=proto_types.SPENDP2SHWITNESS,
@ -247,9 +261,11 @@ class TestMsgSigntxSegwit(common.TrezorTest):
amount=1610436
)
out1 = proto_types.TxOutputType(address='T7nZJt6QbGJy6Hok4EF2LqtJPcT7z7VFSrSysGS3tEqCfDPwizqy4',
out1 = proto_types.TxOutputType(
address='T7nZJt6QbGJy6Hok4EF2LqtJPcT7z7VFSrSysGS3tEqCfDPwizqy4',
amount=1605000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses([
@ -285,14 +301,15 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_multisig_2(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
nodes = map(lambda index : self.client.get_public_node(self.client.expand_path("999'/1'/"+str(index)+"'")), range(1,4))
nodes = map(lambda index: self.client.get_public_node(self.client.expand_path("999'/1'/%d'" % index)), range(1, 4))
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=map(lambda n: proto_types.HDNodePathType(node=deserialize(n.xpub), address_n=[2, 1]), nodes),
signatures=[b'', b'', b''],
m=2,
)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("999'/1'/2'/2/1"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("999'/1'/2'/2/1"),
prev_hash=binascii.unhexlify('f41cbedd8becee05a830f418d13aa665125464547db5c7a6cd28f21639fe1228'),
prev_index=0,
script_type=proto_types.SPENDWITNESS,
@ -300,9 +317,11 @@ class TestMsgSigntxSegwit(common.TrezorTest):
amount=1605000
)
out1 = proto_types.TxOutputType(address='T7nY3A3kewpDKumsdhonP4TBDfTXFSc2RNhZxkqmeeszRDHjM5yUn',
out1 = proto_types.TxOutputType(
address='T7nY3A3kewpDKumsdhonP4TBDfTXFSc2RNhZxkqmeeszRDHjM5yUn',
amount=1604000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses([
@ -338,7 +357,7 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_multisig_3_change(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
nodes = map(lambda index : self.client.get_public_node(self.client.expand_path("999'/1'/"+str(index)+"'")), range(1,4))
nodes = map(lambda index: self.client.get_public_node(self.client.expand_path("999'/1'/%d'" % index)), range(1, 4))
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=map(lambda n: proto_types.HDNodePathType(node=deserialize(n.xpub), address_n=[2, 0]), nodes),
signatures=[b'', b'', b''],
@ -350,7 +369,8 @@ class TestMsgSigntxSegwit(common.TrezorTest):
m=2,
)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("999'/1'/1'/2/0"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("999'/1'/1'/2/0"),
prev_hash=binascii.unhexlify('c9348040bbc2024e12dcb4a0b4806b0398646b91acf314da028c3f03dd0179fc'),
prev_index=0,
script_type=proto_types.SPENDWITNESS,
@ -358,10 +378,12 @@ class TestMsgSigntxSegwit(common.TrezorTest):
amount=1604000
)
out1 = proto_types.TxOutputType(address_n=self.client.expand_path("999'/1'/1'/1/1"),
out1 = proto_types.TxOutputType(
address_n=self.client.expand_path("999'/1'/1'/1/1"),
amount=1603000,
multisig=multisig2,
script_type=proto_types.PAYTOP2SHWITNESS)
script_type=proto_types.PAYTOP2SHWITNESS
)
with self.client:
self.client.set_expected_responses([
@ -396,7 +418,7 @@ class TestMsgSigntxSegwit(common.TrezorTest):
def test_send_multisig_4_change(self):
self.setup_mnemonic_allallall()
self.client.set_tx_api(TxApiTestnet)
nodes = map(lambda index : self.client.get_public_node(self.client.expand_path("999'/1'/"+str(index)+"'")), range(1,4))
nodes = map(lambda index: self.client.get_public_node(self.client.expand_path("999'/1'/%d'" % index)), range(1, 4))
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=map(lambda n: proto_types.HDNodePathType(node=deserialize(n.xpub), address_n=[1, 1]), nodes),
signatures=[b'', b'', b''],
@ -408,7 +430,8 @@ class TestMsgSigntxSegwit(common.TrezorTest):
m=2,
)
inp1 = proto_types.TxInputType(address_n=self.client.expand_path("999'/1'/1'/1/1"),
inp1 = proto_types.TxInputType(
address_n=self.client.expand_path("999'/1'/1'/1/1"),
prev_hash=binascii.unhexlify('31bc1c88ce6ae337a6b3057a16d5bad0b561ad1dfc047d0a7fbb8814668f91e5'),
prev_index=0,
script_type=proto_types.SPENDP2SHWITNESS,
@ -416,10 +439,12 @@ class TestMsgSigntxSegwit(common.TrezorTest):
amount=1603000
)
out1 = proto_types.TxOutputType(address_n=self.client.expand_path("999'/1'/1'/1/2"),
out1 = proto_types.TxOutputType(
address_n=self.client.expand_path("999'/1'/1'/1/2"),
amount=1602000,
multisig=multisig2,
script_type=proto_types.PAYTOWITNESS)
script_type=proto_types.PAYTOWITNESS
)
with self.client:
self.client.set_expected_responses([
@ -451,5 +476,6 @@ class TestMsgSigntxSegwit(common.TrezorTest):
# c0bf56060a109624b4635222696d94a7d533cacea1b3f8245417a4348c045829
self.assertEqual(binascii.hexlify(serialized_tx), b'01000000000101e5918f661488bb7f0a7d04fc1dad61b5d0bad5167a05b3a637e36ace881cbc3100000000232200205b9824093eaf5cdcf8247c00dc0b557a7720957828fcde8384ac11f80a91f403ffffffff01d071180000000000220020e77caf5fbef07b1e461475c02afd4aed877693263d69c81e14617304349b629a040047304402204832553b0da1009da496881e58e8e2e41010cfe5c0161623048093f1b1a817b7022020dad8bf887acf574af80bfe4b39cd24e95019fd5e6b8ae967471e21ddc67354014830450221009e5d60847e7275edcf4619ed8ee462c56a042eef75d17da2d44e6b13d78e50e50220665195492900ef87a5eb8a924fa0ac9afc4fc75ca704ff356dc3a213979970c80169522103f4040006e3561b3e76c6d4113225c84748ab9d55ffd23f9578ab4c18fb0c3b9721020975f2e6922897ff6b80da6412a8d6ebd67e33c9611d081656a53ef967964e5021026b0546f23a6ce6b756c2c30b4176ce6f1c3268744f7aca82668d5116c4f764e453ae00000000')
if __name__ == '__main__':
unittest.main()

View File

@ -22,9 +22,9 @@ import binascii
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
from trezorlib.client import CallException
from trezorlib.tx_api import TxApiZcashTestnet
class TestMsgSigntx(common.TrezorTest):
def test_one_one_fee(self):
@ -33,13 +33,15 @@ class TestMsgSigntx(common.TrezorTest):
# tx: 93373e63cc626c4a7d049ad775d6511bb5eba985f142db660c9b9f955c722f5c
# input 0: 1.234567 TAZ
inp1 = proto_types.TxInputType(address_n=[2147483692, 2147483649, 2147483648, 0, 0], # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
inp1 = proto_types.TxInputType(
address_n=[2147483692, 2147483649, 2147483648, 0, 0], # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
# amount=123456700,
prev_hash=binascii.unhexlify(b'93373e63cc626c4a7d049ad775d6511bb5eba985f142db660c9b9f955c722f5c'),
prev_index=0,
)
out1 = proto_types.TxOutputType(address='tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z',
out1 = proto_types.TxOutputType(
address='tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z',
amount=123456700 - 1940,
script_type=proto_types.PAYTOADDRESS,
)
@ -68,5 +70,6 @@ class TestMsgSigntx(common.TrezorTest):
# Accepted by network: tx dcc2a10894e0e8a785c2afd4de2d958207329b9acc2b987fd768a09c5efc4547
self.assertEqual(binascii.hexlify(serialized_tx), b'01000000015c2f725c959f9b0c66db42f185a9ebb51b51d675d79a047d4a6c62cc633e3793000000006a4730440220670b2b63d749a7038f9aea6ddf0302fe63bdcad93dafa4a89a1f0e7300ae2484022002c50af43fd867490cea0c527273c5828ff1b9a5115678f155a1830737cf29390121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff0128c55b07000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000')
if __name__ == '__main__':
unittest.main()

View File

@ -21,7 +21,6 @@ import common
import binascii
import base64
from trezorlib.client import CallException
class TestMsgVerifymessage(common.TrezorTest):
@ -164,5 +163,6 @@ class TestMsgVerifymessage(common.TrezorTest):
self.assertTrue(res_nfc)
"""
if __name__ == '__main__':
unittest.main()

View File

@ -21,6 +21,7 @@ import common
from trezorlib import messages_pb2 as proto
class TestDeviceWipe(common.TrezorTest):
def test_wipe_device(self):
self.setup_mnemonic_pin_passphrase()
@ -39,5 +40,6 @@ class TestDeviceWipe(common.TrezorTest):
self.assertEqual(features.passphrase_protection, False)
self.assertNotEqual(features.device_id, device_id)
if __name__ == '__main__':
unittest.main()

View File

@ -21,7 +21,6 @@ from __future__ import print_function
import unittest
import common
import binascii
import itertools
import trezorlib.messages_pb2 as proto
import trezorlib.ckd_public as bip32
@ -33,6 +32,7 @@ from trezorlib.client import CallException
# https://sx.dyne.org/multisig.html
#
class TestMultisig(common.TrezorTest):
def test_2_of_3(self):
@ -62,24 +62,29 @@ class TestMultisig(common.TrezorTest):
node = bip32.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node, address_n=[1]),
proto_types.HDNodePathType(node=node, address_n=[2]),
proto_types.HDNodePathType(node=node, address_n=[3])],
proto_types.HDNodePathType(node=node, address_n=[3])
],
signatures=[b'', b'', b''],
m=2,
)
# Let's go to sign with key 1
inp1 = proto_types.TxInputType(address_n=[1],
inp1 = proto_types.TxInputType(
address_n=[1],
prev_hash=binascii.unhexlify('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52'),
prev_index=1,
script_type=proto_types.SPENDMULTISIG,
multisig=multisig,
)
out1 = proto_types.TxOutputType(address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
out1 = proto_types.TxOutputType(
address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses([
@ -106,15 +111,18 @@ class TestMultisig(common.TrezorTest):
# Let's do second signature using 3rd key
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node, address_n=[1]),
proto_types.HDNodePathType(node=node, address_n=[2]),
proto_types.HDNodePathType(node=node, address_n=[3])],
proto_types.HDNodePathType(node=node, address_n=[3])
],
signatures=[signatures1[0], b'', b''], # Fill signature from previous signing process
m=2,
)
# Let's do a second signature with key 3
inp3 = proto_types.TxInputType(address_n=[3],
inp3 = proto_types.TxInputType(
address_n=[3],
prev_hash=binascii.unhexlify('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52'),
prev_index=1,
script_type=proto_types.SPENDMULTISIG,
@ -169,9 +177,11 @@ class TestMultisig(common.TrezorTest):
signatures = [b''] * 15
out1 = proto_types.TxOutputType(address='17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1',
out1 = proto_types.TxOutputType(
address='17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1',
amount=10000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
for x in range(15):
multisig = proto_types.MultisigRedeemScriptType(
@ -180,7 +190,8 @@ class TestMultisig(common.TrezorTest):
m=15,
)
inp1 = proto_types.TxInputType(address_n=[x],
inp1 = proto_types.TxInputType(
address_n=[x],
prev_hash=binascii.unhexlify('6189e3febb5a21cee8b725aa1ef04ffce7e609448446d3a8d6f483c634ef5315'),
prev_index=1,
script_type=proto_types.SPENDMULTISIG,
@ -214,24 +225,29 @@ class TestMultisig(common.TrezorTest):
node = bip32.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
multisig = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node, address_n=[1]),
proto_types.HDNodePathType(node=node, address_n=[2]),
proto_types.HDNodePathType(node=node, address_n=[3])],
proto_types.HDNodePathType(node=node, address_n=[3])
],
signatures=[b'', b'', b''],
m=2,
)
# Let's go to sign with key 10, which is NOT in pubkeys
inp1 = proto_types.TxInputType(address_n=[10],
inp1 = proto_types.TxInputType(
address_n=[10],
prev_hash=binascii.unhexlify('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52'),
prev_index=1,
script_type=proto_types.SPENDMULTISIG,
multisig=multisig,
)
out1 = proto_types.TxOutputType(address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
out1 = proto_types.TxOutputType(
address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
# It should throw Failure 'Pubkey not found in multisig script'

View File

@ -19,12 +19,11 @@
import unittest
import common
import binascii
import itertools
import trezorlib.messages_pb2 as proto
import trezorlib.ckd_public as bip32
import trezorlib.types_pb2 as proto_types
from trezorlib.client import CallException
class TestMultisigChange(common.TrezorTest):
@ -63,44 +62,53 @@ class TestMultisigChange(common.TrezorTest):
# input 1: 0.001 BTC
multisig_in1 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node_ext1, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node_ext1, address_n=[1]),
proto_types.HDNodePathType(node=node_ext2, address_n=[1]),
proto_types.HDNodePathType(node=node_int, address_n=[1])],
proto_types.HDNodePathType(node=node_int, address_n=[1])
],
signatures=[b'', b'', b''],
m=2,
)
multisig_in2 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node_ext1, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node_ext1, address_n=[1]),
proto_types.HDNodePathType(node=node_int, address_n=[1]),
proto_types.HDNodePathType(node=node_ext2, address_n=[1])],
proto_types.HDNodePathType(node=node_ext2, address_n=[1])
],
signatures=[b'', b'', b''],
m=2,
)
multisig_in3 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=node_ext1, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=node_ext1, address_n=[1]),
proto_types.HDNodePathType(node=node_ext3, address_n=[1]),
proto_types.HDNodePathType(node=node_int, address_n=[1])],
proto_types.HDNodePathType(node=node_int, address_n=[1])
],
signatures=[b'', b'', b''],
m=2,
)
inp1 = proto_types.TxInputType(address_n=[1],
inp1 = proto_types.TxInputType(
address_n=[1],
prev_hash=binascii.unhexlify('d1d08ea63255af4ad16b098e9885a252632086fa6be53301521d05253ce8a73d'),
prev_index=0,
script_type=proto_types.SPENDMULTISIG,
multisig=multisig_in1,
)
inp2 = proto_types.TxInputType(address_n=[1],
inp2 = proto_types.TxInputType(
address_n=[1],
prev_hash=binascii.unhexlify('a6e2829d089cee47e481b1a753a53081b40738cc87e38f1d9b23ab57d9ad4396'),
prev_index=0,
script_type=proto_types.SPENDMULTISIG,
multisig=multisig_in2,
)
inp3 = proto_types.TxInputType(address_n=[1],
inp3 = proto_types.TxInputType(
address_n=[1],
prev_hash=binascii.unhexlify('e4bc1ae5e5007a08f2b3926fe11c66612e8f73c6b00c69c7027213b84d259be3'),
prev_index=1,
script_type=proto_types.SPENDMULTISIG,
@ -152,13 +160,17 @@ class TestMultisigChange(common.TrezorTest):
def test_external_external(self):
self.setup_mnemonic_nopin_nopassphrase()
out1 = proto_types.TxOutputType(address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
out1 = proto_types.TxOutputType(
address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
out2 = proto_types.TxOutputType(address='17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1',
out2 = proto_types.TxOutputType(
address='17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
@ -170,13 +182,17 @@ class TestMultisigChange(common.TrezorTest):
def test_external_internal(self):
self.setup_mnemonic_nopin_nopassphrase()
out1 = proto_types.TxOutputType(address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
out1 = proto_types.TxOutputType(
address='12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
out2 = proto_types.TxOutputType(address_n=[4],
out2 = proto_types.TxOutputType(
address_n=[4],
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2, change=2))
@ -188,13 +204,17 @@ class TestMultisigChange(common.TrezorTest):
def test_internal_external(self):
self.setup_mnemonic_nopin_nopassphrase()
out1 = proto_types.TxOutputType(address_n=[4],
out1 = proto_types.TxOutputType(
address_n=[4],
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
out2 = proto_types.TxOutputType(address='17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1',
out2 = proto_types.TxOutputType(
address='17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2, change=1))
@ -206,13 +226,17 @@ class TestMultisigChange(common.TrezorTest):
def test_multisig_external_external(self):
self.setup_mnemonic_nopin_nopassphrase()
out1 = proto_types.TxOutputType(address='3796Q9jVirg2KY1WQRqtmHKXCoSk8MB7Td',
out1 = proto_types.TxOutputType(
address='3796Q9jVirg2KY1WQRqtmHKXCoSk8MB7Td',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
out2 = proto_types.TxOutputType(address='3CTPCg3ksh59jWt9zQpTPHCSQDCdJoQQ9d',
out2 = proto_types.TxOutputType(
address='3CTPCg3ksh59jWt9zQpTPHCSQDCdJoQQ9d',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
@ -225,21 +249,27 @@ class TestMultisigChange(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
multisig_out1 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=self.node_int, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=self.node_int, address_n=[1]),
proto_types.HDNodePathType(node=self.node_ext1, address_n=[1]),
proto_types.HDNodePathType(node=self.node_ext2, address_n=[1])],
proto_types.HDNodePathType(node=self.node_ext2, address_n=[1])
],
signatures=[b'', b'', b''],
m=2,
)
out1 = proto_types.TxOutputType(address_n=[1],
out1 = proto_types.TxOutputType(
address_n=[1],
multisig=multisig_out1,
amount=100000,
script_type=proto_types.PAYTOMULTISIG)
script_type=proto_types.PAYTOMULTISIG
)
out2 = proto_types.TxOutputType(address='3CTPCg3ksh59jWt9zQpTPHCSQDCdJoQQ9d',
out2 = proto_types.TxOutputType(
address='3CTPCg3ksh59jWt9zQpTPHCSQDCdJoQQ9d',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2, change=1))
@ -252,21 +282,27 @@ class TestMultisigChange(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
multisig_out2 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=self.node_int, address_n=[2]),
pubkeys=[
proto_types.HDNodePathType(node=self.node_int, address_n=[2]),
proto_types.HDNodePathType(node=self.node_ext1, address_n=[2]),
proto_types.HDNodePathType(node=self.node_ext2, address_n=[2])],
proto_types.HDNodePathType(node=self.node_ext2, address_n=[2])
],
signatures=[b'', b'', b''],
m=2,
)
out1 = proto_types.TxOutputType(address='37Wf955dcCaFSJmiNaGpacczMwj7iC8JMx',
out1 = proto_types.TxOutputType(
address='37Wf955dcCaFSJmiNaGpacczMwj7iC8JMx',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
out2 = proto_types.TxOutputType(address_n=[2],
out2 = proto_types.TxOutputType(
address_n=[2],
multisig=multisig_out2,
amount=100000,
script_type=proto_types.PAYTOMULTISIG)
script_type=proto_types.PAYTOMULTISIG
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2, change=2))
@ -279,21 +315,27 @@ class TestMultisigChange(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
multisig_out2 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=self.node_int, address_n=[2]),
pubkeys=[
proto_types.HDNodePathType(node=self.node_int, address_n=[2]),
proto_types.HDNodePathType(node=self.node_ext1, address_n=[2]),
proto_types.HDNodePathType(node=self.node_ext3, address_n=[2])],
proto_types.HDNodePathType(node=self.node_ext3, address_n=[2])
],
signatures=[b'', b'', b''],
m=2,
)
out1 = proto_types.TxOutputType(address='3796Q9jVirg2KY1WQRqtmHKXCoSk8MB7Td',
out1 = proto_types.TxOutputType(
address='3796Q9jVirg2KY1WQRqtmHKXCoSk8MB7Td',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
out2 = proto_types.TxOutputType(address_n=[2],
out2 = proto_types.TxOutputType(
address_n=[2],
multisig=multisig_out2,
amount=100000,
script_type=proto_types.PAYTOMULTISIG)
script_type=proto_types.PAYTOMULTISIG
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
@ -306,21 +348,27 @@ class TestMultisigChange(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
multisig_out1 = proto_types.MultisigRedeemScriptType(
pubkeys=[proto_types.HDNodePathType(node=self.node_ext1, address_n=[1]),
pubkeys=[
proto_types.HDNodePathType(node=self.node_ext1, address_n=[1]),
proto_types.HDNodePathType(node=self.node_ext2, address_n=[1]),
proto_types.HDNodePathType(node=self.node_int, address_n=[1])],
proto_types.HDNodePathType(node=self.node_int, address_n=[1])
],
signatures=[b'', b'', b''],
m=2,
)
out1 = proto_types.TxOutputType(address_n=[1],
out1 = proto_types.TxOutputType(
address_n=[1],
multisig=multisig_out1,
amount=100000,
script_type=proto_types.PAYTOMULTISIG)
script_type=proto_types.PAYTOMULTISIG
)
out2 = proto_types.TxOutputType(address='3CTPCg3ksh59jWt9zQpTPHCSQDCdJoQQ9d',
out2 = proto_types.TxOutputType(
address='3CTPCg3ksh59jWt9zQpTPHCSQDCdJoQQ9d',
amount=100000,
script_type=proto_types.PAYTOADDRESS)
script_type=proto_types.PAYTOADDRESS
)
with self.client:
self.client.set_expected_responses(self._responses(self.inp1, self.inp3))
@ -328,5 +376,6 @@ class TestMultisigChange(common.TrezorTest):
self.assertEqual(binascii.hexlify(serialized_tx), b'01000000023da7e83c25051d520133e56bfa86206352a285988e096bd14aaf5532a68ed0d100000000b40047304402204b7d6c7e9feef91209cbdf4deaf855696dc22a40e57bd3eafd5e00b0ee41d9de0220262c5a05d0b46ef98fddfef3831b3ebb6841ffbeb10666f8fb6f8d2e3023e30d014c69522102c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e210388460dc439f4c8f5bcfc268c36e11b4375cad5c3535c336cfdf8c32c3afad5c1210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a653aeffffffffe39b254db8137202c7690cb0c6738f2e61661ce16f92b3f2087a00e5e51abce401000000b500483045022100bb2118da21c8a84f115b655f640f269a40be77ae2c0af9c5ffd8260a85dbfc7702202e7b5b6c05b8f50bd879dbee88828e80e85448d686b63a1a50e99d921923f6f5014c69522102c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e2102e0c21e2a7cf00b94c5421725acff97f9826598b91f2340c5ddda730caca7d648210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a653aeffffffff02a08601000000000017a914a4efc33d43d7a8a0040182c76ab624ff862f50d287a08601000000000017a9147615527d78854293edadf83682ea26937f8a51bb8700000000')
if __name__ == '__main__':
unittest.main()

View File

@ -17,9 +17,8 @@
# along with this library. If not, see <http://www.gnu.org/licenses/>.
import unittest
import common
import binascii
import itertools
import common
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
@ -37,18 +36,21 @@ class TestOpReturn(common.TrezorTest):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
out2 = proto_types.TxOutputType(op_return_data=b'test of the op_return data',
out2 = proto_types.TxOutputType(
op_return_data=b'test of the op_return data',
amount=0,
script_type=proto_types.PAYTOOPRETURN,
)
@ -81,18 +83,21 @@ class TestOpReturn(common.TrezorTest):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
out1 = proto_types.TxOutputType(op_return_data=b'test of the op_return data',
out1 = proto_types.TxOutputType(
op_return_data=b'test of the op_return data',
amount=10000,
script_type=proto_types.PAYTOOPRETURN,
)
@ -109,5 +114,6 @@ class TestOpReturn(common.TrezorTest):
])
self.assertRaises(CallException, self.client.sign_tx, 'Bitcoin', [inp1, ], [out1, ])
if __name__ == '__main__':
unittest.main()

View File

@ -23,19 +23,21 @@ import unittest
import common
from trezorlib import messages_pb2 as proto
from trezorlib import types_pb2 as types
from trezorlib.client import PinException, CallException
from trezorlib.client import PinException
# FIXME TODO Add passphrase tests
class TestProtectCall(common.TrezorTest):
def _some_protected_call(self, button, pin, passphrase):
# This method perform any call which have protection in the device
res = self.client.ping('random data',
res = self.client.ping(
'random data',
button_protection=button,
pin_protection=pin,
passphrase_protection=passphrase)
passphrase_protection=passphrase
)
self.assertEqual(res, 'random data')
"""
@ -131,5 +133,6 @@ class TestProtectCall(common.TrezorTest):
self.assertRaises(PinException, self._some_protected_call, False, True, False)
test_backoff(attempt, start)
if __name__ == '__main__':
unittest.main()

View File

@ -38,61 +38,75 @@ class TestProtectionLevels(common.TrezorTest):
def test_apply_settings(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.PinMatrixRequest(),
self.client.set_expected_responses([
proto.PinMatrixRequest(),
proto.ButtonRequest(),
proto.Success(),
proto.Features()]) # TrezorClient reinitializes device
proto.Features()
]) # TrezorClient reinitializes device
self.client.apply_settings(label='nazdar')
def test_change_pin(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.ButtonRequest(),
self.client.set_expected_responses([
proto.ButtonRequest(),
proto.PinMatrixRequest(),
proto.PinMatrixRequest(),
proto.PinMatrixRequest(),
proto.Success(),
proto.Features()])
proto.Features()
])
self.client.change_pin()
def test_ping(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.ButtonRequest(),
self.client.set_expected_responses([
proto.ButtonRequest(),
proto.PinMatrixRequest(),
proto.PassphraseRequest(),
proto.Success()])
proto.Success()
])
self.client.ping('msg', True, True, True)
def test_get_entropy(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.ButtonRequest(),
proto.Entropy()])
self.client.set_expected_responses([
proto.ButtonRequest(),
proto.Entropy()
])
self.client.get_entropy(10)
def test_get_public_key(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.PinMatrixRequest(),
self.client.set_expected_responses([
proto.PinMatrixRequest(),
proto.PassphraseRequest(),
proto.PublicKey()])
proto.PublicKey()
])
self.client.get_public_node([])
def test_get_address(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.PinMatrixRequest(),
self.client.set_expected_responses([
proto.PinMatrixRequest(),
proto.PassphraseRequest(),
proto.Address()])
proto.Address()
])
self.client.get_address('Bitcoin', [])
def test_wipe_device(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.ButtonRequest(),
self.client.set_expected_responses([
proto.ButtonRequest(),
proto.Success(),
proto.Features()])
proto.Features()
])
self.client.wipe_device()
def test_load_device(self):
@ -108,10 +122,7 @@ class TestProtectionLevels(common.TrezorTest):
def test_reset_device(self):
with self.client:
self.client.set_expected_responses([proto.EntropyRequest()] + \
[proto.ButtonRequest()] * 24 + \
[proto.Success(),
proto.Features()])
self.client.set_expected_responses([proto.EntropyRequest()] + [proto.ButtonRequest()] * 24 + [proto.Success(), proto.Features()])
self.client.reset_device(False, 128, True, False, 'label', 'english')
# This must fail, because device is already initialized
@ -120,9 +131,7 @@ class TestProtectionLevels(common.TrezorTest):
def test_recovery_device(self):
with self.client:
self.client.set_mnemonic(self.mnemonic12)
self.client.set_expected_responses([proto.WordRequest()] * 24 + \
[proto.Success(),
proto.Features()])
self.client.set_expected_responses([proto.WordRequest()] * 24 + [proto.Success(), proto.Features()])
self.client.recovery_device(12, False, False, 'label', 'english')
# This must fail, because device is already initialized
@ -131,10 +140,12 @@ class TestProtectionLevels(common.TrezorTest):
def test_sign_message(self):
with self.client:
self.setup_mnemonic_pin_passphrase()
self.client.set_expected_responses([proto.ButtonRequest(),
self.client.set_expected_responses([
proto.ButtonRequest(),
proto.PinMatrixRequest(),
proto.PassphraseRequest(),
proto.MessageSignature()])
proto.MessageSignature()
])
self.client.sign_message('Bitcoin', [], 'testing message')
def test_verify_message(self):
@ -179,12 +190,14 @@ class TestProtectionLevels(common.TrezorTest):
def test_signtx(self):
self.setup_mnemonic_pin_passphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = proto_types.TxOutputType(
address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
@ -215,5 +228,6 @@ class TestProtectionLevels(common.TrezorTest):
# def test_firmware_upload(self):
# pass
if __name__ == '__main__':
unittest.main()

View File

@ -19,18 +19,18 @@
from __future__ import print_function
import unittest
import common
import binascii
import sys
import common
import trezorlib.messages_pb2 as proto
import trezorlib.types_pb2 as proto_types
if sys.version_info < (3,):
def byteindex(data, index):
return ord(data[index])
else:
byteindex = lambda data, index: data[index]
def byteindex(data, index):
return data[index]
TXHASH_d5f65e = binascii.unhexlify(b'd5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')
@ -74,14 +74,16 @@ class TestZeroSig(common.TrezorTest):
def test_one_zero_signature(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto_types.TxOutputType(address_n=[177],
out1 = proto_types.TxOutputType(
address_n=[177],
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
@ -95,14 +97,16 @@ class TestZeroSig(common.TrezorTest):
def test_two_zero_signature(self):
self.setup_mnemonic_nopin_nopassphrase()
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
inp1 = proto_types.TxInputType(
address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
# Following address_n has been mined by 'test_mine_zero_signature'
out1 = proto_types.TxOutputType(address_n=[16518],
out1 = proto_types.TxOutputType(
address_n=[16518],
amount=390000 - 10000,
script_type=proto_types.PAYTOADDRESS,
)
@ -113,5 +117,6 @@ class TestZeroSig(common.TrezorTest):
# TREZOR must strip leading zero from signature
self.assertEqual(siglen, 66)
if __name__ == '__main__':
unittest.main()

View File

@ -19,7 +19,7 @@
import common
import unittest
from trezorlib.protobuf_json import json2pb, pb2json
from trezorlib.protobuf_json import pb2json
import trezorlib.messages_pb2 as msg

View File

@ -25,20 +25,20 @@ from trezorlib.tx_api import TxApiBitcoin, TxApiTestnet
class TestTxApi(unittest.TestCase):
def test_get(self):
tx = TxApiBitcoin.get_tx('39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5')
tx = TxApiBitcoin.get_tx('54aa5680dea781f45ebb536e53dffc526d68c0eb5c00547e323b2c32382dfba3')
tx = TxApiBitcoin.get_tx('58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e')
tx = TxApiBitcoin.get_tx('6189e3febb5a21cee8b725aa1ef04ffce7e609448446d3a8d6f483c634ef5315')
tx = TxApiBitcoin.get_tx('a6e2829d089cee47e481b1a753a53081b40738cc87e38f1d9b23ab57d9ad4396')
tx = TxApiBitcoin.get_tx('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52')
tx = TxApiBitcoin.get_tx('c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb')
tx = TxApiBitcoin.get_tx('c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c')
tx = TxApiBitcoin.get_tx('d1d08ea63255af4ad16b098e9885a252632086fa6be53301521d05253ce8a73d')
tx = TxApiBitcoin.get_tx('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')
tx = TxApiBitcoin.get_tx('e4bc1ae5e5007a08f2b3926fe11c66612e8f73c6b00c69c7027213b84d259be3')
TxApiBitcoin.get_tx('39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5')
TxApiBitcoin.get_tx('54aa5680dea781f45ebb536e53dffc526d68c0eb5c00547e323b2c32382dfba3')
TxApiBitcoin.get_tx('58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e')
TxApiBitcoin.get_tx('6189e3febb5a21cee8b725aa1ef04ffce7e609448446d3a8d6f483c634ef5315')
TxApiBitcoin.get_tx('a6e2829d089cee47e481b1a753a53081b40738cc87e38f1d9b23ab57d9ad4396')
TxApiBitcoin.get_tx('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52')
TxApiBitcoin.get_tx('c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb')
TxApiBitcoin.get_tx('c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c')
TxApiBitcoin.get_tx('d1d08ea63255af4ad16b098e9885a252632086fa6be53301521d05253ce8a73d')
TxApiBitcoin.get_tx('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')
TxApiBitcoin.get_tx('e4bc1ae5e5007a08f2b3926fe11c66612e8f73c6b00c69c7027213b84d259be3')
tx = TxApiTestnet.get_tx('6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54')
tx = TxApiTestnet.get_tx('d6da21677d7cca5f42fbc7631d062c9ae918a0254f7c6c22de8e8cb7fd5b8236')
TxApiTestnet.get_tx('6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54')
TxApiTestnet.get_tx('d6da21677d7cca5f42fbc7631d062c9ae918a0254f7c6c22de8e8cb7fd5b8236')
if __name__ == '__main__':

View File

@ -15,7 +15,7 @@ import json
import hashlib
import binascii
from trezorlib.client import TrezorClient, TrezorClientDebug
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
# Python2 vs Python3
@ -24,6 +24,7 @@ try:
except NameError:
pass
def wait_for_devices():
devices = HidTransport.enumerate()
while not len(devices):
@ -33,6 +34,7 @@ def wait_for_devices():
return devices
def choose_device(devices):
if not len(devices):
raise Exception("No TREZOR connected!")
@ -71,9 +73,10 @@ def choose_device(devices):
except:
raise Exception("Invalid choice, exiting...")
def main():
if not 'encfs_root' in os.environ:
if 'encfs_root' not in os.environ:
sys.stderr.write('\nThis is not a standalone script and is not meant to be run independently.\n')
sys.stderr.write('\nUsage: encfs --standard --extpass=./encfs_aes_getpass.py ~/.crypt ~/crypt\n')
sys.exit(1)
@ -122,5 +125,6 @@ def main():
print(passw)
if __name__ == '__main__':
main()

View File

@ -4,6 +4,7 @@ from __future__ import print_function
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
@ -30,5 +31,6 @@ def main():
client.close()
if __name__ == '__main__':
main()

View File

@ -2,9 +2,8 @@
from __future__ import print_function
from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient, TrezorDebugClient
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
import binascii
import sys
# usage examples
@ -15,6 +14,7 @@ import sys
# note that in order for this to work, your trezor device must
# be running a firmware that was built with debug link enabled
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
@ -46,5 +46,6 @@ def main():
client.close()
if __name__ == '__main__':
main()

View File

@ -2,11 +2,12 @@
from __future__ import print_function
from trezorlib.debuglink import DebugLink
from trezorlib.client import TrezorClient, TrezorDebugClient
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
import binascii
import sys
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
@ -24,8 +25,9 @@ def main():
client = TrezorClient(transport)
debug = DebugLink(debug_transport)
mem = debug.memory_write(int(sys.argv[1],16), binascii.unhexlify(sys.argv[2]), flash=True)
debug.memory_write(int(sys.argv[1], 16), binascii.unhexlify(sys.argv[2]), flash=True)
client.close()
if __name__ == '__main__':
main()

View File

@ -22,6 +22,7 @@ try:
except NameError:
pass
def generate_entropy(strength, internal_entropy, external_entropy):
'''
strength - length of produced seed. One of 128, 192, 256
@ -50,6 +51,7 @@ def generate_entropy(strength, internal_entropy, external_entropy):
return entropy_stripped
def main():
print(__doc__)
@ -72,5 +74,6 @@ def main():
print("Generated mnemonic is:", words)
if __name__ == '__main__':
main()

View File

@ -5,18 +5,19 @@
# push confirmation
from __future__ import print_function
import binascii
import io
import sys
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
def get_client():
devices = HidTransport.enumerate() # List all connected TREZORs on USB
if len(devices) == 0: # Check whether we found any
devices = HidTransport.enumerate() # list all connected TREZORs on USB
if len(devices) == 0: # check whether we found any
return None
transport = HidTransport(devices[0]) # Use first connected device
return TrezorClient(transport) # Creates object for communicating with TREZOR
transport = HidTransport(devices[0]) # use first connected device
return TrezorClient(transport) # creates object for communicating with TREZOR
def main():
client = get_client()
@ -35,5 +36,6 @@ def main():
client.close()
if __name__ == '__main__':
main()

View File

@ -20,20 +20,26 @@ from __future__ import print_function
import binascii
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
from trezorlib.tx_api import *
from trezorlib.tx_api import TxApiBitcoin, TxApiTestnet, TxApiLitecoin
from trezorlib import types_pb2 as types
# Python2 vs Python3
try:
input = raw_input
except NameError:
pass
def get_client():
devices = HidTransport.enumerate() # List all connected TREZORs on USB
if len(devices) == 0: # Check whether we found any
devices = HidTransport.enumerate() # list all connected TREZORs on USB
if len(devices) == 0: # check whether we found any
return None
transport = HidTransport(devices[0]) # Use first connected device
return TrezorClient(transport) # Creates object for communicating with TREZOR
transport = HidTransport(devices[0]) # use first connected device
return TrezorClient(transport) # creates object for communicating with TREZOR
def get_txapi():
coin = raw_input('Which coin {Bitcoin, Testnet, Litecoin}? ').strip()
coin = input('Which coin {Bitcoin, Testnet, Litecoin}? ').strip()
if coin not in {'Bitcoin', 'Testnet', 'Litecoin'}:
return None, None
txapi_lookup = {
@ -66,11 +72,11 @@ def main():
while True:
print()
prev_in_hash = raw_input('Previous input hash (empty to move on): ').strip()
prev_in_hash = input('Previous input hash (empty to move on): ').strip()
if prev_in_hash == '':
break
prev_in_vout = raw_input('Previous input index: ').strip()
addrn = raw_input("Node path to sign with (e.g.- %s/0'/0/0): " % coin).strip()
prev_in_vout = input('Previous input index: ').strip()
addrn = input("Node path to sign with (e.g.- %s/0'/0/0): " % coin).strip()
inputs.append(types.TxInputType(
prev_hash=binascii.unhexlify(prev_in_hash),
prev_index=int(prev_in_vout, 10),
@ -81,10 +87,10 @@ def main():
while True:
print()
out_addr = raw_input('Pay to address (empty to move on): ').strip()
out_addr = input('Pay to address (empty to move on): ').strip()
if out_addr == '':
break
out_amount = raw_input('Amount (in satoshis): ').strip()
out_amount = input('Amount (in satoshis): ').strip()
outputs.append(types.TxOutputType(
amount=int(out_amount, 10),
script_type=types.PAYTOADDRESS,

View File

@ -10,4 +10,4 @@ deps =
-rrequirements.txt
commands =
python -m compileall trezorlib/
python trezorctl
python trezorctl --help

View File

@ -36,7 +36,8 @@ if sys.version_info < (3,):
def byteindex(data, index):
return ord(data[index])
else:
byteindex = lambda data, index: data[index]
def byteindex(data, index):
return data[index]
def point_to_pubkey(point):
@ -46,6 +47,7 @@ def point_to_pubkey(point):
vk = x_str + y_str
return struct.pack('B', (byteindex(vk, 63) & 1) + 2) + vk[0:32] # To compressed key
def sec_to_public_pair(pubkey):
"""Convert a public key in sec binary format to a public pair."""
x = string_to_number(pubkey[1:33])
@ -64,15 +66,19 @@ def sec_to_public_pair(pubkey):
return public_pair_for_x(ecdsa.ecdsa.generator_secp256k1, x, is_even=(sec0 == b'\2'))
def is_prime(n):
return (bool)(n & PRIME_DERIVATION_FLAG)
def fingerprint(pubkey):
return string_to_number(tools.hash_160(pubkey)[:4])
def get_address(public_node, address_type):
return tools.public_key_to_bc_address(public_node.public_key, address_type)
def public_ckd(public_node, n):
if not isinstance(n, list):
raise Exception('Parameter must be a list')
@ -85,6 +91,7 @@ def public_ckd(public_node, n):
return node
def get_subnode(node, i):
# Public Child key derivation (CKD) algorithm of BIP32
i_as_bytes = struct.pack(">L", i)
@ -106,8 +113,7 @@ def get_subnode(node, i):
# BIP32 magic converts old public key to new public point
x, y = sec_to_public_pair(node.public_key)
point = I_left_as_exponent * SECP256k1.generator + \
Point(SECP256k1.curve, x, y, SECP256k1.order)
point = I_left_as_exponent * SECP256k1.generator + Point(SECP256k1.curve, x, y, SECP256k1.order)
if point == INFINITY:
raise Exception("Point cannot be INFINITY")
@ -117,6 +123,7 @@ def get_subnode(node, i):
return node_out
def serialize(node, version=0x0488B21E):
s = b''
s += struct.pack('>I', version)
@ -131,6 +138,7 @@ def serialize(node, version=0x0488B21E):
s += tools.Hash(s)[:4]
return tools.b58encode(s)
def deserialize(xpub):
data = tools.b58decode(xpub, None)

View File

@ -25,17 +25,24 @@ import time
import binascii
import hashlib
import unicodedata
import json
# import json
import getpass
from mnemonic import Mnemonic
from . import tools
from . import mapping
# from . import mapping
from . import messages_pb2 as proto
from . import types_pb2 as types
from .debuglink import DebugLink
# Python2 vs Python3
try:
input = raw_input
except NameError:
pass
# try:
# from PIL import Image
# SCREENSHOT = True
@ -59,7 +66,9 @@ def getch():
return msvcrt.getch()
# POSIX system. Create and return a getch that manipulates the tty.
import sys, tty
import sys
import tty
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
@ -72,10 +81,12 @@ def getch():
return _getch()
def get_buttonrequest_value(code):
# Converts integer code to its string representation of ButtonRequestType
return [k for k, v in types.ButtonRequestType.items() if v == code][0]
def pprint(msg):
msg_class = msg.__class__.__name__
msg_size = msg.ByteSize()
@ -89,19 +100,23 @@ def pprint(msg):
else:
return "<%s> (%d bytes):\n%s" % (msg_class, msg_size, msg)
def log(msg):
sys.stderr.write(str(msg))
sys.stderr.write('\n')
sys.stderr.flush()
class CallException(Exception):
def __init__(self, code, message):
super(CallException, self).__init__()
self.args = [code, message]
class PinException(CallException):
pass
class field(object):
# Decorator extracts single value from
# protobuf object. If the field is not
@ -116,6 +131,7 @@ class field(object):
return getattr(ret, self.field)
return wrapped_f
class expect(object):
# Decorator checks if the method
# returned one of expected protobuf messages
@ -131,6 +147,7 @@ class expect(object):
return ret
return wrapped_f
def session(f):
# Decorator wraps a BaseClient method
# with session activation / deactivation
@ -143,6 +160,7 @@ def session(f):
client.transport.session_end()
return wrapped_f
def normalize_nfc(txt):
if sys.version_info[0] < 3:
if isinstance(txt, unicode):
@ -157,6 +175,7 @@ def normalize_nfc(txt):
raise Exception('unicode/str or bytes/str expected')
class BaseClient(object):
# Implements very basic layer of sending raw protobuf
# messages to device and getting its response back.
@ -178,9 +197,9 @@ class BaseClient(object):
handler_name = "callback_%s" % resp.__class__.__name__
handler = getattr(self, handler_name, None)
if handler != None:
if handler is not None:
msg = handler(resp)
if msg == None:
if msg is None:
raise Exception("Callback %s must return protobuf message, not None" % handler)
resp = self.call(msg)
@ -196,6 +215,7 @@ class BaseClient(object):
def close(self):
self.transport.close()
class DebugWireMixin(object):
def call_raw(self, msg):
log("SENDING " + pprint(msg))
@ -203,6 +223,7 @@ class DebugWireMixin(object):
log("RECEIVED " + pprint(resp))
return resp
class TextUIMixin(object):
# This class demonstrates easy test-based UI
# integration between the device and wallet.
@ -233,8 +254,7 @@ class TextUIMixin(object):
return proto.WordAck(word='\x08')
# ignore middle column if only 6 keys requested.
if (msg.type == types.WordRequestType_Matrix6 and
character in ('2', '5', '8')):
if (isinstance(msg.type, types.WordRequestType_Matrix6) and character in ('2', '5', '8')):
continue
if (ord(character) >= ord('1') and ord(character) <= ord('9')):
@ -274,14 +294,12 @@ class TextUIMixin(object):
types.WordRequestType_Matrix6):
return self.callback_RecoveryMatrix(msg)
log("Enter one word of mnemonic: ")
try:
word = raw_input()
except NameError:
word = input() # Python 3
word = input()
if self.expand:
word = self.mnemonic_wordlist.expand_word(word)
return proto.WordAck(word=word)
class DebugLinkMixin(object):
# This class implements automatic responses
# and other functionality for unit tests
@ -328,14 +346,14 @@ class DebugLinkMixin(object):
def __exit__(self, _type, value, traceback):
self.in_with_statement -= 1
if _type != None:
if _type is not None:
# Another exception raised
return False
# return isinstance(value, TypeError)
# Evaluate missed responses in 'with' statement
if self.expected_responses != None and len(self.expected_responses):
raise Exception("Some of expected responses didn't come from device: %s" % \
if self.expected_responses is not None and len(self.expected_responses):
raise Exception("Some of expected responses didn't come from device: %s" %
[pprint(x) for x in self.expected_responses])
# Cleanup
@ -376,7 +394,7 @@ class DebugLinkMixin(object):
return resp
def _check_request(self, msg):
if self.expected_responses != None:
if self.expected_responses is not None:
try:
expected = self.expected_responses.pop(0)
except IndexError:
@ -423,6 +441,7 @@ class DebugLinkMixin(object):
raise Exception("Unexpected call")
class ProtocolMixin(object):
PRIME_DERIVATION_FLAG = 0x80000000
VENDORS = ('bitcointrezor.com', 'trezor.io')
@ -553,7 +572,6 @@ class ProtocolMixin(object):
return response.signature_v, response.signature_r, response.signature_s
@field('entropy')
@expect(proto.Entropy)
def get_entropy(self, size):
@ -575,13 +593,13 @@ class ProtocolMixin(object):
@expect(proto.Success)
def apply_settings(self, label=None, language=None, use_passphrase=None, homescreen=None):
settings = proto.ApplySettings()
if label != None:
if label is not None:
settings.label = label
if language:
settings.language = language
if use_passphrase != None:
if use_passphrase is not None:
settings.use_passphrase = use_passphrase
if homescreen != None:
if homescreen is not None:
settings.homescreen = homescreen
out = self.call(settings)
@ -760,7 +778,7 @@ class ProtocolMixin(object):
serialized_tx += res.serialized.serialized_tx
if res.HasField('serialized') and res.serialized.HasField('signature_index'):
if signatures[res.serialized.signature_index] != None:
if signatures[res.serialized.signature_index] is not None:
raise Exception("Signature for index %d already filled" % res.serialized.signature_index)
signatures[res.serialized.signature_index] = res.serialized.signature
@ -797,7 +815,7 @@ class ProtocolMixin(object):
else:
msg.outputs.extend([current_tx.outputs[res.details.request_index], ])
if debug_processor != None:
if debug_processor is not None:
# If debug_processor function is provided,
# pass thru it the request and prepared response.
# This is useful for unit tests, see test_msg_signtx
@ -816,7 +834,7 @@ class ProtocolMixin(object):
if None in signatures:
raise Exception("Some signatures are missing!")
log("SIGNED IN %.03f SECONDS, CALLED %d MESSAGES, %d BYTES" % \
log("SIGNED IN %.03f SECONDS, CALLED %d MESSAGES, %d BYTES" %
(time.time() - start, counter, len(serialized_tx)))
return (signatures, serialized_tx)
@ -844,7 +862,8 @@ class ProtocolMixin(object):
# optimization to load the wordlist once, instead of for each recovery word
self.mnemonic_wordlist = Mnemonic('english')
res = self.call(proto.RecoveryDevice(word_count=int(word_count),
res = self.call(proto.RecoveryDevice(
word_count=int(word_count),
passphrase_protection=bool(passphrase_protection),
pin_protection=bool(pin_protection),
label=label,
@ -963,7 +982,7 @@ class ProtocolMixin(object):
@session
def firmware_update(self, fp):
if self.features.bootloader_mode == False:
if self.features.bootloader_mode is False:
raise Exception("Device must be in bootloader mode")
data = fp.read()
@ -1000,11 +1019,14 @@ class ProtocolMixin(object):
raise Exception("Unexpected message %s" % resp)
class TrezorClient(ProtocolMixin, TextUIMixin, BaseClient):
pass
class TrezorClientDebug(ProtocolMixin, TextUIMixin, DebugWireMixin, BaseClient):
pass
class TrezorDebugClient(ProtocolMixin, DebugLinkMixin, DebugWireMixin, BaseClient):
pass

View File

@ -19,17 +19,20 @@
from __future__ import print_function
from . import messages_pb2 as proto
from .transport import NotImplementedException
def pin_info(pin):
print("Device asks for PIN %s" % pin)
def button_press(yes_no):
print("User pressed", '"y"' if yes_no else '"n"')
def pprint(msg):
return "<%s> (%d bytes):\n%s" % (msg.__class__.__name__, msg.ByteSize(), msg)
class DebugLink(object):
def __init__(self, transport, pin_func=pin_info, button_func=button_press):
self.transport = transport
@ -126,4 +129,4 @@ class DebugLink(object):
self._call(proto.DebugLinkMemoryWrite(address=address, memory=memory, flash=flash), nowait=True)
def flash_erase(self, sector):
obj = self._call(proto.DebugLinkFlashErase(sector=sector), nowait=True)
self._call(proto.DebugLinkFlashErase(sector=sector), nowait=True)

View File

@ -21,6 +21,7 @@ from . import messages_pb2 as proto
map_type_to_class = {}
map_class_to_type = {}
def build_map():
for msg_type, i in proto.MessageType.items():
msg_name = msg_type.replace('MessageType_', '')
@ -29,6 +30,7 @@ def build_map():
map_type_to_class[i] = msg_class
map_class_to_type[msg_class] = i
def get_type(msg):
return map_class_to_type[msg.__class__]
@ -36,6 +38,7 @@ def get_type(msg):
def get_class(t):
return map_type_to_class[t]
def check_missing():
from google.protobuf import reflection
@ -47,5 +50,6 @@ def check_missing():
if len(missing):
raise Exception("Following protobuf messages are not defined in mapping: %s" % missing)
build_map()
check_missing()

View File

@ -41,11 +41,12 @@ __version__='0.0.6'
__author__ = 'Paul Dovbush <dpp@dpp.su>'
import json # py2.6+ TODO: add support for other JSON serialization modules
from google.protobuf.descriptor import FieldDescriptor as FD
from functools import partial
class ParseError(Exception): pass
class ParseError(Exception):
pass
def json2pb(pb, js, useFieldNumber=False):
@ -79,7 +80,6 @@ def json2pb(pb, js, useFieldNumber=False):
return pb
def pb2json(pb, useFieldNumber=False):
''' convert google.protobuf.descriptor instance to JSON string '''
js = {}
@ -94,7 +94,8 @@ def pb2json(pb, useFieldNumber=False):
ftype = partial(pb2json, useFieldNumber=useFieldNumber)
# ---- monkey patching ----
elif field.type == FD.TYPE_ENUM:
ftype = lambda x: field.enum_type.values[x].name
def ftype(x):
return field.enum_type.values[x].name
# ---- end of monkey patching ----
elif field.type in _ftype2js:
ftype = _ftype2js[field.type]

View File

@ -13,6 +13,7 @@ except:
from PyQt5.QtCore import QRegExp, Qt
from PyQt5.Qt import QT_VERSION_STR
class PinButton(QPushButton):
def __init__(self, password, encoded_value):
super(PinButton, self).__init__('?')
@ -30,6 +31,7 @@ class PinButton(QPushButton):
self.password.setText(self.password.text() + str(self.encoded_value))
self.password.setFocus()
class PinMatrixWidget(QWidget):
'''
Displays widget with nine blank buttons and password box.
@ -101,6 +103,7 @@ class PinMatrixWidget(QWidget):
def get_value(self):
return self.password.text()
if __name__ == '__main__':
'''
Demo application showing PinMatrix widget in action

View File

@ -25,13 +25,18 @@ import sys
if sys.version_info < (3,):
def byteindex(data, index):
return ord(data[index])
def iterbytes(data):
return (ord(char) for char in data)
else:
byteindex = lambda data, index: data[index]
def byteindex(data, index):
return data[index]
iterbytes = iter
Hash = lambda x: hashlib.sha256(hashlib.sha256(x).digest()).digest()
def Hash(data):
return hashlib.sha256(hashlib.sha256(data).digest()).digest()
def hash_160(public_key):
md = hashlib.new('ripemd160')
@ -45,11 +50,13 @@ def hash_160_to_bc_address(h160, address_type):
addr = vh160 + h[0:4]
return b58encode(addr)
def compress_pubkey(public_key):
if byteindex(public_key, 0) == 4:
return bytes((byteindex(public_key, 64) & 1) + 2) + public_key[1:33]
raise Exception("Pubkey is already compressed")
def public_key_to_bc_address(public_key, address_type, compress=True):
if public_key[0] == '\x04' and compress:
public_key = compress_pubkey(public_key)
@ -57,9 +64,11 @@ def public_key_to_bc_address(public_key, address_type, compress=True):
h160 = hash_160(public_key)
return hash_160_to_bc_address(h160, address_type)
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)
def b58encode(v):
""" encode v, which is a string of bytes, to base58."""
@ -85,6 +94,7 @@ def b58encode(v):
return (__b58chars[0] * nPad) + result
def b58decode(v, length):
""" decode v into a string of len bytes."""
long_value = 0
@ -111,6 +121,7 @@ def b58decode(v, length):
return result
def monkeypatch_google_protobuf_text_format():
# monkeypatching: text formatting of protobuf messages
import google.protobuf.text_format
@ -125,4 +136,3 @@ def monkeypatch_google_protobuf_text_format():
_oldPrintFieldValue(field, value, out, indent, as_utf8, as_one_line)
google.protobuf.text_format.PrintFieldValue = _customPrintFieldValue

View File

@ -19,15 +19,18 @@
from __future__ import absolute_import
import struct
from . import mapping
import binascii
from . import mapping
class NotImplementedException(Exception):
pass
class ConnectionError(Exception):
pass
class Transport(object):
def __init__(self, device, *args, **kwargs):
self.device = device
@ -84,7 +87,7 @@ class Transport(object):
"""
while True:
data = self._read()
if data != None:
if data is not None:
break
return self._parse_message(data)
@ -129,6 +132,7 @@ class Transport(object):
def _session_end(self):
pass
class TransportV1(Transport):
def write(self, msg):
ser = msg.SerializeToString()
@ -172,6 +176,7 @@ class TransportV1(Transport):
return chunk[1:]
class TransportV2(Transport):
def write(self, msg):
if not self.session_id:

View File

@ -28,9 +28,11 @@ from .transport import TransportV1
TREZORD_HOST = 'https://localback.net:21324'
CONFIG_URL = 'https://wallet.trezor.io/data/config_signed.bin'
def get_error(resp):
return ' (error=%d str=%s)' % (resp.status_code, resp.json()['error'])
class BridgeTransport(TransportV1):
CONFIGURED = False
@ -47,7 +49,8 @@ class BridgeTransport(TransportV1):
@staticmethod
def configure():
if BridgeTransport.CONFIGURED: return
if BridgeTransport.CONFIGURED:
return
r = requests.get(CONFIG_URL, verify=False)
if r.status_code != 200:
raise Exception('Could not fetch config from %s' % CONFIG_URL)
@ -88,7 +91,7 @@ class BridgeTransport(TransportV1):
self.session = None
def _ready_to_read(self):
return self.response != None
return self.response is not None
def write(self, protobuf_msg):
# Override main 'write' method, HTTP transport cannot be

View File

@ -18,10 +18,11 @@
'''USB HID implementation of Transport.'''
import hid
import time
import hid
from .transport import TransportV1, TransportV2, ConnectionError
def enumerate():
"""
Return a list of available TREZOR devices.
@ -46,6 +47,7 @@ def enumerate():
# List of two-tuples (path_normal, path_debuglink)
return sorted(devices.values())
def path_to_transport(path):
try:
device = [d for d in hid.enumerate(0, 0) if d['path'] == path][0]
@ -56,10 +58,11 @@ def path_to_transport(path):
try:
transport = DEVICE_TRANSPORTS[(device['vendor_id'], device['product_id'])]
except IndexError:
raise Exception("Unknown transport for VID:PID %04x:%04x" % (vid, pid))
raise Exception("Unknown transport for VID:PID %04x:%04x" % (device['vendor_id'], device['product_id']))
return transport
class _HidTransport(object):
def __init__(self, device, *args, **kwargs):
self.hid = None
@ -134,12 +137,15 @@ class _HidTransport(object):
return bytearray(data)
class HidTransportV1(_HidTransport, TransportV1):
pass
class HidTransportV2(_HidTransport, TransportV2):
pass
DEVICE_IDS = [
(0x534c, 0x0001), # TREZOR
(0x1209, 0x53c0), # TREZORv2 Bootloader
@ -152,11 +158,13 @@ DEVICE_TRANSPORTS = {
(0x1209, 0x53c1): HidTransportV2, # TREZORv2
}
# Backward compatible wrapper, decides for proper transport
# based on VID/PID of given path
def HidTransport(device, *args, **kwargs):
transport = path_to_transport(device[0])
return transport(device, *args, **kwargs)
# Backward compatibility hack; HidTransport is a function, not a class like before
HidTransport.enumerate = enumerate

View File

@ -18,15 +18,18 @@
from __future__ import print_function
import os
import time
from select import select
from .transport import TransportV1
"""PipeTransport implements fake wire transport over local named pipe.
Use this transport for talking with trezor simulator."""
class PipeTransport(TransportV1):
def __init__(self, device, is_device, *args, **kwargs):
self.is_device = is_device # Set True if act as device
self.is_device = is_device # set True if act as device
super(PipeTransport, self).__init__(device, *args, **kwargs)

View File

@ -20,7 +20,8 @@
import socket
from select import select
from .transport import TransportV2, ConnectionError
from .transport import TransportV2
class UdpTransport(TransportV2):
def __init__(self, device, *args, **kwargs):

View File

@ -25,6 +25,7 @@ from . import types_pb2 as proto_types
cache_dir = None
class TxApi(object):
def __init__(self, network, url):
@ -177,4 +178,3 @@ TxApiTestnet = TxApiInsight(network='insight_testnet', url='https://test-insight
TxApiLitecoin = TxApiBlockCypher(network='blockcypher_litecoin', url='https://api.blockcypher.com/v1/ltc/main/')
TxApiSegnet = TxApiSmartbit(network='smartbit_segnet', url='https://segnet-api.smartbit.com.au/v1/blockchain/')
TxApiZcashTestnet = TxApiInsight(network='insight_zcashtestnet', url='https://explorer.testnet.z.cash/api/', zcash=True)