Class CashuWallet

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

Hierarchy

  • CashuWallet

Constructors

  • Parameters

    • mint: CashuMint

      Cashu mint instance is used to make api calls

    • Optional options: {
          keys?: MintKeys;
          mnemonicOrSeed?: string | Uint8Array;
          unit?: string;
      }
      • Optional keys?: MintKeys
      • Optional mnemonicOrSeed?: string | Uint8Array
      • Optional unit?: string

    Returns CashuWallet

Properties

_keys: undefined | MintKeys
_seed: undefined | Uint8Array
_unit: string = 'sat'
mint: CashuMint

Accessors

Methods

  • returns proofs that are already spent (use for keeping wallet state clean)

    Type Parameters

    • T extends {
          secret: string;
      }

    Parameters

    • proofs: T[]

      (only the 'Y' field is required)

    Returns Promise<T[]>

  • construct proofs from

    Params

    promises,

    Params

    rs,

    Params

    secrets, and

    Params

    keyset

    Parameters

    • promises: SerializedBlindedSignature[]

      array of serialized blinded signatures

    • rs: bigint[]

      arrays of binding factors

    • secrets: Uint8Array[]

      array of secrets

    • keyset: MintKeys

      mint keyset

    Returns Proof[]

    array of serialized proofs

  • Creates blinded messages for a according to

    Parameters

    • amounts: number[]
    • keysetId: string
    • Optional counter: number
    • Optional pubkey: string

    Returns BlindedMessageData & {
        amounts: number[];
    }

    blinded messages, secrets, rs, and amounts

  • 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.

    • Optional description: 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

  • Creates blinded messages for a given amount

    Parameters

    • amount: number

      amount to create blinded messages for

    • keyset: MintKeys
    • Optional amountPreference: AmountPreference[]

      optional preference for splitting proofs into specific amounts. overrides amount param

    • Optional counter: number
    • Optional pubkey: string

    Returns BlindedMessageData & {
        amounts: number[];
    }

    blinded messages, secrets, rs, and amounts

  • Initialize the wallet with the mints public keys

    Parameters

    • Optional keysetId: string
    • Optional unit: string

    Returns Promise<MintKeys>

  • Melt tokens for a melt quote. proofsToSend must be at least amount+fee_reserve form the melt quote. Returns payment proof and change proofs

    Parameters

    • meltQuote: MeltQuoteResponse

      ID of the melt quote

    • proofsToSend: Proof[]

      proofs to melt

    • Optional options: {
          counter?: number;
          keysetId?: string;
          privkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional privkey?: string

    Returns Promise<MeltTokensResponse>

  • Mint tokens for a given mint quote

    Parameters

    • amount: number

      amount to request

    • quote: string

      ID of mint quote

    • Optional options: {
          counter?: number;
          keysetId?: string;
          preference?: AmountPreference[];
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional preference?: AmountPreference[]
      • Optional pubkey?: string

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

    proofs

  • Helper function that pays a Lightning invoice directly without having to create a melt quote before The combined amount of Proofs must match the payment amount including fees.

    Parameters

    • invoice: string
    • proofsToSend: Proof[]

      the exact amount to send including fees

    • Optional meltQuote: MeltQuoteResponse

      melt quote for the invoice

    • Optional options: {
          counter?: number;
          keysetId?: string;
          privkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional privkey?: string

    Returns Promise<MeltTokensResponse>

  • Helper function to ingest a Cashu token and pay a Lightning invoice with it.

    Parameters

    • invoice: string

      Lightning invoice

    • token: string

      cashu token

    • meltQuote: MeltQuoteResponse

      melt quote for the invoice

    • Optional options: {
          counter?: number;
          keysetId?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string

    Returns Promise<MeltTokensResponse>

  • 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

    • Optional options: {
          counter?: number;
          keysetId?: string;
          preference?: AmountPreference[];
          privkey?: string;
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional preference?: AmountPreference[]
      • Optional privkey?: string
      • Optional pubkey?: string

    Returns Promise<Proof[]>

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

  • Receive a single cashu token entry

    Parameters

    • tokenEntry: TokenEntry

      a single entry of a cashu token

    • Optional options: {
          counter?: number;
          keysetId?: string;
          preference?: AmountPreference[];
          privkey?: string;
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional preference?: AmountPreference[]
      • Optional privkey?: string
      • Optional pubkey?: string

    Returns Promise<Proof[]>

    New token entry with newly created proofs, proofs 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

    • Optional options: {
          keysetId?: string;
      }
      • Optional keysetId?: string

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

    proofs

  • 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

      amount to send while performing the optimal split (least proofs possible). can be set to undefined if preference is set

    • proofs: Proof[]

      proofs matching that amount

    • Optional options: {
          counter?: number;
          keysetId?: string;
          preference?: AmountPreference[] | Preferences;
          privkey?: string;
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional preference?: AmountPreference[] | Preferences
      • Optional privkey?: string
      • Optional pubkey?: string

    Returns Promise<SendResponse>

    promise of the change- and send-proofs

  • Parameters

    • amount: number
    • amountAvailable: number

    Returns {
        amountKeep: number;
        amountSend: number;
    }

    • amountKeep: number
    • amountSend: number

Generated using TypeDoc