@sebastienrousseau/crypto-mcp 0.0.8 → 0.0.9

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.
Files changed (45) hide show
  1. package/README.md +75 -22
  2. package/dist/protocol.d.ts +18 -0
  3. package/dist/protocol.d.ts.map +1 -0
  4. package/dist/protocol.js +63 -0
  5. package/dist/server.d.ts +1 -0
  6. package/dist/server.d.ts.map +1 -1
  7. package/dist/server.js +16 -14
  8. package/dist/tools/annotations.d.ts +6 -0
  9. package/dist/tools/annotations.d.ts.map +1 -0
  10. package/dist/tools/annotations.js +48 -0
  11. package/dist/tools/definitions.d.ts +4 -0
  12. package/dist/tools/definitions.d.ts.map +1 -1
  13. package/dist/tools/definitions.js +190 -132
  14. package/dist/tools/index.d.ts +1 -0
  15. package/dist/tools/index.d.ts.map +1 -1
  16. package/dist/tools/index.js +24 -6
  17. package/dist/tools/kem.d.ts +4 -0
  18. package/dist/tools/kem.d.ts.map +1 -0
  19. package/dist/tools/kem.js +20 -0
  20. package/dist/tools/keyimport.d.ts +5 -0
  21. package/dist/tools/keyimport.d.ts.map +1 -0
  22. package/dist/tools/keyimport.js +206 -0
  23. package/dist/tools/keys.d.ts +9 -0
  24. package/dist/tools/keys.d.ts.map +1 -1
  25. package/dist/tools/keys.js +56 -41
  26. package/dist/tools/keystore.d.ts +25 -0
  27. package/dist/tools/keystore.d.ts.map +1 -0
  28. package/dist/tools/keystore.js +81 -0
  29. package/dist/tools/kms.d.ts +1 -0
  30. package/dist/tools/kms.d.ts.map +1 -1
  31. package/dist/tools/kms.js +27 -18
  32. package/dist/tools/result.d.ts +0 -1
  33. package/dist/tools/result.d.ts.map +1 -1
  34. package/dist/tools/result.js +0 -8
  35. package/dist/tools/signing.d.ts.map +1 -1
  36. package/dist/tools/signing.js +81 -34
  37. package/dist/tools/symmetric.d.ts +1 -0
  38. package/dist/tools/symmetric.d.ts.map +1 -1
  39. package/dist/tools/symmetric.js +18 -7
  40. package/dist/tools/validate.d.ts +3 -0
  41. package/dist/tools/validate.d.ts.map +1 -0
  42. package/dist/tools/validate.js +76 -0
  43. package/dist/types.d.ts +19 -2
  44. package/dist/types.d.ts.map +1 -1
  45. package/package.json +19 -17
@@ -1,9 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TOOLS = exports.HASH_ALGORITHMS = exports.EC_CURVES = exports.RSA_MODULUS_LENGTHS = exports.KEY_TYPES = void 0;
4
- exports.KEY_TYPES = ["rsa", "ecc", "ed25519", "ml-kem-768"];
3
+ exports.TOOLS = exports.MAX_KEY_LENGTH = exports.MAX_TEXT_LENGTH = exports.HASH_ALGORITHMS = exports.MAX_KEY_FILE_BYTES = exports.KEY_DIR_ENV = exports.EC_CURVES = exports.RSA_MODULUS_LENGTHS = exports.KEY_TYPES = void 0;
4
+ const keystore_1 = require("./keystore");
5
+ const annotations_1 = require("./annotations");
6
+ exports.KEY_TYPES = [
7
+ "rsa",
8
+ "ecc",
9
+ "ed25519",
10
+ "ml-kem-768",
11
+ "symmetric-256",
12
+ "hmac-sha256",
13
+ ];
5
14
  exports.RSA_MODULUS_LENGTHS = [2048, 3072, 4096];
6
15
  exports.EC_CURVES = ["prime256v1", "secp384r1", "secp256k1"];
16
+ exports.KEY_DIR_ENV = "CRYPTO_MCP_KEY_DIR";
17
+ exports.MAX_KEY_FILE_BYTES = 65_536;
18
+ const MAX_KEY_PATH_LENGTH = 512;
19
+ const RAW_KEY_KINDS = ["symmetric-256", "hmac-sha256"];
7
20
  exports.HASH_ALGORITHMS = [
8
21
  "sha256",
9
22
  "sha384",
@@ -11,133 +24,206 @@ exports.HASH_ALGORITHMS = [
11
24
  "sha3-256",
12
25
  "blake2b512",
13
26
  ];
14
- exports.TOOLS = [
27
+ const AEAD_ALGORITHMS = ["aes-256-gcm", "chacha20-poly1305"];
28
+ const KMS_PROVIDERS = ["aws", "gcp", "azure", "vault", "local"];
29
+ exports.MAX_TEXT_LENGTH = 1_048_576;
30
+ exports.MAX_KEY_LENGTH = 16_384;
31
+ const HEX_BYTES = "^(?:[0-9a-fA-F]{2})*$";
32
+ const ML_KEM_768_PUBLIC_KEY_HEX = 2368;
33
+ const ML_KEM_768_CIPHERTEXT_HEX = 2176;
34
+ const HANDLE_NOTE = "Secret key material stays inside the server; only an opaque keyHandle is returned.";
35
+ function keyHandle(description) {
36
+ return {
37
+ type: "string",
38
+ description: `${description} Key handles look like 'kh_' followed by 32 hex characters.`,
39
+ maxLength: 35,
40
+ pattern: keystore_1.KEY_HANDLE_PATTERN,
41
+ };
42
+ }
43
+ function text(description) {
44
+ return { type: "string", description, maxLength: exports.MAX_TEXT_LENGTH };
45
+ }
46
+ function hex(description, length, upTo = false) {
47
+ return {
48
+ type: "string",
49
+ description,
50
+ minLength: upTo ? 2 : length,
51
+ maxLength: length,
52
+ pattern: HEX_BYTES,
53
+ };
54
+ }
55
+ function oneOf(description, values) {
56
+ return { type: "string", description, enum: values };
57
+ }
58
+ const KMS_PROVIDER = oneOf("KMS provider ('aws', 'gcp', 'azure', 'vault', or 'local'). Only 'local' (random, in-process key material that does not survive a restart) is configured; the others return an error.", KMS_PROVIDERS);
59
+ const KEK_LABEL = {
60
+ type: "string",
61
+ description: "Label of the Key Encryption Key (KEK). It names the key; it is never used to derive it.",
62
+ minLength: 1,
63
+ maxLength: 256,
64
+ };
65
+ const KEY_TOOLS = [
15
66
  {
16
67
  name: "crypto_generate_key",
17
- description: "Generate cryptographic keypairs for classical (RSA, ECC, Ed25519) or post-quantum (ML-KEM-768, FIPS 203) algorithms.",
68
+ description: `Generate a key inside the server: a classical (RSA, ECC, Ed25519) or post-quantum (ML-KEM-768, FIPS 203) keypair, a 256-bit symmetric key, or an HMAC-SHA256 key. Returns a keyHandle and, for keypairs, the public key. ${HANDLE_NOTE}`,
18
69
  inputSchema: {
19
70
  type: "object",
71
+ additionalProperties: false,
20
72
  properties: {
21
- type: {
22
- type: "string",
23
- description: "Key algorithm: 'rsa', 'ecc', 'ed25519', or 'ml-kem-768'.",
24
- enum: exports.KEY_TYPES,
25
- },
73
+ type: oneOf("Key type: 'rsa', 'ecc', 'ed25519', 'ml-kem-768', 'symmetric-256' (for crypto_encrypt, crypto_decrypt and crypto_kms_wrap), or 'hmac-sha256'.", exports.KEY_TYPES),
26
74
  modulusLength: {
27
- type: "number",
75
+ type: "integer",
28
76
  description: "Modulus length for RSA (2048, 3072, 4096). Default is 2048.",
77
+ enum: exports.RSA_MODULUS_LENGTHS,
29
78
  },
30
- curve: {
31
- type: "string",
32
- description: "Elliptic curve: 'prime256v1' (P-256), 'secp384r1' (P-384), or 'secp256k1'.",
33
- enum: exports.EC_CURVES,
34
- },
79
+ curve: oneOf("Elliptic curve for 'ecc': 'prime256v1' (P-256), 'secp384r1' (P-384), or 'secp256k1'. Default is 'prime256v1'.", exports.EC_CURVES),
35
80
  },
36
81
  required: ["type"],
37
82
  },
38
83
  },
39
84
  {
40
- name: "crypto_encrypt",
41
- description: "Encrypt plaintext using authenticated symmetric encryption (AES-256-GCM, ChaCha20-Poly1305) or asymmetric keys.",
85
+ name: "crypto_key_list",
86
+ description: `List the key handles this server holds, with each key's type and public metadata. At most ${keystore_1.MAX_KEYS} keys are held; beyond that the least recently used key is destroyed.`,
87
+ inputSchema: {
88
+ type: "object",
89
+ additionalProperties: false,
90
+ properties: {},
91
+ },
92
+ },
93
+ {
94
+ name: "crypto_key_destroy",
95
+ description: "Destroy a key: overwrite its secret bytes where the runtime allows and invalidate its handle.",
96
+ inputSchema: {
97
+ type: "object",
98
+ additionalProperties: false,
99
+ properties: { keyHandle: keyHandle("Handle of the key to destroy.") },
100
+ required: ["keyHandle"],
101
+ },
102
+ },
103
+ {
104
+ name: "crypto_key_import",
105
+ description: `Import an existing key from a file in the directory the server operator set in ${exports.KEY_DIR_ENV} (disabled when it is unset). Reads an unencrypted PKCS#8 PEM private key (Ed25519, RSA 2048/3072/4096, ECDSA P-256/P-384/secp256k1; the type comes from the key) or a raw 32-byte key, as 32 binary bytes or 64 hex digits, imported as 'symmetric-256' (default) or 'hmac-sha256'. Files over ${exports.MAX_KEY_FILE_BYTES} bytes are refused. The key bytes never pass through the conversation. ${HANDLE_NOTE}`,
42
106
  inputSchema: {
43
107
  type: "object",
108
+ additionalProperties: false,
44
109
  properties: {
45
- plaintext: {
110
+ path: {
46
111
  type: "string",
47
- description: "Plaintext string to encrypt.",
112
+ description: `Path of the key file, relative to ${exports.KEY_DIR_ENV}. Absolute paths, '..' segments and symlinks that lead outside the directory are refused.`,
113
+ minLength: 1,
114
+ maxLength: MAX_KEY_PATH_LENGTH,
48
115
  },
49
- algorithm: {
50
- type: "string",
51
- description: "Encryption algorithm ('aes-256-gcm' or 'chacha20-poly1305'). Default is 'aes-256-gcm'.",
52
- enum: ["aes-256-gcm", "chacha20-poly1305"],
53
- },
54
- key: {
116
+ kind: oneOf("For a raw 32-byte key only: 'symmetric-256' (crypto_encrypt, crypto_decrypt, crypto_kms_wrap; default) or 'hmac-sha256' (crypto_sign, crypto_verify).", RAW_KEY_KINDS),
117
+ },
118
+ required: ["path"],
119
+ },
120
+ },
121
+ {
122
+ name: "crypto_inspect_key",
123
+ description: "Inspect and parse PEM certificate, public key, or OpenPGP armored block.",
124
+ inputSchema: {
125
+ type: "object",
126
+ additionalProperties: false,
127
+ properties: {
128
+ keyData: {
55
129
  type: "string",
56
- description: "Hex-encoded 256-bit key (64 hex characters). If omitted, a secure 256-bit key is generated and returned.",
130
+ description: "PEM or armored key string.",
131
+ maxLength: exports.MAX_KEY_LENGTH,
57
132
  },
58
133
  },
134
+ required: ["keyData"],
135
+ },
136
+ },
137
+ ];
138
+ const CIPHER_TOOLS = [
139
+ {
140
+ name: "crypto_encrypt",
141
+ description: `Encrypt plaintext with authenticated encryption (AES-256-GCM or ChaCha20-Poly1305) under a symmetric-256 key handle. Without keyHandle, a new key is generated and its handle returned. ${HANDLE_NOTE}`,
142
+ inputSchema: {
143
+ type: "object",
144
+ additionalProperties: false,
145
+ properties: {
146
+ plaintext: text("Plaintext string to encrypt."),
147
+ algorithm: oneOf("Encryption algorithm ('aes-256-gcm' or 'chacha20-poly1305'). Default is 'aes-256-gcm'.", AEAD_ALGORITHMS),
148
+ keyHandle: keyHandle("Handle of a symmetric-256 key. If omitted, a new key is generated."),
149
+ },
59
150
  required: ["plaintext"],
60
151
  },
61
152
  },
62
153
  {
63
154
  name: "crypto_decrypt",
64
- description: "Decrypt ciphertext encrypted with authenticated AES-256-GCM or ChaCha20-Poly1305.",
155
+ description: "Decrypt and authenticate an AES-256-GCM or ChaCha20-Poly1305 ciphertext with a symmetric-256 key handle.",
65
156
  inputSchema: {
66
157
  type: "object",
158
+ additionalProperties: false,
67
159
  properties: {
68
- ciphertext: {
69
- type: "string",
70
- description: "Hex-encoded or base64-encoded ciphertext payload.",
71
- },
72
- algorithm: {
73
- type: "string",
74
- description: "Algorithm used for encryption ('aes-256-gcm' or 'chacha20-poly1305').",
75
- enum: ["aes-256-gcm", "chacha20-poly1305"],
76
- },
77
- key: {
78
- type: "string",
79
- description: "Hex-encoded 256-bit key (64 hex characters).",
80
- },
81
- iv: {
82
- type: "string",
83
- description: "Hex-encoded initialization vector / nonce.",
84
- },
85
- authTag: {
86
- type: "string",
87
- description: "Hex-encoded 128-bit authentication tag.",
88
- },
160
+ ciphertext: hex("Hex-encoded ciphertext.", 2 * exports.MAX_TEXT_LENGTH, true),
161
+ algorithm: oneOf("Algorithm used for encryption ('aes-256-gcm' or 'chacha20-poly1305'). Default is 'aes-256-gcm'.", AEAD_ALGORITHMS),
162
+ keyHandle: keyHandle("Handle of the symmetric-256 key."),
163
+ iv: hex("Hex-encoded 96-bit nonce (24 hex characters).", 24),
164
+ authTag: hex("Hex-encoded 128-bit authentication tag.", 32),
89
165
  },
90
- required: ["ciphertext", "key", "iv", "authTag"],
166
+ required: ["ciphertext", "keyHandle", "iv", "authTag"],
91
167
  },
92
168
  },
169
+ {
170
+ name: "crypto_kem_encapsulate",
171
+ description: `Encapsulate a shared secret to an ML-KEM-768 (FIPS 203) public key. Returns the KEM ciphertext for the recipient and a symmetric-256 keyHandle for the shared secret, usable with crypto_encrypt. ${HANDLE_NOTE}`,
172
+ inputSchema: {
173
+ type: "object",
174
+ additionalProperties: false,
175
+ properties: {
176
+ publicKey: hex("Hex-encoded ML-KEM-768 public key (2368 hex characters).", ML_KEM_768_PUBLIC_KEY_HEX),
177
+ },
178
+ required: ["publicKey"],
179
+ },
180
+ },
181
+ {
182
+ name: "crypto_kem_decapsulate",
183
+ description: `Recover an ML-KEM-768 shared secret with an ml-kem-768 key handle. Returns a symmetric-256 keyHandle for the shared secret. ${HANDLE_NOTE}`,
184
+ inputSchema: {
185
+ type: "object",
186
+ additionalProperties: false,
187
+ properties: {
188
+ keyHandle: keyHandle("Handle of the ml-kem-768 key."),
189
+ ciphertext: hex("Hex-encoded ML-KEM-768 ciphertext (2176 hex characters).", ML_KEM_768_CIPHERTEXT_HEX),
190
+ },
191
+ required: ["keyHandle", "ciphertext"],
192
+ },
193
+ },
194
+ ];
195
+ const SIGNATURE_TOOLS = [
93
196
  {
94
197
  name: "crypto_sign",
95
- description: "Digitally sign data using Ed25519, RSA-PSS, or HMAC.",
198
+ description: "Sign data with a key handle. The algorithm follows the key: Ed25519, RSASSA-PSS (SHA-256), ECDSA (SHA-256; SHA-384 on P-384), or HMAC-SHA256.",
96
199
  inputSchema: {
97
200
  type: "object",
201
+ additionalProperties: false,
98
202
  properties: {
99
- data: {
100
- type: "string",
101
- description: "Data string to sign.",
102
- },
103
- algorithm: {
104
- type: "string",
105
- description: "Signing algorithm ('ed25519', 'rsa-pss', or 'hmac-sha256').",
106
- enum: ["ed25519", "rsa-pss", "hmac-sha256"],
107
- },
108
- privateKey: {
109
- type: "string",
110
- description: "Private key in PEM format or secret key for HMAC.",
111
- },
203
+ data: text("Data string to sign."),
204
+ keyHandle: keyHandle("Handle of an ed25519, rsa, ecc, or hmac-sha256 key."),
112
205
  },
113
- required: ["data", "algorithm", "privateKey"],
206
+ required: ["data", "keyHandle"],
114
207
  },
115
208
  },
116
209
  {
117
210
  name: "crypto_verify",
118
- description: "Verify digital signature against original data and public key.",
211
+ description: "Verify a signature against a public key PEM (Ed25519, RSA-PSS, ECDSA) or a key handle (also HMAC-SHA256). Pass exactly one of publicKey or keyHandle.",
119
212
  inputSchema: {
120
213
  type: "object",
214
+ additionalProperties: false,
121
215
  properties: {
122
- data: {
123
- type: "string",
124
- description: "Original data string.",
125
- },
126
- signature: {
127
- type: "string",
128
- description: "Hex-encoded signature.",
129
- },
130
- algorithm: {
131
- type: "string",
132
- description: "Signing algorithm ('ed25519', 'rsa-pss', or 'hmac-sha256').",
133
- enum: ["ed25519", "rsa-pss", "hmac-sha256"],
134
- },
216
+ data: text("Original data string."),
217
+ signature: hex("Hex-encoded signature.", 1024, true),
135
218
  publicKey: {
136
219
  type: "string",
137
- description: "Public key in PEM format or secret key for HMAC.",
220
+ description: "Public key in SPKI PEM format. Private keys are refused.",
221
+ minLength: 1,
222
+ maxLength: exports.MAX_KEY_LENGTH,
138
223
  },
224
+ keyHandle: keyHandle("Handle of an ed25519, rsa, ecc, or hmac-sha256 key."),
139
225
  },
140
- required: ["data", "signature", "algorithm", "publicKey"],
226
+ required: ["data", "signature"],
141
227
  },
142
228
  },
143
229
  {
@@ -145,93 +231,65 @@ exports.TOOLS = [
145
231
  description: "Compute cryptographic digest (SHA-256, SHA-384, SHA-512, SHA3-256, BLAKE2b512).",
146
232
  inputSchema: {
147
233
  type: "object",
234
+ additionalProperties: false,
148
235
  properties: {
149
- data: {
150
- type: "string",
151
- description: "Data string to hash.",
152
- },
153
- algorithm: {
154
- type: "string",
155
- description: "Hash algorithm.",
156
- enum: exports.HASH_ALGORITHMS,
157
- },
236
+ data: text("Data string to hash."),
237
+ algorithm: oneOf("Hash algorithm.", exports.HASH_ALGORITHMS),
158
238
  },
159
239
  required: ["data"],
160
240
  },
161
241
  },
242
+ ];
243
+ const KMS_AND_AUDIT_TOOLS = [
162
244
  {
163
245
  name: "crypto_kms_wrap",
164
- description: "Wrap a Data Encryption Key (DEK) under a Key Encryption Key held by a KMS provider. Only the 'local' provider (random, in-process key material that does not survive a restart) is configured.",
246
+ description: "Wrap the Data Encryption Key (DEK) a symmetric-256 key handle refers to under a Key Encryption Key held by a KMS provider. Only the 'local' provider is configured.",
165
247
  inputSchema: {
166
248
  type: "object",
249
+ additionalProperties: false,
167
250
  properties: {
168
- provider: {
169
- type: "string",
170
- description: "KMS provider ('aws', 'gcp', 'azure', 'vault', or 'local'). Only 'local' is configured; the others return an error.",
171
- enum: ["aws", "gcp", "azure", "vault", "local"],
172
- },
173
- keyId: {
174
- type: "string",
175
- description: "Label of the Key Encryption Key (KEK). It names the key; it is never used to derive it.",
176
- },
177
- dek: {
178
- type: "string",
179
- description: "Hex-encoded 256-bit Data Encryption Key to wrap.",
180
- },
251
+ provider: KMS_PROVIDER,
252
+ keyId: KEK_LABEL,
253
+ keyHandle: keyHandle("Handle of the symmetric-256 DEK to wrap."),
181
254
  },
182
- required: ["provider", "keyId", "dek"],
255
+ required: ["provider", "keyId", "keyHandle"],
183
256
  },
184
257
  },
185
258
  {
186
259
  name: "crypto_kms_unwrap",
187
- description: "Unwrap a Data Encryption Key (DEK) previously wrapped by crypto_kms_wrap in this server process. Only the 'local' provider is configured.",
260
+ description: `Unwrap a DEK previously wrapped by crypto_kms_wrap in this server process into a symmetric-256 key handle. Only the 'local' provider is configured. ${HANDLE_NOTE}`,
188
261
  inputSchema: {
189
262
  type: "object",
263
+ additionalProperties: false,
190
264
  properties: {
191
- provider: {
192
- type: "string",
193
- description: "KMS provider ('aws', 'gcp', 'azure', 'vault', or 'local'). Only 'local' is configured; the others return an error.",
194
- enum: ["aws", "gcp", "azure", "vault", "local"],
195
- },
196
- keyId: {
197
- type: "string",
198
- description: "Key Encryption Key (KEK) identifier.",
199
- },
200
- wrappedKey: {
201
- type: "string",
202
- description: "Hex-encoded wrapped key payload.",
203
- },
265
+ provider: KMS_PROVIDER,
266
+ keyId: KEK_LABEL,
267
+ wrappedKey: hex("Hex-encoded wrapped key payload.", 1024, true),
204
268
  },
205
269
  required: ["provider", "keyId", "wrappedKey"],
206
270
  },
207
271
  },
208
- {
209
- name: "crypto_inspect_key",
210
- description: "Inspect and parse PEM certificate, public key, or OpenPGP armored block.",
211
- inputSchema: {
212
- type: "object",
213
- properties: {
214
- keyData: {
215
- type: "string",
216
- description: "PEM or armored key string.",
217
- },
218
- },
219
- required: ["keyData"],
220
- },
221
- },
222
272
  {
223
273
  name: "crypto_audit_cbom",
224
274
  description: "Generate a Cryptographic Bill of Materials (CBOM) inventory from cryptographic identifiers.",
225
275
  inputSchema: {
226
276
  type: "object",
277
+ additionalProperties: false,
227
278
  properties: {
228
279
  algorithms: {
229
280
  type: "string",
230
281
  description: "Comma-separated list of algorithm names to evaluate (e.g. 'RSA-2048,AES-256-GCM,ML-KEM-768,SHA-1').",
282
+ maxLength: 4096,
231
283
  },
232
284
  },
233
285
  required: ["algorithms"],
234
286
  },
235
287
  },
236
288
  ];
289
+ exports.TOOLS = [
290
+ ...KEY_TOOLS,
291
+ ...CIPHER_TOOLS,
292
+ ...SIGNATURE_TOOLS,
293
+ ...KMS_AND_AUDIT_TOOLS,
294
+ ].map((tool) => ({ ...tool, ...(0, annotations_1.annotationsFor)(tool.name) }));
237
295
  //# sourceMappingURL=definitions.js.map
@@ -1,4 +1,5 @@
1
1
  import { MCPCallToolResult } from "../types";
2
2
  export { TOOLS } from "./definitions";
3
+ export { validateArguments } from "./validate";
3
4
  export declare function executeTool(name: string, args?: Record<string, unknown>): Promise<MCPCallToolResult>;
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAQ7C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAmBtC,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACjC,OAAO,CAAC,iBAAiB,CAAC,CAQ5B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,UAAU,CAAC;AAYjE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAwC/C,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACjC,OAAO,CAAC,iBAAiB,CAAC,CAU5B"}
@@ -1,17 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TOOLS = void 0;
3
+ exports.validateArguments = exports.TOOLS = void 0;
4
4
  exports.executeTool = executeTool;
5
5
  const cbom_1 = require("./cbom");
6
+ const definitions_1 = require("./definitions");
7
+ const keyimport_1 = require("./keyimport");
8
+ const kem_1 = require("./kem");
6
9
  const keys_1 = require("./keys");
7
10
  const kms_1 = require("./kms");
8
11
  const result_1 = require("./result");
9
12
  const signing_1 = require("./signing");
10
13
  const symmetric_1 = require("./symmetric");
11
- var definitions_1 = require("./definitions");
12
- Object.defineProperty(exports, "TOOLS", { enumerable: true, get: function () { return definitions_1.TOOLS; } });
14
+ const validate_1 = require("./validate");
15
+ var definitions_2 = require("./definitions");
16
+ Object.defineProperty(exports, "TOOLS", { enumerable: true, get: function () { return definitions_2.TOOLS; } });
17
+ var validate_2 = require("./validate");
18
+ Object.defineProperty(exports, "validateArguments", { enumerable: true, get: function () { return validate_2.validateArguments; } });
13
19
  const HANDLERS = {
14
20
  crypto_generate_key: keys_1.generateKey,
21
+ crypto_key_list: keys_1.listKeys,
22
+ crypto_key_destroy: keys_1.destroyKey,
23
+ crypto_key_import: keyimport_1.importKey,
24
+ crypto_kem_encapsulate: kem_1.kemEncapsulate,
25
+ crypto_kem_decapsulate: kem_1.kemDecapsulate,
15
26
  crypto_encrypt: symmetric_1.encrypt,
16
27
  crypto_decrypt: symmetric_1.decrypt,
17
28
  crypto_sign: signing_1.sign,
@@ -22,12 +33,19 @@ const HANDLERS = {
22
33
  crypto_inspect_key: keys_1.inspectKey,
23
34
  crypto_audit_cbom: cbom_1.auditCbom,
24
35
  };
36
+ const REGISTRY = new Map(definitions_1.TOOLS.map((tool) => [
37
+ tool.name,
38
+ { schema: tool.inputSchema, handler: HANDLERS[tool.name] },
39
+ ]));
25
40
  async function executeTool(name, args = {}) {
26
- const handler = Object.hasOwn(HANDLERS, name) ? HANDLERS[name] : undefined;
27
- if (!handler)
41
+ const tool = REGISTRY.get(name);
42
+ if (!tool)
28
43
  return (0, result_1.errorResult)(`Unknown tool name: ${name}`);
44
+ const problem = (0, validate_1.validateArguments)(tool.schema, args);
45
+ if (problem)
46
+ return (0, result_1.errorResult)(`Invalid arguments for ${name}: ${problem}`);
29
47
  try {
30
- return await handler(args);
48
+ return await tool.handler(args);
31
49
  }
32
50
  catch (err) {
33
51
  return (0, result_1.errorResult)(`Tool error (${name}): ${err.message}`);
@@ -0,0 +1,4 @@
1
+ import { ToolHandler } from "./result";
2
+ export declare const kemEncapsulate: ToolHandler;
3
+ export declare const kemDecapsulate: ToolHandler;
4
+ //# sourceMappingURL=kem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kem.d.ts","sourceRoot":"","sources":["../../src/tools/kem.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAc,MAAM,UAAU,CAAC;AASnD,eAAO,MAAM,cAAc,EAAE,WAS5B,CAAC;AAGF,eAAO,MAAM,cAAc,EAAE,WAW5B,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kemDecapsulate = exports.kemEncapsulate = void 0;
4
+ const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
5
+ const keystore_1 = require("./keystore");
6
+ const result_1 = require("./result");
7
+ const kemEncapsulate = async (args) => {
8
+ const { ciphertext, sharedSecret, algorithm } = (0, crypto_lib_1.mlKemEncap)(768, String(args.publicKey));
9
+ const keyHandle = keystore_1.keyStore.add((0, keystore_1.symmetricKey)(Buffer.from(sharedSecret, "hex"), "ml-kem-768 encapsulation"));
10
+ return (0, result_1.jsonResult)({ algorithm, ciphertext, keyHandle });
11
+ };
12
+ exports.kemEncapsulate = kemEncapsulate;
13
+ const kemDecapsulate = async (args) => {
14
+ const key = keystore_1.keyStore.use(String(args.keyHandle), ["ml-kem-768"]);
15
+ const { sharedSecret, algorithm } = (0, crypto_lib_1.mlKemDecap)(768, key.secret.toString("hex"), String(args.ciphertext));
16
+ const keyHandle = keystore_1.keyStore.add((0, keystore_1.symmetricKey)(Buffer.from(sharedSecret, "hex"), "ml-kem-768 decapsulation"));
17
+ return (0, result_1.jsonResult)({ algorithm, keyHandle });
18
+ };
19
+ exports.kemDecapsulate = kemDecapsulate;
20
+ //# sourceMappingURL=kem.js.map
@@ -0,0 +1,5 @@
1
+ import fs from "node:fs";
2
+ import { ToolHandler } from "./result";
3
+ export declare function readAtMost(handle: Pick<fs.promises.FileHandle, "read">, max: number): Promise<Buffer>;
4
+ export declare const importKey: ToolHandler;
5
+ //# sourceMappingURL=keyimport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyimport.d.ts","sourceRoot":"","sources":["../../src/tools/keyimport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,SAAS,CAAC;AAUzB,OAAO,EAAY,WAAW,EAAc,MAAM,UAAU,CAAC;AA2F7D,wBAAsB,UAAU,CAC9B,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,EAC5C,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAajB;AAuKD,eAAO,MAAM,SAAS,EAAE,WAUvB,CAAC"}