PHPackages                             nimiq/xpub - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nimiq/xpub

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nimiq/xpub
==========

A simple class to derive BTC and ETH extended public keys and addresses without GMP.

1.4.3(5mo ago)113.9k6Apache-2.0PHPPHP &gt;=7.1CI passing

Since Nov 14Pushed 5mo ago8 watchersCompare

[ Source](https://github.com/nimiq/php-xpub)[ Packagist](https://packagist.org/packages/nimiq/xpub)[ Docs](https://github.com/nimiq/php-xpub)[ RSS](/packages/nimiq-xpub/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

Nimiq XPub
==========

[](#nimiq-xpub)

[![Build Status](https://github.com/nimiq/php-xpub/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/nimiq/php-xpub/actions/workflows/php.yml)

A simple class to derive BTC and ETH extended public keys and addresses without GMP. Only the BCMath extension is required (but GMP is still used for faster calculations when available).

Supports the following formats:

TypeMainnetTestnetBIP44 (standard)xpubtpubBIP49 (nested segwit)ypubupubBIP84 (native segwit)zpubvpubInstallation
------------

[](#installation)

The Nimiq XPub package is availabe via the [Packagist package registry](https://packagist.org/packages/nimiq/xpub) and can be installed with [Composer](https://getcomposer.org):

```
composer require nimiq/xpub
```

### Requirements

[](#requirements)

- PHP &gt;= 7.1
- BCMath or GMP extension

Usage
-----

[](#usage)

```
# PSR-4 autoloading with composer
use Nimiq\XPub;

# Create an XPub class instance from an xpub/tpub/ypub/upub/zpub/vpub string.
$xpub = XPub::fromString( 'xpub...' ); // => BIP44 Original
$xpub = XPub::fromString( 'ypub...' ); // => BIP49 Nested SegWit
$xpub = XPub::fromString( 'zpub...' ); // => BIP84 Native SegWit

# You can also specify the address scheme to override auto-detection.
$xpub = XPub::fromString( 'xpub...', XPub::BIP84 );
$xpub = XPub::fromString( 'xpub...', XPub::BIP49 );
$xpub = XPub::fromString( 'zpub...', XPub::BIP44 );

# Derive a child extended public key from it.
$xpub_i = $xpub->derive( $i );
# You can also pass an array to derive a path.
$xpub_i_k = $xpub->derive( [$i, $k]);

# An XPub can be serialized back into a string.
# Pass $asHex = true to serialize into a HEX string, base58 is the default.
$xpub_string = $xpub_i->toString( $asHex = false );

# An XPub can be converted into an address.
# Pass $coin = 'eth' to convert into an ETH address.
#
# By default, xpubs are converted into standard addresses,
# ypubs are converted into nested segwit addresses,
# and zpubs are converted into native segwit addresses.
$address = $xpub_i->toAddress( $coin = 'btc' );
```

*[See the tests](test/test.php) for further example usage.*

Conversion
----------

[](#conversion)

You can use this library to convert between xpub formats, for example:

```
// Parse any extended public key string
$xpub = XPub::fromString( 'xpub...' );

// Change the version on the instance
$xpub->version = 'zpub'; // Use any of the supported formats from the table at the top of the README

// Stringify to the target format
$zpub = $xpub->toString(); // 'zpub...'
```

Helpers
-------

[](#helpers)

The `XPub` class also exposes two common hashing methods:

```
# Get a hash160
$hashed_hex = XPub::hash160( $input_hex );

# Get a double sha256
$hashed_hex = XPub::doubleSha256( $input_hex );
```

Development
-----------

[](#development)

### Testing

[](#testing)

To execute the test suite run:

```
composer run-script test
# or
php test/test.php
```

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance70

Regular maintenance activity

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~280 days

Recently: every ~231 days

Total

9

Last Release

173d ago

PHP version history (2 changes)1.1.0PHP ^7.1

1.2.1PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33815469?v=4)[Nimiq](/maintainers/nimiq)[@nimiq](https://github.com/nimiq)

---

Top Contributors

[![sisou](https://avatars.githubusercontent.com/u/1828163?v=4)](https://github.com/sisou "sisou (29 commits)")[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

addressbcmathbitcoinbtcderivationethethereumgmpnimiqphpaddressbitcoinbcmathethereumblockchainderivationnimiq

### Embed Badge

![Health badge](/badges/nimiq-xpub/health.svg)

```
[![Health](https://phpackages.com/badges/nimiq-xpub/health.svg)](https://phpackages.com/packages/nimiq-xpub)
```

###  Alternatives

[kornrunner/ethereum-offline-raw-tx

Pure PHP Ethereum Offline Raw Transaction Signer

62200.8k22](/packages/kornrunner-ethereum-offline-raw-tx)[olifanton/interop

Olifanton interop library

1071.8k3](/packages/olifanton-interop)[kornrunner/solidity

Pure PHP implementation of Solidity

1940.5k11](/packages/kornrunner-solidity)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
