public static Safe Load(string password, string walletFilePath) { if (!File.Exists(walletFilePath)) { throw new ArgumentException($"No wallet file found at {walletFilePath}"); } var walletFileRawContent = WalletFileSerializer.Deserialize(walletFilePath); var encryptedBitcoinPrivateKeyString = walletFileRawContent.EncryptedSeed; var chainCodeString = walletFileRawContent.ChainCode; var chainCode = Convert.FromBase64String(chainCodeString); Network network; var networkString = walletFileRawContent.Network; network = networkString == Network.Main.ToString() ? Network.Main : Network.TestNet; DateTimeOffset creationTime = DateTimeOffset.ParseExact(walletFileRawContent.CreationTime, "yyyy-MM-dd", CultureInfo.InvariantCulture); var safe = new Safe(password, walletFilePath, network, creationTime); var privateKey = Key.Parse(encryptedBitcoinPrivateKeyString, password, safe.Network); var seedExtKey = new ExtKey(privateKey, chainCode); safe.SetSeed(seedExtKey); return(safe); }
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 = Convert.FromBase64String(chainCodeString); Network network; var networkString = walletFileRawContent.Network; if (networkString == Network.Main.ToString()) { network = Network.Main; } 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); }