aboutsummaryrefslogtreecommitdiff
path: root/src/pubkey.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter@wuille.net>2023-04-17 14:25:41 -0400
committerPieter Wuille <pieter@wuille.net>2023-06-23 14:22:33 -0400
commiteff72a0dff8fa83af873ad9b15dbac50b8d4eca3 (patch)
tree65c1e1f011f3817350c84d4f30a9fdfa57ea6a71 /src/pubkey.cpp
parent42239f839081bba9a426ebb9f1b7a56e35a2d428 (diff)
downloadbitcoin-eff72a0dff8fa83af873ad9b15dbac50b8d4eca3.tar.xz
Add ElligatorSwift key creation and ECDH logic
Co-authored-by: Dhruv Mehta <856960+dhruv@users.noreply.github.com>
Diffstat (limited to 'src/pubkey.cpp')
-rw-r--r--src/pubkey.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/pubkey.cpp b/src/pubkey.cpp
index ae5dccfb5a..4866feed67 100644
--- a/src/pubkey.cpp
+++ b/src/pubkey.cpp
@@ -7,6 +7,7 @@
#include <hash.h>
#include <secp256k1.h>
+#include <secp256k1_ellswift.h>
#include <secp256k1_extrakeys.h>
#include <secp256k1_recovery.h>
#include <secp256k1_schnorrsig.h>
@@ -335,6 +336,20 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
return true;
}
+CPubKey EllSwiftPubKey::Decode() const
+{
+ secp256k1_pubkey pubkey;
+ secp256k1_ellswift_decode(secp256k1_context_static, &pubkey, UCharCast(m_pubkey.data()));
+
+ size_t sz = CPubKey::COMPRESSED_SIZE;
+ std::array<uint8_t, CPubKey::COMPRESSED_SIZE> vch_bytes;
+
+ secp256k1_ec_pubkey_serialize(secp256k1_context_static, vch_bytes.data(), &sz, &pubkey, SECP256K1_EC_COMPRESSED);
+ assert(sz == vch_bytes.size());
+
+ return CPubKey{vch_bytes.begin(), vch_bytes.end()};
+}
+
void CExtPubKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
code[0] = nDepth;
memcpy(code+1, vchFingerprint, 4);