Ejemplo n.º 1
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()
def wallet_generate_recover_bip39(
    method,
    walletspath,
    default_wallet_name,
    mixdepth=DEFAULT_MIXDEPTH,
    callbacks=(cli_display_user_words, cli_user_mnemonic_entry,
               cli_get_wallet_passphrase_check, cli_get_wallet_file_name,
               cli_get_mnemonic_extension)):
    """Optionally provide callbacks:
    0 - display seed
    1 - enter seed (for recovery)
    2 - enter wallet password
    3 - enter wallet file name
    4 - enter mnemonic extension
    The defaults are for terminal entry.
    """
    entropy = None
    mnemonic_extension = None
    if method == "generate":
        mnemonic_extension = callbacks[4]()
    elif method == 'recover':
        words, mnemonic_extension = callbacks[1]()
        mnemonic_extension = mnemonic_extension and mnemonic_extension.strip()
        if not words:
            return False
        try:
            entropy = SegwitLegacyWallet.entropy_from_mnemonic(words)
        except WalletError:
            return False
    else:
        raise Exception(
            "unknown method for wallet creation: '{}'".format(method))

    password = callbacks[2]()
    if not password:
        return False

    wallet_name = callbacks[3]()
    if wallet_name == "cancelled":
        # currently used only by Qt, because user has option
        # to click cancel in dialog.
        return False
    if not wallet_name:
        wallet_name = default_wallet_name
    wallet_path = os.path.join(walletspath, wallet_name)

    wallet = create_wallet(wallet_path,
                           password,
                           mixdepth,
                           entropy=entropy,
                           entropy_extension=mnemonic_extension)
    mnemonic, mnext = wallet.get_mnemonic_words()
    callbacks[0] and callbacks[0](mnemonic, mnext or '')
    wallet.close()
    return True
Ejemplo n.º 3
0
def test_bip39_seeds(monkeypatch, setup_wallet, entropy, mnemonic, key, xpriv):
    jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet')
    created_entropy = SegwitLegacyWallet.entropy_from_mnemonic(mnemonic)
    assert entropy == hexlify(created_entropy).decode('ascii')
    storage = VolatileStorage()
    SegwitLegacyWallet.initialize(
        storage, get_network(), entropy=created_entropy,
        entropy_extension='TREZOR', max_mixdepth=4)
    wallet = SegwitLegacyWallet(storage)
    assert (mnemonic, b'TREZOR') == wallet.get_mnemonic_words()
    assert key == hexlify(wallet._create_master_key()).decode('ascii')

    # need to monkeypatch this, else we'll default to the BIP-49 path
    monkeypatch.setattr(SegwitLegacyWallet, '_get_bip32_base_path',
                        BIP32Wallet._get_bip32_base_path)
    assert xpriv == wallet.get_bip32_priv_export()
Ejemplo n.º 4
0
def test_bip49_seed(monkeypatch, setup_wallet):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')
    mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
    master_xpriv = 'tprv8ZgxMBicQKsPe5YMU9gHen4Ez3ApihUfykaqUorj9t6FDqy3nP6eoXiAo2ssvpAjoLroQxHqr3R5nE3a5dU3DHTjTgJDd7zrbniJr6nrCzd'
    account0_xpriv = 'tprv8gRrNu65W2Msef2BdBSUgFdRTGzC8EwVXnV7UGS3faeXtuMVtGfEdidVeGbThs4ELEoayCAzZQ4uUji9DUiAs7erdVskqju7hrBcDvDsdbY'
    addr0_script_hash = '336caa13e08b96080a32b5d818d59b4ab3b36742'

    entropy = SegwitLegacyWallet.entropy_from_mnemonic(mnemonic)
    storage = VolatileStorage()
    SegwitLegacyWallet.initialize(
        storage, get_network(), entropy=entropy, max_mixdepth=0)
    wallet = SegwitLegacyWallet(storage)
    assert (mnemonic, None) == wallet.get_mnemonic_words()
    assert account0_xpriv == wallet.get_bip32_priv_export(0)
    assert addr0_script_hash == hexlify(wallet.get_external_script(0)[2:-1]).decode('ascii')

    # FIXME: is this desired behaviour? BIP49 wallet will not return xpriv for
    # the root key but only for key after base path
    monkeypatch.setattr(SegwitLegacyWallet, '_get_bip32_base_path',
                        BIP32Wallet._get_bip32_base_path)
    assert master_xpriv == wallet.get_bip32_priv_export()
Ejemplo n.º 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.')
    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()