Exemple #1
0
def test_bip32_test_vector_1(monkeypatch, setup_wallet):
    jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet')

    entropy = unhexlify('000102030405060708090a0b0c0d0e0f')
    storage = VolatileStorage()
    LegacyWallet.initialize(
        storage, get_network(), entropy=entropy, max_mixdepth=0)

    # test vector 1 is using hardened derivation for the account/mixdepth level
    monkeypatch.setattr(LegacyWallet, '_get_mixdepth_from_path',
                        BIP49Wallet._get_mixdepth_from_path)
    monkeypatch.setattr(LegacyWallet, '_get_bip32_mixdepth_path_level',
                        BIP49Wallet._get_bip32_mixdepth_path_level)
    monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path',
                        BIP32Wallet._get_bip32_base_path)
    monkeypatch.setattr(LegacyWallet, '_create_master_key',
                        BIP32Wallet._create_master_key)

    wallet = LegacyWallet(storage)

    assert wallet.get_bip32_priv_export() == 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
    assert wallet.get_bip32_pub_export() == 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
    assert wallet.get_bip32_priv_export(0) == 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
    assert wallet.get_bip32_pub_export(0) == 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'
    assert wallet.get_bip32_priv_export(0, 1) == 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
    assert wallet.get_bip32_pub_export(0, 1) == 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
Exemple #2
0
def test_bip32_addresses_p2pkh(monkeypatch, setup_wallet, mixdepth, internal,
                               index, address, wif):
    """
    Test with a random but fixed entropy
    """
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')

    entropy = unhexlify(
        '2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817')
    storage = VolatileStorage()
    LegacyWallet.initialize(storage,
                            get_network(),
                            entropy=entropy,
                            max_mixdepth=3)

    monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path',
                        BIP32Wallet._get_bip32_base_path)
    monkeypatch.setattr(LegacyWallet, '_create_master_key',
                        BIP32Wallet._create_master_key)

    wallet = LegacyWallet(storage)

    # wallet needs to know about all intermediate keys
    for i in range(index + 1):
        wallet.get_new_script(mixdepth, internal)

    assert wif == wallet.get_wif(mixdepth, internal, index)
    assert address == wallet.get_addr(mixdepth, internal, index)
Exemple #3
0
def test_bip32_test_vector_3(monkeypatch, setup_wallet):
    jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet')

    entropy = unhexlify(
        '4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be'
    )
    storage = VolatileStorage()
    LegacyWallet.initialize(storage,
                            get_network(),
                            entropy=entropy,
                            max_mixdepth=0)

    # test vector 3 is using hardened derivation for the account/mixdepth level
    monkeypatch.setattr(LegacyWallet, '_get_mixdepth_from_path',
                        BIP49Wallet._get_mixdepth_from_path)
    monkeypatch.setattr(LegacyWallet, '_get_bip32_mixdepth_path_level',
                        BIP49Wallet._get_bip32_mixdepth_path_level)
    monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path',
                        BIP32Wallet._get_bip32_base_path)
    monkeypatch.setattr(LegacyWallet, '_create_master_key',
                        BIP32Wallet._create_master_key)

    wallet = LegacyWallet(storage)

    assert wallet.get_bip32_priv_export(
    ) == 'xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6'
    assert wallet.get_bip32_pub_export(
    ) == 'xpub661MyMwAqRbcEZVB4dScxMAdx6d4nFc9nvyvH3v4gJL378CSRZiYmhRoP7mBy6gSPSCYk6SzXPTf3ND1cZAceL7SfJ1Z3GC8vBgp2epUt13'
    assert wallet.get_bip32_priv_export(
        0
    ) == 'xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L'
    assert wallet.get_bip32_pub_export(
        0
    ) == 'xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y'
Exemple #4
0
def test_bip32_test_vector_2(monkeypatch, setup_wallet):
    jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet')

    entropy = unhexlify(
        'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
    )
    storage = VolatileStorage()
    LegacyWallet.initialize(storage,
                            get_network(),
                            entropy=entropy,
                            max_mixdepth=0)

    monkeypatch.setattr(LegacyWallet, '_get_bip32_base_path',
                        BIP32Wallet._get_bip32_base_path)
    monkeypatch.setattr(LegacyWallet, '_create_master_key',
                        BIP32Wallet._create_master_key)

    wallet = LegacyWallet(storage)

    assert wallet.get_bip32_priv_export(
    ) == 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
    assert wallet.get_bip32_pub_export(
    ) == 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
    assert wallet.get_bip32_priv_export(
        0
    ) == 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
    assert wallet.get_bip32_pub_export(
        0
    ) == 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
Exemple #5
0
def wallet_generate_recover(method, walletspath,
                            default_wallet_name='wallet.jmdat',
                            mixdepth=DEFAULT_MIXDEPTH):
    if is_segwit_mode():
        #Here using default callbacks for scripts (not used in Qt)
        return wallet_generate_recover_bip39(
            method, walletspath, default_wallet_name, mixdepth=mixdepth)

    entropy = None
    if method == 'recover':
        seed = raw_input("Input 12 word recovery seed: ")
        try:
            entropy = LegacyWallet.entropy_from_mnemonic(seed)
        except WalletError as e:
            print("Unable to restore seed: {}".format(e.message))
            return False
    elif method != 'generate':
        raise Exception("unknown method for wallet creation: '{}'"
                        .format(method))

    password = cli_get_wallet_passphrase_check()
    if not password:
        return False

    wallet_name = cli_get_wallet_file_name()
    if not wallet_name:
        wallet_name = default_wallet_name
    wallet_path = os.path.join(walletspath, wallet_name)

    wallet = create_wallet(wallet_path, password, mixdepth,
                           wallet_cls=LegacyWallet, entropy=entropy)
    print("Write down and safely store this wallet recovery seed\n\n{}\n"
          .format(wallet.get_mnemonic_words()[0]))
    wallet.close()
    return True
Exemple #6
0
def test_wrong_wallet_cls(setup_wallet):
    storage = VolatileStorage()
    SegwitLegacyWallet.initialize(storage, get_network())
    wallet = SegwitLegacyWallet(storage)

    wallet.save()
    data = storage.file_data

    del wallet
    del storage

    storage = VolatileStorage(data=data)

    with pytest.raises(Exception):
        LegacyWallet(storage)
Exemple #7
0
def test_wallet_id(setup_wallet):
    storage1 = VolatileStorage()
    SegwitLegacyWallet.initialize(storage1, get_network())
    wallet1 = SegwitLegacyWallet(storage1)

    storage2 = VolatileStorage()
    LegacyWallet.initialize(storage2, get_network(), entropy=wallet1._entropy)
    wallet2 = LegacyWallet(storage2)

    assert wallet1.get_wallet_id() != wallet2.get_wallet_id()

    storage2 = VolatileStorage()
    SegwitLegacyWallet.initialize(storage2, get_network(),
                                  entropy=wallet1._entropy)
    wallet2 = SegwitLegacyWallet(storage2)

    assert wallet1.get_wallet_id() == wallet2.get_wallet_id()