24using XOnly32 = std::array<unsigned char, 32>;
47 std::span<const unsigned char> serialized);
54 std::span<const unsigned char> topic,
118 std::span<const unsigned char> message,
144 std::span<const unsigned char> topic,
170 std::span<const unsigned char> message,
197 std::span<const unsigned char> message,
198 std::span<const unsigned char> topic,
213 std::span<const unsigned char> message,
370 "PreparedNonce::scalar:consumed");
394 std::span<const unsigned char> message,
404 std::span<const unsigned char> message,
411 void clear() noexcept;
418 bool available_{
false};
435 return prepared_.public_nonce();
440 return prepared_.available();
456 return prepared_.scalar();
484 std::span<const unsigned char> message,
494 std::span<const unsigned char> message,
499 : prepared_(std::move(prepared)), proof_(std::move(
proof)) {}
501 PreparedNonce prepared_;
552 std::span<const unsigned char> message,
582 std::span<const unsigned char> topic,
622 std::span<const unsigned char> message,
633 std::span<const unsigned char> topic,
652 std::span<const unsigned char> message,
663 std::span<const unsigned char> message,
686 std::span<const unsigned char> message,
687 std::span<const unsigned char> topic,
699 std::span<const unsigned char> message,
706 : secret_(std::move(secret)), public_key_(std::move(
public_key)) {}
709 PublicKey public_key_{};
High-level Purify key generation, evaluation, witness generation, and circuit helpers.
C++ wrappers for the BPPP functionality used by Purify.
Public-key-agnostic native verifier-circuit template.
Move-only packed Purify secret stored in dedicated heap memory.
Common interface for reusable experimental BPPP backend state.
Caller-owned cache for reusable experimental circuit reduction and BPPP backend data.
Result< PreparedNonce > prepare_message_nonce(std::span< const unsigned char > message, purify_secp_context *secp_context) const
Deterministically prepares a message-bound nonce.
Result< PreparedNonce > prepare_topic_nonce(std::span< const unsigned char > topic, purify_secp_context *secp_context) const
Deterministically prepares a topic-bound nonce.
Result< ProvenSignature > sign_message_with_proof(std::span< const unsigned char > message, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Signs a message and returns the signature bundled with its BPPP nonce proof.
const PublicKey & public_key() const noexcept
Returns the public key bundle associated with this signer.
Result< Signature > sign_with_prepared_topic(std::span< const unsigned char > message, PreparedNonce &&prepared, purify_secp_context *secp_context) const
Signs a message using an already prepared topic-bound nonce.
KeyPair & operator=(KeyPair &&other) noexcept=default
KeyPair & operator=(const KeyPair &)=delete
static Result< KeyPair > from_secret(const SecretKey &secret, purify_secp_context *secp_context)
Derives a PureSign++ signing key pair from one packed Purify secret.
Result< PreparedNonceWithProof > prepare_message_nonce_with_proof(std::span< const unsigned char > message, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Deterministically prepares a message-bound nonce together with its BPPP proof.
Result< ProvenSignature > sign_with_prepared_topic_proof(std::span< const unsigned char > message, PreparedNonceWithProof &&prepared, purify_secp_context *secp_context) const
Signs a message using an already prepared topic-bound nonce proof bundle.
Result< Signature > sign_message_with_prepared(std::span< const unsigned char > message, PreparedNonce &&prepared, purify_secp_context *secp_context) const
Signs a message using an already prepared message-bound nonce.
Result< ProvenSignature > sign_with_topic_proof(std::span< const unsigned char > message, std::span< const unsigned char > topic, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Signs a message with a topic-bound nonce proof.
Result< Signature > sign_message(std::span< const unsigned char > message, purify_secp_context *secp_context) const
Signs a message with a deterministically derived message-bound nonce.
Result< PreparedNonceWithProof > prepare_topic_nonce_with_proof(std::span< const unsigned char > topic, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Deterministically prepares a topic-bound nonce together with its BPPP proof.
KeyPair(const KeyPair &)=delete
Result< Signature > sign_with_topic(std::span< const unsigned char > message, std::span< const unsigned char > topic, purify_secp_context *secp_context) const
Signs a message using a topic-bound deterministic nonce.
KeyPair(KeyPair &&other) noexcept=default
Result< ProvenSignature > sign_message_with_prepared_proof(std::span< const unsigned char > message, PreparedNonceWithProof &&prepared, purify_secp_context *secp_context) const
Signs a message using an already prepared message-bound nonce proof bundle.
static constexpr std::size_t kSerializedSize
const UInt512 & public_key() const noexcept
static Result< NonceHost > deserialize(std::span< const unsigned char > serialized)
Result< bool > verify_topic_nonce_proof(std::span< const unsigned char > topic, const NonceProof &nonce_proof, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Result< Scalar32 > scalar() const
Explicitly exports the secret nonce scalar from the wrapped prepared nonce.
PreparedNonceWithProof(const PreparedNonceWithProof &)=delete
const NonceProof & proof() const noexcept
Returns the public nonce proof carried by this bundle.
Result< ProvenSignature > sign_message(const SecretKey &secret, std::span< const unsigned char > message, purify_secp_context *secp_context) &&
Consumes this message-bound prepared proof bundle and signs the message.
static PreparedNonceWithProof from_parts(PreparedNonce prepared, NonceProof proof)
Bundles a prepared nonce with its matching BPPP-backed public nonce proof.
PreparedNonceWithProof & operator=(PreparedNonceWithProof &&other) noexcept=default
Result< Scalar32 > raw_scalar() const
Explicitly exports the scalar for the proof's full raw point.
~PreparedNonceWithProof()=default
PreparedNonceWithProof(PreparedNonceWithProof &&other) noexcept=default
Result< ProvenSignature > sign_topic_message(const SecretKey &secret, std::span< const unsigned char > message, purify_secp_context *secp_context) &&
Consumes this topic-bound prepared proof bundle and signs the message.
const Nonce & public_nonce() const noexcept
Returns the public nonce proved by this bundle.
bool available() const noexcept
Returns whether the wrapped secret nonce remains available.
PreparedNonceWithProof & operator=(const PreparedNonceWithProof &)=delete
Move-only prepared nonce bound to either a message or a topic.
Result< Signature > sign_message(const Bip340Key &signer, std::span< const unsigned char > message, purify_secp_context *secp_context) &&
Consumes this message-bound nonce and signs the matching message.
bool available() const noexcept
Returns whether the secret nonce remains available to consume.
Result< Scalar32 > scalar() const
Explicitly exports the secret nonce scalar.
const Nonce & public_nonce() const noexcept
Returns the public nonce corresponding to this prepared secret nonce scalar.
PreparedNonce & operator=(const PreparedNonce &)=delete
PreparedNonce(const PreparedNonce &)=delete
Result< Signature > sign_topic_message(const Bip340Key &signer, std::span< const unsigned char > message, purify_secp_context *secp_context) &&
Consumes this topic-bound nonce and signs a message under that topic binding.
static PreparedNonce from_parts(Scope scope, const Scalar32 &scalar, const Nonce &nonce, const XOnly32 &signer_pubkey, const XOnly32 &binding_digest)
Builds a prepared nonce from already-derived nonce components.
std::array< unsigned char, 33 > PointBytes
Compressed 33-byte curve-point encoding.
std::array< unsigned char, 32 > ScalarBytes
Big-endian 32-byte scalar encoding.
std::array< unsigned char, 32 > XOnly32
std::array< unsigned char, 32 > Scalar32
std::array< unsigned char, 64 > Signature64
constexpr Unexpected< Error > unexpected_error(ErrorCode code, const char *context=nullptr)
Constructs an unexpected Error value from a machine-readable code.
BigUInt< 8 > UInt512
512-bit unsigned integer used for private and packed public keys.
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
Canonical BIP340 keypair derived deterministically from a packed Purify secret.
Cacheable message-bound nonce-proof template for the BPPP-backed PureSign++ proof(R) flow.
bppp::ExperimentalCircuitCache backend_cache
NativeBulletproofCircuitTemplate circuit_template
static Result< MessageProofCache > build(std::span< const unsigned char > message)
Builds a reusable verifier template for one exact message.
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 > from_secret(const SecretKey &secret, purify_secp_context *secp_context)
Derives both public identities from one packed Purify secret.
Result< bool > verify_message_nonce_proof(std::span< const unsigned char > message, const NonceProof &nonce_proof, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Verifies a message-bound BPPP nonce proof against this public key.
static Result< PublicKey > deserialize(std::span< const unsigned char > serialized, purify_secp_context *secp_context)
Parses a serialized PureSign++ public-key bundle.
Result< bool > verify_topic_nonce_proof(std::span< const unsigned char > topic, const NonceProof &nonce_proof, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Verifies a topic-bound BPPP nonce proof against this public key.
Result< bool > verify_signature(std::span< const unsigned char > message, const Signature &signature, purify_secp_context *secp_context) const
Verifies a plain BIP340 signature against this bundle's x-only public key.
Bytes serialize() const
Serializes this PureSign++ public-key bundle into its fixed-size wire format.
Result< bool > verify_message_signature_with_proof(std::span< const unsigned char > message, const ProvenSignature &signature, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Verifies a message signature bundled with its BPPP nonce proof.
static constexpr std::size_t kSerializedSize
Result< bool > verify_topic_signature_with_proof(std::span< const unsigned char > message, std::span< const unsigned char > topic, const ProvenSignature &signature, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *circuit_cache=nullptr) const
Verifies a topic-bound signature bundled with its BPPP nonce proof.
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.
Cacheable topic-bound nonce-proof template for the BPPP-backed PureSign++ proof(R) flow.
bppp::ExperimentalCircuitCache backend_cache
NativeBulletproofCircuitTemplate circuit_template
static Result< TopicProofCache > build(std::span< const unsigned char > topic)
Builds a reusable verifier template for one exact topic.