Repository: bitcoin/bitcoin
File: src/key.h (C/C++)

Code before:
     *  know the private key (because the private key itself is always used as entropy as well).
     */
    EllSwiftPubKey EllSwiftCreate(Span<const std::byte> entropy) const;

    /** Compute a BIP324-style ECDH shared secret.
     *
     *  - their_ellswift: EllSwiftPubKey that was received from the other side.
     *  - our_ellswift: EllSwiftPubKey that was sent to the other side (must have been generated
     *                  from *this using EllSwiftCreate()).
     *  - initiating: whether we are the initiating party (true) or responding party (false).
     */
    ECDHSecret ComputeBIP324ECDHSecret(const EllSwiftPubKey& their_ellswift,
                                       const EllSwiftPubKey& our_ellswift,
                                       bool initiating) const;
    /** Compute a KeyPair
     *
     *  Wraps a `secp256k1_keypair` type.
     *
     *  `merkle_root` is used to optionally perform tweaking of
     *  the internal key, as specified in BIP341:
     *
     *  - If merkle_root == nullptr: no tweaking is done, use the internal key directly (this is
     *                               used for signatures in BIP342 script).
     *  - If merkle_root->IsNull():  tweak the internal key with H_TapTweak(pubkey) (this is used for
     *                               key path spending when no scripts are present).
     *  - Otherwise:                 tweak the internal key H_TapTweak(pubkey || *merkle_root)
     *                               (this is used for key path spending, with specific
     *                               Merkle root of the script tree).
     */
    KeyPair ComputeKeyPair(const uint256* merkle_root) const;
};

CKey GenerateRandomKey(bool compressed = true) noexcept;

struct CExtKey {
    unsigned char nDepth;
    unsigned char vchFingerprint[4];
    unsigned int nChild;
    ChainCode chaincode;
    CKey key;

    friend bool operator==(const CExtKey& a, const CExtKey& b)
    {
        return a.nDepth == b.nDepth &&
            memcmp(a.vchFingerprint, b.vchFingerprint, sizeof(vchFingerprint)) == 0 &&
            a.nChild == b.nChild &&
            a.chaincode == b.chaincode &&
            a.key == b.key;
    }

    CExtKey() = default;

Review comment (suggestion):
```suggestion
     *  - Otherwise:                 tweak the internal key with H_TapTweak(pubkey || *merkle_root)
```

Code after:
     *  know the private key (because the private key itself is always used as entropy as well).
     */
    EllSwiftPubKey EllSwiftCreate(Span<const std::byte> entropy) const;

    /** Compute a BIP324-style ECDH shared secret.
     *
     *  - their_ellswift: EllSwiftPubKey that was received from the other side.
     *  - our_ellswift: EllSwiftPubKey that was sent to the other side (must have been generated
     *                  from *this using EllSwiftCreate()).
     *  - initiating: whether we are the initiating party (true) or responding party (false).
     */
    ECDHSecret ComputeBIP324ECDHSecret(const EllSwiftPubKey& their_ellswift,
                                       const EllSwiftPubKey& our_ellswift,
                                       bool initiating) const;
    /** Compute a KeyPair
     *
     *  Wraps a `secp256k1_keypair` type.
     *
     *  `merkle_root` is used to optionally perform tweaking of
     *  the internal key, as specified in BIP341:
     *
     *  - If merkle_root == nullptr: no tweaking is done, use the internal key directly (this is
     *                               used for signatures in BIP342 script).
     *  - If merkle_root->IsNull():  tweak the internal key with H_TapTweak(pubkey) (this is used for
     *                               key path spending when no scripts are present).
     *  - Otherwise:                 tweak the internal key with H_TapTweak(pubkey || *merkle_root)
     *                               (this is used for key path spending with the
     *                               Merkle root of the script tree).
     */
    KeyPair ComputeKeyPair(const uint256* merkle_root) const;
};

CKey GenerateRandomKey(bool compressed = true) noexcept;

struct CExtKey {
    unsigned char nDepth;
    unsigned char vchFingerprint[4];
    unsigned int nChild;
    ChainCode chaincode;
    CKey key;

    friend bool operator==(const CExtKey& a, const CExtKey& b)
    {
        return a.nDepth == b.nDepth &&
            memcmp(a.vchFingerprint, b.vchFingerprint, sizeof(vchFingerprint)) == 0 &&
            a.nChild == b.nChild &&
            a.chaincode == b.chaincode &&
            a.key == b.key;
    }

    CExtKey() = default;