| 339 | } |
| 340 | |
| 341 | bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc, uint256* bip32_tweak_out) const { |
| 342 | assert(IsValid()); |
| 343 | assert((nChild >> 31) == 0); |
| 344 | assert(size() == COMPRESSED_SIZE); |
| 345 | unsigned char out[64]; |
| 346 | BIP32Hash(cc, nChild, *begin(), begin()+1, out); |
| 347 | memcpy(ccChild.begin(), out+32, 32); |
| 348 | if (bip32_tweak_out) { |
| 349 | memcpy(bip32_tweak_out->begin(), out, 32); |
| 350 | } |
| 351 | secp256k1_pubkey pubkey; |
| 352 | if (!secp256k1_ec_pubkey_parse(secp256k1_context_static, &pubkey, vch, size())) { |
| 353 | return false; |
| 354 | } |
| 355 | if (!secp256k1_ec_pubkey_tweak_add(secp256k1_context_static, &pubkey, out)) { |
| 356 | return false; |
| 357 | } |
| 358 | unsigned char pub[COMPRESSED_SIZE]; |
| 359 | size_t publen = COMPRESSED_SIZE; |
| 360 | secp256k1_ec_pubkey_serialize(secp256k1_context_static, pub, &publen, &pubkey, SECP256K1_EC_COMPRESSED); |
| 361 | pubkeyChild.Set(pub, pub + publen); |
| 362 | return true; |
| 363 | } |
| 364 | |
| 365 | EllSwiftPubKey::EllSwiftPubKey(std::span<const std::byte> ellswift) noexcept |
| 366 | { |
nothing calls this directly
no test coverage detected