An open API service indexing awesome lists of open source software.

https://github.com/ngmachado/stealth-payment-cli

anonymous and secure transactions using stealth addresses on EVM
https://github.com/ngmachado/stealth-payment-cli

Last synced: about 1 month ago
JSON representation

anonymous and secure transactions using stealth addresses on EVM

Awesome Lists containing this project

README

        

# πŸ›‘οΈ Stealth Payment System CLI

## πŸ“– Overview

The **Stealth Payment System CLI** provides a secure and private escrow mechanism for **Ethereum (ETH) transactions**. The system allows **senders to deposit ETH** into a smart contract without directly linking it to the receiver. **Zero-Knowledge Proofs (ZK-SNARKs)** ensure **privacy and security**, preventing double-spending and making transactions unlinkable.

## ✨ Key Features

- **πŸ”‘ Stealth Addresses** – Unique, per-transaction addresses hide recipient identity.
- **πŸ›‘οΈ Zero-Knowledge Proofs** – Uses zk-SNARKs for secure and anonymous fund claims.
- **πŸ’° Anonymous Payments** – No direct on-chain link between sender and receiver.
- **⚑ CLI Interface** – Lightweight command-line interface for seamless interaction.

---

## πŸ—οΈ System Architecture

### πŸ”Ή **Smart Contracts**
- **Carrier Contract** – Registers recipient public keys.
- **Escrow Contract** – Manages deposits and claims using commitments and ZK-SNARK proofs.

### πŸ”Ή **Cryptographic Components**
- **Commitment** – A cryptographic hash that binds the deposit to a **shared secret** without revealing it.
- **Shared Secret** – Derived using **Elliptic Curve Diffie-Hellman (ECDH)** between sender and receiver.
- **Nullifier** – A unique value ensuring **each deposit can only be claimed once**.
- **ZK-SNARK Proof** – Receiver proves knowledge of the **shared secret** without revealing it.

---

## πŸ”‘ Privacy & Security Features

βœ” **No Link Between Sender & Receiver**
βœ” **Prevents Double-Spending with Nullifiers**
βœ” **Each Transaction Uses a Unique Ephemeral Key**
βœ” **Zero-Knowledge Proofs Ensure Private Fund Claims**

---

## πŸ”„ **Deposit Process**

1️⃣ **Retrieve Receiver's Public Key**
- The sender fetches the recipient’s registered public key (`pub_r`) from the Carrier Contract.

2️⃣ **Generate Ephemeral Key Pair**
- The sender creates an ephemeral key pair:
```math
eph\_pub = eph\_priv \times G
```
- This ensures that each deposit is uniquely linked to the sender.

3️⃣ **Compute Shared Secret (ECDH)**
- The sender computes the shared secret:
```math
shared = eph\_priv \times pub_r
```
- The receiver **can later compute the same shared secret** using their private key.

4️⃣ **Compute Hashed Secret**
- The sender hashes the shared secret:
```math
hashedSecret = poseidon.hash(sharedSecretX)
```

5️⃣ **Compute Stealth Public Key**
- The stealth public key is computed as:
```math
pub\_once = hash(shared) \times G + pub_r
```
- This ensures only the receiver can derive the corresponding private key.

6️⃣ **Compute Commitment & Deposit Transaction**
- The **commitment** is stored in the Escrow Contract:
```math
commitment = poseidon.hash(hashedSecret)
```
- The sender deposits funds by calling:
```sh
bun cli.ts deposit -r -a
```

---

## πŸ”“ **Claim Process**

1️⃣ **Receiver Identifies the Deposit**
- Uses their private key to **compute the same shared secret**.

2️⃣ **Compute Hashed Secret & Commitment**
- Ensures that the computed **commitment matches** the one stored on-chain.

3️⃣ **Compute Nullifier**
- To prevent double-spending:
```math
depositNullifier = poseidon.hash([computedCommitment, safeSharedSecret])
```

4️⃣ **Generate ZK-SNARK Proof**
- Proves knowledge of the **shared secret** without revealing it.

5️⃣ **Submit Claim Transaction**
- The receiver submits:
```sh
bun cli.ts claim
```

---

## πŸ›  Prerequisites

βœ… **[Bun](https://bun.sh/) installed**
βœ… **Node.js v18+**
βœ… **Ethereum-compatible wallet with ETH for gas**
βœ… **Access to an Ethereum RPC endpoint**
βœ… **[snarkjs](https://github.com/iden3/snarkjs) for zk-SNARK proof generation**

---

## πŸš€ Installation

```sh
# Clone the repository
git clone https://github.com/ngmachado/stealth-payment-cli
cd stealth-payment-cli

# Install dependencies
bun install

# Add execution permission (optional)
chmod +x cli.ts
```

---

## πŸ’» CLI Usage Guide

### πŸ”Ή 1️⃣ Setup & Wallet Configuration
```sh
bun cli.ts setup
```
πŸ”‘ **Inputs required:**
- Encryption password (secure storage)
- Private key (for signing transactions)
- Ethereum RPC URL

---

### πŸ”Ή 2️⃣ Register Public Key
```sh
bun cli.ts register
```
πŸ“‘ Registers your **public key** on-chain (required for receiving funds).

---

### πŸ”Ή 3️⃣ Deposit ETH to a Stealth Address
```sh
bun cli.ts deposit -r -a
```
Example:
```sh
bun cli.ts deposit -r 0x1234...5678 -a 0.5
```
---

### πŸ”Ή 4️⃣ Scan for Incoming Deposits
```sh
bun cli.ts scan
```

---

## ⚠️ Security Considerations

βœ” **Keep private keys secure & never share them**
βœ” **Use a strong encryption password during setup**
βœ” **Consider using a private RPC endpoint to prevent metadata leakage**
βœ” **This is experimental software – use at your own risk**

---

## πŸ”’ Privacy Enhancements

βœ” **Zero-knowledge proofs** ensure claim privacy
βœ” **Ephemeral keys** prevent on-chain linking
βœ” **Stealth addresses** mask recipient identity
βœ” **ECDH key exchange** secures communication

---

## πŸ“œ License
This project is licensed under the **MIT License**.

---

## ⚠️ Disclaimer
🚨 This is **experimental software** provided **as-is** without any warranty.
🚨 **This codebase has NOT been audited** – use at your own risk!

---

### **πŸ”— Useful Resources**
- [Bun Documentation](https://bun.sh/docs)
- [snarkjs Library](https://github.com/iden3/snarkjs)

---

πŸ”₯ **Stealth Payment System - Privacy-Preserving Crypto Payments** πŸ”₯