Applesauce
    Preparing search index...

    A reusable NIP-60 / Cashu wallet.

    Wraps a signer, relay pool, event store and couch, exposes RxJS observable fields for wallet state and status, and async methods for the common wallet operations. Robustly loads wallet events using an initial request, negentropy sync where available, and a live subscription (see loadWalletEvents).

    const wallet = new NutWallet({ pubkey, signer, pool, eventStore, couch, autoUnlock: true });
    await wallet.start();
    wallet.balance$.subscribe((balance) => console.log(balance));
    Index

    Constructors

    Properties

    actions: ActionRunner
    autoUnlock: boolean

    Whether to automatically unlock the wallet, tokens and history as they load

    autoUnlockSub?: Subscription
    backupPromise?: Promise<void>
    balance$: ChainableObservable<Record<string, number> | undefined>

    A map of mint url to balance in sats

    busy$: Observable<boolean>

    Whether any async operation is currently running

    couch: Couch
    couch$: BehaviorSubject<Token[]> = ...
    couchTokens$: Observable<Token[]> = ...

    The tokens currently held in the couch (refreshed after operations and via refreshCouch)

    decryptionCache?: EncryptedContentCache

    An optional persistent cache of decrypted event content, consulted before decrypting and written to after

    error$: BehaviorSubject<Error | null> = ...
    errorState$: Observable<Error | null> = ...

    The most recent error (cleared at the start of each operation)

    eventStore: EventStore
    fallbackRelays?: string[]

    Static relays passed by the caller, used as a publishing fallback before the wallet loads

    history$: ChainableObservable<Casts.WalletHistory[] | undefined>

    The wallet's history events

    historyCount$: Observable<number>

    The number of history events

    loaded$: BehaviorSubject<boolean> = ...
    loading$: BehaviorSubject<boolean> = ...
    loadingState$: Observable<boolean> = ...

    Whether the initial load is in progress

    loadingSub?: Subscription
    log: Debugger
    mints: Map<string, Mint> = ...

    A cache of cashu-ts Mint instances keyed by normalized url, reused across mint list changes. A Mint caches the mint's info and owns a single WebSocket connection, so reusing instances avoids re-fetching mint info and keeps one socket per mint.

    mints$: ChainableObservable<Mint[]>

    The cached cashu-ts Mint instances for the wallet's mints (reused across mint list changes)

    mintUrls$: ChainableObservable<string[] | undefined>

    The mint urls configured on the wallet (undefined until unlocked)

    negentropy$: BehaviorSubject<Record<string, boolean>> = ...
    negentropySupport$: Observable<Record<string, boolean>> = ...

    A map of relay url to whether it supports NIP-77 negentropy sync

    operations$: BehaviorSubject<Partial<Record<NutWalletOperation, boolean>>> = ...
    operationsState$: Observable<Partial<Record<NutWalletOperation, boolean>>> = ...

    A map of operation name to whether it is currently running

    pool: RelayPool
    pubkey: string
    relays$: ChainableObservable<string[]>

    The relays used for loading and publishing wallet events

    relayStatus$: Observable<RelayStatusInfo[]>

    Per-relay connection status for the wallet's relays

    signer: ISigner
    staleTokenCount$: Observable<number>

    The number of token events that are marked deleted but still present

    staleTokens$: Observable<NostrEvent[]>

    Token events marked as deleted by a newer token event but still present (cleanup candidates)

    started$: BehaviorSubject<boolean> = ...

    The high-level lifecycle status of the wallet

    syncing$: BehaviorSubject<boolean> = ...
    syncingState$: Observable<boolean> = ...

    Whether a negentropy sync is in progress

    tokenCount$: Observable<number>

    The number of token events

    tokenRelayCoverage$: Observable<TokenRelayCoverage>

    How the wallet's token events are spread across its relays

    tokens$: ChainableObservable<Casts.WalletToken[] | undefined>

    The wallet's token events

    totalBalance$: Observable<number>

    The total balance across all mints in sats

    unlocked$: Observable<boolean>

    Whether the wallet event is currently unlocked

    unlocking: boolean = false
    useDeleteEvents: boolean

    Whether the wallet loads, subscribes to and publishes NIP-09 delete events for its events. When false the wallet completely ignores kind-5 delete events for its wallet, token and history events (see NutWalletOptions.useDeleteEvents). The loading half is fixed when the wallet starts; toggling at runtime with setUseDeleteEvents only affects publishing until the next resync.

    user: User
    wallet$: ChainableObservable<Casts.Wallet | undefined>

    The NIP-60 wallet cast (undefined until it loads)

    walletRelays$: ChainableObservable<string[] | undefined>

    The relays configured on the wallet (undefined until unlocked)

    wallets: Map<string, Promise<Wallet>> = ...

    A cache of loaded cashu Wallet instances keyed by normalized mint url (wallets are specific to this wallet)

    Methods

    • Publishes a single NIP-09 delete event for every token event that a newer token event has marked as deleted but is still present. Cleans up the spent token events left on relays when operations run with setUseDeleteEvents disabled.

      Returns Promise<void>

    • Creates a bolt11 mint quote (lightning invoice) to deposit amount sats into a mint. Pay the returned request invoice, then wait for it with waitForMintQuote and redeem it with redeemMintQuote (or use mint to do all three in one call).

      Parameters

      • mint: string
      • amount: number
      • Optionaldescription: string

      Returns Promise<MintQuoteBolt11Response>

    • Deposits funds into a mint using the given payment method, minting the resulting proofs into the wallet. This is the method-agnostic entry point; new payment methods are added as additional DepositOptions variants without changing this signature.

      For bolt11 it creates a mint quote, surfaces the invoice via onQuote, waits for it to be paid, and redeems the proofs.

      Parameters

      Returns Promise<void>

    • Returns a cached, loaded cashu CashuWallet for a mint, building it from the cached Mint. Bound to the instance so it can be passed to actions as a wallet provider.

      Parameters

      • mint: string

      Returns Promise<Wallet>

    • Returns whether the mint at a url supports a given NUT number

      Parameters

      • mint: string
      • nut: number

      Returns Promise<boolean>

    • Shared melt orchestration for every payment method. Creates a method-specific melt quote, selects proofs for the amount + fee reserve (under couch safety), melts them via the method-specific call, and keeps any remainder plus the mint's change. The two callbacks isolate the only payment-method-specific steps so new methods (bolt12, onchain) reuse this body.

      Type Parameters

      • Q extends Pick<MeltQuoteBaseResponse, "quote">

      Parameters

      • mint: string
      • createQuote: (
            cashuWallet: Wallet,
        ) => Promise<{ amount: number; feeReserve: number; quote: Q }>
      • melt: (cashuWallet: Wallet, quote: Q, send: Proof[]) => Promise<MeltProofsResponse<Q>>

      Returns Promise<MeltProofsResponse<Q>>

    • Polls a bolt11 mint quote until it is paid (fallback for mints without NIP-17 support)

      Parameters

      • cashuWallet: Wallet
      • quote: string
      • Optionaloptions: { interval?: number; signal?: AbortSignal; timeoutMs?: number }

      Returns Promise<MintQuoteBolt11Response>

    • Receives a Cashu token (encoded string or decoded Token) into the wallet

      Parameters

      • token: string | Token

      Returns Promise<void>

    • Redeems an already-paid bolt11 mint quote, minting proofs and adding them to the wallet

      Parameters

      • mint: string
      • amount: number
      • quote: string | MintQuoteBolt11Response

      Returns Promise<void>

    • Resolves the relays an event should be published to: the relays passed by the action, plus the wallet's own relays and the user's outbox relays. Read synchronously so publishing is never blocked on loading.

      Parameters

      • Optionalextra: string[]

      Returns string[]

    • Rolls every unlocked token over to a fresh cashu token. For each mint the proofs are swapped at the mint (rotating the secrets) and a single new token event is created whose del field references the rolled-over token events. Unlike consolidateTokens, this swaps the proofs at the mint even when a mint only has a single token event, so it is a good way to exercise the del reconciliation flow end to end. Every new token event is published together with a single batched delete event covering all mints, keeping signer operations to a minimum.

      Returns Promise<void>

    • Creates a Cashu token to send and returns the encoded token string.

      Parameters

      • amount: number

        the amount to send in sats

      • Optionaloptions: { mint?: string }
        • Optionalmint?: string

          restrict the send to a specific mint (otherwise any mint with enough balance is used)

      Returns Promise<string>

    • Enables or disables publishing NIP-09 delete events for old token events during spend, rollover and consolidate operations. When disabled, spent token events are left on relays until cleanupDeletedTokens removes them in a single batched delete. This only affects publishing; to also change whether the wallet loads and subscribes to delete events, call resync afterwards.

      Parameters

      • enabled: boolean

      Returns void

    • Reconciles the mint cache to a set of urls and returns the matching Mint instances. Mints that are no longer in the list have their WebSocket disconnected and are dropped.

      Parameters

      • urls: string[]

      Returns Mint[]

    • Waits for a bolt11 mint quote to be paid. Uses a NIP-17 WebSocket subscription when the mint supports it and falls back to polling the quote otherwise.

      Parameters

      • mint: string
      • quote: string
      • Optionaloptions: { interval?: number; signal?: AbortSignal; timeoutMs?: number }
        • Optionalinterval?: number

          polling interval in ms when the mint does not support NIP-17 (default 3000)

        • Optionalsignal?: AbortSignal

          aborts the wait

        • OptionaltimeoutMs?: number

          rejects after this many milliseconds

      Returns Promise<MintQuoteBolt11Response>