Skip to content
This repository has been archived by the owner on May 27, 2019. It is now read-only.

Latest commit

 

History

History
134 lines (97 loc) · 7.64 KB

File metadata and controls

134 lines (97 loc) · 7.64 KB

WARNING: This repository is no longer maintained ⚠️

This repository will not be updated. The repository will be kept available in read-only mode.

Securing Artwork using Blockchain Digital Certificates

This code pattern is a sample auction Node.js based application that demonstrates storing base64 encoded and encrypted images on a Blockchain ledger and retrieving the same. This application launches Hyperledger Fabric network and then starts the application as a REST API server built on top of NodeSDK APIs.

Auction Blockchain Application Credits: Mohan Venkataraman, Sandeep Pulluru and Ratnakar Asara

Disclaimer: The image used in this sample demo has been downloaded from publicly available images on the internet, and the copyright belongs to the respective owners. The usage here is strictly for non-commercial purposes as sample data. We recommend that users create their own sample data as appropriate. All details used in the sample data are fictitious. The information provided in this README.md is subject to change. Also this is based out of fabric-sample balance-transfer example.

When the reader has completed this code pattern, he or she will understand how to:

  • Set up a Blockchain network
  • Generate a base64 encrypted image and store it on the blockchain ledger
  • Query chaincode to retrieve image and store it in a public folder

Flow

  1. Teardown any existing networks, remove any existing containers or images lying around
  2. Launch the Hyperledger Fabric network
  3. Launch the Node.js application (Rest Server wrapper of top of the NodeSDK API)
  4. Create the channel myChannel
  5. Install and instantiate the auction chaincode
  6. Invoke a transaction where the Node.js app transforms a base 64 encrypted image into a string format
  7. Store the encrypted image image on the Blockchain ledger
  8. Query ledger to get the image data by its imageID and save the image as a Thumbnail in a public folder

Prerequisites

  • Docker: 17.09.x or higher
  • Docker Compose: 1.16.1 or higher
  • jq
  • Hyperledger Fabric SDK: Enables backend to connect to IBM Blockchain service
  • Node.js packages: If expecting to run this application locally, please continue by installing Node.js runtime and NPM. Currently the Hyperledger Fabric SDK only appears to work with node v8.9.0+, but is not yet supported on node v9.0+. If your system requires newer versions of node for other projects, we'd suggest using nvm to easily switch between node versions. We did so with the following commands
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
# Place next three lines in ~/.bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
nvm install v8.9.0
nvm use 8.9.0

Included components

  • Hyperledger Fabric v1.1 Hyperledger Fabric is a platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility and scalability.

Featured technologies

Steps

  1. Clone the repo
  2. Launch Hyperledger Fabric Network and Node App
  3. Create the Network Channel and Invoke a Transaction

Step 1. Clone the repo

Clone the SecuringArt-using-Blockchain-DigitalCertificates repo locally. In a terminal, run:

git clone https://github.com/IBM/SecuringArt-using-Blockchain-DigitalCertificates

Step 2. Launch Hyperledger Fabric Network and Node App

In one terminal launch hyperledger fabric network and Node.js application (a REST Server wrapper on top of Fabric NodeSDK api) with the following command

cd SecuringArt-using-Blockchain-DigitalCertificates
./bootstrap_app.sh

The above script bootstrap_app.sh performs the following actions:

  • remove any old docker images
  • Downloads fabric images
  • restarts the Fabric network
  • Installs required node modules
  • Starts the node application on Port 4000

NOTE: You may be tempted to run http://localhost:4000 at this point - please do not do that; otherwise you will get an UnauthorizedError: No authorization token was found error. After running the bootstrap_app.sh command, immediately go to Create the Network Channel and Invoke a Transaction and run the quicketest.sh command.

Step 3. Create the Network Channel and Invoke a Transaction

In another terminal issue the following command from auction directory.

./quicktest.sh

The above script quicktest.sh performs the following actions:

  • creates a channel named mychannel & and all the peers on the network joins the channel
  • Installs & Instantiates auction chaincode
  • send an Invoke transaction. where Node.js app generates base64 encrypted image in to a string format and sends it to chaincode, then auction chaincode stores the image on the Blockchain ledger of the channel mychannel.
  • Query chaincode to get the Image data using the imageID, the image will be saved as Thumbnail and saved in public/images folder.

You should see similar results from running quicktest.sh:

  • For all the image processing & conversion refer to the Node.js code here

  • Storing an image using chaincode, refer the code snippet here

  • Please check youtube video available here: https://goo.gl/jH1uCQ

Links

Learn more

  • Blockchain Code Patterns: Enjoyed this Code Pattern? Check out our other Blockchain Code Patterns

  • Blockchain 101: Learn why IBM believes that blockchain can transform businesses, industries – and even the world. Blockchain 101

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ