/// <summary> /// Create an Account /// </summary> /// <returns></returns> public async Task <WalletAccountResult> CreateAccount() { try { // Generate Secret var bip39 = new BIP39(); var passphrase = bip39.GenerateMnemonic(128, BIP39Wordlist.English); // Create Accounts using (var hc = new HttpClient()) { var values = new Dictionary <string, string> { { "secret", passphrase } }; var content = new FormUrlEncodedContent(values); var response = await hc.PostAsync("http://localhost:7777/api/accounts/open", content); string responseString = await response.Content.ReadAsStringAsync(); var accountResult = JsonConvert.DeserializeObject <WalletAccountResult>(responseString); accountResult.account.secret = passphrase; return(accountResult.success ? accountResult : null); } } catch (Exception e) { Console.Write("Error creating Account Exception " + e.Message); return(null); } }
/// <summary> /// Generates the key pair. /// </summary> /// <returns>The key pair.</returns> /// <param name="brainKey">Brain key.</param> public KeyPair GenerateKeyPair(string brainKey = null) { string brain_key = brainKey; if (brain_key == null) { brain_key = String.Join(" ", bip39.GenerateMnemonic(160, BIP39Wordlist.English).Split('\r').AsEnumerable <string>().Select(a => { return(a.Trim()); }).ToArray()).Trim(); } byte[] private_key_bytes = Hash.SHA256(brain_key + " " + 0); Crypto.PrivateKey privateKey = Crypto.PrivateKey.FromBytes(private_key_bytes); return(new KeyPair() { BrainKey = brain_key, PrivateKey = privateKey.ToWif(), PublicKey = privateKey.GetPublicKey().ToString() }); }
public static string GenerateMnemonic(BIP39Wordlist wordlistType, int entropyStrength = 256) { return(Bip39.GenerateMnemonic(entropyStrength, wordlistType)); }