1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! # kryphocron — primitives crate
//!
//! The vocabulary the kryphocron substrate uses to express its
//! threat-model commitments in Rust types.
//!
//! The crate ships the substrate's authority discipline
//! end-to-end: issuance, bind (with stage-3 audience-oracle
//! consultation), reborrow, context derivation, tier-aware
//! visibility, audit emission with composite-rollback semantics,
//! timing-channel equalization, JWT and capability-claim
//! verification, and the three-message sync-handshake protocol.
//! 0.3 adds the §8.3 at-rest content-codec seam with an
//! encoding-at-default baseline (laquna + a default rotation
//! oracle).
//!
//! This crate provides:
//!
//! - Tier-aware envelope types ([`Tier`], [`Tiered`]) and the
//! [`HasNsid`] trait family connecting lexicons to tier
//! classification (§4.1, §4.4). [`tier::visible_to`] is the
//! tier × requester-class read predicate.
//! - [`AuthContext`], the in-process authentication context type,
//! the [`ingress`] submodule that constructs it from verified
//! evidence, and [`AuthContext::derive_for`] for scope-narrowing
//! sub-context derivation across three legal narrowings
//! (drop-to-anonymous, narrow-capabilities,
//! service-to-service) (§4.2).
//! - Capability proof types and the [`authority`] module that
//! issues them via [`authority::issue_user`] /
//! [`authority::issue_channel`] /
//! [`authority::issue_substrate`] /
//! [`authority::issue_moderation`]. Each issued proof exposes
//! `bind` and `reborrow` async methods running the §4.3
//! pipeline (pre-checks → stage-0 deprecation gate →
//! stage-2 oracle consultation, user-class only →
//! stage-5 predicate → audit emit → stage-6 timing
//! equalization → return). Proofs are unforgeable in safe
//! code via sealed traits and [`PhantomData`]-token patterns
//! (§4.3, §4.7).
//! - [`TargetRepresentation`] split into structural and sensitive
//! layers; routine operator audit reads structural, forensic
//! detail requires the segregated decryption key (§4.4).
//! - [`oracle`] traits — [`oracle::BlockOracle`],
//! [`oracle::AudienceOracle`], [`oracle::MuteOracle`] — with
//! freshness commitments and per-query worst-case latency
//! reporting consumed by [`equalize_timing_target_for`] (§4.5).
//! - [`equalize_timing`] for closing the §4.6 timing-channel gap
//! at the bind path's stage 6.
//! - Wire-format types for cross-service capability claims and
//! the per-entry delegation receipt machinery that makes
//! attribution chains tamper-evident across hops (§4.8).
//! - [`audit`] pipeline: per-class sink traits, the §4.9
//! composite-audit machinery ([`audit::composite_audit`])
//! with class-priority commit order, rollback fan-out, and
//! the [`audit::FallbackAuditSink`] escalation contract; a
//! 30+ variant audit-event vocabulary; the §6.7 inspection-
//! notification queue trait ([`authority::InspectionNotificationQueueImpl`])
//! for moderation-class fan-out.
//! - [`verification`] submodule — [`verification::VerifiedJwt`],
//! [`verification::VerifiedCapabilityClaim`],
//! [`verification::VerifiedSyncMessage`], and the three-message
//! sync-handshake evidence types
//! ([`verification::VerifiedSyncHello`],
//! [`verification::VerifiedSyncAccept`],
//! [`verification::VerifiedSyncEstablished`]) — the only path
//! that produces verified evidence the [`ingress`] submodule
//! accepts (§7.2, §7.5).
//! - [`trust`] service-trust-declaration verification (§7.4).
//! - [`resolver`] trait surfaces for DID resolution and federation-
//! peer trust (§7.3, §7.7).
//! - [`encryption`] at-rest hook surfaces: the §8.2 audit-encryption
//! trait surface and opaque key-id types, plus the §8.3
//! [`encryption::ContentCodec`] content-codec seam. 0.3 ships
//! [`encryption::DefaultAtRestHooks`] — laquna ([`codec::laquna`]) +
//! a default rotation oracle — as the encoding-at-default baseline;
//! operators substitute *strengthening* codecs (rev 3 §2.1 / §5).
//!
//! ## Discipline
//!
//! - **The wrong path is harder to write than the right path.**
//! Misuse of a primitive is a compile error wherever possible,
//! a runtime error otherwise, and a silent success never.
//! - **Capabilities are unforgeable in safe code.** Code outside
//! the crate's [`authority`] module cannot construct
//! authorization proofs in safe Rust. Sealed traits and a
//! private token type carried in [`PhantomData`] on every
//! proof type enforce this. The crate forbids `unsafe` at the
//! lints level.
//! - **Tier is not a label, it's a structural property.** A
//! function that emits to a public surface cannot accept a
//! private-tier value, by type, not by runtime check.
//! - **Audit reflects action, not intent.** Audit events fire
//! on the *binding* of a capability proof (success or
//! failure), not on its issuance.
//! - **Door-open, not door-ajar.** Where the spec defers to
//! operator policy (audit-encryption algorithm, oracle
//! backends, audit sink storage, inspection-notification
//! queue), the crate ships a trait surface + explicit no-op
//! default (e.g. [`authority::NoInspectionNotifications`]);
//! operators install real implementations when their
//! deployment needs them. The §8.3 at-rest *content codec* is
//! the exception — it is encoding-at-default, not door-open:
//! the baseline installs a real codec (rev 3 §2.1).
//!
//! ## Enrichment posture
//!
//! The audit pipeline is wired end-to-end. Certain audit-event
//! payload fields ship with placeholder data pending per-class
//! sealed-extraction traits in a future release (channel-class
//! peer + session id; substrate-class scope kind; moderation-
//! class case id). Bind consults the universal
//! block-vs-resource-owner query and, for audience-gated
//! capabilities, the audience oracle (§4.5); a generalized
//! per-capability multi-query oracle-results-builder is future
//! work. The [`AuthContext::derive_for`]
//! [`ingress::NarrowCapabilities`] narrowing ships recording-only
//! — the [`AuthContext`] gains a capabilities field in a future
//! release for structural superset enforcement.
//! [`tier::visible_to`] is the tier-only standalone predicate; an
//! audience-aware overload is future work (bind itself already
//! consults the audience oracle).
//!
//! [`PhantomData`]: core::marker::PhantomData
// Dead-code lints are addressed per-item with targeted
// `#[allow]` annotations where the type/function is part of the
// public surface but not consumed by the crate itself yet
// (operator-pluggable trait surfaces, future-accessor scaffolding).
// The vendored laquna codec internals (`src/codec/laquna/internal/`) are
// `no_std`-style source using `alloc::` paths. Bring `alloc` into the extern
// prelude crate-wide so those paths resolve in the `std` crate (rev 3 §3.1).
extern crate alloc;
// Internal modules.
// Public modules per §9.1.
/// §4.3 capability proof issuance, sealed trait machinery, and
/// the v1 capability vocabulary.
/// §8.3 at-rest content encode / decode seams driving an installed
/// [`encryption::ContentCodec`].
/// §4.9 audit pipeline traits, sink types, composite-audit
/// rollback machinery, fallback sink contract.
/// Built-in [`encryption::ContentCodec`] implementations (rev 3 §3.7).
/// [`codec::laquna`] is the substrate's default at-rest content codec.
/// §8 at-rest hook surfaces: the §8.2 audit-encryption trait surface
/// (type vocabulary only) and the §8.3 [`encryption::ContentCodec`]
/// content-codec seam.
/// §4.2 ingress submodule — constructs [`AuthContext`] values from
/// verified evidence types produced by [`verification`].
/// §4.5 oracle traits: block, audience, mute. Freshness
/// commitments and per-query worst-case latency reporting.
/// §5.4 / rev6 §4.2 private-record structural validation and the read-side
/// post-authorization witness ([`read_pipeline::ReadAuthorization`]).
/// §7.3, §7.7 DID resolution and federation-peer trust trait
/// surfaces. The crate ships trait shapes; concrete resolvers are
/// operator territory.
/// §7.4 service-trust-declaration verification.
///
/// Trust declarations are minted by operator tooling (typically a
/// CLI signing with a hardware-token-held trust-root key). The
/// crate provides the verification path; construction is operator-
/// managed.
/// §4.1, §4.4 tier model and tier-aware envelope types.
/// §7.2 JWT / handshake / claim verification. The only path that
/// produces [`verification::VerifiedJwt`],
/// [`verification::VerifiedCapabilityClaim`],
/// [`verification::VerifiedSyncMessage`], and the three-message
/// sync-handshake evidence values; downstream code that takes one
/// of those types knows verification ran.
// Internal areas that span §4 but don't carry their own
// committed public module path in §9.1. We expose them at the
// crate root to keep the public-surface lookup short.
// Crate-root re-exports of the load-bearing public types.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Outcome;
pub use ;
pub use ;
pub use ;
// §5.3 / §5.4 / §5.6 re-exports from the lexicon companion crate.
// The lexicon set's compiled-in registry is the substrate's
// runtime trust anchor for tier classification and deprecation
// state.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;