Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 1.05 KB

README.md

File metadata and controls

48 lines (34 loc) · 1.05 KB

eike-grundke/xpub

With this library extended public keys of BTC or ETH network can be derived for any index

xpub, tpub, vpub and zpub supported

Installation

composer require eike-grundke/xpub

Requirements

  • PHP >= 8.1
  • BCMath or GMP extension

Usage

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);