@kya-os/checkpoint-wasm-runtime 1.1.1 → 1.1.3
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 +116 -0
- package/dist/edge.d.mts +531 -4
- package/dist/edge.d.ts +531 -4
- package/dist/edge.js +1 -1
- package/dist/edge.mjs +2 -2
- package/dist/engine.js +11 -0
- package/dist/engine.mjs +22 -4
- package/dist/index.d.mts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +3 -1
- package/dist/index.mjs +5 -2
- package/dist/node.d.mts +2 -3
- package/dist/node.d.ts +2 -3
- package/dist/node.js +1 -1
- package/dist/node.mjs +5 -2
- 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 +34 -4
- package/dist/orchestrator.d.mts +86 -6
- package/dist/orchestrator.d.ts +86 -6
- package/dist/orchestrator.js +29 -2
- package/dist/orchestrator.mjs +36 -4
- 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
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CONFIDENCE, D as DetectionClass, F as ForgeabilityRisk,
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { h as IWasmLoader, l as IWasmBindings, a as IDetectorOptions, I as IDetector } from './rules-detector-ZIKHN-_y.mjs';
|
|
2
|
+
export { C as CONFIDENCE, D as DetectionClass, c as DynamicWasmLoader, F as ForgeabilityRisk, d as ICustomerPolicy, e as IDetectedAgent, b as IDetectionInput, f as IDetectionResult, m as IPathRule, g as IPolicyLoader, n as PolicyLoadError, P as PolicyLoader, o as PolicyLoaderConfig, R as RulesDetector, V as VerificationMethod, W as WasmDetector, i as createDynamicLoader, j as createPolicyLoader, k as createRulesDetector } from './rules-detector-ZIKHN-_y.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Static WASM Loader for Edge Runtime
|
|
6
|
+
*
|
|
7
|
+
* This loader is designed for environments that require static WASM imports,
|
|
8
|
+
* such as Vercel Edge Runtime and Cloudflare Workers.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // In your middleware.ts:
|
|
13
|
+
* import wasmModule from '@kya-os/checkpoint-wasm-runtime/wasm?module';
|
|
14
|
+
* import { StaticWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/edge';
|
|
15
|
+
*
|
|
16
|
+
* const loader = new StaticWasmLoader(wasmModule);
|
|
17
|
+
* const detector = new WasmDetector(loader);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The `?module` suffix tells bundlers (webpack, esbuild) to import the WASM
|
|
21
|
+
* as a pre-compiled WebAssembly.Module, which is required for Edge Runtime.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Static WASM Loader
|
|
26
|
+
*
|
|
27
|
+
* For Edge Runtime environments that require pre-compiled WASM modules.
|
|
28
|
+
* The consumer must provide the WASM module via a static import with `?module` suffix.
|
|
29
|
+
*
|
|
30
|
+
* This loader uses the wasm-bindgen generated JS glue code to properly
|
|
31
|
+
* initialize the WASM module with all required imports.
|
|
32
|
+
*/
|
|
33
|
+
declare class StaticWasmLoader implements IWasmLoader {
|
|
34
|
+
private readonly wasmModule;
|
|
35
|
+
private bindings;
|
|
36
|
+
private loadPromise;
|
|
37
|
+
private wasmExports;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new StaticWasmLoader
|
|
40
|
+
* @param wasmModule - Pre-compiled WebAssembly.Module from static import
|
|
41
|
+
*/
|
|
42
|
+
constructor(wasmModule: WebAssembly.Module);
|
|
43
|
+
/**
|
|
44
|
+
* Load and instantiate the WASM module
|
|
45
|
+
*/
|
|
46
|
+
load(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Internal load implementation using wasm-bindgen initSync
|
|
49
|
+
*/
|
|
50
|
+
private doLoad;
|
|
51
|
+
/**
|
|
52
|
+
* Get the WASM bindings after loading
|
|
53
|
+
*/
|
|
54
|
+
getBindings(): IWasmBindings;
|
|
55
|
+
/**
|
|
56
|
+
* Check if WASM is loaded
|
|
57
|
+
*/
|
|
58
|
+
isLoaded(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Get the loading strategy name
|
|
61
|
+
*/
|
|
62
|
+
getStrategy(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Create bindings wrapper using wasm-bindgen exports
|
|
65
|
+
*/
|
|
66
|
+
private createBindings;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a static loader with validation
|
|
70
|
+
*/
|
|
71
|
+
declare function createStaticLoader(wasmModule: WebAssembly.Module): StaticWasmLoader;
|
|
5
72
|
|
|
6
73
|
/**
|
|
7
74
|
* Create a detector with automatic runtime selection
|
|
@@ -55,4 +122,4 @@ declare function createEdgeDetector(wasmModule: WebAssembly.Module, options?: ID
|
|
|
55
122
|
*/
|
|
56
123
|
declare function createFallbackDetector(): IDetector;
|
|
57
124
|
|
|
58
|
-
export { IDetector, IDetectorOptions, createDetector, createEdgeDetector, createFallbackDetector };
|
|
125
|
+
export { IDetector, IDetectorOptions, IWasmBindings, IWasmLoader, StaticWasmLoader, createDetector, createEdgeDetector, createFallbackDetector, createStaticLoader };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CONFIDENCE, D as DetectionClass, F as ForgeabilityRisk,
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { h as IWasmLoader, l as IWasmBindings, a as IDetectorOptions, I as IDetector } from './rules-detector-ZIKHN-_y.js';
|
|
2
|
+
export { C as CONFIDENCE, D as DetectionClass, c as DynamicWasmLoader, F as ForgeabilityRisk, d as ICustomerPolicy, e as IDetectedAgent, b as IDetectionInput, f as IDetectionResult, m as IPathRule, g as IPolicyLoader, n as PolicyLoadError, P as PolicyLoader, o as PolicyLoaderConfig, R as RulesDetector, V as VerificationMethod, W as WasmDetector, i as createDynamicLoader, j as createPolicyLoader, k as createRulesDetector } from './rules-detector-ZIKHN-_y.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Static WASM Loader for Edge Runtime
|
|
6
|
+
*
|
|
7
|
+
* This loader is designed for environments that require static WASM imports,
|
|
8
|
+
* such as Vercel Edge Runtime and Cloudflare Workers.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // In your middleware.ts:
|
|
13
|
+
* import wasmModule from '@kya-os/checkpoint-wasm-runtime/wasm?module';
|
|
14
|
+
* import { StaticWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/edge';
|
|
15
|
+
*
|
|
16
|
+
* const loader = new StaticWasmLoader(wasmModule);
|
|
17
|
+
* const detector = new WasmDetector(loader);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The `?module` suffix tells bundlers (webpack, esbuild) to import the WASM
|
|
21
|
+
* as a pre-compiled WebAssembly.Module, which is required for Edge Runtime.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Static WASM Loader
|
|
26
|
+
*
|
|
27
|
+
* For Edge Runtime environments that require pre-compiled WASM modules.
|
|
28
|
+
* The consumer must provide the WASM module via a static import with `?module` suffix.
|
|
29
|
+
*
|
|
30
|
+
* This loader uses the wasm-bindgen generated JS glue code to properly
|
|
31
|
+
* initialize the WASM module with all required imports.
|
|
32
|
+
*/
|
|
33
|
+
declare class StaticWasmLoader implements IWasmLoader {
|
|
34
|
+
private readonly wasmModule;
|
|
35
|
+
private bindings;
|
|
36
|
+
private loadPromise;
|
|
37
|
+
private wasmExports;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new StaticWasmLoader
|
|
40
|
+
* @param wasmModule - Pre-compiled WebAssembly.Module from static import
|
|
41
|
+
*/
|
|
42
|
+
constructor(wasmModule: WebAssembly.Module);
|
|
43
|
+
/**
|
|
44
|
+
* Load and instantiate the WASM module
|
|
45
|
+
*/
|
|
46
|
+
load(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Internal load implementation using wasm-bindgen initSync
|
|
49
|
+
*/
|
|
50
|
+
private doLoad;
|
|
51
|
+
/**
|
|
52
|
+
* Get the WASM bindings after loading
|
|
53
|
+
*/
|
|
54
|
+
getBindings(): IWasmBindings;
|
|
55
|
+
/**
|
|
56
|
+
* Check if WASM is loaded
|
|
57
|
+
*/
|
|
58
|
+
isLoaded(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Get the loading strategy name
|
|
61
|
+
*/
|
|
62
|
+
getStrategy(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Create bindings wrapper using wasm-bindgen exports
|
|
65
|
+
*/
|
|
66
|
+
private createBindings;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a static loader with validation
|
|
70
|
+
*/
|
|
71
|
+
declare function createStaticLoader(wasmModule: WebAssembly.Module): StaticWasmLoader;
|
|
5
72
|
|
|
6
73
|
/**
|
|
7
74
|
* Create a detector with automatic runtime selection
|
|
@@ -55,4 +122,4 @@ declare function createEdgeDetector(wasmModule: WebAssembly.Module, options?: ID
|
|
|
55
122
|
*/
|
|
56
123
|
declare function createFallbackDetector(): IDetector;
|
|
57
124
|
|
|
58
|
-
export { IDetector, IDetectorOptions, createDetector, createEdgeDetector, createFallbackDetector };
|
|
125
|
+
export { IDetector, IDetectorOptions, IWasmBindings, IWasmLoader, StaticWasmLoader, createDetector, createEdgeDetector, createFallbackDetector, createStaticLoader };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var checkpointShared = require('@kya-os/checkpoint-shared');
|
|
4
4
|
|
|
5
|
+
// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.15.32_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js
|
|
6
|
+
|
|
5
7
|
// src/types.ts
|
|
6
8
|
var CONFIDENCE = {
|
|
7
9
|
/** Minimum confidence for isAgent=true */
|
|
@@ -1441,7 +1443,7 @@ var RulesDetector = class {
|
|
|
1441
1443
|
return;
|
|
1442
1444
|
}
|
|
1443
1445
|
try {
|
|
1444
|
-
this.rules = checkpointShared.
|
|
1446
|
+
this.rules = checkpointShared.RuleLoader.loadSync();
|
|
1445
1447
|
this.ready = true;
|
|
1446
1448
|
} catch (error) {
|
|
1447
1449
|
console.warn("[RulesDetector] Failed to load rules:", error);
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { RuleLoader } from '@kya-os/checkpoint-shared';
|
|
3
|
+
|
|
4
|
+
createRequire(import.meta.url);
|
|
2
5
|
|
|
3
6
|
// src/types.ts
|
|
4
7
|
var CONFIDENCE = {
|
|
@@ -1439,7 +1442,7 @@ var RulesDetector = class {
|
|
|
1439
1442
|
return;
|
|
1440
1443
|
}
|
|
1441
1444
|
try {
|
|
1442
|
-
this.rules =
|
|
1445
|
+
this.rules = RuleLoader.loadSync();
|
|
1443
1446
|
this.ready = true;
|
|
1444
1447
|
} catch (error) {
|
|
1445
1448
|
console.warn("[RulesDetector] Failed to load rules:", error);
|
package/dist/node.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CONFIDENCE, D as DetectionClass, F as ForgeabilityRisk,
|
|
3
|
-
export { D as DynamicWasmLoader, c as createDynamicLoader } from './dynamic-loader-qGJacfEC.mjs';
|
|
1
|
+
import { I as IDetector, a as IDetectorOptions, b as IDetectionInput } from './rules-detector-ZIKHN-_y.mjs';
|
|
2
|
+
export { C as CONFIDENCE, D as DetectionClass, c as DynamicWasmLoader, F as ForgeabilityRisk, d as ICustomerPolicy, e as IDetectedAgent, f as IDetectionResult, g as IPolicyLoader, h as IWasmLoader, P as PolicyLoader, R as RulesDetector, V as VerificationMethod, W as WasmDetector, i as createDynamicLoader, j as createPolicyLoader, k as createRulesDetector } from './rules-detector-ZIKHN-_y.mjs';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Create a detector for Node.js with dynamic WASM loading
|
package/dist/node.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CONFIDENCE, D as DetectionClass, F as ForgeabilityRisk,
|
|
3
|
-
export { D as DynamicWasmLoader, c as createDynamicLoader } from './dynamic-loader-cS-pUisw.js';
|
|
1
|
+
import { I as IDetector, a as IDetectorOptions, b as IDetectionInput } from './rules-detector-ZIKHN-_y.js';
|
|
2
|
+
export { C as CONFIDENCE, D as DetectionClass, c as DynamicWasmLoader, F as ForgeabilityRisk, d as ICustomerPolicy, e as IDetectedAgent, f as IDetectionResult, g as IPolicyLoader, h as IWasmLoader, P as PolicyLoader, R as RulesDetector, V as VerificationMethod, W as WasmDetector, i as createDynamicLoader, j as createPolicyLoader, k as createRulesDetector } from './rules-detector-ZIKHN-_y.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Create a detector for Node.js with dynamic WASM loading
|
package/dist/node.js
CHANGED
|
@@ -786,7 +786,7 @@ var RulesDetector = class {
|
|
|
786
786
|
return;
|
|
787
787
|
}
|
|
788
788
|
try {
|
|
789
|
-
this.rules = checkpointShared.
|
|
789
|
+
this.rules = checkpointShared.RuleLoader.loadSync();
|
|
790
790
|
this.ready = true;
|
|
791
791
|
} catch (error) {
|
|
792
792
|
console.warn("[RulesDetector] Failed to load rules:", error);
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { RuleLoader } from '@kya-os/checkpoint-shared';
|
|
3
|
+
|
|
4
|
+
createRequire(import.meta.url);
|
|
2
5
|
|
|
3
6
|
// src/types.ts
|
|
4
7
|
var CONFIDENCE = {
|
|
@@ -784,7 +787,7 @@ var RulesDetector = class {
|
|
|
784
787
|
return;
|
|
785
788
|
}
|
|
786
789
|
try {
|
|
787
|
-
this.rules =
|
|
790
|
+
this.rules = RuleLoader.loadSync();
|
|
788
791
|
this.ready = true;
|
|
789
792
|
} catch (error) {
|
|
790
793
|
console.warn("[RulesDetector] Failed to load rules:", error);
|
|
@@ -1,9 +1,203 @@
|
|
|
1
1
|
export { initEngineEdge } from './engine-edge.mjs';
|
|
2
|
-
import { V as VerifyResult } from './types-D0j85fF0.mjs';
|
|
3
|
-
import {
|
|
4
|
-
export { B as BuildAgentRequestOpts, R as RenderedResponse, b as buildAgentRequest, e as extractAgentDid, a as extractCredentialStatusUrl, c as extractIssuer, h as hasMalformedJwsBody, r as renderDecisionAsResponse } from './render-decision-C1a-iuiW.mjs';
|
|
2
|
+
import { E as EnforcementMode, A as AgentRequest, V as VerifyResult } from './types-D0j85fF0.mjs';
|
|
3
|
+
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter, ClockAdapter } from './adapters.mjs';
|
|
5
4
|
import '@kya-os/checkpoint-shared';
|
|
6
|
-
|
|
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;
|
|
7
201
|
|
|
8
202
|
/**
|
|
9
203
|
* `verifyRequestEdge` async-init orchestrator — Edge-WASM-2 (folded into
|
|
@@ -46,4 +240,4 @@ declare function makeVerifyRequestEdge(opts: VerifyRequestOpts): (req: IncomingH
|
|
|
46
240
|
*/
|
|
47
241
|
declare function verifyRequestEdge(req: IncomingHttpLike, opts: VerifyRequestOpts): Promise<VerifyResult>;
|
|
48
242
|
|
|
49
|
-
export { IncomingHttpLike, VerifyRequestOpts, makeVerifyRequestEdge, verifyRequestEdge };
|
|
243
|
+
export { type BuildAgentRequestOpts, type IncomingHttpLike, type RenderedResponse, type VerifyRequestOpts, buildAgentRequest, extractAgentDid, extractCredentialStatusUrl, extractIssuer, hasMalformedJwsBody, makeVerifyRequestEdge, renderDecisionAsResponse, verifyRequestEdge };
|