# Credential Backup: Clone DNA Pattern ### Prototype Version (Model and Pseudo Code) --- ## SSI-DNA #### Model ```rust [Private Entry] struct Credentials{ data: HashMap // (Title, Value) } ``` #### Zome Functions ```rust // Creating some credential-data for backing up fn create_credentials(data:HashMap){ save_data_on_sourcechain(data) } // Get credential data fn get_credentials(){ return query_sourcechain_for_credential_data } // Generate a unique NetworkId for Backup DNA fn generate_backup_networkId(secret_words:[String; 12])-> networkId{ return Hash_Function(secret_words) } // Backup Data to SSIBackup-DNA fn backup_data(backup_dna_cell:String, secret_words:[String; 12]){ data = get_credentials() Utility::encrypt_data(data,secret_words) CallTargetCell(backup_dna_cell).save_data(data) } // Restore Data to SSIBackup-DNA fn restore_backup_data(backup_dna_cell:String, secret_words:[String; 12]){ backup-data = CallTargetCell(backup_dna_cell).get_data() data = Utility::decrypt_data(backup-data,secret_words) create_credentials(data) } ``` #### Utility Functions ```rust fn encrypt_data(data:HashMap, secret_words:[String; 12])->HashMap { return asymetric-encryption(data, secret_words) } fn decrypt_data(encrypted_data: HashMap, secret_words:[String; 12]) ->HashMap{ return asymetric-decryption(data, secret_words) } ``` ___ ## SSIBackup-DNA ```rust [Public Entry] struct Credentials{ data: HashMap } ``` #### Zome Functions ```rust // Save data for backing up fn save_data(data:HashMap){ save_data_on_DHT(data) } // Get backed up data fn get_data(){ return Query_DHT() } ``` ___ ## From Test or UI #### Create Backup ```json networkId = generate_backup_networkId(secret_words); backup_dna_cell = install_Backup_DNA(netowrkId){ // Clone SSIBackup-DNA } backup_data(backup_dna_cell); ``` #### Restore Backup ```json networkId = generate_backup_networkId(secret_words); backup_dna_cell = install_Backup_DNA(netowrkId){ // Clone SSIBackup-DNA } restore_backup_data(backup_dna_cell); ``` --- ## Test Scenario: from Tryorama or UI 1. Create an agent **Alice** 2. Create an agent **Bob** as close friend of Alice 3. Alice installs SSI-DNA 4. Alice creates some credential data 5. Alice clones a SSIBackup-DNA and recieves Cellid & networkId 6. Alice backup her data to SSIBackup-DNA 9. Delay a bit for gossip 10. Assert if backup data is located in SSIBackup-DNA of Alice. 11. Bob clones SSIBackup-DNA with networkId 12. Delay a bit for gossip 13. **Assert** if backup data is located in SSIBackup-DNA of Bob. 14. Create an agent **New-Alice** 15. New-Alice install SSI-DNA 16. New-Alice clones SSIBackup-DNA with networkId 17. Delay a bit for gossip 18. New-Alice restore data 19. **Assert** if the credentail data of New-Alice == credentail data of Alice