@verax-ai/proxy 0.6.1 → 0.8.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/approvals.d.ts +30 -1
- package/dist/approvals.js +71 -14
- package/dist/control-sync.js +7 -1
- package/dist/data-classes.d.ts +36 -0
- package/dist/data-classes.js +412 -0
- package/dist/explain.js +128 -16
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/inputs.d.ts +4 -0
- package/dist/inputs.js +41 -0
- package/dist/ledger-manifest.d.ts +2 -0
- package/dist/ledger-manifest.js +1 -0
- package/dist/ledger.d.ts +2 -0
- package/dist/ledger.js +4 -0
- package/dist/policy.d.ts +12 -2
- package/dist/policy.js +208 -7
- package/dist/process-halt.d.ts +9 -0
- package/dist/process-halt.js +68 -0
- package/dist/proxy.js +215 -47
- package/dist/reconcile.d.ts +10 -1
- package/dist/reconcile.js +89 -14
- package/dist/result-classes.d.ts +35 -0
- package/dist/result-classes.js +485 -0
- package/dist/types.d.ts +64 -7
- package/dist/types.js +6 -1
- package/dist/verify-ledger.d.ts +7 -0
- package/dist/verify-ledger.js +180 -17
- package/package.json +3 -2
package/dist/explain.js
CHANGED
|
@@ -2,10 +2,11 @@ import { audit, DECISION_PROFILE } from "@cedulon/audit";
|
|
|
2
2
|
import { findDecisionRecordChainBreak } from "@cedulon/core";
|
|
3
3
|
import { approvalsLogFor } from "./approvals.js";
|
|
4
4
|
import { sha256Canonical } from "./hash.js";
|
|
5
|
-
import { inputsLogFor } from "./inputs.js";
|
|
5
|
+
import { inputsLogFor, inputsMatchingHash } from "./inputs.js";
|
|
6
6
|
import { lookupResolvedBy } from "./ledger.js";
|
|
7
7
|
import { loadCheckpoints } from "./checkpoints.js";
|
|
8
8
|
import { samePublicKey, thirdPartyReceiptCoversRow } from "./third-party.js";
|
|
9
|
+
import { resultRecordIsMismatch } from "./verify-ledger.js";
|
|
9
10
|
async function pairFor(ledger, decisions, record, inputsLog, approvals) {
|
|
10
11
|
const ref = record.claims.ref;
|
|
11
12
|
if (!ref)
|
|
@@ -23,7 +24,9 @@ async function pairFor(ledger, decisions, record, inputsLog, approvals) {
|
|
|
23
24
|
}
|
|
24
25
|
return { defer: null, resolution: null };
|
|
25
26
|
}
|
|
26
|
-
const own =
|
|
27
|
+
const own = typeof record.claims.inputsHash === "string"
|
|
28
|
+
? await inputsMatchingHash(inputsLog, ref, record.claims.inputsHash)
|
|
29
|
+
: await inputsLog.get(ref);
|
|
27
30
|
if (own?.approver?.resolves) {
|
|
28
31
|
const defer = decisions.find((d) => d.claims.ref === own.approver?.resolves) ?? null;
|
|
29
32
|
return { defer, resolution: record };
|
|
@@ -31,6 +34,68 @@ async function pairFor(ledger, decisions, record, inputsLog, approvals) {
|
|
|
31
34
|
return { defer: null, resolution: null };
|
|
32
35
|
}
|
|
33
36
|
const WINDOW_COVERAGE = "window-coverage";
|
|
37
|
+
function allowedClassOf(record) {
|
|
38
|
+
const named = record.claims.effectClass;
|
|
39
|
+
if (typeof named === "string" && named !== "")
|
|
40
|
+
return named;
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
function extractSettlementRow(extract) {
|
|
44
|
+
if (!extract || typeof extract !== "object")
|
|
45
|
+
return undefined;
|
|
46
|
+
const body = extract.body;
|
|
47
|
+
const effects = body?.effects;
|
|
48
|
+
// One row or nothing: with more, the row a finding came from is unknown.
|
|
49
|
+
if (!Array.isArray(effects) || effects.length !== 1)
|
|
50
|
+
return undefined;
|
|
51
|
+
const row = effects[0];
|
|
52
|
+
if (!row || typeof row !== "object")
|
|
53
|
+
return undefined;
|
|
54
|
+
return row;
|
|
55
|
+
}
|
|
56
|
+
function isBoundHaltedRow(row, record) {
|
|
57
|
+
const allowedClass = allowedClassOf(record);
|
|
58
|
+
if (!row || !allowedClass || record.claims.decision !== "allow")
|
|
59
|
+
return false;
|
|
60
|
+
return (row.ref === record.claims.ref &&
|
|
61
|
+
typeof row.effectHash === "string" &&
|
|
62
|
+
row.effectHash === record.claims.effectHash &&
|
|
63
|
+
row.effectClass === `${allowedClass}:halted`);
|
|
64
|
+
}
|
|
65
|
+
function selfOrSameOrg(witnessClass) {
|
|
66
|
+
return witnessClass === "self" || witnessClass === "same-org";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Every row the audit saw for a ref: the ledger row, plus the extract that
|
|
70
|
+
* was presented for the explained ref (the caller's, or the stored receipt).
|
|
71
|
+
*/
|
|
72
|
+
function auditedRows(effect, explainedRef, presentedExtract) {
|
|
73
|
+
const rows = [effect.row];
|
|
74
|
+
if (effect.row.ref === explainedRef && presentedExtract !== undefined) {
|
|
75
|
+
rows.push(extractSettlementRow(presentedExtract));
|
|
76
|
+
}
|
|
77
|
+
return rows;
|
|
78
|
+
}
|
|
79
|
+
function dropResultRecordMissingEffect(findings, record, resultOf, effect) {
|
|
80
|
+
if (typeof resultOf !== "string" || !effect || effect.row.ref !== resultOf)
|
|
81
|
+
return findings;
|
|
82
|
+
if (typeof effect.resultHash === "string" && record.claims.requestHash !== effect.resultHash) {
|
|
83
|
+
return findings;
|
|
84
|
+
}
|
|
85
|
+
const ref = record.claims.ref;
|
|
86
|
+
return findings.filter((finding) => !(finding.id === ref && finding.code === "receipt-without-settlement"));
|
|
87
|
+
}
|
|
88
|
+
function dropBoundHaltedClassMismatch(findings, decisions, effects, explainedRef, presentedExtract) {
|
|
89
|
+
return findings.filter((finding) => {
|
|
90
|
+
if (finding.code !== "effect-class-mismatch")
|
|
91
|
+
return true;
|
|
92
|
+
const record = decisions.find((d) => d.claims.ref === finding.id);
|
|
93
|
+
const effect = effects.find((e) => e.row.ref === finding.id && e.row.effectClass !== "duplicate-effect");
|
|
94
|
+
if (!record || !effect || !selfOrSameOrg(effect.witnessClass))
|
|
95
|
+
return true;
|
|
96
|
+
return !auditedRows(effect, explainedRef, presentedExtract).every((row) => isBoundHaltedRow(row, record));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
34
99
|
function resolveIssuerTrust(opts) {
|
|
35
100
|
if (opts?.issuerTrust) {
|
|
36
101
|
return {
|
|
@@ -98,8 +163,19 @@ export async function explain(ledger, ref, opts) {
|
|
|
98
163
|
if (!record) {
|
|
99
164
|
throw new Error(`explain-unknown-ref:${ref}`);
|
|
100
165
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
166
|
+
const inputsLog = opts?.inputsLog ?? inputsLogFor(ledger);
|
|
167
|
+
// The row inputsHash names. When none does, the last row for the ref is
|
|
168
|
+
// read so a tampered row is an inputs-hash-mismatch, not a missing document.
|
|
169
|
+
const inputsDoc = !record.claims.ref
|
|
170
|
+
? null
|
|
171
|
+
: typeof record.claims.inputsHash === "string"
|
|
172
|
+
? ((await inputsMatchingHash(inputsLog, record.claims.ref, record.claims.inputsHash)) ??
|
|
173
|
+
(await inputsLog.get(record.claims.ref)))
|
|
174
|
+
: await inputsLog.get(record.claims.ref);
|
|
175
|
+
const resultOf = typeof inputsDoc?.resultOf === "string" ? inputsDoc.resultOf : undefined;
|
|
176
|
+
const effect = effects.find((e) => e.row.ref === (resultOf ?? ref) && e.row.effectClass !== "duplicate-effect") ?? null;
|
|
177
|
+
const userExtract = opts?.extract;
|
|
178
|
+
const presentedExtract = userExtract ?? effect?.receipt;
|
|
103
179
|
const extractPresented = Boolean(presentedExtract);
|
|
104
180
|
const resolvedTrust = resolveIssuerTrust(opts);
|
|
105
181
|
const issuerTrust = resolvedTrust.pin;
|
|
@@ -133,12 +209,8 @@ export async function explain(ledger, ref, opts) {
|
|
|
133
209
|
.map((f) => f.code)),
|
|
134
210
|
]
|
|
135
211
|
: [];
|
|
136
|
-
const applicable = dropWindow
|
|
137
|
-
|
|
138
|
-
: report.findings;
|
|
139
|
-
const applicableWarnings = dropWindow
|
|
140
|
-
? report.warnings.filter((f) => f.code !== WINDOW_COVERAGE)
|
|
141
|
-
: report.warnings;
|
|
212
|
+
const applicable = dropResultRecordMissingEffect(dropBoundHaltedClassMismatch(dropWindow ? report.findings.filter((f) => f.code !== WINDOW_COVERAGE) : report.findings, decisions, effects, ref, presentedExtract), record, resultOf, effect);
|
|
213
|
+
const applicableWarnings = dropResultRecordMissingEffect(dropBoundHaltedClassMismatch(dropWindow ? report.warnings.filter((f) => f.code !== WINDOW_COVERAGE) : report.warnings, decisions, effects, ref, presentedExtract), record, resultOf, effect);
|
|
142
214
|
const refFindings = applicable.filter((f) => f.id === ref);
|
|
143
215
|
const issuerFinding = applicable.find((f) => f.code === "issuer-key-mismatch" || f.id === "issuer") ??
|
|
144
216
|
applicableWarnings.find((f) => f.code === "issuer-key-mismatch") ??
|
|
@@ -177,36 +249,76 @@ export async function explain(ledger, ref, opts) {
|
|
|
177
249
|
conditions.push(name);
|
|
178
250
|
}
|
|
179
251
|
const issuerMismatch = applicable.concat(applicableWarnings).some((f) => f.code === "issuer-key-mismatch" || (pinned && f.code === "unauthenticated-issuer"));
|
|
180
|
-
const inputsLog = opts?.inputsLog ?? inputsLogFor(ledger);
|
|
181
252
|
const approvals = approvalsLogFor(ledger);
|
|
182
|
-
const inputsDoc = record.claims.ref ? await inputsLog.get(record.claims.ref) : null;
|
|
183
253
|
const inputsMismatch = Boolean(inputsDoc &&
|
|
184
254
|
typeof record.claims.inputsHash === "string" &&
|
|
185
255
|
sha256Canonical(inputsDoc) !== record.claims.inputsHash);
|
|
186
256
|
const inputsMissing = typeof record.claims.inputsHash === "string" && inputsDoc === null;
|
|
257
|
+
let resultMismatch = false;
|
|
258
|
+
if (typeof inputsDoc?.resultOf === "string") {
|
|
259
|
+
const resultHashByRef = new Map();
|
|
260
|
+
const effectClassByRef = new Map();
|
|
261
|
+
for (const e of effects) {
|
|
262
|
+
if (e.row.effectClass === "duplicate-effect")
|
|
263
|
+
continue;
|
|
264
|
+
if (typeof e.resultHash === "string")
|
|
265
|
+
resultHashByRef.set(e.row.ref, e.resultHash);
|
|
266
|
+
if (typeof e.row.effectClass === "string")
|
|
267
|
+
effectClassByRef.set(e.row.ref, e.row.effectClass);
|
|
268
|
+
}
|
|
269
|
+
let namedCount = 0;
|
|
270
|
+
for (const rec of decisions) {
|
|
271
|
+
if (typeof rec.claims.ref !== "string" || typeof rec.claims.inputsHash !== "string")
|
|
272
|
+
continue;
|
|
273
|
+
const other = rec.claims.ref === record.claims.ref
|
|
274
|
+
? inputsDoc
|
|
275
|
+
: await inputsMatchingHash(inputsLog, rec.claims.ref, rec.claims.inputsHash);
|
|
276
|
+
if (other?.resultOf === inputsDoc.resultOf)
|
|
277
|
+
namedCount += 1;
|
|
278
|
+
}
|
|
279
|
+
resultMismatch = resultRecordIsMismatch(record, { resultOf: inputsDoc.resultOf, resultClasses: inputsDoc.resultClasses }, resultHashByRef, effectClassByRef, namedCount);
|
|
280
|
+
}
|
|
187
281
|
if (inputsMissing)
|
|
188
282
|
conditions.push("inputs document missing");
|
|
189
|
-
const
|
|
283
|
+
const haltedUnbound = effect !== null &&
|
|
284
|
+
auditedRows(effect, ref, presentedExtract).some((row) => typeof row?.effectClass === "string" && row.effectClass.endsWith(":halted") && !isBoundHaltedRow(row, record));
|
|
285
|
+
const balanced = refFindings.length === 0 &&
|
|
286
|
+
!chainBreak &&
|
|
287
|
+
!issuerMismatch &&
|
|
288
|
+
!inputsMismatch &&
|
|
289
|
+
!inputsMissing &&
|
|
290
|
+
!resultMismatch &&
|
|
291
|
+
!haltedUnbound;
|
|
190
292
|
const code = chainBreak
|
|
191
293
|
? "receipt-chain-break"
|
|
192
294
|
: inputsMismatch
|
|
193
295
|
? "inputs-hash-mismatch"
|
|
194
296
|
: inputsMissing
|
|
195
297
|
? "inputs-document-missing"
|
|
196
|
-
:
|
|
298
|
+
: resultMismatch
|
|
299
|
+
? "result-record-mismatch"
|
|
300
|
+
: haltedUnbound
|
|
301
|
+
? (hit?.code ?? "effect-class-mismatch")
|
|
302
|
+
: (hit?.code ?? null);
|
|
197
303
|
const detail = chainBreak
|
|
198
304
|
? `receipt-chain-break at ${breakAt ?? "unknown"} (${brk?.reason ?? "broken"})`
|
|
199
305
|
: inputsMismatch
|
|
200
306
|
? "inputs document hash does not match claims.inputsHash"
|
|
201
307
|
: inputsMissing
|
|
202
308
|
? "claims.inputsHash is on the record; the inputs document is not on disk"
|
|
203
|
-
:
|
|
309
|
+
: resultMismatch
|
|
310
|
+
? "result record does not bind to the named call the way verifyLedger requires"
|
|
311
|
+
: haltedUnbound && !hit
|
|
312
|
+
? "halted effect is not bound to the same allow"
|
|
313
|
+
: (hit?.detail ?? null);
|
|
204
314
|
const findingCount = chainBreak
|
|
205
315
|
? Math.max(refFindings.length, 1)
|
|
206
316
|
: refFindings.length +
|
|
207
317
|
(issuerMismatch && pinned ? 1 : 0) +
|
|
208
318
|
(inputsMismatch ? 1 : 0) +
|
|
209
|
-
(inputsMissing ? 1 : 0)
|
|
319
|
+
(inputsMissing ? 1 : 0) +
|
|
320
|
+
(resultMismatch ? 1 : 0) +
|
|
321
|
+
(haltedUnbound && refFindings.length === 0 ? 1 : 0);
|
|
210
322
|
const guarantee = guaranteeWithConditions(report.guarantee, conditions);
|
|
211
323
|
const summary = balanced
|
|
212
324
|
? balancedSummary(guarantee, conditions, report.summary)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createProxy, LedgerDenyUnrecorded } from "./proxy.ts";
|
|
2
|
+
export { clearProcessHalted, isProcessHalted, markProcessHalted, persistHaltedSwitch } from "./process-halt.ts";
|
|
2
3
|
export { effectDescriptor, sha256Canonical } from "./hash.ts";
|
|
3
4
|
export { samePublicKey, thirdPartyReceiptRejection } from "./third-party.ts";
|
|
4
5
|
export { loadPolicy, TERMINAL_CONTROL_CLASS, DISPLAY_ESCAPE_CLASS, terminalText, terminalLines } from "./policy.ts";
|
|
@@ -6,8 +7,8 @@ export type { PolicyParseOptions } from "./policy.ts";
|
|
|
6
7
|
export { FileLedger, MemoryLedger, readLedgerTail, lockHolderAlive, lockState, lockBeatOf } from "./ledger.ts";
|
|
7
8
|
export { indexCoverage, listPieceFiles } from "./ledger-manifest.ts";
|
|
8
9
|
export { explain } from "./explain.ts";
|
|
9
|
-
export { approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.ts";
|
|
10
|
-
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.ts";
|
|
10
|
+
export { approvalArgsBound, approvalDispatchArgs, approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.ts";
|
|
11
|
+
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadSignedForwardedHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.ts";
|
|
11
12
|
export { tenantKey } from "./tenant.ts";
|
|
12
13
|
export { diskProbe } from "./disk.ts";
|
|
13
14
|
export { checkpointsPath, readCheckpointFile } from "./checkpoints.ts";
|
|
@@ -18,7 +19,7 @@ export type { ApprovalRow, ApproveResult } from "./approvals.ts";
|
|
|
18
19
|
export type { CardCsvOpts, ChannelRow, ReconcileReport } from "./reconcile.ts";
|
|
19
20
|
export type { FileLedgerOpts, LedgerCounts, LockHolder } from "./ledger.ts";
|
|
20
21
|
export type { ApprovalSignature, ControlSignature, OperatorRemovalInput, RevokeInput } from "./types.ts";
|
|
21
|
-
export type { EffectSigner, ExplainChain, ExplainPair, ExplainFinding, ExplainOpts, ExplainResult, ExplainTrustRoot, ExplainWarning, ExtractWindow, Ledger, LedgerEffect, Policy, PolicyDecision, Principal, ProxyDeps, RecordSigner, ToolCall, ToolResult, WitnessClass, } from "./types.ts";
|
|
22
|
+
export type { EffectSigner, ExplainChain, ExplainPair, ExplainFinding, ExplainOpts, ExplainResult, ExplainTrustRoot, ExplainWarning, ExtractWindow, Ledger, LedgerEffect, MediaContent, Policy, PolicyDecision, Principal, ProxyDeps, RecordSigner, ResultContent, TextContent, ToolCall, ToolResult, WitnessClass, } from "./types.ts";
|
|
22
23
|
export { verifyLedger } from "./verify-ledger.ts";
|
|
23
24
|
export type { VerifyResult, VerifyOptions, VerifyTrust, VerifyControl, VerifyInputs, VerifyAnchors, } from "./verify-ledger.ts";
|
|
24
25
|
export { anchorEntryHash, appendAnchor, readAnchors } from "./anchors.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export { createProxy, LedgerDenyUnrecorded } from "./proxy.js";
|
|
2
|
+
export { clearProcessHalted, isProcessHalted, markProcessHalted, persistHaltedSwitch } from "./process-halt.js";
|
|
2
3
|
export { effectDescriptor, sha256Canonical } from "./hash.js";
|
|
3
4
|
export { samePublicKey, thirdPartyReceiptRejection } from "./third-party.js";
|
|
4
5
|
export { loadPolicy, TERMINAL_CONTROL_CLASS, DISPLAY_ESCAPE_CLASS, terminalText, terminalLines } from "./policy.js";
|
|
5
6
|
export { FileLedger, MemoryLedger, readLedgerTail, lockHolderAlive, lockState, lockBeatOf } from "./ledger.js";
|
|
6
7
|
export { indexCoverage, listPieceFiles } from "./ledger-manifest.js";
|
|
7
8
|
export { explain } from "./explain.js";
|
|
8
|
-
export { approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.js";
|
|
9
|
-
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.js";
|
|
9
|
+
export { approvalArgsBound, approvalDispatchArgs, approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.js";
|
|
10
|
+
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadSignedForwardedHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.js";
|
|
10
11
|
export { tenantKey } from "./tenant.js";
|
|
11
12
|
// The body writes checkpoints and signs its own effect attestations. Both were
|
|
12
13
|
// reached through a relative path into this package, which only exists inside
|
package/dist/inputs.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare class MemoryInputsLog implements InputsLog {
|
|
|
3
3
|
private readonly rows;
|
|
4
4
|
append(ref: string, inputs: DecisionInputs): Promise<void>;
|
|
5
5
|
get(ref: string): Promise<DecisionInputs | null>;
|
|
6
|
+
getMatching(ref: string, hash: string): Promise<DecisionInputs | null>;
|
|
6
7
|
}
|
|
7
8
|
export declare class FileInputsLog implements InputsLog {
|
|
8
9
|
private readonly dir;
|
|
@@ -15,5 +16,8 @@ export declare class FileInputsLog implements InputsLog {
|
|
|
15
16
|
private paths;
|
|
16
17
|
append(ref: string, inputs: DecisionInputs): Promise<void>;
|
|
17
18
|
get(ref: string): Promise<DecisionInputs | null>;
|
|
19
|
+
getMatching(ref: string, hash: string): Promise<DecisionInputs | null>;
|
|
18
20
|
}
|
|
21
|
+
/** The inputs row `hash` names. Last-row `get` is not this. */
|
|
22
|
+
export declare function inputsMatchingHash(log: InputsLog, ref: string, hash: string): Promise<DecisionInputs | null>;
|
|
19
23
|
export declare function inputsLogFor(ledger: object): InputsLog;
|
package/dist/inputs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
+
import { sha256Canonical } from "./hash.js";
|
|
2
3
|
import { appendDurable, ledgerFs } from "./ledger.js";
|
|
3
4
|
export class MemoryInputsLog {
|
|
4
5
|
rows = new Map();
|
|
@@ -8,6 +9,12 @@ export class MemoryInputsLog {
|
|
|
8
9
|
async get(ref) {
|
|
9
10
|
return this.rows.get(ref) ?? null;
|
|
10
11
|
}
|
|
12
|
+
async getMatching(ref, hash) {
|
|
13
|
+
const row = this.rows.get(ref);
|
|
14
|
+
if (!row)
|
|
15
|
+
return null;
|
|
16
|
+
return sha256Canonical(row) === hash ? row : null;
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
19
|
export class FileInputsLog {
|
|
13
20
|
dir;
|
|
@@ -52,6 +59,40 @@ export class FileInputsLog {
|
|
|
52
59
|
}
|
|
53
60
|
return found;
|
|
54
61
|
}
|
|
62
|
+
async getMatching(ref, hash) {
|
|
63
|
+
let found = null;
|
|
64
|
+
for (const path of this.paths().all) {
|
|
65
|
+
let text;
|
|
66
|
+
try {
|
|
67
|
+
text = await ledgerFs.readFile(path, "utf8");
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err.code === "ENOENT")
|
|
71
|
+
continue;
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
for (const line of text.split("\n")) {
|
|
75
|
+
if (line === "")
|
|
76
|
+
continue;
|
|
77
|
+
const row = JSON.parse(line);
|
|
78
|
+
if (row.ref !== ref)
|
|
79
|
+
continue;
|
|
80
|
+
if (sha256Canonical(row.inputs) === hash)
|
|
81
|
+
found = row.inputs;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return found;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The inputs row `hash` names. Last-row `get` is not this. */
|
|
88
|
+
export async function inputsMatchingHash(log, ref, hash) {
|
|
89
|
+
const matching = log;
|
|
90
|
+
if (typeof matching.getMatching === "function")
|
|
91
|
+
return matching.getMatching(ref, hash);
|
|
92
|
+
const row = await log.get(ref);
|
|
93
|
+
if (!row)
|
|
94
|
+
return null;
|
|
95
|
+
return sha256Canonical(row) === hash ? row : null;
|
|
55
96
|
}
|
|
56
97
|
const STASH = Symbol.for("verax.inputsLog");
|
|
57
98
|
export function inputsLogFor(ledger) {
|
package/dist/ledger-manifest.js
CHANGED
|
@@ -226,6 +226,7 @@ export function parseIndexText(text) {
|
|
|
226
226
|
reasonCode: typeof raw.reasonCode === "string" ? raw.reasonCode : "",
|
|
227
227
|
subject: typeof raw.subject === "string" ? raw.subject : "",
|
|
228
228
|
policyHash: typeof raw.policyHash === "string" ? raw.policyHash : "",
|
|
229
|
+
...(typeof raw.inputsHash === "string" ? { inputsHash: raw.inputsHash } : {}),
|
|
229
230
|
});
|
|
230
231
|
}
|
|
231
232
|
return rows;
|
package/dist/ledger.d.ts
CHANGED
package/dist/ledger.js
CHANGED
|
@@ -179,6 +179,7 @@ function indexRowOf(signed) {
|
|
|
179
179
|
subject: signed.claims.subject,
|
|
180
180
|
policyHash: signed.claims.policyHash,
|
|
181
181
|
timestampMs: signed.claims.timestampMs,
|
|
182
|
+
...(typeof signed.claims.inputsHash === "string" ? { inputsHash: signed.claims.inputsHash } : {}),
|
|
182
183
|
};
|
|
183
184
|
}
|
|
184
185
|
function resolutionKindOf(row) {
|
|
@@ -604,6 +605,7 @@ export class FileLedger {
|
|
|
604
605
|
subject: line.subject,
|
|
605
606
|
policyHash: line.policyHash,
|
|
606
607
|
timestampMs: line.ts,
|
|
608
|
+
...(line.inputsHash !== undefined ? { inputsHash: line.inputsHash } : {}),
|
|
607
609
|
};
|
|
608
610
|
this.byRef.set(line.ref, row);
|
|
609
611
|
if (line.tenantRef !== "")
|
|
@@ -665,6 +667,7 @@ export class FileLedger {
|
|
|
665
667
|
reasonCode: row.reasonCode,
|
|
666
668
|
subject: row.subject,
|
|
667
669
|
policyHash: row.policyHash,
|
|
670
|
+
...(row.inputsHash !== undefined ? { inputsHash: row.inputsHash } : {}),
|
|
668
671
|
});
|
|
669
672
|
}
|
|
670
673
|
}
|
|
@@ -706,6 +709,7 @@ export class FileLedger {
|
|
|
706
709
|
reasonCode: row.reasonCode,
|
|
707
710
|
subject: row.subject,
|
|
708
711
|
policyHash: row.policyHash,
|
|
712
|
+
...(row.inputsHash !== undefined ? { inputsHash: row.inputsHash } : {}),
|
|
709
713
|
};
|
|
710
714
|
await appendPlain(indexPath(this.dir), lineOf(line));
|
|
711
715
|
this.applyIndexLine(line);
|
package/dist/policy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Policy } from "./types.ts";
|
|
1
|
+
import type { DataClassChoice, MediaConfig, Policy, ResultClassChoice } from "./types.ts";
|
|
2
2
|
export type PolicySpend = {
|
|
3
3
|
maxAmountMinor: number;
|
|
4
4
|
currency: string;
|
|
@@ -20,9 +20,11 @@ export type PolicyRule = {
|
|
|
20
20
|
mode?: "allow" | "approve";
|
|
21
21
|
spend?: PolicySpend;
|
|
22
22
|
egress?: true;
|
|
23
|
+
dataClasses?: Readonly<Record<string, DataClassChoice>>;
|
|
24
|
+
resultClasses?: Readonly<Record<string, ResultClassChoice>>;
|
|
23
25
|
};
|
|
24
26
|
export type PolicyDocument = {
|
|
25
|
-
version: 1;
|
|
27
|
+
version: 1 | 2;
|
|
26
28
|
default: "deny";
|
|
27
29
|
approvalTtlMs?: number;
|
|
28
30
|
egress?: readonly string[];
|
|
@@ -33,6 +35,14 @@ export type PolicyDocument = {
|
|
|
33
35
|
dailyMax?: number;
|
|
34
36
|
diskFreeBytes?: number;
|
|
35
37
|
};
|
|
38
|
+
dataClasses?: Readonly<Record<string, DataClassChoice>>;
|
|
39
|
+
resultClasses?: Readonly<Record<string, ResultClassChoice>>;
|
|
40
|
+
media?: MediaConfig;
|
|
41
|
+
localTools?: readonly string[];
|
|
42
|
+
fileTypes?: {
|
|
43
|
+
block: readonly string[];
|
|
44
|
+
};
|
|
45
|
+
scanCharCap?: number;
|
|
36
46
|
rules: PolicyRule[];
|
|
37
47
|
};
|
|
38
48
|
/** Named per tool. Do not sniff `host` / `url` on arbitrary arguments. */
|