-
Notifications
You must be signed in to change notification settings - Fork 79
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
Generate extended public keys from an extended key #29
base: master
Are you sure you want to change the base?
Generate extended public keys from an extended key #29
Conversation
This patch doesn't seem to work. Firstly, the get-extended param is not read from the command-line. maybe you forgot to commit changes in Util.php? Even after I added that, I get an error that $key is undefined on line 54 of hd-wallet-derive.php. After fixing that, I got another error. If you fix the PR so that I can test it out, I will evaluate further. thanks. |
You're right, I missed a few things there... Too eager to push I guess. I will fix it in the new few days and update the PR. These changes were taken from another project where I needed to run this package as a JSON server instead of through the CLI. |
ok, yeah I'll take a look once you update... |
I've updated the PR with the fixes and tested the solution. Please confirm and let me know if there are other other changes that I should do. I tried to used the same naming conventions in order to match the current usage style. |
|
||
// store results here | ||
$extkeys = array(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest you arrange these pieces of code as foreach
somehow like this:
public function getExtendedPublicKeys($key) {
$params = $this->get_params();
$coin = $params['coin'];
list($symbol) = explode('-', $coin);
$networkCoinFactory = new NetworkCoinFactory();
$network = $networkCoinFactory->getNetworkCoinInstance($coin);
Bitcoin::setNetwork($network);
// get initial key type for the coin
$initial_key_type = $this->getKeyTypeFromCoinAndKey($coin, $key);
$addrTypes = [
'x' => 'legacy',
'y' => 'p2sh-segwit',
'z' => 'bech32'
];
$types = ['x', 'y', 'z'];
$extkeys = array();
foreach ($types as $type) {
$this->params['addr-type'] = $addrTypes[$type];
$key_type = $type;
$xyzPub = $type . 'pub';
$master = $this->fromExtended($coin, $key, $network, $initial_key_type);
if ( $this->networkSupportsKeyType($network, $key_type, $coin ) && method_exists($master, 'getPublicKey') ) {
$extkeys[] = [ $xyzPub => $this->toExtendedKey($coin, $master->withoutPrivateKey(), $network, $key_type)];
}
}
return $extkeys;
}
I would also suggest you squash all the commits into a single one to keep nice clean history
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I concur with @melaxon's suggestions.
Given an extended public/private key generate the corresponding extended public keys in "legacy", "p2sh-segwit" or "bech32" address types (if supported)
These can then be used by hd-addr to check the generated addresses for funds as mentioned in issue #28 .