@cheqd/sdk
Version:
A TypeScript SDK built with CosmJS to interact with the cheqd network ledger
490 lines • 26.1 kB
TypeScript
import { DeliverTxResponse, QueryClient } from '@cosmjs/stargate-cjs';
import { AbstractCheqdSDKModule, MinimalImportableCheqdSDKModule } from './_';
import { CheqdSigningStargateClient } from '../signer';
import { DIDDocument, DidStdFee, IContext, ISignInputs, QueryExtensionSetup, SpecValidationResult, DIDDocumentWithMetadata, AuthenticationValidationResult, DidFeeOptions } from '../types';
import { MsgCreateDidDoc, MsgCreateDidDocResponse, MsgDeactivateDidDoc, MsgDeactivateDidDocResponse, MsgUpdateDidDoc, MsgUpdateDidDocResponse, SignInfo, QueryAllDidDocVersionsMetadataResponse, DidDocWithMetadata, DidDoc, Metadata, QueryParamsResponse, FeeRange } from '@cheqd/ts-proto-cjs/cheqd/did/v2/index';
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing-cjs';
import { CheqdQuerier } from '../querier';
import { DIDDocumentMetadata } from 'did-resolver-cjs';
import { OracleExtension } from './oracle';
import { Coin } from 'cosmjs-types/cosmos/base/v1beta1/coin';
/** Default extension key for DID-related query operations */
export declare const defaultDidExtensionKey: "did";
/**
* Standard W3C and DID-related context URIs used in DID documents.
* These contexts define the semantic meaning of properties in DID documents.
*/
export declare const contexts: {
/** W3C DID Core v1 context */
readonly W3CDIDv1: "https://www.w3.org/ns/did/v1";
/** Ed25519 Signature Suite 2020 context */
readonly W3CSuiteEd255192020: "https://w3id.org/security/suites/ed25519-2020/v1";
/** Ed25519 Signature Suite 2018 context */
readonly W3CSuiteEd255192018: "https://w3id.org/security/suites/ed25519-2018/v1";
/** JSON Web Signature Suite 2020 context */
readonly W3CSuiteJws2020: "https://w3id.org/security/suites/jws-2020/v1";
/** Linked Domains context for domain verification */
readonly LinkedDomainsContext: "https://identity.foundation/.well-known/did-configuration/v1";
};
/**
* Protobuf message type literals for DID operations.
* Used for consistent message type identification across the module.
*/
export declare const protobufLiterals: {
/** Create DID document message type */
readonly MsgCreateDidDoc: "MsgCreateDidDoc";
/** Create DID document response message type */
readonly MsgCreateDidDocResponse: "MsgCreateDidDocResponse";
/** Update DID document message type */
readonly MsgUpdateDidDoc: "MsgUpdateDidDoc";
/** Update DID document response message type */
readonly MsgUpdateDidDocResponse: "MsgUpdateDidDocResponse";
/** Deactivate DID document message type */
readonly MsgDeactivateDidDoc: "MsgDeactivateDidDoc";
/** Deactivate DID document response message type */
readonly MsgDeactivateDidDocResponse: "MsgDeactivateDidDocResponse";
};
/** Type URL for MsgCreateDidDoc messages */
export declare const typeUrlMsgCreateDidDoc: "/cheqd.did.v2.MsgCreateDidDoc";
/** Type URL for MsgCreateDidDocResponse messages */
export declare const typeUrlMsgCreateDidDocResponse: "/cheqd.did.v2.MsgCreateDidDocResponse";
/** Type URL for MsgUpdateDidDoc messages */
export declare const typeUrlMsgUpdateDidDoc: "/cheqd.did.v2.MsgUpdateDidDoc";
/** Type URL for MsgUpdateDidDocResponse messages */
export declare const typeUrlMsgUpdateDidDocResponse: "/cheqd.did.v2.MsgUpdateDidDocResponse";
/** Type URL for MsgDeactivateDidDoc messages */
export declare const typeUrlMsgDeactivateDidDoc: "/cheqd.did.v2.MsgDeactivateDidDoc";
/** Type URL for MsgDeactivateDidDocResponse messages */
export declare const typeUrlMsgDeactivateDidDocResponse: "/cheqd.did.v2.MsgDeactivateDidDocResponse";
/**
* Encode object interface for MsgCreateDidDoc messages.
* Used for type-safe message encoding in transactions.
*/
export interface MsgCreateDidDocEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgCreateDidDoc;
readonly value: Partial<MsgCreateDidDoc>;
}
/**
* Type guard function to check if an object is a MsgCreateDidDocEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgCreateDidDocEncodeObject
*/
export declare function isMsgCreateDidDocEncodeObject(obj: EncodeObject): obj is MsgCreateDidDocEncodeObject;
/**
* Type guard function to check if an object is a MsgUpdateDidDocEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateDidDocEncodeObject
*/
export declare function isMsgUpdateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject;
/**
* Type guard function to check if an object is a MsgDeactivateDidDocEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgDeactivateDidDocEncodeObject
*/
export declare function isMsgDeactivateDidDocEncodeObject(obj: EncodeObject): obj is MsgDeactivateDidDocEncodeObject;
/**
* Encode object interface for MsgCreateDidDocResponse messages.
* Used for type-safe response message handling.
*/
export interface MsgCreateDidDocResponseEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgCreateDidDocResponse;
readonly value: Partial<MsgCreateDidDocResponse>;
}
/**
* Type guard function to check if an object is a MsgCreateDidDocResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgCreateDidDocResponseEncodeObject
*/
export declare function MsgCreateDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgCreateDidDocResponseEncodeObject;
/**
* Encode object interface for MsgUpdateDidDoc messages.
* Used for type-safe message encoding in update transactions.
*/
export interface MsgUpdateDidDocEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgUpdateDidDoc;
readonly value: Partial<MsgUpdateDidDoc>;
}
/**
* Type guard function to check if an object is a MsgUpdateDidDocEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateDidDocEncodeObject
*/
export declare function MsgUpdateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject;
/**
* Encode object interface for MsgUpdateDidDocResponse messages.
* Used for type-safe response message handling in update operations.
*/
export interface MsgUpdateDidDocResponseEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgUpdateDidDocResponse;
readonly value: Partial<MsgUpdateDidDocResponse>;
}
/**
* Type guard function to check if an object is a MsgUpdateDidDocResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateDidDocResponseEncodeObject
*/
export declare function MsgUpdateDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocResponseEncodeObject;
/**
* Encode object interface for MsgDeactivateDidDoc messages.
* Used for type-safe message encoding in deactivation transactions.
*/
export interface MsgDeactivateDidDocEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgDeactivateDidDoc;
readonly value: Partial<MsgDeactivateDidDoc>;
}
/**
* Type guard function to check if an object is a MsgDeactivateDidDocEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgDeactivateDidDocEncodeObject
*/
export declare function MsgDeactivateDidDocEncodeObject(obj: EncodeObject): obj is MsgUpdateDidDocEncodeObject;
/**
* Encode object interface for MsgDeactivateDidDocResponse messages.
* Used for type-safe response message handling in deactivation operations.
*/
export interface MsgDeactivateDidDocResponseEncodeObject extends EncodeObject {
readonly typeUrl: typeof typeUrlMsgDeactivateDidDocResponse;
readonly value: Partial<MsgDeactivateDidDocResponse>;
}
/**
* Type guard function to check if an object is a MsgDeactivateDidDocResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgDeactivateDidDocResponseEncodeObject
*/
export declare function MsgDeactiveDidDocResponseEncodeObject(obj: EncodeObject): obj is MsgDeactivateDidDocResponseEncodeObject;
/** Minimal importable version of the DID module for clean external interfaces */
export type MinimalImportableDIDModule = MinimalImportableCheqdSDKModule<DIDModule>;
/**
* DID extension interface for querier functionality.
* Provides methods for querying DID documents and their versions.
*/
export type DidExtension = {
readonly [defaultDidExtensionKey]: {
/** Query a DID document by ID */
readonly didDoc: (id: string) => Promise<DidDocWithMetadata>;
/** Query a specific version of a DID document */
readonly didDocVersion: (id: string, versionId: string) => Promise<DidDocWithMetadata>;
/** Query metadata for all versions of a DID document */
readonly allDidDocVersionsMetadata: (id: string, paginationKey?: Uint8Array) => Promise<QueryAllDidDocVersionsMetadataResponse>;
/** Query DID module parameters */
readonly params: () => Promise<QueryParamsResponse>;
};
};
/**
* Sets up the DID extension for the querier client.
* Creates and configures the DID-specific query methods.
*
* @param base - Base QueryClient to extend
* @returns Configured DID extension with query methods
*/
export declare const setupDidExtension: (base: QueryClient) => DidExtension;
/**
* DID Module class providing comprehensive DID document management functionality.
* Handles creation, updates, deactivation, and querying of DID documents on the Cheqd blockchain.
*/
export declare class DIDModule extends AbstractCheqdSDKModule {
static readonly registryTypes: Iterable<[string, GeneratedType]>;
/** Base denomination for Cheqd network transactions */
static readonly baseMinimalDenom: "ncheq";
/** Base denomination in USD for Cheqd network transactions */
static readonly baseUsdDenom: "usd";
/** Default slippage tolerance in base points (BPS) */
static readonly defaultSlippageBps = 500n;
/**
* Standard fee amounts for DID operations.
* These represent the default costs for different DID document operations.
*/
static readonly fees: {
/** Default fee for creating a new DID document */
readonly DefaultCreateDidDocFee: {
readonly amount: "50000000000";
readonly denom: "ncheq";
};
/** Default fee for updating an existing DID document */
readonly DefaultUpdateDidDocFee: {
readonly amount: "25000000000";
readonly denom: "ncheq";
};
/** Default fee for deactivating a DID document */
readonly DefaultDeactivateDidDocFee: {
readonly amount: "10000000000";
readonly denom: "ncheq";
};
/** Default fee for creating a new DID document in USD */
readonly DefaultCreateDidDocFeeUSD: {
readonly amount: "2000000000000000000";
readonly denom: "usd";
};
/** Default fee for updating an existing DID document in USD */
readonly DefaultUpdateDidDocFeeUSD: {
readonly amount: "1000000000000000000";
readonly denom: "usd";
};
/** Default fee for deactivating a DID document in USD */
readonly DefaultDeactivateDidDocFeeUSD: {
readonly amount: "400000000000000000";
readonly denom: "usd";
};
};
/**
* Standard gas limits for DID operations.
* These represent the default gas limits for different DID document operations.
*/
static readonly gasLimits: {
/** Gas limit for creating a new DID document */
readonly CreateDidDocGasLimit: "360000";
/** Gas limit for updating an existing DID document */
readonly UpdateDidDocGasLimit: "360000";
/** Gas limit for deactivating a DID document */
readonly DeactivateDidDocGasLimit: "360000";
};
/** Querier extension setup function for DID operations */
static readonly querierExtensionSetup: QueryExtensionSetup<DidExtension>;
/** Querier instance with DID extension capabilities */
querier: CheqdQuerier & DidExtension & OracleExtension;
private oracleFeesAvailability?;
/**
* Constructs a new DID module instance.
*
* @param signer - Signing client for blockchain transactions
* @param querier - Querier client with DID extension for data retrieval
*/
constructor(signer: CheqdSigningStargateClient, querier: CheqdQuerier & DidExtension & OracleExtension);
/**
* Gets the registry types for DID message encoding/decoding.
*
* @returns Iterable of [typeUrl, GeneratedType] pairs for the registry
*/
getRegistryTypes(): Iterable<[string, GeneratedType]>;
/**
* Gets the querier extension setup for DID operations.
*
* @returns Query extension setup function for DID functionality
*/
getQuerierExtensionSetup(): QueryExtensionSetup<DidExtension>;
/**
* Creates a new DID document transaction on the blockchain.
* Validates the DID payload and authentication before submission.
*
* @param signInputs - Signing inputs or pre-computed signatures for the transaction
* @param didPayload - DID document payload to create
* @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 versionId - Optional version identifier for the DID document
* @param feeOptions - Optional fee options for the transaction
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
* @throws Error if DID payload is not spec compliant or authentication is invalid
*/
createDidDocTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, versionId?: string, feeOptions?: DidFeeOptions, context?: IContext): Promise<DeliverTxResponse>;
/**
* Updates an existing DID document transaction on the blockchain.
* Validates the updated DID payload and handles key rotation scenarios.
*
* @param signInputs - Signing inputs or pre-computed signatures for the transaction
* @param didPayload - Updated DID document payload
* @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 versionId - Optional version identifier for the updated DID document
* @param feeOptions - Optional fee options for the transaction
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
* @throws Error if DID payload is not spec compliant or authentication is invalid
*/
updateDidDocTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, versionId?: string, feeOptions?: DidFeeOptions, context?: IContext): Promise<DeliverTxResponse>;
/**
* Deactivates an existing DID document transaction on the blockchain.
* Validates authentication and creates a deactivation transaction.
*
* @param signInputs - Signing inputs or pre-computed signatures for the transaction
* @param didPayload - DID document payload containing the ID to deactivate
* @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 versionId - Optional version identifier for the deactivation
* @param feeOptions - Optional fee options for the transaction
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
* @throws Error if DID payload is not spec compliant or authentication is invalid
*/
deactivateDidDocTx(signInputs: ISignInputs[] | SignInfo[], didPayload: DIDDocument, address: string, fee?: DidStdFee | 'auto' | number, memo?: string, versionId?: string, feeOptions?: DidFeeOptions, context?: IContext): Promise<DeliverTxResponse>;
/**
* Queries a DID document by its identifier.
* Retrieves the latest version of the DID document with metadata.
*
* @param id - DID identifier to query
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the DID document with metadata
*/
queryDidDoc(id: string, context?: IContext): Promise<DIDDocumentWithMetadata>;
/**
* Queries a specific version of a DID document by its identifier and version ID.
*
* @param id - DID identifier to query
* @param versionId - Specific version identifier to retrieve
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the DID document version with metadata
*/
queryDidDocVersion(id: string, versionId: string, context?: IContext): Promise<DIDDocumentWithMetadata>;
/**
* Queries metadata for all versions of a DID document.
* Retrieves version history information for a specific DID.
*
* @param id - DID identifier to query version metadata for
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to array of version metadata and pagination info
*/
queryAllDidDocVersionsMetadata(id: string, context?: IContext): Promise<{
didDocumentVersionsMetadata: DIDDocumentMetadata[];
pagination: QueryAllDidDocVersionsMetadataResponse['pagination'];
}>;
private shouldUseOracleFees;
/**
* Queries the DID module parameters from the blockchain.
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the DID module parameters
*/
queryDidParams(context?: IContext): Promise<QueryParamsResponse>;
/**
* Generates oracle-powered fees for creating a DID document.
*
* @param feePayer - Address of the account that will pay the transaction fees
* @param granter - Optional address of the account granting fee payment permissions
* @param feeOptions - Options for fetching oracle fees
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the fee configuration for DID document creation with oracle fees
*/
generateCreateDidDocFees(feePayer: string, granter?: string, feeOptions?: DidFeeOptions, context?: IContext): Promise<DidStdFee>;
/**
* Generates oracle-powered fees for updating a DID document.
*
* @param feePayer - Address of the account that will pay the transaction fees
* @param granter - Optional address of the account granting fee payment permissions
* @param feeOptions - Options for fetching oracle fees
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the fee configuration for DID document update with oracle fees
*/
generateUpdateDidDocFees(feePayer: string, granter?: string, fetchOptions?: DidFeeOptions, context?: IContext): Promise<DidStdFee>;
/** Generates oracle-powered fees for deactivating a DID document.
*
* @param feePayer - Address of the account that will pay the transaction fees
* @param granter - Optional address of the account granting fee payment permissions
* @param feeOptions - Options for fetching oracle fees
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the fee configuration for DID document deactivation with oracle fees
*/
generateDeactivateDidDocFees(feePayer: string, granter?: string, feeOptions?: DidFeeOptions, context?: IContext): Promise<DidStdFee>;
/**
* Gets the fee range for a specific DID operation from the module parameters.
* @param feeParams - DID module fee parameters
* @param operation - DID operation type ('create', 'update', 'deactivate')
* @param feeOptions - Options for fee retrieval
* @returns Promise resolving to the fee range for the specified operation
*/
getPriceRangeFromDidParams(feeParams: QueryParamsResponse, operation: 'create' | 'update' | 'deactivate', feeOptions?: DidFeeOptions): Promise<FeeRange>;
/**
* Calculates the oracle fee amount based on the provided fee range and options.
* @param feeRange - Fee range for the DID operation
* @param feeOptions - Options for fee calculation
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the calculated fee amount as a Coin
*/
private calculateOracleFeeAmount;
/**
* Applies slippage to a given coin amount based on the specified basis points.
* @param coin - Coin amount to apply slippage to
* @param slippageBps - Slippage in basis points (bps)
* @returns Coin with adjusted amount after applying slippage
*/
static applySlippageToCoin(coin: Coin, slippageBps: number): Coin;
/**
* Checks if a fee range represents a fixed fee (minAmount equals maxAmount).
* @param feeRange - Fee range to check
* @returns True if the fee range is fixed, false otherwise
*/
static isFixedRange(feeRange: FeeRange): boolean;
/**
* Validates a DID document against the Cheqd specification requirements.
* Ensures all required fields are present and verification methods are supported.
*
* @param didDocument - DID document to validate
* @returns Promise resolving to validation result with protobuf conversion or error details
*/
static validateSpecCompliantPayload(didDocument: DIDDocument): Promise<SpecValidationResult>;
/**
* Converts a protobuf DID document to a specification-compliant DID document format.
* Handles context inclusion, verification method formatting, and service denormalization.
*
* @param protobufDidDocument - Protobuf DID document to convert
* @returns Promise resolving to a spec-compliant DID document
*/
static toSpecCompliantPayload(protobufDidDocument: DidDoc): Promise<DIDDocument>;
/**
* Converts protobuf metadata to specification-compliant DID document metadata format.
* Handles date formatting and optional field normalization.
*
* @param protobufDidDocument - Protobuf metadata to convert
* @returns Promise resolving to spec-compliant DID document metadata
*/
static toSpecCompliantMetadata(protobufDidDocument: Metadata): Promise<DIDDocumentMetadata>;
/**
* Validates that provided signatures match the authentication requirements in a DID document.
* Checks signature count, authentication presence, and controller authorization.
*
* @param didDocument - DID document containing authentication requirements
* @param signatures - Array of signatures to validate against authentication
* @param querier - Optional querier for retrieving external controller documents
* @param externalControllersDidDocuments - Optional pre-loaded external controller documents
* @returns Promise resolving to validation result with error details if invalid
*/
static validateAuthenticationAgainstSignatures(didDocument: DIDDocument, signatures: readonly SignInfo[], querier?: CheqdQuerier & DidExtension, externalControllersDidDocuments?: DIDDocument[]): Promise<AuthenticationValidationResult>;
/**
* Validates authentication against signatures for key rotation scenarios.
* Handles validation during DID document updates where keys may have changed.
*
* @param didDocument - Updated DID document to validate
* @param signatures - Array of signatures to validate
* @param querier - Querier for retrieving previous DID document and controllers
* @param previousDidDocument - Optional previous version of the DID document
* @param externalControllersDidDocuments - Optional pre-loaded external controller documents
* @returns Promise resolving to validation result with controller documents and previous document
*/
static validateAuthenticationAgainstSignaturesKeyRotation(didDocument: DIDDocument, signatures: readonly SignInfo[], querier: CheqdQuerier & DidExtension, previousDidDocument?: DIDDocument, externalControllersDidDocuments?: DIDDocument[]): Promise<AuthenticationValidationResult>;
/**
* Generates standard fees for creating a DID document.
*
* @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 DID document creation
*/
static generateCreateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee>;
/**
* Generates fee configuration for DID document update transactions.
* Uses default update fees and gas requirements.
*
* @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 DID document updates
*/
static generateUpdateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee>;
/**
* Generates fee configuration for DID document deactivation transactions.
* Uses default deactivation fees and gas requirements.
*
* @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 DID document deactivation
*/
static generateDeactivateDidDocFees(feePayer: string, granter?: string): Promise<DidStdFee>;
}
//# sourceMappingURL=did.d.ts.map