mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 01:35:20 +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()))
|
return ' '.join(sorted(known_commands.keys()))
|
||||||
|
|
||||||
@command('')
|
@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.
|
"""Create a new wallet.
|
||||||
If you want to be prompted for an argument, type '?' or ':' (concealed)
|
If you want to be prompted for an argument, type '?' or ':' (concealed)
|
||||||
"""
|
"""
|
||||||
|
@ -140,7 +140,7 @@ class Commands:
|
||||||
passphrase=passphrase,
|
passphrase=passphrase,
|
||||||
password=password,
|
password=password,
|
||||||
encrypt_file=encrypt_file,
|
encrypt_file=encrypt_file,
|
||||||
segwit=segwit)
|
seed_type=seed_type)
|
||||||
return {
|
return {
|
||||||
'seed': d['seed'],
|
'seed': d['seed'],
|
||||||
'path': d['wallet'].storage.path,
|
'path': d['wallet'].storage.path,
|
||||||
|
@ -203,11 +203,10 @@ class Commands:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@command('')
|
@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"""
|
"""Create a seed"""
|
||||||
from .mnemonic import Mnemonic
|
from .mnemonic import Mnemonic
|
||||||
t = 'segwit' if segwit else 'standard'
|
s = Mnemonic(language).make_seed(seed_type, num_bits=nbits)
|
||||||
s = Mnemonic(language).make_seed(t, nbits)
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
@command('n')
|
@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)."),
|
'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"),
|
'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"),
|
'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"),
|
'language': ("-L", "Default language for wordlist"),
|
||||||
'passphrase': (None, "Seed extension"),
|
'passphrase': (None, "Seed extension"),
|
||||||
'privkey': (None, "Private key. Set to '?' to get a prompt."),
|
'privkey': (None, "Private key. Set to '?' to get a prompt."),
|
||||||
|
|
|
@ -160,7 +160,9 @@ class Mnemonic(Logger):
|
||||||
i = i*n + k
|
i = i*n + k
|
||||||
return i
|
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)
|
prefix = version.seed_prefix(seed_type)
|
||||||
# increase num_bits in order to obtain a uniform distribution for the last word
|
# increase num_bits in order to obtain a uniform distribution for the last word
|
||||||
bpw = math.log(len(self.wordlist), 2)
|
bpw = math.log(len(self.wordlist), 2)
|
||||||
|
|
|
@ -120,7 +120,7 @@ class Test_NewMnemonic(SequentialTestCase):
|
||||||
iters = 10
|
iters = 10
|
||||||
m = mnemonic.Mnemonic(lang='en')
|
m = mnemonic.Mnemonic(lang='en')
|
||||||
for _ in range(iters):
|
for _ in range(iters):
|
||||||
seed = m.make_seed()
|
seed = m.make_seed("standard")
|
||||||
i = m.mnemonic_decode(seed)
|
i = m.mnemonic_decode(seed)
|
||||||
self.assertEqual(m.mnemonic_encode(i), seed)
|
self.assertEqual(m.mnemonic_encode(i), seed)
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,6 @@ class TestCreateRestoreWallet(WalletTestCase):
|
||||||
passphrase=passphrase,
|
passphrase=passphrase,
|
||||||
password=password,
|
password=password,
|
||||||
encrypt_file=encrypt_file,
|
encrypt_file=encrypt_file,
|
||||||
segwit=True,
|
|
||||||
gap_limit=1)
|
gap_limit=1)
|
||||||
wallet = d['wallet'] # type: Standard_Wallet
|
wallet = d['wallet'] # type: Standard_Wallet
|
||||||
wallet.check_password(password)
|
wallet.check_password(password)
|
||||||
|
|
|
@ -19,3 +19,4 @@ def seed_prefix(seed_type):
|
||||||
return SEED_PREFIX_2FA
|
return SEED_PREFIX_2FA
|
||||||
elif seed_type == '2fa_segwit':
|
elif seed_type == '2fa_segwit':
|
||||||
return SEED_PREFIX_2FA_SW
|
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))
|
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"""
|
"""Create a new wallet"""
|
||||||
storage = WalletStorage(path)
|
storage = WalletStorage(path)
|
||||||
if storage.file_exists():
|
if storage.file_exists():
|
||||||
raise Exception("Remove the existing wallet first!")
|
raise Exception("Remove the existing wallet first!")
|
||||||
|
|
||||||
seed_type = 'segwit' if segwit else 'standard'
|
|
||||||
seed = Mnemonic('en').make_seed(seed_type)
|
seed = Mnemonic('en').make_seed(seed_type)
|
||||||
k = keystore.from_seed(seed, passphrase)
|
k = keystore.from_seed(seed, passphrase)
|
||||||
storage.put('keystore', k.dump())
|
storage.put('keystore', k.dump())
|
||||||
|
|
Loading…
Add table
Reference in a new issue