@sebastienrousseau/crypto-middleware 0.0.9 → 0.0.25

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.
package/dist/common.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { JwtPayload, MiddlewareConfig } from "./types";
2
2
  export declare function encryptPayload(key: string, data: unknown): string;
3
3
  export declare function decryptPayload(key: string, sealed: string): unknown;
4
+ export declare function encryptPqPayload(recipientX25519Public: string, recipientMlKemPublic: string, data: unknown, chunkSize?: number): string;
5
+ export declare function decryptPqPayload(recipientX25519Secret: string, recipientMlKemSecret: string, sealed: string, chunkSize?: number): unknown;
4
6
  export declare function verifyHmacSignature(hmacKey: string, body: string, signature: string): boolean;
5
7
  export interface JwtVerifyOptions {
6
8
  issuer?: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAyB,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAgB9E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAIjE;AAgBD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAYnE;AAsBD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CA4BT;AAWD,MAAM,WAAW,gBAAgB;IAK/B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAM5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAiHD,wBAAgB,SAAS,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,gBAAqB,GAC7B,UAAU,CAcZ;AAUD,wBAAgB,eAAe,CAC7B,MAAM,EAA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EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,gBAAqB,GAC7B,UAAU,CAcZ;AAUD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,UAAU,CAcZ;AAUD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,EACtD,IAAI,EAAE,OAAO,GACZ,IAAI,CAcN;AAoBD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAYlE"}
package/dist/common.js CHANGED
@@ -2,12 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encryptPayload = encryptPayload;
4
4
  exports.decryptPayload = decryptPayload;
5
+ exports.encryptPqPayload = encryptPqPayload;
6
+ exports.decryptPqPayload = decryptPqPayload;
5
7
  exports.verifyHmacSignature = verifyHmacSignature;
6
8
  exports.verifyJwt = verifyJwt;
7
9
  exports.verifyBearerJwt = verifyBearerJwt;
8
10
  exports.verifyRequestSignature = verifyRequestSignature;
9
11
  exports.matchRoute = matchRoute;
10
12
  const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
13
+ const streaming_1 = require("@sebastienrousseau/crypto-lib/streaming");
11
14
  const types_1 = require("./types");
12
15
  function encryptPayload(key, data) {
13
16
  const plaintext = typeof data === "string" ? data : JSON.stringify(data);
@@ -24,6 +27,34 @@ function decryptPayload(key, sealed) {
24
27
  throw new types_1.CryptoMiddlewareError(`Decryption failed: ${err.message}`, 400, "DECRYPTION_FAILED");
25
28
  }
26
29
  }
30
+ function encryptPqPayload(recipientX25519Public, recipientMlKemPublic, data, chunkSize) {
31
+ const plaintext = typeof data === "string" ? data : JSON.stringify(data);
32
+ const ptBytes = Buffer.from(plaintext, "utf8");
33
+ const res = (0, streaming_1.streamPqEncrypt)({
34
+ recipientX25519Public,
35
+ recipientMlKemPublic,
36
+ plaintext: ptBytes,
37
+ ...(chunkSize !== undefined ? { chunkSize } : {}),
38
+ });
39
+ return Buffer.from(res.ciphertext).toString("base64");
40
+ }
41
+ function decryptPqPayload(recipientX25519Secret, recipientMlKemSecret, sealed, chunkSize) {
42
+ try {
43
+ const ctBytes = Buffer.from(sealed, "base64");
44
+ const decrypted = (0, streaming_1.streamPqDecrypt)({
45
+ recipientX25519Secret,
46
+ recipientMlKemSecret,
47
+ ciphertext: ctBytes,
48
+ ...(chunkSize !== undefined ? { chunkSize } : {}),
49
+ });
50
+ const plaintext = Buffer.from(decrypted).toString("utf8");
51
+ (0, crypto_lib_1.wipeMemory)(decrypted);
52
+ return JSON.parse(plaintext);
53
+ }
54
+ catch (err) {
55
+ throw new types_1.CryptoMiddlewareError(`PQ decryption failed: ${err.message}`, 400, "DECRYPTION_FAILED");
56
+ }
57
+ }
27
58
  function verifyHmacSignature(hmacKey, body, signature) {
28
59
  if (!signature) {
29
60
  throw new types_1.CryptoMiddlewareError("Missing signature header", 401, "MISSING_SIGNATURE");
package/dist/express.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Request, Response, NextFunction } from "express";
2
- import { MiddlewareConfig } from "./types";
2
+ import { MiddlewareConfig, PqStreamPluginConfig } from "./types";
3
3
  export declare function createCryptoMiddleware(config: MiddlewareConfig): (req: Request, res: Response, next: NextFunction) => void;
4
+ export declare function createPqStreamMiddleware(config: PqStreamPluginConfig): (req: Request, res: Response, next: NextFunction) => void;
4
5
  //# sourceMappingURL=express.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAyB,MAAM,SAAS,CAAC;AAwFlE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,IAK3D,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,KACjB,IAAI,CAqBR"}
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EACL,gBAAgB,EAEhB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAwIjB,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,IAK3D,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,KACjB,IAAI,CAqBR;AAQD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,oBAAoB,SAhC5D,OAAO,OACP,QAAQ,QACP,YAAY,KACjB,IAAI,CAiDR"}
package/dist/express.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCryptoMiddleware = createCryptoMiddleware;
4
+ exports.createPqStreamMiddleware = createPqStreamMiddleware;
4
5
  const types_1 = require("./types");
5
6
  const common_1 = require("./common");
6
7
  function requireKey(config, operation) {
@@ -23,6 +24,31 @@ function encryptJsonResponses(config, res) {
23
24
  return originalJson({ encrypted: sealed });
24
25
  };
25
26
  }
27
+ function decryptPqBody(config, req) {
28
+ const xSecret = config.pqKeys?.recipientX25519Secret;
29
+ const kemSecret = config.pqKeys?.recipientMlKemSecret;
30
+ if (!xSecret || !kemSecret) {
31
+ throw new types_1.CryptoMiddlewareError("recipientX25519Secret and recipientMlKemSecret are required for pq-decrypt-request operation", 500, "MISSING_CONFIG");
32
+ }
33
+ if (req.body && typeof req.body === "object" && "encrypted" in req.body) {
34
+ req.body = (0, common_1.decryptPqPayload)(xSecret, kemSecret, req.body.encrypted, config.chunkSize);
35
+ }
36
+ }
37
+ function encryptPqJsonResponses(config, res) {
38
+ const xPublic = config.pqKeys?.recipientX25519Public;
39
+ const kemPublic = config.pqKeys?.recipientMlKemPublic;
40
+ if (!xPublic || !kemPublic) {
41
+ throw new types_1.CryptoMiddlewareError("recipientX25519Public and recipientMlKemPublic are required for pq-encrypt-response operation", 500, "MISSING_CONFIG");
42
+ }
43
+ const originalJson = res.json.bind(res);
44
+ res.json = function encryptedPqJson(body) {
45
+ const sealed = (0, common_1.encryptPqPayload)(xPublic, kemPublic, body, config.chunkSize);
46
+ return originalJson({
47
+ encrypted: sealed,
48
+ algorithm: "X25519-ML-KEM-768-XChaCha20-Poly1305",
49
+ });
50
+ };
51
+ }
26
52
  function applyOperations(config, operations, req, res) {
27
53
  if (operations.includes("verify-jwt")) {
28
54
  req.jwtPayload = (0, common_1.verifyBearerJwt)(config, req.headers.authorization);
@@ -32,9 +58,14 @@ function applyOperations(config, operations, req, res) {
32
58
  }
33
59
  if (operations.includes("decrypt-request"))
34
60
  decryptBody(config, req);
61
+ if (operations.includes("pq-decrypt-request"))
62
+ decryptPqBody(config, req);
35
63
  if (operations.includes("encrypt-response")) {
36
64
  encryptJsonResponses(config, res);
37
65
  }
66
+ if (operations.includes("pq-encrypt-response")) {
67
+ encryptPqJsonResponses(config, res);
68
+ }
38
69
  }
39
70
  function createCryptoMiddleware(config) {
40
71
  const operations = config.operations ?? [];
@@ -60,4 +91,21 @@ function createCryptoMiddleware(config) {
60
91
  }
61
92
  };
62
93
  }
94
+ function createPqStreamMiddleware(config) {
95
+ const operations = [];
96
+ if (config.recipientKeys.recipientX25519Secret &&
97
+ config.recipientKeys.recipientMlKemSecret) {
98
+ operations.push("pq-decrypt-request");
99
+ }
100
+ if (config.recipientKeys.recipientX25519Public &&
101
+ config.recipientKeys.recipientMlKemPublic) {
102
+ operations.push("pq-encrypt-response");
103
+ }
104
+ return createCryptoMiddleware({
105
+ pqKeys: config.recipientKeys,
106
+ ...(config.routes !== undefined ? { routes: config.routes } : {}),
107
+ ...(config.chunkSize !== undefined ? { chunkSize: config.chunkSize } : {}),
108
+ operations,
109
+ });
110
+ }
63
111
  //# sourceMappingURL=express.js.map
package/dist/fastify.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { FastifyInstance } from "fastify";
2
- import { MiddlewareConfig } from "./types";
2
+ import { MiddlewareConfig, PqStreamPluginConfig } from "./types";
3
3
  declare function cryptoPluginImpl(fastify: FastifyInstance, opts: MiddlewareConfig): Promise<void>;
4
4
  export declare const cryptoPlugin: typeof cryptoPluginImpl;
5
+ declare function pqStreamPluginImpl(fastify: FastifyInstance, opts: PqStreamPluginConfig): Promise<void>;
6
+ export declare const pqStreamPlugin: typeof pqStreamPluginImpl;
5
7
  export {};
6
8
  //# sourceMappingURL=fastify.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAE7E,OAAO,EAAE,gBAAgB,EAAyB,MAAM,SAAS,CAAC;AA8HlE,iBAAe,gBAAgB,CAC7B,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,IAAI,CAAC,CAgBf;AAGD,eAAO,MAAM,YAAY,yBAGvB,CAAC"}
1
+ {"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAE7E,OAAO,EACL,gBAAgB,EAEhB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAoMjB,iBAAe,gBAAgB,CAC7B,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAGD,eAAO,MAAM,YAAY,yBAGvB,CAAC;AAGH,iBAAe,kBAAkB,CAC/B,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAGD,eAAO,MAAM,cAAc,2BAGzB,CAAC"}
package/dist/fastify.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cryptoPlugin = void 0;
6
+ exports.pqStreamPlugin = exports.cryptoPlugin = void 0;
7
7
  const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
8
8
  const types_1 = require("./types");
9
9
  const common_1 = require("./common");
@@ -70,6 +70,49 @@ function registerEncryption(fastify, opts, routes) {
70
70
  return payload;
71
71
  });
72
72
  }
73
+ function registerPqDecryption(fastify, opts, routes) {
74
+ fastify.addHook("preHandler", async (request, reply) => {
75
+ if (!(0, common_1.matchRoute)(request.url, routes))
76
+ return;
77
+ const xSecret = opts.pqKeys?.recipientX25519Secret;
78
+ const kemSecret = opts.pqKeys?.recipientMlKemSecret;
79
+ if (!xSecret || !kemSecret) {
80
+ reply.code(500).send({
81
+ error: "recipientX25519Secret and recipientMlKemSecret are required for pq-decrypt-request operation",
82
+ code: "MISSING_CONFIG",
83
+ });
84
+ return;
85
+ }
86
+ try {
87
+ const body = request.body;
88
+ if (body && typeof body === "object" && "encrypted" in body) {
89
+ request.body =
90
+ (0, common_1.decryptPqPayload)(xSecret, kemSecret, body.encrypted, opts.chunkSize);
91
+ }
92
+ }
93
+ catch (err) {
94
+ sendMiddlewareError(reply, err);
95
+ }
96
+ });
97
+ }
98
+ function registerPqEncryption(fastify, opts, routes) {
99
+ fastify.addHook("preSerialization", async (request, _reply, payload) => {
100
+ if (!(0, common_1.matchRoute)(request.url, routes))
101
+ return payload;
102
+ const xPublic = opts.pqKeys?.recipientX25519Public;
103
+ const kemPublic = opts.pqKeys?.recipientMlKemPublic;
104
+ if (!xPublic || !kemPublic)
105
+ return payload;
106
+ if (payload !== null && typeof payload === "object") {
107
+ const sealed = (0, common_1.encryptPqPayload)(xPublic, kemPublic, payload, opts.chunkSize);
108
+ return {
109
+ encrypted: sealed,
110
+ algorithm: "X25519-ML-KEM-768-XChaCha20-Poly1305",
111
+ };
112
+ }
113
+ return payload;
114
+ });
115
+ }
73
116
  async function cryptoPluginImpl(fastify, opts) {
74
117
  const operations = opts.operations ?? [];
75
118
  const routes = opts.routes ?? [];
@@ -77,12 +120,38 @@ async function cryptoPluginImpl(fastify, opts) {
77
120
  if (operations.includes("decrypt-request")) {
78
121
  registerDecryption(fastify, opts, routes);
79
122
  }
123
+ if (operations.includes("pq-decrypt-request")) {
124
+ registerPqDecryption(fastify, opts, routes);
125
+ }
80
126
  if (operations.includes("encrypt-response")) {
81
127
  registerEncryption(fastify, opts, routes);
82
128
  }
129
+ if (operations.includes("pq-encrypt-response")) {
130
+ registerPqEncryption(fastify, opts, routes);
131
+ }
83
132
  }
84
133
  exports.cryptoPlugin = (0, fastify_plugin_1.default)(cryptoPluginImpl, {
85
134
  name: "crypto-middleware",
86
135
  fastify: "4.x || 5.x",
87
136
  });
137
+ async function pqStreamPluginImpl(fastify, opts) {
138
+ const routes = opts.routes ?? [];
139
+ const { recipientKeys, chunkSize } = opts;
140
+ const config = {
141
+ pqKeys: recipientKeys,
142
+ ...(chunkSize !== undefined ? { chunkSize } : {}),
143
+ };
144
+ if (recipientKeys.recipientX25519Secret &&
145
+ recipientKeys.recipientMlKemSecret) {
146
+ registerPqDecryption(fastify, config, routes);
147
+ }
148
+ if (recipientKeys.recipientX25519Public &&
149
+ recipientKeys.recipientMlKemPublic) {
150
+ registerPqEncryption(fastify, config, routes);
151
+ }
152
+ }
153
+ exports.pqStreamPlugin = (0, fastify_plugin_1.default)(pqStreamPluginImpl, {
154
+ name: "crypto-middleware-pq-stream",
155
+ fastify: "4.x || 5.x",
156
+ });
88
157
  //# sourceMappingURL=fastify.js.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export type { MiddlewareConfig, JwtPayload } from "./types";
1
+ export type { MiddlewareConfig, JwtPayload, PqKeysConfig, PqStreamPluginConfig, } from "./types";
2
2
  export { CryptoMiddlewareError } from "./types";
3
3
  export type { JwtVerifyOptions } from "./common";
4
- export { encryptPayload, decryptPayload, verifyHmacSignature, verifyJwt, matchRoute, } from "./common";
5
- export { createCryptoMiddleware } from "./express";
6
- export { cryptoPlugin } from "./fastify";
4
+ export { encryptPayload, decryptPayload, encryptPqPayload, decryptPqPayload, verifyHmacSignature, verifyJwt, matchRoute, } from "./common";
5
+ export { createCryptoMiddleware, createPqStreamMiddleware } from "./express";
6
+ export { cryptoPlugin, pqStreamPlugin } from "./fastify";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EACL,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,oBAAoB,GACrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGjD,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAG7E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cryptoPlugin = exports.createCryptoMiddleware = exports.matchRoute = exports.verifyJwt = exports.verifyHmacSignature = exports.decryptPayload = exports.encryptPayload = exports.CryptoMiddlewareError = void 0;
3
+ exports.pqStreamPlugin = exports.cryptoPlugin = exports.createPqStreamMiddleware = exports.createCryptoMiddleware = exports.matchRoute = exports.verifyJwt = exports.verifyHmacSignature = exports.decryptPqPayload = exports.encryptPqPayload = exports.decryptPayload = exports.encryptPayload = exports.CryptoMiddlewareError = void 0;
4
4
  var types_1 = require("./types");
5
5
  Object.defineProperty(exports, "CryptoMiddlewareError", { enumerable: true, get: function () { return types_1.CryptoMiddlewareError; } });
6
6
  var common_1 = require("./common");
7
7
  Object.defineProperty(exports, "encryptPayload", { enumerable: true, get: function () { return common_1.encryptPayload; } });
8
8
  Object.defineProperty(exports, "decryptPayload", { enumerable: true, get: function () { return common_1.decryptPayload; } });
9
+ Object.defineProperty(exports, "encryptPqPayload", { enumerable: true, get: function () { return common_1.encryptPqPayload; } });
10
+ Object.defineProperty(exports, "decryptPqPayload", { enumerable: true, get: function () { return common_1.decryptPqPayload; } });
9
11
  Object.defineProperty(exports, "verifyHmacSignature", { enumerable: true, get: function () { return common_1.verifyHmacSignature; } });
10
12
  Object.defineProperty(exports, "verifyJwt", { enumerable: true, get: function () { return common_1.verifyJwt; } });
11
13
  Object.defineProperty(exports, "matchRoute", { enumerable: true, get: function () { return common_1.matchRoute; } });
12
14
  var express_1 = require("./express");
13
15
  Object.defineProperty(exports, "createCryptoMiddleware", { enumerable: true, get: function () { return express_1.createCryptoMiddleware; } });
16
+ Object.defineProperty(exports, "createPqStreamMiddleware", { enumerable: true, get: function () { return express_1.createPqStreamMiddleware; } });
14
17
  var fastify_1 = require("./fastify");
15
18
  Object.defineProperty(exports, "cryptoPlugin", { enumerable: true, get: function () { return fastify_1.cryptoPlugin; } });
19
+ Object.defineProperty(exports, "pqStreamPlugin", { enumerable: true, get: function () { return fastify_1.pqStreamPlugin; } });
16
20
  //# sourceMappingURL=index.js.map
package/dist/types.d.ts CHANGED
@@ -1,11 +1,24 @@
1
+ export interface PqKeysConfig {
2
+ recipientX25519Secret?: string | undefined;
3
+ recipientMlKemSecret?: string | undefined;
4
+ recipientX25519Public?: string | undefined;
5
+ recipientMlKemPublic?: string | undefined;
6
+ }
7
+ export interface PqStreamPluginConfig {
8
+ recipientKeys: PqKeysConfig;
9
+ routes?: string[] | undefined;
10
+ chunkSize?: number | undefined;
11
+ }
1
12
  export interface MiddlewareConfig {
2
- key?: string;
3
- routes?: string[];
4
- operations?: Array<"decrypt-request" | "encrypt-response" | "verify-signature" | "verify-jwt">;
13
+ key?: string | undefined;
14
+ routes?: string[] | undefined;
15
+ operations?: Array<"decrypt-request" | "encrypt-response" | "verify-signature" | "verify-jwt" | "pq-decrypt-request" | "pq-encrypt-response">;
5
16
  hmacKey?: string;
6
17
  jwtSecret?: string;
7
18
  jwtIssuer?: string;
8
19
  jwtAudience?: string;
20
+ pqKeys?: PqKeysConfig | undefined;
21
+ chunkSize?: number | undefined;
9
22
  }
10
23
  export interface JwtPayload {
11
24
  sub?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,gBAAgB;IAE/B,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,UAAU,CAAC,EAAE,KAAK,CAChB,iBAAiB,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,YAAY,CAC3E,CAAC;IAEF,OAAO,CAAC,EAAE,MAAM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,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAE9B,UAAU,CAAC,EAAE,KAAK,CACd,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,GAClB,YAAY,GACZ,oBAAoB,GACpB,qBAAqB,CACxB,CAAC;IAEF,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IAElC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAcD,MAAM,WAAW,UAAU;IAEzB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAKxB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAUD,qBAAa,qBAAsB,SAAQ,KAAK;IAE9C,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAGjB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAM9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-middleware",
3
- "version": "0.0.9",
3
+ "version": "0.0.25",
4
4
  "description": "Plug-and-play cryptographic middleware for Express and Fastify -- auto-decrypt requests, verify signatures, and encrypt responses.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "fastify-plugin": "^6.0.0",
38
- "@sebastienrousseau/crypto-lib": "0.0.9"
38
+ "@sebastienrousseau/crypto-lib": "0.0.25"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "express": "^5.2.1",
@@ -50,7 +50,7 @@
50
50
  }
51
51
  },
52
52
  "devDependencies": {
53
- "@sebastienrousseau/mocha-config": "^0.0.5",
53
+ "@sebastienrousseau/mocha-config": "^0.0.7",
54
54
  "@types/chai": "^5.2.3",
55
55
  "@types/chai-as-promised": "^8.0.2",
56
56
  "@types/express": "^5.0.6",