UNPKG

interchainjs

Version:

InterchainJS is a JavaScript library for interacting with Cosmos SDK based blockchains.

80 lines (79 loc) 2.9 kB
import { IWallet, IUniSigner } from '@interchainjs/types'; import { OfflineSigner } from '@interchainjs/cosmos'; export declare const COSMOS_AMINO: "cosmos_amino"; export declare const COSMOS_DIRECT: "cosmos_direct"; export declare const ETHEREUM_LEGACY: "ethereum_legacy"; export declare const ETHEREUM_EIP1559: "ethereum_eip1559"; export declare const SOLANA_STD: "solana_std"; export type SignerType = typeof COSMOS_AMINO | typeof COSMOS_DIRECT | typeof ETHEREUM_LEGACY | typeof ETHEREUM_EIP1559 | typeof SOLANA_STD; /** * Options for getSigner function */ export interface GetSignerOptions { /** The preferred signing method */ preferredSignType: SignerType; /** Signer-specific configuration options */ signerOptions: unknown; } /** * Signer factory function that returns the appropriate signer instance * based on the preferred sign type and configuration options. * * @template T - The specific signer type that extends IUniSigner * @param walletOrSigner - Wallet instance or OfflineSigner for signing (Solana Keypair implements IWallet) * @param options - Configuration options including preferredSignType and signer-specific settings * @returns Configured signer instance of type T * @throws Error if the sign type is unsupported or required dependencies are missing * * @example * ```typescript * import { * getSigner, * COSMOS_DIRECT, * COSMOS_AMINO, * ETHEREUM_LEGACY, * ETHEREUM_EIP1559, * SOLANA_STD * } from '@interchainjs/interchain/core'; * * // Create a Cosmos direct signer with specific type using IWallet * const directSigner = getSigner<DirectSigner>(myWallet, { * preferredSignType: COSMOS_DIRECT, * signerOptions: { * queryClient: cosmosQueryClient, * chainId: 'cosmoshub-4', * addressPrefix: 'cosmos' * } * }); * * // Create an Amino signer with specific type using OfflineAminoSigner * const aminoOfflineSigner = await wallet.toOfflineAminoSigner(); * const aminoSigner = getSigner<AminoSigner>(aminoOfflineSigner, { * preferredSignType: COSMOS_AMINO, * signerOptions: { * queryClient: cosmosQueryClient, * chainId: 'osmosis-1', * addressPrefix: 'osmo' * } * }); * * // Create an Ethereum legacy signer with specific type * const legacySigner = getSigner<LegacyEthereumSigner>(myWallet, { * preferredSignType: ETHEREUM_LEGACY, * signerOptions: { * queryClient: ethereumQueryClient, * gasMultiplier: 1.2 * } * }); * * // Create a Solana signer using any IWallet (Solana Keypair implements IWallet) * const solanaSigner = getSigner<SolanaSigner>(myKeypair, { * preferredSignType: SOLANA_STD, * signerOptions: { * queryClient: solanaQueryClient, * commitment: 'confirmed' * } * }); * ``` */ export declare function getSigner<T extends IUniSigner>(walletOrSigner: IWallet | OfflineSigner, options: GetSignerOptions): T;