Derive BIP32 tweak from master xpub to child pubkey.
| 227 | |
| 228 | //! Derive BIP32 tweak from master xpub to child pubkey. |
| 229 | bool DerivePubTweak(const std::vector<uint32_t>& vPath, const CPubKey& keyMaster, const ChainCode &ccMaster, std::vector<unsigned char>& tweakSum) |
| 230 | { |
| 231 | tweakSum.clear(); |
| 232 | tweakSum.resize(32); |
| 233 | std::vector<unsigned char> tweak; |
| 234 | CPubKey keyParent = keyMaster; |
| 235 | CPubKey keyChild; |
| 236 | ChainCode ccChild; |
| 237 | ChainCode ccParent = ccMaster; |
| 238 | for (unsigned int i = 0; i < vPath.size(); i++) { |
| 239 | if ((vPath[i] >> 31) != 0) { |
| 240 | return false; |
| 241 | } |
| 242 | keyParent.Derive(keyChild, ccChild, vPath[i], ccParent, &tweak); |
| 243 | CHECK_NONFATAL(tweak.size() == 32); |
| 244 | ccParent = ccChild; |
| 245 | keyParent = keyChild; |
| 246 | if (i == 0) { |
| 247 | tweakSum = tweak; |
| 248 | } else { |
| 249 | bool ret = secp256k1_ec_seckey_tweak_add(secp256k1_ctx, tweakSum.data(), tweak.data()); |
| 250 | if (!ret) { |
| 251 | return false; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | return true; |
| 256 | } |
| 257 | |
| 258 | // For general cryptographic design of peg-out authorization scheme, see: https://github.com/ElementsProject/secp256k1-zkp/blob/secp256k1-zkp/src/modules/whitelist/whitelist.md |
| 259 | RPCHelpMan initpegoutwallet() |
no test coverage detected