# Hosted operator API (BLS based)

## Overview

The AltLayer-hosted operator comes with APIs. With the APIs, AVS only needs to design and implement its business logic. The API will handle the signature signing and submission to the aggregator.&#x20;

<figure><img src="https://3112893033-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8DRtEPgHrIg4b65B1smQ%2Fuploads%2F4AC1U5fH4zjeKGAqR0TV%2Fimage.png?alt=media&#x26;token=187e6fbe-04a6-40cf-a901-ffe702020bf4" alt=""><figcaption></figcaption></figure>

To interact with the API, there are two options

1. Interact with the managed operator&#x20;
2. Interact with the managed operator proxy

## The rationale of operator proxy

While direct interaction with the operator provides the most significant degree of flexibility, it is often necessary to construct the parameters, which can be low-level.&#x20;

Let's use the following example to illustrate it

```solidity
    function confirmMessage(
        Params1 p1,
        ...
        ParamsN pN,
        NonSignerStakesAndSignature memory nonSignerStakesAndSignature
    ) external whenNotPaused onlyConfirmer {
    ...
    }

```

The operator API has a parameter called `params_raw`. This is the abi-encoded bytes of `p1....pN`. It can be complex to construct the encoded bytes.

The managed operator proxy abstracted away the complexity. It supports any AVS using the [task manager convention](https://github.com/Layr-Labs/incredible-squaring-avs/blob/master/contracts/src/IncredibleSquaringTaskManager.sol). When using the operator proxy API, there is no need to compute `param_raw`. The AVS builder can focus on providing the actual payload.  As such, the API is much simpler and easier to use.&#x20;

## Getting the operator and/or operator proxy endpoint and credentials

Go to the operator section and click on the menu button for "Hosted Operator Service".

<figure><img src="https://3112893033-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8DRtEPgHrIg4b65B1smQ%2Fuploads%2FEDCpxJyN4AGDwS1JQPmj%2Fimage.png?alt=media&#x26;token=6b1b8ed2-a8f8-43cd-b659-f0f5433a2182" alt=""><figcaption></figcaption></figure>

Click on the "Credentials" link to display the endpoints, username and password. The username and password are required as the operator and operator proxy API have basic access authentication enabled.&#x20;

<figure><img src="https://3112893033-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8DRtEPgHrIg4b65B1smQ%2Fuploads%2FLYMEBx22DU8IGFzZF7Px%2Fimage.png?alt=media&#x26;token=df1101bb-d7d9-4379-ba46-979eee6e3707" alt=""><figcaption></figcaption></figure>

## Operator API

### Request header

* Content-Type: application/json
* Authorization: Basic \<base64 encoded of admin`:password`>

### Request body

```json
{
  "id": "1",
  "jsonrpc": "2.0",
  "method": "operator_createSigTask",
  "params": [
    {
      "avs_name": "op",
      "method": "tt",
      "params_raw": "0x00",
      "reference_block_number": 1000,
      "quorum_numbers": [
        0
      ],
      "quorum_threshold_percentages": [
        66
      ],
      "sig_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
    }
  ]
}
```

* `method`: operator\_createSigTask. This is the API method and should not be changed
* `params.avs_name`: name of the AVS
* `params.method`: the smart contract method that handled the contract call from the aggregator e.g `respondToTask`
* `params.param_raw`: the abi-encoded call data. It can be all calldata or a subset of the calldata
* `params.reference_block_number`: reference block number for quorum\_numbers and quorum\_threshold\_percentages&#x20;
* `params.quorum_numbers` : quorum number in which operators have signed for
* `params.quorum_threshold_percentages` : quorum threshold for the particular quorum number
* `params.sig_hash` : the signed hash of `param_raw`

### Sample curl request&#x20;

{% hint style="info" %}
Remember to update&#x20;

1. basic auth credentials
2. avs name
3. method
4. params
5. operator endpoint
   {% endhint %}

```bash
curl --noproxy '*' \
  -H "Content-Type: application/json" \
  --header 'Authorization: Basic <base64 encoded admin:password>' 
  -d '{
    "id": "1",
    "jsonrpc": "2.0",
    "method": "operator_createSigTask",
    "params": [
      {
        "avs_name": "op",
        "method": "tt",
        "params_raw": "0x00",
        "reference_block_number": 1000,
        "quorum_numbers": [0],
        "quorum_threshold_percentages": [66],
        "sig_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
      }
    ]
  }' \
  https://your-avs-operator.alt.technology

```

## Operator Proxy API

### Request header

* Content-Type: application/json
* Authorization: Basic \<base64 encoded of admin`:password`>

### Request body

```bash
{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "operator_createSigTaskResponse",
    "params": [
        {
            "method": "respondToRequest",
            "task_created_block": 3003011,
            "message": "0x00",
            "task_index": 100,
            "resp_message": "0x0000"
        }
    ]
}
```

* `method`: operator\_createSigTaskResponse. This is the API method and should not be changed
* `params`.method: the smart contract method that handled the contract call from the aggregator, e.g `respondToTask`
* `params.task_created_block`: the block number in which the task is created
* `params.message`: the task message found inside the Task struct
* `params.task_index`: the task index in the smart contract&#x20;
* `params.resp_message`: the response message for the task

### Sample curl request&#x20;

{% hint style="info" %}
Remember to update&#x20;

1. basic auth credentials
2. params
3. operator proxy endpoint
   {% endhint %}

```bash
curl --noproxy '*' -H "Content-Type: application/json" --header 'Authorization: Basic <base64 encoded admin:password>' \
-d '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "operator_createSigTaskResponse",
    "params": [
        {
            "method": "respondToRequest",
            "task_created_block": 3003011,
            "message": "0x00",
            "task_index": 100,
            "resp_message": "0x0000"
        }
    ]
}' \
https://your-avs.alt.technology
```

### Sample success response

```json
{
    "jsonrpc": "2.0",
    "id": 2,
    "result": {
        "task_index": 1,
        "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "sig_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
    }
}
```
