@odingard/guardian-sdk 0.1.0 → 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.
- package/README.md +252 -17
- package/dist/contracts.js +9865 -0
- package/dist/index.js +12976 -1787
- package/dist/public-catalog.v1.json +6915 -0
- package/dist-dts/catalog.d.ts +14 -0
- package/dist-dts/client.d.ts +51 -1
- package/dist-dts/contracts/action-pack.d.ts +464 -0
- package/dist-dts/contracts/action-registry.d.ts +91 -1
- package/dist-dts/contracts/action.d.ts +1408 -17
- package/dist-dts/contracts/agent-state.d.ts +386 -0
- package/dist-dts/contracts/approval.d.ts +224 -5
- package/dist-dts/contracts/assurance.d.ts +60 -0
- package/dist-dts/contracts/authority-graph.d.ts +294 -0
- package/dist-dts/contracts/authority-state.d.ts +17 -2
- package/dist-dts/contracts/authority.d.ts +31 -5
- package/dist-dts/contracts/billing.d.ts +32 -0
- package/dist-dts/contracts/calendar.d.ts +6 -6
- package/dist-dts/contracts/denial.d.ts +648 -0
- package/dist-dts/contracts/evidence.d.ts +73 -16
- package/dist-dts/contracts/execution.d.ts +449 -55
- package/dist-dts/contracts/identifiers.d.ts +16 -0
- package/dist-dts/contracts/index.d.ts +22 -0
- package/dist-dts/contracts/intent.d.ts +335 -0
- package/dist-dts/contracts/lineage.d.ts +218 -0
- package/dist-dts/contracts/local.d.ts +101 -0
- package/dist-dts/contracts/multi-principal.d.ts +292 -0
- package/dist-dts/contracts/multiparty.d.ts +169 -0
- package/dist-dts/contracts/obligation.d.ts +196 -0
- package/dist-dts/contracts/plan.d.ts +67 -0
- package/dist-dts/contracts/policy-simulation.d.ts +681 -0
- package/dist-dts/contracts/prerequisite.d.ts +147 -0
- package/dist-dts/contracts/protected-data.d.ts +67 -0
- package/dist-dts/contracts/receipt.d.ts +3126 -0
- package/dist-dts/contracts/resource-claims.d.ts +146 -0
- package/dist-dts/contracts/runtime.d.ts +111 -0
- package/dist-dts/contracts/safety-envelope.d.ts +287 -0
- package/dist-dts/contracts/sequence.d.ts +132 -0
- package/dist-dts/contracts/sources.d.ts +191 -0
- package/dist-dts/contracts/tools.d.ts +50 -5
- package/dist-dts/contracts/transaction.d.ts +360 -0
- package/dist-dts/contracts-entry.d.ts +1 -0
- package/dist-dts/embedded.d.ts +58 -0
- package/dist-dts/evidence/evidence.d.ts +25 -0
- package/dist-dts/evidence/receipt.d.ts +61 -0
- package/dist-dts/index.d.ts +5 -1
- package/dist-dts/lifecycle.d.ts +25 -0
- package/dist-dts/proposal.d.ts +16 -0
- package/dist-dts/receipts.d.ts +37 -0
- package/package.json +12 -6
- package/dist-dts/__tests__/client.test.d.ts +0 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { StepUpLevel } from "./multi-principal.js";
|
|
3
|
+
/**
|
|
4
|
+
* WO-023: guardian.obligation.v1 — declarative obligations.
|
|
5
|
+
*
|
|
6
|
+
* An obligation is a human-authored condition attached to an intent: "ALLOW,
|
|
7
|
+
* provided these conditions are satisfied." Obligations are declarative
|
|
8
|
+
* inputs to the ONE authority kernel (directive §89, K15): they never add a
|
|
9
|
+
* verdict (the triad stays ALLOW/ASK/DENY), never widen a grant, and never
|
|
10
|
+
* issue authority. This evaluator is pure and read-only — it may look at the
|
|
11
|
+
* context and return a state; it cannot broaden authority, mint
|
|
12
|
+
* capabilities, or bypass the existing ASK machinery.
|
|
13
|
+
*
|
|
14
|
+
* Evaluation phases (§11–12):
|
|
15
|
+
* - "decision" — mechanical verifiers settled deterministically at the
|
|
16
|
+
* decision point (satisfied | failed).
|
|
17
|
+
* - "human" — human-facing conditions that force the existing ASK
|
|
18
|
+
* machinery (step-up / second approver / quorum compose
|
|
19
|
+
* with the WO-019 approval chain).
|
|
20
|
+
* - "post_action" — recorded as pending and transitioned by evidence or
|
|
21
|
+
* the sweeper; unfulfilled ones surface as overdue, never
|
|
22
|
+
* silently dropped.
|
|
23
|
+
* - "time" — pending until a derived due instant elapses.
|
|
24
|
+
* - "unwired" — types with no verifier in this build: they evaluate
|
|
25
|
+
* `failed` with rule OBLIGATION_VERIFIER_UNAVAILABLE and
|
|
26
|
+
* therefore DENY (fail-closed).
|
|
27
|
+
*/
|
|
28
|
+
export declare const OBLIGATION_CONTRACT_SCHEMA = "guardian.obligation.v1";
|
|
29
|
+
/** All 23 obligation types named by directive §12. */
|
|
30
|
+
export declare const ObligationTypeSchema: z.ZodEnum<{
|
|
31
|
+
log: "log";
|
|
32
|
+
retain_receipt: "retain_receipt";
|
|
33
|
+
notify: "notify";
|
|
34
|
+
delay: "delay";
|
|
35
|
+
cooling_period: "cooling_period";
|
|
36
|
+
delete_after_use: "delete_after_use";
|
|
37
|
+
redact: "redact";
|
|
38
|
+
encrypt: "encrypt";
|
|
39
|
+
tokenize: "tokenize";
|
|
40
|
+
minimize: "minimize";
|
|
41
|
+
verify_counterparty: "verify_counterparty";
|
|
42
|
+
verify_resource: "verify_resource";
|
|
43
|
+
verify_effect: "verify_effect";
|
|
44
|
+
attest_runtime: "attest_runtime";
|
|
45
|
+
require_consent: "require_consent";
|
|
46
|
+
require_location: "require_location";
|
|
47
|
+
require_device: "require_device";
|
|
48
|
+
require_network: "require_network";
|
|
49
|
+
require_contract: "require_contract";
|
|
50
|
+
step_up: "step_up";
|
|
51
|
+
second_approver: "second_approver";
|
|
52
|
+
quorum: "quorum";
|
|
53
|
+
authenticate: "authenticate";
|
|
54
|
+
}>;
|
|
55
|
+
export type ObligationType = z.infer<typeof ObligationTypeSchema>;
|
|
56
|
+
/** Bounded, deterministic per-type params (fields[], seconds, quorumSize, level...). */
|
|
57
|
+
export declare const ObligationParamsSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
58
|
+
export type ObligationParams = z.infer<typeof ObligationParamsSchema>;
|
|
59
|
+
export declare const ObligationSchema: z.ZodObject<{
|
|
60
|
+
type: z.ZodEnum<{
|
|
61
|
+
log: "log";
|
|
62
|
+
retain_receipt: "retain_receipt";
|
|
63
|
+
notify: "notify";
|
|
64
|
+
delay: "delay";
|
|
65
|
+
cooling_period: "cooling_period";
|
|
66
|
+
delete_after_use: "delete_after_use";
|
|
67
|
+
redact: "redact";
|
|
68
|
+
encrypt: "encrypt";
|
|
69
|
+
tokenize: "tokenize";
|
|
70
|
+
minimize: "minimize";
|
|
71
|
+
verify_counterparty: "verify_counterparty";
|
|
72
|
+
verify_resource: "verify_resource";
|
|
73
|
+
verify_effect: "verify_effect";
|
|
74
|
+
attest_runtime: "attest_runtime";
|
|
75
|
+
require_consent: "require_consent";
|
|
76
|
+
require_location: "require_location";
|
|
77
|
+
require_device: "require_device";
|
|
78
|
+
require_network: "require_network";
|
|
79
|
+
require_contract: "require_contract";
|
|
80
|
+
step_up: "step_up";
|
|
81
|
+
second_approver: "second_approver";
|
|
82
|
+
quorum: "quorum";
|
|
83
|
+
authenticate: "authenticate";
|
|
84
|
+
}>;
|
|
85
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
|
|
86
|
+
}, z.core.$strict>;
|
|
87
|
+
export type Obligation = z.infer<typeof ObligationSchema>;
|
|
88
|
+
export declare const ObligationStateValueSchema: z.ZodEnum<{
|
|
89
|
+
satisfied: "satisfied";
|
|
90
|
+
pending: "pending";
|
|
91
|
+
failed: "failed";
|
|
92
|
+
not_applicable: "not_applicable";
|
|
93
|
+
}>;
|
|
94
|
+
export type ObligationStateValue = z.infer<typeof ObligationStateValueSchema>;
|
|
95
|
+
/** Outcome rules reported on each obligation state. */
|
|
96
|
+
export declare const ObligationRuleSchema: z.ZodEnum<{
|
|
97
|
+
OBLIGATION_SATISFIED: "OBLIGATION_SATISFIED";
|
|
98
|
+
PENDING_POST_ACTION: "PENDING_POST_ACTION";
|
|
99
|
+
PENDING_TIME: "PENDING_TIME";
|
|
100
|
+
PENDING_HUMAN: "PENDING_HUMAN";
|
|
101
|
+
OBLIGATION_PARAMS_INVALID: "OBLIGATION_PARAMS_INVALID";
|
|
102
|
+
COUNTERPARTY_UNVERIFIED: "COUNTERPARTY_UNVERIFIED";
|
|
103
|
+
RESOURCE_NOT_COVERED: "RESOURCE_NOT_COVERED";
|
|
104
|
+
OBLIGATION_VERIFIER_UNAVAILABLE: "OBLIGATION_VERIFIER_UNAVAILABLE";
|
|
105
|
+
}>;
|
|
106
|
+
export type ObligationRule = z.infer<typeof ObligationRuleSchema>;
|
|
107
|
+
export declare const ObligationStateSchema: z.ZodObject<{
|
|
108
|
+
obligationType: z.ZodEnum<{
|
|
109
|
+
log: "log";
|
|
110
|
+
retain_receipt: "retain_receipt";
|
|
111
|
+
notify: "notify";
|
|
112
|
+
delay: "delay";
|
|
113
|
+
cooling_period: "cooling_period";
|
|
114
|
+
delete_after_use: "delete_after_use";
|
|
115
|
+
redact: "redact";
|
|
116
|
+
encrypt: "encrypt";
|
|
117
|
+
tokenize: "tokenize";
|
|
118
|
+
minimize: "minimize";
|
|
119
|
+
verify_counterparty: "verify_counterparty";
|
|
120
|
+
verify_resource: "verify_resource";
|
|
121
|
+
verify_effect: "verify_effect";
|
|
122
|
+
attest_runtime: "attest_runtime";
|
|
123
|
+
require_consent: "require_consent";
|
|
124
|
+
require_location: "require_location";
|
|
125
|
+
require_device: "require_device";
|
|
126
|
+
require_network: "require_network";
|
|
127
|
+
require_contract: "require_contract";
|
|
128
|
+
step_up: "step_up";
|
|
129
|
+
second_approver: "second_approver";
|
|
130
|
+
quorum: "quorum";
|
|
131
|
+
authenticate: "authenticate";
|
|
132
|
+
}>;
|
|
133
|
+
state: z.ZodEnum<{
|
|
134
|
+
satisfied: "satisfied";
|
|
135
|
+
pending: "pending";
|
|
136
|
+
failed: "failed";
|
|
137
|
+
not_applicable: "not_applicable";
|
|
138
|
+
}>;
|
|
139
|
+
rule: z.ZodEnum<{
|
|
140
|
+
OBLIGATION_SATISFIED: "OBLIGATION_SATISFIED";
|
|
141
|
+
PENDING_POST_ACTION: "PENDING_POST_ACTION";
|
|
142
|
+
PENDING_TIME: "PENDING_TIME";
|
|
143
|
+
PENDING_HUMAN: "PENDING_HUMAN";
|
|
144
|
+
OBLIGATION_PARAMS_INVALID: "OBLIGATION_PARAMS_INVALID";
|
|
145
|
+
COUNTERPARTY_UNVERIFIED: "COUNTERPARTY_UNVERIFIED";
|
|
146
|
+
RESOURCE_NOT_COVERED: "RESOURCE_NOT_COVERED";
|
|
147
|
+
OBLIGATION_VERIFIER_UNAVAILABLE: "OBLIGATION_VERIFIER_UNAVAILABLE";
|
|
148
|
+
}>;
|
|
149
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
150
|
+
dueEpochMs: z.ZodOptional<z.ZodNumber>;
|
|
151
|
+
}, z.core.$strict>;
|
|
152
|
+
export type ObligationState = z.infer<typeof ObligationStateSchema>;
|
|
153
|
+
export type ObligationPhase = "decision" | "human" | "post_action" | "time" | "unwired";
|
|
154
|
+
export declare function obligationPhase(type: ObligationType): ObligationPhase;
|
|
155
|
+
export declare function isHumanFacingObligation(type: ObligationType): boolean;
|
|
156
|
+
/** True for pending obligations the sweeper completes when due time passes. */
|
|
157
|
+
export declare function isTimeElapsedObligation(type: ObligationType): boolean;
|
|
158
|
+
/** True for obligations that run as recorded parameter transforms. */
|
|
159
|
+
export declare function isTransformObligation(type: ObligationType): boolean;
|
|
160
|
+
/** Read-only facts the evaluator may consult. It cannot mutate or mint. */
|
|
161
|
+
export type ObligationContext = Readonly<{
|
|
162
|
+
nowEpochMs: number;
|
|
163
|
+
/** The action's declared counterparty (merchant) label, if any. */
|
|
164
|
+
merchantId?: string | undefined;
|
|
165
|
+
/** The action's resource ref. */
|
|
166
|
+
resource: string;
|
|
167
|
+
/** Counterparties declared on the enclosing intent (absent = none declared). */
|
|
168
|
+
intentCounterparties?: readonly string[] | undefined;
|
|
169
|
+
/** Resources declared on the enclosing intent (absent = unconstrained). */
|
|
170
|
+
intentResources?: readonly string[] | undefined;
|
|
171
|
+
/** True when the narrowed authority chain still covers this action. */
|
|
172
|
+
chainCoversAction: boolean;
|
|
173
|
+
}>;
|
|
174
|
+
export declare function positiveIntParam(params: ObligationParams | undefined, key: string): number | null;
|
|
175
|
+
export declare function stringArrayParam(params: ObligationParams | undefined, key: string): readonly string[] | null;
|
|
176
|
+
export declare function stringParam(params: ObligationParams | undefined, key: string): string | null;
|
|
177
|
+
/**
|
|
178
|
+
* Pure obligation evaluation. Deterministic and read-only: identical inputs
|
|
179
|
+
* always produce identical states and the evaluator issues no authority.
|
|
180
|
+
*/
|
|
181
|
+
export declare function evaluateObligation(obligation: Obligation, context: ObligationContext): ObligationState;
|
|
182
|
+
/**
|
|
183
|
+
* Deterministically evaluate every declared obligation, in declared order.
|
|
184
|
+
*/
|
|
185
|
+
export declare function evaluateObligations(obligations: readonly Obligation[], context: ObligationContext): readonly ObligationState[];
|
|
186
|
+
/** First failed state, if any — a failed/unsettleable obligation denies. */
|
|
187
|
+
export declare function firstFailedObligation(states: readonly ObligationState[]): ObligationState | null;
|
|
188
|
+
/**
|
|
189
|
+
* Human-facing obligations raise the WO-019 approval requirement. This
|
|
190
|
+
* composes step_up → requiredFactor and second_approver/quorum →
|
|
191
|
+
* requiredApprovals; it never lowers an existing requirement.
|
|
192
|
+
*/
|
|
193
|
+
export declare function obligationApprovalRequirement(obligations: readonly Obligation[]): {
|
|
194
|
+
requiredFactor?: StepUpLevel;
|
|
195
|
+
requiredApprovals?: number;
|
|
196
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { IntentContract } from "./intent.js";
|
|
3
|
+
/**
|
|
4
|
+
* WO-022: guardian.plan.v1 — Plan Authority.
|
|
5
|
+
*
|
|
6
|
+
* A plan is a PROPOSAL, never authority. It decomposes an intent into an
|
|
7
|
+
* ordered task graph; submitting one enlarges nothing. The gateway's
|
|
8
|
+
* intent pre-gate uses plan task membership only to bind taskId → plan →
|
|
9
|
+
* intent provenance. Scope validation (validatePlanAgainstIntent) runs at
|
|
10
|
+
* submission so a plan cannot even propose work outside its intent.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PLAN_CONTRACT_SCHEMA = "guardian.plan.v1";
|
|
13
|
+
export declare const PlanStatusSchema: z.ZodEnum<{
|
|
14
|
+
draft: "draft";
|
|
15
|
+
active: "active";
|
|
16
|
+
revoked: "revoked";
|
|
17
|
+
completed: "completed";
|
|
18
|
+
}>;
|
|
19
|
+
export type PlanStatus = z.infer<typeof PlanStatusSchema>;
|
|
20
|
+
export declare const PlanNodeSchema: z.ZodObject<{
|
|
21
|
+
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
|
|
22
|
+
title: z.ZodString;
|
|
23
|
+
actionFamily: z.ZodOptional<z.ZodString>;
|
|
24
|
+
actionIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
agentId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "AgentId", "out">>;
|
|
26
|
+
dependsOn: z.ZodArray<z.core.$ZodBranded<z.ZodString, "TaskId", "out">>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export type PlanNode = z.infer<typeof PlanNodeSchema>;
|
|
29
|
+
export declare const PlanContractSchema: z.ZodObject<{
|
|
30
|
+
schema: z.ZodLiteral<"guardian.plan.v1">;
|
|
31
|
+
planId: z.core.$ZodBranded<z.ZodString, "PlanId", "out">;
|
|
32
|
+
intentId: z.core.$ZodBranded<z.ZodString, "IntentId", "out">;
|
|
33
|
+
tenantId: z.core.$ZodBranded<z.ZodString, "TenantId", "out">;
|
|
34
|
+
principalId: z.core.$ZodBranded<z.ZodString, "PrincipalId", "out">;
|
|
35
|
+
createdBy: z.ZodString;
|
|
36
|
+
title: z.ZodString;
|
|
37
|
+
nodes: z.ZodArray<z.ZodObject<{
|
|
38
|
+
taskId: z.core.$ZodBranded<z.ZodString, "TaskId", "out">;
|
|
39
|
+
title: z.ZodString;
|
|
40
|
+
actionFamily: z.ZodOptional<z.ZodString>;
|
|
41
|
+
actionIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
42
|
+
agentId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "AgentId", "out">>;
|
|
43
|
+
dependsOn: z.ZodArray<z.core.$ZodBranded<z.ZodString, "TaskId", "out">>;
|
|
44
|
+
}, z.core.$strict>>;
|
|
45
|
+
status: z.ZodEnum<{
|
|
46
|
+
draft: "draft";
|
|
47
|
+
active: "active";
|
|
48
|
+
revoked: "revoked";
|
|
49
|
+
completed: "completed";
|
|
50
|
+
}>;
|
|
51
|
+
version: z.ZodNumber;
|
|
52
|
+
createdAtEpochMs: z.ZodNumber;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
export type PlanContract = z.infer<typeof PlanContractSchema>;
|
|
55
|
+
export type PlanValidationFailure = "PLAN_DUPLICATE_TASK" | "PLAN_UNKNOWN_DEPENDENCY" | "PLAN_FORWARD_DEPENDENCY" | "PLAN_CYCLE";
|
|
56
|
+
/** Structural DAG validation: unique taskIds, resolvable backward-only
|
|
57
|
+
* dependsOn references, acyclic. */
|
|
58
|
+
export declare function validatePlanDag(nodes: readonly PlanNode[]): PlanValidationFailure | null;
|
|
59
|
+
export type PlanScopeFailure = "PLAN_TASK_FAMILY_OUT_OF_SCOPE" | "PLAN_TASK_ACTIONS_OUT_OF_SCOPE" | "PLAN_TASK_AGENT_UNAUTHORIZED";
|
|
60
|
+
/**
|
|
61
|
+
* Every task a plan proposes must fit inside the intent: declared families
|
|
62
|
+
* must be in allowedActionFamilies (when the intent constrains them), and
|
|
63
|
+
* declared agents must be in authorizedAgents.
|
|
64
|
+
*/
|
|
65
|
+
export declare function validatePlanAgainstIntent(plan: Pick<PlanContract, "nodes">, intent: Pick<IntentContract, "allowedActionFamilies" | "authorizedAgents">): PlanScopeFailure | null;
|
|
66
|
+
/** Whether any active plan contains the given taskId. */
|
|
67
|
+
export declare function planContainsTask(plan: Pick<PlanContract, "nodes" | "status">, taskId: string): boolean;
|