@dorafactory/maci-sdk 0.1.3-pre.36 → 0.1.3-pre.38

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.js CHANGED
@@ -913,6 +913,58 @@ var Tree = class _Tree {
913
913
  idx = parentIdx;
914
914
  }
915
915
  }
916
+ /**
917
+ * Compute zero hashes for a tree with given parameters
918
+ * This is a static utility that can be used without creating a Tree instance
919
+ *
920
+ * @param degree - The branching factor of the tree
921
+ * @param maxDepth - Maximum depth to compute zero hashes for
922
+ * @param zero - The zero value at leaf level
923
+ * @returns Array of zero hashes where zeroHashes[i] is the hash of a completely empty subtree of depth i
924
+ */
925
+ static computeZeroHashes(degree, maxDepth, zero) {
926
+ const zeroHashes = new Array(maxDepth + 1);
927
+ zeroHashes[0] = zero;
928
+ for (let i = 1; i <= maxDepth; i++) {
929
+ const children = new Array(degree).fill(zeroHashes[i - 1]);
930
+ zeroHashes[i] = poseidon(children);
931
+ }
932
+ return zeroHashes;
933
+ }
934
+ /**
935
+ * Extend a tree root from a smaller depth to a larger depth
936
+ * This is much more efficient than rebuilding the entire larger tree
937
+ * when you know that all additional leaves are zero.
938
+ *
939
+ * Example: If you have a tree of depth 3 with 5^3=125 real leaves,
940
+ * and you want to extend it to depth 5 (5^5=3125 capacity), where
941
+ * the additional 3000 leaves are all zeros, this function computes
942
+ * the new root in O(k) time instead of O(5^5).
943
+ *
944
+ * @param smallRoot - Root hash of the smaller tree (depth=fromDepth)
945
+ * @param fromDepth - Original tree depth
946
+ * @param toDepth - Target tree depth (must be > fromDepth)
947
+ * @param zeroHashes - Precomputed zero hashes (from computeZeroHashes or Tree.zeros)
948
+ * @param degree - Tree branching factor (default: 5)
949
+ * @returns Root hash of the extended tree
950
+ */
951
+ static extendTreeRoot(smallRoot, fromDepth, toDepth, zeroHashes, degree = 5) {
952
+ if (toDepth <= fromDepth) {
953
+ throw new Error("toDepth must be greater than fromDepth");
954
+ }
955
+ if (zeroHashes.length <= toDepth) {
956
+ throw new Error("zeroHashes array is too short for target depth");
957
+ }
958
+ let currentRoot = smallRoot;
959
+ for (let level = fromDepth; level < toDepth; level++) {
960
+ const siblings = [currentRoot];
961
+ for (let i = 1; i < degree; i++) {
962
+ siblings.push(zeroHashes[level]);
963
+ }
964
+ currentRoot = poseidon(siblings);
965
+ }
966
+ return currentRoot;
967
+ }
916
968
  };
917
969
 
918
970
  // src/libs/crypto/babyjub.ts
@@ -9084,7 +9136,7 @@ var MaciClient2 = class {
9084
9136
  this.rpcEndpoint = rpcEndpoint || defaultParams.rpcEndpoint;
9085
9137
  this.restEndpoint = restEndpoint || defaultParams.restEndpoint;
9086
9138
  this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
9087
- this.saasApiEndpoint = saasApiEndpoint;
9139
+ this.saasApiEndpoint = saasApiEndpoint || defaultParams.saasApiEndpoint;
9088
9140
  this.certificateApiEndpoint = certificateApiEndpoint || defaultParams.certificateApiEndpoint;
9089
9141
  this.registryAddress = registryAddress || defaultParams.registryAddress;
9090
9142
  this.saasAddress = saasAddress || defaultParams.saasAddress;