mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-12 23:52:39 +00:00
more python3 stuff
This commit is contained in:
parent
c567ceec94
commit
de9b10fd90
@ -29,7 +29,7 @@ also found in ``helloworld.py``
|
|||||||
|
|
||||||
# Check whether we found any
|
# Check whether we found any
|
||||||
if len(devices) == 0:
|
if len(devices) == 0:
|
||||||
print 'No TREZOR found'
|
print('No TREZOR found')
|
||||||
return
|
return
|
||||||
|
|
||||||
# Use first connected device
|
# Use first connected device
|
||||||
@ -39,13 +39,13 @@ also found in ``helloworld.py``
|
|||||||
client = TrezorClient(transport)
|
client = TrezorClient(transport)
|
||||||
|
|
||||||
# Print out TREZOR's features and settings
|
# Print out TREZOR's features and settings
|
||||||
print client.features
|
print(client.features)
|
||||||
|
|
||||||
# Get the first address of first BIP44 account
|
# Get the first address of first BIP44 account
|
||||||
# (should be the same address as shown in mytrezor.com)
|
# (should be the same address as shown in mytrezor.com)
|
||||||
bip32_path = client.expand_path("44'/0'/0'/0/0")
|
bip32_path = client.expand_path("44'/0'/0'/0/0")
|
||||||
address = client.get_address('Bitcoin', bip32_path)
|
address = client.get_address('Bitcoin', bip32_path)
|
||||||
print 'Bitcoin address:', address
|
print('Bitcoin address:', address)
|
||||||
|
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ def main():
|
|||||||
|
|
||||||
# Check whether we found any
|
# Check whether we found any
|
||||||
if len(devices) == 0:
|
if len(devices) == 0:
|
||||||
print 'No TREZOR found'
|
print('No TREZOR found')
|
||||||
return
|
return
|
||||||
|
|
||||||
# Use first connected device
|
# Use first connected device
|
||||||
@ -19,13 +19,13 @@ def main():
|
|||||||
client = TrezorClient(transport)
|
client = TrezorClient(transport)
|
||||||
|
|
||||||
# Print out TREZOR's features and settings
|
# Print out TREZOR's features and settings
|
||||||
print client.features
|
print(client.features)
|
||||||
|
|
||||||
# Get the first address of first BIP44 account
|
# Get the first address of first BIP44 account
|
||||||
# (should be the same address as shown in mytrezor.com)
|
# (should be the same address as shown in mytrezor.com)
|
||||||
bip32_path = client.expand_path("44'/0'/0'/0/0")
|
bip32_path = client.expand_path("44'/0'/0'/0/0")
|
||||||
address = client.get_address('Bitcoin', bip32_path)
|
address = client.get_address('Bitcoin', bip32_path)
|
||||||
print 'Bitcoin address:', address
|
print('Bitcoin address:', address)
|
||||||
|
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
@ -15,6 +15,12 @@ import binascii
|
|||||||
import hashlib
|
import hashlib
|
||||||
import mnemonic
|
import mnemonic
|
||||||
|
|
||||||
|
# Python2 vs Python3
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
def generate_entropy(strength, internal_entropy, external_entropy):
|
def generate_entropy(strength, internal_entropy, external_entropy):
|
||||||
'''
|
'''
|
||||||
strength - length of produced seed. One of 128, 192, 256
|
strength - length of produced seed. One of 128, 192, 256
|
||||||
@ -44,11 +50,11 @@ def generate_entropy(strength, internal_entropy, external_entropy):
|
|||||||
return entropy_stripped
|
return entropy_stripped
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print __doc__
|
print(__doc__)
|
||||||
|
|
||||||
comp = binascii.unhexlify(raw_input("Please enter computer-generated entropy (in hex): ").strip())
|
comp = binascii.unhexlify(input("Please enter computer-generated entropy (in hex): ").strip())
|
||||||
trzr = binascii.unhexlify(raw_input("Please enter TREZOR-generated entropy (in hex): ").strip())
|
trzr = binascii.unhexlify(input("Please enter TREZOR-generated entropy (in hex): ").strip())
|
||||||
word_count = int(raw_input("How many words your mnemonic has? "))
|
word_count = int(input("How many words your mnemonic has? "))
|
||||||
|
|
||||||
strength = word_count * 32 / 3
|
strength = word_count * 32 / 3
|
||||||
|
|
||||||
@ -56,14 +62,14 @@ def main():
|
|||||||
|
|
||||||
words = mnemonic.Mnemonic('english').to_mnemonic(entropy)
|
words = mnemonic.Mnemonic('english').to_mnemonic(entropy)
|
||||||
if not mnemonic.Mnemonic('english').check(words):
|
if not mnemonic.Mnemonic('english').check(words):
|
||||||
print "Mnemonic is invalid"
|
print("Mnemonic is invalid")
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(words.split(' ')) != word_count:
|
if len(words.split(' ')) != word_count:
|
||||||
print "Mnemonic length mismatch!"
|
print("Mnemonic length mismatch!")
|
||||||
return
|
return
|
||||||
|
|
||||||
print "Generated mnemonic is:", words
|
print("Generated mnemonic is:", words)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -23,7 +23,7 @@ class TestMultisig(common.TrezorTest):
|
|||||||
#key3 = self.client.get_public_node([3])
|
#key3 = self.client.get_public_node([3])
|
||||||
|
|
||||||
# xpub:
|
# xpub:
|
||||||
# print ckd_public.serialize(self.client.get_public_node([]).node)
|
# print(ckd_public.serialize(self.client.get_public_node([]).node))
|
||||||
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
|
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
|
||||||
|
|
||||||
# pubkeys:
|
# pubkeys:
|
||||||
@ -133,7 +133,7 @@ class TestMultisig(common.TrezorTest):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# xpub:
|
# xpub:
|
||||||
# print ckd_public.serialize(self.client.get_public_node([]).node)
|
# print(ckd_public.serialize(self.client.get_public_node([]).node))
|
||||||
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
|
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
|
||||||
node = ckd_public.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
|
node = ckd_public.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ class TestMultisig(common.TrezorTest):
|
|||||||
# multisig address: 3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz
|
# multisig address: 3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz
|
||||||
|
|
||||||
# xpub:
|
# xpub:
|
||||||
# print ckd_public.serialize(self.client.get_public_node([]).node)
|
# print(ckd_public.serialize(self.client.get_public_node([]).node))
|
||||||
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
|
# xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy
|
||||||
node = ckd_public.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
|
node = ckd_public.deserialize('xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy')
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ class TestZeroSig(common.TrezorTest):
|
|||||||
tx = self.client.call(msg)
|
tx = self.client.call(msg)
|
||||||
|
|
||||||
siglen = ord(tx.serialized_tx[44])
|
siglen = ord(tx.serialized_tx[44])
|
||||||
print siglen
|
print(siglen)
|
||||||
if siglen < 67:
|
if siglen < 67:
|
||||||
print "!!!!", n
|
print("!!!!", n)
|
||||||
print binascii.hexlify(tx.serialized_tx)
|
print(binascii.hexlify(tx.serialized_tx))
|
||||||
return
|
return
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -17,11 +17,17 @@ import binascii
|
|||||||
from trezorlib.client import TrezorClient, TrezorClientDebug
|
from trezorlib.client import TrezorClient, TrezorClientDebug
|
||||||
from trezorlib.transport_hid import HidTransport
|
from trezorlib.transport_hid import HidTransport
|
||||||
|
|
||||||
|
# Python2 vs Python3
|
||||||
|
try:
|
||||||
|
input = raw_input
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
def wait_for_devices():
|
def wait_for_devices():
|
||||||
devices = HidTransport.enumerate()
|
devices = HidTransport.enumerate()
|
||||||
while not len(devices):
|
while not len(devices):
|
||||||
sys.stderr.write("Please connect TREZOR to computer and press Enter...")
|
sys.stderr.write("Please connect TREZOR to computer and press Enter...")
|
||||||
raw_input()
|
input()
|
||||||
devices = HidTransport.enumerate()
|
devices = HidTransport.enumerate()
|
||||||
|
|
||||||
return devices
|
return devices
|
||||||
@ -59,7 +65,7 @@ def choose_device(devices):
|
|||||||
sys.stderr.write("Please choose device to use: ")
|
sys.stderr.write("Please choose device to use: ")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
device_id = int(raw_input())
|
device_id = int(input())
|
||||||
return HidTransport(devices[device_id])
|
return HidTransport(devices[device_id])
|
||||||
except:
|
except:
|
||||||
raise Exception("Invalid choice, exiting...")
|
raise Exception("Invalid choice, exiting...")
|
||||||
@ -76,7 +82,7 @@ def main():
|
|||||||
# New encfs drive, let's generate password
|
# New encfs drive, let's generate password
|
||||||
|
|
||||||
sys.stderr.write('Please provide label for new drive: ')
|
sys.stderr.write('Please provide label for new drive: ')
|
||||||
label = raw_input()
|
label = input()
|
||||||
|
|
||||||
sys.stderr.write('Computer asked TREZOR for new strong password.\n')
|
sys.stderr.write('Computer asked TREZOR for new strong password.\n')
|
||||||
sys.stderr.write('Please confirm action on your device.\n')
|
sys.stderr.write('Please confirm action on your device.\n')
|
||||||
@ -107,7 +113,7 @@ def main():
|
|||||||
binascii.unhexlify(data['password_encrypted_hex']),
|
binascii.unhexlify(data['password_encrypted_hex']),
|
||||||
False, True)
|
False, True)
|
||||||
|
|
||||||
print passw
|
print(passw)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
20
trezorctl
20
trezorctl
@ -210,7 +210,7 @@ class Commands(object):
|
|||||||
if args.file:
|
if args.file:
|
||||||
fp = open(args.file, 'r')
|
fp = open(args.file, 'r')
|
||||||
elif args.url:
|
elif args.url:
|
||||||
print "Downloading from", args.url
|
print("Downloading from", args.url)
|
||||||
resp = urllib.urlretrieve(args.url)
|
resp = urllib.urlretrieve(args.url)
|
||||||
fp = open(resp[0], 'r')
|
fp = open(resp[0], 'r')
|
||||||
urllib.urlcleanup() # We still keep file pointer open
|
urllib.urlcleanup() # We still keep file pointer open
|
||||||
@ -223,13 +223,13 @@ class Commands(object):
|
|||||||
release = next((r for r in releases if version_string(r) == args.version))
|
release = next((r for r in releases if version_string(r) == args.version))
|
||||||
else:
|
else:
|
||||||
release = max(releases, key=version)
|
release = max(releases, key=version)
|
||||||
print "No file, url, or version given. Fetching latest version: %s" % version_string(release)
|
print("No file, url, or version given. Fetching latest version: %s" % version_string(release))
|
||||||
print "Firmware fingerprint: %s" % release['fingerprint']
|
print("Firmware fingerprint: %s" % release['fingerprint'])
|
||||||
args.url = release['url']
|
args.url = release['url']
|
||||||
return self.firmware_update(args)
|
return self.firmware_update(args)
|
||||||
|
|
||||||
if fp.read(8) == '54525a52':
|
if fp.read(8) == '54525a52':
|
||||||
print "Converting firmware to binary"
|
print("Converting firmware to binary")
|
||||||
|
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
fp_old = fp
|
fp_old = fp
|
||||||
@ -243,7 +243,7 @@ class Commands(object):
|
|||||||
if fp.read(4) != 'TRZR':
|
if fp.read(4) != 'TRZR':
|
||||||
raise Exception("TREZOR firmware header expected")
|
raise Exception("TREZOR firmware header expected")
|
||||||
|
|
||||||
print "Please confirm action on device..."
|
print("Please confirm action on device...")
|
||||||
|
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
return self.client.firmware_update(fp=fp)
|
return self.client.firmware_update(fp=fp)
|
||||||
@ -443,13 +443,13 @@ def main():
|
|||||||
if args.cmd == 'list':
|
if args.cmd == 'list':
|
||||||
devices = list_usb()
|
devices = list_usb()
|
||||||
if args.json:
|
if args.json:
|
||||||
print json.dumps(devices)
|
print(json.dumps(devices))
|
||||||
else:
|
else:
|
||||||
for dev in devices:
|
for dev in devices:
|
||||||
if dev[1] != None:
|
if dev[1] != None:
|
||||||
print "%s - debuglink enabled" % dev[0]
|
print("%s - debuglink enabled" % dev[0])
|
||||||
else:
|
else:
|
||||||
print dev[0]
|
print(dev[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
transport = get_transport(args.transport, args.path)
|
transport = get_transport(args.transport, args.path)
|
||||||
@ -463,9 +463,9 @@ def main():
|
|||||||
res = args.func(cmds, args)
|
res = args.func(cmds, args)
|
||||||
|
|
||||||
if args.json:
|
if args.json:
|
||||||
print json.dumps(res, sort_keys=True, indent=4)
|
print(json.dumps(res, sort_keys=True, indent=4))
|
||||||
else:
|
else:
|
||||||
print res
|
print(res)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -203,7 +203,10 @@ class TextUIMixin(object):
|
|||||||
|
|
||||||
def callback_WordRequest(self, msg):
|
def callback_WordRequest(self, msg):
|
||||||
log("Enter one word of mnemonic: ")
|
log("Enter one word of mnemonic: ")
|
||||||
word = raw_input()
|
try:
|
||||||
|
word = raw_input()
|
||||||
|
except NameError:
|
||||||
|
word = input() # Python 3
|
||||||
return proto.WordAck(word=word)
|
return proto.WordAck(word=word)
|
||||||
|
|
||||||
class DebugLinkMixin(object):
|
class DebugLinkMixin(object):
|
||||||
|
@ -91,8 +91,8 @@ if __name__ == '__main__':
|
|||||||
matrix = PinMatrixWidget()
|
matrix = PinMatrixWidget()
|
||||||
|
|
||||||
def clicked():
|
def clicked():
|
||||||
print "PinMatrix value is", matrix.get_value()
|
print("PinMatrix value is", matrix.get_value())
|
||||||
print "Possible button combinations:", matrix.get_strength()
|
print("Possible button combinations:", matrix.get_strength())
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
ok = QPushButton('OK')
|
ok = QPushButton('OK')
|
||||||
|
@ -53,7 +53,7 @@ class HidTransport(Transport):
|
|||||||
raise Exception("Unknown USB interface number: %d" % interface_number)
|
raise Exception("Unknown USB interface number: %d" % interface_number)
|
||||||
|
|
||||||
# List of two-tuples (path_normal, path_debuglink)
|
# List of two-tuples (path_normal, path_debuglink)
|
||||||
return devices.values()
|
return list(devices.values())
|
||||||
|
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user