27 "nonce_proof_matches_nonce:secp_context");
30 "nonce_proof_matches_nonce:invalid_commitment_point");
33 return xonly == nonce_proof.nonce.xonly;
36Status validate_circuit_proof_encoding(
39 static constexpr std::size_t kRoundCount = 12;
41 const bppp::candidate::CircuitZkNormArgProofV4 proof{
42 nonce_proof.raw_commitment,
43 nonce_proof.mask_commitment,
45 nonce_proof.public_commitment_dlog_nonce,
46 nonce_proof.public_commitment_dlog_response,
47 nonce_proof.norm_proof,
52 kRoundCount, secp_context);
58 std::span<const unsigned char> serialized) {
64 serialized.data(), serialized.size());
67 "NonceHost::deserialize:public_key");
74 std::array<unsigned char, 64> packed =
purify_pubkey.to_bytes_be();
75 out.insert(out.end(), packed.begin(), packed.end());
88 std::copy(serialized.begin() + 64, serialized.end(), out.
bip340_pubkey.begin());
90 "PublicKey::deserialize:secp_context");
93 "PublicKey::deserialize:bip340_validate_xonly_pubkey");
108 std::copy(serialized.begin(), serialized.end(), out.
xonly.begin());
110 "Nonce::deserialize:secp_context");
125 std::copy(
bytes.begin() + 32,
bytes.end(), out.begin());
139 std::copy(serialized.begin(), serialized.end(), out.
bytes.begin());
141 "Signature::deserialize:secp_context");
150 "NonceProof::serialize:nonce_proof_matches_nonce");
155 validate_circuit_proof_encoding(*
this, secp_context),
156 "NonceProof::serialize:circuit_proof");
161 out.insert(out.end(),
nonce.xonly.begin(),
nonce.xonly.end());
165 out.insert(out.end(),
t2.begin(),
t2.end());
177 constexpr std::size_t kHeaderSize =
178 1 + 32 + 33 + 33 + 33 + 32 + 32 + 32;
187 std::copy_n(serialized.begin() + 1, 32, out.
nonce.
xonly.begin());
189 "NonceProof::deserialize:secp_context");
194 std::copy_n(serialized.begin() + 66, 33, out.
raw_commitment.begin());
196 std::copy_n(serialized.begin() + 132, 32, out.
t2.begin());
197 std::copy_n(serialized.begin() + 164, 32,
199 std::copy_n(serialized.begin() + 196, 32,
201 out.
norm_proof.assign(serialized.begin() + kHeaderSize,
204 validate_circuit_proof_encoding(out, secp_context),
205 "NonceProof::deserialize:circuit_proof");
208 "NonceProof::deserialize:nonce_proof_matches_nonce");
217 "ProvenSignature::serialize:nonce_proof");
221 out.insert(out.end(), nonce_proof_bytes.begin(), nonce_proof_bytes.end());
239 "ProvenSignature::deserialize:nonce_proof");
245 "ProvenSignature::deserialize:signature");
static constexpr std::size_t kSerializedSize
const UInt512 & public_key() const noexcept
static Result< NonceHost > deserialize(std::span< const unsigned char > serialized)
#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.
Status validate_circuit_zk_norm_arg_proof_v4_fixed_encoding(const CircuitZkNormArgProofV4 &proof, CircuitCommitmentModeV4 mode, std::size_t round_count, purify_secp_context *secp_context)
std::array< unsigned char, 32 > XOnly32
std::array< unsigned char, 32 > Scalar32
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.
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
Expected< void, Error > Status
Expected-returning convenience alias for Purify status-only APIs.
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
Experimental BPPP-backed PureSign proof(R) helpers.
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.
struct purify_secp_context purify_secp_context
Caller-owned reusable secp256k1 context handle shared across Purify C and C++ APIs.
static BigUInt from_bytes_be(const unsigned char *data, std::size_t size)
bppp::PointBytes commitment_point
static Result< NonceProof > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
bppp::PointBytes raw_commitment
bppp::PointBytes mask_commitment
Result< Bytes > serialize(purify_secp_context *secp_context) const
bppp::ScalarBytes public_commitment_dlog_response
XOnly32 public_commitment_dlog_nonce
static constexpr std::size_t kNormProofSize
static constexpr unsigned char kSerializationVersion
static constexpr std::size_t kSerializedSize
Public BIP340 nonce point in x-only form.
static Result< Nonce > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Parses a serialized x-only nonce.
Bytes serialize() const
Serializes this x-only nonce into its fixed-size wire format.
static constexpr std::size_t kSerializedSize
Result< Bytes > serialize(purify_secp_context *secp_context) const
static constexpr unsigned char kSerializationVersion
static Result< ProvenSignature > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
static constexpr std::size_t kSerializedSize
static Result< PublicKey > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Parses a serialized PureSign++ public-key bundle.
Bytes serialize() const
Serializes this PureSign++ public-key bundle into its fixed-size wire format.
static constexpr std::size_t kSerializedSize
Standard 64-byte BIP340 signature.
Bytes serialize() const
Serializes this signature into its fixed-size wire format.
static constexpr std::size_t kSerializedSize
Scalar32 s() const
Returns the 32-byte Schnorr s scalar encoded in the last 32 signature bytes.
Nonce nonce() const
Returns the x-only public nonce encoded in the first 32 signature bytes.
static Result< Signature > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Parses a serialized BIP340 signature.