@sebastienrousseau/crypto-server 0.0.39 → 0.0.40

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 (80) hide show
  1. package/dist/config/openapi.d.ts +65 -0
  2. package/dist/config/openapi.d.ts.map +1 -0
  3. package/dist/config/openapi.js +84 -0
  4. package/dist/lib/lifecycle.d.ts.map +1 -1
  5. package/dist/lib/lifecycle.js +2 -1
  6. package/dist/lib/problem.d.ts +32 -0
  7. package/dist/lib/problem.d.ts.map +1 -1
  8. package/dist/lib/problem.js +45 -7
  9. package/dist/routes/index.d.ts.map +1 -1
  10. package/dist/routes/index.js +2 -0
  11. package/dist/routes/probes.d.ts +26 -0
  12. package/dist/routes/probes.d.ts.map +1 -1
  13. package/dist/routes/probes.js +79 -3
  14. package/dist/routes/v1/decrypt.d.ts.map +1 -1
  15. package/dist/routes/v1/decrypt.js +3 -2
  16. package/dist/routes/v1/encrypt.d.ts.map +1 -1
  17. package/dist/routes/v1/encrypt.js +7 -3
  18. package/dist/routes/v1/generate.d.ts.map +1 -1
  19. package/dist/routes/v1/generate.js +3 -2
  20. package/dist/routes/v1/index.d.ts.map +1 -1
  21. package/dist/routes/v1/index.js +27 -1
  22. package/dist/routes/v1/revoke.d.ts.map +1 -1
  23. package/dist/routes/v1/revoke.js +3 -2
  24. package/dist/routes/v1/verify.d.ts.map +1 -1
  25. package/dist/routes/v1/verify.js +3 -2
  26. package/dist/routes/v2/algorithms.d.ts.map +1 -1
  27. package/dist/routes/v2/algorithms.js +13 -0
  28. package/dist/routes/v2/compliance.d.ts.map +1 -1
  29. package/dist/routes/v2/compliance.js +98 -23
  30. package/dist/routes/v2/encrypt.d.ts.map +1 -1
  31. package/dist/routes/v2/encrypt.js +6 -0
  32. package/dist/routes/v2/hash.d.ts.map +1 -1
  33. package/dist/routes/v2/hash.js +6 -0
  34. package/dist/routes/v2/hpke.d.ts.map +1 -1
  35. package/dist/routes/v2/hpke.js +11 -0
  36. package/dist/routes/v2/kdf.d.ts.map +1 -1
  37. package/dist/routes/v2/kdf.js +7 -0
  38. package/dist/routes/v2/key-wrap.d.ts.map +1 -1
  39. package/dist/routes/v2/key-wrap.js +9 -2
  40. package/dist/routes/v2/keys.d.ts.map +1 -1
  41. package/dist/routes/v2/keys.js +47 -0
  42. package/dist/routes/v2/kms-responses.d.ts +61 -0
  43. package/dist/routes/v2/kms-responses.d.ts.map +1 -0
  44. package/dist/routes/v2/kms-responses.js +79 -0
  45. package/dist/routes/v2/kms.d.ts.map +1 -1
  46. package/dist/routes/v2/kms.js +7 -0
  47. package/dist/routes/v2/mac.d.ts.map +1 -1
  48. package/dist/routes/v2/mac.js +7 -0
  49. package/dist/routes/v2/multi-recipient.d.ts.map +1 -1
  50. package/dist/routes/v2/multi-recipient.js +21 -0
  51. package/dist/routes/v2/opaque.d.ts.map +1 -1
  52. package/dist/routes/v2/opaque.js +24 -0
  53. package/dist/routes/v2/password-encrypt.d.ts.map +1 -1
  54. package/dist/routes/v2/password-encrypt.js +6 -0
  55. package/dist/routes/v2/password.d.ts.map +1 -1
  56. package/dist/routes/v2/password.js +18 -0
  57. package/dist/routes/v2/pq-hash-sign.d.ts.map +1 -1
  58. package/dist/routes/v2/pq-hash-sign.js +12 -1
  59. package/dist/routes/v2/pq-sign.d.ts.map +1 -1
  60. package/dist/routes/v2/pq-sign.js +12 -1
  61. package/dist/routes/v2/pq.d.ts.map +1 -1
  62. package/dist/routes/v2/pq.js +33 -1
  63. package/dist/routes/v2/sealedbox.d.ts.map +1 -1
  64. package/dist/routes/v2/sealedbox.js +10 -0
  65. package/dist/routes/v2/secretbox.d.ts.map +1 -1
  66. package/dist/routes/v2/secretbox.js +6 -0
  67. package/dist/routes/v2/signing.d.ts.map +1 -1
  68. package/dist/routes/v2/signing.js +10 -0
  69. package/dist/routes/v2/stream-schemas.d.ts +70 -0
  70. package/dist/routes/v2/stream-schemas.d.ts.map +1 -1
  71. package/dist/routes/v2/stream-schemas.js +55 -0
  72. package/dist/server.d.ts.map +1 -1
  73. package/dist/server.js +11 -16
  74. package/dist/utils/keys.d.ts +1 -0
  75. package/dist/utils/keys.d.ts.map +1 -1
  76. package/dist/utils/keys.js +4 -0
  77. package/dist/utils/response-schemas.d.ts +92 -0
  78. package/dist/utils/response-schemas.d.ts.map +1 -0
  79. package/dist/utils/response-schemas.js +111 -0
  80. package/package.json +23 -21
@@ -33,6 +33,16 @@ export declare const SIGN_SCHEMA: {
33
33
  };
34
34
  };
35
35
  };
36
+ response: {
37
+ 200: {
38
+ type: "object";
39
+ description: string;
40
+ required: string[];
41
+ properties: {
42
+ data: unknown;
43
+ };
44
+ };
45
+ };
36
46
  };
37
47
  export declare const VERIFY_SCHEMA: {
38
48
  tags: string[];
@@ -73,6 +83,16 @@ export declare const VERIFY_SCHEMA: {
73
83
  };
74
84
  };
75
85
  };
86
+ response: {
87
+ 200: {
88
+ type: "object";
89
+ description: string;
90
+ required: string[];
91
+ properties: {
92
+ data: unknown;
93
+ };
94
+ };
95
+ };
76
96
  };
77
97
  export declare const ISO20022_SCHEMA: {
78
98
  tags: string[];
@@ -158,6 +178,16 @@ export declare const ISO20022_SCHEMA: {
158
178
  payload: {};
159
179
  };
160
180
  };
181
+ response: {
182
+ 200: {
183
+ type: "object";
184
+ description: string;
185
+ required: string[];
186
+ properties: {
187
+ data: unknown;
188
+ };
189
+ };
190
+ };
161
191
  };
162
192
  export declare const STREAM_PQ_ENCRYPT_SCHEMA: {
163
193
  tags: string[];
@@ -188,6 +218,16 @@ export declare const STREAM_PQ_ENCRYPT_SCHEMA: {
188
218
  };
189
219
  };
190
220
  };
221
+ response: {
222
+ 200: {
223
+ type: "object";
224
+ description: string;
225
+ required: string[];
226
+ properties: {
227
+ data: unknown;
228
+ };
229
+ };
230
+ };
191
231
  };
192
232
  export declare const STREAM_PQ_DECRYPT_SCHEMA: {
193
233
  tags: string[];
@@ -214,6 +254,16 @@ export declare const STREAM_PQ_DECRYPT_SCHEMA: {
214
254
  };
215
255
  };
216
256
  };
257
+ response: {
258
+ 200: {
259
+ type: "object";
260
+ description: string;
261
+ required: string[];
262
+ properties: {
263
+ data: unknown;
264
+ };
265
+ };
266
+ };
217
267
  };
218
268
  export declare const STREAM_MULTI_PQ_ENCRYPT_SCHEMA: {
219
269
  tags: string[];
@@ -261,6 +311,16 @@ export declare const STREAM_MULTI_PQ_ENCRYPT_SCHEMA: {
261
311
  };
262
312
  };
263
313
  };
314
+ response: {
315
+ 200: {
316
+ type: "object";
317
+ description: string;
318
+ required: string[];
319
+ properties: {
320
+ data: unknown;
321
+ };
322
+ };
323
+ };
264
324
  };
265
325
  export declare const STREAM_MULTI_PQ_DECRYPT_SCHEMA: {
266
326
  tags: string[];
@@ -292,5 +352,15 @@ export declare const STREAM_MULTI_PQ_DECRYPT_SCHEMA: {
292
352
  };
293
353
  };
294
354
  };
355
+ response: {
356
+ 200: {
357
+ type: "object";
358
+ description: string;
359
+ required: string[];
360
+ properties: {
361
+ data: unknown;
362
+ };
363
+ };
364
+ };
295
365
  };
296
366
  //# sourceMappingURL=stream-schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-schemas.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/stream-schemas.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BvB,CAAC;AAGF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BzB,CAAC;AAGF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuE3B,CAAC;AAGF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBpC,CAAC;AAGF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;CAepC,CAAC;AAGF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B1C,CAAC;AAGF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiB1C,CAAC"}
1
+ {"version":3,"file":"stream-schemas.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/stream-schemas.ts"],"names":[],"mappings":"AA6GA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BvB,CAAC;AAGF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BzB,CAAC;AAGF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwE3B,CAAC;AAGF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBpC,CAAC;AAGF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBpC,CAAC;AAGF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+B1C,CAAC;AAGF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkB1C,CAAC"}
@@ -2,6 +2,54 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.STREAM_MULTI_PQ_DECRYPT_SCHEMA = exports.STREAM_MULTI_PQ_ENCRYPT_SCHEMA = exports.STREAM_PQ_DECRYPT_SCHEMA = exports.STREAM_PQ_ENCRYPT_SCHEMA = exports.ISO20022_SCHEMA = exports.VERIFY_SCHEMA = exports.SIGN_SCHEMA = void 0;
4
4
  const keys_1 = require("../../utils/keys");
5
+ const response_schemas_1 = require("../../utils/response-schemas");
6
+ const SIGN_RESPONSE = (0, response_schemas_1.dataRoute)("One Ed25519 signature per item, in request order.", (0, response_schemas_1.fields)({
7
+ count: (0, response_schemas_1.integer)("Number of signatures."),
8
+ signatures: {
9
+ type: "array",
10
+ items: (0, response_schemas_1.fields)({
11
+ id: { type: "string", description: "The item's id." },
12
+ signature: (0, response_schemas_1.hex)("The 64-byte Ed25519 signature."),
13
+ algorithm: (0, response_schemas_1.literal)("ed25519", "Signature algorithm."),
14
+ }),
15
+ },
16
+ }), 404);
17
+ const VERIFY_RESPONSE = (0, response_schemas_1.dataRoute)("One result per item, in request order; a malformed item is not valid.", (0, response_schemas_1.fields)({
18
+ count: (0, response_schemas_1.integer)("Number of items."),
19
+ validCount: (0, response_schemas_1.integer)("Number of valid signatures."),
20
+ allValid: (0, response_schemas_1.flag)("Whether every signature is valid."),
21
+ results: {
22
+ type: "array",
23
+ items: (0, response_schemas_1.fields)({
24
+ id: { type: "string", description: "The item's id." },
25
+ valid: (0, response_schemas_1.flag)("Whether the item's signature is valid."),
26
+ }),
27
+ },
28
+ }));
29
+ const ISO20022_RESPONSE = (0, response_schemas_1.dataRoute)("The verdict on each part of the envelope.", (0, response_schemas_1.fields)({
30
+ valid: (0, response_schemas_1.flag)("Whether the digest and both signatures pass."),
31
+ digestMatches: (0, response_schemas_1.flag)("Whether the payload digest matches the envelope."),
32
+ classicalValid: (0, response_schemas_1.flag)("Whether the Ed25519 signature verifies."),
33
+ postQuantumValid: (0, response_schemas_1.flag)("Whether the ML-DSA signature verifies."),
34
+ messageId: { type: "string", description: "The envelope's messageId." },
35
+ }));
36
+ const PQ_ENCRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The STREAM ciphertext.", (0, response_schemas_1.fields)({
37
+ ciphertext: (0, response_schemas_1.base64)("The chunked STREAM ciphertext with its header."),
38
+ algorithm: (0, response_schemas_1.literal)("x25519-ml-kem-768-xchacha20-poly1305-stream", "Stream algorithm."),
39
+ }));
40
+ const PQ_DECRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The plaintext.", (0, response_schemas_1.fields)({ plaintext: response_schemas_1.PLAINTEXT }), 404);
41
+ const MULTI_PQ_ENCRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The multi-recipient STREAM ciphertext.", (0, response_schemas_1.fields)({
42
+ ciphertext: (0, response_schemas_1.base64)("The chunked STREAM ciphertext with one key slot per recipient."),
43
+ algorithm: (0, response_schemas_1.literal)("multi-x25519-ml-kem-768-xchacha20-poly1305-stream", "Stream algorithm."),
44
+ recipientCount: (0, response_schemas_1.integer)("Number of recipients."),
45
+ }));
46
+ const MULTI_PQ_DECRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The plaintext and the recipient slot that opened it.", (0, response_schemas_1.fields)({
47
+ plaintext: response_schemas_1.PLAINTEXT,
48
+ recipientId: {
49
+ type: "string",
50
+ description: "The recipient slot that opened the ciphertext.",
51
+ },
52
+ }), 404);
5
53
  exports.SIGN_SCHEMA = {
6
54
  tags: ["Streaming"],
7
55
  summary: "Batch sign messages with sub-millisecond throughput",
@@ -28,6 +76,7 @@ exports.SIGN_SCHEMA = {
28
76
  },
29
77
  },
30
78
  },
79
+ response: SIGN_RESPONSE,
31
80
  };
32
81
  exports.VERIFY_SCHEMA = {
33
82
  tags: ["Streaming"],
@@ -56,6 +105,7 @@ exports.VERIFY_SCHEMA = {
56
105
  },
57
106
  },
58
107
  },
108
+ response: VERIFY_RESPONSE,
59
109
  };
60
110
  exports.ISO20022_SCHEMA = {
61
111
  tags: ["Wholesale Payments"],
@@ -127,6 +177,7 @@ exports.ISO20022_SCHEMA = {
127
177
  payload: {},
128
178
  },
129
179
  },
180
+ response: ISO20022_RESPONSE,
130
181
  };
131
182
  exports.STREAM_PQ_ENCRYPT_SCHEMA = {
132
183
  tags: ["Streaming"],
@@ -143,6 +194,7 @@ exports.STREAM_PQ_ENCRYPT_SCHEMA = {
143
194
  chunkSize: { type: "integer", minimum: 64, maximum: 1048576 },
144
195
  },
145
196
  },
197
+ response: PQ_ENCRYPT_RESPONSE,
146
198
  };
147
199
  exports.STREAM_PQ_DECRYPT_SCHEMA = {
148
200
  tags: ["Streaming"],
@@ -158,6 +210,7 @@ exports.STREAM_PQ_DECRYPT_SCHEMA = {
158
210
  chunkSize: { type: "integer", minimum: 64, maximum: 1048576 },
159
211
  },
160
212
  },
213
+ response: PQ_DECRYPT_RESPONSE,
161
214
  };
162
215
  exports.STREAM_MULTI_PQ_ENCRYPT_SCHEMA = {
163
216
  tags: ["Streaming"],
@@ -187,6 +240,7 @@ exports.STREAM_MULTI_PQ_ENCRYPT_SCHEMA = {
187
240
  chunkSize: { type: "integer", minimum: 1024, maximum: 16777216 },
188
241
  },
189
242
  },
243
+ response: MULTI_PQ_ENCRYPT_RESPONSE,
190
244
  };
191
245
  exports.STREAM_MULTI_PQ_DECRYPT_SCHEMA = {
192
246
  tags: ["Streaming"],
@@ -203,5 +257,6 @@ exports.STREAM_MULTI_PQ_DECRYPT_SCHEMA = {
203
257
  chunkSize: { type: "integer", minimum: 1024, maximum: 16777216 },
204
258
  },
205
259
  },
260
+ response: MULTI_PQ_DECRYPT_RESPONSE,
206
261
  };
207
262
  //# sourceMappingURL=stream-schemas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAsDA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAoEnC,iBAAe,IAAI,CACjB,SAAS,GAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,QAAQ,CAAM,GAC3D,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CA4FlC;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AA6DA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AA+DnC,iBAAe,IAAI,CACjB,SAAS,GAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,QAAQ,CAAM,GAC3D,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CA+FlC;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
package/dist/server.js CHANGED
@@ -51,6 +51,7 @@ const logger_1 = __importStar(require("./lib/logger"));
51
51
  const auth_1 = require("./lib/auth");
52
52
  const auth_policy_1 = require("./config/auth-policy");
53
53
  const env_1 = require("./config/env");
54
+ const openapi_1 = require("./config/openapi");
54
55
  const metering_1 = require("./enterprise/metering");
55
56
  const key_store_1 = require("./lib/key-store");
56
57
  const kms_providers_1 = require("./lib/kms-providers");
@@ -63,28 +64,21 @@ const http_metrics_1 = require("./lib/http-metrics");
63
64
  const audit_1 = require("./lib/audit");
64
65
  const readiness_1 = require("./lib/readiness");
65
66
  const routes_1 = __importDefault(require("./routes"));
67
+ const probes_1 = require("./routes/probes");
68
+ const response_schemas_1 = require("./utils/response-schemas");
66
69
  const fastify = __importStar(require("fastify"));
70
+ const HEALTH_CHECK = { ...constants_1.healthCheckOptions, schemaOptions: probes_1.HEALTH_SCHEMA };
67
71
  async function registerDocs(app) {
68
72
  if (!(0, env_1.docsEnabled)())
69
73
  return;
70
74
  await app.register(swagger_1.default, {
71
75
  openapi: {
72
- info: {
73
- title: "Crypto Service Suite API",
74
- description: "REST API for low-level cryptographic operations: key generation, encryption, decryption, signing, verification, and revocation.",
75
- version: JSON.parse(constants_1.LIB_VERSION),
76
- },
77
- components: {
78
- securitySchemes: {
79
- apiKey: {
80
- type: "apiKey",
81
- name: "x-api-key",
82
- in: "header",
83
- },
84
- },
85
- },
86
- security: [{ apiKey: [] }],
76
+ ...openapi_1.OPENAPI_DOCUMENT,
77
+ info: { ...openapi_1.OPENAPI_DOCUMENT.info, version: JSON.parse(constants_1.LIB_VERSION) },
87
78
  },
79
+ transform: openapi_1.documentRoute,
80
+ transformObject: openapi_1.documentObject,
81
+ refResolver: { buildLocalReference: (json) => String(json["$id"]) },
88
82
  });
89
83
  await app.register(swagger_ui_1.default, {
90
84
  routePrefix: "/docs",
@@ -128,6 +122,7 @@ async function init(overrides = {}) {
128
122
  reply.header("Pragma", "no-cache");
129
123
  }
130
124
  });
125
+ (0, response_schemas_1.addSharedSchemas)(app);
131
126
  await registerDocs(app);
132
127
  await app
133
128
  .register(accepts_1.default, { decorateReply: true })
@@ -135,7 +130,7 @@ async function init(overrides = {}) {
135
130
  .register(cors_1.default, constants_1.corsOptions)
136
131
  .register(etag_1.default)
137
132
  .register(compress_1.default, constants_1.compressOptions)
138
- .register(fastify_healthcheck_1.default, constants_1.healthCheckOptions)
133
+ .register(fastify_healthcheck_1.default, HEALTH_CHECK)
139
134
  .register(rate_limit_1.default, {
140
135
  ...constants_1.rateLimitOptions,
141
136
  max: (0, constants_1.resolveRateLimitMax)(),
@@ -11,6 +11,7 @@ export declare const KEY_ID_SCHEMA: {
11
11
  readonly description: "Identifier of a server-held key, returned by a key-generation route.";
12
12
  };
13
13
  export declare function resolveKey(request: FastifyRequest, keyId: string, algorithms?: readonly string[]): Promise<StoredKey>;
14
+ export declare function pqSecretKey(key: StoredKey): string;
14
15
  export declare function deleteKey(request: FastifyRequest, keyId: string): Promise<void>;
15
16
  export declare function storeKey(request: FastifyRequest, algorithm: string, publicParts: KeyParts, privateParts: KeyParts): Promise<StoredKey>;
16
17
  export declare function serverPgpPrivateKey(): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/utils/keys.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAG1B,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,eAAe;QAEvB,QAAQ,EAAE,QAAQ,CAAC;KACpB;CACF;AAGD,eAAO,MAAM,aAAa;;;;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IAAI,CAAC,CAEf;AAGD,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,QAAQ,EACrB,YAAY,EAAE,QAAQ,GACrB,OAAO,CAAC,SAAS,CAAC,CASpB;AAOD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAG3D;AAGD,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEjE"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KEY_ID_SCHEMA = void 0;
4
4
  exports.resolveKey = resolveKey;
5
+ exports.pqSecretKey = pqSecretKey;
5
6
  exports.deleteKey = deleteKey;
6
7
  exports.storeKey = storeKey;
7
8
  exports.serverPgpPrivateKey = serverPgpPrivateKey;
@@ -20,6 +21,9 @@ function principalOf(request) {
20
21
  function resolveKey(request, keyId, algorithms) {
21
22
  return request.server.keyStore.get(keyId, principalOf(request), algorithms);
22
23
  }
24
+ function pqSecretKey(key) {
25
+ return key.privateParts["secretKey"] ?? key.privateParts["privateKey"];
26
+ }
23
27
  function deleteKey(request, keyId) {
24
28
  return request.server.keyStore.delete(keyId, principalOf(request));
25
29
  }
@@ -0,0 +1,92 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ export declare const HEX_PATTERN = "^([0-9a-f]{2})*$";
3
+ export declare const BASE64_PATTERN = "^[A-Za-z0-9+/]*={0,2}$";
4
+ export declare const hex: (description: string) => {
5
+ type: "string";
6
+ pattern: string;
7
+ contentEncoding: string;
8
+ description: string;
9
+ };
10
+ export declare const base64: (description: string) => {
11
+ type: "string";
12
+ pattern: string;
13
+ contentEncoding: string;
14
+ description: string;
15
+ };
16
+ export declare const text: (description: string) => {
17
+ type: "string";
18
+ description: string;
19
+ };
20
+ export declare const PLAINTEXT: {
21
+ type: "string";
22
+ description: string;
23
+ };
24
+ export declare const literal: (value: string, description: string) => {
25
+ type: "string";
26
+ enum: string[];
27
+ description: string;
28
+ };
29
+ export declare const flag: (description: string) => {
30
+ type: "boolean";
31
+ description: string;
32
+ };
33
+ export declare const integer: (description: string) => {
34
+ type: "integer";
35
+ description: string;
36
+ };
37
+ export declare const fields: (properties: Record<string, unknown>, description?: string) => {
38
+ required: string[];
39
+ properties: Record<string, unknown>;
40
+ description?: string;
41
+ type: "object";
42
+ };
43
+ export declare const dataBody: (description: string, data: unknown) => {
44
+ type: "object";
45
+ description: string;
46
+ required: string[];
47
+ properties: {
48
+ data: unknown;
49
+ };
50
+ };
51
+ export declare const ok: (description: string, data: unknown) => {
52
+ 200: {
53
+ type: "object";
54
+ description: string;
55
+ required: string[];
56
+ properties: {
57
+ data: unknown;
58
+ };
59
+ };
60
+ };
61
+ export declare const PROBLEM_ID = "Problem";
62
+ export declare function addSharedSchemas(app: FastifyInstance): void;
63
+ export declare function problems(...statuses: number[]): Record<number, Record<string, unknown>>;
64
+ export declare const BODY_ERRORS: readonly [400, 401, 403, 413, 415, 429, 500];
65
+ export declare const GET_ERRORS: readonly [401, 403, 429, 500];
66
+ export declare const bodyProblems: (...extra: number[]) => Record<number, Record<string, unknown>>;
67
+ export declare const dataRoute: (description: string, data: unknown, ...extraErrors: number[]) => {
68
+ 200: {
69
+ type: "object";
70
+ description: string;
71
+ required: string[];
72
+ properties: {
73
+ data: unknown;
74
+ };
75
+ };
76
+ };
77
+ export declare const KEY_ID: {
78
+ type: "string";
79
+ pattern: string;
80
+ description: string;
81
+ };
82
+ export declare const KEY_ALGORITHM: {
83
+ type: "string";
84
+ description: string;
85
+ };
86
+ export declare const publicKeyView: (algorithm: unknown, publicKey: unknown) => {
87
+ required: string[];
88
+ properties: Record<string, unknown>;
89
+ description?: string;
90
+ type: "object";
91
+ };
92
+ //# sourceMappingURL=response-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-schemas.d.ts","sourceRoot":"","sources":["../../src/utils/response-schemas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,eAAO,MAAM,SAAS,GACpB,aAAa,MAAM,EACnB,MAAM,OAAO,EACb,GAAG,aAAa,MAAM,EAAE;;;;;;;;;CAC0C,CAAC;AAGrE,eAAO,MAAM,MAAM;;;;CAKlB,CAAC;AAGF,eAAO,MAAM,aAAa;;;CAIzB,CAAC;AAGF,eAAO,MAAM,aAAa,GAAI,WAAW,OAAO,EAAE,WAAW,OAAO;;;;;CACnB,CAAC"}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publicKeyView = exports.KEY_ALGORITHM = exports.KEY_ID = exports.dataRoute = exports.bodyProblems = exports.GET_ERRORS = exports.BODY_ERRORS = exports.PROBLEM_ID = exports.ok = exports.dataBody = exports.fields = exports.integer = exports.flag = exports.literal = exports.PLAINTEXT = exports.text = exports.base64 = exports.hex = exports.BASE64_PATTERN = exports.HEX_PATTERN = void 0;
4
+ exports.addSharedSchemas = addSharedSchemas;
5
+ exports.problems = problems;
6
+ const key_store_1 = require("../lib/key-store");
7
+ const problem_1 = require("../lib/problem");
8
+ exports.HEX_PATTERN = "^([0-9a-f]{2})*$";
9
+ exports.BASE64_PATTERN = "^[A-Za-z0-9+/]*={0,2}$";
10
+ const hex = (description) => ({
11
+ type: "string",
12
+ pattern: exports.HEX_PATTERN,
13
+ contentEncoding: "base16",
14
+ description: `${description} Lowercase hex.`,
15
+ });
16
+ exports.hex = hex;
17
+ const base64 = (description) => ({
18
+ type: "string",
19
+ pattern: exports.BASE64_PATTERN,
20
+ contentEncoding: "base64",
21
+ description: `${description} Standard base64 (RFC 4648 section 4), padded.`,
22
+ });
23
+ exports.base64 = base64;
24
+ const text = (description) => ({
25
+ type: "string",
26
+ description: `${description} UTF-8 text.`,
27
+ });
28
+ exports.text = text;
29
+ exports.PLAINTEXT = (0, exports.text)("The decrypted bytes, decoded as UTF-8 (invalid sequences become U+FFFD).");
30
+ const literal = (value, description) => ({
31
+ type: "string",
32
+ enum: [value],
33
+ description,
34
+ });
35
+ exports.literal = literal;
36
+ const flag = (description) => ({
37
+ type: "boolean",
38
+ description,
39
+ });
40
+ exports.flag = flag;
41
+ const integer = (description) => ({
42
+ type: "integer",
43
+ description,
44
+ });
45
+ exports.integer = integer;
46
+ const fields = (properties, description) => ({
47
+ type: "object",
48
+ ...(description === undefined ? {} : { description }),
49
+ required: Object.keys(properties),
50
+ properties,
51
+ });
52
+ exports.fields = fields;
53
+ const dataBody = (description, data) => ({
54
+ type: "object",
55
+ description,
56
+ required: ["data"],
57
+ properties: { data },
58
+ });
59
+ exports.dataBody = dataBody;
60
+ const ok = (description, data) => ({
61
+ 200: (0, exports.dataBody)(description, data),
62
+ });
63
+ exports.ok = ok;
64
+ const PROBLEM_DESCRIPTIONS = {
65
+ 400: "The body failed its schema (validation-failed, with errors[]) or the input was rejected (invalid-input, key-algorithm-mismatch, request-error).",
66
+ 401: "Missing or invalid credentials (unauthorized).",
67
+ 403: "The principal lacks the scope the route requires (forbidden).",
68
+ 404: "No such key for this principal; another principal's key answers the same (key-not-found, kms-key-not-found).",
69
+ 409: "The resource is in a conflicting state (conflict, kms-key-disabled).",
70
+ 413: "The request body is larger than the server accepts (payload-too-large).",
71
+ 415: "The request media type is not supported; send application/json (request-error).",
72
+ 429: "A rate limit or quota was exceeded (rate-limited, key-quota-exceeded).",
73
+ 500: "An internal error (internal-error); the detail never carries the cause.",
74
+ 501: "The KMS provider does not implement the operation (not-implemented).",
75
+ 503: "The server is busy or a store is full; retry later (service-unavailable, key-store-full).",
76
+ };
77
+ exports.PROBLEM_ID = "Problem";
78
+ function addSharedSchemas(app) {
79
+ if (app.getSchema(exports.PROBLEM_ID) === undefined) {
80
+ app.addSchema({ $id: exports.PROBLEM_ID, ...problem_1.PROBLEM_SCHEMA });
81
+ }
82
+ }
83
+ function problems(...statuses) {
84
+ return Object.fromEntries(statuses.map((status) => [
85
+ status,
86
+ {
87
+ description: PROBLEM_DESCRIPTIONS[status],
88
+ content: {
89
+ [problem_1.PROBLEM_CONTENT_TYPE]: { schema: { $ref: `${exports.PROBLEM_ID}#` } },
90
+ },
91
+ },
92
+ ]));
93
+ }
94
+ exports.BODY_ERRORS = [400, 401, 403, 413, 415, 429, 500];
95
+ exports.GET_ERRORS = [401, 403, 429, 500];
96
+ const bodyProblems = (...extra) => problems(...exports.BODY_ERRORS, ...extra);
97
+ exports.bodyProblems = bodyProblems;
98
+ const dataRoute = (description, data, ...extraErrors) => ({ ...(0, exports.ok)(description, data), ...(0, exports.bodyProblems)(...extraErrors) });
99
+ exports.dataRoute = dataRoute;
100
+ exports.KEY_ID = {
101
+ type: "string",
102
+ pattern: key_store_1.KEY_ID_PATTERN,
103
+ description: "Identifier of the server-held key; use it with the signing, decryption and decapsulation routes.",
104
+ };
105
+ exports.KEY_ALGORITHM = {
106
+ type: "string",
107
+ description: "Algorithm of the key, e.g. ed25519, x25519, ml-kem-768, x25519-ml-kem-768, ml-dsa-65, slh-dsa-sha2-128f.",
108
+ };
109
+ const publicKeyView = (algorithm, publicKey) => (0, exports.fields)({ keyId: exports.KEY_ID, algorithm, publicKey });
110
+ exports.publicKeyView = publicKeyView;
111
+ //# sourceMappingURL=response-schemas.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-server",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "Fastify REST API for cryptography as a service: post-quantum ML-KEM and ML-DSA, encryption, signing, hashing and KMS endpoints, with OpenAPI docs, API key or JWT auth, rate limiting and OpenTelemetry.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
@@ -38,34 +38,36 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@fastify/accepts": "^5.0.7",
41
- "@fastify/compress": "^9.2.2",
42
- "@fastify/cors": "^11.3.1",
43
- "@fastify/etag": "^6.2.1",
41
+ "@fastify/compress": "^9.3.0",
42
+ "@fastify/cors": "^11.4.1",
43
+ "@fastify/etag": "^6.2.2",
44
44
  "@fastify/helmet": "^13.2.0",
45
- "@fastify/jwt": "^10.2.4",
46
- "@fastify/otel": "^0.21.3",
47
- "@fastify/rate-limit": "^11.2.1",
48
- "@fastify/swagger": "^9.9.2",
49
- "@fastify/swagger-ui": "^6.1.2",
45
+ "@fastify/jwt": "^10.2.7",
46
+ "@fastify/otel": "^0.21.4",
47
+ "@fastify/rate-limit": "^11.2.2",
48
+ "@fastify/swagger": "^9.9.3",
49
+ "@fastify/swagger-ui": "^6.1.3",
50
50
  "@opentelemetry/api": "^1.9.0",
51
- "@opentelemetry/exporter-metrics-otlp-http": "^0.223.0",
52
- "@opentelemetry/exporter-trace-otlp-http": "^0.223.0",
53
- "@opentelemetry/instrumentation-http": "^0.223.0",
54
- "@opentelemetry/resources": "^2.12.0",
55
- "@opentelemetry/sdk-metrics": "^2.12.0",
56
- "@opentelemetry/sdk-node": "^0.223.0",
57
- "@opentelemetry/semantic-conventions": "^1.43.0",
58
- "fastify": "^5.12.7",
51
+ "@opentelemetry/exporter-metrics-otlp-http": "^0.223.1",
52
+ "@opentelemetry/exporter-trace-otlp-http": "^0.223.1",
53
+ "@opentelemetry/instrumentation-http": "^0.223.1",
54
+ "@opentelemetry/resources": "^2.12.1",
55
+ "@opentelemetry/sdk-metrics": "^2.12.1",
56
+ "@opentelemetry/sdk-node": "^0.223.1",
57
+ "@opentelemetry/semantic-conventions": "^1.45.0",
58
+ "fastify": "^5.12.8",
59
59
  "fastify-healthcheck": "^5.1.0",
60
60
  "pino": "10.4.0",
61
- "@sebastienrousseau/crypto-kms": "0.0.39",
62
- "@sebastienrousseau/crypto-lib": "0.0.39"
61
+ "@sebastienrousseau/crypto-kms": "0.0.40",
62
+ "@sebastienrousseau/crypto-lib": "0.0.40"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/chai": "^5.2.3",
66
66
  "@types/chai-as-promised": "^8.0.2",
67
67
  "@types/mocha": "^10.0.10",
68
- "@types/node": "^26.6.5",
68
+ "@types/node": "^26.6.6",
69
+ "ajv": "^8.20.0",
70
+ "ajv-formats": "^3.0.1",
69
71
  "c8": "^12.0.0",
70
72
  "chai": "^6.3.0",
71
73
  "chai-as-promised": "^8.0.2",
@@ -73,7 +75,7 @@
73
75
  "mocha": "^12.0.3",
74
76
  "openpgp": "^6.3.2",
75
77
  "prettier": "^3.9.10",
76
- "rimraf": "^6.1.3",
78
+ "rimraf": "^6.1.4",
77
79
  "ts-node": "^10.9.2",
78
80
  "typedoc": "^0.28.20",
79
81
  "typescript": "~5.9.3"