From 0c617c804047cbaf0f2029a0a33d3e3d4ac514eb Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Wed, 27 Sep 2023 11:49:03 +0200
Subject: [PATCH] feature(packaging): add node.js export
---
nucypher-core-wasm-bundler/README.md | 2 +-
nucypher-core-wasm-bundler/package-lock.json | 685 +++++++++++++++++-
nucypher-core-wasm-bundler/package.json | 22 +-
nucypher-core-wasm-bundler/rollup.config.js | 10 +-
nucypher-core-wasm-bundler/src/index.ts | 4 -
nucypher-core-wasm-bundler/src/index_core.ts | 2 +-
nucypher-core-wasm-bundler/src/index_fat.ts | 6 +
nucypher-core-wasm-bundler/src/index_node.ts | 8 +
nucypher-core-wasm-bundler/src/wasm.ts | 24 +-
nucypher-core-wasm-bundler/tests/wasm.test.ts | 15 +
nucypher-core-wasm-bundler/vitest.config.ts | 5 +
11 files changed, 746 insertions(+), 37 deletions(-)
delete mode 100644 nucypher-core-wasm-bundler/src/index.ts
create mode 100644 nucypher-core-wasm-bundler/src/index_fat.ts
create mode 100644 nucypher-core-wasm-bundler/src/index_node.ts
create mode 100644 nucypher-core-wasm-bundler/tests/wasm.test.ts
create mode 100644 nucypher-core-wasm-bundler/vitest.config.ts
diff --git a/nucypher-core-wasm-bundler/README.md b/nucypher-core-wasm-bundler/README.md
index 6f7f479..98cf52c 100644
--- a/nucypher-core-wasm-bundler/README.md
+++ b/nucypher-core-wasm-bundler/README.md
@@ -4,4 +4,4 @@
npm install
npm run build
npm run build:minify
-```
\ No newline at end of file
+```
diff --git a/nucypher-core-wasm-bundler/package-lock.json b/nucypher-core-wasm-bundler/package-lock.json
index 817934c..90eee3d 100644
--- a/nucypher-core-wasm-bundler/package-lock.json
+++ b/nucypher-core-wasm-bundler/package-lock.json
@@ -1,10 +1,12 @@
{
- "name": "@nucypher/nucypher-core-wasm",
+ "name": "@nucypher/nucypher-core",
+ "version": "0.13.0-alpha.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
- "name": "@nucypher/nucypher-core-wasm",
+ "name": "@nucypher/nucypher-core",
+ "version": "0.13.0-alpha.0",
"license": "GPL-3.0-only",
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.3",
@@ -12,11 +14,43 @@
"@types/node": "^20.5.6",
"rollup": "^3.29.2",
"tslib": "^2.6.2",
- "typescript": "^5.2.2"
+ "typescript": "^5.2.2",
+ "vitest": "^0.34.5"
}
},
+ "node_modules/@esbuild/linux-x64": {
+ "version": "0.18.20",
+ "cpu": [
+ "x64"
+ ],
+ "dev": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "linux"
+ ],
+ "engines": {
+ "node": ">=12"
+ }
+ },
+ "node_modules/@jest/schemas": {
+ "version": "29.6.3",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@sinclair/typebox": "^0.27.8"
+ },
+ "engines": {
+ "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
+ }
+ },
+ "node_modules/@jridgewell/sourcemap-codec": {
+ "version": "1.4.15",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@rollup/plugin-typescript": {
- "version": "11.1.3",
+ "version": "11.1.4",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -41,9 +75,12 @@
}
},
"node_modules/@rollup/plugin-wasm": {
- "version": "6.1.3",
+ "version": "6.2.1",
"dev": true,
"license": "MIT",
+ "dependencies": {
+ "@rollup/pluginutils": "^5.0.2"
+ },
"engines": {
"node": ">=14.0.0"
},
@@ -77,16 +114,239 @@
}
}
},
+ "node_modules/@sinclair/typebox": {
+ "version": "0.27.8",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@types/chai": {
+ "version": "4.3.6",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/@types/chai-subset": {
+ "version": "1.3.3",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/chai": "*"
+ }
+ },
"node_modules/@types/estree": {
- "version": "1.0.1",
+ "version": "1.0.2",
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
- "version": "20.6.3",
+ "version": "20.7.0",
"dev": true,
"license": "MIT"
},
+ "node_modules/@vitest/expect": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/spy": "0.34.5",
+ "@vitest/utils": "0.34.5",
+ "chai": "^4.3.7"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/runner": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@vitest/utils": "0.34.5",
+ "p-limit": "^4.0.0",
+ "pathe": "^1.1.1"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/snapshot": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "magic-string": "^0.30.1",
+ "pathe": "^1.1.1",
+ "pretty-format": "^29.5.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/spy": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "tinyspy": "^2.1.1"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/@vitest/utils": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "diff-sequences": "^29.4.3",
+ "loupe": "^2.3.6",
+ "pretty-format": "^29.5.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/acorn": {
+ "version": "8.10.0",
+ "dev": true,
+ "license": "MIT",
+ "bin": {
+ "acorn": "bin/acorn"
+ },
+ "engines": {
+ "node": ">=0.4.0"
+ }
+ },
+ "node_modules/acorn-walk": {
+ "version": "8.2.0",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.4.0"
+ }
+ },
+ "node_modules/ansi-styles": {
+ "version": "5.2.0",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=10"
+ },
+ "funding": {
+ "url": "https://github.com/chalk/ansi-styles?sponsor=1"
+ }
+ },
+ "node_modules/assertion-error": {
+ "version": "1.1.0",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
+ "node_modules/cac": {
+ "version": "6.7.14",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=8"
+ }
+ },
+ "node_modules/chai": {
+ "version": "4.3.8",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "assertion-error": "^1.1.0",
+ "check-error": "^1.0.2",
+ "deep-eql": "^4.1.2",
+ "get-func-name": "^2.0.0",
+ "loupe": "^2.3.1",
+ "pathval": "^1.1.1",
+ "type-detect": "^4.0.5"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/check-error": {
+ "version": "1.0.2",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
+ "node_modules/debug": {
+ "version": "4.3.4",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "ms": "2.1.2"
+ },
+ "engines": {
+ "node": ">=6.0"
+ },
+ "peerDependenciesMeta": {
+ "supports-color": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/deep-eql": {
+ "version": "4.1.3",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "type-detect": "^4.0.0"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/diff-sequences": {
+ "version": "29.6.3",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
+ }
+ },
+ "node_modules/esbuild": {
+ "version": "0.18.20",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "bin": {
+ "esbuild": "bin/esbuild"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "optionalDependencies": {
+ "@esbuild/android-arm": "0.18.20",
+ "@esbuild/android-arm64": "0.18.20",
+ "@esbuild/android-x64": "0.18.20",
+ "@esbuild/darwin-arm64": "0.18.20",
+ "@esbuild/darwin-x64": "0.18.20",
+ "@esbuild/freebsd-arm64": "0.18.20",
+ "@esbuild/freebsd-x64": "0.18.20",
+ "@esbuild/linux-arm": "0.18.20",
+ "@esbuild/linux-arm64": "0.18.20",
+ "@esbuild/linux-ia32": "0.18.20",
+ "@esbuild/linux-loong64": "0.18.20",
+ "@esbuild/linux-mips64el": "0.18.20",
+ "@esbuild/linux-ppc64": "0.18.20",
+ "@esbuild/linux-riscv64": "0.18.20",
+ "@esbuild/linux-s390x": "0.18.20",
+ "@esbuild/linux-x64": "0.18.20",
+ "@esbuild/netbsd-x64": "0.18.20",
+ "@esbuild/openbsd-x64": "0.18.20",
+ "@esbuild/sunos-x64": "0.18.20",
+ "@esbuild/win32-arm64": "0.18.20",
+ "@esbuild/win32-ia32": "0.18.20",
+ "@esbuild/win32-x64": "0.18.20"
+ }
+ },
"node_modules/estree-walker": {
"version": "2.0.2",
"dev": true,
@@ -97,6 +357,14 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/get-func-name": {
+ "version": "2.0.2",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/has": {
"version": "1.0.3",
"dev": true,
@@ -119,11 +387,111 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/jsonc-parser": {
+ "version": "3.2.0",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/local-pkg": {
+ "version": "0.4.3",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=14"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/antfu"
+ }
+ },
+ "node_modules/loupe": {
+ "version": "2.3.6",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "get-func-name": "^2.0.0"
+ }
+ },
+ "node_modules/magic-string": {
+ "version": "0.30.3",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@jridgewell/sourcemap-codec": "^1.4.15"
+ },
+ "engines": {
+ "node": ">=12"
+ }
+ },
+ "node_modules/mlly": {
+ "version": "1.4.2",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "acorn": "^8.10.0",
+ "pathe": "^1.1.1",
+ "pkg-types": "^1.0.3",
+ "ufo": "^1.3.0"
+ }
+ },
+ "node_modules/ms": {
+ "version": "2.1.2",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/nanoid": {
+ "version": "3.3.6",
+ "dev": true,
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "bin": {
+ "nanoid": "bin/nanoid.cjs"
+ },
+ "engines": {
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
+ }
+ },
+ "node_modules/p-limit": {
+ "version": "4.0.0",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "yocto-queue": "^1.0.0"
+ },
+ "engines": {
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
"node_modules/path-parse": {
"version": "1.0.7",
"dev": true,
"license": "MIT"
},
+ "node_modules/pathe": {
+ "version": "1.1.1",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/pathval": {
+ "version": "1.1.1",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
+ "node_modules/picocolors": {
+ "version": "1.0.0",
+ "dev": true,
+ "license": "ISC"
+ },
"node_modules/picomatch": {
"version": "2.3.1",
"dev": true,
@@ -135,6 +503,61 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
+ "node_modules/pkg-types": {
+ "version": "1.0.3",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "jsonc-parser": "^3.2.0",
+ "mlly": "^1.2.0",
+ "pathe": "^1.1.0"
+ }
+ },
+ "node_modules/postcss": {
+ "version": "8.4.30",
+ "dev": true,
+ "funding": [
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/postcss/"
+ },
+ {
+ "type": "tidelift",
+ "url": "https://tidelift.com/funding/github/npm/postcss"
+ },
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/ai"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "nanoid": "^3.3.6",
+ "picocolors": "^1.0.0",
+ "source-map-js": "^1.0.2"
+ },
+ "engines": {
+ "node": "^10 || ^12 || >=14"
+ }
+ },
+ "node_modules/pretty-format": {
+ "version": "29.7.0",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@jest/schemas": "^29.6.3",
+ "ansi-styles": "^5.0.0",
+ "react-is": "^18.0.0"
+ },
+ "engines": {
+ "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
+ }
+ },
+ "node_modules/react-is": {
+ "version": "18.2.0",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/resolve": {
"version": "1.22.6",
"dev": true,
@@ -152,7 +575,7 @@
}
},
"node_modules/rollup": {
- "version": "3.29.2",
+ "version": "3.29.3",
"dev": true,
"license": "MIT",
"bin": {
@@ -166,6 +589,40 @@
"fsevents": "~2.3.2"
}
},
+ "node_modules/siginfo": {
+ "version": "2.0.0",
+ "dev": true,
+ "license": "ISC"
+ },
+ "node_modules/source-map-js": {
+ "version": "1.0.2",
+ "dev": true,
+ "license": "BSD-3-Clause",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/stackback": {
+ "version": "0.0.2",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/std-env": {
+ "version": "3.4.3",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/strip-literal": {
+ "version": "1.3.0",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "acorn": "^8.10.0"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/antfu"
+ }
+ },
"node_modules/supports-preserve-symlinks-flag": {
"version": "1.0.0",
"dev": true,
@@ -177,11 +634,40 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/tinybench": {
+ "version": "2.5.1",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/tinypool": {
+ "version": "0.7.0",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/tinyspy": {
+ "version": "2.1.1",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
"node_modules/tslib": {
"version": "2.6.2",
"dev": true,
"license": "0BSD"
},
+ "node_modules/type-detect": {
+ "version": "4.0.8",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=4"
+ }
+ },
"node_modules/typescript": {
"version": "5.2.2",
"dev": true,
@@ -193,6 +679,189 @@
"engines": {
"node": ">=14.17"
}
+ },
+ "node_modules/ufo": {
+ "version": "1.3.0",
+ "dev": true,
+ "license": "MIT"
+ },
+ "node_modules/vite": {
+ "version": "4.4.9",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "esbuild": "^0.18.10",
+ "postcss": "^8.4.27",
+ "rollup": "^3.27.1"
+ },
+ "bin": {
+ "vite": "bin/vite.js"
+ },
+ "engines": {
+ "node": "^14.18.0 || >=16.0.0"
+ },
+ "funding": {
+ "url": "https://github.com/vitejs/vite?sponsor=1"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.2"
+ },
+ "peerDependencies": {
+ "@types/node": ">= 14",
+ "less": "*",
+ "lightningcss": "^1.21.0",
+ "sass": "*",
+ "stylus": "*",
+ "sugarss": "*",
+ "terser": "^5.4.0"
+ },
+ "peerDependenciesMeta": {
+ "@types/node": {
+ "optional": true
+ },
+ "less": {
+ "optional": true
+ },
+ "lightningcss": {
+ "optional": true
+ },
+ "sass": {
+ "optional": true
+ },
+ "stylus": {
+ "optional": true
+ },
+ "sugarss": {
+ "optional": true
+ },
+ "terser": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/vite-node": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "cac": "^6.7.14",
+ "debug": "^4.3.4",
+ "mlly": "^1.4.0",
+ "pathe": "^1.1.1",
+ "picocolors": "^1.0.0",
+ "vite": "^3.0.0 || ^4.0.0 || ^5.0.0-0"
+ },
+ "bin": {
+ "vite-node": "vite-node.mjs"
+ },
+ "engines": {
+ "node": ">=v14.18.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ }
+ },
+ "node_modules/vitest": {
+ "version": "0.34.5",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/chai": "^4.3.5",
+ "@types/chai-subset": "^1.3.3",
+ "@types/node": "*",
+ "@vitest/expect": "0.34.5",
+ "@vitest/runner": "0.34.5",
+ "@vitest/snapshot": "0.34.5",
+ "@vitest/spy": "0.34.5",
+ "@vitest/utils": "0.34.5",
+ "acorn": "^8.9.0",
+ "acorn-walk": "^8.2.0",
+ "cac": "^6.7.14",
+ "chai": "^4.3.7",
+ "debug": "^4.3.4",
+ "local-pkg": "^0.4.3",
+ "magic-string": "^0.30.1",
+ "pathe": "^1.1.1",
+ "picocolors": "^1.0.0",
+ "std-env": "^3.3.3",
+ "strip-literal": "^1.0.1",
+ "tinybench": "^2.5.0",
+ "tinypool": "^0.7.0",
+ "vite": "^3.1.0 || ^4.0.0 || ^5.0.0-0",
+ "vite-node": "0.34.5",
+ "why-is-node-running": "^2.2.2"
+ },
+ "bin": {
+ "vitest": "vitest.mjs"
+ },
+ "engines": {
+ "node": ">=v14.18.0"
+ },
+ "funding": {
+ "url": "https://opencollective.com/vitest"
+ },
+ "peerDependencies": {
+ "@edge-runtime/vm": "*",
+ "@vitest/browser": "*",
+ "@vitest/ui": "*",
+ "happy-dom": "*",
+ "jsdom": "*",
+ "playwright": "*",
+ "safaridriver": "*",
+ "webdriverio": "*"
+ },
+ "peerDependenciesMeta": {
+ "@edge-runtime/vm": {
+ "optional": true
+ },
+ "@vitest/browser": {
+ "optional": true
+ },
+ "@vitest/ui": {
+ "optional": true
+ },
+ "happy-dom": {
+ "optional": true
+ },
+ "jsdom": {
+ "optional": true
+ },
+ "playwright": {
+ "optional": true
+ },
+ "safaridriver": {
+ "optional": true
+ },
+ "webdriverio": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/why-is-node-running": {
+ "version": "2.2.2",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "siginfo": "^2.0.0",
+ "stackback": "0.0.2"
+ },
+ "bin": {
+ "why-is-node-running": "cli.js"
+ },
+ "engines": {
+ "node": ">=8"
+ }
+ },
+ "node_modules/yocto-queue": {
+ "version": "1.0.0",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12.20"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
}
}
}
diff --git a/nucypher-core-wasm-bundler/package.json b/nucypher-core-wasm-bundler/package.json
index a2ed355..6b81d24 100644
--- a/nucypher-core-wasm-bundler/package.json
+++ b/nucypher-core-wasm-bundler/package.json
@@ -4,23 +4,28 @@
"license": "GPL-3.0-only",
"sideEffects": false,
"type": "module",
- "main": "./dist/umd/index.js",
- "module": "./dist/es/index.js",
+ "main": "./dist/umd/index_fat.js",
+ "module": "./dist/es/index_fat.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
- "import": "./dist/es/index.js",
- "default": "./dist/cjs/index.cjs"
- }
+ "node": "./dist/node/index_node.cjs",
+ "import": "./dist/es/index_fat.js",
+ "default": "./dist/cjs/index_fat.cjs"
+ },
+ "./nucypher_core.wasm": "./dist/nucypher_core_wasm_bg.wasm",
+ "./package.json": "./package.json"
},
"files": [
"dist"
],
"scripts": {
"build": "wasm-pack build -t web --out-dir ../nucypher-core-wasm-bundler/src/pkg ../nucypher-core-wasm && rm -rf dist/ && rollup -c",
- "build:minify": "npm run build && npx terser@latest --compress --mangle --output dist/cjs/index.cjs -- dist/cjs/index.cjs",
- "format": "npx prettier@latest --write src/ tests/ package.json rollup.config.js tsconfig.json vite.config.ts cli.js"
+ "pretest": "npm run build",
+ "build:minify": "npm run build && npx terser@latest --compress --mangle --output dist/cjs/index_fat.cjs -- dist/cjs/index_fat.cjs",
+ "test": "vitest run",
+ "format": "npx prettier@latest --write src/ tests/ package.json rollup.config.js tsconfig.json"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.3",
@@ -28,6 +33,7 @@
"@types/node": "^20.5.6",
"rollup": "^3.29.2",
"tslib": "^2.6.2",
- "typescript": "^5.2.2"
+ "typescript": "^5.2.2",
+ "vitest": "^0.34.5"
}
}
diff --git a/nucypher-core-wasm-bundler/rollup.config.js b/nucypher-core-wasm-bundler/rollup.config.js
index c822de1..db1364b 100644
--- a/nucypher-core-wasm-bundler/rollup.config.js
+++ b/nucypher-core-wasm-bundler/rollup.config.js
@@ -12,7 +12,7 @@ const outDir = (fmt, env) => {
};
const rolls = (fmt, env) => ({
- input: env !== "slim" ? "src/index.ts" : "src/index_slim.ts",
+ input: `src/index_${env}.ts`,
output: {
dir: `dist`,
format: fmt,
@@ -20,6 +20,7 @@ const rolls = (fmt, env) => ({
outDir(fmt, env) + `/[name].` + (fmt === "cjs" ? "cjs" : "js"),
name: "@nucypher/nucypher-core-wasm",
},
+ external: ["node:crypto"],
plugins: [
env !== "slim" &&
wasm(
@@ -30,7 +31,7 @@ const rolls = (fmt, env) => ({
publicPath: "../",
fileName: "[name][extname]",
}
- : { targetEnv: "auto-inline" }
+ : { targetEnv: "auto-inline" },
),
typescript({
target: fmt === "es" ? "ES2022" : "ES2017",
@@ -44,7 +45,7 @@ const rolls = (fmt, env) => ({
fs.mkdirSync(`./dist/types/pkg`, { recursive: true });
fs.copyFileSync(
path.resolve("./src/pkg/nucypher_core_wasm.d.ts"),
- path.resolve(`./dist/types/pkg/nucypher_core_wasm.d.ts`)
+ path.resolve("./dist/types/pkg/nucypher_core_wasm.d.ts"),
);
},
},
@@ -55,8 +56,7 @@ export default [
rolls("umd", "fat"),
rolls("es", "fat"),
rolls("cjs", "fat"),
- // TODO: No support a separate node build ATM
- // rolls("cjs", "node"),
+ rolls("cjs", "node"),
// TODO: Slim build is not supported ATM
// rolls("es", "slim"),
// rolls("cjs", "slim"),
diff --git a/nucypher-core-wasm-bundler/src/index.ts b/nucypher-core-wasm-bundler/src/index.ts
deleted file mode 100644
index 4596eca..0000000
--- a/nucypher-core-wasm-bundler/src/index.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { initialize } from "./wasm";
-
-export { initialize };
-export * from "./index_core.js";
diff --git a/nucypher-core-wasm-bundler/src/index_core.ts b/nucypher-core-wasm-bundler/src/index_core.ts
index 1660c80..63eea7e 100644
--- a/nucypher-core-wasm-bundler/src/index_core.ts
+++ b/nucypher-core-wasm-bundler/src/index_core.ts
@@ -1 +1 @@
-export * from "./pkg/nucypher_core_wasm.js";
+export * from "./wasm.js";
diff --git a/nucypher-core-wasm-bundler/src/index_fat.ts b/nucypher-core-wasm-bundler/src/index_fat.ts
new file mode 100644
index 0000000..d21d7fa
--- /dev/null
+++ b/nucypher-core-wasm-bundler/src/index_fat.ts
@@ -0,0 +1,6 @@
+export * from "./index_core.js";
+import wasm from "./pkg/nucypher_core_wasm_bg.wasm";
+import { setWasmInit } from "./wasm.js";
+
+// @ts-ignore
+setWasmInit(() => wasm());
diff --git a/nucypher-core-wasm-bundler/src/index_node.ts b/nucypher-core-wasm-bundler/src/index_node.ts
new file mode 100644
index 0000000..b399796
--- /dev/null
+++ b/nucypher-core-wasm-bundler/src/index_node.ts
@@ -0,0 +1,8 @@
+import { webcrypto } from "node:crypto";
+
+// Fixes Node.js ES module support
+// See: https://docs.rs/getrandom/latest/getrandom/#nodejs-es-module-support
+// @ts-ignore
+globalThis.crypto = webcrypto;
+
+export * from "./index_fat";
diff --git a/nucypher-core-wasm-bundler/src/wasm.ts b/nucypher-core-wasm-bundler/src/wasm.ts
index 99b6293..21bb511 100644
--- a/nucypher-core-wasm-bundler/src/wasm.ts
+++ b/nucypher-core-wasm-bundler/src/wasm.ts
@@ -1,17 +1,21 @@
-import wasm from "./pkg/nucypher_core_wasm_bg.wasm";
import init, { InitInput } from "./pkg/nucypher_core_wasm.js";
+export * from "./pkg/nucypher_core_wasm.js";
+
+let wasmInit: (() => InitInput) | undefined = undefined;
+
+export const setWasmInit = (arg: () => InitInput) => {
+ wasmInit = arg;
+};
+
let initialized: Promise | undefined = undefined;
-export const initialize = async (maybeWasm?: InitInput) => {
+
+export const initialize = async (wasm?: InitInput) => {
if (initialized === undefined) {
- // We're using a Promise to make sure that the WASM module is properly recognized by the JS code
- // generated by wasm-pack:
- // V here
- // const { instance, module } = await __wbg_load(await input, imports);
- // Ignoring "expression not callable" error
- // @ts-ignore
- const wasmPromise = Promise.resolve(maybeWasm ? maybeWasm : wasm());
- initialized = init(wasmPromise).then(() => void 0);
+ //@ts-ignore
+ const loadModule = wasm ?? wasmInit();
+ initialized = init(loadModule).then(() => void 0);
}
+
await initialized;
};
diff --git a/nucypher-core-wasm-bundler/tests/wasm.test.ts b/nucypher-core-wasm-bundler/tests/wasm.test.ts
new file mode 100644
index 0000000..2e0e65a
--- /dev/null
+++ b/nucypher-core-wasm-bundler/tests/wasm.test.ts
@@ -0,0 +1,15 @@
+import { beforeAll, describe, expect, it } from "vitest";
+import { SecretKey, initialize, EthereumAddress } from "..";
+
+describe("WASM module", () => {
+ beforeAll(async () => {
+ await initialize();
+ });
+
+ it("can use nucypher-core objects", async () => {
+ expect(
+ EthereumAddress.fromString("0x0000000000000000000000000000000000000000"),
+ ).toBeDefined();
+ expect(SecretKey.random()).toBeDefined();
+ });
+});
diff --git a/nucypher-core-wasm-bundler/vitest.config.ts b/nucypher-core-wasm-bundler/vitest.config.ts
new file mode 100644
index 0000000..77a73cf
--- /dev/null
+++ b/nucypher-core-wasm-bundler/vitest.config.ts
@@ -0,0 +1,5 @@
+import { defineConfig } from "vitest/config";
+
+export default defineConfig({
+ test: {},
+});