PHPackages                             nova-carnivore/bolt11-php - 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. [Payment Processing](/categories/payments)
4. /
5. nova-carnivore/bolt11-php

ActiveLibrary[Payment Processing](/categories/payments)

nova-carnivore/bolt11-php
=========================

Modern PHP 8.3+ BOLT 11 Lightning Network invoice encoder/decoder

v0.1.0(3mo ago)00MITPHPPHP ^8.3CI passing

Since Feb 14Pushed 3mo agoCompare

[ Source](https://github.com/nova-carnivore/bolt11-php)[ Packagist](https://packagist.org/packages/nova-carnivore/bolt11-php)[ RSS](/packages/nova-carnivore-bolt11-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

bolt11-php
==========

[](#bolt11-php)

[![PHP Version](https://camo.githubusercontent.com/7e80c5a44b0f819258f09384c7af693fe7f3f1ebe4ae8c6833b5c34f2dd57d03/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e332d3838393242462e737667)](https://php.net)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![CI](https://github.com/nova-carnivore/bolt11-php/actions/workflows/ci.yml/badge.svg)](https://github.com/nova-carnivore/bolt11-php/actions/workflows/ci.yml)[![PHPStan Level](https://camo.githubusercontent.com/3eef5bfb737c3eb8f74ff340fd46dc7a1cc6a5af7e425296fcec68a1ad6f5ad9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d6c6576656c253230392d627269676874677265656e2e737667)](https://phpstan.org)[![Latest Version](https://camo.githubusercontent.com/f7522f3338979f5b2bbe1e887bd1505c0412260ab7ef34d7d00f1d85eef5e7df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f76612d6361726e69766f72652f626f6c7431312d7068702e737667)](https://packagist.org/packages/nova-carnivore/bolt11-php)

Modern PHP 8.3+ BOLT 11 Lightning Network invoice encoder/decoder. Full spec compliance, production-ready.

Features
--------

[](#features)

- ⚡ **Full BOLT 11 spec compliance** — All 12 spec test vectors pass
- 🔐 **Encode, sign &amp; decode** — Complete lifecycle support
- 🏗️ **Modern PHP 8.3+** — Enums, readonly classes, named arguments, match expressions
- 🔍 **PHPStan level 9** — Maximum static analysis strictness
- 🌐 **All networks** — Bitcoin, Testnet, Signet, Regtest
- 🏷️ **All tag types** — payment\_hash, description, route hints, feature bits, metadata, and more
- 🔄 **Round-trip safe** — Encode → sign → decode preserves all data
- 📏 **PSR-12 code style** — Enforced with PHP-CS-Fixer
- 🔒 **Security-hardened crypto** — Uses paragonie/ecc with constant-time operations

Installation
------------

[](#installation)

```
composer require nova-carnivore/bolt11-php
```

### Requirements

[](#requirements)

- PHP 8.3 or higher
- ext-gmp (required by paragonie/ecc)

Quick Start
-----------

[](#quick-start)

### Decode an Invoice

[](#decode-an-invoice)

```
use Nova\Bitcoin\Bolt11\Decoder;

$invoice = Decoder::decode('lnbc2500u1pvjluez...');

$invoice->satoshis;          // 250000
$invoice->millisatoshis;     // '250000000'
$invoice->network;           // Network::Bitcoin
$invoice->timestamp;         // 1496314658
$invoice->payeeNodeKey;      // '03e7156ae33b...'

// Access tags
$invoice->getPaymentHash();   // hex string
$invoice->getDescription();   // 'string'
$invoice->getPaymentSecret(); // hex string
$invoice->isExpired();        // bool
$invoice->getTag('payment_hash'); // Tag object
```

### Encode an Invoice

[](#encode-an-invoice)

```
use Nova\Bitcoin\Bolt11\Encoder;
use Nova\Bitcoin\Bolt11\Network;
use Nova\Bitcoin\Bolt11\Tag;

$unsigned = Encoder::encode(
    network: Network::Bitcoin,
    satoshis: 1000,
    tags: [
        Tag::paymentHash('0001020304050607...'),
        Tag::paymentSecret('1111111111111111...'),
        Tag::description('test payment'),
        Tag::expiry(3600),
    ],
);
```

### Sign an Invoice

[](#sign-an-invoice)

```
use Nova\Bitcoin\Bolt11\Signer;

$signed = Signer::sign($unsigned, $privateKeyHex);

$signed->paymentRequest; // 'lnbc10u1...'
$signed->complete;       // true
$signed->payeeNodeKey;   // compressed public key
```

### Amount Helpers

[](#amount-helpers)

```
use Nova\Bitcoin\Bolt11\Helpers;

Helpers::satToHrp(250000);       // '2500u'
Helpers::hrpToSat('2500u');      // '250000'
Helpers::millisatToHrp('1000');  // '10n'
Helpers::hrpToMillisat('10n');   // '1000'
```

API Reference
-------------

[](#api-reference)

### `Decoder::decode(string $paymentRequest): Invoice`

[](#decoderdecodestring-paymentrequest-invoice)

Decodes a BOLT 11 payment request string into an `Invoice` object. Handles both lowercase and UPPERCASE invoices.

### `Encoder::encode(...): Invoice`

[](#encoderencode-invoice)

Creates an unsigned invoice. Parameters:

ParameterTypeDefaultDescription`network``Network``Network::Bitcoin`Target network`satoshis``?int``null`Amount in satoshis`millisatoshis``?string``null`Amount in millisatoshis`tags``array``[]`Tagged fields`timestamp``?int``null`Unix timestamp (defaults to now)### `Signer::sign(Invoice $invoice, string $privateKeyHex): Invoice`

[](#signersigninvoice-invoice-string-privatekeyhex-invoice)

Signs an unsigned invoice with a secp256k1 private key.

### `Invoice` (Value Object)

[](#invoice-value-object)

PropertyTypeDescription`complete``bool`Whether the invoice is fully signed`prefix``string`Full HRP (e.g. `lnbc2500u`)`network``?Network`Bitcoin network enum`satoshis``?int`Amount in satoshis`millisatoshis``?string`Amount in millisatoshis`timestamp``int`Unix timestamp`payeeNodeKey``?string`Compressed public key (hex)`signature``string`64-byte compact signature (hex)`recoveryFlag``int`Signature recovery flag (0-3)`tags``array`All tagged fields`paymentRequest``?string`Full bech32-encoded string### Tag Factory Methods

[](#tag-factory-methods)

```
Tag::paymentHash(string $hex): Tag
Tag::paymentSecret(string $hex): Tag
Tag::description(string $text): Tag
Tag::descriptionHash(string $hex): Tag
Tag::payeeNodeKey(string $hex): Tag
Tag::expiry(int $seconds): Tag
Tag::minFinalCltvExpiry(int $blocks): Tag
Tag::fallbackAddress(int $code, string $addressHash): Tag
Tag::routeHint(array $hops): Tag
Tag::featureBits(FeatureBits $bits): Tag
Tag::metadata(string $hex): Tag
```

### Enums

[](#enums)

```
enum Network: string {
    case Bitcoin = 'bc';
    case Testnet = 'tb';
    case Signet  = 'tbs';
    case Regtest = 'bcrt';
}

enum TagType: int {
    case PaymentHash = 1;
    case PaymentSecret = 16;
    case Description = 13;
    // ... and more
}

enum Multiplier: string {
    case Milli = 'm';
    case Micro = 'u';
    case Nano  = 'n';
    case Pico  = 'p';
}
```

BOLT 11 Spec Compliance
-----------------------

[](#bolt-11-spec-compliance)

All 12 official test vectors pass:

\#TestStatus1Donation (any amount)✅2$3 coffee (2500µ, 60s expiry)✅3UTF-8 description (ナンセンス 1杯)✅4Hashed description (20m)✅5Testnet with P2PKH fallback✅6Mainnet with P2PKH + route hints✅7Feature bits (8, 14, 99)✅8Uppercase invoice✅9Metadata (0x01fafaf0)✅10Pico-BTC amount (9678785340p)✅11High-S signature recovery✅12Unknown tags (silently ignored)✅### Supported Tagged Fields

[](#supported-tagged-fields)

CodeLetterFieldSupported1`p`payment\_hash✅16`s`payment\_secret✅13`d`description✅27`m`metadata✅19`n`payee node key✅23`h`description\_hash✅6`x`expiry✅24`c`min\_final\_cltv\_expiry✅9`f`fallback address✅3`r`route hints✅5`9`feature bits✅Exception Handling
------------------

[](#exception-handling)

```
use Nova\Bitcoin\Bolt11\Exception\{
    Bolt11Exception,           // Base exception
    InvalidInvoiceException,   // Malformed invoice
    InvalidChecksumException,  // Bad bech32 checksum
    InvalidSignatureException, // Signature issues
    InvalidAmountException,    // Bad amount format
    UnsupportedNetworkException, // Unknown network
};

try {
    $invoice = Decoder::decode($paymentRequest);
} catch (InvalidChecksumException $e) {
    // Bad checksum
} catch (InvalidInvoiceException $e) {
    // Malformed invoice
} catch (Bolt11Exception $e) {
    // Any BOLT 11 error
}
```

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

[](#development)

```
# Install dependencies
composer install

# Run tests
vendor/bin/phpunit

# Static analysis
vendor/bin/phpstan analyse

# Code style check
vendor/bin/php-cs-fixer fix --dry-run --diff

# Fix code style
vendor/bin/php-cs-fixer fix
```

Architecture
------------

[](#architecture)

```
src/
├── Decoder.php            # Main decoder
├── Encoder.php            # Main encoder
├── Signer.php             # Invoice signing (secp256k1)
├── Secp256k1Recovery.php  # ECDSA public key recovery
├── Invoice.php            # Immutable value object
├── Tag.php                # Tag value object with factory methods
├── TagType.php            # Tag type enum
├── Network.php            # Network enum (Bitcoin, Testnet, Signet, Regtest)
├── Multiplier.php         # Amount multiplier enum (m, u, n, p)
├── Amount.php             # Amount value object
├── RouteHint.php          # Route hint value object
├── FallbackAddress.php    # Fallback address value object
├── FeatureBits.php        # Feature bits handler
├── Bech32.php             # Bech32 encoder/decoder
├── Helpers.php            # Static helper methods
└── Exception/
    ├── Bolt11Exception.php
    ├── InvalidInvoiceException.php
    ├── InvalidChecksumException.php
    ├── InvalidSignatureException.php
    ├── InvalidAmountException.php
    └── UnsupportedNetworkException.php

```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance82

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

93d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/56e851d5bb00007a398de4c57afd1bfd709e2922fd8ad929c2feb65a92315957?d=identicon)[nova-carnivore](/maintainers/nova-carnivore)

---

Top Contributors

[![nova-carnivore](https://avatars.githubusercontent.com/u/259974792?v=4)](https://github.com/nova-carnivore "nova-carnivore (4 commits)")

---

Tags

invoicebitcoinLightninglightning-networkbech32bolt11payment-requestlnbc

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nova-carnivore-bolt11-php/health.svg)

```
[![Health](https://phpackages.com/badges/nova-carnivore-bolt11-php/health.svg)](https://phpackages.com/packages/nova-carnivore-bolt11-php)
```

###  Alternatives

[laraveldaily/laravel-invoices

Missing invoices for Laravel

1.5k1.3M4](/packages/laraveldaily-laravel-invoices)[horstoeko/zugferd

A library for creating and reading european electronic invoices

4174.3M18](/packages/horstoeko-zugferd)[atgp/factur-x

PHP library to manage your Factur-X / ZUGFeRD 2.0 PDF invoices files

138825.5k3](/packages/atgp-factur-x)[num-num/ubl-invoice

A modern object-oriented PHP library to create and read valid UBL and EN 16931/Peppol BIS 3.0 files

135820.5k](/packages/num-num-ubl-invoice)[anam/phantommagick

PhantomMagick provides a simple API to ease the process of converting HTML to PDF or images

161456.4k2](/packages/anam-phantommagick)[jorijn/bitcoin-bolt11

A library for decoding lightning network payment requests as defined in BOLT #11

1121.9k](/packages/jorijn-bitcoin-bolt11)

PHPackages © 2026

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