https://github.com/block/ln-invoice
Parse lightning network payment requests (invoices) in Kotlin.
https://github.com/block/ln-invoice
Last synced: 4 months ago
JSON representation
Parse lightning network payment requests (invoices) in Kotlin.
- Host: GitHub
- URL: https://github.com/block/ln-invoice
- Owner: block
- License: apache-2.0
- Created: 2023-07-19T21:29:52.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2026-01-13T23:09:53.000Z (5 months ago)
- Last Synced: 2026-01-24T22:39:06.787Z (4 months ago)
- Language: Kotlin
- Homepage: https://block.github.io/ln-invoice/
- Size: 104 KB
- Stars: 18
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README

Parse Bitcoin Lightning Network invoices (payment requests) in Kotlin. This library implements decoding of invoices as per
[BOLT-11: # Invoice Protocol for Lightning Payments](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md#bolt-11-invoice-protocol-for-lightning-payments)
[
](https://central.sonatype.com/namespace/app.cash.lninvoice)
## Getting Started
On the [Sonatype page for ln-invoice](https://central.sonatype.com/namespace/app.cash.lninvoice), choose the latest version
of `ln-invoice` and follow the instructions for inclusion in your build tool.
### Parsing a payment request
```kotlin
const val sample = "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq" +
"5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q5sqqqqqq" +
"qqqqqqqqqpqsq67gye39hfg3zd8rgc80k32tvy9xk2xunwm5lzexnvpx6fd77en8qaq424dxgt56cag2dpt359" +
"k3ssyhetktkpqh24jqnjyw6uqd08sgptq44qu"
val request: ErrorOr = PaymentRequest.parse(sample)
```
See `app.cash.lninvoice.PaymentRequestTest` for more parsing examples, lifted directly from the BOLT-11 spec.
LN-Invoice is functional programming safe by default, using [Quiver](https://github.com/block/quiver)
(an extension of [Arrow](https://arrow-kt.io/)). If you prefer to deal with thrown exceptions when parsing,
simply add `.orThrow()`.
```kotlin
val request: PaymentRequest = PaymentRequest.parse(sample).orThrow()
```
Fields in `PaymentRequest` instances that contain binary data use
[Okio's ByteString](https://square.github.io/okio/).
If you need this as a byte array, call `.toByteArray()`
```kotlin
val signature: ByteString = invoice.signature
val sigBytes: ByteArray = signature.toByteArray()
```
## Documentation
The [API documentation](https://block.github.io/ln-invoice) is published with each release.
## Changelog
See a list of changes in each release in the [CHANGELOG](CHANGELOG.md).
## Contributing
### Building
1. Install [Hermit](https://cashapp.github.io/hermit/), the hermetic project tooling tool.
2. Use `gradle` to run all tests locally:
```shell
gradle build
```
For more details on contributing, see the [CONTRIBUTING](CONTRIBUTING.md) guide.