@agent-custody/receipts 0.6.18 → 0.7.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 +18 -11
- package/dist/a2a.d.ts +93 -0
- package/dist/a2a.js +391 -0
- package/dist/capture.d.ts +153 -0
- package/dist/capture.js +559 -0
- package/dist/cli.js +117 -5
- package/dist/config.d.ts +92 -0
- package/dist/config.js +34 -2
- package/dist/crypto.d.ts +2 -2
- package/dist/crypto.js +7 -4
- package/dist/delegation.d.ts +7 -0
- package/dist/delegation.js +15 -1
- package/dist/gateway-http.js +13 -1
- package/dist/gateway.d.ts +10 -0
- package/dist/gateway.js +136 -13
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/issue.d.ts +14 -4
- package/dist/issue.js +66 -7
- package/dist/log-sink.d.ts +11 -1
- package/dist/log-sink.js +24 -5
- package/dist/otel.js +5 -4
- package/dist/portal.d.ts +23 -2
- package/dist/portal.js +181 -36
- package/dist/receipt.d.ts +19 -8
- package/dist/retention.d.ts +8 -1
- package/dist/retention.js +21 -2
- package/dist/sdk/index.js +10 -1
- package/dist/splunk.js +6 -4
- package/dist/upstream.d.ts +9 -7
- package/dist/upstream.js +16 -8
- package/dist/verify.d.ts +16 -0
- package/dist/verify.js +171 -13
- package/docs/compliance.md +9 -3
- package/docs/sdk.md +19 -0
- package/docs/tutorials.md +5 -0
- package/docs/usage.md +68 -3
- package/docs/verification.md +11 -4
- package/package.json +4 -3
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1394 -270
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { AuthorizationPredicate } from "./receipt.ts";
|
|
2
|
+
export type CaptureMode = "clear" | "digest" | "encrypted";
|
|
3
|
+
/** One side of a call: the arguments, the result, or the facts. */
|
|
4
|
+
export interface CaptureSide {
|
|
5
|
+
/** clear: the side in the receipt as it was; digest: withheld fields leave a commitment; encrypted: withheld fields leave a commitment and the value under the customer's key */
|
|
6
|
+
mode: CaptureMode;
|
|
7
|
+
/** top-level fields kept in clear in digest or encrypted mode, e.g. the amount and the customer id of a refund */
|
|
8
|
+
clear?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A tool's rule. Once any side is private, the rule is private: a side it does not set is withheld whole, field by
|
|
12
|
+
* field, and so is every other value in the receipt that is not structural (policy errors, an error message, a denial
|
|
13
|
+
* reason, the result's metadata, a provider's delivery body). A side set to mode clear stays in clear.
|
|
14
|
+
*/
|
|
15
|
+
export interface CaptureRule {
|
|
16
|
+
args?: CaptureSide;
|
|
17
|
+
result?: CaptureSide;
|
|
18
|
+
facts?: CaptureSide;
|
|
19
|
+
}
|
|
20
|
+
/** by tool name, or "*" for every tool without a rule of its own */
|
|
21
|
+
export type CaptureConfig = Record<string, CaptureRule>;
|
|
22
|
+
/** A path into the predicate, one segment per key: `["request", "args", "reason"]`. Segments are keys, so a field named "." or "*" is just a field. */
|
|
23
|
+
export type Path = string[];
|
|
24
|
+
/**
|
|
25
|
+
* On the receipt, inside the signed statement: how the call was captured and which paths are withheld. The verifier
|
|
26
|
+
* trusts the note, not the shape of the data: a path the note names must hold a commitment, and commitment-shaped data
|
|
27
|
+
* at a path the note does not name is ordinary data, in the digest like anything else.
|
|
28
|
+
*/
|
|
29
|
+
export interface CaptureNote {
|
|
30
|
+
mode: "digest" | "encrypted";
|
|
31
|
+
withheld: Path[];
|
|
32
|
+
}
|
|
33
|
+
export interface Withheld {
|
|
34
|
+
$custody: "withheld";
|
|
35
|
+
/** sha256 over salt || canonical JSON of the value; the salt is not in the receipt */
|
|
36
|
+
sha256: string;
|
|
37
|
+
}
|
|
38
|
+
export interface Encrypted {
|
|
39
|
+
$custody: "encrypted";
|
|
40
|
+
alg: "A256GCM";
|
|
41
|
+
/** sha256 of the key, so a reviewer knows which key reveals it */
|
|
42
|
+
keyid: string;
|
|
43
|
+
iv: string;
|
|
44
|
+
/** AES-256-GCM over the canonical JSON of `{ salt, value }` */
|
|
45
|
+
ciphertext: string;
|
|
46
|
+
tag: string;
|
|
47
|
+
sha256: string;
|
|
48
|
+
}
|
|
49
|
+
export type Commitment = Withheld | Encrypted;
|
|
50
|
+
/** What a disclosure carries at a withheld path: the value and the salt the commitment was made with. Without `value` it is unfinished (`reveal --include-salts` writes it so for the holder to fill in) and fails verification. */
|
|
51
|
+
export interface Disclosed {
|
|
52
|
+
$custody: "disclosed";
|
|
53
|
+
salt: string;
|
|
54
|
+
value?: unknown;
|
|
55
|
+
}
|
|
56
|
+
/** A 32-byte key from hex (64 chars) or base64 (44 chars), as an environment variable holds it. */
|
|
57
|
+
export declare function captureKeyFrom(text: string): Buffer;
|
|
58
|
+
export declare function captureKeyId(key: Buffer): string;
|
|
59
|
+
/** A well-formed commitment: the sha256 a verifier checks, and for an encrypted one the fields the key needs. A `$custody` tag alone is not one. */
|
|
60
|
+
export declare function isCommitment(v: unknown): v is Commitment;
|
|
61
|
+
/** What an encrypted commitment is bound to: the receipt and the path, so a ciphertext moved to another receipt or path does not decrypt. */
|
|
62
|
+
export declare function aadFor(receiptId: unknown, path: Path): string;
|
|
63
|
+
/** A disclosed value as a disclosure carries it: the salt, and the value when the holder has filled it in. */
|
|
64
|
+
export declare function isDisclosed(v: unknown): v is Disclosed;
|
|
65
|
+
/** Replaces a value with its commitment, carrying the value and the salt encrypted when a key is given (bound to `aad`, see `aadFor`); the salt is returned to the caller, never written into the receipt. */
|
|
66
|
+
export declare function withhold(value: unknown, key?: Buffer, aad?: string): {
|
|
67
|
+
commitment: Commitment;
|
|
68
|
+
salt: string;
|
|
69
|
+
};
|
|
70
|
+
/** True when `value` under `salt` is what the commitment was made over. */
|
|
71
|
+
export declare function checkCommitment(c: Commitment, value: unknown, salt: string): boolean;
|
|
72
|
+
/** The value and the salt behind an encrypted commitment, under the key that made it; checked against the commitment too. */
|
|
73
|
+
export declare function reveal(c: Commitment, key: Buffer, aad?: string): {
|
|
74
|
+
value: unknown;
|
|
75
|
+
salt: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The salt of a digest over a part that holds withheld values: derived from the salts of those values, in note order,
|
|
79
|
+
* so whoever can restore the values can recompute the digest and nobody else can confirm a guess against it. No salt
|
|
80
|
+
* when nothing under the part is withheld: the values are public, and so may the digest be.
|
|
81
|
+
*/
|
|
82
|
+
export declare function digestSalt(salts: string[]): string | undefined;
|
|
83
|
+
/** The tool's rule, else the "*" rule: by own property, so a tool named `constructor` or `toString` does not find an inherited member and fall through to clear. */
|
|
84
|
+
export declare function ruleFor(capture: CaptureConfig | undefined, tool: string): CaptureRule | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The rule for a call: the tool's own, else the wildcard. For a name no upstream offers, which is text the agent
|
|
87
|
+
* chose, both together, side by side: the more private mode, and only the fields both keep in clear, so that a rule
|
|
88
|
+
* left for a retired name can never be selected by an agent to widen what is in clear. A mode does not order which
|
|
89
|
+
* fields are public, so the clear lists are intersected, not taken from the more private rule. The gateway and the
|
|
90
|
+
* issuer both call this, so the fact arguments kept in clear and the view agree.
|
|
91
|
+
*/
|
|
92
|
+
export declare function effectiveRule(capture: CaptureConfig | undefined, tool: string, unknownTool?: boolean): CaptureRule | undefined;
|
|
93
|
+
/** The one mode a rule withholds in: encrypted when any side is, else digest; clear when no side is private. */
|
|
94
|
+
export declare function ruleMode(rule: CaptureRule | undefined): CaptureMode;
|
|
95
|
+
export declare const pathKey: (p: Path) => string;
|
|
96
|
+
export declare const pathText: (p: Path) => string;
|
|
97
|
+
export declare const under: (p: Path, prefix: Path) => boolean;
|
|
98
|
+
/** The value at a path, by own properties only; undefined when the path leaves the data. */
|
|
99
|
+
export declare function getAt(root: unknown, path: Path): unknown;
|
|
100
|
+
/** A copy of `root` with `value` at `path`, every object on the way copied (null-prototype), the rest shared. Creates objects for missing segments. */
|
|
101
|
+
export declare function setAt<T>(root: T, path: Path, value: unknown): T;
|
|
102
|
+
/** the slot in a captured side's view that holds the commitment over every field not kept in clear */
|
|
103
|
+
export declare const REST = "$rest";
|
|
104
|
+
/** What the producer knows about this call that the view needs: which fact arguments copy a call argument that is in clear, and the full lookup results behind the fact digests. */
|
|
105
|
+
export interface CaptureContext {
|
|
106
|
+
/** per fact name: the lookup arguments that may stay in clear under a private args rule (constants, or copies of call arguments the rule keeps in clear) */
|
|
107
|
+
clearFactArgs?: Record<string, string[]>;
|
|
108
|
+
/** per fact name: the lookup's full result, which the receipt's `resultDigest` then commits to; without it the digest the producer computed is withheld */
|
|
109
|
+
factResults?: Record<string, unknown>;
|
|
110
|
+
/** the tool name is not one any upstream offers, so it is text the agent chose: under a private rule the view shows "(unknown tool)" in its place, the rule having been selected by the real name */
|
|
111
|
+
unknownTool?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/** The view the issuer signs, and the salts behind its commitments by `pathKey`, which the issuer keeps and never signs. */
|
|
114
|
+
export interface PrivateView<P> {
|
|
115
|
+
predicate: P;
|
|
116
|
+
salts: Record<string, string>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The statement a receipt carries under a tool's rule: the predicate with every non-structural value withheld as the
|
|
120
|
+
* rule says, the three digests salted from the field salts, and the note of what is withheld at `capture`. Under a
|
|
121
|
+
* clear rule, the predicate itself and no salts. Applied by the issuer to every statement it signs, the authorization
|
|
122
|
+
* included; given the authorization's view as `prior`, the receipt's view carries the same request, facts, and policy,
|
|
123
|
+
* so that the receipt still names the authorization and nothing is withheld twice.
|
|
124
|
+
*/
|
|
125
|
+
export declare function privateView<P extends AuthorizationPredicate>(predicate: P, rule: CaptureRule | undefined, key?: Buffer, ctx?: CaptureContext, prior?: PrivateView<AuthorizationPredicate>): PrivateView<P>;
|
|
126
|
+
export type How = "disclosed" | "decrypted";
|
|
127
|
+
export interface Restoration<P> {
|
|
128
|
+
/** the predicate with every restorable path put back */
|
|
129
|
+
predicate: P;
|
|
130
|
+
/** how each restored path came back, by `pathKey` */
|
|
131
|
+
restored: Map<string, How>;
|
|
132
|
+
/** the salt of each restored path, by `pathKey`: what the digests over them are salted from */
|
|
133
|
+
salts: Map<string, string>;
|
|
134
|
+
/** the value of each restored path as it was committed, by `pathKey`; a `$rest` is folded into its parent in `predicate`, so this is where it stays whole */
|
|
135
|
+
values: Map<string, unknown>;
|
|
136
|
+
/** the withheld paths whose value could not be had */
|
|
137
|
+
missing: Path[];
|
|
138
|
+
/** paths where the note, the data, a disclosure, or the key contradict each other; each a reason a check must fail */
|
|
139
|
+
problems: {
|
|
140
|
+
path: Path;
|
|
141
|
+
error: string;
|
|
142
|
+
}[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The full statement behind a view, under its note: a path the note names must hold a commitment; the disclosure, when
|
|
146
|
+
* it carries that path as `{ $custody: "disclosed", salt, value }`, must match the commitment; else the key reveals
|
|
147
|
+
* what was encrypted under it; else the path stays withheld. A disclosure is a partial predicate with those at the
|
|
148
|
+
* withheld paths, as `agent-custody reveal` writes it. Nothing here throws: the problems are reported, so a verifier
|
|
149
|
+
* fails the right check.
|
|
150
|
+
*/
|
|
151
|
+
export declare function restorePaths<P>(predicate: P, note: CaptureNote | undefined, disclosed?: unknown, key?: Buffer): Restoration<P>;
|
|
152
|
+
/** The salt a digest over `prefix` was made with, once every withheld path under it is restored: see `digestSalt`. */
|
|
153
|
+
export declare function digestSaltFor<P>(r: Restoration<P>, note: CaptureNote | undefined, prefix: Path): string | undefined;
|