@hinkal/common 0.2.22 → 0.2.24
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 +27 -28
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +1 -0
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +35 -36
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +86 -83
- 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 +72 -73
- 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,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
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { CIRCOM_P as
|
|
4
|
-
import { babyJubInstance as
|
|
1
|
+
import { ethers as n } from "ethers";
|
|
2
|
+
import P from "libsodium-wrappers";
|
|
3
|
+
import { CIRCOM_P as S } from "../../constants/protocol.constants.mjs";
|
|
4
|
+
import { babyJubInstance as v } from "../../crypto/babyJub.mjs";
|
|
5
5
|
import { poseidonHash as c } from "../../crypto/poseidon.mjs";
|
|
6
|
-
import { getCircomSign as
|
|
7
|
-
import { AttachableMemoryCacheDevice as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
const E = new v(), R = new v(), L = {
|
|
6
|
+
import { getCircomSign as u } from "./keyUtils.mjs";
|
|
7
|
+
import { AttachableMemoryCacheDevice as K } from "../cacheDevices/AttachableMemoryCacheDevice.mjs";
|
|
8
|
+
import { isSolanaLike as d, networkRegistry as p } from "../../constants/chains.constants.mjs";
|
|
9
|
+
import { Keypair as g, VersionedTransaction as m } from "@solana/web3.js";
|
|
10
|
+
import w from "tweetnacl";
|
|
11
|
+
import f from "bs58";
|
|
12
|
+
import { createCustomSolanaConnection as b } from "../../functions/utils/create-provider.mjs";
|
|
13
|
+
const F = new K(), B = new K(), W = {
|
|
15
14
|
privateKey: "",
|
|
16
15
|
publicKey: ""
|
|
17
16
|
};
|
|
@@ -31,14 +30,14 @@ class l {
|
|
|
31
30
|
throw Error("No signature provided");
|
|
32
31
|
}
|
|
33
32
|
verifyMessage(e) {
|
|
34
|
-
return this.requireSignature(),
|
|
33
|
+
return this.requireSignature(), n.verifyMessage(e, this.signature);
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
36
|
* get shielded private key from message signature used to login to the application,
|
|
38
37
|
* this private key is used to generate encryption keypairs as well as public key
|
|
39
38
|
* @retuns 0x-prefixed shielded private key
|
|
40
39
|
*/
|
|
41
|
-
getShieldedPrivateKey = () => (this.requireSignature(),
|
|
40
|
+
getShieldedPrivateKey = () => (this.requireSignature(), n.keccak256(this.signature));
|
|
42
41
|
/**
|
|
43
42
|
* generate shielded public key from private key
|
|
44
43
|
* @param privateKey the key used to generate the shielded public key, this should be the signature
|
|
@@ -49,11 +48,11 @@ class l {
|
|
|
49
48
|
/**
|
|
50
49
|
* deterministically derive an EVM address from the shielded private key
|
|
51
50
|
*/
|
|
52
|
-
getDerivedEthereumAddress = () => (this.requireSignature(), new
|
|
51
|
+
getDerivedEthereumAddress = () => (this.requireSignature(), new n.Wallet(this.getShieldedPrivateKey()).address);
|
|
53
52
|
/**
|
|
54
53
|
* deterministically derive a Solana public key from the shielded private key
|
|
55
54
|
*/
|
|
56
|
-
getDerivedSolanaPublicKey = () => (this.requireSignature(), g.fromSeed(
|
|
55
|
+
getDerivedSolanaPublicKey = () => (this.requireSignature(), g.fromSeed(n.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());
|
|
57
56
|
/**
|
|
58
57
|
* generate access token, this accessKey is what should be sent to the server for signing
|
|
59
58
|
* @returns accessKey in hexstring with 0x prefixed
|
|
@@ -62,22 +61,22 @@ class l {
|
|
|
62
61
|
getSignerPrivateKeyFromNonce = (e) => {
|
|
63
62
|
this.requireSignature();
|
|
64
63
|
const r = c(e, this.getShieldedPrivateKey(), this.getShieldedPublicKey());
|
|
65
|
-
return
|
|
64
|
+
return n.keccak256(n.toUtf8Bytes(r));
|
|
66
65
|
};
|
|
67
66
|
getSignerSolanaPrivateKeyFromNonce = (e) => {
|
|
68
|
-
const r = this.getSignerPrivateKeyFromNonce(e), t =
|
|
69
|
-
return
|
|
67
|
+
const r = this.getSignerPrivateKeyFromNonce(e), t = n.getBytes(r), i = g.fromSeed(t);
|
|
68
|
+
return f.encode(i.secretKey);
|
|
70
69
|
};
|
|
71
70
|
getEvmPrivateKeyFromSolanaPrivateKey = (e) => {
|
|
72
|
-
const t =
|
|
73
|
-
return
|
|
71
|
+
const t = f.decode(e).slice(0, 32);
|
|
72
|
+
return n.hexlify(t);
|
|
74
73
|
};
|
|
75
74
|
static getSignerFromPrivateKey = (e, r) => {
|
|
76
|
-
if (
|
|
77
|
-
const i =
|
|
75
|
+
if (d(e)) {
|
|
76
|
+
const i = n.getBytes(r);
|
|
78
77
|
return g.fromSeed(i);
|
|
79
78
|
}
|
|
80
|
-
return new
|
|
79
|
+
return new n.Wallet(r);
|
|
81
80
|
};
|
|
82
81
|
static getSignerAddressFromPrivateKey(e, r) {
|
|
83
82
|
const t = l.getSignerFromPrivateKey(e, r);
|
|
@@ -86,14 +85,14 @@ class l {
|
|
|
86
85
|
static signMessageFromPrivateKey = async (e, r, t) => {
|
|
87
86
|
const i = l.getSignerFromPrivateKey(e, r);
|
|
88
87
|
if (i instanceof g) {
|
|
89
|
-
const a =
|
|
90
|
-
return `0x${Buffer.from(
|
|
88
|
+
const a = n.isHexString(t) ? n.getBytes(t) : new TextEncoder().encode(t), o = w.sign.detached(a, i.secretKey);
|
|
89
|
+
return `0x${Buffer.from(o).toString("hex")}`;
|
|
91
90
|
}
|
|
92
|
-
const
|
|
93
|
-
return i.signMessage(
|
|
91
|
+
const s = n.isHexString(t) ? n.getBytes(t) : t;
|
|
92
|
+
return i.signMessage(s);
|
|
94
93
|
};
|
|
95
94
|
static signSolanaTransactionFromPrivateKey = (e, r, t) => {
|
|
96
|
-
if (!
|
|
95
|
+
if (!d(e))
|
|
97
96
|
throw new Error("Solana transaction signing is only available for Solana chains");
|
|
98
97
|
const i = l.getSignerFromPrivateKey(e, r);
|
|
99
98
|
if (!(i instanceof g))
|
|
@@ -101,29 +100,29 @@ class l {
|
|
|
101
100
|
t.sign([i]);
|
|
102
101
|
};
|
|
103
102
|
static sendAndSignTransactionFromPrivateKey = async (e, r, t) => {
|
|
104
|
-
const i = l.getSignerFromPrivateKey(e, r), { fetchRpcUrl:
|
|
105
|
-
if (!
|
|
103
|
+
const i = l.getSignerFromPrivateKey(e, r), { fetchRpcUrl: s } = p[e];
|
|
104
|
+
if (!s)
|
|
106
105
|
throw new Error("No RPC URL found for chainId");
|
|
107
106
|
if (i instanceof g) {
|
|
108
|
-
if (!(t instanceof
|
|
107
|
+
if (!(t instanceof m))
|
|
109
108
|
throw new Error("Invalid transaction type for Solana");
|
|
110
|
-
return t.sign([i]), await
|
|
109
|
+
return t.sign([i]), await b(s).sendRawTransaction(t.serialize());
|
|
111
110
|
}
|
|
112
|
-
if (t instanceof
|
|
111
|
+
if (t instanceof m)
|
|
113
112
|
throw new Error("Invalid transaction type for EVM");
|
|
114
|
-
const a = new
|
|
113
|
+
const a = new n.JsonRpcProvider(s);
|
|
115
114
|
return (await i.connect(a).sendTransaction(t)).hash;
|
|
116
115
|
};
|
|
117
|
-
static signTypedDataFromPrivateKey = async (e, r, t, i,
|
|
118
|
-
if (
|
|
116
|
+
static signTypedDataFromPrivateKey = async (e, r, t, i, s) => {
|
|
117
|
+
if (d(e))
|
|
119
118
|
throw new Error("Solana does not support typed data");
|
|
120
|
-
return await l.getSignerFromPrivateKey(e, r).signTypedData(t, i,
|
|
119
|
+
return await l.getSignerFromPrivateKey(e, r).signTypedData(t, i, s);
|
|
121
120
|
};
|
|
122
121
|
static authorizeDelegation = async (e, r, t, i) => {
|
|
123
|
-
if (
|
|
122
|
+
if (d(e))
|
|
124
123
|
throw new Error("Solana does not support delegation");
|
|
125
|
-
const
|
|
126
|
-
return await l.getSignerFromPrivateKey(e, r).connect(
|
|
124
|
+
const s = new n.JsonRpcProvider(p[e].fetchRpcUrl);
|
|
125
|
+
return await l.getSignerFromPrivateKey(e, r).connect(s).authorize({ address: t, ...i !== void 0 && { nonce: i } });
|
|
127
126
|
};
|
|
128
127
|
getWalletSalt = (e) => (this.requireSignature(), c(this.getShieldedPublicKey(), this.getShieldedPrivateKey(), e));
|
|
129
128
|
/**
|
|
@@ -140,24 +139,24 @@ class l {
|
|
|
140
139
|
* @returns accessKey in hexstring with 0x prefixed
|
|
141
140
|
*/
|
|
142
141
|
getBackendToken = () => (this.requireSignature(), c(this.getAccessKey(), this.getShieldedPublicKey()));
|
|
143
|
-
static getRandomizedStealthPair =
|
|
142
|
+
static getRandomizedStealthPair = F.attach(
|
|
144
143
|
(e, r) => {
|
|
145
|
-
const t =
|
|
146
|
-
return { H0:
|
|
144
|
+
const t = v(), i = BigInt(r) % S, s = e * i % S, a = t.mulPointEscalar(t.Base8, e), o = t.mulPointEscalar(t.Base8, s), h = [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]))];
|
|
145
|
+
return { H0: h, H1: y };
|
|
147
146
|
}
|
|
148
147
|
);
|
|
149
148
|
static getStealthAddressCompressedPoints = (e, r) => {
|
|
150
|
-
const { H0: t, H1: i } = this.getRandomizedStealthPair(e, r), [
|
|
151
|
-
return { h0:
|
|
149
|
+
const { H0: t, H1: i } = this.getRandomizedStealthPair(e, r), [s, a] = [t, i].map((o) => BigInt(o[1]) + 2n ** 255n * u(o[0]));
|
|
150
|
+
return { h0: s, h1: a };
|
|
152
151
|
};
|
|
153
|
-
static getStealthAddress =
|
|
154
|
-
const { H0: t, H1: i } = this.getRandomizedStealthPair(e, r), a = [2n *
|
|
152
|
+
static getStealthAddress = B.attach((e, r) => {
|
|
153
|
+
const { H0: t, H1: i } = this.getRandomizedStealthPair(e, r), a = [2n * u(t[0]) + u(i[0]), t[1], i[1]];
|
|
155
154
|
return c(...a);
|
|
156
155
|
});
|
|
157
156
|
static getStealthAddressWithEKey = (e, r) => ({ stealthAddress: this.getStealthAddress(e, r), encryptionKey: this.getEncryptionKeyPair(r).publicKey });
|
|
158
157
|
static checkSignature = (e, r, t, i) => {
|
|
159
|
-
const { h0:
|
|
160
|
-
return r ===
|
|
158
|
+
const { h0: s, h1: a } = this.getStealthAddressCompressedPoints(e, i);
|
|
159
|
+
return r === s && t === a;
|
|
161
160
|
};
|
|
162
161
|
/**
|
|
163
162
|
* generate private and public keypair
|
|
@@ -165,16 +164,16 @@ class l {
|
|
|
165
164
|
* and must correspond to 32 bytes
|
|
166
165
|
*/
|
|
167
166
|
static getEncryptionKeyPair = (e) => {
|
|
168
|
-
const r =
|
|
167
|
+
const r = P.crypto_box_seed_keypair(n.getBytes(e));
|
|
169
168
|
return {
|
|
170
|
-
privateKey:
|
|
171
|
-
publicKey:
|
|
169
|
+
privateKey: n.hexlify(r.privateKey),
|
|
170
|
+
publicKey: n.hexlify(r.publicKey)
|
|
172
171
|
};
|
|
173
172
|
};
|
|
174
173
|
}
|
|
175
174
|
export {
|
|
176
|
-
|
|
175
|
+
W as EncryptionKeyPairDefaultValue,
|
|
177
176
|
l as UserKeys,
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
B as stealthAddressCacheDevice,
|
|
178
|
+
F as stealthPairCacheDevice
|
|
180
179
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../../functions/utils/resolve-sync.utils.cjs");class h{blockchainEventEmitter;eventName;constructor(e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../../functions/utils/resolve-sync.utils.cjs");class h{blockchainEventEmitter;eventName;constructor(e,s){this.blockchainEventEmitter=e,this.eventName=s,e.addEventProcessorFunction(this.processEventsPage.bind(this))}get latestBlockNumber(){return this.blockchainEventEmitter.latestBlockNumber}intervalClear(){this.blockchainEventEmitter.intervalClear()}async processEventsPage(e){const s=new Set;e.forEach(t=>{t.eventName==="BlockedUtxosCreated"&&s.add(t.transactionHash)});const n=[];await v.resolveSync(e.map(t=>async()=>{if(t.eventName!==this.eventName)return;const{args:c,blockNumber:i,transactionHash:a}=t;if(!c)throw new Error("Wrong event structure");const r=this.mapEvent(c),l=s.has(a);await this.acceptEvent(r,i,a,l)&&n.push(r)}));const o=n.length;return await this.afterEventsAccepted(o),n.length}}exports.AbstractEventService=h;
|
|
@@ -2,8 +2,8 @@ import { resolveSync as v } from "../../../functions/utils/resolve-sync.utils.mj
|
|
|
2
2
|
class u {
|
|
3
3
|
blockchainEventEmitter;
|
|
4
4
|
eventName;
|
|
5
|
-
constructor(t,
|
|
6
|
-
this.blockchainEventEmitter = t, this.eventName =
|
|
5
|
+
constructor(t, s) {
|
|
6
|
+
this.blockchainEventEmitter = t, this.eventName = s, t.addEventProcessorFunction(this.processEventsPage.bind(this));
|
|
7
7
|
}
|
|
8
8
|
get latestBlockNumber() {
|
|
9
9
|
return this.blockchainEventEmitter.latestBlockNumber;
|
|
@@ -12,24 +12,24 @@ class u {
|
|
|
12
12
|
this.blockchainEventEmitter.intervalClear();
|
|
13
13
|
}
|
|
14
14
|
async processEventsPage(t) {
|
|
15
|
-
const
|
|
16
|
-
t.forEach((
|
|
17
|
-
|
|
15
|
+
const s = /* @__PURE__ */ new Set();
|
|
16
|
+
t.forEach((e) => {
|
|
17
|
+
e.eventName === "BlockedUtxosCreated" && s.add(e.transactionHash);
|
|
18
18
|
});
|
|
19
|
-
const
|
|
19
|
+
const n = [];
|
|
20
20
|
await v(
|
|
21
|
-
t.map((
|
|
22
|
-
if (
|
|
21
|
+
t.map((e) => async () => {
|
|
22
|
+
if (e.eventName !== this.eventName)
|
|
23
23
|
return;
|
|
24
|
-
const { args:
|
|
25
|
-
if (!
|
|
24
|
+
const { args: a, blockNumber: i, transactionHash: c } = e;
|
|
25
|
+
if (!a)
|
|
26
26
|
throw new Error("Wrong event structure");
|
|
27
|
-
const r = this.mapEvent(
|
|
28
|
-
await this.acceptEvent(r, i,
|
|
27
|
+
const r = this.mapEvent(a), h = s.has(c);
|
|
28
|
+
await this.acceptEvent(r, i, c, h) && n.push(r);
|
|
29
29
|
})
|
|
30
30
|
);
|
|
31
|
-
const o =
|
|
32
|
-
return await this.afterEventsAccepted(o),
|
|
31
|
+
const o = n.length;
|
|
32
|
+
return await this.afterEventsAccepted(o), n.length;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("ethers"),i=require("./AbstractSnapshotService.cjs");class s extends i.AbstractSnapshotService{constructor(e){super(e,"Nullified")}_nullifiers;get nullifiers(){return this._nullifiers}serializeSnapshot(e){return{nullifiers:Array.from(e.payload.nullifiers).map(r=>r.toString()),latestBlockNumber:e.latestBlockNumber}}deserializeSnapshot(e){return{latestBlockNumber:e.latestBlockNumber??0,payload:{nullifiers:new Set(e.nullifiers??[])}}}acceptEvent(e,r){try{return this._nullifiers.has(e.nullifier)?!1:(this._nullifiers.add(e.nullifier),!0)}catch(t){return console.error(t),!1}}mapEvent(e){const{nullifier:r}=e;return{nullifier:l.ethers.toBeHex(r)}}getSnapshotPayload(){return{nullifiers:this._nullifiers}}populateSnapshot({payload:{nullifiers:e}}){this._nullifiers=e}}exports.AbstractNullifierSnapshotService=s;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumber } from 'ethers';
|
|
2
1
|
import { NullifierEvent } from '../../../types/commitments.types';
|
|
3
2
|
import { AbstractSnapshotService, Snapshot } from './AbstractSnapshotService';
|
|
4
3
|
import { BlockchainEventEmitter } from './BlockchainEventEmitter';
|
|
@@ -9,14 +8,14 @@ export type NullifierSerializedSnapshot = {
|
|
|
9
8
|
latestBlockNumber?: number;
|
|
10
9
|
nullifiers?: string[];
|
|
11
10
|
};
|
|
12
|
-
export declare abstract class AbstractNullifierSnapshotService extends AbstractSnapshotService<NullifierEvent<string>, NullifierEvent<
|
|
11
|
+
export declare abstract class AbstractNullifierSnapshotService extends AbstractSnapshotService<NullifierEvent<string>, NullifierEvent<bigint>, NullifierSnapshotPayload, NullifierSerializedSnapshot> {
|
|
13
12
|
constructor(hinkalEventEmitter: BlockchainEventEmitter);
|
|
14
13
|
private _nullifiers;
|
|
15
14
|
get nullifiers(): Set<string>;
|
|
16
15
|
protected serializeSnapshot(snapshot: Snapshot<NullifierSnapshotPayload>): NullifierSerializedSnapshot;
|
|
17
16
|
protected deserializeSnapshot(serializedSnapshot: NullifierSerializedSnapshot): Snapshot<NullifierSnapshotPayload>;
|
|
18
17
|
protected acceptEvent(event: NullifierEvent<string>, _blockNumber: number): boolean;
|
|
19
|
-
protected mapEvent(event: NullifierEvent<
|
|
18
|
+
protected mapEvent(event: NullifierEvent<bigint>): NullifierEvent<string>;
|
|
20
19
|
protected getSnapshotPayload(): NullifierSnapshotPayload;
|
|
21
20
|
protected populateSnapshot({ payload: { nullifiers } }: Snapshot<NullifierSnapshotPayload>): void;
|
|
22
21
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ethers as i } from "ethers";
|
|
2
|
+
import { AbstractSnapshotService as t } from "./AbstractSnapshotService.mjs";
|
|
3
|
+
class a extends t {
|
|
3
4
|
constructor(r) {
|
|
4
5
|
super(r, "Nullified");
|
|
5
6
|
}
|
|
@@ -31,7 +32,7 @@ class n extends i {
|
|
|
31
32
|
mapEvent(r) {
|
|
32
33
|
const { nullifier: e } = r;
|
|
33
34
|
return {
|
|
34
|
-
nullifier:
|
|
35
|
+
nullifier: i.toBeHex(e)
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
getSnapshotPayload() {
|
|
@@ -44,5 +45,5 @@ class n extends i {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
export {
|
|
47
|
-
|
|
48
|
+
a as AbstractNullifierSnapshotService
|
|
48
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../../constants/save-depths.cjs"),a=require("./AbstractEventService.cjs");class i extends a.AbstractEventService{savedLatestBlockNumber=0;chainId=0;constructor(t,e){super(t,e)}async init(){await this.loadSnapshot()
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../../constants/save-depths.cjs"),a=require("./AbstractEventService.cjs"),r=require("../../../functions/utils/getSignerFromContract.cjs");class i extends a.AbstractEventService{savedLatestBlockNumber=0;chainId=0;constructor(t,e){super(t,e)}async init(){await this.loadSnapshot();const t=r.getProviderFromContract(this.blockchainEventEmitter.contract);this.chainId=Number((await t.getNetwork()).chainId)}async retrieveEventsFromLatestBlock(){await this.blockchainEventEmitter.retrieveEvents(this.latestBlockNumber)}async loadSnapshot(){const t=await this.fetchSnapshot(),e=this.deserializeSnapshot(t);this.populateSnapshot(e),this.blockchainEventEmitter.syncFromAtMost(e.latestBlockNumber),this.savedLatestBlockNumber=e.latestBlockNumber}saveSnapshot(){return this.savedLatestBlockNumber=this.latestBlockNumber,this.persistSnapshot(this.serializeSnapshot({latestBlockNumber:this.latestBlockNumber,payload:this.getSnapshotPayload()}))}async afterEventsAccepted(t){(t>0||this.savedLatestBlockNumber+s.saveDepths[this.chainId]<this.latestBlockNumber)&&await this.saveSnapshot()}}exports.AbstractSnapshotService=i;
|