예제 #1
0
        public async Task <string> walletImportIpfs(string identifier,
                                                    string jsonConfig)
        {
            WalletBackupModel model =
                WalletBackupModel.importFromJson(jsonConfig);

            IpfsFacilitator ipfs = new IpfsFacilitator();

            string localPath = IOFacilitator.homePath() + "temp";

            try
            {
                // get file content
                string txt = await ipfs.getFile(model.ipfs_path, identifier);

                // create local file from ipfs content
                IOFacilitator.createFile(txt, "temp.txt");
                // convert txt to binary
                IOFacilitator.convertTextToByteFile("temp.txt", "temp");
                // import wallet into client
                string res = await walletImportLocal(identifier, localPath, model.wallet_key,
                                                     model.export_key);

                return(res);
            }
            catch (Exception e)
            {
                return($"Error: {e.Message}");
            }
        }
예제 #2
0
        public async Task <string> walletExportIpfs(
            string exportKey, string walletKey = "")
        {
            string path = IOFacilitator.homePath() + d_identifier + "WBtemp";

            try
            {
                // create export file
                await walletExportLocal(path, exportKey);

                // convert export file from byte file to txt file
                string textFilePath = IOFacilitator.convertByteToTextFile(
                    d_identifier + "WBtemp");

                // upload text file to ipfs
                IpfsFacilitator ipfs     = new IpfsFacilitator();
                string          ipfsPath = await ipfs.addFile(textFilePath);

                WalletBackupModel model = new WalletBackupModel(
                    ipfsPath,
                    d_identifier,
                    (walletKey == "" ? d_identifier : walletKey),
                    exportKey);

                model.exportToJsonFile();

                return(JsonConvert.SerializeObject(model));
            }
            catch (Exception e)
            {
                return($"Error: {e.Message}");
            }
        }
예제 #3
0
        public async Task <string> downloadEmergencyEHR()
        {
            IpfsFacilitator ipfs         = new IpfsFacilitator();
            string          encryptedEHR = await ipfs.getFile(ipfs_path, "");

            // decrypt ehr data
            CipherFacilitator cipher = new CipherFacilitator();

            cipher.setKey(encryption_key);
            cipher.setIV(encryption_iv);
            return(cipher.decrypt(encryptedEHR));
        }
예제 #4
0
        static public async Task <string> backupEHR(string walletId, string ehrJson)
        {
            // encrypt ehr data
            CipherFacilitator cipher       = new CipherFacilitator();
            string            encryptedEHR = cipher.encrypt(ehrJson);

            string relPath = walletId + "ESjson.temp";

            IOFacilitator.createFile(encryptedEHR, relPath);
            IpfsFacilitator ipfs      = new IpfsFacilitator();
            string          localPath = IOFacilitator.homePath() + relPath;
            string          ipfsPath  = await ipfs.addFile(localPath);

            ShellFacilitator.Bash("rm -f " + localPath);

            EHRBackupModel model = new EHRBackupModel(ipfsPath,
                                                      cipher.getKey(), cipher.getIV());

            model.exportToJsonFile(walletId);
            return(model.toJson());
        }