Skip to main content

CashuWallet

@cashu/cashu-ts


@cashu/cashu-ts / CashuWallet

Class: CashuWallet

Defined in: cashu-ts/src/CashuWallet.ts:81

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

Constructors

new CashuWallet()

new CashuWallet(mint, options?): CashuWallet

Defined in: cashu-ts/src/CashuWallet.ts:104

Parameters

mint

CashuMint

Cashu mint instance is used to make api calls

options?
bip39seed?

Uint8Array

BIP39 seed for deterministic secrets.

denominationTarget?

number

target number proofs per denomination (default: see

keepFactory?

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

keys?

MintKeys | MintKeys[]

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

keysets?

MintKeyset[]

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

mintInfo?

GetInfoResponse

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

unit?

string

optionally set unit (default is 'sat')

Returns

CashuWallet

Constant

DEFAULT_DENOMINATION_TARGET)

Properties

mint

mint: CashuMint

Defined in: cashu-ts/src/CashuWallet.ts:91

Accessors

keys

Get Signature

get keys(): Map<string, MintKeys>

Defined in: cashu-ts/src/CashuWallet.ts:146

Returns

Map<string, MintKeys>


keysetId

Get Signature

get keysetId(): string

Defined in: cashu-ts/src/CashuWallet.ts:149

Returns

string

Set Signature

set keysetId(keysetId): void

Defined in: cashu-ts/src/CashuWallet.ts:155

Parameters
keysetId

string

Returns

void


keysets

Get Signature

get keysets(): MintKeyset[]

Defined in: cashu-ts/src/CashuWallet.ts:158

Returns

MintKeyset[]


mintInfo

Get Signature

get mintInfo(): MintInfo

Defined in: cashu-ts/src/CashuWallet.ts:161

Returns

MintInfo


unit

Get Signature

get unit(): string

Defined in: cashu-ts/src/CashuWallet.ts:143

Returns

string

Methods

batchRestore()

batchRestore(gapLimit?, batchSize?, counter?, keysetId?): Promise<{ lastCounterWithSignature: number; proofs: Proof[]; }>

Defined in: cashu-ts/src/CashuWallet.ts:611

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

Parameters

gapLimit?

number = 300

the amount of empty counters that should be returned before restoring ends (defaults to 300)

batchSize?

number = 100

the amount of proofs that should be restored at a time (defaults to 100)

counter?

number = 0

the counter that should be used as a starting point (defaults to 0)

keysetId?

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[]; }>


checkMeltQuote()

checkMeltQuote(quote): Promise<MeltQuoteResponse>

Defined in: cashu-ts/src/CashuWallet.ts:874

Return an existing melt quote from the mint.

Parameters

quote

string

ID of the melt quote

Returns

Promise<MeltQuoteResponse>

the mint will return an existing melt quote


checkMintQuote()

checkMintQuote(quote): Promise<MintQuoteResponse>

Defined in: cashu-ts/src/CashuWallet.ts:739

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


checkProofsStates()

checkProofsStates(proofs): Promise<ProofState[]>

Defined in: cashu-ts/src/CashuWallet.ts:1053

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


createLockedMintQuote()

createLockedMintQuote(amount, pubkey, description?): Promise<LockedMintQuoteResponse>

Defined in: cashu-ts/src/CashuWallet.ts:712

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

description?

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.


createMeltQuote()

createMeltQuote(invoice): Promise<MeltQuoteResponse>

Defined in: cashu-ts/src/CashuWallet.ts:828

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


createMintQuote()

createMintQuote(amount, description?): Promise<MintQuoteResponse>

Defined in: cashu-ts/src/CashuWallet.ts:695

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.

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


createMultiPathMeltQuote()

createMultiPathMeltQuote(invoice, millisatPartialAmount): Promise<MeltQuoteResponse>

Defined in: cashu-ts/src/CashuWallet.ts:843

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


getActiveKeyset()

getActiveKeyset(keysets): MintKeyset

Defined in: cashu-ts/src/CashuWallet.ts:206

Choose a keyset to activate based on the lowest input fee

Note: this function will filter out deprecated base64 keysets

Parameters

keysets

MintKeyset[]

keysets to choose from

Returns

MintKeyset

active keyset


getAllKeys()

getAllKeys(): Promise<MintKeys[]>

Defined in: cashu-ts/src/CashuWallet.ts:236

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

Returns

Promise<MintKeys[]>

keyset


getFeesForKeyset()

getFeesForKeyset(nInputs, keysetId): number

Defined in: cashu-ts/src/CashuWallet.ts:486

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


getFeesForProofs()

getFeesForProofs(proofs): number

Defined in: cashu-ts/src/CashuWallet.ts:454

calculates the fees based on inputs (proofs)

Parameters

proofs

Proof[]

input proofs to calculate fees for

Returns

number

fee amount


getKeys()

getKeys(keysetId?, forceRefresh?): Promise<MintKeys>

Defined in: cashu-ts/src/CashuWallet.ts:253

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

keysetId?

string

optional keysetId to get keys for

forceRefresh?

boolean

Returns

Promise<MintKeys>

keyset


getKeySets()

getKeySets(): Promise<MintKeyset[]>

Defined in: cashu-ts/src/CashuWallet.ts:225

Get keysets from the mint with the unit of the wallet

Returns

Promise<MintKeyset[]>

keysets with wallet's unit


getMintInfo()

getMintInfo(): Promise<MintInfo>

Defined in: cashu-ts/src/CashuWallet.ts:172

Get information about the mint

Returns

Promise<MintInfo>

mint info


lazyGetMintInfo()

lazyGetMintInfo(): Promise<MintInfo>

Defined in: cashu-ts/src/CashuWallet.ts:182

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

Returns

Promise<MintInfo>

mint info


loadMint()

loadMint(): Promise<void>

Defined in: cashu-ts/src/CashuWallet.ts:192

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

Returns

Promise<void>


meltProofs()

meltProofs(meltQuote, proofsToSend, options?): Promise<MeltProofsResponse>

Defined in: cashu-ts/src/CashuWallet.ts:887

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

options?

MeltProofOptions

Optional parameters for configuring the Melting Proof operation

Returns

Promise<MeltProofsResponse>


mintProofs()

Call Signature

mintProofs(amount, quote, options?): Promise<Proof[]>

Defined in: cashu-ts/src/CashuWallet.ts:751

Mint proofs for a given mint quote

Parameters
amount

number

amount to request

quote

MintQuoteResponse

ID of mint quote (when quote is a string)

options?

MintProofOptions & object

Optional parameters for configuring the Mint Proof operation

Returns

Promise<Proof[]>

proofs

Call Signature

mintProofs(amount, quote, options?): Promise<Proof[]>

Defined in: cashu-ts/src/CashuWallet.ts:756

Mint proofs for a given mint quote

Parameters
amount

number

amount to request

quote

string

ID of mint quote (when quote is a string)

options?

MintProofOptions

Optional parameters for configuring the Mint Proof operation

Returns

Promise<Proof[]>

proofs


onMeltQuotePaid()

onMeltQuotePaid(quoteId, callback, errorCallback): Promise<SubscriptionCanceller>

Defined in: cashu-ts/src/CashuWallet.ts:1112

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

Parameters

quoteId

string

callback

(payload) => void

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

errorCallback

(e) => void

Returns

Promise<SubscriptionCanceller>


onMeltQuoteUpdates()

onMeltQuoteUpdates(quoteIds, callback, errorCallback): Promise<SubscriptionCanceller>

Defined in: cashu-ts/src/CashuWallet.ts:1158

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

Parameters

quoteIds

string[]

callback

(payload) => void

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

errorCallback

(e) => void

Returns

Promise<SubscriptionCanceller>


onMintQuotePaid()

onMintQuotePaid(quoteId, callback, errorCallback): Promise<SubscriptionCanceller>

Defined in: cashu-ts/src/CashuWallet.ts:1135

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) => void

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

errorCallback

(e) => void

Returns

Promise<SubscriptionCanceller>


onMintQuoteUpdates()

onMintQuoteUpdates(quoteIds, callback, errorCallback): Promise<SubscriptionCanceller>

Defined in: cashu-ts/src/CashuWallet.ts:1086

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) => void

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

errorCallback

(e) => void

Returns

Promise<SubscriptionCanceller>


onProofStateUpdates()

onProofStateUpdates(proofs, callback, errorCallback): Promise<SubscriptionCanceller>

Defined in: cashu-ts/src/CashuWallet.ts:1184

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) => void

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

errorCallback

(e) => void

Returns

Promise<SubscriptionCanceller>


receive()

receive(token, options?): Promise<Proof[]>

Defined in: cashu-ts/src/CashuWallet.ts:287

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

Parameters

token

Cashu token, either as string or decoded

string | Token

options?

ReceiveOptions

Optional configuration for token processing

Returns

Promise<Proof[]>

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


restore()

restore(start, count, options?): Promise<{ lastCounterWithSignature: number; proofs: Proof[]; }>

Defined in: cashu-ts/src/CashuWallet.ts:643

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

options?

RestoreOptions

Returns

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


selectProofsToSend()

selectProofsToSend(proofs, amountToSend, includeFees?): SendResponse

Defined in: cashu-ts/src/CashuWallet.ts:399

Parameters

proofs

Proof[]

amountToSend

number

includeFees?

boolean

Returns

SendResponse


send()

send(amount, proofs, options?): Promise<SendResponse>

Defined in: cashu-ts/src/CashuWallet.ts:334

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)

options?

SendOptions

Optional parameters for configuring the send operation

Returns

Promise<SendResponse>


swap()

swap(amount, proofs, options?): Promise<SendResponse>

Defined in: cashu-ts/src/CashuWallet.ts:505

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

options?

SwapOptions

Optional parameters for configuring the swap operation

Returns

Promise<SendResponse>

promise of the change- and send-proofs