@kya-os/mcp-i-core 1.1.13-canary.2 → 1.2.1-canary.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/dist/__tests__/utils/mock-providers.d.ts +5 -3
- package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
- package/dist/__tests__/utils/mock-providers.js +23 -12
- package/dist/__tests__/utils/mock-providers.js.map +1 -1
- package/dist/index.d.ts +33 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/base.d.ts +18 -3
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/base.js +5 -1
- package/dist/providers/base.js.map +1 -1
- package/dist/providers/memory.d.ts +2 -2
- package/dist/providers/memory.d.ts.map +1 -1
- package/dist/providers/memory.js +9 -5
- package/dist/providers/memory.js.map +1 -1
- package/dist/runtime/base.d.ts +40 -1
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +148 -20
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/access-control.service.d.ts +121 -0
- package/dist/services/access-control.service.d.ts.map +1 -0
- package/dist/services/access-control.service.js +458 -0
- package/dist/services/access-control.service.js.map +1 -0
- package/dist/services/crypto.service.d.ts +69 -0
- package/dist/services/crypto.service.d.ts.map +1 -0
- package/dist/services/crypto.service.js +225 -0
- package/dist/services/crypto.service.js.map +1 -0
- package/dist/services/errors.d.ts +49 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +66 -0
- package/dist/services/errors.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/proof-verifier.d.ts +98 -0
- package/dist/services/proof-verifier.d.ts.map +1 -0
- package/dist/services/proof-verifier.js +319 -0
- package/dist/services/proof-verifier.js.map +1 -0
- package/dist/services/storage.service.d.ts +116 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/services/storage.service.js +405 -0
- package/dist/services/storage.service.js.map +1 -0
- package/dist/utils/base64.d.ts +31 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +138 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/storage-keys.d.ts +120 -0
- package/dist/utils/storage-keys.d.ts.map +1 -0
- package/dist/utils/storage-keys.js +217 -0
- package/dist/utils/storage-keys.js.map +1 -0
- package/package.json +5 -4
- package/dist/compliance/schema-verifier-v2.d.ts +0 -110
- package/dist/compliance/schema-verifier-v2.d.ts.map +0 -1
- package/dist/compliance/schema-verifier-v2.js +0 -510
- package/dist/compliance/schema-verifier-v2.js.map +0 -1
- package/dist/did/resolver.d.ts +0 -92
- package/dist/did/resolver.d.ts.map +0 -1
- package/dist/did/resolver.js +0 -203
- package/dist/did/resolver.js.map +0 -1
- package/dist/proof/proof-engine.d.ts +0 -89
- package/dist/proof/proof-engine.d.ts.map +0 -1
- package/dist/proof/proof-engine.js +0 -249
- package/dist/proof/proof-engine.js.map +0 -1
- package/dist/runtime/base-v2.d.ts +0 -117
- package/dist/runtime/base-v2.d.ts.map +0 -1
- package/dist/runtime/base-v2.js +0 -328
- package/dist/runtime/base-v2.js.map +0 -1
- package/dist/types/providers.d.ts +0 -142
- package/dist/types/providers.d.ts.map +0 -1
- package/dist/types/providers.js +0 -43
- package/dist/types/providers.js.map +0 -1
- package/dist/verification/interfaces.d.ts +0 -125
- package/dist/verification/interfaces.d.ts.map +0 -1
- package/dist/verification/interfaces.js +0 -101
- package/dist/verification/interfaces.js.map +0 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CryptoService
|
|
4
|
+
*
|
|
5
|
+
* Centralized cryptographic operations service that provides consistent
|
|
6
|
+
* signature verification across all platforms (Cloudflare, Node.js, etc.).
|
|
7
|
+
*
|
|
8
|
+
* This service eliminates code duplication and ensures cryptographic operations
|
|
9
|
+
* behave identically everywhere.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CryptoService = void 0;
|
|
13
|
+
const base64_js_1 = require("../utils/base64.js");
|
|
14
|
+
class CryptoService {
|
|
15
|
+
cryptoProvider;
|
|
16
|
+
constructor(cryptoProvider) {
|
|
17
|
+
this.cryptoProvider = cryptoProvider;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Verify raw Ed25519 signature
|
|
21
|
+
* @param data - Data that was signed
|
|
22
|
+
* @param signature - Signature bytes
|
|
23
|
+
* @param publicKey - Base64 encoded Ed25519 public key (32 bytes)
|
|
24
|
+
*/
|
|
25
|
+
async verifyEd25519(data, signature, publicKey) {
|
|
26
|
+
try {
|
|
27
|
+
const result = await this.cryptoProvider.verify(data, signature, publicKey);
|
|
28
|
+
// Ensure we always return a boolean (handle undefined from unmocked providers)
|
|
29
|
+
return result === true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// Log error for debugging but return false for invalid signatures
|
|
33
|
+
console.error("[CryptoService] Ed25519 verification error:", error);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parse JWS into components
|
|
39
|
+
* @param jws - Full compact JWS string (header.payload.signature)
|
|
40
|
+
* @returns Parsed JWS components
|
|
41
|
+
*/
|
|
42
|
+
parseJWS(jws) {
|
|
43
|
+
const parts = jws.split(".");
|
|
44
|
+
if (parts.length !== 3) {
|
|
45
|
+
throw new Error("Invalid JWS format: expected header.payload.signature");
|
|
46
|
+
}
|
|
47
|
+
const [headerB64, payloadB64, signatureB64] = parts;
|
|
48
|
+
// Decode header
|
|
49
|
+
let header;
|
|
50
|
+
try {
|
|
51
|
+
header = JSON.parse((0, base64_js_1.base64urlDecodeToString)(headerB64));
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw new Error(`Invalid header base64: ${error instanceof Error ? error.message : String(error)}`);
|
|
55
|
+
}
|
|
56
|
+
// Decode payload (optional, may be detached)
|
|
57
|
+
let payload;
|
|
58
|
+
if (payloadB64) {
|
|
59
|
+
try {
|
|
60
|
+
payload = JSON.parse((0, base64_js_1.base64urlDecodeToString)(payloadB64));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// Payload decoding failed - this is an error for non-detached JWS
|
|
64
|
+
// Re-throw to let caller handle it (they can check if it's detached format)
|
|
65
|
+
throw new Error(`Invalid payload base64: ${error instanceof Error ? error.message : String(error)}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Decode signature bytes
|
|
69
|
+
let signatureBytes;
|
|
70
|
+
try {
|
|
71
|
+
signatureBytes = (0, base64_js_1.base64urlDecodeToBytes)(signatureB64);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// Invalid signature base64 - this is a fatal error
|
|
75
|
+
throw new Error(`Invalid signature base64: ${error instanceof Error ? error.message : String(error)}`);
|
|
76
|
+
}
|
|
77
|
+
// Create signing input (header.payload)
|
|
78
|
+
const signingInput = `${headerB64}.${payloadB64}`;
|
|
79
|
+
return {
|
|
80
|
+
header,
|
|
81
|
+
payload,
|
|
82
|
+
signatureBytes,
|
|
83
|
+
signingInput,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Verify JWS signature (full compact format: header.payload.signature)
|
|
88
|
+
* @param jws - Full compact JWS string (or detached format: header..signature)
|
|
89
|
+
* @param publicKeyJwk - Ed25519 public key in JWK format
|
|
90
|
+
* @param options - Verification options
|
|
91
|
+
* @param options.detachedPayload - Optional detached payload (Uint8Array or string) for detached JWS format
|
|
92
|
+
* @param options.expectedKid - Optional expected key ID to validate
|
|
93
|
+
* @param options.alg - Optional expected algorithm (defaults to 'EdDSA')
|
|
94
|
+
*/
|
|
95
|
+
async verifyJWS(jws, publicKeyJwk, options) {
|
|
96
|
+
try {
|
|
97
|
+
// Validate JWK format
|
|
98
|
+
if (!this.isValidEd25519JWK(publicKeyJwk)) {
|
|
99
|
+
console.error("[CryptoService] Invalid Ed25519 JWK format");
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
// Validate expected kid if provided
|
|
103
|
+
if (options?.expectedKid && publicKeyJwk.kid !== options.expectedKid) {
|
|
104
|
+
console.error("[CryptoService] Key ID mismatch");
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
// Parse JWS components - handle malformed JWS gracefully
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
parsed = this.parseJWS(jws);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// Malformed JWS - check if it's detached format with provided payload
|
|
114
|
+
if (options?.detachedPayload !== undefined) {
|
|
115
|
+
const parts = jws.split(".");
|
|
116
|
+
if (parts.length === 3 && parts[1] === "") {
|
|
117
|
+
// Detached format: header..signature
|
|
118
|
+
try {
|
|
119
|
+
const headerB64 = parts[0];
|
|
120
|
+
const signatureB64 = parts[2];
|
|
121
|
+
const header = JSON.parse((0, base64_js_1.base64urlDecodeToString)(headerB64));
|
|
122
|
+
const signatureBytes = (0, base64_js_1.base64urlDecodeToBytes)(signatureB64);
|
|
123
|
+
parsed = {
|
|
124
|
+
header,
|
|
125
|
+
payload: undefined,
|
|
126
|
+
signatureBytes,
|
|
127
|
+
signingInput: "", // Will be reconstructed below
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
console.error("[CryptoService] Invalid detached JWS format");
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
console.error("[CryptoService] Invalid JWS format:", error);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
console.error("[CryptoService] Invalid JWS format:", error);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Validate algorithm
|
|
146
|
+
const expectedAlg = options?.alg || "EdDSA";
|
|
147
|
+
if (parsed.header.alg !== expectedAlg) {
|
|
148
|
+
console.error(`[CryptoService] Unsupported algorithm: ${parsed.header.alg}, expected ${expectedAlg}`);
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
// Handle detached payload if provided
|
|
152
|
+
let signingInput;
|
|
153
|
+
let signingInputBytes;
|
|
154
|
+
if (options?.detachedPayload !== undefined) {
|
|
155
|
+
// Detached format: reconstruct signing input from header + detached payload
|
|
156
|
+
const headerB64 = jws.split(".")[0];
|
|
157
|
+
let payloadB64;
|
|
158
|
+
if (options.detachedPayload instanceof Uint8Array) {
|
|
159
|
+
// Uint8Array payload
|
|
160
|
+
payloadB64 = (0, base64_js_1.base64urlEncodeFromBytes)(options.detachedPayload);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// String payload (backward compatibility)
|
|
164
|
+
payloadB64 = (0, base64_js_1.base64urlEncodeFromBytes)(new TextEncoder().encode(options.detachedPayload));
|
|
165
|
+
}
|
|
166
|
+
signingInput = `${headerB64}.${payloadB64}`;
|
|
167
|
+
signingInputBytes = new TextEncoder().encode(signingInput);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// Full compact format: use parsed signing input
|
|
171
|
+
if (!parsed.signingInput) {
|
|
172
|
+
console.error("[CryptoService] Missing signing input for compact JWS");
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
signingInput = parsed.signingInput;
|
|
176
|
+
signingInputBytes = new TextEncoder().encode(signingInput);
|
|
177
|
+
}
|
|
178
|
+
// Extract raw public key from JWK
|
|
179
|
+
let publicKeyBase64;
|
|
180
|
+
try {
|
|
181
|
+
publicKeyBase64 = this.jwkToBase64PublicKey(publicKeyJwk);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
console.error("[CryptoService] Failed to extract public key:", error);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
// Verify signature
|
|
188
|
+
return await this.verifyEd25519(signingInputBytes, parsed.signatureBytes, publicKeyBase64);
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
// Security-safe failure: never throw, always return false
|
|
192
|
+
console.error("[CryptoService] JWS verification error:", error);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Validate Ed25519 JWK format
|
|
198
|
+
*/
|
|
199
|
+
isValidEd25519JWK(jwk) {
|
|
200
|
+
return (typeof jwk === "object" &&
|
|
201
|
+
jwk !== null &&
|
|
202
|
+
"kty" in jwk &&
|
|
203
|
+
jwk.kty === "OKP" &&
|
|
204
|
+
"crv" in jwk &&
|
|
205
|
+
jwk.crv === "Ed25519" &&
|
|
206
|
+
"x" in jwk &&
|
|
207
|
+
typeof jwk.x === "string" &&
|
|
208
|
+
jwk.x.length > 0);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Convert Ed25519 JWK to base64 encoded public key
|
|
212
|
+
*/
|
|
213
|
+
jwkToBase64PublicKey(jwk) {
|
|
214
|
+
// The 'x' field contains the base64url encoded public key
|
|
215
|
+
// Convert from base64url to standard base64
|
|
216
|
+
const publicKeyBytes = (0, base64_js_1.base64urlDecodeToBytes)(jwk.x);
|
|
217
|
+
// Verify key length (Ed25519 public keys are 32 bytes)
|
|
218
|
+
if (publicKeyBytes.length !== 32) {
|
|
219
|
+
throw new Error(`Invalid Ed25519 public key length: ${publicKeyBytes.length}`);
|
|
220
|
+
}
|
|
221
|
+
return (0, base64_js_1.bytesToBase64)(publicKeyBytes);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.CryptoService = CryptoService;
|
|
225
|
+
//# sourceMappingURL=crypto.service.js.map
|
|
@@ -0,0 +1 @@
|
|
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,CAAC;QAErD,uDAAuD;QACvD,IAAI,cAAc,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,sCAAsC,cAAc,CAAC,MAAM,EAAE,CAC9D,CAAC;QACJ,CAAC;QAED,OAAO,IAAA,yBAAa,EAAC,cAAc,CAAC,CAAC;IACvC,CAAC;CACF;AArQD,sCAqQC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof Verification Error Codes and Types
|
|
3
|
+
*
|
|
4
|
+
* Specific error codes for proof verification failures to enable
|
|
5
|
+
* better error handling and debugging.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Error codes for proof verification
|
|
9
|
+
*/
|
|
10
|
+
export declare const PROOF_VERIFICATION_ERROR_CODES: {
|
|
11
|
+
readonly INVALID_PROOF_STRUCTURE: "INVALID_PROOF_STRUCTURE";
|
|
12
|
+
readonly MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD";
|
|
13
|
+
readonly NONCE_REPLAY_DETECTED: "NONCE_REPLAY_DETECTED";
|
|
14
|
+
readonly TIMESTAMP_SKEW_EXCEEDED: "TIMESTAMP_SKEW_EXCEEDED";
|
|
15
|
+
readonly TIMESTAMP_INVALID: "TIMESTAMP_INVALID";
|
|
16
|
+
readonly INVALID_JWS_SIGNATURE: "INVALID_JWS_SIGNATURE";
|
|
17
|
+
readonly INVALID_JWS_FORMAT: "INVALID_JWS_FORMAT";
|
|
18
|
+
readonly INVALID_JWS_HEADER: "INVALID_JWS_HEADER";
|
|
19
|
+
readonly INVALID_JWS_PAYLOAD: "INVALID_JWS_PAYLOAD";
|
|
20
|
+
readonly INVALID_JWS_SIGNATURE_BASE64: "INVALID_JWS_SIGNATURE_BASE64";
|
|
21
|
+
readonly UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM";
|
|
22
|
+
readonly INVALID_JWK_FORMAT: "INVALID_JWK_FORMAT";
|
|
23
|
+
readonly INVALID_JWK_KTY: "INVALID_JWK_KTY";
|
|
24
|
+
readonly INVALID_JWK_CRV: "INVALID_JWK_CRV";
|
|
25
|
+
readonly INVALID_JWK_X_FIELD: "INVALID_JWK_X_FIELD";
|
|
26
|
+
readonly INVALID_JWK_KEY_LENGTH: "INVALID_JWK_KEY_LENGTH";
|
|
27
|
+
readonly JWK_KID_MISMATCH: "JWK_KID_MISMATCH";
|
|
28
|
+
readonly DID_RESOLUTION_FAILED: "DID_RESOLUTION_FAILED";
|
|
29
|
+
readonly DID_DOCUMENT_NOT_FOUND: "DID_DOCUMENT_NOT_FOUND";
|
|
30
|
+
readonly VERIFICATION_METHOD_NOT_FOUND: "VERIFICATION_METHOD_NOT_FOUND";
|
|
31
|
+
readonly PUBLIC_KEY_NOT_FOUND: "PUBLIC_KEY_NOT_FOUND";
|
|
32
|
+
readonly UNSUPPORTED_DID_METHOD: "UNSUPPORTED_DID_METHOD";
|
|
33
|
+
readonly VERIFICATION_ERROR: "VERIFICATION_ERROR";
|
|
34
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
35
|
+
};
|
|
36
|
+
export type ProofVerificationErrorCode = typeof PROOF_VERIFICATION_ERROR_CODES[keyof typeof PROOF_VERIFICATION_ERROR_CODES];
|
|
37
|
+
/**
|
|
38
|
+
* Proof verification error with specific error code
|
|
39
|
+
*/
|
|
40
|
+
export declare class ProofVerificationError extends Error {
|
|
41
|
+
readonly code: ProofVerificationErrorCode;
|
|
42
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
43
|
+
constructor(code: ProofVerificationErrorCode, message: string, details?: Record<string, unknown> | undefined);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a proof verification error
|
|
47
|
+
*/
|
|
48
|
+
export declare function createProofVerificationError(code: ProofVerificationErrorCode, message: string, details?: Record<string, unknown>): ProofVerificationError;
|
|
49
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/services/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;CAoCjC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GACpC,OAAO,8BAA8B,CAAC,MAAM,OAAO,8BAA8B,CAAC,CAAC;AAErF;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;aAE7B,IAAI,EAAE,0BAA0B;aAEhC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,0BAA0B,EAChD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,0BAA0B,EAChC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,sBAAsB,CAExB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Proof Verification Error Codes and Types
|
|
4
|
+
*
|
|
5
|
+
* Specific error codes for proof verification failures to enable
|
|
6
|
+
* better error handling and debugging.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ProofVerificationError = exports.PROOF_VERIFICATION_ERROR_CODES = void 0;
|
|
10
|
+
exports.createProofVerificationError = createProofVerificationError;
|
|
11
|
+
/**
|
|
12
|
+
* Error codes for proof verification
|
|
13
|
+
*/
|
|
14
|
+
exports.PROOF_VERIFICATION_ERROR_CODES = {
|
|
15
|
+
// Proof structure errors
|
|
16
|
+
INVALID_PROOF_STRUCTURE: "INVALID_PROOF_STRUCTURE",
|
|
17
|
+
MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD",
|
|
18
|
+
// Security errors
|
|
19
|
+
NONCE_REPLAY_DETECTED: "NONCE_REPLAY_DETECTED",
|
|
20
|
+
TIMESTAMP_SKEW_EXCEEDED: "TIMESTAMP_SKEW_EXCEEDED",
|
|
21
|
+
TIMESTAMP_INVALID: "TIMESTAMP_INVALID",
|
|
22
|
+
// Signature errors
|
|
23
|
+
INVALID_JWS_SIGNATURE: "INVALID_JWS_SIGNATURE",
|
|
24
|
+
INVALID_JWS_FORMAT: "INVALID_JWS_FORMAT",
|
|
25
|
+
INVALID_JWS_HEADER: "INVALID_JWS_HEADER",
|
|
26
|
+
INVALID_JWS_PAYLOAD: "INVALID_JWS_PAYLOAD",
|
|
27
|
+
INVALID_JWS_SIGNATURE_BASE64: "INVALID_JWS_SIGNATURE_BASE64",
|
|
28
|
+
UNSUPPORTED_ALGORITHM: "UNSUPPORTED_ALGORITHM",
|
|
29
|
+
// JWK errors
|
|
30
|
+
INVALID_JWK_FORMAT: "INVALID_JWK_FORMAT",
|
|
31
|
+
INVALID_JWK_KTY: "INVALID_JWK_KTY",
|
|
32
|
+
INVALID_JWK_CRV: "INVALID_JWK_CRV",
|
|
33
|
+
INVALID_JWK_X_FIELD: "INVALID_JWK_X_FIELD",
|
|
34
|
+
INVALID_JWK_KEY_LENGTH: "INVALID_JWK_KEY_LENGTH",
|
|
35
|
+
JWK_KID_MISMATCH: "JWK_KID_MISMATCH",
|
|
36
|
+
// DID resolution errors
|
|
37
|
+
DID_RESOLUTION_FAILED: "DID_RESOLUTION_FAILED",
|
|
38
|
+
DID_DOCUMENT_NOT_FOUND: "DID_DOCUMENT_NOT_FOUND",
|
|
39
|
+
VERIFICATION_METHOD_NOT_FOUND: "VERIFICATION_METHOD_NOT_FOUND",
|
|
40
|
+
PUBLIC_KEY_NOT_FOUND: "PUBLIC_KEY_NOT_FOUND",
|
|
41
|
+
UNSUPPORTED_DID_METHOD: "UNSUPPORTED_DID_METHOD",
|
|
42
|
+
// Generic errors
|
|
43
|
+
VERIFICATION_ERROR: "VERIFICATION_ERROR",
|
|
44
|
+
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Proof verification error with specific error code
|
|
48
|
+
*/
|
|
49
|
+
class ProofVerificationError extends Error {
|
|
50
|
+
code;
|
|
51
|
+
details;
|
|
52
|
+
constructor(code, message, details) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.details = details;
|
|
56
|
+
this.name = "ProofVerificationError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.ProofVerificationError = ProofVerificationError;
|
|
60
|
+
/**
|
|
61
|
+
* Create a proof verification error
|
|
62
|
+
*/
|
|
63
|
+
function createProofVerificationError(code, message, details) {
|
|
64
|
+
return new ProofVerificationError(code, message, details);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/services/errors.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA+DH,oEAMC;AAnED;;GAEG;AACU,QAAA,8BAA8B,GAAG;IAC5C,yBAAyB;IACzB,uBAAuB,EAAE,yBAAyB;IAClD,sBAAsB,EAAE,wBAAwB;IAEhD,kBAAkB;IAClB,qBAAqB,EAAE,uBAAuB;IAC9C,uBAAuB,EAAE,yBAAyB;IAClD,iBAAiB,EAAE,mBAAmB;IAEtC,mBAAmB;IACnB,qBAAqB,EAAE,uBAAuB;IAC9C,kBAAkB,EAAE,oBAAoB;IACxC,kBAAkB,EAAE,oBAAoB;IACxC,mBAAmB,EAAE,qBAAqB;IAC1C,4BAA4B,EAAE,8BAA8B;IAC5D,qBAAqB,EAAE,uBAAuB;IAE9C,aAAa;IACb,kBAAkB,EAAE,oBAAoB;IACxC,eAAe,EAAE,iBAAiB;IAClC,eAAe,EAAE,iBAAiB;IAClC,mBAAmB,EAAE,qBAAqB;IAC1C,sBAAsB,EAAE,wBAAwB;IAChD,gBAAgB,EAAE,kBAAkB;IAEpC,wBAAwB;IACxB,qBAAqB,EAAE,uBAAuB;IAC9C,sBAAsB,EAAE,wBAAwB;IAChD,6BAA6B,EAAE,+BAA+B;IAC9D,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAEhD,iBAAiB;IACjB,kBAAkB,EAAE,oBAAoB;IACxC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAKX;;GAEG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAE7B;IAEA;IAHlB,YACkB,IAAgC,EAChD,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAA4B;QAEhC,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AATD,wDASC;AAED;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,IAAgC,EAChC,OAAe,EACf,OAAiC;IAEjC,OAAO,IAAI,sBAAsB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CryptoService } from './crypto.service.js';
|
|
2
|
+
export type { Ed25519JWK, ParsedJWS } from './crypto.service.js';
|
|
3
|
+
export { AccessControlApiService } from './access-control.service.js';
|
|
4
|
+
export type { AccessControlApiServiceConfig, AccessControlApiServiceMetrics, } from './access-control.service.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,YAAY,EACV,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccessControlApiService = exports.CryptoService = void 0;
|
|
4
|
+
var crypto_service_js_1 = require("./crypto.service.js");
|
|
5
|
+
Object.defineProperty(exports, "CryptoService", { enumerable: true, get: function () { return crypto_service_js_1.CryptoService; } });
|
|
6
|
+
var access_control_service_js_1 = require("./access-control.service.js");
|
|
7
|
+
Object.defineProperty(exports, "AccessControlApiService", { enumerable: true, get: function () { return access_control_service_js_1.AccessControlApiService; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAA3C,kHAAA,aAAa,OAAA;AAGtB,yEAAsE;AAA7D,oIAAA,uBAAuB,OAAA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProofVerifier
|
|
3
|
+
*
|
|
4
|
+
* Centralized proof verification service that validates DetachedProof
|
|
5
|
+
* signatures, enforces nonce replay protection, and checks timestamp skew.
|
|
6
|
+
*/
|
|
7
|
+
import { type Ed25519JWK } from "./crypto.service.js";
|
|
8
|
+
import { CryptoProvider } from "../providers/base.js";
|
|
9
|
+
import { ClockProvider } from "../providers/base.js";
|
|
10
|
+
import { NonceCacheProvider } from "../providers/base.js";
|
|
11
|
+
import { FetchProvider } from "../providers/base.js";
|
|
12
|
+
import { type DetachedProof } from "@kya-os/contracts/proof";
|
|
13
|
+
import { type ProofVerificationErrorCode } from "./errors.js";
|
|
14
|
+
export interface ProofVerificationResult {
|
|
15
|
+
valid: boolean;
|
|
16
|
+
reason?: string;
|
|
17
|
+
error?: Error;
|
|
18
|
+
errorCode?: ProofVerificationErrorCode;
|
|
19
|
+
details?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface ProofVerifierConfig {
|
|
22
|
+
cryptoProvider: CryptoProvider;
|
|
23
|
+
clockProvider: ClockProvider;
|
|
24
|
+
nonceCacheProvider: NonceCacheProvider;
|
|
25
|
+
fetchProvider: FetchProvider;
|
|
26
|
+
timestampSkewSeconds?: number;
|
|
27
|
+
nonceTtlSeconds?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare class ProofVerifier {
|
|
30
|
+
private cryptoService;
|
|
31
|
+
private clock;
|
|
32
|
+
private nonceCache;
|
|
33
|
+
private fetch;
|
|
34
|
+
private timestampSkewSeconds;
|
|
35
|
+
private nonceTtlSeconds;
|
|
36
|
+
constructor(config: ProofVerifierConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Verify a DetachedProof
|
|
39
|
+
* Automatically reconstructs canonical payload from proof.meta for signature verification
|
|
40
|
+
* @param proof - The proof to verify
|
|
41
|
+
* @param publicKeyJwk - Ed25519 public key in JWK format (from DID document)
|
|
42
|
+
* @returns Verification result
|
|
43
|
+
*/
|
|
44
|
+
verifyProof(proof: DetachedProof, publicKeyJwk: Ed25519JWK): Promise<ProofVerificationResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Verify proof with detached payload (for CLI/verifier compatibility)
|
|
47
|
+
* @param proof - The proof to verify
|
|
48
|
+
* @param canonicalPayload - Canonical JSON payload (for detached JWS) as string or Uint8Array
|
|
49
|
+
* @param publicKeyJwk - Ed25519 public key in JWK format
|
|
50
|
+
* @returns Verification result
|
|
51
|
+
*/
|
|
52
|
+
verifyProofDetached(proof: DetachedProof, canonicalPayload: string | Uint8Array, publicKeyJwk: Ed25519JWK): Promise<ProofVerificationResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Validate proof structure using Zod schema
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
private validateProofStructure;
|
|
58
|
+
/**
|
|
59
|
+
* Validate nonce replay protection
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
private validateNonce;
|
|
63
|
+
/**
|
|
64
|
+
* Validate timestamp skew
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
private validateTimestamp;
|
|
68
|
+
/**
|
|
69
|
+
* Verify JWS signature
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
private verifySignature;
|
|
73
|
+
/**
|
|
74
|
+
* Add nonce to cache to prevent replay (scoped to agent DID)
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private addNonceToCache;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch public key from DID document
|
|
80
|
+
* @param did - DID to resolve
|
|
81
|
+
* @param kid - Key ID (optional, defaults to first verification method)
|
|
82
|
+
* @returns Ed25519 JWK or null if not found
|
|
83
|
+
* @throws {ProofVerificationError} If DID resolution fails with specific error code
|
|
84
|
+
*/
|
|
85
|
+
fetchPublicKeyFromDID(did: string, kid?: string): Promise<Ed25519JWK | null>;
|
|
86
|
+
/**
|
|
87
|
+
* Build canonical payload from proof meta
|
|
88
|
+
*
|
|
89
|
+
* CRITICAL: This must reconstruct the exact JWS payload structure that was originally signed.
|
|
90
|
+
* The original JWS payload uses standard JWT claims (aud, sub, iss) plus custom proof claims,
|
|
91
|
+
* NOT the proof.meta structure directly.
|
|
92
|
+
*
|
|
93
|
+
* @param meta - Proof metadata
|
|
94
|
+
* @returns Canonical JSON string matching the original JWS payload structure
|
|
95
|
+
*/
|
|
96
|
+
buildCanonicalPayload(meta: DetachedProof["meta"]): string;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=proof-verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-verifier.d.ts","sourceRoot":"","sources":["../../src/services/proof-verifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,qBAAqB,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