23typedef std::vector<unsigned char, secure_allocator<unsigned char> >
CPrivKey;
29using ECDHSecret = std::array<std::byte, ECDH_SECRET_SIZE>;
40 static const unsigned int SIZE = 279;
48 "COMPRESSED_SIZE is larger than SIZE");
52 using KeyType = std::array<unsigned char, 32>;
61 bool static Check(
const unsigned char* vch);
102 template <
typename T>
103 void Set(
const T pbegin,
const T pend,
bool fCompressedIn)
105 if (
size_t(pend - pbegin) != std::tuple_size_v<KeyType>) {
109 memcpy(
keydata->data(), (
unsigned char*)&pbegin[0],
keydata->size());
118 const std::byte*
data()
const {
return keydata ?
reinterpret_cast<const std::byte*
>(
keydata->data()) :
nullptr; }
147 bool Sign(
const uint256& hash, std::vector<unsigned char>& vchSig,
bool grind =
true, uint32_t test_case = 0)
const;
206 bool initiating)
const;
229 unsigned char vchFingerprint[4];
244 CExtKey(
const CExtPubKey& xpub,
const CKey& key_in) : nDepth(xpub.nDepth), nChild(xpub.nChild), chaincode(xpub.chaincode), key(key_in)
251 [[nodiscard]]
bool Derive(
CExtKey&
out,
unsigned int nChild)
const;
275 if (
this != &other) {
276 if (other.m_keypair) {
297 using KeyType = std::array<unsigned char, 96>;
An encapsulated private key.
bool SignSchnorr(const uint256 &hash, Span< unsigned char > sig, const uint256 *merkle_root, const uint256 &aux) const
Create a BIP-340 Schnorr signature, for the xonly-pubkey corresponding to *this, optionally tweaked b...
KeyPair ComputeKeyPair(const uint256 *merkle_root) const
Compute a KeyPair.
static const unsigned int SIZE
secp256k1:
friend bool operator==(const CKey &a, const CKey &b)
unsigned int size() const
Simple read-only vector-like interface.
bool IsValid() const
Check whether this private key is valid.
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized signature.
const std::byte * begin() const
ECDHSecret ComputeBIP324ECDHSecret(const EllSwiftPubKey &their_ellswift, const EllSwiftPubKey &our_ellswift, bool initiating) const
Compute a BIP324-style ECDH shared secret.
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized OpenSSL private key data).
static const unsigned int COMPRESSED_SIZE
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
bool fCompressed
Whether the public key corresponding to this private key is (to be) compressed.
CPubKey GetPubKey() const
Compute the public key from a private key.
const std::byte * end() const
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
bool VerifyPubKey(const CPubKey &vchPubKey) const
Verify thoroughly whether a private key and a public key match.
EllSwiftPubKey EllSwiftCreate(Span< const std::byte > entropy) const
Create an ellswift-encoded public key for this key, with specified entropy.
bool Load(const CPrivKey &privkey, const CPubKey &vchPubKey, bool fSkipCheck)
Load private key and check that public key matches.
static bool Check(const unsigned char *vch)
Check whether the 32-byte array pointed to by vch is valid keydata.
std::array< unsigned char, 32 > KeyType
see www.keylength.com script supports up to 75 for single byte push
bool Derive(CKey &keyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child key.
secure_unique_ptr< KeyType > keydata
The actual byte data. nullptr for invalid keys.
bool SignCompact(const uint256 &hash, std::vector< unsigned char > &vchSig) const
Create a compact signature (65 bytes), which allows reconstructing the used public key.
const std::byte * data() const
An encapsulated public key.
static const size_t OUTPUT_SIZE
RAII class initializing and deinitializing global state for elliptic curve support.
KeyPair() noexcept=default
std::array< unsigned char, 96 > KeyType
bool IsValid() const
Check whether this keypair is valid.
bool SignSchnorr(const uint256 &hash, Span< unsigned char > sig, const uint256 &aux) const
secure_unique_ptr< KeyType > m_keypair
KeyPair(const KeyPair &other)
A Span is an object that can refer to a contiguous sequence of objects.
std::vector< unsigned char, secure_allocator< unsigned char > > CPrivKey
CPrivKey is a serialized private key, with all parameters included (SIZE bytes)
static constexpr size_t ECDH_SECRET_SIZE
Size of ECDH shared secrets.
std::array< std::byte, ECDH_SECRET_SIZE > ECDHSecret
bool ECC_InitSanityCheck()
Check that required EC support is available at runtime.
CKey GenerateRandomKey(bool compressed=true) noexcept
DecodeResult Decode(const std::string &str, CharLimit limit)
Decode a Bech32 or Bech32m string.
std::string Encode(Encoding encoding, const std::string &hrp, const data &values)
Encode a Bech32 or Bech32m string.
const unsigned int BIP32_EXTKEY_SIZE
std::unique_ptr< T, SecureUniqueDeleter< T > > secure_unique_ptr
unsigned char * UCharCast(char *c)
unsigned char vchFingerprint[4]
CExtKey(const CExtPubKey &xpub, const CKey &key_in)
friend bool operator==(const CExtKey &a, const CExtKey &b)
unsigned char vchFingerprint[4]
An ElligatorSwift-encoded public key.