Skip to content

Receiving a request

As a miner in the Fiber network, you need to securely receive and decrypt requests from validators. This guide will walk you through the process of handling incoming requests, decrypting the payload, and verifying the request’s authenticity.

Decryption Process

When a request is received, it is encrypted using a symmetric key. The decryption process involves the following steps:

  1. Retrieve the Symmetric Key: The symmetric key used for encryption is identified using the symmetric_key_uuid and hotkey_ss58_address headers.
  2. Decrypt the Payload: The encrypted payload is decrypted using the retrieved symmetric key.
  3. Parse the Decrypted Data: The decrypted data is parsed into the expected model.

Decrypting the Payload

The decrypt_general_payload function handles the decryption process. Here is the implementation:

def decrypt_general_payload(
model: Type[T],
encrypted_payload: bytes = Depends(get_body),
symmetric_key_uuid: str = Header(...),
hotkey_ss58_address: str = Header(...),
config: Config = Depends(get_config),
) -> T:
symmetric_key_info = config.encryption_keys_handler.get_symmetric_key(hotkey_ss58_address, symmetric_key_uuid)
if not symmetric_key_info:
raise HTTPException(status_code=400, detail="No symmetric key found for that hotkey and uuid")
decrypted_data = symmetric_key_info.fernet.decrypt(encrypted_payload)
data_dict = json.loads(decrypted_data.decode())
return model(**data_dict)