ic-reactor
    Preparing search index...

    Interface Agent

    An Agent able to make calls and queries to a Replica.

    interface Agent {
        rootKey: null | Uint8Array<ArrayBufferLike>;
        getPrincipal(): Promise<types.Principal>;
        createReadStateRequest(
            options: utils.agent.ReadStateOptions,
            identity?: types.Identity,
        ): Promise<unknown>;
        readState(
            effectiveCanisterId: string | types.Principal,
            options: utils.agent.ReadStateOptions,
            identity?: types.Identity,
            request?: unknown,
        ): Promise<utils.agent.ReadStateResponse>;
        call(
            canisterId: string | types.Principal,
            fields: utils.agent.CallOptions,
        ): Promise<utils.agent.SubmitResponse>;
        status(): Promise<utils.candid.JsonObject>;
        query(
            canisterId: string | types.Principal,
            options: utils.agent.QueryFields,
            identity?: types.Identity | Promise<types.Identity>,
        ): Promise<utils.agent.ApiQueryResponse>;
        fetchRootKey(): Promise<Uint8Array<ArrayBufferLike>>;
        invalidateIdentity(): void;
        replaceIdentity(identity: types.Identity): void;
    }

    Implemented by

    Index

    Properties

    rootKey: null | Uint8Array<ArrayBufferLike>

    Methods

    • Returns the principal ID associated with this agent (by default). It only shows the principal of the default identity in the agent, which is the principal used when calls don't specify it.

      Returns Promise<types.Principal>

    • Send a read state query to the replica. This includes a list of paths to return, and will return a Certificate. This will only reject on communication errors, but the certificate might contain less information than requested.

      Parameters

      • effectiveCanisterId: string | types.Principal

        A Canister ID related to this call.

      • options: utils.agent.ReadStateOptions

        The options for this call.

      • Optionalidentity: types.Identity

        Identity for the call. If not specified, uses the instance identity.

      • Optionalrequest: unknown

        The request to send in case it has already been created.

      Returns Promise<utils.agent.ReadStateResponse>

    • Query the status endpoint of the replica. This normally has a few fields that corresponds to the version of the replica, its root public key, and any other information made public.

      Returns Promise<utils.candid.JsonObject>

      A JsonObject that is essentially a record of fields from the status endpoint.

    • By default, the agent is configured to talk to the main Internet Computer, and verifies responses using a hard-coded public key.

      This function will instruct the agent to ask the endpoint for its public key, and use that instead. This is required when talking to a local test instance, for example.

      Only use this when you are not talking to the main Internet Computer, otherwise you are prone to man-in-the-middle attacks! Do not call this function by default.

      Returns Promise<Uint8Array<ArrayBufferLike>>

    • If an application needs to invalidate an identity under certain conditions, an Agent may expose an invalidateIdentity method. Invoking this method will set the inner identity used by the Agent to null.

      A use case for this would be - after a certain period of inactivity, a secure application chooses to invalidate the identity of any HttpAgent instances. An invalid identity can be replaced by Agent.replaceIdentity

      Returns void

    • If an application needs to replace an identity under certain conditions, an Agent may expose a replaceIdentity method. Invoking this method will set the inner identity used by the Agent to a newly provided identity.

      A use case for this would be - after authenticating using @dfinity/auth-client, you can replace the AnonymousIdentity of your Actor with a DelegationIdentity.

      Actor.agentOf(defaultActor).replaceIdentity(await authClient.getIdentity());
      

      Parameters

      Returns void