public bool CreateAccount(string password, string accoutName) { //bitcoin wallet var bitcoinPath = System.Environment.CurrentDirectory + $"\\bitcoin{accoutName}.json"; Safe.Create(out var mnemonic, password, bitcoinPath, Network.TestNet); //Ethereum wallet var ethereumPath = System.Environment.CurrentDirectory + $"\\ethereum{accoutName}.json"; var wallet = new Nethereum.HdWallet.Wallet(Wordlist.English, WordCount.Twelve); try { SaveWalletToJsonFile(wallet, password, ethereumPath); } catch (Exception e) { } var encryptedMnemonic = Encrypt(mnemonic.ToString(), password); File.WriteAllBytes($@".\{accoutName}.txt", encryptedMnemonic); return(true); }
public static void SignOut() { // Clear wallets aggregateWallet.Clear(); mnemonicWallet = null; TournamentsMenu.SetState(TournamentsMenu.TournamentMenuState.AccountUnlockRequired); }
public void SaveWalletToJsonFile(Nethereum.HdWallet.Wallet wallet, string password, string pathfile) { var words = string.Join(" ", wallet.Words); var encryptedWords = Rijndael256.Rijndael.Encrypt(words, password, KeySize.Aes256); var date = DateTime.Now; var walletJsonData = new { encryptedWords = encryptedWords, date = date }; var json = JsonConvert.SerializeObject(walletJsonData); File.WriteAllText(pathfile, json); }
public static bool importWallet(string mnemonic, string password = "", bool makeActive = true) { mnemonicWallet = new Nethereum.HdWallet.Wallet(mnemonic, password); if (makeActive) { _currentAddress = mnemonicWallet.GetAccount(0).Address; } return(true); }
public virtual string GetAddress(long aIndex) { var lKey = new Nethereum.Signer.EthECKey(GetIndexKey(aIndex)); // may need to fix this to support the new keygen var lWallet = new Nethereum.HdWallet.Wallet(HexStringToByteArray(GetIndexKey(0))); var lAddress = lWallet.GetAccount((int)aIndex).Address; // do not lower case as it has checksum if (!FAddresses.ContainsKey(lAddress.ToLower())) // lowercase here for look up { FAddresses.Add(lAddress.ToLower(), aIndex); } return(lAddress); }
private void button2_Click(object sender, EventArgs e) { var mnemonic = richTextBox1.Text.Trim(); var wallet = new Nethereum.HdWallet.Wallet(mnemonic, string.Empty); var account = wallet.GetAccount(0); var loginForm = new LoggedInForm(account, EthereumServer); loginForm.Show(); Close(); }
public override bool RestoreWallet(string walletName, string words, string password) { try { var wallet = new Nethereum.HdWallet.Wallet(words, null); var ethereumPath = System.Environment.CurrentDirectory + $"\\ethereum{walletName}.json"; CredentialService.SaveWalletToJsonFile(wallet, password, ethereumPath); CredentialService.CreateSimpleAccount(password, walletName, words); } catch (Exception e) { return(false); } return(true); }
private static void Main(string[] args) { Task.Run(() => { try { // initialize settings Init(); Console.WriteLine($"Take it easy, the console will display important messages, actually, it's running!! :)"); ConnectionFactory factory = new ConnectionFactory(); factory.UserName = ApplicationSettings.RabbitMQUsername; factory.Password = ApplicationSettings.RabbitMQPassword; factory.HostName = ApplicationSettings.RabbitMQHostname; factory.Port = ApplicationSettings.RabbitMQPort; factory.RequestedHeartbeat = 60; factory.DispatchConsumersAsync = true; var connection = factory.CreateConnection(); var channel = connection.CreateModel(); channel.QueueDeclare(queue: ApplicationSettings.UserRegistrationQueueName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); var consumer = new AsyncEventingBasicConsumer(channel); consumer.Received += async(model, ea) => { UserRegistrationResponse response = new UserRegistrationResponse { IsSucceded = true, ResultId = (int)UserRegistrationResponseEnum.Success }; // forced-to-disposal WalletRegistrationInfo walletInfo = null; NBitcoin.Wordlist nwordlist = null; Nethereum.HdWallet.Wallet wallet = null; Nethereum.Web3.Accounts.Account account = null; string jsonDecrypted = string.Empty; string jsonEncrypted = string.Empty; User user = null; UserActivationDataHelper userActivationDataHelper = null; MailHelper mailHelper = null; try { byte[] body = ea.Body; var message = Encoding.UTF8.GetString(body); var decrypted = string.Empty; decrypted = NETCore.Encrypt.EncryptProvider.AESDecrypt(message, secret); var obj_decrypted = JsonConvert.DeserializeObject <UserRegistrationMessage>(decrypted); var aeskey_wallet = NETCore.Encrypt.EncryptProvider.CreateAesKey(); var key_wallet = aeskey_wallet.Key; nwordlist = new NBitcoin.Wordlist(wordlist.ToArray(), ' ', "english"); wallet = new Nethereum.HdWallet.Wallet(nwordlist, NBitcoin.WordCount.Eighteen, key_wallet); account = wallet.GetAccount(0); walletInfo = new WalletRegistrationInfo(); walletInfo.address = account.Address; walletInfo.privateKey = account.PrivateKey; walletInfo.password = key_wallet; walletInfo.mnemonic = string.Join(" ", wallet.Words); jsonDecrypted = JsonConvert.SerializeObject(walletInfo); var aeskey_data = NETCore.Encrypt.EncryptProvider.CreateAesKey(); var key_data = aeskey_data.Key; jsonEncrypted = NETCore.Encrypt.EncryptProvider.AESEncrypt(jsonDecrypted, key_data); string identicon = string.Empty; try { Identicon.FromValue($"{account.Address}", size: 160).SaveAsPng($"{account.Address}.png"); byte[] binary = System.IO.File.ReadAllBytes($"{account.Address}.png"); identicon = Convert.ToBase64String(binary); System.IO.File.Delete($"{account.Address}.png"); Console.WriteLine($">> Identicon deleted from local storage"); } catch (Exception ex) { Console.WriteLine($">> Exception: {ex.Message}, StackTrace: {ex.StackTrace}"); if (ex.InnerException != null) { Console.WriteLine($">> Inner Exception Message: {ex.InnerException.Message}, Inner Exception StackTrace: {ex.InnerException.StackTrace}"); } try { System.IO.File.Delete($"{account.Address}.png"); Console.WriteLine($">> Identicon deleted from local storage"); } catch { } } userActivationDataHelper = new UserActivationDataHelper(mongoDBConnectionInfo); // get user by email user = userActivationDataHelper.GetUser(obj_decrypted.email); if (user != null) { throw new BusinessException((int)UserRegistrationResponseEnum.FailedEmailAlreadyExists); } user = new User(); user.fullname = obj_decrypted.fullname; user.email = obj_decrypted.email; user.address = account.Address; user.dataenc = jsonEncrypted; user.datakey = key_data; user.identicon = identicon; // register user await userActivationDataHelper.RegisterUserAsync(user); mailHelper = new MailHelper(); // send email await mailHelper.SendRegistrationEmailAsync(user.email, user.fullname); Console.WriteLine($">> Email: {user.email} activated successfully"); channel.BasicAck(ea.DeliveryTag, false); Console.WriteLine($">> Acknowledgement completed, delivery tag: {ea.DeliveryTag}"); } catch (Exception ex) { if (ex is BusinessException) { response.IsSucceded = false; response.ResultId = ((BusinessException)ex).ResultId; string message = EnumDescription.GetEnumDescription((UserRegistrationResponseEnum)response.ResultId); Console.WriteLine($">> Message information: {message}"); } else { Console.WriteLine($">> Exception: {ex.Message}, StackTrace: {ex.StackTrace}"); if (ex.InnerException != null) { Console.WriteLine($">> Inner Exception Message: {ex.InnerException.Message}, Inner Exception StackTrace: {ex.InnerException.StackTrace}"); } } } finally { nwordlist = null; wallet = null; account = null; walletInfo = null; jsonDecrypted = null; jsonEncrypted = null; user = null; userActivationDataHelper.Dispose(); mailHelper.Dispose(); } }; String consumerTag = channel.BasicConsume(ApplicationSettings.UserRegistrationQueueName, false, consumer); } catch (Exception ex) { Console.WriteLine($">> Exception: {ex.Message}, StackTrace: {ex.StackTrace}"); if (ex.InnerException != null) { Console.WriteLine($">> Inner Exception Message: {ex.InnerException.Message}, Inner Exception StackTrace: {ex.InnerException.StackTrace}"); } } }); // handle Control+C or Control+Break Console.CancelKeyPress += (o, e) => { Console.WriteLine("Exit"); // allow the manin thread to continue and exit... waitHandle.Set(); }; // wait waitHandle.WaitOne(); }
private byte[] GetBinaryPrivateKey(long aIndex) { var lWallet = new Nethereum.HdWallet.Wallet(HexStringToByteArray(GetIndexKey(0))); return(lWallet.GetPrivateKey((int)aIndex)); }