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 #2
0
def create_wallet_for_sync(wallet_file, password, wallet_structure, a):
    #Prepare a testnet wallet file for this wallet
    password_key = bitcoin.bin_dbl_sha256(password)
    #We need a distinct seed for each run so as not to step over each other;
    #make it through a deterministic hash
    seedh = bitcoin.sha256("".join([str(x) for x in a]))[:32]
    encrypted_seed = encryptData(password_key, seedh.decode('hex'))
    timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
    walletfilejson = {
        'creator': 'joinmarket project',
        'creation_time': timestamp,
        'encrypted_seed': encrypted_seed.encode('hex'),
        'network': get_network()
    }
    walletfile = json.dumps(walletfilejson)
    if not os.path.exists('wallets'):
        os.makedirs('wallets')
    with open(os.path.join('wallets', wallet_file), "wb") as f:
        f.write(walletfile)
    #The call to Wallet() in make_wallets should now find the file
    #and read from it:
    return make_wallets(1, [wallet_structure],
                        fixed_seeds=[wallet_file],
                        test_wallet=True,
                        passwords=[password])[0]['wallet']
Exemple #3
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 #4
0
def test_timelocked_output_signing(setup_wallet):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')
    ensure_bip65_activated()
    storage = VolatileStorage()
    SegwitLegacyWalletFidelityBonds.initialize(storage, get_network())
    wallet = SegwitLegacyWalletFidelityBonds(storage)

    index = 0
    timenumber = 0
    script = wallet.get_script_and_update_map(
        FidelityBondMixin.FIDELITY_BOND_MIXDEPTH,
        FidelityBondMixin.BIP32_TIMELOCK_ID, index, timenumber)
    utxo = fund_wallet_addr(wallet, wallet.script_to_addr(script))
    timestamp = wallet._time_number_to_timestamp(timenumber)

    tx = btc.mktx([utxo], [{
        "address":
        str(
            btc.CCoinAddress.from_scriptPubKey(
                btc.standard_scripthash_scriptpubkey(btc.Hash160(b"\x00")))),
        "value":
        10**8 - 9000
    }],
                  locktime=timestamp + 1)
    success, msg = wallet.sign_tx(tx, {0: (script, 10**8)})
    assert success, msg
    txout = jm_single().bc_interface.pushtx(tx.serialize())
    assert txout
 def __init__(self):
     storage = VolatileStorage()
     super().initialize(storage, get_network(), max_mixdepth=5)
     super().__init__(storage)
     self._add_utxos()
     self.ex_utxos = {}
     self.inject_addr_get_failure = False
def persist_walletfile(walletspath,
                       default_wallet_name,
                       encrypted_seed,
                       callbacks=(cli_get_walletname, )):
    timestamp = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
    walletfile = json.dumps({
        'creator': 'joinmarket project',
        'creation_time': timestamp,
        'encrypted_seed': encrypted_seed.encode('hex'),
        'network': get_network()
    })
    walletname = callbacks[0]()
    if len(walletname) == 0:
        walletname = default_wallet_name
    walletpath = os.path.join(walletspath, walletname)
    # Does a wallet with the same name exist?
    if os.path.isfile(walletpath):
        print('ERROR: ' + walletpath + ' already exists. Aborting.')
        return False
    else:
        fd = open(walletpath, 'w')
        fd.write(walletfile)
        fd.close()
        print('saved to ' + walletname)
    return True
Exemple #7
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)
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 #9
0
def create_volatile_wallet(seedphrase, wallet_cls=SegwitWallet):
    storage = VolatileStorage()
    wallet_cls.initialize(storage,
                          get_network(),
                          max_mixdepth=4,
                          entropy=wallet_cls.entropy_from_mnemonic(seedphrase))
    storage.save()
    return wallet_cls(storage)
Exemple #10
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()
Exemple #11
0
def test_is_standard_wallet_script(setup_wallet, wallet_cls):
    storage = VolatileStorage()
    wallet_cls.initialize(
        storage, get_network(), max_mixdepth=0)
    wallet = wallet_cls(storage)
    script = wallet.get_new_script(0, 1)
    assert wallet.is_known_script(script)
    path = wallet.script_to_path(script)
    assert wallet.is_standard_wallet_script(path)
Exemple #12
0
def test_gettimelockaddress_in_past(setup_wallet):
    jm_single().config.set("BLOCKCHAIN", "network", "mainnet")
    storage = VolatileStorage()
    SegwitWalletFidelityBonds.initialize(storage, get_network())
    wallet = SegwitWalletFidelityBonds(storage)

    assert wallet_gettimelockaddress(wallet, "2020-01") == ""
    assert wallet_gettimelockaddress(wallet, "2021-01") == ""
    assert wallet_gettimelockaddress(wallet, "2021-02") != ""
def create_wallet(path, password, max_mixdepth, wallet_cls=None, **kwargs):
    storage = Storage(path, password, create=True)
    wallet_cls = wallet_cls or get_wallet_cls()
    wallet_cls.initialize(storage,
                          get_network(),
                          max_mixdepth=max_mixdepth,
                          **kwargs)
    storage.save()
    return wallet_cls(storage)
Exemple #14
0
def get_populated_wallet(amount=10**8, num=3):
    storage = VolatileStorage()
    SegwitLegacyWallet.initialize(storage, get_network())
    wallet = SegwitLegacyWallet(storage)

    # fund three wallet addresses at mixdepth 0
    for i in range(num):
        fund_wallet_addr(wallet, wallet.get_internal_addr(0), amount / 10**8)

    return wallet
Exemple #15
0
def test_watchonly_wallet(setup_wallet):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')
    storage = VolatileStorage()
    SegwitLegacyWalletFidelityBonds.initialize(storage, get_network())
    wallet = SegwitLegacyWalletFidelityBonds(storage)

    paths = [
        "m/49'/1'/0'/0/0", "m/49'/1'/0'/1/0", "m/49'/1'/0'/2/0:1577836800",
        "m/49'/1'/0'/2/0:2314051200"
    ]
    burn_path = "m/49'/1'/0'/3/0"

    scripts = [
        wallet.get_script_from_path(wallet.path_repr_to_path(path))
        for path in paths
    ]
    privkey, engine = wallet._get_key_from_path(
        wallet.path_repr_to_path(burn_path))
    burn_pubkey = engine.privkey_to_pubkey(privkey)

    master_pub_key = wallet.get_bip32_pub_export(
        FidelityBondMixin.FIDELITY_BOND_MIXDEPTH)
    watchonly_storage = VolatileStorage()
    entropy = FidelityBondMixin.get_xpub_from_fidelity_bond_master_pub_key(
        master_pub_key).encode()
    FidelityBondWatchonlyWallet.initialize(watchonly_storage,
                                           get_network(),
                                           entropy=entropy)
    watchonly_wallet = FidelityBondWatchonlyWallet(watchonly_storage)

    watchonly_scripts = [
        watchonly_wallet.get_script_from_path(
            watchonly_wallet.path_repr_to_path(path)) for path in paths
    ]
    privkey, engine = wallet._get_key_from_path(
        wallet.path_repr_to_path(burn_path))
    watchonly_burn_pubkey = engine.privkey_to_pubkey(privkey)

    for script, watchonly_script in zip(scripts, watchonly_scripts):
        assert script == watchonly_script
    assert burn_pubkey == watchonly_burn_pubkey
Exemple #16
0
def test_is_standard_wallet_script_nonstandard(setup_wallet):
    storage = VolatileStorage()
    SegwitWalletFidelityBonds.initialize(
        storage, get_network(), max_mixdepth=0)
    wallet = SegwitWalletFidelityBonds(storage)
    import_path = wallet.import_private_key(
        0, 'cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM')
    assert wallet.is_standard_wallet_script(import_path)
    ts = wallet.datetime_to_time_number(
        datetime.datetime.strptime("2021-07", "%Y-%m"))
    tl_path = wallet.get_path(0, wallet.BIP32_TIMELOCK_ID, ts)
    assert not wallet.is_standard_wallet_script(tl_path)
    def __init__(self, balances):
        """Creates the wallet, setting the balances of the mixdepths
        as given by the array.  (And the number of mixdepths from the array
        elements."""

        load_test_config()

        storage = VolatileStorage()
        super().initialize(storage, get_network(), max_mixdepth=len(balances)-1)
        super().__init__(storage)

        for m, b in enumerate(balances):
            self.add_utxo_at_mixdepth(m, b)
Exemple #18
0
def test_signmessage(seed, hdpath, walletcls, message, sig, addr):
    load_test_config()
    jm_single().config.set('BLOCKCHAIN', 'network', 'mainnet')
    select_chain_params("bitcoin/mainnet")
    storage = VolatileStorage()
    walletcls.initialize(
        storage, get_network(), entropy=seed, max_mixdepth=3)
    wallet = walletcls(storage)
    s, m, a = wallet_signmessage(wallet, hdpath, message,
                                        out_str=False)
    assert (s, m, a) == (sig, message, addr)
    jm_single().config.set("BLOCKCHAIN", "network", "testnet")
    select_chain_params("bitcoin/regtest")
Exemple #19
0
def test_gettimelockaddress_method(setup_wallet, timenumber, locktime_string):
    jm_single().config.set("BLOCKCHAIN", "network", "mainnet")
    storage = VolatileStorage()
    SegwitWalletFidelityBonds.initialize(storage, get_network())
    wallet = SegwitWalletFidelityBonds(storage)

    m = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH
    address_type = FidelityBondMixin.BIP32_TIMELOCK_ID
    script = wallet.get_script_and_update_map(m, address_type, timenumber)
    addr = wallet.script_to_addr(script)

    addr_from_method = wallet_gettimelockaddress(wallet, locktime_string)

    assert addr == addr_from_method
Exemple #20
0
def test_signing_simple(setup_wallet, wallet_cls, type_check):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')
    storage = VolatileStorage()
    wallet_cls.initialize(storage, get_network())
    wallet = wallet_cls(storage)
    utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(0))
    tx = btc.deserialize(btc.mktx(['{}:{}'.format(hexlify(utxo[0]).decode('ascii'), utxo[1])],
                                  ['00'*17 + ':' + str(10**8 - 9000)]))
    binarize_tx(tx)
    script = wallet.get_script(0, 1, 0)
    wallet.sign_tx(tx, {0: (script, 10**8)})
    type_check(tx)
    txout = jm_single().bc_interface.pushtx(hexlify(btc.serialize(tx)).decode('ascii'))
    assert txout
Exemple #21
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 #22
0
def test_bip32_burn_keys(setup_wallet, index, wif):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')

    entropy = unhexlify('2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817')
    storage = VolatileStorage()
    SegwitWalletFidelityBonds.initialize(
        storage, get_network(), entropy=entropy, max_mixdepth=1)
    wallet = SegwitWalletFidelityBonds(storage)
    mixdepth = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH
    address_type = FidelityBondMixin.BIP32_BURN_ID

    #advance index_cache enough
    wallet.set_next_index(mixdepth, address_type, index, force=True)

    assert wif == wallet.get_wif_path(wallet.get_path(mixdepth, address_type, index))
Exemple #23
0
def test_signing_simple(setup_wallet, wallet_cls, type_check):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')
    storage = VolatileStorage()
    wallet_cls.initialize(storage, get_network())
    wallet = wallet_cls(storage)
    utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(0))
    # The dummy output is constructed as an unspendable p2sh:
    tx = btc.deserialize(btc.mktx(['{}:{}'.format(
        hexlify(utxo[0]).decode('ascii'), utxo[1])],
        [btc.p2sh_scriptaddr(b"\x00",magicbyte=196) + ':' + str(10**8 - 9000)]))
    script = wallet.get_script(0, 1, 0)
    tx = wallet.sign_tx(tx, {0: (script, 10**8)})
    type_check(tx)
    txout = jm_single().bc_interface.pushtx(btc.serialize(tx))
    assert txout
Exemple #24
0
def test_gettimelockaddress_method(setup_wallet, timenumber, locktime_string):
    storage = VolatileStorage()
    SegwitLegacyWalletFidelityBonds.initialize(storage, get_network())
    wallet = SegwitLegacyWalletFidelityBonds(storage)

    m = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH
    address_type = FidelityBondMixin.BIP32_TIMELOCK_ID
    index = wallet.get_next_unused_index(m, address_type)
    script = wallet.get_script_and_update_map(m, address_type, index,
                                              timenumber)
    addr = wallet.script_to_addr(script)

    addr_from_method = wallet_gettimelockaddress(wallet, locktime_string)

    assert addr == addr_from_method
def open_test_wallet_maybe(path,
                           seed,
                           max_mixdepth,
                           test_wallet_cls=SegwitLegacyWallet,
                           **kwargs):
    """
    Create a volatile test wallet if path is a hex-encoded string of length 64,
    otherwise run open_wallet().

    params:
        path: path to wallet file, ignored for test wallets
        seed: hex-encoded test seed
        max_mixdepth: maximum mixdepth to use
        kwargs: see open_wallet()

    returns:
        wallet object
    """
    # If the native flag is set in the config, it overrides the argument
    # test_wallet_cls
    if jm_single().config.get("POLICY", "native") == "true":
        test_wallet_cls = SegwitWallet
    if len(seed) == test_wallet_cls.ENTROPY_BYTES * 2:
        try:
            seed = binascii.unhexlify(seed)
        except binascii.Error:
            pass
        else:
            if max_mixdepth is None:
                max_mixdepth = DEFAULT_MIXDEPTH

            storage = VolatileStorage()
            test_wallet_cls.initialize(storage,
                                       get_network(),
                                       max_mixdepth=max_mixdepth,
                                       entropy=seed)
            #wallet instantiation insists on no unexpected kwargs,
            #but Qt caller opens both test and mainnet with same args,
            #hence these checks/deletes of unwanted args for tests.
            if 'ask_for_password' in kwargs:
                del kwargs['ask_for_password']
            if 'password' in kwargs:
                del kwargs['password']
            if 'read_only' in kwargs:
                del kwargs['read_only']
            return test_wallet_cls(storage, **kwargs)

    return open_wallet(path, mixdepth=max_mixdepth, **kwargs)
Exemple #26
0
def test_imported_key_removed(setup_wallet):
    wif = 'cRAGLvPmhpzJNgdMT4W2gVwEW3fusfaDqdQWM2vnWLgXKzCWKtcM'

    storage = VolatileStorage()
    SegwitLegacyWallet.initialize(storage, get_network())
    wallet = SegwitLegacyWallet(storage)

    path = wallet.import_private_key(1, wif)
    script = wallet.get_script_from_path(path)
    assert wallet.is_known_script(script)

    wallet.remove_imported_key(path=path)
    assert not wallet.is_known_script(script)

    with pytest.raises(WalletError):
        wallet.get_script_from_path(path)
Exemple #27
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()
Exemple #28
0
def test_freeze_timelocked_utxos(setup_env_nodeps):
    storage = VolatileStorage()
    SegwitWalletFidelityBonds.initialize(storage, get_network())
    wallet = SegwitWalletFidelityBonds(storage)
    ts = wallet.datetime_to_time_number(
        datetime.datetime.strptime("2021-07", "%Y-%m"))
    tl_path = wallet.get_path(wallet.FIDELITY_BOND_MIXDEPTH,
                              wallet.BIP32_TIMELOCK_ID, ts)
    tl_script = wallet.get_script_from_path(tl_path)
    utxo = (b'a' * 32, 0)
    wallet.add_utxo(utxo[0], utxo[1], tl_script, 100000000)
    assert not wallet._utxos.is_disabled(*utxo)

    maker = OfflineMaker(WalletService(wallet))
    maker.freeze_timelocked_utxos()
    assert wallet._utxos.is_disabled(*utxo)
Exemple #29
0
def test_bip32_timelocked_addresses(setup_wallet, timenumber, address, wif):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')

    entropy = unhexlify('2e0339ba89b4a1272cdf78b27ee62669ee01992a59e836e2807051be128ca817')
    storage = VolatileStorage()
    SegwitWalletFidelityBonds.initialize(
        storage, get_network(), entropy=entropy, max_mixdepth=1)
    wallet = SegwitWalletFidelityBonds(storage)
    mixdepth = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH
    address_type = FidelityBondMixin.BIP32_TIMELOCK_ID

    #wallet needs to know about the script beforehand
    wallet.get_script_and_update_map(mixdepth, address_type, timenumber)

    assert address == wallet.get_addr(mixdepth, address_type, timenumber)
    assert wif == wallet.get_wif_path(wallet.get_path(mixdepth, address_type, timenumber))
Exemple #30
0
def test_signing_simple(setup_wallet, wallet_cls, type_check):
    jm_single().config.set('BLOCKCHAIN', 'network', 'testnet')
    storage = VolatileStorage()
    wallet_cls.initialize(storage, get_network())
    wallet = wallet_cls(storage)
    utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(0))
    # The dummy output is of length 25 bytes, because, for SegwitWallet, we else
    # trigger the tx-size-small DOS limit in Bitcoin Core (82 bytes is the
    # smallest "normal" transaction size (non-segwit size, ie no witness)
    tx = btc.deserialize(
        btc.mktx(['{}:{}'.format(hexlify(utxo[0]).decode('ascii'), utxo[1])],
                 ['00' * 25 + ':' + str(10**8 - 9000)]))
    script = wallet.get_script(0, 1, 0)
    tx = wallet.sign_tx(tx, {0: (script, 10**8)})
    type_check(tx)
    txout = jm_single().bc_interface.pushtx(btc.serialize(tx))
    assert txout