@kevaundray/lean-pq 0.0.0-stage → 0.7.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.
- package/README.md +162 -2
- package/facade.d.ts +79 -0
- package/facade.js +27 -0
- package/index.d.ts +58 -0
- package/index.js +716 -0
- package/package.json +64 -3
package/README.md
CHANGED
|
@@ -1,3 +1,163 @@
|
|
|
1
|
-
#
|
|
1
|
+
# lean-pq Node.js bindings
|
|
2
|
+
|
|
3
|
+
Node.js bindings for [leanVM](https://github.com/leanEthereum/leanVM)'s post-quantum signatures,
|
|
4
|
+
leanXMSS and leanSPHINCS, and their recursive aggregation. Implemented with Rust and `napi-rs`
|
|
5
|
+
over the safe `lean-pq` Rust crate; they do not use the repository's C bridge.
|
|
6
|
+
|
|
7
|
+
- **leanXMSS** is stateful: a key signs at `2^32` leaf indices; never sign two different messages
|
|
8
|
+
at the same leaf index.
|
|
9
|
+
- **leanSPHINCS** is stateless: a key keeps one subtree of height `keptHeight` (at most 26),
|
|
10
|
+
trading signing capacity for key generation time.
|
|
11
|
+
|
|
12
|
+
Public keys and messages are 32-byte `Buffer`s; signatures are `Buffer`s of 2404 (leanXMSS) or
|
|
13
|
+
4276 (leanSPHINCS) bytes. Key generation, preparation, signing, setup, aggregation, and aggregate
|
|
14
|
+
decoding return Promises so their native work does not block the JavaScript event loop.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
<!-- x-release-please-start-version -->
|
|
19
|
+
```sh
|
|
20
|
+
npm install @kevaundray/lean-pq@0.7.0
|
|
21
|
+
```
|
|
22
|
+
<!-- x-release-please-end -->
|
|
23
|
+
|
|
24
|
+
npm installs a prebuilt binary through a per-platform optional dependency, so installing needs
|
|
25
|
+
no Rust toolchain. Prebuilt binaries cover Node.js 18.17 or later on:
|
|
26
|
+
|
|
27
|
+
| Platform | Package |
|
|
28
|
+
| ------------------------ | ------------------------------------ |
|
|
29
|
+
| Linux x64, glibc 2.17+ | `@kevaundray/lean-pq-linux-x64-gnu` |
|
|
30
|
+
| Linux arm64, glibc 2.17+ | `@kevaundray/lean-pq-linux-arm64-gnu` |
|
|
31
|
+
| Linux x64, musl | `@kevaundray/lean-pq-linux-x64-musl` |
|
|
32
|
+
| Linux arm64, musl | `@kevaundray/lean-pq-linux-arm64-musl` |
|
|
33
|
+
| macOS x64 | `@kevaundray/lean-pq-darwin-x64` |
|
|
34
|
+
| macOS arm64 | `@kevaundray/lean-pq-darwin-arm64` |
|
|
35
|
+
| Windows x64 | `@kevaundray/lean-pq-win32-x64-msvc` |
|
|
36
|
+
|
|
37
|
+
The x64 binaries require a CPU with AVX2 and PCLMULQDQ. The Windows binary links the C runtime
|
|
38
|
+
statically, so it needs no Visual C++ redistributable. Installing with `--omit=optional` or
|
|
39
|
+
`--no-optional` skips the binary and leaves the package unable to load.
|
|
40
|
+
|
|
41
|
+
## Sign and verify
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const lpq = require('@kevaundray/lean-pq')
|
|
45
|
+
|
|
46
|
+
const message = Buffer.alloc(32, 0x42)
|
|
47
|
+
|
|
48
|
+
const xmssKey = await lpq.XmssSecretKey.fromSeed(Buffer.alloc(32, 1))
|
|
49
|
+
const xmssSignature = await xmssKey.sign(message, 7)
|
|
50
|
+
lpq.xmssVerify(xmssKey.publicKey, message, xmssSignature) // throws if invalid
|
|
51
|
+
|
|
52
|
+
const sphincsKey = await lpq.SphincsSecretKey.fromSeed(Buffer.alloc(32, 2), 4)
|
|
53
|
+
const sphincsSignature = await sphincsKey.sign(message)
|
|
54
|
+
lpq.sphincsVerify(sphincsKey.publicKey, message, sphincsSignature)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Persist your own durable high-water leaf index alongside a leanXMSS key's `toBytes()` and advance
|
|
58
|
+
it before publishing a signature. `toBytes()` is secret material: the leanXMSS seed, or the
|
|
59
|
+
leanSPHINCS seed followed by its kept height. `XmssSecretKey.prepare(leafIndex)` builds the bottom
|
|
60
|
+
tree a leaf index falls in ahead of signing there.
|
|
61
|
+
|
|
62
|
+
## Aggregation
|
|
63
|
+
|
|
64
|
+
`aggregate` verifies every raw signature before proving and runs one proof at a time per process.
|
|
65
|
+
`Aggregate.fromBytes` verifies the proof it decodes, so every `Aggregate` is proven. An aggregate
|
|
66
|
+
attests the claims it lists, not the claims you wanted: compare `xmssClaims` and `sphincsClaims`
|
|
67
|
+
against what you expect. `setup()` moves the one-time guest build ahead of the first proof;
|
|
68
|
+
calling it is optional and idempotent.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
const leaf = await lpq.aggregate({
|
|
72
|
+
xmss: [{ publicKey: xmssKey.publicKey, message, signature: xmssSignature }],
|
|
73
|
+
sphincs: [{ publicKey: sphincsKey.publicKey, message, signature: sphincsSignature }],
|
|
74
|
+
})
|
|
75
|
+
const root = await lpq.aggregate({ children: [leaf] })
|
|
76
|
+
|
|
77
|
+
const received = await lpq.Aggregate.fromBytes(root.toBytes())
|
|
78
|
+
received.xmssClaims // [{ publicKey: xmssKey.publicKey, message }]
|
|
79
|
+
received.sphincsClaims // [{ publicKey: sphincsKey.publicKey, message }]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
One aggregation takes seconds and about 1.6 GB of memory.
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
Install Node.js 18.17 or later and Rust, then run:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
cd bindings/node
|
|
90
|
+
npm ci
|
|
91
|
+
npm run build
|
|
92
|
+
npm test
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`npm run build` compiles in release mode; debug builds of leanVM prove roughly 30x slower.
|
|
96
|
+
|
|
97
|
+
`npm/` holds the per-platform package manifests. `napi create-npm-dirs` generates them from
|
|
98
|
+
`package.json`'s `napi.targets`; rerun it and commit the result after changing the targets.
|
|
99
|
+
|
|
100
|
+
## Releasing
|
|
101
|
+
|
|
102
|
+
Each `vX.Y.Z` release tag publishes `@kevaundray/lean-pq` and every platform package at version
|
|
103
|
+
`X.Y.Z` from `.github/workflows/release.yml`, independently of the PyPI publish:
|
|
104
|
+
|
|
105
|
+
1. `node-build` stamps the version and builds one addon per target.
|
|
106
|
+
2. `node-package` fills the platform packages, sets the root package's `optionalDependencies` with
|
|
107
|
+
`napi pre-publish --skip-optional-publish`, and packs every tarball.
|
|
108
|
+
3. `node-test` installs the root and platform tarball on each platform and signs, verifies and
|
|
109
|
+
aggregates through them (`scripts/install-check.sh`).
|
|
110
|
+
4. `node-publish` publishes the platform packages, then the root package, with npm trusted
|
|
111
|
+
publishing. npm adds provenance automatically. Versions already on npm are skipped, so a
|
|
112
|
+
failed run can be re-dispatched on the same tag: `gh workflow run release.yml --ref vX.Y.Z`.
|
|
113
|
+
|
|
114
|
+
CI checks the packaging without publishing: it packs the root and Linux x64 packages, installs both
|
|
115
|
+
tarballs into a fresh project, and runs `scripts/smoke.js` against them. To run it locally after
|
|
116
|
+
`npm run build`:
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
pack=$(mktemp -d)
|
|
120
|
+
cp lean_pq_node.linux-x64-gnu.node npm/linux-x64-gnu/
|
|
121
|
+
npm pack --ignore-scripts --pack-destination "$pack"
|
|
122
|
+
npm pack --ignore-scripts --pack-destination "$pack" ./npm/linux-x64-gnu
|
|
123
|
+
sh scripts/install-check.sh "$pack/kevaundray-lean-pq-0.0.0-dev.tgz" \
|
|
124
|
+
"$pack/kevaundray-lean-pq-linux-x64-gnu-0.0.0-dev.tgz" --aggregate
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### One-time npm setup
|
|
128
|
+
|
|
129
|
+
npm can attach a trusted publisher only to a package that already exists, so the first release
|
|
130
|
+
publishes the eight packages with a short-lived token, and later releases use trusted publishing.
|
|
131
|
+
A platform package added later, such as `@kevaundray/lean-pq-win32-x64-msvc`, goes through the
|
|
132
|
+
same steps on the first release that includes it; `node-package` warns about every package not
|
|
133
|
+
yet on npm.
|
|
134
|
+
|
|
135
|
+
1. From the npm account that owns the `@kevaundray` scope, create a **granular access token** on
|
|
136
|
+
npmjs.com (**Access Tokens → Generate New Token → Granular Access Token**) with read and write
|
|
137
|
+
access to packages, a short expiry such as 7 days, and no other permissions. If your account
|
|
138
|
+
requires two-factor authentication for publishing, allow the token to bypass it; CI cannot
|
|
139
|
+
answer a 2FA prompt.
|
|
140
|
+
2. Store it as a repository secret:
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
gh secret set NPM_TOKEN -R ethereum/lean-pq-bindings
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
3. Cut a release. `node-publish` tries trusted publishing first, falls back to the token, and
|
|
147
|
+
publishes `@kevaundray/lean-pq` and the seven platform packages with provenance.
|
|
148
|
+
4. Add a trusted publisher to each of the eight packages, on npmjs.com under the package's
|
|
149
|
+
**Settings → Trusted publishing**, or with npm 11.15 or later:
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
npm trust github <package> --repo ethereum/lean-pq-bindings --file release.yml --env npm --allow-publish --yes
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The fields are repository `ethereum/lean-pq-bindings`, workflow `release.yml`, environment
|
|
156
|
+
`npm`, with `npm publish` allowed.
|
|
157
|
+
5. Delete the secret and revoke the token, then set each package's **Settings → Publishing
|
|
158
|
+
access** to "Require two-factor authentication and disallow tokens":
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
gh secret delete NPM_TOKEN -R ethereum/lean-pq-bindings
|
|
162
|
+
```
|
|
2
163
|
|
|
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.
|
package/facade.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** A `(publicKey, message)` pair an aggregate attests. Both are 32 bytes. */
|
|
2
|
+
export interface Claim {
|
|
3
|
+
publicKey: Buffer
|
|
4
|
+
message: Buffer
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** A raw signature to aggregate: a 32-byte public key, a 32-byte message, and its signature. */
|
|
8
|
+
export interface SignedMessage {
|
|
9
|
+
publicKey: Buffer
|
|
10
|
+
message: Buffer
|
|
11
|
+
signature: Buffer
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Builds the aggregation guest ahead of the first proof. Optional and idempotent. */
|
|
15
|
+
export declare function setup(): Promise<void>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A stateful leanXMSS secret key with `2^32` leaf indices. Never sign two different messages at
|
|
19
|
+
* the same leaf index.
|
|
20
|
+
*/
|
|
21
|
+
export declare class XmssSecretKey {
|
|
22
|
+
private constructor()
|
|
23
|
+
static generate(): Promise<XmssSecretKey>
|
|
24
|
+
static fromSeed(seed: Buffer): Promise<XmssSecretKey>
|
|
25
|
+
static fromBytes(data: Buffer): Promise<XmssSecretKey>
|
|
26
|
+
/** SECRET KEY MATERIAL: the 32-byte seed. */
|
|
27
|
+
toBytes(): Buffer
|
|
28
|
+
get publicKey(): Buffer
|
|
29
|
+
/** Builds the bottom tree `leafIndex` falls in ahead of signing there. */
|
|
30
|
+
prepare(leafIndex: number): Promise<void>
|
|
31
|
+
/** Resolves to a 2404-byte signature. */
|
|
32
|
+
sign(message: Buffer, leafIndex: number): Promise<Buffer>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Throws if `signature` is not a valid leanXMSS signature of `message` under `publicKey`. */
|
|
36
|
+
export declare function xmssVerify(publicKey: Buffer, message: Buffer, signature: Buffer): void
|
|
37
|
+
|
|
38
|
+
/** A stateless leanSPHINCS secret key keeping one subtree of height `keptHeight` (at most 26). */
|
|
39
|
+
export declare class SphincsSecretKey {
|
|
40
|
+
private constructor()
|
|
41
|
+
static generate(keptHeight: number): Promise<SphincsSecretKey>
|
|
42
|
+
static fromSeed(seed: Buffer, keptHeight: number): Promise<SphincsSecretKey>
|
|
43
|
+
static fromBytes(data: Buffer): Promise<SphincsSecretKey>
|
|
44
|
+
/** SECRET KEY MATERIAL: the 32-byte seed, then the kept height. */
|
|
45
|
+
toBytes(): Buffer
|
|
46
|
+
get publicKey(): Buffer
|
|
47
|
+
get keptHeight(): number
|
|
48
|
+
/** Resolves to a 4276-byte signature. */
|
|
49
|
+
sign(message: Buffer): Promise<Buffer>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Throws if `signature` is not a valid leanSPHINCS signature of `message` under `publicKey`. */
|
|
53
|
+
export declare function sphincsVerify(publicKey: Buffer, message: Buffer, signature: Buffer): void
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A recursive proof that each listed public key signed its message. Every instance has been
|
|
57
|
+
* proven by `aggregate` or verified by `Aggregate.fromBytes`. It attests the claims it lists, not
|
|
58
|
+
* the claims you wanted: compare `xmssClaims` and `sphincsClaims` against what you expect.
|
|
59
|
+
*/
|
|
60
|
+
export declare class Aggregate {
|
|
61
|
+
private constructor()
|
|
62
|
+
/** Decodes and verifies an aggregate. */
|
|
63
|
+
static fromBytes(data: Buffer): Promise<Aggregate>
|
|
64
|
+
toBytes(): Buffer
|
|
65
|
+
/** Strictly sorted. */
|
|
66
|
+
get xmssClaims(): Array<Claim>
|
|
67
|
+
/** Strictly sorted. */
|
|
68
|
+
get sphincsClaims(): Array<Claim>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Proves every raw signature and every child's claims in one aggregate whose claims are their
|
|
73
|
+
* union. Raw signatures are verified first; at most 16 children; empty input is rejected.
|
|
74
|
+
*/
|
|
75
|
+
export declare function aggregate(input?: {
|
|
76
|
+
children?: Array<Aggregate>
|
|
77
|
+
xmss?: Array<SignedMessage>
|
|
78
|
+
sphincs?: Array<SignedMessage>
|
|
79
|
+
}): Promise<Aggregate>
|
package/facade.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const native = require('./index.js')
|
|
2
|
+
|
|
3
|
+
const { Aggregate, SphincsSecretKey, XmssSecretKey } = native
|
|
4
|
+
|
|
5
|
+
XmssSecretKey.generate = native.generateXmssSecretKey
|
|
6
|
+
XmssSecretKey.fromSeed = native.xmssSecretKeyFromSeed
|
|
7
|
+
XmssSecretKey.fromBytes = native.xmssSecretKeyFromBytes
|
|
8
|
+
|
|
9
|
+
SphincsSecretKey.generate = native.generateSphincsSecretKey
|
|
10
|
+
SphincsSecretKey.fromSeed = native.sphincsSecretKeyFromSeed
|
|
11
|
+
SphincsSecretKey.fromBytes = native.sphincsSecretKeyFromBytes
|
|
12
|
+
|
|
13
|
+
Aggregate.fromBytes = native.aggregateFromBytes
|
|
14
|
+
|
|
15
|
+
function aggregate({ children = [], xmss = [], sphincs = [] } = {}) {
|
|
16
|
+
return native.aggregate(children, xmss, sphincs)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
setup: native.setup,
|
|
21
|
+
XmssSecretKey,
|
|
22
|
+
xmssVerify: native.xmssVerify,
|
|
23
|
+
SphincsSecretKey,
|
|
24
|
+
sphincsVerify: native.sphincsVerify,
|
|
25
|
+
Aggregate,
|
|
26
|
+
aggregate,
|
|
27
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class Aggregate {
|
|
4
|
+
toBytes(): Buffer
|
|
5
|
+
get xmssClaims(): Array<Claim>
|
|
6
|
+
get sphincsClaims(): Array<Claim>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare class SphincsSecretKey {
|
|
10
|
+
/** SECRET KEY MATERIAL: the seed, then the kept height. */
|
|
11
|
+
toBytes(): Buffer
|
|
12
|
+
get publicKey(): Buffer
|
|
13
|
+
get keptHeight(): number
|
|
14
|
+
sign(message: Buffer): Promise<Buffer>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare class XmssSecretKey {
|
|
18
|
+
/** SECRET KEY MATERIAL: the seed. */
|
|
19
|
+
toBytes(): Buffer
|
|
20
|
+
get publicKey(): Buffer
|
|
21
|
+
prepare(leafIndex: number): Promise<void>
|
|
22
|
+
sign(message: Buffer, leafIndex: number): Promise<Buffer>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare function aggregate(children: Array<Aggregate>, xmss: Array<SignedMessage>, sphincs: Array<SignedMessage>): Promise<Aggregate>
|
|
26
|
+
|
|
27
|
+
export declare function aggregateFromBytes(data: Buffer): Promise<Aggregate>
|
|
28
|
+
|
|
29
|
+
/** A `(public key, message)` pair an aggregate attests. */
|
|
30
|
+
export interface Claim {
|
|
31
|
+
publicKey: Buffer
|
|
32
|
+
message: Buffer
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare function generateSphincsSecretKey(keptHeight: number): Promise<SphincsSecretKey>
|
|
36
|
+
|
|
37
|
+
export declare function generateXmssSecretKey(): Promise<XmssSecretKey>
|
|
38
|
+
|
|
39
|
+
export declare function setup(): Promise<void>
|
|
40
|
+
|
|
41
|
+
/** A raw signature to aggregate. */
|
|
42
|
+
export interface SignedMessage {
|
|
43
|
+
publicKey: Buffer
|
|
44
|
+
message: Buffer
|
|
45
|
+
signature: Buffer
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export declare function sphincsSecretKeyFromBytes(data: Buffer): Promise<SphincsSecretKey>
|
|
49
|
+
|
|
50
|
+
export declare function sphincsSecretKeyFromSeed(seed: Buffer, keptHeight: number): Promise<SphincsSecretKey>
|
|
51
|
+
|
|
52
|
+
export declare function sphincsVerify(publicKey: Buffer, message: Buffer, signature: Buffer): void
|
|
53
|
+
|
|
54
|
+
export declare function xmssSecretKeyFromBytes(data: Buffer): Promise<XmssSecretKey>
|
|
55
|
+
|
|
56
|
+
export declare function xmssSecretKeyFromSeed(seed: Buffer): Promise<XmssSecretKey>
|
|
57
|
+
|
|
58
|
+
export declare function xmssVerify(publicKey: Buffer, message: Buffer, signature: Buffer): void
|
package/index.js
ADDED
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { readFileSync } = require('fs')
|
|
7
|
+
let nativeBinding = null
|
|
8
|
+
const loadErrors = []
|
|
9
|
+
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
let musl = false
|
|
12
|
+
if (process.platform === 'linux') {
|
|
13
|
+
musl = isMuslFromFilesystem()
|
|
14
|
+
if (musl === null) {
|
|
15
|
+
musl = isMuslFromReport()
|
|
16
|
+
}
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromChildProcess()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return musl
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
25
|
+
|
|
26
|
+
const isMuslFromFilesystem = () => {
|
|
27
|
+
try {
|
|
28
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
29
|
+
} catch {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isMuslFromReport = () => {
|
|
35
|
+
let report = null
|
|
36
|
+
if (process.report && typeof process.report.getReport === 'function') {
|
|
37
|
+
process.report.excludeNetwork = true
|
|
38
|
+
report = process.report.getReport()
|
|
39
|
+
}
|
|
40
|
+
if (!report) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
47
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isMuslFromChildProcess = () => {
|
|
55
|
+
try {
|
|
56
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function requireNative() {
|
|
64
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
65
|
+
try {
|
|
66
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
loadErrors.push(err)
|
|
69
|
+
}
|
|
70
|
+
} else if (process.platform === 'android') {
|
|
71
|
+
if (process.arch === 'arm64') {
|
|
72
|
+
try {
|
|
73
|
+
return require('./lean_pq_node.android-arm64.node')
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadErrors.push(e)
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const binding = require('@kevaundray/lean-pq-android-arm64')
|
|
79
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-android-arm64/package.json').version
|
|
80
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
|
+
}
|
|
83
|
+
return binding
|
|
84
|
+
} catch (e) {
|
|
85
|
+
loadErrors.push(e)
|
|
86
|
+
}
|
|
87
|
+
} else if (process.arch === 'arm') {
|
|
88
|
+
try {
|
|
89
|
+
return require('./lean_pq_node.android-arm-eabi.node')
|
|
90
|
+
} catch (e) {
|
|
91
|
+
loadErrors.push(e)
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const binding = require('@kevaundray/lean-pq-android-arm-eabi')
|
|
95
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-android-arm-eabi/package.json').version
|
|
96
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
|
+
}
|
|
99
|
+
return binding
|
|
100
|
+
} catch (e) {
|
|
101
|
+
loadErrors.push(e)
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
105
|
+
}
|
|
106
|
+
} else if (process.platform === 'win32') {
|
|
107
|
+
if (process.arch === 'x64') {
|
|
108
|
+
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
109
|
+
try {
|
|
110
|
+
return require('./lean_pq_node.win32-x64-gnu.node')
|
|
111
|
+
} catch (e) {
|
|
112
|
+
loadErrors.push(e)
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const binding = require('@kevaundray/lean-pq-win32-x64-gnu')
|
|
116
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-win32-x64-gnu/package.json').version
|
|
117
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
|
+
}
|
|
120
|
+
return binding
|
|
121
|
+
} catch (e) {
|
|
122
|
+
loadErrors.push(e)
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
126
|
+
return require('./lean_pq_node.win32-x64-msvc.node')
|
|
127
|
+
} catch (e) {
|
|
128
|
+
loadErrors.push(e)
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const binding = require('@kevaundray/lean-pq-win32-x64-msvc')
|
|
132
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-win32-x64-msvc/package.json').version
|
|
133
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
|
+
}
|
|
136
|
+
return binding
|
|
137
|
+
} catch (e) {
|
|
138
|
+
loadErrors.push(e)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else if (process.arch === 'ia32') {
|
|
142
|
+
try {
|
|
143
|
+
return require('./lean_pq_node.win32-ia32-msvc.node')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const binding = require('@kevaundray/lean-pq-win32-ia32-msvc')
|
|
149
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-win32-ia32-msvc/package.json').version
|
|
150
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
|
+
}
|
|
153
|
+
return binding
|
|
154
|
+
} catch (e) {
|
|
155
|
+
loadErrors.push(e)
|
|
156
|
+
}
|
|
157
|
+
} else if (process.arch === 'arm64') {
|
|
158
|
+
try {
|
|
159
|
+
return require('./lean_pq_node.win32-arm64-msvc.node')
|
|
160
|
+
} catch (e) {
|
|
161
|
+
loadErrors.push(e)
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const binding = require('@kevaundray/lean-pq-win32-arm64-msvc')
|
|
165
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-win32-arm64-msvc/package.json').version
|
|
166
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
|
+
}
|
|
169
|
+
return binding
|
|
170
|
+
} catch (e) {
|
|
171
|
+
loadErrors.push(e)
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
175
|
+
}
|
|
176
|
+
} else if (process.platform === 'darwin') {
|
|
177
|
+
try {
|
|
178
|
+
return require('./lean_pq_node.darwin-universal.node')
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadErrors.push(e)
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const binding = require('@kevaundray/lean-pq-darwin-universal')
|
|
184
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-darwin-universal/package.json').version
|
|
185
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
|
+
}
|
|
188
|
+
return binding
|
|
189
|
+
} catch (e) {
|
|
190
|
+
loadErrors.push(e)
|
|
191
|
+
}
|
|
192
|
+
if (process.arch === 'x64') {
|
|
193
|
+
try {
|
|
194
|
+
return require('./lean_pq_node.darwin-x64.node')
|
|
195
|
+
} catch (e) {
|
|
196
|
+
loadErrors.push(e)
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const binding = require('@kevaundray/lean-pq-darwin-x64')
|
|
200
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-darwin-x64/package.json').version
|
|
201
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
|
+
}
|
|
204
|
+
return binding
|
|
205
|
+
} catch (e) {
|
|
206
|
+
loadErrors.push(e)
|
|
207
|
+
}
|
|
208
|
+
} else if (process.arch === 'arm64') {
|
|
209
|
+
try {
|
|
210
|
+
return require('./lean_pq_node.darwin-arm64.node')
|
|
211
|
+
} catch (e) {
|
|
212
|
+
loadErrors.push(e)
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const binding = require('@kevaundray/lean-pq-darwin-arm64')
|
|
216
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-darwin-arm64/package.json').version
|
|
217
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
|
+
}
|
|
220
|
+
return binding
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadErrors.push(e)
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
226
|
+
}
|
|
227
|
+
} else if (process.platform === 'freebsd') {
|
|
228
|
+
if (process.arch === 'x64') {
|
|
229
|
+
try {
|
|
230
|
+
return require('./lean_pq_node.freebsd-x64.node')
|
|
231
|
+
} catch (e) {
|
|
232
|
+
loadErrors.push(e)
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const binding = require('@kevaundray/lean-pq-freebsd-x64')
|
|
236
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-freebsd-x64/package.json').version
|
|
237
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
|
+
}
|
|
240
|
+
return binding
|
|
241
|
+
} catch (e) {
|
|
242
|
+
loadErrors.push(e)
|
|
243
|
+
}
|
|
244
|
+
} else if (process.arch === 'arm64') {
|
|
245
|
+
try {
|
|
246
|
+
return require('./lean_pq_node.freebsd-arm64.node')
|
|
247
|
+
} catch (e) {
|
|
248
|
+
loadErrors.push(e)
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const binding = require('@kevaundray/lean-pq-freebsd-arm64')
|
|
252
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-freebsd-arm64/package.json').version
|
|
253
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
|
+
}
|
|
256
|
+
return binding
|
|
257
|
+
} catch (e) {
|
|
258
|
+
loadErrors.push(e)
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
262
|
+
}
|
|
263
|
+
} else if (process.platform === 'linux') {
|
|
264
|
+
if (process.arch === 'x64') {
|
|
265
|
+
if (isMusl()) {
|
|
266
|
+
try {
|
|
267
|
+
return require('./lean_pq_node.linux-x64-musl.node')
|
|
268
|
+
} catch (e) {
|
|
269
|
+
loadErrors.push(e)
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const binding = require('@kevaundray/lean-pq-linux-x64-musl')
|
|
273
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-x64-musl/package.json').version
|
|
274
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
|
+
}
|
|
277
|
+
return binding
|
|
278
|
+
} catch (e) {
|
|
279
|
+
loadErrors.push(e)
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
try {
|
|
283
|
+
return require('./lean_pq_node.linux-x64-gnu.node')
|
|
284
|
+
} catch (e) {
|
|
285
|
+
loadErrors.push(e)
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const binding = require('@kevaundray/lean-pq-linux-x64-gnu')
|
|
289
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-x64-gnu/package.json').version
|
|
290
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
|
+
}
|
|
293
|
+
return binding
|
|
294
|
+
} catch (e) {
|
|
295
|
+
loadErrors.push(e)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} else if (process.arch === 'arm64') {
|
|
299
|
+
if (isMusl()) {
|
|
300
|
+
try {
|
|
301
|
+
return require('./lean_pq_node.linux-arm64-musl.node')
|
|
302
|
+
} catch (e) {
|
|
303
|
+
loadErrors.push(e)
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const binding = require('@kevaundray/lean-pq-linux-arm64-musl')
|
|
307
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-arm64-musl/package.json').version
|
|
308
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
|
+
}
|
|
311
|
+
return binding
|
|
312
|
+
} catch (e) {
|
|
313
|
+
loadErrors.push(e)
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
try {
|
|
317
|
+
return require('./lean_pq_node.linux-arm64-gnu.node')
|
|
318
|
+
} catch (e) {
|
|
319
|
+
loadErrors.push(e)
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
const binding = require('@kevaundray/lean-pq-linux-arm64-gnu')
|
|
323
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-arm64-gnu/package.json').version
|
|
324
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
|
+
}
|
|
327
|
+
return binding
|
|
328
|
+
} catch (e) {
|
|
329
|
+
loadErrors.push(e)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} else if (process.arch === 'arm') {
|
|
333
|
+
if (isMusl()) {
|
|
334
|
+
try {
|
|
335
|
+
return require('./lean_pq_node.linux-arm-musleabihf.node')
|
|
336
|
+
} catch (e) {
|
|
337
|
+
loadErrors.push(e)
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
const binding = require('@kevaundray/lean-pq-linux-arm-musleabihf')
|
|
341
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-arm-musleabihf/package.json').version
|
|
342
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
|
+
}
|
|
345
|
+
return binding
|
|
346
|
+
} catch (e) {
|
|
347
|
+
loadErrors.push(e)
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
try {
|
|
351
|
+
return require('./lean_pq_node.linux-arm-gnueabihf.node')
|
|
352
|
+
} catch (e) {
|
|
353
|
+
loadErrors.push(e)
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const binding = require('@kevaundray/lean-pq-linux-arm-gnueabihf')
|
|
357
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-arm-gnueabihf/package.json').version
|
|
358
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
|
+
}
|
|
361
|
+
return binding
|
|
362
|
+
} catch (e) {
|
|
363
|
+
loadErrors.push(e)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} else if (process.arch === 'loong64') {
|
|
367
|
+
if (isMusl()) {
|
|
368
|
+
try {
|
|
369
|
+
return require('./lean_pq_node.linux-loong64-musl.node')
|
|
370
|
+
} catch (e) {
|
|
371
|
+
loadErrors.push(e)
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const binding = require('@kevaundray/lean-pq-linux-loong64-musl')
|
|
375
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-loong64-musl/package.json').version
|
|
376
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
|
+
}
|
|
379
|
+
return binding
|
|
380
|
+
} catch (e) {
|
|
381
|
+
loadErrors.push(e)
|
|
382
|
+
}
|
|
383
|
+
} else {
|
|
384
|
+
try {
|
|
385
|
+
return require('./lean_pq_node.linux-loong64-gnu.node')
|
|
386
|
+
} catch (e) {
|
|
387
|
+
loadErrors.push(e)
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const binding = require('@kevaundray/lean-pq-linux-loong64-gnu')
|
|
391
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-loong64-gnu/package.json').version
|
|
392
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
|
+
}
|
|
395
|
+
return binding
|
|
396
|
+
} catch (e) {
|
|
397
|
+
loadErrors.push(e)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} else if (process.arch === 'riscv64') {
|
|
401
|
+
if (isMusl()) {
|
|
402
|
+
try {
|
|
403
|
+
return require('./lean_pq_node.linux-riscv64-musl.node')
|
|
404
|
+
} catch (e) {
|
|
405
|
+
loadErrors.push(e)
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
const binding = require('@kevaundray/lean-pq-linux-riscv64-musl')
|
|
409
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-riscv64-musl/package.json').version
|
|
410
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
|
+
}
|
|
413
|
+
return binding
|
|
414
|
+
} catch (e) {
|
|
415
|
+
loadErrors.push(e)
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
try {
|
|
419
|
+
return require('./lean_pq_node.linux-riscv64-gnu.node')
|
|
420
|
+
} catch (e) {
|
|
421
|
+
loadErrors.push(e)
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const binding = require('@kevaundray/lean-pq-linux-riscv64-gnu')
|
|
425
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-riscv64-gnu/package.json').version
|
|
426
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
|
+
}
|
|
429
|
+
return binding
|
|
430
|
+
} catch (e) {
|
|
431
|
+
loadErrors.push(e)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
} else if (process.arch === 'ppc64') {
|
|
435
|
+
try {
|
|
436
|
+
return require('./lean_pq_node.linux-ppc64-gnu.node')
|
|
437
|
+
} catch (e) {
|
|
438
|
+
loadErrors.push(e)
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const binding = require('@kevaundray/lean-pq-linux-ppc64-gnu')
|
|
442
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-ppc64-gnu/package.json').version
|
|
443
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
|
+
}
|
|
446
|
+
return binding
|
|
447
|
+
} catch (e) {
|
|
448
|
+
loadErrors.push(e)
|
|
449
|
+
}
|
|
450
|
+
} else if (process.arch === 's390x') {
|
|
451
|
+
try {
|
|
452
|
+
return require('./lean_pq_node.linux-s390x-gnu.node')
|
|
453
|
+
} catch (e) {
|
|
454
|
+
loadErrors.push(e)
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const binding = require('@kevaundray/lean-pq-linux-s390x-gnu')
|
|
458
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-linux-s390x-gnu/package.json').version
|
|
459
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
|
+
}
|
|
462
|
+
return binding
|
|
463
|
+
} catch (e) {
|
|
464
|
+
loadErrors.push(e)
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
468
|
+
}
|
|
469
|
+
} else if (process.platform === 'openharmony') {
|
|
470
|
+
if (process.arch === 'arm64') {
|
|
471
|
+
try {
|
|
472
|
+
return require('./lean_pq_node.openharmony-arm64.node')
|
|
473
|
+
} catch (e) {
|
|
474
|
+
loadErrors.push(e)
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const binding = require('@kevaundray/lean-pq-openharmony-arm64')
|
|
478
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-openharmony-arm64/package.json').version
|
|
479
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
|
+
}
|
|
482
|
+
return binding
|
|
483
|
+
} catch (e) {
|
|
484
|
+
loadErrors.push(e)
|
|
485
|
+
}
|
|
486
|
+
} else if (process.arch === 'x64') {
|
|
487
|
+
try {
|
|
488
|
+
return require('./lean_pq_node.openharmony-x64.node')
|
|
489
|
+
} catch (e) {
|
|
490
|
+
loadErrors.push(e)
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const binding = require('@kevaundray/lean-pq-openharmony-x64')
|
|
494
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-openharmony-x64/package.json').version
|
|
495
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
|
+
}
|
|
498
|
+
return binding
|
|
499
|
+
} catch (e) {
|
|
500
|
+
loadErrors.push(e)
|
|
501
|
+
}
|
|
502
|
+
} else if (process.arch === 'arm') {
|
|
503
|
+
try {
|
|
504
|
+
return require('./lean_pq_node.openharmony-arm.node')
|
|
505
|
+
} catch (e) {
|
|
506
|
+
loadErrors.push(e)
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
const binding = require('@kevaundray/lean-pq-openharmony-arm')
|
|
510
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-openharmony-arm/package.json').version
|
|
511
|
+
if (bindingPackageVersion !== '0.7.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
|
+
}
|
|
514
|
+
return binding
|
|
515
|
+
} catch (e) {
|
|
516
|
+
loadErrors.push(e)
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function createLoadErrorChain(errors) {
|
|
527
|
+
return errors.reduce((previous, current) => {
|
|
528
|
+
let message
|
|
529
|
+
try {
|
|
530
|
+
message =
|
|
531
|
+
current && typeof current.message === 'string'
|
|
532
|
+
? current.message
|
|
533
|
+
: String(current)
|
|
534
|
+
} catch {
|
|
535
|
+
message = 'Unknown error'
|
|
536
|
+
}
|
|
537
|
+
const error = new Error(message)
|
|
538
|
+
error.cause = previous
|
|
539
|
+
return error
|
|
540
|
+
}, null)
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
544
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
545
|
+
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
546
|
+
// 'error' → require WASI without initializing a native fallback
|
|
547
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
548
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
549
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
550
|
+
//
|
|
551
|
+
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
552
|
+
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
553
|
+
const __napiWasiFlavors = ["wasm32-wasi"]
|
|
554
|
+
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
555
|
+
const __napiWasiFlavorRequested =
|
|
556
|
+
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
557
|
+
if (
|
|
558
|
+
__napiWasiFlavorRequested &&
|
|
559
|
+
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
560
|
+
) {
|
|
561
|
+
throw new Error(
|
|
562
|
+
'Unsupported WASI flavor "' +
|
|
563
|
+
__napiWasiFlavor +
|
|
564
|
+
'". Available flavors: ' +
|
|
565
|
+
__napiWasiFlavors.join(', '),
|
|
566
|
+
)
|
|
567
|
+
}
|
|
568
|
+
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
569
|
+
const forceWasi =
|
|
570
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
571
|
+
forceWasiError ||
|
|
572
|
+
__napiWasiFlavorRequested
|
|
573
|
+
|
|
574
|
+
if (!forceWasi) {
|
|
575
|
+
nativeBinding = requireNative()
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (!nativeBinding || forceWasi) {
|
|
579
|
+
let wasiBinding = null
|
|
580
|
+
let wasiBindingLoaded = false
|
|
581
|
+
const wasiBindingErrors = []
|
|
582
|
+
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
583
|
+
try {
|
|
584
|
+
require.resolve(specifier)
|
|
585
|
+
} catch (resolveError) {
|
|
586
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
587
|
+
throw resolveError
|
|
588
|
+
}
|
|
589
|
+
if (isPackage) {
|
|
590
|
+
try {
|
|
591
|
+
require.resolve(specifier + '/package.json')
|
|
592
|
+
} catch (packageError) {
|
|
593
|
+
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
594
|
+
return resolveError
|
|
595
|
+
}
|
|
596
|
+
// An exports restriction proves the package exists even when its
|
|
597
|
+
// package.json is not public. Preserve the root resolution failure.
|
|
598
|
+
throw resolveError
|
|
599
|
+
}
|
|
600
|
+
// The package exists but its main/export target is broken.
|
|
601
|
+
throw resolveError
|
|
602
|
+
}
|
|
603
|
+
return resolveError
|
|
604
|
+
}
|
|
605
|
+
if (localArtifacts) {
|
|
606
|
+
let artifactError = null
|
|
607
|
+
for (let i = 0; i < localArtifacts.length; i++) {
|
|
608
|
+
try {
|
|
609
|
+
require.resolve(localArtifacts[i])
|
|
610
|
+
return null
|
|
611
|
+
} catch (resolveError) {
|
|
612
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
613
|
+
throw resolveError
|
|
614
|
+
}
|
|
615
|
+
artifactError = resolveError
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return artifactError
|
|
619
|
+
}
|
|
620
|
+
return null
|
|
621
|
+
}
|
|
622
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
|
|
623
|
+
let candidateError = null
|
|
624
|
+
let candidateFailed = false
|
|
625
|
+
try {
|
|
626
|
+
candidateError = __napiWasiResolveCandidate('./lean_pq_node.wasi.cjs', false, ["./lean_pq_node.wasm32-wasi.debug.wasm","./lean_pq_node.wasm32-wasi.wasm"])
|
|
627
|
+
candidateFailed = candidateError !== null
|
|
628
|
+
if (!candidateFailed) {
|
|
629
|
+
wasiBinding = require('./lean_pq_node.wasi.cjs')
|
|
630
|
+
nativeBinding = wasiBinding
|
|
631
|
+
wasiBindingLoaded = true
|
|
632
|
+
}
|
|
633
|
+
} catch (err) {
|
|
634
|
+
candidateError = err
|
|
635
|
+
candidateFailed = true
|
|
636
|
+
}
|
|
637
|
+
if (candidateFailed) {
|
|
638
|
+
wasiBindingErrors.push(candidateError)
|
|
639
|
+
loadErrors.push(candidateError)
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
|
|
643
|
+
let candidateError = null
|
|
644
|
+
let candidateFailed = false
|
|
645
|
+
try {
|
|
646
|
+
candidateError = __napiWasiResolveCandidate('@kevaundray/lean-pq-wasm32-wasi', true, undefined)
|
|
647
|
+
candidateFailed = candidateError !== null
|
|
648
|
+
if (!candidateFailed) {
|
|
649
|
+
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
650
|
+
const bindingPackageVersion = require('@kevaundray/lean-pq-wasm32-wasi/package.json').version
|
|
651
|
+
if (bindingPackageVersion !== '0.7.0') {
|
|
652
|
+
throw new Error(`WASI binding package version mismatch, expected 0.7.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
wasiBinding = require('@kevaundray/lean-pq-wasm32-wasi')
|
|
656
|
+
nativeBinding = wasiBinding
|
|
657
|
+
wasiBindingLoaded = true
|
|
658
|
+
}
|
|
659
|
+
} catch (err) {
|
|
660
|
+
candidateError = err
|
|
661
|
+
candidateFailed = true
|
|
662
|
+
}
|
|
663
|
+
if (candidateFailed) {
|
|
664
|
+
wasiBindingErrors.push(candidateError)
|
|
665
|
+
loadErrors.push(candidateError)
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (
|
|
669
|
+
!wasiBindingLoaded &&
|
|
670
|
+
forceWasi &&
|
|
671
|
+
!forceWasiError &&
|
|
672
|
+
!__napiWasiFlavorRequested
|
|
673
|
+
) {
|
|
674
|
+
nativeBinding = requireNative()
|
|
675
|
+
}
|
|
676
|
+
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
677
|
+
const error = new Error(
|
|
678
|
+
__napiWasiFlavorRequested
|
|
679
|
+
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
680
|
+
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
681
|
+
)
|
|
682
|
+
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
683
|
+
throw error
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (!nativeBinding) {
|
|
688
|
+
if (loadErrors.length > 0) {
|
|
689
|
+
const error = new Error(
|
|
690
|
+
`Cannot find native binding. ` +
|
|
691
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
692
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
693
|
+
)
|
|
694
|
+
// assign instead of the `new Error(message, { cause })` options form,
|
|
695
|
+
// which Node < 16.9 silently ignores
|
|
696
|
+
error.cause = createLoadErrorChain(loadErrors)
|
|
697
|
+
throw error
|
|
698
|
+
}
|
|
699
|
+
throw new Error(`Failed to load native binding`)
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
module.exports = nativeBinding
|
|
703
|
+
module.exports.Aggregate = nativeBinding.Aggregate
|
|
704
|
+
module.exports.SphincsSecretKey = nativeBinding.SphincsSecretKey
|
|
705
|
+
module.exports.XmssSecretKey = nativeBinding.XmssSecretKey
|
|
706
|
+
module.exports.aggregate = nativeBinding.aggregate
|
|
707
|
+
module.exports.aggregateFromBytes = nativeBinding.aggregateFromBytes
|
|
708
|
+
module.exports.generateSphincsSecretKey = nativeBinding.generateSphincsSecretKey
|
|
709
|
+
module.exports.generateXmssSecretKey = nativeBinding.generateXmssSecretKey
|
|
710
|
+
module.exports.setup = nativeBinding.setup
|
|
711
|
+
module.exports.sphincsSecretKeyFromBytes = nativeBinding.sphincsSecretKeyFromBytes
|
|
712
|
+
module.exports.sphincsSecretKeyFromSeed = nativeBinding.sphincsSecretKeyFromSeed
|
|
713
|
+
module.exports.sphincsVerify = nativeBinding.sphincsVerify
|
|
714
|
+
module.exports.xmssSecretKeyFromBytes = nativeBinding.xmssSecretKeyFromBytes
|
|
715
|
+
module.exports.xmssSecretKeyFromSeed = nativeBinding.xmssSecretKeyFromSeed
|
|
716
|
+
module.exports.xmssVerify = nativeBinding.xmssVerify
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevaundray/lean-pq",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Node.js bindings for leanXMSS and leanSPHINCS post-quantum signatures and their leanVM aggregation",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ethereum/lean-pq-bindings.git",
|
|
9
|
+
"directory": "bindings/node"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/ethereum/lean-pq-bindings/tree/main/bindings/node#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ethereum/lean-pq-bindings/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"xmss",
|
|
17
|
+
"sphincs",
|
|
18
|
+
"leanxmss",
|
|
19
|
+
"leansphincs",
|
|
20
|
+
"post-quantum",
|
|
21
|
+
"ethereum",
|
|
22
|
+
"napi-rs"
|
|
23
|
+
],
|
|
24
|
+
"main": "facade.js",
|
|
25
|
+
"types": "facade.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"facade.js",
|
|
28
|
+
"facade.d.ts",
|
|
29
|
+
"index.js",
|
|
30
|
+
"index.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.17.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"provenance": true
|
|
38
|
+
},
|
|
39
|
+
"napi": {
|
|
40
|
+
"binaryName": "lean_pq_node",
|
|
41
|
+
"targets": [
|
|
42
|
+
"x86_64-unknown-linux-gnu",
|
|
43
|
+
"aarch64-unknown-linux-gnu",
|
|
44
|
+
"x86_64-unknown-linux-musl",
|
|
45
|
+
"aarch64-unknown-linux-musl",
|
|
46
|
+
"x86_64-apple-darwin",
|
|
47
|
+
"aarch64-apple-darwin",
|
|
48
|
+
"x86_64-pc-windows-msvc"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "napi build --platform --release",
|
|
53
|
+
"test": "node --test"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@napi-rs/cli": "^3.8.6"
|
|
57
|
+
},
|
|
58
|
+
"optionalDependencies": {
|
|
59
|
+
"@kevaundray/lean-pq-linux-x64-gnu": "0.7.0",
|
|
60
|
+
"@kevaundray/lean-pq-linux-arm64-gnu": "0.7.0",
|
|
61
|
+
"@kevaundray/lean-pq-linux-x64-musl": "0.7.0",
|
|
62
|
+
"@kevaundray/lean-pq-linux-arm64-musl": "0.7.0",
|
|
63
|
+
"@kevaundray/lean-pq-darwin-x64": "0.7.0",
|
|
64
|
+
"@kevaundray/lean-pq-darwin-arm64": "0.7.0",
|
|
65
|
+
"@kevaundray/lean-pq-win32-x64-msvc": "0.7.0"
|
|
66
|
+
}
|
|
6
67
|
}
|