import { Transaction, BroadcastResponse, BroadcastFailure, Broadcaster } from '../transaction/index.js';
import LookupResolver from './LookupResolver.js';
/**
 * Tagged BEEF
 *
 * @description
 * Tagged BEEF ([Background Evaluation Extended Format](https://brc.dev/62)) structure. Comprises a transaction, its SPV information, and the overlay topics where its inclusion is requested.
 */
export interface TaggedBEEF {
    beef: number[];
    topics: string[];
    offChainValues?: number[];
}
/**
 * Instructs the Overlay Services Engine about which outputs to admit and which previous outputs to retain. Returned by a Topic Manager.
 */
export interface AdmittanceInstructions {
    /**
     * The indices of all admissible outputs into the managed topic from the provided transaction.
     */
    outputsToAdmit: number[];
    /**
     * The indices of all inputs from the provided transaction which spend previously-admitted outputs that should be retained for historical record-keeping.
     */
    coinsToRetain: number[];
    /**
     * The indices of all inputs from the provided transaction which reference previously-admitted outputs,
     * which are now considered spent and have been removed from the managed topic.
     */
    coinsRemoved?: number[];
}
/**
 * Submitted Transaction Execution AcKnowledgment
 *
 * @description
 * Comprises the topics where a transaction was submitted, and for each one, the output indices for the UTXOs newly admitted into the topics, and the coins retained.
 * An object whose keys are topic names and whose values are topical admittance instructions denoting the state of the submitted transaction with respect to the associated topic.
 */
export type STEAK = Record<string, AdmittanceInstructions>;
/** The require mode for topic acknowledgment: all topics must be present, or any one suffices. */
export type RequireMode = 'all' | 'any';
/** Specifies which topics must be acknowledged: all, any, or a specific list. */
export type TopicAcknowledgmentRequirement = RequireMode | string[];
/** Configuration options for the SHIP broadcaster. */
export interface SHIPBroadcasterConfig {
    /**
     * The network preset to use, unless other options override it.
     * - mainnet: use mainnet resolver and HTTPS facilitator
     * - testnet: use testnet resolver and HTTPS facilitator
     * - local: directly send to localhost:8080 and a facilitator that permits plain HTTP
     */
    networkPreset?: 'mainnet' | 'testnet' | 'local';
    /** The facilitator used to make requests to Overlay Services hosts. */
    facilitator?: OverlayBroadcastFacilitator;
    /** The resolver used to locate suitable hosts with SHIP */
    resolver?: LookupResolver;
    /** Determines which topics (all, any, or a specific list) must be present within all STEAKs received from every host for the broadcast to be considered a success. By default, all hosts must acknowledge all topics. */
    requireAcknowledgmentFromAllHostsForTopics?: TopicAcknowledgmentRequirement;
    /** Determines which topics (all, any, or a specific list) must be present within STEAK received from at least one host for the broadcast to be considered a success. */
    requireAcknowledgmentFromAnyHostForTopics?: TopicAcknowledgmentRequirement;
    /** Determines a mapping whose keys are specific hosts and whose values are the topics (all, any, or a specific list) that must be present within the STEAK received by the given hosts, in order for the broadcast to be considered a success. */
    requireAcknowledgmentFromSpecificHostsForTopics?: Record<string, TopicAcknowledgmentRequirement>;
}
/** Facilitates transaction broadcasts that return STEAK. */
export interface OverlayBroadcastFacilitator {
    send: (url: string, taggedBEEF: TaggedBEEF) => Promise<STEAK>;
}
export declare class HTTPSOverlayBroadcastFacilitator implements OverlayBroadcastFacilitator {
    httpClient: typeof fetch;
    allowHTTP: boolean;
    constructor(httpClient?: typeof fetch, allowHTTP?: boolean);
    send(url: string, taggedBEEF: TaggedBEEF): Promise<STEAK>;
}
/**
 * Broadcasts transactions to one or more overlay topics.
 */
export default class TopicBroadcaster implements Broadcaster {
    private readonly topics;
    private readonly facilitator;
    private readonly resolver;
    private readonly requireAcknowledgmentFromAllHostsForTopics;
    private readonly requireAcknowledgmentFromAnyHostForTopics;
    private readonly requireAcknowledgmentFromSpecificHostsForTopics;
    private readonly networkPreset;
    private interestedHostsCache;
    private interestedHostsInFlight;
    private readonly interestedHostsTtlMs;
    /**
     * Constructs an instance of the SHIP broadcaster.
     *
     * @param {string[]} topics - The list of SHIP topic names where transactions are to be sent.
     * @param {SHIPBroadcasterConfig} config - Configuration options for the SHIP broadcaster.
     */
    constructor(topics: string[], config?: SHIPBroadcasterConfig);
    /**
     * Broadcasts a transaction to Overlay Services via SHIP.
     *
     * @param {Transaction} tx - The transaction to be sent.
     * @returns {Promise<BroadcastResponse | BroadcastFailure>} A promise that resolves to either a success or failure response.
     */
    broadcast(tx: Transaction): Promise<BroadcastResponse | BroadcastFailure>;
    /** Resolves the (requiredTopics, require) pair for requireAcknowledgmentFromAllHostsForTopics. */
    private resolveAllHostsRequirement;
    private checkAllHostsRequirement;
    /** Resolves the (requiredTopics, require) pair for requireAcknowledgmentFromAnyHostForTopics. */
    private resolveAnyHostRequirement;
    private checkAnyHostRequirement;
    private checkSpecificHostsRequirement;
    /**
     * Returns true if `acknowledgedTopics` satisfies the given requirement against `requiredTopics`.
     */
    private topicsMatchRequirement;
    private checkAcknowledgmentFromAllHosts;
    private checkAcknowledgmentFromAnyHost;
    private checkAcknowledgmentFromSpecificHosts;
    /**
     * Finds which hosts are interested in transactions tagged with the given set of topics.
     *
     * @returns A mapping of URLs for hosts interested in this transaction. Keys are URLs, values are which of our topics the specific host cares about.
     */
    private findInterestedHosts;
    /**
     * Performs the actual SHIP lookup to discover interested hosts.
     * @private
     */
    private fetchInterestedHosts;
}
//# sourceMappingURL=SHIPBroadcaster.d.ts.map