|
|
@ -21,7 +21,7 @@ from mnemonic import Mnemonic
|
|
|
|
|
|
|
|
|
|
|
|
from . import messages as proto
|
|
|
|
from . import messages as proto
|
|
|
|
from . import tools
|
|
|
|
from . import tools
|
|
|
|
from .tools import field, expect, session
|
|
|
|
from .tools import expect, session
|
|
|
|
|
|
|
|
|
|
|
|
from .transport import enumerate_devices, get_transport
|
|
|
|
from .transport import enumerate_devices, get_transport
|
|
|
|
|
|
|
|
|
|
|
@ -44,8 +44,7 @@ class TrezorDevice:
|
|
|
|
return get_transport(path, prefix_search=False)
|
|
|
|
return get_transport(path, prefix_search=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def apply_settings(client, label=None, language=None, use_passphrase=None, homescreen=None, passphrase_source=None, auto_lock_delay_ms=None):
|
|
|
|
def apply_settings(client, label=None, language=None, use_passphrase=None, homescreen=None, passphrase_source=None, auto_lock_delay_ms=None):
|
|
|
|
settings = proto.ApplySettings()
|
|
|
|
settings = proto.ApplySettings()
|
|
|
|
if label is not None:
|
|
|
|
if label is not None:
|
|
|
@ -66,39 +65,34 @@ def apply_settings(client, label=None, language=None, use_passphrase=None, homes
|
|
|
|
return out
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def apply_flags(client, flags):
|
|
|
|
def apply_flags(client, flags):
|
|
|
|
out = client.call(proto.ApplyFlags(flags=flags))
|
|
|
|
out = client.call(proto.ApplyFlags(flags=flags))
|
|
|
|
client.init_device() # Reload Features
|
|
|
|
client.init_device() # Reload Features
|
|
|
|
return out
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def change_pin(client, remove=False):
|
|
|
|
def change_pin(client, remove=False):
|
|
|
|
ret = client.call(proto.ChangePin(remove=remove))
|
|
|
|
ret = client.call(proto.ChangePin(remove=remove))
|
|
|
|
client.init_device() # Re-read features
|
|
|
|
client.init_device() # Re-read features
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def set_u2f_counter(client, u2f_counter):
|
|
|
|
def set_u2f_counter(client, u2f_counter):
|
|
|
|
ret = client.call(proto.SetU2FCounter(u2f_counter=u2f_counter))
|
|
|
|
ret = client.call(proto.SetU2FCounter(u2f_counter=u2f_counter))
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def wipe_device(client):
|
|
|
|
def wipe_device(client):
|
|
|
|
ret = client.call(proto.WipeDevice())
|
|
|
|
ret = client.call(proto.WipeDevice())
|
|
|
|
client.init_device()
|
|
|
|
client.init_device()
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def recovery_device(client, word_count, passphrase_protection, pin_protection, label, language, type=proto.RecoveryDeviceType.ScrambledWords, expand=False, dry_run=False):
|
|
|
|
def recovery_device(client, word_count, passphrase_protection, pin_protection, label, language, type=proto.RecoveryDeviceType.ScrambledWords, expand=False, dry_run=False):
|
|
|
|
if client.features.initialized and not dry_run:
|
|
|
|
if client.features.initialized and not dry_run:
|
|
|
|
raise RuntimeError("Device is initialized already. Call wipe_device() and try again.")
|
|
|
|
raise RuntimeError("Device is initialized already. Call wipe_device() and try again.")
|
|
|
@ -127,8 +121,7 @@ def recovery_device(client, word_count, passphrase_protection, pin_protection, l
|
|
|
|
return res
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
@session
|
|
|
|
@session
|
|
|
|
def reset_device(client, display_random, strength, passphrase_protection, pin_protection, label, language, u2f_counter=0, skip_backup=False):
|
|
|
|
def reset_device(client, display_random, strength, passphrase_protection, pin_protection, label, language, u2f_counter=0, skip_backup=False):
|
|
|
|
if client.features.initialized:
|
|
|
|
if client.features.initialized:
|
|
|
@ -155,15 +148,13 @@ def reset_device(client, display_random, strength, passphrase_protection, pin_pr
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def backup_device(client):
|
|
|
|
def backup_device(client):
|
|
|
|
ret = client.call(proto.BackupDevice())
|
|
|
|
ret = client.call(proto.BackupDevice())
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def load_device_by_mnemonic(client, mnemonic, pin, passphrase_protection, label, language='english', skip_checksum=False, expand=False):
|
|
|
|
def load_device_by_mnemonic(client, mnemonic, pin, passphrase_protection, label, language='english', skip_checksum=False, expand=False):
|
|
|
|
# Convert mnemonic to UTF8 NKFD
|
|
|
|
# Convert mnemonic to UTF8 NKFD
|
|
|
|
mnemonic = Mnemonic.normalize_string(mnemonic)
|
|
|
|
mnemonic = Mnemonic.normalize_string(mnemonic)
|
|
|
@ -191,8 +182,7 @@ def load_device_by_mnemonic(client, mnemonic, pin, passphrase_protection, label,
|
|
|
|
return resp
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def load_device_by_xprv(client, xprv, pin, passphrase_protection, label, language):
|
|
|
|
def load_device_by_xprv(client, xprv, pin, passphrase_protection, label, language):
|
|
|
|
if client.features.initialized:
|
|
|
|
if client.features.initialized:
|
|
|
|
raise RuntimeError("Device is initialized already. Call wipe_device() and try again.")
|
|
|
|
raise RuntimeError("Device is initialized already. Call wipe_device() and try again.")
|
|
|
@ -236,8 +226,7 @@ def load_device_by_xprv(client, xprv, pin, passphrase_protection, label, languag
|
|
|
|
return resp
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@field('message')
|
|
|
|
@expect(proto.Success, field="message")
|
|
|
|
@expect(proto.Success)
|
|
|
|
|
|
|
|
def self_test(client):
|
|
|
|
def self_test(client):
|
|
|
|
if client.features.bootloader_mode is False:
|
|
|
|
if client.features.bootloader_mode is False:
|
|
|
|
raise RuntimeError("Device must be in bootloader mode")
|
|
|
|
raise RuntimeError("Device must be in bootloader mode")
|
|
|
|