Keyring Connect

1. Use a test Policy

Use our Keyring Connect Test Policy (ID: 7 see here). 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

  3. Other parameters:

    • Refresh rate: 1 year

🔗 Address of the deployed Sepolia Policy Manager contract.

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.

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.

Example: Uniswap v4

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

  • 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.

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

🔗 KeyringCredentialViewer deployed on Sepolia

3. Test User Flow

Test the end-to-end user journey on the Keyring app.

You'll need Sepolia ETH to create your credentials. You can get some here:

🔗 Alchemy

🔗 Infura

🔗 Mining faucet

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

  • Download the browser extension

  • Navigate to [Binance] and generate your proofs

  • Create credentials

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.

Last updated