@ledgerhq/zcash-utils 0.1.5 → 0.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/index.d.ts CHANGED
@@ -33,8 +33,20 @@ export interface SyncParams {
33
33
  maxRetries?: number
34
34
  /** Emit per-phase timing diagnostics to stderr every 10 seconds. */
35
35
  verbose?: boolean
36
+ /**
37
+ * Hex-encoded nullifiers of notes received in previous scans that are still
38
+ * unspent. Enables spent detection across incremental sync boundaries.
39
+ */
40
+ knownNullifiers?: Array<string>
36
41
  }
37
- /** A single shielded note found during decryption. */
42
+ /**
43
+ * A single shielded note found during decryption.
44
+ *
45
+ * Shared between Orchard and Sapling. The spending fields (`nullifier`,
46
+ * `rseed`, `cmx`, `position`, `recipient`) are Orchard-specific and `None`
47
+ * for Sapling notes. A dedicated Sapling type is deferred until Sapling
48
+ * spending is needed.
49
+ */
38
50
  export interface ShieldedNote {
39
51
  /** Amount in zatoshis (f64 for JS Number compatibility). */
40
52
  amount: number
@@ -42,6 +54,24 @@ export interface ShieldedNote {
42
54
  transferType: string
43
55
  /** Memo text decoded from the note. */
44
56
  memo: string
57
+ /** Orchard nullifier (64-char hex = 32 bytes). Used for spent detection and PCZT. */
58
+ nullifier?: string
59
+ /** rho value (64-char hex = 32 bytes). Required with rseed for Note::from_parts. */
60
+ rho?: string
61
+ /** Random seed (64-char hex = 32 bytes). Required for spending. */
62
+ rseed?: string
63
+ /** Extracted note commitment cmx (64-char hex = 32 bytes). Required for Merkle witness. */
64
+ cmx?: string
65
+ /**
66
+ * Leaf position in the Orchard commitment tree (decimal string).
67
+ * None when ChainMetadata is absent.
68
+ * String avoids f64 precision loss on u64 -> f64 -> u64 round-trips.
69
+ */
70
+ position?: string
71
+ /** Recipient bytes (86-char hex = 43 bytes: 11-byte d + 32-byte pk_d). For note reconstruction. */
72
+ recipient?: string
73
+ /** True if this note was spent in a later block within the scanned range. */
74
+ isSpent: boolean
45
75
  }
46
76
  /** A matched and fully-decrypted shielded transaction. */
47
77
  export interface ShieldedTransaction {
@@ -66,6 +96,11 @@ export interface ShieldedTransaction {
66
96
  export interface SyncStats {
67
97
  blocksScanned: number
68
98
  elapsedMs: number
99
+ /**
100
+ * Hex-encoded nullifiers from `knownNullifiers` that were spent in the scanned range.
101
+ * JS uses this to mark previously-stored notes as spent.
102
+ */
103
+ spentKnownNullifiers: Array<string>
69
104
  }
70
105
  /**
71
106
  * Start scanning a range of compact blocks and return a transaction stream.
@@ -80,6 +115,14 @@ export interface SyncStats {
80
115
  export declare function startSync(params: SyncParams): Promise<TransactionStream>
81
116
  /** Returns the current chain tip height from the gRPC endpoint. */
82
117
  export declare function getChainTip(grpcUrl: string): Promise<number>
118
+ /**
119
+ * Find the block height closest to the given Unix timestamp via interpolation search.
120
+ *
121
+ * Returns the height of the latest block whose timestamp is ≤ the target.
122
+ * If the timestamp is before genesis, returns the genesis height.
123
+ * If the timestamp is after the chain tip, returns the tip height.
124
+ */
125
+ export declare function findBlockHeight(grpcUrl: string, timestamp: number): Promise<number>
83
126
  /**
84
127
  * Async iterator over matched shielded transactions.
85
128
  *
@@ -97,7 +140,9 @@ export declare class TransactionStream {
97
140
  /**
98
141
  * Returns the next matched transaction, or `null` when the scan is complete.
99
142
  *
100
- * Safety: napi-rs requires `unsafe` for `&mut self` in async methods.
143
+ * # Safety
144
+ *
145
+ * napi-rs requires `unsafe` for `&mut self` in async methods.
101
146
  * This method is safe to call — it only mutates the internal channel receiver.
102
147
  */
103
148
  next(): Promise<ShieldedTransaction | null>
@@ -115,7 +160,9 @@ export declare class TransactionStream {
115
160
  * returns `null`). Calling this before the stream is done will wait until
116
161
  * the background sync task finishes.
117
162
  *
118
- * Safety: napi-rs requires `unsafe` for `&mut self` in async methods.
163
+ * # Safety
164
+ *
165
+ * napi-rs requires `unsafe` for `&mut self` in async methods.
119
166
  */
120
167
  stats(): Promise<SyncStats>
121
168
  }
Binary file
Binary file
package/index.js CHANGED
@@ -310,8 +310,9 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { TransactionStream, startSync, getChainTip } = nativeBinding
313
+ const { TransactionStream, startSync, getChainTip, findBlockHeight } = nativeBinding
314
314
 
315
315
  module.exports.TransactionStream = TransactionStream
316
316
  module.exports.startSync = startSync
317
317
  module.exports.getChainTip = getChainTip
318
+ module.exports.findBlockHeight = findBlockHeight
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": "0.1.5",
3
+ "version": "0.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",
@@ -47,6 +47,7 @@
47
47
  "cli": "cargo run -q -p zcash-cli",
48
48
  "cli:derive": "cargo run -q -p zcash-cli -- derive --help",
49
49
  "cli:tip": "cargo run -q -p zcash-cli -- tip --help",
50
+ "cli:height-at": "cargo run -q -p zcash-cli -- height-at --help",
50
51
  "cli:sync": "cargo run -q -p zcash-cli -- sync --help",
51
52
  "// ── Node.js validation & benchmarks ───────────────────────────────": "",
52
53
  "sync-tx": "tsx examples/sync-tx.node.ts --start-height 1130000 --end-height 1180000",