| 1042 | |
| 1043 | |
| 1044 | static RPCHelpMan createblindedaddress() |
| 1045 | { |
| 1046 | return RPCHelpMan{"createblindedaddress", |
| 1047 | "\nCreates a blinded address using the provided blinding key.\n", |
| 1048 | { |
| 1049 | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The unblinded address to be blinded."}, |
| 1050 | {"blinding_key", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The blinding public key. This can be obtained for a given address using `getaddressinfo` (`confidential_key` field)."}, |
| 1051 | }, |
| 1052 | RPCResult{ |
| 1053 | RPCResult::Type::STR, "blinded_address", "The blinded address" |
| 1054 | }, |
| 1055 | RPCExamples{ |
| 1056 | "\nCreate a blinded address\n" |
| 1057 | + HelpExampleCli("createblindedaddress", "HEZk3iQi1jC49bxUriTtynnXgWWWdAYx16 ec09811118b6febfa5ebe68642e5091c418fbace07e655da26b4a845a691fc2d") + |
| 1058 | "\nAs a json rpc call\n" |
| 1059 | + HelpExampleRpc("createblindedaddress", "HEZk3iQi1jC49bxUriTtynnXgWWWdAYx16, ec09811118b6febfa5ebe68642e5091c418fbace07e655da26b4a845a691fc2d") |
| 1060 | }, |
| 1061 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 1062 | { |
| 1063 | CTxDestination address = DecodeDestination(request.params[0].get_str()); |
| 1064 | if (!IsValidDestination(address)) { |
| 1065 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address or script"); |
| 1066 | } |
| 1067 | if (IsBlindDestination(address)) { |
| 1068 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Not an unblinded address"); |
| 1069 | } |
| 1070 | |
| 1071 | if (!IsHex(request.params[1].get_str())) { |
| 1072 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal for key"); |
| 1073 | } |
| 1074 | std::vector<unsigned char> keydata = ParseHex(request.params[1].get_str()); |
| 1075 | if (keydata.size() != 33) { |
| 1076 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal key length, must be length 66."); |
| 1077 | } |
| 1078 | |
| 1079 | CPubKey key; |
| 1080 | key.Set(keydata.begin(), keydata.end()); |
| 1081 | |
| 1082 | // Append blinding key and return |
| 1083 | std::visit(BlindingPubkeyAdderVisitor(key), address); |
| 1084 | return EncodeDestination(address); |
| 1085 | }, |
| 1086 | }; |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | // END ELEMENTS CALLS |
nothing calls this directly
no test coverage detected