@bsv/sdk
Version:
BSV Blockchain Software Development Kit
87 lines • 3.62 kB
TypeScript
/**
* The question asked to the Overlay Services Engine when a consumer of state wishes to look up information.
*/
export interface LookupQuestion {
/**
* The identifier for a Lookup Service which the person asking the question wishes to use.
*/
service: string;
/**
* The query which will be forwarded to the Lookup Service.
* Its type depends on that prescribed by the Lookup Service employed.
*/
query: unknown;
}
/**
* How the Overlay Services Engine responds to a Lookup Question.
* It may comprise either an output list or a freeform response from the Lookup Service.
*/
export type LookupAnswer = {
type: 'output-list';
outputs: Array<{
beef: number[];
outputIndex: number;
context?: number[];
}>;
};
/** Default SLAP trackers */
export declare const DEFAULT_SLAP_TRACKERS: string[];
/** Default testnet SLAP trackers */
export declare const DEFAULT_TESTNET_SLAP_TRACKERS: string[];
/** Configuration options for the Lookup resolver. */
export interface LookupResolverConfig {
/**
* The network preset to use, unless other options override it.
* - mainnet: use mainnet SLAP trackers and HTTPS facilitator
* - testnet: use testnet SLAP trackers and HTTPS facilitator
* - local: directly query from localhost:8080 and a facilitator that permits plain HTTP
*/
networkPreset?: 'mainnet' | 'testnet' | 'local';
/** The facilitator used to make requests to Overlay Services hosts. */
facilitator?: OverlayLookupFacilitator;
/** The list of SLAP trackers queried to resolve Overlay Services hosts for a given lookup service. */
slapTrackers?: string[];
/** Map of lookup service names to arrays of hosts to use in place of resolving via SLAP. */
hostOverrides?: Record<string, string[]>;
/** Map of lookup service names to arrays of hosts to use in addition to resolving via SLAP. */
additionalHosts?: Record<string, string[]>;
}
/** Facilitates lookups to URLs that return answers. */
export interface OverlayLookupFacilitator {
/**
* Returns a lookup answer for a lookup question
* @param url - Overlay Service URL to send the lookup question to.
* @param question - Lookup question to find an answer to.
* @param timeout - Specifics how long to wait for a lookup answer in milliseconds.
* @returns
*/
lookup: (url: string, question: LookupQuestion, timeout?: number) => Promise<LookupAnswer>;
}
export declare class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
fetchClient: typeof fetch;
allowHTTP: boolean;
constructor(httpClient?: typeof fetch, allowHTTP?: boolean);
lookup(url: string, question: LookupQuestion, timeout?: number): Promise<LookupAnswer>;
}
/**
* Represents an SHIP transaction broadcaster.
*/
export default class LookupResolver {
private readonly facilitator;
private readonly slapTrackers;
private readonly hostOverrides;
private readonly additionalHosts;
private readonly networkPreset;
constructor(config?: LookupResolverConfig);
/**
* Given a LookupQuestion, returns a LookupAnswer. Aggregates across multiple services and supports resiliency.
*/
query(question: LookupQuestion, timeout?: number): Promise<LookupAnswer>;
/**
* Returns a list of competent hosts for a given lookup service.
* @param service Service for which competent hosts are to be returned
* @returns Array of hosts competent for resolving queries
*/
private findCompetentHosts;
}
//# sourceMappingURL=LookupResolver.d.ts.map