# @integraledger/lcp/cardano

> The exports of @integraledger/lcp/cardano.

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

## Interfaces

### CardanoOnChain

#### Properties

| Property       | Type                             | Description                                  |
| -------------- | -------------------------------- | -------------------------------------------- |
|  `blockHeight` | `bigint`                         | -                                            |
|  `cbor?`       | `Uint8Array`\<`ArrayBufferLike`> | The transaction as included, when asked for. |
|  `slot`        | `bigint`                         | -                                            |
|  `valid`       | `boolean`                        | db-sync's `tx.valid_contract`.               |

***

### CardanoPayload

The payload x402's Cardano scheme defines.

#### Properties

| Property       | Type     |
| -------------- | -------- |
|  `nonce`       | `string` |
|  `transaction` | `string` |

***

### CardanoPaymentPayload

#### Properties

| Property       | Type                                                             |
| -------------- | ---------------------------------------------------------------- |
|  `accepted`    | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |
|  `extensions?` | `object`                                                         |
|  `payload`     | [`CardanoPayload`](#cardanopayload)                              |
|  `resource?`   | `object`                                                         |
| `resource.url` | `string`                                                         |
|  `x402Version` | `2`                                                              |

***

### CardanoReader

Bounded, read-only calls against one network's indexer. Every failure rejects with `ReaderError`.

#### Properties

| Property   | Modifier   | Type                                |
| ---------- | ---------- | ----------------------------------- |
|  `network` | `readonly` | [`CardanoNetwork`](#cardanonetwork) |

#### Methods

##### tip()

> **tip**(): `Promise`\<\{ `blockHeight`: `bigint`; `slot`: `bigint`; }>

###### Returns

`Promise`\<\{ `blockHeight`: `bigint`; `slot`: `bigint`; }>

##### transaction()

> **transaction**(`txId`, `withCbor`): `Promise`\<[`CardanoOnChain`](#cardanoonchain) | `null`>

###### Parameters

| Parameter  | Type                |
| ---------- | ------------------- |
| `txId`     | `` `0x${string}` `` |
| `withCbor` | `boolean`           |

###### Returns

`Promise`\<[`CardanoOnChain`](#cardanoonchain) | `null`>

***

### CardanoRef

#### Properties

| Property   | Type                                | Description                                                     |
| ---------- | ----------------------------------- | --------------------------------------------------------------- |
|  `network` | [`CardanoNetwork`](#cardanonetwork) | -                                                               |
|  `ttlSlot` | `string`                            | The last slot the transaction can land in, as a decimal string. |
|  `txId`    | `` `0x${string}` ``                 | -                                                               |

***

### CardanoTx

#### Properties

| Property   | Type                                                       |
| ---------- | ---------------------------------------------------------- |
|  `h`       | `` `0x${string}` `` \| [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) |
|  `ttlSlot` | `bigint` \| `null`                                         |
|  `txId`    | `` `0x${string}` ``                                        |

***

### CardanoUnsigned

#### Properties

| Property                | Type                                                             |
| ----------------------- | ---------------------------------------------------------------- |
|  `request`              | `object`                                                         |
| `request.accepted`      | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |
| `request.auxiliaryData` | `Uint8Array`                                                     |
| `request.kind`          | `"cardano-transaction"`                                          |

#### Methods

##### complete()

> **complete**(`signed`): `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`CardanoPaymentPayload`](#cardanopaymentpayload)>

###### Parameters

| Parameter | Type                                |
| --------- | ----------------------------------- |
| `signed`  | [`CardanoPayload`](#cardanopayload) |

###### Returns

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

## Type Aliases

### CardanoNetwork

> **CardanoNetwork** = `"cardano:mainnet"` | `"cardano:preprod"` | `"cardano:preview"`

***

### CardanoStatus

> **CardanoStatus** = \{ `blockHeight`: `bigint`; `confirmations`: `bigint`; `state`: `"settled"`; } | \{ `state`: `"pending"`; `why`: `"not-found"` | `"unreadable"`; } | \{ `state`: `"failed"`; `why`: `"phase-2-invalid"` | `"expired"`; }

## Variables

### exactCardano

> `const` **exactCardano**: `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`: (`choice`, `h`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`CardanoUnsigned`](#cardanounsigned)>; `carrier`: `null`; `claims`: `boolean`; `id`: `"x402/exact/cardano"`; `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); `recover`: (`ref`, `reader`) => `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>; `reference`: (`presented`) => `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`CardanoRef`](#cardanoref)>; `status`: (`ref`, `reader`) => `Promise`\<[`CardanoStatus`](#cardanostatus)>; `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); }>

***

### LCP\_MARKER

> `const` **LCP\_MARKER**: `"lcp:sha256:0x"` = `"lcp:sha256:0x"`

CIP-20 line 1 of the carrier; line 2 is the hash's 64 lowercase hex digits.

## Functions

### auxiliaryData()

> **auxiliaryData**(`h`): `Uint8Array`\<`ArrayBufferLike`> | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)

The exact auxiliary data the payer attaches: `#6.259({0: {674: {"msg": [LCP_MARKER, <64 hex>]}}})`. A value that is
not a 32-byte hash is `x402/payload-malformed`.

#### Parameters

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

#### Returns

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

***

### cardanoOptionCheck()

> **cardanoOptionCheck**(`option`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | `undefined`

The pairing's filter: undefined for an option this pairing can pay, or the refusal naming why not.

#### Parameters

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

#### Returns

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

***

### cardanoPairingOf()

> **cardanoPairingOf**(`option`): `"x402/exact/cardano"` | `undefined`

This pairing's id for an option it can pay, or undefined.

#### Parameters

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

#### Returns

`"x402/exact/cardano"` | `undefined`

***

### cardanoRecover()

> **cardanoRecover**(`ref`, `reader`): `Promise`\<`` `0x${string}` `` | [`Refusal`](https://lcp.integraledger.com/reference/api#refusal)>

Reads the hash back from the included transaction alone, by its id. One call.

#### Parameters

| Parameter     | Type                                                                              |
| ------------- | --------------------------------------------------------------------------------- |
| `ref`         | \{ `network`: [`CardanoNetwork`](#cardanonetwork); `txId`: `` `0x${string}` ``; } |
| `ref.network` | [`CardanoNetwork`](#cardanonetwork)                                               |
| `ref.txId`    | `` `0x${string}` ``                                                               |
| `reader`      | [`CardanoReader`](#cardanoreader)                                                 |

#### Returns

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

***

### cardanoStatus()

> **cardanoStatus**(`ref`, `reader`): `Promise`\<[`CardanoStatus`](#cardanostatus)>

Reads the recorded id. A failed read, or a reader for another network, is pending. An absent transaction is
expired once the tip's slot is past its TTL; a present one fails only when the ledger marks it invalid. Two calls.

#### Parameters

| Parameter | Type                              |
| --------- | --------------------------------- |
| `ref`     | [`CardanoRef`](#cardanoref)       |
| `reader`  | [`CardanoReader`](#cardanoreader) |

#### Returns

`Promise`\<[`CardanoStatus`](#cardanostatus)>

***

### decodeCardanoTx()

> **decodeCardanoTx**(`base64`): `Promise`\<[`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`CardanoTx`](#cardanotx)>

Decodes a base64 transaction `[body, witness set, bool, auxiliary data / nil]`, keeping each item's bytes as
received. The id is the Blake2b-256 of the body's bytes; the auxiliary data must hash to the body's key 7.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `base64`  | `string` |

#### Returns

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