Skip to content

feat: NIP-03 opentimestamps support (#105)#515

Merged
cameri merged 9 commits intocameri:mainfrom
archief2910:feature/105-NIP-03-opentimestamps-support
Apr 19, 2026
Merged

feat: NIP-03 opentimestamps support (#105)#515
cameri merged 9 commits intocameri:mainfrom
archief2910:feature/105-NIP-03-opentimestamps-support

Conversation

@archief2910
Copy link
Copy Markdown
Contributor

Description

This PR adds NIP-03 support: kind 1040 events that carry a base64-encoded OpenTimestamps (.ots) proof for another event.

  • src/utils/nip03.ts — Structural parser and validator for binary .ots files: magic header, version, hash op, file digest, commitment tree, and attestation classification. Enforces SHA-256 file digest, digest equals the e-tagged event id (hex), and at least one Bitcoin block-header attestation. Does not verify against the Bitcoin chain (clients use ots verify / Esplora as in the NIP).
  • TimestampEventStrategy — Handles kind 1040: requires exactly one e tag (valid 64-char hex id), optional well-formed k tag, then runs validateOtsProof on content.
  • eventStrategyFactory — Dispatches kind 1040 to TimestampEventStrategy (alongside existing strategies).
  • EventKinds.OPEN_TIMESTAMPS and EventTags.Kind in src/constants/base.ts; isOpenTimestampsEvent in src/utils/event.ts.
  • package.json supportedNips and README.md features list updated to include NIP-03.

Related Issue

Closes #105

Motivation and Context

Issue #105 asks for NIP-03 so relays can accept and store OpenTimestamps attestations in a way that is not misleading: invalid proofs (wrong digest, no Bitcoin attestation, corrupt .ots) are rejected before persistence, while full blockchain verification remains a client concern per the NIP.

How Has This Been Tested?

  • Environment: Node as in package.json engines, Windows (local); CI should run Linux.
  • Commands run:
    • npm run build:check
    • npm run lint
    • npm run knip
    • npm run test:unit (full suite)
  • New tests: test/unit/utils/nip03.spec.ts (parser + validateOtsProof), test/unit/handlers/event-strategies/timestamp-event-strategy.spec.ts (strategy), extended test/unit/factories/event-strategy-factory.spec.ts.

Screenshots (if appropriate):

N/A

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.

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 18, 2026

Coverage Status

coverage: 70.415% (+2.1%) from 68.308% — archief2910:feature/105-NIP-03-opentimestamps-support into cameri:main

@archief2910
Copy link
Copy Markdown
Contributor Author

hi @cameri , can you review it once i have implemented the nip-03 through this pr.

@cameri cameri self-assigned this Apr 19, 2026
@cameri cameri requested a review from Copilot April 19, 2026 02:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds relay-side support for NIP-03 OpenTimestamps attestations by introducing structural .ots proof parsing/validation and a new event strategy for kind 1040, plus unit/integration coverage and metadata/docs updates.

Changes:

  • Add src/utils/nip03.ts to parse .ots binaries and validate base64-encoded proofs (sha256 digest match + bitcoin attestation requirement).
  • Add TimestampEventStrategy for kind 1040 and dispatch it from eventStrategyFactory.
  • Update constants/metadata (EventKinds.OPEN_TIMESTAMPS, EventTags.Kind, supportedNips, README) and add tests (unit + cucumber integration).

Reviewed changes

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

Show a summary per file
File Description
src/utils/nip03.ts New OpenTimestamps .ots parser + validateOtsProof utility used by kind-1040 validation.
src/handlers/event-strategies/timestamp-event-strategy.ts New strategy enforcing NIP-03 tag requirements and proof validation before persistence.
src/factories/event-strategy-factory.ts Routes kind 1040 events to TimestampEventStrategy.
src/utils/event.ts Adds isOpenTimestampsEvent kind predicate used by the factory.
src/constants/base.ts Adds EventKinds.OPEN_TIMESTAMPS and EventTags.Kind.
test/unit/utils/nip03.spec.ts Unit tests for .ots parsing and proof validation.
test/unit/handlers/event-strategies/timestamp-event-strategy.spec.ts Unit tests for strategy acceptance/rejection behavior.
test/unit/factories/event-strategy-factory.spec.ts Ensures factory returns TimestampEventStrategy for kind 1040.
test/integration/features/nip-03/nip-03.feature.ts Cucumber steps to publish/subscribe to NIP-03 events end-to-end.
test/integration/features/nip-03/nip-03.feature Feature scenarios for valid and mismatching-digest attestations.
package.json Adds NIP-03 to supportedNips.
README.md Documents NIP-03 support in the features list.
.changeset/nip-03-opentimestamps.md Changeset for the new feature release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/handlers/event-strategies/timestamp-event-strategy.ts
Comment thread src/handlers/event-strategies/timestamp-event-strategy.ts Outdated
Comment thread src/utils/nip03.ts
@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 19, 2026

were you able to test it with a client that supports OTS?

@archief2910
Copy link
Copy Markdown
Contributor Author

yes i was able to test it with the client that supports ots . it worked i will update them in a bit.

@archief2910
Copy link
Copy Markdown
Contributor Author

archief2910 commented Apr 19, 2026

the environment in which i ran was with relay in docker and my ots tool was opentimestamps-client on the path.we grab a real kind 1040 from the public relay , run ots on the proof to show it’s a real timestamp file, then my local nostream accepts and returns that same NIP-03-shaped event.

@archief2910 archief2910 changed the title feat: nip 03 opentimestamps support (#105) feat: NIP-03 opentimestamps support (#105) Apr 19, 2026
Comment thread scripts/smoke-nip03.ts
@@ -0,0 +1,459 @@
#!/usr/bin/env node
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's migrate this to TypeScript

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@cameri cameri merged commit 5c12f36 into cameri:main Apr 19, 2026
13 checks passed
@archief2910 archief2910 deleted the feature/105-NIP-03-opentimestamps-support branch April 19, 2026 14:41
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.

Support NIP-03 Open Timestamps

4 participants