@kapa123456789/sdk 0.0.82 → 0.0.84

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 (60) hide show
  1. package/common/src/constants/chains.constants.cjs +1 -1
  2. package/common/src/constants/chains.constants.mjs +1 -1
  3. package/common/src/crypto/babyJub.cjs +1 -1
  4. package/common/src/crypto/babyJub.mjs +1 -1
  5. package/common/src/crypto/eddsa.cjs +1 -1
  6. package/common/src/crypto/eddsa.mjs +1 -1
  7. package/common/src/crypto/poseidon.cjs +1 -1
  8. package/common/src/crypto/poseidon.mjs +1 -1
  9. package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
  10. package/common/src/data-structures/Hinkal/Hinkal.mjs +4 -41
  11. package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
  12. package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +46 -73
  13. package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
  14. package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +16 -37
  15. package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
  16. package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +18 -47
  17. package/common/src/data-structures/crypto-keys/keys.cjs +1 -1
  18. package/common/src/data-structures/crypto-keys/keys.mjs +8 -2
  19. package/common/src/data-structures/token-price-fetcher/TokenChecker.cjs +1 -1
  20. package/common/src/data-structures/token-price-fetcher/TokenChecker.mjs +5 -5
  21. package/common/src/functions/pre-transaction/getFeeStructure.cjs +1 -1
  22. package/common/src/functions/pre-transaction/getFeeStructure.mjs +10 -21
  23. package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
  24. package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +71 -89
  25. package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -1
  26. package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +8 -17
  27. package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
  28. package/common/src/functions/snarkjs/generateZkProof.mjs +8 -26
  29. package/common/src/functions/utils/evmNetworkFunctions.cjs +1 -1
  30. package/common/src/functions/utils/evmNetworkFunctions.d.ts +1 -0
  31. package/common/src/functions/utils/evmNetworkFunctions.mjs +4 -0
  32. package/common/src/functions/utils/process.utils.cjs +1 -1
  33. package/common/src/functions/utils/process.utils.mjs +6 -10
  34. package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
  35. package/common/src/functions/web3/functionCalls/transactCallDirect.mjs +43 -61
  36. package/common/src/functions/web3/functionCalls/transactCallDirectTron.cjs +1 -1
  37. package/common/src/functions/web3/functionCalls/transactCallDirectTron.mjs +65 -73
  38. package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
  39. package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +14 -22
  40. package/common/src/types/scheduled-transactions.types.d.ts +1 -0
  41. package/common/src/webworker/logError-F50ubgnd.js +2 -0
  42. package/common/src/webworker/package.json +1 -1
  43. package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
  44. package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
  45. package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
  46. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
  47. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
  48. package/common/src/webworker/utxoWorkerNode.cjs +1 -1
  49. package/common/src/webworker/viteWorkerURL.constant.cjs +3 -3
  50. package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
  51. package/common/src/webworker/{workerProxy-D22p2w2G.js → workerProxy-BP_AUL0j.js} +1 -1
  52. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
  53. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
  54. package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
  55. package/functions/integrations/swapApi.cjs +1 -1
  56. package/functions/integrations/swapApi.mjs +4 -9
  57. package/package.json +1 -1
  58. package/services/Hinkal.cjs +1 -1
  59. package/services/Hinkal.mjs +3 -42
  60. package/common/src/webworker/logError-o9XP6THu.js +0 -2
@@ -10,27 +10,22 @@ var o = async (t, r, i, a, o) => {
10
10
  let s = t.hinkalCommon, [c, l] = await e(r, [a, o]);
11
11
  return n(s, r, i, c, l);
12
12
  }, s = async (n, a, s, c, l) => {
13
- console.log("getEvmSwapPrices", a, s, c, l);
14
- let [u, d] = await e(a, [c, l]);
15
- console.log("getEvmSwapPrices", u, d);
16
- let [f, p, m] = await Promise.allSettled([
13
+ let [u, d] = await e(a, [c, l]), [f, p, m] = await Promise.allSettled([
17
14
  t(o(n, a, s, c, l)),
18
15
  t(r(a, u, d, s)),
19
16
  t(i(a, u, d, s))
20
17
  ]);
21
- return console.log("getEvmSwapPrices", f, p, m), {
18
+ return {
22
19
  uniswap: f.status === "fulfilled" ? f.value : null,
23
20
  odos: p.status === "fulfilled" ? p.value : null,
24
21
  oneInch: m.status === "fulfilled" ? m.value : null
25
22
  };
26
23
  }, c = async (n, r, i, o) => {
27
- console.log("getSolanaSwapPrices", n, r, i, o);
28
24
  let [s, c] = await e(n, [i, o]);
29
- console.log("getSolanaSwapPrices", s, c);
30
25
  try {
31
26
  return { okx: await t(a(n, s, c, r)) };
32
- } catch (e) {
33
- return console.log("getSolanaSwapPrices error", e), { okx: null };
27
+ } catch {
28
+ return { okx: null };
34
29
  }
35
30
  };
36
31
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapa123456789/sdk",
3
- "version": "0.0.82",
3
+ "version": "0.0.84",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"
@@ -1 +1 @@
1
- const e=require(`../common/src/constants/chains.constants.cjs`),t=require(`../common/src/types/hinkal.types.cjs`);require(`../common/src/types/index.cjs`);const n=require(`../common/src/functions/utils/erc20tokenFunctions.cjs`);require(`../common/src/functions/index.cjs`);const r=require(`../common/src/data-structures/Hinkal/Hinkal.cjs`),i=require(`../internal/token.utils.cjs`);var a=class{hinkalCommon;mappedPrivateBalancesSource;mappedPrivateBalances={};constructor(e){this.hinkalCommon=new r.Hinkal(e)}getProviderAdapter(e){return this.hinkalCommon.getProviderAdapter(e)}initProviderAdapter(e,t){return this.hinkalCommon.initProviderAdapter(e,t)}initUserKeys(e=t.LoginMessageMode.PROTOCOL){return this.hinkalCommon.initUserKeys(e)}initUserKeysWithSignature(e){return this.hinkalCommon.initUserKeysWithSignature(e)}initUserKeysFromSeedPhrases(e){return this.hinkalCommon.initUserKeysFromSeedPhrases(e)}storeAndGetInitialSignature(e,t=!1,n){return this.hinkalCommon.storeAndGetInitialSignature(e,t,n)}resetProviderAdapters(){return this.hinkalCommon.resetProviderAdapters()}disconnectFromConnector(){return this.hinkalCommon.disconnectFromConnector()}destroy(){return this.hinkalCommon.destroy()}signMessage(e){return this.hinkalCommon.signMessage(e)}signTypedData(e,t,n){return this.hinkalCommon.signTypedData(e,t,n)}getSupportedChains(){return this.hinkalCommon.getSupportedChains()}isSelectedNetworkSupported(e){return this.hinkalCommon.isSelectedNetworkSupported(e)}switchNetwork(t){let n=e.networkRegistry[t];if(!n)throw Error(`Network with chainId ${t} not supported`);return this.hinkalCommon.switchNetwork(n)}resetMerkle(e){return this.hinkalCommon.resetMerkle(e)}resetMerkleTreesIfNecessary(e){return this.hinkalCommon.resetMerkleTreesIfNecessary(e)}getMappedPrivateBalances(e){return e===this.mappedPrivateBalancesSource?this.mappedPrivateBalances:(this.mappedPrivateBalancesSource=e,this.mappedPrivateBalances=i.mapPrivateBalances(e),this.mappedPrivateBalances)}get privateBalancesWithUSD(){return this.getMappedPrivateBalances(this.hinkalCommon.privateBalancesWithUSD)}onPrivateBalancesWithUSDChange(e){return this.hinkalCommon.onPrivateBalancesWithUSDChange(t=>e(this.getMappedPrivateBalances(t)))}async getTotalBalance(e,t=!1,n=!1){return(await this.hinkalCommon.getTotalBalance(e,void 0,void 0,t,n)).map(i.mapTokenBalance)}async getStuckShieldedBalances(e,t=!1,n=!1){return(await this.hinkalCommon.getStuckShieldedBalances(e,void 0,void 0,t,n)).map(i.mapTokenBalance)}monitorConnectedAddress(e){return this.hinkalCommon.monitorConnectedAddress(e)}waitForTransaction(e,t,n){return this.hinkalCommon.waitForTransaction(e,t,n)}getSolanaPublicKey(){return this.hinkalCommon.getSolanaPublicKey()}getEthereumAddress(){return this.hinkalCommon.getEthereumAddress()}getEthereumAddressByChain(e){return this.hinkalCommon.getEthereumAddressByChain(e)}getRecipientInfo(){return this.hinkalCommon.getRecipientInfo()}getShieldedPublicKey(){return this.hinkalCommon.userKeys.getShieldedPublicKey()}async prooflessDeposit(e,t,r,i){return this.hinkalCommon.prooflessDeposit(await n.resolveErc20Tokens(e,t),r,i)}async prooflessDepositWithPublicFee(e,t,r,i,a){return this.hinkalCommon.prooflessDepositWithPublicFee(await n.resolveErc20Token(e,t),r,i,a)}async deposit(e,t,r,i,a){console.log(`[hinkal.deposit] start`,{chainId:e,erc20Addresses:t,amountChanges:r.map(String)});try{let o=await n.resolveErc20Tokens(e,t);console.log(`[hinkal.deposit] resolved tokens`);let s=await this.hinkalCommon.deposit(o,r,i,a);return console.log(`[hinkal.deposit] success`,{result:s}),s}catch(e){throw console.log(`[hinkal.deposit] error`,e),e}}async depositSolana(e,t,r){return this.hinkalCommon.depositSolana(r,await n.resolveErc20Token(e,t))}async depositForOther(e,t,r,i,a,o){return this.hinkalCommon.depositForOther(await n.resolveErc20Tokens(e,t),r,i,a,o)}async depositSolanaForOther(e,t,r,i){return this.hinkalCommon.depositSolanaForOther(r,await n.resolveErc20Token(e,t),i)}async depositAndWithdraw(e,t,r,i,a,o,s){return this.hinkalCommon.depositAndWithdraw(await n.resolveErc20Token(e,t),r,i,a,o,void 0,void 0,void 0,s)}async depositAndBridge(e,t,r,i,a,o){return this.hinkalCommon.depositAndBridge(await n.resolveErc20Token(e,t),r,i,a,void 0,void 0,void 0,o)}async checkSendTransactionStatus(e){return this.hinkalCommon.checkSendTransactionStatus(e)}async nearDepositAndBridge(e,t,r,i,a,o,s){return this.hinkalCommon.nearDepositAndBridge(await n.resolveErc20Token(e,t),r,i,a,o,s)}async claimUtxo(e,t,r,i,a){return this.hinkalCommon.claimUtxo(await n.resolveErc20Token(e,t),r,i,a)}async transfer(e,t,r,i,a,o){console.log(`[hinkal.transfer] start`,{chainId:e,erc20Addresses:t,amountChanges:r.map(String),recipientAddress:i});try{let s=await n.resolveErc20Tokens(e,t);console.log(`[hinkal.transfer] resolved tokens`);let c=await this.hinkalCommon.transfer(s,r,i,a,o);return console.log(`[hinkal.transfer] success`,{result:c}),c}catch(e){throw console.log(`[hinkal.transfer] error`,e),e}}async withdraw(e,t,r,i,a,o,s){console.log(`[hinkal.withdraw] start`,{chainId:e,erc20Addresses:t,deltaAmounts:r.map(String),recipientAddress:i,isRelayerOff:a});try{let c=await n.resolveErc20Tokens(e,t);console.log(`[hinkal.withdraw] resolved tokens`);let l=await this.hinkalCommon.withdraw(c,r,i,a,o,s);return console.log(`[hinkal.withdraw] success`,{result:l}),l}catch(e){throw console.log(`[hinkal.withdraw] error`,e),e}}async withdrawStuckUtxos(e,t,r){return this.hinkalCommon.withdrawStuckUtxos(await n.resolveErc20Token(e,t),r)}async swap(e,t,r,i,a,o,s){return this.hinkalCommon.swap(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}async actionPrivateWallet(e,t,r,a,o,s,c,l,u){return this.hinkalCommon.actionPrivateWallet(e,await n.resolveErc20Tokens(e,t),r,a,o,await i.resolveCommonTokenChanges(e,s),c,l,u)}async proxySwap(e,t,r,i,a,o,s,c,l){return this.hinkalCommon.proxySwap(await n.resolveErc20Tokens(e,t),r,i,a,o,s,c,l)}async proxyToPrivate(e,t,r,i,a,o,s){return this.hinkalCommon.proxyToPrivate(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}async proxySend(e,t,r,i,a,o,s){return this.hinkalCommon.proxySend(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}};exports.Hinkal=a;
1
+ const e=require(`../common/src/constants/chains.constants.cjs`),t=require(`../common/src/types/hinkal.types.cjs`);require(`../common/src/types/index.cjs`);const n=require(`../common/src/functions/utils/erc20tokenFunctions.cjs`);require(`../common/src/functions/index.cjs`);const r=require(`../common/src/data-structures/Hinkal/Hinkal.cjs`),i=require(`../internal/token.utils.cjs`);var a=class{hinkalCommon;mappedPrivateBalancesSource;mappedPrivateBalances={};constructor(e){this.hinkalCommon=new r.Hinkal(e)}getProviderAdapter(e){return this.hinkalCommon.getProviderAdapter(e)}initProviderAdapter(e,t){return this.hinkalCommon.initProviderAdapter(e,t)}initUserKeys(e=t.LoginMessageMode.PROTOCOL){return this.hinkalCommon.initUserKeys(e)}initUserKeysWithSignature(e){return this.hinkalCommon.initUserKeysWithSignature(e)}initUserKeysFromSeedPhrases(e){return this.hinkalCommon.initUserKeysFromSeedPhrases(e)}storeAndGetInitialSignature(e,t=!1,n){return this.hinkalCommon.storeAndGetInitialSignature(e,t,n)}resetProviderAdapters(){return this.hinkalCommon.resetProviderAdapters()}disconnectFromConnector(){return this.hinkalCommon.disconnectFromConnector()}destroy(){return this.hinkalCommon.destroy()}signMessage(e){return this.hinkalCommon.signMessage(e)}signTypedData(e,t,n){return this.hinkalCommon.signTypedData(e,t,n)}getSupportedChains(){return this.hinkalCommon.getSupportedChains()}isSelectedNetworkSupported(e){return this.hinkalCommon.isSelectedNetworkSupported(e)}switchNetwork(t){let n=e.networkRegistry[t];if(!n)throw Error(`Network with chainId ${t} not supported`);return this.hinkalCommon.switchNetwork(n)}resetMerkle(e){return this.hinkalCommon.resetMerkle(e)}resetMerkleTreesIfNecessary(e){return this.hinkalCommon.resetMerkleTreesIfNecessary(e)}getMappedPrivateBalances(e){return e===this.mappedPrivateBalancesSource?this.mappedPrivateBalances:(this.mappedPrivateBalancesSource=e,this.mappedPrivateBalances=i.mapPrivateBalances(e),this.mappedPrivateBalances)}get privateBalancesWithUSD(){return this.getMappedPrivateBalances(this.hinkalCommon.privateBalancesWithUSD)}onPrivateBalancesWithUSDChange(e){return this.hinkalCommon.onPrivateBalancesWithUSDChange(t=>e(this.getMappedPrivateBalances(t)))}async getTotalBalance(e,t=!1,n=!1){return(await this.hinkalCommon.getTotalBalance(e,void 0,void 0,t,n)).map(i.mapTokenBalance)}async getStuckShieldedBalances(e,t=!1,n=!1){return(await this.hinkalCommon.getStuckShieldedBalances(e,void 0,void 0,t,n)).map(i.mapTokenBalance)}monitorConnectedAddress(e){return this.hinkalCommon.monitorConnectedAddress(e)}waitForTransaction(e,t,n){return this.hinkalCommon.waitForTransaction(e,t,n)}getSolanaPublicKey(){return this.hinkalCommon.getSolanaPublicKey()}getEthereumAddress(){return this.hinkalCommon.getEthereumAddress()}getEthereumAddressByChain(e){return this.hinkalCommon.getEthereumAddressByChain(e)}getRecipientInfo(){return this.hinkalCommon.getRecipientInfo()}getShieldedPublicKey(){return this.hinkalCommon.userKeys.getShieldedPublicKey()}async prooflessDeposit(e,t,r,i){return this.hinkalCommon.prooflessDeposit(await n.resolveErc20Tokens(e,t),r,i)}async prooflessDepositWithPublicFee(e,t,r,i,a){return this.hinkalCommon.prooflessDepositWithPublicFee(await n.resolveErc20Token(e,t),r,i,a)}async deposit(e,t,r,i,a){return this.hinkalCommon.deposit(await n.resolveErc20Tokens(e,t),r,i,a)}async depositSolana(e,t,r){return this.hinkalCommon.depositSolana(r,await n.resolveErc20Token(e,t))}async depositForOther(e,t,r,i,a,o){return this.hinkalCommon.depositForOther(await n.resolveErc20Tokens(e,t),r,i,a,o)}async depositSolanaForOther(e,t,r,i){return this.hinkalCommon.depositSolanaForOther(r,await n.resolveErc20Token(e,t),i)}async depositAndWithdraw(e,t,r,i,a,o,s){return this.hinkalCommon.depositAndWithdraw(await n.resolveErc20Token(e,t),r,i,a,o,void 0,void 0,void 0,s)}async depositAndBridge(e,t,r,i,a,o){return this.hinkalCommon.depositAndBridge(await n.resolveErc20Token(e,t),r,i,a,void 0,void 0,void 0,o)}async checkSendTransactionStatus(e){return this.hinkalCommon.checkSendTransactionStatus(e)}async nearDepositAndBridge(e,t,r,i,a,o,s){return this.hinkalCommon.nearDepositAndBridge(await n.resolveErc20Token(e,t),r,i,a,o,s)}async claimUtxo(e,t,r,i,a){return this.hinkalCommon.claimUtxo(await n.resolveErc20Token(e,t),r,i,a)}async transfer(e,t,r,i,a,o){return this.hinkalCommon.transfer(await n.resolveErc20Tokens(e,t),r,i,a,o)}async withdraw(e,t,r,i,a,o,s){return this.hinkalCommon.withdraw(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}async withdrawStuckUtxos(e,t,r){return this.hinkalCommon.withdrawStuckUtxos(await n.resolveErc20Token(e,t),r)}async swap(e,t,r,i,a,o,s){return this.hinkalCommon.swap(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}async actionPrivateWallet(e,t,r,a,o,s,c,l,u){return this.hinkalCommon.actionPrivateWallet(e,await n.resolveErc20Tokens(e,t),r,a,o,await i.resolveCommonTokenChanges(e,s),c,l,u)}async proxySwap(e,t,r,i,a,o,s,c,l){return this.hinkalCommon.proxySwap(await n.resolveErc20Tokens(e,t),r,i,a,o,s,c,l)}async proxyToPrivate(e,t,r,i,a,o,s){return this.hinkalCommon.proxyToPrivate(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}async proxySend(e,t,r,i,a,o,s){return this.hinkalCommon.proxySend(await n.resolveErc20Tokens(e,t),r,i,a,o,s)}};exports.Hinkal=a;
@@ -106,19 +106,7 @@ var c = class {
106
106
  return this.hinkalCommon.prooflessDepositWithPublicFee(await n(e, t), r, i, a);
107
107
  }
108
108
  async deposit(e, t, n, i, a) {
109
- console.log("[hinkal.deposit] start", {
110
- chainId: e,
111
- erc20Addresses: t,
112
- amountChanges: n.map(String)
113
- });
114
- try {
115
- let o = await r(e, t);
116
- console.log("[hinkal.deposit] resolved tokens");
117
- let s = await this.hinkalCommon.deposit(o, n, i, a);
118
- return console.log("[hinkal.deposit] success", { result: s }), s;
119
- } catch (e) {
120
- throw console.log("[hinkal.deposit] error", e), e;
121
- }
109
+ return this.hinkalCommon.deposit(await r(e, t), n, i, a);
122
110
  }
123
111
  async depositSolana(e, t, r) {
124
112
  return this.hinkalCommon.depositSolana(r, await n(e, t));
@@ -145,37 +133,10 @@ var c = class {
145
133
  return this.hinkalCommon.claimUtxo(await n(e, t), r, i, a);
146
134
  }
147
135
  async transfer(e, t, n, i, a, o) {
148
- console.log("[hinkal.transfer] start", {
149
- chainId: e,
150
- erc20Addresses: t,
151
- amountChanges: n.map(String),
152
- recipientAddress: i
153
- });
154
- try {
155
- let s = await r(e, t);
156
- console.log("[hinkal.transfer] resolved tokens");
157
- let c = await this.hinkalCommon.transfer(s, n, i, a, o);
158
- return console.log("[hinkal.transfer] success", { result: c }), c;
159
- } catch (e) {
160
- throw console.log("[hinkal.transfer] error", e), e;
161
- }
136
+ return this.hinkalCommon.transfer(await r(e, t), n, i, a, o);
162
137
  }
163
138
  async withdraw(e, t, n, i, a, o, s) {
164
- console.log("[hinkal.withdraw] start", {
165
- chainId: e,
166
- erc20Addresses: t,
167
- deltaAmounts: n.map(String),
168
- recipientAddress: i,
169
- isRelayerOff: a
170
- });
171
- try {
172
- let c = await r(e, t);
173
- console.log("[hinkal.withdraw] resolved tokens");
174
- let l = await this.hinkalCommon.withdraw(c, n, i, a, o, s);
175
- return console.log("[hinkal.withdraw] success", { result: l }), l;
176
- } catch (e) {
177
- throw console.log("[hinkal.withdraw] error", e), e;
178
- }
139
+ return this.hinkalCommon.withdraw(await r(e, t), n, i, a, o, s);
179
140
  }
180
141
  async withdrawStuckUtxos(e, t, r) {
181
142
  return this.hinkalCommon.withdrawStuckUtxos(await n(e, t), r);
@@ -1,2 +0,0 @@
1
- const e=require(`./workerProxy-D22p2w2G.js`);let t=require(`buffer`),n=require(`process`);n=e.l(n);let r=require(`circomlibjs-hinkal-fork`),i=require(`ethers`),a=require(`libsodium-wrappers`);a=e.l(a);let o=require(`@solana/web3.js`),s=require(`bs58`);s=e.l(s);let c=require(`tweetnacl`);c=e.l(c);let l=require(`tronweb`);var u=new class{babyjub=void 0;async init(){this.babyjub||=await(0,r.buildBabyjub)()}getJub(){return this.babyjub}},d=()=>u.getJub(),f=new class{eddsa=void 0;async init(){this.eddsa||=await(0,r.buildEddsa)()}getEddsa(){return this.eddsa}},p=()=>f.getEddsa();function m(e){return typeof e==`object`&&`toBigInt`in e?e.toBigInt():BigInt(e)}var h=new class{poseidon=void 0;async init(){this.poseidon||=await(0,r.buildPoseidon)()}getPoseidon(){return this.poseidon}};function g(...e){let t=h.getPoseidon();return m(t.F.toString(t(e)))}var _=(...e)=>{let t=h.getPoseidon();return i.ethers.toBeHex(t.F.toString(t([...e])))},v=async(e=!1)=>{(typeof window<`u`||typeof self<`u`)&&(typeof window<`u`&&(window.global=window),globalThis.Buffer=t.Buffer,globalThis.process=n.default),await Promise.all([a.default.ready,h.init(),u.init(),...e?[]:[f.init()]])};`${`00`.repeat(20)}`;var y=21888242871839275222246405745257275088548364400416034343698204186575808495617n,b=y/2n,x=200n;`${`00`.repeat(32)}`;var S=class{inMemoryCache=new Map;constructor(e){e&&this.mergeWithSerialized(e)}getInMemory(e){return this.inMemoryCache.get(e)??void 0}setInMemory(e,t){this.inMemoryCache.set(e,t)}mergeWithSerialized(t){Object.entries(t).forEach(([t,n])=>{this.set(t,e.s(n))})}},C=class extends S{isAttached=!1;get(e){return this.getInMemory(e)}set(e,t){this.setInMemory(e,t)}serialize(){return Object.fromEntries([...this.inMemoryCache].map(([t,n])=>[t,e.c(n)]))}attach(t){if(this.isAttached)throw Error(`can't reattach cache device`);return this.isAttached=!0,(...n)=>{let r=e.c(n),i=this.get(r);if(i!==void 0)return i;let a=t(...n);return this.set(r,a),a}}},w=e=>{if(e<0n||e>=21888242871839275222246405745257275088548364400416034343698204186575808495617n)throw RangeError();return e>b},T=e=>w(e)?1n:0n,E=new C,D=new C,O=new C,k=class{signature;nullifyingKey;PREFIX_FOR_SPENDING_PAIR=`1`;PREFIX_FOR_NULLIFYING_PAIR=`2`;constructor(e,t){this.signature=e,this.nullifyingKey=t}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error(`No signature provided`)}requireKeyMaterial(){if(!this.signature&&!this.nullifyingKey)throw Error(`No signature or private key provided`)}verifyTronMessage(e,t){return this.requireSignature(),t===l.Trx.verifyMessageV2(e,this.signature)}getShieldedPrivateKey=()=>(this.requireKeyMaterial(),this.nullifyingKey||=i.ethers.keccak256(this.signature),this.nullifyingKey);getShieldedPublicKey=()=>(this.requireKeyMaterial(),_(this.getShieldedPrivateKey()));getSpendingKeyPair=()=>{this.requireSignature();let e=p(),t=d(),n=_(this.PREFIX_FOR_SPENDING_PAIR,this.getSignature()),r=Buffer.from(i.ethers.getBytes(n)),a=e.prv2pub(r);return{privSpendingKey:n,pubSpendingBJJPoint:[BigInt(t.F.toString(a[0])),BigInt(t.F.toString(a[1]))]}};signEddsa=e=>{this.requireSignature();let t=d(),n=p(),r=Buffer.from(i.ethers.getBytes(this.getSpendingKeyPair().privSpendingKey)),a=t.F.e(e),o=n.signPoseidon(r,a);return{R8:[BigInt(t.F.toString(o.R8[0])),BigInt(t.F.toString(o.R8[1]))],S:BigInt(o.S)}};getShieldedPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=_(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return i.ethers.keccak256(i.ethers.toUtf8Bytes(`hinkal-offchain-shielded-key:${t}`))};getClaimableSignatureFromNonce=e=>{this.requireKeyMaterial();let t=_(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return i.ethers.keccak256(i.ethers.toUtf8Bytes(`hinkal-claimable-utxo-signature:${t}`))};getDerivedEthereumAddress=()=>(this.requireKeyMaterial(),new i.ethers.Wallet(this.getShieldedPrivateKey()).address);getDerivedSolanaPublicKey=()=>(this.requireKeyMaterial(),o.Keypair.fromSeed(i.ethers.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());getNearIntentsAccountId=()=>{this.requireKeyMaterial();let e=o.Keypair.fromSeed(i.ethers.getBytes(this.getShieldedPrivateKey()));return i.ethers.hexlify(e.publicKey.toBytes()).slice(2)};getNearIntentsKeyPairString=()=>{this.requireKeyMaterial();let e=o.Keypair.fromSeed(i.ethers.getBytes(this.getShieldedPrivateKey()));return`ed25519:${s.default.encode(e.secretKey)}`};getSignerPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=_(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return i.ethers.keccak256(i.ethers.toUtf8Bytes(t))};getSignerSolanaPrivateKeyFromNonce=e=>{let t=this.getSignerPrivateKeyFromNonce(e),n=i.ethers.getBytes(t),r=o.Keypair.fromSeed(n);return s.default.encode(r.secretKey)};verifyMessage(e){return this.requireSignature(),i.ethers.verifyMessage(e,this.signature)}verifySolanaMessage(e,t){this.requireSignature();let n=new TextEncoder().encode(e),r=i.ethers.getBytes(this.signature),a=new o.PublicKey(t).toBytes();return c.default.sign.detached.verify(n,r,a)}static getRandomizedStealthPairOld=D.attach((e,t)=>{let n=d(),r=e*(BigInt(t)%y)%y,i=n.mulPointEscalar(n.Base8,e),a=n.mulPointEscalar(n.Base8,r);return{H0:[BigInt(n.F.toString(i[0])),BigInt(n.F.toString(i[1]))],H1:[BigInt(n.F.toString(a[0])),BigInt(n.F.toString(a[1]))]}});static getRandomizedStealthPair=E.attach((e,t)=>{let n=d(),r=BigInt(t)%y,i=n.mulPointEscalar(n.Base8,e),a=n.mulPointEscalar(i,r);return{H0:[BigInt(n.F.toString(i[0])),BigInt(n.F.toString(i[1]))],H1:[BigInt(n.F.toString(a[0])),BigInt(n.F.toString(a[1]))]}});static getStealthAddressCompressedPoints=(e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t),[i,a]=[n,r].map(e=>BigInt(e[1])+2n**255n*T(e[0]));return{h0:i,h1:a}};static checkSignature=(e,t,n,r)=>{let{h0:i,h1:a}=this.getStealthAddressCompressedPoints(e,r);return t===i&&n===a};static getStealthAddress=O.attach((e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t);return _(2n*T(n[0])+T(r[0]),n[1],r[1])});static getH1FromH0=(e,t)=>{let n=d(),r=BigInt(t)%y,i=[n.F.e(e[0]),n.F.e(e[1])],a=n.mulPointEscalar(i,r);return[BigInt(n.F.toString(a[0])),BigInt(n.F.toString(a[1]))]};static verifyStealthPair=(e,t,n,r=!0)=>{let i=this.getH1FromH0(e,n);return r?i[1]===t[1]:i===t};static getStealthAddressNewStyle=(e,t,n)=>{if(n?.length!==2)throw Error(`Spending public key must be an array of 2 elements`);let r=this.getH1FromH0(e,t);return _(2n*T(e[0])+T(r[0]),e[1],r[1],n[0],n[1],t)};static findCorrectRandomization(e,t){if(!t)throw Error(`No Private Shielded Key Provided`);let n=BigInt(t)%y,r,i,a=0n;do r=e*10n**a%y,i=r*n%y,a+=1n;while(i>=2n**253n||r>=2n**253n);return r}static getH0FromRandomization=e=>{let t=d(),n=t.mulPointEscalar(t.Base8,e);return[BigInt(t.F.toString(n[0])),BigInt(t.F.toString(n[1]))]};static findH0(e,t){if(!t)return;let{H0:n}=this.getRandomizedStealthPair(e,t);return n}static getEncryptionKeyPair=e=>{let t=a.default.crypto_box_seed_keypair(i.ethers.getBytes(e));return{privateKey:i.ethers.hexlify(t.privateKey),publicKey:i.ethers.hexlify(t.publicKey)}};getAccessKey=()=>(this.requireKeyMaterial(),_(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getBackendToken=()=>(this.requireKeyMaterial(),_(this.getAccessKey(),this.getShieldedPublicKey()))},A={CANNOT_CERTIFY_FOR_PAST_WEEK:`Certification for the past week is not available`,CYCLICAL_REFERRALS_FORBIDDEN:`Cyclical referrals are forbidden`,USER_IS_UNRANKED:`Please certify transactions to see rank`},j={WC_NO_MATCHING_KEY:`creating the transaction failed
2
- version`,CONNECTION_PROBLEM:`Failed to connect wallet. Please try again.`,REQUEST_PENDING:`request of type 'wallet_requestpermissions' already pending for origin`},M={INSUFFICIENT_FUNDS:`Insufficient funds`,INSUFFICIENT_FUNDS_WITHDRAW:`Not enough funds to withdraw`,INSUFFICIENT_FUNDS_TRANSFER:`Not enough funds to transfer`,INSUFFICIENT_FUNDS_TO_TRANSACT:`Not enough funds to transact`,INSUFFICIENT_FUNDS_GAS:`Insufficient funds for gas * price`,INSUFFICIENT_TRON_BALANCE_FOR_FEE:`Insufficient TRX balance to cover transfer amount and transaction fee reserve`,INSUFFICIENT_SOL_BALANCE:`Insufficient SOL balance`},N={GAS_PRICE_EXCEEDS_AUTOSHIELD_LIMIT:`Skipped shielding due to gas fee exceeding your limit.`,AUTO_SHIELD_INSUFFICIENT_GAS:`Auto-Shield skipped due to insufficient gas.`};({...A,...j,...M,...N});var P=e=>BigInt(i.ethers.hexlify(i.ethers.randomBytes(e))),F=()=>Math.floor(Date.now()/1e3),I=class t{amount;erc20TokenAddress;mintAddress;timeStamp;nullifyingKey;spendingPublicKey;randomization;H0;stealthAddress;encryptionKey;commitment;nullifier;isBlocked;isNewStyle;constructor({amount:e,erc20TokenAddress:t,mintAddress:n,timeStamp:r,nullifyingKey:i,spendingPublicKey:a,randomization:o,H0:s,stealthAddress:c,encryptionKey:l,commitment:u=void 0,nullifier:d=void 0,isBlocked:f=!1,isNewStyle:p=!1}){this.amount=e,this.erc20TokenAddress=t,this.mintAddress=n,this.timeStamp=r??F().toString(),this.nullifyingKey=i,this.spendingPublicKey=a,this.randomization=o??(i?k.findCorrectRandomization(P(31),i):void 0),this.H0=s??(p&&this.randomization?k.findH0(this.randomization,i):void 0),this.stealthAddress=c,this.encryptionKey=l,this.commitment=u,this.nullifier=d,this.isBlocked=f,this.isNewStyle=p}static createFrom(e,n){return new t({...e.getConstructableParams(),nullifier:void 0,commitment:void 0,...n})}getConstructableParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,nullifyingKey:this.nullifyingKey,spendingPublicKey:this.spendingPublicKey,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,encryptionKey:this.encryptionKey,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getBasicUtxoParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getCommitment(){if(!this.commitment){let e=[this.amount,this.erc20TokenAddress,BigInt(this.getStealthAddress()),this.timeStamp];this.commitment=_(...e)}return this.commitment}getNullifier(){if(!this.nullifier){if(!this.nullifyingKey)throw Error(`No Nullifiers if private key is not provided`);let e=this.getCommitment(),t=_(this.nullifyingKey,e);this.nullifier=_(e,t)}return this.nullifier}getStealthAddress(){if(!this.stealthAddress){if(!this.nullifyingKey)throw Error(`No stealth address in UTXO if private key is not provided`);if(this.isNewStyle){if(!this.H0)throw Error(`No H0 point provided`);this.stealthAddress=k.getStealthAddressNewStyle(this.H0,this.nullifyingKey,this.spendingPublicKey)}else{if(!this.randomization)throw Error(`No randomization provided`);this.stealthAddress=k.getStealthAddress(this.randomization,this.nullifyingKey)}}return this.stealthAddress}getTokenAddress(t){let n=e.r(t)?this.mintAddress:this.erc20TokenAddress;if(!n)throw Error(`No token address provided`);return n}getEncryptionKey(){if(!this.nullifyingKey){if(!this.encryptionKey)throw Error(`No encryption key provided in UTXO`);return this.encryptionKey}return k.getEncryptionKeyPair(this.nullifyingKey).publicKey}},L=()=>a.default.crypto_box_SEALBYTES+a.default.crypto_secretbox_KEYBYTES,R=e=>{let t=a.default.crypto_secretbox_NONCEBYTES,n=L(),r=0,i=e[r];r+=1;let o=e.slice(r,r+t);r+=t;let s=[];for(let t=0;t<i;t+=1)s.push(e.slice(r,r+n)),r+=n;return{nonce:o,sealedKeys:s,ciphertext:e.slice(r)}},z=(e,t,n,r)=>{let{nonce:o,sealedKeys:s,ciphertext:c}=R(e),l=a.default.crypto_box_seal_open(s[r],i.ethers.getBytes(n),i.ethers.getBytes(t)),u=a.default.crypto_secretbox_open_easy(c,o,l);return Buffer.from(u)},B=(e,t,n)=>{let r=a.default.crypto_box_seal_open(e,i.ethers.getBytes(n),i.ethers.getBytes(t));return Buffer.from(r)},V=54912,H=2,U=e=>e[0]*256+e[1],W=(e,t)=>{let{privateKey:n,publicKey:r}=k.getEncryptionKeyPair(t.getShieldedPrivateKey()),i=U(e)===V?z(e.slice(H),n,r,0):B(e,n,r),a=Buffer.from(i).toString(`utf-8`).split(`0x`).filter(e=>e.length!==0),s=e=>BigInt(`0x${e}`),c=e=>`0x${e}`,l=a.length>=8,u=l&&s(a[5])===1n,d=l?8:6,f=a[d]?c(a[d]):void 0,p=f?new o.PublicKey(Buffer.from(f.slice(2),`hex`)).toString():void 0;return{amount:s(a[0]),erc20TokenAddress:c(a[1]),randomization:s(a[2]),stealthAddress:c(a[3]),nullifyingKey:t.getShieldedPrivateKey(),timeStamp:s(a[4]).toString(),isNewStyle:u,...u?{H0:[s(a[6]),s(a[7])]}:{},mintAddress:p}},G=(e,t)=>new I(W(e,t)),K=e=>e&2n**255n-1n,q=e=>e>>255n&1n,J=(...t)=>{e.a&&console.log(...t)};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return x}});