UNPKG

@cheqd/sdk

Version:

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

79 lines 5.69 kB
import { EncodeObject, OfflineSigner } from '@cosmjs/proto-signing-cjs'; import { DeliverTxResponse, GasPrice, HttpEndpoint, SigningStargateClient, SigningStargateClientOptions, SignerData } from '@cosmjs/stargate-cjs'; import { Tendermint37Client } from '@cosmjs/tendermint-rpc-cjs'; import { MsgCreateDidDocPayload, SignInfo, MsgUpdateDidDocPayload, MsgDeactivateDidDocPayload, VerificationMethod } from '@cheqd/ts-proto-cjs/cheqd/did/v2'; import { DIDDocument, DidStdFee, ISignInputs, MessageBatch, TSignerAlgo, TxExtension } from './types'; import { Signer } from 'did-jwt-cjs'; import { SignerInfo, TxRaw } from 'cosmjs-types-cjs/cosmos/tx/v1beta1/tx'; import { SignMode } from 'cosmjs-types-cjs/cosmos/tx/signing/v1beta1/signing'; import { Any } from 'cosmjs-types-cjs/google/protobuf/any'; import { Coin } from 'cosmjs-types-cjs/cosmos/base/v1beta1/coin'; import { CheqdQuerier } from './querier'; export declare function calculateDidFee(gasLimit: number, gasPrice: string | GasPrice): DidStdFee; export declare function makeSignerInfos(signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number; }>, signMode: SignMode): SignerInfo[]; export declare function makeDidAuthInfoBytes(signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number; }>, feeAmount: readonly Coin[], gasLimit: number, feePayer: string, signMode?: SignMode): Uint8Array; export declare class CheqdSigningStargateClient extends SigningStargateClient { private didSigners; private readonly _gasPrice; private readonly _signer; private readonly endpoint?; static readonly maxGasLimit: number; static connectWithSigner(endpoint: string | HttpEndpoint, signer: OfflineSigner, options?: (SigningStargateClientOptions & { endpoint?: string; }) | undefined): Promise<CheqdSigningStargateClient>; constructor(cometClient: Tendermint37Client | undefined, signer: OfflineSigner, options?: SigningStargateClientOptions & { endpoint?: string; }); signAndBroadcast(signerAddress: string, messages: readonly EncodeObject[], fee: DidStdFee | 'auto' | number, memo?: string): Promise<DeliverTxResponse>; sign(signerAddress: string, messages: readonly EncodeObject[], fee: DidStdFee, memo: string, explicitSignerData?: SignerData): Promise<TxRaw>; private _signDirect; /** * Broadcasts a signed transaction to the network and monitors its inclusion in a block, * with support for retrying on failure and graceful timeout handling. * * ## Optimizations over base implementation: * - Implements a retry policy (`maxRetries`, default: 3) to handle transient broadcast errors. * - Prevents double spend by reusing the exact same signed transaction (immutable `Uint8Array`). * - Tracks and returns the last known transaction hash (`txId`), even in the case of timeout or failure. * - Throws a `TimeoutError` if the transaction is not found within `timeoutMs`, attaching the `txHash` if known. * - Polling frequency and timeout are customizable via `pollIntervalMs` and `timeoutMs` parameters. * * @param tx - The signed transaction bytes to broadcast. * @param timeoutMs - Maximum duration (in milliseconds) to wait for block inclusion. Defaults to 60,000 ms. * @param pollIntervalMs - Polling interval (in milliseconds) when checking for transaction inclusion. Defaults to 3,000 ms. * @param maxRetries - Maximum number of times to retry `broadcastTxSync` on failure. Defaults to 3. * * @returns A `Promise` that resolves to `DeliverTxResponse` upon successful inclusion in a block. * @throws `BroadcastTxError` if the transaction is rejected by the node during CheckTx. * @throws `TimeoutError` if the transaction is not found on-chain within the timeout window. Includes `txHash` if available. */ broadcastTx(tx: Uint8Array, timeoutMs?: number, pollIntervalMs?: number, maxRetries?: number): Promise<DeliverTxResponse>; /** * Broadcasts a signed transaction to the network without monitoring it. * * If broadcasting is rejected by the node for some reason (e.g. because of a CheckTx failure), * an error is thrown. * * If the transaction is broadcasted, a `string` containing the hash of the transaction is returned. The caller then * usually needs to check if the transaction was included in a block and was successful. * * @returns Returns the hash of the transaction */ broadcastTxSync(tx: Uint8Array): Promise<string>; simulate(signerAddress: string, messages: readonly EncodeObject[], memo: string | undefined): Promise<number>; constructSimulateExtension(querier: CheqdQuerier): Promise<TxExtension>; batchMessages(messages: readonly EncodeObject[], signerAddress: string, memo?: string, maxGasLimit?: number): Promise<MessageBatch>; checkDidSigners(verificationMethods?: Partial<VerificationMethod>[]): Promise<TSignerAlgo>; getDidSigner(verificationMethodId: string, verificationMethods: Partial<VerificationMethod>[]): Promise<(secretKey: Uint8Array) => Signer>; signCreateDidDocTx(signInputs: ISignInputs[], payload: MsgCreateDidDocPayload): Promise<SignInfo[]>; signUpdateDidDocTx(signInputs: ISignInputs[], payload: MsgUpdateDidDocPayload, externalControllers?: DIDDocument[], previousDidDocument?: DIDDocument): Promise<SignInfo[]>; signDeactivateDidDocTx(signInputs: ISignInputs[], payload: MsgDeactivateDidDocPayload, verificationMethod: VerificationMethod[]): Promise<SignInfo[]>; static signIdentityTx(signBytes: Uint8Array, signInputs: ISignInputs[]): Promise<SignInfo[]>; } //# sourceMappingURL=signer.d.ts.map