# Blockchain-Enabled Privacy-Preserving Ecosystem for DNA Sequence Sharing
## Appendix A  
_Pseudocode for DNA Sharing Chaincode_  
The following pseudocode figure outlines the core logic of the Hyperledger Fabric chaincode for the DNA sharing chain, including access update and query functionalities:state: PatientAccess[patientID]//mapofpatientIDtoaccesscontrolobject -accessiblelevels: map<DNA_segment_ID,allowedOrglypes> - accessTickets: map<DNA_segment_ID, EncryptedAccessTicket> Orgly[progID] //mapoforganization(researchinstitute)IDtoitsype(classification,  
functionRegisterKcessControl(patientIDentity, e.g., // collectedbyhistoryofhealthafterverifyingpatientregistrationdetails ifcertisvalid: PatientAccess[patientID]={accessLevels:(),accessTickets:()} //(myregretationshouldinstatoryforresearchinstitutes) else: reject\"Invalidcertification\"  
functionUpdateAccessTicket(patientID,segmentID,allowedTypes): //PatientdefineswhoconcessoperationDMagement require(caller=patientID)//onlythepatientowner(owner)canupdatetheiraccess PatientAccess[patientID].accessLevels[segmentID]=allowedtypes emitEvent(\"AccessTicket(patientID,segmentID,allowedTypes)  
functionUploadAccessTicket(patientID,segmentID,encryptedficket): //AfterupladingDMttohospitalDB,patientstoretheencryptedecesspointeronchion require(caller=patientID)||caller=ministryOfHealth PatientAccess[patientID].accessTickets[segmentID]=encryptedficket emitEvent(\"AccessTicketUploaded\",patientID,segmentID)  
functionQueryData(requesterorgUI, optionaltags): //Researcher requestsaccesstodata(optionallyfilteredbysbys(likediseaseor demographic) requesterType=Orgly[requesterorgID]//c.g., \"hospital\", \"Rowagency\" resultTickets=[] foreachpatientIDinPatientAccess: foreachsegmentIDinPatientAccess[patientID].accessLevels: allowedTypes=PatientAccess[patientID].accessLevels[segmentID] ticket=PatientAccess[patientID].accessLevels[segmentID] ifrequesterTypein allowedTypesandtickets  
* On-Chain Identity Creation: Upon confirmation, the registration transaction is sent to the IdentityManager contract, where the Ministry's node verifies the ID. If valid, a unique identity contract is generated and owned by the user. * UI Confirmation: The front end displays the newly created identity details. MetaMask logs the contract interaction, allowing the user to verify that the process is completed on-chain. 2. DNA Data Access Control Setup  
Objective: A patient defines who can access specific segments of their DNA data by configuring an access control object on the DNA sharing chain, as shown in Figure 10.  
Key Steps:  
* Access Control Object Registration: The patient uploads a certificate signing request (CSR) and private key. The Ministry of Health and Welfare certifies the request, creating a new on-chain object to manage permissions. * Assign Permissions: Through a user-friendly table, the patient selects which research institute types (e.g., clinics, medical centers) can view each DNA segment. Clicking Save triggers an update transaction, signed via MetaMask or offline signing. * Blockchain Enforcement: The DNA sharing chain securely stores these permissions, preventing unauthorized edits. Patients can revise or revoke access at any time by submitting another signed transaction. 3. Research Institute Data Request Process  
Objective: A registered research institute queries the DNA sharing chain for authorized access to patient data. Key Steps:  
* Submit a Query: The institute enters filtering criteria (e.g., patient ID, genetic markers) and signs a transaction via MetaMask to request data access. * Permission Check: The chaincode evaluates the institute's classification against patients' access levels. If matched, it generates encrypted access tickets. * Result Display: The front end receives an event indicating which data (if any) the institute can view. 4. Data Retrieval Workflow  
Objective: The research institute downloads DNA sequences authorized in the previous step, using the encrypted access tickets.