With this library extended public keys of BTC or ETH network can be derived for any index
xpub
, tpub
, vpub
and zpub
supported
composer require eike-grundke/xpub
- PHP >= 8.1
- BCMath or GMP extension
use Grundke\ExtendedPublicKey;
use Grundke\Enum\CoinEnum;
use Grundke\Enum\BipEnum;
$xPub = ExtendedPublicKey::fromString('xpub...' ; // bip44
$xPub = ExtendedPublicKey::fromString('zpub...'); // bip84 (native SegWit)
// explicit bip
$xPub = ExtendedPublicKey::fromString('xpub...', BipEnum::BIP84);
$xPub = ExtendedPublicKey::fromString('zpub...', BipEnum::BIP44);
$xPubFromIndex = $xPub->derive($i);
$xPubFromIndices = $xpub->derive([$i1, $i2]);
// to base58 string
$xPubString = $xPubFromIndex->toString();
// to hex string
$xPubHex = $xPubFromIndex->toString(true);
// to address
$address = $xPubFromIndex->toAddress(CoinEnum::BTC);
# static functions
# hash160
$hash = ExtendedPublicKey::hash160($hex);
# double sha256
$hash = ExtendedPublicKey::doubleSha256($hex);