Class CashuWallet

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

Hierarchy

  • CashuWallet

Constructors

  • Constant

    DEFAULT_DENOMINATION_TARGET)

    Parameters

    • mint: CashuMint

      Cashu mint instance is used to make api calls

    • Optional options: {
          bip39seed?: Uint8Array;
          denominationTarget?: number;
          keys?: MintKeys | MintKeys[];
          keysets?: MintKeyset[];
          mintInfo?: GetInfoResponse;
          unit?: string;
      }
      • Optional bip39seed?: Uint8Array

        BIP39 seed for deterministic secrets. This can lead to poor performance, in which case the seed should be directly provided

      • Optional denominationTarget?: number

        target number proofs per denomination (default: see

      • Optional keys?: MintKeys | MintKeys[]

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

      • Optional keysets?: MintKeyset[]

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

      • Optional mintInfo?: GetInfoResponse

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

      • Optional unit?: string

        optionally set unit (default is 'sat')

    Returns CashuWallet

Properties

_denominationTarget: number = DEFAULT_DENOMINATION_TARGET
_keys: Map<string, MintKeys> = ...
_keysetId: undefined | string
_keysets: MintKeyset[] = []
_mintInfo: undefined | GetInfoResponse = undefined
_seed: undefined | Uint8Array = undefined
_unit: string = DEFAULT_UNIT
mint: CashuMint

Accessors

Methods

  • Gets an existing mint quote from the mint.

    Parameters

    • quote: string

      Quote ID

    Returns Promise<MintQuoteResponse>

    the mint will create and return a Lightning invoice for the specified amount

  • 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[]>

  • 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 BlindingData & {
        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 split: number[]

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

    • Optional counter: number
    • Optional pubkey: string

    Returns BlindingData & {
        amounts: number[];
    }

    blinded messages, secrets, rs, and amounts

  • Choose a keyset to activate based on the lowest input fee

    Note: this function will filter out deprecated base64 keysets

    Parameters

    Returns MintKeyset

    active keyset

  • 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

  • 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

    • Optional keysetId: string

      optional keysetId to get keys for

    • Optional forceRefresh: boolean

    Returns Promise<MintKeys>

    keyset

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

    Returns Promise<void>

  • Melt proofs for a melt quote. proofsToSend must be at least amount+fee_reserve form the melt quote. This function does not perform coin selection!. Returns melt quote 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<MeltProofsResponse>

  • Mint proofs for a given mint quote

    Parameters

    • amount: number

      amount to request

    • quote: string

      ID of mint quote

    • Optional options: {
          counter?: number;
          keysetId?: string;
          outputAmounts?: OutputAmounts;
          proofsWeHave?: Proof[];
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional outputAmounts?: OutputAmounts
      • Optional proofsWeHave?: Proof[]
      • Optional pubkey?: string

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

    proofs

  • 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

    • Optional options: {
          counter?: number;
          keysetId?: string;
          outputAmounts?: OutputAmounts;
          privkey?: string;
          proofsWeHave?: Proof[];
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional keysetId?: string
      • Optional outputAmounts?: OutputAmounts
      • Optional privkey?: string
      • Optional proofsWeHave?: Proof[]
      • Optional pubkey?: string

    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

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

        set a custom keysetId to restore from. keysetIds can be loaded with CashuMint.getKeySets()

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

    proofs

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

    • Optional options: {
          counter?: number;
          includeFees?: boolean;
          keysetId?: string;
          offline?: boolean;
          outputAmounts?: OutputAmounts;
          privkey?: string;
          proofsWeHave?: Proof[];
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional includeFees?: boolean
      • Optional keysetId?: string
      • Optional offline?: boolean
      • Optional outputAmounts?: OutputAmounts
      • Optional privkey?: string
      • Optional proofsWeHave?: Proof[]
      • Optional pubkey?: string

    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

      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;
          includeFees?: boolean;
          keysetId?: string;
          outputAmounts?: OutputAmounts;
          privkey?: string;
          proofsWeHave?: Proof[];
          pubkey?: string;
      }
      • Optional counter?: number
      • Optional includeFees?: boolean
      • Optional keysetId?: string
      • Optional outputAmounts?: OutputAmounts
      • Optional privkey?: string
      • Optional proofsWeHave?: Proof[]
      • Optional pubkey?: string

    Returns Promise<SendResponse>

    promise of the change- and send-proofs

Generated using TypeDoc