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}");
            }
        }
        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}");
            }
        }
Example #3
0
        static public void convertTextToByteFile(string relPathTxt, string relPath)
        {
            string path    = IOFacilitator.homePath();
            string command = "xxd -r " + path + relPathTxt + " > " + path + relPath;

            ShellFacilitator.Bash(command);
        }
Example #4
0
 static public void createFile(Stream content, string relFilePath)
 {
     using (var fileStream = File.Create(IOFacilitator.homePath()
                                         + relFilePath))
     {
         content.CopyTo(fileStream);
     }
 }
Example #5
0
        static public string convertByteToTextFile(string relPath)
        {
            string path    = IOFacilitator.homePath() + relPath;
            string command = "xxd " + path + " > " + path + ".txt";

            ShellFacilitator.Bash(command);
            return(path + ".txt");
        }
Example #6
0
        static public void setupFolderStructure()
        {
            string command = "mkdir " + IOFacilitator.homePath();

            // create env folder
            ShellFacilitator.Bash(command + "/env");
            // create wallet_export folder
            ShellFacilitator.Bash(command + "/wallet_export");
        }
Example #7
0
 static public void createFile(string content, string relFilePath)
 {
     using (StreamWriter fileStream = new StreamWriter(
                IOFacilitator.homePath() + relFilePath))
     {
         fileStream.Write(content);
         fileStream.Flush();
     }
 }
Example #8
0
        static public void listDirectories(string relativePath)
        {
            string fullPath = IOFacilitator.homePath() + relativePath;

            string []     files = Directory.GetDirectories(fullPath);
            List <string> list  = new List <string>(files);

            list.Sort();
            foreach (string file in list)
            {
                Console.WriteLine(file.Replace(fullPath + "/", ""));
            }
        }
        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());
        }
Example #10
0
        public static async Task start()
        {
            if (IOFacilitator.directoryExists(IOFacilitator.homePath(), "wallet_export"))
            {
                Console.WriteLine("Welcome back to the indy medical client!");
            }
            else
            {
                SetupFacilitator.setupFolderStructure();
                Console.WriteLine("Welcome to the indy doctor emergency client!");
                Console.WriteLine("You can setup the environment using the command:");
                Console.WriteLine("> EHR environment setup");
                Console.WriteLine("However you have to connect to a pool first using:");
                Console.WriteLine("pool connect");
                Console.WriteLine("> Use the command `help` to list all available commands");

                if (ensurer("Would you like to create the default pool(sandbox)?\nBeaware the pool config must be created using |generate_indy_pool_transactions|"))
                {
                    await d_pool.create("sandbox");
                }
            }
            await run();
        }
Example #11
0
 static public bool fileExists(string relativePath)
 {
     return(File.Exists(IOFacilitator.homePath() + relativePath));
 }