public IAddressableDestination GetDestination(ScriptPubKeyType type) { switch (type) { case ScriptPubKeyType.Legacy: return(Hash); case ScriptPubKeyType.Segwit: return(WitHash); case ScriptPubKeyType.SegwitP2SH: return(WitHash.ScriptPubKey.Hash); #pragma warning disable CS0618 // Type or member is obsolete case ScriptPubKeyType.TaprootBIP86: #pragma warning restore CS0618 // Type or member is obsolete #if HAS_SPAN return(GetTaprootFullPubKey()); #else throw new NotSupportedException("ScriptPubKeyType.TaprootBIP86 is not supported by .net framework"); #endif default: throw new NotSupportedException(); } }
public async Task DisplayAddressAsync(ScriptPubKeyType addressType, KeyPath keyPath, CancellationToken cancellationToken = default) { if (keyPath == null) { throw new ArgumentNullException(nameof(keyPath)); } List <string> commandArguments = new List <string>(); commandArguments.Add("--path"); commandArguments.Add(keyPath.ToString(true, "h")); switch (addressType) { case ScriptPubKeyType.Segwit: commandArguments.Add("--wpkh"); break; case ScriptPubKeyType.SegwitP2SH: commandArguments.Add("--sh_wpkh"); break; } var response = await SendCommandAsync( command : HwiCommands.DisplayAddress, commandArguments : commandArguments.ToArray(), cancellationToken).ConfigureAwait(false); if (!HwiClient.IgnoreInvalidNetwork) { HwiParser.ParseAddress(response, HwiClient.Network); } }
public BitcoinAddress GetAddress(ScriptPubKeyType type, Network network) { switch (type) { case ScriptPubKeyType.Legacy: return(this.Hash.GetAddress(network)); case ScriptPubKeyType.Segwit: if (!network.Consensus.SupportSegwit) { throw new NotSupportedException("This network does not support segwit"); } return(this.WitHash.GetAddress(network)); case ScriptPubKeyType.SegwitP2SH: if (!network.Consensus.SupportSegwit) { throw new NotSupportedException("This network does not support segwit"); } return(this.WitHash.ScriptPubKey.Hash.GetAddress(network)); default: throw new NotSupportedException("Unsupported ScriptPubKeyType"); } }
/// <summary> /// Get the balance change if you were signing this transaction. /// </summary> /// <param name="accountHDScriptPubKey">The hdScriptPubKey used to generate addresses</param> /// <param name="accountKey">The account key that will be used to sign (ie. 49'/0'/0')</param> /// <param name="accountKeyPath">The account key path</param> /// <returns>The balance change</returns> public Money GetBalance(ScriptPubKeyType scriptPubKeyType, IHDKey accountKey, RootedKeyPath accountKeyPath = null) { if (accountKey == null) { throw new ArgumentNullException(nameof(accountKey)); } return(GetBalance(new HDKeyScriptPubKey(accountKey, scriptPubKeyType), accountKey, accountKeyPath)); }
/// <summary> /// Sign all inputs which derive <paramref name="accountKey"/> of type <paramref name="scriptPubKeyType"/>. /// </summary> /// <param name="scriptPubKeyType">The way to derive addresses from the accountKey</param> /// <param name="accountKey">The account key with which to sign</param> /// <param name="sigHash">The SigHash</param> /// <returns>This PSBT</returns> public PSBT SignAll(ScriptPubKeyType scriptPubKeyType, IHDKey accountKey, SigHash sigHash = SigHash.All) { if (accountKey == null) { throw new ArgumentNullException(nameof(accountKey)); } return(SignAll(new HDKeyScriptPubKey(accountKey, scriptPubKeyType), accountKey, sigHash)); }
public BitcoinAddress GetAddress(ScriptPubKeyType scriptPubKeyType, Network network) { if (network == null) { throw new ArgumentNullException(nameof(network)); } return(PubKey.GetAddress(scriptPubKeyType, network)); }
public static IHDScriptPubKey AsHDScriptPubKey(this IHDKey hdKey, ScriptPubKeyType type) { if (hdKey == null) { throw new ArgumentNullException(nameof(hdKey)); } return(new HDKeyScriptPubKey(hdKey, type)); }
public HDKeyScriptPubKey(IHDKey hdKey, ScriptPubKeyType type) { if (hdKey == null) { throw new ArgumentNullException(nameof(hdKey)); } this.hdKey = hdKey; this.type = type; }
public Script GetScriptPubKey(ScriptPubKeyType type) { switch (type) { case ScriptPubKeyType.Legacy: return(Hash.ScriptPubKey); case ScriptPubKeyType.Segwit: return(WitHash.ScriptPubKey); case ScriptPubKeyType.SegwitP2SH: return(WitHash.ScriptPubKey.Hash.ScriptPubKey); default: throw new NotSupportedException(); } }
private KeyPath GetKeyPath(ScriptPubKeyType addressType) { switch (addressType) { case ScriptPubKeyType.Legacy: return(new KeyPath("44'/1'/0'")); case ScriptPubKeyType.Segwit: return(new KeyPath("84'/1'/0'")); case ScriptPubKeyType.SegwitP2SH: return(new KeyPath("49'/1'/0'")); default: throw new NotSupportedException(addressType.ToString()); } }
public void Finalize(string input) { int numOfBytes = input.Length / 8; byte[] bytes = new byte[numOfBytes]; for (int i = 0; i < numOfBytes; ++i) { bytes[i] = Convert.ToByte(input.Substring(8 * i, 8), 2); } Mnemonic mnem = new Mnemonic(Wordlist.English, bytes); textBox1.Text = mnem.ToString(); ExtKey hdroot = mnem.DeriveExtKey(); int addressType = 0; ScriptPubKeyType typeofAddress = ScriptPubKeyType.Segwit; if (radioButton1.Checked == true) { addressType = 44; typeofAddress = ScriptPubKeyType.Legacy; } else if (radioButton2.Checked == true) { addressType = 49; typeofAddress = ScriptPubKeyType.SegwitP2SH; } else if (radioButton3.Checked == true) { addressType = 84; } for (int i = 0; i < numericUpDown.Value; i++) { var pKey = hdroot.Derive(new KeyPath("m/" + addressType + "'/0'/0'/0/" + i)); var address = pKey.PrivateKey.PubKey.GetAddress(typeofAddress, Network.Main); if (checkBox1.Checked == false) { richTextBox1.Text += address.ToString() + "\n"; } else { richTextBox1.Text += address.ToString() + "," + pKey.PrivateKey.GetWif(Network.Main) + "\n"; } } }
static void GenerateAddress(string basePath, Network net, string words, ScriptPubKeyType scriptPubKeyType) { Mnemonic restoreNnemo = new Mnemonic(words); Console.WriteLine("GenerateAddress ########################## Start"); ExtKey masterKey = restoreNnemo.DeriveExtKey(); for (int i = 0; i < 10; i++) { //NBitcoin.KeyPath keypth = new NBitcoin.KeyPath("m/44'/0'/0'/0/" + i); NBitcoin.KeyPath keypth = new NBitcoin.KeyPath(basePath + "/0/" + i); ExtKey key = masterKey.Derive(keypth); string address = key.PrivateKey.PubKey.GetAddress(scriptPubKeyType, net).ToString(); string privateKey = key.PrivateKey.GetBitcoinSecret(net).ToString(); Console.WriteLine($" publicKey {address} , privateKey {privateKey} "); } Console.WriteLine("GenerateAddress ########################## End"); }
private async Task <PSBT> CreatePSBT(HwiTester tester, ScriptPubKeyType addressType) { var accountKeyPath = new RootedKeyPath(tester.Device.Fingerprint.Value, GetKeyPath(addressType)); var accountKey = await tester.Device.GetXPubAsync(accountKeyPath.KeyPath); Logger.LogInformation($"Signing with xpub {accountKeyPath}: {accountKey}..."); List <Transaction> knownTransactions = new List <Transaction>(); TransactionBuilder builder = accountKey.Network.CreateTransactionBuilder(); CreateCoin(builder, knownTransactions, addressType, Money.Coins(1.0m), accountKey, "0/0"); CreateCoin(builder, knownTransactions, addressType, Money.Coins(1.2m), accountKey, "0/1"); builder.Send(new Key().PubKey.GetScriptPubKey(addressType), Money.Coins(2.0m)); builder.SetChange(accountKey.Derive(new KeyPath("1/0")).ExtPubKey.PubKey.GetScriptPubKey(addressType)); builder.SendEstimatedFees(new FeeRate(1.0m)); var psbt = builder.BuildPSBT(false); psbt.AddTransactions(knownTransactions.ToArray()); psbt.AddKeyPath(accountKey, new KeyPath[] { new KeyPath("0/0"), new KeyPath("0/1"), new KeyPath("1/0") }); psbt.RebaseKeyPaths(accountKey, accountKeyPath); return(psbt); }
static void CorrectOne(string basePath, Network net, string words, ScriptPubKeyType scriptPubKeyType, string password = null) { Console.WriteLine("-------------------------------------"); Console.WriteLine($" basePath: {basePath}"); Console.WriteLine($" words: {words}"); Console.WriteLine(); //https://stackoverflow.com/questions/46550818/nbitcoin-and-mnemonic-standards Mnemonic mnemo = new Mnemonic(words, Wordlist.English); ExtKey hdroot = mnemo.DeriveExtKey(password); for (int i = 0; i < 10; i++) { var privkey = hdroot.Derive(new NBitcoin.KeyPath(basePath + "/0/" + i.ToString())); var publicKey = privkey.Neuter().PubKey; var privateKey = privkey.Neuter().GetWif(net); var address = publicKey.GetAddress(scriptPubKeyType, net).ToString(); Console.WriteLine($"{ net.ToString() } , public key : { address} , privateKey {privateKey}"); Console.WriteLine(""); } ExtKey masterKey = hdroot.Derive(new NBitcoin.KeyPath(basePath)); string masterPublicKey = masterKey.Neuter().GetWif(net).ToString(); string masterPrivateKey = masterKey.GetWif(net).ToString(); Console.WriteLine($""); Console.WriteLine($"MasterPrivateKey : {net.ToString()} {masterPrivateKey} "); Console.WriteLine($"MasterPublicKey : {net.ToString()} {masterPublicKey} "); Console.WriteLine($""); Console.WriteLine("-------------------------------------"); /* Console.WriteLine("Master key 11111 : " + hdroot.ToString(net)); * ExtPubKey masterPubKey = hdroot.Neuter(); * Console.WriteLine("Master PubKey " + masterPubKey.ToString(net)); * Console.WriteLine(); * Console.WriteLine(); */ }
public BitcoinAddress GetAddress(ScriptPubKeyType type, Network network) { switch (type) { case ScriptPubKeyType.Legacy: return(this.Hash.GetAddress(network)); case ScriptPubKeyType.Segwit: if (!network.Consensus.SupportSegwit) { throw new NotSupportedException("This network does not support segwit"); } return(this.WitHash.GetAddress(network)); case ScriptPubKeyType.SegwitP2SH: if (!network.Consensus.SupportSegwit) { throw new NotSupportedException("This network does not support segwit"); } return(this.WitHash.ScriptPubKey.Hash.GetAddress(network)); #pragma warning disable CS0618 // Type or member is obsolete case ScriptPubKeyType.TaprootBIP86: #pragma warning restore CS0618 // Type or member is obsolete if (!network.Consensus.SupportTaproot) { throw new NotSupportedException("This network does not support taproot"); } #if !HAS_SPAN throw new NotSupportedException("This feature of taproot is not supported in .NET Framework"); #else return(GetTaprootFullPubKey().GetAddress(network)); #endif default: throw new NotSupportedException("Unsupported ScriptPubKeyType"); } }
public IAddressableDestination GetDestination(ScriptPubKeyType scriptPubKeyType) { return(PubKey.GetDestination(scriptPubKeyType)); }
private DerivationStrategyBase ParseCore(string str) { bool legacy = false; bool p2sh = false; bool keepOrder = false; bool taproot = false; ScriptPubKeyType type = ScriptPubKeyType.Segwit; Dictionary <string, bool> optionsDictionary = new Dictionary <string, bool>(5); foreach (Match optionMatch in _OptionRegex.Matches(str)) { var key = optionMatch.Groups[1].Value.ToLowerInvariant(); if (!AuthorizedOptions.Contains(key)) { throw new FormatException($"The option '{key}' is not supported by this network"); } if (!optionsDictionary.TryAdd(key, true)) { throw new FormatException($"The option '{key}' is duplicated"); } } str = _OptionRegex.Replace(str, string.Empty); if (optionsDictionary.Remove("legacy")) { legacy = true; type = ScriptPubKeyType.Legacy; } if (optionsDictionary.Remove("p2sh")) { p2sh = true; type = ScriptPubKeyType.SegwitP2SH; } if (optionsDictionary.Remove("keeporder")) { keepOrder = true; } if (optionsDictionary.Remove("taproot")) { taproot = true; #pragma warning disable CS0618 // Type or member is obsolete type = ScriptPubKeyType.TaprootBIP86; #pragma warning restore CS0618 // Type or member is obsolete } if (!legacy && !_Network.Consensus.SupportSegwit) { throw new FormatException("Segwit is not supported you need to specify option '-[legacy]'"); } if (legacy && p2sh) { throw new FormatException("The option 'legacy' is incompatible with 'p2sh'"); } if (taproot) { if (!_Network.Consensus.SupportTaproot) { throw new FormatException("Taproot is not supported, you need to remove option '-[taproot]'"); } else { if (p2sh) { throw new FormatException("The option 'taproot' is incompatible with 'p2sh'"); } if (legacy) { throw new FormatException("The option 'taproot' is incompatible with 'legacy'"); } if (keepOrder) { throw new FormatException("The option 'taproot' is incompatible with 'keeporder'"); } } } var options = new DerivationStrategyOptions() { KeepOrder = keepOrder, ScriptPubKeyType = type, AdditionalOptions = new ReadOnlyDictionary <string, bool>(optionsDictionary) }; var match = MultiSigRegex.Match(str); if (match.Success) { var sigCount = int.Parse(match.Groups[1].Value); var pubKeys = match.Groups .OfType <Group>() .Skip(2) .SelectMany(g => g.Captures.OfType <Capture>()) .Select(g => new BitcoinExtPubKey(g.Value.Substring(1), Network)) .ToArray(); return(CreateMultiSigDerivationStrategy(pubKeys, sigCount, options)); } else { var key = _Network.Parse <BitcoinExtPubKey>(str); return(CreateDirectDerivationStrategy(key, options)); } }
public static OwnershipProof Generate(Key key, OwnershipIdentifier ownershipIdentifier, byte[] commitmentData, bool userConfirmation, ScriptPubKeyType scriptPubKeyType) => scriptPubKeyType switch {
private void CreateCoin(TransactionBuilder builder, List <Transaction> knownTransactions, ScriptPubKeyType addressType, Money money, BitcoinExtPubKey xpub, string path) { var pubkey = xpub.Derive(new KeyPath(path)).ExtPubKey.PubKey; if (addressType == ScriptPubKeyType.Legacy) { var prevTx = xpub.Network.CreateTransaction(); prevTx.Inputs.Add(RandomOutpoint(), new Key().ScriptPubKey); var txout = prevTx.Outputs.Add(money, pubkey.GetScriptPubKey(addressType)); var coin = new Coin(new OutPoint(prevTx, 0), txout); builder.AddCoins(coin); knownTransactions.Add(prevTx); } if (addressType == ScriptPubKeyType.Segwit) { var outpoint = RandomOutpoint(); var txout = xpub.Network.Consensus.ConsensusFactory.CreateTxOut(); txout.Value = money; txout.ScriptPubKey = pubkey.GetScriptPubKey(addressType); var coin = new Coin(outpoint, txout); builder.AddCoins(coin); } if (addressType == ScriptPubKeyType.SegwitP2SH) { var outpoint = RandomOutpoint(); var txout = xpub.Network.Consensus.ConsensusFactory.CreateTxOut(); txout.Value = money; txout.ScriptPubKey = pubkey.GetScriptPubKey(addressType); var coin = new Coin(outpoint, txout).ToScriptCoin(pubkey.GetScriptPubKey(ScriptPubKeyType.Segwit)); builder.AddCoins(coin); } }
private void Btn_CreateWallet_Click(object sender, EventArgs e) { string basePath; ScriptPubKeyType scriptPubKeyType = (ScriptPubKeyType)Cmb_ScriptPubKeyType.SelectedItem; NetworkType networkType = (NetworkType)Cmb_Network.SelectedItem; Network net = Network.Main; if (networkType == NetworkType.Mainnet) { net = Network.Main; } else if (networkType == NetworkType.Testnet) { net = Network.TestNet; } else if (networkType == NetworkType.Regtest) { net = Network.RegTest; } basePath = Path; if (string.IsNullOrWhiteSpace(basePath)) { if (net == Network.Main) { basePath = MainNetworkPath; } else { basePath = TestNetworkPath; } } Mnemonic mnemonic = new Mnemonic(Wordlist, WordCount.Twelve); string words = Txt_Words.Text.Trim(); if (string.IsNullOrWhiteSpace(words)) { words = mnemonic.ToString(); } string password = null; if (Chk_IsPassword.Checked) { password = Txt_Password.Text.Trim(); if (string.IsNullOrWhiteSpace(password)) { password = Guid.NewGuid().ToString(); } } Mnemonic mnemo = new Mnemonic(words, Wordlist); ExtKey hdroot = mnemo.DeriveExtKey(password); List <string> addresses = new List <string>(); for (int i = 0; i < 10; i++) { var privkey = hdroot.Derive(new NBitcoin.KeyPath(basePath + "/0/" + i.ToString())); var publicKey = privkey.Neuter().PubKey; var privateKey = privkey.Neuter().GetWif(net); var address = publicKey.GetAddress(scriptPubKeyType, net).ToString(); addresses.Add(address); } ExtKey masterKey = hdroot.Derive(new NBitcoin.KeyPath(basePath)); string masterPublicKey = masterKey.Neuter().GetWif(net).ToString(); string masterPrivateKey = masterKey.GetWif(net).ToString(); Txt_Address.Text = addresses[0]; Txt_Addresses.Text = string.Join("\r\n", addresses); Txt_Words.Text = words; Txt_Password.Text = password; Txt_MasterPublicKey.Text = masterPublicKey; }
public static BitcoinAddress GetAddressFromPubKey(ExtPubKey key, uint index, Network net, ScriptPubKeyType pubkeytype = ScriptPubKeyType.Legacy) { return(key.Derive(index).PubKey.GetAddress(pubkeytype, net)); }
public WalletId RegisterDerivationScheme(string crytoCode, ScriptPubKeyType segwit = ScriptPubKeyType.Legacy, bool importKeysToNBX = false) { return(RegisterDerivationSchemeAsync(crytoCode, segwit, importKeysToNBX).GetAwaiter().GetResult()); }
public BitcoinAddress GetAddress(ScriptPubKeyType type) { return(PrivateKey.PubKey.GetAddress(type, Network)); }
public async Task <WalletId> RegisterDerivationSchemeAsync(string cryptoCode, ScriptPubKeyType segwit = ScriptPubKeyType.Legacy, bool importKeysToNBX = false) { SupportedNetwork = parent.NetworkProvider.GetNetwork <BTCPayNetwork>(cryptoCode); var store = parent.PayTester.GetController <StoresController>(UserId, StoreId); GenerateWalletResponseV = await parent.ExplorerClient.GenerateWalletAsync(new GenerateWalletRequest() { ScriptPubKeyType = segwit, SavePrivateKeys = importKeysToNBX, }); await store.AddDerivationScheme(StoreId, new DerivationSchemeViewModel() { Enabled = true, CryptoCode = cryptoCode, Network = SupportedNetwork, RootFingerprint = GenerateWalletResponseV.AccountKeyPath.MasterFingerprint.ToString(), RootKeyPath = SupportedNetwork.GetRootKeyPath(), Source = "NBXplorer", AccountKey = GenerateWalletResponseV.AccountHDKey.Neuter().ToWif(), DerivationSchemeFormat = "BTCPay", KeyPath = GenerateWalletResponseV.AccountKeyPath.KeyPath.ToString(), DerivationScheme = DerivationScheme.ToString(), Confirmation = true }, cryptoCode); return(new WalletId(StoreId, cryptoCode)); }
public Script GetScriptPubKey(ScriptPubKeyType type) { return(GetDestination(type).ScriptPubKey); }
public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit) { Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); // Replace previous wallet case if (Driver.PageSource.Contains("id=\"ChangeWalletLink\"")) { Driver.FindElement(By.Id("ChangeWalletLink")).Click(); Driver.FindElement(By.Id("continue")).Click(); } if (string.IsNullOrEmpty(seed)) { var option = privkeys ? "Hotwallet" : "Watchonly"; Logs.Tester.LogInformation($"Generating new seed ({option})"); Driver.FindElement(By.Id("GenerateWalletLink")).Click(); Driver.FindElement(By.Id($"Generate{option}Link")).Click(); } else { Logs.Tester.LogInformation("Progressing with existing seed"); Driver.FindElement(By.Id("ImportWalletOptionsLink")).Click(); Driver.FindElement(By.Id("ImportSeedLink")).Click(); Driver.FindElement(By.Id("ExistingMnemonic")).SendKeys(seed); Driver.SetCheckbox(By.Id("SavePrivateKeys"), privkeys); } Driver.FindElement(By.Id("ScriptPubKeyType")).Click(); Driver.FindElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click(); // Open advanced settings via JS, because if we click the link it triggers the toggle animation. // This leads to Selenium trying to click the button while it is moving resulting in an error. Driver.ExecuteJavaScript("document.getElementById('AdvancedSettings').classList.add('show')"); Driver.SetCheckbox(By.Id("ImportKeysToRPC"), importkeys); Driver.FindElement(By.Id("Continue")).Click(); // Seed backup page FindAlertMessage(); if (string.IsNullOrEmpty(seed)) { seed = Driver.FindElements(By.Id("RecoveryPhrase")).First().GetAttribute("data-mnemonic"); } // Confirm seed backup Driver.FindElement(By.Id("confirm")).Click(); Driver.FindElement(By.Id("submit")).Click(); WalletId = new WalletId(StoreId, cryptoCode); return(new Mnemonic(seed)); }
public Script GetScriptPubKey(ScriptPubKeyType scriptPubKeyType) { return(PubKey.GetScriptPubKey(scriptPubKeyType)); }
public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit) { var isImport = !string.IsNullOrEmpty(seed); Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); // Replace previous wallet case if (Driver.PageSource.Contains("id=\"ChangeWalletLink\"")) { Driver.FindElement(By.Id("ChangeWalletLink")).Click(); Driver.WaitForElement(By.Id("ConfirmInput")).SendKeys("REPLACE"); Driver.FindElement(By.Id("ConfirmContinue")).Click(); } if (isImport) { Logs.Tester.LogInformation("Progressing with existing seed"); Driver.FindElement(By.Id("ImportWalletOptionsLink")).Click(); Driver.FindElement(By.Id("ImportSeedLink")).Click(); Driver.FindElement(By.Id("ExistingMnemonic")).SendKeys(seed); Driver.SetCheckbox(By.Id("SavePrivateKeys"), privkeys); } else { var option = privkeys ? "Hotwallet" : "Watchonly"; Logs.Tester.LogInformation($"Generating new seed ({option})"); Driver.FindElement(By.Id("GenerateWalletLink")).Click(); Driver.FindElement(By.Id($"Generate{option}Link")).Click(); } Driver.FindElement(By.Id("ScriptPubKeyType")).Click(); Driver.FindElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click(); Driver.ToggleCollapse("AdvancedSettings"); Driver.SetCheckbox(By.Id("ImportKeysToRPC"), importkeys); Driver.FindElement(By.Id("Continue")).Click(); if (isImport) { // Confirm addresses Driver.FindElement(By.Id("Confirm")).Click(); } else { // Seed backup FindAlertMessage(); if (string.IsNullOrEmpty(seed)) { seed = Driver.FindElements(By.Id("RecoveryPhrase")).First().GetAttribute("data-mnemonic"); } // Confirm seed backup Driver.FindElement(By.Id("confirm")).Click(); Driver.FindElement(By.Id("submit")).Click(); } WalletId = new WalletId(StoreId, cryptoCode); return(new Mnemonic(seed)); }
public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit) { Driver.FindElement(By.Id($"Modify{cryptoCode}")).Click(); Driver.FindElement(By.Id("import-from-btn")).Click(); Driver.FindElement(By.Id("nbxplorergeneratewalletbtn")).Click(); Driver.FindElement(By.Id("ExistingMnemonic")).SendKeys(seed); SetCheckbox(Driver.FindElement(By.Id("SavePrivateKeys")), privkeys); SetCheckbox(Driver.FindElement(By.Id("ImportKeysToRPC")), importkeys); Driver.FindElement(By.Id("ScriptPubKeyType")).Click(); Driver.FindElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click(); Logs.Tester.LogInformation("Trying to click btn-generate"); Driver.FindElement(By.Id("btn-generate")).Click(); // Seed backup page FindAlertMessage(); if (string.IsNullOrEmpty(seed)) { seed = Driver.FindElements(By.Id("recovery-phrase")).First().GetAttribute("data-mnemonic"); } // Confirm seed backup Driver.FindElement(By.Id("confirm")).Click(); Driver.FindElement(By.Id("submit")).Click(); WalletId = new WalletId(StoreId, cryptoCode); return(new Mnemonic(seed)); }
public Mnemonic GenerateWallet(string cryptoCode = "BTC", string seed = "", bool importkeys = false, bool privkeys = false, ScriptPubKeyType format = ScriptPubKeyType.Segwit) { Driver.FindElement(By.Id($"Modify{cryptoCode}")).ForceClick(); Driver.FindElement(By.Id("import-from-btn")).ForceClick(); Driver.FindElement(By.Id("nbxplorergeneratewalletbtn")).ForceClick(); Driver.WaitForElement(By.Id("ExistingMnemonic")).SendKeys(seed); SetCheckbox(Driver.WaitForElement(By.Id("SavePrivateKeys")), privkeys); SetCheckbox(Driver.WaitForElement(By.Id("ImportKeysToRPC")), importkeys); Driver.WaitForElement(By.Id("ScriptPubKeyType")).Click(); Driver.WaitForElement(By.CssSelector($"#ScriptPubKeyType option[value={format}]")).Click(); Logs.Tester.LogInformation("Trying to click btn-generate"); Driver.WaitForElement(By.Id("btn-generate")).ForceClick(); AssertHappyMessage(); if (string.IsNullOrEmpty(seed)) { seed = Driver.FindElements(By.ClassName("alert-success")).First().FindElement(By.TagName("code")).Text; } return(new Mnemonic(seed)); }