Skip to content

An JavaScript library for building Cashu wallets

License

Notifications You must be signed in to change notification settings

bitsalv/cashu-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cashu-js

cashu-js is an npm package for building Cashu ecash wallets.

Cashu is an Ecash implementation based on David Wagner's variant of Chaumian blinding. Token logic based on minicash (description) which implements a Blind Diffie-Hellman Key Exchange scheme written down by Ruben Somsen here.

Progress

  • Request mint
  • Mint tokens
  • Split tokens
  • Send tokens
  • Receive tokens
  • Melt tokens
  • Check spendable
  • Check fees
  • Keysets
  • Local storage
  • Serialize tokens V1
  • Serialize tokens V2
  • LNURL-pay

Running and testing the client

You need a Cashu mint for testing. If you don't already have one, follow the instructions below to set one up. Then we will run the JS code in this repo.

Set up a mint

Install the Cashu Python mint and run the server on localhost:3338. Don't be afraid. This is a quick an easy process if you follow the instructions carefully.

Run the mint:

LIGHTNING=FALSE poetry run mint

Here we made sure to disable Lightning for testing purposes, otherwise the mint will demand a Lightning payment (set LIGHTNING=FALSE in .env file to disable it permanently).

Set up cashu-js

Clone this repository and install the dependencies:

git clone https://github.com/cashubtc/cashu-js-wallet.git
npm install
Mint tokens and receive Lightnign invoices

Get a Lightning invoice:

node src/index.js invoice 420

Save the <invoice_hash> for the next step (or compute it yourself from the bolt11 invoice). Note: This step will fail if you've set LIGHTNING=FALSE in the mint. Just skip to the next step if so.

After paying it, enter:

node src/index.js invoice 420 <invoice_hash>

Where <invoice_hash> is the hash of the bolt11 invoice. Note: If you've set LIGHTNING=FALSE in the mint, you can use any invoice_hash you want here.

Melt tokens and pay Lightnign invoices
node src/index.js pay <invoice>
Send tokens
node src/index.js send 69
Receive tokens
node src/index.js receive W3siaWQiOiJEU0FsOW52dnlm...
Receive tokens
node src/index.js receive W3siaWQiOiJEU0FsOW52dnlm...
Run tests
node test/test_crypto.js

Use in browser

Install browserify and other packages using npm install --save-dev and run

browserify -p common-shakeify src/wallet.js -o dist/bundle.js
node_modules/terser/bin/terser  -c toplevel,sequences=false --mangle -- dist/bundle.js > dist/bundle.min.js

Check the /dist directory for an example HTML.

About

An JavaScript library for building Cashu wallets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%