# Blockchain and Self Sovereign Identity to Support Quality in the Food Supply Chain
## 3 The Proposed SSI System
### On-Chain Subsystem  
The on-chain subsystem is composed of two smart contracts, _CertificationRegistry.sol_ and _CertificationVerifier.sol_. Both smart contracts were written in Solidity code and deployed in the Ethereum network. We assumed that each certification body takes care of the deployment of the _CertificationRegistry.sol_ smart contract, and of the publication of both contract address and body address. The deployment of the _CertificationVerifier.sol_ smart contract and the publication of its address is edited by a single body. In this work to test the proposed system we deployed the smart contracts in a local network, specifically Ganache, by a node.js application. In the following, the code of the two smart contracts above quoted is shown. The smart contract named _CertificationRegistry.sol_ (see Figure 3) implements a certification registry, in which each certification is represented by a variable of type _struct_. The _struct_ defines five variables. Two variables of type _address_ that define the issuer's (issuer) and the holder's addresses (holder) of the certification. A variable named signature of type _bytes_ that contains all useful data to verify the validity of a certification. Finally, the _struct_ defines two variables of type _string_, certificationName that defines the type of the issued certification and dataState that defines the state of a certification that can be Active or Revoked. All other information related to a certification are stored in the IPFS system. The _CertificationRegistry.sol_ smart contract defines a mapping named registry to store all certifications. Mapping in Solidity is seen as hash tables, hence it contains keys and map each of them to a value. In our case, registry maps keys of type _string_ to a value of type _struct_, so IPFS hash to certification data. In the code the keys are defined through the parameter _IPFShash that is the unique identifier of the certification. It is the hash that allows to uniquely identify the file stored in IPFS, hence to retrieve a precise certification. contractCertificationRegistry{ mapping(string=>Certification)publicregistry; structCertification{ addressissuer; addressholder; bytesignature; stringdataState; stringcertificationName; } zodifieronlyHolder(stringmemory_IPFShash){ require(registry[_IPFShash].holder==msg.sender,\"access denied\"); _: } addressowner; constructor(){ owner=msg.sender; } modifieronlyIssuer(){ require(msg.sender==owner,\"access denied\"); _: } functionaddCertification{ address_holder, bytesmemory_signature, stringmemory_dataState, stringmemory_IPFShash, stringmemory_certificationName } publiconlyIssuer {  registry[_IPFShash].holder=_holder; registry[_IPFShash].issuer=msg.sender; registry[_IPFShash].signature=_signature; registry[_IPFShash].dataState=_dataState; registry[_IPFShash].certificationName=_certificationName; } functionremoveCertification(stringmemory_IPFShash)onlyHolder( _IPFShash)public{ deleteregistry[_IPFShash]; } functiongetCertification(stringmemory_IPFShash)publicview returns( address, address, bytesmemory, stringmemory, stringmemory){ return(registry[_IPFShash].holder, registry[_IPFShash].issuer, registry[_IPFShash].signature, registry[_IPFShash].dataStateState, registry[_IPFShash].certificationName); } functionmodifyCertificationState(stringmemory_IPFShash, stringmemory_dataState)onlyIssuer()public{ registry[_IPFShash].dataState=_dataState; } }  
The code shows how only the issuer of the certification can add/store a certification in the register on chain. The contract defines a variable named owner of type address. When deploying a contract, _msg. sender_ is the owner of the contract. In our case, the owner is the certification body. The variable owner will have the address of the owner of the contract, hence of the certification body that originally deployed the contract. Through the onlylssuer() _modifier_, we control the behavior of the addCertification smart contract's function. This modifier allows only the contract owner to run the addCertification function.