I'm trying to find the private key related to a specific CScript scriptPubKey, which belongs to the wallet and is of type TxoutType::WITNESS_V1_TAPROOT.
So I was getting the key through DescriptorScriptPubKeyMan::GetSigningProvider(&script, true) and it looks like the returned key failed to recreate the scriptPubKey that was looked for.
So I created the test below in the DescriptorScriptPubKeyMan and it looks like scriptPubKey created from the returned CKey is different from the one passed as parameter to GetSigningProvider(), as shown below.
I don't think this is a error or a bug. Maybe I'm using a function differently than expected, but I thought it best to report it anyway.
for (auto const& [scriptPubKey, index] : m_map_script_pub_keys)
{
std::vector<std::vector<unsigned char>> solutions;
TxoutType whichType = Solver(scriptPubKey, solutions);
// Confirm the scriptPubKey is WITNESS_V1_TAPROOT
if (whichType != TxoutType::WITNESS_V1_TAPROOT) {
return false;
}
std::unique_ptr<FlatSigningProvider> coin_keys = GetSigningProvider(scriptPubKey, true);
if (!coin_keys || coin_keys->keys.size() != 1) {
return false;
}
auto& key = coin_keys->keys.begin()->second;
XOnlyPubKey pubkey = XOnlyPubKey(key.GetPubKey());
auto destScriptPubKey = GetScriptForDestination(WitnessV1Taproot(pubkey));
CTxDestination address;
ExtractDestination(destScriptPubKey, address);
CTxDestination address2;
ExtractDestination(scriptPubKey, address2);
std::cout << "---> " << index << std::endl;
std::cout << "---> address from PrivKey : " << EncodeDestination(address) << std::endl;
std::cout << "---> address from m_map_script_pub_keys: " << EncodeDestination(address2) << std::endl;
}
results:
....
---> 827
---> address from PrivKey : bcrt1pzrm0jd2k3xlht7qxly4frzmkcsl88tu36vh6qy6glqfsmy7pehqsljyf9g
---> address from m_map_script_pub_keys: bcrt1plmy7d5h7unq0w9e9crqmqmztnz29pnmz8j6jaw7hpm4fqt0wv59q0q4zlq
---> 524
---> address from PrivKey : bcrt1pf3pxl3443umsux2345yddhgwtm2lyj5wnvg5cd00qj03ehs4ftxs5v3362
---> address from m_map_script_pub_keys: bcrt1plmv07yph7cpdylv74vxk8mqhmplrv9hucgsztggmyc00t5dz677sue0wcc
---> 668
---> address from PrivKey : bcrt1p9jjeh99gcre5xvk7ap6slvmg42fcyzkakdqmyw0y3wmfe76jm0xsq68z9r
---> address from m_map_script_pub_keys: bcrt1playljc8rhyjm0d572r405tfj3g3nfxawuqerzcke6l00f0nfmy3qgrdx86
---> 196
---> address from PrivKey : bcrt1paxnn7ve979qrxmujvy2t5gktu8tk8ynpq47ad2pr9g50s8lu30lqdl4z78
---> address from m_map_script_pub_keys: bcrt1pla0z8qefr0ngu7t2hx08l49j64whh60yjm6edkel5y9dln3uzxls0w2tlh