@verax-ai/proxy 0.6.0 → 0.6.1
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/reconcile.d.ts +7 -0
- package/dist/reconcile.js +49 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { FileLedger, MemoryLedger, readLedgerTail, lockHolderAlive, lockState, l
|
|
|
7
7
|
export { indexCoverage, listPieceFiles } from "./ledger-manifest.ts";
|
|
8
8
|
export { explain } from "./explain.ts";
|
|
9
9
|
export { approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.ts";
|
|
10
|
-
export { loadDecisionRefsFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile } from "./reconcile.ts";
|
|
10
|
+
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.ts";
|
|
11
11
|
export { tenantKey } from "./tenant.ts";
|
|
12
12
|
export { diskProbe } from "./disk.ts";
|
|
13
13
|
export { checkpointsPath, readCheckpointFile } from "./checkpoints.ts";
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { FileLedger, MemoryLedger, readLedgerTail, lockHolderAlive, lockState, l
|
|
|
6
6
|
export { indexCoverage, listPieceFiles } from "./ledger-manifest.js";
|
|
7
7
|
export { explain } from "./explain.js";
|
|
8
8
|
export { approvePending, approvalsLogFor, createApprovalBudgetGuard, enqueueApprovalCommand, loadApprovalsFromDir, } from "./approvals.js";
|
|
9
|
-
export { loadDecisionRefsFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile } from "./reconcile.js";
|
|
9
|
+
export { loadDecisionRefsFromDir, loadDecisionRequestHashesFromDir, loadEffectsFromDir, parseCardCsv, parseChannelJsonl, reconcile, } from "./reconcile.js";
|
|
10
10
|
export { tenantKey } from "./tenant.js";
|
|
11
11
|
// The body writes checkpoints and signs its own effect attestations. Both were
|
|
12
12
|
// reached through a relative path into this package, which only exists inside
|
package/dist/reconcile.d.ts
CHANGED
|
@@ -69,6 +69,11 @@ export declare function parseCardCsv(text: string, opts: CardCsvOpts): ParsedCar
|
|
|
69
69
|
export declare function parseChannelJsonl(text: string): ChannelRow[];
|
|
70
70
|
/** Decision refs, read the same way `verifyLedger` lists decision files. */
|
|
71
71
|
export declare function loadDecisionRefsFromDir(stateDir: string): Set<string>;
|
|
72
|
+
/**
|
|
73
|
+
* requestHash on each decision, keyed by that decision's ref.
|
|
74
|
+
* Same files as `loadDecisionRefsFromDir`, still without the ledger lock.
|
|
75
|
+
*/
|
|
76
|
+
export declare function loadDecisionRequestHashesFromDir(stateDir: string): Map<string, string>;
|
|
72
77
|
export declare function loadEffectsFromDir(stateDir: string): LedgerEffect[];
|
|
73
78
|
export declare function reconcile(channelRows: readonly ChannelRow[], effects: readonly LedgerEffect[], opts?: {
|
|
74
79
|
toleranceMs?: number;
|
|
@@ -81,4 +86,6 @@ export declare function reconcile(channelRows: readonly ChannelRow[], effects: r
|
|
|
81
86
|
descriptorsByPayee?: Readonly<Record<string, readonly string[]>>;
|
|
82
87
|
/** Effect refs that have a decision. Absent means none: an effect is not a match. */
|
|
83
88
|
decisionRefs?: ReadonlySet<string>;
|
|
89
|
+
/** Effect ref to the requestHash on the signed decision of that ref. */
|
|
90
|
+
decisionRequestHashes?: ReadonlyMap<string, string>;
|
|
84
91
|
}): ReconcileReport;
|
package/dist/reconcile.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { sha256Canonical } from "./hash.js";
|
|
4
5
|
import { readLedgerManifest, requireLedgerPiecePath } from "./ledger-manifest.js";
|
|
5
6
|
function asChannelRow(raw, line) {
|
|
6
7
|
if (raw === null || typeof raw !== "object") {
|
|
@@ -221,9 +222,8 @@ function decisionPaths(dir) {
|
|
|
221
222
|
const tek = join(dir, "decisions.jsonl");
|
|
222
223
|
return existsSync(tek) ? [tek] : [];
|
|
223
224
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const refs = new Set();
|
|
225
|
+
function readDecisionLines(stateDir) {
|
|
226
|
+
const claims = [];
|
|
227
227
|
for (const path of decisionPaths(stateDir)) {
|
|
228
228
|
let text = "";
|
|
229
229
|
try {
|
|
@@ -238,12 +238,35 @@ export function loadDecisionRefsFromDir(stateDir) {
|
|
|
238
238
|
if (line === "")
|
|
239
239
|
continue;
|
|
240
240
|
const row = JSON.parse(line);
|
|
241
|
-
|
|
242
|
-
refs.add(row.claims.ref);
|
|
241
|
+
claims.push(row.claims ?? {});
|
|
243
242
|
}
|
|
244
243
|
}
|
|
244
|
+
return claims;
|
|
245
|
+
}
|
|
246
|
+
/** Decision refs, read the same way `verifyLedger` lists decision files. */
|
|
247
|
+
export function loadDecisionRefsFromDir(stateDir) {
|
|
248
|
+
const refs = new Set();
|
|
249
|
+
for (const claims of readDecisionLines(stateDir)) {
|
|
250
|
+
if (typeof claims.ref === "string")
|
|
251
|
+
refs.add(claims.ref);
|
|
252
|
+
}
|
|
245
253
|
return refs;
|
|
246
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* requestHash on each decision, keyed by that decision's ref.
|
|
257
|
+
* Same files as `loadDecisionRefsFromDir`, still without the ledger lock.
|
|
258
|
+
*/
|
|
259
|
+
export function loadDecisionRequestHashesFromDir(stateDir) {
|
|
260
|
+
const hashes = new Map();
|
|
261
|
+
for (const claims of readDecisionLines(stateDir)) {
|
|
262
|
+
if (typeof claims.ref !== "string")
|
|
263
|
+
continue;
|
|
264
|
+
if (typeof claims.requestHash !== "string" || claims.requestHash === "")
|
|
265
|
+
continue;
|
|
266
|
+
hashes.set(claims.ref, claims.requestHash);
|
|
267
|
+
}
|
|
268
|
+
return hashes;
|
|
269
|
+
}
|
|
247
270
|
export function loadEffectsFromDir(stateDir) {
|
|
248
271
|
try {
|
|
249
272
|
const text = readFileSync(join(stateDir, "effects.jsonl"), "utf8");
|
|
@@ -289,8 +312,23 @@ function approvalForEffect(approvals, effectRef) {
|
|
|
289
312
|
return undefined;
|
|
290
313
|
return approvals.find((r) => r.allowRef === effectRef || r.ref === effectRef);
|
|
291
314
|
}
|
|
292
|
-
|
|
315
|
+
/** The row may lend amount, currency and payee only when it still hashes to the signed request. */
|
|
316
|
+
function boundApproval(effect, approvals, requestHashes) {
|
|
317
|
+
if (!requestHashes)
|
|
318
|
+
return undefined;
|
|
319
|
+
const signed = requestHashes.get(effect.row.ref);
|
|
320
|
+
if (typeof signed !== "string" || signed === "")
|
|
321
|
+
return undefined;
|
|
293
322
|
const snap = approvalForEffect(approvals, effect.row.ref);
|
|
323
|
+
if (!snap)
|
|
324
|
+
return undefined;
|
|
325
|
+
const rowHash = sha256Canonical({ name: snap.subject, arguments: snap.args });
|
|
326
|
+
if (rowHash !== signed)
|
|
327
|
+
return undefined;
|
|
328
|
+
return snap;
|
|
329
|
+
}
|
|
330
|
+
function effectAmount(effect, approvals, requestHashes) {
|
|
331
|
+
const snap = boundApproval(effect, approvals, requestHashes);
|
|
294
332
|
const amountMinor = snap && typeof snap.args.amountMinor === "number" ? snap.args.amountMinor : undefined;
|
|
295
333
|
const currency = snap && typeof snap.args.currency === "string" ? snap.args.currency : undefined;
|
|
296
334
|
return { amountMinor, currency };
|
|
@@ -315,10 +353,10 @@ function amountGate(row, fromSnap) {
|
|
|
315
353
|
}
|
|
316
354
|
return "match";
|
|
317
355
|
}
|
|
318
|
-
function descriptorsFor(effect, approvals, byPayee) {
|
|
356
|
+
function descriptorsFor(effect, approvals, byPayee, requestHashes) {
|
|
319
357
|
if (!byPayee)
|
|
320
358
|
return undefined;
|
|
321
|
-
const snap =
|
|
359
|
+
const snap = boundApproval(effect, approvals, requestHashes);
|
|
322
360
|
const payee = snap && typeof snap.args.payee === "string" ? snap.args.payee : undefined;
|
|
323
361
|
if (!payee)
|
|
324
362
|
return undefined;
|
|
@@ -392,7 +430,7 @@ export function reconcile(channelRows, effects, opts) {
|
|
|
392
430
|
ghost.push(asGhost(marked, effects));
|
|
393
431
|
continue;
|
|
394
432
|
}
|
|
395
|
-
const fromSnap = effectAmount(effects[idx], opts?.approvals);
|
|
433
|
+
const fromSnap = effectAmount(effects[idx], opts?.approvals, opts?.decisionRequestHashes);
|
|
396
434
|
const gate = amountGate(row, fromSnap);
|
|
397
435
|
if (gate === "unknown") {
|
|
398
436
|
ghost.push(asGhost(marked, effects, "amount-unknown"));
|
|
@@ -418,7 +456,7 @@ export function reconcile(channelRows, effects, opts) {
|
|
|
418
456
|
return false;
|
|
419
457
|
if (Math.abs(row.occurredAtMs - e.row.timestampMs) > rowTol)
|
|
420
458
|
return false;
|
|
421
|
-
const stamps = descriptorsFor(e, opts?.approvals, opts?.descriptorsByPayee);
|
|
459
|
+
const stamps = descriptorsFor(e, opts?.approvals, opts?.descriptorsByPayee, opts?.decisionRequestHashes);
|
|
422
460
|
if (stamps) {
|
|
423
461
|
const text = row.descriptor ?? "";
|
|
424
462
|
if (!descriptorHits(text, stamps)) {
|
|
@@ -426,7 +464,7 @@ export function reconcile(channelRows, effects, opts) {
|
|
|
426
464
|
return false;
|
|
427
465
|
}
|
|
428
466
|
}
|
|
429
|
-
const fromSnap = effectAmount(e, opts?.approvals);
|
|
467
|
+
const fromSnap = effectAmount(e, opts?.approvals, opts?.decisionRequestHashes);
|
|
430
468
|
const gate = amountGate(row, fromSnap);
|
|
431
469
|
if (gate === "unknown") {
|
|
432
470
|
unknownNear = true;
|