You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get the private key of the derived address generated from the code below.
I know I must pass my private key somewhere, but I do not know where. This problem is the function $child_key->getPrivateKey(). It returns an error: Unable to get private key, not known.
$xpub = '...........';
$pubkeytype = substr($xpub, 0, 4);
$bitcoin_prefixes = new BitcoinRegistry();
$adapter = Bitcoin::getEcAdapter();
$slip132 = new Slip132(new KeyToScriptHelper($adapter));
if ($pubkeytype == 'xpub') $pubPrefix = $slip132->p2pkh($bitcoin_prefixes);
if ($pubkeytype == 'ypub') $pubPrefix = $slip132->p2shP2wpkh($bitcoin_prefixes);
if ($pubkeytype == 'zpub') $pubPrefix = $slip132->p2wpkh($bitcoin_prefixes);
$config = new GlobalPrefixConfig([new NetworkConfig(NetworkFactory::bitcoin(), [$pubPrefix])]);
$serializer = new Base58ExtendedKeySerializer(new ExtendedKeySerializer($adapter, $config));
$key = $serializer->parse(NetworkFactory::bitcoin(), $xpub);
$child_key = $key->derivePath($path);
return [$child_key->getPrivateKey(), $child_key->getAddress(new AddressCreator())->getAddress()];
Thank you!
The text was updated successfully, but these errors were encountered:
Schiocco
changed the title
How to get private key of derived address from?
How to get private key of derived address?
Jan 12, 2023
I'm trying to get the private key of the derived address generated from the code below.
I know I must pass my private key somewhere, but I do not know where. This problem is the function $child_key->getPrivateKey(). It returns an error: Unable to get private key, not known.
Thank you!
The text was updated successfully, but these errors were encountered: