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

Function DerivePubTweak

src/wallet/rpc/elements.cpp:229–256  ·  view source on GitHub ↗

Derive BIP32 tweak from master xpub to child pubkey.

Source from the content-addressed store, hash-verified

227
228//! Derive BIP32 tweak from master xpub to child pubkey.
229bool DerivePubTweak(const std::vector<uint32_t>& vPath, const CPubKey& keyMaster, const ChainCode &ccMaster, std::vector<unsigned char>& tweakSum)
230{
231 tweakSum.clear();
232 tweakSum.resize(32);
233 std::vector<unsigned char> tweak;
234 CPubKey keyParent = keyMaster;
235 CPubKey keyChild;
236 ChainCode ccChild;
237 ChainCode ccParent = ccMaster;
238 for (unsigned int i = 0; i < vPath.size(); i++) {
239 if ((vPath[i] >> 31) != 0) {
240 return false;
241 }
242 keyParent.Derive(keyChild, ccChild, vPath[i], ccParent, &tweak);
243 CHECK_NONFATAL(tweak.size() == 32);
244 ccParent = ccChild;
245 keyParent = keyChild;
246 if (i == 0) {
247 tweakSum = tweak;
248 } else {
249 bool ret = secp256k1_ec_seckey_tweak_add(secp256k1_ctx, tweakSum.data(), tweak.data());
250 if (!ret) {
251 return false;
252 }
253 }
254 }
255 return true;
256}
257
258// For general cryptographic design of peg-out authorization scheme, see: https://github.com/ElementsProject/secp256k1-zkp/blob/secp256k1-zkp/src/modules/whitelist/whitelist.md
259RPCHelpMan initpegoutwallet()

Callers 1

sendtomainchain_pakFunction · 0.85

Calls 6

clearMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
DeriveMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected