mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 01:11:35 +00:00
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
This commit is contained in:
parent
0ec9f79402
commit
1c75d939d9
6 changed files with 11 additions and 11 deletions
|
@ -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."),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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}")
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue