@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.
- package/README.md +30 -29
- package/dist/agent-record.d.ts +62 -0
- package/dist/agent-record.js +527 -0
- package/dist/agent-schemas.generated.d.ts +15 -0
- package/dist/agent-schemas.generated.js +5759 -0
- package/dist/case-file.d.ts +32 -89
- package/dist/case-file.js +41 -93
- package/dist/case.d.ts +339 -822
- package/dist/case.js +667 -1160
- package/dist/chain.d.ts +19 -47
- package/dist/chain.js +78 -205
- package/dist/claims.d.ts +211 -0
- package/dist/claims.js +1081 -0
- package/dist/cli.d.ts +45 -68
- package/dist/cli.js +618 -1022
- package/dist/compose.js +23 -65
- package/dist/crypto.d.ts +7 -8
- package/dist/crypto.js +60 -147
- package/dist/declaration.d.ts +68 -194
- package/dist/declaration.js +175 -518
- package/dist/environment.d.ts +9 -30
- package/dist/environment.js +17 -66
- package/dist/evidence.d.ts +119 -160
- package/dist/evidence.js +744 -1103
- package/dist/exit-codes.d.ts +11 -27
- package/dist/exit-codes.js +24 -59
- package/dist/file-match.d.ts +33 -79
- package/dist/file-match.js +33 -69
- package/dist/grading.d.ts +98 -135
- package/dist/grading.js +224 -380
- package/dist/handoff.d.ts +62 -160
- package/dist/handoff.js +153 -393
- package/dist/index.d.ts +14 -10
- package/dist/index.js +60 -167
- package/dist/json-schema.d.ts +29 -0
- package/dist/json-schema.js +298 -0
- package/dist/merkle.js +16 -28
- package/dist/message-parts.d.ts +56 -212
- package/dist/message-parts.js +142 -502
- package/dist/side-content.d.ts +11 -22
- package/dist/side-content.js +22 -65
- package/dist/types.d.ts +17 -0
- package/dist/types.js +19 -5
- package/dist/verifier.d.ts +40 -114
- package/dist/verifier.js +196 -535
- package/dist/witness-cache.d.ts +24 -45
- package/dist/witness-cache.js +38 -81
- package/dist/witness-lookup.d.ts +36 -57
- package/dist/witness-lookup.js +89 -139
- package/dist/zip-reader.d.ts +18 -33
- package/dist/zip-reader.js +19 -34
- package/package.json +11 -3
- package/src/agent-record.ts +608 -0
- package/src/agent-schemas.generated.ts +5764 -0
- package/src/case-file.ts +45 -109
- package/src/case.ts +814 -1328
- package/src/chain.ts +85 -224
- package/src/claims.ts +1253 -0
- package/src/cli.ts +714 -1176
- package/src/compose.ts +33 -79
- package/src/crypto.ts +60 -147
- package/src/declaration.ts +219 -656
- package/src/environment.ts +17 -65
- package/src/evidence.ts +958 -1381
- package/src/exit-codes.ts +24 -63
- package/src/file-match.ts +40 -89
- package/src/grading.ts +287 -421
- package/src/handoff.ts +175 -427
- package/src/index.ts +131 -177
- package/src/json-schema.ts +295 -0
- package/src/merkle.ts +16 -28
- package/src/message-parts.ts +155 -533
- package/src/side-content.ts +25 -68
- package/src/types.ts +55 -36
- package/src/verifier.ts +202 -526
- package/src/witness-cache.ts +45 -94
- package/src/witness-lookup.ts +107 -177
- package/src/zip-reader.ts +20 -38
- package/vectors/README.md +52 -34
- package/vectors/agent-record.json +2175 -0
- package/vectors/case-file-index.json +1 -1
- package/vectors/case-split.json +2 -2
- package/vectors/chain-reading.json +3 -3
- package/vectors/file-match.json +285 -148
- package/vectors/jcs-reader.json +6 -6
- package/vectors/pack-grading.json +102 -25
- package/vectors/sandbox-evidence.json +573 -581
- package/vectors/stamp-on-chain.json +18 -18
- package/vectors/witness-cache.json +49 -49
- package/dist/agent-proof.d.ts +0 -28
- package/dist/agent-proof.js +0 -226
- package/dist/run-adapters.d.ts +0 -10
- package/dist/run-adapters.js +0 -35
- package/dist/run.d.ts +0 -209
- package/dist/run.js +0 -1405
- package/src/agent-proof.ts +0 -264
- package/src/run-adapters.ts +0 -44
- package/src/run.ts +0 -1598
package/dist/exit-codes.d.ts
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
export declare const EXIT_VERIFIED = 0;
|
|
2
2
|
export declare const EXIT_FAILED = 1;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const EXIT_UNDETERMINED = 3;
|
|
5
|
-
export declare const EXIT_MIXED = 4;
|
|
3
|
+
export declare const EXIT_INCOMPLETE = 2;
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* that are ALL signed `dev` whose only unsettled witnesses are simulated.
|
|
10
|
-
* Not a verdict word: the verdict stays what the checks established
|
|
11
|
-
* (`sandboxExit`). No flag turns 5 into 0.
|
|
12
|
-
*/
|
|
13
|
-
export declare const EXIT_SANDBOX = 5;
|
|
14
|
-
/**
|
|
15
|
-
* The exit code of each of the eight verdict words (`evidence-bundle.md` §3).
|
|
16
|
-
* `undetermined` is the name of 3, and never a word here.
|
|
5
|
+
* Not a verdict: the verdict is `verified` and a record is signed `environment: "dev"`
|
|
6
|
+
* (envelope-spec section 2). A failed or incomplete sandbox run keeps 1 or 2.
|
|
17
7
|
*/
|
|
8
|
+
export declare const EXIT_SANDBOX = 3;
|
|
9
|
+
/** A bad flag, a missing file, or an input that is not a pack or a case at all. */
|
|
10
|
+
export declare const EXIT_COULD_NOT_RUN = 4;
|
|
11
|
+
/** The exit code of each verdict (`evidence-bundle.md` section 3). */
|
|
18
12
|
export declare const EXIT_CODES: Readonly<Record<string, number>>;
|
|
19
|
-
/** What every verb's help prints
|
|
13
|
+
/** What every verb's help prints. */
|
|
20
14
|
export declare const EXIT_CODES_HELP: string;
|
|
21
15
|
/**
|
|
22
|
-
* The exit code of a verdict
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export declare function exitCodeFor(verdict: unknown): number;
|
|
26
|
-
/**
|
|
27
|
-
* The code a verb exits with once the environment marker is read. 5 where the
|
|
28
|
-
* run would otherwise exit 0 and the pack or case holds a record signed `dev`;
|
|
29
|
-
* 5 where the run is undetermined only because a simulated witness could not
|
|
30
|
-
* be looked up (`onlySimulatedUnsettled`, which the caller works out) and
|
|
31
|
-
* EVERY record is signed `dev`, so a production or mixed pack carrying a
|
|
32
|
-
* simulated witness keeps 3; the code unchanged everywhere else. A failure
|
|
33
|
-
* stays 1, malformed 2 and mixed 4.
|
|
16
|
+
* The exit code of a verdict. `verified` over a record signed `dev` is 3. A value outside
|
|
17
|
+
* the three verdicts is 4, never 0.
|
|
34
18
|
*/
|
|
35
|
-
export declare function
|
|
19
|
+
export declare function exitCodeFor(verdict: unknown, environmentMarker?: string | null): number;
|
package/dist/exit-codes.js
CHANGED
|
@@ -1,75 +1,40 @@
|
|
|
1
|
-
// One exit-code table for every verb (
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// an exit code through this one table, for `verify`, `case` and `export` alike,
|
|
5
|
-
// and every verb's `--help` prints `EXIT_CODES_HELP` byte for byte. The twin is
|
|
6
|
-
// `src/sanning_proof/exit_codes.py`; the specification is `evidence-export.md`
|
|
7
|
-
// §5.
|
|
8
|
-
//
|
|
9
|
-
// Until 0.13.0 `verify` exited 0 on `partial` unless a gateway was unreachable,
|
|
10
|
-
// while `case` exited 3 on it, so a CI gate reading `verify`'s exit code read a
|
|
11
|
-
// stamp witnessed by nobody as verified. Every word that means "could not be
|
|
12
|
-
// settled" now exits 3, which is the code's name: undetermined.
|
|
1
|
+
// One exit-code table for every verb (`verify`, `case`, `export`), shared by both
|
|
2
|
+
// commands. Every verb's `--help` prints `EXIT_CODES_HELP` byte for byte
|
|
3
|
+
// (evidence-export.md section 5).
|
|
13
4
|
export const EXIT_VERIFIED = 0;
|
|
14
5
|
export const EXIT_FAILED = 1;
|
|
15
|
-
export const
|
|
16
|
-
export const EXIT_UNDETERMINED = 3;
|
|
17
|
-
export const EXIT_MIXED = 4;
|
|
6
|
+
export const EXIT_INCOMPLETE = 2;
|
|
18
7
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* that are ALL signed `dev` whose only unsettled witnesses are simulated.
|
|
22
|
-
* Not a verdict word: the verdict stays what the checks established
|
|
23
|
-
* (`sandboxExit`). No flag turns 5 into 0.
|
|
24
|
-
*/
|
|
25
|
-
export const EXIT_SANDBOX = 5;
|
|
26
|
-
/**
|
|
27
|
-
* The exit code of each of the eight verdict words (`evidence-bundle.md` §3).
|
|
28
|
-
* `undetermined` is the name of 3, and never a word here.
|
|
8
|
+
* Not a verdict: the verdict is `verified` and a record is signed `environment: "dev"`
|
|
9
|
+
* (envelope-spec section 2). A failed or incomplete sandbox run keeps 1 or 2.
|
|
29
10
|
*/
|
|
11
|
+
export const EXIT_SANDBOX = 3;
|
|
12
|
+
/** A bad flag, a missing file, or an input that is not a pack or a case at all. */
|
|
13
|
+
export const EXIT_COULD_NOT_RUN = 4;
|
|
14
|
+
/** The exit code of each verdict (`evidence-bundle.md` section 3). */
|
|
30
15
|
export const EXIT_CODES = Object.freeze({
|
|
31
16
|
verified: EXIT_VERIFIED,
|
|
32
17
|
failed: EXIT_FAILED,
|
|
33
|
-
|
|
34
|
-
partial: EXIT_UNDETERMINED,
|
|
35
|
-
pending: EXIT_UNDETERMINED,
|
|
36
|
-
incomplete: EXIT_UNDETERMINED,
|
|
37
|
-
not_found: EXIT_UNDETERMINED,
|
|
38
|
-
mixed: EXIT_MIXED,
|
|
18
|
+
incomplete: EXIT_INCOMPLETE,
|
|
39
19
|
});
|
|
40
|
-
/** What every verb's help prints
|
|
20
|
+
/** What every verb's help prints. */
|
|
41
21
|
export const EXIT_CODES_HELP = [
|
|
42
22
|
"Exit codes, one table for every verb:",
|
|
43
|
-
" 0 verified
|
|
44
|
-
" 1 failed",
|
|
45
|
-
" 2
|
|
46
|
-
" 3
|
|
47
|
-
" 4
|
|
48
|
-
" 5 sandbox: a record is signed environment dev; would be 0, or only a simulated witness is unchecked",
|
|
23
|
+
" 0 verified: every claim in scope is proven; export: the export was written",
|
|
24
|
+
" 1 failed: a claim is disproven",
|
|
25
|
+
" 2 incomplete: nothing is disproven and a claim is not proven",
|
|
26
|
+
" 3 sandbox: verified, and a record is signed environment dev",
|
|
27
|
+
" 4 could not run: a bad flag, a missing file, or an input that is not a pack or case",
|
|
49
28
|
].join("\n");
|
|
50
29
|
/**
|
|
51
|
-
* The exit code of a verdict
|
|
52
|
-
*
|
|
30
|
+
* The exit code of a verdict. `verified` over a record signed `dev` is 3. A value outside
|
|
31
|
+
* the three verdicts is 4, never 0.
|
|
53
32
|
*/
|
|
54
|
-
export function exitCodeFor(verdict) {
|
|
55
|
-
if (typeof verdict
|
|
56
|
-
return
|
|
33
|
+
export function exitCodeFor(verdict, environmentMarker = null) {
|
|
34
|
+
if (typeof verdict !== "string" || !Object.prototype.hasOwnProperty.call(EXIT_CODES, verdict)) {
|
|
35
|
+
return EXIT_COULD_NOT_RUN;
|
|
57
36
|
}
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The code a verb exits with once the environment marker is read. 5 where the
|
|
62
|
-
* run would otherwise exit 0 and the pack or case holds a record signed `dev`;
|
|
63
|
-
* 5 where the run is undetermined only because a simulated witness could not
|
|
64
|
-
* be looked up (`onlySimulatedUnsettled`, which the caller works out) and
|
|
65
|
-
* EVERY record is signed `dev`, so a production or mixed pack carrying a
|
|
66
|
-
* simulated witness keeps 3; the code unchanged everywhere else. A failure
|
|
67
|
-
* stays 1, malformed 2 and mixed 4.
|
|
68
|
-
*/
|
|
69
|
-
export function sandboxExit(code, environmentMarker, onlySimulatedUnsettled = false) {
|
|
70
|
-
if (code === EXIT_VERIFIED && environmentMarker !== null)
|
|
71
|
-
return EXIT_SANDBOX;
|
|
72
|
-
if (code === EXIT_UNDETERMINED && environmentMarker === "dev" && onlySimulatedUnsettled)
|
|
37
|
+
if (verdict === "verified" && environmentMarker !== null)
|
|
73
38
|
return EXIT_SANDBOX;
|
|
74
|
-
return
|
|
39
|
+
return EXIT_CODES[verdict];
|
|
75
40
|
}
|
package/dist/file-match.d.ts
CHANGED
|
@@ -1,56 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Matches files handed in beside a pack against the commitments its signed
|
|
3
|
+
* records make (evidence-bundle.md §5.7). Conformance: `vectors/file-match.json`.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* - Matching is by SHA-256 of the exact bytes only. A file's name is a label
|
|
6
|
+
* and is never compared with an `event_id`, a part name or a path.
|
|
7
|
+
* - Unmatched is reported, never guessed.
|
|
8
|
+
* - Only what a record's own key signed counts: a verified envelope whose
|
|
9
|
+
* `event_bytes` bind to its `payload_hash`, or a hand-off message whose bytes
|
|
10
|
+
* bind to that record's `message_hash`. No wrapper field is read.
|
|
11
|
+
* - The verdict does not move (`FILE_MATCH_SCOPE`).
|
|
8
12
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* commits to (naming the record, its signer and its `signed_at`), which match
|
|
15
|
-
* no record, and which commitments had no file offered.
|
|
16
|
-
*
|
|
17
|
-
* THE RULES THAT CARRY THE WEIGHT:
|
|
18
|
-
*
|
|
19
|
-
* - By hash, and by nothing else. A file's name is carried through as the
|
|
20
|
-
* caller's label and is never compared with an `event_id`, a part's name or
|
|
21
|
-
* a `logs/` path. There is no layout convention.
|
|
22
|
-
* - Unmatched is reported, never guessed.
|
|
23
|
-
* - Only what a record's own key signed: a verified envelope whose
|
|
24
|
-
* `event_bytes` bind to its `payload_hash`, or a hand-off message whose
|
|
25
|
-
* bytes bind to that record's `message_hash`. No wrapper field is read.
|
|
26
|
-
* - The verdict does not move. A match proves that a signed record in the
|
|
27
|
-
* pack committed to those exact bytes, and nothing more (`FILE_MATCH_SCOPE`).
|
|
28
|
-
*
|
|
29
|
-
* WHAT COUNTS AS A COMMITMENT, in record order and then part order:
|
|
30
|
-
*
|
|
31
|
-
* 1. `record`: a record outside envelope-spec.md 4.1 commits through
|
|
32
|
-
* `event.content_hash`, 64 hex characters in either case.
|
|
33
|
-
* 2. `file_part`: a record 4.1 governs commits to its MESSAGE through
|
|
34
|
-
* `event.message_hash` (5.1, A20), never through a `content_hash` it also
|
|
35
|
-
* writes. Where the message's JCS bytes are in hand (in the body, or in
|
|
36
|
-
* the side content) and bind to it, each file part of that message (A18)
|
|
37
|
-
* commits by its `content_hash`.
|
|
38
|
-
*
|
|
39
|
-
* Side content is read for ONE thing, to find a hand-off message that binds to
|
|
40
|
-
* a signed `message_hash`. It is never an offered file.
|
|
41
|
-
*
|
|
42
|
-
* Pure: a bundle, the files and the optional side content in, a reading out.
|
|
13
|
+
* A record outside envelope-spec.md §4.1 commits through `event.content_hash`.
|
|
14
|
+
* A hand-off record commits to its message through `event.message_hash`, and,
|
|
15
|
+
* where the message bytes are in hand and bind, each file part of that message
|
|
16
|
+
* commits by its `content_hash`. Side content is read only to find such a
|
|
17
|
+
* message; it is never an offered file.
|
|
43
18
|
*/
|
|
44
19
|
import type { SideContentMap } from "./side-content.js";
|
|
45
|
-
/** The
|
|
20
|
+
/** The scope sentence every surface prints with the reading (§5.7). */
|
|
46
21
|
export declare const FILE_MATCH_SCOPE: string;
|
|
47
22
|
/** Why a record's commitments could not be read, in the order they are tested. */
|
|
48
23
|
export declare const NOT_READ_REASONS: readonly ["no_records", "record_unreadable", "record_not_verified", "record_withheld", "no_content_hash", "handoff_record_malformed", "message_withheld"];
|
|
49
24
|
export type NotReadReason = (typeof NOT_READ_REASONS)[number];
|
|
50
25
|
/**
|
|
51
|
-
* Why a file was
|
|
52
|
-
*
|
|
53
|
-
* skipped, so "no match" is never read as "no file was there".
|
|
26
|
+
* Why a found file was not hashed (§5.7.5). A skipped file is listed, never
|
|
27
|
+
* dropped, so "no match" is never read as "no file was there".
|
|
54
28
|
*/
|
|
55
29
|
export declare const SKIPPED_REASONS: readonly ["symbolic_link", "not_regular", "unreadable", "too_large", "refused"];
|
|
56
30
|
export type SkippedReason = (typeof SKIPPED_REASONS)[number];
|
|
@@ -63,13 +37,9 @@ export interface FileCommitment {
|
|
|
63
37
|
contentHash: string;
|
|
64
38
|
signer: string;
|
|
65
39
|
signedAt: string | null;
|
|
66
|
-
/**
|
|
67
|
-
* The pack, by its position in the packs `matchCaseFiles` was handed (the
|
|
68
|
-
* same position the case reading's `packIndex` names), or `null` from
|
|
69
|
-
* `matchFiles`, which reads one pack (A43).
|
|
70
|
-
*/
|
|
40
|
+
/** Position in the packs `matchCaseFiles` was handed, or `null` from `matchFiles`. */
|
|
71
41
|
packIndex: number | null;
|
|
72
|
-
/**
|
|
42
|
+
/** Position in the events the pack presents. */
|
|
73
43
|
recordIndex: number;
|
|
74
44
|
}
|
|
75
45
|
export interface MatchedFile {
|
|
@@ -85,19 +55,15 @@ export interface UnmatchedFile {
|
|
|
85
55
|
export interface SkippedFile {
|
|
86
56
|
name: string;
|
|
87
57
|
reason: SkippedReason;
|
|
88
|
-
/** The reader's own words, for a `.zip` entry
|
|
58
|
+
/** The reader's own words, for a refused `.zip` entry. */
|
|
89
59
|
detail?: string;
|
|
90
60
|
}
|
|
91
61
|
export interface NotRead {
|
|
92
62
|
packRef: string | null;
|
|
93
63
|
eventId: string | null;
|
|
94
64
|
reason: NotReadReason;
|
|
95
|
-
/** As on `FileCommitment` (A43). */
|
|
96
65
|
packIndex: number | null;
|
|
97
|
-
/**
|
|
98
|
-
* As on `FileCommitment`, or `null` where the pack presents no events at all
|
|
99
|
-
* (`no_records`).
|
|
100
|
-
*/
|
|
66
|
+
/** `null` where the pack presents no events (`no_records`). */
|
|
101
67
|
recordIndex: number | null;
|
|
102
68
|
}
|
|
103
69
|
export interface FileMatchReading {
|
|
@@ -107,17 +73,12 @@ export interface FileMatchReading {
|
|
|
107
73
|
notOffered: FileCommitment[];
|
|
108
74
|
notRead: NotRead[];
|
|
109
75
|
scope: string;
|
|
110
|
-
/**
|
|
111
|
-
* Files found and not hashed. The matching functions leave it empty: it is
|
|
112
|
-
* the caller's, because only a caller that reads a folder knows a link.
|
|
113
|
-
*/
|
|
76
|
+
/** Files found and not hashed. Filled by the caller, which alone reads folders. */
|
|
114
77
|
skipped?: SkippedFile[];
|
|
115
78
|
}
|
|
116
79
|
/**
|
|
117
|
-
* A file handed in beside a pack. `name` is a label
|
|
118
|
-
*
|
|
119
|
-
* caller has already hashed it: a command streams a file of any size rather
|
|
120
|
-
* than hold it.
|
|
80
|
+
* A file handed in beside a pack. `name` is a label, never compared. Give
|
|
81
|
+
* `bytes`, or `sha256` (64 lowercase hex) when the caller streamed the file.
|
|
121
82
|
*/
|
|
122
83
|
export type OfferedFile = {
|
|
123
84
|
name: string;
|
|
@@ -135,30 +96,23 @@ export interface FileMatchPack {
|
|
|
135
96
|
content?: SideContentMap | null;
|
|
136
97
|
}
|
|
137
98
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* find a hand-off message that binds to its record's `message_hash`; it is
|
|
141
|
-
* never an offered file.
|
|
99
|
+
* Matches each offered file against one pack's signed commitments. `content`
|
|
100
|
+
* is the pack's side content, read only to bind hand-off messages.
|
|
142
101
|
*/
|
|
143
102
|
export declare function matchFiles(bundle: unknown, files: readonly OfferedFile[], content?: SideContentMap | null): Promise<FileMatchReading>;
|
|
144
|
-
/**
|
|
103
|
+
/** `matchFiles` over every pack of a case. */
|
|
145
104
|
export declare function matchCaseFiles(packs: readonly FileMatchPack[], files: readonly OfferedFile[]): Promise<FileMatchReading>;
|
|
146
|
-
/** The reading as the `files` member of `--json
|
|
105
|
+
/** The reading as the `files` member of `--json`. */
|
|
147
106
|
export declare function fileMatchToJson(reading: FileMatchReading): Record<string, unknown>;
|
|
148
107
|
/**
|
|
149
108
|
* The commitments no offered file matched and no disclosed log answers.
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* and is not returned. Only the text report's count reads this; the reading, and
|
|
154
|
-
* `--json`, still list every commitment no file matched.
|
|
109
|
+
* A record whose own pack discloses bytes hashing to its `content_hash` is
|
|
110
|
+
* accounted for. Only the text report's count reads this; `--json` still lists
|
|
111
|
+
* every unmatched commitment.
|
|
155
112
|
*/
|
|
156
113
|
export declare function notAccountedFor(reading: FileMatchReading, contents: ReadonlyMap<string, SideContentMap | null | undefined>): Promise<FileCommitment[]>;
|
|
157
114
|
/**
|
|
158
|
-
* The text report's lines for the reading
|
|
159
|
-
*
|
|
160
|
-
* By default every commitment no file matched is a line. `notAmong` is the case
|
|
161
|
-
* command's report when no `--files` was given: one count line for the recorded
|
|
162
|
-
* files no loose file matched, and no line for each (A41).
|
|
115
|
+
* The text report's lines for the reading. With `notAmong` (the case command
|
|
116
|
+
* with no `--files`), unmatched commitments collapse to one count line.
|
|
163
117
|
*/
|
|
164
118
|
export declare function renderFileMatch(reading: FileMatchReading, notAmong?: number): string[];
|
package/dist/file-match.js
CHANGED
|
@@ -1,45 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Matches files handed in beside a pack against the commitments its signed
|
|
3
|
+
* records make (evidence-bundle.md §5.7). Conformance: `vectors/file-match.json`.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* - Matching is by SHA-256 of the exact bytes only. A file's name is a label
|
|
6
|
+
* and is never compared with an `event_id`, a part name or a path.
|
|
7
|
+
* - Unmatched is reported, never guessed.
|
|
8
|
+
* - Only what a record's own key signed counts: a verified envelope whose
|
|
9
|
+
* `event_bytes` bind to its `payload_hash`, or a hand-off message whose bytes
|
|
10
|
+
* bind to that record's `message_hash`. No wrapper field is read.
|
|
11
|
+
* - The verdict does not move (`FILE_MATCH_SCOPE`).
|
|
8
12
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* commits to (naming the record, its signer and its `signed_at`), which match
|
|
15
|
-
* no record, and which commitments had no file offered.
|
|
16
|
-
*
|
|
17
|
-
* THE RULES THAT CARRY THE WEIGHT:
|
|
18
|
-
*
|
|
19
|
-
* - By hash, and by nothing else. A file's name is carried through as the
|
|
20
|
-
* caller's label and is never compared with an `event_id`, a part's name or
|
|
21
|
-
* a `logs/` path. There is no layout convention.
|
|
22
|
-
* - Unmatched is reported, never guessed.
|
|
23
|
-
* - Only what a record's own key signed: a verified envelope whose
|
|
24
|
-
* `event_bytes` bind to its `payload_hash`, or a hand-off message whose
|
|
25
|
-
* bytes bind to that record's `message_hash`. No wrapper field is read.
|
|
26
|
-
* - The verdict does not move. A match proves that a signed record in the
|
|
27
|
-
* pack committed to those exact bytes, and nothing more (`FILE_MATCH_SCOPE`).
|
|
28
|
-
*
|
|
29
|
-
* WHAT COUNTS AS A COMMITMENT, in record order and then part order:
|
|
30
|
-
*
|
|
31
|
-
* 1. `record`: a record outside envelope-spec.md 4.1 commits through
|
|
32
|
-
* `event.content_hash`, 64 hex characters in either case.
|
|
33
|
-
* 2. `file_part`: a record 4.1 governs commits to its MESSAGE through
|
|
34
|
-
* `event.message_hash` (5.1, A20), never through a `content_hash` it also
|
|
35
|
-
* writes. Where the message's JCS bytes are in hand (in the body, or in
|
|
36
|
-
* the side content) and bind to it, each file part of that message (A18)
|
|
37
|
-
* commits by its `content_hash`.
|
|
38
|
-
*
|
|
39
|
-
* Side content is read for ONE thing, to find a hand-off message that binds to
|
|
40
|
-
* a signed `message_hash`. It is never an offered file.
|
|
41
|
-
*
|
|
42
|
-
* Pure: a bundle, the files and the optional side content in, a reading out.
|
|
13
|
+
* A record outside envelope-spec.md §4.1 commits through `event.content_hash`.
|
|
14
|
+
* A hand-off record commits to its message through `event.message_hash`, and,
|
|
15
|
+
* where the message bytes are in hand and bind, each file part of that message
|
|
16
|
+
* commits by its `content_hash`. Side content is read only to find such a
|
|
17
|
+
* message; it is never an offered file.
|
|
43
18
|
*/
|
|
44
19
|
import { hexToBytes, isHexField, sha256Hex } from "./crypto.js";
|
|
45
20
|
import { resolveTraceEvents } from "./evidence.js";
|
|
@@ -47,7 +22,7 @@ import { isConformantHandoffRecord, isHandoffNamespace } from "./handoff.js";
|
|
|
47
22
|
import { isFilePart } from "./message-parts.js";
|
|
48
23
|
import { sideContentEntry } from "./side-content.js";
|
|
49
24
|
import { jcsParse, verifyEnvelope } from "./verifier.js";
|
|
50
|
-
/** The
|
|
25
|
+
/** The scope sentence every surface prints with the reading (§5.7). */
|
|
51
26
|
export const FILE_MATCH_SCOPE = "A match proves that a signed record in the pack committed to these exact " +
|
|
52
27
|
"bytes, and nothing more.";
|
|
53
28
|
/** Why a record's commitments could not be read, in the order they are tested. */
|
|
@@ -61,9 +36,8 @@ export const NOT_READ_REASONS = [
|
|
|
61
36
|
"message_withheld",
|
|
62
37
|
];
|
|
63
38
|
/**
|
|
64
|
-
* Why a file was
|
|
65
|
-
*
|
|
66
|
-
* skipped, so "no match" is never read as "no file was there".
|
|
39
|
+
* Why a found file was not hashed (§5.7.5). A skipped file is listed, never
|
|
40
|
+
* dropped, so "no match" is never read as "no file was there".
|
|
67
41
|
*/
|
|
68
42
|
export const SKIPPED_REASONS = [
|
|
69
43
|
"symbolic_link",
|
|
@@ -77,7 +51,6 @@ const SKIPPED_TEXT = {
|
|
|
77
51
|
not_regular: "not a regular file: not read",
|
|
78
52
|
unreadable: "could not be read",
|
|
79
53
|
too_large: "past the 1 GiB read from folders in one run: not read",
|
|
80
|
-
// Followed by the reader's own words, `renderSkipped`.
|
|
81
54
|
refused: "a .zip entry the reader refused",
|
|
82
55
|
};
|
|
83
56
|
const REASON_TEXT = {
|
|
@@ -89,9 +62,8 @@ const REASON_TEXT = {
|
|
|
89
62
|
handoff_record_malformed: "it is a hand-off record that commits to no message a reader can bind to",
|
|
90
63
|
message_withheld: "its message is not in hand, so its file parts cannot be read",
|
|
91
64
|
};
|
|
92
|
-
// The
|
|
93
|
-
|
|
94
|
-
const RECORD_PROFILES = ["sanning.agent/v1", "sanning.events/v2"];
|
|
65
|
+
// The accepted profiles minus the quarantined `sanning.mlflow/v1`.
|
|
66
|
+
const RECORD_PROFILES = ["sanning.events/v2"];
|
|
95
67
|
function isObject(v) {
|
|
96
68
|
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
97
69
|
}
|
|
@@ -101,8 +73,8 @@ function strOrNull(v) {
|
|
|
101
73
|
function own(o, key) {
|
|
102
74
|
return Object.prototype.hasOwnProperty.call(o, key) ? o[key] : undefined;
|
|
103
75
|
}
|
|
104
|
-
// The
|
|
105
|
-
//
|
|
76
|
+
// The key and signature must be hex at their lengths, as every body verifier
|
|
77
|
+
// requires inside a bundle.
|
|
106
78
|
function envelopeSpelled(envelope) {
|
|
107
79
|
for (const [name, nibbles] of [
|
|
108
80
|
["public_key", 64],
|
|
@@ -255,8 +227,8 @@ async function readPack(bundle, content, packRef, packIndex) {
|
|
|
255
227
|
}
|
|
256
228
|
return { commitments, notRead };
|
|
257
229
|
}
|
|
258
|
-
// A malformed
|
|
259
|
-
//
|
|
230
|
+
// A malformed entry is the caller's mistake, not the evidence's, so it throws
|
|
231
|
+
// rather than reading as an unmatched file.
|
|
260
232
|
async function offeredDigests(files) {
|
|
261
233
|
const out = [];
|
|
262
234
|
for (const entry of files) {
|
|
@@ -310,16 +282,14 @@ async function match(commitments, notRead, files) {
|
|
|
310
282
|
};
|
|
311
283
|
}
|
|
312
284
|
/**
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* find a hand-off message that binds to its record's `message_hash`; it is
|
|
316
|
-
* never an offered file.
|
|
285
|
+
* Matches each offered file against one pack's signed commitments. `content`
|
|
286
|
+
* is the pack's side content, read only to bind hand-off messages.
|
|
317
287
|
*/
|
|
318
288
|
export async function matchFiles(bundle, files, content) {
|
|
319
289
|
const { commitments, notRead } = await readPack(bundle, content, null, null);
|
|
320
290
|
return match(commitments, notRead, files);
|
|
321
291
|
}
|
|
322
|
-
/**
|
|
292
|
+
/** `matchFiles` over every pack of a case. */
|
|
323
293
|
export async function matchCaseFiles(packs, files) {
|
|
324
294
|
const commitments = [];
|
|
325
295
|
const notRead = [];
|
|
@@ -347,7 +317,7 @@ function commitmentJson(c) {
|
|
|
347
317
|
signed_at: c.signedAt,
|
|
348
318
|
};
|
|
349
319
|
}
|
|
350
|
-
/** The reading as the `files` member of `--json
|
|
320
|
+
/** The reading as the `files` member of `--json`. */
|
|
351
321
|
export function fileMatchToJson(reading) {
|
|
352
322
|
const skipped = reading.skipped ?? [];
|
|
353
323
|
return {
|
|
@@ -367,8 +337,7 @@ export function fileMatchToJson(reading) {
|
|
|
367
337
|
reason: n.reason,
|
|
368
338
|
rendered: renderNotRead(n),
|
|
369
339
|
})),
|
|
370
|
-
//
|
|
371
|
-
// file is the object it was before a folder could be offered (A40).
|
|
340
|
+
// Omitted when empty, so a reading with nothing skipped keeps its shape.
|
|
372
341
|
...(skipped.length > 0
|
|
373
342
|
? {
|
|
374
343
|
skipped: skipped.map((k) => ({
|
|
@@ -406,11 +375,9 @@ function renderNotRead(n) {
|
|
|
406
375
|
}
|
|
407
376
|
/**
|
|
408
377
|
* The commitments no offered file matched and no disclosed log answers.
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* and is not returned. Only the text report's count reads this; the reading, and
|
|
413
|
-
* `--json`, still list every commitment no file matched.
|
|
378
|
+
* A record whose own pack discloses bytes hashing to its `content_hash` is
|
|
379
|
+
* accounted for. Only the text report's count reads this; `--json` still lists
|
|
380
|
+
* every unmatched commitment.
|
|
414
381
|
*/
|
|
415
382
|
export async function notAccountedFor(reading, contents) {
|
|
416
383
|
const out = [];
|
|
@@ -426,11 +393,8 @@ export async function notAccountedFor(reading, contents) {
|
|
|
426
393
|
return out;
|
|
427
394
|
}
|
|
428
395
|
/**
|
|
429
|
-
* The text report's lines for the reading
|
|
430
|
-
*
|
|
431
|
-
* By default every commitment no file matched is a line. `notAmong` is the case
|
|
432
|
-
* command's report when no `--files` was given: one count line for the recorded
|
|
433
|
-
* files no loose file matched, and no line for each (A41).
|
|
396
|
+
* The text report's lines for the reading. With `notAmong` (the case command
|
|
397
|
+
* with no `--files`), unmatched commitments collapse to one count line.
|
|
434
398
|
*/
|
|
435
399
|
export function renderFileMatch(reading, notAmong) {
|
|
436
400
|
const skipped = reading.skipped ?? [];
|