private void Save(string password, string walletFilePath, Network network) { if (File.Exists(walletFilePath)) { throw new Exception("WalletFileAlreadyExists"); } var directoryPath = Path.GetDirectoryName(Path.GetFullPath(walletFilePath)); if (directoryPath != null) { Directory.CreateDirectory(directoryPath); } var privateKey = _seedPrivateKey.PrivateKey; var chainCode = _seedPrivateKey.ChainCode; var encryptedBitcoinPrivateKeyString = privateKey.GetEncryptedBitcoinSecret(password, _network).ToWif(); var chainCodeString = System.Convert.ToBase64String(chainCode); var networkString = network.ToString(); WalletFileSerializer.Serialize(walletFilePath, encryptedBitcoinPrivateKeyString, chainCodeString, networkString); }
public static Safe Load(string password, string walletFilePath) { if (!File.Exists(walletFilePath)) { throw new Exception("WalletFileDoesNotExists"); } var walletFileRawContent = WalletFileSerializer.Deserialize(walletFilePath); var encryptedBitcoinPrivateKeyString = walletFileRawContent.EncryptedSeed; var chainCodeString = walletFileRawContent.ChainCode; var chainCode = System.Convert.FromBase64String(chainCodeString); Network network; var networkString = walletFileRawContent.Network; if (networkString == Network.MainNet.ToString()) { network = Network.MainNet; } else if (networkString == Network.TestNet.ToString()) { network = Network.TestNet; } else { throw new Exception("NotRecognizedNetworkInWalletFile"); } var safe = new Safe(password, walletFilePath, network); var privateKey = Key.Parse(encryptedBitcoinPrivateKeyString, password, safe._network); var seedExtKey = new ExtKey(privateKey, chainCode); safe.SetSeed(seedExtKey); return(safe); }