npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nostrwatch/schemata-js-ajv

v1.0.2

Published

AJV-powered validation for Nostr events, NIP-11 info documents, and protocol messages.

Downloads

37

Readme

@nostrwatch/schemata-js-ajv

AJV-powered validation for Nostr events, NIP-11 info documents, and protocol messages.

npm version License Status Runtime

Overview

@nostrwatch/schemata-js-ajv wraps the @nostrability/schemata JSON Schema definitions with AJV validation, exposing three ready-to-use validation functions for common Nostr data structures. A NIP-11 info document is the metadata object a relay (a WebSocket server that stores and forwards Nostr events) serves at its HTTP endpoint. This package validates that document as well as individual Nostr events and protocol messages.

Validation results include both hard errors (schema violations) and soft warnings (additional properties not defined in the schema).

Installation

pnpm add @nostrwatch/schemata-js-ajv

Or with npm:

npm install @nostrwatch/schemata-js-ajv

AJV is a peer dependency — install it alongside:

pnpm add ajv

Quick Start

import {validateNip11} from '@nostrwatch/schemata-js-ajv'

const nip11 = {
  name: 'Damus Relay',
  description: 'A Nostr relay',
  pubkey: 'abc123...',
  contact: '[email protected]',
  supported_nips: [1, 11, 42],
  software: 'strfry',
  version: '1.0.0'
}

const result = validateNip11(nip11)
console.log(result)
// { valid: true, errors: [], warnings: [] }

API

validateNip11(nip11)

validateNip11(nip11: any): SchemaValidatorResult | undefined

Validates a NIP-11 relay information document against the @nostrability/schemata nip11Schema. Returns a SchemaValidatorResult with validation errors and warnings about additional properties.

| Parameter | Type | Description | |-----------|------|-------------| | nip11 | any | A NIP-11 relay info document object |

validateNote(note)

validateNote(note: NostrEvent): SchemaValidatorResult | undefined

Validates a Nostr event (note) against the schema for its kind. The schema is looked up from @nostrability/schemata using the key kind${kind}Schema. Returns a result with a warning if no schema exists for the given kind.

| Parameter | Type | Description | |-----------|------|-------------| | note | NostrEvent | A Nostr event object (from nostr-tools) |

validateMessage(message, subject, slug)

validateMessage(message: any, subject: 'relay' | 'client', slug: string): SchemaValidatorResult | undefined

Validates a Nostr protocol message against the schema for the given subject and message type. The schema key is constructed as ${subject}${capitalize(slug)}Schema (e.g., relayNoticeSchema for subject='relay', slug='notice').

| Parameter | Type | Description | |-----------|------|-------------| | message | any | The protocol message to validate | | subject | 'relay' \| 'client' | Message origin: from the relay or from the client | | slug | string | Message type name (e.g., 'notice', 'event', 'ok') |

SchemaValidatorResult

type SchemaValidatorResult = {
  valid: boolean
  warnings: ErrorObject[]
  errors: ErrorObject[]
}
  • validtrue if the data passes all schema constraints
  • errors — AJV validation errors (schema violations); empty when valid is true
  • warnings — additional property warnings; populated even when valid is true

validate(schema, data)

validate(schema: any, data: any): SchemaValidatorResult

Low-level validator. Compiles an arbitrary JSON Schema with AJV and validates data against it. Use validateNip11, validateNote, or validateMessage for common cases.

Known Limitations

  • Partial kind coverage: Only event kinds with a corresponding schema in @nostrability/schemata can be validated. validateNote returns a warning (not an error) when no schema exists for the given kind.
  • No multi-stage validation: The content field of events that contain stringified JSON (e.g., kind 0 metadata) is not recursively validated.
  • Alpha accuracy: False positives and false negatives are possible. The schemas are in early development.

Agent Skills

No agent skills defined yet for this package.

Related Packages

License

MIT