# Using BLS

### 1. Download version 3.0.X validator client

Check the current Node.js version to ensure that the node version is equal to or greater than v16.0.0.

```
node -v
```

If the Node.js version does not meet the requirement, it is recommended to use nvm (Node Version Manager) to switch to a different Node.js version.

```
nvm use 16
```

Once you have verified that the current Node.js version meets the requirements, proceed to execute the following command to install the latest version of the client:

```
npm install @rei-network/cli@3 -g
```

Eg:

```
node -v
v14.19.3

nvm use 16

node -v
v16.18.0

npm install @rei-network/cli@3 -g
```

After the installation is completed, execute the following command to check the version number and confirm if the installation was successful:

```
rei --version
```

Eg:

```
[root@rei-testnet-validators rei-cli] rei --version
3.0.1
```

### 2. Generate bls keystore

Use the following command and enter the password according to the prompt to complete the generation of bls keystore.

```
rei bls new --datadir <path>
```

> **note:**&#x20;
>
> * This command will create a new bls directory under the specified path, and generate a keystore file in the bls directory.&#x20;
> * The specified path is recommended to be the original validator datadir (or migrate the generated bls directory to the original validator datadir), otherwise it will affect the unlocking of the bls private key after rei-dao hardfork.&#x20;
> * Please keep the password safe, otherwise bls keystore will not be able to unlock the bls private key.

Eg:

```
[root@rei-testnet-validators rei-cli] rei bls new --datadir ~/node
Your new bls secrect keyfile is locked with a password. Please give a password. Do not forget this password.
? Password: [hidden]
? Repeat password: [hidden]

Your new key was generated

Public key: 0xa91f44ef2da6a839fbad9654615f017f98d2c5b189cd87e062fbec7c9188a4f951425c5e4e4e1547e91afdc53c2399df
Path of the secret key file: /root/node/bls/UTC--2023-06-27T19-06-09.134Z--0xa91f44ef2da6a839fbad9654615f017f98d2c5b189cd87e062fbec7c9188a4f951425c5e4e4e1547e91afdc53c2399df.json

If you have not registered the BLS public key, please go to https://dao.rei.network to register.
- You can share your publickey with anyone. Others need it to interact with you.
- You must NEVER share the secret key with anyone! The key controls access to your block signature!
- You must BACKUP your key file! Without the key, it's impossible to access block signature!
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!
```

From the above information, we can know that the path of the bls keystore file generated in this example is:

```
/root/node/bls/UTC--2023-06-27T19-06-09.134Z--0xa91f44ef2da6a839fbad9654615f017f98d2c5b189cd87e062fbec7c9188a4f951425c5e4e4e1547e91afdc53c2399df.json
```

### 3. Obtain bls publicKey

First, let's enter the directory where the bls keystore file is located

```
cd ~/datadir/bls
```

Check the file list to get the name of the bls keystore file we generated

```
ls
```

Eg:

```
[root@rei-testnet-validators rei-cli] cd ~/node/bls
[root@rei-testnet-validators bls] ls
UTC--2023-06-27T19-06-09.134Z--0xa91f44ef2da6a839fbad9654615f017f98d2c5b189cd87e062fbec7c9188a4f951425c5e4e4e1547e91afdc53c2399df.json
```

Check out the bls keystore file

```
cat UTC--2023-06-26T19-43-41.889Z--0x8dbfbd24c6e56fbe57cdb5f131e8b255ac7120be6a731b915050530d58fd0d4aba99e4c8cf9541c3b21645bf59272920.json
```

The displayed data is as follows, where the publicKey is the bls public key we need

```
{
  "encryptedSecretKey": "315160b845d2daedc0d857a9cc289a1bffe448b17366cca6af3fac480204522a",
  "iv": "2cf770d6eff32c40c6d805361038f391",
  "publicKey": "0x8dbfbd24c6e56fbe57cdb5f131e8b255ac7120be6a731b915050530d58fd0d4aba99e4c8cf9541c3b21645bf59272920"
}
```

### 4. Register the bls public key to the chain and check whether the registration is successful

Regarding the bls registration contract, its abi is as follows:

```
interface IValidatorBLS {

    function setBLSPublicKey(bytes calldata key) external;

    function getBLSPublicKey(address) external view returns (bytes memory);

    function isRegistered(address) external view returns (bool);

    function isBLSPublicKeyExist(bytes calldata) external view returns (bool);
}
```

### Functions

**setBLSPublicKey :** register bls public key

#### Declaration

```
function setBLSPublicKey(bytes memory key) external
```

#### Args

| Arg |  Type |   Description  |
| :-: | :---: | :------------: |
| key | bytes | bls public key |

**getBLSPublicKey :** Query bls public key

#### Declaration

```
function getBLSPublicKey(address) external view returns (bytes memory)
```

#### Args

<table data-full-width="false"><thead><tr><th align="center">Arg</th><th align="center">Type</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center">address</td><td align="center">address</td><td align="center">validator address</td></tr></tbody></table>

**isRegistered :** Query whether the address register bls public key

#### Declaration

```
function isRegistered(address) external view returns (bool)
```

|   Arg   |   Type  |    Description    |
| :-----: | :-----: | :---------------: |
| address | address | validator address |

**isBLSPublicKeyExist :** Query whether bls public key is registered

#### Declaration

```
function isBLSPublicKeyExist(bytes memory) external view returns (bool)
```

| Arg |  Type |   Description  |
| :-: | :---: | :------------: |
| key | bytes | bls public key |

For developers, you can call the setBLSPublicKey method of the validatorBLS contract to register the bls public key to the chain

> **note:**&#x20;
>
> * Before rei-dao fork, the contract address is `0x5b84072EE3e72a58A906FA15182beEdaB5298076` , after rei-dao fork, the contract address is `0x0000000000000000000000000000000001009`&#x20;
> * After the registration is complete, you can call the isRegistered method to check whether the registration is successful or call the getBLSPublicKey method to check whether the bls public key is consistent with the registered one

For general users, you can register bls public key to the chain through [REI DAO](https://dao.rei.network/#/myAccount/portfolio) \
**The steps are as follows:**

{% tabs %}
{% tab title="UI" %}
**Step1**: Navigate to <https://dao.rei.network/#/myAccount/portfolio>

**Step2**: Click on `Register BLS public key` button, enter the `BLS public key` to Register

<figure><img src="https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FY5kyDQHzG9jtZ4yfjypJ%2F%E6%88%AA%E5%B1%8F2023-06-29%20%E4%B8%8B%E5%8D%884.20.15.png?alt=media&#x26;token=22decb9b-a648-4e6e-8a81-5d623e76f8b3" alt=""><figcaption><p>Register BLS public key</p></figcaption></figure>

*Please note that it may take 1 to 2 minutes for the registration record to be updated here after registering with the BLS public key.*

<figure><img src="https://1587922022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F66Nmajb3NGWZfp8dG26G%2Fuploads%2FIdjd8Yj33j35ThXFIVR1%2F%E6%88%AA%E5%B1%8F2023-06-29%20%E4%B8%8B%E5%8D%884.27.06.png?alt=media&#x26;token=a20403e7-03ea-4ae6-9209-0d9f9aa401f9" alt=""><figcaption><p>Register BLS public key</p></figcaption></figure>
{% endtab %}
{% endtabs %}
