Skip to content

feat(nip98): add Authorization header verifier - #722

Open
Anshumancanrock wants to merge 1 commit into
cameri:mainfrom
Anshumancanrock:feat/nip98-verifier
Open

feat(nip98): add Authorization header verifier#722
Anshumancanrock wants to merge 1 commit into
cameri:mainfrom
Anshumancanrock:feat/nip98-verifier

Conversation

@Anshumancanrock

Copy link
Copy Markdown
Collaborator

Description

First chunk of NIP-98 support. Adds a standalone verifier for Authorization: Nostr <base64-event> headers.

  • verifyNip98Auth() in src/utils/nip98.ts
  • checks kind 27235, timestamp skew, exact u/method, optional body payload hash, then id + sig
  • oversized headers get rejected early
  • also fixed a small sinon redeclare in info.spec.ts that was breaking the full unit suite

Middleware / admin API wiring comes next.

Related Issue

Part of NIP-98 admin auth work.

Motivation and Context

Need a solid crypto check we can drop into middleware later. Keeping it as a pure util makes this easy to review on its own.

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

@changeset-bot

changeset-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a569fcc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coveralls

coveralls commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 70.186% (+0.4%) from 69.776% — Anshumancanrock:feat/nip98-verifier into cameri:main

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds foundational NIP-98 support by introducing a standalone utility to verify Authorization: Nostr <base64-event> headers (kind 27235) and accompanying unit tests, plus a small unit test import cleanup.

Changes:

  • Added verifyNip98Auth() + helpers to parse and validate NIP-98 auth headers (kind, skew window, payload binding, event id + signature).
  • Added a comprehensive unit test suite for NIP-98 verification behavior.
  • Updated info.spec.ts to use ES module imports (fixing the sinon redeclare issue) and extended constants for NIP-98 kind/tags.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/nip98.ts New NIP-98 Authorization header verification utility.
src/constants/base.ts Adds NIP-98 HTTP_AUTH kind and u/method/payload tag constants.
test/unit/utils/nip98.spec.ts New unit tests covering NIP-98 parsing/validation edge cases.
test/unit/cli/info.spec.ts Switches to ESM imports and reformats a stub to fix test suite issues.
.knip.json Updates Knip ignore configuration for the new util file.
.changeset/nip98-auth-verifier.md Adds a changeset entry for the new feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/utils/nip98.ts Outdated
Comment thread src/utils/nip98.ts
Comment on lines +174 to +193
if (body === undefined || policy === 'ignore') {
return undefined
}

const expectedPayload = hashNip98Payload(body)
const hasBody = bodyByteLength(body) > 0

if (policy === 'require-when-body' && hasBody && payloadTag === undefined) {
return fail('invalid: missing payload tag')
}

if (payloadTag === undefined) {
return undefined
}

if (!isHexEqual(payloadTag.toLowerCase(), expectedPayload)) {
return fail('invalid: payload tag does not match request body')
}

return undefined
Comment thread .knip.json
Comment on lines 16 to 19
"ignore": [
".nostr/**"
".nostr/**",
"src/utils/nip98.ts"
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants