@zcash-app/core 0.0.0-stage → 0.1.0-alpha.1

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 (5) hide show
  1. package/LICENSE +201 -0
  2. package/index.d.ts +272 -0
  3. package/index.js +794 -0
  4. package/package.json +55 -3
  5. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 create-zcash-app contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/index.d.ts ADDED
@@ -0,0 +1,272 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
12
+ /** A handle to an open Zcash wallet database with thread-safe access and async background scanning. */
13
+ export declare class WalletHandle {
14
+ /**
15
+ * Opens or initializes a wallet database file with strict 0700/0600 permissions,
16
+ * WAL mode, busy_timeout=5000ms, and starts background proving key warm-up.
17
+ */
18
+ static open(dbPath: string, networkStr: string, ufvkStr: string, accountId?: string | undefined | null, birthday?: number | undefined | null): WalletHandle
19
+ /** Returns the Unified Full Viewing Key string for this wallet. */
20
+ get ufvk(): string
21
+ /** Returns the network string for this wallet. */
22
+ get network(): string
23
+ /** Asynchronously scans a batch of raw CompactBlock protobuf buffers off the main Node.js event loop. */
24
+ scanBlocks(rawBlocks: Array<Buffer>): Promise<unknown>
25
+ /** Returns a comprehensive balance and sync status summary. */
26
+ getWalletSummary(): WalletSummary
27
+ /** Queries spendable notes confirmed at the given anchor height with min_confs. */
28
+ querySpendableNotes(anchorHeight: number, minConfs: number): Array<JsSpendableNote>
29
+ /** Resolves a detected reorganization by rolling back wallet state to a common ancestor. */
30
+ resolveReorg(fromHeight: number, ancestorHashes: Array<Buffer>): number
31
+ /** Reserves notes for an in-flight send transaction under BEGIN IMMEDIATE. */
32
+ reserveNotes(notes: Array<number>, txid: Buffer, expiryHeight: number): void
33
+ /** Marks an in-flight reservation as broadcast to the network. */
34
+ markBroadcast(txid: Buffer): number
35
+ /** Marks an in-flight reservation as broadcast to the network, re-keying from a reservation_id. */
36
+ markBroadcastWithReservation(txid: Buffer, reservationId: Buffer): number
37
+ /** Refreshes the heartbeat timestamp of an active in-flight reservation to prevent stale timeout. */
38
+ refreshHeartbeat(reservationId: Buffer): number
39
+ /** Asynchronously builds, proves, signs, and serializes a V6 Ironwood transaction in a background worker thread. */
40
+ buildAndProveTransaction(req: JsBuildTransactionRequest): Promise<unknown>
41
+ /** Returns the 32-byte Ironwood commitment tree root at the specified block height. */
42
+ getTreeRootAtHeight(height: number): Buffer | null
43
+ /** Cancels an in-flight reservation if proving fails or transaction is aborted. */
44
+ cancelReservation(txid: Buffer): number
45
+ /** Resets wallet state (wipes scanned blocks, notes, tree, and pending spends, clearing chain continuity metadata). */
46
+ reset(): void
47
+ /** Returns the 32-byte Ironwood commitment tree root at the specified checkpoint depth (0 = tip). */
48
+ getTreeRoot(depth?: number | undefined | null): Buffer | null
49
+ /** Looks up a received note by its 32-byte commitment hex (cmx). */
50
+ getNoteByCmx(cmxHex: string): JsSpendableNote | null
51
+ /** Upserts a decrypted transaction record into wallet_transactions idempotently. */
52
+ upsertWalletTransaction(txid: string, actionIndex: number, height: number, direction: string, value: number, fee: number | undefined | null, memo: string | undefined | null, counterparty: string | undefined | null, pool: string): void
53
+ /** Queries persisted wallet_transactions ordered by block height descending. */
54
+ getWalletTransactions(limit?: number | undefined | null, offset?: number | undefined | null): Array<JsPersistedTransaction>
55
+ /** Returns all distinct transaction IDs (and their heights) that touched the wallet in the given block range. */
56
+ getTouchedTransactions(minHeight: number, maxHeight: number): Array<JsTouchedTx>
57
+ /** Records a transaction fetch attempt in the persistent retry queue. */
58
+ recordTxFetchAttempt(txid: string, height: number, status: string, error?: string | undefined | null): void
59
+ /** Returns counts of pending and failed transaction fetches. */
60
+ getTxFetchCounts(): JsTxFetchStatus
61
+ /** Deletes wallet_transactions rows at height >= from_height (e.g. on chain reorganization). */
62
+ deleteWalletTransactionsFromHeight(fromHeight: number): number
63
+ /** Checks whether the wallet's commitment tree is empty (no checkpoints and no scanned blocks). */
64
+ isTreeEmpty(): boolean
65
+ /**
66
+ * Initializes the commitment tree frontier from a machine-captured or lightwalletd GetTreeState
67
+ * frontier hex at height B - 1, and verifies that the parsed tree size equals expected_tree_size
68
+ * (the CompactBlock ironwoodCommitmentTreeSize at B - 1).
69
+ *
70
+ * Inserts the starting checkpoint into ShardTree and records the checkpoint block in scanned_blocks.
71
+ * This operation is idempotent: if the tree is already initialized at this height with the matching
72
+ * tree size and root, it returns Ok with `already_initialized: true`.
73
+ */
74
+ initTreeFrontier(height: number, frontierHex: string, expectedTreeSize: number, blockHash?: Buffer | undefined | null): JsTreeFrontierInitResult
75
+ }
76
+
77
+ /**
78
+ * Deserializes a hex-encoded Ironwood commitment tree frontier from GetTreeState/z_gettreestate
79
+ * and returns its 32-byte Merkle root hex.
80
+ */
81
+ export declare function decodeIronwoodFrontierRoot(frontierHex: string): string
82
+
83
+ export declare function decodeTransaction(rawTxBytes: Buffer, networkStr?: string | undefined | null, height?: number | undefined | null): JsDecodedTransaction
84
+
85
+ export interface DecryptedNote {
86
+ pool: string
87
+ valueZatoshis: number
88
+ recipient: string
89
+ actionIndex: number
90
+ nullifier: string
91
+ rho: string
92
+ rseed: string
93
+ }
94
+
95
+ export declare function decryptTransaction(ufvkStr: string, networkStr: string, rawTxBytes: Buffer, height: number): JsDecryptedTransactionResult
96
+
97
+ export declare function deriveAccountFromMnemonic(mnemonicStr: string, accountIndex: number, networkStr: string): DerivedAccount
98
+
99
+ export interface DerivedAccount {
100
+ ufvk: string
101
+ unifiedAddress: string
102
+ spendHandle: number
103
+ network: string
104
+ }
105
+
106
+ export declare function generateMnemonic(): string
107
+
108
+ export declare function getAddressFromUfvk(ufvkStr: string, networkStr: string, diversifierIndex?: number | undefined | null): string
109
+
110
+ export declare function getDefaultTxExpiryDelta(networkStr: string, height: number): number
111
+
112
+ export declare function getExpectedBranchId(networkStr: string, height: number): string
113
+
114
+ export declare function getTransparentAddressFromUfvk(ufvkStr: string, networkStr: string): string | null
115
+
116
+ /**
117
+ * Returns the 32-byte Merkle root hex of the empty Ironwood commitment tree.
118
+ *
119
+ * GetTreeState / z_gettreestate report an empty Ironwood frontier as zero bytes (Zaino sends
120
+ * `000000`) when the pool has no commitments at that height. The anchor of that tree is this
121
+ * value, so the anchor check can compare against it instead of skipping verification.
122
+ */
123
+ export declare function ironwoodEmptyTreeRoot(): string
124
+
125
+ export interface JsBuildTransactionRequest {
126
+ spendHandle?: number
127
+ spendingKeyBytes?: Buffer
128
+ recipientAddress: string
129
+ amountZatoshis: number
130
+ memo?: string
131
+ anchorBytes: Buffer
132
+ anchorHeight: number
133
+ expiryHeight?: number
134
+ spendableNoteIds: Array<number>
135
+ reservationId: Buffer
136
+ }
137
+
138
+ export interface JsBuiltTransaction {
139
+ txid: string
140
+ rawBytes: Buffer
141
+ fee: number
142
+ numActions: number
143
+ expiryHeight: number
144
+ }
145
+
146
+ export interface JsDecodedActionCounts {
147
+ transparentInputs: number
148
+ transparentOutputs: number
149
+ saplingSpends: number
150
+ saplingOutputs: number
151
+ orchardActions: number
152
+ ironwoodActions: number
153
+ }
154
+
155
+ export interface JsDecodedAnchorPair {
156
+ walletOrchardOrder: string
157
+ zebraRpcOrder: string
158
+ }
159
+
160
+ export interface JsDecodedAnchors {
161
+ sapling?: JsDecodedAnchorPair
162
+ orchard?: JsDecodedAnchorPair
163
+ ironwood?: JsDecodedAnchorPair
164
+ }
165
+
166
+ export interface JsDecodedTransaction {
167
+ txid: string
168
+ version: number
169
+ consensusBranchId: string
170
+ expiryHeight: number
171
+ fee?: number
172
+ pools: Array<string>
173
+ actionCounts: JsDecodedActionCounts
174
+ anchors: JsDecodedAnchors
175
+ nullifiers: Array<string>
176
+ noteCommitments: Array<string>
177
+ size: number
178
+ }
179
+
180
+ export interface JsDecryptedActionIncoming {
181
+ actionIndex: number
182
+ value: number
183
+ memo: JsDecryptedMemo
184
+ recipient: string
185
+ isChange: boolean
186
+ isInternal: boolean
187
+ }
188
+
189
+ export interface JsDecryptedActionOutgoing {
190
+ actionIndex: number
191
+ value: number
192
+ memo: JsDecryptedMemo
193
+ recipient: string
194
+ }
195
+
196
+ export interface JsDecryptedMemo {
197
+ text?: string
198
+ hex: string
199
+ }
200
+
201
+ export interface JsDecryptedTransactionResult {
202
+ txid: string
203
+ fee?: number
204
+ expiryHeight: number
205
+ consensusBranchId: string
206
+ incoming: Array<JsDecryptedActionIncoming>
207
+ outgoing: Array<JsDecryptedActionOutgoing>
208
+ }
209
+
210
+ export interface JsPersistedTransaction {
211
+ id: number
212
+ txid: string
213
+ actionIndex: number
214
+ height: number
215
+ direction: string
216
+ value: number
217
+ fee?: number
218
+ memo?: string
219
+ counterparty?: string
220
+ pool: string
221
+ createdAt: number
222
+ }
223
+
224
+ export interface JsScanResult {
225
+ status: string
226
+ lastScannedHeight: number
227
+ notesDetected: number
228
+ fromHeight?: number
229
+ count?: number
230
+ }
231
+
232
+ export interface JsSpendableNote {
233
+ id: number
234
+ recipient: string
235
+ valueZatoshis: number
236
+ nullifier: string
237
+ height: number
238
+ treePosition: number
239
+ }
240
+
241
+ export interface JsTouchedTx {
242
+ txidBytes: Buffer
243
+ height: number
244
+ }
245
+
246
+ export interface JsTreeFrontierInitResult {
247
+ height: number
248
+ treeSize: number
249
+ rootHex: string
250
+ alreadyInitialized: boolean
251
+ }
252
+
253
+ export interface JsTxFetchStatus {
254
+ pendingCount: number
255
+ failedCount: number
256
+ }
257
+
258
+ /** Returns the conventional ZIP 317 fee for a transaction with the given number of actions. */
259
+ export declare function quoteFee(numActions: number): number
260
+
261
+ export declare function tryDecryptAction(ufvkStr: string, networkStr: string, ephemeralKey: Buffer, cmx: Buffer, encCiphertext: Buffer, isIronwood: boolean, actionIndex: number, nullifier?: Buffer | undefined | null): DecryptedNote | null
262
+
263
+ export interface WalletSummary {
264
+ lastScannedHeight: number
265
+ treeSize: number
266
+ unspentNotesCount: number
267
+ totalBalanceZatoshis: number
268
+ spendableBalanceZatoshis: number
269
+ }
270
+
271
+ /** Warms up the static circuit proving key in a background thread ahead of first send. */
272
+ export declare function warmupProver(): void
package/index.js ADDED
@@ -0,0 +1,794 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ /* auto-generated by NAPI-RS */
4
+
5
+ const { readFileSync } = require('fs')
6
+ let nativeBinding = null
7
+ // Which artifact actually loaded. The WASI fallback chain overwrites it with
8
+ // the flavor it resolved; the late native retry below leaves it alone because
9
+ // it only runs while no WASI candidate has been loaded.
10
+ let __napiLoadedBindingTarget = 'native'
11
+ const loadErrors = []
12
+
13
+ const isMusl = () => {
14
+ let musl = false
15
+ if (process.platform === 'linux') {
16
+ musl = isMuslFromFilesystem()
17
+ if (musl === null) {
18
+ musl = isMuslFromReport()
19
+ }
20
+ if (musl === null) {
21
+ musl = isMuslFromChildProcess()
22
+ }
23
+ }
24
+ return musl
25
+ }
26
+
27
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
28
+
29
+ const isMuslFromFilesystem = () => {
30
+ try {
31
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
32
+ } catch {
33
+ return null
34
+ }
35
+ }
36
+
37
+ const isMuslFromReport = () => {
38
+ let report = null
39
+ if (process.report && typeof process.report.getReport === 'function') {
40
+ process.report.excludeNetwork = true
41
+ report = process.report.getReport()
42
+ }
43
+ if (!report) {
44
+ return null
45
+ }
46
+ if (report.header && report.header.glibcVersionRuntime) {
47
+ return false
48
+ }
49
+ if (Array.isArray(report.sharedObjects)) {
50
+ if (report.sharedObjects.some(isFileMusl)) {
51
+ return true
52
+ }
53
+ }
54
+ return false
55
+ }
56
+
57
+ const isMuslFromChildProcess = () => {
58
+ try {
59
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
60
+ } catch (e) {
61
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
62
+ return false
63
+ }
64
+ }
65
+
66
+ function requireNative() {
67
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
68
+ try {
69
+ const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
70
+ // The override may be a generated WASI loader, which already reports its
71
+ // own flavor. Adopt it: `module.exports` aliases this object, so claiming
72
+ // 'native' would both misreport the artifact and overwrite the loader's
73
+ // marker through the alias.
74
+ __napiLoadedBindingTarget =
75
+ overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
76
+ ? overrideBinding.__napiBindingTarget
77
+ : 'native'
78
+ return overrideBinding
79
+ } catch (err) {
80
+ loadErrors.push(err)
81
+ }
82
+ } else if (process.platform === 'android') {
83
+ if (process.arch === 'arm64') {
84
+ try {
85
+ return require('./zcash-core.android-arm64.node')
86
+ } catch (e) {
87
+ loadErrors.push(e)
88
+ }
89
+ try {
90
+ const binding = require('@zcash-app/core-android-arm64')
91
+ const bindingPackageVersion = require('@zcash-app/core-android-arm64/package.json').version
92
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
93
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
94
+ }
95
+ return binding
96
+ } catch (e) {
97
+ loadErrors.push(e)
98
+ }
99
+ } else if (process.arch === 'arm') {
100
+ try {
101
+ return require('./zcash-core.android-arm-eabi.node')
102
+ } catch (e) {
103
+ loadErrors.push(e)
104
+ }
105
+ try {
106
+ const binding = require('@zcash-app/core-android-arm-eabi')
107
+ const bindingPackageVersion = require('@zcash-app/core-android-arm-eabi/package.json').version
108
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
109
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
110
+ }
111
+ return binding
112
+ } catch (e) {
113
+ loadErrors.push(e)
114
+ }
115
+ } else {
116
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
117
+ }
118
+ } else if (process.platform === 'win32') {
119
+ if (process.arch === 'x64') {
120
+ 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')) {
121
+ try {
122
+ return require('./zcash-core.win32-x64-gnu.node')
123
+ } catch (e) {
124
+ loadErrors.push(e)
125
+ }
126
+ try {
127
+ const binding = require('@zcash-app/core-win32-x64-gnu')
128
+ const bindingPackageVersion = require('@zcash-app/core-win32-x64-gnu/package.json').version
129
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
130
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
131
+ }
132
+ return binding
133
+ } catch (e) {
134
+ loadErrors.push(e)
135
+ }
136
+ } else {
137
+ try {
138
+ return require('./zcash-core.win32-x64-msvc.node')
139
+ } catch (e) {
140
+ loadErrors.push(e)
141
+ }
142
+ try {
143
+ const binding = require('@zcash-app/core-win32-x64-msvc')
144
+ const bindingPackageVersion = require('@zcash-app/core-win32-x64-msvc/package.json').version
145
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
146
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
147
+ }
148
+ return binding
149
+ } catch (e) {
150
+ loadErrors.push(e)
151
+ }
152
+ }
153
+ } else if (process.arch === 'ia32') {
154
+ try {
155
+ return require('./zcash-core.win32-ia32-msvc.node')
156
+ } catch (e) {
157
+ loadErrors.push(e)
158
+ }
159
+ try {
160
+ const binding = require('@zcash-app/core-win32-ia32-msvc')
161
+ const bindingPackageVersion = require('@zcash-app/core-win32-ia32-msvc/package.json').version
162
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
163
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
164
+ }
165
+ return binding
166
+ } catch (e) {
167
+ loadErrors.push(e)
168
+ }
169
+ } else if (process.arch === 'arm64') {
170
+ try {
171
+ return require('./zcash-core.win32-arm64-msvc.node')
172
+ } catch (e) {
173
+ loadErrors.push(e)
174
+ }
175
+ try {
176
+ const binding = require('@zcash-app/core-win32-arm64-msvc')
177
+ const bindingPackageVersion = require('@zcash-app/core-win32-arm64-msvc/package.json').version
178
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
179
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
180
+ }
181
+ return binding
182
+ } catch (e) {
183
+ loadErrors.push(e)
184
+ }
185
+ } else {
186
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
187
+ }
188
+ } else if (process.platform === 'darwin') {
189
+ try {
190
+ return require('./zcash-core.darwin-universal.node')
191
+ } catch (e) {
192
+ loadErrors.push(e)
193
+ }
194
+ try {
195
+ const binding = require('@zcash-app/core-darwin-universal')
196
+ const bindingPackageVersion = require('@zcash-app/core-darwin-universal/package.json').version
197
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
198
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
199
+ }
200
+ return binding
201
+ } catch (e) {
202
+ loadErrors.push(e)
203
+ }
204
+ if (process.arch === 'x64') {
205
+ try {
206
+ return require('./zcash-core.darwin-x64.node')
207
+ } catch (e) {
208
+ loadErrors.push(e)
209
+ }
210
+ try {
211
+ const binding = require('@zcash-app/core-darwin-x64')
212
+ const bindingPackageVersion = require('@zcash-app/core-darwin-x64/package.json').version
213
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
214
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
215
+ }
216
+ return binding
217
+ } catch (e) {
218
+ loadErrors.push(e)
219
+ }
220
+ } else if (process.arch === 'arm64') {
221
+ try {
222
+ return require('./zcash-core.darwin-arm64.node')
223
+ } catch (e) {
224
+ loadErrors.push(e)
225
+ }
226
+ try {
227
+ const binding = require('@zcash-app/core-darwin-arm64')
228
+ const bindingPackageVersion = require('@zcash-app/core-darwin-arm64/package.json').version
229
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
230
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
231
+ }
232
+ return binding
233
+ } catch (e) {
234
+ loadErrors.push(e)
235
+ }
236
+ } else {
237
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
238
+ }
239
+ } else if (process.platform === 'freebsd') {
240
+ if (process.arch === 'x64') {
241
+ try {
242
+ return require('./zcash-core.freebsd-x64.node')
243
+ } catch (e) {
244
+ loadErrors.push(e)
245
+ }
246
+ try {
247
+ const binding = require('@zcash-app/core-freebsd-x64')
248
+ const bindingPackageVersion = require('@zcash-app/core-freebsd-x64/package.json').version
249
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
250
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
251
+ }
252
+ return binding
253
+ } catch (e) {
254
+ loadErrors.push(e)
255
+ }
256
+ } else if (process.arch === 'arm64') {
257
+ try {
258
+ return require('./zcash-core.freebsd-arm64.node')
259
+ } catch (e) {
260
+ loadErrors.push(e)
261
+ }
262
+ try {
263
+ const binding = require('@zcash-app/core-freebsd-arm64')
264
+ const bindingPackageVersion = require('@zcash-app/core-freebsd-arm64/package.json').version
265
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
266
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
267
+ }
268
+ return binding
269
+ } catch (e) {
270
+ loadErrors.push(e)
271
+ }
272
+ } else {
273
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
274
+ }
275
+ } else if (process.platform === 'linux') {
276
+ if (process.arch === 'x64') {
277
+ if (isMusl()) {
278
+ try {
279
+ return require('./zcash-core.linux-x64-musl.node')
280
+ } catch (e) {
281
+ loadErrors.push(e)
282
+ }
283
+ try {
284
+ const binding = require('@zcash-app/core-linux-x64-musl')
285
+ const bindingPackageVersion = require('@zcash-app/core-linux-x64-musl/package.json').version
286
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
287
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
288
+ }
289
+ return binding
290
+ } catch (e) {
291
+ loadErrors.push(e)
292
+ }
293
+ } else {
294
+ try {
295
+ return require('./zcash-core.linux-x64-gnu.node')
296
+ } catch (e) {
297
+ loadErrors.push(e)
298
+ }
299
+ try {
300
+ const binding = require('@zcash-app/core-linux-x64-gnu')
301
+ const bindingPackageVersion = require('@zcash-app/core-linux-x64-gnu/package.json').version
302
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
303
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
304
+ }
305
+ return binding
306
+ } catch (e) {
307
+ loadErrors.push(e)
308
+ }
309
+ }
310
+ } else if (process.arch === 'arm64') {
311
+ if (isMusl()) {
312
+ try {
313
+ return require('./zcash-core.linux-arm64-musl.node')
314
+ } catch (e) {
315
+ loadErrors.push(e)
316
+ }
317
+ try {
318
+ const binding = require('@zcash-app/core-linux-arm64-musl')
319
+ const bindingPackageVersion = require('@zcash-app/core-linux-arm64-musl/package.json').version
320
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
321
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
322
+ }
323
+ return binding
324
+ } catch (e) {
325
+ loadErrors.push(e)
326
+ }
327
+ } else {
328
+ try {
329
+ return require('./zcash-core.linux-arm64-gnu.node')
330
+ } catch (e) {
331
+ loadErrors.push(e)
332
+ }
333
+ try {
334
+ const binding = require('@zcash-app/core-linux-arm64-gnu')
335
+ const bindingPackageVersion = require('@zcash-app/core-linux-arm64-gnu/package.json').version
336
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
337
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
338
+ }
339
+ return binding
340
+ } catch (e) {
341
+ loadErrors.push(e)
342
+ }
343
+ }
344
+ } else if (process.arch === 'arm') {
345
+ if (isMusl()) {
346
+ try {
347
+ return require('./zcash-core.linux-arm-musleabihf.node')
348
+ } catch (e) {
349
+ loadErrors.push(e)
350
+ }
351
+ try {
352
+ const binding = require('@zcash-app/core-linux-arm-musleabihf')
353
+ const bindingPackageVersion = require('@zcash-app/core-linux-arm-musleabihf/package.json').version
354
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
355
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
356
+ }
357
+ return binding
358
+ } catch (e) {
359
+ loadErrors.push(e)
360
+ }
361
+ } else {
362
+ try {
363
+ return require('./zcash-core.linux-arm-gnueabihf.node')
364
+ } catch (e) {
365
+ loadErrors.push(e)
366
+ }
367
+ try {
368
+ const binding = require('@zcash-app/core-linux-arm-gnueabihf')
369
+ const bindingPackageVersion = require('@zcash-app/core-linux-arm-gnueabihf/package.json').version
370
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
371
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
372
+ }
373
+ return binding
374
+ } catch (e) {
375
+ loadErrors.push(e)
376
+ }
377
+ }
378
+ } else if (process.arch === 'loong64') {
379
+ if (isMusl()) {
380
+ try {
381
+ return require('./zcash-core.linux-loong64-musl.node')
382
+ } catch (e) {
383
+ loadErrors.push(e)
384
+ }
385
+ try {
386
+ const binding = require('@zcash-app/core-linux-loong64-musl')
387
+ const bindingPackageVersion = require('@zcash-app/core-linux-loong64-musl/package.json').version
388
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
389
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
390
+ }
391
+ return binding
392
+ } catch (e) {
393
+ loadErrors.push(e)
394
+ }
395
+ } else {
396
+ try {
397
+ return require('./zcash-core.linux-loong64-gnu.node')
398
+ } catch (e) {
399
+ loadErrors.push(e)
400
+ }
401
+ try {
402
+ const binding = require('@zcash-app/core-linux-loong64-gnu')
403
+ const bindingPackageVersion = require('@zcash-app/core-linux-loong64-gnu/package.json').version
404
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
405
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
406
+ }
407
+ return binding
408
+ } catch (e) {
409
+ loadErrors.push(e)
410
+ }
411
+ }
412
+ } else if (process.arch === 'riscv64') {
413
+ if (isMusl()) {
414
+ try {
415
+ return require('./zcash-core.linux-riscv64-musl.node')
416
+ } catch (e) {
417
+ loadErrors.push(e)
418
+ }
419
+ try {
420
+ const binding = require('@zcash-app/core-linux-riscv64-musl')
421
+ const bindingPackageVersion = require('@zcash-app/core-linux-riscv64-musl/package.json').version
422
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
423
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
424
+ }
425
+ return binding
426
+ } catch (e) {
427
+ loadErrors.push(e)
428
+ }
429
+ } else {
430
+ try {
431
+ return require('./zcash-core.linux-riscv64-gnu.node')
432
+ } catch (e) {
433
+ loadErrors.push(e)
434
+ }
435
+ try {
436
+ const binding = require('@zcash-app/core-linux-riscv64-gnu')
437
+ const bindingPackageVersion = require('@zcash-app/core-linux-riscv64-gnu/package.json').version
438
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
439
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
440
+ }
441
+ return binding
442
+ } catch (e) {
443
+ loadErrors.push(e)
444
+ }
445
+ }
446
+ } else if (process.arch === 'ppc64') {
447
+ try {
448
+ return require('./zcash-core.linux-ppc64-gnu.node')
449
+ } catch (e) {
450
+ loadErrors.push(e)
451
+ }
452
+ try {
453
+ const binding = require('@zcash-app/core-linux-ppc64-gnu')
454
+ const bindingPackageVersion = require('@zcash-app/core-linux-ppc64-gnu/package.json').version
455
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
456
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
457
+ }
458
+ return binding
459
+ } catch (e) {
460
+ loadErrors.push(e)
461
+ }
462
+ } else if (process.arch === 's390x') {
463
+ try {
464
+ return require('./zcash-core.linux-s390x-gnu.node')
465
+ } catch (e) {
466
+ loadErrors.push(e)
467
+ }
468
+ try {
469
+ const binding = require('@zcash-app/core-linux-s390x-gnu')
470
+ const bindingPackageVersion = require('@zcash-app/core-linux-s390x-gnu/package.json').version
471
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
472
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
473
+ }
474
+ return binding
475
+ } catch (e) {
476
+ loadErrors.push(e)
477
+ }
478
+ } else {
479
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
480
+ }
481
+ } else if (process.platform === 'openharmony') {
482
+ if (process.arch === 'arm64') {
483
+ try {
484
+ return require('./zcash-core.openharmony-arm64.node')
485
+ } catch (e) {
486
+ loadErrors.push(e)
487
+ }
488
+ try {
489
+ const binding = require('@zcash-app/core-openharmony-arm64')
490
+ const bindingPackageVersion = require('@zcash-app/core-openharmony-arm64/package.json').version
491
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
492
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
493
+ }
494
+ return binding
495
+ } catch (e) {
496
+ loadErrors.push(e)
497
+ }
498
+ } else if (process.arch === 'x64') {
499
+ try {
500
+ return require('./zcash-core.openharmony-x64.node')
501
+ } catch (e) {
502
+ loadErrors.push(e)
503
+ }
504
+ try {
505
+ const binding = require('@zcash-app/core-openharmony-x64')
506
+ const bindingPackageVersion = require('@zcash-app/core-openharmony-x64/package.json').version
507
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
508
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
509
+ }
510
+ return binding
511
+ } catch (e) {
512
+ loadErrors.push(e)
513
+ }
514
+ } else if (process.arch === 'arm') {
515
+ try {
516
+ return require('./zcash-core.openharmony-arm.node')
517
+ } catch (e) {
518
+ loadErrors.push(e)
519
+ }
520
+ try {
521
+ const binding = require('@zcash-app/core-openharmony-arm')
522
+ const bindingPackageVersion = require('@zcash-app/core-openharmony-arm/package.json').version
523
+ if (bindingPackageVersion !== '0.1.0-alpha.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
524
+ throw new Error(`Native binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
525
+ }
526
+ return binding
527
+ } catch (e) {
528
+ loadErrors.push(e)
529
+ }
530
+ } else {
531
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
532
+ }
533
+ } else {
534
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
535
+ }
536
+ }
537
+
538
+ function createLoadErrorChain(errors) {
539
+ return errors.reduce((previous, current) => {
540
+ let message
541
+ try {
542
+ message =
543
+ current && typeof current.message === 'string'
544
+ ? current.message
545
+ : String(current)
546
+ } catch {
547
+ message = 'Unknown error'
548
+ }
549
+ const error = new Error(message)
550
+ error.cause = previous
551
+ return error
552
+ }, null)
553
+ }
554
+
555
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
556
+ // unset / any other value → native binding preferred, WASI is only a fallback
557
+ // 'true' → prefer WASI, but retain native as a lazy fallback
558
+ // 'error' → require WASI without initializing a native fallback
559
+ // Treating any non-empty string as truthy (the historical behavior) meant
560
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
561
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
562
+ //
563
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
564
+ // WASI loading. It never crosses into another flavor or falls back to native.
565
+ const __napiWasiFlavors = ['wasm32-wasi']
566
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
567
+ const __napiWasiFlavorRequested =
568
+ typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
569
+ if (
570
+ __napiWasiFlavorRequested &&
571
+ __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
572
+ ) {
573
+ throw new Error(
574
+ 'Unsupported WASI flavor "' +
575
+ __napiWasiFlavor +
576
+ '". Available flavors: ' +
577
+ __napiWasiFlavors.join(', '),
578
+ )
579
+ }
580
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
581
+ const forceWasi =
582
+ process.env.NAPI_RS_FORCE_WASI === 'true' ||
583
+ forceWasiError ||
584
+ __napiWasiFlavorRequested
585
+
586
+ if (!forceWasi) {
587
+ nativeBinding = requireNative()
588
+ }
589
+
590
+ if (!nativeBinding || forceWasi) {
591
+ let wasiBinding = null
592
+ let wasiBindingLoaded = false
593
+ const wasiBindingErrors = []
594
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
595
+ try {
596
+ require.resolve(specifier)
597
+ } catch (resolveError) {
598
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
599
+ throw resolveError
600
+ }
601
+ if (isPackage) {
602
+ try {
603
+ require.resolve(specifier + '/package.json')
604
+ } catch (packageError) {
605
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
606
+ return resolveError
607
+ }
608
+ // An exports restriction proves the package exists even when its
609
+ // package.json is not public. Preserve the root resolution failure.
610
+ throw resolveError
611
+ }
612
+ // The package exists but its main/export target is broken.
613
+ throw resolveError
614
+ }
615
+ return resolveError
616
+ }
617
+ if (localArtifacts) {
618
+ let artifactError = null
619
+ for (let i = 0; i < localArtifacts.length; i++) {
620
+ try {
621
+ require.resolve(localArtifacts[i])
622
+ return null
623
+ } catch (resolveError) {
624
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
625
+ throw resolveError
626
+ }
627
+ artifactError = resolveError
628
+ }
629
+ }
630
+ return artifactError
631
+ }
632
+ return null
633
+ }
634
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
635
+ let candidateError = null
636
+ let candidateFailed = false
637
+ try {
638
+ candidateError = __napiWasiResolveCandidate('./zcash-core.wasi.cjs', false, ['./zcash-core.wasm32-wasi.debug.wasm', './zcash-core.wasm32-wasi.wasm'])
639
+ candidateFailed = candidateError !== null
640
+ if (!candidateFailed) {
641
+ wasiBinding = require('./zcash-core.wasi.cjs')
642
+ nativeBinding = wasiBinding
643
+ __napiLoadedBindingTarget = 'wasm32-wasi'
644
+ wasiBindingLoaded = true
645
+ }
646
+ } catch (err) {
647
+ candidateError = err
648
+ candidateFailed = true
649
+ }
650
+ if (candidateFailed) {
651
+ wasiBindingErrors.push(candidateError)
652
+ loadErrors.push(candidateError)
653
+ }
654
+ }
655
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
656
+ let candidateError = null
657
+ let candidateFailed = false
658
+ try {
659
+ candidateError = __napiWasiResolveCandidate('@zcash-app/core-wasm32-wasi', true, undefined)
660
+ candidateFailed = candidateError !== null
661
+ if (!candidateFailed) {
662
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
663
+ const bindingPackageVersion = require('@zcash-app/core-wasm32-wasi/package.json').version
664
+ if (bindingPackageVersion !== '0.1.0-alpha.1') {
665
+ throw new Error(`WASI binding package version mismatch, expected 0.1.0-alpha.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
666
+ }
667
+ }
668
+ wasiBinding = require('@zcash-app/core-wasm32-wasi')
669
+ nativeBinding = wasiBinding
670
+ __napiLoadedBindingTarget = 'wasm32-wasi'
671
+ wasiBindingLoaded = true
672
+ }
673
+ } catch (err) {
674
+ candidateError = err
675
+ candidateFailed = true
676
+ }
677
+ if (candidateFailed) {
678
+ wasiBindingErrors.push(candidateError)
679
+ loadErrors.push(candidateError)
680
+ }
681
+ }
682
+ if (
683
+ !wasiBindingLoaded &&
684
+ forceWasi &&
685
+ !forceWasiError &&
686
+ !__napiWasiFlavorRequested
687
+ ) {
688
+ nativeBinding = requireNative()
689
+ }
690
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
691
+ const error = new Error(
692
+ __napiWasiFlavorRequested
693
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
694
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
695
+ )
696
+ error.cause = createLoadErrorChain(wasiBindingErrors)
697
+ throw error
698
+ }
699
+ }
700
+
701
+ if (!nativeBinding) {
702
+ if (loadErrors.length > 0) {
703
+ const error = new Error(
704
+ `Cannot find native binding. ` +
705
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
706
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
707
+ )
708
+ // assign instead of the `new Error(message, { cause })` options form,
709
+ // which Node < 16.9 silently ignores
710
+ error.cause = createLoadErrorChain(loadErrors)
711
+ throw error
712
+ }
713
+ throw new Error(`Failed to load native binding`)
714
+ }
715
+
716
+ function __napiStampBindingTarget(exportsObject, target) {
717
+ if (
718
+ Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
719
+ ) {
720
+ if (exportsObject.__napiBindingTarget === target) {
721
+ // Already ours: the root entry aliases the object it loaded, so a WASI
722
+ // fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
723
+ // is a generated loader — arrives already stamped with this same value.
724
+ return target
725
+ }
726
+ const error = new Error(
727
+ '`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
728
+ )
729
+ error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
730
+ throw error
731
+ }
732
+ if (!Object.isExtensible(exportsObject)) {
733
+ // A `#[napi(module_exports)]` hook may seal or freeze this object
734
+ // (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
735
+ // never a reason to fail an otherwise successful load, so the stamp is
736
+ // skipped. What a consumer still sees then follows the entry point: the
737
+ // browser and deferred loaders declare `__napiBindingTarget` at module
738
+ // level and go on reporting it, while the CommonJS entries hand back this
739
+ // very object as `module.exports`, so there the value is absent.
740
+ return target
741
+ }
742
+ try {
743
+ // [[Define]], not [[Set]]: an ordinary assignment walks the prototype
744
+ // chain, so an inherited accessor could swallow the value or throw and
745
+ // fail an otherwise successful load. The descriptor is what a successful
746
+ // assignment would have produced.
747
+ Object.defineProperty(exportsObject, '__napiBindingTarget', {
748
+ configurable: true,
749
+ enumerable: true,
750
+ value: target,
751
+ writable: true,
752
+ })
753
+ } catch {
754
+ // Same rule as the non-extensible skip above: reporting the artifact is
755
+ // metadata, never a reason to fail an otherwise successful load. An exotic
756
+ // object (a Proxy whose defineProperty trap refuses) is skipped, not
757
+ // thrown over.
758
+ }
759
+ // The CommonJS loaders assign this return value so `cjs-module-lexer` — and
760
+ // therefore Node's CJS -> ESM named export detection — can see
761
+ // `__napiBindingTarget` statically.
762
+ return target
763
+ }
764
+ // Stamp before the alias, not after. The guard only reads `nativeBinding`
765
+ // (`hasOwnProperty` plus a comparison), which is safe against any addon
766
+ // accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
767
+ // expose a getter reporting this very value and a setter that throws. So the
768
+ // assignment lands on the loader's own `module.exports`, still the original
769
+ // object here, and the alias below replaces it.
770
+ //
771
+ // The assignment is what keeps the marker a statically visible CommonJS export:
772
+ // `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
773
+ // a bare call, and the later `module.exports = nativeBinding` does not undo the
774
+ // detection. The assignment itself always succeeds — its target is this
775
+ // loader's own, still extensible `module.exports` — and the alias below then
776
+ // discards the value it wrote. What a consumer reads is whatever the guard put
777
+ // on `nativeBinding`, so on a frozen binding, where the guard skips, the
778
+ // linked import resolves to `undefined`.
779
+ module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
780
+ module.exports = nativeBinding
781
+ module.exports.WalletHandle = nativeBinding.WalletHandle
782
+ module.exports.decodeIronwoodFrontierRoot = nativeBinding.decodeIronwoodFrontierRoot
783
+ module.exports.decodeTransaction = nativeBinding.decodeTransaction
784
+ module.exports.decryptTransaction = nativeBinding.decryptTransaction
785
+ module.exports.deriveAccountFromMnemonic = nativeBinding.deriveAccountFromMnemonic
786
+ module.exports.generateMnemonic = nativeBinding.generateMnemonic
787
+ module.exports.getAddressFromUfvk = nativeBinding.getAddressFromUfvk
788
+ module.exports.getDefaultTxExpiryDelta = nativeBinding.getDefaultTxExpiryDelta
789
+ module.exports.getExpectedBranchId = nativeBinding.getExpectedBranchId
790
+ module.exports.getTransparentAddressFromUfvk = nativeBinding.getTransparentAddressFromUfvk
791
+ module.exports.ironwoodEmptyTreeRoot = nativeBinding.ironwoodEmptyTreeRoot
792
+ module.exports.quoteFee = nativeBinding.quoteFee
793
+ module.exports.tryDecryptAction = nativeBinding.tryDecryptAction
794
+ module.exports.warmupProver = nativeBinding.warmupProver
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@zcash-app/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Rust crypto core for create-zcash-app: trial-decryption, key derivation, and proving",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "license": "Apache-2.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Ultra-Tech-code/create-zcash-app.git",
11
+ "directory": "packages/core"
12
+ },
13
+ "homepage": "https://github.com/Ultra-Tech-code/create-zcash-app#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/Ultra-Tech-code/create-zcash-app/issues"
16
+ },
17
+ "keywords": [
18
+ "zcash",
19
+ "shielded",
20
+ "orchard",
21
+ "ironwood",
22
+ "nu7",
23
+ "crypto",
24
+ "rust",
25
+ "napi"
26
+ ],
27
+ "files": [
28
+ "index.js",
29
+ "index.d.ts"
30
+ ],
31
+ "napi": {
32
+ "binaryName": "zcash-core",
33
+ "targets": [
34
+ "aarch64-apple-darwin",
35
+ "x86_64-apple-darwin",
36
+ "x86_64-unknown-linux-gnu",
37
+ "aarch64-unknown-linux-gnu",
38
+ "x86_64-pc-windows-msvc"
39
+ ]
40
+ },
41
+ "devDependencies": {
42
+ "@napi-rs/cli": "^3.0.0"
43
+ },
44
+ "optionalDependencies": {
45
+ "@zcash-app/core-darwin-arm64": "0.1.0-alpha.1",
46
+ "@zcash-app/core-darwin-x64": "0.1.0-alpha.1",
47
+ "@zcash-app/core-linux-x64-gnu": "0.1.0-alpha.1",
48
+ "@zcash-app/core-linux-arm64-gnu": "0.1.0-alpha.1",
49
+ "@zcash-app/core-win32-x64-msvc": "0.1.0-alpha.1"
50
+ },
51
+ "scripts": {
52
+ "artifacts": "napi artifacts",
53
+ "build": "napi build --platform --release",
54
+ "build:debug": "napi build --platform",
55
+ "prepublish": "napi pre-publish --dry-run --tag-style npm",
56
+ "test": "cargo test"
57
+ }
6
58
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
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.