Skip to main content

Ecash wallet and mint with Bitcoin Lightning support

Project description

cashu

Cashu is a Chaumian Ecash wallet and mint with Bitcoin Lightning support.

Disclaimer: The author is NOT a cryptographer and this work has not been reviewed. This means that there is very likely a fatal flaw somewhere. Cashu is still experimental and not production-ready.

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. The database mechanics and the Lightning backend uses parts from LNbits.

Install

Prerequisites

These steps help you install Python via pyenv and Poetry. If you already have Poetry running on your computer, you can skip this step and jump right to Install Cashu.

sudo apt install -y build-essential pkg-config libffi-dev libpq-dev zlib1g-dev libssl-dev python3-dev
# on mac: brew install postgres

# install python using pyenv
curl https://pyenv.run | bash

# !! follow the instructions of pyenv init to setup pyenv !!
pyenv init

# restart your shell (or source your .rc file), then install python:
pyenv install 3.9.13

# install poetry
curl -sSL https://install.python-poetry.org | python3 -
echo export PATH=\"$HOME/.local/bin:$PATH\" >> ~/.bashrc
source ~/.bashrc

Install Cashu

# install cashu
git clone https://github.com/callebtc/cashu.git
cd cashu
pyenv local 3.9.13
poetry install

Update Cashu

To update Cashu to the newest version enter

git pull && poetry install

Configuration

mv .env.example .env
# edit .env file
vim .env

To use the wallet with the public test mint, you need to change the appropriate entries in the .env file.

Test instance

Warning: this instance is just for demonstration only. Currently, only Lightning deposits work but not withdrawals. The server could vanish at any moment so consider any Satoshis you deposit a donation. I will add Lightning withdrawals soon so unless someone comes up with a huge inflation bug, you might be able to claim them back at a later point in time.

Change the appropriate .env file settings to

MINT_HOST=8333.space
MINT_PORT=3338

Using Cashu

Cashu should be now installed. To execute the following commands, activate your virtual Poetry environment via

poetry shell

If you don't activate your environment, just prepent poetry run to all following commands.

Using the wallet

Request a mint

This command will return a Lightning invoice and a payment hash. You have to pay the invoice before you can receive the tokens. Note: Minting tokens involves two steps: requesting a mint, and actually minting tokens (see below).

cashu mint 420

Returns:

Balance: 0 sat (Available: 0 sat in 0 tokens)
{
    'pr': 'lnbc4200n1p3jp5clsp5vcfkyqtnkcx9287auhesqwj40che77pd4ymaltc3ruazh3vcgs3qpp5qzwkavpd4pmfkdmq9trdnrk2lswkt0fypqg55h2sucx6yq9ushzsdq4vdshx6r4ypjx2ur0wd5hgxqyjw5qcqpjrzjq0qly7quwdwq2wr52et5gl65dagdgqdwgn9an58mhejnsvmmu996xzetgvqqwzcqqqqqqqqqqqqqqqqq9q9qyysgqfjwnl4za4naf7l2wwcck2gk6y9mvjt5dz9gptfkpl0j50ygkdkuxyjcy3zgd2tk4995yw8gx39cx2qwm9dgwc0t9t6hrgvjzauykqrqpgw0xx3', 
    'hash': '009d6eb02da8769b37602ac6d98ecafc1d65bd2408114a5d50e60da200bc85c5'
}

Mint tokens

After paying the invoice, copy the hash value from above and add it to the command

cashu mint 420 --hash=009d6eb02da8769b37602ac6d98ecafc1d65bd2408114a5d50e60da200bc85c5

You should see your balance update accordingly:

Balance: 0 sat (Available: 0 sat in 0 tokens)
Balance: 420 sat (Available: 420 sat in 4 tokens)

Available tokens here means those tokens that have not been reserved for sending.

Check balance

cashu balance

Send tokens

To send tokens to another user, enter

cashu send 69

You should see the encoded token. Copy the token and send it to another user such as via email or a messenger. The token looks like this:

W3siYW1vdW50IjogMSwgIkMiOiB7IngiOiAzMzg0Mzg0NDYzNzAwMTY1NDA2MTQxMDY3Mzg1MDg5MjA2MTU2NjQxMjM4Nzg5MDE4NzAzODg0NjAwNDUzNTAwNzY3...

You can now see that your available balance has dropped by the amount that you reserved for sending if you enter cashu balance:

Balance: 420 sat (Available: 351 sat in 7 tokens)

Receive tokens

To receive tokens, another user enters:

cashu receive W3siYW1vdW50IjogMSwgIkMiOi...

You should see the balance increase:

Balance: 0 sat (Available: 0 sat in 0 tokens)
Balance: 69 sat (Available: 69 sat in 3 tokens)

Burn tokens

The sending user needs to burn (invalidate) their tokens from above, otherwise they will try to double spend them (which won't work because the server keeps a list of all spent tokens):

cashu burn W3siYW1vdW50IjogMSwgIkMiOi...

Returns:

Balance: 420 sat (Available: 351 sat in 7 tokens)
Balance: 351 sat (Available: 351 sat in 7 tokens)

Pay a Lightning invoice

cashu pay lnbc120n1p3jfmdapp5r9jz...

Returns:

Balance: 351 sat (Available: 351 sat in 7 tokens)
Balance: 339 sat (Available: 339 sat in 8 tokens)

Run a mint yourself

This command runs the mint on your local computer. Skip this step if you want to use the public test mint instead.

mint

You can turn off Lightning support and mint as many tokens as you like by setting LIGHTNING=FALSE in the .env file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cashu-0.1.6.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

cashu-0.1.6-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file cashu-0.1.6.tar.gz.

File metadata

  • Download URL: cashu-0.1.6.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for cashu-0.1.6.tar.gz
Algorithm Hash digest
SHA256 141dcda9fb7c41f9f04bfaa5f560b0a937e8907df6e093a9944484e105fe97da
MD5 99bdef8e09ceb345772661e7cf09d2b0
BLAKE2b-256 2926582b8833b194db6cfd96eda4d3d21101fe8e1b649bc4e29f2be1f177badd

See more details on using hashes here.

File details

Details for the file cashu-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: cashu-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for cashu-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fb9805b78b195f56c1d0307bf66c4f45f9adb29380a284909c984d79eca896c9
MD5 53fb58ac77bb8c694f18a876f0065767
BLAKE2b-256 2a7e0dd9e644cc39d9ec71e2e9761d0151df8be0d0129a090fdc3f036c8ed5f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page