@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
@@ -7,6 +7,7 @@ const auth_1 = require("../../lib/auth");
7
7
  const problem_1 = require("../../lib/problem");
8
8
  const kms_providers_1 = require("../../lib/kms-providers");
9
9
  const audit_1 = require("../../lib/audit");
10
+ const kms_responses_1 = require("./kms-responses");
10
11
  class KmsKeyNotOwnedError extends Error {
11
12
  name = "KmsKeyNotOwnedError";
12
13
  }
@@ -82,6 +83,7 @@ const CREATE_KEY_SCHEMA = {
82
83
  metadata: { type: "object", additionalProperties: { type: "string" } },
83
84
  },
84
85
  },
86
+ response: kms_responses_1.CREATE_KEY_RESPONSE,
85
87
  };
86
88
  const WRAP_SCHEMA = {
87
89
  tags: ["KMS"],
@@ -101,6 +103,7 @@ const WRAP_SCHEMA = {
101
103
  context: { type: "object", additionalProperties: { type: "string" } },
102
104
  },
103
105
  },
106
+ response: kms_responses_1.WRAP_RESPONSE,
104
107
  };
105
108
  const UNWRAP_SCHEMA = {
106
109
  tags: ["KMS"],
@@ -116,6 +119,7 @@ const UNWRAP_SCHEMA = {
116
119
  context: { type: "object", additionalProperties: { type: "string" } },
117
120
  },
118
121
  },
122
+ response: kms_responses_1.UNWRAP_RESPONSE,
119
123
  };
120
124
  const DATA_KEY_SCHEMA = {
121
125
  tags: ["KMS"],
@@ -130,6 +134,7 @@ const DATA_KEY_SCHEMA = {
130
134
  keySpec: { type: "string" },
131
135
  },
132
136
  },
137
+ response: kms_responses_1.DATA_KEY_RESPONSE,
133
138
  };
134
139
  const ENCRYPT_SCHEMA = {
135
140
  tags: ["KMS"],
@@ -150,6 +155,7 @@ const ENCRYPT_SCHEMA = {
150
155
  context: { type: "object", additionalProperties: { type: "string" } },
151
156
  },
152
157
  },
158
+ response: kms_responses_1.ENCRYPT_RESPONSE,
153
159
  };
154
160
  const DECRYPT_SCHEMA = {
155
161
  tags: ["KMS"],
@@ -165,6 +171,7 @@ const DECRYPT_SCHEMA = {
165
171
  context: { type: "object", additionalProperties: { type: "string" } },
166
172
  },
167
173
  },
174
+ response: kms_responses_1.DECRYPT_RESPONSE,
168
175
  };
169
176
  function registerCreateKey(app) {
170
177
  app.post("/v2/kms/create-key", {
@@ -1 +1 @@
1
- {"version":3,"file":"mac.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/mac.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAgG/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
1
+ {"version":3,"file":"mac.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/mac.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA+G/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
@@ -34,7 +34,9 @@ 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");
37
38
  const HMAC_ALGORITHMS = ["sha256", "sha384", "sha512", "sha3-256", "sha3-512"];
39
+ const HMAC_ALGORITHM = { type: "string", enum: HMAC_ALGORITHMS };
38
40
  function registerHmac(app) {
39
41
  app.post("/v2/hmac", {
40
42
  schema: {
@@ -50,6 +52,7 @@ function registerHmac(app) {
50
52
  data: { type: "string", minLength: 1 },
51
53
  },
52
54
  },
55
+ response: (0, response_schemas_1.dataRoute)("The HMAC of the UTF-8 bytes of data, keyed with the hex key (at least 16 bytes).", (0, response_schemas_1.fields)({ mac: (0, response_schemas_1.hex)("The tag."), algorithm: HMAC_ALGORITHM })),
53
56
  },
54
57
  }, async (request, reply) => {
55
58
  try {
@@ -83,6 +86,10 @@ function registerHmacVerify(app) {
83
86
  mac: { type: "string", minLength: 1 },
84
87
  },
85
88
  },
89
+ response: (0, response_schemas_1.dataRoute)("Whether the tag matches, compared in constant time.", (0, response_schemas_1.fields)({
90
+ valid: (0, response_schemas_1.flag)("Whether the tag matches."),
91
+ algorithm: HMAC_ALGORITHM,
92
+ })),
86
93
  },
87
94
  config: { rateLimit: { max: 100, timeWindow: "1 minute" } },
88
95
  }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"multi-recipient.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/multi-recipient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAuB/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAiDE"}
1
+ {"version":3,"file":"multi-recipient.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/multi-recipient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA2D/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAkDE"}
@@ -34,6 +34,26 @@ 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 WRAPPED_FOR = {
39
+ type: "object",
40
+ required: ["type", "wrappedKey", "ephemeralPublicKey"],
41
+ properties: {
42
+ type: {
43
+ type: "string",
44
+ enum: ["x25519", "x25519-ml-kem-768"],
45
+ description: "x25519 for a classical recipient, x25519-ml-kem-768 for a pq one.",
46
+ },
47
+ wrappedKey: (0, response_schemas_1.base64)("The content key, wrapped for this recipient."),
48
+ ephemeralPublicKey: (0, response_schemas_1.hex)("The sender's ephemeral X25519 public key."),
49
+ mlKemCiphertext: (0, response_schemas_1.hex)("The ML-KEM-768 ciphertext (pq recipients only)."),
50
+ },
51
+ };
52
+ const ENCRYPT_RESPONSE = (0, response_schemas_1.dataRoute)("The ciphertext and one wrapped key per recipient, in request order.", (0, response_schemas_1.fields)({
53
+ ciphertext: (0, response_schemas_1.base64)("The content, sealed with XChaCha20-Poly1305 under a random key."),
54
+ recipients: { type: "array", items: WRAPPED_FOR },
55
+ algorithm: (0, response_schemas_1.literal)("multi-recipient-secretbox", "Envelope algorithm."),
56
+ }));
37
57
  function toLibRecipient(r) {
38
58
  if (r.type === "classical") {
39
59
  return { type: "x25519", publicKey: r.publicKey };
@@ -73,6 +93,7 @@ exports.default = (app) => {
73
93
  },
74
94
  },
75
95
  },
96
+ response: ENCRYPT_RESPONSE,
76
97
  },
77
98
  }, async (request, reply) => {
78
99
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"opaque.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/opaque.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;yBAyS7D,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
1
+ {"version":3,"file":"opaque.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/opaque.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;yBA+V7D,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
@@ -5,6 +5,8 @@ const problem_1 = require("../../lib/problem");
5
5
  const route_helpers_1 = require("../../utils/route-helpers");
6
6
  const auth_1 = require("../../lib/auth");
7
7
  const opaque_store_1 = require("../../lib/opaque-store");
8
+ const response_schemas_1 = require("../../utils/response-schemas");
9
+ const LOGIN_PROBLEMS = (0, response_schemas_1.problems)(400, 413, 415, 429, 500, 503);
8
10
  const { pake } = crypto_lib_1.protocols;
9
11
  function parseHex(hex) {
10
12
  if (hex.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(hex)) {
@@ -47,6 +49,7 @@ const REGISTER_INIT_SCHEMA = {
47
49
  suite: { type: "string", enum: SUPPORTED_SUITES },
48
50
  },
49
51
  },
52
+ response: (0, response_schemas_1.dataRoute)("The server's registration response.", (0, response_schemas_1.fields)({ response: (0, response_schemas_1.hex)("The serialized RegistrationResponse.") }), 503),
50
53
  };
51
54
  const REGISTER_FINISH_SCHEMA = {
52
55
  tags: ["OPAQUE"],
@@ -62,6 +65,13 @@ const REGISTER_FINISH_SCHEMA = {
62
65
  suite: { type: "string", enum: SUPPORTED_SUITES },
63
66
  },
64
67
  },
68
+ response: (0, response_schemas_1.dataRoute)("The credential is registered.", (0, response_schemas_1.fields)({
69
+ status: (0, response_schemas_1.literal)("registered", "Always registered."),
70
+ credentialIdentifier: {
71
+ type: "string",
72
+ description: "The identifier, as the request gave it.",
73
+ },
74
+ }), 409, 503),
65
75
  };
66
76
  const LOGIN_INIT_SCHEMA = {
67
77
  tags: ["OPAQUE"],
@@ -77,6 +87,16 @@ const LOGIN_INIT_SCHEMA = {
77
87
  suite: { type: "string", enum: SUPPORTED_SUITES },
78
88
  },
79
89
  },
90
+ response: {
91
+ ...(0, response_schemas_1.ok)("KE2 and the login session to finish.", (0, response_schemas_1.fields)({
92
+ sessionId: {
93
+ type: "string",
94
+ description: "Single-use login session identifier; pass it to /v2/opaque/login/finish.",
95
+ },
96
+ ke2: (0, response_schemas_1.hex)("The serialized KE2 message."),
97
+ })),
98
+ ...LOGIN_PROBLEMS,
99
+ },
80
100
  };
81
101
  const LOGIN_FINISH_SCHEMA = {
82
102
  tags: ["OPAQUE"],
@@ -91,6 +111,10 @@ const LOGIN_FINISH_SCHEMA = {
91
111
  ke3: { type: "string", minLength: 2, pattern: "^[0-9a-fA-F]+$" },
92
112
  },
93
113
  },
114
+ response: {
115
+ ...(0, response_schemas_1.ok)("The shared session key; the client derives the same key.", (0, response_schemas_1.fields)({ sessionKey: (0, response_schemas_1.hex)("The session key.") })),
116
+ ...LOGIN_PROBLEMS,
117
+ },
94
118
  };
95
119
  function registerRegisterInit(app) {
96
120
  app.post("/v2/opaque/register/init", { ...OPAQUE_RATE_LIMIT, schema: REGISTER_INIT_SCHEMA }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"password-encrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/password-encrypt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAoF/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
1
+ {"version":3,"file":"password-encrypt.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/password-encrypt.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA8G/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const route_helpers_1 = require("../../utils/route-helpers");
4
+ const response_schemas_1 = require("../../utils/response-schemas");
4
5
  function registerEncrypt(app) {
5
6
  app.post("/v2/password/encrypt", {
6
7
  schema: {
@@ -16,6 +17,10 @@ function registerEncrypt(app) {
16
17
  plaintext: { type: "string", minLength: 1 },
17
18
  },
18
19
  },
20
+ response: (0, response_schemas_1.dataRoute)("The password-encrypted envelope.", (0, response_schemas_1.fields)({
21
+ encrypted: (0, response_schemas_1.base64)("Self-describing envelope: version, Argon2id parameters, salt, nonce and ciphertext; pass it to /v2/password/decrypt as ciphertext."),
22
+ algorithm: (0, response_schemas_1.literal)("argon2id-xchacha20-poly1305", "Envelope algorithm."),
23
+ }), 503),
19
24
  },
20
25
  }, async (request, reply) => {
21
26
  const { password, plaintext } = request.body;
@@ -38,6 +43,7 @@ function registerDecrypt(app) {
38
43
  ciphertext: { type: "string", minLength: 1 },
39
44
  },
40
45
  },
46
+ response: (0, response_schemas_1.dataRoute)("The plaintext; data is the text itself, not an object.", response_schemas_1.PLAINTEXT, 503),
41
47
  },
42
48
  }, async (request, reply) => {
43
49
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/password.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAY/C,eAAO,MAAM,aAAa;;;EAGxB,CAAC;yBA2Ga,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
1
+ {"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/password.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA+C/C,eAAO,MAAM,aAAa;;;EAGxB,CAAC;yBAiHa,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
@@ -2,6 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ARGON2_FLOORS = void 0;
4
4
  const route_helpers_1 = require("../../utils/route-helpers");
5
+ const response_schemas_1 = require("../../utils/response-schemas");
6
+ const ARGON2_PARAMS = (0, response_schemas_1.fields)({
7
+ t: (0, response_schemas_1.integer)("Passes (time cost)."),
8
+ m: (0, response_schemas_1.integer)("Memory in KiB."),
9
+ p: (0, response_schemas_1.integer)("Lanes (parallelism)."),
10
+ }, "Argon2id parameters; pass them back to verify.");
11
+ const HASH_RESPONSE = (0, response_schemas_1.dataRoute)("The Argon2id hash and everything needed to verify it.", (0, response_schemas_1.fields)({
12
+ hash: (0, response_schemas_1.hex)("The 32-byte Argon2id hash."),
13
+ salt: (0, response_schemas_1.hex)("The random 16-byte salt."),
14
+ params: ARGON2_PARAMS,
15
+ algorithm: (0, response_schemas_1.literal)("argon2id", "Password hashing algorithm."),
16
+ phc: {
17
+ type: "string",
18
+ description: "The same hash as a PHC string ($argon2id$v=19$m=..,t=..,p=..$salt$hash, unpadded base64 fields).",
19
+ },
20
+ }), 503);
5
21
  exports.ARGON2_FLOORS = Object.freeze({
6
22
  memoryCostKiB: 19456,
7
23
  timeCost: 2,
@@ -32,6 +48,7 @@ function registerHash(app) {
32
48
  parallelism: { type: "integer", minimum: 1, maximum: 8 },
33
49
  },
34
50
  },
51
+ response: HASH_RESPONSE,
35
52
  },
36
53
  }, async (request, reply) => {
37
54
  const body = request.body;
@@ -66,6 +83,7 @@ function registerVerify(app) {
66
83
  },
67
84
  },
68
85
  },
86
+ response: (0, response_schemas_1.dataRoute)("Whether the password matches the hash.", (0, response_schemas_1.fields)({ valid: (0, response_schemas_1.flag)("Whether the password matches.") }), 503),
69
87
  },
70
88
  }, async (request, reply) => {
71
89
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"pq-hash-sign.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq-hash-sign.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAiK/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
1
+ {"version":3,"file":"pq-hash-sign.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq-hash-sign.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAkM/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const route_helpers_1 = require("../../utils/route-helpers");
37
37
  const keys_1 = require("../../utils/keys");
38
+ const response_schemas_1 = require("../../utils/response-schemas");
38
39
  const SLH_DSA_VARIANTS = [
39
40
  "sha2-128f",
40
41
  "sha2-128s",
@@ -50,6 +51,7 @@ const SLH_DSA_VARIANTS = [
50
51
  "shake-256s",
51
52
  ];
52
53
  const SLH_DSA_ALGORITHMS = SLH_DSA_VARIANTS.map((v) => `slh-dsa-${v}`);
54
+ const SLH_DSA = { type: "string", enum: SLH_DSA_ALGORITHMS };
53
55
  function registerKeygen(app) {
54
56
  app.post("/v2/pq/slh-dsa/keygen", {
55
57
  config: { rateLimit: { max: 10, timeWindow: "1 minute" } },
@@ -65,6 +67,7 @@ function registerKeygen(app) {
65
67
  variant: { type: "string", enum: SLH_DSA_VARIANTS },
66
68
  },
67
69
  },
70
+ response: (0, response_schemas_1.dataRoute)("The keyId and public key of the new server-held key pair.", (0, response_schemas_1.publicKeyView)(SLH_DSA, (0, response_schemas_1.hex)("The SLH-DSA public key.")), 503),
68
71
  },
69
72
  }, async (request, reply) => {
70
73
  const { variant } = request.body;
@@ -89,13 +92,17 @@ function registerSign(app) {
89
92
  message: { type: "string", minLength: 1 },
90
93
  },
91
94
  },
95
+ response: (0, response_schemas_1.dataRoute)("The signature over the UTF-8 bytes of message.", (0, response_schemas_1.fields)({
96
+ signature: (0, response_schemas_1.hex)("The SLH-DSA signature."),
97
+ algorithm: SLH_DSA,
98
+ }), 404, 503),
92
99
  },
93
100
  }, async (request, reply) => {
94
101
  const body = request.body;
95
102
  const key = await (0, keys_1.resolveKey)(request, body.keyId, SLH_DSA_ALGORITHMS);
96
103
  const variant = key.algorithm.slice("slh-dsa-".length);
97
104
  return reply.send({
98
- data: await request.server.signer.run("modern", "slhDsaSign", variant, key.privateParts["secretKey"], body.message),
105
+ data: await request.server.signer.run("modern", "slhDsaSign", variant, (0, keys_1.pqSecretKey)(key), body.message),
99
106
  });
100
107
  });
101
108
  }
@@ -115,6 +122,10 @@ function registerVerify(app) {
115
122
  signature: { type: "string", minLength: 1 },
116
123
  },
117
124
  },
125
+ response: (0, response_schemas_1.dataRoute)("Whether the signature is valid.", (0, response_schemas_1.fields)({
126
+ valid: (0, response_schemas_1.flag)("Whether the signature is valid."),
127
+ algorithm: SLH_DSA,
128
+ })),
118
129
  },
119
130
  config: { rateLimit: { max: 100, timeWindow: "1 minute" } },
120
131
  }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"pq-sign.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq-sign.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA6I/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
1
+ {"version":3,"file":"pq-sign.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq-sign.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA+K/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
@@ -35,7 +35,9 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const route_helpers_1 = require("../../utils/route-helpers");
37
37
  const keys_1 = require("../../utils/keys");
38
+ const response_schemas_1 = require("../../utils/response-schemas");
38
39
  const ML_DSA_ALGORITHMS = ["ml-dsa-44", "ml-dsa-65", "ml-dsa-87"];
40
+ const ML_DSA = { type: "string", enum: ML_DSA_ALGORITHMS };
39
41
  function registerKeygen(app) {
40
42
  app.post("/v2/pq/dsa/keygen", {
41
43
  schema: {
@@ -50,6 +52,7 @@ function registerKeygen(app) {
50
52
  level: { type: "number", enum: [44, 65, 87] },
51
53
  },
52
54
  },
55
+ response: (0, response_schemas_1.dataRoute)("The keyId and public key of the new server-held key pair.", (0, response_schemas_1.publicKeyView)(ML_DSA, (0, response_schemas_1.hex)("The ML-DSA public key.")), 503),
53
56
  },
54
57
  }, async (request, reply) => {
55
58
  const { level } = request.body;
@@ -73,13 +76,17 @@ function registerSign(app) {
73
76
  message: { type: "string", minLength: 1 },
74
77
  },
75
78
  },
79
+ response: (0, response_schemas_1.dataRoute)("The signature over the UTF-8 bytes of message.", (0, response_schemas_1.fields)({
80
+ signature: (0, response_schemas_1.hex)("The ML-DSA signature."),
81
+ algorithm: ML_DSA,
82
+ }), 404, 503),
76
83
  },
77
84
  }, async (request, reply) => {
78
85
  const body = request.body;
79
86
  const key = await (0, keys_1.resolveKey)(request, body.keyId, ML_DSA_ALGORITHMS);
80
87
  const level = Number(key.algorithm.slice("ml-dsa-".length));
81
88
  return reply.send({
82
- data: await request.server.signer.run("modern", "mlDsaSign", level, key.privateParts["secretKey"], body.message),
89
+ data: await request.server.signer.run("modern", "mlDsaSign", level, (0, keys_1.pqSecretKey)(key), body.message),
83
90
  });
84
91
  });
85
92
  }
@@ -99,6 +106,10 @@ function registerVerify(app) {
99
106
  signature: { type: "string", minLength: 1 },
100
107
  },
101
108
  },
109
+ response: (0, response_schemas_1.dataRoute)("Whether the signature is valid.", (0, response_schemas_1.fields)({
110
+ valid: (0, response_schemas_1.flag)("Whether the signature is valid."),
111
+ algorithm: ML_DSA,
112
+ })),
102
113
  },
103
114
  config: { rateLimit: { max: 100, timeWindow: "1 minute" } },
104
115
  }, async (request, reply) => {
@@ -1 +1 @@
1
- {"version":3,"file":"pq.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAuQ/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAUE"}
1
+ {"version":3,"file":"pq.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA6U/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAUE"}
@@ -3,6 +3,10 @@ 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
5
  const keys_1 = require("../../utils/keys");
6
+ const response_schemas_1 = require("../../utils/response-schemas");
7
+ const ML_KEM_768 = (0, response_schemas_1.literal)("ml-kem-768", "KEM algorithm.");
8
+ const HYBRID = (0, response_schemas_1.literal)("x25519-ml-kem-768", "Hybrid KEM algorithm.");
9
+ const SHARED_SECRET = (0, response_schemas_1.hex)("The 32-byte shared secret.");
6
10
  const EMPTY_BODY = {
7
11
  type: "object",
8
12
  additionalProperties: false,
@@ -15,6 +19,7 @@ function registerMlKemKeygen(app) {
15
19
  summary: "Generate a server-held ML-KEM-768 key pair",
16
20
  description: "Generates a NIST FIPS 203 ML-KEM-768 key pair, keeps the secret key on the server and returns its keyId with the public key.",
17
21
  body: EMPTY_BODY,
22
+ response: (0, response_schemas_1.dataRoute)("The keyId and public key of the new server-held key pair.", (0, response_schemas_1.publicKeyView)(ML_KEM_768, (0, response_schemas_1.hex)("The 1184-byte ML-KEM-768 public key.")), 503),
18
23
  },
19
24
  }, async (request, reply) => {
20
25
  const { publicKey, secretKey, algorithm } = (0, modern_1.mlKemKeygen)(768);
@@ -36,6 +41,11 @@ function registerMlKemEncapsulate(app) {
36
41
  publicKey: { type: "string", minLength: 1 },
37
42
  },
38
43
  },
44
+ response: (0, response_schemas_1.dataRoute)("The ciphertext to send and the shared secret to keep.", (0, response_schemas_1.fields)({
45
+ ciphertext: (0, response_schemas_1.hex)("The 1088-byte ML-KEM-768 ciphertext."),
46
+ sharedSecret: SHARED_SECRET,
47
+ algorithm: ML_KEM_768,
48
+ })),
39
49
  },
40
50
  }, async (request, reply) => {
41
51
  try {
@@ -63,12 +73,13 @@ function registerMlKemDecapsulate(app) {
63
73
  ciphertext: { type: "string", minLength: 1 },
64
74
  },
65
75
  },
76
+ response: (0, response_schemas_1.dataRoute)("The shared secret.", (0, response_schemas_1.fields)({ sharedSecret: SHARED_SECRET, algorithm: ML_KEM_768 }), 404),
66
77
  },
67
78
  }, async (request, reply) => {
68
79
  const { keyId, ciphertext } = request.body;
69
80
  const key = await (0, keys_1.resolveKey)(request, keyId, ["ml-kem-768"]);
70
81
  try {
71
- const result = (0, modern_1.mlKemDecapsulate)(768, key.privateParts["secretKey"], ciphertext);
82
+ const result = (0, modern_1.mlKemDecapsulate)(768, (0, keys_1.pqSecretKey)(key), ciphertext);
72
83
  return reply.send({ data: result });
73
84
  }
74
85
  catch (error) {
@@ -77,6 +88,19 @@ function registerMlKemDecapsulate(app) {
77
88
  });
78
89
  }
79
90
  const COMBINER = "crypto-service/hybrid-kem/v2";
91
+ const COMBINER_FIELD = (0, response_schemas_1.literal)(COMBINER, "Shared-secret combiner.");
92
+ const HYBRID_ENCAPSULATE_RESPONSE = (0, response_schemas_1.dataRoute)("The ephemeral data to send and the combined shared secret to keep.", (0, response_schemas_1.fields)({
93
+ x25519EphemeralPublic: (0, response_schemas_1.hex)("The 32-byte ephemeral X25519 public key."),
94
+ mlKemCiphertext: (0, response_schemas_1.hex)("The 1088-byte ML-KEM-768 ciphertext."),
95
+ sharedSecret: SHARED_SECRET,
96
+ algorithm: HYBRID,
97
+ combiner: COMBINER_FIELD,
98
+ }));
99
+ const HYBRID_DECAPSULATE_RESPONSE = (0, response_schemas_1.dataRoute)("The combined shared secret.", (0, response_schemas_1.fields)({
100
+ sharedSecret: SHARED_SECRET,
101
+ algorithm: HYBRID,
102
+ combiner: COMBINER_FIELD,
103
+ }), 404);
80
104
  function registerHybridKeygen(app) {
81
105
  app.post("/v2/pq/hybrid/keygen", {
82
106
  schema: {
@@ -84,6 +108,12 @@ function registerHybridKeygen(app) {
84
108
  summary: "Generate a server-held hybrid X25519 + ML-KEM-768 key pair",
85
109
  description: "Generates classical (X25519) and post-quantum (ML-KEM-768) key pairs for hybrid key exchange, keeps the private keys on the server and returns a keyId with the public keys.",
86
110
  body: EMPTY_BODY,
111
+ response: (0, response_schemas_1.dataRoute)("The keyId and public keys of the new server-held key pair.", (0, response_schemas_1.fields)({
112
+ keyId: response_schemas_1.KEY_ID,
113
+ algorithm: HYBRID,
114
+ x25519PublicKey: (0, response_schemas_1.hex)("The 32-byte X25519 public key."),
115
+ mlKemPublicKey: (0, response_schemas_1.hex)("The 1184-byte ML-KEM-768 public key."),
116
+ }), 503),
87
117
  },
88
118
  }, async (request, reply) => {
89
119
  const kp = (0, modern_1.hybridKemKeygen)(768);
@@ -112,6 +142,7 @@ function registerHybridEncapsulate(app) {
112
142
  mlKemPublicKey: { type: "string", minLength: 1 },
113
143
  },
114
144
  },
145
+ response: HYBRID_ENCAPSULATE_RESPONSE,
115
146
  },
116
147
  }, async (request, reply) => {
117
148
  try {
@@ -144,6 +175,7 @@ function registerHybridDecapsulate(app) {
144
175
  mlKemCiphertext: { type: "string", minLength: 1 },
145
176
  },
146
177
  },
178
+ response: HYBRID_DECAPSULATE_RESPONSE,
147
179
  },
148
180
  }, async (request, reply) => {
149
181
  const body = request.body;
@@ -1 +1 @@
1
- {"version":3,"file":"sealedbox.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/sealedbox.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAmK/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
1
+ {"version":3,"file":"sealedbox.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/sealedbox.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAqM/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAKE"}
@@ -35,6 +35,12 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const route_helpers_1 = require("../../utils/route-helpers");
37
37
  const keys_1 = require("../../utils/keys");
38
+ const response_schemas_1 = require("../../utils/response-schemas");
39
+ const sealedResponse = (algorithm, layout) => (0, response_schemas_1.dataRoute)("The sealed box.", (0, response_schemas_1.fields)({
40
+ sealed: (0, response_schemas_1.base64)(layout),
41
+ algorithm: (0, response_schemas_1.literal)(algorithm, "Sealed-box algorithm."),
42
+ }));
43
+ const OPEN_RESPONSE = (0, response_schemas_1.dataRoute)("The plaintext; data is the text itself, not an object.", response_schemas_1.PLAINTEXT, 404);
38
44
  const loadSealedbox = async () => (await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/high-level")))).sealedbox;
39
45
  function registerSeal(app) {
40
46
  app.post("/v2/sealedbox/seal", {
@@ -50,6 +56,7 @@ function registerSeal(app) {
50
56
  plaintext: { type: "string", minLength: 1 },
51
57
  },
52
58
  },
59
+ response: sealedResponse("x25519-xchacha20-poly1305", "ephemeral X25519 public key (32 bytes) || nonce (24 bytes) || ciphertext || tag (16 bytes)."),
53
60
  },
54
61
  }, async (request, reply) => {
55
62
  try {
@@ -77,6 +84,7 @@ function registerOpen(app) {
77
84
  sealed: { type: "string", minLength: 1 },
78
85
  },
79
86
  },
87
+ response: OPEN_RESPONSE,
80
88
  },
81
89
  }, async (request, reply) => {
82
90
  const { keyId, sealed } = request.body;
@@ -108,6 +116,7 @@ function registerSealPq(app) {
108
116
  plaintext: { type: "string", minLength: 1 },
109
117
  },
110
118
  },
119
+ response: sealedResponse("x25519-ml-kem-768-xchacha20-poly1305", "ephemeral X25519 public key (32 bytes) || ML-KEM-768 ciphertext (1088 bytes) || nonce (24 bytes) || ciphertext || tag (16 bytes)."),
111
120
  },
112
121
  }, async (request, reply) => {
113
122
  try {
@@ -137,6 +146,7 @@ function registerOpenPq(app) {
137
146
  sealed: { type: "string", minLength: 1 },
138
147
  },
139
148
  },
149
+ response: OPEN_RESPONSE,
140
150
  },
141
151
  }, async (request, reply) => {
142
152
  const { keyId, sealed } = request.body;
@@ -1 +1 @@
1
- {"version":3,"file":"secretbox.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/secretbox.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAqF/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
1
+ {"version":3,"file":"secretbox.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/secretbox.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAyG/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAGE"}
@@ -34,6 +34,7 @@ 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");
37
38
  const loadSecretbox = async () => (await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/high-level")))).secretbox;
38
39
  function registerSeal(app) {
39
40
  app.post("/v2/secretbox/seal", {
@@ -50,6 +51,10 @@ function registerSeal(app) {
50
51
  aad: { type: "string" },
51
52
  },
52
53
  },
54
+ response: (0, response_schemas_1.dataRoute)("The sealed box.", (0, response_schemas_1.fields)({
55
+ sealed: (0, response_schemas_1.base64)("nonce (24 bytes) || ciphertext || Poly1305 tag (16 bytes)."),
56
+ algorithm: (0, response_schemas_1.literal)("xchacha20-poly1305", "AEAD algorithm."),
57
+ })),
53
58
  },
54
59
  }, async (request, reply) => {
55
60
  try {
@@ -78,6 +83,7 @@ function registerOpen(app) {
78
83
  aad: { type: "string" },
79
84
  },
80
85
  },
86
+ response: (0, response_schemas_1.dataRoute)("The plaintext; data is the text itself, not an object.", response_schemas_1.PLAINTEXT),
81
87
  },
82
88
  }, async (request, reply) => {
83
89
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/signing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBA0F/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAIE"}
1
+ {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/signing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAmH/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAIE"}
@@ -3,6 +3,8 @@ 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
5
  const keys_1 = require("../../utils/keys");
6
+ const response_schemas_1 = require("../../utils/response-schemas");
7
+ const ED25519 = (0, response_schemas_1.literal)("ed25519", "Signature algorithm.");
6
8
  function registerSign(app) {
7
9
  app.post("/v2/sign", {
8
10
  schema: {
@@ -22,6 +24,10 @@ function registerSign(app) {
22
24
  },
23
25
  },
24
26
  },
27
+ response: (0, response_schemas_1.dataRoute)("The signature over the UTF-8 bytes of message.", (0, response_schemas_1.fields)({
28
+ signature: (0, response_schemas_1.hex)("The 64-byte Ed25519 signature."),
29
+ algorithm: ED25519,
30
+ }), 404),
25
31
  },
26
32
  }, async (request, reply) => {
27
33
  const { keyId, message } = request.body;
@@ -50,6 +56,10 @@ function registerVerify(app) {
50
56
  signature: { type: "string", minLength: 128, maxLength: 128 },
51
57
  },
52
58
  },
59
+ response: (0, response_schemas_1.dataRoute)("Whether the signature is valid.", (0, response_schemas_1.fields)({
60
+ valid: (0, response_schemas_1.flag)("Whether the signature is valid."),
61
+ algorithm: ED25519,
62
+ })),
53
63
  },
54
64
  config: { rateLimit: { max: 100, timeWindow: "1 minute" } },
55
65
  }, async (request, reply) => {