import * as Store from '../../../internal/Store.js' import * as Screening from './Screening.js' /** Coordinates concurrent cached screening before credential processing. */ export type Manager = { /** Rejects when any payment participant fails screening. */ screen(addresses: readonly string[]): Promise } /** Creates a cached address-screening manager. */ export function create(options: create.Options): Manager { const { chainId, provider = Screening.allowAll, store, ttl = Screening.defaultTtl } = options return { async screen(addresses) { const results = await Promise.all( addresses.map((address) => Screening.screen({ address, chainId, provider, store, ttl })), ) if (results.some((result) => !result.allowed)) throw new RejectedError() }, } } export declare namespace create { /** Dependencies for cached address screening. */ type Options = { /** Tempo chain that owns the screened addresses. */ chainId: number /** Address-screening provider. */ provider?: Screening.Provider | undefined /** Cache used for screening results. */ store: Store.Store /** Cache duration. @default `Ttl.days(1)` */ ttl?: number | undefined } } /** Indicates that an address-screening provider rejected a participant. */ export class RejectedError extends Error { override name = 'Mpp.ScreenManager.RejectedError' }