public List <string> GetPrivateKeys(string password, List <Coin> spentCoins) { var wallet = WalletDao.GetWalletById(CurrentWallet.Id); if (MD5Helper.ToMD5(password) != wallet.Password) { throw new WTException(ExceptionCode.WrongWalletPassword, "密码错误"); } var network = NetworkOperator.Instance.Network; var addresses = spentCoins.Select(o => o.ScriptPubKey.GetDestinationAddress(network).ToString()).Distinct().ToList(); var addressInfos = AddressDao.GetByAddresses(CurrentWallet.Id, addresses); if (addressInfos.Count == 0 || addressInfos.Count != addresses.Count) { throw new WTException(ExceptionCode.AddressNotExisted, "当前钱包找不到相关比特币地址"); } var privateKeys = new List <string>(); foreach (var addr in addressInfos) { var keyPath = new KeyPath(addr.KeyPath); var rootXPrivKey = ExtKey.Parse(CurrentWallet.RootXPrivKey, network); var xPrivKey = rootXPrivKey.Derive(keyPath); var privKeyWif = xPrivKey.PrivateKey.GetWif(network).ToString(); privateKeys.Add(privKeyWif); } return(privateKeys); }
public bool Login(string pwd) { var wallet = WalletDao.GetActiveWallet(); if (MD5Helper.ToMD5(pwd) != wallet.Password) { return(false); } var mnemonicWords = CryptHelper.AESDecryptText(wallet.MnemonicWords, pwd); var result = KeyOperator.Instance.Recover(pwd, mnemonicWords); GlobalWallet.Set(new ActiveWallet { Id = wallet.Id, Name = wallet.WalletName, RootXPrivKey = result.RootExtPrivKeyWif, RootXPubKey = result.RootExtPubKeyWif }); return(true); }
public MnemonicResult CreateWallet(string password) { var result = KeyOperator.Instance.CreateMnemonicRoot(password); var mnemonic = string.Join(" ", result.MnemonicWords); var wallet = new WalletInfo { Id = Guid.NewGuid().ToString("N"), WalletName = "Wallet_" + DateTime.Now.ToString("yyyyMMddHHmm"), Password = MD5Helper.ToMD5(password), MnemonicWords = CryptHelper.AESEncryptText(mnemonic, password) }; var rootAddress = new AddressInfo { Id = Guid.NewGuid().ToString("N"), Address = result.RootAddress, ExtPubKeyWif = result.RootExtPubKeyWif, WalletId = wallet.Id, Network = result.Network, KeyPath = null, AddressType = (long)CustomAddressType.Root, AddressCategory = (long)AddressCategory.Default, Name = "Coinbase" }; WalletDao.Create(wallet); AddressDao.Create(rootAddress); GlobalWallet.Set(new ActiveWallet { Id = wallet.Id, Name = wallet.WalletName, RootXPrivKey = result.RootExtPrivKeyWif, RootXPubKey = result.RootExtPubKeyWif }); return(result); }
public WalletInfo GetActiveWallet() { return(WalletDao.GetActiveWallet()); }
public bool CheckAnyWalletExisted() { return(WalletDao.AnyWalletExisted()); }
public WalletManager(WalletDao walletDao, AddressDao addressDao) { this.WalletDao = walletDao; this.AddressDao = addressDao; }
public AccountManager(WalletDao walletDao) { this.WalletDao = walletDao; }
public TransactionManager(WalletDao walletDao, AddressDao addressDao, TransactionDao TxDao) { this.WalletDao = walletDao; this.AddressDao = addressDao; this.TransactionDao = TxDao; }