Skip to content

feat: add name field to npubs#2

Open
sh1ftred wants to merge 1 commit into
cloudronfrom
feat/npub-names
Open

feat: add name field to npubs#2
sh1ftred wants to merge 1 commit into
cloudronfrom
feat/npub-names

Conversation

@sh1ftred

@sh1ftred sh1ftred commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional name field to registered npubs, allowing admins to assign human-readable labels to npub entries. This works the same way as the existing role field — set it at creation time, update it later.

Changes

  • DB schema: New nullable name column on routstr_auth_npubs table, auto-migrated from older DBs via ALTER TABLE ADD COLUMN
  • NpubEntry interface: Added name: string | null
  • AuthStore.addNpub(): Accepts optional name parameter
  • AuthStore.updateNpubName(): New method (mirrors updateNpubRole())
  • POST /npubs: Accepts optional "name" field in the body
  • PATCH /npubs: Now accepts "role" and/or "name" (at least one required, admin-only)
  • GET /npubs: Includes name in the response
  • Validation: name must be a string or null; passing anything else returns a 400 error

API Usage for External Clients

Set a name when adding an npub

curl -X POST http://localhost:8008/npubs \
  -H "Authorization: Nostr <base64-event>" \
  -H "Content-Type: application/json" \
  -d '{"npub": "npub1...", "role": "user", "name": "Alice"}'

Update an npub's name (admin only)

Just like updating a role, use PATCH /npubs with NIP-98 admin auth:

# Update name only
curl -X PATCH http://localhost:8008/npubs \
  -H "Authorization: Nostr <base64-event>" \
  -H "Content-Type: application/json" \
  -d '{"npub": "npub1...", "name": "Bob"}'

# Update both role and name in a single request
curl -X PATCH http://localhost:8008/npubs \
  -H "Authorization: Nostr <base64-event>" \
  -H "Content-Type: application/json" \
  -d '{"npub": "npub1...", "role": "admin", "name": "Bob"}'

# Clear a name by setting it to null
curl -X PATCH http://localhost:8008/npubs \
  -H "Authorization: Nostr <base64-event>" \
  -H "Content-Type: application/json" \
  -d '{"npub": "npub1...", "name": null}'

List npubs with names

curl http://localhost:8008/npubs
# => { "npubs": [{ "npub": "npub1...", "name": "Alice", "role": "admin" }, ...] }

Backward Compatibility

  • Existing DBs are auto-migrated; the name column is added on first run
  • The name field is optional in all request bodies (defaults to null)
  • The PATCH /npubs endpoint previously required role; now it requires at least one of role or name

- Add nullable 'name' column to routstr_auth_npubs table
- Auto-migrate existing DBs with ALTER TABLE ADD COLUMN
- Accept 'name' in POST /npubs (add) and PATCH /npubs (update)
- PATCH /npubs now accepts 'role' and/or 'name' (at least one required)
- name can be set to null to clear it
- Only admins can update names (same as roles)
- Include 'name' in GET /npubs, POST /npubs, and PATCH /npubs responses
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