@sebastienrousseau/crypto-wasm 0.0.8 → 0.0.24

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.
@@ -8,6 +8,13 @@ export declare class WasmAccelerator {
8
8
  init(wasmSource?: BufferSource | Response): Promise<void>;
9
9
  status(): WasmStatus;
10
10
  hash(algorithm: string, data: Uint8Array): Promise<Uint8Array>;
11
+ mlKemEncapsulate(publicKey: Uint8Array): Promise<{
12
+ ciphertext: Uint8Array;
13
+ sharedSecret: Uint8Array;
14
+ }>;
15
+ mlKemDecapsulate(secretKey: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
16
+ mlDsaSign(secretKey: Uint8Array, message: Uint8Array): Promise<Uint8Array>;
17
+ mlDsaVerify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): Promise<boolean>;
11
18
  benchmark(operation: AcceleratedOperation, iterations?: number): Promise<BenchmarkResult>;
12
19
  destroy(): void;
13
20
  }
@@ -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;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,oBA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@@ const ALL_OPERATIONS = [
45
45
  "ed25519-sign",
46
46
  "ed25519-verify",
47
47
  "x25519-exchange",
48
+ "ml-kem-encapsulate",
49
+ "ml-kem-decapsulate",
50
+ "ml-dsa-sign",
51
+ "ml-dsa-verify",
48
52
  ];
49
53
  class WasmAccelerator {
50
54
  _module = null;
@@ -115,6 +119,66 @@ class WasmAccelerator {
115
119
  }
116
120
  return hashFn(data);
117
121
  }
122
+ async mlKemEncapsulate(publicKey) {
123
+ if (!this.isAvailable) {
124
+ const { mlKemEncapsulate } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
125
+ const hexKey = Buffer.from(publicKey).toString("hex");
126
+ const res = mlKemEncapsulate(hexKey);
127
+ return {
128
+ ciphertext: new Uint8Array(Buffer.from(res.ciphertext, "hex")),
129
+ sharedSecret: new Uint8Array(Buffer.from(res.sharedSecret, "hex")),
130
+ };
131
+ }
132
+ const exports = this._instance.exports;
133
+ const fn = exports["ml_kem_encapsulate"];
134
+ if (typeof fn !== "function") {
135
+ throw new Error('WASM module does not export "ml_kem_encapsulate"');
136
+ }
137
+ return fn(publicKey);
138
+ }
139
+ async mlKemDecapsulate(secretKey, ciphertext) {
140
+ if (!this.isAvailable) {
141
+ const { mlKemDecapsulate } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
142
+ const hexCt = Buffer.from(ciphertext).toString("hex");
143
+ const hexSk = Buffer.from(secretKey).toString("hex");
144
+ const res = mlKemDecapsulate(hexSk, hexCt);
145
+ return new Uint8Array(Buffer.from(res.sharedSecret, "hex"));
146
+ }
147
+ const exports = this._instance.exports;
148
+ const fn = exports["ml_kem_decapsulate"];
149
+ if (typeof fn !== "function") {
150
+ throw new Error('WASM module does not export "ml_kem_decapsulate"');
151
+ }
152
+ return fn(secretKey, ciphertext);
153
+ }
154
+ async mlDsaSign(secretKey, message) {
155
+ if (!this.isAvailable) {
156
+ const { mlDsaSign } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
157
+ const hexSk = Buffer.from(secretKey).toString("hex");
158
+ const res = mlDsaSign(65, hexSk, message);
159
+ return new Uint8Array(Buffer.from(res.signature, "hex"));
160
+ }
161
+ const exports = this._instance.exports;
162
+ const fn = exports["ml_dsa_sign"];
163
+ if (typeof fn !== "function") {
164
+ throw new Error('WASM module does not export "ml_dsa_sign"');
165
+ }
166
+ return fn(secretKey, message);
167
+ }
168
+ async mlDsaVerify(publicKey, message, signature) {
169
+ if (!this.isAvailable) {
170
+ const { mlDsaVerify } = await Promise.resolve().then(() => __importStar(require("@sebastienrousseau/crypto-lib/modern")));
171
+ const hexSig = Buffer.from(signature).toString("hex");
172
+ const hexPk = Buffer.from(publicKey).toString("hex");
173
+ return mlDsaVerify(65, hexPk, message, hexSig).valid;
174
+ }
175
+ const exports = this._instance.exports;
176
+ const fn = exports["ml_dsa_verify"];
177
+ if (typeof fn !== "function") {
178
+ throw new Error('WASM module does not export "ml_dsa_verify"');
179
+ }
180
+ return fn(publicKey, message, signature);
181
+ }
118
182
  async benchmark(operation, iterations = 1000) {
119
183
  const data = new Uint8Array(1024).fill(0x42);
120
184
  const { createHash } = await Promise.resolve().then(() => __importStar(require("node:crypto")));
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type AcceleratedOperation = "hash-sha256" | "hash-sha512" | "hash-blake3" | "aes-gcm-encrypt" | "aes-gcm-decrypt" | "argon2-hash" | "ed25519-sign" | "ed25519-verify" | "x25519-exchange";
1
+ export type AcceleratedOperation = "hash-sha256" | "hash-sha512" | "hash-blake3" | "aes-gcm-encrypt" | "aes-gcm-decrypt" | "argon2-hash" | "ed25519-sign" | "ed25519-verify" | "x25519-exchange" | "ml-kem-encapsulate" | "ml-kem-decapsulate" | "ml-dsa-sign" | "ml-dsa-verify";
2
2
  export interface BenchmarkResult {
3
3
  operation: AcceleratedOperation;
4
4
  jsTimeMs: number;
@@ -1 +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"}
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,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,aAAa,GACb,eAAe,CAAC;AAiBpB,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/package.json CHANGED
@@ -1,37 +1,42 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-wasm",
3
- "version": "0.0.8",
3
+ "version": "0.0.24",
4
4
  "description": "WebAssembly performance accelerator for crypto-lib — near-native speed for heavy cryptographic operations.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "engines": {
8
8
  "node": ">=22.0.0"
9
9
  },
10
+ "type": "commonjs",
10
11
  "main": "./dist/index.js",
11
12
  "types": "./dist/index.d.ts",
12
- "sideEffects": false,
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
16
  "require": "./dist/index.js",
17
- "import": "./dist/index.js"
18
- }
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./package.json": "./package.json"
19
20
  },
21
+ "sideEffects": false,
20
22
  "files": [
21
23
  "dist/**/*.js",
22
24
  "dist/**/*.d.ts",
23
25
  "dist/**/*.d.ts.map",
24
26
  "wasm/"
25
27
  ],
28
+ "dependencies": {
29
+ "@sebastienrousseau/crypto-lib": "0.0.24"
30
+ },
26
31
  "devDependencies": {
27
- "@types/chai": "^4.3.7",
32
+ "@types/chai": "^5.2.3",
28
33
  "@types/chai-as-promised": "^8.0.2",
29
- "@types/mocha": "^10.0.2",
34
+ "@types/mocha": "^10.0.10",
30
35
  "@types/node": "^26.6.3",
31
36
  "c8": "^12.0.0",
32
- "chai": "^4.5.0",
33
- "chai-as-promised": "^7.1.2",
34
- "mocha": "^10.8.2",
37
+ "chai": "^6.3.0",
38
+ "chai-as-promised": "^8.0.2",
39
+ "mocha": "^12.0.3",
35
40
  "rimraf": "^6.1.3",
36
41
  "ts-node": "^10.9.2",
37
42
  "typedoc": "^0.28.20",
@@ -53,8 +58,8 @@
53
58
  "clean": "rimraf ./coverage ./dist ./docs",
54
59
  "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
55
60
  "docs": "typedoc",
56
- "lint": "eslint --ext .ts src __tests__",
57
- "lint:fix": "eslint --cache --fix --ext .ts src __tests__",
61
+ "lint": "eslint src __tests__",
62
+ "lint:fix": "eslint --cache --fix src __tests__",
58
63
  "format": "prettier --write src/**/*.ts",
59
64
  "format:check": "prettier --check \"src/**/*.ts\""
60
65
  }