import { type Agent, type ApiQueryResponse, type CallOptions, HttpAgent, type Identity, type InputTargetPrincipal, type QueryFields, type ReadStateOptions, type ReadStateResponse, type SubmitResponse, type UpdateResult } from '@icp-sdk/core/agent'; import { type JsonObject } from '@icp-sdk/core/candid'; import { Principal } from '@icp-sdk/core/principal'; import type { Signer, Transport } from '../index.js'; /** Options for creating a {@link SignerAgent}. */ export interface SignerAgentOptions { /** The {@link Signer} used to send ICRC-49 canister call requests. */ signer: Signer; /** The principal of the account on whose behalf canister calls are made. */ account: Principal; /** * An {@link HttpAgent} used for fetching the root key and status. * @default A new HttpAgent connected to the IC mainnet. */ agent?: HttpAgent; /** * Source of randomness for nonces bound to upgraded query calls. * @default globalThis.crypto */ crypto?: Pick; } /** * Error thrown by {@link SignerAgent} when a signer returns an invalid * response or certificate validation fails. */ export declare class SignerAgentError extends Error { } /** * An {@link Agent} implementation that routes canister calls through a * {@link Signer} for user approval. Drop-in replacement for {@link HttpAgent} * when canister calls need to be signed by an external signer. * * Calls are sent to the signer via ICRC-49, and the returned content map * and certificate are validated before being returned to the caller. * * Use {@link SignerAgent.create} or {@link SignerAgent.createSync} to * construct an instance — the constructor is private. * @example * ```ts * const agent = await SignerAgent.create({ signer, account }); * const result = await agent.update(canisterId, { methodName: "transfer", arg, effectiveCanisterId: canisterId }); * ``` */ export declare class SignerAgent implements Agent { #private; private constructor(); /** The root key used for certificate verification. */ get rootKey(): Uint8Array; /** The signer this agent routes calls through. */ get signer(): Signer; /** * Creates a new SignerAgent, asynchronously initializing the * underlying HttpAgent if one is not provided. * @param options - The signer agent options. */ static create(options: SignerAgentOptions): Promise>; /** * Creates a new SignerAgent synchronously. * Use this when you already have an HttpAgent or don't need async initialization. * @param options - The signer agent options. */ static createSync(options: SignerAgentOptions): SignerAgent; /** * Sends a canister call through the signer. * Returns the request ID and a synthetic HTTP response. * @param canisterId - The target canister principal or its text representation. * @param fields - The call options including method name and arguments. */ call(canisterId: Principal | string, fields: CallOptions): Promise; /** * Executes a canister update call and returns the certified result. * Combines {@link call} with certificate validation and reply extraction. * @param canisterId - The target canister principal or its text representation. * @param fields - The call options including method name and arguments. * @param _pollingOptions - Ignored. The signer already returns the * certificate with the reply in a single round-trip. */ update(canisterId: Principal | string, fields: CallOptions, _pollingOptions?: unknown): Promise; /** * Executes a query by upgrading it to a canister call through the signer. * The signer signs and submits the call, and the reply is extracted * from the certified response. * @param canisterId - The target canister principal or its text representation. * @param options - The query fields including method name and arguments. * @param _identity - Ignored. The signer manages identity internally. */ query(canisterId: Principal | string, options: QueryFields, _identity?: Identity | Promise): Promise; /** Fetches the IC root key via the underlying HttpAgent. */ fetchRootKey(): Promise; /** Returns the account principal this agent makes calls on behalf of. */ getPrincipal(): Promise; /** * @internal * @param _options - The read state options. * @param _identity - The identity to use for the request. */ createReadStateRequest(_options: ReadStateOptions, _identity?: Identity): Promise; /** * Returns the raw certificate for a previously completed call. * The certificate is deleted after being read (single-use). * * Only supports `request_status` paths for request IDs that were * returned by a prior {@link call}, {@link update}, or {@link query}. * @param _effectiveTarget - The effective target of the read state request (unused). * @param options - The read state options containing paths to look up. * @param _identity - The identity to use (unused). * @param _request - The request object (unused). */ readState(_effectiveTarget: InputTargetPrincipal, options: ReadStateOptions, _identity?: Identity | Promise, _request?: unknown): Promise; /** Queries the IC replica status via the underlying HttpAgent. */ status(): Promise; /** * Replaces the account principal used for subsequent calls. * @param account - The new account principal to use for subsequent calls. */ replaceAccount(account: Principal): void; }