@strkfarm/sdk 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/modules/pricer.ts
8
2
  import axios2 from "axios";
9
3
 
@@ -1987,2033 +1981,7 @@ import { processMultiProof, processProof } from "@ericnordelo/strk-merkle-tree/d
1987
1981
  import { standardLeafHash } from "@ericnordelo/strk-merkle-tree/dist/hashes";
1988
1982
  import { MerkleTreeImpl } from "@ericnordelo/strk-merkle-tree/dist/merkletree";
1989
1983
  import { num as num2 } from "starknet";
1990
-
1991
- // ../node_modules/@noble/hashes/esm/_assert.js
1992
- function number(n) {
1993
- if (!Number.isSafeInteger(n) || n < 0)
1994
- throw new Error(`Wrong positive integer: ${n}`);
1995
- }
1996
- function bytes(b, ...lengths) {
1997
- if (!(b instanceof Uint8Array))
1998
- throw new Error("Expected Uint8Array");
1999
- if (lengths.length > 0 && !lengths.includes(b.length))
2000
- throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
2001
- }
2002
- function hash(hash6) {
2003
- if (typeof hash6 !== "function" || typeof hash6.create !== "function")
2004
- throw new Error("Hash should be wrapped by utils.wrapConstructor");
2005
- number(hash6.outputLen);
2006
- number(hash6.blockLen);
2007
- }
2008
- function exists(instance, checkFinished = true) {
2009
- if (instance.destroyed)
2010
- throw new Error("Hash instance has been destroyed");
2011
- if (checkFinished && instance.finished)
2012
- throw new Error("Hash#digest() has already been called");
2013
- }
2014
- function output(out, instance) {
2015
- bytes(out);
2016
- const min = instance.outputLen;
2017
- if (out.length < min) {
2018
- throw new Error(`digestInto() expects output buffer of length at least ${min}`);
2019
- }
2020
- }
2021
-
2022
- // ../node_modules/@noble/hashes/esm/cryptoNode.js
2023
- import * as nc from "crypto";
2024
- var crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : void 0;
2025
-
2026
- // ../node_modules/@noble/hashes/esm/utils.js
2027
- var u8a = (a) => a instanceof Uint8Array;
2028
- var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2029
- var rotr = (word, shift) => word << 32 - shift | word >>> shift;
2030
- var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
2031
- if (!isLE)
2032
- throw new Error("Non little-endian hardware is not supported");
2033
- function utf8ToBytes(str) {
2034
- if (typeof str !== "string")
2035
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
2036
- return new Uint8Array(new TextEncoder().encode(str));
2037
- }
2038
- function toBytes(data) {
2039
- if (typeof data === "string")
2040
- data = utf8ToBytes(data);
2041
- if (!u8a(data))
2042
- throw new Error(`expected Uint8Array, got ${typeof data}`);
2043
- return data;
2044
- }
2045
- function concatBytes(...arrays) {
2046
- const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
2047
- let pad = 0;
2048
- arrays.forEach((a) => {
2049
- if (!u8a(a))
2050
- throw new Error("Uint8Array expected");
2051
- r.set(a, pad);
2052
- pad += a.length;
2053
- });
2054
- return r;
2055
- }
2056
- var Hash = class {
2057
- // Safe version that clones internal state
2058
- clone() {
2059
- return this._cloneInto();
2060
- }
2061
- };
2062
- var toStr = {}.toString;
2063
- function wrapConstructor(hashCons) {
2064
- const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
2065
- const tmp = hashCons();
2066
- hashC.outputLen = tmp.outputLen;
2067
- hashC.blockLen = tmp.blockLen;
2068
- hashC.create = () => hashCons();
2069
- return hashC;
2070
- }
2071
- function randomBytes(bytesLength = 32) {
2072
- if (crypto && typeof crypto.getRandomValues === "function") {
2073
- return crypto.getRandomValues(new Uint8Array(bytesLength));
2074
- }
2075
- throw new Error("crypto.getRandomValues must be defined");
2076
- }
2077
-
2078
- // ../node_modules/@noble/hashes/esm/_sha2.js
2079
- function setBigUint64(view, byteOffset, value, isLE2) {
2080
- if (typeof view.setBigUint64 === "function")
2081
- return view.setBigUint64(byteOffset, value, isLE2);
2082
- const _32n = BigInt(32);
2083
- const _u32_max = BigInt(4294967295);
2084
- const wh = Number(value >> _32n & _u32_max);
2085
- const wl = Number(value & _u32_max);
2086
- const h = isLE2 ? 4 : 0;
2087
- const l = isLE2 ? 0 : 4;
2088
- view.setUint32(byteOffset + h, wh, isLE2);
2089
- view.setUint32(byteOffset + l, wl, isLE2);
2090
- }
2091
- var SHA2 = class extends Hash {
2092
- constructor(blockLen, outputLen, padOffset, isLE2) {
2093
- super();
2094
- this.blockLen = blockLen;
2095
- this.outputLen = outputLen;
2096
- this.padOffset = padOffset;
2097
- this.isLE = isLE2;
2098
- this.finished = false;
2099
- this.length = 0;
2100
- this.pos = 0;
2101
- this.destroyed = false;
2102
- this.buffer = new Uint8Array(blockLen);
2103
- this.view = createView(this.buffer);
2104
- }
2105
- update(data) {
2106
- exists(this);
2107
- const { view, buffer, blockLen } = this;
2108
- data = toBytes(data);
2109
- const len = data.length;
2110
- for (let pos = 0; pos < len; ) {
2111
- const take = Math.min(blockLen - this.pos, len - pos);
2112
- if (take === blockLen) {
2113
- const dataView = createView(data);
2114
- for (; blockLen <= len - pos; pos += blockLen)
2115
- this.process(dataView, pos);
2116
- continue;
2117
- }
2118
- buffer.set(data.subarray(pos, pos + take), this.pos);
2119
- this.pos += take;
2120
- pos += take;
2121
- if (this.pos === blockLen) {
2122
- this.process(view, 0);
2123
- this.pos = 0;
2124
- }
2125
- }
2126
- this.length += data.length;
2127
- this.roundClean();
2128
- return this;
2129
- }
2130
- digestInto(out) {
2131
- exists(this);
2132
- output(out, this);
2133
- this.finished = true;
2134
- const { buffer, view, blockLen, isLE: isLE2 } = this;
2135
- let { pos } = this;
2136
- buffer[pos++] = 128;
2137
- this.buffer.subarray(pos).fill(0);
2138
- if (this.padOffset > blockLen - pos) {
2139
- this.process(view, 0);
2140
- pos = 0;
2141
- }
2142
- for (let i = pos; i < blockLen; i++)
2143
- buffer[i] = 0;
2144
- setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
2145
- this.process(view, 0);
2146
- const oview = createView(out);
2147
- const len = this.outputLen;
2148
- if (len % 4)
2149
- throw new Error("_sha2: outputLen should be aligned to 32bit");
2150
- const outLen = len / 4;
2151
- const state = this.get();
2152
- if (outLen > state.length)
2153
- throw new Error("_sha2: outputLen bigger than state");
2154
- for (let i = 0; i < outLen; i++)
2155
- oview.setUint32(4 * i, state[i], isLE2);
2156
- }
2157
- digest() {
2158
- const { buffer, outputLen } = this;
2159
- this.digestInto(buffer);
2160
- const res = buffer.slice(0, outputLen);
2161
- this.destroy();
2162
- return res;
2163
- }
2164
- _cloneInto(to) {
2165
- to || (to = new this.constructor());
2166
- to.set(...this.get());
2167
- const { blockLen, buffer, length, finished, destroyed, pos } = this;
2168
- to.length = length;
2169
- to.pos = pos;
2170
- to.finished = finished;
2171
- to.destroyed = destroyed;
2172
- if (length % blockLen)
2173
- to.buffer.set(buffer);
2174
- return to;
2175
- }
2176
- };
2177
-
2178
- // ../node_modules/@noble/hashes/esm/sha256.js
2179
- var Chi = (a, b, c) => a & b ^ ~a & c;
2180
- var Maj = (a, b, c) => a & b ^ a & c ^ b & c;
2181
- var SHA256_K = /* @__PURE__ */ new Uint32Array([
2182
- 1116352408,
2183
- 1899447441,
2184
- 3049323471,
2185
- 3921009573,
2186
- 961987163,
2187
- 1508970993,
2188
- 2453635748,
2189
- 2870763221,
2190
- 3624381080,
2191
- 310598401,
2192
- 607225278,
2193
- 1426881987,
2194
- 1925078388,
2195
- 2162078206,
2196
- 2614888103,
2197
- 3248222580,
2198
- 3835390401,
2199
- 4022224774,
2200
- 264347078,
2201
- 604807628,
2202
- 770255983,
2203
- 1249150122,
2204
- 1555081692,
2205
- 1996064986,
2206
- 2554220882,
2207
- 2821834349,
2208
- 2952996808,
2209
- 3210313671,
2210
- 3336571891,
2211
- 3584528711,
2212
- 113926993,
2213
- 338241895,
2214
- 666307205,
2215
- 773529912,
2216
- 1294757372,
2217
- 1396182291,
2218
- 1695183700,
2219
- 1986661051,
2220
- 2177026350,
2221
- 2456956037,
2222
- 2730485921,
2223
- 2820302411,
2224
- 3259730800,
2225
- 3345764771,
2226
- 3516065817,
2227
- 3600352804,
2228
- 4094571909,
2229
- 275423344,
2230
- 430227734,
2231
- 506948616,
2232
- 659060556,
2233
- 883997877,
2234
- 958139571,
2235
- 1322822218,
2236
- 1537002063,
2237
- 1747873779,
2238
- 1955562222,
2239
- 2024104815,
2240
- 2227730452,
2241
- 2361852424,
2242
- 2428436474,
2243
- 2756734187,
2244
- 3204031479,
2245
- 3329325298
2246
- ]);
2247
- var IV = /* @__PURE__ */ new Uint32Array([
2248
- 1779033703,
2249
- 3144134277,
2250
- 1013904242,
2251
- 2773480762,
2252
- 1359893119,
2253
- 2600822924,
2254
- 528734635,
2255
- 1541459225
2256
- ]);
2257
- var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
2258
- var SHA256 = class extends SHA2 {
2259
- constructor() {
2260
- super(64, 32, 8, false);
2261
- this.A = IV[0] | 0;
2262
- this.B = IV[1] | 0;
2263
- this.C = IV[2] | 0;
2264
- this.D = IV[3] | 0;
2265
- this.E = IV[4] | 0;
2266
- this.F = IV[5] | 0;
2267
- this.G = IV[6] | 0;
2268
- this.H = IV[7] | 0;
2269
- }
2270
- get() {
2271
- const { A, B, C, D, E, F, G, H } = this;
2272
- return [A, B, C, D, E, F, G, H];
2273
- }
2274
- // prettier-ignore
2275
- set(A, B, C, D, E, F, G, H) {
2276
- this.A = A | 0;
2277
- this.B = B | 0;
2278
- this.C = C | 0;
2279
- this.D = D | 0;
2280
- this.E = E | 0;
2281
- this.F = F | 0;
2282
- this.G = G | 0;
2283
- this.H = H | 0;
2284
- }
2285
- process(view, offset) {
2286
- for (let i = 0; i < 16; i++, offset += 4)
2287
- SHA256_W[i] = view.getUint32(offset, false);
2288
- for (let i = 16; i < 64; i++) {
2289
- const W15 = SHA256_W[i - 15];
2290
- const W2 = SHA256_W[i - 2];
2291
- const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
2292
- const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
2293
- SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
2294
- }
2295
- let { A, B, C, D, E, F, G, H } = this;
2296
- for (let i = 0; i < 64; i++) {
2297
- const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
2298
- const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
2299
- const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
2300
- const T2 = sigma0 + Maj(A, B, C) | 0;
2301
- H = G;
2302
- G = F;
2303
- F = E;
2304
- E = D + T1 | 0;
2305
- D = C;
2306
- C = B;
2307
- B = A;
2308
- A = T1 + T2 | 0;
2309
- }
2310
- A = A + this.A | 0;
2311
- B = B + this.B | 0;
2312
- C = C + this.C | 0;
2313
- D = D + this.D | 0;
2314
- E = E + this.E | 0;
2315
- F = F + this.F | 0;
2316
- G = G + this.G | 0;
2317
- H = H + this.H | 0;
2318
- this.set(A, B, C, D, E, F, G, H);
2319
- }
2320
- roundClean() {
2321
- SHA256_W.fill(0);
2322
- }
2323
- destroy() {
2324
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
2325
- this.buffer.fill(0);
2326
- }
2327
- };
2328
- var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
2329
-
2330
- // ../node_modules/@noble/curves/esm/abstract/utils.js
2331
- var utils_exports = {};
2332
- __export(utils_exports, {
2333
- bitGet: () => bitGet,
2334
- bitLen: () => bitLen,
2335
- bitMask: () => bitMask,
2336
- bitSet: () => bitSet,
2337
- bytesToHex: () => bytesToHex,
2338
- bytesToNumberBE: () => bytesToNumberBE,
2339
- bytesToNumberLE: () => bytesToNumberLE,
2340
- concatBytes: () => concatBytes2,
2341
- createHmacDrbg: () => createHmacDrbg,
2342
- ensureBytes: () => ensureBytes,
2343
- equalBytes: () => equalBytes,
2344
- hexToBytes: () => hexToBytes,
2345
- hexToNumber: () => hexToNumber,
2346
- numberToBytesBE: () => numberToBytesBE,
2347
- numberToBytesLE: () => numberToBytesLE,
2348
- numberToHexUnpadded: () => numberToHexUnpadded,
2349
- numberToVarBytesBE: () => numberToVarBytesBE,
2350
- utf8ToBytes: () => utf8ToBytes2,
2351
- validateObject: () => validateObject
2352
- });
2353
- var _0n = BigInt(0);
2354
- var _1n = BigInt(1);
2355
- var _2n = BigInt(2);
2356
- var u8a2 = (a) => a instanceof Uint8Array;
2357
- var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
2358
- function bytesToHex(bytes2) {
2359
- if (!u8a2(bytes2))
2360
- throw new Error("Uint8Array expected");
2361
- let hex = "";
2362
- for (let i = 0; i < bytes2.length; i++) {
2363
- hex += hexes[bytes2[i]];
2364
- }
2365
- return hex;
2366
- }
2367
- function numberToHexUnpadded(num11) {
2368
- const hex = num11.toString(16);
2369
- return hex.length & 1 ? `0${hex}` : hex;
2370
- }
2371
- function hexToNumber(hex) {
2372
- if (typeof hex !== "string")
2373
- throw new Error("hex string expected, got " + typeof hex);
2374
- return BigInt(hex === "" ? "0" : `0x${hex}`);
2375
- }
2376
- function hexToBytes(hex) {
2377
- if (typeof hex !== "string")
2378
- throw new Error("hex string expected, got " + typeof hex);
2379
- const len = hex.length;
2380
- if (len % 2)
2381
- throw new Error("padded hex string expected, got unpadded hex of length " + len);
2382
- const array = new Uint8Array(len / 2);
2383
- for (let i = 0; i < array.length; i++) {
2384
- const j = i * 2;
2385
- const hexByte = hex.slice(j, j + 2);
2386
- const byte = Number.parseInt(hexByte, 16);
2387
- if (Number.isNaN(byte) || byte < 0)
2388
- throw new Error("Invalid byte sequence");
2389
- array[i] = byte;
2390
- }
2391
- return array;
2392
- }
2393
- function bytesToNumberBE(bytes2) {
2394
- return hexToNumber(bytesToHex(bytes2));
2395
- }
2396
- function bytesToNumberLE(bytes2) {
2397
- if (!u8a2(bytes2))
2398
- throw new Error("Uint8Array expected");
2399
- return hexToNumber(bytesToHex(Uint8Array.from(bytes2).reverse()));
2400
- }
2401
- function numberToBytesBE(n, len) {
2402
- return hexToBytes(n.toString(16).padStart(len * 2, "0"));
2403
- }
2404
- function numberToBytesLE(n, len) {
2405
- return numberToBytesBE(n, len).reverse();
2406
- }
2407
- function numberToVarBytesBE(n) {
2408
- return hexToBytes(numberToHexUnpadded(n));
2409
- }
2410
- function ensureBytes(title, hex, expectedLength) {
2411
- let res;
2412
- if (typeof hex === "string") {
2413
- try {
2414
- res = hexToBytes(hex);
2415
- } catch (e) {
2416
- throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
2417
- }
2418
- } else if (u8a2(hex)) {
2419
- res = Uint8Array.from(hex);
2420
- } else {
2421
- throw new Error(`${title} must be hex string or Uint8Array`);
2422
- }
2423
- const len = res.length;
2424
- if (typeof expectedLength === "number" && len !== expectedLength)
2425
- throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
2426
- return res;
2427
- }
2428
- function concatBytes2(...arrays) {
2429
- const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
2430
- let pad = 0;
2431
- arrays.forEach((a) => {
2432
- if (!u8a2(a))
2433
- throw new Error("Uint8Array expected");
2434
- r.set(a, pad);
2435
- pad += a.length;
2436
- });
2437
- return r;
2438
- }
2439
- function equalBytes(b1, b2) {
2440
- if (b1.length !== b2.length)
2441
- return false;
2442
- for (let i = 0; i < b1.length; i++)
2443
- if (b1[i] !== b2[i])
2444
- return false;
2445
- return true;
2446
- }
2447
- function utf8ToBytes2(str) {
2448
- if (typeof str !== "string")
2449
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
2450
- return new Uint8Array(new TextEncoder().encode(str));
2451
- }
2452
- function bitLen(n) {
2453
- let len;
2454
- for (len = 0; n > _0n; n >>= _1n, len += 1)
2455
- ;
2456
- return len;
2457
- }
2458
- function bitGet(n, pos) {
2459
- return n >> BigInt(pos) & _1n;
2460
- }
2461
- var bitSet = (n, pos, value) => {
2462
- return n | (value ? _1n : _0n) << BigInt(pos);
2463
- };
2464
- var bitMask = (n) => (_2n << BigInt(n - 1)) - _1n;
2465
- var u8n = (data) => new Uint8Array(data);
2466
- var u8fr = (arr) => Uint8Array.from(arr);
2467
- function createHmacDrbg(hashLen, qByteLen, hmacFn) {
2468
- if (typeof hashLen !== "number" || hashLen < 2)
2469
- throw new Error("hashLen must be a number");
2470
- if (typeof qByteLen !== "number" || qByteLen < 2)
2471
- throw new Error("qByteLen must be a number");
2472
- if (typeof hmacFn !== "function")
2473
- throw new Error("hmacFn must be a function");
2474
- let v = u8n(hashLen);
2475
- let k = u8n(hashLen);
2476
- let i = 0;
2477
- const reset = () => {
2478
- v.fill(1);
2479
- k.fill(0);
2480
- i = 0;
2481
- };
2482
- const h = (...b) => hmacFn(k, v, ...b);
2483
- const reseed = (seed = u8n()) => {
2484
- k = h(u8fr([0]), seed);
2485
- v = h();
2486
- if (seed.length === 0)
2487
- return;
2488
- k = h(u8fr([1]), seed);
2489
- v = h();
2490
- };
2491
- const gen = () => {
2492
- if (i++ >= 1e3)
2493
- throw new Error("drbg: tried 1000 values");
2494
- let len = 0;
2495
- const out = [];
2496
- while (len < qByteLen) {
2497
- v = h();
2498
- const sl = v.slice();
2499
- out.push(sl);
2500
- len += v.length;
2501
- }
2502
- return concatBytes2(...out);
2503
- };
2504
- const genUntil = (seed, pred) => {
2505
- reset();
2506
- reseed(seed);
2507
- let res = void 0;
2508
- while (!(res = pred(gen())))
2509
- reseed();
2510
- reset();
2511
- return res;
2512
- };
2513
- return genUntil;
2514
- }
2515
- var validatorFns = {
2516
- bigint: (val) => typeof val === "bigint",
2517
- function: (val) => typeof val === "function",
2518
- boolean: (val) => typeof val === "boolean",
2519
- string: (val) => typeof val === "string",
2520
- stringOrUint8Array: (val) => typeof val === "string" || val instanceof Uint8Array,
2521
- isSafeInteger: (val) => Number.isSafeInteger(val),
2522
- array: (val) => Array.isArray(val),
2523
- field: (val, object) => object.Fp.isValid(val),
2524
- hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
2525
- };
2526
- function validateObject(object, validators, optValidators = {}) {
2527
- const checkField = (fieldName, type, isOptional) => {
2528
- const checkVal = validatorFns[type];
2529
- if (typeof checkVal !== "function")
2530
- throw new Error(`Invalid validator "${type}", expected function`);
2531
- const val = object[fieldName];
2532
- if (isOptional && val === void 0)
2533
- return;
2534
- if (!checkVal(val, object)) {
2535
- throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
2536
- }
2537
- };
2538
- for (const [fieldName, type] of Object.entries(validators))
2539
- checkField(fieldName, type, false);
2540
- for (const [fieldName, type] of Object.entries(optValidators))
2541
- checkField(fieldName, type, true);
2542
- return object;
2543
- }
2544
-
2545
- // ../node_modules/@noble/curves/esm/abstract/modular.js
2546
- var _0n2 = BigInt(0);
2547
- var _1n2 = BigInt(1);
2548
- var _2n2 = BigInt(2);
2549
- var _3n = BigInt(3);
2550
- var _4n = BigInt(4);
2551
- var _5n = BigInt(5);
2552
- var _8n = BigInt(8);
2553
- var _9n = BigInt(9);
2554
- var _16n = BigInt(16);
2555
- function mod(a, b) {
2556
- const result = a % b;
2557
- return result >= _0n2 ? result : b + result;
2558
- }
2559
- function pow(num11, power, modulo) {
2560
- if (modulo <= _0n2 || power < _0n2)
2561
- throw new Error("Expected power/modulo > 0");
2562
- if (modulo === _1n2)
2563
- return _0n2;
2564
- let res = _1n2;
2565
- while (power > _0n2) {
2566
- if (power & _1n2)
2567
- res = res * num11 % modulo;
2568
- num11 = num11 * num11 % modulo;
2569
- power >>= _1n2;
2570
- }
2571
- return res;
2572
- }
2573
- function invert(number2, modulo) {
2574
- if (number2 === _0n2 || modulo <= _0n2) {
2575
- throw new Error(`invert: expected positive integers, got n=${number2} mod=${modulo}`);
2576
- }
2577
- let a = mod(number2, modulo);
2578
- let b = modulo;
2579
- let x = _0n2, y = _1n2, u = _1n2, v = _0n2;
2580
- while (a !== _0n2) {
2581
- const q = b / a;
2582
- const r = b % a;
2583
- const m = x - u * q;
2584
- const n = y - v * q;
2585
- b = a, a = r, x = u, y = v, u = m, v = n;
2586
- }
2587
- const gcd = b;
2588
- if (gcd !== _1n2)
2589
- throw new Error("invert: does not exist");
2590
- return mod(x, modulo);
2591
- }
2592
- function tonelliShanks(P) {
2593
- const legendreC = (P - _1n2) / _2n2;
2594
- let Q, S, Z;
2595
- for (Q = P - _1n2, S = 0; Q % _2n2 === _0n2; Q /= _2n2, S++)
2596
- ;
2597
- for (Z = _2n2; Z < P && pow(Z, legendreC, P) !== P - _1n2; Z++)
2598
- ;
2599
- if (S === 1) {
2600
- const p1div4 = (P + _1n2) / _4n;
2601
- return function tonelliFast(Fp, n) {
2602
- const root = Fp.pow(n, p1div4);
2603
- if (!Fp.eql(Fp.sqr(root), n))
2604
- throw new Error("Cannot find square root");
2605
- return root;
2606
- };
2607
- }
2608
- const Q1div2 = (Q + _1n2) / _2n2;
2609
- return function tonelliSlow(Fp, n) {
2610
- if (Fp.pow(n, legendreC) === Fp.neg(Fp.ONE))
2611
- throw new Error("Cannot find square root");
2612
- let r = S;
2613
- let g = Fp.pow(Fp.mul(Fp.ONE, Z), Q);
2614
- let x = Fp.pow(n, Q1div2);
2615
- let b = Fp.pow(n, Q);
2616
- while (!Fp.eql(b, Fp.ONE)) {
2617
- if (Fp.eql(b, Fp.ZERO))
2618
- return Fp.ZERO;
2619
- let m = 1;
2620
- for (let t2 = Fp.sqr(b); m < r; m++) {
2621
- if (Fp.eql(t2, Fp.ONE))
2622
- break;
2623
- t2 = Fp.sqr(t2);
2624
- }
2625
- const ge = Fp.pow(g, _1n2 << BigInt(r - m - 1));
2626
- g = Fp.sqr(ge);
2627
- x = Fp.mul(x, ge);
2628
- b = Fp.mul(b, g);
2629
- r = m;
2630
- }
2631
- return x;
2632
- };
2633
- }
2634
- function FpSqrt(P) {
2635
- if (P % _4n === _3n) {
2636
- const p1div4 = (P + _1n2) / _4n;
2637
- return function sqrt3mod4(Fp, n) {
2638
- const root = Fp.pow(n, p1div4);
2639
- if (!Fp.eql(Fp.sqr(root), n))
2640
- throw new Error("Cannot find square root");
2641
- return root;
2642
- };
2643
- }
2644
- if (P % _8n === _5n) {
2645
- const c1 = (P - _5n) / _8n;
2646
- return function sqrt5mod8(Fp, n) {
2647
- const n2 = Fp.mul(n, _2n2);
2648
- const v = Fp.pow(n2, c1);
2649
- const nv = Fp.mul(n, v);
2650
- const i = Fp.mul(Fp.mul(nv, _2n2), v);
2651
- const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
2652
- if (!Fp.eql(Fp.sqr(root), n))
2653
- throw new Error("Cannot find square root");
2654
- return root;
2655
- };
2656
- }
2657
- if (P % _16n === _9n) {
2658
- }
2659
- return tonelliShanks(P);
2660
- }
2661
- var FIELD_FIELDS = [
2662
- "create",
2663
- "isValid",
2664
- "is0",
2665
- "neg",
2666
- "inv",
2667
- "sqrt",
2668
- "sqr",
2669
- "eql",
2670
- "add",
2671
- "sub",
2672
- "mul",
2673
- "pow",
2674
- "div",
2675
- "addN",
2676
- "subN",
2677
- "mulN",
2678
- "sqrN"
2679
- ];
2680
- function validateField(field) {
2681
- const initial = {
2682
- ORDER: "bigint",
2683
- MASK: "bigint",
2684
- BYTES: "isSafeInteger",
2685
- BITS: "isSafeInteger"
2686
- };
2687
- const opts = FIELD_FIELDS.reduce((map, val) => {
2688
- map[val] = "function";
2689
- return map;
2690
- }, initial);
2691
- return validateObject(field, opts);
2692
- }
2693
- function FpPow(f, num11, power) {
2694
- if (power < _0n2)
2695
- throw new Error("Expected power > 0");
2696
- if (power === _0n2)
2697
- return f.ONE;
2698
- if (power === _1n2)
2699
- return num11;
2700
- let p = f.ONE;
2701
- let d = num11;
2702
- while (power > _0n2) {
2703
- if (power & _1n2)
2704
- p = f.mul(p, d);
2705
- d = f.sqr(d);
2706
- power >>= _1n2;
2707
- }
2708
- return p;
2709
- }
2710
- function FpInvertBatch(f, nums) {
2711
- const tmp = new Array(nums.length);
2712
- const lastMultiplied = nums.reduce((acc, num11, i) => {
2713
- if (f.is0(num11))
2714
- return acc;
2715
- tmp[i] = acc;
2716
- return f.mul(acc, num11);
2717
- }, f.ONE);
2718
- const inverted = f.inv(lastMultiplied);
2719
- nums.reduceRight((acc, num11, i) => {
2720
- if (f.is0(num11))
2721
- return acc;
2722
- tmp[i] = f.mul(acc, tmp[i]);
2723
- return f.mul(acc, num11);
2724
- }, inverted);
2725
- return tmp;
2726
- }
2727
- function nLength(n, nBitLength2) {
2728
- const _nBitLength = nBitLength2 !== void 0 ? nBitLength2 : n.toString(2).length;
2729
- const nByteLength = Math.ceil(_nBitLength / 8);
2730
- return { nBitLength: _nBitLength, nByteLength };
2731
- }
2732
- function Field(ORDER, bitLen2, isLE2 = false, redef = {}) {
2733
- if (ORDER <= _0n2)
2734
- throw new Error(`Expected Field ORDER > 0, got ${ORDER}`);
2735
- const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
2736
- if (BYTES > 2048)
2737
- throw new Error("Field lengths over 2048 bytes are not supported");
2738
- const sqrtP = FpSqrt(ORDER);
2739
- const f = Object.freeze({
2740
- ORDER,
2741
- BITS,
2742
- BYTES,
2743
- MASK: bitMask(BITS),
2744
- ZERO: _0n2,
2745
- ONE: _1n2,
2746
- create: (num11) => mod(num11, ORDER),
2747
- isValid: (num11) => {
2748
- if (typeof num11 !== "bigint")
2749
- throw new Error(`Invalid field element: expected bigint, got ${typeof num11}`);
2750
- return _0n2 <= num11 && num11 < ORDER;
2751
- },
2752
- is0: (num11) => num11 === _0n2,
2753
- isOdd: (num11) => (num11 & _1n2) === _1n2,
2754
- neg: (num11) => mod(-num11, ORDER),
2755
- eql: (lhs, rhs) => lhs === rhs,
2756
- sqr: (num11) => mod(num11 * num11, ORDER),
2757
- add: (lhs, rhs) => mod(lhs + rhs, ORDER),
2758
- sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
2759
- mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
2760
- pow: (num11, power) => FpPow(f, num11, power),
2761
- div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
2762
- // Same as above, but doesn't normalize
2763
- sqrN: (num11) => num11 * num11,
2764
- addN: (lhs, rhs) => lhs + rhs,
2765
- subN: (lhs, rhs) => lhs - rhs,
2766
- mulN: (lhs, rhs) => lhs * rhs,
2767
- inv: (num11) => invert(num11, ORDER),
2768
- sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
2769
- invertBatch: (lst) => FpInvertBatch(f, lst),
2770
- // TODO: do we really need constant cmov?
2771
- // We don't have const-time bigints anyway, so probably will be not very useful
2772
- cmov: (a, b, c) => c ? b : a,
2773
- toBytes: (num11) => isLE2 ? numberToBytesLE(num11, BYTES) : numberToBytesBE(num11, BYTES),
2774
- fromBytes: (bytes2) => {
2775
- if (bytes2.length !== BYTES)
2776
- throw new Error(`Fp.fromBytes: expected ${BYTES}, got ${bytes2.length}`);
2777
- return isLE2 ? bytesToNumberLE(bytes2) : bytesToNumberBE(bytes2);
2778
- }
2779
- });
2780
- return Object.freeze(f);
2781
- }
2782
- function getFieldBytesLength(fieldOrder) {
2783
- if (typeof fieldOrder !== "bigint")
2784
- throw new Error("field order must be bigint");
2785
- const bitLength = fieldOrder.toString(2).length;
2786
- return Math.ceil(bitLength / 8);
2787
- }
2788
- function getMinHashLength(fieldOrder) {
2789
- const length = getFieldBytesLength(fieldOrder);
2790
- return length + Math.ceil(length / 2);
2791
- }
2792
- function mapHashToField(key, fieldOrder, isLE2 = false) {
2793
- const len = key.length;
2794
- const fieldLen = getFieldBytesLength(fieldOrder);
2795
- const minLen = getMinHashLength(fieldOrder);
2796
- if (len < 16 || len < minLen || len > 1024)
2797
- throw new Error(`expected ${minLen}-1024 bytes of input, got ${len}`);
2798
- const num11 = isLE2 ? bytesToNumberBE(key) : bytesToNumberLE(key);
2799
- const reduced = mod(num11, fieldOrder - _1n2) + _1n2;
2800
- return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
2801
- }
2802
-
2803
- // ../node_modules/@noble/curves/esm/abstract/poseidon.js
2804
- function validateOpts(opts) {
2805
- const { Fp, mds, reversePartialPowIdx: rev, roundConstants: rc } = opts;
2806
- const { roundsFull, roundsPartial, sboxPower, t } = opts;
2807
- validateField(Fp);
2808
- for (const i of ["t", "roundsFull", "roundsPartial"]) {
2809
- if (typeof opts[i] !== "number" || !Number.isSafeInteger(opts[i]))
2810
- throw new Error(`Poseidon: invalid param ${i}=${opts[i]} (${typeof opts[i]})`);
2811
- }
2812
- if (!Array.isArray(mds) || mds.length !== t)
2813
- throw new Error("Poseidon: wrong MDS matrix");
2814
- const _mds = mds.map((mdsRow) => {
2815
- if (!Array.isArray(mdsRow) || mdsRow.length !== t)
2816
- throw new Error(`Poseidon MDS matrix row: ${mdsRow}`);
2817
- return mdsRow.map((i) => {
2818
- if (typeof i !== "bigint")
2819
- throw new Error(`Poseidon MDS matrix value=${i}`);
2820
- return Fp.create(i);
2821
- });
2822
- });
2823
- if (rev !== void 0 && typeof rev !== "boolean")
2824
- throw new Error(`Poseidon: invalid param reversePartialPowIdx=${rev}`);
2825
- if (roundsFull % 2 !== 0)
2826
- throw new Error(`Poseidon roundsFull is not even: ${roundsFull}`);
2827
- const rounds = roundsFull + roundsPartial;
2828
- if (!Array.isArray(rc) || rc.length !== rounds)
2829
- throw new Error("Poseidon: wrong round constants");
2830
- const roundConstants = rc.map((rc2) => {
2831
- if (!Array.isArray(rc2) || rc2.length !== t)
2832
- throw new Error(`Poseidon wrong round constants: ${rc2}`);
2833
- return rc2.map((i) => {
2834
- if (typeof i !== "bigint" || !Fp.isValid(i))
2835
- throw new Error(`Poseidon wrong round constant=${i}`);
2836
- return Fp.create(i);
2837
- });
2838
- });
2839
- if (!sboxPower || ![3, 5, 7].includes(sboxPower))
2840
- throw new Error(`Poseidon wrong sboxPower=${sboxPower}`);
2841
- const _sboxPower = BigInt(sboxPower);
2842
- let sboxFn = (n) => FpPow(Fp, n, _sboxPower);
2843
- if (sboxPower === 3)
2844
- sboxFn = (n) => Fp.mul(Fp.sqrN(n), n);
2845
- else if (sboxPower === 5)
2846
- sboxFn = (n) => Fp.mul(Fp.sqrN(Fp.sqrN(n)), n);
2847
- return Object.freeze({ ...opts, rounds, sboxFn, roundConstants, mds: _mds });
2848
- }
2849
- function poseidon(opts) {
2850
- const _opts = validateOpts(opts);
2851
- const { Fp, mds, roundConstants, rounds, roundsPartial, sboxFn, t } = _opts;
2852
- const halfRoundsFull = _opts.roundsFull / 2;
2853
- const partialIdx = _opts.reversePartialPowIdx ? t - 1 : 0;
2854
- const poseidonRound = (values, isFull, idx) => {
2855
- values = values.map((i, j) => Fp.add(i, roundConstants[idx][j]));
2856
- if (isFull)
2857
- values = values.map((i) => sboxFn(i));
2858
- else
2859
- values[partialIdx] = sboxFn(values[partialIdx]);
2860
- values = mds.map((i) => i.reduce((acc, i2, j) => Fp.add(acc, Fp.mulN(i2, values[j])), Fp.ZERO));
2861
- return values;
2862
- };
2863
- const poseidonHash = function poseidonHash2(values) {
2864
- if (!Array.isArray(values) || values.length !== t)
2865
- throw new Error(`Poseidon: wrong values (expected array of bigints with length ${t})`);
2866
- values = values.map((i) => {
2867
- if (typeof i !== "bigint")
2868
- throw new Error(`Poseidon: wrong value=${i} (${typeof i})`);
2869
- return Fp.create(i);
2870
- });
2871
- let round = 0;
2872
- for (let i = 0; i < halfRoundsFull; i++)
2873
- values = poseidonRound(values, true, round++);
2874
- for (let i = 0; i < roundsPartial; i++)
2875
- values = poseidonRound(values, false, round++);
2876
- for (let i = 0; i < halfRoundsFull; i++)
2877
- values = poseidonRound(values, true, round++);
2878
- if (round !== rounds)
2879
- throw new Error(`Poseidon: wrong number of rounds: last round=${round}, total=${rounds}`);
2880
- return values;
2881
- };
2882
- poseidonHash.roundConstants = roundConstants;
2883
- return poseidonHash;
2884
- }
2885
-
2886
- // ../node_modules/@noble/curves/esm/abstract/curve.js
2887
- var _0n3 = BigInt(0);
2888
- var _1n3 = BigInt(1);
2889
- function wNAF(c, bits) {
2890
- const constTimeNegate = (condition, item) => {
2891
- const neg = item.negate();
2892
- return condition ? neg : item;
2893
- };
2894
- const opts = (W) => {
2895
- const windows = Math.ceil(bits / W) + 1;
2896
- const windowSize = 2 ** (W - 1);
2897
- return { windows, windowSize };
2898
- };
2899
- return {
2900
- constTimeNegate,
2901
- // non-const time multiplication ladder
2902
- unsafeLadder(elm, n) {
2903
- let p = c.ZERO;
2904
- let d = elm;
2905
- while (n > _0n3) {
2906
- if (n & _1n3)
2907
- p = p.add(d);
2908
- d = d.double();
2909
- n >>= _1n3;
2910
- }
2911
- return p;
2912
- },
2913
- /**
2914
- * Creates a wNAF precomputation window. Used for caching.
2915
- * Default window size is set by `utils.precompute()` and is equal to 8.
2916
- * Number of precomputed points depends on the curve size:
2917
- * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
2918
- * - 𝑊 is the window size
2919
- * - 𝑛 is the bitlength of the curve order.
2920
- * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
2921
- * @returns precomputed point tables flattened to a single array
2922
- */
2923
- precomputeWindow(elm, W) {
2924
- const { windows, windowSize } = opts(W);
2925
- const points = [];
2926
- let p = elm;
2927
- let base = p;
2928
- for (let window = 0; window < windows; window++) {
2929
- base = p;
2930
- points.push(base);
2931
- for (let i = 1; i < windowSize; i++) {
2932
- base = base.add(p);
2933
- points.push(base);
2934
- }
2935
- p = base.double();
2936
- }
2937
- return points;
2938
- },
2939
- /**
2940
- * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
2941
- * @param W window size
2942
- * @param precomputes precomputed tables
2943
- * @param n scalar (we don't check here, but should be less than curve order)
2944
- * @returns real and fake (for const-time) points
2945
- */
2946
- wNAF(W, precomputes, n) {
2947
- const { windows, windowSize } = opts(W);
2948
- let p = c.ZERO;
2949
- let f = c.BASE;
2950
- const mask = BigInt(2 ** W - 1);
2951
- const maxNumber = 2 ** W;
2952
- const shiftBy = BigInt(W);
2953
- for (let window = 0; window < windows; window++) {
2954
- const offset = window * windowSize;
2955
- let wbits = Number(n & mask);
2956
- n >>= shiftBy;
2957
- if (wbits > windowSize) {
2958
- wbits -= maxNumber;
2959
- n += _1n3;
2960
- }
2961
- const offset1 = offset;
2962
- const offset2 = offset + Math.abs(wbits) - 1;
2963
- const cond1 = window % 2 !== 0;
2964
- const cond2 = wbits < 0;
2965
- if (wbits === 0) {
2966
- f = f.add(constTimeNegate(cond1, precomputes[offset1]));
2967
- } else {
2968
- p = p.add(constTimeNegate(cond2, precomputes[offset2]));
2969
- }
2970
- }
2971
- return { p, f };
2972
- },
2973
- wNAFCached(P, precomputesMap, n, transform) {
2974
- const W = P._WINDOW_SIZE || 1;
2975
- let comp = precomputesMap.get(P);
2976
- if (!comp) {
2977
- comp = this.precomputeWindow(P, W);
2978
- if (W !== 1) {
2979
- precomputesMap.set(P, transform(comp));
2980
- }
2981
- }
2982
- return this.wNAF(W, comp, n);
2983
- }
2984
- };
2985
- }
2986
- function validateBasic(curve2) {
2987
- validateField(curve2.Fp);
2988
- validateObject(curve2, {
2989
- n: "bigint",
2990
- h: "bigint",
2991
- Gx: "field",
2992
- Gy: "field"
2993
- }, {
2994
- nBitLength: "isSafeInteger",
2995
- nByteLength: "isSafeInteger"
2996
- });
2997
- return Object.freeze({
2998
- ...nLength(curve2.n, curve2.nBitLength),
2999
- ...curve2,
3000
- ...{ p: curve2.Fp.ORDER }
3001
- });
3002
- }
3003
-
3004
- // ../node_modules/@noble/curves/esm/abstract/weierstrass.js
3005
- function validatePointOpts(curve2) {
3006
- const opts = validateBasic(curve2);
3007
- validateObject(opts, {
3008
- a: "field",
3009
- b: "field"
3010
- }, {
3011
- allowedPrivateKeyLengths: "array",
3012
- wrapPrivateKey: "boolean",
3013
- isTorsionFree: "function",
3014
- clearCofactor: "function",
3015
- allowInfinityPoint: "boolean",
3016
- fromBytes: "function",
3017
- toBytes: "function"
3018
- });
3019
- const { endo, Fp, a } = opts;
3020
- if (endo) {
3021
- if (!Fp.eql(a, Fp.ZERO)) {
3022
- throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");
3023
- }
3024
- if (typeof endo !== "object" || typeof endo.beta !== "bigint" || typeof endo.splitScalar !== "function") {
3025
- throw new Error("Expected endomorphism with beta: bigint and splitScalar: function");
3026
- }
3027
- }
3028
- return Object.freeze({ ...opts });
3029
- }
3030
- var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports;
3031
- var DER = {
3032
- // asn.1 DER encoding utils
3033
- Err: class DERErr extends Error {
3034
- constructor(m = "") {
3035
- super(m);
3036
- }
3037
- },
3038
- _parseInt(data) {
3039
- const { Err: E } = DER;
3040
- if (data.length < 2 || data[0] !== 2)
3041
- throw new E("Invalid signature integer tag");
3042
- const len = data[1];
3043
- const res = data.subarray(2, len + 2);
3044
- if (!len || res.length !== len)
3045
- throw new E("Invalid signature integer: wrong length");
3046
- if (res[0] & 128)
3047
- throw new E("Invalid signature integer: negative");
3048
- if (res[0] === 0 && !(res[1] & 128))
3049
- throw new E("Invalid signature integer: unnecessary leading zero");
3050
- return { d: b2n(res), l: data.subarray(len + 2) };
3051
- },
3052
- toSig(hex) {
3053
- const { Err: E } = DER;
3054
- const data = typeof hex === "string" ? h2b(hex) : hex;
3055
- if (!(data instanceof Uint8Array))
3056
- throw new Error("ui8a expected");
3057
- let l = data.length;
3058
- if (l < 2 || data[0] != 48)
3059
- throw new E("Invalid signature tag");
3060
- if (data[1] !== l - 2)
3061
- throw new E("Invalid signature: incorrect length");
3062
- const { d: r, l: sBytes } = DER._parseInt(data.subarray(2));
3063
- const { d: s, l: rBytesLeft } = DER._parseInt(sBytes);
3064
- if (rBytesLeft.length)
3065
- throw new E("Invalid signature: left bytes after parsing");
3066
- return { r, s };
3067
- },
3068
- hexFromSig(sig) {
3069
- const slice = (s2) => Number.parseInt(s2[0], 16) & 8 ? "00" + s2 : s2;
3070
- const h = (num11) => {
3071
- const hex = num11.toString(16);
3072
- return hex.length & 1 ? `0${hex}` : hex;
3073
- };
3074
- const s = slice(h(sig.s));
3075
- const r = slice(h(sig.r));
3076
- const shl = s.length / 2;
3077
- const rhl = r.length / 2;
3078
- const sl = h(shl);
3079
- const rl = h(rhl);
3080
- return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
3081
- }
3082
- };
3083
- var _0n4 = BigInt(0);
3084
- var _1n4 = BigInt(1);
3085
- var _2n3 = BigInt(2);
3086
- var _3n2 = BigInt(3);
3087
- var _4n2 = BigInt(4);
3088
- function weierstrassPoints(opts) {
3089
- const CURVE2 = validatePointOpts(opts);
3090
- const { Fp } = CURVE2;
3091
- const toBytes2 = CURVE2.toBytes || ((_c, point, _isCompressed) => {
3092
- const a = point.toAffine();
3093
- return concatBytes2(Uint8Array.from([4]), Fp.toBytes(a.x), Fp.toBytes(a.y));
3094
- });
3095
- const fromBytes = CURVE2.fromBytes || ((bytes2) => {
3096
- const tail = bytes2.subarray(1);
3097
- const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
3098
- const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
3099
- return { x, y };
3100
- });
3101
- function weierstrassEquation(x) {
3102
- const { a, b } = CURVE2;
3103
- const x2 = Fp.sqr(x);
3104
- const x3 = Fp.mul(x2, x);
3105
- return Fp.add(Fp.add(x3, Fp.mul(x, a)), b);
3106
- }
3107
- if (!Fp.eql(Fp.sqr(CURVE2.Gy), weierstrassEquation(CURVE2.Gx)))
3108
- throw new Error("bad generator point: equation left != right");
3109
- function isWithinCurveOrder(num11) {
3110
- return typeof num11 === "bigint" && _0n4 < num11 && num11 < CURVE2.n;
3111
- }
3112
- function assertGE(num11) {
3113
- if (!isWithinCurveOrder(num11))
3114
- throw new Error("Expected valid bigint: 0 < bigint < curve.n");
3115
- }
3116
- function normPrivateKeyToScalar(key) {
3117
- const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE2;
3118
- if (lengths && typeof key !== "bigint") {
3119
- if (key instanceof Uint8Array)
3120
- key = bytesToHex(key);
3121
- if (typeof key !== "string" || !lengths.includes(key.length))
3122
- throw new Error("Invalid key");
3123
- key = key.padStart(nByteLength * 2, "0");
3124
- }
3125
- let num11;
3126
- try {
3127
- num11 = typeof key === "bigint" ? key : bytesToNumberBE(ensureBytes("private key", key, nByteLength));
3128
- } catch (error) {
3129
- throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
3130
- }
3131
- if (wrapPrivateKey)
3132
- num11 = mod(num11, n);
3133
- assertGE(num11);
3134
- return num11;
3135
- }
3136
- const pointPrecomputes = /* @__PURE__ */ new Map();
3137
- function assertPrjPoint(other) {
3138
- if (!(other instanceof Point))
3139
- throw new Error("ProjectivePoint expected");
3140
- }
3141
- class Point {
3142
- constructor(px, py, pz) {
3143
- this.px = px;
3144
- this.py = py;
3145
- this.pz = pz;
3146
- if (px == null || !Fp.isValid(px))
3147
- throw new Error("x required");
3148
- if (py == null || !Fp.isValid(py))
3149
- throw new Error("y required");
3150
- if (pz == null || !Fp.isValid(pz))
3151
- throw new Error("z required");
3152
- }
3153
- // Does not validate if the point is on-curve.
3154
- // Use fromHex instead, or call assertValidity() later.
3155
- static fromAffine(p) {
3156
- const { x, y } = p || {};
3157
- if (!p || !Fp.isValid(x) || !Fp.isValid(y))
3158
- throw new Error("invalid affine point");
3159
- if (p instanceof Point)
3160
- throw new Error("projective point not allowed");
3161
- const is0 = (i) => Fp.eql(i, Fp.ZERO);
3162
- if (is0(x) && is0(y))
3163
- return Point.ZERO;
3164
- return new Point(x, y, Fp.ONE);
3165
- }
3166
- get x() {
3167
- return this.toAffine().x;
3168
- }
3169
- get y() {
3170
- return this.toAffine().y;
3171
- }
3172
- /**
3173
- * Takes a bunch of Projective Points but executes only one
3174
- * inversion on all of them. Inversion is very slow operation,
3175
- * so this improves performance massively.
3176
- * Optimization: converts a list of projective points to a list of identical points with Z=1.
3177
- */
3178
- static normalizeZ(points) {
3179
- const toInv = Fp.invertBatch(points.map((p) => p.pz));
3180
- return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
3181
- }
3182
- /**
3183
- * Converts hash string or Uint8Array to Point.
3184
- * @param hex short/long ECDSA hex
3185
- */
3186
- static fromHex(hex) {
3187
- const P = Point.fromAffine(fromBytes(ensureBytes("pointHex", hex)));
3188
- P.assertValidity();
3189
- return P;
3190
- }
3191
- // Multiplies generator point by privateKey.
3192
- static fromPrivateKey(privateKey) {
3193
- return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
3194
- }
3195
- // "Private method", don't use it directly
3196
- _setWindowSize(windowSize) {
3197
- this._WINDOW_SIZE = windowSize;
3198
- pointPrecomputes.delete(this);
3199
- }
3200
- // A point on curve is valid if it conforms to equation.
3201
- assertValidity() {
3202
- if (this.is0()) {
3203
- if (CURVE2.allowInfinityPoint && !Fp.is0(this.py))
3204
- return;
3205
- throw new Error("bad point: ZERO");
3206
- }
3207
- const { x, y } = this.toAffine();
3208
- if (!Fp.isValid(x) || !Fp.isValid(y))
3209
- throw new Error("bad point: x or y not FE");
3210
- const left = Fp.sqr(y);
3211
- const right = weierstrassEquation(x);
3212
- if (!Fp.eql(left, right))
3213
- throw new Error("bad point: equation left != right");
3214
- if (!this.isTorsionFree())
3215
- throw new Error("bad point: not in prime-order subgroup");
3216
- }
3217
- hasEvenY() {
3218
- const { y } = this.toAffine();
3219
- if (Fp.isOdd)
3220
- return !Fp.isOdd(y);
3221
- throw new Error("Field doesn't support isOdd");
3222
- }
3223
- /**
3224
- * Compare one point to another.
3225
- */
3226
- equals(other) {
3227
- assertPrjPoint(other);
3228
- const { px: X1, py: Y1, pz: Z1 } = this;
3229
- const { px: X2, py: Y2, pz: Z2 } = other;
3230
- const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
3231
- const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
3232
- return U1 && U2;
3233
- }
3234
- /**
3235
- * Flips point to one corresponding to (x, -y) in Affine coordinates.
3236
- */
3237
- negate() {
3238
- return new Point(this.px, Fp.neg(this.py), this.pz);
3239
- }
3240
- // Renes-Costello-Batina exception-free doubling formula.
3241
- // There is 30% faster Jacobian formula, but it is not complete.
3242
- // https://eprint.iacr.org/2015/1060, algorithm 3
3243
- // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
3244
- double() {
3245
- const { a, b } = CURVE2;
3246
- const b3 = Fp.mul(b, _3n2);
3247
- const { px: X1, py: Y1, pz: Z1 } = this;
3248
- let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
3249
- let t0 = Fp.mul(X1, X1);
3250
- let t1 = Fp.mul(Y1, Y1);
3251
- let t2 = Fp.mul(Z1, Z1);
3252
- let t3 = Fp.mul(X1, Y1);
3253
- t3 = Fp.add(t3, t3);
3254
- Z3 = Fp.mul(X1, Z1);
3255
- Z3 = Fp.add(Z3, Z3);
3256
- X3 = Fp.mul(a, Z3);
3257
- Y3 = Fp.mul(b3, t2);
3258
- Y3 = Fp.add(X3, Y3);
3259
- X3 = Fp.sub(t1, Y3);
3260
- Y3 = Fp.add(t1, Y3);
3261
- Y3 = Fp.mul(X3, Y3);
3262
- X3 = Fp.mul(t3, X3);
3263
- Z3 = Fp.mul(b3, Z3);
3264
- t2 = Fp.mul(a, t2);
3265
- t3 = Fp.sub(t0, t2);
3266
- t3 = Fp.mul(a, t3);
3267
- t3 = Fp.add(t3, Z3);
3268
- Z3 = Fp.add(t0, t0);
3269
- t0 = Fp.add(Z3, t0);
3270
- t0 = Fp.add(t0, t2);
3271
- t0 = Fp.mul(t0, t3);
3272
- Y3 = Fp.add(Y3, t0);
3273
- t2 = Fp.mul(Y1, Z1);
3274
- t2 = Fp.add(t2, t2);
3275
- t0 = Fp.mul(t2, t3);
3276
- X3 = Fp.sub(X3, t0);
3277
- Z3 = Fp.mul(t2, t1);
3278
- Z3 = Fp.add(Z3, Z3);
3279
- Z3 = Fp.add(Z3, Z3);
3280
- return new Point(X3, Y3, Z3);
3281
- }
3282
- // Renes-Costello-Batina exception-free addition formula.
3283
- // There is 30% faster Jacobian formula, but it is not complete.
3284
- // https://eprint.iacr.org/2015/1060, algorithm 1
3285
- // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
3286
- add(other) {
3287
- assertPrjPoint(other);
3288
- const { px: X1, py: Y1, pz: Z1 } = this;
3289
- const { px: X2, py: Y2, pz: Z2 } = other;
3290
- let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO;
3291
- const a = CURVE2.a;
3292
- const b3 = Fp.mul(CURVE2.b, _3n2);
3293
- let t0 = Fp.mul(X1, X2);
3294
- let t1 = Fp.mul(Y1, Y2);
3295
- let t2 = Fp.mul(Z1, Z2);
3296
- let t3 = Fp.add(X1, Y1);
3297
- let t4 = Fp.add(X2, Y2);
3298
- t3 = Fp.mul(t3, t4);
3299
- t4 = Fp.add(t0, t1);
3300
- t3 = Fp.sub(t3, t4);
3301
- t4 = Fp.add(X1, Z1);
3302
- let t5 = Fp.add(X2, Z2);
3303
- t4 = Fp.mul(t4, t5);
3304
- t5 = Fp.add(t0, t2);
3305
- t4 = Fp.sub(t4, t5);
3306
- t5 = Fp.add(Y1, Z1);
3307
- X3 = Fp.add(Y2, Z2);
3308
- t5 = Fp.mul(t5, X3);
3309
- X3 = Fp.add(t1, t2);
3310
- t5 = Fp.sub(t5, X3);
3311
- Z3 = Fp.mul(a, t4);
3312
- X3 = Fp.mul(b3, t2);
3313
- Z3 = Fp.add(X3, Z3);
3314
- X3 = Fp.sub(t1, Z3);
3315
- Z3 = Fp.add(t1, Z3);
3316
- Y3 = Fp.mul(X3, Z3);
3317
- t1 = Fp.add(t0, t0);
3318
- t1 = Fp.add(t1, t0);
3319
- t2 = Fp.mul(a, t2);
3320
- t4 = Fp.mul(b3, t4);
3321
- t1 = Fp.add(t1, t2);
3322
- t2 = Fp.sub(t0, t2);
3323
- t2 = Fp.mul(a, t2);
3324
- t4 = Fp.add(t4, t2);
3325
- t0 = Fp.mul(t1, t4);
3326
- Y3 = Fp.add(Y3, t0);
3327
- t0 = Fp.mul(t5, t4);
3328
- X3 = Fp.mul(t3, X3);
3329
- X3 = Fp.sub(X3, t0);
3330
- t0 = Fp.mul(t3, t1);
3331
- Z3 = Fp.mul(t5, Z3);
3332
- Z3 = Fp.add(Z3, t0);
3333
- return new Point(X3, Y3, Z3);
3334
- }
3335
- subtract(other) {
3336
- return this.add(other.negate());
3337
- }
3338
- is0() {
3339
- return this.equals(Point.ZERO);
3340
- }
3341
- wNAF(n) {
3342
- return wnaf.wNAFCached(this, pointPrecomputes, n, (comp) => {
3343
- const toInv = Fp.invertBatch(comp.map((p) => p.pz));
3344
- return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
3345
- });
3346
- }
3347
- /**
3348
- * Non-constant-time multiplication. Uses double-and-add algorithm.
3349
- * It's faster, but should only be used when you don't care about
3350
- * an exposed private key e.g. sig verification, which works over *public* keys.
3351
- */
3352
- multiplyUnsafe(n) {
3353
- const I = Point.ZERO;
3354
- if (n === _0n4)
3355
- return I;
3356
- assertGE(n);
3357
- if (n === _1n4)
3358
- return this;
3359
- const { endo } = CURVE2;
3360
- if (!endo)
3361
- return wnaf.unsafeLadder(this, n);
3362
- let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
3363
- let k1p = I;
3364
- let k2p = I;
3365
- let d = this;
3366
- while (k1 > _0n4 || k2 > _0n4) {
3367
- if (k1 & _1n4)
3368
- k1p = k1p.add(d);
3369
- if (k2 & _1n4)
3370
- k2p = k2p.add(d);
3371
- d = d.double();
3372
- k1 >>= _1n4;
3373
- k2 >>= _1n4;
3374
- }
3375
- if (k1neg)
3376
- k1p = k1p.negate();
3377
- if (k2neg)
3378
- k2p = k2p.negate();
3379
- k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
3380
- return k1p.add(k2p);
3381
- }
3382
- /**
3383
- * Constant time multiplication.
3384
- * Uses wNAF method. Windowed method may be 10% faster,
3385
- * but takes 2x longer to generate and consumes 2x memory.
3386
- * Uses precomputes when available.
3387
- * Uses endomorphism for Koblitz curves.
3388
- * @param scalar by which the point would be multiplied
3389
- * @returns New point
3390
- */
3391
- multiply(scalar) {
3392
- assertGE(scalar);
3393
- let n = scalar;
3394
- let point, fake;
3395
- const { endo } = CURVE2;
3396
- if (endo) {
3397
- const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
3398
- let { p: k1p, f: f1p } = this.wNAF(k1);
3399
- let { p: k2p, f: f2p } = this.wNAF(k2);
3400
- k1p = wnaf.constTimeNegate(k1neg, k1p);
3401
- k2p = wnaf.constTimeNegate(k2neg, k2p);
3402
- k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
3403
- point = k1p.add(k2p);
3404
- fake = f1p.add(f2p);
3405
- } else {
3406
- const { p, f } = this.wNAF(n);
3407
- point = p;
3408
- fake = f;
3409
- }
3410
- return Point.normalizeZ([point, fake])[0];
3411
- }
3412
- /**
3413
- * Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
3414
- * Not using Strauss-Shamir trick: precomputation tables are faster.
3415
- * The trick could be useful if both P and Q are not G (not in our case).
3416
- * @returns non-zero affine point
3417
- */
3418
- multiplyAndAddUnsafe(Q, a, b) {
3419
- const G = Point.BASE;
3420
- const mul = (P, a2) => a2 === _0n4 || a2 === _1n4 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
3421
- const sum = mul(this, a).add(mul(Q, b));
3422
- return sum.is0() ? void 0 : sum;
3423
- }
3424
- // Converts Projective point to affine (x, y) coordinates.
3425
- // Can accept precomputed Z^-1 - for example, from invertBatch.
3426
- // (x, y, z) ∋ (x=x/z, y=y/z)
3427
- toAffine(iz) {
3428
- const { px: x, py: y, pz: z } = this;
3429
- const is0 = this.is0();
3430
- if (iz == null)
3431
- iz = is0 ? Fp.ONE : Fp.inv(z);
3432
- const ax = Fp.mul(x, iz);
3433
- const ay = Fp.mul(y, iz);
3434
- const zz = Fp.mul(z, iz);
3435
- if (is0)
3436
- return { x: Fp.ZERO, y: Fp.ZERO };
3437
- if (!Fp.eql(zz, Fp.ONE))
3438
- throw new Error("invZ was invalid");
3439
- return { x: ax, y: ay };
3440
- }
3441
- isTorsionFree() {
3442
- const { h: cofactor, isTorsionFree } = CURVE2;
3443
- if (cofactor === _1n4)
3444
- return true;
3445
- if (isTorsionFree)
3446
- return isTorsionFree(Point, this);
3447
- throw new Error("isTorsionFree() has not been declared for the elliptic curve");
3448
- }
3449
- clearCofactor() {
3450
- const { h: cofactor, clearCofactor } = CURVE2;
3451
- if (cofactor === _1n4)
3452
- return this;
3453
- if (clearCofactor)
3454
- return clearCofactor(Point, this);
3455
- return this.multiplyUnsafe(CURVE2.h);
3456
- }
3457
- toRawBytes(isCompressed = true) {
3458
- this.assertValidity();
3459
- return toBytes2(Point, this, isCompressed);
3460
- }
3461
- toHex(isCompressed = true) {
3462
- return bytesToHex(this.toRawBytes(isCompressed));
3463
- }
3464
- }
3465
- Point.BASE = new Point(CURVE2.Gx, CURVE2.Gy, Fp.ONE);
3466
- Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
3467
- const _bits = CURVE2.nBitLength;
3468
- const wnaf = wNAF(Point, CURVE2.endo ? Math.ceil(_bits / 2) : _bits);
3469
- return {
3470
- CURVE: CURVE2,
3471
- ProjectivePoint: Point,
3472
- normPrivateKeyToScalar,
3473
- weierstrassEquation,
3474
- isWithinCurveOrder
3475
- };
3476
- }
3477
- function validateOpts2(curve2) {
3478
- const opts = validateBasic(curve2);
3479
- validateObject(opts, {
3480
- hash: "hash",
3481
- hmac: "function",
3482
- randomBytes: "function"
3483
- }, {
3484
- bits2int: "function",
3485
- bits2int_modN: "function",
3486
- lowS: "boolean"
3487
- });
3488
- return Object.freeze({ lowS: true, ...opts });
3489
- }
3490
- function weierstrass(curveDef) {
3491
- const CURVE2 = validateOpts2(curveDef);
3492
- const { Fp, n: CURVE_ORDER2 } = CURVE2;
3493
- const compressedLen = Fp.BYTES + 1;
3494
- const uncompressedLen = 2 * Fp.BYTES + 1;
3495
- function isValidFieldElement(num11) {
3496
- return _0n4 < num11 && num11 < Fp.ORDER;
3497
- }
3498
- function modN(a) {
3499
- return mod(a, CURVE_ORDER2);
3500
- }
3501
- function invN(a) {
3502
- return invert(a, CURVE_ORDER2);
3503
- }
3504
- const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
3505
- ...CURVE2,
3506
- toBytes(_c, point, isCompressed) {
3507
- const a = point.toAffine();
3508
- const x = Fp.toBytes(a.x);
3509
- const cat = concatBytes2;
3510
- if (isCompressed) {
3511
- return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
3512
- } else {
3513
- return cat(Uint8Array.from([4]), x, Fp.toBytes(a.y));
3514
- }
3515
- },
3516
- fromBytes(bytes2) {
3517
- const len = bytes2.length;
3518
- const head = bytes2[0];
3519
- const tail = bytes2.subarray(1);
3520
- if (len === compressedLen && (head === 2 || head === 3)) {
3521
- const x = bytesToNumberBE(tail);
3522
- if (!isValidFieldElement(x))
3523
- throw new Error("Point is not on curve");
3524
- const y2 = weierstrassEquation(x);
3525
- let y = Fp.sqrt(y2);
3526
- const isYOdd = (y & _1n4) === _1n4;
3527
- const isHeadOdd = (head & 1) === 1;
3528
- if (isHeadOdd !== isYOdd)
3529
- y = Fp.neg(y);
3530
- return { x, y };
3531
- } else if (len === uncompressedLen && head === 4) {
3532
- const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
3533
- const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
3534
- return { x, y };
3535
- } else {
3536
- throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
3537
- }
3538
- }
3539
- });
3540
- const numToNByteStr = (num11) => bytesToHex(numberToBytesBE(num11, CURVE2.nByteLength));
3541
- function isBiggerThanHalfOrder(number2) {
3542
- const HALF = CURVE_ORDER2 >> _1n4;
3543
- return number2 > HALF;
3544
- }
3545
- function normalizeS(s) {
3546
- return isBiggerThanHalfOrder(s) ? modN(-s) : s;
3547
- }
3548
- const slcNum = (b, from, to) => bytesToNumberBE(b.slice(from, to));
3549
- class Signature2 {
3550
- constructor(r, s, recovery) {
3551
- this.r = r;
3552
- this.s = s;
3553
- this.recovery = recovery;
3554
- this.assertValidity();
3555
- }
3556
- // pair (bytes of r, bytes of s)
3557
- static fromCompact(hex) {
3558
- const l = CURVE2.nByteLength;
3559
- hex = ensureBytes("compactSignature", hex, l * 2);
3560
- return new Signature2(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
3561
- }
3562
- // DER encoded ECDSA signature
3563
- // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
3564
- static fromDER(hex) {
3565
- const { r, s } = DER.toSig(ensureBytes("DER", hex));
3566
- return new Signature2(r, s);
3567
- }
3568
- assertValidity() {
3569
- if (!isWithinCurveOrder(this.r))
3570
- throw new Error("r must be 0 < r < CURVE.n");
3571
- if (!isWithinCurveOrder(this.s))
3572
- throw new Error("s must be 0 < s < CURVE.n");
3573
- }
3574
- addRecoveryBit(recovery) {
3575
- return new Signature2(this.r, this.s, recovery);
3576
- }
3577
- recoverPublicKey(msgHash) {
3578
- const { r, s, recovery: rec } = this;
3579
- const h = bits2int_modN(ensureBytes("msgHash", msgHash));
3580
- if (rec == null || ![0, 1, 2, 3].includes(rec))
3581
- throw new Error("recovery id invalid");
3582
- const radj = rec === 2 || rec === 3 ? r + CURVE2.n : r;
3583
- if (radj >= Fp.ORDER)
3584
- throw new Error("recovery id 2 or 3 invalid");
3585
- const prefix = (rec & 1) === 0 ? "02" : "03";
3586
- const R = Point.fromHex(prefix + numToNByteStr(radj));
3587
- const ir = invN(radj);
3588
- const u1 = modN(-h * ir);
3589
- const u2 = modN(s * ir);
3590
- const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2);
3591
- if (!Q)
3592
- throw new Error("point at infinify");
3593
- Q.assertValidity();
3594
- return Q;
3595
- }
3596
- // Signatures should be low-s, to prevent malleability.
3597
- hasHighS() {
3598
- return isBiggerThanHalfOrder(this.s);
3599
- }
3600
- normalizeS() {
3601
- return this.hasHighS() ? new Signature2(this.r, modN(-this.s), this.recovery) : this;
3602
- }
3603
- // DER-encoded
3604
- toDERRawBytes() {
3605
- return hexToBytes(this.toDERHex());
3606
- }
3607
- toDERHex() {
3608
- return DER.hexFromSig({ r: this.r, s: this.s });
3609
- }
3610
- // padded bytes of r, then padded bytes of s
3611
- toCompactRawBytes() {
3612
- return hexToBytes(this.toCompactHex());
3613
- }
3614
- toCompactHex() {
3615
- return numToNByteStr(this.r) + numToNByteStr(this.s);
3616
- }
3617
- }
3618
- const utils2 = {
3619
- isValidPrivateKey(privateKey) {
3620
- try {
3621
- normPrivateKeyToScalar(privateKey);
3622
- return true;
3623
- } catch (error) {
3624
- return false;
3625
- }
3626
- },
3627
- normPrivateKeyToScalar,
3628
- /**
3629
- * Produces cryptographically secure private key from random of size
3630
- * (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
3631
- */
3632
- randomPrivateKey: () => {
3633
- const length = getMinHashLength(CURVE2.n);
3634
- return mapHashToField(CURVE2.randomBytes(length), CURVE2.n);
3635
- },
3636
- /**
3637
- * Creates precompute table for an arbitrary EC point. Makes point "cached".
3638
- * Allows to massively speed-up `point.multiply(scalar)`.
3639
- * @returns cached point
3640
- * @example
3641
- * const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
3642
- * fast.multiply(privKey); // much faster ECDH now
3643
- */
3644
- precompute(windowSize = 8, point = Point.BASE) {
3645
- point._setWindowSize(windowSize);
3646
- point.multiply(BigInt(3));
3647
- return point;
3648
- }
3649
- };
3650
- function getPublicKey(privateKey, isCompressed = true) {
3651
- return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
3652
- }
3653
- function isProbPub(item) {
3654
- const arr = item instanceof Uint8Array;
3655
- const str = typeof item === "string";
3656
- const len = (arr || str) && item.length;
3657
- if (arr)
3658
- return len === compressedLen || len === uncompressedLen;
3659
- if (str)
3660
- return len === 2 * compressedLen || len === 2 * uncompressedLen;
3661
- if (item instanceof Point)
3662
- return true;
3663
- return false;
3664
- }
3665
- function getSharedSecret(privateA, publicB, isCompressed = true) {
3666
- if (isProbPub(privateA))
3667
- throw new Error("first arg must be private key");
3668
- if (!isProbPub(publicB))
3669
- throw new Error("second arg must be public key");
3670
- const b = Point.fromHex(publicB);
3671
- return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
3672
- }
3673
- const bits2int2 = CURVE2.bits2int || function(bytes2) {
3674
- const num11 = bytesToNumberBE(bytes2);
3675
- const delta = bytes2.length * 8 - CURVE2.nBitLength;
3676
- return delta > 0 ? num11 >> BigInt(delta) : num11;
3677
- };
3678
- const bits2int_modN = CURVE2.bits2int_modN || function(bytes2) {
3679
- return modN(bits2int2(bytes2));
3680
- };
3681
- const ORDER_MASK = bitMask(CURVE2.nBitLength);
3682
- function int2octets(num11) {
3683
- if (typeof num11 !== "bigint")
3684
- throw new Error("bigint expected");
3685
- if (!(_0n4 <= num11 && num11 < ORDER_MASK))
3686
- throw new Error(`bigint expected < 2^${CURVE2.nBitLength}`);
3687
- return numberToBytesBE(num11, CURVE2.nByteLength);
3688
- }
3689
- function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
3690
- if (["recovered", "canonical"].some((k) => k in opts))
3691
- throw new Error("sign() legacy options not supported");
3692
- const { hash: hash6, randomBytes: randomBytes4 } = CURVE2;
3693
- let { lowS, prehash, extraEntropy: ent } = opts;
3694
- if (lowS == null)
3695
- lowS = true;
3696
- msgHash = ensureBytes("msgHash", msgHash);
3697
- if (prehash)
3698
- msgHash = ensureBytes("prehashed msgHash", hash6(msgHash));
3699
- const h1int = bits2int_modN(msgHash);
3700
- const d = normPrivateKeyToScalar(privateKey);
3701
- const seedArgs = [int2octets(d), int2octets(h1int)];
3702
- if (ent != null) {
3703
- const e = ent === true ? randomBytes4(Fp.BYTES) : ent;
3704
- seedArgs.push(ensureBytes("extraEntropy", e));
3705
- }
3706
- const seed = concatBytes2(...seedArgs);
3707
- const m = h1int;
3708
- function k2sig(kBytes) {
3709
- const k = bits2int2(kBytes);
3710
- if (!isWithinCurveOrder(k))
3711
- return;
3712
- const ik = invN(k);
3713
- const q = Point.BASE.multiply(k).toAffine();
3714
- const r = modN(q.x);
3715
- if (r === _0n4)
3716
- return;
3717
- const s = modN(ik * modN(m + r * d));
3718
- if (s === _0n4)
3719
- return;
3720
- let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n4);
3721
- let normS = s;
3722
- if (lowS && isBiggerThanHalfOrder(s)) {
3723
- normS = normalizeS(s);
3724
- recovery ^= 1;
3725
- }
3726
- return new Signature2(r, normS, recovery);
3727
- }
3728
- return { seed, k2sig };
3729
- }
3730
- const defaultSigOpts = { lowS: CURVE2.lowS, prehash: false };
3731
- const defaultVerOpts = { lowS: CURVE2.lowS, prehash: false };
3732
- function sign(msgHash, privKey, opts = defaultSigOpts) {
3733
- const { seed, k2sig } = prepSig(msgHash, privKey, opts);
3734
- const C = CURVE2;
3735
- const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
3736
- return drbg(seed, k2sig);
3737
- }
3738
- Point.BASE._setWindowSize(8);
3739
- function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
3740
- const sg = signature;
3741
- msgHash = ensureBytes("msgHash", msgHash);
3742
- publicKey = ensureBytes("publicKey", publicKey);
3743
- if ("strict" in opts)
3744
- throw new Error("options.strict was renamed to lowS");
3745
- const { lowS, prehash } = opts;
3746
- let _sig = void 0;
3747
- let P;
3748
- try {
3749
- if (typeof sg === "string" || sg instanceof Uint8Array) {
3750
- try {
3751
- _sig = Signature2.fromDER(sg);
3752
- } catch (derError) {
3753
- if (!(derError instanceof DER.Err))
3754
- throw derError;
3755
- _sig = Signature2.fromCompact(sg);
3756
- }
3757
- } else if (typeof sg === "object" && typeof sg.r === "bigint" && typeof sg.s === "bigint") {
3758
- const { r: r2, s: s2 } = sg;
3759
- _sig = new Signature2(r2, s2);
3760
- } else {
3761
- throw new Error("PARSE");
3762
- }
3763
- P = Point.fromHex(publicKey);
3764
- } catch (error) {
3765
- if (error.message === "PARSE")
3766
- throw new Error(`signature must be Signature instance, Uint8Array or hex string`);
3767
- return false;
3768
- }
3769
- if (lowS && _sig.hasHighS())
3770
- return false;
3771
- if (prehash)
3772
- msgHash = CURVE2.hash(msgHash);
3773
- const { r, s } = _sig;
3774
- const h = bits2int_modN(msgHash);
3775
- const is = invN(s);
3776
- const u1 = modN(h * is);
3777
- const u2 = modN(r * is);
3778
- const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
3779
- if (!R)
3780
- return false;
3781
- const v = modN(R.x);
3782
- return v === r;
3783
- }
3784
- return {
3785
- CURVE: CURVE2,
3786
- getPublicKey,
3787
- getSharedSecret,
3788
- sign,
3789
- verify,
3790
- ProjectivePoint: Point,
3791
- Signature: Signature2,
3792
- utils: utils2
3793
- };
3794
- }
3795
-
3796
- // ../node_modules/@noble/hashes/esm/hmac.js
3797
- var HMAC = class extends Hash {
3798
- constructor(hash6, _key) {
3799
- super();
3800
- this.finished = false;
3801
- this.destroyed = false;
3802
- hash(hash6);
3803
- const key = toBytes(_key);
3804
- this.iHash = hash6.create();
3805
- if (typeof this.iHash.update !== "function")
3806
- throw new Error("Expected instance of class which extends utils.Hash");
3807
- this.blockLen = this.iHash.blockLen;
3808
- this.outputLen = this.iHash.outputLen;
3809
- const blockLen = this.blockLen;
3810
- const pad = new Uint8Array(blockLen);
3811
- pad.set(key.length > blockLen ? hash6.create().update(key).digest() : key);
3812
- for (let i = 0; i < pad.length; i++)
3813
- pad[i] ^= 54;
3814
- this.iHash.update(pad);
3815
- this.oHash = hash6.create();
3816
- for (let i = 0; i < pad.length; i++)
3817
- pad[i] ^= 54 ^ 92;
3818
- this.oHash.update(pad);
3819
- pad.fill(0);
3820
- }
3821
- update(buf) {
3822
- exists(this);
3823
- this.iHash.update(buf);
3824
- return this;
3825
- }
3826
- digestInto(out) {
3827
- exists(this);
3828
- bytes(out, this.outputLen);
3829
- this.finished = true;
3830
- this.iHash.digestInto(out);
3831
- this.oHash.update(out);
3832
- this.oHash.digestInto(out);
3833
- this.destroy();
3834
- }
3835
- digest() {
3836
- const out = new Uint8Array(this.oHash.outputLen);
3837
- this.digestInto(out);
3838
- return out;
3839
- }
3840
- _cloneInto(to) {
3841
- to || (to = Object.create(Object.getPrototypeOf(this), {}));
3842
- const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
3843
- to = to;
3844
- to.finished = finished;
3845
- to.destroyed = destroyed;
3846
- to.blockLen = blockLen;
3847
- to.outputLen = outputLen;
3848
- to.oHash = oHash._cloneInto(to.oHash);
3849
- to.iHash = iHash._cloneInto(to.iHash);
3850
- return to;
3851
- }
3852
- destroy() {
3853
- this.destroyed = true;
3854
- this.oHash.destroy();
3855
- this.iHash.destroy();
3856
- }
3857
- };
3858
- var hmac = (hash6, key, message) => new HMAC(hash6, key).update(message).digest();
3859
- hmac.create = (hash6, key) => new HMAC(hash6, key);
3860
-
3861
- // ../node_modules/@noble/curves/esm/_shortw_utils.js
3862
- function getHash(hash6) {
3863
- return {
3864
- hash: hash6,
3865
- hmac: (key, ...msgs) => hmac(hash6, key, concatBytes(...msgs)),
3866
- randomBytes
3867
- };
3868
- }
3869
-
3870
- // ../node_modules/@scure/starknet/lib/esm/index.js
3871
- var CURVE_ORDER = BigInt("3618502788666131213697322783095070105526743751716087489154079457884512865583");
3872
- var MAX_VALUE = BigInt("0x800000000000000000000000000000000000000000000000000000000000000");
3873
- var nBitLength = 252;
3874
- function bits2int(bytes2) {
3875
- while (bytes2[0] === 0)
3876
- bytes2 = bytes2.subarray(1);
3877
- const delta = bytes2.length * 8 - nBitLength;
3878
- const num11 = bytesToNumberBE(bytes2);
3879
- return delta > 0 ? num11 >> BigInt(delta) : num11;
3880
- }
3881
- function hex0xToBytes(hex) {
3882
- if (typeof hex === "string") {
3883
- hex = strip0x(hex);
3884
- if (hex.length & 1)
3885
- hex = "0" + hex;
3886
- }
3887
- return hexToBytes(hex);
3888
- }
3889
- var curve = weierstrass({
3890
- a: BigInt(1),
3891
- b: BigInt("3141592653589793238462643383279502884197169399375105820974944592307816406665"),
3892
- Fp: Field(BigInt("0x800000000000011000000000000000000000000000000000000000000000001")),
3893
- n: CURVE_ORDER,
3894
- nBitLength,
3895
- Gx: BigInt("874739451078007766457464989774322083649278607533249481151382481072868806602"),
3896
- Gy: BigInt("152666792071518830868575557812948353041420400780739481342941381225525861407"),
3897
- h: BigInt(1),
3898
- lowS: false,
3899
- ...getHash(sha256),
3900
- bits2int,
3901
- bits2int_modN: (bytes2) => {
3902
- const hex = bytesToNumberBE(bytes2).toString(16);
3903
- if (hex.length === 63)
3904
- bytes2 = hex0xToBytes(hex + "0");
3905
- return mod(bits2int(bytes2), CURVE_ORDER);
3906
- }
3907
- });
3908
- function ensureBytes2(hex) {
3909
- return ensureBytes("", typeof hex === "string" ? hex0xToBytes(hex) : hex);
3910
- }
3911
- var { CURVE, ProjectivePoint, Signature, utils } = curve;
3912
- function extractX(bytes2) {
3913
- const hex = bytesToHex(bytes2.subarray(1));
3914
- const stripped = hex.replace(/^0+/gm, "");
3915
- return `0x${stripped}`;
3916
- }
3917
- function strip0x(hex) {
3918
- return hex.replace(/^0x/i, "");
3919
- }
3920
- var MASK_31 = 2n ** 31n - 1n;
3921
- var PEDERSEN_POINTS = [
3922
- new ProjectivePoint(2089986280348253421170679821480865132823066470938446095505822317253594081284n, 1713931329540660377023406109199410414810705867260802078187082345529207694986n, 1n),
3923
- new ProjectivePoint(996781205833008774514500082376783249102396023663454813447423147977397232763n, 1668503676786377725805489344771023921079126552019160156920634619255970485781n, 1n),
3924
- new ProjectivePoint(2251563274489750535117886426533222435294046428347329203627021249169616184184n, 1798716007562728905295480679789526322175868328062420237419143593021674992973n, 1n),
3925
- new ProjectivePoint(2138414695194151160943305727036575959195309218611738193261179310511854807447n, 113410276730064486255102093846540133784865286929052426931474106396135072156n, 1n),
3926
- new ProjectivePoint(2379962749567351885752724891227938183011949129833673362440656643086021394946n, 776496453633298175483985398648758586525933812536653089401905292063708816422n, 1n)
3927
- ];
3928
- function pedersenPrecompute(p1, p2) {
3929
- const out = [];
3930
- let p = p1;
3931
- for (let i = 0; i < 248; i++) {
3932
- out.push(p);
3933
- p = p.double();
3934
- }
3935
- p = p2;
3936
- for (let i = 0; i < 4; i++) {
3937
- out.push(p);
3938
- p = p.double();
3939
- }
3940
- return out;
3941
- }
3942
- var PEDERSEN_POINTS1 = pedersenPrecompute(PEDERSEN_POINTS[1], PEDERSEN_POINTS[2]);
3943
- var PEDERSEN_POINTS2 = pedersenPrecompute(PEDERSEN_POINTS[3], PEDERSEN_POINTS[4]);
3944
- function pedersenArg(arg) {
3945
- let value;
3946
- if (typeof arg === "bigint") {
3947
- value = arg;
3948
- } else if (typeof arg === "number") {
3949
- if (!Number.isSafeInteger(arg))
3950
- throw new Error(`Invalid pedersenArg: ${arg}`);
3951
- value = BigInt(arg);
3952
- } else {
3953
- value = bytesToNumberBE(ensureBytes2(arg));
3954
- }
3955
- if (!(0n <= value && value < curve.CURVE.Fp.ORDER))
3956
- throw new Error(`PedersenArg should be 0 <= value < CURVE.P: ${value}`);
3957
- return value;
3958
- }
3959
- function pedersenSingle(point, value, constants3) {
3960
- let x = pedersenArg(value);
3961
- for (let j = 0; j < 252; j++) {
3962
- const pt = constants3[j];
3963
- if (pt.equals(point))
3964
- throw new Error("Same point");
3965
- if ((x & 1n) !== 0n)
3966
- point = point.add(pt);
3967
- x >>= 1n;
3968
- }
3969
- return point;
3970
- }
3971
- function pedersen(x, y) {
3972
- let point = PEDERSEN_POINTS[0];
3973
- point = pedersenSingle(point, x, PEDERSEN_POINTS1);
3974
- point = pedersenSingle(point, y, PEDERSEN_POINTS2);
3975
- return extractX(point.toRawBytes(true));
3976
- }
3977
- var MASK_250 = bitMask(250);
3978
- var Fp251 = Field(BigInt("3618502788666131213697322783095070105623107215331596699973092056135872020481"));
3979
- function poseidonRoundConstant(Fp, name, idx) {
3980
- const val = Fp.fromBytes(sha256(utf8ToBytes(`${name}${idx}`)));
3981
- return Fp.create(val);
3982
- }
3983
- var MDS_SMALL = [
3984
- [3, 1, 1],
3985
- [1, -1, 1],
3986
- [1, 1, -2]
3987
- ].map((i) => i.map(BigInt));
3988
- function poseidonBasic(opts, mds) {
3989
- validateField(opts.Fp);
3990
- if (!Number.isSafeInteger(opts.rate) || !Number.isSafeInteger(opts.capacity))
3991
- throw new Error(`Wrong poseidon opts: ${opts}`);
3992
- const m = opts.rate + opts.capacity;
3993
- const rounds = opts.roundsFull + opts.roundsPartial;
3994
- const roundConstants = [];
3995
- for (let i = 0; i < rounds; i++) {
3996
- const row = [];
3997
- for (let j = 0; j < m; j++)
3998
- row.push(poseidonRoundConstant(opts.Fp, "Hades", m * i + j));
3999
- roundConstants.push(row);
4000
- }
4001
- const res = poseidon({
4002
- ...opts,
4003
- t: m,
4004
- sboxPower: 3,
4005
- reversePartialPowIdx: true,
4006
- mds,
4007
- roundConstants
4008
- });
4009
- res.m = m;
4010
- res.rate = opts.rate;
4011
- res.capacity = opts.capacity;
4012
- return res;
4013
- }
4014
- var poseidonSmall = poseidonBasic({ Fp: Fp251, rate: 2, capacity: 1, roundsFull: 8, roundsPartial: 83 }, MDS_SMALL);
4015
-
4016
- // src/utils/oz-merkle.ts
1984
+ import * as starknet from "@scure/starknet";
4017
1985
  function hash_leaf(leaf) {
4018
1986
  if (leaf.data.length < 1) {
4019
1987
  throw new Error("Invalid leaf data");
@@ -4026,7 +1994,7 @@ function hash_leaf(leaf) {
4026
1994
  return `0x${num2.toHexString(value).replace(/^0x/, "").padStart(64, "0")}`;
4027
1995
  }
4028
1996
  function pedersen_hash(a, b) {
4029
- return BigInt(pedersen(a, b).toString());
1997
+ return BigInt(starknet.pedersen(a, b).toString());
4030
1998
  }
4031
1999
  var StandardMerkleTree = class _StandardMerkleTree extends MerkleTreeImpl {
4032
2000
  constructor(tree, values, leafEncoding) {
@@ -4183,6 +2151,7 @@ function getMainnetConfig(rpcUrl = "https://starknet-mainnet.public.blastapi.io"
4183
2151
  provider: new RpcProvider2({
4184
2152
  nodeUrl: rpcUrl,
4185
2153
  blockIdentifier
2154
+ // specVersion
4186
2155
  }),
4187
2156
  stage: "production",
4188
2157
  network: "mainnet" /* mainnet */
@@ -17938,7 +15907,7 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
17938
15907
  quote.buyAmount.toString(),
17939
15908
  tokenToBuyInfo.decimals
17940
15909
  ).multipliedBy(0.9999);
17941
- const output2 = await this.avnu.getSwapInfo(
15910
+ const output = await this.avnu.getSwapInfo(
17942
15911
  quote,
17943
15912
  this.address.address,
17944
15913
  0,
@@ -17946,9 +15915,9 @@ var EkuboCLVault = class _EkuboCLVault extends BaseStrategy {
17946
15915
  minAmountOut.toWei()
17947
15916
  );
17948
15917
  logger.verbose(
17949
- `${_EkuboCLVault.name}: getSwapInfoToHandleUnused => swap info found: ${JSON.stringify(output2)}`
15918
+ `${_EkuboCLVault.name}: getSwapInfoToHandleUnused => swap info found: ${JSON.stringify(output)}`
17950
15919
  );
17951
- return output2;
15920
+ return output;
17952
15921
  }
17953
15922
  }
17954
15923
  throw new Error("Failed to get swap info");
@@ -20503,7 +18472,7 @@ var SenseiStrategies = [
20503
18472
  ];
20504
18473
 
20505
18474
  // src/strategies/universal-adapters/baseAdapter.ts
20506
- import { hash as hash2, num as num6, shortString } from "starknet";
18475
+ import { hash, num as num6, shortString } from "starknet";
20507
18476
 
20508
18477
  // src/strategies/universal-adapters/adapter-utils.ts
20509
18478
  var SIMPLE_SANITIZER = ContractAddr.from("0x11b59e89b35dfceb3e48ec18c01f8ec569592026c275bcb58e22af9f4dedaac");
@@ -20529,7 +18498,7 @@ var BaseAdapter = class extends CacheClass {
20529
18498
  // sanitizer address
20530
18499
  target.toBigInt(),
20531
18500
  // contract
20532
- toBigInt(hash2.getSelectorFromName(method)),
18501
+ toBigInt(hash.getSelectorFromName(method)),
20533
18502
  // method name
20534
18503
  BigInt(packedArguments.length),
20535
18504
  ...packedArguments
@@ -20539,7 +18508,7 @@ var BaseAdapter = class extends CacheClass {
20539
18508
  };
20540
18509
 
20541
18510
  // src/strategies/universal-adapters/common-adapter.ts
20542
- import { hash as hash3, uint256 as uint2566 } from "starknet";
18511
+ import { hash as hash2, uint256 as uint2566 } from "starknet";
20543
18512
  var CommonAdapter = class extends BaseAdapter {
20544
18513
  constructor(config) {
20545
18514
  super();
@@ -20569,7 +18538,7 @@ var CommonAdapter = class extends BaseAdapter {
20569
18538
  sanitizer: SIMPLE_SANITIZER,
20570
18539
  call: {
20571
18540
  contractAddress: this.config.manager,
20572
- selector: hash3.getSelectorFromName("flash_loan"),
18541
+ selector: hash2.getSelectorFromName("flash_loan"),
20573
18542
  calldata: [
20574
18543
  this.config.manager.toBigInt(),
20575
18544
  // receiver
@@ -20608,7 +18577,7 @@ var CommonAdapter = class extends BaseAdapter {
20608
18577
  sanitizer: SIMPLE_SANITIZER,
20609
18578
  call: {
20610
18579
  contractAddress: token,
20611
- selector: hash3.getSelectorFromName("approve"),
18580
+ selector: hash2.getSelectorFromName("approve"),
20612
18581
  calldata: [
20613
18582
  spender.toBigInt(),
20614
18583
  // spender
@@ -20624,7 +18593,7 @@ var CommonAdapter = class extends BaseAdapter {
20624
18593
  };
20625
18594
 
20626
18595
  // src/strategies/universal-adapters/vesu-adapter.ts
20627
- import { CairoCustomEnum as CairoCustomEnum2, Contract as Contract8, hash as hash4, RpcProvider as RpcProvider4, uint256 as uint2567 } from "starknet";
18596
+ import { CairoCustomEnum as CairoCustomEnum2, Contract as Contract8, hash as hash3, RpcProvider as RpcProvider4, uint256 as uint2567 } from "starknet";
20628
18597
 
20629
18598
  // src/data/vesu-singleton.abi.json
20630
18599
  var vesu_singleton_abi_default = [
@@ -22907,13 +20876,13 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
22907
20876
  toBigInt(positionData.length),
22908
20877
  ...positionData
22909
20878
  ];
22910
- const output2 = this.constructSimpleLeafData({
20879
+ const output = this.constructSimpleLeafData({
22911
20880
  id: this.config.id,
22912
20881
  target: this.VESU_SINGLETON,
22913
20882
  method: "modify_position",
22914
20883
  packedArguments
22915
20884
  });
22916
- return { leaf: output2, callConstructor: this.getModifyPositionCall.bind(this) };
20885
+ return { leaf: output, callConstructor: this.getModifyPositionCall.bind(this) };
22917
20886
  };
22918
20887
  this.getModifyPositionCall = (params) => {
22919
20888
  const _collateral = {
@@ -22950,7 +20919,7 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
22950
20919
  sanitizer: SIMPLE_SANITIZER,
22951
20920
  call: {
22952
20921
  contractAddress: this.VESU_SINGLETON,
22953
- selector: hash4.getSelectorFromName("modify_position"),
20922
+ selector: hash3.getSelectorFromName("modify_position"),
22954
20923
  calldata: [
22955
20924
  ...call.calldata
22956
20925
  ]
@@ -23006,8 +20975,8 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
23006
20975
  if (cacheData) {
23007
20976
  return cacheData;
23008
20977
  }
23009
- const output2 = await this.getVesuSingletonContract(config).call("ltv_config", [this.config.poolId.address, this.config.collateral.address.address, this.config.debt.address.address]);
23010
- this.setCache(CACHE_KEY, Number(output2.max_ltv) / 1e18, 3e5);
20978
+ const output = await this.getVesuSingletonContract(config).call("ltv_config", [this.config.poolId.address, this.config.collateral.address.address, this.config.debt.address.address]);
20979
+ this.setCache(CACHE_KEY, Number(output.max_ltv) / 1e18, 3e5);
23011
20980
  return this.getCache(CACHE_KEY);
23012
20981
  }
23013
20982
  async getPositions(config) {
@@ -23019,7 +20988,7 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
23019
20988
  if (cacheData) {
23020
20989
  return cacheData;
23021
20990
  }
23022
- const output2 = await this.getVesuSingletonContract(config).call("position_unsafe", [
20991
+ const output = await this.getVesuSingletonContract(config).call("position_unsafe", [
23023
20992
  this.config.poolId.address,
23024
20993
  this.config.collateral.address.address,
23025
20994
  this.config.debt.address.address,
@@ -23027,8 +20996,8 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
23027
20996
  ]);
23028
20997
  const token1Price = await this.pricer.getPrice(this.config.collateral.symbol);
23029
20998
  const token2Price = await this.pricer.getPrice(this.config.debt.symbol);
23030
- const collateralAmount = Web3Number.fromWei(output2["1"].toString(), this.config.collateral.decimals);
23031
- const debtAmount = Web3Number.fromWei(output2["2"].toString(), this.config.debt.decimals);
20999
+ const collateralAmount = Web3Number.fromWei(output["1"].toString(), this.config.collateral.decimals);
21000
+ const debtAmount = Web3Number.fromWei(output["2"].toString(), this.config.debt.decimals);
23032
21001
  const value = [{
23033
21002
  amount: collateralAmount,
23034
21003
  token: this.config.collateral,
@@ -23052,14 +21021,14 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
23052
21021
  if (cacheData) {
23053
21022
  return cacheData;
23054
21023
  }
23055
- const output2 = await this.getVesuSingletonContract(config).call("check_collateralization_unsafe", [
21024
+ const output = await this.getVesuSingletonContract(config).call("check_collateralization_unsafe", [
23056
21025
  this.config.poolId.address,
23057
21026
  this.config.collateral.address.address,
23058
21027
  this.config.debt.address.address,
23059
21028
  this.config.vaultAllocator.address
23060
21029
  ]);
23061
- const collateralAmount = Web3Number.fromWei(output2["1"].toString(), 18);
23062
- const debtAmount = Web3Number.fromWei(output2["2"].toString(), 18);
21030
+ const collateralAmount = Web3Number.fromWei(output["1"].toString(), 18);
21031
+ const debtAmount = Web3Number.fromWei(output["2"].toString(), 18);
23063
21032
  const value = [{
23064
21033
  token: this.config.collateral,
23065
21034
  usdValue: collateralAmount.toNumber(),
@@ -23076,8 +21045,8 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
23076
21045
  const collateralizationProm = this.getCollateralization(this.networkConfig);
23077
21046
  const positionsProm = this.getPositions(this.networkConfig);
23078
21047
  const ltvProm = this.getLTVConfig(this.networkConfig);
23079
- const output2 = await Promise.all([collateralizationProm, positionsProm, ltvProm]);
23080
- const [collateralization, positions, ltv] = output2;
21048
+ const output = await Promise.all([collateralizationProm, positionsProm, ltvProm]);
21049
+ const [collateralization, positions, ltv] = output;
23081
21050
  const collateralTokenAmount = positions[0].amount;
23082
21051
  const collateralUSDAmount = collateralization[0].usdValue;
23083
21052
  const collateralPrice = collateralUSDAmount / collateralTokenAmount.toNumber();
@@ -25345,6 +23314,11 @@ var vault_manager_abi_default = [
25345
23314
  ];
25346
23315
 
25347
23316
  // src/strategies/universal-strategy.ts
23317
+ var AUMTypes = /* @__PURE__ */ ((AUMTypes2) => {
23318
+ AUMTypes2["FINALISED"] = "finalised";
23319
+ AUMTypes2["DEFISPRING"] = "defispring";
23320
+ return AUMTypes2;
23321
+ })(AUMTypes || {});
25348
23322
  var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25349
23323
  constructor(config, pricer, metadata) {
25350
23324
  super(config);
@@ -25429,6 +23403,19 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25429
23403
  ]);
25430
23404
  return [call1, call2];
25431
23405
  }
23406
+ async withdrawCall(amountInfo, receiver, owner) {
23407
+ assert(
23408
+ amountInfo.tokenInfo.address.eq(this.asset().address),
23409
+ "Withdraw token mismatch"
23410
+ );
23411
+ const shares = await this.contract.call("convert_to_shares", [uint2568.bnToUint256(amountInfo.amount.toWei())]);
23412
+ const call = this.contract.populate("request_redeem", [
23413
+ uint2568.bnToUint256(shares.toString()),
23414
+ receiver.address,
23415
+ owner.address
23416
+ ]);
23417
+ return [call];
23418
+ }
25432
23419
  /**
25433
23420
  * Calculates the Total Value Locked (TVL) for a specific user.
25434
23421
  * @param user - Address of the user
@@ -25475,14 +23462,24 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25475
23462
  const collateral2APY = Number(collateralAsset2.supplyApy.value) / 1e18;
25476
23463
  const debt2APY = Number(debtAsset2.borrowApr.value) / 1e18;
25477
23464
  const positions = await this.getVaultPositions();
23465
+ logger.verbose(`${this.metadata.name}::netAPY: positions: ${JSON.stringify(positions)}`);
23466
+ if (positions.every((p) => p.amount.isZero())) {
23467
+ return { net: 0, splits: [{
23468
+ apy: 0,
23469
+ id: "base"
23470
+ }, {
23471
+ apy: 0,
23472
+ id: "defispring"
23473
+ }] };
23474
+ }
25478
23475
  const weights = positions.map((p, index) => p.usdValue * (index % 2 == 0 ? 1 : -1));
25479
23476
  const baseAPYs = [collateral1APY, debt1APY, collateral2APY, debt2APY];
25480
23477
  assert(positions.length == baseAPYs.length, "Positions and APYs length mismatch");
25481
23478
  const rewardAPYs = [Number(collateralAsset1.defiSpringSupplyApr.value) / 1e18, 0, Number(collateralAsset2.defiSpringSupplyApr.value) / 1e18, 0];
25482
23479
  const baseAPY = this.computeAPY(baseAPYs, weights);
25483
23480
  const rewardAPY = this.computeAPY(rewardAPYs, weights);
25484
- const apys = [...baseAPYs, ...rewardAPYs];
25485
23481
  const netAPY = baseAPY + rewardAPY;
23482
+ logger.verbose(`${this.metadata.name}::netAPY: net: ${netAPY}, baseAPY: ${baseAPY}, rewardAPY: ${rewardAPY}`);
25486
23483
  return { net: netAPY, splits: [{
25487
23484
  apy: baseAPY,
25488
23485
  id: "base"
@@ -25517,6 +23514,16 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25517
23514
  usdValue
25518
23515
  };
25519
23516
  }
23517
+ async getUnusedBalance() {
23518
+ const balance = await new ERC20(this.config).balanceOf(this.asset().address, this.metadata.additionalInfo.vaultAllocator, this.asset().decimals);
23519
+ const price = await this.pricer.getPrice(this.metadata.depositTokens[0].symbol);
23520
+ const usdValue = Number(balance.toFixed(6)) * price.price;
23521
+ return {
23522
+ tokenInfo: this.asset(),
23523
+ amount: balance,
23524
+ usdValue
23525
+ };
23526
+ }
25520
23527
  async getAUM() {
25521
23528
  const currentAUM = await this.contract.call("aum", []);
25522
23529
  const lastReportTime = await this.contract.call("last_report_timestamp", []);
@@ -25524,14 +23531,32 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25524
23531
  const [vesuAdapter1, vesuAdapter2] = this.getVesuAdapters();
25525
23532
  const leg1AUM = await vesuAdapter1.getPositions(this.config);
25526
23533
  const leg2AUM = await vesuAdapter2.getPositions(this.config);
25527
- const aumToken = leg1AUM[0].amount.plus(leg2AUM[0].usdValue / token1Price.price).minus(leg1AUM[1].usdValue / token1Price.price).minus(leg2AUM[1].amount);
23534
+ const balance = await this.getUnusedBalance();
23535
+ logger.verbose(`${this.getTag()} unused balance: ${balance.amount.toNumber()}`);
23536
+ const vesuAum = leg1AUM[0].amount.plus(leg2AUM[0].usdValue / token1Price.price).minus(leg1AUM[1].usdValue / token1Price.price).minus(leg2AUM[1].amount);
23537
+ const zeroAmt = Web3Number.fromWei("0", this.asset().decimals);
23538
+ const net = {
23539
+ tokenInfo: this.asset(),
23540
+ amount: zeroAmt,
23541
+ usdValue: 0
23542
+ };
23543
+ const prevAum = Web3Number.fromWei(currentAUM.toString(), this.asset().decimals);
23544
+ if (vesuAum.isZero()) {
23545
+ return { net, splits: [{
23546
+ aum: zeroAmt,
23547
+ id: "finalised" /* FINALISED */
23548
+ }, {
23549
+ aum: zeroAmt,
23550
+ id: "defispring" /* DEFISPRING */
23551
+ }], prevAum };
23552
+ }
23553
+ const aumToken = vesuAum.plus(balance.amount);
25528
23554
  logger.verbose(`${this.getTag()} Actual AUM: ${aumToken}`);
25529
23555
  const netAPY = await this.netAPY();
25530
23556
  const defispringAPY = netAPY.splits.find((s) => s.id === "defispring")?.apy || 0;
25531
23557
  if (!defispringAPY) throw new Error("DefiSpring APY not found");
25532
23558
  const timeDiff = Math.round(Date.now() / 1e3) - Number(lastReportTime);
25533
23559
  const growthRate = timeDiff * defispringAPY / (365 * 24 * 60 * 60);
25534
- const prevAum = Web3Number.fromWei(currentAUM.toString(), this.asset().decimals);
25535
23560
  const rewardAssets = prevAum.multipliedBy(growthRate);
25536
23561
  logger.verbose(`${this.getTag()} DefiSpring AUM time difference: ${timeDiff}`);
25537
23562
  logger.verbose(`${this.getTag()} Current AUM: ${currentAUM}`);
@@ -25539,16 +23564,13 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25539
23564
  logger.verbose(`${this.getTag()} rewards AUM: ${rewardAssets}`);
25540
23565
  const newAUM = aumToken.plus(rewardAssets);
25541
23566
  logger.verbose(`${this.getTag()} New AUM: ${newAUM}`);
25542
- const net = {
25543
- tokenInfo: this.asset(),
25544
- amount: newAUM,
25545
- usdValue: newAUM.multipliedBy(token1Price.price).toNumber()
25546
- };
23567
+ net.amount = newAUM;
23568
+ net.usdValue = newAUM.multipliedBy(token1Price.price).toNumber();
25547
23569
  const splits = [{
25548
- id: "finalised",
23570
+ id: "finalised" /* FINALISED */,
25549
23571
  aum: aumToken
25550
23572
  }, {
25551
- id: "defispring",
23573
+ id: "defispring" /* DEFISPRING */,
25552
23574
  aum: rewardAssets
25553
23575
  }];
25554
23576
  return { net, splits, prevAum };
@@ -25599,19 +23621,19 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
25599
23621
  debtAmount: params.debtAmount,
25600
23622
  isBorrow: params.isDeposit
25601
23623
  }));
25602
- const output2 = [{
23624
+ const output = [{
25603
23625
  proofs: manage5Info.proofs,
25604
23626
  manageCall: manageCall5,
25605
23627
  step: STEP2_ID
25606
23628
  }];
25607
23629
  if (approveAmount.gt(0)) {
25608
- output2.unshift({
23630
+ output.unshift({
25609
23631
  proofs: manage4Info.proofs,
25610
23632
  manageCall: manageCall4,
25611
23633
  step: STEP1_ID
25612
23634
  });
25613
23635
  }
25614
- return output2;
23636
+ return output;
25615
23637
  }
25616
23638
  getTag() {
25617
23639
  return `${_UniversalStrategy.name}:${this.metadata.name}`;
@@ -25846,6 +23868,7 @@ var usdcVaultSettings = {
25846
23868
  manager: ContractAddr.from("0xf41a2b1f498a7f9629db0b8519259e66e964260a23d20003f3e42bb1997a07"),
25847
23869
  vaultAllocator: ContractAddr.from("0x228cca1005d3f2b55cbaba27cb291dacf1b9a92d1d6b1638195fbd3d0c1e3ba"),
25848
23870
  redeemRequestNFT: ContractAddr.from("0x906d03590010868cbf7590ad47043959d7af8e782089a605d9b22567b64fda"),
23871
+ aumOracle: ContractAddr.from("0x6faf45ed185dec13ef723c9ead4266cab98d06f2cb237e331b1fa5c2aa79afe"),
25849
23872
  leafAdapters: [],
25850
23873
  adapters: [],
25851
23874
  targetHealthFactor: 1.3,
@@ -25855,6 +23878,37 @@ var wbtcVaultSettings = {
25855
23878
  manager: ContractAddr.from("0xef8a664ffcfe46a6af550766d27c28937bf1b77fb4ab54d8553e92bca5ba34"),
25856
23879
  vaultAllocator: ContractAddr.from("0x1e01c25f0d9494570226ad28a7fa856c0640505e809c366a9fab4903320e735"),
25857
23880
  redeemRequestNFT: ContractAddr.from("0x4fec59a12f8424281c1e65a80b5de51b4e754625c60cddfcd00d46941ec37b2"),
23881
+ aumOracle: ContractAddr.from("0x2edf4edbed3f839e7f07dcd913e92299898ff4cf0ba532f8c572c66c5b331b2"),
23882
+ leafAdapters: [],
23883
+ adapters: [],
23884
+ targetHealthFactor: 1.3,
23885
+ minHealthFactor: 1.25
23886
+ };
23887
+ var ethVaultSettings = {
23888
+ manager: ContractAddr.from("0x494888b37206616bd09d759dcda61e5118470b9aa7f58fb84f21c778a7b8f97"),
23889
+ vaultAllocator: ContractAddr.from("0x4acc0ad6bea58cb578d60ff7c31f06f44369a7a9a7bbfffe4701f143e427bd"),
23890
+ redeemRequestNFT: ContractAddr.from("0x2e6cd71e5060a254d4db00655e420db7bf89da7755bb0d5f922e2f00c76ac49"),
23891
+ aumOracle: ContractAddr.from("0x4b747f2e75c057bed9aa2ce46fbdc2159dc684c15bd32d4f95983a6ecf39a05"),
23892
+ leafAdapters: [],
23893
+ adapters: [],
23894
+ targetHealthFactor: 1.3,
23895
+ minHealthFactor: 1.25
23896
+ };
23897
+ var strkVaultSettings = {
23898
+ manager: ContractAddr.from("0xcc6a5153ca56293405506eb20826a379d982cd738008ef7e808454d318fb81"),
23899
+ vaultAllocator: ContractAddr.from("0xf29d2f82e896c0ed74c9eff220af34ac148e8b99846d1ace9fbb02c9191d01"),
23900
+ redeemRequestNFT: ContractAddr.from("0x46902423bd632c428376b84fcee9cac5dbe016214e93a8103bcbde6e1de656b"),
23901
+ aumOracle: ContractAddr.from("0x6d7dbfad4bb51715da211468389a623da00c0625f8f6efbea822ee5ac5231f4"),
23902
+ leafAdapters: [],
23903
+ adapters: [],
23904
+ targetHealthFactor: 1.3,
23905
+ minHealthFactor: 1.25
23906
+ };
23907
+ var usdtVaultSettings = {
23908
+ manager: ContractAddr.from("0x39bb9843503799b552b7ed84b31c06e4ff10c0537edcddfbf01fe944b864029"),
23909
+ vaultAllocator: ContractAddr.from("0x56437d18c43727ac971f6c7086031cad7d9d6ccb340f4f3785a74cc791c931a"),
23910
+ redeemRequestNFT: ContractAddr.from("0x5af0c2a657eaa8e23ed78e855dac0c51e4f69e2cf91a18c472041a1f75bb41f"),
23911
+ aumOracle: ContractAddr.from("0x7018f8040c8066a4ab929e6760ae52dd43b6a3a289172f514750a61fcc565cc"),
25858
23912
  leafAdapters: [],
25859
23913
  adapters: [],
25860
23914
  targetHealthFactor: 1.3,
@@ -25898,6 +23952,63 @@ var UniversalStrategies = [
25898
23952
  contractDetails: [],
25899
23953
  faqs: [],
25900
23954
  investmentSteps: []
23955
+ },
23956
+ {
23957
+ name: "ETH Evergreen",
23958
+ description: "A universal strategy for managing ETH assets",
23959
+ address: ContractAddr.from("0x446c22d4d3f5cb52b4950ba832ba1df99464c6673a37c092b1d9622650dbd8"),
23960
+ launchBlock: 0,
23961
+ type: "ERC4626",
23962
+ depositTokens: [Global.getDefaultTokens().find((token) => token.symbol === "ETH")],
23963
+ additionalInfo: getLooperSettings("ETH", "WBTC", ethVaultSettings, VesuPools.Genesis, VesuPools.Genesis),
23964
+ risk: {
23965
+ riskFactor: _riskFactor4,
23966
+ netRisk: _riskFactor4.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor4.reduce((acc, curr) => acc + curr.weight, 0),
23967
+ notARisks: getNoRiskTags(_riskFactor4)
23968
+ },
23969
+ protocols: [Protocols.VESU],
23970
+ maxTVL: Web3Number.fromWei(0, 18),
23971
+ contractDetails: [],
23972
+ faqs: [],
23973
+ investmentSteps: []
23974
+ },
23975
+ {
23976
+ name: "STRK Evergreen",
23977
+ description: "A universal strategy for managing STRK assets",
23978
+ address: ContractAddr.from("0x55d012f57e58c96e0a5c7ebbe55853989d01e6538b15a95e7178aca4af05c21"),
23979
+ launchBlock: 0,
23980
+ type: "ERC4626",
23981
+ depositTokens: [Global.getDefaultTokens().find((token) => token.symbol === "STRK")],
23982
+ additionalInfo: getLooperSettings("STRK", "ETH", strkVaultSettings, VesuPools.Genesis, VesuPools.Genesis),
23983
+ risk: {
23984
+ riskFactor: _riskFactor4,
23985
+ netRisk: _riskFactor4.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor4.reduce((acc, curr) => acc + curr.weight, 0),
23986
+ notARisks: getNoRiskTags(_riskFactor4)
23987
+ },
23988
+ protocols: [Protocols.VESU],
23989
+ maxTVL: Web3Number.fromWei(0, 18),
23990
+ contractDetails: [],
23991
+ faqs: [],
23992
+ investmentSteps: []
23993
+ },
23994
+ {
23995
+ name: "USDT Evergreen",
23996
+ description: "A universal strategy for managing USDT assets",
23997
+ address: ContractAddr.from("0x1c4933d1880c6778585e597154eaca7b428579d72f3aae425ad2e4d26c6bb3"),
23998
+ launchBlock: 0,
23999
+ type: "ERC4626",
24000
+ depositTokens: [Global.getDefaultTokens().find((token) => token.symbol === "USDT")],
24001
+ additionalInfo: getLooperSettings("USDT", "ETH", usdtVaultSettings, VesuPools.Genesis, VesuPools.Genesis),
24002
+ risk: {
24003
+ riskFactor: _riskFactor4,
24004
+ netRisk: _riskFactor4.reduce((acc, curr) => acc + curr.value * curr.weight, 0) / _riskFactor4.reduce((acc, curr) => acc + curr.weight, 0),
24005
+ notARisks: getNoRiskTags(_riskFactor4)
24006
+ },
24007
+ protocols: [Protocols.VESU],
24008
+ maxTVL: Web3Number.fromWei(0, 6),
24009
+ contractDetails: [],
24010
+ faqs: [],
24011
+ investmentSteps: []
25901
24012
  }
25902
24013
  ];
25903
24014
 
@@ -26004,16 +24115,16 @@ var PricerRedis = class extends Pricer {
26004
24115
 
26005
24116
  // src/node/deployer.ts
26006
24117
  import assert2 from "assert";
26007
- import { TransactionExecutionStatus, constants as constants2, extractContractHashes, json, num as num10, transaction } from "starknet";
24118
+ import { TransactionExecutionStatus, constants as constants3, extractContractHashes, json, num as num10, transaction } from "starknet";
26008
24119
  import { readFileSync as readFileSync2, existsSync, writeFileSync as writeFileSync2 } from "fs";
26009
24120
 
26010
24121
  // src/utils/store.ts
26011
24122
  import fs, { readFileSync, writeFileSync } from "fs";
26012
- import { Account as Account3, constants } from "starknet";
26013
- import * as crypto3 from "crypto";
24123
+ import { Account as Account3, constants as constants2 } from "starknet";
24124
+ import * as crypto2 from "crypto";
26014
24125
 
26015
24126
  // src/utils/encrypt.ts
26016
- import * as crypto2 from "crypto";
24127
+ import * as crypto from "crypto";
26017
24128
  var PasswordJsonCryptoUtil = class {
26018
24129
  constructor() {
26019
24130
  this.algorithm = "aes-256-gcm";
@@ -26029,14 +24140,14 @@ var PasswordJsonCryptoUtil = class {
26029
24140
  }
26030
24141
  // Number of iterations for PBKDF2
26031
24142
  deriveKey(password, salt) {
26032
- return crypto2.pbkdf2Sync(password, salt, this.pbkdf2Iterations, this.keyLength, "sha256");
24143
+ return crypto.pbkdf2Sync(password, salt, this.pbkdf2Iterations, this.keyLength, "sha256");
26033
24144
  }
26034
24145
  encrypt(data, password) {
26035
24146
  const jsonString = JSON.stringify(data);
26036
- const salt = crypto2.randomBytes(this.saltLength);
26037
- const iv = crypto2.randomBytes(this.ivLength);
24147
+ const salt = crypto.randomBytes(this.saltLength);
24148
+ const iv = crypto.randomBytes(this.ivLength);
26038
24149
  const key = this.deriveKey(password, salt);
26039
- const cipher = crypto2.createCipheriv(this.algorithm, key, iv, { authTagLength: this.tagLength });
24150
+ const cipher = crypto.createCipheriv(this.algorithm, key, iv, { authTagLength: this.tagLength });
26040
24151
  let encrypted = cipher.update(jsonString, "utf8", "hex");
26041
24152
  encrypted += cipher.final("hex");
26042
24153
  const tag = cipher.getAuthTag();
@@ -26049,7 +24160,7 @@ var PasswordJsonCryptoUtil = class {
26049
24160
  const tag = data.subarray(this.saltLength + this.ivLength, this.saltLength + this.ivLength + this.tagLength);
26050
24161
  const encrypted = data.subarray(this.saltLength + this.ivLength + this.tagLength);
26051
24162
  const key = this.deriveKey(password, salt);
26052
- const decipher = crypto2.createDecipheriv(this.algorithm, key, iv, { authTagLength: this.tagLength });
24163
+ const decipher = crypto.createDecipheriv(this.algorithm, key, iv, { authTagLength: this.tagLength });
26053
24164
  decipher.setAuthTag(tag);
26054
24165
  try {
26055
24166
  let decrypted = decipher.update(encrypted.toString("hex"), "hex", "utf8");
@@ -26070,7 +24181,7 @@ function getDefaultStoreConfig(network) {
26070
24181
  SECRET_FILE_FOLDER: `${process.env.HOME}/.starknet-store`,
26071
24182
  NETWORK: network,
26072
24183
  ACCOUNTS_FILE_NAME: "accounts.json",
26073
- PASSWORD: crypto3.randomBytes(16).toString("hex")
24184
+ PASSWORD: crypto2.randomBytes(16).toString("hex")
26074
24185
  };
26075
24186
  }
26076
24187
  var Store = class _Store {
@@ -26094,7 +24205,7 @@ var Store = class _Store {
26094
24205
  logger.warn(`This not stored anywhere, please you backup this password for future use`);
26095
24206
  logger.warn(`\u26A0\uFE0F=========================================\u26A0\uFE0F`);
26096
24207
  }
26097
- getAccount(accountKey, txVersion = constants.TRANSACTION_VERSION.V2) {
24208
+ getAccount(accountKey, txVersion = constants2.TRANSACTION_VERSION.V2) {
26098
24209
  const accounts = this.loadAccounts();
26099
24210
  logger.verbose(`nAccounts loaded for network: ${Object.keys(accounts).length}`);
26100
24211
  const data = accounts[accountKey];
@@ -26188,7 +24299,7 @@ function getAccount(accountKey, config, password = process.env.ACCOUNT_SECURE_PA
26188
24299
  ...storeConfig,
26189
24300
  PASSWORD: password
26190
24301
  });
26191
- return store.getAccount(accountKey);
24302
+ return store.getAccount(accountKey, "0x3");
26192
24303
  }
26193
24304
  async function myDeclare(contract_name, package_name = "strkfarm", config, acc) {
26194
24305
  const provider2 = config.provider;
@@ -26238,7 +24349,7 @@ async function deployContract(contract_name, classHash, constructorData, config,
26238
24349
  classHash,
26239
24350
  constructorCalldata: constructorData
26240
24351
  });
26241
- console.log("Deploy fee", contract_name, Number(fee.suggestedMaxFee) / 10 ** 18, "ETH");
24352
+ console.log("Deploy fee", contract_name, Number(fee.overall_fee) / 10 ** 18, "ETH");
26242
24353
  const tx = await acc.deployContract({
26243
24354
  classHash,
26244
24355
  constructorCalldata: constructorData
@@ -26280,7 +24391,7 @@ async function prepareMultiDeployContracts(contracts, config, acc) {
26280
24391
  }
26281
24392
  async function executeDeployCalls(contractsInfo, acc, provider2) {
26282
24393
  for (let contractInfo of contractsInfo) {
26283
- assert2(num10.toHexString(contractInfo.call.contractAddress) == num10.toHexString(constants2.UDC.ADDRESS), "Must be pointed at UDC address");
24394
+ assert2(num10.toHexString(contractInfo.call.contractAddress) == num10.toHexString(constants3.UDC.ADDRESS), "Must be pointed at UDC address");
26284
24395
  }
26285
24396
  const allCalls = contractsInfo.map((info) => info.call);
26286
24397
  await executeTransactions(allCalls, acc, provider2, `Deploying contracts: ${contractsInfo.map((info) => info.contract_name).join(", ")}`);
@@ -26319,6 +24430,7 @@ var Deployer = {
26319
24430
  };
26320
24431
  var deployer_default = Deployer;
26321
24432
  export {
24433
+ AUMTypes,
26322
24434
  AutoCompounderSTRK,
26323
24435
  AvnuWrapper,
26324
24436
  BaseAdapter,
@@ -26371,26 +24483,3 @@ export {
26371
24483
  highlightTextWithLinks,
26372
24484
  logger
26373
24485
  };
26374
- /*! Bundled license information:
26375
-
26376
- @noble/hashes/esm/utils.js:
26377
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26378
-
26379
- @noble/curves/esm/abstract/utils.js:
26380
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26381
-
26382
- @noble/curves/esm/abstract/modular.js:
26383
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26384
-
26385
- @noble/curves/esm/abstract/poseidon.js:
26386
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26387
-
26388
- @noble/curves/esm/abstract/curve.js:
26389
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26390
-
26391
- @noble/curves/esm/abstract/weierstrass.js:
26392
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26393
-
26394
- @noble/curves/esm/_shortw_utils.js:
26395
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
26396
- */