-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add new schemas package using zod, bring acc validation package… #801
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
Merged
Ansonhkg
merged 3 commits into
feat/naga-fix-bls-wasm-cleanup
from
feature/lit-3796-js-sdk-add-minimal-zod
Feb 25, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f3d85d4
feat: add new schemas package using zod, bring acc validation package…
FedericoAmura 6070756
feat: migrate accs validator to new accs schemas package and remove a…
FedericoAmura f69dd87
feat: define supported lit chains in constants and use those values t…
FedericoAmura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Lit Protocol Access Control Condition definitions | ||
|
||
The Lit Protocol Access Control Condition definitions are a set of Zod schemas that define the conditions that can be used to control access to a resource. | ||
|
||
## Condition definition | ||
|
||
A condition definition is a Zod schema that defines a condition that can be used to control access to a resource. More information can be found in the [Lit Protocol Access Control Condition definition specification](https://developer.litprotocol.com/v3/sdk/access-control/condition-types/unified-access-control-conditions) | ||
|
||
## Condition types | ||
|
||
The following condition types are defined: | ||
|
||
- EVM Basic Conditions | ||
- EVM Custom Contract Conditions | ||
- Solana RPC Conditions | ||
- Cosmos or Kyve Conditions | ||
|
||
Each has its own Zod schema that defines their properties. | ||
|
||
## Derived types | ||
|
||
Each condition type has a derived type that can be used to type the condition object when using Typescript. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'access-control-conditions-schemas', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[t]s$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: | ||
'../../coverage/packages/access-control-conditions-schemas', | ||
setupFilesAfterEnv: ['../../jest.setup.js'], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@lit-protocol/access-control-conditions-schemas", | ||
"license": "MIT", | ||
"homepage": "https://github.com/Lit-Protocol/js-sdk", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/LIT-Protocol/js-sdk" | ||
}, | ||
"keywords": [ | ||
"library" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/LIT-Protocol/js-sdk/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "../../dist/packages/access-control-conditions-schemas" | ||
}, | ||
"gitHead": "0d7334c2c55f448e91fe32f29edc5db8f5e09e4b", | ||
"tags": [ | ||
"universal" | ||
], | ||
"version": "8.0.0-alpha.0", | ||
"main": "./dist/src/index.js", | ||
"typings": "./dist/src/index.d.ts" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "access-control-conditions-schemas", | ||
"$schema": "../../node_modules/nx/access-control-conditions-schemas/project-schema.json", | ||
"sourceRoot": "packages/access-control-conditions-schemas/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/access-control-conditions-schemas", | ||
"main": "packages/access-control-conditions-schemas/src/index.ts", | ||
"tsConfig": "packages/access-control-conditions-schemas/tsconfig.lib.json", | ||
"assets": ["packages/access-control-conditions-schemas/*.md"], | ||
"updateBuildableProjectDepsInPackageJson": true | ||
} | ||
}, | ||
"generateDoc": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "yarn typedoc --entryPointStrategy expand packages/access-control-conditions-schemas/src --exclude packages/access-control-conditions-schemas/src/**/*.spec.** --tsconfig packages/access-control-conditions-schemas/tsconfig.json" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/access-control-conditions-schemas/**/*.ts" | ||
] | ||
} | ||
}, | ||
"testPackage": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": [ | ||
"{workspaceRoot}/coverage/packages/access-control-conditions-schemas" | ||
], | ||
"options": { | ||
"jestConfig": "packages/access-control-conditions-schemas/jest.config.ts", | ||
"passWithNoTests": true | ||
} | ||
}, | ||
"testWatch": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": [ | ||
"{workspaceRoot}/coverage/packages/access-control-conditions-schemas" | ||
], | ||
"options": { | ||
"jestConfig": "packages/access-control-conditions-schemas/jest.config.ts", | ||
"passWithNoTests": true, | ||
"watch": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './lib/access-control-conditions'; | ||
export * from './lib/AtomAcc'; | ||
export * from './lib/EvmBasicAcc'; | ||
export * from './lib/EvmContractAcc'; | ||
export * from './lib/OperatorAcc'; | ||
export * from './lib/SolAcc'; |
41 changes: 41 additions & 0 deletions
41
packages/access-control-conditions-schemas/src/lib/AtomAcc.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { AtomAccSchema } from './AtomAcc'; | ||
|
||
describe('AtomAccSchema', () => { | ||
const validAtomAcc = { | ||
conditionType: 'cosmos', | ||
path: '/cosmos/bank/v1beta1/balances/:userAddress', | ||
chain: 'cosmos', | ||
returnValueTest: { | ||
key: '$.balances[0].amount', | ||
comparator: '>=', | ||
value: '1000000', | ||
}, | ||
}; | ||
|
||
it('should validate a valid Atom access control condition', () => { | ||
expect(AtomAccSchema.safeParse(validAtomAcc).success).toBeTruthy(); | ||
}); | ||
|
||
it('should not validate an invalid Atom access control condition', () => { | ||
expect( | ||
AtomAccSchema.safeParse({ | ||
...validAtomAcc, | ||
path: undefined, | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
AtomAccSchema.safeParse({ | ||
...validAtomAcc, | ||
chain: 'invalidChain', | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
AtomAccSchema.safeParse({ | ||
...validAtomAcc, | ||
returnValueTest: undefined, | ||
}).success | ||
).toBeFalsy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/access-control-conditions-schemas/src/lib/AtomAcc.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { z } from 'zod'; | ||
|
||
import { ChainEnumAtom, ReturnValueTestSchema } from './common'; | ||
|
||
export const AtomAccSchema = z | ||
.object({ | ||
conditionType: z.literal('cosmos').optional(), | ||
path: z.string(), | ||
chain: ChainEnumAtom, | ||
method: z.string().optional(), | ||
parameters: z.array(z.string()).optional(), | ||
returnValueTest: ReturnValueTestSchema, | ||
}) | ||
.strict(); | ||
|
||
export type AtomAcc = z.infer<typeof AtomAccSchema>; |
70 changes: 70 additions & 0 deletions
70
packages/access-control-conditions-schemas/src/lib/EvmBasic.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { EvmBasicAccSchema } from './EvmBasicAcc'; | ||
|
||
describe('EvmBasicAccSchema', () => { | ||
const validEVMBasicAcc = { | ||
conditionType: 'evmBasic', | ||
contractAddress: '0x50D8EB685a9F262B13F28958aBc9670F06F819d9', | ||
standardContractType: 'MolochDAOv2.1', | ||
chain: 'ethereum', | ||
method: 'members', | ||
parameters: [':userAddress'], | ||
returnValueTest: { | ||
comparator: '=', | ||
value: 'true', | ||
}, | ||
}; | ||
|
||
it('should validate a valid EVM basic access control condition', () => { | ||
expect(EvmBasicAccSchema.safeParse(validEVMBasicAcc).success).toBeTruthy(); | ||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
conditionType: undefined, | ||
}).success | ||
).toBeTruthy(); | ||
}); | ||
|
||
it('should not validate an invalid EVM basic access control conditions', () => { | ||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
chain: 'invalidChain', | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
chain: undefined, | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
chain: 1, | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
method: undefined, | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
contractAddress: undefined, | ||
}).success | ||
).toBeFalsy(); | ||
|
||
expect( | ||
EvmBasicAccSchema.safeParse({ | ||
...validEVMBasicAcc, | ||
standardContractType: undefined, | ||
}).success | ||
).toBeFalsy(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE!