zkverifyjs
Version:
Submit proofs to zkVerify and query proof state with ease using our npm package.
143 lines • 6.34 kB
TypeScript
import { ApiPromise } from '@polkadot/api';
import { EventEmitter } from 'events';
import { OptimisticVerifyResult, ProofProcessor } from '../../types.js';
import { Groth16Config, Plonky2Config, ProofOptions, ProofType, Risc0Config, TeeConfig, UltraplonkConfig, UltrahonkConfig } from '../../config/index.js';
import { Extrinsic } from '@polkadot/types/interfaces';
import { AccountConnection, EstablishedConnection, WalletConnection } from '../../api/connection/types.js';
export * from './runtimeVersion/index.js';
import { KeyringPair } from '@polkadot/keyring/types';
import { SubmittableExtrinsic } from '@polkadot/api/types';
export interface WaitForNodeToSyncOptions {
/**
* Maximum total wait time in ms before throwing. Default 300_000 (5 min).
*/
timeoutMs?: number;
/**
* Delay between health polls in ms. Default 1000.
*/
pollIntervalMs?: number;
/**
* Optional AbortSignal to cancel the wait early. When aborted the function
* rejects with an `AbortError`.
*/
signal?: AbortSignal;
}
/**
* Waits for the zkVerify node to finish syncing. Polls `system.health` at a
* fixed interval up to a bounded deadline; throws on timeout or abort.
*
* @param api - The ApiPromise instance.
* @param options - Optional timeout, poll interval, and abort signal.
* @returns A promise that resolves when the node is synced.
* @throws {Error} If the deadline is reached before the node finishes syncing.
* @throws {DOMException} `AbortError` if the supplied signal is aborted.
*/
export declare function waitForNodeToSync(api: ApiPromise, options?: WaitForNodeToSyncOptions): Promise<void>;
export declare function getProofProcessor(proofType: ProofType): ProofProcessor;
export declare function getProofPallet(proofType: ProofType): string;
export declare function checkReadOnly(connection: AccountConnection | WalletConnection | EstablishedConnection): void;
/**
* Interprets a dry run response and returns whether it was successful and any error message.
* @param api - The Polkadot.js API instance.
* @param resultHex - The hex-encoded response from a dry run.
* @param proofType
* @returns An object containing `success` (boolean) and `message` (string).
*/
export declare function interpretDryRunResponse(api: ApiPromise, resultHex: string, proofType?: ProofType): Promise<OptimisticVerifyResult>;
/**
* Retrieves the selected account from the connection based on the provided account address.
* If no account address is provided, it defaults to the first available account.
*
* @param {AccountConnection} connection - The connection containing account information.
* @param {string | undefined} accountAddress - The optional account address to retrieve.
* @returns {KeyringPair} - The selected account.
* @throws {Error} If the account is not found.
*/
export declare const getSelectedAccount: (connection: AccountConnection, accountAddress?: string) => KeyringPair;
/**
* Retrieves the selected `KeyringPair` from the given connection if it is an `AccountConnection`.
*
* - If the connection has local `accounts` (i.e., it's an `AccountConnection`), it uses the provided `accountAddress`
* to select the appropriate account via `getSelectedAccount`.
* - If the connection is a `WalletConnection`, returns `undefined`.
*
* @param {AccountConnection | WalletConnection} connection - The connection object which may contain accounts.
* @param {string} [accountAddress] - Optional address of the account to select.
* @returns {KeyringPair | undefined} - The selected `KeyringPair` if available, otherwise `undefined`.
*/
export declare function getKeyringAccountIfAvailable(connection: AccountConnection | WalletConnection, accountAddress?: string): KeyringPair | undefined;
/**
* Extracts a human-readable error message from various error types.
*
* @param err - The error object to extract a message from.
* @returns A string message describing the error.
*/
export declare const extractErrorMessage: (err: unknown) => string;
/**
* Safe wrapper for emitting events without crashing.
*/
export declare const safeEmit: (emitter: EventEmitter, event: string, data: unknown) => void;
/**
* Type guard for Groth16Config
*/
export declare function isGroth16Config(options: ProofOptions): options is ProofOptions & {
config: Groth16Config;
};
/**
* Type guard for Plonky2Config
*/
export declare function isPlonky2Config(options: ProofOptions): options is ProofOptions & {
config: Plonky2Config;
};
/**
* Type guard for Risc0Config
*/
export declare function isRisc0Config(options: ProofOptions): options is ProofOptions & {
config: Risc0Config;
};
/**
* Type guard for Ultraplonk Config
*/
export declare function isUltraplonkConfig(options: ProofOptions): options is ProofOptions & {
config: UltraplonkConfig;
};
/**
* Type guard for Ultrahonk Config
*/
export declare function isUltrahonkConfig(options: ProofOptions): options is ProofOptions & {
config: UltrahonkConfig & {
variant: NonNullable<UltrahonkConfig['variant']>;
};
};
/**
* Type guard for versioned Ultrahonk Config
*/
export declare function isVersionedUltrahonkConfig(options: ProofOptions): options is ProofOptions & {
config: Required<UltrahonkConfig>;
};
/**
* Type guard for TEE Config
*/
export declare function isTeeConfig(options: ProofOptions): options is ProofOptions & {
config: TeeConfig & {
variant: NonNullable<TeeConfig['variant']>;
};
};
/**
* Ensures the provided extrinsic is a SubmittableExtrinsic.
* Converts a raw Extrinsic to Submittable if needed using the given API instance.
*
* @param extrinsic - A SubmittableExtrinsic or raw Extrinsic.
* @param api - An instance of ApiPromise used to convert the extrinsic.
* @returns A SubmittableExtrinsic<'promise'> ready to be signed and submitted.
*/
export declare function toSubmittableExtrinsic(extrinsic: SubmittableExtrinsic<'promise'> | Extrinsic, api: ApiPromise): SubmittableExtrinsic<'promise'>;
/**
* Asserts that the given input is a 0x-prefixed hex string.
*
* @param input - The string to validate.
* @returns The input unchanged, for ergonomic inline use.
* @throws {Error} If the input does not start with `0x`.
*/
export declare function validateHexString(input: string): string;
//# sourceMappingURL=index.d.ts.map