@kya-os/checkpoint-wasm-runtime 1.0.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/CHANGELOG.md +58 -0
- package/dist/adapters.d.mts +257 -0
- package/dist/adapters.d.ts +257 -0
- package/dist/adapters.js +603 -0
- package/dist/adapters.js.map +1 -0
- package/dist/adapters.mjs +586 -0
- package/dist/adapters.mjs.map +1 -0
- package/dist/dynamic-loader-cS-pUisw.d.ts +65 -0
- package/dist/dynamic-loader-qGJacfEC.d.mts +65 -0
- package/dist/edge.d.mts +22 -0
- package/dist/edge.d.ts +22 -0
- package/dist/edge.js +1403 -0
- package/dist/edge.js.map +1 -0
- package/dist/edge.mjs +1391 -0
- package/dist/edge.mjs.map +1 -0
- package/dist/engine-edge.d.mts +58 -0
- package/dist/engine-edge.d.ts +58 -0
- package/dist/engine-edge.js +537 -0
- package/dist/engine-edge.js.map +1 -0
- package/dist/engine-edge.mjs +533 -0
- package/dist/engine-edge.mjs.map +1 -0
- package/dist/engine.d.mts +34 -0
- package/dist/engine.d.ts +34 -0
- package/dist/engine.js +11 -0
- package/dist/engine.js.map +1 -0
- package/dist/engine.mjs +9 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +1652 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1637 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node.d.mts +26 -0
- package/dist/node.d.ts +26 -0
- package/dist/node.js +972 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +960 -0
- package/dist/node.mjs.map +1 -0
- package/dist/orchestrator-edge.d.mts +243 -0
- package/dist/orchestrator-edge.d.ts +243 -0
- package/dist/orchestrator-edge.js +1076 -0
- package/dist/orchestrator-edge.js.map +1 -0
- package/dist/orchestrator-edge.mjs +1065 -0
- package/dist/orchestrator-edge.mjs.map +1 -0
- package/dist/orchestrator.d.mts +50 -0
- package/dist/orchestrator.d.ts +50 -0
- package/dist/orchestrator.js +1185 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/orchestrator.mjs +1172 -0
- package/dist/orchestrator.mjs.map +1 -0
- package/dist/rules-detector-DjbTJ1-Q.d.mts +470 -0
- package/dist/rules-detector-DjbTJ1-Q.d.ts +470 -0
- package/dist/static-loader-C1hUlksK.d.ts +72 -0
- package/dist/static-loader-Ds4iNw7c.d.mts +72 -0
- package/dist/types-D0j85fF0.d.mts +163 -0
- package/dist/types-D0j85fF0.d.ts +163 -0
- package/package.json +141 -0
- package/wasm/agentshield_wasm.d.ts +485 -0
- package/wasm/agentshield_wasm.js +1551 -0
- package/wasm/agentshield_wasm_bg.wasm +0 -0
- package/wasm/agentshield_wasm_bg.wasm.d.ts +97 -0
- package/wasm/kya-os-engine/kya_os_engine.d.ts +24 -0
- package/wasm/kya-os-engine/kya_os_engine.js +517 -0
- package/wasm/kya-os-engine/kya_os_engine_bg.wasm +0 -0
- package/wasm/kya-os-engine/kya_os_engine_bg.wasm.d.ts +8 -0
- package/wasm/kya-os-engine-web/kya_os_engine.d.ts +56 -0
- package/wasm/kya-os-engine-web/kya_os_engine.js +574 -0
- package/wasm/kya-os-engine-web/kya_os_engine_bg.wasm +0 -0
- package/wasm/kya-os-engine-web/kya_os_engine_bg.wasm.d.ts +8 -0
- package/wasm/package.json +30 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
export { initEngineEdge } from './engine-edge.js';
|
|
2
|
+
import { E as EnforcementMode, A as AgentRequest, V as VerifyResult } from './types-D0j85fF0.js';
|
|
3
|
+
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter, ClockAdapter } from './adapters.js';
|
|
4
|
+
import '@kya-os/checkpoint-shared';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Orchestrator-layer types — Phase C, host-side only.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here crosses the WASM boundary. The engine ABI types live
|
|
10
|
+
* in `../types.ts`; the adapter interfaces live in
|
|
11
|
+
* `../adapters/index.ts`. This file is the host-wrapper-facing
|
|
12
|
+
* surface — what Phase D (Next.js) and Phase E (Express) import.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Framework-agnostic HTTP request shape.
|
|
17
|
+
*
|
|
18
|
+
* Next.js / Express / Cloudflare Workers / Hono adapters marshal
|
|
19
|
+
* their native request type into this shape before calling
|
|
20
|
+
* `verifyRequest`. The shape is intentionally minimal — only what
|
|
21
|
+
* the engine needs to make a verdict.
|
|
22
|
+
*/
|
|
23
|
+
interface IncomingHttpLike {
|
|
24
|
+
method: string;
|
|
25
|
+
/** Path + query string (no scheme + host). */
|
|
26
|
+
url: string;
|
|
27
|
+
headers: Record<string, string | string[] | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Parsed body if the framework has already parsed it (Next.js
|
|
30
|
+
* with `await req.json()`, Express with `body-parser`). Falsy if
|
|
31
|
+
* the caller hasn't materialised the body — the orchestrator
|
|
32
|
+
* treats that as "no MCP-I envelope present" and routes to
|
|
33
|
+
* PlainHttp.
|
|
34
|
+
*/
|
|
35
|
+
body?: Buffer | string | object | null;
|
|
36
|
+
/** Client IP if the framework surfaces one (Express `req.ip`). */
|
|
37
|
+
remoteAddress?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Options the host wrapper passes per-`verifyRequest`-construction.
|
|
41
|
+
* The five adapters + clock + tenant identifier + enforcement mode.
|
|
42
|
+
*/
|
|
43
|
+
interface VerifyRequestOpts {
|
|
44
|
+
didResolver: DidResolverAdapter;
|
|
45
|
+
statusListCache: StatusListCacheAdapter;
|
|
46
|
+
reputationOracle: ReputationOracleAdapter;
|
|
47
|
+
policyEvaluator: PolicyEvaluatorAdapter;
|
|
48
|
+
clock: ClockAdapter;
|
|
49
|
+
/** Tenant identifier — the host customer this request targets. */
|
|
50
|
+
tenantHost: string;
|
|
51
|
+
enforcementMode: EnforcementMode;
|
|
52
|
+
/** Returned to the PolicyEvaluator when the request has no agent DID. Default 1.0. */
|
|
53
|
+
reputationBaseline?: number;
|
|
54
|
+
/**
|
|
55
|
+
* **Envelope-1 (#2537) coordination flag.** Pre-Envelope-1 the TS
|
|
56
|
+
* bouncer ships MCP-I proofs as `{protected,payload,signature}` JSON
|
|
57
|
+
* in a `KYA-Delegation` header. Post-Envelope-1 they ship compact
|
|
58
|
+
* JWS in `_meta.proof.jws` of the body. When this flag is true the
|
|
59
|
+
* orchestrator also accepts the legacy header form. **Default off.**
|
|
60
|
+
* Delete this flag once Envelope-1 ships end-to-end.
|
|
61
|
+
*/
|
|
62
|
+
legacyEnvelopeFallback?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Argus URL — passed only so the orchestrator can detect "Argus
|
|
65
|
+
* not configured" at construction time and log the one-shot
|
|
66
|
+
* warning. The actual reputation fetch goes through `reputationOracle`.
|
|
67
|
+
*/
|
|
68
|
+
argusUrl?: string;
|
|
69
|
+
/** Injectable for the once-only Argus configuration warning. */
|
|
70
|
+
logger?: (msg: string) => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Transport-agnostic response shape `renderDecisionAsResponse`
|
|
74
|
+
* produces. Host wrappers adapt this to their framework's response
|
|
75
|
+
* type (NextResponse / Express `res` / Cloudflare Response).
|
|
76
|
+
*
|
|
77
|
+
* `status === null` means "pass through" — the request continues to
|
|
78
|
+
* the next handler. Happens in two cases:
|
|
79
|
+
* 1. `Decision::Permit` (no block in Enforce mode).
|
|
80
|
+
* 2. **Any verdict in Observe mode** — Observe never blocks, but
|
|
81
|
+
* the response headers still carry the would-have-been verdict.
|
|
82
|
+
*/
|
|
83
|
+
interface RenderedResponse {
|
|
84
|
+
status: number | null;
|
|
85
|
+
headers: Record<string, string>;
|
|
86
|
+
body?: string | object;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* HTTP-to-`AgentRequest` translator — Phase C.1.
|
|
91
|
+
*
|
|
92
|
+
* Detects which engine protocol the request belongs to and builds
|
|
93
|
+
* the typed `AgentRequest` the WASM consumes. Conservative
|
|
94
|
+
* detection: never escalates an ambiguous request into a higher
|
|
95
|
+
* verification tier. Anonymous PlainHttp is the default.
|
|
96
|
+
*
|
|
97
|
+
* **What this layer parses and what it doesn't.** It parses *only
|
|
98
|
+
* what's needed to drive conditional pre-fetch* — header presence,
|
|
99
|
+
* the MCP-I envelope's payload segment (to extract `iss` + `sub` +
|
|
100
|
+
* optional credentialStatus URL). It does **not** verify
|
|
101
|
+
* signatures, decode VC chains for revocation bits, or evaluate
|
|
102
|
+
* scope. Those live in the engine (H-1's parser + Stages 2-5).
|
|
103
|
+
*
|
|
104
|
+
* **Buffer-portability note.** This module uses `Buffer.from(...)` and
|
|
105
|
+
* `Buffer.isBuffer(...)` at multiple call sites (the JWS preflight
|
|
106
|
+
* `hasMalformedJwsBody`, both `tryBuildMcpIFromBody` variants, the
|
|
107
|
+
* legacy-header reconstitution path, and `bodyAsBytes`). All of these
|
|
108
|
+
* assume the Node `Buffer` global is available — provided natively by
|
|
109
|
+
* the Node runtime, polyfilled on Vercel Edge, and gated behind
|
|
110
|
+
* `nodejs_compat` on Cloudflare Workers. Bare-Edge and pure-browser
|
|
111
|
+
* embedders would need a `Buffer` polyfill or a refactor to
|
|
112
|
+
* `TextEncoder` / `Uint8Array.from`. Tracked as a follow-up since
|
|
113
|
+
* Phase D's Vercel Node + Vercel Edge targets are both covered today.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
interface BuildAgentRequestOpts {
|
|
117
|
+
/** See `VerifyRequestOpts.legacyEnvelopeFallback`. */
|
|
118
|
+
legacyEnvelopeFallback?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Translate an HTTP-like request into the engine's `AgentRequest`.
|
|
122
|
+
*
|
|
123
|
+
* Detection order (conservative — never escalate ambiguous input):
|
|
124
|
+
* 1. MCP-I L2 detached proof in `_meta.proof.jws` (spec form).
|
|
125
|
+
* 2. (Legacy, opt-in) MCP-I in `KYA-Delegation` header
|
|
126
|
+
* (Envelope-1 #2537 transition window only).
|
|
127
|
+
* 3. RFC 9421 HTTP Message Signatures (`Signature-Input` header).
|
|
128
|
+
* 4. PlainHttp (default — anonymous traffic).
|
|
129
|
+
*/
|
|
130
|
+
declare function buildAgentRequest(req: IncomingHttpLike, opts?: BuildAgentRequestOpts): AgentRequest;
|
|
131
|
+
/**
|
|
132
|
+
* Preflight check — does the request body carry a `_meta.proof.jws`
|
|
133
|
+
* string that `parseJwsPayloadStruct` cannot project into a typed
|
|
134
|
+
* `McpIPayload`?
|
|
135
|
+
*
|
|
136
|
+
* The caller declared intent (an MCP-I envelope) by including the
|
|
137
|
+
* JWS field; structural failure to extract the payload means the
|
|
138
|
+
* envelope is malformed, not absent. Without this preflight, the
|
|
139
|
+
* orchestrator would silently fall through to PlainHttp — pre-#2560
|
|
140
|
+
* that happened to also Block (engine returned `Block(ParseError)`
|
|
141
|
+
* for every PlainHttp), so the regression was invisible; post-#2560
|
|
142
|
+
* the engine's Stage 1 + stub policy returns `Permit` for anonymous
|
|
143
|
+
* PlainHttp and tampered envelopes would be silently accepted.
|
|
144
|
+
*
|
|
145
|
+
* Returns `true` when the orchestrator should synthesize
|
|
146
|
+
* `Block(ParseError)` BEFORE calling `buildAgentRequest`.
|
|
147
|
+
*/
|
|
148
|
+
declare function hasMalformedJwsBody(req: IncomingHttpLike): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Issuer DID — Stage 1 (identity resolution) targets this. `null`
|
|
151
|
+
* for PlainHttp (anonymous → no DID to resolve).
|
|
152
|
+
*/
|
|
153
|
+
declare function extractIssuer(request: AgentRequest): string | null;
|
|
154
|
+
/**
|
|
155
|
+
* Agent DID — used by ReputationOracle. Defaults to `payload.sub`
|
|
156
|
+
* for MCP-I (subject = the agent the proof is *about*).
|
|
157
|
+
*/
|
|
158
|
+
declare function extractAgentDid(request: AgentRequest): string | null;
|
|
159
|
+
/**
|
|
160
|
+
* Status-list URL for revocation pre-fetch. Pulled from the JWS
|
|
161
|
+
* payload's `vc.credentialStatus.id` (W3C VC Data Model 1.1).
|
|
162
|
+
* `null` when the envelope is L1 (no VC chain) — Stage 3 will skip.
|
|
163
|
+
*/
|
|
164
|
+
declare function extractCredentialStatusUrl(request: AgentRequest): string | null;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Transport-agnostic `Decision` → HTTP renderer — Phase C.3.
|
|
168
|
+
*
|
|
169
|
+
* Translates a `VerifyResult` into a framework-neutral
|
|
170
|
+
* `{ status, headers, body }` shape. Phase D (Next.js) adapts this
|
|
171
|
+
* to `NextResponse`; Phase E (Express) adapts it to `res.status().set().send()`.
|
|
172
|
+
* One source of truth for the verdict→HTTP mapping.
|
|
173
|
+
*
|
|
174
|
+
* Mapping table (§ 4.5 of Phase C kickoff):
|
|
175
|
+
*
|
|
176
|
+
* | Decision | HTTP | Notes |
|
|
177
|
+
* |-----------------------------------|------|-----------------------------------------|
|
|
178
|
+
* | Permit | null | Pass through to next handler |
|
|
179
|
+
* | Block(Unauthenticated) | 401 | WWW-Authenticate header |
|
|
180
|
+
* | Block(InvalidSignature) | 403 | |
|
|
181
|
+
* | Block(Revoked) | 403 | |
|
|
182
|
+
* | Block(Expired) | 401 | Refresh-the-credential semantics |
|
|
183
|
+
* | Block(OutOfScope) | 403 | Body carries requested + granted |
|
|
184
|
+
* | Block(LowReputation) | 403 | Body carries score + threshold |
|
|
185
|
+
* | Block(PolicyDenied) | 403 | Body carries detail |
|
|
186
|
+
* | Block(ParseError) | 400 | Body carries detail |
|
|
187
|
+
* | Challenge | 401 | Body carries ChallengeParams |
|
|
188
|
+
* | Redirect | 302 | Location header |
|
|
189
|
+
* | Instruct | 422 | application/problem+json body |
|
|
190
|
+
*
|
|
191
|
+
* Observe mode overrides: every verdict renders as `status: null`
|
|
192
|
+
* (pass through) with an `X-Checkpoint-Would-Have-Been` header
|
|
193
|
+
* carrying the verdict kind, plus the standard attribution headers.
|
|
194
|
+
*
|
|
195
|
+
* Every response carries the Phase 0.1 attribution headers:
|
|
196
|
+
* `X-Checkpoint-Engine`, `X-Checkpoint-Engine-Version`, and
|
|
197
|
+
* (when present) `X-Checkpoint-Ruleset-Hash`.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
declare function renderDecisionAsResponse(result: VerifyResult): RenderedResponse;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* `verifyRequestEdge` async-init orchestrator — Edge-WASM-2 (folded into
|
|
204
|
+
* Phase D's PR).
|
|
205
|
+
*
|
|
206
|
+
* Mirror of [[./verify-request.ts]] for edge runtimes. Differs in only
|
|
207
|
+
* three places:
|
|
208
|
+
*
|
|
209
|
+
* 1. Imports `engineVerifyEdge` + `initEngineEdge` from `../edge`
|
|
210
|
+
* instead of `engineVerify` from `../index` (Node target).
|
|
211
|
+
* 2. Awaits `initEngineEdge()` before the engine call — async-init
|
|
212
|
+
* pattern required by the `--target web` wasm-bindgen build.
|
|
213
|
+
* 3. The final engine call is `await engineVerifyEdge(...)` rather
|
|
214
|
+
* than the synchronous `engineVerify(...)`.
|
|
215
|
+
*
|
|
216
|
+
* **The two files MUST stay in sync.** Any change to verify-request.ts
|
|
217
|
+
* (new adapter, new error-classification rule, new ContextSpec field)
|
|
218
|
+
* MUST be mirrored here. The cross-target parity test in
|
|
219
|
+
* [[__tests__/verify-request-parity.test.ts]] guards the verdict-shape
|
|
220
|
+
* invariant — both orchestrators must produce identical
|
|
221
|
+
* `VerifyResult.decision` / `engineInfo.name` on identical inputs.
|
|
222
|
+
*
|
|
223
|
+
* Cedar-1 forward-compat: same seam as the Node variant — step (5)
|
|
224
|
+
* (tenant policy eval) is the only place the PolicyEvaluator
|
|
225
|
+
* interface gets exercised. When Cedar-1 swaps implementations, this
|
|
226
|
+
* orchestrator does not change.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Factory — constructs a `verifyRequestEdge` closure that remembers the
|
|
231
|
+
* one-shot Argus-not-configured warning state. Use this when the
|
|
232
|
+
* host wrapper wants the startup log; call `verifyRequestEdge` directly
|
|
233
|
+
* (the loose function below) if you don't.
|
|
234
|
+
*/
|
|
235
|
+
declare function makeVerifyRequestEdge(opts: VerifyRequestOpts): (req: IncomingHttpLike) => Promise<VerifyResult>;
|
|
236
|
+
/**
|
|
237
|
+
* Single-shot async entry. Use [`makeVerifyRequestEdge`] in long-lived
|
|
238
|
+
* hosts (so the Argus warning is one-shot per process); use this
|
|
239
|
+
* loose form in tests + one-off invocations.
|
|
240
|
+
*/
|
|
241
|
+
declare function verifyRequestEdge(req: IncomingHttpLike, opts: VerifyRequestOpts): Promise<VerifyResult>;
|
|
242
|
+
|
|
243
|
+
export { type BuildAgentRequestOpts, type IncomingHttpLike, type RenderedResponse, type VerifyRequestOpts, buildAgentRequest, extractAgentDid, extractCredentialStatusUrl, extractIssuer, hasMalformedJwsBody, makeVerifyRequestEdge, renderDecisionAsResponse, verifyRequestEdge };
|