Skip to content

eike-grundke/xpub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Derivation of extended public keys, for BTC and ETH network

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages