@hinkal/common 0.0.113 → 0.0.115
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/assets/{snarkjsWorkerLauncher-fuD5h_j0.js → snarkjsWorkerLauncher-CaBCnle3.js} +283 -257
- package/assets/snarkjsWorkerLogic-BAbiO5gj.js +17935 -0
- package/assets/snarkjsWorkerLogic-wHJfYCfg.js +15636 -0
- package/assets/{utxoWorkerLogic-CtFLQiAX.js → utxoWorkerLogic-BGFm-Zl2.js} +2 -2
- package/assets/{zkProofWorkerLauncher-J3Ts5_Ba.js → zkProofWorkerLauncher-BteYxRBn.js} +1 -1
- package/assets/{zkProofWorkerLogic-CPNuu61R.js → zkProofWorkerLogic-DiLbAhAo.js} +8354 -8298
- package/common.mjs +644 -0
- package/common10.mjs +30 -0
- package/common100.mjs +156 -0
- package/common101.mjs +568 -0
- package/common102.mjs +1603 -0
- package/common103.mjs +1764 -0
- package/common104.mjs +2030 -0
- package/common105.mjs +701 -0
- package/common106.mjs +480 -0
- package/common107.mjs +2082 -0
- package/common108.mjs +39 -0
- package/common109.mjs +24 -0
- package/common11.mjs +30 -0
- package/common110.mjs +41 -0
- package/common111.mjs +206 -0
- package/common112.mjs +48 -0
- package/common113.mjs +39 -0
- package/common114.mjs +70 -0
- package/common115.mjs +67 -0
- package/common116.mjs +5 -0
- package/common117.mjs +61 -0
- package/common118.mjs +20 -0
- package/common119.mjs +7 -0
- package/common12.mjs +58 -0
- package/common120.mjs +22 -0
- package/common121.mjs +16 -0
- package/common122.mjs +57 -0
- package/common123.mjs +45 -0
- package/common124.mjs +57 -0
- package/common125.mjs +229 -0
- package/common126.mjs +203 -0
- package/common127.mjs +29 -0
- package/common128.mjs +38 -0
- package/common129.mjs +15 -0
- package/common13.mjs +156 -0
- package/common130.mjs +105 -0
- package/common131.mjs +4 -0
- package/common132.mjs +14 -0
- package/common133.mjs +7 -0
- package/common134.mjs +6 -0
- package/common135.mjs +8 -0
- package/common136.mjs +40 -0
- package/common137.mjs +41 -0
- package/common138.mjs +72 -0
- package/common139.mjs +107 -0
- package/common14.mjs +32 -0
- package/common140.mjs +9 -0
- package/common141.mjs +10 -0
- package/common142.mjs +97 -0
- package/common143.mjs +65 -0
- package/common144.mjs +61 -0
- package/common145.mjs +95 -0
- package/common146.mjs +129 -0
- package/common147.mjs +105 -0
- package/common148.mjs +96 -0
- package/common149.mjs +18 -0
- package/common15.mjs +16 -0
- package/common150.mjs +45 -0
- package/common151.mjs +41 -0
- package/common152.mjs +108 -0
- package/common153.mjs +40 -0
- package/common154.mjs +19 -0
- package/common155.mjs +24 -0
- package/common156.mjs +21 -0
- package/common157.mjs +22 -0
- package/common158.mjs +4 -0
- package/common159.mjs +4 -0
- package/common16.mjs +6 -0
- package/common160.mjs +15 -0
- package/common161.mjs +13 -0
- package/common162.mjs +4 -0
- package/common163.mjs +15 -0
- package/common164.mjs +36 -0
- package/common165.mjs +58 -0
- package/common166.mjs +27 -0
- package/common167.mjs +15 -0
- package/common168.mjs +25 -0
- package/common169.mjs +4 -0
- package/common17.mjs +6877 -0
- package/common170.mjs +85 -0
- package/common171.mjs +2251 -0
- package/common172.mjs +856 -0
- package/common173.mjs +973 -0
- package/common174.mjs +1255 -0
- package/common175.mjs +591 -0
- package/common176.mjs +1392 -0
- package/common177.mjs +463 -0
- package/common178.mjs +137 -0
- package/common179.mjs +2700 -0
- package/common18.mjs +7415 -0
- package/common180.mjs +946 -0
- package/common181.mjs +973 -0
- package/common182.mjs +1327 -0
- package/common183.mjs +591 -0
- package/common184.mjs +1455 -0
- package/common185.mjs +490 -0
- package/common186.mjs +137 -0
- package/common187.mjs +2768 -0
- package/common188.mjs +8 -0
- package/common189.mjs +14 -0
- package/common19.mjs +11427 -0
- package/common190.mjs +115623 -0
- package/common191.mjs +42 -0
- package/common192.mjs +1022 -0
- package/common193.mjs +1423 -0
- package/common194.mjs +208 -0
- package/common195.mjs +340 -0
- package/common196.mjs +674 -0
- package/common197.mjs +1002 -0
- package/common198.mjs +883 -0
- package/common199.mjs +262 -0
- package/common2.mjs +67 -0
- package/common20.mjs +7417 -0
- package/common200.mjs +264 -0
- package/common201.mjs +173 -0
- package/common202.mjs +999 -0
- package/common203.mjs +80 -0
- package/common204.mjs +56 -0
- package/common205.mjs +42 -0
- package/common206.mjs +14 -0
- package/common207.mjs +4 -0
- package/common208.mjs +62 -0
- package/common209.mjs +4 -0
- package/common21.mjs +7439 -0
- package/common210.mjs +4 -0
- package/common211.mjs +58 -0
- package/common212.mjs +40 -0
- package/common213.mjs +45 -0
- package/common214.mjs +36 -0
- package/common215.mjs +32 -0
- package/common216.mjs +44 -0
- package/common217.mjs +32 -0
- package/common218.mjs +38 -0
- package/common219.mjs +9 -0
- package/common22.mjs +7411 -0
- package/common220.mjs +32 -0
- package/common221.mjs +47 -0
- package/common222.mjs +14 -0
- package/common223.mjs +30 -0
- package/common224.mjs +91 -0
- package/common225.mjs +112 -0
- package/common226.mjs +96 -0
- package/common227.mjs +30 -0
- package/common228.mjs +138 -0
- package/common229.mjs +18 -0
- package/common23.mjs +8425 -0
- package/common230.mjs +42 -0
- package/common231.mjs +60 -0
- package/common232.mjs +48 -0
- package/common233.mjs +47 -0
- package/common234.mjs +44 -0
- package/common235.mjs +74 -0
- package/common236.mjs +4 -0
- package/common237.mjs +60 -0
- package/common238.mjs +4 -0
- package/common239.mjs +30 -0
- package/common24.mjs +9600 -0
- package/common240.mjs +4 -0
- package/common241.mjs +153 -0
- package/common242.mjs +31 -0
- package/common243.mjs +30 -0
- package/common244.mjs +68 -0
- package/common245.mjs +57 -0
- package/common246.mjs +97 -0
- package/common247.mjs +36 -0
- package/common248.mjs +43 -0
- package/common249.mjs +44 -0
- package/common25.mjs +13283 -0
- package/common250.mjs +59 -0
- package/common251.mjs +75 -0
- package/{snarkjsWorkerLogic-CVna_BW9.mjs → common252.mjs} +1 -1
- package/common253.mjs +66 -0
- package/common254.mjs +70 -0
- package/common255.mjs +211 -0
- package/common256.mjs +8 -0
- package/{workerProxy-BDj498Ht.mjs → common257.mjs} +1 -1
- package/common26.mjs +4329 -0
- package/common27.mjs +4329 -0
- package/common28.mjs +204 -0
- package/common29.mjs +57 -0
- package/common3.mjs +27 -0
- package/common30.mjs +276 -0
- package/common31.mjs +118 -0
- package/common32.mjs +157 -0
- package/common33.mjs +29 -0
- package/common34.mjs +26 -0
- package/common35.mjs +53 -0
- package/common36.mjs +55 -0
- package/common37.mjs +18 -0
- package/common38.mjs +636 -0
- package/common39.mjs +24 -0
- package/common4.mjs +37 -0
- package/common40.mjs +13 -0
- package/common41.mjs +27 -0
- package/common42.mjs +15 -0
- package/common43.mjs +24 -0
- package/common44.mjs +253 -0
- package/common45.mjs +26 -0
- package/common46.mjs +15 -0
- package/common47.mjs +9 -0
- package/common48.mjs +25 -0
- package/common49.mjs +40 -0
- package/common5.mjs +37 -0
- package/common50.mjs +41 -0
- package/common51.mjs +90 -0
- package/common52.mjs +10 -0
- package/common53.mjs +299 -0
- package/common54.mjs +101 -0
- package/common55.mjs +83 -0
- package/common56.mjs +112 -0
- package/common57.mjs +140 -0
- package/common58.mjs +95 -0
- package/common59.mjs +98 -0
- package/common6.mjs +32 -0
- package/common60.mjs +5 -0
- package/common61.mjs +91 -0
- package/common62.mjs +66 -0
- package/common63.mjs +49 -0
- package/common64.mjs +177 -0
- package/common65.mjs +8 -0
- package/common66.mjs +131 -0
- package/common67.mjs +132 -0
- package/common68.mjs +59 -0
- package/common69.mjs +35 -0
- package/common7.mjs +37 -0
- package/common70.mjs +118 -0
- package/common71.mjs +134 -0
- package/common72.mjs +33 -0
- package/common73.mjs +29 -0
- package/common74.mjs +218 -0
- package/common75.mjs +194 -0
- package/common76.mjs +62 -0
- package/common77.mjs +181 -0
- package/common78.mjs +83 -0
- package/common79.mjs +9 -0
- package/common8.mjs +38 -0
- package/common80.mjs +21 -0
- package/common81.mjs +184 -0
- package/common82.mjs +53 -0
- package/common83.mjs +35 -0
- package/common84.mjs +7 -0
- package/common85.mjs +4 -0
- package/common86.mjs +350 -0
- package/common87.mjs +570 -0
- package/common88.mjs +519 -0
- package/common89.mjs +1422 -0
- package/common9.mjs +41 -0
- package/common90.mjs +1136 -0
- package/common91.mjs +334 -0
- package/common92.mjs +291 -0
- package/common93.mjs +205 -0
- package/common94.mjs +201 -0
- package/common95.mjs +89 -0
- package/common96.mjs +721 -0
- package/common97.mjs +346 -0
- package/common98.mjs +542 -0
- package/common99.mjs +393 -0
- package/package.json +4 -4
- package/assets/snarkjsWorkerLogic-B6N4z_eM.js +0 -12136
- package/assets/snarkjsWorkerLogic-Fv0M38Mc.js +0 -12087
- package/index-DXElTGy9.mjs +0 -254449
- package/index.js +0 -457
- package/utxoWorkerLogic-B1Hh-bq4.mjs +0 -64
- package/zkProofWorkerLogic-D9rxuuiK.mjs +0 -60
package/common64.mjs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import "ethers";
|
|
2
|
+
import "axios";
|
|
3
|
+
import "./common28.mjs";
|
|
4
|
+
import "./common157.mjs";
|
|
5
|
+
import "./common164.mjs";
|
|
6
|
+
import "./common168.mjs";
|
|
7
|
+
import "circomlibjs";
|
|
8
|
+
import "./common51.mjs";
|
|
9
|
+
import "./common50.mjs";
|
|
10
|
+
import "./common139.mjs";
|
|
11
|
+
import "./common191.mjs";
|
|
12
|
+
import "./common117.mjs";
|
|
13
|
+
import "./common72.mjs";
|
|
14
|
+
import "./common121.mjs";
|
|
15
|
+
import "./common35.mjs";
|
|
16
|
+
import { logError as l } from "./common84.mjs";
|
|
17
|
+
import "./common129.mjs";
|
|
18
|
+
import { MerkleTreeIncompleteError as a } from "./common65.mjs";
|
|
19
|
+
import "./common42.mjs";
|
|
20
|
+
import "./common31.mjs";
|
|
21
|
+
import "./common77.mjs";
|
|
22
|
+
import "libsodium-wrappers";
|
|
23
|
+
import "./common33.mjs";
|
|
24
|
+
import "./common30.mjs";
|
|
25
|
+
import "./common36.mjs";
|
|
26
|
+
import "./common41.mjs";
|
|
27
|
+
class o {
|
|
28
|
+
constructor(e, t, i, r, n, s) {
|
|
29
|
+
this.hashFunction = e, this.levels = t, this.defaultNodeValue = i, this.tree = r ?? /* @__PURE__ */ new Map(), this.count = s ?? 0n, this.index = n ?? 2n ** (t - 1n);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* the map where the items are stored
|
|
33
|
+
*/
|
|
34
|
+
tree;
|
|
35
|
+
/**
|
|
36
|
+
* amount of elements inserted inside the bottom row of the tree
|
|
37
|
+
*/
|
|
38
|
+
count;
|
|
39
|
+
/**
|
|
40
|
+
* the maximum index inserted into the tree
|
|
41
|
+
* used together with count to make sure that the merkle tree is complete.
|
|
42
|
+
* meaning that there aren't any missing elements between getStartIndex() and index
|
|
43
|
+
*/
|
|
44
|
+
index;
|
|
45
|
+
static createWithData(e, t, i, r, n, s) {
|
|
46
|
+
return new o(r, n, s, e, t, i);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param hashFunction the hashFunction used to fill the upper layers of the merkle tree
|
|
50
|
+
* @param levels the amount of layers in the merkle tree
|
|
51
|
+
* @param defaultNodeValue the default value of an empty node in the merkle tree
|
|
52
|
+
*/
|
|
53
|
+
static create(e, t, i) {
|
|
54
|
+
return new o(e, t, i);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* get starting nodeIndex from which inserts are allowed
|
|
58
|
+
*/
|
|
59
|
+
getStartIndex() {
|
|
60
|
+
return 2n ** (this.levels - 1n);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* implementation of logarithm2 function from merkle contract
|
|
64
|
+
*/
|
|
65
|
+
logarithm2(e) {
|
|
66
|
+
let t = 0n;
|
|
67
|
+
for (; 2n ** t < e; )
|
|
68
|
+
t += 1n;
|
|
69
|
+
return t;
|
|
70
|
+
}
|
|
71
|
+
bigIntMax(e, t) {
|
|
72
|
+
return e > t ? e : t;
|
|
73
|
+
}
|
|
74
|
+
forceInsert(e, t) {
|
|
75
|
+
if (t < this.getStartIndex())
|
|
76
|
+
throw new RangeError();
|
|
77
|
+
this.tree.set(t, e);
|
|
78
|
+
const i = this.index - this.getStartIndex(), r = this.logarithm2(i);
|
|
79
|
+
let n = t;
|
|
80
|
+
for (let s = 1n; s <= r; s += 1n) {
|
|
81
|
+
n /= 2n;
|
|
82
|
+
const h = this.hashFunction(
|
|
83
|
+
this.tree.get(n * 2n) || this.defaultNodeValue,
|
|
84
|
+
this.tree.get(n * 2n + 1n) || this.defaultNodeValue
|
|
85
|
+
);
|
|
86
|
+
this.tree.set(n, h);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* insert value into the merkle tree
|
|
91
|
+
* @param value the value to insert
|
|
92
|
+
* @param nodeIndex the index to insert the value, you can get starting index from getStartIndex()
|
|
93
|
+
* @return true - if added, false - if already exists
|
|
94
|
+
* @throws will throw RangeError if nodeIndex is less than getStartIndex()
|
|
95
|
+
*/
|
|
96
|
+
insert(e, t) {
|
|
97
|
+
let i = !1;
|
|
98
|
+
return this.tree.has(t) && (i = !0, l(`Editing commitment index: ${t} `)), i || (this.count += 1n), this.index = this.bigIntMax(this.index, t + 1n), this.forceInsert(e, t), !0;
|
|
99
|
+
}
|
|
100
|
+
remove(e) {
|
|
101
|
+
this.forceInsert(this.defaultNodeValue, e);
|
|
102
|
+
}
|
|
103
|
+
completenessCheck() {
|
|
104
|
+
if (this.count !== this.index - this.getStartIndex())
|
|
105
|
+
throw new a();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* get root hash of the merkle tree
|
|
109
|
+
* @returns the hash, if the merkle tree is empty, will return
|
|
110
|
+
* @throws will throw MerkleTreeIncompleteError if there are missing elements in the tree
|
|
111
|
+
*/
|
|
112
|
+
getRootHash() {
|
|
113
|
+
this.completenessCheck();
|
|
114
|
+
for (let e = 1n; e < 2n ** this.levels; e *= 2n)
|
|
115
|
+
if (this.tree.get(e))
|
|
116
|
+
return this.tree.get(e);
|
|
117
|
+
return this.defaultNodeValue;
|
|
118
|
+
}
|
|
119
|
+
getMerkleData() {
|
|
120
|
+
return this.completenessCheck(), new Map(this.tree);
|
|
121
|
+
}
|
|
122
|
+
getSiblingIndex(e) {
|
|
123
|
+
return e === 1n ? 1n : e % 2n === 1n ? e - 1n : e + 1n;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* get sibling hashes needed by main.circom
|
|
127
|
+
* @throws will throw MerkleTreeIncompleteError if there are missing elements in the tree
|
|
128
|
+
*/
|
|
129
|
+
getSiblingHashesForVerification(e) {
|
|
130
|
+
this.completenessCheck();
|
|
131
|
+
let t;
|
|
132
|
+
for (let r = this.getStartIndex(); r < this.getStartIndex() + this.index; r += 1n)
|
|
133
|
+
if (this.tree.get(r) === e) {
|
|
134
|
+
t = r;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (t === void 0)
|
|
138
|
+
return new Array(Number(this.levels)).fill(0n);
|
|
139
|
+
const i = [];
|
|
140
|
+
for (; t !== 0n; )
|
|
141
|
+
i.push(this.tree.get(this.getSiblingIndex(t)) || this.defaultNodeValue), t /= 2n;
|
|
142
|
+
return i;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* get item's sibling hashes side
|
|
146
|
+
* @returns sibling's indexes
|
|
147
|
+
* @throws will throw MerkleTreeIncompleteError if there are missing elements in the tree
|
|
148
|
+
*/
|
|
149
|
+
getSiblingSides(e) {
|
|
150
|
+
this.completenessCheck();
|
|
151
|
+
let t;
|
|
152
|
+
for (let r = this.getStartIndex(); r < this.getStartIndex() + this.index; r += 1n)
|
|
153
|
+
if (this.tree.get(r) === e) {
|
|
154
|
+
t = r;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (t === void 0)
|
|
158
|
+
return new Array(Number(this.levels)).fill(0n);
|
|
159
|
+
const i = [];
|
|
160
|
+
for (; t !== 0n; ) {
|
|
161
|
+
const r = t % 2n === 0n ? 0n : 1n;
|
|
162
|
+
i.push(r), t /= 2n;
|
|
163
|
+
}
|
|
164
|
+
return i;
|
|
165
|
+
}
|
|
166
|
+
toJSON() {
|
|
167
|
+
const { tree: e, count: t, index: i } = this;
|
|
168
|
+
return {
|
|
169
|
+
tree: Object.fromEntries(e),
|
|
170
|
+
count: t.toString(),
|
|
171
|
+
index: i.toString()
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
o as MerkleTree
|
|
177
|
+
};
|
package/common65.mjs
ADDED
package/common66.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import "./common28.mjs";
|
|
2
|
+
import "./common157.mjs";
|
|
3
|
+
import "./common164.mjs";
|
|
4
|
+
import "./common168.mjs";
|
|
5
|
+
import "ethers";
|
|
6
|
+
import { zeroAddress as i } from "./common34.mjs";
|
|
7
|
+
import { poseidonFunction as m } from "./common45.mjs";
|
|
8
|
+
import "./common51.mjs";
|
|
9
|
+
import { toBigInt as t } from "./common114.mjs";
|
|
10
|
+
import "axios";
|
|
11
|
+
import "./common50.mjs";
|
|
12
|
+
import "./common139.mjs";
|
|
13
|
+
import "./common191.mjs";
|
|
14
|
+
import "./common117.mjs";
|
|
15
|
+
import "./common72.mjs";
|
|
16
|
+
import "./common121.mjs";
|
|
17
|
+
import "./common35.mjs";
|
|
18
|
+
import "./common33.mjs";
|
|
19
|
+
import "./common129.mjs";
|
|
20
|
+
import "circomlibjs";
|
|
21
|
+
import { MerkleTree as o } from "./common64.mjs";
|
|
22
|
+
import { AbstractSnapshotService as c } from "./common69.mjs";
|
|
23
|
+
import "./common42.mjs";
|
|
24
|
+
import "./common31.mjs";
|
|
25
|
+
import "./common77.mjs";
|
|
26
|
+
import "libsodium-wrappers";
|
|
27
|
+
import "./common30.mjs";
|
|
28
|
+
import "./common36.mjs";
|
|
29
|
+
import "./common41.mjs";
|
|
30
|
+
class G extends c {
|
|
31
|
+
constructor(e, s, r, d) {
|
|
32
|
+
super(
|
|
33
|
+
e,
|
|
34
|
+
{
|
|
35
|
+
name: "NewAccessKeyAdded",
|
|
36
|
+
args: ["accessKey", "index", "senderAddress"]
|
|
37
|
+
},
|
|
38
|
+
s,
|
|
39
|
+
r,
|
|
40
|
+
d
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
_merkleTree;
|
|
44
|
+
_senderAddresses;
|
|
45
|
+
_senderAddressIndexMap;
|
|
46
|
+
get merkleTree() {
|
|
47
|
+
return this._merkleTree;
|
|
48
|
+
}
|
|
49
|
+
get senderAddresses() {
|
|
50
|
+
return this._senderAddresses;
|
|
51
|
+
}
|
|
52
|
+
get senderAddressIndexMap() {
|
|
53
|
+
return this._senderAddressIndexMap;
|
|
54
|
+
}
|
|
55
|
+
serializeSnapshot(e) {
|
|
56
|
+
return {
|
|
57
|
+
merkleTree: e.payload.merkleTree.toJSON(),
|
|
58
|
+
senderAddresses: Array.from(e.payload.senderAddresses),
|
|
59
|
+
latestBlockNumber: e.latestBlockNumber,
|
|
60
|
+
reserveBlockNumber: e.reserveBlockNumber,
|
|
61
|
+
senderAddressIndexMap: Array.from(e.payload.senderAddressIndexMap).map(([s, r]) => ({
|
|
62
|
+
address: s,
|
|
63
|
+
index: r
|
|
64
|
+
}))
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
deserializeSnapshot(e) {
|
|
68
|
+
let s, r;
|
|
69
|
+
if (e.latestBlockNumber && e.merkleTree) {
|
|
70
|
+
const d = new Map(
|
|
71
|
+
Object.entries(e.merkleTree.tree).map(([n, p]) => [
|
|
72
|
+
BigInt(n),
|
|
73
|
+
BigInt(p)
|
|
74
|
+
])
|
|
75
|
+
);
|
|
76
|
+
s = o.createWithData(
|
|
77
|
+
d,
|
|
78
|
+
t(e.merkleTree.index),
|
|
79
|
+
t(e.merkleTree.count),
|
|
80
|
+
m,
|
|
81
|
+
25n,
|
|
82
|
+
0n
|
|
83
|
+
);
|
|
84
|
+
} else
|
|
85
|
+
s = o.create(m, 25n, 0n);
|
|
86
|
+
return e.latestBlockNumber && e.senderAddressIndexMap ? r = new Map(
|
|
87
|
+
e.senderAddressIndexMap.map(({ address: d, index: n }) => [d, n])
|
|
88
|
+
) : r = /* @__PURE__ */ new Map(), {
|
|
89
|
+
latestBlockNumber: e.latestBlockNumber ?? 0,
|
|
90
|
+
reserveBlockNumber: e.reserveBlockNumber ?? 0,
|
|
91
|
+
payload: {
|
|
92
|
+
merkleTree: s,
|
|
93
|
+
senderAddresses: e.senderAddresses ?? [],
|
|
94
|
+
senderAddressIndexMap: r
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
acceptEvent(e, s) {
|
|
99
|
+
try {
|
|
100
|
+
return this._merkleTree.insert(e.accessKey, e.index), this._senderAddressIndexMap.set(
|
|
101
|
+
e.senderAddress,
|
|
102
|
+
Math.max(Number(e.index), this._senderAddressIndexMap.get(e.senderAddress) ?? 0)
|
|
103
|
+
), this._senderAddresses.includes(e.senderAddress) || this._senderAddresses.push(e.senderAddress), e.accessKey === 0n && e.senderAddress === i && this._merkleTree.remove(e.index), !0;
|
|
104
|
+
} catch (r) {
|
|
105
|
+
return console.error(r), !1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
mapEvent(e) {
|
|
109
|
+
const { accessKey: s, index: r, senderAddress: d } = e;
|
|
110
|
+
return {
|
|
111
|
+
accessKey: t(s),
|
|
112
|
+
index: t(r),
|
|
113
|
+
senderAddress: d
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
getSnapshotPayload() {
|
|
117
|
+
return {
|
|
118
|
+
merkleTree: this._merkleTree,
|
|
119
|
+
senderAddresses: this._senderAddresses,
|
|
120
|
+
senderAddressIndexMap: this._senderAddressIndexMap
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
populateSnapshot({
|
|
124
|
+
payload: { merkleTree: e, senderAddresses: s, senderAddressIndexMap: r }
|
|
125
|
+
}) {
|
|
126
|
+
this._merkleTree = e, this._senderAddresses = s, this._senderAddressIndexMap = r;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
G as AbstractAccessTokenSnapshotService
|
|
131
|
+
};
|
package/common67.mjs
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { poseidonFunction as o } from "./common45.mjs";
|
|
2
|
+
import "circomlibjs";
|
|
3
|
+
import { MerkleTree as p } from "./common64.mjs";
|
|
4
|
+
import { toBigInt as i } from "./common114.mjs";
|
|
5
|
+
import "ethers";
|
|
6
|
+
import "axios";
|
|
7
|
+
import "./common28.mjs";
|
|
8
|
+
import "./common157.mjs";
|
|
9
|
+
import "./common164.mjs";
|
|
10
|
+
import "./common168.mjs";
|
|
11
|
+
import "./common51.mjs";
|
|
12
|
+
import "./common139.mjs";
|
|
13
|
+
import "./common191.mjs";
|
|
14
|
+
import "./common50.mjs";
|
|
15
|
+
import "./common117.mjs";
|
|
16
|
+
import "./common35.mjs";
|
|
17
|
+
import "./common33.mjs";
|
|
18
|
+
import "libsodium-wrappers";
|
|
19
|
+
import { AbstractSnapshotService as c } from "./common69.mjs";
|
|
20
|
+
import "./common42.mjs";
|
|
21
|
+
import "./common31.mjs";
|
|
22
|
+
import "./common77.mjs";
|
|
23
|
+
import "./common72.mjs";
|
|
24
|
+
import "./common30.mjs";
|
|
25
|
+
import "./common36.mjs";
|
|
26
|
+
import "./common41.mjs";
|
|
27
|
+
import "./common121.mjs";
|
|
28
|
+
import "./common129.mjs";
|
|
29
|
+
class D extends c {
|
|
30
|
+
constructor(e, t, m, r) {
|
|
31
|
+
super(
|
|
32
|
+
e,
|
|
33
|
+
{
|
|
34
|
+
name: "NewCommitment",
|
|
35
|
+
args: ["commitment", "index", "encryptedOutput"]
|
|
36
|
+
},
|
|
37
|
+
t,
|
|
38
|
+
m,
|
|
39
|
+
r
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
_merkleTree;
|
|
43
|
+
_encryptedOutputs;
|
|
44
|
+
get merkleTree() {
|
|
45
|
+
return this._merkleTree;
|
|
46
|
+
}
|
|
47
|
+
get encryptedOutputs() {
|
|
48
|
+
return this._encryptedOutputs;
|
|
49
|
+
}
|
|
50
|
+
serializeSnapshot(e) {
|
|
51
|
+
return {
|
|
52
|
+
merkleTree: e.payload.merkleTree.toJSON(),
|
|
53
|
+
latestBlockNumber: e.latestBlockNumber,
|
|
54
|
+
reserveBlockNumber: e.reserveBlockNumber,
|
|
55
|
+
encryptedOutputs: e.payload.encryptedOutputs.map((t) => ({
|
|
56
|
+
value: t.value,
|
|
57
|
+
isPositive: String(t.isPositive)
|
|
58
|
+
}))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
deserializeSnapshot(e) {
|
|
62
|
+
let t;
|
|
63
|
+
if (e.latestBlockNumber && e.merkleTree) {
|
|
64
|
+
const r = new Map(
|
|
65
|
+
Object.entries(e.merkleTree.tree).map(([u, n]) => [
|
|
66
|
+
BigInt(u),
|
|
67
|
+
BigInt(n)
|
|
68
|
+
])
|
|
69
|
+
);
|
|
70
|
+
t = p.createWithData(
|
|
71
|
+
r,
|
|
72
|
+
i(e.merkleTree.index),
|
|
73
|
+
i(e.merkleTree.count),
|
|
74
|
+
o,
|
|
75
|
+
25n,
|
|
76
|
+
0n
|
|
77
|
+
);
|
|
78
|
+
} else
|
|
79
|
+
t = p.create(o, 25n, 0n);
|
|
80
|
+
const m = e.encryptedOutputs?.map((r) => ({
|
|
81
|
+
value: r.value,
|
|
82
|
+
isPositive: JSON.parse(r.isPositive)
|
|
83
|
+
}));
|
|
84
|
+
return {
|
|
85
|
+
latestBlockNumber: e.latestBlockNumber ?? 0,
|
|
86
|
+
reserveBlockNumber: e.reserveBlockNumber ?? 0,
|
|
87
|
+
payload: {
|
|
88
|
+
merkleTree: t,
|
|
89
|
+
encryptedOutputs: m || []
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
getSnapshotPayload() {
|
|
94
|
+
return {
|
|
95
|
+
merkleTree: this._merkleTree,
|
|
96
|
+
encryptedOutputs: this._encryptedOutputs
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
populateSnapshot({
|
|
100
|
+
payload: { merkleTree: e, encryptedOutputs: t }
|
|
101
|
+
}) {
|
|
102
|
+
this._merkleTree = e, this._encryptedOutputs = t;
|
|
103
|
+
}
|
|
104
|
+
mapEvent(e) {
|
|
105
|
+
const { commitment: t, index: m, encryptedOutput: r } = e;
|
|
106
|
+
return {
|
|
107
|
+
commitment: i(t),
|
|
108
|
+
index: i(m),
|
|
109
|
+
encryptedOutput: r
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
acceptEvent(e, t) {
|
|
113
|
+
if (!this.encryptedOutputs.map((m) => m.value).includes(e.encryptedOutput)) {
|
|
114
|
+
if (this.isServer && console.log(
|
|
115
|
+
`Adding commitment to file ${e.commitment} at index ${e.index} for encrypted output ${e.encryptedOutput}. Block Number: ${t}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
`
|
|
119
|
+
), !this._merkleTree.insert(e.commitment, e.index >= 0 ? e.index : -1n * e.index))
|
|
120
|
+
return console.log(`Could not add ${e.commitment} at index ${e.index} `), !1;
|
|
121
|
+
const r = {
|
|
122
|
+
value: e.encryptedOutput,
|
|
123
|
+
isPositive: e.index >= 0n
|
|
124
|
+
};
|
|
125
|
+
return this._encryptedOutputs.push(r), !0;
|
|
126
|
+
}
|
|
127
|
+
return !1;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
D as AbstractCommitmentsSnapshotService
|
|
132
|
+
};
|
package/common68.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AbstractSnapshotService as i } from "./common69.mjs";
|
|
2
|
+
class s extends i {
|
|
3
|
+
constructor(e, r, l, t) {
|
|
4
|
+
super(
|
|
5
|
+
e,
|
|
6
|
+
{
|
|
7
|
+
name: "Nullified",
|
|
8
|
+
args: ["nullifier"]
|
|
9
|
+
},
|
|
10
|
+
r,
|
|
11
|
+
l,
|
|
12
|
+
t
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
_nullifiers;
|
|
16
|
+
get nullifiers() {
|
|
17
|
+
return this._nullifiers;
|
|
18
|
+
}
|
|
19
|
+
serializeSnapshot(e) {
|
|
20
|
+
return {
|
|
21
|
+
nullifiers: Array.from(e.payload.nullifiers).map((r) => r.toString()),
|
|
22
|
+
latestBlockNumber: e.latestBlockNumber,
|
|
23
|
+
reserveBlockNumber: e.reserveBlockNumber
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
deserializeSnapshot(e) {
|
|
27
|
+
return {
|
|
28
|
+
latestBlockNumber: e.latestBlockNumber ?? 0,
|
|
29
|
+
reserveBlockNumber: e.reserveBlockNumber ?? 0,
|
|
30
|
+
payload: {
|
|
31
|
+
nullifiers: new Set(e.nullifiers ?? [])
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
acceptEvent(e, r) {
|
|
36
|
+
try {
|
|
37
|
+
return this._nullifiers.add(e.nullifier), !0;
|
|
38
|
+
} catch (l) {
|
|
39
|
+
return console.error(l), !1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
mapEvent(e) {
|
|
43
|
+
const { nullifier: r } = e;
|
|
44
|
+
return {
|
|
45
|
+
nullifier: r.toHexString()
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
getSnapshotPayload() {
|
|
49
|
+
return {
|
|
50
|
+
nullifiers: this._nullifiers
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
populateSnapshot({ payload: { nullifiers: e } }) {
|
|
54
|
+
this._nullifiers = e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
s as AbstractNullifierSnapshotService
|
|
59
|
+
};
|
package/common69.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AbstractEventService as o } from "./common70.mjs";
|
|
2
|
+
class h extends o {
|
|
3
|
+
reserveBlockNumber;
|
|
4
|
+
constructor(t, e, s, r, a) {
|
|
5
|
+
super(t, e, s, r, a), this.reserveBlockNumber = s;
|
|
6
|
+
}
|
|
7
|
+
async init() {
|
|
8
|
+
await this.loadSnapshot(), await super.init();
|
|
9
|
+
}
|
|
10
|
+
async retrieveEventsFromLatestBlock() {
|
|
11
|
+
await super.retrieveEvents(this._latestBlockNumber);
|
|
12
|
+
}
|
|
13
|
+
async restoreSnapshotState() {
|
|
14
|
+
await this.retrieveEvents(this.reserveBlockNumber, !0) && (this.reserveBlockNumber = this.latestBlockNumber, await this.afterEventsAccepted());
|
|
15
|
+
}
|
|
16
|
+
async loadSnapshot() {
|
|
17
|
+
const t = await this.fetchSnapshot(), e = this.deserializeSnapshot(t);
|
|
18
|
+
this.populateSnapshot(e), this._latestBlockNumber = e.latestBlockNumber, this.reserveBlockNumber = e.reserveBlockNumber;
|
|
19
|
+
}
|
|
20
|
+
saveSnapshot() {
|
|
21
|
+
return this.persistSnapshot(
|
|
22
|
+
this.serializeSnapshot({
|
|
23
|
+
latestBlockNumber: this._latestBlockNumber,
|
|
24
|
+
reserveBlockNumber: this.reserveBlockNumber,
|
|
25
|
+
payload: this.getSnapshotPayload()
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
afterEventsAccepted() {
|
|
30
|
+
return this.saveSnapshot();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
h as AbstractSnapshotService
|
|
35
|
+
};
|
package/common7.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import p from "axios";
|
|
2
|
+
import "./common28.mjs";
|
|
3
|
+
import "./common157.mjs";
|
|
4
|
+
import "./common164.mjs";
|
|
5
|
+
import "./common168.mjs";
|
|
6
|
+
import "ethers";
|
|
7
|
+
import "circomlibjs";
|
|
8
|
+
import "./common51.mjs";
|
|
9
|
+
import { getServerURL as a } from "./common2.mjs";
|
|
10
|
+
import "./common50.mjs";
|
|
11
|
+
import "./common139.mjs";
|
|
12
|
+
import "./common191.mjs";
|
|
13
|
+
import "./common117.mjs";
|
|
14
|
+
import "./common72.mjs";
|
|
15
|
+
import "./common121.mjs";
|
|
16
|
+
import "./common35.mjs";
|
|
17
|
+
import { API_CONFIG as e } from "./common32.mjs";
|
|
18
|
+
import "./common33.mjs";
|
|
19
|
+
import "./common129.mjs";
|
|
20
|
+
import "./common42.mjs";
|
|
21
|
+
import "./common31.mjs";
|
|
22
|
+
import "./common77.mjs";
|
|
23
|
+
import "libsodium-wrappers";
|
|
24
|
+
import "./common30.mjs";
|
|
25
|
+
import "./common36.mjs";
|
|
26
|
+
import "./common41.mjs";
|
|
27
|
+
const _ = async (t, r, o, m, i) => (await p.get(
|
|
28
|
+
`${a(t)}${e.ROUTES.axelarGasEstimate(
|
|
29
|
+
r,
|
|
30
|
+
o,
|
|
31
|
+
m,
|
|
32
|
+
i
|
|
33
|
+
)}`
|
|
34
|
+
)).data;
|
|
35
|
+
export {
|
|
36
|
+
_ as getAxelarGasEstimate
|
|
37
|
+
};
|
package/common70.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { blockReorgDepth as v } from "./common42.mjs";
|
|
2
|
+
import "ethers";
|
|
3
|
+
import "axios";
|
|
4
|
+
import "./common28.mjs";
|
|
5
|
+
import "./common157.mjs";
|
|
6
|
+
import "./common164.mjs";
|
|
7
|
+
import "./common168.mjs";
|
|
8
|
+
import "circomlibjs";
|
|
9
|
+
import "./common51.mjs";
|
|
10
|
+
import "./common139.mjs";
|
|
11
|
+
import "./common191.mjs";
|
|
12
|
+
import "./common50.mjs";
|
|
13
|
+
import "./common117.mjs";
|
|
14
|
+
import "./common35.mjs";
|
|
15
|
+
import "./common33.mjs";
|
|
16
|
+
import "libsodium-wrappers";
|
|
17
|
+
import { getSequence as m, resolveSync as c } from "./common120.mjs";
|
|
18
|
+
import "./common31.mjs";
|
|
19
|
+
import "./common77.mjs";
|
|
20
|
+
import "./common72.mjs";
|
|
21
|
+
import "./common30.mjs";
|
|
22
|
+
import "./common36.mjs";
|
|
23
|
+
import "./common41.mjs";
|
|
24
|
+
import "./common121.mjs";
|
|
25
|
+
import "./common129.mjs";
|
|
26
|
+
class M {
|
|
27
|
+
contract;
|
|
28
|
+
eventConfig;
|
|
29
|
+
_latestBlockNumber;
|
|
30
|
+
maxPageSize;
|
|
31
|
+
isReady = !1;
|
|
32
|
+
_onNewEvent;
|
|
33
|
+
isServer;
|
|
34
|
+
intervalId;
|
|
35
|
+
inProgress;
|
|
36
|
+
// to remove race conditions
|
|
37
|
+
constructor(t, r, e, s, n) {
|
|
38
|
+
this.contract = t, this.eventConfig = r, this._latestBlockNumber = e, this.maxPageSize = n, this.isServer = s, this.inProgress = !1;
|
|
39
|
+
}
|
|
40
|
+
get latestBlockNumber() {
|
|
41
|
+
return this._latestBlockNumber;
|
|
42
|
+
}
|
|
43
|
+
set onNewEvent(t) {
|
|
44
|
+
this._onNewEvent = t;
|
|
45
|
+
}
|
|
46
|
+
intervalClear() {
|
|
47
|
+
this.isReady = !1, this._onNewEvent = void 0, clearInterval(this.intervalId);
|
|
48
|
+
}
|
|
49
|
+
async init() {
|
|
50
|
+
if (this.isReady)
|
|
51
|
+
throw new Error("Already initialized");
|
|
52
|
+
this.isReady = !0, await this.retrieveEvents(this._latestBlockNumber + 1), this.intervalId = setInterval(async () => {
|
|
53
|
+
await this.retrieveEvents(this.latestBlockNumber);
|
|
54
|
+
}, 3500);
|
|
55
|
+
}
|
|
56
|
+
requireReady() {
|
|
57
|
+
if (!this.isReady)
|
|
58
|
+
throw new Error("Not ready");
|
|
59
|
+
}
|
|
60
|
+
emitNewEvent(t) {
|
|
61
|
+
this._onNewEvent?.(t);
|
|
62
|
+
}
|
|
63
|
+
getLastBlockNumberForEventRequest = async () => {
|
|
64
|
+
const t = await this.contract.provider.getBlockNumber();
|
|
65
|
+
if (!this.isServer)
|
|
66
|
+
return t;
|
|
67
|
+
const { chainId: r } = await this.contract.provider.getNetwork();
|
|
68
|
+
return Math.max(this.latestBlockNumber, t - v[r] + 1);
|
|
69
|
+
};
|
|
70
|
+
async retrieveEvents(t, r = !1) {
|
|
71
|
+
try {
|
|
72
|
+
if (this.requireReady(), this.inProgress && !r)
|
|
73
|
+
return !1;
|
|
74
|
+
this.inProgress = !0;
|
|
75
|
+
const e = await this.getLastBlockNumberForEventRequest();
|
|
76
|
+
if (e < t)
|
|
77
|
+
return this.inProgress = !1, !1;
|
|
78
|
+
const s = m(t, e, this.maxPageSize);
|
|
79
|
+
return await c(
|
|
80
|
+
s.map(({ from: n, to: i }) => async () => {
|
|
81
|
+
const o = await this.contract.queryFilter(
|
|
82
|
+
this.contract.filters[this.eventConfig.name](),
|
|
83
|
+
n,
|
|
84
|
+
i
|
|
85
|
+
);
|
|
86
|
+
let a = [];
|
|
87
|
+
o.length > 0 && (a = await this.processEventsPage(o)), this._latestBlockNumber = i, await this.afterEventsAccepted(), a.length > 0 && this.emitNewEvent();
|
|
88
|
+
})
|
|
89
|
+
), this.inProgress = !1, !0;
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return console.log("retrieveEvents error:", { err: e }), this.inProgress = !1, !1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async processEventsPage(t) {
|
|
95
|
+
const r = [];
|
|
96
|
+
return await c(
|
|
97
|
+
t.map((e) => async () => {
|
|
98
|
+
const { args: s, blockNumber: n } = e;
|
|
99
|
+
if (!s)
|
|
100
|
+
throw new Error("Wrong event structure");
|
|
101
|
+
const i = this.mapEvent(s);
|
|
102
|
+
await this.acceptEvent(i, n) && r.push(i);
|
|
103
|
+
})
|
|
104
|
+
), r;
|
|
105
|
+
}
|
|
106
|
+
handleEvent = async (...t) => {
|
|
107
|
+
const { args: r } = this.eventConfig, { blockNumber: e } = t[t.length - 1], s = t.slice(0, r.length), n = r.reduce((a, h, l) => (a[h] = s[l], a), {});
|
|
108
|
+
if (!e)
|
|
109
|
+
throw new Error("Wrong event structure");
|
|
110
|
+
const i = this.mapEvent(n);
|
|
111
|
+
if (!await this.acceptEvent(i, e))
|
|
112
|
+
throw new Error("Failed to retrieve events");
|
|
113
|
+
this._latestBlockNumber = e, await this.afterEventsAccepted(), this.emitNewEvent(i);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
M as AbstractEventService
|
|
118
|
+
};
|