# Keyring Connect

## 1. **Use a test Policy**

Use our Keyring Connect Test Policy (ID: 7 [see here](https://app.keyring.network/policies/keyring-connect-test)). It includes usual data points verified by a centralised exchange. Policy setup:

1. **Data sources**: Binance, Binance U.S., Kraken, Coinbase, Revolut
2. **Rule**: Individual users
   * KYC is passed
   * Exclude if residence country is in [FATF blacklist](https://www.fatf-gafi.org/en/countries/black-and-grey-lists.html)
3. **Other parameters**:&#x20;
   * Refresh rate: 1 year

## **2.** On-chain Permissioning

Hook your chosen functions with permissioning reading from the KeyringCredentialViewer, for Test Policy 7. The hook uses a `view` function, which maps wallet addresses to Policy IDs. Here, it will verify that a user wallet has valid credentials for Policy 7.&#x20;

```solidity
if(!keyring.checkCredential(policyId, msg.sender)) {
    revert Unauthorized();
}
```

The Keyring view function `checkCredential` will return a boolean value if the given address (in this case the `msg.sender`) is authorised or not for the given Policy ID.

<details>

<summary>Example: Uniswap v4</summary>

In our Uniswap v4 example, here are the functions we'd want to permission:&#x20;

* `beforeAddLiquidity` : this function is invoked whenever a user deposits one of the two supported assets (or both) in the pool and receives an LP token representing a pro-rata ownership over the pool TVL. By hooking into the preliminary step of this process, we can prevent bad actors from tainting the pool even before an actual token transfer is initiated (thus achieving max gas efficiency).
* `beforeSwap` : similarly, we can block unwanted users from interacting with the pool by tapping into the swap checker hook and revert if a non-permissioned user tries to initiate a swap.

***

**Part 1: Hook initialisation**. In the specific example of Uniswap v4 Keyring hook, we are setting up a Keyring Cache instance and a single immutable PolicyID, but projects may want to have a mutable Policy ID if they wish or use multiple policies to check their users.

```solidity
IKeyringCache public immutable keyringCredentialViewer;
uint256 public immutable policyId;

error Unauthorized();

constructor(IPoolManager _poolManager, address _keyring, uint256 _policyId) BaseHook(_poolManager) {
    keyringCache = IKeyringCache(_keyring);
    policyId = _policyId;
}
```

***

**Part 2: Include hook in relevant functions**. Code example available here: <https://github.com/Keyring-Network/keyring-integration-examples>

</details>

### Useful links

🔗 [KeyringCredentialViewer](https://sepolia.etherscan.io/address/0x0b33fE66FF4Fa1B9784403c0b2315530735A6AEE) deployed on Sepolia

## 3. Test User Flow

Test the end-to-end user journey on the Keyring app.&#x20;

{% hint style="info" %}
You'll need Sepolia ETH to create your credentials. You can get some here:&#x20;

🔗 [Alchemy](https://www.alchemy.com/faucets/ethereum-sepolia)

🔗 [Infura](https://www.infura.io/faucet/sepolia)

🔗 [Mining faucet](https://sepolia-faucet.pk910.de/)
{% endhint %}

Navigate to <https://sandbox-titan.app.keyring.network/> and test the user journey with your own Sepolia test environment:

* Select onboarding for Policy 7 and follow the steps&#x20;
* Download the browser extension&#x20;
* Navigate to \[Binance] and generate your proofs
* Create credentials

{% hint style="warning" %}
We are not mocking accounts on data source websites. Therefore, you'll only be able to validate onboarding if you verify the requirements set out by the Policy.
{% 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://docs.keyring.network/docs/protocol-guide/sandbox/keyring-connect.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.
