mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
refactor: Update XOnlyPubKey::GetKeyIDs() to return a pair of pubkeys
This commit is contained in:
parent
9a4c92eb9a
commit
4041cbf3c6
2 changed files with 13 additions and 10 deletions
|
@ -197,21 +197,24 @@ constexpr XOnlyPubKey XOnlyPubKey::NUMS_H{
|
|||
[]() consteval { return XOnlyPubKey{"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"_hex_u8}; }(),
|
||||
};
|
||||
|
||||
std::vector<CKeyID> XOnlyPubKey::GetKeyIDs() const
|
||||
std::array<CKeyID,2> XOnlyPubKey::GetKeyIDs() const
|
||||
{
|
||||
std::vector<CKeyID> out;
|
||||
// For now, use the old full pubkey-based key derivation logic. As it is indexed by
|
||||
// Hash160(full pubkey), we need to return both a version prefixed with 0x02, and one
|
||||
// with 0x03.
|
||||
unsigned char b[33] = {0x02};
|
||||
std::copy(m_keydata.begin(), m_keydata.end(), b + 1);
|
||||
CPubKey fullpubkey;
|
||||
fullpubkey.Set(b, b + 33);
|
||||
out.push_back(fullpubkey.GetID());
|
||||
|
||||
CPubKey full_pubkey;
|
||||
full_pubkey.Set(b, b + 33);
|
||||
CKeyID id_even_pubkey{full_pubkey.GetID()};
|
||||
|
||||
b[0] = 0x03;
|
||||
fullpubkey.Set(b, b + 33);
|
||||
out.push_back(fullpubkey.GetID());
|
||||
return out;
|
||||
full_pubkey.Set(b, b + 33);
|
||||
CKeyID id_odd_pubKey{full_pubkey.GetID()};
|
||||
|
||||
// Return [0] = even-Y, [1] = odd-Y
|
||||
return std::array<CKeyID,2>{ id_even_pubkey, id_odd_pubKey };
|
||||
}
|
||||
|
||||
CPubKey XOnlyPubKey::GetEvenCorrespondingCPubKey() const
|
||||
|
|
|
@ -282,10 +282,10 @@ public:
|
|||
/** Construct a Taproot tweaked output point with this point as internal key. */
|
||||
std::optional<std::pair<XOnlyPubKey, bool>> CreateTapTweak(const uint256* merkle_root) const;
|
||||
|
||||
/** Returns a list of CKeyIDs for the CPubKeys that could have been used to create this XOnlyPubKey.
|
||||
/** Returns two CKeyIDs for the CPubKeys that could have been used to create this XOnlyPubKey.
|
||||
* This is needed for key lookups since keys are indexed by CKeyID.
|
||||
*/
|
||||
std::vector<CKeyID> GetKeyIDs() const;
|
||||
std::array<CKeyID,2> GetKeyIDs() const;
|
||||
|
||||
CPubKey GetEvenCorrespondingCPubKey() const;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue