import { ChainId } from '@kadena/client'; import { ICommand } from '@kadena/client'; import type { IExecutionPayloadObject } from '@kadena/client'; import { IKeyPair } from '@kadena/client'; import type { IPactCommand } from '@kadena/client'; import type { IQuicksignResponse } from '@kadena/client'; import type { ISigningRequest } from '@kadena/client'; import { IUnsignedCommand } from '@kadena/client'; import { StandardSchemaV1 } from '@standard-schema/spec'; /** * @public */ export declare type AdapterFactory = ReturnType; /** * @public */ export declare type AdapterFactoryCreator = (options: T) => { name: string; detect(): Promise; adapter(provider: IProvider): Promise; }; /** * @public * An abstract base adapter that implements common (and minimal) functionality. * Concrete adapters (e.g. Ecko, XWallet) can override or extend these behaviors. */ export declare abstract class BaseWalletAdapter implements IAdapter { abstract name: string; protected provider: IProvider; protected networkId: string; connectSchema: StandardSchemaV1; constructor(options: IBaseWalletAdapterOptions); /** * Forward a typed `request` to the underlying provider. * We cast the result to ensure it matches the method's return type. * Validates that the response is a JSON-RPC 2.0 compliant response. * Throws an error if the response does not conform to the standard. */ request(args: KdaRequestArgs): Promise; on(event: string, listener: (...args: any[]) => void): this; off(event: string, listener: (...args: any[]) => void): this; /** * Connect: call `kadena_connect`. params are defined per specific adapter. */ connect(params: StandardSchemaV1.InferInput>): Promise; /** * Disconnect: call `kadena_disconnect` with optional networkId. */ disconnect(): Promise; /** * Returns the currently active account by calling `kadena_getAccount_v1`. */ getActiveAccount(): Promise; /** * Retrieve all accounts via `kadena_getAccounts_v2`. */ getAccounts(): Promise; /** * Get the currently active network by calling `kadena_getNetwork_v1`. */ getActiveNetwork(): Promise; /** * Retrieve all networks via `kadena_getNetworks_v1`. */ getNetworks(): Promise; /** * Sign a transaction: call `kadena_signTransaction`. * Uses kadena_quicksign_v1 */ signTransaction(command: IUnsignedCommand | IUnsignedCommand[]): Promise<(IUnsignedCommand | ICommand) | (IUnsignedCommand | ICommand)[]>; /** * Sign a command: call `kadena_signCommand`. * Uses kadena_sign_v1 */ signCommand(command: IUnsignedCommand | ISigningRequestPartial): Promise; /** * Subscribe to account-change events. */ onAccountChange(cb: (newAccount: IAccountInfo) => void): void; /** * Subscribe to network-change events. */ onNetworkChange(cb: (newNetwork: INetworkInfo) => void): void; } /** @public */ export declare type CapabilityGuard = { cgName: string; cgArgs: PactValue[]; cgPactId?: string; }; export { ChainId } /** * @public */ export declare type CommandSigDatas = { cmd: string; sigs: { pubKey: string; sig: string | null; }[]; }[]; /** * Converts a parsed transaction command into an ISigningRequestPartial object. * * @param parsedTransaction - The parsed transaction command (IPactCommand) to convert. * @returns The ISigningRequestPartial representation of the transaction, ready for signing. * * @throws Will throw an error if the provided transaction is not an execution command. * * @remarks * This function first verifies that the transaction is an execution command using the isExecCommand type guard. * If the verification passes, it extracts relevant properties such as code, data, capabilities (caps), * nonce, chainId, gasLimit, gasPrice, sender, and ttl, transforming the transaction into a signing request. * * @public */ export declare const convertSignRequest: (parsedTransaction: IPactCommand) => ISigningRequestPartial; /** * Finalizes transactions by applying wallet signatures from a quick sign response. * * @param response - The quick sign response containing signed command data. * @param transactionHashes - An array of original transaction hashes. * @param transactions - An array of transactions (IUnsignedCommand or ICommand) to update with signatures. * @param isList - A boolean flag indicating if the original input was a list of transactions. * * @returns The updated transaction if a single transaction was provided, or the array of updated transactions. * * @throws Will throw an error if the response is missing, indicates a failure, * if the responses property is not an array, or if any transaction hash does not match. * * @remarks * This function validates the quick sign response by ensuring it has a successful status and that * the response contains an array of signed command outcomes. For each successful outcome, it verifies * that the outcome hash matches the corresponding transaction hash. The function then uses the * `addSignatures` helper to add the received signatures to the respective transaction. * * @public */ export declare const finalizeQuickSignTransaction: (response: IQuicksignResponse, transactionHashes: string[], transactions: (IUnsignedCommand | ICommand)[], isList: boolean) => IUnsignedCommand | (IUnsignedCommand | ICommand)[]; /** @public */ export declare type Guard = KeySet | KeySetRef | UserGuard | CapabilityGuard | ModuleGuard | PactGuard; /** * @public * Represents a Kadena account. * Conforms to KIP-0037 and KIP-0038. */ export declare interface IAccountInfo { accountName: string; label?: string; networkId: string; contract: string; guard: Guard; keyset: KeySet; existsOnChains: string[]; } /** * @public * The standardized Adapter interface. * (Wallets/Adapters implement these methods). */ export declare interface IAdapter { name: string; request(args: { method: string; [key: string]: any; }): Promise; on(event: string, listener: (...args: any[]) => void): this; off(event: string, listener: (...args: any[]) => void): this; connect(params?: unknown): Promise; disconnect(): Promise; getActiveAccount(): Promise; getAccounts(): Promise; getActiveNetwork(): Promise; getNetworks(): Promise; signTransaction(transaction: IUnsignedCommand | IUnsignedCommand[]): Promise<(IUnsignedCommand | ICommand) | (IUnsignedCommand | ICommand)[]>; signCommand(command: ISigningRequestPartial | IUnsignedCommand): Promise; onAccountChange(cb: (newAccount: IAccountInfo) => void): void; onNetworkChange(cb: (newNetwork: INetworkInfo) => void): void; } /** * @public */ export declare interface IAdapterFactoryData { name: string; detected: boolean; } /** * @public */ export declare interface IBaseWalletAdapterOptions { provider: IProvider; networkId?: string; } /** * @public */ export declare interface IBaseWalletFactoryOptions { networkId?: string; } export { ICommand } /** * @public */ export declare interface IJsonRpcError { id: number; jsonrpc: '2.0'; error: { code: number; message: string; data?: object; }; } /** * @public */ export declare interface IJsonRpcSuccess { id: number; jsonrpc: '2.0'; result: T; } /** * Core "kadena_*" method definitions (aligned with the spec). * Here we define the shape of each method's `params` and `response`. */ /** * @public */ export declare interface IKdaMethodMap { kadena_connect: { params: KdaConnectOptions; response: JsonRpcResponse; }; kadena_disconnect: { params: { networkId?: string; }; response: JsonRpcResponse; }; kadena_getAccount_v1: { params: {}; response: JsonRpcResponse; }; kadena_getAccounts_v2: { params: {}; response: JsonRpcResponse; }; kadena_getNetwork_v1: { params: {}; response: JsonRpcResponse; }; kadena_changeNetwork_v1: { params: { networkId: string; }; response: JsonRpcResponse<{ success: boolean; reason?: string; }>; }; kadena_getNetworks_v1: { params: {}; response: JsonRpcResponse; }; kadena_sign_v1: { params: ISigningRequestPartial; response: JsonRpcResponse<{ body: ICommand | IUnsignedCommand; chainId: ChainId; }>; }; kadena_quicksign_v1: { params: { commandSigDatas: CommandSigDatas; }; response: JsonRpcResponse; }; } export { IKeyPair } /** * @public * Represents a Kadena Network (e.g., mainnet01). * Conforms to KIP-0039 and KIP-0040. */ export declare interface INetworkInfo { networkName: string; networkId: string; urls: string[]; } /** * @public */ export declare interface IProvider { request(args: { method: string; [key: string]: any; }): Promise; on(event: string, listener: (...args: any[]) => void): void; off(event: string, listener: (...args: any[]) => void): void; } /** @public */ export declare const isCapabilityGuard: (guard: Guard) => guard is CapabilityGuard; /** * Type guard to determine whether a parsed transaction is an execution command. * * @param parsedTransaction - The parsed transaction command to evaluate. * @returns True if the transaction payload contains the 'exec' property, indicating an execution command. * * @remarks * This function checks if the `payload` property of the parsed transaction has an `exec` key. * If true, it narrows the type of the transaction to include IExecutionPayloadObject. * * @public */ export declare function isExecCommand(parsedTransaction: IPactCommand): parsedTransaction is IPactCommand & { payload: IExecutionPayloadObject; }; /** * @public */ export declare type ISigningRequestPartial = { caps: ISigningRequest['caps']; code: string; } & Omit, 'caps' | 'pactCode'>; /** * @public */ export declare const isJsonRpcResponse: (response: any) => boolean; /** * @public */ export declare const isJsonRpcSuccess: (response: JsonRpcResponse) => response is IJsonRpcSuccess; /** @public */ export declare const isKeySetGuard: (guard: Guard) => guard is KeySet; /** @public */ export declare const isKeySetRefGuard: (guard: Guard) => guard is KeySetRef; /** @public */ export declare const isModuleGuard: (guard: Guard) => guard is ModuleGuard; /** @public */ export declare const isPactGuard: (guard: Guard) => guard is PactGuard; /** @public */ export declare const isUserGuard: (guard: Guard) => guard is UserGuard; export { IUnsignedCommand } /** * @public */ export declare type JsonRpcResponse = IJsonRpcSuccess | IJsonRpcError; /** * @public */ export declare type KdaConnectOptions = Record; /** * @public */ export declare type KdaMethod = keyof IKdaMethodMap; /** * @public */ export declare type KdaRequestArgs = { method: M; } & { params?: IKdaMethodMap[M]['params']; }; /** @public */ export declare type KeySet = { keys: string[]; pred: string; }; /** @public */ export declare type KeySetRef = { keysetref: { ns?: string; ksn: string; }; }; /** @public */ export declare type ModuleGuard = { moduleName: ModuleName; name: string; }; /** @public */ export declare type ModuleName = { name: string; namespace?: string; }; /** * @public * An optional secretKey, ensuring that private keys can be omitted. */ export declare type OptionalKeyPair = Omit & { secretKey?: string; }; /** @public */ export declare type PactGuard = { pactId: string; name: string; }; /** @public */ export declare type PactValue = PvLiteral | PvList | Guard | PvObject | PvModRef | PvTime | PvCapToken; /** * Parses the command string of a transaction into an IPactCommand object. * * @param transaction - The transaction to parse, either an IUnsignedCommand or ICommand. * @returns The parsed transaction as an IPactCommand. * * @remarks * This function extracts the `cmd` field from the provided transaction and parses it using JSON.parse. * It assumes that the `cmd` field contains a valid JSON string representing an IPactCommand. * * @public */ export declare const parseTransactionCommand: (transaction: IUnsignedCommand | ICommand) => IPactCommand; /** * Prepares a quick sign command from one or multiple transactions. * * @param transactionList - A single transaction or an array of transactions * (IUnsignedCommand or ICommand) to prepare for quick signing. * @returns An object containing: * - commandSigDatas: Array of objects with command data and corresponding signatures. * - transactionHashes: Array of transaction hashes. * - transactions: Array of transactions processed. * - isList: Boolean indicating if the original input was an array. * * @throws \{Error\} If no transaction is provided or if there is a network mismatch between transactions. * * @remarks * The function ensures that all transactions belong to the same network. It extracts the * necessary command data and signatures from each transaction, building a list of commands * for quick signing. This is useful when you need to prepare one or more transactions for * processing via a quick-sign mechanism. * * @public */ export declare const prepareQuickSignCmd: (transactionList: IUnsignedCommand | Array) => Promise<{ commandSigDatas: { cmd: string; sigs: { pubKey: string; sig: string | null; }[]; }[]; transactionHashes: string[]; transactions: (IUnsignedCommand | ICommand)[]; isList: boolean; }>; /** * Prepares the sign command for Wallets. * * @param transaction - The transaction to be signed. It can be an IUnsignedCommand, ICommand, or ISigningRequestPartial. * * @returns An ISigningRequestPartial object ready for signing. * * @remarks * This function first checks if the provided transaction is already in the ISigningRequestPartial format. * If so, it returns the transaction immediately, avoiding any redundant transformation. Otherwise, * it parses the transaction using `parseTransactionCommand` and transforms it via `signRequest`. * * It is preferred to use the `quicksign` function for signing when possible. * * @public */ export declare function prepareSignCmd(transaction: IUnsignedCommand | ICommand | ISigningRequestPartial): ISigningRequestPartial; /** @public */ export declare type PvCapToken = { ctName: string; ctArgs: PactValue[]; }; /** @public */ export declare type PvDecimal = number | { decimal: string; }; /** @public */ export declare type PvInteger = { int: number | string; }; /** @public */ export declare type PvList = PactValue[]; /** @public */ export declare type PvLiteral = string | PvInteger | PvDecimal | boolean; /** @public */ export declare type PvModRef = { refName: string; refSpec: ModuleName[]; }; /** @public */ export declare type PvObject = { [key: string]: PactValue; }; /** @public */ export declare type PvTime = { time: string; } | { timep: string; }; export { StandardSchemaV1 } /** @public */ export declare type UserGuard = { fun: string; args: PactValue[]; }; /** * @public * A client that manages multiple wallet adapters by calling "request" with standard "kadena_*" methods. */ export declare class WalletAdapterClient { private adapterFactories; private adapters; private eventEmitter; constructor(adapters: (IAdapter | AdapterFactory)[]); isDetected(name: string): boolean; init(): Promise; getProviders(): { name: string; detected: boolean; }[]; getDetectedAdapters(): IAdapter[]; getAdapter(adapterName: string): IAdapter | undefined; onAdapterDetected(cb: (adapter: IAdapter) => void, options?: { signal?: AbortSignal; }): void; private getAdapterAsserted; /** * A generic method to call adapter.request(...) for manual calling. */ request(adapterName: string, args: { method: string; [key: string]: any; }): Promise; /** * Connect using "kadena_connect". */ connect(adapterName: IAdapter['name'], params?: unknown): Promise; /** * Disconnect using "kadena_disconnect". */ disconnect(adapterName: string): Promise; /** * Retrieve the active account via "kadena_getAccount_v1". */ getActiveAccount(adapterName: string): Promise; /** * Retrieve all accounts (if multi-account is supported) via "kadena_getAccounts_v2". * Otherwise it will return a single Account wrapped in an Array. */ getAccounts(adapterName: string): Promise; /** * Retrieve the current network via "kadena_getNetwork_v1". */ getActiveNetwork(adapterName: string): Promise; /** * Retrieve all networks (if multi-network is supported) via "kadena_getNetworks_v1". * Otherwise it will return a single Network wrapped in an Array. */ getNetworks(adapterName: string): Promise; /** * Sign transaction via "kadena_signTransaction". */ signTransaction(adapterName: string, transaction: IUnsignedCommand | IUnsignedCommand[]): Promise<(IUnsignedCommand | ICommand) | (IUnsignedCommand | ICommand)[]>; /** * Sign command via "kadena_signCommand". */ signCommand(adapterName: string, command: ISigningRequestPartial | IUnsignedCommand): Promise; /** * Subscribe to account change events. */ onAccountChange(adapterName: string, cb: (newAccount: IAccountInfo) => void): void; /** * Subscribe to network change events. */ onNetworkChange(adapterName: string, cb: (newNetwork: INetworkInfo) => void): void; } export { }