@kya-os/verifier 1.3.3-canary.0 → 1.3.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/dist/worker.d.ts +160 -0
- package/package.json +2 -2
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { VerifierResult } from "@kya-os/contracts/verifier";
|
|
2
|
+
import { type VerifierConfig } from "./core.js";
|
|
3
|
+
/**
|
|
4
|
+
* Cloudflare Worker environment bindings
|
|
5
|
+
* Extend this interface in your Worker to add custom bindings
|
|
6
|
+
*/
|
|
7
|
+
export interface WorkerEnv {
|
|
8
|
+
NONCE_CACHE?: KVNamespace;
|
|
9
|
+
KYA_API_URL?: string;
|
|
10
|
+
KYA_API_KEY?: string;
|
|
11
|
+
XMCP_I_TS_SKEW_SEC?: string;
|
|
12
|
+
XMCP_I_SESSION_TTL?: string;
|
|
13
|
+
KYA_VOUCHED_API_KEY?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cloudflare KV Namespace interface
|
|
17
|
+
*/
|
|
18
|
+
export interface KVNamespace {
|
|
19
|
+
get(key: string, options?: {
|
|
20
|
+
type?: "text" | "json" | "arrayBuffer" | "stream";
|
|
21
|
+
}): Promise<any>;
|
|
22
|
+
put(key: string, value: string | ArrayBuffer | ReadableStream, options?: {
|
|
23
|
+
expiration?: number;
|
|
24
|
+
expirationTtl?: number;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
delete(key: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Worker-specific verifier configuration
|
|
30
|
+
*/
|
|
31
|
+
export interface WorkerVerifierConfig extends VerifierConfig {
|
|
32
|
+
/**
|
|
33
|
+
* KV namespace for nonce caching (prevents replay attacks)
|
|
34
|
+
* Bind in wrangler.toml: [[kv_namespaces]] binding = "NONCE_CACHE"
|
|
35
|
+
*/
|
|
36
|
+
kvNamespace?: KVNamespace;
|
|
37
|
+
/**
|
|
38
|
+
* Nonce cache TTL in seconds
|
|
39
|
+
* @default 1800 (30 minutes)
|
|
40
|
+
*/
|
|
41
|
+
nonceTtl?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Allow mock data for testing (NEVER use in production)
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
allowMockData?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create verifier config from Worker environment
|
|
50
|
+
*
|
|
51
|
+
* @param env - Worker environment bindings
|
|
52
|
+
* @param overrides - Optional config overrides
|
|
53
|
+
* @returns WorkerVerifierConfig
|
|
54
|
+
*/
|
|
55
|
+
export declare function createConfigFromEnv(env: WorkerEnv, overrides?: Partial<WorkerVerifierConfig>): WorkerVerifierConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Cloudflare Worker verifier function
|
|
58
|
+
*
|
|
59
|
+
* Usage with environment bindings:
|
|
60
|
+
* ```typescript
|
|
61
|
+
* export default {
|
|
62
|
+
* async fetch(request: Request, env: WorkerEnv): Promise<Response> {
|
|
63
|
+
* const config = createConfigFromEnv(env);
|
|
64
|
+
* const result = await verifyWorker(request, config);
|
|
65
|
+
*
|
|
66
|
+
* if (!result.success) {
|
|
67
|
+
* return applyVerificationToResponse(result);
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* // Continue with verified request...
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param request - The incoming request
|
|
76
|
+
* @param config - Optional verifier configuration
|
|
77
|
+
* @returns Promise<VerifierResult> - Verification result with headers or error
|
|
78
|
+
*/
|
|
79
|
+
export declare function verifyWorker(request: Request, config?: WorkerVerifierConfig): Promise<VerifierResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Cloudflare Worker middleware factory
|
|
82
|
+
*
|
|
83
|
+
* Creates a middleware function that can be used in Worker request handlers
|
|
84
|
+
*
|
|
85
|
+
* @param config - Optional verifier configuration
|
|
86
|
+
* @returns Middleware function
|
|
87
|
+
*/
|
|
88
|
+
export declare function createWorkerMiddleware(config?: VerifierConfig): (request: Request) => Promise<VerifierResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Helper to apply verification result to a Response
|
|
91
|
+
*
|
|
92
|
+
* @param result - Verification result
|
|
93
|
+
* @param response - Response to modify
|
|
94
|
+
* @returns Modified response with headers or error response
|
|
95
|
+
*/
|
|
96
|
+
export declare function applyVerificationToResponse(result: VerifierResult, response?: Response): Response;
|
|
97
|
+
/**
|
|
98
|
+
* Complete example with environment bindings and KV nonce cache
|
|
99
|
+
*
|
|
100
|
+
* wrangler.toml:
|
|
101
|
+
* ```toml
|
|
102
|
+
* name = "my-mcp-verifier"
|
|
103
|
+
* main = "src/index.ts"
|
|
104
|
+
* compatibility_date = "2024-01-01"
|
|
105
|
+
*
|
|
106
|
+
* [[kv_namespaces]]
|
|
107
|
+
* binding = "NONCE_CACHE"
|
|
108
|
+
* id = "your-kv-namespace-id"
|
|
109
|
+
*
|
|
110
|
+
* [vars]
|
|
111
|
+
* KYA_API_URL = "https://knowthat.ai"
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* src/index.ts:
|
|
115
|
+
* ```typescript
|
|
116
|
+
* import { verifyWorker, applyVerificationToResponse, createConfigFromEnv, type WorkerEnv } from "@kya-os/verifier/worker";
|
|
117
|
+
*
|
|
118
|
+
* export default {
|
|
119
|
+
* async fetch(request: Request, env: WorkerEnv): Promise<Response> {
|
|
120
|
+
* // Create config from environment
|
|
121
|
+
* const config = createConfigFromEnv(env);
|
|
122
|
+
*
|
|
123
|
+
* // Verify the request
|
|
124
|
+
* const result = await verifyWorker(request, config);
|
|
125
|
+
*
|
|
126
|
+
* if (!result.success) {
|
|
127
|
+
* return applyVerificationToResponse(result);
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* // Access verified agent context
|
|
131
|
+
* const agentDID = result.agentContext?.did;
|
|
132
|
+
* const agentScopes = result.agentContext?.scopes || [];
|
|
133
|
+
*
|
|
134
|
+
* // Continue with verified request
|
|
135
|
+
* const response = new Response(JSON.stringify({
|
|
136
|
+
* message: "Verified!",
|
|
137
|
+
* agent: result.agentContext
|
|
138
|
+
* }), {
|
|
139
|
+
* headers: { "Content-Type": "application/json" }
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* // Add verification headers to response
|
|
143
|
+
* return applyVerificationToResponse(result, response);
|
|
144
|
+
* }
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* Deploy:
|
|
149
|
+
* ```bash
|
|
150
|
+
* # Create KV namespace
|
|
151
|
+
* wrangler kv:namespace create NONCE_CACHE
|
|
152
|
+
*
|
|
153
|
+
* # Add secrets
|
|
154
|
+
* wrangler secret put KYA_VOUCHED_API_KEY
|
|
155
|
+
*
|
|
156
|
+
* # Deploy
|
|
157
|
+
* wrangler deploy
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
//# sourceMappingURL=worker.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/verifier",
|
|
3
|
-
"version": "1.3.3
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Isomorphic verifier middleware for XMCP-I proof validation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"clean": "rm -rf dist"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@kya-os/contracts": "^1.5.2
|
|
35
|
+
"@kya-os/contracts": "^1.5.2",
|
|
36
36
|
"jose": "^5.2.0",
|
|
37
37
|
"json-canonicalize": "^2.0.0"
|
|
38
38
|
},
|