RohanNero / block3d

An open-source authentication toolkit designed to streamline access control within Nextjs dapps.
https://block3d.gitbook.io/block3d
GNU General Public License v3.0
1 stars 0 forks source link

Add support for rules that rely on an external function call #1

Open RohanNero opened 4 months ago

RohanNero commented 4 months ago

Overview

Currently, users can specify a list of addresses that will be whitelisted to view the site, however, this is undesirable in cases where the list of addresses is massive or when the list of addresses updates frequently.

Solution

To fix this, we could:

  1. add the contracts array rule field to simple rules OR create a new dynamic rule type.
  2. add a new optional field, calldata, into the Contract type. This will be used to make the function call that should return an array of addresses OR a boolean.

This also means we would need to specify whether or not the user's address should be included in the calldata. For this I propose we add optional userArg field to the Contract object. This is a boolean value that when true means we will pass the user's address along with the calldata when making the function call.

If a boolean is returned by the function call, we will need another optional field inside contracts that lets the user mark what the expected value is.

Example:

This dynamic rule example utilizes Chainalysis' SanctionsList contract to block all sanctioned addresses on Ethereum Mainnet.

{
      type: "dynamic", 
      title: "Sanctioned",
      contracts: [
        {
          address: "0x40C57923924B5c5c5455c48D93317139ADDaC8fb", 
          chainId: 1,
          calldata: "0xdf592f7d",
          userArg: true,
          expect: false, 
        },
      ],
    },