Skip to content

navahas/hlf-solana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hyperledger Fabric + Solana

Prerequisites

  • Docker & Docker Compose
  • Node.js and npm
  • Rust toolchain
  • Solana CLI
  • Anchor CLI

Architecture Overview

The key insight is that Fabric handles encryption/decryption and signature verification, while Solana provides transparent vote recording and state management.

┌─────────────────┐      ┌─────────────────┐     ┌─────────────────┐
│     User        │      │   Fabric HLF    │     │     Solana      │
│  (Solana Key)   │      │   (Chaincode)   │     │    (Program)    │
└─────────────────┘      └─────────────────┘     └─────────────────┘
         │                         │                        │
         │─── register(sig) —─────▶│                        │
         │◄── DH pubkey ─—─────────│                        │
         │                         │                        │
         │─── vote(option,sig) ───▶│                        │
         │                         │─── encrypted vote ────▶│
         │                         │                        │
         │─── count() ────────────▶│                        │
         │◄── results ─────────────│                        │

Flow: Register → Vote (encrypted in HLF) → Record (in Solana) → Count (decrypt in HLF)
Mermaid Diagram
sequenceDiagram
  participant User
  participant API
  participant Solana
  participant Fabric
  
  Note over Fabric: initializeTrustedParty() creates DH keypair
  
  User->>Fabric: registerUser(solanaAddress, message, signature)
  Note right of Fabric: Verify signature<br/>Generate user DH keypair
  Fabric-->>User: User DH Public Key
  
  User->>API: createPoll(pollId, options)
  API->>Fabric: createPoll(hlfPollId, creator, options)
  API->>Solana: createPoll(pollId, options, hlfPollId)
  
  User->>API: submitVote(pollId, voteOption)
  API->>Fabric: submitVote(hlfPollId, voterAddress, voteOption, message, signature)
  Note right of Fabric: Verify signature<br/>Check duplicates<br/>Encrypt vote with shared secret<br/>(user pubkey + trusted party privkey)
  Fabric-->>API: voteId
  API->>Solana: vote(pollId, option, hlfVoteId)
  Solana-->>API: Confirm transaction
  
  User->>API: countVotes(pollId)
  API->>Fabric: countVotes(hlfPollId)
  Note right of Fabric: Decrypt votes using shared secrets<br/>Tally results
  Fabric-->>API: {OptionA: count, OptionB: count}
  API-->>User: Results
Loading

QuickStart

To get the project up and running quickly, follow these steps in two separate terminal windows.

  • Terminal 1 (Hyperledger Fabric & Chaincode)
mkdir -p ./bin
ln -s "$PWD/hlf.sh" ./bin/hlf
export PATH="$PWD/bin:$PATH"
hlf install && hlf start && hlf deploy && hlf run
  • Terminal 2 (Solana Program)
cd solana-program
npm install
anchor build
anchor test
  • Extra: Cleanup & HLF help (Terminal 1)
hlf help
hlf stop

Setup Instructions

  1. Set up hlf CLI (dev-friendly)

The main script for interacing with the project is ./hlf.sh. To use it like a CLI tool(hlf), you can symlink for convenience.

Run the following from the root of the project:

mkdir -p ./bin
ln -s "$PWD/hlf.sh" ./bin/hlf

Then, add the bin directory to your shell’s PATH:

export PATH="$PWD/bin:$PATH"

Note

This export is only valid for your current shell session. If you start a new terminal, you’ll need to re-export or add it to your shell profile (~/.bashrc, ~/.zshrc).

To see all the options run hlf help

  1. Start Hyperledger Fabric Network
hlf install
hlf start

Installs Fabric Docker images/binaries, clones fabric-samples repo and start test network.

  1. Deploy & Run the Fabric chaincode
hlf deploy
hlf run

Deploys chaincode (as-a-service), installs dependencies, builds, and runs it.

  1. Run the Solana program
cd solana-program
npm install
anchor build
anchor test

About

Hybrid Voting System using Hyperledger Fabric & Solana

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •