@kya-os/mcp-i-core 1.7.0 → 1.8.1
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/README.md +1 -1
- package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
- package/dist/conformance/capability-verifier-adapter.js +61 -0
- package/dist/conformance/index.d.ts +10 -0
- package/dist/conformance/index.js +19 -0
- package/dist/conformance/validate-level2.d.ts +203 -0
- package/dist/conformance/validate-level2.js +294 -0
- package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
- package/dist/conformance/vc-jwt-verifier.js +147 -0
- package/dist/delegation/did-web-resolver.d.ts +60 -0
- package/dist/delegation/did-web-resolver.js +129 -0
- package/dist/delegation/outbound-proof.d.ts +3 -2
- package/dist/delegation/outbound-proof.js +3 -2
- package/dist/delegation/utils.d.ts +3 -1
- package/dist/index.d.ts +9 -63
- package/dist/index.js +22 -161
- package/dist/utils/base58.d.ts +4 -28
- package/dist/utils/base58.js +18 -98
- package/dist/utils/base64.d.ts +4 -29
- package/dist/utils/base64.js +18 -167
- package/dist/utils/did-helpers.d.ts +4 -165
- package/dist/utils/did-helpers.js +18 -217
- package/package.json +5 -7
- package/dist/auth/handshake.d.ts +0 -119
- package/dist/auth/handshake.js +0 -250
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.js +0 -11
- package/dist/auth/types.d.ts +0 -46
- package/dist/auth/types.js +0 -10
- package/dist/cache/oauth-config-cache.d.ts +0 -69
- package/dist/cache/oauth-config-cache.js +0 -76
- package/dist/cache/tool-protection-cache.d.ts +0 -89
- package/dist/cache/tool-protection-cache.js +0 -118
- package/dist/compliance/index.d.ts +0 -8
- package/dist/compliance/index.js +0 -24
- package/dist/compliance/schema-registry.d.ts +0 -50
- package/dist/compliance/schema-registry.js +0 -438
- package/dist/compliance/schema-verifier.d.ts +0 -110
- package/dist/compliance/schema-verifier.js +0 -518
- package/dist/config/remote-config.d.ts +0 -173
- package/dist/config/remote-config.js +0 -253
- package/dist/config.d.ts +0 -182
- package/dist/config.js +0 -148
- package/dist/identity/idp-token-resolver.d.ts +0 -69
- package/dist/identity/idp-token-resolver.js +0 -136
- package/dist/identity/idp-token-storage.interface.d.ts +0 -80
- package/dist/identity/idp-token-storage.interface.js +0 -14
- package/dist/identity/user-did-manager.d.ts +0 -228
- package/dist/identity/user-did-manager.js +0 -356
- package/dist/logging/index.d.ts +0 -5
- package/dist/logging/index.js +0 -10
- package/dist/logging/logger.d.ts +0 -33
- package/dist/logging/logger.js +0 -104
- package/dist/proof/generator.d.ts +0 -109
- package/dist/proof/generator.js +0 -236
- package/dist/proof/index.d.ts +0 -5
- package/dist/proof/index.js +0 -11
- package/dist/providers/base.d.ts +0 -95
- package/dist/providers/base.js +0 -47
- package/dist/providers/memory.d.ts +0 -42
- package/dist/providers/memory.js +0 -121
- package/dist/runtime/audit-logger.d.ts +0 -37
- package/dist/runtime/audit-logger.js +0 -9
- package/dist/runtime/base.d.ts +0 -375
- package/dist/runtime/base.js +0 -1491
- package/dist/runtime/ext-apps-constants.d.ts +0 -14
- package/dist/runtime/ext-apps-constants.js +0 -17
- package/dist/services/access-control.service.d.ts +0 -138
- package/dist/services/access-control.service.js +0 -721
- package/dist/services/authorization/authorization-registry.d.ts +0 -29
- package/dist/services/authorization/authorization-registry.js +0 -58
- package/dist/services/authorization/types.d.ts +0 -53
- package/dist/services/authorization/types.js +0 -10
- package/dist/services/batch-delegation.service.d.ts +0 -53
- package/dist/services/batch-delegation.service.js +0 -95
- package/dist/services/crypto.service.d.ts +0 -69
- package/dist/services/crypto.service.js +0 -225
- package/dist/services/delegation-error-formatter.d.ts +0 -124
- package/dist/services/delegation-error-formatter.js +0 -214
- package/dist/services/errors.d.ts +0 -49
- package/dist/services/errors.js +0 -66
- package/dist/services/index.d.ts +0 -9
- package/dist/services/index.js +0 -15
- package/dist/services/oauth-config.service.d.ts +0 -53
- package/dist/services/oauth-config.service.js +0 -141
- package/dist/services/oauth-provider-registry.d.ts +0 -88
- package/dist/services/oauth-provider-registry.js +0 -128
- package/dist/services/oauth-service.d.ts +0 -122
- package/dist/services/oauth-service.js +0 -442
- package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
- package/dist/services/oauth-token-retrieval.service.js +0 -150
- package/dist/services/policy.service.d.ts +0 -130
- package/dist/services/policy.service.js +0 -399
- package/dist/services/proof-verifier.d.ts +0 -98
- package/dist/services/proof-verifier.js +0 -319
- package/dist/services/provider-resolver.d.ts +0 -89
- package/dist/services/provider-resolver.js +0 -196
- package/dist/services/provider-validator.d.ts +0 -55
- package/dist/services/provider-validator.js +0 -135
- package/dist/services/session-registration.service.d.ts +0 -80
- package/dist/services/session-registration.service.js +0 -174
- package/dist/services/storage.service.d.ts +0 -116
- package/dist/services/storage.service.js +0 -411
- package/dist/services/tool-context-builder.d.ts +0 -74
- package/dist/services/tool-context-builder.js +0 -215
- package/dist/services/tool-protection.service.d.ts +0 -193
- package/dist/services/tool-protection.service.js +0 -736
- package/dist/session/index.d.ts +0 -5
- package/dist/session/index.js +0 -11
- package/dist/session/manager.d.ts +0 -113
- package/dist/session/manager.js +0 -273
- package/dist/types/oauth-required-error.d.ts +0 -46
- package/dist/types/oauth-required-error.js +0 -42
- package/dist/types/tool-protection.d.ts +0 -144
- package/dist/types/tool-protection.js +0 -48
- package/dist/utils/cors.d.ts +0 -44
- package/dist/utils/cors.js +0 -71
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -24
- package/dist/utils/storage-keys.d.ts +0 -120
- package/dist/utils/storage-keys.js +0 -217
package/dist/proof/generator.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Proof Generation — Platform-agnostic Protocol Reference
|
|
4
|
-
*
|
|
5
|
-
* Handles JCS canonicalization, SHA-256 digest generation, and Ed25519 JWS
|
|
6
|
-
* signing (compact format) according to MCP-I requirements 5.1, 5.2, 5.3, 5.6.
|
|
7
|
-
*
|
|
8
|
-
* This module is the authoritative proof implementation. All platform adapters
|
|
9
|
-
* (Node.js, Cloudflare Workers) inject a CryptoProvider and delegate here.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ProofGenerator = void 0;
|
|
13
|
-
exports.createProofResponse = createProofResponse;
|
|
14
|
-
exports.extractCanonicalData = extractCanonicalData;
|
|
15
|
-
const jose_1 = require("jose");
|
|
16
|
-
const json_canonicalize_1 = require("json-canonicalize");
|
|
17
|
-
const crypto_service_1 = require("../services/crypto.service");
|
|
18
|
-
/**
|
|
19
|
-
* Platform-agnostic proof generator.
|
|
20
|
-
* Requires a CryptoProvider for all cryptographic operations.
|
|
21
|
-
*/
|
|
22
|
-
class ProofGenerator {
|
|
23
|
-
identity;
|
|
24
|
-
cryptoProvider;
|
|
25
|
-
constructor(identity, cryptoProvider) {
|
|
26
|
-
this.identity = identity;
|
|
27
|
-
this.cryptoProvider = cryptoProvider;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate proof for tool request/response.
|
|
31
|
-
* Requirements: 5.1, 5.2, 5.3, 5.6
|
|
32
|
-
*/
|
|
33
|
-
async generateProof(request, response, session, options = {}) {
|
|
34
|
-
const hashes = await this.generateCanonicalHashes(request, response);
|
|
35
|
-
const meta = {
|
|
36
|
-
did: this.identity.did,
|
|
37
|
-
kid: this.identity.kid,
|
|
38
|
-
ts: Math.floor(Date.now() / 1000),
|
|
39
|
-
nonce: session.nonce,
|
|
40
|
-
audience: session.audience,
|
|
41
|
-
sessionId: session.sessionId,
|
|
42
|
-
requestHash: hashes.requestHash,
|
|
43
|
-
responseHash: hashes.responseHash,
|
|
44
|
-
...options,
|
|
45
|
-
};
|
|
46
|
-
const jws = await this.generateJWS(meta);
|
|
47
|
-
return { jws, meta };
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Generate canonical hashes for request and response.
|
|
51
|
-
* Requirement: 5.1
|
|
52
|
-
*/
|
|
53
|
-
async generateCanonicalHashes(request, response) {
|
|
54
|
-
const canonicalRequest = {
|
|
55
|
-
method: request.method,
|
|
56
|
-
...(request.params ? { params: request.params } : {}),
|
|
57
|
-
};
|
|
58
|
-
const canonicalResponse = response.data;
|
|
59
|
-
const requestHash = await this.generateSHA256Hash(canonicalRequest);
|
|
60
|
-
const responseHash = await this.generateSHA256Hash(canonicalResponse);
|
|
61
|
-
return { requestHash, responseHash };
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Generate SHA-256 hash with JCS canonicalization.
|
|
65
|
-
* Requirement: 5.2
|
|
66
|
-
*
|
|
67
|
-
* Delegates to CryptoProvider.hash() which must return "sha256:<hex>".
|
|
68
|
-
*/
|
|
69
|
-
async generateSHA256Hash(data) {
|
|
70
|
-
const canonicalJson = this.canonicalizeJSON(data);
|
|
71
|
-
const encoded = new TextEncoder().encode(canonicalJson);
|
|
72
|
-
return this.cryptoProvider.hash(encoded);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* JCS canonicalization implementation (RFC 8785)
|
|
76
|
-
*/
|
|
77
|
-
canonicalizeJSON(obj) {
|
|
78
|
-
return (0, json_canonicalize_1.canonicalize)(obj);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Generate Ed25519 JWS in compact format (header.payload.signature).
|
|
82
|
-
* Requirement: 5.3
|
|
83
|
-
*
|
|
84
|
-
* Uses standard JWT claims (aud, sub, iss) in addition to custom claims.
|
|
85
|
-
*/
|
|
86
|
-
async generateJWS(meta) {
|
|
87
|
-
try {
|
|
88
|
-
const privateKeyPem = this.formatPrivateKeyAsPEM(this.identity.privateKey);
|
|
89
|
-
const privateKey = await (0, jose_1.importPKCS8)(privateKeyPem, "EdDSA");
|
|
90
|
-
const payload = {
|
|
91
|
-
aud: meta.audience,
|
|
92
|
-
sub: meta.did,
|
|
93
|
-
iss: meta.did,
|
|
94
|
-
requestHash: meta.requestHash,
|
|
95
|
-
responseHash: meta.responseHash,
|
|
96
|
-
ts: meta.ts,
|
|
97
|
-
nonce: meta.nonce,
|
|
98
|
-
sessionId: meta.sessionId,
|
|
99
|
-
...(meta.scopeId && { scopeId: meta.scopeId }),
|
|
100
|
-
...(meta.delegationRef && { delegationRef: meta.delegationRef }),
|
|
101
|
-
...(meta.clientDid && { clientDid: meta.clientDid }),
|
|
102
|
-
};
|
|
103
|
-
const jwt = await new jose_1.SignJWT(payload)
|
|
104
|
-
.setProtectedHeader({
|
|
105
|
-
alg: "EdDSA",
|
|
106
|
-
kid: this.identity.kid,
|
|
107
|
-
})
|
|
108
|
-
.sign(privateKey);
|
|
109
|
-
return jwt;
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
throw new Error(`Failed to generate JWS: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Format base64 private key as PKCS#8 PEM for JOSE library.
|
|
117
|
-
*/
|
|
118
|
-
formatPrivateKeyAsPEM(base64PrivateKey) {
|
|
119
|
-
// Decode the base64 private key bytes
|
|
120
|
-
// Use platform-agnostic approach (atob + Uint8Array)
|
|
121
|
-
const binaryStr = atob(base64PrivateKey);
|
|
122
|
-
const keyData = new Uint8Array(binaryStr.length);
|
|
123
|
-
for (let i = 0; i < binaryStr.length; i++) {
|
|
124
|
-
keyData[i] = binaryStr.charCodeAt(i);
|
|
125
|
-
}
|
|
126
|
-
// Ed25519 PKCS#8 header (ASN.1 encoding)
|
|
127
|
-
const pkcs8Header = new Uint8Array([
|
|
128
|
-
0x30,
|
|
129
|
-
0x2e, // SEQUENCE, length 46
|
|
130
|
-
0x02,
|
|
131
|
-
0x01,
|
|
132
|
-
0x00, // INTEGER version 0
|
|
133
|
-
0x30,
|
|
134
|
-
0x05, // SEQUENCE, length 5
|
|
135
|
-
0x06,
|
|
136
|
-
0x03,
|
|
137
|
-
0x2b,
|
|
138
|
-
0x65,
|
|
139
|
-
0x70, // OID for Ed25519
|
|
140
|
-
0x04,
|
|
141
|
-
0x22, // OCTET STRING, length 34
|
|
142
|
-
0x04,
|
|
143
|
-
0x20, // OCTET STRING, length 32 (the actual key)
|
|
144
|
-
]);
|
|
145
|
-
// Take first 32 bytes of key (Ed25519 raw private key)
|
|
146
|
-
const rawKey = keyData.subarray(0, 32);
|
|
147
|
-
const fullKey = new Uint8Array(pkcs8Header.length + rawKey.length);
|
|
148
|
-
fullKey.set(pkcs8Header);
|
|
149
|
-
fullKey.set(rawKey, pkcs8Header.length);
|
|
150
|
-
// Base64-encode the full DER-encoded key
|
|
151
|
-
let binaryStrOut = "";
|
|
152
|
-
for (let i = 0; i < fullKey.length; i++) {
|
|
153
|
-
binaryStrOut += String.fromCharCode(fullKey[i]);
|
|
154
|
-
}
|
|
155
|
-
const base64Key = btoa(binaryStrOut);
|
|
156
|
-
// Format as PEM with 64-char line breaks
|
|
157
|
-
const formattedKey = base64Key.match(/.{1,64}/g)?.join("\n") ?? base64Key;
|
|
158
|
-
return ("-----BEGIN PRIVATE KEY-----\n" +
|
|
159
|
-
formattedKey +
|
|
160
|
-
"\n-----END PRIVATE KEY-----");
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Verify a proof (for testing/validation).
|
|
164
|
-
*/
|
|
165
|
-
async verifyProof(proof, request, response) {
|
|
166
|
-
try {
|
|
167
|
-
const expectedHashes = await this.generateCanonicalHashes(request, response);
|
|
168
|
-
if (proof.meta.requestHash !== expectedHashes.requestHash ||
|
|
169
|
-
proof.meta.responseHash !== expectedHashes.responseHash) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
const publicKeyJwk = this.base64PublicKeyToJWK(this.identity.publicKey);
|
|
173
|
-
const cryptoService = new crypto_service_1.CryptoService(this.cryptoProvider);
|
|
174
|
-
return cryptoService.verifyJWS(proof.jws, publicKeyJwk, {
|
|
175
|
-
expectedKid: this.identity.kid,
|
|
176
|
-
alg: "EdDSA",
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Convert base64 public key to Ed25519 JWK format.
|
|
185
|
-
*/
|
|
186
|
-
base64PublicKeyToJWK(publicKeyBase64) {
|
|
187
|
-
// Decode base64 to bytes (platform-agnostic)
|
|
188
|
-
const binaryStr = atob(publicKeyBase64);
|
|
189
|
-
const publicKeyBytes = new Uint8Array(binaryStr.length);
|
|
190
|
-
for (let i = 0; i < binaryStr.length; i++) {
|
|
191
|
-
publicKeyBytes[i] = binaryStr.charCodeAt(i);
|
|
192
|
-
}
|
|
193
|
-
if (publicKeyBytes.length !== 32) {
|
|
194
|
-
throw new Error(`Invalid Ed25519 public key length: ${publicKeyBytes.length}`);
|
|
195
|
-
}
|
|
196
|
-
// Convert to base64url
|
|
197
|
-
let binaryStrOut = "";
|
|
198
|
-
for (let i = 0; i < publicKeyBytes.length; i++) {
|
|
199
|
-
binaryStrOut += String.fromCharCode(publicKeyBytes[i]);
|
|
200
|
-
}
|
|
201
|
-
const base64url = btoa(binaryStrOut)
|
|
202
|
-
.replace(/\+/g, "-")
|
|
203
|
-
.replace(/\//g, "_")
|
|
204
|
-
.replace(/=/g, "");
|
|
205
|
-
return {
|
|
206
|
-
kty: "OKP",
|
|
207
|
-
crv: "Ed25519",
|
|
208
|
-
x: base64url,
|
|
209
|
-
kid: this.identity.kid,
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
exports.ProofGenerator = ProofGenerator;
|
|
214
|
-
/**
|
|
215
|
-
* Create a tool response with proof.
|
|
216
|
-
*/
|
|
217
|
-
async function createProofResponse(request, data, identity, session, cryptoProvider, options = {}) {
|
|
218
|
-
const response = { data };
|
|
219
|
-
const proofGenerator = new ProofGenerator(identity, cryptoProvider);
|
|
220
|
-
const proof = await proofGenerator.generateProof(request, response, session, options);
|
|
221
|
-
response.meta = { proof };
|
|
222
|
-
return response;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Extract canonical data for hashing (utility for testing).
|
|
226
|
-
*/
|
|
227
|
-
function extractCanonicalData(request, response) {
|
|
228
|
-
return {
|
|
229
|
-
request: {
|
|
230
|
-
method: request.method,
|
|
231
|
-
...(request.params ? { params: request.params } : {}),
|
|
232
|
-
},
|
|
233
|
-
response: response.data,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
//# sourceMappingURL=generator.js.map
|
package/dist/proof/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Proof module — platform-agnostic proof generation reference implementation.
|
|
3
|
-
*/
|
|
4
|
-
export { ProofGenerator, createProofResponse, extractCanonicalData, type ProofAgentIdentity, type ToolRequest, type ToolResponse, type ProofOptions, } from "./generator";
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/proof/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractCanonicalData = exports.createProofResponse = exports.ProofGenerator = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Proof module — platform-agnostic proof generation reference implementation.
|
|
6
|
-
*/
|
|
7
|
-
var generator_1 = require("./generator");
|
|
8
|
-
Object.defineProperty(exports, "ProofGenerator", { enumerable: true, get: function () { return generator_1.ProofGenerator; } });
|
|
9
|
-
Object.defineProperty(exports, "createProofResponse", { enumerable: true, get: function () { return generator_1.createProofResponse; } });
|
|
10
|
-
Object.defineProperty(exports, "extractCanonicalData", { enumerable: true, get: function () { return generator_1.extractCanonicalData; } });
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
package/dist/providers/base.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base Provider Classes
|
|
3
|
-
*
|
|
4
|
-
* Abstract classes that define the provider interfaces for
|
|
5
|
-
* platform-specific implementations.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Cryptographic operations provider
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class CryptoProvider {
|
|
11
|
-
abstract sign(data: Uint8Array, privateKey: string): Promise<Uint8Array>;
|
|
12
|
-
abstract verify(data: Uint8Array, signature: Uint8Array, publicKey: string): Promise<boolean>;
|
|
13
|
-
abstract generateKeyPair(): Promise<{
|
|
14
|
-
privateKey: string;
|
|
15
|
-
publicKey: string;
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* Compute SHA-256 hash of data.
|
|
19
|
-
* Returns "sha256:<hex>" format for cross-platform parity.
|
|
20
|
-
*/
|
|
21
|
-
abstract hash(data: Uint8Array): Promise<string>;
|
|
22
|
-
abstract randomBytes(length: number): Promise<Uint8Array>;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Clock/timing operations provider
|
|
26
|
-
*/
|
|
27
|
-
export declare abstract class ClockProvider {
|
|
28
|
-
abstract now(): number;
|
|
29
|
-
abstract isWithinSkew(timestamp: number, skewSeconds: number): boolean;
|
|
30
|
-
abstract hasExpired(expiresAt: number): boolean;
|
|
31
|
-
abstract calculateExpiry(ttlSeconds: number): number;
|
|
32
|
-
abstract format(timestamp: number): string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Network fetch operations provider
|
|
36
|
-
*/
|
|
37
|
-
export declare abstract class FetchProvider {
|
|
38
|
-
abstract resolveDID(did: string): Promise<any>;
|
|
39
|
-
abstract fetchStatusList(url: string): Promise<any>;
|
|
40
|
-
abstract fetchDelegationChain(id: string): Promise<any[]>;
|
|
41
|
-
abstract fetch(url: string, options?: any): Promise<Response>;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Storage operations provider
|
|
45
|
-
*/
|
|
46
|
-
export declare abstract class StorageProvider {
|
|
47
|
-
abstract get(key: string): Promise<string | null>;
|
|
48
|
-
abstract set(key: string, value: string): Promise<void>;
|
|
49
|
-
abstract delete(key: string): Promise<void>;
|
|
50
|
-
abstract exists(key: string): Promise<boolean>;
|
|
51
|
-
abstract list(prefix?: string): Promise<string[]>;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Nonce cache provider
|
|
55
|
-
* Handles replay prevention
|
|
56
|
-
*
|
|
57
|
-
* Nonces should be scoped per agent to prevent cross-agent replay attacks.
|
|
58
|
-
* When agentDid is provided, implementations should use agent-scoped keys.
|
|
59
|
-
*/
|
|
60
|
-
export declare abstract class NonceCacheProvider {
|
|
61
|
-
/**
|
|
62
|
-
* Check if a nonce has been used
|
|
63
|
-
* @param nonce - The nonce to check
|
|
64
|
-
* @param agentDid - Optional agent DID for scoping (prevents cross-agent replay attacks)
|
|
65
|
-
*/
|
|
66
|
-
abstract has(nonce: string, agentDid?: string): Promise<boolean>;
|
|
67
|
-
/**
|
|
68
|
-
* Add a nonce to the cache
|
|
69
|
-
* @param nonce - The nonce to cache
|
|
70
|
-
* @param ttlSeconds - Time to live in seconds (callers now pass TTL, not absolute timestamp)
|
|
71
|
-
* @param agentDid - Optional agent DID for scoping (prevents cross-agent replay attacks)
|
|
72
|
-
*/
|
|
73
|
-
abstract add(nonce: string, ttlSeconds: number, agentDid?: string): Promise<void>;
|
|
74
|
-
abstract cleanup(): Promise<void>;
|
|
75
|
-
abstract destroy(): Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Identity provider for managing agent identities
|
|
79
|
-
*/
|
|
80
|
-
export interface AgentIdentity {
|
|
81
|
-
did: string;
|
|
82
|
-
kid: string;
|
|
83
|
-
privateKey: string;
|
|
84
|
-
publicKey: string;
|
|
85
|
-
createdAt: string;
|
|
86
|
-
type: 'development' | 'production';
|
|
87
|
-
metadata?: Record<string, any>;
|
|
88
|
-
}
|
|
89
|
-
export declare abstract class IdentityProvider {
|
|
90
|
-
abstract getIdentity(): Promise<AgentIdentity>;
|
|
91
|
-
abstract saveIdentity(identity: AgentIdentity): Promise<void>;
|
|
92
|
-
abstract rotateKeys(): Promise<AgentIdentity>;
|
|
93
|
-
abstract deleteIdentity(): Promise<void>;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=base.d.ts.map
|
package/dist/providers/base.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Base Provider Classes
|
|
4
|
-
*
|
|
5
|
-
* Abstract classes that define the provider interfaces for
|
|
6
|
-
* platform-specific implementations.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.IdentityProvider = exports.NonceCacheProvider = exports.StorageProvider = exports.FetchProvider = exports.ClockProvider = exports.CryptoProvider = void 0;
|
|
10
|
-
/**
|
|
11
|
-
* Cryptographic operations provider
|
|
12
|
-
*/
|
|
13
|
-
class CryptoProvider {
|
|
14
|
-
}
|
|
15
|
-
exports.CryptoProvider = CryptoProvider;
|
|
16
|
-
/**
|
|
17
|
-
* Clock/timing operations provider
|
|
18
|
-
*/
|
|
19
|
-
class ClockProvider {
|
|
20
|
-
}
|
|
21
|
-
exports.ClockProvider = ClockProvider;
|
|
22
|
-
/**
|
|
23
|
-
* Network fetch operations provider
|
|
24
|
-
*/
|
|
25
|
-
class FetchProvider {
|
|
26
|
-
}
|
|
27
|
-
exports.FetchProvider = FetchProvider;
|
|
28
|
-
/**
|
|
29
|
-
* Storage operations provider
|
|
30
|
-
*/
|
|
31
|
-
class StorageProvider {
|
|
32
|
-
}
|
|
33
|
-
exports.StorageProvider = StorageProvider;
|
|
34
|
-
/**
|
|
35
|
-
* Nonce cache provider
|
|
36
|
-
* Handles replay prevention
|
|
37
|
-
*
|
|
38
|
-
* Nonces should be scoped per agent to prevent cross-agent replay attacks.
|
|
39
|
-
* When agentDid is provided, implementations should use agent-scoped keys.
|
|
40
|
-
*/
|
|
41
|
-
class NonceCacheProvider {
|
|
42
|
-
}
|
|
43
|
-
exports.NonceCacheProvider = NonceCacheProvider;
|
|
44
|
-
class IdentityProvider {
|
|
45
|
-
}
|
|
46
|
-
exports.IdentityProvider = IdentityProvider;
|
|
47
|
-
//# sourceMappingURL=base.js.map
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory-based provider implementations
|
|
3
|
-
*
|
|
4
|
-
* Simple in-memory implementations for development and testing.
|
|
5
|
-
*/
|
|
6
|
-
import { StorageProvider, NonceCacheProvider, IdentityProvider, AgentIdentity } from './base';
|
|
7
|
-
/**
|
|
8
|
-
* In-memory storage provider
|
|
9
|
-
*/
|
|
10
|
-
export declare class MemoryStorageProvider extends StorageProvider {
|
|
11
|
-
private store;
|
|
12
|
-
get(key: string): Promise<string | null>;
|
|
13
|
-
set(key: string, value: string): Promise<void>;
|
|
14
|
-
delete(key: string): Promise<void>;
|
|
15
|
-
exists(key: string): Promise<boolean>;
|
|
16
|
-
list(prefix?: string): Promise<string[]>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* In-memory nonce cache provider
|
|
20
|
-
*/
|
|
21
|
-
export declare class MemoryNonceCacheProvider extends NonceCacheProvider {
|
|
22
|
-
private nonces;
|
|
23
|
-
has(nonce: string, agentDid?: string): Promise<boolean>;
|
|
24
|
-
add(nonce: string, ttlSeconds: number, agentDid?: string): Promise<void>;
|
|
25
|
-
cleanup(): Promise<void>;
|
|
26
|
-
destroy(): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* In-memory identity provider
|
|
30
|
-
*/
|
|
31
|
-
export declare class MemoryIdentityProvider extends IdentityProvider {
|
|
32
|
-
private identity?;
|
|
33
|
-
private cryptoProvider;
|
|
34
|
-
constructor(cryptoProvider?: any);
|
|
35
|
-
getIdentity(): Promise<AgentIdentity>;
|
|
36
|
-
saveIdentity(identity: AgentIdentity): Promise<void>;
|
|
37
|
-
rotateKeys(): Promise<AgentIdentity>;
|
|
38
|
-
deleteIdentity(): Promise<void>;
|
|
39
|
-
private generateIdentity;
|
|
40
|
-
private generateDIDFromPublicKey;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=memory.d.ts.map
|
package/dist/providers/memory.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Memory-based provider implementations
|
|
4
|
-
*
|
|
5
|
-
* Simple in-memory implementations for development and testing.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.MemoryIdentityProvider = exports.MemoryNonceCacheProvider = exports.MemoryStorageProvider = void 0;
|
|
9
|
-
const base_1 = require("./base");
|
|
10
|
-
/**
|
|
11
|
-
* In-memory storage provider
|
|
12
|
-
*/
|
|
13
|
-
class MemoryStorageProvider extends base_1.StorageProvider {
|
|
14
|
-
store = new Map();
|
|
15
|
-
async get(key) {
|
|
16
|
-
return this.store.get(key) ?? null;
|
|
17
|
-
}
|
|
18
|
-
async set(key, value) {
|
|
19
|
-
this.store.set(key, value);
|
|
20
|
-
}
|
|
21
|
-
async delete(key) {
|
|
22
|
-
this.store.delete(key);
|
|
23
|
-
}
|
|
24
|
-
async exists(key) {
|
|
25
|
-
return this.store.has(key);
|
|
26
|
-
}
|
|
27
|
-
async list(prefix) {
|
|
28
|
-
const keys = Array.from(this.store.keys());
|
|
29
|
-
if (prefix) {
|
|
30
|
-
return keys.filter(k => k.startsWith(prefix));
|
|
31
|
-
}
|
|
32
|
-
return keys;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.MemoryStorageProvider = MemoryStorageProvider;
|
|
36
|
-
/**
|
|
37
|
-
* In-memory nonce cache provider
|
|
38
|
-
*/
|
|
39
|
-
class MemoryNonceCacheProvider extends base_1.NonceCacheProvider {
|
|
40
|
-
nonces = new Map();
|
|
41
|
-
async has(nonce, agentDid) {
|
|
42
|
-
const key = agentDid ? `nonce:${agentDid}:${nonce}` : `nonce:${nonce}`;
|
|
43
|
-
const expiry = this.nonces.get(key);
|
|
44
|
-
if (!expiry)
|
|
45
|
-
return false;
|
|
46
|
-
if (Date.now() > expiry) {
|
|
47
|
-
this.nonces.delete(key);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
async add(nonce, ttlSeconds, agentDid) {
|
|
53
|
-
const key = agentDid ? `nonce:${agentDid}:${nonce}` : `nonce:${nonce}`;
|
|
54
|
-
// Convert TTL seconds to absolute expiration timestamp for storage
|
|
55
|
-
const expiresAt = Date.now() + (ttlSeconds * 1000);
|
|
56
|
-
this.nonces.set(key, expiresAt);
|
|
57
|
-
}
|
|
58
|
-
async cleanup() {
|
|
59
|
-
const now = Date.now();
|
|
60
|
-
for (const [nonce, expiry] of this.nonces) {
|
|
61
|
-
if (now > expiry) {
|
|
62
|
-
this.nonces.delete(nonce);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async destroy() {
|
|
67
|
-
this.nonces.clear();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.MemoryNonceCacheProvider = MemoryNonceCacheProvider;
|
|
71
|
-
/**
|
|
72
|
-
* In-memory identity provider
|
|
73
|
-
*/
|
|
74
|
-
class MemoryIdentityProvider extends base_1.IdentityProvider {
|
|
75
|
-
identity;
|
|
76
|
-
cryptoProvider;
|
|
77
|
-
constructor(cryptoProvider) {
|
|
78
|
-
super();
|
|
79
|
-
this.cryptoProvider = cryptoProvider;
|
|
80
|
-
}
|
|
81
|
-
async getIdentity() {
|
|
82
|
-
if (!this.identity) {
|
|
83
|
-
this.identity = await this.generateIdentity();
|
|
84
|
-
}
|
|
85
|
-
return this.identity;
|
|
86
|
-
}
|
|
87
|
-
async saveIdentity(identity) {
|
|
88
|
-
this.identity = identity;
|
|
89
|
-
}
|
|
90
|
-
async rotateKeys() {
|
|
91
|
-
this.identity = await this.generateIdentity();
|
|
92
|
-
return this.identity;
|
|
93
|
-
}
|
|
94
|
-
async deleteIdentity() {
|
|
95
|
-
this.identity = undefined;
|
|
96
|
-
}
|
|
97
|
-
async generateIdentity() {
|
|
98
|
-
if (!this.cryptoProvider) {
|
|
99
|
-
throw new Error('Crypto provider required for identity generation');
|
|
100
|
-
}
|
|
101
|
-
const keyPair = await this.cryptoProvider.generateKeyPair();
|
|
102
|
-
const did = this.generateDIDFromPublicKey(keyPair.publicKey);
|
|
103
|
-
return {
|
|
104
|
-
did,
|
|
105
|
-
kid: `${did}#key-1`,
|
|
106
|
-
privateKey: keyPair.privateKey,
|
|
107
|
-
publicKey: keyPair.publicKey,
|
|
108
|
-
createdAt: new Date().toISOString(),
|
|
109
|
-
type: 'development'
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
generateDIDFromPublicKey(publicKey) {
|
|
113
|
-
// Simplified DID generation
|
|
114
|
-
const keyHash = Buffer.from(publicKey, 'base64')
|
|
115
|
-
.toString('base64url')
|
|
116
|
-
.substring(0, 32);
|
|
117
|
-
return `did:key:z${keyHash}`;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.MemoryIdentityProvider = MemoryIdentityProvider;
|
|
121
|
-
//# sourceMappingURL=memory.js.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audit Logger Interface
|
|
3
|
-
*
|
|
4
|
-
* Platform-agnostic interface for audit logging in the MCP-I framework.
|
|
5
|
-
* Implementations should be provided by platform-specific packages.
|
|
6
|
-
*/
|
|
7
|
-
import type { AuditContext, AuditEventContext } from "@kya-os/contracts/audit";
|
|
8
|
-
/**
|
|
9
|
-
* Interface for audit logging implementations
|
|
10
|
-
*
|
|
11
|
-
* This interface is platform-agnostic and can be implemented by:
|
|
12
|
-
* - Node.js implementations (using Node.js crypto)
|
|
13
|
-
* - Cloudflare Workers implementations (using Web Crypto API)
|
|
14
|
-
* - Other platform-specific implementations
|
|
15
|
-
*/
|
|
16
|
-
export interface IAuditLogger {
|
|
17
|
-
/**
|
|
18
|
-
* Log an audit record (with session deduplication)
|
|
19
|
-
*
|
|
20
|
-
* This method logs audit records using the frozen audit.v1 format.
|
|
21
|
-
* Only the first call per session is logged (deduplication).
|
|
22
|
-
*
|
|
23
|
-
* @param context - Audit context with identity, session, hashes, and verification status
|
|
24
|
-
*/
|
|
25
|
-
logAuditRecord(context: AuditContext): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Log an event (without session deduplication)
|
|
28
|
-
*
|
|
29
|
-
* This method logs events using the frozen audit.v1 format.
|
|
30
|
-
* Unlike logAuditRecord(), this always logs the event, allowing
|
|
31
|
-
* multiple events per session (e.g., consent events).
|
|
32
|
-
*
|
|
33
|
-
* @param context - Event context with eventType, identity, session, and optional eventData
|
|
34
|
-
*/
|
|
35
|
-
logEvent(context: AuditEventContext): Promise<void>;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=audit-logger.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Audit Logger Interface
|
|
4
|
-
*
|
|
5
|
-
* Platform-agnostic interface for audit logging in the MCP-I framework.
|
|
6
|
-
* Implementations should be provided by platform-specific packages.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
//# sourceMappingURL=audit-logger.js.map
|