public async Task <IActionResult> Create(string mnemonic = null, string passphrase = null) { string[] mnemonicDefault = await _walletService.CreateMnemonic(Language.English, WordCount.TwentyFour); string[] passphraseDefault = await _walletService.CreateMnemonic(Language.English, WordCount.Twelve); string joinMmnemonic = string.Join(" ", mnemonic ?? string.Join(' ', mnemonicDefault)); string joinPassphrase = string.Join(" ", passphrase ?? string.Join(' ', passphraseDefault)); string id = _walletService.CreateWallet(joinMmnemonic.ToSecureString(), joinPassphrase.ToSecureString()); var session = _walletService.SessionAddOrUpdate(new Session(id.ToSecureString(), joinPassphrase.ToSecureString())); var request = _walletService.Addresses(session.SessionId); if (!request.Success) { return(new BadRequestObjectResult(request.NonSuccessMessage)); } if (request.Result.Any() != true) { return(new NotFoundResult()); } return(new OkObjectResult(new { path = Util.WalletPath(id), identifier = id, mnemonic = joinMmnemonic, passphrase = joinPassphrase, address = request.Result })); }
public async Task <IActionResult> CreateWallet() { string[] mnemonicDefault = await _walletService.CreateMnemonic(NBitcoin.Language.English, NBitcoin.WordCount.TwentyFour); string[] passphraseDefault = await _walletService.CreateMnemonic(NBitcoin.Language.English, NBitcoin.WordCount.Twelve); string joinMmnemonic = string.Join(" ", mnemonicDefault); string joinPassphrase = string.Join(" ", passphraseDefault); string id = _walletService.CreateWallet(joinMmnemonic.ToSecureString(), joinPassphrase.ToSecureString()); var session = _walletService.SessionAddOrUpdate(new Session(id.ToSecureString(), joinPassphrase.ToSecureString())); var address = _walletService.Addresses(session.SessionId).First(); return(new OkObjectResult(new { path = Util.WalletPath(id), identifier = id, mnemonic = joinMmnemonic, passphrase = joinPassphrase, address })); }
public override async Task Execute() { _console.ForegroundColor = ConsoleColor.Magenta; _console.WriteLine("\nSeed phrase\n"); Options(out Language lang, out WordCount wCount, 3); var mnemonic = await _walletService.CreateMnemonic(lang, wCount); _console.ForegroundColor = ConsoleColor.Magenta; _console.WriteLine(""); _console.WriteLine("Passphrase"); Options(out lang, out wCount, 1); var passphrase = await _walletService.CreateMnemonic(lang, wCount); _console.WriteLine("Seed phrase: " + string.Join(" ", mnemonic)); _console.WriteLine("Passphrase: " + string.Join(" ", passphrase)); _console.ForegroundColor = ConsoleColor.White; }
public async override Task Execute() { var yesNo = Prompt.GetYesNo("Create default mnemonic and passphrase?", true, ConsoleColor.Yellow); try { if (yesNo) { var mnemonicDefault = await _walletService.CreateMnemonic(NBitcoin.Language.English, NBitcoin.WordCount.TwentyFour); var passphraseDefault = await _walletService.CreateMnemonic(NBitcoin.Language.English, NBitcoin.WordCount.Twelve); var joinMmnemonic = string.Join(" ", mnemonicDefault); var joinPassphrase = string.Join(" ", passphraseDefault); var id = _walletService.CreateWallet(joinMmnemonic.ToSecureString(), joinPassphrase.ToSecureString()); var path = Util.WalletPath(id); _console.WriteLine(); _console.WriteLine("Wallet Path:"); _console.ForegroundColor = ConsoleColor.Green; _console.WriteLine($"{path}"); _console.ForegroundColor = ConsoleColor.White; _console.WriteLine(); _console.WriteLine("Wallet ID:"); _console.ForegroundColor = ConsoleColor.Green; _console.WriteLine($"{id}"); _console.ForegroundColor = ConsoleColor.White; _console.WriteLine(); _console.WriteLine("Seed phrase:"); _console.ForegroundColor = ConsoleColor.Green; _console.WriteLine($"{joinMmnemonic}"); _console.ForegroundColor = ConsoleColor.White; _console.WriteLine(); _console.WriteLine("Passphrase:"); _console.ForegroundColor = ConsoleColor.Green; _console.WriteLine($"{joinPassphrase}"); _console.ForegroundColor = ConsoleColor.White; _console.WriteLine(); joinMmnemonic.ZeroString(); joinPassphrase.ZeroString(); } else { using var mnemonic = Prompt.GetPasswordAsSecureString("Mnemonic:", ConsoleColor.Yellow); using var passphrase = Prompt.GetPasswordAsSecureString("Passphrase:", ConsoleColor.Yellow); var id = _walletService.CreateWallet(mnemonic, passphrase); var path = Util.WalletPath(id); _console.WriteLine($"Wallet ID: {id}"); _console.WriteLine($"Wallet Path: {path}"); } } catch (Exception ex) { _console.ForegroundColor = ConsoleColor.Red; _console.WriteLine($"Please create the mnemonics first. See help for more info.\n {ex.Message}"); _console.ForegroundColor = ConsoleColor.White; } }