Skip to content

a2Fsa2k/barter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Barter - Offline P2P Crypto Wallet

A Go-based CLI application for peer-to-peer cryptocurrency transactions over local networks without internet connectivity. Uses TCP for data transfer, UDP for peer discovery, and Ed25519 for cryptographic signatures.

Features

  • Offline P2P transactions over Wi-Fi Direct, hotspot, or localhost
  • Ed25519 cryptographic signatures with fingerprint-based identity
  • UDP broadcast peer discovery with TCP block transfer
  • Simple blockchain (one transaction = one block)
  • JSON persistence for keys, state, and ledger
  • Deterministic port assignment for multi-wallet support
  • Real-time transaction validation and balance updates

Requirements

  • Go 1.21 or higher
  • Linux/macOS/Windows
  • Network connectivity between peers (local network, no internet required)

Installation

# Clone the repository
git clone git@github.com:yourusername/barter.git
cd barter

# Build the binary
go build -o barter .

# Or use make
make build

Usage

Starting a Wallet

./barter --wallet <name>

On first run, the wallet generates an Ed25519 keypair and initializes with 100 tokens.

Interactive Menu

  1. Send Money - Discover peers and send tokens
  2. View Blockchain - Display transaction history
  3. View Peers - Scan for active wallets on network
  4. Exit - Shutdown wallet

Multi-Wallet Demo

Open two terminals and run:

# Terminal 1
./barter --wallet alice

# Terminal 2
./barter --wallet bob

Alice and Bob can now discover each other and exchange tokens.

Architecture

Wallet Structure

Each wallet consists of:

  • Ed25519 key pair with 4-character fingerprint
  • Persistent JSON storage (keys, state, ledger)
  • TCP listener for incoming transactions
  • UDP listener for peer discovery
  • Deterministic port assignment based on wallet name

Network Protocol

Peer Discovery (UDP broadcast)

  • Wallets broadcast discovery requests
  • Peers respond with their identity and TCP port
  • Each wallet uses a unique UDP port (TCP port + 1000)

Transaction Transfer (TCP)

  • Sender creates signed block
  • Block sent to receiver's TCP port
  • Receiver validates signature and updates balance
  • Both wallets persist the transaction

Blockchain

Each block contains:

  • Index, sender/receiver public keys, amount
  • Timestamp, nonce, previous hash
  • Transaction ID (SHA-256 of block data)
  • Ed25519 signature

Validation includes:

  • Signature verification
  • Timestamp tolerance check
  • Previous hash chain verification
  • Double-spend prevention

File Structure

wallets/
  <wallet-name>/
    keys.json       # Ed25519 keypair and fingerprint
    state.json      # Balance and last sender hashes
    ledger.json     # Full blockchain

Development

Build

make build

Clean

make clean

Project Structure

.
├── main.go         # Core wallet implementation
├── go.mod          # Go module definition
├── Makefile        # Build automation
└── README.md       # Documentation

Security Considerations

  • Ed25519 signatures prevent transaction forgery
  • Timestamp validation prevents replay attacks
  • Previous hash linking prevents chain manipulation
  • Private keys stored locally (never transmitted)

This is a demonstration project. For production use, additional security measures would be required including:

  • Secure key storage (hardware security modules)
  • Network encryption (TLS)
  • Consensus mechanism for distributed ledger
  • Rate limiting and DoS protection

License

MIT License - see LICENSE file for details.

Author

Built as a demonstration of P2P networking, cryptography, and blockchain concepts in Go.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors