@sebastienrousseau/crypto-server 0.0.2 → 0.0.8

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 (136) hide show
  1. package/README.md +292 -123
  2. package/dist/@types/types.d.ts +34 -14
  3. package/dist/@types/types.d.ts.map +1 -1
  4. package/dist/@types/types.js +15 -0
  5. package/dist/config/auth-policy.d.ts +2 -0
  6. package/dist/config/auth-policy.d.ts.map +1 -0
  7. package/dist/config/auth-policy.js +18 -0
  8. package/dist/config/constants.d.ts +54 -0
  9. package/dist/config/constants.d.ts.map +1 -0
  10. package/dist/config/constants.js +101 -0
  11. package/dist/config/env.d.ts +16 -0
  12. package/dist/config/env.d.ts.map +1 -0
  13. package/dist/config/env.js +74 -0
  14. package/dist/enterprise/metering.d.ts +19 -0
  15. package/dist/enterprise/metering.d.ts.map +1 -0
  16. package/dist/enterprise/metering.js +159 -0
  17. package/dist/enterprise/types.d.ts +78 -0
  18. package/dist/enterprise/types.d.ts.map +1 -0
  19. package/dist/enterprise/types.js +3 -0
  20. package/dist/index.js +38 -74
  21. package/dist/lib/auth.d.ts +14 -0
  22. package/dist/lib/auth.d.ts.map +1 -0
  23. package/dist/lib/auth.js +120 -0
  24. package/dist/lib/logger.d.ts.map +1 -1
  25. package/dist/lib/logger.js +6 -5
  26. package/dist/lib/telemetry.d.ts +4 -0
  27. package/dist/lib/telemetry.d.ts.map +1 -0
  28. package/dist/lib/telemetry.js +92 -0
  29. package/dist/lib/version.d.ts +2 -0
  30. package/dist/lib/version.d.ts.map +1 -0
  31. package/dist/lib/version.js +7 -0
  32. package/dist/routes/index.d.ts.map +1 -1
  33. package/dist/routes/index.js +19 -4
  34. package/dist/routes/probes.d.ts +4 -0
  35. package/dist/routes/probes.d.ts.map +1 -0
  36. package/dist/routes/probes.js +52 -0
  37. package/dist/routes/v1/decrypt.d.ts +2 -2
  38. package/dist/routes/v1/decrypt.d.ts.map +1 -1
  39. package/dist/routes/v1/decrypt.js +49 -6
  40. package/dist/routes/v1/encrypt.d.ts +2 -2
  41. package/dist/routes/v1/encrypt.d.ts.map +1 -1
  42. package/dist/routes/v1/encrypt.js +48 -6
  43. package/dist/routes/v1/generate.d.ts +2 -2
  44. package/dist/routes/v1/generate.d.ts.map +1 -1
  45. package/dist/routes/v1/generate.js +85 -13
  46. package/dist/routes/v1/index.d.ts +4 -0
  47. package/dist/routes/v1/index.d.ts.map +1 -0
  48. package/dist/routes/v1/index.js +19 -0
  49. package/dist/routes/v1/revoke.d.ts +2 -2
  50. package/dist/routes/v1/revoke.d.ts.map +1 -1
  51. package/dist/routes/v1/revoke.js +57 -5
  52. package/dist/routes/v1/verify.d.ts +4 -0
  53. package/dist/routes/v1/verify.d.ts.map +1 -0
  54. package/dist/routes/v1/verify.js +60 -0
  55. package/dist/routes/v2/algorithms.d.ts +4 -0
  56. package/dist/routes/v2/algorithms.d.ts.map +1 -0
  57. package/dist/routes/v2/algorithms.js +15 -0
  58. package/dist/routes/v2/compliance.d.ts +31 -0
  59. package/dist/routes/v2/compliance.d.ts.map +1 -0
  60. package/dist/routes/v2/compliance.js +223 -0
  61. package/dist/routes/v2/encrypt.d.ts +4 -0
  62. package/dist/routes/v2/encrypt.d.ts.map +1 -0
  63. package/dist/routes/v2/encrypt.js +62 -0
  64. package/dist/routes/v2/hash.d.ts +4 -0
  65. package/dist/routes/v2/hash.d.ts.map +1 -0
  66. package/dist/routes/v2/hash.js +34 -0
  67. package/dist/routes/v2/index.d.ts +4 -0
  68. package/dist/routes/v2/index.d.ts.map +1 -0
  69. package/dist/routes/v2/index.js +44 -0
  70. package/dist/routes/v2/kdf.d.ts +4 -0
  71. package/dist/routes/v2/kdf.d.ts.map +1 -0
  72. package/dist/routes/v2/kdf.js +54 -0
  73. package/dist/routes/v2/key-wrap.d.ts +4 -0
  74. package/dist/routes/v2/key-wrap.d.ts.map +1 -0
  75. package/dist/routes/v2/key-wrap.js +97 -0
  76. package/dist/routes/v2/keys.d.ts +4 -0
  77. package/dist/routes/v2/keys.d.ts.map +1 -0
  78. package/dist/routes/v2/keys.js +88 -0
  79. package/dist/routes/v2/mac.d.ts +4 -0
  80. package/dist/routes/v2/mac.d.ts.map +1 -0
  81. package/dist/routes/v2/mac.js +102 -0
  82. package/dist/routes/v2/multi-recipient.d.ts +4 -0
  83. package/dist/routes/v2/multi-recipient.d.ts.map +1 -0
  84. package/dist/routes/v2/multi-recipient.js +88 -0
  85. package/dist/routes/v2/password-encrypt.d.ts +4 -0
  86. package/dist/routes/v2/password-encrypt.d.ts.map +1 -0
  87. package/dist/routes/v2/password-encrypt.js +92 -0
  88. package/dist/routes/v2/password.d.ts +4 -0
  89. package/dist/routes/v2/password.d.ts.map +1 -0
  90. package/dist/routes/v2/password.js +109 -0
  91. package/dist/routes/v2/pq-hash-sign.d.ts +4 -0
  92. package/dist/routes/v2/pq-hash-sign.d.ts.map +1 -0
  93. package/dist/routes/v2/pq-hash-sign.js +131 -0
  94. package/dist/routes/v2/pq-sign.d.ts +4 -0
  95. package/dist/routes/v2/pq-sign.d.ts.map +1 -0
  96. package/dist/routes/v2/pq-sign.js +117 -0
  97. package/dist/routes/v2/pq.d.ts +4 -0
  98. package/dist/routes/v2/pq.d.ts.map +1 -0
  99. package/dist/routes/v2/pq.js +149 -0
  100. package/dist/routes/v2/sealedbox.d.ts +4 -0
  101. package/dist/routes/v2/sealedbox.d.ts.map +1 -0
  102. package/dist/routes/v2/sealedbox.js +145 -0
  103. package/dist/routes/v2/secretbox.d.ts +4 -0
  104. package/dist/routes/v2/secretbox.d.ts.map +1 -0
  105. package/dist/routes/v2/secretbox.js +94 -0
  106. package/dist/routes/v2/signing.d.ts +4 -0
  107. package/dist/routes/v2/signing.d.ts.map +1 -0
  108. package/dist/routes/v2/signing.js +66 -0
  109. package/dist/routes/v2/stream.d.ts +4 -0
  110. package/dist/routes/v2/stream.d.ts.map +1 -0
  111. package/dist/routes/v2/stream.js +206 -0
  112. package/dist/server.d.ts +4 -0
  113. package/dist/server.d.ts.map +1 -0
  114. package/dist/server.js +124 -0
  115. package/dist/utils/route-helpers.d.ts +15 -0
  116. package/dist/utils/route-helpers.d.ts.map +1 -0
  117. package/dist/utils/route-helpers.js +42 -0
  118. package/dist/utils/validation.d.ts +29 -0
  119. package/dist/utils/validation.d.ts.map +1 -0
  120. package/dist/utils/validation.js +162 -0
  121. package/package.json +103 -140
  122. package/dist/@types/types.js.map +0 -1
  123. package/dist/COPYRIGHT +0 -14
  124. package/dist/Report.txt +0 -90
  125. package/dist/config/endpoints.config.d.ts +0 -7
  126. package/dist/config/endpoints.config.d.ts.map +0 -1
  127. package/dist/config/endpoints.config.js +0 -8
  128. package/dist/config/endpoints.config.js.map +0 -1
  129. package/dist/index.js.map +0 -1
  130. package/dist/lib/logger.js.map +0 -1
  131. package/dist/package.json +0 -141
  132. package/dist/routes/index.js.map +0 -1
  133. package/dist/routes/v1/decrypt.js.map +0 -1
  134. package/dist/routes/v1/encrypt.js.map +0 -1
  135. package/dist/routes/v1/generate.js.map +0 -1
  136. package/dist/routes/v1/revoke.js.map +0 -1
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const route_helpers_1 = require("../../utils/route-helpers");
37
+ exports.default = (app) => {
38
+ app.post("/v2/password/hash", {
39
+ config: { rateLimit: { max: 5, timeWindow: "1 minute" } },
40
+ schema: {
41
+ tags: ["Password"],
42
+ summary: "Hash a password with Argon2id",
43
+ body: {
44
+ type: "object",
45
+ required: ["password"],
46
+ additionalProperties: false,
47
+ properties: {
48
+ password: { type: "string", minLength: 1, maxLength: 1024 },
49
+ timeCost: { type: "integer", minimum: 1, maximum: 10 },
50
+ memoryCost: { type: "integer", minimum: 1024, maximum: 262144 },
51
+ parallelism: { type: "integer", minimum: 1, maximum: 8 },
52
+ },
53
+ },
54
+ },
55
+ }, async (request, reply) => {
56
+ try {
57
+ const { hashPassword } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/password")));
58
+ const body = request.body;
59
+ const result = hashPassword({
60
+ password: body.password,
61
+ ...(body.timeCost ? { timeCost: body.timeCost } : {}),
62
+ ...(body.memoryCost ? { memoryCost: body.memoryCost } : {}),
63
+ ...(body.parallelism ? { parallelism: body.parallelism } : {}),
64
+ });
65
+ return reply.send({ data: result });
66
+ }
67
+ catch (error) {
68
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Password hashing");
69
+ }
70
+ });
71
+ app.post("/v2/password/verify", {
72
+ config: { rateLimit: { max: 5, timeWindow: "1 minute" } },
73
+ schema: {
74
+ tags: ["Password"],
75
+ summary: "Verify a password against an Argon2id hash",
76
+ body: {
77
+ type: "object",
78
+ required: ["password", "hash", "salt", "params"],
79
+ additionalProperties: false,
80
+ properties: {
81
+ password: { type: "string", minLength: 1, maxLength: 1024 },
82
+ hash: { type: "string", minLength: 1 },
83
+ salt: { type: "string", minLength: 1 },
84
+ params: {
85
+ type: "object",
86
+ required: ["t", "m", "p"],
87
+ additionalProperties: false,
88
+ properties: {
89
+ t: { type: "integer", minimum: 1, maximum: 10 },
90
+ m: { type: "integer", minimum: 8, maximum: 262144 },
91
+ p: { type: "integer", minimum: 1, maximum: 8 },
92
+ },
93
+ },
94
+ },
95
+ },
96
+ },
97
+ }, async (request, reply) => {
98
+ try {
99
+ const { verifyPassword } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/password")));
100
+ const body = request.body;
101
+ const result = verifyPassword(body);
102
+ return reply.send({ data: result });
103
+ }
104
+ catch (error) {
105
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Password verification");
106
+ }
107
+ });
108
+ };
109
+ //# sourceMappingURL=password.js.map
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ declare const _default: (app: FastifyInstance) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=pq-hash-sign.d.ts.map
@@ -0,0 +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;yBAqB/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAiHE"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const route_helpers_1 = require("../../utils/route-helpers");
37
+ const SLH_DSA_VARIANTS = [
38
+ "sha2-128f",
39
+ "sha2-128s",
40
+ "sha2-192f",
41
+ "sha2-192s",
42
+ "sha2-256f",
43
+ "sha2-256s",
44
+ "shake-128f",
45
+ "shake-128s",
46
+ "shake-192f",
47
+ "shake-192s",
48
+ "shake-256f",
49
+ "shake-256s",
50
+ ];
51
+ exports.default = (app) => {
52
+ app.post("/v2/pq/slh-dsa/keygen", {
53
+ schema: {
54
+ tags: ["Post-Quantum Hash-Based Signatures"],
55
+ summary: "Generate SLH-DSA key pair (FIPS 205)",
56
+ body: {
57
+ type: "object",
58
+ required: ["variant"],
59
+ additionalProperties: false,
60
+ properties: {
61
+ variant: { type: "string", enum: SLH_DSA_VARIANTS },
62
+ },
63
+ },
64
+ },
65
+ }, async (request, reply) => {
66
+ try {
67
+ const { slhDsaKeygen } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/pq-hash-sign")));
68
+ const { variant } = request.body;
69
+ return reply.send({ data: slhDsaKeygen(variant) });
70
+ }
71
+ catch (error) {
72
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Key generation");
73
+ }
74
+ });
75
+ app.post("/v2/pq/slh-dsa/sign", {
76
+ schema: {
77
+ tags: ["Post-Quantum Hash-Based Signatures"],
78
+ summary: "Sign with SLH-DSA (FIPS 205)",
79
+ body: {
80
+ type: "object",
81
+ required: ["variant", "secretKey", "message"],
82
+ additionalProperties: false,
83
+ properties: {
84
+ variant: { type: "string", enum: SLH_DSA_VARIANTS },
85
+ secretKey: { type: "string", minLength: 1 },
86
+ message: { type: "string", minLength: 1 },
87
+ },
88
+ },
89
+ },
90
+ }, async (request, reply) => {
91
+ try {
92
+ const { slhDsaSign } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/pq-hash-sign")));
93
+ const body = request.body;
94
+ return reply.send({
95
+ data: slhDsaSign(body.variant, body.secretKey, body.message),
96
+ });
97
+ }
98
+ catch (error) {
99
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Signing");
100
+ }
101
+ });
102
+ app.post("/v2/pq/slh-dsa/verify", {
103
+ schema: {
104
+ tags: ["Post-Quantum Hash-Based Signatures"],
105
+ summary: "Verify with SLH-DSA (FIPS 205)",
106
+ body: {
107
+ type: "object",
108
+ required: ["variant", "publicKey", "message", "signature"],
109
+ additionalProperties: false,
110
+ properties: {
111
+ variant: { type: "string", enum: SLH_DSA_VARIANTS },
112
+ publicKey: { type: "string", minLength: 1 },
113
+ message: { type: "string", minLength: 1 },
114
+ signature: { type: "string", minLength: 1 },
115
+ },
116
+ },
117
+ },
118
+ }, async (request, reply) => {
119
+ try {
120
+ const { slhDsaVerify } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/pq-hash-sign")));
121
+ const body = request.body;
122
+ return reply.send({
123
+ data: slhDsaVerify(body.variant, body.publicKey, body.message, body.signature),
124
+ });
125
+ }
126
+ catch (error) {
127
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Verification");
128
+ }
129
+ });
130
+ };
131
+ //# sourceMappingURL=pq-hash-sign.js.map
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ declare const _default: (app: FastifyInstance) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=pq-sign.d.ts.map
@@ -0,0 +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;yBAI/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA6GE"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const route_helpers_1 = require("../../utils/route-helpers");
37
+ exports.default = (app) => {
38
+ app.post("/v2/pq/dsa/keygen", {
39
+ schema: {
40
+ tags: ["Post-Quantum Signatures"],
41
+ summary: "Generate ML-DSA key pair (FIPS 204)",
42
+ body: {
43
+ type: "object",
44
+ required: ["level"],
45
+ additionalProperties: false,
46
+ properties: {
47
+ level: { type: "number", enum: [44, 65, 87] },
48
+ },
49
+ },
50
+ },
51
+ }, async (request, reply) => {
52
+ try {
53
+ const { mlDsaKeygen } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/pq-sign")));
54
+ const { level } = request.body;
55
+ return reply.send({ data: mlDsaKeygen(level) });
56
+ }
57
+ catch (error) {
58
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Key generation");
59
+ }
60
+ });
61
+ app.post("/v2/pq/dsa/sign", {
62
+ schema: {
63
+ tags: ["Post-Quantum Signatures"],
64
+ summary: "Sign with ML-DSA (FIPS 204)",
65
+ body: {
66
+ type: "object",
67
+ required: ["level", "secretKey", "message"],
68
+ additionalProperties: false,
69
+ properties: {
70
+ level: { type: "number", enum: [44, 65, 87] },
71
+ secretKey: { type: "string", minLength: 1 },
72
+ message: { type: "string", minLength: 1 },
73
+ },
74
+ },
75
+ },
76
+ }, async (request, reply) => {
77
+ try {
78
+ const { mlDsaSign } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/pq-sign")));
79
+ const body = request.body;
80
+ return reply.send({
81
+ data: mlDsaSign(body.level, body.secretKey, body.message),
82
+ });
83
+ }
84
+ catch (error) {
85
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Signing");
86
+ }
87
+ });
88
+ app.post("/v2/pq/dsa/verify", {
89
+ schema: {
90
+ tags: ["Post-Quantum Signatures"],
91
+ summary: "Verify with ML-DSA (FIPS 204)",
92
+ body: {
93
+ type: "object",
94
+ required: ["level", "publicKey", "message", "signature"],
95
+ additionalProperties: false,
96
+ properties: {
97
+ level: { type: "number", enum: [44, 65, 87] },
98
+ publicKey: { type: "string", minLength: 1 },
99
+ message: { type: "string", minLength: 1 },
100
+ signature: { type: "string", minLength: 1 },
101
+ },
102
+ },
103
+ },
104
+ }, async (request, reply) => {
105
+ try {
106
+ const { mlDsaVerify } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/modern/pq-sign")));
107
+ const body = request.body;
108
+ return reply.send({
109
+ data: mlDsaVerify(body.level, body.publicKey, body.message, body.signature),
110
+ });
111
+ }
112
+ catch (error) {
113
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Verification");
114
+ }
115
+ });
116
+ };
117
+ //# sourceMappingURL=pq-sign.js.map
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ declare const _default: (app: FastifyInstance) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=pq.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pq.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/pq.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAY/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA4ME"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const modern_1 = require("@sebastienrousseau/crypto-lib/dist/modern");
4
+ const route_helpers_1 = require("../../utils/route-helpers");
5
+ exports.default = (app) => {
6
+ app.post("/v2/pq/keygen", {
7
+ schema: {
8
+ tags: ["Post-Quantum"],
9
+ summary: "Generate ML-KEM-768 key pair",
10
+ description: "Generate a NIST FIPS 203 ML-KEM-768 key pair for quantum-resistant key encapsulation.",
11
+ body: { type: "object", additionalProperties: false, properties: {} },
12
+ },
13
+ }, async (request, reply) => {
14
+ try {
15
+ const keyPair = (0, modern_1.mlKemGenerateKeyPair)();
16
+ return reply.send({ data: keyPair });
17
+ }
18
+ catch (error) {
19
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Key generation");
20
+ }
21
+ });
22
+ app.post("/v2/pq/encapsulate", {
23
+ schema: {
24
+ tags: ["Post-Quantum"],
25
+ summary: "ML-KEM encapsulate",
26
+ description: "Encapsulate a shared secret using an ML-KEM-768 public key.",
27
+ body: {
28
+ type: "object",
29
+ required: ["publicKey"],
30
+ additionalProperties: false,
31
+ properties: {
32
+ publicKey: { type: "string", minLength: 1 },
33
+ },
34
+ },
35
+ },
36
+ }, async (request, reply) => {
37
+ try {
38
+ const { publicKey } = request.body;
39
+ const result = (0, modern_1.mlKemEncapsulate)(publicKey);
40
+ return reply.send({ data: result });
41
+ }
42
+ catch (error) {
43
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Encapsulation");
44
+ }
45
+ });
46
+ app.post("/v2/pq/decapsulate", {
47
+ schema: {
48
+ tags: ["Post-Quantum"],
49
+ summary: "ML-KEM decapsulate",
50
+ description: "Decapsulate and recover the shared secret using the ML-KEM secret key.",
51
+ body: {
52
+ type: "object",
53
+ required: ["secretKey", "ciphertext"],
54
+ additionalProperties: false,
55
+ properties: {
56
+ secretKey: { type: "string", minLength: 1 },
57
+ ciphertext: { type: "string", minLength: 1 },
58
+ },
59
+ },
60
+ },
61
+ }, async (request, reply) => {
62
+ try {
63
+ const { secretKey, ciphertext } = request.body;
64
+ const result = (0, modern_1.mlKemDecapsulate)(secretKey, ciphertext);
65
+ return reply.send({ data: result });
66
+ }
67
+ catch (error) {
68
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Decapsulation");
69
+ }
70
+ });
71
+ app.post("/v2/pq/hybrid/keygen", {
72
+ schema: {
73
+ tags: ["Post-Quantum"],
74
+ summary: "Generate hybrid X25519 + ML-KEM-768 key pair",
75
+ description: "Generates both classical (X25519) and post-quantum (ML-KEM-768) key pairs for hybrid key exchange.",
76
+ body: { type: "object", additionalProperties: false, properties: {} },
77
+ },
78
+ }, async (request, reply) => {
79
+ try {
80
+ const keyPair = (0, modern_1.hybridGenerateKeyPair)();
81
+ return reply.send({ data: keyPair });
82
+ }
83
+ catch (error) {
84
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Key generation");
85
+ }
86
+ });
87
+ app.post("/v2/pq/hybrid/encapsulate", {
88
+ schema: {
89
+ tags: ["Post-Quantum"],
90
+ summary: "Hybrid encapsulate (X25519 + ML-KEM-768)",
91
+ description: "Performs X25519 ECDH + ML-KEM encapsulation, derives a combined shared secret via HKDF-SHA256.",
92
+ body: {
93
+ type: "object",
94
+ required: ["x25519PublicKey", "mlKemPublicKey"],
95
+ additionalProperties: false,
96
+ properties: {
97
+ x25519PublicKey: { type: "string", minLength: 64, maxLength: 64 },
98
+ mlKemPublicKey: { type: "string", minLength: 1 },
99
+ },
100
+ },
101
+ },
102
+ }, async (request, reply) => {
103
+ try {
104
+ const { x25519PublicKey, mlKemPublicKey } = request.body;
105
+ const result = (0, modern_1.hybridEncapsulate)(x25519PublicKey, mlKemPublicKey);
106
+ return reply.send({ data: result });
107
+ }
108
+ catch (error) {
109
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Hybrid encapsulation");
110
+ }
111
+ });
112
+ app.post("/v2/pq/hybrid/decapsulate", {
113
+ schema: {
114
+ tags: ["Post-Quantum"],
115
+ summary: "Hybrid decapsulate (X25519 + ML-KEM-768)",
116
+ description: "Recovers the combined shared secret using private keys and sender's ephemeral data.",
117
+ body: {
118
+ type: "object",
119
+ required: [
120
+ "x25519PrivateKey",
121
+ "mlKemSecretKey",
122
+ "x25519EphemeralPublic",
123
+ "mlKemCiphertext",
124
+ ],
125
+ additionalProperties: false,
126
+ properties: {
127
+ x25519PrivateKey: { type: "string", minLength: 64, maxLength: 64 },
128
+ mlKemSecretKey: { type: "string", minLength: 1 },
129
+ x25519EphemeralPublic: {
130
+ type: "string",
131
+ minLength: 64,
132
+ maxLength: 64,
133
+ },
134
+ mlKemCiphertext: { type: "string", minLength: 1 },
135
+ },
136
+ },
137
+ },
138
+ }, async (request, reply) => {
139
+ try {
140
+ const body = request.body;
141
+ const result = (0, modern_1.hybridDecapsulate)(body.x25519PrivateKey, body.mlKemSecretKey, body.x25519EphemeralPublic, body.mlKemCiphertext);
142
+ return reply.send({ data: result });
143
+ }
144
+ catch (error) {
145
+ return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Hybrid decapsulation");
146
+ }
147
+ });
148
+ };
149
+ //# sourceMappingURL=pq.js.map
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ declare const _default: (app: FastifyInstance) => void;
3
+ export default _default;
4
+ //# sourceMappingURL=sealedbox.d.ts.map
@@ -0,0 +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;yBAI/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA6IE"}