@gurge/sdk 0.3.26 → 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/hinkalClaimUtxo.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalClaimUtxo.mjs +1 -1
- 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/hinkalPrivateWallet.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalPrivateWallet.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +1 -1
- 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 +1 -1
- 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 +32 -43
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +2 -2
- 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/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 +1 -0
- 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/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +43 -49
- 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/index.cjs +1 -1
- package/common/src/functions/utils/index.mjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +44 -94
- package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
- package/common/src/functions/web3/events/getShieldedBalance.mjs +64 -64
- 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 -14
- package/common/src/crypto/rnUtxoCrypto.mjs +0 -40
- 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 -49
- 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-DFS-H2t0.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,39 +1,33 @@
|
|
|
1
1
|
import { bigintMax as e, countTotalAmountInUtxos as t } from "../utils/amounts.utils.mjs";
|
|
2
2
|
import { transactionErrorCodes as n } from "../../error-handling/error-codes.constants.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
|
|
5
|
-
import { createRnDeltaTiming as a } from "../utils/hinkalTiming.utils.mjs";
|
|
3
|
+
import { Utxo as r } from "../../data-structures/utxo/Utxo.mjs";
|
|
6
4
|
//#region libs/shared/common/src/functions/pre-transaction/outputUtxoProcessing.ts
|
|
7
|
-
var
|
|
8
|
-
let
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
spendingPublicKey: _,
|
|
5
|
+
var i = (i, a, o, s, c = !0, l, u) => {
|
|
6
|
+
let d = t(a), { erc20TokenAddress: f, mintAddress: p } = a[0];
|
|
7
|
+
if (c && o < 0n && d + o < 0n) throw Error(n.INSUFFICIENT_FUNDS_TO_TRANSACT);
|
|
8
|
+
let m = [new r({
|
|
9
|
+
amount: e(d + o, 0n),
|
|
10
|
+
erc20TokenAddress: f,
|
|
11
|
+
mintAddress: p,
|
|
12
|
+
nullifyingKey: i.getShieldedPrivateKey(),
|
|
13
|
+
timeStamp: s,
|
|
14
|
+
spendingPublicKey: i.getSpendingKeyPair().pubSpendingBJJPoint,
|
|
18
15
|
isNewStyle: !0
|
|
19
16
|
})];
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
amount: f,
|
|
27
|
-
erc20TokenAddress: h,
|
|
28
|
-
mintAddress: g,
|
|
17
|
+
if (l !== void 0 && u !== void 0) {
|
|
18
|
+
let [e, t, n, , i] = l.split(",");
|
|
19
|
+
m.push(new r({
|
|
20
|
+
amount: u,
|
|
21
|
+
erc20TokenAddress: f,
|
|
22
|
+
mintAddress: p,
|
|
29
23
|
H0: [BigInt(t), BigInt(n)],
|
|
30
24
|
stealthAddress: e,
|
|
31
|
-
encryptionKey:
|
|
32
|
-
timeStamp:
|
|
25
|
+
encryptionKey: i,
|
|
26
|
+
timeStamp: s,
|
|
33
27
|
isNewStyle: !0
|
|
34
|
-
}))
|
|
28
|
+
}));
|
|
35
29
|
}
|
|
36
|
-
return
|
|
30
|
+
return { outputUtxos: m };
|
|
37
31
|
};
|
|
38
32
|
//#endregion
|
|
39
|
-
export {
|
|
33
|
+
export { i as outputUtxoProcessing };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../types/external-action.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../types/external-action.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/bit.operations.cjs`),l=require(`./common.snarkjs.cjs`),ee=require(`./signedMessageHash.cjs`),u=require(`./generateCircomData.cjs`),te=require(`../../data-structures/AccountActions/AccountActions.cjs`),d=require(`./generateMainAndCommitmentZkProof.cjs`),f=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),p=require(`../private-wallet/emporium.helpers.cjs`);var m=async(m,h,g,_,v,y,b,x,S,C=t.zeroAddress,w=e.chainIds.localhost,T=h.map(()=>!1),E=void 0,D,O)=>{let k=l.getZkProofVerifierName(h,g),A=l.calcAmountChanges(h,g),j=h.map(e=>e[0].erc20TokenAddress),M=l.calcEncryptedOutputs(g),N=t.defaultSignatureData,P=_.getShieldedPrivateKey(),{pubSpendingBJJPoint:F}=_.getSpendingKeyPair(),I=l.calcStealthAddressStructure(i.UserKeys.findCorrectRandomization(r.randomBigInt(31),P),P,_.getSpendingKeyPair().pubSpendingBJJPoint),{inCommitmentSiblings:ne,inCommitmentSiblingSides:re,rootHashHinkal:L,inNullifiers:R}=await f.getDataFromWorkers(w,m,h.map(e=>e.map(e=>e.getConstructableParams()))),z=l.buildOutCommitments(g),B=r.randomBigInt(31),V=n.poseidonFunction(B),H=BigInt(g.length>0?g[0][0].timeStamp:a.getCurrentTimeInSeconds()),U={rootHashHinkal:L,spendingPublicKey:F,nullifyingPrivateKey:P,erc20TokenAddresses:j,amountChanges:A,inAmounts:h.map(e=>e.map(e=>e.amount.toString())),inRandomizations:h.map(e=>e.map(e=>l.getUtxoCircuitInRandomization(e))),inH0Ax:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:h.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:h.map(e=>e.map(e=>e.timeStamp)),inNullifiers:R,inCommitmentSiblings:ne,inCommitmentSiblingSides:re,outAmounts:g.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:H,outPublicKeys:g.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:z,calldataHash:0n,messageSeed:B,H0Ax:c.takeOffHighestBit(I.extraRandomization),H0Ay:I.H0},W=l.calcPublicSignalCount(k,U.erc20TokenAddresses,U.amountChanges,U.inNullifiers,U.outCommitments),G=l.calcAmountChanges(h,g,!0),K=l.getSlippageValues(G);s.Logger.log({publicSignalCount:W});let q=Array.isArray(b)?b:[b],J=e.getOnchainChainId(w),Y=O?te.AccountActions.getSignerAddressFromPrivateKey(J,O):void 0,X=v===o.ExternalActionId.Emporium?await p.encodeEmporiumMetadata(w,y??t.zeroAddress,O,q,V,Y):await p.encodeEmporiumMetadata(w,t.zeroAddress,void 0,v===0n?[]:q,V,t.zeroAddress);U.calldataHash=l.createCallDataHash(W,C,y,v,X,M,E,K,T,S,N,D);let Z=ee.computeSignedMessageHashEvm({rootHashHinkal:L,erc20TokenAddresses:j,amountChanges:A,outTimeStamp:H,inNullifiers:R,outCommitments:z,calldataHash:U.calldataHash,message:V,outH1Ay:I.H1,H0Ax:U.H0Ax,H0Ay:I.H0}),{R8:Q,S:ie}=_.signEddsa(Z);U.eddsaSignature=[Q[0],Q[1],ie],U.signedMessageHash=Z;let $=k.startsWith(`mainEVMCircuitMin0`),ae={outTimeStamp:H,calldataHash:U.calldataHash,messageSeed:B},{zkCallData:oe,commitmentValidationData:se}=await d.generateMainAndCommitmentZkProof(w,_,j,h,k,$?ae:U,x);return{zkCallData:oe,circomData:u.generateCircomData(z,R,L,G,j,g,M,W,v,y,X,C,U.calldataHash,I,T,E,$?Number(H):void 0,K,S,N,D),dimData:{tokenNumber:h.length,nullifierAmount:h.length>0?h[0].length:0,outputAmount:g.length>0?g[0].length:0},encryptedOutputs:M,commitmentValidationData:se}};exports.constructZkProof=m;
|
|
@@ -1,55 +1,49 @@
|
|
|
1
|
-
import { chainIds as e, getOnchainChainId as
|
|
2
|
-
import { defaultSignatureData as
|
|
3
|
-
import { poseidonFunction as
|
|
4
|
-
import { randomBigInt as
|
|
5
|
-
import { UserKeys as
|
|
6
|
-
import { getCurrentTimeInSeconds as
|
|
7
|
-
import { ExternalActionId as
|
|
8
|
-
import { Logger as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { buildOutCommitments as a, calcAmountChanges as o, calcEncryptedOutputs as s, calcPublicSignalCount as c, calcStealthAddressStructure as l, createCallDataHash as se, getSlippageValues as ce, getUtxoCircuitH0Coords as u, getUtxoCircuitInRandomization as le, getZkProofVerifierName as ue } from "./common.snarkjs.mjs";
|
|
1
|
+
import { chainIds as e, getOnchainChainId as t } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { defaultSignatureData as ee, zeroAddress as n } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { poseidonFunction as te } from "../../crypto/poseidon.mjs";
|
|
4
|
+
import { randomBigInt as r } from "../web3/etherFunctions.mjs";
|
|
5
|
+
import { UserKeys as i } from "../../data-structures/crypto-keys/keys.mjs";
|
|
6
|
+
import { getCurrentTimeInSeconds as a } from "../utils/time.utils.mjs";
|
|
7
|
+
import { ExternalActionId as o } from "../../types/external-action.types.mjs";
|
|
8
|
+
import { Logger as s } from "../../error-handling/logger.mjs";
|
|
9
|
+
import { takeOffHighestBit as ne } from "../utils/bit.operations.mjs";
|
|
10
|
+
import { buildOutCommitments as re, calcAmountChanges as c, calcEncryptedOutputs as ie, calcPublicSignalCount as ae, calcStealthAddressStructure as oe, createCallDataHash as se, getSlippageValues as ce, getUtxoCircuitH0Coords as l, getUtxoCircuitInRandomization as le, getZkProofVerifierName as ue } from "./common.snarkjs.mjs";
|
|
12
11
|
import { computeSignedMessageHashEvm as de } from "./signedMessageHash.mjs";
|
|
13
12
|
import { generateCircomData as fe } from "./generateCircomData.mjs";
|
|
14
|
-
import { AccountActions as
|
|
13
|
+
import { AccountActions as u } from "../../data-structures/AccountActions/AccountActions.mjs";
|
|
15
14
|
import { generateMainAndCommitmentZkProof as d } from "./generateMainAndCommitmentZkProof.mjs";
|
|
16
|
-
import { getDataFromWorkers as
|
|
17
|
-
import { encodeEmporiumMetadata as
|
|
15
|
+
import { getDataFromWorkers as f } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
16
|
+
import { encodeEmporiumMetadata as p } from "../private-wallet/emporium.helpers.mjs";
|
|
18
17
|
//#region libs/shared/common/src/functions/snarkjs/constructGeneralZkProof.ts
|
|
19
|
-
var
|
|
20
|
-
let
|
|
21
|
-
he.log("done", {
|
|
22
|
-
verifierName: O,
|
|
23
|
-
chainId: C
|
|
24
|
-
});
|
|
25
|
-
let B = a(h), V = n(31), H = ne(V), U = BigInt(h.length > 0 ? h[0][0].timeStamp : r()), W = {
|
|
18
|
+
var m = async (m, h, g, _, v, y, b, pe, x, S = n, C = e.localhost, w = h.map(() => !1), T = void 0, E, D) => {
|
|
19
|
+
let O = ue(h, g), k = c(h, g), A = h.map((e) => e[0].erc20TokenAddress), j = ie(g), M = ee, N = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: P } = _.getSpendingKeyPair(), F = oe(i.findCorrectRandomization(r(31), N), N, _.getSpendingKeyPair().pubSpendingBJJPoint), { inCommitmentSiblings: I, inCommitmentSiblingSides: L, rootHashHinkal: R, inNullifiers: z } = await f(C, m, h.map((e) => e.map((e) => e.getConstructableParams()))), B = re(g), V = r(31), H = te(V), U = BigInt(g.length > 0 ? g[0][0].timeStamp : a()), W = {
|
|
26
20
|
rootHashHinkal: R,
|
|
27
21
|
spendingPublicKey: P,
|
|
28
22
|
nullifyingPrivateKey: N,
|
|
29
23
|
erc20TokenAddresses: A,
|
|
30
24
|
amountChanges: k,
|
|
31
|
-
inAmounts:
|
|
32
|
-
inRandomizations:
|
|
33
|
-
inH0Ax:
|
|
34
|
-
inH0Ay:
|
|
35
|
-
isNewStyle:
|
|
36
|
-
inTimeStamps:
|
|
25
|
+
inAmounts: h.map((e) => e.map((e) => e.amount.toString())),
|
|
26
|
+
inRandomizations: h.map((e) => e.map((e) => le(e))),
|
|
27
|
+
inH0Ax: h.map((e) => e.map((e) => l(e)[0].toString())),
|
|
28
|
+
inH0Ay: h.map((e) => e.map((e) => l(e)[1].toString())),
|
|
29
|
+
isNewStyle: h.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
30
|
+
inTimeStamps: h.map((e) => e.map((e) => e.timeStamp)),
|
|
37
31
|
inNullifiers: z,
|
|
38
32
|
inCommitmentSiblings: I,
|
|
39
33
|
inCommitmentSiblingSides: L,
|
|
40
|
-
outAmounts:
|
|
34
|
+
outAmounts: g.map((e) => e.map((e) => e.amount.toString())),
|
|
41
35
|
outTimeStamp: U,
|
|
42
|
-
outPublicKeys:
|
|
36
|
+
outPublicKeys: g.map((e) => e.map((e) => e.getStealthAddress())),
|
|
43
37
|
outCommitments: B,
|
|
44
38
|
calldataHash: 0n,
|
|
45
39
|
messageSeed: V,
|
|
46
|
-
H0Ax:
|
|
40
|
+
H0Ax: ne(F.extraRandomization),
|
|
47
41
|
H0Ay: F.H0
|
|
48
|
-
}, G =
|
|
49
|
-
|
|
50
|
-
let J = Array.isArray(
|
|
51
|
-
W.calldataHash = se(G, S,
|
|
52
|
-
let
|
|
42
|
+
}, G = ae(O, W.erc20TokenAddresses, W.amountChanges, W.inNullifiers, W.outCommitments), K = c(h, g, !0), q = ce(K);
|
|
43
|
+
s.log({ publicSignalCount: G });
|
|
44
|
+
let J = Array.isArray(b) ? b : [b], me = t(C), he = D ? u.getSignerAddressFromPrivateKey(me, D) : void 0, Y = v === o.Emporium ? await p(C, y ?? n, D, J, H, he) : await p(C, n, void 0, v === 0n ? [] : J, H, n);
|
|
45
|
+
W.calldataHash = se(G, S, y, v, Y, j, T, q, w, x, M, E);
|
|
46
|
+
let X = de({
|
|
53
47
|
rootHashHinkal: R,
|
|
54
48
|
erc20TokenAddresses: A,
|
|
55
49
|
amountChanges: k,
|
|
@@ -61,28 +55,28 @@ var p = async (p, m, h, g, _, v, y, b, x, S = t, C = e.localhost, w = m.map(() =
|
|
|
61
55
|
outH1Ay: F.H1,
|
|
62
56
|
H0Ax: W.H0Ax,
|
|
63
57
|
H0Ay: F.H0
|
|
64
|
-
}), { R8:
|
|
58
|
+
}), { R8: Z, S: ge } = _.signEddsa(X);
|
|
65
59
|
W.eddsaSignature = [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
], W.signedMessageHash =
|
|
70
|
-
let
|
|
60
|
+
Z[0],
|
|
61
|
+
Z[1],
|
|
62
|
+
ge
|
|
63
|
+
], W.signedMessageHash = X;
|
|
64
|
+
let Q = O.startsWith("mainEVMCircuitMin0"), $ = {
|
|
71
65
|
outTimeStamp: U,
|
|
72
66
|
calldataHash: W.calldataHash,
|
|
73
67
|
messageSeed: V
|
|
74
|
-
}, { zkCallData:
|
|
68
|
+
}, { zkCallData: _e, commitmentValidationData: ve } = await d(C, _, A, h, O, Q ? $ : W, pe);
|
|
75
69
|
return {
|
|
76
|
-
zkCallData:
|
|
77
|
-
circomData: fe(B, z, R, K, A,
|
|
70
|
+
zkCallData: _e,
|
|
71
|
+
circomData: fe(B, z, R, K, A, g, j, G, v, y, Y, S, W.calldataHash, F, w, T, Q ? Number(U) : void 0, q, x, M, E),
|
|
78
72
|
dimData: {
|
|
79
|
-
tokenNumber:
|
|
80
|
-
nullifierAmount:
|
|
81
|
-
outputAmount:
|
|
73
|
+
tokenNumber: h.length,
|
|
74
|
+
nullifierAmount: h.length > 0 ? h[0].length : 0,
|
|
75
|
+
outputAmount: g.length > 0 ? g[0].length : 0
|
|
82
76
|
},
|
|
83
77
|
encryptedOutputs: j,
|
|
84
|
-
commitmentValidationData:
|
|
78
|
+
commitmentValidationData: ve
|
|
85
79
|
};
|
|
86
80
|
};
|
|
87
81
|
//#endregion
|
|
88
|
-
export {
|
|
82
|
+
export { m as constructZkProof };
|
|
@@ -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(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.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(`./
|
|
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,6 +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 "./bigint-math.utils.mjs";
|
|
5
6
|
import "./time.utils.mjs";
|
|
6
7
|
import "./upToDateState.mjs";
|
|
7
8
|
import "./cacheFunctions.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,6 +1,6 @@
|
|
|
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 {
|
|
3
|
+
import { Utxo as r } from "../../../data-structures/utxo/Utxo.mjs";
|
|
4
4
|
import { checkAddressNotUpdated as i } from "../../utils/upToDateState.mjs";
|
|
5
5
|
import { getHinkalCache as a, resetCache as o, setHinkalCache as s } from "../../utils/cacheFunctions.mjs";
|
|
6
6
|
import { encodeTokenWithId as c } from "../../utils/encodeTokenWithId.mjs";
|
|
@@ -9,100 +9,50 @@ import { getInputUtxosEnclave as u } from "./getInputUtxosEnclave.mjs";
|
|
|
9
9
|
import { hashEthereumAddress as d } from "../../utils/addresses.mjs";
|
|
10
10
|
import { getScheduledTransactionsNullifierIndexes as f } from "../../../API/scheduled-transactions-calls.mjs";
|
|
11
11
|
import { addressToHexFormat as p } from "../../utils/tron.utils.mjs";
|
|
12
|
-
import {
|
|
13
|
-
import { Mutex as h } from "async-mutex";
|
|
12
|
+
import { Mutex as m } from "async-mutex";
|
|
14
13
|
//#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
|
|
15
|
-
var
|
|
16
|
-
if (e.allowParallelBalanceLocalDecryption) return t();
|
|
17
|
-
let n = m("utxoPrep.mutex");
|
|
18
|
-
return g.isLocked() && n.log("waiting-for-lock"), g.runExclusive(async () => {
|
|
19
|
-
n.log("lock-acquired");
|
|
20
|
-
try {
|
|
21
|
-
return await t();
|
|
22
|
-
} finally {
|
|
23
|
-
n.log("lock-released");
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}, v = async (e, t, n, r, a, o, c, l, u) => _(e, async () => {
|
|
27
|
-
let d = m("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 () => {
|
|
28
15
|
u += 1;
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
d.log("batchProcess-done", { additionalEncryptedOutputs: h.length });
|
|
36
|
-
let g = [...c, ...h], _ = m("wallet.checkAddress");
|
|
37
|
-
await i(e, r), _.log("during-decrypt"), s({
|
|
38
|
-
lastOutput: p,
|
|
39
|
-
encryptedOutputs: g
|
|
40
|
-
}, e, n, a), d.log("cache-write", { encryptedOutputs: g.length });
|
|
41
|
-
let v = await e.utxoUtils.buildBatchProcess(g, t, n);
|
|
42
|
-
return d.log("buildBatchProcess-done", { utxoCount: v.length }), v;
|
|
43
|
-
}), y = async (e, t, n, r) => {
|
|
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) => {
|
|
44
22
|
let { utxos: i, encryptedOutputs: a, lastOutput: o } = await u(e, n, t);
|
|
45
23
|
return s({
|
|
46
24
|
encryptedOutputs: a,
|
|
47
25
|
lastOutput: o
|
|
48
26
|
}, e, n, r), i;
|
|
49
|
-
},
|
|
27
|
+
}, y = async (e, t, n, r, i, a, o, s, c) => {
|
|
50
28
|
try {
|
|
51
|
-
return await
|
|
29
|
+
return await v(e, t, n, i);
|
|
52
30
|
} catch {
|
|
53
|
-
return
|
|
31
|
+
return _(e, t, n, r, i, a, o, s, c);
|
|
54
32
|
}
|
|
55
|
-
},
|
|
33
|
+
}, b = (e) => {
|
|
56
34
|
if (Array.isArray(e)) return e;
|
|
57
35
|
if (e !== void 0) return [e];
|
|
58
|
-
},
|
|
59
|
-
for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let
|
|
78
|
-
u.log("cache.read", { cachedEncryptedOutputs: y.length });
|
|
79
|
-
let C = m("wallet.checkAddress");
|
|
80
|
-
await i(e, d), C.log("before-decrypt");
|
|
81
|
-
let w = x !== "", T = _.findIndex((e) => e.value === x);
|
|
82
|
-
u.log("findLastOutputIndex", {
|
|
83
|
-
hinkalOutputs: _.length,
|
|
84
|
-
lastOutputIndex: T
|
|
85
|
-
});
|
|
86
|
-
let E = T > -1, D = !w && T === -1, O = e.areMerkleTreeUpdatesDisabled(), k = !O && (E || !c && D), A = !O && c && D, j = !k && !A;
|
|
87
|
-
u.log("branch", {
|
|
88
|
-
decryptLocally: k,
|
|
89
|
-
decryptRemotely: A,
|
|
90
|
-
useCache: j,
|
|
91
|
-
outputsSlice: T > -1 ? _.length - (T + 1) : 0
|
|
92
|
-
});
|
|
93
|
-
let M = [];
|
|
94
|
-
k ? (M = await v(e, p, t, d, f, _, y, x, T), u.log("decryptLocally-done", { utxoCount: M.length })) : A ? (M = await b(e, p, t, d, f, _, y, x, T), u.log("decryptRemotely-done", { utxoCount: M.length })) : j && (M = await e.utxoUtils.buildBatchProcess(y, p, t), u.log("useCache-buildBatchProcess-done", { utxoCount: M.length }));
|
|
95
|
-
let N = m("wallet.checkAddress");
|
|
96
|
-
await i(e, d), N.log("after-decrypt");
|
|
97
|
-
let P = await S(e, M, g);
|
|
98
|
-
u.log("filterSpentUtxos", {
|
|
99
|
-
allUtxos: M.length,
|
|
100
|
-
inputUtxos: P.length
|
|
101
|
-
});
|
|
102
|
-
let F = l ? P.filter((e) => e.isBlocked) : P.filter((e) => !e.isBlocked);
|
|
103
|
-
return u.log("done", { inputUtxos: F.length }), { inputUtxos: F };
|
|
104
|
-
}, T = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
|
|
105
|
-
let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await w({
|
|
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({
|
|
106
56
|
hinkal: e,
|
|
107
57
|
chainId: n,
|
|
108
58
|
passedShieldedPublicKey: r,
|
|
@@ -117,15 +67,15 @@ var g = new h(), _ = async (e, t) => {
|
|
|
117
67
|
nullifiers: l.map((e) => e.getNullifier())
|
|
118
68
|
});
|
|
119
69
|
return { inputUtxos: u.map((e) => l[e]).filter((e) => !!e) };
|
|
120
|
-
},
|
|
121
|
-
let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await
|
|
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({
|
|
122
72
|
hinkal: t,
|
|
123
73
|
chainId: o,
|
|
124
74
|
ethAddress: d,
|
|
125
75
|
passedShieldedPrivateKey: s,
|
|
126
76
|
resetCacheBefore: f,
|
|
127
77
|
allowRemoteDecryption: m
|
|
128
|
-
}) : await
|
|
78
|
+
}) : await C({
|
|
129
79
|
hinkal: t,
|
|
130
80
|
tokenWithId: r,
|
|
131
81
|
minInput: i,
|
|
@@ -136,27 +86,27 @@ var g = new h(), _ = async (e, t) => {
|
|
|
136
86
|
ethAddress: d,
|
|
137
87
|
resetCacheBefore: f,
|
|
138
88
|
allowRemoteDecryption: m
|
|
139
|
-
}), y =
|
|
89
|
+
}), y = b(r), x = /* @__PURE__ */ new Map();
|
|
140
90
|
v.forEach((e) => {
|
|
141
91
|
let t = e.getTokenAddress(o);
|
|
142
92
|
if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
|
|
143
93
|
let r = c(o, {
|
|
144
94
|
erc20TokenAddress: t,
|
|
145
95
|
tokenId: 0
|
|
146
|
-
}), i =
|
|
147
|
-
|
|
96
|
+
}), i = x.get(r) ?? [];
|
|
97
|
+
x.set(r, [...i, e]);
|
|
148
98
|
}), p?.forEach((e) => {
|
|
149
99
|
let t = c(o, {
|
|
150
100
|
erc20TokenAddress: e.erc20TokenAddress,
|
|
151
101
|
tokenId: 0
|
|
152
102
|
});
|
|
153
|
-
|
|
103
|
+
x.set(t, x.get(t) ?? []);
|
|
154
104
|
});
|
|
155
|
-
for (let [t, n] of
|
|
105
|
+
for (let [t, n] of x) {
|
|
156
106
|
let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
|
|
157
|
-
|
|
107
|
+
S(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
|
|
158
108
|
}
|
|
159
|
-
return
|
|
109
|
+
return x;
|
|
160
110
|
};
|
|
161
111
|
//#endregion
|
|
162
|
-
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;
|