public Settings() { Network = ConfigurationManager.AppSettings["Network"].ToLower() == "main" ? Network.Main : Network.TestNet; BaseUrl = ConfigurationManager.AppSettings["BaseUrl"]; Address = BitcoinAddress.GetFromBase58Data(ConfigurationManager.AppSettings["Address"]) as BitcoinAddress; NumberOfTries = Int32.Parse(ConfigurationManager.AppSettings["NumberOfTries"]); OutputDir = ConfigurationManager.AppSettings["OutputDir"]; RequiredConfirmations = Int32.Parse(ConfigurationManager.AppSettings["RequiredConfirmations"]); }
public GetWalletPubKeyResponse(byte[] bytes) { MemoryStream ms = new MemoryStream(bytes); var len = ms.ReadByte(); UncompressedPublicKey = new PubKey(ms.ReadBytes(len)); len = ms.ReadByte(); var addr = Encoding.ASCII.GetString(ms.ReadBytes(len)); Address = BitcoinAddress.GetFromBase58Data(addr); ChainCode = ms.ReadBytes(32); }
private async void bGenerate_Click(object sender, EventArgs e) { try { var dictionary = await ReadWordList(); var settings = Settings.ReadAppSettings(); var wordList = textWordList.Text; var splittedWordList = wordList.Split(new char[] { ' ' }); splittedWordList = splittedWordList.Where(c => !string.IsNullOrEmpty(c)).ToArray(); if (splittedWordList.Count() != 12) { Alert("The count of words should be exactly 12"); } else { for (int i = 0; i < 12; i++) { if (!dictionary.ContainsKey(splittedWordList[i])) { Alert(string.Format("{0} is not present in the dictionary", splittedWordList[i])); return; } } var initialKey = GenerateKeyFrom12Words(splittedWordList, dictionary); textGeneratedBitcoinPrivateKey.Text = string.Empty; if (string.IsNullOrEmpty(textBitcoinPrivateAddr.Text.Trim())) { BitcoinSecret secret = new BitcoinSecret(initialKey, settings.Network); textGeneratedBitcoinPrivateKey.Text = secret.ToWif(); var addr = secret.GetAddress(); textBitcoinPrivateAddr.Text = addr.ToString(); } else { var initialKeyBytes = initialKey.ToBytes(); BitcoinAddress addr = null; try { addr = BitcoinAddress.GetFromBase58Data(textBitcoinPrivateAddr.Text.Trim(), settings.Network) as BitcoinAddress; var bitcoinAddressFound = false; for (byte i = 0; i <= 255; i++) { var keyBytes = initialKeyBytes; keyBytes[0] = i; Key key = new Key(keyBytes); BitcoinSecret secret = new BitcoinSecret(key, settings.Network); if (secret.GetAddress() == addr) { textGeneratedBitcoinPrivateKey.Text = secret.ToWif(); bitcoinAddressFound = true; } if (i == 255) { break; } } if (!bitcoinAddressFound) { Alert("The provided address is not a valid Bitcoin address for 12 words."); } } catch (Exception exp) { Alert("Invalid address string: " + exp.ToString()); } } textGeneratedEthereumPrivateKey.Text = string.Empty; var ethPrivateAddr = textEthereumPrivateAddr.Text.Trim(); if (ethPrivateAddr != "Ethereum address to get the private key for" && !String.IsNullOrEmpty(ethPrivateAddr)) { var ethPrivateKeyFound = false; for (byte i = 0; i <= 255; i++) { var keyBytes = initialKey.ToBytes(); keyBytes[0] = i; ethPrivateAddr = ethPrivateAddr.ToLower(); var ethAccount = new Account(keyBytes.ToHex()).Address.ToLower(); if (ethAccount == ethPrivateAddr || ethAccount == string.Concat("0x", ethPrivateAddr)) { textGeneratedEthereumPrivateKey.Text = keyBytes.ToHex(); ethPrivateKeyFound = true; } if (i == 255) { break; } } if (!ethPrivateKeyFound) { Alert("The provided address is not a valid ethereum address for 12 words."); } } } } catch (Exception exp) { Alert(exp.ToString()); } }