| 333 | } |
| 334 | |
| 335 | bool 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 | |
| 361 | void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const { |
| 362 | code[0] = nDepth; |
nothing calls this directly
no test coverage detected