Closed passionofvc closed 6 years ago
Here's it decoded, looks like you posted the main key, but haven't derived anything from it. Try calling derivePath("0'/0'/1'")
first!
+---------------+--------------------------------------------------------------------+
| bytes | 0488ade4 |
| depth | 0 |
| fpr | 0 |
| hardened | false |
| address index | 0 |
| chain code | f930708ef20817f04c5a5c5c0ff2c7f295ccb4da28fef6ec3136dac21c2ae2ae |
| public key | 033f3e7e1bf7aa5935aa1ae566854e71cc4e258f985655ca8008588d97ae24d9b1 |
| private key | 2bb86ddb0dd6cd314ccb1a88b86cd74c55e905baf0cd7f0d02a3e538992bb6de |
+---------------+--------------------------------------------------------------------+
$key="xprv9s21ZrQH143K4YFY8z2JysNbKzrHtB3rFRSdbiFmDvKQdRtYYW31MVbFQvqFqWgMjfCTpnCtc7d2Vk9CzCxCzJRyaA1i3aCsuonwR6RMHit";
$master = HierarchicalKeyFactory::fromExtended($key, Bitcoin::getNetwork());
$c = $master->derivePath("0'/0'/1'");
echo $c->getAddress(new AddressCreator())->getAddress().PHP_EOL;
this example works on 0.0.35 (getAddress on HierarchicalKey is new), otherwise just derive the addess as you did from the public key.
hi @afk11 thanks, I will add derive path and test above code again.
hi @afk11 it work perfectly. Incidentally I use "bitwasp/bitcoin": "0.0.35.0".
php test.php
1PcEG477xuZXMR76Szo79joxu4hzdxxNmH
KzKviwwgNiQHeD22inCw3B18aR9xLHrK3Eu5oDPTTuFjNHQLJo6J
f7fc64f86a997c4c16a907632aa68c8e0168c3a1
Ah, great, then you can do it the easy way as of that version, HierarchicalKey now exposes getAddress, in case you decide to use some of the zpub/ypub/etc proposals
$master = HierarchicalKeyFactory::fromExtended($key, Bitcoin::getNetwork());
$child = $master->derivePath("0'/0'/1'");
$address = $child->getAddress(new AddressCreator())->getAddress().PHP_EOL;
I test for recovery bitcoind wallet(wallet.dat), dumpwallet command to get mastekey info, and retrieve private key info from extended private masterkey, but it gave me the wrong output address info.
I can use http://bip32.org to convert it and it show me correct private key and address.
■input custom path [m/0'/0'/1'] ■output Private Key (WIF) : KzKviwwgNiQHeD22inCw3B18aR9xLHrK3Eu5oDPTTuFjNHQLJo6J Address : 1PcEG477xuZXMR76Szo79joxu4hzdxxNmH
■dump wallet from bitcoins wallet.dat