@cashu/cashu-ts
    Preparing search index...

    Class CashuWallet

    Class that represents a Cashu wallet. This class should act as the entry point for this library.

    Index

    Constructors

    • Parameters

      • mint: CashuMint

        Cashu mint instance is used to make api calls.

      • Optionaloptions: {
            bip39seed?: Uint8Array<ArrayBufferLike>;
            denominationTarget?: number;
            keepFactory?: OutputDataFactory;
            keys?: MintKeys | MintKeys[];
            keysets?: MintKeyset[];
            logger?: Logger;
            mintInfo?: GetInfoResponse;
            unit?: string;
        }
        • Optionalbip39seed?: Uint8Array<ArrayBufferLike>

          BIP39 seed for deterministic secrets.

        • OptionaldenominationTarget?: number

          Target number proofs per denomination (default: see

        • OptionalkeepFactory?: OutputDataFactory

          A function that will be used by all parts of the library that produce proofs to be kept (change, etc.). This can lead to poor performance, in which case the seed should be directly provided.

        • Optionalkeys?: MintKeys | MintKeys[]

          Public keys from the mint (will be fetched from mint if not provided)

        • Optionalkeysets?: MintKeyset[]

          Keysets from the mint (will be fetched from mint if not provided)

        • Optionallogger?: Logger
        • OptionalmintInfo?: GetInfoResponse

          Mint info from the mint (will be fetched from mint if not provided)

        • Optionalunit?: string

          Optionally set unit (default is 'sat')

      Returns CashuWallet

      DEFAULT_DENOMINATION_TARGET)

    Properties

    mint: CashuMint

    Accessors

    Methods

    • Restores batches of deterministic proofs until no more signatures are returned from the mint.

      Parameters

      • OptionalgapLimit: number = 300

        The amount of empty counters that should be returned before restoring ends (defaults to 300). Default is 300

      • OptionalbatchSize: number = 100

        The amount of proofs that should be restored at a time (defaults to 100). Default is 100

      • Optionalcounter: number = 0

        The counter that should be used as a starting point (defaults to 0). Default is 0

      • OptionalkeysetId: string

        Which keysetId to use for the restoration. If none is passed the instance's default one will be used.

      Returns Promise<{ lastCounterWithSignature?: number; proofs: Proof[] }>

    • Get an array of the states of proofs from the mint (as an array of CheckStateEnum's)

      Parameters

      • proofs: Proof[]

        (only the secret field is required)

      Returns Promise<ProofState[]>

    • Requests a mint quote from the mint that is locked to a public key.

      Parameters

      • amount: number

        Amount requesting for mint.

      • pubkey: string

        Public key to lock the quote to.

      • Optionaldescription: string

        Optional description for the mint quote.

      Returns Promise<LockedMintQuoteResponse>

      The mint will return a mint quote with a Lightning invoice for minting tokens of the specified amount and unit. The quote will be locked to the specified pubkey.

    • Requests a melt quote from the mint. Response returns amount and fees for a given unit in order to pay a Lightning invoice.

      Parameters

      • invoice: string

        LN invoice that needs to get a fee estimate.

      Returns Promise<MeltQuoteResponse>

      The mint will create and return a melt quote for the invoice with an amount and fee reserve.

    • Requests a mint quote form the mint. Response returns a Lightning payment request for the requested given amount and unit.

      Parameters

      • amount: number

        Amount requesting for mint.

      • Optionaldescription: string

        Optional description for the mint quote.

      Returns Promise<MintQuoteResponse>

      The mint will return a mint quote with a Lightning invoice for minting tokens of the specified amount and unit.

    • Requests a multi path melt quote from the mint.

      Parameters

      • invoice: string

        LN invoice that needs to get a fee estimate.

      • millisatPartialAmount: number

      Returns Promise<MeltQuoteResponse>

      The mint will create and return a melt quote for the invoice with an amount and fee reserve.

    • Get all active keys from the mint and set the keyset with the lowest fees as the active wallet keyset.

      Returns Promise<MintKeys[]>

      Keyset.

    • Calculates the fees based on inputs for a given keyset.

      Parameters

      • nInputs: number

        Number of inputs.

      • keysetId: string

        KeysetId used to lookup input_fee_ppk

      Returns number

      Fee amount.

    • Calculates the fees based on inputs (proofs)

      Parameters

      • proofs: Proof[]

        Input proofs to calculate fees for.

      Returns number

      Fee amount.

      Throws an error if the proofs keyset is unknown.

    • Get public keys from the mint. If keys were already fetched, it will return those.

      If keysetId is set, it will fetch and return that specific keyset. Otherwise, we select an active keyset with the unit of the wallet.

      Parameters

      • OptionalkeysetId: string

        Optional keysetId to get keys for.

      • OptionalforceRefresh: boolean

      Returns Promise<MintKeys>

      Keyset.

    • Get information about the mint.

      Returns Promise<MintInfo>

      Mint info.

    • Get stored information about the mint or request it if not loaded.

      Returns Promise<MintInfo>

      Mint info.

    • Load mint information, keysets and keys. This function can be called if no keysets are passed in the constructor.

      Returns Promise<void>

    • Mint proofs for a given mint quote.

      Parameters

      • amount: number

        Amount to request.

      • quote: MintQuoteResponse

        ID of mint quote (when quote is a string)

      • Optionaloptions: MintProofOptions & { privateKey: string }

        Optional parameters for configuring the Mint Proof operation.

      Returns Promise<Proof[]>

      Proofs.

    • Mint proofs for a given mint quote.

      Parameters

      • amount: number

        Amount to request.

      • quote: string

        ID of mint quote (when quote is a string)

      • Optionaloptions: MintProofOptions

        Optional parameters for configuring the Mint Proof operation.

      Returns Promise<Proof[]>

      Proofs.

    • Register a callback to be called whenever a melt quote's state changes.

      Parameters

      • quoteId: string
      • callback: (payload: MeltQuoteResponse) => void

        Callback function that will be called whenever a melt quote state changes.

      • errorCallback: (e: Error) => void

      Returns Promise<SubscriptionCanceller>

    • Register a callback to be called when a single melt quote gets paid.

      Parameters

      • quoteIds: string[]
      • callback: (payload: MeltQuoteResponse) => void

        Callback function that will be called when this melt quote gets paid.

      • errorCallback: (e: Error) => void

      Returns Promise<SubscriptionCanceller>

    • Register a callback to be called when a single mint quote gets paid.

      Parameters

      • quoteId: string

        Mint quote id that should be subscribed to.

      • callback: (payload: MintQuoteResponse) => void

        Callback function that will be called when this mint quote gets paid.

      • errorCallback: (e: Error) => void

      Returns Promise<SubscriptionCanceller>

    • Register a callback to be called whenever a mint quote's state changes.

      Parameters

      • quoteIds: string[]

        List of mint quote IDs that should be subscribed to.

      • callback: (payload: MintQuoteResponse) => void

        Callback function that will be called whenever a mint quote state changes.

      • errorCallback: (e: Error) => void

      Returns Promise<SubscriptionCanceller>

    • Register a callback to be called whenever a subscribed proof state changes.

      Parameters

      • proofs: Proof[]

        List of proofs that should be subscribed to.

      • callback: (payload: ProofState & { proof: Proof }) => void

        Callback function that will be called whenever a proof's state changes.

      • errorCallback: (e: Error) => void

      Returns Promise<SubscriptionCanceller>

    • Receive an encoded or raw Cashu token (only supports single tokens. It will only process the first token in the token array)

      Parameters

      • token: string | Token

        Cashu token, either as string or decoded.

      • Optionaloptions: ReceiveOptions

        Optional configuration for token processing.

      Returns Promise<Proof[]>

      New token with newly created proofs, token entries that had errors.

    • Regenerates.

      Parameters

      • start: number

        Set starting point for count (first cycle for each keyset should usually be 0)

      • count: number

        Set number of blinded messages that should be generated.

      • Optionaloptions: RestoreOptions
        • OptionalkeysetId?: string

      Returns Promise<{ lastCounterWithSignature?: number; proofs: Proof[] }>

    • Selects proofs to send based on amount and fee inclusion.

      Parameters

      • proofs: Proof[]

        Array of Proof objects available to select from.

      • amountToSend: number

        The target amount to send.

      • includeFees: boolean = false

        Optional boolean to include fees; Default: false.

      Returns SendResponse

      SendResponse containing proofs to keep and proofs to send.

      Uses an adapted Randomized Greedy with Local Improvement (RGLI) algorithm, which has a time complexity O(n log n) and space complexity O(n).

    • Send proofs of a given amount, by providing at least the required amount of proofs.

      Parameters

      • amount: number

        Amount to send.

      • proofs: Proof[]

        Array of proofs (accumulated amount of proofs must be >= than amount)

      • Optionaloptions: SendOptions

        Optional parameters for configuring the send operation.

      Returns Promise<SendResponse>

    • Splits and creates sendable tokens if no amount is specified, the amount is implied by the cumulative amount of all proofs if both amount and preference are set, but the preference cannot fulfill the amount, then we use the default split.

      Parameters

      • amount: number
      • proofs: Proof[]
      • Optionaloptions: SwapOptions

        Optional parameters for configuring the swap operation.

      Returns Promise<SendResponse>

      Promise of the change- and send-proofs.