| 254 | } |
| 255 | |
| 256 | bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const { |
| 257 | assert(IsValid()); |
| 258 | assert(IsCompressed()); |
| 259 | std::vector<unsigned char, secure_allocator<unsigned char>> vout(64); |
| 260 | if ((nChild >> 31) == 0) { |
| 261 | CPubKey pubkey = GetPubKey(); |
| 262 | assert(pubkey.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE); |
| 263 | BIP32Hash(cc, nChild, *pubkey.begin(), pubkey.begin()+1, vout.data()); |
| 264 | } else { |
| 265 | assert(size() == 32); |
| 266 | BIP32Hash(cc, nChild, 0, begin(), vout.data()); |
| 267 | } |
| 268 | memcpy(ccChild.begin(), vout.data()+32, 32); |
| 269 | memcpy((unsigned char*)keyChild.begin(), begin(), 32); |
| 270 | bool ret = secp256k1_ec_privkey_tweak_add(secp256k1_context_sign, (unsigned char*)keyChild.begin(), vout.data()); |
| 271 | keyChild.fCompressed = true; |
| 272 | keyChild.fValid = ret; |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | bool CExtKey::Derive(CExtKey& out, unsigned int nChild) const { |
| 277 | out.nDepth = nDepth + 1; |
no test coverage detected