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.
- 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
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.
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).
Clone this repository and install the dependencies:
git clone https://github.com/cashubtc/cashu-js-wallet.git
npm install
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.
node src/index.js pay <invoice>
node src/index.js send 69
node src/index.js receive W3siaWQiOiJEU0FsOW52dnlm...
node src/index.js receive W3siaWQiOiJEU0FsOW52dnlm...
node test/test_crypto.js
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.