@sanning/proof 0.11.1 → 0.13.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 (51) hide show
  1. package/README.md +43 -8
  2. package/dist/agent-proof.d.ts +2 -2
  3. package/dist/agent-proof.js +4 -4
  4. package/dist/case-file.d.ts +126 -0
  5. package/dist/case-file.js +349 -0
  6. package/dist/case.d.ts +199 -43
  7. package/dist/case.js +522 -146
  8. package/dist/cli.d.ts +132 -1
  9. package/dist/cli.js +1140 -96
  10. package/dist/crypto.d.ts +1 -1
  11. package/dist/crypto.js +5 -1
  12. package/dist/declaration.d.ts +58 -52
  13. package/dist/declaration.js +256 -33
  14. package/dist/evidence.d.ts +2 -0
  15. package/dist/evidence.js +134 -19
  16. package/dist/exit-codes.d.ts +17 -0
  17. package/dist/exit-codes.js +50 -0
  18. package/dist/grading.d.ts +28 -13
  19. package/dist/grading.js +90 -31
  20. package/dist/handoff.d.ts +16 -1
  21. package/dist/handoff.js +91 -16
  22. package/dist/index.d.ts +10 -7
  23. package/dist/index.js +15 -7
  24. package/dist/message-parts.d.ts +11 -9
  25. package/dist/message-parts.js +11 -9
  26. package/dist/types.d.ts +1 -0
  27. package/dist/verifier.d.ts +9 -2
  28. package/dist/verifier.js +28 -12
  29. package/dist/zip-reader.d.ts +50 -0
  30. package/dist/zip-reader.js +220 -0
  31. package/package.json +2 -2
  32. package/src/agent-proof.ts +4 -4
  33. package/src/case-file.ts +419 -0
  34. package/src/case.ts +651 -156
  35. package/src/cli.ts +1325 -100
  36. package/src/crypto.ts +5 -1
  37. package/src/declaration.ts +248 -52
  38. package/src/evidence.ts +142 -21
  39. package/src/exit-codes.ts +54 -0
  40. package/src/grading.ts +109 -52
  41. package/src/handoff.ts +108 -17
  42. package/src/index.ts +60 -3
  43. package/src/message-parts.ts +11 -9
  44. package/src/types.ts +5 -0
  45. package/src/verifier.ts +35 -13
  46. package/src/zip-reader.ts +229 -0
  47. package/vectors/README.md +56 -3
  48. package/vectors/case-file-index.json +668 -0
  49. package/vectors/case-split.json +1102 -0
  50. package/vectors/pack-grading.json +68 -4
  51. package/vectors/stamp-on-chain.json +3 -3
package/dist/cli.d.ts CHANGED
@@ -1,8 +1,139 @@
1
1
  #!/usr/bin/env node
2
+ import { type WitnessLine } from "./case.js";
2
3
  interface Cli {
3
4
  out: (s: string) => void;
4
5
  err: (s: string) => void;
5
6
  fetchImpl?: typeof fetch;
6
7
  }
7
- export declare function runCli(argv: string[], io: Cli): Promise<number>;
8
+ /** Each control character in `text` as a visible escape: `\x1b` for ESC,
9
+ * `\u202e` for RIGHT-TO-LEFT OVERRIDE. Every other character is unchanged, a
10
+ * backslash included, so a line with none is printed as it was. */
11
+ export declare function escapeControl(text: string): string;
12
+ export declare function runCli(argv: string[], stream: Cli): Promise<number>;
13
+ /** The error text for an input with no pack in it, word for word the page's. */
14
+ export declare const NO_BUNDLE = "No bundle.json found. An evidence pack contains bundle.json plus logs/.";
15
+ /** A directory nested deeper than this below an argument refuses the input. */
16
+ export declare const MAX_WALK_DEPTH = 32;
17
+ /** More names than this, across every argument, refuse the input. */
18
+ export declare const MAX_WALK_ENTRIES = 50000;
19
+ /**
20
+ * `bundle.json` nested deeper than this is refused before it is parsed, by
21
+ * `verify` and by `case` alike (see `readBundleBytes`).
22
+ */
23
+ export declare const MAX_JSON_DEPTH = 512;
24
+ /**
25
+ * The input could not be read as a case. The message is the whole report,
26
+ * identical in both kernels, and the command exits 2 on it. `hint` is an
27
+ * optional second line naming a way through.
28
+ */
29
+ export declare class CaseInputError extends Error {
30
+ readonly hint: string | null;
31
+ constructor(message: string, hint?: string | null);
32
+ }
33
+ /**
34
+ * `bundle.json` bytes that `readBundleBytes` will not read. `tooDeep` separates
35
+ * the one refusal that is not a parse error; `detail` is the parser's own words,
36
+ * which differ by kernel and are printed by `verify` only.
37
+ */
38
+ export declare class BundleReadError extends Error {
39
+ readonly tooDeep: boolean;
40
+ readonly detail: string;
41
+ constructor(tooDeep: boolean, detail: string);
42
+ }
43
+ /**
44
+ * How both `verify` and `case` turn `bundle.json` bytes into JSON, in both
45
+ * kernels (`read_bundle_bytes` in the Python twin). UTF-8 with each ill-formed
46
+ * sequence read as U+FFFD, and a byte-order mark kept; then nesting deeper than
47
+ * MAX_JSON_DEPTH is refused before any parser walks into it; then `JSON.parse`.
48
+ * Throws `BundleReadError`.
49
+ */
50
+ export declare function readBundleBytes(bytes: Uint8Array): unknown;
51
+ export interface SplitPack {
52
+ ref: string;
53
+ bundlePath: string;
54
+ bundleBytes: Uint8Array;
55
+ /**
56
+ * `logs/<event_id>.json` bytes by event id. A `Map` and not an object: an
57
+ * event id is written by the audited party, and `obj["__proto__"] = bytes`
58
+ * replaces the prototype instead of storing the disclosure.
59
+ */
60
+ content: Map<string, Uint8Array>;
61
+ unaccounted: string[];
62
+ }
63
+ export interface SplitCase {
64
+ packs: SplitPack[];
65
+ /** Paths that belong to no pack, sorted. Never opened. */
66
+ outside: string[];
67
+ /** The part of `outside` that is not a regular file. Never followed, never opened. */
68
+ notRegular: string[];
69
+ }
70
+ /** One name the walk found that is not a directory. */
71
+ export interface TreeEntry {
72
+ /** Where it sits on disk. Empty for an entry read out of a case-file `.zip`. */
73
+ fsPath: string;
74
+ /**
75
+ * `true` for a regular file; `false` for a link or anything else, including a
76
+ * `.zip` entry the reader refused.
77
+ */
78
+ regular: boolean;
79
+ /** The bytes of an entry read out of a case-file `.zip`. */
80
+ data?: Uint8Array | null;
81
+ }
82
+ /**
83
+ * The page's `splitCase` followed by its `assemble` per pack, over the walk's
84
+ * tree. `read` opens a file; it is called for the files a pack owns and for
85
+ * nothing else.
86
+ */
87
+ export declare function splitCase(tree: Map<string, TreeEntry>, read: (entry: TreeEntry, key: string) => Promise<Uint8Array>): Promise<SplitCase>;
88
+ /** `verify`'s reader, with the refusal named by the pack's path. */
89
+ export declare function loadBundle(pack: SplitPack): unknown;
90
+ /**
91
+ * A regular file's bytes. Opened without following a link and without
92
+ * blocking, then checked again, so a file swapped for a link or a pipe after
93
+ * the walk listed it is refused rather than followed or waited on.
94
+ */
95
+ export declare function readFileEntry(entry: TreeEntry, key: string): Promise<Uint8Array>;
96
+ /**
97
+ * Every name under the directories named, keyed `<name>/<path inside>`. Each
98
+ * argument must be a directory, and not a link to one. A `.zip` is refused
99
+ * with the way through.
100
+ */
101
+ export declare function treeFromArguments(paths: readonly string[]): Promise<Map<string, TreeEntry>>;
102
+ export declare const CASE_USAGE: string;
103
+ interface OnChainRow {
104
+ ref: string;
105
+ witnesses: number;
106
+ confirmed: number;
107
+ mismatched: number;
108
+ unreachable: number;
109
+ not_checked: number;
110
+ }
111
+ interface OnChainHalf {
112
+ /** Present only where a lookup ran: each gateway that answered, in the order given. */
113
+ answered?: string[];
114
+ checked: boolean;
115
+ gateways: string[];
116
+ packs: OnChainRow[];
117
+ verdict: "not_checked" | "confirmed" | "failed" | "undetermined";
118
+ }
119
+ /**
120
+ * The witness line (evidence-bundle 5.5.6 v1.20, A24, D7) from the on-chain
121
+ * half: `confirmed` is `confirmed`, `not_checked` and `undetermined` are
122
+ * `not_checked` with the reason, and `failed` is `differs`. It never moves the
123
+ * headline.
124
+ */
125
+ export declare function witnessLine(onChain: OnChainHalf): WitnessLine;
126
+ /**
127
+ * The case verdict's code, moved only by an on-chain half that was asked for:
128
+ * a witness that does not match is a failure whatever the reading said, and an
129
+ * on-chain half that could not be settled is never a clean 0.
130
+ */
131
+ export declare function caseExitCode(verdict: string, onChainVerdict: string): number;
132
+ /**
133
+ * `proof case <folder>... [--gateways <urls>] [--json]`. Every path out of the
134
+ * command is an exit code from the table: an exception nobody expected exits 2,
135
+ * never 1, because 1 would name the evidence failed over a defect in this
136
+ * command.
137
+ */
138
+ export declare function runCase(argv: readonly string[], stream: Cli): Promise<number>;
8
139
  export {};