import { Agent, HttpDetailsResponse, QueryResponseRejected, ReplicaRejectCode, SubmitResponse } from '@dfinity/agent/lib/cjs/agent'; import { AgentError } from '@dfinity/agent/lib/cjs/errors'; import { IDL } from '@dfinity/candid'; import { PollStrategyFactory } from '@dfinity/agent/lib/cjs/polling'; import { Principal } from '@dfinity/principal'; import { RequestId } from '@dfinity/agent/lib/cjs/request_id'; import { Certificate, CreateCertificateOptions } from '@dfinity/agent/lib/cjs/certificate'; import _SERVICE, { canister_install_mode } from '@dfinity/agent/lib/cjs/canisters/management_service'; import { NodeSignature } from '@dfinity/agent/lib/cjs/agent/api'; export declare class ActorCallError extends AgentError { readonly canisterId: Principal; readonly methodName: string; readonly type: 'query' | 'update'; readonly props: Record; constructor(canisterId: Principal, methodName: string, type: 'query' | 'update', props: Record); } export declare class QueryCallRejectedError extends ActorCallError { readonly result: QueryResponseRejected; constructor(canisterId: Principal, methodName: string, result: QueryResponseRejected); } export declare class UpdateCallRejectedError extends ActorCallError { readonly requestId: RequestId; readonly response: SubmitResponse['response']; readonly reject_code: ReplicaRejectCode; readonly reject_message: string; readonly error_code?: string | undefined; constructor(canisterId: Principal, methodName: string, requestId: RequestId, response: SubmitResponse['response'], reject_code: ReplicaRejectCode, reject_message: string, error_code?: string | undefined); } /** * Configuration to make calls to the Replica. */ export interface CallConfig { /** * An agent to use in this call, otherwise the actor or call will try to discover the * agent to use. */ agent?: Agent; /** * A polling strategy factory that dictates how much and often we should poll the * read_state endpoint to get the result of an update call. */ pollingStrategyFactory?: PollStrategyFactory; /** * The canister ID of this Actor. */ canisterId?: string | Principal; /** * The effective canister ID. This should almost always be ignored. */ effectiveCanisterId?: Principal; } /** * Configuration that can be passed to customize the Actor behaviour. */ export interface ActorConfig extends CallConfig { /** * The Canister ID of this Actor. This is required for an Actor. */ canisterId: string | Principal; /** * An override function for update calls' CallConfig. This will be called on every calls. */ callTransform?(methodName: string, args: unknown[], callConfig: CallConfig): Partial | void; /** * An override function for query calls' CallConfig. This will be called on every query. */ queryTransform?(methodName: string, args: unknown[], callConfig: CallConfig): Partial | void; /** * Polyfill for BLS Certificate verification in case wasm is not supported */ blsVerify?: CreateCertificateOptions['blsVerify']; } /** * A subclass of an actor. Actor class itself is meant to be a based class. */ export type ActorSubclass> = Actor & T; /** * An actor method type, defined for each methods of the actor service. */ export interface ActorMethod { (...args: Args): Promise; withOptions(options: CallConfig): (...args: Args) => Promise; prepare(...args: Args): Promise<{ requestId: RequestId; commit: () => Promise; }>; fetchResponse(requestId: RequestId): Promise; } /** * An actor method type, defined for each methods of the actor service. */ export interface ActorMethodWithHttpDetails extends ActorMethod { (...args: Args): Promise<{ httpDetails: HttpDetailsResponse; result: Ret; }>; } /** * An actor method type, defined for each methods of the actor service. */ export interface ActorMethodExtended extends ActorMethod { (...args: Args): Promise<{ certificate?: Certificate; httpDetails?: HttpDetailsResponse; signatures?: NodeSignature[]; result: Ret; }>; prepare(...args: Args): Promise<{ requestId: RequestId; commit: () => Promise<{ certificate?: Certificate; httpDetails?: HttpDetailsResponse; signatures?: NodeSignature[]; result: Ret; }>; }>; fetchResponse(requestId: RequestId): Promise<{ certificate?: Certificate; httpDetails?: HttpDetailsResponse; signatures?: NodeSignature[]; result: Ret; }>; } export type FunctionWithArgsAndReturn = (...args: Args) => Ret; export type ActorMethodMappedWithHttpDetails = { [K in keyof T]: T[K] extends FunctionWithArgsAndReturn ? ActorMethodWithHttpDetails : never; }; export type ActorMethodMappedExtended = { [K in keyof T]: T[K] extends FunctionWithArgsAndReturn> ? ActorMethodExtended : never; }; /** * The mode used when installing a canister. */ export type CanisterInstallMode = { reinstall: null; } | { upgrade: [] | [ { skip_pre_upgrade: [] | [boolean]; } ]; } | { install: null; }; /** * Internal metadata for actors. It's an enhanced version of ActorConfig with * some fields marked as required (as they are defaulted) and canisterId as * a Principal type. */ interface ActorMetadata { service: IDL.ServiceClass; agent?: Agent; config: ActorConfig; } declare const metadataSymbol: unique symbol; export interface CreateActorClassOpts { httpDetails?: boolean; certificate?: boolean; } interface CreateCanisterSettings { freezing_threshold?: bigint; controllers?: Array; memory_allocation?: bigint; compute_allocation?: bigint; } /** * An actor base class. An actor is an object containing only functions that will * return a promise. These functions are derived from the IDL definition. */ export declare class Actor { /** * Get the Agent class this Actor would call, or undefined if the Actor would use * the default agent (global.ic.agent). * @param actor The actor to get the agent of. */ static agentOf(actor: Actor): Agent | undefined; /** * Get the interface of an actor, in the form of an instance of a Service. * @param actor The actor to get the interface of. */ static interfaceOf(actor: Actor): IDL.ServiceClass; static canisterIdOf(actor: Actor): Principal; static install(fields: { module: ArrayBuffer; mode?: canister_install_mode; arg?: ArrayBuffer; }, config: ActorConfig): Promise; static createCanister(config?: CallConfig, settings?: CreateCanisterSettings): Promise; static createAndInstallCanister(interfaceFactory: IDL.InterfaceFactory, fields: { module: ArrayBuffer; arg?: ArrayBuffer; }, config?: CallConfig): Promise; static createActorClass(interfaceFactory: IDL.InterfaceFactory, options?: CreateActorClassOpts): ActorConstructor; static createActor>(interfaceFactory: IDL.InterfaceFactory, configuration: ActorConfig): ActorSubclass; /** * Returns an actor with methods that return the http response details along with the result * @param interfaceFactory - the interface factory for the actor * @param configuration - the configuration for the actor * @deprecated - use createActor with actorClassOptions instead */ static createActorWithHttpDetails>(interfaceFactory: IDL.InterfaceFactory, configuration: ActorConfig): ActorSubclass>; /** * Returns an actor with methods that return the http response details along with the result * @param interfaceFactory - the interface factory for the actor * @param configuration - the configuration for the actor * @param actorClassOptions - options for the actor class extended details to return with the result */ static createActorWithExtendedDetails>(interfaceFactory: IDL.InterfaceFactory, configuration: ActorConfig, actorClassOptions?: CreateActorClassOpts): ActorSubclass>; private [metadataSymbol]; protected constructor(metadata: ActorMetadata); } export type ActorConstructor = new (config: ActorConfig) => ActorSubclass; export declare const ACTOR_METHOD_WITH_HTTP_DETAILS = "http-details"; export declare const ACTOR_METHOD_WITH_CERTIFICATE = "certificate"; export type ManagementCanisterRecord = _SERVICE; /** * Create a management canister actor * @param config - a CallConfig */ export declare function getManagementCanister(config: CallConfig): ActorSubclass; export declare class AdvancedActor extends Actor { constructor(metadata: ActorMetadata); } export {};