@hinkal/common 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants/coingecko.constants.cjs +1 -1
- package/constants/coingecko.constants.mjs +14 -13
- package/constants/vite.constants.cjs +1 -1
- package/constants/vite.constants.mjs +22 -21
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +71 -70
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +8 -7
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +35 -34
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.mjs +28 -27
- package/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/functions/pre-transaction/outputUtxoProcessing.mjs +3 -2
- package/functions/pre-transaction/processAmountChanges.cjs +1 -1
- package/functions/pre-transaction/processAmountChanges.mjs +3 -2
- package/functions/protocols/pendle.helpers.cjs +1 -1
- package/functions/protocols/pendle.helpers.mjs +11 -10
- package/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/functions/snarkjs/common.snarkjs.mjs +28 -27
- package/functions/staking/index.cjs +1 -1
- package/functions/staking/index.mjs +25 -24
- package/functions/utils/process.utils.cjs +1 -1
- package/functions/utils/process.utils.mjs +3 -2
- package/functions/utils/requireEnv.cjs +1 -1
- package/functions/utils/requireEnv.mjs +5 -4
- package/functions/web3/events/balanceChangedHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedHandler.mjs +4 -3
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +9 -8
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +3 -2
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.mjs +3 -2
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +3 -2
- package/package.json +1 -1
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +4 -2
- package/providers/prepareWagmiv1Hinkal.cjs +1 -1
- package/providers/prepareWagmiv1Hinkal.mjs +4 -2
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.mjs +11 -10
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +2 -2
- package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.mjs +29 -28
- package/webworker/workerProxy.cjs +1 -1
- package/webworker/workerProxy.mjs +4 -3
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chains.constants.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.cjs"),e=require("./chains.constants.cjs"),s="https://api.coingecko.com/api/v3",c="https://pro-api.coingecko.com/api/v3",i=t.default.env.COINGECKO_API_KEY,r="x-cg-pro-api-key",o=i?c:s,h=n=>`${o}/simple/price?ids=${n}&vs_currencies=USD,ETH`,l=(n,a)=>`${o}/simple/token_price/${a}?contract_addresses=${n}&vs_currencies=USD`,d=`${c}/coins/list`,I={[e.chainIds.arbMainnet]:"ethereum",[e.chainIds.localhost]:"ethereum",[e.chainIds.ethMainnet]:"ethereum",[e.chainIds.optimism]:"ethereum",[e.chainIds.avalanche]:"avalanche-2",[e.chainIds.polygon]:"matic-network",[e.chainIds.bnbMainnet]:"binancecoin",[e.chainIds.base]:"ethereum"},u=n=>{switch(e.getNonLocalhostChainId(n)){case e.chainIds.ethMainnet:return"ethereum";case e.chainIds.polygon:return"polygon-pos";case e.chainIds.bnbMainnet:return"binance-smart-chain";case e.chainIds.optimism:return"optimistic-ethereum";case e.chainIds.arbMainnet:return"arbitrum-one";case e.chainIds.avalanche:return"avalanche";case e.chainIds.base:return"base";default:return"ethereum"}},m={[e.chainIds.polygon]:"polygon-pos",[e.chainIds.arbMainnet]:"arbitrum-one",[e.chainIds.ethMainnet]:"ethereum",[e.chainIds.avalanche]:"avalanche",[e.chainIds.bnbMainnet]:"binance-smart-chain",[e.chainIds.optimism]:"optimistic-ethereum",[e.chainIds.base]:"base"};exports.COINGECKO_API_KEY=i;exports.CoinGeckoChainLabels=m;exports.coingeckoPriceUrl=h;exports.coingeckoPriceUrl2=l;exports.coingeckoTokenListUrl=d;exports.getCoingeckoIdForNativeTokens=I;exports.getCoingeckoPlatform=u;exports.proCoingeckoUrl=c;exports.proHeader=r;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import c from "../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
2
|
+
import { chainIds as e, getNonLocalhostChainId as r } from "./chains.constants.mjs";
|
|
3
|
+
const i = "https://api.coingecko.com/api/v3", t = "https://pro-api.coingecko.com/api/v3", s = c.env.COINGECKO_API_KEY, p = "x-cg-pro-api-key", a = s ? t : i, l = (n) => `${a}/simple/price?ids=${n}&vs_currencies=USD,ETH`, u = (n, o) => `${a}/simple/token_price/${o}?contract_addresses=${n}&vs_currencies=USD`, b = `${t}/coins/list`, g = {
|
|
3
4
|
[e.arbMainnet]: "ethereum",
|
|
4
5
|
[e.localhost]: "ethereum",
|
|
5
6
|
[e.ethMainnet]: "ethereum",
|
|
@@ -8,8 +9,8 @@ const i = "https://api.coingecko.com/api/v3", t = "https://pro-api.coingecko.com
|
|
|
8
9
|
[e.polygon]: "matic-network",
|
|
9
10
|
[e.bnbMainnet]: "binancecoin",
|
|
10
11
|
[e.base]: "ethereum"
|
|
11
|
-
},
|
|
12
|
-
switch (
|
|
12
|
+
}, k = (n) => {
|
|
13
|
+
switch (r(n)) {
|
|
13
14
|
case e.ethMainnet:
|
|
14
15
|
return "ethereum";
|
|
15
16
|
case e.polygon:
|
|
@@ -27,7 +28,7 @@ const i = "https://api.coingecko.com/api/v3", t = "https://pro-api.coingecko.com
|
|
|
27
28
|
default:
|
|
28
29
|
return "ethereum";
|
|
29
30
|
}
|
|
30
|
-
},
|
|
31
|
+
}, C = {
|
|
31
32
|
[e.polygon]: "polygon-pos",
|
|
32
33
|
[e.arbMainnet]: "arbitrum-one",
|
|
33
34
|
[e.ethMainnet]: "ethereum",
|
|
@@ -37,13 +38,13 @@ const i = "https://api.coingecko.com/api/v3", t = "https://pro-api.coingecko.com
|
|
|
37
38
|
[e.base]: "base"
|
|
38
39
|
};
|
|
39
40
|
export {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
s as COINGECKO_API_KEY,
|
|
42
|
+
C as CoinGeckoChainLabels,
|
|
43
|
+
l as coingeckoPriceUrl,
|
|
44
|
+
u as coingeckoPriceUrl2,
|
|
45
|
+
b as coingeckoTokenListUrl,
|
|
46
|
+
g as getCoingeckoIdForNativeTokens,
|
|
47
|
+
k as getCoingeckoPlatform,
|
|
47
48
|
t as proCoingeckoUrl,
|
|
48
|
-
|
|
49
|
+
p as proHeader
|
|
49
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../functions/utils/enum.utils.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.cjs"),p=require("../functions/utils/enum.utils.cjs"),d=require("../functions/utils/process.utils.cjs");var r=(e=>(e.DEVELOPMENT="development",e.STAGING="staging",e.PLAYGROUND="playground",e.PRODUCTION="production",e))(r||{});const t={development:["localhost","192.","127."],playground:["playground"],staging:["working-branch"]};function i(e,a){return a.some(c=>e.includes(c))}const g=()=>(require("dotenv").config({path:"DOTENV_OVERRIDE"in n.default.env?n.default.env.DOTENV_OVERRIDE:void 0}),p.toEnumValue(r,n.default.env.DEPLOYMENT_MODE)||"development"),f=()=>{if(!d.isOnServer()&&typeof window>"u")return;if(d.isOnServer())return g();const e=window?.location?.host;return i(e,t.development)?"development":i(e,t.playground)?"playground":i(e,t.staging)?"staging":"production"},v=typeof n.default<"u"&&n.default.versions!=null&&n.default.versions.node!=null,y=typeof __webpack_require__<"u",o=f(),s=o==="staging",u=o==="playground",l=o==="development",m=s||l||u;exports.DEPLOYMENT_MODE=r;exports.deploymentMode=o;exports.isDevelopment=l;exports.isNode=v;exports.isNotProduction=m;exports.isPlayground=u;exports.isStaging=s;exports.isWebpack=y;
|
|
@@ -1,34 +1,35 @@
|
|
|
1
|
+
import n from "../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
1
2
|
import { toEnumValue as p } from "../functions/utils/enum.utils.mjs";
|
|
2
|
-
import { isOnServer as
|
|
3
|
-
var
|
|
4
|
-
const
|
|
3
|
+
import { isOnServer as i } from "../functions/utils/process.utils.mjs";
|
|
4
|
+
var d = /* @__PURE__ */ ((e) => (e.DEVELOPMENT = "development", e.STAGING = "staging", e.PLAYGROUND = "playground", e.PRODUCTION = "production", e))(d || {});
|
|
5
|
+
const o = {
|
|
5
6
|
development: ["localhost", "192.", "127."],
|
|
6
7
|
playground: ["playground"],
|
|
7
8
|
// The code deployed to the 'playground' branch is hosted by Netlify at 'hinkal-playground.netlify.app'
|
|
8
9
|
staging: ["working-branch"]
|
|
9
10
|
// The code deployed to the 'new' branch is hosted by Netlify at 'working-branch.netlify.app'
|
|
10
11
|
};
|
|
11
|
-
function
|
|
12
|
-
return
|
|
12
|
+
function t(e, s) {
|
|
13
|
+
return s.some((u) => e.includes(u));
|
|
13
14
|
}
|
|
14
|
-
const
|
|
15
|
+
const l = () => (require("dotenv").config({
|
|
15
16
|
// allow overriding .env file path, see startServer.sh script for explenation on why it is needed
|
|
16
|
-
path: "DOTENV_OVERRIDE" in
|
|
17
|
-
}), p(
|
|
18
|
-
if (!
|
|
17
|
+
path: "DOTENV_OVERRIDE" in n.env ? n.env.DOTENV_OVERRIDE : void 0
|
|
18
|
+
}), p(d, n.env.DEPLOYMENT_MODE) || "development"), c = () => {
|
|
19
|
+
if (!i() && typeof window > "u")
|
|
19
20
|
return;
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
21
|
+
if (i())
|
|
22
|
+
return l();
|
|
22
23
|
const e = window?.location?.host;
|
|
23
|
-
return
|
|
24
|
-
},
|
|
24
|
+
return t(e, o.development) ? "development" : t(e, o.playground) ? "playground" : t(e, o.staging) ? "staging" : "production";
|
|
25
|
+
}, R = typeof n < "u" && n.versions != null && n.versions.node != null, w = typeof __webpack_require__ < "u", r = c(), g = r === "staging", a = r === "playground", m = r === "development", D = g || m || a;
|
|
25
26
|
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
d as DEPLOYMENT_MODE,
|
|
28
|
+
r as deploymentMode,
|
|
29
|
+
m as isDevelopment,
|
|
30
|
+
R as isNode,
|
|
31
|
+
D as isNotProduction,
|
|
32
|
+
a as isPlayground,
|
|
33
|
+
g as isStaging,
|
|
34
|
+
w as isWebpack
|
|
34
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../types/hinkal.types.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.cjs"),h=require("../../types/hinkal.types.cjs"),d=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),v=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),C=require("./hinkalActionBeefy.cjs"),P=require("./hinkalActionConvex.cjs"),w=require("./hinkalActionCurve.cjs"),T=require("./hinkalActionPendle.cjs"),l=require("./hinkalDeposit.cjs"),m=require("./hinkalSwap.cjs"),q=require("./hinkalWithdraw.cjs"),f=require("./resetMerkleTrees.cjs"),u=require("../merkle-tree/MerkleTree.cjs"),g=require("../../crypto/poseidon.cjs");require("circomlibjs");const S=require("../../constants/chains.constants.cjs"),p=require("../../error-handling/error-codes.constants.cjs"),E=require("../../API/callMonitor.cjs"),F=require("./hinkalActionLidoEth.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const H=require("../../API/getAxelarGasEstimate.cjs"),k=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");require("../../constants/contracts.constants.cjs");const I=require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const M=require("../transactions-manager/TransactionsManager.cjs");require("../../functions/utils/external-action.utils.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");const R=require("../../functions/utils/reloadPage.cjs"),L=require("./hinkalActionVolatile.cjs"),A=require("./hinkalActionPendleLP.cjs"),W=require("../../API/getConnextReceiveFee.cjs"),x=require("./hinkalActionStake.cjs"),K=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),N=require("./hinkalPrivateWallet.cjs");class U{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;transactionsManager;utxoUtils=K.multiThreadedUtxoUtils;constructor(){this.userKeys=new o.UserKeys(void 0),this.merkleTreeHinkal=u.MerkleTree.create(g.poseidonFunction,25n,0n),this.merkleTreeAccessToken=u.MerkleTree.create(g.poseidonFunction,25n,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.transactionsManager=new M.TransactionsManager}async initProviderAdapter(e,t){await this.updateProviderAdapter(t),this.providerAdapter?.initConnector(e);const r=await this.connectAndPatchProvider(e);await t.init(r),await this.setListeners()}async initUserKeys(){this.userKeys=new o.UserKeys(await this.getProviderAdapter().signMessage(this.signingMessage))}async initUserKeysWithPassword(e){this.userKeys=new o.UserKeys(e)}async resetMerkle(){this.isSelectedNetworkSupported()&&await f.resetMerkleTrees(this)}getProviderAdapter(){if(!this.providerAdapter)throw new Error("ProviderAdapter is not initialized");return this.providerAdapter}async waitForTransaction(e,t=1){return!!await this.providerAdapter?.waitForTransaction(e,t)}getContractMetadata(e,t){return this.getProviderAdapter().getContractMetadata(e,t)}getContract(e,t=void 0,r){return this.getProviderAdapter().getContract(e,t,r)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,r){return await this.getProviderAdapter().signTypedData(e,t,r)}getContractWithSigner(e,t=""){return this.getProviderAdapter().getContractWithSigner(e,t)}getContractWithFetcher(e,t=""){return this.getProviderAdapter().getContractWithFetcher(e,t)}getContractWithFetcherForEthereum(e,t){return this.getProviderAdapter().getContractWithFetcherForEthereum(e,t)}isSelectedNetworkSupported(){return!!S.networkRegistry[this.getCurrentChainId()]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(p.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}getCurrentChainId(){const{chainId:e}=this.getProviderAdapter();if(!e)throw new Error("Illegal State: no chainId");return e}getSelectedNetwork(){return this.providerAdapter?.getSelectedNetwork()}isPermitterAvailable(){return this.getProviderAdapter().isPermitterAvailable()}async connectAndPatchProvider(e){return await this.getProviderAdapter().connectAndPatchProvider(e)}async disconnectFromConnector(){await this.getProviderAdapter().disconnectFromConnector()}async updateProviderAdapter(e){try{this.providerAdapter&&this.providerAdapter.release(),this.providerAdapter=e}catch(t){throw console.error(t),Error("updateProviderAdapter failed, please try again.")}}async setListeners(){this.providerAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.getProviderAdapter().onAccountChanged();const e=h.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):c.default?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=h.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):c.default?.emit("message",t,void 0)}else await this.disconnectFromConnector(),R.reloadPage()}async monitorConnectedAddress(){E.monitor(await this.getEthereumAddress(),this.getCurrentChainId())}async getBalances(){return v.getShieldedBalance(this)}getSupportedPassportLinks(){return I.supportedPassportLinks}checkAccessToken(){return a.checkHinkalAccessToken(this)}async getAxelarEstimate(e,t,r,n){return H.getAxelarGasEstimate(e,t,r,n,this.userKeys.getAccessKey())}async getConnextReceiveFee(e,t){return W.getConnextReceiveFee(this.getCurrentChainId(),e,t)}async mintHinkalAccessToken(e){return a.mintAccessToken(this,e)}async mintHinkalAccessTokenCrossChain(e,t){return a.mintTokenCrossChain(this,e,t)}async getHinkalTreeRootHash(){return this.getContractWithFetcher(d.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){return this.getContractWithFetcher(d.ContractType.CrossChainAccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(p.transactionErrorCodes.UNSUPPORTED_NETWORK);const[e,t]=await Promise.all([this.getHinkalTreeRootHash(),this.getAccessTokenTreeRootHash()]);(e.toBigInt()!==this.merkleTreeHinkal.getRootHash()||t.toBigInt()!==this.merkleTreeAccessToken.getRootHash())&&await this.resetMerkle()}async getEventsFromHinkal(){await Promise.all([this.accessTokenSnapshotService?.retrieveEventsFromLatestBlock(),this.commitmentsSnapshotService?.retrieveEventsFromLatestBlock(),this.nullifierSnapshotService?.retrieveEventsFromLatestBlock()])}getEthereumAddress(){return this.getProviderAdapter().getAddress()}async getRandomRelay(){return(await k.API.getIdleRelay(this.getCurrentChainId())).relay}getGasPrice(){if(!this.providerAdapter?.chainId)throw new Error("Illegal State of providerAdapter in Hinkal: no chainId");return this.providerAdapter.getGasPrice()}getAPI(){return k.API}async deposit(e,t){return l.hinkalDeposit(this,e,t)}async depositForOther(e,t,r){return l.hinkalDepositForOther(this,e,t,r)}async withdraw(e,t,r,n,i=!1){return q.hinkalWithdraw(this,e,t,r,n,i)}async swap(e,t,r,n,i=!1,s=!1){return m.hinkalSwap(this,e,t,r,n,i,s)}async actionCurve(e,t,r,n,i,s=!1){return w.hinkalActionCurve(this,e,t,r,n,i,s)}async actionConvex(e,t,r,n,i=!1){return P.hinkalActionConvex(this,e,t,r,n,i)}async actionBeefy(e,t,r,n,i,s,y=!1){return C.hinkalActionBeefy(this,e,t,r,n,i,s,y)}async actionLido(e,t,r,n,i,s=!1){return F.hinkalActionLido(this,e,t,r,n,i,s)}async actionPendle(e,t,r,n,i=!1){return T.hinkalActionPendle(this,e,t,r,n,i)}async actionPendleLP(e,t,r,n,i=!1){return A.hinkalActionPendleLP(this,e,t,r,n,i)}async actionVolatile(e,t,r,n=!1){return L.hinkalActionVolatile(this,e,t,r,n)}async actionStake(e,t,r,n){return x.hinkalActionStake(this,e,t,r,n)}async actionPrivateWallet(e,t,r,n=[],i,s=!1){return N.hinkalPrivateWallet(this,e,t,r,n,i,s)}async getPendleLPClaimableParams(e,t){return A.hinkalGetPendleLPClaimableParams(this,e,t)}}exports.Hinkal=U;
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import o from "../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
2
|
+
import { EventType as c } from "../../types/hinkal.types.mjs";
|
|
3
|
+
import { ContractType as h } from "../../types/ethereum-network.types.mjs";
|
|
4
|
+
import { checkHinkalAccessToken as u, mintAccessToken as k, mintTokenCrossChain as A } from "../../functions/web3/functionCalls/accessTokenCalls.mjs";
|
|
5
|
+
import { getShieldedBalance as v } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
5
6
|
import { UserKeys as s } from "../crypto-keys/keys.mjs";
|
|
6
|
-
import { hinkalActionBeefy as
|
|
7
|
-
import { hinkalActionConvex as
|
|
8
|
-
import { hinkalActionCurve as
|
|
9
|
-
import { hinkalActionPendle as
|
|
10
|
-
import { hinkalDeposit as
|
|
11
|
-
import { hinkalSwap as
|
|
12
|
-
import { hinkalWithdraw as
|
|
13
|
-
import { resetMerkleTrees as
|
|
14
|
-
import { MerkleTree as
|
|
15
|
-
import { poseidonFunction as
|
|
7
|
+
import { hinkalActionBeefy as y } from "./hinkalActionBeefy.mjs";
|
|
8
|
+
import { hinkalActionConvex as f } from "./hinkalActionConvex.mjs";
|
|
9
|
+
import { hinkalActionCurve as C } from "./hinkalActionCurve.mjs";
|
|
10
|
+
import { hinkalActionPendle as w } from "./hinkalActionPendle.mjs";
|
|
11
|
+
import { hinkalDeposit as P, hinkalDepositForOther as T } from "./hinkalDeposit.mjs";
|
|
12
|
+
import { hinkalSwap as S } from "./hinkalSwap.mjs";
|
|
13
|
+
import { hinkalWithdraw as E } from "./hinkalWithdraw.mjs";
|
|
14
|
+
import { resetMerkleTrees as H } from "./resetMerkleTrees.mjs";
|
|
15
|
+
import { MerkleTree as d } from "../merkle-tree/MerkleTree.mjs";
|
|
16
|
+
import { poseidonFunction as p } from "../../crypto/poseidon.mjs";
|
|
16
17
|
import "circomlibjs";
|
|
17
|
-
import { networkRegistry as
|
|
18
|
-
import { transactionErrorCodes as
|
|
19
|
-
import { monitor as
|
|
20
|
-
import { hinkalActionLido as
|
|
18
|
+
import { networkRegistry as F } from "../../constants/chains.constants.mjs";
|
|
19
|
+
import { transactionErrorCodes as l } from "../../error-handling/error-codes.constants.mjs";
|
|
20
|
+
import { monitor as I } from "../../API/callMonitor.mjs";
|
|
21
|
+
import { hinkalActionLido as R } from "./hinkalActionLidoEth.mjs";
|
|
21
22
|
import "../../constants/vite.constants.mjs";
|
|
22
23
|
import "axios";
|
|
23
24
|
import "../../constants/coingecko.constants.mjs";
|
|
24
|
-
import { getAxelarGasEstimate as
|
|
25
|
-
import { API as
|
|
25
|
+
import { getAxelarGasEstimate as L } from "../../API/getAxelarGasEstimate.mjs";
|
|
26
|
+
import { API as m } from "../../API/API.mjs";
|
|
26
27
|
import "ethers";
|
|
27
28
|
import "../../types/curve.types.mjs";
|
|
28
29
|
import "../../constants/contracts.constants.mjs";
|
|
29
|
-
import { supportedPassportLinks as
|
|
30
|
+
import { supportedPassportLinks as M } from "../../constants/kyc.constants.mjs";
|
|
30
31
|
import "../../constants/axelar.constants.mjs";
|
|
31
32
|
import "../../constants/rewards.constants.mjs";
|
|
32
33
|
import "../../constants/reorg-depths.constants.mjs";
|
|
33
|
-
import { TransactionsManager as
|
|
34
|
+
import { TransactionsManager as W } from "../transactions-manager/TransactionsManager.mjs";
|
|
34
35
|
import "../../functions/utils/external-action.utils.mjs";
|
|
35
36
|
import "../../types/circom-data.types.mjs";
|
|
36
37
|
import "../../types/transactions.types.mjs";
|
|
37
|
-
import { reloadPage as
|
|
38
|
-
import { hinkalActionVolatile as
|
|
39
|
-
import { hinkalActionPendleLP as
|
|
40
|
-
import { getConnextReceiveFee as
|
|
41
|
-
import { hinkalActionStake as
|
|
42
|
-
import { multiThreadedUtxoUtils as
|
|
43
|
-
import { hinkalPrivateWallet as
|
|
44
|
-
class
|
|
38
|
+
import { reloadPage as N } from "../../functions/utils/reloadPage.mjs";
|
|
39
|
+
import { hinkalActionVolatile as K } from "./hinkalActionVolatile.mjs";
|
|
40
|
+
import { hinkalActionPendleLP as O, hinkalGetPendleLPClaimableParams as x } from "./hinkalActionPendleLP.mjs";
|
|
41
|
+
import { getConnextReceiveFee as B } from "../../API/getConnextReceiveFee.mjs";
|
|
42
|
+
import { hinkalActionStake as U } from "./hinkalActionStake.mjs";
|
|
43
|
+
import { multiThreadedUtxoUtils as b } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
|
|
44
|
+
import { hinkalPrivateWallet as D } from "./hinkalPrivateWallet.mjs";
|
|
45
|
+
class We {
|
|
45
46
|
providerAdapter;
|
|
46
47
|
userKeys;
|
|
47
48
|
signingMessage = "Login to Hinkal Protocol";
|
|
@@ -53,9 +54,9 @@ class Le {
|
|
|
53
54
|
nullifierSnapshotService;
|
|
54
55
|
accessTokenSnapshotService;
|
|
55
56
|
transactionsManager;
|
|
56
|
-
utxoUtils =
|
|
57
|
+
utxoUtils = b;
|
|
57
58
|
constructor() {
|
|
58
|
-
this.userKeys = new s(void 0), this.merkleTreeHinkal =
|
|
59
|
+
this.userKeys = new s(void 0), this.merkleTreeHinkal = d.create(p, 25n, 0n), this.merkleTreeAccessToken = d.create(p, 25n, 0n), this.nullifiers = /* @__PURE__ */ new Set(), this.encryptedOutputs = [], this.transactionsManager = new W();
|
|
59
60
|
}
|
|
60
61
|
async initProviderAdapter(e, t) {
|
|
61
62
|
await this.updateProviderAdapter(t), this.providerAdapter?.initConnector(e);
|
|
@@ -69,7 +70,7 @@ class Le {
|
|
|
69
70
|
this.userKeys = new s(e);
|
|
70
71
|
}
|
|
71
72
|
async resetMerkle() {
|
|
72
|
-
this.isSelectedNetworkSupported() && await
|
|
73
|
+
this.isSelectedNetworkSupported() && await H(this);
|
|
73
74
|
}
|
|
74
75
|
getProviderAdapter() {
|
|
75
76
|
if (!this.providerAdapter)
|
|
@@ -101,13 +102,13 @@ class Le {
|
|
|
101
102
|
return this.getProviderAdapter().getContractWithFetcherForEthereum(e, t);
|
|
102
103
|
}
|
|
103
104
|
isSelectedNetworkSupported() {
|
|
104
|
-
return !!
|
|
105
|
+
return !!F[this.getCurrentChainId()];
|
|
105
106
|
}
|
|
106
107
|
async switchNetwork(e) {
|
|
107
108
|
try {
|
|
108
109
|
await this.getProviderAdapter().switchNetwork(e);
|
|
109
110
|
} catch {
|
|
110
|
-
throw new Error(
|
|
111
|
+
throw new Error(l.FAILED_TO_SWITCH_NETWORKS);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
getCurrentChainId() {
|
|
@@ -147,31 +148,31 @@ class Le {
|
|
|
147
148
|
}
|
|
148
149
|
async onAccountChanged() {
|
|
149
150
|
await this.getProviderAdapter().onAccountChanged();
|
|
150
|
-
const e =
|
|
151
|
-
typeof document < "u" ? document?.dispatchEvent(new Event(e)) :
|
|
151
|
+
const e = c.AccountChanged;
|
|
152
|
+
typeof document < "u" ? document?.dispatchEvent(new Event(e)) : o?.emit("message", e, void 0);
|
|
152
153
|
}
|
|
153
154
|
async onChainChanged(e) {
|
|
154
155
|
if (e) {
|
|
155
156
|
await this.getProviderAdapter().onChainChanged(e);
|
|
156
|
-
const t =
|
|
157
|
-
typeof document < "u" ? document.dispatchEvent(new Event(t)) :
|
|
157
|
+
const t = c.NetworkChange;
|
|
158
|
+
typeof document < "u" ? document.dispatchEvent(new Event(t)) : o?.emit("message", t, void 0);
|
|
158
159
|
} else
|
|
159
|
-
await this.disconnectFromConnector(),
|
|
160
|
+
await this.disconnectFromConnector(), N();
|
|
160
161
|
}
|
|
161
162
|
async monitorConnectedAddress() {
|
|
162
|
-
|
|
163
|
+
I(await this.getEthereumAddress(), this.getCurrentChainId());
|
|
163
164
|
}
|
|
164
165
|
async getBalances() {
|
|
165
|
-
return
|
|
166
|
+
return v(this);
|
|
166
167
|
}
|
|
167
168
|
getSupportedPassportLinks() {
|
|
168
|
-
return
|
|
169
|
+
return M;
|
|
169
170
|
}
|
|
170
171
|
checkAccessToken() {
|
|
171
|
-
return
|
|
172
|
+
return u(this);
|
|
172
173
|
}
|
|
173
174
|
async getAxelarEstimate(e, t, r, i) {
|
|
174
|
-
return
|
|
175
|
+
return L(
|
|
175
176
|
e,
|
|
176
177
|
t,
|
|
177
178
|
r,
|
|
@@ -180,23 +181,23 @@ class Le {
|
|
|
180
181
|
);
|
|
181
182
|
}
|
|
182
183
|
async getConnextReceiveFee(e, t) {
|
|
183
|
-
return
|
|
184
|
+
return B(this.getCurrentChainId(), e, t);
|
|
184
185
|
}
|
|
185
186
|
async mintHinkalAccessToken(e) {
|
|
186
|
-
return
|
|
187
|
+
return k(this, e);
|
|
187
188
|
}
|
|
188
189
|
async mintHinkalAccessTokenCrossChain(e, t) {
|
|
189
|
-
return
|
|
190
|
+
return A(this, e, t);
|
|
190
191
|
}
|
|
191
192
|
async getHinkalTreeRootHash() {
|
|
192
|
-
return this.getContractWithFetcher(
|
|
193
|
+
return this.getContractWithFetcher(h.HinkalContract).getRootHash();
|
|
193
194
|
}
|
|
194
195
|
async getAccessTokenTreeRootHash() {
|
|
195
|
-
return this.getContractWithFetcher(
|
|
196
|
+
return this.getContractWithFetcher(h.CrossChainAccessTokenContract).getRootHash();
|
|
196
197
|
}
|
|
197
198
|
async resetMerkleTreesIfNecessary() {
|
|
198
199
|
if (!this.isSelectedNetworkSupported())
|
|
199
|
-
throw new Error(
|
|
200
|
+
throw new Error(l.UNSUPPORTED_NETWORK);
|
|
200
201
|
const [e, t] = await Promise.all([
|
|
201
202
|
this.getHinkalTreeRootHash(),
|
|
202
203
|
this.getAccessTokenTreeRootHash()
|
|
@@ -214,7 +215,7 @@ class Le {
|
|
|
214
215
|
return this.getProviderAdapter().getAddress();
|
|
215
216
|
}
|
|
216
217
|
async getRandomRelay() {
|
|
217
|
-
return (await
|
|
218
|
+
return (await m.getIdleRelay(this.getCurrentChainId())).relay;
|
|
218
219
|
}
|
|
219
220
|
getGasPrice() {
|
|
220
221
|
if (!this.providerAdapter?.chainId)
|
|
@@ -222,22 +223,22 @@ class Le {
|
|
|
222
223
|
return this.providerAdapter.getGasPrice();
|
|
223
224
|
}
|
|
224
225
|
getAPI() {
|
|
225
|
-
return
|
|
226
|
+
return m;
|
|
226
227
|
}
|
|
227
228
|
async deposit(e, t) {
|
|
228
|
-
return
|
|
229
|
+
return P(this, e, t);
|
|
229
230
|
}
|
|
230
231
|
async depositForOther(e, t, r) {
|
|
231
|
-
return
|
|
232
|
+
return T(this, e, t, r);
|
|
232
233
|
}
|
|
233
234
|
// async transfer(token: ERC20Token, amount: bigint, recipientAddress: string): Promise<ethers.ContractTransaction> {
|
|
234
235
|
// return hinkalTransfer(this, token, amount, recipientAddress);
|
|
235
236
|
// }
|
|
236
237
|
async withdraw(e, t, r, i, n = !1) {
|
|
237
|
-
return
|
|
238
|
+
return E(this, e, t, r, i, n);
|
|
238
239
|
}
|
|
239
240
|
async swap(e, t, r, i, n = !1, a = !1) {
|
|
240
|
-
return
|
|
241
|
+
return S(
|
|
241
242
|
this,
|
|
242
243
|
e,
|
|
243
244
|
t,
|
|
@@ -248,13 +249,13 @@ class Le {
|
|
|
248
249
|
);
|
|
249
250
|
}
|
|
250
251
|
async actionCurve(e, t, r, i, n, a = !1) {
|
|
251
|
-
return
|
|
252
|
+
return C(this, e, t, r, i, n, a);
|
|
252
253
|
}
|
|
253
254
|
async actionConvex(e, t, r, i, n = !1) {
|
|
254
|
-
return
|
|
255
|
+
return f(this, e, t, r, i, n);
|
|
255
256
|
}
|
|
256
|
-
async actionBeefy(e, t, r, i, n, a,
|
|
257
|
-
return
|
|
257
|
+
async actionBeefy(e, t, r, i, n, a, g = !1) {
|
|
258
|
+
return y(
|
|
258
259
|
this,
|
|
259
260
|
e,
|
|
260
261
|
t,
|
|
@@ -262,17 +263,17 @@ class Le {
|
|
|
262
263
|
i,
|
|
263
264
|
n,
|
|
264
265
|
a,
|
|
265
|
-
|
|
266
|
+
g
|
|
266
267
|
);
|
|
267
268
|
}
|
|
268
269
|
async actionLido(e, t, r, i, n, a = !1) {
|
|
269
|
-
return
|
|
270
|
+
return R(this, e, t, r, i, n, a);
|
|
270
271
|
}
|
|
271
272
|
async actionPendle(e, t, r, i, n = !1) {
|
|
272
|
-
return
|
|
273
|
+
return w(this, e, t, r, i, n);
|
|
273
274
|
}
|
|
274
275
|
async actionPendleLP(e, t, r, i, n = !1) {
|
|
275
|
-
return
|
|
276
|
+
return O(
|
|
276
277
|
this,
|
|
277
278
|
e,
|
|
278
279
|
t,
|
|
@@ -282,18 +283,18 @@ class Le {
|
|
|
282
283
|
);
|
|
283
284
|
}
|
|
284
285
|
async actionVolatile(e, t, r, i = !1) {
|
|
285
|
-
return
|
|
286
|
+
return K(this, e, t, r, i);
|
|
286
287
|
}
|
|
287
288
|
async actionStake(e, t, r, i) {
|
|
288
|
-
return
|
|
289
|
+
return U(this, e, t, r, i);
|
|
289
290
|
}
|
|
290
291
|
async actionPrivateWallet(e, t, r, i = [], n, a = !1) {
|
|
291
|
-
return
|
|
292
|
+
return D(this, e, t, r, i, n, a);
|
|
292
293
|
}
|
|
293
294
|
async getPendleLPClaimableParams(e, t) {
|
|
294
|
-
return
|
|
295
|
+
return x(this, e, t);
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
298
|
export {
|
|
298
|
-
|
|
299
|
+
We as Hinkal
|
|
299
300
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../constants/chains.constants.cjs"),x=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("axios");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");const A=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("../../constants/reorg-depths.constants.cjs");const C=require("../../functions/snarkjs/constructEmporiumProof.cjs"),P=require("../../functions/pre-transaction/processAmountChanges.cjs"),R=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),w=require("../../functions/web3/events/getShieldedBalance.cjs"),U=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),I=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),T=async(e,o,r,d,q=[],p,y=!1)=>{const a=o.map(t=>0n);r=P.processAmountChanges({erc20Addresses:o,amountChanges:r,flatFees:a,feeUnit:void 0,externalActionId:A.ExternalActionId.Emporium});const s=[...await w.addPaddingToUtxos(e,o,r)],i=[];for(let t=0;t<o.length;t+=1){const{outputUtxos:E}=R.outputUtxoProcessing(e.userKeys,s[t],r[t]);i.push(E)}const n=await e.getRandomRelay();if(!n)throw Error(x.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{contractData:g}=f.networkRegistry[e.getCurrentChainId()],{emporiumAddress:c}=g;if(!c)throw Error("No Emporium Address Provided");const{zkCallData:u,circomData:l,dimData:m}=await C.constructEmporiumProof(e.merkleTreeHinkal,e.merkleTreeAccessToken,s,i,e.userKeys,r.length,s[0].length,c,q,n,e.getCurrentChainId(),d,a,p);return y?await U.estimateGasRelayer(e,u,m,l):await I.transactCallRelayer(e.getCurrentChainId(),u,m,l)};exports.hinkalPrivateWallet=T;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../constants/chains.constants.cjs"),x=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("axios");require("../../constants/vite.constants.cjs");require("../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.cjs");require("../../types/circom-data.types.cjs");const A=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("../../constants/reorg-depths.constants.cjs");const C=require("../../functions/snarkjs/constructEmporiumProof.cjs"),P=require("../../functions/pre-transaction/processAmountChanges.cjs"),R=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),w=require("../../functions/web3/events/getShieldedBalance.cjs"),U=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),I=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),T=async(e,o,r,d,q=[],p,y=!1)=>{const a=o.map(t=>0n);r=P.processAmountChanges({erc20Addresses:o,amountChanges:r,flatFees:a,feeUnit:void 0,externalActionId:A.ExternalActionId.Emporium});const s=[...await w.addPaddingToUtxos(e,o,r)],i=[];for(let t=0;t<o.length;t+=1){const{outputUtxos:E}=R.outputUtxoProcessing(e.userKeys,s[t],r[t]);i.push(E)}const n=await e.getRandomRelay();if(!n)throw Error(x.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{contractData:g}=f.networkRegistry[e.getCurrentChainId()],{emporiumAddress:c}=g;if(!c)throw Error("No Emporium Address Provided");const{zkCallData:u,circomData:l,dimData:m}=await C.constructEmporiumProof(e.merkleTreeHinkal,e.merkleTreeAccessToken,s,i,e.userKeys,r.length,s[0].length,c,q,n,e.getCurrentChainId(),d,a,p);return y?await U.estimateGasRelayer(e,u,m,l):await I.transactCallRelayer(e.getCurrentChainId(),u,m,l)};exports.hinkalPrivateWallet=T;
|
|
@@ -3,6 +3,7 @@ import { transactionErrorCodes as A } from "../../error-handling/error-codes.con
|
|
|
3
3
|
import "ethers";
|
|
4
4
|
import "axios";
|
|
5
5
|
import "../../constants/vite.constants.mjs";
|
|
6
|
+
import "../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
6
7
|
import "../../types/circom-data.types.mjs";
|
|
7
8
|
import { ExternalActionId as w } from "../../types/external-action.types.mjs";
|
|
8
9
|
import "../../types/transactions.types.mjs";
|
|
@@ -15,7 +16,7 @@ import { outputUtxoProcessing as C } from "../../functions/pre-transaction/outpu
|
|
|
15
16
|
import { addPaddingToUtxos as I } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
16
17
|
import { estimateGasRelayer as P } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
17
18
|
import { transactCallRelayer as T } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
18
|
-
const
|
|
19
|
+
const Q = async (t, e, o, u, d = [], l, E = !1) => {
|
|
19
20
|
const m = e.map((r) => 0n);
|
|
20
21
|
o = U({
|
|
21
22
|
erc20Addresses: e,
|
|
@@ -32,10 +33,10 @@ const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
32
33
|
const s = await t.getRandomRelay();
|
|
33
34
|
if (!s)
|
|
34
35
|
throw Error(A.RELAYER_NOT_AVAILABLE);
|
|
35
|
-
const { contractData: x } = g[t.getCurrentChainId()], { emporiumAddress:
|
|
36
|
-
if (!
|
|
36
|
+
const { contractData: x } = g[t.getCurrentChainId()], { emporiumAddress: p } = x;
|
|
37
|
+
if (!p)
|
|
37
38
|
throw Error("No Emporium Address Provided");
|
|
38
|
-
const { zkCallData:
|
|
39
|
+
const { zkCallData: n, circomData: c, dimData: f } = await R(
|
|
39
40
|
t.merkleTreeHinkal,
|
|
40
41
|
t.merkleTreeAccessToken,
|
|
41
42
|
i,
|
|
@@ -43,7 +44,7 @@ const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
43
44
|
t.userKeys,
|
|
44
45
|
o.length,
|
|
45
46
|
i[0].length,
|
|
46
|
-
|
|
47
|
+
p,
|
|
47
48
|
d,
|
|
48
49
|
s,
|
|
49
50
|
t.getCurrentChainId(),
|
|
@@ -51,8 +52,8 @@ const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
51
52
|
m,
|
|
52
53
|
l
|
|
53
54
|
);
|
|
54
|
-
return E ? await P(t,
|
|
55
|
+
return E ? await P(t, n, f, c) : await T(t.getCurrentChainId(), n, f, c);
|
|
55
56
|
};
|
|
56
57
|
export {
|
|
57
|
-
|
|
58
|
+
Q as hinkalPrivateWallet
|
|
58
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("ethers"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../node_modules/vite-plugin-node-polyfills/shims/buffer/dist/index.cjs"),r=require("ethers"),y=require("libsodium-wrappers"),p=require("../utxo/Utxo.cjs"),u=require("./keys.cjs");(async()=>await y.ready)();const h=(e,i)=>{const n=[t.from(r.ethers.utils.hexlify(i?0n:e.amount)),t.from(r.ethers.utils.hexlify(e.erc20TokenAddress)),t.from(r.ethers.utils.hexlify(e.randomization)),t.from(e.getStealthAddress()),t.from(r.ethers.utils.hexlify(BigInt(e.timeStamp)))];e.tokenId>0&&n.push(t.from(r.ethers.utils.hexlify(e.tokenId)));const a=t.concat(n);return y.crypto_box_seal(a,r.ethers.utils.arrayify(e.getEncryptionKey()))},f=(e,i)=>{const{publicKey:n,privateKey:a}=u.UserKeys.getEncryptionKeyPair(i.getShieldedPrivateKey()),d=y.crypto_box_seal_open(e,r.ethers.utils.arrayify(n),r.ethers.utils.arrayify(a)),s=t.from(d).toString("utf-8").split("0x").filter(o=>o.length!==0).map((o,l)=>{let c;return[0,2,4,5].includes(l)?c=BigInt(`0x${o}`):[1,3].includes(l)&&(c=`0x${o}`),c});return{amount:s[0],erc20TokenAddress:s[1],randomization:s[2],stealthAddress:s[3],shieldedPrivateKey:i.getShieldedPrivateKey(),timeStamp:s[4].toString(),tokenId:s[5]?Number(s[5]):0}},m=(e,i)=>new p.Utxo(f(e,i));exports.decryptUtxo=m;exports.decryptUtxoConstructorArgs=f;exports.encryptUtxo=h;
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import e from "../../node_modules/vite-plugin-node-polyfills/shims/buffer/dist/index.mjs";
|
|
2
|
+
import { ethers as r } from "ethers";
|
|
3
|
+
import f from "libsodium-wrappers";
|
|
4
|
+
import { Utxo as l } from "../utxo/Utxo.mjs";
|
|
5
|
+
import { UserKeys as m } from "./keys.mjs";
|
|
6
|
+
(async () => await f.ready)();
|
|
7
|
+
const S = (t, o) => {
|
|
8
|
+
const n = [
|
|
9
|
+
e.from(r.utils.hexlify(o ? 0n : t.amount)),
|
|
10
|
+
e.from(r.utils.hexlify(t.erc20TokenAddress)),
|
|
11
|
+
e.from(r.utils.hexlify(t.randomization)),
|
|
12
|
+
e.from(t.getStealthAddress()),
|
|
13
|
+
e.from(r.utils.hexlify(BigInt(t.timeStamp)))
|
|
13
14
|
];
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
},
|
|
18
|
-
const { publicKey:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
),
|
|
23
|
-
let
|
|
24
|
-
return [0, 2, 4, 5].includes(
|
|
15
|
+
t.tokenId > 0 && n.push(e.from(r.utils.hexlify(t.tokenId)));
|
|
16
|
+
const a = e.concat(n);
|
|
17
|
+
return f.crypto_box_seal(a, r.utils.arrayify(t.getEncryptionKey()));
|
|
18
|
+
}, p = (t, o) => {
|
|
19
|
+
const { publicKey: n, privateKey: a } = m.getEncryptionKeyPair(o.getShieldedPrivateKey()), c = f.crypto_box_seal_open(
|
|
20
|
+
t,
|
|
21
|
+
r.utils.arrayify(n),
|
|
22
|
+
r.utils.arrayify(a)
|
|
23
|
+
), i = e.from(c).toString("utf-8").split("0x").filter((s) => s.length !== 0).map((s, d) => {
|
|
24
|
+
let y;
|
|
25
|
+
return [0, 2, 4, 5].includes(d) ? y = BigInt(`0x${s}`) : [1, 3].includes(d) && (y = `0x${s}`), y;
|
|
25
26
|
});
|
|
26
27
|
return {
|
|
27
|
-
amount:
|
|
28
|
-
erc20TokenAddress:
|
|
29
|
-
randomization:
|
|
30
|
-
stealthAddress:
|
|
31
|
-
shieldedPrivateKey:
|
|
32
|
-
timeStamp:
|
|
33
|
-
tokenId:
|
|
28
|
+
amount: i[0],
|
|
29
|
+
erc20TokenAddress: i[1],
|
|
30
|
+
randomization: i[2],
|
|
31
|
+
stealthAddress: i[3],
|
|
32
|
+
shieldedPrivateKey: o.getShieldedPrivateKey(),
|
|
33
|
+
timeStamp: i[4].toString(),
|
|
34
|
+
tokenId: i[5] ? Number(i[5]) : 0
|
|
34
35
|
// tokenId
|
|
35
36
|
};
|
|
36
|
-
},
|
|
37
|
+
}, b = (t, o) => new l(p(t, o));
|
|
37
38
|
export {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
b as decryptUtxo,
|
|
40
|
+
p as decryptUtxoConstructorArgs,
|
|
41
|
+
S as encryptUtxo
|
|
41
42
|
};
|