@sebastienrousseau/crypto-server 0.0.38 → 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
@@ -4,6 +4,7 @@ const pgp_1 = require("@sebastienrousseau/crypto-lib/pgp");
4
4
  const validation_1 = require("../../utils/validation");
5
5
  const route_helpers_1 = require("../../utils/route-helpers");
6
6
  const problem_1 = require("../../lib/problem");
7
+ const response_schemas_1 = require("../../utils/response-schemas");
7
8
  const verifySchema = {
8
9
  tags: ["Signing"],
9
10
  deprecated: true,
@@ -11,6 +12,7 @@ const verifySchema = {
11
12
  description: "Verifies a clear-signed PGP message, or a message and its base64-encoded detached signature, against the supplied verification keys. `verified` is true only when every signature found verifies; input that carries no signature answers 400.",
12
13
  response: {
13
14
  200: {
15
+ description: "Whether the signature verified, with the signed text and signer key IDs.",
14
16
  type: "object",
15
17
  additionalProperties: true,
16
18
  properties: {
@@ -24,8 +26,7 @@ const verifySchema = {
24
26
  },
25
27
  },
26
28
  },
27
- 400: problem_1.PROBLEM_SCHEMA,
28
- 401: problem_1.PROBLEM_SCHEMA,
29
+ ...(0, response_schemas_1.bodyProblems)(),
29
30
  },
30
31
  body: {
31
32
  type: "object",
@@ -1 +1 @@
1
- {"version":3,"file":"algorithms.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/algorithms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAI/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAeE"}
1
+ {"version":3,"file":"algorithms.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/algorithms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAmB/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAmBE"}
@@ -1,12 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const modern_1 = require("@sebastienrousseau/crypto-lib/modern");
4
+ const response_schemas_1 = require("../../utils/response-schemas");
5
+ const IDS = { type: "array", items: { type: "string" } };
6
+ const CATALOGUE = {
7
+ type: "object",
8
+ description: "Algorithm identifiers, by category.",
9
+ required: Object.keys(modern_1.SUPPORTED_ALGORITHMS),
10
+ properties: Object.fromEntries(Object.keys(modern_1.SUPPORTED_ALGORITHMS).map((category) => [category, IDS])),
11
+ additionalProperties: IDS,
12
+ };
4
13
  exports.default = (app) => {
5
14
  app.get("/v2/algorithms", {
6
15
  schema: {
7
16
  tags: ["Algorithms"],
8
17
  summary: "List supported algorithms",
9
18
  description: "Returns all cryptographic algorithms supported by the v2 API.",
19
+ response: {
20
+ ...(0, response_schemas_1.ok)("Supported algorithms.", CATALOGUE),
21
+ ...(0, response_schemas_1.problems)(...response_schemas_1.GET_ERRORS),
22
+ },
10
23
  },
11
24
  }, async () => {
12
25
  return { data: modern_1.SUPPORTED_ALGORITHMS };
@@ -1 +1 @@
1
- {"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/compliance.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAe1D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQtD;AAGD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,aAAa,CAAC;IAE3D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAGD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC;IAC5C,QAAQ,CAAC,4BAA4B,EAAE,aAAa,CAAC;QACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,CAAC;QAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IACH,QAAQ,CAAC,sBAAsB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAChE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AA4FD,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,IAAiB,GACrB,kBAAkB,CAmBpB;AA8CD,wBAAgB,SAAS,CAAC,GAAG,GAAE,IAAiB,GAAG,WAAW,CA0B7D;yBAGe,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAyDE"}
1
+ {"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/compliance.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAuB1D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQtD;AAGD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,aAAa,CAAC;IAE3D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAGD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,0BAA0B,EAAE,MAAM,CAAC;IAC5C,QAAQ,CAAC,4BAA4B,EAAE,aAAa,CAAC;QACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,YAAY,CAAC;QAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;KACvC,CAAC,CAAC;IACH,QAAQ,CAAC,sBAAsB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAChE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AA4FD,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,IAAiB,GACrB,kBAAkB,CAmBpB;AA8CD,wBAAgB,SAAS,CAAC,GAAG,GAAE,IAAiB,GAAG,WAAW,CA0B7D;yBA4Ge,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAyCE"}
@@ -10,6 +10,7 @@ const node_crypto_1 = require("node:crypto");
10
10
  const node_fs_1 = require("node:fs");
11
11
  const node_path_1 = __importDefault(require("node:path"));
12
12
  const modern_1 = require("@sebastienrousseau/crypto-lib/modern");
13
+ const response_schemas_1 = require("../../utils/response-schemas");
13
14
  const PACKAGES_ROOT = node_path_1.default.resolve(__dirname, "..", "..", "..", "..");
14
15
  function readPackageVersion(dir) {
15
16
  try {
@@ -177,34 +178,101 @@ function buildCbom(now = new Date()) {
177
178
  components: CBOM_COMPONENTS,
178
179
  };
179
180
  }
181
+ const CYCLONEDX = "application/vnd.cyclonedx+json";
182
+ const GET_PROBLEMS = (0, response_schemas_1.problems)(...response_schemas_1.GET_ERRORS);
183
+ const STRING = { type: "string" };
184
+ const DORA = (0, response_schemas_1.fields)({
185
+ standard: (0, response_schemas_1.literal)("DORA (EU 2022/2554)", "The regulation."),
186
+ article: (0, response_schemas_1.literal)("Article 9 & Article 13", "The articles."),
187
+ status: STRING,
188
+ disclaimer: STRING,
189
+ quantumResistanceRatio: {
190
+ type: "number",
191
+ description: "Post-quantum identifiers / all identifiers, two decimals.",
192
+ },
193
+ activePrimitivesCount: (0, response_schemas_1.integer)("Algorithm identifiers listed."),
194
+ postQuantumPrimitivesCount: (0, response_schemas_1.integer)("Post-quantum identifiers listed."),
195
+ algorithmDeprecationSchedule: {
196
+ type: "array",
197
+ items: (0, response_schemas_1.fields)({
198
+ algorithm: STRING,
199
+ category: { type: "string", enum: ["symmetric", "asymmetric"] },
200
+ sunsetDate: {
201
+ type: "string",
202
+ description: "An ISO 8601 date-time, or a note such as Immediate.",
203
+ },
204
+ recommendedMigration: STRING,
205
+ }),
206
+ },
207
+ cryptographicInventory: {
208
+ type: "array",
209
+ items: (0, response_schemas_1.fields)({
210
+ package: STRING,
211
+ status: {
212
+ type: "string",
213
+ enum: ["implemented", "partial", "placeholder"],
214
+ },
215
+ fipsCompliance: {
216
+ type: "string",
217
+ description: "What the package implements (name kept for clients).",
218
+ },
219
+ version: {
220
+ type: "string",
221
+ description: "The package version, or unknown.",
222
+ },
223
+ }),
224
+ },
225
+ timestamp: {
226
+ type: "string",
227
+ format: "date-time",
228
+ description: "When the assessment was built.",
229
+ },
230
+ }, "Self-reported inventory; not a compliance verdict.");
231
+ const NAME_VALUE = (0, response_schemas_1.fields)({ name: STRING, value: STRING });
232
+ const CBOM = {
233
+ type: "object",
234
+ description: "CycloneDX 1.6 cryptographic bill of materials.",
235
+ required: [
236
+ "bomFormat",
237
+ "specVersion",
238
+ "serialNumber",
239
+ "version",
240
+ "metadata",
241
+ "components",
242
+ ],
243
+ additionalProperties: true,
244
+ properties: {
245
+ bomFormat: (0, response_schemas_1.literal)("CycloneDX", "Always CycloneDX."),
246
+ specVersion: (0, response_schemas_1.literal)("1.6", "CycloneDX specification version."),
247
+ serialNumber: {
248
+ type: "string",
249
+ pattern: "^urn:uuid:[0-9a-f-]{36}$",
250
+ description: "A fresh urn:uuid for every document.",
251
+ },
252
+ version: (0, response_schemas_1.integer)("BOM version."),
253
+ metadata: { type: "object", additionalProperties: true },
254
+ components: {
255
+ type: "array",
256
+ items: {
257
+ type: "object",
258
+ additionalProperties: true,
259
+ properties: {
260
+ type: STRING,
261
+ name: STRING,
262
+ version: STRING,
263
+ properties: { type: "array", items: NAME_VALUE },
264
+ },
265
+ },
266
+ },
267
+ },
268
+ };
180
269
  exports.default = (app) => {
181
270
  app.get("/v2/compliance/dora", {
182
271
  schema: {
183
272
  tags: ["Compliance"],
184
273
  summary: "DORA cryptographic inventory (self-assessment)",
185
274
  description: "Returns a self-reported cryptographic inventory, post-quantum algorithm counts and recommended sunset dates. It is not a compliance assessment or verdict under Regulation (EU) 2022/2554.",
186
- response: {
187
- 200: {
188
- type: "object",
189
- properties: {
190
- data: {
191
- type: "object",
192
- properties: {
193
- standard: { type: "string" },
194
- article: { type: "string" },
195
- status: { type: "string" },
196
- disclaimer: { type: "string" },
197
- quantumResistanceRatio: { type: "number" },
198
- activePrimitivesCount: { type: "number" },
199
- postQuantumPrimitivesCount: { type: "number" },
200
- algorithmDeprecationSchedule: { type: "array" },
201
- cryptographicInventory: { type: "array" },
202
- timestamp: { type: "string" },
203
- },
204
- },
205
- },
206
- },
207
- },
275
+ response: { ...(0, response_schemas_1.ok)("The self-assessment.", DORA), ...GET_PROBLEMS },
208
276
  },
209
277
  }, async () => {
210
278
  return { data: buildDoraSelfAssessment() };
@@ -214,9 +282,16 @@ exports.default = (app) => {
214
282
  tags: ["Compliance"],
215
283
  summary: "Cryptographic Bill of Materials (CBOM) in CycloneDX 1.6 format",
216
284
  description: "Emits a machine-readable CycloneDX 1.6 CBOM listing the post-quantum algorithms this service implements. It is informational input for CRA and DORA work and does not by itself establish compliance.",
285
+ response: {
286
+ 200: {
287
+ description: "A CycloneDX 1.6 document, not wrapped in data; a fresh serialNumber on every call.",
288
+ content: { [CYCLONEDX]: { schema: CBOM } },
289
+ },
290
+ ...GET_PROBLEMS,
291
+ },
217
292
  },
218
293
  }, async (_request, reply) => {
219
- reply.header("Content-Type", "application/vnd.cyclonedx+json; charset=utf-8");
294
+ reply.header("Content-Type", `${CYCLONEDX}; charset=utf-8`);
220
295
  return buildCbom();
221
296
  });
222
297
  };
@@ -1 +1 @@
1
- {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/encrypt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA4C/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA4BE"}
1
+ {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/encrypt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA6D/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA4BE"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const modern_1 = require("@sebastienrousseau/crypto-lib/modern");
4
4
  const route_helpers_1 = require("../../utils/route-helpers");
5
+ const response_schemas_1 = require("../../utils/response-schemas");
5
6
  const encryptSchema = {
6
7
  tags: ["Modern Encryption"],
7
8
  summary: "Encrypt with XChaCha20-Poly1305",
@@ -20,6 +21,10 @@ const encryptSchema = {
20
21
  plaintext: { type: "string", minLength: 1, maxLength: 10 * 1024 * 1024 },
21
22
  },
22
23
  },
24
+ response: (0, response_schemas_1.dataRoute)("The ciphertext.", (0, response_schemas_1.fields)({
25
+ ciphertext: (0, response_schemas_1.base64)("nonce (24 bytes) || ciphertext || Poly1305 tag (16 bytes)."),
26
+ algorithm: (0, response_schemas_1.literal)("xchacha20-poly1305", "AEAD algorithm."),
27
+ })),
23
28
  };
24
29
  const decryptSchema = {
25
30
  tags: ["Modern Encryption"],
@@ -34,6 +39,7 @@ const decryptSchema = {
34
39
  ciphertext: { type: "string", minLength: 1 },
35
40
  },
36
41
  },
42
+ response: (0, response_schemas_1.dataRoute)("The plaintext.", (0, response_schemas_1.fields)({ plaintext: response_schemas_1.PLAINTEXT })),
37
43
  };
38
44
  exports.default = (app) => {
39
45
  app.post("/v2/encrypt", { schema: encryptSchema }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/hash.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAqB/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAiBE"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/hash.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA8B/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAiBE"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const modern_1 = require("@sebastienrousseau/crypto-lib/modern");
4
4
  const route_helpers_1 = require("../../utils/route-helpers");
5
+ const response_schemas_1 = require("../../utils/response-schemas");
5
6
  const hashSchema = {
6
7
  tags: ["Hashing"],
7
8
  summary: "Compute a cryptographic hash",
@@ -15,6 +16,11 @@ const hashSchema = {
15
16
  data: { type: "string", minLength: 1, maxLength: 10 * 1024 * 1024 },
16
17
  },
17
18
  },
19
+ response: (0, response_schemas_1.dataRoute)("The digest of the UTF-8 bytes of data.", (0, response_schemas_1.fields)({
20
+ digest: (0, response_schemas_1.hex)("The digest."),
21
+ algorithm: { type: "string", enum: [...modern_1.HASH_ALGORITHMS] },
22
+ length: (0, response_schemas_1.integer)("Digest length in bytes."),
23
+ })),
18
24
  };
19
25
  exports.default = (app) => {
20
26
  app.post("/v2/hash", { schema: hashSchema }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/hpke.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA+L/C,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAI5D"}
1
+ {"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/hpke.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAiO/C,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAI5D"}
@@ -36,6 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.default = hpkeRoute;
37
37
  const route_helpers_1 = require("../../utils/route-helpers");
38
38
  const keys_1 = require("../../utils/keys");
39
+ const response_schemas_1 = require("../../utils/response-schemas");
40
+ const KEMS = ["x25519", "p256", "x-wing", "x25519-ml-kem-768"];
39
41
  const loadHpke = async () => await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
40
42
  function ensureHex(text) {
41
43
  const isHex = /^[0-9a-fA-F]*$/.test(text) && text.length % 2 === 0;
@@ -55,6 +57,7 @@ const KEYGEN_SCHEMA = {
55
57
  },
56
58
  },
57
59
  },
60
+ response: (0, response_schemas_1.dataRoute)("The keyId and public key of the new server-held HPKE key pair.", (0, response_schemas_1.publicKeyView)({ type: "string", enum: KEMS, description: "The KEM." }, (0, response_schemas_1.hex)("The KEM public key.")), 503),
58
61
  };
59
62
  const SEAL_SCHEMA = {
60
63
  tags: ["HPKE"],
@@ -77,6 +80,10 @@ const SEAL_SCHEMA = {
77
80
  pskId: { type: "string" },
78
81
  },
79
82
  },
83
+ response: (0, response_schemas_1.dataRoute)("The HPKE ciphertext and encapsulated key; send both to the recipient.", (0, response_schemas_1.fields)({
84
+ ciphertext: (0, response_schemas_1.hex)("The AEAD ciphertext, tag included."),
85
+ encapsulatedKey: (0, response_schemas_1.hex)("The KEM encapsulated key (enc)."),
86
+ })),
80
87
  };
81
88
  const OPEN_SCHEMA = {
82
89
  tags: ["HPKE"],
@@ -96,6 +103,10 @@ const OPEN_SCHEMA = {
96
103
  pskId: { type: "string" },
97
104
  },
98
105
  },
106
+ response: (0, response_schemas_1.dataRoute)("The plaintext, as text and as the raw bytes.", (0, response_schemas_1.fields)({
107
+ plaintext: response_schemas_1.PLAINTEXT,
108
+ hex: (0, response_schemas_1.hex)("The decrypted bytes."),
109
+ }), 404),
99
110
  };
100
111
  function registerKeygen(app) {
101
112
  app.post("/v2/hpke/keygen", { schema: KEYGEN_SCHEMA }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"kdf.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kdf.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAc/C,eAAO,MAAM,UAAU;;;;EAIrB,CAAC;yBA+Ca,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAqBE"}
1
+ {"version":3,"file":"kdf.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kdf.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAe/C,eAAO,MAAM,UAAU;;;;EAIrB,CAAC;yBA0Da,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAqBE"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KDF_FLOORS = void 0;
4
4
  const modern_1 = require("@sebastienrousseau/crypto-lib/modern");
5
5
  const route_helpers_1 = require("../../utils/route-helpers");
6
+ const response_schemas_1 = require("../../utils/response-schemas");
6
7
  exports.KDF_FLOORS = Object.freeze({
7
8
  scryptN: 131072,
8
9
  scryptR: 8,
@@ -46,6 +47,12 @@ const kdfSchema = {
46
47
  },
47
48
  },
48
49
  },
50
+ response: (0, response_schemas_1.dataRoute)("The derived key.", (0, response_schemas_1.fields)({
51
+ derivedKey: (0, response_schemas_1.hex)("The derived key."),
52
+ salt: (0, response_schemas_1.hex)("The salt used: the request's, or 16 random bytes."),
53
+ algorithm: { type: "string", enum: [...modern_1.KDF_ALGORITHMS] },
54
+ keyLength: (0, response_schemas_1.integer)("Derived key length in bytes."),
55
+ }), 503),
49
56
  };
50
57
  exports.default = (app) => {
51
58
  app.post("/v2/kdf", { schema: kdfSchema }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"key-wrap.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/key-wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAwF/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
1
+ {"version":3,"file":"key-wrap.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/key-wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAuG/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
@@ -34,6 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const route_helpers_1 = require("../../utils/route-helpers");
37
+ const response_schemas_1 = require("../../utils/response-schemas");
38
+ const KW_ALGORITHM = { type: "string", enum: ["aes-kw", "aes-kwp"] };
37
39
  function registerKeysWrap(app) {
38
40
  app.post("/v2/keys/wrap", {
39
41
  schema: {
@@ -46,9 +48,13 @@ function registerKeysWrap(app) {
46
48
  properties: {
47
49
  kek: { type: "string", minLength: 1 },
48
50
  keyToWrap: { type: "string", minLength: 1 },
49
- algorithm: { type: "string", enum: ["aes-kw", "aes-kwp"] },
51
+ algorithm: KW_ALGORITHM,
50
52
  },
51
53
  },
54
+ response: (0, response_schemas_1.dataRoute)("The wrapped key.", (0, response_schemas_1.fields)({
55
+ wrapped: (0, response_schemas_1.base64)("The wrapped key (RFC 3394 / RFC 5649 output)."),
56
+ algorithm: KW_ALGORITHM,
57
+ })),
52
58
  },
53
59
  }, async (request, reply) => {
54
60
  try {
@@ -76,9 +82,10 @@ function registerKeysUnwrap(app) {
76
82
  properties: {
77
83
  kek: { type: "string", minLength: 1 },
78
84
  wrappedKey: { type: "string", minLength: 1 },
79
- algorithm: { type: "string", enum: ["aes-kw", "aes-kwp"] },
85
+ algorithm: KW_ALGORITHM,
80
86
  },
81
87
  },
88
+ response: (0, response_schemas_1.dataRoute)("The unwrapped key; data is the key itself, not an object.", (0, response_schemas_1.hex)("The unwrapped key.")),
82
89
  },
83
90
  }, async (request, reply) => {
84
91
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/keys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA4I/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAIE"}
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/keys.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA8N/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAIE"}
@@ -35,6 +35,43 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const keys_1 = require("@sebastienrousseau/crypto-lib/keys");
37
37
  const keys_2 = require("../../utils/keys");
38
+ const response_schemas_1 = require("../../utils/response-schemas");
39
+ const KEY_METADATA = {
40
+ type: "object",
41
+ description: "Key metadata: the request's, with kid always set.",
42
+ required: ["kid"],
43
+ properties: {
44
+ kid: { type: "string", description: "Key identifier (JWK kid)." },
45
+ use: { type: "string", enum: ["sig", "enc"] },
46
+ exp: { type: "string", description: "Expiry, as the request gave it." },
47
+ },
48
+ };
49
+ const GENERATE_RESPONSE = (0, response_schemas_1.dataRoute)("The keyId and public key of the new server-held key pair.", (0, response_schemas_1.fields)({
50
+ keyId: response_schemas_1.KEY_ID,
51
+ algorithm: { type: "string", enum: [...keys_1.KEY_ALGORITHMS] },
52
+ publicKey: (0, response_schemas_1.hex)("The public key."),
53
+ kid: {
54
+ type: "string",
55
+ description: "Key identifier: the request's metadata.kid, or base64url of the first 16 bytes of SHA-256(public key).",
56
+ },
57
+ metadata: KEY_METADATA,
58
+ }), 503);
59
+ const EXPORT_RESPONSE = (0, response_schemas_1.dataRoute)("The public and private parts of a server-held key.", {
60
+ type: "object",
61
+ required: ["keyId", "algorithm"],
62
+ properties: {
63
+ keyId: response_schemas_1.KEY_ID,
64
+ algorithm: response_schemas_1.KEY_ALGORITHM,
65
+ publicKey: (0, response_schemas_1.hex)("Public key (single-key algorithms)."),
66
+ x25519PublicKey: (0, response_schemas_1.hex)("X25519 public key (x25519-ml-kem-768)."),
67
+ mlKemPublicKey: (0, response_schemas_1.hex)("ML-KEM-768 public key (x25519-ml-kem-768)."),
68
+ privateKey: (0, response_schemas_1.hex)("Private key (POST /v2/keys/generate and POST /v2/hpke/keygen)."),
69
+ secretKey: (0, response_schemas_1.hex)("Secret key (POST /v2/pq/keygen, /v2/pq/dsa/keygen, /v2/pq/slh-dsa/keygen)."),
70
+ x25519PrivateKey: (0, response_schemas_1.hex)("X25519 private key (x25519-ml-kem-768)."),
71
+ mlKemSecretKey: (0, response_schemas_1.hex)("ML-KEM-768 secret key (x25519-ml-kem-768)."),
72
+ },
73
+ additionalProperties: (0, response_schemas_1.hex)("Another key part."),
74
+ }, 404);
38
75
  function registerGenerate(app) {
39
76
  app.post("/v2/keys/generate", {
40
77
  schema: {
@@ -61,6 +98,7 @@ function registerGenerate(app) {
61
98
  },
62
99
  },
63
100
  },
101
+ response: GENERATE_RESPONSE,
64
102
  },
65
103
  }, async (request, reply) => {
66
104
  const { algorithm, metadata } = request.body;
@@ -85,6 +123,7 @@ function registerExport(app) {
85
123
  additionalProperties: false,
86
124
  properties: { keyId: keys_2.KEY_ID_SCHEMA },
87
125
  },
126
+ response: EXPORT_RESPONSE,
88
127
  },
89
128
  }, async (request, reply) => {
90
129
  const { keyId } = request.body;
@@ -107,6 +146,14 @@ function registerDelete(app) {
107
146
  additionalProperties: false,
108
147
  properties: { keyId: keys_2.KEY_ID_SCHEMA },
109
148
  },
149
+ response: (0, response_schemas_1.dataRoute)("The key is deleted.", (0, response_schemas_1.fields)({
150
+ keyId: response_schemas_1.KEY_ID,
151
+ deleted: {
152
+ type: "boolean",
153
+ enum: [true],
154
+ description: "Always true.",
155
+ },
156
+ }), 404),
110
157
  },
111
158
  }, async (request, reply) => {
112
159
  const { keyId } = request.body;
@@ -0,0 +1,61 @@
1
+ export declare const CREATE_KEY_RESPONSE: {
2
+ 200: {
3
+ type: "object";
4
+ description: string;
5
+ required: string[];
6
+ properties: {
7
+ data: unknown;
8
+ };
9
+ };
10
+ };
11
+ export declare const WRAP_RESPONSE: {
12
+ 200: {
13
+ type: "object";
14
+ description: string;
15
+ required: string[];
16
+ properties: {
17
+ data: unknown;
18
+ };
19
+ };
20
+ };
21
+ export declare const UNWRAP_RESPONSE: {
22
+ 200: {
23
+ type: "object";
24
+ description: string;
25
+ required: string[];
26
+ properties: {
27
+ data: unknown;
28
+ };
29
+ };
30
+ };
31
+ export declare const DATA_KEY_RESPONSE: {
32
+ 200: {
33
+ type: "object";
34
+ description: string;
35
+ required: string[];
36
+ properties: {
37
+ data: unknown;
38
+ };
39
+ };
40
+ };
41
+ export declare const ENCRYPT_RESPONSE: {
42
+ 200: {
43
+ type: "object";
44
+ description: string;
45
+ required: string[];
46
+ properties: {
47
+ data: unknown;
48
+ };
49
+ };
50
+ };
51
+ export declare const DECRYPT_RESPONSE: {
52
+ 200: {
53
+ type: "object";
54
+ description: string;
55
+ required: string[];
56
+ properties: {
57
+ data: unknown;
58
+ };
59
+ };
60
+ };
61
+ //# sourceMappingURL=kms-responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kms-responses.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kms-responses.ts"],"names":[],"mappings":"AA4CA,eAAO,MAAM,mBAAmB;;;;;;;;;CA4B/B,CAAC;AAGF,eAAO,MAAM,aAAa;;;;;;;;;CAQzB,CAAC;AAGF,eAAO,MAAM,eAAe;;;;;;;;;CAQ3B,CAAC;AAGF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAGF,eAAO,MAAM,gBAAgB;;;;;;;;;CAkB5B,CAAC;AAGF,eAAO,MAAM,gBAAgB;;;;;;;;;CAS5B,CAAC"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DECRYPT_RESPONSE = exports.ENCRYPT_RESPONSE = exports.DATA_KEY_RESPONSE = exports.UNWRAP_RESPONSE = exports.WRAP_RESPONSE = exports.CREATE_KEY_RESPONSE = void 0;
4
+ const response_schemas_1 = require("../../utils/response-schemas");
5
+ const KEY_ID = {
6
+ type: "string",
7
+ description: "The provider's key identifier (local keys: local-<hex>).",
8
+ };
9
+ const PROVIDER = {
10
+ type: "string",
11
+ description: "The provider that served the request (local, aws, gcp, vault).",
12
+ };
13
+ const OPAQUE = (description) => ({
14
+ type: "string",
15
+ description: `${description} Opaque, provider-specific string; pass it back unchanged.`,
16
+ });
17
+ const KEY_ERRORS = [404, 409, 501, 503];
18
+ exports.CREATE_KEY_RESPONSE = (0, response_schemas_1.dataRoute)("The new key's metadata.", {
19
+ type: "object",
20
+ required: [
21
+ "keyId",
22
+ "algorithm",
23
+ "usage",
24
+ "createdAt",
25
+ "enabled",
26
+ "provider",
27
+ ],
28
+ properties: {
29
+ keyId: KEY_ID,
30
+ algorithm: { type: "string", description: "Key algorithm." },
31
+ usage: { type: "string", enum: ["encrypt", "sign", "wrap"] },
32
+ createdAt: {
33
+ type: "string",
34
+ format: "date-time",
35
+ description: "Creation time, ISO 8601.",
36
+ },
37
+ enabled: (0, response_schemas_1.flag)("Whether the key is enabled."),
38
+ provider: PROVIDER,
39
+ currentVersion: (0, response_schemas_1.integer)("Current key version, when versioned."),
40
+ },
41
+ }, 501, 503);
42
+ exports.WRAP_RESPONSE = (0, response_schemas_1.dataRoute)("The wrapped key.", (0, response_schemas_1.fields)({
43
+ wrappedKey: OPAQUE("The wrapped key."),
44
+ keyId: KEY_ID,
45
+ provider: PROVIDER,
46
+ }), ...KEY_ERRORS);
47
+ exports.UNWRAP_RESPONSE = (0, response_schemas_1.dataRoute)("The unwrapped key.", (0, response_schemas_1.fields)({
48
+ unwrappedKey: (0, response_schemas_1.hex)("The unwrapped key bytes."),
49
+ keyId: KEY_ID,
50
+ provider: PROVIDER,
51
+ }), ...KEY_ERRORS);
52
+ exports.DATA_KEY_RESPONSE = (0, response_schemas_1.dataRoute)("A data key, in the clear and wrapped by the KMS key.", (0, response_schemas_1.fields)({
53
+ plaintext: (0, response_schemas_1.hex)("The data key bytes; use, then discard."),
54
+ ciphertext: OPAQUE("The data key, encrypted by the KMS key."),
55
+ keyId: KEY_ID,
56
+ provider: PROVIDER,
57
+ }), ...KEY_ERRORS);
58
+ exports.ENCRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The ciphertext.", {
59
+ type: "object",
60
+ required: ["ciphertext", "keyId", "provider"],
61
+ properties: {
62
+ ciphertext: OPAQUE("The ciphertext."),
63
+ keyId: KEY_ID,
64
+ keyVersion: (0, response_schemas_1.integer)("Key version used, when versioned."),
65
+ context: {
66
+ type: "object",
67
+ additionalProperties: { type: "string" },
68
+ description: "Encryption context, when the provider echoes it.",
69
+ },
70
+ provider: PROVIDER,
71
+ },
72
+ }, ...KEY_ERRORS);
73
+ exports.DECRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The plaintext, as text and as the raw bytes.", (0, response_schemas_1.fields)({
74
+ plaintext: response_schemas_1.PLAINTEXT,
75
+ hex: (0, response_schemas_1.hex)("The decrypted bytes."),
76
+ keyId: KEY_ID,
77
+ provider: PROVIDER,
78
+ }), ...KEY_ERRORS);
79
+ //# sourceMappingURL=kms-responses.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAS7E,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,eAAe;QAEvB,GAAG,EAAE,WAAW,CAAC;QAEjB,SAAS,EAAE,SAAS,CAAC;KACtB;CACF;AAwYD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAO3D"}
1
+ {"version":3,"file":"kms.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/kms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAS7E,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAWtD,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,eAAe;QAEvB,GAAG,EAAE,WAAW,CAAC;QAEjB,SAAS,EAAE,SAAS,CAAC;KACtB;CACF;AA8YD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CAO3D"}