NIT Trichy B Tech Thesis Template

Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

BIOMETRICS USING BLOCKCHAIN

A thesis submitted in partial fulfillment of the requirements for


the award of the degree of

B.Tech.

in

ELECTRONICS AND COMMUNICATION ENGINEERING

By ASHISH CHITALE (108119028)

RUSHIKESH KANAME (108119050)

DEPARTMENT OF
DEPARTMENT NAME
NATIONAL INSTITUTE OF TECHNOLOGY
TIRUCHIRAPPALLI-620015
MAY 2023
BONAFIDE CERTIFICATE

This is to certify that the project titled BIOMETRICS USING BLOCKCHAIN is


a bonafide record of the work done by

ASHISH CHITALE (108119028)


RUSHIKESH KANAME (108119050)

in partial fulfillment of the requirements for the award of the degree of Bachelor of
Technology in ELECTRONICS AND COMMUNICATION ENGINEERING of

the NATIONAL INSTITUTE OF TECHNOLOGY, TIRUCHIRAPPALLI, during


the year 2022-2023.

Dr. P. SUDHARSAN Dr. M Bhaskar


Project Guide Head of the Department

Dr. Kunwar Singh


Co Guide

Project Viva-voce held on

Internal Examiner 1 Internal Examiner 2

i
ABSTRACT

Biometrics, with its distinctiveness to every character, has been adapted as a security
authentication function by way of many establishments. These biometric information
are processed into templates that are saved on databases, and a central authority central-
izes and controls those databases. This kind of storing biometric data, or in our case fin-
gerprint template, is uneven and susceptible to many essential safety attacks, including
fake template input, template modification or deletion, and channel interception by way
of a malicious attacker. The proposed solution consists of a novel approach for secur-
ing encrypted fingerprint templates through the use of symmetric peer-to-peer networks
and symmetric encryption. Specifically, the fingerprint template is encrypted using the
Advanced Encryption Standard (AES) algorithm, and subsequently uploaded onto a
symmetrically distributed storage system called the InterPlanetary File system (IPFS).
In order to avoid the slow transaction speed associated with decentralized blockchains,
the hash of the encrypted template is stored on the Ethereum network instead of the
template itself. This ensures that only the template’s hash is stored, which helps to re-
duce costs and prevent identity theft. Results from our experiments demonstrate that
the proposed system provides a high level of security for fingerprint templates through
the use of encryption, hashing, and decentralization.
Keywords: Biometrics, Blockchain, IPFS, AES, Decentralization

ii
ACKNOWLEDGEMENT

We would like to thank the following people for their support and guidance without

whom the completion of this project in fruition would not be possible.

Dr. P. Sudharsan, our project guide, for helping us and guiding us in the course of this
project .

Dr. M. Bhaskar, the Head of the Department, Department of DEPARTMENT NAME.

Our internal reviewers, Dr. E. S. Gopi , Dr. P. Sudharsan, for their insight and advice

provided during the review sessions.

We would also like to thank our individual parents and friends for their constant support.

iii
TABLE OF CONTENTS

Title Page No.

ABSTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii

ACKNOWLEDGEMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii

TABLE OF CONTENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv

LIST OF TABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii

LIST OF FIGURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


1.2 Thesis Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.1 Blockchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 IPFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Ethereum Virtual Machine (EVM) . . . . . . . . . . . . . . . . . . . . 6

3 Literature Survey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1 Fingernail analysis management system using microscopy sensor and
blockchain technology . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.2 An Architecture for Biometric Electronic Identification Document Sys-


tem Based on Blockchain . . . . . . . . . . . . . . . . . . . . . . . . . 8

iv
3.3 Decentralized document version control using ethereum blockchain and

IPFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Cloud Data Provenance using IPFS and Blockchain Technology . . . . 9

4 Proposed Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.1 Proposed Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5 Technology Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.1 NodeJs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.2 Metamask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3 HardHat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.4 Remix Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5.5 Solidity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.6 Smart Contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.7 Advanced Encryption Standard(AES) . . . . . . . . . . . . . . . . . . 17

5.8 HTML CSS Javascript . . . . . . . . . . . . . . . . . . . . . . . . . . 17


5.8.1 HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.8.2 CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.8.3 Javascript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6 Design and Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 19


6.1 User Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

6.1.1 Taking User Input . . . . . . . . . . . . . . . . . . . . . . . . . 19


6.1.2 Preprocessing User Input . . . . . . . . . . . . . . . . . . . . . 20
6.1.3 Storing the Data On IPFS . . . . . . . . . . . . . . . . . . . . . 21

6.1.4 Upload the CID on Ethereum Test Network . . . . . . . . . . . 22


6.2 User Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2.1 Getting User Input . . . . . . . . . . . . . . . . . . . . . . . . 23

6.2.2 Retrieving the Storage Data . . . . . . . . . . . . . . . . . . . . 23


6.2.3 FingerPrint Matching . . . . . . . . . . . . . . . . . . . . . . . 24
6.2.4 SIFT Fingerprint Matching Algorithm . . . . . . . . . . . . . . 24

v
6.2.5 Authenticate User Data . . . . . . . . . . . . . . . . . . . . . . 25

7 Results and Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . 26


7.1 Cost Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.2 Time analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

7.3 Security Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

8 Conclusion and Future Scope . . . . . . . . . . . . . . . . . . . . . . . . . 29


8.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

8.2 Future Directions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

A Code Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

vi
List of Tables

7.1 Cost analysis of Traditional system . . . . . . . . . . . . . . . . . . . 26


7.2 Cost analysis of Traditional system vs cost analysis of our system . . . . 27

vii
List of Figures

2.1 Structure of a Blockchain . . . . . . . . . . . . . . . . . . . . . . . . . 5

4.1 Proposed Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

6.1 User Input Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20


6.2 Data sent to IPFS Successfully . . . . . . . . . . . . . . . . . . . . . . 21
6.3 smart contracts to upload and retrive data from Ethereum Test Net . . . 22

6.4 Data sent to Ethereum Network Successfully . . . . . . . . . . . . . . . 22


6.5 Verify user Input Form . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.6 User Verified Successfully . . . . . . . . . . . . . . . . . . . . . . . . 25

7.1 Cost analysis of our system against the Traditional system . . . . . . . . 27

7.2 Time analysis of our system against the Traditional system . . . . . . . 28

viii
Chapter 1

Introduction

Biometric refers to the measurement and analysis of an individual’s physical and behav-
ioral characteristics for the purpose of identifying and verifying their identity. Biometric
identifiers can include physical attributes such as fingerprints, facial features, iris pat-

terns, and voice recognition, or behavioral traits such as gait, keystroke dynamics, and
signature recognition.
Biometric systems provide a highly accurate means of identifying individuals. Un-

like traditional identification methods such as passwords or PINs, biometric identifiers


are unique to each individual and cannot be easily replicated or shared with others. This
makes biometric systems an effective tool for preventing fraud, identity theft, and other

forms of criminal activity.


Biometric systems are convenient and user-friendly. They eliminate the need for
individuals to remember passwords or carry physical identification cards, which can

be lost, stolen, or forgotten. Biometric systems can also be integrated into a variety
of devices, such as smartphones and laptops, making it easy for individuals to access
secure systems and services.

1.1 Problem Statement

Biometric technology is widely used by organizations to verify the identity of individ-

uals, owing to the unique and intrinsic nature of biometric traits. In this process, the
biometric traits of an individual, such as fingerprints, facial features, or iris patterns, are
scanned and transformed into digital templates that are then stored in a central database

1
controlled by a central authority.

However, this method of storing biometric data can pose a significant security risk.
One potential threat is the creation of false templates, which occurs when an attacker
creates a new biometric template that is similar enough to the original to fool the sys-

tem. Another risk is the alteration or deletion of existing templates, which can be used
to grant unauthorized access or to disrupt the system’s operations. Furthermore, the
transmission of biometric data from the user’s device to the central database can also be

intercepted by malicious parties, compromising the security and confidentiality of the


data. This is particularly concerning as biometric data is considered a sensitive form of
personal information and may be used for identity theft or other malicious purposes.

To address these concerns, we are exploring alternative solutions for storing and
transmitting biometric data. One such approach is to use blockchain technology, which
can provide a secure, decentralized, and tamper-proof method of storing and sharing

biometric data. By utilizing the distributed nature of blockchain, biometric data can
be stored across multiple nodes, reducing the risk of a single point of failure or attack.
Additionally, the use of smart contracts can enforce strict access controls and ensure the

integrity of the data.


This thesis introduces a proposed system that utilizes a peer-to-peer symmetric sys-
tem for securing fingerprint templates. The system offers several contributions, includ-

ing:

• Proposal for Decentralized Fingerprint Storage using Ethereum and IPFS Archi-

tecture.

• Make the system more cost-effective and efficient by using algorithms like data
hashing.

• To address vulnerabilities associated with distributing templates on IPFS, encryp-

tion techniques are implemented.

• The system’s efficiency and scalability are improved by uploading an IPFS ID


instead of the entire fingerprint template.

2
1.2 Thesis Structure

In order to present a well-organized and structured argument, this thesis is divided into
the following sections:

• Chapter 2: Background provides the necessary Background for following chap-


ters.

• Chapter 3: Literature Survey consists of literature survey which Provides a

comprehensive survey of the relevant literature on the topic of the thesis.

• chapter 4: Proposed Solution Outlines the research approach and methods used
in the thesis.

• Chapter 5: Technologies Used Consists of detailed information of various tech-


nologies used for this Project.

• Chapter 6: System Design and Implementation the technical details and steps

taken to build the proposed system or solution outlined in the previous chapters.

• Chapter 7:Results and Interpretation Presents the results of the research and
analyzes them in the context of the existing system.

3
Chapter 2

Background

This section provides an overview of blockchain technology and the reasons for its use.
Key features of blockchain technology that contribute to its security are also discussed.
Along with Blockchain we have discussed IPFS and Ethereum Virtual Machine also

called as EVM.

2.1 Blockchain

A blockchain is a digital ledger technology that enables secure and transparent trans-
actions among various parties in a decentralized manner. Essentially, it is a distributed
database that stores transactions in blocks, which are then linked together in a sequential

order to form a ”blockchain.” This chain of blocks provides a secure and tamper-proof
method of storing data because each block contains a unique cryptographic hash that
links it to the previous block. One of the key features of blockchain is that it is a peer-to-

peer network, meaning that there is no central authority controlling the system. Instead,
all nodes in the network maintain a copy of the ledger and work together to validate
transactions. This makes the system more resilient to attacks, as there is no single point

of failure.

4
Figure 2.1: Structure of a Blockchain

Another important aspect of blockchain is that it uses cryptography to ensure the


integrity and security of transactions. Each block in the chain contains a cryptographic
hash of the previous block, making it impossible to alter past transactions without also

altering all subsequent blocks. Additionally, transactions are verified and approved
by a network of nodes using complex algorithms and consensus mechanisms, further
ensuring the validity of the data. The most well-known implementation of blockchain

technology is the cryptocurrency Bitcoin, but the potential applications of blockchain


go far beyond just digital currencies. It has been proposed for use in a wide range of
industries, including finance, healthcare, supply chain management, and more, as a way

to increase efficiency, security, and transparency.


In the context of biometrics, blockchain technology can be used to store and man-
age biometric data in a secure and decentralized manner, reducing the risk of data

breaches and unauthorized access. By incorporating biometric authentication into the


blockchain, users can maintain control over their own data and grant access to third par-
ties as needed, while maintaining the privacy and security of their sensitive information.

2.2 IPFS

IPFS, an acronym for InterPlanetary File System, is a revolutionary protocol and net-

work that facilitates a distributed method for storing and accessing files in a decentral-

5
ized manner. This innovative technology allows for the storage of files on a network of

computers that operate on a peer-to-peer basis, which renders the system more resilient
to failures and censorship than traditional centralized file storage systems. A major
advantage of IPFS is that it allows for faster and more efficient distribution of content

as users can access the nearest copy of a file instead of relying on a single central-
ized server, which can often result in slower download speeds and service disruptions.
Moreover, IPFS uses content-based addressing, which means that files are identified by

their content, rather than their name or location. This enhances the integrity of the data
stored, as any modifications made to the content would result in a distinct address.
IPFS leverages a distributed hash table (DHT) to facilitate content routing within

the network. Whenever a file is added to the IPFS network, its hash is used to iden-
tify the nodes that store the file. As a result, nodes can efficiently locate and retrieve
files from the network based on their unique hash identifiers. IPFS has the capability

to cache frequently accessed files locally, leading to decreased network traffic and im-
proved performance. Additionally, IPFS employs cryptographic techniques to ensure
the security of content on the network. By encrypting files with their corresponding

hash, any alteration to the file would generate a different hash, making it challenging
for malicious actors to manipulate files within the network.

2.3 Ethereum Virtual Machine (EVM)

The Ethereum blockchain runs on a software environment called the Ethereum Virtual
Machine (EVM), which is responsible for executing smart contracts and processing

transactions. It is a Turing-complete virtual machine, which allows it to perform any


computation that a traditional computer can. To ensure that all nodes on the network
agree on the state of the blockchain, the EVM is designed to be deterministic. This is

achieved through the use of a consensus algorithm. Smart contracts on the Ethereum
network are written in high-level programming languages like Solidity and then com-
piled into bytecode that can be executed on the EVM. The EVM runs the bytecode in a

sandboxed environment, making sure that the code cannot access or modify the state of

6
the blockchain outside of the contract. One of the crucial features of the EVM is its abil-

ity to maintain a state transition function, which enables it to update the blockchain’s
state based on the execution of smart contracts. The EVM’s state transition function
enables the creation of complex decentralized applications that can automate various

processes and transactions. The Ethereum Virtual machine (EVM) makes it easier to
implement DApp architecture on the network.

7
Chapter 3

Literature Survey

3.1 Fingernail analysis management system using mi-


croscopy sensor and blockchain technology

In this paper, the researchers proposed a system for securing fingernail data that relied
on node.js to simulate a management center. The system used a network of data man-
agement nodes responsible for storing and processing fingernail data sent from device

nodes. To minimize the burden on nodes from storing and processing fingernail tem-
plates, the authors implemented an off-chain approach. Specifically, they adopted the
”full chain” technique for storing the pre-processed data in all data centers. The idea of

”Off Chain” preprocesing is inspired from this research paper.

3.2 An Architecture for Biometric Electronic Identifi-


cation Document System Based on Blockchain

In this paper the researchers proposed an architecture for a biometric electronic identi-

fication document (e-ID) system that utilizes blockchain technology for citizen identity
verification during various transactions such as notary, registration, tax declaration and
payment, basic health services, and registration of economic activities. The system was

proposed to solve the invasion of malicious attackers on the previous system. The sys-
tem is considered secure as it combines citizen information with their fingerprint data,
which is then uploaded onto the blockchain network to verify the identities of registered

citizens.

8
3.3 Decentralized document version control using ethereum
blockchain and IPFS

The paper introduces a framework and solution for document sharing and version con-
trol, utilizing blockchain technology to enable secure, decentralized multi-user collab-
oration with no involvement of a centralized third party. The proposed solution is based

on the Ethereum smart contract to regulate and govern the document version control
process among creators, developers, and validators, and also utilizes the IPFS (Inter-
Planetary File System) to store documents on a decentralized file system. The solution

automates essential interactions among multiple actors, including developers and ap-
provers, to facilitate efficient collaboration while ensuring security and transparency.

3.4 Cloud Data Provenance using IPFS and Blockchain


Technology

In this paper the authors propose a system to address the issue of data tampering in
cloud data storage by combining the InterPlanetary File System (IPFS) and Ethereum
network. By leveraging blockchain technology, the proposed system removes the need

for users to rely on a centralized cloud storage provider (CSSP) who may have the
power to manipulate or misuse the data for their own benefit. The use of IPFS and

Ethereum creates a decentralized and secure storage system, where data is distributed
across a network of nodes and stored immutably on the blockchain, making it resistant
to tampering or unauthorized access.

9
Chapter 4

Proposed Solution

The aforementioned systems have distinctive characteristics, primarily centered around


the elimination of centralized data storage. Some systems utilize IPFS to store raw data
on the Ethereum network, which can be cost-efficient. However, one important aspect

that some of these systems overlook is encrypting data prior to uploading it onto IPFS.
Moreover, even if the data is encrypted, storing it on the blockchain network can still be
expensive. Hence, our proposed system employs encryption on the fingerprint template

and saves the hash on IPFS, thus reducing costs while still ensuring data security.

10
4.1 Proposed Architecture

Figure 4.1: Proposed Architecture

We used image processing techniques to convert the fingerprint image to a binary for-
mat, such as black and white pixels, where black represents the fingerprint ridges and

white represents the valleys. Once we have the binary data, we will apply the AES
encryption algorithm to encrypt the data. This can be done using a software library or
a programming language that supports AES encryption. After encryption, we saved the

encrypted data to our IPFS system. The encrypted data will look like random bytes of
data and will not be readable in its encrypted form without the secret key. To decrypt

11
the data, we used the same secret key that was used for encryption and apply the AES

decryption algorithm. The decrypted data will be the same as the original binary data
obtained from the fingerprint image.
In this system, pre-processing and encryption of the fingerprint template is done

“off-chain” in order to reduce the bottleneck of the system. The IPFS works as a dis-
tributed file system, which reduces the gas price involved when deploying smart con-
tracts and executing commands on the Ethereum network. The IPFS, after successfully

storing the encrypted fingerprint template, returns a unique 46-character hash. Sub-
sequently, this hash, with the use of a smart contract, is uploaded unto the Ethereum
network. For authentication, the user data, returned from the Ethereum network, is

compared with given user input.

12
Chapter 5

Technology Used

5.1 NodeJs

Node.js is a powerful open-source JavaScript runtime environment that has become a


popular choice for developing server-side applications. It is built on top of Google’s V8
JavaScript engine, which allows it to execute JavaScript code quickly and efficiently.

Node.js was originally created by Ryan Dahl in 2009 and has since become a prominent
technology in the world of web development.
One of the key features of Node.js is its event-driven, non-blocking I/O model. This

means that Node.js applications are highly scalable and can handle a large number of
concurrent connections without compromising performance. Instead of waiting for I/O
operations to complete, Node.js uses a callback mechanism to continue executing code

while I/O operations are being processed in the background. This approach allows
Node.js to handle a large number of requests with a relatively small number of threads,
making it ideal for building real-time applications such as chat apps, online gaming

platforms, and social media platforms.


Node.js provides a rich set of built-in modules, including HTTP, file system, and
cryptography, that can be used to develop complex applications. It also has a vibrant

ecosystem of third-party modules that can be easily integrated into Node.js applications
using the Node Package Manager (npm). This has made Node.js a popular choice for
building web applications, command-line tools, and server-side scripts.

Node.js is also cross-platform, which means that it can be run on a wide variety
of operating systems, including Windows, macOS, and Linux. This makes it easy to

13
develop and deploy Node.js applications on a range of environments.

5.2 Metamask

Metamask is a cryptocurrency wallet that is used as a browser extension for Google

Chrome, Firefox, and other web browsers. It allows users to store, manage, and transfer
Ethereum and other ERC-20 tokens directly within their browser. Metamask is a non-
custodial wallet, which means that users retain control of their private keys and funds,

rather than relying on a third-party custodian.


Metamask provides a simple and user-friendly interface for interacting with decen-
tralized applications (dApps) on the Ethereum network. Users can use Metamask to

securely and conveniently access various dApps, such as decentralized exchanges, de-
centralized finance (DeFi) protocols, and blockchain-based games, without having to
leave their web browser. Metamask also provides features such as transaction history,

gas fee estimation, and customizable network settings.


Metamask uses advanced encryption techniques to ensure the security of user data
and funds. When a user creates a new Metamask wallet, a unique seed phrase is gen-

erated, which can be used to restore access to the wallet in case the device is lost or
stolen. Additionally, Metamask supports hardware wallets, such as Trezor and Ledger,
for even greater security.

5.3 HardHat

Hardhat is an open-source development environment for building and testing smart con-

tracts on the Ethereum blockchain. It is designed to make the process of developing,


deploying, and testing smart contracts easier and more efficient for developers. Hardhat
is built on top of the Ethereum Virtual Machine (EVM) and provides a range of pow-

erful features for smart contract development, including built-in support for contract
debugging, automated testing, and deployment scripts.
One of the key benefits of Hardhat is its ability to provide a local Ethereum network

for testing smart contracts. This allows developers to test their contracts in a safe and

14
controlled environment before deploying them to the main Ethereum network. Hardhat

also provides a range of tools for testing smart contracts, including a built-in testing
framework, which makes it easier to write automated tests for smart contracts.
Hardhat is highly customizable and supports a wide range of plugins, allowing de-

velopers to easily extend its capabilities. It also provides powerful command-line tools
that enable developers to quickly and easily interact with their contracts, compile them,
and deploy them to the Ethereum network. As the hardhat provides free ethereum test

network we used it for simulation and experimentation of our project.

5.4 Remix Compiler

Remix Compiler is a browser-based Solidity compiler and development environment


for creating and testing smart contracts on the Ethereum blockchain. It is an open-
source tool that provides developers with a convenient and user-friendly interface for

creating, testing, and deploying smart contracts.


Remix Compiler supports the Solidity programming language, which is widely used
for developing smart contracts on the Ethereum blockchain. It provides a range of fea-

tures, including code highlighting, syntax checking, and autocomplete, to help devel-
opers write clean and error-free Solidity code.
One of the key features of Remix Compiler is its ability to simulate and debug

smart contracts directly within the browser. This allows developers to test their con-
tracts in a safe and controlled environment before deploying them to the Ethereum
network. Remix Compiler also provides a range of testing tools, including a built-in

testing framework and a code coverage tool, to help developers ensure the quality and
reliability of their contracts.
In addition to its development and testing features, Remix Compiler also provides

tools for deploying and interacting with smart contracts on the Ethereum network. It
supports multiple networks, including the main Ethereum network, test networks such
as Rinkeby and Kovan, and local networks running on the developer’s machine.

15
5.5 Solidity

Solidity is a high-level programming language used for writing smart contracts on the
Ethereum blockchain. It was developed by the Ethereum Foundation and is designed

to be easy to learn and use, with syntax similar to that of other popular programming
languages such as JavaScript and C++.
Smart contracts are self-executing programs that run on the Ethereum blockchain

and are used to automate the exchange of assets, such as cryptocurrencies or digital
assets, without the need for intermediaries. Solidity is the most popular language used
for writing smart contracts on the Ethereum blockchain.

Solidity provides a range of features that make it well-suited for writing complex
and secure smart contracts. It includes features such as built-in data types, control
structures, and functions, as well as support for inheritance and polymorphism. Solidity

also provides a range of security features, such as function modifiers and access control,
to help developers prevent vulnerabilities in their smart contracts.
One of the key benefits of Solidity is its ability to interact with other smart con-

tracts and decentralized applications (dApps) on the Ethereum blockchain. This allows
developers to create complex applications that can interact with other applications and
services on the Ethereum network.

5.6 Smart Contracts

Smart contracts are self-executing programs that run on a blockchain network. They

are used to automate the execution of contracts and agreements between parties in a
trustless and decentralized manner.
Smart contracts are written in programming languages such as Solidity (for the

Ethereum network) and allow for the creation of rules and conditions that must be met
before the contract can be executed. These rules and conditions can be enforced auto-
matically, without the need for intermediaries such as lawyers or banks.

Smart contracts can be used in a wide range of applications, from financial transac-

16
tions and supply chain management to voting systems and real estate transactions. They

provide a secure and transparent way of executing contracts and agreements, with all
transactions recorded on the blockchain and visible to all parties.
One of the key benefits of smart contracts is that they are trustless and decentralized,

meaning that they operate without the need for a central authority or intermediary. This
makes them highly resistant to fraud, censorship, and manipulation. Smart contracts
can also reduce transaction costs and increase efficiency by automating the execution

of contracts and agreements. We used smart contracts to upload and retrieve data on
ethereum test network.

5.7 Advanced Encryption Standard(AES)

AES is a block cipher encryption algorithm that uses symmetric-key cryptography,


which means that the same secret key is used for both encryption and decryption. It

is a widely accepted and secure encryption algorithm used in various applications, such
as securing sensitive data and communications, protecting personal information, and
providing secure storage and access control.

The AES encryption algorithm operates on fixed-size blocks of plaintext, typically


128 bits in length, and can use key sizes of 128, 192, or 256 bits. It uses a series of
mathematical operations, including substitution, permutation, and XOR operations, to

transform the plaintext into ciphertext.


One of the key benefits of AES is its ability to provide a high level of security
while remaining efficient and fast in operation. It is considered one of the most secure

symmetric encryption algorithms and is widely used in various applications that require
strong encryption, such as online banking and electronic commerce.

5.8 HTML CSS Javascript

HTML, CSS, and JavaScript are three core technologies used in web development.

17
5.8.1 HTML

HTML (Hypertext Markup Language) is a markup language used to create the structure

and content of web pages. It provides a way to define the layout of a web page and
include content such as text, images, and videos. HTML documents are interpreted by
web browsers and converted into a visual representation that can be displayed to users.

5.8.2 CSS

CSS (Cascading Style Sheets) is a stylesheet language used to define the presentation
and styling of web pages written in HTML. CSS provides a way to control the layout,
typography, colors, and other visual aspects of a web page. It allows developers to

separate the presentation of a web page from its content, making it easier to maintain
and update the design of a website.

5.8.3 Javascript

JavaScript is a scripting language used to add interactivity and dynamic functionality to


web pages. It allows developers to add behavior to web pages and create interactive user

interfaces. JavaScript code is executed by web browsers and can interact with HTML
and CSS to dynamically modify the content and presentation of a web page.
Together, HTML, CSS, and JavaScript form the foundation of web development,

allowing developers to create and design web pages that are interactive, visually ap-
pealing, and responsive. They are essential tools for creating modern, dynamic, and
interactive websites and web applications.

18
Chapter 6

Design and Implementation

This section presents a comprehensive description of the implementation of our project,


which involves two key phases: user registration and user verification. Together, these
phases encompass the entire functioning of a biometric system. To develop our system,

we constructed a web application comprising both a frontend and a backend. For the
frontend, we utilized technologies such as HTML, CSS, and JavaScript, while for the
backend, we relied on Node.js technology to establish the necessary infrastructure.

6.1 User Registration

The first phase of the biometric system involves user registration, which entails gather-

ing user information such as name, email, and fingerprint. This input is then subjected
to preprocessing procedures, which comprise multiple steps, including data hashing
and encryption, before being uploaded to the IPFS desktop. Upon successful upload,

the system generates a corresponding CID that is subsequently stored on the Ethereum
blockchain.

6.1.1 Taking User Input

We created a form using Html to collect user input data like name, email and fingerprint
of the user. The details of the code are given in Appendices section.

19
Figure 6.1: User Input Form

6.1.2 Preprocessing User Input

Our proposed system incorporates a unique approach to mitigate the performance bot-

tleneck associated with directly uploading user data onto the blockchain. Specifically,
we employ an ”off-chain” preprocessing method that enhances system efficiency. The
preprocessing procedure comprises the following steps:

Fingerprint Data Hashing

Data hashing for a fingerprint image involves generating a unique fixed-size string of

characters, known as a hash value, based on the biometric features and characteristics of
the fingerprint. This hash value serves as a digital fingerprint of the biometric data and

20
can be used for various purposes, such as verifying the identity of the user and detecting

any modifications or tampering with the data.

Data Encryption

After obtaining the data hash for the fingerprint image, we apply encryption using the
AES algorithm to ensure data security before uploading it to the IPFS. This process

ensures the immutability feature of the entire system. By encrypting the template, we
render it useless to malicious attackers, since decryption without the appropriate key is
virtually impossible, even through brute-force attacks. This step serves to augment the

system’s security by adding an extra layer of protection.

6.1.3 Storing the Data On IPFS

The encrypted data is stored on the IPFS, which functions as a decentralized file system.
By leveraging IPFS, we reduce the gas price required to deploy smart contracts and
execute commands on the ethereum test network. After successfully storing the data on

IPFS, a corresponding CID or IPFS ID is generated, which we subsequently store on


the ethereum test network.

Figure 6.2: Data sent to IPFS Successfully

21
6.1.4 Upload the CID on Ethereum Test Network

After obtaining the CID, we proceed to upload it onto the Ethereum test network using

Hardhat, which is an inbuilt JavaScript library. For our simulation, we utilized Georli
as our test network, as it does not entail any real monetary expenses. We created and
deployed smart contracts for data uploading and retrieval using remix IDE. Metamask

wallet was used for deploying these smart contracts.

Figure 6.3: smart contracts to upload and retrive data from Ethereum Test Net

Figure 6.4: Data sent to Ethereum Network Successfully

22
6.2 User Verification

In this section, we will delve into user verification, which entails collecting user input
and comparing it against the encrypted user data that we possess. Since the data we

possess is encrypted, we need to decrypt it before performing the comparison. Addi-


tionally, we will explore the fingerprint matching algorithm utilized in this project.

6.2.1 Getting User Input

For User Verification also we need to get inputs from user like user email and user
fingerprint. The image below shows the same.

Figure 6.5: Verify user Input Form

6.2.2 Retrieving the Storage Data

In order to authenticate user input against the data stored in our system, it is necessary
for both sets of information to be in the same format. However, since our stored data is
encrypted, it must be decrypted prior to comparison. To encrypt the data, we utilized

23
the AES algorithm, which is a symmetric encryption method that utilizes the same key

for both encryption and decryption processes. So to decrypt the data, use the same
secret key that was used for encryption and apply the AES decryption algorithm. The
decrypted data will be the same as the original binary data obtained from the fingerprint

image.

6.2.3 FingerPrint Matching

To perform fingerprint matching, the initial step is to identify the fingerprints that need
to be compared. Next, functions are created to extract the characteristics of these im-

ages. These extracted features are then used to generate descriptors for a group of key-
points, enabling the comparison of descriptors between the images. We used SIFT fin-
ger print matching algorithm. Its an inbuilt library in Javascript. SIFT (Scale-Invariant

Feature Transform) is a popular fingerprint matching algorithm that can identify corre-
sponding keypoints between two different fingerprint images, even if they are captured
from different angles or have been subjected to certain transformations such as scal-

ing, rotation, or translation. One interesting aspect of SIFT is that it uses a technique
called the Difference of Gaussian (DoG) to detect and describe the local features in the
fingerprint images.

6.2.4 SIFT Fingerprint Matching Algorithm

SIFT (Scale-Invariant Feature Transform) is a fingerprint matching algorithm that can

match fingerprints based on their unique local features, such as ridges, valleys, and
minutiae. The algorithm works by first detecting a set of keypoints in the fingerprint
image. These keypoints are selected based on their distinctive local features and are

then described using a set of orientation and scale-invariant descriptors. The descrip-
tors are generated based on the local gradient directions and magnitudes of the im-
age patches surrounding the keypoints. Once the keypoints have been detected and

described, the algorithm matches corresponding keypoints in two different fingerprint


images by comparing their descriptors. This matching process is typically performed
using a nearest-neighbor search, where the closest matching keypoints are identified

24
based on the distance between their descriptors.

We used this algorithm because it can handle variations in fingerprint orientation,


which is a critical factor in matching fingerprints accurately. SIFT uses a technique
called orientation assignment to assign a canonical orientation to each keypoint in the

fingerprint image, allowing it to match fingerprints that have been rotated with respect
to each other. Overall, SIFT is a powerful fingerprint matching algorithm that can
effectively match fingerprints under a wide range of variations, making it a popular

choice in biometric identification systems.

6.2.5 Authenticate User Data

Upon receiving the user input, we retrieved all the stored data within our system. In our
proposed system, the user’s data is compared with all other available user data to verify

its authenticity. This verification process is used to determine whether the user’s data
is already present within the system, and if not, it is subsequently added. Furthermore,
this verification procedure can be utilized to detect the manipulation or presence of

counterfeit data. If the user is verified successfully, success verdict will be shown on
user’s screen as shown below.

Figure 6.6: User Verified Successfully

25
Chapter 7

Results and Interpretation

In this section we aim to provide a clear and detailed account of the research results
and to interpret them in light of the research questions, hypotheses, and theoretical
framework. We have categorized the performance analysis in 3 parts i.e., cost analysis,

time analysis, security analysis.

7.1 Cost Analysis

We considered various images of different sizes and got the cost of uploading them
directly on blockchain. We used Ethereum blockchain test network for this experi-
mentation. The table below represents the gas consumed to upload a file directly on

blockchain.

File Size(B) Gas Consumed in Traditional system(in gas units)


107 223559
938 465001
4610 665595
10111 1064139
12379 1383016
Table 7.1: Cost analysis of Traditional system

As indicated in the table presented earlier, the amount of gas used increases with
larger file sizes. This is due to the fact that larger files require more data to be stored

on the blockchain, which in turn necessitates more computational resources and storage
space. This increased demand for resources can result in higher fees to compensate
the network nodes for the additional processing and storage costs. Furthermore, some

26
blockchain networks may prioritize smaller transactions, leading to longer confirmation

times and higher fees for larger file uploads.


However, our proposed architecture takes a different approach by uploading the
IPFS CID, whose size remains constant at 32 bytes for every input. This means that the

amount of gas consumed in our case is constant, regardless of the size of the input. This
makes our system more efficient and scalable.

File Size(B) Gas Consumed(in gas units) Gas consumed using our System(in gas units)
107 223559 5057
938 465001 5103
4610 665595 4080
10111 1064139 5009
12379 1383016 4912

Table 7.2: Cost analysis of Traditional system vs cost analysis of our system

Figure 7.1: Cost analysis of our system against the Traditional system

7.2 Time analysis

As the size of the uploaded file increases, the processing time required for the trans-
action to be included in a block on the Ethereum blockchain also increases. This is

27
because larger files consume more gas, which in turn demands more computational re-

sources and processing time. For instance, a transaction involving the upload of a small
file of a few bytes may be processed and added to a block relatively quickly. In contrast,
a transaction involving a larger file of several megabytes could take several minutes or

even hours to be processed and included in a block, depending on the congestion of the
network and the gas price set by the user. The figure below represents time analysis of
our improved system against Traditional system.

Figure 7.2: Time analysis of our system against the Traditional system

7.3 Security Analysis

Our system employs blockchain, a highly secure technology. To enhance security, we

have incorporated AES encryption, which makes our system almost impervious to se-
curity breaches. AES-128 encryption offers a key space of 2128 , indicating that there
are 2128 potential keys that can be utilized for data decryption. Assuming that a hacker

gains access to a supercomputer capable of testing 1016 keys per second, it would still
take them around 1017 seconds, equivalent to 3.17 × 109 years, to perform a brute force
attack and test all possible keys.

28
Chapter 8

Conclusion and Future Scope

In this section we have summarized the key findings and contributions of the research
study. We have provided a concise overview of the main results, their implications,
and the significance of the research. We have given future scope for this project which

outlines potential directions for future research in the same area or related fields. The
future scope identifies gaps in the current study and suggest ways to fill those gaps.

8.1 Conclusion

Blockchain technology has revolutionized the field of research and information secu-
rity, and the proposed system represents a viable replacement for traditional fingerprint

databases. The system incorporates the use of IPFS, which is a cost-effective and dis-
tributed file system for securely storing data. Compared to other decentralized biomet-
ric architectures, the proposed method is cost-efficient. By storing only the hash of the

fingerprint recognition template on the Ethereum network, we have demonstrated how


cost-effective the system can be.
In addition to cost savings, the decentralized nature of the system provides bene-

fits such as enhanced security, accessibility, and trust. The system does not require a
dedicated database administrator, which further reduces costs. Overall, our study has
demonstrated the feasibility and advantages of merging IPFS and public blockchain to

secure encrypted fingerprint templates, with a focus on economic and performance con-
siderations. We have presented two case studies that showcase modernized methods and
protocols for fingerprint template storage, highlighting the potential of this approach to

29
improve the security and efficiency of biometric authentication systems.

8.2 Future Directions

This proposed system has the potential for future extensions, including the incorpora-

tion of a ”side chain” feature for fingerprint processing into a comprehensive authenti-
cation system. This means that the proposed system could be integrated into a larger
system that incorporates other security features such as encryption and authentication.

Another potential future extension is to develop a robust hashing function for dif-
ferent types of fingerprint processing. This would involve creating a hashing algorithm
that is optimized for processing a wide range of fingerprint data, thus improving the

accuracy and efficiency of the proposed system.


In simpler terms, the proposed system could be further developed to include addi-
tional security features and functionality, such as authentication, and the development

of a more robust hashing algorithm could enhance the accuracy and efficiency of the
system in processing fingerprint data.

30
Bibliography

[1] Shih Hsiung Lee and Chu Sing Yang. Fingernail analysis management system using

microscopy sensor and blockchain technology. International Journal of Distributed


Sensor Networks, 14(3):155014771876704, March 2018.

[2] Rafael Páez, Manuel Pérez, Gustavo Ramı́rez, Juan Montes, and Lucas Bouvarel.
An architecture for biometric electronic identification document system based on

blockchain †. Future Internet, 12(1):10, January 2020.

[3] N. Nizamuddin, K. Salah, M. Ajmal Azad, J. Arshad, and M.H. Rehman. Decen-
tralized document version control using ethereum blockchain and IPFS. Computers
&amp Electrical Engineering, 76:183–197, June 2019.

[4] Syed Saud Hasan, Nazatul Haque Sultan, and Ferdous Ahmed Barbhuiya. Cloud

data provenance using IPFS and blockchain technology. In Proceedings of the


Seventh International Workshop on Security in Cloud Computing. ACM, July 2019.

[5] Geeks for Geeks. Blockchain. https://www.geeksforgeeks.org/


Blockchain/, April 2021.

[6] Qi Yao and Huajun Zhang. Improving agricultural product traceability using

blockchain. Sensors, 22(9):3388, April 2022.

31
Appendices

32
Appendix A

Code Attachments

A.1 Register User

This part of code handles taking user input. When user enters his details in front end part
and clicks on enter button, events are fired in the back end. Those events are handled
by following functions.
1
2 % import e x p r e s s from "express" ;
3 % import m u l t e r from "multer" ;
4 % import F i n g e r p r i n t 2 from "fingerprintjs2" ;
5 % import * a s IPFS from "ipfs-core" ;
6
7 const upload = multer ( ) ;
8 c o n s t app = e x p r e s s ( ) ;
9 c o n s t node = a w a i t IPFS . c r e a t e ( ) ;
10
11 // use body-parser middleware to parse request bodies
12 app . u s e ( e x p r e s s . u r l e n c o d e d ( { e x t e n d e d : t r u e } ) ) ;
13
14 // set the view engine to ejs
15 app . s e t ( "view engine" , "ejs" ) ;
16
17 // render the form template
18 app . g e t ( "/" , ( r e q , r e s ) => {
19 r e s . r e n d e r ( "form" ) ;
20 }) ;
21

22 // handle form submission


23 app . p o s t ( "/addFingerprint" , u p l o a d . s i n g l e ( "image" ) , a s y n c ( r e q , r e s )
=> {
24 c o n s t b u f f e r = B u f f e r . from ( r e q . f i l e . b u f f e r ) ;
25 c o n s t b y t e S t r i n g = b u f f e r . t o S t r i n g ( "binary" ) ;
26

27 c o n s t f i n g e r p r i n t T e m p l a t e = F i n g e r p r i n t 2 . x64hash128 ( b y t e S t r i n g ) ;
28
29 c o n s t r e s u l t = a w a i t node . add ( {
30 p a t h : $ { r e q . body . e m a i l } . t x t ,
31 c o n t e n t : JSON . s t r i n g i f y ( {
32 name : r e q . body . name ,

33
33 e m a i l : r e q . body . e m a i l ,
34 hashedTemplate : f ing erp rin tTe mp lat e ,
35
36 }) ,
37 }) ;
38
39 console . log ( r e s u l t . cid . t o S t r i n g ( ) ) ;
40
41 c o n s t chunks = [ ] ;
42 f o r a w a i t ( c o n s t chunk o f node . c a t ( r e s u l t . c i d ) ) {
43 c h u n k s . p u s h ( chunk ) ;
44 }
45

46 c o n s t r e t r i e v e d M e t a d a t a = JSON . p a r s e ( c h u n k s . t o S t r i n g ( ) ) ;
47
48 console . log ( retrievedMetadata ) ;
49 }) ;
50
51 // start the server
52 c o n s t PORT = p r o c e s s . env . PORT | | 3 0 0 0 ;
53 app . l i s t e n ( PORT , ( ) => {
54 c o n s o l e . l o g ( S e r v e r l i s t e n i n g on p o r t $ {PORT} ) ;
55 }) ;

A.2 Data Preprocessing

In this section we have mentioned all the steps involved in data preprocessing including
data hashing and encryption. Function to decrypt the data is also incuded here.
1
2
3
4 // using canvas to encrypt the image to binary data
5 c o n s t c a n v a s = document . c r e a t e E l e m e n t ( ’canvas’ ) ;
6

7 //function to generate a random key for aes encryption


8
9 c o n s t g e n e r a t e K e y = ( k e y S i z e ) => {
10 //const keySize = 256; // key size in bits (256-bit key for AES
-256)
11 c o n s t key = C r y p t o J S . l i b . WordArray . random ( k e y S i z e / 8 ) ; // key in
WordArray format
12 c o n s t keyHex = key . t o S t r i n g ( ) ; // key in hexadecimal string
format
13 r e t u r n keyHex ;
14 }
15
16 // function to decrypt the data
17
18 c o n s t d e c r y p t D a t a = ( e n c r y p t e d S t r i n g , key ) => {
19 c o n s t d e c r y p t e d = C r y p t o J S . AES . d e c r y p t ( e n c r y p t e d S t r i n g , key ) ;
20 c o n s t d e c r y p t e d D a t a = d e c r y p t e d . t o S t r i n g ( CryptoJS . enc . Utf8 ) ;
21 return decryptedData ;
22 }
23

34
24

25 // code to convert an image to binary data using canvas


26 //Get the binary data: Use the toDataURL method of the canvas
element to get the binary data in base64 format.
27 c o n s t d a t a = c a n v a s . toDataURL ( ’registerFingerprint/jpeg’ ) ;
28 //console.log(data:${data});
29

30 //generate a key to encrypt the data


31 c o n s t key = g e n e r a t e K e y ( 1 2 8 ) ;
32 //console.log(key: ${key}\n);
33
34 // encrypt the ’data’ using aes with the help of ’key’
35 c o n s t e n c r y p t e d = C r y p t o J S . AES . e n c r y p t ( d a t a , key ) ;
36
37 // conver the data to string as it is an object now
38 const encryptedString = encrypted . toString () ;
39 //console.log(encryptedString: ${encryptedString});

A.3 Connect To IPFS


1 import { c r e a t e } from "ipfs-http-client"
2
3 // connect to ipfs daemon API server
4
5 const c l i e n t = create () ;
6
7
8 c l i e n t . i d ( ) . t h e n ( i n f o => {
9 c o n s o l e . l o g ( "Connected to IPFS with peer ID: " , i n f o . i d ) ;
10 } ) . c a t c h ( e r r o r => {
11 c o n s o l e . l o g ( "here error" ) ;
12 c o n s o l e . e r r o r ( "Error connecting to IPFS: " , e r r o r ) ;
13 }) ;
14
15

16
17
18 e x p o r t a s y n c f u n c t i o n addImageToIPFS ( i m a g e D a t a ) {
19 c o n s t a d d e d = a w a i t c l i e n t . add ( i m a g e D a t a ) ;
20 c o n s o l e . log ( added . c i d . t o S t r i n g ( ) ) ;
21 return added . c i d . t o S t r i n g ( ) ;
22 }
23
24 // function to add data on ipfs
25
26 a s y n c f u n c t i o n add ( ) {
27 c o n s t i m a g e U r l = ’https://imageurl.jpg’ ;
28 c o n s t response = await f e t c h ( imageUrl ) ;
29 c o n s t imageData = a w a i t r e s p o n s e . blob ( ) ;
30 c o n s t c i d = a w a i t addImageToIPFS ( i m a g e D a t a ) ;
31 c o n s o l e . l o g ( Image a d d e d t o IPFS w i t h CID $ { c i d } ) ;
32 }
33

34 add ( ) ;

35
A.4 FingerPrint Matching
1 // Define the fingerprints to compare
2 c o n s t f i n g e r p r i n t 1 = document . g e t E l e m e n t B y I d ( ’fingerprint1’ ) ;
3 c o n s t f i n g e r p r i n t 2 = document . g e t E l e m e n t B y I d ( ’fingerprint2’ ) ;
4
5 // Load the jsfeat library
6 j s f e a t = r e q u i r e ( ’jsfeat’ ) ;
7

8 // Define a function to detect features in a fingerprint image


9 f u n c t i o n d e t e c t F e a t u r e s ( img ) {
10 c o n s t c a n v a s = document . c r e a t e E l e m e n t ( ’canvas’ ) ;
11 c a n v a s . w i d t h = img . w i d t h ;
12 c a n v a s . h e i g h t = img . h e i g h t ;
13 c o n s t c t x = c a n v a s . g e t C o n t e x t ( ’2d’ ) ;
14 c t x . drawImage ( img , 0 , 0 ) ;
15 c o n s t i m a g e D a t a = c t x . g e t I m a g e D a t a ( 0 , 0 , img . w i d t h , img . h e i g h t ) ;
16 c o n s t j s f e a t I m g = new j s f e a t . m a t r i x t ( img . w i d t h , img . h e i g h t , j s f e a t
. U8 t | j s f e a t . C1 t ) ;
17 j s f e a t . i m g p r o c . g r a y s c a l e ( i m a g e D a t a . d a t a , img . w i d t h , img . h e i g h t ,
jsfeatImg ) ;
18 j s f e a t . imgproc . e q u a l i z e h i s t o g r a m ( j s f e a t I m g , j s f e a t I m g ) ;
19 const corners = [ ] ;
20 j s f e a t . fast corners . set threshold (20) ;
21 j s f e a t . f a s t c o r n e r s . d e t e c t ( jsfeatImg , corners , 5) ;
22 return c o r n e r s ;
23 }
24
25 // Define a function to compute descriptors for a set of keypoints
26 f u n c t i o n c o m p u t e D e s c r i p t o r s ( img , k e y p o i n t s ) {
27 c o n s t c a n v a s = document . c r e a t e E l e m e n t ( ’canvas’ ) ;
28 c a n v a s . w i d t h = img . w i d t h ;
29 c a n v a s . h e i g h t = img . h e i g h t ;
30 c o n s t c t x = c a n v a s . g e t C o n t e x t ( ’2d’ ) ;
31 c t x . drawImage ( img , 0 , 0 ) ;
32 c o n s t i m a g e D a t a = c t x . g e t I m a g e D a t a ( 0 , 0 , img . w i d t h , img . h e i g h t ) ;
33 c o n s t j s f e a t I m g = new j s f e a t . m a t r i x t ( img . w i d t h , img . h e i g h t , j s f e a t
. U8 t | j s f e a t . C1 t ) ;
34 j s f e a t . i m g p r o c . g r a y s c a l e ( i m a g e D a t a . d a t a , img . w i d t h , img . h e i g h t ,
jsfeatImg ) ;
35 c o n s t d e s c r i p t o r s = new j s f e a t . m a t r i x t ( k e y p o i n t s . l e n g t h , 1 2 8 ,
j s f e a t . U8 t | j s f e a t . C1 t ) ;
36 j s f e a t . surf . dense descriptors ( jsfeatImg , keypoints , d e s c r i p t o r s ) ;
37 return d e s c r i p t o r s ;
38 }
39
40 // Define a function to match descriptors between two images
41 function matchDescriptors ( descriptors1 , descriptors2 ) {
42 const matches = [ ] ;
43 const d i s t s = [ ] ;
44 j s f e a t . m a t u t i l . f i l l ( d i s t s , 255) ;
45 j s f e a t . imgproc . m a t c h d e s c r i p t o r s b r u t e f o r c e ( d e s c r i p t o r s 1 ,
d e s c r i p t o r s 2 , matches , d i s t s ) ;
46 const filteredMatches = [ ] ;
47 const distThreshold = 0.2;
48 f o r ( l e t i = 0 ; i < m a t c h e s . l e n g t h ; i ++) {
49 if ( dists [ i ] < distThreshold ) {

36
50 f i l t e r e d M a t c h e s . push ( matches [ i ] ) ;
51 }
52 }
53 return f i l t e r e d M a t c h e s ;
54 }
55
56 // Call the SIFT functions to compare the fingerprints
57 const keypoints1 = detectFeatures ( fingerprint1 ) ;
58 const keypoints2 = detectFeatures ( fingerprint2 ) ;
59 const descriptors1 = computeDescriptors ( fingerprint1 , keypoints1 ) ;
60 const descriptors2 = computeDescriptors ( fingerprint2 , keypoints2 ) ;
61 const matches = m at c h De s c ri p t o rs ( d e s c r i p t o r s 1 , d e s c r i p t o r s 2 ) ;
62

63 // Print the number of matches


64 console . log ( matches . l e n g t h ) ;

A.5 Smart Contracts

This sections provides the smart contracts written in solidity language. The smart con-

tracts were written and deployed using remix ide.


1
2 pragma s o l i d i t y >=0.7.0 < 0 . 9 . 0 ;
3 c o n t r a c t ImgStorage {
4
5 s t r u c t Fing {
6 s t r i n g name ;
7 string hashid ;
8 }
9
10
11 Fing [ ] d at a ;
12 f u n c t i o n p u s h ( s t r i n g memory name , s t r i n g memory h a s h i d ) p u b l i c {
13 F i n g memory f i n g 1 ;
14 f i n g 1 . name = name ;
15 fing1 . hashid = hashid ;
16 d a t a . push ( f i n g 1 ) ;
17 }
18
19
20 f u n c t i o n r e t u r n D a t a ( ) p u b l i c view r e t u r n s ( F i n g [ ] memory ) {
21 return data ;
22 }
23
24 }
25

26 % C o n t r a c t t o u p l o a d and r e t r i v e d a t a
27
28 pragma s o l i d i t y >=0.7.0 < 0 . 9 . 0 ;
29
30 c o n t r a c t ImageUpload {
31

32 / / D e c l a r e a b y t e s v a r i a b l e t o s t o r e t h e image
33 b y t e s p u b l i c image ;
34

37
35 / / D e c l a r e an e v e n t t o e m i t when a new image i s u p l o a d e d
36 e v e n t NewImage ( b y t e s i m a g e ) ;
37
38 / / F u n c t i o n t o u p l o a d t h e image t o t h e b l o c k c h a i n
39 f u n c t i o n u p l o a d I m a g e ( s t r i n g memory i m a g e ) p u b l i c {
40 image = b y t e s ( i m a g e ) ;
41 e m i t NewImage ( image ) ;
42 }
43
44 / / F u n c t i o n t o g e t t h e u p l o a d e d image
45 f u n c t i o n g e t I m a g e ( ) p u b l i c view r e t u r n s ( b y t e s memory ) {
46 r e t u r n image ;
47 }
48
49 }

38

You might also like