@verax-ai/proxy 0.8.2 → 0.10.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/dist/anchors.d.ts +28 -5
- package/dist/anchors.js +21 -8
- package/dist/approvals.js +2 -0
- package/dist/canary.d.ts +118 -0
- package/dist/canary.js +755 -0
- package/dist/explain.js +7 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.js +6 -2
- package/dist/inputs.d.ts +5 -0
- package/dist/inputs.js +38 -0
- package/dist/ledger.js +17 -1
- package/dist/policy.d.ts +9 -1
- package/dist/policy.js +38 -1
- package/dist/proxy.js +274 -26
- package/dist/session-taint.d.ts +92 -0
- package/dist/session-taint.js +343 -0
- package/dist/signed-statement.d.ts +26 -0
- package/dist/signed-statement.js +146 -0
- package/dist/tool-labels.d.ts +43 -0
- package/dist/tool-labels.js +94 -0
- package/dist/transparency-receipt.d.ts +38 -0
- package/dist/transparency-receipt.js +103 -1
- package/dist/types.d.ts +82 -1
- package/dist/verify-ledger.d.ts +12 -0
- package/dist/verify-ledger.js +81 -33
- package/package.json +7 -7
package/dist/anchors.d.ts
CHANGED
|
@@ -1,20 +1,43 @@
|
|
|
1
1
|
export declare const ANCHORS_NAME = "checkpoint-anchors.jsonl";
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* `register`: the digest route; the log's leaf entry is SHA-256 of the 32
|
|
4
|
+
* checkpoint-hash octets. `entries`: SCRAPI; the witness registers a Signed
|
|
5
|
+
* Statement for the checkpoint and the row keeps it beside the receipt.
|
|
6
|
+
*/
|
|
7
|
+
export type AnchorRoute = "register" | "entries";
|
|
8
|
+
/** A receipt from the digest route, over an RFC 9162 log. */
|
|
9
|
+
export type DigestAnchorRow = {
|
|
5
10
|
v: 1;
|
|
6
11
|
checkpointHash: string;
|
|
7
12
|
service: string;
|
|
8
|
-
route:
|
|
13
|
+
route: "register";
|
|
9
14
|
entryHash: string;
|
|
10
15
|
leafIndex: number;
|
|
11
16
|
treeSize: number;
|
|
12
17
|
receiptB64: string;
|
|
13
18
|
atMs: number;
|
|
14
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* A Signed Statement registered over SCRAPI and the receipt for it. The
|
|
22
|
+
* receipt commits to the SHA-256 of `statementB64`'s octets, and `entryId` is
|
|
23
|
+
* the service's name for the entry (a CCF transaction id).
|
|
24
|
+
*/
|
|
25
|
+
export type StatementAnchorRow = {
|
|
26
|
+
v: 2;
|
|
27
|
+
checkpointHash: string;
|
|
28
|
+
service: string;
|
|
29
|
+
route: "entries";
|
|
30
|
+
entryId: string;
|
|
31
|
+
statementB64: string;
|
|
32
|
+
receiptB64: string;
|
|
33
|
+
atMs: number;
|
|
34
|
+
};
|
|
35
|
+
export type AnchorRow = DigestAnchorRow | StatementAnchorRow;
|
|
15
36
|
export declare function anchorsPath(dir: string): string;
|
|
16
|
-
/** The leaf entry the
|
|
37
|
+
/** The leaf entry the digest route's log holds for this checkpoint. */
|
|
17
38
|
export declare function anchorEntryHash(checkpointHash: string, route: AnchorRoute): string;
|
|
39
|
+
/** A CCF transaction id, `<view>.<seqno>`, as SCRAPI names an entry. */
|
|
40
|
+
export declare function isEntryId(value: unknown): value is string;
|
|
18
41
|
/** Rows in file order. A line that is not a row is named, not skipped silently. */
|
|
19
42
|
export declare function readAnchors(dir: string): {
|
|
20
43
|
present: boolean;
|
package/dist/anchors.js
CHANGED
|
@@ -19,10 +19,11 @@ import { appendFileSync, existsSync, lstatSync, readFileSync } from "node:fs";
|
|
|
19
19
|
import { join } from "node:path";
|
|
20
20
|
export const ANCHORS_NAME = "checkpoint-anchors.jsonl";
|
|
21
21
|
const HASH = /^[0-9a-f]{64}$/;
|
|
22
|
+
const ENTRY_ID = /^[0-9]{1,20}\.[0-9]{1,20}$/;
|
|
22
23
|
export function anchorsPath(dir) {
|
|
23
24
|
return join(dir, ANCHORS_NAME);
|
|
24
25
|
}
|
|
25
|
-
/** The leaf entry the
|
|
26
|
+
/** The leaf entry the digest route's log holds for this checkpoint. */
|
|
26
27
|
export function anchorEntryHash(checkpointHash, route) {
|
|
27
28
|
if (!HASH.test(checkpointHash))
|
|
28
29
|
throw new Error("anchor-checkpoint-hash");
|
|
@@ -30,25 +31,37 @@ export function anchorEntryHash(checkpointHash, route) {
|
|
|
30
31
|
return createHash("sha256").update(Buffer.from(checkpointHash, "hex")).digest("hex");
|
|
31
32
|
throw new Error(`anchor-route-${String(route)}`);
|
|
32
33
|
}
|
|
34
|
+
/** A CCF transaction id, `<view>.<seqno>`, as SCRAPI names an entry. */
|
|
35
|
+
export function isEntryId(value) {
|
|
36
|
+
return typeof value === "string" && ENTRY_ID.test(value);
|
|
37
|
+
}
|
|
33
38
|
function asRow(value) {
|
|
34
39
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
35
40
|
return null;
|
|
36
41
|
const r = value;
|
|
37
|
-
if (r.v !== 1 || r.route !== "register")
|
|
38
|
-
return null;
|
|
39
42
|
if (typeof r.checkpointHash !== "string" || !HASH.test(r.checkpointHash))
|
|
40
43
|
return null;
|
|
41
|
-
if (typeof r.entryHash !== "string" || !HASH.test(r.entryHash))
|
|
42
|
-
return null;
|
|
43
44
|
if (typeof r.service !== "string" || r.service === "")
|
|
44
45
|
return null;
|
|
45
46
|
if (typeof r.receiptB64 !== "string" || r.receiptB64 === "")
|
|
46
47
|
return null;
|
|
47
|
-
if (!Number.isSafeInteger(r.leafIndex) || !Number.isSafeInteger(r.treeSize))
|
|
48
|
-
return null;
|
|
49
48
|
if (typeof r.atMs !== "number")
|
|
50
49
|
return null;
|
|
51
|
-
|
|
50
|
+
if (r.v === 1 && r.route === "register") {
|
|
51
|
+
if (typeof r.entryHash !== "string" || !HASH.test(r.entryHash))
|
|
52
|
+
return null;
|
|
53
|
+
if (!Number.isSafeInteger(r.leafIndex) || !Number.isSafeInteger(r.treeSize))
|
|
54
|
+
return null;
|
|
55
|
+
return r;
|
|
56
|
+
}
|
|
57
|
+
if (r.v === 2 && r.route === "entries") {
|
|
58
|
+
if (!isEntryId(r.entryId))
|
|
59
|
+
return null;
|
|
60
|
+
if (typeof r.statementB64 !== "string" || r.statementB64 === "")
|
|
61
|
+
return null;
|
|
62
|
+
return r;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
52
65
|
}
|
|
53
66
|
/** Rows in file order. A line that is not a row is named, not skipped silently. */
|
|
54
67
|
export function readAnchors(dir) {
|
package/dist/approvals.js
CHANGED
|
@@ -369,6 +369,8 @@ async function approvePendingUnlocked(opts) {
|
|
|
369
369
|
inputs: prior?.inputs ?? [],
|
|
370
370
|
approver: approverInputs(opts),
|
|
371
371
|
...(signed.inputs?.dataClasses !== undefined ? { dataClasses: signed.inputs.dataClasses } : {}),
|
|
372
|
+
...(prior?.session !== undefined ? { session: prior.session } : {}),
|
|
373
|
+
...(prior?.toolLabels !== undefined ? { toolLabels: prior.toolLabels } : {}),
|
|
372
374
|
};
|
|
373
375
|
const inputsHash = sha256Canonical(inputs);
|
|
374
376
|
const dispatchArgs = approvalDispatchArgs(snap);
|
package/dist/canary.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A canary is a credential-shaped value nothing legitimate uses. The gate
|
|
3
|
+
* compares a call with the active values before the tool runs. The files and
|
|
4
|
+
* the decision name the id, never the value.
|
|
5
|
+
*
|
|
6
|
+
* `CANARY_CHECK_BOUND_MS` is the ceiling `canary-perf` enforces for one check
|
|
7
|
+
* of 50 canaries against about 4 KiB of punctuated prose and URLs. The
|
|
8
|
+
* measured median lives in `docs/PERF.md`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CANARY_FILE = "canaries.json";
|
|
11
|
+
/** Exclusive create, same idea as `ledger.lock`. Held only across one add or remove. */
|
|
12
|
+
export declare const CANARY_LOCK_FILE = "canaries.lock";
|
|
13
|
+
export declare const CANARY_FINDING = "canary-exfiltration";
|
|
14
|
+
/**
|
|
15
|
+
* A local finding, not a signed alarm. `verax.incident.v1` is the memory
|
|
16
|
+
* integrity record: the incident writer accepts only those codes, signs them
|
|
17
|
+
* with the record key, and copies them to the alarm outbox. This file is
|
|
18
|
+
* written by the proxy, which does not hold that key, including when policy
|
|
19
|
+
* is `deny` and nothing halts. No alarm is sent.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CANARY_INCIDENT_PURPOSE = "verax.canary-finding.v1";
|
|
22
|
+
export declare const CANARY_CHECK_BOUND_MS = 25;
|
|
23
|
+
export declare const CANARY_SHAPES: readonly ["api-key", "bearer", "password", "card"];
|
|
24
|
+
export type CanaryShape = (typeof CANARY_SHAPES)[number];
|
|
25
|
+
export type StoredCanary = {
|
|
26
|
+
id: string;
|
|
27
|
+
label: string;
|
|
28
|
+
shape: CanaryShape;
|
|
29
|
+
value: string;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
retiredAt: string | null;
|
|
32
|
+
};
|
|
33
|
+
export type CanaryListRow = {
|
|
34
|
+
id: string;
|
|
35
|
+
label: string;
|
|
36
|
+
createdAt: string;
|
|
37
|
+
status: "active" | "retired";
|
|
38
|
+
};
|
|
39
|
+
export type CanaryNeedle = {
|
|
40
|
+
id: string;
|
|
41
|
+
value: string;
|
|
42
|
+
};
|
|
43
|
+
export type CanaryMatch = {
|
|
44
|
+
id: string;
|
|
45
|
+
where: string;
|
|
46
|
+
subject: string;
|
|
47
|
+
};
|
|
48
|
+
export declare class CanaryStoreError extends Error {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
export declare function readCanaryFile(stateDir: string): StoredCanary[];
|
|
52
|
+
export declare function writeCanaryFile(stateDir: string, rows: readonly StoredCanary[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Runs after the store is read and before it is written, while the
|
|
55
|
+
* cross-process lock is held. The race test pauses one update on the
|
|
56
|
+
* snapshot it already read. Production leaves this null.
|
|
57
|
+
*/
|
|
58
|
+
export declare const canaryTestHooks: {
|
|
59
|
+
afterRead: (() => void) | null;
|
|
60
|
+
};
|
|
61
|
+
export declare function addCanary(stateDir: string, opts?: {
|
|
62
|
+
label?: string;
|
|
63
|
+
shape?: CanaryShape;
|
|
64
|
+
now?: number;
|
|
65
|
+
}): {
|
|
66
|
+
id: string;
|
|
67
|
+
value: string;
|
|
68
|
+
label: string;
|
|
69
|
+
shape: CanaryShape;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
};
|
|
72
|
+
/** `retired` when this call retired it or it was already retired. `missing` when the id is unknown. */
|
|
73
|
+
export declare function retireCanary(stateDir: string, id: string, now?: number): "retired" | "missing";
|
|
74
|
+
export declare function listCanaries(stateDir: string): CanaryListRow[];
|
|
75
|
+
/** The active value, for the operator plant path. A retired id returns null. */
|
|
76
|
+
export declare function activeCanaryValue(stateDir: string, id: string): string | null;
|
|
77
|
+
export declare function loadActiveCanaries(stateDir: string): {
|
|
78
|
+
ok: true;
|
|
79
|
+
canaries: CanaryNeedle[];
|
|
80
|
+
} | {
|
|
81
|
+
ok: false;
|
|
82
|
+
reason: "canary-unreadable";
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The first active canary found in the arguments, the tool name, or the
|
|
86
|
+
* arguments joined so a value split across fields is still one string.
|
|
87
|
+
* String leaves are joined on their own, so a number sitting between two
|
|
88
|
+
* halves is not part of that string. A second join runs only when a number
|
|
89
|
+
* leaf is present, and it includes those leaves with the strings. A secret
|
|
90
|
+
* split into two JSON numbers is still one string when no string value sits
|
|
91
|
+
* between them. The string join is searched first. Hex is the whole value
|
|
92
|
+
* in any letter case. Base64 and base64url are searched at each byte
|
|
93
|
+
* alignment; an aligned slice is only a candidate until that slice and
|
|
94
|
+
* the bytes beside it decode to the whole value. A one-character near
|
|
95
|
+
* miss is not that value. Both are searched in the text and in each
|
|
96
|
+
* percent-decoded variant, including that variant with whitespace
|
|
97
|
+
* removed. Percent-encoding is decoded up to three times; an invalid `%`
|
|
98
|
+
* sequence is left as it is, and `+` is also tried as a space. A number
|
|
99
|
+
* leaf is read as `String(value)`. Past 32 levels or 1,000,000 characters
|
|
100
|
+
* the walk continues, iteratively, for the raw search only. A value that
|
|
101
|
+
* is found is a match. Otherwise the result is `too-wide`. The result
|
|
102
|
+
* never carries the value.
|
|
103
|
+
*/
|
|
104
|
+
export declare function matchCanary(args: Record<string, unknown>, canaries: readonly CanaryNeedle[], toolName?: string): CanaryMatch | "too-wide" | null;
|
|
105
|
+
export declare function writeCanaryIncident(stateDir: string, hit: {
|
|
106
|
+
id: string;
|
|
107
|
+
where: string;
|
|
108
|
+
enforcement: "halt" | "deny";
|
|
109
|
+
observedAt: number;
|
|
110
|
+
}): void;
|
|
111
|
+
/**
|
|
112
|
+
* The same switch `verax halt` writes: an empty `halted` file, then one
|
|
113
|
+
* history line. A later call copies that line into the ledger. The line names
|
|
114
|
+
* the actor and does not name the value.
|
|
115
|
+
*/
|
|
116
|
+
export declare function haltForCanary(stateDir: string, atMs: number): void;
|
|
117
|
+
/** Used when the switch file could not be written. Same flag the proxy already honours. */
|
|
118
|
+
export declare function markCanaryHalted(stateDir: string): void;
|