-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I cant create BIP84 Account Extended Public Key #1205
Comments
Sytehel-1337
changed the title
I cant create BIP32 Extended Public Key
I cant create BIP84 Extended Public Key
Mar 24, 2024
Sytehel-1337
changed the title
I cant create BIP84 Extended Public Key
I cant create BIP84 Account Extended Public Key
Mar 24, 2024
using System;
using System.Runtime.InteropServices;
using NBitcoin;
namespace BitcoinAddressLib
{
[ComVisible(true)]
[Guid("12345678-90AB-CDEF-1234-567890ABCDEF")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface Ibtc
{
string GenerateAddressWrapper(string mnemonic, int bipType, int account, int chain, int addressIndex);
}
[ComVisible(true)]
[Guid("ABCDEF12-3456-7890-CDEF-1234567890AB")]
[ClassInterface(ClassInterfaceType.None)]
public class BitcoinAddressGenerator : Ibtc
{
public string GenerateAddressWrapper(string mnemonic, int bipType, int account, int chain, int addressIndex)
{
ScriptPubKeyType addressType;
switch (bipType)
{
case 44:
addressType = ScriptPubKeyType.Legacy;
break;
case 49:
addressType = ScriptPubKeyType.SegwitP2SH;
break;
case 84:
addressType = ScriptPubKeyType.Segwit;
break;
default:
throw new ArgumentException("Unsupport");
}
BitcoinAddress address = GenerateBtcAddress(mnemonic, addressType, account, chain, addressIndex);
System.Diagnostics.Debug.WriteLine($"Address: {address}");
return address.ToString();
}
private static BitcoinAddress GenerateBtcAddress(string mnemonic, ScriptPubKeyType addressType, int account, int chain, int addressIndex)
{
Mnemonic mnemo = new Mnemonic(mnemonic, Wordlist.English);
ExtKey masterKey = mnemo.DeriveExtKey();
string derivationPath = $"m/{44}'/0'/{account}'/{chain}/{addressIndex}";
if (addressType == ScriptPubKeyType.SegwitP2SH)
{
derivationPath = $"m/{49}'/0'/{account}'/{chain}/{addressIndex}";
}
else if (addressType == ScriptPubKeyType.Segwit)
{
derivationPath = $"m/{84}'/0'/{account}'/{chain}/{addressIndex}";
}
ExtKey key = masterKey.Derive(new KeyPath(derivationPath));
return key.Neuter().PubKey.GetAddress(addressType, Network.Main);
}
}
} Try this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried many methods but I couldn't succeed. Can I do this with nbitcoin? if i can how can i do it (must be start with "zpub")
This code creates the extended public address very well for bip44, but when it comes to bip84 it does not create it.
The text was updated successfully, but these errors were encountered: