Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251KeyFingerprint id_key_fingerprint() const252{253return key.GetPubKey().GetID().fingerprint();254}256void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const;257void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);258[[nodiscard]] bool Derive(CExtKey& out, unsigned int nChild) const;259CExtPubKey Neuter() const;260void SetSeed(std::span<const std::byte> seed);261};263//! Get extended key and origin info for a given path264//! @param[in] ext_key The extended private key to derive from265//! @param[in] path The BIP 32 path266//! @return the resulting extended private key and origin info267std::optional<std::pair<CExtKey, KeyOriginInfo>> DeriveExtKey(const CExtKey& ext_key, const std::vector<uint32_t>& path);269/** KeyPair270*271* Wraps a `secp256k1_keypair` type, an opaque data structure for holding a secret and public key.272* This is intended for BIP340 keys and allows us to easily determine if the secret key needs to273* be negated by checking the parity of the public key. This class primarily intended for passing274* secret keys to libsecp256k1 functions expecting a `secp256k1_keypair`. For all other cases,275* CKey should be preferred.276*277* A KeyPair can be created from a CKey with an optional merkle_root tweak (per BIP342). See278* CKey::ComputeKeyPair for more details.279*/280class KeyPair281{282public:283KeyPair() noexcept = default;284KeyPair(KeyPair&&) noexcept = default;285KeyPair& operator=(KeyPair&&) noexcept = default;286KeyPair& operator=(const KeyPair& other)287{288if (this != &other) {289if (other.m_keypair) {290MakeKeyPairData();291*m_keypair = *other.m_keypair;292} else {293ClearKeyPairData();294}295}296return *this;297}299KeyPair(const KeyPair& other) { *this = other; }301friend KeyPair CKey::ComputeKeyPair(const uint256* merkle_root) const;302[[nodiscard]] bool SignSchnorr(const uint256& hash, std::span<unsigned char> sig, const uint256& aux) const;304//! Check whether this keypair is valid.305bool IsValid() const { return !!m_keypair; }307private:308KeyPair(const CKey& key, const uint256* merkle_root);310using KeyType = std::array<unsigned char, 96>;311secure_unique_ptr<KeyType> m_keypair;313void MakeKeyPairData()314{315if (!m_keypair) m_keypair = make_secure_unique<KeyType>();316}318void ClearKeyPairData()319{320m_keypair.reset();321}322};324/** Check that required EC support is available at runtime. */325bool ECC_InitSanityCheck();327/** Access the secp256k1 context used for signing and MuSig2 nonce generation. */328secp256k1_context* GetSecp256k1SignContext();330/**331* RAII class initializing and deinitializing global state for elliptic curve support.332* Only one instance may be initialized at a time.333*334* In the future global ECC state could be removed, and this class could contain335* state and be passed as an argument to ECC key functions.336*/337class ECC_Context338{339public:340ECC_Context();341~ECC_Context();342};344#endif // BITCOIN_KEY_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.