@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.
Files changed (242) hide show
  1. package/API/proxyAccountsCalls.cjs +1 -1
  2. package/API/proxyAccountsCalls.mjs +13 -13
  3. package/README.md +63 -267
  4. package/constants/activity.constants.cjs +1 -1
  5. package/constants/activity.constants.mjs +0 -1
  6. package/constants/addresses.constants.cjs +1 -1
  7. package/constants/addresses.constants.mjs +9 -10
  8. package/constants/contracts.constants.cjs +1 -1
  9. package/constants/contracts.constants.d.ts +3 -3
  10. package/constants/contracts.constants.mjs +29 -29
  11. package/constants/server.constants.cjs +1 -1
  12. package/constants/server.constants.mjs +28 -29
  13. package/constants/tasks.constants.cjs +1 -1
  14. package/constants/tasks.constants.mjs +4 -5
  15. package/crypto/poseidon.cjs +1 -1
  16. package/crypto/poseidon.mjs +10 -10
  17. package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
  18. package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +24 -24
  19. package/data-structures/Hinkal/Hinkal.cjs +1 -1
  20. package/data-structures/Hinkal/Hinkal.mjs +4 -5
  21. package/data-structures/Hinkal/IHinkal.d.ts +2 -2
  22. package/data-structures/Hinkal/hinkalApprove.cjs +1 -1
  23. package/data-structures/Hinkal/hinkalApprove.mjs +40 -40
  24. package/data-structures/Hinkal/hinkalCheckTokenRegistry.cjs +1 -1
  25. package/data-structures/Hinkal/hinkalCheckTokenRegistry.mjs +7 -8
  26. package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
  27. package/data-structures/Hinkal/hinkalDeposit.mjs +4 -5
  28. package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
  29. package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +2 -3
  30. package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
  31. package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +18 -19
  32. package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
  33. package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +3 -4
  34. package/data-structures/Hinkal/hinkalInsideTransact.cjs +1 -1
  35. package/data-structures/Hinkal/hinkalInsideTransact.mjs +14 -13
  36. package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
  37. package/data-structures/Hinkal/hinkalPrivateWallet.mjs +2 -3
  38. package/data-structures/Hinkal/hinkalProoflessDeposit.cjs +1 -1
  39. package/data-structures/Hinkal/hinkalProoflessDeposit.mjs +27 -26
  40. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
  41. package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +38 -39
  42. package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
  43. package/data-structures/Hinkal/hinkalSolanaSwap.mjs +16 -17
  44. package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
  45. package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +24 -25
  46. package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
  47. package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +15 -16
  48. package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
  49. package/data-structures/Hinkal/hinkalSwap.mjs +2 -3
  50. package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
  51. package/data-structures/Hinkal/hinkalTransfer.mjs +2 -3
  52. package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
  53. package/data-structures/Hinkal/hinkalWithdraw.mjs +9 -10
  54. package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
  55. package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +8 -9
  56. package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
  57. package/data-structures/Hinkal/resetMerkleTrees.mjs +10 -10
  58. package/data-structures/IndexedDB/activity-db.cjs +1 -1
  59. package/data-structures/IndexedDB/activity-db.mjs +39 -41
  60. package/data-structures/IndexedDB/balances-db.cjs +1 -1
  61. package/data-structures/IndexedDB/balances-db.mjs +8 -9
  62. package/data-structures/IndexedDB/contact-db.cjs +1 -1
  63. package/data-structures/IndexedDB/contact-db.mjs +21 -23
  64. package/data-structures/IndexedDB/signatures-db.cjs +1 -1
  65. package/data-structures/IndexedDB/signatures-db.mjs +2 -3
  66. package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
  67. package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +34 -36
  68. package/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
  69. package/data-structures/crypto-keys/decodeUTXO.mjs +45 -45
  70. package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
  71. package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +28 -27
  72. package/data-structures/crypto-keys/keys.cjs +1 -1
  73. package/data-structures/crypto-keys/keys.d.ts +2 -3
  74. package/data-structures/crypto-keys/keys.mjs +56 -57
  75. package/data-structures/event-service/evm/AbstractEventService.cjs +1 -1
  76. package/data-structures/event-service/evm/AbstractEventService.mjs +14 -14
  77. package/data-structures/event-service/evm/AbstractNullifierSnapshotService.cjs +1 -1
  78. package/data-structures/event-service/evm/AbstractNullifierSnapshotService.d.ts +2 -3
  79. package/data-structures/event-service/evm/AbstractNullifierSnapshotService.mjs +5 -4
  80. package/data-structures/event-service/evm/AbstractSnapshotService.cjs +1 -1
  81. package/data-structures/event-service/evm/AbstractSnapshotService.mjs +6 -3
  82. package/data-structures/event-service/evm/BlockchainEventEmitter.cjs +1 -1
  83. package/data-structures/event-service/evm/BlockchainEventEmitter.d.ts +1 -1
  84. package/data-structures/event-service/evm/BlockchainEventEmitter.mjs +22 -18
  85. package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.cjs +1 -1
  86. package/data-structures/event-service/solana/AbstractSolanaNullifierSnapshotService.mjs +2 -2
  87. package/data-structures/presale/PresaleContractWrapper.cjs +1 -1
  88. package/data-structures/presale/PresaleContractWrapper.d.ts +3 -3
  89. package/data-structures/presale/PresaleContractWrapper.mjs +10 -10
  90. package/data-structures/provider-adapter/IProviderAdapter.d.ts +7 -7
  91. package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.cjs +1 -1
  92. package/data-structures/snapshot/evm-snapshots/ClientAccessTokenSnapshotService.mjs +16 -14
  93. package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.cjs +1 -1
  94. package/data-structures/snapshot/evm-snapshots/ClientApprovalsSnapshotService.mjs +7 -5
  95. package/error-handling/get-error.message.cjs +1 -1
  96. package/error-handling/get-error.message.mjs +2 -3
  97. package/functions/kyc/zkMeHelper.cjs +1 -1
  98. package/functions/kyc/zkMeHelper.mjs +3 -3
  99. package/functions/pre-transaction/getFlatFees.cjs +1 -1
  100. package/functions/pre-transaction/getFlatFees.mjs +2 -3
  101. package/functions/pre-transaction/getSolanaCalldataHash.cjs +1 -1
  102. package/functions/pre-transaction/getSolanaCalldataHash.mjs +21 -21
  103. package/functions/pre-transaction/getVolatileTransferAmount.cjs +1 -1
  104. package/functions/pre-transaction/getVolatileTransferAmount.mjs +2 -3
  105. package/functions/pre-transaction/interaction-to-action.cjs +1 -1
  106. package/functions/pre-transaction/interaction-to-action.mjs +2 -3
  107. package/functions/private-wallet/emporium.helpers.cjs +1 -1
  108. package/functions/private-wallet/emporium.helpers.d.ts +6 -7
  109. package/functions/private-wallet/emporium.helpers.mjs +104 -105
  110. package/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
  111. package/functions/private-wallet/emporium.swap.helpers.mjs +44 -43
  112. package/functions/private-wallet/opProducer.cjs +1 -1
  113. package/functions/private-wallet/opProducer.mjs +1 -1
  114. package/functions/snarkjs/common.snarkjs.cjs +1 -1
  115. package/functions/snarkjs/common.snarkjs.mjs +21 -18
  116. package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
  117. package/functions/snarkjs/constructSolanaZkProof.mjs +11 -12
  118. package/functions/utils/addresses.cjs +1 -1
  119. package/functions/utils/addresses.mjs +6 -6
  120. package/functions/utils/cacheFunctions.cjs +1 -1
  121. package/functions/utils/cacheFunctions.d.ts +1 -1
  122. package/functions/utils/cacheFunctions.mjs +55 -54
  123. package/functions/utils/convertEmporiumOpToCallInfo.cjs +1 -1
  124. package/functions/utils/convertEmporiumOpToCallInfo.mjs +5 -5
  125. package/functions/utils/create-provider.cjs +1 -1
  126. package/functions/utils/create-provider.d.ts +2 -2
  127. package/functions/utils/create-provider.mjs +5 -5
  128. package/functions/utils/encryptInputForEnclave.cjs +1 -1
  129. package/functions/utils/encryptInputForEnclave.mjs +9 -9
  130. package/functions/utils/ethers-formatter.utils.d.ts +1 -1
  131. package/functions/utils/external-action.utils.cjs +1 -1
  132. package/functions/utils/external-action.utils.mjs +2 -2
  133. package/functions/utils/getContractAddress.cjs +1 -0
  134. package/functions/utils/getContractAddress.d.ts +2 -0
  135. package/functions/utils/getContractAddress.mjs +9 -0
  136. package/functions/utils/getDataFromTransaction.cjs +1 -1
  137. package/functions/utils/getDataFromTransaction.d.ts +0 -11
  138. package/functions/utils/getDataFromTransaction.mjs +26 -50
  139. package/functions/utils/getRecipientInfoFromUserKeys.cjs +1 -1
  140. package/functions/utils/getRecipientInfoFromUserKeys.mjs +1 -1
  141. package/functions/utils/getSignerFromContract.cjs +1 -0
  142. package/functions/utils/getSignerFromContract.d.ts +3 -0
  143. package/functions/utils/getSignerFromContract.mjs +16 -0
  144. package/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
  145. package/functions/utils/getUtxosFromReceipt.utils.d.ts +1 -1
  146. package/functions/utils/getUtxosFromReceipt.utils.mjs +15 -16
  147. package/functions/utils/inLogicMetadata.cjs +1 -1
  148. package/functions/utils/inLogicMetadata.mjs +2 -2
  149. package/functions/utils/nftTokenFunctions.cjs +1 -1
  150. package/functions/utils/nftTokenFunctions.mjs +2 -3
  151. package/functions/utils/publicBalance.utils.cjs +1 -1
  152. package/functions/utils/publicBalance.utils.d.ts +1 -1
  153. package/functions/utils/publicBalance.utils.mjs +42 -42
  154. package/functions/utils/rpc-int-encode.cjs +1 -1
  155. package/functions/utils/rpc-int-encode.d.ts +1 -2
  156. package/functions/utils/rpc-int-encode.mjs +3 -6
  157. package/functions/utils/solanaMint.utils.cjs +1 -1
  158. package/functions/utils/solanaMint.utils.mjs +6 -6
  159. package/functions/web3/EIP-712.cjs +1 -1
  160. package/functions/web3/EIP-712.d.ts +4 -4
  161. package/functions/web3/EIP-712.mjs +1 -1
  162. package/functions/web3/etherFunctions.cjs +1 -1
  163. package/functions/web3/etherFunctions.mjs +32 -29
  164. package/functions/web3/events/balanceChangedCustomHandler.cjs +1 -1
  165. package/functions/web3/events/balanceChangedCustomHandler.mjs +4 -5
  166. package/functions/web3/events/balanceChangedHandler.cjs +1 -1
  167. package/functions/web3/events/balanceChangedHandler.mjs +2 -3
  168. package/functions/web3/events/getApprovedBalance.cjs +1 -1
  169. package/functions/web3/events/getApprovedBalance.mjs +1 -1
  170. package/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
  171. package/functions/web3/events/getInputUtxosEnclave.mjs +20 -20
  172. package/functions/web3/events/getTransactionLogEvents.cjs +1 -1
  173. package/functions/web3/events/getTransactionLogEvents.d.ts +3 -3
  174. package/functions/web3/events/getTransactionLogEvents.mjs +6 -5
  175. package/functions/web3/events/index.d.ts +0 -1
  176. package/functions/web3/fetchSolanaMerkleTreeRootHash.cjs +1 -1
  177. package/functions/web3/fetchSolanaMerkleTreeRootHash.d.ts +1 -2
  178. package/functions/web3/fetchSolanaMerkleTreeRootHash.mjs +4 -5
  179. package/functions/web3/functionCalls/accessTokenCalls.cjs +1 -1
  180. package/functions/web3/functionCalls/accessTokenCalls.mjs +10 -11
  181. package/functions/web3/functionCalls/approveToken.cjs +1 -1
  182. package/functions/web3/functionCalls/approveToken.mjs +61 -58
  183. package/functions/web3/functionCalls/constructBatchCall.cjs +1 -1
  184. package/functions/web3/functionCalls/constructBatchCall.d.ts +2 -2
  185. package/functions/web3/functionCalls/constructBatchCall.mjs +10 -9
  186. package/functions/web3/functionCalls/estimateGasRelayer.cjs +1 -1
  187. package/functions/web3/functionCalls/estimateGasRelayer.mjs +1 -1
  188. package/functions/web3/functionCalls/inHinkalApprovalCalls.cjs +1 -1
  189. package/functions/web3/functionCalls/inHinkalApprovalCalls.mjs +18 -21
  190. package/functions/web3/functionCalls/recoverTransactionFromError.d.ts +1 -1
  191. package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
  192. package/functions/web3/functionCalls/transactCallDirect.mjs +38 -34
  193. package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
  194. package/functions/web3/functionCalls/transactCallRelayer.mjs +8 -10
  195. package/functions/web3/getContractMetadata.cjs +1 -1
  196. package/functions/web3/getContractMetadata.d.ts +1 -1
  197. package/functions/web3/getContractMetadata.mjs +25 -25
  198. package/functions/web3/getPublicAddressBalance.cjs +1 -1
  199. package/functions/web3/getPublicAddressBalance.mjs +7 -6
  200. package/functions/web3/getTokenHolder.cjs +1 -1
  201. package/functions/web3/getTokenHolder.mjs +16 -15
  202. package/functions/web3/odosAPI.cjs +1 -1
  203. package/functions/web3/odosAPI.mjs +6 -7
  204. package/functions/web3/oneInchAPI.cjs +1 -1
  205. package/functions/web3/oneInchAPI.mjs +2 -3
  206. package/functions/web3/runContractFunction.cjs +1 -1
  207. package/functions/web3/runContractFunction.d.ts +6 -5
  208. package/functions/web3/runContractFunction.mjs +41 -45
  209. package/functions/web3/uniswapAPI.cjs +1 -1
  210. package/functions/web3/uniswapAPI.d.ts +2 -2
  211. package/functions/web3/uniswapAPI.mjs +23 -24
  212. package/index.cjs +1 -1
  213. package/index.mjs +336 -340
  214. package/package.json +3 -4
  215. package/providers/CustomEthersProvider.d.ts +1 -1
  216. package/providers/EthersProviderAdapter.cjs +1 -1
  217. package/providers/EthersProviderAdapter.d.ts +7 -7
  218. package/providers/EthersProviderAdapter.mjs +46 -44
  219. package/providers/SolanaProviderAdapter.d.ts +1 -1
  220. package/providers/WagmiProviderAdapter.cjs +1 -1
  221. package/providers/WagmiProviderAdapter.d.ts +5 -5
  222. package/providers/WagmiProviderAdapter.mjs +37 -33
  223. package/providers/prepareEthersHinkal.cjs +1 -1
  224. package/providers/prepareEthersHinkal.d.ts +2 -2
  225. package/providers/prepareEthersHinkal.mjs +3 -5
  226. package/providers/prepareWagmiHinkal.cjs +1 -1
  227. package/providers/prepareWagmiHinkal.mjs +3 -5
  228. package/types/activities.types.d.ts +2 -3
  229. package/types/big-intable.types.d.ts +3 -2
  230. package/types/ethereum-network.types.d.ts +10 -10
  231. package/types/transactions.types.cjs +1 -1
  232. package/types/transactions.types.d.ts +2 -3
  233. package/types/transactions.types.mjs +6 -7
  234. package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
  235. package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
  236. package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
  237. package/webworker/utxoWorker/utxoWorkerLogic.mjs +1 -1
  238. package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
  239. package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
  240. package/functions/web3/events/web3RetrieveEvents.cjs +0 -1
  241. package/functions/web3/events/web3RetrieveEvents.d.ts +0 -14
  242. package/functions/web3/events/web3RetrieveEvents.mjs +0 -9
@@ -1,17 +1,16 @@
1
- import { utils as o, ethers as d } from "ethers";
2
- import w from "libsodium-wrappers";
3
- import { CIRCOM_P as m } from "../../constants/protocol.constants.mjs";
4
- import { babyJubInstance as b } from "../../crypto/babyJub.mjs";
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 y } from "./keyUtils.mjs";
7
- import { AttachableMemoryCacheDevice as v } from "../cacheDevices/AttachableMemoryCacheDevice.mjs";
8
- import { ethers as u, hexlify as F } from "ethers-v6h";
9
- import { isSolanaLike as h, networkRegistry as p } from "../../constants/chains.constants.mjs";
10
- import { Keypair as g, VersionedTransaction as K } from "@solana/web3.js";
11
- import k from "tweetnacl";
12
- import P from "bs58";
13
- import { createCustomSolanaConnection as A } from "../../functions/utils/create-provider.mjs";
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(), o.verifyMessage(e, this.signature);
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(), d.utils.keccak256(this.signature));
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 u.Wallet(this.getShieldedPrivateKey()).address);
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(o.arrayify(this.getShieldedPrivateKey())).publicKey.toBase58());
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 o.keccak256(o.toUtf8Bytes(r));
64
+ return n.keccak256(n.toUtf8Bytes(r));
66
65
  };
67
66
  getSignerSolanaPrivateKeyFromNonce = (e) => {
68
- const r = this.getSignerPrivateKeyFromNonce(e), t = o.arrayify(r), i = g.fromSeed(t);
69
- return P.encode(i.secretKey);
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 = P.decode(e).slice(0, 32);
73
- return F(t);
71
+ const t = f.decode(e).slice(0, 32);
72
+ return n.hexlify(t);
74
73
  };
75
74
  static getSignerFromPrivateKey = (e, r) => {
76
- if (h(e)) {
77
- const i = o.arrayify(r);
75
+ if (d(e)) {
76
+ const i = n.getBytes(r);
78
77
  return g.fromSeed(i);
79
78
  }
80
- return new u.Wallet(r);
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 = o.isHexString(t) ? o.arrayify(t) : new TextEncoder().encode(t), s = k.sign.detached(a, i.secretKey);
90
- return `0x${Buffer.from(s).toString("hex")}`;
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 n = o.isHexString(t) ? o.arrayify(t) : t;
93
- return i.signMessage(n);
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 (!h(e))
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: n } = p[e];
105
- if (!n)
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 K))
107
+ if (!(t instanceof m))
109
108
  throw new Error("Invalid transaction type for Solana");
110
- return t.sign([i]), await A(n).sendRawTransaction(t.serialize());
109
+ return t.sign([i]), await b(s).sendRawTransaction(t.serialize());
111
110
  }
112
- if (t instanceof K)
111
+ if (t instanceof m)
113
112
  throw new Error("Invalid transaction type for EVM");
114
- const a = new u.JsonRpcProvider(n);
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, n) => {
118
- if (h(e))
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, n);
119
+ return await l.getSignerFromPrivateKey(e, r).signTypedData(t, i, s);
121
120
  };
122
121
  static authorizeDelegation = async (e, r, t, i) => {
123
- if (h(e))
122
+ if (d(e))
124
123
  throw new Error("Solana does not support delegation");
125
- const n = new u.JsonRpcProvider(p[e].fetchRpcUrl);
126
- return await l.getSignerFromPrivateKey(e, r).connect(n).authorize({ address: t, ...i !== void 0 && { nonce: i } });
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 = E.attach(
142
+ static getRandomizedStealthPair = F.attach(
144
143
  (e, r) => {
145
- const t = b(), i = BigInt(r) % m, n = e * i % m, a = t.mulPointEscalar(t.Base8, e), s = t.mulPointEscalar(t.Base8, n), S = [BigInt(t.F.toString(a[0])), BigInt(t.F.toString(a[1]))], f = [BigInt(t.F.toString(s[0])), BigInt(t.F.toString(s[1]))];
146
- return { H0: S, H1: f };
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), [n, a] = [t, i].map((s) => BigInt(s[1]) + 2n ** 255n * y(s[0]));
151
- return { h0: n, h1: a };
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 = R.attach((e, r) => {
154
- const { H0: t, H1: i } = this.getRandomizedStealthPair(e, r), a = [2n * y(t[0]) + y(i[0]), t[1], i[1]];
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: n, h1: a } = this.getStealthAddressCompressedPoints(e, i);
160
- return r === n && t === a;
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 = w.crypto_box_seed_keypair(d.utils.arrayify(e));
167
+ const r = P.crypto_box_seed_keypair(n.getBytes(e));
169
168
  return {
170
- privateKey: d.utils.hexlify(r.privateKey),
171
- publicKey: d.utils.hexlify(r.publicKey)
169
+ privateKey: n.hexlify(r.privateKey),
170
+ publicKey: n.hexlify(r.publicKey)
172
171
  };
173
172
  };
174
173
  }
175
174
  export {
176
- L as EncryptionKeyPairDefaultValue,
175
+ W as EncryptionKeyPairDefaultValue,
177
176
  l as UserKeys,
178
- R as stealthAddressCacheDevice,
179
- E as stealthPairCacheDevice
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,t){this.blockchainEventEmitter=e,this.eventName=t,e.addEventProcessorFunction(this.processEventsPage.bind(this))}get latestBlockNumber(){return this.blockchainEventEmitter.latestBlockNumber}intervalClear(){this.blockchainEventEmitter.intervalClear()}async processEventsPage(e){const t=new Set;e.forEach(({event:s,transactionHash:n})=>{s==="BlockedUtxosCreated"&&t.add(n)});const c=[];await v.resolveSync(e.map(s=>async()=>{if(s.event!==this.eventName)return;const{args:n,blockNumber:i,transactionHash:r}=s;if(!n)throw new Error("Wrong event structure");const a=this.mapEvent(n),l=t.has(r);await this.acceptEvent(a,i,r,l)&&c.push(a)}));const o=c.length;return await this.afterEventsAccepted(o),c.length}}exports.AbstractEventService=h;
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, e) {
6
- this.blockchainEventEmitter = t, this.eventName = e, t.addEventProcessorFunction(this.processEventsPage.bind(this));
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 e = /* @__PURE__ */ new Set();
16
- t.forEach(({ event: s, transactionHash: n }) => {
17
- s === "BlockedUtxosCreated" && e.add(n);
15
+ const s = /* @__PURE__ */ new Set();
16
+ t.forEach((e) => {
17
+ e.eventName === "BlockedUtxosCreated" && s.add(e.transactionHash);
18
18
  });
19
- const c = [];
19
+ const n = [];
20
20
  await v(
21
- t.map((s) => async () => {
22
- if (s.event !== this.eventName)
21
+ t.map((e) => async () => {
22
+ if (e.eventName !== this.eventName)
23
23
  return;
24
- const { args: n, blockNumber: i, transactionHash: a } = s;
25
- if (!n)
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(n), h = e.has(a);
28
- await this.acceptEvent(r, i, a, h) && c.push(r);
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 = c.length;
32
- return await this.afterEventsAccepted(o), c.length;
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 t=require("./AbstractSnapshotService.cjs");class i extends t.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(l){return console.error(l),!1}}mapEvent(e){const{nullifier:r}=e;return{nullifier:r.toHexString()}}getSnapshotPayload(){return{nullifiers:this._nullifiers}}populateSnapshot({payload:{nullifiers:e}}){this._nullifiers=e}}exports.AbstractNullifierSnapshotService=i;
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<BigNumber>, NullifierSnapshotPayload, NullifierSerializedSnapshot> {
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<BigNumber>): NullifierEvent<string>;
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 { AbstractSnapshotService as i } from "./AbstractSnapshotService.mjs";
2
- class n extends i {
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: e.toHexString()
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
- n as AbstractNullifierSnapshotService
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(),this.chainId=(await this.blockchainEventEmitter.contract.provider.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;
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;
@@ -1,13 +1,16 @@
1
1
  import { saveDepths as e } from "../../../constants/save-depths.mjs";
2
2
  import { AbstractEventService as a } from "./AbstractEventService.mjs";
3
- class c extends a {
3
+ import { getProviderFromContract as o } from "../../../functions/utils/getSignerFromContract.mjs";
4
+ class n extends a {
4
5
  savedLatestBlockNumber = 0;
5
6
  chainId = 0;
6
7
  constructor(t, s) {
7
8
  super(t, s);
8
9
  }
9
10
  async init() {
10
- await this.loadSnapshot(), this.chainId = (await this.blockchainEventEmitter.contract.provider.getNetwork()).chainId;
11
+ await this.loadSnapshot();
12
+ const t = o(this.blockchainEventEmitter.contract);
13
+ this.chainId = Number((await t.getNetwork()).chainId);
11
14
  }
12
15
  async retrieveEventsFromLatestBlock() {
13
16
  await this.blockchainEventEmitter.retrieveEvents(this.latestBlockNumber);
@@ -29,5 +32,5 @@ class c extends a {
29
32
  }
30
33
  }
31
34
  export {
32
- c as AbstractSnapshotService
35
+ n as AbstractSnapshotService
33
36
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../../../constants/reorg-depths.constants.cjs"),l=require("../../../functions/utils/resolve-sync.utils.cjs"),m=require("../../../functions/utils/mutexes.utils.cjs");class y{contract;depositOnChainUtxosContract;_latestBlockNumber;_initialBlockNumber;onEventsProcessed;eventProcessors=new Set;maxPageSize;isReady=!1;isServer;intervalId;inProgress;eventsFetchingMutex;constructor(e,r,h,s,i,a=m.balanceFetchingMutex){this.contract=e,this.depositOnChainUtxosContract=i,this._initialBlockNumber=r,this.maxPageSize=s,this.isServer=h,this.inProgress=!1,this.eventsFetchingMutex=a}get latestBlockNumber(){return this._latestBlockNumber??this._initialBlockNumber}syncFromAtMost(e){(this._latestBlockNumber===void 0||e<this._latestBlockNumber)&&(this._latestBlockNumber=e)}intervalClear(){this.isReady=!1,this.eventProcessors=new Set,clearInterval(this.intervalId)}async init(){if(this.isReady)throw new Error("Already initialized");this.isReady=!0,await this.retrieveEvents(this.latestBlockNumber+1),this.intervalId=setInterval(async()=>{await this.retrieveEvents(this.latestBlockNumber)},3500)}requireReady(){if(!this.isReady)throw new Error("Not ready")}addEventProcessorFunction(e){if(this.isReady)throw new Error("Can't add event processor after event emitter initialized");this.eventProcessors.add(e)}async getLastBlockNumberForEventRequest(){const e=await this.contract.provider.getBlockNumber();if(!this.isServer)return e;const{chainId:r}=await this.contract.provider.getNetwork();return Math.max(this.latestBlockNumber,e-d.blockReorgDepth[r]+1)}async retrieveEvents(e,r=!1){return this.requireReady(),await this.eventsFetchingMutex.runExclusive(async()=>{try{if(this.inProgress&&!r)return!1;this.inProgress=!0;let s=0;const i=await this.getLastBlockNumberForEventRequest();if(i<e)return this.inProgress=!1,!1;const a=l.getSequence(e,i,this.maxPageSize),o=[];if(await l.resolveSync(a.map(({from:t,to:n})=>async()=>{const c=await this.contract.queryFilter("*",t,n);o.push(...c)})),this.depositOnChainUtxosContract){const{depositOnChainUtxosContract:t}=this;await l.resolveSync(a.map(({from:n,to:c})=>async()=>{const v=await t.queryFilter("*",n,c);o.push(...v)}))}const u=await Promise.all([...this.eventProcessors].map(t=>t(o)));return this._latestBlockNumber=i,s+=u.reduce((t,n)=>t+n,0),this.onEventsProcessed?.(s),this.inProgress=!1,!0}catch(s){return console.log("retrieveEvents error:",{err:s}),this.inProgress=!1,!1}})}}exports.BlockchainEventEmitter=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("ethers"),y=require("../../../constants/reorg-depths.constants.cjs"),h=require("../../../functions/utils/resolve-sync.utils.cjs"),f=require("../../../functions/utils/mutexes.utils.cjs"),d=require("../../../functions/utils/getSignerFromContract.cjs");class E{contract;depositOnChainUtxosContract;_latestBlockNumber;_initialBlockNumber;onEventsProcessed;eventProcessors=new Set;maxPageSize;isReady=!1;isServer;intervalId;inProgress;eventsFetchingMutex;constructor(e,r,u,s,i,a=f.balanceFetchingMutex){this.contract=e,this.depositOnChainUtxosContract=i,this._initialBlockNumber=r,this.maxPageSize=s,this.isServer=u,this.inProgress=!1,this.eventsFetchingMutex=a}get latestBlockNumber(){return this._latestBlockNumber??this._initialBlockNumber}syncFromAtMost(e){(this._latestBlockNumber===void 0||e<this._latestBlockNumber)&&(this._latestBlockNumber=e)}intervalClear(){this.isReady=!1,this.eventProcessors=new Set,clearInterval(this.intervalId)}async init(){if(this.isReady)throw new Error("Already initialized");this.isReady=!0,await this.retrieveEvents(this.latestBlockNumber+1),this.intervalId=setInterval(async()=>{await this.retrieveEvents(this.latestBlockNumber)},3500)}requireReady(){if(!this.isReady)throw new Error("Not ready")}addEventProcessorFunction(e){if(this.isReady)throw new Error("Can't add event processor after event emitter initialized");this.eventProcessors.add(e)}async getLastBlockNumberForEventRequest(){const e=await d.getProviderFromContract(this.contract).getBlockNumber();if(!this.isServer)return e;const{chainId:r}=await d.getProviderFromContract(this.contract).getNetwork();return Math.max(this.latestBlockNumber,e-y.blockReorgDepth[Number(r)]+1)}async retrieveEvents(e,r=!1){return this.requireReady(),await this.eventsFetchingMutex.runExclusive(async()=>{try{if(this.inProgress&&!r)return!1;this.inProgress=!0;let s=0;const i=await this.getLastBlockNumberForEventRequest();if(i<e)return this.inProgress=!1,!1;const a=h.getSequence(e,i,this.maxPageSize),o=[];if(await h.resolveSync(a.map(({from:t,to:n})=>async()=>{const c=(await this.contract.queryFilter("*",t,n)).filter(l=>l instanceof v.ethers.EventLog);o.push(...c)})),this.depositOnChainUtxosContract){const{depositOnChainUtxosContract:t}=this;await h.resolveSync(a.map(({from:n,to:c})=>async()=>{const l=(await t.queryFilter("*",n,c)).filter(g=>g instanceof v.ethers.EventLog);o.push(...l)}))}const m=await Promise.all([...this.eventProcessors].map(t=>t(o)));return this._latestBlockNumber=i,s+=m.reduce((t,n)=>t+n,0),this.onEventsProcessed?.(s),this.inProgress=!1,!0}catch(s){return console.log("retrieveEvents error:",{err:s}),this.inProgress=!1,!1}})}}exports.BlockchainEventEmitter=E;
@@ -1,6 +1,6 @@
1
1
  import { ethers } from 'ethers';
2
2
  import { Mutex } from 'async-mutex';
3
- export type EventProcessorFunction = (events: ethers.Event[]) => Promise<number> | number;
3
+ export type EventProcessorFunction = (events: ethers.EventLog[]) => Promise<number> | number;
4
4
  export declare class BlockchainEventEmitter {
5
5
  readonly contract: ethers.Contract;
6
6
  readonly depositOnChainUtxosContract?: ethers.Contract;
@@ -1,7 +1,9 @@
1
- import { blockReorgDepth as d } from "../../../constants/reorg-depths.constants.mjs";
2
- import { getSequence as m, resolveSync as h } from "../../../functions/utils/resolve-sync.utils.mjs";
3
- import { balanceFetchingMutex as y } from "../../../functions/utils/mutexes.utils.mjs";
4
- class w {
1
+ import { ethers as u } from "ethers";
2
+ import { blockReorgDepth as g } from "../../../constants/reorg-depths.constants.mjs";
3
+ import { getSequence as y, resolveSync as v } from "../../../functions/utils/resolve-sync.utils.mjs";
4
+ import { balanceFetchingMutex as E } from "../../../functions/utils/mutexes.utils.mjs";
5
+ import { getProviderFromContract as m } from "../../../functions/utils/getSignerFromContract.mjs";
6
+ class b {
5
7
  contract;
6
8
  depositOnChainUtxosContract;
7
9
  _latestBlockNumber;
@@ -15,8 +17,8 @@ class w {
15
17
  inProgress;
16
18
  // to remove race conditions
17
19
  eventsFetchingMutex;
18
- constructor(t, r, l, s, i, n = y) {
19
- this.contract = t, this.depositOnChainUtxosContract = i, this._initialBlockNumber = r, this.maxPageSize = s, this.isServer = l, this.inProgress = !1, this.eventsFetchingMutex = n;
20
+ constructor(t, r, h, s, i, n = E) {
21
+ this.contract = t, this.depositOnChainUtxosContract = i, this._initialBlockNumber = r, this.maxPageSize = s, this.isServer = h, this.inProgress = !1, this.eventsFetchingMutex = n;
20
22
  }
21
23
  get latestBlockNumber() {
22
24
  return this._latestBlockNumber ?? this._initialBlockNumber;
@@ -44,11 +46,11 @@ class w {
44
46
  this.eventProcessors.add(t);
45
47
  }
46
48
  async getLastBlockNumberForEventRequest() {
47
- const t = await this.contract.provider.getBlockNumber();
49
+ const t = await m(this.contract).getBlockNumber();
48
50
  if (!this.isServer)
49
51
  return t;
50
- const { chainId: r } = await this.contract.provider.getNetwork();
51
- return Math.max(this.latestBlockNumber, t - d[r] + 1);
52
+ const { chainId: r } = await m(this.contract).getNetwork();
53
+ return Math.max(this.latestBlockNumber, t - g[Number(r)] + 1);
52
54
  }
53
55
  async retrieveEvents(t, r = !1) {
54
56
  return this.requireReady(), await this.eventsFetchingMutex.runExclusive(async () => {
@@ -60,25 +62,27 @@ class w {
60
62
  const i = await this.getLastBlockNumberForEventRequest();
61
63
  if (i < t)
62
64
  return this.inProgress = !1, !1;
63
- const n = m(t, i, this.maxPageSize), o = [];
64
- if (await h(
65
+ const n = y(t, i, this.maxPageSize), o = [];
66
+ if (await v(
65
67
  n.map(({ from: e, to: a }) => async () => {
66
- const c = await this.contract.queryFilter("*", e, a);
68
+ const c = (await this.contract.queryFilter("*", e, a)).filter(
69
+ (l) => l instanceof u.EventLog
70
+ );
67
71
  o.push(...c);
68
72
  })
69
73
  ), this.depositOnChainUtxosContract) {
70
74
  const { depositOnChainUtxosContract: e } = this;
71
- await h(
75
+ await v(
72
76
  n.map(({ from: a, to: c }) => async () => {
73
- const v = await e.queryFilter("*", a, c);
74
- o.push(...v);
77
+ const l = (await e.queryFilter("*", a, c)).filter((f) => f instanceof u.EventLog);
78
+ o.push(...l);
75
79
  })
76
80
  );
77
81
  }
78
- const u = await Promise.all(
82
+ const d = await Promise.all(
79
83
  [...this.eventProcessors].map((e) => e(o))
80
84
  );
81
- return this._latestBlockNumber = i, s += u.reduce((e, a) => e + a, 0), this.onEventsProcessed?.(s), this.inProgress = !1, !0;
85
+ return this._latestBlockNumber = i, s += d.reduce((e, a) => e + a, 0), this.onEventsProcessed?.(s), this.inProgress = !1, !0;
82
86
  } catch (s) {
83
87
  return console.log("retrieveEvents error:", { err: s }), this.inProgress = !1, !1;
84
88
  }
@@ -86,5 +90,5 @@ class w {
86
90
  }
87
91
  }
88
92
  export {
89
- w as BlockchainEventEmitter
93
+ b as BlockchainEventEmitter
90
94
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("ethers"),i=require("../../../functions/utils/amounts.utils.cjs"),n=require("./AbstractSolanaSnapshotService.cjs");class s extends n.AbstractSolanaSnapshotService{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(l){return console.error(l),!1}}mapEvent(e){return{nullifier:t.BigNumber.from(i.advancedToBigInt(e.nullifier)).toHexString()}}getSnapshotPayload(){return{nullifiers:this._nullifiers}}populateSnapshot({payload:{nullifiers:e}}){this._nullifiers=e}}exports.AbstractSolanaNullifierSnapshotService=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("ethers"),i=require("../../../functions/utils/amounts.utils.cjs"),s=require("./AbstractSolanaSnapshotService.cjs");class n extends s.AbstractSolanaSnapshotService{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(l){return console.error(l),!1}}mapEvent(e){return{nullifier:t.ethers.toBeHex(i.advancedToBigInt(e.nullifier))}}getSnapshotPayload(){return{nullifiers:this._nullifiers}}populateSnapshot({payload:{nullifiers:e}}){this._nullifiers=e}}exports.AbstractSolanaNullifierSnapshotService=n;
@@ -1,4 +1,4 @@
1
- import { BigNumber as i } from "ethers";
1
+ import { ethers as i } from "ethers";
2
2
  import { advancedToBigInt as t } from "../../../functions/utils/amounts.utils.mjs";
3
3
  import { AbstractSolanaSnapshotService as n } from "./AbstractSolanaSnapshotService.mjs";
4
4
  class f extends n {
@@ -32,7 +32,7 @@ class f extends n {
32
32
  }
33
33
  mapEvent(r) {
34
34
  return {
35
- nullifier: i.from(t(r.nullifier)).toHexString()
35
+ nullifier: i.toBeHex(t(r.nullifier))
36
36
  };
37
37
  }
38
38
  getSnapshotPayload() {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../constants/presale.constants.cjs"),s=require("ethers");class o{contract;eventsFrom;constructor(t,e){const{address:r,eventsFrom:a}=n.presaleContractInfoByChain[e];this.contract=new s.ethers.Contract(r,n.presaleABI,t),this.eventsFrom=a}deposit(t,e,r){return this.contract.deposit(t.erc20TokenAddress,e,r)}withdraw(t,e){return this.contract.withdraw(t,e)}moveToNextStage(t){return this.contract.moveToNextStage(t||{})}async estimateMoveToNextStageGas(){return(await this.contract.estimateGas.moveToNextStage()).toBigInt()}async getTotalDeposit(){return(await this.contract.totalDeposit()).toBigInt()}async getDeposits(t,e){return(await this.contract.deposits(t,e.erc20TokenAddress)).toBigInt()}async getTotalHINK(t){return(await this.contract.totalHINK(t)).toBigInt()}async getCurrentPresaleStageIndex(){const t=await this.contract.currentPresaleStageIndex();return Number(t)}async getCurrentMaxDepositAmount(){return(await this.contract.currentMaxDepositAmount()).toBigInt()}async currentPresaleStage(){const[t,e]=await this.contract.currentPresaleStage(),[r,a]=[t,e].map(BigInt);return{amountToRaise:r,priceMultiplier:a}}async calculateHINK(t){return(await this.contract.calculateHINK(t)).toBigInt()}async queryDeposits(){return this.contract.queryFilter(this.contract.filters.Deposit(),this.eventsFrom)}onEvent(t,e){this.contract.on(t,e)}}exports.PresaleContractWrapper=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../constants/presale.constants.cjs"),n=require("ethers");class o{contract;eventsFrom;constructor(t,e){const{address:r,eventsFrom:a}=s.presaleContractInfoByChain[e];this.contract=new n.ethers.Contract(r,s.presaleABI,t),this.eventsFrom=a}deposit(t,e,r){return this.contract.deposit(t.erc20TokenAddress,e,r)}withdraw(t,e){return this.contract.withdraw(t,e)}moveToNextStage(t){return this.contract.moveToNextStage(t||{})}async estimateMoveToNextStageGas(){return this.contract.moveToNextStage.estimateGas()}async getTotalDeposit(){return await this.contract.totalDeposit()}async getDeposits(t,e){return await this.contract.deposits(t,e.erc20TokenAddress)}async getTotalHINK(t){return await this.contract.totalHINK(t)}async getCurrentPresaleStageIndex(){const t=await this.contract.currentPresaleStageIndex();return Number(t)}async getCurrentMaxDepositAmount(){return await this.contract.currentMaxDepositAmount()}async currentPresaleStage(){const[t,e]=await this.contract.currentPresaleStage(),[r,a]=[t,e].map(BigInt);return{amountToRaise:r,priceMultiplier:a}}async calculateHINK(t){return await this.contract.calculateHINK(t)}async queryDeposits(){return this.contract.queryFilter(this.contract.filters.Deposit(),this.eventsFrom)}onEvent(t,e){this.contract.on(t,e)}}exports.PresaleContractWrapper=o;
@@ -3,7 +3,7 @@ import { ethers } from 'ethers';
3
3
  export declare class PresaleContractWrapper {
4
4
  contract: ethers.Contract;
5
5
  eventsFrom: number;
6
- constructor(signerOrProvider: ethers.Signer | ethers.providers.Provider, chainId: number);
6
+ constructor(signerOrProvider: ethers.Signer | ethers.Provider, chainId: number);
7
7
  deposit(token: ERC20Token, amount: bigint, minHINK: bigint): Promise<ethers.ContractTransaction>;
8
8
  withdraw(token: string, amount: bigint): Promise<ethers.ContractTransaction>;
9
9
  moveToNextStage(overrides?: ethers.Overrides): Promise<ethers.ContractTransaction>;
@@ -18,6 +18,6 @@ export declare class PresaleContractWrapper {
18
18
  priceMultiplier: bigint;
19
19
  }>;
20
20
  calculateHINK(amount: bigint): Promise<bigint>;
21
- queryDeposits(): Promise<ethers.Event[]>;
22
- onEvent(eventName: string, handleEvent: ethers.providers.Listener): void;
21
+ queryDeposits(): Promise<(ethers.Log | ethers.EventLog)[]>;
22
+ onEvent(eventName: string, handleEvent: ethers.Listener): void;
23
23
  }
@@ -1,11 +1,11 @@
1
- import { presaleContractInfoByChain as n, presaleABI as o } from "../../constants/presale.constants.mjs";
2
- import { ethers as s } from "ethers";
1
+ import { presaleContractInfoByChain as s, presaleABI as n } from "../../constants/presale.constants.mjs";
2
+ import { ethers as o } from "ethers";
3
3
  class l {
4
4
  contract;
5
5
  eventsFrom;
6
6
  constructor(t, e) {
7
- const { address: r, eventsFrom: a } = n[e];
8
- this.contract = new s.Contract(r, o, t), this.eventsFrom = a;
7
+ const { address: r, eventsFrom: a } = s[e];
8
+ this.contract = new o.Contract(r, n, t), this.eventsFrom = a;
9
9
  }
10
10
  deposit(t, e, r) {
11
11
  return this.contract.deposit(t.erc20TokenAddress, e, r);
@@ -17,30 +17,30 @@ class l {
17
17
  return this.contract.moveToNextStage(t || {});
18
18
  }
19
19
  async estimateMoveToNextStageGas() {
20
- return (await this.contract.estimateGas.moveToNextStage()).toBigInt();
20
+ return this.contract.moveToNextStage.estimateGas();
21
21
  }
22
22
  async getTotalDeposit() {
23
- return (await this.contract.totalDeposit()).toBigInt();
23
+ return await this.contract.totalDeposit();
24
24
  }
25
25
  async getDeposits(t, e) {
26
- return (await this.contract.deposits(t, e.erc20TokenAddress)).toBigInt();
26
+ return await this.contract.deposits(t, e.erc20TokenAddress);
27
27
  }
28
28
  async getTotalHINK(t) {
29
- return (await this.contract.totalHINK(t)).toBigInt();
29
+ return await this.contract.totalHINK(t);
30
30
  }
31
31
  async getCurrentPresaleStageIndex() {
32
32
  const t = await this.contract.currentPresaleStageIndex();
33
33
  return Number(t);
34
34
  }
35
35
  async getCurrentMaxDepositAmount() {
36
- return (await this.contract.currentMaxDepositAmount()).toBigInt();
36
+ return await this.contract.currentMaxDepositAmount();
37
37
  }
38
38
  async currentPresaleStage() {
39
39
  const [t, e] = await this.contract.currentPresaleStage(), [r, a] = [t, e].map(BigInt);
40
40
  return { amountToRaise: r, priceMultiplier: a };
41
41
  }
42
42
  async calculateHINK(t) {
43
- return (await this.contract.calculateHINK(t)).toBigInt();
43
+ return await this.contract.calculateHINK(t);
44
44
  }
45
45
  async queryDeposits() {
46
46
  return this.contract.queryFilter(this.contract.filters.Deposit(), this.eventsFrom);
@@ -1,5 +1,5 @@
1
1
  import { ContractMetadata, ContractType, EthereumNetwork } from '../../types/ethereum-network.types';
2
- import { Contract, ethers, Signer } from 'ethers';
2
+ import { ethers } from 'ethers';
3
3
  import { Call } from '../../types/eip5792.types';
4
4
  export interface ChainEventListener {
5
5
  onAccountChanged(): void;
@@ -8,7 +8,7 @@ export interface ChainEventListener {
8
8
  export interface IProviderAdapter<ConnectorType = unknown> {
9
9
  chainId: number | undefined;
10
10
  initConnector(connector: ConnectorType): void;
11
- initSigner?(signer: Signer): void;
11
+ initSigner?(signer: ethers.Signer): void;
12
12
  init(chainId?: number): Promise<void>;
13
13
  initConfig?(config?: any): Promise<void> | void;
14
14
  connectToConnector(connector: ConnectorType): Promise<number>;
@@ -22,10 +22,10 @@ export interface IProviderAdapter<ConnectorType = unknown> {
22
22
  release(): void;
23
23
  getContractMetadata(contractType: ContractType, chainId?: number): ContractMetadata;
24
24
  getContract(contractType: ContractType, contractAddress?: string, chainId?: number): ethers.Contract;
25
- getContractWithSigner(contract: ContractType, contractAddress?: string): Contract;
26
- getContractWithFetcher(contract: ContractType, contractAddress?: string): Contract;
27
- getContractWithFetcherForEthereum(contract: ContractType, contractAddress?: string): Contract;
28
- sendTransaction(tx: ethers.providers.TransactionRequest): Promise<ethers.providers.TransactionResponse>;
25
+ getContractWithSigner(contract: ContractType, contractAddress?: string): ethers.Contract;
26
+ getContractWithFetcher(contract: ContractType, contractAddress?: string): ethers.Contract;
27
+ getContractWithFetcherForEthereum(contract: ContractType, contractAddress?: string): ethers.Contract;
28
+ sendTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionResponse>;
29
29
  switchNetwork(network: EthereumNetwork): Promise<unknown>;
30
30
  switchAccount(signer: ethers.Signer): Promise<void>;
31
31
  onAccountChanged(): Promise<unknown>;
@@ -33,6 +33,6 @@ export interface IProviderAdapter<ConnectorType = unknown> {
33
33
  isPermitterAvailable(): boolean;
34
34
  getGasPrice(): Promise<bigint>;
35
35
  signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, unknown>): Promise<string>;
36
- sendBatchCallsTransaction?(calls: Call[]): Promise<ethers.providers.TransactionResponse>;
36
+ sendBatchCallsTransaction?(calls: Call[]): Promise<ethers.TransactionResponse>;
37
37
  supportsBatchCall?(): Promise<boolean>;
38
38
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../event-service/evm/AbstractAccessTokenSnapshotService.cjs");require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../../constants/vite.constants.cjs");require("../../../error-handling/error-codes.constants.cjs");require("../../../constants/save-depths.cjs");require("../../../constants/reorg-depths.constants.cjs");require("../../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("../../../constants/chains.constants.cjs");require("@solana/web3.js");require("../../crypto-keys/keys.cjs");const c=require("../SnapshotFetcherService.cjs");class i extends t.AbstractAccessTokenSnapshotService{snapshotsService;constructor(e,s){super(e),this.snapshotsService=s}async fetchSnapshot(){const{contract:e}=this.blockchainEventEmitter,{chainId:s}=await e.provider.getNetwork();this.snapshotsService||(this.snapshotsService=new c.SnapshotFetcherService(s,e.address));const r=await this.snapshotsService.getAccessTokens();if(r.accessTokenContractAddress!==e.address||r.chainId!==s)throw Error("Commitment Snapshot: incorrect contract or chain id");return{latestBlockNumber:r.latestBlockNumber,merkleTree:r.merkleTree,senderAddresses:r.senderAddresses,senderAddressIndexMap:r.senderAddressIndexMap}}persistSnapshot(e){return Promise.resolve()}}exports.ClientAccessTokenSnapshotService=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../event-service/evm/AbstractAccessTokenSnapshotService.cjs");require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../../constants/vite.constants.cjs");require("../../../error-handling/error-codes.constants.cjs");require("../../../constants/save-depths.cjs");const i=require("../../../functions/utils/getSignerFromContract.cjs");require("../../../constants/reorg-depths.constants.cjs");require("../../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("../../../constants/chains.constants.cjs");require("@solana/web3.js");require("../../crypto-keys/keys.cjs");const o=require("../SnapshotFetcherService.cjs"),n=require("../../../functions/utils/getContractAddress.cjs");class a extends c.AbstractAccessTokenSnapshotService{snapshotsService;constructor(e,s){super(e),this.snapshotsService=s}async fetchSnapshot(){const{contract:e}=this.blockchainEventEmitter,{chainId:s}=await i.getProviderFromContract(e).getNetwork(),t=Number(s);this.snapshotsService||(this.snapshotsService=new o.SnapshotFetcherService(t,n.getContractAddress(e)));const r=await this.snapshotsService.getAccessTokens();if(r.accessTokenContractAddress!==n.getContractAddress(e)||r.chainId!==t)throw Error("Commitment Snapshot: incorrect contract or chain id");return{latestBlockNumber:r.latestBlockNumber,merkleTree:r.merkleTree,senderAddresses:r.senderAddresses,senderAddressIndexMap:r.senderAddressIndexMap}}persistSnapshot(e){return Promise.resolve()}}exports.ClientAccessTokenSnapshotService=a;