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

Method Derive

src/pubkey.cpp:335–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc, std::vector<unsigned char>* tweak) const {
336 assert(IsValid());
337 assert((nChild >> 31) == 0);
338 assert(size() == COMPRESSED_SIZE);
339 unsigned char out[64];
340 BIP32Hash(cc, nChild, *begin(), begin()+1, out);
341 memcpy(ccChild.begin(), out+32, 32);
342 if (tweak) {
343 tweak->clear();
344 *tweak = std::vector<unsigned char>(out, out+32);
345 }
346 secp256k1_pubkey pubkey;
347 assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
348 if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size())) {
349 return false;
350 }
351 if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, out)) {
352 return false;
353 }
354 unsigned char pub[COMPRESSED_SIZE];
355 size_t publen = COMPRESSED_SIZE;
356 secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED);
357 pubkeyChild.Set(pub, pub + publen);
358 return true;
359}
360
361void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
362 code[0] = nDepth;

Callers

nothing calls this directly

Calls 10

BIP32HashFunction · 0.85
beginFunction · 0.85
sizeFunction · 0.70
beginMethod · 0.45
clearMethod · 0.45
SetMethod · 0.45
GetIDMethod · 0.45

Tested by

no test coverage detected