@sebastienrousseau/crypto-mcp 0.0.34 → 0.0.36

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 CHANGED
@@ -14,14 +14,14 @@
14
14
 
15
15
  `@sebastienrousseau/crypto-mcp` implements the **Model Context Protocol (MCP)** specification, turning the Crypto Service Suite into a secure, tool-enabled cryptographic runtime for AI agents and LLM-driven environments (including Cursor, Antigravity, Claude Desktop, VS Code, and Zed).
16
16
 
17
- Instead of relying on fragile shell scripts or unverified LLM math, agents invoke cryptographically verified tools backed by `@sebastienrousseau/crypto-lib`, `@sebastienrousseau/crypto-kms`, and `@sebastienrousseau/crypto-wasm`.
17
+ Instead of relying on fragile shell scripts or unverified LLM math, agents invoke cryptographically verified tools backed by `@sebastienrousseau/crypto-lib` and `@sebastienrousseau/crypto-kms`.
18
18
 
19
19
  ---
20
20
 
21
21
  ## Features
22
22
 
23
23
  - **Standard MCP Protocol**: JSON-RPC 2.0 over stdio, with tools, resources and prompts.
24
- - **Key handles, not key material**: keys are generated, unwrapped or derived inside the server process. Tools return an opaque `keyHandle` (`kh_` followed by 32 hex characters) plus public metadata; no tool returns a private key, a symmetric key or a DEK, and no tool accepts one.
24
+ - **Key handles, not key material**: keys are generated, unwrapped or derived inside the server process. Tools return an opaque `keyHandle` (`kh_` followed by 32 hex characters) plus public metadata; no tool returns a private key, a symmetric key or a DEK, no tool accepts one, and no tool wraps an existing key to public keys the client chooses unless the operator allows it (`MCP_ALLOW_KEY_EXPORT=1`).
25
25
  - **Post-Quantum Cryptography (PQC)**: ML-KEM-768 (NIST FIPS 203) key generation, encapsulation and decapsulation.
26
26
  - **Classical Primitives**: RSA-2048/3072/4096 (RSASSA-PSS), ECDSA on P-256, P-384 and secp256k1, Ed25519, HMAC-SHA256, and AES-256-GCM / ChaCha20-Poly1305.
27
27
  - **Envelope Encryption**: wrap and unwrap DEKs under a key-encryption key. Only the `local` provider (random, in-process keys that do not survive a restart) is configured; `aws`, `gcp`, `azure` and `vault` return an error.
@@ -87,6 +87,8 @@ Signature algorithms by key type: `ed25519` signs Ed25519, `rsa` signs RSASSA-PS
87
87
 
88
88
  A key handle is a capability: whoever can call the server with it can use the key, but cannot read it. Handles live only as long as the server process. The store holds at most 64 keys; adding one more destroys the least recently used key, so a client that needs a key for long should keep using it or expect to generate a new one. `crypto_key_destroy` removes a key at once.
89
89
 
90
+ `crypto_hybrid_kem_multi_encapsulate` wraps a fresh 256-bit DEK for the recipients it is given. It refuses an existing `keyHandle` unless the server runs with `MCP_ALLOW_KEY_EXPORT=1`: wrapping an existing key to public keys the client names would let a prompt-injected client send that key to keys it controls.
91
+
90
92
  A typical session:
91
93
 
92
94
  1. `crypto_generate_key` with `type: "ed25519"` returns `keyHandle` and `publicKey`.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAE9D,eAAO,MAAM,SAAS,EAAE,WAAW,EAelC,CAAC;AAEF,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,qBAAqB,CAAC,CAmMhC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAE9D,eAAO,MAAM,SAAS,EAAE,WAAW,EAelC,CAAC;AAoLF,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,qBAAqB,CAAC,CAYhC"}
@@ -16,198 +16,191 @@ exports.RESOURCES = [
16
16
  mimeType: "application/json",
17
17
  },
18
18
  ];
19
- async function readResource(uri) {
20
- if (uri === "crypto://standards/pqc") {
21
- const data = {
22
- standards: [
23
- {
24
- name: "ML-KEM",
25
- fips: 203,
26
- type: "Key Encapsulation Mechanism",
27
- basis: "Module Learning with Errors (M-LWE)",
28
- variants: [
29
- {
30
- level: 1,
31
- name: "ML-KEM-512",
32
- publicKeyBytes: 800,
33
- ciphertextBytes: 768,
34
- sharedSecretBytes: 32,
35
- },
36
- {
37
- level: 3,
38
- name: "ML-KEM-768",
39
- publicKeyBytes: 1184,
40
- ciphertextBytes: 1088,
41
- sharedSecretBytes: 32,
42
- },
43
- {
44
- level: 5,
45
- name: "ML-KEM-1024",
46
- publicKeyBytes: 1568,
47
- ciphertextBytes: 1568,
48
- sharedSecretBytes: 32,
49
- },
50
- ],
51
- },
52
- {
53
- name: "ML-DSA",
54
- fips: 204,
55
- type: "Digital Signature",
56
- basis: "Module Learning with Errors (M-LWE)",
57
- variants: [
58
- {
59
- level: 2,
60
- name: "ML-DSA-44",
61
- publicKeyBytes: 1312,
62
- signatureBytes: 2420,
63
- },
64
- {
65
- level: 3,
66
- name: "ML-DSA-65",
67
- publicKeyBytes: 1952,
68
- signatureBytes: 3309,
69
- },
70
- {
71
- level: 5,
72
- name: "ML-DSA-87",
73
- publicKeyBytes: 2592,
74
- signatureBytes: 4627,
75
- },
76
- ],
77
- },
78
- {
79
- name: "SLH-DSA",
80
- fips: 205,
81
- type: "Stateless Hash-Based Digital Signature",
82
- basis: "Hash Trees (SPHINCS+)",
83
- variants: [
84
- {
85
- level: 1,
86
- name: "SLH-DSA-128s",
87
- publicKeyBytes: 32,
88
- signatureBytes: 7856,
89
- },
90
- {
91
- level: 5,
92
- name: "SLH-DSA-256s",
93
- publicKeyBytes: 64,
94
- signatureBytes: 29792,
95
- },
96
- ],
97
- },
98
- ],
99
- timelines: {
100
- nsaCnsa2: {
101
- softwareTransition: 2027,
102
- webAndProtocols: 2030,
103
- legacyDeprecation: 2033,
104
- },
105
- doraEnforcement: 2025,
106
- cyberResilienceAct: 2027,
107
- },
108
- };
109
- return {
110
- contents: [
111
- {
112
- uri,
113
- mimeType: "application/json",
114
- text: JSON.stringify(data, null, 2),
115
- },
116
- ],
117
- };
118
- }
119
- if (uri === "crypto://algorithms/matrix") {
120
- const matrix = {
121
- symmetric: [
122
- {
123
- name: "AES-256-GCM",
124
- securityBits: 256,
125
- quantumSafe: true,
126
- recommended: true,
127
- },
128
- {
129
- name: "ChaCha20-Poly1305",
130
- securityBits: 256,
131
- quantumSafe: true,
132
- recommended: true,
133
- },
134
- {
135
- name: "3DES",
136
- securityBits: 112,
137
- quantumSafe: false,
138
- recommended: false,
139
- status: "DEPRECATED",
140
- },
141
- ],
142
- asymmetric: [
143
- {
19
+ const PQC_STANDARDS = {
20
+ standards: [
21
+ {
22
+ name: "ML-KEM",
23
+ fips: 203,
24
+ type: "Key Encapsulation Mechanism",
25
+ basis: "Module Learning with Errors (M-LWE)",
26
+ variants: [
27
+ {
28
+ level: 1,
29
+ name: "ML-KEM-512",
30
+ publicKeyBytes: 800,
31
+ ciphertextBytes: 768,
32
+ sharedSecretBytes: 32,
33
+ },
34
+ {
35
+ level: 3,
144
36
  name: "ML-KEM-768",
145
- securityBits: 192,
146
- quantumSafe: true,
147
- recommended: true,
148
- standard: "FIPS 203",
37
+ publicKeyBytes: 1184,
38
+ ciphertextBytes: 1088,
39
+ sharedSecretBytes: 32,
149
40
  },
150
41
  {
151
- name: "RSA-2048",
152
- securityBits: 112,
153
- quantumSafe: false,
154
- recommended: false,
155
- status: "PHASING_OUT",
42
+ level: 5,
43
+ name: "ML-KEM-1024",
44
+ publicKeyBytes: 1568,
45
+ ciphertextBytes: 1568,
46
+ sharedSecretBytes: 32,
156
47
  },
48
+ ],
49
+ },
50
+ {
51
+ name: "ML-DSA",
52
+ fips: 204,
53
+ type: "Digital Signature",
54
+ basis: "Module Learning with Errors (M-LWE)",
55
+ variants: [
157
56
  {
158
- name: "RSA-4096",
159
- securityBits: 128,
160
- quantumSafe: false,
161
- recommended: false,
162
- status: "PHASING_OUT",
57
+ level: 2,
58
+ name: "ML-DSA-44",
59
+ publicKeyBytes: 1312,
60
+ signatureBytes: 2420,
163
61
  },
164
62
  {
165
- name: "ECDSA (P-256)",
166
- securityBits: 128,
167
- quantumSafe: false,
168
- recommended: false,
169
- status: "PHASING_OUT",
63
+ level: 3,
64
+ name: "ML-DSA-65",
65
+ publicKeyBytes: 1952,
66
+ signatureBytes: 3309,
170
67
  },
171
68
  {
172
- name: "Ed25519",
173
- securityBits: 128,
174
- quantumSafe: false,
175
- recommended: false,
176
- status: "PHASING_OUT",
69
+ level: 5,
70
+ name: "ML-DSA-87",
71
+ publicKeyBytes: 2592,
72
+ signatureBytes: 4627,
177
73
  },
178
74
  ],
179
- hashes: [
75
+ },
76
+ {
77
+ name: "SLH-DSA",
78
+ fips: 205,
79
+ type: "Stateless Hash-Based Digital Signature",
80
+ basis: "Hash Trees (SPHINCS+)",
81
+ variants: [
180
82
  {
181
- name: "SHA-256",
182
- securityBits: 256,
183
- quantumSafe: true,
184
- status: "SECURE",
83
+ level: 1,
84
+ name: "SLH-DSA-128s",
85
+ publicKeyBytes: 32,
86
+ signatureBytes: 7856,
185
87
  },
186
88
  {
187
- name: "SHA-512",
188
- securityBits: 512,
189
- quantumSafe: true,
190
- status: "SECURE",
191
- },
192
- {
193
- name: "SHA-1",
194
- securityBits: 0,
195
- quantumSafe: false,
196
- status: "BROKEN",
197
- },
198
- { name: "MD5", securityBits: 0, quantumSafe: false, status: "BROKEN" },
199
- ],
200
- };
201
- return {
202
- contents: [
203
- {
204
- uri,
205
- mimeType: "application/json",
206
- text: JSON.stringify(matrix, null, 2),
89
+ level: 5,
90
+ name: "SLH-DSA-256s",
91
+ publicKeyBytes: 64,
92
+ signatureBytes: 29792,
207
93
  },
208
94
  ],
209
- };
210
- }
211
- throw new Error(`Resource not found: ${uri}`);
95
+ },
96
+ ],
97
+ timelines: {
98
+ nsaCnsa2: {
99
+ softwareTransition: 2027,
100
+ webAndProtocols: 2030,
101
+ legacyDeprecation: 2033,
102
+ },
103
+ doraEnforcement: 2025,
104
+ cyberResilienceAct: 2027,
105
+ },
106
+ };
107
+ const ALGORITHM_MATRIX = {
108
+ symmetric: [
109
+ {
110
+ name: "AES-256-GCM",
111
+ securityBits: 256,
112
+ quantumSafe: true,
113
+ recommended: true,
114
+ },
115
+ {
116
+ name: "ChaCha20-Poly1305",
117
+ securityBits: 256,
118
+ quantumSafe: true,
119
+ recommended: true,
120
+ },
121
+ {
122
+ name: "3DES",
123
+ securityBits: 112,
124
+ quantumSafe: false,
125
+ recommended: false,
126
+ status: "DEPRECATED",
127
+ },
128
+ ],
129
+ asymmetric: [
130
+ {
131
+ name: "ML-KEM-768",
132
+ securityBits: 192,
133
+ quantumSafe: true,
134
+ recommended: true,
135
+ standard: "FIPS 203",
136
+ },
137
+ {
138
+ name: "RSA-2048",
139
+ securityBits: 112,
140
+ quantumSafe: false,
141
+ recommended: false,
142
+ status: "PHASING_OUT",
143
+ },
144
+ {
145
+ name: "RSA-4096",
146
+ securityBits: 128,
147
+ quantumSafe: false,
148
+ recommended: false,
149
+ status: "PHASING_OUT",
150
+ },
151
+ {
152
+ name: "ECDSA (P-256)",
153
+ securityBits: 128,
154
+ quantumSafe: false,
155
+ recommended: false,
156
+ status: "PHASING_OUT",
157
+ },
158
+ {
159
+ name: "Ed25519",
160
+ securityBits: 128,
161
+ quantumSafe: false,
162
+ recommended: false,
163
+ status: "PHASING_OUT",
164
+ },
165
+ ],
166
+ hashes: [
167
+ {
168
+ name: "SHA-256",
169
+ securityBits: 256,
170
+ quantumSafe: true,
171
+ status: "SECURE",
172
+ },
173
+ {
174
+ name: "SHA-512",
175
+ securityBits: 512,
176
+ quantumSafe: true,
177
+ status: "SECURE",
178
+ },
179
+ {
180
+ name: "SHA-1",
181
+ securityBits: 0,
182
+ quantumSafe: false,
183
+ status: "BROKEN",
184
+ },
185
+ { name: "MD5", securityBits: 0, quantumSafe: false, status: "BROKEN" },
186
+ ],
187
+ };
188
+ const CONTENTS = new Map([
189
+ ["crypto://standards/pqc", PQC_STANDARDS],
190
+ ["crypto://algorithms/matrix", ALGORITHM_MATRIX],
191
+ ]);
192
+ async function readResource(uri) {
193
+ const data = CONTENTS.get(uri);
194
+ if (data === undefined)
195
+ throw new Error(`Resource not found: ${uri}`);
196
+ return {
197
+ contents: [
198
+ {
199
+ uri,
200
+ mimeType: "application/json",
201
+ text: JSON.stringify(data, null, 2),
202
+ },
203
+ ],
204
+ };
212
205
  }
213
206
  //# sourceMappingURL=index.js.map
package/dist/server.d.ts CHANGED
@@ -6,7 +6,9 @@ export declare class CryptoMcpServer {
6
6
  private readonly name;
7
7
  private readonly version;
8
8
  isInitialized(): boolean;
9
+ private readonly handlers;
9
10
  handleRequest(request: JSONRPCRequest): Promise<JSONRPCResponse>;
11
+ private initialize;
10
12
  listenStdio(input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream): void;
11
13
  }
12
14
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAuB,MAAM,SAAS,CAAC;AAc/E,eAAO,MAAM,mBAAmB,QAId,CAAC;AAOnB,eAAO,MAAM,cAAc,EAAE,MAIpB,CAAC;AAEV,qBAAa,eAAe;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAKnC,aAAa,IAAI,OAAO;IAOlB,aAAa,CACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAqGpB,WAAW,CAChB,KAAK,GAAE,MAAM,CAAC,cAA8B,EAC5C,MAAM,GAAE,MAAM,CAAC,cAA+B,GAC7C,IAAI;CA0BR"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAuB,MAAM,SAAS,CAAC;AAc/E,eAAO,MAAM,mBAAmB,QAId,CAAC;AAOnB,eAAO,MAAM,cAAc,EAAE,MAIpB,CAAC;AAyBV,qBAAa,eAAe;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAKnC,aAAa,IAAI,OAAO;IAS/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAYtB;IAKU,aAAa,CACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;YAiBb,UAAU;IAoBjB,WAAW,CAChB,KAAK,GAAE,MAAM,CAAC,cAA8B,EAC5C,MAAM,GAAE,MAAM,CAAC,cAA+B,GAC7C,IAAI;CA0BR"}
package/dist/server.js CHANGED
@@ -16,6 +16,16 @@ exports.SERVER_INSTRUCTIONS = "Cryptographic tools that keep key material inside
16
16
  "encrypt, decrypt, sign, KEM and KMS tools. No tool returns a private " +
17
17
  "or secret key.";
18
18
  exports.SERVER_VERSION = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, "..", "package.json"), "utf8")).version;
19
+ const fail = (id, code, message) => ({ jsonrpc: "2.0", id, error: { code, message } });
20
+ async function callTool(params) {
21
+ const toolName = (0, protocol_1.requireName)(params, tools_1.TOOLS, "tool");
22
+ return (0, tools_1.executeTool)(toolName, (0, protocol_1.requireArguments)(params));
23
+ }
24
+ async function promptFor(params) {
25
+ const promptName = (0, protocol_1.requireName)(params, prompts_1.PROMPTS, "prompt");
26
+ const promptArgs = (0, protocol_1.requirePromptArguments)(prompts_1.PROMPTS.find((p) => p.name === promptName)?.arguments, (0, protocol_1.requireArguments)(params));
27
+ return (0, prompts_1.getPrompt)(promptName, promptArgs);
28
+ }
19
29
  class CryptoMcpServer {
20
30
  initialized = false;
21
31
  name = "crypto-service";
@@ -23,89 +33,52 @@ class CryptoMcpServer {
23
33
  isInitialized() {
24
34
  return this.initialized;
25
35
  }
36
+ handlers = new Map([
37
+ ["initialize", (params) => this.initialize(params)],
38
+ ["ping", async () => ({})],
39
+ ["tools/list", async () => ({ tools: tools_1.TOOLS })],
40
+ ["tools/call", callTool],
41
+ ["resources/list", async () => ({ resources: resources_1.RESOURCES })],
42
+ [
43
+ "resources/read",
44
+ (params) => (0, resources_1.readResource)(params ? String(params.uri) : ""),
45
+ ],
46
+ ["prompts/list", async () => ({ prompts: prompts_1.PROMPTS })],
47
+ ["prompts/get", promptFor],
48
+ ]);
26
49
  async handleRequest(request) {
27
50
  const id = request.id ?? null;
28
51
  if (!request.jsonrpc || request.jsonrpc !== "2.0") {
29
- return {
30
- jsonrpc: "2.0",
31
- id,
32
- error: {
33
- code: -32600,
34
- message: "Invalid Request: jsonrpc must be '2.0'",
35
- },
36
- };
52
+ return fail(id, -32600, "Invalid Request: jsonrpc must be '2.0'");
53
+ }
54
+ const handler = this.handlers.get(request.method);
55
+ if (!handler) {
56
+ return fail(id, -32601, `Method not found: ${request.method}`);
37
57
  }
38
58
  try {
39
- switch (request.method) {
40
- case "initialize": {
41
- this.initialized = true;
42
- const result = {
43
- protocolVersion: (0, protocol_1.negotiateProtocolVersion)(request.params?.protocolVersion),
44
- capabilities: {
45
- tools: {},
46
- resources: {},
47
- prompts: {},
48
- },
49
- serverInfo: {
50
- name: this.name,
51
- version: this.version,
52
- },
53
- instructions: exports.SERVER_INSTRUCTIONS,
54
- };
55
- return { jsonrpc: "2.0", id, result };
56
- }
57
- case "ping": {
58
- return { jsonrpc: "2.0", id, result: {} };
59
- }
60
- case "tools/list": {
61
- return { jsonrpc: "2.0", id, result: { tools: tools_1.TOOLS } };
62
- }
63
- case "tools/call": {
64
- const toolName = (0, protocol_1.requireName)(request.params, tools_1.TOOLS, "tool");
65
- const toolArgs = (0, protocol_1.requireArguments)(request.params);
66
- const result = await (0, tools_1.executeTool)(toolName, toolArgs);
67
- return { jsonrpc: "2.0", id, result };
68
- }
69
- case "resources/list": {
70
- return { jsonrpc: "2.0", id, result: { resources: resources_1.RESOURCES } };
71
- }
72
- case "resources/read": {
73
- const params = request.params;
74
- const uri = params ? String(params.uri) : "";
75
- const result = await (0, resources_1.readResource)(uri);
76
- return { jsonrpc: "2.0", id, result };
77
- }
78
- case "prompts/list": {
79
- return { jsonrpc: "2.0", id, result: { prompts: prompts_1.PROMPTS } };
80
- }
81
- case "prompts/get": {
82
- const promptName = (0, protocol_1.requireName)(request.params, prompts_1.PROMPTS, "prompt");
83
- const promptArgs = (0, protocol_1.requirePromptArguments)(prompts_1.PROMPTS.find((p) => p.name === promptName)?.arguments, (0, protocol_1.requireArguments)(request.params));
84
- const result = await (0, prompts_1.getPrompt)(promptName, promptArgs);
85
- return { jsonrpc: "2.0", id, result };
86
- }
87
- default:
88
- return {
89
- jsonrpc: "2.0",
90
- id,
91
- error: {
92
- code: -32601,
93
- message: `Method not found: ${request.method}`,
94
- },
95
- };
96
- }
59
+ return { jsonrpc: "2.0", id, result: await handler(request.params) };
97
60
  }
98
61
  catch (err) {
99
- return {
100
- jsonrpc: "2.0",
101
- id,
102
- error: {
103
- code: err instanceof protocol_1.McpError ? err.code : -32603,
104
- message: err.message,
105
- },
106
- };
62
+ const code = err instanceof protocol_1.McpError ? err.code : -32603;
63
+ return fail(id, code, err.message);
107
64
  }
108
65
  }
66
+ async initialize(params) {
67
+ this.initialized = true;
68
+ return {
69
+ protocolVersion: (0, protocol_1.negotiateProtocolVersion)(params?.protocolVersion),
70
+ capabilities: {
71
+ tools: {},
72
+ resources: {},
73
+ prompts: {},
74
+ },
75
+ serverInfo: {
76
+ name: this.name,
77
+ version: this.version,
78
+ },
79
+ instructions: exports.SERVER_INSTRUCTIONS,
80
+ };
81
+ }
109
82
  listenStdio(input = process.stdin, output = process.stdout) {
110
83
  const rl = node_readline_1.default.createInterface({
111
84
  input,
@@ -1 +1 @@
1
- {"version":3,"file":"kem.d.ts","sourceRoot":"","sources":["../../src/tools/kem.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAc,MAAM,UAAU,CAAC;AA2BnD,eAAO,MAAM,cAAc,EAAE,WAa5B,CAAC;AAGF,eAAO,MAAM,cAAc,EAAE,WAoB5B,CAAC;AAGF,eAAO,MAAM,2BAA2B,EAAE,WAoBzC,CAAC;AAGF,eAAO,MAAM,2BAA2B,EAAE,WAuBzC,CAAC;AAmBF,eAAO,MAAM,gCAAgC,EAAE,WAoC9C,CAAC;AAgEF,eAAO,MAAM,gCAAgC,EAAE,WAqB9C,CAAC"}
1
+ {"version":3,"file":"kem.d.ts","sourceRoot":"","sources":["../../src/tools/kem.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAc,MAAM,UAAU,CAAC;AA2BnD,eAAO,MAAM,cAAc,EAAE,WAa5B,CAAC;AAGF,eAAO,MAAM,cAAc,EAAE,WAoB5B,CAAC;AAGF,eAAO,MAAM,2BAA2B,EAAE,WAoBzC,CAAC;AAGF,eAAO,MAAM,2BAA2B,EAAE,WAuBzC,CAAC;AAmBF,eAAO,MAAM,gCAAgC,EAAE,WA2C9C,CAAC;AAgEF,eAAO,MAAM,gCAAgC,EAAE,WAqB9C,CAAC"}
package/dist/tools/kem.js CHANGED
@@ -24,7 +24,7 @@ function inferLevelFromKey(keyKind) {
24
24
  }
25
25
  const kemEncapsulate = async (args) => {
26
26
  const level = resolveKemLevel(args.level, 768);
27
- const { ciphertext, sharedSecret, algorithm } = (0, crypto_lib_1.mlKemEncap)(level, String(args.publicKey));
27
+ const { ciphertext, sharedSecret, algorithm } = (0, crypto_lib_1.mlKemEncapsulate)(level, String(args.publicKey));
28
28
  const keyHandle = keystore_1.keyStore.add((0, keystore_1.symmetricKey)(Buffer.from(sharedSecret, "hex"), `${algorithm} encapsulation`));
29
29
  return (0, result_1.jsonResult)({ algorithm, ciphertext, keyHandle });
30
30
  };
@@ -37,7 +37,7 @@ const kemDecapsulate = async (args) => {
37
37
  ]);
38
38
  const defaultLevel = inferLevelFromKey(key.kind);
39
39
  const level = resolveKemLevel(args.level, defaultLevel);
40
- const { sharedSecret, algorithm } = (0, crypto_lib_1.mlKemDecap)(level, key.secret.toString("hex"), String(args.ciphertext));
40
+ const { sharedSecret, algorithm } = (0, crypto_lib_1.mlKemDecapsulate)(level, key.secret.toString("hex"), String(args.ciphertext));
41
41
  const keyHandle = keystore_1.keyStore.add((0, keystore_1.symmetricKey)(Buffer.from(sharedSecret, "hex"), `${algorithm} decapsulation`));
42
42
  return (0, result_1.jsonResult)({ algorithm, keyHandle });
43
43
  };
@@ -80,6 +80,9 @@ const hybridKemMultiEncapsulateHandler = async (args) => {
80
80
  let dek;
81
81
  let keyHandle;
82
82
  if (args.keyHandle !== undefined && args.keyHandle !== null) {
83
+ if (process.env["MCP_ALLOW_KEY_EXPORT"] !== "1") {
84
+ throw new Error("Wrapping an existing keyHandle exports the key; omit keyHandle to wrap a fresh key, or set MCP_ALLOW_KEY_EXPORT=1 on the server to allow it");
85
+ }
83
86
  keyHandle = String(args.keyHandle);
84
87
  const stored = keystore_1.keyStore.use(keyHandle, ["symmetric-256"]);
85
88
  dek = Buffer.from(stored.secret);
@@ -75,7 +75,7 @@ function generateSymmetric() {
75
75
  return (0, keystore_1.symmetricKey)(node_crypto_1.default.randomBytes(32), "generated");
76
76
  }
77
77
  function generateX25519() {
78
- const pair = (0, crypto_lib_1.generateX25519KeyPair)();
78
+ const pair = (0, crypto_lib_1.x25519Keygen)();
79
79
  return {
80
80
  kind: "x25519",
81
81
  secret: Buffer.from(pair.privateKey, "hex"),
@@ -89,7 +89,7 @@ exports.STREAM_TOOLS = [
89
89
  additionalProperties: false,
90
90
  properties: {
91
91
  recipients: (0, schema_helpers_1.text)("JSON-serialized array of recipient public key objects: [{ id?, x25519PublicKey, mlKemPublicKey }]."),
92
- keyHandle: (0, schema_helpers_1.keyHandle)("Optional handle of an existing symmetric-256 key to encapsulate. If omitted, a fresh 256-bit DEK is generated."),
92
+ keyHandle: (0, schema_helpers_1.keyHandle)("Optional handle of an existing symmetric-256 key to encapsulate. Refused unless the server sets MCP_ALLOW_KEY_EXPORT=1, since it sends the key to the recipients. If omitted, a fresh 256-bit DEK is generated."),
93
93
  },
94
94
  required: ["recipients"],
95
95
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-mcp",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "Model Context Protocol (MCP) server that gives AI assistants and agents cryptography tools: key generation, encryption, ML-KEM, ML-DSA signing, hashing, streaming encryption, KMS and CBOM.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
@@ -28,9 +28,8 @@
28
28
  "dist/**/*.d.ts.map"
29
29
  ],
30
30
  "dependencies": {
31
- "@sebastienrousseau/crypto-lib": "0.0.34",
32
- "@sebastienrousseau/crypto-kms": "0.0.34",
33
- "@sebastienrousseau/crypto-wasm": "0.0.34"
31
+ "@sebastienrousseau/crypto-kms": "0.0.36",
32
+ "@sebastienrousseau/crypto-lib": "0.0.36"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@types/chai": "^5.2.3",
@@ -74,6 +73,7 @@
74
73
  "build": "tsc --build tsconfig.json",
75
74
  "clean": "rimraf ./coverage ./dist ./docs",
76
75
  "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
76
+ "test:run": "mocha --config=.mocharc.cjs",
77
77
  "docs": "typedoc",
78
78
  "lint": "eslint src __tests__",
79
79
  "lint:fix": "eslint --cache --fix src __tests__",