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

Method Derive

src/key.cpp:325–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

323}
324
325bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc, std::vector<unsigned char>* tweak) const {
326 assert(IsValid());
327 assert(IsCompressed());
328 std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
329 if ((nChild >> 31) == 0) {
330 CPubKey pubkey = GetPubKey();
331 assert(pubkey.size() == CPubKey::COMPRESSED_SIZE);
332 BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data());
333 } else {
334 assert(size() == 32);
335 BIP32Hash(cc, nChild, 0, begin(), vout.data());
336 }
337 if (tweak) {
338 tweak->clear();
339 *tweak = std::vector<unsigned char>(vout.data(), vout.data()+32);
340 }
341 memcpy(ccChild.begin(), vout.data()+32, 32);
342 memcpy((unsigned char*)keyChild.begin(), begin(), 32);
343 bool ret = secp256k1_ec_seckey_tweak_add(secp256k1_context_sign, (unsigned char*)keyChild.begin(), vout.data());
344 keyChild.fCompressed = true;
345 keyChild.fValid = ret;
346 return ret;
347}
348
349bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
350 out.nDepth = nDepth + 1;

Callers 8

DeriveNewChildKeyMethod · 0.45
DerivePubTweakFunction · 0.45
GetDerivedExtKeyMethod · 0.45
GetPubKeyMethod · 0.45
GetPrivKeyMethod · 0.45
RunTestFunction · 0.45
DoCheckFunction · 0.45
FUZZ_TARGET_INITFunction · 0.45

Calls 11

GetPubKeyFunction · 0.85
BIP32HashFunction · 0.85
beginFunction · 0.85
sizeFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
dataMethod · 0.45
clearMethod · 0.45
GetIDMethod · 0.45
GetPubKeyMethod · 0.45

Tested by 3

RunTestFunction · 0.36
DoCheckFunction · 0.36
FUZZ_TARGET_INITFunction · 0.36