# Base Registry

## Overview

The base registry (<mark style="color:red;">`BaseRegistry.sol`</mark>) is a contract that implements the core functionality that a registry needs, and thus it is used as a base for most KAIO registries. These then extend the functionality as needed for their specific purpose.

## Data Storage

The base registry inherits the functions and date types from the [Eternal Registry Storage](/how-kaio-works/smart-contracts/registries/eternal-registry-storage.md), but adds restrictions to who can store data in it. This is checked with the following functions:

* ***\_checkHasAccess()*** : This function checks that the identifier to store data for is valid, and that the caller has the correct role in order to store data for that identifier. Usually the role required is for admins, but extra access can be given to certain users without roles. For example in the investor registry, dealers have this extra access and can thus add data to storage.
* ***\_onlyConfigurableKey()*** : This function checks that the key to store data for is not restricted. Some keys are restricted since they are already being used by the contracts, and should not be modifiable by users, regardless of their role. One such example would be the `FUND_ID` in the instrument registry, since no one should be able to modify its value once it is set by the contract.

## User Registry

An extension of the base registry known as the base user registry (<mark style="color:red;">`BaseUserRegistry.sol`</mark>) is used for registries storing user information, such as for investors or dealers. It includes additional functionality for adding and querying wallets for users, with wallets being associated with their Id.

### Adding Wallet

* **Function**: `addWallet(address _wallet, uint256 _expiry, bytes _signature)`
* **Purpose**: Adds a new wallet to an existing user.
* **Parameters**:
  * `address _wallet`: Address of the wallet.
  * `uint256 _expiry`: Signature expiry timestamp.
  * `bytes _signature`: Signature proving ownership of wallet.
* **Validation Checks**:
  * Checks the signature is not expired.
  * Ensures the signature is signed by the caller.
  * Verifies the signature is meant for the given contract.
  * Confirms the signature is meant for the given chain.
  * Makes sure the caller has a valid user Id.
  * Checks the wallet is not already owned.
* **Behavior**:
  * Adds a new wallet to the caller using their Id.
  * Emits a `WalletAdded` event, signaling the wallet has been added.
* **Example**:

  ```solidity
  addWallet(0xWallet, 1714879500, 0xSignature);
  ```

### Getting Wallets

* **Function**: `getWallets(bytes32 _userId)`
* **Purpose**: Returns the list of wallets for a given user.
* **Parameters**:
  * `bytes32 _userId`: Id of the user.
* **Return Values:**
  * `address[]`: List of the addresses for the user's wallets.
* **Example**:

  ```solidity
  getWallets(0xUserId);
  ```

### Getting Id from Wallet

* **Function**: `getIdFromWallet(address wallet)`
* **Purpose**: Returns the Id to which a given wallets belongs to.
* **Parameters**:
  * `address wallet`: Address of the wallet to check.
* **Return Values:**
  * `bytes32`: Id of the user owning the wallet.
* **Example**:

  ```solidity
  getIdFromWallet(0xWallet);
  ```


---

# 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://docs.kaio.xyz/how-kaio-works/smart-contracts/registries/base-registry.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.
