import * as Store from '../../../internal/Store.js' import * as Ttl from '../../../internal/Ttl.js' /** Address-screening result. */ export type Result = { allowed: boolean } /** Address-screening provider. */ export type Provider = { /** Screens one normalized account address on a Tempo chain. */ screen(options: { address: string; chainId: number }): Promise } /** Allows every address while the external screening provider is unconfigured. */ export const allowAll: Provider = { async screen() { return { allowed: true } }, } /** Screens one address, caching the provider result by chain and normalized address. */ export async function screen(options: screen.Options): Promise { const { address, chainId, provider, store, ttl = defaultTtl } = options return Store.memoize(() => provider.screen({ address, chainId }), { key: `mpp:screen:v1:${chainId}:${address.toLowerCase()}`, store, ttl, }) } export declare namespace screen { /** Dependencies used to screen an address. */ type Options = { /** Normalized account address. */ address: string /** Tempo chain identifier. */ chainId: number /** Address-screening provider. */ provider: Provider /** Cache used for provider results. */ store: Store.Store /** Cache duration. @default `Ttl.days(1)` */ ttl?: number | undefined } } /** Default address-screening cache lifetime (24 hours). */ export const defaultTtl = Ttl.days(1)