| 266 | } |
| 267 | |
| 268 | bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const { |
| 269 | assert(IsValid()); |
| 270 | assert(IsCompressed()); |
| 271 | std::vector<unsigned char, secure_allocator<unsigned char>> vout(64); |
| 272 | if ((nChild >> 31) == 0) { |
| 273 | CPubKey pubkey = GetPubKey(); |
| 274 | assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE); |
| 275 | BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data()); |
| 276 | } else { |
| 277 | assert(size() == 32); |
| 278 | BIP32Hash(cc, nChild, 0, begin(), vout.data()); |
| 279 | } |
| 280 | memcpy(ccChild.begin(), vout.data()+32, 32); |
| 281 | memcpy((unsigned char*)keyChild.begin(), begin(), 32); |
| 282 | bool ret = secp256k1_ec_privkey_tweak_add(secp256k1_context_sign, (unsigned char*)keyChild.begin(), vout.data()); |
| 283 | keyChild.fCompressed = true; |
| 284 | keyChild.fValid = ret; |
| 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const { |
| 289 | out.nDepth = nDepth + 1; |