@aboutcircles/sdk 0.1.14 → 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 +549 -549
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12656,9 +12656,9 @@ class R03 {
|
|
|
12656
12656
|
if (Y2 !== undefined && this.pendingResponses[Y2])
|
|
12657
12657
|
this.pendingResponses[Y2].resolve(G2), delete this.pendingResponses[Y2];
|
|
12658
12658
|
if (Z3 === "eth_subscription" && K3) {
|
|
12659
|
-
let { subscription:
|
|
12660
|
-
if (this.subscriptionListeners[
|
|
12661
|
-
this.subscriptionListeners[
|
|
12659
|
+
let { subscription: X4, result: q3 } = K3;
|
|
12660
|
+
if (this.subscriptionListeners[X4])
|
|
12661
|
+
this.subscriptionListeners[X4].forEach((M2) => M2(q3));
|
|
12662
12662
|
}
|
|
12663
12663
|
}, this.websocket.onclose = () => {
|
|
12664
12664
|
console.warn("WebSocket closed"), this.websocketConnected = false;
|
|
@@ -12701,7 +12701,7 @@ class R03 {
|
|
|
12701
12701
|
if (!this.subscriptionListeners[Z3])
|
|
12702
12702
|
this.subscriptionListeners[Z3] = [];
|
|
12703
12703
|
return this.subscriptionListeners[Z3].push((K3) => {
|
|
12704
|
-
z$2(K3).forEach((
|
|
12704
|
+
z$2(K3).forEach((X4) => Q4.emit(X4));
|
|
12705
12705
|
}), Q4.property;
|
|
12706
12706
|
}
|
|
12707
12707
|
}
|
|
@@ -12715,8 +12715,8 @@ function A8($3, J2 = false) {
|
|
|
12715
12715
|
function EJ3($3, J2 = false) {
|
|
12716
12716
|
let Q4 = $3.length, G2 = new Uint32Array(Q4), Y2 = new Uint32Array(Q4);
|
|
12717
12717
|
for (let Z3 = 0;Z3 < Q4; Z3++) {
|
|
12718
|
-
let { h: K3, l:
|
|
12719
|
-
[G2[Z3], Y2[Z3]] = [K3,
|
|
12718
|
+
let { h: K3, l: X4 } = A8($3[Z3], J2);
|
|
12719
|
+
[G2[Z3], Y2[Z3]] = [K3, X4];
|
|
12720
12720
|
}
|
|
12721
12721
|
return [G2, Y2];
|
|
12722
12722
|
}
|
|
@@ -12844,20 +12844,20 @@ 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
|
|
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++) {
|
|
12853
|
-
let
|
|
12854
|
-
Y2 = $3[j4], Z3 = $3[j4 + 1], $3[j4] =
|
|
12853
|
+
let X4 = mJ2[K3], q3 = gJ3(Y2, Z3, X4), M2 = vJ3(Y2, Z3, X4), j4 = hJ[K3];
|
|
12854
|
+
Y2 = $3[j4], Z3 = $3[j4 + 1], $3[j4] = q3, $3[j4 + 1] = M2;
|
|
12855
12855
|
}
|
|
12856
12856
|
for (let K3 = 0;K3 < 50; K3 += 10) {
|
|
12857
|
-
for (let
|
|
12858
|
-
Q4[
|
|
12859
|
-
for (let
|
|
12860
|
-
$3[K3 +
|
|
12857
|
+
for (let X4 = 0;X4 < 10; X4++)
|
|
12858
|
+
Q4[X4] = $3[K3 + X4];
|
|
12859
|
+
for (let X4 = 0;X4 < 10; X4++)
|
|
12860
|
+
$3[K3 + X4] ^= ~Q4[(X4 + 2) % 10] & Q4[(X4 + 4) % 10];
|
|
12861
12861
|
}
|
|
12862
12862
|
$3[0] ^= u83[G2], $3[1] ^= c82[G2];
|
|
12863
12863
|
}
|
|
@@ -13004,32 +13004,32 @@ function C03($3, J2, Q4) {
|
|
|
13004
13004
|
function n82($3, J2, Q4) {
|
|
13005
13005
|
let G2 = $3.slice(0, $3.indexOf("[")), Y2 = $3.endsWith("[]"), Z3 = u03(G2, Q4), K3;
|
|
13006
13006
|
if (Z3) {
|
|
13007
|
-
let
|
|
13008
|
-
K3 =
|
|
13009
|
-
let N =
|
|
13010
|
-
return
|
|
13011
|
-
}).join("") +
|
|
13007
|
+
let X4 = J2.map((j4) => C03(G2, j4, Q4)), q3 = J2.length * B$2;
|
|
13008
|
+
K3 = X4.map((j4) => {
|
|
13009
|
+
let N = q3;
|
|
13010
|
+
return q3 += j4.length / 2, K02(N);
|
|
13011
|
+
}).join("") + X4.join("");
|
|
13012
13012
|
} else
|
|
13013
|
-
K3 = J2.map((
|
|
13013
|
+
K3 = J2.map((X4) => C03(G2, X4, Q4)).join("");
|
|
13014
13014
|
return Y2 ? K02(J2.length) + K3 : K3;
|
|
13015
13015
|
}
|
|
13016
13016
|
function o82($3, J2) {
|
|
13017
13017
|
let Q4 = Array.isArray(J2), G2 = [], Y2 = [], Z3 = [];
|
|
13018
13018
|
for (let K3 = 0;K3 < $3.length; K3++) {
|
|
13019
|
-
let
|
|
13019
|
+
let X4 = $3[K3], q3 = Q4 ? J2[K3] : J2[X4.name || ""], M2 = u03(X4.type, X4.components);
|
|
13020
13020
|
if (Z3.push(M2), M2)
|
|
13021
|
-
G2.push(""), Y2.push(C03(
|
|
13021
|
+
G2.push(""), Y2.push(C03(X4.type, q3, X4.components));
|
|
13022
13022
|
else
|
|
13023
|
-
G2.push(C03(
|
|
13023
|
+
G2.push(C03(X4.type, q3, X4.components));
|
|
13024
13024
|
}
|
|
13025
13025
|
if (Y2.length > 0) {
|
|
13026
|
-
let K3 = G2.reduce((M2, j4, N) => M2 + (Z3[N] ? B$2 : j4.length / 2), 0),
|
|
13026
|
+
let K3 = G2.reduce((M2, j4, N) => M2 + (Z3[N] ? B$2 : j4.length / 2), 0), X4 = "", q3 = 0;
|
|
13027
13027
|
for (let M2 = 0;M2 < $3.length; M2++)
|
|
13028
13028
|
if (Z3[M2])
|
|
13029
|
-
|
|
13029
|
+
X4 += K02(K3), K3 += Y2[q3].length / 2, q3++;
|
|
13030
13030
|
else
|
|
13031
|
-
|
|
13032
|
-
return
|
|
13031
|
+
X4 += G2[M2];
|
|
13032
|
+
return X4 + Y2.join("");
|
|
13033
13033
|
}
|
|
13034
13034
|
return G2.join("");
|
|
13035
13035
|
}
|
|
@@ -13072,21 +13072,21 @@ function e03($3, J2, Q4 = 0, G2) {
|
|
|
13072
13072
|
function a82($3, J2, Q4, G2) {
|
|
13073
13073
|
let Y2 = $3.slice(0, $3.indexOf("[")), Z3 = J2.slice(Q4, Q4 + u4);
|
|
13074
13074
|
if ($3.endsWith("[]")) {
|
|
13075
|
-
let
|
|
13076
|
-
for (let N = 0;N <
|
|
13077
|
-
let
|
|
13078
|
-
M2.push(
|
|
13075
|
+
let X4 = parseInt(Z3, 16) * 2, q3 = parseInt(J2.slice(X4, X4 + u4), 16), M2 = [], j4 = X4 + u4;
|
|
13076
|
+
for (let N = 0;N < q3; N++) {
|
|
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
|
}
|
|
13082
13082
|
let K3 = $3.match(/\[(\d+)\]$/);
|
|
13083
13083
|
if (K3) {
|
|
13084
|
-
let
|
|
13085
|
-
for (let j4 = 0;j4 <
|
|
13084
|
+
let X4 = parseInt(K3[1]), q3 = [], M2 = 0;
|
|
13085
|
+
for (let j4 = 0;j4 < X4; j4++) {
|
|
13086
13086
|
let N = e03(Y2, J2, Q4 + M2, G2);
|
|
13087
|
-
|
|
13087
|
+
q3.push(N.value), M2 += N.consumed;
|
|
13088
13088
|
}
|
|
13089
|
-
return { value:
|
|
13089
|
+
return { value: q3, consumed: M2 };
|
|
13090
13090
|
}
|
|
13091
13091
|
throw Error(`Invalid array type: ${$3}`);
|
|
13092
13092
|
}
|
|
@@ -13119,13 +13119,13 @@ function r82($3, J2, Q4) {
|
|
|
13119
13119
|
return { value: "0x" + J2.slice(Y2 + u4, Y2 + u4 + Z3), consumed: u4 };
|
|
13120
13120
|
}
|
|
13121
13121
|
if ($3 === "string") {
|
|
13122
|
-
let Y2 = parseInt(G2, 16) * 2, Z3 = parseInt(J2.slice(Y2, Y2 + u4), 16) * 2, K3 = J2.slice(Y2 + u4, Y2 + u4 + Z3),
|
|
13123
|
-
return { value: new TextDecoder().decode(
|
|
13122
|
+
let Y2 = parseInt(G2, 16) * 2, Z3 = parseInt(J2.slice(Y2, Y2 + u4), 16) * 2, K3 = J2.slice(Y2 + u4, Y2 + u4 + Z3), X4 = new Uint8Array(K3.match(/.{2}/g)?.map((q3) => parseInt(q3, 16)) || []);
|
|
13123
|
+
return { value: new TextDecoder().decode(X4), consumed: u4 };
|
|
13124
13124
|
}
|
|
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 || [];
|
|
@@ -13133,23 +13133,23 @@ function H$2($3) {
|
|
|
13133
13133
|
return Z3;
|
|
13134
13134
|
if (G2.length !== K3.length)
|
|
13135
13135
|
throw Error(`Expected ${K3.length} arguments, got ${G2.length}`);
|
|
13136
|
-
let
|
|
13137
|
-
for (let
|
|
13138
|
-
let
|
|
13139
|
-
if (M2.push(
|
|
13140
|
-
|
|
13136
|
+
let X4 = [], q3 = [], M2 = [];
|
|
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
|
-
|
|
13143
|
-
}
|
|
13144
|
-
if (
|
|
13145
|
-
return Z3 +
|
|
13146
|
-
let j4 =
|
|
13147
|
-
for (let
|
|
13148
|
-
if (M2[
|
|
13149
|
-
N += K02(j4), j4 +=
|
|
13142
|
+
X4.push(C03(H4.type, G2[D3], V2));
|
|
13143
|
+
}
|
|
13144
|
+
if (q3.length === 0)
|
|
13145
|
+
return Z3 + X4.join("");
|
|
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 +=
|
|
13152
|
-
return Z3 + N +
|
|
13151
|
+
N += X4[D3];
|
|
13152
|
+
return Z3 + N + q3.join("");
|
|
13153
13153
|
}
|
|
13154
13154
|
function m$2($3) {
|
|
13155
13155
|
let { abi: J2, functionName: Q4, data: G2 } = $3, Y2 = J2.find((M2) => M2.type === "function" && M2.name === Q4);
|
|
@@ -13161,32 +13161,32 @@ function m$2($3) {
|
|
|
13161
13161
|
let K3 = P$2(G2);
|
|
13162
13162
|
if (Z3.length === 1)
|
|
13163
13163
|
return e03(Z3[0].type, K3, 0, Z3[0].components).value;
|
|
13164
|
-
let
|
|
13164
|
+
let X4 = [], q3 = 0;
|
|
13165
13165
|
for (let M2 of Z3) {
|
|
13166
|
-
let j4 = e03(M2.type, K3,
|
|
13167
|
-
|
|
13166
|
+
let j4 = e03(M2.type, K3, q3, M2.components);
|
|
13167
|
+
X4.push(j4.value), q3 += j4.consumed;
|
|
13168
13168
|
}
|
|
13169
|
-
return
|
|
13169
|
+
return X4;
|
|
13170
13170
|
}
|
|
13171
13171
|
function M03($3, J2) {
|
|
13172
13172
|
if ($3.length !== J2.length)
|
|
13173
13173
|
throw Error(`Type/value length mismatch: ${$3.length} types, ${J2.length} values`);
|
|
13174
13174
|
let Q4 = [], G2 = [], Y2 = [];
|
|
13175
|
-
for (let
|
|
13176
|
-
let M2 = $3[
|
|
13175
|
+
for (let q3 = 0;q3 < $3.length; q3++) {
|
|
13176
|
+
let M2 = $3[q3], j4 = u03(M2);
|
|
13177
13177
|
if (Y2.push(j4), j4)
|
|
13178
|
-
Q4.push(""), G2.push(C03(M2, J2[
|
|
13178
|
+
Q4.push(""), G2.push(C03(M2, J2[q3]));
|
|
13179
13179
|
else
|
|
13180
|
-
Q4.push(C03(M2, J2[
|
|
13180
|
+
Q4.push(C03(M2, J2[q3]));
|
|
13181
13181
|
}
|
|
13182
13182
|
if (G2.length === 0)
|
|
13183
13183
|
return "0x" + Q4.join("");
|
|
13184
|
-
let Z3 = Q4.reduce((
|
|
13185
|
-
for (let
|
|
13186
|
-
if (Y2[
|
|
13187
|
-
K3 += K02(Z3), Z3 += G2[
|
|
13184
|
+
let Z3 = Q4.reduce((q3, M2, j4) => q3 + (Y2[j4] ? B$2 : M2.length / 2), 0), K3 = "", X4 = 0;
|
|
13185
|
+
for (let q3 = 0;q3 < $3.length; q3++)
|
|
13186
|
+
if (Y2[q3])
|
|
13187
|
+
K3 += K02(Z3), Z3 += G2[X4].length / 2, X4++;
|
|
13188
13188
|
else
|
|
13189
|
-
K3 += Q4[
|
|
13189
|
+
K3 += Q4[q3];
|
|
13190
13190
|
return "0x" + K3 + G2.join("");
|
|
13191
13191
|
}
|
|
13192
13192
|
function L3($3) {
|
|
@@ -13323,9 +13323,9 @@ class $03 {
|
|
|
13323
13323
|
else {
|
|
13324
13324
|
let Z3 = [];
|
|
13325
13325
|
for (let K3 = 0;K3 < Q4; K3++) {
|
|
13326
|
-
let
|
|
13327
|
-
if (
|
|
13328
|
-
Z3.push(this.createEqualityPredicate(
|
|
13326
|
+
let X4 = this.cursorColumns[K3], q3 = $3[X4.name];
|
|
13327
|
+
if (q3 !== undefined)
|
|
13328
|
+
Z3.push(this.createEqualityPredicate(X4, q3));
|
|
13329
13329
|
}
|
|
13330
13330
|
Z3.push(this.createComparisonPredicate(G2, Y2)), J2.push({ Type: "Conjunction", ConjunctionType: "And", Predicates: Z3 });
|
|
13331
13331
|
}
|
|
@@ -13406,22 +13406,22 @@ class x03 {
|
|
|
13406
13406
|
break;
|
|
13407
13407
|
let Y2 = {};
|
|
13408
13408
|
G2.forEach((K3) => {
|
|
13409
|
-
let
|
|
13409
|
+
let X4 = L3(K3.truster), q3 = L3(K3.trustee), M2 = X4 !== J2 ? K3.truster : K3.trustee;
|
|
13410
13410
|
if (!Y2[M2])
|
|
13411
13411
|
Y2[M2] = [];
|
|
13412
13412
|
Y2[M2].push(K3);
|
|
13413
13413
|
});
|
|
13414
|
-
let Z3 = Object.entries(Y2).filter(([K3]) => L3(K3) !== J2).map(([K3,
|
|
13415
|
-
let
|
|
13416
|
-
if (
|
|
13414
|
+
let Z3 = Object.entries(Y2).filter(([K3]) => L3(K3) !== J2).map(([K3, X4]) => {
|
|
13415
|
+
let q3 = Math.max(...X4.map((j4) => j4.timestamp)), M2;
|
|
13416
|
+
if (X4.length === 2)
|
|
13417
13417
|
M2 = "mutuallyTrusts";
|
|
13418
|
-
else if (L3(
|
|
13418
|
+
else if (L3(X4[0]?.trustee) === J2)
|
|
13419
13419
|
M2 = "trustedBy";
|
|
13420
|
-
else if (L3(
|
|
13420
|
+
else if (L3(X4[0]?.truster) === J2)
|
|
13421
13421
|
M2 = "trusts";
|
|
13422
13422
|
else
|
|
13423
13423
|
throw Error("Unexpected trust list row. Couldn't determine trust relation.");
|
|
13424
|
-
return { subjectAvatar: J2, relation: M2, objectAvatar: K3, timestamp:
|
|
13424
|
+
return { subjectAvatar: J2, relation: M2, objectAvatar: K3, timestamp: q3 };
|
|
13425
13425
|
});
|
|
13426
13426
|
return f2(Z3);
|
|
13427
13427
|
}
|
|
@@ -13543,8 +13543,8 @@ class d4 {
|
|
|
13543
13543
|
return this.v1ToDemurrage($3, Z3, K3, Y2, this.PERIOD_SEC);
|
|
13544
13544
|
}
|
|
13545
13545
|
static attoCirclesToAttoCrc($3, J2) {
|
|
13546
|
-
let Q4 = J2 - this.INFLATION_DAY_ZERO_UNIX, G2 = Q4 / this.PERIOD_SEC, Y2 = Q4 % this.PERIOD_SEC, Z3 = this.v1InflateFactor(G2), K3 = this.v1InflateFactor(G2 + 1n),
|
|
13547
|
-
return $3 * 3n * this.V1_ACCURACY * this.PERIOD_SEC /
|
|
13546
|
+
let Q4 = J2 - this.INFLATION_DAY_ZERO_UNIX, G2 = Q4 / this.PERIOD_SEC, Y2 = Q4 % this.PERIOD_SEC, Z3 = this.v1InflateFactor(G2), K3 = this.v1InflateFactor(G2 + 1n), X4 = Z3 * (this.PERIOD_SEC - Y2) + K3 * Y2;
|
|
13547
|
+
return $3 * 3n * this.V1_ACCURACY * this.PERIOD_SEC / X4;
|
|
13548
13548
|
}
|
|
13549
13549
|
static v1ToDemurrage($3, J2, Q4, G2, Y2) {
|
|
13550
13550
|
let Z3 = J2 * (Y2 - G2) + Q4 * G2;
|
|
@@ -13614,9 +13614,9 @@ class G$ {
|
|
|
13614
13614
|
try {
|
|
13615
13615
|
let K3 = await this.getProfileByAddress($3);
|
|
13616
13616
|
if (K3) {
|
|
13617
|
-
let
|
|
13618
|
-
if (!G2 || !
|
|
13619
|
-
Y2.push(
|
|
13617
|
+
let X4 = { ...K3, address: $3 };
|
|
13618
|
+
if (!G2 || !X4.avatarType || G2.includes(X4.avatarType))
|
|
13619
|
+
Y2.push(X4);
|
|
13620
13620
|
}
|
|
13621
13621
|
} catch (K3) {
|
|
13622
13622
|
console.warn("Failed to get profile by address:", K3);
|
|
@@ -13624,8 +13624,8 @@ class G$ {
|
|
|
13624
13624
|
try {
|
|
13625
13625
|
let K3 = await this.searchProfiles($3, J2, Q4, G2);
|
|
13626
13626
|
if (Z3 && Y2.length > 0) {
|
|
13627
|
-
let
|
|
13628
|
-
Y2.push(...
|
|
13627
|
+
let X4 = $3.toLowerCase(), q3 = K3.filter((M2) => M2.address?.toLowerCase() !== X4);
|
|
13628
|
+
Y2.push(...q3);
|
|
13629
13629
|
} else
|
|
13630
13630
|
Y2.push(...K3);
|
|
13631
13631
|
} catch (K3) {
|
|
@@ -13680,15 +13680,15 @@ class Z$ {
|
|
|
13680
13680
|
let J2 = L3($3), Q4 = 96, G2 = await this.client.call("circles_getAvatarInfoBatch", [[J2]]);
|
|
13681
13681
|
if ((G2.length > 0 ? G2[0] : undefined)?.version === 2)
|
|
13682
13682
|
return [];
|
|
13683
|
-
let Z3 = await this.client.call("circles_query", [{ Namespace: "V_Crc", Table: "TrustRelations", Columns: ["truster", "trustee"], Filter: [{ Type: "Conjunction", ConjunctionType: "And", Predicates: [{ Type: "FilterPredicate", FilterType: "Equals", Column: "version", Value: 2 }, { Type: "FilterPredicate", FilterType: "Equals", Column: "trustee", Value: J2 }] }], Order: [] }]),
|
|
13684
|
-
if (
|
|
13683
|
+
let Z3 = await this.client.call("circles_query", [{ Namespace: "V_Crc", Table: "TrustRelations", Columns: ["truster", "trustee"], Filter: [{ Type: "Conjunction", ConjunctionType: "And", Predicates: [{ Type: "FilterPredicate", FilterType: "Equals", Column: "version", Value: 2 }, { Type: "FilterPredicate", FilterType: "Equals", Column: "trustee", Value: J2 }] }], Order: [] }]), X4 = this.transformQueryResponse(Z3).map((j4) => j4.truster);
|
|
13684
|
+
if (X4.length === 0)
|
|
13685
13685
|
return [];
|
|
13686
|
-
let
|
|
13687
|
-
for (let j4 of
|
|
13686
|
+
let q3 = await this.client.call("circles_getAvatarInfoBatch", [X4]), M2 = [];
|
|
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);
|
|
@@ -13702,14 +13702,14 @@ class Z$ {
|
|
|
13702
13702
|
let G2 = await this.client.call("circles_query", [{ Namespace: "V_Crc", Table: "TrustRelations", Columns: ["trustee", "truster"], Filter: [{ Type: "Conjunction", ConjunctionType: "And", Predicates: [{ Type: "FilterPredicate", FilterType: "Equals", Column: "version", Value: 2 }, { Type: "FilterPredicate", FilterType: "Equals", Column: "truster", Value: Q4 }] }], Order: [] }]), Z3 = this.transformQueryResponse(G2).map((M2) => M2.trustee);
|
|
13703
13703
|
if (Z3.length === 0)
|
|
13704
13704
|
return [];
|
|
13705
|
-
let K3 = await this.client.call("circles_getAvatarInfoBatch", [Z3]),
|
|
13706
|
-
return f2(
|
|
13705
|
+
let K3 = await this.client.call("circles_getAvatarInfoBatch", [Z3]), X4 = new Set(K3.filter((M2) => M2 !== null).map((M2) => L3(M2.avatar))), q3 = Z3.filter((M2) => !X4.has(L3(M2)));
|
|
13706
|
+
return f2(q3);
|
|
13707
13707
|
}
|
|
13708
13708
|
}
|
|
13709
13709
|
}
|
|
13710
13710
|
function QQ($3, J2) {
|
|
13711
|
-
let Q4 = BigInt($3), G2 = d4.attoCirclesToCircles(Q4), Y2 = d4.attoCirclesToAttoCrc(Q4, BigInt(J2)), Z3 = d4.attoCirclesToCircles(Y2), K3 = d4.attoCirclesToAttoStaticCircles(Q4, BigInt(J2)),
|
|
13712
|
-
return { attoCircles: Q4, circles: G2, staticAttoCircles: K3, staticCircles:
|
|
13711
|
+
let Q4 = BigInt($3), G2 = d4.attoCirclesToCircles(Q4), Y2 = d4.attoCirclesToAttoCrc(Q4, BigInt(J2)), Z3 = d4.attoCirclesToCircles(Y2), K3 = d4.attoCirclesToAttoStaticCircles(Q4, BigInt(J2)), X4 = d4.attoCirclesToCircles(K3);
|
|
13712
|
+
return { attoCircles: Q4, circles: G2, staticAttoCircles: K3, staticCircles: X4, attoCrc: Y2, crc: Z3 };
|
|
13713
13713
|
}
|
|
13714
13714
|
|
|
13715
13715
|
class K$2 {
|
|
@@ -13720,8 +13720,8 @@ class K$2 {
|
|
|
13720
13720
|
getTransactionHistory($3, J2 = 50, Q4 = "DESC") {
|
|
13721
13721
|
let G2 = L3($3), Y2 = [{ Type: "Conjunction", ConjunctionType: "And", Predicates: [{ Type: "FilterPredicate", FilterType: "Equals", Column: "version", Value: 2 }, { Type: "Conjunction", ConjunctionType: "Or", Predicates: [{ Type: "FilterPredicate", FilterType: "Equals", Column: "from", Value: G2 }, { Type: "FilterPredicate", FilterType: "Equals", Column: "to", Value: G2 }] }] }];
|
|
13722
13722
|
return new $03(this.client, { namespace: "V_Crc", table: "TransferSummary", sortOrder: Q4, columns: [], filter: Y2, limit: J2 }, (Z3) => {
|
|
13723
|
-
let K3 = QQ(Z3.value, Z3.timestamp),
|
|
13724
|
-
return f2(
|
|
13723
|
+
let K3 = QQ(Z3.value, Z3.timestamp), X4 = { ...Z3, ...K3 };
|
|
13724
|
+
return f2(X4);
|
|
13725
13725
|
});
|
|
13726
13726
|
}
|
|
13727
13727
|
}
|
|
@@ -14015,8 +14015,8 @@ Context: ${JSON.stringify(this.context, null, 2)}`;
|
|
|
14015
14015
|
function GQ2($3, J2, Q4, G2) {
|
|
14016
14016
|
if (typeof $3.setBigUint64 === "function")
|
|
14017
14017
|
return $3.setBigUint64(J2, Q4, G2);
|
|
14018
|
-
let Y2 = BigInt(32), Z3 = BigInt(4294967295), K3 = Number(Q4 >> Y2 & Z3),
|
|
14019
|
-
$3.setUint32(J2 +
|
|
14018
|
+
let Y2 = BigInt(32), Z3 = BigInt(4294967295), K3 = Number(Q4 >> Y2 & Z3), X4 = Number(Q4 & Z3), q3 = G2 ? 4 : 0, M2 = G2 ? 0 : 4;
|
|
14019
|
+
$3.setUint32(J2 + q3, K3, G2), $3.setUint32(J2 + M2, X4, G2);
|
|
14020
14020
|
}
|
|
14021
14021
|
function oJ2($3, J2, Q4) {
|
|
14022
14022
|
return $3 & J2 ^ ~$3 & Q4;
|
|
@@ -14036,9 +14036,9 @@ class n$2 extends E03 {
|
|
|
14036
14036
|
for (let Z3 = 0;Z3 < Y2; ) {
|
|
14037
14037
|
let K3 = Math.min(G2 - this.pos, Y2 - Z3);
|
|
14038
14038
|
if (K3 === G2) {
|
|
14039
|
-
let
|
|
14039
|
+
let X4 = O$2($3);
|
|
14040
14040
|
for (;G2 <= Y2 - Z3; Z3 += G2)
|
|
14041
|
-
this.process(
|
|
14041
|
+
this.process(X4, Z3);
|
|
14042
14042
|
continue;
|
|
14043
14043
|
}
|
|
14044
14044
|
if (Q4.set($3.subarray(Z3, Z3 + K3), this.pos), this.pos += K3, Z3 += K3, this.pos === G2)
|
|
@@ -14054,13 +14054,13 @@ class n$2 extends E03 {
|
|
|
14054
14054
|
for (let j4 = Z3;j4 < G2; j4++)
|
|
14055
14055
|
J2[j4] = 0;
|
|
14056
14056
|
GQ2(Q4, G2 - 8, BigInt(this.length * 8), Y2), this.process(Q4, 0);
|
|
14057
|
-
let K3 = O$2($3),
|
|
14058
|
-
if (
|
|
14057
|
+
let K3 = O$2($3), X4 = this.outputLen;
|
|
14058
|
+
if (X4 % 4)
|
|
14059
14059
|
throw Error("_sha2: outputLen should be aligned to 32bit");
|
|
14060
|
-
let
|
|
14061
|
-
if (
|
|
14060
|
+
let q3 = X4 / 4, M2 = this.get();
|
|
14061
|
+
if (q3 > M2.length)
|
|
14062
14062
|
throw Error("_sha2: outputLen bigger than state");
|
|
14063
|
-
for (let j4 = 0;j4 <
|
|
14063
|
+
for (let j4 = 0;j4 < q3; j4++)
|
|
14064
14064
|
K3.setUint32(4 * j4, M2[j4], Y2);
|
|
14065
14065
|
}
|
|
14066
14066
|
digest() {
|
|
@@ -14090,25 +14090,25 @@ class aJ extends n$2 {
|
|
|
14090
14090
|
this.A = W03[0] | 0, this.B = W03[1] | 0, this.C = W03[2] | 0, this.D = W03[3] | 0, this.E = W03[4] | 0, this.F = W03[5] | 0, this.G = W03[6] | 0, this.H = W03[7] | 0;
|
|
14091
14091
|
}
|
|
14092
14092
|
get() {
|
|
14093
|
-
let { A: $3, B: J2, C: Q4, D: G2, E: Y2, F: Z3, G: K3, H:
|
|
14094
|
-
return [$3, J2, Q4, G2, Y2, Z3, K3,
|
|
14093
|
+
let { A: $3, B: J2, C: Q4, D: G2, E: Y2, F: Z3, G: K3, H: X4 } = this;
|
|
14094
|
+
return [$3, J2, Q4, G2, Y2, Z3, K3, X4];
|
|
14095
14095
|
}
|
|
14096
|
-
set($3, J2, Q4, G2, Y2, Z3, K3,
|
|
14097
|
-
this.A = $3 | 0, this.B = J2 | 0, this.C = Q4 | 0, this.D = G2 | 0, this.E = Y2 | 0, this.F = Z3 | 0, this.G = K3 | 0, this.H =
|
|
14096
|
+
set($3, J2, Q4, G2, Y2, Z3, K3, X4) {
|
|
14097
|
+
this.A = $3 | 0, this.B = J2 | 0, this.C = Q4 | 0, this.D = G2 | 0, this.E = Y2 | 0, this.F = Z3 | 0, this.G = K3 | 0, this.H = X4 | 0;
|
|
14098
14098
|
}
|
|
14099
14099
|
process($3, J2) {
|
|
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
|
-
let { A: Q4, B: G2, C: Y2, D: Z3, E: K3, F:
|
|
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 =
|
|
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
|
-
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,
|
|
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
|
}
|
|
14113
14113
|
roundClean() {
|
|
14114
14114
|
Z03(B0);
|
|
@@ -14213,12 +14213,12 @@ function q$($3) {
|
|
|
14213
14213
|
throw Error("hex string expected, got unpadded hex of length " + J2);
|
|
14214
14214
|
let G2 = new Uint8Array(Q4);
|
|
14215
14215
|
for (let Y2 = 0, Z3 = 0;Y2 < Q4; Y2++, Z3 += 2) {
|
|
14216
|
-
let K3 = rJ2($3.charCodeAt(Z3)),
|
|
14217
|
-
if (K3 === undefined ||
|
|
14218
|
-
let
|
|
14219
|
-
throw Error('hex string expected, got non-hex character "' +
|
|
14216
|
+
let K3 = rJ2($3.charCodeAt(Z3)), X4 = rJ2($3.charCodeAt(Z3 + 1));
|
|
14217
|
+
if (K3 === undefined || X4 === undefined) {
|
|
14218
|
+
let q3 = $3[Z3] + $3[Z3 + 1];
|
|
14219
|
+
throw Error('hex string expected, got non-hex character "' + q3 + '" at index ' + Z3);
|
|
14220
14220
|
}
|
|
14221
|
-
G2[Y2] = K3 * 16 +
|
|
14221
|
+
G2[Y2] = K3 * 16 + X4;
|
|
14222
14222
|
}
|
|
14223
14223
|
return G2;
|
|
14224
14224
|
}
|
|
@@ -14290,40 +14290,40 @@ function G82($3, J2, Q4) {
|
|
|
14290
14290
|
throw Error("hmacFn must be a function");
|
|
14291
14291
|
let G2 = s$2($3), Y2 = s$2($3), Z3 = 0, K3 = () => {
|
|
14292
14292
|
G2.fill(1), Y2.fill(0), Z3 = 0;
|
|
14293
|
-
},
|
|
14294
|
-
if (Y2 =
|
|
14293
|
+
}, X4 = (...N) => Q4(Y2, G2, ...N), q3 = (N = s$2(0)) => {
|
|
14294
|
+
if (Y2 = X4(eJ2([0]), N), G2 = X4(), N.length === 0)
|
|
14295
14295
|
return;
|
|
14296
|
-
Y2 =
|
|
14296
|
+
Y2 = X4(eJ2([1]), N), G2 = X4();
|
|
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
|
-
G2 =
|
|
14303
|
-
let
|
|
14304
|
-
|
|
14302
|
+
G2 = X4();
|
|
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,
|
|
14309
|
-
K3(),
|
|
14310
|
-
let
|
|
14311
|
-
while (!(
|
|
14312
|
-
|
|
14313
|
-
return K3(),
|
|
14308
|
+
return (N, z2) => {
|
|
14309
|
+
K3(), q3(N);
|
|
14310
|
+
let D3 = undefined;
|
|
14311
|
+
while (!(D3 = z2(M2())))
|
|
14312
|
+
q3();
|
|
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) };
|
|
14317
14317
|
function b03($3, J2, Q4 = {}) {
|
|
14318
14318
|
let G2 = (Y2, Z3, K3) => {
|
|
14319
|
-
let
|
|
14320
|
-
if (typeof
|
|
14319
|
+
let X4 = KQ2[Z3];
|
|
14320
|
+
if (typeof X4 !== "function")
|
|
14321
14321
|
throw Error("invalid validator function");
|
|
14322
|
-
let
|
|
14323
|
-
if (K3 &&
|
|
14322
|
+
let q3 = $3[Y2];
|
|
14323
|
+
if (K3 && q3 === undefined)
|
|
14324
14324
|
return;
|
|
14325
|
-
if (!q3
|
|
14326
|
-
throw Error("param " + String(Y2) + " is invalid. Expected " + Z3 + ", got " +
|
|
14325
|
+
if (!X4(q3, $3))
|
|
14326
|
+
throw Error("param " + String(Y2) + " is invalid. Expected " + Z3 + ", got " + q3);
|
|
14327
14327
|
};
|
|
14328
14328
|
for (let [Y2, Z3] of Object.entries(J2))
|
|
14329
14329
|
G2(Y2, Z3, false);
|
|
@@ -14364,10 +14364,10 @@ function A$2($3, J2) {
|
|
|
14364
14364
|
throw Error("invert: expected non-zero number");
|
|
14365
14365
|
if (J2 <= a4)
|
|
14366
14366
|
throw Error("invert: expected positive modulus, got " + J2);
|
|
14367
|
-
let Q4 = i4($3, J2), G2 = J2, Y2 = a4, Z3 = n4, K3 = n4,
|
|
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 =
|
|
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");
|
|
@@ -14380,10 +14380,10 @@ function q82($3, J2) {
|
|
|
14380
14380
|
return G2;
|
|
14381
14381
|
}
|
|
14382
14382
|
function qQ2($3, J2) {
|
|
14383
|
-
let Q4 = ($3.ORDER - K82) / X82, G2 = $3.mul(J2, f03), Y2 = $3.pow(G2, Q4), Z3 = $3.mul(J2, Y2), K3 = $3.mul($3.mul(Z3, f03), Y2),
|
|
14384
|
-
if (!$3.eql($3.sqr(
|
|
14383
|
+
let Q4 = ($3.ORDER - K82) / X82, G2 = $3.mul(J2, f03), Y2 = $3.pow(G2, Q4), Z3 = $3.mul(J2, Y2), K3 = $3.mul($3.mul(Z3, f03), Y2), X4 = $3.mul(Z3, $3.sub(K3, $3.ONE));
|
|
14384
|
+
if (!$3.eql($3.sqr(X4), J2))
|
|
14385
14385
|
throw Error("Cannot find square root");
|
|
14386
|
-
return
|
|
14386
|
+
return X4;
|
|
14387
14387
|
}
|
|
14388
14388
|
function MQ($3) {
|
|
14389
14389
|
if ($3 < BigInt(3))
|
|
@@ -14398,23 +14398,23 @@ function MQ($3) {
|
|
|
14398
14398
|
if (Q4 === 1)
|
|
14399
14399
|
return q82;
|
|
14400
14400
|
let Z3 = Y2.pow(G2, J2), K3 = (J2 + n4) / f03;
|
|
14401
|
-
return function(
|
|
14402
|
-
if (
|
|
14401
|
+
return function(q3, M2) {
|
|
14402
|
+
if (q3.is0(M2))
|
|
14403
14403
|
return M2;
|
|
14404
|
-
if (Y8(
|
|
14404
|
+
if (Y8(q3, M2) !== 1)
|
|
14405
14405
|
throw Error("Cannot find square root");
|
|
14406
|
-
let j4 = Q4, N =
|
|
14407
|
-
while (!
|
|
14408
|
-
if (
|
|
14409
|
-
return
|
|
14410
|
-
let
|
|
14411
|
-
while (!
|
|
14412
|
-
if (
|
|
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
|
+
return q3.ZERO;
|
|
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) {
|
|
@@ -14447,15 +14447,15 @@ function WQ2($3, J2, Q4) {
|
|
|
14447
14447
|
return G2;
|
|
14448
14448
|
}
|
|
14449
14449
|
function ZJ3($3, J2, Q4 = false) {
|
|
14450
|
-
let G2 = Array(J2.length).fill(Q4 ? $3.ZERO : undefined), Y2 = J2.reduce((K3,
|
|
14451
|
-
if ($3.is0(
|
|
14450
|
+
let G2 = Array(J2.length).fill(Q4 ? $3.ZERO : undefined), Y2 = J2.reduce((K3, X4, q3) => {
|
|
14451
|
+
if ($3.is0(X4))
|
|
14452
14452
|
return K3;
|
|
14453
|
-
return G2[
|
|
14453
|
+
return G2[q3] = K3, $3.mul(K3, X4);
|
|
14454
14454
|
}, $3.ONE), Z3 = $3.inv(Y2);
|
|
14455
|
-
return J2.reduceRight((K3,
|
|
14456
|
-
if ($3.is0(
|
|
14455
|
+
return J2.reduceRight((K3, X4, q3) => {
|
|
14456
|
+
if ($3.is0(X4))
|
|
14457
14457
|
return K3;
|
|
14458
|
-
return G2[
|
|
14458
|
+
return G2[q3] = $3.mul(K3, G2[q3]), $3.mul(K3, X4);
|
|
14459
14459
|
}, Z3), G2;
|
|
14460
14460
|
}
|
|
14461
14461
|
function Y8($3, J2) {
|
|
@@ -14476,20 +14476,20 @@ function j$2($3, J2, Q4 = false, G2 = {}) {
|
|
|
14476
14476
|
let { nBitLength: Y2, nByteLength: Z3 } = KJ3($3, J2);
|
|
14477
14477
|
if (Z3 > 2048)
|
|
14478
14478
|
throw Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
14479
|
-
let K3,
|
|
14480
|
-
if (typeof
|
|
14481
|
-
throw Error("invalid field element: expected bigint, got " + typeof
|
|
14482
|
-
return a4 <=
|
|
14483
|
-
}, is0: (
|
|
14479
|
+
let K3, X4 = Object.freeze({ ORDER: $3, isLE: Q4, BITS: Y2, BYTES: Z3, MASK: F03(Y2), ZERO: a4, ONE: n4, create: (q3) => i4(q3, $3), isValid: (q3) => {
|
|
14480
|
+
if (typeof q3 !== "bigint")
|
|
14481
|
+
throw Error("invalid field element: expected bigint, got " + typeof q3);
|
|
14482
|
+
return a4 <= q3 && q3 < $3;
|
|
14483
|
+
}, is0: (q3) => q3 === a4, isOdd: (q3) => (q3 & n4) === n4, neg: (q3) => i4(-q3, $3), eql: (q3, M2) => q3 === M2, sqr: (q3) => i4(q3 * q3, $3), add: (q3, M2) => i4(q3 + M2, $3), sub: (q3, M2) => i4(q3 - M2, $3), mul: (q3, M2) => i4(q3 * M2, $3), pow: (q3, M2) => WQ2(X4, q3, M2), div: (q3, M2) => i4(q3 * A$2(M2, $3), $3), sqrN: (q3) => q3 * q3, addN: (q3, M2) => q3 + M2, subN: (q3, M2) => q3 - M2, mulN: (q3, M2) => q3 * M2, inv: (q3) => A$2(q3, $3), sqrt: G2.sqrt || ((q3) => {
|
|
14484
14484
|
if (!K3)
|
|
14485
14485
|
K3 = jQ($3);
|
|
14486
|
-
return K3(
|
|
14487
|
-
}), toBytes: (
|
|
14488
|
-
if (
|
|
14489
|
-
throw Error("Field.fromBytes: expected " + Z3 + " bytes, got " +
|
|
14490
|
-
return Q4 ? JJ2(
|
|
14491
|
-
}, invertBatch: (
|
|
14492
|
-
return Object.freeze(
|
|
14486
|
+
return K3(X4, q3);
|
|
14487
|
+
}), toBytes: (q3) => Q4 ? QJ3(q3, Z3) : w03(q3, Z3), fromBytes: (q3) => {
|
|
14488
|
+
if (q3.length !== Z3)
|
|
14489
|
+
throw Error("Field.fromBytes: expected " + Z3 + " bytes, got " + q3.length);
|
|
14490
|
+
return Q4 ? JJ2(q3) : z02(q3);
|
|
14491
|
+
}, invertBatch: (q3) => ZJ3(X4, q3), cmov: (q3, M2, j4) => j4 ? M2 : q3 });
|
|
14492
|
+
return Object.freeze(X4);
|
|
14493
14493
|
}
|
|
14494
14494
|
function M82($3) {
|
|
14495
14495
|
if (typeof $3 !== "bigint")
|
|
@@ -14505,8 +14505,8 @@ function j82($3, J2, Q4 = false) {
|
|
|
14505
14505
|
let G2 = $3.length, Y2 = M82(J2), Z3 = XJ3(J2);
|
|
14506
14506
|
if (G2 < 16 || G2 < Z3 || G2 > 1024)
|
|
14507
14507
|
throw Error("expected " + Z3 + "-1024 bytes of input, got " + G2);
|
|
14508
|
-
let K3 = Q4 ? JJ2($3) : z02($3),
|
|
14509
|
-
return Q4 ? QJ3(
|
|
14508
|
+
let K3 = Q4 ? JJ2($3) : z02($3), X4 = i4(K3, J2 - n4) + n4;
|
|
14509
|
+
return Q4 ? QJ3(X4, Y2) : w03(X4, Y2);
|
|
14510
14510
|
}
|
|
14511
14511
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
14512
14512
|
var U82 = BigInt(0);
|
|
@@ -14525,11 +14525,11 @@ function MJ2($3, J2) {
|
|
|
14525
14525
|
return { windows: Q4, windowSize: G2, mask: Z3, maxNumber: Y2, shiftBy: K3 };
|
|
14526
14526
|
}
|
|
14527
14527
|
function W82($3, J2, Q4) {
|
|
14528
|
-
let { windowSize: G2, mask: Y2, maxNumber: Z3, shiftBy: K3 } = Q4,
|
|
14529
|
-
if (
|
|
14530
|
-
|
|
14531
|
-
let M2 = J2 * G2, j4 = M2 + Math.abs(
|
|
14532
|
-
return { nextN:
|
|
14528
|
+
let { windowSize: G2, mask: Y2, maxNumber: Z3, shiftBy: K3 } = Q4, X4 = Number($3 & Y2), q3 = $3 >> K3;
|
|
14529
|
+
if (X4 > G2)
|
|
14530
|
+
X4 -= Z3, q3 += WJ2;
|
|
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))
|
|
@@ -14564,35 +14564,35 @@ function D82($3, J2) {
|
|
|
14564
14564
|
}
|
|
14565
14565
|
return Y2;
|
|
14566
14566
|
}, precomputeWindow(Q4, G2) {
|
|
14567
|
-
let { windows: Y2, windowSize: Z3 } = MJ2(G2, J2), K3 = [],
|
|
14567
|
+
let { windows: Y2, windowSize: Z3 } = MJ2(G2, J2), K3 = [], X4 = Q4, q3 = X4;
|
|
14568
14568
|
for (let M2 = 0;M2 < Y2; M2++) {
|
|
14569
|
-
|
|
14569
|
+
q3 = X4, K3.push(q3);
|
|
14570
14570
|
for (let j4 = 1;j4 < Z3; j4++)
|
|
14571
|
-
|
|
14572
|
-
|
|
14571
|
+
q3 = q3.add(X4), K3.push(q3);
|
|
14572
|
+
X4 = q3.double();
|
|
14573
14573
|
}
|
|
14574
14574
|
return K3;
|
|
14575
14575
|
}, wNAF(Q4, G2, Y2) {
|
|
14576
|
-
let { ZERO: Z3, BASE: K3 } = $3,
|
|
14577
|
-
for (let
|
|
14578
|
-
let { nextN: M2, offset: j4, isZero: N, isNeg:
|
|
14576
|
+
let { ZERO: Z3, BASE: K3 } = $3, X4 = MJ2(Q4, J2);
|
|
14577
|
+
for (let q3 = 0;q3 < X4.windows; q3++) {
|
|
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) {
|
|
14586
14586
|
let K3 = MJ2(Q4, J2);
|
|
14587
|
-
for (let
|
|
14587
|
+
for (let X4 = 0;X4 < K3.windows; X4++) {
|
|
14588
14588
|
if (Y2 === U82)
|
|
14589
14589
|
break;
|
|
14590
|
-
let { nextN:
|
|
14591
|
-
if (Y2 =
|
|
14590
|
+
let { nextN: q3, offset: M2, isZero: j4, isNeg: N } = W82(Y2, X4, K3);
|
|
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;
|
|
@@ -14620,28 +14620,28 @@ function V82($3, J2, Q4, G2) {
|
|
|
14620
14620
|
let Y2 = Q4.length, Z3 = G2.length;
|
|
14621
14621
|
if (Y2 !== Z3)
|
|
14622
14622
|
throw Error("arrays of points and scalars must have equal length");
|
|
14623
|
-
let K3 = $3.ZERO,
|
|
14624
|
-
if (
|
|
14625
|
-
|
|
14626
|
-
else if (
|
|
14627
|
-
|
|
14628
|
-
else if (
|
|
14629
|
-
|
|
14630
|
-
let M2 = F03(
|
|
14631
|
-
for (let
|
|
14623
|
+
let K3 = $3.ZERO, X4 = Q82(BigInt(Y2)), q3 = 1;
|
|
14624
|
+
if (X4 > 12)
|
|
14625
|
+
q3 = X4 - 3;
|
|
14626
|
+
else if (X4 > 4)
|
|
14627
|
+
q3 = X4 - 2;
|
|
14628
|
+
else if (X4 > 0)
|
|
14629
|
+
q3 = 2;
|
|
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 } });
|
|
@@ -14692,25 +14692,25 @@ var D03 = { Err: R8, _tlv: { encode: ($3, J2) => {
|
|
|
14692
14692
|
if (!Z3)
|
|
14693
14693
|
K3 = Y2;
|
|
14694
14694
|
else {
|
|
14695
|
-
let
|
|
14696
|
-
if (!
|
|
14695
|
+
let q3 = Y2 & 127;
|
|
14696
|
+
if (!q3)
|
|
14697
14697
|
throw new Q4("tlv.decode(long): indefinite length not supported");
|
|
14698
|
-
if (
|
|
14698
|
+
if (q3 > 4)
|
|
14699
14699
|
throw new Q4("tlv.decode(long): byte length is too big");
|
|
14700
|
-
let M2 = J2.subarray(G2, G2 +
|
|
14701
|
-
if (M2.length !==
|
|
14700
|
+
let M2 = J2.subarray(G2, G2 + q3);
|
|
14701
|
+
if (M2.length !== q3)
|
|
14702
14702
|
throw new Q4("tlv.decode: length bytes not complete");
|
|
14703
14703
|
if (M2[0] === 0)
|
|
14704
14704
|
throw new Q4("tlv.decode(long): zero leftmost byte");
|
|
14705
14705
|
for (let j4 of M2)
|
|
14706
14706
|
K3 = K3 << 8 | j4;
|
|
14707
|
-
if (G2 +=
|
|
14707
|
+
if (G2 += q3, K3 < 128)
|
|
14708
14708
|
throw new Q4("tlv.decode(long): not minimal encoding");
|
|
14709
14709
|
}
|
|
14710
|
-
let
|
|
14711
|
-
if (
|
|
14710
|
+
let X4 = J2.subarray(G2, G2 + K3);
|
|
14711
|
+
if (X4.length !== K3)
|
|
14712
14712
|
throw new Q4("tlv.decode: wrong value length");
|
|
14713
|
-
return { v:
|
|
14713
|
+
return { v: X4, l: J2.subarray(G2 + K3) };
|
|
14714
14714
|
} }, _int: { encode($3) {
|
|
14715
14715
|
let { Err: J2 } = D03;
|
|
14716
14716
|
if ($3 < V03)
|
|
@@ -14732,10 +14732,10 @@ var D03 = { Err: R8, _tlv: { encode: ($3, J2) => {
|
|
|
14732
14732
|
let { Err: J2, _int: Q4, _tlv: G2 } = D03, Y2 = e5("signature", $3), { v: Z3, l: K3 } = G2.decode(48, Y2);
|
|
14733
14733
|
if (K3.length)
|
|
14734
14734
|
throw new J2("invalid signature: left bytes after parsing");
|
|
14735
|
-
let { v:
|
|
14735
|
+
let { v: X4, l: q3 } = G2.decode(2, Z3), { v: M2, l: j4 } = G2.decode(2, q3);
|
|
14736
14736
|
if (j4.length)
|
|
14737
14737
|
throw new J2("invalid signature: left bytes after parsing");
|
|
14738
|
-
return { r: Q4.decode(
|
|
14738
|
+
return { r: Q4.decode(X4), s: Q4.decode(M2) };
|
|
14739
14739
|
}, hexFromSig($3) {
|
|
14740
14740
|
let { _tlv: J2, _int: Q4 } = D03, G2 = J2.encode(2, Q4.encode($3.r)), Y2 = J2.encode(2, Q4.encode($3.s)), Z3 = G2 + Y2;
|
|
14741
14741
|
return J2.encode(48, Z3);
|
|
@@ -14749,101 +14749,101 @@ 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
|
-
function
|
|
14764
|
-
let
|
|
14765
|
-
return Q4.eql(
|
|
14763
|
+
function X4(U2, R4) {
|
|
14764
|
+
let B4 = Q4.sqr(R4), I4 = K3(U2);
|
|
14765
|
+
return Q4.eql(B4, I4);
|
|
14766
14766
|
}
|
|
14767
|
-
if (!
|
|
14767
|
+
if (!X4(J2.Gx, J2.Gy))
|
|
14768
14768
|
throw Error("bad curve params: generator point");
|
|
14769
|
-
let
|
|
14770
|
-
if (Q4.is0(Q4.add(
|
|
14769
|
+
let q3 = Q4.mul(Q4.pow(J2.a, DJ3), VQ), M2 = Q4.mul(Q4.sqr(J2.b), BigInt(27));
|
|
14770
|
+
if (Q4.is0(Q4.add(q3, M2)))
|
|
14771
14771
|
throw Error("bad curve params: a or b");
|
|
14772
14772
|
function j4(U2) {
|
|
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 (!
|
|
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,45 +14962,45 @@ 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);
|
|
14981
14981
|
return b03(J2, { hash: "hash", hmac: "function", randomBytes: "function" }, { bits2int: "function", bits2int_modN: "function", lowS: "boolean" }), Object.freeze({ lowS: true, ...J2 });
|
|
14982
14982
|
}
|
|
14983
14983
|
function C8($3) {
|
|
14984
|
-
let J2 = RQ($3), { Fp: Q4, n: G2, nByteLength: Y2, nBitLength: Z3 } = J2, K3 = Q4.BYTES + 1,
|
|
14985
|
-
function
|
|
14984
|
+
let J2 = RQ($3), { Fp: Q4, n: G2, nByteLength: Y2, nBitLength: Z3 } = J2, K3 = Q4.BYTES + 1, X4 = 2 * Q4.BYTES + 1;
|
|
14985
|
+
function q3(W3) {
|
|
14986
14986
|
return i4(W3, G2);
|
|
14987
14987
|
}
|
|
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 ===
|
|
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 =
|
|
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,94 +15098,94 @@ 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
|
|
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
|
-
let b$2 = M2(g03), o03 = j4.BASE.multiply(g03).toAffine(), S03 =
|
|
15143
|
+
let b$2 = M2(g03), o03 = j4.BASE.multiply(g03).toAffine(), S03 = q3(o03.x);
|
|
15144
15144
|
if (S03 === V03)
|
|
15145
15145
|
return;
|
|
15146
|
-
let t03 =
|
|
15146
|
+
let t03 = q3(b$2 * q3(N$2 + S03 * s3));
|
|
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
|
}
|
|
@@ -15195,12 +15195,12 @@ function C8($3) {
|
|
|
15195
15195
|
return false;
|
|
15196
15196
|
if (b4)
|
|
15197
15197
|
C3 = J2.hash(C3);
|
|
15198
|
-
let { r: N$2, s: F$2 } = r4, H03 = w3(C3), g03 = M2(F$2), b$2 =
|
|
15198
|
+
let { r: N$2, s: F$2 } = r4, H03 = w3(C3), g03 = M2(F$2), b$2 = q3(H03 * g03), o03 = q3(N$2 * g03), S03 = j4.BASE.multiplyAndAddUnsafe(O03, b$2, o03)?.toAffine();
|
|
15199
15199
|
if (!S03)
|
|
15200
15200
|
return false;
|
|
15201
|
-
return
|
|
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),
|
|
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"),
|
|
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
|
-
let K3 = Number(Q4) / 1000000000000000000,
|
|
15268
|
-
return new
|
|
15267
|
+
let K3 = Number(Q4) / 1000000000000000000, X4 = Number(G2) / 1000000000000000000;
|
|
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 = [];
|
|
@@ -15295,21 +15295,21 @@ function T82($3, J2, Q4) {
|
|
|
15295
15295
|
$3.forEach((K3) => {
|
|
15296
15296
|
G2.add(K3.from.toLowerCase()), G2.add(K3.to.toLowerCase()), G2.add(K3.tokenOwner.toLowerCase());
|
|
15297
15297
|
});
|
|
15298
|
-
let Y2 = [...G2].sort((K3,
|
|
15299
|
-
let
|
|
15298
|
+
let Y2 = [...G2].sort((K3, X4) => {
|
|
15299
|
+
let q3 = BigInt(K3), M2 = BigInt(X4), j4 = q3 < M2, N = q3 > M2;
|
|
15300
15300
|
return j4 ? -1 : N ? 1 : 0;
|
|
15301
15301
|
}), Z3 = {};
|
|
15302
|
-
return Y2.forEach((K3,
|
|
15303
|
-
Z3[K3] =
|
|
15302
|
+
return Y2.forEach((K3, X4) => {
|
|
15303
|
+
Z3[K3] = X4;
|
|
15304
15304
|
}), { sorted: Y2, idx: Z3 };
|
|
15305
15305
|
}
|
|
15306
15306
|
function HQ2($3, J2) {
|
|
15307
15307
|
let Q4 = new Set, G2 = [], Y2 = null;
|
|
15308
15308
|
if ($3.forEach((Z3, K3) => {
|
|
15309
|
-
let
|
|
15310
|
-
if (
|
|
15309
|
+
let X4 = Z3.from.toLowerCase(), q3 = Z3.to.toLowerCase();
|
|
15310
|
+
if (X4 === J2 && q3 === J2)
|
|
15311
15311
|
Y2 = K3;
|
|
15312
|
-
else if (
|
|
15312
|
+
else if (q3 === J2)
|
|
15313
15313
|
G2.push(K3);
|
|
15314
15314
|
}), Y2 !== null)
|
|
15315
15315
|
Q4.add(Y2);
|
|
@@ -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:
|
|
15322
|
-
return { streamSinkId:
|
|
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
|
-
if (
|
|
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(
|
|
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 }));
|
|
@@ -15340,13 +15340,13 @@ function LJ3($3, J2) {
|
|
|
15340
15340
|
}
|
|
15341
15341
|
async function PJ2($3, J2, Q4) {
|
|
15342
15342
|
let G2 = new Map, Y2 = new Set;
|
|
15343
|
-
return Q4.transfers.forEach((
|
|
15344
|
-
if ($3.toLowerCase() ===
|
|
15345
|
-
Y2.add(
|
|
15346
|
-
}), (await new I$2(J2).token.getTokenInfoBatch(Array.from(Y2))).forEach((
|
|
15347
|
-
if (
|
|
15348
|
-
|
|
15349
|
-
G2.set(
|
|
15343
|
+
return Q4.transfers.forEach((X4) => {
|
|
15344
|
+
if ($3.toLowerCase() === X4.from.toLowerCase())
|
|
15345
|
+
Y2.add(X4.tokenOwner.toLowerCase());
|
|
15346
|
+
}), (await new I$2(J2).token.getTokenInfoBatch(Array.from(Y2))).forEach((X4) => {
|
|
15347
|
+
if (X4.isWrapped && !X4.isInflationary)
|
|
15348
|
+
X4.tokenType = "CrcV2_ERC20WrapperDeployed_Demurraged";
|
|
15349
|
+
G2.set(X4.tokenAddress.toLowerCase(), X4);
|
|
15350
15350
|
}), G2;
|
|
15351
15351
|
}
|
|
15352
15352
|
function BJ2($3, J2) {
|
|
@@ -15410,106 +15410,106 @@ class W$ {
|
|
|
15410
15410
|
let Z3 = $3.toLowerCase(), K3 = J2.toLowerCase();
|
|
15411
15411
|
if (!Q4.transfers || Q4.transfers.length === 0)
|
|
15412
15412
|
throw o5.noPathFound(Z3, K3);
|
|
15413
|
-
let
|
|
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
|
-
|
|
15417
|
+
X4.transfers.push({ from: K3, to: K3, tokenOwner: g3, value: Q4.maxFlow });
|
|
15418
15418
|
}
|
|
15419
|
-
let
|
|
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
|
-
let Z3 = $3.toLowerCase(), K3 = J2.toLowerCase(),
|
|
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
|
|
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(
|
|
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(),
|
|
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
|
|
15466
|
-
if (j4 >=
|
|
15467
|
-
if (console.log(`✓ Already have ${Number(j4) / 1000000000000000000} CRC unwrapped (target: ${Number(
|
|
15468
|
-
let O4 = await this.hubV2.toTokenId(Z3), b4 = this.hubV2.safeTransferFrom(Y2, K3, O4,
|
|
15469
|
-
|
|
15465
|
+
let V2 = j4 + N + d4.attoStaticCirclesToAttoCircles(z2), P = [];
|
|
15466
|
+
if (j4 >= X4) {
|
|
15467
|
+
if (console.log(`✓ Already have ${Number(j4) / 1000000000000000000} CRC unwrapped (target: ${Number(X4) / 1000000000000000000} CRC). No replenish needed.`), K3 !== Y2) {
|
|
15468
|
+
let O4 = await this.hubV2.toTokenId(Z3), b4 = this.hubV2.safeTransferFrom(Y2, K3, O4, X4);
|
|
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(
|
|
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
|
-
let b4 = await this.hubV2.toTokenId(Z3), m3 = this.hubV2.safeTransferFrom(Y2, K3, b4,
|
|
15486
|
-
|
|
15485
|
+
let b4 = await this.hubV2.toTokenId(Z3), m3 = this.hubV2.safeTransferFrom(Y2, K3, b4, X4);
|
|
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;
|
|
@@ -15540,18 +15540,18 @@ class W$ {
|
|
|
15540
15540
|
}
|
|
15541
15541
|
_createInflationaryUnwrapAndWrapCalls($3, J2, Q4) {
|
|
15542
15542
|
let G2 = [], Y2 = [];
|
|
15543
|
-
for (let [Z3, [K3,
|
|
15544
|
-
if (
|
|
15543
|
+
for (let [Z3, [K3, X4]] of Object.entries($3)) {
|
|
15544
|
+
if (X4 !== "CrcV2_ERC20WrapperDeployed_Inflationary")
|
|
15545
15545
|
continue;
|
|
15546
|
-
let
|
|
15546
|
+
let q3 = J2.get(Z3.toLowerCase()), M2 = Q4.get(Z3.toLowerCase()) || 0n;
|
|
15547
15547
|
if (M2 === 0n)
|
|
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,12 +15624,12 @@ 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
|
|
15628
|
-
let Z3 = await this.findInvitePath(Q4), K3 = await this.generateInviteData([G2], false),
|
|
15629
|
-
if (
|
|
15630
|
-
throw
|
|
15631
|
-
let M2 =
|
|
15632
|
-
return await
|
|
15627
|
+
throw v3.inviteeAlreadyRegistered(Q4, G2);
|
|
15628
|
+
let Z3 = await this.findInvitePath(Q4), K3 = await this.generateInviteData([G2], false), X4 = new W$(this.config), q3 = await this.getRealInviters(Q4);
|
|
15629
|
+
if (q3.length === 0)
|
|
15630
|
+
throw v3.noPathFound(Q4, this.config.invitationModuleAddress);
|
|
15631
|
+
let M2 = q3[0].address;
|
|
15632
|
+
return await X4.buildFlowMatrixTx(Q4, this.config.invitationModuleAddress, Z3, { toTokens: [M2], useWrappedBalances: true, txData: L$2(K3) }, true);
|
|
15633
15633
|
}
|
|
15634
15634
|
async findInvitePath($3, J2) {
|
|
15635
15635
|
let Q4 = $3.toLowerCase(), G2;
|
|
@@ -15638,58 +15638,58 @@ 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
|
-
if (!
|
|
15656
|
-
throw new
|
|
15657
|
-
let
|
|
15658
|
-
for (let
|
|
15659
|
-
if (
|
|
15660
|
-
|
|
15661
|
-
let
|
|
15662
|
-
if (
|
|
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)
|
|
15663
15663
|
return [];
|
|
15664
|
-
let
|
|
15665
|
-
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)
|
|
15666
15666
|
return [];
|
|
15667
|
-
let
|
|
15668
|
-
for (let
|
|
15669
|
-
if (
|
|
15670
|
-
let
|
|
15671
|
-
|
|
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);
|
|
15672
15672
|
}
|
|
15673
|
-
let
|
|
15674
|
-
for (let [
|
|
15675
|
-
let
|
|
15676
|
-
if (
|
|
15677
|
-
|
|
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 });
|
|
15678
15678
|
}
|
|
15679
|
-
return this.orderRealInviters(
|
|
15679
|
+
return this.orderRealInviters(H4, J2);
|
|
15680
15680
|
}
|
|
15681
15681
|
async generateReferral($3) {
|
|
15682
15682
|
let J2 = $3.toLowerCase(), Q4 = k$2(), G2 = w$2(Q4), Y2 = await this.getRealInviters(J2);
|
|
15683
15683
|
if (Y2.length === 0)
|
|
15684
|
-
throw
|
|
15685
|
-
let K3 = Y2[0].address,
|
|
15684
|
+
throw v3.noProxyInviters(J2);
|
|
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);
|
|
15686
15686
|
await this.saveReferralData(J2, Q4);
|
|
15687
15687
|
let N = [];
|
|
15688
15688
|
return N.push(...j4), { transactions: N, privateKey: Q4 };
|
|
15689
15689
|
}
|
|
15690
15690
|
async generateInviteData($3, J2 = true) {
|
|
15691
15691
|
if ($3.length === 0)
|
|
15692
|
-
throw
|
|
15692
|
+
throw v3.noAddressesProvided();
|
|
15693
15693
|
if (!J2)
|
|
15694
15694
|
if ($3.length === 1)
|
|
15695
15695
|
return M03(["address"], [$3[0]]);
|
|
@@ -15704,7 +15704,7 @@ class SJ3 {
|
|
|
15704
15704
|
}
|
|
15705
15705
|
}
|
|
15706
15706
|
computeAddress($3) {
|
|
15707
|
-
let Q4 = $3.toLowerCase().replace("0x", "").padStart(64, "0"), G2 = c$2.replace("0x", "") + Q4, Y2 = y$2("0x" + G2), Z3 = "ff", K3 = u$2.toLowerCase().replace("0x", ""),
|
|
15707
|
+
let Q4 = $3.toLowerCase().replace("0x", "").padStart(64, "0"), G2 = c$2.replace("0x", "") + Q4, Y2 = y$2("0x" + G2), Z3 = "ff", K3 = u$2.toLowerCase().replace("0x", ""), X4 = Y2.replace("0x", ""), q3 = l$.replace("0x", ""), M2 = "ff" + K3 + X4 + q3, N = "0x" + y$2("0x" + M2).slice(-40);
|
|
15708
15708
|
return L03(N);
|
|
15709
15709
|
}
|
|
15710
15710
|
generateSecrets($3) {
|
|
@@ -15735,12 +15735,12 @@ class IQ {
|
|
|
15735
15735
|
}
|
|
15736
15736
|
async generateInvites($3, J2) {
|
|
15737
15737
|
if (J2 <= 0)
|
|
15738
|
-
throw new
|
|
15738
|
+
throw new v3("Count must be greater than 0", { code: "INVITATION_INVALID_COUNT", source: "VALIDATION", context: { count: J2 } });
|
|
15739
15739
|
let Q4 = $3.toLowerCase(), G2 = J2 === 1, Y2 = await this.simulateClaim(Q4, J2);
|
|
15740
15740
|
if (!Y2.length)
|
|
15741
|
-
throw new
|
|
15742
|
-
let Z3 = this.invitations.generateSecrets(J2), K3 = Z3.map((j4) => j4.signer),
|
|
15743
|
-
return await Promise.all(Z3.map((j4) => this.invitations.saveReferralData(Q4, j4.secret))), { invites: Z3, transactions: [
|
|
15741
|
+
throw new v3("No invitation IDs returned from claim", { code: "INVITATION_NO_IDS", source: "INVITATIONS", context: { inviter: Q4, count: J2 } });
|
|
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);
|
|
15743
|
+
return await Promise.all(Z3.map((j4) => this.invitations.saveReferralData(Q4, j4.secret))), { invites: Z3, transactions: [q3, M2] };
|
|
15744
15744
|
}
|
|
15745
15745
|
async listReferrals($3, J2 = 10, Q4 = 0) {
|
|
15746
15746
|
return this.invitations.listReferrals($3, J2, Q4);
|