A template for simplifying the validation of nostr events, their attributes and their respective tags using JSON-Schema standards.
@nostrwatch/schemata-js-ajv
- Typescript library for validating nostr events, depends on this package.
- Download ZIP file (all languages) or include package (js only for now)
- Validate
.json
schemas against nostr events.
You shouldn't. You should write a wrapper or use one that already exists. Wrappers must use the following typings.
type NSchemaResult [ boolean, NSchemaMessage[] ]
interface NSchemaMessage {
level: "info" | "warning" | "error"
message: string
}
And provide the following interface:
validate(event: NostrEvent): NSchemaResult
validateMany(events: NostrEvent[]): NSchemaResult[]
- Fork the repo.
pnpm install
pnpm build
pnpm test
Familiarize yourself with the aliases section and the file structure.
- Create a new directory for your NIP, and a directory for each kind. ...this is going to be annoying to write, so it should probbaly be automated.
This toolkit uses path conventions for build and testing schemata.
nips/nip-XY/kind-N/schema.yaml
Kinds are assumed to belong to a NIP, but if you are working with an experimental kind, you won't have a NIP. For these situations, simply place the kind into a nipless "nipless"
nips/nipless/kind-X