本文整理汇总了Python中trezorlib.transport_hid.HidTransport类的典型用法代码示例。如果您正苦于以下问题:Python HidTransport类的具体用法?Python HidTransport怎么用?Python HidTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HidTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_for_devices
def wait_for_devices():
devices = HidTransport.enumerate()
while not len(devices):
sys.stderr.write("Please connect Trezor to computer and press Enter...")
raw_input()
devices = HidTransport.enumerate()
return devices
示例2: get_client
def get_client(self):
if not TREZOR:
give_error("please install github.com/trezor/python-trezor")
if not self.client or self.client.bad:
try:
d = HidTransport.enumerate()[0]
self.transport = HidTransport(d)
except:
give_error(
"Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it."
)
self.client = QtGuiTrezorClient(self.transport)
if (self.client.features.major_version == 1 and self.client.features.minor_version < 2) or (
self.client.features.major_version == 1
and self.client.features.minor_version == 2
and self.client.features.patch_version < 1
):
give_error("Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com")
self.client.set_tx_api(self)
# self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
self.client.bad = False
self.device_checked = False
self.proper_device = False
return self.client
示例3: get_transport
def get_transport(transport_string, path, **kwargs):
if transport_string == 'usb':
from trezorlib.transport_hid import HidTransport
if path == '':
try:
path = list_usb()[0][0]
except IndexError:
raise Exception("No Trezor found on USB")
for d in HidTransport.enumerate():
# Two-tuple of (normal_interface, debug_interface)
if path in d:
return HidTransport(d, **kwargs)
raise Exception("Device not found")
if transport_string == 'serial':
from trezorlib.transport_serial import SerialTransport
return SerialTransport(path, **kwargs)
if transport_string == 'pipe':
from trezorlib.transport_pipe import PipeTransport
return PipeTransport(path, is_device=False, **kwargs)
if transport_string == 'socket':
from trezorlib.transport_socket import SocketTransportClient
return SocketTransportClient(path, **kwargs)
if transport_string == 'fake':
from trezorlib.transport_fake import FakeTransport
return FakeTransport(path, **kwargs)
raise NotImplemented("Unknown transport")
示例4: main
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# Check whether we found any
if len(devices) == 0:
print 'No TREZOR found'
return
# Use first connected device
transport = HidTransport(devices[0])
# Creates object for manipulating TREZOR
client = TrezorClient(transport)
# Print out TREZOR's features and settings
print client.features
# Get the first address of first BIP44 account
# (should be the same address as shown in mytrezor.com)
bip32_path = client.expand_path("44'/0'/0'/0/0")
address = client.get_address('Bitcoin', bip32_path)
print 'Bitcoin address:', address
client.close()
示例5: __init__
def __init__(self, w3, index):
self.w3 = w3
self.client = TrezorClient(HidTransport.enumerate()[0])
self.index = index
self.address = self.w3.toChecksumAddress(
"0x" + bytes(self.client.ethereum_get_address([44 + BIP32_HARDEN,
60 + BIP32_HARDEN,
BIP32_HARDEN, 0,
index])).hex())
示例6: client
def client():
# pylint: disable=import-error
from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport
from trezorlib.messages_pb2 import PassphraseAck
devices = list(HidTransport.enumerate())
if len(devices) != 1:
msg = '{:d} Trezor devices found'.format(len(devices))
raise IOError(msg)
t = TrezorClient(HidTransport(devices[0]))
t.callback_PassphraseRequest = lambda msg: PassphraseAck(passphrase='')
return t
示例7: choose_device
def choose_device(devices):
if not len(devices):
raise Exception("No Trezor connected!")
if len(devices) == 1:
try:
return HidTransport(devices[0])
except IOError:
raise Exception("Device is currently in use")
i = 0
sys.stderr.write("----------------------------\n")
sys.stderr.write("Available devices:\n")
for d in devices:
try:
t = HidTransport(d)
except IOError:
sys.stderr.write("[-] <device is currently in use>\n")
continue
client = TrezorClient(t)
if client.features.label:
sys.stderr.write("[%d] %s\n" % (i, client.features.label))
else:
sys.stderr.write("[%d] <no label>\n" % i)
t.close()
i += 1
sys.stderr.write("----------------------------\n")
sys.stderr.write("Please choose device to use: ")
try:
device_id = int(raw_input())
return HidTransport(devices[device_id])
except:
raise Exception("Invalid choice, exiting...")
示例8: get_client
def get_client(self):
if not TREZOR:
raise Exception('please install github.com/trezor/python-trezor')
if not self.client or self.client.bad:
try:
d = HidTransport.enumerate()[0]
self.transport = HidTransport(d)
except:
raise Exception("Trezor not found")
self.client = QtGuiTrezorClient(self.transport)
self.client.set_tx_api(self)
#self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
self.client.bad = False
self.device_checked = False
self.proper_device = False
return self.client
示例9: get_client
def get_client(self):
if not TREZOR:
give_error('please install github.com/trezor/python-trezor')
if not self.client or self.client.bad:
try:
d = HidTransport.enumerate()[0]
self.transport = HidTransport(d)
except:
give_error('Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.')
self.client = QtGuiTrezorClient(self.transport)
self.client.set_tx_api(self)
#self.client.clear_session()# TODO Doesn't work with firmware 1.1, returns proto.Failure
self.client.bad = False
self.device_checked = False
self.proper_device = False
return self.client
示例10: get_client
def get_client(self):
if not TREZOR:
give_error('please install github.com/trezor/python-trezor')
if not self.client or self.client.bad:
d = HidTransport.enumerate()
if not d:
give_error('Could not connect to your Trezor. Please verify the cable is connected and that no other app is using it.')
self.transport = HidTransport(d[0])
self.client = QtGuiTrezorClient(self.transport)
self.client.handler = self.handler
self.client.set_tx_api(self)
self.client.bad = False
if not self.atleast_version(1, 2, 1):
self.client = None
give_error('Outdated Trezor firmware. Please update the firmware from https://www.mytrezor.com')
return self.client
示例11: main
def main():
devices = HidTransport.enumerate()
if not devices:
print('TREZOR is not plugged in. Please, connect TREZOR and retry.')
return
client = TrezorClient(devices[0])
print()
print('Confirm operation on TREZOR')
print()
masterKey = getMasterKey(client)
# print('master key:', masterKey)
fileName = getFileEncKey(masterKey)[0]
# print('file name:', fileName)
path = os.path.expanduser('~/Dropbox/Apps/TREZOR Password Manager/')
# print('path to file:', path)
encKey = getFileEncKey(masterKey)[2]
# print('enckey:', encKey)
full_path = path + fileName
parsed_json = decryptStorage(full_path, encKey)
# list entries
entries = parsed_json['entries']
printEntries(entries)
entry_id = input('Select entry number to decrypt: ')
entry_id = str(entry_id)
plain_nonce = getDecryptedNonce(client, entries[entry_id])
pwdArr = entries[entry_id]['password']['data']
pwdHex = ''.join([ hex(x)[2:].zfill(2) for x in pwdArr ])
print('password: ', decryptEntryValue(plain_nonce, unhexlify(pwdHex)))
safeNoteArr = entries[entry_id]['safe_note']['data']
safeNoteHex = ''.join([ hex(x)[2:].zfill(2) for x in safeNoteArr ])
print('safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex)))
return
示例12: main
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# Check whether we found any
if len(devices) == 0:
print('No TREZOR found')
return
# Use first connected device
transport = HidTransport(devices[0])
# Creates object for manipulating TREZOR
debug_transport = HidTransport(devices[0], **{'debug_link': True})
client = TrezorClient(transport)
debug = DebugLink(debug_transport)
mem = debug.memory_write(int(sys.argv[1],16), binascii.unhexlify(sys.argv[2]), flash=True)
client.close()
示例13: main
def main():
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# Check whether we found any
if len(devices) == 0:
print('No TREZOR found')
return
# Use first connected device
transport = HidTransport(devices[0])
# Creates object for manipulating TREZOR
debug_transport = HidTransport(devices[0], **{'debug_link': True})
client = TrezorClient(transport)
debug = DebugLink(debug_transport)
mem = debug.memory_read(int(sys.argv[1],16), int(sys.argv[2],16))
f = open('memory.dat', 'w')
f.write(mem)
f.close()
client.close()
示例14: main
def main():
numinputs = 600
sizeinputtx = 10
# List all connected TREZORs on USB
devices = HidTransport.enumerate()
# Check whether we found any
if len(devices) == 0:
print('No TREZOR found')
return
# Use first connected device
print(devices[0][0])
# transport = BridgeTransport(devices[0][0])
transport = HidTransport(devices[0])
txstore = MyTXAPIBitcoin()
# Creates object for manipulating TREZOR
client = TrezorClient(transport)
# client.set_tx_api(TXAPITestnet())
txstore.set_client(client)
txstore.set_publickey(client.get_public_node(client.expand_path("44'/0'/0'")))
print("creating input txs")
txstore.create_inputs(numinputs, sizeinputtx)
print("go")
client.set_tx_api(txstore)
# client.set_tx_api(MyTXAPIBitcoin())
# Print out TREZOR's features and settings
print(client.features)
# Get the first address of first BIP44 account
# (should be the same address as shown in mytrezor.com)
outputs = [
proto_types.TxOutputType(
amount=0,
script_type=proto_types.PAYTOADDRESS,
address='p2xtZoXeX5X8BP8JfFhQK2nD3emtjch7UeFm'
# op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6')
# address_n=client.expand_path("44'/0'/0'/0/35"),
# address='3PUxV6Cc4udQZQsJhArVUzvvVoKC8ohkAj',
),
# proto_types.TxOutputType(
# amount=0,
# script_type=proto_types.PAYTOOPRETURN,
# op_return_data=binascii.unhexlify('2890770995194662774cd192ee383b805e9a066e6a456be037727649228fb7f6')
# ),
# proto_types.TxOutputType(
# amount= 8120,
# script_type=proto_types.PAYTOADDRESS,
# address_n=client.expand_path("44'/1'/0'/1/0"),
# address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# address='14KRxYgFc7Se8j7MDdrK5PTNv8meq4GivK',
# ),
# proto_types.TxOutputType(
# amount= 18684 - 2000,
# script_type=proto_types.PAYTOADDRESS,
# address_n=client.expand_path("44'/0'/0'/0/7"),
# # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# # address='1s9TSqr3PHZdXGrYws59Uaf5SPqavH43z',
# ),
# proto_types.TxOutputType(
# amount= 1000,
# script_type=proto_types.PAYTOADDRESS,
# # address_n=client.expand_path("44'/0'/0'/0/18"),
# # address='1PtCkQgyN6xHmXWzLmFFrDNA5vYhYLeNFZ',
# address='1NcMqUvyWv1K3Zxwmx5sqfj7ZEmPCSdJFM',
# ),
]
# (signatures, serialized_tx) = client.sign_tx('Testnet', inputs, outputs)
(signatures, serialized_tx) = client.sign_tx('Bitcoin', txstore.get_inputs(), txstore.get_outputs())
print('Transaction:', binascii.hexlify(serialized_tx))
client.close()
示例15: decryptStorage
full_path = ''.join((path, fileName))
parsed_json = decryptStorage(full_path, encKey)
#list entries
entries = parsed_json['entries']
printEntries(entries)
entry_id = raw_input('Select entry number to decrypt: ')
entry_id = str(entry_id)
plain_nonce = getDecryptedNonce(entries[entry_id])
pwdArr = entries[entry_id]['password']['data']
pwdHex = ''.join([ hex(x)[2:].zfill(2) for x in pwdArr ])
print 'password: ', decryptEntryValue(plain_nonce, unhexlify(pwdHex))
safeNoteArr = entries[entry_id]['safe_note']['data']
safeNoteHex = ''.join([ hex(x)[2:].zfill(2) for x in safeNoteArr ])
print 'safe_note:', decryptEntryValue(plain_nonce, unhexlify(safeNoteHex))
return
if __name__ == '__main__':
try:
# init TREZOR transport
client = TrezorClient(HidTransport(HidTransport.enumerate()[0]))
except:
print 'TREZOR is not plugged in. Please, connect TREZOR and retry.'
else:
main()