Browse Source

commands: change API of "make_seed" and "create" commands

instead of "segwit" boolean, take a "seed_type" optional arg
default seed_type to "segwit"
previously these commands created legacy seeds by defalt
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
parent
commit
1c75d939d9
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/commands.py
  2. 4
      electrum/mnemonic.py
  3. 2
      electrum/tests/test_mnemonic.py
  4. 1
      electrum/tests/test_wallet.py
  5. 1
      electrum/version.py
  6. 3
      electrum/wallet.py

11
electrum/commands.py

@ -132,7 +132,7 @@ class Commands:
return ' '.join(sorted(known_commands.keys()))
@command('')
def create(self, passphrase=None, password=None, encrypt_file=True, segwit=False):
def create(self, passphrase=None, password=None, encrypt_file=True, seed_type=None):
"""Create a new wallet.
If you want to be prompted for an argument, type '?' or ':' (concealed)
"""
@ -140,7 +140,7 @@ class Commands:
passphrase=passphrase,
password=password,
encrypt_file=encrypt_file,
segwit=segwit)
seed_type=seed_type)
return {
'seed': d['seed'],
'path': d['wallet'].storage.path,
@ -203,11 +203,10 @@ class Commands:
return True
@command('')
def make_seed(self, nbits=132, language=None, segwit=False):
def make_seed(self, nbits=132, language=None, seed_type=None):
"""Create a seed"""
from .mnemonic import Mnemonic
t = 'segwit' if segwit else 'standard'
s = Mnemonic(language).make_seed(t, nbits)
s = Mnemonic(language).make_seed(seed_type, num_bits=nbits)
return s
@command('n')
@ -810,7 +809,7 @@ command_options = {
'from_addr': ("-F", "Source address (must be a wallet address; use sweep to spend from non-wallet address)."),
'change_addr': ("-c", "Change address. Default is a spare address, or the source address if it's not in the wallet"),
'nbits': (None, "Number of bits of entropy"),
'segwit': (None, "Create segwit seed"),
'seed_type': (None, "The type of seed to create, e.g. 'standard' or 'segwit'"),
'language': ("-L", "Default language for wordlist"),
'passphrase': (None, "Seed extension"),
'privkey': (None, "Private key. Set to '?' to get a prompt."),

4
electrum/mnemonic.py

@ -160,7 +160,9 @@ class Mnemonic(Logger):
i = i*n + k
return i
def make_seed(self, seed_type='standard', num_bits=132):
def make_seed(self, seed_type=None, *, num_bits=132):
if seed_type is None:
seed_type = 'segwit'
prefix = version.seed_prefix(seed_type)
# increase num_bits in order to obtain a uniform distribution for the last word
bpw = math.log(len(self.wordlist), 2)

2
electrum/tests/test_mnemonic.py

@ -120,7 +120,7 @@ class Test_NewMnemonic(SequentialTestCase):
iters = 10
m = mnemonic.Mnemonic(lang='en')
for _ in range(iters):
seed = m.make_seed()
seed = m.make_seed("standard")
i = m.mnemonic_decode(seed)
self.assertEqual(m.mnemonic_encode(i), seed)

1
electrum/tests/test_wallet.py

@ -156,7 +156,6 @@ class TestCreateRestoreWallet(WalletTestCase):
passphrase=passphrase,
password=password,
encrypt_file=encrypt_file,
segwit=True,
gap_limit=1)
wallet = d['wallet'] # type: Standard_Wallet
wallet.check_password(password)

1
electrum/version.py

@ -19,3 +19,4 @@ def seed_prefix(seed_type):
return SEED_PREFIX_2FA
elif seed_type == '2fa_segwit':
return SEED_PREFIX_2FA_SW
raise Exception(f"unknown seed_type: {seed_type}")

3
electrum/wallet.py

@ -2005,13 +2005,12 @@ class Wallet(object):
raise WalletFileException("Unknown wallet type: " + str(wallet_type))
def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True, segwit=True, gap_limit=None):
def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True, seed_type=None, gap_limit=None):
"""Create a new wallet"""
storage = WalletStorage(path)
if storage.file_exists():
raise Exception("Remove the existing wallet first!")
seed_type = 'segwit' if segwit else 'standard'
seed = Mnemonic('en').make_seed(seed_type)
k = keystore.from_seed(seed, passphrase)
storage.put('keystore', k.dump())

Loading…
Cancel
Save