@sebastienrousseau/crypto-server 0.0.33 → 0.0.35
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 +21 -17
- package/dist/enterprise/metering.d.ts.map +1 -1
- package/dist/enterprise/metering.js +22 -19
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +16 -30
- package/package.json +16 -9
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
**The Crypto Service ecosystem**
|
|
34
34
|
|
|
35
|
-
- [The Crypto Service ecosystem](#the-crypto-service-ecosystem) — full
|
|
35
|
+
- [The Crypto Service ecosystem](#the-crypto-service-ecosystem) — full 18-package suite overview
|
|
36
36
|
|
|
37
37
|
**Package reference**
|
|
38
38
|
|
|
@@ -106,22 +106,26 @@ curl -s -X POST http://localhost:3000/v2/hash \
|
|
|
106
106
|
|
|
107
107
|
Crypto Service provides a complete cryptography stack across 14 specialized packages:
|
|
108
108
|
|
|
109
|
-
| Package
|
|
110
|
-
|
|
|
111
|
-
| [`@sebastienrousseau/crypto-api`](
|
|
112
|
-
| [`@sebastienrousseau/crypto-
|
|
113
|
-
| [`@sebastienrousseau/crypto-
|
|
114
|
-
| [`@sebastienrousseau/crypto-
|
|
115
|
-
| [`@sebastienrousseau/crypto-
|
|
116
|
-
| [`@sebastienrousseau/crypto-
|
|
117
|
-
| [`@sebastienrousseau/crypto-
|
|
118
|
-
| [`@sebastienrousseau/crypto-
|
|
119
|
-
| [`@sebastienrousseau/crypto-
|
|
120
|
-
|
|
|
121
|
-
| [`@sebastienrousseau/crypto-
|
|
122
|
-
| [`@sebastienrousseau/crypto-
|
|
123
|
-
| [`@sebastienrousseau/crypto-
|
|
124
|
-
| [`@sebastienrousseau/crypto-
|
|
109
|
+
| Package | Role | Description |
|
|
110
|
+
| :---------------------------------------------------------------------------------------------------------------------------------------------- | :-------------- | :----------------------------------------------------------------------------------------------------------------------------- |
|
|
111
|
+
| [`@sebastienrousseau/crypto-api`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-api) | API Schemas | Shared TypeScript types and utilities for the Crypto Service Suite, defining the canonical API surface. |
|
|
112
|
+
| [`@sebastienrousseau/crypto-benchmarks`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-benchmarks) | Benchmarks | Benchmarks comparing classical and post-quantum cryptography: ops/sec, latency and throughput. |
|
|
113
|
+
| [`@sebastienrousseau/crypto-cbom`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-cbom) | CBOM | Cryptographic Bill of Materials generator and auditor (CycloneDX 1.6, SPDX 3.0). |
|
|
114
|
+
| [`@sebastienrousseau/crypto-cli`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-cli) | Terminal CLI | Command-line interface: hashing, key generation, encryption, signing, HPKE, Argon2id and CBOM scans, with an interactive menu. |
|
|
115
|
+
| [`@sebastienrousseau/crypto-edge`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-edge) | Edge Runtime | Edge-runtime cryptographic operations using the Web Crypto API, optimized for Cloudflare Workers, Vercel Edge, and Deno. |
|
|
116
|
+
| [`@sebastienrousseau/crypto-kms`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-kms) | Cloud KMS | Unified KMS interface: AWS KMS and local providers implemented; GCP, Azure and Vault are stubs. |
|
|
117
|
+
| [`@sebastienrousseau/crypto-lib`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-lib) | Core Library | Core library: post-quantum ML-KEM, ML-DSA and SLH-DSA, plus classical, modern and OpenPGP cryptography for TypeScript. |
|
|
118
|
+
| [`@sebastienrousseau/crypto-lsp`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-lsp) | IDE Analysis | Language server that flags weak and quantum-vulnerable cryptography in the editor, with quick fixes. |
|
|
119
|
+
| [`@sebastienrousseau/crypto-mcp`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-mcp) | AI Agents | Model Context Protocol server exposing cryptography tools to AI assistants and agents. |
|
|
120
|
+
| [`@sebastienrousseau/crypto-middleware`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-middleware) | Middleware | Cryptographic middleware for Express and Fastify: decrypt requests, encrypt responses, verify HMAC signatures and JWTs. |
|
|
121
|
+
| [`@sebastienrousseau/crypto-prisma`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-prisma) | ORM Adapter | Transparent field-level encryption extension for Prisma Client, using XChaCha20-Poly1305. |
|
|
122
|
+
| [`@sebastienrousseau/crypto-react`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-react) | React Hooks | React hooks and context provider for client-side cryptographic operations with zero boilerplate. |
|
|
123
|
+
| [`@sebastienrousseau/crypto-sdk`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-sdk) | Client SDK | A zero-dependency, typed HTTP client for the Crypto Service REST API, with full post-quantum support. |
|
|
124
|
+
| **[`@sebastienrousseau/crypto-server`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-server)** _(this package)_ | **HTTP API** | **A hardened Fastify REST API for cryptographic operations, with rate limiting, OpenAPI schemas, and post-quantum endpoints.** |
|
|
125
|
+
| [`@sebastienrousseau/crypto-testing`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-testing) | Test Support | Deterministic keys, fast mocks, and test fixtures for crypto-lib |
|
|
126
|
+
| [`@sebastienrousseau/crypto-typeorm`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-typeorm) | ORM Adapter | TypeORM column-level encryption with a single decorator, powered by crypto-lib. |
|
|
127
|
+
| [`@sebastienrousseau/crypto-vue`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-vue) | Vue Composables | Vue 3 composables for client-side cryptography |
|
|
128
|
+
| [`@sebastienrousseau/crypto-wasm`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-wasm) | Acceleration | Placeholder for a WebAssembly accelerator; no WebAssembly module ships yet. |
|
|
125
129
|
|
|
126
130
|
<p align="right"><a href="#contents">Back to Top</a></p>
|
|
127
131
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metering.d.ts","sourceRoot":"","sources":["../../src/enterprise/metering.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAG7E,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEZ,MAAM,SAAS,CAAC;AAWjB,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAsBxD,CAAC;AAGF,eAAO,MAAM,mBAAmB,QAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"metering.d.ts","sourceRoot":"","sources":["../../src/enterprise/metering.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAG7E,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,WAAW,EAEZ,MAAM,SAAS,CAAC;AAWjB,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAsBxD,CAAC;AAGF,eAAO,MAAM,mBAAmB,QAAS,CAAC;AA+B1C,qBAAa,cAAc;IAKvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;gBAIvC,UAAU,GAAE,MAA4B;IAI3D,IAAW,IAAI,IAAI,MAAM,CAExB;IASM,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW;IAOhD,OAAO,CAAC,QAAQ;IAwBhB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,YAAY;IAqBb,YAAY,CACjB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,EACjB,aAAa,CAAC,EAAE,MAAM,EACtB,KAAK,GAAE,MAAmB,GACzB,mBAAmB;IA2Cf,KAAK,IAAI,IAAI;CAGrB;AAGD,eAAO,MAAM,qBAAqB,gBAAuB,CAAC;AA6B1D,eAAO,MAAM,gBAAgB,GAC3B,KAAK,eAAe,EACpB,SAAQ,cAAqC,KAC5C,IAmCF,CAAC"}
|
|
@@ -28,6 +28,18 @@ exports.TIER_QUOTAS = {
|
|
|
28
28
|
};
|
|
29
29
|
exports.DEFAULT_MAX_TENANTS = 10_000;
|
|
30
30
|
const ANONYMOUS_TENANT = "anonymous";
|
|
31
|
+
const remainingTokens = (usage) => Math.floor(Math.max(0, usage.tokens));
|
|
32
|
+
function secondsToReset(usage, nowMs) {
|
|
33
|
+
const msIntoWindow = (nowMs - usage.lastRefillMs) % 60000;
|
|
34
|
+
return Math.max(1, Math.ceil((60000 - msIntoWindow) / 1000));
|
|
35
|
+
}
|
|
36
|
+
function recordRequest(usage, contentLength) {
|
|
37
|
+
usage.tokens -= 1;
|
|
38
|
+
usage.totalRequests += 1;
|
|
39
|
+
if (contentLength !== undefined && contentLength > 0) {
|
|
40
|
+
usage.totalBytes += contentLength;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
31
43
|
class MeteringEngine {
|
|
32
44
|
maxTenants;
|
|
33
45
|
tenants = new Map();
|
|
@@ -79,43 +91,34 @@ class MeteringEngine {
|
|
|
79
91
|
const quota = exports.TIER_QUOTAS[tier];
|
|
80
92
|
const usage = this.getUsage(tenantKey, tier, nowMs);
|
|
81
93
|
this.refillTokens(usage, quota, nowMs);
|
|
94
|
+
const status = { limit: quota.maxRequestsPerMinute, tier };
|
|
82
95
|
if (contentLength !== undefined &&
|
|
83
96
|
contentLength > quota.maxBytesPerPayload) {
|
|
84
|
-
const resetSeconds = Math.ceil((60000 - ((nowMs - usage.lastRefillMs) % 60000)) / 1000);
|
|
85
97
|
return {
|
|
86
98
|
allowed: false,
|
|
87
|
-
|
|
88
|
-
remaining:
|
|
89
|
-
resetSeconds:
|
|
90
|
-
tier,
|
|
99
|
+
...status,
|
|
100
|
+
remaining: remainingTokens(usage),
|
|
101
|
+
resetSeconds: secondsToReset(usage, nowMs),
|
|
91
102
|
error: `Payload size (${contentLength} bytes) exceeds tier limit of ${quota.maxBytesPerPayload} bytes`,
|
|
92
103
|
statusCode: 413,
|
|
93
104
|
};
|
|
94
105
|
}
|
|
95
106
|
if (usage.tokens < 1) {
|
|
96
|
-
const resetSeconds = Math.ceil((60000 - ((nowMs - usage.lastRefillMs) % 60000)) / 1000);
|
|
97
107
|
return {
|
|
98
108
|
allowed: false,
|
|
99
|
-
|
|
109
|
+
...status,
|
|
100
110
|
remaining: 0,
|
|
101
|
-
resetSeconds:
|
|
102
|
-
tier,
|
|
111
|
+
resetSeconds: secondsToReset(usage, nowMs),
|
|
103
112
|
error: `Tenant rate limit exceeded for tier '${tier}'. Limit: ${quota.maxRequestsPerMinute} req/min.`,
|
|
104
113
|
statusCode: 429,
|
|
105
114
|
};
|
|
106
115
|
}
|
|
107
|
-
usage
|
|
108
|
-
usage.totalRequests += 1;
|
|
109
|
-
if (contentLength !== undefined && contentLength > 0) {
|
|
110
|
-
usage.totalBytes += contentLength;
|
|
111
|
-
}
|
|
112
|
-
const resetSeconds = Math.ceil((60000 - ((nowMs - usage.lastRefillMs) % 60000)) / 1000);
|
|
116
|
+
recordRequest(usage, contentLength);
|
|
113
117
|
return {
|
|
114
118
|
allowed: true,
|
|
115
|
-
|
|
116
|
-
remaining:
|
|
117
|
-
resetSeconds:
|
|
118
|
-
tier,
|
|
119
|
+
...status,
|
|
120
|
+
remaining: remainingTokens(usage),
|
|
121
|
+
resetSeconds: secondsToReset(usage, nowMs),
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
reset() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMvC,MAAM,WAAW,eAAe;IAE9B,KAAK,EAAE,MAAM,CAAC;IAEd,OAAO,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AE,MAAM,CAAA;CAAE,GACvC,gBAAgB,CAAC,MAAM,CAAC,CAK1B;AAKD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAAC,MAAM,CAAC,CAgB1B;AASD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAMpD;AAKD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAAC,MAAM,CAAC,CAc1B;AAKD,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,SAAS,CAAC,EAAE,GAC1B,gBAAgB,CAAC,CAAC,CAAC,CAcrB;AAKD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAAC,IAAI,CAAC,CAexB;AAMD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,eAAe,EAAE,GACxB,IAAI,CAIN;AAOD,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAKD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,OAAO,CAcT"}
|
package/dist/utils/validation.js
CHANGED
|
@@ -31,42 +31,28 @@ function validateRequiredString(value, fieldName) {
|
|
|
31
31
|
}
|
|
32
32
|
return { valid: true, value };
|
|
33
33
|
}
|
|
34
|
+
const invalid = (field, message) => ({
|
|
35
|
+
valid: false,
|
|
36
|
+
error: { field, message },
|
|
37
|
+
});
|
|
38
|
+
function rangeProblem(n, { min, max }) {
|
|
39
|
+
if (min !== undefined && n < min)
|
|
40
|
+
return `must be at least ${min}`;
|
|
41
|
+
if (max !== undefined && n > max)
|
|
42
|
+
return `must be at most ${max}`;
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
34
45
|
function validateRequiredNumber(value, fieldName, options) {
|
|
35
46
|
if (value === undefined || value === null) {
|
|
36
|
-
return {
|
|
37
|
-
valid: false,
|
|
38
|
-
error: { field: fieldName, message: `${fieldName} is required` },
|
|
39
|
-
};
|
|
47
|
+
return invalid(fieldName, `${fieldName} is required`);
|
|
40
48
|
}
|
|
41
49
|
const numValue = typeof value === "number" ? value : Number(value);
|
|
42
|
-
const { min, max } = options ?? {};
|
|
43
50
|
if (!Number.isFinite(numValue)) {
|
|
44
|
-
return {
|
|
45
|
-
valid: false,
|
|
46
|
-
error: {
|
|
47
|
-
field: fieldName,
|
|
48
|
-
message: `${fieldName} must be a valid number`,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (min !== undefined && numValue < min) {
|
|
53
|
-
return {
|
|
54
|
-
valid: false,
|
|
55
|
-
error: {
|
|
56
|
-
field: fieldName,
|
|
57
|
-
message: `${fieldName} must be at least ${min}`,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (max !== undefined && numValue > max) {
|
|
62
|
-
return {
|
|
63
|
-
valid: false,
|
|
64
|
-
error: {
|
|
65
|
-
field: fieldName,
|
|
66
|
-
message: `${fieldName} must be at most ${max}`,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
51
|
+
return invalid(fieldName, `${fieldName} must be a valid number`);
|
|
69
52
|
}
|
|
53
|
+
const problem = rangeProblem(numValue, options ?? {});
|
|
54
|
+
if (problem)
|
|
55
|
+
return invalid(fieldName, `${fieldName} ${problem}`);
|
|
70
56
|
return { valid: true, value: numValue };
|
|
71
57
|
}
|
|
72
58
|
function validateOptionalNumber(value, defaultValue, fieldName, options) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebastienrousseau/crypto-server",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.35",
|
|
4
|
+
"description": "Fastify REST API for cryptography as a service: post-quantum ML-KEM and ML-DSA, encryption, signing, hashing and KMS endpoints, with OpenAPI docs, API key or JWT auth, rate limiting and OpenTelemetry.",
|
|
5
5
|
"author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
7
7
|
"homepage": "https://crypto-server.io",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"fastify-healthcheck": "^5.1.0",
|
|
61
61
|
"uuid": "^14.0.3",
|
|
62
62
|
"winston": "^3.17.0",
|
|
63
|
-
"@sebastienrousseau/crypto-
|
|
64
|
-
"@sebastienrousseau/crypto-
|
|
63
|
+
"@sebastienrousseau/crypto-lib": "0.0.35",
|
|
64
|
+
"@sebastienrousseau/crypto-kms": "0.0.35"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/chai": "^5.2.3",
|
|
@@ -82,13 +82,20 @@
|
|
|
82
82
|
"typescript": "~5.9.3"
|
|
83
83
|
},
|
|
84
84
|
"keywords": [
|
|
85
|
-
"
|
|
85
|
+
"fastify",
|
|
86
|
+
"rest-api",
|
|
86
87
|
"cryptography",
|
|
87
88
|
"encryption",
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
89
|
+
"post-quantum",
|
|
90
|
+
"pqc",
|
|
91
|
+
"ml-kem",
|
|
92
|
+
"ml-dsa",
|
|
93
|
+
"openapi",
|
|
94
|
+
"microservice",
|
|
95
|
+
"opentelemetry",
|
|
96
|
+
"jwt",
|
|
97
|
+
"kms",
|
|
98
|
+
"openpgp"
|
|
92
99
|
],
|
|
93
100
|
"publishConfig": {
|
|
94
101
|
"access": "public"
|