@gurge/sdk 0.3.27 → 0.3.28
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/common/src/crypto/BabyJubRN.cjs +1 -0
- package/common/src/crypto/BabyJubRN.d.ts +2 -0
- package/common/src/crypto/BabyJubRN.mjs +66 -0
- package/common/src/crypto/EddsaRN.cjs +1 -0
- package/common/src/crypto/EddsaRN.mjs +41 -0
- package/common/src/crypto/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +6 -12
- package/common/src/crypto/eddsa.cjs +1 -1
- package/common/src/crypto/eddsa.mjs +6 -12
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +6 -12
- package/common/src/crypto/preProcessing.cjs +1 -1
- package/common/src/crypto/preProcessing.mjs +13 -23
- package/common/src/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
- package/common/src/data-structures/Hinkal/handleAutoDepositBack.mjs +9 -9
- package/common/src/data-structures/Hinkal/hinkalClaimUtxo.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalClaimUtxo.mjs +6 -6
- package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.mjs +18 -18
- package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +17 -17
- package/common/src/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalPrivateWallet.mjs +13 -13
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.mjs +11 -11
- package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.mjs +14 -14
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +51 -51
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +51 -51
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.mjs +20 -20
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +19 -19
- package/common/src/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSwap.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +9 -9
- package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.d.ts +3 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +35 -46
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +33 -33
- package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.cjs +1 -1
- package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.mjs +1 -1
- package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs +1 -1
- package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs +26 -42
- package/common/src/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
- package/common/src/data-structures/crypto-keys/decodeUTXO.mjs +7 -7
- package/common/src/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/common/src/data-structures/crypto-keys/encryptDecryptUtxo.mjs +1 -1
- package/common/src/data-structures/utxo/Utxo.cjs +1 -1
- package/common/src/data-structures/utxo/Utxo.d.ts +0 -1
- package/common/src/data-structures/utxo/Utxo.mjs +6 -19
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +4 -3
- package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
- package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +43 -86
- package/common/src/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/common/src/functions/pre-transaction/outputUtxoProcessing.d.ts +2 -2
- package/common/src/functions/pre-transaction/outputUtxoProcessing.mjs +22 -28
- package/common/src/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
- package/common/src/functions/private-wallet/emporium.swap.helpers.mjs +14 -14
- package/common/src/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/common/src/functions/snarkjs/common.snarkjs.mjs +7 -7
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +60 -67
- package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.mjs +60 -60
- package/common/src/functions/snarkjs/verifyCommitmentValidationData.cjs +1 -1
- package/common/src/functions/snarkjs/verifyCommitmentValidationData.mjs +1 -1
- package/common/src/functions/utils/bigint-math.utils.cjs +1 -1
- package/common/src/functions/utils/bigint-math.utils.d.ts +2 -0
- package/common/src/functions/utils/bigint-math.utils.mjs +18 -1
- package/common/src/functions/utils/buildClaimableDepositPlan.cjs +1 -1
- package/common/src/functions/utils/buildClaimableDepositPlan.mjs +1 -1
- package/common/src/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
- package/common/src/functions/utils/getUtxosFromReceipt.utils.mjs +1 -1
- package/common/src/functions/utils/getUtxosFromReceiptSolana.cjs +1 -1
- package/common/src/functions/utils/getUtxosFromReceiptSolana.mjs +4 -4
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.mjs +3 -3
- package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +71 -122
- package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
- package/common/src/functions/web3/events/getShieldedBalance.mjs +64 -64
- package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +42 -42
- package/common/src/types/index.cjs +1 -1
- package/common/src/types/index.mjs +1 -1
- package/common/src/webworker/logError-D8yBaP96.js +2 -0
- package/common/src/webworker/package.json +1 -1
- package/common/src/webworker/performTaskWithWorker.cjs +1 -1
- package/common/src/webworker/performTaskWithWorker.mjs +17 -18
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.cjs +3 -4
- package/common/src/webworker/viteWorkerURL.constant.d.ts +0 -1
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -4
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/package.json +1 -1
- package/react-native/HinkalWebViewWorker.cjs +4 -76
- package/react-native/HinkalWebViewWorker.mjs +49 -152
- package/react-native/bridge/HinkalRNWorker.cjs +1 -1
- package/react-native/bridge/HinkalRNWorker.d.ts +0 -1
- package/react-native/bridge/HinkalRNWorker.mjs +11 -16
- package/react-native/shims/circomlibjs-hinkal-fork.js +2 -2
- package/react-native/shims/circomlibjs.js +2 -2
- package/react-native/workerCDNUrls.cjs +1 -1
- package/react-native/workerCDNUrls.d.ts +0 -1
- package/react-native/workerCDNUrls.mjs +2 -2
- package/sdk/package.json.cjs +1 -1
- package/sdk/package.json.mjs +1 -1
- package/common/src/crypto/rnCryptoBridge.cjs +0 -1
- package/common/src/crypto/rnCryptoBridge.d.ts +0 -8
- package/common/src/crypto/rnCryptoBridge.mjs +0 -10
- package/common/src/crypto/rnUtxoCrypto.cjs +0 -1
- package/common/src/crypto/rnUtxoCrypto.d.ts +0 -25
- package/common/src/crypto/rnUtxoCrypto.mjs +0 -74
- package/common/src/functions/utils/hinkalTiming.utils.cjs +0 -1
- package/common/src/functions/utils/hinkalTiming.utils.d.ts +0 -11
- package/common/src/functions/utils/hinkalTiming.utils.mjs +0 -21
- package/common/src/functions/utils/utxoPadding.utils.cjs +0 -1
- package/common/src/functions/utils/utxoPadding.utils.d.ts +0 -2
- package/common/src/functions/utils/utxoPadding.utils.mjs +0 -14
- package/common/src/webworker/cryptoWorker/cryptoWorker.types.cjs +0 -1
- package/common/src/webworker/cryptoWorker/cryptoWorker.types.d.ts +0 -51
- package/common/src/webworker/cryptoWorker/cryptoWorker.types.mjs +0 -6
- package/common/src/webworker/cryptoWorker/cryptoWorkerLauncher.d.ts +0 -1
- package/common/src/webworker/cryptoWorker/cryptoWorkerLogic.d.ts +0 -2
- package/common/src/webworker/logError-Dy_GXEF5.js +0 -2
- package/react-native/bridge/RnWebViewCryptoBridge.cjs +0 -1
- package/react-native/bridge/RnWebViewCryptoBridge.d.ts +0 -7
- package/react-native/bridge/RnWebViewCryptoBridge.mjs +0 -49
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
import { chainIds as e } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { poseidonFunction as t } from "../../crypto/poseidon.mjs";
|
|
3
3
|
import { randomBigInt as n } from "../web3/etherFunctions.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { encodeToByte32Array as
|
|
8
|
-
import { computeSignedMessageHashSolana as
|
|
4
|
+
import { formatMintAddress as r } from "../utils/solanaMint.utils.mjs";
|
|
5
|
+
import { takeOffHighestBit as i } from "../utils/bit.operations.mjs";
|
|
6
|
+
import { buildOutCommitments as a, calcAmountChanges as o, calcStealthAddressStructure as s, getUtxoCircuitH0Coords as c, getUtxoCircuitInRandomization as l } from "./common.snarkjs.mjs";
|
|
7
|
+
import { encodeToByte32Array as u } from "../pre-transaction/solana.mjs";
|
|
8
|
+
import { computeSignedMessageHashSolana as d } from "./signedMessageHash.mjs";
|
|
9
9
|
import "../pre-transaction/index.mjs";
|
|
10
|
-
import { generateMainAndCommitmentZkProof as
|
|
10
|
+
import { generateMainAndCommitmentZkProof as f } from "./generateMainAndCommitmentZkProof.mjs";
|
|
11
11
|
import "../utils/index.mjs";
|
|
12
|
-
import { getDataFromWorkers as
|
|
13
|
-
import { getSolanaCalldataHash as
|
|
12
|
+
import { getDataFromWorkers as p } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
13
|
+
import { getSolanaCalldataHash as m } from "../pre-transaction/getSolanaCalldataHash.mjs";
|
|
14
14
|
import "../web3/index.mjs";
|
|
15
|
-
import { PublicKey as
|
|
15
|
+
import { PublicKey as h } from "@solana/web3.js";
|
|
16
16
|
//#region libs/shared/common/src/functions/snarkjs/constructSolanaZkProof.ts
|
|
17
|
-
var
|
|
18
|
-
let
|
|
19
|
-
rootHashHinkal:
|
|
20
|
-
mintAccountPart1:
|
|
21
|
-
mintAccountPart2:
|
|
22
|
-
amountChanges:
|
|
23
|
-
outTimeStamp: BigInt(
|
|
24
|
-
inNullifiers:
|
|
25
|
-
outCommitments:
|
|
26
|
-
calldataHash:
|
|
27
|
-
message:
|
|
28
|
-
swapperAccountAdditionalSeed:
|
|
29
|
-
outH1Ay:
|
|
30
|
-
H0Ax:
|
|
31
|
-
H0Ay:
|
|
32
|
-
}), { R8:
|
|
33
|
-
rootHashHinkal:
|
|
34
|
-
spendingPublicKey:
|
|
17
|
+
var g = async (g, _, v, y, b, x, S, C, w, T, E, D, ee, O = e.solanaLocalnet, k = [], A = [], j = 0n) => {
|
|
18
|
+
let M = new h(T), N = new h(E), P = v.getShieldedPrivateKey(), { pubSpendingBJJPoint: F } = v.getSpendingKeyPair(), I = s(S, P, v.getSpendingKeyPair().pubSpendingBJJPoint), L = n(31), R = t(L), z = t(j), B = y.map((e) => r(e)), V = B.map((e) => e.mintAccountPart1), H = B.map((e) => e.mintAccountPart2), U = m(D, M, N, ee, C, w, k, A), te = `${D.tokenNumber}x${D.nullifierAmount}x${D.outputAmount}`, W = o(b, x), { inCommitmentSiblings: G, inCommitmentSiblingSides: K, rootHashHinkal: q, inNullifiers: J } = await p(O, _, b.map((e) => e.map((e) => e.getConstructableParams()))), Y = a(x), X = i(I.extraRandomization), Z = I.H0, Q = d({
|
|
19
|
+
rootHashHinkal: q,
|
|
20
|
+
mintAccountPart1: V,
|
|
21
|
+
mintAccountPart2: H,
|
|
22
|
+
amountChanges: W,
|
|
23
|
+
outTimeStamp: BigInt(x[0][0].timeStamp),
|
|
24
|
+
inNullifiers: J,
|
|
25
|
+
outCommitments: Y,
|
|
26
|
+
calldataHash: U,
|
|
27
|
+
message: R,
|
|
28
|
+
swapperAccountAdditionalSeed: z,
|
|
29
|
+
outH1Ay: I.H1,
|
|
30
|
+
H0Ax: X,
|
|
31
|
+
H0Ay: Z
|
|
32
|
+
}), { R8: $, S: ne } = v.signEddsa(Q), re = {
|
|
33
|
+
rootHashHinkal: q,
|
|
34
|
+
spendingPublicKey: F,
|
|
35
35
|
eddsaSignature: [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
$[0],
|
|
37
|
+
$[1],
|
|
38
|
+
ne
|
|
39
39
|
],
|
|
40
|
-
signedMessageHash:
|
|
41
|
-
nullifyingPrivateKey:
|
|
42
|
-
mintAccountPart1:
|
|
43
|
-
mintAccountPart2:
|
|
44
|
-
amountChanges:
|
|
45
|
-
inAmounts:
|
|
46
|
-
inRandomizations:
|
|
47
|
-
inH0Ax:
|
|
48
|
-
inH0Ay:
|
|
49
|
-
isNewStyle:
|
|
50
|
-
inTimeStamps:
|
|
51
|
-
inNullifiers:
|
|
52
|
-
inCommitmentSiblings:
|
|
53
|
-
inCommitmentSiblingSides:
|
|
54
|
-
outAmounts:
|
|
55
|
-
outTimeStamp: BigInt(
|
|
56
|
-
outPublicKeys:
|
|
57
|
-
outCommitments:
|
|
58
|
-
calldataHash:
|
|
59
|
-
messageSeed:
|
|
60
|
-
swapperAccountSalt:
|
|
61
|
-
H0Ax:
|
|
62
|
-
H0Ay:
|
|
63
|
-
}, { zkCallData:
|
|
40
|
+
signedMessageHash: Q,
|
|
41
|
+
nullifyingPrivateKey: P,
|
|
42
|
+
mintAccountPart1: V,
|
|
43
|
+
mintAccountPart2: H,
|
|
44
|
+
amountChanges: W,
|
|
45
|
+
inAmounts: b.map((e) => e.map((e) => e.amount.toString())),
|
|
46
|
+
inRandomizations: b.map((e) => e.map((e) => l(e))),
|
|
47
|
+
inH0Ax: b.map((e) => e.map((e) => c(e)[0].toString())),
|
|
48
|
+
inH0Ay: b.map((e) => e.map((e) => c(e)[1].toString())),
|
|
49
|
+
isNewStyle: b.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
50
|
+
inTimeStamps: b.map((e) => e.map((e) => e.timeStamp)),
|
|
51
|
+
inNullifiers: J,
|
|
52
|
+
inCommitmentSiblings: G,
|
|
53
|
+
inCommitmentSiblingSides: K,
|
|
54
|
+
outAmounts: x.map((e) => e.map((e) => e.amount.toString())),
|
|
55
|
+
outTimeStamp: BigInt(x[0][0].timeStamp),
|
|
56
|
+
outPublicKeys: x.map((e) => e.map((e) => e.getStealthAddress())),
|
|
57
|
+
outCommitments: Y,
|
|
58
|
+
calldataHash: U,
|
|
59
|
+
messageSeed: L,
|
|
60
|
+
swapperAccountSalt: j,
|
|
61
|
+
H0Ax: X,
|
|
62
|
+
H0Ay: Z
|
|
63
|
+
}, { zkCallData: ie, publicSignals: ae, commitmentValidationData: oe } = await f(O, v, y, b, `mainSolanaCircuit${te}`, re, g), [se, ce, le] = ie;
|
|
64
64
|
return {
|
|
65
|
-
proofAArr: se.map(BigInt).map(
|
|
66
|
-
proofBArr: ce.flat().map(BigInt).map(
|
|
67
|
-
proofCArr: le.map(BigInt).map(
|
|
68
|
-
publicInputsArr:
|
|
69
|
-
commitmentValidationData:
|
|
65
|
+
proofAArr: se.map(BigInt).map(u).flat(),
|
|
66
|
+
proofBArr: ce.flat().map(BigInt).map(u).flat(),
|
|
67
|
+
proofCArr: le.map(BigInt).map(u).flat(),
|
|
68
|
+
publicInputsArr: ae.map(BigInt).map(u),
|
|
69
|
+
commitmentValidationData: oe
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
72
|
//#endregion
|
|
73
|
-
export {
|
|
73
|
+
export { g as constructSolanaZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`),require(
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`../../data-structures/http/HttpClient.cjs`),require(`./common.snarkjs.cjs`),require(`../utils/bytes32.utils.cjs`),require(`./getZKFiles.cjs`),require(`ethers`),require(`snarkjs`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../constants/protocol.constants.cjs`);
|
|
1
|
+
const e=require(`../../constants/protocol.constants.cjs`);var t=(t,n=e.CIRCOM_P)=>{let r=t%n;return r>=0n?r:r+n},n=(n,r=e.CIRCOM_P)=>{let i=1n,a=0n,o=t(n,r),s=r;if(o===0n)throw Error(`Division by zero`);for(;o>1n;){let e=s%o,t=s/o;s=o,o=e;let n=a-i*t;a=i,i=n}return i<0n?i+r:i};exports.mod=t,exports.modInverse=n;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare const mod: (value: bigint, m?: bigint) => bigint;
|
|
2
2
|
export declare const modpow: (b: bigint, e: bigint, m: bigint) => bigint;
|
|
3
|
+
/** Modular inverse via extended Euclidean algorithm (much faster than Fermat modpow on RN). */
|
|
4
|
+
export declare const modInverse: (value: bigint, m?: bigint) => bigint;
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
import "../../constants/protocol.constants.mjs";
|
|
1
|
+
import { CIRCOM_P as e } from "../../constants/protocol.constants.mjs";
|
|
2
|
+
//#region libs/shared/common/src/functions/utils/bigint-math.utils.ts
|
|
3
|
+
var t = (t, n = e) => {
|
|
4
|
+
let r = t % n;
|
|
5
|
+
return r >= 0n ? r : r + n;
|
|
6
|
+
}, n = (n, r = e) => {
|
|
7
|
+
let i = 1n, a = 0n, o = t(n, r), s = r;
|
|
8
|
+
if (o === 0n) throw Error("Division by zero");
|
|
9
|
+
for (; o > 1n;) {
|
|
10
|
+
let e = s % o, t = s / o;
|
|
11
|
+
s = o, o = e;
|
|
12
|
+
let n = a - i * t;
|
|
13
|
+
a = i, i = n;
|
|
14
|
+
}
|
|
15
|
+
return i < 0n ? i + r : i;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { t as mod, n as modInverse };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../web3/etherFunctions.cjs`),require(`../../data-structures/crypto-keys/keys.cjs`),require(
|
|
1
|
+
require(`../web3/etherFunctions.cjs`),require(`../../data-structures/crypto-keys/keys.cjs`),require(`../../data-structures/utxo/Utxo.cjs`),require(`./addresses.cjs`),require(`../snarkjs/common.snarkjs.cjs`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`./amounts.utils.cjs`);require(`../../data-structures/crypto-keys/keys.cjs`)
|
|
1
|
+
require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`./amounts.utils.cjs`);require(`../../data-structures/crypto-keys/keys.cjs`);const n=require(`../../types/ethereum-network.types.cjs`);require(`../../types/index.cjs`),require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const r=require(`../../data-structures/crypto-keys/decodeUTXO.cjs`),i=require(`./getContractAddress.cjs`);require(`ethers`);var a=(a,o,s,c)=>{let l=o.getContractWithFetcher(s,n.ContractType.HinkalContract),u=l.interface,d=o.userKeys.getShieldedPrivateKey(),f=i.getContractAddress(l);return a.logs.filter(t=>e.caseInsensitiveEqual(t.address,f)).map(n=>{try{let i=u.parseLog(n);if(i?.name===`NewCommitment`){let{encryptedOutput:n,index:a}=i.args;if(t.toBigInt(a)<0n){let t=r.decodeUtxo(n,d,s);if(e.caseInsensitiveEqual(t.erc20TokenAddress,c))return t}}}catch{return null}return null}).filter(e=>e!==null)};exports.getOnChainUtxosFromReceipt=a;
|
|
@@ -2,9 +2,9 @@ import "../../constants/chains.constants.mjs";
|
|
|
2
2
|
import { caseInsensitiveEqual as e } from "./caseInsensitive.utils.mjs";
|
|
3
3
|
import { toBigInt as t } from "./amounts.utils.mjs";
|
|
4
4
|
import "../../data-structures/crypto-keys/keys.mjs";
|
|
5
|
-
import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
|
|
6
5
|
import { ContractType as n } from "../../types/ethereum-network.types.mjs";
|
|
7
6
|
import "../../types/index.mjs";
|
|
7
|
+
import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
|
|
8
8
|
import { decodeUtxo as r } from "../../data-structures/crypto-keys/decodeUTXO.mjs";
|
|
9
9
|
import { getContractAddress as i } from "./getContractAddress.mjs";
|
|
10
10
|
import "ethers";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`../../crypto/poseidon.cjs`);require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`../../crypto/poseidon.cjs`),n=require(`../../data-structures/utxo/Utxo.cjs`);require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const r=require(`./bit.operations.cjs`),i=require(`./bytes32.utils.cjs`);let a=require(`ethers`),o=require(`@solana/web3.js`),s=require(`@coral-xyz/anchor`);var c=(c,l,u,d)=>[...new s.EventParser(l.programId,new s.BorshCoder(l.idl)).parseLogs(c.meta?.logMessages??[])].filter(({name:t})=>e.caseInsensitiveEqual(t,`newCommitment`)).filter(({data:e})=>e.encryptedOutput.length===0).map(e=>{let{onChainData:s}=e.data,[c,l,d,f,p,m,,h]=s.map(i.convertBytes32ToBigInt),[,g,_]=s,v=new o.PublicKey([...g.slice(16),..._.slice(16)]),y=t.poseidonHash(l,d),b=r.extractHighestBit(f)===1n,x=new n.Utxo({amount:c,timeStamp:h.toString(),nullifyingKey:u.getShieldedPrivateKey(),mintAddress:v.toBase58(),erc20TokenAddress:y,stealthAddress:a.ethers.toBeHex(p),isNewStyle:b,...b?{H0:[r.takeOffHighestBit(f),m]}:{randomization:f}});return x.getStealthAddress(),x}).filter(t=>e.caseInsensitiveEqual(t.erc20TokenAddress,d));exports.getOnChainUtxosFromReceiptSolana=c;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "../../constants/chains.constants.mjs";
|
|
2
2
|
import { caseInsensitiveEqual as e } from "./caseInsensitive.utils.mjs";
|
|
3
3
|
import { poseidonHash as t } from "../../crypto/poseidon.mjs";
|
|
4
|
+
import { Utxo as n } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
5
|
import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
|
|
5
|
-
import { extractHighestBit as
|
|
6
|
-
import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
|
|
6
|
+
import { extractHighestBit as r, takeOffHighestBit as i } from "./bit.operations.mjs";
|
|
7
7
|
import { convertBytes32ToBigInt as a } from "./bytes32.utils.mjs";
|
|
8
8
|
import { ethers as o } from "ethers";
|
|
9
9
|
import { PublicKey as s } from "@solana/web3.js";
|
|
10
10
|
import { BorshCoder as c, EventParser as l } from "@coral-xyz/anchor";
|
|
11
11
|
//#region libs/shared/common/src/functions/utils/getUtxosFromReceiptSolana.ts
|
|
12
12
|
var u = (u, d, f, p) => [...new l(d.programId, new c(d.idl)).parseLogs(u.meta?.logMessages ?? [])].filter(({ name: t }) => e(t, "newCommitment")).filter(({ data: e }) => e.encryptedOutput.length === 0).map((e) => {
|
|
13
|
-
let { onChainData: c } = e.data, [l, u, d, p, m, h, , g] = c.map(a), [, _, v] = c, y = new s([..._.slice(16), ...v.slice(16)]), b = t(u, d), x =
|
|
13
|
+
let { onChainData: c } = e.data, [l, u, d, p, m, h, , g] = c.map(a), [, _, v] = c, y = new s([..._.slice(16), ...v.slice(16)]), b = t(u, d), x = r(p) === 1n, S = new n({
|
|
14
14
|
amount: l,
|
|
15
15
|
timeStamp: g.toString(),
|
|
16
16
|
nullifyingKey: f.getShieldedPrivateKey(),
|
|
@@ -18,7 +18,7 @@ var u = (u, d, f, p) => [...new l(d.programId, new c(d.idl)).parseLogs(u.meta?.l
|
|
|
18
18
|
erc20TokenAddress: b,
|
|
19
19
|
stealthAddress: o.toBeHex(m),
|
|
20
20
|
isNewStyle: x,
|
|
21
|
-
...x ? { H0: [
|
|
21
|
+
...x ? { H0: [i(p), h] } : { randomization: p }
|
|
22
22
|
});
|
|
23
23
|
return S.getStealthAddress(), S;
|
|
24
24
|
}).filter((t) => e(t.erc20TokenAddress, p));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.utils.cjs`),require(`./
|
|
1
|
+
require(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.utils.cjs`),require(`./bigint-math.utils.cjs`),require(`./time.utils.cjs`),require(`./upToDateState.cjs`),require(`./cacheFunctions.cjs`),require(`./enclaveHandshakeService.cjs`),require(`./encryptInputForEnclave.cjs`),require(`./solanaMint.utils.cjs`),require(`./customEnclaveFunctionsRegister.cjs`),require(`./addresses.cjs`),require(`./tron.utils.cjs`),require(`./get-signature-header.cjs`),require(`./auth.utils.cjs`),require(`./string.utils.cjs`),require(`./token-check.utils.cjs`),require(`./map.utils.cjs`),require(`./mutexes.utils.cjs`),require(`./erc20tokenFunctions.cjs`),require(`../pre-transaction/outputUtxoProcessing.cjs`),require(`./external-action.utils.cjs`),require(`./bit.operations.cjs`),require(`../pre-transaction/solana.cjs`),require(`../pre-transaction/process-gas-estimates.cjs`),require(`../pre-transaction/getVolatileTransferAmount.cjs`),require(`../pre-transaction/constructAdminData.cjs`),require(`./create-provider.cjs`),require(`../pre-transaction/convert-okx-instructions.cjs`),require(`./process.utils.cjs`),require(`../pre-transaction/sendV0Transaction.cjs`),require(`./bytes32.utils.cjs`),require(`../pre-transaction/recipientUtxoProcessing.cjs`),require(`../pre-transaction/ensureAmountChanges.cjs`),require(`../pre-transaction/getFeeStructure.cjs`),require(`../pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),require(`../pre-transaction/buildCommitmentValidationData.cjs`),require(`../pre-transaction/index.cjs`),require(`./serialize-utxos.utils.cjs`),require(`./resolve-sync.utils.cjs`),require(`./convertIntegrationProviderToExternalActionId.cjs`),require(`./evmNetworkFunctions.cjs`),require(`./userAgent.cjs`),require(`./reloadPage.cjs`),require(`./cacheDevice.utils.cjs`),require(`./getBlockExplorerUrl.cjs`),require(`./involves-permit2-op.cjs`),require(`./convertEmporiumOpToCallInfo.cjs`),require(`./getRecipientInfoFromUserKeys.cjs`),require(`./publicBalance.utils.cjs`),require(`./rpc-int-encode.cjs`),require(`./walletBalances.utils.cjs`),require(`./nftTokenFunctions.cjs`),require(`./inLogicMetadata.cjs`),require(`./networks.utils.cjs`),require(`./postToOffscreen.cjs`),require(`./solanaSendPreflight.utils.cjs`),require(`./prepareHinkal.cjs`),require(`./getContractAddress.cjs`),require(`./getUtxosFromReceipt.utils.cjs`),require(`./getUtxosFromReceiptSolana.cjs`),require(`./fees.utils.cjs`),require(`./enclave-utxo-storage.cjs`),require(`./enclave-signature-storage.cjs`),require(`./tx-confirmation.utils.cjs`),require(`./buildClaimableDepositPlan.cjs`),require(`./formatter.cjs`),require(`./tronSimulation.utils.cjs`),require(`./getSignerFromContract.cjs`),require(`./deposit-claimable.utils.cjs`),require(`./transfer-claimable.utils.cjs`),require(`./dispatchBalanceRefreshes.cjs`),require(`./lifi.utils.cjs`),require(`./enclave-recipient-info-storage.cjs`),require(`./solana-memo.cjs`),require(`./mnemonics.cjs`),require(`./nearIntents.utils.cjs`);
|
|
@@ -2,8 +2,7 @@ import "./abi.utils.mjs";
|
|
|
2
2
|
import "./serialize.utils.mjs";
|
|
3
3
|
import "./caseInsensitive.utils.mjs";
|
|
4
4
|
import "./amounts.utils.mjs";
|
|
5
|
-
import "./
|
|
6
|
-
import "./bit.operations.mjs";
|
|
5
|
+
import "./bigint-math.utils.mjs";
|
|
7
6
|
import "./time.utils.mjs";
|
|
8
7
|
import "./upToDateState.mjs";
|
|
9
8
|
import "./cacheFunctions.mjs";
|
|
@@ -21,6 +20,8 @@ import "./map.utils.mjs";
|
|
|
21
20
|
import "./mutexes.utils.mjs";
|
|
22
21
|
import "./erc20tokenFunctions.mjs";
|
|
23
22
|
import "../pre-transaction/outputUtxoProcessing.mjs";
|
|
23
|
+
import "./external-action.utils.mjs";
|
|
24
|
+
import "./bit.operations.mjs";
|
|
24
25
|
import "../pre-transaction/solana.mjs";
|
|
25
26
|
import "../pre-transaction/process-gas-estimates.mjs";
|
|
26
27
|
import "../pre-transaction/getVolatileTransferAmount.mjs";
|
|
@@ -37,7 +38,6 @@ import "../pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
|
|
|
37
38
|
import "../pre-transaction/buildCommitmentValidationData.mjs";
|
|
38
39
|
import "../pre-transaction/index.mjs";
|
|
39
40
|
import "./serialize-utxos.utils.mjs";
|
|
40
|
-
import "./bigint-math.utils.mjs";
|
|
41
41
|
import "./resolve-sync.utils.mjs";
|
|
42
42
|
import "./convertIntegrationProviderToExternalActionId.mjs";
|
|
43
43
|
import "./evmNetworkFunctions.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../
|
|
1
|
+
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/upToDateState.cjs`),i=require(`../../utils/cacheFunctions.cjs`),a=require(`../../utils/encodeTokenWithId.cjs`),o=require(`../../utils/solanaMint.utils.cjs`),s=require(`./getInputUtxosEnclave.cjs`),c=require(`../../utils/addresses.cjs`),l=require(`../../../API/scheduled-transactions-calls.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t)=>e.allowParallelBalanceLocalDecryption?t():d.runExclusive(t),p=async(e,t,n,a,o,s,c,l,u)=>f(e,async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await r.checkAddressNotUpdated(e,a),i.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,o),await e.utxoUtils.buildBatchProcess(m,t,n)}),m=async(e,t,n,r)=>{let{utxos:a,encryptedOutputs:o,lastOutput:c}=await s.getInputUtxosEnclave(e,n,t);return i.setHinkalCache({encryptedOutputs:o,lastOutput:c},e,n,r),a},h=async(e,t,n,r,i,a,o,s,c)=>{try{return await m(e,t,n,i)}catch{return p(e,t,n,r,i,a,o,s,c)}},g=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},_=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),v=(e,t,r,i,a,o,s,c)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new n.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0})),r)for(;e.length>6;)e.splice(e.length-1)},y=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=a??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,f=e.encryptedOutputsByChain[t],m=e.nullifiersByChain[t],g=Array.from(f);o&&i.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=i.getHinkalCache(e,t,u);await r.checkAddressNotUpdated(e,l);let b=y!==``,x=g.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1,w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E,O=[];T?O=await p(e,d,t,l,u,g,v,y,x):E?O=await h(e,d,t,l,u,g,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),await r.checkAddressNotUpdated(e,l);let k=await _(e,O,m);return{inputUtxos:c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked)}},b=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1,allowRemoteDecryption:o=!1})=>{let s=i??await t.getEthereumAddressByChain(n),d=c.hashEthereumAddress(e.isTronLike(n)?u.addressToHexFormat(s):s),{inputUtxos:f}=await y({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:s,resetCacheBefore:a,allowRemoteDecryption:o,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await l.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},x=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:s=!0,chainId:c,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,allowRemoteDecryption:m=!1,useBlockedUtxos:h=!1})=>{let _=l??n.userKeys.getShieldedPrivateKey(),x=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=h?await b({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await y({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=g(r),w=new Map;S.forEach(e=>{let n=e.getTokenAddress(c);if(C&&!C.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=a.encodeTokenWithId(c,{erc20TokenAddress:n,tokenId:0}),i=w.get(r)??[];w.set(r,[...i,e])}),p?.forEach(e=>{let t=a.encodeTokenWithId(c,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});w.set(t,w.get(t)??[])});for(let[t,n]of w){let r=t.split(`-`)[0],a=Number(t.split(`-`)[1]),l=e.isSolanaLike(c),u=l?r:void 0;v(n,i,s,_,x,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=h,exports.getInputUtxoAndBalance=y,exports.getInputUtxoAndBalanceOfStuckUtxos=b,exports.getInputUtxoAndBalancePerToken=x,exports.getInputUtxosRemotely=m;
|
|
@@ -1,109 +1,58 @@
|
|
|
1
1
|
import { isSolanaLike as e, isTronLike as t } from "../../../constants/chains.constants.mjs";
|
|
2
2
|
import { caseInsensitiveEqual as n } from "../../utils/caseInsensitive.utils.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { createRnDeltaTiming as h } from "../../utils/hinkalTiming.utils.mjs";
|
|
14
|
-
import { Mutex as g } from "async-mutex";
|
|
3
|
+
import { Utxo as r } from "../../../data-structures/utxo/Utxo.mjs";
|
|
4
|
+
import { checkAddressNotUpdated as i } from "../../utils/upToDateState.mjs";
|
|
5
|
+
import { getHinkalCache as a, resetCache as o, setHinkalCache as s } from "../../utils/cacheFunctions.mjs";
|
|
6
|
+
import { encodeTokenWithId as c } from "../../utils/encodeTokenWithId.mjs";
|
|
7
|
+
import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
|
|
8
|
+
import { getInputUtxosEnclave as u } from "./getInputUtxosEnclave.mjs";
|
|
9
|
+
import { hashEthereumAddress as d } from "../../utils/addresses.mjs";
|
|
10
|
+
import { getScheduledTransactionsNullifierIndexes as f } from "../../../API/scheduled-transactions-calls.mjs";
|
|
11
|
+
import { addressToHexFormat as p } from "../../utils/tron.utils.mjs";
|
|
12
|
+
import { Mutex as m } from "async-mutex";
|
|
15
13
|
//#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
|
|
16
|
-
var
|
|
17
|
-
if (e.allowParallelBalanceLocalDecryption) return t();
|
|
18
|
-
let n = h("utxoPrep.mutex");
|
|
19
|
-
return _.isLocked() && n.log("waiting-for-lock"), _.runExclusive(async () => {
|
|
20
|
-
n.log("lock-acquired");
|
|
21
|
-
try {
|
|
22
|
-
return await t();
|
|
23
|
-
} finally {
|
|
24
|
-
n.log("lock-released");
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}, y = async (e, t, n, r, i, o, s, l, u) => v(e, async () => {
|
|
28
|
-
let d = h("utxoPrep.decrypt");
|
|
14
|
+
var h = new m(), g = async (e, t) => e.allowParallelBalanceLocalDecryption ? t() : h.runExclusive(t), _ = async (e, t, n, r, a, o, c, l, u) => g(e, async () => {
|
|
29
15
|
u += 1;
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
await a(e, r), _.log("during-decrypt"), c({
|
|
39
|
-
lastOutput: p,
|
|
40
|
-
encryptedOutputs: g
|
|
41
|
-
}, e, n, i), d.log("cache-write", { encryptedOutputs: g.length });
|
|
42
|
-
let v = await e.utxoUtils.buildBatchProcess(g, t, n);
|
|
43
|
-
return d.log("buildBatchProcess-done", { utxoCount: v.length }), v;
|
|
44
|
-
}), b = async (e, t, n, r) => {
|
|
45
|
-
let { utxos: i, encryptedOutputs: a, lastOutput: o } = await d(e, n, t);
|
|
46
|
-
return c({
|
|
16
|
+
let d = o.slice(u), { lastOutput: f, additionalEncryptedOutputs: p } = await e.utxoUtils.batchProcess(d, l, t, n), m = [...c, ...p];
|
|
17
|
+
return await i(e, r), s({
|
|
18
|
+
lastOutput: f,
|
|
19
|
+
encryptedOutputs: m
|
|
20
|
+
}, e, n, a), await e.utxoUtils.buildBatchProcess(m, t, n);
|
|
21
|
+
}), v = async (e, t, n, r) => {
|
|
22
|
+
let { utxos: i, encryptedOutputs: a, lastOutput: o } = await u(e, n, t);
|
|
23
|
+
return s({
|
|
47
24
|
encryptedOutputs: a,
|
|
48
25
|
lastOutput: o
|
|
49
26
|
}, e, n, r), i;
|
|
50
|
-
},
|
|
27
|
+
}, y = async (e, t, n, r, i, a, o, s, c) => {
|
|
51
28
|
try {
|
|
52
|
-
return await
|
|
29
|
+
return await v(e, t, n, i);
|
|
53
30
|
} catch {
|
|
54
|
-
return
|
|
31
|
+
return _(e, t, n, r, i, a, o, s, c);
|
|
55
32
|
}
|
|
56
|
-
},
|
|
33
|
+
}, b = (e) => {
|
|
57
34
|
if (Array.isArray(e)) return e;
|
|
58
35
|
if (e !== void 0) return [e];
|
|
59
|
-
},
|
|
60
|
-
for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
let
|
|
79
|
-
u.log("cache.read", { cachedEncryptedOutputs: v.length });
|
|
80
|
-
let S = h("wallet.checkAddress");
|
|
81
|
-
await a(e, d), S.log("before-decrypt");
|
|
82
|
-
let w = b !== "", T = _.findIndex((e) => e.value === b);
|
|
83
|
-
u.log("findLastOutputIndex", {
|
|
84
|
-
hinkalOutputs: _.length,
|
|
85
|
-
lastOutputIndex: T
|
|
86
|
-
});
|
|
87
|
-
let E = T > -1, D = !w && T === -1, O = e.areMerkleTreeUpdatesDisabled(), k = !O && (E || !c && D), A = !O && c && D, j = !k && !A;
|
|
88
|
-
u.log("branch", {
|
|
89
|
-
decryptLocally: k,
|
|
90
|
-
decryptRemotely: A,
|
|
91
|
-
useCache: j,
|
|
92
|
-
outputsSlice: T > -1 ? _.length - (T + 1) : 0
|
|
93
|
-
});
|
|
94
|
-
let M = [];
|
|
95
|
-
k ? (M = await y(e, p, t, d, f, _, v, b, T), u.log("decryptLocally-done", { utxoCount: M.length })) : A ? (M = await x(e, p, t, d, f, _, v, b, T), u.log("decryptRemotely-done", { utxoCount: M.length })) : j && (M = await e.utxoUtils.buildBatchProcess(v, p, t), u.log("useCache-buildBatchProcess-done", { utxoCount: M.length }));
|
|
96
|
-
let N = h("wallet.checkAddress");
|
|
97
|
-
await a(e, d), N.log("after-decrypt");
|
|
98
|
-
let P = await C(e, M, g);
|
|
99
|
-
u.log("filterSpentUtxos", {
|
|
100
|
-
allUtxos: M.length,
|
|
101
|
-
inputUtxos: P.length
|
|
102
|
-
});
|
|
103
|
-
let F = l ? P.filter((e) => e.isBlocked) : P.filter((e) => !e.isBlocked);
|
|
104
|
-
return u.log("done", { inputUtxos: F.length }), { inputUtxos: F };
|
|
105
|
-
}, E = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
|
|
106
|
-
let s = i ?? await e.getEthereumAddressByChain(n), c = f(t(n) ? m(s) : s), { inputUtxos: l } = await T({
|
|
36
|
+
}, x = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), S = (e, t, n, i, a, o, s, c) => {
|
|
37
|
+
for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) if (e.push(new r({
|
|
38
|
+
amount: 0n,
|
|
39
|
+
erc20TokenAddress: o,
|
|
40
|
+
mintAddress: c,
|
|
41
|
+
nullifyingKey: i,
|
|
42
|
+
spendingPublicKey: a,
|
|
43
|
+
isNewStyle: !0
|
|
44
|
+
})), n) for (; e.length > 6;) e.splice(e.length - 1);
|
|
45
|
+
}, C = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
|
|
46
|
+
let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: f } = e, p = e.encryptedOutputsByChain[t], m = e.nullifiersByChain[t], h = Array.from(p);
|
|
47
|
+
s && o(e, t, d);
|
|
48
|
+
let { encryptedOutputs: g, lastOutput: v } = a(e, t, d);
|
|
49
|
+
await i(e, u);
|
|
50
|
+
let b = v !== "", S = h.findIndex((e) => e.value === v), C = S > -1, w = !b && S === -1, T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !c && w), D = !T && c && w, O = !E && !D, k = [];
|
|
51
|
+
E ? k = await _(e, f, t, u, d, h, g, v, S) : D ? k = await y(e, f, t, u, d, h, g, v, S) : O && (k = await e.utxoUtils.buildBatchProcess(g, f, t)), await i(e, u);
|
|
52
|
+
let A = await x(e, k, m);
|
|
53
|
+
return { inputUtxos: l ? A.filter((e) => e.isBlocked) : A.filter((e) => !e.isBlocked) };
|
|
54
|
+
}, w = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
|
|
55
|
+
let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await C({
|
|
107
56
|
hinkal: e,
|
|
108
57
|
chainId: n,
|
|
109
58
|
passedShieldedPublicKey: r,
|
|
@@ -113,51 +62,51 @@ var _ = new g(), v = async (e, t) => {
|
|
|
113
62
|
useBlockedUtxos: !0
|
|
114
63
|
});
|
|
115
64
|
if (!l.length) return { inputUtxos: [] };
|
|
116
|
-
let { indexes: u } = await
|
|
65
|
+
let { indexes: u } = await f({
|
|
117
66
|
hashedEthereumAddress: c,
|
|
118
67
|
nullifiers: l.map((e) => e.getNullifier())
|
|
119
68
|
});
|
|
120
69
|
return { inputUtxos: u.map((e) => l[e]).filter((e) => !!e) };
|
|
121
|
-
},
|
|
122
|
-
let
|
|
70
|
+
}, T = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: u = void 0, ethAddress: d = void 0, resetCacheBefore: f = !1, ensuredTokensWithId: p, allowRemoteDecryption: m = !1, useBlockedUtxos: h = !1 }) => {
|
|
71
|
+
let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await w({
|
|
123
72
|
hinkal: t,
|
|
124
|
-
chainId:
|
|
125
|
-
ethAddress:
|
|
126
|
-
passedShieldedPrivateKey:
|
|
127
|
-
resetCacheBefore:
|
|
128
|
-
allowRemoteDecryption:
|
|
129
|
-
}) : await
|
|
73
|
+
chainId: o,
|
|
74
|
+
ethAddress: d,
|
|
75
|
+
passedShieldedPrivateKey: s,
|
|
76
|
+
resetCacheBefore: f,
|
|
77
|
+
allowRemoteDecryption: m
|
|
78
|
+
}) : await C({
|
|
130
79
|
hinkal: t,
|
|
131
|
-
tokenWithId:
|
|
132
|
-
minInput:
|
|
133
|
-
sliceIfMore6:
|
|
134
|
-
chainId:
|
|
135
|
-
passedShieldedPrivateKey:
|
|
136
|
-
passedShieldedPublicKey:
|
|
137
|
-
ethAddress:
|
|
138
|
-
resetCacheBefore:
|
|
139
|
-
allowRemoteDecryption:
|
|
140
|
-
}),
|
|
141
|
-
|
|
142
|
-
let t = e.getTokenAddress(
|
|
143
|
-
if (
|
|
144
|
-
let r =
|
|
80
|
+
tokenWithId: r,
|
|
81
|
+
minInput: i,
|
|
82
|
+
sliceIfMore6: a,
|
|
83
|
+
chainId: o,
|
|
84
|
+
passedShieldedPrivateKey: s,
|
|
85
|
+
passedShieldedPublicKey: u,
|
|
86
|
+
ethAddress: d,
|
|
87
|
+
resetCacheBefore: f,
|
|
88
|
+
allowRemoteDecryption: m
|
|
89
|
+
}), y = b(r), x = /* @__PURE__ */ new Map();
|
|
90
|
+
v.forEach((e) => {
|
|
91
|
+
let t = e.getTokenAddress(o);
|
|
92
|
+
if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
|
|
93
|
+
let r = c(o, {
|
|
145
94
|
erc20TokenAddress: t,
|
|
146
95
|
tokenId: 0
|
|
147
96
|
}), i = x.get(r) ?? [];
|
|
148
97
|
x.set(r, [...i, e]);
|
|
149
|
-
}),
|
|
150
|
-
let t =
|
|
98
|
+
}), p?.forEach((e) => {
|
|
99
|
+
let t = c(o, {
|
|
151
100
|
erc20TokenAddress: e.erc20TokenAddress,
|
|
152
101
|
tokenId: 0
|
|
153
102
|
});
|
|
154
103
|
x.set(t, x.get(t) ?? []);
|
|
155
104
|
});
|
|
156
105
|
for (let [t, n] of x) {
|
|
157
|
-
let r = t.split("-")[0],
|
|
158
|
-
|
|
106
|
+
let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
|
|
107
|
+
S(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
|
|
159
108
|
}
|
|
160
109
|
return x;
|
|
161
110
|
};
|
|
162
111
|
//#endregion
|
|
163
|
-
export {
|
|
112
|
+
export { y as attemptGetInputUtxosRemotely, C as getInputUtxoAndBalance, w as getInputUtxoAndBalanceOfStuckUtxos, T as getInputUtxoAndBalancePerToken, v as getInputUtxosRemotely };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../
|
|
1
|
+
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../data-structures/utxo/Utxo.cjs`),o=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxoAndBalance.cjs`),u=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),d=require(`../../utils/map.utils.cjs`),f=require(`../../utils/mutexes.utils.cjs`),p=require(`../../utils/erc20tokenFunctions.cjs`);let m=require(`async-mutex`);var h=async(t,r,i,a,o,s=!1,c,h=!1,g=!1)=>d.getOrCreateMapValue(t.balanceFetchingMutexByChain,r,()=>new m.Mutex).runExclusive(async()=>f.getChainBalanceFetchingMutex(r).runShared(async()=>{let{inputUtxos:d}=g?await l.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await l.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});h&&e.isExtension&&await u.privateTokensDB.fetchAndUpdatePrivateTokens(d.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let f=(e.isExtension?await u.privateTokensDB.getPrivateTokens(r,o):await p.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:d.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:d.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),m=new Map;return f.forEach(e=>{m.set(e.token.erc20TokenAddress.toLowerCase(),e)}),m})),g=async(e,n,u,d,f=6,m=u.map(()=>0),h=!1,g=!1)=>{let{userKeys:_}=e,v=_.getSpendingKeyPair().pubSpendingBJJPoint,y=[],b=[];if(u.length===0)return[];if(h){for(let e=0;e<u.length;e+=1){let r=t.isSolanaLike(n),i=r?u[e]:void 0,o=r?c.formatMintAddress(u[e]).compressedAddress:u[e];y.push(Array.from({length:f},()=>new a.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:i,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0})))}return y}let x=await l.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:u.map((e,t)=>({erc20TokenAddress:u[t],tokenId:m[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:g,chainId:n}),S=0;for(let e=0;e<u.length;e+=1){let t=x.get(s.encodeTokenWithId(n,{erc20TokenAddress:u[e],tokenId:m[e]}))??[];if(!t)throw Error(`Missing utxos for token`);S=Math.max(t.length,S),b.push(t)}if(S===2)return b;for(let[e,s]of b.entries())if(s.length>f){let t=s.slice(0,f),a=t.reduce((e,t)=>e+t.amount,0n);if(d[e]<0n&&a<-d[e]){let t=await p.getErc20TokenFromAPI(n,u[e]);if(!t)throw Error(`Token not found`);let s=t.decimals===18?6:2,c=Number(i.getAmountWithPrecision(a,t,s));throw new o.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`)}y.push(t)}else if(s.length<=f){let r=[...s],i=f-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?u[e]:void 0,l=o?c.formatMintAddress(u[e]).compressedAddress:u[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:l,mintAddress:s,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0}))}y.push(r)}return y};exports.addPaddingToUtxos=g,exports.getShieldedBalance=h;
|