# @integraledger/lcp/casper

> The exports of @integraledger/lcp/casper.

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

## Interfaces

### CasperCall

One executed contract call, as the reader reports it.

#### Properties

| Property       | Type                             |
| -------------- | -------------------------------- |
|  `args`        | `object`                         |
| `args.from?`   | `string`                         |
| `args.nonce?`  | `Uint8Array`\<`ArrayBufferLike`> |
| `args.to?`     | `string`                         |
| `args.value?`  | `bigint`                         |
|  `blockHeight` | `bigint` \| `null`               |
|  `entryPoint`  | `string` \| `null`               |
|  `error`       | `string` \| `null`               |
|  `executed`    | `boolean`                        |
|  `packageHash` | `string` \| `null`               |

***

### CasperChoice

#### Properties

| Property    | Type                                                             |
| ----------- | ---------------------------------------------------------------- |
|  `accepted` | [`PaymentRequirements`](https://lcp.integraledger.com/reference/api/x402#paymentrequirements) |
|  `from`     | `string`                                                         |
|  `now`      | `number`                                                         |
|  `required` | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired)         |

***

### CasperReader

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

#### Properties

| Property   | Modifier   | Type                     |
| ---------- | ---------- | ------------------------ |
|  `network` | `readonly` | `` `casper:${string}` `` |

#### Methods

##### transaction()

> **transaction**(`hash`): `Promise`\<[`CasperCall`](#caspercall) | `null`>

`info_get_transaction`, as a `Version1` transaction and then as a `Deploy`; null when the node knows neither.

###### Parameters

| Parameter | Type     |
| --------- | -------- |
| `hash`    | `string` |

###### Returns

`Promise`\<[`CasperCall`](#caspercall) | `null`>

***

### CasperRef

The read keys recorded at claim.

#### Properties

| Property        | Type                     |
| --------------- | ------------------------ |
|  `asset`        | `string`                 |
|  `idDigest`     | `` `0x${string}` ``      |
|  `network`      | `` `casper:${string}` `` |
|  `settleBy`     | `number`                 |
|  `transaction?` | `string`                 |

***

### CasperUnsigned

#### Properties

| Property            | Type                                    |
| ------------------- | --------------------------------------- |
|  `request`          | `object`                                |
| `request.kind`      | `"casper-eip712"`                       |
| `request.typedData` | [`Cep3009TypedData`](#cep3009typeddata) |

#### Methods

##### complete()

> **complete**(`publicKey`, `signature`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`CasperPaymentPayload`](#casperpaymentpayload)

Both arguments are hex with a one-byte algorithm tag: `01` ed25519, `02` secp256k1.

###### Parameters

| Parameter   | Type     |
| ----------- | -------- |
| `publicKey` | `string` |
| `signature` | `string` |

###### Returns

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

***

### Cep3009TypedData

#### Properties

| Property                          | Type                                   | Description               |
| --------------------------------- | -------------------------------------- | ------------------------- |
|  `domain`                         | `object`                               | -                         |
| `domain.chain_name`               | `` `casper:${string}` ``               | -                         |
| `domain.contract_package_hash`    | `string`                               | -                         |
| `domain.name`                     | `string`                               | -                         |
| `domain.version`                  | `string`                               | -                         |
|  `message`                        | `object`                               | -                         |
| `message.from`                    | `string`                               | -                         |
| `message.nonce`                   | `string`                               | 64 hex digits, no prefix. |
| `message.to`                      | `string`                               | -                         |
| `message.validAfter`              | `bigint`                               | -                         |
| `message.validBefore`             | `bigint`                               | -                         |
| `message.value`                   | `bigint`                               | -                         |
|  `primaryType`                    | `"TransferWithAuthorization"`          | -                         |
|  `types`                          | `object`                               | -                         |
| `types.EIP712Domain`              | [`Field`](https://lcp.integraledger.com/reference/api/evm#field)\[] | -                         |
| `types.TransferWithAuthorization` | [`Field`](https://lcp.integraledger.com/reference/api/evm#field)\[] | -                         |

## Type Aliases

### CasperAddress

> **CasperAddress** = `string`

66 hex digits, no prefix: tag `00` (account hash) or `01` (package hash), then 32 bytes.

***

### CasperAuthorization

> **CasperAuthorization** = `object`

#### Properties

| Property       | Type     |
| -------------- | -------- |
|  `from`        | `string` |
|  `nonce`       | `string` |
|  `to`          | `string` |
|  `validAfter`  | `string` |
|  `validBefore` | `string` |
|  `value`       | `string` |

***

### CasperNetwork

> **CasperNetwork** = `` `casper:${string}` ``

CAIP-2: `casper:` and the chainspec name.

***

### CasperPaymentPayload

> **CasperPaymentPayload** = `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.authorization` | [`CasperAuthorization`](#casperauthorization)                             |
| `payload.publicKey`     | `string`                                                                  |
| `payload.signature`     | `string`                                                                  |
|  `resource?`            | [`PaymentRequired`](https://lcp.integraledger.com/reference/api/x402#paymentrequired)\[`"resource"`]   |
|  `x402Version`          | `2`                                                                       |

***

### CasperStatus

> **CasperStatus** = \{ `blockHeight`: `bigint`; `finality`: `"finalized"`; `state`: `"settled"`; } | \{ `state`: `"pending"`; `why`: `"not-found"` | `"not-executed"` | `"unreadable"`; } | \{ `state`: `"failed"`; `why`: `"reverted"` | `"not-this-instrument"`; }

***

### PackageHash

> **PackageHash** = `string`

64 hex digits, no prefix.

## Variables

### CASPER\_DOMAIN\_TYPEHASH

> `const` **CASPER\_DOMAIN\_TYPEHASH**: `"0xe20dd13933eeb9d6099b53d5ffd59cfd50fe774983038681a378371664fad4fb"`

keccak256("EIP712Domain(string name,string version,string chain\_name,bytes32 contract\_package\_hash)")

***

### exactCasper

> `const` **exactCasper**: `Readonly`\<\{ `advertise`: [`X402Advertise`](https://lcp.integraledger.com/reference/api/x402#x402advertise); `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) | [`CasperUnsigned`](#casperunsigned)>; `claims`: `boolean`; `id`: `"x402/exact/casper"`; `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) | [`CasperRef`](#casperref)>; `status`: (`ref`, `reader`) => `Promise`\<[`CasperStatus`](#casperstatus)>; `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); }>

## Functions

### casperIdDigest()

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

SHA-256 over the 33 + 33 bytes of the two addresses and the value as a 32-byte big-endian integer.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `from`    | `string` |
| `to`      | `string` |
| `value`   | `bigint` |

#### Returns

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

***

### casperOption()

> **casperOption**(`o`): `o is PaymentRequirements`

The pairing's filter: an `exact` option on a `casper:` network that `build` can turn into typed data.

#### Parameters

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

#### Returns

`o is PaymentRequirements`

***

### casperRecover()

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

The hash from a settlement transaction alone: the `nonce` argument of the executed authorization call on `asset`.

#### Parameters

| Parameter         | Type                                                                                  |
| ----------------- | ------------------------------------------------------------------------------------- |
| `ref`             | \{ `asset`: `string`; `network`: `` `casper:${string}` ``; `transaction`: `string`; } |
| `ref.asset`       | `string`                                                                              |
| `ref.network`     | `` `casper:${string}` ``                                                              |
| `ref.transaction` | `string`                                                                              |
| `reader`          | [`CasperReader`](#casperreader)                                                       |

#### Returns

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

***

### casperStatus()

> **casperStatus**(`ref`, `reader`): `Promise`\<[`CasperStatus`](#casperstatus)>

Reads the named transaction. Settled, at the height of its block, when it executed without error as a call to
`ref.asset`'s `transfer_with_authorization` or `receive_with_authorization` whose `nonce` argument is `h` and whose
`from`, `to` and `value` hash to `ref.idDigest`. A failed read, or a reader for another network, is pending.

#### Parameters

| Parameter | Type                                 |
| --------- | ------------------------------------ |
| `ref`     | [`CasperRef`](#casperref) & `object` |
| `reader`  | [`CasperReader`](#casperreader)      |

#### Returns

`Promise`\<[`CasperStatus`](#casperstatus)>

***

### cep3009TypedData()

> **cep3009TypedData**(`a`): [`Refusal`](https://lcp.integraledger.com/reference/api#refusal) | [`Cep3009TypedData`](#cep3009typeddata)

The CEP-3009 typed data for `TransferWithAuthorization`, with `validAfter` 0 and the hash as the nonce.

#### Parameters

| Parameter       | Type                                                                                                                                                                                                            |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `a`             | \{ `asset`: `string`; `from`: `string`; `name`: `string`; `network`: `` `casper:${string}` ``; `nonce`: `` `0x${string}` ``; `to`: `string`; `validBefore`: `bigint`; `value`: `string`; `version`: `string`; } |
| `a.asset`       | `string`                                                                                                                                                                                                        |
| `a.from`        | `string`                                                                                                                                                                                                        |
| `a.name`        | `string`                                                                                                                                                                                                        |
| `a.network`     | `` `casper:${string}` ``                                                                                                                                                                                        |
| `a.nonce`       | `` `0x${string}` ``                                                                                                                                                                                             |
| `a.to`          | `string`                                                                                                                                                                                                        |
| `a.validBefore` | `bigint`                                                                                                                                                                                                        |
| `a.value`       | `string`                                                                                                                                                                                                        |
| `a.version`     | `string`                                                                                                                                                                                                        |

#### Returns

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