@hinkal/common 0.1.53 → 0.1.56
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/crypto/babyJub.cjs +1 -1
- package/crypto/babyJub.mjs +4 -4
- package/crypto/poseidon.cjs +1 -1
- package/crypto/poseidon.mjs +12 -12
- package/crypto/preProcessing.cjs +1 -1
- package/crypto/preProcessing.mjs +7 -5
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +6 -3
- package/data-structures/Hinkal/hinkalActionStake.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionStake.mjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +11 -8
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +8 -9
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.mjs +6 -7
- package/data-structures/event-service/AbstractAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/event-service/AbstractAccessTokenSnapshotService.mjs +9 -6
- package/data-structures/event-service/AbstractCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/event-service/AbstractCommitmentsSnapshotService.mjs +11 -8
- package/data-structures/event-service/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/AbstractEventService.mjs +24 -21
- package/data-structures/snapshot/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientAccessTokenSnapshotService.mjs +6 -3
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.mjs +6 -3
- package/data-structures/snapshot/ClientNullifierSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientNullifierSnapshotService.mjs +7 -4
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.mjs +1 -1
- package/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/functions/pre-transaction/outputUtxoProcessing.mjs +8 -5
- package/functions/pre-transaction/processAmountChanges.cjs +1 -1
- package/functions/pre-transaction/processAmountChanges.mjs +13 -10
- package/functions/protocols/pendle.helpers.cjs +1 -1
- package/functions/protocols/pendle.helpers.mjs +18 -16
- package/functions/staking/index.cjs +1 -1
- package/functions/staking/index.mjs +24 -22
- package/functions/utils/resolve-sync.utils.cjs +1 -1
- package/functions/utils/resolve-sync.utils.d.ts +1 -0
- package/functions/utils/resolve-sync.utils.mjs +12 -3
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +2 -2
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +14 -11
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +10 -7
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.mjs +23 -20
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +6 -3
- package/index.cjs +1 -1
- package/index.mjs +210 -209
- package/package.json +4 -2
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +4 -5
- package/providers/prepareWagmiv1Hinkal.cjs +1 -1
- package/providers/prepareWagmiv1Hinkal.mjs +4 -5
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
package/crypto/babyJub.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("circomlibjs-hinkal-fork");class e{babyjub=void 0;async init(){this.babyjub||(this.babyjub=await t.buildBabyjub())}getJub(){return this.babyjub}}const b=new e,u=()=>b.getJub();exports.babyJubInstance=u;exports.jubHolder=b;
|
package/crypto/babyJub.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { buildBabyjub as b } from "circomlibjs";
|
|
1
|
+
import { buildBabyjub as b } from "circomlibjs-hinkal-fork";
|
|
2
2
|
class t {
|
|
3
3
|
babyjub = void 0;
|
|
4
4
|
async init() {
|
|
5
|
-
this.babyjub = await b();
|
|
5
|
+
this.babyjub || (this.babyjub = await b());
|
|
6
6
|
}
|
|
7
7
|
getJub() {
|
|
8
8
|
return this.babyjub;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
const u = new t(),
|
|
11
|
+
const u = new t(), e = () => u.getJub();
|
|
12
12
|
export {
|
|
13
|
-
|
|
13
|
+
e as babyJubInstance,
|
|
14
14
|
u as jubHolder
|
|
15
15
|
};
|
package/crypto/poseidon.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("ethers"),t=require("../functions/utils/amounts.utils.cjs"),s=require("circomlibjs-hinkal-fork");class r{poseidon=void 0;async init(){this.poseidon||(this.poseidon=await s.buildPoseidon())}getPoseidon(){return this.poseidon}}const n=new r;function d(...e){const o=n.getPoseidon();return t.toBigInt(o.F.toString(o(e)))}const u=(...e)=>{const o=n.getPoseidon();return i.BigNumber.from(o.F.toString(o([...e]))).toHexString()};exports.poseidonFunction=d;exports.poseidonHash=u;exports.poseidonHolder=n;
|
package/crypto/poseidon.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { BigNumber as t } from "ethers";
|
|
2
|
+
import { toBigInt as e } from "../functions/utils/amounts.utils.mjs";
|
|
3
|
+
import { buildPoseidon as s } from "circomlibjs-hinkal-fork";
|
|
4
4
|
class r {
|
|
5
5
|
poseidon = void 0;
|
|
6
6
|
async init() {
|
|
7
|
-
this.poseidon = await
|
|
7
|
+
this.poseidon || (this.poseidon = await s());
|
|
8
8
|
}
|
|
9
9
|
getPoseidon() {
|
|
10
10
|
return this.poseidon;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
function g(...
|
|
15
|
-
const o =
|
|
16
|
-
return
|
|
13
|
+
const n = new r();
|
|
14
|
+
function g(...i) {
|
|
15
|
+
const o = n.getPoseidon();
|
|
16
|
+
return e(o.F.toString(o(i)));
|
|
17
17
|
}
|
|
18
|
-
const m = (...
|
|
19
|
-
const o =
|
|
20
|
-
return
|
|
18
|
+
const m = (...i) => {
|
|
19
|
+
const o = n.getPoseidon();
|
|
20
|
+
return t.from(o.F.toString(o([...i]))).toHexString();
|
|
21
21
|
};
|
|
22
22
|
export {
|
|
23
23
|
g as poseidonFunction,
|
|
24
24
|
m as poseidonHash,
|
|
25
|
-
|
|
25
|
+
n as poseidonHolder
|
|
26
26
|
};
|
package/crypto/preProcessing.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./babyJub.cjs"),o=require("./poseidon.cjs"),i=require("libsodium-wrappers"),r=require("process"),n=require("buffer"),s=async()=>{(typeof window<"u"||typeof WorkerGlobalScope<"u")&&(typeof window<"u"&&(window.global=window),globalThis.Buffer=n.Buffer,globalThis.process=r),await Promise.all([i.ready,o.poseidonHolder.init(),e.jubHolder.init()])};exports.preProcessing=s;
|
package/crypto/preProcessing.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { jubHolder as
|
|
1
|
+
import { jubHolder as o } from "./babyJub.mjs";
|
|
2
2
|
import { poseidonHolder as i } from "./poseidon.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import e from "libsodium-wrappers";
|
|
4
|
+
import r from "process";
|
|
5
|
+
import { Buffer as f } from "buffer";
|
|
6
|
+
const l = async () => {
|
|
7
|
+
(typeof window < "u" || typeof WorkerGlobalScope < "u") && (typeof window < "u" && (window.global = window), globalThis.Buffer = f, globalThis.process = r), await Promise.all([e.ready, i.init(), o.init()]);
|
|
6
8
|
};
|
|
7
9
|
export {
|
|
8
|
-
|
|
10
|
+
l as preProcessing
|
|
9
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../types/hinkal.types.cjs"),h=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),A=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),y=require("./hinkalActionBeefy.cjs"),C=require("./hinkalActionConvex.cjs"),P=require("./hinkalActionCurve.cjs"),w=require("./hinkalActionPendle.cjs"),d=require("./hinkalDeposit.cjs"),m=require("./hinkalSwap.cjs"),T=require("./hinkalWithdraw.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../types/hinkal.types.cjs"),h=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),A=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),y=require("./hinkalActionBeefy.cjs"),C=require("./hinkalActionConvex.cjs"),P=require("./hinkalActionCurve.cjs"),w=require("./hinkalActionPendle.cjs"),d=require("./hinkalDeposit.cjs"),m=require("./hinkalSwap.cjs"),T=require("./hinkalWithdraw.cjs"),q=require("./resetMerkleTrees.cjs"),l=require("../merkle-tree/MerkleTree.cjs"),u=require("../../crypto/poseidon.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const S=require("../../constants/chains.constants.cjs"),g=require("../../error-handling/error-codes.constants.cjs"),f=require("../../API/callMonitor.cjs"),E=require("./hinkalActionLidoEth.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const M=require("../../API/getAxelarGasEstimate.cjs"),p=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");require("../../constants/contracts.constants.cjs");const F=require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const H=require("../transactions-manager/TransactionsManager.cjs");require("../../functions/utils/external-action.utils.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");const I=require("../../functions/utils/reloadPage.cjs"),R=require("./hinkalActionVolatile.cjs"),k=require("./hinkalActionPendleLP.cjs"),L=require("../../API/getConnextReceiveFee.cjs"),W=require("./hinkalActionStake.cjs"),x=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),K=require("./hinkalPrivateWallet.cjs");class N{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;transactionsManager;utxoUtils;inMemoryCache;constructor(){this.userKeys=new o.UserKeys(void 0),this.merkleTreeHinkal=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.merkleTreeAccessToken=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.transactionsManager=new H.TransactionsManager,this.utxoUtils=new x.MultiThreadedUtxoUtils,this.inMemoryCache=new Map}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 q.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(g.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=c.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=c.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):process?.emit("message",t,void 0)}else await this.disconnectFromConnector(),I.reloadPage()}async monitorConnectedAddress(){f.monitor(await this.getEthereumAddress(),this.getCurrentChainId())}async getBalances(){return A.getShieldedBalance(this)}getSupportedPassportLinks(){return F.supportedPassportLinks}checkAccessToken(){return a.checkHinkalAccessToken(this)}async getAxelarEstimate(e,t,r,n){return M.getAxelarGasEstimate(e,t,r,n,this.userKeys.getAccessKey())}async getConnextReceiveFee(e,t){return L.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(h.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){return this.getContractWithFetcher(h.ContractType.CrossChainAccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(g.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 p.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 p.API}snapshotsClearInterval(){this.commitmentsSnapshotService?.intervalClear(),this.accessTokenSnapshotService?.intervalClear(),this.nullifierSnapshotService?.intervalClear()}async deposit(e,t){return d.hinkalDeposit(this,e,t)}async depositForOther(e,t,r){return d.hinkalDepositForOther(this,e,t,r)}async withdraw(e,t,r,n,i=!1){return T.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 P.hinkalActionCurve(this,e,t,r,n,i,s)}async actionConvex(e,t,r,n,i=!1){return C.hinkalActionConvex(this,e,t,r,n,i)}async actionBeefy(e,t,r,n,i,s,v=!1){return y.hinkalActionBeefy(this,e,t,r,n,i,s,v)}async actionLido(e,t,r,n,i,s=!1){return E.hinkalActionLido(this,e,t,r,n,i,s)}async actionPendle(e,t,r,n,i=!1){return w.hinkalActionPendle(this,e,t,r,n,i)}async actionPendleLP(e,t,r,n,i=!1){return k.hinkalActionPendleLP(this,e,t,r,n,i)}async actionVolatile(e,t,r,n=!1){return R.hinkalActionVolatile(this,e,t,r,n)}async actionStake(e,t,r,n){return W.hinkalActionStake(this,e,t,r,n)}async actionPrivateWallet(e,t,r,n=[],i,s=!1){return K.hinkalPrivateWallet(this,e,t,r,n,i,s)}async getPendleLPClaimableParams(e,t){return k.hinkalGetPendleLPClaimableParams(this,e,t)}}exports.Hinkal=N;
|
|
@@ -13,7 +13,10 @@ import { hinkalWithdraw as S } from "./hinkalWithdraw.mjs";
|
|
|
13
13
|
import { resetMerkleTrees as E } from "./resetMerkleTrees.mjs";
|
|
14
14
|
import { MerkleTree as h } from "../merkle-tree/MerkleTree.mjs";
|
|
15
15
|
import { poseidonFunction as d } from "../../crypto/poseidon.mjs";
|
|
16
|
-
import "circomlibjs";
|
|
16
|
+
import "circomlibjs-hinkal-fork";
|
|
17
|
+
import "libsodium-wrappers";
|
|
18
|
+
import "process";
|
|
19
|
+
import "buffer";
|
|
17
20
|
import { networkRegistry as H } from "../../constants/chains.constants.mjs";
|
|
18
21
|
import { transactionErrorCodes as p } from "../../error-handling/error-codes.constants.mjs";
|
|
19
22
|
import { monitor as F } from "../../API/callMonitor.mjs";
|
|
@@ -41,7 +44,7 @@ import { getConnextReceiveFee as O } from "../../API/getConnextReceiveFee.mjs";
|
|
|
41
44
|
import { hinkalActionStake as B } from "./hinkalActionStake.mjs";
|
|
42
45
|
import { MultiThreadedUtxoUtils as U } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
|
|
43
46
|
import { hinkalPrivateWallet as b } from "./hinkalPrivateWallet.mjs";
|
|
44
|
-
class
|
|
47
|
+
class Ne {
|
|
45
48
|
providerAdapter;
|
|
46
49
|
userKeys;
|
|
47
50
|
signingMessage = "Login to Hinkal Protocol";
|
|
@@ -299,5 +302,5 @@ class Re {
|
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
304
|
export {
|
|
302
|
-
|
|
305
|
+
Ne as Hinkal
|
|
303
306
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),p=require("../../functions/staking/index.cjs"),f=require("../../functions/utils/erc20tokenFunctions.cjs"),B=require("../../functions/web3/etherFunctions.cjs"),O=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),_=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),b=require("../../functions/web3/events/getShieldedBalance.cjs"),l=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const S=require("../../types/ethereum-network.types.cjs"),M=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const m=require("../../types/hinkal.stake.types.cjs");require("ethers");const j=require("../crypto-keys/keys.cjs");require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),p=require("../../functions/staking/index.cjs"),f=require("../../functions/utils/erc20tokenFunctions.cjs"),B=require("../../functions/web3/etherFunctions.cjs"),O=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),_=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),b=require("../../functions/web3/events/getShieldedBalance.cjs"),l=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const S=require("../../types/ethereum-network.types.cjs"),M=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const m=require("../../types/hinkal.stake.types.cjs");require("ethers");const j=require("../crypto-keys/keys.cjs");require("libsodium-wrappers");const w=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),z=async(t,g,o,s,a)=>{const C=await t.getEthereumAddress(),i=f.getERC20Token(g[0],t.getCurrentChainId());if(!i)throw Error("Deposit Action: No Token Found");const u=s===m.HinkalStakeMode.Stake,n=s===m.HinkalStakeMode.Unstake,{erc20TokenAddress:E}=i,r=[...await b.addPaddingToUtxos(t,g,o,2,void 0,s!==m.HinkalStakeMode.Deposit)];if(u||n){r[0][0]=l.Utxo.createFrom(r[0][0],{amount:o[0]*(u?1n:-1n),isStakeOrUnstakeInput:!0});for(let e=0;e<r.length;e+=1)for(let c=0;c<r[e].length;c+=1)e===0&&c===0||(r[e][c]=l.Utxo.createFrom(r[e][c],{amount:0n}))}const{outputUtxos:H}=O.outputUtxoProcessing(t.userKeys,r[0],o[0]),d=[H.map(e=>l.Utxo.createFrom(e,{isStake:u,isUnstakeOutput:n}))];n&&(d[0][0]=l.Utxo.createFrom(d[0][0],{amount:0n,isUnstakeOutput:n}));const P=[!1],k=B.randomBigInt(30),h=j.UserKeys.getEncryptionKeyPair(t.userKeys.getShieldedPrivateKey()),K=p.encryptStake(k,a,T.ownerPublicKey),D=p.encryptStake(k,a,h.publicKey),F=n?0n:p.createStakeCommitment(!0,a,k,E,o[0],BigInt(d[0][0].timeStamp)),I=u?0:1,v=p.encodeHStakeMetadata(I,F,C,K,D),x=t.getContractWithSigner(S.ContractType.HinkalWrapper2),y=t.getContractWithSigner(S.ContractType.HinkalStakeExternalAction),{zkCallData:q,dimData:A,circomData:U}=await _.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,r,d,t.userKeys,"swapperME1x2x1",M.ExternalActionId.HinkalStake,y.address,v,T.zeroAddress,t.getCurrentChainId(),P,void 0,void 0,{stakedTokenRecipient:a,stakeBlinding:k,mode:s,depositorAddress:C});if(n){const e=f.getHToken(i,t.getCurrentChainId());if(!e)throw new Error("hToken not found");const W=(await t.getContractWithFetcher(S.ContractType.HToken,e.erc20TokenAddress).previewWithdraw(-o[0])).toBigInt();return w.transactCallDirect(t,W,e,q,U,A,y,x)}return w.transactCallDirect(t,o[0],i,q,U,A,y,x)};exports.hinkalActionStake=z;
|
|
@@ -14,7 +14,7 @@ import "../../types/curve.types.mjs";
|
|
|
14
14
|
import { HinkalStakeMode as y } from "../../types/hinkal.stake.types.mjs";
|
|
15
15
|
import "ethers";
|
|
16
16
|
import { UserKeys as G } from "../crypto-keys/keys.mjs";
|
|
17
|
-
import "
|
|
17
|
+
import "libsodium-wrappers";
|
|
18
18
|
import { transactCallDirect as w } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
19
19
|
const pt = async (t, g, e, a, s) => {
|
|
20
20
|
const A = await t.getEthereumAddress(), c = b(g[0], t.getCurrentChainId());
|
|
@@ -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
|
|
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-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");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,m,d=[],p,y=!1)=>{const i=o.map(t=>0n);r=P.processAmountChanges({erc20Addresses:o,amountChanges:r,flatFees:i,feeUnit:void 0,externalActionId:A.ExternalActionId.Emporium});const s=[...await w.addPaddingToUtxos(e,o,r)],a=[];for(let t=0;t<o.length;t+=1){const{outputUtxos:E}=R.outputUtxoProcessing(e.userKeys,s[t],r[t]);a.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:q}=await C.constructEmporiumProof(e.merkleTreeHinkal,e.merkleTreeAccessToken,s,a,e.userKeys,r.length,s[0].length,c,d,n,e.getCurrentChainId(),m,i,p);return y?await U.estimateGasRelayer(e,u,q,l):await I.transactCallRelayer(e.getCurrentChainId(),u,q,l)};exports.hinkalPrivateWallet=T;
|
|
@@ -7,7 +7,10 @@ import "../../types/circom-data.types.mjs";
|
|
|
7
7
|
import { ExternalActionId as w } from "../../types/external-action.types.mjs";
|
|
8
8
|
import "../../types/transactions.types.mjs";
|
|
9
9
|
import "../../types/curve.types.mjs";
|
|
10
|
-
import "circomlibjs";
|
|
10
|
+
import "circomlibjs-hinkal-fork";
|
|
11
|
+
import "libsodium-wrappers";
|
|
12
|
+
import "process";
|
|
13
|
+
import "buffer";
|
|
11
14
|
import "../../constants/reorg-depths.constants.mjs";
|
|
12
15
|
import { constructEmporiumProof as R } from "../../functions/snarkjs/constructEmporiumProof.mjs";
|
|
13
16
|
import { processAmountChanges as U } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
@@ -15,7 +18,7 @@ import { outputUtxoProcessing as C } from "../../functions/pre-transaction/outpu
|
|
|
15
18
|
import { addPaddingToUtxos as I } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
16
19
|
import { estimateGasRelayer as P } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
17
20
|
import { transactCallRelayer as T } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
18
|
-
const
|
|
21
|
+
const X = async (t, e, o, u, d = [], l, E = !1) => {
|
|
19
22
|
const m = e.map((r) => 0n);
|
|
20
23
|
o = U({
|
|
21
24
|
erc20Addresses: e,
|
|
@@ -32,10 +35,10 @@ const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
32
35
|
const s = await t.getRandomRelay();
|
|
33
36
|
if (!s)
|
|
34
37
|
throw Error(A.RELAYER_NOT_AVAILABLE);
|
|
35
|
-
const { contractData: x } = g[t.getCurrentChainId()], { emporiumAddress:
|
|
36
|
-
if (!
|
|
38
|
+
const { contractData: x } = g[t.getCurrentChainId()], { emporiumAddress: p } = x;
|
|
39
|
+
if (!p)
|
|
37
40
|
throw Error("No Emporium Address Provided");
|
|
38
|
-
const { zkCallData:
|
|
41
|
+
const { zkCallData: n, circomData: c, dimData: f } = await R(
|
|
39
42
|
t.merkleTreeHinkal,
|
|
40
43
|
t.merkleTreeAccessToken,
|
|
41
44
|
i,
|
|
@@ -43,7 +46,7 @@ const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
43
46
|
t.userKeys,
|
|
44
47
|
o.length,
|
|
45
48
|
i[0].length,
|
|
46
|
-
|
|
49
|
+
p,
|
|
47
50
|
d,
|
|
48
51
|
s,
|
|
49
52
|
t.getCurrentChainId(),
|
|
@@ -51,8 +54,8 @@ const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
51
54
|
m,
|
|
52
55
|
l
|
|
53
56
|
);
|
|
54
|
-
return E ? await P(t,
|
|
57
|
+
return E ? await P(t, n, f, c) : await T(t.getCurrentChainId(), n, f, c);
|
|
55
58
|
};
|
|
56
59
|
export {
|
|
57
|
-
|
|
60
|
+
X as hinkalPrivateWallet
|
|
58
61
|
};
|
|
@@ -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("ethers"),y=require("libsodium-wrappers"),l=require("../utxo/Utxo.cjs"),u=require("./keys.cjs"),p=(e,s)=>{const i=[Buffer.from(t.ethers.utils.hexlify(s?0n:e.amount)),Buffer.from(t.ethers.utils.hexlify(e.erc20TokenAddress)),Buffer.from(t.ethers.utils.hexlify(e.randomization)),Buffer.from(e.getStealthAddress()),Buffer.from(t.ethers.utils.hexlify(BigInt(e.timeStamp)))];e.tokenId>0&&i.push(Buffer.from(t.ethers.utils.hexlify(e.tokenId)));const n=Buffer.concat(i);return y.crypto_box_seal(n,t.ethers.utils.arrayify(e.getEncryptionKey()))},d=(e,s)=>{const{publicKey:i,privateKey:n}=u.UserKeys.getEncryptionKeyPair(s.getShieldedPrivateKey()),c=y.crypto_box_seal_open(e,t.ethers.utils.arrayify(i),t.ethers.utils.arrayify(n)),r=Buffer.from(c).toString("utf-8").split("0x").filter(o=>o.length!==0).map((o,a)=>{let f;return[0,2,4,5].includes(a)?f=BigInt(`0x${o}`):[1,3].includes(a)&&(f=`0x${o}`),f});return{amount:r[0],erc20TokenAddress:r[1],randomization:r[2],stealthAddress:r[3],shieldedPrivateKey:s.getShieldedPrivateKey(),timeStamp:r[4].toString(),tokenId:r[5]?Number(r[5]):0}},h=(e,s)=>new l.Utxo(d(e,s));exports.decryptUtxo=h;exports.decryptUtxoConstructorArgs=d;exports.encryptUtxo=p;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ethers as t } from "ethers";
|
|
2
|
-
import
|
|
3
|
-
import { Utxo as
|
|
4
|
-
import { UserKeys as
|
|
5
|
-
(async () => await a.ready)();
|
|
2
|
+
import l from "libsodium-wrappers";
|
|
3
|
+
import { Utxo as c } from "../utxo/Utxo.mjs";
|
|
4
|
+
import { UserKeys as d } from "./keys.mjs";
|
|
6
5
|
const B = (e, i) => {
|
|
7
6
|
const o = [
|
|
8
7
|
Buffer.from(t.utils.hexlify(i ? 0n : e.amount)),
|
|
@@ -13,15 +12,15 @@ const B = (e, i) => {
|
|
|
13
12
|
];
|
|
14
13
|
e.tokenId > 0 && o.push(Buffer.from(t.utils.hexlify(e.tokenId)));
|
|
15
14
|
const n = Buffer.concat(o);
|
|
16
|
-
return
|
|
15
|
+
return l.crypto_box_seal(n, t.utils.arrayify(e.getEncryptionKey()));
|
|
17
16
|
}, m = (e, i) => {
|
|
18
|
-
const { publicKey: o, privateKey: n } =
|
|
17
|
+
const { publicKey: o, privateKey: n } = d.getEncryptionKeyPair(i.getShieldedPrivateKey()), a = l.crypto_box_seal_open(
|
|
19
18
|
e,
|
|
20
19
|
t.utils.arrayify(o),
|
|
21
20
|
t.utils.arrayify(n)
|
|
22
|
-
), r = Buffer.from(
|
|
21
|
+
), r = Buffer.from(a).toString("utf-8").split("0x").filter((f) => f.length !== 0).map((f, y) => {
|
|
23
22
|
let s;
|
|
24
|
-
return [0, 2, 4, 5].includes(
|
|
23
|
+
return [0, 2, 4, 5].includes(y) ? s = BigInt(`0x${f}`) : [1, 3].includes(y) && (s = `0x${f}`), s;
|
|
25
24
|
});
|
|
26
25
|
return {
|
|
27
26
|
amount: r[0],
|
|
@@ -33,7 +32,7 @@ const B = (e, i) => {
|
|
|
33
32
|
tokenId: r[5] ? Number(r[5]) : 0
|
|
34
33
|
// tokenId
|
|
35
34
|
};
|
|
36
|
-
}, x = (e, i) => new
|
|
35
|
+
}, x = (e, i) => new c(m(e, i));
|
|
37
36
|
export {
|
|
38
37
|
x as decryptUtxo,
|
|
39
38
|
m as decryptUtxoConstructorArgs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),y=require("libsodium-wrappers"),g=require("../../constants/protocol.constants.cjs"),S=require("../../crypto/babyJub.cjs"),o=require("../../crypto/poseidon.cjs"),h=require("../../functions/utils/memoize.utils.cjs"),c=require("./keyUtils.cjs"),p={privateKey:"",publicKey:""};class K{signature;constructor(e){this.signature=e}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error("No signature provided")}verifyMessage(e){return this.requireSignature(),u.utils.verifyMessage(e,this.signature)}getShieldedPrivateKey=()=>(this.requireSignature(),u.ethers.utils.keccak256(this.signature));getShieldedPublicKey=()=>(this.requireSignature(),o.poseidonHash(this.getShieldedPrivateKey()));getAccessKey=()=>(this.requireSignature(),o.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getWalletSalt=e=>(this.requireSignature(),o.poseidonHash(this.getShieldedPublicKey(),this.getShieldedPrivateKey(),e));getBackendToken=()=>(this.requireSignature(),o.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()));static getRandomizedStealthPair=h.memoizeFunc((e,i)=>{const t=S.babyJubInstance(),s=BigInt(i)%g.CIRCOM_P,n=e*s%g.CIRCOM_P,r=t.mulPointEscalar(t.Base8,e),a=t.mulPointEscalar(t.Base8,n),d=[BigInt(t.F.toString(r[0])),BigInt(t.F.toString(r[1]))],l=[BigInt(t.F.toString(a[0])),BigInt(t.F.toString(a[1]))];return{H0:d,H1:l}});static getStealthAddressCompressedPoints=(e,i)=>{const{H0:t,H1:s}=this.getRandomizedStealthPair(e,i),[n,r]=[t,s].map(a=>BigInt(a[1])+2n**255n*c.getCircomSign(a[0]));return{h0:n,h1:r}};static getStealthAddress=h.memoizeFunc((e,i)=>{const{H0:t,H1:s}=this.getRandomizedStealthPair(e,i),r=[2n*c.getCircomSign(t[0])+c.getCircomSign(s[0]),t[1],s[1]];return o.poseidonHash(...r)});static getStealthAddressWithEKey=(e,i)=>({stealthAddress:this.getStealthAddress(e,i),encryptionKey:this.getEncryptionKeyPair(i).publicKey});static checkSignature=(e,i,t,s)=>{const{h0:n,h1:r}=this.getStealthAddressCompressedPoints(e,s);return i===n&&t===r};static getEncryptionKeyPair=e=>{const i=y.crypto_box_seed_keypair(u.ethers.utils.arrayify(e));return{privateKey:u.ethers.utils.hexlify(i.privateKey),publicKey:u.ethers.utils.hexlify(i.publicKey)}}}exports.EncryptionKeyPairDefaultValue=p;exports.UserKeys=K;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { utils as
|
|
2
|
-
import
|
|
1
|
+
import { utils as y, ethers as o } from "ethers";
|
|
2
|
+
import S from "libsodium-wrappers";
|
|
3
3
|
import { CIRCOM_P as h } from "../../constants/protocol.constants.mjs";
|
|
4
4
|
import { babyJubInstance as m } from "../../crypto/babyJub.mjs";
|
|
5
5
|
import { poseidonHash as u } from "../../crypto/poseidon.mjs";
|
|
6
6
|
import { memoizeFunc as c } from "../../functions/utils/memoize.utils.mjs";
|
|
7
7
|
import { getCircomSign as g } from "./keyUtils.mjs";
|
|
8
|
-
(async () => await d.ready)();
|
|
9
8
|
const q = {
|
|
10
9
|
privateKey: "",
|
|
11
10
|
publicKey: ""
|
|
@@ -26,7 +25,7 @@ class H {
|
|
|
26
25
|
throw Error("No signature provided");
|
|
27
26
|
}
|
|
28
27
|
verifyMessage(t) {
|
|
29
|
-
return this.requireSignature(),
|
|
28
|
+
return this.requireSignature(), y.verifyMessage(t, this.signature);
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* get shielded private key from message signature used to login to the application,
|
|
@@ -54,8 +53,8 @@ class H {
|
|
|
54
53
|
getBackendToken = () => (this.requireSignature(), u(this.getAccessKey(), this.getShieldedPublicKey()));
|
|
55
54
|
static getRandomizedStealthPair = c(
|
|
56
55
|
(t, i) => {
|
|
57
|
-
const e = m(), r = BigInt(i) % h, n = t * r % h, s = e.mulPointEscalar(e.Base8, t), a = e.mulPointEscalar(e.Base8, n),
|
|
58
|
-
return { H0:
|
|
56
|
+
const e = m(), r = BigInt(i) % h, n = t * r % h, s = e.mulPointEscalar(e.Base8, t), a = e.mulPointEscalar(e.Base8, n), d = [BigInt(e.F.toString(s[0])), BigInt(e.F.toString(s[1]))], l = [BigInt(e.F.toString(a[0])), BigInt(e.F.toString(a[1]))];
|
|
57
|
+
return { H0: d, H1: l };
|
|
59
58
|
}
|
|
60
59
|
);
|
|
61
60
|
static getStealthAddressCompressedPoints = (t, i) => {
|
|
@@ -77,7 +76,7 @@ class H {
|
|
|
77
76
|
* and must correspond to 32 bytes
|
|
78
77
|
*/
|
|
79
78
|
static getEncryptionKeyPair = (t) => {
|
|
80
|
-
const i =
|
|
79
|
+
const i = S.crypto_box_seed_keypair(o.utils.arrayify(t));
|
|
81
80
|
return {
|
|
82
81
|
privateKey: o.utils.hexlify(i.privateKey),
|
|
83
82
|
publicKey: o.utils.hexlify(i.publicKey)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../constants/protocol.constants.cjs"),c=require("../../crypto/poseidon.cjs");require("circomlibjs");const n=require("../../functions/utils/amounts.utils.cjs"),o=require("../merkle-tree/MerkleTree.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../constants/protocol.constants.cjs"),c=require("../../crypto/poseidon.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const n=require("../../functions/utils/amounts.utils.cjs"),o=require("../merkle-tree/MerkleTree.cjs"),u=require("./AbstractSnapshotService.cjs");class A extends u.AbstractSnapshotService{constructor(e,s,r,d){super(e,{name:"NewAccessKeyAdded",args:["accessKey","index","senderAddress"]},s,r,d)}_merkleTree;_senderAddresses;_senderAddressIndexMap;get merkleTree(){return this._merkleTree}get senderAddresses(){return this._senderAddresses}get senderAddressIndexMap(){return this._senderAddressIndexMap}serializeSnapshot(e){return{merkleTree:e.payload.merkleTree.toJSON(),senderAddresses:Array.from(e.payload.senderAddresses),latestBlockNumber:e.latestBlockNumber,reserveBlockNumber:e.reserveBlockNumber,senderAddressIndexMap:Array.from(e.payload.senderAddressIndexMap).map(([s,r])=>({address:s,index:r}))}}deserializeSnapshot(e){let s,r;if(e.latestBlockNumber&&e.merkleTree){const d=new Map(Object.entries(e.merkleTree.tree).map(([t,a])=>[BigInt(t),BigInt(a)]));s=o.MerkleTree.createWithData(d,n.toBigInt(e.merkleTree.index),n.toBigInt(e.merkleTree.count),c.poseidonFunction,25n,0n)}else s=o.MerkleTree.create(c.poseidonFunction,25n,0n);return e.latestBlockNumber&&e.senderAddressIndexMap?r=new Map(e.senderAddressIndexMap.map(({address:d,index:t})=>[d,t])):r=new Map,{latestBlockNumber:e.latestBlockNumber??0,reserveBlockNumber:e.reserveBlockNumber??0,payload:{merkleTree:s,senderAddresses:e.senderAddresses??[],senderAddressIndexMap:r}}}acceptEvent(e,s){try{return this._merkleTree.insert(e.accessKey,e.index),this._senderAddressIndexMap.set(e.senderAddress,Math.max(Number(e.index),this._senderAddressIndexMap.get(e.senderAddress)??0)),this._senderAddresses.includes(e.senderAddress)||this._senderAddresses.push(e.senderAddress),e.accessKey===0n&&e.senderAddress===l.zeroAddress&&this._merkleTree.remove(e.index),!0}catch(r){return console.error(r),!1}}mapEvent(e){const{accessKey:s,index:r,senderAddress:d}=e;return{accessKey:n.toBigInt(s),index:n.toBigInt(r),senderAddress:d}}getSnapshotPayload(){return{merkleTree:this._merkleTree,senderAddresses:this._senderAddresses,senderAddressIndexMap:this._senderAddressIndexMap}}populateSnapshot({payload:{merkleTree:e,senderAddresses:s,senderAddressIndexMap:r}}){this._merkleTree=e,this._senderAddresses=s,this._senderAddressIndexMap=r}}exports.AbstractAccessTokenSnapshotService=A;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { zeroAddress as
|
|
1
|
+
import { zeroAddress as o } from "../../constants/protocol.constants.mjs";
|
|
2
2
|
import { poseidonFunction as m } from "../../crypto/poseidon.mjs";
|
|
3
|
-
import "circomlibjs";
|
|
3
|
+
import "circomlibjs-hinkal-fork";
|
|
4
|
+
import "libsodium-wrappers";
|
|
5
|
+
import "process";
|
|
6
|
+
import "buffer";
|
|
4
7
|
import { toBigInt as n } from "../../functions/utils/amounts.utils.mjs";
|
|
5
8
|
import { MerkleTree as c } from "../merkle-tree/MerkleTree.mjs";
|
|
6
|
-
import { AbstractSnapshotService as
|
|
7
|
-
class
|
|
9
|
+
import { AbstractSnapshotService as l } from "./AbstractSnapshotService.mjs";
|
|
10
|
+
class I extends l {
|
|
8
11
|
constructor(e, s, r, d) {
|
|
9
12
|
super(
|
|
10
13
|
e,
|
|
@@ -77,7 +80,7 @@ class M extends o {
|
|
|
77
80
|
return this._merkleTree.insert(e.accessKey, e.index), this._senderAddressIndexMap.set(
|
|
78
81
|
e.senderAddress,
|
|
79
82
|
Math.max(Number(e.index), this._senderAddressIndexMap.get(e.senderAddress) ?? 0)
|
|
80
|
-
), this._senderAddresses.includes(e.senderAddress) || this._senderAddresses.push(e.senderAddress), e.accessKey === 0n && e.senderAddress ===
|
|
83
|
+
), this._senderAddresses.includes(e.senderAddress) || this._senderAddresses.push(e.senderAddress), e.accessKey === 0n && e.senderAddress === o && this._merkleTree.remove(e.index), !0;
|
|
81
84
|
} catch (r) {
|
|
82
85
|
return console.error(r), !1;
|
|
83
86
|
}
|
|
@@ -104,5 +107,5 @@ class M extends o {
|
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
export {
|
|
107
|
-
|
|
110
|
+
I as AbstractAccessTokenSnapshotService
|
|
108
111
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../crypto/poseidon.cjs");require("circomlibjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../crypto/poseidon.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const i=require("../merkle-tree/MerkleTree.cjs"),n=require("../../functions/utils/amounts.utils.cjs"),m=require("./AbstractSnapshotService.cjs");class p extends m.AbstractSnapshotService{constructor(e,t,u,r){super(e,{name:"NewCommitment",args:["commitment","index","encryptedOutput"]},t,u,r)}_merkleTree;_encryptedOutputs;get merkleTree(){return this._merkleTree}get encryptedOutputs(){return this._encryptedOutputs}serializeSnapshot(e){return{merkleTree:e.payload.merkleTree.toJSON(),latestBlockNumber:e.latestBlockNumber,reserveBlockNumber:e.reserveBlockNumber,encryptedOutputs:e.payload.encryptedOutputs.map(t=>({value:t.value,isPositive:String(t.isPositive)}))}}deserializeSnapshot(e){let t;if(e.latestBlockNumber&&e.merkleTree){const r=new Map(Object.entries(e.merkleTree.tree).map(([c,o])=>[BigInt(c),BigInt(o)]));t=i.MerkleTree.createWithData(r,n.toBigInt(e.merkleTree.index),n.toBigInt(e.merkleTree.count),s.poseidonFunction,25n,0n)}else t=i.MerkleTree.create(s.poseidonFunction,25n,0n);const u=e.encryptedOutputs?.map(r=>({value:r.value,isPositive:JSON.parse(r.isPositive)}));return{latestBlockNumber:e.latestBlockNumber??0,reserveBlockNumber:e.reserveBlockNumber??0,payload:{merkleTree:t,encryptedOutputs:u||[]}}}getSnapshotPayload(){return{merkleTree:this._merkleTree,encryptedOutputs:this._encryptedOutputs}}populateSnapshot({payload:{merkleTree:e,encryptedOutputs:t}}){this._merkleTree=e,this._encryptedOutputs=t}mapEvent(e){const{commitment:t,index:u,encryptedOutput:r}=e;return{commitment:n.toBigInt(t),index:n.toBigInt(u),encryptedOutput:r}}acceptEvent(e,t){if(!this.encryptedOutputs.map(u=>u.value).includes(e.encryptedOutput)){if(!this._merkleTree.insert(e.commitment,e.index>=0?e.index:-1n*e.index))return!1;const r={value:e.encryptedOutput,isPositive:e.index>=0n};return this._encryptedOutputs.push(r),!0}return!1}}exports.AbstractCommitmentsSnapshotService=p;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { poseidonFunction as
|
|
2
|
-
import "circomlibjs";
|
|
3
|
-
import
|
|
1
|
+
import { poseidonFunction as m } from "../../crypto/poseidon.mjs";
|
|
2
|
+
import "circomlibjs-hinkal-fork";
|
|
3
|
+
import "libsodium-wrappers";
|
|
4
|
+
import "process";
|
|
5
|
+
import "buffer";
|
|
6
|
+
import { MerkleTree as s } from "../merkle-tree/MerkleTree.mjs";
|
|
4
7
|
import { toBigInt as n } from "../../functions/utils/amounts.utils.mjs";
|
|
5
8
|
import { AbstractSnapshotService as i } from "./AbstractSnapshotService.mjs";
|
|
6
|
-
class
|
|
9
|
+
class v extends i {
|
|
7
10
|
constructor(e, t, u, r) {
|
|
8
11
|
super(
|
|
9
12
|
e,
|
|
@@ -44,16 +47,16 @@ class O extends i {
|
|
|
44
47
|
BigInt(p)
|
|
45
48
|
])
|
|
46
49
|
);
|
|
47
|
-
t =
|
|
50
|
+
t = s.createWithData(
|
|
48
51
|
r,
|
|
49
52
|
n(e.merkleTree.index),
|
|
50
53
|
n(e.merkleTree.count),
|
|
51
|
-
|
|
54
|
+
m,
|
|
52
55
|
25n,
|
|
53
56
|
0n
|
|
54
57
|
);
|
|
55
58
|
} else
|
|
56
|
-
t =
|
|
59
|
+
t = s.create(m, 25n, 0n);
|
|
57
60
|
const u = e.encryptedOutputs?.map((r) => ({
|
|
58
61
|
value: r.value,
|
|
59
62
|
isPositive: JSON.parse(r.isPositive)
|
|
@@ -100,5 +103,5 @@ class O extends i {
|
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
export {
|
|
103
|
-
|
|
106
|
+
v as AbstractCommitmentsSnapshotService
|
|
104
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../constants/reorg-depths.constants.cjs"),o=require("../../functions/utils/resolve-sync.utils.cjs");require("ethers");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const v=require("../../error-handling/logError.cjs");class g{contract;eventConfig;_latestBlockNumber;maxPageSize;isReady=!1;_onNewEvent;isServer;intervalId;inProgress;constructor(e,r,t,s,n){this.contract=e,this.eventConfig=r,this._latestBlockNumber=t,this.maxPageSize=n,this.isServer=s,this.inProgress=!1}get latestBlockNumber(){return this._latestBlockNumber}set onNewEvent(e){this._onNewEvent=e}intervalClear(){this.isReady=!1,this._onNewEvent=void 0,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")}emitNewEvent(e){this._onNewEvent?.(e)}getLastBlockNumberForEventRequest=async()=>{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-u.blockReorgDepth[r]+1)};async retrieveEvents(e,r=!1){try{if(this.requireReady(),this.inProgress&&!r)return!1;this.inProgress=!0;const t=await this.getLastBlockNumberForEventRequest();if(t<e)return this.inProgress=!1,!1;const s=o.getSequence(e,t,this.maxPageSize);return await o.resolveSync(s.map(({from:n,to:i})=>async()=>{const c=await this.contract.queryFilter(this.contract.filters[this.eventConfig.name](),n,i);let a=[];c.length>0&&(a=await this.processEventsPage(c)),this._latestBlockNumber=i,await this.afterEventsAccepted(),a.length>0&&this.emitNewEvent()})),this.inProgress=!1,!0}catch(t){return v.logError("retrieveEvents error:",{err:t}),this.inProgress=!1,!1}}async processEventsPage(e){const r=[];return await o.resolveSync(e.map(t=>async()=>{const{args:s,blockNumber:n}=t;if(!s)throw new Error("Wrong event structure");const i=this.mapEvent(s);await this.acceptEvent(i,n)&&r.push(i)})),r}handleEvent=async(...e)=>{const{args:r}=this.eventConfig,{blockNumber:t}=e[e.length-1],s=e.slice(0,r.length),n=r.reduce((a,l,h)=>(a[l]=s[h],a),{});if(!t)throw new Error("Wrong event structure");const i=this.mapEvent(n);if(!await this.acceptEvent(i,t))throw new Error("Failed to retrieve events");this._latestBlockNumber=t,await this.afterEventsAccepted(),this.emitNewEvent(i)}}exports.AbstractEventService=g;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { blockReorgDepth as v } from "../../constants/reorg-depths.constants.mjs";
|
|
2
|
-
import { getSequence as
|
|
2
|
+
import { getSequence as m, resolveSync as c } from "../../functions/utils/resolve-sync.utils.mjs";
|
|
3
3
|
import "ethers";
|
|
4
4
|
import "axios";
|
|
5
5
|
import "../../constants/chains.constants.mjs";
|
|
@@ -7,9 +7,12 @@ import "../../constants/vite.constants.mjs";
|
|
|
7
7
|
import "../../types/circom-data.types.mjs";
|
|
8
8
|
import "../../types/transactions.types.mjs";
|
|
9
9
|
import "../../types/curve.types.mjs";
|
|
10
|
-
import "circomlibjs";
|
|
11
|
-
import
|
|
12
|
-
|
|
10
|
+
import "circomlibjs-hinkal-fork";
|
|
11
|
+
import "libsodium-wrappers";
|
|
12
|
+
import "process";
|
|
13
|
+
import "buffer";
|
|
14
|
+
import { logError as u } from "../../error-handling/logError.mjs";
|
|
15
|
+
class q {
|
|
13
16
|
contract;
|
|
14
17
|
eventConfig;
|
|
15
18
|
_latestBlockNumber;
|
|
@@ -20,8 +23,8 @@ class R {
|
|
|
20
23
|
intervalId;
|
|
21
24
|
inProgress;
|
|
22
25
|
// to remove race conditions
|
|
23
|
-
constructor(e,
|
|
24
|
-
this.contract = e, this.eventConfig =
|
|
26
|
+
constructor(e, r, t, s, n) {
|
|
27
|
+
this.contract = e, this.eventConfig = r, this._latestBlockNumber = t, this.maxPageSize = n, this.isServer = s, this.inProgress = !1;
|
|
25
28
|
}
|
|
26
29
|
get latestBlockNumber() {
|
|
27
30
|
return this._latestBlockNumber;
|
|
@@ -50,20 +53,20 @@ class R {
|
|
|
50
53
|
const e = await this.contract.provider.getBlockNumber();
|
|
51
54
|
if (!this.isServer)
|
|
52
55
|
return e;
|
|
53
|
-
const { chainId:
|
|
54
|
-
return Math.max(this.latestBlockNumber, e - v[
|
|
56
|
+
const { chainId: r } = await this.contract.provider.getNetwork();
|
|
57
|
+
return Math.max(this.latestBlockNumber, e - v[r] + 1);
|
|
55
58
|
};
|
|
56
|
-
async retrieveEvents(e,
|
|
59
|
+
async retrieveEvents(e, r = !1) {
|
|
57
60
|
try {
|
|
58
|
-
if (this.requireReady(), this.inProgress && !
|
|
61
|
+
if (this.requireReady(), this.inProgress && !r)
|
|
59
62
|
return !1;
|
|
60
63
|
this.inProgress = !0;
|
|
61
64
|
const t = await this.getLastBlockNumberForEventRequest();
|
|
62
65
|
if (t < e)
|
|
63
66
|
return this.inProgress = !1, !1;
|
|
64
|
-
const
|
|
67
|
+
const s = m(e, t, this.maxPageSize);
|
|
65
68
|
return await c(
|
|
66
|
-
|
|
69
|
+
s.map(({ from: n, to: i }) => async () => {
|
|
67
70
|
const o = await this.contract.queryFilter(
|
|
68
71
|
this.contract.filters[this.eventConfig.name](),
|
|
69
72
|
n,
|
|
@@ -74,23 +77,23 @@ class R {
|
|
|
74
77
|
})
|
|
75
78
|
), this.inProgress = !1, !0;
|
|
76
79
|
} catch (t) {
|
|
77
|
-
return
|
|
80
|
+
return u("retrieveEvents error:", { err: t }), this.inProgress = !1, !1;
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
async processEventsPage(e) {
|
|
81
|
-
const
|
|
84
|
+
const r = [];
|
|
82
85
|
return await c(
|
|
83
86
|
e.map((t) => async () => {
|
|
84
|
-
const { args:
|
|
85
|
-
if (!
|
|
87
|
+
const { args: s, blockNumber: n } = t;
|
|
88
|
+
if (!s)
|
|
86
89
|
throw new Error("Wrong event structure");
|
|
87
|
-
const i = this.mapEvent(
|
|
88
|
-
await this.acceptEvent(i, n) &&
|
|
90
|
+
const i = this.mapEvent(s);
|
|
91
|
+
await this.acceptEvent(i, n) && r.push(i);
|
|
89
92
|
})
|
|
90
|
-
),
|
|
93
|
+
), r;
|
|
91
94
|
}
|
|
92
95
|
handleEvent = async (...e) => {
|
|
93
|
-
const { args:
|
|
96
|
+
const { args: r } = this.eventConfig, { blockNumber: t } = e[e.length - 1], s = e.slice(0, r.length), n = r.reduce((a, h, l) => (a[h] = s[l], a), {});
|
|
94
97
|
if (!t)
|
|
95
98
|
throw new Error("Wrong event structure");
|
|
96
99
|
const i = this.mapEvent(n);
|
|
@@ -100,5 +103,5 @@ class R {
|
|
|
100
103
|
};
|
|
101
104
|
}
|
|
102
105
|
export {
|
|
103
|
-
|
|
106
|
+
q as AbstractEventService
|
|
104
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../event-service/AbstractAccessTokenSnapshotService.cjs");require("circomlibjs");require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../event-service/AbstractAccessTokenSnapshotService.cjs");require("ethers");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("axios");require("../../constants/chains.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const t=require("../../API/fetchCommitmentsCache.cjs");class c extends s.AbstractAccessTokenSnapshotService{constructor(r,e){super(r,0,!1,e)}async fetchSnapshot(){const{chainId:r}=await this.contract.provider.getNetwork(),e=await t.fetchAccessTokenSnapshot(r);if(e.accessTokenContractAddress!==this.contract.address||e.chainId!==r)throw Error("Commitment Snapshot: incorrect contract or chain id");return{latestBlockNumber:e.latestBlockNumber,merkleTree:e.merkleTree,senderAddresses:e.senderAddresses,senderAddressIndexMap:e.senderAddressIndexMap}}persistSnapshot(r){return Promise.resolve()}}exports.ClientAccessTokenSnapshotService=c;
|