Example #1
0
        public static walletManagement 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;

            var wallet = new walletManagement(password, walletFilePath, network);

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

            wallet.SetSeed(seedExtKey);

            return(wallet);
        }
Example #2
0
        /// <summary>
        ///     Creates a mnemonic, a seed, encrypts it and stores in the specified path.
        /// </summary>
        /// <param name="mnemonic">empty</param>
        /// <param name="password"></param>
        /// <param name="walletFilePath"></param>
        /// <param name="network"></param>
        /// <returns>WalletManagement</returns>
        public static walletManagement Create(out Mnemonic mnemonic, string password, string walletFilePath,
                                              Network network)
        {
            var wallet = new walletManagement(password, walletFilePath, network);

            mnemonic = wallet.SetSeed(password);

            var addresses = new Addresses();

            addresses.change    = new List <string>();
            addresses.receiving = new List <string>();
            foreach (var addr in wallet.GetFirstNAddresses(10, HdPathType.Change))
            {
                addresses.change.Add(addr.ToString());
            }
            foreach (var addr in wallet.GetFirstNAddresses(10, HdPathType.Receive))
            {
                addresses.receiving.Add(addr.ToString());
            }

            wallet.Save(password, walletFilePath, network, addresses);

            return(wallet);
        }