@bug-fix/drand-client
Version:
A client to the drand randomness beacon network.
152 lines (143 loc) • 5.08 kB
text/typescript
declare function roundAt(time: number, chain: ChainInfo): number;
declare function roundTime(chain: ChainInfo, round: number): number;
type HttpOptions = {
userAgent?: string;
headers?: Record<string, string>;
};
declare class HttpChain implements Chain {
baseUrl: string;
private options;
private httpOptions;
constructor(baseUrl: string, options?: ChainOptions, httpOptions?: HttpOptions);
info(): Promise<ChainInfo>;
}
declare class HttpCachingChain implements Chain {
baseUrl: string;
private options;
private chain;
private cachedInfo?;
constructor(baseUrl: string, options?: ChainOptions);
info(): Promise<ChainInfo>;
}
declare class HttpChainClient implements ChainClient {
private someChain;
options: ChainOptions;
httpOptions: HttpOptions;
constructor(someChain: Chain, options?: ChainOptions, httpOptions?: HttpOptions);
get(roundNumber: number): Promise<RandomnessBeacon>;
latest(): Promise<RandomnessBeacon>;
chain(): Chain;
}
interface SpeedTest {
start: () => void;
stop: () => void;
average: () => number;
}
type SpeedTestEntry = {
test: SpeedTest;
url: string;
};
declare class FastestNodeClient implements ChainClient {
baseUrls: Array<string>;
options: ChainOptions;
private speedTestIntervalMs;
speedTests: Array<SpeedTestEntry>;
speedTestHttpOptions: {
userAgent: string;
};
constructor(baseUrls: Array<string>, options?: ChainOptions, speedTestIntervalMs?: number);
latest(): Promise<RandomnessBeacon>;
get(roundNumber: number): Promise<RandomnessBeacon>;
chain(): Chain;
start(): void;
current(): Chain;
stop(): void;
}
declare class MultiBeaconNode implements DrandNode {
baseUrl: string;
private options;
constructor(baseUrl: string, options?: ChainOptions);
chains(): Promise<Array<Chain>>;
health(): Promise<HealthCheckResponse>;
}
declare function defaultClient(): HttpChainClient;
declare function quicknetClient(): HttpChainClient;
declare function fastnetClient(): HttpChainClient;
declare function testnetDefaultClient(): HttpChainClient;
declare function testnetQuicknetClient(): HttpChainClient;
interface DrandNode {
chains(): Promise<Array<Chain>>;
health(): Promise<HealthCheckResponse>;
}
interface Chain {
baseUrl: string;
info(): Promise<ChainInfo>;
}
type ChainOptions = {
disableBeaconVerification: boolean;
noCache: boolean;
chainVerificationParams?: ChainVerificationParams;
};
declare const defaultChainOptions: ChainOptions;
type ChainVerificationParams = {
chainHash: string;
publicKey: string;
};
type HealthCheckResponse = {
status: number;
current: number;
expected: number;
};
interface ChainClient {
options: ChainOptions;
latest(): Promise<RandomnessBeacon>;
get(roundNumber: number): Promise<RandomnessBeacon>;
chain(): Chain;
}
declare function fetchBeacon(client: ChainClient, roundNumber?: number): Promise<RandomnessBeacon>;
declare function fetchBeaconByTime(client: ChainClient, time: number): Promise<RandomnessBeacon>;
declare function watch(client: ChainClient, abortController: AbortController, options?: WatchOptions): AsyncGenerator<RandomnessBeacon>;
type WatchOptions = {
retriesOnFailure: number;
};
type ChainInfo = {
public_key: string;
period: number;
genesis_time: number;
hash: string;
groupHash: string;
schemeID: string;
metadata: {
beaconID: string;
};
};
type RandomnessBeacon = G2ChainedBeacon | G2UnchainedBeacon | G1UnchainedBeacon | G1RFC9380Beacon;
type G2ChainedBeacon = {
round: number;
randomness: string;
signature: string;
previous_signature: string;
};
type G2UnchainedBeacon = {
round: number;
randomness: string;
signature: string;
_phantomg2?: never;
};
type G1UnchainedBeacon = {
round: number;
randomness: string;
signature: string;
_phantomg1?: never;
};
type G1RFC9380Beacon = {
round: number;
randomness: string;
signature: string;
_phantomg19380?: never;
};
declare function isChainedBeacon(value: any, info: ChainInfo): value is G2ChainedBeacon;
declare function isUnchainedBeacon(value: any, info: ChainInfo): value is G2UnchainedBeacon;
declare function isG1G2SwappedBeacon(value: any, info: ChainInfo): value is G1UnchainedBeacon;
declare function isG1Rfc9380(value: any, info: ChainInfo): value is G1RFC9380Beacon;
export { type Chain, type ChainClient, type ChainInfo, type ChainOptions, type ChainVerificationParams, type DrandNode, FastestNodeClient, type G1RFC9380Beacon, type G1UnchainedBeacon, type G2ChainedBeacon, type G2UnchainedBeacon, type HealthCheckResponse, HttpCachingChain, HttpChain, HttpChainClient, MultiBeaconNode, type RandomnessBeacon, type WatchOptions, defaultChainOptions, defaultClient, fastnetClient, fetchBeacon, fetchBeaconByTime, isChainedBeacon, isG1G2SwappedBeacon, isG1Rfc9380, isUnchainedBeacon, quicknetClient, roundAt, roundTime, testnetDefaultClient, testnetQuicknetClient, watch };