# 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  
(1) Design of contract algorithm for uploading supervision data  
The user uploads the supervision data contract and uploads the original supervision data file to the IPFS. Firstly, construct supervision data, which includes the user public key, construction time of supervision data, encrypted file data, and digital signature of the uploader. The data structure for constructing supervision data \(D\) is:  
\[D=\{PK,Ts,E(Dlog+Ts\|K),Sign(H(E(Dlog+Ts\|K))\|SK) \tag{3}\]  
where _PK_ is the user's public key; _Ts_ is the time when users construct supervision data, and the data construction time is represented using Unix timestamps; \(E(Dlog+Ts\|K)\) represents encrypting the original file _Dlog_ using the key \(K\); \(Sign(H(E(Dlog+Ts\|K))\|SK)\) means that \begin{table}
\begin{tabular}{c c c} \hline \hline
**Attribute** & **Data Type** & **Description** \\ \hline Key _ID_ & bytes32 & Key _ID_ \\ Ciphertext & bytes & Encrypted ciphertext \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Ciphertext structure. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Attribute** & **Data Type** & **Description** \\ \hline File _ID_ & unit32 & File _ID_ \\ File Name & string & File name \\ File Hash & string & File _CID_ value \\ Create Time & timestamp & File creation time \\ Owner & string & Uploader’s unit name \\ Audit Option & bool & Document review comments \\ Signature & string & File signature information \\ \hline \hline \end{tabular}
\end{table} 
Table 7: Supervision data structure. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Attribute** & **Data Type** & **Description** \\ \hline Address & address & User’s address in blockchain \\ File _ID_ & unit32 & File _ID_ \\ FileHash & string & File _CID_ value \\ PublicKey & string & Public Key \\ SecretKey & string & Private key \\ \hline \hline \end{tabular}
\end{table} 
Table 8: Contract structure. the uploader uses their own private key \(SK\) to digitally sign the encrypted file, in order to confirm the source of the data. After receiving the uploaded supervision data, the IPFS node uses the uploader's public key for signature verification. If the verification is successful, it indicates that the uploaded file data source is consistent with the user's public key source in the supervision data, and the system allows uploading. According to the CP-ABE algorithm, the attribute key \(Enck(K)\) is generated, and the file data are stored in the IPFS. The unique hash address \(CID\) that identifies the file is returned to the client. If the verification fails, the upload will be abandoned and the upload failure message is returned to the client. The algorithm for uploading supervision data is shown in Algorithm 1. ```
Input: Encrypt file data \(E(Dlog+Ts\|K)\), digital signature Sign, user public key \(Upk\), file generation timestamp \(Ts\) Output: Success or Failed 1. \(E(Dlog)=\)\(Encrypt\)\((Dlog\), \(Ts\), \(K)\) //Encrypt the original file 2. address = pkToAddress \((Upk)\)//Convert public key to address type 3. flag = SignVerify (\(PK\), Sign \((H(E(Dlog+Ts\|K))\|SK)\) //IPFS node verifies the received file information 4. If flag! = nil \(\;\) //Evaluate the validation results 5. return Failed //Signature verification failed with error message returned } 6. file_hash = uploadToIPFS \((Ek(Dlog+Ts\|K))\) //Upload the ciphertext information of the original data to IPFS 7. \(Enck(K)=\)\(Encrypt\)\((K\), \(Pa\), \(PK)\) //Generate access policy key \(Enck(K)\) based on CP-ABE algorithm 8. ipfs_hash_Enck(\(K\)) = uploadToIPFS \((Enck(K))\) //Upload the ciphertext information of the attribute key to IPFS 9. return Success //Complete the upload operation
```  
**Algorithm 1**Uploading Supervision Data  
(2) Algorithm design for metadata upload contract  
Users upload metadata to the blockchain by uploading contracts through metadata.