> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inco.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Library Reference

> All functions exposed by the Inco library

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @inco/lightning
  ```

  ```bash yarn theme={null}
  yarn add @inco/lightning
  ```

  ```bash bun theme={null}
  bun add @inco/lightning
  ```
</CodeGroup>

## Types

* `ebool`: Encrypted `bool`
* `euint256`: Encrypted `uint256`
* `eaddress`: Encrypted `address`

## Math operations

All arithmetic operations return an `euint256`.
All binary operations may use either an `euint256` or a regular `uint256` as the first or second argument, or two `euint256`s.

Bitwise operations work on both `euint256` and `ebool` types, and may use either encrypted or plain values as arguments.

| Name           | Function | Type   | Returns           |
| -------------- | -------- | ------ | ----------------- |
| Addition       | `e.add`  | Binary | euint256          |
| Subtraction    | `e.sub`  | Binary | euint256          |
| Multiplication | `e.mul`  | Binary | euint256          |
| Division       | `e.div`  | Binary | euint256          |
| Remainder      | `e.rem`  | Binary | euint256          |
| BitAnd         | `e.and`  | Binary | euint256 or ebool |
| BitOr          | `e.or`   | Binary | euint256 or ebool |
| BitXor         | `e.xor`  | Binary | euint256 or ebool |
| Shift Right    | `e.shr`  | Binary | euint256          |
| Shift Left     | `e.shl`  | Binary | euint256          |
| Rotate Right   | `e.rotr` | Binary | euint256          |
| Rotate Left    | `e.rotl` | Binary | euint256          |

## Comparison operations

| Name                  | Function | Type   | Returns  | Notes                                                            |
| --------------------- | -------- | ------ | -------- | ---------------------------------------------------------------- |
| Equal                 | `e.eq`   | Binary | ebool    | Works with euint256, eaddress, and combinations with plain types |
| Not equal             | `e.ne`   | Binary | ebool    | Works with euint256, eaddress, and combinations with plain types |
| Greater than or equal | `e.ge`   | Binary | ebool    | euint256 only                                                    |
| Greater than          | `e.gt`   | Binary | ebool    | euint256 only                                                    |
| Less than or equal    | `e.le`   | Binary | ebool    | euint256 only                                                    |
| Less than             | `e.lt`   | Binary | ebool    | euint256 only                                                    |
| Min                   | `e.min`  | Binary | euint256 | euint256 only                                                    |
| Max                   | `e.max`  | Binary | euint256 | euint256 only                                                    |
| Not                   | `e.not`  | Unary  | ebool    | ebool only                                                       |

## Multiplexer

* `e.select(ebool, euint256, euint256) returns(euint256)`: Select between two `euint256`s based on an `ebool` condition
* `e.select(ebool, ebool, ebool) returns(ebool)`: Select between two `ebool`s based on an `ebool` condition
* `e.select(ebool, eaddress, eaddress) returns(eaddress)`: Select between two `eaddress`es based on an `ebool` condition

## Random Functions

All random functions require payment of the Inco fee.

* `e.rand() returns(euint256)`: Generate a random `euint256` value
* `e.randBounded(uint256) returns(euint256)`: Generate a random `euint256` value bounded by a `uint256` upper limit
* `e.randBounded(euint256) returns(euint256)`: Generate a random `euint256` value bounded by an `euint256` upper limit

## Inputs

* `e.asEuint256(uint256) returns(euint256)`: Convert a `uint256` to an `euint256` (trivial encrypt)
* `e.asEbool(bool) returns(ebool)`: Convert a `bool` to an `ebool` (trivial encrypt)
* `e.asEaddress(address) returns(eaddress)`: Convert an `address` to an `eaddress` (trivial encrypt)
* `e.newEuint256(bytes memory input) returns(euint256)`: Create a new `euint256` from a ciphertext
* `e.newEbool(bytes memory input) returns(ebool)`: Create a new `ebool` from a ciphertext
* `e.newEaddress(bytes memory input) returns(eaddress)`: Create a new `eaddress` from a ciphertext

## Type Casting

* `e.asEbool(euint256) returns(ebool)`: Cast an `euint256` to an `ebool`
* `e.asEuint256(ebool) returns(euint256)`: Cast an `ebool` to an `euint256`

## Access control

* `e.allow(euint256, address)`: Allow a user to access an `euint256` value permanently
* `e.allow(ebool, address)`: Allow a user to access an `ebool` value permanently
* `e.allow(eaddress, address)`: Allow a user to access an `eaddress` value permanently
* `e.allowThis(euint256)`: Allow the current contract to access an `euint256` value permanently
* `e.allowThis(ebool)`: Allow the current contract to access an `ebool` value permanently
* `e.allowThis(eaddress)`: Allow the current contract to access an `eaddress` value permanently
* `e.reveal(euint256)`: Make an `euint256` value publicly accessible
* `e.reveal(ebool)`: Make an `ebool` value publicly accessible
* `e.reveal(eaddress)`: Make an `eaddress` value publicly accessible
* `e.isAllowed(address, euint256) returns(bool)`: Check if a user is allowed to access an `euint256` value
