@zhuxe-js/native 0.0.0-stage → 0.1.0

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.
Files changed (2) hide show
  1. package/README.md +88 -2
  2. package/package.json +64 -5
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # @zhuxe-js/native
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
+ Optional native accelerators for [`zhuxe-assistance`](https://www.npmjs.com/package/zhuxe-assistance). Moves the crypto hot path off pure JavaScript and onto a compiled backend, with transparent fallback so the client works everywhere regardless of what's installed.
4
+
5
+ ## How it works
6
+
7
+ The same Rust core is shipped two ways, selected at load time. Callers never
8
+ change – the client resolves the fastest available backend and degrades
9
+ gracefully:
10
+
11
+ | Backend | What it is | Requires |
12
+ | -------- | ---------------------------------------- | ------------------------------------- |
13
+ | **napi** | Compiled Rust addon (fastest) | Building from source (Rust toolchain) |
14
+ | **wasm** | WebAssembly build of the same Rust core | Nothing – ships inside this package |
15
+ | **js** | Pure-JS / `node:crypto` (no accelerator) | Nothing – built into `zhuxe-assistance` |
16
+
17
+ If the native addon can't load, the WASM fallback is used; if that's disabled,
18
+ the pure-JS path in `zhuxe-assistance` takes over. Installing this package is always
19
+ safe: a missing or unsupported binary never breaks the client.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @zhuxe-js/native
25
+ ```
26
+
27
+ The published package currently ships the WASM backend only – it works on any
28
+ OS/arch with no toolchain. Prebuilt NAPI binaries are not on npm yet; to use
29
+ the (faster) native addon, build it from source inside a repo checkout with a
30
+ Rust toolchain installed:
31
+
32
+ ```bash
33
+ npm run build:napi -w packages/native
34
+ ```
35
+
36
+ ## Backend selection
37
+
38
+ The default (`auto`) tries the NAPI addon first, then the WASM build, then
39
+ the pure-JS path. To pin a single backend, set `ZHUXE_NATIVE_BACKEND` before
40
+ the process starts:
41
+
42
+ ```bash
43
+ ZHUXE_NATIVE_BACKEND=napi # only the native addon
44
+ ZHUXE_NATIVE_BACKEND=wasm # only the WebAssembly build
45
+ ZHUXE_NATIVE_BACKEND=js # disable the accelerator, use the pure-JS path
46
+ ```
47
+
48
+ A pinned backend that is unavailable does not error – the client silently
49
+ falls back to the pure-JS path.
50
+
51
+ ## One WASM artifact, Node and browser
52
+
53
+ The WASM backend is a single `--target web` build under `wasm/pkg/` – the
54
+ same artifact serves both environments:
55
+
56
+ - **Node**: `zhuxe-assistance` loads it automatically (the glue is ESM, loaded via
57
+ `require(esm)` and initialised synchronously with the bundled `.wasm`
58
+ bytes). This needs Node 20.19+ / 22.12+; on older runtimes the client
59
+ silently falls back to the pure-JS path.
60
+ - **Browser / bundler**: import it directly and initialise before use:
61
+
62
+ ```js
63
+ import init, {
64
+ x25519ScalarMult,
65
+ xeddsaSign,
66
+ xeddsaVerify
67
+ } from '@zhuxe-js/native/wasm/pkg/zhuxe_native_wasm.js'
68
+
69
+ await init()
70
+ const shared = x25519ScalarMult(privateKey, publicKey)
71
+ ```
72
+
73
+ ## Notes
74
+
75
+ - **Optional by design.** The accelerator is a performance layer, not a
76
+ correctness dependency – outputs are byte-identical across all three
77
+ backends (verified by the cross-check tests).
78
+ - **ABI-stable binaries.** The native addon is built with N-API, so one binary
79
+ per platform works across every supported Node version – no rebuild on Node
80
+ upgrades.
81
+ - **WASM runs anywhere.** The bundled WebAssembly fallback runs on any platform
82
+ the native addon doesn't cover.
83
+ - **The root import is the NAPI addon.** `require('@zhuxe-js/native')` resolves
84
+ to the compiled addon, so on the published wasm-only package it throws a
85
+ module-not-found error – that failure is exactly what makes `zhuxe-assistance` fall
86
+ through to the WASM build. To use the primitives directly, import the
87
+ `wasm/pkg` subpath shown above.
88
+
89
+ See the main [`zhuxe-assistance`](../../README.md) docs for the client contract.
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
- "name": "@zhuxe-js/native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@zhuxe-js/native",
3
+ "version": "0.1.0",
4
+ "description": "Native accelerators for zhuxe-assistance (Rust NAPI addon + WASM fallback)",
5
+ "license": "MIT",
6
+ "author": "vinikjkkj <contact@vinicius.email> (https://github.com/vinikjkkj)",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/abay62096-dotcom/zhuxe.git",
10
+ "directory": "packages/native"
11
+ },
12
+ "keywords": [
13
+ "zhuxe",
14
+ "napi",
15
+ "wasm",
16
+ "x25519",
17
+ "xeddsa",
18
+ "curve25519",
19
+ "crypto"
20
+ ],
21
+ "types": "binding.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./binding.d.ts",
25
+ "default": "./binding.js"
26
+ },
27
+ "./wasm/*": "./wasm/*"
28
+ },
29
+ "files": [
30
+ "wasm/pkg"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "peerDependencies": {
36
+ "zhuxe-assistance": "^1.7.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "zhuxe-assistance": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "engines": {
44
+ "node": ">=20.19.0"
45
+ },
46
+ "napi": {
47
+ "binaryName": "zhuxe-native",
48
+ "targets": [
49
+ "x86_64-pc-windows-msvc",
50
+ "x86_64-unknown-linux-gnu",
51
+ "x86_64-unknown-linux-musl",
52
+ "aarch64-unknown-linux-gnu",
53
+ "aarch64-apple-darwin",
54
+ "x86_64-apple-darwin"
55
+ ]
56
+ },
57
+ "scripts": {
58
+ "build:napi": "napi build --platform --release --js binding.js --dts binding.d.ts",
59
+ "build:napi:debug": "napi build --platform --js binding.js --dts binding.d.ts",
60
+ "build:wasm": "cargo build -p zhuxe-native-wasm --release --target wasm32-unknown-unknown --target-dir target && wasm-bindgen --target web --out-dir wasm/pkg target/wasm32-unknown-unknown/release/zhuxe_native_wasm.wasm && node -e \"require('node:fs').writeFileSync('wasm/pkg/package.json', JSON.stringify({ type: 'module' }) + '\\n')\""
61
+ },
62
+ "devDependencies": {
63
+ "@napi-rs/cli": "^3.0.0"
64
+ }
65
+ }