UNPKG

mochimo-mesh-api-client

Version:

A TypeScript client library for interacting with the Mochimo blockchain API

269 lines (263 loc) 8.55 kB
import { WOTSWallet } from 'mochimo-wots'; interface NetworkIdentifier { blockchain: string; network: string; } interface Currency { symbol: string; decimals: number; } declare const MCM_CURRENCY: Currency; declare const NETWORK_IDENTIFIER: NetworkIdentifier; interface Amount { value: string; currency: Currency; } interface AccountIdentifier { address: string; } interface PublicKey { hex_bytes: string; curve_type: string; } type ResolveTagResponse = { result: { address: string; amount: string; }; idempotent: boolean; }; interface TransactionIdentifier { hash: string; } interface MempoolResponse { transaction_identifiers: TransactionIdentifier[]; } interface MempoolTransactionResponse { transaction: { transaction_identifier: TransactionIdentifier; operations: Operation[]; metadata?: Record<string, any>; }; metadata?: Record<string, any>; } interface BalanceResponse { balances: { currency: { decimals: number; symbol: string; }; value: string; }[]; block_identifier: { hash: string; index: number; }; } interface RequiredPublicKey { address: string; } interface PreprocessOptions { block_to_live: number; change_pk: string; source_addr: string; } interface PreprocessResponse { options: PreprocessOptions; required_public_keys: RequiredPublicKey[]; } interface MetadataResponse { metadata: { block_to_live: number; change_pk: string; source_balance: number; }; suggested_fee: { value: string; currency: Currency; }[]; } interface SigningPayload { account_identifier: AccountIdentifier; hex_bytes: string; signature_type: string; } interface PayloadsResponse { unsigned_transaction: string; payloads: SigningPayload[]; } interface TransactionSubmitResponse { transaction_identifier: { hash: string; }; } interface BlockIdentifier { index?: number; hash?: string; } interface Operation { operation_identifier: { index: number; }; type: string; status: string; account: AccountIdentifier; amount: Amount; metadata?: Record<string, any>; } interface Operation { operation_identifier: { index: number; }; type: string; status: string; account: AccountIdentifier; amount: { value: string; currency: { symbol: string; decimals: number; }; }; } interface Transaction { transaction_identifier: TransactionIdentifier; operations: Operation[]; } interface Block { block_identifier: BlockIdentifier; parent_block_identifier: BlockIdentifier; timestamp: number; transactions: Transaction[]; } interface NetworkStatus { current_block_identifier: BlockIdentifier; genesis_block_identifier: BlockIdentifier; current_block_timestamp: number; } declare class MochimoApiClient { baseUrl: string; private networkIdentifier; constructor(baseUrl: string); private headersToObject; private handleResponse; private makeRequest; derive(publicKey: string, tag: string): Promise<any>; preprocess(operations: Operation[], metadata: any): Promise<PreprocessResponse>; metadata(options: PreprocessOptions, publicKeys: PublicKey[]): Promise<MetadataResponse>; payloads(operations: Operation[], metadata: any, publicKeys: PublicKey[]): Promise<PayloadsResponse>; combine(unsignedTransaction: string, signatures: any[]): Promise<any>; submit(signedTransaction: string): Promise<TransactionSubmitResponse>; parse(transaction: string, signed: boolean): Promise<any>; resolveTag(tag: string): Promise<ResolveTagResponse>; getAccountBalance(address: string): Promise<BalanceResponse>; getBlock(identifier: BlockIdentifier): Promise<{ block: Block; }>; getNetworkStatus(): Promise<NetworkStatus>; /** * Get all transaction identifiers in the mempool */ getMempoolTransactions(): Promise<MempoolResponse>; /** * Get a specific transaction from the mempool * @param transactionHash - The hash of the transaction to fetch */ getMempoolTransaction(transactionHash: string): Promise<MempoolTransactionResponse>; /** * Monitor the mempool for a specific transaction * @param transactionHash - The hash of the transaction to monitor * @param timeout - Maximum time to wait in milliseconds * @param interval - Check interval in milliseconds */ waitForTransaction(transactionHash: string, timeout?: number, interval?: number): Promise<MempoolTransactionResponse>; } interface TransactionParams { sourceTag: string; sourceAddress: string; destinationTag: string; amount: bigint; fee: bigint; publicKey: string; changePk: string; memo?: string; blockToLive: number; sourceBalance: bigint; } declare class TransactionBuilder { construction: MochimoApiClient; constructor(baseUrl: string); private createTransactionBytes; buildTransaction(params: { sourceTag: string; sourceAddress: string; destinationTag: string; amount: bigint; fee: bigint; publicKey: string; changePk: string; memo?: string; blockToLive: number; sourceBalance?: bigint; }): Promise<PayloadsResponse>; submitSignedTransaction(signedTransaction: string): Promise<TransactionSubmitResponse>; createSignature(publicKey: Uint8Array, unsignedTx: string, signatureBytes: Uint8Array): { signing_payload: { hex_bytes: string; signature_type: string; }; public_key: { hex_bytes: string; curve_type: string; }; signature_type: string; hex_bytes: string; }; /** * Submit a transaction and wait for it to appear in the mempool * @param signedTransaction - The signed transaction to submit * @param timeout - Maximum time to wait for mempool appearance */ submitAndMonitor(signedTransaction: string, timeout?: number): Promise<MempoolTransactionResponse>; /** * Get all transactions currently in the mempool */ getMempoolTransactions(): Promise<MempoolResponse>; /** * Get a specific transaction from the mempool */ getMempoolTransaction(transactionHash: string): Promise<MempoolTransactionResponse>; buildAndSignTransaction(sourceWallet: WOTSWallet, changeWallet: WOTSWallet, destinationTag: string, amount: bigint, fee: bigint, memo?: string, blockToLive?: number): Promise<{ buildResult: PayloadsResponse; submitResult: TransactionSubmitResponse; signedTransaction: any; }>; static createWallets(seed: string, index: number, parentWallet?: WOTSWallet): { sourceWallet: WOTSWallet; changeWallet: WOTSWallet; }; } /** * Validates a transaction memo according to MDST reference field rules: * - Contains only uppercase [A-Z], digits [0-9], dash [-] * - Groups can be multiple uppercase OR digits (not both) * - Dashes must separate different group types * - Cannot have consecutive groups of the same type * - Cannot start or end with a dash * * Valid examples: "AB-00-EF", "123-CDE-789", "ABC", "123" * Invalid examples: "AB-CD-EF", "123-456-789", "ABC-", "-123" * * @param memo - The memo string to validate * @returns true if valid, false otherwise */ declare function isValidMemo(memo: string): boolean; /** * Formats a memo string to be compatible with MDST reference field. * Adds null termination and pads with zeros to 16 bytes. * * @param memo - The memo string to format * @returns Uint8Array of 16 bytes containing the formatted memo */ declare function formatMemo(memo: string): Uint8Array; export { type AccountIdentifier, type Amount, type BalanceResponse, type Block, type BlockIdentifier, type Currency, MCM_CURRENCY, type MempoolResponse, type MempoolTransactionResponse, type MetadataResponse, MochimoApiClient, NETWORK_IDENTIFIER, type NetworkIdentifier, type NetworkStatus, type Operation, type PayloadsResponse, type PreprocessOptions, type PreprocessResponse, type PublicKey, type RequiredPublicKey, type ResolveTagResponse, type SigningPayload, type Transaction, TransactionBuilder, type TransactionIdentifier, type TransactionParams, type TransactionSubmitResponse, formatMemo, isValidMemo };