# @integraledger/lcp

> The exports of @integraledger/lcp.

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

## Interfaces

### CarrierAfterH

The optional member of a pairing whose carrier the seller writes after H: `advertise`'s checks and placement, without
the checks on that carrier.

#### Methods

##### advertiseBeforeCarrier()?

> `optional` **advertiseBeforeCarrier**(`doc`, `h`, `link`, `offer`, `agreementUrl?`): `unknown`

###### Parameters

| Parameter       | Type                |
| --------------- | ------------------- |
| `doc`           | `never`             |
| `h`             | `` `0x${string}` `` |
| `link`          | `string`            |
| `offer`         | `never`             |
| `agreementUrl?` | `string`            |

###### Returns

`unknown`

***

### PresentedOn

What the buyer presents as payment, per surface: the union of the payment types of every pairing on it. Every
pairing's `bound` and `reference` take `unknown` and check what they are given.

#### Properties

| Property | Type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Description                                                                |
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|  `ack`   | [`Json`](#json)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | ACK defines no payer signature; its `bound` refuses whatever is presented. |
|  `acp`   | [`Presented`](https://lcp.integraledger.com/reference/api/acp#presented)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | -                                                                          |
|  `ap2`   | [`Presented`](https://lcp.integraledger.com/reference/api/ap2#presented)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | -                                                                          |
|  `card`  | [`TapPresented`](https://lcp.integraledger.com/reference/api/card#tappresented) \| [`ViImmediate`](https://lcp.integraledger.com/reference/api/card#viimmediate) \| [`ViAutonomous`](https://lcp.integraledger.com/reference/api/card#viautonomous)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | -                                                                          |
|  `mpp`   | [`MppCredential`](https://lcp.integraledger.com/reference/api/mpp#mppcredential)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | -                                                                          |
|  `ucp`   | [`Presented`](https://lcp.integraledger.com/reference/api/ap2#presented)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | -                                                                          |
|  `x402`  | [`PaymentPayload`](https://lcp.integraledger.com/reference/api/x402#paymentpayload) \| [`HederaPaymentPayload`](https://lcp.integraledger.com/reference/api/hedera#hederapaymentpayload) \| [`ExecutorPaymentPayload`](https://lcp.integraledger.com/reference/api/hedera#executorpaymentpayload) \| [`LnPaymentPayload`](https://lcp.integraledger.com/reference/api/lightning#lnpaymentpayload) \| [`AptosPaymentPayload`](https://lcp.integraledger.com/reference/api/aptos#aptospaymentpayload) \| [`AvmPaymentPayload`](https://lcp.integraledger.com/reference/api/avm#avmpaymentpayload) \| [`CardanoPaymentPayload`](https://lcp.integraledger.com/reference/api/cardano#cardanopaymentpayload) \| [`CasperPaymentPayload`](https://lcp.integraledger.com/reference/api/casper#casperpaymentpayload) \| [`CcdPaymentPayload`](https://lcp.integraledger.com/reference/api/ccd#ccdpaymentpayload) \| [`NearPayment`](https://lcp.integraledger.com/reference/api/near#nearpayment) \| [`PolkadotPaymentPayload`](https://lcp.integraledger.com/reference/api/polkadot#polkadotpaymentpayload) \| [`StarknetPayment`](https://lcp.integraledger.com/reference/api/starknet#starknetpayment) \| [`SuiPaymentPayload`](https://lcp.integraledger.com/reference/api/sui#suipaymentpayload) \| [`TronPayment`](https://lcp.integraledger.com/reference/api/tron#tronpayment) \| [`TvmPayment`](https://lcp.integraledger.com/reference/api/tvm#tvmpayment) \| [`BatchPaymentPayload`](https://lcp.integraledger.com/reference/api/x402-batch-settlement#batchpaymentpayload) \| [`CloudflarePaymentPayload`](https://lcp.integraledger.com/reference/api/x402-batch-settlement#cloudflarepaymentpayload) \| [`SvmPaymentPayload`](https://lcp.integraledger.com/reference/api/x402-exact-solana#svmpaymentpayload) \| [`StellarPaymentPayload`](https://lcp.integraledger.com/reference/api/x402-exact-stellar#stellarpaymentpayload) \| [`XrplPaymentPayload`](https://lcp.integraledger.com/reference/api/x402-exact-xrpl#xrplpaymentpayload) \| [`UptoSvmPaymentPayload`](https://lcp.integraledger.com/reference/api/x402-upto-solana#uptosvmpaymentpayload) | -                                                                          |

***

### PushMode

The optional member of a push-mode pairing: the transaction its credential names, or undefined.

#### Methods

##### landedTx()?

> `optional` **landedTx**(`presented`): `string` | `undefined`

###### Parameters

| Parameter   | Type      |
| ----------- | --------- |
| `presented` | `unknown` |

###### Returns

`string` | `undefined`

***

### TieRequestOn

The request a surface's `tie` takes with its options: x402's request commitment; the others' `tie` takes none.

#### Properties

| Property | Type                                                         |
| -------- | ------------------------------------------------------------ |
|  `ack`   | `never`                                                      |
|  `acp`   | `never`                                                      |
|  `ap2`   | `never`                                                      |
|  `card`  | `never`                                                      |
|  `mpp`   | `never`                                                      |
|  `ucp`   | `never`                                                      |
|  `x402`  | [`RequestCommitment`](https://lcp.integraledger.com/reference/api/x402#requestcommitment) |

***

### TxSpelling

The optional member of a pairing whose rail spells one transaction id more than one way: the id in the one spelling
a record keeps.

#### Methods

##### txId()?

> `optional` **txId**(`tx`): `string`

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `tx`      | `string` |

###### Returns

`string`

## Type Aliases

### AtrHash

> **AtrHash** = `` `0x${string}` ``

`0x` followed by 64 hex digits. Every hash this module emits is lowercase.

***

### Binding

> **Binding** = [`X402Binding`](#x402binding) | [`MppBinding`](#mppbinding) | *typeof* [`paymentRequest`](https://lcp.integraledger.com/reference/api/ack#paymentrequest) | *typeof* [`delegated`](https://lcp.integraledger.com/reference/api/acp#delegated) | *typeof* [`undelegated`](https://lcp.integraledger.com/reference/api/acp#undelegated) | *typeof* [`checkoutMandate`](https://lcp.integraledger.com/reference/api/ap2#checkoutmandate) | *typeof* [`viAutonomous`](https://lcp.integraledger.com/reference/api/card#viautonomous-1) | *typeof* [`viImmediate`](https://lcp.integraledger.com/reference/api/card#viimmediate-1) | *typeof* [`sellerReference`](https://lcp.integraledger.com/reference/api/card#sellerreference) | *typeof* [`visaTap`](https://lcp.integraledger.com/reference/api/card#visatap) | *typeof* [`bookingAp2Mandate`](https://lcp.integraledger.com/reference/api/ucp#bookingap2mandate) | *typeof* [`bookingUnsigned`](https://lcp.integraledger.com/reference/api/ucp#bookingunsigned) | *typeof* [`ap2Mandate`](https://lcp.integraledger.com/reference/api/ucp#ap2mandate) | *typeof* [`unsigned`](https://lcp.integraledger.com/reference/api/ucp#unsigned-1) & [`PushMode`](#pushmode) & [`CarrierAfterH`](#carrierafterh) & [`TxSpelling`](#txspelling)

A pairing of protocol, scheme and rail.

***

### CoreRefusal

> **CoreRefusal** = `object`

#### Properties

| Property   | Type                                                                                                                                                    |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|  `code`    | `"core/slot-name"` \| `"core/slot-reserved"` \| `"core/slot-duplicate"` \| `"core/content-not-json"` \| `"core/binding-not-json"` \| `"core/too-large"` |
|  `refused` | `true`                                                                                                                                                  |

***

### Json

> **Json** = `string` | `number` | `boolean` | `null` | readonly [`Json`](#json)\[] | \{\[`k`: `string`]: [`Json`](#json); }

A JSON value. Numbers in a binding value must be safe integers.

***

### MppBinding

> **MppBinding** = *typeof* [`MPP_BINDINGS`](https://lcp.integraledger.com/reference/api/mpp#mpp_bindings)\[`number`]

An MPP pairing of intent and method.

***

### PairingId

> **PairingId** = [`Binding`](#binding)\[`"id"`]

***

### PairingOn

> **PairingOn**\<`S`> = `Extract`\<[`PairingId`](#pairingid), `` `${S}/${string}` ``>

The pairing ids of one surface.

#### Type Parameters

| Type Parameter                      |
| ----------------------------------- |
| `S` *extends* [`Surface`](#surface) |

***

### Presented

> **Presented** = [`PresentedOn`](#presentedon)\[[`Surface`](#surface)]

What the buyer presents as payment.

***

### Refusal

> **Refusal** = `object`

A refusal returned as a value. `code` is `<entry point>/<reason>`.

#### Properties

| Property   | Type     |
| ---------- | -------- |
|  `code`    | `string` |
|  `refused` | `true`   |

***

### Surface

> **Surface** = keyof [`PresentedOn`](#presentedon)

The surfaces: a pairing id's first "/" segment.

***

### X402Binding

> **X402Binding** = *typeof* [`exactEip3009`](https://lcp.integraledger.com/reference/api/x402#exacteip3009) | *typeof* [`authCaptureEip3009`](https://lcp.integraledger.com/reference/api/x402#authcaptureeip3009) | *typeof* [`authCapturePermit2`](https://lcp.integraledger.com/reference/api/x402#authcapturepermit2) | *typeof* [`batchCloudflare`](https://lcp.integraledger.com/reference/api/x402-batch-settlement#batchcloudflare) | *typeof* [`batchEvm`](https://lcp.integraledger.com/reference/api/x402-batch-settlement#batchevm) | *typeof* [`batchSvm`](https://lcp.integraledger.com/reference/api/x402-batch-settlement#batchsvm) | *typeof* [`exactAvm`](https://lcp.integraledger.com/reference/api/avm#exactavm) | *typeof* [`exactAptos`](https://lcp.integraledger.com/reference/api/aptos#exactaptos) | *typeof* [`exactCardano`](https://lcp.integraledger.com/reference/api/cardano#exactcardano) | *typeof* [`exactCasper`](https://lcp.integraledger.com/reference/api/casper#exactcasper) | *typeof* [`exactCcd`](https://lcp.integraledger.com/reference/api/ccd#exactccd) | *typeof* [`exactErc7710`](https://lcp.integraledger.com/reference/api/x402#exacterc7710) | *typeof* [`exactErc7710Salt`](https://lcp.integraledger.com/reference/api/x402#exacterc7710salt) | *typeof* [`exactPermit2`](https://lcp.integraledger.com/reference/api/x402#exactpermit2) | *typeof* [`exactHedera`](https://lcp.integraledger.com/reference/api/hedera#exacthedera) | *typeof* [`exactHederaExecutor`](https://lcp.integraledger.com/reference/api/hedera#exacthederaexecutor) | *typeof* [`exactLnbtc`](https://lcp.integraledger.com/reference/api/lightning#exactlnbtc) | *typeof* [`exactLnbtcNamed`](https://lcp.integraledger.com/reference/api/lightning#exactlnbtcnamed) | *typeof* [`exactNear`](https://lcp.integraledger.com/reference/api/near#exactnear) | *typeof* [`exactPolkadotRemark`](https://lcp.integraledger.com/reference/api/polkadot#exactpolkadotremark) | *typeof* [`exactSvm`](https://lcp.integraledger.com/reference/api/x402-exact-solana#exactsvm) | *typeof* [`exactStarknet`](https://lcp.integraledger.com/reference/api/starknet#exactstarknet) | *typeof* [`exactStellar`](https://lcp.integraledger.com/reference/api/x402-exact-stellar#exactstellar) | *typeof* [`exactSui`](https://lcp.integraledger.com/reference/api/sui#exactsui) | *typeof* [`exactTronMemo`](https://lcp.integraledger.com/reference/api/tron#exacttronmemo) | *typeof* [`exactTvm`](https://lcp.integraledger.com/reference/api/tvm#exacttvm) | *typeof* [`exactXrpl`](https://lcp.integraledger.com/reference/api/x402-exact-xrpl#exactxrpl) | *typeof* [`uptoPermit2`](https://lcp.integraledger.com/reference/api/x402#uptopermit2) | *typeof* [`uptoSvm`](https://lcp.integraledger.com/reference/api/x402-upto-solana#uptosvm)

An x402 pairing of scheme and rail.

## Variables

### BINDINGS

> `const` **BINDINGS**: readonly [`Binding`](#binding)\[]

Every pairing this package implements.

***

### MAX\_JSON\_DEPTH

> `const` **MAX\_JSON\_DEPTH**: `64` = `64`

The deepest nesting of arrays and objects in any JSON this package writes or reads.

## Functions

### assemble()

> **assemble**(`id`, `binding`, `content`, `limits?`): `Promise`\<[`CoreRefusal`](#corerefusal) | \{ `atrHash`: `` `0x${string}` ``; `bytes`: `Uint8Array`; }>

Writes the ATR's bytes and hashes them. The same inputs always give the same bytes. Every problem with the inputs
is returned as a refusal.

#### Parameters

| Parameter          | Type                                                               |
| ------------------ | ------------------------------------------------------------------ |
| `id`               | `string`                                                           |
| `binding`          | readonly \[`string`, [`Json`](#json)]                              |
| `content`          | readonly readonly \[`string`, `Uint8Array`\<`ArrayBufferLike`>]\[] |
| `limits?`          | \{ `maxBytes?`: `number`; }                                        |
| `limits.maxBytes?` | `number`                                                           |

#### Returns

`Promise`\<[`CoreRefusal`](#corerefusal) | \{ `atrHash`: `` `0x${string}` ``; `bytes`: `Uint8Array`; }>

***

### canonicalJson()

> **canonicalJson**(`v`): `string` | [`CoreRefusal`](#corerefusal)

The RFC 8785 form of `v`: object members sorted by the UTF-16 code units of their names, recursively, and every
primitive written as `JSON.stringify` writes it. Refuses what `digestJson` refuses.

#### Parameters

| Parameter | Type            |
| --------- | --------------- |
| `v`       | [`Json`](#json) |

#### Returns

`string` | [`CoreRefusal`](#corerefusal)

***

### canonicalTx()

> **canonicalTx**(`binding`, `tx`): `string`

A transaction id as a record keeps it: the pairing's `txId`, where it has one, else the id unchanged.

#### Parameters

| Parameter | Type                                 |
| --------- | ------------------------------------ |
| `binding` | [`Binding`](#binding) \| `undefined` |
| `tx`      | `string`                             |

#### Returns

`string`

***

### digestJson()

> **digestJson**(`v`): `Promise`\<`` `0x${string}` `` | [`CoreRefusal`](#corerefusal)>

SHA-256 over the RFC 8785 form of `v`. Refuses a value deeper than 64 levels, a non-finite number, a string with
an unpaired surrogate, or anything that is not a JSON value.

#### Parameters

| Parameter | Type            |
| --------- | --------------- |
| `v`       | [`Json`](#json) |

#### Returns

`Promise`\<`` `0x${string}` `` | [`CoreRefusal`](#corerefusal)>

***

### fromLcpString()

> **fromLcpString**(`s`): `` `0x${string}` `` | `null`

Decodes `lcp:sha256:0x…`, returning the lowercase hash, or null for anything else.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `s`       | `string` |

#### Returns

`` `0x${string}` `` | `null`

***

### fromLegalContext()

> **fromLegalContext**(`o`): \{ `h`: `` `0x${string}` ``; `url`: `string`; } | `null`

Decodes the structured form: `type` "sha256", a 32-byte hash, and an `https://` link in either spelling. Returns
the lowercase hash and the link, or null for anything else, including two spellings that disagree. Other members
are ignored.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `o`       | `unknown` |

#### Returns

\{ `h`: `` `0x${string}` ``; `url`: `string`; } | `null`

***

### fromRawBytes()

> **fromRawBytes**(`b`): `` `0x${string}` `` | `null`

The lowercase hash of exactly 32 raw bytes, or null.

#### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `b`       | `Uint8Array` |

#### Returns

`` `0x${string}` `` | `null`

***

### hash()

> **hash**(`bytes`): `Promise`\<`` `0x${string}` ``>

SHA-256 over the bytes as given, as `0x` and lowercase hex.

#### Parameters

| Parameter | Type         |
| --------- | ------------ |
| `bytes`   | `Uint8Array` |

#### Returns

`Promise`\<`` `0x${string}` ``>

***

### hashEquals()

> **hashEquals**(`a`, `b`): `boolean`

True when `a` and `b` are each `0x` and 64 hex digits, in either case, and decode to the same 32 bytes (LCP §2.5).
Anything else is false.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `a`       | `string` |
| `b`       | `string` |

#### Returns

`boolean`

***

### isHashWithNonHttpsLink()

> **isHashWithNonHttpsLink**(`info`): `boolean`

True for a structured form's inner object that `fromLegalContext` would decode except that its one link, in either
spelling, is a link of another scheme (`isOtherSchemeLink`).

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `info`    | `unknown` |

#### Returns

`boolean`

***

### isHttpsLink()

> **isHttpsLink**(`s`): `s is string`

The one https-link rule. The raw string holds no whitespace, control character or backslash; it parses as an
absolute URL; its scheme is `https`, compared case-insensitively (RFC 3986 §3.1); its authority has a host, a DNS
name or an IP literal, and no userinfo.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `s`       | `unknown` |

#### Returns

`s is string`

***

### isOtherSchemeLink()

> **isOtherSchemeLink**(`s`): `s is string`

True for a string of at most 2048 characters that parses as an absolute URL whose scheme is not `https`: the one
failing link refused as `link-not-https`. Every other failing link is `legal-context-malformed`.

#### Parameters

| Parameter | Type      |
| --------- | --------- |
| `s`       | `unknown` |

#### Returns

`s is string`

***

### jsonWithinDepth()

> **jsonWithinDepth**(`text`): `boolean`

True when no array or object in JSON text is nested more than `MAX_JSON_DEPTH` deep. Brackets inside strings are
skipped; nothing else about the text is checked.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `text`    | `string` |

#### Returns

`boolean`

***

### newAtrId()

> **newAtrId**(): `string`

A random RFC 9562 version 4 UUID, lowercase.

#### Returns

`string`

***

### pairingOf()

> **pairingOf**(`option`): [`PairingOn`](#pairingon)\<`"x402"`> | `undefined`

The x402 pairing that serves an option: a Lightning option's by `lnbtcPairingOf`, which names `x402/exact/lnbtc` for
an option whose invoice is not yet written; else the first x402 pairing in `BINDINGS` whose `read` offers it, on a
document holding that option alone. Undefined when none does.

#### Parameters

| Parameter | Type                                                             |
| --------- | ---------------------------------------------------------------- |
| `option`  | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |

#### Returns

[`PairingOn`](#pairingon)\<`"x402"`> | `undefined`

***

### pairingsOfPlaced()

> **pairingsOfPlaced**(`c`): readonly [`MppPairing`](https://lcp.integraledger.com/reference/api/mpp#mpppairing)\[]

The pairings a placed challenge offers: `pairingsOf` over the challenge with its `opaque` removed, so the LCP members
`place` wrote are not read as an occupied carrier. None when the challenge does not read.

#### Parameters

| Parameter | Type                                              |
| --------- | ------------------------------------------------- |
| `c`       | [`MppChallenge`](https://lcp.integraledger.com/reference/api/mpp#mppchallenge) |

#### Returns

readonly [`MppPairing`](https://lcp.integraledger.com/reference/api/mpp#mpppairing)\[]

***

### parseJson()

> **parseJson**(`text`): `unknown`

The value of JSON text nested at most `MAX_JSON_DEPTH` deep; undefined for text that is deeper or is not JSON.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `text`    | `string` |

#### Returns

`unknown`

***

### toLcpString()

> **toLcpString**(`h`): `string`

LCP §8.1 string form: `lcp:sha256:0x…`. Throws TypeError when `h` is not a 32-byte hash.

#### Parameters

| Parameter | Type                |
| --------- | ------------------- |
| `h`       | `` `0x${string}` `` |

#### Returns

`string`

***

### toLegalContext()

> **toLegalContext**(`h`, `url`, `spelling?`): `object`

LCP §8.1 structured form, with the link beside the digest. `spelling` "snake" writes `legal_context_url`.
Throws TypeError when `h` is not a 32-byte hash or `url` is not an `https://` URL.

#### Parameters

| Parameter  | Type                   | Default value |
| ---------- | ---------------------- | ------------- |
| `h`        | `` `0x${string}` ``    | `undefined`   |
| `url`      | `string`               | `undefined`   |
| `spelling` | `"camel"` \| `"snake"` | `"camel"`     |

#### Returns

`object`

| Name                              | Type                |
| --------------------------------- | ------------------- |
| `legalContext`                    | `object`            |
| `legalContext.legal_context_url?` | `string`            |
| `legalContext.legalContextUrl?`   | `string`            |
| `legalContext.type`               | `"sha256"`          |
| `legalContext.value`              | `` `0x${string}` `` |

***

### toRawBytes()

> **toRawBytes**(`h`): `Uint8Array`

The raw 32 bytes of a hash. Throws TypeError when `h` is not a 32-byte hash.

#### Parameters

| Parameter | Type                |
| --------- | ------------------- |
| `h`       | `` `0x${string}` `` |

#### Returns

`Uint8Array`

## References

### LcpPattern

Re-exports [LcpPattern](https://lcp.integraledger.com/reference/api/x402#lcppattern)
