UNPKG

@dfinity/agent

Version:

JavaScript and TypeScript library to interact with the Internet Computer

64 lines 2.76 kB
import { type RequestId } from '../request_id.ts'; import { type CreateCertificateOptions, Certificate } from '../certificate.ts'; import { type Agent } from '../agent/api.ts'; import { Principal } from '@dfinity/principal'; export * as strategy from './strategy.ts'; import { type ReadStateRequest } from '../agent/http/types.ts'; import { RequestStatusResponseStatus } from '../agent/index.ts'; export { defaultStrategy } from './strategy.ts'; export type PollStrategy = (canisterId: Principal, requestId: RequestId, status: RequestStatusResponseStatus) => Promise<void>; export type PollStrategyFactory = () => PollStrategy; /** * Options for controlling polling behavior */ export interface PollingOptions { /** * A polling strategy that dictates how much and often we should poll the * read_state endpoint to get the result of an update call. * @default defaultStrategy() */ strategy?: PollStrategy; /** * Whether to reuse the same signed request for polling or create a new unsigned request each time. * @default false */ preSignReadStateRequest?: boolean; /** * Optional replacement function that verifies the BLS signature of a certificate. */ blsVerify?: CreateCertificateOptions['blsVerify']; /** * The request to use for polling. If not provided, a new request will be created. * This is only used if `preSignReadStateRequest` is set to false. */ request?: ReadStateRequest; } export declare const DEFAULT_POLLING_OPTIONS: PollingOptions; /** * Polls the IC to check the status of the given request then * returns the response bytes once the request has been processed. * @param agent The agent to use to poll read_state. * @param canisterId The effective canister ID. * @param requestId The Request ID to poll status for. * @param options polling options to control behavior */ export declare function pollForResponse(agent: Agent, canisterId: Principal, requestId: RequestId, options?: PollingOptions): Promise<{ certificate: Certificate; reply: Uint8Array; }>; /** * Constructs a read state request for the given paths. * If the request is already signed and has an expiry, it will be returned as is. * Otherwise, a new request will be created. * @param options The options to use for creating the request. * @param options.paths The paths to read from. * @param options.agent The agent to use to create the request. * @param options.pollingOptions The options to use for creating the request. * @returns The read state request. */ export declare function constructRequest(options: { paths: Uint8Array[][]; agent: Agent; pollingOptions: PollingOptions; }): Promise<ReadStateRequest>; //# sourceMappingURL=index.d.ts.map