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

chore(credentials): use the zk-kit logical-expressions package #544

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/credentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"@bandada/utils": "2.3.0",
"@zk-kit/logical-expressions": "1.0.0",
"ethers": "5.7.0"
},
"devDependencies": {
Expand Down
120 changes: 0 additions & 120 deletions libs/credentials/src/evaluateExpression.ts

This file was deleted.

88 changes: 0 additions & 88 deletions libs/credentials/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
validateManyCredentials
} from "./validateCredentials"
import { testUtils } from "."
import { evaluate, tokenize } from "./evaluateExpression"
import checkCriteria from "./checkCriteria"
import getJsonRpcProvider from "./getJsonRpcProvider"
import queryGraph from "./queryGraph"
Expand Down Expand Up @@ -315,91 +314,4 @@ describe("Credentials library", () => {
expect(result).toBeTruthy()
})
})
describe("# evaluateExpression", () => {
describe("# tokenize", () => {
it("Should sucessfully tokenize a logical expression", () => {
const expression = "true and false or ( true and true )"

const tokens = tokenize(expression)

const result = [
"true",
"and",
"false",
"or",
"(",
"true",
"and",
"true",
")"
]

expect(tokens).toStrictEqual(result)
})
})
describe("# evaluate", () => {
it("Should sucessfully evaluate a logical expression with the and operator", () => {
const expression = ["true", "and", "false"]
const result = evaluate(expression)
expect(result).toBeFalsy()
})
it("Should sucessfully evaluate a logical expression with the or operator", () => {
const expression = ["true", "or", "false"]
const result = evaluate(expression)
expect(result).toBeTruthy()
})
it("Should sucessfully evaluate a logical expression with the not operator", () => {
const expression = ["not", "false"]
const result = evaluate(expression)
expect(result).toBeTruthy()
})
it("Should sucessfully evaluate a logical expression with the xor operator", () => {
const expression = ["false", "xor", "true"]
const result = evaluate(expression)
expect(result).toBeTruthy()
})
it("Should sucessfully evaluate a logical expression with the and or not and xor operators", () => {
const expression = [
"true",
"and",
"false",
"or",
"not",
"false",
"xor",
"true"
]
const result = evaluate(expression)
expect(result).toBeFalsy()
})
it("Should sucessfully evaluate a logical expression with parentheses", () => {
const expression = [
"true",
"and",
"false",
"or",
"(",
"true",
"and",
"true",
")"
]
const result = evaluate(expression)
expect(result).toBeTruthy()
})
it("Should sucessfully evaluate a logical expression with the and or not and xor operators in parentheses", () => {
const expression = [
"true",
"and",
"false",
"or",
"(",
"not",
")"
]
const result = evaluate(expression)
expect(result).toBeTruthy()
})
})
})
})
3 changes: 1 addition & 2 deletions libs/credentials/src/validateCredentials.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { evaluate } from "@zk-kit/logical-expressions"
import checkCriteria from "./checkCriteria"
import getAPI from "./getAPI"
import getProvider from "./getProvider"
import getValidator from "./getValidator"
import { Context, Credentials, Web2Provider } from "./types"

import { evaluate } from "./evaluateExpression"

/**
* It checks if the user meets the credentials of a group.
* It also adds utility functions to the credentials context that
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,7 @@ __metadata:
dependencies:
"@bandada/utils": "npm:2.3.0"
"@rollup/plugin-typescript": "npm:^11.0.0"
"@zk-kit/logical-expressions": "npm:1.0.0"
ethers: "npm:5.7.0"
rimraf: "npm:^4.1.2"
rollup: "npm:^3.17.2"
Expand Down Expand Up @@ -10452,6 +10453,13 @@ __metadata:
languageName: node
linkType: hard

"@zk-kit/logical-expressions@npm:1.0.0":
version: 1.0.0
resolution: "@zk-kit/logical-expressions@npm:1.0.0"
checksum: 10/d1309904bc7080b55b56e2fce8fa1d99bda63f7671045bfa5012c7460b9b00d10f58f7b27943e995c1288cb597f4ec5b09861bb1c62c1721fad7810109baa2af
languageName: node
linkType: hard

"JSONStream@npm:^1.0.4, JSONStream@npm:^1.3.5":
version: 1.3.5
resolution: "JSONStream@npm:1.3.5"
Expand Down
Loading