@sebastienrousseau/crypto-wasm 0.0.0-stage → 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ This project is dual-licensed under either of:
2
+
3
+ * Apache License, Version 2.0 — see LICENSE-APACHE
4
+ * MIT license — see LICENSE-MIT
5
+
6
+ at your option.
7
+
8
+ SPDX-License-Identifier: Apache-2.0 OR MIT
package/README.md CHANGED
@@ -1,3 +1,312 @@
1
- # Temporary Holding Version
1
+ <!-- SPDX-License-Identifier: Apache-2.0 OR MIT -->
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/sebastienrousseau/crypto-service/main/assets/crypto-wasm-logo.svg" alt="crypto-wasm logo" width="360" />
5
+ </p>
6
+
7
+ <h1 align="center">@sebastienrousseau/crypto-wasm</h1>
8
+
9
+ <p align="center">
10
+ WebAssembly performance accelerator for crypto-lib — near-native speed for SHA-256, AES-GCM, Argon2, Ed25519, and X25519.
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://github.com/sebastienrousseau/crypto-service/actions"><img src="https://img.shields.io/github/actions/workflow/status/sebastienrousseau/crypto-service/ci.yml?branch=main&style=for-the-badge&logo=github" alt="Build" /></a>
15
+ <a href="https://coveralls.io/github/sebastienrousseau/crypto-service?branch=main"><img src="https://img.shields.io/coveralls/github/sebastienrousseau/crypto-service?branch=main&style=for-the-badge" alt="Coverage" /></a>
16
+ <a href="https://www.npmjs.com/package/@sebastienrousseau/crypto-wasm"><img src="https://img.shields.io/npm/v/@sebastienrousseau/crypto-wasm.svg?style=for-the-badge&color=f14041&logo=npm" alt="Registry" /></a>
17
+ <a href="https://sebastienrousseau.github.io/crypto-service/"><img src="https://img.shields.io/badge/docs-TypeDoc-blue.svg?style=for-the-badge&labelColor=555555&logo=typescript" alt="Docs" /></a>
18
+ <a href="https://scorecard.dev/viewer/?uri=github.com/sebastienrousseau/crypto-service" title="ossf-scorecard"><img src="https://img.shields.io/badge/OpenSSF-Scorecard-blue?style=for-the-badge&logo=openssf" alt="OpenSSF Scorecard" /></a>
19
+ <a href="https://github.com/sebastienrousseau/crypto-service/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg?style=for-the-badge" alt="License: Apache-2.0 OR MIT" /></a>
20
+ <a href="https://github.com/sebastienrousseau/crypto-service/blob/main/docs/POLICIES.md"><img src="https://img.shields.io/badge/Node.js-%3E%3D22-93450a.svg?style=for-the-badge&logo=node.js" alt="Node.js 22 or newer" /></a>
21
+ </p>
22
+
23
+ ---
24
+
25
+ ## Contents
26
+
27
+ **Getting started**
28
+
29
+ - [Install](#install) — installation via pnpm, npm, or yarn
30
+ - [Requirements](#requirements) — runtime floor and environment prerequisites
31
+ - [Quick Start](#quick-start) — minimal working usage sample
32
+
33
+ **The Crypto Service ecosystem**
34
+
35
+ - [The Crypto Service ecosystem](#the-crypto-service-ecosystem) — full 14-package suite overview
36
+
37
+ **Package reference**
38
+
39
+ - [Reference & Usage](#overview) — features, configuration, and capabilities
40
+ - [Examples](#examples) — runnable sample code
41
+
42
+ **Operational**
43
+
44
+ - [Development](#development) — build, lint, format, and test targets
45
+ - [Security](#security) — vulnerability disclosure and cryptographic invariants
46
+ - [Documentation](#documentation) — TypeDoc API docs and ecosystem guides
47
+ - [Stability guarantees](#stability-guarantees) — SemVer axis and release policy
48
+ - [License](#license)
49
+
50
+ ---
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pnpm add @sebastienrousseau/crypto-wasm
56
+ # or
57
+ npm install @sebastienrousseau/crypto-wasm
58
+ # or
59
+ yarn add @sebastienrousseau/crypto-wasm
60
+ ```
61
+
62
+ <p align="right"><a href="#contents">Back to Top</a></p>
63
+
64
+ ---
65
+
66
+ ## Requirements
67
+
68
+ - **Node.js**: `^22.0.0` or `>=24.0.0` (active and maintenance LTS releases)
69
+ - **Package Manager**: `pnpm >=9` (recommended) or `npm >=10`
70
+ - **TypeScript**: `>=5.0` (when compiling with TypeScript)
71
+
72
+ <p align="right"><a href="#contents">Back to Top</a></p>
73
+
74
+ ---
75
+
76
+ ## Quick Start
77
+
78
+ ```ts
79
+ import {
80
+ WasmAccelerator,
81
+ isWasmSupported,
82
+ } from "@sebastienrousseau/crypto-wasm";
83
+
84
+ const accel = new WasmAccelerator();
85
+ await accel.init();
86
+
87
+ // Hash data -- uses WASM when available, JS fallback otherwise
88
+ const digest = await accel.hash("sha256", new TextEncoder().encode("hello"));
89
+ console.log(Buffer.from(digest).toString("hex"));
90
+ ```
91
+
92
+ <p align="right"><a href="#contents">Back to Top</a></p>
93
+
94
+ ---
95
+
96
+ ## The Crypto Service ecosystem
97
+
98
+ Crypto Service provides a complete cryptography stack across 14 specialized packages:
99
+
100
+ | Package | Role | Description |
101
+ | :---------------------------------------------------------------------- | :--------------- | :------------------------------------------------------------------------------------------------------------------------------------- |
102
+ | [`@sebastienrousseau/crypto-api`](../crypto-api) | API Schemas | Shared TypeScript types and utilities for the Crypto Service Suite, defining the canonical API surface. |
103
+ | [`@sebastienrousseau/crypto-cli`](../crypto-cli) | Terminal CLI | An interactive command-line interface for cryptographic operations, supporting both legacy OpenPGP and modern post-quantum algorithms. |
104
+ | [`@sebastienrousseau/crypto-edge`](../crypto-edge) | Edge Runtime | Edge-runtime cryptographic operations using the Web Crypto API, optimized for Cloudflare Workers, Vercel Edge, and Deno. |
105
+ | [`@sebastienrousseau/crypto-kms`](../crypto-kms) | Cloud KMS | Unified Key Management Service interface for AWS KMS, GCP Cloud KMS, Azure Key Vault, and HashiCorp Vault. |
106
+ | [`@sebastienrousseau/crypto-lib`](../crypto-lib) | Core Library | A modern cryptographic library for TypeScript, with post-quantum support, zero unsafe dependencies, and 100% test coverage. |
107
+ | [`@sebastienrousseau/crypto-middleware`](../crypto-middleware) | Middleware | Framework-agnostic cryptographic middleware for Express, Fastify, and Koa applications. |
108
+ | [`@sebastienrousseau/crypto-prisma`](../crypto-prisma) | ORM Adapter | Transparent field-level encryption extension for Prisma Client, using XChaCha20-Poly1305. |
109
+ | [`@sebastienrousseau/crypto-react`](../crypto-react) | React Hooks | React hooks and context provider for client-side cryptographic operations with zero boilerplate. |
110
+ | [`@sebastienrousseau/crypto-sdk`](../crypto-sdk) | Client SDK | A zero-dependency, typed HTTP client for the Crypto Service REST API, with full post-quantum support. |
111
+ | [`@sebastienrousseau/crypto-server`](../crypto-server) | HTTP API | A hardened Fastify REST API for cryptographic operations, with rate limiting, OpenAPI schemas, and post-quantum endpoints. |
112
+ | [`@sebastienrousseau/crypto-testing`](../crypto-testing) | Test Support | Deterministic keys, fast mocks, and test fixtures for crypto-lib |
113
+ | [`@sebastienrousseau/crypto-typeorm`](../crypto-typeorm) | ORM Adapter | TypeORM column-level encryption with a single decorator, powered by crypto-lib. |
114
+ | [`@sebastienrousseau/crypto-vue`](../crypto-vue) | Vue Composables | Vue 3 composables for client-side cryptography |
115
+ | **[`@sebastienrousseau/crypto-wasm`](../crypto-wasm)** _(this package)_ | **Acceleration** | **WebAssembly performance accelerator for crypto-lib** |
116
+
117
+ <p align="right"><a href="#contents">Back to Top</a></p>
118
+
119
+ ---
120
+
121
+ ## Overview
122
+
123
+ crypto-wasm is an optional performance accelerator for the Crypto
124
+ Service Suite. When installed alongside crypto-lib, heavy
125
+ cryptographic operations are automatically routed through a
126
+ WebAssembly module compiled from Rust, delivering near-native speed
127
+ for hashing, AES-GCM encryption, Argon2 password hashing, and
128
+ Ed25519/X25519 operations. If the WASM module is unavailable, every
129
+ operation transparently falls back to the equivalent pure-JavaScript
130
+ implementation.
131
+
132
+ <p align="right"><a href="#contents">Back to Top</a></p>
133
+
134
+ ## How It Works
135
+
136
+ ### Auto-Detection
137
+
138
+ When crypto-lib detects `@sebastienrousseau/crypto-wasm` as an
139
+ installed dependency, it automatically routes heavy cryptographic
140
+ operations through the WASM module. No configuration is needed.
141
+
142
+ ```
143
+ crypto-lib --> crypto-wasm installed?
144
+ | |
145
+ YES NO
146
+ | |
147
+ WASM path JS fallback
148
+ (near-native) (pure JS)
149
+ ```
150
+
151
+ ### Transparent Fallback
152
+
153
+ If the WASM module is not compiled or not available in the current
154
+ runtime, every operation falls back to the equivalent
155
+ pure-JavaScript implementation. Your application code does not need
156
+ to handle either case differently.
157
+
158
+ ### Runtime Detection
159
+
160
+ ```ts
161
+ import { detectCapabilities } from "@sebastienrousseau/crypto-wasm";
162
+
163
+ const caps = detectCapabilities();
164
+ // { wasmSupported: true, streamingSupported: true, simdSupported: true }
165
+ ```
166
+
167
+ <p align="right"><a href="#contents">Back to Top</a></p>
168
+
169
+ ## Supported Operations
170
+
171
+ | Operation | ID | Description |
172
+ | :-------------- | :---------------- | :----------------------------------- |
173
+ | SHA-256 | `hash-sha256` | SHA-256 hash computation |
174
+ | SHA-512 | `hash-sha512` | SHA-512 hash computation |
175
+ | BLAKE3 | `hash-blake3` | BLAKE3 hash computation |
176
+ | AES-GCM Encrypt | `aes-gcm-encrypt` | AES-256-GCM authenticated encryption |
177
+ | AES-GCM Decrypt | `aes-gcm-decrypt` | AES-256-GCM authenticated decryption |
178
+ | Argon2 | `argon2-hash` | Argon2id/i/d password hashing |
179
+ | Ed25519 Sign | `ed25519-sign` | Ed25519 signature generation |
180
+ | Ed25519 Verify | `ed25519-verify` | Ed25519 signature verification |
181
+ | X25519 | `x25519-exchange` | X25519 Diffie-Hellman key exchange |
182
+
183
+ <p align="right"><a href="#contents">Back to Top</a></p>
184
+
185
+ ## Building from Source
186
+
187
+ The WASM module is compiled from Rust. A Rust toolchain with
188
+ `wasm32-unknown-unknown` target is required.
189
+
190
+ ```bash
191
+ # Install Rust (if not already installed)
192
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
193
+
194
+ # Add the WASM target
195
+ rustup target add wasm32-unknown-unknown
196
+
197
+ # Install wasm-pack
198
+ cargo install wasm-pack
199
+
200
+ # Build the WASM module
201
+ pnpm run build:wasm
202
+ ```
203
+
204
+ The compiled `.wasm` file is placed in `wasm/crypto_accel.wasm`.
205
+
206
+ <p align="right"><a href="#contents">Back to Top</a></p>
207
+
208
+ ## Benchmarks
209
+
210
+ Run the built-in benchmark to compare JS and WASM performance:
211
+
212
+ ```ts
213
+ import { WasmAccelerator } from "@sebastienrousseau/crypto-wasm";
214
+
215
+ const accel = new WasmAccelerator();
216
+ await accel.init();
217
+
218
+ const result = await accel.benchmark("hash-sha256", 10000);
219
+ console.log(`JS: ${result.jsTimeMs.toFixed(2)} ms`);
220
+ console.log(`WASM: ${result.wasmTimeMs.toFixed(2)} ms`);
221
+ console.log(`Speedup: ${result.speedup.toFixed(2)}x`);
222
+ ```
223
+
224
+ **Expected speedups** (once Rust WASM module is compiled):
225
+
226
+ | Operation | Expected Speedup |
227
+ | :-------------------- | :--------------- |
228
+ | SHA-256 (large input) | 2-5x |
229
+ | AES-GCM | 3-8x |
230
+ | Argon2 | 5-15x |
231
+ | Ed25519 Sign | 2-4x |
232
+ | Ed25519 Verify | 2-4x |
233
+ | X25519 | 2-4x |
234
+
235
+ <p align="right"><a href="#contents">Back to Top</a></p>
236
+
237
+ ## Examples
238
+
239
+ All examples are self-contained TypeScript files in the `examples/`
240
+ directory. Run any example with:
241
+
242
+ ```bash
243
+ npx ts-node examples/<name>.ts
244
+ ```
245
+
246
+ | Category | Example | Purpose |
247
+ | :--------- | :-------------------------------------- | :----------------------------------------- |
248
+ | Accelerate | [accelerate.ts](examples/accelerate.ts) | Basic WASM acceleration for hashing |
249
+ | Benchmark | [benchmark.ts](examples/benchmark.ts) | Compare JS vs WASM performance |
250
+ | Detect | [detect.ts](examples/detect.ts) | Check WASM availability and capabilities |
251
+ | Fallback | [fallback.ts](examples/fallback.ts) | Graceful fallback when WASM is unavailable |
252
+
253
+ <p align="right"><a href="#contents">Back to Top</a></p>
254
+
255
+ <p align="right"><a href="#contents">Back to Top</a></p>
256
+
257
+ ---
258
+
259
+ ## Development
260
+
261
+ ```bash
262
+ pnpm --filter @sebastienrousseau/crypto-wasm run build
263
+ pnpm --filter @sebastienrousseau/crypto-wasm run test
264
+ pnpm --filter @sebastienrousseau/crypto-wasm run lint
265
+ pnpm --filter @sebastienrousseau/crypto-wasm run format
266
+ ```
267
+
268
+ All 18 packages in the Crypto Service workspace maintain a **100% coverage floor** across statements, branches, functions, and lines.
269
+
270
+ <p align="right"><a href="#contents">Back to Top</a></p>
271
+
272
+ ---
273
+
274
+ ## Security
275
+
276
+ Report vulnerabilities privately via [GitHub Security Advisories](https://github.com/sebastienrousseau/crypto-service/security/advisories) or according to [`SECURITY.md`](../../SECURITY.md). Never report security issues publicly.
277
+
278
+ Cryptographic operations use the `@noble/*` libraries, Node.js `crypto` and OpenPGP.js. `@noble/post-quantum` has not been independently audited and does not guarantee constant-time execution, and no module in this suite is FIPS 140-3 validated. Key zeroization is limited: JavaScript strings and garbage-collected buffers cannot be reliably wiped. See [`SECURITY.md`](../../SECURITY.md).
279
+
280
+ <p align="right"><a href="#contents">Back to Top</a></p>
281
+
282
+ ---
283
+
284
+ ## Documentation
285
+
286
+ - [Full Suite Documentation](https://sebastienrousseau.github.io/crypto-service/)
287
+ - [API Reference (TypeDoc)](https://sebastienrousseau.github.io/crypto-service/)
288
+ - [Developer Guide](../../DEVELOPMENT.md)
289
+ - [Security Policy](../../SECURITY.md)
290
+ - [Architecture & Design](../../ARCHITECTURE.md)
291
+
292
+ <p align="right"><a href="#contents">Back to Top</a></p>
293
+
294
+ ---
295
+
296
+ ## Stability guarantees
297
+
298
+ Versions advance strictly one step at a time on the `0.0.x` line (`v0.0.1` → `v0.0.2` → `v0.0.3` ... → `v0.0.999` → `v0.1.0`). Work for every release iteration begins on a dedicated `feat/v<version>` branch.
299
+
300
+ All 18 packages in the workspace move in lockstep. Public API signatures, cipher output formats, and serialization schemas are strictly versioned. Breaking changes to serialized formats or algorithm defaults are considered major breaking changes. Minimum toolchain upgrades (e.g. Node.js LTS floor) are governed by [POLICIES.md](../../docs/POLICIES.md).
301
+
302
+ <p align="right"><a href="#contents">Back to Top</a></p>
303
+
304
+ ---
305
+
306
+ ## License
307
+
308
+ Dual-licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) or [MIT](https://opensource.org/licenses/MIT), at your option.
309
+
310
+ Copyright (c) 2022-2026 Sebastien Rousseau and The Crypto Service Suite contributors.
311
+
312
+ <p align="right"><a href="#contents">Back to Top</a></p>
@@ -0,0 +1,14 @@
1
+ import type { AcceleratedOperation, BenchmarkResult, WasmStatus } from "./types";
2
+ export declare class WasmAccelerator {
3
+ private _module;
4
+ private _instance;
5
+ private _initialized;
6
+ get isAvailable(): boolean;
7
+ get wasmModule(): WebAssembly.Module | null;
8
+ init(wasmSource?: BufferSource | Response): Promise<void>;
9
+ status(): WasmStatus;
10
+ hash(algorithm: string, data: Uint8Array): Promise<Uint8Array>;
11
+ benchmark(operation: AcceleratedOperation, iterations?: number): Promise<BenchmarkResult>;
12
+ destroy(): void;
13
+ }
14
+ //# sourceMappingURL=accelerator.d.ts.map
@@ -0,0 +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;AAqCjB,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;IA4B9D,SAAS,CACb,SAAS,EAAE,oBAAoB,EAC/B,UAAU,SAAO,GAChB,OAAO,CAAC,eAAe,CAAC;IA6B3B,OAAO,IAAI,IAAI;CAKhB"}
@@ -0,0 +1,147 @@
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
+ exports.WasmAccelerator = void 0;
37
+ const version_1 = require("./version");
38
+ const ALL_OPERATIONS = [
39
+ "hash-sha256",
40
+ "hash-sha512",
41
+ "hash-blake3",
42
+ "aes-gcm-encrypt",
43
+ "aes-gcm-decrypt",
44
+ "argon2-hash",
45
+ "ed25519-sign",
46
+ "ed25519-verify",
47
+ "x25519-exchange",
48
+ ];
49
+ class WasmAccelerator {
50
+ _module = null;
51
+ _instance = null;
52
+ _initialized = false;
53
+ get isAvailable() {
54
+ return this._initialized && this._instance !== null;
55
+ }
56
+ get wasmModule() {
57
+ return this._module;
58
+ }
59
+ async init(wasmSource) {
60
+ if (this._initialized)
61
+ return;
62
+ try {
63
+ if (wasmSource) {
64
+ if (wasmSource instanceof Response) {
65
+ const { module, instance } = await WebAssembly.instantiateStreaming(wasmSource);
66
+ this._module = module;
67
+ this._instance = instance;
68
+ }
69
+ else {
70
+ const { module, instance } = await WebAssembly.instantiate(wasmSource);
71
+ this._module = module;
72
+ this._instance = instance;
73
+ }
74
+ }
75
+ else {
76
+ const fs = await Promise.resolve().then(() => __importStar(require("node:fs/promises")));
77
+ const path = await Promise.resolve().then(() => __importStar(require("node:path")));
78
+ const wasmPath = path.join(__dirname, "..", "wasm", "crypto_accel.wasm");
79
+ const buffer = await fs.readFile(wasmPath);
80
+ const { module, instance } = await WebAssembly.instantiate(buffer);
81
+ this._module = module;
82
+ this._instance = instance;
83
+ }
84
+ this._initialized = true;
85
+ }
86
+ catch {
87
+ this._initialized = true;
88
+ this._module = null;
89
+ this._instance = null;
90
+ }
91
+ }
92
+ status() {
93
+ return {
94
+ available: this.isAvailable,
95
+ version: this.isAvailable ? version_1.VERSION : null,
96
+ operations: this.isAvailable ? [...ALL_OPERATIONS] : [],
97
+ memoryUsageBytes: this._instance
98
+ ? this._instance.exports.memory.buffer
99
+ .byteLength
100
+ : 0,
101
+ };
102
+ }
103
+ async hash(algorithm, data) {
104
+ if (!this.isAvailable) {
105
+ const { createHash } = await Promise.resolve().then(() => __importStar(require("node:crypto")));
106
+ const nodeAlg = algorithm.replace("-", "").toLowerCase();
107
+ const h = createHash(nodeAlg);
108
+ h.update(data);
109
+ return new Uint8Array(h.digest());
110
+ }
111
+ const exports = this._instance.exports;
112
+ const hashFn = exports[`hash_${algorithm.replace("-", "_")}`];
113
+ if (typeof hashFn !== "function") {
114
+ throw new Error(`WASM module does not export hash function for "${algorithm}"`);
115
+ }
116
+ return hashFn(data);
117
+ }
118
+ async benchmark(operation, iterations = 1000) {
119
+ const data = new Uint8Array(1024).fill(0x42);
120
+ const { createHash } = await Promise.resolve().then(() => __importStar(require("node:crypto")));
121
+ const jsStart = performance.now();
122
+ for (let i = 0; i < iterations; i++) {
123
+ const h = createHash("sha256");
124
+ h.update(data);
125
+ h.digest();
126
+ }
127
+ const jsTimeMs = performance.now() - jsStart;
128
+ const wasmStart = performance.now();
129
+ for (let i = 0; i < iterations; i++) {
130
+ await this.hash("sha256", data);
131
+ }
132
+ const wasmTimeMs = performance.now() - wasmStart;
133
+ return {
134
+ operation,
135
+ jsTimeMs,
136
+ wasmTimeMs,
137
+ speedup: wasmTimeMs > 0 ? jsTimeMs / wasmTimeMs : 0,
138
+ };
139
+ }
140
+ destroy() {
141
+ this._module = null;
142
+ this._instance = null;
143
+ this._initialized = false;
144
+ }
145
+ }
146
+ exports.WasmAccelerator = WasmAccelerator;
147
+ //# sourceMappingURL=accelerator.js.map
@@ -0,0 +1,9 @@
1
+ export declare function isWasmSupported(): boolean;
2
+ export declare function isStreamingSupported(): boolean;
3
+ export declare function isSimdSupported(): boolean;
4
+ export declare function detectCapabilities(): {
5
+ wasmSupported: boolean;
6
+ streamingSupported: boolean;
7
+ simdSupported: boolean;
8
+ };
9
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAqBA,wBAAgB,eAAe,IAAI,OAAO,CAwBzC;AAoBD,wBAAgB,oBAAoB,IAAI,OAAO,CAK9C;AAkBD,wBAAgB,eAAe,IAAI,OAAO,CAoDzC;AAeD,wBAAgB,kBAAkB,IAAI;IAEpC,aAAa,EAAE,OAAO,CAAC;IAEvB,kBAAkB,EAAE,OAAO,CAAC;IAE5B,aAAa,EAAE,OAAO,CAAC;CACxB,CAMA"}
package/dist/detect.js ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWasmSupported = isWasmSupported;
4
+ exports.isStreamingSupported = isStreamingSupported;
5
+ exports.isSimdSupported = isSimdSupported;
6
+ exports.detectCapabilities = detectCapabilities;
7
+ function isWasmSupported() {
8
+ try {
9
+ if (typeof WebAssembly === "object" &&
10
+ typeof WebAssembly.instantiate === "function") {
11
+ const minimal = new Uint8Array([
12
+ 0x00,
13
+ 0x61,
14
+ 0x73,
15
+ 0x6d,
16
+ 0x01,
17
+ 0x00,
18
+ 0x00,
19
+ 0x00,
20
+ ]);
21
+ const mod = new WebAssembly.Module(minimal);
22
+ return mod instanceof WebAssembly.Module;
23
+ }
24
+ }
25
+ catch {
26
+ }
27
+ return false;
28
+ }
29
+ function isStreamingSupported() {
30
+ return (typeof WebAssembly === "object" &&
31
+ typeof WebAssembly.instantiateStreaming === "function");
32
+ }
33
+ function isSimdSupported() {
34
+ try {
35
+ const simd = new Uint8Array([
36
+ 0x00,
37
+ 0x61,
38
+ 0x73,
39
+ 0x6d,
40
+ 0x01,
41
+ 0x00,
42
+ 0x00,
43
+ 0x00,
44
+ 0x01,
45
+ 0x05,
46
+ 0x01,
47
+ 0x60,
48
+ 0x00,
49
+ 0x01,
50
+ 0x7b,
51
+ 0x03,
52
+ 0x02,
53
+ 0x01,
54
+ 0x00,
55
+ 0x0a,
56
+ 0x16,
57
+ 0x01,
58
+ 0x14,
59
+ 0x00,
60
+ 0xfd,
61
+ 0x0c,
62
+ 0x00,
63
+ 0x00,
64
+ 0x00,
65
+ 0x00,
66
+ 0x00,
67
+ 0x00,
68
+ 0x00,
69
+ 0x00,
70
+ 0x00,
71
+ 0x00,
72
+ 0x00,
73
+ 0x00,
74
+ 0x00,
75
+ 0x00,
76
+ 0x00,
77
+ 0x00,
78
+ 0x0b,
79
+ ]);
80
+ return new WebAssembly.Module(simd) instanceof WebAssembly.Module;
81
+ }
82
+ catch {
83
+ return false;
84
+ }
85
+ }
86
+ function detectCapabilities() {
87
+ return {
88
+ wasmSupported: isWasmSupported(),
89
+ streamingSupported: isStreamingSupported(),
90
+ simdSupported: isSimdSupported(),
91
+ };
92
+ }
93
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1,4 @@
1
+ export { WasmAccelerator } from "./accelerator";
2
+ export { detectCapabilities, isSimdSupported, isStreamingSupported, isWasmSupported, } from "./detect";
3
+ export type { AcceleratedOperation, BenchmarkResult, WasmStatus, } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,eAAe,GAChB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,oBAAoB,EACpB,eAAe,EACf,UAAU,GACX,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWasmSupported = exports.isStreamingSupported = exports.isSimdSupported = exports.detectCapabilities = exports.WasmAccelerator = void 0;
4
+ var accelerator_1 = require("./accelerator");
5
+ Object.defineProperty(exports, "WasmAccelerator", { enumerable: true, get: function () { return accelerator_1.WasmAccelerator; } });
6
+ var detect_1 = require("./detect");
7
+ Object.defineProperty(exports, "detectCapabilities", { enumerable: true, get: function () { return detect_1.detectCapabilities; } });
8
+ Object.defineProperty(exports, "isSimdSupported", { enumerable: true, get: function () { return detect_1.isSimdSupported; } });
9
+ Object.defineProperty(exports, "isStreamingSupported", { enumerable: true, get: function () { return detect_1.isStreamingSupported; } });
10
+ Object.defineProperty(exports, "isWasmSupported", { enumerable: true, get: function () { return detect_1.isWasmSupported; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ export type AcceleratedOperation = "hash-sha256" | "hash-sha512" | "hash-blake3" | "aes-gcm-encrypt" | "aes-gcm-decrypt" | "argon2-hash" | "ed25519-sign" | "ed25519-verify" | "x25519-exchange";
2
+ export interface BenchmarkResult {
3
+ operation: AcceleratedOperation;
4
+ jsTimeMs: number;
5
+ wasmTimeMs: number;
6
+ speedup: number;
7
+ }
8
+ export interface WasmStatus {
9
+ available: boolean;
10
+ version: string | null;
11
+ operations: AcceleratedOperation[];
12
+ memoryUsageBytes: number;
13
+ }
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,oBAAoB,GAC5B,aAAa,GACb,aAAa,GACb,aAAa,GACb,iBAAiB,GACjB,iBAAiB,GACjB,aAAa,GACb,cAAc,GACd,gBAAgB,GAChB,iBAAiB,CAAC;AAiBtB,MAAM,WAAW,eAAe;IAE9B,SAAS,EAAE,oBAAoB,CAAC;IAEhC,QAAQ,EAAE,MAAM,CAAC;IAEjB,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAgBD,MAAM,WAAW,UAAU;IAEzB,SAAS,EAAE,OAAO,CAAC;IAEnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,UAAU,EAAE,oBAAoB,EAAE,CAAC;IAEnC,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,2 @@
1
+ export declare const VERSION: string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,OAAO,EAAE,MAIb,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ exports.VERSION = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "..", "package.json"), "utf8")).version;
7
+ //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.7",
4
+ "description": "WebAssembly performance accelerator for crypto-lib — near-native speed for heavy cryptographic operations.",
5
+ "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
+ "license": "MIT OR Apache-2.0",
7
+ "engines": {
8
+ "node": ">=22.0.0"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "sideEffects": false,
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "require": "./dist/index.js",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist/**/*.js",
22
+ "dist/**/*.d.ts",
23
+ "dist/**/*.d.ts.map",
24
+ "wasm/"
25
+ ],
26
+ "devDependencies": {
27
+ "@types/chai": "^4.3.7",
28
+ "@types/chai-as-promised": "^8.0.2",
29
+ "@types/mocha": "^10.0.2",
30
+ "@types/node": "^26.4.1",
31
+ "c8": "^12.0.0",
32
+ "chai": "^4.5.0",
33
+ "chai-as-promised": "^7.1.2",
34
+ "mocha": "^10.8.2",
35
+ "rimraf": "^6.1.3",
36
+ "ts-node": "^10.9.2",
37
+ "typedoc": "^0.28.20",
38
+ "typescript": "~5.9.3"
39
+ },
40
+ "homepage": "https://github.com/sebastienrousseau/crypto-service/tree/main/packages/crypto-wasm",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "private": false,
45
+ "scripts": {
46
+ "build": "tsc --build tsconfig.json",
47
+ "build:wasm": "echo 'WASM build requires Rust toolchain — see README'",
48
+ "clean": "rimraf ./coverage ./dist ./docs",
49
+ "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
50
+ "docs": "typedoc",
51
+ "lint": "eslint --ext .ts src __tests__",
52
+ "lint:fix": "eslint --cache --fix --ext .ts src __tests__",
53
+ "format": "prettier --write src/**/*.ts",
54
+ "format:check": "prettier --check \"src/**/*.ts\""
55
+ }
6
56
  }
package/wasm/.gitkeep ADDED
File without changes