@cheqd/sdk
Version:
A TypeScript SDK built with CosmJS to interact with the cheqd network ledger
205 lines • 10.7 kB
TypeScript
import { AbstractCheqdSDKModule, MinimalImportableCheqdSDKModule } from './_';
import { CheqdSigningStargateClient } from '../signer';
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing-cjs';
import { DidStdFee, IContext, ISignInputs, QueryExtensionSetup } from '../types';
import { Metadata, MsgCreateResource, MsgCreateResourcePayload, QueryCollectionResourcesResponse, ResourceWithMetadata } from '@cheqd/ts-proto-cjs/cheqd/resource/v2';
import { DeliverTxResponse, QueryClient } from '@cosmjs/stargate-cjs';
import { SignInfo } from '@cheqd/ts-proto-cjs/cheqd/did/v2/index';
import { CheqdQuerier } from '../querier';
/** Default extension key for resource-related query operations */
export declare const defaultResourceExtensionKey: "resource";
/**
* Protobuf message type literals for resource operations.
* Used for consistent message type identification across the module.
*/
export declare const protobufLiterals: {
/** Create resource message type */
readonly MsgCreateResource: "MsgCreateResource";
/** Create resource response message type */
readonly MsgCreateResourceResponse: "MsgCreateResourceResponse";
};
/** Type URL for MsgCreateResource messages */
export declare const typeUrlMsgCreateResource: "/cheqd.resource.v2.MsgCreateResource";
/** Type URL for MsgCreateResourceResponse messages */
export declare const typeUrlMsgCreateResourceResponse: "/cheqd.resource.v2.MsgCreateResourceResponse";
/**
* Encode object interface for MsgCreateResource messages.
* Used for type-safe message encoding in resource creation transactions.
*/
export interface MsgCreateResourceEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgCreateResource;
readonly value: Partial<MsgCreateResource>;
}
/**
* Type guard function to check if an object is a MsgCreateResourceEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgCreateResourceEncodeObject
*/
export declare function isMsgCreateResourceEncodeObject(obj: EncodeObject): obj is MsgCreateResourceEncodeObject;
/** Minimal importable version of the resource module for clean external interfaces */
export type MinimalImportableResourceModule = MinimalImportableCheqdSDKModule<ResourceModule>;
/**
* Resource extension interface for querier functionality.
* Provides methods for querying resources and their metadata.
*/
export type ResourceExtension = {
readonly [defaultResourceExtensionKey]: {
/** Query a specific resource by collection and resource ID */
readonly resource: (collectionId: string, resourceId: string) => Promise<ResourceWithMetadata>;
/** Query metadata for a specific resource */
readonly resourceMetadata: (collectionId: string, resourceId: string) => Promise<Metadata>;
/** Query all resources in a collection with pagination support */
readonly collectionResources: (collectionId: string, paginationKey?: Uint8Array) => Promise<QueryCollectionResourcesResponse>;
};
};
/**
* Sets up the resource extension for the querier client.
* Creates and configures the resource-specific query methods.
*
* @param base - Base QueryClient to extend
* @returns Configured resource extension with query methods
*/
export declare const setupResourceExtension: (base: QueryClient) => ResourceExtension;
/**
* Resource Module class providing comprehensive linked resource functionality.
* Handles creation, querying, and metadata management of resources linked to DID documents.
*/
export declare class ResourceModule extends AbstractCheqdSDKModule {
static readonly registryTypes: Iterable<[string, GeneratedType]>;
/** Base denomination for Cheqd network transactions */
static readonly baseMinimalDenom: "ncheq";
/**
* Standard fee amounts for different resource types.
* Fees vary based on resource content type and processing requirements.
*/
static readonly fees: {
/** Default fee for creating image resources */
readonly DefaultCreateResourceImageFee: {
readonly amount: "10000000000";
readonly denom: "ncheq";
};
/** Default fee for creating JSON resources */
readonly DefaultCreateResourceJsonFee: {
readonly amount: "10000000000";
readonly denom: "ncheq";
};
/** Default fee for creating other types of resources */
readonly DefaultCreateResourceDefaultFee: {
readonly amount: "10000000000";
readonly denom: "ncheq";
};
};
/** Querier extension setup function for resource operations */
static readonly querierExtensionSetup: QueryExtensionSetup<ResourceExtension>;
/** Querier instance with resource extension capabilities */
/** Querier instance with resource extension capabilities */
querier: CheqdQuerier & ResourceExtension;
/**
* Constructs a new resource module instance.
*
* @param signer - Signing client for blockchain transactions
* @param querier - Querier client with resource extension for data retrieval
*/
constructor(signer: CheqdSigningStargateClient, querier: CheqdQuerier & ResourceExtension);
/**
* Gets the registry types for resource message encoding/decoding.
*
* @returns Iterable of [typeUrl, GeneratedType] pairs for the registry
*/
getRegistryTypes(): Iterable<[string, GeneratedType]>;
/**
* Gets the querier extension setup for resource operations.
*
* @returns Query extension setup function for resource functionality
*/
getQuerierExtensionSetup(): QueryExtensionSetup<ResourceExtension>;
/**
* Signs a resource payload with provided signature inputs.
* Creates a complete signed resource message ready for blockchain submission.
*
* @param payload - Resource payload to sign
* @param signInputs - Signing inputs or pre-computed signatures
* @returns Promise resolving to the signed resource message
*/
static signPayload(payload: MsgCreateResourcePayload, signInputs: ISignInputs[] | SignInfo[]): Promise<MsgCreateResource>;
/**
* Creates a linked resource transaction on the blockchain.
* Handles automatic fee calculation based on resource content type and size.
*
* @param signInputs - Signing inputs or pre-computed signatures for the transaction
* @param resourcePayload - Resource payload containing data and metadata
* @param address - Address of the account submitting the transaction
* @param fee - Transaction fee configuration or 'auto' for automatic calculation
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
* @throws Error if linked resource data is empty when automatic fee calculation is requested
*/
createLinkedResourceTx(signInputs: ISignInputs[] | SignInfo[], resourcePayload: Partial<MsgCreateResourcePayload>, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, context?: IContext): Promise<DeliverTxResponse>;
/**
* Queries a specific linked resource by collection and resource ID.
* Retrieves the complete resource data along with its metadata.
*
* @param collectionId - ID of the collection containing the resource
* @param resourceId - ID of the resource to query
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the resource with metadata
*/
queryLinkedResource(collectionId: string, resourceId: string, context?: IContext): Promise<ResourceWithMetadata>;
/**
* Queries metadata for a specific linked resource.
* Retrieves only the metadata without the resource content data.
*
* @param collectionId - ID of the collection containing the resource
* @param resourceId - ID of the resource to query metadata for
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the resource metadata
*/
queryLinkedResourceMetadata(collectionId: string, resourceId: string, context?: IContext): Promise<Metadata>;
/**
* Queries all resources in a collection with pagination support.
* Retrieves a list of all resources belonging to a specific collection.
*
* @param collectionId - ID of the collection to query resources for
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the collection resources response with pagination
*/
queryLinkedResources(collectionId: string, context?: IContext): Promise<QueryCollectionResourcesResponse>;
/**
* Reads and determines the MIME type of resource content.
* Analyzes the content to identify the appropriate MIME type for fee calculation and validation.
*
* @param content - Resource content as byte array
* @returns Promise resolving to the detected MIME type string
*/
static readMimeType(content: Uint8Array): Promise<string>;
/**
* Generates fee configuration for image resource creation transactions.
* Uses higher gas limits appropriate for image processing and storage.
*
* @param feePayer - Address of the account that will pay the transaction fees
* @param granter - Optional address of the account granting fee payment permissions
* @returns Promise resolving to the fee configuration for image resources
*/
static generateCreateResourceImageFees(feePayer: string, granter?: string): Promise<DidStdFee>;
/**
* Generates fee configuration for JSON resource creation transactions.
* Uses gas limits optimized for JSON data processing and validation.
*
* @param feePayer - Address of the account that will pay the transaction fees
* @param granter - Optional address of the account granting fee payment permissions
* @returns Promise resolving to the fee configuration for JSON resources
*/
static generateCreateResourceJsonFees(feePayer: string, granter?: string): Promise<DidStdFee>;
/**
* Generates fee configuration for default resource creation transactions.
* Uses standard gas limits for generic resource types and binary data.
*
* @param feePayer - Address of the account that will pay the transaction fees
* @param granter - Optional address of the account granting fee payment permissions
* @returns Promise resolving to the fee configuration for default resources
*/
static generateCreateResourceDefaultFees(feePayer: string, granter?: string): Promise<DidStdFee>;
}
//# sourceMappingURL=resource.d.ts.map