@agent-custody/receipts 0.12.0 → 0.13.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 +7 -4
- package/dist/cli.js +71 -0
- package/dist/completeness.d.ts +106 -0
- package/dist/completeness.js +240 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/docs/completeness.md +59 -0
- package/docs/threat-model.md +1 -0
- package/docs/tutorials.md +2 -0
- package/package.json +1 -1
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): thirty-
|
|
13
|
+
- [Tutorials](docs/tutorials.md): thirty-five 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
|
|
@@ -22,6 +22,7 @@ Anyone holding the public keys can verify a receipt offline. The agent is not tr
|
|
|
22
22
|
- [Verifying a receipt](docs/verification.md): what each check means and what a verified receipt does and does not prove
|
|
23
23
|
- [What the evidence satisfies](docs/compliance.md): the receipts, packs, and certificates mapped to SOC 2, ISO 27001, the EU AI Act, and UK GDPR, with what none of them claims
|
|
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
|
|
@@ -192,7 +193,7 @@ Every field carries a provenance label. This is the design decision that matters
|
|
|
192
193
|
bun install # from the repository root, once for the workspace
|
|
193
194
|
cd packages/receipts
|
|
194
195
|
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 thirty-
|
|
196
|
+
node examples/01-keys-and-signing.ts # first of thirty-five step-by-step examples, see docs/tutorials.md
|
|
196
197
|
bun run test # this package; `bun run test` at the root runs every package
|
|
197
198
|
```
|
|
198
199
|
|
|
@@ -251,6 +252,7 @@ src/log-export.ts a tenant's export of their own log, self-checked, as a log fi
|
|
|
251
252
|
src/witness.ts the witness: countersigns the log's checkpoints from another operator's machine, or refuses with an alarm
|
|
252
253
|
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
254
|
src/anchor-evm.ts the anchor's transactions on Ethereum or another EVM chain, through the optional dependency viem
|
|
255
|
+
src/completeness.ts completeness from the provider's side: the provider's own list, matched against verified receipts
|
|
254
256
|
src/signer.ts the signer: the log's key in its own process, the key document verifiers fetch
|
|
255
257
|
src/checkpoints.ts signed heads published on a schedule, to files and to Postgres
|
|
256
258
|
src/log-store.ts the log server's backends: the file, and Postgres with tenants, hashed tokens, one writer per tenant, rate limits
|
|
@@ -281,7 +283,7 @@ src/retention.ts pruning the log: leaves become their hashes, bundles are remo
|
|
|
281
283
|
src/index.ts the package's public surface; adapters are exported on ./sdk/<framework> subpaths
|
|
282
284
|
tsconfig.build.json emits dist/ (JavaScript plus declarations) for consumers; the repo itself runs the .ts directly
|
|
283
285
|
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/ thirty-
|
|
286
|
+
examples/ thirty-five 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
287
|
test/ unit tests per module, end-to-end gateway test, SDK and hook tests,
|
|
286
288
|
adapter tests against the real packages, and a test that runs every policy in docs/policies.md
|
|
287
289
|
docs/ tutorials, usage (gateway), codex-recovery (live demo), approvals, sdk, policies, verification
|
|
@@ -338,13 +340,14 @@ The design is two producers feeding one verifier. The SDK is the top of the funn
|
|
|
338
340
|
- 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
341
|
- 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
342
|
- 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).
|
|
343
|
+
- 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
344
|
|
|
342
345
|
**Next, in the order it pays off**
|
|
343
346
|
|
|
344
347
|
The first three close the gap between a log the operator cannot rewrite and a record the operator cannot shape.
|
|
345
348
|
|
|
346
349
|
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
|
|
350
|
+
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
351
|
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
352
|
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
353
|
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).
|
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";
|
|
@@ -93,6 +94,12 @@ const USAGE = `agent-custody <command>
|
|
|
93
94
|
log --file <log.jsonl> --key <log.key> [--port 8787] [--host 127.0.0.1] [--token-env <NAME>] reference log server
|
|
94
95
|
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
96
|
policy simulate --policy <proposed.cedar> --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--approval-key <pub>]... [--log-key <pub>]... [--json] [--out <file>]
|
|
97
|
+
completeness --receipts <dir> --issuer-key <pub>... [--principal-key <pub>]... [--log-key <pub>]... [--log <log.jsonl>] [--log-id <id>]
|
|
98
|
+
--provider stripe --object refunds|payouts|transfers --key-env NAME --tool <name>... --since <ISO> --until <ISO>
|
|
99
|
+
[--id-path id] [--amount-field amount] [--currency-field currency] [--beneficiary <arg>=<field>]... [--json]
|
|
100
|
+
for an auditor: lists the provider's objects in the window with a read-only key, and
|
|
101
|
+
matches each to a verified receipt by the provider's object id; reports actions with no
|
|
102
|
+
receipt, receipts the provider does not have, and mismatched amounts; exits 1 unless complete
|
|
96
103
|
replay verified local receipts against a proposed policy using their recorded inputs;
|
|
97
104
|
--out saves the full JSON report. Exits 1 when any call could not be evaluated.
|
|
98
105
|
log ... --db-env NAME the same server over Postgres: tenants and tokens from the database, one writer per tenant,
|
|
@@ -746,6 +753,70 @@ async function main(argv) {
|
|
|
746
753
|
console.log(values.json ? JSON.stringify(result, null, 2) : formatReport(result));
|
|
747
754
|
return result.ok ? 0 : 1;
|
|
748
755
|
}
|
|
756
|
+
case "completeness": {
|
|
757
|
+
const { values } = parseArgs({
|
|
758
|
+
args: rest,
|
|
759
|
+
options: {
|
|
760
|
+
receipts: { type: "string" },
|
|
761
|
+
"issuer-key": { type: "string", multiple: true },
|
|
762
|
+
"principal-key": { type: "string", multiple: true },
|
|
763
|
+
"approval-key": { type: "string", multiple: true },
|
|
764
|
+
"log-key": { type: "string", multiple: true },
|
|
765
|
+
log: { type: "string" },
|
|
766
|
+
"log-id": { type: "string" },
|
|
767
|
+
provider: { type: "string" },
|
|
768
|
+
object: { type: "string", default: "refunds" },
|
|
769
|
+
"key-env": { type: "string" },
|
|
770
|
+
tool: { type: "string", multiple: true },
|
|
771
|
+
since: { type: "string" },
|
|
772
|
+
until: { type: "string" },
|
|
773
|
+
"id-path": { type: "string" },
|
|
774
|
+
"amount-field": { type: "string" },
|
|
775
|
+
"currency-field": { type: "string" },
|
|
776
|
+
beneficiary: { type: "string", multiple: true },
|
|
777
|
+
json: { type: "boolean", default: false },
|
|
778
|
+
},
|
|
779
|
+
});
|
|
780
|
+
if (!values.receipts || !values["issuer-key"]?.length || !values["key-env"] || !values.tool?.length || !values.since || !values.until)
|
|
781
|
+
throw new Error("completeness needs --receipts, --issuer-key, --provider stripe, --key-env, --tool, --since and --until");
|
|
782
|
+
if (values.provider !== "stripe")
|
|
783
|
+
throw new Error(`completeness supports --provider stripe; got "${values.provider ?? ""}"`);
|
|
784
|
+
const objects = ["refunds", "payouts", "transfers"];
|
|
785
|
+
if (!objects.includes(values.object))
|
|
786
|
+
throw new Error(`--object is one of ${objects.join(", ")}; got "${values.object}"`);
|
|
787
|
+
const sinceMs = Date.parse(values.since);
|
|
788
|
+
const untilMs = Date.parse(values.until);
|
|
789
|
+
if (!Number.isFinite(sinceMs) || !Number.isFinite(untilMs) || untilMs <= sinceMs)
|
|
790
|
+
throw new Error("--since and --until must be ISO times, --until after --since");
|
|
791
|
+
const beneficiary = {};
|
|
792
|
+
for (const pair of values.beneficiary ?? []) {
|
|
793
|
+
const at = pair.indexOf("=");
|
|
794
|
+
if (at < 1 || at === pair.length - 1)
|
|
795
|
+
throw new Error(`--beneficiary takes <argument>=<provider field>; got "${pair}"`);
|
|
796
|
+
beneficiary[pair.slice(0, at)] = pair.slice(at + 1);
|
|
797
|
+
}
|
|
798
|
+
const report = await checkCompleteness({
|
|
799
|
+
receiptsDir: values.receipts,
|
|
800
|
+
verify: {
|
|
801
|
+
issuerKeys: values["issuer-key"].map(loadPublicKey),
|
|
802
|
+
principalKeys: (values["principal-key"] ?? []).map(loadPublicKey),
|
|
803
|
+
...(values["approval-key"] ? { approvalKeys: values["approval-key"].map(loadPublicKey) } : {}),
|
|
804
|
+
...(values["log-key"] ? { logKeys: values["log-key"].map(loadPublicKey) } : {}),
|
|
805
|
+
...(values.log ? { logFile: values.log } : {}),
|
|
806
|
+
...(values["log-id"] ? { logId: values["log-id"] } : {}),
|
|
807
|
+
},
|
|
808
|
+
source: stripeSource({ secretKey: secretFrom(values["key-env"]), object: values.object }),
|
|
809
|
+
tools: values.tool,
|
|
810
|
+
sinceMs,
|
|
811
|
+
untilMs,
|
|
812
|
+
...(values["id-path"] ? { idPath: values["id-path"] } : {}),
|
|
813
|
+
...(values["amount-field"] ? { amountField: values["amount-field"] } : {}),
|
|
814
|
+
...(values["currency-field"] ? { currencyField: values["currency-field"] } : {}),
|
|
815
|
+
...(Object.keys(beneficiary).length ? { beneficiary } : {}),
|
|
816
|
+
});
|
|
817
|
+
console.log(values.json ? JSON.stringify(report, null, 2) : formatCompleteness(report));
|
|
818
|
+
return report.complete ? 0 : 1;
|
|
819
|
+
}
|
|
749
820
|
case "policy": {
|
|
750
821
|
const [subcommand, ...args] = rest;
|
|
751
822
|
if (subcommand !== "simulate")
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type VerifyOptions } from "./verify.ts";
|
|
2
|
+
/** One provider object, reduced to what the comparison reads. */
|
|
3
|
+
export interface ProviderObject {
|
|
4
|
+
id: string;
|
|
5
|
+
/** when the provider created it, as epoch milliseconds */
|
|
6
|
+
createdMs: number;
|
|
7
|
+
amount?: number;
|
|
8
|
+
currency?: string;
|
|
9
|
+
/** the provider's own object, for beneficiary fields */
|
|
10
|
+
raw: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderSource {
|
|
13
|
+
/** for reports, e.g. "stripe refunds" */
|
|
14
|
+
name: string;
|
|
15
|
+
list(sinceMs: number, untilMs: number): AsyncIterable<ProviderObject>;
|
|
16
|
+
}
|
|
17
|
+
export type StripeObject = "refunds" | "payouts" | "transfers";
|
|
18
|
+
export interface StripeSourceOptions {
|
|
19
|
+
/** a read-only (restricted) key; from the environment, never a flag */
|
|
20
|
+
secretKey: string;
|
|
21
|
+
object: StripeObject;
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
fetch?: typeof fetch;
|
|
24
|
+
}
|
|
25
|
+
/** Lists Stripe objects created in the window, every page, with `created[gte]` and `created[lt]`. */
|
|
26
|
+
export declare function stripeSource(o: StripeSourceOptions): ProviderSource;
|
|
27
|
+
export interface CompletenessOptions {
|
|
28
|
+
/** the auditor's copy of the receipts directory */
|
|
29
|
+
receiptsDir: string;
|
|
30
|
+
/** how each receipt is verified; only receipts that verify are matched */
|
|
31
|
+
verify: VerifyOptions;
|
|
32
|
+
source: ProviderSource;
|
|
33
|
+
/** the tools whose executed calls create provider objects, e.g. ["stripe.refund"] */
|
|
34
|
+
tools: string[];
|
|
35
|
+
sinceMs: number;
|
|
36
|
+
untilMs: number;
|
|
37
|
+
/** where the provider's object id sits in the JSON of the result's first text item; default "id" */
|
|
38
|
+
idPath?: string;
|
|
39
|
+
/** the call argument that holds the amount in minor units; default "amount" */
|
|
40
|
+
amountField?: string;
|
|
41
|
+
/** the call argument that holds the currency; default "currency", compared case-insensitively when both sides have one */
|
|
42
|
+
currencyField?: string;
|
|
43
|
+
/** call argument → provider field pairs that must be equal, e.g. { charge: "charge" } */
|
|
44
|
+
beneficiary?: Record<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* provider objects are listed this far either side of the window, so a receipt signed just inside the window still
|
|
47
|
+
* finds an object the provider created just outside it; default fifteen minutes
|
|
48
|
+
*/
|
|
49
|
+
marginMs?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface CompletenessReport {
|
|
52
|
+
provider: string;
|
|
53
|
+
tools: string[];
|
|
54
|
+
window: {
|
|
55
|
+
since: string;
|
|
56
|
+
until: string;
|
|
57
|
+
};
|
|
58
|
+
receiptsRead: number;
|
|
59
|
+
matched: {
|
|
60
|
+
receiptId: string;
|
|
61
|
+
providerId: string;
|
|
62
|
+
}[];
|
|
63
|
+
/** provider objects in the window with no verified receipt: actions taken outside the gateway */
|
|
64
|
+
providerOnly: {
|
|
65
|
+
providerId: string;
|
|
66
|
+
created: string;
|
|
67
|
+
amount?: number;
|
|
68
|
+
currency?: string;
|
|
69
|
+
}[];
|
|
70
|
+
/** executed receipts in the window whose provider object the provider does not have */
|
|
71
|
+
receiptOnly: {
|
|
72
|
+
receiptId: string;
|
|
73
|
+
providerId: string;
|
|
74
|
+
timestamp: string;
|
|
75
|
+
}[];
|
|
76
|
+
mismatches: {
|
|
77
|
+
receiptId: string;
|
|
78
|
+
providerId: string;
|
|
79
|
+
field: string;
|
|
80
|
+
receipt: unknown;
|
|
81
|
+
provider: unknown;
|
|
82
|
+
}[];
|
|
83
|
+
/** provider objects that more than one verified receipt names: one action recorded twice, or receipts that disagree */
|
|
84
|
+
duplicates: {
|
|
85
|
+
providerId: string;
|
|
86
|
+
receiptIds: string[];
|
|
87
|
+
}[];
|
|
88
|
+
/** receipt files that did not verify, and so were not matched */
|
|
89
|
+
unverified: {
|
|
90
|
+
file: string;
|
|
91
|
+
failing: string[];
|
|
92
|
+
}[];
|
|
93
|
+
/** verified, executed receipts whose provider id cannot be read */
|
|
94
|
+
unmatchable: {
|
|
95
|
+
receiptId: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
}[];
|
|
98
|
+
/** calls committed before they were forwarded whose outcome receipt is missing: each may be a provider object above */
|
|
99
|
+
forwardedWithoutOutcome: {
|
|
100
|
+
receiptId: string;
|
|
101
|
+
tool: string;
|
|
102
|
+
}[];
|
|
103
|
+
complete: boolean;
|
|
104
|
+
}
|
|
105
|
+
export declare function checkCompleteness(o: CompletenessOptions): Promise<CompletenessReport>;
|
|
106
|
+
export declare function formatCompleteness(r: CompletenessReport): string;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Completeness from the provider's side. Receipts prove what went through the gateway; nothing on the gateway's side
|
|
2
|
+
// can see an action that never did. An auditor with a read-only key of their own lists the provider's objects over a
|
|
3
|
+
// window and matches each one to a verified receipt by the provider's object id, which the receipt's result carries.
|
|
4
|
+
// A provider object with no receipt is an action taken outside the gateway; a receipt with no provider object is an
|
|
5
|
+
// action the provider does not have. Nothing here writes, retries, or calls the provider for anything but a list.
|
|
6
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { isCommitment, REST } from "./capture.js";
|
|
9
|
+
import { verifyOrphanAuthorization } from "./simulate.js";
|
|
10
|
+
import { verifyBundle } from "./verify.js";
|
|
11
|
+
/** Lists Stripe objects created in the window, every page, with `created[gte]` and `created[lt]`. */
|
|
12
|
+
export function stripeSource(o) {
|
|
13
|
+
const f = o.fetch ?? fetch;
|
|
14
|
+
const base = o.baseUrl ?? "https://api.stripe.com/";
|
|
15
|
+
return {
|
|
16
|
+
name: `stripe ${o.object}`,
|
|
17
|
+
async *list(sinceMs, untilMs) {
|
|
18
|
+
let after;
|
|
19
|
+
for (;;) {
|
|
20
|
+
const url = new URL(`v1/${o.object}`, base);
|
|
21
|
+
url.searchParams.set("limit", "100");
|
|
22
|
+
url.searchParams.set("created[gte]", String(Math.floor(sinceMs / 1000)));
|
|
23
|
+
url.searchParams.set("created[lt]", String(Math.ceil(untilMs / 1000)));
|
|
24
|
+
if (after)
|
|
25
|
+
url.searchParams.set("starting_after", after);
|
|
26
|
+
const res = await f(url, { headers: { authorization: `Bearer ${o.secretKey}` }, signal: AbortSignal.timeout(15_000) });
|
|
27
|
+
if (!res.ok)
|
|
28
|
+
throw new Error(`stripe ${o.object}: HTTP ${res.status}`);
|
|
29
|
+
const page = (await res.json());
|
|
30
|
+
const data = Array.isArray(page.data) ? page.data : [];
|
|
31
|
+
for (const obj of data) {
|
|
32
|
+
if (typeof obj.id !== "string" || typeof obj.created !== "number")
|
|
33
|
+
throw new Error(`stripe ${o.object}: an object without an id or a created time`);
|
|
34
|
+
yield {
|
|
35
|
+
id: obj.id,
|
|
36
|
+
createdMs: obj.created * 1000,
|
|
37
|
+
...(typeof obj.amount === "number" ? { amount: obj.amount } : {}),
|
|
38
|
+
...(typeof obj.currency === "string" ? { currency: obj.currency } : {}),
|
|
39
|
+
raw: obj,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (!page.has_more || data.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
after = data[data.length - 1].id;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const AUTHORIZATION = ".authorization.json";
|
|
50
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
51
|
+
function at(value, path) {
|
|
52
|
+
let v = value;
|
|
53
|
+
for (const part of path.split(".")) {
|
|
54
|
+
if (!v || typeof v !== "object" || !Object.hasOwn(v, part))
|
|
55
|
+
return undefined;
|
|
56
|
+
v = v[part];
|
|
57
|
+
}
|
|
58
|
+
return v;
|
|
59
|
+
}
|
|
60
|
+
/** The provider object id that an executed call's result carries, or why it cannot be read. */
|
|
61
|
+
function providerIdOf(p, idPath) {
|
|
62
|
+
const result = p.execution.result;
|
|
63
|
+
if (isCommitment(result))
|
|
64
|
+
return { reason: "the result is withheld under a capture rule; the provider's object id cannot be read from the receipt" };
|
|
65
|
+
const r = result;
|
|
66
|
+
// a `$rest` commitment may hold only unrelated fields: the content is withheld only when it is not kept in clear
|
|
67
|
+
if (r && !Object.hasOwn(r, "content") && isCommitment(r[REST]))
|
|
68
|
+
return { reason: "the result content is withheld under a capture rule; the provider's object id cannot be read from the receipt" };
|
|
69
|
+
const content = r?.content;
|
|
70
|
+
const first = Array.isArray(content) ? content[0] : undefined;
|
|
71
|
+
if (isCommitment(content) || isCommitment(first))
|
|
72
|
+
return { reason: "the result content is withheld under a capture rule; the provider's object id cannot be read from the receipt" };
|
|
73
|
+
const text = first?.text;
|
|
74
|
+
if (isCommitment(text))
|
|
75
|
+
return { reason: "the result content is withheld under a capture rule; the provider's object id cannot be read from the receipt" };
|
|
76
|
+
if (typeof text !== "string")
|
|
77
|
+
return { reason: "the result carries no text to read the provider's object id from" };
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = JSON.parse(text);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return { reason: "the result's text is not JSON" };
|
|
84
|
+
}
|
|
85
|
+
const id = at(parsed, idPath);
|
|
86
|
+
return typeof id === "string" && id.length ? { id } : { reason: `the result has no string at "${idPath}"` };
|
|
87
|
+
}
|
|
88
|
+
/** A call argument, or that a capture rule withholds it: listed fields stay in clear beside one `$rest` commitment. */
|
|
89
|
+
function argOf(args, field) {
|
|
90
|
+
if (Object.hasOwn(args, field))
|
|
91
|
+
return isCommitment(args[field]) ? { withheld: true } : { value: args[field] };
|
|
92
|
+
return isCommitment(args[REST]) ? { withheld: true } : { value: undefined };
|
|
93
|
+
}
|
|
94
|
+
export async function checkCompleteness(o) {
|
|
95
|
+
const idPath = o.idPath ?? "id";
|
|
96
|
+
const amountField = o.amountField ?? "amount";
|
|
97
|
+
const currencyField = o.currencyField ?? "currency";
|
|
98
|
+
const margin = o.marginMs ?? 15 * 60_000;
|
|
99
|
+
const tools = new Set(o.tools);
|
|
100
|
+
const inWindow = (ms) => ms >= o.sinceMs && ms < o.untilMs;
|
|
101
|
+
const report = {
|
|
102
|
+
provider: o.source.name,
|
|
103
|
+
tools: [...o.tools],
|
|
104
|
+
window: { since: iso(o.sinceMs), until: iso(o.untilMs) },
|
|
105
|
+
receiptsRead: 0,
|
|
106
|
+
matched: [],
|
|
107
|
+
providerOnly: [],
|
|
108
|
+
receiptOnly: [],
|
|
109
|
+
mismatches: [],
|
|
110
|
+
duplicates: [],
|
|
111
|
+
unverified: [],
|
|
112
|
+
unmatchable: [],
|
|
113
|
+
forwardedWithoutOutcome: [],
|
|
114
|
+
complete: false,
|
|
115
|
+
};
|
|
116
|
+
const names = readdirSync(o.receiptsDir, { withFileTypes: true }).filter((e) => (e.isFile() || e.isSymbolicLink()) && e.name.endsWith(".json")).map((e) => e.name).sort();
|
|
117
|
+
const outcomes = new Set();
|
|
118
|
+
const byProviderId = new Map();
|
|
119
|
+
for (const name of names) {
|
|
120
|
+
if (name.endsWith(AUTHORIZATION))
|
|
121
|
+
continue;
|
|
122
|
+
report.receiptsRead++;
|
|
123
|
+
let result;
|
|
124
|
+
try {
|
|
125
|
+
result = verifyBundle(JSON.parse(readFileSync(join(o.receiptsDir, name), "utf8")), o.verify);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
report.unverified.push({ file: name, failing: [e instanceof Error ? e.message : String(e)] });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!result.ok || !result.statement) {
|
|
132
|
+
report.unverified.push({ file: name, failing: result.checks.filter((c) => !c.ok).map((c) => c.name) });
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const p = result.statement.predicate;
|
|
136
|
+
// the gateway names each file by its receipt id: a valid receipt under another name could stand in for a missing outcome
|
|
137
|
+
if (name !== `${p.receiptId}.json`) {
|
|
138
|
+
report.unverified.push({ file: name, failing: [`the file name does not match the signed receipt id ${p.receiptId}`] });
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
outcomes.add(p.receiptId);
|
|
142
|
+
if (!tools.has(p.tool.name) || p.reconciliation || p.execution.status !== "executed")
|
|
143
|
+
continue;
|
|
144
|
+
const id = providerIdOf(p, idPath);
|
|
145
|
+
if ("reason" in id) {
|
|
146
|
+
if (inWindow(Date.parse(p.timestamp)))
|
|
147
|
+
report.unmatchable.push({ receiptId: p.receiptId, reason: id.reason });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
byProviderId.set(id.id, [...(byProviderId.get(id.id) ?? []), p]);
|
|
151
|
+
}
|
|
152
|
+
for (const name of names) {
|
|
153
|
+
if (!name.endsWith(AUTHORIZATION))
|
|
154
|
+
continue;
|
|
155
|
+
// committed and forwarded, then nothing: the provider may hold an object this report cannot tie to a receipt
|
|
156
|
+
let auth;
|
|
157
|
+
try {
|
|
158
|
+
auth = verifyOrphanAuthorization(JSON.parse(readFileSync(join(o.receiptsDir, name), "utf8")), o.verify.issuerKeys, o.verify.logKeys ?? []);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
report.unverified.push({ file: name, failing: [e instanceof Error ? e.message : String(e)] });
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (name !== `${auth.receiptId}${AUTHORIZATION}`)
|
|
165
|
+
report.unverified.push({ file: name, failing: [`the file name does not match the signed receipt id ${auth.receiptId}`] });
|
|
166
|
+
if (outcomes.has(auth.receiptId) || !tools.has(auth.tool.name) || !inWindow(Date.parse(auth.timestamp)))
|
|
167
|
+
continue;
|
|
168
|
+
report.forwardedWithoutOutcome.push({ receiptId: auth.receiptId, tool: auth.tool.name });
|
|
169
|
+
}
|
|
170
|
+
const seen = new Set();
|
|
171
|
+
for await (const obj of o.source.list(o.sinceMs - margin, o.untilMs + margin)) {
|
|
172
|
+
seen.add(obj.id);
|
|
173
|
+
const receipts = byProviderId.get(obj.id) ?? [];
|
|
174
|
+
// the margin finds a receipt across the window's edge; it does not widen the period reported on
|
|
175
|
+
const inScope = inWindow(obj.createdMs) || receipts.some((p) => inWindow(Date.parse(p.timestamp)));
|
|
176
|
+
if (!inScope)
|
|
177
|
+
continue;
|
|
178
|
+
if (!receipts.length) {
|
|
179
|
+
report.providerOnly.push({ providerId: obj.id, created: iso(obj.createdMs), ...(obj.amount !== undefined ? { amount: obj.amount } : {}), ...(obj.currency !== undefined ? { currency: obj.currency } : {}) });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (receipts.length > 1)
|
|
183
|
+
report.duplicates.push({ providerId: obj.id, receiptIds: receipts.map((p) => p.receiptId) });
|
|
184
|
+
for (const p of receipts) {
|
|
185
|
+
report.matched.push({ receiptId: p.receiptId, providerId: obj.id });
|
|
186
|
+
const args = p.request.args;
|
|
187
|
+
const withheld = (arg) => report.unmatchable.push({ receiptId: p.receiptId, reason: `the argument "${arg}" is withheld under a capture rule, so it cannot be compared` });
|
|
188
|
+
const amount = argOf(args, amountField);
|
|
189
|
+
if ("withheld" in amount) {
|
|
190
|
+
if (obj.amount !== undefined)
|
|
191
|
+
withheld(amountField);
|
|
192
|
+
}
|
|
193
|
+
else if (obj.amount !== undefined && amount.value !== obj.amount)
|
|
194
|
+
report.mismatches.push({ receiptId: p.receiptId, providerId: obj.id, field: "amount", receipt: amount.value, provider: obj.amount });
|
|
195
|
+
const currency = argOf(args, currencyField);
|
|
196
|
+
if ("withheld" in currency) {
|
|
197
|
+
if (obj.currency !== undefined)
|
|
198
|
+
withheld(currencyField);
|
|
199
|
+
}
|
|
200
|
+
else if (typeof currency.value === "string" && obj.currency !== undefined && currency.value.toLowerCase() !== obj.currency.toLowerCase())
|
|
201
|
+
report.mismatches.push({ receiptId: p.receiptId, providerId: obj.id, field: "currency", receipt: currency.value, provider: obj.currency });
|
|
202
|
+
for (const [arg, field] of Object.entries(o.beneficiary ?? {})) {
|
|
203
|
+
const value = argOf(args, arg);
|
|
204
|
+
if ("withheld" in value || value.value === undefined) {
|
|
205
|
+
report.unmatchable.push({ receiptId: p.receiptId, reason: `the beneficiary argument "${arg}" is missing or withheld, so it cannot be compared` });
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const provider = at(obj.raw, field);
|
|
209
|
+
if (String(value.value) !== String(provider))
|
|
210
|
+
report.mismatches.push({ receiptId: p.receiptId, providerId: obj.id, field: arg, receipt: value.value, provider });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const [providerId, receipts] of byProviderId) {
|
|
215
|
+
if (seen.has(providerId))
|
|
216
|
+
continue;
|
|
217
|
+
for (const p of receipts)
|
|
218
|
+
if (inWindow(Date.parse(p.timestamp)))
|
|
219
|
+
report.receiptOnly.push({ receiptId: p.receiptId, providerId, timestamp: p.timestamp });
|
|
220
|
+
}
|
|
221
|
+
report.matched.sort((a, b) => a.receiptId.localeCompare(b.receiptId));
|
|
222
|
+
report.complete = [report.providerOnly, report.receiptOnly, report.mismatches, report.duplicates, report.unverified, report.unmatchable, report.forwardedWithoutOutcome].every((l) => l.length === 0);
|
|
223
|
+
return report;
|
|
224
|
+
}
|
|
225
|
+
export function formatCompleteness(r) {
|
|
226
|
+
const lines = [`${r.provider} for ${r.tools.join(", ")}, ${r.window.since} to ${r.window.until}: ${r.receiptsRead} receipt(s) read, ${r.matched.length} matched`];
|
|
227
|
+
const section = (title, rows) => {
|
|
228
|
+
if (rows.length)
|
|
229
|
+
lines.push("", `${title} (${rows.length})`, ...rows.map((row) => ` ${row}`));
|
|
230
|
+
};
|
|
231
|
+
section("PROVIDER ACTIONS WITH NO RECEIPT", r.providerOnly.map((x) => `${x.providerId} created ${x.created}${x.amount !== undefined ? ` amount ${x.amount}${x.currency ? ` ${x.currency}` : ""}` : ""}`));
|
|
232
|
+
section("RECEIPTS THE PROVIDER DOES NOT HAVE", r.receiptOnly.map((x) => `${x.receiptId} names ${x.providerId}, signed ${x.timestamp}`));
|
|
233
|
+
section("MISMATCHES", r.mismatches.map((x) => `${x.receiptId} / ${x.providerId}: ${x.field} is ${JSON.stringify(x.receipt)} in the receipt, ${JSON.stringify(x.provider)} at the provider`));
|
|
234
|
+
section("ONE PROVIDER OBJECT, SEVERAL RECEIPTS", r.duplicates.map((x) => `${x.providerId} is named by ${x.receiptIds.join(", ")}`));
|
|
235
|
+
section("FORWARDED WITHOUT AN OUTCOME RECEIPT", r.forwardedWithoutOutcome.map((x) => `${x.receiptId} (${x.tool}): committed and forwarded, no receipt of the outcome`));
|
|
236
|
+
section("UNMATCHABLE", r.unmatchable.map((x) => `${x.receiptId}: ${x.reason}`));
|
|
237
|
+
section("NOT VERIFIED, NOT MATCHED", r.unverified.map((x) => `${x.file}: ${x.failing.join("; ")}`));
|
|
238
|
+
lines.push("", r.complete ? "RESULT: COMPLETE" : "RESULT: INCOMPLETE");
|
|
239
|
+
return lines.join("\n");
|
|
240
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export { bothCheckpoints, dirCheckpoints, postgresCheckpoints } from "./checkpoi
|
|
|
26
26
|
export { adminRoutes, welcomeSheet } from "./log-admin.ts";
|
|
27
27
|
export { fetchWitnessKeys, Witness } from "./witness.ts";
|
|
28
28
|
export { Anchor, ANCHOR_CHAINS, anchorCalldata, anchorLeaf, checkAnchorRecord, resolveAnchorChain } from "./anchor.ts";
|
|
29
|
+
export { checkCompleteness, formatCompleteness, stripeSource } from "./completeness.ts";
|
|
30
|
+
export type { CompletenessOptions, CompletenessReport, ProviderObject, ProviderSource, StripeObject, StripeSourceOptions } from "./completeness.ts";
|
|
29
31
|
export type { AnchorChain, AnchorCheck, AnchorCheckOptions, AnchorOptions, AnchorRecord, AnchorRun, AnchorTenantOutcome, AnchorTxOutcome } from "./anchor.ts";
|
|
30
32
|
export { evmChain } from "./anchor-evm.ts";
|
|
31
33
|
export type { EvmChainOptions } from "./anchor-evm.ts";
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { bothCheckpoints, dirCheckpoints, postgresCheckpoints } from "./checkpoi
|
|
|
18
18
|
export { adminRoutes, welcomeSheet } from "./log-admin.js";
|
|
19
19
|
export { fetchWitnessKeys, Witness } from "./witness.js";
|
|
20
20
|
export { Anchor, ANCHOR_CHAINS, anchorCalldata, anchorLeaf, checkAnchorRecord, resolveAnchorChain } from "./anchor.js";
|
|
21
|
+
export { checkCompleteness, formatCompleteness, stripeSource } from "./completeness.js";
|
|
21
22
|
export { evmChain } from "./anchor-evm.js";
|
|
22
23
|
export { checkLog, formatLogCheck } from "./log-check.js";
|
|
23
24
|
export * from "./config.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Completeness: matching the provider's records against the receipts
|
|
2
|
+
|
|
3
|
+
A verified receipt proves what went through the gateway. Nothing on the gateway's side can see an action that never went through it: whoever holds the Stripe key can issue a refund straight through Stripe's API. The provider's own record is the only place that action shows. `agent-custody completeness` lets an auditor check it, with a read-only key of their own.
|
|
4
|
+
|
|
5
|
+
## What it reports
|
|
6
|
+
|
|
7
|
+
For a window and a set of tools, it lists the provider's objects and matches each to a verified receipt by the provider's object id, which the receipt's result carries.
|
|
8
|
+
|
|
9
|
+
| section | meaning | what to do |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| provider actions with no receipt | an object the provider created in the window that no verified receipt names | the finding this command exists for: an action taken outside the gateway, or by a gateway whose receipts you were not given |
|
|
12
|
+
| receipts the provider does not have | an executed receipt in the window whose object the provider has no record of | a receipt for something that did not happen at the provider, or an object in another account or mode |
|
|
13
|
+
| mismatches | a matched pair whose amount, currency (ignoring case), or a beneficiary field differs | the receipt and the provider disagree about what happened |
|
|
14
|
+
| one provider object, several receipts | more than one verified receipt names the same provider object; each is still compared with it | one action recorded twice, or receipts that contradict each other |
|
|
15
|
+
| forwarded without an outcome receipt | a call committed to the log before it was forwarded (`precommit`) whose outcome receipt is missing | the gateway stopped after forwarding; this explains a provider object that has no receipt, without guessing which one |
|
|
16
|
+
| unmatchable | a verified, executed receipt whose provider id cannot be read, or whose amount, currency, or beneficiary argument cannot be compared, because a capture rule withholds it | match it by hand against the values disclosed with `agent-custody reveal` |
|
|
17
|
+
| not verified | a receipt file that failed verification, or a valid receipt or authorization stored under a name that is not its signed receipt id | it is not matched, so its provider object shows as having no receipt |
|
|
18
|
+
|
|
19
|
+
The result is `COMPLETE` only when every section but the matches is empty, and the command exits 1 otherwise.
|
|
20
|
+
|
|
21
|
+
Only receipts that verify against the keys you give are matched. A forged or edited receipt file cannot cover for a provider action, because it fails verification and its object then appears as having no receipt. Denied, withheld, and failed calls are not expected to have a provider object, and reconciliation receipts are skipped, because the original receipt is the one that names the object.
|
|
22
|
+
|
|
23
|
+
The provider is listed fifteen minutes either side of the window (`marginMs` in code), so a receipt signed just inside the window still finds an object created just outside it. The margin does not widen the period reported on: a pair is reported only when its receipt or its object falls inside the window, and a call forwarded without an outcome only when its authorization was signed inside it.
|
|
24
|
+
|
|
25
|
+
An authorization is tied to its outcome by the receipt id both of them sign, never by the file name. A valid receipt copied under the name of a missing outcome therefore hides nothing: it is reported as not verified, and the call is still listed as forwarded without an outcome.
|
|
26
|
+
|
|
27
|
+
## Running it
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
export STRIPE_AUDIT_KEY=rk_live_... # a restricted key with read access to refunds, held by the auditor
|
|
31
|
+
agent-custody completeness --receipts ./receipts --issuer-key gateway.pub --principal-key principal.pub \
|
|
32
|
+
--log log.jsonl --provider stripe --object refunds --key-env STRIPE_AUDIT_KEY \
|
|
33
|
+
--tool stripe.refund --since 2026-10-01T00:00:00Z --until 2026-11-01T00:00:00Z
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| flag | default | meaning |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `--receipts <dir>` | | the auditor's copy of the receipts directory, authorization files included |
|
|
39
|
+
| `--issuer-key`, `--principal-key`, `--approval-key`, `--log-key`, `--log`, `--log-id` | | how each receipt is verified, as for `verify` |
|
|
40
|
+
| `--provider stripe` | | the provider; Stripe is the only one so far |
|
|
41
|
+
| `--object` | `refunds` | `refunds`, `payouts`, or `transfers` |
|
|
42
|
+
| `--key-env NAME` | | the environment variable holding the read-only key; never a flag value |
|
|
43
|
+
| `--tool <name>` | | each tool whose executed calls create provider objects; repeatable |
|
|
44
|
+
| `--since`, `--until` | | the window, ISO times; `--until` is exclusive |
|
|
45
|
+
| `--id-path` | `id` | where the provider's object id sits in the JSON of the result's first text item; Stripe's own response uses `id` |
|
|
46
|
+
| `--amount-field`, `--currency-field` | `amount`, `currency` | the call arguments compared with the provider's amount and currency |
|
|
47
|
+
| `--beneficiary <arg>=<field>` | | a call argument that must equal a provider field, such as `charge=charge` or `customer_id=metadata.customer_id`; repeatable |
|
|
48
|
+
| `--json` | | the full report as JSON |
|
|
49
|
+
|
|
50
|
+
Use a restricted Stripe key with read-only access to the objects you check. The command only lists objects: it never creates, retries, or reconciles anything. The operator's `reconcile` command is a different thing: it settles one financial operation through the gateway and writes a receipt.
|
|
51
|
+
|
|
52
|
+
## Limits
|
|
53
|
+
|
|
54
|
+
- **The receipts you were given.** The check proves completeness against those receipts. A second gateway, or a second receipts directory, that issued receipts you were not handed shows up as provider actions with no receipt, which is the correct finding.
|
|
55
|
+
- **One provider account and mode per run.** Test-mode and live-mode objects are separate lists.
|
|
56
|
+
- **The id must be readable.** A capture rule that withholds the result content also withholds the object id inside it, and such receipts are reported as unmatchable, never as matched or missing. A rule that keeps `content` in clear (`result: { mode: "digest", clear: ["content"] }`) leaves the id readable. Likewise, keep the amount, currency, and beneficiary arguments in clear, or those comparisons are reported as unmatchable. Reading values from disclosures is still to come.
|
|
57
|
+
- **Stripe first.** Other providers, and on-chain transfers from an agent's wallet, are `ProviderSource` implementations still to come.
|
|
58
|
+
|
|
59
|
+
In code, `checkCompleteness({ receiptsDir, verify, source, tools, sinceMs, untilMs })` returns the report, `stripeSource({ secretKey, object })` lists Stripe objects, and `formatCompleteness(report)` prints it. Example 35 runs the whole check against a stand-in for Stripe's list API.
|
package/docs/threat-model.md
CHANGED
|
@@ -53,6 +53,7 @@ Each row names the attacker, the move, the defence, and whether the defence is a
|
|
|
53
53
|
| Rewrite a receipt after the fact | The receipt's envelope is signed by the gateway key, which the operator holds, so the signature alone does not stop this. What stops it is the log: the leaf hash of the original envelope is in a tree whose head the log signed, and a rewritten receipt has a different hash with no inclusion proof. | evidence, with a remote log; deployment, with a local log the operator can rewrite |
|
|
54
54
|
| Drop a receipt | The log's tree only grows, and consistency proofs between any two heads show nothing was removed. A receipt the operator never logged never existed as evidence, which is the point of `precommit` for consequential calls: the authorization leaf goes in before the action. [Strict mode](usage.md#strict-mode) does that for every call, with a remote hash-only log and no outbox, and its receipts say so, so a verifier can require it; a modified gateway can still claim strict mode. | evidence for logged receipts; withheld calls for pre-committed tools, and for every call under strict mode |
|
|
55
55
|
| Forge a receipt for an action that never happened | Nothing in the log stops the operator logging a fabricated receipt; the log commits to existence, not truth. What limits it: the upstream's signature over the result when the upstream signs, provider attestations where the provider delivers them, and the principal's signature on the grant. A forged receipt for a signing upstream fails its `upstream` checks. | evidence, where the upstream signs; otherwise the operator's word |
|
|
56
|
+
| Act outside the gateway with the provider's own credentials | Nothing on the gateway's side sees it. `agent-custody completeness` lists the provider's objects with the auditor's own read-only key and reports each one that no verified receipt names; a forged receipt file fails verification and cannot cover for it. | evidence, for a provider that lists its objects (Stripe today) |
|
|
56
57
|
| Replace the policy and claim a different one decided | The receipt carries the sha256 of the policy text; a verifier with the policy file can check it, and a policy change is a different digest in every later receipt. | evidence |
|
|
57
58
|
| Produce a second, cleaner history | With a remote log, both histories would need heads signed by the log's key at the same size with different roots; the checkpoints host and the witness make that detectable. With a local log, a copy taken earlier by someone else is the only defence. | evidence with a witnessed remote log |
|
|
58
59
|
| Erase what an agent believed | `forget` erases the value and leaves a digest keyed by a forget key held outside the ledger, so the erasure is provable without the value. A forget with `none` leaves nothing and the custody pack says so. | evidence |
|
package/docs/tutorials.md
CHANGED
|
@@ -44,6 +44,7 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
44
44
|
| 32 | the gateway console | [32-console.ts](../examples/32-console.ts) | a gateway that has made two receipts, and its operator's console: a token on every route, the receipts with a verdict each, a stricter policy replayed against the recorded calls before it is saved, the save recorded with the old version kept and a stale edit refused, and a grant inspected, revoked, and then refused by the gateway | `src/console.ts`, `src/console-page.ts` |
|
|
45
45
|
| 33 | anchoring the log on a chain | [33-chain-anchor.ts](../examples/33-chain-anchor.ts) | a log publishes a checkpoint, the anchor commits it to a stand-in chain in one transaction, and `log-check` passes against the chain; the operator swaps in a rewritten log under the same key and log id, and `log-check` fails it from the chain alone |
|
|
46
46
|
| 34 | strict mode | [34-strict-mode.ts](../examples/34-strict-mode.ts) | `check` lists what strict mode would refuse; a local log and a log that is not hash-only are refused at startup; behind a hash-only log with a pinned key, a read is precommitted and its receipt says `issuer.strict`; `requireStrict` accepts it and refuses an ordinary receipt; with the log down the call is not forwarded and the outbox stays empty | `src/config.ts`, `src/gateway.ts`, `src/check.ts`, `src/verify.ts` |
|
|
47
|
+
| 35 | completeness from the provider's side | [35-completeness.ts](../examples/35-completeness.ts) | two refunds through the gateway and a third issued straight through the provider; the auditor lists the provider's refunds with a read-only key, matches two to verified receipts, and reports the third as an action with no receipt |
|
|
47
48
|
|
|
48
49
|
## How policies are defined, in one paragraph
|
|
49
50
|
|
|
@@ -55,6 +56,7 @@ A policy is a Cedar file. The gateway turns each tool call into a Cedar request:
|
|
|
55
56
|
- [codex-recovery.md](codex-recovery.md): the opt-in live Codex support incident, operator-reviewed recovery, and its offline state example
|
|
56
57
|
- [approvals.md](approvals.md): exact-action signatures, two-person thresholds, consumption, and privacy limits
|
|
57
58
|
- [console.md](console.md): the admin console: run it, what each tab does, how it is protected, and its limits
|
|
59
|
+
- [completeness.md](completeness.md): matching the provider's own records against verified receipts, to find actions taken outside the gateway
|
|
58
60
|
- [anchoring.md](anchoring.md): the log's checkpoints on Ethereum: what an anchor proves, running it, and checking a log against the chain
|
|
59
61
|
- [financial-operations.md](financial-operations.md): payment retries, budget reservations, provider contract, and operator reconciliation
|
|
60
62
|
- [sdk.md](sdk.md): the interceptor and every adapter
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/receipts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"mcpName": "io.github.svayatta/agent-custody",
|
|
5
5
|
"description": "Chain of custody for AI agents: signed, independently verifiable receipts for tool calls. MCP gateway + Cedar policy + Merkle transparency log",
|
|
6
6
|
"license": "Apache-2.0",
|