@slide-computer/signer-agent
Version:
Initiate transactions with signers on the Internet Computer
69 lines (68 loc) • 2.84 kB
TypeScript
import { type Agent, type ApiQueryResponse, HttpAgent, type Identity, type QueryFields, type ReadStateOptions, type ReadStateResponse, type SubmitResponse } from "@dfinity/agent";
import { type JsonObject } from "@dfinity/candid";
import { Principal } from "@dfinity/principal";
import { type Signer } from "@slide-computer/signer";
export interface SignerAgentOptions<T extends Pick<Signer, "callCanister">> {
/**
* Signer instance that should be used to send ICRC-25 JSON-RPC messages
*/
signer: T;
/**
* Principal of account that should be used to make calls
*/
account: Principal;
/**
* Optional, used to fetch root key
* @default uses {@link HttpAgent} by default
*/
agent?: HttpAgent;
/**
* Optional, delay in milliseconds used to detect parallel calls and turn them into a single batch call
* @default 20
*/
scheduleDelay?: number;
/**
* Optional, validation used with batch call canister
* @default null
*/
validation?: {
canisterId: Principal;
method: string;
} | null;
}
export declare class SignerAgentError extends Error {
constructor(message: string);
}
export declare class SignerAgent<T extends Pick<Signer, "callCanister" | "openChannel" | "supportedStandards" | "batchCallCanister"> = Signer> implements Agent {
#private;
private constructor();
get rootKey(): ArrayBuffer;
get signer(): T;
static create<T extends Pick<Signer, "callCanister" | "openChannel" | "supportedStandards" | "batchCallCanister">>(options: SignerAgentOptions<T>): Promise<SignerAgent<T>>;
static createSync<T extends Pick<Signer, "callCanister" | "openChannel" | "supportedStandards" | "batchCallCanister">>(options: SignerAgentOptions<T>): SignerAgent<T>;
execute(): Promise<void>;
call(canisterId: Principal | string, options: {
methodName: string;
arg: ArrayBuffer;
effectiveCanisterId?: Principal | string;
}): Promise<SubmitResponse>;
fetchRootKey(): Promise<ArrayBuffer>;
getPrincipal(): Promise<Principal>;
query(canisterId: Principal | string, options: QueryFields): Promise<ApiQueryResponse>;
createReadStateRequest(_options: ReadStateOptions): Promise<any>;
readState(_canisterId: Principal | string, options: ReadStateOptions, _identity?: Identity | Promise<Identity>, _request?: any): Promise<ReadStateResponse>;
status(): Promise<JsonObject>;
replaceAccount(account: Principal): void;
replaceValidation(validation?: {
canisterId: Principal;
method: string;
}): void;
/**
* Enable manual triggering of canister calls execution
*/
batch(): void;
/**
* Clear scheduled canister calls and switch back to automatic canister calls execution
*/
clear(): void;
}