@integraledger/lcp/lightning
BOLT11 invoices and the Lightning pairings: on x402 (`x402/exact/lnbtc/payment-hash`) the ATR commits the option's `extra.paymentHash`, and on MPP the seller's node writes the ATR hash as the invoice's description hash `h`.
For AI agents: this page as Markdown, and llms.txt, the index of every page.
BOLT11 invoices and the Lightning pairings: on x402 (x402/exact/lnbtc/payment-hash) the ATR commits the option's
extra.paymentHash, and on MPP the seller's node writes the ATR hash as the invoice's description hash h.
The payment hash is that of the invoice the seller's node issues after the agreement. The payer signs nothing; it pays the invoice.
Interfaces
Bolt11
A decoded BOLT11 invoice. B is what its bytes are backed by: decodeBolt11 gives Bolt11<ArrayBuffer>, each byte
field in its own fresh ArrayBuffer, and a function that reads one takes any backing.
Type Parameters
| Type Parameter | Default type |
|---|---|
B extends ArrayBufferLike | ArrayBufferLike |
Properties
| Property | Type | Description |
|---|---|---|
amountMsat | bigint | null | - |
currency | "bc" | "tb" | "tbs" | "bcrt" | - |
description | string | null | The d field as strict UTF-8, a leading byte-order mark kept as a character; null when the invoice has none. |
descriptionHash | Uint8Array<B> | null | - |
expiry | number | - |
metadata | Uint8Array<B> | null | - |
paymentHash | Uint8Array<B> | - |
signer | string | The compressed secp256k1 public key that signed the invoice, as 66 lowercase hex digits: the n field's key where the invoice has one, and otherwise the key recovered from the signature. |
tags | readonly number[] | Every tagged field's type, in invoice order. |
timestamp | number | - |
LnChoice
The buyer's choice: the 402 document, the option it pays, its validation time in Unix seconds, and its own request.
Properties
| Property | Type | Description |
|---|---|---|
accepted | PaymentRequirements | - |
now | number | - |
request | LnbtcRequest | The request the buyer means to make, from which build computes the scheme's request hash. |
required | PaymentRequired | - |
LnMppChoice
Properties
| Property | Type | Description |
|---|---|---|
challenge | MppChallenge & object | - |
returnInvoice? | string | session only: the payer's return invoice, a BOLT11 invoice with no amount, which the open action registers. |
LnMppUnsigned
Properties
| Property | Type |
|---|---|
request | object |
request.invoice | string |
request.kind | "bolt11-pay" |
Methods
complete()
complete(
preimage):Refusal|MppCredential
The credential for the paid invoice's preimage. A credential over the credential size bound, 64 KiB, its echoed
challenge included, is mpp/credential-malformed, as bound refuses it, and is read first; a preimage that is not
64 lowercase hex digits is ln/preimage-malformed.
Parameters
| Parameter | Type |
|---|---|
preimage | string |
Returns
LnRef
The read keys reference returns: the invoice's payment hash as lowercase hex, and when the payment can land.
Properties
| Property | Type |
|---|---|
network | string |
paymentHash | string |
settleBy | number |
LnUnsigned
Properties
| Property | Type | Description |
|---|---|---|
request | object | The payer's node pays exactly this invoice. |
request.invoice | string | - |
request.kind | "bolt11-pay" | - |
Methods
complete()
complete(
preimage):Refusal|LnPaymentPayload
Parameters
| Parameter | Type |
|---|---|
preimage | string |
Returns
Type Aliases
ExactLnbtcReason
ExactLnbtcReason =
"unsupported_scheme"|"network_mismatch"|"unsupported_network"|"invalid_exact_lnbtc_asset"|"invalid_exact_lnbtc_amount"|"invalid_exact_lnbtc_amount_mismatch"|"invalid_exact_lnbtc_pay_to_mismatch"|"invalid_exact_lnbtc_pay_to_malformed"|"invalid_exact_lnbtc_max_timeout_mismatch"|"invalid_exact_lnbtc_extra_mismatch"|"invalid_exact_lnbtc_request_binding"|"invalid_exact_lnbtc_request_mismatch"|"invalid_exact_lnbtc_asset_transfer_method"|"invalid_exact_lnbtc_payment_flow"|"invalid_exact_lnbtc_invoice_missing"|"invalid_exact_lnbtc_invoice_decode_failed"|"invalid_exact_lnbtc_invoice_description"|"invalid_exact_lnbtc_invoice_request_mismatch"|"invalid_exact_lnbtc_invoice_payee_mismatch"|"invalid_exact_lnbtc_invoice_currency_mismatch"|"invalid_exact_lnbtc_invoice_amount_mismatch"|"invalid_exact_lnbtc_max_timeout"|"invalid_exact_lnbtc_invoice_expiry_mismatch"|"invalid_exact_lnbtc_invoice_created_in_future"|"invalid_exact_lnbtc_invoice_payment_hash_mismatch"|"invalid_exact_lnbtc_preimage_missing"|"invalid_exact_lnbtc_preimage_malformed"|"invalid_exact_lnbtc_preimage_length"|"invalid_exact_lnbtc_preimage_hash_mismatch"|"invalid_exact_lnbtc_invoice_expired"
The scheme's errorReason strings its validation gives, and this form's one more.
ExactLnbtcValidation
ExactLnbtcValidation = {
network:LnNetwork;paymentHash:string;valid:true; } | {reason:ExactLnbtcReason;valid:false; }
The validation's answer: the network and payment hash of the scheme's consumption key, or the scheme's reason.
LnbtcRequest
LnbtcRequest = {
body:Uint8Array;headers?:LnHeaderFields;method:string;profile:"http:1";url:string; } | {arguments?:Json;meta?:Json;name:string;profile:"mcp:1";server:string; }
The buyer's intended request, which the scheme's request binding commits to.
Union Members
Type Literal
{ body: Uint8Array; headers?: LnHeaderFields; method: string; profile: "http:1"; url: string; }
| Name | Type | Description |
|---|---|---|
body | Uint8Array | The content bytes after transfer decoding; empty where the request has no body. |
headers? | LnHeaderFields | - |
method | string | The method, case kept. |
profile | "http:1" | An HTTP request (the scheme's http:1). |
url | string | The absolute URL the request is made to, its query included. |
Type Literal
{ arguments?: Json; meta?: Json; name: string; profile: "mcp:1"; server: string; }
| Name | Type | Description |
|---|---|---|
arguments? | Json | params.arguments; absent is {}. |
meta? | Json | params._meta; absent is {}. |
name | string | - |
profile | "mcp:1" | An MCP tools/call (the scheme's mcp:1). |
server | string | The MCP server the buyer means to call, as its own configuration spells it. |
LnHeaderFields
LnHeaderFields =
Readonly<Record<string,string| readonlystring[]>>
A request's header fields as received: each field's name, in any case, with its lines in order, or its one line.
LnNetwork
LnNetwork =
"lnbtc:000000000019d6689c085ae165831e93"|"lnbtc:000000000933ea01ad0ee984209779ba"
x402's lnbtc network ids, in CAIP-2 form: lnbtc: and the first 32 hex digits of the genesis block hash of
Bitcoin mainnet or testnet3. lnbtc is x402's own namespace.
LnPaymentPayload
LnPaymentPayload =
object
Properties
| Property | Type |
|---|---|
accepted | PaymentRequirements |
extensions? | PaymentRequired["extensions"] |
payload | object |
payload.preimage | string |
resource? | PaymentRequired["resource"] |
x402Version | 2 |
Variables
chargeLightning
constchargeLightning:Readonly<{advertise: (doc,h,link,offer,position,act?,agreementUrl?) =>Refusal|MppChallenge[];advertiseBeforeCarrier: (doc,h,link,offer,position,act?,agreementUrl?) =>Refusal|MppChallenge[];bound: (presented) =>Promise<Refusal|`0x${string}`>;broadcaster: (presented) =>Promise<Refusal|Broadcaster>;build: (choice,h) =>Promise<Refusal|LnMppUnsigned>;claims:boolean;data:PairingData;id:"mpp/charge/lightning";pattern:LcpPattern;read: (doc) =>Refusal| {agreement?:string;h:`0x${string}`;link:string;offer: {challenges:MppChallenge[]; }; };reference: (presented) =>Promise<Refusal|LnRef>;tie: (options) => ["mpp", {challenges:MppChallenge[]; }];unplaced: (c) =>Refusal|MppChallenge; }>
mpp/charge/lightning. The payer broadcasts (broadcaster answers "payer"): its node pays the invoice before the
preimage is presented. The seller's node, which received the payment, confirms it; reference names the invoice,
and no status reads it.
exactLnbtcPaymentHash
constexactLnbtcPaymentHash:Readonly<{advertise:X402Advertise;advertiseBeforeCarrier:X402Advertise;bound: (presented) =>Promise<Refusal|`0x${string}`>;broadcaster: (presented) =>Promise<Refusal|Broadcaster>;build: (c,h) =>Promise<Refusal|LnUnsigned>;claims:boolean;data:PairingData;id:"x402/exact/lnbtc/payment-hash";pattern:LcpPattern;read: (doc) =>Refusal|X402Read;reference: (presented,option) =>Promise<Refusal|LnRef>;tie: (accepts,request) => ["x402", {accepts: readonlyPaymentRequirements[];request:RequestCommitment|ToolCallCommitment; }];unplaced: (option) =>Refusal|PaymentRequirements; }>
x402/exact/lnbtc/payment-hash. The payer broadcasts (broadcaster answers "payer"): its node pays the invoice
before the preimage is presented. No ledger shows the payment, and no status reads it. advertiseBeforeCarrier
places the offer the seller issues before its node writes the invoice; advertise the option with the invoice.
sessionLightning
constsessionLightning:Readonly<{advertise: (doc,h,link,offer,position,act?,agreementUrl?) =>Refusal|MppChallenge[];advertiseBeforeCarrier: (doc,h,link,offer,position,act?,agreementUrl?) =>Refusal|MppChallenge[];bound: (presented) =>Promise<Refusal|`0x${string}`>;broadcaster: (presented) =>Promise<Refusal|Broadcaster>;build: (choice,h) =>Promise<Refusal|LnMppUnsigned>;channel:Readonly<{boundWithin: (presented) =>Promise<Refusal|`0x${string}`>;kind: (presented) =>"open"|"close"|Refusal|"within";ref: (presented) =>Promise<Refusal| {channel:string;network:string; }>;until: (_presented) =>number|undefined; }>;claims:boolean;data:PairingData;id:"mpp/session/lightning";pattern:LcpPattern;read: (doc) =>Refusal| {agreement?:string;h:`0x${string}`;link:string;offer: {challenges:MppChallenge[]; }; };reference: (presented) =>Promise<Refusal|LnRef>;tie: (options) => ["mpp", {challenges:MppChallenge[]; }];unplaced: (c) =>Refusal|MppChallenge; }>
mpp/session/lightning. broadcaster answers by the payment's action (sessionBroadcasts), for the actions
channel.kind takes. "payer": the opening and a top-up, whose deposits the payer's node paid, and a bearer proof,
which draws on them; the seller's node, which received each deposit, confirms it, and no status reads it.
"payee": the close, whose refund the seller's node pays. Any other action gets ln/no-payment-in-action, as bound
refuses it.
Functions
checkPreimage()
checkPreimage(
preimage,paymentHash):true|Refusal
The preimage check: true where preimage is 64 lowercase hex digits whose SHA-256 is paymentHash, itself 64
lowercase hex digits; else ln/preimage-malformed, ln/payment-hash-required or ln/preimage-mismatch, in that
order. A resource server makes it before it serves a Lightning payment.
Parameters
| Parameter | Type |
|---|---|
preimage | string |
paymentHash | string |
Returns
true | Refusal
decodeBolt11()
decodeBolt11(
invoice):Promise<Refusal|Bolt11<ArrayBuffer>>
Decodes a BOLT11 invoice of up to 8,192 characters strictly, past Bech32's 90-character limit, which BOLT 11 lets an
invoice exceed: exactly one p and one s field, at most one n field, and a signature that verifies, by the n
key where the invoice has one (a low s required) and otherwise by public-key recovery; signer is that key. An
invoice that fails is ln/invoice-malformed; one of more characters, or of more than 64 tagged fields, is
ln/invoice-too-large.
Parameters
| Parameter | Type |
|---|---|
invoice | string |
Returns
Promise<Refusal | Bolt11<ArrayBuffer>>
invoiceH()
invoiceH(
b,field):Refusal|`0x${string}`
The one 32-byte h or m field of an invoice, as the hash it carries.
Parameters
| Parameter | Type |
|---|---|
b | Bolt11 |
field | "h" | "m" |
Returns
Refusal | `0x${string}`
requestHash()
requestHash(
profile,params,request,resourceUrl):string|Refusal
The scheme's request hash of request under profile and params, as 64 lowercase hex digits: SHA-256 of the UTF-8
of RFC 8785's form of the profile's binding object. ln/request-hash-mismatch where the request is not of profile,
where on http:1 resourceUrl is not the request's URL, or on mcp:1 the option's server is not the request's;
ln/request-binding-malformed where params are not the profile's or the request cannot be bound: a method that is
not a token, a URL that is not an absolute http or https URL in ASCII without user information or fragment, a
body that is not bytes or is over 1 MiB, a header record that is not a record of strings or lists of strings or a
bound field's value outside the scheme's form, a tool name that is empty, arguments or _meta that are not a JSON
object, or a value RFC 8785 cannot write.
A seller's server computes it from the request that will execute, with the option's extra.requestBindingProfile
and extra.requestBindingParams and the document's resource.url, and writes it as the option's extra.requestHash,
the invoice's h and the requirements it validates a payment against (profile x402/exact/lnbtc/payment-hash, rules
2, 5 and 10); the buyer's build computes it from the buyer's intended request and holds it to extra.requestHash.
Parameters
| Parameter | Type |
|---|---|
profile | unknown |
params | unknown |
request | unknown |
resourceUrl | unknown |
Returns
string | Refusal
validateExactLnbtc()
validateExactLnbtc(
payload,requirements,at):Refusal|ExactLnbtcValidation
x402's validation of exact on lnbtc (the scheme's Facilitator Validation, checks 1 to 7 and its Paid-but-expired
Policy), in the scheme's order, with this form's one check added at the end of check 5: the accepted invoice's p
is requirements.extra.paymentHash (invalid_exact_lnbtc_invoice_payment_hash_mismatch). payload is the payment
presented; requirements the ones the resource server built from its own record of the sale; now the validation
time and skew the clock-skew allowance, in seconds, 60 by default. A failure answers the scheme's errorReason; a
success answers the network and the payment hash of the scheme's consumption key. It moves nothing, reads nothing,
and records nothing: the resource server or a settler records the key once after it. A now or skew that is not a
non-negative safe integer is ln/time-malformed.
Parameters
| Parameter | Type |
|---|---|
payload | unknown |
requirements | unknown |
at | { now: number; skew?: number; } |
at.now | number |
at.skew? | number |
Returns
Refusal | ExactLnbtcValidation
References
Broadcaster
Re-exports Broadcaster
X402Advertise
Re-exports X402Advertise
X402Read
Re-exports X402Read
Last updated on
@integraledger/lcp/hedera
Hedera: the x402 pairings `x402/exact/hedera` (the ATR hash as the signed body memo) and `x402/exact/hedera/transfer-executor` (the hash advertised in the challenge only), with the transaction wire form and the Mirror Node settlement read.
@integraledger/lcp/mpp
The `mpp` entry point: MPP's challenge pieces, its three fields (`encodeChallenge` writes a `WWW-Authenticate` value, `encodeCredential` and `decodeCredential` write and read an `Authorization` value, `encodeReceipt` and `decodeReceipt` write and read a `Payment-Receipt` value) and its pairings: the EVM charges, defined here, and every other MPP charge, session and subscription pairing but Lightning's, re-exported from its module.