Skip to content

fix(admin): accept and decode NIP-19 npub in moderation pubkey actions - #1364

Merged
cameri merged 1 commit into
cameri:rewrite/mainfrom
tirthraj01:fix/1321-moderation-npub
Dec 3, 2026
Merged

cameri merged 1 commit into
cameri:rewrite/mainfrom
tirthraj01:fix/1321-moderation-npub

Conversation

@tirthraj01

Copy link
Copy Markdown
Collaborator

Fixes #1321

Summary

  • Add normalize_pubkey in crates/nostream-admin/src/utils/moderation.rs to trim whitespace, lowercase valid 64-character hex pubkeys, and decode npub1… bech32 strings via nostream_core::nip19::decode_npub_hex instead of rejecting valid npub inputs with 400.
  • Wire require_pubkey (ban-pubkey, unban-pubkey, whitelist-pubkey, unwhitelist-pubkey) and normalize (PATCH /admin/moderation/limits) to normalize_pubkey, keeping PUBKEY_REQUIRED ("pubkey is required and must be a 64-character hex pubkey or npub") aligned with the UI label/prompt.
  • Add unit tests in crates/nostream-admin/src/utils/moderation.rs and integration tests in crates/nostream-admin/tests/write_path.rs covering:
    • POST /admin/moderation/actions banning a valid npub1… and persisting its lowercase hex pubkey
    • asserting /admin/ (Pubkey or npub, hex or npub), /admin/assets/admin-moderation.js (Enter a pubkey or npub to ban.), and the 400 refusal response match the accepted forms.

Verification

  • cargo fmt --all --check
  • cargo clippy -p nostream-admin --all-targets --all-features -- -D warnings
  • cargo clippy -p nostream-admin --lib --bins --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used -D clippy::todo -D clippy::unimplemented -D clippy::panic
  • cargo test -p nostream-admin --all-features

@changeset-bot

changeset-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b8d4f6

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3beb8c45-fe54-4bef-8037-d0b92a44ef01

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] This PR appears safe to merge.

Summary

Moderation actions and limits updates now accept NIP-19 npub values alongside hex pubkeys.

  • Admin moderation accepts npub keys and stores them as lowercase hex.

Reviews (1) · Last reviewed commit: "fix(admin): accept and decode NIP-19 npu..." · Reviewed by Greptile

@cameri
cameri merged commit 8326c10 into cameri:rewrite/main Dec 3, 2026
19 checks passed
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.

2 participants