MCPcopy Create free account
hub / github.com/ElementsProject/elements / importblindingkey

Function importblindingkey

src/wallet/rpc/backup.cpp:2049–2101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2047}
2048
2049RPCHelpMan importblindingkey()
2050{
2051 return RPCHelpMan{"importblindingkey",
2052 "\nImports a private blinding key in hex for a CT address.",
2053 {
2054 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The CT address"},
2055 {"hexkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The blinding key in hex"},
2056 },
2057 RPCResult{RPCResult::Type::NONE, "", ""},
2058 RPCExamples{
2059 HelpExampleCli("importblindingkey", "\"my blinded CT address\" <blindinghex>")
2060 },
2061 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
2062{
2063 std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
2064 if (!wallet) return NullUniValue;
2065 CWallet* const pwallet = wallet.get();
2066
2067 LOCK(pwallet->cs_wallet);
2068
2069 CTxDestination dest = DecodeDestination(request.params[0].get_str());
2070 if (!IsValidDestination(dest)) {
2071 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address.");
2072 }
2073 if (!IsBlindDestination(dest)) {
2074 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Address is not confidential.");
2075 }
2076
2077 if (!IsHex(request.params[1].get_str())) {
2078 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal for key");
2079 }
2080 std::vector<unsigned char> keydata = ParseHex(request.params[1].get_str());
2081 if (keydata.size() != 32) {
2082 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal key length");
2083 }
2084
2085 CKey key;
2086 key.Set(keydata.begin(), keydata.end(), true);
2087 if (!key.IsValid() || key.GetPubKey() != GetDestinationBlindingKey(dest)) {
2088 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Address and key do not match");
2089 }
2090
2091 uint256 keyval;
2092 memcpy(keyval.begin(), &keydata[0], 32);
2093 if (!pwallet->AddSpecificBlindingKey(CScriptID(GetScriptForDestination(dest)), keyval)) {
2094 throw JSONRPCError(RPC_WALLET_ERROR, "Failed to import blinding key");
2095 }
2096 pwallet->MarkDirty();
2097
2098 return NullUniValue;
2099},
2100 };
2101}
2102
2103RPCHelpMan importmasterblindingkey()
2104{

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
DecodeDestinationFunction · 0.85
IsValidDestinationFunction · 0.85
JSONRPCErrorFunction · 0.85
IsBlindDestinationFunction · 0.85
IsHexFunction · 0.85
ParseHexFunction · 0.85
CScriptIDClass · 0.85
GetScriptForDestinationFunction · 0.85

Tested by

no test coverage detected