@predicatesystems/authority 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -26
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/verify/comparators.d.ts +52 -0
- package/dist/verify/comparators.d.ts.map +1 -0
- package/dist/verify/comparators.js +100 -0
- package/dist/verify/comparators.js.map +1 -0
- package/dist/verify/index.d.ts +34 -0
- package/dist/verify/index.d.ts.map +1 -0
- package/dist/verify/index.js +35 -0
- package/dist/verify/index.js.map +1 -0
- package/dist/verify/types.d.ts +290 -0
- package/dist/verify/types.d.ts.map +1 -0
- package/dist/verify/types.js +102 -0
- package/dist/verify/types.js.map +1 -0
- package/dist/verify/verifier.d.ts +102 -0
- package/dist/verify/verifier.d.ts.map +1 -0
- package/dist/verify/verifier.js +347 -0
- package/dist/verify/verifier.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for post-execution verification.
|
|
3
|
+
*
|
|
4
|
+
* These types support verifying that actual operations match
|
|
5
|
+
* what was authorized via a mandate.
|
|
6
|
+
*
|
|
7
|
+
* The verification system uses discriminated unions to support different
|
|
8
|
+
* evidence schemas based on the action domain:
|
|
9
|
+
*
|
|
10
|
+
* - `file`: File system operations with content hashes
|
|
11
|
+
* - `cli`: Terminal/shell operations with transcript evidence
|
|
12
|
+
* - `browser`: Web operations with DOM/A11y state
|
|
13
|
+
* - `http`: HTTP requests with response evidence
|
|
14
|
+
* - `db`: Database operations with query evidence
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Evidence type discriminator.
|
|
18
|
+
*/
|
|
19
|
+
export type EvidenceType = "file" | "cli" | "browser" | "http" | "db" | "generic";
|
|
20
|
+
/**
|
|
21
|
+
* Base interface for all evidence types.
|
|
22
|
+
*/
|
|
23
|
+
interface BaseEvidence {
|
|
24
|
+
/** Discriminator field for type narrowing */
|
|
25
|
+
type: EvidenceType;
|
|
26
|
+
/** The action that was actually performed (e.g., "fs.read", "cli.exec") */
|
|
27
|
+
action: string;
|
|
28
|
+
/** The resource that was accessed (path, URL, command, etc.) */
|
|
29
|
+
resource: string;
|
|
30
|
+
/** Timestamp when operation was executed (ISO 8601) */
|
|
31
|
+
executedAt?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Evidence for file system operations (fs.read, fs.write, etc.)
|
|
35
|
+
*/
|
|
36
|
+
export interface FileEvidence extends BaseEvidence {
|
|
37
|
+
type: "file";
|
|
38
|
+
/** Hash of file content (SHA-256) */
|
|
39
|
+
contentHash?: string;
|
|
40
|
+
/** File size in bytes */
|
|
41
|
+
fileSize?: number;
|
|
42
|
+
/** File permissions (octal string, e.g., "644") */
|
|
43
|
+
permissions?: string;
|
|
44
|
+
/** Last modified timestamp (ISO 8601) */
|
|
45
|
+
modifiedAt?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Evidence for terminal/CLI operations (cli.exec, cli.spawn, etc.)
|
|
49
|
+
*/
|
|
50
|
+
export interface CliEvidence extends BaseEvidence {
|
|
51
|
+
type: "cli";
|
|
52
|
+
/** The exact command that was executed */
|
|
53
|
+
command?: string;
|
|
54
|
+
/** Exit code of the process */
|
|
55
|
+
exitCode?: number;
|
|
56
|
+
/** Hash of stdout transcript */
|
|
57
|
+
stdoutHash?: string;
|
|
58
|
+
/** Hash of stderr transcript */
|
|
59
|
+
stderrHash?: string;
|
|
60
|
+
/** Combined transcript hash (stdout + stderr) */
|
|
61
|
+
transcriptHash?: string;
|
|
62
|
+
/** Working directory where command was executed */
|
|
63
|
+
cwd?: string;
|
|
64
|
+
/** Duration in milliseconds */
|
|
65
|
+
durationMs?: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Evidence for browser/web operations (browser.click, browser.navigate, etc.)
|
|
69
|
+
*/
|
|
70
|
+
export interface BrowserEvidence extends BaseEvidence {
|
|
71
|
+
type: "browser";
|
|
72
|
+
/** Final URL after navigation */
|
|
73
|
+
finalUrl?: string;
|
|
74
|
+
/** DOM selector that was interacted with */
|
|
75
|
+
selector?: string;
|
|
76
|
+
/** Hash of accessibility tree state */
|
|
77
|
+
a11yTreeHash?: string;
|
|
78
|
+
/** Hash of visible DOM state */
|
|
79
|
+
domStateHash?: string;
|
|
80
|
+
/** Screenshot hash (if captured) */
|
|
81
|
+
screenshotHash?: string;
|
|
82
|
+
/** Page title after operation */
|
|
83
|
+
pageTitle?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Evidence for HTTP operations (http.get, http.post, etc.)
|
|
87
|
+
*/
|
|
88
|
+
export interface HttpEvidence extends BaseEvidence {
|
|
89
|
+
type: "http";
|
|
90
|
+
/** HTTP method used */
|
|
91
|
+
method?: string;
|
|
92
|
+
/** Response status code */
|
|
93
|
+
statusCode?: number;
|
|
94
|
+
/** Hash of response body */
|
|
95
|
+
responseBodyHash?: string;
|
|
96
|
+
/** Response content type */
|
|
97
|
+
contentType?: string;
|
|
98
|
+
/** Response size in bytes */
|
|
99
|
+
responseSize?: number;
|
|
100
|
+
/** Request duration in milliseconds */
|
|
101
|
+
durationMs?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Evidence for database operations (db.query, db.insert, etc.)
|
|
105
|
+
*/
|
|
106
|
+
export interface DbEvidence extends BaseEvidence {
|
|
107
|
+
type: "db";
|
|
108
|
+
/** Hash of query/statement */
|
|
109
|
+
queryHash?: string;
|
|
110
|
+
/** Number of rows affected */
|
|
111
|
+
rowsAffected?: number;
|
|
112
|
+
/** Hash of result set (for queries) */
|
|
113
|
+
resultHash?: string;
|
|
114
|
+
/** Query duration in milliseconds */
|
|
115
|
+
durationMs?: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Generic evidence for unknown or custom action types.
|
|
119
|
+
*/
|
|
120
|
+
export interface GenericEvidence extends BaseEvidence {
|
|
121
|
+
type: "generic";
|
|
122
|
+
/** Arbitrary evidence hash */
|
|
123
|
+
evidenceHash?: string;
|
|
124
|
+
/** Additional metadata */
|
|
125
|
+
metadata?: Record<string, unknown>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Discriminated union of all evidence types.
|
|
129
|
+
*
|
|
130
|
+
* Use the `type` field to narrow to a specific evidence type:
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* function processEvidence(evidence: ExecutionEvidence) {
|
|
135
|
+
* switch (evidence.type) {
|
|
136
|
+
* case "file":
|
|
137
|
+
* console.log("File hash:", evidence.contentHash);
|
|
138
|
+
* break;
|
|
139
|
+
* case "cli":
|
|
140
|
+
* console.log("Exit code:", evidence.exitCode);
|
|
141
|
+
* break;
|
|
142
|
+
* case "browser":
|
|
143
|
+
* console.log("Final URL:", evidence.finalUrl);
|
|
144
|
+
* break;
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export type ExecutionEvidence = FileEvidence | CliEvidence | BrowserEvidence | HttpEvidence | DbEvidence | GenericEvidence;
|
|
150
|
+
/**
|
|
151
|
+
* Extract the domain from an action string.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* getActionDomain("fs.read") // => "file"
|
|
155
|
+
* getActionDomain("cli.exec") // => "cli"
|
|
156
|
+
* getActionDomain("browser.click") // => "browser"
|
|
157
|
+
* getActionDomain("custom.action") // => "generic"
|
|
158
|
+
*/
|
|
159
|
+
export declare function getEvidenceType(action: string): EvidenceType;
|
|
160
|
+
/**
|
|
161
|
+
* Type guard for FileEvidence.
|
|
162
|
+
*/
|
|
163
|
+
export declare function isFileEvidence(evidence: ExecutionEvidence): evidence is FileEvidence;
|
|
164
|
+
/**
|
|
165
|
+
* Type guard for CliEvidence.
|
|
166
|
+
*/
|
|
167
|
+
export declare function isCliEvidence(evidence: ExecutionEvidence): evidence is CliEvidence;
|
|
168
|
+
/**
|
|
169
|
+
* Type guard for BrowserEvidence.
|
|
170
|
+
*/
|
|
171
|
+
export declare function isBrowserEvidence(evidence: ExecutionEvidence): evidence is BrowserEvidence;
|
|
172
|
+
/**
|
|
173
|
+
* Type guard for HttpEvidence.
|
|
174
|
+
*/
|
|
175
|
+
export declare function isHttpEvidence(evidence: ExecutionEvidence): evidence is HttpEvidence;
|
|
176
|
+
/**
|
|
177
|
+
* Type guard for DbEvidence.
|
|
178
|
+
*/
|
|
179
|
+
export declare function isDbEvidence(evidence: ExecutionEvidence): evidence is DbEvidence;
|
|
180
|
+
/**
|
|
181
|
+
* Reason codes for verification failure.
|
|
182
|
+
*/
|
|
183
|
+
export type VerificationFailureReason = "resource_mismatch" | "action_mismatch" | "mandate_expired" | "mandate_not_found" | "evidence_mismatch";
|
|
184
|
+
/**
|
|
185
|
+
* Details about an authorized operation from a mandate.
|
|
186
|
+
*/
|
|
187
|
+
export interface AuthorizedOperation {
|
|
188
|
+
action: string;
|
|
189
|
+
resource: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Legacy ActualOperation interface for backward compatibility.
|
|
193
|
+
*
|
|
194
|
+
* @deprecated Use ExecutionEvidence discriminated union instead.
|
|
195
|
+
*/
|
|
196
|
+
export interface ActualOperation {
|
|
197
|
+
/** The action that was actually performed */
|
|
198
|
+
action: string;
|
|
199
|
+
/** The resource that was actually accessed */
|
|
200
|
+
resource: string;
|
|
201
|
+
/** Timestamp when operation was executed (ISO 8601) */
|
|
202
|
+
executedAt?: string;
|
|
203
|
+
/** @deprecated Use FileEvidence.contentHash instead */
|
|
204
|
+
contentHash?: string;
|
|
205
|
+
/** @deprecated Use CliEvidence.transcriptHash instead */
|
|
206
|
+
transcriptHash?: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Request to verify an operation against its mandate.
|
|
210
|
+
*
|
|
211
|
+
* Supports both the legacy ActualOperation format and the new
|
|
212
|
+
* discriminated union ExecutionEvidence format.
|
|
213
|
+
*/
|
|
214
|
+
export interface VerifyRequest {
|
|
215
|
+
/** Mandate ID from the authorization decision */
|
|
216
|
+
mandateId: string;
|
|
217
|
+
/**
|
|
218
|
+
* The actual operation that was performed.
|
|
219
|
+
*
|
|
220
|
+
* Can be either:
|
|
221
|
+
* - ExecutionEvidence (discriminated union with `type` field) - recommended
|
|
222
|
+
* - ActualOperation (legacy format without `type` field) - deprecated
|
|
223
|
+
*/
|
|
224
|
+
actual: ExecutionEvidence | ActualOperation;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Result of verification.
|
|
228
|
+
*/
|
|
229
|
+
export interface VerifyResult {
|
|
230
|
+
/** Whether the operation matched the authorization */
|
|
231
|
+
verified: boolean;
|
|
232
|
+
/** Reason for verification failure (if verified is false) */
|
|
233
|
+
reason?: VerificationFailureReason;
|
|
234
|
+
/** Details about the mismatch (if verification failed) */
|
|
235
|
+
details?: {
|
|
236
|
+
authorized: AuthorizedOperation;
|
|
237
|
+
actual: ExecutionEvidence | ActualOperation;
|
|
238
|
+
};
|
|
239
|
+
/** Audit trail ID from the sidecar (if verification succeeded) */
|
|
240
|
+
auditId?: string;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Mandate details retrieved from the sidecar.
|
|
244
|
+
*/
|
|
245
|
+
export interface MandateDetails {
|
|
246
|
+
/** Unique mandate identifier */
|
|
247
|
+
mandate_id: string;
|
|
248
|
+
/** Principal that was granted authorization */
|
|
249
|
+
principal: string;
|
|
250
|
+
/** Action that was authorized */
|
|
251
|
+
action: string;
|
|
252
|
+
/** Resource that was authorized */
|
|
253
|
+
resource: string;
|
|
254
|
+
/** Hash of the stated intent */
|
|
255
|
+
intent_hash: string;
|
|
256
|
+
/** When the mandate was issued (ISO 8601) */
|
|
257
|
+
issued_at: string;
|
|
258
|
+
/** When the mandate expires (ISO 8601) */
|
|
259
|
+
expires_at: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Type guard for MandateDetails.
|
|
263
|
+
*/
|
|
264
|
+
export declare function isMandateDetails(value: unknown): value is MandateDetails;
|
|
265
|
+
/**
|
|
266
|
+
* Request to record a verification in the audit log.
|
|
267
|
+
*/
|
|
268
|
+
export interface RecordVerificationRequest {
|
|
269
|
+
/** Mandate ID that was verified */
|
|
270
|
+
mandateId: string;
|
|
271
|
+
/** Whether verification succeeded */
|
|
272
|
+
verified: boolean;
|
|
273
|
+
/** The actual operation details */
|
|
274
|
+
actual: ExecutionEvidence | ActualOperation;
|
|
275
|
+
/** Reason for failure (if verified is false) */
|
|
276
|
+
reason?: VerificationFailureReason;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Response from recording a verification.
|
|
280
|
+
*/
|
|
281
|
+
export interface RecordVerificationResponse {
|
|
282
|
+
/** Audit trail ID */
|
|
283
|
+
audit_id: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Type guard for RecordVerificationResponse.
|
|
287
|
+
*/
|
|
288
|
+
export declare function isRecordVerificationResponse(value: unknown): value is RecordVerificationResponse;
|
|
289
|
+
export {};
|
|
290
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/verify/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAElF;;GAEG;AACH,UAAU,YAAY;IACpB,6CAA6C;IAC7C,IAAI,EAAE,YAAY,CAAC;IAEnB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IAEf,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IAEjB,uDAAuD;IACvD,UAAU,CAAC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E;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IAEnB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAElB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IAEf,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IAEjB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IAEpB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAElB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAcxE;AAMD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAElB,qCAAqC;IACrC,QAAQ,EAAE,OAAO,CAAC;IAElB,mCAAmC;IACnC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAE5C,gDAAgD;IAChD,MAAM,CAAC,EAAE,yBAAyB,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,0BAA0B,CAMrC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for post-execution verification.
|
|
3
|
+
*
|
|
4
|
+
* These types support verifying that actual operations match
|
|
5
|
+
* what was authorized via a mandate.
|
|
6
|
+
*
|
|
7
|
+
* The verification system uses discriminated unions to support different
|
|
8
|
+
* evidence schemas based on the action domain:
|
|
9
|
+
*
|
|
10
|
+
* - `file`: File system operations with content hashes
|
|
11
|
+
* - `cli`: Terminal/shell operations with transcript evidence
|
|
12
|
+
* - `browser`: Web operations with DOM/A11y state
|
|
13
|
+
* - `http`: HTTP requests with response evidence
|
|
14
|
+
* - `db`: Database operations with query evidence
|
|
15
|
+
*/
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// Helper Functions
|
|
18
|
+
// =============================================================================
|
|
19
|
+
/**
|
|
20
|
+
* Extract the domain from an action string.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* getActionDomain("fs.read") // => "file"
|
|
24
|
+
* getActionDomain("cli.exec") // => "cli"
|
|
25
|
+
* getActionDomain("browser.click") // => "browser"
|
|
26
|
+
* getActionDomain("custom.action") // => "generic"
|
|
27
|
+
*/
|
|
28
|
+
export function getEvidenceType(action) {
|
|
29
|
+
const prefix = action.split(".")[0];
|
|
30
|
+
const domainMap = {
|
|
31
|
+
fs: "file",
|
|
32
|
+
file: "file",
|
|
33
|
+
cli: "cli",
|
|
34
|
+
shell: "cli",
|
|
35
|
+
terminal: "cli",
|
|
36
|
+
browser: "browser",
|
|
37
|
+
web: "browser",
|
|
38
|
+
http: "http",
|
|
39
|
+
https: "http",
|
|
40
|
+
db: "db",
|
|
41
|
+
database: "db",
|
|
42
|
+
sql: "db",
|
|
43
|
+
};
|
|
44
|
+
return domainMap[prefix] ?? "generic";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Type guard for FileEvidence.
|
|
48
|
+
*/
|
|
49
|
+
export function isFileEvidence(evidence) {
|
|
50
|
+
return evidence.type === "file";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type guard for CliEvidence.
|
|
54
|
+
*/
|
|
55
|
+
export function isCliEvidence(evidence) {
|
|
56
|
+
return evidence.type === "cli";
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type guard for BrowserEvidence.
|
|
60
|
+
*/
|
|
61
|
+
export function isBrowserEvidence(evidence) {
|
|
62
|
+
return evidence.type === "browser";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Type guard for HttpEvidence.
|
|
66
|
+
*/
|
|
67
|
+
export function isHttpEvidence(evidence) {
|
|
68
|
+
return evidence.type === "http";
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Type guard for DbEvidence.
|
|
72
|
+
*/
|
|
73
|
+
export function isDbEvidence(evidence) {
|
|
74
|
+
return evidence.type === "db";
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Type guard for MandateDetails.
|
|
78
|
+
*/
|
|
79
|
+
export function isMandateDetails(value) {
|
|
80
|
+
if (typeof value !== "object" || value === null) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const obj = value;
|
|
84
|
+
return (typeof obj.mandate_id === "string" &&
|
|
85
|
+
typeof obj.principal === "string" &&
|
|
86
|
+
typeof obj.action === "string" &&
|
|
87
|
+
typeof obj.resource === "string" &&
|
|
88
|
+
typeof obj.intent_hash === "string" &&
|
|
89
|
+
typeof obj.issued_at === "string" &&
|
|
90
|
+
typeof obj.expires_at === "string");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Type guard for RecordVerificationResponse.
|
|
94
|
+
*/
|
|
95
|
+
export function isRecordVerificationResponse(value) {
|
|
96
|
+
if (typeof value !== "object" || value === null) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const obj = value;
|
|
100
|
+
return typeof obj.audit_id === "string";
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/verify/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2LH,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,MAA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O,GAAG,CAAC,MAAM,KAAK,QAAQ;QAC9B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ;QAChC,OAAO,GAAG,CAAC,WAAW,KAAK,QAAQ;QACnC,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ;QACjC,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,CACnC,CAAC;AACJ,CAAC;AA+BD;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-execution verification module.
|
|
3
|
+
*
|
|
4
|
+
* The Verifier class compares actual operations against what was
|
|
5
|
+
* authorized via a mandate, detecting unauthorized deviations.
|
|
6
|
+
*/
|
|
7
|
+
import { type MandateDetails, type RecordVerificationRequest, type VerifyRequest, type VerifyResult } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for mandate retrieval.
|
|
10
|
+
*
|
|
11
|
+
* Can be implemented by AuthorityClient or a custom provider.
|
|
12
|
+
*/
|
|
13
|
+
export interface MandateProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Retrieve mandate details by ID.
|
|
16
|
+
* @param mandateId - The mandate ID to look up
|
|
17
|
+
* @returns Mandate details or null if not found
|
|
18
|
+
*/
|
|
19
|
+
getMandate(mandateId: string): Promise<MandateDetails | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Record a verification result in the audit log.
|
|
22
|
+
* @param request - Verification details to record
|
|
23
|
+
* @returns Audit trail ID
|
|
24
|
+
*/
|
|
25
|
+
recordVerification(request: RecordVerificationRequest): Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for creating a Verifier.
|
|
29
|
+
*/
|
|
30
|
+
export interface VerifierOptions {
|
|
31
|
+
/** Base URL of the sidecar */
|
|
32
|
+
baseUrl: string;
|
|
33
|
+
/** Request timeout in milliseconds */
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Verifier for post-execution authorization checks.
|
|
38
|
+
*
|
|
39
|
+
* Compares actual operations against mandates to detect unauthorized
|
|
40
|
+
* deviations from what was authorized.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const verifier = new Verifier({ baseUrl: 'http://127.0.0.1:8787' });
|
|
45
|
+
*
|
|
46
|
+
* const result = await verifier.verify({
|
|
47
|
+
* mandateId: decision.mandate_id,
|
|
48
|
+
* actual: {
|
|
49
|
+
* action: 'fs.read',
|
|
50
|
+
* resource: '/src/index.ts',
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* if (!result.verified) {
|
|
55
|
+
* console.error('Operation mismatch:', result.reason);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare class Verifier implements MandateProvider {
|
|
60
|
+
private readonly baseUrl;
|
|
61
|
+
private readonly timeoutMs;
|
|
62
|
+
constructor(options: VerifierOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Verify that an actual operation matches its mandate.
|
|
65
|
+
*
|
|
66
|
+
* @param request - Verification request with mandate ID and actual operation
|
|
67
|
+
* @returns Verification result
|
|
68
|
+
*/
|
|
69
|
+
verify(request: VerifyRequest): Promise<VerifyResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Verify an operation locally without sidecar communication.
|
|
72
|
+
*
|
|
73
|
+
* Use this when the sidecar endpoints are not available yet (Phase 2).
|
|
74
|
+
* This performs the same matching logic but skips mandate retrieval
|
|
75
|
+
* and audit logging.
|
|
76
|
+
*
|
|
77
|
+
* @param mandate - Known mandate details
|
|
78
|
+
* @param request - Verification request
|
|
79
|
+
* @returns Verification result (without auditId)
|
|
80
|
+
*/
|
|
81
|
+
verifyLocal(mandate: MandateDetails, request: VerifyRequest): VerifyResult;
|
|
82
|
+
/**
|
|
83
|
+
* Retrieve mandate details from the sidecar.
|
|
84
|
+
*
|
|
85
|
+
* @param mandateId - Mandate ID to look up
|
|
86
|
+
* @returns Mandate details or null if not found
|
|
87
|
+
*/
|
|
88
|
+
getMandate(mandateId: string): Promise<MandateDetails | null>;
|
|
89
|
+
/**
|
|
90
|
+
* Record a verification result in the sidecar's audit log.
|
|
91
|
+
*
|
|
92
|
+
* @param request - Verification details to record
|
|
93
|
+
* @returns Audit trail ID
|
|
94
|
+
*/
|
|
95
|
+
recordVerification(request: RecordVerificationRequest): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Build the actual operation payload for the verification request.
|
|
98
|
+
* Handles the discriminated union by extracting type-specific fields.
|
|
99
|
+
*/
|
|
100
|
+
private buildActualPayload;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../../src/verify/verifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,YAAY,EAQlB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAE9D;;;;OAIG;IACH,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACzE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,8BAA8B;IAC9B,OAAO,EAAE,MAAM,C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