def main():
    parser = OptionParser(
        usage='usage: %prog [options] wallet_file_name password',
        description='Create a wallet with the given wallet name and password.')
    add_base_options(parser)
    (options, args) = parser.parse_args()
    if options.wallet_password_stdin:
        stdin = sys.stdin.read()
        password = stdin.encode("utf-8")
    else:
        assert len(
            args
        ) > 1, "must provide password via stdin (see --help), or as second argument."
        password = args[1].encode("utf-8")
    load_program_config(config_path=options.datadir)
    wallet_root_path = os.path.join(jm_single().datadir, "wallets")
    wallet_name = os.path.join(wallet_root_path, args[0])
    if jm_single().config.get("POLICY", "native") == "true":
        walletclass = SegwitWallet
    else:
        walletclass = SegwitLegacyWallet
    wallet = create_wallet(wallet_name, password, 4, walletclass)
    jmprint("recovery_seed:{}".format(wallet.get_mnemonic_words()[0]),
            "important")
    wallet.close()
예제 #2
0
def main():
    parser = OptionParser(
        usage='usage: %prog [options] wallet_file_name',
        description='Create a wallet with the given wallet name')
    (options, args) = parser.parse_args()

    load_program_config(config_path="/data/.joinmarket")
    with open(os.path.join(jm_single().datadir, "jm-wallet-seed"),
              "r") as file:
        words = file.read().replace('\n', '')
        words.strip()
    with open(os.path.join(jm_single().datadir, "jm-wallet-password"),
              "r") as file:
        password = file.read().replace('\n', '').encode("utf-8")
    entropy = SegwitLegacyWallet.entropy_from_mnemonic(str(words))
    wallet_root_path = os.path.join(jm_single().datadir, "wallets")
    # add wallet as first argument
    wallet_name = os.path.join(wallet_root_path, args[0])
    wallet = create_wallet(wallet_name,
                           password,
                           4,
                           SegwitLegacyWallet,
                           entropy=entropy,
                           entropy_extension=None)
    jmprint("recovery_seed:{}".format(wallet.get_mnemonic_words()[0]),
            "important")
    wallet.close()
예제 #3
0
def test_create_wallet(setup_wallet, password, wallet_cls):
    wallet_name = test_create_wallet_filename
    password = password.encode("utf-8")
    # test mainnet (we are not transacting)
    btc.select_chain_params("bitcoin")
    wallet = create_wallet(wallet_name, password, 4, wallet_cls)
    mnemonic = wallet.get_mnemonic_words()[0]
    firstkey = wallet.get_key_from_addr(wallet.get_addr(0,0,0))
    print("Created mnemonic, firstkey: ", mnemonic, firstkey)
    wallet.close()
    # ensure that the wallet file created is openable with the password,
    # and has the parameters that were claimed on creation:
    new_wallet = open_test_wallet_maybe(wallet_name, "", 4,
                        password=password, ask_for_password=False)
    assert new_wallet.get_mnemonic_words()[0] == mnemonic
    assert new_wallet.get_key_from_addr(
        new_wallet.get_addr(0,0,0)) == firstkey
    os.remove(wallet_name)
    btc.select_chain_params("bitcoin/regtest")
 def createwallet(self, request):
     print_req(request)
     # we only handle one wallet at a time;
     # if there is a currently unlocked wallet,
     # refuse to process the request:
     if self.services["wallet"]:
         raise WalletAlreadyUnlocked()
     request_data = self.get_POST_body(
         request, ["walletname", "password", "wallettype"])
     if not request_data:
         raise InvalidRequestFormat()
     wallettype = request_data["wallettype"]
     if wallettype == "sw":
         wallet_cls = SegwitWallet
     elif wallettype == "sw-legacy":
         wallet_cls = SegwitLegacyWallet
     elif wallettype == "sw-fb":
         wallet_cls = SegwitWalletFidelityBonds
     else:
         raise InvalidRequestFormat()
     # use the config's data location combined with the json
     # data to construct the wallet path:
     wallet_root_path = os.path.join(jm_single().datadir, "wallets")
     wallet_name = os.path.join(wallet_root_path,
                                request_data["walletname"])
     try:
         wallet = create_wallet(
             wallet_name,
             request_data["password"].encode("ascii"),
             4,
             wallet_cls=wallet_cls)
         # extension not yet supported in RPC create; TODO
         seed, extension = wallet.get_mnemonic_words()
     except RetryableStorageError:
         raise LockExists()
     except StorageError:
         raise WalletAlreadyExists()
     # finally, after the wallet is successfully created, we should
     # start the wallet service, then return info to the caller:
     return self.initialize_wallet_service(request,
                                           wallet,
                                           request_data["walletname"],
                                           seedphrase=seed)
예제 #5
0
def main():
    parser = OptionParser(
    usage='usage: %prog [options] wallet_file_name password',
    description='Create a wallet with the given wallet name and password.')
    (options, args) = parser.parse_args()

    # Load up defaults
    load_program_config(config_path='/data/.joinmarket')
    wallet_root_path = os.path.join(jm_single().datadir, "wallets")
    # get wallet from first argument
    wallet_name = os.path.join(wallet_root_path, args[0])
    wallet = create_wallet(wallet_name, args[1].encode("utf-8"), 4, SegwitLegacyWallet)
    # Open file for writing
    seedfile = open(os.path.join(jm_single().datadir, "jm-wallet-seed"), "w")
    seedfile.write(wallet.get_mnemonic_words()[0])
    seedfile.write("\n")
    seedfile.close()

    jmprint("recovery_seed:{}"
         .format(wallet.get_mnemonic_words()[0]), "important")
    wallet.close()
def main():
    parser = OptionParser(
        usage='usage: %prog [options] wallet_file_name [password]',
        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:
        password = wallet_utils.read_password_stdin()
    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")
    wallet_path = os.path.join(wallet_root_path, wallet_name)
    if jm_single().config.get("POLICY", "native") == "true":
        walletclass = SegwitWalletFidelityBonds
    else:
        # Fidelity Bonds are not available for segwit legacy wallets
        walletclass = SegwitLegacyWallet
    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()