@ledgerhq/zcash-utils 2.2.0 → 2.3.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/CHANGELOG.md CHANGED
@@ -1,51 +1,36 @@
1
1
  # @ledgerhq/zcash-utils
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9defc44: Relicense to `Apache-2.0`, aligning with the Ledger device stack this package belongs to: the Device Management Kit, the Zcash device signer kit and the Zcash device app are all `Apache-2.0`. Nothing in the repository stated a license authoritatively before — `package.json` declared `MIT`, the four Rust crates declared `MIT OR Apache-2.0`, and no LICENSE file existed at all.
8
+
9
+ The declaration now lives in `[workspace.package]` of the root `Cargo.toml`, inherited by every crate, and is mirrored in `package.json`. The full Apache 2.0 text ships as `LICENSE.md`, which npm includes in the tarball even though the `files` field does not name it, so the published package now carries its own license text.
10
+
11
+ ### Patch Changes
12
+
13
+ - 57b3588: Document the whole published API in the README, which had drifted to covering three of the eleven exports. Everything the send path is made of — `buildTransaction`, `buildIronwoodTransaction`, `parsePczt`, `finalizeTransaction`, `broadcastTransaction` — plus `findBlockHeight`, `transactionDetails` and `orchardAddressFromUfvk` were absent, as were the note fields that make a note spendable (`nullifier`, `rho`, `rseed`, `cmx`, `position`, `recipient`, `isSpent`), `knownNullifiers` / `spentKnownNullifiers`, and `transparentOut` / `hasTransparentInputs`.
14
+
15
+ The README now walks the send round trip through the device rather than listing functions, and states the two encoding conventions a caller has to get right: zatoshis are JS numbers on the scanning path but decimal strings on the crafting path, and txids come in display order everywhere except `TransparentInputJs.txid`, which is internal order. Its install step names the Artifactory registry the package actually publishes to.
16
+
3
17
  ## 2.2.0
4
18
 
5
19
  ### Minor Changes
6
20
 
7
- - 0a94002: Build a transparent send without a UFVK. `buildTransaction` required a UFVK for
8
- every flow, including a fully transparent one — which carries no shielded bundle
9
- and reads no shielded key material. Its only key requirement is the
10
- account-level transparent pubkey at `m/44'/coin'/account'`, used to derive the
11
- internal change address and to verify each input's signing path. A wallet always
12
- holds those bytes (they are the payload of the account xpub) whereas obtaining a
13
- UFVK takes a user confirmation on the device, so the requirement forced a
14
- viewing-key export on anyone spending public funds.
15
-
16
- `ufvk` is now optional and a `transparentAccountPubkey` field accepts those 65
17
- bytes (32-byte chain code ‖ 33-byte compressed pubkey) as hex. A transparent
18
- send supplies the pubkey and omits the UFVK; both may be supplied together, in
19
- which case the UFVK's transparent component is authoritative and the standalone
20
- field only has to agree with it — a mismatch means key material from two
21
- different accounts and fails the build rather than picking one. Every flow with
22
- a shielded bundle (an Orchard spend, or a shielded recipient) still requires the
23
- UFVK and now says so explicitly instead of failing deeper on a missing Orchard
24
- component; `buildIronwoodTransaction`, whose bundle is always shielded, is
25
- unchanged.
26
-
27
- The two orchestrators now share one transparent-input decoder, so the
28
- fund-safety check that ties each input's `(derivationScope, addressIndex)` to
29
- its pubkey has a single implementation instead of two copies.
21
+ - 0a94002: Build a transparent send without a UFVK. `buildTransaction` required a UFVK for every flow, including a fully transparent one — which carries no shielded bundle and reads no shielded key material. Its only key requirement is the account-level transparent pubkey at `m/44'/coin'/account'`, used to derive the internal change address and to verify each input's signing path. A wallet always holds those bytes (they are the payload of the account xpub) whereas obtaining a UFVK takes a user confirmation on the device, so the requirement forced a viewing-key export on anyone spending public funds.
22
+
23
+ `ufvk` is now optional and a `transparentAccountPubkey` field accepts those 65 bytes (32-byte chain code ‖ 33-byte compressed pubkey) as hex. A transparent send supplies the pubkey and omits the UFVK; both may be supplied together, in which case the UFVK's transparent component is authoritative and the standalone field only has to agree with it — a mismatch means key material from two different accounts and fails the build rather than picking one. Every flow with a shielded bundle (an Orchard spend, or a shielded recipient) still requires the UFVK and now says so explicitly instead of failing deeper on a missing Orchard component; `buildIronwoodTransaction`, whose bundle is always shielded, is unchanged.
24
+
25
+ The two orchestrators now share one transparent-input decoder, so the fund-safety check that ties each input's `(derivationScope, addressIndex)` to its pubkey has a single implementation instead of two copies.
30
26
 
31
27
  ### Patch Changes
32
28
 
33
- - 0a94002: Refresh the dependency lock and collapse the duplicate `shardtree`. The lock
34
- carried two copies of it — our own `0.6.2` plus the `0.7.0` that
35
- `zcash_client_backend` links — so the commitment-tree types existed twice under
36
- identical names and a witness built against one could not cross into the other.
37
- Declaring `shardtree = "0.7"` leaves a single `0.7.1` copy that both sides share.
29
+ - 0a94002: Refresh the dependency lock and collapse the duplicate `shardtree`. The lock carried two copies of it — our own `0.6.2` plus the `0.7.0` that `zcash_client_backend` links — so the commitment-tree types existed twice under identical names and a witness built against one could not cross into the other. Declaring `shardtree = "0.7"` leaves a single `0.7.1` copy that both sides share.
38
30
 
39
- `pczt` moves to `0.9.3`, still pinned exactly: it defines the byte stream the
40
- firmware parses, so it may only move as a deliberate, tested step and never as a
41
- side effect of `cargo update`. `bitcoin` stays on the `0.32.x` maintenance line
42
- for the same reason — the parallel `0.32.10x` feature line sorts higher and a
43
- broad update would otherwise drift onto it — and the pin is now documented in
44
- `Cargo.toml` so the next refresh keeps it.
31
+ `pczt` moves to `0.9.3`, still pinned exactly: it defines the byte stream the firmware parses, so it may only move as a deliberate, tested step and never as a side effect of `cargo update`. `bitcoin` stays on the `0.32.x` maintenance line for the same reason — the parallel `0.32.10x` feature line sorts higher and a broad update would otherwise drift onto it — and the pin is now documented in `Cargo.toml` so the next refresh keeps it.
45
32
 
46
- The rest is a routine refresh of transitive dependencies. No Zcash protocol crate
47
- moves: `zcash_primitives`, `zcash_keys`, `zcash_transparent`, `orchard` and
48
- `zcash_client_backend` all stay where they were.
33
+ The rest is a routine refresh of transitive dependencies. No Zcash protocol crate moves: `zcash_primitives`, `zcash_keys`, `zcash_transparent`, `orchard` and `zcash_client_backend` all stay where they were.
49
34
 
50
35
  ## 2.1.1
51
36
 
@@ -73,17 +58,12 @@
73
58
 
74
59
  Since 0.3.1 the addon grew from a scan-only library into a full Orchard send pipeline:
75
60
 
76
- - V5 PCZT transaction builder supporting Orchard send flows and mixed
77
- transparent + Orchard inputs, with bip32 derivation stamped on the change
78
- output and every transparent input
79
- - `buildTransaction`, `finalizeTransaction`, and `broadcastTransaction` to
80
- build, finalize, and submit a shielded transaction
81
- - `parsePczt(pcztHex)` to decode canonical PCZT bytes into a structured
82
- `PcztTransaction` consumed by `@ledgerhq/device-signer-kit-zcash`
61
+ - V5 PCZT transaction builder supporting Orchard send flows and mixed transparent + Orchard inputs, with bip32 derivation stamped on the change output and every transparent input
62
+ - `buildTransaction`, `finalizeTransaction`, and `broadcastTransaction` to build, finalize, and submit a shielded transaction
63
+ - `parsePczt(pcztHex)` to decode canonical PCZT bytes into a structured `PcztTransaction` consumed by `@ledgerhq/device-signer-kit-zcash`
83
64
  - On-demand Orchard ShardTree witness computation at craft time
84
65
  - `findBlockHeight(grpcUrl, timestamp)` binary search over block timestamps
85
- - NU6.2-aware crate versions for correct branch-id resolution and shielded
86
- parsing at/above the NU6.2 activation height
66
+ - NU6.2-aware crate versions for correct branch-id resolution and shielded parsing at/above the NU6.2 activation height
87
67
 
88
68
  ### Minor Changes
89
69
 
@@ -124,8 +104,7 @@
124
104
  - `zcash_crypto::tree::{build_witnesses, WitnessInputs, WitnessOutput, ShardLeaves}`
125
105
  - `zcash_sync::witness::{compute_witnesses, WitnessRequest, NoteRef}`
126
106
 
127
- Witness data is fetched and assembled on demand at craft time. No tree state
128
- is persisted between calls.
107
+ Witness data is fetched and assembled on demand at craft time. No tree state is persisted between calls.
129
108
 
130
109
  - 68d013b: Add `buildIronwoodTransaction` for the Ironwood (NU6.3) shielded pool: builds, proves, and serializes an unsigned V6 PCZT carrying an Ironwood bundle (spends and/or outputs), reusing the existing Orchard V5 crafting lifecycle against the updated Action circuit. Ironwood outputs use the `0x03` quantum-recoverable note plaintext, the emitted PCZT is redacted and serialized in the v2 wire format (required for any V6 transaction), and a dedicated non-zero-anchor check rejects an all-zero Ironwood commitment-tree root before it can be silently embedded. Anchor/witness resolution reuses the existing Ironwood sync path (`fetchIronwoodAnchor` / Ironwood witness computation). The shipped Orchard V5 send flow (`buildTransaction`) is unchanged. Like the V5 builder, this is device-coupled (not exposed via the CLI) and depends on release-candidate wallet-side crates (`pczt`, `zcash_client_backend`) pending stable NU6.3 releases.
131
110
  - 65c6a95: Add `transactionDetails`, which fetches transactions by txid and reads from each what only the raw bytes hold: the fee it actually paid, and the addresses its shielded outputs paid.
package/LICENSE.md ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026-present Ledger
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,129 +1,206 @@
1
1
  # @ledgerhq/zcash-utils
2
2
 
3
- Native Node.js (NAPI) addon for Zcash shielded transaction scanning — built in Rust via [napi-rs](https://napi.rs).
3
+ Native Node.js (NAPI) addon for Zcash wallet operations — built in Rust via [napi-rs](https://napi.rs).
4
+
5
+ It covers the two halves of a shielded wallet that cannot be done in TypeScript: **scanning** the chain for notes belonging to an account (trial decryption of every compact block), and **crafting** a send as a PCZT for a Ledger device to sign, then reassembling and broadcasting the signed transaction. Halo 2 proving, PCZT (postcard) serialization, and the binding signature all happen here, in Rust.
6
+
7
+ Spending key material never enters this layer. It reads a Unified Full Viewing Key and an account-level transparent pubkey; every signature comes from the device.
4
8
 
5
9
  ## Installation
6
10
 
11
+ The package is published to Ledger's internal JFrog Artifactory, not to public npm, so the `@ledgerhq` scope must be routed there:
12
+
13
+ ```sh
14
+ # ~/.npmrc
15
+ @ledgerhq:registry=https://<artifactory-host>/
16
+ ```
17
+
7
18
  ```sh
8
- npm install @ledgerhq/zcash-utils
9
- # or
10
19
  pnpm add @ledgerhq/zcash-utils
11
20
  ```
12
21
 
13
- ## Quick start
22
+ Prebuilt `.node` binaries are bundled in the package for six targets: `darwin-arm64`, `darwin-x64`, `linux-x64-gnu`, `linux-arm64-gnu`, `win32-x64-msvc`, `win32-arm64-msvc`. On any other platform, build from source — see [`CONTRIBUTING.md`](CONTRIBUTING.md).
23
+
24
+ ## Quick start — scanning
14
25
 
15
26
  ```typescript
16
27
  import { startSync, getChainTip } from "@ledgerhq/zcash-utils";
17
28
 
18
- const tip = await getChainTip(
19
- "https://zaino-zec-testnet.nodes.stg.ledger-test.com/",
20
- );
29
+ const grpcUrl = "https://zaino-zec-testnet.nodes.stg.ledger-test.com/";
30
+ const tip = await getChainTip(grpcUrl);
21
31
 
22
32
  const stream = await startSync({
23
- grpcUrl: "https://zaino-zec-testnet.nodes.stg.ledger-test.com/",
33
+ grpcUrl,
24
34
  viewingKey: "uviewtest1...",
25
35
  startHeight: tip - 1000,
26
36
  endHeight: tip,
27
37
  network: "testnet",
38
+ // Skips all Sapling crypto work. Ledger wallets are Orchard-only, but the
39
+ // default is false. Ironwood notes are decrypted regardless of this flag.
28
40
  orchardOnly: true,
41
+ // Nullifiers of still-unspent notes from previous scans, so a note spent
42
+ // in this range is detected across the incremental sync boundary.
43
+ knownNullifiers: [],
29
44
  });
30
45
 
31
46
  let tx;
32
47
  while ((tx = await stream.next()) !== null) {
33
- console.log(tx.txid, tx.orchardNotes);
48
+ // Each note carries its spending fields (nullifier, rho, rseed, cmx,
49
+ // position, recipient) — persist them, they are the inputs to a later send.
50
+ console.log(tx.txid, tx.orchardNotes, tx.ironwoodNotes);
34
51
  }
35
52
 
36
53
  const stats = await stream.stats();
54
+ // stats.spentKnownNullifiers — previously-stored notes to mark as spent.
37
55
  console.log(`Scanned ${stats.blocksScanned} blocks in ${stats.elapsedMs}ms`);
38
56
  ```
39
57
 
58
+ ## Sending: the full flow
59
+
60
+ A send is a round trip through the device. This package owns every step except the signing itself.
61
+
62
+ 1. **Craft** — `buildTransaction` (Orchard and/or transparent source) or `buildIronwoodTransaction` (Ironwood source) selects change, computes Merkle witnesses against an anchor, generates the Halo 2 proof, and returns canonical PCZT bytes as hex. The spend inputs are notes found by a previous scan; the fee is chosen by the caller and validated against ZIP-317.
63
+ 2. **Parse** — `parsePczt` decodes those bytes into the structured `PcztTransaction` the device signer consumes. The PCZT postcard format is not trivially parseable in TypeScript, which is why this exists.
64
+ 3. **Sign** — `signPcztTransaction` from [`@ledgerhq/device-signer-kit-zcash`](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/packages/signer/signer-zcash) streams the PCZT to the device over APDUs and returns one RedPallas `spendAuthSig` per _real_ shielded spend, plus one secp256k1 signature per transparent input. Dummy padding spends are not signed on device; they are self-signed host-side, which is why the counts line up with the unsigned actions this package expects back.
65
+ 4. **Finalize** — `finalizeTransaction` injects those signatures, computes the binding signature host-side, and extracts the signed V5 (ZIP-225) or V6 (ZIP-230) transaction.
66
+ 5. **Broadcast** — `broadcastTransaction` submits it and returns the txid.
67
+
68
+ ```typescript
69
+ import {
70
+ buildTransaction,
71
+ parsePczt,
72
+ finalizeTransaction,
73
+ broadcastTransaction,
74
+ type PcztTransaction,
75
+ type ShieldedNote,
76
+ } from "@ledgerhq/zcash-utils";
77
+
78
+ // A note found by a previous scan — its spending fields are what make it
79
+ // spendable (see Quick start above).
80
+ declare const note: ShieldedNote;
81
+
82
+ // Your wrapper around the signer kit's device action. It answers in bytes —
83
+ // `{ orchard: [{ spendAuthSig }], ironwood: [...], transparentInputSigs: [] }`
84
+ // — so hex-encoding the result is the caller's step. See the signer kit's own
85
+ // documentation for its exact shape.
86
+ declare function signOnDevice(pczt: PcztTransaction): Promise<{
87
+ orchardSignatures: string[];
88
+ transparentSignatures: string[];
89
+ }>;
90
+
91
+ const { pcztHex } = await buildTransaction({
92
+ grpcUrl,
93
+ // Required by any flow carrying an Orchard bundle. A fully transparent send
94
+ // omits it and passes `transparentAccountPubkey` instead — spending public
95
+ // funds must not require a viewing-key export from the device.
96
+ ufvk: "uviewtest1...",
97
+ network: "testnet",
98
+ // Both read from the device: they let it confirm the PCZT is its own seed's.
99
+ seedFingerprint: "<64-char hex>",
100
+ accountIndex: 0,
101
+ // Caller-owned, decimal zatoshis. Validated against ZIP-317, and change is
102
+ // derived from it — this crate does not compute a fee.
103
+ feeZat: "15000",
104
+ spends: [
105
+ {
106
+ recipient: note.recipient!, // 86-char hex
107
+ valueZat: String(note.amount),
108
+ rho: note.rho!, // 64-char hex
109
+ rseed: note.rseed!, // 64-char hex
110
+ cmx: note.cmx!, // 64-char hex
111
+ position: note.position!, // decimal u64 string
112
+ },
113
+ ],
114
+ // Always present, empty for a shielded-only send.
115
+ transparentInputs: [],
116
+ outputs: [{ address: "u1...", valueZat: "85000", memo: "thanks!" }],
117
+ });
118
+
119
+ const { orchardSignatures, transparentSignatures } = await signOnDevice(parsePczt(pcztHex));
120
+
121
+ const { txHex, txid } = await finalizeTransaction({
122
+ pczt: pcztHex,
123
+ orchardSignatures, // one 128-hex-char RedPallas sig per real Orchard spend
124
+ // Supply the list matching the PCZT's shielded bundle; the other may be
125
+ // empty or omitted. Each is length-checked against the PCZT's unsigned
126
+ // actions, so signatures for a pool the PCZT does not spend fail closed.
127
+ ironwoodSignatures: [],
128
+ transparentSignatures, // one DER-hex secp256k1 sig per transparent input
129
+ });
130
+
131
+ await broadcastTransaction(grpcUrl, txHex);
132
+ ```
133
+
134
+ Only t-addresses (P2PKH/P2SH) and u-addresses with an Orchard receiver are accepted as destinations. Sapling z-addresses and TEX (ZIP-320) addresses are rejected.
135
+
40
136
  ## API
41
137
 
42
- ### `startSync(params: SyncParams): Promise<TransactionStream>`
138
+ Full signatures, every field, and its constraints are in [`index.d.ts`](index.d.ts), generated by napi-rs from the Rust doc comments — that file is the reference, not this table.
43
139
 
44
- Starts scanning a range of compact blocks and returns a transaction stream. The scan runs in the background immediately in Rust — no JS event loop blocking. `GetTransaction` is called only for matched transactions.
140
+ ### Chain queries
45
141
 
46
- ### `getChainTip(grpcUrl: string): Promise<number>`
142
+ | Export | Purpose |
143
+ | --- | --- |
144
+ | `getChainTip(grpcUrl)` | Current chain tip height. |
145
+ | `findBlockHeight(grpcUrl, timestamp)` | Height of the latest block at or before a Unix timestamp, by interpolation search. Clamps to genesis / tip. |
47
146
 
48
- Returns the current chain tip height from the gRPC endpoint.
147
+ ### Scanning
49
148
 
50
- ### `TransactionStream`
149
+ | Export | Purpose |
150
+ | --- | --- |
151
+ | `startSync(params)` | Starts scanning a block range in the background and returns a `TransactionStream`. Trial decryption runs entirely in Rust; `GetTransaction` is called only for matched transactions. |
152
+ | `TransactionStream` | Async iterator: `next()` yields the next match or `null` at end of scan, `cancel()` aborts the background task, `stats()` returns scan statistics once exhausted. |
153
+ | `transactionDetails(grpcUrl, requests, network?, ufvk?)` | Reads from raw transaction bytes what an explorer cannot: the true cross-pool fee, and — with a `ufvk` — the payees of shielded outputs. A transaction that cannot be fetched, parsed, or fully priced yields a `null` fee rather than an approximation. |
51
154
 
52
- Async iterator over matched shielded transactions.
155
+ ### Sending
53
156
 
54
- | Method | Description |
55
- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------- |
56
- | `next(): Promise<ShieldedTransaction \| null>` | Returns the next matched transaction, or `null` when the scan is complete. |
57
- | `cancel(): void` | Cancels the background scan immediately. Buffered transactions are still consumable via `next()`. |
58
- | `stats(): Promise<SyncStats>` | Returns scan statistics once the stream is exhausted. |
157
+ | Export | Purpose |
158
+ | --- | --- |
159
+ | `buildTransaction(params)` | Builds, proves, and serializes a V5 PCZT from Orchard notes, transparent UTXOs, or both. Bears the Halo 2 proving cost inline (~2–5 s cold, ~hundreds of ms after, via a process-global proving-key cache). |
160
+ | `buildIronwoodTransaction(params)` | Same, for an Ironwood (NU6.3) source — a redacted V6 PCZT. See the status note below. |
161
+ | `parsePczt(pcztHex)` | Decodes canonical PCZT bytes into the `PcztTransaction` the device signer consumes. Fails if a field the device needs to sign is missing. |
162
+ | `finalizeTransaction(params)` | Injects device signatures, computes the binding signature, extracts the signed transaction and its txid. CPU-bound (proof verification), dispatched to a blocking thread. |
163
+ | `broadcastTransaction(grpcUrl, txHex)` | Submits a signed transaction to a lightwalletd / Zaino endpoint; returns the txid. |
59
164
 
60
- ## Types
165
+ ### Receiving
61
166
 
62
- ### `SyncParams`
167
+ | Export | Purpose |
168
+ | --- | --- |
169
+ | `orchardAddressFromUfvk(ufvk)` | The Orchard-only unified address, derived exactly as the device derives it (external scope, diversifier index 0, single receiver) — so it passes on-device verification. Use this for the Receive flow. |
63
170
 
64
- ```typescript
65
- interface SyncParams {
66
- /** gRPC endpoint URL */
67
- grpcUrl: string;
68
- /** Unified Full Viewing Key (UFVK) for the account to scan */
69
- viewingKey: string;
70
- /** First block height to scan (inclusive) */
71
- startHeight: number;
72
- /** Last block height to scan (inclusive) */
73
- endHeight: number;
74
- /** "mainnet" or "testnet" (default: "testnet") */
75
- network?: string;
76
- /**
77
- * When true, only Orchard actions are processed — eliminates all Sapling
78
- * crypto work. Set to true for Ledger wallets (Orchard-only support).
79
- */
80
- orchardOnly?: boolean;
81
- /**
82
- * Maximum retry attempts per range on transient errors.
83
- * The failing range is split in half on each retry. Defaults to 3.
84
- */
85
- maxRetries?: number;
86
- /** Emit per-phase timing diagnostics to stderr every 10 seconds */
87
- verbose?: boolean;
88
- }
89
- ```
171
+ Key derivation is deliberately **not** exported here: it lives in the `zcash-crypto` crate and the `ledger-zcash-cli` binary. A wallet gets its keys from the device.
90
172
 
91
- ### `ShieldedTransaction`
173
+ ## Value encoding
92
174
 
93
- ```typescript
94
- interface ShieldedTransaction {
95
- txid: string; // Transaction ID (big-endian hex)
96
- hex: string; // Raw transaction bytes (hex)
97
- blockHeight: number;
98
- blockHash: string; // Block hash (big-endian hex)
99
- blockTime: number; // Unix timestamp (seconds)
100
- fee: number; // Fee in zatoshis
101
- saplingNotes: ShieldedNote[];
102
- orchardNotes: ShieldedNote[];
103
- ironwoodNotes: ShieldedNote[]; // Ironwood (NU6.3) pool notes
104
- }
105
- ```
175
+ The same quantity is not spelled the same way everywhere in this API. Read this before wiring anything up.
106
176
 
107
- ### `ShieldedNote`
177
+ **Zatoshi amounts.** The scanning path returns them as JS numbers (`ShieldedNote.amount`, `ShieldedTransaction.fee`, `transparentOut`). Every crafting and PCZT field instead uses a **decimal string** (`valueZat`, `feeZat`, `value`, `spendValue`, `valueBalance`), which avoids the precision loss of a `u64`/`i128` round-tripping through an f64.
108
178
 
109
- ```typescript
110
- interface ShieldedNote {
111
- amount: number; // Amount in zatoshis
112
- transferType: string; // "incoming", "outgoing", or "internal"
113
- memo: string;
114
- pool: string; // "sapling", "orchard", or "ironwood" — the shielded pool this note belongs to
115
- }
116
- ```
179
+ **Txid byte order.** Three fields, three conventions:
117
180
 
118
- ### `SyncStats`
181
+ | Field | Order |
182
+ | --- | --- |
183
+ | `ShieldedTransaction.txid`, `FinalizeTransactionResult.txid`, `TransactionDetailsRequest.txid`, `TransparentPrevout.txid` | Big-endian _display_ order — matches explorers and the Ledger Live operation hash. |
184
+ | `TransparentInputJs.txid` | Little-endian _internal_ order. Ledger Live surfaces txids in display order, so callers must reverse before passing. |
185
+ | `PcztTransparentInput.prevoutTxid` | Internal byte order, as stored in the PCZT. |
119
186
 
120
- ```typescript
121
- interface SyncStats {
122
- blocksScanned: number;
123
- elapsedMs: number;
124
- }
125
- ```
187
+ **`scriptPubKey`** keeps its canonical Bitcoin/Zcash casing, rather than napi's default camelCasing of the Rust field name (`scriptPubkey`).
188
+
189
+ ## Ironwood (NU6.3) status
190
+
191
+ `buildIronwoodTransaction` is exposed so the JS side can be wired up in parallel, but Rust-side Ironwood crafting is still a dry run: the wallet-side crates it depends on (`pczt`, `zcash_client_backend`) are release candidates for NU6.3. Those pins are re-confirmed and bumped to the stable releases before the mainnet build cut. See [`docs/architecture.md`](docs/architecture.md).
192
+
193
+ Ironwood notes on the scanning path are complete and not gated by `orchardOnly`: `ShieldedTransaction.ironwoodNotes` is populated alongside `orchardNotes`, and `ShieldedNote.pool` distinguishes them.
194
+
195
+ ## Documentation
196
+
197
+ - [`docs/architecture.md`](docs/architecture.md) — crate layout, dependency graph, design decisions
198
+ - [`docs/key-derivation.md`](docs/key-derivation.md) — BIP-39 → ZIP-32 → UFVK pipeline
199
+ - [`docs/block-sync.md`](docs/block-sync.md) — gRPC trial + full decryption
200
+ - [`docs/ffi-node.md`](docs/ffi-node.md) — this addon in depth, with worked examples
201
+ - [`docs/build-targets.md`](docs/build-targets.md) — build scripts and prerequisites
202
+ - [`CONTRIBUTING.md`](CONTRIBUTING.md) — building, testing, CLI usage, release process
126
203
 
127
204
  ## License
128
205
 
129
- MIT OR Apache-2.0
206
+ [Apache-2.0](LICENSE.md), as the rest of the Ledger device stack.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/zcash-utils",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Native Zcash key derivation and shielded sync — Node.js (NAPI)",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,10 +21,11 @@
21
21
  "@changesets/cli": "^2.29.8",
22
22
  "@napi-rs/cli": "^2.18.0",
23
23
  "@types/node": "^25.5.2",
24
+ "prettier": "^3.9.6",
24
25
  "tsx": "^4.21.0",
25
26
  "typescript": "^6.0.2"
26
27
  },
27
- "license": "MIT",
28
+ "license": "Apache-2.0",
28
29
  "scripts": {
29
30
  "// ── NAPI (Node.js / Electron) ──────────────────────────────────────": "",
30
31
  "build": "./scripts/build-napi.sh",
@@ -40,6 +41,9 @@
40
41
  "// ── Coverage ───────────────────────────────────────────────────────": "",
41
42
  "coverage": "./scripts/coverage.sh",
42
43
  "coverage:open": "OPEN_REPORT=1 ./scripts/coverage.sh",
44
+ "// ── Formatting ─────────────────────────────────────────────────────": "",
45
+ "format": "prettier --write \"**/*.md\"",
46
+ "format:check": "prettier --check \"**/*.md\"",
43
47
  "// ── Rustdoc ────────────────────────────────────────────────────────": "",
44
48
  "doc": "cargo doc --workspace --no-deps",
45
49
  "doc:open": "cargo doc --workspace --no-deps --open",