@agent-custody/receipts 0.12.0 → 0.14.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 -12
- package/dist/claude-init.d.ts +46 -0
- package/dist/claude-init.js +208 -0
- package/dist/cli.js +115 -0
- package/dist/completeness.d.ts +106 -0
- package/dist/completeness.js +240 -0
- package/dist/deny-report.d.ts +30 -0
- package/dist/deny-report.js +106 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/log-admin.js +3 -3
- package/dist/log.d.ts +13 -2
- package/dist/log.js +97 -17
- package/dist/policy.d.ts +6 -0
- package/dist/policy.js +17 -0
- package/dist/sdk/claude.js +18 -2
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.js +3 -1
- package/dist/witness.js +3 -3
- package/docs/completeness.md +59 -0
- package/docs/compliance.md +117 -7
- package/docs/policies.md +12 -0
- package/docs/sdk.md +83 -1
- package/docs/threat-model.md +1 -0
- package/docs/tutorials.md +4 -0
- package/docs/usage.md +1 -1
- package/package.json +3 -2
- package/templates/claude-code.cedar +96 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Two producers, one receipt format, one verifier.
|
|
|
10
10
|
Anyone holding the public keys can verify a receipt offline. The agent is not trusted. The layer around it is, and the receipt says exactly how far that trust extends, starting with who issued it. What the receipt file carries of a call is a choice per tool: a field can be withheld as a commitment or encrypted under your key, and the verifier recomputes the digests when it is shown the values.
|
|
11
11
|
|
|
12
12
|
- [Reference](https://docs.agent-custody.dev/reference/): every function, endpoint, MCP tool, and command with its request and response
|
|
13
|
-
- [Tutorials](docs/tutorials.md):
|
|
13
|
+
- [Tutorials](docs/tutorials.md): runnable examples, one per aspect of the code, all executed by the test suite
|
|
14
14
|
- [Financial operations](docs/financial-operations.md): durable operation ids, provider idempotency keys, atomic daily budget reservations, and reconciliation receipts for uncertain outcomes
|
|
15
15
|
- [The gateway console](docs/console.md): an admin service for the person who runs a gateway: config, tools, receipts with a verdict each, a policy editor that replays recorded calls before it saves, grant revocation, and an audit trail
|
|
16
16
|
- [Configuring the gateway](docs/configuration.md): who may use which tools and where the tools live, a worked example with two agents, the Docker image, and `agent-custody check` to validate a config before it starts
|
|
@@ -20,8 +20,9 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
|
|
|
20
20
|
- [The interceptor SDK](docs/sdk.md): Claude Code hooks, the Claude Agent SDK, adapters for the OpenAI Agents SDK, Vercel AI SDK, LangChain, OpenClaw and DeepSeek Harness, a Hermes Agent plugin and Google ADK callbacks through the Python package, and wrapping tool functions in anything else
|
|
21
21
|
- [Writing policies](docs/policies.md): how a tool call becomes a Cedar request, with tested examples, and replaying history against a proposed policy with `policy simulate`
|
|
22
22
|
- [Verifying a receipt](docs/verification.md): what each check means and what a verified receipt does and does not prove
|
|
23
|
-
- [What the evidence satisfies](docs/compliance.md): the receipts, packs, and certificates mapped to SOC 2, ISO 27001, the EU AI Act, and
|
|
23
|
+
- [What the evidence satisfies](docs/compliance.md): the receipts, packs, and certificates mapped to SOC 2, ISO 27001, UK GDPR, the EU AI Act, FINRA, MAS, Colorado, DORA, the CSA AI Controls Matrix, the OWASP agentic guidance, and ISO/IEC 42001. Each regulation has a primary source, an "as of" date, and a list of what a receipt does not supply
|
|
24
24
|
- [Anchoring the log on a chain](docs/anchoring.md): the log's checkpoints committed to Ethereum mainnet, or another EVM chain the installation picks, from a published address, what that proves and what it does not, running the anchor, and `log-check` against the chain
|
|
25
|
+
- [Completeness](docs/completeness.md): an auditor's read-only key lists the provider's objects and matches each to a verified receipt, so an action taken outside the gateway shows up
|
|
25
26
|
- [Payment mandates and agent identity](docs/mandates.md): the design for fitting grants and receipts to Google's AP2 mandates, Visa's Trusted Agent Protocol and Mastercard Agent Pay; not yet built
|
|
26
27
|
- [Threat model](docs/threat-model.md): every party who could make a receipt false, the move, what stops it, and whether that is a property of the evidence or of the deployment; and what is not defended
|
|
27
28
|
- [Aligning with IETF SCITT](docs/scitt.md): the receipt as a SCITT signed statement, the log as a transparency service, our RFC 9162 proofs as COSE Receipts (RFC 9942), what differs and the options for each, an agent-action profile, and the steps toward the working group
|
|
@@ -37,7 +38,7 @@ Published on npm as [`@agent-custody/receipts`](https://www.npmjs.com/package/@a
|
|
|
37
38
|
Record receipts from inside your own agent, no gateway needed. Generate a signing key, point a config at it, wrap the functions the agent calls:
|
|
38
39
|
|
|
39
40
|
```bash
|
|
40
|
-
npx agent-custody keygen --dir keys --name app
|
|
41
|
+
npx @agent-custody/receipts keygen --dir keys --name app
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
```json
|
|
@@ -55,7 +56,9 @@ const bundle = JSON.parse(readFileSync("receipts/<id>.json", "utf8"));
|
|
|
55
56
|
verifyBundle(bundle, { issuerKeys: [loadPublicKey("keys/app.pub")], logFile: "log.jsonl" }).ok; // true
|
|
56
57
|
```
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
For your own Claude Code sessions, one command does the whole setup (key, config in observe mode, starter deny policy, hooks), and `agent-custody report` lists the calls the policy would have denied: `npx @agent-custody/receipts init claude-code`, then see [docs/sdk.md](docs/sdk.md#claude-code).
|
|
60
|
+
|
|
61
|
+
Framework hooks and adapters, including Claude Code, the OpenAI Agents SDK, the Vercel AI SDK, LangChain, OpenClaw, DeepSeek Harness, Hermes and Google ADK, are in [docs/sdk.md](docs/sdk.md). To enforce rather than record, put the gateway between the agent and its tools: `npx @agent-custody/receipts gateway --config gateway.json`, set up in [docs/usage.md](docs/usage.md); between an agent and the agents it delegates to over A2A, `--a2a` serves the gateway as an A2A agent itself. The gateway is listed in the [MCP Registry](https://registry.modelcontextprotocol.io/) as `io.github.svayatta/agent-custody`; its entry is [server.json](server.json), published after each npm release by running the `mcp-registry` workflow from the Actions tab (GitHub OIDC, no token).
|
|
59
62
|
|
|
60
63
|
## How it fits together
|
|
61
64
|
|
|
@@ -113,7 +116,7 @@ Every receipt names its issuer, and the verifier prints what that issuer kind is
|
|
|
113
116
|
| --- | --- | --- | --- | --- |
|
|
114
117
|
| any MCP host: Claude Desktop, Claude Code, Cursor, custom | gateway | yes | | a real MCP client and upstream over stdio |
|
|
115
118
|
| Codex CLI (headless) | gateway | yes | | a manual `codex exec` run and offline MCP recovery checks; [guide](docs/codex-recovery.md) |
|
|
116
|
-
| Claude Code | SDK | `hook` command, PreToolUse deny | PostToolUse | the documented hook contract, via stdin |
|
|
119
|
+
| Claude Code | SDK | `hook` command, PreToolUse deny; `init claude-code` sets it up | PostToolUse | the documented hook contract, via stdin; `init` and `report` against a temporary home |
|
|
117
120
|
| Claude Agent SDK | SDK | `claudeAgentHooks` | same | the same handler |
|
|
118
121
|
| OpenAI Agents SDK (JS) | SDK | `wrapTools` | `observeRunner` | a real `Runner` with a scripted model |
|
|
119
122
|
| Vercel AI SDK | SDK | `wrapTools` | | a real `generateText` loop over the SDK's mock model |
|
|
@@ -192,7 +195,7 @@ Every field carries a provenance label. This is the design decision that matters
|
|
|
192
195
|
bun install # from the repository root, once for the workspace
|
|
193
196
|
cd packages/receipts
|
|
194
197
|
node scripts/demo.ts # gateway: keys, grant, policy, four tool calls, verification, a tampering attempt; then the SDK wrapping the same tool
|
|
195
|
-
node examples/01-keys-and-signing.ts # first of
|
|
198
|
+
node examples/01-keys-and-signing.ts # first of the step-by-step examples, see docs/tutorials.md
|
|
196
199
|
bun run test # this package; `bun run test` at the root runs every package
|
|
197
200
|
```
|
|
198
201
|
|
|
@@ -243,7 +246,7 @@ If a vendor tells you their receipts prove more than the first five rows, ask th
|
|
|
243
246
|
```
|
|
244
247
|
src/config.ts gateway and SDK config schemas, path resolution
|
|
245
248
|
src/crypto.ts canonical JSON, sha256, Ed25519 keys, DSSE sign/verify
|
|
246
|
-
src/log.ts Merkle log: append, root, inclusion and consistency proofs, verify, JSONL persistence
|
|
249
|
+
src/log.ts Merkle log: append, root, inclusion and consistency proofs, verify, JSONL persistence; an O_EXCL lock file makes an append safe when several processes share one log file
|
|
247
250
|
src/log-check.ts the outside monitor: verifies the head, checkpoints, witness, and anchor of a running log
|
|
248
251
|
src/portal.ts the tenant portal: register, first key, usage against plan, keys, Stripe billing, export, member roles, TOTP MFA, single sign-on, on the log's Postgres
|
|
249
252
|
src/sso.ts enterprise sign-in for the portal: OIDC (code and PKCE, id_token checked against the IdP's key set) and SAML 2.0 (signed assertions only, through @node-saml/node-saml)
|
|
@@ -251,6 +254,7 @@ src/log-export.ts a tenant's export of their own log, self-checked, as a log fi
|
|
|
251
254
|
src/witness.ts the witness: countersigns the log's checkpoints from another operator's machine, or refuses with an alarm
|
|
252
255
|
src/anchor.ts the anchor: commits a Merkle root over new checkpoints to a chain, or refuses with an alarm; checks a record against JSON-RPC
|
|
253
256
|
src/anchor-evm.ts the anchor's transactions on Ethereum or another EVM chain, through the optional dependency viem
|
|
257
|
+
src/completeness.ts completeness from the provider's side: the provider's own list, matched against verified receipts
|
|
254
258
|
src/signer.ts the signer: the log's key in its own process, the key document verifiers fetch
|
|
255
259
|
src/checkpoints.ts signed heads published on a schedule, to files and to Postgres
|
|
256
260
|
src/log-store.ts the log server's backends: the file, and Postgres with tenants, hashed tokens, one writer per tenant, rate limits
|
|
@@ -276,12 +280,15 @@ src/upstream.ts attested execution: an upstream signs its result for the rece
|
|
|
276
280
|
src/capture.ts private evidence: per-tool capture rules applied by the issuer to the whole statement, withheld values as salted commitments or encrypted under the customer's key, restore and reveal
|
|
277
281
|
vectors/ conformance vectors: receipts, keys, logs, proofs, and expected verdicts; `bun run vectors` regenerates them
|
|
278
282
|
src/verify.ts offline verification, the human-readable report, and the audit that a later log extends an earlier one
|
|
279
|
-
src/
|
|
283
|
+
src/claude-init.ts `init claude-code`: the agent key, the observe-mode config, the starter policy, and the three hooks merged into the settings file with absolute paths
|
|
284
|
+
src/deny-report.ts `report`: verifies the receipts of an SDK config and lists the calls the policy would have denied
|
|
285
|
+
templates/ the starter Cedar policy that `init claude-code` copies (shipped in the package)
|
|
286
|
+
src/cli.ts keygen, grant, gateway, init, report, hook, serve, log, prune, verify, reveal, audit, policy simulate
|
|
280
287
|
src/retention.ts pruning the log: leaves become their hashes, bundles are removed, proofs survive
|
|
281
288
|
src/index.ts the package's public surface; adapters are exported on ./sdk/<framework> subpaths
|
|
282
289
|
tsconfig.build.json emits dist/ (JavaScript plus declarations) for consumers; the repo itself runs the .ts directly
|
|
283
290
|
scripts/ fake Stripe upstream (signs its results with --key), a second fake upstream, fixture builders for gateway and SDK, the replay builder (`replay.ts`: example 27 and state example 07 as a folder of receipts and public keys anyone can verify with the published packages), demo
|
|
284
|
-
examples/
|
|
291
|
+
examples/ runnable tutorials, plus examples/languages/: Python, Go, Java, and Rust clients of the sidecar, run by the test suite, one per aspect; each is run by the test suite
|
|
285
292
|
test/ unit tests per module, end-to-end gateway test, SDK and hook tests,
|
|
286
293
|
adapter tests against the real packages, and a test that runs every policy in docs/policies.md
|
|
287
294
|
docs/ tutorials, usage (gateway), codex-recovery (live demo), approvals, sdk, policies, verification
|
|
@@ -293,6 +300,8 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
293
300
|
|
|
294
301
|
**Done**
|
|
295
302
|
|
|
303
|
+
- An incident replay: `node examples/38-incident-replay.ts` plays a Claude Code session against the starter deny set in enforce mode. `terraform destroy` and `rm -rf ~` are denied before they run, and the denial receipts verify offline with the public key only. The site page [An incident replay](../../site/guide/incident-replay.md) shows the output and the limit: a credential in the agent's environment goes around the hook (tutorial 38).
|
|
304
|
+
- One command for Claude Code (issue #204): `agent-custody init claude-code` makes the agent key, writes `sdk.json` in observe mode with no log, writes a starter deny policy, and merges the three hooks into `.claude/settings.local.json` or `~/.claude/settings.json` with absolute paths, safe to run two times. `agent-custody report` verifies the receipts and prints the calls the policy would have denied, with the reason, the rule, and the receipt id; removing the `mode` line enforces. The default local log takes a lock for each append, so hooks that run at the same time keep one log; `--log-url` needs `--log-key`; a second run keeps the pinned log key and warns about log flags it does not apply; `init` warns when git does not ignore the project settings file ([sdk.md](docs/sdk.md#claude-code), tutorial 36).
|
|
296
305
|
- Strict mode: `"strict": true` refuses a local log, a log that is not hash-only, and a log without pinned keys; precommits every tool, in observe mode too; and turns the outbox off. No call the agent makes is forwarded before its authorization is in a log the operator does not run, every receipt says `issuer.strict`, and `verify --require-strict` requires it ([usage](docs/usage.md#strict-mode), tutorial 34). [Issue #177](https://github.com/svayatta/agent-custody/issues/177).
|
|
297
306
|
- Policy reload: the gateway re-reads `policy.cedar` whenever it changes and applies it from the next call, with no restart and no dropped session; a policy that does not parse is refused and the one in force stays, and every change or refusal is recorded in `receipts/policy-reloads.jsonl` ([usage](docs/usage.md)).
|
|
298
307
|
- Live Codex support recovery demo: model-selected MCP calls, incorrect CRM memory, a reviewed recovery plan, simulated credit compensation, and verified evidence; [guide](docs/codex-recovery.md), with offline regression coverage.
|
|
@@ -338,17 +347,16 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
338
347
|
- The [state review console](../state/README.md#explain-one-action): search receipts by transaction, customer, agent or time, read the ten answers, and hand over a portable HTML/JSON case whose signatures, authorizations and inclusion proofs can be verified offline.
|
|
339
348
|
- A log outage after an ordinary call (issue #149): the signed receipt waits in `receipts/outbox/` and the gateway appends it when the log is back, the agent gets the real outcome marked `log-pending`, `GET /health` counts the pending receipts, and `requirePrecommit` refuses a remote log with an empty `precommit`. The [failure table](docs/usage.md#when-the-log-fails) gives each case.
|
|
340
349
|
- The anchor (issue #176): `agent-custody anchor` proves each new checkpoint extends the last one it anchored, then commits a Merkle root over them in one transaction from its address to itself, on Ethereum by default or on Base, Arbitrum, Optimism, Polygon, or any EVM chain by id (`--chain`), with a fee cap sized per chain. It publishes each log's record and inclusion proof, sends nothing for an idle log, skips a run above a fee cap, and never has two transactions in flight. Every transaction covers every watched log, and a transaction counts only once its block is finalized, following reorgs. `log-check --anchor-url` checks the record against one or more JSON-RPC endpoints, requires the log id the verifier pinned and the address's newest transaction, and checks the log's head against the anchored checkpoint, so a rewritten or rolled-back tree is caught from the chain alone ([anchoring](docs/anchoring.md), example 33).
|
|
350
|
+
- Completeness from the provider's side (issue #178): `agent-custody completeness` lists Stripe's refunds, payouts, or transfers over a window with the auditor's own read-only key, and matches each to a verified receipt by the provider's object id. It reports actions with no receipt, receipts the provider does not have, amount, currency, and beneficiary mismatches, calls forwarded without an outcome receipt, and receipts it cannot match ([completeness](docs/completeness.md), example 35).
|
|
341
351
|
|
|
342
352
|
**Next, in the order it pays off**
|
|
343
353
|
|
|
344
354
|
The first three close the gap between a log the operator cannot rewrite and a record the operator cannot shape.
|
|
345
355
|
|
|
346
356
|
1. Run the anchor for log.agent-custody.dev on mainnet: a funded key held only by the anchor service on the host, its records served beside the checkpoints, its address and each tenant's log id published in the welcome sheet and on the security page, and the monitor checking it. The code is done. [Issue #176](https://github.com/svayatta/agent-custody/issues/176).
|
|
347
|
-
2. Completeness
|
|
357
|
+
2. Completeness beyond Stripe: the same check over GitHub's actions, and over on-chain transfers out of an agent's wallet, where the chain itself lists every transfer. [Issue #178](https://github.com/svayatta/agent-custody/issues/178).
|
|
348
358
|
3. A TEE gateway: a confidential container with a reproducible, attested build, the signing key generated and kept in the enclave, TLS ending inside it, and both verifiers checking the path from the receipt key, through the attestation, to the release. It replaces the TEE-hosted signer planned before. [Issue #179](https://github.com/svayatta/agent-custody/issues/179).
|
|
349
359
|
4. Run the witness for log.agent-custody.dev on a machine and under an account that is not ours, and require it in the welcome sheet. The code is done; what it needs is a second operator. [Issue #116](https://github.com/svayatta/agent-custody/issues/116).
|
|
350
360
|
5. Post-quantum signatures: ML-DSA beside Ed25519 in the same DSSE envelope, hybrid by default when a PQ key is present, in every signed artefact and in the browser verifier. [Issue #11](https://github.com/svayatta/agent-custody/issues/11).
|
|
351
361
|
6. Receiver attestation for agent-to-agent calls: the delegate signs its answer for the receipt, as a signing upstream does today.
|
|
352
362
|
7. SD-JWT redaction, then ZK proofs of policy compliance. Not before.
|
|
353
|
-
|
|
354
|
-
A Python SDK follows the same shape once the TypeScript adapters have settled.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure"];
|
|
2
|
+
export declare const HOOK_MATCHER = "Bash|Write|Edit|MultiEdit|NotebookEdit|mcp__.*";
|
|
3
|
+
export interface ClaudeInitOptions {
|
|
4
|
+
/** The absolute path of the CLI script that runs now. The hook runs this script. */
|
|
5
|
+
cliPath: string;
|
|
6
|
+
/** The Node binary that the hook runs. Default: the binary that runs now. */
|
|
7
|
+
nodePath?: string;
|
|
8
|
+
/** Default: `~/.config/agent-custody` */
|
|
9
|
+
dir?: string;
|
|
10
|
+
/** Write the hooks to `~/.claude/settings.json`. Default: `.claude/settings.local.json` in `cwd`. */
|
|
11
|
+
user?: boolean;
|
|
12
|
+
/** Leave out `"mode": "observe"`, so the policy blocks a denied call. */
|
|
13
|
+
enforce?: boolean;
|
|
14
|
+
logUrl?: string;
|
|
15
|
+
logId?: string;
|
|
16
|
+
/** The NAME of the environment variable that holds the log token. Never the token. */
|
|
17
|
+
logTokenEnv?: string;
|
|
18
|
+
/** The log's public key file. A log URL needs it. The command copies it into the directory when it writes a new config. */
|
|
19
|
+
logKey?: string;
|
|
20
|
+
home?: string;
|
|
21
|
+
cwd?: string;
|
|
22
|
+
/** One line of progress. Default: stdout. */
|
|
23
|
+
print?: (line: string) => void;
|
|
24
|
+
}
|
|
25
|
+
export interface ClaudeInitResult {
|
|
26
|
+
dir: string;
|
|
27
|
+
configFile: string;
|
|
28
|
+
settingsFile: string;
|
|
29
|
+
hookCommand: string;
|
|
30
|
+
}
|
|
31
|
+
/** A shell word for a path: bare when it is plain, in single quotes otherwise. */
|
|
32
|
+
export declare function shellQuote(s: string): string;
|
|
33
|
+
type Json = Record<string, unknown>;
|
|
34
|
+
/** Parses a settings file. Throws, and so changes nothing, when the text is not a JSON object with usable `hooks`. */
|
|
35
|
+
export declare function parseSettings(text: string, file: string): Json;
|
|
36
|
+
export type HookChange = "added" | "updated" | "kept";
|
|
37
|
+
/**
|
|
38
|
+
* Registers the hook command for the three events and keeps every other key and hook. A hook of ours is a command
|
|
39
|
+
* that ends with `hook --config <this config>`. It is updated in place when its command differs, and never added twice.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mergeHooks(settings: Json, command: string, configFile: string): {
|
|
42
|
+
settings: Json;
|
|
43
|
+
changes: Record<string, HookChange>;
|
|
44
|
+
};
|
|
45
|
+
export declare function initClaudeCode(o: ClaudeInitOptions): ClaudeInitResult;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// `agent-custody init claude-code`: the key, the config, the starter policy, and the three hooks for the user's own
|
|
2
|
+
// Claude Code sessions, in one command. It is safe to run two times.
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir, userInfo } from "node:os";
|
|
6
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
7
|
+
import { SdkConfigSchema, loadSdkConfig } from "./config.js";
|
|
8
|
+
import { generateKeyPair, publicKeyFromPem, writeKeyPair } from "./crypto.js";
|
|
9
|
+
export const HOOK_EVENTS = ["PreToolUse", "PostToolUse", "PostToolUseFailure"];
|
|
10
|
+
export const HOOK_MATCHER = "Bash|Write|Edit|MultiEdit|NotebookEdit|mcp__.*";
|
|
11
|
+
const KEY_NAME = "claude-code";
|
|
12
|
+
const DEFAULT_TOKEN_ENV = "AGENT_CUSTODY_LOG_TOKEN";
|
|
13
|
+
/** A shell word for a path: bare when it is plain, in single quotes otherwise. */
|
|
14
|
+
export function shellQuote(s) {
|
|
15
|
+
return /^[A-Za-z0-9_\/.:@%+=,-]+$/.test(s) ? s : `'${s.replaceAll("'", `'\\''`)}'`;
|
|
16
|
+
}
|
|
17
|
+
const isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
18
|
+
/** Parses a settings file. Throws, and so changes nothing, when the text is not a JSON object with usable `hooks`. */
|
|
19
|
+
export function parseSettings(text, file) {
|
|
20
|
+
let settings;
|
|
21
|
+
try {
|
|
22
|
+
settings = JSON.parse(text);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
throw new Error(`${file} is not valid JSON (${e instanceof Error ? e.message : String(e)}). Fix the file and run the command again. The command changed nothing.`);
|
|
26
|
+
}
|
|
27
|
+
if (!isObject(settings))
|
|
28
|
+
throw new Error(`${file} does not hold a JSON object. The command changed nothing.`);
|
|
29
|
+
const hooks = settings.hooks;
|
|
30
|
+
if (hooks !== undefined && !isObject(hooks))
|
|
31
|
+
throw new Error(`"hooks" in ${file} is not an object. The command changed nothing.`);
|
|
32
|
+
for (const event of HOOK_EVENTS) {
|
|
33
|
+
if (hooks?.[event] !== undefined && !Array.isArray(hooks[event]))
|
|
34
|
+
throw new Error(`"hooks.${event}" in ${file} is not an array. The command changed nothing.`);
|
|
35
|
+
}
|
|
36
|
+
return settings;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Registers the hook command for the three events and keeps every other key and hook. A hook of ours is a command
|
|
40
|
+
* that ends with `hook --config <this config>`. It is updated in place when its command differs, and never added twice.
|
|
41
|
+
*/
|
|
42
|
+
export function mergeHooks(settings, command, configFile) {
|
|
43
|
+
const ours = ` hook --config ${shellQuote(configFile)}`;
|
|
44
|
+
const hooks = { ...(isObject(settings.hooks) ? settings.hooks : {}) };
|
|
45
|
+
const changes = {};
|
|
46
|
+
for (const event of HOOK_EVENTS) {
|
|
47
|
+
const entries = (hooks[event] ?? []).map((entry) => (isObject(entry) ? { ...entry } : entry));
|
|
48
|
+
let change;
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
if (!isObject(entry) || !Array.isArray(entry.hooks))
|
|
51
|
+
continue;
|
|
52
|
+
entry.hooks = entry.hooks.map((hook) => {
|
|
53
|
+
if (!isObject(hook) || typeof hook.command !== "string" || !hook.command.endsWith(ours))
|
|
54
|
+
return hook;
|
|
55
|
+
if (hook.command === command) {
|
|
56
|
+
change ??= "kept";
|
|
57
|
+
return hook;
|
|
58
|
+
}
|
|
59
|
+
change = "updated";
|
|
60
|
+
return { ...hook, command };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (!change) {
|
|
64
|
+
entries.push({ matcher: HOOK_MATCHER, hooks: [{ type: "command", command }] });
|
|
65
|
+
change = "added";
|
|
66
|
+
}
|
|
67
|
+
hooks[event] = entries;
|
|
68
|
+
changes[event] = change;
|
|
69
|
+
}
|
|
70
|
+
return { settings: { ...settings, hooks }, changes };
|
|
71
|
+
}
|
|
72
|
+
function buildConfig(o, user) {
|
|
73
|
+
const config = {
|
|
74
|
+
agentId: "claude-code",
|
|
75
|
+
principalId: user,
|
|
76
|
+
framework: "claude-code",
|
|
77
|
+
identity: { keyFile: `keys/${KEY_NAME}.key` },
|
|
78
|
+
policyFile: "policy.cedar",
|
|
79
|
+
...(o.enforce ? {} : { mode: "observe" }),
|
|
80
|
+
receiptsDir: "receipts",
|
|
81
|
+
};
|
|
82
|
+
if (o.logUrl) {
|
|
83
|
+
config.log = {
|
|
84
|
+
url: o.logUrl,
|
|
85
|
+
tokenEnv: o.logTokenEnv ?? DEFAULT_TOKEN_ENV,
|
|
86
|
+
hashOnly: true,
|
|
87
|
+
keys: ["log.pub"],
|
|
88
|
+
...(o.logId ? { logId: o.logId } : {}),
|
|
89
|
+
timeoutMs: 3000,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
config.logFile = "log.jsonl";
|
|
94
|
+
}
|
|
95
|
+
return config;
|
|
96
|
+
}
|
|
97
|
+
/** Throws unless the file holds a PUBLIC key in PEM form. A private key is refused too, so that `log.pub` never holds one. */
|
|
98
|
+
function checkLogKey(file) {
|
|
99
|
+
const text = readFileSync(file, "utf8");
|
|
100
|
+
try {
|
|
101
|
+
if (!text.includes("-----BEGIN PUBLIC KEY-----"))
|
|
102
|
+
throw new Error("no PEM public key");
|
|
103
|
+
publicKeyFromPem(text);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error(`init: the log key file ${file} does not hold a public key in PEM form. Give the .pub file of the log.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** True when the path is in a git work tree and git does not ignore it. False when git cannot tell. */
|
|
110
|
+
function notIgnoredByGit(file) {
|
|
111
|
+
return spawnSync("git", ["check-ignore", "-q", file], { cwd: dirname(file), stdio: "ignore", timeout: 5000 }).status === 1;
|
|
112
|
+
}
|
|
113
|
+
function userName() {
|
|
114
|
+
try {
|
|
115
|
+
return userInfo().username;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return "user";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function initClaudeCode(o) {
|
|
122
|
+
const print = o.print ?? ((line) => console.log(line));
|
|
123
|
+
const home = o.home ?? homedir();
|
|
124
|
+
const dir = resolve(o.dir ?? join(home, ".config", "agent-custody"));
|
|
125
|
+
const settingsFile = o.user ? join(home, ".claude", "settings.json") : join(resolve(o.cwd ?? process.cwd()), ".claude", "settings.local.json");
|
|
126
|
+
const configFile = join(dir, "sdk.json");
|
|
127
|
+
if (!isAbsolute(o.cliPath))
|
|
128
|
+
throw new Error("init: the CLI path must be absolute");
|
|
129
|
+
if ((o.logId || o.logTokenEnv || o.logKey) && !o.logUrl)
|
|
130
|
+
throw new Error("init: --log-id, --log-token-env, and --log-key need --log-url");
|
|
131
|
+
if (o.logTokenEnv && !/^[A-Z_][A-Z0-9_]*$/.test(o.logTokenEnv))
|
|
132
|
+
throw new Error("init: --log-token-env takes the NAME of an environment variable, such as AGENT_CUSTODY_LOG_TOKEN. Never give the token itself.");
|
|
133
|
+
if (o.logUrl && !o.logKey)
|
|
134
|
+
throw new Error("init: --log-url needs --log-key <pub>, the public key of the log. Without it, `report` cannot check the tree head of any receipt, and every receipt fails.");
|
|
135
|
+
if (o.logKey && !existsSync(o.logKey))
|
|
136
|
+
throw new Error(`init: the log key file ${o.logKey} does not exist`);
|
|
137
|
+
if (o.logKey)
|
|
138
|
+
checkLogKey(o.logKey);
|
|
139
|
+
const config = buildConfig(o, userName());
|
|
140
|
+
const checked = SdkConfigSchema.safeParse(config);
|
|
141
|
+
if (!checked.success)
|
|
142
|
+
throw new Error(`init: the config is not valid: ${checked.error.issues.map((i) => `${i.path.join(".") || "(config)"}: ${i.message}`).join("; ")}`);
|
|
143
|
+
// Read the settings before any write, so that a settings file we cannot merge leaves the machine as it was.
|
|
144
|
+
const settingsText = existsSync(settingsFile) ? readFileSync(settingsFile, "utf8") : undefined;
|
|
145
|
+
const settings = settingsText === undefined ? {} : parseSettings(settingsText, settingsFile);
|
|
146
|
+
print("agent-custody init claude-code");
|
|
147
|
+
const keyFile = join(dir, "keys", `${KEY_NAME}.key`);
|
|
148
|
+
mkdirSync(join(dir, "keys"), { recursive: true, mode: 0o700 });
|
|
149
|
+
if (existsSync(keyFile)) {
|
|
150
|
+
print(`1. Key: kept the existing key ${keyFile}`);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const kp = generateKeyPair();
|
|
154
|
+
writeKeyPair(kp, join(dir, "keys"), KEY_NAME);
|
|
155
|
+
print(`1. Key: made ${keyFile} (key id ${kp.keyid.slice(0, 16)}). The file is readable by you only.`);
|
|
156
|
+
}
|
|
157
|
+
const policyFile = join(dir, "policy.cedar");
|
|
158
|
+
if (existsSync(policyFile)) {
|
|
159
|
+
print(`2. Policy: kept the existing ${policyFile}`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
copyFileSync(new URL("../templates/claude-code.cedar", import.meta.url), policyFile);
|
|
163
|
+
print(`2. Policy: wrote the starter deny set to ${policyFile}. It forbids force push (not --force-with-lease), rm -rf on /, ~, and $HOME, terraform destroy and apply -destroy, and drop database.`);
|
|
164
|
+
}
|
|
165
|
+
mkdirSync(join(dir, "receipts"), { recursive: true, mode: 0o700 });
|
|
166
|
+
if (existsSync(configFile)) {
|
|
167
|
+
print(`3. Config: kept the existing ${configFile}. The command does not change it.`);
|
|
168
|
+
const ignored = [["--enforce", o.enforce], ["--log-url", o.logUrl], ["--log-id", o.logId], ["--log-token-env", o.logTokenEnv], ["--log-key", o.logKey]].filter(([, given]) => given).map(([flag]) => flag);
|
|
169
|
+
if (ignored.length)
|
|
170
|
+
print(` Warning: ${ignored.join(", ")} not applied, because the config exists. The pinned log key stays as it is. Edit ${configFile}, or remove the file and run this command again.`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (o.logKey)
|
|
174
|
+
copyFileSync(o.logKey, join(dir, "log.pub"));
|
|
175
|
+
writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`);
|
|
176
|
+
print(`3. Config: wrote ${configFile}, ${o.enforce ? "in enforce mode: a denied call is blocked" : 'with "mode": "observe": the policy records a denied call and blocks nothing'}.`);
|
|
177
|
+
print(o.logUrl ? ` Receipts go to ${o.logUrl} as hashes. The token comes from the environment variable ${o.logTokenEnv ?? DEFAULT_TOKEN_ENV}.` : ` Receipts stay on this machine in ${join(dir, "receipts")}. No log is configured.`);
|
|
178
|
+
}
|
|
179
|
+
loadSdkConfig(configFile);
|
|
180
|
+
const nodePath = o.nodePath ?? process.execPath;
|
|
181
|
+
const hookCommand = `${shellQuote(nodePath)} ${shellQuote(o.cliPath)} hook --config ${shellQuote(configFile)}`;
|
|
182
|
+
const merged = mergeHooks(settings, hookCommand, configFile);
|
|
183
|
+
mkdirSync(dirname(settingsFile), { recursive: true });
|
|
184
|
+
writeFileSync(settingsFile, `${JSON.stringify(merged.settings, null, 2)}\n`);
|
|
185
|
+
const by = (c) => HOOK_EVENTS.filter((e) => merged.changes[e] === c);
|
|
186
|
+
const parts = [["registered", "added"], ["updated", "updated"], ["found already registered", "kept"]].filter(([, c]) => by(c).length).map(([word, c]) => `${word} ${by(c).join(", ")}`);
|
|
187
|
+
print(`4. Hooks: ${parts.join("; ")} in ${settingsFile}. The command keeps every other key and hook in that file.`);
|
|
188
|
+
if (!o.user && notIgnoredByGit(settingsFile)) {
|
|
189
|
+
print("");
|
|
190
|
+
print(`Warning: ${settingsFile} is in a git repository, and git does not ignore it. The file holds absolute paths of your home directory.`);
|
|
191
|
+
print("Add this line to .gitignore: .claude/settings.local.json");
|
|
192
|
+
}
|
|
193
|
+
if (/[\\/]_npx[\\/]/.test(o.cliPath)) {
|
|
194
|
+
print("");
|
|
195
|
+
print("Warning: this command runs from the npx cache, and npm can clear that cache. The hooks then stop working.");
|
|
196
|
+
print("Install the package globally with `npm install -g @agent-custody/receipts`, and run this command again. The second run updates the hook paths.");
|
|
197
|
+
}
|
|
198
|
+
if (o.logUrl && !process.env[o.logTokenEnv ?? DEFAULT_TOKEN_ENV]) {
|
|
199
|
+
print("");
|
|
200
|
+
print(`Note: ${o.logTokenEnv ?? DEFAULT_TOKEN_ENV} is not set in this shell. Set it in the environment that starts Claude Code.`);
|
|
201
|
+
}
|
|
202
|
+
print("");
|
|
203
|
+
print("Next:");
|
|
204
|
+
print(` 1. Start a Claude Code session ${o.user ? "in any directory" : "in this directory"} and work as usual. Nothing is blocked${o.enforce ? " except a call that the policy denies" : ""}.`);
|
|
205
|
+
print(` 2. Run: ${shellQuote(nodePath)} ${shellQuote(o.cliPath)} report --config ${shellQuote(configFile)}`);
|
|
206
|
+
print(" The report lists each call that the policy would have denied.");
|
|
207
|
+
return { dir, configFile, settingsFile, hookCommand };
|
|
208
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ import { connectSigner, fetchLogKeys, localSigner, serveSigner } from "./signer.
|
|
|
16
16
|
import { fetchWitnessKeys, Witness } from "./witness.js";
|
|
17
17
|
import { checkLog, formatLogCheck } from "./log-check.js";
|
|
18
18
|
import { Anchor, ANCHOR_CHAINS, resolveAnchorChain } from "./anchor.js";
|
|
19
|
+
import { checkCompleteness, formatCompleteness, stripeSource } from "./completeness.js";
|
|
19
20
|
import { evmChain } from "./anchor-evm.js";
|
|
20
21
|
import { serveHttp } from "./gateway-http.js";
|
|
21
22
|
import { serveA2a } from "./a2a.js";
|
|
@@ -30,6 +31,9 @@ import { serveConsole } from "./console.js";
|
|
|
30
31
|
import { TREEHEAD_TYPE } from "./receipt.js";
|
|
31
32
|
import { MerkleLog } from "./log.js";
|
|
32
33
|
import { createSdkIssuer } from "./sdk/index.js";
|
|
34
|
+
import { initClaudeCode } from "./claude-init.js";
|
|
35
|
+
import { denyReport, formatDenyReport } from "./deny-report.js";
|
|
36
|
+
import { fileURLToPath } from "node:url";
|
|
33
37
|
import { handleHookEvent } from "./sdk/claude.js";
|
|
34
38
|
import { auditExtends, formatReport, verifyBundle } from "./verify.js";
|
|
35
39
|
import { formatSimulation, simulatePolicy, verifyOrphanAuthorization } from "./simulate.js";
|
|
@@ -86,6 +90,11 @@ const USAGE = `agent-custody <command>
|
|
|
86
90
|
gateway --config <gateway.json> [--http [--port 8790] [--host 127.0.0.1] [--idle-minutes 30]]
|
|
87
91
|
stdio: one gateway for the grant the config names. --http: one shared gateway, MCP over
|
|
88
92
|
Streamable HTTP at /mcp, each connection presenting its own grant as Authorization: Bearer
|
|
93
|
+
init claude-code [--dir <dir>] [--user] [--enforce] [--log-url <url> [--log-id <id>] [--log-token-env NAME] [--log-key <pub>]]
|
|
94
|
+
one command for your own Claude Code sessions: an agent key, sdk.json in observe mode, a starter deny
|
|
95
|
+
policy, and the three hooks in .claude/settings.local.json (--user: ~/.claude/settings.json). Safe to run twice
|
|
96
|
+
report --config <sdk.json> the calls that the policy would have denied, from the receipts: tool, command or path, rule, receipt id;
|
|
97
|
+
a receipt that does not verify is counted apart. Exits 1 when any receipt does not verify
|
|
89
98
|
hook [--config <sdk.json>] Claude Code hook command; reads the event on stdin (or AGENT_CUSTODY_CONFIG)
|
|
90
99
|
serve --config <sdk.json> [--port 8788] [--host 127.0.0.1] the SDK as a local HTTP API for agents in other languages
|
|
91
100
|
prune --log <log.jsonl> --before <ISO instant> [--receipts <dir>]
|
|
@@ -93,6 +102,12 @@ const USAGE = `agent-custody <command>
|
|
|
93
102
|
log --file <log.jsonl> --key <log.key> [--port 8787] [--host 127.0.0.1] [--token-env <NAME>] reference log server
|
|
94
103
|
verify <bundle.json> --issuer-key <pub> [--principal-key <pub>] [--approval-key <pub>] [--log-key <pub> | --log-url <url>] [--log-id <id>] [--require-strict] [--upstream-key <pub>] [--stripe-secret-env NAME] [--github-secret-env NAME] [--log <log.jsonl>] [--disclose <file>] [--capture-key-env NAME] [--json]
|
|
95
104
|
policy simulate --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--approval-key <pub>]... [--log-key <pub>]... [--json] [--out <file>]
|
|
105
|
+
completeness --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--log-key <pub>]... [--log <log.jsonl>] [--log-id <id>]
|
|
106
|
+
--provider stripe --object refunds|payouts|transfers --key-env NAME --tool <name>... --since <ISO> --until <ISO>
|
|
107
|
+
[--id-path id] [--amount-field amount] [--currency-field currency] [--beneficiary <arg>=<field>]... [--json]
|
|
108
|
+
for an auditor: lists the provider's objects in the window with a read-only key, and
|
|
109
|
+
matches each to a verified receipt by the provider's object id; reports actions with no
|
|
110
|
+
receipt, receipts the provider does not have, and mismatched amounts; exits 1 unless complete
|
|
96
111
|
replay verified local receipts against a proposed policy using their recorded inputs;
|
|
97
112
|
--out saves the full JSON report. Exits 1 when any call could not be evaluated.
|
|
98
113
|
log ... --db-env NAME the same server over Postgres: tenants and tokens from the database, one writer per tenant,
|
|
@@ -324,6 +339,42 @@ async function main(argv) {
|
|
|
324
339
|
await gw.close();
|
|
325
340
|
return 0;
|
|
326
341
|
}
|
|
342
|
+
case "init": {
|
|
343
|
+
const [target, ...args] = rest;
|
|
344
|
+
if (target !== "claude-code")
|
|
345
|
+
throw new Error("init needs a target: init claude-code");
|
|
346
|
+
const { values } = parseArgs({
|
|
347
|
+
args,
|
|
348
|
+
options: {
|
|
349
|
+
dir: { type: "string" },
|
|
350
|
+
user: { type: "boolean", default: false },
|
|
351
|
+
enforce: { type: "boolean", default: false },
|
|
352
|
+
"log-url": { type: "string" },
|
|
353
|
+
"log-id": { type: "string" },
|
|
354
|
+
"log-token-env": { type: "string" },
|
|
355
|
+
"log-key": { type: "string" },
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
initClaudeCode({
|
|
359
|
+
cliPath: fileURLToPath(import.meta.url),
|
|
360
|
+
...(values.dir ? { dir: values.dir } : {}),
|
|
361
|
+
user: values.user,
|
|
362
|
+
enforce: values.enforce,
|
|
363
|
+
...(values["log-url"] ? { logUrl: values["log-url"] } : {}),
|
|
364
|
+
...(values["log-id"] ? { logId: values["log-id"] } : {}),
|
|
365
|
+
...(values["log-token-env"] ? { logTokenEnv: values["log-token-env"] } : {}),
|
|
366
|
+
...(values["log-key"] ? { logKey: values["log-key"] } : {}),
|
|
367
|
+
});
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
case "report": {
|
|
371
|
+
const { values } = parseArgs({ args: rest, options: { config: { type: "string" } } });
|
|
372
|
+
if (!values.config)
|
|
373
|
+
throw new Error("report needs --config <sdk.json>");
|
|
374
|
+
const report = denyReport(resolve(values.config));
|
|
375
|
+
console.log(formatDenyReport(report));
|
|
376
|
+
return report.unverified.length ? 1 : 0;
|
|
377
|
+
}
|
|
327
378
|
case "hook": {
|
|
328
379
|
const { values } = parseArgs({ args: rest, options: { config: { type: "string" } } });
|
|
329
380
|
const configPath = values.config ?? process.env.AGENT_CUSTODY_CONFIG;
|
|
@@ -746,6 +797,70 @@ async function main(argv) {
|
|
|
746
797
|
console.log(values.json ? JSON.stringify(result, null, 2) : formatReport(result));
|
|
747
798
|
return result.ok ? 0 : 1;
|
|
748
799
|
}
|
|
800
|
+
case "completeness": {
|
|
801
|
+
const { values } = parseArgs({
|
|
802
|
+
args: rest,
|
|
803
|
+
options: {
|
|
804
|
+
receipts: { type: "string" },
|
|
805
|
+
"issuer-key": { type: "string", multiple: true },
|
|
806
|
+
"principal-key": { type: "string", multiple: true },
|
|
807
|
+
"approval-key": { type: "string", multiple: true },
|
|
808
|
+
"log-key": { type: "string", multiple: true },
|
|
809
|
+
log: { type: "string" },
|
|
810
|
+
"log-id": { type: "string" },
|
|
811
|
+
provider: { type: "string" },
|
|
812
|
+
object: { type: "string", default: "refunds" },
|
|
813
|
+
"key-env": { type: "string" },
|
|
814
|
+
tool: { type: "string", multiple: true },
|
|
815
|
+
since: { type: "string" },
|
|
816
|
+
until: { type: "string" },
|
|
817
|
+
"id-path": { type: "string" },
|
|
818
|
+
"amount-field": { type: "string" },
|
|
819
|
+
"currency-field": { type: "string" },
|
|
820
|
+
beneficiary: { type: "string", multiple: true },
|
|
821
|
+
json: { type: "boolean", default: false },
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
if (!values.receipts || !values["issuer-key"]?.length || !values["key-env"] || !values.tool?.length || !values.since || !values.until)
|
|
825
|
+
throw new Error("completeness needs --receipts, --issuer-key, --provider stripe, --key-env, --tool, --since and --until");
|
|
826
|
+
if (values.provider !== "stripe")
|
|
827
|
+
throw new Error(`completeness supports --provider stripe; got "${values.provider ?? ""}"`);
|
|
828
|
+
const objects = ["refunds", "payouts", "transfers"];
|
|
829
|
+
if (!objects.includes(values.object))
|
|
830
|
+
throw new Error(`--object is one of ${objects.join(", ")}; got "${values.object}"`);
|
|
831
|
+
const sinceMs = Date.parse(values.since);
|
|
832
|
+
const untilMs = Date.parse(values.until);
|
|
833
|
+
if (!Number.isFinite(sinceMs) || !Number.isFinite(untilMs) || untilMs <= sinceMs)
|
|
834
|
+
throw new Error("--since and --until must be ISO times, --until after --since");
|
|
835
|
+
const beneficiary = {};
|
|
836
|
+
for (const pair of values.beneficiary ?? []) {
|
|
837
|
+
const at = pair.indexOf("=");
|
|
838
|
+
if (at < 1 || at === pair.length - 1)
|
|
839
|
+
throw new Error(`--beneficiary takes <argument>=<provider field>; got "${pair}"`);
|
|
840
|
+
beneficiary[pair.slice(0, at)] = pair.slice(at + 1);
|
|
841
|
+
}
|
|
842
|
+
const report = await checkCompleteness({
|
|
843
|
+
receiptsDir: values.receipts,
|
|
844
|
+
verify: {
|
|
845
|
+
issuerKeys: values["issuer-key"].map(loadPublicKey),
|
|
846
|
+
principalKeys: (values["principal-key"] ?? []).map(loadPublicKey),
|
|
847
|
+
...(values["approval-key"] ? { approvalKeys: values["approval-key"].map(loadPublicKey) } : {}),
|
|
848
|
+
...(values["log-key"] ? { logKeys: values["log-key"].map(loadPublicKey) } : {}),
|
|
849
|
+
...(values.log ? { logFile: values.log } : {}),
|
|
850
|
+
...(values["log-id"] ? { logId: values["log-id"] } : {}),
|
|
851
|
+
},
|
|
852
|
+
source: stripeSource({ secretKey: secretFrom(values["key-env"]), object: values.object }),
|
|
853
|
+
tools: values.tool,
|
|
854
|
+
sinceMs,
|
|
855
|
+
untilMs,
|
|
856
|
+
...(values["id-path"] ? { idPath: values["id-path"] } : {}),
|
|
857
|
+
...(values["amount-field"] ? { amountField: values["amount-field"] } : {}),
|
|
858
|
+
...(values["currency-field"] ? { currencyField: values["currency-field"] } : {}),
|
|
859
|
+
...(Object.keys(beneficiary).length ? { beneficiary } : {}),
|
|
860
|
+
});
|
|
861
|
+
console.log(values.json ? JSON.stringify(report, null, 2) : formatCompleteness(report));
|
|
862
|
+
return report.complete ? 0 : 1;
|
|
863
|
+
}
|
|
749
864
|
case "policy": {
|
|
750
865
|
const [subcommand, ...args] = rest;
|
|
751
866
|
if (subcommand !== "simulate")
|