@sebastienrousseau/crypto-server 0.0.1 → 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.
- package/README.md +292 -123
- package/dist/@types/types.d.ts +34 -14
- package/dist/@types/types.d.ts.map +1 -1
- package/dist/@types/types.js +15 -0
- package/dist/config/auth-policy.d.ts +2 -0
- package/dist/config/auth-policy.d.ts.map +1 -0
- package/dist/config/auth-policy.js +18 -0
- package/dist/config/constants.d.ts +54 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +101 -0
- package/dist/config/env.d.ts +16 -0
- package/dist/config/env.d.ts.map +1 -0
- package/dist/config/env.js +74 -0
- package/dist/enterprise/metering.d.ts +19 -0
- package/dist/enterprise/metering.d.ts.map +1 -0
- package/dist/enterprise/metering.js +159 -0
- package/dist/enterprise/types.d.ts +78 -0
- package/dist/enterprise/types.d.ts.map +1 -0
- package/dist/enterprise/types.js +3 -0
- package/dist/index.js +38 -74
- package/dist/lib/auth.d.ts +14 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +120 -0
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +6 -5
- package/dist/lib/telemetry.d.ts +4 -0
- package/dist/lib/telemetry.d.ts.map +1 -0
- package/dist/lib/telemetry.js +92 -0
- package/dist/lib/version.d.ts +2 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +7 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +19 -4
- package/dist/routes/probes.d.ts +4 -0
- package/dist/routes/probes.d.ts.map +1 -0
- package/dist/routes/probes.js +52 -0
- package/dist/routes/v1/decrypt.d.ts +2 -2
- package/dist/routes/v1/decrypt.d.ts.map +1 -1
- package/dist/routes/v1/decrypt.js +49 -6
- package/dist/routes/v1/encrypt.d.ts +2 -2
- package/dist/routes/v1/encrypt.d.ts.map +1 -1
- package/dist/routes/v1/encrypt.js +48 -6
- package/dist/routes/v1/generate.d.ts +2 -2
- package/dist/routes/v1/generate.d.ts.map +1 -1
- package/dist/routes/v1/generate.js +85 -13
- package/dist/routes/v1/index.d.ts +4 -0
- package/dist/routes/v1/index.d.ts.map +1 -0
- package/dist/routes/v1/index.js +19 -0
- package/dist/routes/v1/revoke.d.ts +2 -2
- package/dist/routes/v1/revoke.d.ts.map +1 -1
- package/dist/routes/v1/revoke.js +57 -5
- package/dist/routes/v1/verify.d.ts +4 -0
- package/dist/routes/v1/verify.d.ts.map +1 -0
- package/dist/routes/v1/verify.js +60 -0
- package/dist/routes/v2/algorithms.d.ts +4 -0
- package/dist/routes/v2/algorithms.d.ts.map +1 -0
- package/dist/routes/v2/algorithms.js +15 -0
- package/dist/routes/v2/compliance.d.ts +31 -0
- package/dist/routes/v2/compliance.d.ts.map +1 -0
- package/dist/routes/v2/compliance.js +223 -0
- package/dist/routes/v2/encrypt.d.ts +4 -0
- package/dist/routes/v2/encrypt.d.ts.map +1 -0
- package/dist/routes/v2/encrypt.js +62 -0
- package/dist/routes/v2/hash.d.ts +4 -0
- package/dist/routes/v2/hash.d.ts.map +1 -0
- package/dist/routes/v2/hash.js +34 -0
- package/dist/routes/v2/index.d.ts +4 -0
- package/dist/routes/v2/index.d.ts.map +1 -0
- package/dist/routes/v2/index.js +44 -0
- package/dist/routes/v2/kdf.d.ts +4 -0
- package/dist/routes/v2/kdf.d.ts.map +1 -0
- package/dist/routes/v2/kdf.js +54 -0
- package/dist/routes/v2/key-wrap.d.ts +4 -0
- package/dist/routes/v2/key-wrap.d.ts.map +1 -0
- package/dist/routes/v2/key-wrap.js +97 -0
- package/dist/routes/v2/keys.d.ts +4 -0
- package/dist/routes/v2/keys.d.ts.map +1 -0
- package/dist/routes/v2/keys.js +88 -0
- package/dist/routes/v2/mac.d.ts +4 -0
- package/dist/routes/v2/mac.d.ts.map +1 -0
- package/dist/routes/v2/mac.js +102 -0
- package/dist/routes/v2/multi-recipient.d.ts +4 -0
- package/dist/routes/v2/multi-recipient.d.ts.map +1 -0
- package/dist/routes/v2/multi-recipient.js +88 -0
- package/dist/routes/v2/password-encrypt.d.ts +4 -0
- package/dist/routes/v2/password-encrypt.d.ts.map +1 -0
- package/dist/routes/v2/password-encrypt.js +92 -0
- package/dist/routes/v2/password.d.ts +4 -0
- package/dist/routes/v2/password.d.ts.map +1 -0
- package/dist/routes/v2/password.js +109 -0
- package/dist/routes/v2/pq-hash-sign.d.ts +4 -0
- package/dist/routes/v2/pq-hash-sign.d.ts.map +1 -0
- package/dist/routes/v2/pq-hash-sign.js +131 -0
- package/dist/routes/v2/pq-sign.d.ts +4 -0
- package/dist/routes/v2/pq-sign.d.ts.map +1 -0
- package/dist/routes/v2/pq-sign.js +117 -0
- package/dist/routes/v2/pq.d.ts +4 -0
- package/dist/routes/v2/pq.d.ts.map +1 -0
- package/dist/routes/v2/pq.js +149 -0
- package/dist/routes/v2/sealedbox.d.ts +4 -0
- package/dist/routes/v2/sealedbox.d.ts.map +1 -0
- package/dist/routes/v2/sealedbox.js +145 -0
- package/dist/routes/v2/secretbox.d.ts +4 -0
- package/dist/routes/v2/secretbox.d.ts.map +1 -0
- package/dist/routes/v2/secretbox.js +94 -0
- package/dist/routes/v2/signing.d.ts +4 -0
- package/dist/routes/v2/signing.d.ts.map +1 -0
- package/dist/routes/v2/signing.js +66 -0
- package/dist/routes/v2/stream.d.ts +4 -0
- package/dist/routes/v2/stream.d.ts.map +1 -0
- package/dist/routes/v2/stream.js +206 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +124 -0
- package/dist/utils/route-helpers.d.ts +15 -0
- package/dist/utils/route-helpers.d.ts.map +1 -0
- package/dist/utils/route-helpers.js +42 -0
- package/dist/utils/validation.d.ts +29 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +162 -0
- package/package.json +103 -140
- package/dist/@types/types.js.map +0 -1
- package/dist/COPYRIGHT +0 -14
- package/dist/Report.txt +0 -90
- package/dist/config/endpoints.config.d.ts +0 -7
- package/dist/config/endpoints.config.d.ts.map +0 -1
- package/dist/config/endpoints.config.js +0 -8
- package/dist/config/endpoints.config.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/logger.js.map +0 -1
- package/dist/package.json +0 -141
- package/dist/routes/index.js.map +0 -1
- package/dist/routes/v1/decrypt.js.map +0 -1
- package/dist/routes/v1/encrypt.js.map +0 -1
- package/dist/routes/v1/generate.js.map +0 -1
- package/dist/routes/v1/revoke.js.map +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
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/sealedbox/seal", {
|
|
39
|
+
schema: {
|
|
40
|
+
tags: ["Sealed Box"],
|
|
41
|
+
summary: "Anonymous public-key encryption (X25519 sealed box)",
|
|
42
|
+
body: {
|
|
43
|
+
type: "object",
|
|
44
|
+
required: ["recipientPublicKey", "plaintext"],
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
properties: {
|
|
47
|
+
recipientPublicKey: { type: "string", minLength: 1 },
|
|
48
|
+
plaintext: { type: "string", minLength: 1 },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}, async (request, reply) => {
|
|
53
|
+
try {
|
|
54
|
+
const { seal } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/high-level/sealedbox")));
|
|
55
|
+
const { recipientPublicKey, plaintext } = request.body;
|
|
56
|
+
return reply.send({ data: seal(recipientPublicKey, plaintext) });
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Encryption");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
app.post("/v2/sealedbox/open", {
|
|
63
|
+
schema: {
|
|
64
|
+
tags: ["Sealed Box"],
|
|
65
|
+
summary: "Decrypt an anonymous sealed box (X25519)",
|
|
66
|
+
body: {
|
|
67
|
+
type: "object",
|
|
68
|
+
required: ["recipientSecretKey", "sealed"],
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
properties: {
|
|
71
|
+
recipientSecretKey: { type: "string", minLength: 1 },
|
|
72
|
+
sealed: { type: "string", minLength: 1 },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
}, async (request, reply) => {
|
|
77
|
+
try {
|
|
78
|
+
const { open } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/high-level/sealedbox")));
|
|
79
|
+
const { recipientSecretKey, sealed } = request.body;
|
|
80
|
+
const plaintext = open(recipientSecretKey, sealed);
|
|
81
|
+
return reply.send({
|
|
82
|
+
data: Buffer.from(plaintext).toString("utf8"),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Decryption");
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
app.post("/v2/sealedbox/seal-pq", {
|
|
90
|
+
schema: {
|
|
91
|
+
tags: ["Sealed Box"],
|
|
92
|
+
summary: "Post-quantum anonymous encryption (X25519 + ML-KEM-768 sealed box)",
|
|
93
|
+
body: {
|
|
94
|
+
type: "object",
|
|
95
|
+
required: ["x25519PublicKey", "mlKemPublicKey", "plaintext"],
|
|
96
|
+
additionalProperties: false,
|
|
97
|
+
properties: {
|
|
98
|
+
x25519PublicKey: { type: "string", minLength: 1 },
|
|
99
|
+
mlKemPublicKey: { type: "string", minLength: 1 },
|
|
100
|
+
plaintext: { type: "string", minLength: 1 },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
}, async (request, reply) => {
|
|
105
|
+
try {
|
|
106
|
+
const { sealPQ } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/high-level/sealedbox")));
|
|
107
|
+
const { x25519PublicKey, mlKemPublicKey, plaintext } = request.body;
|
|
108
|
+
return reply.send({
|
|
109
|
+
data: sealPQ(x25519PublicKey, mlKemPublicKey, plaintext),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Encryption");
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
app.post("/v2/sealedbox/open-pq", {
|
|
117
|
+
schema: {
|
|
118
|
+
tags: ["Sealed Box"],
|
|
119
|
+
summary: "Decrypt a post-quantum sealed box (X25519 + ML-KEM-768)",
|
|
120
|
+
body: {
|
|
121
|
+
type: "object",
|
|
122
|
+
required: ["x25519SecretKey", "mlKemSecretKey", "sealed"],
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
properties: {
|
|
125
|
+
x25519SecretKey: { type: "string", minLength: 1 },
|
|
126
|
+
mlKemSecretKey: { type: "string", minLength: 1 },
|
|
127
|
+
sealed: { type: "string", minLength: 1 },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
}, async (request, reply) => {
|
|
132
|
+
try {
|
|
133
|
+
const { openPQ } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/high-level/sealedbox")));
|
|
134
|
+
const { x25519SecretKey, mlKemSecretKey, sealed } = request.body;
|
|
135
|
+
const plaintext = openPQ(x25519SecretKey, mlKemSecretKey, sealed);
|
|
136
|
+
return reply.send({
|
|
137
|
+
data: Buffer.from(plaintext).toString("utf8"),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Decryption");
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=sealedbox.js.map
|
|
@@ -0,0 +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;yBAI/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAyEE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
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/secretbox/seal", {
|
|
39
|
+
schema: {
|
|
40
|
+
tags: ["Secretbox"],
|
|
41
|
+
summary: "Encrypt with XChaCha20-Poly1305 (secretbox seal)",
|
|
42
|
+
body: {
|
|
43
|
+
type: "object",
|
|
44
|
+
required: ["key", "plaintext"],
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
properties: {
|
|
47
|
+
key: { type: "string", minLength: 1 },
|
|
48
|
+
plaintext: { type: "string", minLength: 1 },
|
|
49
|
+
aad: { type: "string" },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}, async (request, reply) => {
|
|
54
|
+
try {
|
|
55
|
+
const { seal } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/high-level/secretbox")));
|
|
56
|
+
const { key, plaintext, aad } = request.body;
|
|
57
|
+
const aadBytes = aad ? Buffer.from(aad, "utf8") : undefined;
|
|
58
|
+
return reply.send({ data: seal(key, plaintext, aadBytes) });
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Encryption");
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
app.post("/v2/secretbox/open", {
|
|
65
|
+
schema: {
|
|
66
|
+
tags: ["Secretbox"],
|
|
67
|
+
summary: "Decrypt with XChaCha20-Poly1305 (secretbox open)",
|
|
68
|
+
body: {
|
|
69
|
+
type: "object",
|
|
70
|
+
required: ["key", "ciphertext"],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
properties: {
|
|
73
|
+
key: { type: "string", minLength: 1 },
|
|
74
|
+
ciphertext: { type: "string", minLength: 1 },
|
|
75
|
+
aad: { type: "string" },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
}, async (request, reply) => {
|
|
80
|
+
try {
|
|
81
|
+
const { open } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/dist/high-level/secretbox")));
|
|
82
|
+
const { key, ciphertext, aad } = request.body;
|
|
83
|
+
const aadBytes = aad ? Buffer.from(aad, "utf8") : undefined;
|
|
84
|
+
const plaintext = open(key, ciphertext, aadBytes);
|
|
85
|
+
return reply.send({
|
|
86
|
+
data: Buffer.from(plaintext).toString("utf8"),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Decryption");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=secretbox.js.map
|
|
@@ -0,0 +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;yBAQ/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBA6EE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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/sign", {
|
|
7
|
+
schema: {
|
|
8
|
+
tags: ["Signing"],
|
|
9
|
+
summary: "Sign with Ed25519",
|
|
10
|
+
description: "Create an Ed25519 digital signature over a message.",
|
|
11
|
+
body: {
|
|
12
|
+
type: "object",
|
|
13
|
+
required: ["privateKey", "message"],
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
privateKey: { type: "string", minLength: 64, maxLength: 64 },
|
|
17
|
+
message: {
|
|
18
|
+
type: "string",
|
|
19
|
+
minLength: 1,
|
|
20
|
+
maxLength: 10 * 1024 * 1024,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}, async (request, reply) => {
|
|
26
|
+
try {
|
|
27
|
+
const { privateKey, message } = request.body;
|
|
28
|
+
const result = (0, modern_1.ed25519Sign)(privateKey, message);
|
|
29
|
+
return reply.send({ data: result });
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Signing");
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
app.post("/v2/verify", {
|
|
36
|
+
schema: {
|
|
37
|
+
tags: ["Signing"],
|
|
38
|
+
summary: "Verify an Ed25519 signature",
|
|
39
|
+
description: "Verify a digital signature against a message and public key.",
|
|
40
|
+
body: {
|
|
41
|
+
type: "object",
|
|
42
|
+
required: ["publicKey", "message", "signature"],
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
publicKey: { type: "string", minLength: 64, maxLength: 64 },
|
|
46
|
+
message: {
|
|
47
|
+
type: "string",
|
|
48
|
+
minLength: 1,
|
|
49
|
+
maxLength: 10 * 1024 * 1024,
|
|
50
|
+
},
|
|
51
|
+
signature: { type: "string", minLength: 128, maxLength: 128 },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}, async (request, reply) => {
|
|
56
|
+
try {
|
|
57
|
+
const { publicKey, message, signature } = request.body;
|
|
58
|
+
const result = (0, modern_1.ed25519Verify)(publicKey, message, signature);
|
|
59
|
+
return reply.send({ data: result });
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Verification");
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/routes/v2/stream.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;yBAuQ/B,KAAK,eAAe,KAAG,IAAI;AAA3C,wBAIE"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
4
|
+
const iso20022_1 = require("@sebastienrousseau/crypto-lib/dist/protocols/iso20022");
|
|
5
|
+
const route_helpers_1 = require("../../utils/route-helpers");
|
|
6
|
+
const SIGN_SCHEMA = {
|
|
7
|
+
tags: ["Streaming"],
|
|
8
|
+
summary: "Batch sign messages with sub-millisecond throughput",
|
|
9
|
+
description: "Process high-throughput batch digital signing operations over multiple payloads.",
|
|
10
|
+
body: {
|
|
11
|
+
type: "object",
|
|
12
|
+
required: ["items"],
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
properties: {
|
|
15
|
+
items: {
|
|
16
|
+
type: "array",
|
|
17
|
+
minItems: 1,
|
|
18
|
+
maxItems: 1000,
|
|
19
|
+
items: {
|
|
20
|
+
type: "object",
|
|
21
|
+
required: ["id", "message", "privateKey"],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
properties: {
|
|
24
|
+
id: { type: "string" },
|
|
25
|
+
message: { type: "string", minLength: 1 },
|
|
26
|
+
privateKey: { type: "string", minLength: 64, maxLength: 64 },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const VERIFY_SCHEMA = {
|
|
34
|
+
tags: ["Streaming"],
|
|
35
|
+
summary: "Batch verify digital signatures",
|
|
36
|
+
description: "Batch verification pipeline for high-concurrency payment and transaction verification.",
|
|
37
|
+
body: {
|
|
38
|
+
type: "object",
|
|
39
|
+
required: ["items"],
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
properties: {
|
|
42
|
+
items: {
|
|
43
|
+
type: "array",
|
|
44
|
+
minItems: 1,
|
|
45
|
+
maxItems: 1000,
|
|
46
|
+
items: {
|
|
47
|
+
type: "object",
|
|
48
|
+
required: ["id", "message", "signature", "publicKey"],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
properties: {
|
|
51
|
+
id: { type: "string" },
|
|
52
|
+
message: { type: "string", minLength: 1 },
|
|
53
|
+
signature: { type: "string", minLength: 1 },
|
|
54
|
+
publicKey: { type: "string", minLength: 64, maxLength: 64 },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const ISO20022_SCHEMA = {
|
|
62
|
+
tags: ["Wholesale Payments"],
|
|
63
|
+
summary: "Verify ISO 20022 post-quantum dual-signature envelope",
|
|
64
|
+
description: "Validates the payload digest and both the Ed25519 and ML-DSA signatures of a pacs.008, pain.001 or camt.053 envelope. Signatures are checked against trustedKeys, the signer's public keys from the caller's own registry; the public keys inside the envelope are ignored.",
|
|
65
|
+
body: {
|
|
66
|
+
type: "object",
|
|
67
|
+
required: ["envelope", "payload", "trustedKeys"],
|
|
68
|
+
additionalProperties: false,
|
|
69
|
+
properties: {
|
|
70
|
+
trustedKeys: {
|
|
71
|
+
type: "object",
|
|
72
|
+
required: ["classicalPublicKey", "postQuantumPublicKey"],
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
properties: {
|
|
75
|
+
classicalPublicKey: { type: "string", minLength: 1 },
|
|
76
|
+
postQuantumPublicKey: { type: "string", minLength: 1 },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
envelope: {
|
|
80
|
+
type: "object",
|
|
81
|
+
required: [
|
|
82
|
+
"messageId",
|
|
83
|
+
"messageType",
|
|
84
|
+
"payloadDigest",
|
|
85
|
+
"digestAlgorithm",
|
|
86
|
+
"timestamp",
|
|
87
|
+
"classical",
|
|
88
|
+
"postQuantum",
|
|
89
|
+
],
|
|
90
|
+
additionalProperties: false,
|
|
91
|
+
properties: {
|
|
92
|
+
messageId: { type: "string" },
|
|
93
|
+
messageType: {
|
|
94
|
+
type: "string",
|
|
95
|
+
enum: ["pacs.008", "pain.001", "camt.053", "generic"],
|
|
96
|
+
},
|
|
97
|
+
payloadDigest: { type: "string" },
|
|
98
|
+
digestAlgorithm: {
|
|
99
|
+
type: "string",
|
|
100
|
+
enum: ["sha256", "sha384", "sha512"],
|
|
101
|
+
},
|
|
102
|
+
timestamp: { type: "string" },
|
|
103
|
+
classical: {
|
|
104
|
+
type: "object",
|
|
105
|
+
required: ["algorithm", "signature", "publicKey"],
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
properties: {
|
|
108
|
+
algorithm: { type: "string" },
|
|
109
|
+
signature: { type: "string" },
|
|
110
|
+
publicKey: { type: "string" },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
postQuantum: {
|
|
114
|
+
type: "object",
|
|
115
|
+
required: ["algorithm", "signature", "publicKey"],
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
properties: {
|
|
118
|
+
algorithm: {
|
|
119
|
+
type: "string",
|
|
120
|
+
enum: ["ml-dsa-44", "ml-dsa-65", "ml-dsa-87"],
|
|
121
|
+
},
|
|
122
|
+
signature: { type: "string" },
|
|
123
|
+
publicKey: { type: "string" },
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
payload: {},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
function registerBatchSign(app) {
|
|
133
|
+
app.post("/v2/stream/sign", { schema: SIGN_SCHEMA }, async (request, reply) => {
|
|
134
|
+
try {
|
|
135
|
+
const { items } = request.body;
|
|
136
|
+
const signatures = items.map((item) => {
|
|
137
|
+
const res = (0, crypto_lib_1.ed25519Sign)(item.privateKey, item.message);
|
|
138
|
+
return {
|
|
139
|
+
id: item.id,
|
|
140
|
+
signature: res.signature,
|
|
141
|
+
algorithm: "ed25519",
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
return reply.send({
|
|
145
|
+
data: {
|
|
146
|
+
count: signatures.length,
|
|
147
|
+
signatures,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Batch signing");
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function registerBatchVerify(app) {
|
|
157
|
+
app.post("/v2/stream/verify", { schema: VERIFY_SCHEMA }, async (request, reply) => {
|
|
158
|
+
try {
|
|
159
|
+
const { items } = request.body;
|
|
160
|
+
let validCount = 0;
|
|
161
|
+
const results = items.map((item) => {
|
|
162
|
+
try {
|
|
163
|
+
const res = (0, crypto_lib_1.ed25519Verify)(item.publicKey, item.message, item.signature);
|
|
164
|
+
if (res.valid)
|
|
165
|
+
validCount++;
|
|
166
|
+
return { id: item.id, valid: res.valid };
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return { id: item.id, valid: false };
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return reply.send({
|
|
173
|
+
data: {
|
|
174
|
+
count: results.length,
|
|
175
|
+
validCount,
|
|
176
|
+
allValid: validCount === results.length,
|
|
177
|
+
results,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "Batch verification");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function registerIso20022Verify(app) {
|
|
187
|
+
app.post("/v2/stream/iso20022", { schema: ISO20022_SCHEMA }, async (request, reply) => {
|
|
188
|
+
try {
|
|
189
|
+
const { envelope, payload, trustedKeys } = request.body;
|
|
190
|
+
const result = (0, iso20022_1.verifyIso20022Payment)(envelope, payload, {
|
|
191
|
+
classicalPublicKeyHex: trustedKeys.classicalPublicKey,
|
|
192
|
+
postQuantumPublicKeyHex: trustedKeys.postQuantumPublicKey,
|
|
193
|
+
});
|
|
194
|
+
return reply.send({ data: result });
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
return (0, route_helpers_1.classifyCryptoError)(error, request, reply, "ISO 20022 verification");
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
exports.default = (app) => {
|
|
202
|
+
registerBatchSign(app);
|
|
203
|
+
registerBatchVerify(app);
|
|
204
|
+
registerIso20022Verify(app);
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=stream.js.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AA4CnC,iBAAe,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CA0DtD;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.init = init;
|
|
40
|
+
const constants_1 = require("./config/constants");
|
|
41
|
+
const accepts_1 = __importDefault(require("@fastify/accepts"));
|
|
42
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
43
|
+
const etag_1 = __importDefault(require("@fastify/etag"));
|
|
44
|
+
const compress_1 = __importDefault(require("@fastify/compress"));
|
|
45
|
+
const fastify_healthcheck_1 = __importDefault(require("fastify-healthcheck"));
|
|
46
|
+
const helmet_1 = __importDefault(require("@fastify/helmet"));
|
|
47
|
+
const rate_limit_1 = __importDefault(require("@fastify/rate-limit"));
|
|
48
|
+
const swagger_1 = __importDefault(require("@fastify/swagger"));
|
|
49
|
+
const swagger_ui_1 = __importDefault(require("@fastify/swagger-ui"));
|
|
50
|
+
const crypto_1 = require("crypto");
|
|
51
|
+
const logger_1 = __importDefault(require("./lib/logger"));
|
|
52
|
+
const auth_1 = require("./lib/auth");
|
|
53
|
+
const metering_1 = require("./enterprise/metering");
|
|
54
|
+
const routes_1 = __importDefault(require("./routes"));
|
|
55
|
+
const fastify = __importStar(require("fastify"));
|
|
56
|
+
function isPublicPath(url) {
|
|
57
|
+
return (0, constants_1.isProbePath)(url) || url.startsWith("/docs");
|
|
58
|
+
}
|
|
59
|
+
async function registerDocs(app) {
|
|
60
|
+
await app.register(swagger_1.default, {
|
|
61
|
+
openapi: {
|
|
62
|
+
info: {
|
|
63
|
+
title: "Crypto Service Suite API",
|
|
64
|
+
description: "REST API for low-level cryptographic operations: key generation, encryption, decryption, signing, verification, and revocation.",
|
|
65
|
+
version: JSON.parse(constants_1.LIB_VERSION),
|
|
66
|
+
},
|
|
67
|
+
components: {
|
|
68
|
+
securitySchemes: {
|
|
69
|
+
apiKey: {
|
|
70
|
+
type: "apiKey",
|
|
71
|
+
name: "x-api-key",
|
|
72
|
+
in: "header",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
security: [{ apiKey: [] }],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
await app.register(swagger_ui_1.default, {
|
|
80
|
+
routePrefix: "/docs",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async function init() {
|
|
84
|
+
const app = fastify.fastify(constants_1.fastifyOptions);
|
|
85
|
+
logger_1.default.info("\n\nEnvironment details: " + constants_1.consoleOutput);
|
|
86
|
+
app.addHook("onRequest", async (request, reply) => {
|
|
87
|
+
const reqId = request.headers["x-request-id"] ?? (0, crypto_1.randomUUID)();
|
|
88
|
+
reply.header("x-request-id", reqId);
|
|
89
|
+
});
|
|
90
|
+
app.addHook("onSend", async (request, reply) => {
|
|
91
|
+
if (request.url.startsWith("/v2/")) {
|
|
92
|
+
reply.header("Cache-Control", "no-store, no-cache, must-revalidate");
|
|
93
|
+
reply.header("Pragma", "no-cache");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
await registerDocs(app);
|
|
97
|
+
await app
|
|
98
|
+
.register(accepts_1.default, { decorateReply: true })
|
|
99
|
+
.register(helmet_1.default, constants_1.helmetOptions)
|
|
100
|
+
.register(cors_1.default, constants_1.corsOptions)
|
|
101
|
+
.register(etag_1.default)
|
|
102
|
+
.register(compress_1.default, constants_1.compressOptions)
|
|
103
|
+
.register(fastify_healthcheck_1.default, constants_1.healthCheckOptions)
|
|
104
|
+
.register(rate_limit_1.default, {
|
|
105
|
+
...constants_1.rateLimitOptions,
|
|
106
|
+
max: (0, constants_1.resolveRateLimitMax)(),
|
|
107
|
+
});
|
|
108
|
+
await (0, auth_1.registerAuth)(app);
|
|
109
|
+
app.addHook("onRequest", async (request, reply) => {
|
|
110
|
+
if (isPublicPath(request.url))
|
|
111
|
+
return;
|
|
112
|
+
const auth = await (0, auth_1.authenticate)(request, reply);
|
|
113
|
+
if (!auth)
|
|
114
|
+
return reply;
|
|
115
|
+
request.auth = auth;
|
|
116
|
+
});
|
|
117
|
+
(0, metering_1.registerMetering)(app);
|
|
118
|
+
await app.register(async (scope) => {
|
|
119
|
+
(0, routes_1.default)(scope);
|
|
120
|
+
});
|
|
121
|
+
await app.ready();
|
|
122
|
+
return app;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=server.js.map
|