-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refine schemas and implement into auditor
- Loading branch information
Showing
39 changed files
with
1,133 additions
and
238 deletions.
There are no files selected for viewing
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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
76 changes: 7 additions & 69 deletions
76
libraries/auditor/src/nips/Nip42/schemata/client-auth-event.schema.json
This file contains 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 |
---|---|---|
@@ -1,69 +1,7 @@ | ||
{ | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"const": "AUTH" | ||
}, | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"pattern": "^[a-f0-9]{64}$", | ||
"description": "32-byte lowercase hex-encoded sha256 hash of the serialized event data" | ||
}, | ||
"pubkey": { | ||
"type": "string", | ||
"pattern": "^[a-f0-9]{64}$", | ||
"description": "32-byte lowercase hex-encoded public key of the event creator" | ||
}, | ||
"created_at": { | ||
"type": "integer", | ||
"minimum": 1000000000, | ||
"maximum": 9999999999, | ||
"description": "Unix timestamp in seconds (10-digit timestamp, not in milliseconds)" | ||
}, | ||
"kind": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"maximum": 65535, | ||
"description": "Integer between 0 and 65535" | ||
}, | ||
"tags": { | ||
"type": "array", | ||
"items": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"description": "Arbitrary string within the tag array" | ||
}, | ||
"minItems": 1 | ||
}, | ||
"description": "Array of arrays, each containing arbitrary strings as tags" | ||
}, | ||
"content": { | ||
"type": "string", | ||
"description": "Arbitrary string content of the event" | ||
}, | ||
"sig": { | ||
"type": "string", | ||
"pattern": "^[a-f0-9]{128}$", | ||
"description": "64-byte lowercase hex-encoded signature of the sha256 hash of the serialized event data (same as 'id' field)" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"pubkey", | ||
"created_at", | ||
"kind", | ||
"tags", | ||
"content", | ||
"sig" | ||
], | ||
"additionalProperties": false | ||
} | ||
], | ||
"minItems": 2, | ||
"maxItems": 2 | ||
} | ||
--- | ||
type: "array" | ||
items: | ||
- const: "AUTH" | ||
- $ref: "@/note.yaml" | ||
minItems: "2" | ||
maxItems: "2" |
Submodule schemata
added at
3b4b8b
This file contains 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 @@ | ||
{ | ||
"name": "@nostrwatch/schemata-js-ajv", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@nostrwatch/schemata": "workspace:^", | ||
"ajv": "^8.17.1", | ||
"nostr-tools": "^2.10.4" | ||
} | ||
} |
This file contains 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,29 @@ | ||
import Ajv, { type ErrorObject } from 'ajv'; | ||
import * as NostrSchemata from '@nostrwatch/schemata' | ||
import { type NostrEvent } from 'nostr-tools' | ||
|
||
const ajv = new Ajv(); | ||
|
||
export type ValidatorResult = { | ||
valid: boolean; | ||
warnings: string[]; | ||
errors: ErrorObject[]; | ||
} | ||
|
||
export const validate = (note: NostrEvent): ValidatorResult | undefined => { | ||
const { kind } = note; | ||
const result: ValidatorResult = { valid: false, errors: [], warnings: [] } | ||
const schema = NostrSchemata?.[`kind${kind}Schema`]; | ||
if(!schema) { | ||
result.warnings.push('No schema found for kind'); | ||
return result; | ||
} | ||
const validate = ajv.compile(schema); | ||
const valid = validate(note); | ||
if(valid) { | ||
result.valid = true; | ||
return result; | ||
} | ||
result.errors = validate.errors ?? []; | ||
return result; | ||
} |
This file contains 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,20 @@ | ||
{ | ||
"name": "@nostrwatch/nip01-schema", | ||
"version": "0.0.1", | ||
"main": "dist/index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"json-loader": "0.5.7", | ||
"ts-loader": "9.5.1", | ||
"typescript": "5.5.4", | ||
"webpack": "5.93.0", | ||
"webpack-cli": "5.1.4", | ||
"webpack-merge": "6.0.1", | ||
"webpack-node-externals": "3.0.0", | ||
"yaml-convert": "1.0.1" | ||
}, | ||
"scripts": { | ||
"prebuild": "mkdir -p dist && yaml-convert --pretty true --input src/schema.yaml --output src/schema.json && cp src/schema.json dist/schema.json", | ||
"build": "tsc && webpack --mode development --stats verbose" | ||
} | ||
} |
This file contains 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,2 @@ | ||
const schema = require('./schema.json') | ||
module.exports = schema |
Oops, something went wrong.