@sanning/proof 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +30 -29
  2. package/dist/agent-record.d.ts +62 -0
  3. package/dist/agent-record.js +527 -0
  4. package/dist/agent-schemas.generated.d.ts +15 -0
  5. package/dist/agent-schemas.generated.js +5759 -0
  6. package/dist/case-file.d.ts +32 -89
  7. package/dist/case-file.js +41 -93
  8. package/dist/case.d.ts +339 -822
  9. package/dist/case.js +667 -1160
  10. package/dist/chain.d.ts +19 -47
  11. package/dist/chain.js +78 -205
  12. package/dist/claims.d.ts +211 -0
  13. package/dist/claims.js +1081 -0
  14. package/dist/cli.d.ts +45 -68
  15. package/dist/cli.js +618 -1022
  16. package/dist/compose.js +23 -65
  17. package/dist/crypto.d.ts +7 -8
  18. package/dist/crypto.js +60 -147
  19. package/dist/declaration.d.ts +68 -194
  20. package/dist/declaration.js +175 -518
  21. package/dist/environment.d.ts +9 -30
  22. package/dist/environment.js +17 -66
  23. package/dist/evidence.d.ts +119 -160
  24. package/dist/evidence.js +744 -1103
  25. package/dist/exit-codes.d.ts +11 -27
  26. package/dist/exit-codes.js +24 -59
  27. package/dist/file-match.d.ts +33 -79
  28. package/dist/file-match.js +33 -69
  29. package/dist/grading.d.ts +98 -135
  30. package/dist/grading.js +224 -380
  31. package/dist/handoff.d.ts +62 -160
  32. package/dist/handoff.js +153 -393
  33. package/dist/index.d.ts +14 -10
  34. package/dist/index.js +60 -167
  35. package/dist/json-schema.d.ts +29 -0
  36. package/dist/json-schema.js +298 -0
  37. package/dist/merkle.js +16 -28
  38. package/dist/message-parts.d.ts +56 -212
  39. package/dist/message-parts.js +142 -502
  40. package/dist/side-content.d.ts +11 -22
  41. package/dist/side-content.js +22 -65
  42. package/dist/types.d.ts +17 -0
  43. package/dist/types.js +19 -5
  44. package/dist/verifier.d.ts +40 -114
  45. package/dist/verifier.js +196 -535
  46. package/dist/witness-cache.d.ts +24 -45
  47. package/dist/witness-cache.js +38 -81
  48. package/dist/witness-lookup.d.ts +36 -57
  49. package/dist/witness-lookup.js +89 -139
  50. package/dist/zip-reader.d.ts +18 -33
  51. package/dist/zip-reader.js +19 -34
  52. package/package.json +11 -3
  53. package/src/agent-record.ts +608 -0
  54. package/src/agent-schemas.generated.ts +5764 -0
  55. package/src/case-file.ts +45 -109
  56. package/src/case.ts +814 -1328
  57. package/src/chain.ts +85 -224
  58. package/src/claims.ts +1253 -0
  59. package/src/cli.ts +714 -1176
  60. package/src/compose.ts +33 -79
  61. package/src/crypto.ts +60 -147
  62. package/src/declaration.ts +219 -656
  63. package/src/environment.ts +17 -65
  64. package/src/evidence.ts +958 -1381
  65. package/src/exit-codes.ts +24 -63
  66. package/src/file-match.ts +40 -89
  67. package/src/grading.ts +287 -421
  68. package/src/handoff.ts +175 -427
  69. package/src/index.ts +131 -177
  70. package/src/json-schema.ts +295 -0
  71. package/src/merkle.ts +16 -28
  72. package/src/message-parts.ts +155 -533
  73. package/src/side-content.ts +25 -68
  74. package/src/types.ts +55 -36
  75. package/src/verifier.ts +202 -526
  76. package/src/witness-cache.ts +45 -94
  77. package/src/witness-lookup.ts +107 -177
  78. package/src/zip-reader.ts +20 -38
  79. package/vectors/README.md +52 -34
  80. package/vectors/agent-record.json +2175 -0
  81. package/vectors/case-file-index.json +1 -1
  82. package/vectors/case-split.json +2 -2
  83. package/vectors/chain-reading.json +3 -3
  84. package/vectors/file-match.json +285 -148
  85. package/vectors/jcs-reader.json +6 -6
  86. package/vectors/pack-grading.json +102 -25
  87. package/vectors/sandbox-evidence.json +573 -581
  88. package/vectors/stamp-on-chain.json +18 -18
  89. package/vectors/witness-cache.json +49 -49
  90. package/dist/agent-proof.d.ts +0 -28
  91. package/dist/agent-proof.js +0 -226
  92. package/dist/run-adapters.d.ts +0 -10
  93. package/dist/run-adapters.js +0 -35
  94. package/dist/run.d.ts +0 -209
  95. package/dist/run.js +0 -1405
  96. package/src/agent-proof.ts +0 -264
  97. package/src/run-adapters.ts +0 -44
  98. package/src/run.ts +0 -1598
@@ -1,20 +1,12 @@
1
- // The environment marker: is this sandbox evidence?
1
+ // The environment marker: whether a pack holds sandbox evidence.
2
2
  //
3
- // `environment` is an OPTIONAL skeleton field inside every envelope's signed
4
- // scope, `"dev"` or `"production"` (envelope-spec §2, A1 and A9). The spec
5
- // says a verifier MAY surface the value as `environment_marker` in its result
6
- // and a profile MAY refuse to count dev-marked envelopes toward production
7
- // evidence. Both commands now do the first, and print a pack or case that
8
- // holds a `dev` envelope as sandbox evidence rather than as `VERIFIED`.
9
- //
10
- // The marker is read from the signed envelopes the pack holds, never from a
11
- // wrapper field, a pack name or anything else the holder could write without a
12
- // key. It never moves the verdict word: a sandbox pack that verifies is still
13
- // `verified`, and the commands map that to the headline `SANDBOX` and exit 5
14
- // (`sandboxExit` in `./exit-codes.ts`). The Python twin is
15
- // `src/sanning_proof/environment.py`.
3
+ // `environment` is an optional field inside every envelope's signed scope,
4
+ // `"dev"` or `"production"` (envelope-spec section 2). It is read from the signed
5
+ // envelopes a pack holds, never from a wrapper field, a pack name or anything
6
+ // else the holder could write without a key. It is a label, never a claim or a
7
+ // verdict: a sandbox pack that verifies is still `verified`, prints the sandbox
8
+ // line, and exits 3 (`exitCodeFor`).
16
9
 
17
- import { isAgentProofSpec } from "./agent-proof.js";
18
10
  import {
19
11
  ANCHOR_TRACE_BODY_TYPE,
20
12
  EXPORT_BODY_TYPE,
@@ -26,16 +18,7 @@ import {
26
18
  /** `"dev"` when every envelope is signed `dev`, `"mixed"` when only some are. */
27
19
  export type EnvironmentMarker = "dev" | "mixed";
28
20
 
29
- /** The headline `verify` prints for sandbox evidence in place of `VERIFIED`. */
30
- export const SANDBOX_HEADLINE = "SANDBOX";
31
-
32
- /** The title `case` prints for sandbox evidence in place of `Verified` (case titles are title case). */
33
- export const SANDBOX_TITLE = "Sandbox";
34
-
35
- /** The one line printed with it, and with any other headline, wherever the marker is present. */
36
- export const SANDBOX_LINE = "Sandbox evidence (environment dev): not production evidence";
37
-
38
- // The same bound `resolveTraceEvents` puts on unwrapping export wrappers.
21
+ // Same bound as `resolveTraceEvents` puts on unwrapping export wrappers.
39
22
  const MAX_EXPORT_UNWRAP = 4;
40
23
 
41
24
  function isObject(v: unknown): v is Record<string, unknown> {
@@ -56,19 +39,12 @@ function entryEnvelopes(list: unknown, out: Record<string, unknown>[]): void {
56
39
  }
57
40
 
58
41
  /**
59
- * The signed envelopes a pack holds: every checkpoint and event envelope of an
60
- * anchor-trace body, every event envelope of a stamp-evidence body, the same
61
- * inside an export's inline source bundle, and an agent proof's checkpoint
62
- * envelope. A stamp-trace body holds none. A value that is not an object is
63
- * not an envelope and is not counted.
42
+ * The signed envelopes a pack holds: checkpoint and event envelopes of an
43
+ * anchor-trace body, event envelopes of a stamp-evidence body (also inside an
44
+ * export's inline source bundle). Non-objects are not counted.
64
45
  */
65
46
  export function packEnvelopes(bundle: unknown): Record<string, unknown>[] {
66
47
  const out: Record<string, unknown>[] = [];
67
- if (isObject(bundle) && isAgentProofSpec(own(bundle, "spec_version"))) {
68
- const env = own(bundle, "checkpoint_envelope");
69
- if (isObject(env)) out.push(env);
70
- return out;
71
- }
72
48
  let cur: unknown = bundle;
73
49
  for (let depth = 0; depth < MAX_EXPORT_UNWRAP; depth++) {
74
50
  if (!isObject(cur)) return out;
@@ -91,10 +67,9 @@ export function packEnvelopes(bundle: unknown): Record<string, unknown>[] {
91
67
  }
92
68
 
93
69
  /**
94
- * The environment marker over one or more packs: `"dev"` where every envelope
95
- * they hold is signed `environment: "dev"`, `"mixed"` where some are and some
96
- * are not (`production`, or no `environment` at all), and `null` where none
97
- * is, which is every production pack and every pack that holds no envelope.
70
+ * The marker over one or more packs: `"dev"` where every envelope is signed
71
+ * `environment: "dev"`, `"mixed"` where only some are, `null` where none is
72
+ * (including a pack that holds no envelope).
98
73
  */
99
74
  export function environmentMarker(bundles: readonly unknown[]): EnvironmentMarker | null {
100
75
  let total = 0;
@@ -110,32 +85,9 @@ export function environmentMarker(bundles: readonly unknown[]): EnvironmentMarke
110
85
  }
111
86
 
112
87
  /**
113
- * Whether a body's only unsettled witnesses are simulated: the body has events
114
- * and witnesses (checkpoints, stamps or both), every witness is named, at
115
- * least one is simulated, and every other one a gateway confirmed. Then the
116
- * one thing that keeps the bundle from `verified` is a simulated witness
117
- * nobody can look up: no mismatch, no unreachable gateway, no witness of
118
- * another kind, no checkpoint or stamp witnessed by nobody.
119
- */
120
- export function onlySimulatedUnsettled(result: EvidenceBundleResult): boolean {
121
- const witnesses = [...result.checkpoints, ...(result.stamps ?? [])];
122
- if (witnesses.length === 0 || result.events.length === 0) return false;
123
- let simulated = 0;
124
- for (const w of witnesses) {
125
- if (w.anchorRef === null) return false;
126
- if (w.anchorRef.kind === SIMULATED_WITNESS_KIND) simulated++;
127
- else if (w.onChain?.rollup !== "confirm") return false;
128
- }
129
- return simulated > 0;
130
- }
131
-
132
- /**
133
- * Whether a run with gateways counted only simulated witnesses, so nothing
134
- * was looked up on a chain: gateways were passed, the run is not counted as
135
- * checked on a chain, and it holds a simulated witness. A run that stopped
136
- * before its witnesses were read (a bad wrapper signature or `body_hash`, an
137
- * unknown `body_type`, an export whose source is not inline) holds none, so it
138
- * is not one, and prints what it printed before simulated witnesses existed.
88
+ * Whether a run with gateways counted only simulated witnesses, so nothing was
89
+ * looked up on a chain. A run that stopped before reading its witnesses holds
90
+ * none and is not one.
139
91
  */
140
92
  export function simulatedOnlyRun(result: EvidenceBundleResult, gateways: readonly string[]): boolean {
141
93
  if (gateways.length === 0 || result.onChainChecked) return false;