# PublicResolver

### Overview

`PublicResolver` is a contract that provides additional functionality for managing operator approvals and registration controllers for Payment ID tokens. The contract supports both direct and signature-based authorization.

### Key Concepts

| Concept                       | Description                                                                           |
| ----------------------------- | ------------------------------------------------------------------------------------- |
| **Operator Approvals**        | Allows owners to authorize operators to manage their Payment ID tokens.               |
| **Signature-Based Approvals** | Enables gasless approvals using EIP-712 signatures.                                   |
| **Registration Controller**   | Manages centralized registration operations and is initialized once.                  |
| **PID Registry Integration**  | Ensures authorization consistency by verifying token ownership with the PID registry. |

### Data Structures

#### Immutable Components

| Name                        | Type      | Description                                    |
| --------------------------- | --------- | ---------------------------------------------- |
| `APPROVAL_FOR_ALL_TYPEHASH` | `bytes32` | Type hash for operator approval via signature. |

#### State Variables

| Name                     | Type                                           | Description                                        |
| ------------------------ | ---------------------------------------------- | -------------------------------------------------- |
| `pidRegistry`            | `IPIDRegistry`                                 | Stores the reference to the PID registry contract. |
| `registrationController` | `address`                                      | Stores the address of the registration controller. |
| `_operatorApprovals`     | `mapping(address => mapping(address => bool))` | Mapping tracking operator approvals for owners.    |

### Functions

#### Initialization

**Constructor**

```solidity
constructor(address _pidRegistry, address _publicKeyRegistry)
```

| Input Parameter      | Type      | Description                                  |
| -------------------- | --------- | -------------------------------------------- |
| `_pidRegistry`       | `address` | Address of the PID registry contract.        |
| `_publicKeyRegistry` | `address` | Address of the public key registry contract. |

**init**

```solidity
function init(address _registrationController) external
```

| Input Parameter           | Type      | Description                             |
| ------------------------- | --------- | --------------------------------------- |
| `_registrationController` | `address` | Address of the registration controller. |

#### Operator Management

**setApprovalForAll**

```solidity
function setApprovalForAll(address operator, bool approved) external
```

| Input Parameter | Type      | Description                           |
| --------------- | --------- | ------------------------------------- |
| `operator`      | `address` | Address to be approved or revoked.    |
| `approved`      | `bool`    | `true` to approve, `false` to revoke. |

**setApprovalForAllWithSig**

```solidity
function setApprovalForAllWithSig(address owner, address operator, bool approved, bytes calldata signature) external
```

| Input Parameter | Type             | Description                                 |
| --------------- | ---------------- | ------------------------------------------- |
| `owner`         | `address`        | Address of the token owner.                 |
| `operator`      | `address`        | Address to be approved or revoked.          |
| `approved`      | `bool`           | `true` to approve, `false` to revoke.       |
| `signature`     | `bytes calldata` | EIP-712 signature authorizing the approval. |

**isApprovedForAll**

```solidity
function isApprovedForAll(address account, address operator) public view returns (bool)
```

| Input Parameter | Type      | Description                                    |
| --------------- | --------- | ---------------------------------------------- |
| `account`       | `address` | Owner account to check for operator approvals. |
| `operator`      | `address` | Address to check.                              |
| **Returns**     | `bool`    | `true` if approved, `false` otherwise.         |

#### Authorization Check

**isAuthorised**

```solidity
function isAuthorised(uint256 tokenId) internal view override returns (bool)
```

| Input Parameter | Type      | Description                              |
| --------------- | --------- | ---------------------------------------- |
| `tokenId`       | `uint256` | Token ID to verify authorization for.    |
| **Returns**     | `bool`    | `true` if authorized, `false` otherwise. |

### Events

| Event                           | Parameters                                         | Description                                          |
| ------------------------------- | -------------------------------------------------- | ---------------------------------------------------- |
| `ApprovalForAll`                | `(address owner, address operator, bool approved)` | Emitted when operator approval status is updated.    |
| `RegistrationControllerUpdated` | `(address oldController, address newController)`   | Emitted when the registration controller is updated. |

### Errors

| Error                                           | Description                                                         |
| ----------------------------------------------- | ------------------------------------------------------------------- |
| `PublicResolver__InvalidOperator`               | Thrown when an operator action is invalid.                          |
| `PublicResolver__AlreadyInitialized`            | Thrown when trying to reinitialize the registration controller.     |
| `PublicResolver__InvalidRegistrationController` | Thrown when an invalid registration controller address is provided. |
