Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Groups with multiple credentials and logical operators #530

Merged
merged 8 commits into from
Jul 2, 2024

Conversation

vplasencia
Copy link
Member

@vplasencia vplasencia commented Jun 21, 2024

Description

This PR adds support for groups with multiple credentials and logical operators.

Related Issue

Closes #223

Does this introduce a breaking change?

  • Yes
  • No

Other information

Information about groups with many credentials

A user can use the Dashboard app or API to create a group with many credentials.

This is the structure of a credential group with only one credential

{
    (other group info)
    
    ...

    "credentials": "{}"
}

Example:

{
    (other group info)
    
    ...

    "credentials": "{\"id\":\"GITHUB_FOLLOWERS\",\"criteria\":{\"minFollowers\":20}}"
}

This is the structure of a credential group with multiple credentials:

{
    "credentials": "{credentials:[], "expression":[]}"
}

Example:

{
    (other group info)

    ...


    "credentials": "{\"credentials\":[{\"id\":\"BLOCKCHAIN_TRANSACTIONS\",\"criteria\":{\"minTransactions\":12,\"network\":\"Sepolia\"}},{\"id\":\"BLOCKCHAIN_BALANCE\",\"criteria\":{\"minBalance\":\"3\",\"network\":\"Sepolia\"}}],\"expression\":[\"\",\"and\",\"\"]}"
}

The user will be able to join a credential group by using a URL like this:

<dashboard-url>/credentials?group=<group-id>&member=<member-id>&type=multiple

Example:

http://localhost:3001/credentials?group=79609564395766533586300841856737&member=15316025723065452012129624296669307962292967176408402265701167251062457738490&type=multiple

Then the user will be asked to prove all the credentials.

Since checking credentials require using different URLs under the hood, the main user data to later check the credentials will be saved in local storage. It's removed when all the values are completed.

The local storage will look like this:

bandada_credentials: {
    "provider1": [],
    "provider2": [],
    "provider3": [] 
}

Example:

bandada_credentials: {
    "blockchain": ["<oauth-state>",null,"<account-address>"],
    "github": ["<oauth-state>", <oauth-code>],
    "twitter": ["<oauth-state>", <oauth-code>]
}

Some information about the implementation

  • Related to evaluating a logical expression.

The expression property, in the credentials' property in a multiple credential group, is an array with strings. Every position will have an empty string or a string with a logical operator. Every empty string represents a credential. Then the first empty string represents the first credential in the list of credentials, the second empty string represents the second credential in the list of credentials and so on.

If for example, we have something like:

{
    "credentials": "{credentials:[credential1, credential2], "expression":["", "and", ""]}"
}

The expression that will be evaluated is: credential1 and credential2.

After all the credentials are evaluated, we will have true or false for every one of them and then we will have an expression like: ["true", "and", "true"] in case credential1 and credential2 both evaluate to true.

Then the logical expression will be evaluated using the Shunting Yard algorithm adapted to evaluate expressions with logical operators.

  • There is a new function to evaluate many credentials in the Credentials library.

Copy link

vercel bot commented Jun 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bandada-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2024 6:51pm
bandada-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2024 6:51pm

Copy link
Collaborator

@0xjei 0xjei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant work! It's really tidy <3

Just a thought: we should open a PR to add more tests to cover more edge cases (like using parenthesis, large numbers of credentials, and so on). Otherwise, it looks great!

@vplasencia
Copy link
Member Author

Hey @0xjei thank you very much for reviewing it. I will add a couple of new test cases.

@vplasencia
Copy link
Member Author

Hey @0xjei. I just added more tests to cover all possible logical operators and more complex logical expressions, and some of them with parentheses. Added a new test for many credentials with parentheses in the expression. Please see 74e7874.

@vplasencia vplasencia requested a review from 0xjei June 27, 2024 18:54
Copy link
Collaborator

@0xjei 0xjei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing, tysm for adding these cases!

@vplasencia vplasencia merged commit e366f5c into main Jul 2, 2024
5 checks passed
@vplasencia vplasencia deleted the feat/many-credentials branch September 13, 2024 20:59
@vplasencia vplasencia mentioned this pull request Nov 28, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add logic operators on reputation criteria
2 participants