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