@aboutcircles/sdk 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +338 -335
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12844,9 +12844,9 @@ function l82($3, J2 = 24) {
|
|
|
12844
12844
|
for (let K3 = 0;K3 < 10; K3++)
|
|
12845
12845
|
Q4[K3] = $3[K3] ^ $3[K3 + 10] ^ $3[K3 + 20] ^ $3[K3 + 30] ^ $3[K3 + 40];
|
|
12846
12846
|
for (let K3 = 0;K3 < 10; K3 += 2) {
|
|
12847
|
-
let X4 = (K3 + 8) % 10, q3 = (K3 + 2) % 10, M2 = Q4[q3], j4 = Q4[q3 + 1], N = gJ3(M2, j4, 1) ^ Q4[X4],
|
|
12848
|
-
for (let
|
|
12849
|
-
$3[K3 +
|
|
12847
|
+
let X4 = (K3 + 8) % 10, q3 = (K3 + 2) % 10, M2 = Q4[q3], j4 = Q4[q3 + 1], N = gJ3(M2, j4, 1) ^ Q4[X4], z2 = vJ3(M2, j4, 1) ^ Q4[X4 + 1];
|
|
12848
|
+
for (let D3 = 0;D3 < 50; D3 += 10)
|
|
12849
|
+
$3[K3 + D3] ^= N, $3[K3 + D3 + 1] ^= z2;
|
|
12850
12850
|
}
|
|
12851
12851
|
let Y2 = $3[2], Z3 = $3[3];
|
|
12852
12852
|
for (let K3 = 0;K3 < 24; K3++) {
|
|
@@ -13074,8 +13074,8 @@ function a82($3, J2, Q4, G2) {
|
|
|
13074
13074
|
if ($3.endsWith("[]")) {
|
|
13075
13075
|
let X4 = parseInt(Z3, 16) * 2, q3 = parseInt(J2.slice(X4, X4 + u4), 16), M2 = [], j4 = X4 + u4;
|
|
13076
13076
|
for (let N = 0;N < q3; N++) {
|
|
13077
|
-
let
|
|
13078
|
-
M2.push(
|
|
13077
|
+
let z2 = e03(Y2, J2, j4, G2);
|
|
13078
|
+
M2.push(z2.value), j4 += z2.consumed;
|
|
13079
13079
|
}
|
|
13080
13080
|
return { value: M2, consumed: u4 };
|
|
13081
13081
|
}
|
|
@@ -13125,7 +13125,7 @@ function r82($3, J2, Q4) {
|
|
|
13125
13125
|
throw Error(`Unsupported type: ${$3}`);
|
|
13126
13126
|
}
|
|
13127
13127
|
function H$2($3) {
|
|
13128
|
-
let { abi: J2, functionName: Q4, args: G2 = [] } = $3, Y2 = J2.find((
|
|
13128
|
+
let { abi: J2, functionName: Q4, args: G2 = [] } = $3, Y2 = J2.find((D3) => D3.type === "function" && D3.name === Q4);
|
|
13129
13129
|
if (!Y2)
|
|
13130
13130
|
throw Error(`Function "${Q4}" not found in ABI`);
|
|
13131
13131
|
let Z3 = i82(Y2), K3 = Y2.inputs || [];
|
|
@@ -13134,21 +13134,21 @@ function H$2($3) {
|
|
|
13134
13134
|
if (G2.length !== K3.length)
|
|
13135
13135
|
throw Error(`Expected ${K3.length} arguments, got ${G2.length}`);
|
|
13136
13136
|
let X4 = [], q3 = [], M2 = [];
|
|
13137
|
-
for (let
|
|
13138
|
-
let
|
|
13139
|
-
if (M2.push(
|
|
13140
|
-
X4.push(""), q3.push(C03(
|
|
13137
|
+
for (let D3 = 0;D3 < K3.length; D3++) {
|
|
13138
|
+
let H4 = K3[D3], V2 = H4.components, P = u03(H4.type, V2);
|
|
13139
|
+
if (M2.push(P), P)
|
|
13140
|
+
X4.push(""), q3.push(C03(H4.type, G2[D3], V2));
|
|
13141
13141
|
else
|
|
13142
|
-
X4.push(C03(
|
|
13142
|
+
X4.push(C03(H4.type, G2[D3], V2));
|
|
13143
13143
|
}
|
|
13144
13144
|
if (q3.length === 0)
|
|
13145
13145
|
return Z3 + X4.join("");
|
|
13146
|
-
let j4 = X4.reduce((
|
|
13147
|
-
for (let
|
|
13148
|
-
if (M2[
|
|
13149
|
-
N += K02(j4), j4 += q3[
|
|
13146
|
+
let j4 = X4.reduce((D3, H4, V2) => D3 + (M2[V2] ? B$2 : H4.length / 2), 0), N = "", z2 = 0;
|
|
13147
|
+
for (let D3 = 0;D3 < K3.length; D3++)
|
|
13148
|
+
if (M2[D3])
|
|
13149
|
+
N += K02(j4), j4 += q3[z2].length / 2, z2++;
|
|
13150
13150
|
else
|
|
13151
|
-
N += X4[
|
|
13151
|
+
N += X4[D3];
|
|
13152
13152
|
return Z3 + N + q3.join("");
|
|
13153
13153
|
}
|
|
13154
13154
|
function m$2($3) {
|
|
@@ -13241,7 +13241,7 @@ var S$2 = "0x0000000000000000000000000000000000000000";
|
|
|
13241
13241
|
var X03 = BigInt(96) * BigInt(1000000000000000000);
|
|
13242
13242
|
var $$ = BigInt("9999999999999999999999999999999999999");
|
|
13243
13243
|
var u$2 = "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67";
|
|
13244
|
-
var c$2 = "
|
|
13244
|
+
var c$2 = "0x89867a67674bd4bf33165a653cde826b696ab7d050166b71066dfa0b9b6f90f4";
|
|
13245
13245
|
var l$ = "0xe298282cefe913ab5d282047161268a8222e4bd4ed106300c547894bbefd31ee";
|
|
13246
13246
|
|
|
13247
13247
|
class U03 {
|
|
@@ -13687,8 +13687,8 @@ class Z$ {
|
|
|
13687
13687
|
for (let j4 of q3) {
|
|
13688
13688
|
if (!j4?.isHuman)
|
|
13689
13689
|
continue;
|
|
13690
|
-
let
|
|
13691
|
-
if (
|
|
13690
|
+
let z2 = (await this.client.call("circles_getTokenBalances", [j4.avatar])).find((D3) => L3(D3.tokenAddress) === L3(j4.avatar));
|
|
13691
|
+
if (z2 && z2.circles >= 96)
|
|
13692
13692
|
M2.push(j4);
|
|
13693
13693
|
}
|
|
13694
13694
|
return f2(M2);
|
|
@@ -14100,13 +14100,13 @@ class aJ extends n$2 {
|
|
|
14100
14100
|
for (let j4 = 0;j4 < 16; j4++, J2 += 4)
|
|
14101
14101
|
B0[j4] = $3.getUint32(J2, false);
|
|
14102
14102
|
for (let j4 = 16;j4 < 64; j4++) {
|
|
14103
|
-
let N = B0[j4 - 15],
|
|
14104
|
-
B0[j4] =
|
|
14103
|
+
let N = B0[j4 - 15], z2 = B0[j4 - 2], D3 = G03(N, 7) ^ G03(N, 18) ^ N >>> 3, H4 = G03(z2, 17) ^ G03(z2, 19) ^ z2 >>> 10;
|
|
14104
|
+
B0[j4] = H4 + B0[j4 - 7] + D3 + B0[j4 - 16] | 0;
|
|
14105
14105
|
}
|
|
14106
14106
|
let { A: Q4, B: G2, C: Y2, D: Z3, E: K3, F: X4, G: q3, H: M2 } = this;
|
|
14107
14107
|
for (let j4 = 0;j4 < 64; j4++) {
|
|
14108
|
-
let N = G03(K3, 6) ^ G03(K3, 11) ^ G03(K3, 25),
|
|
14109
|
-
M2 = q3, q3 = X4, X4 = K3, K3 = Z3 +
|
|
14108
|
+
let N = G03(K3, 6) ^ G03(K3, 11) ^ G03(K3, 25), z2 = M2 + N + oJ2(K3, X4, q3) + YQ2[j4] + B0[j4] | 0, H4 = (G03(Q4, 2) ^ G03(Q4, 13) ^ G03(Q4, 22)) + tJ2(Q4, G2, Y2) | 0;
|
|
14109
|
+
M2 = q3, q3 = X4, X4 = K3, K3 = Z3 + z2 | 0, Z3 = Y2, Y2 = G2, G2 = Q4, Q4 = z2 + H4 | 0;
|
|
14110
14110
|
}
|
|
14111
14111
|
Q4 = Q4 + this.A | 0, G2 = G2 + this.B | 0, Y2 = Y2 + this.C | 0, Z3 = Z3 + this.D | 0, K3 = K3 + this.E | 0, X4 = X4 + this.F | 0, q3 = q3 + this.G | 0, M2 = M2 + this.H | 0, this.set(Q4, G2, Y2, Z3, K3, X4, q3, M2);
|
|
14112
14112
|
}
|
|
@@ -14297,20 +14297,20 @@ function G82($3, J2, Q4) {
|
|
|
14297
14297
|
}, M2 = () => {
|
|
14298
14298
|
if (Z3++ >= 1000)
|
|
14299
14299
|
throw Error("drbg: tried 1000 values");
|
|
14300
|
-
let N = 0,
|
|
14300
|
+
let N = 0, z2 = [];
|
|
14301
14301
|
while (N < J2) {
|
|
14302
14302
|
G2 = X4();
|
|
14303
|
-
let
|
|
14304
|
-
|
|
14303
|
+
let D3 = G2.slice();
|
|
14304
|
+
z2.push(D3), N += G2.length;
|
|
14305
14305
|
}
|
|
14306
|
-
return M$(...
|
|
14306
|
+
return M$(...z2);
|
|
14307
14307
|
};
|
|
14308
|
-
return (N,
|
|
14308
|
+
return (N, z2) => {
|
|
14309
14309
|
K3(), q3(N);
|
|
14310
|
-
let
|
|
14311
|
-
while (!(
|
|
14310
|
+
let D3 = undefined;
|
|
14311
|
+
while (!(D3 = z2(M2())))
|
|
14312
14312
|
q3();
|
|
14313
|
-
return K3(),
|
|
14313
|
+
return K3(), D3;
|
|
14314
14314
|
};
|
|
14315
14315
|
}
|
|
14316
14316
|
var KQ2 = { bigint: ($3) => typeof $3 === "bigint", function: ($3) => typeof $3 === "function", boolean: ($3) => typeof $3 === "boolean", string: ($3) => typeof $3 === "string", stringOrUint8Array: ($3) => typeof $3 === "string" || d03($3), isSafeInteger: ($3) => Number.isSafeInteger($3), array: ($3) => Array.isArray($3), field: ($3, J2) => J2.Fp.isValid($3), hash: ($3) => typeof $3 === "function" && Number.isSafeInteger($3.outputLen) };
|
|
@@ -14366,8 +14366,8 @@ function A$2($3, J2) {
|
|
|
14366
14366
|
throw Error("invert: expected positive modulus, got " + J2);
|
|
14367
14367
|
let Q4 = i4($3, J2), G2 = J2, Y2 = a4, Z3 = n4, K3 = n4, X4 = a4;
|
|
14368
14368
|
while (Q4 !== a4) {
|
|
14369
|
-
let M2 = G2 / Q4, j4 = G2 % Q4, N = Y2 - K3 * M2,
|
|
14370
|
-
G2 = Q4, Q4 = j4, Y2 = K3, Z3 = X4, K3 = N, X4 =
|
|
14369
|
+
let M2 = G2 / Q4, j4 = G2 % Q4, N = Y2 - K3 * M2, z2 = Z3 - X4 * M2;
|
|
14370
|
+
G2 = Q4, Q4 = j4, Y2 = K3, Z3 = X4, K3 = N, X4 = z2;
|
|
14371
14371
|
}
|
|
14372
14372
|
if (G2 !== n4)
|
|
14373
14373
|
throw Error("invert: does not exist");
|
|
@@ -14403,18 +14403,18 @@ function MQ($3) {
|
|
|
14403
14403
|
return M2;
|
|
14404
14404
|
if (Y8(q3, M2) !== 1)
|
|
14405
14405
|
throw Error("Cannot find square root");
|
|
14406
|
-
let j4 = Q4, N = q3.mul(q3.ONE, Z3),
|
|
14407
|
-
while (!q3.eql(
|
|
14408
|
-
if (q3.is0(
|
|
14406
|
+
let j4 = Q4, N = q3.mul(q3.ONE, Z3), z2 = q3.pow(M2, J2), D3 = q3.pow(M2, K3);
|
|
14407
|
+
while (!q3.eql(z2, q3.ONE)) {
|
|
14408
|
+
if (q3.is0(z2))
|
|
14409
14409
|
return q3.ZERO;
|
|
14410
|
-
let
|
|
14411
|
-
while (!q3.eql(
|
|
14412
|
-
if (
|
|
14410
|
+
let H4 = 1, V2 = q3.sqr(z2);
|
|
14411
|
+
while (!q3.eql(V2, q3.ONE))
|
|
14412
|
+
if (H4++, V2 = q3.sqr(V2), H4 === j4)
|
|
14413
14413
|
throw Error("Cannot find square root");
|
|
14414
|
-
let
|
|
14415
|
-
j4 =
|
|
14414
|
+
let P = n4 << BigInt(j4 - H4 - 1), S3 = q3.pow(N, P);
|
|
14415
|
+
j4 = H4, N = q3.sqr(S3), z2 = q3.mul(z2, N), D3 = q3.mul(D3, S3);
|
|
14416
14416
|
}
|
|
14417
|
-
return
|
|
14417
|
+
return D3;
|
|
14418
14418
|
};
|
|
14419
14419
|
}
|
|
14420
14420
|
function jQ($3) {
|
|
@@ -14528,8 +14528,8 @@ function W82($3, J2, Q4) {
|
|
|
14528
14528
|
let { windowSize: G2, mask: Y2, maxNumber: Z3, shiftBy: K3 } = Q4, X4 = Number($3 & Y2), q3 = $3 >> K3;
|
|
14529
14529
|
if (X4 > G2)
|
|
14530
14530
|
X4 -= Z3, q3 += WJ2;
|
|
14531
|
-
let M2 = J2 * G2, j4 = M2 + Math.abs(X4) - 1, N = X4 === 0,
|
|
14532
|
-
return { nextN: q3, offset: j4, isZero: N, isNeg:
|
|
14531
|
+
let M2 = J2 * G2, j4 = M2 + Math.abs(X4) - 1, N = X4 === 0, z2 = X4 < 0, D3 = J2 % 2 !== 0;
|
|
14532
|
+
return { nextN: q3, offset: j4, isZero: N, isNeg: z2, isNegF: D3, offsetF: M2 };
|
|
14533
14533
|
}
|
|
14534
14534
|
function NQ2($3, J2) {
|
|
14535
14535
|
if (!Array.isArray($3))
|
|
@@ -14575,11 +14575,11 @@ function D82($3, J2) {
|
|
|
14575
14575
|
}, wNAF(Q4, G2, Y2) {
|
|
14576
14576
|
let { ZERO: Z3, BASE: K3 } = $3, X4 = MJ2(Q4, J2);
|
|
14577
14577
|
for (let q3 = 0;q3 < X4.windows; q3++) {
|
|
14578
|
-
let { nextN: M2, offset: j4, isZero: N, isNeg:
|
|
14578
|
+
let { nextN: M2, offset: j4, isZero: N, isNeg: z2, isNegF: D3, offsetF: H4 } = W82(Y2, q3, X4);
|
|
14579
14579
|
if (Y2 = M2, N)
|
|
14580
|
-
K3 = K3.add(qJ3(
|
|
14580
|
+
K3 = K3.add(qJ3(D3, G2[H4]));
|
|
14581
14581
|
else
|
|
14582
|
-
Z3 = Z3.add(qJ3(
|
|
14582
|
+
Z3 = Z3.add(qJ3(z2, G2[j4]));
|
|
14583
14583
|
}
|
|
14584
14584
|
return { p: Z3, f: K3 };
|
|
14585
14585
|
}, wNAFUnsafe(Q4, G2, Y2, Z3 = $3.ZERO) {
|
|
@@ -14591,8 +14591,8 @@ function D82($3, J2) {
|
|
|
14591
14591
|
if (Y2 = q3, j4)
|
|
14592
14592
|
continue;
|
|
14593
14593
|
else {
|
|
14594
|
-
let
|
|
14595
|
-
Z3 = Z3.add(N ?
|
|
14594
|
+
let z2 = G2[M2];
|
|
14595
|
+
Z3 = Z3.add(N ? z2.negate() : z2);
|
|
14596
14596
|
}
|
|
14597
14597
|
}
|
|
14598
14598
|
return Z3;
|
|
@@ -14627,21 +14627,21 @@ function V82($3, J2, Q4, G2) {
|
|
|
14627
14627
|
q3 = X4 - 2;
|
|
14628
14628
|
else if (X4 > 0)
|
|
14629
14629
|
q3 = 2;
|
|
14630
|
-
let M2 = F03(q3), j4 = Array(Number(M2) + 1).fill(K3), N = Math.floor((J2.BITS - 1) / q3) * q3,
|
|
14631
|
-
for (let
|
|
14630
|
+
let M2 = F03(q3), j4 = Array(Number(M2) + 1).fill(K3), N = Math.floor((J2.BITS - 1) / q3) * q3, z2 = K3;
|
|
14631
|
+
for (let D3 = N;D3 >= 0; D3 -= q3) {
|
|
14632
14632
|
j4.fill(K3);
|
|
14633
|
-
for (let
|
|
14634
|
-
let
|
|
14635
|
-
j4[
|
|
14633
|
+
for (let V2 = 0;V2 < Z3; V2++) {
|
|
14634
|
+
let P = G2[V2], S3 = Number(P >> BigInt(D3) & M2);
|
|
14635
|
+
j4[S3] = j4[S3].add(Q4[V2]);
|
|
14636
14636
|
}
|
|
14637
|
-
let
|
|
14638
|
-
for (let
|
|
14639
|
-
|
|
14640
|
-
if (
|
|
14641
|
-
for (let
|
|
14642
|
-
|
|
14637
|
+
let H4 = K3;
|
|
14638
|
+
for (let V2 = j4.length - 1, P = K3;V2 > 0; V2--)
|
|
14639
|
+
P = P.add(j4[V2]), H4 = H4.add(P);
|
|
14640
|
+
if (z2 = z2.add(H4), D3 !== 0)
|
|
14641
|
+
for (let V2 = 0;V2 < q3; V2++)
|
|
14642
|
+
z2 = z2.double();
|
|
14643
14643
|
}
|
|
14644
|
-
return
|
|
14644
|
+
return z2;
|
|
14645
14645
|
}
|
|
14646
14646
|
function NJ2($3) {
|
|
14647
14647
|
return YJ3($3.Fp), b03($3, { n: "bigint", h: "bigint", Gx: "field", Gy: "field" }, { nBitLength: "isSafeInteger", nByteLength: "isSafeInteger" }), Object.freeze({ ...KJ3($3.n, $3.nBitLength), ...$3, ...{ p: $3.Fp.ORDER } });
|
|
@@ -14749,20 +14749,20 @@ var KY = BigInt(2);
|
|
|
14749
14749
|
var DJ3 = BigInt(3);
|
|
14750
14750
|
var VQ = BigInt(4);
|
|
14751
14751
|
function OQ($3) {
|
|
14752
|
-
let J2 = DQ($3), { Fp: Q4 } = J2, G2 = j$2(J2.n, J2.nBitLength), Y2 = J2.toBytes || ((U2, R4,
|
|
14753
|
-
let
|
|
14754
|
-
return M$(Uint8Array.from([4]), Q4.toBytes(
|
|
14752
|
+
let J2 = DQ($3), { Fp: Q4 } = J2, G2 = j$2(J2.n, J2.nBitLength), Y2 = J2.toBytes || ((U2, R4, B4) => {
|
|
14753
|
+
let I4 = R4.toAffine();
|
|
14754
|
+
return M$(Uint8Array.from([4]), Q4.toBytes(I4.x), Q4.toBytes(I4.y));
|
|
14755
14755
|
}), Z3 = J2.fromBytes || ((U2) => {
|
|
14756
|
-
let R4 = U2.subarray(1),
|
|
14757
|
-
return { x:
|
|
14756
|
+
let R4 = U2.subarray(1), B4 = Q4.fromBytes(R4.subarray(0, Q4.BYTES)), I4 = Q4.fromBytes(R4.subarray(Q4.BYTES, 2 * Q4.BYTES));
|
|
14757
|
+
return { x: B4, y: I4 };
|
|
14758
14758
|
});
|
|
14759
14759
|
function K3(U2) {
|
|
14760
|
-
let { a: R4, b:
|
|
14761
|
-
return Q4.add(Q4.add(w3, Q4.mul(U2, R4)),
|
|
14760
|
+
let { a: R4, b: B4 } = J2, I4 = Q4.sqr(U2), w3 = Q4.mul(I4, U2);
|
|
14761
|
+
return Q4.add(Q4.add(w3, Q4.mul(U2, R4)), B4);
|
|
14762
14762
|
}
|
|
14763
14763
|
function X4(U2, R4) {
|
|
14764
|
-
let
|
|
14765
|
-
return Q4.eql(
|
|
14764
|
+
let B4 = Q4.sqr(R4), I4 = K3(U2);
|
|
14765
|
+
return Q4.eql(B4, I4);
|
|
14766
14766
|
}
|
|
14767
14767
|
if (!X4(J2.Gx, J2.Gy))
|
|
14768
14768
|
throw Error("bad curve params: generator point");
|
|
@@ -14773,77 +14773,77 @@ function OQ($3) {
|
|
|
14773
14773
|
return x$2(U2, p5, J2.n);
|
|
14774
14774
|
}
|
|
14775
14775
|
function N(U2) {
|
|
14776
|
-
let { allowedPrivateKeyLengths: R4, nByteLength:
|
|
14776
|
+
let { allowedPrivateKeyLengths: R4, nByteLength: B4, wrapPrivateKey: I4, n: w3 } = J2;
|
|
14777
14777
|
if (R4 && typeof U2 !== "bigint") {
|
|
14778
14778
|
if (d03(U2))
|
|
14779
14779
|
U2 = n03(U2);
|
|
14780
14780
|
if (typeof U2 !== "string" || !R4.includes(U2.length))
|
|
14781
14781
|
throw Error("invalid private key");
|
|
14782
|
-
U2 = U2.padStart(
|
|
14782
|
+
U2 = U2.padStart(B4 * 2, "0");
|
|
14783
14783
|
}
|
|
14784
|
-
let
|
|
14784
|
+
let x3;
|
|
14785
14785
|
try {
|
|
14786
|
-
|
|
14786
|
+
x3 = typeof U2 === "bigint" ? U2 : z02(e5("private key", U2, B4));
|
|
14787
14787
|
} catch (y4) {
|
|
14788
|
-
throw Error("invalid private key, expected hex or " +
|
|
14788
|
+
throw Error("invalid private key, expected hex or " + B4 + " bytes, got " + typeof U2);
|
|
14789
14789
|
}
|
|
14790
|
-
if (
|
|
14791
|
-
|
|
14792
|
-
return y03("private key",
|
|
14790
|
+
if (I4)
|
|
14791
|
+
x3 = i4(x3, w3);
|
|
14792
|
+
return y03("private key", x3, p5, w3), x3;
|
|
14793
14793
|
}
|
|
14794
|
-
function
|
|
14795
|
-
if (!(U2 instanceof
|
|
14794
|
+
function z2(U2) {
|
|
14795
|
+
if (!(U2 instanceof V2))
|
|
14796
14796
|
throw Error("ProjectivePoint expected");
|
|
14797
14797
|
}
|
|
14798
|
-
let
|
|
14799
|
-
let { px:
|
|
14798
|
+
let D3 = GJ3((U2, R4) => {
|
|
14799
|
+
let { px: B4, py: I4, pz: w3 } = U2;
|
|
14800
14800
|
if (Q4.eql(w3, Q4.ONE))
|
|
14801
|
-
return { x:
|
|
14802
|
-
let
|
|
14801
|
+
return { x: B4, y: I4 };
|
|
14802
|
+
let x3 = U2.is0();
|
|
14803
14803
|
if (R4 == null)
|
|
14804
|
-
R4 =
|
|
14805
|
-
let y4 = Q4.mul(
|
|
14806
|
-
if (
|
|
14804
|
+
R4 = x3 ? Q4.ONE : Q4.inv(w3);
|
|
14805
|
+
let y4 = Q4.mul(B4, R4), E4 = Q4.mul(I4, R4), k4 = Q4.mul(w3, R4);
|
|
14806
|
+
if (x3)
|
|
14807
14807
|
return { x: Q4.ZERO, y: Q4.ZERO };
|
|
14808
14808
|
if (!Q4.eql(k4, Q4.ONE))
|
|
14809
14809
|
throw Error("invZ was invalid");
|
|
14810
|
-
return { x: y4, y:
|
|
14811
|
-
}),
|
|
14810
|
+
return { x: y4, y: E4 };
|
|
14811
|
+
}), H4 = GJ3((U2) => {
|
|
14812
14812
|
if (U2.is0()) {
|
|
14813
14813
|
if (J2.allowInfinityPoint && !Q4.is0(U2.py))
|
|
14814
14814
|
return;
|
|
14815
14815
|
throw Error("bad point: ZERO");
|
|
14816
14816
|
}
|
|
14817
|
-
let { x: R4, y:
|
|
14818
|
-
if (!Q4.isValid(R4) || !Q4.isValid(
|
|
14817
|
+
let { x: R4, y: B4 } = U2.toAffine();
|
|
14818
|
+
if (!Q4.isValid(R4) || !Q4.isValid(B4))
|
|
14819
14819
|
throw Error("bad point: x or y not FE");
|
|
14820
|
-
if (!X4(R4,
|
|
14820
|
+
if (!X4(R4, B4))
|
|
14821
14821
|
throw Error("bad point: equation left != right");
|
|
14822
14822
|
if (!U2.isTorsionFree())
|
|
14823
14823
|
throw Error("bad point: not in prime-order subgroup");
|
|
14824
14824
|
return true;
|
|
14825
14825
|
});
|
|
14826
14826
|
|
|
14827
|
-
class
|
|
14828
|
-
constructor(U2, R4,
|
|
14827
|
+
class V2 {
|
|
14828
|
+
constructor(U2, R4, B4) {
|
|
14829
14829
|
if (U2 == null || !Q4.isValid(U2))
|
|
14830
14830
|
throw Error("x required");
|
|
14831
14831
|
if (R4 == null || !Q4.isValid(R4) || Q4.is0(R4))
|
|
14832
14832
|
throw Error("y required");
|
|
14833
|
-
if (
|
|
14833
|
+
if (B4 == null || !Q4.isValid(B4))
|
|
14834
14834
|
throw Error("z required");
|
|
14835
|
-
this.px = U2, this.py = R4, this.pz =
|
|
14835
|
+
this.px = U2, this.py = R4, this.pz = B4, Object.freeze(this);
|
|
14836
14836
|
}
|
|
14837
14837
|
static fromAffine(U2) {
|
|
14838
|
-
let { x: R4, y:
|
|
14839
|
-
if (!U2 || !Q4.isValid(R4) || !Q4.isValid(
|
|
14838
|
+
let { x: R4, y: B4 } = U2 || {};
|
|
14839
|
+
if (!U2 || !Q4.isValid(R4) || !Q4.isValid(B4))
|
|
14840
14840
|
throw Error("invalid affine point");
|
|
14841
|
-
if (U2 instanceof
|
|
14841
|
+
if (U2 instanceof V2)
|
|
14842
14842
|
throw Error("projective point not allowed");
|
|
14843
|
-
let
|
|
14844
|
-
if (
|
|
14845
|
-
return
|
|
14846
|
-
return new
|
|
14843
|
+
let I4 = (w3) => Q4.eql(w3, Q4.ZERO);
|
|
14844
|
+
if (I4(R4) && I4(B4))
|
|
14845
|
+
return V2.ZERO;
|
|
14846
|
+
return new V2(R4, B4, Q4.ONE);
|
|
14847
14847
|
}
|
|
14848
14848
|
get x() {
|
|
14849
14849
|
return this.toAffine().x;
|
|
@@ -14852,24 +14852,24 @@ function OQ($3) {
|
|
|
14852
14852
|
return this.toAffine().y;
|
|
14853
14853
|
}
|
|
14854
14854
|
static normalizeZ(U2) {
|
|
14855
|
-
let R4 = ZJ3(Q4, U2.map((
|
|
14856
|
-
return U2.map((
|
|
14855
|
+
let R4 = ZJ3(Q4, U2.map((B4) => B4.pz));
|
|
14856
|
+
return U2.map((B4, I4) => B4.toAffine(R4[I4])).map(V2.fromAffine);
|
|
14857
14857
|
}
|
|
14858
14858
|
static fromHex(U2) {
|
|
14859
|
-
let R4 =
|
|
14859
|
+
let R4 = V2.fromAffine(Z3(e5("pointHex", U2)));
|
|
14860
14860
|
return R4.assertValidity(), R4;
|
|
14861
14861
|
}
|
|
14862
14862
|
static fromPrivateKey(U2) {
|
|
14863
|
-
return
|
|
14863
|
+
return V2.BASE.multiply(N(U2));
|
|
14864
14864
|
}
|
|
14865
14865
|
static msm(U2, R4) {
|
|
14866
|
-
return V82(
|
|
14866
|
+
return V82(V2, G2, U2, R4);
|
|
14867
14867
|
}
|
|
14868
14868
|
_setWindowSize(U2) {
|
|
14869
|
-
|
|
14869
|
+
g3.setWindowSize(this, U2);
|
|
14870
14870
|
}
|
|
14871
14871
|
assertValidity() {
|
|
14872
|
-
|
|
14872
|
+
H4(this);
|
|
14873
14873
|
}
|
|
14874
14874
|
hasEvenY() {
|
|
14875
14875
|
let { y: U2 } = this.toAffine();
|
|
@@ -14878,83 +14878,83 @@ function OQ($3) {
|
|
|
14878
14878
|
throw Error("Field doesn't support isOdd");
|
|
14879
14879
|
}
|
|
14880
14880
|
equals(U2) {
|
|
14881
|
-
|
|
14882
|
-
let { px: R4, py:
|
|
14883
|
-
return
|
|
14881
|
+
z2(U2);
|
|
14882
|
+
let { px: R4, py: B4, pz: I4 } = this, { px: w3, py: x3, pz: y4 } = U2, E4 = Q4.eql(Q4.mul(R4, y4), Q4.mul(w3, I4)), k4 = Q4.eql(Q4.mul(B4, y4), Q4.mul(x3, I4));
|
|
14883
|
+
return E4 && k4;
|
|
14884
14884
|
}
|
|
14885
14885
|
negate() {
|
|
14886
|
-
return new
|
|
14886
|
+
return new V2(this.px, Q4.neg(this.py), this.pz);
|
|
14887
14887
|
}
|
|
14888
14888
|
double() {
|
|
14889
|
-
let { a: U2, b: R4 } = J2,
|
|
14890
|
-
return W3 = Q4.add(W3, W3), k4 = Q4.mul(
|
|
14889
|
+
let { a: U2, b: R4 } = J2, B4 = Q4.mul(R4, DJ3), { px: I4, py: w3, pz: x3 } = this, y4 = Q4.ZERO, E4 = Q4.ZERO, k4 = Q4.ZERO, A3 = Q4.mul(I4, I4), c4 = Q4.mul(w3, w3), h4 = Q4.mul(x3, x3), W3 = Q4.mul(I4, w3);
|
|
14890
|
+
return W3 = Q4.add(W3, W3), k4 = Q4.mul(I4, x3), k4 = Q4.add(k4, k4), y4 = Q4.mul(U2, k4), E4 = Q4.mul(B4, h4), E4 = Q4.add(y4, E4), y4 = Q4.sub(c4, E4), E4 = Q4.add(c4, E4), E4 = Q4.mul(y4, E4), y4 = Q4.mul(W3, y4), k4 = Q4.mul(B4, k4), h4 = Q4.mul(U2, h4), W3 = Q4.sub(A3, h4), W3 = Q4.mul(U2, W3), W3 = Q4.add(W3, k4), k4 = Q4.add(A3, A3), A3 = Q4.add(k4, A3), A3 = Q4.add(A3, h4), A3 = Q4.mul(A3, W3), E4 = Q4.add(E4, A3), h4 = Q4.mul(w3, x3), h4 = Q4.add(h4, h4), A3 = Q4.mul(h4, W3), y4 = Q4.sub(y4, A3), k4 = Q4.mul(h4, c4), k4 = Q4.add(k4, k4), k4 = Q4.add(k4, k4), new V2(y4, E4, k4);
|
|
14891
14891
|
}
|
|
14892
14892
|
add(U2) {
|
|
14893
|
-
|
|
14894
|
-
let { px: R4, py:
|
|
14895
|
-
F2 = Q4.mul(F2,
|
|
14893
|
+
z2(U2);
|
|
14894
|
+
let { px: R4, py: B4, pz: I4 } = this, { px: w3, py: x3, pz: y4 } = U2, E4 = Q4.ZERO, k4 = Q4.ZERO, A3 = Q4.ZERO, c4 = J2.a, h4 = Q4.mul(J2.b, DJ3), W3 = Q4.mul(R4, w3), C3 = Q4.mul(B4, x3), T3 = Q4.mul(I4, y4), F2 = Q4.add(R4, B4), _4 = Q4.add(w3, x3);
|
|
14895
|
+
F2 = Q4.mul(F2, _4), _4 = Q4.add(W3, C3), F2 = Q4.sub(F2, _4), _4 = Q4.add(R4, I4);
|
|
14896
14896
|
let O4 = Q4.add(w3, y4);
|
|
14897
|
-
return
|
|
14897
|
+
return _4 = Q4.mul(_4, O4), O4 = Q4.add(W3, T3), _4 = Q4.sub(_4, O4), O4 = Q4.add(B4, I4), E4 = Q4.add(x3, y4), O4 = Q4.mul(O4, E4), E4 = Q4.add(C3, T3), O4 = Q4.sub(O4, E4), A3 = Q4.mul(c4, _4), E4 = Q4.mul(h4, T3), A3 = Q4.add(E4, A3), E4 = Q4.sub(C3, A3), A3 = Q4.add(C3, A3), k4 = Q4.mul(E4, A3), C3 = Q4.add(W3, W3), C3 = Q4.add(C3, W3), T3 = Q4.mul(c4, T3), _4 = Q4.mul(h4, _4), C3 = Q4.add(C3, T3), T3 = Q4.sub(W3, T3), T3 = Q4.mul(c4, T3), _4 = Q4.add(_4, T3), W3 = Q4.mul(C3, _4), k4 = Q4.add(k4, W3), W3 = Q4.mul(O4, _4), E4 = Q4.mul(F2, E4), E4 = Q4.sub(E4, W3), W3 = Q4.mul(F2, C3), A3 = Q4.mul(O4, A3), A3 = Q4.add(A3, W3), new V2(E4, k4, A3);
|
|
14898
14898
|
}
|
|
14899
14899
|
subtract(U2) {
|
|
14900
14900
|
return this.add(U2.negate());
|
|
14901
14901
|
}
|
|
14902
14902
|
is0() {
|
|
14903
|
-
return this.equals(
|
|
14903
|
+
return this.equals(V2.ZERO);
|
|
14904
14904
|
}
|
|
14905
14905
|
wNAF(U2) {
|
|
14906
|
-
return
|
|
14906
|
+
return g3.wNAFCached(this, U2, V2.normalizeZ);
|
|
14907
14907
|
}
|
|
14908
14908
|
multiplyUnsafe(U2) {
|
|
14909
|
-
let { endo: R4, n:
|
|
14910
|
-
y03("scalar", U2, V03,
|
|
14911
|
-
let
|
|
14909
|
+
let { endo: R4, n: B4 } = J2;
|
|
14910
|
+
y03("scalar", U2, V03, B4);
|
|
14911
|
+
let I4 = V2.ZERO;
|
|
14912
14912
|
if (U2 === V03)
|
|
14913
|
-
return
|
|
14913
|
+
return I4;
|
|
14914
14914
|
if (this.is0() || U2 === p5)
|
|
14915
14915
|
return this;
|
|
14916
|
-
if (!R4 ||
|
|
14917
|
-
return
|
|
14918
|
-
let { k1neg: w3, k1:
|
|
14919
|
-
while (
|
|
14920
|
-
if (
|
|
14916
|
+
if (!R4 || g3.hasPrecomputes(this))
|
|
14917
|
+
return g3.wNAFCachedUnsafe(this, U2, V2.normalizeZ);
|
|
14918
|
+
let { k1neg: w3, k1: x3, k2neg: y4, k2: E4 } = R4.splitScalar(U2), k4 = I4, A3 = I4, c4 = this;
|
|
14919
|
+
while (x3 > V03 || E4 > V03) {
|
|
14920
|
+
if (x3 & p5)
|
|
14921
14921
|
k4 = k4.add(c4);
|
|
14922
|
-
if (
|
|
14923
|
-
|
|
14924
|
-
c4 = c4.double(),
|
|
14922
|
+
if (E4 & p5)
|
|
14923
|
+
A3 = A3.add(c4);
|
|
14924
|
+
c4 = c4.double(), x3 >>= p5, E4 >>= p5;
|
|
14925
14925
|
}
|
|
14926
14926
|
if (w3)
|
|
14927
14927
|
k4 = k4.negate();
|
|
14928
14928
|
if (y4)
|
|
14929
|
-
|
|
14930
|
-
return
|
|
14929
|
+
A3 = A3.negate();
|
|
14930
|
+
return A3 = new V2(Q4.mul(A3.px, R4.beta), A3.py, A3.pz), k4.add(A3);
|
|
14931
14931
|
}
|
|
14932
14932
|
multiply(U2) {
|
|
14933
|
-
let { endo: R4, n:
|
|
14934
|
-
y03("scalar", U2, p5,
|
|
14935
|
-
let
|
|
14933
|
+
let { endo: R4, n: B4 } = J2;
|
|
14934
|
+
y03("scalar", U2, p5, B4);
|
|
14935
|
+
let I4, w3;
|
|
14936
14936
|
if (R4) {
|
|
14937
|
-
let { k1neg:
|
|
14938
|
-
|
|
14937
|
+
let { k1neg: x3, k1: y4, k2neg: E4, k2: k4 } = R4.splitScalar(U2), { p: A3, f: c4 } = this.wNAF(y4), { p: h4, f: W3 } = this.wNAF(k4);
|
|
14938
|
+
A3 = g3.constTimeNegate(x3, A3), h4 = g3.constTimeNegate(E4, h4), h4 = new V2(Q4.mul(h4.px, R4.beta), h4.py, h4.pz), I4 = A3.add(h4), w3 = c4.add(W3);
|
|
14939
14939
|
} else {
|
|
14940
|
-
let { p:
|
|
14941
|
-
|
|
14940
|
+
let { p: x3, f: y4 } = this.wNAF(U2);
|
|
14941
|
+
I4 = x3, w3 = y4;
|
|
14942
14942
|
}
|
|
14943
|
-
return
|
|
14943
|
+
return V2.normalizeZ([I4, w3])[0];
|
|
14944
14944
|
}
|
|
14945
|
-
multiplyAndAddUnsafe(U2, R4,
|
|
14946
|
-
let
|
|
14947
|
-
return
|
|
14945
|
+
multiplyAndAddUnsafe(U2, R4, B4) {
|
|
14946
|
+
let I4 = V2.BASE, w3 = (y4, E4) => E4 === V03 || E4 === p5 || !y4.equals(I4) ? y4.multiplyUnsafe(E4) : y4.multiply(E4), x3 = w3(this, R4).add(w3(U2, B4));
|
|
14947
|
+
return x3.is0() ? undefined : x3;
|
|
14948
14948
|
}
|
|
14949
14949
|
toAffine(U2) {
|
|
14950
|
-
return
|
|
14950
|
+
return D3(this, U2);
|
|
14951
14951
|
}
|
|
14952
14952
|
isTorsionFree() {
|
|
14953
14953
|
let { h: U2, isTorsionFree: R4 } = J2;
|
|
14954
14954
|
if (U2 === p5)
|
|
14955
14955
|
return true;
|
|
14956
14956
|
if (R4)
|
|
14957
|
-
return R4(
|
|
14957
|
+
return R4(V2, this);
|
|
14958
14958
|
throw Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
14959
14959
|
}
|
|
14960
14960
|
clearCofactor() {
|
|
@@ -14962,19 +14962,19 @@ function OQ($3) {
|
|
|
14962
14962
|
if (U2 === p5)
|
|
14963
14963
|
return this;
|
|
14964
14964
|
if (R4)
|
|
14965
|
-
return R4(
|
|
14965
|
+
return R4(V2, this);
|
|
14966
14966
|
return this.multiplyUnsafe(J2.h);
|
|
14967
14967
|
}
|
|
14968
14968
|
toRawBytes(U2 = true) {
|
|
14969
|
-
return i03("isCompressed", U2), this.assertValidity(), Y2(
|
|
14969
|
+
return i03("isCompressed", U2), this.assertValidity(), Y2(V2, this, U2);
|
|
14970
14970
|
}
|
|
14971
14971
|
toHex(U2 = true) {
|
|
14972
14972
|
return i03("isCompressed", U2), n03(this.toRawBytes(U2));
|
|
14973
14973
|
}
|
|
14974
14974
|
}
|
|
14975
|
-
|
|
14976
|
-
let { endo:
|
|
14977
|
-
return { CURVE: J2, ProjectivePoint:
|
|
14975
|
+
V2.BASE = new V2(J2.Gx, J2.Gy, Q4.ONE), V2.ZERO = new V2(Q4.ZERO, Q4.ONE, Q4.ZERO);
|
|
14976
|
+
let { endo: P, nBitLength: S3 } = J2, g3 = D82(V2, P ? Math.ceil(S3 / 2) : S3);
|
|
14977
|
+
return { CURVE: J2, ProjectivePoint: V2, normPrivateKeyToScalar: N, weierstrassEquation: K3, isWithinCurveOrder: j4 };
|
|
14978
14978
|
}
|
|
14979
14979
|
function RQ($3) {
|
|
14980
14980
|
let J2 = NJ2($3);
|
|
@@ -14988,19 +14988,19 @@ function C8($3) {
|
|
|
14988
14988
|
function M2(W3) {
|
|
14989
14989
|
return A$2(W3, G2);
|
|
14990
14990
|
}
|
|
14991
|
-
let { ProjectivePoint: j4, normPrivateKeyToScalar: N, weierstrassEquation:
|
|
14992
|
-
let F2 = C3.toAffine(),
|
|
14993
|
-
if (i03("isCompressed",
|
|
14994
|
-
return O4(Uint8Array.from([C3.hasEvenY() ? 2 : 3]),
|
|
14991
|
+
let { ProjectivePoint: j4, normPrivateKeyToScalar: N, weierstrassEquation: z2, isWithinCurveOrder: D3 } = OQ({ ...J2, toBytes(W3, C3, T3) {
|
|
14992
|
+
let F2 = C3.toAffine(), _4 = Q4.toBytes(F2.x), O4 = M$;
|
|
14993
|
+
if (i03("isCompressed", T3), T3)
|
|
14994
|
+
return O4(Uint8Array.from([C3.hasEvenY() ? 2 : 3]), _4);
|
|
14995
14995
|
else
|
|
14996
|
-
return O4(Uint8Array.from([4]),
|
|
14996
|
+
return O4(Uint8Array.from([4]), _4, Q4.toBytes(F2.y));
|
|
14997
14997
|
}, fromBytes(W3) {
|
|
14998
|
-
let C3 = W3.length,
|
|
14999
|
-
if (C3 === K3 && (
|
|
15000
|
-
let
|
|
15001
|
-
if (!x$2(
|
|
14998
|
+
let C3 = W3.length, T3 = W3[0], F2 = W3.subarray(1);
|
|
14999
|
+
if (C3 === K3 && (T3 === 2 || T3 === 3)) {
|
|
15000
|
+
let _4 = z02(F2);
|
|
15001
|
+
if (!x$2(_4, p5, Q4.ORDER))
|
|
15002
15002
|
throw Error("Point is not on curve");
|
|
15003
|
-
let O4 =
|
|
15003
|
+
let O4 = z2(_4), b4;
|
|
15004
15004
|
try {
|
|
15005
15005
|
b4 = Q4.sqrt(O4);
|
|
15006
15006
|
} catch (s3) {
|
|
@@ -15008,61 +15008,61 @@ function C8($3) {
|
|
|
15008
15008
|
throw Error("Point is not on curve" + r4);
|
|
15009
15009
|
}
|
|
15010
15010
|
let m3 = (b4 & p5) === p5;
|
|
15011
|
-
if ((
|
|
15011
|
+
if ((T3 & 1) === 1 !== m3)
|
|
15012
15012
|
b4 = Q4.neg(b4);
|
|
15013
|
-
return { x:
|
|
15014
|
-
} else if (C3 === X4 &&
|
|
15015
|
-
let
|
|
15016
|
-
return { x:
|
|
15013
|
+
return { x: _4, y: b4 };
|
|
15014
|
+
} else if (C3 === X4 && T3 === 4) {
|
|
15015
|
+
let _4 = Q4.fromBytes(F2.subarray(0, Q4.BYTES)), O4 = Q4.fromBytes(F2.subarray(Q4.BYTES, 2 * Q4.BYTES));
|
|
15016
|
+
return { x: _4, y: O4 };
|
|
15017
15017
|
} else {
|
|
15018
|
-
let
|
|
15019
|
-
throw Error("invalid Point, expected length of " +
|
|
15018
|
+
let _4 = K3, O4 = X4;
|
|
15019
|
+
throw Error("invalid Point, expected length of " + _4 + ", or uncompressed " + O4 + ", got " + C3);
|
|
15020
15020
|
}
|
|
15021
15021
|
} });
|
|
15022
|
-
function
|
|
15022
|
+
function H4(W3) {
|
|
15023
15023
|
let C3 = G2 >> p5;
|
|
15024
15024
|
return W3 > C3;
|
|
15025
15025
|
}
|
|
15026
|
-
function
|
|
15027
|
-
return
|
|
15026
|
+
function V2(W3) {
|
|
15027
|
+
return H4(W3) ? q3(-W3) : W3;
|
|
15028
15028
|
}
|
|
15029
|
-
let
|
|
15029
|
+
let P = (W3, C3, T3) => z02(W3.slice(C3, T3));
|
|
15030
15030
|
|
|
15031
|
-
class
|
|
15032
|
-
constructor(W3, C3,
|
|
15033
|
-
if (y03("r", W3, p5, G2), y03("s", C3, p5, G2), this.r = W3, this.s = C3,
|
|
15034
|
-
this.recovery =
|
|
15031
|
+
class S3 {
|
|
15032
|
+
constructor(W3, C3, T3) {
|
|
15033
|
+
if (y03("r", W3, p5, G2), y03("s", C3, p5, G2), this.r = W3, this.s = C3, T3 != null)
|
|
15034
|
+
this.recovery = T3;
|
|
15035
15035
|
Object.freeze(this);
|
|
15036
15036
|
}
|
|
15037
15037
|
static fromCompact(W3) {
|
|
15038
15038
|
let C3 = Y2;
|
|
15039
|
-
return W3 = e5("compactSignature", W3, C3 * 2), new
|
|
15039
|
+
return W3 = e5("compactSignature", W3, C3 * 2), new S3(P(W3, 0, C3), P(W3, C3, 2 * C3));
|
|
15040
15040
|
}
|
|
15041
15041
|
static fromDER(W3) {
|
|
15042
|
-
let { r: C3, s:
|
|
15043
|
-
return new
|
|
15042
|
+
let { r: C3, s: T3 } = D03.toSig(e5("DER", W3));
|
|
15043
|
+
return new S3(C3, T3);
|
|
15044
15044
|
}
|
|
15045
15045
|
assertValidity() {}
|
|
15046
15046
|
addRecoveryBit(W3) {
|
|
15047
|
-
return new
|
|
15047
|
+
return new S3(this.r, this.s, W3);
|
|
15048
15048
|
}
|
|
15049
15049
|
recoverPublicKey(W3) {
|
|
15050
|
-
let { r: C3, s:
|
|
15050
|
+
let { r: C3, s: T3, recovery: F2 } = this, _4 = w3(e5("msgHash", W3));
|
|
15051
15051
|
if (F2 == null || ![0, 1, 2, 3].includes(F2))
|
|
15052
15052
|
throw Error("recovery id invalid");
|
|
15053
15053
|
let O4 = F2 === 2 || F2 === 3 ? C3 + J2.n : C3;
|
|
15054
15054
|
if (O4 >= Q4.ORDER)
|
|
15055
15055
|
throw Error("recovery id 2 or 3 invalid");
|
|
15056
|
-
let b4 = (F2 & 1) === 0 ? "02" : "03", m3 = j4.fromHex(b4 + zJ3(O4, Q4.BYTES)), l4 = M2(O4), s3 = q3(-
|
|
15056
|
+
let b4 = (F2 & 1) === 0 ? "02" : "03", m3 = j4.fromHex(b4 + zJ3(O4, Q4.BYTES)), l4 = M2(O4), s3 = q3(-_4 * l4), r4 = q3(T3 * l4), O03 = j4.BASE.multiplyAndAddUnsafe(m3, s3, r4);
|
|
15057
15057
|
if (!O03)
|
|
15058
15058
|
throw Error("point at infinify");
|
|
15059
15059
|
return O03.assertValidity(), O03;
|
|
15060
15060
|
}
|
|
15061
15061
|
hasHighS() {
|
|
15062
|
-
return
|
|
15062
|
+
return H4(this.s);
|
|
15063
15063
|
}
|
|
15064
15064
|
normalizeS() {
|
|
15065
|
-
return this.hasHighS() ? new
|
|
15065
|
+
return this.hasHighS() ? new S3(this.r, q3(-this.s), this.recovery) : this;
|
|
15066
15066
|
}
|
|
15067
15067
|
toDERRawBytes() {
|
|
15068
15068
|
return q$(this.toDERHex());
|
|
@@ -15078,7 +15078,7 @@ function C8($3) {
|
|
|
15078
15078
|
return zJ3(this.r, W3) + zJ3(this.s, W3);
|
|
15079
15079
|
}
|
|
15080
15080
|
}
|
|
15081
|
-
let
|
|
15081
|
+
let g3 = { isValidPrivateKey(W3) {
|
|
15082
15082
|
try {
|
|
15083
15083
|
return N(W3), true;
|
|
15084
15084
|
} catch (C3) {
|
|
@@ -15098,47 +15098,47 @@ function C8($3) {
|
|
|
15098
15098
|
return false;
|
|
15099
15099
|
if (W3 instanceof j4)
|
|
15100
15100
|
return true;
|
|
15101
|
-
let
|
|
15102
|
-
if (J2.allowedPrivateKeyLengths || Y2 ===
|
|
15101
|
+
let T3 = e5("key", W3).length, F2 = Q4.BYTES, _4 = F2 + 1, O4 = 2 * F2 + 1;
|
|
15102
|
+
if (J2.allowedPrivateKeyLengths || Y2 === _4)
|
|
15103
15103
|
return;
|
|
15104
15104
|
else
|
|
15105
|
-
return
|
|
15105
|
+
return T3 === _4 || T3 === O4;
|
|
15106
15106
|
}
|
|
15107
|
-
function
|
|
15107
|
+
function B4(W3, C3, T3 = true) {
|
|
15108
15108
|
if (R4(W3) === true)
|
|
15109
15109
|
throw Error("first arg must be private key");
|
|
15110
15110
|
if (R4(C3) === false)
|
|
15111
15111
|
throw Error("second arg must be public key");
|
|
15112
|
-
return j4.fromHex(C3).multiply(N(W3)).toRawBytes(
|
|
15112
|
+
return j4.fromHex(C3).multiply(N(W3)).toRawBytes(T3);
|
|
15113
15113
|
}
|
|
15114
|
-
let
|
|
15114
|
+
let I4 = J2.bits2int || function(W3) {
|
|
15115
15115
|
if (W3.length > 8192)
|
|
15116
15116
|
throw Error("input is too large");
|
|
15117
|
-
let C3 = z02(W3),
|
|
15118
|
-
return
|
|
15117
|
+
let C3 = z02(W3), T3 = W3.length * 8 - Z3;
|
|
15118
|
+
return T3 > 0 ? C3 >> BigInt(T3) : C3;
|
|
15119
15119
|
}, w3 = J2.bits2int_modN || function(W3) {
|
|
15120
|
-
return q3(
|
|
15121
|
-
},
|
|
15120
|
+
return q3(I4(W3));
|
|
15121
|
+
}, x3 = F03(Z3);
|
|
15122
15122
|
function y4(W3) {
|
|
15123
|
-
return y03("num < 2^" + Z3, W3, V03,
|
|
15123
|
+
return y03("num < 2^" + Z3, W3, V03, x3), w03(W3, Y2);
|
|
15124
15124
|
}
|
|
15125
|
-
function
|
|
15126
|
-
if (["recovered", "canonical"].some((H03) => (H03 in
|
|
15125
|
+
function E4(W3, C3, T3 = k4) {
|
|
15126
|
+
if (["recovered", "canonical"].some((H03) => (H03 in T3)))
|
|
15127
15127
|
throw Error("sign() legacy options not supported");
|
|
15128
|
-
let { hash: F2, randomBytes:
|
|
15128
|
+
let { hash: F2, randomBytes: _4 } = J2, { lowS: O4, prehash: b4, extraEntropy: m3 } = T3;
|
|
15129
15129
|
if (O4 == null)
|
|
15130
15130
|
O4 = true;
|
|
15131
|
-
if (W3 = e5("msgHash", W3), O82(
|
|
15131
|
+
if (W3 = e5("msgHash", W3), O82(T3), b4)
|
|
15132
15132
|
W3 = e5("prehashed msgHash", F2(W3));
|
|
15133
15133
|
let l4 = w3(W3), s3 = N(C3), r4 = [y4(s3), y4(l4)];
|
|
15134
15134
|
if (m3 != null && m3 !== false) {
|
|
15135
|
-
let H03 = m3 === true ?
|
|
15135
|
+
let H03 = m3 === true ? _4(Q4.BYTES) : m3;
|
|
15136
15136
|
r4.push(e5("extraEntropy", H03));
|
|
15137
15137
|
}
|
|
15138
15138
|
let O03 = M$(...r4), N$2 = l4;
|
|
15139
15139
|
function F$2(H03) {
|
|
15140
|
-
let g03 =
|
|
15141
|
-
if (!
|
|
15140
|
+
let g03 = I4(H03);
|
|
15141
|
+
if (!D3(g03))
|
|
15142
15142
|
return;
|
|
15143
15143
|
let b$2 = M2(g03), o03 = j4.BASE.multiply(g03).toAffine(), S03 = q3(o03.x);
|
|
15144
15144
|
if (S03 === V03)
|
|
@@ -15147,45 +15147,45 @@ function C8($3) {
|
|
|
15147
15147
|
if (t03 === V03)
|
|
15148
15148
|
return;
|
|
15149
15149
|
let v03 = (o03.x === S03 ? 0 : 2) | Number(o03.y & p5), IJ3 = t03;
|
|
15150
|
-
if (O4 &&
|
|
15151
|
-
IJ3 =
|
|
15152
|
-
return new
|
|
15150
|
+
if (O4 && H4(t03))
|
|
15151
|
+
IJ3 = V2(t03), v03 ^= 1;
|
|
15152
|
+
return new S3(S03, IJ3, v03);
|
|
15153
15153
|
}
|
|
15154
15154
|
return { seed: O03, k2sig: F$2 };
|
|
15155
15155
|
}
|
|
15156
|
-
let k4 = { lowS: J2.lowS, prehash: false },
|
|
15157
|
-
function c4(W3, C3,
|
|
15158
|
-
let { seed: F2, k2sig:
|
|
15159
|
-
return G82(O4.hash.outputLen, O4.nByteLength, O4.hmac)(F2,
|
|
15156
|
+
let k4 = { lowS: J2.lowS, prehash: false }, A3 = { lowS: J2.lowS, prehash: false };
|
|
15157
|
+
function c4(W3, C3, T3 = k4) {
|
|
15158
|
+
let { seed: F2, k2sig: _4 } = E4(W3, C3, T3), O4 = J2;
|
|
15159
|
+
return G82(O4.hash.outputLen, O4.nByteLength, O4.hmac)(F2, _4);
|
|
15160
15160
|
}
|
|
15161
15161
|
j4.BASE._setWindowSize(8);
|
|
15162
|
-
function
|
|
15163
|
-
let
|
|
15164
|
-
C3 = e5("msgHash", C3),
|
|
15162
|
+
function h4(W3, C3, T3, F2 = A3) {
|
|
15163
|
+
let _4 = W3;
|
|
15164
|
+
C3 = e5("msgHash", C3), T3 = e5("publicKey", T3);
|
|
15165
15165
|
let { lowS: O4, prehash: b4, format: m3 } = F2;
|
|
15166
15166
|
if (O82(F2), "strict" in F2)
|
|
15167
15167
|
throw Error("options.strict was renamed to lowS");
|
|
15168
15168
|
if (m3 !== undefined && m3 !== "compact" && m3 !== "der")
|
|
15169
15169
|
throw Error("format must be compact or der");
|
|
15170
|
-
let l4 = typeof
|
|
15170
|
+
let l4 = typeof _4 === "string" || d03(_4), s3 = !l4 && !m3 && typeof _4 === "object" && _4 !== null && typeof _4.r === "bigint" && typeof _4.s === "bigint";
|
|
15171
15171
|
if (!l4 && !s3)
|
|
15172
15172
|
throw Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
15173
15173
|
let r4 = undefined, O03;
|
|
15174
15174
|
try {
|
|
15175
15175
|
if (s3)
|
|
15176
|
-
r4 = new
|
|
15176
|
+
r4 = new S3(_4.r, _4.s);
|
|
15177
15177
|
if (l4) {
|
|
15178
15178
|
try {
|
|
15179
15179
|
if (m3 !== "compact")
|
|
15180
|
-
r4 =
|
|
15180
|
+
r4 = S3.fromDER(_4);
|
|
15181
15181
|
} catch (v03) {
|
|
15182
15182
|
if (!(v03 instanceof D03.Err))
|
|
15183
15183
|
throw v03;
|
|
15184
15184
|
}
|
|
15185
15185
|
if (!r4 && m3 !== "der")
|
|
15186
|
-
r4 =
|
|
15186
|
+
r4 = S3.fromCompact(_4);
|
|
15187
15187
|
}
|
|
15188
|
-
O03 = j4.fromHex(
|
|
15188
|
+
O03 = j4.fromHex(T3);
|
|
15189
15189
|
} catch (v03) {
|
|
15190
15190
|
return false;
|
|
15191
15191
|
}
|
|
@@ -15200,7 +15200,7 @@ function C8($3) {
|
|
|
15200
15200
|
return false;
|
|
15201
15201
|
return q3(S03.x) === N$2;
|
|
15202
15202
|
}
|
|
15203
|
-
return { CURVE: J2, getPublicKey: U2, getSharedSecret:
|
|
15203
|
+
return { CURVE: J2, getPublicKey: U2, getSharedSecret: B4, sign: c4, verify: h4, ProjectivePoint: j4, Signature: S3, utils: g3 };
|
|
15204
15204
|
}
|
|
15205
15205
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15206
15206
|
function CQ2($3) {
|
|
@@ -15218,21 +15218,21 @@ var PQ2 = BigInt(1);
|
|
|
15218
15218
|
var VJ3 = BigInt(2);
|
|
15219
15219
|
var B8 = ($3, J2) => ($3 + J2 / VJ3) / J2;
|
|
15220
15220
|
function BQ2($3) {
|
|
15221
|
-
let J2 = H8, Q4 = BigInt(3), G2 = BigInt(6), Y2 = BigInt(11), Z3 = BigInt(22), K3 = BigInt(23), X4 = BigInt(44), q3 = BigInt(88), M2 = $3 * $3 * $3 % J2, j4 = M2 * M2 * $3 % J2, N = J02(j4, Q4, J2) * j4 % J2,
|
|
15222
|
-
if (!OJ3.eql(OJ3.sqr(
|
|
15221
|
+
let J2 = H8, Q4 = BigInt(3), G2 = BigInt(6), Y2 = BigInt(11), Z3 = BigInt(22), K3 = BigInt(23), X4 = BigInt(44), q3 = BigInt(88), M2 = $3 * $3 * $3 % J2, j4 = M2 * M2 * $3 % J2, N = J02(j4, Q4, J2) * j4 % J2, z2 = J02(N, Q4, J2) * j4 % J2, D3 = J02(z2, VJ3, J2) * M2 % J2, H4 = J02(D3, Y2, J2) * D3 % J2, V2 = J02(H4, Z3, J2) * H4 % J2, P = J02(V2, X4, J2) * V2 % J2, S3 = J02(P, q3, J2) * P % J2, g3 = J02(S3, X4, J2) * V2 % J2, U2 = J02(g3, Q4, J2) * j4 % J2, R4 = J02(U2, K3, J2) * H4 % J2, B4 = J02(R4, G2, J2) * M2 % J2, I4 = J02(B4, VJ3, J2);
|
|
15222
|
+
if (!OJ3.eql(OJ3.sqr(I4), $3))
|
|
15223
15223
|
throw Error("Cannot find square root");
|
|
15224
|
-
return
|
|
15224
|
+
return I4;
|
|
15225
15225
|
}
|
|
15226
15226
|
var OJ3 = j$2(H8, undefined, undefined, { sqrt: BQ2 });
|
|
15227
15227
|
var RJ3 = L8({ a: LQ, b: BigInt(7), Fp: OJ3, n: P8, Gx: BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"), Gy: BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"), h: BigInt(1), lowS: true, endo: { beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"), splitScalar: ($3) => {
|
|
15228
|
-
let J2 = P8, Q4 = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), G2 = -PQ2 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), Y2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), Z3 = Q4, K3 = BigInt("0x100000000000000000000000000000000"), X4 = B8(Z3 * $3, J2), q3 = B8(-G2 * $3, J2), M2 = i4($3 - X4 * Q4 - q3 * Y2, J2), j4 = i4(-X4 * G2 - q3 * Z3, J2), N = M2 > K3,
|
|
15228
|
+
let J2 = P8, Q4 = BigInt("0x3086d221a7d46bcde86c90e49284eb15"), G2 = -PQ2 * BigInt("0xe4437ed6010e88286f547fa90abfe4c3"), Y2 = BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), Z3 = Q4, K3 = BigInt("0x100000000000000000000000000000000"), X4 = B8(Z3 * $3, J2), q3 = B8(-G2 * $3, J2), M2 = i4($3 - X4 * Q4 - q3 * Y2, J2), j4 = i4(-X4 * G2 - q3 * Z3, J2), N = M2 > K3, z2 = j4 > K3;
|
|
15229
15229
|
if (N)
|
|
15230
15230
|
M2 = J2 - M2;
|
|
15231
|
-
if (
|
|
15231
|
+
if (z2)
|
|
15232
15232
|
j4 = J2 - j4;
|
|
15233
15233
|
if (M2 > K3 || j4 > K3)
|
|
15234
15234
|
throw Error("splitScalar: Endomorphism failed, k=" + $3);
|
|
15235
|
-
return { k1neg: N, k1: M2, k2neg:
|
|
15235
|
+
return { k1neg: N, k1: M2, k2neg: z2, k2: j4 };
|
|
15236
15236
|
} } }, sJ2);
|
|
15237
15237
|
function k$2() {
|
|
15238
15238
|
let $3 = RJ3.utils.randomPrivateKey();
|
|
@@ -15253,25 +15253,25 @@ function y$2($3) {
|
|
|
15253
15253
|
return "0x" + Buffer.from(Q4).toString("hex");
|
|
15254
15254
|
}
|
|
15255
15255
|
|
|
15256
|
-
class
|
|
15256
|
+
class v3 extends E$2 {
|
|
15257
15257
|
constructor($3, J2) {
|
|
15258
15258
|
super("InvitationError", $3, { ...J2, source: J2?.source || "INVITATIONS" });
|
|
15259
15259
|
}
|
|
15260
15260
|
static noPathFound($3, J2, Q4) {
|
|
15261
|
-
return new
|
|
15261
|
+
return new v3(`No valid invitation path found from ${$3} to ${J2}. ${Q4 || "The inviter may not have enough balance of the proxy inviter's token or there's no trust connection."}`, { code: "INVITATION_NO_PATH", source: "PATHFINDING", context: { from: $3, to: J2, reason: Q4 } });
|
|
15262
15262
|
}
|
|
15263
15263
|
static noProxyInviters($3) {
|
|
15264
|
-
return new
|
|
15264
|
+
return new v3(`No proxy inviters found for ${$3}. The inviter must have mutual trust connections with users who are also trusted by the invitation module, and these users must have sufficient balance.`, { code: "INVITATION_NO_PROXY_INVITERS", source: "VALIDATION", context: { inviter: $3 } });
|
|
15265
15265
|
}
|
|
15266
15266
|
static insufficientBalance($3, J2, Q4, G2, Y2, Z3) {
|
|
15267
15267
|
let K3 = Number(Q4) / 1000000000000000000, X4 = Number(G2) / 1000000000000000000;
|
|
15268
|
-
return new
|
|
15268
|
+
return new v3(`Insufficient balance for ${$3} invitation(s). Can only afford ${J2} invitation(s). Requested: ${K3.toFixed(6)} CRC, Available: ${X4.toFixed(6)} CRC.`, { code: "INVITATION_INSUFFICIENT_BALANCE", source: "VALIDATION", context: { from: Y2, to: Z3, requestedInvites: $3, availableInvites: J2, requested: Q4.toString(), available: G2.toString(), requestedCrc: K3, availableCrc: X4 } });
|
|
15269
15269
|
}
|
|
15270
15270
|
static inviteeAlreadyRegistered($3, J2) {
|
|
15271
|
-
return new
|
|
15271
|
+
return new v3(`Invitee ${J2} is already registered as a human in Circles Hub. Cannot invite an already registered user.`, { code: "INVITATION_INVITEE_ALREADY_REGISTERED", source: "VALIDATION", context: { inviter: $3, invitee: J2 } });
|
|
15272
15272
|
}
|
|
15273
15273
|
static noAddressesProvided() {
|
|
15274
|
-
return new
|
|
15274
|
+
return new v3("At least one address must be provided for invitation.", { code: "INVITATION_NO_ADDRESSES_PROVIDED", source: "VALIDATION" });
|
|
15275
15275
|
}
|
|
15276
15276
|
}
|
|
15277
15277
|
var S82 = [];
|
|
@@ -15318,19 +15318,19 @@ function HQ2($3, J2) {
|
|
|
15318
15318
|
return Q4;
|
|
15319
15319
|
}
|
|
15320
15320
|
function CJ2($3, J2, Q4, G2) {
|
|
15321
|
-
let Y2 = $3.toLowerCase(), Z3 = J2.toLowerCase(), { sorted: K3, idx: X4 } = T82(G2, Y2, Z3), q3 = HQ2(G2, Z3), M2 = G2.map((
|
|
15322
|
-
return { streamSinkId: q3.has(
|
|
15321
|
+
let Y2 = $3.toLowerCase(), Z3 = J2.toLowerCase(), { sorted: K3, idx: X4 } = T82(G2, Y2, Z3), q3 = HQ2(G2, Z3), M2 = G2.map((S3, g3) => {
|
|
15322
|
+
return { streamSinkId: q3.has(g3) ? 1 : 0, amount: S3.value };
|
|
15323
15323
|
});
|
|
15324
15324
|
if (q3.size === 0)
|
|
15325
15325
|
throw Error(`No terminal edges detected. Flow must have at least one edge delivering to receiver ${Z3}`);
|
|
15326
|
-
let j4 = Array.from(q3), N = [{ sourceCoordinate: X4[Y2], flowEdgeIds: j4, data: new Uint8Array(0) }],
|
|
15327
|
-
G2.forEach((
|
|
15328
|
-
|
|
15326
|
+
let j4 = Array.from(q3), N = [{ sourceCoordinate: X4[Y2], flowEdgeIds: j4, data: new Uint8Array(0) }], z2 = [];
|
|
15327
|
+
G2.forEach((S3) => {
|
|
15328
|
+
z2.push(X4[S3.tokenOwner.toLowerCase()]), z2.push(X4[S3.from.toLowerCase()]), z2.push(X4[S3.to.toLowerCase()]);
|
|
15329
15329
|
});
|
|
15330
|
-
let
|
|
15331
|
-
if (
|
|
15332
|
-
throw Error(`Terminal sum ${
|
|
15333
|
-
return { flowVertices: K3, flowEdges: M2, streams: N, packedCoordinates:
|
|
15330
|
+
let D3 = I82(z2), H4 = BigInt(Q4), V2 = M2.filter((S3) => S3.streamSinkId === 1).reduce((S3, g3) => S3 + BigInt(g3.amount.toString()), BigInt(0));
|
|
15331
|
+
if (V2 !== H4)
|
|
15332
|
+
throw Error(`Terminal sum ${V2} does not equal expected ${H4}`);
|
|
15333
|
+
return { flowVertices: K3, flowEdges: M2, streams: N, packedCoordinates: D3, sourceCoordinate: X4[Y2] };
|
|
15334
15334
|
}
|
|
15335
15335
|
function LJ3($3, J2) {
|
|
15336
15336
|
let Q4 = $3.streams.map((G2) => ({ sourceCoordinate: G2.sourceCoordinate, flowEdgeIds: G2.flowEdgeIds, data: G2.data instanceof Uint8Array ? U$(G2.data) : G2.data }));
|
|
@@ -15412,104 +15412,104 @@ class W$ {
|
|
|
15412
15412
|
throw o5.noPathFound(Z3, K3);
|
|
15413
15413
|
let X4 = { ...Q4 };
|
|
15414
15414
|
if (Y2 && G2?.toTokens?.length === 1) {
|
|
15415
|
-
let
|
|
15415
|
+
let g3 = G2.toTokens[0].toLowerCase();
|
|
15416
15416
|
if (Q4.maxFlow > 0n)
|
|
15417
|
-
X4.transfers.push({ from: K3, to: K3, tokenOwner:
|
|
15417
|
+
X4.transfers.push({ from: K3, to: K3, tokenOwner: g3, value: Q4.maxFlow });
|
|
15418
15418
|
}
|
|
15419
15419
|
let q3 = await PJ2(Z3, this.config.circlesRpcUrl, X4), M2 = BJ2(X4, q3), j4 = Object.keys(M2).length > 0;
|
|
15420
15420
|
if (j4 && !G2?.useWrappedBalances)
|
|
15421
15421
|
throw o5.wrappedTokensRequired();
|
|
15422
|
-
let N = [],
|
|
15422
|
+
let N = [], z2 = [];
|
|
15423
15423
|
if (j4) {
|
|
15424
|
-
let
|
|
15425
|
-
N = [...U2, ...R4],
|
|
15424
|
+
let g3 = await this._getTokenBalanceMap(Z3), U2 = this._createDemurragedUnwrapCalls(M2), { unwrapCalls: R4, wrapCalls: B4 } = this._createInflationaryUnwrapAndWrapCalls(M2, q3, g3);
|
|
15425
|
+
N = [...U2, ...R4], z2 = B4, X4 = HJ3(X4, q3);
|
|
15426
15426
|
}
|
|
15427
|
-
let
|
|
15427
|
+
let D3 = CJ2(Z3, K3, X4.maxFlow, X4.transfers), H4 = LJ3(D3, G2?.txData), V2 = this.hubV2.operateFlowMatrix(D3.flowVertices, D3.flowEdges, H4, D3.packedCoordinates), P = false;
|
|
15428
15428
|
try {
|
|
15429
|
-
|
|
15430
|
-
} catch (
|
|
15431
|
-
console.warn("Failed to check approval status, including approval transaction:",
|
|
15429
|
+
P = await this.hubV2.isApprovedForAll(Z3, Z3);
|
|
15430
|
+
} catch (g3) {
|
|
15431
|
+
console.warn("Failed to check approval status, including approval transaction:", g3);
|
|
15432
15432
|
}
|
|
15433
|
-
return [...
|
|
15433
|
+
return [...P ? [] : [this.hubV2.setApprovalForAll(Z3, true)], ...N, V2, ...z2];
|
|
15434
15434
|
}
|
|
15435
15435
|
async constructAdvancedTransfer($3, J2, Q4, G2, Y2 = false) {
|
|
15436
15436
|
let Z3 = $3.toLowerCase(), K3 = J2.toLowerCase(), X4 = BigInt(Q4);
|
|
15437
15437
|
if (Z3 === K3 && G2?.fromTokens?.length === 1 && G2?.toTokens?.length === 1) {
|
|
15438
|
-
let
|
|
15439
|
-
if (
|
|
15440
|
-
let
|
|
15441
|
-
return [{ to:
|
|
15438
|
+
let D3 = G2.fromTokens[0], H4 = G2.toTokens[0], [V2, P] = await Promise.all([this.liftERC20.erc20Circles(0, H4), this.liftERC20.erc20Circles(1, H4)]);
|
|
15439
|
+
if (D3.toLowerCase() === V2.toLowerCase() && V2 !== S$2) {
|
|
15440
|
+
let g3 = new c03({ address: D3, rpcUrl: this.config.circlesRpcUrl }).unwrap(X4);
|
|
15441
|
+
return [{ to: g3.to, data: g3.data, value: g3.value ?? 0n }];
|
|
15442
15442
|
}
|
|
15443
|
-
if (
|
|
15444
|
-
let
|
|
15443
|
+
if (D3.toLowerCase() === P.toLowerCase() && P !== S$2) {
|
|
15444
|
+
let S3 = new l03({ address: D3, rpcUrl: this.config.circlesRpcUrl }), g3 = d4.attoCirclesToAttoStaticCircles(X4), U2 = S3.unwrap(g3);
|
|
15445
15445
|
return [{ to: U2.to, data: U2.data, value: U2.value ?? 0n }];
|
|
15446
15446
|
}
|
|
15447
15447
|
}
|
|
15448
|
-
let q3 = this._truncateToSixDecimals(X4), M2 = await this._getDefaultTokenExcludeList(K3, G2?.excludeFromTokens), { ...j4 } = G2 || {}, N = { ...j4, ...M2 ? { excludeFromTokens: M2 } : {} },
|
|
15449
|
-
if (!
|
|
15448
|
+
let q3 = this._truncateToSixDecimals(X4), M2 = await this._getDefaultTokenExcludeList(K3, G2?.excludeFromTokens), { ...j4 } = G2 || {}, N = { ...j4, ...M2 ? { excludeFromTokens: M2 } : {} }, z2 = await this.pathfinder.findPath({ from: Z3, to: K3, targetFlow: q3, ...N });
|
|
15449
|
+
if (!z2.transfers || z2.transfers.length === 0)
|
|
15450
15450
|
throw o5.noPathFound(Z3, K3);
|
|
15451
|
-
if (
|
|
15452
|
-
throw o5.insufficientBalance(q3,
|
|
15453
|
-
return this.buildFlowMatrixTx(Z3, K3,
|
|
15451
|
+
if (z2.maxFlow < q3)
|
|
15452
|
+
throw o5.insufficientBalance(q3, z2.maxFlow, Z3, K3);
|
|
15453
|
+
return this.buildFlowMatrixTx(Z3, K3, z2, G2, Y2);
|
|
15454
15454
|
}
|
|
15455
15455
|
async constructReplenish($3, J2, Q4, G2) {
|
|
15456
|
-
let Y2 = $3.toLowerCase(), Z3 = J2.toLowerCase(), K3 = (G2 || $3).toLowerCase(), X4 = BigInt(Q4), M2 = (await this.balance.getTokenBalances(Y2)).filter((O4) => O4.tokenOwner.toLowerCase() === Z3), j4 = 0n, N = 0n,
|
|
15456
|
+
let Y2 = $3.toLowerCase(), Z3 = J2.toLowerCase(), K3 = (G2 || $3).toLowerCase(), X4 = BigInt(Q4), M2 = (await this.balance.getTokenBalances(Y2)).filter((O4) => O4.tokenOwner.toLowerCase() === Z3), j4 = 0n, N = 0n, z2 = 0n, D3 = null, H4 = null;
|
|
15457
15457
|
for (let O4 of M2)
|
|
15458
15458
|
if (O4.isWrapped)
|
|
15459
15459
|
if (O4.tokenType.includes("Demurrage"))
|
|
15460
|
-
N = BigInt(O4.attoCircles),
|
|
15460
|
+
N = BigInt(O4.attoCircles), D3 = O4.tokenAddress;
|
|
15461
15461
|
else
|
|
15462
|
-
|
|
15462
|
+
z2 = BigInt(O4.staticAttoCircles), H4 = O4.tokenAddress;
|
|
15463
15463
|
else
|
|
15464
15464
|
j4 = BigInt(O4.attoCircles);
|
|
15465
|
-
let
|
|
15465
|
+
let V2 = j4 + N + d4.attoStaticCirclesToAttoCircles(z2), P = [];
|
|
15466
15466
|
if (j4 >= X4) {
|
|
15467
15467
|
if (console.log(`✓ Already have ${Number(j4) / 1000000000000000000} CRC unwrapped (target: ${Number(X4) / 1000000000000000000} CRC). No replenish needed.`), K3 !== Y2) {
|
|
15468
15468
|
let O4 = await this.hubV2.toTokenId(Z3), b4 = this.hubV2.safeTransferFrom(Y2, K3, O4, X4);
|
|
15469
|
-
|
|
15469
|
+
P.push({ to: b4.to, data: b4.data, value: b4.value ?? 0n });
|
|
15470
15470
|
}
|
|
15471
|
-
return
|
|
15472
|
-
}
|
|
15473
|
-
let
|
|
15474
|
-
if (console.log(`Current unwrapped: ${Number(j4) / 1000000000000000000} CRC`), console.log(`Target amount: ${Number(X4) / 1000000000000000000} CRC`), console.log(`Need to acquire: ${Number(
|
|
15475
|
-
let O4 =
|
|
15476
|
-
if (N > 0n &&
|
|
15477
|
-
let b4 = O4 > N ? N : O4, l4 = new c03({ address:
|
|
15478
|
-
|
|
15471
|
+
return P;
|
|
15472
|
+
}
|
|
15473
|
+
let S3 = X4 - j4;
|
|
15474
|
+
if (console.log(`Current unwrapped: ${Number(j4) / 1000000000000000000} CRC`), console.log(`Target amount: ${Number(X4) / 1000000000000000000} CRC`), console.log(`Need to acquire: ${Number(S3) / 1000000000000000000} CRC`), V2 >= X4) {
|
|
15475
|
+
let O4 = S3;
|
|
15476
|
+
if (N > 0n && D3 && O4 > 0n) {
|
|
15477
|
+
let b4 = O4 > N ? N : O4, l4 = new c03({ address: D3, rpcUrl: this.config.circlesRpcUrl }).unwrap(b4);
|
|
15478
|
+
P.push({ to: l4.to, data: l4.data, value: l4.value ?? 0n }), O4 -= b4;
|
|
15479
15479
|
}
|
|
15480
|
-
if (
|
|
15481
|
-
let b4 = d4.attoCirclesToAttoStaticCircles(O4), m3 = b4 >
|
|
15482
|
-
|
|
15480
|
+
if (z2 > 0n && H4 && O4 > 0n) {
|
|
15481
|
+
let b4 = d4.attoCirclesToAttoStaticCircles(O4), m3 = b4 > z2 ? z2 : b4, s3 = new l03({ address: H4, rpcUrl: this.config.circlesRpcUrl }).unwrap(m3);
|
|
15482
|
+
P.push({ to: s3.to, data: s3.data, value: s3.value ?? 0n });
|
|
15483
15483
|
}
|
|
15484
15484
|
if (K3 !== Y2) {
|
|
15485
15485
|
let b4 = await this.hubV2.toTokenId(Z3), m3 = this.hubV2.safeTransferFrom(Y2, K3, b4, X4);
|
|
15486
|
-
|
|
15486
|
+
P.push({ to: m3.to, data: m3.data, value: m3.value ?? 0n });
|
|
15487
15487
|
}
|
|
15488
|
-
return
|
|
15488
|
+
return P;
|
|
15489
15489
|
}
|
|
15490
|
-
let U2 = !await this.hubV2.isTrusted(Y2, Z3), R4 = BigInt(Math.floor(Date.now() / 1000) + 31536000),
|
|
15490
|
+
let U2 = !await this.hubV2.isTrusted(Y2, Z3), R4 = BigInt(Math.floor(Date.now() / 1000) + 31536000), B4 = d4.truncateToInt64(S3), I4 = S3 % d4.FACTOR_1E12 !== 0n, w3 = d4.blowUpToBigInt(I4 ? B4 + 1n : B4), x3;
|
|
15491
15491
|
try {
|
|
15492
|
-
|
|
15492
|
+
x3 = await this.pathfinder.findPath({ from: Y2, to: K3, targetFlow: w3, toTokens: [Z3], useWrappedBalances: true, simulatedTrusts: U2 ? [{ truster: Y2, trustee: Z3 }] : undefined });
|
|
15493
15493
|
} catch (O4) {
|
|
15494
|
-
let b4 = Number(
|
|
15495
|
-
throw new o5(`Insufficient tokens to replenish. Target: ${m3.toFixed(6)} CRC, Current unwrapped: ${Number(j4) / 1000000000000000000} CRC, Need: ${l4.toFixed(6)} CRC, Available (including all paths): ${b4.toFixed(6)} CRC. Cannot acquire the remaining ${(Number(
|
|
15494
|
+
let b4 = Number(V2) / 1000000000000000000, m3 = Number(X4) / 1000000000000000000, l4 = Number(S3) / 1000000000000000000;
|
|
15495
|
+
throw new o5(`Insufficient tokens to replenish. Target: ${m3.toFixed(6)} CRC, Current unwrapped: ${Number(j4) / 1000000000000000000} CRC, Need: ${l4.toFixed(6)} CRC, Available (including all paths): ${b4.toFixed(6)} CRC. Cannot acquire the remaining ${(Number(S3 - (V2 - j4)) / 1000000000000000000).toFixed(6)} CRC.`, { code: "REPLENISH_INSUFFICIENT_TOKENS", source: "VALIDATION", context: { from: Y2, tokenId: Z3, target: X4.toString(), unwrapped: j4.toString(), deficit: S3.toString(), available: V2.toString(), targetCrc: m3, unwrappedCrc: Number(j4) / 1000000000000000000, deficitCrc: l4, availableCrc: b4 } });
|
|
15496
15496
|
}
|
|
15497
|
-
if (!
|
|
15497
|
+
if (!x3.transfers || x3.transfers.length === 0)
|
|
15498
15498
|
throw o5.noPathFound(Y2, K3, `No path to acquire token ${Z3}`);
|
|
15499
|
-
if (
|
|
15500
|
-
let O4 = Number(
|
|
15501
|
-
throw new o5(`Pathfinder can only provide ${O4.toFixed(6)} CRC of the ${b4.toFixed(6)} CRC deficit needed for token ${Z3}.`, { code: "REPLENISH_INSUFFICIENT_PATH_FLOW", source: "PATHFINDING", context: { from: Y2, tokenId: Z3, deficit: w3.toString(), pathFlow:
|
|
15499
|
+
if (x3.maxFlow < w3) {
|
|
15500
|
+
let O4 = Number(x3.maxFlow) / 1000000000000000000, b4 = Number(w3) / 1000000000000000000;
|
|
15501
|
+
throw new o5(`Pathfinder can only provide ${O4.toFixed(6)} CRC of the ${b4.toFixed(6)} CRC deficit needed for token ${Z3}.`, { code: "REPLENISH_INSUFFICIENT_PATH_FLOW", source: "PATHFINDING", context: { from: Y2, tokenId: Z3, deficit: w3.toString(), pathFlow: x3.maxFlow.toString(), deficitCrc: b4, pathFlowCrc: O4 } });
|
|
15502
15502
|
}
|
|
15503
15503
|
if (U2) {
|
|
15504
15504
|
let O4 = this.hubV2.trust(Z3, R4);
|
|
15505
|
-
|
|
15505
|
+
P.push({ to: O4.to, data: O4.data, value: O4.value ?? 0n });
|
|
15506
15506
|
}
|
|
15507
|
-
let y4 = await PJ2(Y2, this.config.circlesRpcUrl,
|
|
15507
|
+
let y4 = await PJ2(Y2, this.config.circlesRpcUrl, x3), E4 = BJ2(x3, y4), k4 = Object.keys(E4).length > 0, A3 = [], c4 = [];
|
|
15508
15508
|
if (k4) {
|
|
15509
|
-
let O4 = await this._getTokenBalanceMap(Y2), b4 = this._createDemurragedUnwrapCalls(
|
|
15510
|
-
|
|
15509
|
+
let O4 = await this._getTokenBalanceMap(Y2), b4 = this._createDemurragedUnwrapCalls(E4), { unwrapCalls: m3, wrapCalls: l4 } = this._createInflationaryUnwrapAndWrapCalls(E4, y4, O4);
|
|
15510
|
+
A3 = [...b4, ...m3], c4 = l4, x3 = HJ3(x3, y4);
|
|
15511
15511
|
}
|
|
15512
|
-
let
|
|
15512
|
+
let h4 = CJ2(Y2, K3, x3.maxFlow, x3.transfers), W3 = LJ3(h4), C3 = this.hubV2.operateFlowMatrix(h4.flowVertices, h4.flowEdges, W3, h4.packedCoordinates), T3 = { to: C3.to, data: C3.data, value: C3.value ?? 0n }, F2 = false;
|
|
15513
15513
|
try {
|
|
15514
15514
|
F2 = await this.hubV2.isApprovedForAll(Y2, Y2);
|
|
15515
15515
|
} catch (O4) {
|
|
@@ -15519,8 +15519,8 @@ class W$ {
|
|
|
15519
15519
|
let O4 = this.hubV2.trust(Z3, 0n);
|
|
15520
15520
|
c4.push({ to: O4.to, data: O4.data, value: O4.value ?? 0n });
|
|
15521
15521
|
}
|
|
15522
|
-
let
|
|
15523
|
-
return
|
|
15522
|
+
let _4 = F2 ? [] : [{ to: this.hubV2.setApprovalForAll(Y2, true).to, data: this.hubV2.setApprovalForAll(Y2, true).data, value: 0n }];
|
|
15523
|
+
return P.push(..._4, ...A3, T3, ...c4), P;
|
|
15524
15524
|
}
|
|
15525
15525
|
async _getTokenBalanceMap($3) {
|
|
15526
15526
|
let J2 = await this.balance.getTokenBalances($3), Q4 = new Map;
|
|
@@ -15548,10 +15548,10 @@ class W$ {
|
|
|
15548
15548
|
continue;
|
|
15549
15549
|
let N = new l03({ address: Z3, rpcUrl: this.config.circlesRpcUrl }).unwrap(M2);
|
|
15550
15550
|
G2.push({ to: N.to, data: N.data, value: N.value ?? 0n });
|
|
15551
|
-
let
|
|
15552
|
-
if (
|
|
15553
|
-
let
|
|
15554
|
-
Y2.push({ to:
|
|
15551
|
+
let z2 = q3?.tokenOwner, D3 = d4.attoStaticCirclesToAttoCircles(M2) - K3;
|
|
15552
|
+
if (D3 > 0n) {
|
|
15553
|
+
let H4 = this.hubV2.wrap(z2, D3, 1);
|
|
15554
|
+
Y2.push({ to: H4.to, data: H4.data, value: H4.value ?? 0n });
|
|
15555
15555
|
}
|
|
15556
15556
|
}
|
|
15557
15557
|
return { unwrapCalls: G2, wrapCalls: Y2 };
|
|
@@ -15584,16 +15584,16 @@ class SJ3 {
|
|
|
15584
15584
|
referralsModule;
|
|
15585
15585
|
constructor($3) {
|
|
15586
15586
|
if (!$3.referralsServiceUrl)
|
|
15587
|
-
throw new
|
|
15587
|
+
throw new v3("referralsServiceUrl is required in config", { code: "INVITATION_MISSING_CONFIG", source: "INVITATIONS", context: { missingField: "referralsServiceUrl" } });
|
|
15588
15588
|
this.config = $3, this.rpcClient = new R03($3.circlesRpcUrl), this.pathfinder = new U03(this.rpcClient), this.trust = new x03(this.rpcClient), this.hubV2 = new P03({ address: $3.v2HubAddress, rpcUrl: $3.circlesRpcUrl }), this.referralsModule = new p03({ address: $3.referralsModuleAddress, rpcUrl: $3.circlesRpcUrl });
|
|
15589
15589
|
}
|
|
15590
15590
|
async saveReferralData($3, J2) {
|
|
15591
15591
|
try {
|
|
15592
15592
|
let Q4 = await fetch(`${this.config.referralsServiceUrl}/store`, { method: "POST", headers: { accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify({ privateKey: J2, inviter: $3 }) });
|
|
15593
15593
|
if (!Q4.ok)
|
|
15594
|
-
throw new
|
|
15594
|
+
throw new v3(`HTTP error! status: ${Q4.status}`, { code: "INVITATION_HTTP_ERROR", source: "INVITATIONS", context: { status: Q4.status, url: `${this.config.referralsServiceUrl}/store` } });
|
|
15595
15595
|
} catch (Q4) {
|
|
15596
|
-
throw console.error("Failed to save referral data:", Q4), new
|
|
15596
|
+
throw console.error("Failed to save referral data:", Q4), new v3(`Failed to save referral data: ${Q4 instanceof Error ? Q4.message : "Unknown error"}`, { code: "INVITATION_SAVE_REFERRAL_FAILED", source: "INVITATIONS", cause: Q4 });
|
|
15597
15597
|
}
|
|
15598
15598
|
}
|
|
15599
15599
|
async listReferrals($3, J2 = 10, Q4 = 0) {
|
|
@@ -15602,12 +15602,12 @@ class SJ3 {
|
|
|
15602
15602
|
G2.searchParams.set("limit", String(J2)), G2.searchParams.set("offset", String(Q4));
|
|
15603
15603
|
let Y2 = await fetch(G2.toString(), { method: "GET", headers: { accept: "application/json" } });
|
|
15604
15604
|
if (!Y2.ok)
|
|
15605
|
-
throw new
|
|
15605
|
+
throw new v3(`HTTP error! status: ${Y2.status}`, { code: "INVITATION_HTTP_ERROR", source: "INVITATIONS", context: { status: Y2.status, url: G2.toString() } });
|
|
15606
15606
|
return await Y2.json();
|
|
15607
15607
|
} catch (G2) {
|
|
15608
|
-
if (G2 instanceof
|
|
15608
|
+
if (G2 instanceof v3)
|
|
15609
15609
|
throw G2;
|
|
15610
|
-
throw new
|
|
15610
|
+
throw new v3(`Failed to list referrals: ${G2 instanceof Error ? G2.message : "Unknown error"}`, { code: "INVITATION_LIST_REFERRALS_FAILED", source: "INVITATIONS", cause: G2 });
|
|
15611
15611
|
}
|
|
15612
15612
|
}
|
|
15613
15613
|
orderRealInviters($3, J2) {
|
|
@@ -15624,10 +15624,10 @@ class SJ3 {
|
|
|
15624
15624
|
async generateInvite($3, J2) {
|
|
15625
15625
|
let Q4 = $3.toLowerCase(), G2 = J2.toLowerCase();
|
|
15626
15626
|
if (await this.hubV2.isHuman(G2))
|
|
15627
|
-
throw
|
|
15627
|
+
throw v3.inviteeAlreadyRegistered(Q4, G2);
|
|
15628
15628
|
let Z3 = await this.findInvitePath(Q4), K3 = await this.generateInviteData([G2], false), X4 = new W$(this.config), q3 = await this.getRealInviters(Q4);
|
|
15629
15629
|
if (q3.length === 0)
|
|
15630
|
-
throw
|
|
15630
|
+
throw v3.noPathFound(Q4, this.config.invitationModuleAddress);
|
|
15631
15631
|
let M2 = q3[0].address;
|
|
15632
15632
|
return await X4.buildFlowMatrixTx(Q4, this.config.invitationModuleAddress, Z3, { toTokens: [M2], useWrappedBalances: true, txData: L$2(K3) }, true);
|
|
15633
15633
|
}
|
|
@@ -15638,47 +15638,50 @@ class SJ3 {
|
|
|
15638
15638
|
else {
|
|
15639
15639
|
let Z3 = await this.getRealInviters(Q4);
|
|
15640
15640
|
if (Z3.length === 0)
|
|
15641
|
-
throw
|
|
15641
|
+
throw v3.noPathFound(Q4, this.config.invitationModuleAddress);
|
|
15642
15642
|
G2 = Z3[0].address;
|
|
15643
15643
|
}
|
|
15644
15644
|
let Y2 = await this.pathfinder.findPath({ from: Q4, to: this.config.invitationModuleAddress, targetFlow: X03, toTokens: [G2], useWrappedBalances: true });
|
|
15645
15645
|
if (!Y2.transfers || Y2.transfers.length === 0)
|
|
15646
|
-
throw
|
|
15646
|
+
throw v3.noPathFound(Q4, this.config.invitationModuleAddress);
|
|
15647
15647
|
if (Y2.maxFlow < X03) {
|
|
15648
15648
|
let K3 = Number(Y2.maxFlow / X03);
|
|
15649
|
-
throw
|
|
15649
|
+
throw v3.insufficientBalance(1, K3, X03, Y2.maxFlow, Q4, this.config.invitationModuleAddress);
|
|
15650
15650
|
}
|
|
15651
15651
|
return Y2;
|
|
15652
15652
|
}
|
|
15653
15653
|
async getRealInviters($3) {
|
|
15654
|
-
let J2 = $3.toLowerCase(), Q4 = await this.trust.getTrustedBy(J2), G2 = await this.trust.getMutualTrusts(J2), Y2 = new Set([...Q4.map((
|
|
15655
|
-
|
|
15656
|
-
|
|
15657
|
-
|
|
15658
|
-
let
|
|
15659
|
-
|
|
15654
|
+
let J2 = $3.toLowerCase(), Q4 = await this.trust.getTrustedBy(J2), G2 = await this.trust.getMutualTrusts(J2), Y2 = new Set([...Q4.map((P) => P.objectAvatar.toLowerCase()), ...G2.map((P) => P.objectAvatar.toLowerCase())]), [Z3, K3] = await Promise.all([this.trust.getTrusts(this.config.invitationModuleAddress), this.trust.getMutualTrusts(this.config.invitationModuleAddress)]), X4 = new Set([...Z3.map((P) => P.objectAvatar.toLowerCase()), ...K3.map((P) => P.objectAvatar.toLowerCase())]);
|
|
15655
|
+
if (!X4.has(J2))
|
|
15656
|
+
throw new v3("Inviter must enable the invitation module before creating invitations", { code: "INVITATION_MODULE_NOT_ENABLED", source: "INVITATIONS", context: { inviter: J2, invitationModule: this.config.invitationModuleAddress } });
|
|
15657
|
+
let M2 = [];
|
|
15658
|
+
for (let P of Y2)
|
|
15659
|
+
if (X4.has(P))
|
|
15660
|
+
M2.push(P);
|
|
15661
|
+
let j4 = [...M2, J2];
|
|
15662
|
+
if (j4.length === 0)
|
|
15660
15663
|
return [];
|
|
15661
|
-
let
|
|
15662
|
-
if (!
|
|
15664
|
+
let N = await this.pathfinder.findPath({ from: J2, to: this.config.invitationModuleAddress, useWrappedBalances: true, targetFlow: $$, toTokens: j4 });
|
|
15665
|
+
if (!N.transfers || N.transfers.length === 0)
|
|
15663
15666
|
return [];
|
|
15664
|
-
let
|
|
15665
|
-
for (let
|
|
15666
|
-
if (
|
|
15667
|
-
let
|
|
15668
|
-
|
|
15667
|
+
let z2 = new Map, D3 = this.config.invitationModuleAddress.toLowerCase();
|
|
15668
|
+
for (let P of N.transfers)
|
|
15669
|
+
if (P.to.toLowerCase() === D3) {
|
|
15670
|
+
let S3 = P.tokenOwner.toLowerCase(), g3 = z2.get(S3) || BigInt(0);
|
|
15671
|
+
z2.set(S3, g3 + P.value);
|
|
15669
15672
|
}
|
|
15670
|
-
let
|
|
15671
|
-
for (let [
|
|
15672
|
-
let
|
|
15673
|
-
if (
|
|
15674
|
-
|
|
15673
|
+
let H4 = [];
|
|
15674
|
+
for (let [P, S3] of z2.entries()) {
|
|
15675
|
+
let g3 = Number(S3 / X03);
|
|
15676
|
+
if (g3 >= 1)
|
|
15677
|
+
H4.push({ address: P, possibleInvites: g3 });
|
|
15675
15678
|
}
|
|
15676
|
-
return this.orderRealInviters(
|
|
15679
|
+
return this.orderRealInviters(H4, J2);
|
|
15677
15680
|
}
|
|
15678
15681
|
async generateReferral($3) {
|
|
15679
15682
|
let J2 = $3.toLowerCase(), Q4 = k$2(), G2 = w$2(Q4), Y2 = await this.getRealInviters(J2);
|
|
15680
15683
|
if (Y2.length === 0)
|
|
15681
|
-
throw
|
|
15684
|
+
throw v3.noProxyInviters(J2);
|
|
15682
15685
|
let K3 = Y2[0].address, X4 = await this.findInvitePath(J2, K3), q3 = new W$(this.config), M2 = await this.generateInviteData([G2], true), j4 = await q3.buildFlowMatrixTx(J2, this.config.invitationModuleAddress, X4, { toTokens: [K3], useWrappedBalances: true, txData: L$2(M2) }, true);
|
|
15683
15686
|
await this.saveReferralData(J2, Q4);
|
|
15684
15687
|
let N = [];
|
|
@@ -15686,7 +15689,7 @@ class SJ3 {
|
|
|
15686
15689
|
}
|
|
15687
15690
|
async generateInviteData($3, J2 = true) {
|
|
15688
15691
|
if ($3.length === 0)
|
|
15689
|
-
throw
|
|
15692
|
+
throw v3.noAddressesProvided();
|
|
15690
15693
|
if (!J2)
|
|
15691
15694
|
if ($3.length === 1)
|
|
15692
15695
|
return M03(["address"], [$3[0]]);
|
|
@@ -15732,10 +15735,10 @@ class IQ {
|
|
|
15732
15735
|
}
|
|
15733
15736
|
async generateInvites($3, J2) {
|
|
15734
15737
|
if (J2 <= 0)
|
|
15735
|
-
throw new
|
|
15738
|
+
throw new v3("Count must be greater than 0", { code: "INVITATION_INVALID_COUNT", source: "VALIDATION", context: { count: J2 } });
|
|
15736
15739
|
let Q4 = $3.toLowerCase(), G2 = J2 === 1, Y2 = await this.simulateClaim(Q4, J2);
|
|
15737
15740
|
if (!Y2.length)
|
|
15738
|
-
throw new
|
|
15741
|
+
throw new v3("No invitation IDs returned from claim", { code: "INVITATION_NO_IDS", source: "INVITATIONS", context: { inviter: Q4, count: J2 } });
|
|
15739
15742
|
let Z3 = this.invitations.generateSecrets(J2), K3 = Z3.map((j4) => j4.signer), X4 = await this.invitationFarm.invitationModule(), q3 = G2 ? this.invitationFarm.claimInvite() : this.invitationFarm.claimInvites(BigInt(J2)), M2 = G2 ? this.buildSingleTransfer(Q4, X4, Y2[0], K3[0]) : this.buildBatchTransfer(Q4, X4, Y2, K3);
|
|
15740
15743
|
return await Promise.all(Z3.map((j4) => this.invitations.saveReferralData(Q4, j4.secret))), { invites: Z3, transactions: [q3, M2] };
|
|
15741
15744
|
}
|