@hinkal/common 0.2.22 → 0.2.23
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/API/proxyAccountsCalls.cjs +1 -1
- package/API/proxyAccountsCalls.mjs +13 -13
- package/README.md +63 -267
- package/constants/activity.constants.cjs +1 -1
- package/constants/activity.constants.mjs +0 -1
- package/constants/addresses.constants.cjs +1 -1
- package/constants/addresses.constants.mjs +9 -10
- package/constants/contracts.constants.cjs +1 -1
- package/constants/contracts.constants.d.ts +3 -3
- package/constants/contracts.constants.mjs +29 -29
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.mjs +28 -29
- package/constants/tasks.constants.cjs +1 -1
- package/constants/tasks.constants.mjs +4 -5
- package/crypto/poseidon.cjs +1 -1
- package/crypto/poseidon.mjs +10 -10
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +24 -24
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +4 -5
- package/data-structures/Hinkal/IHinkal.d.ts +2 -2
- package/data-structures/Hinkal/hinkalApprove.cjs +1 -1
- package/data-structures/Hinkal/hinkalApprove.mjs +40 -40
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.cjs +1 -1
- package/data-structures/Hinkal/hinkalCheckTokenRegistry.mjs +7 -8
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +4 -5
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +2 -3
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +18 -19
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +3 -4
- package/data-structures/Hinkal/hinkalInsideTransact.cjs +1 -1
- package/data-structures/Hinkal/hinkalInsideTransact.mjs +14 -13
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +2 -3
- package/data-structures/Hinkal/hinkalProoflessDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalProoflessDeposit.mjs +27 -26
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +38 -39
- package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.mjs +16 -17
- package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +24 -25
- package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +15 -16
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +2 -3
- package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalTransfer.mjs +2 -3
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +9 -10
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +8 -9
- package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/data-structures/Hinkal/resetMerkleTrees.mjs +10 -10
- package/data-structures/IndexedDB/activity-db.cjs +1 -1
- package/data-structures/IndexedDB/activity-db.mjs +39 -41
- package/data-structures/IndexedDB/balances-db.cjs +1 -1
- package/data-structures/IndexedDB/balances-db.mjs +8 -9
- package/data-structures/IndexedDB/contact-db.cjs +1 -1
- package/data-structures/IndexedDB/contact-db.mjs +21 -23
- package/data-structures/IndexedDB/signatures-db.cjs +1 -1
- package/data-structures/IndexedDB/signatures-db.mjs +2 -3
- package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +34 -36
- package/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
- package/data-structures/crypto-keys/decodeUTXO.mjs +45 -45
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +28 -27
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.d.ts +2 -3
- package/data-structures/crypto-keys/keys.mjs +56 -57
- package/data-structures/event-service/evm/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractEventService.mjs +14 -14
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.d.ts +2 -3
- package/data-structures/event-service/evm/AbstractNullifierSnapshotService.mjs +5 -4
- package/data-structures/event-service/evm/AbstractSnapshotService.cjs +1 -1
- package/data-structures/event-service/evm/AbstractSnapshotService.mjs +6 -3
- package/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +1 -1
- package/data-structures/event-service/evm/BlockchainEventEmitter.mjs +22 -18
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
- package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.mjs +2 -2
- package/data-structures/presale/PresaleContractWrapper.cjs +1 -1
- package/data-structures/presale/PresaleContractWrapper.d.ts +3 -3
- package/data-structures/presale/PresaleContractWrapper.mjs +10 -10
- package/data-structures/provider-adapter/IProviderAdapter.d.ts +7 -7
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.mjs +16 -14
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.mjs +7 -5
- package/error-handling/get-error.message.cjs +1 -1
- package/error-handling/get-error.message.mjs +2 -3
- package/functions/kyc/zkMeHelper.cjs +1 -1
- package/functions/kyc/zkMeHelper.mjs +3 -3
- package/functions/pre-transaction/getFlatFees.cjs +1 -1
- package/functions/pre-transaction/getFlatFees.mjs +2 -3
- package/functions/pre-transaction/getSolanaCalldataHash.cjs +1 -1
- package/functions/pre-transaction/getSolanaCalldataHash.mjs +21 -21
- package/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
- package/functions/pre-transaction/getVolatileTransferAmount.mjs +2 -3
- package/functions/pre-transaction/interaction-to-action.cjs +1 -1
- package/functions/pre-transaction/interaction-to-action.mjs +2 -3
- package/functions/private-wallet/emporium.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.helpers.d.ts +6 -7
- package/functions/private-wallet/emporium.helpers.mjs +104 -105
- package/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
- package/functions/private-wallet/emporium.swap.helpers.mjs +44 -43
- package/functions/private-wallet/opProducer.cjs +1 -1
- package/functions/private-wallet/opProducer.mjs +1 -1
- package/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/functions/snarkjs/common.snarkjs.mjs +21 -18
- package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/functions/snarkjs/constructSolanaZkProof.mjs +11 -12
- package/functions/utils/addresses.cjs +1 -1
- package/functions/utils/addresses.mjs +6 -6
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.d.ts +1 -1
- package/functions/utils/cacheFunctions.mjs +55 -54
- package/functions/utils/convertEmporiumOpToCallInfo.cjs +1 -1
- package/functions/utils/convertEmporiumOpToCallInfo.mjs +5 -5
- package/functions/utils/create-provider.cjs +1 -1
- package/functions/utils/create-provider.d.ts +2 -2
- package/functions/utils/create-provider.mjs +5 -5
- package/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/functions/utils/encryptInputForEnclave.mjs +9 -9
- package/functions/utils/ethers-formatter.utils.d.ts +1 -1
- package/functions/utils/external-action.utils.cjs +1 -1
- package/functions/utils/external-action.utils.mjs +2 -2
- package/functions/utils/getContractAddress.cjs +1 -0
- package/functions/utils/getContractAddress.d.ts +2 -0
- package/functions/utils/getContractAddress.mjs +9 -0
- package/functions/utils/getDataFromTransaction.cjs +1 -1
- package/functions/utils/getDataFromTransaction.d.ts +0 -11
- package/functions/utils/getDataFromTransaction.mjs +26 -50
- package/functions/utils/getRecipientInfoFromUserKeys.cjs +1 -1
- package/functions/utils/getRecipientInfoFromUserKeys.mjs +1 -1
- package/functions/utils/getSignerFromContract.cjs +1 -0
- package/functions/utils/getSignerFromContract.d.ts +3 -0
- package/functions/utils/getSignerFromContract.mjs +16 -0
- package/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
- package/functions/utils/getUtxosFromReceipt.utils.d.ts +1 -1
- package/functions/utils/getUtxosFromReceipt.utils.mjs +15 -16
- package/functions/utils/inLogicMetadata.cjs +1 -1
- package/functions/utils/inLogicMetadata.mjs +2 -2
- package/functions/utils/nftTokenFunctions.cjs +1 -1
- package/functions/utils/nftTokenFunctions.mjs +2 -3
- package/functions/utils/publicBalance.utils.cjs +1 -1
- package/functions/utils/publicBalance.utils.d.ts +1 -1
- package/functions/utils/publicBalance.utils.mjs +42 -42
- package/functions/utils/rpc-int-encode.cjs +1 -1
- package/functions/utils/rpc-int-encode.d.ts +1 -2
- package/functions/utils/rpc-int-encode.mjs +3 -6
- package/functions/utils/solanaMint.utils.cjs +1 -1
- package/functions/utils/solanaMint.utils.mjs +6 -6
- package/functions/web3/EIP-712.cjs +1 -1
- package/functions/web3/EIP-712.d.ts +4 -4
- package/functions/web3/EIP-712.mjs +1 -1
- package/functions/web3/etherFunctions.cjs +1 -1
- package/functions/web3/etherFunctions.mjs +32 -29
- package/functions/web3/events/balanceChangedCustomHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedCustomHandler.mjs +4 -5
- package/functions/web3/events/balanceChangedHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedHandler.mjs +2 -3
- package/functions/web3/events/getApprovedBalance.cjs +1 -1
- package/functions/web3/events/getApprovedBalance.mjs +1 -1
- package/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
- package/functions/web3/events/getInputUtxosEnclave.mjs +20 -20
- package/functions/web3/events/getTransactionLogEvents.cjs +1 -1
- package/functions/web3/events/getTransactionLogEvents.d.ts +3 -3
- package/functions/web3/events/getTransactionLogEvents.mjs +6 -5
- package/functions/web3/events/index.d.ts +0 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.cjs +1 -1
- package/functions/web3/fetchSolanaMerkleTreeRootHash.d.ts +1 -2
- package/functions/web3/fetchSolanaMerkleTreeRootHash.mjs +4 -5
- package/functions/web3/functionCalls/accessTokenCalls.cjs +1 -1
- package/functions/web3/functionCalls/accessTokenCalls.mjs +10 -11
- package/functions/web3/functionCalls/approveToken.cjs +1 -1
- package/functions/web3/functionCalls/approveToken.mjs +61 -58
- package/functions/web3/functionCalls/constructBatchCall.cjs +1 -1
- package/functions/web3/functionCalls/constructBatchCall.d.ts +2 -2
- package/functions/web3/functionCalls/constructBatchCall.mjs +10 -9
- package/functions/web3/functionCalls/estimateGasRelayer.cjs +1 -1
- package/functions/web3/functionCalls/estimateGasRelayer.mjs +1 -1
- package/functions/web3/functionCalls/inHinkalApprovalCalls.cjs +1 -1
- package/functions/web3/functionCalls/inHinkalApprovalCalls.mjs +18 -21
- package/functions/web3/functionCalls/recoverTransactionFromError.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +38 -34
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +8 -10
- package/functions/web3/getContractMetadata.cjs +1 -1
- package/functions/web3/getContractMetadata.d.ts +1 -1
- package/functions/web3/getContractMetadata.mjs +25 -25
- package/functions/web3/getPublicAddressBalance.cjs +1 -1
- package/functions/web3/getPublicAddressBalance.mjs +7 -6
- package/functions/web3/getTokenHolder.cjs +1 -1
- package/functions/web3/getTokenHolder.mjs +16 -15
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +6 -7
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +2 -3
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.d.ts +6 -5
- package/functions/web3/runContractFunction.mjs +41 -45
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.d.ts +2 -2
- package/functions/web3/uniswapAPI.mjs +23 -24
- package/index.cjs +1 -1
- package/index.mjs +336 -340
- package/package.json +3 -4
- package/providers/CustomEthersProvider.d.ts +1 -1
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.d.ts +7 -7
- package/providers/EthersProviderAdapter.mjs +46 -44
- package/providers/SolanaProviderAdapter.d.ts +1 -1
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.d.ts +5 -5
- package/providers/WagmiProviderAdapter.mjs +37 -33
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.d.ts +2 -2
- package/providers/prepareEthersHinkal.mjs +3 -5
- package/providers/prepareWagmiHinkal.cjs +1 -1
- package/providers/prepareWagmiHinkal.mjs +3 -5
- package/types/activities.types.d.ts +2 -3
- package/types/big-intable.types.d.ts +3 -2
- package/types/ethereum-network.types.d.ts +10 -10
- package/types/transactions.types.cjs +1 -1
- package/types/transactions.types.d.ts +2 -3
- package/types/transactions.types.mjs +6 -7
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/functions/web3/events/web3RetrieveEvents.cjs +0 -1
- package/functions/web3/events/web3RetrieveEvents.d.ts +0 -14
- package/functions/web3/events/web3RetrieveEvents.mjs +0 -9
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { ethers as
|
|
1
|
+
import { ethers as E } from "ethers";
|
|
2
2
|
import { get as B, update as w } from "idb-keyval";
|
|
3
3
|
import { API as C } from "../../API/API.mjs";
|
|
4
4
|
import { networkRegistry as v } from "../../constants/chains.constants.mjs";
|
|
5
|
-
import { Logger as
|
|
6
|
-
import { lowerCaseIncludes as
|
|
5
|
+
import { Logger as T } from "../../error-handling/logger.mjs";
|
|
6
|
+
import { lowerCaseIncludes as h } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
7
7
|
import { StorageKeys as k } from "../../types/cache.types.mjs";
|
|
8
|
-
import { getStateKey as
|
|
9
|
-
import { zeroAddress as
|
|
8
|
+
import { getStateKey as d } from "../../functions/utils/string.utils.mjs";
|
|
9
|
+
import { zeroAddress as I } from "../../constants/protocol.constants.mjs";
|
|
10
10
|
import { Mutex as _ } from "async-mutex";
|
|
11
11
|
import { isNFTToken as P } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
12
|
-
import { tokenVisibilityStorage as
|
|
12
|
+
import { tokenVisibilityStorage as x } from "./token-visibility-db.mjs";
|
|
13
13
|
import "../../types/circom-data.types.mjs";
|
|
14
|
-
import "../../types/transactions.types.mjs";
|
|
15
14
|
import "../../types/activities.types.mjs";
|
|
16
15
|
import "@coral-xyz/anchor";
|
|
17
16
|
import "@solana/web3.js";
|
|
18
17
|
import "circomlibjs-hinkal-fork";
|
|
19
18
|
import "../../constants/kyc.constants.mjs";
|
|
20
|
-
import { createCustomRpcProvider as
|
|
19
|
+
import { createCustomRpcProvider as N } from "../../functions/utils/create-provider.mjs";
|
|
21
20
|
import "../../functions/utils/convertIntegrationProviderToExternalActionId.mjs";
|
|
22
21
|
import "../../error-handling/error-codes.constants.mjs";
|
|
23
22
|
import "../crypto-keys/keys.mjs";
|
|
@@ -48,56 +47,55 @@ import "../../API/tenderly.api.mjs";
|
|
|
48
47
|
import "node-forge";
|
|
49
48
|
import "../../functions/web3/events/getApprovedBalance.mjs";
|
|
50
49
|
import "../../functions/web3/getTokenHolder.mjs";
|
|
51
|
-
import "ethers-v6h";
|
|
52
50
|
class K {
|
|
53
51
|
fetchedTokens = {};
|
|
54
52
|
updateMutexes = {};
|
|
55
|
-
transferEventTopic =
|
|
53
|
+
transferEventTopic = E.id("Transfer(address,address,uint256)");
|
|
56
54
|
getMutex(e) {
|
|
57
55
|
return this.updateMutexes[e] || (this.updateMutexes[e] = new _()), this.updateMutexes[e];
|
|
58
56
|
}
|
|
59
57
|
async getPublicTokens(e, s) {
|
|
60
|
-
const o =
|
|
58
|
+
const o = d(s, e);
|
|
61
59
|
return (await B(k.EVENTS_PUBLIC_TOKENS))?.[o] || [];
|
|
62
60
|
}
|
|
63
61
|
getFetchedTokens(e, s) {
|
|
64
|
-
const o =
|
|
62
|
+
const o = d(s, e);
|
|
65
63
|
return this.fetchedTokens[o] || [];
|
|
66
64
|
}
|
|
67
65
|
async fetchAndUpdatePublicTokens(e, s) {
|
|
68
|
-
const o =
|
|
66
|
+
const o = d(e, s);
|
|
69
67
|
await this.getMutex(o).runExclusive(async () => {
|
|
70
68
|
try {
|
|
71
|
-
const r = (await this.getPublicTokens(s, e)).map((a) => a.erc20TokenAddress), { toEvents: i, fromEvents: p, latestBlock: c } = await this.getEvents(e, s),
|
|
69
|
+
const r = (await this.getPublicTokens(s, e)).map((a) => a.erc20TokenAddress), { toEvents: i, fromEvents: p, latestBlock: c } = await this.getEvents(e, s), u = [...i, ...p], { erc20Tokens: m } = await this.fetchPublicTokens(u, s, r), S = await x.hideSpamsAndFetchHiddenTokensAddresses(
|
|
72
70
|
s,
|
|
73
|
-
|
|
74
|
-
), L =
|
|
75
|
-
(a) => !
|
|
71
|
+
m
|
|
72
|
+
), L = m.filter(
|
|
73
|
+
(a) => !h(S, a.erc20TokenAddress)
|
|
76
74
|
// filter out hidden tokens
|
|
77
75
|
);
|
|
78
76
|
await w(k.EVENTS_PUBLIC_TOKENS, (a = {}) => {
|
|
79
|
-
const
|
|
80
|
-
(
|
|
77
|
+
const l = a[o] || [], y = l.map((f) => f.erc20TokenAddress), b = L.filter(
|
|
78
|
+
(f) => !h(y, f.erc20TokenAddress)
|
|
81
79
|
);
|
|
82
|
-
|
|
83
|
-
const A = this.updateTokenIds(p, i,
|
|
80
|
+
l.push(...b);
|
|
81
|
+
const A = this.updateTokenIds(p, i, l), g = {
|
|
84
82
|
...a,
|
|
85
83
|
[o]: A
|
|
86
84
|
};
|
|
87
|
-
return this.fetchedTokens =
|
|
85
|
+
return this.fetchedTokens = g, g;
|
|
88
86
|
}), c && await this.updateLastProcessedBlock(s, e, c);
|
|
89
87
|
} catch (t) {
|
|
90
|
-
|
|
88
|
+
T.error("public tokens db error", t);
|
|
91
89
|
}
|
|
92
90
|
});
|
|
93
91
|
}
|
|
94
92
|
async getLastProcessedBlock(e, s) {
|
|
95
|
-
const o = await B(k.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS) || {}, n =
|
|
93
|
+
const o = await B(k.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS) || {}, n = d(s, e);
|
|
96
94
|
return o[n] || O[e];
|
|
97
95
|
}
|
|
98
96
|
async updateLastProcessedBlock(e, s, o) {
|
|
99
97
|
await w(k.PUBLIC_TOKENS_LAST_PROCESSED_BLOCKS, (n = {}) => {
|
|
100
|
-
const t =
|
|
98
|
+
const t = d(s, e);
|
|
101
99
|
return {
|
|
102
100
|
...n,
|
|
103
101
|
[t]: o
|
|
@@ -109,7 +107,7 @@ class K {
|
|
|
109
107
|
const { fetchRpcUrl: o } = v[s];
|
|
110
108
|
if (!o)
|
|
111
109
|
throw Error("No fetchRpcUrl in PublicTokensDB");
|
|
112
|
-
const n =
|
|
110
|
+
const n = N(o), t = await this.getLastProcessedBlock(s, e) + 1, r = await n.getBlockNumber(), i = E.zeroPadValue(e.toLowerCase(), 32), p = {
|
|
113
111
|
topics: [this.transferEventTopic, null, i],
|
|
114
112
|
fromBlock: t,
|
|
115
113
|
toBlock: r
|
|
@@ -117,10 +115,10 @@ class K {
|
|
|
117
115
|
topics: [this.transferEventTopic, i, null],
|
|
118
116
|
fromBlock: t,
|
|
119
117
|
toBlock: r
|
|
120
|
-
}, [
|
|
121
|
-
return { toEvents:
|
|
118
|
+
}, [u, m] = await Promise.all([n.getLogs(p), n.getLogs(c)]);
|
|
119
|
+
return { toEvents: u, fromEvents: m, latestBlock: r };
|
|
122
120
|
} catch (o) {
|
|
123
|
-
return
|
|
121
|
+
return T.error("Error fetching events:", o), { toEvents: [], fromEvents: [], latestBlock: void 0 };
|
|
124
122
|
}
|
|
125
123
|
}
|
|
126
124
|
// First get existed tokenIds from tokens
|
|
@@ -136,14 +134,14 @@ class K {
|
|
|
136
134
|
}), s.forEach((t) => {
|
|
137
135
|
if (t.topics.length <= 3)
|
|
138
136
|
return;
|
|
139
|
-
const r = t.address.toLowerCase(), i =
|
|
137
|
+
const r = t.address.toLowerCase(), i = BigInt(t.topics[3]).toString();
|
|
140
138
|
n.has(r) || n.set(r, []), n.get(r)?.push(i);
|
|
141
139
|
}), e.forEach((t) => {
|
|
142
140
|
if (t.topics.length <= 3)
|
|
143
141
|
return;
|
|
144
142
|
const r = t.address.toLowerCase(), i = n.get(r);
|
|
145
143
|
if (i?.length) {
|
|
146
|
-
const p =
|
|
144
|
+
const p = BigInt(t.topics[3]).toString(), c = i.indexOf(p);
|
|
147
145
|
c !== -1 && i.splice(c, 1);
|
|
148
146
|
}
|
|
149
147
|
}), o.forEach((t) => {
|
|
@@ -155,19 +153,19 @@ class K {
|
|
|
155
153
|
}
|
|
156
154
|
async fetchPublicTokens(e, s, o) {
|
|
157
155
|
try {
|
|
158
|
-
const n = [
|
|
159
|
-
(r) => r && !
|
|
156
|
+
const n = [I, ...new Set(e.map((r) => r.address))].filter(
|
|
157
|
+
(r) => r && !h(o, r)
|
|
160
158
|
);
|
|
161
159
|
return n.length ? { erc20Tokens: (await C.tokensInfoCall(s, n)).filter(
|
|
162
160
|
(r) => !!r
|
|
163
161
|
) } : { erc20Tokens: [] };
|
|
164
162
|
} catch (n) {
|
|
165
|
-
return
|
|
163
|
+
return T.error("Error fetching public tokens:", n), { erc20Tokens: [] };
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
166
|
}
|
|
169
|
-
const
|
|
167
|
+
const xt = new K();
|
|
170
168
|
export {
|
|
171
169
|
K as EventsPublicTokensDB,
|
|
172
|
-
|
|
170
|
+
xt as eventsPublicTokensDB
|
|
173
171
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@solana/web3.js"),E=require("../../crypto/poseidon.cjs"),B=require("../../constants/chains.constants.cjs"),z=require("../utxo/Utxo.cjs"),_=require("./keys.cjs"),a=require("ethers"),y="solana-on-chain-utxo:",x=8,P=e=>{if(e.length!==x)throw new Error(`Expected ${x} on-chain fields, received ${e.length}`);const t=e.map((n,r)=>{const o=n instanceof Uint8Array?n:Uint8Array.from(n);if(o.length!==32)throw new Error(`Expected bytes32 length 32 at position ${r}, got ${o.length}`);return`0x${Buffer.from(o).toString("hex")}`});return`${y}${a.ethers.AbiCoder.defaultAbiCoder().encode(["bytes32[8]"],[t])}`},I=e=>e.startsWith(y),S=e=>{if(!I(e))throw new Error("Invalid encoded Solana UTXO payload");const[t]=a.ethers.AbiCoder.defaultAbiCoder().decode(["bytes32[8]"],e.slice(y.length)),n=t;if(!Array.isArray(n)||n.length!==x)throw new Error("Malformed encoded Solana UTXO payload");const[r,o,s,i,d,c,h,l]=n,m=BigInt(r),u=BigInt(i),A=a.ethers.toBeHex(BigInt(d)),g=BigInt(c),f=BigInt(h),H=BigInt(l).toString(),k=Array.from(a.ethers.getBytes(o)),w=Array.from(a.ethers.getBytes(s)),C=Uint8Array.from([...k.slice(16),...w.slice(16)]),p=new O.PublicKey(C).toBase58(),T=E.poseidonHash(BigInt(o),BigInt(s));return{amount:m,erc20TokenAddress:T,mintAddress:p,randomization:u,stealthAddress:A,H0:g,H1:f,timeStamp:H}},U=e=>{const t=a.ethers.AbiCoder.defaultAbiCoder().decode(["uint256","address","tuple(uint256, uint256, uint256, uint256)","uint256","uint256"],e),n=BigInt(t[0]),r=t[1],o=BigInt(t[2][0]),s=a.ethers.toBeHex(BigInt(t[2][1])),i=BigInt(t[2][2]),d=BigInt(t[2][3]),c=BigInt(t[3]).toString(),h=Number(t[4]);return{amount:n,erc20TokenAddress:r,randomization:o,stealthAddress:s,H0:i,H1:d,timeStamp:c,tokenId:h}},b=(e,t,n)=>{if(B.isSolanaLike(n)){const{amount:h,erc20TokenAddress:l,mintAddress:m,randomization:u,stealthAddress:A,timeStamp:g}=S(e);return{amount:h,erc20TokenAddress:l,mintAddress:m,timeStamp:g,tokenId:0,randomization:u,shieldedPrivateKey:t,stealthAddress:A}}const{amount:r,erc20TokenAddress:o,timeStamp:s,tokenId:i,randomization:d,stealthAddress:c}=U(e);return{amount:r,erc20TokenAddress:o,timeStamp:s,tokenId:i,randomization:d,shieldedPrivateKey:t,stealthAddress:c}},$=(e,t,n)=>new z.Utxo(b(e,t,n)),q=(e,t,n)=>{const{randomization:r,H0:o,H1:s}=B.isSolanaLike(n)?S(e):U(e),i=_.UserKeys.checkSignature(r,o,s,t);if(!i)throw new Error("UTXO doesn't belong to user");return i};exports.abiDecodeUtxo=U;exports.checkUtxoSignature=q;exports.decodeSolanaOnChainUtxo=S;exports.decodeUtxo=$;exports.decodeUtxoConstructorArgs=b;exports.encodeSolanaOnChainUtxo=P;exports.isSolanaOnChainUtxo=I;
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { ethers as a } from "ethers";
|
|
2
1
|
import { PublicKey as T } from "@solana/web3.js";
|
|
3
|
-
import { poseidonHash as
|
|
2
|
+
import { poseidonHash as C } from "../../crypto/poseidon.mjs";
|
|
4
3
|
import { isSolanaLike as y } from "../../constants/chains.constants.mjs";
|
|
5
|
-
import { Utxo as
|
|
6
|
-
import { UserKeys as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { Utxo as E } from "../utxo/Utxo.mjs";
|
|
5
|
+
import { UserKeys as z } from "./keys.mjs";
|
|
6
|
+
import { ethers as d } from "ethers";
|
|
7
|
+
const f = "solana-on-chain-utxo:", x = 8, F = (e) => {
|
|
8
|
+
if (e.length !== x)
|
|
9
|
+
throw new Error(`Expected ${x} on-chain fields, received ${e.length}`);
|
|
10
|
+
const t = e.map((o, r) => {
|
|
11
|
+
const n = o instanceof Uint8Array ? o : Uint8Array.from(o);
|
|
12
12
|
if (n.length !== 32)
|
|
13
13
|
throw new Error(`Expected bytes32 length 32 at position ${r}, got ${n.length}`);
|
|
14
14
|
return `0x${Buffer.from(n).toString("hex")}`;
|
|
15
15
|
});
|
|
16
|
-
return `${
|
|
17
|
-
},
|
|
18
|
-
if (!
|
|
16
|
+
return `${f}${d.AbiCoder.defaultAbiCoder().encode(["bytes32[8]"], [t])}`;
|
|
17
|
+
}, O = (e) => e.startsWith(f), B = (e) => {
|
|
18
|
+
if (!O(e))
|
|
19
19
|
throw new Error("Invalid encoded Solana UTXO payload");
|
|
20
|
-
const [t] =
|
|
20
|
+
const [t] = d.AbiCoder.defaultAbiCoder().decode(
|
|
21
21
|
["bytes32[8]"],
|
|
22
|
-
|
|
23
|
-
),
|
|
24
|
-
if (!Array.isArray(
|
|
22
|
+
e.slice(f.length)
|
|
23
|
+
), o = t;
|
|
24
|
+
if (!Array.isArray(o) || o.length !== x)
|
|
25
25
|
throw new Error("Malformed encoded Solana UTXO payload");
|
|
26
26
|
const [
|
|
27
27
|
r,
|
|
28
28
|
n,
|
|
29
29
|
s,
|
|
30
30
|
i,
|
|
31
|
-
|
|
31
|
+
a,
|
|
32
32
|
c,
|
|
33
33
|
m,
|
|
34
|
-
|
|
35
|
-
] =
|
|
34
|
+
A
|
|
35
|
+
] = o, l = BigInt(r), g = BigInt(i), h = d.toBeHex(BigInt(a)), u = BigInt(c), H = BigInt(m), S = BigInt(A).toString(), p = Array.from(d.getBytes(n)), U = Array.from(d.getBytes(s)), b = Uint8Array.from([...p.slice(16), ...U.slice(16)]), w = new T(b).toBase58(), k = C(BigInt(n), BigInt(s));
|
|
36
36
|
return {
|
|
37
|
-
amount:
|
|
37
|
+
amount: l,
|
|
38
38
|
erc20TokenAddress: k,
|
|
39
39
|
mintAddress: w,
|
|
40
|
-
randomization:
|
|
40
|
+
randomization: g,
|
|
41
41
|
stealthAddress: h,
|
|
42
|
-
H0:
|
|
43
|
-
H1:
|
|
44
|
-
timeStamp:
|
|
42
|
+
H0: u,
|
|
43
|
+
H1: H,
|
|
44
|
+
timeStamp: S
|
|
45
45
|
};
|
|
46
|
-
},
|
|
47
|
-
const t =
|
|
46
|
+
}, I = (e) => {
|
|
47
|
+
const t = d.AbiCoder.defaultAbiCoder().decode(
|
|
48
48
|
["uint256", "address", "tuple(uint256, uint256, uint256, uint256)", "uint256", "uint256"],
|
|
49
|
-
|
|
50
|
-
),
|
|
49
|
+
e
|
|
50
|
+
), o = BigInt(t[0]), r = t[1], n = BigInt(t[2][0]), s = d.toBeHex(BigInt(t[2][1])), i = BigInt(t[2][2]), a = BigInt(t[2][3]), c = BigInt(t[3]).toString(), m = Number(t[4]);
|
|
51
51
|
return {
|
|
52
|
-
amount:
|
|
52
|
+
amount: o,
|
|
53
53
|
erc20TokenAddress: r,
|
|
54
54
|
randomization: n,
|
|
55
55
|
stealthAddress: s,
|
|
56
56
|
H0: i,
|
|
57
|
-
H1:
|
|
57
|
+
H1: a,
|
|
58
58
|
timeStamp: c,
|
|
59
59
|
tokenId: m
|
|
60
60
|
};
|
|
61
|
-
},
|
|
62
|
-
if (y(
|
|
63
|
-
const { amount: m, erc20TokenAddress:
|
|
61
|
+
}, $ = (e, t, o) => {
|
|
62
|
+
if (y(o)) {
|
|
63
|
+
const { amount: m, erc20TokenAddress: A, mintAddress: l, randomization: g, stealthAddress: h, timeStamp: u } = B(e);
|
|
64
64
|
return {
|
|
65
65
|
amount: m,
|
|
66
|
-
erc20TokenAddress:
|
|
67
|
-
mintAddress:
|
|
68
|
-
timeStamp:
|
|
66
|
+
erc20TokenAddress: A,
|
|
67
|
+
mintAddress: l,
|
|
68
|
+
timeStamp: u,
|
|
69
69
|
tokenId: 0,
|
|
70
|
-
randomization:
|
|
70
|
+
randomization: g,
|
|
71
71
|
shieldedPrivateKey: t,
|
|
72
72
|
stealthAddress: h
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
const { amount: r, erc20TokenAddress: n, timeStamp: s, tokenId: i, randomization:
|
|
75
|
+
const { amount: r, erc20TokenAddress: n, timeStamp: s, tokenId: i, randomization: a, stealthAddress: c } = I(e);
|
|
76
76
|
return {
|
|
77
77
|
amount: r,
|
|
78
78
|
erc20TokenAddress: n,
|
|
79
79
|
timeStamp: s,
|
|
80
80
|
tokenId: i,
|
|
81
|
-
randomization:
|
|
81
|
+
randomization: a,
|
|
82
82
|
shieldedPrivateKey: t,
|
|
83
83
|
stealthAddress: c
|
|
84
84
|
};
|
|
85
|
-
}, v = (
|
|
86
|
-
const { randomization: r, H0: n, H1: s } = y(
|
|
85
|
+
}, v = (e, t, o) => new E($(e, t, o)), M = (e, t, o) => {
|
|
86
|
+
const { randomization: r, H0: n, H1: s } = y(o) ? B(e) : I(e), i = z.checkSignature(r, n, s, t);
|
|
87
87
|
if (!i)
|
|
88
88
|
throw new Error("UTXO doesn't belong to user");
|
|
89
89
|
return i;
|
|
90
90
|
};
|
|
91
91
|
export {
|
|
92
|
-
|
|
92
|
+
I as abiDecodeUtxo,
|
|
93
93
|
M as checkUtxoSignature,
|
|
94
|
-
|
|
94
|
+
B as decodeSolanaOnChainUtxo,
|
|
95
95
|
v as decodeUtxo,
|
|
96
|
-
|
|
96
|
+
$ as decodeUtxoConstructorArgs,
|
|
97
97
|
F as encodeSolanaOnChainUtxo,
|
|
98
|
-
|
|
98
|
+
O as isSolanaOnChainUtxo
|
|
99
99
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("ethers"),a=require("libsodium-wrappers"),l=require("../utxo/Utxo.cjs"),m=require("@solana/web3.js"),B=require("./keys.cjs"),g=e=>{const r=[Buffer.from(o.ethers.toBeHex(e.amount)),Buffer.from(e.erc20TokenAddress),Buffer.from(o.ethers.toBeHex(e.randomization)),Buffer.from(e.getStealthAddress()),Buffer.from(o.ethers.toBeHex(BigInt(e.timeStamp))),Buffer.from(o.ethers.toBeHex(e.tokenId??0))];if(e.mintAddress){const t=new m.PublicKey(e.mintAddress).toBytes();r.push(Buffer.from(t))}const n=Buffer.concat(r);return a.crypto_box_seal(n,o.ethers.getBytes(e.getEncryptionKey()))},p=(e,r)=>{const{publicKey:n,privateKey:c}=B.UserKeys.getEncryptionKeyPair(r.getShieldedPrivateKey()),d=a.crypto_box_seal_open(e,o.ethers.getBytes(n),o.ethers.getBytes(c)),t=Buffer.from(d).toString("utf-8").split("0x").filter(s=>s.length!==0).map((s,y)=>{let i;return[0,2,4,5].includes(y)?i=BigInt(`0x${s}`):[1,3,6].includes(y)&&(i=`0x${s}`),i}),f=typeof t[6]=="string"?t[6]:void 0,u=f?new m.PublicKey(Buffer.from(f.slice(2),"hex")).toString():void 0;return{amount:t[0],erc20TokenAddress:t[1],randomization:t[2],stealthAddress:t[3],shieldedPrivateKey:r.getShieldedPrivateKey(),timeStamp:t[4].toString(),tokenId:t[5]?Number(t[5]):0,mintAddress:u}},h=(e,r)=>new l.Utxo(p(e,r));exports.decryptUtxo=h;exports.decryptUtxoConstructorArgs=p;exports.encryptUtxo=g;
|
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
import { ethers as
|
|
2
|
-
import
|
|
3
|
-
import { Utxo as
|
|
4
|
-
import { PublicKey as
|
|
5
|
-
import { UserKeys as
|
|
1
|
+
import { ethers as o } from "ethers";
|
|
2
|
+
import a from "libsodium-wrappers";
|
|
3
|
+
import { Utxo as B } from "../utxo/Utxo.mjs";
|
|
4
|
+
import { PublicKey as p } from "@solana/web3.js";
|
|
5
|
+
import { UserKeys as l } from "./keys.mjs";
|
|
6
6
|
const K = (e) => {
|
|
7
|
-
const
|
|
8
|
-
Buffer.from(
|
|
9
|
-
Buffer.from(
|
|
10
|
-
|
|
7
|
+
const r = [
|
|
8
|
+
Buffer.from(o.toBeHex(e.amount)),
|
|
9
|
+
Buffer.from(e.erc20TokenAddress),
|
|
10
|
+
// if it is zeroAddress toBeHex will return 0x00
|
|
11
|
+
Buffer.from(o.toBeHex(e.randomization)),
|
|
11
12
|
Buffer.from(e.getStealthAddress()),
|
|
12
|
-
Buffer.from(
|
|
13
|
-
Buffer.from(
|
|
13
|
+
Buffer.from(o.toBeHex(BigInt(e.timeStamp))),
|
|
14
|
+
Buffer.from(o.toBeHex(e.tokenId ?? 0))
|
|
14
15
|
];
|
|
15
16
|
if (e.mintAddress) {
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
const t = new p(e.mintAddress).toBytes();
|
|
18
|
+
r.push(Buffer.from(t));
|
|
18
19
|
}
|
|
19
|
-
const
|
|
20
|
-
return
|
|
21
|
-
},
|
|
22
|
-
const { publicKey:
|
|
20
|
+
const s = Buffer.concat(r);
|
|
21
|
+
return a.crypto_box_seal(s, o.getBytes(e.getEncryptionKey()));
|
|
22
|
+
}, g = (e, r) => {
|
|
23
|
+
const { publicKey: s, privateKey: f } = l.getEncryptionKeyPair(r.getShieldedPrivateKey()), d = a.crypto_box_seal_open(
|
|
23
24
|
e,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
), t = Buffer.from(
|
|
27
|
-
let
|
|
28
|
-
return [0, 2, 4, 5].includes(
|
|
29
|
-
}),
|
|
25
|
+
o.getBytes(s),
|
|
26
|
+
o.getBytes(f)
|
|
27
|
+
), t = Buffer.from(d).toString("utf-8").split("0x").filter((n) => n.length !== 0).map((n, c) => {
|
|
28
|
+
let i;
|
|
29
|
+
return [0, 2, 4, 5].includes(c) ? i = BigInt(`0x${n}`) : [1, 3, 6].includes(c) && (i = `0x${n}`), i;
|
|
30
|
+
}), m = typeof t[6] == "string" ? t[6] : void 0, y = m ? new p(Buffer.from(m.slice(2), "hex")).toString() : void 0;
|
|
30
31
|
return {
|
|
31
32
|
amount: t[0],
|
|
32
33
|
erc20TokenAddress: t[1],
|
|
33
34
|
randomization: t[2],
|
|
34
35
|
stealthAddress: t[3],
|
|
35
|
-
shieldedPrivateKey:
|
|
36
|
+
shieldedPrivateKey: r.getShieldedPrivateKey(),
|
|
36
37
|
timeStamp: t[4].toString(),
|
|
37
38
|
tokenId: t[5] ? Number(t[5]) : 0,
|
|
38
39
|
// tokenId
|
|
39
|
-
mintAddress:
|
|
40
|
+
mintAddress: y
|
|
40
41
|
};
|
|
41
|
-
}, S = (e,
|
|
42
|
+
}, S = (e, r) => new B(g(e, r));
|
|
42
43
|
export {
|
|
43
44
|
S as decryptUtxo,
|
|
44
|
-
|
|
45
|
+
g as decryptUtxoConstructorArgs,
|
|
45
46
|
K as encryptUtxo
|
|
46
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("ethers"),w=require("libsodium-wrappers"),S=require("../../constants/protocol.constants.cjs"),f=require("../../crypto/babyJub.cjs"),h=require("../../crypto/poseidon.cjs"),d=require("./keyUtils.cjs"),K=require("../cacheDevices/AttachableMemoryCacheDevice.cjs"),l=require("../../constants/chains.constants.cjs"),c=require("@solana/web3.js"),m=require("tweetnacl"),p=require("bs58"),b=require("../../functions/utils/create-provider.cjs"),v=new K.AttachableMemoryCacheDevice,P=new K.AttachableMemoryCacheDevice,q={privateKey:"",publicKey:""};class g{signature;constructor(e){this.signature=e}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error("No signature provided")}verifyMessage(e){return this.requireSignature(),n.ethers.verifyMessage(e,this.signature)}getShieldedPrivateKey=()=>(this.requireSignature(),n.ethers.keccak256(this.signature));getShieldedPublicKey=()=>(this.requireSignature(),h.poseidonHash(this.getShieldedPrivateKey()));getDerivedEthereumAddress=()=>(this.requireSignature(),new n.ethers.Wallet(this.getShieldedPrivateKey()).address);getDerivedSolanaPublicKey=()=>(this.requireSignature(),c.Keypair.fromSeed(n.ethers.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());getAccessKey=()=>(this.requireSignature(),h.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getSignerPrivateKeyFromNonce=e=>{this.requireSignature();const r=h.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return n.ethers.keccak256(n.ethers.toUtf8Bytes(r))};getSignerSolanaPrivateKeyFromNonce=e=>{const r=this.getSignerPrivateKeyFromNonce(e),t=n.ethers.getBytes(r),i=c.Keypair.fromSeed(t);return p.encode(i.secretKey)};getEvmPrivateKeyFromSolanaPrivateKey=e=>{const t=p.decode(e).slice(0,32);return n.ethers.hexlify(t)};static getSignerFromPrivateKey=(e,r)=>{if(l.isSolanaLike(e)){const i=n.ethers.getBytes(r);return c.Keypair.fromSeed(i)}return new n.ethers.Wallet(r)};static getSignerAddressFromPrivateKey(e,r){const t=g.getSignerFromPrivateKey(e,r);return t instanceof c.Keypair?t.publicKey.toString():t.address}static signMessageFromPrivateKey=async(e,r,t)=>{const i=g.getSignerFromPrivateKey(e,r);if(i instanceof c.Keypair){const a=n.ethers.isHexString(t)?n.ethers.getBytes(t):new TextEncoder().encode(t),o=m.sign.detached(a,i.secretKey);return`0x${Buffer.from(o).toString("hex")}`}const s=n.ethers.isHexString(t)?n.ethers.getBytes(t):t;return i.signMessage(s)};static signSolanaTransactionFromPrivateKey=(e,r,t)=>{if(!l.isSolanaLike(e))throw new Error("Solana transaction signing is only available for Solana chains");const i=g.getSignerFromPrivateKey(e,r);if(!(i instanceof c.Keypair))throw new Error("Unable to derive Solana keypair for signing");t.sign([i])};static sendAndSignTransactionFromPrivateKey=async(e,r,t)=>{const i=g.getSignerFromPrivateKey(e,r),{fetchRpcUrl:s}=l.networkRegistry[e];if(!s)throw new Error("No RPC URL found for chainId");if(i instanceof c.Keypair){if(!(t instanceof c.VersionedTransaction))throw new Error("Invalid transaction type for Solana");return t.sign([i]),await b.createCustomSolanaConnection(s).sendRawTransaction(t.serialize())}if(t instanceof c.VersionedTransaction)throw new Error("Invalid transaction type for EVM");const a=new n.ethers.JsonRpcProvider(s);return(await i.connect(a).sendTransaction(t)).hash};static signTypedDataFromPrivateKey=async(e,r,t,i,s)=>{if(l.isSolanaLike(e))throw new Error("Solana does not support typed data");return await g.getSignerFromPrivateKey(e,r).signTypedData(t,i,s)};static authorizeDelegation=async(e,r,t,i)=>{if(l.isSolanaLike(e))throw new Error("Solana does not support delegation");const s=new n.ethers.JsonRpcProvider(l.networkRegistry[e].fetchRpcUrl);return await g.getSignerFromPrivateKey(e,r).connect(s).authorize({address:t,...i!==void 0&&{nonce:i}})};getWalletSalt=e=>(this.requireSignature(),h.poseidonHash(this.getShieldedPublicKey(),this.getShieldedPrivateKey(),e));getInHinkalAddress=e=>{this.requireSignature();const r=h.poseidonHash(this.getShieldedPrivateKey(),e);return BigInt(r)};getBackendToken=()=>(this.requireSignature(),h.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()));static getRandomizedStealthPair=v.attach((e,r)=>{const t=f.babyJubInstance(),i=BigInt(r)%S.CIRCOM_P,s=e*i%S.CIRCOM_P,a=t.mulPointEscalar(t.Base8,e),o=t.mulPointEscalar(t.Base8,s),u=[BigInt(t.F.toString(a[0])),BigInt(t.F.toString(a[1]))],y=[BigInt(t.F.toString(o[0])),BigInt(t.F.toString(o[1]))];return{H0:u,H1:y}});static getStealthAddressCompressedPoints=(e,r)=>{const{H0:t,H1:i}=this.getRandomizedStealthPair(e,r),[s,a]=[t,i].map(o=>BigInt(o[1])+2n**255n*d.getCircomSign(o[0]));return{h0:s,h1:a}};static getStealthAddress=P.attach((e,r)=>{const{H0:t,H1:i}=this.getRandomizedStealthPair(e,r),a=[2n*d.getCircomSign(t[0])+d.getCircomSign(i[0]),t[1],i[1]];return h.poseidonHash(...a)});static getStealthAddressWithEKey=(e,r)=>({stealthAddress:this.getStealthAddress(e,r),encryptionKey:this.getEncryptionKeyPair(r).publicKey});static checkSignature=(e,r,t,i)=>{const{h0:s,h1:a}=this.getStealthAddressCompressedPoints(e,i);return r===s&&t===a};static getEncryptionKeyPair=e=>{const r=w.crypto_box_seed_keypair(n.ethers.getBytes(e));return{privateKey:n.ethers.hexlify(r.privateKey),publicKey:n.ethers.hexlify(r.publicKey)}}}exports.EncryptionKeyPairDefaultValue=q;exports.UserKeys=g;exports.stealthAddressCacheDevice=P;exports.stealthPairCacheDevice=v;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { AttachableMemoryCacheDevice } from '../cacheDevices/AttachableMemoryCacheDevice';
|
|
3
|
-
import { ethers as ethersV6 } from 'ethers-v6h';
|
|
4
3
|
import { VersionedTransaction } from '@solana/web3.js';
|
|
5
4
|
export declare const stealthPairCacheDevice: AttachableMemoryCacheDevice<{
|
|
6
5
|
H0: [bigint, bigint];
|
|
@@ -52,9 +51,9 @@ export declare class UserKeys {
|
|
|
52
51
|
static getSignerAddressFromPrivateKey(chainId: number, privateKey: string): string;
|
|
53
52
|
static signMessageFromPrivateKey: (chainId: number, privateKey: string, message: string) => Promise<string>;
|
|
54
53
|
static signSolanaTransactionFromPrivateKey: (chainId: number, privateKey: string, transaction: VersionedTransaction) => void;
|
|
55
|
-
static sendAndSignTransactionFromPrivateKey: (chainId: number, privateKey: string, transaction:
|
|
54
|
+
static sendAndSignTransactionFromPrivateKey: (chainId: number, privateKey: string, transaction: ethers.TransactionRequest | VersionedTransaction) => Promise<string>;
|
|
56
55
|
static signTypedDataFromPrivateKey: (chainId: number, privateKey: string, domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, value: Record<string, any>) => Promise<string>;
|
|
57
|
-
static authorizeDelegation: (chainId: number, privateKey: string, implementation: string, nonce?: number) => Promise<
|
|
56
|
+
static authorizeDelegation: (chainId: number, privateKey: string, implementation: string, nonce?: number) => Promise<ethers.Authorization>;
|
|
58
57
|
getWalletSalt: (walletNonce: bigint) => string;
|
|
59
58
|
/**
|
|
60
59
|
* generate inHinkalAddress - a user unique address linking him with a specific app
|