@gurge/sdk 0.3.25 → 0.3.26
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/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +12 -6
- package/common/src/crypto/eddsa.cjs +1 -1
- package/common/src/crypto/eddsa.mjs +12 -6
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +12 -6
- package/common/src/crypto/preProcessing.cjs +1 -1
- package/common/src/crypto/preProcessing.mjs +23 -13
- package/common/src/crypto/rnCryptoBridge.cjs +1 -0
- package/common/src/crypto/rnCryptoBridge.d.ts +8 -0
- package/common/src/crypto/rnCryptoBridge.mjs +10 -0
- package/common/src/crypto/rnUtxoCrypto.cjs +1 -0
- package/common/src/crypto/rnUtxoCrypto.d.ts +14 -0
- package/common/src/crypto/rnUtxoCrypto.mjs +40 -0
- 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.mjs +1 -1
- 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/utxo/Utxo.cjs +1 -1
- package/common/src/data-structures/utxo/Utxo.d.ts +1 -0
- package/common/src/data-structures/utxo/Utxo.mjs +19 -6
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +0 -1
- package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
- package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +86 -54
- 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 +28 -27
- package/common/src/functions/utils/bigint-math.utils.cjs +1 -1
- package/common/src/functions/utils/bigint-math.utils.mjs +1 -12
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.mjs +1 -1
- package/common/src/functions/utils/utxoPadding.utils.cjs +1 -0
- package/common/src/functions/utils/utxoPadding.utils.d.ts +2 -0
- package/common/src/functions/utils/utxoPadding.utils.mjs +14 -0
- package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +14 -11
- package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
- package/common/src/functions/web3/events/getShieldedBalance.mjs +64 -64
- package/common/src/webworker/cryptoWorker/cryptoWorker.types.cjs +1 -0
- package/common/src/webworker/cryptoWorker/cryptoWorker.types.d.ts +49 -0
- package/common/src/webworker/cryptoWorker/cryptoWorker.types.mjs +6 -0
- package/common/src/webworker/cryptoWorker/cryptoWorkerLauncher.d.ts +1 -0
- package/common/src/webworker/cryptoWorker/cryptoWorkerLogic.d.ts +2 -0
- package/common/src/webworker/logError-DFS-H2t0.js +2 -0
- package/common/src/webworker/package.json +1 -1
- 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 +4 -3
- package/common/src/webworker/viteWorkerURL.constant.d.ts +1 -0
- package/common/src/webworker/viteWorkerURL.constant.mjs +4 -3
- 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 +63 -3
- package/react-native/HinkalWebViewWorker.mjs +134 -51
- package/react-native/bridge/RnWebViewCryptoBridge.cjs +1 -0
- package/react-native/bridge/RnWebViewCryptoBridge.d.ts +7 -0
- package/react-native/bridge/RnWebViewCryptoBridge.mjs +49 -0
- 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 +1 -0
- 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/BabyJubRN.cjs +0 -1
- package/common/src/crypto/BabyJubRN.mjs +0 -33
- package/common/src/crypto/EddsaRN.cjs +0 -1
- package/common/src/crypto/EddsaRN.mjs +0 -41
- package/common/src/webworker/logError-DCl9T86l.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../crypto/poseidon.cjs`),n=require(`../../functions/web3/etherFunctions.cjs`),r=require(`../crypto-keys/keys.cjs`),i=require(`../../functions/utils/time.utils.cjs`);var
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../crypto/poseidon.cjs`),n=require(`../../functions/web3/etherFunctions.cjs`),r=require(`../crypto-keys/keys.cjs`),i=require(`../../crypto/rnUtxoCrypto.cjs`),a=require(`../../functions/utils/time.utils.cjs`);var o=class o{amount;erc20TokenAddress;mintAddress;timeStamp;nullifyingKey;spendingPublicKey;randomization;H0;stealthAddress;encryptionKey;commitment;nullifier;isBlocked;isNewStyle;constructor({amount:e,erc20TokenAddress:t,mintAddress:i,timeStamp:o,nullifyingKey:s,spendingPublicKey:c,randomization:l,H0:u,stealthAddress:d,encryptionKey:f,commitment:p=void 0,nullifier:m=void 0,isBlocked:h=!1,isNewStyle:g=!1}){this.amount=e,this.erc20TokenAddress=t,this.mintAddress=i,this.timeStamp=o??a.getCurrentTimeInSeconds().toString(),this.nullifyingKey=s,this.spendingPublicKey=c,this.randomization=l??(s?r.UserKeys.findCorrectRandomization(n.randomBigInt(31),s):void 0),this.H0=u??(g&&this.randomization?r.UserKeys.findH0(this.randomization,s):void 0),this.stealthAddress=d,this.encryptionKey=f,this.commitment=p,this.nullifier=m,this.isBlocked=h,this.isNewStyle=g}static async createAsync(e){if(i.needsRnNewStyleCrypto(e)){let t=await i.prepareNewStyleUtxoFields(e.nullifyingKey,e.spendingPublicKey);return new o({...e,randomization:t.randomization,H0:t.H0,stealthAddress:t.stealthAddress})}return new o(e)}static createFrom(e,t){return new o({...e.getConstructableParams(),nullifier:void 0,commitment:void 0,...t})}getConstructableParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,nullifyingKey:this.nullifyingKey,spendingPublicKey:this.spendingPublicKey,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,encryptionKey:this.encryptionKey,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getBasicUtxoParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getCommitment(){if(!this.commitment){let e=[this.amount,this.erc20TokenAddress,BigInt(this.getStealthAddress()),this.timeStamp];this.commitment=t.poseidonHash(...e)}return this.commitment}getNullifier(){if(!this.nullifier){if(!this.nullifyingKey)throw Error(`No Nullifiers if private key is not provided`);let e=this.getCommitment(),n=t.poseidonHash(this.nullifyingKey,e);this.nullifier=t.poseidonHash(e,n)}return this.nullifier}getStealthAddress(){if(!this.stealthAddress){if(!this.nullifyingKey)throw Error(`No stealth address in UTXO if private key is not provided`);if(this.isNewStyle){if(!this.H0)throw Error(`No H0 point provided`);this.stealthAddress=r.UserKeys.getStealthAddressNewStyle(this.H0,this.nullifyingKey,this.spendingPublicKey)}else{if(!this.randomization)throw Error(`No randomization provided`);this.stealthAddress=r.UserKeys.getStealthAddress(this.randomization,this.nullifyingKey)}}return this.stealthAddress}getTokenAddress(t){let n=e.isSolanaLike(t)?this.mintAddress:this.erc20TokenAddress;if(!n)throw Error(`No token address provided`);return n}getEncryptionKey(){if(!this.nullifyingKey){if(!this.encryptionKey)throw Error(`No encryption key provided in UTXO`);return this.encryptionKey}return r.UserKeys.getEncryptionKeyPair(this.nullifyingKey).publicKey}};exports.Utxo=o;
|
|
@@ -49,6 +49,7 @@ export declare class Utxo {
|
|
|
49
49
|
* @param isBlocked [optional] whether the UTXO is blocked
|
|
50
50
|
*/
|
|
51
51
|
constructor({ amount, erc20TokenAddress, mintAddress, timeStamp, nullifyingKey, spendingPublicKey, randomization, H0, stealthAddress, encryptionKey, commitment, nullifier, isBlocked, isNewStyle, }: IUtxoConstructor);
|
|
52
|
+
static createAsync(params: IUtxoConstructor): Promise<Utxo>;
|
|
52
53
|
static createFrom(utxoToCreateFrom: Utxo, patch: Partial<IUtxoConstructor>): Utxo;
|
|
53
54
|
getConstructableParams(): IUtxoConstructor;
|
|
54
55
|
getBasicUtxoParams(): IUtxoConstructor;
|
|
@@ -2,9 +2,10 @@ import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
|
|
|
2
2
|
import { poseidonHash as t } from "../../crypto/poseidon.mjs";
|
|
3
3
|
import { randomBigInt as n } from "../../functions/web3/etherFunctions.mjs";
|
|
4
4
|
import { UserKeys as r } from "../crypto-keys/keys.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { needsRnNewStyleCrypto as i, prepareNewStyleUtxoFields as a } from "../../crypto/rnUtxoCrypto.mjs";
|
|
6
|
+
import { getCurrentTimeInSeconds as o } from "../../functions/utils/time.utils.mjs";
|
|
6
7
|
//#region libs/shared/common/src/data-structures/utxo/Utxo.ts
|
|
7
|
-
var
|
|
8
|
+
var s = class s {
|
|
8
9
|
amount;
|
|
9
10
|
erc20TokenAddress;
|
|
10
11
|
mintAddress;
|
|
@@ -19,11 +20,23 @@ var a = class a {
|
|
|
19
20
|
nullifier;
|
|
20
21
|
isBlocked;
|
|
21
22
|
isNewStyle;
|
|
22
|
-
constructor({ amount: e, erc20TokenAddress: t, mintAddress:
|
|
23
|
-
this.amount = e, this.erc20TokenAddress = t, this.mintAddress =
|
|
23
|
+
constructor({ amount: e, erc20TokenAddress: t, mintAddress: i, timeStamp: a, nullifyingKey: s, spendingPublicKey: c, randomization: l, H0: u, stealthAddress: d, encryptionKey: f, commitment: p = void 0, nullifier: m = void 0, isBlocked: h = !1, isNewStyle: g = !1 }) {
|
|
24
|
+
this.amount = e, this.erc20TokenAddress = t, this.mintAddress = i, this.timeStamp = a ?? o().toString(), this.nullifyingKey = s, this.spendingPublicKey = c, this.randomization = l ?? (s ? r.findCorrectRandomization(n(31), s) : void 0), this.H0 = u ?? (g && this.randomization ? r.findH0(this.randomization, s) : void 0), this.stealthAddress = d, this.encryptionKey = f, this.commitment = p, this.nullifier = m, this.isBlocked = h, this.isNewStyle = g;
|
|
25
|
+
}
|
|
26
|
+
static async createAsync(e) {
|
|
27
|
+
if (i(e)) {
|
|
28
|
+
let t = await a(e.nullifyingKey, e.spendingPublicKey);
|
|
29
|
+
return new s({
|
|
30
|
+
...e,
|
|
31
|
+
randomization: t.randomization,
|
|
32
|
+
H0: t.H0,
|
|
33
|
+
stealthAddress: t.stealthAddress
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return new s(e);
|
|
24
37
|
}
|
|
25
38
|
static createFrom(e, t) {
|
|
26
|
-
return new
|
|
39
|
+
return new s({
|
|
27
40
|
...e.getConstructableParams(),
|
|
28
41
|
nullifier: void 0,
|
|
29
42
|
commitment: void 0,
|
|
@@ -110,4 +123,4 @@ var a = class a {
|
|
|
110
123
|
}
|
|
111
124
|
};
|
|
112
125
|
//#endregion
|
|
113
|
-
export {
|
|
126
|
+
export { s as Utxo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./utils/abi.utils.cjs`),require(`./utils/serialize.utils.cjs`),require(`./utils/caseInsensitive.utils.cjs`),require(`./utils/amounts.utils.cjs`),require(`./web3/etherFunctions.cjs`),require(`./utils/
|
|
1
|
+
require(`./utils/abi.utils.cjs`),require(`./utils/serialize.utils.cjs`),require(`./utils/caseInsensitive.utils.cjs`),require(`./utils/amounts.utils.cjs`),require(`./web3/etherFunctions.cjs`),require(`./utils/time.utils.cjs`),require(`./utils/upToDateState.cjs`),require(`./utils/cacheFunctions.cjs`),require(`./utils/enclaveHandshakeService.cjs`),require(`./utils/encryptInputForEnclave.cjs`),require(`./utils/solanaMint.utils.cjs`),require(`./utils/customEnclaveFunctionsRegister.cjs`),require(`./utils/addresses.cjs`),require(`./utils/tron.utils.cjs`),require(`./web3/events/getInputUtxoAndBalance.cjs`),require(`./utils/get-signature-header.cjs`),require(`./utils/auth.utils.cjs`),require(`./utils/string.utils.cjs`),require(`./utils/token-check.utils.cjs`),require(`./utils/map.utils.cjs`),require(`./utils/mutexes.utils.cjs`),require(`./utils/erc20tokenFunctions.cjs`),require(`./web3/events/getShieldedBalance.cjs`),require(`./pre-transaction/outputUtxoProcessing.cjs`),require(`./utils/external-action.utils.cjs`),require(`./utils/bit.operations.cjs`),require(`./snarkjs/common.snarkjs.cjs`),require(`./pre-transaction/solana.cjs`),require(`./snarkjs/signedMessageHash.cjs`),require(`./pre-transaction/process-gas-estimates.cjs`),require(`./pre-transaction/getVolatileTransferAmount.cjs`),require(`./pre-transaction/constructAdminData.cjs`),require(`./utils/create-provider.cjs`),require(`./pre-transaction/convert-okx-instructions.cjs`),require(`./web3/getSolanaPriorityFee.cjs`),require(`./utils/process.utils.cjs`),require(`./pre-transaction/sendV0Transaction.cjs`),require(`./utils/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(`./snarkjs/generateZkProof.cjs`),require(`./snarkjs/generateMainAndCommitmentZkProof.cjs`),require(`./utils/serialize-utxos.utils.cjs`),require(`./utils/resolve-sync.utils.cjs`),require(`./utils/reloadPage.cjs`),require(`./utils/cacheDevice.utils.cjs`),require(`./utils/involves-permit2-op.cjs`),require(`./utils/convertEmporiumOpToCallInfo.cjs`),require(`./utils/getRecipientInfoFromUserKeys.cjs`),require(`./utils/publicBalance.utils.cjs`),require(`./utils/postToOffscreen.cjs`),require(`./utils/getContractAddress.cjs`),require(`./utils/getUtxosFromReceipt.utils.cjs`),require(`./utils/getUtxosFromReceiptSolana.cjs`),require(`./utils/fees.utils.cjs`),require(`./utils/enclave-signature-storage.cjs`),require(`./utils/tx-confirmation.utils.cjs`),require(`./utils/tronSimulation.utils.cjs`),require(`./utils/getSignerFromContract.cjs`),require(`./utils/mnemonics.cjs`),require(`./utils/nearIntents.utils.cjs`),require(`./utils/index.cjs`),require(`./snarkjs/fetchOnChainRootHashes.cjs`),require(`./private-wallet/emporium.helpers.cjs`),require(`./snarkjs/constructGeneralZkProof.cjs`),require(`./web3/uniswapAPI.cjs`),require(`./web3/odosAPI.cjs`),require(`./web3/oneInchAPI.cjs`),require(`./web3/okxAPI.cjs`),require(`./web3/index.cjs`),require(`./snarkjs/constructSolanaZkProof.cjs`),require(`./snarkjs/index.cjs`),require(`./private-wallet/emporium.swap.helpers.cjs`),require(`./private-wallet/index.cjs`),require(`./auto-deposit-back-helpers/get-tokens-to-deposit-back.cjs`),require(`./auto-deposit-back-helpers/get-gas-token-records.cjs`),require(`./auto-deposit-back-helpers/select-gas-token.cjs`),require(`./auto-deposit-back-helpers/update-hinkal.cjs`),require(`./auto-deposit-back-helpers/index.cjs`);
|
|
@@ -3,7 +3,6 @@ import "./utils/serialize.utils.mjs";
|
|
|
3
3
|
import "./utils/caseInsensitive.utils.mjs";
|
|
4
4
|
import "./utils/amounts.utils.mjs";
|
|
5
5
|
import "./web3/etherFunctions.mjs";
|
|
6
|
-
import "./utils/bigint-math.utils.mjs";
|
|
7
6
|
import "./utils/time.utils.mjs";
|
|
8
7
|
import "./utils/upToDateState.mjs";
|
|
9
8
|
import "./utils/cacheFunctions.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/
|
|
1
|
+
const e=require(`../../constants/vite.constants.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../crypto/rnCryptoBridge.cjs`),r=require(`../../data-structures/crypto-keys/keys.cjs`),i=require(`../../webworker/cryptoWorker/cryptoWorker.types.cjs`),a=require(`../../crypto/rnUtxoCrypto.cjs`),o=require(`../utils/solanaMint.utils.cjs`),s=require(`../utils/hinkalTiming.utils.cjs`),c=require(`../snarkjs/common.snarkjs.cjs`),l=require(`../../webworker/worker.registry.cjs`),u=require(`../../webworker/performTaskWithWorker.cjs`),d=require(`../../webworker/zkProofWorker/zkProofWorker.types.cjs`);var f=async(f,p,m,h)=>{let g=s.createRnDeltaTiming(`mainThread.commitmentValidation`);if(c.hasOnlyZeroAmounts(h))return;let _=t.isSolanaLike(f),v=h.map(e=>e.map(e=>e.amount.toString())),y=h.map(e=>e.map(e=>e.timeStamp)),b=h.map(e=>e.map(e=>c.getUtxoCircuitInRandomization(e))),x=h.map(e=>e.map(e=>e.getConstructableParams()));g.log(`serializeInputs`);let S=s.createRnDeltaTiming(`mainThread.getCommitment`),C=h.map(e=>e.map(e=>e.amount===0n?`0`:BigInt(e.getCommitment()).toString()));S.log(`all-utxos`,{count:h.reduce((e,t)=>e+t.length,0)});let w=await u.performTaskWithWorker({type:l.WorkerVariant.ZKProof,payload:{type:d.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:x}}});g.log(`buildInNullifiers-worker-done`);let T=p.getShieldedPrivateKey(),E=await a.getSpendingPublicKeyForRn(p),D=_?m.map(e=>{let{compressedAddress:t}=o.formatMintAddress(e);return BigInt(t).toString()}):m.map(e=>BigInt(e).toString()),O=s.createRnDeltaTiming(`mainThread.stealthValidation`),k=0;if(e.isReactNative){let e=[];h.forEach((t,n)=>{t.forEach((t,r)=>{k+=1;let i=t.spendingPublicKey??E;e.push({tokenIdx:n,utxoIdx:r,utxoStealthAddress:t.getStealthAddress(),isNewStyle:!!t.isNewStyle,randomization:t.randomization?.toString(),H0:t.H0?[t.H0[0].toString(),t.H0[1].toString()]:void 0,spendingPublicKey:[i[0].toString(),i[1].toString()]})})});let t=n.getRnCryptoBridge();await t.init(),(await t.call(i.CryptoWorkerOp.BATCH_STEALTH_VALIDATION,{nullifyingPrivateKey:T,defaultSpendingPublicKey:[E[0].toString(),E[1].toString()],checks:e})).forEach((t,n)=>{if(t.matches)return;let{tokenIdx:r,utxoIdx:i}=e[n];throw Error(`Commitment validation stealth mismatch at tokenIdx=${r}, utxoIdx=${i}`)})}else h.forEach((e,t)=>{e.forEach((e,n)=>{k+=1;let i=e.getStealthAddress(),a=e.spendingPublicKey??E,o=e.isNewStyle&&e.H0?r.UserKeys.getStealthAddressNewStyle(e.H0,T,a):r.UserKeys.getStealthAddress(BigInt(e.randomization),T);if(BigInt(i).toString()!==BigInt(o).toString())throw Error(`Commitment validation stealth mismatch at tokenIdx=${t}, utxoIdx=${n}`)})});O.log(`all-utxos`,{stealthChecks:k});let A={nullifyingPrivateKey:T,spendingPublicKey:E,erc20TokenAddresses:D,inAmounts:v,inRandomizations:b,inH0Ax:h.map(e=>e.map(e=>c.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:h.map(e=>e.map(e=>c.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:h.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:y,inCommitments:C,inNullifiers:w};if(!m.length||!h[0]?.length)return;let j=`commitmentCalculator${m.length}x${h[0].length}`;return g.log(`done`,{verifierName:j}),{tokenAddresses:D,inAmounts:v,inTimeStamps:y,inRandomizations:b,inCommitments:C,inNullifiers:w,verifierName:j,commitmentInput:A}},p=(e,t)=>{if(!(!e||!t))return{tokenAddresses:e.tokenAddresses,inAmounts:e.inAmounts,inTimeStamps:e.inTimeStamps,inRandomizations:e.inRandomizations,inCommitments:e.inCommitments,inNullifiers:e.inNullifiers,proof:{a:t.zkCallData[0],b:t.zkCallData[1],c:t.zkCallData[2]}}};exports.buildCommitmentValidationData=f,exports.buildCommitmentValidationDataFromProof=p;
|
|
@@ -1,64 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { isReactNative as e } from "../../constants/vite.constants.mjs";
|
|
2
|
+
import { isSolanaLike as t } from "../../constants/chains.constants.mjs";
|
|
3
|
+
import { getRnCryptoBridge as n } from "../../crypto/rnCryptoBridge.mjs";
|
|
4
|
+
import { UserKeys as r } from "../../data-structures/crypto-keys/keys.mjs";
|
|
5
|
+
import { CryptoWorkerOp as i } from "../../webworker/cryptoWorker/cryptoWorker.types.mjs";
|
|
6
|
+
import { getSpendingPublicKeyForRn as a } from "../../crypto/rnUtxoCrypto.mjs";
|
|
7
|
+
import { formatMintAddress as o } from "../utils/solanaMint.utils.mjs";
|
|
8
|
+
import { createRnDeltaTiming as s } from "../utils/hinkalTiming.utils.mjs";
|
|
9
|
+
import { getUtxoCircuitH0Coords as c, getUtxoCircuitInRandomization as l, hasOnlyZeroAmounts as u } from "../snarkjs/common.snarkjs.mjs";
|
|
10
|
+
import { WorkerVariant as d } from "../../webworker/worker.registry.mjs";
|
|
11
|
+
import { performTaskWithWorker as f } from "../../webworker/performTaskWithWorker.mjs";
|
|
12
|
+
import { ZKProofWorkerActionType as p } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
|
|
9
13
|
//#region libs/shared/common/src/functions/pre-transaction/buildCommitmentValidationData.ts
|
|
10
|
-
var
|
|
11
|
-
let
|
|
12
|
-
if (
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
type:
|
|
14
|
+
var m = async (m, h, g, _) => {
|
|
15
|
+
let v = s("mainThread.commitmentValidation");
|
|
16
|
+
if (u(_)) return;
|
|
17
|
+
let y = t(m), b = _.map((e) => e.map((e) => e.amount.toString())), x = _.map((e) => e.map((e) => e.timeStamp)), S = _.map((e) => e.map((e) => l(e))), C = _.map((e) => e.map((e) => e.getConstructableParams()));
|
|
18
|
+
v.log("serializeInputs");
|
|
19
|
+
let w = s("mainThread.getCommitment"), T = _.map((e) => e.map((e) => e.amount === 0n ? "0" : BigInt(e.getCommitment()).toString()));
|
|
20
|
+
w.log("all-utxos", { count: _.reduce((e, t) => e + t.length, 0) });
|
|
21
|
+
let E = await f({
|
|
22
|
+
type: d.ZKProof,
|
|
19
23
|
payload: {
|
|
20
|
-
type:
|
|
21
|
-
data: { inputUtxosSerialized:
|
|
24
|
+
type: p.BUILD_IN_NULLIFIERS,
|
|
25
|
+
data: { inputUtxosSerialized: C }
|
|
22
26
|
}
|
|
23
27
|
});
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
let { compressedAddress: t } =
|
|
28
|
+
v.log("buildInNullifiers-worker-done");
|
|
29
|
+
let D = h.getShieldedPrivateKey(), O = await a(h), k = y ? g.map((e) => {
|
|
30
|
+
let { compressedAddress: t } = o(e);
|
|
27
31
|
return BigInt(t).toString();
|
|
28
|
-
}) :
|
|
29
|
-
|
|
30
|
-
e
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
}) : g.map((e) => BigInt(e).toString()), A = s("mainThread.stealthValidation"), j = 0;
|
|
33
|
+
if (e) {
|
|
34
|
+
let e = [];
|
|
35
|
+
_.forEach((t, n) => {
|
|
36
|
+
t.forEach((t, r) => {
|
|
37
|
+
j += 1;
|
|
38
|
+
let i = t.spendingPublicKey ?? O;
|
|
39
|
+
e.push({
|
|
40
|
+
tokenIdx: n,
|
|
41
|
+
utxoIdx: r,
|
|
42
|
+
utxoStealthAddress: t.getStealthAddress(),
|
|
43
|
+
isNewStyle: !!t.isNewStyle,
|
|
44
|
+
randomization: t.randomization?.toString(),
|
|
45
|
+
H0: t.H0 ? [t.H0[0].toString(), t.H0[1].toString()] : void 0,
|
|
46
|
+
spendingPublicKey: [i[0].toString(), i[1].toString()]
|
|
47
|
+
});
|
|
48
|
+
});
|
|
34
49
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
let t = n();
|
|
51
|
+
await t.init(), (await t.call(i.BATCH_STEALTH_VALIDATION, {
|
|
52
|
+
nullifyingPrivateKey: D,
|
|
53
|
+
defaultSpendingPublicKey: [O[0].toString(), O[1].toString()],
|
|
54
|
+
checks: e
|
|
55
|
+
})).forEach((t, n) => {
|
|
56
|
+
if (t.matches) return;
|
|
57
|
+
let { tokenIdx: r, utxoIdx: i } = e[n];
|
|
58
|
+
throw Error(`Commitment validation stealth mismatch at tokenIdx=${r}, utxoIdx=${i}`);
|
|
59
|
+
});
|
|
60
|
+
} else _.forEach((e, t) => {
|
|
61
|
+
e.forEach((e, n) => {
|
|
62
|
+
j += 1;
|
|
63
|
+
let i = e.getStealthAddress(), a = e.spendingPublicKey ?? O, o = e.isNewStyle && e.H0 ? r.getStealthAddressNewStyle(e.H0, D, a) : r.getStealthAddress(BigInt(e.randomization), D);
|
|
64
|
+
if (BigInt(i).toString() !== BigInt(o).toString()) throw Error(`Commitment validation stealth mismatch at tokenIdx=${t}, utxoIdx=${n}`);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
A.log("all-utxos", { stealthChecks: j });
|
|
68
|
+
let M = {
|
|
69
|
+
nullifyingPrivateKey: D,
|
|
70
|
+
spendingPublicKey: O,
|
|
71
|
+
erc20TokenAddresses: k,
|
|
72
|
+
inAmounts: b,
|
|
73
|
+
inRandomizations: S,
|
|
74
|
+
inH0Ax: _.map((e) => e.map((e) => c(e)[0].toString())),
|
|
75
|
+
inH0Ay: _.map((e) => e.map((e) => c(e)[1].toString())),
|
|
76
|
+
isNewStyle: _.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
77
|
+
inTimeStamps: x,
|
|
78
|
+
inCommitments: T,
|
|
79
|
+
inNullifiers: E
|
|
48
80
|
};
|
|
49
|
-
if (!
|
|
50
|
-
let
|
|
51
|
-
return
|
|
52
|
-
tokenAddresses:
|
|
53
|
-
inAmounts:
|
|
54
|
-
inTimeStamps:
|
|
55
|
-
inRandomizations:
|
|
56
|
-
inCommitments:
|
|
57
|
-
inNullifiers:
|
|
58
|
-
verifierName:
|
|
59
|
-
commitmentInput:
|
|
81
|
+
if (!g.length || !_[0]?.length) return;
|
|
82
|
+
let N = `commitmentCalculator${g.length}x${_[0].length}`;
|
|
83
|
+
return v.log("done", { verifierName: N }), {
|
|
84
|
+
tokenAddresses: k,
|
|
85
|
+
inAmounts: b,
|
|
86
|
+
inTimeStamps: x,
|
|
87
|
+
inRandomizations: S,
|
|
88
|
+
inCommitments: T,
|
|
89
|
+
inNullifiers: E,
|
|
90
|
+
verifierName: N,
|
|
91
|
+
commitmentInput: M
|
|
60
92
|
};
|
|
61
|
-
},
|
|
93
|
+
}, h = (e, t) => {
|
|
62
94
|
if (!(!e || !t)) return {
|
|
63
95
|
tokenAddresses: e.tokenAddresses,
|
|
64
96
|
inAmounts: e.inAmounts,
|
|
@@ -74,4 +106,4 @@ var u = async (u, d, f, p) => {
|
|
|
74
106
|
};
|
|
75
107
|
};
|
|
76
108
|
//#endregion
|
|
77
|
-
export {
|
|
109
|
+
export { m as buildCommitmentValidationData, h as buildCommitmentValidationDataFromProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../utils/amounts.utils.cjs`),t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../data-structures/utxo/Utxo.cjs`),
|
|
1
|
+
const e=require(`../utils/amounts.utils.cjs`),t=require(`../../error-handling/error-codes.constants.cjs`),n=require(`../../crypto/rnUtxoCrypto.cjs`),r=require(`../../data-structures/utxo/Utxo.cjs`),i=require(`../utils/hinkalTiming.utils.cjs`);var a=async(a,o,s,c,l=!0,u,d)=>{let f=i.createRnDeltaTiming(`mainThread.outputUtxo`),p=e.countTotalAmountInUtxos(o),{erc20TokenAddress:m,mintAddress:h}=o[0];if(l&&s<0n&&p+s<0n)throw Error(t.transactionErrorCodes.INSUFFICIENT_FUNDS_TO_TRANSACT);f.log(`sumInputs`);let g=await n.getSpendingPublicKeyForRn(a),_=[await r.Utxo.createAsync({amount:e.bigintMax(p+s,0n),erc20TokenAddress:m,mintAddress:h,nullifyingKey:a.getShieldedPrivateKey(),timeStamp:c,spendingPublicKey:g,isNewStyle:!0})];if(f.log(`newUtxo-change`,{randomization:!!_[0].randomization,h0:!!_[0].H0}),u!==void 0&&d!==void 0){let[e,t,n,,i]=u.split(`,`);_.push(new r.Utxo({amount:d,erc20TokenAddress:m,mintAddress:h,H0:[BigInt(t),BigInt(n)],stealthAddress:e,encryptionKey:i,timeStamp:c,isNewStyle:!0})),f.log(`newUtxo-recipient`)}return f.log(`done`,{outputCount:_.length}),{outputUtxos:_}};exports.outputUtxoProcessing=a;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserKeys } from '../../data-structures/crypto-keys/keys';
|
|
2
2
|
import { Utxo } from '../../data-structures/utxo/Utxo';
|
|
3
|
-
export declare const outputUtxoProcessing: (userKeys: UserKeys, inputUtxos: Utxo[], amountChange: bigint, timeStamp?: string, revertIfNegative?: boolean, recipientAddress?: string, recipientAmountChange?: bigint) => {
|
|
3
|
+
export declare const outputUtxoProcessing: (userKeys: UserKeys, inputUtxos: Utxo[], amountChange: bigint, timeStamp?: string, revertIfNegative?: boolean, recipientAddress?: string, recipientAmountChange?: bigint) => Promise<{
|
|
4
4
|
outputUtxos: Utxo[];
|
|
5
|
-
}
|
|
5
|
+
}>;
|
|
@@ -1,38 +1,39 @@
|
|
|
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 {
|
|
3
|
+
import { getSpendingPublicKeyForRn as r } from "../../crypto/rnUtxoCrypto.mjs";
|
|
4
|
+
import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
|
|
5
|
+
import { createRnDeltaTiming as a } from "../utils/hinkalTiming.utils.mjs";
|
|
5
6
|
//#region libs/shared/common/src/functions/pre-transaction/outputUtxoProcessing.ts
|
|
6
|
-
var
|
|
7
|
-
let
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
amount: e(
|
|
12
|
-
erc20TokenAddress:
|
|
13
|
-
mintAddress:
|
|
14
|
-
nullifyingKey:
|
|
15
|
-
timeStamp:
|
|
16
|
-
spendingPublicKey:
|
|
7
|
+
var o = async (o, s, c, l, u = !0, d, f) => {
|
|
8
|
+
let p = a("mainThread.outputUtxo"), m = t(s), { erc20TokenAddress: h, mintAddress: g } = s[0];
|
|
9
|
+
if (u && c < 0n && m + c < 0n) throw Error(n.INSUFFICIENT_FUNDS_TO_TRANSACT);
|
|
10
|
+
p.log("sumInputs");
|
|
11
|
+
let _ = await r(o), v = [await i.createAsync({
|
|
12
|
+
amount: e(m + c, 0n),
|
|
13
|
+
erc20TokenAddress: h,
|
|
14
|
+
mintAddress: g,
|
|
15
|
+
nullifyingKey: o.getShieldedPrivateKey(),
|
|
16
|
+
timeStamp: l,
|
|
17
|
+
spendingPublicKey: _,
|
|
17
18
|
isNewStyle: !0
|
|
18
19
|
})];
|
|
19
|
-
if (
|
|
20
|
-
randomization: !!
|
|
21
|
-
h0: !!
|
|
22
|
-
}),
|
|
23
|
-
let [e, t, n, ,
|
|
24
|
-
|
|
25
|
-
amount:
|
|
26
|
-
erc20TokenAddress:
|
|
27
|
-
mintAddress:
|
|
20
|
+
if (p.log("newUtxo-change", {
|
|
21
|
+
randomization: !!v[0].randomization,
|
|
22
|
+
h0: !!v[0].H0
|
|
23
|
+
}), d !== void 0 && f !== void 0) {
|
|
24
|
+
let [e, t, n, , r] = d.split(",");
|
|
25
|
+
v.push(new i({
|
|
26
|
+
amount: f,
|
|
27
|
+
erc20TokenAddress: h,
|
|
28
|
+
mintAddress: g,
|
|
28
29
|
H0: [BigInt(t), BigInt(n)],
|
|
29
30
|
stealthAddress: e,
|
|
30
|
-
encryptionKey:
|
|
31
|
-
timeStamp:
|
|
31
|
+
encryptionKey: r,
|
|
32
|
+
timeStamp: l,
|
|
32
33
|
isNewStyle: !0
|
|
33
|
-
})),
|
|
34
|
+
})), p.log("newUtxo-recipient");
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return p.log("done", { outputCount: v.length }), { outputUtxos: v };
|
|
36
37
|
};
|
|
37
38
|
//#endregion
|
|
38
|
-
export {
|
|
39
|
+
export { o as outputUtxoProcessing };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
require(`../../constants/protocol.constants.cjs`);
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
import
|
|
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 = (e, n, r) => {
|
|
7
|
-
let i = 1n, a = t(e, r), o = n;
|
|
8
|
-
for (; o > 0n;) o % 2n == 1n && (i = i * a % r), o /= 2n, a = a * a % r;
|
|
9
|
-
return i;
|
|
10
|
-
};
|
|
11
|
-
//#endregion
|
|
12
|
-
export { t as mod, n as modpow };
|
|
1
|
+
import "../../constants/protocol.constants.mjs";
|
|
@@ -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(`./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(`./bigint-math.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,7 +2,6 @@ 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";
|
|
6
5
|
import "./time.utils.mjs";
|
|
7
6
|
import "./upToDateState.mjs";
|
|
8
7
|
import "./cacheFunctions.mjs";
|
|
@@ -38,6 +37,7 @@ import "../pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
|
|
|
38
37
|
import "../pre-transaction/buildCommitmentValidationData.mjs";
|
|
39
38
|
import "../pre-transaction/index.mjs";
|
|
40
39
|
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";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`../../crypto/rnUtxoCrypto.cjs`),t=require(`../../data-structures/utxo/Utxo.cjs`);var n=async(n,r)=>n<=0?[]:e.needsRnNewStyleCrypto(r)?(await e.prepareNewStyleUtxoFieldsBatch(Array.from({length:n},()=>({nullifyingKey:r.nullifyingKey,spendingPublicKey:r.spendingPublicKey})))).map(e=>new t.Utxo({...r,randomization:e.randomization,H0:e.H0,stealthAddress:e.stealthAddress})):Array.from({length:n},()=>new t.Utxo(r));exports.createPaddingUtxos=n;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { needsRnNewStyleCrypto as e, prepareNewStyleUtxoFieldsBatch as t } from "../../crypto/rnUtxoCrypto.mjs";
|
|
2
|
+
import { Utxo as n } from "../../data-structures/utxo/Utxo.mjs";
|
|
3
|
+
//#region libs/shared/common/src/functions/utils/utxoPadding.utils.ts
|
|
4
|
+
var r = async (r, i) => r <= 0 ? [] : e(i) ? (await t(Array.from({ length: r }, () => ({
|
|
5
|
+
nullifyingKey: i.nullifyingKey,
|
|
6
|
+
spendingPublicKey: i.spendingPublicKey
|
|
7
|
+
})))).map((e) => new n({
|
|
8
|
+
...i,
|
|
9
|
+
randomization: e.randomization,
|
|
10
|
+
H0: e.H0,
|
|
11
|
+
stealthAddress: e.stealthAddress
|
|
12
|
+
})) : Array.from({ length: r }, () => new n(i));
|
|
13
|
+
//#endregion
|
|
14
|
+
export { r as createPaddingUtxos };
|
|
@@ -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(`../../utils/utxoPadding.utils.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`),d=require(`../../utils/hinkalTiming.utils.cjs`);var f=new(require(`async-mutex`)).Mutex,p=async(e,t)=>{if(e.allowParallelBalanceLocalDecryption)return t();let n=d.createRnDeltaTiming(`utxoPrep.mutex`);return f.isLocked()&&n.log(`waiting-for-lock`),f.runExclusive(async()=>{n.log(`lock-acquired`);try{return await t()}finally{n.log(`lock-released`)}})},m=async(e,t,n,a,o,s,c,l,u)=>p(e,async()=>{let f=d.createRnDeltaTiming(`utxoPrep.decrypt`);u+=1;let p=s.slice(u);f.log(`batchProcess-start`,{outputsSlice:p.length,cached:c.length});let{lastOutput:m,additionalEncryptedOutputs:h}=await e.utxoUtils.batchProcess(p,l,t,n);f.log(`batchProcess-done`,{additionalEncryptedOutputs:h.length});let g=[...c,...h],_=d.createRnDeltaTiming(`wallet.checkAddress`);await r.checkAddressNotUpdated(e,a),_.log(`during-decrypt`),i.setHinkalCache({lastOutput:m,encryptedOutputs:g},e,n,o),f.log(`cache-write`,{encryptedOutputs:g.length});let v=await e.utxoUtils.buildBatchProcess(g,t,n);return f.log(`buildBatchProcess-done`,{utxoCount:v.length}),v}),h=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},g=async(e,t,n,r,i,a,o,s,c)=>{try{return await h(e,t,n,i)}catch{return m(e,t,n,r,i,a,o,s,c)}},_=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},v=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),y=async(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;){let[t]=await n.createPaddingUtxos(1,{amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0});if(e.push(t),r)for(;e.length>6;)e.splice(e.length-1)}},b=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=d.createRnDeltaTiming(`utxoPrep`);l.log(`start`);let u=a;u?l.log(`wallet.getEthereumAddress-skipped`,{ethAddressPassed:!0}):(u=await e.getEthereumAddress(),l.log(`wallet.getEthereumAddress`));let f=n??e.userKeys.getShieldedPublicKey(),{userKeys:p}=e,h=e.encryptedOutputsByChain[t],_=e.nullifiersByChain[t],y=Array.from(h);o&&i.resetCache(e,t,f);let{encryptedOutputs:b,lastOutput:x}=i.getHinkalCache(e,t,f);l.log(`cache.read`,{cachedEncryptedOutputs:b.length});let S=d.createRnDeltaTiming(`wallet.checkAddress`);await r.checkAddressNotUpdated(e,u),S.log(`before-decrypt`);let C=x!==``,w=y.findIndex(e=>e.value===x);l.log(`findLastOutputIndex`,{hinkalOutputs:y.length,lastOutputIndex:w});let T=w>-1,E=!C&&w===-1,D=e.areMerkleTreeUpdatesDisabled(),O=!D&&(T||!s&&E),k=!D&&s&&E,A=!O&&!k;l.log(`branch`,{decryptLocally:O,decryptRemotely:k,useCache:A,outputsSlice:w>-1?y.length-(w+1):0});let j=[];O?(j=await m(e,p,t,u,f,y,b,x,w),l.log(`decryptLocally-done`,{utxoCount:j.length})):k?(j=await g(e,p,t,u,f,y,b,x,w),l.log(`decryptRemotely-done`,{utxoCount:j.length})):A&&(j=await e.utxoUtils.buildBatchProcess(b,p,t),l.log(`useCache-buildBatchProcess-done`,{utxoCount:j.length}));let M=d.createRnDeltaTiming(`wallet.checkAddress`);await r.checkAddressNotUpdated(e,u),M.log(`after-decrypt`);let N=await v(e,j,_);l.log(`filterSpentUtxos`,{allUtxos:j.length,inputUtxos:N.length});let P=c?N.filter(e=>e.isBlocked):N.filter(e=>!e.isBlocked);return l.log(`done`,{inputUtxos:P.length}),{inputUtxos:P}},x=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 b({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)}},S=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 g=l??n.userKeys.getShieldedPrivateKey(),v=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=h?await x({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await b({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=_(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;await y(n,i,s,g,v,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=g,exports.getInputUtxoAndBalance=b,exports.getInputUtxoAndBalanceOfStuckUtxos=x,exports.getInputUtxoAndBalancePerToken=S,exports.getInputUtxosRemotely=h;
|
|
@@ -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 { createPaddingUtxos as r } from "../../utils/utxoPadding.utils.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";
|
|
@@ -55,15 +55,18 @@ var g = new h(), _ = async (e, t) => {
|
|
|
55
55
|
}, x = (e) => {
|
|
56
56
|
if (Array.isArray(e)) return e;
|
|
57
57
|
if (e !== void 0) return [e];
|
|
58
|
-
}, S = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), C = (e, t, n, i, a, o, s, c) => {
|
|
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
|
-
|
|
58
|
+
}, S = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), C = async (e, t, n, i, a, o, s, c) => {
|
|
59
|
+
for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) {
|
|
60
|
+
let [t] = await r(1, {
|
|
61
|
+
amount: 0n,
|
|
62
|
+
erc20TokenAddress: o,
|
|
63
|
+
mintAddress: c,
|
|
64
|
+
nullifyingKey: i,
|
|
65
|
+
spendingPublicKey: a,
|
|
66
|
+
isNewStyle: !0
|
|
67
|
+
});
|
|
68
|
+
if (e.push(t), n) for (; e.length > 6;) e.splice(e.length - 1);
|
|
69
|
+
}
|
|
67
70
|
}, w = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
|
|
68
71
|
let u = m("utxoPrep");
|
|
69
72
|
u.log("start");
|
|
@@ -151,7 +154,7 @@ var g = new h(), _ = async (e, t) => {
|
|
|
151
154
|
});
|
|
152
155
|
for (let [t, n] of b) {
|
|
153
156
|
let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
|
|
154
|
-
C(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
|
|
157
|
+
await C(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
|
|
155
158
|
}
|
|
156
159
|
return b;
|
|
157
160
|
};
|
|
@@ -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(`../../../crypto/rnUtxoCrypto.cjs`),o=require(`../../utils/utxoPadding.utils.cjs`),s=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const c=require(`../../utils/encodeTokenWithId.cjs`),l=require(`../../utils/solanaMint.utils.cjs`),u=require(`./getInputUtxoAndBalance.cjs`),d=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),f=require(`../../utils/map.utils.cjs`),p=require(`../../utils/mutexes.utils.cjs`),m=require(`../../utils/erc20tokenFunctions.cjs`);let h=require(`async-mutex`);var g=async(t,r,i,a,o,s=!1,c,l=!1,g=!1)=>f.getOrCreateMapValue(t.balanceFetchingMutexByChain,r,()=>new h.Mutex).runExclusive(async()=>p.getChainBalanceFetchingMutex(r).runShared(async()=>{let{inputUtxos:f}=g?await u.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await u.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});l&&e.isExtension&&await d.privateTokensDB.fetchAndUpdatePrivateTokens(f.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let p=(e.isExtension?await d.privateTokensDB.getPrivateTokens(r,o):await m.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:f.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:f.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),h=new Map;return p.forEach(e=>{h.set(e.token.erc20TokenAddress.toLowerCase(),e)}),h})),_=async(e,n,d,f,p=6,h=d.map(()=>0),g=!1,_=!1)=>{let{userKeys:v}=e,y=await a.getSpendingPublicKeyForRn(v),b=[],x=[];if(d.length===0)return[];if(g){for(let e=0;e<d.length;e+=1){let r=t.isSolanaLike(n),i=r?d[e]:void 0,a=r?l.formatMintAddress(d[e]).compressedAddress:d[e];b.push(await o.createPaddingUtxos(p,{amount:0n,erc20TokenAddress:a,mintAddress:i,nullifyingKey:v.getShieldedPrivateKey(),spendingPublicKey:y,isNewStyle:!0}))}return b}let S=await u.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:d.map((e,t)=>({erc20TokenAddress:d[t],tokenId:h[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:_,chainId:n}),C=0;for(let e=0;e<d.length;e+=1){let t=S.get(c.encodeTokenWithId(n,{erc20TokenAddress:d[e],tokenId:h[e]}))??[];if(!t)throw Error(`Missing utxos for token`);C=Math.max(t.length,C),x.push(t)}if(C===2)return x;for(let[e,a]of x.entries())if(a.length>p){let t=a.slice(0,p),o=t.reduce((e,t)=>e+t.amount,0n);if(f[e]<0n&&o<-f[e]){let t=await m.getErc20TokenFromAPI(n,d[e]);if(!t)throw Error(`Token not found`);let a=t.decimals===18?6:2,c=Number(i.getAmountWithPrecision(o,t,a));throw new s.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`)}b.push(t)}else if(a.length<=p){let r=[...a],i=p-a.length;if(i>0){let a=t.isSolanaLike(n),s=a?d[e]:void 0,c=a?l.formatMintAddress(d[e]).compressedAddress:d[e];r.push(...await o.createPaddingUtxos(i,{amount:0n,erc20TokenAddress:c,mintAddress:s,nullifyingKey:v.getShieldedPrivateKey(),spendingPublicKey:y,isNewStyle:!0}))}b.push(r)}return b};exports.addPaddingToUtxos=_,exports.getShieldedBalance=g;
|