const e=require(`../../functions/utils/caseInsensitive.utils.cjs`),t=require(`../../API/fetchCommitmentsCache.cjs`);var n=300*1e3,r=class{chainId;contractAddress;snapshotsPromise;lastFetchedAt;cacheDurationMs;constructor(e,t,r=n){this.chainId=e,this.contractAddress=t,this.cacheDurationMs=r}async fetchSnapshots(){return this.lastFetchedAt=Date.now(),t.fetchSnapshots(this.chainId)}async ensureSnapshots(t=!1){let n=Date.now(),r=!this.lastFetchedAt||n-this.lastFetchedAt>this.cacheDurationMs;(t||!this.snapshotsPromise||r)&&(this.snapshotsPromise=this.fetchSnapshots());let i=await this.snapshotsPromise;if(!e.caseInsensitiveEqual(i.commitments.hinkalAddress,this.contractAddress)||i.commitments.chainId!==this.chainId)throw Error(`Snapshots: incorrect contract or chain id`);return i}async getAll(e=!1){return this.ensureSnapshots(e)}async getCommitments(e=!1){return(await this.ensureSnapshots(e)).commitments}async getAccessTokens(e=!1){return(await this.ensureSnapshots(e)).accessTokens}async getNullifiers(e=!1){return(await this.ensureSnapshots(e)).nullifiers}};exports.SnapshotFetcherService=r;