-
Notifications
You must be signed in to change notification settings - Fork 421
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
How do I get a hex-encoded key from MPK? #881
Comments
Sorry for the delay. Are you using BIP32? Electrum has an old style 'master public key' thing, probably not relevant Use |
does this support testnet keys though? for example a vpub########### key |
even tpub, tried doing $config = new GlobalPrefixConfig([
|
Does this example help a bit? https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/zpub.parse.php So vpub would be a testnet key, with the bytes I think if you based it on the example above, just edit https://github.com/Bit-Wasp/bitcoin-php/blob/1.0/examples/zpub.parse.php#L21-L26 here to use NetworkFactory::bitcoinTestnet() as the network, and $bitcoinRegistry should be I seem to have screwed up the comments in this file, in case that throws you (referring to it as zpub, although it's vpub on testnet) |
I get to make it work however the address that it returns is not for testnet, it returns a wallet address that starts with bc######### where it should return an address that starts with tb######### right? |
So when i use the address from that I get an invalid address error Edit: Actually, if i also use $fkey->derivePath("84'/0'/0'"); it returns an error that a private master key is required. My only inputs are all pubkeys. Not private keys. So i could get an address if i dont use $fkey->derivePath("84'/0'/0'"), i could get if i use $fkey->derivePath("0/0"); The addresses i get from $fkey->derivePath("0/0")/ $fkey->derivePath("0/1")/ etc ; when i try to send funds then bitcoin says that the address is invalid |
That would suggest you are passing the mainnet network, not testnet. (NetworkFactory::bitcoin() vs NetworkFactory::bitcoinTestnet())
This is a feature of BIP32 hardened derivations. You should probably do a refresher on BIP32. Essentially if you have a public key, you cannot derive any hardened child subkeys like you are doing here (See the apostrophe in the bip32 path 84'/0'/0'). Instead of giving the root public key The examples are kind of sucky in that, while they illustrate one way to accomplish something, they often need rewriting to fit in with what you are trying to do. I find deriving and comparing to bip32.org can help confirm if things are going correctly. |
I did so changed as instructed still gives address on mainnet; |
Is there an example of doing this? |
I have posted my problem here and my code: https://stackoverflow.com/questions/69914451/bit-wasp-bitcoin-php-generate-wallet-from-extended-public-key |
Oh, I think I understand the address network problem - can you pass that testnet network into the final return $child_key->getAddress(new AddressCreator())->getAddress(); becomes return $child_key->getAddress(new AddressCreator())->getAddress($btc); The objects in this library tend not to store which network they belong to, so calling I'm kicking myself I didn't catch it sooner :) The rule when dealing with multiple networks in your codebase - whenever you call something that outputs a base58/bech32 etc encoding, always pass the network you want it for. I think there's a PR open for a network to make the default network issue much easier to detect. See #716 |
No. Write a separate script, taking a root private key, and deriving 84'/0'/0'. then convert to the public key (path: Don't forget you can test with bip32.org |
I understand this however the problem with this is that I or the users wont put in their private keys into the system as it'll give them risks. I dont understand what you mean by root public key, on my test im using Electrum wallet, Then Wallet>information>master public key |
Problem is solved; |
Ah apologies, now I understand
Great to hear |
How do I get a Hex-encoded public key from Master Public Key?
The text was updated successfully, but these errors were encountered: