@kya-os/checkpoint-wasm-runtime 1.1.1 → 1.1.2
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 +55 -0
- package/dist/edge.d.mts +531 -4
- package/dist/edge.d.ts +531 -4
- package/dist/engine.js +11 -0
- package/dist/engine.mjs +17 -1
- package/dist/index.d.mts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +2 -0
- package/dist/node.d.mts +2 -3
- package/dist/node.d.ts +2 -3
- package/dist/orchestrator-edge.d.mts +199 -5
- package/dist/orchestrator-edge.d.ts +199 -5
- package/dist/orchestrator-node.d.mts +313 -5
- package/dist/orchestrator-node.d.ts +313 -5
- package/dist/orchestrator-node.js +23 -0
- package/dist/orchestrator-node.mjs +29 -1
- package/dist/orchestrator.d.mts +86 -6
- package/dist/orchestrator.d.ts +86 -6
- package/dist/orchestrator.js +29 -2
- package/dist/orchestrator.mjs +31 -1
- package/dist/{rules-detector-DjbTJ1-Q.d.mts → rules-detector-ZIKHN-_y.d.mts} +63 -1
- package/dist/{rules-detector-DjbTJ1-Q.d.ts → rules-detector-ZIKHN-_y.d.ts} +63 -1
- package/package.json +1 -1
- package/dist/dynamic-loader-cS-pUisw.d.ts +0 -65
- package/dist/dynamic-loader-qGJacfEC.d.mts +0 -65
- package/dist/render-decision-C1a-iuiW.d.mts +0 -200
- package/dist/render-decision-Dsjwt96g.d.ts +0 -200
- package/dist/static-loader-C1hUlksK.d.ts +0 -72
- package/dist/static-loader-Ds4iNw7c.d.mts +0 -72
|
@@ -315,6 +315,68 @@ declare class WasmDetector implements IDetector {
|
|
|
315
315
|
private createDefaultResult;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Dynamic WASM Loader for Node.js
|
|
320
|
+
*
|
|
321
|
+
* This loader dynamically loads and compiles WASM at runtime,
|
|
322
|
+
* which is supported in Node.js but NOT in Edge Runtime.
|
|
323
|
+
*
|
|
324
|
+
* Usage:
|
|
325
|
+
* ```typescript
|
|
326
|
+
* import { DynamicWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/node';
|
|
327
|
+
*
|
|
328
|
+
* const loader = new DynamicWasmLoader();
|
|
329
|
+
* const detector = new WasmDetector(loader);
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Dynamic WASM Loader
|
|
335
|
+
*
|
|
336
|
+
* For Node.js environments that support dynamic WASM compilation.
|
|
337
|
+
* Automatically finds and loads the WASM module.
|
|
338
|
+
*/
|
|
339
|
+
declare class DynamicWasmLoader implements IWasmLoader {
|
|
340
|
+
private readonly wasmPath?;
|
|
341
|
+
private bindings;
|
|
342
|
+
private instance;
|
|
343
|
+
private loadPromise;
|
|
344
|
+
/**
|
|
345
|
+
* Create a new DynamicWasmLoader
|
|
346
|
+
* @param wasmPath - Optional custom path to WASM file
|
|
347
|
+
*/
|
|
348
|
+
constructor(wasmPath?: string | undefined);
|
|
349
|
+
/**
|
|
350
|
+
* Load and compile the WASM module
|
|
351
|
+
*/
|
|
352
|
+
load(): Promise<void>;
|
|
353
|
+
private doLoad;
|
|
354
|
+
/**
|
|
355
|
+
* Get the WASM bindings after loading
|
|
356
|
+
*/
|
|
357
|
+
getBindings(): IWasmBindings;
|
|
358
|
+
/**
|
|
359
|
+
* Check if WASM is loaded
|
|
360
|
+
*/
|
|
361
|
+
isLoaded(): boolean;
|
|
362
|
+
/**
|
|
363
|
+
* Get the loading strategy name
|
|
364
|
+
*/
|
|
365
|
+
getStrategy(): string;
|
|
366
|
+
/**
|
|
367
|
+
* Create wasm-bindgen required imports
|
|
368
|
+
*/
|
|
369
|
+
private createWasmBindgenImports;
|
|
370
|
+
/**
|
|
371
|
+
* Create bindings wrapper from WASM exports
|
|
372
|
+
*/
|
|
373
|
+
private createBindings;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Create a dynamic loader
|
|
377
|
+
*/
|
|
378
|
+
declare function createDynamicLoader(wasmPath?: string): DynamicWasmLoader;
|
|
379
|
+
|
|
318
380
|
/**
|
|
319
381
|
* Policy Loader
|
|
320
382
|
*
|
|
@@ -467,4 +529,4 @@ declare class RulesDetector implements IDetector {
|
|
|
467
529
|
*/
|
|
468
530
|
declare function createRulesDetector(): RulesDetector;
|
|
469
531
|
|
|
470
|
-
export { CONFIDENCE as C, type DetectionClass as D, type ForgeabilityRisk as F, type
|
|
532
|
+
export { CONFIDENCE as C, type DetectionClass as D, type ForgeabilityRisk as F, type IDetector as I, PolicyLoader as P, RulesDetector as R, type VerificationMethod as V, WasmDetector as W, type IDetectorOptions as a, type IDetectionInput as b, DynamicWasmLoader as c, type ICustomerPolicy as d, type IDetectedAgent as e, type IDetectionResult as f, type IPolicyLoader as g, type IWasmLoader as h, createDynamicLoader as i, createPolicyLoader as j, createRulesDetector as k, type IWasmBindings as l, type IPathRule as m, PolicyLoadError as n, type PolicyLoaderConfig as o };
|
package/package.json
CHANGED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { i as IWasmLoader, h as IWasmBindings } from './rules-detector-DjbTJ1-Q.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Dynamic WASM Loader for Node.js
|
|
5
|
-
*
|
|
6
|
-
* This loader dynamically loads and compiles WASM at runtime,
|
|
7
|
-
* which is supported in Node.js but NOT in Edge Runtime.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { DynamicWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/node';
|
|
12
|
-
*
|
|
13
|
-
* const loader = new DynamicWasmLoader();
|
|
14
|
-
* const detector = new WasmDetector(loader);
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Dynamic WASM Loader
|
|
20
|
-
*
|
|
21
|
-
* For Node.js environments that support dynamic WASM compilation.
|
|
22
|
-
* Automatically finds and loads the WASM module.
|
|
23
|
-
*/
|
|
24
|
-
declare class DynamicWasmLoader implements IWasmLoader {
|
|
25
|
-
private readonly wasmPath?;
|
|
26
|
-
private bindings;
|
|
27
|
-
private instance;
|
|
28
|
-
private loadPromise;
|
|
29
|
-
/**
|
|
30
|
-
* Create a new DynamicWasmLoader
|
|
31
|
-
* @param wasmPath - Optional custom path to WASM file
|
|
32
|
-
*/
|
|
33
|
-
constructor(wasmPath?: string | undefined);
|
|
34
|
-
/**
|
|
35
|
-
* Load and compile the WASM module
|
|
36
|
-
*/
|
|
37
|
-
load(): Promise<void>;
|
|
38
|
-
private doLoad;
|
|
39
|
-
/**
|
|
40
|
-
* Get the WASM bindings after loading
|
|
41
|
-
*/
|
|
42
|
-
getBindings(): IWasmBindings;
|
|
43
|
-
/**
|
|
44
|
-
* Check if WASM is loaded
|
|
45
|
-
*/
|
|
46
|
-
isLoaded(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Get the loading strategy name
|
|
49
|
-
*/
|
|
50
|
-
getStrategy(): string;
|
|
51
|
-
/**
|
|
52
|
-
* Create wasm-bindgen required imports
|
|
53
|
-
*/
|
|
54
|
-
private createWasmBindgenImports;
|
|
55
|
-
/**
|
|
56
|
-
* Create bindings wrapper from WASM exports
|
|
57
|
-
*/
|
|
58
|
-
private createBindings;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Create a dynamic loader
|
|
62
|
-
*/
|
|
63
|
-
declare function createDynamicLoader(wasmPath?: string): DynamicWasmLoader;
|
|
64
|
-
|
|
65
|
-
export { DynamicWasmLoader as D, createDynamicLoader as c };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { i as IWasmLoader, h as IWasmBindings } from './rules-detector-DjbTJ1-Q.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Dynamic WASM Loader for Node.js
|
|
5
|
-
*
|
|
6
|
-
* This loader dynamically loads and compiles WASM at runtime,
|
|
7
|
-
* which is supported in Node.js but NOT in Edge Runtime.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { DynamicWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/node';
|
|
12
|
-
*
|
|
13
|
-
* const loader = new DynamicWasmLoader();
|
|
14
|
-
* const detector = new WasmDetector(loader);
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Dynamic WASM Loader
|
|
20
|
-
*
|
|
21
|
-
* For Node.js environments that support dynamic WASM compilation.
|
|
22
|
-
* Automatically finds and loads the WASM module.
|
|
23
|
-
*/
|
|
24
|
-
declare class DynamicWasmLoader implements IWasmLoader {
|
|
25
|
-
private readonly wasmPath?;
|
|
26
|
-
private bindings;
|
|
27
|
-
private instance;
|
|
28
|
-
private loadPromise;
|
|
29
|
-
/**
|
|
30
|
-
* Create a new DynamicWasmLoader
|
|
31
|
-
* @param wasmPath - Optional custom path to WASM file
|
|
32
|
-
*/
|
|
33
|
-
constructor(wasmPath?: string | undefined);
|
|
34
|
-
/**
|
|
35
|
-
* Load and compile the WASM module
|
|
36
|
-
*/
|
|
37
|
-
load(): Promise<void>;
|
|
38
|
-
private doLoad;
|
|
39
|
-
/**
|
|
40
|
-
* Get the WASM bindings after loading
|
|
41
|
-
*/
|
|
42
|
-
getBindings(): IWasmBindings;
|
|
43
|
-
/**
|
|
44
|
-
* Check if WASM is loaded
|
|
45
|
-
*/
|
|
46
|
-
isLoaded(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Get the loading strategy name
|
|
49
|
-
*/
|
|
50
|
-
getStrategy(): string;
|
|
51
|
-
/**
|
|
52
|
-
* Create wasm-bindgen required imports
|
|
53
|
-
*/
|
|
54
|
-
private createWasmBindgenImports;
|
|
55
|
-
/**
|
|
56
|
-
* Create bindings wrapper from WASM exports
|
|
57
|
-
*/
|
|
58
|
-
private createBindings;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Create a dynamic loader
|
|
62
|
-
*/
|
|
63
|
-
declare function createDynamicLoader(wasmPath?: string): DynamicWasmLoader;
|
|
64
|
-
|
|
65
|
-
export { DynamicWasmLoader as D, createDynamicLoader as c };
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { E as EnforcementMode, A as AgentRequest, V as VerifyResult } from './types-D0j85fF0.mjs';
|
|
2
|
-
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter, ClockAdapter } from './adapters.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Orchestrator-layer types — Phase C, host-side only.
|
|
6
|
-
*
|
|
7
|
-
* Nothing here crosses the WASM boundary. The engine ABI types live
|
|
8
|
-
* in `../types.ts`; the adapter interfaces live in
|
|
9
|
-
* `../adapters/index.ts`. This file is the host-wrapper-facing
|
|
10
|
-
* surface — what Phase D (Next.js) and Phase E (Express) import.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Framework-agnostic HTTP request shape.
|
|
15
|
-
*
|
|
16
|
-
* Next.js / Express / Cloudflare Workers / Hono adapters marshal
|
|
17
|
-
* their native request type into this shape before calling
|
|
18
|
-
* `verifyRequest`. The shape is intentionally minimal — only what
|
|
19
|
-
* the engine needs to make a verdict.
|
|
20
|
-
*/
|
|
21
|
-
interface IncomingHttpLike {
|
|
22
|
-
method: string;
|
|
23
|
-
/** Path + query string (no scheme + host). */
|
|
24
|
-
url: string;
|
|
25
|
-
headers: Record<string, string | string[] | undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Parsed body if the framework has already parsed it (Next.js
|
|
28
|
-
* with `await req.json()`, Express with `body-parser`). Falsy if
|
|
29
|
-
* the caller hasn't materialised the body — the orchestrator
|
|
30
|
-
* treats that as "no MCP-I envelope present" and routes to
|
|
31
|
-
* PlainHttp.
|
|
32
|
-
*/
|
|
33
|
-
body?: Buffer | string | object | null;
|
|
34
|
-
/** Client IP if the framework surfaces one (Express `req.ip`). */
|
|
35
|
-
remoteAddress?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Options the host wrapper passes per-`verifyRequest`-construction.
|
|
39
|
-
* The five adapters + clock + tenant identifier + enforcement mode.
|
|
40
|
-
*/
|
|
41
|
-
interface VerifyRequestOpts {
|
|
42
|
-
didResolver: DidResolverAdapter;
|
|
43
|
-
statusListCache: StatusListCacheAdapter;
|
|
44
|
-
reputationOracle: ReputationOracleAdapter;
|
|
45
|
-
policyEvaluator: PolicyEvaluatorAdapter;
|
|
46
|
-
clock: ClockAdapter;
|
|
47
|
-
/** Tenant identifier — the host customer this request targets. */
|
|
48
|
-
tenantHost: string;
|
|
49
|
-
enforcementMode: EnforcementMode;
|
|
50
|
-
/** Returned to the PolicyEvaluator when the request has no agent DID. Default 1.0. */
|
|
51
|
-
reputationBaseline?: number;
|
|
52
|
-
/**
|
|
53
|
-
* **Envelope-1 (#2537) coordination flag.** Pre-Envelope-1 the TS
|
|
54
|
-
* bouncer ships MCP-I proofs as `{protected,payload,signature}` JSON
|
|
55
|
-
* in a `KYA-Delegation` header. Post-Envelope-1 they ship compact
|
|
56
|
-
* JWS in `_meta.proof.jws` of the body. When this flag is true the
|
|
57
|
-
* orchestrator also accepts the legacy header form. **Default off.**
|
|
58
|
-
* Delete this flag once Envelope-1 ships end-to-end.
|
|
59
|
-
*/
|
|
60
|
-
legacyEnvelopeFallback?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Argus URL — passed only so the orchestrator can detect "Argus
|
|
63
|
-
* not configured" at construction time and log the one-shot
|
|
64
|
-
* warning. The actual reputation fetch goes through `reputationOracle`.
|
|
65
|
-
*/
|
|
66
|
-
argusUrl?: string;
|
|
67
|
-
/** Injectable for the once-only Argus configuration warning. */
|
|
68
|
-
logger?: (msg: string) => void;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Transport-agnostic response shape `renderDecisionAsResponse`
|
|
72
|
-
* produces. Host wrappers adapt this to their framework's response
|
|
73
|
-
* type (NextResponse / Express `res` / Cloudflare Response).
|
|
74
|
-
*
|
|
75
|
-
* `status === null` means "pass through" — the request continues to
|
|
76
|
-
* the next handler. Happens in two cases:
|
|
77
|
-
* 1. `Decision::Permit` (no block in Enforce mode).
|
|
78
|
-
* 2. **Any verdict in Observe mode** — Observe never blocks, but
|
|
79
|
-
* the response headers still carry the would-have-been verdict.
|
|
80
|
-
*/
|
|
81
|
-
interface RenderedResponse {
|
|
82
|
-
status: number | null;
|
|
83
|
-
headers: Record<string, string>;
|
|
84
|
-
body?: string | object;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* HTTP-to-`AgentRequest` translator — Phase C.1.
|
|
89
|
-
*
|
|
90
|
-
* Detects which engine protocol the request belongs to and builds
|
|
91
|
-
* the typed `AgentRequest` the WASM consumes. Conservative
|
|
92
|
-
* detection: never escalates an ambiguous request into a higher
|
|
93
|
-
* verification tier. Anonymous PlainHttp is the default.
|
|
94
|
-
*
|
|
95
|
-
* **What this layer parses and what it doesn't.** It parses *only
|
|
96
|
-
* what's needed to drive conditional pre-fetch* — header presence,
|
|
97
|
-
* the MCP-I envelope's payload segment (to extract `iss` + `sub` +
|
|
98
|
-
* optional credentialStatus URL). It does **not** verify
|
|
99
|
-
* signatures, decode VC chains for revocation bits, or evaluate
|
|
100
|
-
* scope. Those live in the engine (H-1's parser + Stages 2-5).
|
|
101
|
-
*
|
|
102
|
-
* **Buffer-portability note.** This module uses `Buffer.from(...)` and
|
|
103
|
-
* `Buffer.isBuffer(...)` at multiple call sites (the JWS preflight
|
|
104
|
-
* `hasMalformedJwsBody`, both `tryBuildMcpIFromBody` variants, the
|
|
105
|
-
* legacy-header reconstitution path, and `bodyAsBytes`). All of these
|
|
106
|
-
* assume the Node `Buffer` global is available — provided natively by
|
|
107
|
-
* the Node runtime, polyfilled on Vercel Edge, and gated behind
|
|
108
|
-
* `nodejs_compat` on Cloudflare Workers. Bare-Edge and pure-browser
|
|
109
|
-
* embedders would need a `Buffer` polyfill or a refactor to
|
|
110
|
-
* `TextEncoder` / `Uint8Array.from`. Tracked as a follow-up since
|
|
111
|
-
* Phase D's Vercel Node + Vercel Edge targets are both covered today.
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
interface BuildAgentRequestOpts {
|
|
115
|
-
/** See `VerifyRequestOpts.legacyEnvelopeFallback`. */
|
|
116
|
-
legacyEnvelopeFallback?: boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Translate an HTTP-like request into the engine's `AgentRequest`.
|
|
120
|
-
*
|
|
121
|
-
* Detection order (conservative — never escalate ambiguous input):
|
|
122
|
-
* 1. MCP-I L2 detached proof in `_meta.proof.jws` (spec form).
|
|
123
|
-
* 2. (Legacy, opt-in) MCP-I in `KYA-Delegation` header
|
|
124
|
-
* (Envelope-1 #2537 transition window only).
|
|
125
|
-
* 3. RFC 9421 HTTP Message Signatures (`Signature-Input` header).
|
|
126
|
-
* 4. PlainHttp (default — anonymous traffic).
|
|
127
|
-
*/
|
|
128
|
-
declare function buildAgentRequest(req: IncomingHttpLike, opts?: BuildAgentRequestOpts): AgentRequest;
|
|
129
|
-
/**
|
|
130
|
-
* Preflight check — does the request body carry a `_meta.proof.jws`
|
|
131
|
-
* string that `parseJwsPayloadStruct` cannot project into a typed
|
|
132
|
-
* `McpIPayload`?
|
|
133
|
-
*
|
|
134
|
-
* The caller declared intent (an MCP-I envelope) by including the
|
|
135
|
-
* JWS field; structural failure to extract the payload means the
|
|
136
|
-
* envelope is malformed, not absent. Without this preflight, the
|
|
137
|
-
* orchestrator would silently fall through to PlainHttp — pre-#2560
|
|
138
|
-
* that happened to also Block (engine returned `Block(ParseError)`
|
|
139
|
-
* for every PlainHttp), so the regression was invisible; post-#2560
|
|
140
|
-
* the engine's Stage 1 + stub policy returns `Permit` for anonymous
|
|
141
|
-
* PlainHttp and tampered envelopes would be silently accepted.
|
|
142
|
-
*
|
|
143
|
-
* Returns `true` when the orchestrator should synthesize
|
|
144
|
-
* `Block(ParseError)` BEFORE calling `buildAgentRequest`.
|
|
145
|
-
*/
|
|
146
|
-
declare function hasMalformedJwsBody(req: IncomingHttpLike): boolean;
|
|
147
|
-
/**
|
|
148
|
-
* Issuer DID — Stage 1 (identity resolution) targets this. `null`
|
|
149
|
-
* for PlainHttp (anonymous → no DID to resolve).
|
|
150
|
-
*/
|
|
151
|
-
declare function extractIssuer(request: AgentRequest): string | null;
|
|
152
|
-
/**
|
|
153
|
-
* Agent DID — used by ReputationOracle. Defaults to `payload.sub`
|
|
154
|
-
* for MCP-I (subject = the agent the proof is *about*).
|
|
155
|
-
*/
|
|
156
|
-
declare function extractAgentDid(request: AgentRequest): string | null;
|
|
157
|
-
/**
|
|
158
|
-
* Status-list URL for revocation pre-fetch. Pulled from the JWS
|
|
159
|
-
* payload's `vc.credentialStatus.id` (W3C VC Data Model 1.1).
|
|
160
|
-
* `null` when the envelope is L1 (no VC chain) — Stage 3 will skip.
|
|
161
|
-
*/
|
|
162
|
-
declare function extractCredentialStatusUrl(request: AgentRequest): string | null;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Transport-agnostic `Decision` → HTTP renderer — Phase C.3.
|
|
166
|
-
*
|
|
167
|
-
* Translates a `VerifyResult` into a framework-neutral
|
|
168
|
-
* `{ status, headers, body }` shape. Phase D (Next.js) adapts this
|
|
169
|
-
* to `NextResponse`; Phase E (Express) adapts it to `res.status().set().send()`.
|
|
170
|
-
* One source of truth for the verdict→HTTP mapping.
|
|
171
|
-
*
|
|
172
|
-
* Mapping table (§ 4.5 of Phase C kickoff):
|
|
173
|
-
*
|
|
174
|
-
* | Decision | HTTP | Notes |
|
|
175
|
-
* |-----------------------------------|------|-----------------------------------------|
|
|
176
|
-
* | Permit | null | Pass through to next handler |
|
|
177
|
-
* | Block(Unauthenticated) | 401 | WWW-Authenticate header |
|
|
178
|
-
* | Block(InvalidSignature) | 403 | |
|
|
179
|
-
* | Block(Revoked) | 403 | |
|
|
180
|
-
* | Block(Expired) | 401 | Refresh-the-credential semantics |
|
|
181
|
-
* | Block(OutOfScope) | 403 | Body carries requested + granted |
|
|
182
|
-
* | Block(LowReputation) | 403 | Body carries score + threshold |
|
|
183
|
-
* | Block(PolicyDenied) | 403 | Body carries detail |
|
|
184
|
-
* | Block(ParseError) | 400 | Body carries detail |
|
|
185
|
-
* | Challenge | 401 | Body carries ChallengeParams |
|
|
186
|
-
* | Redirect | 302 | Location header |
|
|
187
|
-
* | Instruct | 422 | application/problem+json body |
|
|
188
|
-
*
|
|
189
|
-
* Observe mode overrides: every verdict renders as `status: null`
|
|
190
|
-
* (pass through) with an `X-Checkpoint-Would-Have-Been` header
|
|
191
|
-
* carrying the verdict kind, plus the standard attribution headers.
|
|
192
|
-
*
|
|
193
|
-
* Every response carries the Phase 0.1 attribution headers:
|
|
194
|
-
* `X-Checkpoint-Engine`, `X-Checkpoint-Engine-Version`, and
|
|
195
|
-
* (when present) `X-Checkpoint-Ruleset-Hash`.
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
declare function renderDecisionAsResponse(result: VerifyResult): RenderedResponse;
|
|
199
|
-
|
|
200
|
-
export { type BuildAgentRequestOpts as B, type IncomingHttpLike as I, type RenderedResponse as R, type VerifyRequestOpts as V, extractCredentialStatusUrl as a, buildAgentRequest as b, extractIssuer as c, extractAgentDid as e, hasMalformedJwsBody as h, renderDecisionAsResponse as r };
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { E as EnforcementMode, A as AgentRequest, V as VerifyResult } from './types-D0j85fF0.js';
|
|
2
|
-
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter, ClockAdapter } from './adapters.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Orchestrator-layer types — Phase C, host-side only.
|
|
6
|
-
*
|
|
7
|
-
* Nothing here crosses the WASM boundary. The engine ABI types live
|
|
8
|
-
* in `../types.ts`; the adapter interfaces live in
|
|
9
|
-
* `../adapters/index.ts`. This file is the host-wrapper-facing
|
|
10
|
-
* surface — what Phase D (Next.js) and Phase E (Express) import.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Framework-agnostic HTTP request shape.
|
|
15
|
-
*
|
|
16
|
-
* Next.js / Express / Cloudflare Workers / Hono adapters marshal
|
|
17
|
-
* their native request type into this shape before calling
|
|
18
|
-
* `verifyRequest`. The shape is intentionally minimal — only what
|
|
19
|
-
* the engine needs to make a verdict.
|
|
20
|
-
*/
|
|
21
|
-
interface IncomingHttpLike {
|
|
22
|
-
method: string;
|
|
23
|
-
/** Path + query string (no scheme + host). */
|
|
24
|
-
url: string;
|
|
25
|
-
headers: Record<string, string | string[] | undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Parsed body if the framework has already parsed it (Next.js
|
|
28
|
-
* with `await req.json()`, Express with `body-parser`). Falsy if
|
|
29
|
-
* the caller hasn't materialised the body — the orchestrator
|
|
30
|
-
* treats that as "no MCP-I envelope present" and routes to
|
|
31
|
-
* PlainHttp.
|
|
32
|
-
*/
|
|
33
|
-
body?: Buffer | string | object | null;
|
|
34
|
-
/** Client IP if the framework surfaces one (Express `req.ip`). */
|
|
35
|
-
remoteAddress?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Options the host wrapper passes per-`verifyRequest`-construction.
|
|
39
|
-
* The five adapters + clock + tenant identifier + enforcement mode.
|
|
40
|
-
*/
|
|
41
|
-
interface VerifyRequestOpts {
|
|
42
|
-
didResolver: DidResolverAdapter;
|
|
43
|
-
statusListCache: StatusListCacheAdapter;
|
|
44
|
-
reputationOracle: ReputationOracleAdapter;
|
|
45
|
-
policyEvaluator: PolicyEvaluatorAdapter;
|
|
46
|
-
clock: ClockAdapter;
|
|
47
|
-
/** Tenant identifier — the host customer this request targets. */
|
|
48
|
-
tenantHost: string;
|
|
49
|
-
enforcementMode: EnforcementMode;
|
|
50
|
-
/** Returned to the PolicyEvaluator when the request has no agent DID. Default 1.0. */
|
|
51
|
-
reputationBaseline?: number;
|
|
52
|
-
/**
|
|
53
|
-
* **Envelope-1 (#2537) coordination flag.** Pre-Envelope-1 the TS
|
|
54
|
-
* bouncer ships MCP-I proofs as `{protected,payload,signature}` JSON
|
|
55
|
-
* in a `KYA-Delegation` header. Post-Envelope-1 they ship compact
|
|
56
|
-
* JWS in `_meta.proof.jws` of the body. When this flag is true the
|
|
57
|
-
* orchestrator also accepts the legacy header form. **Default off.**
|
|
58
|
-
* Delete this flag once Envelope-1 ships end-to-end.
|
|
59
|
-
*/
|
|
60
|
-
legacyEnvelopeFallback?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Argus URL — passed only so the orchestrator can detect "Argus
|
|
63
|
-
* not configured" at construction time and log the one-shot
|
|
64
|
-
* warning. The actual reputation fetch goes through `reputationOracle`.
|
|
65
|
-
*/
|
|
66
|
-
argusUrl?: string;
|
|
67
|
-
/** Injectable for the once-only Argus configuration warning. */
|
|
68
|
-
logger?: (msg: string) => void;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Transport-agnostic response shape `renderDecisionAsResponse`
|
|
72
|
-
* produces. Host wrappers adapt this to their framework's response
|
|
73
|
-
* type (NextResponse / Express `res` / Cloudflare Response).
|
|
74
|
-
*
|
|
75
|
-
* `status === null` means "pass through" — the request continues to
|
|
76
|
-
* the next handler. Happens in two cases:
|
|
77
|
-
* 1. `Decision::Permit` (no block in Enforce mode).
|
|
78
|
-
* 2. **Any verdict in Observe mode** — Observe never blocks, but
|
|
79
|
-
* the response headers still carry the would-have-been verdict.
|
|
80
|
-
*/
|
|
81
|
-
interface RenderedResponse {
|
|
82
|
-
status: number | null;
|
|
83
|
-
headers: Record<string, string>;
|
|
84
|
-
body?: string | object;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* HTTP-to-`AgentRequest` translator — Phase C.1.
|
|
89
|
-
*
|
|
90
|
-
* Detects which engine protocol the request belongs to and builds
|
|
91
|
-
* the typed `AgentRequest` the WASM consumes. Conservative
|
|
92
|
-
* detection: never escalates an ambiguous request into a higher
|
|
93
|
-
* verification tier. Anonymous PlainHttp is the default.
|
|
94
|
-
*
|
|
95
|
-
* **What this layer parses and what it doesn't.** It parses *only
|
|
96
|
-
* what's needed to drive conditional pre-fetch* — header presence,
|
|
97
|
-
* the MCP-I envelope's payload segment (to extract `iss` + `sub` +
|
|
98
|
-
* optional credentialStatus URL). It does **not** verify
|
|
99
|
-
* signatures, decode VC chains for revocation bits, or evaluate
|
|
100
|
-
* scope. Those live in the engine (H-1's parser + Stages 2-5).
|
|
101
|
-
*
|
|
102
|
-
* **Buffer-portability note.** This module uses `Buffer.from(...)` and
|
|
103
|
-
* `Buffer.isBuffer(...)` at multiple call sites (the JWS preflight
|
|
104
|
-
* `hasMalformedJwsBody`, both `tryBuildMcpIFromBody` variants, the
|
|
105
|
-
* legacy-header reconstitution path, and `bodyAsBytes`). All of these
|
|
106
|
-
* assume the Node `Buffer` global is available — provided natively by
|
|
107
|
-
* the Node runtime, polyfilled on Vercel Edge, and gated behind
|
|
108
|
-
* `nodejs_compat` on Cloudflare Workers. Bare-Edge and pure-browser
|
|
109
|
-
* embedders would need a `Buffer` polyfill or a refactor to
|
|
110
|
-
* `TextEncoder` / `Uint8Array.from`. Tracked as a follow-up since
|
|
111
|
-
* Phase D's Vercel Node + Vercel Edge targets are both covered today.
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
interface BuildAgentRequestOpts {
|
|
115
|
-
/** See `VerifyRequestOpts.legacyEnvelopeFallback`. */
|
|
116
|
-
legacyEnvelopeFallback?: boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Translate an HTTP-like request into the engine's `AgentRequest`.
|
|
120
|
-
*
|
|
121
|
-
* Detection order (conservative — never escalate ambiguous input):
|
|
122
|
-
* 1. MCP-I L2 detached proof in `_meta.proof.jws` (spec form).
|
|
123
|
-
* 2. (Legacy, opt-in) MCP-I in `KYA-Delegation` header
|
|
124
|
-
* (Envelope-1 #2537 transition window only).
|
|
125
|
-
* 3. RFC 9421 HTTP Message Signatures (`Signature-Input` header).
|
|
126
|
-
* 4. PlainHttp (default — anonymous traffic).
|
|
127
|
-
*/
|
|
128
|
-
declare function buildAgentRequest(req: IncomingHttpLike, opts?: BuildAgentRequestOpts): AgentRequest;
|
|
129
|
-
/**
|
|
130
|
-
* Preflight check — does the request body carry a `_meta.proof.jws`
|
|
131
|
-
* string that `parseJwsPayloadStruct` cannot project into a typed
|
|
132
|
-
* `McpIPayload`?
|
|
133
|
-
*
|
|
134
|
-
* The caller declared intent (an MCP-I envelope) by including the
|
|
135
|
-
* JWS field; structural failure to extract the payload means the
|
|
136
|
-
* envelope is malformed, not absent. Without this preflight, the
|
|
137
|
-
* orchestrator would silently fall through to PlainHttp — pre-#2560
|
|
138
|
-
* that happened to also Block (engine returned `Block(ParseError)`
|
|
139
|
-
* for every PlainHttp), so the regression was invisible; post-#2560
|
|
140
|
-
* the engine's Stage 1 + stub policy returns `Permit` for anonymous
|
|
141
|
-
* PlainHttp and tampered envelopes would be silently accepted.
|
|
142
|
-
*
|
|
143
|
-
* Returns `true` when the orchestrator should synthesize
|
|
144
|
-
* `Block(ParseError)` BEFORE calling `buildAgentRequest`.
|
|
145
|
-
*/
|
|
146
|
-
declare function hasMalformedJwsBody(req: IncomingHttpLike): boolean;
|
|
147
|
-
/**
|
|
148
|
-
* Issuer DID — Stage 1 (identity resolution) targets this. `null`
|
|
149
|
-
* for PlainHttp (anonymous → no DID to resolve).
|
|
150
|
-
*/
|
|
151
|
-
declare function extractIssuer(request: AgentRequest): string | null;
|
|
152
|
-
/**
|
|
153
|
-
* Agent DID — used by ReputationOracle. Defaults to `payload.sub`
|
|
154
|
-
* for MCP-I (subject = the agent the proof is *about*).
|
|
155
|
-
*/
|
|
156
|
-
declare function extractAgentDid(request: AgentRequest): string | null;
|
|
157
|
-
/**
|
|
158
|
-
* Status-list URL for revocation pre-fetch. Pulled from the JWS
|
|
159
|
-
* payload's `vc.credentialStatus.id` (W3C VC Data Model 1.1).
|
|
160
|
-
* `null` when the envelope is L1 (no VC chain) — Stage 3 will skip.
|
|
161
|
-
*/
|
|
162
|
-
declare function extractCredentialStatusUrl(request: AgentRequest): string | null;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Transport-agnostic `Decision` → HTTP renderer — Phase C.3.
|
|
166
|
-
*
|
|
167
|
-
* Translates a `VerifyResult` into a framework-neutral
|
|
168
|
-
* `{ status, headers, body }` shape. Phase D (Next.js) adapts this
|
|
169
|
-
* to `NextResponse`; Phase E (Express) adapts it to `res.status().set().send()`.
|
|
170
|
-
* One source of truth for the verdict→HTTP mapping.
|
|
171
|
-
*
|
|
172
|
-
* Mapping table (§ 4.5 of Phase C kickoff):
|
|
173
|
-
*
|
|
174
|
-
* | Decision | HTTP | Notes |
|
|
175
|
-
* |-----------------------------------|------|-----------------------------------------|
|
|
176
|
-
* | Permit | null | Pass through to next handler |
|
|
177
|
-
* | Block(Unauthenticated) | 401 | WWW-Authenticate header |
|
|
178
|
-
* | Block(InvalidSignature) | 403 | |
|
|
179
|
-
* | Block(Revoked) | 403 | |
|
|
180
|
-
* | Block(Expired) | 401 | Refresh-the-credential semantics |
|
|
181
|
-
* | Block(OutOfScope) | 403 | Body carries requested + granted |
|
|
182
|
-
* | Block(LowReputation) | 403 | Body carries score + threshold |
|
|
183
|
-
* | Block(PolicyDenied) | 403 | Body carries detail |
|
|
184
|
-
* | Block(ParseError) | 400 | Body carries detail |
|
|
185
|
-
* | Challenge | 401 | Body carries ChallengeParams |
|
|
186
|
-
* | Redirect | 302 | Location header |
|
|
187
|
-
* | Instruct | 422 | application/problem+json body |
|
|
188
|
-
*
|
|
189
|
-
* Observe mode overrides: every verdict renders as `status: null`
|
|
190
|
-
* (pass through) with an `X-Checkpoint-Would-Have-Been` header
|
|
191
|
-
* carrying the verdict kind, plus the standard attribution headers.
|
|
192
|
-
*
|
|
193
|
-
* Every response carries the Phase 0.1 attribution headers:
|
|
194
|
-
* `X-Checkpoint-Engine`, `X-Checkpoint-Engine-Version`, and
|
|
195
|
-
* (when present) `X-Checkpoint-Ruleset-Hash`.
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
declare function renderDecisionAsResponse(result: VerifyResult): RenderedResponse;
|
|
199
|
-
|
|
200
|
-
export { type BuildAgentRequestOpts as B, type IncomingHttpLike as I, type RenderedResponse as R, type VerifyRequestOpts as V, extractCredentialStatusUrl as a, buildAgentRequest as b, extractIssuer as c, extractAgentDid as e, hasMalformedJwsBody as h, renderDecisionAsResponse as r };
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { i as IWasmLoader, h as IWasmBindings } from './rules-detector-DjbTJ1-Q.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Static WASM Loader for Edge Runtime
|
|
5
|
-
*
|
|
6
|
-
* This loader is designed for environments that require static WASM imports,
|
|
7
|
-
* such as Vercel Edge Runtime and Cloudflare Workers.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // In your middleware.ts:
|
|
12
|
-
* import wasmModule from '@kya-os/checkpoint-wasm-runtime/wasm?module';
|
|
13
|
-
* import { StaticWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/edge';
|
|
14
|
-
*
|
|
15
|
-
* const loader = new StaticWasmLoader(wasmModule);
|
|
16
|
-
* const detector = new WasmDetector(loader);
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* The `?module` suffix tells bundlers (webpack, esbuild) to import the WASM
|
|
20
|
-
* as a pre-compiled WebAssembly.Module, which is required for Edge Runtime.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Static WASM Loader
|
|
25
|
-
*
|
|
26
|
-
* For Edge Runtime environments that require pre-compiled WASM modules.
|
|
27
|
-
* The consumer must provide the WASM module via a static import with `?module` suffix.
|
|
28
|
-
*
|
|
29
|
-
* This loader uses the wasm-bindgen generated JS glue code to properly
|
|
30
|
-
* initialize the WASM module with all required imports.
|
|
31
|
-
*/
|
|
32
|
-
declare class StaticWasmLoader implements IWasmLoader {
|
|
33
|
-
private readonly wasmModule;
|
|
34
|
-
private bindings;
|
|
35
|
-
private loadPromise;
|
|
36
|
-
private wasmExports;
|
|
37
|
-
/**
|
|
38
|
-
* Create a new StaticWasmLoader
|
|
39
|
-
* @param wasmModule - Pre-compiled WebAssembly.Module from static import
|
|
40
|
-
*/
|
|
41
|
-
constructor(wasmModule: WebAssembly.Module);
|
|
42
|
-
/**
|
|
43
|
-
* Load and instantiate the WASM module
|
|
44
|
-
*/
|
|
45
|
-
load(): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Internal load implementation using wasm-bindgen initSync
|
|
48
|
-
*/
|
|
49
|
-
private doLoad;
|
|
50
|
-
/**
|
|
51
|
-
* Get the WASM bindings after loading
|
|
52
|
-
*/
|
|
53
|
-
getBindings(): IWasmBindings;
|
|
54
|
-
/**
|
|
55
|
-
* Check if WASM is loaded
|
|
56
|
-
*/
|
|
57
|
-
isLoaded(): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Get the loading strategy name
|
|
60
|
-
*/
|
|
61
|
-
getStrategy(): string;
|
|
62
|
-
/**
|
|
63
|
-
* Create bindings wrapper using wasm-bindgen exports
|
|
64
|
-
*/
|
|
65
|
-
private createBindings;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Create a static loader with validation
|
|
69
|
-
*/
|
|
70
|
-
declare function createStaticLoader(wasmModule: WebAssembly.Module): StaticWasmLoader;
|
|
71
|
-
|
|
72
|
-
export { StaticWasmLoader as S, createStaticLoader as c };
|