A digital identity smart contract built on hyperledger fabric

Akinola Ayodeji
4 min readMay 6, 2020

--

The traditional identity systems of today are fragmented, insecure, and exclusive. Blockchain enables more secure management and storage of digital identities by providing unified, inter-operable, and tamper-proof infrastructure with key benefits to enterprises and users. This project was inspired by the Bank verification number implemented by the Central bank of Nigeria to curb illegal banking. This BVN is currently being used by other Government bodies as a means of identifying individuals E.G national identity management system.

Solution

This is a simple implementation of a digital identity system using blockchain technology and it’s built on IBM hyperledger fabric using smart contract coupled with a CLI for interacting with the network for performing a variety of actions. This solution uses RSA key pairs to encrypt user identity in the world state in the blockchain and these keys are stored inside the user wallet. A combination of letters and numbers of length 16 (C64B32C60227CC ) is generated for each user, anyone with the id can request for the user data, user can decide to grant or revoke access to their data.

NB: This project is basically for learning purpose for anyone trying to understand how hyperledger smart contract works

Prerequisites

Flow Diagram

This flow diagram depicts how users(identities) and organizations get to interact with the blockchain network via the CLI

CLI Based interaction

Get started

Install & setup docker and Golang if you don’t have them installed already

Docker: https://www.docker.com/products/docker-desktop

Golang: https://golang.org/dl/

Setup hyper ledger fabric

setup all the images needed for Hyperledger Fabric v2.0. create a new folder or a navigate to a blank folder via your CLI and run the below command

curl -sSL https://bit.ly/2ysbOFE | bash -s 2.0.0

The command above downloads and executes a bash script that will download and extract all of the platform-specific binaries you will need to set up our network and place them into the folder you navigated to. It retrieves the following platform-specific binaries:

  • configtxgen,
  • configtxlator,
  • cryptogen,
  • discover,
  • idemixgen
  • orderer,
  • peer
  • fabric-ca-client

Read more: https://hyperledger-fabric.readthedocs.io/en/release-2.0/install.html

Setup Vscode IBM Blockchain Extention

The IBM Blockchain Platform extension helps developers to create, test, and debug smart contracts, connect to Hyperledger Fabric environments, and build applications that transact on your blockchain network.

Install: https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform

Clone Solution Repository

git clone https://github.com/TheDhejavu/digital-identity

Smart contract

Install

there are two smart contracts located inside the repo that you cloned in the previous step. Javascript & Golang but the Golang is currently under development. Add Js-contract to your Vscode workspace and install it by following these steps:

Vscode IBM blockchain Extention(install)

Instantiate

Follow the following steps to instantiate the smart contract

Vscode IBM blockchain Extention(Instantiate)

Install the CLI application

From the digital-identity directory inside cli-application, navigate to the JS folder.

cd JS

Run the following command to install the application dependencies. It will take about a minute to complete:

npm install

This process is installing the key application dependencies defined in package.json

Create a global symlink for the CLI dependency with npm link.

npm link

Config files

createconfig.jsonfile in the cli-application/JS folder and add the following information

{"connectionProfileFilename":"fabric_connection.json","channelName":"mychannel","appAdmin": "admin","caName": "http://localhost:17050","contractName":"identity"
}

create fabric_connection.json file in the cli-application/JS folder and export your connection file data by clicking on the blue circled part on your vscode which is illustrated below. paste this data into your fabric_connection.json

Export connection file

CLI Commands

Enroll Admin

node enrollAdmin.js

Register User

node registerUser.js -name=<USERNAME>

Register organization

node registerOrg.js -org=<ORG_ID>

Create Identity

dig run createIdentity -u <USERNAME> -a '{ firstName: 'akinola', lastName: <LASTNAME>, userName: <USERNAME>, dob: <DOB>, residentialAddress: <ADDRESS>, email: <EMAIL>, passCode: <PASSCODE>}'

Create Organisation

dig run createOrg -u <ORG_ID> -a '{ name: <NAME>, description: <DESCRIPTION>, location: <LOCATION>, type: <TYPE_OF_ORG>, identity: <ORG_ID> }'

Query all data

dig run queryWithQueryString -u ayodeji -a '{ "selector": { }}' --query

Request for user identity

dig run requestUserIdentity -u <ORG_ID> -a '{"identityId": <ID> }'

Get Request identity

dig run getRequestedIdentity -u ayodeji -a '{ "selector": { }}' --query

Grant organization access to identity

dig run grantOrgAccessToIdentity -u ayodeji -a '{"requestId": <ID>, "orgId": <ORG_UID>}'

Check out the repo for the rest of the command

https://github.com/TheDhejavu/digital-identity

Common Errors associated with smart contract while working with Vscode blockchain Extention

1. error upgrading smart contract: chain code registration failed: container exited with 1

2. error instantiating smart contract: chain code registration failed: container exited with 1

Possible Fixes:

  1. Review your smart contract for possible syntax error
  2. Change the name of your smart contract and start a newer version with a different name and version.

Thanks. please leave a comment below if you have any questions.

--

--