Skip to content

Commit

Permalink
Merge pull request #173 from instagibbs/updatecreateblind
Browse files Browse the repository at this point in the history
have createblindedaddress use blinding pubkey instead
  • Loading branch information
instagibbs committed Jun 16, 2017
2 parents ebf836d + 6db18a1 commit f8d9b8d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
31 changes: 29 additions & 2 deletions qa/rpc-tests/confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ def run_test(self):
# Check createblindedaddress functionality
blinded_addr = self.nodes[0].getnewaddress()
validated_addr = self.nodes[0].validateaddress(blinded_addr)
blinding_pubkey = self.nodes[0].validateaddress(blinded_addr)["confidential_key"]
blinding_key = self.nodes[0].dumpblindingkey(blinded_addr)
assert_equal(blinded_addr, self.nodes[1].createblindedaddress(validated_addr["unconfidential"], blinding_key))
assert_equal(blinded_addr, self.nodes[1].createblindedaddress(validated_addr["unconfidential"], blinding_pubkey))

# If a blinding key is over-ridden by a newly imported one, funds may be unaccounted for
new_addr = self.nodes[0].getnewaddress()
new_validated = self.nodes[0].validateaddress(new_addr)
self.nodes[2].sendtoaddress(new_addr, 1)
diff_blind = self.nodes[1].createblindedaddress(new_validated["unconfidential"], blinding_key)
self.sync_all()
diff_blind = self.nodes[1].createblindedaddress(new_validated["unconfidential"], blinding_pubkey)
assert_equal(len(self.nodes[0].listunspent(0, 0, [new_validated["unconfidential"]])), 1)
self.nodes[0].importblindingkey(diff_blind, blinding_key)
# CT values for this wallet transaction have been cached via importblindingkey
Expand Down Expand Up @@ -364,5 +365,31 @@ def run_test(self):
assert_equal(self.nodes[0].getwalletinfo()["balance"][issued["token"]], 1)


# Check blinded multisig functionality
# Get two pubkeys
blinded_addr = self.nodes[0].getnewaddress()
pubkey = self.nodes[0].validateaddress(blinded_addr)["pubkey"]
blinded_addr2 = self.nodes[1].getnewaddress()
pubkey2 = self.nodes[1].validateaddress(blinded_addr2)["pubkey"]
pubkeys = [pubkey, pubkey2]
# Add multisig address
unconfidential_addr = self.nodes[0].addmultisigaddress(2, pubkeys)
self.nodes[1].addmultisigaddress(2, pubkeys)
self.nodes[0].importaddress(unconfidential_addr)
self.nodes[1].importaddress(unconfidential_addr)
# Use blinding key from node 0's original getnewaddress call
blinding_pubkey = self.nodes[0].validateaddress(blinded_addr)["confidential_key"]
blinding_key = self.nodes[0].dumpblindingkey(blinded_addr)
# Create blinded address from p2sh address and import corresponding privkey
blinded_multisig_addr = self.nodes[0].createblindedaddress(unconfidential_addr, blinding_pubkey)
self.nodes[0].importblindingkey(blinded_multisig_addr, blinding_key)
self.nodes[1].importblindingkey(blinded_multisig_addr, blinding_key)
# Send coins to blinded multisig address and check that they were received
self.nodes[2].sendtoaddress(blinded_multisig_addr, 1)
self.sync_all()
assert_equal(len(self.nodes[0].listunspent(0, 0, [unconfidential_addr])), 1)
assert_equal(len(self.nodes[1].listunspent(0, 0, [unconfidential_addr])), 1)


if __name__ == '__main__':
CTTest ().main ()
12 changes: 6 additions & 6 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ UniValue createblindedaddress(const UniValue& params, bool fHelp)
"\nCreates a blinded address using the provided blinding key.\n"
"\nArguments:\n"
"1. \"address\" (string, required) The unblinded address to be blinded.\n"
"2. \"key\" (string, required) The blinding private key.\n"
"2. \"key\" (string, required) The blinding public key. This can be obtained for a given address using `validateaddress`.\n"
"\nResult:\n"
"\"blinded_address\" (string) The blinded address.\n"
"\nExamples:\n"
Expand All @@ -386,14 +386,14 @@ UniValue createblindedaddress(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal for key");
}
std::vector<unsigned char> keydata = ParseHex(params[1].get_str());
if (keydata.size() != 32) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal key length, must be 32 bytes long.");
if (keydata.size() != 33) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal key length, must be length 66.");
}

CKey key;
key.Set(keydata.begin(), keydata.end(), true);
CPubKey key;
key.Set(keydata.begin(), keydata.end());

return address.AddBlindingKey(key.GetPubKey()).ToString();
return address.AddBlindingKey(key).ToString();
}

UniValue verifymessage(const UniValue& params, bool fHelp)
Expand Down

0 comments on commit f8d9b8d

Please sign in to comment.