purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
anchor_escrow.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Judica, Inc.
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or https://opensource.org/license/mit/.
4
5#pragma once
6
7#include <array>
8#include <cstddef>
9#include <span>
10#include <utility>
11
12#include "purify/api.hpp"
13#include "purify/bppp.hpp"
15
16namespace purify::accountable {
17
22
30using AnchorEscrowContextDigest = std::array<unsigned char, 32>;
31
40public:
42
45 const AnchorEscrowAuxiliaryScalar&) = delete;
47 const AnchorEscrowAuxiliaryScalar&) = delete;
49 AnchorEscrowAuxiliaryScalar&& other) noexcept;
51 AnchorEscrowAuxiliaryScalar&& other) noexcept;
53
56 const Bytes& encoded);
57
58private:
59 explicit AnchorEscrowAuxiliaryScalar(const Bytes& encoded)
60 : bytes_(encoded) {}
61
62 void clear() noexcept;
63
64 Bytes bytes_{};
65
68 const RecoveryBoundSigningRoster&, const UInt512&,
69 const AnchorPunishmentKey&, const AnchorEscrowContextDigest&,
72};
73
76public:
79 const AnchorPunishmentPublicKey&) = default;
81 default;
83 AnchorPunishmentPublicKey&&) noexcept = default;
84
85 [[nodiscard]] static Result<AnchorPunishmentPublicKey> create(
86 const std::array<unsigned char, 32>& xonly,
87 purify_secp_context* secp_context);
88
89 [[nodiscard]] const std::array<unsigned char, 32>& xonly() const noexcept {
90 return xonly_;
91 }
92
94 const AnchorPunishmentPublicKey&) = default;
95
96private:
98 const std::array<unsigned char, 32>& xonly) : xonly_(xonly) {}
99
100 std::array<unsigned char, 32> xonly_{};
101
103};
104
107public:
111 AnchorPunishmentKey& operator=(AnchorPunishmentKey&&) noexcept = default;
112
114 [[nodiscard]] static Result<AnchorPunishmentKey> from_secret(
115 std::array<unsigned char, 32> secret,
116 purify_secp_context* secp_context);
117
118 [[nodiscard]] const Bip340Key& bip340_key() const noexcept {
119 return key_;
120 }
121
122 [[nodiscard]] const AnchorPunishmentPublicKey& public_key() const
123 noexcept {
124 return public_key_;
125 }
126
127private:
128 explicit AnchorPunishmentKey(Bip340Key key)
129 : key_(std::move(key)), public_key_(key_.xonly_pubkey) {}
130
131 Bip340Key key_;
132 AnchorPunishmentPublicKey public_key_;
133};
134
137 static constexpr std::size_t kSerializedSize = 96;
138
141};
142
150public:
151 static constexpr unsigned char kSerializationVersion = 4;
152 static constexpr std::size_t kNormProofSize = 974;
153 static constexpr std::size_t kProofPayloadSize = 1136;
154 static constexpr std::size_t kSerializedSize =
156
160 AnchorEscrowRecord& operator=(AnchorEscrowRecord&&) noexcept = default;
161
162 [[nodiscard]] const AnchorEscrowCiphertext& ciphertext() const noexcept {
163 return ciphertext_;
164 }
165
166 [[nodiscard]] Result<Bytes> serialize(
167 purify_secp_context* secp_context) const;
168 [[nodiscard]] static Result<AnchorEscrowRecord> deserialize(
169 std::span<const unsigned char> encoded,
170 purify_secp_context* secp_context);
171
172private:
173 AnchorEscrowRecord() = default;
174
175 [[nodiscard]] Status validate_encoding(
176 purify_secp_context* secp_context) const;
177
178 AnchorEscrowCiphertext ciphertext_{};
179 bppp::PointBytes raw_commitment_{};
180 bppp::PointBytes mask_commitment_{};
181 bppp::ScalarBytes t2_{};
182 std::array<unsigned char, 32> public_commitment_dlog_nonce_{};
183 bppp::ScalarBytes public_commitment_dlog_response_{};
184 Bytes norm_proof_;
185
187 const RecoveryBoundSigningRoster&, const UInt512&,
188 const AnchorPunishmentKey&, const AnchorEscrowContextDigest&,
190 bppp::ExperimentalCircuitBackend*);
193 const RecoveryBoundSigningRoster&, const UInt512&,
194 const AnchorPunishmentKey&, const AnchorEscrowContextDigest&,
195 const bppp::ScalarBytes&,
196 purify_secp_context*, bppp::ExperimentalCircuitBackend*);
198 const RecoveryBoundSigningRoster&, const UInt512&,
199 const AnchorPunishmentPublicKey&, const AnchorEscrowContextDigest&,
200 const AnchorEscrowRecord&,
201 purify_secp_context*, bppp::ExperimentalCircuitBackend*);
203};
204
206 2 * bppp::PointBytes{}.size() +
207 2 * bppp::ScalarBytes{}.size() +
208 std::array<unsigned char, 32>{}.size() +
210static_assert(AnchorEscrowRecord::kSerializedSize == 1233);
211
224 const RecoveryBoundSigningRoster& roster,
225 const UInt512& advertised_anchor_root,
226 const AnchorPunishmentKey& punishment_key,
227 const AnchorEscrowContextDigest& context_digest,
228 purify_secp_context* secp_context,
229 bppp::ExperimentalCircuitBackend* cache = nullptr);
230
241[[nodiscard]] Result<AnchorEscrowRecord>
243 const RecoveryBoundSigningRoster& roster,
244 const UInt512& advertised_anchor_root,
245 const AnchorPunishmentKey& punishment_key,
246 const AnchorEscrowContextDigest& context_digest,
247 const AnchorEscrowAuxiliaryScalar& auxiliary_scalar,
248 purify_secp_context* secp_context,
249 bppp::ExperimentalCircuitBackend* cache = nullptr);
250
253 const RecoveryBoundSigningRoster& roster,
254 const UInt512& advertised_anchor_root,
255 const AnchorPunishmentPublicKey& punishment_key,
256 const AnchorEscrowContextDigest& context_digest,
257 const AnchorEscrowRecord& record,
258 purify_secp_context* secp_context,
259 bppp::ExperimentalCircuitBackend* cache = nullptr);
260
271 const RecoveryBoundSigningRoster& roster,
272 const FieldElement& exposed_signing_scalar,
273 const UInt512& advertised_anchor_root,
274 const AnchorPunishmentPublicKey& punishment_key,
275 const AnchorEscrowContextDigest& context_digest,
276 const AnchorEscrowRecord& record,
277 purify_secp_context* secp_context,
278 bppp::ExperimentalCircuitBackend* cache = nullptr);
279
281[[nodiscard]] Result<AnchorPunishmentKey>
284 const FieldElement& exposed_signing_scalar,
285 const UInt512& advertised_anchor_root,
286 const AnchorPunishmentPublicKey& punishment_key,
287 const AnchorEscrowContextDigest& context_digest,
288 const AnchorEscrowRecord& record,
289 purify_secp_context* secp_context,
290 bppp::ExperimentalCircuitBackend* cache = nullptr);
291
292} // namespace purify::accountable
High-level Purify key generation, evaluation, witness generation, and circuit helpers.
C++ wrappers for the BPPP functionality used by Purify.
Field element modulo the backend scalar field used by this implementation.
Definition numeric.hpp:834
friend Result< AnchorEscrowRecord > create_anchor_escrow_deterministic(const RecoveryBoundSigningRoster &, const UInt512 &, const AnchorPunishmentKey &, const AnchorEscrowContextDigest &, const AnchorEscrowAuxiliaryScalar &, purify_secp_context *, bppp::ExperimentalCircuitBackend *)
AnchorEscrowAuxiliaryScalar & operator=(const AnchorEscrowAuxiliaryScalar &)=delete
static Result< AnchorEscrowAuxiliaryScalar > from_bytes(const Bytes &encoded)
AnchorEscrowAuxiliaryScalar(const AnchorEscrowAuxiliaryScalar &)=delete
friend Result< AnchorEscrowRecord > create_anchor_escrow(const RecoveryBoundSigningRoster &, const UInt512 &, const AnchorPunishmentKey &, const AnchorEscrowContextDigest &, purify_secp_context *, bppp::ExperimentalCircuitBackend *)
Result< Bytes > serialize(purify_secp_context *secp_context) const
AnchorEscrowRecord(AnchorEscrowRecord &&) noexcept=default
friend Result< AnchorEscrowRecord > create_anchor_escrow_with_aux_randomness(const RecoveryBoundSigningRoster &, const UInt512 &, const AnchorPunishmentKey &, const AnchorEscrowContextDigest &, const bppp::ScalarBytes &, purify_secp_context *, bppp::ExperimentalCircuitBackend *)
AnchorEscrowRecord(const AnchorEscrowRecord &)=default
const AnchorEscrowCiphertext & ciphertext() const noexcept
static constexpr std::size_t kSerializedSize
static constexpr std::size_t kNormProofSize
static constexpr unsigned char kSerializationVersion
friend Result< bool > verify_anchor_escrow(const RecoveryBoundSigningRoster &, const UInt512 &, const AnchorPunishmentPublicKey &, const AnchorEscrowContextDigest &, const AnchorEscrowRecord &, purify_secp_context *, bppp::ExperimentalCircuitBackend *)
AnchorEscrowRecord & operator=(const AnchorEscrowRecord &)=default
static Result< AnchorEscrowRecord > deserialize(std::span< const unsigned char > encoded, purify_secp_context *secp_context)
static constexpr std::size_t kProofPayloadSize
AnchorPunishmentKey & operator=(const AnchorPunishmentKey &)=delete
const AnchorPunishmentPublicKey & public_key() const noexcept
AnchorPunishmentKey(const AnchorPunishmentKey &)=delete
static Result< AnchorPunishmentKey > from_secret(std::array< unsigned char, 32 > secret, purify_secp_context *secp_context)
AnchorPunishmentKey(AnchorPunishmentKey &&) noexcept=default
const Bip340Key & bip340_key() const noexcept
AnchorPunishmentPublicKey(AnchorPunishmentPublicKey &&) noexcept=default
AnchorPunishmentPublicKey & operator=(const AnchorPunishmentPublicKey &)=default
AnchorPunishmentPublicKey(const AnchorPunishmentPublicKey &)=default
const std::array< unsigned char, 32 > & xonly() const noexcept
static Result< AnchorPunishmentPublicKey > create(const std::array< unsigned char, 32 > &xonly, purify_secp_context *secp_context)
friend bool operator==(const AnchorPunishmentPublicKey &, const AnchorPunishmentPublicKey &)=default
A nonce-host-bound roster with an authorized recovery-root relation.
Common interface for reusable experimental BPPP backend state.
Definition bppp.hpp:129
Result< AnchorPunishmentKey > recover_distributed_escrowed_anchor(const VerifiedDistributedRecoverySetup &setup, const FieldElement &exposed_signing_scalar, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< AnchorEscrowRecord > create_anchor_escrow_deterministic(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowAuxiliaryScalar &auxiliary_scalar, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
std::array< unsigned char, 32 > AnchorEscrowContextDigest
Result< AnchorEscrowRecord > create_anchor_escrow(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentKey &punishment_key, const AnchorEscrowContextDigest &context_digest, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< AnchorPunishmentKey > recover_escrowed_anchor(const RecoveryBoundSigningRoster &roster, const FieldElement &exposed_signing_scalar, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
Result< bool > verify_anchor_escrow(const RecoveryBoundSigningRoster &roster, const UInt512 &advertised_anchor_root, const AnchorPunishmentPublicKey &punishment_key, const AnchorEscrowContextDigest &context_digest, const AnchorEscrowRecord &record, purify_secp_context *secp_context, bppp::ExperimentalCircuitBackend *cache=nullptr)
std::array< unsigned char, 33 > PointBytes
Compressed 33-byte curve-point encoding.
Definition bppp.hpp:32
std::array< unsigned char, 32 > ScalarBytes
Big-endian 32-byte scalar encoding.
Definition bppp.hpp:30
BigUInt< 8 > UInt512
512-bit unsigned integer used for private and packed public keys.
Definition numeric.hpp:821
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
Definition error.hpp:99
Expected< void, Error > Status
Expected-returning convenience alias for Purify status-only APIs.
Definition error.hpp:102
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
Definition common.hpp:99
struct purify_secp_context purify_secp_context
Caller-owned reusable secp256k1 context handle shared across Purify C and C++ APIs.
Canonical BIP340 keypair derived deterministically from a packed Purify secret.
Definition api.hpp:38
static constexpr std::size_t kSerializedSize