| 251 | } |
| 252 | |
| 253 | bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const |
| 254 | { |
| 255 | assert(IsValid()); |
| 256 | assert((nChild >> 31) == 0); |
| 257 | assert(size() == COMPRESSED_PUBLIC_KEY_SIZE); |
| 258 | unsigned char out[64]; |
| 259 | BIP32Hash(cc, nChild, *begin(), begin() + 1, out); |
| 260 | memcpy(ccChild.begin(), out + 32, 32); |
| 261 | secp256k1_pubkey pubkey; |
| 262 | if (!secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, &(*this)[0], size())) { |
| 263 | return false; |
| 264 | } |
| 265 | if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_verify, &pubkey, out)) { |
| 266 | return false; |
| 267 | } |
| 268 | unsigned char pub[COMPRESSED_PUBLIC_KEY_SIZE]; |
| 269 | size_t publen = COMPRESSED_PUBLIC_KEY_SIZE; |
| 270 | secp256k1_ec_pubkey_serialize(secp256k1_context_verify, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED); |
| 271 | pubkeyChild.Set(pub, pub + publen); |
| 272 | return true; |
| 273 | } |
| 274 | |
| 275 | void CExtPubKey::Encode(unsigned char code[74]) const |
| 276 | { |
nothing calls this directly
no test coverage detected