void SetMnemonic(Mnemonic mnemonic) { _mnemonic = mnemonic; LegacyAddress = _mnemonic.DeriveExtKey().GetPublicKey().GetAddress(ScriptPubKeyType.Legacy, Network.Main) .ToString(); PublicId = _mnemonic.DeriveExtKey().GetPublicKey().GetAddress(ScriptPubKeyType.SegwitP2SH, Network.Main) .ToString(); }
public void CreateHDWallet() { // 通过已知的助记词生成账号 var wallet = new Wallet(Words, Password); var account = wallet.GetAccount(0); Console.WriteLine(account.Address); var prk = wallet.GetPrivateKey(account.Address);//获取账号对应的秘钥 var accprk = account.PrivateKey; Console.WriteLine("the prk is {0}", prk.ToHex()); Console.WriteLine("the accprk is {0}", accprk); // 第一次创建钱包 生成随机的助记词 并保存 var mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); Console.WriteLine(mnemonic.ToString()); var masterKey = mnemonic.DeriveExtKey("123456"); //生成一组组秘钥对 可以通过该秘钥继续生成子孙密钥对 var privateKey = masterKey.PrivateKey; //获取的是bitcoin的私钥 var wallet1 = new Wallet(mnemonic.ToString(), "123456"); Console.WriteLine("the wallet1 mnemonic is {0}", mnemonic.ToString()); var account1 = wallet1.GetAccount(0); Console.WriteLine("the wallet1 account is {0}", account1.Address); var keySvc = new KeyStoreService(); var json = keySvc.EncryptAndGenerateDefaultKeyStoreAsJson("123456", account1.PrivateKey.HexToByteArray(), account1.Address); var path = string.Format(@"e:\{0}.json", keySvc.GenerateUTCFileName(account1.Address)); File.WriteAllText(path, json); }
public void Slip77Tests() { //test vector: https://github.com/vulpemventures/slip77/commit/bc0fa0c712512d27cf1e2d6e1aaee5c36a3d38fa var allMnemonic = new Mnemonic("all all all all all all all all all all all all"); var master = Slip21Node.FromSeed(allMnemonic.DeriveSeed()); Assert.Equal("dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756", master.Key.ToHex()); var slip77 = Slip21Node.FromSeed(allMnemonic.DeriveSeed()).GetSlip77Node(); var script = Script.FromHex("76a914a579388225827d9f2fe9014add644487808c695d88ac"); var privateBlindingKey = slip77.DeriveSlip77BlindingKey(script); var unconfidentialAddress = BitcoinAddress.Create("2dpWh6jbhAowNsQ5agtFzi7j6nKscj6UnEr", Altcoins.Liquid.Instance.Regtest); var publicBlindingKey = privateBlindingKey.PubKey; Assert.Equal("4e6e94df28448c7bb159271fe546da464ea863b3887d2eec6afd841184b70592", privateBlindingKey.ToHex()); Assert.Equal("0223ef5cf5d1185f86204b9386c8541061a24b6f72fa4a29e3a0b60e1c20ffaf5b", publicBlindingKey.ToHex()); Assert.Equal("CTEkf75DFff5ReB7juTg2oehrj41aMj21kvvJaQdWsEAQohz1EDhu7Ayh6goxpz3GZRVKidTtaXaXYEJ", new BitcoinBlindedAddress(publicBlindingKey, unconfidentialAddress).ToString()); //test vector: https://github.com/trezor/trezor-firmware/pull/398/files#diff-afc9a622fb2281269983493a9da47a364e94f8bd338e5322f4a7cef99f98ee69R119 var abusiveWords = new Mnemonic("alcohol woman abuse must during monitor noble actual mixed trade anger aisle"); var derived = abusiveWords.DeriveExtKey().Derive(new KeyPath("44'/1'/0'/0/0")); var addr = derived.PrivateKey.ScriptPubKey.GetDestinationAddress(Liquid.Instance.Regtest); var abusiveslip77 = Slip21Node.FromSeed(abusiveWords.DeriveSeed()).GetSlip77Node(); Assert.Equal("26f1dc2c52222394236d76e0809516255cfcca94069fd5187c0f090d18f42ad6", abusiveslip77.DeriveSlip77BlindingKey(addr.ScriptPubKey).ToHex()); }
static void MasterPublicKeyAndPrivateKey1(Network net, string words, string password) { Mnemonic mnemonic = new Mnemonic(words); ExtKey fatherKey = mnemonic.DeriveExtKey(); ExtPubKey pubKey = fatherKey.Neuter(); string wifStr = pubKey.Derive(0).ToString(net); Console.WriteLine(wifStr); Console.WriteLine(); Console.WriteLine(); for (int i = 0; i < 10; i++) { BitcoinAddress address1 = pubKey.Derive((uint)i).PubKey.GetAddress(ScriptPubKeyType.Legacy, net); Console.WriteLine(address1.ToString()); } //var wiff = ""; //for (int i = 0; i < 10; i++) //{ // ExtKey key = fatherKey.Derive((uint)i); // var c = ("Key " + i + " : " + key.PrivateKey.GetBitcoinSecret(net).GetAddress(ScriptPubKeyType.Legacy).ToString() + " , wif:" + key.GetWif(net)); // var c1 = ("Key " + i + " : " + key.PrivateKey.GetBitcoinSecret(net).GetAddress(ScriptPubKeyType.Segwit).ToString() + " , wif:" + key.GetWif(net)); // var c2 = ("Key " + i + " : " + key.PrivateKey.GetBitcoinSecret(net).GetAddress(ScriptPubKeyType.SegwitP2SH).ToString() + " , wif:" + key.GetWif(net)); // Console.WriteLine(c); // Console.WriteLine(c1); // Console.WriteLine(c2); //} }
/// <inheritdoc /> public Mnemonic CreateWallet(string password, string folderPath, string name, string network, string passphrase = null) { // for now the passphrase is set to be the password by default. if (passphrase == null) { passphrase = password; } // generate the root seed used to generate keys from a mnemonic picked at random // and a passphrase optionally provided by the user Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey extendedKey = mnemonic.DeriveExtKey(passphrase); Network coinNetwork = WalletHelpers.GetNetwork(network); // create a wallet file Wallet wallet = this.GenerateWalletFile(password, folderPath, name, coinNetwork, extendedKey); // generate multiple accounts and addresses from the get-go for (int i = 0; i < WalletCreationAccountsCount; i++) { HdAccount account = CreateNewAccount(wallet, this.coinType, password); this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer); this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer, true); } // save the changes to the file and add addresses to be tracked this.SaveToFile(wallet); this.PubKeys = this.LoadKeys(this.coinType); this.Load(wallet); return(mnemonic); }
/// <summary> /// Gets the HD private key generated by this mnemonic and passphrase. /// </summary> /// <param name="mnemonic">The mnemonic used to generate the key.</param> /// <param name="passphrase">The passphrase used in generating the key.</param> /// <returns>The HD private key generated by this mnemonic and passphrase.</returns> /// <remarks>This key is sometimes referred to as the 'root seed' or the 'master key'.</remarks> public static ExtKey GetHdPrivateKey(Mnemonic mnemonic, string passphrase) { Guard.NotNull(mnemonic, nameof(mnemonic)); Guard.NotEmpty(passphrase, nameof(passphrase)); return(mnemonic.DeriveExtKey(passphrase)); }
public static HDKeyManager Create(out Mnemonic mnemonic) { mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); var extKey = mnemonic.DeriveExtKey(); return(new HDKeyManager(extKey, DefaultAccountKeyPath)); }
public static void test() { //getting the mnemonic with a custom wordlist (generated by overriding the Italian one) Wordlist wl = getItalianWordlist(); int[] arr = Enumerable.Range(0, wl.WordCount - 1).ToArray(); String[] ewl = wl.GetWords(arr); ewl[0] = "dry"; ewl[1] = "drive"; ewl[2] = "brown"; ewl[3] = "parade"; ewl[4] = "drastic"; ewl[5] = "shine"; ewl[6] = "embrace"; ewl[7] = "hard"; ewl[8] = "report"; ewl[9] = "loan"; ewl[10] = "fold"; ewl[11] = "iron"; Wordlist wlCustom = new Wordlist(ewl, ' ', "custom"); Mnemonic mnemo = new Mnemonic("dry brown drive parade drastic shine embrace hard report loan fold iron", wlCustom); ExtKey hdroot = mnemo.DeriveExtKey(); var firstprivkey = hdroot.Derive(new KeyPath("m/0'/0/0")); var firstpubKey = firstprivkey.Neuter().PubKey; String address = firstpubKey.GetAddress(Network.Main).ToString(); Console.WriteLine(address); // --> 1AE1LyUWpfb32dReDuGezvdMGXHiFnq4jH }
/// <summary>Generates a new private key.</summary> public Key GeneratePrivateKey() { var mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); Key privateKey = mnemonic.DeriveExtKey().PrivateKey; return(privateKey); }
public ExtKey GetPrivateKey(string mnemoic, string senha) { var mnemo = new Mnemonic(mnemoic, Wordlist.PortugueseBrazil); ExtKey pkey = mnemo.DeriveExtKey(senha); return(pkey); }
public ExtKey GetExtKey(Network network) { ExtKey extKey = null; try { var mnemonic = new Mnemonic(SeedOrKey); extKey = mnemonic.DeriveExtKey(Passphrase); } catch (Exception) { } if (extKey == null) { try { extKey = ExtKey.Parse(SeedOrKey, network); } catch (Exception) { } } return(extKey); }
public void RunRule_ProvenHeadersActive_And_InvalidCoinstakeKernelSignature_BadBlockSignatureErrorIsThrown() { // Setup private key. var mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); Key privateKey = mnemonic.DeriveExtKey().PrivateKey; // Setup previous chained header. PosBlock prevPosBlock = new PosBlockBuilder(this.network, privateKey).Build(); ProvenBlockHeader prevProvenBlockHeader = new ProvenBlockHeaderBuilder(prevPosBlock, this.network).Build(); var previousChainedHeader = new ChainedHeader(prevProvenBlockHeader, prevProvenBlockHeader.GetHash(), null); previousChainedHeader.SetPrivatePropertyValue("Height", this.options.ProvenHeadersActivationHeight + 1); // Setup proven header with valid coinstake. PosBlock posBlock = new PosBlockBuilder(this.network, privateKey).Build(); posBlock.UpdateMerkleRoot(); ProvenBlockHeader provenBlockHeader = new ProvenBlockHeaderBuilder(posBlock, this.network).Build(); provenBlockHeader.HashPrevBlock = prevProvenBlockHeader.GetHash(); provenBlockHeader.Coinstake.Time = provenBlockHeader.Time; // Setup chained header and move it to the height higher than proven header activation height. this.ruleContext.ValidationContext.ChainedHeaderToValidate = new ChainedHeader(provenBlockHeader, provenBlockHeader.GetHash(), previousChainedHeader); this.ruleContext.ValidationContext.ChainedHeaderToValidate.SetPrivatePropertyValue("Height", this.options.ProvenHeadersActivationHeight + 2); // Setup coinstake transaction with a valid stake age. uint unspentOutputsHeight = (uint)this.options.ProvenHeadersActivationHeight + 10; var unspentOutputs = new UnspentOutputs(unspentOutputsHeight, new Transaction()) { Outputs = new[] { new TxOut(new Money(100), privateKey.PubKey) } }; this.coinView .Setup(m => m.FetchCoinsAsync(It.IsAny <uint256[]>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new FetchCoinsResponse(new[] { unspentOutputs }, posBlock.GetHash())); // Setup stake validator to pass signature validation. this.stakeValidator .Setup(m => m.VerifySignature(It.IsAny <UnspentOutputs>(), It.IsAny <Transaction>(), It.IsAny <int>(), It.IsAny <ScriptVerify>())) .Returns(true); // Setup stake validator to pass stake kernel hash validation. this.stakeChain.Setup(m => m.Get(It.IsAny <uint256>())).Returns(new BlockStake()); this.stakeValidator .Setup(m => m.CheckStakeKernelHash(It.IsAny <PosRuleContext>(), It.IsAny <uint>(), It.IsAny <uint256>(), It.IsAny <UnspentOutputs>(), It.IsAny <OutPoint>(), It.IsAny <uint>())); // Setup stake validator to pass stake age check. this.stakeValidator .Setup(m => m.IsConfirmedInNPrevBlocks(It.IsAny <UnspentOutputs>(), It.IsAny <ChainedHeader>(), It.IsAny <long>())) .Returns(true); // When we run the validation rule, we should hit bad merkle proof error. Action ruleValidation = () => this.consensusRules.RegisterRule <ProvenHeaderCoinstakeRule>().Run(this.ruleContext); ruleValidation.Should().Throw <ConsensusErrorException>() .And.ConsensusError .Should().Be(ConsensusErrors.BadBlockSignature); }
public void CanGenerateTaprootPubKey() { var mnemo = new Mnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"); var root = mnemo.DeriveExtKey(); // From BIP86 foreach (var v in new[]
/// <summary> /// Create an HD private key /// </summary> private static ExtKey CreateExtKey() { Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey extKey = mnemonic.DeriveExtKey(); return(extKey); }
public Identity(Mnemonic mnemonic, int index = 0) { Index = index; // This means we'll keep the recovery phrase in-memory for the lifetime of the process. This is needed for identity and // hub communication, but we should in the future only derive the extkey from the purpose (302) of identity, and then we should // use the extpubkey to derive wallet addresses (purpose 44). If we want to trust users to use the same recovery phrase for // both wallets and hub/identity, we must ensure that the private keys for the wallet is as secure as possible. this.mnemonic = mnemonic; masterNode = mnemonic.DeriveExtKey(); identity = masterNode.Derive(new KeyPath("m/302'")).Derive(index, true); ProfileNetwork network = new ProfileNetwork(); BitcoinAddress address = identity.ScriptPubKey.GetDestinationAddress(network); //this.identity = masterNode.Derive(new KeyPath("m/302'/0'")); // The default for keys is to be compressed, making it 33 bytes as oppose to 65. //identityPubKey = identity.GetPublicKey(); // FingerPrint = identityPubKey.GetHDFingerPrint(); // TODO: FIX THIS, API CHANGES! Id = address.ToString(); }
public static (Features.Wallet.Types.Wallet wallet, ExtKey key) GenerateBlankWalletWithExtKey(string name, string password) { var mnemonic = new Mnemonic("grass industry beef stereo soap employ million leader frequent salmon crumble banana"); ExtKey extendedKey = mnemonic.DeriveExtKey(password); var walletFile = new Features.Wallet.Types.Wallet { Name = name, EncryptedSeed = extendedKey.PrivateKey.GetEncryptedBitcoinSecret(password, KnownNetworks.Main).ToWif(), ChainCode = extendedKey.ChainCode, CreationTime = DateTimeOffset.Now, Network = KnownNetworks.Main, walletStore = new WalletMemoryStore(), BlockLocator = new List <uint256>() { KnownNetworks.Main.GenesisHash }, AccountsRoot = new List <AccountRoot> { new AccountRoot() { Accounts = new List <HdAccount>(), CoinType = KnownNetworks.Main.Consensus.CoinType, LastBlockSyncedHash = KnownNetworks.Main.GenesisHash, LastBlockSyncedHeight = 0 } }, }; var data = walletFile.walletStore.GetData(); data.BlockLocator = walletFile.BlockLocator; data.WalletName = walletFile.Name; data.WalletTip = new Utilities.HashHeightPair(KnownNetworks.Main.GenesisHash, 0); walletFile.walletStore.SetData(data); return(walletFile, extendedKey); }
void GenerateNewMnemonic(object sender, EventArgs args) { Mnemonic mnemo = new Mnemonic(Wordlist.English); ExtKey hdRoot = mnemo.DeriveExtKey("my password"); message.Text = mnemo.ToString(); }
public void CreateAccount() { if (signUpPW.text.Length > 7) { password = signUpPW.text; WalletManager.Instance.CreateAccount(password); seedPanel.SetActive(true); // Creat mnemonic Mnemonic mnemo = new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey hdRoot = mnemo.DeriveExtKey(password); seedText.text = mnemo.ToString(); IsEncryptedJson(); Debug.Log(mnemo); Debug.Log("Address:" + WalletManager.Instance.publicAddress); Debug.Log("PrivateKey:" + WalletManager.Instance.privateKey); Debug.Log("Json:" + WalletManager.Instance.encryptedJson); Debug.Log("Password:" + WalletManager.Instance.password); password = null; //UIFunction(); } }
public dynamic CreateNewHDWallet(string walletName, string network, string passPhrase) { Network ltcNetwork = null; if (network.ToLower() == "main") { ltcNetwork = NBitcoin.Altcoins.Litecoin.Instance.Mainnet; } else { ltcNetwork = NBitcoin.Altcoins.Litecoin.Instance.Testnet; } Mnemonic mnemo = new Mnemonic(Wordlist.English, WordCount.Fifteen); ExtKey hdroot = mnemo.DeriveExtKey(passPhrase); var wif = hdroot.GetWif(ltcNetwork); dynamic response = new ExpandoObject(); response.wif = wif; response.mnemo = mnemo; response.Network = network.ToLower() == "main" ? "Main" : "TestNet"; return(response); }
private static void GeneratePublicPrivateKeys() { // Generate keys for signing. var mnemonicForSigningKey = new Mnemonic(Wordlist.English, WordCount.Twelve); PubKey signingPubKey = mnemonicForSigningKey.DeriveExtKey().PrivateKey.PubKey; // Generate keys for migning. var tool = new KeyTool(new DataFolder(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location))); Key key = tool.GeneratePrivateKey(); string savePath = tool.GetPrivateKeySavePath(); tool.SavePrivateKey(key); PubKey miningPubKey = key.PubKey; Console.WriteLine($"-----------------------------------------------------------------------------"); Console.WriteLine($"-- Please give the following 2 public keys to the federation administrator --"); Console.WriteLine($"-----------------------------------------------------------------------------"); Console.WriteLine($"1. Your signing pubkey: {Encoders.Hex.EncodeData(signingPubKey.ToBytes(false))}"); Console.WriteLine($"2. Your mining pubkey: {Encoders.Hex.EncodeData(miningPubKey.ToBytes(false))}"); Console.WriteLine(Environment.NewLine); Console.WriteLine($"------------------------------------------------------------------------------------------"); Console.WriteLine($"-- Please keep the following 12 words for yourself and note them down in a secure place --"); Console.WriteLine($"------------------------------------------------------------------------------------------"); Console.WriteLine($"Your signing mnemonic: {string.Join(" ", mnemonicForSigningKey.Words)}"); Console.WriteLine(Environment.NewLine); Console.WriteLine($"------------------------------------------------------------------------------------------------------------"); Console.WriteLine($"-- Please save the following file in a secure place, you'll need it when the federation has been created. --"); Console.WriteLine($"------------------------------------------------------------------------------------------------------------"); Console.WriteLine($"File path: {savePath}"); Console.WriteLine(Environment.NewLine); }
public dynamic CreateNewHDWallet(string walletName, string network, string passPhrase) { Network btcNetwork = null; if (network.ToLower() == "main") { btcNetwork = Network.Main; } else { btcNetwork = Network.TestNet; } Mnemonic mnemo = new Mnemonic(Wordlist.English, WordCount.Fifteen); ExtKey hdroot = mnemo.DeriveExtKey(passPhrase); var wif = hdroot.GetWif(btcNetwork); dynamic response = new ExpandoObject(); response.wif = wif; response.mnemo = mnemo; response.btcNetwork = btcNetwork; return(response); }
/// <inheritdoc /> public Mnemonic CreateWallet(string password, string name, string passphrase = null) { // for now the passphrase is set to be the password by default. if (passphrase == null) { passphrase = password; } // generate the root seed used to generate keys from a mnemonic picked at random // and a passphrase optionally provided by the user Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey extendedKey = mnemonic.DeriveExtKey(passphrase); // create a wallet file Wallet wallet = this.GenerateWalletFile(password, name, extendedKey); // generate multiple accounts and addresses from the get-go for (int i = 0; i < WalletCreationAccountsCount; i++) { HdAccount account = CreateNewAccount(wallet, this.coinType, password); this.CreateAddressesInAccount(account, UnusedAddressesBuffer); this.CreateAddressesInAccount(account, UnusedAddressesBuffer, true); } // update the height of the we start syncing from this.UpdateLastBlockSyncedHeight(wallet, this.chain.Tip); // save the changes to the file and add addresses to be tracked this.SaveToFile(wallet); this.Load(wallet); this.LoadKeysLookup(); return(mnemonic); }
private Mnemonic SetSeed(string password, Mnemonic mnemonic = null) { mnemonic = mnemonic ?? new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey = mnemonic.DeriveExtKey(password); return(mnemonic); }
public void CanNormalizeMnemonicString() { var mnemonic = new Mnemonic("turtle front uncle idea crush write shrug there lottery flower risk shell", Wordlist.English); var mnemonic2 = new Mnemonic("turtle front uncle idea crush write shrug there lottery flower risk shell", Wordlist.English); Assert.Equal(mnemonic.DeriveExtKey().ScriptPubKey, mnemonic2.DeriveExtKey().ScriptPubKey); Assert.Equal(mnemonic.ToString(), mnemonic2.ToString()); }
public ExtPubKeyExplorerTests() { Random = new Random(Seed: 6439); var mnemonic = new Mnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"); ExtKey = mnemonic.DeriveExtKey(); ExtPubKey = ExtKey.Derive(new KeyPath("m/84'/0'/0'/1/0")).Neuter(); }
public ExtPubKeyExplorerTests() { Random = new Random(Seed: 6439); var mnemonic = new Mnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"); ExtKey = mnemonic.DeriveExtKey(); ExtPubKey = ExtKey.Derive(new KeyPath($"{KeyManager.DefaultAccountKeyPath.ToString(true, "h")}/1/0")).Neuter(); }
public string GenerateRandomIdentity() { // Generate a random seed and new identity. var mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey masterNode = mnemonic.DeriveExtKey(); ExtPubKey walletRoot = masterNode.Derive(new KeyPath("m/44'")).Neuter(); ExtKey identityRoot = masterNode.Derive(new KeyPath("m/302'")); ExtKey identity0 = identityRoot.Derive(0, true); ExtKey identity1 = identityRoot.Derive(1, true); BitcoinPubKeyAddress identity0Address = identity0.PrivateKey.PubKey.GetAddress(profileNetwork); BitcoinPubKeyAddress identity1Address = identity1.PrivateKey.PubKey.GetAddress(profileNetwork); string identity0Id = identity0Address.ToString(); // Create an identity profile that should be signed and pushed. IdentityModel identityModel = new IdentityModel { Id = identity0Id, Name = "Random Person", ShortName = "Random", Alias = "Who Knows", Email = "*****@*****.**", Title = "President" }; byte[] entityBytes = MessagePackSerializer.Serialize(identityModel); // Testing to only sign the name. string signature = identity0.PrivateKey.SignMessage(entityBytes); IdentityDocument identityDocument = new IdentityDocument { Owner = identityModel.Id, Body = identityModel, Signature = signature }; string json = JsonConvert.SerializeObject(identityDocument); RestClient client = CreateClient(); // Persist the identity. var request2 = new RestRequest($"/identity/{identityModel.Id}"); request2.AddJsonBody(identityDocument); IRestResponse <string> response2 = client.Put <string>(request2); if (response2.StatusCode != System.Net.HttpStatusCode.OK) { throw new ApplicationException(response2.ErrorMessage); } return(identity0Id); }
public OpenChainSession(ApiProxy api, string passphrase) : base(api) { Mnemonic mnemonic = new Mnemonic(passphrase); passphraseKey = mnemonic.DeriveExtKey(); rootKey = passphraseKey.Derive(44, true).Derive(64, true).Derive(0, true).Derive(0).Derive(0); var bprootkey = rootKey.PrivateKey.PubKey.GetAddress(OpenChainServer.OpenChainNetwork); Account = $"/p2pkh/{bprootkey}/"; }
public static void test2() { Mnemonic mnemo = new Mnemonic("dry brown drive parade drastic shine embrace hard report loan fold iron", Wordlist.English); ExtKey hdroot = mnemo.DeriveExtKey(); var firstprivkey = hdroot.Derive(new KeyPath("m/44'/0'/0'/0/0")); var firstpubKey = firstprivkey.Neuter().PubKey; String address = firstpubKey.GetAddress(Network.Main).ToString(); Console.WriteLine(address); // --> 1DMDJ266gxMCJiTcWk5MZFbfxxx4Ss3URN }
private BitcoinSecret HDPrivKey(string seed, int account, int n, string passphrase = null, bool change = false, bool segwit = false, bool bech32 = false) { var mnemonic = new Mnemonic(seed, Wordlist.English); var masterKey = mnemonic.DeriveExtKey(passphrase); //this is the root key string derivationpath = dpath(segwit, bech32); KeyPath kp = KeyPath.Parse(derivationpath + Convert.ToString(account) + "'/" + (change ? "1" : "0") + "/" + Convert.ToString(n)); ExtKey key = masterKey.Derive(kp); var p = key.PrivateKey.GetWif(Network.Main); return(p); }