@ocash/sdk 0.1.4-rc.2 → 0.1.4-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -7295,7 +7295,7 @@ var MerkleEngine = class _MerkleEngine {
7295
7295
  const isZero = BigInt(onChainNorm) === 0n;
7296
7296
  if (!isZero && onChainNorm !== result.rootHash) {
7297
7297
  const target = state.mergedElements;
7298
- await this.rollback(chainId, target);
7298
+ await this._rollback(chainId, target);
7299
7299
  throw new SdkError("MERKLE", "Local merkle root mismatch with on-chain root \u2014 rolled back", {
7300
7300
  chainId,
7301
7301
  rootIndex,
@@ -7328,21 +7328,31 @@ var MerkleEngine = class _MerkleEngine {
7328
7328
  }
7329
7329
  // ── Rollback (tree O(1) + sync cursor reset) ──
7330
7330
  /**
7331
- * Unified rollback: rewind tree to a previous batch boundary AND reset the
7332
- * sync cursor so memo sync restarts from the same point.
7331
+ * Public rollback: step back one batch (32 elements) from the current position.
7332
+ * Upper-layer code calls this on any error to reset and retry.
7333
7333
  *
7334
7334
  * What gets rolled back:
7335
7335
  * - ChairmanMerkle tree version pointer (O(1) — old nodes still in storage)
7336
7336
  * - Pending leaves buffer (cleared)
7337
7337
  * - Sync cursor: memo + merkle fields (nullifier left unchanged — independent)
7338
7338
  *
7339
+ * @returns true if rollback succeeded, false if already at 0 or target version doesn't exist.
7340
+ */
7341
+ async rollback(chainId) {
7342
+ const state = this.ensureChainState(chainId);
7343
+ const target = Math.max(0, state.mergedElements - SUBTREE_SIZE);
7344
+ return this._rollback(chainId, target);
7345
+ }
7346
+ /**
7347
+ * Internal rollback to an exact batch boundary.
7348
+ *
7339
7349
  * @param targetMergedElements Must be a non-negative multiple of 32.
7340
7350
  * Pass 0 to reset to the empty tree.
7341
7351
  * @returns true if rollback succeeded, false if the target version doesn't exist.
7342
7352
  */
7343
- async rollback(chainId, targetMergedElements) {
7353
+ async _rollback(chainId, targetMergedElements) {
7344
7354
  if (targetMergedElements < 0 || targetMergedElements % SUBTREE_SIZE !== 0) {
7345
- throw new SdkError("MERKLE", "rollback target must be a non-negative multiple of 32", { targetMergedElements });
7355
+ throw new SdkError("MERKLE", "_rollback target must be a non-negative multiple of 32", { targetMergedElements });
7346
7356
  }
7347
7357
  const state = this.ensureChainState(chainId);
7348
7358
  const pending = this.ensurePendingLeaves(chainId);