Metadata-Version: 2.1
Name: cashu
Version: 0.15.0
Summary: Ecash wallet and mint for Bitcoin Lightning
Home-page: https://github.com/cashubtc/cashu
Author: Calle
Author-email: calle@protonmail.com
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: anyio ==4.0.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: asn1crypto ==1.5.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: attrs ==23.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: base58 ==2.1.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: bech32 ==1.2.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: bip32 ==3.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: bitstring ==3.1.9 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: bolt11 ==2.0.5 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: certifi ==2023.7.22 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: cffi ==1.16.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: click ==8.1.7 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: coincurve ==18.0.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: cryptography ==41.0.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: ecdsa ==0.18.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: environs ==9.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: fastapi ==0.103.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: h11 ==0.14.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: httpcore ==0.18.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: httpx[socks] ==0.25.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: idna ==3.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: importlib-metadata ==6.8.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: loguru ==0.7.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: marshmallow ==3.20.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: mnemonic ==0.20 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: outcome ==1.2.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: packaging ==23.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: pycparser ==2.21 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: pycryptodomex ==3.19.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: pydantic ==1.10.13 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: python-dotenv ==1.0.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: represent ==1.6.0.post0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: secp256k1 ==0.14.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: setuptools ==68.2.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: six ==1.16.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: sniffio ==1.3.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: socksio ==1.0.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: sqlalchemy-aio ==0.17.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: sqlalchemy ==1.3.24 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: starlette ==0.27.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: typing-extensions ==4.8.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: uvicorn ==0.23.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: websocket-client ==1.6.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: wheel ==0.41.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: zipp ==3.17.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
Requires-Dist: colorama ==0.4.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" and platform_system == "Windows" or python_full_version >= "3.8.1" and python_full_version < "4.0.0" and sys_platform == "win32"
Requires-Dist: win32-setctime ==1.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" and sys_platform == "win32"
Requires-Dist: exceptiongroup ==1.1.3 ; python_full_version >= "3.8.1" and python_version < "3.11"

# Cashu Nutshell

**Cashu Nutshell is a Chaumian Ecash wallet and mint for Bitcoin Lightning. Cashu Nutshell is the reference implementation in Python.**

<a href="https://pypi.org/project/cashu/"><img alt="Release" src="https://img.shields.io/pypi/v/cashu?color=black"></a> <a href="https://pepy.tech/project/cashu"> <img alt="Downloads" src="https://pepy.tech/badge/cashu"></a> <a href="https://app.codecov.io/gh/cashubtc/nutshell"><img alt="Coverage" src="https://img.shields.io/codecov/c/gh/cashubtc/nutshell"></a>


*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 ([protocol specs](https://github.com/cashubtc/nuts)). Token logic based on [minicash](https://github.com/phyro/minicash) ([description](https://gist.github.com/phyro/935badc682057f418842c72961cf096c)) which implements a [Blind Diffie-Hellman Key Exchange](https://cypherpunks.venona.com/date/1996/03/msg01848.html) scheme written down [here](https://gist.github.com/RubenSomsen/be7a4760dd4596d06963d67baf140406). The database mechanics in Cashu Nutshell and the Lightning backend uses parts from [LNbits](https://github.com/lnbits/lnbits-legend).

<p align="center">
<a href="#the-cashu-protocol">Cashu protocol</a> ·
<a href="#easy-install">Quick Install</a> ·
<a href="#manual-install-poetry">Manual install</a> ·
<a href="#configuration">Configuration</a> ·
<a href="#using-cashu">Using Cashu</a> ·
<a href="#running-a-mint">Run a mint</a>
</p>

### Feature overview of Nutshell

- Bitcoin Lightning support
- Standalone Cashu CLI  wallet and mint server
- Wallet and mint library to include in Python projects
- PostgreSQL and SQLite
- Wallet with builtin Tor
- Use multiple mints in one wallet
- Send and receive tokens on nostr

### Advanced features
- Deterministic wallet with seed phrase backup
- Programmable ecash with, e.g., Pay-to-Pubkey support
- Wallet and mint support for keyset rotations
- DLEQ proofs for offline transactions

## The Cashu protocol
Different Cashu clients and mints use the same protocol to achieve interoperability. See the [documentation page](https://docs.cashu.space/) for more information on other projects. If you are interested in developing on your own Cashu project, please refer to the protocol specs [protocol specs](https://github.com/cashubtc/nuts).

## Easy Install

The easiest way to use Cashu is to install the package it via pip:
```bash
pip install cashu
```

To update Cashu, use `pip install cashu -U`.

If you have problems running the command above on Ubuntu, run `sudo apt install -y pip pkg-config` and `pip install wheel`. On macOS, you might have to run `pip install wheel` and `brew install pkg-config`.

You can skip the entire next section about Poetry and jump right to [Using Cashu](#using-cashu).

## Manual install: Poetry
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](#poetry-install-cashu).

#### Poetry: Prerequisites

```bash
# on ubuntu:
sudo apt install -y build-essential pkg-config libffi-dev libpq-dev zlib1g-dev libssl-dev python3-dev libsqlite3-dev ncurses-dev libbz2-dev libreadline-dev lzma-dev

# 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.10.4

# install poetry
curl -sSL https://install.python-poetry.org | python3 -
echo export PATH=\"$HOME/.local/bin:$PATH\" >> ~/.bashrc
source ~/.bashrc
```
#### Poetry: Install Cashu
```bash
# install cashu
git clone https://github.com/cashubtc/nutshell.git cashu
cd cashu
pyenv local 3.10.4
poetry install
```

If you would like to use PostgreSQL as the mint database, use the command `poetry install --extras pgsql`.

#### Poetry: Update Cashu
To update Cashu to the newest version enter
```bash
git pull && poetry install
```
#### Poetry: Using the Nutshell wallet

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

```bash
poetry shell
```

If you don't activate your environment, just prepend `poetry run` to all following commands.
## Configuration
```bash
mv .env.example .env
# edit .env file
vim .env
```

To use the wallet with the [public test mint](#test-instance), you need to change the appropriate entries in the `.env` file.

#### Test instance
*Warning: this instance is just for demonstration only. The server could vanish at any moment so consider any Satoshis you deposit a donation.*

Change the appropriate `.env` file settings to
```bash
MINT_URL=https://8333.space:3338
```

# Using Cashu
```bash
cashu info
```
This command shows information about your wallet.

#### Check balance
```bash
cashu balance
```

#### Generate a Lightning invoice

This command will return a Lightning invoice that you need to pay to mint new ecash tokens.

```bash
cashu invoice 420
```

The client will check every few seconds if the invoice has been paid. If you abort this step but still pay the invoice, you can use the command `cashu invoice <amount> --id <id>`.

#### Pay a Lightning invoice
```bash
cashu pay lnbc120n1p3jfmdapp5r9jz...
```

#### Send tokens
To send tokens to another user, enter
```bash
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:
```bash
cashuAeyJwcm9vZnMiOiBbey...
```

#### Receive tokens
To receive tokens, another user enters:
```bash
cashu receive cashuAeyJwcm9vZnMiOiBbey...
```

# Starting the wallet API daemon
Nutshell wallet can be used in daemon mode that can be controlled through a REST API:
```bash
cashu -d
```

You can find the API docs at [http://localhost:4448/docs](http://localhost:4448/docs).

# Running a mint
This command runs the mint on your local computer. Skip this step if you want to use the [public test mint](#test-instance) instead.

Before you can run your own mint, make sure to enable a Lightning backend in `MINT_LIGHTNING_BACKEND` and set `MINT_PRIVATE_KEY` in your `.env` file.
```bash
poetry run mint
```

For testing, you can use Nutshell without a Lightning backend by setting `MINT_LIGHTNING_BACKEND=FakeWallet` in the `.env` file.


# Running tests
To run the tests in this repository, first install the dev dependencies with
```bash
poetry install --with dev
```

Then, make sure to set up your mint's `.env` file to use a fake Lightning backend and disable Tor:
```bash
MINT_LIGHTNING_BACKEND=FakeWallet
TOR=FALSE
```
You can run the tests with
```bash
poetry run pytest tests
```
