# Keys y certificado del pool

{% hint style="info" %}
Este procedimiento solo se realiza para el nodo productor de bloques.
{% endhint %}

{% hint style="danger" %}
Es muy recomendado que toda operación que implique acceso a las *cold keys*, *payment.addr* o *stake.addr* se realicen en una maquina sin acceso a internet a fin de minimizar posibilidades de exponer info sensitiva de nuestro pool y/o fondos a terceros mal intencionados. Luego se copian los archivos firmados al BP o un relay online y desde ahí se les agrega a la blockchain.
{% endhint %}

## KES keys (Key Evolving Signature)

Son las llaves "calientes", éstas deben ser rotadas cada 62 periodos KES, equivalente a 93 días.

```
cd ~/cardano-node/block 

cardano-cli node key-gen-KES \
	--verification-key-file BP.kes.vkey \
	--signing-key-file BP.kes.skey
```

## Cold keys y `cold.counter`.

Son las llaves frías, éstas son inmutables. El `cold.counter` ira evolucionando&#x20;

```
cardano-cli node key-gen \
	--cold-verification-key-file BP.cold.vkey \
	--cold-signing-key-file BP.cold.skey \
	--operational-certificate-issue-counter-file BP.counter
```

## Certificado Operacional

Primero debemos calcular el periodo KES actual, para esto necesitamos algunos datos. Primero consultamos el tip o `slotNo`

```
cardano-cli query tip --mainnet | jq .slotNo
```

{% hint style="info" %}
Para que este valor sea el correcto el nodo debe estar completamente sincronizado con la red.
{% endhint %}

Consultamos la cantidad de slots por periodo KES

```
cat ~/cardano-node/block/shelley-genesis.json | jq .slotsPerKESPeriod
```

Con estos dos valores podemos calcular el periodo KES actual

```
expr $(cardano-cli query tip --mainnet | jq .slotNo) \
 / $(cat ~/cardano-node/block/shelley-genesis.json | jq .slotsPerKESPeriod)
```

Con este dato podemos finalmente generar nuestro certificado

```
cardano-cli node issue-op-cert \
	--kes-verification-key-file BP.kes.vkey \
	--cold-signing-key-file BP.cold.skey \
	--operational-certificate-issue-counter BP.counter \
	--kes-period 120 \
	--out-file BP.node.opcert
```

## VRF Keys

Generamos un nuevo par de llaves VRF

```
cardano-cli node key-gen-VRF \
	--verification-key-file BP.vrf.vkey \
	--signing-key-file BP.vrf.skey
```

## Restringir permisos a los keys

Para evitar que terceros puedan tener acceso a nuestros pool keys, solo permitimos el acceso de lectura a nuestro usuario. Este punto es necesario a partir del nodo 1.21.2.

```
sudo chmod -R 400 ~/cardano-node/BP.*.skey
sudo chmod -R 400 ~/cardano-node/BP.*.vkey
sudo chmod -R 400 ~/cardano-node/BP.counter
sudo chmod -R 400 ~/cardano-node/BP.node.opcert
```

## Iniciar en modo productor de bloques (BP)

Para esto debemos iniciar `cardano-node` indicándole la ubicación de los archivos necesarios para que el pool pueda firmar bloques, ver TEMP y BLOCK en [Archivos de Servicio](/primeros-pasos/ejecutar-servicio.md#archivo-de-servicio):

* `kes.skey`
* `vrf.skey`
* `node.cert`

{% code title="/etc/systemd/system/BLOCK.service" %}

```
[Unit]
Description=Cardano Haskell Node - BLOCK
After=syslog.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=5
User=ubuntu
LimitNOFILE=131072
WorkingDirectory=/home/ubuntu/cardano-node/block
EnvironmentFile=/home/ubuntu/cardano-node/block/env
ExecStart=/home/ubuntu/.local/bin/cardano-node \
  +RTS -N -RTS run \
  --topology ${TOPOLOGY} \
  --database-path ${DATABASE_PATH} \
  --socket-path ${SOCKET_PATH} \
  --host-addr ${HOST_ADDR} \
  --port ${PORT} \
  --config ${CONFIG} \
  --shelley-kes-key ${SHELLEY_KES_KEY} \
  --shelley-vrf-key ${SHELLEY_VRF_KEY} \
  --shelley-operational-certificate ${SHELLEY_OPCERT}
KillSignal=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=BLOCK

[Install]
WantedBy=multi-user.target
```

{% endcode %}

{% hint style="info" %}
A partir de este punto se recomienda utilizar el servicio [BLOCK](/primeros-pasos/ejecutar-servicio.md) para iniciar nuestro BP.&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://es-kb.topopool.com/primeros-pasos/pool-keys-and-certs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
