@cashu/cashu-ts
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

Cashu TS

GitHub Workflow Status GitHub issues GitHub package.json version npm npm type definitions npm bundle size code coverage

⚠️ Don't be reckless: This project is in early development, it does however work with real sats! Always use amounts you don't mind losing.

Cashu TS is a JavaScript library for Cashu wallets written in Typescript.

Wallet Features:

  • [x] connect to mint (load keys)
  • [x] request minting tokens
  • [x] minting tokens
  • [x] sending tokens (get encoded token for chosen value)
  • [x] receiving tokens
  • [x] melting tokens
  • [x] check if tokens are spent
  • [ ] ...

Implemented NUTs:

Supported token formats:

  • [x] v1 read
  • [x] v2 read (deprecated)
  • [x] v3 read/write
  • [x] v4 read/write

Usage

Go to the docs for detailed usage, or have a look at the integration tests for examples on how to implement a wallet.

Install

npm i @cashu/cashu-ts

Examples

Mint tokens

import { CashuMint, CashuWallet, MintQuoteState } from '@cashu/cashu-ts';
const mintUrl = 'http://localhost:3338'; // the mint URL
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint);
const mintQuote = await wallet.createMintQuote(64);
// pay the invoice here before you continue...
const mintQuoteChecked = await wallet.checkMintQuote(mintQuote.quote);
if (mintQuoteChecked.state == MintQuoteState.PAID) {
	const { proofs } = await wallet.mintTokens(64, mintQuote.quote);
}

Melt tokens

import { CashuMint, CashuWallet } from '@cashu/cashu-ts';
const mintUrl = 'http://localhost:3338'; // the mint URL
const mint = new CashuMint(mintUrl);
const wallet = new CashuWallet(mint);

const invoice = 'lnbc......'; // Lightning invoice to pay
const meltQuote = await wallet.createMeltQuote(invoice);
const amountToSend = meltQuote.amount + meltQuote.fee_reserve;

// in a real wallet, we would coin select the correct amount of proofs from the wallet's storage
// instead of that, here we swap `proofs` with the mint to get the correct amount of proofs
const { returnChange: proofsToKeep, send: proofsToSend } = await wallet.send(amountToSend, proofs);
// store proofsToKeep in wallet ..

const meltResponse = await wallet.meltTokens(meltQuote, proofsToSend);
// store meltResponse.change in wallet ..

Contribute

Contributions are very welcome.

If you want to contribute, please open an Issue or a PR. If you open a PR, please do so from the development branch as the base branch.

Version

* `main`
|\
|\ \
| | * `hotfix`
| |
| * `staging`
| |\
| |\ \
| | | * `bugfix`
| | |
| | * `development`
| | |\
| | | * `feature1`
| | | |
| | |/
| | *
| | |\
| | | * `feature2`
| | |/
| |/
|/ (create new version)

Dependencies (6)

Dev Dependencies (18)

Package Sidebar

Install

npm i @cashu/cashu-ts

Weekly Downloads

965

Version

1.2.1

License

MIT

Unpacked Size

434 kB

Total Files

166

Last publish

Collaborators

  • egge21m
  • callebtc
  • gandlaf21