@agent-custody/receipts 0.6.19 → 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/README.md +20 -11
- package/dist/a2a.js +19 -7
- package/dist/approval.d.ts +74 -0
- package/dist/approval.js +196 -0
- package/dist/capture.d.ts +153 -0
- package/dist/capture.js +607 -0
- package/dist/cli.js +221 -6
- package/dist/config.d.ts +144 -0
- package/dist/config.js +92 -3
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +7 -4
- package/dist/delegation.d.ts +7 -0
- package/dist/delegation.js +15 -1
- package/dist/gateway-http.js +13 -1
- package/dist/gateway.d.ts +15 -0
- package/dist/gateway.js +414 -27
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/issue.d.ts +20 -5
- package/dist/issue.js +76 -8
- package/dist/log-sink.d.ts +11 -1
- package/dist/log-sink.js +24 -5
- package/dist/operations.d.ts +101 -0
- package/dist/operations.js +239 -0
- package/dist/otel.js +16 -8
- package/dist/portal.d.ts +23 -2
- package/dist/portal.js +181 -36
- package/dist/receipt.d.ts +54 -8
- package/dist/rest.js +14 -1
- package/dist/retention.d.ts +8 -1
- package/dist/retention.js +21 -2
- package/dist/sdk/index.js +10 -1
- package/dist/simulate.d.ts +58 -0
- package/dist/simulate.js +204 -0
- package/dist/splunk.js +17 -8
- package/dist/upstream.d.ts +9 -7
- package/dist/upstream.js +16 -8
- package/dist/verify.d.ts +18 -0
- package/dist/verify.js +405 -15
- package/docs/approvals.md +107 -0
- package/docs/compliance.md +1 -1
- package/docs/financial-operations.md +99 -0
- package/docs/policies.md +22 -0
- package/docs/tutorials.md +7 -0
- package/docs/usage.md +71 -5
- package/docs/verification.md +35 -10
- package/package.json +1 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +3612 -292
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { hostname, userInfo } from "node:os";
|
|
3
|
+
import { captureKeyFrom, getAt, pathText, restorePaths, setAt } from "./capture.js";
|
|
4
|
+
import { saltsFileFor } from "./retention.js";
|
|
3
5
|
import { parseArgs } from "node:util";
|
|
4
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { dirname, resolve } from "node:path";
|
|
6
|
+
import { closeSync, constants as fsConstants, existsSync, fchmodSync, openSync, readFileSync, readdirSync, writeFileSync, writeSync } from "node:fs";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
8
|
import { loadConfig, loadSdkConfig } from "./config.js";
|
|
7
|
-
import { generateKeyPair, loadPrivateKey, loadPublicKey, writeKeyPair } from "./crypto.js";
|
|
8
|
-
import { createDelegation, decodeDelegation, delegateFrom } from "./delegation.js";
|
|
9
|
-
import { createGateway, createGatewayHost, serveStdio } from "./gateway.js";
|
|
9
|
+
import { dsseVerify, generateKeyPair, loadPrivateKey, loadPublicKey, writeKeyPair } from "./crypto.js";
|
|
10
|
+
import { createDelegation, decodeDelegation, delegateFrom, grantDigest } from "./delegation.js";
|
|
11
|
+
import { createGateway, createGatewayHost, serveStdio, writeRevokedGrants } from "./gateway.js";
|
|
10
12
|
import { postgresResolver, serveLog } from "./log-sink.js";
|
|
11
13
|
import { importLogFile, PostgresTenancy } from "./log-store.js";
|
|
12
14
|
import { bothCheckpoints, dirCheckpoints, postgresCheckpoints } from "./checkpoints.js";
|
|
@@ -26,6 +28,7 @@ import { MerkleLog } from "./log.js";
|
|
|
26
28
|
import { createSdkIssuer } from "./sdk/index.js";
|
|
27
29
|
import { handleHookEvent } from "./sdk/claude.js";
|
|
28
30
|
import { auditExtends, formatReport, verifyBundle } from "./verify.js";
|
|
31
|
+
import { formatSimulation, simulatePolicy, verifyOrphanAuthorization } from "./simulate.js";
|
|
29
32
|
/** A shared secret from an environment variable; never from the command line, where it would land in shell history. */
|
|
30
33
|
function secretFrom(envName) {
|
|
31
34
|
const v = process.env[envName];
|
|
@@ -40,6 +43,11 @@ const USAGE = `agent-custody <command>
|
|
|
40
43
|
--agent-key names the agent's own key in the grant, so the agent may delegate
|
|
41
44
|
delegate --key <agent.key> --parent <grant.json> --agent <sub-agent> --scopes <a,b> [--ttl-hours N] [--agent-key <sub.pub>] --out <file>
|
|
42
45
|
a narrower grant for a sub-agent, signed by the agent the parent names; the parent travels inside
|
|
46
|
+
reveal <bundle> --capture-key-env NAME --issuer-key <pub> [--out <file>] [--include-salts] the values a receipt withheld (capture mode encrypted), as a disclosure file
|
|
47
|
+
for verify --disclose; needs the customer's capture key
|
|
48
|
+
revoke --config <gateway.json> --grant <grant.json> revokes a grant: its digest goes into the config's revokedGrants file, every
|
|
49
|
+
session under it or under a grant delegated from it refuses its next call, and no new session opens for them
|
|
50
|
+
reconcile --config <gateway.json> --operation <uuid> operator-only provider lookup; commits a receipt before closing an unknown/pending financial operation
|
|
43
51
|
gateway --config <gateway.json> [--http [--port 8790] [--host 127.0.0.1] [--idle-minutes 30]]
|
|
44
52
|
stdio: one gateway for the grant the config names. --http: one shared gateway, MCP over
|
|
45
53
|
Streamable HTTP at /mcp, each connection presenting its own grant as Authorization: Bearer
|
|
@@ -48,7 +56,10 @@ const USAGE = `agent-custody <command>
|
|
|
48
56
|
prune --log <log.jsonl> --before <ISO instant> [--receipts <dir>]
|
|
49
57
|
retention on the receipt log: replaces older leaves with their hashes, so proofs still verify and the content is gone
|
|
50
58
|
log --file <log.jsonl> --key <log.key> [--port 8787] [--host 127.0.0.1] [--token-env <NAME>] reference log server
|
|
51
|
-
verify <bundle.json> --issuer-key <pub> [--principal-key <pub>] [--log-key <pub> | --log-url <url>] [--log-id <id>] [--upstream-key <pub>] [--stripe-secret-env NAME] [--github-secret-env NAME] [--log <log.jsonl>] [--json]
|
|
59
|
+
verify <bundle.json> --issuer-key <pub> [--principal-key <pub>] [--approval-key <pub>] [--log-key <pub> | --log-url <url>] [--log-id <id>] [--upstream-key <pub>] [--stripe-secret-env NAME] [--github-secret-env NAME] [--log <log.jsonl>] [--disclose <file>] [--capture-key-env NAME] [--json]
|
|
60
|
+
policy simulate --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--approval-key <pub>]... [--log-key <pub>]... [--json] [--out <file>]
|
|
61
|
+
replay verified local receipts against a proposed policy using their recorded inputs;
|
|
62
|
+
--out saves the full JSON report. Exits 1 when any call could not be evaluated.
|
|
52
63
|
log ... --db-env NAME the same server over Postgres: tenants and tokens from the database, one writer per tenant,
|
|
53
64
|
root paths serve the tenant "default" (created with --log-id). Needs the pg package.
|
|
54
65
|
log ... (--key <log.key> [--retired-key <pub>]... | --signer-url <url> [--signer-token-env NAME]) [--checkpoint-dir <dir>] [--checkpoint-every <seconds>] [--checkpoint-heartbeat <seconds>]
|
|
@@ -122,6 +133,22 @@ function loadTenants(path) {
|
|
|
122
133
|
async function main(argv) {
|
|
123
134
|
const [cmd, ...rest] = argv;
|
|
124
135
|
switch (cmd) {
|
|
136
|
+
case "reconcile": {
|
|
137
|
+
const { values } = parseArgs({ args: rest, options: { config: { type: "string" }, operation: { type: "string" } } });
|
|
138
|
+
if (!values.config || !values.operation)
|
|
139
|
+
throw new Error("reconcile needs --config and --operation");
|
|
140
|
+
const cfg = loadConfig(values.config);
|
|
141
|
+
const host = await createGatewayHost(cfg);
|
|
142
|
+
try {
|
|
143
|
+
const bundle = await host.reconcile(values.operation);
|
|
144
|
+
const p = JSON.parse(Buffer.from(bundle.envelope.payload, "base64").toString("utf8")).predicate;
|
|
145
|
+
console.log(JSON.stringify({ operation: values.operation, status: p.operation.status, receipt: join(cfg.receiptsDir, `${p.receiptId}.json`) }));
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
await host.close();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
125
152
|
case "keygen": {
|
|
126
153
|
const { values } = parseArgs({ args: rest, options: { dir: { type: "string" }, name: { type: "string" } } });
|
|
127
154
|
if (!values.dir || !values.name)
|
|
@@ -176,6 +203,24 @@ async function main(argv) {
|
|
|
176
203
|
console.log(`delegated to ${chain.agent}: scopes [${chain.scopes.join(", ")}] until ${chain.expiresAt}, under ${decodeDelegation(parent).agent}'s grant from ${chain.principal}`);
|
|
177
204
|
return 0;
|
|
178
205
|
}
|
|
206
|
+
case "revoke": {
|
|
207
|
+
const { values } = parseArgs({ args: rest, options: { config: { type: "string" }, grant: { type: "string" } } });
|
|
208
|
+
if (!values.config || !values.grant)
|
|
209
|
+
throw new Error("revoke needs --config and --grant");
|
|
210
|
+
const cfg = loadConfig(values.config);
|
|
211
|
+
if (!cfg.revokedGrants)
|
|
212
|
+
throw new Error("revoke needs revokedGrants in the config: the file the gateway re-reads on every call");
|
|
213
|
+
const envelope = JSON.parse(readFileSync(values.grant, "utf8"));
|
|
214
|
+
const chain = decodeDelegation(envelope);
|
|
215
|
+
if (!chain)
|
|
216
|
+
throw new Error(`${values.grant} is not a delegation grant`);
|
|
217
|
+
const digest = grantDigest(envelope);
|
|
218
|
+
const list = existsSync(cfg.revokedGrants) ? JSON.parse(readFileSync(cfg.revokedGrants, "utf8")) : [];
|
|
219
|
+
if (!list.includes(digest))
|
|
220
|
+
writeRevokedGrants(cfg.revokedGrants, [...list, digest]);
|
|
221
|
+
console.log(`revoked ${chain.agent}'s grant from ${chain.principal} (${digest.slice(0, 12)}…): ${cfg.revokedGrants} now lists ${list.includes(digest) ? list.length : list.length + 1} grant(s); a running gateway refuses it on its next call`);
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
179
224
|
case "gateway": {
|
|
180
225
|
const { values } = parseArgs({ args: rest, options: { config: { type: "string" }, http: { type: "boolean", default: false }, a2a: { type: "boolean", default: false }, port: { type: "string", default: "8790" }, host: { type: "string", default: "127.0.0.1" }, "idle-minutes": { type: "string", default: "30" } } });
|
|
181
226
|
if (!values.config)
|
|
@@ -494,6 +539,7 @@ async function main(argv) {
|
|
|
494
539
|
"issuer-key": { type: "string", multiple: true },
|
|
495
540
|
"gateway-key": { type: "string", multiple: true },
|
|
496
541
|
"principal-key": { type: "string", multiple: true },
|
|
542
|
+
"approval-key": { type: "string", multiple: true },
|
|
497
543
|
"log-key": { type: "string", multiple: true },
|
|
498
544
|
"log-url": { type: "string" },
|
|
499
545
|
"log-id": { type: "string" },
|
|
@@ -501,6 +547,8 @@ async function main(argv) {
|
|
|
501
547
|
"stripe-secret-env": { type: "string" },
|
|
502
548
|
"github-secret-env": { type: "string" },
|
|
503
549
|
log: { type: "string" },
|
|
550
|
+
disclose: { type: "string" },
|
|
551
|
+
"capture-key-env": { type: "string" },
|
|
504
552
|
json: { type: "boolean", default: false },
|
|
505
553
|
},
|
|
506
554
|
});
|
|
@@ -509,20 +557,187 @@ async function main(argv) {
|
|
|
509
557
|
if (!file || issuerKeyFiles.length === 0)
|
|
510
558
|
throw new Error("verify needs <bundle> --issuer-key (alias --gateway-key)");
|
|
511
559
|
const bundle = JSON.parse(readFileSync(file, "utf8"));
|
|
560
|
+
const captureKey = values["capture-key-env"] ? captureKeyFrom(secretFrom(values["capture-key-env"])) : undefined;
|
|
561
|
+
const disclosed = values.disclose ? JSON.parse(readFileSync(values.disclose, "utf8")) : undefined;
|
|
512
562
|
const fetchedLogKeys = values["log-url"] ? (await fetchLogKeys(values["log-url"])).keys : [];
|
|
513
563
|
const logKeys = [...(values["log-key"] ?? []).map(loadPublicKey), ...fetchedLogKeys];
|
|
514
564
|
const result = verifyBundle(bundle, {
|
|
515
565
|
issuerKeys: issuerKeyFiles.map(loadPublicKey),
|
|
516
566
|
principalKeys: (values["principal-key"] ?? []).map(loadPublicKey),
|
|
567
|
+
...(values["approval-key"] ? { approvalKeys: values["approval-key"].map(loadPublicKey) } : {}),
|
|
517
568
|
...(logKeys.length ? { logKeys } : {}),
|
|
518
569
|
...(values["log-id"] ? { logId: values["log-id"] } : {}),
|
|
519
570
|
...(values["upstream-key"] ? { upstreamKeys: values["upstream-key"].map(loadPublicKey) } : {}),
|
|
520
571
|
...(values["stripe-secret-env"] || values["github-secret-env"] ? { providerSecrets: { ...(values["stripe-secret-env"] ? { stripe: secretFrom(values["stripe-secret-env"]) } : {}), ...(values["github-secret-env"] ? { github: secretFrom(values["github-secret-env"]) } : {}) } } : {}),
|
|
521
572
|
...(values.log ? { logFile: values.log } : {}),
|
|
573
|
+
...(captureKey ? { captureKey } : {}),
|
|
574
|
+
...(disclosed ? { disclosed } : {}),
|
|
522
575
|
});
|
|
523
576
|
console.log(values.json ? JSON.stringify(result, null, 2) : formatReport(result));
|
|
524
577
|
return result.ok ? 0 : 1;
|
|
525
578
|
}
|
|
579
|
+
case "policy": {
|
|
580
|
+
const [subcommand, ...args] = rest;
|
|
581
|
+
if (subcommand !== "simulate")
|
|
582
|
+
throw new Error("policy needs the simulate subcommand: policy simulate --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>");
|
|
583
|
+
const { values } = parseArgs({
|
|
584
|
+
args,
|
|
585
|
+
options: {
|
|
586
|
+
policy: { type: "string" },
|
|
587
|
+
receipts: { type: "string" },
|
|
588
|
+
"issuer-key": { type: "string", multiple: true },
|
|
589
|
+
"principal-key": { type: "string", multiple: true },
|
|
590
|
+
"approval-key": { type: "string", multiple: true },
|
|
591
|
+
"log-key": { type: "string", multiple: true },
|
|
592
|
+
"capture-key-env": { type: "string" },
|
|
593
|
+
disclose: { type: "string", multiple: true },
|
|
594
|
+
json: { type: "boolean", default: false },
|
|
595
|
+
out: { type: "string" },
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
if (!values.policy || !values.receipts || !values["issuer-key"]?.length)
|
|
599
|
+
throw new Error("policy simulate needs --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>");
|
|
600
|
+
const policy = readFileSync(values.policy, "utf8");
|
|
601
|
+
const keys = {
|
|
602
|
+
issuerKeys: values["issuer-key"].map(loadPublicKey),
|
|
603
|
+
principalKeys: (values["principal-key"] ?? []).map(loadPublicKey),
|
|
604
|
+
approvalKeys: (values["approval-key"] ?? []).map(loadPublicKey),
|
|
605
|
+
logKeys: (values["log-key"] ?? []).map(loadPublicKey),
|
|
606
|
+
};
|
|
607
|
+
const names = readdirSync(values.receipts, { withFileTypes: true })
|
|
608
|
+
.filter((entry) => (entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".json"))
|
|
609
|
+
.map((entry) => entry.name);
|
|
610
|
+
const AUTHORIZATION = ".authorization.json";
|
|
611
|
+
const files = names.filter((name) => !name.endsWith(AUTHORIZATION)).sort();
|
|
612
|
+
const have = new Set(files);
|
|
613
|
+
const fail = (file, error) => { throw new Error(`policy simulate: ${file}: ${error instanceof Error ? error.message : String(error)}`); };
|
|
614
|
+
// A gateway that dies after it forwards a precommit call leaves <id>.authorization.json and no <id>.json. That
|
|
615
|
+
// call went upstream, so it counts as skipped and the report is incomplete.
|
|
616
|
+
const unreplayable = names.filter((name) => name.endsWith(AUTHORIZATION) && !have.has(`${name.slice(0, -AUTHORIZATION.length)}.json`)).sort().map((name) => {
|
|
617
|
+
const file = join(values.receipts, name);
|
|
618
|
+
try {
|
|
619
|
+
const p = verifyOrphanAuthorization(JSON.parse(readFileSync(file, "utf8")), keys.issuerKeys, keys.logKeys);
|
|
620
|
+
if (`${p.receiptId}${AUTHORIZATION}` !== name)
|
|
621
|
+
throw new Error("the file name does not match the receipt id in the authorization");
|
|
622
|
+
return { receiptId: p.receiptId, tool: p.tool.name, reason: "only the authorization survives; the receipt is missing, so the outcome and the call cannot be replayed" };
|
|
623
|
+
}
|
|
624
|
+
catch (error) {
|
|
625
|
+
return fail(file, error);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
if (!files.length && !unreplayable.length)
|
|
629
|
+
throw new Error(`policy simulate: no receipt bundles found in ${values.receipts}`);
|
|
630
|
+
const captureKey = values["capture-key-env"] ? captureKeyFrom(secretFrom(values["capture-key-env"])) : undefined;
|
|
631
|
+
const disclosures = new Map();
|
|
632
|
+
for (const file of values.disclose ?? []) {
|
|
633
|
+
try {
|
|
634
|
+
const disclosure = JSON.parse(readFileSync(file, "utf8"));
|
|
635
|
+
if (typeof disclosure?.receiptId !== "string")
|
|
636
|
+
throw new Error("the disclosure names no receiptId");
|
|
637
|
+
disclosures.set(disclosure.receiptId, disclosure);
|
|
638
|
+
}
|
|
639
|
+
catch (error) {
|
|
640
|
+
fail(file, error);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
// One bundle at a time: the replay needs the predicate of the receipt it is on, not the results of the others.
|
|
644
|
+
function* verified() {
|
|
645
|
+
for (const name of files) {
|
|
646
|
+
const file = join(values.receipts, name);
|
|
647
|
+
try {
|
|
648
|
+
const bundle = JSON.parse(readFileSync(file, "utf8"));
|
|
649
|
+
const result = verifyBundle(bundle, keys);
|
|
650
|
+
if (!result.ok || !result.statement) {
|
|
651
|
+
const failures = result.checks.filter((check) => !check.ok).map((check) => `${check.name}${check.detail ? ` (${check.detail})` : ""}`);
|
|
652
|
+
throw new Error(`receipt verification failed: ${failures.join("; ")}`);
|
|
653
|
+
}
|
|
654
|
+
yield result.statement.predicate;
|
|
655
|
+
}
|
|
656
|
+
catch (error) {
|
|
657
|
+
fail(file, error);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const report = simulatePolicy(policy, verified(), { unreplayable, ...(captureKey ? { captureKey } : {}), disclosures });
|
|
662
|
+
const json = JSON.stringify(report, null, 2);
|
|
663
|
+
if (values.out) {
|
|
664
|
+
// Reports name calls and decisions: keep them owner-only, including when replacing an existing file.
|
|
665
|
+
const fd = openSync(values.out, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_TRUNC | fsConstants.O_NOFOLLOW, 0o600);
|
|
666
|
+
try {
|
|
667
|
+
fchmodSync(fd, 0o600);
|
|
668
|
+
writeSync(fd, json);
|
|
669
|
+
}
|
|
670
|
+
finally {
|
|
671
|
+
closeSync(fd);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
console.log(values.json ? json : formatSimulation(report));
|
|
675
|
+
return report.complete ? 0 : 1;
|
|
676
|
+
}
|
|
677
|
+
case "reveal": {
|
|
678
|
+
// The values a receipt withheld, under the customer's key, as a disclosure file: hand it to a reviewer with the
|
|
679
|
+
// receipt, and `verify --disclose` recomputes every digest from it.
|
|
680
|
+
const { values, positionals } = parseArgs({ args: rest, allowPositionals: true, options: { "capture-key-env": { type: "string" }, "issuer-key": { type: "string", multiple: true }, out: { type: "string" }, "include-salts": { type: "boolean" } } });
|
|
681
|
+
const file = positionals[0];
|
|
682
|
+
if (!file || !values["capture-key-env"] || !values["issuer-key"]?.length)
|
|
683
|
+
throw new Error("reveal needs <bundle> --capture-key-env NAME --issuer-key <pub> [--out disclosure.json] [--include-salts]");
|
|
684
|
+
const key = captureKeyFrom(secretFrom(values["capture-key-env"]));
|
|
685
|
+
const bundle = JSON.parse(readFileSync(file, "utf8"));
|
|
686
|
+
// only the issuer's own statement is decrypted: a bundle someone assembled around another receipt's ciphertexts is refused before any value comes back
|
|
687
|
+
const signed = dsseVerify(bundle.envelope, values["issuer-key"].map((f) => loadPublicKey(f)));
|
|
688
|
+
if (!signed.ok)
|
|
689
|
+
throw new Error(`reveal: the bundle is not signed by the issuer key given (${signed.error}); nothing is revealed`);
|
|
690
|
+
const p = signed.payload.predicate;
|
|
691
|
+
// Every withheld path the key reveals goes into the disclosure at its own path, value and salt. A path withheld
|
|
692
|
+
// as a digest only carries no value to reveal, and its salt is not written unless asked for (--include-salts):
|
|
693
|
+
// a salt beside no value would hand a reviewer the means to confirm guesses, and a file that carries one does
|
|
694
|
+
// not verify until the holder fills in the value.
|
|
695
|
+
const back = restorePaths(p, p.capture, undefined, key);
|
|
696
|
+
for (const x of back.problems)
|
|
697
|
+
throw new Error(x.error);
|
|
698
|
+
// the id comes from the bundle: it is checked before it becomes part of a path
|
|
699
|
+
const saltsFile = saltsFileFor(dirname(file), p.receiptId);
|
|
700
|
+
const kept = values["include-salts"] && existsSync(saltsFile) ? JSON.parse(readFileSync(saltsFile, "utf8")).salts ?? {} : {};
|
|
701
|
+
let disclosure = { receiptId: p.receiptId };
|
|
702
|
+
let saltsWritten = 0;
|
|
703
|
+
for (const path of p.capture?.withheld ?? []) {
|
|
704
|
+
const k = JSON.stringify(path);
|
|
705
|
+
if (back.restored.has(k))
|
|
706
|
+
disclosure = setAt(disclosure, path, { $custody: "disclosed", salt: back.salts.get(k), value: back.values.get(k) });
|
|
707
|
+
else if (kept[k]) {
|
|
708
|
+
disclosure = setAt(disclosure, path, { $custody: "disclosed", salt: kept[k] });
|
|
709
|
+
saltsWritten++;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
// a value withheld without its value cannot be revealed by anyone but its holder; one encrypted under another key is a different matter, said separately
|
|
713
|
+
const foreign = back.missing.filter((w) => getAt(p, w)?.$custody === "encrypted");
|
|
714
|
+
const notRevealed = back.missing.filter((w) => !foreign.includes(w)).map(pathText);
|
|
715
|
+
const foreignNote = foreign.length ? ` Encrypted under key ${String(getAt(p, foreign[0]).keyid).slice(0, 12)}…, not the one given: ${foreign.map(pathText).join(", ")}.` : "";
|
|
716
|
+
if (foreign.length && back.restored.size === 0)
|
|
717
|
+
throw new Error(`reveal: nothing revealed; the values are encrypted under key ${String(getAt(p, foreign[0]).keyid).slice(0, 12)}…, not the one given`);
|
|
718
|
+
const text = JSON.stringify(disclosure, null, 2);
|
|
719
|
+
const how = saltsWritten ? `; their salts are written in the file for the holder to add \"value\" beside, and the file does not verify until then: do not hand it over unfinished` : values["include-salts"] ? ` (no salts file at ${saltsFile})` : `; --include-salts writes their salts from ${saltsFile} for the holder to complete`;
|
|
720
|
+
const note = (notRevealed.length ? ` Not revealed, withheld without a value: ${notRevealed.join(", ")}; only the party that holds them can disclose them${how}.` : "") + foreignNote;
|
|
721
|
+
if (values.out) {
|
|
722
|
+
// decrypted values and salts: the owner's alone, whatever the umask, whatever mode a file already there had,
|
|
723
|
+
// and never through a symlink someone left at that name
|
|
724
|
+
const fd = openSync(values.out, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_TRUNC | fsConstants.O_NOFOLLOW, 0o600);
|
|
725
|
+
try {
|
|
726
|
+
fchmodSync(fd, 0o600);
|
|
727
|
+
writeSync(fd, text);
|
|
728
|
+
}
|
|
729
|
+
finally {
|
|
730
|
+
closeSync(fd);
|
|
731
|
+
}
|
|
732
|
+
console.log(`disclosure for receipt ${p.receiptId} written to ${values.out}; verify it with --disclose ${values.out}.${note}`);
|
|
733
|
+
}
|
|
734
|
+
else {
|
|
735
|
+
console.log(text);
|
|
736
|
+
if (note)
|
|
737
|
+
console.error(note.trim());
|
|
738
|
+
}
|
|
739
|
+
return 0;
|
|
740
|
+
}
|
|
526
741
|
case "audit": {
|
|
527
742
|
const { values } = parseArgs({
|
|
528
743
|
args: rest,
|
package/dist/config.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare const RestToolSchema: z.ZodObject<{
|
|
|
16
16
|
json: "json";
|
|
17
17
|
none: "none";
|
|
18
18
|
}>>;
|
|
19
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
19
20
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
20
21
|
}, z.core.$strip>;
|
|
21
22
|
export type RestToolConfig = z.infer<typeof RestToolSchema>;
|
|
@@ -41,6 +42,7 @@ declare const RestUpstreamSchema: z.ZodObject<{
|
|
|
41
42
|
json: "json";
|
|
42
43
|
none: "none";
|
|
43
44
|
}>>;
|
|
45
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
44
46
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
47
|
}, z.core.$strip>>;
|
|
46
48
|
}, z.core.$strip>;
|
|
@@ -83,6 +85,7 @@ declare const UpstreamSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
83
85
|
json: "json";
|
|
84
86
|
none: "none";
|
|
85
87
|
}>>;
|
|
88
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
86
89
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
87
90
|
}, z.core.$strip>>;
|
|
88
91
|
}, z.core.$strip>;
|
|
@@ -103,6 +106,48 @@ declare const FactSchema: z.ZodObject<{
|
|
|
103
106
|
forTools: z.ZodArray<z.ZodString>;
|
|
104
107
|
optional: z.ZodDefault<z.ZodBoolean>;
|
|
105
108
|
}, z.core.$strip>;
|
|
109
|
+
declare const OperationToolSchema: z.ZodObject<{
|
|
110
|
+
tool: z.ZodString;
|
|
111
|
+
budget: z.ZodString;
|
|
112
|
+
amountField: z.ZodDefault<z.ZodString>;
|
|
113
|
+
currencyField: z.ZodDefault<z.ZodString>;
|
|
114
|
+
idempotencyHeader: z.ZodDefault<z.ZodString>;
|
|
115
|
+
reconcile: z.ZodObject<{
|
|
116
|
+
tool: z.ZodString;
|
|
117
|
+
args: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
118
|
+
statusPath: z.ZodString;
|
|
119
|
+
identityPath: z.ZodDefault<z.ZodString>;
|
|
120
|
+
confirmed: z.ZodArray<z.ZodString>;
|
|
121
|
+
failed: z.ZodArray<z.ZodString>;
|
|
122
|
+
pending: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
declare const OperationsSchema: z.ZodObject<{
|
|
126
|
+
database: z.ZodString;
|
|
127
|
+
budgets: z.ZodArray<z.ZodObject<{
|
|
128
|
+
id: z.ZodString;
|
|
129
|
+
currency: z.ZodString;
|
|
130
|
+
limit: z.ZodNumber;
|
|
131
|
+
}, z.core.$strip>>;
|
|
132
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
133
|
+
tool: z.ZodString;
|
|
134
|
+
budget: z.ZodString;
|
|
135
|
+
amountField: z.ZodDefault<z.ZodString>;
|
|
136
|
+
currencyField: z.ZodDefault<z.ZodString>;
|
|
137
|
+
idempotencyHeader: z.ZodDefault<z.ZodString>;
|
|
138
|
+
reconcile: z.ZodObject<{
|
|
139
|
+
tool: z.ZodString;
|
|
140
|
+
args: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
141
|
+
statusPath: z.ZodString;
|
|
142
|
+
identityPath: z.ZodDefault<z.ZodString>;
|
|
143
|
+
confirmed: z.ZodArray<z.ZodString>;
|
|
144
|
+
failed: z.ZodArray<z.ZodString>;
|
|
145
|
+
pending: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
146
|
+
}, z.core.$strip>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
}, z.core.$strip>;
|
|
149
|
+
export type OperationsConfig = z.infer<typeof OperationsSchema>;
|
|
150
|
+
export type OperationToolConfig = z.infer<typeof OperationToolSchema>;
|
|
106
151
|
export declare const GatewayConfigSchema: z.ZodObject<{
|
|
107
152
|
identity: z.ZodObject<{
|
|
108
153
|
keyFile: z.ZodString;
|
|
@@ -136,6 +181,7 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
136
181
|
json: "json";
|
|
137
182
|
none: "none";
|
|
138
183
|
}>>;
|
|
184
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
139
185
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
140
186
|
}, z.core.$strip>>;
|
|
141
187
|
}, z.core.$strip>;
|
|
@@ -177,6 +223,7 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
177
223
|
json: "json";
|
|
178
224
|
none: "none";
|
|
179
225
|
}>>;
|
|
226
|
+
idempotencyHeader: z.ZodOptional<z.ZodString>;
|
|
180
227
|
inputSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
181
228
|
}, z.core.$strip>>;
|
|
182
229
|
}, z.core.$strip>;
|
|
@@ -202,6 +249,72 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
202
249
|
optional: z.ZodDefault<z.ZodBoolean>;
|
|
203
250
|
}, z.core.$strip>>>;
|
|
204
251
|
precommit: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
252
|
+
approvals: z.ZodOptional<z.ZodObject<{
|
|
253
|
+
trustedKeys: z.ZodArray<z.ZodString>;
|
|
254
|
+
usedDir: z.ZodString;
|
|
255
|
+
maxLifetimeSeconds: z.ZodOptional<z.ZodNumber>;
|
|
256
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
257
|
+
tool: z.ZodString;
|
|
258
|
+
minApprovers: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
|
|
259
|
+
fields: z.ZodOptional<z.ZodObject<{
|
|
260
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
261
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
262
|
+
beneficiary: z.ZodOptional<z.ZodString>;
|
|
263
|
+
}, z.core.$strip>>;
|
|
264
|
+
}, z.core.$strip>>;
|
|
265
|
+
}, z.core.$strip>>;
|
|
266
|
+
operations: z.ZodOptional<z.ZodObject<{
|
|
267
|
+
database: z.ZodString;
|
|
268
|
+
budgets: z.ZodArray<z.ZodObject<{
|
|
269
|
+
id: z.ZodString;
|
|
270
|
+
currency: z.ZodString;
|
|
271
|
+
limit: z.ZodNumber;
|
|
272
|
+
}, z.core.$strip>>;
|
|
273
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
274
|
+
tool: z.ZodString;
|
|
275
|
+
budget: z.ZodString;
|
|
276
|
+
amountField: z.ZodDefault<z.ZodString>;
|
|
277
|
+
currencyField: z.ZodDefault<z.ZodString>;
|
|
278
|
+
idempotencyHeader: z.ZodDefault<z.ZodString>;
|
|
279
|
+
reconcile: z.ZodObject<{
|
|
280
|
+
tool: z.ZodString;
|
|
281
|
+
args: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
282
|
+
statusPath: z.ZodString;
|
|
283
|
+
identityPath: z.ZodDefault<z.ZodString>;
|
|
284
|
+
confirmed: z.ZodArray<z.ZodString>;
|
|
285
|
+
failed: z.ZodArray<z.ZodString>;
|
|
286
|
+
pending: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
287
|
+
}, z.core.$strip>;
|
|
288
|
+
}, z.core.$strip>>;
|
|
289
|
+
}, z.core.$strip>>;
|
|
290
|
+
revokedGrants: z.ZodOptional<z.ZodString>;
|
|
291
|
+
capture: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
292
|
+
args: z.ZodOptional<z.ZodObject<{
|
|
293
|
+
mode: z.ZodEnum<{
|
|
294
|
+
clear: "clear";
|
|
295
|
+
digest: "digest";
|
|
296
|
+
encrypted: "encrypted";
|
|
297
|
+
}>;
|
|
298
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
299
|
+
}, z.core.$strip>>;
|
|
300
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
301
|
+
mode: z.ZodEnum<{
|
|
302
|
+
clear: "clear";
|
|
303
|
+
digest: "digest";
|
|
304
|
+
encrypted: "encrypted";
|
|
305
|
+
}>;
|
|
306
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
307
|
+
}, z.core.$strip>>;
|
|
308
|
+
facts: z.ZodOptional<z.ZodObject<{
|
|
309
|
+
mode: z.ZodEnum<{
|
|
310
|
+
clear: "clear";
|
|
311
|
+
digest: "digest";
|
|
312
|
+
encrypted: "encrypted";
|
|
313
|
+
}>;
|
|
314
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
315
|
+
}, z.core.$strip>>;
|
|
316
|
+
}, z.core.$strip>>>;
|
|
317
|
+
captureKeyEnv: z.ZodOptional<z.ZodString>;
|
|
205
318
|
mode: z.ZodOptional<z.ZodEnum<{
|
|
206
319
|
enforce: "enforce";
|
|
207
320
|
observe: "observe";
|
|
@@ -213,6 +326,8 @@ export declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
213
326
|
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
214
327
|
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
215
328
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
329
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
330
|
+
logId: z.ZodOptional<z.ZodString>;
|
|
216
331
|
}, z.core.$strip>>;
|
|
217
332
|
otel: z.ZodOptional<z.ZodObject<{
|
|
218
333
|
url: z.ZodString;
|
|
@@ -250,6 +365,8 @@ export declare const SdkConfigSchema: z.ZodObject<{
|
|
|
250
365
|
tokenEnv: z.ZodOptional<z.ZodString>;
|
|
251
366
|
hashOnly: z.ZodOptional<z.ZodBoolean>;
|
|
252
367
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
368
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
369
|
+
logId: z.ZodOptional<z.ZodString>;
|
|
253
370
|
}, z.core.$strip>>;
|
|
254
371
|
otel: z.ZodOptional<z.ZodObject<{
|
|
255
372
|
url: z.ZodString;
|
|
@@ -265,6 +382,33 @@ export declare const SdkConfigSchema: z.ZodObject<{
|
|
|
265
382
|
host: z.ZodOptional<z.ZodString>;
|
|
266
383
|
}, z.core.$strip>>;
|
|
267
384
|
framework: z.ZodOptional<z.ZodString>;
|
|
385
|
+
capture: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
386
|
+
args: z.ZodOptional<z.ZodObject<{
|
|
387
|
+
mode: z.ZodEnum<{
|
|
388
|
+
clear: "clear";
|
|
389
|
+
digest: "digest";
|
|
390
|
+
encrypted: "encrypted";
|
|
391
|
+
}>;
|
|
392
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
393
|
+
}, z.core.$strip>>;
|
|
394
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
395
|
+
mode: z.ZodEnum<{
|
|
396
|
+
clear: "clear";
|
|
397
|
+
digest: "digest";
|
|
398
|
+
encrypted: "encrypted";
|
|
399
|
+
}>;
|
|
400
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
401
|
+
}, z.core.$strip>>;
|
|
402
|
+
facts: z.ZodOptional<z.ZodObject<{
|
|
403
|
+
mode: z.ZodEnum<{
|
|
404
|
+
clear: "clear";
|
|
405
|
+
digest: "digest";
|
|
406
|
+
encrypted: "encrypted";
|
|
407
|
+
}>;
|
|
408
|
+
clear: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
409
|
+
}, z.core.$strip>>;
|
|
410
|
+
}, z.core.$strip>>>;
|
|
411
|
+
captureKeyEnv: z.ZodOptional<z.ZodString>;
|
|
268
412
|
}, z.core.$strip>;
|
|
269
413
|
export type SdkConfig = z.infer<typeof SdkConfigSchema>;
|
|
270
414
|
export declare function loadSdkConfig(path: string): SdkConfig;
|