| 290 | } |
| 291 | |
| 292 | bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const { |
| 293 | assert(IsValid()); |
| 294 | assert(IsCompressed()); |
| 295 | std::vector<unsigned char, secure_allocator<unsigned char>> vout(64); |
| 296 | if ((nChild >> 31) == 0) { |
| 297 | CPubKey pubkey = GetPubKey(); |
| 298 | assert(pubkey.size() == CPubKey::COMPRESSED_SIZE); |
| 299 | BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data()); |
| 300 | } else { |
| 301 | assert(size() == 32); |
| 302 | BIP32Hash(cc, nChild, 0, UCharCast(begin()), vout.data()); |
| 303 | } |
| 304 | memcpy(ccChild.begin(), vout.data()+32, 32); |
| 305 | keyChild.Set(begin(), begin() + 32, true); |
| 306 | bool ret = secp256k1_ec_seckey_tweak_add(secp256k1_context_static, (unsigned char*)keyChild.begin(), vout.data()); |
| 307 | if (!ret) keyChild.ClearKeyData(); |
| 308 | return ret; |
| 309 | } |
| 310 | |
| 311 | EllSwiftPubKey CKey::EllSwiftCreate(std::span<const std::byte> ent32) const |
| 312 | { |