# A Blockchain-Based Supervision Data Security Sharing Framework
## 3 Blockchain-Based Framework for Secure Sharing of Engineering Supervision Data
### Design of Smart Contract for Engineering Supervision Data Sharing
#### 3.3.2 Design of Smart Contract Algorithm
Firstly, construct the supervision data metadata \(Tx\), which mainly includes the following: uploading the user's department, file name, completion timestamp of supervision data construction, hash address that uniquely identifies the file, and digital signature. Specifically:  
\[Tx=\{N,PK,TS,CID,Sign(CID+Ts\|SK)\} \tag{4}\]  
where \(N\) refers to the file name; \(PK\) is the upload of the user public key; \(TS\) is the timestamp of the completion of supervision data construction; \(CID\) refers to the hash address that uniquely identifies the file returned by the IPFS file system; \(Sign(CID+Ts\|SK)\) refers to the user using a private key to digitally sign and verify the authenticity of uploaded data on a file hash address. After sending the metadata to the blockchain node, the signature information in the metadata is first verified. If the verification is successful, send a query request to the IPFS node, compare whether the public key of the signer in data \(D\) and \(Tx\) is the same, and ensure that the identity of the supervisor data uploader and metadata uploader is consistent. If consistent, send the metadata to the blockchain nodes for broadcasting and packaging to the blockchain system. If there is inconsistency, return the uplink failure message to the client. The metadata upload contract algorithm can be found in Algorithm 2. ```
Input: File name \(N\), user public key _Upk_, file _CID_, timestamp _Ts_, digital signature _Sign_ Output: Success or Failed  1. requestMsg = GenerateUploadRequest (_N_, _Upk_, _Ts_, _CID_, _Sign_) //Construct the request body for uploading data hash to the blockchain  2. address = pXtoAddress (_Upk_) //Convert public key to address type  3. flag = SignVerify (requestMsg. _Upk_, requestMsg. (_CID_ + \(T_{\text{S}}\|SK\))//Verify the signature  information in the request body  4. If flag! = nil[  5. return failed//Signature verification failed, message tampered with  ]  6. IpfsAddress = requestIfpsInfo (_CID_)//Retrieve the identity information of the uploader based on the summary information  7. flag = VerifyUploaderInfo (address, ipfs_Address)//Verify the identity information to ensure the consistency of the uploader's identity  If flag == false[  Return failed  ]  9. tx_hash = contractInstance.request_upload (_N_, _Upk_, _Ts_, _CID_, _Sign_). transaction ((from: address))]//Call the request_upload method in the contract to upload the file hash to the blockchain  10. return Success//Complete the upload operation
```  
**Algorithm 2**Metadata Upload  
The user sends a query request \(R\) to the blockchain, indexing it through the file _ID_, which is the unique feature value mapped to the file. After completing the query, the result is returned to the user. The query request message is defined as equation:  
\[R=\{\textit{TYPE}=\textit{``SHARE''},\textit{ID}\} \tag{5}\]  
where _SHARE_ indicates that the request is a production query request. To avoid performance degradation caused by increased query volume, this article designs a fast file retrieval framework: the supervising party node maintains a hash table _TABLE_ to achieve queries based on file _IDs_, which stores the mapping of file _IDs_ to the blockchain location where the files are located. The _TABLE_ structure is shown in equation:  
\[\textit{TABLE}=\{\textit{KEY:ID, VLAUE:}(\textit{TimeStamp,n})\} \tag{6}\]  
where _ID_ refers to the project data number that will not be duplicated globally; _Timestamp_ is the file storage timestamp, and \(n\) is the blockchain location where the query information is stored. Verify the return result of the contract by calling the size method to determine whether file data have been queried. If the query is successful, the first storage record is returned. If it fails the default string is returned. The metadata query contract algorithm can be found in Algorithm 3. ```
Input: Query request \(R\) Output: File Hash
1. if request. type == \"SHARE\" ////Determine the current request type, where \"Share\" indicates a data query request
2. If hashTable [_ID_]!