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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
//! Admission and refusal — the first-class boundary verdict surface.
//!
//! This is where untrusted [`crate::state::Raw`] evidence is judged against a
//! named [`crate::witness::Witness`] and either **admitted** or **refused**.
//! Both outcomes are first-class, strongly-typed values:
//!
//! - [`Admission<T, W>`] — the value crossed the boundary; it may now become
//! [`crate::state::Admitted`] [`crate::evidence::Evidence`].
//! - [`Refusal<R, W>`] — the value was declined for a **specific named reason**
//! `R` (e.g. `DanglingEventObjectLink`, `MissingFinalMarking`). A bare
//! "invalid input" is *not* an acceptable reason here (see
//! [`docs/REFUSAL_LAW.md`](https://github.com/wasm4pm/wasm4pm-compat/blob/main/docs/REFUSAL_LAW.md)).
//!
//! The [`Admit`] trait ties the two together: it is the **only** sanctioned way
//! to turn `Raw` evidence into `Admitted` evidence. There is no free conversion
//! anywhere else in the crate.
//!
//! This module is **structure only**. An [`Admit`] impl encodes *which named law*
//! gates a boundary; it does not run a discovery/conformance engine. When a
//! boundary needs real verification (token replay, soundness checking, …),
//! graduate it to `wasm4pm`.
use PhantomData;
use crateEvidence;
use crateRaw;
/// A value that has been **admitted** across the boundary, answering to `W`.
///
/// Holding an `Admission<T, W>` is proof (at the type level) that an [`Admit`]
/// impl accepted the value against witness `W`. Convert it into sealed
/// [`crate::state::Admitted`] evidence with [`Admission::into_evidence`].
///
/// Structure-only: admission attests *that a named law was satisfied at this
/// boundary*, not that the value is semantically verified by an engine.
/// Graduate to `wasm4pm` for engine-level verification.
// Manual `Debug` so the witness marker `W` need not itself be `Debug` (it is a
// zero-sized `PhantomData` tag). Enables `Result::expect_err` in tests/callers.
/// A value that has been **refused** at the boundary for a *named* reason `R`.
///
/// `Refusal` is not an error string — it is a first-class outcome carrying a
/// specific, auditable reason. The reason type `R` should be a named law
/// (an enum variant like `MissingFinalMarking`), never a catch-all
/// "InvalidInput".
///
/// Structure-only: a refusal records *which law was broken*, not a stack trace
/// or remediation engine. It is the honest "no" at the compatibility boundary.
// Manual `Debug` so the witness marker `W` need not itself be `Debug` (it is a
// zero-sized `PhantomData` tag). Enables `Result::expect` in tests/callers.
// Manual `Display` — shows the human-readable law name that caused the refusal.
// `W` is a zero-sized `PhantomData` tag and carries no displayable value.
/// The boundary verdict trait — the only sanctioned `Raw → Admitted` path.
///
/// An implementor names a single boundary: it takes [`crate::state::Raw`]
/// [`Evidence`] of `Self::Raw` against `Self::Witness`, and returns either an
/// [`Admission`] of `Self::Admitted` or a [`Refusal`] carrying a *named*
/// `Self::Reason`.
///
/// Structure-only contract: `admit` decides admissibility by *shape and named
/// law*. It does not invoke an execution engine. A boundary requiring real
/// semantic verification graduates to `wasm4pm`.
///
/// # Examples
///
/// ```
/// use wasm4pm_compat::admission::{Admit, Admission, Refusal};
/// use wasm4pm_compat::evidence::Evidence;
/// use wasm4pm_compat::state::Raw;
/// use wasm4pm_compat::witness::Ocel20;
///
/// /// A toy OCEL admission: refuse logs whose only event has no object link.
/// enum LinkedOcel {}
///
/// /// `true` = the (single) event carries at least one object link.
/// impl Admit for LinkedOcel {
/// type Raw = bool;
/// type Admitted = bool;
/// type Reason = &'static str;
/// type Witness = Ocel20;
/// fn admit(raw: Evidence<bool, Raw, Ocel20>)
/// -> Result<Admission<bool, Ocel20>, Refusal<&'static str, Ocel20>> {
/// if raw.value {
/// Ok(Admission::new(true))
/// } else {
/// Err(Refusal::new("DanglingEventObjectLink"))
/// }
/// }
/// }
///
/// assert!(LinkedOcel::admit(Evidence::raw(true)).is_ok());
/// let refusal = LinkedOcel::admit(Evidence::raw(false)).unwrap_err();
/// assert_eq!(refusal.reason, "DanglingEventObjectLink");
/// ```
/// The named law a chain recompute can violate: the recomputed BLAKE3 chain
/// digest did not equal the digest the receipt claims.
///
/// A *specific named* reason (never "InvalidInput"). An external `SealingAdmit`
/// impl MAY instead name its own `Self::Reason`; this type is provided so the
/// shared [`recompute_and_match`] seam can refuse without forcing the consumer
/// to define one.
;
/// Crate-internal sealed proof that a chain digest was recomputed and matched.
///
/// The private `_seal` field makes struct-literal construction a compile error
/// (`E0451`) outside this crate, so a `ChainProof` can only be obtained from
/// [`recompute_and_match`], which mints it *after* a successful digest
/// comparison. It is the gate that makes [`RuntimeSeal`] unforgeable while
/// still being mintable by an external consumer through a verified flow.
/// Recomputes a receipt's chain digest with a consumer-supplied rule and, on a
/// byte-for-byte match against the claimed digest, mints a [`ChainProof`].
///
/// `chain_rule` is supplied **by the consumer** (e.g. affidavit's
/// genesis-seeded rolling BLAKE3 fold over its `OperationEvent` bytes), so the
/// chain law stays in the consumer crate and is never copied into this crate.
/// This is the public seam that lets an *external* `SealingAdmit` impl produce
/// a [`RuntimeSeal`] without crate-internal access.
///
/// Structure-only: it compares digests; it does not cryptographically verify
/// provenance. Graduate to `wasm4pm` for replay verification.
///
/// # Examples
///
/// ```
/// use wasm4pm_compat::admission::recompute_and_match;
/// use wasm4pm_compat::receipt::Digest;
///
/// let claimed = Digest::new("blake3:abc");
/// // Consumer supplies its own chain rule; here a trivial stub.
/// let proof = recompute_and_match("events", &claimed, |_e| Digest::new("blake3:abc"));
/// assert!(proof.is_ok());
/// let bad = recompute_and_match("events", &claimed, |_e| Digest::new("blake3:zzz"));
/// assert!(bad.is_err());
/// ```
/// A runtime sealing value — a BLAKE3 chain digest locked at admission time.
///
/// **Value-level**, not a const-generic: a BLAKE3 hash is runtime data and
/// cannot appear in a const-generic position. Non-forgeability is the
/// [`crate::petri::SeparableWfNet`] `_seal` idiom: the inner `hash` field is
/// private, so a `RuntimeSeal` can only be minted through a verified flow —
/// either the public [`RuntimeSeal::from_verified_chain`] (which consumes a
/// [`ChainProof`] minted by [`recompute_and_match`]) or, in-crate, via
/// [`RuntimeSeal::from_chain`].
///
/// Structure-only: it records *that a chain digest was computed and matched*,
/// not that any cryptographic authority verified it. Graduate to `wasm4pm`.
/// A value admitted **with a runtime seal** locked in at the boundary.
///
/// Parallel to [`Admission`], but additionally carries a private
/// [`RuntimeSeal`]. The private `seal` field makes struct-literal construction
/// a compile error outside this crate (`E0451`). Combined with the private
/// `_seal` field on [`Evidence`] itself, the only way to reach
/// [`crate::state::Admitted`] evidence for a chain-sealed witness is via
/// [`SealedAdmission::into_evidence`], which requires a `SealedAdmission`,
/// which requires a [`RuntimeSeal`], which requires a [`ChainProof`].
///
/// Structure-only; graduate to `wasm4pm` for engine-level verification.
/// The chain-sealing boundary seam — **beside** [`Admit`], never replacing it.
///
/// A `SealingAdmit` impl judges raw evidence AND threads a runtime
/// [`RuntimeSeal`] (a recomputed BLAKE3 chain digest) into the verdict. The
/// existing [`Admit`] trait, and its trybuild receipts, are untouched. An
/// external consumer implements it by calling [`recompute_and_match`] with its
/// own chain rule, then [`RuntimeSeal::from_verified_chain`], then
/// [`SealedAdmission::seal`].
///
/// Structure-only: an impl recomputes and matches the chain digest; it does
/// not cryptographically verify provenance. Graduate to `wasm4pm` for that.