Skip to content

Commit bff4a2e

Browse files
committed
chore: 🔧 add wallet-context schema checks to deps gate
1 parent 8c0d65c commit bff4a2e

4 files changed

Lines changed: 117 additions & 4 deletions

File tree

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
},
7171
"devDependencies": {
7272
"@types/bun": "latest",
73+
"ajv": "^8.17.1",
7374
"typescript": "^5.7.0"
7475
}
7576
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://github.com/AElfProject/aelf-skills/docs/schemas/wallet-context.v1.schema.json",
4+
"title": "WalletContextFileV1",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": [
8+
"version",
9+
"activeProfileId",
10+
"profiles",
11+
"lastWriter"
12+
],
13+
"properties": {
14+
"version": {
15+
"type": "integer",
16+
"const": 1
17+
},
18+
"activeProfileId": {
19+
"type": "string",
20+
"minLength": 1
21+
},
22+
"profiles": {
23+
"type": "object",
24+
"minProperties": 0,
25+
"additionalProperties": {
26+
"$ref": "#/$defs/activeProfile"
27+
}
28+
},
29+
"lastWriter": {
30+
"$ref": "#/$defs/lastWriter"
31+
}
32+
},
33+
"$defs": {
34+
"activeProfile": {
35+
"type": "object",
36+
"additionalProperties": false,
37+
"required": [
38+
"walletType",
39+
"source",
40+
"updatedAt"
41+
],
42+
"properties": {
43+
"walletType": {
44+
"type": "string",
45+
"enum": [
46+
"EOA",
47+
"CA"
48+
]
49+
},
50+
"source": {
51+
"type": "string",
52+
"enum": [
53+
"eoa-local",
54+
"ca-keystore",
55+
"env"
56+
]
57+
},
58+
"network": {
59+
"type": "string"
60+
},
61+
"address": {
62+
"type": "string"
63+
},
64+
"caAddress": {
65+
"type": "string"
66+
},
67+
"caHash": {
68+
"type": "string"
69+
},
70+
"walletFile": {
71+
"type": "string"
72+
},
73+
"keystoreFile": {
74+
"type": "string"
75+
},
76+
"updatedAt": {
77+
"type": "string",
78+
"format": "date-time"
79+
}
80+
}
81+
},
82+
"lastWriter": {
83+
"type": "object",
84+
"additionalProperties": false,
85+
"required": [
86+
"skill",
87+
"version"
88+
],
89+
"properties": {
90+
"skill": {
91+
"type": "string",
92+
"minLength": 1
93+
},
94+
"version": {
95+
"type": "string",
96+
"minLength": 1
97+
}
98+
}
99+
}
100+
}
101+
}

scripts/check-deps-baseline.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { existsSync, readFileSync } from 'node:fs';
33
import { homedir } from 'node:os';
44
import { resolve } from 'node:path';
5+
import Ajv from 'ajv';
56

67
type Baseline = {
78
dependencies: Record<string, string>;
@@ -15,6 +16,7 @@ function main() {
1516
const cwd = process.cwd();
1617
const baselinePath = resolve(cwd, 'deps-baseline.json');
1718
const packagePath = resolve(cwd, 'package.json');
19+
const contextSchemaPath = resolve(cwd, 'schemas', 'wallet-context.v1.schema.json');
1820

1921
if (!existsSync(baselinePath)) {
2022
console.error(`[deps:check] missing deps-baseline.json at ${baselinePath}`);
@@ -48,15 +50,23 @@ function main() {
4850
const contextPath =
4951
process.env.PORTKEY_SKILL_WALLET_CONTEXT_PATH ||
5052
resolve(homedir(), '.portkey', 'skill-wallet', 'context.v1.json');
51-
if (existsSync(contextPath)) {
53+
if (!existsSync(contextSchemaPath)) {
54+
failures.push(`missing wallet-context schema: ${contextSchemaPath}`);
55+
} else if (existsSync(contextPath)) {
5256
try {
57+
const schema = readJson<Record<string, unknown>>(contextSchemaPath);
5358
const contextRaw = readJson<Record<string, unknown>>(contextPath);
54-
if (contextRaw.version !== 1) {
55-
failures.push(`wallet-context version expected 1, got ${String(contextRaw.version)}`);
59+
const ajv = new Ajv({ allErrors: true, strict: false });
60+
const validate = ajv.compile(schema);
61+
if (!validate(contextRaw)) {
62+
const details = (validate.errors || [])
63+
.map((err) => `${err.instancePath || '/'} ${err.message || 'invalid'}`)
64+
.join('; ');
65+
failures.push(`wallet-context schema validation failed (${contextPath}): ${details}`);
5666
}
5767
} catch (error) {
5868
const message = error instanceof Error ? error.message : String(error);
59-
failures.push(`wallet-context parse failed: ${message}`);
69+
failures.push(`wallet-context parse/validation failed: ${message}`);
6070
}
6171
}
6272

0 commit comments

Comments
 (0)