mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 12:28:09 +00:00
Change reset device slip39 bool to enum (#350)
Change reset device slip39 bool to enum
This commit is contained in:
commit
79309ba016
@ -191,7 +191,14 @@ message ResetDevice {
|
|||||||
optional uint32 u2f_counter = 7; // U2F counter
|
optional uint32 u2f_counter = 7; // U2F counter
|
||||||
optional bool skip_backup = 8; // postpone seed backup to BackupDevice workflow
|
optional bool skip_backup = 8; // postpone seed backup to BackupDevice workflow
|
||||||
optional bool no_backup = 9; // indicate that no backup is going to be made
|
optional bool no_backup = 9; // indicate that no backup is going to be made
|
||||||
optional bool slip39 = 10; // indicate that we want SLIP-39 backup not BIP-39
|
|
||||||
|
// type of the mnemonic backup (BIP-39 vs SLIP-39 single group vs SLIP-39 multiple groups)
|
||||||
|
optional ResetDeviceBackupType backup_type = 10 [default=ResetDeviceBackupType_Bip39];
|
||||||
|
enum ResetDeviceBackupType {
|
||||||
|
ResetDeviceBackupType_Bip39 = 0; // The traditional Single Backup - BIP39
|
||||||
|
ResetDeviceBackupType_Slip39_Single_Group = 1; // Shamir Backup with only single group (one-level Shamir)
|
||||||
|
ResetDeviceBackupType_Slip39_Multiple_Groups = 2; // Shamir Backup with multiple groups (two-level Shamir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from trezor import config, ui, wire
|
from trezor import config, ui, wire
|
||||||
from trezor.crypto import bip39, hashlib, random, slip39
|
from trezor.crypto import bip39, hashlib, random, slip39
|
||||||
from trezor.messages import ButtonRequestType
|
from trezor.messages import ButtonRequestType, ResetDeviceBackupType
|
||||||
from trezor.messages.EntropyAck import EntropyAck
|
from trezor.messages.EntropyAck import EntropyAck
|
||||||
from trezor.messages.EntropyRequest import EntropyRequest
|
from trezor.messages.EntropyRequest import EntropyRequest
|
||||||
from trezor.messages.Success import Success
|
from trezor.messages.Success import Success
|
||||||
@ -19,13 +19,17 @@ if __debug__:
|
|||||||
if False:
|
if False:
|
||||||
from trezor.messages.ResetDevice import ResetDevice
|
from trezor.messages.ResetDevice import ResetDevice
|
||||||
|
|
||||||
|
_DEFAULT_BACKUP_TYPE = ResetDeviceBackupType.Bip39
|
||||||
|
|
||||||
|
|
||||||
async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
||||||
# validate parameters and device state
|
# validate parameters and device state
|
||||||
_validate_reset_device(msg)
|
_validate_reset_device(msg)
|
||||||
|
|
||||||
|
is_slip39_simple = msg.backup_type == ResetDeviceBackupType.Slip39_Single_Group
|
||||||
|
|
||||||
# make sure user knows he's setting up a new wallet
|
# make sure user knows he's setting up a new wallet
|
||||||
await _show_reset_device_warning(ctx, msg.slip39)
|
await _show_reset_device_warning(ctx, is_slip39_simple)
|
||||||
|
|
||||||
# request new PIN
|
# request new PIN
|
||||||
if msg.pin_protection:
|
if msg.pin_protection:
|
||||||
@ -45,7 +49,7 @@ async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
|||||||
ext_entropy = entropy_ack.entropy
|
ext_entropy = entropy_ack.entropy
|
||||||
secret = _compute_secret_from_entropy(int_entropy, ext_entropy, msg.strength)
|
secret = _compute_secret_from_entropy(int_entropy, ext_entropy, msg.strength)
|
||||||
|
|
||||||
if msg.slip39:
|
if is_slip39_simple:
|
||||||
storage.slip39.set_identifier(slip39.generate_random_identifier())
|
storage.slip39.set_identifier(slip39.generate_random_identifier())
|
||||||
storage.slip39.set_iteration_exponent(slip39.DEFAULT_ITERATION_EXPONENT)
|
storage.slip39.set_iteration_exponent(slip39.DEFAULT_ITERATION_EXPONENT)
|
||||||
|
|
||||||
@ -57,7 +61,7 @@ async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
|||||||
|
|
||||||
# generate and display backup information for the master secret
|
# generate and display backup information for the master secret
|
||||||
if not msg.no_backup and not msg.skip_backup:
|
if not msg.no_backup and not msg.skip_backup:
|
||||||
if msg.slip39:
|
if is_slip39_simple:
|
||||||
await backup_slip39_wallet(ctx, secret)
|
await backup_slip39_wallet(ctx, secret)
|
||||||
else:
|
else:
|
||||||
await backup_bip39_wallet(ctx, secret)
|
await backup_bip39_wallet(ctx, secret)
|
||||||
@ -70,7 +74,7 @@ async def reset_device(ctx: wire.Context, msg: ResetDevice) -> Success:
|
|||||||
storage.device.load_settings(
|
storage.device.load_settings(
|
||||||
label=msg.label, use_passphrase=msg.passphrase_protection
|
label=msg.label, use_passphrase=msg.passphrase_protection
|
||||||
)
|
)
|
||||||
if msg.slip39:
|
if is_slip39_simple:
|
||||||
mnemonic.slip39.store(
|
mnemonic.slip39.store(
|
||||||
secret=secret, needs_backup=msg.skip_backup, no_backup=msg.no_backup
|
secret=secret, needs_backup=msg.skip_backup, no_backup=msg.no_backup
|
||||||
)
|
)
|
||||||
@ -112,8 +116,14 @@ async def backup_bip39_wallet(ctx: wire.Context, secret: bytes) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _validate_reset_device(msg: ResetDevice) -> None:
|
def _validate_reset_device(msg: ResetDevice) -> None:
|
||||||
|
msg.backup_type = msg.backup_type or _DEFAULT_BACKUP_TYPE
|
||||||
|
if msg.backup_type not in (
|
||||||
|
ResetDeviceBackupType.Bip39,
|
||||||
|
ResetDeviceBackupType.Slip39_Single_Group,
|
||||||
|
):
|
||||||
|
raise wire.ProcessError("Backup type not implemented.")
|
||||||
if msg.strength not in (128, 256):
|
if msg.strength not in (128, 256):
|
||||||
if msg.slip39:
|
if msg.backup_type == ResetDeviceBackupType.Slip39_Single_Group:
|
||||||
raise wire.ProcessError("Invalid strength (has to be 128 or 256 bits)")
|
raise wire.ProcessError("Invalid strength (has to be 128 or 256 bits)")
|
||||||
elif msg.strength != 192:
|
elif msg.strength != 192:
|
||||||
raise wire.ProcessError("Invalid strength (has to be 128, 192 or 256 bits)")
|
raise wire.ProcessError("Invalid strength (has to be 128, 192 or 256 bits)")
|
||||||
|
@ -23,7 +23,7 @@ class ResetDevice(p.MessageType):
|
|||||||
u2f_counter: int = None,
|
u2f_counter: int = None,
|
||||||
skip_backup: bool = None,
|
skip_backup: bool = None,
|
||||||
no_backup: bool = None,
|
no_backup: bool = None,
|
||||||
slip39: bool = None,
|
backup_type: int = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.display_random = display_random
|
self.display_random = display_random
|
||||||
self.strength = strength
|
self.strength = strength
|
||||||
@ -34,7 +34,7 @@ class ResetDevice(p.MessageType):
|
|||||||
self.u2f_counter = u2f_counter
|
self.u2f_counter = u2f_counter
|
||||||
self.skip_backup = skip_backup
|
self.skip_backup = skip_backup
|
||||||
self.no_backup = no_backup
|
self.no_backup = no_backup
|
||||||
self.slip39 = slip39
|
self.backup_type = backup_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
@ -48,5 +48,5 @@ class ResetDevice(p.MessageType):
|
|||||||
7: ('u2f_counter', p.UVarintType, 0),
|
7: ('u2f_counter', p.UVarintType, 0),
|
||||||
8: ('skip_backup', p.BoolType, 0),
|
8: ('skip_backup', p.BoolType, 0),
|
||||||
9: ('no_backup', p.BoolType, 0),
|
9: ('no_backup', p.BoolType, 0),
|
||||||
10: ('slip39', p.BoolType, 0),
|
10: ('backup_type', p.UVarintType, 0), # default=ResetDeviceBackupType_Bip39
|
||||||
}
|
}
|
||||||
|
5
core/src/trezor/messages/ResetDeviceBackupType.py
Normal file
5
core/src/trezor/messages/ResetDeviceBackupType.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Automatically generated by pb2py
|
||||||
|
# fmt: off
|
||||||
|
Bip39 = 0
|
||||||
|
Slip39_Single_Group = 1
|
||||||
|
Slip39_Multiple_Groups = 2
|
@ -113,6 +113,14 @@ CHOICE_OUTPUT_SCRIPT_TYPE = ChoiceType(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CHOICE_RESET_DEVICE_TYPE = ChoiceType(
|
||||||
|
{
|
||||||
|
"single": proto.ResetDeviceBackupType.Bip39,
|
||||||
|
"shamir": proto.ResetDeviceBackupType.Slip39_Single_Group,
|
||||||
|
"advanced": proto.ResetDeviceBackupType.Slip39_Multiple_Groups,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UnderscoreAgnosticGroup(click.Group):
|
class UnderscoreAgnosticGroup(click.Group):
|
||||||
"""Command group that normalizes dashes and underscores.
|
"""Command group that normalizes dashes and underscores.
|
||||||
@ -505,7 +513,7 @@ def recovery_device(
|
|||||||
@click.option("-u", "--u2f-counter", default=0)
|
@click.option("-u", "--u2f-counter", default=0)
|
||||||
@click.option("-s", "--skip-backup", is_flag=True)
|
@click.option("-s", "--skip-backup", is_flag=True)
|
||||||
@click.option("-n", "--no-backup", is_flag=True)
|
@click.option("-n", "--no-backup", is_flag=True)
|
||||||
@click.option("-x", "--slip39", is_flag=True)
|
@click.option("-b", "--backup-type", type=CHOICE_RESET_DEVICE_TYPE, default="single")
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def reset_device(
|
def reset_device(
|
||||||
connect,
|
connect,
|
||||||
@ -517,7 +525,7 @@ def reset_device(
|
|||||||
u2f_counter,
|
u2f_counter,
|
||||||
skip_backup,
|
skip_backup,
|
||||||
no_backup,
|
no_backup,
|
||||||
slip39,
|
backup_type,
|
||||||
):
|
):
|
||||||
if strength:
|
if strength:
|
||||||
strength = int(strength)
|
strength = int(strength)
|
||||||
@ -532,7 +540,7 @@ def reset_device(
|
|||||||
u2f_counter=u2f_counter,
|
u2f_counter=u2f_counter,
|
||||||
skip_backup=skip_backup,
|
skip_backup=skip_backup,
|
||||||
no_backup=no_backup,
|
no_backup=no_backup,
|
||||||
slip39=slip39,
|
backup_type=backup_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -167,7 +167,7 @@ def reset(
|
|||||||
u2f_counter=0,
|
u2f_counter=0,
|
||||||
skip_backup=False,
|
skip_backup=False,
|
||||||
no_backup=False,
|
no_backup=False,
|
||||||
slip39=False,
|
backup_type=proto.ResetDeviceBackupType.Bip39,
|
||||||
):
|
):
|
||||||
if client.features.initialized:
|
if client.features.initialized:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
@ -191,7 +191,7 @@ def reset(
|
|||||||
u2f_counter=u2f_counter,
|
u2f_counter=u2f_counter,
|
||||||
skip_backup=bool(skip_backup),
|
skip_backup=bool(skip_backup),
|
||||||
no_backup=bool(no_backup),
|
no_backup=bool(no_backup),
|
||||||
slip39=bool(slip39),
|
backup_type=backup_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
resp = client.call(msg)
|
resp = client.call(msg)
|
||||||
|
@ -23,7 +23,7 @@ class ResetDevice(p.MessageType):
|
|||||||
u2f_counter: int = None,
|
u2f_counter: int = None,
|
||||||
skip_backup: bool = None,
|
skip_backup: bool = None,
|
||||||
no_backup: bool = None,
|
no_backup: bool = None,
|
||||||
slip39: bool = None,
|
backup_type: int = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.display_random = display_random
|
self.display_random = display_random
|
||||||
self.strength = strength
|
self.strength = strength
|
||||||
@ -34,7 +34,7 @@ class ResetDevice(p.MessageType):
|
|||||||
self.u2f_counter = u2f_counter
|
self.u2f_counter = u2f_counter
|
||||||
self.skip_backup = skip_backup
|
self.skip_backup = skip_backup
|
||||||
self.no_backup = no_backup
|
self.no_backup = no_backup
|
||||||
self.slip39 = slip39
|
self.backup_type = backup_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
@ -48,5 +48,5 @@ class ResetDevice(p.MessageType):
|
|||||||
7: ('u2f_counter', p.UVarintType, 0),
|
7: ('u2f_counter', p.UVarintType, 0),
|
||||||
8: ('skip_backup', p.BoolType, 0),
|
8: ('skip_backup', p.BoolType, 0),
|
||||||
9: ('no_backup', p.BoolType, 0),
|
9: ('no_backup', p.BoolType, 0),
|
||||||
10: ('slip39', p.BoolType, 0),
|
10: ('backup_type', p.UVarintType, 0), # default=ResetDeviceBackupType_Bip39
|
||||||
}
|
}
|
||||||
|
5
python/trezorlib/messages/ResetDeviceBackupType.py
Normal file
5
python/trezorlib/messages/ResetDeviceBackupType.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Automatically generated by pb2py
|
||||||
|
# fmt: off
|
||||||
|
Bip39 = 0
|
||||||
|
Slip39_Single_Group = 1
|
||||||
|
Slip39_Multiple_Groups = 2
|
@ -267,6 +267,7 @@ from . import PassphraseSourceType
|
|||||||
from . import PinMatrixRequestType
|
from . import PinMatrixRequestType
|
||||||
from . import RecoveryDeviceType
|
from . import RecoveryDeviceType
|
||||||
from . import RequestType
|
from . import RequestType
|
||||||
|
from . import ResetDeviceBackupType
|
||||||
from . import TezosBallotType
|
from . import TezosBallotType
|
||||||
from . import TezosContractType
|
from . import TezosContractType
|
||||||
from . import WordRequestType
|
from . import WordRequestType
|
||||||
|
@ -7,7 +7,7 @@ import shamir_mnemonic as shamir
|
|||||||
from shamir_mnemonic import MnemonicError
|
from shamir_mnemonic import MnemonicError
|
||||||
|
|
||||||
from trezorlib import device, messages as proto
|
from trezorlib import device, messages as proto
|
||||||
from trezorlib.messages import ButtonRequestType as B
|
from trezorlib.messages import ButtonRequestType as B, ResetDeviceBackupType
|
||||||
|
|
||||||
from .common import TrezorTest, generate_entropy
|
from .common import TrezorTest, generate_entropy
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ class TestMsgResetDeviceT2(TrezorTest):
|
|||||||
pin_protection=False,
|
pin_protection=False,
|
||||||
label="test",
|
label="test",
|
||||||
language="english",
|
language="english",
|
||||||
slip39=True,
|
backup_type=ResetDeviceBackupType.Slip39_Single_Group,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if device is properly initialized
|
# Check if device is properly initialized
|
||||||
|
Loading…
Reference in New Issue
Block a user