Skip to content

SLUDI/SLUDI-Chaincode-Go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hyperledger Fabric Go Chaincode - SLUDI

Overview

This repository contains the Go implementation of the Sri Lanka Unique Digital Identity (SLUDI) chaincode for Hyperledger Fabric networks. The chaincode manages Decentralized Identifiers (DIDs), Verifiable Credentials, Organization Users, and Authentication Logs.

Features

  • DID Management: Create, update, deactivate, and query Decentralized Identifiers
  • Verifiable Credentials: Issue, revoke, verify, and query credentials
  • Organization Users: Register, update, revoke, and restore organization users
  • Authentication Logging: Log and query authentication events
  • System Statistics: Track system-wide metrics

Prerequisites

Component Version Installation Guide
Go 1.21+ Go Installation
Docker 20.10+ Docker Docs
Fabric Samples 2.5+ Fabric Docs

πŸ“¦ Install Fabric Binaries

To download Hyperledger Fabric CLI tools and Docker images:

curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.5.0 1.5.6
  • test-network directory should be at the same level of the project directory

Project Structure

SLUDI-Chaincode-Go/
β”œβ”€β”€ entities/              # Data structures
β”‚   β”œβ”€β”€ did_document.go
β”‚   β”œβ”€β”€ verifiable_credential.go
β”‚   β”œβ”€β”€ authentication_log.go
β”‚   β”œβ”€β”€ organization_user.go
β”‚   └── supporting_types.go
β”œβ”€β”€ contract/              # Smart contract functions
β”‚   β”œβ”€β”€ sludi_contract.go
β”‚   └── org_auth_functions.go
β”œβ”€β”€ main.go               # Entry point
β”œβ”€β”€ go.mod                # Go module definition
β”œβ”€β”€ Dockerfile            # Container build file
└── README.md             # This file

Development Setup

1. Install Dependencies

cd SLUDI-Chaincode-Go
go mod tidy

2. Build the Chaincode

go build

3. Run Tests (if available)

go test ./... -v

Scripts

The scripts/ directory contains deployment and testing utilities:

  • deploy.sh - Main deployment script (start/update modes)
  • test-chaincode.sh - Comprehensive testing with 12 test cases
  • package.sh - Build and package chaincode

See scripts/README.md for detailed usage instructions.

Quick Start

# Navigate to test-network
cd /path/to/fabric-samples/test-network

# Deploy chaincode
../SLUDI-Chaincode/SLUDI-Chaincode-Go/scripts/deploy.sh start 1.0

# Run all tests
../SLUDI-Chaincode/SLUDI-Chaincode-Go/scripts/test-chaincode.sh all

Deployment

Using Deployment Script (Recommended)

The deployment script simplifies the deployment process during development in the test network.

Script Location

scripts/deploy.sh

Script Modes

Mode Description
start Brings down any existing network, starts a new one, creates the channel, and deploys the chaincode. Use this for initial setup or network resets.
update Skips network operations and only deploys the updated chaincode. Use this during development when updating the chaincode logic frequently.

Usage

From test-network directory:

# Full network reset + deploy chaincode version 1.0
../SLUDI-Chaincode/scripts/deploy.sh start 1.0

# Only re-deploy updated chaincode as version 1.1 (no network restart)
../SLUDI-Chaincode/scripts/deploy.sh update 1.1 2

Manual Deployment

If you prefer manual deployment:

# Package the chaincode
peer lifecycle chaincode package sludi-chaincode.tar.gz \
  --path ./SLUDI-Chaincode-Go \
  --lang golang \
  --label sludi-chaincode_1.0

# Install on peer
peer lifecycle chaincode install sludi-chaincode.tar.gz

# Approve and commit (follow standard Fabric lifecycle)

Contract Functions

DID Management

  • CreateDID - Create a new DID document
  • GetDID - Retrieve a DID document
  • UpdateDID - Update DID public keys and services
  • DeactivateDID - Deactivate a DID
  • GetDIDHistory - Get DID modification history

Verifiable Credentials

  • IssueCredential - Issue a new credential
  • GetCredential - Retrieve a credential
  • RevokeCredential - Revoke a credential
  • GetCredentialsBySubject - Query credentials by subject DID
  • GetCredentialsByIssuer - Query credentials by issuer
  • VerifyCredential - Verify credential validity

Organization Users

  • RegisterOrganizationUser - Register a new user
  • GetOrganizationUser - Retrieve user details
  • UpdateOrganizationUser - Update user information
  • RevokeOrganizationUser - Revoke user access
  • RestoreOrganizationUser - Restore revoked user

Authentication

  • LogAuthentication - Log an authentication event
  • GetAuthenticationLog - Retrieve authentication log
  • GetAuthenticationLogsByUser - Query logs by user DID

System

  • InitLedger - Initialize the ledger
  • GetSystemStats - Get system statistics

Example Usage

Create a DID

peer chaincode invoke -C sludi-channel -n sludi-chaincode \
  -c '{"function":"CreateDID","Args":["did:sludi:123","1.0","[]","[]","[]","{\"proofType\":\"Ed25519Signature2018\",\"created\":\"2025-12-03T12:00:00Z\",\"creator\":\"did:sludi:issuer\",\"issuerDid\":\"did:sludi:issuer\",\"signatureValue\":\"abc123\"}"]}'

Get a DID

peer chaincode query -C sludi-channel -n sludi-chaincode \
  -c '{"function":"GetDID","Args":["did:sludi:123"]}'

Get System Stats

peer chaincode query -C sludi-channel -n sludi-chaincode \
  -c '{"function":"GetSystemStats","Args":[]}'

Migration from Java

This is a complete rewrite of the Java chaincode in Go. Key differences:

  • Language: Go instead of Java
  • Build System: Go modules instead of Gradle
  • Deployment: Golang chaincode type instead of Java
  • Performance: Generally faster execution and lower memory footprint

The data structures and functionality remain the same, ensuring compatibility with existing applications.

License

Apache-2.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors