@aboutcircles/sdk-utils 0.1.5 → 0.1.6
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/abi.d.ts +24 -0
- package/dist/abi.d.ts.map +1 -1
- package/dist/abi.js +65 -0
- package/dist/bytes.d.ts +4 -0
- package/dist/bytes.d.ts.map +1 -1
- package/dist/bytes.js +11 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +26 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +21 -0
- package/dist/crypto.d.ts +19 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +45 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1901
- package/package.json +41 -2
package/dist/index.js
CHANGED
|
@@ -1,1901 +1,4 @@
|
|
|
1
|
-
// src/circlesConverter.ts
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
-
static GAMMA_64 = 18443079296116538654n;
|
|
5
|
-
static BETA_64 = 18450409579521241655n;
|
|
6
|
-
static SECONDS_PER_DAY = 86400n;
|
|
7
|
-
static INFLATION_DAY_ZERO_UNIX = 1602720000n;
|
|
8
|
-
static ATTO_FACTOR = 1000000000000000000n;
|
|
9
|
-
static FACTOR_1E12 = 1000000000000n;
|
|
10
|
-
static V1_ACCURACY = 100000000n;
|
|
11
|
-
static V1_INFLATION_PCT_NUM = 107n;
|
|
12
|
-
static V1_INFLATION_PCT_DEN = 100n;
|
|
13
|
-
static PERIOD_SEC = 31556952n;
|
|
14
|
-
static mul64(a, b) {
|
|
15
|
-
return a * b >> 64n;
|
|
16
|
-
}
|
|
17
|
-
static mulU(factor64x64, value) {
|
|
18
|
-
return factor64x64 * value >> 64n;
|
|
19
|
-
}
|
|
20
|
-
static pow64(base64x64, exp) {
|
|
21
|
-
let base = base64x64;
|
|
22
|
-
let exponent = exp;
|
|
23
|
-
let result = this.ONE_64;
|
|
24
|
-
while (exponent > 0n) {
|
|
25
|
-
if ((exponent & 1n) === 1n) {
|
|
26
|
-
result = this.mul64(result, base);
|
|
27
|
-
}
|
|
28
|
-
base = this.mul64(base, base);
|
|
29
|
-
exponent >>= 1n;
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
static ONE_36 = 1000000000000000000000000000000000000000n;
|
|
34
|
-
static GAMMA_36 = 999801332008598957430613406568191166n;
|
|
35
|
-
static BETA_36 = 1000198707468214629156271489013303962n;
|
|
36
|
-
static mul36(a, b) {
|
|
37
|
-
return a * b / this.ONE_36;
|
|
38
|
-
}
|
|
39
|
-
static pow36(base36, exp) {
|
|
40
|
-
let result = this.ONE_36;
|
|
41
|
-
let base = base36;
|
|
42
|
-
let e = exp;
|
|
43
|
-
while (e > 0n) {
|
|
44
|
-
const isOdd = (e & 1n) === 1n;
|
|
45
|
-
if (isOdd) {
|
|
46
|
-
result = this.mul36(result, base);
|
|
47
|
-
}
|
|
48
|
-
base = this.mul36(base, base);
|
|
49
|
-
e >>= 1n;
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
static attoCirclesToCircles(atto) {
|
|
54
|
-
if (atto === 0n)
|
|
55
|
-
return 0;
|
|
56
|
-
const whole = atto / this.ATTO_FACTOR;
|
|
57
|
-
const frac = atto % this.ATTO_FACTOR;
|
|
58
|
-
const MAX_SAFE_INT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
59
|
-
if (whole > MAX_SAFE_INT || whole < -MAX_SAFE_INT) {
|
|
60
|
-
throw new RangeError("Atto value’s integer component exceeds JS double precision.");
|
|
61
|
-
}
|
|
62
|
-
return Number(whole) + Number(frac) / Number(this.ATTO_FACTOR);
|
|
63
|
-
}
|
|
64
|
-
static circlesToAttoCircles(circles) {
|
|
65
|
-
return BigInt(Math.trunc(circles * Number(this.ATTO_FACTOR)));
|
|
66
|
-
}
|
|
67
|
-
static inflationaryToDemurrage(inflationary, day) {
|
|
68
|
-
return this.mulU(this.pow64(this.GAMMA_64, day), inflationary);
|
|
69
|
-
}
|
|
70
|
-
static demurrageToInflationary(demurraged, day) {
|
|
71
|
-
return this.mulU(this.pow64(this.BETA_64, day), demurraged);
|
|
72
|
-
}
|
|
73
|
-
static dayFromTimestamp(unixSeconds) {
|
|
74
|
-
return (unixSeconds - this.INFLATION_DAY_ZERO_UNIX) / this.SECONDS_PER_DAY;
|
|
75
|
-
}
|
|
76
|
-
static attoCirclesToAttoStaticCircles(demurraged, nowUnixSeconds = BigInt(Math.floor(Date.now() / 1000))) {
|
|
77
|
-
return this.demurrageToInflationary(demurraged, this.dayFromTimestamp(nowUnixSeconds));
|
|
78
|
-
}
|
|
79
|
-
static attoStaticCirclesToAttoCircles(staticCircles, nowUnixSeconds = BigInt(Math.floor(Date.now() / 1000))) {
|
|
80
|
-
return this.inflationaryToDemurrage(staticCircles, this.dayFromTimestamp(nowUnixSeconds));
|
|
81
|
-
}
|
|
82
|
-
static inflationaryToDemurrageExact(inflationary, day) {
|
|
83
|
-
const factor = this.pow36(this.GAMMA_36, day);
|
|
84
|
-
return inflationary * factor / this.ONE_36;
|
|
85
|
-
}
|
|
86
|
-
static demurrageToInflationaryExact(demurraged, day) {
|
|
87
|
-
const factor = this.pow36(this.BETA_36, day);
|
|
88
|
-
return demurraged * factor / this.ONE_36;
|
|
89
|
-
}
|
|
90
|
-
static attoCirclesToAttoStaticCirclesExact(demurraged, nowUnixSeconds = BigInt(Math.floor(Date.now() / 1000))) {
|
|
91
|
-
const day = this.dayFromTimestamp(nowUnixSeconds);
|
|
92
|
-
return this.demurrageToInflationaryExact(demurraged, day);
|
|
93
|
-
}
|
|
94
|
-
static attoStaticCirclesToAttoCirclesExact(staticCircles, nowUnixSeconds = BigInt(Math.floor(Date.now() / 1000))) {
|
|
95
|
-
const day = this.dayFromTimestamp(nowUnixSeconds);
|
|
96
|
-
return this.inflationaryToDemurrageExact(staticCircles, day);
|
|
97
|
-
}
|
|
98
|
-
static truncateToInt64(wei) {
|
|
99
|
-
const truncated = wei / this.FACTOR_1E12;
|
|
100
|
-
const MAX_INT64 = 9223372036854775807n;
|
|
101
|
-
return truncated > MAX_INT64 ? MAX_INT64 : truncated;
|
|
102
|
-
}
|
|
103
|
-
static blowUpToBigInt(sixDecimals) {
|
|
104
|
-
return sixDecimals * this.FACTOR_1E12;
|
|
105
|
-
}
|
|
106
|
-
static truncateToSixDecimals(wei) {
|
|
107
|
-
return this.blowUpToBigInt(this.truncateToInt64(wei));
|
|
108
|
-
}
|
|
109
|
-
static v1InflateFactor(periodIdx) {
|
|
110
|
-
if (periodIdx === 0n)
|
|
111
|
-
return this.V1_ACCURACY;
|
|
112
|
-
return this.V1_ACCURACY * this.V1_INFLATION_PCT_NUM ** periodIdx / this.V1_INFLATION_PCT_DEN ** periodIdx;
|
|
113
|
-
}
|
|
114
|
-
static attoCrcToAttoCircles(v1Amount, blockTimestampUtc) {
|
|
115
|
-
const secondsSinceEpoch = blockTimestampUtc - this.INFLATION_DAY_ZERO_UNIX;
|
|
116
|
-
const periodIdx = secondsSinceEpoch / this.PERIOD_SEC;
|
|
117
|
-
const secondsIntoPeriod = secondsSinceEpoch % this.PERIOD_SEC;
|
|
118
|
-
const factorCur = this.v1InflateFactor(periodIdx);
|
|
119
|
-
const factorNext = this.v1InflateFactor(periodIdx + 1n);
|
|
120
|
-
return this.v1ToDemurrage(v1Amount, factorCur, factorNext, secondsIntoPeriod, this.PERIOD_SEC);
|
|
121
|
-
}
|
|
122
|
-
static attoCirclesToAttoCrc(demurraged, blockTimestampUtc) {
|
|
123
|
-
const secondsSinceEpoch = blockTimestampUtc - this.INFLATION_DAY_ZERO_UNIX;
|
|
124
|
-
const periodIdx = secondsSinceEpoch / this.PERIOD_SEC;
|
|
125
|
-
const secondsIntoPeriod = secondsSinceEpoch % this.PERIOD_SEC;
|
|
126
|
-
const factorCur = this.v1InflateFactor(periodIdx);
|
|
127
|
-
const factorNext = this.v1InflateFactor(periodIdx + 1n);
|
|
128
|
-
const rP = factorCur * (this.PERIOD_SEC - secondsIntoPeriod) + factorNext * secondsIntoPeriod;
|
|
129
|
-
return demurraged * 3n * this.V1_ACCURACY * this.PERIOD_SEC / rP;
|
|
130
|
-
}
|
|
131
|
-
static v1ToDemurrage(v1Amount, factorCur, factorNext, secondsInto, periodSec) {
|
|
132
|
-
const rP = factorCur * (periodSec - secondsInto) + factorNext * secondsInto;
|
|
133
|
-
return v1Amount * 3n * this.V1_ACCURACY * periodSec / rP;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// src/bytes.ts
|
|
137
|
-
var byteToHex = [];
|
|
138
|
-
for (let i = 0;i < 256; i++) {
|
|
139
|
-
byteToHex[i] = i.toString(16).padStart(2, "0");
|
|
140
|
-
}
|
|
141
|
-
function bytesToHex(bytes) {
|
|
142
|
-
let hex = "0x";
|
|
143
|
-
for (let i = 0;i < bytes.length; i++) {
|
|
144
|
-
hex += byteToHex[bytes[i]];
|
|
145
|
-
}
|
|
146
|
-
return hex;
|
|
147
|
-
}
|
|
148
|
-
// ../../node_modules/@noble/hashes/esm/_u64.js
|
|
149
|
-
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
150
|
-
var _32n = /* @__PURE__ */ BigInt(32);
|
|
151
|
-
function fromBig(n, le = false) {
|
|
152
|
-
if (le)
|
|
153
|
-
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
154
|
-
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
155
|
-
}
|
|
156
|
-
function split(lst, le = false) {
|
|
157
|
-
const len = lst.length;
|
|
158
|
-
let Ah = new Uint32Array(len);
|
|
159
|
-
let Al = new Uint32Array(len);
|
|
160
|
-
for (let i = 0;i < len; i++) {
|
|
161
|
-
const { h, l } = fromBig(lst[i], le);
|
|
162
|
-
[Ah[i], Al[i]] = [h, l];
|
|
163
|
-
}
|
|
164
|
-
return [Ah, Al];
|
|
165
|
-
}
|
|
166
|
-
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
167
|
-
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
168
|
-
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
169
|
-
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
170
|
-
|
|
171
|
-
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
172
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
173
|
-
function isBytes(a) {
|
|
174
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
175
|
-
}
|
|
176
|
-
function anumber(n) {
|
|
177
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
178
|
-
throw new Error("positive integer expected, got " + n);
|
|
179
|
-
}
|
|
180
|
-
function abytes(b, ...lengths) {
|
|
181
|
-
if (!isBytes(b))
|
|
182
|
-
throw new Error("Uint8Array expected");
|
|
183
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
184
|
-
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
185
|
-
}
|
|
186
|
-
function aexists(instance, checkFinished = true) {
|
|
187
|
-
if (instance.destroyed)
|
|
188
|
-
throw new Error("Hash instance has been destroyed");
|
|
189
|
-
if (checkFinished && instance.finished)
|
|
190
|
-
throw new Error("Hash#digest() has already been called");
|
|
191
|
-
}
|
|
192
|
-
function aoutput(out, instance) {
|
|
193
|
-
abytes(out);
|
|
194
|
-
const min = instance.outputLen;
|
|
195
|
-
if (out.length < min) {
|
|
196
|
-
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function u32(arr) {
|
|
200
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
201
|
-
}
|
|
202
|
-
function clean(...arrays) {
|
|
203
|
-
for (let i = 0;i < arrays.length; i++) {
|
|
204
|
-
arrays[i].fill(0);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
208
|
-
function byteSwap(word) {
|
|
209
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
210
|
-
}
|
|
211
|
-
function byteSwap32(arr) {
|
|
212
|
-
for (let i = 0;i < arr.length; i++) {
|
|
213
|
-
arr[i] = byteSwap(arr[i]);
|
|
214
|
-
}
|
|
215
|
-
return arr;
|
|
216
|
-
}
|
|
217
|
-
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
218
|
-
function utf8ToBytes(str) {
|
|
219
|
-
if (typeof str !== "string")
|
|
220
|
-
throw new Error("string expected");
|
|
221
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
222
|
-
}
|
|
223
|
-
function toBytes(data) {
|
|
224
|
-
if (typeof data === "string")
|
|
225
|
-
data = utf8ToBytes(data);
|
|
226
|
-
abytes(data);
|
|
227
|
-
return data;
|
|
228
|
-
}
|
|
229
|
-
class Hash {
|
|
230
|
-
}
|
|
231
|
-
function createHasher(hashCons) {
|
|
232
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
233
|
-
const tmp = hashCons();
|
|
234
|
-
hashC.outputLen = tmp.outputLen;
|
|
235
|
-
hashC.blockLen = tmp.blockLen;
|
|
236
|
-
hashC.create = () => hashCons();
|
|
237
|
-
return hashC;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// ../../node_modules/@noble/hashes/esm/sha3.js
|
|
241
|
-
var _0n = BigInt(0);
|
|
242
|
-
var _1n = BigInt(1);
|
|
243
|
-
var _2n = BigInt(2);
|
|
244
|
-
var _7n = BigInt(7);
|
|
245
|
-
var _256n = BigInt(256);
|
|
246
|
-
var _0x71n = BigInt(113);
|
|
247
|
-
var SHA3_PI = [];
|
|
248
|
-
var SHA3_ROTL = [];
|
|
249
|
-
var _SHA3_IOTA = [];
|
|
250
|
-
for (let round = 0, R = _1n, x = 1, y = 0;round < 24; round++) {
|
|
251
|
-
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
252
|
-
SHA3_PI.push(2 * (5 * y + x));
|
|
253
|
-
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
254
|
-
let t = _0n;
|
|
255
|
-
for (let j = 0;j < 7; j++) {
|
|
256
|
-
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
257
|
-
if (R & _2n)
|
|
258
|
-
t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
259
|
-
}
|
|
260
|
-
_SHA3_IOTA.push(t);
|
|
261
|
-
}
|
|
262
|
-
var IOTAS = split(_SHA3_IOTA, true);
|
|
263
|
-
var SHA3_IOTA_H = IOTAS[0];
|
|
264
|
-
var SHA3_IOTA_L = IOTAS[1];
|
|
265
|
-
var rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
266
|
-
var rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
267
|
-
function keccakP(s, rounds = 24) {
|
|
268
|
-
const B = new Uint32Array(5 * 2);
|
|
269
|
-
for (let round = 24 - rounds;round < 24; round++) {
|
|
270
|
-
for (let x = 0;x < 10; x++)
|
|
271
|
-
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
272
|
-
for (let x = 0;x < 10; x += 2) {
|
|
273
|
-
const idx1 = (x + 8) % 10;
|
|
274
|
-
const idx0 = (x + 2) % 10;
|
|
275
|
-
const B0 = B[idx0];
|
|
276
|
-
const B1 = B[idx0 + 1];
|
|
277
|
-
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
278
|
-
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
279
|
-
for (let y = 0;y < 50; y += 10) {
|
|
280
|
-
s[x + y] ^= Th;
|
|
281
|
-
s[x + y + 1] ^= Tl;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
let curH = s[2];
|
|
285
|
-
let curL = s[3];
|
|
286
|
-
for (let t = 0;t < 24; t++) {
|
|
287
|
-
const shift = SHA3_ROTL[t];
|
|
288
|
-
const Th = rotlH(curH, curL, shift);
|
|
289
|
-
const Tl = rotlL(curH, curL, shift);
|
|
290
|
-
const PI = SHA3_PI[t];
|
|
291
|
-
curH = s[PI];
|
|
292
|
-
curL = s[PI + 1];
|
|
293
|
-
s[PI] = Th;
|
|
294
|
-
s[PI + 1] = Tl;
|
|
295
|
-
}
|
|
296
|
-
for (let y = 0;y < 50; y += 10) {
|
|
297
|
-
for (let x = 0;x < 10; x++)
|
|
298
|
-
B[x] = s[y + x];
|
|
299
|
-
for (let x = 0;x < 10; x++)
|
|
300
|
-
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
301
|
-
}
|
|
302
|
-
s[0] ^= SHA3_IOTA_H[round];
|
|
303
|
-
s[1] ^= SHA3_IOTA_L[round];
|
|
304
|
-
}
|
|
305
|
-
clean(B);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
class Keccak extends Hash {
|
|
309
|
-
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
310
|
-
super();
|
|
311
|
-
this.pos = 0;
|
|
312
|
-
this.posOut = 0;
|
|
313
|
-
this.finished = false;
|
|
314
|
-
this.destroyed = false;
|
|
315
|
-
this.enableXOF = false;
|
|
316
|
-
this.blockLen = blockLen;
|
|
317
|
-
this.suffix = suffix;
|
|
318
|
-
this.outputLen = outputLen;
|
|
319
|
-
this.enableXOF = enableXOF;
|
|
320
|
-
this.rounds = rounds;
|
|
321
|
-
anumber(outputLen);
|
|
322
|
-
if (!(0 < blockLen && blockLen < 200))
|
|
323
|
-
throw new Error("only keccak-f1600 function is supported");
|
|
324
|
-
this.state = new Uint8Array(200);
|
|
325
|
-
this.state32 = u32(this.state);
|
|
326
|
-
}
|
|
327
|
-
clone() {
|
|
328
|
-
return this._cloneInto();
|
|
329
|
-
}
|
|
330
|
-
keccak() {
|
|
331
|
-
swap32IfBE(this.state32);
|
|
332
|
-
keccakP(this.state32, this.rounds);
|
|
333
|
-
swap32IfBE(this.state32);
|
|
334
|
-
this.posOut = 0;
|
|
335
|
-
this.pos = 0;
|
|
336
|
-
}
|
|
337
|
-
update(data) {
|
|
338
|
-
aexists(this);
|
|
339
|
-
data = toBytes(data);
|
|
340
|
-
abytes(data);
|
|
341
|
-
const { blockLen, state } = this;
|
|
342
|
-
const len = data.length;
|
|
343
|
-
for (let pos = 0;pos < len; ) {
|
|
344
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
345
|
-
for (let i = 0;i < take; i++)
|
|
346
|
-
state[this.pos++] ^= data[pos++];
|
|
347
|
-
if (this.pos === blockLen)
|
|
348
|
-
this.keccak();
|
|
349
|
-
}
|
|
350
|
-
return this;
|
|
351
|
-
}
|
|
352
|
-
finish() {
|
|
353
|
-
if (this.finished)
|
|
354
|
-
return;
|
|
355
|
-
this.finished = true;
|
|
356
|
-
const { state, suffix, pos, blockLen } = this;
|
|
357
|
-
state[pos] ^= suffix;
|
|
358
|
-
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
359
|
-
this.keccak();
|
|
360
|
-
state[blockLen - 1] ^= 128;
|
|
361
|
-
this.keccak();
|
|
362
|
-
}
|
|
363
|
-
writeInto(out) {
|
|
364
|
-
aexists(this, false);
|
|
365
|
-
abytes(out);
|
|
366
|
-
this.finish();
|
|
367
|
-
const bufferOut = this.state;
|
|
368
|
-
const { blockLen } = this;
|
|
369
|
-
for (let pos = 0, len = out.length;pos < len; ) {
|
|
370
|
-
if (this.posOut >= blockLen)
|
|
371
|
-
this.keccak();
|
|
372
|
-
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
373
|
-
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
374
|
-
this.posOut += take;
|
|
375
|
-
pos += take;
|
|
376
|
-
}
|
|
377
|
-
return out;
|
|
378
|
-
}
|
|
379
|
-
xofInto(out) {
|
|
380
|
-
if (!this.enableXOF)
|
|
381
|
-
throw new Error("XOF is not possible for this instance");
|
|
382
|
-
return this.writeInto(out);
|
|
383
|
-
}
|
|
384
|
-
xof(bytes) {
|
|
385
|
-
anumber(bytes);
|
|
386
|
-
return this.xofInto(new Uint8Array(bytes));
|
|
387
|
-
}
|
|
388
|
-
digestInto(out) {
|
|
389
|
-
aoutput(out, this);
|
|
390
|
-
if (this.finished)
|
|
391
|
-
throw new Error("digest() was already called");
|
|
392
|
-
this.writeInto(out);
|
|
393
|
-
this.destroy();
|
|
394
|
-
return out;
|
|
395
|
-
}
|
|
396
|
-
digest() {
|
|
397
|
-
return this.digestInto(new Uint8Array(this.outputLen));
|
|
398
|
-
}
|
|
399
|
-
destroy() {
|
|
400
|
-
this.destroyed = true;
|
|
401
|
-
clean(this.state);
|
|
402
|
-
}
|
|
403
|
-
_cloneInto(to) {
|
|
404
|
-
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
405
|
-
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
406
|
-
to.state32.set(this.state32);
|
|
407
|
-
to.pos = this.pos;
|
|
408
|
-
to.posOut = this.posOut;
|
|
409
|
-
to.finished = this.finished;
|
|
410
|
-
to.rounds = rounds;
|
|
411
|
-
to.suffix = suffix;
|
|
412
|
-
to.outputLen = outputLen;
|
|
413
|
-
to.enableXOF = enableXOF;
|
|
414
|
-
to.destroyed = this.destroyed;
|
|
415
|
-
return to;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
var gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
419
|
-
var keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
|
|
420
|
-
|
|
421
|
-
// src/abi.ts
|
|
422
|
-
var HEX_CHARS = 64;
|
|
423
|
-
var BYTES_PER_WORD = 32;
|
|
424
|
-
var strip0x = (hex) => hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
425
|
-
var toHex64 = (num) => num.toString(16).padStart(HEX_CHARS, "0");
|
|
426
|
-
function checksumAddress(address) {
|
|
427
|
-
const addr = address.toLowerCase().replace("0x", "");
|
|
428
|
-
const hash = bytesToHex(keccak_256(new TextEncoder().encode(addr))).slice(2);
|
|
429
|
-
let result = "0x";
|
|
430
|
-
for (let i = 0;i < addr.length; i++) {
|
|
431
|
-
result += parseInt(hash[i], 16) >= 8 ? addr[i].toUpperCase() : addr[i];
|
|
432
|
-
}
|
|
433
|
-
return result;
|
|
434
|
-
}
|
|
435
|
-
function getTypeString(type, components) {
|
|
436
|
-
if (type === "tuple" && components) {
|
|
437
|
-
const types = components.map((c) => getTypeString(c.type, c.components));
|
|
438
|
-
return `(${types.join(",")})`;
|
|
439
|
-
}
|
|
440
|
-
const tupleArrayMatch = type.match(/^tuple(\[\d*\])$/);
|
|
441
|
-
if (tupleArrayMatch && components) {
|
|
442
|
-
const baseType = getTypeString("tuple", components);
|
|
443
|
-
return `${baseType}${tupleArrayMatch[1]}`;
|
|
444
|
-
}
|
|
445
|
-
return type;
|
|
446
|
-
}
|
|
447
|
-
function getFunctionSignature(abiFunction) {
|
|
448
|
-
const inputs = abiFunction.inputs || [];
|
|
449
|
-
const types = inputs.map((input) => getTypeString(input.type, input.components));
|
|
450
|
-
return `${abiFunction.name}(${types.join(",")})`;
|
|
451
|
-
}
|
|
452
|
-
function getFunctionSelector(abiFunction) {
|
|
453
|
-
const signature = getFunctionSignature(abiFunction);
|
|
454
|
-
const hash = keccak_256(new TextEncoder().encode(signature));
|
|
455
|
-
return bytesToHex(hash.slice(0, 4));
|
|
456
|
-
}
|
|
457
|
-
function isDynamicType(type, components) {
|
|
458
|
-
if (type === "string" || type === "bytes")
|
|
459
|
-
return true;
|
|
460
|
-
if (type.includes("[")) {
|
|
461
|
-
const baseType = type.slice(0, type.indexOf("["));
|
|
462
|
-
if (type.endsWith("[]"))
|
|
463
|
-
return true;
|
|
464
|
-
if (baseType === "tuple") {
|
|
465
|
-
return isTupleDynamic(components);
|
|
466
|
-
}
|
|
467
|
-
return isDynamicType(baseType);
|
|
468
|
-
}
|
|
469
|
-
if (type === "tuple") {
|
|
470
|
-
return isTupleDynamic(components);
|
|
471
|
-
}
|
|
472
|
-
return false;
|
|
473
|
-
}
|
|
474
|
-
function isTupleDynamic(components) {
|
|
475
|
-
return components?.some((c) => isDynamicType(c.type, c.components)) ?? false;
|
|
476
|
-
}
|
|
477
|
-
function encodeParam(type, value, components) {
|
|
478
|
-
if (type === "tuple" && components) {
|
|
479
|
-
return encodeTuple(components, value);
|
|
480
|
-
}
|
|
481
|
-
if (type.includes("[")) {
|
|
482
|
-
return encodeArray(type, value, components);
|
|
483
|
-
}
|
|
484
|
-
return encodePrimitive(type, value);
|
|
485
|
-
}
|
|
486
|
-
function encodeArray(type, arr, components) {
|
|
487
|
-
const baseType = type.slice(0, type.indexOf("["));
|
|
488
|
-
const isDynamic = type.endsWith("[]");
|
|
489
|
-
const elementsAreDynamic = isDynamicType(baseType, components);
|
|
490
|
-
let encoded;
|
|
491
|
-
if (elementsAreDynamic) {
|
|
492
|
-
const encodings = arr.map((v) => encodeParam(baseType, v, components));
|
|
493
|
-
let offset = arr.length * BYTES_PER_WORD;
|
|
494
|
-
const offsets = encodings.map((enc) => {
|
|
495
|
-
const currentOffset = offset;
|
|
496
|
-
offset += enc.length / 2;
|
|
497
|
-
return toHex64(currentOffset);
|
|
498
|
-
});
|
|
499
|
-
encoded = offsets.join("") + encodings.join("");
|
|
500
|
-
} else {
|
|
501
|
-
encoded = arr.map((v) => encodeParam(baseType, v, components)).join("");
|
|
502
|
-
}
|
|
503
|
-
return isDynamic ? toHex64(arr.length) + encoded : encoded;
|
|
504
|
-
}
|
|
505
|
-
function encodeTuple(components, value) {
|
|
506
|
-
const isArray = Array.isArray(value);
|
|
507
|
-
const encodings = [];
|
|
508
|
-
const dynamicData = [];
|
|
509
|
-
const isDynamic = [];
|
|
510
|
-
for (let i = 0;i < components.length; i++) {
|
|
511
|
-
const component = components[i];
|
|
512
|
-
const val = isArray ? value[i] : value[component.name || ""];
|
|
513
|
-
const dynamic = isDynamicType(component.type, component.components);
|
|
514
|
-
isDynamic.push(dynamic);
|
|
515
|
-
if (dynamic) {
|
|
516
|
-
encodings.push("");
|
|
517
|
-
dynamicData.push(encodeParam(component.type, val, component.components));
|
|
518
|
-
} else {
|
|
519
|
-
encodings.push(encodeParam(component.type, val, component.components));
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
if (dynamicData.length > 0) {
|
|
523
|
-
let offset = encodings.reduce((sum, enc, i) => sum + (isDynamic[i] ? BYTES_PER_WORD : enc.length / 2), 0);
|
|
524
|
-
let result = "";
|
|
525
|
-
let dynamicIndex = 0;
|
|
526
|
-
for (let i = 0;i < components.length; i++) {
|
|
527
|
-
if (isDynamic[i]) {
|
|
528
|
-
result += toHex64(offset);
|
|
529
|
-
offset += dynamicData[dynamicIndex].length / 2;
|
|
530
|
-
dynamicIndex++;
|
|
531
|
-
} else {
|
|
532
|
-
result += encodings[i];
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return result + dynamicData.join("");
|
|
536
|
-
}
|
|
537
|
-
return encodings.join("");
|
|
538
|
-
}
|
|
539
|
-
function encodePrimitive(type, value) {
|
|
540
|
-
if (type === "address") {
|
|
541
|
-
return strip0x(value).toLowerCase().padStart(HEX_CHARS, "0");
|
|
542
|
-
}
|
|
543
|
-
if (type === "bool") {
|
|
544
|
-
return toHex64(value ? 1 : 0);
|
|
545
|
-
}
|
|
546
|
-
if (type.startsWith("uint")) {
|
|
547
|
-
const num = typeof value === "bigint" ? value : BigInt(value);
|
|
548
|
-
return toHex64(num);
|
|
549
|
-
}
|
|
550
|
-
if (type.startsWith("int")) {
|
|
551
|
-
let num = typeof value === "bigint" ? value : BigInt(value);
|
|
552
|
-
if (num < 0n) {
|
|
553
|
-
const bits = type === "int" ? 256 : parseInt(type.slice(3));
|
|
554
|
-
num = (1n << BigInt(bits)) + num;
|
|
555
|
-
}
|
|
556
|
-
return toHex64(num);
|
|
557
|
-
}
|
|
558
|
-
if (type.startsWith("bytes") && type !== "bytes") {
|
|
559
|
-
return strip0x(value).padEnd(HEX_CHARS, "0");
|
|
560
|
-
}
|
|
561
|
-
if (type === "bytes") {
|
|
562
|
-
const bytes = strip0x(value);
|
|
563
|
-
const length = toHex64(bytes.length / 2);
|
|
564
|
-
const padded = bytes.padEnd(Math.ceil(bytes.length / HEX_CHARS) * HEX_CHARS, "0");
|
|
565
|
-
return length + padded;
|
|
566
|
-
}
|
|
567
|
-
if (type === "string") {
|
|
568
|
-
const bytes = Array.from(new TextEncoder().encode(value)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
569
|
-
const length = toHex64(bytes.length / 2);
|
|
570
|
-
const padded = bytes.padEnd(Math.ceil(bytes.length / HEX_CHARS) * HEX_CHARS, "0");
|
|
571
|
-
return length + padded;
|
|
572
|
-
}
|
|
573
|
-
throw new Error(`Unsupported type: ${type}`);
|
|
574
|
-
}
|
|
575
|
-
function decodeParam(type, data, offset = 0, components) {
|
|
576
|
-
if (type === "tuple" && components) {
|
|
577
|
-
return decodeTuple(components, data, offset);
|
|
578
|
-
}
|
|
579
|
-
if (type.includes("[")) {
|
|
580
|
-
return decodeArray(type, data, offset, components);
|
|
581
|
-
}
|
|
582
|
-
return decodePrimitive(type, data, offset);
|
|
583
|
-
}
|
|
584
|
-
function decodeArray(type, data, offset, components) {
|
|
585
|
-
const baseType = type.slice(0, type.indexOf("["));
|
|
586
|
-
const chunk = data.slice(offset, offset + HEX_CHARS);
|
|
587
|
-
if (type.endsWith("[]")) {
|
|
588
|
-
const dataOffset = parseInt(chunk, 16) * 2;
|
|
589
|
-
const length = parseInt(data.slice(dataOffset, dataOffset + HEX_CHARS), 16);
|
|
590
|
-
const values = [];
|
|
591
|
-
let currentOffset = dataOffset + HEX_CHARS;
|
|
592
|
-
for (let i = 0;i < length; i++) {
|
|
593
|
-
const result = decodeParam(baseType, data, currentOffset, components);
|
|
594
|
-
values.push(result.value);
|
|
595
|
-
currentOffset += result.consumed;
|
|
596
|
-
}
|
|
597
|
-
return { value: values, consumed: HEX_CHARS };
|
|
598
|
-
}
|
|
599
|
-
const match = type.match(/\[(\d+)\]$/);
|
|
600
|
-
if (match) {
|
|
601
|
-
const length = parseInt(match[1]);
|
|
602
|
-
const values = [];
|
|
603
|
-
let consumed = 0;
|
|
604
|
-
for (let i = 0;i < length; i++) {
|
|
605
|
-
const result = decodeParam(baseType, data, offset + consumed, components);
|
|
606
|
-
values.push(result.value);
|
|
607
|
-
consumed += result.consumed;
|
|
608
|
-
}
|
|
609
|
-
return { value: values, consumed };
|
|
610
|
-
}
|
|
611
|
-
throw new Error(`Invalid array type: ${type}`);
|
|
612
|
-
}
|
|
613
|
-
function decodeTuple(components, data, offset) {
|
|
614
|
-
const values = [];
|
|
615
|
-
let currentOffset = offset;
|
|
616
|
-
for (const component of components) {
|
|
617
|
-
const result = decodeParam(component.type, data, currentOffset, component.components);
|
|
618
|
-
values.push(result.value);
|
|
619
|
-
currentOffset += result.consumed;
|
|
620
|
-
}
|
|
621
|
-
return { value: values, consumed: currentOffset - offset };
|
|
622
|
-
}
|
|
623
|
-
function decodePrimitive(type, data, offset) {
|
|
624
|
-
const chunk = data.slice(offset, offset + HEX_CHARS);
|
|
625
|
-
if (type === "address") {
|
|
626
|
-
return {
|
|
627
|
-
value: checksumAddress("0x" + chunk.slice(24)),
|
|
628
|
-
consumed: HEX_CHARS
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
if (type === "bool") {
|
|
632
|
-
return {
|
|
633
|
-
value: parseInt(chunk, 16) !== 0,
|
|
634
|
-
consumed: HEX_CHARS
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
if (type.startsWith("uint")) {
|
|
638
|
-
return {
|
|
639
|
-
value: BigInt("0x" + chunk),
|
|
640
|
-
consumed: HEX_CHARS
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
if (type.startsWith("int")) {
|
|
644
|
-
const value = BigInt("0x" + chunk);
|
|
645
|
-
const bits = type === "int" ? 256 : parseInt(type.slice(3));
|
|
646
|
-
const signBit = 1n << BigInt(bits - 1);
|
|
647
|
-
return {
|
|
648
|
-
value: value >= signBit ? value - (1n << BigInt(bits)) : value,
|
|
649
|
-
consumed: HEX_CHARS
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
if (type.startsWith("bytes") && type !== "bytes") {
|
|
653
|
-
const size = parseInt(type.match(/^bytes(\d+)$/)[1]);
|
|
654
|
-
return {
|
|
655
|
-
value: "0x" + chunk.slice(0, size * 2),
|
|
656
|
-
consumed: HEX_CHARS
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
if (type === "bytes") {
|
|
660
|
-
const dataOffset = parseInt(chunk, 16) * 2;
|
|
661
|
-
const length = parseInt(data.slice(dataOffset, dataOffset + HEX_CHARS), 16) * 2;
|
|
662
|
-
return {
|
|
663
|
-
value: "0x" + data.slice(dataOffset + HEX_CHARS, dataOffset + HEX_CHARS + length),
|
|
664
|
-
consumed: HEX_CHARS
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
if (type === "string") {
|
|
668
|
-
const dataOffset = parseInt(chunk, 16) * 2;
|
|
669
|
-
const length = parseInt(data.slice(dataOffset, dataOffset + HEX_CHARS), 16) * 2;
|
|
670
|
-
const bytes = data.slice(dataOffset + HEX_CHARS, dataOffset + HEX_CHARS + length);
|
|
671
|
-
const byteArray = new Uint8Array(bytes.match(/.{2}/g)?.map((b) => parseInt(b, 16)) || []);
|
|
672
|
-
return {
|
|
673
|
-
value: new TextDecoder().decode(byteArray),
|
|
674
|
-
consumed: HEX_CHARS
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
throw new Error(`Unsupported type: ${type}`);
|
|
678
|
-
}
|
|
679
|
-
function encodeFunctionData(config) {
|
|
680
|
-
const { abi, functionName, args = [] } = config;
|
|
681
|
-
const abiFunction = abi.find((item) => item.type === "function" && item.name === functionName);
|
|
682
|
-
if (!abiFunction) {
|
|
683
|
-
throw new Error(`Function "${functionName}" not found in ABI`);
|
|
684
|
-
}
|
|
685
|
-
const selector = getFunctionSelector(abiFunction);
|
|
686
|
-
const inputs = abiFunction.inputs || [];
|
|
687
|
-
if (inputs.length === 0)
|
|
688
|
-
return selector;
|
|
689
|
-
if (args.length !== inputs.length) {
|
|
690
|
-
throw new Error(`Expected ${inputs.length} arguments, got ${args.length}`);
|
|
691
|
-
}
|
|
692
|
-
const encodings = [];
|
|
693
|
-
const dynamicData = [];
|
|
694
|
-
const isDynamic = [];
|
|
695
|
-
for (let i = 0;i < inputs.length; i++) {
|
|
696
|
-
const input = inputs[i];
|
|
697
|
-
const components = input.components;
|
|
698
|
-
const dynamic = isDynamicType(input.type, components);
|
|
699
|
-
isDynamic.push(dynamic);
|
|
700
|
-
if (dynamic) {
|
|
701
|
-
encodings.push("");
|
|
702
|
-
dynamicData.push(encodeParam(input.type, args[i], components));
|
|
703
|
-
} else {
|
|
704
|
-
encodings.push(encodeParam(input.type, args[i], components));
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
if (dynamicData.length === 0) {
|
|
708
|
-
return selector + encodings.join("");
|
|
709
|
-
}
|
|
710
|
-
let offset = encodings.reduce((sum, enc, i) => sum + (isDynamic[i] ? BYTES_PER_WORD : enc.length / 2), 0);
|
|
711
|
-
let result = "";
|
|
712
|
-
let dynamicIndex = 0;
|
|
713
|
-
for (let i = 0;i < inputs.length; i++) {
|
|
714
|
-
if (isDynamic[i]) {
|
|
715
|
-
result += toHex64(offset);
|
|
716
|
-
offset += dynamicData[dynamicIndex].length / 2;
|
|
717
|
-
dynamicIndex++;
|
|
718
|
-
} else {
|
|
719
|
-
result += encodings[i];
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
return selector + result + dynamicData.join("");
|
|
723
|
-
}
|
|
724
|
-
function decodeFunctionResult(config) {
|
|
725
|
-
const { abi, functionName, data } = config;
|
|
726
|
-
const abiFunction = abi.find((item) => item.type === "function" && item.name === functionName);
|
|
727
|
-
if (!abiFunction) {
|
|
728
|
-
throw new Error(`Function "${functionName}" not found in ABI`);
|
|
729
|
-
}
|
|
730
|
-
const outputs = abiFunction.outputs || [];
|
|
731
|
-
if (outputs.length === 0)
|
|
732
|
-
return;
|
|
733
|
-
const cleanData = strip0x(data);
|
|
734
|
-
if (outputs.length === 1) {
|
|
735
|
-
return decodeParam(outputs[0].type, cleanData, 0, outputs[0].components).value;
|
|
736
|
-
}
|
|
737
|
-
const results = [];
|
|
738
|
-
let offset = 0;
|
|
739
|
-
for (const output of outputs) {
|
|
740
|
-
const result = decodeParam(output.type, cleanData, offset, output.components);
|
|
741
|
-
results.push(result.value);
|
|
742
|
-
offset += result.consumed;
|
|
743
|
-
}
|
|
744
|
-
return results;
|
|
745
|
-
}
|
|
746
|
-
function getErrorSelector(errorItem) {
|
|
747
|
-
const inputs = errorItem.inputs || [];
|
|
748
|
-
const types = inputs.map((input) => getTypeString(input.type, input.components));
|
|
749
|
-
const signature = `${errorItem.name}(${types.join(",")})`;
|
|
750
|
-
const hash = keccak_256(new TextEncoder().encode(signature));
|
|
751
|
-
return bytesToHex(hash.slice(0, 4));
|
|
752
|
-
}
|
|
753
|
-
function decodeErrorResult(config) {
|
|
754
|
-
const { abi, data } = config;
|
|
755
|
-
if (!data || data.length < 10) {
|
|
756
|
-
return null;
|
|
757
|
-
}
|
|
758
|
-
const selector = data.slice(0, 10).toLowerCase();
|
|
759
|
-
const cleanData = strip0x(data.slice(10));
|
|
760
|
-
const errors = abi.filter((item) => item.type === "error");
|
|
761
|
-
for (const errorItem of errors) {
|
|
762
|
-
const errorSelector = getErrorSelector(errorItem);
|
|
763
|
-
if (errorSelector.toLowerCase() === selector) {
|
|
764
|
-
const inputs = errorItem.inputs || [];
|
|
765
|
-
if (inputs.length === 0) {
|
|
766
|
-
return { errorName: errorItem.name };
|
|
767
|
-
}
|
|
768
|
-
const decodedArgs = [];
|
|
769
|
-
let offset = 0;
|
|
770
|
-
for (const input of inputs) {
|
|
771
|
-
const result = decodeParam(input.type, cleanData, offset, input.components);
|
|
772
|
-
decodedArgs.push(result.value);
|
|
773
|
-
offset += result.consumed;
|
|
774
|
-
}
|
|
775
|
-
return {
|
|
776
|
-
errorName: errorItem.name,
|
|
777
|
-
args: decodedArgs
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
return null;
|
|
782
|
-
}
|
|
783
|
-
// ../../node_modules/multiformats/dist/src/bytes.js
|
|
784
|
-
var empty = new Uint8Array(0);
|
|
785
|
-
function equals(aa, bb) {
|
|
786
|
-
if (aa === bb) {
|
|
787
|
-
return true;
|
|
788
|
-
}
|
|
789
|
-
if (aa.byteLength !== bb.byteLength) {
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
for (let ii = 0;ii < aa.byteLength; ii++) {
|
|
793
|
-
if (aa[ii] !== bb[ii]) {
|
|
794
|
-
return false;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
return true;
|
|
798
|
-
}
|
|
799
|
-
function coerce(o) {
|
|
800
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
801
|
-
return o;
|
|
802
|
-
}
|
|
803
|
-
if (o instanceof ArrayBuffer) {
|
|
804
|
-
return new Uint8Array(o);
|
|
805
|
-
}
|
|
806
|
-
if (ArrayBuffer.isView(o)) {
|
|
807
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
808
|
-
}
|
|
809
|
-
throw new Error("Unknown type, must be binary type");
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
// ../../node_modules/multiformats/dist/src/vendor/base-x.js
|
|
813
|
-
function base(ALPHABET, name) {
|
|
814
|
-
if (ALPHABET.length >= 255) {
|
|
815
|
-
throw new TypeError("Alphabet too long");
|
|
816
|
-
}
|
|
817
|
-
var BASE_MAP = new Uint8Array(256);
|
|
818
|
-
for (var j = 0;j < BASE_MAP.length; j++) {
|
|
819
|
-
BASE_MAP[j] = 255;
|
|
820
|
-
}
|
|
821
|
-
for (var i = 0;i < ALPHABET.length; i++) {
|
|
822
|
-
var x = ALPHABET.charAt(i);
|
|
823
|
-
var xc = x.charCodeAt(0);
|
|
824
|
-
if (BASE_MAP[xc] !== 255) {
|
|
825
|
-
throw new TypeError(x + " is ambiguous");
|
|
826
|
-
}
|
|
827
|
-
BASE_MAP[xc] = i;
|
|
828
|
-
}
|
|
829
|
-
var BASE = ALPHABET.length;
|
|
830
|
-
var LEADER = ALPHABET.charAt(0);
|
|
831
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
832
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
833
|
-
function encode(source) {
|
|
834
|
-
if (source instanceof Uint8Array)
|
|
835
|
-
;
|
|
836
|
-
else if (ArrayBuffer.isView(source)) {
|
|
837
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
838
|
-
} else if (Array.isArray(source)) {
|
|
839
|
-
source = Uint8Array.from(source);
|
|
840
|
-
}
|
|
841
|
-
if (!(source instanceof Uint8Array)) {
|
|
842
|
-
throw new TypeError("Expected Uint8Array");
|
|
843
|
-
}
|
|
844
|
-
if (source.length === 0) {
|
|
845
|
-
return "";
|
|
846
|
-
}
|
|
847
|
-
var zeroes = 0;
|
|
848
|
-
var length = 0;
|
|
849
|
-
var pbegin = 0;
|
|
850
|
-
var pend = source.length;
|
|
851
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
852
|
-
pbegin++;
|
|
853
|
-
zeroes++;
|
|
854
|
-
}
|
|
855
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
856
|
-
var b58 = new Uint8Array(size);
|
|
857
|
-
while (pbegin !== pend) {
|
|
858
|
-
var carry = source[pbegin];
|
|
859
|
-
var i2 = 0;
|
|
860
|
-
for (var it1 = size - 1;(carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
861
|
-
carry += 256 * b58[it1] >>> 0;
|
|
862
|
-
b58[it1] = carry % BASE >>> 0;
|
|
863
|
-
carry = carry / BASE >>> 0;
|
|
864
|
-
}
|
|
865
|
-
if (carry !== 0) {
|
|
866
|
-
throw new Error("Non-zero carry");
|
|
867
|
-
}
|
|
868
|
-
length = i2;
|
|
869
|
-
pbegin++;
|
|
870
|
-
}
|
|
871
|
-
var it2 = size - length;
|
|
872
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
873
|
-
it2++;
|
|
874
|
-
}
|
|
875
|
-
var str = LEADER.repeat(zeroes);
|
|
876
|
-
for (;it2 < size; ++it2) {
|
|
877
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
878
|
-
}
|
|
879
|
-
return str;
|
|
880
|
-
}
|
|
881
|
-
function decodeUnsafe(source) {
|
|
882
|
-
if (typeof source !== "string") {
|
|
883
|
-
throw new TypeError("Expected String");
|
|
884
|
-
}
|
|
885
|
-
if (source.length === 0) {
|
|
886
|
-
return new Uint8Array;
|
|
887
|
-
}
|
|
888
|
-
var psz = 0;
|
|
889
|
-
if (source[psz] === " ") {
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
var zeroes = 0;
|
|
893
|
-
var length = 0;
|
|
894
|
-
while (source[psz] === LEADER) {
|
|
895
|
-
zeroes++;
|
|
896
|
-
psz++;
|
|
897
|
-
}
|
|
898
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
899
|
-
var b256 = new Uint8Array(size);
|
|
900
|
-
while (source[psz]) {
|
|
901
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
902
|
-
if (carry === 255) {
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
var i2 = 0;
|
|
906
|
-
for (var it3 = size - 1;(carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
907
|
-
carry += BASE * b256[it3] >>> 0;
|
|
908
|
-
b256[it3] = carry % 256 >>> 0;
|
|
909
|
-
carry = carry / 256 >>> 0;
|
|
910
|
-
}
|
|
911
|
-
if (carry !== 0) {
|
|
912
|
-
throw new Error("Non-zero carry");
|
|
913
|
-
}
|
|
914
|
-
length = i2;
|
|
915
|
-
psz++;
|
|
916
|
-
}
|
|
917
|
-
if (source[psz] === " ") {
|
|
918
|
-
return;
|
|
919
|
-
}
|
|
920
|
-
var it4 = size - length;
|
|
921
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
922
|
-
it4++;
|
|
923
|
-
}
|
|
924
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
925
|
-
var j2 = zeroes;
|
|
926
|
-
while (it4 !== size) {
|
|
927
|
-
vch[j2++] = b256[it4++];
|
|
928
|
-
}
|
|
929
|
-
return vch;
|
|
930
|
-
}
|
|
931
|
-
function decode(string) {
|
|
932
|
-
var buffer = decodeUnsafe(string);
|
|
933
|
-
if (buffer) {
|
|
934
|
-
return buffer;
|
|
935
|
-
}
|
|
936
|
-
throw new Error(`Non-${name} character`);
|
|
937
|
-
}
|
|
938
|
-
return {
|
|
939
|
-
encode,
|
|
940
|
-
decodeUnsafe,
|
|
941
|
-
decode
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
var src = base;
|
|
945
|
-
var _brrp__multiformats_scope_baseX = src;
|
|
946
|
-
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
947
|
-
|
|
948
|
-
// ../../node_modules/multiformats/dist/src/bases/base.js
|
|
949
|
-
class Encoder {
|
|
950
|
-
name;
|
|
951
|
-
prefix;
|
|
952
|
-
baseEncode;
|
|
953
|
-
constructor(name, prefix, baseEncode) {
|
|
954
|
-
this.name = name;
|
|
955
|
-
this.prefix = prefix;
|
|
956
|
-
this.baseEncode = baseEncode;
|
|
957
|
-
}
|
|
958
|
-
encode(bytes) {
|
|
959
|
-
if (bytes instanceof Uint8Array) {
|
|
960
|
-
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
961
|
-
} else {
|
|
962
|
-
throw Error("Unknown type, must be binary type");
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
class Decoder {
|
|
968
|
-
name;
|
|
969
|
-
prefix;
|
|
970
|
-
baseDecode;
|
|
971
|
-
prefixCodePoint;
|
|
972
|
-
constructor(name, prefix, baseDecode) {
|
|
973
|
-
this.name = name;
|
|
974
|
-
this.prefix = prefix;
|
|
975
|
-
const prefixCodePoint = prefix.codePointAt(0);
|
|
976
|
-
if (prefixCodePoint === undefined) {
|
|
977
|
-
throw new Error("Invalid prefix character");
|
|
978
|
-
}
|
|
979
|
-
this.prefixCodePoint = prefixCodePoint;
|
|
980
|
-
this.baseDecode = baseDecode;
|
|
981
|
-
}
|
|
982
|
-
decode(text) {
|
|
983
|
-
if (typeof text === "string") {
|
|
984
|
-
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
985
|
-
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
986
|
-
}
|
|
987
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
988
|
-
} else {
|
|
989
|
-
throw Error("Can only multibase decode strings");
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
or(decoder) {
|
|
993
|
-
return or(this, decoder);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
class ComposedDecoder {
|
|
998
|
-
decoders;
|
|
999
|
-
constructor(decoders) {
|
|
1000
|
-
this.decoders = decoders;
|
|
1001
|
-
}
|
|
1002
|
-
or(decoder) {
|
|
1003
|
-
return or(this, decoder);
|
|
1004
|
-
}
|
|
1005
|
-
decode(input) {
|
|
1006
|
-
const prefix = input[0];
|
|
1007
|
-
const decoder = this.decoders[prefix];
|
|
1008
|
-
if (decoder != null) {
|
|
1009
|
-
return decoder.decode(input);
|
|
1010
|
-
} else {
|
|
1011
|
-
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
function or(left, right) {
|
|
1016
|
-
return new ComposedDecoder({
|
|
1017
|
-
...left.decoders ?? { [left.prefix]: left },
|
|
1018
|
-
...right.decoders ?? { [right.prefix]: right }
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
class Codec {
|
|
1023
|
-
name;
|
|
1024
|
-
prefix;
|
|
1025
|
-
baseEncode;
|
|
1026
|
-
baseDecode;
|
|
1027
|
-
encoder;
|
|
1028
|
-
decoder;
|
|
1029
|
-
constructor(name, prefix, baseEncode, baseDecode) {
|
|
1030
|
-
this.name = name;
|
|
1031
|
-
this.prefix = prefix;
|
|
1032
|
-
this.baseEncode = baseEncode;
|
|
1033
|
-
this.baseDecode = baseDecode;
|
|
1034
|
-
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
1035
|
-
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
1036
|
-
}
|
|
1037
|
-
encode(input) {
|
|
1038
|
-
return this.encoder.encode(input);
|
|
1039
|
-
}
|
|
1040
|
-
decode(input) {
|
|
1041
|
-
return this.decoder.decode(input);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
function from({ name, prefix, encode, decode }) {
|
|
1045
|
-
return new Codec(name, prefix, encode, decode);
|
|
1046
|
-
}
|
|
1047
|
-
function baseX({ name, prefix, alphabet }) {
|
|
1048
|
-
const { encode, decode } = base_x_default(alphabet, name);
|
|
1049
|
-
return from({
|
|
1050
|
-
prefix,
|
|
1051
|
-
name,
|
|
1052
|
-
encode,
|
|
1053
|
-
decode: (text) => coerce(decode(text))
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
function decode(string, alphabetIdx, bitsPerChar, name) {
|
|
1057
|
-
let end = string.length;
|
|
1058
|
-
while (string[end - 1] === "=") {
|
|
1059
|
-
--end;
|
|
1060
|
-
}
|
|
1061
|
-
const out = new Uint8Array(end * bitsPerChar / 8 | 0);
|
|
1062
|
-
let bits = 0;
|
|
1063
|
-
let buffer = 0;
|
|
1064
|
-
let written = 0;
|
|
1065
|
-
for (let i = 0;i < end; ++i) {
|
|
1066
|
-
const value = alphabetIdx[string[i]];
|
|
1067
|
-
if (value === undefined) {
|
|
1068
|
-
throw new SyntaxError(`Non-${name} character`);
|
|
1069
|
-
}
|
|
1070
|
-
buffer = buffer << bitsPerChar | value;
|
|
1071
|
-
bits += bitsPerChar;
|
|
1072
|
-
if (bits >= 8) {
|
|
1073
|
-
bits -= 8;
|
|
1074
|
-
out[written++] = 255 & buffer >> bits;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
|
|
1078
|
-
throw new SyntaxError("Unexpected end of data");
|
|
1079
|
-
}
|
|
1080
|
-
return out;
|
|
1081
|
-
}
|
|
1082
|
-
function encode(data, alphabet, bitsPerChar) {
|
|
1083
|
-
const pad = alphabet[alphabet.length - 1] === "=";
|
|
1084
|
-
const mask = (1 << bitsPerChar) - 1;
|
|
1085
|
-
let out = "";
|
|
1086
|
-
let bits = 0;
|
|
1087
|
-
let buffer = 0;
|
|
1088
|
-
for (let i = 0;i < data.length; ++i) {
|
|
1089
|
-
buffer = buffer << 8 | data[i];
|
|
1090
|
-
bits += 8;
|
|
1091
|
-
while (bits > bitsPerChar) {
|
|
1092
|
-
bits -= bitsPerChar;
|
|
1093
|
-
out += alphabet[mask & buffer >> bits];
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
if (bits !== 0) {
|
|
1097
|
-
out += alphabet[mask & buffer << bitsPerChar - bits];
|
|
1098
|
-
}
|
|
1099
|
-
if (pad) {
|
|
1100
|
-
while ((out.length * bitsPerChar & 7) !== 0) {
|
|
1101
|
-
out += "=";
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
return out;
|
|
1105
|
-
}
|
|
1106
|
-
function createAlphabetIdx(alphabet) {
|
|
1107
|
-
const alphabetIdx = {};
|
|
1108
|
-
for (let i = 0;i < alphabet.length; ++i) {
|
|
1109
|
-
alphabetIdx[alphabet[i]] = i;
|
|
1110
|
-
}
|
|
1111
|
-
return alphabetIdx;
|
|
1112
|
-
}
|
|
1113
|
-
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
1114
|
-
const alphabetIdx = createAlphabetIdx(alphabet);
|
|
1115
|
-
return from({
|
|
1116
|
-
prefix,
|
|
1117
|
-
name,
|
|
1118
|
-
encode(input) {
|
|
1119
|
-
return encode(input, alphabet, bitsPerChar);
|
|
1120
|
-
},
|
|
1121
|
-
decode(input) {
|
|
1122
|
-
return decode(input, alphabetIdx, bitsPerChar, name);
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
// ../../node_modules/multiformats/dist/src/bases/base32.js
|
|
1128
|
-
var base32 = rfc4648({
|
|
1129
|
-
prefix: "b",
|
|
1130
|
-
name: "base32",
|
|
1131
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567",
|
|
1132
|
-
bitsPerChar: 5
|
|
1133
|
-
});
|
|
1134
|
-
var base32upper = rfc4648({
|
|
1135
|
-
prefix: "B",
|
|
1136
|
-
name: "base32upper",
|
|
1137
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
1138
|
-
bitsPerChar: 5
|
|
1139
|
-
});
|
|
1140
|
-
var base32pad = rfc4648({
|
|
1141
|
-
prefix: "c",
|
|
1142
|
-
name: "base32pad",
|
|
1143
|
-
alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
|
|
1144
|
-
bitsPerChar: 5
|
|
1145
|
-
});
|
|
1146
|
-
var base32padupper = rfc4648({
|
|
1147
|
-
prefix: "C",
|
|
1148
|
-
name: "base32padupper",
|
|
1149
|
-
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
|
1150
|
-
bitsPerChar: 5
|
|
1151
|
-
});
|
|
1152
|
-
var base32hex = rfc4648({
|
|
1153
|
-
prefix: "v",
|
|
1154
|
-
name: "base32hex",
|
|
1155
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv",
|
|
1156
|
-
bitsPerChar: 5
|
|
1157
|
-
});
|
|
1158
|
-
var base32hexupper = rfc4648({
|
|
1159
|
-
prefix: "V",
|
|
1160
|
-
name: "base32hexupper",
|
|
1161
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
|
|
1162
|
-
bitsPerChar: 5
|
|
1163
|
-
});
|
|
1164
|
-
var base32hexpad = rfc4648({
|
|
1165
|
-
prefix: "t",
|
|
1166
|
-
name: "base32hexpad",
|
|
1167
|
-
alphabet: "0123456789abcdefghijklmnopqrstuv=",
|
|
1168
|
-
bitsPerChar: 5
|
|
1169
|
-
});
|
|
1170
|
-
var base32hexpadupper = rfc4648({
|
|
1171
|
-
prefix: "T",
|
|
1172
|
-
name: "base32hexpadupper",
|
|
1173
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
|
|
1174
|
-
bitsPerChar: 5
|
|
1175
|
-
});
|
|
1176
|
-
var base32z = rfc4648({
|
|
1177
|
-
prefix: "h",
|
|
1178
|
-
name: "base32z",
|
|
1179
|
-
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
|
|
1180
|
-
bitsPerChar: 5
|
|
1181
|
-
});
|
|
1182
|
-
|
|
1183
|
-
// ../../node_modules/multiformats/dist/src/bases/base36.js
|
|
1184
|
-
var base36 = baseX({
|
|
1185
|
-
prefix: "k",
|
|
1186
|
-
name: "base36",
|
|
1187
|
-
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
1188
|
-
});
|
|
1189
|
-
var base36upper = baseX({
|
|
1190
|
-
prefix: "K",
|
|
1191
|
-
name: "base36upper",
|
|
1192
|
-
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
1193
|
-
});
|
|
1194
|
-
|
|
1195
|
-
// ../../node_modules/multiformats/dist/src/bases/base58.js
|
|
1196
|
-
var base58btc = baseX({
|
|
1197
|
-
name: "base58btc",
|
|
1198
|
-
prefix: "z",
|
|
1199
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
1200
|
-
});
|
|
1201
|
-
var base58flickr = baseX({
|
|
1202
|
-
name: "base58flickr",
|
|
1203
|
-
prefix: "Z",
|
|
1204
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
1205
|
-
});
|
|
1206
|
-
|
|
1207
|
-
// ../../node_modules/multiformats/dist/src/vendor/varint.js
|
|
1208
|
-
var encode_1 = encode2;
|
|
1209
|
-
var MSB = 128;
|
|
1210
|
-
var REST = 127;
|
|
1211
|
-
var MSBALL = ~REST;
|
|
1212
|
-
var INT = Math.pow(2, 31);
|
|
1213
|
-
function encode2(num, out, offset) {
|
|
1214
|
-
out = out || [];
|
|
1215
|
-
offset = offset || 0;
|
|
1216
|
-
var oldOffset = offset;
|
|
1217
|
-
while (num >= INT) {
|
|
1218
|
-
out[offset++] = num & 255 | MSB;
|
|
1219
|
-
num /= 128;
|
|
1220
|
-
}
|
|
1221
|
-
while (num & MSBALL) {
|
|
1222
|
-
out[offset++] = num & 255 | MSB;
|
|
1223
|
-
num >>>= 7;
|
|
1224
|
-
}
|
|
1225
|
-
out[offset] = num | 0;
|
|
1226
|
-
encode2.bytes = offset - oldOffset + 1;
|
|
1227
|
-
return out;
|
|
1228
|
-
}
|
|
1229
|
-
var decode2 = read;
|
|
1230
|
-
var MSB$1 = 128;
|
|
1231
|
-
var REST$1 = 127;
|
|
1232
|
-
function read(buf, offset) {
|
|
1233
|
-
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
|
|
1234
|
-
do {
|
|
1235
|
-
if (counter >= l) {
|
|
1236
|
-
read.bytes = 0;
|
|
1237
|
-
throw new RangeError("Could not decode varint");
|
|
1238
|
-
}
|
|
1239
|
-
b = buf[counter++];
|
|
1240
|
-
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
|
|
1241
|
-
shift += 7;
|
|
1242
|
-
} while (b >= MSB$1);
|
|
1243
|
-
read.bytes = counter - offset;
|
|
1244
|
-
return res;
|
|
1245
|
-
}
|
|
1246
|
-
var N1 = Math.pow(2, 7);
|
|
1247
|
-
var N2 = Math.pow(2, 14);
|
|
1248
|
-
var N3 = Math.pow(2, 21);
|
|
1249
|
-
var N4 = Math.pow(2, 28);
|
|
1250
|
-
var N5 = Math.pow(2, 35);
|
|
1251
|
-
var N6 = Math.pow(2, 42);
|
|
1252
|
-
var N7 = Math.pow(2, 49);
|
|
1253
|
-
var N8 = Math.pow(2, 56);
|
|
1254
|
-
var N9 = Math.pow(2, 63);
|
|
1255
|
-
var length = function(value) {
|
|
1256
|
-
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
|
|
1257
|
-
};
|
|
1258
|
-
var varint = {
|
|
1259
|
-
encode: encode_1,
|
|
1260
|
-
decode: decode2,
|
|
1261
|
-
encodingLength: length
|
|
1262
|
-
};
|
|
1263
|
-
var _brrp_varint = varint;
|
|
1264
|
-
var varint_default = _brrp_varint;
|
|
1265
|
-
|
|
1266
|
-
// ../../node_modules/multiformats/dist/src/varint.js
|
|
1267
|
-
function decode3(data, offset = 0) {
|
|
1268
|
-
const code = varint_default.decode(data, offset);
|
|
1269
|
-
return [code, varint_default.decode.bytes];
|
|
1270
|
-
}
|
|
1271
|
-
function encodeTo(int, target, offset = 0) {
|
|
1272
|
-
varint_default.encode(int, target, offset);
|
|
1273
|
-
return target;
|
|
1274
|
-
}
|
|
1275
|
-
function encodingLength(int) {
|
|
1276
|
-
return varint_default.encodingLength(int);
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
// ../../node_modules/multiformats/dist/src/hashes/digest.js
|
|
1280
|
-
function create(code, digest) {
|
|
1281
|
-
const size = digest.byteLength;
|
|
1282
|
-
const sizeOffset = encodingLength(code);
|
|
1283
|
-
const digestOffset = sizeOffset + encodingLength(size);
|
|
1284
|
-
const bytes = new Uint8Array(digestOffset + size);
|
|
1285
|
-
encodeTo(code, bytes, 0);
|
|
1286
|
-
encodeTo(size, bytes, sizeOffset);
|
|
1287
|
-
bytes.set(digest, digestOffset);
|
|
1288
|
-
return new Digest(code, size, digest, bytes);
|
|
1289
|
-
}
|
|
1290
|
-
function decode4(multihash) {
|
|
1291
|
-
const bytes = coerce(multihash);
|
|
1292
|
-
const [code, sizeOffset] = decode3(bytes);
|
|
1293
|
-
const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
|
|
1294
|
-
const digest = bytes.subarray(sizeOffset + digestOffset);
|
|
1295
|
-
if (digest.byteLength !== size) {
|
|
1296
|
-
throw new Error("Incorrect length");
|
|
1297
|
-
}
|
|
1298
|
-
return new Digest(code, size, digest, bytes);
|
|
1299
|
-
}
|
|
1300
|
-
function equals2(a, b) {
|
|
1301
|
-
if (a === b) {
|
|
1302
|
-
return true;
|
|
1303
|
-
} else {
|
|
1304
|
-
const data = b;
|
|
1305
|
-
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
class Digest {
|
|
1310
|
-
code;
|
|
1311
|
-
size;
|
|
1312
|
-
digest;
|
|
1313
|
-
bytes;
|
|
1314
|
-
constructor(code, size, digest, bytes) {
|
|
1315
|
-
this.code = code;
|
|
1316
|
-
this.size = size;
|
|
1317
|
-
this.digest = digest;
|
|
1318
|
-
this.bytes = bytes;
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
// ../../node_modules/multiformats/dist/src/cid.js
|
|
1323
|
-
function format(link, base2) {
|
|
1324
|
-
const { bytes, version } = link;
|
|
1325
|
-
switch (version) {
|
|
1326
|
-
case 0:
|
|
1327
|
-
return toStringV0(bytes, baseCache(link), base2 ?? base58btc.encoder);
|
|
1328
|
-
default:
|
|
1329
|
-
return toStringV1(bytes, baseCache(link), base2 ?? base32.encoder);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
var cache = new WeakMap;
|
|
1333
|
-
function baseCache(cid) {
|
|
1334
|
-
const baseCache2 = cache.get(cid);
|
|
1335
|
-
if (baseCache2 == null) {
|
|
1336
|
-
const baseCache3 = new Map;
|
|
1337
|
-
cache.set(cid, baseCache3);
|
|
1338
|
-
return baseCache3;
|
|
1339
|
-
}
|
|
1340
|
-
return baseCache2;
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
class CID {
|
|
1344
|
-
code;
|
|
1345
|
-
version;
|
|
1346
|
-
multihash;
|
|
1347
|
-
bytes;
|
|
1348
|
-
"/";
|
|
1349
|
-
constructor(version, code, multihash, bytes) {
|
|
1350
|
-
this.code = code;
|
|
1351
|
-
this.version = version;
|
|
1352
|
-
this.multihash = multihash;
|
|
1353
|
-
this.bytes = bytes;
|
|
1354
|
-
this["/"] = bytes;
|
|
1355
|
-
}
|
|
1356
|
-
get asCID() {
|
|
1357
|
-
return this;
|
|
1358
|
-
}
|
|
1359
|
-
get byteOffset() {
|
|
1360
|
-
return this.bytes.byteOffset;
|
|
1361
|
-
}
|
|
1362
|
-
get byteLength() {
|
|
1363
|
-
return this.bytes.byteLength;
|
|
1364
|
-
}
|
|
1365
|
-
toV0() {
|
|
1366
|
-
switch (this.version) {
|
|
1367
|
-
case 0: {
|
|
1368
|
-
return this;
|
|
1369
|
-
}
|
|
1370
|
-
case 1: {
|
|
1371
|
-
const { code, multihash } = this;
|
|
1372
|
-
if (code !== DAG_PB_CODE) {
|
|
1373
|
-
throw new Error("Cannot convert a non dag-pb CID to CIDv0");
|
|
1374
|
-
}
|
|
1375
|
-
if (multihash.code !== SHA_256_CODE) {
|
|
1376
|
-
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
|
|
1377
|
-
}
|
|
1378
|
-
return CID.createV0(multihash);
|
|
1379
|
-
}
|
|
1380
|
-
default: {
|
|
1381
|
-
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
toV1() {
|
|
1386
|
-
switch (this.version) {
|
|
1387
|
-
case 0: {
|
|
1388
|
-
const { code, digest } = this.multihash;
|
|
1389
|
-
const multihash = create(code, digest);
|
|
1390
|
-
return CID.createV1(this.code, multihash);
|
|
1391
|
-
}
|
|
1392
|
-
case 1: {
|
|
1393
|
-
return this;
|
|
1394
|
-
}
|
|
1395
|
-
default: {
|
|
1396
|
-
throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
equals(other) {
|
|
1401
|
-
return CID.equals(this, other);
|
|
1402
|
-
}
|
|
1403
|
-
static equals(self, other) {
|
|
1404
|
-
const unknown = other;
|
|
1405
|
-
return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
|
|
1406
|
-
}
|
|
1407
|
-
toString(base2) {
|
|
1408
|
-
return format(this, base2);
|
|
1409
|
-
}
|
|
1410
|
-
toJSON() {
|
|
1411
|
-
return { "/": format(this) };
|
|
1412
|
-
}
|
|
1413
|
-
link() {
|
|
1414
|
-
return this;
|
|
1415
|
-
}
|
|
1416
|
-
[Symbol.toStringTag] = "CID";
|
|
1417
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
1418
|
-
return `CID(${this.toString()})`;
|
|
1419
|
-
}
|
|
1420
|
-
static asCID(input) {
|
|
1421
|
-
if (input == null) {
|
|
1422
|
-
return null;
|
|
1423
|
-
}
|
|
1424
|
-
const value = input;
|
|
1425
|
-
if (value instanceof CID) {
|
|
1426
|
-
return value;
|
|
1427
|
-
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
|
|
1428
|
-
const { version, code, multihash, bytes } = value;
|
|
1429
|
-
return new CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
|
|
1430
|
-
} else if (value[cidSymbol] === true) {
|
|
1431
|
-
const { version, multihash, code } = value;
|
|
1432
|
-
const digest = decode4(multihash);
|
|
1433
|
-
return CID.create(version, code, digest);
|
|
1434
|
-
} else {
|
|
1435
|
-
return null;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
static create(version, code, digest) {
|
|
1439
|
-
if (typeof code !== "number") {
|
|
1440
|
-
throw new Error("String codecs are no longer supported");
|
|
1441
|
-
}
|
|
1442
|
-
if (!(digest.bytes instanceof Uint8Array)) {
|
|
1443
|
-
throw new Error("Invalid digest");
|
|
1444
|
-
}
|
|
1445
|
-
switch (version) {
|
|
1446
|
-
case 0: {
|
|
1447
|
-
if (code !== DAG_PB_CODE) {
|
|
1448
|
-
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
|
|
1449
|
-
} else {
|
|
1450
|
-
return new CID(version, code, digest, digest.bytes);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
case 1: {
|
|
1454
|
-
const bytes = encodeCID(version, code, digest.bytes);
|
|
1455
|
-
return new CID(version, code, digest, bytes);
|
|
1456
|
-
}
|
|
1457
|
-
default: {
|
|
1458
|
-
throw new Error("Invalid version");
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
static createV0(digest) {
|
|
1463
|
-
return CID.create(0, DAG_PB_CODE, digest);
|
|
1464
|
-
}
|
|
1465
|
-
static createV1(code, digest) {
|
|
1466
|
-
return CID.create(1, code, digest);
|
|
1467
|
-
}
|
|
1468
|
-
static decode(bytes) {
|
|
1469
|
-
const [cid, remainder] = CID.decodeFirst(bytes);
|
|
1470
|
-
if (remainder.length !== 0) {
|
|
1471
|
-
throw new Error("Incorrect length");
|
|
1472
|
-
}
|
|
1473
|
-
return cid;
|
|
1474
|
-
}
|
|
1475
|
-
static decodeFirst(bytes) {
|
|
1476
|
-
const specs = CID.inspectBytes(bytes);
|
|
1477
|
-
const prefixSize = specs.size - specs.multihashSize;
|
|
1478
|
-
const multihashBytes = coerce(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
|
|
1479
|
-
if (multihashBytes.byteLength !== specs.multihashSize) {
|
|
1480
|
-
throw new Error("Incorrect length");
|
|
1481
|
-
}
|
|
1482
|
-
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
|
|
1483
|
-
const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
|
|
1484
|
-
const cid = specs.version === 0 ? CID.createV0(digest) : CID.createV1(specs.codec, digest);
|
|
1485
|
-
return [cid, bytes.subarray(specs.size)];
|
|
1486
|
-
}
|
|
1487
|
-
static inspectBytes(initialBytes) {
|
|
1488
|
-
let offset = 0;
|
|
1489
|
-
const next = () => {
|
|
1490
|
-
const [i, length2] = decode3(initialBytes.subarray(offset));
|
|
1491
|
-
offset += length2;
|
|
1492
|
-
return i;
|
|
1493
|
-
};
|
|
1494
|
-
let version = next();
|
|
1495
|
-
let codec = DAG_PB_CODE;
|
|
1496
|
-
if (version === 18) {
|
|
1497
|
-
version = 0;
|
|
1498
|
-
offset = 0;
|
|
1499
|
-
} else {
|
|
1500
|
-
codec = next();
|
|
1501
|
-
}
|
|
1502
|
-
if (version !== 0 && version !== 1) {
|
|
1503
|
-
throw new RangeError(`Invalid CID version ${version}`);
|
|
1504
|
-
}
|
|
1505
|
-
const prefixSize = offset;
|
|
1506
|
-
const multihashCode = next();
|
|
1507
|
-
const digestSize = next();
|
|
1508
|
-
const size = offset + digestSize;
|
|
1509
|
-
const multihashSize = size - prefixSize;
|
|
1510
|
-
return { version, codec, multihashCode, digestSize, multihashSize, size };
|
|
1511
|
-
}
|
|
1512
|
-
static parse(source, base2) {
|
|
1513
|
-
const [prefix, bytes] = parseCIDtoBytes(source, base2);
|
|
1514
|
-
const cid = CID.decode(bytes);
|
|
1515
|
-
if (cid.version === 0 && source[0] !== "Q") {
|
|
1516
|
-
throw Error("Version 0 CID string must not include multibase prefix");
|
|
1517
|
-
}
|
|
1518
|
-
baseCache(cid).set(prefix, source);
|
|
1519
|
-
return cid;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
function parseCIDtoBytes(source, base2) {
|
|
1523
|
-
switch (source[0]) {
|
|
1524
|
-
case "Q": {
|
|
1525
|
-
const decoder = base2 ?? base58btc;
|
|
1526
|
-
return [
|
|
1527
|
-
base58btc.prefix,
|
|
1528
|
-
decoder.decode(`${base58btc.prefix}${source}`)
|
|
1529
|
-
];
|
|
1530
|
-
}
|
|
1531
|
-
case base58btc.prefix: {
|
|
1532
|
-
const decoder = base2 ?? base58btc;
|
|
1533
|
-
return [base58btc.prefix, decoder.decode(source)];
|
|
1534
|
-
}
|
|
1535
|
-
case base32.prefix: {
|
|
1536
|
-
const decoder = base2 ?? base32;
|
|
1537
|
-
return [base32.prefix, decoder.decode(source)];
|
|
1538
|
-
}
|
|
1539
|
-
case base36.prefix: {
|
|
1540
|
-
const decoder = base2 ?? base36;
|
|
1541
|
-
return [base36.prefix, decoder.decode(source)];
|
|
1542
|
-
}
|
|
1543
|
-
default: {
|
|
1544
|
-
if (base2 == null) {
|
|
1545
|
-
throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");
|
|
1546
|
-
}
|
|
1547
|
-
return [source[0], base2.decode(source)];
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
function toStringV0(bytes, cache2, base2) {
|
|
1552
|
-
const { prefix } = base2;
|
|
1553
|
-
if (prefix !== base58btc.prefix) {
|
|
1554
|
-
throw Error(`Cannot string encode V0 in ${base2.name} encoding`);
|
|
1555
|
-
}
|
|
1556
|
-
const cid = cache2.get(prefix);
|
|
1557
|
-
if (cid == null) {
|
|
1558
|
-
const cid2 = base2.encode(bytes).slice(1);
|
|
1559
|
-
cache2.set(prefix, cid2);
|
|
1560
|
-
return cid2;
|
|
1561
|
-
} else {
|
|
1562
|
-
return cid;
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
function toStringV1(bytes, cache2, base2) {
|
|
1566
|
-
const { prefix } = base2;
|
|
1567
|
-
const cid = cache2.get(prefix);
|
|
1568
|
-
if (cid == null) {
|
|
1569
|
-
const cid2 = base2.encode(bytes);
|
|
1570
|
-
cache2.set(prefix, cid2);
|
|
1571
|
-
return cid2;
|
|
1572
|
-
} else {
|
|
1573
|
-
return cid;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
var DAG_PB_CODE = 112;
|
|
1577
|
-
var SHA_256_CODE = 18;
|
|
1578
|
-
function encodeCID(version, code, multihash) {
|
|
1579
|
-
const codeOffset = encodingLength(version);
|
|
1580
|
-
const hashOffset = codeOffset + encodingLength(code);
|
|
1581
|
-
const bytes = new Uint8Array(hashOffset + multihash.byteLength);
|
|
1582
|
-
encodeTo(version, bytes, 0);
|
|
1583
|
-
encodeTo(code, bytes, codeOffset);
|
|
1584
|
-
bytes.set(multihash, hashOffset);
|
|
1585
|
-
return bytes;
|
|
1586
|
-
}
|
|
1587
|
-
var cidSymbol = Symbol.for("@ipld/js-cid/CID");
|
|
1588
|
-
|
|
1589
|
-
// src/cid.ts
|
|
1590
|
-
function cidV0ToHex(cidV0) {
|
|
1591
|
-
const cid = CID.parse(cidV0, base58btc);
|
|
1592
|
-
if (cid.version !== 0) {
|
|
1593
|
-
throw new Error(`Expected CIDv0, got CIDv${cid.version}`);
|
|
1594
|
-
}
|
|
1595
|
-
if (cid.multihash.code !== 18) {
|
|
1596
|
-
throw new Error("Unsupported hash algorithm. Only SHA-256 is supported for CIDv0.");
|
|
1597
|
-
}
|
|
1598
|
-
const digest = cid.multihash.digest;
|
|
1599
|
-
const hexString = `0x${Array.from(digest).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
1600
|
-
return hexString;
|
|
1601
|
-
}
|
|
1602
|
-
function cidV0ToUint8Array(cidV0) {
|
|
1603
|
-
const cid = CID.parse(cidV0, base58btc);
|
|
1604
|
-
if (cid.version !== 0) {
|
|
1605
|
-
throw new Error(`Expected CIDv0, got CIDv${cid.version}`);
|
|
1606
|
-
}
|
|
1607
|
-
if (cid.multihash.code !== 18) {
|
|
1608
|
-
throw new Error("Unsupported hash algorithm. Only SHA-256 is supported for CIDv0.");
|
|
1609
|
-
}
|
|
1610
|
-
return cid.multihash.digest;
|
|
1611
|
-
}
|
|
1612
|
-
// src/address.ts
|
|
1613
|
-
function uint256ToAddress(uint256) {
|
|
1614
|
-
const hex = uint256.toString(16);
|
|
1615
|
-
const paddedHex = hex.padStart(64, "0");
|
|
1616
|
-
const addressHex = paddedHex.slice(-40);
|
|
1617
|
-
return `0x${addressHex}`;
|
|
1618
|
-
}
|
|
1619
|
-
// src/constants.ts
|
|
1620
|
-
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1621
|
-
// src/errors.ts
|
|
1622
|
-
class CirclesError extends Error {
|
|
1623
|
-
name;
|
|
1624
|
-
code;
|
|
1625
|
-
source;
|
|
1626
|
-
cause;
|
|
1627
|
-
context;
|
|
1628
|
-
constructor(name, message, options) {
|
|
1629
|
-
super(message);
|
|
1630
|
-
this.name = name;
|
|
1631
|
-
this.code = options?.code;
|
|
1632
|
-
this.source = options?.source ?? "UNKNOWN";
|
|
1633
|
-
this.cause = options?.cause;
|
|
1634
|
-
this.context = options?.context;
|
|
1635
|
-
if (Error.captureStackTrace) {
|
|
1636
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
toJSON() {
|
|
1640
|
-
return {
|
|
1641
|
-
name: this.name,
|
|
1642
|
-
message: this.message,
|
|
1643
|
-
code: this.code,
|
|
1644
|
-
source: this.source,
|
|
1645
|
-
context: this.context,
|
|
1646
|
-
cause: this.cause instanceof Error ? {
|
|
1647
|
-
name: this.cause.name,
|
|
1648
|
-
message: this.cause.message
|
|
1649
|
-
} : this.cause,
|
|
1650
|
-
stack: this.stack
|
|
1651
|
-
};
|
|
1652
|
-
}
|
|
1653
|
-
toString() {
|
|
1654
|
-
let result = `[${this.source}] ${this.name}: ${this.message}`;
|
|
1655
|
-
if (this.code) {
|
|
1656
|
-
result += ` (Code: ${this.code})`;
|
|
1657
|
-
}
|
|
1658
|
-
if (this.context) {
|
|
1659
|
-
result += `
|
|
1660
|
-
Context: ${JSON.stringify(this.context, null, 2)}`;
|
|
1661
|
-
}
|
|
1662
|
-
return result;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
class ValidationError extends CirclesError {
|
|
1667
|
-
constructor(message, options) {
|
|
1668
|
-
super("ValidationError", message, { ...options, source: "VALIDATION" });
|
|
1669
|
-
}
|
|
1670
|
-
static invalidAddress(address) {
|
|
1671
|
-
return new ValidationError("Invalid Ethereum address", {
|
|
1672
|
-
code: "VALIDATION_INVALID_ADDRESS",
|
|
1673
|
-
context: { address }
|
|
1674
|
-
});
|
|
1675
|
-
}
|
|
1676
|
-
static invalidAmount(amount, reason) {
|
|
1677
|
-
return new ValidationError(reason || "Invalid amount", {
|
|
1678
|
-
code: "VALIDATION_INVALID_AMOUNT",
|
|
1679
|
-
context: { amount, reason }
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
static missingParameter(paramName) {
|
|
1683
|
-
return new ValidationError(`Missing required parameter: ${paramName}`, {
|
|
1684
|
-
code: "VALIDATION_MISSING_PARAM",
|
|
1685
|
-
context: { paramName }
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
static invalidParameter(paramName, value, reason) {
|
|
1689
|
-
return new ValidationError(`Invalid parameter '${paramName}': ${reason || "value is invalid"}`, {
|
|
1690
|
-
code: "VALIDATION_INVALID_PARAM",
|
|
1691
|
-
context: { paramName, value, reason }
|
|
1692
|
-
});
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
class EncodingError extends CirclesError {
|
|
1697
|
-
constructor(message, options) {
|
|
1698
|
-
super("EncodingError", message, { ...options, source: "ENCODING" });
|
|
1699
|
-
}
|
|
1700
|
-
static abiEncoding(functionName, cause) {
|
|
1701
|
-
return new EncodingError("Failed to encode ABI data", {
|
|
1702
|
-
code: "ENCODING_ABI_FAILED",
|
|
1703
|
-
cause,
|
|
1704
|
-
context: { functionName }
|
|
1705
|
-
});
|
|
1706
|
-
}
|
|
1707
|
-
static cidConversion(cid, cause) {
|
|
1708
|
-
return new EncodingError("Failed to convert CID", {
|
|
1709
|
-
code: "ENCODING_CID_FAILED",
|
|
1710
|
-
cause,
|
|
1711
|
-
context: { cid }
|
|
1712
|
-
});
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
function wrapError(error, source = "UNKNOWN") {
|
|
1716
|
-
if (error instanceof CirclesError) {
|
|
1717
|
-
return error;
|
|
1718
|
-
}
|
|
1719
|
-
if (error instanceof Error) {
|
|
1720
|
-
return new CirclesError(error.name || "UnknownError", error.message, {
|
|
1721
|
-
source,
|
|
1722
|
-
cause: error
|
|
1723
|
-
});
|
|
1724
|
-
}
|
|
1725
|
-
return new CirclesError("UnknownError", String(error), {
|
|
1726
|
-
source,
|
|
1727
|
-
cause: error
|
|
1728
|
-
});
|
|
1729
|
-
}
|
|
1730
|
-
function isCirclesError(error) {
|
|
1731
|
-
return error instanceof CirclesError;
|
|
1732
|
-
}
|
|
1733
|
-
function getErrorMessage(error) {
|
|
1734
|
-
if (isCirclesError(error)) {
|
|
1735
|
-
return error.message;
|
|
1736
|
-
}
|
|
1737
|
-
if (error instanceof Error) {
|
|
1738
|
-
return error.message;
|
|
1739
|
-
}
|
|
1740
|
-
return String(error);
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
// src/contractErrors.ts
|
|
1744
|
-
var ERROR_CODE_MESSAGES = {
|
|
1745
|
-
0: "Avatar already registered",
|
|
1746
|
-
1: "Avatar must be registered before inviting",
|
|
1747
|
-
2: "Invalid invitation",
|
|
1748
|
-
3: "Avatar must be registered",
|
|
1749
|
-
4: "Only self can register",
|
|
1750
|
-
5: "Maximum value reached",
|
|
1751
|
-
6: "Inflationary supply already set",
|
|
1752
|
-
7: "Group has no collateral",
|
|
1753
|
-
161: "Trust to zero address is not allowed",
|
|
1754
|
-
16: "Invalid parameter"
|
|
1755
|
-
};
|
|
1756
|
-
function extractErrorData(error) {
|
|
1757
|
-
if (error?.details && typeof error.details === "string") {
|
|
1758
|
-
const match = error.details.match(/err:\s*(0x[0-9a-fA-F]+)/);
|
|
1759
|
-
if (match) {
|
|
1760
|
-
return match[1];
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
if (error?.data && typeof error.data === "string" && error.data.startsWith("0x")) {
|
|
1764
|
-
return error.data;
|
|
1765
|
-
}
|
|
1766
|
-
let currentError = error;
|
|
1767
|
-
while (currentError) {
|
|
1768
|
-
if (currentError.data && typeof currentError.data === "string") {
|
|
1769
|
-
return currentError.data;
|
|
1770
|
-
}
|
|
1771
|
-
currentError = currentError.cause;
|
|
1772
|
-
}
|
|
1773
|
-
return null;
|
|
1774
|
-
}
|
|
1775
|
-
function formatErrorMessage(errorName, args, errorAbi) {
|
|
1776
|
-
if (!args || args.length === 0) {
|
|
1777
|
-
return errorName;
|
|
1778
|
-
}
|
|
1779
|
-
if (!errorAbi || !errorAbi.inputs) {
|
|
1780
|
-
const formattedArgs = args.map((arg) => {
|
|
1781
|
-
if (typeof arg === "bigint") {
|
|
1782
|
-
return arg.toString();
|
|
1783
|
-
}
|
|
1784
|
-
return String(arg);
|
|
1785
|
-
}).join(", ");
|
|
1786
|
-
return `${errorName}(${formattedArgs})`;
|
|
1787
|
-
}
|
|
1788
|
-
const codeIndex = errorAbi.inputs.findIndex((input) => input.name === "code" || input.name === "" && input.type === "uint8");
|
|
1789
|
-
let baseMessage = errorName;
|
|
1790
|
-
let detailsParts = [];
|
|
1791
|
-
if (codeIndex !== -1) {
|
|
1792
|
-
const code = Number(args[codeIndex]);
|
|
1793
|
-
const humanMessage = ERROR_CODE_MESSAGES[code];
|
|
1794
|
-
if (humanMessage) {
|
|
1795
|
-
baseMessage = humanMessage;
|
|
1796
|
-
}
|
|
1797
|
-
}
|
|
1798
|
-
errorAbi.inputs.forEach((input, index) => {
|
|
1799
|
-
const arg = args[index];
|
|
1800
|
-
const name = input.name || `arg${index}`;
|
|
1801
|
-
if (!input.name && input.type === "uint8") {
|
|
1802
|
-
return;
|
|
1803
|
-
}
|
|
1804
|
-
let formattedValue;
|
|
1805
|
-
if (typeof arg === "bigint") {
|
|
1806
|
-
formattedValue = arg.toString();
|
|
1807
|
-
} else if (typeof arg === "string" && arg.startsWith("0x")) {
|
|
1808
|
-
formattedValue = arg;
|
|
1809
|
-
} else {
|
|
1810
|
-
formattedValue = String(arg);
|
|
1811
|
-
}
|
|
1812
|
-
if (name === "code" || input.type === "uint8") {
|
|
1813
|
-
formattedValue = `0x${Number(arg).toString(16)}`;
|
|
1814
|
-
}
|
|
1815
|
-
detailsParts.push(`${name}: ${formattedValue}`);
|
|
1816
|
-
});
|
|
1817
|
-
if (detailsParts.length > 0) {
|
|
1818
|
-
return `${baseMessage} (${detailsParts.join(", ")})`;
|
|
1819
|
-
}
|
|
1820
|
-
return baseMessage;
|
|
1821
|
-
}
|
|
1822
|
-
function parseContractError(error, abi) {
|
|
1823
|
-
const errorData = extractErrorData(error);
|
|
1824
|
-
if (!errorData) {
|
|
1825
|
-
return null;
|
|
1826
|
-
}
|
|
1827
|
-
const decoded = decodeErrorResult({ abi, data: errorData });
|
|
1828
|
-
if (!decoded) {
|
|
1829
|
-
return null;
|
|
1830
|
-
}
|
|
1831
|
-
const errorAbi = abi.find((item) => item.type === "error" && item.name === decoded.errorName);
|
|
1832
|
-
const selector = errorData.slice(0, 10);
|
|
1833
|
-
const formattedMessage = formatErrorMessage(decoded.errorName, decoded.args, errorAbi);
|
|
1834
|
-
return {
|
|
1835
|
-
errorName: decoded.errorName,
|
|
1836
|
-
args: decoded.args,
|
|
1837
|
-
selector,
|
|
1838
|
-
rawData: errorData,
|
|
1839
|
-
formattedMessage
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
class ContractError extends CirclesError {
|
|
1844
|
-
decodedError;
|
|
1845
|
-
constructor(message, options) {
|
|
1846
|
-
super("ContractError", message, { ...options, source: "CORE" });
|
|
1847
|
-
this.decodedError = options?.decodedError;
|
|
1848
|
-
}
|
|
1849
|
-
static fromTransactionError(error, abi, context) {
|
|
1850
|
-
const decoded = parseContractError(error, abi);
|
|
1851
|
-
if (decoded) {
|
|
1852
|
-
return new ContractError(`Transaction failed: ${decoded.formattedMessage}`, {
|
|
1853
|
-
code: decoded.selector,
|
|
1854
|
-
cause: error,
|
|
1855
|
-
context: {
|
|
1856
|
-
...context,
|
|
1857
|
-
errorName: decoded.errorName,
|
|
1858
|
-
errorArgs: decoded.args
|
|
1859
|
-
},
|
|
1860
|
-
decodedError: decoded
|
|
1861
|
-
});
|
|
1862
|
-
}
|
|
1863
|
-
const message = error?.message || String(error);
|
|
1864
|
-
return new ContractError(`Transaction failed: ${message}`, {
|
|
1865
|
-
cause: error,
|
|
1866
|
-
context
|
|
1867
|
-
});
|
|
1868
|
-
}
|
|
1869
|
-
toString() {
|
|
1870
|
-
let result = super.toString();
|
|
1871
|
-
if (this.decodedError) {
|
|
1872
|
-
result += `
|
|
1873
|
-
Decoded Error: ${this.decodedError.formattedMessage}`;
|
|
1874
|
-
if (this.decodedError.args && this.decodedError.args.length > 0) {
|
|
1875
|
-
result += `
|
|
1876
|
-
Arguments: ${JSON.stringify(this.decodedError.args, (_, v) => typeof v === "bigint" ? v.toString() : v)}`;
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
return result;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
export {
|
|
1883
|
-
wrapError,
|
|
1884
|
-
uint256ToAddress,
|
|
1885
|
-
parseContractError,
|
|
1886
|
-
isCirclesError,
|
|
1887
|
-
getErrorMessage,
|
|
1888
|
-
encodeFunctionData,
|
|
1889
|
-
decodeFunctionResult,
|
|
1890
|
-
decodeErrorResult,
|
|
1891
|
-
cidV0ToUint8Array,
|
|
1892
|
-
cidV0ToHex,
|
|
1893
|
-
checksumAddress,
|
|
1894
|
-
bytesToHex,
|
|
1895
|
-
ZERO_ADDRESS,
|
|
1896
|
-
ValidationError,
|
|
1897
|
-
EncodingError,
|
|
1898
|
-
ContractError,
|
|
1899
|
-
CirclesError,
|
|
1900
|
-
CirclesConverter
|
|
1901
|
-
};
|
|
1
|
+
class d${static ONE_64=1n<<64n;static GAMMA_64=18443079296116538654n;static BETA_64=18450409579521241655n;static SECONDS_PER_DAY=86400n;static INFLATION_DAY_ZERO_UNIX=1602720000n;static ATTO_FACTOR=1000000000000000000n;static FACTOR_1E12=1000000000000n;static V1_ACCURACY=100000000n;static V1_INFLATION_PCT_NUM=107n;static V1_INFLATION_PCT_DEN=100n;static PERIOD_SEC=31556952n;static mul64(J,Q){return J*Q>>64n}static mulU(J,Q){return J*Q>>64n}static pow64(J,Q){let $=J,q=Q,Y=this.ONE_64;while(q>0n){if((q&1n)===1n)Y=this.mul64(Y,$);$=this.mul64($,$),q>>=1n}return Y}static ONE_36=1000000000000000000000000000000000000000n;static GAMMA_36=999801332008598957430613406568191166n;static BETA_36=1000198707468214629156271489013303962n;static mul36(J,Q){return J*Q/this.ONE_36}static pow36(J,Q){let $=this.ONE_36,q=J,Y=Q;while(Y>0n){if((Y&1n)===1n)$=this.mul36($,q);q=this.mul36(q,q),Y>>=1n}return $}static attoCirclesToCircles(J){if(J===0n)return 0;let Q=J/this.ATTO_FACTOR,$=J%this.ATTO_FACTOR,q=BigInt(Number.MAX_SAFE_INTEGER);if(Q>q||Q<-q)throw RangeError("Atto value’s integer component exceeds JS double precision.");return Number(Q)+Number($)/Number(this.ATTO_FACTOR)}static circlesToAttoCircles(J){return BigInt(Math.trunc(J*Number(this.ATTO_FACTOR)))}static inflationaryToDemurrage(J,Q){return this.mulU(this.pow64(this.GAMMA_64,Q),J)}static demurrageToInflationary(J,Q){return this.mulU(this.pow64(this.BETA_64,Q),J)}static dayFromTimestamp(J){return(J-this.INFLATION_DAY_ZERO_UNIX)/this.SECONDS_PER_DAY}static attoCirclesToAttoStaticCircles(J,Q=BigInt(Math.floor(Date.now()/1000))){return this.demurrageToInflationary(J,this.dayFromTimestamp(Q))}static attoStaticCirclesToAttoCircles(J,Q=BigInt(Math.floor(Date.now()/1000))){return this.inflationaryToDemurrage(J,this.dayFromTimestamp(Q))}static inflationaryToDemurrageExact(J,Q){let $=this.pow36(this.GAMMA_36,Q);return J*$/this.ONE_36}static demurrageToInflationaryExact(J,Q){let $=this.pow36(this.BETA_36,Q);return J*$/this.ONE_36}static attoCirclesToAttoStaticCirclesExact(J,Q=BigInt(Math.floor(Date.now()/1000))){let $=this.dayFromTimestamp(Q);return this.demurrageToInflationaryExact(J,$)}static attoStaticCirclesToAttoCirclesExact(J,Q=BigInt(Math.floor(Date.now()/1000))){let $=this.dayFromTimestamp(Q);return this.inflationaryToDemurrageExact(J,$)}static truncateToInt64(J){let Q=J/this.FACTOR_1E12,$=9223372036854775807n;return Q>$?$:Q}static blowUpToBigInt(J){return J*this.FACTOR_1E12}static truncateToSixDecimals(J){return this.blowUpToBigInt(this.truncateToInt64(J))}static v1InflateFactor(J){if(J===0n)return this.V1_ACCURACY;return this.V1_ACCURACY*this.V1_INFLATION_PCT_NUM**J/this.V1_INFLATION_PCT_DEN**J}static attoCrcToAttoCircles(J,Q){let $=Q-this.INFLATION_DAY_ZERO_UNIX,q=$/this.PERIOD_SEC,Y=$%this.PERIOD_SEC,G=this.v1InflateFactor(q),Z=this.v1InflateFactor(q+1n);return this.v1ToDemurrage(J,G,Z,Y,this.PERIOD_SEC)}static attoCirclesToAttoCrc(J,Q){let $=Q-this.INFLATION_DAY_ZERO_UNIX,q=$/this.PERIOD_SEC,Y=$%this.PERIOD_SEC,G=this.v1InflateFactor(q),Z=this.v1InflateFactor(q+1n),X=G*(this.PERIOD_SEC-Y)+Z*Y;return J*3n*this.V1_ACCURACY*this.PERIOD_SEC/X}static v1ToDemurrage(J,Q,$,q,Y){let G=Q*(Y-q)+$*q;return J*3n*this.V1_ACCURACY*Y/G}}var c$=[];for(let J=0;J<256;J++)c$[J]=J.toString(16).padStart(2,"0");function bJ(J){let Q="0x";for(let $=0;$<J.length;$++)Q+=c$[J[$]];return Q}function Y8(J){let Q=J.startsWith("0x")?J.slice(2):J,$=new Uint8Array(Q.length/2);for(let q=0;q<Q.length;q+=2)$[q/2]=parseInt(Q.slice(q,q+2),16);return $}var sJ=BigInt(4294967295),p$=BigInt(32);function G8(J,Q=!1){if(Q)return{h:Number(J&sJ),l:Number(J>>p$&sJ)};return{h:Number(J>>p$&sJ)|0,l:Number(J&sJ)|0}}function i$(J,Q=!1){let $=J.length,q=new Uint32Array($),Y=new Uint32Array($);for(let G=0;G<$;G++){let{h:Z,l:X}=G8(J[G],Q);[q[G],Y[G]]=[Z,X]}return[q,Y]}var n$=(J,Q,$)=>J<<$|Q>>>32-$,o$=(J,Q,$)=>Q<<$|J>>>32-$,r$=(J,Q,$)=>Q<<$-32|J>>>64-$,a$=(J,Q,$)=>J<<$-32|Q>>>64-$;var zJ=typeof globalThis==="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Z8(J){return J instanceof Uint8Array||ArrayBuffer.isView(J)&&J.constructor.name==="Uint8Array"}function OJ(J){if(!Number.isSafeInteger(J)||J<0)throw Error("positive integer expected, got "+J)}function t(J,...Q){if(!Z8(J))throw Error("Uint8Array expected");if(Q.length>0&&!Q.includes(J.length))throw Error("Uint8Array expected of length "+Q+", got length="+J.length)}function s$(J){if(typeof J!=="function"||typeof J.create!=="function")throw Error("Hash should be wrapped by utils.createHasher");OJ(J.outputLen),OJ(J.blockLen)}function qJ(J,Q=!0){if(J.destroyed)throw Error("Hash instance has been destroyed");if(Q&&J.finished)throw Error("Hash#digest() has already been called")}function tJ(J,Q){t(J);let $=Q.outputLen;if(J.length<$)throw Error("digestInto() expects output buffer of length at least "+$)}function t$(J){return new Uint32Array(J.buffer,J.byteOffset,Math.floor(J.byteLength/4))}function e(...J){for(let Q=0;Q<J.length;Q++)J[Q].fill(0)}function eJ(J){return new DataView(J.buffer,J.byteOffset,J.byteLength)}function r(J,Q){return J<<32-Q|J>>>Q}var K8=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function X8(J){return J<<24&4278190080|J<<8&16711680|J>>>8&65280|J>>>24&255}function M8(J){for(let Q=0;Q<J.length;Q++)J[Q]=X8(J[Q]);return J}var j$=K8?(J)=>J:M8;function U8(J){if(typeof J!=="string")throw Error("string expected");return new Uint8Array(new TextEncoder().encode(J))}function VJ(J){if(typeof J==="string")J=U8(J);return t(J),J}function e$(...J){let Q=0;for(let q=0;q<J.length;q++){let Y=J[q];t(Y),Q+=Y.length}let $=new Uint8Array(Q);for(let q=0,Y=0;q<J.length;q++){let G=J[q];$.set(G,Y),Y+=G.length}return $}class TJ{}function J$(J){let Q=(q)=>J().update(VJ(q)).digest(),$=J();return Q.outputLen=$.outputLen,Q.blockLen=$.blockLen,Q.create=()=>J(),Q}function J0(J=32){if(zJ&&typeof zJ.getRandomValues==="function")return zJ.getRandomValues(new Uint8Array(J));if(zJ&&typeof zJ.randomBytes==="function")return Uint8Array.from(zJ.randomBytes(J));throw Error("crypto.getRandomValues must be defined")}var j8=BigInt(0),mJ=BigInt(1),N8=BigInt(2),W8=BigInt(7),z8=BigInt(256),O8=BigInt(113),q0=[],Y0=[],G0=[];for(let J=0,Q=mJ,$=1,q=0;J<24;J++){[$,q]=[q,(2*$+3*q)%5],q0.push(2*(5*q+$)),Y0.push((J+1)*(J+2)/2%64);let Y=j8;for(let G=0;G<7;G++)if(Q=(Q<<mJ^(Q>>W8)*O8)%z8,Q&N8)Y^=mJ<<(mJ<<BigInt(G))-mJ;G0.push(Y)}var Z0=i$(G0,!0),V8=Z0[0],T8=Z0[1],$0=(J,Q,$)=>$>32?r$(J,Q,$):n$(J,Q,$),Q0=(J,Q,$)=>$>32?a$(J,Q,$):o$(J,Q,$);function D8(J,Q=24){let $=new Uint32Array(10);for(let q=24-Q;q<24;q++){for(let Z=0;Z<10;Z++)$[Z]=J[Z]^J[Z+10]^J[Z+20]^J[Z+30]^J[Z+40];for(let Z=0;Z<10;Z+=2){let X=(Z+8)%10,K=(Z+2)%10,M=$[K],U=$[K+1],O=$0(M,U,1)^$[X],I=Q0(M,U,1)^$[X+1];for(let w=0;w<50;w+=10)J[Z+w]^=O,J[Z+w+1]^=I}let Y=J[2],G=J[3];for(let Z=0;Z<24;Z++){let X=Y0[Z],K=$0(Y,G,X),M=Q0(Y,G,X),U=q0[Z];Y=J[U],G=J[U+1],J[U]=K,J[U+1]=M}for(let Z=0;Z<50;Z+=10){for(let X=0;X<10;X++)$[X]=J[Z+X];for(let X=0;X<10;X++)J[Z+X]^=~$[(X+2)%10]&$[(X+4)%10]}J[0]^=V8[q],J[1]^=T8[q]}e($)}class N$ extends TJ{constructor(J,Q,$,q=!1,Y=24){super();if(this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=J,this.suffix=Q,this.outputLen=$,this.enableXOF=q,this.rounds=Y,OJ($),!(0<J&&J<200))throw Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=t$(this.state)}clone(){return this._cloneInto()}keccak(){j$(this.state32),D8(this.state32,this.rounds),j$(this.state32),this.posOut=0,this.pos=0}update(J){qJ(this),J=VJ(J),t(J);let{blockLen:Q,state:$}=this,q=J.length;for(let Y=0;Y<q;){let G=Math.min(Q-this.pos,q-Y);for(let Z=0;Z<G;Z++)$[this.pos++]^=J[Y++];if(this.pos===Q)this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:J,suffix:Q,pos:$,blockLen:q}=this;if(J[$]^=Q,(Q&128)!==0&&$===q-1)this.keccak();J[q-1]^=128,this.keccak()}writeInto(J){qJ(this,!1),t(J),this.finish();let Q=this.state,{blockLen:$}=this;for(let q=0,Y=J.length;q<Y;){if(this.posOut>=$)this.keccak();let G=Math.min($-this.posOut,Y-q);J.set(Q.subarray(this.posOut,this.posOut+G),q),this.posOut+=G,q+=G}return J}xofInto(J){if(!this.enableXOF)throw Error("XOF is not possible for this instance");return this.writeInto(J)}xof(J){return OJ(J),this.xofInto(new Uint8Array(J))}digestInto(J){if(tJ(J,this),this.finished)throw Error("digest() was already called");return this.writeInto(J),this.destroy(),J}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,e(this.state)}_cloneInto(J){let{blockLen:Q,suffix:$,outputLen:q,rounds:Y,enableXOF:G}=this;return J||(J=new N$(Q,$,q,G,Y)),J.state32.set(this.state32),J.pos=this.pos,J.posOut=this.posOut,J.finished=this.finished,J.rounds=Y,J.suffix=$,J.outputLen=q,J.enableXOF=G,J.destroyed=this.destroyed,J}}var I8=(J,Q,$)=>J$(()=>new N$(Q,J,$));var DJ=(()=>I8(1,136,32))();var g=64,Q$=32,hJ=(J)=>J.startsWith("0x")?J.slice(2):J;var JJ=(J)=>J.toString(16).padStart(g,"0");function q$(J){let Q=J.toLowerCase().replace("0x",""),$=bJ(DJ(new TextEncoder().encode(Q))).slice(2),q="0x";for(let Y=0;Y<Q.length;Y++)q+=parseInt($[Y],16)>=8?Q[Y].toUpperCase():Q[Y];return q}function $$(J,Q){if(J==="tuple"&&Q)return`(${Q.map((Y)=>$$(Y.type,Y.components)).join(",")})`;let $=J.match(/^tuple(\[\d*\])$/);if($&&Q)return`${$$("tuple",Q)}${$[1]}`;return J}function R8(J){let $=(J.inputs||[]).map((q)=>$$(q.type,q.components));return`${J.name}(${$.join(",")})`}function w8(J){let Q=R8(J),$=DJ(new TextEncoder().encode(Q));return bJ($.slice(0,4))}function AJ(J,Q){if(J==="string"||J==="bytes")return!0;if(J.includes("[")){let $=J.slice(0,J.indexOf("["));if(J.endsWith("[]"))return!0;if($==="tuple")return K0(Q);return AJ($)}if(J==="tuple")return K0(Q);return!1}function K0(J){return J?.some((Q)=>AJ(Q.type,Q.components))??!1}function UJ(J,Q,$){if(J==="tuple"&&$)return k8($,Q);if(J.includes("["))return L8(J,Q,$);return P8(J,Q)}function L8(J,Q,$){let q=J.slice(0,J.indexOf("[")),Y=J.endsWith("[]"),G=AJ(q,$),Z;if(G){let X=Q.map((U)=>UJ(q,U,$)),K=Q.length*Q$;Z=X.map((U)=>{let O=K;return K+=U.length/2,JJ(O)}).join("")+X.join("")}else Z=Q.map((X)=>UJ(q,X,$)).join("");return Y?JJ(Q.length)+Z:Z}function k8(J,Q){let $=Array.isArray(Q),q=[],Y=[],G=[];for(let Z=0;Z<J.length;Z++){let X=J[Z],K=$?Q[Z]:Q[X.name||""],M=AJ(X.type,X.components);if(G.push(M),M)q.push(""),Y.push(UJ(X.type,K,X.components));else q.push(UJ(X.type,K,X.components))}if(Y.length>0){let Z=q.reduce((M,U,O)=>M+(G[O]?Q$:U.length/2),0),X="",K=0;for(let M=0;M<J.length;M++)if(G[M])X+=JJ(Z),Z+=Y[K].length/2,K++;else X+=q[M];return X+Y.join("")}return q.join("")}function P8(J,Q){if(J==="address")return hJ(Q).toLowerCase().padStart(g,"0");if(J==="bool")return JJ(Q?1:0);if(J.startsWith("uint")){let $=typeof Q==="bigint"?Q:BigInt(Q);return JJ($)}if(J.startsWith("int")){let $=typeof Q==="bigint"?Q:BigInt(Q);if($<0n){let q=J==="int"?256:parseInt(J.slice(3));$=(1n<<BigInt(q))+$}return JJ($)}if(J.startsWith("bytes")&&J!=="bytes")return hJ(Q).padEnd(g,"0");if(J==="bytes"){let $=hJ(Q),q=JJ($.length/2),Y=$.padEnd(Math.ceil($.length/g)*g,"0");return q+Y}if(J==="string"){let $=Array.from(new TextEncoder().encode(Q)).map((G)=>G.toString(16).padStart(2,"0")).join(""),q=JJ($.length/2),Y=$.padEnd(Math.ceil($.length/g)*g,"0");return q+Y}throw Error(`Unsupported type: ${J}`)}function BJ(J,Q,$=0,q){if(J==="tuple"&&q)return B8(q,Q,$);if(J.includes("["))return C8(J,Q,$,q);return A8(J,Q,$)}function C8(J,Q,$,q){let Y=J.slice(0,J.indexOf("[")),G=Q.slice($,$+g);if(J.endsWith("[]")){let X=parseInt(G,16)*2,K=parseInt(Q.slice(X,X+g),16),M=[],U=X+g;for(let O=0;O<K;O++){let I=BJ(Y,Q,U,q);M.push(I.value),U+=I.consumed}return{value:M,consumed:g}}let Z=J.match(/\[(\d+)\]$/);if(Z){let X=parseInt(Z[1]),K=[],M=0;for(let U=0;U<X;U++){let O=BJ(Y,Q,$+M,q);K.push(O.value),M+=O.consumed}return{value:K,consumed:M}}throw Error(`Invalid array type: ${J}`)}function B8(J,Q,$){let q=[],Y=$;for(let G of J){let Z=BJ(G.type,Q,Y,G.components);q.push(Z.value),Y+=Z.consumed}return{value:q,consumed:Y-$}}function A8(J,Q,$){let q=Q.slice($,$+g);if(J==="address")return{value:q$("0x"+q.slice(24)),consumed:g};if(J==="bool")return{value:parseInt(q,16)!==0,consumed:g};if(J.startsWith("uint"))return{value:BigInt("0x"+q),consumed:g};if(J.startsWith("int")){let Y=BigInt("0x"+q),G=J==="int"?256:parseInt(J.slice(3)),Z=1n<<BigInt(G-1);return{value:Y>=Z?Y-(1n<<BigInt(G)):Y,consumed:g}}if(J.startsWith("bytes")&&J!=="bytes"){let Y=parseInt(J.match(/^bytes(\d+)$/)[1]);return{value:"0x"+q.slice(0,Y*2),consumed:g}}if(J==="bytes"){let Y=parseInt(q,16)*2,G=parseInt(Q.slice(Y,Y+g),16)*2;return{value:"0x"+Q.slice(Y+g,Y+g+G),consumed:g}}if(J==="string"){let Y=parseInt(q,16)*2,G=parseInt(Q.slice(Y,Y+g),16)*2,Z=Q.slice(Y+g,Y+g+G),X=new Uint8Array(Z.match(/.{2}/g)?.map((K)=>parseInt(K,16))||[]);return{value:new TextDecoder().decode(X),consumed:g}}throw Error(`Unsupported type: ${J}`)}function S8(J){let{abi:Q,functionName:$,args:q=[]}=J,Y=Q.find((w)=>w.type==="function"&&w.name===$);if(!Y)throw Error(`Function "${$}" not found in ABI`);let G=w8(Y),Z=Y.inputs||[];if(Z.length===0)return G;if(q.length!==Z.length)throw Error(`Expected ${Z.length} arguments, got ${q.length}`);let X=[],K=[],M=[];for(let w=0;w<Z.length;w++){let T=Z[w],z=T.components,v=AJ(T.type,z);if(M.push(v),v)X.push(""),K.push(UJ(T.type,q[w],z));else X.push(UJ(T.type,q[w],z))}if(K.length===0)return G+X.join("");let U=X.reduce((w,T,z)=>w+(M[z]?Q$:T.length/2),0),O="",I=0;for(let w=0;w<Z.length;w++)if(M[w])O+=JJ(U),U+=K[I].length/2,I++;else O+=X[w];return G+O+K.join("")}function H8(J){let{abi:Q,functionName:$,data:q}=J,Y=Q.find((M)=>M.type==="function"&&M.name===$);if(!Y)throw Error(`Function "${$}" not found in ABI`);let G=Y.outputs||[];if(G.length===0)return;let Z=hJ(q);if(G.length===1)return BJ(G[0].type,Z,0,G[0].components).value;let X=[],K=0;for(let M of G){let U=BJ(M.type,Z,K,M.components);X.push(U.value),K+=U.consumed}return X}function E8(J){let $=(J.inputs||[]).map((G)=>$$(G.type,G.components)),q=`${J.name}(${$.join(",")})`,Y=DJ(new TextEncoder().encode(q));return bJ(Y.slice(0,4))}function W$(J){let{abi:Q,data:$}=J;if(!$||$.length<10)return null;let q=$.slice(0,10).toLowerCase(),Y=hJ($.slice(10)),G=Q.filter((Z)=>Z.type==="error");for(let Z of G)if(E8(Z).toLowerCase()===q){let K=Z.inputs||[];if(K.length===0)return{errorName:Z.name};let M=[],U=0;for(let O of K){let I=BJ(O.type,Y,U,O.components);M.push(I.value),U+=I.consumed}return{errorName:Z.name,args:M}}return null}function x8(J,Q){if(J.length!==Q.length)throw Error(`Type/value length mismatch: ${J.length} types, ${Q.length} values`);let $=[],q=[],Y=[];for(let K=0;K<J.length;K++){let M=J[K],U=AJ(M);if(Y.push(U),U)$.push(""),q.push(UJ(M,Q[K]));else $.push(UJ(M,Q[K]))}if(q.length===0)return"0x"+$.join("");let G=$.reduce((K,M,U)=>K+(Y[U]?Q$:M.length/2),0),Z="",X=0;for(let K=0;K<J.length;K++)if(Y[K])Z+=JJ(G),G+=q[X].length/2,X++;else Z+=$[K];return"0x"+Z+q.join("")}var Gq=new Uint8Array(0);function X0(J,Q){if(J===Q)return!0;if(J.byteLength!==Q.byteLength)return!1;for(let $=0;$<J.byteLength;$++)if(J[$]!==Q[$])return!1;return!0}function SJ(J){if(J instanceof Uint8Array&&J.constructor.name==="Uint8Array")return J;if(J instanceof ArrayBuffer)return new Uint8Array(J);if(ArrayBuffer.isView(J))return new Uint8Array(J.buffer,J.byteOffset,J.byteLength);throw Error("Unknown type, must be binary type")}function _8(J,Q){if(J.length>=255)throw TypeError("Alphabet too long");var $=new Uint8Array(256);for(var q=0;q<$.length;q++)$[q]=255;for(var Y=0;Y<J.length;Y++){var G=J.charAt(Y),Z=G.charCodeAt(0);if($[Z]!==255)throw TypeError(G+" is ambiguous");$[Z]=Y}var X=J.length,K=J.charAt(0),M=Math.log(X)/Math.log(256),U=Math.log(256)/Math.log(X);function O(T){if(T instanceof Uint8Array);else if(ArrayBuffer.isView(T))T=new Uint8Array(T.buffer,T.byteOffset,T.byteLength);else if(Array.isArray(T))T=Uint8Array.from(T);if(!(T instanceof Uint8Array))throw TypeError("Expected Uint8Array");if(T.length===0)return"";var z=0,v=0,x=0,f=T.length;while(x!==f&&T[x]===0)x++,z++;var j=(f-x)*U+1>>>0,W=new Uint8Array(j);while(x!==f){var D=T[x],R=0;for(var L=j-1;(D!==0||R<v)&&L!==-1;L--,R++)D+=256*W[L]>>>0,W[L]=D%X>>>0,D=D/X>>>0;if(D!==0)throw Error("Non-zero carry");v=R,x++}var C=j-v;while(C!==j&&W[C]===0)C++;var H=K.repeat(z);for(;C<j;++C)H+=J.charAt(W[C]);return H}function I(T){if(typeof T!=="string")throw TypeError("Expected String");if(T.length===0)return new Uint8Array;var z=0;if(T[z]===" ")return;var v=0,x=0;while(T[z]===K)v++,z++;var f=(T.length-z)*M+1>>>0,j=new Uint8Array(f);while(T[z]){var W=$[T.charCodeAt(z)];if(W===255)return;var D=0;for(var R=f-1;(W!==0||D<x)&&R!==-1;R--,D++)W+=X*j[R]>>>0,j[R]=W%256>>>0,W=W/256>>>0;if(W!==0)throw Error("Non-zero carry");x=D,z++}if(T[z]===" ")return;var L=f-x;while(L!==f&&j[L]===0)L++;var C=new Uint8Array(v+(f-L)),H=v;while(L!==f)C[H++]=j[L++];return C}function w(T){var z=I(T);if(z)return z;throw Error(`Non-${Q} character`)}return{encode:O,decodeUnsafe:I,decode:w}}var v8=_8,g8=v8,M0=g8;class U0{name;prefix;baseEncode;constructor(J,Q,$){this.name=J,this.prefix=Q,this.baseEncode=$}encode(J){if(J instanceof Uint8Array)return`${this.prefix}${this.baseEncode(J)}`;else throw Error("Unknown type, must be binary type")}}class j0{name;prefix;baseDecode;prefixCodePoint;constructor(J,Q,$){this.name=J,this.prefix=Q;let q=Q.codePointAt(0);if(q===void 0)throw Error("Invalid prefix character");this.prefixCodePoint=q,this.baseDecode=$}decode(J){if(typeof J==="string"){if(J.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(J)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(J.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(J){return W0(this,J)}}class N0{decoders;constructor(J){this.decoders=J}or(J){return W0(this,J)}decode(J){let Q=J[0],$=this.decoders[Q];if($!=null)return $.decode(J);else throw RangeError(`Unable to decode multibase string ${JSON.stringify(J)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}function W0(J,Q){return new N0({...J.decoders??{[J.prefix]:J},...Q.decoders??{[Q.prefix]:Q}})}class z0{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(J,Q,$,q){this.name=J,this.prefix=Q,this.baseEncode=$,this.baseDecode=q,this.encoder=new U0(J,Q,$),this.decoder=new j0(J,Q,q)}encode(J){return this.encoder.encode(J)}decode(J){return this.decoder.decode(J)}}function O0({name:J,prefix:Q,encode:$,decode:q}){return new z0(J,Q,$,q)}function HJ({name:J,prefix:Q,alphabet:$}){let{encode:q,decode:Y}=M0($,J);return O0({prefix:Q,name:J,encode:q,decode:(G)=>SJ(Y(G))})}function F8(J,Q,$,q){let Y=J.length;while(J[Y-1]==="=")--Y;let G=new Uint8Array(Y*$/8|0),Z=0,X=0,K=0;for(let M=0;M<Y;++M){let U=Q[J[M]];if(U===void 0)throw SyntaxError(`Non-${q} character`);if(X=X<<$|U,Z+=$,Z>=8)Z-=8,G[K++]=255&X>>Z}if(Z>=$||(255&X<<8-Z)!==0)throw SyntaxError("Unexpected end of data");return G}function f8(J,Q,$){let q=Q[Q.length-1]==="=",Y=(1<<$)-1,G="",Z=0,X=0;for(let K=0;K<J.length;++K){X=X<<8|J[K],Z+=8;while(Z>$)Z-=$,G+=Q[Y&X>>Z]}if(Z!==0)G+=Q[Y&X<<$-Z];if(q)while((G.length*$&7)!==0)G+="=";return G}function y8(J){let Q={};for(let $=0;$<J.length;++$)Q[J[$]]=$;return Q}function $J({name:J,prefix:Q,bitsPerChar:$,alphabet:q}){let Y=y8(q);return O0({prefix:Q,name:J,encode(G){return f8(G,q,$)},decode(G){return F8(G,Y,$,J)}})}var uJ=$J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Nq=$J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wq=$J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zq=$J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Oq=$J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vq=$J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tq=$J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Dq=$J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Iq=$J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Y$=HJ({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lq=HJ({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var o=HJ({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Cq=HJ({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var b8=D0,V0=128,m8=127,h8=~m8,u8=Math.pow(2,31);function D0(J,Q,$){Q=Q||[],$=$||0;var q=$;while(J>=u8)Q[$++]=J&255|V0,J/=128;while(J&h8)Q[$++]=J&255|V0,J>>>=7;return Q[$]=J|0,D0.bytes=$-q+1,Q}var l8=z$,d8=128,T0=127;function z$(J,q){var $=0,q=q||0,Y=0,G=q,Z,X=J.length;do{if(G>=X)throw z$.bytes=0,RangeError("Could not decode varint");Z=J[G++],$+=Y<28?(Z&T0)<<Y:(Z&T0)*Math.pow(2,Y),Y+=7}while(Z>=d8);return z$.bytes=G-q,$}var c8=Math.pow(2,7),p8=Math.pow(2,14),i8=Math.pow(2,21),n8=Math.pow(2,28),o8=Math.pow(2,35),r8=Math.pow(2,42),a8=Math.pow(2,49),s8=Math.pow(2,56),t8=Math.pow(2,63),e8=function(J){return J<c8?1:J<p8?2:J<i8?3:J<n8?4:J<o8?5:J<r8?6:J<a8?7:J<s8?8:J<t8?9:10},JQ={encode:b8,decode:l8,encodingLength:e8},$Q=JQ,lJ=$Q;function dJ(J,Q=0){return[lJ.decode(J,Q),lJ.decode.bytes]}function EJ(J,Q,$=0){return lJ.encode(J,Q,$),Q}function xJ(J){return lJ.encodingLength(J)}function R0(J,Q){let $=Q.byteLength,q=xJ(J),Y=q+xJ($),G=new Uint8Array(Y+$);return EJ(J,G,0),EJ($,G,q),G.set(Q,Y),new cJ(J,$,Q,G)}function w0(J){let Q=SJ(J),[$,q]=dJ(Q),[Y,G]=dJ(Q.subarray(q)),Z=Q.subarray(q+G);if(Z.byteLength!==Y)throw Error("Incorrect length");return new cJ($,Y,Z,Q)}function L0(J,Q){if(J===Q)return!0;else{let $=Q;return J.code===$.code&&J.size===$.size&&$.bytes instanceof Uint8Array&&X0(J.bytes,$.bytes)}}class cJ{code;size;digest;bytes;constructor(J,Q,$,q){this.code=J,this.size=Q,this.digest=$,this.bytes=q}}function k0(J,Q){let{bytes:$,version:q}=J;switch(q){case 0:return YQ($,O$(J),Q??o.encoder);default:return GQ($,O$(J),Q??uJ.encoder)}}var P0=new WeakMap;function O$(J){let Q=P0.get(J);if(Q==null){let $=new Map;return P0.set(J,$),$}return Q}class y{code;version;multihash;bytes;"/";constructor(J,Q,$,q){this.code=Q,this.version=J,this.multihash=$,this.bytes=q,this["/"]=q}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:J,multihash:Q}=this;if(J!==pJ)throw Error("Cannot convert a non dag-pb CID to CIDv0");if(Q.code!==ZQ)throw Error("Cannot convert non sha2-256 multihash CID to CIDv0");return y.createV0(Q)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:J,digest:Q}=this.multihash,$=R0(J,Q);return y.createV1(this.code,$)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(J){return y.equals(this,J)}static equals(J,Q){let $=Q;return $!=null&&J.code===$.code&&J.version===$.version&&L0(J.multihash,$.multihash)}toString(J){return k0(this,J)}toJSON(){return{"/":k0(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(J){if(J==null)return null;let Q=J;if(Q instanceof y)return Q;else if(Q["/"]!=null&&Q["/"]===Q.bytes||Q.asCID===Q){let{version:$,code:q,multihash:Y,bytes:G}=Q;return new y($,q,Y,G??C0($,q,Y.bytes))}else if(Q[KQ]===!0){let{version:$,multihash:q,code:Y}=Q,G=w0(q);return y.create($,Y,G)}else return null}static create(J,Q,$){if(typeof Q!=="number")throw Error("String codecs are no longer supported");if(!($.bytes instanceof Uint8Array))throw Error("Invalid digest");switch(J){case 0:if(Q!==pJ)throw Error(`Version 0 CID must use dag-pb (code: ${pJ}) block encoding`);else return new y(J,Q,$,$.bytes);case 1:{let q=C0(J,Q,$.bytes);return new y(J,Q,$,q)}default:throw Error("Invalid version")}}static createV0(J){return y.create(0,pJ,J)}static createV1(J,Q){return y.create(1,J,Q)}static decode(J){let[Q,$]=y.decodeFirst(J);if($.length!==0)throw Error("Incorrect length");return Q}static decodeFirst(J){let Q=y.inspectBytes(J),$=Q.size-Q.multihashSize,q=SJ(J.subarray($,$+Q.multihashSize));if(q.byteLength!==Q.multihashSize)throw Error("Incorrect length");let Y=q.subarray(Q.multihashSize-Q.digestSize),G=new cJ(Q.multihashCode,Q.digestSize,Y,q);return[Q.version===0?y.createV0(G):y.createV1(Q.codec,G),J.subarray(Q.size)]}static inspectBytes(J){let Q=0,$=()=>{let[U,O]=dJ(J.subarray(Q));return Q+=O,U},q=$(),Y=pJ;if(q===18)q=0,Q=0;else Y=$();if(q!==0&&q!==1)throw RangeError(`Invalid CID version ${q}`);let G=Q,Z=$(),X=$(),K=Q+X,M=K-G;return{version:q,codec:Y,multihashCode:Z,digestSize:X,multihashSize:M,size:K}}static parse(J,Q){let[$,q]=qQ(J,Q),Y=y.decode(q);if(Y.version===0&&J[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return O$(Y).set($,J),Y}}function qQ(J,Q){switch(J[0]){case"Q":{let $=Q??o;return[o.prefix,$.decode(`${o.prefix}${J}`)]}case o.prefix:{let $=Q??o;return[o.prefix,$.decode(J)]}case uJ.prefix:{let $=Q??uJ;return[uJ.prefix,$.decode(J)]}case Y$.prefix:{let $=Q??Y$;return[Y$.prefix,$.decode(J)]}default:{if(Q==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[J[0],Q.decode(J)]}}}function YQ(J,Q,$){let{prefix:q}=$;if(q!==o.prefix)throw Error(`Cannot string encode V0 in ${$.name} encoding`);let Y=Q.get(q);if(Y==null){let G=$.encode(J).slice(1);return Q.set(q,G),G}else return Y}function GQ(J,Q,$){let{prefix:q}=$,Y=Q.get(q);if(Y==null){let G=$.encode(J);return Q.set(q,G),G}else return Y}var pJ=112,ZQ=18;function C0(J,Q,$){let q=xJ(J),Y=q+xJ(Q),G=new Uint8Array(Y+$.byteLength);return EJ(J,G,0),EJ(Q,G,q),G.set($,Y),G}var KQ=Symbol.for("@ipld/js-cid/CID");function XQ(J){let Q=y.parse(J,o);if(Q.version!==0)throw Error(`Expected CIDv0, got CIDv${Q.version}`);if(Q.multihash.code!==18)throw Error("Unsupported hash algorithm. Only SHA-256 is supported for CIDv0.");let $=Q.multihash.digest;return`0x${Array.from($).map((Y)=>Y.toString(16).padStart(2,"0")).join("")}`}function MQ(J){let Q=y.parse(J,o);if(Q.version!==0)throw Error(`Expected CIDv0, got CIDv${Q.version}`);if(Q.multihash.code!==18)throw Error("Unsupported hash algorithm. Only SHA-256 is supported for CIDv0.");return Q.multihash.digest}function UQ(J){return`0x${J.toString(16).padStart(64,"0").slice(-40)}`}var jQ="0x0000000000000000000000000000000000000000",NQ=BigInt(96)*BigInt(1000000000000000000),WQ=BigInt("9999999999999999999999999999999999999"),zQ="0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",OQ="0x440ea2f93c9703f7d456d48796f7bc25b8721582535a492ce0a09df32146242a",VQ="0xe298282cefe913ab5d282047161268a8222e4bd4ed106300c547894bbefd31ee";var TQ={100:{circlesRpcUrl:"https://rpc.aboutcircles.com/",pathfinderUrl:"https://pathfinder.aboutcircles.com",profileServiceUrl:"https://rpc.aboutcircles.com/profiles/",referralsServiceUrl:"https://staging.circlesubi.network/referrals",v1HubAddress:"0x29b9a7fbb8995b2423a71cc17cf9810798f6c543",v2HubAddress:"0xc12C1E50ABB450d6205Ea2C3Fa861b3B834d13e8",nameRegistryAddress:"0xA27566fD89162cC3D40Cb59c87AAaA49B85F3474",baseGroupMintPolicy:"0xcCa27c26CF7BAC2a9928f42201d48220F0e3a549",standardTreasury:"0x08F90aB73A515308f03A718257ff9887ED330C6e",coreMembersGroupDeployer:"0xFEca40Eb02FB1f4F5F795fC7a03c1A27819B1Ded",baseGroupFactoryAddress:"0xD0B5Bd9962197BEaC4cbA24244ec3587f19Bd06d",liftERC20Address:"0x5F99a795dD2743C36D63511f0D4bc667e6d3cDB5",invitationEscrowAddress:"0x8F8B74fa13eaaff4176D061a0F98ad5c8E19c903",invitationFarmAddress:"0x0000000000000000000000000000000000000000",referralsModuleAddress:"0xd6dF7cc2C2DB03ec91761f4469D8dBAac7e538C9",invitationModuleAddress:"0x00738aca013B7B2e6cfE1690F0021C3182Fa40B5"}};class QJ extends Error{name;code;source;cause;context;constructor(J,Q,$){super(Q);if(this.name=J,this.code=$?.code,this.source=$?.source??"UNKNOWN",this.cause=$?.cause,this.context=$?.context,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,source:this.source,context:this.context,cause:this.cause instanceof Error?{name:this.cause.name,message:this.cause.message}:this.cause,stack:this.stack}}toString(){let J=`[${this.source}] ${this.name}: ${this.message}`;if(this.code)J+=` (Code: ${this.code})`;if(this.context)J+=`
|
|
2
|
+
Context: ${JSON.stringify(this.context,null,2)}`;return J}}class _J extends QJ{constructor(J,Q){super("ValidationError",J,{...Q,source:"VALIDATION"})}static invalidAddress(J){return new _J("Invalid Ethereum address",{code:"VALIDATION_INVALID_ADDRESS",context:{address:J}})}static invalidAmount(J,Q){return new _J(Q||"Invalid amount",{code:"VALIDATION_INVALID_AMOUNT",context:{amount:J,reason:Q}})}static missingParameter(J){return new _J(`Missing required parameter: ${J}`,{code:"VALIDATION_MISSING_PARAM",context:{paramName:J}})}static invalidParameter(J,Q,$){return new _J(`Invalid parameter '${J}': ${$||"value is invalid"}`,{code:"VALIDATION_INVALID_PARAM",context:{paramName:J,value:Q,reason:$}})}}class G$ extends QJ{constructor(J,Q){super("EncodingError",J,{...Q,source:"ENCODING"})}static abiEncoding(J,Q){return new G$("Failed to encode ABI data",{code:"ENCODING_ABI_FAILED",cause:Q,context:{functionName:J}})}static cidConversion(J,Q){return new G$("Failed to convert CID",{code:"ENCODING_CID_FAILED",cause:Q,context:{cid:J}})}}function DQ(J,Q="UNKNOWN"){if(J instanceof QJ)return J;if(J instanceof Error)return new QJ(J.name||"UnknownError",J.message,{source:Q,cause:J});return new QJ("UnknownError",String(J),{source:Q,cause:J})}function B0(J){return J instanceof QJ}function IQ(J){if(B0(J))return J.message;if(J instanceof Error)return J.message;return String(J)}var RQ={0:"Avatar already registered",1:"Avatar must be registered before inviting",2:"Invalid invitation",3:"Avatar must be registered",4:"Only self can register",5:"Maximum value reached",6:"Inflationary supply already set",7:"Group has no collateral",161:"Trust to zero address is not allowed",16:"Invalid parameter"};function wQ(J){if(J?.details&&typeof J.details==="string"){let $=J.details.match(/err:\s*(0x[0-9a-fA-F]+)/);if($)return $[1]}if(J?.data&&typeof J.data==="string"&&J.data.startsWith("0x"))return J.data;let Q=J;while(Q){if(Q.data&&typeof Q.data==="string")return Q.data;Q=Q.cause}return null}function LQ(J,Q,$){if(!Q||Q.length===0)return J;if(!$||!$.inputs){let Z=Q.map((X)=>{if(typeof X==="bigint")return X.toString();return String(X)}).join(", ");return`${J}(${Z})`}let q=$.inputs.findIndex((Z)=>Z.name==="code"||Z.name===""&&Z.type==="uint8"),Y=J,G=[];if(q!==-1){let Z=Number(Q[q]),X=RQ[Z];if(X)Y=X}if($.inputs.forEach((Z,X)=>{let K=Q[X],M=Z.name||`arg${X}`;if(!Z.name&&Z.type==="uint8")return;let U;if(typeof K==="bigint")U=K.toString();else if(typeof K==="string"&&K.startsWith("0x"))U=K;else U=String(K);if(M==="code"||Z.type==="uint8")U=`0x${Number(K).toString(16)}`;G.push(`${M}: ${U}`)}),G.length>0)return`${Y} (${G.join(", ")})`;return Y}function A0(J,Q){let $=wQ(J);if(!$)return null;let q=W$({abi:Q,data:$});if(!q)return null;let Y=Q.find((X)=>X.type==="error"&&X.name===q.errorName),G=$.slice(0,10),Z=LQ(q.errorName,q.args,Y);return{errorName:q.errorName,args:q.args,selector:G,rawData:$,formattedMessage:Z}}class Z$ extends QJ{decodedError;constructor(J,Q){super("ContractError",J,{...Q,source:"CORE"});this.decodedError=Q?.decodedError}static fromTransactionError(J,Q,$){let q=A0(J,Q);if(q)return new Z$(`Transaction failed: ${q.formattedMessage}`,{code:q.selector,cause:J,context:{...$,errorName:q.errorName,errorArgs:q.args},decodedError:q});let Y=J?.message||String(J);return new Z$(`Transaction failed: ${Y}`,{cause:J,context:$})}toString(){let J=super.toString();if(this.decodedError){if(J+=`
|
|
3
|
+
Decoded Error: ${this.decodedError.formattedMessage}`,this.decodedError.args&&this.decodedError.args.length>0)J+=`
|
|
4
|
+
Arguments: ${JSON.stringify(this.decodedError.args,(Q,$)=>typeof $==="bigint"?$.toString():$)}`}return J}}function kQ(J,Q,$,q){if(typeof J.setBigUint64==="function")return J.setBigUint64(Q,$,q);let Y=BigInt(32),G=BigInt(4294967295),Z=Number($>>Y&G),X=Number($&G),K=q?4:0,M=q?0:4;J.setUint32(Q+K,Z,q),J.setUint32(Q+M,X,q)}function S0(J,Q,$){return J&Q^~J&$}function H0(J,Q,$){return J&Q^J&$^Q&$}class V$ extends TJ{constructor(J,Q,$,q){super();this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=J,this.outputLen=Q,this.padOffset=$,this.isLE=q,this.buffer=new Uint8Array(J),this.view=eJ(this.buffer)}update(J){qJ(this),J=VJ(J),t(J);let{view:Q,buffer:$,blockLen:q}=this,Y=J.length;for(let G=0;G<Y;){let Z=Math.min(q-this.pos,Y-G);if(Z===q){let X=eJ(J);for(;q<=Y-G;G+=q)this.process(X,G);continue}if($.set(J.subarray(G,G+Z),this.pos),this.pos+=Z,G+=Z,this.pos===q)this.process(Q,0),this.pos=0}return this.length+=J.length,this.roundClean(),this}digestInto(J){qJ(this),tJ(J,this),this.finished=!0;let{buffer:Q,view:$,blockLen:q,isLE:Y}=this,{pos:G}=this;if(Q[G++]=128,e(this.buffer.subarray(G)),this.padOffset>q-G)this.process($,0),G=0;for(let U=G;U<q;U++)Q[U]=0;kQ($,q-8,BigInt(this.length*8),Y),this.process($,0);let Z=eJ(J),X=this.outputLen;if(X%4)throw Error("_sha2: outputLen should be aligned to 32bit");let K=X/4,M=this.get();if(K>M.length)throw Error("_sha2: outputLen bigger than state");for(let U=0;U<K;U++)Z.setUint32(4*U,M[U],Y)}digest(){let{buffer:J,outputLen:Q}=this;this.digestInto(J);let $=J.slice(0,Q);return this.destroy(),$}_cloneInto(J){J||(J=new this.constructor),J.set(...this.get());let{blockLen:Q,buffer:$,length:q,finished:Y,destroyed:G,pos:Z}=this;if(J.destroyed=G,J.finished=Y,J.length=q,J.pos=Z,q%Q)J.buffer.set($);return J}clone(){return this._cloneInto()}}var YJ=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var PQ=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),jJ=new Uint32Array(64);class E0 extends V${constructor(J=32){super(64,J,8,!1);this.A=YJ[0]|0,this.B=YJ[1]|0,this.C=YJ[2]|0,this.D=YJ[3]|0,this.E=YJ[4]|0,this.F=YJ[5]|0,this.G=YJ[6]|0,this.H=YJ[7]|0}get(){let{A:J,B:Q,C:$,D:q,E:Y,F:G,G:Z,H:X}=this;return[J,Q,$,q,Y,G,Z,X]}set(J,Q,$,q,Y,G,Z,X){this.A=J|0,this.B=Q|0,this.C=$|0,this.D=q|0,this.E=Y|0,this.F=G|0,this.G=Z|0,this.H=X|0}process(J,Q){for(let U=0;U<16;U++,Q+=4)jJ[U]=J.getUint32(Q,!1);for(let U=16;U<64;U++){let O=jJ[U-15],I=jJ[U-2],w=r(O,7)^r(O,18)^O>>>3,T=r(I,17)^r(I,19)^I>>>10;jJ[U]=T+jJ[U-7]+w+jJ[U-16]|0}let{A:$,B:q,C:Y,D:G,E:Z,F:X,G:K,H:M}=this;for(let U=0;U<64;U++){let O=r(Z,6)^r(Z,11)^r(Z,25),I=M+O+S0(Z,X,K)+PQ[U]+jJ[U]|0,T=(r($,2)^r($,13)^r($,22))+H0($,q,Y)|0;M=K,K=X,X=Z,Z=G+I|0,G=Y,Y=q,q=$,$=I+T|0}$=$+this.A|0,q=q+this.B|0,Y=Y+this.C|0,G=G+this.D|0,Z=Z+this.E|0,X=X+this.F|0,K=K+this.G|0,M=M+this.H|0,this.set($,q,Y,G,Z,X,K,M)}roundClean(){e(jJ)}destroy(){this.set(0,0,0,0,0,0,0,0),e(this.buffer)}}var x0=J$(()=>new E0);class T$ extends TJ{constructor(J,Q){super();this.finished=!1,this.destroyed=!1,s$(J);let $=VJ(Q);if(this.iHash=J.create(),typeof this.iHash.update!=="function")throw Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let q=this.blockLen,Y=new Uint8Array(q);Y.set($.length>q?J.create().update($).digest():$);for(let G=0;G<Y.length;G++)Y[G]^=54;this.iHash.update(Y),this.oHash=J.create();for(let G=0;G<Y.length;G++)Y[G]^=106;this.oHash.update(Y),e(Y)}update(J){return qJ(this),this.iHash.update(J),this}digestInto(J){qJ(this),t(J,this.outputLen),this.finished=!0,this.iHash.digestInto(J),this.oHash.update(J),this.oHash.digestInto(J),this.destroy()}digest(){let J=new Uint8Array(this.oHash.outputLen);return this.digestInto(J),J}_cloneInto(J){J||(J=Object.create(Object.getPrototypeOf(this),{}));let{oHash:Q,iHash:$,finished:q,destroyed:Y,blockLen:G,outputLen:Z}=this;return J=J,J.finished=q,J.destroyed=Y,J.blockLen=G,J.outputLen=Z,J.oHash=Q._cloneInto(J.oHash),J.iHash=$._cloneInto(J.iHash),J}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}var D$=(J,Q,$)=>new T$(J,Q).update($).digest();D$.create=(J,Q)=>new T$(J,Q);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var L$=BigInt(0),w$=BigInt(1);function vJ(J){return J instanceof Uint8Array||ArrayBuffer.isView(J)&&J.constructor.name==="Uint8Array"}function k$(J){if(!vJ(J))throw Error("Uint8Array expected")}function gJ(J,Q){if(typeof Q!=="boolean")throw Error(J+" boolean expected, got "+Q)}function iJ(J){let Q=J.toString(16);return Q.length&1?"0"+Q:Q}function g0(J){if(typeof J!=="string")throw Error("hex string expected, got "+typeof J);return J===""?L$:BigInt("0x"+J)}var F0=typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function",CQ=Array.from({length:256},(J,Q)=>Q.toString(16).padStart(2,"0"));function FJ(J){if(k$(J),F0)return J.toHex();let Q="";for(let $=0;$<J.length;$++)Q+=CQ[J[$]];return Q}var GJ={_0:48,_9:57,A:65,F:70,a:97,f:102};function _0(J){if(J>=GJ._0&&J<=GJ._9)return J-GJ._0;if(J>=GJ.A&&J<=GJ.F)return J-(GJ.A-10);if(J>=GJ.a&&J<=GJ.f)return J-(GJ.a-10);return}function nJ(J){if(typeof J!=="string")throw Error("hex string expected, got "+typeof J);if(F0)return Uint8Array.fromHex(J);let Q=J.length,$=Q/2;if(Q%2)throw Error("hex string expected, got unpadded hex of length "+Q);let q=new Uint8Array($);for(let Y=0,G=0;Y<$;Y++,G+=2){let Z=_0(J.charCodeAt(G)),X=_0(J.charCodeAt(G+1));if(Z===void 0||X===void 0){let K=J[G]+J[G+1];throw Error('hex string expected, got non-hex character "'+K+'" at index '+G)}q[Y]=Z*16+X}return q}function ZJ(J){return g0(FJ(J))}function P$(J){return k$(J),g0(FJ(Uint8Array.from(J).reverse()))}function IJ(J,Q){return nJ(J.toString(16).padStart(Q*2,"0"))}function C$(J,Q){return IJ(J,Q).reverse()}function p(J,Q,$){let q;if(typeof Q==="string")try{q=nJ(Q)}catch(G){throw Error(J+" must be hex string or Uint8Array, cause: "+G)}else if(vJ(Q))q=Uint8Array.from(Q);else throw Error(J+" must be hex string or Uint8Array");let Y=q.length;if(typeof $==="number"&&Y!==$)throw Error(J+" of length "+$+" expected, got "+Y);return q}function oJ(...J){let Q=0;for(let q=0;q<J.length;q++){let Y=J[q];k$(Y),Q+=Y.length}let $=new Uint8Array(Q);for(let q=0,Y=0;q<J.length;q++){let G=J[q];$.set(G,Y),Y+=G.length}return $}var I$=(J)=>typeof J==="bigint"&&L$<=J;function K$(J,Q,$){return I$(J)&&I$(Q)&&I$($)&&Q<=J&&J<$}function RJ(J,Q,$,q){if(!K$(Q,$,q))throw Error("expected valid "+J+": "+$+" <= n < "+q+", got "+Q)}function f0(J){let Q;for(Q=0;J>L$;J>>=w$,Q+=1);return Q}var wJ=(J)=>(w$<<BigInt(J))-w$,R$=(J)=>new Uint8Array(J),v0=(J)=>Uint8Array.from(J);function y0(J,Q,$){if(typeof J!=="number"||J<2)throw Error("hashLen must be a number");if(typeof Q!=="number"||Q<2)throw Error("qByteLen must be a number");if(typeof $!=="function")throw Error("hmacFn must be a function");let q=R$(J),Y=R$(J),G=0,Z=()=>{q.fill(1),Y.fill(0),G=0},X=(...O)=>$(Y,q,...O),K=(O=R$(0))=>{if(Y=X(v0([0]),O),q=X(),O.length===0)return;Y=X(v0([1]),O),q=X()},M=()=>{if(G++>=1000)throw Error("drbg: tried 1000 values");let O=0,I=[];while(O<Q){q=X();let w=q.slice();I.push(w),O+=q.length}return oJ(...I)};return(O,I)=>{Z(),K(O);let w=void 0;while(!(w=I(M())))K();return Z(),w}}var BQ={bigint:(J)=>typeof J==="bigint",function:(J)=>typeof J==="function",boolean:(J)=>typeof J==="boolean",string:(J)=>typeof J==="string",stringOrUint8Array:(J)=>typeof J==="string"||vJ(J),isSafeInteger:(J)=>Number.isSafeInteger(J),array:(J)=>Array.isArray(J),field:(J,Q)=>Q.Fp.isValid(J),hash:(J)=>typeof J==="function"&&Number.isSafeInteger(J.outputLen)};function LJ(J,Q,$={}){let q=(Y,G,Z)=>{let X=BQ[G];if(typeof X!=="function")throw Error("invalid validator function");let K=J[Y];if(Z&&K===void 0)return;if(!X(K,J))throw Error("param "+String(Y)+" is invalid. Expected "+G+", got "+K)};for(let[Y,G]of Object.entries(Q))q(Y,G,!1);for(let[Y,G]of Object.entries($))q(Y,G,!0);return J}function B$(J){let Q=new WeakMap;return($,...q)=>{let Y=Q.get($);if(Y!==void 0)return Y;let G=J($,...q);return Q.set($,G),G}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var d=BigInt(0),u=BigInt(1),kJ=BigInt(2),AQ=BigInt(3),m0=BigInt(4),h0=BigInt(5),u0=BigInt(8);function h(J,Q){let $=J%Q;return $>=d?$:Q+$}function i(J,Q,$){let q=J;while(Q-- >d)q*=q,q%=$;return q}function X$(J,Q){if(J===d)throw Error("invert: expected non-zero number");if(Q<=d)throw Error("invert: expected positive modulus, got "+Q);let $=h(J,Q),q=Q,Y=d,G=u,Z=u,X=d;while($!==d){let M=q/$,U=q%$,O=Y-Z*M,I=G-X*M;q=$,$=U,Y=Z,G=X,Z=O,X=I}if(q!==u)throw Error("invert: does not exist");return h(Y,Q)}function l0(J,Q){let $=(J.ORDER+u)/m0,q=J.pow(Q,$);if(!J.eql(J.sqr(q),Q))throw Error("Cannot find square root");return q}function SQ(J,Q){let $=(J.ORDER-h0)/u0,q=J.mul(Q,kJ),Y=J.pow(q,$),G=J.mul(Q,Y),Z=J.mul(J.mul(G,kJ),Y),X=J.mul(G,J.sub(Z,J.ONE));if(!J.eql(J.sqr(X),Q))throw Error("Cannot find square root");return X}function HQ(J){if(J<BigInt(3))throw Error("sqrt is not defined for small field");let Q=J-u,$=0;while(Q%kJ===d)Q/=kJ,$++;let q=kJ,Y=rJ(J);while(b0(Y,q)===1)if(q++>1000)throw Error("Cannot find square root: probably non-prime P");if($===1)return l0;let G=Y.pow(q,Q),Z=(Q+u)/kJ;return function(K,M){if(K.is0(M))return M;if(b0(K,M)!==1)throw Error("Cannot find square root");let U=$,O=K.mul(K.ONE,G),I=K.pow(M,Q),w=K.pow(M,Z);while(!K.eql(I,K.ONE)){if(K.is0(I))return K.ZERO;let T=1,z=K.sqr(I);while(!K.eql(z,K.ONE))if(T++,z=K.sqr(z),T===U)throw Error("Cannot find square root");let v=u<<BigInt(U-T-1),x=K.pow(O,v);U=T,O=K.sqr(x),I=K.mul(I,O),w=K.mul(w,x)}return w}}function EQ(J){if(J%m0===AQ)return l0;if(J%u0===h0)return SQ;return HQ(J)}var xQ=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function A$(J){let Q={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},$=xQ.reduce((q,Y)=>{return q[Y]="function",q},Q);return LJ(J,$)}function _Q(J,Q,$){if($<d)throw Error("invalid exponent, negatives unsupported");if($===d)return J.ONE;if($===u)return Q;let q=J.ONE,Y=Q;while($>d){if($&u)q=J.mul(q,Y);Y=J.sqr(Y),$>>=u}return q}function S$(J,Q,$=!1){let q=Array(Q.length).fill($?J.ZERO:void 0),Y=Q.reduce((Z,X,K)=>{if(J.is0(X))return Z;return q[K]=Z,J.mul(Z,X)},J.ONE),G=J.inv(Y);return Q.reduceRight((Z,X,K)=>{if(J.is0(X))return Z;return q[K]=J.mul(Z,q[K]),J.mul(Z,X)},G),q}function b0(J,Q){let $=(J.ORDER-u)/kJ,q=J.pow(Q,$),Y=J.eql(q,J.ONE),G=J.eql(q,J.ZERO),Z=J.eql(q,J.neg(J.ONE));if(!Y&&!G&&!Z)throw Error("invalid Legendre symbol result");return Y?1:G?0:-1}function H$(J,Q){if(Q!==void 0)OJ(Q);let $=Q!==void 0?Q:J.toString(2).length,q=Math.ceil($/8);return{nBitLength:$,nByteLength:q}}function rJ(J,Q,$=!1,q={}){if(J<=d)throw Error("invalid field: expected ORDER > 0, got "+J);let{nBitLength:Y,nByteLength:G}=H$(J,Q);if(G>2048)throw Error("invalid field: expected ORDER of <= 2048 bytes");let Z,X=Object.freeze({ORDER:J,isLE:$,BITS:Y,BYTES:G,MASK:wJ(Y),ZERO:d,ONE:u,create:(K)=>h(K,J),isValid:(K)=>{if(typeof K!=="bigint")throw Error("invalid field element: expected bigint, got "+typeof K);return d<=K&&K<J},is0:(K)=>K===d,isOdd:(K)=>(K&u)===u,neg:(K)=>h(-K,J),eql:(K,M)=>K===M,sqr:(K)=>h(K*K,J),add:(K,M)=>h(K+M,J),sub:(K,M)=>h(K-M,J),mul:(K,M)=>h(K*M,J),pow:(K,M)=>_Q(X,K,M),div:(K,M)=>h(K*X$(M,J),J),sqrN:(K)=>K*K,addN:(K,M)=>K+M,subN:(K,M)=>K-M,mulN:(K,M)=>K*M,inv:(K)=>X$(K,J),sqrt:q.sqrt||((K)=>{if(!Z)Z=EQ(J);return Z(X,K)}),toBytes:(K)=>$?C$(K,G):IJ(K,G),fromBytes:(K)=>{if(K.length!==G)throw Error("Field.fromBytes: expected "+G+" bytes, got "+K.length);return $?P$(K):ZJ(K)},invertBatch:(K)=>S$(X,K),cmov:(K,M,U)=>U?M:K});return Object.freeze(X)}function d0(J){if(typeof J!=="bigint")throw Error("field order must be bigint");let Q=J.toString(2).length;return Math.ceil(Q/8)}function E$(J){let Q=d0(J);return Q+Math.ceil(Q/2)}function c0(J,Q,$=!1){let q=J.length,Y=d0(Q),G=E$(Q);if(q<16||q<G||q>1024)throw Error("expected "+G+"-1024 bytes of input, got "+q);let Z=$?P$(J):ZJ(J),X=h(Z,Q-u)+u;return $?C$(X,Y):IJ(X,Y)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var p0=BigInt(0),F$=BigInt(1);function x$(J,Q){let $=Q.negate();return J?$:Q}function n0(J,Q){if(!Number.isSafeInteger(J)||J<=0||J>Q)throw Error("invalid window size, expected [1.."+Q+"], got W="+J)}function _$(J,Q){n0(J,Q);let $=Math.ceil(Q/J)+1,q=2**(J-1),Y=2**J,G=wJ(J),Z=BigInt(J);return{windows:$,windowSize:q,mask:G,maxNumber:Y,shiftBy:Z}}function i0(J,Q,$){let{windowSize:q,mask:Y,maxNumber:G,shiftBy:Z}=$,X=Number(J&Y),K=J>>Z;if(X>q)X-=G,K+=F$;let M=Q*q,U=M+Math.abs(X)-1,O=X===0,I=X<0,w=Q%2!==0;return{nextN:K,offset:U,isZero:O,isNeg:I,isNegF:w,offsetF:M}}function vQ(J,Q){if(!Array.isArray(J))throw Error("array expected");J.forEach(($,q)=>{if(!($ instanceof Q))throw Error("invalid point at index "+q)})}function gQ(J,Q){if(!Array.isArray(J))throw Error("array of scalars expected");J.forEach(($,q)=>{if(!Q.isValid($))throw Error("invalid scalar at index "+q)})}var v$=new WeakMap,o0=new WeakMap;function g$(J){return o0.get(J)||1}function r0(J,Q){return{constTimeNegate:x$,hasPrecomputes($){return g$($)!==1},unsafeLadder($,q,Y=J.ZERO){let G=$;while(q>p0){if(q&F$)Y=Y.add(G);G=G.double(),q>>=F$}return Y},precomputeWindow($,q){let{windows:Y,windowSize:G}=_$(q,Q),Z=[],X=$,K=X;for(let M=0;M<Y;M++){K=X,Z.push(K);for(let U=1;U<G;U++)K=K.add(X),Z.push(K);X=K.double()}return Z},wNAF($,q,Y){let{ZERO:G,BASE:Z}=J,X=_$($,Q);for(let K=0;K<X.windows;K++){let{nextN:M,offset:U,isZero:O,isNeg:I,isNegF:w,offsetF:T}=i0(Y,K,X);if(Y=M,O)Z=Z.add(x$(w,q[T]));else G=G.add(x$(I,q[U]))}return{p:G,f:Z}},wNAFUnsafe($,q,Y,G=J.ZERO){let Z=_$($,Q);for(let X=0;X<Z.windows;X++){if(Y===p0)break;let{nextN:K,offset:M,isZero:U,isNeg:O}=i0(Y,X,Z);if(Y=K,U)continue;else{let I=q[M];G=G.add(O?I.negate():I)}}return G},getPrecomputes($,q,Y){let G=v$.get(q);if(!G){if(G=this.precomputeWindow(q,$),$!==1)v$.set(q,Y(G))}return G},wNAFCached($,q,Y){let G=g$($);return this.wNAF(G,this.getPrecomputes(G,$,Y),q)},wNAFCachedUnsafe($,q,Y,G){let Z=g$($);if(Z===1)return this.unsafeLadder($,q,G);return this.wNAFUnsafe(Z,this.getPrecomputes(Z,$,Y),q,G)},setWindowSize($,q){n0(q,Q),o0.set($,q),v$.delete($)}}}function a0(J,Q,$,q){vQ($,J),gQ(q,Q);let Y=$.length,G=q.length;if(Y!==G)throw Error("arrays of points and scalars must have equal length");let Z=J.ZERO,X=f0(BigInt(Y)),K=1;if(X>12)K=X-3;else if(X>4)K=X-2;else if(X>0)K=2;let M=wJ(K),U=Array(Number(M)+1).fill(Z),O=Math.floor((Q.BITS-1)/K)*K,I=Z;for(let w=O;w>=0;w-=K){U.fill(Z);for(let z=0;z<G;z++){let v=q[z],x=Number(v>>BigInt(w)&M);U[x]=U[x].add($[z])}let T=Z;for(let z=U.length-1,v=Z;z>0;z--)v=v.add(U[z]),T=T.add(v);if(I=I.add(T),w!==0)for(let z=0;z<K;z++)I=I.double()}return I}function f$(J){return A$(J.Fp),LJ(J,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...H$(J.n,J.nBitLength),...J,...{p:J.Fp.ORDER}})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function s0(J){if(J.lowS!==void 0)gJ("lowS",J.lowS);if(J.prehash!==void 0)gJ("prehash",J.prehash)}function FQ(J){let Q=f$(J);LJ(Q,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:$,Fp:q,a:Y}=Q;if($){if(!q.eql(Y,q.ZERO))throw Error("invalid endo: CURVE.a must be 0");if(typeof $!=="object"||typeof $.beta!=="bigint"||typeof $.splitScalar!=="function")throw Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...Q})}class t0 extends Error{constructor(J=""){super(J)}}var KJ={Err:t0,_tlv:{encode:(J,Q)=>{let{Err:$}=KJ;if(J<0||J>256)throw new $("tlv.encode: wrong tag");if(Q.length&1)throw new $("tlv.encode: unpadded data");let q=Q.length/2,Y=iJ(q);if(Y.length/2&128)throw new $("tlv.encode: long form length too big");let G=q>127?iJ(Y.length/2|128):"";return iJ(J)+G+Y+Q},decode(J,Q){let{Err:$}=KJ,q=0;if(J<0||J>256)throw new $("tlv.encode: wrong tag");if(Q.length<2||Q[q++]!==J)throw new $("tlv.decode: wrong tlv");let Y=Q[q++],G=!!(Y&128),Z=0;if(!G)Z=Y;else{let K=Y&127;if(!K)throw new $("tlv.decode(long): indefinite length not supported");if(K>4)throw new $("tlv.decode(long): byte length is too big");let M=Q.subarray(q,q+K);if(M.length!==K)throw new $("tlv.decode: length bytes not complete");if(M[0]===0)throw new $("tlv.decode(long): zero leftmost byte");for(let U of M)Z=Z<<8|U;if(q+=K,Z<128)throw new $("tlv.decode(long): not minimal encoding")}let X=Q.subarray(q,q+Z);if(X.length!==Z)throw new $("tlv.decode: wrong value length");return{v:X,l:Q.subarray(q+Z)}}},_int:{encode(J){let{Err:Q}=KJ;if(J<XJ)throw new Q("integer: negative integers are not allowed");let $=iJ(J);if(Number.parseInt($[0],16)&8)$="00"+$;if($.length&1)throw new Q("unexpected DER parsing assertion: unpadded hex");return $},decode(J){let{Err:Q}=KJ;if(J[0]&128)throw new Q("invalid signature integer: negative");if(J[0]===0&&!(J[1]&128))throw new Q("invalid signature integer: unnecessary leading zero");return ZJ(J)}},toSig(J){let{Err:Q,_int:$,_tlv:q}=KJ,Y=p("signature",J),{v:G,l:Z}=q.decode(48,Y);if(Z.length)throw new Q("invalid signature: left bytes after parsing");let{v:X,l:K}=q.decode(2,G),{v:M,l:U}=q.decode(2,K);if(U.length)throw new Q("invalid signature: left bytes after parsing");return{r:$.decode(X),s:$.decode(M)}},hexFromSig(J){let{_tlv:Q,_int:$}=KJ,q=Q.encode(2,$.encode(J.r)),Y=Q.encode(2,$.encode(J.s)),G=q+Y;return Q.encode(48,G)}};function y$(J,Q){return FJ(IJ(J,Q))}var XJ=BigInt(0),b=BigInt(1),NY=BigInt(2),b$=BigInt(3),fQ=BigInt(4);function yQ(J){let Q=FQ(J),{Fp:$}=Q,q=rJ(Q.n,Q.nBitLength),Y=Q.toBytes||((j,W,D)=>{let R=W.toAffine();return oJ(Uint8Array.from([4]),$.toBytes(R.x),$.toBytes(R.y))}),G=Q.fromBytes||((j)=>{let W=j.subarray(1),D=$.fromBytes(W.subarray(0,$.BYTES)),R=$.fromBytes(W.subarray($.BYTES,2*$.BYTES));return{x:D,y:R}});function Z(j){let{a:W,b:D}=Q,R=$.sqr(j),L=$.mul(R,j);return $.add($.add(L,$.mul(j,W)),D)}function X(j,W){let D=$.sqr(W),R=Z(j);return $.eql(D,R)}if(!X(Q.Gx,Q.Gy))throw Error("bad curve params: generator point");let K=$.mul($.pow(Q.a,b$),fQ),M=$.mul($.sqr(Q.b),BigInt(27));if($.is0($.add(K,M)))throw Error("bad curve params: a or b");function U(j){return K$(j,b,Q.n)}function O(j){let{allowedPrivateKeyLengths:W,nByteLength:D,wrapPrivateKey:R,n:L}=Q;if(W&&typeof j!=="bigint"){if(vJ(j))j=FJ(j);if(typeof j!=="string"||!W.includes(j.length))throw Error("invalid private key");j=j.padStart(D*2,"0")}let C;try{C=typeof j==="bigint"?j:ZJ(p("private key",j,D))}catch(H){throw Error("invalid private key, expected hex or "+D+" bytes, got "+typeof j)}if(R)C=h(C,L);return RJ("private key",C,b,L),C}function I(j){if(!(j instanceof z))throw Error("ProjectivePoint expected")}let w=B$((j,W)=>{let{px:D,py:R,pz:L}=j;if($.eql(L,$.ONE))return{x:D,y:R};let C=j.is0();if(W==null)W=C?$.ONE:$.inv(L);let H=$.mul(D,W),B=$.mul(R,W),S=$.mul(L,W);if(C)return{x:$.ZERO,y:$.ZERO};if(!$.eql(S,$.ONE))throw Error("invZ was invalid");return{x:H,y:B}}),T=B$((j)=>{if(j.is0()){if(Q.allowInfinityPoint&&!$.is0(j.py))return;throw Error("bad point: ZERO")}let{x:W,y:D}=j.toAffine();if(!$.isValid(W)||!$.isValid(D))throw Error("bad point: x or y not FE");if(!X(W,D))throw Error("bad point: equation left != right");if(!j.isTorsionFree())throw Error("bad point: not in prime-order subgroup");return!0});class z{constructor(j,W,D){if(j==null||!$.isValid(j))throw Error("x required");if(W==null||!$.isValid(W)||$.is0(W))throw Error("y required");if(D==null||!$.isValid(D))throw Error("z required");this.px=j,this.py=W,this.pz=D,Object.freeze(this)}static fromAffine(j){let{x:W,y:D}=j||{};if(!j||!$.isValid(W)||!$.isValid(D))throw Error("invalid affine point");if(j instanceof z)throw Error("projective point not allowed");let R=(L)=>$.eql(L,$.ZERO);if(R(W)&&R(D))return z.ZERO;return new z(W,D,$.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(j){let W=S$($,j.map((D)=>D.pz));return j.map((D,R)=>D.toAffine(W[R])).map(z.fromAffine)}static fromHex(j){let W=z.fromAffine(G(p("pointHex",j)));return W.assertValidity(),W}static fromPrivateKey(j){return z.BASE.multiply(O(j))}static msm(j,W){return a0(z,q,j,W)}_setWindowSize(j){f.setWindowSize(this,j)}assertValidity(){T(this)}hasEvenY(){let{y:j}=this.toAffine();if($.isOdd)return!$.isOdd(j);throw Error("Field doesn't support isOdd")}equals(j){I(j);let{px:W,py:D,pz:R}=this,{px:L,py:C,pz:H}=j,B=$.eql($.mul(W,H),$.mul(L,R)),S=$.eql($.mul(D,H),$.mul(C,R));return B&&S}negate(){return new z(this.px,$.neg(this.py),this.pz)}double(){let{a:j,b:W}=Q,D=$.mul(W,b$),{px:R,py:L,pz:C}=this,H=$.ZERO,B=$.ZERO,S=$.ZERO,A=$.mul(R,R),m=$.mul(L,L),F=$.mul(C,C),N=$.mul(R,L);return N=$.add(N,N),S=$.mul(R,C),S=$.add(S,S),H=$.mul(j,S),B=$.mul(D,F),B=$.add(H,B),H=$.sub(m,B),B=$.add(m,B),B=$.mul(H,B),H=$.mul(N,H),S=$.mul(D,S),F=$.mul(j,F),N=$.sub(A,F),N=$.mul(j,N),N=$.add(N,S),S=$.add(A,A),A=$.add(S,A),A=$.add(A,F),A=$.mul(A,N),B=$.add(B,A),F=$.mul(L,C),F=$.add(F,F),A=$.mul(F,N),H=$.sub(H,A),S=$.mul(F,m),S=$.add(S,S),S=$.add(S,S),new z(H,B,S)}add(j){I(j);let{px:W,py:D,pz:R}=this,{px:L,py:C,pz:H}=j,B=$.ZERO,S=$.ZERO,A=$.ZERO,m=Q.a,F=$.mul(Q.b,b$),N=$.mul(W,L),V=$.mul(D,C),k=$.mul(R,H),_=$.add(W,D),P=$.add(L,C);_=$.mul(_,P),P=$.add(N,V),_=$.sub(_,P),P=$.add(W,R);let E=$.add(L,H);return P=$.mul(P,E),E=$.add(N,k),P=$.sub(P,E),E=$.add(D,R),B=$.add(C,H),E=$.mul(E,B),B=$.add(V,k),E=$.sub(E,B),A=$.mul(m,P),B=$.mul(F,k),A=$.add(B,A),B=$.sub(V,A),A=$.add(V,A),S=$.mul(B,A),V=$.add(N,N),V=$.add(V,N),k=$.mul(m,k),P=$.mul(F,P),V=$.add(V,k),k=$.sub(N,k),k=$.mul(m,k),P=$.add(P,k),N=$.mul(V,P),S=$.add(S,N),N=$.mul(E,P),B=$.mul(_,B),B=$.sub(B,N),N=$.mul(_,V),A=$.mul(E,A),A=$.add(A,N),new z(B,S,A)}subtract(j){return this.add(j.negate())}is0(){return this.equals(z.ZERO)}wNAF(j){return f.wNAFCached(this,j,z.normalizeZ)}multiplyUnsafe(j){let{endo:W,n:D}=Q;RJ("scalar",j,XJ,D);let R=z.ZERO;if(j===XJ)return R;if(this.is0()||j===b)return this;if(!W||f.hasPrecomputes(this))return f.wNAFCachedUnsafe(this,j,z.normalizeZ);let{k1neg:L,k1:C,k2neg:H,k2:B}=W.splitScalar(j),S=R,A=R,m=this;while(C>XJ||B>XJ){if(C&b)S=S.add(m);if(B&b)A=A.add(m);m=m.double(),C>>=b,B>>=b}if(L)S=S.negate();if(H)A=A.negate();return A=new z($.mul(A.px,W.beta),A.py,A.pz),S.add(A)}multiply(j){let{endo:W,n:D}=Q;RJ("scalar",j,b,D);let R,L;if(W){let{k1neg:C,k1:H,k2neg:B,k2:S}=W.splitScalar(j),{p:A,f:m}=this.wNAF(H),{p:F,f:N}=this.wNAF(S);A=f.constTimeNegate(C,A),F=f.constTimeNegate(B,F),F=new z($.mul(F.px,W.beta),F.py,F.pz),R=A.add(F),L=m.add(N)}else{let{p:C,f:H}=this.wNAF(j);R=C,L=H}return z.normalizeZ([R,L])[0]}multiplyAndAddUnsafe(j,W,D){let R=z.BASE,L=(H,B)=>B===XJ||B===b||!H.equals(R)?H.multiplyUnsafe(B):H.multiply(B),C=L(this,W).add(L(j,D));return C.is0()?void 0:C}toAffine(j){return w(this,j)}isTorsionFree(){let{h:j,isTorsionFree:W}=Q;if(j===b)return!0;if(W)return W(z,this);throw Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:j,clearCofactor:W}=Q;if(j===b)return this;if(W)return W(z,this);return this.multiplyUnsafe(Q.h)}toRawBytes(j=!0){return gJ("isCompressed",j),this.assertValidity(),Y(z,this,j)}toHex(j=!0){return gJ("isCompressed",j),FJ(this.toRawBytes(j))}}z.BASE=new z(Q.Gx,Q.Gy,$.ONE),z.ZERO=new z($.ZERO,$.ONE,$.ZERO);let{endo:v,nBitLength:x}=Q,f=r0(z,v?Math.ceil(x/2):x);return{CURVE:Q,ProjectivePoint:z,normPrivateKeyToScalar:O,weierstrassEquation:Z,isWithinCurveOrder:U}}function bQ(J){let Q=f$(J);return LJ(Q,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...Q})}function e0(J){let Q=bQ(J),{Fp:$,n:q,nByteLength:Y,nBitLength:G}=Q,Z=$.BYTES+1,X=2*$.BYTES+1;function K(N){return h(N,q)}function M(N){return X$(N,q)}let{ProjectivePoint:U,normPrivateKeyToScalar:O,weierstrassEquation:I,isWithinCurveOrder:w}=yQ({...Q,toBytes(N,V,k){let _=V.toAffine(),P=$.toBytes(_.x),E=oJ;if(gJ("isCompressed",k),k)return E(Uint8Array.from([V.hasEvenY()?2:3]),P);else return E(Uint8Array.from([4]),P,$.toBytes(_.y))},fromBytes(N){let V=N.length,k=N[0],_=N.subarray(1);if(V===Z&&(k===2||k===3)){let P=ZJ(_);if(!K$(P,b,$.ORDER))throw Error("Point is not on curve");let E=I(P),n;try{n=$.sqrt(E)}catch(s){let c=s instanceof Error?": "+s.message:"";throw Error("Point is not on curve"+c)}let l=(n&b)===b;if((k&1)===1!==l)n=$.neg(n);return{x:P,y:n}}else if(V===X&&k===4){let P=$.fromBytes(_.subarray(0,$.BYTES)),E=$.fromBytes(_.subarray($.BYTES,2*$.BYTES));return{x:P,y:E}}else{let P=Z,E=X;throw Error("invalid Point, expected length of "+P+", or uncompressed "+E+", got "+V)}}});function T(N){let V=q>>b;return N>V}function z(N){return T(N)?K(-N):N}let v=(N,V,k)=>ZJ(N.slice(V,k));class x{constructor(N,V,k){if(RJ("r",N,b,q),RJ("s",V,b,q),this.r=N,this.s=V,k!=null)this.recovery=k;Object.freeze(this)}static fromCompact(N){let V=Y;return N=p("compactSignature",N,V*2),new x(v(N,0,V),v(N,V,2*V))}static fromDER(N){let{r:V,s:k}=KJ.toSig(p("DER",N));return new x(V,k)}assertValidity(){}addRecoveryBit(N){return new x(this.r,this.s,N)}recoverPublicKey(N){let{r:V,s:k,recovery:_}=this,P=L(p("msgHash",N));if(_==null||![0,1,2,3].includes(_))throw Error("recovery id invalid");let E=_===2||_===3?V+Q.n:V;if(E>=$.ORDER)throw Error("recovery id 2 or 3 invalid");let n=(_&1)===0?"02":"03",l=U.fromHex(n+y$(E,$.BYTES)),a=M(E),s=K(-P*a),c=K(k*a),MJ=U.BASE.multiplyAndAddUnsafe(l,s,c);if(!MJ)throw Error("point at infinify");return MJ.assertValidity(),MJ}hasHighS(){return T(this.s)}normalizeS(){return this.hasHighS()?new x(this.r,K(-this.s),this.recovery):this}toDERRawBytes(){return nJ(this.toDERHex())}toDERHex(){return KJ.hexFromSig(this)}toCompactRawBytes(){return nJ(this.toCompactHex())}toCompactHex(){let N=Y;return y$(this.r,N)+y$(this.s,N)}}let f={isValidPrivateKey(N){try{return O(N),!0}catch(V){return!1}},normPrivateKeyToScalar:O,randomPrivateKey:()=>{let N=E$(Q.n);return c0(Q.randomBytes(N),Q.n)},precompute(N=8,V=U.BASE){return V._setWindowSize(N),V.multiply(BigInt(3)),V}};function j(N,V=!0){return U.fromPrivateKey(N).toRawBytes(V)}function W(N){if(typeof N==="bigint")return!1;if(N instanceof U)return!0;let k=p("key",N).length,_=$.BYTES,P=_+1,E=2*_+1;if(Q.allowedPrivateKeyLengths||Y===P)return;else return k===P||k===E}function D(N,V,k=!0){if(W(N)===!0)throw Error("first arg must be private key");if(W(V)===!1)throw Error("second arg must be public key");return U.fromHex(V).multiply(O(N)).toRawBytes(k)}let R=Q.bits2int||function(N){if(N.length>8192)throw Error("input is too large");let V=ZJ(N),k=N.length*8-G;return k>0?V>>BigInt(k):V},L=Q.bits2int_modN||function(N){return K(R(N))},C=wJ(G);function H(N){return RJ("num < 2^"+G,N,XJ,C),IJ(N,Y)}function B(N,V,k=S){if(["recovered","canonical"].some((NJ)=>(NJ in k)))throw Error("sign() legacy options not supported");let{hash:_,randomBytes:P}=Q,{lowS:E,prehash:n,extraEntropy:l}=k;if(E==null)E=!0;if(N=p("msgHash",N),s0(k),n)N=p("prehashed msgHash",_(N));let a=L(N),s=O(V),c=[H(s),H(a)];if(l!=null&&l!==!1){let NJ=l===!0?P($.BYTES):l;c.push(p("extraEntropy",NJ))}let MJ=oJ(...c),aJ=a;function M$(NJ){let PJ=R(NJ);if(!w(PJ))return;let U$=M(PJ),fJ=U.BASE.multiply(PJ).toAffine(),WJ=K(fJ.x);if(WJ===XJ)return;let yJ=K(U$*K(aJ+WJ*s));if(yJ===XJ)return;let CJ=(fJ.x===WJ?0:2)|Number(fJ.y&b),l$=yJ;if(E&&T(yJ))l$=z(yJ),CJ^=1;return new x(WJ,l$,CJ)}return{seed:MJ,k2sig:M$}}let S={lowS:Q.lowS,prehash:!1},A={lowS:Q.lowS,prehash:!1};function m(N,V,k=S){let{seed:_,k2sig:P}=B(N,V,k),E=Q;return y0(E.hash.outputLen,E.nByteLength,E.hmac)(_,P)}U.BASE._setWindowSize(8);function F(N,V,k,_=A){let P=N;V=p("msgHash",V),k=p("publicKey",k);let{lowS:E,prehash:n,format:l}=_;if(s0(_),"strict"in _)throw Error("options.strict was renamed to lowS");if(l!==void 0&&l!=="compact"&&l!=="der")throw Error("format must be compact or der");let a=typeof P==="string"||vJ(P),s=!a&&!l&&typeof P==="object"&&P!==null&&typeof P.r==="bigint"&&typeof P.s==="bigint";if(!a&&!s)throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");let c=void 0,MJ;try{if(s)c=new x(P.r,P.s);if(a){try{if(l!=="compact")c=x.fromDER(P)}catch(CJ){if(!(CJ instanceof KJ.Err))throw CJ}if(!c&&l!=="der")c=x.fromCompact(P)}MJ=U.fromHex(k)}catch(CJ){return!1}if(!c)return!1;if(E&&c.hasHighS())return!1;if(n)V=Q.hash(V);let{r:aJ,s:M$}=c,NJ=L(V),PJ=M(M$),U$=K(NJ*PJ),fJ=K(aJ*PJ),WJ=U.BASE.multiplyAndAddUnsafe(MJ,U$,fJ)?.toAffine();if(!WJ)return!1;return K(WJ.x)===aJ}return{CURVE:Q,getPublicKey:j,getSharedSecret:D,sign:m,verify:F,ProjectivePoint:U,Signature:x,utils:f}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function mQ(J){return{hash:J,hmac:(Q,...$)=>D$(J,Q,e$(...$)),randomBytes:J0}}function J8(J,Q){let $=(q)=>e0({...J,...mQ(q)});return{...$(Q),create:$}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */var q8=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),$8=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),hQ=BigInt(0),uQ=BigInt(1),m$=BigInt(2),Q8=(J,Q)=>(J+Q/m$)/Q;function lQ(J){let Q=q8,$=BigInt(3),q=BigInt(6),Y=BigInt(11),G=BigInt(22),Z=BigInt(23),X=BigInt(44),K=BigInt(88),M=J*J*J%Q,U=M*M*J%Q,O=i(U,$,Q)*U%Q,I=i(O,$,Q)*U%Q,w=i(I,m$,Q)*M%Q,T=i(w,Y,Q)*w%Q,z=i(T,G,Q)*T%Q,v=i(z,X,Q)*z%Q,x=i(v,K,Q)*v%Q,f=i(x,X,Q)*z%Q,j=i(f,$,Q)*U%Q,W=i(j,Z,Q)*T%Q,D=i(W,q,Q)*M%Q,R=i(D,m$,Q);if(!h$.eql(h$.sqr(R),J))throw Error("Cannot find square root");return R}var h$=rJ(q8,void 0,void 0,{sqrt:lQ}),u$=J8({a:hQ,b:BigInt(7),Fp:h$,n:$8,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:(J)=>{let Q=$8,$=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),q=-uQ*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),Y=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),G=$,Z=BigInt("0x100000000000000000000000000000000"),X=Q8(G*J,Q),K=Q8(-q*J,Q),M=h(J-X*$-K*Y,Q),U=h(-X*q-K*G,Q),O=M>Z,I=U>Z;if(O)M=Q-M;if(I)U=Q-U;if(M>Z||U>Z)throw Error("splitScalar: Endomorphism failed, k="+J);return{k1neg:O,k1:M,k2neg:I,k2:U}}}},x0);function dQ(){let J=u$.utils.randomPrivateKey();return"0x"+Buffer.from(J).toString("hex")}function cQ(J){let Q=J.startsWith("0x")?J.slice(2):J,$=Buffer.from(Q,"hex"),q=u$.getPublicKey($,!1),G=DJ(q.slice(1)).slice(-20),Z="0x"+Buffer.from(G).toString("hex");return q$(Z)}function pQ(J){let Q;if(typeof J==="string"){let q=J.startsWith("0x")?J.slice(2):J;Q=Buffer.from(q,"hex")}else Q=J;let $=DJ(Q);return"0x"+Buffer.from($).toString("hex")}export{DQ as wrapError,UQ as uint256ToAddress,cQ as privateKeyToAddress,A0 as parseContractError,pQ as keccak256,B0 as isCirclesError,Y8 as hexToBytes,IQ as getErrorMessage,dQ as generatePrivateKey,S8 as encodeFunctionData,x8 as encodeAbiParameters,H8 as decodeFunctionResult,W$ as decodeErrorResult,TQ as circlesConfig,MQ as cidV0ToUint8Array,XQ as cidV0ToHex,q$ as checksumAddress,bJ as bytesToHex,jQ as ZERO_ADDRESS,_J as ValidationError,zQ as SAFE_PROXY_FACTORY,WQ as MAX_FLOW,NQ as INVITATION_FEE,G$ as EncodingError,Z$ as ContractError,QJ as CirclesError,d$ as CirclesConverter,OQ as ACCOUNT_INITIALIZER_HASH,VQ as ACCOUNT_CREATION_CODE_HASH};
|