# @integraledger/lcp/lightning

> The exports of @integraledger/lcp/lightning.

Source: https://lcp.integraledger.com/reference/api/lightning

## Interfaces

### Bolt11

#### Properties

| Property           | Type                                       | Description                                  |
| ------------------ | ------------------------------------------ | -------------------------------------------- |
|  `amountMsat`      | `bigint` \| `null`                         | -                                            |
|  `currency`        | `"bc"` \| `"tb"` \| `"tbs"` \| `"bcrt"`    | -                                            |
|  `description`     | `string` \| `null`                         | -                                            |
|  `descriptionHash` | `Uint8Array`\<`ArrayBufferLike`> \| `null` | -                                            |
|  `expiry`          | `number`                                   | -                                            |
|  `metadata`        | `Uint8Array`\<`ArrayBufferLike`> \| `null` | -                                            |
|  `paymentHash`     | `Uint8Array`                               | -                                            |
|  `tags`            | readonly `number`\[]                       | Every tagged field's type, in invoice order. |
|  `timestamp`       | `number`                                   | -                                            |

***

### LnMppChoice

#### Properties

| Property          | Type                                                         | Description                                                                                                 |
| ----------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
|  `challenge`      | [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#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`](https://lcp.integraledger.com/reference/api#refusal) | [`MppCredential`](https://lcp.integraledger.com/reference/api/mpp#mppcredential)

###### Parameters

| Parameter  | Type     |
| ---------- | -------- |
| `preimage` | `string` |

###### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`MppCredential`](https://lcp.integraledger.com/reference/api/mpp#mppcredential)

***

### LnRef

The read keys recorded at claim: 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`](https://lcp.integraledger.com/reference/api#refusal) | [`LnPaymentPayload`](#lnpaymentpayload)

###### Parameters

| Parameter  | Type     |
| ---------- | -------- |
| `preimage` | `string` |

###### Returns

[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnPaymentPayload`](#lnpaymentpayload)

## Type Aliases

### LnMppPairing

> **LnMppPairing** = *typeof* `LN_CHARGE` | *typeof* `LN_SESSION`

***

### LnNetwork

> **LnNetwork** = `"lnbtc:000000000019d6689c085ae165831e93"` | `"lnbtc:000000000933ea01ad0ee984209779ba"`

CAIP-2 for Lightning: `lnbtc:` and the first 32 hex digits of the Bitcoin network's genesis block hash.

***

### LnPaymentPayload

> **LnPaymentPayload** = `object`

#### Properties

| Property           | Type                                                                      |
| ------------------ | ------------------------------------------------------------------------- |
|  `accepted`        | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements)          |
|  `extensions?`     | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired)\[`"extensions"`] |
|  `payload`         | `object`                                                                  |
| `payload.preimage` | `string`                                                                  |
|  `resource?`       | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired)\[`"resource"`]   |
|  `x402Version`     | `2`                                                                       |

## Variables

### chargeLightning

> `const` **chargeLightning**: `Readonly`\<\{ `advertise`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; `advertiseBeforeCarrier`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; `bound`: (`presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `build`: (`choice`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnMppUnsigned`](#lnmppunsigned)>; `carrier`: `string`; `claims`: `boolean`; `id`: `"mpp/charge/lightning"`; `pattern`: [`LcpPattern`](https://lcp.integraledger.com/reference/api/x402#lcppattern); `read`: (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `agreement?`: `string`; `h`: `` `0x${string}` ``; `link`: `string`; `offer`: \{ `challenges`: [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; }; }; `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnRef`](#lnref)>; `tie`: (`options`) => \[`"mpp"`, \{ `challenges`: [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; }]; `unplaced`: (`c`) => [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge); }>

***

### exactLnbtc

> `const` **exactLnbtc**: `Readonly`\<\{ `advertise`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired); `advertiseBeforeCarrier`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired); `bound`: (`presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `build`: (`c`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnUnsigned`](#lnunsigned)>; `carrier`: `"extra.invoice#m"`; `claims`: `boolean`; `id`: `"x402/exact/lnbtc"`; `pattern`: [`LcpPattern`](https://lcp.integraledger.com/reference/api/x402#lcppattern); `read`: (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`X402Read`](https://lcp.integraledger.com/reference/api/x402#x402read); `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnRef`](#lnref)>; `tie`: (`accepts`, `request`) => \[`"x402"`, \{ `accepts`: readonly [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements)\[]; `request`: [`RequestCommitment`](https://lcp.integraledger.com/reference/api/x402#requestcommitment); }]; `unplaced`: (`option`) => [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements); }>

***

### exactLnbtcNamed

> `const` **exactLnbtcNamed**: `Readonly`\<\{ `advertise`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired); `bound`: (`presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `build`: (`c`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnUnsigned`](#lnunsigned)>; `carrier`: `null`; `claims`: `boolean`; `id`: `"x402/exact/lnbtc/invoice-named"`; `pattern`: [`LcpPattern`](https://lcp.integraledger.com/reference/api/x402#lcppattern); `read`: (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`X402Read`](https://lcp.integraledger.com/reference/api/x402#x402read); `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnRef`](#lnref)>; `tie`: (`accepts`, `request`) => \[`"x402"`, \{ `accepts`: readonly [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements)\[]; `request`: [`RequestCommitment`](https://lcp.integraledger.com/reference/api/x402#requestcommitment); }]; `unplaced`: (`option`) => [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements); }>

***

### sessionLightning

> `const` **sessionLightning**: `Readonly`\<\{ `advertise`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; `advertiseBeforeCarrier`: (`doc`, `h`, `link`, `offer`, `agreementUrl?`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; `bound`: (`presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `build`: (`choice`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnMppUnsigned`](#lnmppunsigned)>; `carrier`: `string`; `channel`: `Readonly`\<\{ `boundWithin`: (`_presented`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `kind`: (`presented`) => `"open"` | `"close"` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `"within"`; `ref`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `channel`: `string`; `network`: `string`; }>; `until`: (`_presented`) => `number` | `undefined`; }>; `claims`: `boolean`; `id`: `"mpp/session/lightning"`; `pattern`: [`LcpPattern`](https://lcp.integraledger.com/reference/api/x402#lcppattern); `read`: (`doc`) => [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | \{ `agreement?`: `string`; `h`: `` `0x${string}` ``; `link`: `string`; `offer`: \{ `challenges`: [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; }; }; `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`LnRef`](#lnref)>; `tie`: (`options`) => \[`"mpp"`, \{ `challenges`: [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge)\[]; }]; `unplaced`: (`c`) => [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge); }>

## Functions

### atrNamesInvoice()

> **atrNamesInvoice**(`atr`, `invoice`): `boolean`

True when the ATR's bytes are one JSON object whose `x402` slot's `accepts` holds an option whose
`extra.invoice` is exactly `invoice`. Only that slot is read.

#### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `atr`     | `Uint8Array` |
| `invoice` | `string`     |

#### Returns

`boolean`

***

### decodeBolt11()

> **decodeBolt11**(`invoice`): `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`Bolt11`](#bolt11)>

Decodes a BOLT11 invoice without its length limit, up to 8 KiB. The signature is not verified.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `invoice` | `string` |

#### Returns

`Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`Bolt11`](#bolt11)>

***

### invoiceH()

> **invoiceH**(`b`, `field`): `` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

The one 32-byte `h` or `m` field of an invoice, as the hash it carries.

#### Parameters

| Parameter | Type                |
| --------- | ------------------- |
| `b`       | [`Bolt11`](#bolt11) |
| `field`   | `"h"` \| `"m"`      |

#### Returns

`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

***

### lnbtcPairingOf()

> **lnbtcPairingOf**(`option`): `"x402/exact/lnbtc"` | `"x402/exact/lnbtc/invoice-named"` | `undefined`

Which of the two x402 Lightning pairings an option belongs to: by whether its invoice has an `m` field. An option
whose `extra` has no `invoice` is the offer the seller sends before its node writes the invoice, so it is
`x402/exact/lnbtc`; an `invoice-named` option carries its invoice at issue.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `option`  | `unknown` |

#### Returns

`"x402/exact/lnbtc"` | `"x402/exact/lnbtc/invoice-named"` | `undefined`
