@danielsimonjr/mathts-matrix 0.1.1 → 0.1.3

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.
@@ -0,0 +1,78 @@
1
+ import "./chunk-PNKVD2UK.js";
2
+
3
+ // src/backends/wasm/integrity.ts
4
+ var ALGO = "sha384";
5
+ async function sha384OfBuffer(buffer) {
6
+ const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
7
+ const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
8
+ let digest;
9
+ if (isNode) {
10
+ const { createHash } = await import("crypto");
11
+ const hash = createHash(ALGO);
12
+ hash.update(bytes);
13
+ digest = new Uint8Array(hash.digest());
14
+ } else {
15
+ const copy = new ArrayBuffer(bytes.byteLength);
16
+ new Uint8Array(copy).set(bytes);
17
+ const out = await crypto.subtle.digest("SHA-384", copy);
18
+ digest = new Uint8Array(out);
19
+ }
20
+ let binary = "";
21
+ for (let i = 0; i < digest.length; i++) binary += String.fromCharCode(digest[i]);
22
+ const b64 = typeof btoa === "function" ? btoa(binary) : Buffer.from(digest).toString("base64");
23
+ return `sha384-${b64}`;
24
+ }
25
+ async function loadWasmManifest(wasmPath) {
26
+ const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
27
+ const manifestPath = wasmPath.replace(/[^/\\]+$/, "wasm-manifest.json");
28
+ try {
29
+ if (isNode) {
30
+ const fs = await import("fs");
31
+ const { promisify } = await import("util");
32
+ const readFile = promisify(fs.readFile);
33
+ const text = await readFile(manifestPath, "utf8");
34
+ return JSON.parse(text);
35
+ } else {
36
+ const res = await fetch(manifestPath);
37
+ if (!res.ok) return null;
38
+ return await res.json();
39
+ }
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+ async function verifyWasmIntegrity(buffer, wasmPath, options = {}) {
45
+ const fileName = wasmPath.split(/[/\\]/).pop() || wasmPath;
46
+ const manifest = options.manifest !== void 0 ? options.manifest : await loadWasmManifest(wasmPath);
47
+ if (!manifest) {
48
+ if (options.required) {
49
+ throw new Error(
50
+ `WASM integrity check failed: no manifest at sibling of "${wasmPath}" (required)`
51
+ );
52
+ }
53
+ if (typeof console !== "undefined") {
54
+ console.warn(
55
+ `[wasm-integrity] no manifest found beside "${wasmPath}"; skipping SHA-384 verification (set options.required=true to fail closed)`
56
+ );
57
+ }
58
+ return;
59
+ }
60
+ const expected = manifest[fileName];
61
+ if (!expected) {
62
+ if (options.required) {
63
+ throw new Error(`WASM integrity check failed: manifest has no entry for "${fileName}"`);
64
+ }
65
+ return;
66
+ }
67
+ const actual = await sha384OfBuffer(buffer);
68
+ if (actual !== expected) {
69
+ throw new Error(
70
+ `WASM integrity check failed for "${fileName}": expected ${expected}, got ${actual}`
71
+ );
72
+ }
73
+ }
74
+ export {
75
+ loadWasmManifest,
76
+ sha384OfBuffer,
77
+ verifyWasmIntegrity
78
+ };
package/package.json CHANGED
@@ -1,60 +1,60 @@
1
- {
2
- "name": "@danielsimonjr/mathts-matrix",
3
- "version": "0.1.1",
4
- "description": "Matrix operations for MathTS with WASM/WebGPU backend support",
5
- "author": "Daniel Simon Jr.",
6
- "license": "MIT",
7
- "type": "module",
8
- "main": "./dist/index.js",
9
- "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- }
16
- },
17
- "files": [
18
- "dist",
19
- "README.md"
20
- ],
21
- "scripts": {
22
- "build": "tsup src/index.ts --format esm --dts --clean",
23
- "dev": "tsup src/index.ts --format esm --dts --watch",
24
- "test": "vitest run",
25
- "test:watch": "vitest",
26
- "test:coverage": "vitest run --coverage",
27
- "typecheck": "tsc --noEmit",
28
- "lint": "eslint src --ext .ts",
29
- "lint:fix": "eslint src --ext .ts --fix",
30
- "clean": "rm -rf dist",
31
- "build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
32
- },
33
- "dependencies": {
34
- "@danielsimonjr/mathts-core": "*",
35
- "@danielsimonjr/mathts-parallel": "*"
36
- },
37
- "devDependencies": {
38
- "@types/node": "^25.5.2",
39
- "@webgpu/types": "^0.1.67",
40
- "tsup": "^8.0.0",
41
- "typescript": "^5.3.0",
42
- "vitest": "^2.0.0"
43
- },
44
- "publishConfig": {
45
- "access": "public"
46
- },
47
- "repository": {
48
- "type": "git",
49
- "url": "https://github.com/danielsimonjr/mathts",
50
- "directory": "matrix"
51
- },
52
- "keywords": [
53
- "math",
54
- "matrix",
55
- "linear-algebra",
56
- "typescript",
57
- "wasm",
58
- "webgpu"
59
- ]
60
- }
1
+ {
2
+ "name": "@danielsimonjr/mathts-matrix",
3
+ "version": "0.1.3",
4
+ "description": "Matrix operations for MathTS with WASM/WebGPU backend support",
5
+ "author": "Daniel Simon Jr.",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup src/index.ts --format esm --dts --clean",
23
+ "dev": "tsup src/index.ts --format esm --dts --watch",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "test:coverage": "vitest run --coverage",
27
+ "typecheck": "tsc --noEmit",
28
+ "lint": "eslint src --ext .ts",
29
+ "lint:fix": "eslint src --ext .ts --fix",
30
+ "clean": "rm -rf dist",
31
+ "build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
32
+ },
33
+ "dependencies": {
34
+ "@danielsimonjr/mathts-core": "*",
35
+ "@danielsimonjr/mathts-parallel": "*"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^25.5.2",
39
+ "@webgpu/types": "^0.1.67",
40
+ "tsup": "^8.0.0",
41
+ "typescript": "^5.3.0",
42
+ "vitest": "^4.1.5"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/danielsimonjr/mathts",
50
+ "directory": "matrix"
51
+ },
52
+ "keywords": [
53
+ "math",
54
+ "matrix",
55
+ "linear-algebra",
56
+ "typescript",
57
+ "wasm",
58
+ "webgpu"
59
+ ]
60
+ }