/** * * This file contains helper functions for quicksigning and signing transactions. * */ import type { ICommand, IExecutionPayloadObject, IPactCommand, IQuicksignResponse, IUnsignedCommand } from '@kadena/client'; import type { ISigningRequestPartial } from '../types'; /** * 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; /** * 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; }; /** * 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; /** * 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; /** * 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; }>; /** * 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)[];