@sebastienrousseau/crypto-wasm 0.0.34 → 0.0.36

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 CHANGED
@@ -99,12 +99,12 @@ Crypto Service provides a complete cryptography stack across 14 specialized pack
99
99
 
100
100
  | Package | Role | Description |
101
101
  | :------------------------------------------------------------------------------------------------------------------------------------------ | :--------------- | :----------------------------------------------------------------------------------------------------------------------------- |
102
- | [`@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. |
102
+ | [`@sebastienrousseau/crypto-api`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-api) | API docs | Postman collection types and a Postman-to-Markdown converter; the server's API contract is its OpenAPI document. |
103
103
  | [`@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. |
104
104
  | [`@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). |
105
105
  | [`@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. |
106
106
  | [`@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. |
107
- | [`@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. |
107
+ | [`@sebastienrousseau/crypto-kms`](https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-kms) | Cloud KMS | Unified KMS interface: AWS KMS, Google Cloud KMS, Vault Transit and local providers; Azure is a stub. |
108
108
  | [`@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. |
109
109
  | [`@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. |
110
110
  | [`@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. |
@@ -144,8 +144,10 @@ error: `isAvailable` stays `false` and the JavaScript path is used.
144
144
 
145
145
  ### JavaScript fallback
146
146
 
147
- While no module is loaded, `hash()` uses Node.js `crypto`, and the
148
- ML-KEM-768 and ML-DSA-65 methods call crypto-lib. When a module is
147
+ While no module is loaded, `hash()` and the ML-KEM-768 and ML-DSA-65
148
+ methods call crypto-lib. `hash()` takes crypto-lib's hash names
149
+ (`sha256`, `sha384`, `sha512`, `sha3-256`, `sha3-512`, `blake2b`,
150
+ `blake3`; `SHA-256` and `sha-512` are read as `sha256` and `sha512`). When a module is
149
151
  loaded, each method calls the matching export and throws if the
150
152
  module does not provide it.
151
153
 
@@ -164,7 +166,7 @@ const caps = detectCapabilities();
164
166
 
165
167
  | Method | Fallback without a module | Export expected from a module |
166
168
  | :-------------------------------------- | :------------------------ | :------------------------------------------ |
167
- | `hash(algorithm, data)` | Node.js `crypto` | `hash_<algorithm>` |
169
+ | `hash(algorithm, data)` | crypto-lib `hash` | `hash_<algorithm>` |
168
170
  | `mlKemEncapsulate` / `mlKemDecapsulate` | crypto-lib ML-KEM-768 | `ml_kem_encapsulate` / `ml_kem_decapsulate` |
169
171
  | `mlDsaSign` / `mlDsaVerify` | crypto-lib ML-DSA-65 | `ml_dsa_sign` / `ml_dsa_verify` |
170
172
 
@@ -172,10 +174,11 @@ const caps = detectCapabilities();
172
174
 
173
175
  ## Benchmarks
174
176
 
175
- `benchmark()` times SHA-256 hashing of a 1 KiB buffer through Node.js
176
- `crypto` and through `hash()`. Without a module both paths are
177
- JavaScript, so it measures no acceleration. No benchmark results are
178
- published.
177
+ `benchmark(operation)` times the requested hash (`hash-sha256`,
178
+ `hash-sha512` or `hash-blake3`) of a 1 KiB buffer through crypto-lib and
179
+ through `hash()`, and throws for any other operation. Without a module
180
+ both paths are crypto-lib, so it measures no acceleration. No benchmark
181
+ results are published.
179
182
 
180
183
  <p align="right"><a href="#contents">Back to Top</a></p>
181
184
 
@@ -1 +1 @@
1
- {"version":3,"file":"accelerator.d.ts","sourceRoot":"","sources":["../src/accelerator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,UAAU,EACX,MAAM,SAAS,CAAC;AAyCjB,qBAAa,eAAe;IAE1B,OAAO,CAAC,OAAO,CAAmC;IAElD,OAAO,CAAC,SAAS,CAAqC;IAEtD,OAAO,CAAC,YAAY,CAAS;IAG7B,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGD,IAAI,UAAU,IAAI,WAAW,CAAC,MAAM,GAAG,IAAI,CAE1C;IAGK,IAAI,CAAC,UAAU,CAAC,EAAE,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAwC/D,MAAM,IAAI,UAAU;IAmBd,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA2B9D,gBAAgB,CACpB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,YAAY,EAAE,UAAU,CAAA;KAAE,CAAC;IA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,CACb,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,UAAU,CAAC;IAsBhB,WAAW,CACf,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,OAAO,CAAC;IA0Bb,SAAS,CACb,SAAS,EAAE,oBAAoB,EAC/B,UAAU,SAAO,GAChB,OAAO,CAAC,eAAe,CAAC;IA2B3B,OAAO,IAAI,IAAI;CAKhB"}
@@ -50,6 +50,15 @@ const ALL_OPERATIONS = [
50
50
  "ml-dsa-sign",
51
51
  "ml-dsa-verify",
52
52
  ];
53
+ const BENCHMARK_HASHES = {
54
+ "hash-sha256": "sha256",
55
+ "hash-sha512": "sha512",
56
+ "hash-blake3": "blake3",
57
+ };
58
+ function libHashName(algorithm) {
59
+ const name = algorithm.toLowerCase();
60
+ return (/^sha-\d+$/.test(name) ? name.replace("-", "") : name);
61
+ }
53
62
  class WasmAccelerator {
54
63
  _module = null;
55
64
  _instance = null;
@@ -106,11 +115,12 @@ class WasmAccelerator {
106
115
  }
107
116
  async hash(algorithm, data) {
108
117
  if (!this.isAvailable) {
109
- const { createHash } = await Promise.resolve().then(() => __importStar(require("node:crypto")));
110
- const nodeAlg = algorithm.replace("-", "").toLowerCase();
111
- const h = createHash(nodeAlg);
112
- h.update(data);
113
- return new Uint8Array(h.digest());
118
+ const { hash } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
119
+ const { digest } = hash({
120
+ algorithm: libHashName(algorithm),
121
+ data,
122
+ });
123
+ return new Uint8Array(Buffer.from(digest, "hex"));
114
124
  }
115
125
  const exports = this._instance.exports;
116
126
  const hashFn = exports[`hash_${algorithm.replace("-", "_")}`];
@@ -180,19 +190,19 @@ class WasmAccelerator {
180
190
  return fn(publicKey, message, signature);
181
191
  }
182
192
  async benchmark(operation, iterations = 1000) {
193
+ const algorithm = BENCHMARK_HASHES[operation];
194
+ if (algorithm === undefined) {
195
+ throw new Error(`benchmark supports hash-sha256, hash-sha512 and hash-blake3, not ${operation}`);
196
+ }
183
197
  const data = new Uint8Array(1024).fill(0x42);
184
- const { createHash } = await Promise.resolve().then(() => __importStar(require("node:crypto")));
198
+ const { hash } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
185
199
  const jsStart = performance.now();
186
- for (let i = 0; i < iterations; i++) {
187
- const h = createHash("sha256");
188
- h.update(data);
189
- h.digest();
190
- }
200
+ for (let i = 0; i < iterations; i++)
201
+ hash({ algorithm, data });
191
202
  const jsTimeMs = performance.now() - jsStart;
192
203
  const wasmStart = performance.now();
193
- for (let i = 0; i < iterations; i++) {
194
- await this.hash("sha256", data);
195
- }
204
+ for (let i = 0; i < iterations; i++)
205
+ await this.hash(algorithm, data);
196
206
  const wasmTimeMs = performance.now() - wasmStart;
197
207
  return {
198
208
  operation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-wasm",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "Placeholder for a WebAssembly accelerator for crypto-lib. It ships runtime detection and an accelerator interface only; no WebAssembly module yet, so operations run in JavaScript.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
@@ -26,7 +26,7 @@
26
26
  "wasm/"
27
27
  ],
28
28
  "dependencies": {
29
- "@sebastienrousseau/crypto-lib": "0.0.34"
29
+ "@sebastienrousseau/crypto-lib": "0.0.36"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/chai": "^5.2.3",
@@ -63,6 +63,7 @@
63
63
  "build:wasm": "echo 'No WebAssembly module source exists yet; see README'",
64
64
  "clean": "rimraf ./coverage ./dist ./docs",
65
65
  "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
66
+ "test:run": "mocha --config=.mocharc.cjs",
66
67
  "docs": "typedoc",
67
68
  "lint": "eslint src __tests__",
68
69
  "lint:fix": "eslint --cache --fix src __tests__",