import { CashuMint, CashuWallet, MeltQuoteResponse, MeltQuoteState, MintKeys, MintKeyset, MintQuoteResponse, MintQuoteState, OutputData, Proof, Token, getDecodedToken, getEncodedToken } from "@cashu/cashu-ts"; //#region types.d.ts type MintInfo = Awaited>; type ProofState = 'inflight' | 'ready' | 'spent'; interface CoreProof extends Proof { mintUrl: string; state: ProofState; } //#endregion //#region models/Mint.d.ts interface Mint { mintUrl: string; name: string; mintInfo: MintInfo; trusted: boolean; createdAt: number; updatedAt: number; } //#endregion //#region models/Keyset.d.ts interface Keyset { mintUrl: string; id: string; keypairs: Record; active: boolean; feePpk: number; updatedAt: number; } //#endregion //#region models/Counter.d.ts interface Counter { mintUrl: string; keysetId: string; counter: number; } //#endregion //#region models/MintQuote.d.ts interface MintQuote extends MintQuoteResponse { mintUrl: string; } //#endregion //#region models/MeltQuote.d.ts interface MeltQuote extends MeltQuoteResponse { mintUrl: string; } //#endregion //#region models/History.d.ts type BaseHistoryEntry = { id: string; createdAt: number; mintUrl: string; unit: string; metadata?: Record; }; type MintHistoryEntry = BaseHistoryEntry & { type: 'mint'; paymentRequest: string; quoteId: string; state: MintQuoteState; amount: number; }; type MeltHistoryEntry = BaseHistoryEntry & { type: 'melt'; quoteId: string; state: MeltQuoteState; amount: number; }; type SendHistoryEntry = BaseHistoryEntry & { type: 'send'; amount: number; token: Token; }; type ReceiveHistoryEntry = BaseHistoryEntry & { type: 'receive'; amount: number; }; type HistoryEntry = MintHistoryEntry | MeltHistoryEntry | SendHistoryEntry | ReceiveHistoryEntry; //#endregion //#region repositories/memory/MemoryCounterRepository.d.ts declare class MemoryCounterRepository implements CounterRepository { private counters; private key; getCounter(mintUrl: string, keysetId: string): Promise; setCounter(mintUrl: string, keysetId: string, counter: number): Promise; } //#endregion //#region repositories/memory/MemoryKeysetRepository.d.ts declare class MemoryKeysetRepository implements KeysetRepository { private keysetsByMint; private getMintMap; getKeysetsByMintUrl(mintUrl: string): Promise; getKeysetById(mintUrl: string, id: string): Promise; updateKeyset(keyset: Omit): Promise; addKeyset(keyset: Omit): Promise; deleteKeyset(mintUrl: string, keysetId: string): Promise; } //#endregion //#region repositories/memory/MemoryMintRepository.d.ts declare class MemoryMintRepository implements MintRepository { private mints; isTrustedMint(mintUrl: string): Promise; getMintByUrl(mintUrl: string): Promise; getAllMints(): Promise; getAllTrustedMints(): Promise; addNewMint(mint: Mint): Promise; addOrUpdateMint(mint: Mint): Promise; updateMint(mint: Mint): Promise; setMintTrusted(mintUrl: string, trusted: boolean): Promise; deleteMint(mintUrl: string): Promise; } //#endregion //#region repositories/memory/MemoryProofRepository.d.ts type ProofState$1 = 'inflight' | 'ready' | 'spent'; declare class MemoryProofRepository implements ProofRepository { private proofsByMint; private getMintMap; saveProofs(mintUrl: string, proofs: CoreProof[]): Promise; getReadyProofs(mintUrl: string): Promise; getAllReadyProofs(): Promise; getProofsByKeysetId(mintUrl: string, keysetId: string): Promise; setProofState(mintUrl: string, secrets: string[], state: ProofState$1): Promise; deleteProofs(mintUrl: string, secrets: string[]): Promise; wipeProofsByKeysetId(mintUrl: string, keysetId: string): Promise; } //#endregion //#region repositories/memory/MemoryRepositories.d.ts declare class MemoryRepositories implements Repositories { mintRepository: MintRepository; counterRepository: CounterRepository; keysetRepository: KeysetRepository; proofRepository: ProofRepository; mintQuoteRepository: MintQuoteRepository; meltQuoteRepository: MeltQuoteRepository; historyRepository: HistoryRepository; constructor(); init(): Promise; } //#endregion //#region repositories/memory/MemoryMintQuoteRepository.d.ts declare class MemoryMintQuoteRepository implements MintQuoteRepository { private readonly quotes; private makeKey; getMintQuote(mintUrl: string, quoteId: string): Promise; addMintQuote(quote: MintQuote): Promise; setMintQuoteState(mintUrl: string, quoteId: string, state: MintQuote['state']): Promise; getPendingMintQuotes(): Promise; } //#endregion //#region repositories/memory/MemoryMeltQuoteRepository.d.ts declare class MemoryMeltQuoteRepository implements MeltQuoteRepository { private readonly quotes; private makeKey; getMeltQuote(mintUrl: string, quoteId: string): Promise; addMeltQuote(quote: MeltQuote): Promise; setMeltQuoteState(mintUrl: string, quoteId: string, state: MeltQuote['state']): Promise; getPendingMeltQuotes(): Promise; } //#endregion //#region repositories/memory/MemoryHistoryRepository.d.ts type NewHistoryEntry = Omit | Omit | Omit | Omit; declare class MemoryHistoryRepository implements HistoryRepository { private readonly entries; private nextId; getPaginatedHistoryEntries(limit: number, offset: number): Promise; addHistoryEntry(history: NewHistoryEntry): Promise; getMintHistoryEntry(mintUrl: string, quoteId: string): Promise; getMeltHistoryEntry(mintUrl: string, quoteId: string): Promise; updateHistoryEntry(history: Omit | Omit): Promise; deleteHistoryEntry(mintUrl: string, quoteId: string): Promise; } //#endregion //#region repositories/index.d.ts interface MintRepository { isTrustedMint(mintUrl: string): Promise; getMintByUrl(mintUrl: string): Promise; getAllMints(): Promise; getAllTrustedMints(): Promise; addNewMint(mint: Mint): Promise; addOrUpdateMint(mint: Mint): Promise; updateMint(mint: Mint): Promise; setMintTrusted(mintUrl: string, trusted: boolean): Promise; deleteMint(mintUrl: string): Promise; } interface KeysetRepository { getKeysetsByMintUrl(mintUrl: string): Promise; getKeysetById(mintUrl: string, id: string): Promise; updateKeyset(keyset: Omit): Promise; addKeyset(keyset: Omit): Promise; deleteKeyset(mintUrl: string, keysetId: string): Promise; } interface CounterRepository { getCounter(mintUrl: string, keysetId: string): Promise; setCounter(mintUrl: string, keysetId: string, counter: number): Promise; } interface ProofRepository { saveProofs(mintUrl: string, proofs: CoreProof[]): Promise; getReadyProofs(mintUrl: string): Promise; getAllReadyProofs(): Promise; setProofState(mintUrl: string, secrets: string[], state: ProofState): Promise; deleteProofs(mintUrl: string, secrets: string[]): Promise; getProofsByKeysetId(mintUrl: string, keysetId: string): Promise; wipeProofsByKeysetId(mintUrl: string, keysetId: string): Promise; } interface MintQuoteRepository { getMintQuote(mintUrl: string, quoteId: string): Promise; addMintQuote(quote: MintQuote): Promise; setMintQuoteState(mintUrl: string, quoteId: string, state: MintQuote['state']): Promise; getPendingMintQuotes(): Promise; } interface MeltQuoteRepository { getMeltQuote(mintUrl: string, quoteId: string): Promise; addMeltQuote(quote: MeltQuote): Promise; setMeltQuoteState(mintUrl: string, quoteId: string, state: MeltQuote['state']): Promise; getPendingMeltQuotes(): Promise; } interface HistoryRepository { getPaginatedHistoryEntries(limit: number, offset: number): Promise; addHistoryEntry(history: Omit): Promise; getMintHistoryEntry(mintUrl: string, quoteId: string): Promise; getMeltHistoryEntry(mintUrl: string, quoteId: string): Promise; updateHistoryEntry(history: Omit): Promise; deleteHistoryEntry(mintUrl: string, quoteId: string): Promise; } interface Repositories { init(): Promise; mintRepository: MintRepository; counterRepository: CounterRepository; keysetRepository: KeysetRepository; proofRepository: ProofRepository; mintQuoteRepository: MintQuoteRepository; meltQuoteRepository: MeltQuoteRepository; historyRepository: HistoryRepository; } //#endregion //#region logging/Logger.d.ts type LogLevel = 'error' | 'warn' | 'info' | 'debug'; interface Logger { error(message: string, ...meta: unknown[]): void; warn(message: string, ...meta: unknown[]): void; info(message: string, ...meta: unknown[]): void; debug(message: string, ...meta: unknown[]): void; log?(level: LogLevel, message: string, ...meta: unknown[]): void; child?(bindings: Record): Logger; } //#endregion //#region infra/WsConnectionManager.d.ts interface WebSocketLike { send(data: string): void; close(code?: number, reason?: string): void; addEventListener(type: 'open' | 'message' | 'error' | 'close', listener: (event: any) => void): void; removeEventListener(type: 'open' | 'message' | 'error' | 'close', listener: (event: any) => void): void; } type WebSocketFactory = (url: string) => WebSocketLike; declare class WsConnectionManager { private readonly wsFactory; private readonly sockets; private readonly isOpenByMint; private readonly sendQueueByMint; private readonly logger?; private readonly listenersByMint; private readonly reconnectAttemptsByMint; private readonly reconnectTimeoutByMint; private paused; constructor(wsFactory: WebSocketFactory, logger?: Logger); private buildWsUrl; private ensureSocket; private scheduleReconnect; on(mintUrl: string, type: 'open' | 'message' | 'error' | 'close', listener: (event: any) => void): void; off(mintUrl: string, type: 'open' | 'message' | 'error' | 'close', listener: (event: any) => void): void; send(mintUrl: string, message: unknown): void; closeAll(): void; pause(): void; resume(): void; } //#endregion //#region infra/SubscriptionProtocol.d.ts type JsonRpcId = number; type WsRequestMethod = 'subscribe' | 'unsubscribe'; type SubscriptionKind = 'bolt11_mint_quote' | 'bolt11_melt_quote' | 'proof_state'; type UnsubscribeHandler = () => Promise; interface SubscribeParams { kind: SubscriptionKind; subId: string; filters: string[]; } interface UnsubscribeParams { subId: string; } type WsRequest = { jsonrpc: '2.0'; method: WsRequestMethod; params: SubscribeParams | UnsubscribeParams; id: JsonRpcId; }; //#endregion //#region infra/RealTimeTransport.d.ts type TransportEvent = 'open' | 'message' | 'close' | 'error'; interface RealTimeTransport { on(mintUrl: string, event: TransportEvent, handler: (evt: any) => void): void; send(mintUrl: string, req: WsRequest): void; closeAll(): void; pause(): void; resume(): void; } //#endregion //#region infra/SubscriptionManager.d.ts type SubscriptionCallback = (payload: TPayload) => void | Promise; declare class SubscriptionManager { private readonly nextIdByMint; private readonly subscriptions; private readonly activeByMint; private readonly pendingSubscribeByMint; private readonly transportByMint; private readonly logger?; private readonly messageHandlerByMint; private readonly openHandlerByMint; private readonly hasOpenedByMint; private readonly wsFactory?; private readonly capabilitiesProvider?; private paused; constructor(wsFactoryOrManager: WebSocketFactory | RealTimeTransport, logger?: Logger, capabilitiesProvider?: { getMintInfo: (mintUrl: string) => Promise; }); private getTransport; private isWebSocketAvailable; private getNextId; private ensureMessageListener; subscribe(mintUrl: string, kind: SubscriptionKind, filters: string[], onNotification?: SubscriptionCallback): Promise<{ subId: string; unsubscribe: UnsubscribeHandler; }>; addCallback(subId: string, cb: SubscriptionCallback): void; removeCallback(subId: string, cb: SubscriptionCallback): void; unsubscribe(mintUrl: string, subId: string): Promise; closeAll(): void; private reSubscribeMint; private isMintWsSupported; pause(): void; resume(): void; } //#endregion //#region infra/RequestRateLimiter.d.ts type RequestFunction = (options: { endpoint: string; requestBody?: Record; headers?: Record; } & Omit) => Promise; interface RateLimiterOptions { capacity?: number; refillPerMinute?: number; bypassPathPrefixes?: string[]; logger?: Logger; } /** * Token-bucket based request rate limiter that exposes a request-compatible API * for the cashu-ts `_customRequest` parameter. * * - Token capacity determines max burst size. * - Tokens refill continuously based on `refillPerMinute`. * - Paths starting with any configured prefix are not throttled. * - Requests are queued FIFO when tokens are exhausted. */ declare class RequestRateLimiter { private readonly capacity; private readonly refillPerMinute; private tokens; private lastRefillAt; private readonly bypassPathPrefixes; private readonly logger?; private queue; private processingTimer; constructor(options?: RateLimiterOptions); /** * The request function compatible with cashu-ts's `request(options)` signature. * It uses the global fetch under the hood. */ request: RequestFunction; private shouldBypass; private performFetch; private acquireToken; private scheduleProcessingIfNeeded; private processQueue; private refillTokens; private msUntilNextToken; } //#endregion //#region events/EventBus.d.ts type EventHandler = (payload: Payload) => void | Promise; type EventBusOptions = { onError?: (args: { event: keyof Events; payload: Events[keyof Events]; error: unknown; }) => void | Promise; concurrency?: 'sequential' | 'parallel'; throwOnError?: boolean; }; type EmitOptions = { throwOnError?: boolean; failFast?: boolean; }; declare class EventBus { private readonly options; private listeners; constructor(options?: EventBusOptions); on(event: E, handler: EventHandler): () => void; once(event: E, handler: EventHandler): () => void; off(event: E, handler: EventHandler): void; emit(event: E, payload: Events[E], options?: EmitOptions): Promise; } //#endregion //#region events/types.d.ts interface CoreEvents { 'mint:added': { mint: Mint; keysets: Keyset[]; }; 'mint:updated': { mint: Mint; keysets: Keyset[]; }; 'counter:updated': Counter; 'proofs:saved': { mintUrl: string; keysetId: string; proofs: CoreProof[]; }; 'proofs:state-changed': { mintUrl: string; secrets: string[]; state: ProofState; }; 'proofs:deleted': { mintUrl: string; secrets: string[]; }; 'proofs:wiped': { mintUrl: string; keysetId: string; }; 'mint-quote:state-changed': { mintUrl: string; quoteId: string; state: MintQuoteState; }; 'mint-quote:created': { mintUrl: string; quoteId: string; quote: MintQuoteResponse; }; 'mint-quote:added': { mintUrl: string; quoteId: string; quote: MintQuoteResponse; }; 'mint-quote:requeue': { mintUrl: string; quoteId: string; }; 'mint-quote:redeemed': { mintUrl: string; quoteId: string; quote: MintQuoteResponse; }; 'melt-quote:created': { mintUrl: string; quoteId: string; quote: MeltQuoteResponse; }; 'melt-quote:state-changed': { mintUrl: string; quoteId: string; state: MeltQuoteState; }; 'melt-quote:paid': { mintUrl: string; quoteId: string; quote: MeltQuoteResponse; }; 'send:created': { mintUrl: string; token: Token; }; 'receive:created': { mintUrl: string; token: Token; }; 'history:updated': { mintUrl: string; entry: HistoryEntry; }; } //#endregion //#region logging/ConsoleLogger.d.ts type ConsoleLoggerOptions = { level?: LogLevel; }; declare class ConsoleLogger implements Logger { private prefix; private level; private static readonly levelPriority; constructor(prefix?: string, options?: ConsoleLoggerOptions); private shouldLog; error(message: string, ...meta: unknown[]): void; warn(message: string, ...meta: unknown[]): void; info(message: string, ...meta: unknown[]): void; debug(message: string, ...meta: unknown[]): void; log(level: LogLevel, message: string, ...meta: unknown[]): void; child(bindings: Record): Logger; } //#endregion //#region services/CounterService.d.ts declare class CounterService { private readonly counterRepo; private readonly eventBus?; private readonly logger?; constructor(counterRepo: CounterRepository, logger?: Logger, eventBus?: EventBus); getCounter(mintUrl: string, keysetId: string): Promise; incrementCounter(mintUrl: string, keysetId: string, n: number): Promise<{ counter: number; mintUrl: string; keysetId: string; }>; overwriteCounter(mintUrl: string, keysetId: string, counter: number): Promise<{ mintUrl: string; keysetId: string; counter: number; }>; } //#endregion //#region services/MintService.d.ts declare class MintService { private readonly mintRepo; private readonly keysetRepo; private readonly mintAdapter; private readonly eventBus?; private readonly logger?; constructor(mintRepo: MintRepository, keysetRepo: KeysetRepository, logger?: Logger, eventBus?: EventBus); /** * Add a new mint by URL, running a single update cycle to fetch info & keysets. * If the mint already exists, it ensures it is updated. * New mints are added as untrusted by default unless explicitly specified. * * @param mintUrl - The URL of the mint to add * @param options - Optional configuration * @param options.trusted - Whether to add the mint as trusted (default: false) */ addMintByUrl(mintUrl: string, options?: { trusted?: boolean; }): Promise<{ mint: Mint; keysets: Keyset[]; }>; updateMintData(mintUrl: string): Promise<{ mint: Mint; keysets: Keyset[]; }>; isTrustedMint(mintUrl: string): Promise; ensureUpdatedMint(mintUrl: string): Promise<{ mint: Mint; keysets: Keyset[]; }>; deleteMint(mintUrl: string): Promise; getMintInfo(mintUrl: string): Promise; getAllMints(): Promise; getAllTrustedMints(): Promise; trustMint(mintUrl: string): Promise; untrustMint(mintUrl: string): Promise; private updateMint; } //#endregion //#region services/SeedService.d.ts declare class SeedService { private readonly seedGetter; private readonly seedTtlMs; private cachedSeed; private cachedUntil; private inFlight; constructor(seedGetter: () => Promise, options?: { seedTtlMs?: number; }); getSeed(): Promise; clear(): void; } //#endregion //#region services/WalletService.d.ts declare class WalletService { private walletCache; private readonly CACHE_TTL; private readonly mintService; private readonly seedService; private inFlight; private readonly logger?; private readonly requestLimiters; private readonly requestLimiterOptionsForMint?; constructor(mintService: MintService, seedService: SeedService, logger?: Logger, requestLimiterOptionsForMint?: (mintUrl: string) => Partial[0]>); getWallet(mintUrl: string): Promise; getWalletWithActiveKeysetId(mintUrl: string): Promise<{ wallet: CashuWallet; keysetId: string; keyset: MintKeyset; keys: MintKeys; }>; /** * Clear cached wallet for a specific mint URL */ clearCache(mintUrl: string): void; /** * Clear all cached wallets */ clearAllCaches(): void; /** * Force refresh mint data and get fresh wallet */ refreshWallet(mintUrl: string): Promise; private buildWallet; private getOrCreateRequestLimiter; } //#endregion //#region services/ProofService.d.ts declare class ProofService { private readonly counterService; private readonly proofRepository; private readonly eventBus?; private readonly walletService; private readonly seedService; private readonly logger?; constructor(counterService: CounterService, proofRepository: ProofRepository, walletService: WalletService, seedService: SeedService, logger?: Logger, eventBus?: EventBus); createOutputsAndIncrementCounters(mintUrl: string, amount: { keep: number; send: number; }): Promise<{ keep: OutputData[]; send: OutputData[]; }>; saveProofs(mintUrl: string, proofs: CoreProof[]): Promise; getReadyProofs(mintUrl: string): Promise; getAllReadyProofs(): Promise; setProofState(mintUrl: string, secrets: string[], state: 'inflight' | 'ready' | 'spent'): Promise; deleteProofs(mintUrl: string, secrets: string[]): Promise; wipeProofsByKeysetId(mintUrl: string, keysetId: string): Promise; selectProofsToSend(mintUrl: string, amount: number): Promise; private groupProofsByKeysetId; getProofsByKeysetId(mintUrl: string, keysetId: string): Promise; hasProofsForKeyset(mintUrl: string, keysetId: string): Promise; } //#endregion //#region services/MintQuoteService.d.ts declare class MintQuoteService { private readonly mintQuoteRepo; private readonly walletService; private readonly proofService; private readonly eventBus; private readonly logger?; constructor(mintQuoteRepo: MintQuoteRepository, walletService: WalletService, proofService: ProofService, eventBus: EventBus, logger?: Logger); createMintQuote(mintUrl: string, amount: number): Promise; redeemMintQuote(mintUrl: string, quoteId: string): Promise; addExistingMintQuotes(mintUrl: string, quotes: MintQuoteResponse[]): Promise<{ added: string[]; skipped: string[]; }>; updateStateFromRemote(mintUrl: string, quoteId: string, state: MintQuoteState): Promise; private setMintQuoteState; /** * Requeue all PAID (but not yet ISSUED) quotes for processing. * Emits `mint-quote:added` for each PAID quote so the processor can enqueue them. */ requeuePaidMintQuotes(mintUrl?: string): Promise<{ requeued: string[]; }>; } //#endregion //#region services/WalletRestoreService.d.ts declare class WalletRestoreService { private readonly proofService; private readonly counterService; private readonly logger?; private readonly restoreBatchSize; private readonly restoreGapLimit; private readonly restoreStartCounter; constructor(proofService: ProofService, counterService: CounterService, logger?: Logger); /** * Restore and persist proofs for a single keyset. * Enforces the invariant: restored proofs must be >= previously stored proofs. * Throws on any validation or persistence error. No transactions are used here. */ restoreKeyset(mintUrl: string, wallet: CashuWallet, keysetId: string): Promise; } //#endregion //#region services/MeltQuoteService.d.ts declare class MeltQuoteService { private readonly proofService; private readonly walletService; private readonly meltQuoteRepo; private readonly logger?; private readonly eventBus; constructor(proofService: ProofService, walletService: WalletService, meltQuoteRepo: MeltQuoteRepository, eventBus: EventBus, logger?: Logger); createMeltQuote(mintUrl: string, invoice: string): Promise; payMeltQuote(mintUrl: string, quoteId: string): Promise; } //#endregion //#region services/HistoryService.d.ts declare class HistoryService { private readonly historyRepository; private readonly logger?; private readonly eventBus; constructor(historyRepository: HistoryRepository, eventBus: EventBus, logger?: Logger); getPaginatedHistory(offset?: number, limit?: number): Promise; handleSendCreated(mintUrl: string, token: Token): Promise; handleReceiveCreated(mintUrl: string, token: Token): Promise; handleMintQuoteStateChanged(mintUrl: string, quoteId: string, state: MintQuoteState): Promise; handleMeltQuoteStateChanged(mintUrl: string, quoteId: string, state: MeltQuoteState): Promise; handleMeltQuoteCreated(mintUrl: string, quoteId: string, quote: MeltQuoteResponse): Promise; handleMintQuoteCreated(mintUrl: string, quoteId: string, quote: MintQuoteResponse): Promise; handleMintQuoteAdded(mintUrl: string, quoteId: string, quote: MintQuoteResponse): Promise; handleHistoryUpdated(mintUrl: string, entry: HistoryEntry): Promise; } //#endregion //#region api/WalletApi.d.ts declare class WalletApi { private mintService; private walletService; private proofService; private walletRestoreService; private eventBus; private readonly logger?; constructor(mintService: MintService, walletService: WalletService, proofService: ProofService, walletRestoreService: WalletRestoreService, eventBus: EventBus, logger?: Logger); receive(token: Token | string): Promise; send(mintUrl: string, amount: number): Promise; getBalances(): Promise<{ [mintUrl: string]: number; }>; restore(mintUrl: string): Promise; } //#endregion //#region api/QuotesApi.d.ts declare class QuotesApi { private mintQuoteService; private meltQuoteService; constructor(mintQuoteService: MintQuoteService, meltQuoteService: MeltQuoteService); createMintQuote(mintUrl: string, amount: number): Promise; redeemMintQuote(mintUrl: string, quoteId: string): Promise; createMeltQuote(mintUrl: string, invoice: string): Promise; payMeltQuote(mintUrl: string, quoteId: string): Promise; addMintQuote(mintUrl: string, quotes: MintQuoteResponse[]): Promise<{ added: string[]; skipped: string[]; }>; requeuePaidMintQuotes(mintUrl?: string): Promise<{ requeued: string[]; }>; } //#endregion //#region models/Error.d.ts declare class UnknownMintError extends Error { constructor(message: string); } declare class MintFetchError extends Error { readonly mintUrl: string; constructor(mintUrl: string, message?: string, cause?: unknown); } declare class KeysetSyncError extends Error { readonly mintUrl: string; readonly keysetId: string; constructor(mintUrl: string, keysetId: string, message?: string, cause?: unknown); } declare class ProofValidationError extends Error { constructor(message: string); } declare class ProofOperationError extends Error { readonly mintUrl: string; readonly keysetId?: string; constructor(mintUrl: string, message?: string, keysetId?: string, cause?: unknown); } /** * This error is thrown when a HTTP response is not 2XX nor a protocol error. */ declare class HttpResponseError extends Error { status: number; constructor(message: string, status: number); } /** * This error is thrown when a network request fails. */ declare class NetworkError extends Error { constructor(message: string); } /** * This error is thrown when a protocol error occurs per Cashu NUT-00 error codes. */ declare class MintOperationError extends HttpResponseError { code: number; constructor(code: number, detail: string); } //#endregion //#region api/MintApi.d.ts declare class MintApi { private readonly mintService; constructor(mintService: MintService); addMint(mintUrl: string, options?: { trusted?: boolean; }): Promise<{ mint: Mint; keysets: Keyset[]; }>; getMintInfo(mintUrl: string): Promise; isTrustedMint(mintUrl: string): Promise; getAllMints(): Promise; getAllTrustedMints(): Promise; trustMint(mintUrl: string): Promise; untrustMint(mintUrl: string): Promise; } //#endregion //#region api/SubscriptionApi.d.ts declare class SubscriptionApi { private readonly subs; private readonly logger?; constructor(subs: SubscriptionManager, logger?: Logger); awaitMintQuotePaid(mintUrl: string, quoteId: string): Promise; awaitMeltQuotePaid(mintUrl: string, quoteId: string): Promise; private awaitFirstNotification; } //#endregion //#region api/HistoryApi.d.ts declare class HistoryApi { private historyService; constructor(historyService: HistoryService); getPaginatedHistory(offset?: number, limit?: number): Promise; } //#endregion //#region plugins/types.d.ts type ServiceKey = 'mintService' | 'walletService' | 'proofService' | 'seedService' | 'walletRestoreService' | 'counterService' | 'mintQuoteService' | 'meltQuoteService' | 'historyService' | 'subscriptions' | 'eventBus' | 'logger'; interface ServiceMap { mintService: MintService; walletService: WalletService; proofService: ProofService; seedService: SeedService; walletRestoreService: WalletRestoreService; counterService: CounterService; mintQuoteService: MintQuoteService; meltQuoteService: MeltQuoteService; historyService: HistoryService; subscriptions: SubscriptionManager; eventBus: EventBus; logger: Logger; } interface PluginContext { services: Pick; } type CleanupFn = () => void | Promise; type Cleanup = void | CleanupFn | Promise; interface Plugin { name: string; required: Req; optional?: readonly ServiceKey[]; onInit?(ctx: PluginContext): Cleanup; onReady?(ctx: PluginContext): Cleanup; onDispose?(): void | Promise; } //#endregion //#region Manager.d.ts /** * Configuration options for initializing the Coco Cashu manager */ interface CocoConfig { /** Repository implementations for data persistence */ repo: Repositories; /** Function that returns the wallet seed as Uint8Array */ seedGetter: () => Promise; /** Optional logger instance (defaults to NullLogger) */ logger?: Logger; /** Optional WebSocket factory for real-time subscriptions */ webSocketFactory?: WebSocketFactory; /** Optional plugins to extend functionality */ plugins?: Plugin[]; /** * Watcher configuration (all enabled by default) * - Omit to use defaults (enabled) * - Set `disabled: true` to disable * - Provide options to customize behavior */ watchers?: { /** Mint quote watcher (enabled by default) */ mintQuoteWatcher?: { disabled?: boolean; watchExistingPendingOnStart?: boolean; }; /** Proof state watcher (enabled by default) */ proofStateWatcher?: { disabled?: boolean; }; }; /** * Processor configuration (all enabled by default) * - Omit to use defaults (enabled) * - Set `disabled: true` to disable * - Provide options to customize behavior */ processors?: { /** Mint quote processor (enabled by default) */ mintQuoteProcessor?: { disabled?: boolean; processIntervalMs?: number; maxRetries?: number; baseRetryDelayMs?: number; initialEnqueueDelayMs?: number; }; }; } /** * Initializes and configures a new Coco Cashu manager instance * @param config - Configuration options including repositories, seed, and optional features * @returns A fully initialized Manager instance */ declare function initializeCoco(config: CocoConfig): Promise; declare class Manager { readonly mint: MintApi; readonly wallet: WalletApi; readonly quotes: QuotesApi; readonly subscription: SubscriptionApi; readonly history: HistoryApi; private mintService; private walletService; private proofService; private walletRestoreService; private eventBus; private logger; readonly subscriptions: SubscriptionManager; private mintQuoteService; private mintQuoteWatcher?; private mintQuoteProcessor?; private mintQuoteRepository; private proofStateWatcher?; private meltQuoteService; private historyService; private seedService; private counterService; private readonly pluginHost; private subscriptionsPaused; private originalWatcherConfig; private originalProcessorConfig; constructor(repositories: Repositories, seedGetter: () => Promise, logger?: Logger, webSocketFactory?: WebSocketFactory, plugins?: Plugin[], watchers?: CocoConfig['watchers'], processors?: CocoConfig['processors']); on(event: E, handler: (payload: CoreEvents[E]) => void | Promise): () => void; once(event: E, handler: (payload: CoreEvents[E]) => void | Promise): () => void; use(plugin: Plugin): void; dispose(): Promise; off(event: E, handler: (payload: CoreEvents[E]) => void | Promise): void; enableMintQuoteWatcher(options?: { watchExistingPendingOnStart?: boolean; }): Promise; disableMintQuoteWatcher(): Promise; enableMintQuoteProcessor(options?: { processIntervalMs?: number; maxRetries?: number; baseRetryDelayMs?: number; initialEnqueueDelayMs?: number; }): Promise; disableMintQuoteProcessor(): Promise; waitForMintQuoteProcessor(): Promise; enableProofStateWatcher(): Promise; disableProofStateWatcher(): Promise; pauseSubscriptions(): Promise; resumeSubscriptions(): Promise; private getChildLogger; private createEventBus; private createSubscriptionManager; private buildCoreServices; private buildApis; } //#endregion //#region plugins/PluginHost.d.ts declare class PluginHost { private readonly plugins; private readonly cleanups; private services?; private initialized; private readyPhase; use(plugin: Plugin): void; init(services: ServiceMap): Promise; ready(): Promise; dispose(): Promise; private runInit; private runReady; private createContext; } //#endregion export { Cleanup, CleanupFn, CocoConfig, ConsoleLogger, type CoreProof, Counter, CounterRepository, HistoryEntry, HistoryRepository, HttpResponseError, Keyset, KeysetRepository, KeysetSyncError, type Logger, Manager, MeltHistoryEntry, MeltQuote, MeltQuoteRepository, MemoryCounterRepository, MemoryHistoryRepository, MemoryKeysetRepository, MemoryMeltQuoteRepository, MemoryMintQuoteRepository, MemoryMintRepository, MemoryProofRepository, MemoryRepositories, Mint, MintFetchError, MintHistoryEntry, MintOperationError, MintQuote, MintQuoteRepository, MintRepository, NetworkError, Plugin, PluginContext, PluginHost, ProofOperationError, ProofRepository, type ProofState, ProofValidationError, ReceiveHistoryEntry, Repositories, SendHistoryEntry, ServiceKey, ServiceMap, SubscriptionManager, UnknownMintError, type WebSocketFactory, type WebSocketLike, WsConnectionManager, getDecodedToken, getEncodedToken, initializeCoco };