mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
pubkey: introduce a GetEvenCorrespondingCPubKey helper
We'll need to get a compressed key out of an x-only one in other places. Avoid duplicating the code.
This commit is contained in:
parent
ce8845f5dd
commit
fcb6f13f44
3 changed files with 10 additions and 3 deletions
|
@ -204,6 +204,13 @@ std::vector<CKeyID> XOnlyPubKey::GetKeyIDs() const
|
|||
return out;
|
||||
}
|
||||
|
||||
CPubKey XOnlyPubKey::GetEvenCorrespondingCPubKey() const
|
||||
{
|
||||
unsigned char full_key[CPubKey::COMPRESSED_SIZE] = {0x02};
|
||||
std::copy(begin(), end(), full_key + 1);
|
||||
return CPubKey{full_key};
|
||||
}
|
||||
|
||||
bool XOnlyPubKey::IsFullyValid() const
|
||||
{
|
||||
secp256k1_xonly_pubkey pubkey;
|
||||
|
|
|
@ -282,6 +282,8 @@ public:
|
|||
*/
|
||||
std::vector<CKeyID> GetKeyIDs() const;
|
||||
|
||||
CPubKey GetEvenCorrespondingCPubKey() const;
|
||||
|
||||
const unsigned char& operator[](int pos) const { return *(m_keydata.begin() + pos); }
|
||||
const unsigned char* data() const { return m_keydata.begin(); }
|
||||
static constexpr size_t size() { return decltype(m_keydata)::size(); }
|
||||
|
|
|
@ -1401,9 +1401,7 @@ std::unique_ptr<PubkeyProvider> InferPubkey(const CPubKey& pubkey, ParseScriptCo
|
|||
|
||||
std::unique_ptr<PubkeyProvider> InferXOnlyPubkey(const XOnlyPubKey& xkey, ParseScriptContext ctx, const SigningProvider& provider)
|
||||
{
|
||||
unsigned char full_key[CPubKey::COMPRESSED_SIZE] = {0x02};
|
||||
std::copy(xkey.begin(), xkey.end(), full_key + 1);
|
||||
CPubKey pubkey(full_key);
|
||||
CPubKey pubkey{xkey.GetEvenCorrespondingCPubKey()};
|
||||
std::unique_ptr<PubkeyProvider> key_provider = std::make_unique<ConstPubkeyProvider>(0, pubkey, true);
|
||||
KeyOriginInfo info;
|
||||
if (provider.GetKeyOriginByXOnly(xkey, info)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue