@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/index.cjs CHANGED
@@ -7362,7 +7362,7 @@ var MerkleEngine = class _MerkleEngine {
7362
7362
  const isZero = BigInt(onChainNorm) === 0n;
7363
7363
  if (!isZero && onChainNorm !== result.rootHash) {
7364
7364
  const target = state.mergedElements;
7365
- await this.rollback(chainId, target);
7365
+ await this._rollback(chainId, target);
7366
7366
  throw new SdkError("MERKLE", "Local merkle root mismatch with on-chain root \u2014 rolled back", {
7367
7367
  chainId,
7368
7368
  rootIndex,
@@ -7395,21 +7395,31 @@ var MerkleEngine = class _MerkleEngine {
7395
7395
  }
7396
7396
  // ── Rollback (tree O(1) + sync cursor reset) ──
7397
7397
  /**
7398
- * Unified rollback: rewind tree to a previous batch boundary AND reset the
7399
- * sync cursor so memo sync restarts from the same point.
7398
+ * Public rollback: step back one batch (32 elements) from the current position.
7399
+ * Upper-layer code calls this on any error to reset and retry.
7400
7400
  *
7401
7401
  * What gets rolled back:
7402
7402
  * - ChairmanMerkle tree version pointer (O(1) — old nodes still in storage)
7403
7403
  * - Pending leaves buffer (cleared)
7404
7404
  * - Sync cursor: memo + merkle fields (nullifier left unchanged — independent)
7405
7405
  *
7406
+ * @returns true if rollback succeeded, false if already at 0 or target version doesn't exist.
7407
+ */
7408
+ async rollback(chainId) {
7409
+ const state = this.ensureChainState(chainId);
7410
+ const target = Math.max(0, state.mergedElements - SUBTREE_SIZE);
7411
+ return this._rollback(chainId, target);
7412
+ }
7413
+ /**
7414
+ * Internal rollback to an exact batch boundary.
7415
+ *
7406
7416
  * @param targetMergedElements Must be a non-negative multiple of 32.
7407
7417
  * Pass 0 to reset to the empty tree.
7408
7418
  * @returns true if rollback succeeded, false if the target version doesn't exist.
7409
7419
  */
7410
- async rollback(chainId, targetMergedElements) {
7420
+ async _rollback(chainId, targetMergedElements) {
7411
7421
  if (targetMergedElements < 0 || targetMergedElements % SUBTREE_SIZE !== 0) {
7412
- throw new SdkError("MERKLE", "rollback target must be a non-negative multiple of 32", { targetMergedElements });
7422
+ throw new SdkError("MERKLE", "_rollback target must be a non-negative multiple of 32", { targetMergedElements });
7413
7423
  }
7414
7424
  const state = this.ensureChainState(chainId);
7415
7425
  const pending = this.ensurePendingLeaves(chainId);