From 53e7bf1018c4f0be361ed01b28f8983dba5b6d58 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 28 Aug 2021 11:17:34 +0200 Subject: [PATCH] genwallet.py: Add option --recovery-seed-file --- scripts/genwallet.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/genwallet.py b/scripts/genwallet.py index c1d760c..ddffaf0 100755 --- a/scripts/genwallet.py +++ b/scripts/genwallet.py @@ -5,6 +5,7 @@ import os from optparse import OptionParser +from pathlib import Path from jmclient import ( load_program_config, add_base_options, SegwitWalletFidelityBonds, SegwitLegacyWallet, create_wallet, jm_single, wallet_utils @@ -19,6 +20,13 @@ def main(): description='Create a wallet with the given wallet name and password.' ) add_base_options(parser) + parser.add_option( + '--recovery-seed-file', + dest='seed_file', + default=None, + help=('File containing a mnemonic recovery phrase. If provided, the wallet ' + 'is recovered from this seed instead of being newly generated.') + ) (options, args) = parser.parse_args() wallet_name = args[0] if options.wallet_password_stdin: @@ -26,6 +34,7 @@ def main(): else: assert len(args) > 1, "must provide password via stdin (see --help), or as second argument." password = args[1].encode("utf-8") + seed = options.seed_file and Path(options.seed_file).read_text().rstrip() load_program_config(config_path=options.datadir) wallet_root_path = os.path.join(jm_single().datadir, "wallets") @@ -35,7 +44,8 @@ def main(): else: # Fidelity Bonds are not available for segwit legacy wallets walletclass = SegwitLegacyWallet - wallet = create_wallet(wallet_path, password, wallet_utils.DEFAULT_MIXDEPTH, walletclass) + entropy = seed and SegwitLegacyWallet.entropy_from_mnemonic(seed) + wallet = create_wallet(wallet_path, password, wallet_utils.DEFAULT_MIXDEPTH, walletclass, entropy=entropy) jmprint("recovery_seed:{}" .format(wallet.get_mnemonic_words()[0]), "important") wallet.close()