Skip to content

feat(swa): add proof-of-work mining and feed difficulty filter#68

Merged
github-actions[bot] merged 1 commit into
devfrom
feature/proof-of-work
Jun 18, 2026
Merged

feat(swa): add proof-of-work mining and feed difficulty filter#68
github-actions[bot] merged 1 commit into
devfrom
feature/proof-of-work

Conversation

@Ryback2501

Copy link
Copy Markdown
Owner

Summary

  • Implement NIP-13 proof of work on both the produce and consume sides: outgoing notes can mine a nonce tag to a chosen target difficulty, and the feed shows and can filter by committed difficulty.

Changes

Proof of work core (swa/)

  • proofOfWork.js — new module: countLeadingZeroBits (leading-zero-bit difficulty of an id), getEventDifficulty (difficulty of an event), and mineProofOfWork (increments a nonce tag until the id meets a target difficulty). Pure functions, reusing serializeEvent/getEventId.
  • proofOfWork.test.js — unit tests incl. the NIP-13 worked example (36 bits), base-tag preservation, and that mined ids meet the target.

Signing (swa/, browser/)

  • nostr.js (both copies) — createEvent now accepts an optional createdAt, so a mined id is reproducible through signing instead of being regenerated.
  • signer.jsLocalSigner.signEvent forwards draft.created_at, making it consistent with the extension path (which already honored it).
  • Tests added for the reproducible-createdAt behavior in nostr.test.js and signer.test.js.

UI wiring (swa/)

  • app.jscreateOwnEvent mines the nonce before signing when difficulty > 0 (works for both signers); post/reply/quote pass the configured difficulty; a "min PoW" feed filter toggles card visibility (preserving the 1:1 card/event render invariant).
  • store.jspostDifficulty preference persisted in localStorage (default 0 = off).
  • feedView.js — renders a ⛏ PoW badge and stamps data-pow on each card.
  • index.html / style.css — proof-of-work selector in the compose panel and a min-difficulty selector in the feed filters.

Test plan

  • Set "Proof of work" to 8 bits, post a note; confirm "Mining proof of work…" then the note publishes and shows a ⛏ 8+ badge.
  • Reply and quote with PoW enabled; confirm both carry a nonce and a badge.
  • With PoW off, posting works unchanged and no badge shows.
  • Set the feed "min PoW" filter to ≥ 8 bits; confirm low-PoW notes are hidden and clearing the filter restores them.
  • Reload the page; confirm the compose difficulty selection persists.
  • Verify with a signing extension (NIP-07): a mined note still signs and verifies.

@github-actions github-actions Bot merged commit 85f9459 into dev Jun 18, 2026
10 checks passed
@github-actions github-actions Bot deleted the feature/proof-of-work branch June 18, 2026 12:09
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.

1 participant