@kokuin/crypto-napi 0.7.1 → 0.7.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.
package/README.md CHANGED
@@ -32,8 +32,13 @@ Arguments are validated in JavaScript exactly as `nobleCrypto` validates them, s
32
32
  Every backend accepts and rejects exactly the same signatures: the shared corpus and the pinned upstream vectors run
33
33
  against the Rust core, strict noble, `nodeCrypto` and this provider.
34
34
 
35
- Prebuilt binaries are not published yet. In this repository, `pnpm --filter @kokuin/crypto-napi run build:native`
36
- compiles one for the current host into `native/`. Requires Node.js 22 or later.
35
+ Prebuilt binaries install through `optionalDependencies` for linux x64 and arm64 (glibc 2.31 or later, and musl), macOS x64 and arm64,
36
+ and Windows x64 and arm64. Other platforms, and installs that omit optional dependencies, use `nodeCrypto`.
37
+ In this repository, `pnpm --filter @kokuin/crypto-napi run build:native` uses `@napi-rs/cli` to compile one for the current host into `native/`,
38
+ which takes precedence over an installed package. Requires Node.js 22 or later.
39
+
40
+ A bundle that moves this package away from `node_modules` must copy `napiBindingPath()` to `native/` next to its output's parent directory,
41
+ and define `import.meta.url` when its output is CommonJS. `crypto.failure` reports why a binary did not load.
37
42
 
38
43
  ## Named params migration
39
44
 
package/lib/binding.d.ts CHANGED
@@ -33,9 +33,13 @@ export type NapiLoadFailure = {
33
33
  path?: string;
34
34
  cause?: unknown;
35
35
  };
36
- /** The platform suffix of the binary file name, such as `linux-x64-gnu` or `darwin-arm64`. */
36
+ /** The napi-rs platform suffix of the binary, such as `linux-x64-gnu` or `win32-x64-msvc`. */
37
37
  export declare function napiTarget(): string;
38
- /** Where the binary for this platform is expected: `native/kokuin-crypto-napi.<target>.node`. */
38
+ /**
39
+ * The binary for this platform: `native/kokuin-crypto-napi.<target>.node` beside this package when
40
+ * present (a local build, or a copy made for a bundle), otherwise the installed
41
+ * `@kokuin/crypto-napi-<target>` package. Returns the `native/` path when neither exists.
42
+ */
39
43
  export declare function napiBindingPath(): string;
40
44
  /** Load the native binding once per process. Never throws; reports why it could not load. */
41
45
  export declare function loadNapiBinding(): {
package/lib/binding.js CHANGED
@@ -25,13 +25,25 @@ function libc() {
25
25
  const header = process.report?.getReport()?.header;
26
26
  return header?.glibcVersionRuntime ? 'gnu' : 'musl';
27
27
  }
28
- /** The platform suffix of the binary file name, such as `linux-x64-gnu` or `darwin-arm64`. */ export function napiTarget() {
28
+ /** The napi-rs platform suffix of the binary, such as `linux-x64-gnu` or `win32-x64-msvc`. */ export function napiTarget() {
29
29
  const base = `${process.platform}-${process.arch}`;
30
- return process.platform === 'linux' ? `${base}-${libc()}` : base;
30
+ if (process.platform === 'linux') return `${base}-${libc()}`;
31
+ return process.platform === 'win32' ? `${base}-msvc` : base;
31
32
  }
32
- /** Where the binary for this platform is expected: `native/kokuin-crypto-napi.<target>.node`. */ export function napiBindingPath() {
33
+ /**
34
+ * The binary for this platform: `native/kokuin-crypto-napi.<target>.node` beside this package when
35
+ * present (a local build, or a copy made for a bundle), otherwise the installed
36
+ * `@kokuin/crypto-napi-<target>` package. Returns the `native/` path when neither exists.
37
+ */ export function napiBindingPath() {
33
38
  const root = join(dirname(fileURLToPath(import.meta.url)), '..');
34
- return join(root, 'native', `kokuin-crypto-napi.${napiTarget()}.node`);
39
+ const local = join(root, 'native', `kokuin-crypto-napi.${napiTarget()}.node`);
40
+ if (existsSync(local)) return local;
41
+ try {
42
+ return createRequire(import.meta.url).resolve(`@kokuin/crypto-napi-${napiTarget()}`);
43
+ } catch {
44
+ // Unsupported platform, or an install that omitted optional dependencies.
45
+ return local;
46
+ }
35
47
  }
36
48
  let cached;
37
49
  /** Load the native binding once per process. Never throws; reports why it could not load. */ export function loadNapiBinding() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokuin/crypto-napi",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Strict asynchronous crypto provider backed by the Rust core through Node-API, falling back to @kokuin/crypto-node",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,21 +25,45 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@kokuin/crypto-conformance": "^0.0.0",
28
+ "@napi-rs/cli": "^3.10.12",
28
29
  "@noble/curves": "^2.4.0",
29
30
  "@noble/hashes": "^2.4.0",
30
31
  "@types/node": "^26.6.6"
31
32
  },
33
+ "optionalDependencies": {
34
+ "@kokuin/crypto-napi-darwin-arm64": "0.7.3",
35
+ "@kokuin/crypto-napi-darwin-x64": "0.7.3",
36
+ "@kokuin/crypto-napi-linux-arm64-gnu": "0.7.3",
37
+ "@kokuin/crypto-napi-linux-arm64-musl": "0.7.3",
38
+ "@kokuin/crypto-napi-linux-x64-gnu": "0.7.3",
39
+ "@kokuin/crypto-napi-linux-x64-musl": "0.7.3",
40
+ "@kokuin/crypto-napi-win32-arm64-msvc": "0.7.3",
41
+ "@kokuin/crypto-napi-win32-x64-msvc": "0.7.3"
42
+ },
32
43
  "engines": {
33
44
  "node": ">=22"
34
45
  },
35
46
  "publishConfig": {
36
47
  "access": "public"
37
48
  },
49
+ "napi": {
50
+ "binaryName": "kokuin-crypto-napi",
51
+ "targets": [
52
+ "x86_64-unknown-linux-gnu",
53
+ "aarch64-unknown-linux-gnu",
54
+ "x86_64-unknown-linux-musl",
55
+ "aarch64-unknown-linux-musl",
56
+ "x86_64-apple-darwin",
57
+ "aarch64-apple-darwin",
58
+ "x86_64-pc-windows-msvc",
59
+ "aarch64-pc-windows-msvc"
60
+ ]
61
+ },
38
62
  "scripts": {
39
63
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
40
64
  "build:clean": "del-cli lib",
41
65
  "build:js": "del-cli 'lib/**/*.js' && swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
42
- "build:native": "node ../../scripts/build-crypto-napi.mjs",
66
+ "build:native": "napi build --platform --release --no-js --manifest-path ../../crates/kokuin-crypto-napi/Cargo.toml --output-dir native -- --locked --offline",
43
67
  "build:types": "del-cli 'lib/**/*.d.ts' 'lib/**/*.d.ts.map' && tsc --emitDeclarationOnly --skipLibCheck",
44
68
  "test": "pnpm run test:types && pnpm run test:unit",
45
69
  "test:native": "vitest run test/native.test.ts",