@hinkal/common 0.3.8 → 0.3.10
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/README.md +2 -8
- package/common/src/API/API.cjs +1 -1
- package/common/src/API/API.d.ts +4 -5
- package/common/src/API/API.mjs +79 -80
- package/common/src/API/dashboardTransactionCalls.cjs +1 -1
- package/common/src/API/dashboardTransactionCalls.d.ts +4 -1
- package/common/src/API/dashboardTransactionCalls.mjs +2 -2
- package/common/src/API/enclaveRecipientInfoCalls.d.ts +0 -2
- package/common/src/API/enclaveSignatureCalls.cjs +1 -1
- package/common/src/API/enclaveSignatureCalls.d.ts +2 -1
- package/common/src/API/enclaveSignatureCalls.mjs +5 -8
- package/common/src/API/enclaveUtxoCalls.cjs +1 -1
- package/common/src/API/enclaveUtxoCalls.d.ts +12 -8
- package/common/src/API/enclaveUtxoCalls.mjs +17 -20
- package/common/src/API/privateSendRecipientInfoCalls.cjs +1 -1
- package/common/src/API/privateSendRecipientInfoCalls.d.ts +3 -6
- package/common/src/API/privateSendRecipientInfoCalls.mjs +12 -6
- package/common/src/API/scheduled-transactions-calls.cjs +1 -1
- package/common/src/API/scheduled-transactions-calls.d.ts +1 -5
- package/common/src/API/scheduled-transactions-calls.mjs +2 -6
- package/common/src/constants/bridging.constants.cjs +1 -1
- package/common/src/constants/bridging.constants.d.ts +1 -0
- package/common/src/constants/bridging.constants.mjs +1 -1
- package/common/src/constants/chains.constants.cjs +1 -1
- package/common/src/constants/chains.constants.d.ts +18 -17
- package/common/src/constants/chains.constants.mjs +108 -89
- package/common/src/constants/deploy-data/deploy-data-arbMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-arbMainnet.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-base.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-base.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-bnbMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-bnbMainnet.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-ethMainnet.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-ethMainnet.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-optimism.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-optimism.json.mjs +2 -1
- package/common/src/constants/deploy-data/deploy-data-polygon.json.cjs +1 -1
- package/common/src/constants/deploy-data/deploy-data-polygon.json.mjs +2 -1
- package/common/src/constants/events.constants.cjs +1 -1
- package/common/src/constants/events.constants.mjs +1 -16
- package/common/src/constants/protocol.constants.d.ts +1 -3
- package/common/src/constants/server.constants.cjs +1 -1
- package/common/src/constants/server.constants.d.ts +1 -4
- package/common/src/constants/server.constants.mjs +1 -4
- package/common/src/constants/tx-confirmation.constants.cjs +1 -1
- package/common/src/constants/tx-confirmation.constants.d.ts +1 -0
- package/common/src/constants/tx-confirmation.constants.mjs +2 -2
- package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.d.ts +6 -9
- package/common/src/data-structures/Hinkal/Hinkal.mjs +129 -160
- package/common/src/data-structures/Hinkal/IHinkal.d.ts +5 -9
- package/common/src/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
- package/common/src/data-structures/Hinkal/handleAutoDepositBack.mjs +23 -23
- package/common/src/data-structures/Hinkal/hinkalBridgePrivateToPrivate.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalBridgePrivateToPrivate.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +10 -10
- package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +18 -18
- package/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +3 -2
- package/common/src/data-structures/Hinkal/hinkalProxySend.cjs +1 -0
- package/common/src/data-structures/Hinkal/hinkalProxySend.d.ts +6 -0
- package/common/src/data-structures/Hinkal/hinkalProxySend.mjs +16 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +44 -47
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.mjs +2 -2
- package/common/src/data-structures/Hinkal/hinkalTransact.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransact.mjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +4 -4
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +101 -94
- package/common/src/data-structures/Hinkal/index.d.ts +0 -1
- package/common/src/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/activity-db.mjs +34 -34
- package/common/src/data-structures/IndexedDB/index.cjs +1 -1
- package/common/src/data-structures/IndexedDB/index.d.ts +1 -0
- package/common/src/data-structures/IndexedDB/index.mjs +1 -0
- package/common/src/data-structures/IndexedDB/scheduled-transactions-db.cjs +1 -0
- package/common/src/data-structures/IndexedDB/scheduled-transactions-db.d.ts +11 -0
- package/common/src/data-structures/IndexedDB/scheduled-transactions-db.mjs +34 -0
- package/common/src/data-structures/IndexedDB/signatures-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/signatures-db.mjs +11 -11
- package/common/src/data-structures/TokenDBs/PrivateTokensDB.cjs +1 -1
- package/common/src/data-structures/TokenDBs/PrivateTokensDB.mjs +18 -19
- package/common/src/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
- package/common/src/data-structures/event-service/evm/BlockchainEventEmitter.mjs +11 -11
- package/common/src/data-structures/event-service/helpers/ClientEventHelper.cjs +1 -1
- package/common/src/data-structures/event-service/helpers/ClientEventHelper.mjs +6 -6
- package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.cjs +1 -1
- package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.d.ts +1 -0
- package/common/src/data-structures/private-balances/HinkalPrivateBalanceController.mjs +79 -75
- package/common/src/data-structures/provider-adapter/IProviderAdapter.d.ts +1 -4
- package/common/src/error-handling/error-codes.constants.cjs +1 -1
- package/common/src/error-handling/error-codes.constants.d.ts +6 -0
- package/common/src/error-handling/error-codes.constants.mjs +10 -4
- package/common/src/functions/auto-deposit-back-helpers/get-gas-token-records.cjs +1 -1
- package/common/src/functions/auto-deposit-back-helpers/get-gas-token-records.mjs +7 -6
- package/common/src/functions/auto-deposit-back-helpers/select-gas-token.cjs +1 -1
- package/common/src/functions/auto-deposit-back-helpers/select-gas-token.mjs +8 -8
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +1 -2
- package/common/src/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
- package/common/src/functions/pre-transaction/getVolatileTransferAmount.mjs +12 -12
- package/common/src/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/common/src/functions/private-wallet/emporium.helpers.mjs +13 -13
- package/common/src/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
- package/common/src/functions/private-wallet/emporium.swap.helpers.mjs +13 -13
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +4 -4
- package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.mjs +5 -5
- package/common/src/functions/snarkjs/constructTxEnclave.cjs +1 -1
- package/common/src/functions/snarkjs/constructTxEnclave.d.ts +1 -1
- package/common/src/functions/snarkjs/constructTxEnclave.mjs +61 -133
- package/common/src/functions/snarkjs/constructTxEnclaveVerify.cjs +1 -0
- package/common/src/functions/snarkjs/constructTxEnclaveVerify.d.ts +5 -0
- package/common/src/functions/snarkjs/constructTxEnclaveVerify.mjs +295 -0
- package/common/src/functions/utils/addresses.cjs +1 -1
- package/common/src/functions/utils/addresses.d.ts +1 -0
- package/common/src/functions/utils/addresses.mjs +13 -12
- package/common/src/functions/utils/bridge-arrival.utils.cjs +1 -1
- package/common/src/functions/utils/bridge-arrival.utils.mjs +12 -11
- package/common/src/functions/utils/create-provider.cjs +1 -1
- package/common/src/functions/utils/create-provider.mjs +4 -1
- package/common/src/functions/utils/enclave-recipient-info-storage.cjs +1 -1
- package/common/src/functions/utils/enclave-recipient-info-storage.d.ts +4 -1
- package/common/src/functions/utils/enclave-recipient-info-storage.mjs +1 -0
- package/common/src/functions/utils/enclave-signature-storage.cjs +1 -1
- package/common/src/functions/utils/enclave-signature-storage.d.ts +1 -1
- package/common/src/functions/utils/enclave-signature-storage.mjs +3 -3
- package/common/src/functions/utils/enclave-utxo-storage.cjs +1 -1
- package/common/src/functions/utils/enclave-utxo-storage.d.ts +3 -3
- package/common/src/functions/utils/enclave-utxo-storage.mjs +8 -5
- package/common/src/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/common/src/functions/utils/encryptInputForEnclave.d.ts +8 -0
- package/common/src/functions/utils/encryptInputForEnclave.mjs +43 -23
- package/common/src/functions/utils/erc20tokenFunctions.cjs +1 -1
- package/common/src/functions/utils/erc20tokenFunctions.mjs +2 -15
- package/common/src/functions/utils/fees.utils.cjs +1 -1
- package/common/src/functions/utils/fees.utils.mjs +6 -6
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.d.ts +1 -0
- package/common/src/functions/utils/index.mjs +3 -3
- package/common/src/functions/utils/ipfs.d.ts +2 -3
- package/common/src/functions/utils/lifi.utils.d.ts +2 -0
- package/common/src/functions/utils/nearIntents.utils.cjs +1 -1
- package/common/src/functions/utils/nearIntents.utils.mjs +6 -6
- package/common/src/functions/utils/publicBalance.utils.cjs +1 -1
- package/common/src/functions/utils/publicBalance.utils.mjs +9 -10
- package/common/src/functions/utils/temporary-wallet-recovery.utils.cjs +1 -0
- package/common/src/functions/utils/temporary-wallet-recovery.utils.d.ts +7 -0
- package/common/src/functions/utils/temporary-wallet-recovery.utils.mjs +10 -0
- package/common/src/functions/utils/tron.utils.cjs +1 -1
- package/common/src/functions/utils/tron.utils.mjs +16 -29
- package/common/src/functions/utils/tx-confirmation.utils.cjs +1 -1
- package/common/src/functions/utils/tx-confirmation.utils.d.ts +1 -0
- package/common/src/functions/utils/tx-confirmation.utils.mjs +16 -13
- package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +5 -5
- package/common/src/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxosEnclave.d.ts +1 -1
- package/common/src/functions/web3/events/getInputUtxosEnclave.mjs +19 -11
- package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
- package/common/src/functions/web3/events/getShieldedBalance.d.ts +4 -4
- package/common/src/functions/web3/events/getShieldedBalance.mjs +113 -102
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.mjs +16 -16
- package/common/src/providers/SolanaProviderAdapter.cjs +1 -1
- package/common/src/providers/SolanaProviderAdapter.d.ts +1 -4
- package/common/src/providers/SolanaProviderAdapter.mjs +3 -6
- package/common/src/providers/WagmiProviderAdapter.cjs +1 -1
- package/common/src/providers/WagmiProviderAdapter.mjs +5 -5
- package/common/src/types/cache.types.cjs +1 -1
- package/common/src/types/cache.types.d.ts +2 -1
- package/common/src/types/cache.types.mjs +1 -1
- package/common/src/types/enclaveApi.types.d.ts +2 -3
- package/common/src/types/ethereum-network.types.d.ts +1 -0
- package/common/src/types/events.types.d.ts +1 -0
- package/common/src/types/near-intents.types.d.ts +1 -0
- package/common/src/types/remote-proof.types.d.ts +5 -0
- package/common/src/types/remote-tx-build.types.d.ts +37 -4
- package/common/src/types/scheduled-transactions.types.d.ts +18 -0
- package/common/src/types/solana.types.d.ts +0 -3
- package/common/src/webworker/{logError-RKYfeI6h.js → logError-CIIt1CO3.js} +1 -1
- package/common/src/webworker/package.json +5 -6
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +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 +3 -3
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/common/src/webworker/workerProxy-BHzCZ9HT.js +1 -0
- 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 +5 -6
- package/services/Hinkal.cjs +1 -1
- package/services/Hinkal.d.ts +6 -2
- package/services/Hinkal.mjs +9 -4
- package/types/IHinkal.d.ts +6 -2
- package/common/src/API/evm-token-assets.cjs +0 -1
- package/common/src/API/evm-token-assets.mjs +0 -20
- package/common/src/API/getAnyRecipientInfo.d.ts +0 -1
- package/common/src/API/solana-nft-assets.cjs +0 -1
- package/common/src/API/solana-nft-assets.mjs +0 -11
- package/common/src/data-structures/Hinkal/hinkalSolanaSponsoredProxySend.d.ts +0 -5
- package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +0 -1
- package/common/src/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +0 -109
- package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.cjs +0 -1
- package/common/src/data-structures/TokenDBs/ArcPublicTokensDB.mjs +0 -94
- package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.cjs +0 -1
- package/common/src/data-structures/TokenDBs/EventsPublicTokensDB.mjs +0 -134
- package/common/src/data-structures/TokenDBs/PublicTokensDB.cjs +0 -1
- package/common/src/data-structures/TokenDBs/PublicTokensDB.mjs +0 -32
- package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.cjs +0 -1
- package/common/src/data-structures/TokenDBs/TempoPublicTokensDB.mjs +0 -37
- package/common/src/data-structures/TokenDBs/TronPublicTokensDB.cjs +0 -1
- package/common/src/data-structures/TokenDBs/TronPublicTokensDB.mjs +0 -51
- package/common/src/data-structures/TokenDBs/index.cjs +0 -1
- package/common/src/data-structures/TokenDBs/index.mjs +0 -6
- package/common/src/functions/utils/ipfs.cjs +0 -1
- package/common/src/functions/utils/ipfs.mjs +0 -1
- package/common/src/functions/utils/reloadPage.cjs +0 -1
- package/common/src/functions/utils/reloadPage.mjs +0 -4
- package/common/src/webworker/workerProxy-COB7g4Qc.js +0 -1
|
@@ -1,167 +1,95 @@
|
|
|
1
1
|
import { ENCLAVE_URL as e } from "./constant.mjs";
|
|
2
2
|
import { httpClient as t } from "../../data-structures/http/HttpClient.mjs";
|
|
3
3
|
import "../../data-structures/http/index.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { verifySignedEnclaveResponse as n } from "./verifySignedEnclaveResponse.mjs";
|
|
5
|
+
import { enclavePostSealedSigned as r, makeEnclaveHandshakeAndEncryptInput as i } from "../utils/encryptInputForEnclave.mjs";
|
|
6
|
+
import { verifyPrepareSolanaStuckWithdrawResponse as a, verifyPrepareSolanaTxResponse as o, verifyPrepareStuckWithdrawResponse as s, verifyPrepareTxResponse as c } from "./constructTxEnclaveVerify.mjs";
|
|
6
7
|
//#region libs/shared/common/src/functions/snarkjs/constructTxEnclave.ts
|
|
7
|
-
var
|
|
8
|
-
let { keyCiphertext: o, inputCiphertext: s } = await
|
|
8
|
+
var l = (e) => e?.flat().filter((e) => e.amount > 0n).map((e) => e.getCommitment()), u = async (r, a) => {
|
|
9
|
+
let { keyCiphertext: o, inputCiphertext: s } = await i(a), c = await t.post(`${e}${r}`, {
|
|
9
10
|
key: o,
|
|
10
11
|
inputs: s
|
|
11
12
|
});
|
|
12
|
-
return
|
|
13
|
-
},
|
|
14
|
-
if (Array.isArray(e)) return `[${e.map(o).join(",")}]`;
|
|
15
|
-
if (e && typeof e == "object") {
|
|
16
|
-
let t = e;
|
|
17
|
-
return `{${Object.keys(t).filter((e) => t[e] !== void 0).sort().map((e) => `${JSON.stringify(e)}:${o(t[e])}`).join(",")}}`;
|
|
18
|
-
}
|
|
19
|
-
return JSON.stringify(e);
|
|
20
|
-
}, s = (e, t) => {
|
|
21
|
-
if (o({
|
|
22
|
-
chainId: String(e.chainId),
|
|
23
|
-
hinkalAddress: e.hinkalAddress ?? "",
|
|
24
|
-
erc20Addresses: e.erc20Addresses,
|
|
25
|
-
amountChanges: e.amountChanges,
|
|
26
|
-
externalAddress: e.externalAddress,
|
|
27
|
-
...e.originalSender ? { originalSender: e.originalSender } : {},
|
|
28
|
-
relay: e.relay ?? "",
|
|
29
|
-
feeStructure: e.feeStructure ? {
|
|
30
|
-
feeToken: e.feeStructure.feeToken,
|
|
31
|
-
flatFee: e.feeStructure.flatFee.toString(),
|
|
32
|
-
variableRate: e.feeStructure.variableRate.toString()
|
|
33
|
-
} : null,
|
|
34
|
-
externalActionId: e.externalActionId ?? "",
|
|
35
|
-
externalActionMetadata: e.externalActionMetadata ?? "",
|
|
36
|
-
onChainCreation: e.onChainCreation ?? null,
|
|
37
|
-
recipientAddress: e.recipientAddress ?? null,
|
|
38
|
-
recipientAmounts: e.recipientAmounts ?? null,
|
|
39
|
-
selfOutputAmounts: e.selfOutputAmounts ?? null,
|
|
40
|
-
inputCommitments: e.inputCommitments ?? null,
|
|
41
|
-
useBlockedUtxos: e.useBlockedUtxos ?? !1,
|
|
42
|
-
createBlockedUtxos: e.createBlockedUtxos ?? !1,
|
|
43
|
-
...e.forceEmptyUtxos ? { forceEmptyUtxos: !0 } : {},
|
|
44
|
-
messageSeed: e.messageSeed ?? "",
|
|
45
|
-
skipLock: e.skipLock ?? !1,
|
|
46
|
-
...e.speculative ? { speculative: e.speculative } : {},
|
|
47
|
-
slippageValues: e.slippageValues ?? null
|
|
48
|
-
}) !== o(t)) throw Error("Enclave prepare-tx response does not match the request sent - refusing to sign");
|
|
49
|
-
}, c = (e, t) => {
|
|
50
|
-
let n = {
|
|
51
|
-
chainId: String(e.chainId),
|
|
52
|
-
mintAddresses: e.mintAddresses,
|
|
53
|
-
amountChanges: e.amountChanges,
|
|
54
|
-
relayAddress: e.relayAddress,
|
|
55
|
-
recipient: e.recipient,
|
|
56
|
-
signer: e.signer ?? e.relayAddress,
|
|
57
|
-
functionName: e.functionName ?? "transact",
|
|
58
|
-
accounts: e.accounts,
|
|
59
|
-
onChainCreation: e.onChainCreation ?? null,
|
|
60
|
-
relayerFee: e.relayerFee ?? "0",
|
|
61
|
-
variableRate: e.variableRate ?? "0",
|
|
62
|
-
hinkalInstructions: e.hinkalInstructions ?? null,
|
|
63
|
-
remainingAccounts: e.remainingAccounts ?? null,
|
|
64
|
-
swapperAccountSalt: e.swapperAccountSalt ?? "0",
|
|
65
|
-
recipientAddress: e.recipientAddress ?? "",
|
|
66
|
-
recipientAmounts: e.recipientAmounts ?? null,
|
|
67
|
-
inputCommitments: e.inputCommitments ?? null,
|
|
68
|
-
useBlockedUtxos: e.useBlockedUtxos ?? !1,
|
|
69
|
-
messageSeed: e.messageSeed ?? ""
|
|
70
|
-
};
|
|
71
|
-
if (e.recipientAmount && (n.recipientAmount = e.recipientAmount), e.displayRecipient && (n.displayRecipient = e.displayRecipient), e.speculative && (n.speculative = e.speculative), o(n) !== o(t)) throw Error("Enclave prepare-solana-tx response does not match the request sent - refusing to sign");
|
|
72
|
-
}, l = (e) => ({
|
|
13
|
+
return n(c.data, c.signature);
|
|
14
|
+
}, d = (e) => ({
|
|
73
15
|
R8: e.R8.map(String),
|
|
74
16
|
S: e.S.toString()
|
|
75
|
-
}),
|
|
17
|
+
}), f = (e) => ({
|
|
76
18
|
feeToken: e.feeToken,
|
|
77
19
|
flatFee: e.flatFee.toString(),
|
|
78
20
|
variableRate: e.variableRate.toString()
|
|
79
|
-
}),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}, f = async (e, t, n = e.userKeys) => {
|
|
94
|
-
let r = {
|
|
95
|
-
...t,
|
|
96
|
-
amountChanges: t.amountChanges.map(String),
|
|
97
|
-
recipientAmounts: t.recipientAmounts?.map((e) => e.map(String)),
|
|
98
|
-
selfOutputAmounts: t.selfOutputAmounts?.map(String),
|
|
99
|
-
messageSeed: t.messageSeed?.toString(),
|
|
100
|
-
nullifyingKey: n.getShieldedPrivateKey(),
|
|
101
|
-
spendingPublicKey: n.getSpendingKeyPair().pubSpendingBJJPoint.map(String),
|
|
102
|
-
slippageValues: t.slippageValues?.map(String)
|
|
103
|
-
}, i = await a("/prepare-tx", r);
|
|
104
|
-
return s(r, i.request), i;
|
|
105
|
-
}, p = async (e, t) => {
|
|
106
|
-
let { nullifierCount: n } = await a("/estimate-nullifiers", {
|
|
21
|
+
}), p = async (t, n, i = t.userKeys) => {
|
|
22
|
+
let a = {
|
|
23
|
+
...n,
|
|
24
|
+
amountChanges: n.amountChanges.map(String),
|
|
25
|
+
recipientAmounts: n.recipientAmounts?.map((e) => e.map(String)),
|
|
26
|
+
selfOutputAmounts: n.selfOutputAmounts?.map(String),
|
|
27
|
+
messageSeed: n.messageSeed?.toString(),
|
|
28
|
+
nullifyingKey: i.getShieldedPrivateKey(),
|
|
29
|
+
spendingPublicKey: i.getSpendingKeyPair().pubSpendingBJJPoint.map(String),
|
|
30
|
+
slippageValues: n.slippageValues?.map(String)
|
|
31
|
+
}, o = await r(`${e}/prepare-tx`, a);
|
|
32
|
+
return c(a, o), o;
|
|
33
|
+
}, m = async (e, t) => {
|
|
34
|
+
let { nullifierCount: n } = await u("/estimate-nullifiers", {
|
|
107
35
|
...t,
|
|
108
36
|
amountChanges: t.amountChanges.map(String),
|
|
109
37
|
nullifyingKey: e.userKeys.getShieldedPrivateKey(),
|
|
110
38
|
spendingPublicKey: e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint.map(String)
|
|
111
39
|
});
|
|
112
40
|
return n;
|
|
113
|
-
},
|
|
114
|
-
let
|
|
115
|
-
...
|
|
116
|
-
amountChanges:
|
|
117
|
-
relayerFee:
|
|
118
|
-
variableRate:
|
|
119
|
-
swapperAccountSalt:
|
|
120
|
-
recipientAmounts:
|
|
121
|
-
messageSeed:
|
|
122
|
-
nullifyingKey:
|
|
123
|
-
spendingPublicKey:
|
|
124
|
-
},
|
|
125
|
-
return
|
|
126
|
-
},
|
|
127
|
-
let
|
|
128
|
-
...
|
|
129
|
-
nullifyingKey:
|
|
130
|
-
spendingPublicKey:
|
|
131
|
-
},
|
|
132
|
-
return
|
|
133
|
-
},
|
|
134
|
-
let
|
|
135
|
-
...
|
|
136
|
-
feeStructures:
|
|
137
|
-
nullifyingKey:
|
|
138
|
-
spendingPublicKey:
|
|
139
|
-
});
|
|
140
|
-
return
|
|
141
|
-
},
|
|
41
|
+
}, h = async (t, n, i = t.userKeys) => {
|
|
42
|
+
let a = {
|
|
43
|
+
...n,
|
|
44
|
+
amountChanges: n.amountChanges.map(String),
|
|
45
|
+
relayerFee: n.relayerFee?.toString(),
|
|
46
|
+
variableRate: n.variableRate?.toString(),
|
|
47
|
+
swapperAccountSalt: n.swapperAccountSalt?.toString(),
|
|
48
|
+
recipientAmounts: n.recipientAmounts?.map(String),
|
|
49
|
+
messageSeed: n.messageSeed?.toString(),
|
|
50
|
+
nullifyingKey: i.getShieldedPrivateKey(),
|
|
51
|
+
spendingPublicKey: i.getSpendingKeyPair().pubSpendingBJJPoint.map(String)
|
|
52
|
+
}, s = await r(`${e}/prepare-solana-tx`, a);
|
|
53
|
+
return o(a, s), s;
|
|
54
|
+
}, g = async (t, n) => {
|
|
55
|
+
let i = {
|
|
56
|
+
...n,
|
|
57
|
+
nullifyingKey: t.userKeys.getShieldedPrivateKey(),
|
|
58
|
+
spendingPublicKey: t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint.map(String)
|
|
59
|
+
}, a = await r(`${e}/prepare-stuck-withdraw`, i);
|
|
60
|
+
return s(i, a), a.jobs;
|
|
61
|
+
}, _ = async (t, n) => {
|
|
62
|
+
let i = Object.fromEntries(Object.entries(n.feeStructures).map(([e, t]) => [e, f(t)])), o = {
|
|
63
|
+
...n,
|
|
64
|
+
feeStructures: i,
|
|
65
|
+
nullifyingKey: t.userKeys.getShieldedPrivateKey(),
|
|
66
|
+
spendingPublicKey: t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint.map(String)
|
|
67
|
+
}, s = await r(`${e}/prepare-solana-stuck-withdraw`, o);
|
|
68
|
+
return a(o, s), s.jobs;
|
|
69
|
+
}, v = async (e, t) => u("/finalize-tx", {
|
|
142
70
|
jobId: e,
|
|
143
|
-
eddsaSignature:
|
|
144
|
-
}),
|
|
71
|
+
eddsaSignature: d(t)
|
|
72
|
+
}), y = async (e, t) => u("/finalize-solana-tx", {
|
|
145
73
|
jobId: e,
|
|
146
|
-
eddsaSignature:
|
|
147
|
-
}),
|
|
148
|
-
let { txHash: i } = await
|
|
74
|
+
eddsaSignature: d(t)
|
|
75
|
+
}), b = async (e, t, n, r) => {
|
|
76
|
+
let { txHash: i } = await u("/finalize-tx-relay", {
|
|
149
77
|
jobId: e,
|
|
150
|
-
eddsaSignature:
|
|
78
|
+
eddsaSignature: d(t),
|
|
151
79
|
chainId: n,
|
|
152
80
|
adminData: r?.adminData,
|
|
153
81
|
authorizationData: r?.authorizationData,
|
|
154
82
|
withUniswapWorkAround: r?.withUniswapWorkAround
|
|
155
83
|
});
|
|
156
84
|
return i;
|
|
157
|
-
},
|
|
158
|
-
let { txHash: i } = await
|
|
85
|
+
}, x = async (e, t, n, r) => {
|
|
86
|
+
let { txHash: i } = await u("/finalize-solana-tx-relay", {
|
|
159
87
|
jobId: e,
|
|
160
|
-
eddsaSignature:
|
|
88
|
+
eddsaSignature: d(t),
|
|
161
89
|
chainId: n,
|
|
162
90
|
adminData: r?.adminData
|
|
163
91
|
});
|
|
164
92
|
return i;
|
|
165
93
|
};
|
|
166
94
|
//#endregion
|
|
167
|
-
export {
|
|
95
|
+
export { l as collectInputCommitments, m as estimateNullifiersEnclaveCall, y as finalizeSolanaTxEnclaveCall, x as finalizeSolanaTxEnclaveCallRelay, v as finalizeTxEnclaveCall, b as finalizeTxEnclaveCallRelay, _ as prepareSolanaStuckWithdrawEnclaveCall, h as prepareSolanaTxEnclaveCall, g as prepareStuckWithdrawEnclaveCall, p as prepareTxEnclaveCall };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../crypto/poseidon.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../../data-structures/utxo/Utxo.cjs`),o=require(`../utils/solanaMint.utils.cjs`),s=require(`./common.snarkjs.cjs`),c=require(`./signedMessageHash.cjs`),l=require(`../pre-transaction/getSolanaCalldataHash.cjs`);let u=require(`ethers`),d=require(`@solana/web3.js`);var f=e=>e?.inputUtxos.flat().filter(e=>BigInt(e.amount)>0n).map(e=>new a.Utxo({amount:BigInt(e.amount),erc20TokenAddress:e.erc20TokenAddress,stealthAddress:e.stealthAddress,H0:[BigInt(e.H0[0]),BigInt(e.H0[1])],timeStamp:e.timeStamp}).getCommitment()),p=e=>{if(Array.isArray(e))return`[${e.map(p).join(`,`)}]`;if(e&&typeof e==`object`){let t=e;return`{${Object.keys(t).filter(e=>t[e]!==void 0).sort().map(e=>`${JSON.stringify(e)}:${p(t[e])}`).join(`,`)}}`}return JSON.stringify(e)},m=(e,t)=>{if(p({chainId:String(e.chainId),hinkalAddress:e.hinkalAddress??``,erc20Addresses:e.erc20Addresses,amountChanges:e.amountChanges,externalAddress:e.externalAddress,...e.originalSender?{originalSender:e.originalSender}:{},relay:e.relay??``,feeStructure:e.feeStructure?{feeToken:e.feeStructure.feeToken,flatFee:e.feeStructure.flatFee.toString(),variableRate:e.feeStructure.variableRate.toString()}:null,externalActionId:e.externalActionId??``,externalActionMetadata:e.externalActionMetadata??``,onChainCreation:e.onChainCreation??null,recipientAddress:e.recipientAddress??null,recipientAmounts:e.recipientAmounts??null,selfOutputAmounts:e.selfOutputAmounts??null,inputCommitments:e.inputCommitments??null,useBlockedUtxos:e.useBlockedUtxos??!1,createBlockedUtxos:e.createBlockedUtxos??!1,...e.forceEmptyUtxos?{forceEmptyUtxos:!0}:{},messageSeed:e.messageSeed??``,skipLock:e.skipLock??!1,...e.speculative?{speculative:e.speculative}:{},slippageValues:e.slippageValues??null})!==p(t))throw Error(`Enclave prepare-tx response does not match the request sent - refusing to sign`)},h=(e,t,n,r,i,o,s,c)=>{let l=s.map(BigInt),u=new Set,d=e.map((e,s)=>t[s].map((t,c)=>{let d=BigInt(t);if(d===0n)return`0`;let f=new a.Utxo({amount:d,erc20TokenAddress:e,nullifyingKey:o,spendingPublicKey:l,H0:[BigInt(n[s][c]),BigInt(r[s][c])],timeStamp:i[s][c]});return u.add(f.getCommitment()),f.getNullifier()}));if(c&&(u.size!==c.length||!c.every(e=>u.has(e))))throw Error(`Enclave prepare-tx spent a different set of notes than the caller authorized - refusing to sign`);return d},g=(e,t)=>e===0n?`0`:new a.Utxo({amount:e,...t}).getCommitment(),_=(e,t,n,r,i,a,o,s,c,l)=>{if((c?.length??0)!==(l?.length??0))throw Error(`Enclave prepare-tx request has mismatched recipientAddress/recipientAmounts - refusing to sign`);let u=t?.length??1,d=s.map(BigInt);return e.map((e,t)=>{let s=Array.from({length:u},(s,c)=>g(BigInt(n[t][c]),{erc20TokenAddress:e,nullifyingKey:o,spendingPublicKey:d,H0:[BigInt(r[t][c]),BigInt(i[t][c])],timeStamp:a})),f=(c??[]).map((n,r)=>{let[i,o,s]=n.split(`,`);return g(BigInt(l[r][t]),{erc20TokenAddress:e,stealthAddress:i,H0:[BigInt(o),BigInt(s)],timeStamp:a})});return[...s,...f]})},v=(e,t,n,r,i)=>{r&&r.forEach((e,t)=>{if(n[0][t]!==e)throw Error(`Enclave prepare-tx self-output amounts do not match the requested selfOutputAmounts - refusing to sign`)});let a=r?.length??1;e.forEach((e,r)=>{let o=t[r].reduce((e,t)=>e+BigInt(t),0n),s=n[r].slice(0,a).reduce((e,t)=>e+BigInt(t),0n);if(o+BigInt(i[r])!==s)throw Error(`Enclave prepare-tx self-output amount does not match input total + requested amountChanges - refusing to sign`)})},y=e=>e.erc20Addresses.map((t,n)=>BigInt(e.amountChanges[n])+(e.recipientAmounts??[]).reduce((e,t)=>e+BigInt(t[n]),0n)),b=e=>e<0n?t.CIRCOM_P+e:e,x=(t,n,r)=>r.length===0?`mainEVMCircuitMin0`:`${e.isTronLike(t)?`mainTronCircuit`:`mainEVMCircuit`}${n.length}x${n[0].length}x${r[0].length}`,S=(t,n,r)=>e.isTronLike(t)?c.computeSignedMessageHashTron(n):c.computeSignedMessageHashEvm({...n,...r}),C=(e,i,a,o)=>{let c=r.poseidonFunction(BigInt(i.messageSeed)),l=e.relay||t.zeroAddress,u=l!==t.zeroAddress&&e.feeStructure?e.feeStructure:n.zeroFeeStructure,d=e.externalActionMetadata||`0x00`,f=e.erc20Addresses.map((t,n)=>e.onChainCreation?.[n]??!1),p=y(e),m=e.slippageValues?e.slippageValues.map(BigInt):s.getSlippageValues(p);return{calldataHash:s.createCallDataHash(s.calcPublicSignalCount(x(e.chainId,a,o),e.erc20Addresses,p,a,o),l,e.externalAddress,e.externalActionId??0n,c,d,i.encryptedOutputs,i.onChainEncryptedOutput,void 0,m,f,u,e.originalSender,void 0,e.chainId,e.createBlockedUtxos??!1),message:c,amountChangesModWrapped:p.map(b)}},w=(e,t,n,r,a,o)=>{if(!e?.some(Boolean))return;let[s,c]=i.UserKeys.getH1FromH0([BigInt(t),BigInt(n)],o);if(s!==BigInt(r)||c!==BigInt(a))throw Error(`Enclave prepare-tx tx-level stealth pair is not derived from the caller's own key - refusing to sign`)},T=(e,t,n,r,i,a,o,s)=>{if(S(e,{rootHashHinkal:BigInt(n.rootHashHinkal),erc20TokenAddresses:n.request.erc20Addresses,amountChanges:s,outTimeStamp:BigInt(n.outTimeStamp),inNullifiers:r,outCommitments:i,calldataHash:a,message:o,chainId:BigInt(e),verifyingContract:t},{outH1Ax:BigInt(n.outH1Ax),outH1Ay:BigInt(n.outH1Ay),H0Ax:BigInt(n.h0Ax),H0Ay:BigInt(n.h0Ay)})!==BigInt(n.signedMessageHash))throw Error(`Enclave prepare-tx signedMessageHash does not match one built from the caller's own data - refusing to sign`)},E=e=>e.map(e=>o.formatMintAddress(e).compressedAddress),D=e=>e.mintAddresses.map((t,n)=>BigInt(e.amountChanges[n])+(e.recipientAmounts?BigInt(e.recipientAmounts[n]):0n)),O=(e,t,n)=>{if(e.tokenNumber!==t.tokenNumber||e.nullifierAmount!==t.nullifierAmount||e.outputAmount!==t.outputAmount)throw Error(`Enclave ${n} dimensions do not match the caller's own data - refusing to sign`)},k=(e,t,n,i)=>{let a=r.poseidonFunction(BigInt(t.messageSeed));O(t.dimensions,{tokenNumber:e.mintAddresses.length,nullifierAmount:n[0]?.length??0,outputAmount:i[0]?.length??0},`prepare-solana-tx`);let o=e.mintAddresses.map((t,n)=>e.onChainCreation?.[n]??!1),s=o.some(Boolean),c=t.encryptedOutputs.flatMap((e,t)=>o[t]?e.map(()=>[]):e.map(e=>Array.from(u.ethers.getBytes(e)))),f=s?t.onChainEncryptedOutput:`0x`,p=(e.hinkalInstructions??[]).map(e=>({accountIndexes:Buffer.from(e.accountIndexes),data:Buffer.from(e.data),programIndex:e.programIndex})),m=(e.remainingAccounts??[]).map(e=>({pubkey:new d.PublicKey(e.pubkey),isSigner:e.isSigner,isWritable:e.isWritable}));return{calldataHash:l.getSolanaCalldataHash(t.dimensions,new d.PublicKey(e.recipient),new d.PublicKey(e.signer??e.relayAddress),c,f,BigInt(e.relayerFee??`0`),BigInt(e.variableRate??`0`),p,m),message:a}},A=(e,t,n,r,i,a,o,s,l)=>{if(c.computeSignedMessageHashSolana({rootHashHinkal:BigInt(e.rootHashHinkal),mintAccountPart1:t,mintAccountPart2:n,amountChanges:s,outTimeStamp:BigInt(e.outTimeStamp),inNullifiers:r,outCommitments:i,calldataHash:a,message:o,swapperAccountAdditionalSeed:l,outH1Ay:BigInt(e.outH1Ay),H0Ax:BigInt(e.h0Ax),H0Ay:BigInt(e.h0Ay)})!==BigInt(e.signedMessageHash))throw Error(`Enclave prepare-solana-tx signedMessageHash does not match one built from the caller's own data - refusing to sign`)},j=(e,t)=>{let n={chainId:String(e.chainId),mintAddresses:e.mintAddresses,amountChanges:e.amountChanges,relayAddress:e.relayAddress,recipient:e.recipient,signer:e.signer??e.relayAddress,functionName:e.functionName??`transact`,accounts:e.accounts,onChainCreation:e.onChainCreation??null,relayerFee:e.relayerFee??`0`,variableRate:e.variableRate??`0`,hinkalInstructions:e.hinkalInstructions??null,remainingAccounts:e.remainingAccounts??null,swapperAccountSalt:e.swapperAccountSalt??`0`,recipientAddress:e.recipientAddress??``,recipientAmounts:e.recipientAmounts??null,inputCommitments:e.inputCommitments??null,useBlockedUtxos:e.useBlockedUtxos??!1,messageSeed:e.messageSeed??``};if(e.recipientAmount&&(n.recipientAmount=e.recipientAmount),e.displayRecipient&&(n.displayRecipient=e.displayRecipient),e.speculative&&(n.speculative=e.speculative),p(n)!==p(t))throw Error(`Enclave prepare-solana-tx response does not match the request sent - refusing to sign`)},M=(e,t,n,i,a,o,c,l,u)=>{let d=h([n],u.inAmounts,u.inH0Ax,u.inH0Ay,u.inTimeStamps,c,l,void 0),f=_([n],void 0,u.outAmounts,u.outNoteH0Ax,u.outNoteH0Ay,u.outTimeStamp,c,l,void 0,void 0),p=[-u.inAmounts[0].reduce((e,t)=>e+BigInt(t),0n)];v([n],u.inAmounts,u.outAmounts,void 0,p.map(String));let m=p.map(b),g=r.poseidonFunction(BigInt(u.messageSeed)),y=s.getSlippageValues(p),C=s.createCallDataHash(s.calcPublicSignalCount(x(e,d,f),[n],m,d,f),i,a,0n,g,`0x00`,u.encryptedOutputs,u.onChainEncryptedOutput,void 0,y,[!1],o,void 0,void 0,e,!1);if(S(e,{rootHashHinkal:BigInt(u.rootHashHinkal),erc20TokenAddresses:[n],amountChanges:m,outTimeStamp:BigInt(u.outTimeStamp),inNullifiers:d,outCommitments:f,calldataHash:C,message:g,chainId:BigInt(e),verifyingContract:t},{outH1Ax:BigInt(u.outH1Ax),outH1Ay:BigInt(u.outH1Ay),H0Ax:BigInt(u.h0Ax),H0Ay:BigInt(u.h0Ay)})!==BigInt(u.signedMessageHash))throw Error(`Enclave prepare-stuck-withdraw job signedMessageHash does not match one built from the caller's own data - refusing to sign`)},N=(e,t,n,i,a,s,f)=>{let{compressedAddress:p,mintAccountPart1:m,mintAccountPart2:g}=o.formatMintAddress(e),y=h([p],f.inAmounts,f.inH0Ax,f.inH0Ay,f.inTimeStamps,a,s,void 0),x=_([p],void 0,f.outAmounts,f.outNoteH0Ax,f.outNoteH0Ay,f.outTimeStamp,a,s,void 0,void 0),S=[-f.inAmounts[0].reduce((e,t)=>e+BigInt(t),0n)];v([p],f.inAmounts,f.outAmounts,void 0,S.map(String));let C=S.map(b),w=r.poseidonFunction(BigInt(f.messageSeed)),T=f.encryptedOutputs.flatMap(e=>e.map(e=>Array.from(u.ethers.getBytes(e))));O(f.dimensions,{tokenNumber:1,nullifierAmount:y[0].length,outputAmount:x[0].length},`prepare-solana-stuck-withdraw`);let E=l.getSolanaCalldataHash(f.dimensions,new d.PublicKey(n),new d.PublicKey(t),T,`0x`,i.flatFee,i.variableRate,[],[]);if(c.computeSignedMessageHashSolana({rootHashHinkal:BigInt(f.rootHashHinkal),mintAccountPart1:[m],mintAccountPart2:[g],amountChanges:C,outTimeStamp:BigInt(f.outTimeStamp),inNullifiers:y,outCommitments:x,calldataHash:E,message:w,swapperAccountAdditionalSeed:r.poseidonFunction(0n),outH1Ay:BigInt(f.outH1Ay),H0Ax:BigInt(f.h0Ax),H0Ay:BigInt(f.h0Ay)})!==BigInt(f.signedMessageHash))throw Error(`Enclave prepare-solana-stuck-withdraw job signedMessageHash does not match one built from the caller's own data - refusing to sign`)},P=(e,t)=>{if(p({chainId:String(e.chainId),hinkalAddress:e.hinkalAddress??``,erc20Address:e.erc20Address,externalAddress:e.externalAddress,relay:e.relay,feeStructure:{feeToken:e.feeStructure.feeToken,flatFee:e.feeStructure.flatFee.toString(),variableRate:e.feeStructure.variableRate.toString()},hashedEthereumAddress:e.hashedEthereumAddress})!==p(t))throw Error(`Enclave prepare-stuck-withdraw response does not match the request sent - refusing to sign`)},F=(e,t)=>{if(p({chainId:String(e.chainId),mintAddress:e.mintAddress,recipient:e.recipient,relayAddress:e.relayAddress,signer:e.relayAddress,accounts:e.accounts,feeStructures:e.feeStructures,hashedEthereumAddress:e.hashedEthereumAddress})!==p(t))throw Error(`Enclave prepare-solana-stuck-withdraw response does not match the request sent - refusing to sign`)},I=(e,t)=>{m(e,t.request);let n=e.inputCommitments??f(e.speculative)??(e.forceEmptyUtxos?[]:void 0),r=h(e.erc20Addresses,t.inAmounts,t.inH0Ax,t.inH0Ay,t.inTimeStamps,e.nullifyingKey,e.spendingPublicKey,n),i=_(e.erc20Addresses,e.selfOutputAmounts,t.outAmounts,t.outNoteH0Ax,t.outNoteH0Ay,t.outTimeStamp,e.nullifyingKey,e.spendingPublicKey,e.recipientAddress,e.recipientAmounts);v(e.erc20Addresses,t.inAmounts,t.outAmounts,e.selfOutputAmounts,e.amountChanges),w(e.onChainCreation,t.h0Ax,t.h0Ay,t.outH1Ax,t.outH1Ay,e.nullifyingKey);let{calldataHash:a,message:o,amountChangesModWrapped:s}=C(e,t,r,i);T(e.chainId,e.hinkalAddress??``,t,r,i,a,o,s)},L=(e,t)=>{j(e,t.request);let n=E(e.mintAddresses),i=e.recipientAddress?[e.recipientAddress]:void 0,a=e.recipientAmounts?[e.recipientAmounts]:void 0,s=h(n,t.inAmounts,t.inH0Ax,t.inH0Ay,t.inTimeStamps,e.nullifyingKey,e.spendingPublicKey,e.inputCommitments??f(e.speculative)),c=_(n,void 0,t.outAmounts,t.outNoteH0Ax,t.outNoteH0Ay,t.outTimeStamp,e.nullifyingKey,e.spendingPublicKey,i,a);v(n,t.inAmounts,t.outAmounts,void 0,e.amountChanges);let{calldataHash:l,message:u}=k(e,t,s,c),d=D(e).map(b),p=e.mintAddresses.map(e=>o.formatMintAddress(e)),m=r.poseidonFunction(BigInt(e.swapperAccountSalt??`0`));A(t,p.map(e=>e.mintAccountPart1),p.map(e=>e.mintAccountPart2),s,c,l,u,d,m)},R=(e,t)=>{P(e,t.request),t.jobs.forEach(t=>M(e.chainId,e.hinkalAddress??``,e.erc20Address,e.relay,e.externalAddress,e.feeStructure,e.nullifyingKey,e.spendingPublicKey,t))},z=(e,t)=>{F(e,t.request),t.jobs.forEach(t=>{let n=t.inAmounts[0].filter(e=>BigInt(e)>0n).length,r=e.feeStructures[String(n)];if(!r)throw Error(`Enclave prepare-solana-stuck-withdraw response uses nullifierCount ${n} with no matching feeStructure - refusing to sign`);N(e.mintAddress,e.relayAddress,e.recipient,{feeToken:r.feeToken,flatFee:BigInt(r.flatFee),variableRate:BigInt(r.variableRate)},e.nullifyingKey,e.spendingPublicKey,t)})};exports.verifyPrepareSolanaStuckWithdrawResponse=z,exports.verifyPrepareSolanaTxResponse=L,exports.verifyPrepareStuckWithdrawResponse=R,exports.verifyPrepareTxResponse=I;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PrepareSolanaStuckWithdrawRequestType, PrepareSolanaStuckWithdrawResponseType, PrepareSolanaTxRequestType, PrepareSolanaTxResponseType, PrepareStuckWithdrawRequestType, PrepareStuckWithdrawResponseType, PrepareTxRequestType, PrepareTxResponseType } from '../../types/remote-tx-build.types';
|
|
2
|
+
export declare const verifyPrepareTxResponse: (payload: PrepareTxRequestType, response: PrepareTxResponseType) => void;
|
|
3
|
+
export declare const verifyPrepareSolanaTxResponse: (payload: PrepareSolanaTxRequestType, response: PrepareSolanaTxResponseType) => void;
|
|
4
|
+
export declare const verifyPrepareStuckWithdrawResponse: (payload: PrepareStuckWithdrawRequestType, response: PrepareStuckWithdrawResponseType) => void;
|
|
5
|
+
export declare const verifyPrepareSolanaStuckWithdrawResponse: (payload: PrepareSolanaStuckWithdrawRequestType, response: PrepareSolanaStuckWithdrawResponseType) => void;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { isTronLike as e } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { CIRCOM_P as t, zeroAddress as n } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { zeroFeeStructure as r } from "../../types/hinkal.types.mjs";
|
|
4
|
+
import { poseidonFunction as i } from "../../crypto/poseidon.mjs";
|
|
5
|
+
import { UserKeys as a } from "../../data-structures/crypto-keys/keys.mjs";
|
|
6
|
+
import { Utxo as o } from "../../data-structures/utxo/Utxo.mjs";
|
|
7
|
+
import { formatMintAddress as s } from "../utils/solanaMint.utils.mjs";
|
|
8
|
+
import { calcPublicSignalCount as c, createCallDataHash as l, getSlippageValues as u } from "./common.snarkjs.mjs";
|
|
9
|
+
import { computeSignedMessageHashEvm as d, computeSignedMessageHashSolana as f, computeSignedMessageHashTron as p } from "./signedMessageHash.mjs";
|
|
10
|
+
import { getSolanaCalldataHash as m } from "../pre-transaction/getSolanaCalldataHash.mjs";
|
|
11
|
+
import { ethers as h } from "ethers";
|
|
12
|
+
import { PublicKey as g } from "@solana/web3.js";
|
|
13
|
+
//#region libs/shared/common/src/functions/snarkjs/constructTxEnclaveVerify.ts
|
|
14
|
+
var _ = (e) => e?.inputUtxos.flat().filter((e) => BigInt(e.amount) > 0n).map((e) => new o({
|
|
15
|
+
amount: BigInt(e.amount),
|
|
16
|
+
erc20TokenAddress: e.erc20TokenAddress,
|
|
17
|
+
stealthAddress: e.stealthAddress,
|
|
18
|
+
H0: [BigInt(e.H0[0]), BigInt(e.H0[1])],
|
|
19
|
+
timeStamp: e.timeStamp
|
|
20
|
+
}).getCommitment()), v = (e) => {
|
|
21
|
+
if (Array.isArray(e)) return `[${e.map(v).join(",")}]`;
|
|
22
|
+
if (e && typeof e == "object") {
|
|
23
|
+
let t = e;
|
|
24
|
+
return `{${Object.keys(t).filter((e) => t[e] !== void 0).sort().map((e) => `${JSON.stringify(e)}:${v(t[e])}`).join(",")}}`;
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify(e);
|
|
27
|
+
}, y = (e, t) => {
|
|
28
|
+
if (v({
|
|
29
|
+
chainId: String(e.chainId),
|
|
30
|
+
hinkalAddress: e.hinkalAddress ?? "",
|
|
31
|
+
erc20Addresses: e.erc20Addresses,
|
|
32
|
+
amountChanges: e.amountChanges,
|
|
33
|
+
externalAddress: e.externalAddress,
|
|
34
|
+
...e.originalSender ? { originalSender: e.originalSender } : {},
|
|
35
|
+
relay: e.relay ?? "",
|
|
36
|
+
feeStructure: e.feeStructure ? {
|
|
37
|
+
feeToken: e.feeStructure.feeToken,
|
|
38
|
+
flatFee: e.feeStructure.flatFee.toString(),
|
|
39
|
+
variableRate: e.feeStructure.variableRate.toString()
|
|
40
|
+
} : null,
|
|
41
|
+
externalActionId: e.externalActionId ?? "",
|
|
42
|
+
externalActionMetadata: e.externalActionMetadata ?? "",
|
|
43
|
+
onChainCreation: e.onChainCreation ?? null,
|
|
44
|
+
recipientAddress: e.recipientAddress ?? null,
|
|
45
|
+
recipientAmounts: e.recipientAmounts ?? null,
|
|
46
|
+
selfOutputAmounts: e.selfOutputAmounts ?? null,
|
|
47
|
+
inputCommitments: e.inputCommitments ?? null,
|
|
48
|
+
useBlockedUtxos: e.useBlockedUtxos ?? !1,
|
|
49
|
+
createBlockedUtxos: e.createBlockedUtxos ?? !1,
|
|
50
|
+
...e.forceEmptyUtxos ? { forceEmptyUtxos: !0 } : {},
|
|
51
|
+
messageSeed: e.messageSeed ?? "",
|
|
52
|
+
skipLock: e.skipLock ?? !1,
|
|
53
|
+
...e.speculative ? { speculative: e.speculative } : {},
|
|
54
|
+
slippageValues: e.slippageValues ?? null
|
|
55
|
+
}) !== v(t)) throw Error("Enclave prepare-tx response does not match the request sent - refusing to sign");
|
|
56
|
+
}, b = (e, t, n, r, i, a, s, c) => {
|
|
57
|
+
let l = s.map(BigInt), u = /* @__PURE__ */ new Set(), d = e.map((e, s) => t[s].map((t, c) => {
|
|
58
|
+
let d = BigInt(t);
|
|
59
|
+
if (d === 0n) return "0";
|
|
60
|
+
let f = new o({
|
|
61
|
+
amount: d,
|
|
62
|
+
erc20TokenAddress: e,
|
|
63
|
+
nullifyingKey: a,
|
|
64
|
+
spendingPublicKey: l,
|
|
65
|
+
H0: [BigInt(n[s][c]), BigInt(r[s][c])],
|
|
66
|
+
timeStamp: i[s][c]
|
|
67
|
+
});
|
|
68
|
+
return u.add(f.getCommitment()), f.getNullifier();
|
|
69
|
+
}));
|
|
70
|
+
if (c && (u.size !== c.length || !c.every((e) => u.has(e)))) throw Error("Enclave prepare-tx spent a different set of notes than the caller authorized - refusing to sign");
|
|
71
|
+
return d;
|
|
72
|
+
}, x = (e, t) => e === 0n ? "0" : new o({
|
|
73
|
+
amount: e,
|
|
74
|
+
...t
|
|
75
|
+
}).getCommitment(), S = (e, t, n, r, i, a, o, s, c, l) => {
|
|
76
|
+
if ((c?.length ?? 0) !== (l?.length ?? 0)) throw Error("Enclave prepare-tx request has mismatched recipientAddress/recipientAmounts - refusing to sign");
|
|
77
|
+
let u = t?.length ?? 1, d = s.map(BigInt);
|
|
78
|
+
return e.map((e, t) => {
|
|
79
|
+
let s = Array.from({ length: u }, (s, c) => x(BigInt(n[t][c]), {
|
|
80
|
+
erc20TokenAddress: e,
|
|
81
|
+
nullifyingKey: o,
|
|
82
|
+
spendingPublicKey: d,
|
|
83
|
+
H0: [BigInt(r[t][c]), BigInt(i[t][c])],
|
|
84
|
+
timeStamp: a
|
|
85
|
+
})), f = (c ?? []).map((n, r) => {
|
|
86
|
+
let [i, o, s] = n.split(",");
|
|
87
|
+
return x(BigInt(l[r][t]), {
|
|
88
|
+
erc20TokenAddress: e,
|
|
89
|
+
stealthAddress: i,
|
|
90
|
+
H0: [BigInt(o), BigInt(s)],
|
|
91
|
+
timeStamp: a
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return [...s, ...f];
|
|
95
|
+
});
|
|
96
|
+
}, C = (e, t, n, r, i) => {
|
|
97
|
+
r && r.forEach((e, t) => {
|
|
98
|
+
if (n[0][t] !== e) throw Error("Enclave prepare-tx self-output amounts do not match the requested selfOutputAmounts - refusing to sign");
|
|
99
|
+
});
|
|
100
|
+
let a = r?.length ?? 1;
|
|
101
|
+
e.forEach((e, r) => {
|
|
102
|
+
let o = t[r].reduce((e, t) => e + BigInt(t), 0n), s = n[r].slice(0, a).reduce((e, t) => e + BigInt(t), 0n);
|
|
103
|
+
if (o + BigInt(i[r]) !== s) throw Error("Enclave prepare-tx self-output amount does not match input total + requested amountChanges - refusing to sign");
|
|
104
|
+
});
|
|
105
|
+
}, w = (e) => e.erc20Addresses.map((t, n) => BigInt(e.amountChanges[n]) + (e.recipientAmounts ?? []).reduce((e, t) => e + BigInt(t[n]), 0n)), T = (e) => e < 0n ? t + e : e, E = (t, n, r) => r.length === 0 ? "mainEVMCircuitMin0" : `${e(t) ? "mainTronCircuit" : "mainEVMCircuit"}${n.length}x${n[0].length}x${r[0].length}`, D = (t, n, r) => e(t) ? p(n) : d({
|
|
106
|
+
...n,
|
|
107
|
+
...r
|
|
108
|
+
}), O = (e, t, a, o) => {
|
|
109
|
+
let s = i(BigInt(t.messageSeed)), d = e.relay || n, f = d !== n && e.feeStructure ? e.feeStructure : r, p = e.externalActionMetadata || "0x00", m = e.erc20Addresses.map((t, n) => e.onChainCreation?.[n] ?? !1), h = w(e), g = e.slippageValues ? e.slippageValues.map(BigInt) : u(h);
|
|
110
|
+
return {
|
|
111
|
+
calldataHash: l(c(E(e.chainId, a, o), e.erc20Addresses, h, a, o), d, e.externalAddress, e.externalActionId ?? 0n, s, p, t.encryptedOutputs, t.onChainEncryptedOutput, void 0, g, m, f, e.originalSender, void 0, e.chainId, e.createBlockedUtxos ?? !1),
|
|
112
|
+
message: s,
|
|
113
|
+
amountChangesModWrapped: h.map(T)
|
|
114
|
+
};
|
|
115
|
+
}, k = (e, t, n, r, i, o) => {
|
|
116
|
+
if (!e?.some(Boolean)) return;
|
|
117
|
+
let [s, c] = a.getH1FromH0([BigInt(t), BigInt(n)], o);
|
|
118
|
+
if (s !== BigInt(r) || c !== BigInt(i)) throw Error("Enclave prepare-tx tx-level stealth pair is not derived from the caller's own key - refusing to sign");
|
|
119
|
+
}, A = (e, t, n, r, i, a, o, s) => {
|
|
120
|
+
if (D(e, {
|
|
121
|
+
rootHashHinkal: BigInt(n.rootHashHinkal),
|
|
122
|
+
erc20TokenAddresses: n.request.erc20Addresses,
|
|
123
|
+
amountChanges: s,
|
|
124
|
+
outTimeStamp: BigInt(n.outTimeStamp),
|
|
125
|
+
inNullifiers: r,
|
|
126
|
+
outCommitments: i,
|
|
127
|
+
calldataHash: a,
|
|
128
|
+
message: o,
|
|
129
|
+
chainId: BigInt(e),
|
|
130
|
+
verifyingContract: t
|
|
131
|
+
}, {
|
|
132
|
+
outH1Ax: BigInt(n.outH1Ax),
|
|
133
|
+
outH1Ay: BigInt(n.outH1Ay),
|
|
134
|
+
H0Ax: BigInt(n.h0Ax),
|
|
135
|
+
H0Ay: BigInt(n.h0Ay)
|
|
136
|
+
}) !== BigInt(n.signedMessageHash)) throw Error("Enclave prepare-tx signedMessageHash does not match one built from the caller's own data - refusing to sign");
|
|
137
|
+
}, j = (e) => e.map((e) => s(e).compressedAddress), M = (e) => e.mintAddresses.map((t, n) => BigInt(e.amountChanges[n]) + (e.recipientAmounts ? BigInt(e.recipientAmounts[n]) : 0n)), N = (e, t, n) => {
|
|
138
|
+
if (e.tokenNumber !== t.tokenNumber || e.nullifierAmount !== t.nullifierAmount || e.outputAmount !== t.outputAmount) throw Error(`Enclave ${n} dimensions do not match the caller's own data - refusing to sign`);
|
|
139
|
+
}, P = (e, t, n, r) => {
|
|
140
|
+
let a = i(BigInt(t.messageSeed));
|
|
141
|
+
N(t.dimensions, {
|
|
142
|
+
tokenNumber: e.mintAddresses.length,
|
|
143
|
+
nullifierAmount: n[0]?.length ?? 0,
|
|
144
|
+
outputAmount: r[0]?.length ?? 0
|
|
145
|
+
}, "prepare-solana-tx");
|
|
146
|
+
let o = e.mintAddresses.map((t, n) => e.onChainCreation?.[n] ?? !1), s = o.some(Boolean), c = t.encryptedOutputs.flatMap((e, t) => o[t] ? e.map(() => []) : e.map((e) => Array.from(h.getBytes(e)))), l = s ? t.onChainEncryptedOutput : "0x", u = (e.hinkalInstructions ?? []).map((e) => ({
|
|
147
|
+
accountIndexes: Buffer.from(e.accountIndexes),
|
|
148
|
+
data: Buffer.from(e.data),
|
|
149
|
+
programIndex: e.programIndex
|
|
150
|
+
})), d = (e.remainingAccounts ?? []).map((e) => ({
|
|
151
|
+
pubkey: new g(e.pubkey),
|
|
152
|
+
isSigner: e.isSigner,
|
|
153
|
+
isWritable: e.isWritable
|
|
154
|
+
}));
|
|
155
|
+
return {
|
|
156
|
+
calldataHash: m(t.dimensions, new g(e.recipient), new g(e.signer ?? e.relayAddress), c, l, BigInt(e.relayerFee ?? "0"), BigInt(e.variableRate ?? "0"), u, d),
|
|
157
|
+
message: a
|
|
158
|
+
};
|
|
159
|
+
}, F = (e, t, n, r, i, a, o, s, c) => {
|
|
160
|
+
if (f({
|
|
161
|
+
rootHashHinkal: BigInt(e.rootHashHinkal),
|
|
162
|
+
mintAccountPart1: t,
|
|
163
|
+
mintAccountPart2: n,
|
|
164
|
+
amountChanges: s,
|
|
165
|
+
outTimeStamp: BigInt(e.outTimeStamp),
|
|
166
|
+
inNullifiers: r,
|
|
167
|
+
outCommitments: i,
|
|
168
|
+
calldataHash: a,
|
|
169
|
+
message: o,
|
|
170
|
+
swapperAccountAdditionalSeed: c,
|
|
171
|
+
outH1Ay: BigInt(e.outH1Ay),
|
|
172
|
+
H0Ax: BigInt(e.h0Ax),
|
|
173
|
+
H0Ay: BigInt(e.h0Ay)
|
|
174
|
+
}) !== BigInt(e.signedMessageHash)) throw Error("Enclave prepare-solana-tx signedMessageHash does not match one built from the caller's own data - refusing to sign");
|
|
175
|
+
}, I = (e, t) => {
|
|
176
|
+
let n = {
|
|
177
|
+
chainId: String(e.chainId),
|
|
178
|
+
mintAddresses: e.mintAddresses,
|
|
179
|
+
amountChanges: e.amountChanges,
|
|
180
|
+
relayAddress: e.relayAddress,
|
|
181
|
+
recipient: e.recipient,
|
|
182
|
+
signer: e.signer ?? e.relayAddress,
|
|
183
|
+
functionName: e.functionName ?? "transact",
|
|
184
|
+
accounts: e.accounts,
|
|
185
|
+
onChainCreation: e.onChainCreation ?? null,
|
|
186
|
+
relayerFee: e.relayerFee ?? "0",
|
|
187
|
+
variableRate: e.variableRate ?? "0",
|
|
188
|
+
hinkalInstructions: e.hinkalInstructions ?? null,
|
|
189
|
+
remainingAccounts: e.remainingAccounts ?? null,
|
|
190
|
+
swapperAccountSalt: e.swapperAccountSalt ?? "0",
|
|
191
|
+
recipientAddress: e.recipientAddress ?? "",
|
|
192
|
+
recipientAmounts: e.recipientAmounts ?? null,
|
|
193
|
+
inputCommitments: e.inputCommitments ?? null,
|
|
194
|
+
useBlockedUtxos: e.useBlockedUtxos ?? !1,
|
|
195
|
+
messageSeed: e.messageSeed ?? ""
|
|
196
|
+
};
|
|
197
|
+
if (e.recipientAmount && (n.recipientAmount = e.recipientAmount), e.displayRecipient && (n.displayRecipient = e.displayRecipient), e.speculative && (n.speculative = e.speculative), v(n) !== v(t)) throw Error("Enclave prepare-solana-tx response does not match the request sent - refusing to sign");
|
|
198
|
+
}, L = (e, t, n, r, a, o, s, d, f) => {
|
|
199
|
+
let p = b([n], f.inAmounts, f.inH0Ax, f.inH0Ay, f.inTimeStamps, s, d, void 0), m = S([n], void 0, f.outAmounts, f.outNoteH0Ax, f.outNoteH0Ay, f.outTimeStamp, s, d, void 0, void 0), h = [-f.inAmounts[0].reduce((e, t) => e + BigInt(t), 0n)];
|
|
200
|
+
C([n], f.inAmounts, f.outAmounts, void 0, h.map(String));
|
|
201
|
+
let g = h.map(T), _ = i(BigInt(f.messageSeed)), v = u(h), y = l(c(E(e, p, m), [n], g, p, m), r, a, 0n, _, "0x00", f.encryptedOutputs, f.onChainEncryptedOutput, void 0, v, [!1], o, void 0, void 0, e, !1);
|
|
202
|
+
if (D(e, {
|
|
203
|
+
rootHashHinkal: BigInt(f.rootHashHinkal),
|
|
204
|
+
erc20TokenAddresses: [n],
|
|
205
|
+
amountChanges: g,
|
|
206
|
+
outTimeStamp: BigInt(f.outTimeStamp),
|
|
207
|
+
inNullifiers: p,
|
|
208
|
+
outCommitments: m,
|
|
209
|
+
calldataHash: y,
|
|
210
|
+
message: _,
|
|
211
|
+
chainId: BigInt(e),
|
|
212
|
+
verifyingContract: t
|
|
213
|
+
}, {
|
|
214
|
+
outH1Ax: BigInt(f.outH1Ax),
|
|
215
|
+
outH1Ay: BigInt(f.outH1Ay),
|
|
216
|
+
H0Ax: BigInt(f.h0Ax),
|
|
217
|
+
H0Ay: BigInt(f.h0Ay)
|
|
218
|
+
}) !== BigInt(f.signedMessageHash)) throw Error("Enclave prepare-stuck-withdraw job signedMessageHash does not match one built from the caller's own data - refusing to sign");
|
|
219
|
+
}, R = (e, t, n, r, a, o, c) => {
|
|
220
|
+
let { compressedAddress: l, mintAccountPart1: u, mintAccountPart2: d } = s(e), p = b([l], c.inAmounts, c.inH0Ax, c.inH0Ay, c.inTimeStamps, a, o, void 0), _ = S([l], void 0, c.outAmounts, c.outNoteH0Ax, c.outNoteH0Ay, c.outTimeStamp, a, o, void 0, void 0), v = [-c.inAmounts[0].reduce((e, t) => e + BigInt(t), 0n)];
|
|
221
|
+
C([l], c.inAmounts, c.outAmounts, void 0, v.map(String));
|
|
222
|
+
let y = v.map(T), x = i(BigInt(c.messageSeed)), w = c.encryptedOutputs.flatMap((e) => e.map((e) => Array.from(h.getBytes(e))));
|
|
223
|
+
N(c.dimensions, {
|
|
224
|
+
tokenNumber: 1,
|
|
225
|
+
nullifierAmount: p[0].length,
|
|
226
|
+
outputAmount: _[0].length
|
|
227
|
+
}, "prepare-solana-stuck-withdraw");
|
|
228
|
+
let E = m(c.dimensions, new g(n), new g(t), w, "0x", r.flatFee, r.variableRate, [], []);
|
|
229
|
+
if (f({
|
|
230
|
+
rootHashHinkal: BigInt(c.rootHashHinkal),
|
|
231
|
+
mintAccountPart1: [u],
|
|
232
|
+
mintAccountPart2: [d],
|
|
233
|
+
amountChanges: y,
|
|
234
|
+
outTimeStamp: BigInt(c.outTimeStamp),
|
|
235
|
+
inNullifiers: p,
|
|
236
|
+
outCommitments: _,
|
|
237
|
+
calldataHash: E,
|
|
238
|
+
message: x,
|
|
239
|
+
swapperAccountAdditionalSeed: i(0n),
|
|
240
|
+
outH1Ay: BigInt(c.outH1Ay),
|
|
241
|
+
H0Ax: BigInt(c.h0Ax),
|
|
242
|
+
H0Ay: BigInt(c.h0Ay)
|
|
243
|
+
}) !== BigInt(c.signedMessageHash)) throw Error("Enclave prepare-solana-stuck-withdraw job signedMessageHash does not match one built from the caller's own data - refusing to sign");
|
|
244
|
+
}, z = (e, t) => {
|
|
245
|
+
if (v({
|
|
246
|
+
chainId: String(e.chainId),
|
|
247
|
+
hinkalAddress: e.hinkalAddress ?? "",
|
|
248
|
+
erc20Address: e.erc20Address,
|
|
249
|
+
externalAddress: e.externalAddress,
|
|
250
|
+
relay: e.relay,
|
|
251
|
+
feeStructure: {
|
|
252
|
+
feeToken: e.feeStructure.feeToken,
|
|
253
|
+
flatFee: e.feeStructure.flatFee.toString(),
|
|
254
|
+
variableRate: e.feeStructure.variableRate.toString()
|
|
255
|
+
},
|
|
256
|
+
hashedEthereumAddress: e.hashedEthereumAddress
|
|
257
|
+
}) !== v(t)) throw Error("Enclave prepare-stuck-withdraw response does not match the request sent - refusing to sign");
|
|
258
|
+
}, B = (e, t) => {
|
|
259
|
+
if (v({
|
|
260
|
+
chainId: String(e.chainId),
|
|
261
|
+
mintAddress: e.mintAddress,
|
|
262
|
+
recipient: e.recipient,
|
|
263
|
+
relayAddress: e.relayAddress,
|
|
264
|
+
signer: e.relayAddress,
|
|
265
|
+
accounts: e.accounts,
|
|
266
|
+
feeStructures: e.feeStructures,
|
|
267
|
+
hashedEthereumAddress: e.hashedEthereumAddress
|
|
268
|
+
}) !== v(t)) throw Error("Enclave prepare-solana-stuck-withdraw response does not match the request sent - refusing to sign");
|
|
269
|
+
}, V = (e, t) => {
|
|
270
|
+
y(e, t.request);
|
|
271
|
+
let n = e.inputCommitments ?? _(e.speculative) ?? (e.forceEmptyUtxos ? [] : void 0), r = b(e.erc20Addresses, t.inAmounts, t.inH0Ax, t.inH0Ay, t.inTimeStamps, e.nullifyingKey, e.spendingPublicKey, n), i = S(e.erc20Addresses, e.selfOutputAmounts, t.outAmounts, t.outNoteH0Ax, t.outNoteH0Ay, t.outTimeStamp, e.nullifyingKey, e.spendingPublicKey, e.recipientAddress, e.recipientAmounts);
|
|
272
|
+
C(e.erc20Addresses, t.inAmounts, t.outAmounts, e.selfOutputAmounts, e.amountChanges), k(e.onChainCreation, t.h0Ax, t.h0Ay, t.outH1Ax, t.outH1Ay, e.nullifyingKey);
|
|
273
|
+
let { calldataHash: a, message: o, amountChangesModWrapped: s } = O(e, t, r, i);
|
|
274
|
+
A(e.chainId, e.hinkalAddress ?? "", t, r, i, a, o, s);
|
|
275
|
+
}, H = (e, t) => {
|
|
276
|
+
I(e, t.request);
|
|
277
|
+
let n = j(e.mintAddresses), r = e.recipientAddress ? [e.recipientAddress] : void 0, a = e.recipientAmounts ? [e.recipientAmounts] : void 0, o = b(n, t.inAmounts, t.inH0Ax, t.inH0Ay, t.inTimeStamps, e.nullifyingKey, e.spendingPublicKey, e.inputCommitments ?? _(e.speculative)), c = S(n, void 0, t.outAmounts, t.outNoteH0Ax, t.outNoteH0Ay, t.outTimeStamp, e.nullifyingKey, e.spendingPublicKey, r, a);
|
|
278
|
+
C(n, t.inAmounts, t.outAmounts, void 0, e.amountChanges);
|
|
279
|
+
let { calldataHash: l, message: u } = P(e, t, o, c), d = M(e).map(T), f = e.mintAddresses.map((e) => s(e)), p = i(BigInt(e.swapperAccountSalt ?? "0"));
|
|
280
|
+
F(t, f.map((e) => e.mintAccountPart1), f.map((e) => e.mintAccountPart2), o, c, l, u, d, p);
|
|
281
|
+
}, U = (e, t) => {
|
|
282
|
+
z(e, t.request), t.jobs.forEach((t) => L(e.chainId, e.hinkalAddress ?? "", e.erc20Address, e.relay, e.externalAddress, e.feeStructure, e.nullifyingKey, e.spendingPublicKey, t));
|
|
283
|
+
}, W = (e, t) => {
|
|
284
|
+
B(e, t.request), t.jobs.forEach((t) => {
|
|
285
|
+
let n = t.inAmounts[0].filter((e) => BigInt(e) > 0n).length, r = e.feeStructures[String(n)];
|
|
286
|
+
if (!r) throw Error(`Enclave prepare-solana-stuck-withdraw response uses nullifierCount ${n} with no matching feeStructure - refusing to sign`);
|
|
287
|
+
R(e.mintAddress, e.relayAddress, e.recipient, {
|
|
288
|
+
feeToken: r.feeToken,
|
|
289
|
+
flatFee: BigInt(r.flatFee),
|
|
290
|
+
variableRate: BigInt(r.variableRate)
|
|
291
|
+
}, e.nullifyingKey, e.spendingPublicKey, t);
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
//#endregion
|
|
295
|
+
export { W as verifyPrepareSolanaStuckWithdrawResponse, H as verifyPrepareSolanaTxResponse, U as verifyPrepareStuckWithdrawResponse, V as verifyPrepareTxResponse };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`./caseInsensitive.utils.cjs`);let
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`./caseInsensitive.utils.cjs`),r=require(`./tron.utils.cjs`);let i=require(`ethers`),a=require(`@solana/web3.js`);require(`tronweb`);var o=[`http://`,`https://`,`/payment/`,`.app/`,`.com/`,`.netlify.`],s=e=>{if(o.some(t=>e.includes(t)))return!1;let[t,n,r,i,a,s]=e.split(`,`),c=!t||!s||!n||!r||!i||!a,l=t?.substring(0,2)!==`0x`||s?.substring(0,2)!==`0x`,u=s?.length!==66||t?.length>66||t?.length<64,d=e?.includes(`"`);return!(c||l||u||d)},c=e=>{let[t,n,r,i,a]=e.split(`,`);return{H0x:BigInt(n),H0y:BigInt(r),H1x:BigInt(i),H1y:BigInt(a),stealthAddress:BigInt(t)}},l=e=>{let[,,,,,t]=e.split(`,`);if(!t)throw Error(`recipientInfo is missing an encryption key`);return t},u=e=>i.ethers.keccak256(i.ethers.toUtf8Bytes(e.toLowerCase())),d=(t,n)=>u(e.isSolanaLike(t)?n:r.addressToHexFormat(n)),f=e=>i.ethers.keccak256(i.ethers.toUtf8Bytes(e)),p=e=>{try{return new a.PublicKey(e).toBase58()===e}catch{return!1}},m=(r,i)=>(r=r.trim(),r?i===void 0?n.caseInsensitiveEqual(r,t.zeroAddress)||n.caseInsensitiveEqual(r,`11111111111111111111111111111111`):e.isSolanaLike(i)?n.caseInsensitiveEqual(r,t.solanaNativeAddress):n.caseInsensitiveEqual(r,t.zeroAddress):!1);exports.constructStealthAddressStructure=c,exports.getEncryptionKeyFromRecipientInfo=l,exports.hashEthereumAddress=u,exports.hashOwnerAddressForChain=d,exports.hashString=f,exports.isNativePlaceholderAddress=m,exports.isValidPrivateAddress=s,exports.isValidSolanaPublicKey=p;
|
|
@@ -3,6 +3,7 @@ export declare const isValidPrivateAddress: (address: string) => boolean;
|
|
|
3
3
|
export declare const constructStealthAddressStructure: (recipientInfo: string) => StealthAddressStructure;
|
|
4
4
|
export declare const getEncryptionKeyFromRecipientInfo: (recipientInfo: string) => string;
|
|
5
5
|
export declare const hashEthereumAddress: (ethereumAddress: string) => string;
|
|
6
|
+
export declare const hashOwnerAddressForChain: (chainId: number, ethereumAddress: string) => string;
|
|
6
7
|
export declare const hashString: (string: string) => string;
|
|
7
8
|
export declare const isValidSolanaPublicKey: (str: string) => boolean;
|
|
8
9
|
export declare const isNativePlaceholderAddress: (address: string, chainId?: number) => boolean;
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { solanaNativeAddress as t, zeroAddress as n } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { caseInsensitiveEqual as r } from "./caseInsensitive.utils.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { addressToHexFormat as i } from "./tron.utils.mjs";
|
|
5
|
+
import { ethers as a } from "ethers";
|
|
6
|
+
import { PublicKey as o } from "@solana/web3.js";
|
|
6
7
|
import "tronweb";
|
|
7
8
|
//#region libs/shared/common/src/functions/utils/addresses.ts
|
|
8
|
-
var
|
|
9
|
+
var s = [
|
|
9
10
|
"http://",
|
|
10
11
|
"https://",
|
|
11
12
|
"/payment/",
|
|
12
13
|
".app/",
|
|
13
14
|
".com/",
|
|
14
15
|
".netlify."
|
|
15
|
-
],
|
|
16
|
-
if (
|
|
17
|
-
let [t, n, r, i, a,
|
|
16
|
+
], c = (e) => {
|
|
17
|
+
if (s.some((t) => e.includes(t))) return !1;
|
|
18
|
+
let [t, n, r, i, a, o] = e.split(","), c = !t || !o || !n || !r || !i || !a, l = t?.substring(0, 2) !== "0x" || o?.substring(0, 2) !== "0x", u = o?.length !== 66 || t?.length > 66 || t?.length < 64, d = e?.includes("\"");
|
|
18
19
|
return !(c || l || u || d);
|
|
19
|
-
},
|
|
20
|
+
}, l = (e) => {
|
|
20
21
|
let [t, n, r, i, a] = e.split(",");
|
|
21
22
|
return {
|
|
22
23
|
H0x: BigInt(n),
|
|
@@ -25,16 +26,16 @@ var o = [
|
|
|
25
26
|
H1y: BigInt(a),
|
|
26
27
|
stealthAddress: BigInt(t)
|
|
27
28
|
};
|
|
28
|
-
},
|
|
29
|
+
}, u = (e) => {
|
|
29
30
|
let [, , , , , t] = e.split(",");
|
|
30
31
|
if (!t) throw Error("recipientInfo is missing an encryption key");
|
|
31
32
|
return t;
|
|
32
|
-
},
|
|
33
|
+
}, d = (e) => a.keccak256(a.toUtf8Bytes(e.toLowerCase())), f = (t, n) => d(e(t) ? n : i(n)), p = (e) => a.keccak256(a.toUtf8Bytes(e)), m = (e) => {
|
|
33
34
|
try {
|
|
34
|
-
return new
|
|
35
|
+
return new o(e).toBase58() === e;
|
|
35
36
|
} catch {
|
|
36
37
|
return !1;
|
|
37
38
|
}
|
|
38
|
-
},
|
|
39
|
+
}, h = (i, a) => (i = i.trim(), i ? a === void 0 ? r(i, n) || r(i, "11111111111111111111111111111111") : e(a) ? r(i, t) : r(i, n) : !1);
|
|
39
40
|
//#endregion
|
|
40
|
-
export {
|
|
41
|
+
export { l as constructStealthAddressStructure, u as getEncryptionKeyFromRecipientInfo, d as hashEthereumAddress, f as hashOwnerAddressForChain, p as hashString, h as isNativePlaceholderAddress, c as isValidPrivateAddress, m as isValidSolanaPublicKey };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./time.utils.cjs`),
|
|
1
|
+
const e=require(`../../error-handling/error-codes.constants.cjs`),t=require(`./time.utils.cjs`),n=require(`../../constants/bridging.constants.cjs`),r=require(`./publicBalance.utils.cjs`);var i=async(i,a,o,s,c)=>{let l=s-s*BigInt(Math.round(c*n.SLIPPAGE_SCALING_FACTOR))/BigInt(n.SLIPPAGE_SCALING_FACTOR),u=l>0n?l:1n,d=Date.now()+n.BRIDGE_ARRIVAL_TIMEOUT_MS;for(;Date.now()<d;){let e=await r.getPublicBalanceByTokenAddress(i,a,o);if(e!==null&&e>=u)return e;await t.waitLittle(n.BRIDGE_ARRIVAL_POLL_INTERVAL_MS)}throw Error(`${e.transactionErrorCodes.BRIDGE_ARRIVAL_TIMEOUT} ${a} on chain ${i} within timeout.`)};exports.waitForBridgeArrival=i;
|