예제 #1
0
def create_bitcoin_address(test_obj):
    # fee address
    pk = str(test_obj.hdwallet.get_pubkey(path=FEE_PATH).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = FEE_PATH
    test_obj.addr_dic['fee'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set fee addr: ' + str(addr))
    path2 = FEE_PATH + '/0'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set fee ct_addr: ' + str(ct_addr))

    # gen address
    pk = str(test_obj.hdwallet.get_pubkey(path=GEN_PATH).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = FEE_PATH
    test_obj.addr_dic['gen'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set gen addr: ' + str(addr))
    path2 = GEN_PATH + '/0'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set gen ct_addr: ' + str(ct_addr))

    # wpkh main address
    path = '{}/0/0'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['main'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set main addr: ' + str(addr))
    path2 = path + '/0'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set main ct_addr: ' + str(ct_addr))

    # pkh address
    path = '{}/0/1'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2pkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['p2pkh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('pkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set p2pkh addr: ' + str(addr))
    path2 = path + '/0'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set p2pkh ct_addr: ' + str(ct_addr))
    # wpkh address
    path = '{}/0/2'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['p2wpkh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set p2wpkh addr: ' + str(addr))
    path2 = path + '/0'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set p2wpkh ct_addr: ' + str(ct_addr))
    # p2sh-p2wpkh address
    path = '{}/0/3'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2sh_p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['p2sh-p2wpkh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('sh(wpkh({}))'.format(
        str(pk)),
                                                    network=NETWORK)
    print('set p2sh-p2wpkh addr: ' + str(addr))
    path2 = path + '/0'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set p2sh-p2wpkh ct_addr: ' + str(ct_addr))

    # multisig_key
    path = '{}/0/'.format(ROOT_PATH)
    path_list = [path + str(i + 1) for i in range(3)]
    pk1 = str(test_obj.hdwallet.get_pubkey(path=path_list[0]).pubkey)
    pk2 = str(test_obj.hdwallet.get_pubkey(path=path_list[1]).pubkey)
    pk3 = str(test_obj.hdwallet.get_pubkey(path=path_list[2]).pubkey)
    pk_list = [pk1, pk2, pk3]
    req_num = 2
    desc_multi = 'multi({},{},{},{})'.format(req_num, pk1, pk2, pk3)
    addr = AddressUtil.multisig(req_num,
                                pk_list,
                                HashType.P2SH,
                                network=NETWORK)
    test_obj.path_dic[str(addr)] = path_list
    test_obj.addr_dic['p2sh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor(
        'sh({})'.format(desc_multi), network=NETWORK)
    print('set p2sh addr: ' + str(addr))
    path2 = MULTISIG_CT_PATH_BASE + '1'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set p2sh ct_addr: ' + str(ct_addr))
    addr = AddressUtil.multisig(req_num,
                                pk_list,
                                HashType.P2WSH,
                                network=NETWORK)
    test_obj.path_dic[str(addr)] = path_list
    test_obj.addr_dic['p2wsh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor(
        'wsh({})'.format(desc_multi), network=NETWORK)
    print('set p2wsh addr: ' + str(addr))
    path2 = MULTISIG_CT_PATH_BASE + '2'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set p2wsh ct_addr: ' + str(ct_addr))
    addr = AddressUtil.multisig(req_num,
                                pk_list,
                                HashType.P2SH_P2WSH,
                                network=NETWORK)
    test_obj.path_dic[str(addr)] = path_list
    test_obj.addr_dic['p2sh-p2wsh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor(
        'sh(wsh({}))'.format(desc_multi), network=NETWORK)
    print('set p2sh-p2wsh addr: ' + str(addr))
    path2 = MULTISIG_CT_PATH_BASE + '3'
    sk = test_obj.hdwallet.get_privkey(path=path2).privkey
    test_obj.blind_key_dic[str(addr)] = sk
    ct_addr = ConfidentialAddress(addr, sk.pubkey)
    test_obj.ct_addr_dic[str(addr)] = ct_addr
    print('set p2sh-p2wsh ct_addr: ' + str(ct_addr))

    # master blinding key
    path = '{}/0/1001'.format(ROOT_PATH)
    sk = str(test_obj.hdwallet.get_privkey(path=path).privkey)
    test_obj.master_blinding_key = sk
    print('set master blinding key: ' + sk)
예제 #2
0
from cfd.script import HashType
from cfd.util import CfdError


def test_address_func(obj, name, case, req, exp, error):
    try:
        resp = None
        _network = req.get('network', 'mainnet')
        if req.get('isElements', False) and (_network.lower()
                                             == Network.REGTEST.as_str()):
            _network = Network.ELEMENTS_REGTEST

        if name == 'Address.Create':
            _hash_type = HashType.get(req['hashType'])
            if _hash_type == HashType.P2PKH:
                resp = AddressUtil.p2pkh(req['keyData']['hex'],
                                         network=_network)
            elif _hash_type == HashType.P2WPKH:
                resp = AddressUtil.p2wpkh(req['keyData']['hex'],
                                          network=_network)
            elif _hash_type == HashType.P2SH_P2WPKH:
                resp = AddressUtil.p2sh_p2wpkh(req['keyData']['hex'],
                                               network=_network)
            elif _hash_type == HashType.P2SH:
                resp = AddressUtil.p2sh(req['keyData']['hex'],
                                        network=_network)
            elif _hash_type == HashType.P2WSH:
                resp = AddressUtil.p2wsh(req['keyData']['hex'],
                                         network=_network)
            elif _hash_type == HashType.P2SH_P2WSH:
                resp = AddressUtil.p2sh_p2wsh(req['keyData']['hex'],
                                              network=_network)
예제 #3
0
def create_bitcoin_address(test_obj):
    # fee address
    pk = str(test_obj.hdwallet.get_pubkey(path=FEE_PATH).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = FEE_PATH
    test_obj.addr_dic['fee'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set fee addr: ' + str(addr))

    # wpkh main address
    path = '{}/0/0'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['main'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set main addr: ' + str(addr))
    # pkh address
    path = '{}/0/1'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2pkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['p2pkh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('pkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set p2pkh addr: ' + str(addr))
    # wpkh address
    path = '{}/0/2'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['p2wpkh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('wpkh({})'.format(str(pk)),
                                                    network=NETWORK)
    print('set p2wpkh addr: ' + str(addr))
    # p2sh-p2wpkh address
    path = '{}/0/3'.format(ROOT_PATH)
    pk = str(test_obj.hdwallet.get_pubkey(path=path).pubkey)
    addr = AddressUtil.p2sh_p2wpkh(pk, network=NETWORK)
    test_obj.path_dic[str(addr)] = path
    test_obj.addr_dic['p2sh-p2wpkh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor('sh(wpkh({}))'.format(
        str(pk)),
                                                    network=NETWORK)
    print('set p2sh-p2wpkh addr: ' + str(addr))

    # multisig_key
    path = '{}/0/'.format(ROOT_PATH)
    path_list = [path + str(i + 1) for i in range(3)]
    pk1 = str(test_obj.hdwallet.get_pubkey(path=path_list[0]).pubkey)
    pk2 = str(test_obj.hdwallet.get_pubkey(path=path_list[1]).pubkey)
    pk3 = str(test_obj.hdwallet.get_pubkey(path=path_list[2]).pubkey)
    pk_list = [pk1, pk2, pk3]
    req_num = 2
    desc_multi = 'multi({},{},{},{})'.format(req_num, pk1, pk2, pk3)
    addr = AddressUtil.multisig(req_num,
                                pk_list,
                                HashType.P2SH,
                                network=NETWORK)
    test_obj.path_dic[str(addr)] = path_list
    test_obj.addr_dic['p2sh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor(
        'sh({})'.format(desc_multi), network=NETWORK)
    print('set p2sh addr: ' + str(addr))
    addr = AddressUtil.multisig(req_num,
                                pk_list,
                                HashType.P2WSH,
                                network=NETWORK)
    test_obj.path_dic[str(addr)] = path_list
    test_obj.addr_dic['p2wsh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor(
        'wsh({})'.format(desc_multi), network=NETWORK)
    print('set p2wsh addr: ' + str(addr))
    addr = AddressUtil.multisig(req_num,
                                pk_list,
                                HashType.P2SH_P2WSH,
                                network=NETWORK)
    test_obj.path_dic[str(addr)] = path_list
    test_obj.addr_dic['p2sh-p2wsh'] = addr
    test_obj.desc_dic[str(addr)] = parse_descriptor(
        'sh(wsh({}))'.format(desc_multi), network=NETWORK)
    print('set p2sh-p2wsh addr: ' + str(addr))
예제 #4
0
from cfd.address import AddressUtil

PUBKEY = '027592aab5d43618dda13fba71e3993cd7517a712d3da49664c06ee1bd3d1f70af'
SCRIPT_PUBKEY = '76a914925d4028880bd0c9d68fbc7fc7dfee976698629c88ac'

if __name__ == '__main__':
    addr = AddressUtil.p2pkh(PUBKEY)
    if str(addr) != '1ELuNB5fLNUcrLzb93oJDPmjxjnsVwhNHn':
        print('invalid address: ' + str(addr))
    else:
        print('address: ' + str(addr))
    if str(addr.locking_script) != SCRIPT_PUBKEY:
        print('invalid script: ' + str(addr.locking_script))
    else:
        print('locking script: ' + str(addr.locking_script))