Hyperledger Fabric Setup
This guide covers the complete setup of Hyperledger Fabric for document registry and audit traceability in CCDigital.Fabric acts as a trust layer for document traceability. MySQL remains the primary transactional database, while Fabric provides immutable audit records.
Prerequisites
Before starting, ensure you have:- Docker and Docker Compose installed
curl,git, andjqutilities- Node.js LTS (for client scripts)
- Fabric binaries (
peer,orderer,configtxlator) for your selected version
Installation
Bootstrap Fabric
Run the official bootstrap script to download binaries and Docker images:Verify the binaries and image versions are compatible.
Network Setup
Start the Network
Launch the network with certificate authorities:This creates a channel for business transactions and starts peers and orderers.
Chaincode Deployment
Client Integration
MSP Identity Configuration
Define the MSP identity used by the Node.js scripts:TLS Configuration
Integration Scripts
CCDigital uses the following Node.js scripts for Fabric integration. These are referenced inFabricLedgerCliService.java and ExternalToolsProperties.java.
Available Scripts
list-docs.js
Lists documents for a specific person from the ledger.Service:
FabricLedgerCliServiceUsage:sync-db-to-ledger.js
Synchronizes all documents from MySQL to Fabric ledger.Service:
ExternalToolsServiceUsage:read-block-by-ref.js
Reads block details using a functional reference (docId).Service:
FabricAuditCliServiceConfiguration: external-tools.fabric.block-reader-scriptrecord-access-event.js
Records audit events on-chain (verification/document access).Service:
FabricAuditCliServiceConfiguration: external-tools.fabric.record-access-scriptlist-access-events.js
Lists audit events on-chain by person or globally.Configuration:
external-tools.fabric.list-access-scriptSync Scripts
- sync-all-script: Global synchronization from DB to ledger
- sync-person-script: Per-person synchronization from DB to ledger
Environment Variables
Configure the following environment variables for Fabric integration:application.properties under the external-tools.fabric.* prefix.
Synchronization
Full Synchronization
From the Admin dashboard, you can trigger a full synchronization of MySQL data to the Fabric ledger:Per-Person Synchronization
Synchronize documents for a specific person:Query and Validation
Query Documents from Ledger
TheFabricLedgerCliService provides methods to query documents:
Verify Consistency
Validate that document IDs and states in the ledger match the MySQL database:Troubleshooting
Check Peer Logs
Check Chaincode Logs
Verify Script Execution
Test script execution manually:All script executions are handled by
ExternalToolsService with configurable timeouts defined in EXTERNAL_TOOLS_TIMEOUT_SECONDS.Service References
- FabricLedgerCliService (
src/main/java/co/edu/unbosque/ccdigital/service/FabricLedgerCliService.java:35): Main service for document queries - ExternalToolsService (
src/main/java/co/edu/unbosque/ccdigital/service/ExternalToolsService.java): Generic script execution service - ExternalToolsProperties (
src/main/java/co/edu/unbosque/ccdigital/config/ExternalToolsProperties.java:24): Configuration properties - FabricAuditCliService (
src/main/java/co/edu/unbosque/ccdigital/service/FabricAuditCliService.java): Audit event recording - BlockchainTraceDetailService (
src/main/java/co/edu/unbosque/ccdigital/service/BlockchainTraceDetailService.java): Blockchain trace details
Next Steps
Configure ACA-Py
Set up ACA-Py agents for credential issuance and verification
Hyperledger Indy Setup
Configure Indy ledger for identity credentials
