UNPKG

@cheqd/sdk

Version:

A TypeScript SDK built with CosmJS to interact with the cheqd network ledger

140 lines 9.68 kB
import { OfflineSigner } from '@cosmjs/proto-signing'; import { DIDModule, MinimalImportableDIDModule, DidExtension } from './modules/did.js'; import { MinimalImportableResourceModule, ResourceModule, ResourceExtension } from './modules/resource.js'; import { FeemarketModule, FeemarketExtension, MinimalImportableFeemarketModule } from './modules/feemarket.js'; import { AbstractCheqdSDKModule } from './modules/_.js'; import { CheqdSigningStargateClient } from './signer.js'; import { CheqdNetwork, IModuleMethodMap } from './types.js'; import { GasPrice } from '@cosmjs/stargate'; import { CheqdQuerier } from './querier.js'; import { FeeabstractionExtension, FeeabstractionModule, MinimalImportableFeeabstractionModule } from './modules/feeabstraction.js'; /** * Configuration options for initializing the CheqdSDK */ export interface ICheqdSDKOptions { /** Array of modules to be loaded and registered with the SDK */ modules: AbstractCheqdSDKModule[]; /** Optional querier extensions to extend query functionality */ querierExtensions?: Record<string, any>[]; /** RPC URL of the blockchain node to connect to */ rpcUrl: string; /** Network configuration (Mainnet, Testnet, etc.) */ network?: CheqdNetwork; /** Gas price configuration for transactions */ gasPrice?: GasPrice; /** List of method names that are authorized for execution */ authorizedMethods?: string[]; /** Wallet instance for signing transactions */ readonly wallet: OfflineSigner; } /** * Default SDK modules that provide core functionality for DID, Resource, Feemarket, and Fee abstraction operations */ export type DefaultCheqdSDKModules = MinimalImportableDIDModule & MinimalImportableResourceModule & MinimalImportableFeemarketModule & MinimalImportableFeeabstractionModule; /** * Main CheqdSDK class that provides a comprehensive interface for interacting with the Cheqd blockchain. * This class orchestrates modules for DID operations, resource management, fee market interactions, * and fee abstraction functionality. */ export interface CheqdSDK extends DefaultCheqdSDKModules { } /** * Main CheqdSDK class that provides a comprehensive interface for interacting with the Cheqd blockchain. * This class orchestrates modules for DID operations, resource management, fee market interactions, * and fee abstraction functionality. */ export declare class CheqdSDK { /** Map of available methods from loaded modules */ methods: IModuleMethodMap; /** Signing client for executing transactions on the blockchain */ signer: CheqdSigningStargateClient; /** Query client with extensions for reading blockchain data */ querier: CheqdQuerier & DidExtension & ResourceExtension & FeemarketExtension & FeeabstractionExtension; /** Configuration options passed during SDK initialization */ options: ICheqdSDKOptions; /** List of method names that are protected from external access */ private protectedMethods; /** * Constructs a new CheqdSDK instance with the provided configuration options. * * @param options - Configuration options for the SDK including wallet, modules, and network settings * @throws {Error} Throws an error if no wallet is provided in the options */ constructor(options: ICheqdSDKOptions); /** * Executes a method from the loaded modules with the provided parameters. * Only authorized methods can be executed through this interface. * * @template P - Type of parameters to pass to the method * @template R - Return type of the method * @param method - Name of the method to execute * @param params - Parameters to pass to the method * @returns Promise resolving to the method's return value * @throws {Error} Throws an error if the method is not authorized */ execute<P = any, R = any>(method: string, ...params: P[]): Promise<R>; /** * Loads and instantiates the provided modules, making their methods available for execution. * This method also applies mixins to make module methods accessible on the SDK instance. * * @param modules - Array of modules to load and integrate * @returns Promise resolving to the CheqdSDK instance with loaded modules * @private */ private loadModules; /** * Creates and configures a registry with types from all loaded modules. * The registry is used for encoding and decoding blockchain messages. * * @returns Configured Registry instance with all module types * @private */ private loadRegistry; /** * Establishes a connection to the blockchain querier with all necessary extensions. * Extensions provide specialized query capabilities for different modules. * * @returns Promise resolving to a CheqdQuerier instance with all extensions * @private */ private loadQuerierExtensions; /** * Builds and initializes the complete SDK instance by loading all components: * registry, querier extensions, modules, gas price configuration, and signing client. * This method must be called before the SDK can be used for blockchain operations. * * @returns Promise resolving to the fully initialized CheqdSDK instance */ build(): Promise<CheqdSDK>; } /** * Filters methods based on authorization rules and protected method restrictions. * Returns only methods that are explicitly authorized (if authorization list is provided) * and excludes protected methods from external access. * * @param methods - Map of all available methods from modules * @param authorizedMethods - List of method names that are explicitly authorized * @param protectedMethods - List of method names that should be protected from external access * @returns Filtered map containing only authorized and non-protected methods */ export declare function filterUnauthorizedMethods(methods: IModuleMethodMap, authorizedMethods: string[], protectedMethods: string[]): IModuleMethodMap; /** * Factory function that creates and builds a fully initialized CheqdSDK instance. * This is the recommended way to create an SDK instance as it handles all initialization steps. * * @param options - Configuration options for the SDK including wallet, modules, and network settings * @returns Promise resolving to a fully initialized and ready-to-use CheqdSDK instance */ export declare function createCheqdSDK(options: ICheqdSDKOptions): Promise<CheqdSDK>; export { DIDModule, ResourceModule, FeemarketModule, FeeabstractionModule }; export { AbstractCheqdSDKModule, applyMixins } from './modules/_.js'; export { DidExtension, MinimalImportableDIDModule, MsgCreateDidDocEncodeObject, MsgCreateDidDocResponseEncodeObject, MsgUpdateDidDocEncodeObject, MsgUpdateDidDocResponseEncodeObject, MsgDeactivateDidDocEncodeObject, MsgDeactivateDidDocResponseEncodeObject, contexts, defaultDidExtensionKey, protobufLiterals as protobufLiteralsDid, typeUrlMsgCreateDidDoc, typeUrlMsgCreateDidDocResponse, typeUrlMsgUpdateDidDoc, typeUrlMsgUpdateDidDocResponse, typeUrlMsgDeactivateDidDoc, typeUrlMsgDeactivateDidDocResponse, setupDidExtension, isMsgCreateDidDocEncodeObject, isMsgUpdateDidDocEncodeObject, isMsgDeactivateDidDocEncodeObject, } from './modules/did.js'; export { ResourceExtension, MinimalImportableResourceModule, defaultResourceExtensionKey, protobufLiterals as protobufLiteralsResource, typeUrlMsgCreateResource, typeUrlMsgCreateResourceResponse, setupResourceExtension, isMsgCreateResourceEncodeObject, } from './modules/resource.js'; export { FeemarketExtension, MinimalImportableFeemarketModule, DefaultGasPriceTiers, defaultFeemarketExtensionKey, defaultGasPriceTiers, protobufLiterals as protobufLiteralsFeemarket, typeUrlGasPriceResponse, typeUrlGasPricesResponse, typeUrlParamsResponse, setupFeemarketExtension, isGasPriceEncodeObject, isGasPricesEncodeObject, isParamsEncodeObject, } from './modules/feemarket.js'; export { FeeabstractionExtension, MinimalImportableFeeabstractionModule, defaultFeeabstractionExtensionKey, protobufLiterals as protobufLiteralsFeeabstraction, typeUrlMsgAddHostZone, typeUrlMsgAddHostZoneResponse, typeUrlMsgFundFeeAbsModuleAccount, typeUrlMsgFundFeeAbsModuleAccountResponse, typeUrlMsgRemoveHostZone, typeUrlMsgRemoveHostZoneResponse, typeUrlMsgUpdateHostZone, typeUrlMsgUpdateHostZoneResponse, typeUrlMsgSendQueryIbcDenomTWAP, typeUrlMsgSendQueryIbcDenomTWAPResponse, typeUrlMsgSwapCrossChain, typeUrlMsgSwapCrossChainResponse, typeUrlMsgUpdateParams, typeUrlMsgUpdateParamsResponse, setupFeeabstractionExtension, isMsgAddHostZoneEncodeObject, isMsgAddHostZoneResponseEncodeObject, isMsgFundFeeAbsModuleAccountEncodeObject, isMsgFundFeeAbsModuleAccountResponseEncodeObject, isMsgRemoveHostZoneEncodeObject, isMsgRemoveHostZoneResponseEncodeObject, isMsgUpdateHostZoneEncodeObject, isMsgUpdateHostZoneResponseEncodeObject, isMsgSendQueryIbcDenomTWAPEncodeObject, isMsgSendQueryIbcDenomTWAPResponseEncodeObject, isMsgSwapCrossChainEncodeObject, isMsgSwapCrossChainResponseEncodeObject, isMsgUpdateParamsEncodeObject, isMsgUpdateParamsResponseEncodeObject, } from './modules/feeabstraction.js'; export * from './signer.js'; export * from './querier.js'; export * from './registry.js'; export * from './types.js'; export { TImportableEd25519Key, createKeyPairRaw, createKeyPairBase64, createKeyPairHex, createVerificationKeys, createDidVerificationMethod, createDidPayload, createSignInputsFromImportableEd25519Key, validateSpecCompliantPayload, isEqualKeyValuePair, createCosmosPayerWallet, getCosmosAccount, checkBalance, toMultibaseRaw, } from './utils.js'; //# sourceMappingURL=index.d.ts.map