예제 #1
0
        internal static void Write(string walletFilePath, string encryptedBitcoinPrivateKey, string chainCode, Network network)
        {
            if (File.Exists(walletFilePath))
            {
                throw new Exception("WalletFileAlreadyExists");
            }

            var content = new KeyRingStore(encryptedBitcoinPrivateKey, chainCode, network);
            var jsonSerializerconverter = new JsonSerializer();

            lock (Lock)
            {
                var directoryPath = Path.GetDirectoryName(Path.GetFullPath(walletFilePath));
                if (!string.IsNullOrEmpty(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                using (var fileWriter = File.CreateText(walletFilePath))
                {
                    jsonSerializerconverter.Serialize(fileWriter, content);
                    fileWriter.Flush();
                }

                File.SetAttributes(walletFilePath, FileAttributes.ReadOnly | FileAttributes.Hidden);
            }
        }
예제 #2
0
        private void Save(string password)
        {
            var privateKey = _seedPrivateKey.PrivateKey;
            var chainCode  = Convert.ToBase64String(_seedPrivateKey.ChainCode);
            var encryptedBitcoinPrivateKey = privateKey.GetEncryptedBitcoinSecret(password, _network).ToWif();

            KeyRingStore.Write(KeyRingFilePath, encryptedBitcoinPrivateKey, chainCode, _network.ToHiddenBitcoinNetwork());
        }
예제 #3
0
        public static KeyRing Load(string password, string walletFilePath)
        {
            var walletFileRawContent = KeyRingStore.Read(walletFilePath);

            var encryptedBitcoinPrivateKeyString = walletFileRawContent.EncryptedSeed;
            var chainCodeString = walletFileRawContent.ChainCode;
            var network         = walletFileRawContent.Network;
            var chainCode       = Convert.FromBase64String(chainCodeString);

            var wallet = new KeyRing(walletFilePath, network);

            var privateKey = Key.Parse(encryptedBitcoinPrivateKeyString, password, wallet._network);
            var seedExtKey = new ExtKey(privateKey, chainCode);

            wallet.SetSeed(seedExtKey);
            return(wallet);
        }
예제 #4
0
 public void DeleteWalletFile()
 {
     KeyRingStore.Delete(KeyRingFilePath);
 }