Skip to content

Commit f3d85d4

Browse files
committed
feat: add new schemas package using zod, bring acc validation package to also use zod and be integrated into the sdk instead of an external package using ajv
1 parent 1196d13 commit f3d85d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1878
-386
lines changed

local-tests/tests/wrapped-keys/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LIT_NETWORKS_KEYS } from '@lit-protocol/types';
2-
import { LIT_CHAINS } from '@lit-protocol/constants';
2+
import { LIT_CHAINS, LIT_NETWORK } from '@lit-protocol/constants';
33
import { ethers } from 'ethers';
44
import { config } from '@lit-protocol/wrapped-keys';
55
import {
@@ -51,7 +51,7 @@ export function getChainForNetwork(network: LIT_NETWORKS_KEYS): {
5151
chainId: number;
5252
} {
5353
switch (network) {
54-
case 'naga-dev':
54+
case LIT_NETWORK.NagaDev:
5555
return {
5656
chain: 'yellowstone',
5757
chainId: LIT_CHAINS['yellowstone'].chainId,
@@ -66,9 +66,9 @@ export function getGasParamsForNetwork(network: LIT_NETWORKS_KEYS): {
6666
gasLimit: number;
6767
} {
6868
switch (network) {
69-
case 'naga-dev':
69+
case LIT_NETWORK.NagaDev:
7070
return { gasLimit: 5000000 };
71-
case 'custom':
71+
case LIT_NETWORK.Custom:
7272
return { gasLimit: 5000000 };
7373
default:
7474
throw new Error(`Cannot identify chain params for ${network}`);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
"tslib": "^2.7.0",
7171
"tweetnacl": "^1.0.3",
7272
"tweetnacl-util": "^0.15.1",
73-
"uint8arrays": "^4.0.3"
73+
"uint8arrays": "^4.0.3",
74+
"zod": "^3.24.2",
75+
"zod-validation-error": "^3.4.0"
7476
},
7577
"devDependencies": {
7678
"@nx/devkit": "17.3.0",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["*.json"],
19+
"parser": "jsonc-eslint-parser",
20+
"rules": {
21+
"@nx/dependency-checks": "error"
22+
}
23+
}
24+
]
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Lit Protocol Access Control Condition definitions
2+
3+
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.
4+
5+
## Condition definition
6+
7+
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)
8+
9+
## Condition types
10+
11+
The following condition types are defined:
12+
13+
- EVM Basic Conditions
14+
- EVM Custom Contract Conditions
15+
- Solana RPC Conditions
16+
- Cosmos or Kyve Conditions
17+
18+
Each has its own Zod schema that defines their properties.
19+
20+
## Derived types
21+
22+
Each condition type has a derived type that can be used to type the condition object when using Typescript.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'access-control-conditions-schemas',
4+
preset: '../../jest.preset.js',
5+
globals: {
6+
'ts-jest': {
7+
tsconfig: '<rootDir>/tsconfig.spec.json',
8+
},
9+
},
10+
transform: {
11+
'^.+\\.[t]s$': 'ts-jest',
12+
},
13+
moduleFileExtensions: ['ts', 'js', 'html'],
14+
coverageDirectory:
15+
'../../coverage/packages/access-control-conditions-schemas',
16+
setupFilesAfterEnv: ['../../jest.setup.js'],
17+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@lit-protocol/access-control-conditions-schemas",
3+
"license": "MIT",
4+
"homepage": "https://github.com/Lit-Protocol/js-sdk",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/LIT-Protocol/js-sdk"
8+
},
9+
"keywords": [
10+
"library"
11+
],
12+
"bugs": {
13+
"url": "https://github.com/LIT-Protocol/js-sdk/issues"
14+
},
15+
"publishConfig": {
16+
"access": "public",
17+
"directory": "../../dist/packages/access-control-conditions-schemas"
18+
},
19+
"gitHead": "0d7334c2c55f448e91fe32f29edc5db8f5e09e4b",
20+
"tags": [
21+
"universal"
22+
],
23+
"version": "8.0.0-alpha.0",
24+
"main": "./dist/src/index.js",
25+
"typings": "./dist/src/index.d.ts"
26+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "access-control-conditions-schemas",
3+
"$schema": "../../node_modules/nx/access-control-conditions-schemas/project-schema.json",
4+
"sourceRoot": "packages/access-control-conditions-schemas/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nx/js:tsc",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/packages/access-control-conditions-schemas",
12+
"main": "packages/access-control-conditions-schemas/src/index.ts",
13+
"tsConfig": "packages/access-control-conditions-schemas/tsconfig.lib.json",
14+
"assets": ["packages/access-control-conditions-schemas/*.md"],
15+
"updateBuildableProjectDepsInPackageJson": true
16+
}
17+
},
18+
"generateDoc": {
19+
"executor": "nx:run-commands",
20+
"options": {
21+
"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"
22+
}
23+
},
24+
"lint": {
25+
"executor": "@nx/linter:eslint",
26+
"outputs": ["{options.outputFile}"],
27+
"options": {
28+
"lintFilePatterns": [
29+
"packages/access-control-conditions-schemas/**/*.ts"
30+
]
31+
}
32+
},
33+
"testPackage": {
34+
"executor": "@nx/jest:jest",
35+
"outputs": [
36+
"{workspaceRoot}/coverage/packages/access-control-conditions-schemas"
37+
],
38+
"options": {
39+
"jestConfig": "packages/access-control-conditions-schemas/jest.config.ts",
40+
"passWithNoTests": true
41+
}
42+
},
43+
"testWatch": {
44+
"executor": "@nx/jest:jest",
45+
"outputs": [
46+
"{workspaceRoot}/coverage/packages/access-control-conditions-schemas"
47+
],
48+
"options": {
49+
"jestConfig": "packages/access-control-conditions-schemas/jest.config.ts",
50+
"passWithNoTests": true,
51+
"watch": true
52+
}
53+
}
54+
},
55+
"tags": []
56+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from './lib/access-control-conditions';
2+
export * from './lib/AtomAcc';
3+
export * from './lib/EvmBasicAcc';
4+
export * from './lib/EvmContractAcc';
5+
export * from './lib/OperatorAcc';
6+
export * from './lib/SolAcc';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { AtomAccSchema } from './AtomAcc';
2+
3+
describe('AtomAccSchema', () => {
4+
const validAtomAcc = {
5+
conditionType: 'cosmos',
6+
path: '/cosmos/bank/v1beta1/balances/:userAddress',
7+
chain: 'cosmos',
8+
returnValueTest: {
9+
key: '$.balances[0].amount',
10+
comparator: '>=',
11+
value: '1000000',
12+
},
13+
};
14+
15+
it('should validate a valid Atom access control condition', () => {
16+
expect(AtomAccSchema.safeParse(validAtomAcc).success).toBeTruthy();
17+
});
18+
19+
it('should not validate an invalid Atom access control condition', () => {
20+
expect(
21+
AtomAccSchema.safeParse({
22+
...validAtomAcc,
23+
path: undefined,
24+
}).success
25+
).toBeFalsy();
26+
27+
expect(
28+
AtomAccSchema.safeParse({
29+
...validAtomAcc,
30+
chain: 'invalidChain',
31+
}).success
32+
).toBeFalsy();
33+
34+
expect(
35+
AtomAccSchema.safeParse({
36+
...validAtomAcc,
37+
returnValueTest: undefined,
38+
}).success
39+
).toBeFalsy();
40+
});
41+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { z } from 'zod';
2+
3+
import { ChainEnumAtom, ReturnValueTestSchema } from './common';
4+
5+
export const AtomAccSchema = z
6+
.object({
7+
conditionType: z.literal('cosmos').optional(),
8+
path: z.string(),
9+
chain: ChainEnumAtom,
10+
method: z.string().optional(),
11+
parameters: z.array(z.string()).optional(),
12+
returnValueTest: ReturnValueTestSchema,
13+
})
14+
.strict();
15+
16+
export type AtomAcc = z.infer<typeof AtomAccSchema>;

0 commit comments

Comments
 (0)