18#include "../detail/common.hpp"
25Result<bool> nonce_proof_matches_nonce(
const NonceProof& nonce_proof,
purify_secp_context* secp_context) {
29 "nonce_proof_matches_nonce:secp_context");
34 return xonly == nonce_proof.nonce.xonly;
43 out.insert(out.end(), packed.begin(), packed.end());
58 std::copy(serialized.begin() + 64, serialized.end(), out.bip340_pubkey.begin());
60 "PublicKey::deserialize:secp_context");
77 std::copy(serialized.begin(), serialized.end(), out.xonly.begin());
79 "Nonce::deserialize:secp_context");
88 std::copy(
bytes.begin(),
bytes.begin() + 32, out.xonly.begin());
94 std::copy(
bytes.begin() + 32,
bytes.end(), out.begin());
108 std::copy(serialized.begin(), serialized.end(), out.bytes.begin());
110 "Signature::deserialize:secp_context");
119 "NonceProof::serialize:nonce_proof_matches_nonce");
124 if (proof_bytes.size() >
static_cast<std::size_t
>(std::numeric_limits<std::uint32_t>::max())) {
127 std::size_t serialized_size = 0;
133 out.reserve(serialized_size);
134 out.push_back(
static_cast<unsigned char>(2));
137 out.insert(out.end(), proof_bytes.begin(), proof_bytes.end());
143 if (serialized.size() < 37) {
146 if (serialized[0] != 2) {
150 assert(proof_size.has_value() &&
"header length check should guarantee a u32 proof size");
151 if (*proof_size != serialized.size() - 37) {
156 std::copy_n(serialized.begin() + 5, 32, out.nonce.xonly.begin());
159 "NonceProof::deserialize:proof");
160 out.proof = std::move(proof_value);
162 "NonceProof::deserialize:nonce_proof_matches_nonce");
171 "ProvenSignature::serialize:nonce_proof");
172 if (nonce_proof_bytes.size() >
static_cast<std::size_t
>(std::numeric_limits<std::uint32_t>::max())) {
175 std::size_t serialized_size = 0;
181 out.reserve(serialized_size);
182 out.push_back(
static_cast<unsigned char>(1));
184 out.insert(out.end(), nonce_proof_bytes.begin(), nonce_proof_bytes.end());
191 if (serialized.size() < 69) {
194 if (serialized[0] != 1) {
198 assert(nonce_proof_size.has_value() &&
"header length check should guarantee a u32 nonce proof size");
199 const std::size_t payload_size = serialized.size() - 5;
200 if (*nonce_proof_size > payload_size || payload_size - *nonce_proof_size != 64) {
206 "ProvenSignature::deserialize:nonce_proof");
209 "ProvenSignature::deserialize:signature");
Purify result carrier that either holds a value or an error.
#define PURIFY_RETURN_IF_ERROR(expr, context)
Evaluates an expected-like expression and returns the wrapped error on failure.
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)
Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
Legacy Bulletproof-backed Purify-derived BIP340 signing helpers with prepared nonces.
std::optional< std::uint32_t > read_u32_le(std::span< const unsigned char > bytes, std::size_t offset)
void append_u32_le(Bytes &out, std::uint32_t value)
std::array< unsigned char, 32 > Scalar32
std::array< unsigned char, 32 > XOnly32
Status require_secp_context(const purify_secp_context *context, const char *error_context)
constexpr Unexpected< Error > unexpected_error(ErrorCode code, const char *context=nullptr)
Constructs an unexpected Error value from a machine-readable code.
Status validate_public_key(const UInt512 &packed)
Validates the packed public-key encoding range.
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
bool checked_add_size(std::size_t lhs, std::size_t rhs, std::size_t &out) noexcept
Narrow C ABI exposing secp256k1 scalar and HMAC helpers to the C++ headers.
int purify_bip340_xonly_from_point(purify_secp_context *context, const unsigned char point33[33], unsigned char xonly32[32], int *parity_out)
Converts a compressed secp256k1 point into its x-only public key encoding.
int purify_bip340_validate_signature(purify_secp_context *context, const unsigned char sig64[64])
Returns nonzero when the 64-byte BIP340 signature has a syntactically valid encoding.
int purify_bip340_validate_xonly_pubkey(purify_secp_context *context, const unsigned char xonly_pubkey32[32])
Returns nonzero when the x-only public key encoding parses successfully.
static BigUInt from_bytes_be(const unsigned char *data, std::size_t size)
Parses a big-endian byte string into the fixed-width integer.
std::array< unsigned char, Words *8 > to_bytes_be() const
Serializes the value to a fixed-width big-endian byte array.
Result< Bytes > serialize() const
static Result< ExperimentalBulletproofProof > deserialize(std::span< const unsigned char > bytes)
Public nonce together with its experimental Purify statement proof.
ExperimentalBulletproofProof proof
static Result< NonceProof > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Result< Bytes > serialize(purify_secp_context *secp_context) const
Public BIP340 nonce point in x-only form.
static Result< Nonce > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
static constexpr std::size_t kSerializedSize
Standard signature bundled with the public nonce proof it relied on.
static Result< ProvenSignature > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Result< Bytes > serialize(purify_secp_context *secp_context) const
Public key bundle pairing a Purify packed public key with its derived BIP340 x-only key.
static constexpr std::size_t kSerializedSize
Bytes serialize() const
Serializes this public-key bundle into its fixed-size wire format.
static Result< PublicKey > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Parses a serialized public-key bundle.
Standard 64-byte BIP340 signature.
static constexpr std::size_t kSerializedSize
static Result< Signature > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)