コード例 #1
0
# 1) Get unblinded addresses from each participant
addr1 = e1.getaddressinfo(e1.getnewaddress())["unconfidential"]
addr2 = e2.getaddressinfo(e2.getnewaddress())["unconfidential"]

# 2) Get blinding keys, private and public
addrinfo1 = e1.getaddressinfo(e1.getnewaddress())
addrinfo2 = e2.getaddressinfo(addr2)
blindingkey = e1.dumpblindingkey(addrinfo1["address"])
blindingpubkey = addrinfo1["confidential_key"]

# 3) Make multisig address like usual
multisig = e1.createmultisig(2, [addrinfo1["pubkey"], addrinfo2["pubkey"]])

print("4b. Blind the multisig address (using a blinding key from e1).")
# 4) Blind the address using the blinding pubkey
blinded_addr = e1.createblindedaddress(multisig["address"], blindingpubkey)
e1.importaddress(multisig["redeemScript"], "", True,
                 True)  # Make sure p2sh addr is added
e2.importaddress(multisig["redeemScript"], "", True, True)
e1.importaddress(blinded_addr)
e2.importaddress(blinded_addr)

# 5) Now the address can be funded, though e2 will not be able to see values
txid = e1.sendtoaddress(blinded_addr, 1)
sync_all([e1, e2])
assert e1.gettransaction(txid, True)['details'] != []
assert e2.gettransaction(txid, True)['details'] == []

print("4c. Share the blinding key with e2")
e2.importblindingkey(blinded_addr, blindingkey)
assert e1.gettransaction(txid, True)['details'] != []
コード例 #2
0
for out in outputs:
    blinder_idx = None
    if out["scriptPubKey"]["type"] == "fee":
        address = "fee"
    else:
        if out in decoded_a["vout"]:
            blinder_idx = alice_idx
        elif out in decoded_c["vout"]:
            blinder_idx = carol_idx

        # The crappy rawtransaction API requires that we reconstruct blinded addresses,
        # which are split between the "addresses" and "nonce" field
        address = out["scriptPubKey"]["addresses"][0]
        if "commitmentnonce" in out:
            address = alice.createblindedaddress(address, out["commitmentnonce"])

    if blinder_idx is None:
        outputs_createpsbt.append({address: out["value"], "asset": out["asset"]})
    else:
        outputs_createpsbt.append({address: out["value"], "asset": out["asset"], "blinder_index": blinder_idx})

alice_pset = alice.createpsbt(inputs_createpsbt, outputs_createpsbt)
carol_pset = alice.createpsbt(inputs_createpsbt, outputs_createpsbt)
assert alice_pset == carol_pset
print ("Created PSET: ", alice_pset)

# Use `analyzepsbt` to see what's happening
analysis = alice.analyzepsbt(alice_pset)
assert analysis["next"] == "updater"
assert not any([x["has_utxo"] for x in analysis["inputs"]])