@odingard/guardian-sdk 0.0.0-stage → 0.2.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.
Files changed (58) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +302 -2
  3. package/dist/contracts.js +9865 -0
  4. package/dist/index.js +14437 -0
  5. package/dist/public-catalog.v1.json +6915 -0
  6. package/dist-dts/catalog.d.ts +14 -0
  7. package/dist-dts/client.d.ts +130 -0
  8. package/dist-dts/contracts/action-pack.d.ts +464 -0
  9. package/dist-dts/contracts/action-parameters.d.ts +34 -0
  10. package/dist-dts/contracts/action-registry.d.ts +287 -0
  11. package/dist-dts/contracts/action.d.ts +2358 -0
  12. package/dist-dts/contracts/agent-state.d.ts +386 -0
  13. package/dist-dts/contracts/api.d.ts +78 -0
  14. package/dist-dts/contracts/approval.d.ts +425 -0
  15. package/dist-dts/contracts/assurance.d.ts +60 -0
  16. package/dist-dts/contracts/authority-graph.d.ts +294 -0
  17. package/dist-dts/contracts/authority-state.d.ts +108 -0
  18. package/dist-dts/contracts/authority.d.ts +339 -0
  19. package/dist-dts/contracts/billing.d.ts +32 -0
  20. package/dist-dts/contracts/calendar.d.ts +146 -0
  21. package/dist-dts/contracts/canonical-json.d.ts +4 -0
  22. package/dist-dts/contracts/capability.d.ts +28 -0
  23. package/dist-dts/contracts/commerce.d.ts +133 -0
  24. package/dist-dts/contracts/denial.d.ts +648 -0
  25. package/dist-dts/contracts/digest.d.ts +2 -0
  26. package/dist-dts/contracts/email.d.ts +45 -0
  27. package/dist-dts/contracts/evidence.d.ts +1087 -0
  28. package/dist-dts/contracts/execution.d.ts +1732 -0
  29. package/dist-dts/contracts/files.d.ts +61 -0
  30. package/dist-dts/contracts/identifiers.d.ts +49 -0
  31. package/dist-dts/contracts/index.d.ts +41 -0
  32. package/dist-dts/contracts/intent.d.ts +335 -0
  33. package/dist-dts/contracts/lineage.d.ts +218 -0
  34. package/dist-dts/contracts/local.d.ts +101 -0
  35. package/dist-dts/contracts/multi-principal.d.ts +292 -0
  36. package/dist-dts/contracts/multiparty.d.ts +169 -0
  37. package/dist-dts/contracts/obligation.d.ts +196 -0
  38. package/dist-dts/contracts/plan.d.ts +67 -0
  39. package/dist-dts/contracts/policy-simulation.d.ts +681 -0
  40. package/dist-dts/contracts/prerequisite.d.ts +147 -0
  41. package/dist-dts/contracts/protected-data.d.ts +160 -0
  42. package/dist-dts/contracts/receipt.d.ts +3126 -0
  43. package/dist-dts/contracts/resource-claims.d.ts +146 -0
  44. package/dist-dts/contracts/runtime.d.ts +111 -0
  45. package/dist-dts/contracts/safety-envelope.d.ts +287 -0
  46. package/dist-dts/contracts/sequence.d.ts +132 -0
  47. package/dist-dts/contracts/sources.d.ts +191 -0
  48. package/dist-dts/contracts/tools.d.ts +232 -0
  49. package/dist-dts/contracts/transaction.d.ts +360 -0
  50. package/dist-dts/contracts-entry.d.ts +1 -0
  51. package/dist-dts/embedded.d.ts +58 -0
  52. package/dist-dts/evidence/evidence.d.ts +25 -0
  53. package/dist-dts/evidence/receipt.d.ts +61 -0
  54. package/dist-dts/index.d.ts +5 -0
  55. package/dist-dts/lifecycle.d.ts +25 -0
  56. package/dist-dts/proposal.d.ts +41 -0
  57. package/dist-dts/receipts.d.ts +37 -0
  58. package/package.json +56 -4
@@ -0,0 +1,360 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * WO-028: guardian.transaction.v1 — deterministic transaction authority
4
+ * (GUA-AUTHORITY-OS-001 §34–37, §79, §81).
5
+ *
6
+ * A transaction is the recorded lifecycle of one consequential action:
7
+ * PROPOSE → PREPARE → AUTHORIZE → LOCK → COMMIT → VERIFY → SETTLE, entered
8
+ * only when the action or its governing intent declares it. Every stage is
9
+ * a recorded transition bound to the canonical action digest; a skipped or
10
+ * out-of-order stage fails closed.
11
+ *
12
+ * The evaluator in this file is pure and deterministic. It never enlarges
13
+ * authority: it records what the authority path already decided, and a
14
+ * compensating action is a NEW governed action through the same
15
+ * ALLOW/ASK/DENY path — compensation never bypasses ASK. A transaction
16
+ * whose provider outcome is unconfirmed records UNKNOWN or MISMATCH; an
17
+ * unconfirmed effect is never reported SETTLED.
18
+ */
19
+ export declare const TRANSACTION_CONTRACT_SCHEMA = "guardian.transaction.v1";
20
+ export declare const TransactionStageSchema: z.ZodEnum<{
21
+ PROPOSE: "PROPOSE";
22
+ PREPARE: "PREPARE";
23
+ AUTHORIZE: "AUTHORIZE";
24
+ LOCK: "LOCK";
25
+ COMMIT: "COMMIT";
26
+ VERIFY: "VERIFY";
27
+ SETTLE: "SETTLE";
28
+ }>;
29
+ export type TransactionStage = z.infer<typeof TransactionStageSchema>;
30
+ /** The one canonical stage order (§34). */
31
+ export declare const CANONICAL_TRANSACTION_STAGES: readonly TransactionStage[];
32
+ export declare const TransactionStateSchema: z.ZodEnum<{
33
+ AUTHORIZED: "AUTHORIZED";
34
+ PROPOSED: "PROPOSED";
35
+ PREPARED: "PREPARED";
36
+ LOCKED: "LOCKED";
37
+ COMMITTING: "COMMITTING";
38
+ COMMITTED: "COMMITTED";
39
+ VERIFIED: "VERIFIED";
40
+ SETTLED: "SETTLED";
41
+ DENIED: "DENIED";
42
+ EXPIRED: "EXPIRED";
43
+ REVOKED: "REVOKED";
44
+ UNKNOWN: "UNKNOWN";
45
+ MISMATCH: "MISMATCH";
46
+ FAILED: "FAILED";
47
+ CANCELLED: "CANCELLED";
48
+ COMPENSATING: "COMPENSATING";
49
+ COMPENSATED: "COMPENSATED";
50
+ }>;
51
+ export type TransactionState = z.infer<typeof TransactionStateSchema>;
52
+ /** States from which the transaction can never move again. */
53
+ export declare const TERMINAL_TRANSACTION_STATES: readonly TransactionState[];
54
+ export declare function isTerminalTransactionState(state: TransactionState): boolean;
55
+ /**
56
+ * The declared lifecycle of a transaction: a strictly-increasing
57
+ * subsequence of the canonical stage order that must contain PROPOSE.
58
+ * Declared on the action definition and/or the governing intent; the
59
+ * effective declaration is the union in canonical order — declaration
60
+ * only ever adds recorded obligations, it cannot remove a stage the
61
+ * other declaration required.
62
+ */
63
+ export declare const TransactionDeclarationSchema: z.ZodObject<{
64
+ schema: z.ZodLiteral<"guardian.transaction.v1">;
65
+ stages: z.ZodArray<z.ZodEnum<{
66
+ PROPOSE: "PROPOSE";
67
+ PREPARE: "PREPARE";
68
+ AUTHORIZE: "AUTHORIZE";
69
+ LOCK: "LOCK";
70
+ COMMIT: "COMMIT";
71
+ VERIFY: "VERIFY";
72
+ SETTLE: "SETTLE";
73
+ }>>;
74
+ deadlineMs: z.ZodOptional<z.ZodNumber>;
75
+ }, z.core.$strict>;
76
+ export type TransactionDeclaration = z.infer<typeof TransactionDeclarationSchema>;
77
+ export declare function transactionDeclarationDigest(declaration: TransactionDeclaration): string;
78
+ /**
79
+ * Union of two declared lifecycles in canonical order (declaration only
80
+ * ever enlarges the recorded obligation set, never shrinks it). The
81
+ * tighter deadline wins. Returns undefined when neither declares.
82
+ */
83
+ export declare function effectiveTransactionDeclaration(declaredA: TransactionDeclaration | undefined, declaredB: TransactionDeclaration | undefined): TransactionDeclaration | undefined;
84
+ /**
85
+ * Every consequential adapter declares its idempotency posture. The
86
+ * declaration is data on the adapter record — it is required, never
87
+ * inferred. A retry always binds to the recorded execution attempt's
88
+ * idempotency key (the effect key); a retry can never carry a fresh key
89
+ * that would silently produce a second effect.
90
+ */
91
+ export declare const AdapterIdempotencyDeclarationSchema: z.ZodObject<{
92
+ support: z.ZodEnum<{
93
+ none: "none";
94
+ keyed: "keyed";
95
+ "provider-native": "provider-native";
96
+ }>;
97
+ duplicateEffect: z.ZodEnum<{
98
+ "return-existing": "return-existing";
99
+ reject: "reject";
100
+ unsafe: "unsafe";
101
+ }>;
102
+ retry: z.ZodEnum<{
103
+ "same-attempt-key": "same-attempt-key";
104
+ "fresh-authority": "fresh-authority";
105
+ }>;
106
+ reconciliation: z.ZodEnum<{
107
+ none: "none";
108
+ readback: "readback";
109
+ callback: "callback";
110
+ manual: "manual";
111
+ }>;
112
+ }, z.core.$strict>;
113
+ export type AdapterIdempotencyDeclaration = z.infer<typeof AdapterIdempotencyDeclarationSchema>;
114
+ /**
115
+ * Bound into the canonical action of a compensating action: which
116
+ * recorded transaction this action compensates. The action still goes
117
+ * through the full authority path — this binding only declares the
118
+ * relationship.
119
+ */
120
+ export declare const TransactionCompensationBindingSchema: z.ZodObject<{
121
+ transactionId: z.core.$ZodBranded<z.ZodString, "TransactionId", "out">;
122
+ }, z.core.$strict>;
123
+ export type TransactionCompensationBinding = z.infer<typeof TransactionCompensationBindingSchema>;
124
+ export declare const TransactionStageRecordSchema: z.ZodObject<{
125
+ stage: z.ZodEnum<{
126
+ PROPOSE: "PROPOSE";
127
+ PREPARE: "PREPARE";
128
+ AUTHORIZE: "AUTHORIZE";
129
+ LOCK: "LOCK";
130
+ COMMIT: "COMMIT";
131
+ VERIFY: "VERIFY";
132
+ SETTLE: "SETTLE";
133
+ }>;
134
+ atEpochMs: z.ZodNumber;
135
+ binding: z.ZodNullable<z.ZodString>;
136
+ }, z.core.$strict>;
137
+ export type TransactionStageRecord = z.infer<typeof TransactionStageRecordSchema>;
138
+ /** How a revocation mid-transaction resolves (§81). */
139
+ export declare const TransactionResolutionSchema: z.ZodEnum<{
140
+ cancel: "cancel";
141
+ settle: "settle";
142
+ hold: "hold";
143
+ }>;
144
+ export type TransactionResolution = z.infer<typeof TransactionResolutionSchema>;
145
+ export declare const TransactionRecordSchema: z.ZodObject<{
146
+ schemaVersion: z.ZodLiteral<1>;
147
+ schema: z.ZodLiteral<"guardian.transaction.v1">;
148
+ transactionId: z.core.$ZodBranded<z.ZodString, "TransactionId", "out">;
149
+ tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
150
+ principalId: z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">;
151
+ agentId: z.core.$ZodBranded<z.ZodString, "AgentId", "out">;
152
+ requestId: z.core.$ZodBranded<z.ZodString, "RequestId", "out">;
153
+ correlationId: z.core.$ZodBranded<z.ZodString, "CorrelationId", "out">;
154
+ action: z.core.$ZodBranded<z.ZodString, "ActionType", "out">;
155
+ actionDigest: z.ZodString;
156
+ declaration: z.ZodObject<{
157
+ schema: z.ZodLiteral<"guardian.transaction.v1">;
158
+ stages: z.ZodArray<z.ZodEnum<{
159
+ PROPOSE: "PROPOSE";
160
+ PREPARE: "PREPARE";
161
+ AUTHORIZE: "AUTHORIZE";
162
+ LOCK: "LOCK";
163
+ COMMIT: "COMMIT";
164
+ VERIFY: "VERIFY";
165
+ SETTLE: "SETTLE";
166
+ }>>;
167
+ deadlineMs: z.ZodOptional<z.ZodNumber>;
168
+ }, z.core.$strict>;
169
+ declarationDigest: z.ZodString;
170
+ recordedStages: z.ZodArray<z.ZodObject<{
171
+ stage: z.ZodEnum<{
172
+ PROPOSE: "PROPOSE";
173
+ PREPARE: "PREPARE";
174
+ AUTHORIZE: "AUTHORIZE";
175
+ LOCK: "LOCK";
176
+ COMMIT: "COMMIT";
177
+ VERIFY: "VERIFY";
178
+ SETTLE: "SETTLE";
179
+ }>;
180
+ atEpochMs: z.ZodNumber;
181
+ binding: z.ZodNullable<z.ZodString>;
182
+ }, z.core.$strict>>;
183
+ state: z.ZodEnum<{
184
+ AUTHORIZED: "AUTHORIZED";
185
+ PROPOSED: "PROPOSED";
186
+ PREPARED: "PREPARED";
187
+ LOCKED: "LOCKED";
188
+ COMMITTING: "COMMITTING";
189
+ COMMITTED: "COMMITTED";
190
+ VERIFIED: "VERIFIED";
191
+ SETTLED: "SETTLED";
192
+ DENIED: "DENIED";
193
+ EXPIRED: "EXPIRED";
194
+ REVOKED: "REVOKED";
195
+ UNKNOWN: "UNKNOWN";
196
+ MISMATCH: "MISMATCH";
197
+ FAILED: "FAILED";
198
+ CANCELLED: "CANCELLED";
199
+ COMPENSATING: "COMPENSATING";
200
+ COMPENSATED: "COMPENSATED";
201
+ }>;
202
+ resolution: z.ZodNullable<z.ZodEnum<{
203
+ cancel: "cancel";
204
+ settle: "settle";
205
+ hold: "hold";
206
+ }>>;
207
+ attemptId: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "AttemptId", "out">>;
208
+ capabilityId: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "CapabilityId", "out">>;
209
+ idempotencyKey: z.ZodNullable<z.ZodString>;
210
+ compensationOf: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "TransactionId", "out">>;
211
+ compensationBy: z.ZodNullable<z.core.$ZodBranded<z.ZodString, "TransactionId", "out">>;
212
+ terminalReason: z.ZodNullable<z.ZodString>;
213
+ expiresAtEpochMs: z.ZodNullable<z.ZodNumber>;
214
+ version: z.ZodNumber;
215
+ createdAtEpochMs: z.ZodNumber;
216
+ updatedAtEpochMs: z.ZodNumber;
217
+ }, z.core.$strict>;
218
+ export type TransactionRecord = z.infer<typeof TransactionRecordSchema>;
219
+ /** Deterministic transaction id: one transaction per request. */
220
+ export declare function transactionIdForRequest(requestId: string): string;
221
+ /**
222
+ * §36 — whether a transaction's effect may be compensated: a landed (or
223
+ * possibly-landed) effect only; pre-commit states cancel instead.
224
+ */
225
+ export declare function isCompensatableTransaction(record: TransactionRecord): boolean;
226
+ export declare const TransactionCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
227
+ expectedVersion: z.ZodNumber;
228
+ kind: z.ZodLiteral<"record-stage">;
229
+ stage: z.ZodEnum<{
230
+ PROPOSE: "PROPOSE";
231
+ PREPARE: "PREPARE";
232
+ AUTHORIZE: "AUTHORIZE";
233
+ LOCK: "LOCK";
234
+ COMMIT: "COMMIT";
235
+ VERIFY: "VERIFY";
236
+ SETTLE: "SETTLE";
237
+ }>;
238
+ binding: z.ZodNullable<z.ZodString>;
239
+ }, z.core.$strict>, z.ZodObject<{
240
+ expectedVersion: z.ZodNumber;
241
+ kind: z.ZodLiteral<"deny">;
242
+ reason: z.ZodString;
243
+ }, z.core.$strict>, z.ZodObject<{
244
+ expectedVersion: z.ZodNumber;
245
+ kind: z.ZodLiteral<"cancel">;
246
+ reason: z.ZodString;
247
+ }, z.core.$strict>, z.ZodObject<{
248
+ expectedVersion: z.ZodNumber;
249
+ kind: z.ZodLiteral<"expire">;
250
+ reason: z.ZodString;
251
+ }, z.core.$strict>, z.ZodObject<{
252
+ expectedVersion: z.ZodNumber;
253
+ kind: z.ZodLiteral<"revoke">;
254
+ reason: z.ZodString;
255
+ }, z.core.$strict>, z.ZodObject<{
256
+ expectedVersion: z.ZodNumber;
257
+ kind: z.ZodLiteral<"fail">;
258
+ reason: z.ZodString;
259
+ }, z.core.$strict>, z.ZodObject<{
260
+ expectedVersion: z.ZodNumber;
261
+ kind: z.ZodLiteral<"bind-attempt">;
262
+ attemptId: z.core.$ZodBranded<z.ZodString, "AttemptId", "out">;
263
+ capabilityId: z.core.$ZodBranded<z.ZodString, "CapabilityId", "out">;
264
+ idempotencyKey: z.ZodString;
265
+ }, z.core.$strict>, z.ZodObject<{
266
+ expectedVersion: z.ZodNumber;
267
+ kind: z.ZodLiteral<"commit-confirmed">;
268
+ binding: z.ZodNullable<z.ZodString>;
269
+ }, z.core.$strict>, z.ZodObject<{
270
+ expectedVersion: z.ZodNumber;
271
+ kind: z.ZodLiteral<"outcome">;
272
+ outcome: z.ZodEnum<{
273
+ unknown: "unknown";
274
+ verified: "verified";
275
+ mismatch: "mismatch";
276
+ "commit-rejected": "commit-rejected";
277
+ aborted: "aborted";
278
+ }>;
279
+ binding: z.ZodNullable<z.ZodString>;
280
+ }, z.core.$strict>, z.ZodObject<{
281
+ expectedVersion: z.ZodNumber;
282
+ kind: z.ZodLiteral<"compensate">;
283
+ compensationTransactionId: z.core.$ZodBranded<z.ZodString, "TransactionId", "out">;
284
+ }, z.core.$strict>, z.ZodObject<{
285
+ expectedVersion: z.ZodNumber;
286
+ kind: z.ZodLiteral<"compensated">;
287
+ }, z.core.$strict>], "kind">;
288
+ export type TransactionCommand = z.infer<typeof TransactionCommandSchema>;
289
+ /** A transaction command without its optimistic-concurrency version. */
290
+ export type TransactionCommandInput = {
291
+ [K in TransactionCommand["kind"]]: Omit<Extract<TransactionCommand, {
292
+ kind: K;
293
+ }>, "expectedVersion">;
294
+ }[TransactionCommand["kind"]];
295
+ export type TransactionTransitionResult = Readonly<{
296
+ ok: true;
297
+ record: TransactionRecord;
298
+ }> | Readonly<{
299
+ ok: false;
300
+ reasonCode: "MALFORMED_RECORD" | "MALFORMED_COMMAND" | "STALE_VERSION" | "TRANSACTION_EXPIRED" | "SKIPPED_STAGE" | "INVALID_TRANSITION";
301
+ }>;
302
+ /** The next declared stage not yet recorded, or null. */
303
+ export declare function nextDeclaredTransactionStage(record: TransactionRecord): TransactionStage | null;
304
+ /** §81: how a revocation resolves from a given pre-revocation state. */
305
+ export declare function revocationResolutionForState(state: TransactionState): TransactionResolution;
306
+ export declare function transitionTransaction(recordInput: unknown, commandInput: unknown, nowEpochMs: number): TransactionTransitionResult;
307
+ /**
308
+ * Create a transaction record in PROPOSED with PROPOSE already recorded
309
+ * and bound to the canonical action digest.
310
+ */
311
+ export declare function proposeTransaction(input: {
312
+ tenantId: string;
313
+ principalId: string;
314
+ agentId: string;
315
+ requestId: string;
316
+ correlationId: string;
317
+ action: string;
318
+ actionDigest: string;
319
+ declaration: TransactionDeclaration;
320
+ compensationOf?: string;
321
+ atEpochMs: number;
322
+ }): TransactionRecord;
323
+ /**
324
+ * The injected port the gateway and execution paths record through.
325
+ * Implementations persist TransactionRecord rows plus a stage-transition
326
+ * audit; the pure evaluator above is the only writer of state. Every
327
+ * method returns null on failure — callers fail closed.
328
+ */
329
+ export interface TransactionTracker {
330
+ /**
331
+ * Idempotent create keyed on the request-derived transaction id:
332
+ * returns the record (creating it PROPOSED when absent), the existing
333
+ * record when the same action digest is replayed, and null when a
334
+ * record for the id exists with a different digest or the store
335
+ * fails.
336
+ */
337
+ propose(input: {
338
+ tenantId: string;
339
+ principalId: string;
340
+ agentId: string;
341
+ requestId: string;
342
+ correlationId: string;
343
+ action: string;
344
+ actionDigest: string;
345
+ declaration: TransactionDeclaration;
346
+ compensationOf?: string;
347
+ atEpochMs: number;
348
+ }): Promise<TransactionRecord | null>;
349
+ /** Apply one command through the evaluator with CAS semantics. */
350
+ transition(input: {
351
+ tenantId: string;
352
+ transactionId: string;
353
+ command: TransactionCommand;
354
+ atEpochMs: number;
355
+ }): Promise<TransactionRecord | null>;
356
+ get(input: {
357
+ tenantId: string;
358
+ transactionId: string;
359
+ }): Promise<TransactionRecord | null>;
360
+ }
@@ -0,0 +1 @@
1
+ export * from "./contracts/index.js";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * WO-019 — embedded approval primitives for partner apps (extends the WO-015
3
+ * SDK). A partner embeds Guardian authority by driving the human's approval
4
+ * surface through this client; the calls hit `/v1/embedded/approvals`, which
5
+ * runs the identical approval-service methods as the first-party route, so
6
+ * the decision semantics, receipts and evidence are identical.
7
+ *
8
+ * The partner supplies the human's own Guardian session token — the partner
9
+ * never handles agent credentials and cannot widen what the human may see or
10
+ * decide.
11
+ */
12
+ export type EmbeddedApprovalConfig = Readonly<{
13
+ /** e.g. https://guardian-api-staging.odingard.com */
14
+ baseUrl: string;
15
+ /** The human's Guardian session token presented through the partner app. */
16
+ sessionToken: string;
17
+ fetch?: typeof fetch;
18
+ }>;
19
+ export type EmbeddedApprovalSummary = Readonly<{
20
+ approvalId: string;
21
+ state: string;
22
+ version: number;
23
+ headline: string;
24
+ expiresAtEpochMs: number;
25
+ }>;
26
+ export type EmbeddedApprovalView = Readonly<{
27
+ display: unknown;
28
+ challenge: unknown | null;
29
+ }>;
30
+ export type EmbeddedDecisionResult = Readonly<{
31
+ receipt: unknown;
32
+ changed: boolean;
33
+ }>;
34
+ export type EmbeddedResult<T> = {
35
+ ok: true;
36
+ value: T;
37
+ } | {
38
+ ok: false;
39
+ reasonCode: string;
40
+ };
41
+ export declare function isHumanSessionToken(token: unknown): token is string;
42
+ export declare function createEmbeddedApprovalClient(config: EmbeddedApprovalConfig): {
43
+ listApprovals(): Promise<EmbeddedResult<{
44
+ approvals: readonly EmbeddedApprovalSummary[];
45
+ }>>;
46
+ viewApproval(approvalId: string): Promise<EmbeddedResult<EmbeddedApprovalView>>;
47
+ decideApproval(approvalId: string, input: {
48
+ expectedVersion: number;
49
+ decision: "approve" | "deny";
50
+ presentationDigest: string;
51
+ /** WO-019 step-up factor: tap (default), passkey, biometric, second-device. */
52
+ factor?: "tap" | "passkey" | "biometric" | "second-device";
53
+ }): Promise<EmbeddedResult<EmbeddedDecisionResult>>;
54
+ revokeApproval(approvalId: string, input: {
55
+ expectedVersion: number;
56
+ }): Promise<EmbeddedResult<EmbeddedDecisionResult>>;
57
+ };
58
+ export type EmbeddedApprovalClient = ReturnType<typeof createEmbeddedApprovalClient>;
@@ -0,0 +1,25 @@
1
+ import { type EvidenceEvent, type EvidenceChainContext, type EvidenceRecord, type EvidenceRecordCore } from "../contracts/index.js";
2
+ export type AppendEvidenceFailure = "MALFORMED_CHAIN" | "MALFORMED_DRAFT" | "CHAIN_INVALID" | "DUPLICATE_EVIDENCE_ID" | "APPEND_CONTEXT_MISMATCH" | "NON_MONOTONIC_EVENT_TIME" | "CHAIN_LIMIT_EXCEEDED";
3
+ export type AppendEvidenceResult = {
4
+ ok: true;
5
+ record: EvidenceRecord;
6
+ chain: EvidenceRecord[];
7
+ } | {
8
+ ok: false;
9
+ reasonCode: AppendEvidenceFailure;
10
+ };
11
+ export type EvidenceVerificationFailure = "MALFORMED_CHAIN" | "INVALID_GENESIS" | "DUPLICATE_EVIDENCE_ID" | "DUPLICATE_SEQUENCE" | "SEQUENCE_GAP" | "RECORD_REORDERED" | "CONTEXT_MISMATCH" | "ACTION_DIGEST_MISMATCH" | "INVALID_EVENT_ORDER" | "PAYLOAD_DIGEST_MISMATCH" | "BROKEN_LINK" | "NON_MONOTONIC_EVENT_TIME" | "RECORD_HASH_MISMATCH";
12
+ export type EvidenceVerificationResult = {
13
+ valid: true;
14
+ count: number;
15
+ lastRecordHash: string | null;
16
+ context: EvidenceChainContext | null;
17
+ } | {
18
+ valid: false;
19
+ reasonCode: EvidenceVerificationFailure;
20
+ recordIndex: number | null;
21
+ };
22
+ export declare function hashEvidencePayload(event: EvidenceEvent): string;
23
+ export declare function hashEvidenceRecordCore(core: EvidenceRecordCore): string;
24
+ export declare function verifyEvidenceChain(chainInput: unknown, expectedContextInput?: unknown): EvidenceVerificationResult;
25
+ export declare function appendEvidenceRecord(chainInput: unknown, draftInput: unknown): AppendEvidenceResult;
@@ -0,0 +1,61 @@
1
+ import { type ApprovalRecord, type CanonicalAction, type CapabilityClaims, type EvidenceRecord, type ExecutionRecord, type PortableAuthorityReceipt, type PortableReceiptBody, type ReceiptVerificationJwk } from "../contracts/index.js";
2
+ export type ReceiptSigner = Readonly<{
3
+ keyId: string;
4
+ verificationJwk: ReceiptVerificationJwk;
5
+ sign(body: PortableReceiptBody): PortableAuthorityReceipt;
6
+ }>;
7
+ /** Deterministic receipt key id: rkey_<first-16-hex of sha256(x)>. */
8
+ export declare function receiptKeyIdFromX(x: string): string;
9
+ /**
10
+ * Builds a receipt signer from an Ed25519 signing JWK (`{x, d}` as stored in
11
+ * the `receipt-signing-jwk` secret). Throws on malformed key material.
12
+ */
13
+ export declare function createReceiptSignerFromJwk(input: unknown): ReceiptSigner;
14
+ /** Generates an ephemeral signer — development and tests only. */
15
+ export declare function createEphemeralReceiptSigner(): ReceiptSigner;
16
+ export type BuildPortableReceiptInput = Readonly<{
17
+ receiptId: string;
18
+ issuedAtEpochMs: number;
19
+ /** The complete evidence chain for the request, in sequence order. */
20
+ chain: readonly EvidenceRecord[];
21
+ /**
22
+ * The canonical action the kernel evaluated (from the private
23
+ * materialized-action store). The chain binds it via its material digest.
24
+ */
25
+ action?: CanonicalAction | null;
26
+ /** Latest stored approval record, when the request required one. */
27
+ approval?: ApprovalRecord | null;
28
+ /** The issued capability's claims (never the token). */
29
+ capabilityClaims?: CapabilityClaims | null;
30
+ capabilityState?: "issued" | "used" | "expired" | "revoked" | null;
31
+ /** Latest execution ledger record, when execution was attempted. */
32
+ execution?: ExecutionRecord | null;
33
+ }>;
34
+ export type BuildPortableReceiptResult = {
35
+ ok: true;
36
+ body: PortableReceiptBody;
37
+ } | {
38
+ ok: false;
39
+ reasonCode: "CHAIN_INVALID" | "ACTION_UNAVAILABLE" | "DECISION_MISSING" | "APPROVAL_INCONSISTENT" | "CAPABILITY_INCONSISTENT" | "EXECUTION_INCONSISTENT";
40
+ };
41
+ export declare function buildPortableReceipt(input: BuildPortableReceiptInput): BuildPortableReceiptResult;
42
+ /** Recomputes the capability claims digest (same domain as the broker). */
43
+ export declare function capabilityClaimsDigest(claims: CapabilityClaims): string;
44
+ export type PortableReceiptVerificationFailure = "MALFORMED_RECEIPT" | "UNKNOWN_KEY" | "SIGNATURE_INVALID" | "EVIDENCE_CHAIN_INVALID" | "SUBJECT_MISMATCH" | "ACTION_MISMATCH" | "DECISION_MISMATCH" | "APPROVAL_MISMATCH" | "CAPABILITY_MISMATCH" | "EXECUTION_MISMATCH" | "EFFECT_MISMATCH" | "EVIDENCE_HEAD_MISMATCH";
45
+ export type PortableReceiptVerificationResult = {
46
+ valid: true;
47
+ subject: PortableReceiptBody["subject"];
48
+ decision: PortableReceiptBody["decision"]["decision"];
49
+ effect: PortableReceiptBody["effect"]["kind"];
50
+ } | {
51
+ valid: false;
52
+ reasonCode: PortableReceiptVerificationFailure;
53
+ };
54
+ /**
55
+ * Self-contained portable receipt verification. The caller supplies only the
56
+ * receipt and the published verification key set — no Guardian credential,
57
+ * database, or service is required. Every embedded object is re-digested and
58
+ * cross-checked against the embedded evidence chain, and the Ed25519 proof is
59
+ * verified over the canonical receipt body.
60
+ */
61
+ export declare function verifyPortableAuthorityReceipt(receiptInput: unknown, keysInput: unknown): PortableReceiptVerificationResult;
@@ -0,0 +1,5 @@
1
+ export { createGuardianClient, type GuardianClient, type GuardianClientConfig, type GuardianGovernedInvocation, type GuardianInvocation, type GuardianRequestResult, type GuardianToolInvocation, type GuardianMcpInvocation, } from "./client.js";
2
+ export { createEmbeddedApprovalClient, isHumanSessionToken, type EmbeddedApprovalClient, type EmbeddedApprovalConfig, type EmbeddedApprovalSummary, type EmbeddedApprovalView, type EmbeddedDecisionResult, type EmbeddedResult, } from "./embedded.js";
3
+ export { classifyRequestResult, type GuardianDecision } from "./lifecycle.js";
4
+ export { fetchReceiptVerificationKeys, verifyReceiptOffline, verifyReceiptOnline, type ReceiptKeySetResult, type ReceiptVerification, } from "./receipts.js";
5
+ export { findAgentSystem, guardianCatalog, verticalsForAction, type GuardianCatalogAgentSystem, type GuardianCatalogVertical, type GuardianPublicCatalog, } from "./catalog.js";
@@ -0,0 +1,25 @@
1
+ import type { GuardianRequestResult } from "./client.js";
2
+ /**
3
+ * WO-042 — the single, fail-closed reading of a Guardian request result.
4
+ *
5
+ * ALLOW — a capability token was issued; `execute` redeems it.
6
+ * ASK — held for a human; keep `requestId`, then `claim(requestId)`
7
+ * after the human decides. The gateway reports a held ASK as
8
+ * `{ ok: false, reasonCode: "APPROVAL_REQUIRED", requestId }`.
9
+ * DENY — everything else, including ambiguity (ALLOW without a token),
10
+ * an unknown shape, or Guardian being unreachable.
11
+ */
12
+ export type GuardianDecision = {
13
+ decision: "ALLOW";
14
+ requestId: string;
15
+ capabilityToken: string;
16
+ } | {
17
+ decision: "ASK";
18
+ requestId: string;
19
+ reasonCode: string;
20
+ } | {
21
+ decision: "DENY";
22
+ reasonCode: string;
23
+ requestId?: string;
24
+ };
25
+ export declare function classifyRequestResult(result: GuardianRequestResult): GuardianDecision;
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ export declare const AgentActionProposalSchema: z.ZodObject<{
3
+ schemaVersion: z.ZodLiteral<1>;
4
+ requestId: z.core.$ZodBranded<z.ZodString, "RequestId", "out">;
5
+ correlationId: z.core.$ZodBranded<z.ZodString, "CorrelationId", "out">;
6
+ action: z.core.$ZodBranded<z.ZodString, "ActionType", "out">;
7
+ resource: z.core.$ZodBranded<z.ZodString, "ResourceRef", "out">;
8
+ valueCents: z.ZodOptional<z.ZodNumber>;
9
+ merchantId: z.ZodOptional<z.ZodString>;
10
+ merchantCategory: z.ZodOptional<z.ZodString>;
11
+ recurring: z.ZodOptional<z.ZodBoolean>;
12
+ taskId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "TaskId", "out">>;
13
+ intentId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "IntentId", "out">>;
14
+ planId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "PlanId", "out">>;
15
+ parentActionId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "RequestId", "out">>;
16
+ sourceEffectId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "AttemptId", "out">>;
17
+ compensatesTransactionId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "TransactionId", "out">>;
18
+ physicalFacts: z.ZodOptional<z.ZodObject<{
19
+ zone: z.ZodOptional<z.ZodString>;
20
+ speed: z.ZodOptional<z.ZodNumber>;
21
+ force: z.ZodOptional<z.ZodNumber>;
22
+ payload: z.ZodOptional<z.ZodNumber>;
23
+ atEpochMs: z.ZodOptional<z.ZodNumber>;
24
+ humanDistance: z.ZodOptional<z.ZodNumber>;
25
+ environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
26
+ supervised: z.ZodOptional<z.ZodBoolean>;
27
+ }, z.core.$strict>>;
28
+ uses: z.ZodLiteral<1>;
29
+ materialParameters: z.ZodPipe<z.ZodUnknown, z.ZodTransform<Readonly<Record<string, import("./contracts/canonical-json.js").CanonicalJsonValue>>, unknown>>;
30
+ purpose: z.ZodString;
31
+ initiatingContext: z.ZodEnum<{
32
+ agent: "agent";
33
+ user: "user";
34
+ scheduled: "scheduled";
35
+ "external-event": "external-event";
36
+ }>;
37
+ requestedAdapterId: z.core.$ZodBranded<z.ZodString, "AdapterId", "out">;
38
+ requestedTtlMs: z.ZodNumber;
39
+ runtime: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strict>;
41
+ export type AgentActionProposal = z.infer<typeof AgentActionProposalSchema>;
@@ -0,0 +1,37 @@
1
+ import { verifyPortableAuthorityReceipt } from "./evidence/receipt.js";
2
+ /**
3
+ * WO-042 — portable receipt verification for developers and auditors.
4
+ *
5
+ * Offline verification needs only the receipt and Guardian's published
6
+ * Ed25519 verification keys: no agent credential, account, plan or Guardian
7
+ * service is involved once the keys are in hand. It checks the
8
+ * `guardian-canonical-json.v1` signature over the receipt body and
9
+ * re-derives every embedded record against the receipt's evidence chain.
10
+ * Verification is never billable (GUA-REVENUE-001).
11
+ */
12
+ export type ReceiptVerification = ReturnType<typeof verifyPortableAuthorityReceipt>;
13
+ export type ReceiptKeySetResult = {
14
+ ok: true;
15
+ keys: unknown;
16
+ } | {
17
+ ok: false;
18
+ reasonCode: string;
19
+ };
20
+ type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
21
+ /** Fetch the published verification key set (public; no credential). */
22
+ export declare function fetchReceiptVerificationKeys(baseUrl: string, options?: {
23
+ fetch?: FetchLike;
24
+ }): Promise<ReceiptKeySetResult>;
25
+ /** Verify a receipt locally against a key set. Pure; no network. */
26
+ export declare function verifyReceiptOffline(receipt: unknown, keys: unknown): ReceiptVerification;
27
+ /** Ask a Guardian deployment to verify a receipt (public endpoint). */
28
+ export declare function verifyReceiptOnline(baseUrl: string, receipt: unknown, options?: {
29
+ fetch?: FetchLike;
30
+ }): Promise<{
31
+ ok: true;
32
+ result: Record<string, unknown>;
33
+ } | {
34
+ ok: false;
35
+ reasonCode: string;
36
+ }>;
37
+ export {};