Skip to main content

nostr_bbs_core/
lib.rs

1//! Shared Nostr protocol primitives for the nostr-bbs forum.
2//!
3//! This crate provides the cryptographic and protocol building blocks shared
4//! between the WASM client bridge and the Rust Cloudflare Workers. It covers:
5//!
6//! - **NIP-01** event creation, signing, and verification
7//! - **NIP-44** encrypted direct messages (ChaCha20-Poly1305)
8//! - **NIP-98** HTTP auth token creation and verification
9//! - **DID:nostr** document generation (delegates to `solid_pod_rs::did_nostr_types`)
10//! - **Key management** including HKDF derivation from WebAuthn PRF output
11//! - **Value types** (`EventId`, `Timestamp`, `Tag`, etc.)
12
13pub mod calendar;
14pub mod deletion;
15pub mod event;
16pub mod gift_wrap;
17pub mod groups;
18pub mod keys;
19pub mod moderation_events;
20pub mod nip04;
21pub mod nip19;
22pub mod nip26;
23pub mod nip44;
24pub mod nip90;
25pub mod nip98;
26pub mod signer;
27pub mod types;
28
29pub mod d1_helpers;
30pub mod did;
31pub mod governance;
32#[cfg(target_arch = "wasm32")]
33pub mod wasm_bridge;
34
35// ── Re-exports for ergonomic top-level use ─────────────────────────────────
36
37pub use event::{
38    compute_event_id, sign_event, sign_event_deterministic, sign_event_upstream,
39    signing_key_to_upstream, verify_event, verify_event_strict, verify_events_batch, EventError,
40    NostrEvent, PubkeyMismatch, UnsignedEvent,
41};
42pub use gift_wrap::{gift_wrap, unwrap_gift, GiftWrapError, UnwrappedGift};
43pub use keys::{derive_from_prf, generate_keypair, Keypair, PublicKey, SecretKey, Signature};
44pub use nip44::{decrypt as nip44_decrypt, encrypt as nip44_encrypt};
45pub use nip98::{
46    authorization_header as nip98_authorization_header,
47    create_token as create_nip98_token,
48    sign_request_header as nip98_sign_request_header,
49    // Canonical verification entry point (new — preferred for all new code)
50    verify_nip98,
51    verify_nip98_with_replay,
52    // Legacy aliases (backward-compatible, delegate to verify_token_full internally)
53    verify_token as verify_nip98_token,
54    verify_token_at as verify_nip98_token_at,
55    verify_token_at_with_replay as verify_nip98_token_at_with_replay,
56    verify_token_full as verify_nip98_token_full,
57    Nip98Error,
58    Nip98ReplayStore,
59    Nip98Token as VerifiedToken,
60    REPLAY_CACHE_TTL_SECS,
61    TIMESTAMP_TOLERANCE as NIP98_TIMESTAMP_TOLERANCE,
62};
63pub use types::{EventId, Tag, Timestamp};
64
65pub use calendar::{create_calendar_event, create_rsvp, CalendarError, RsvpStatus};
66
67pub use moderation_events::{
68    build_ban, build_moderation_action, build_mute, build_report, build_unban, build_unmute,
69    build_warning, d_tag_of, mute_expires_at, validate_moderation_event, ModerationEventError,
70    ADMIN_ONLY_MOD_KINDS, KIND_BAN, KIND_MODERATION_ACTION, KIND_MUTE, KIND_REPORT,
71    KIND_REPORT_NIP56, KIND_UNBAN, KIND_UNMUTE, KIND_WARNING, MOD_KINDS,
72};
73
74pub use did::{
75    did_nostr_uri, format_multibase_schnorr, is_valid_hex_pubkey, render_did_document_tier1,
76    render_did_document_tier3, verify_webid_tag, well_known_path, NostrPubkey,
77};
78pub use nip04::{nip04_decrypt, nip04_encrypt, nip04_shared_secret, Nip04Error};
79pub use nip19::{
80    decode_naddr, decode_nevent, decode_note, decode_nprofile, decode_npub, decode_nsec,
81    encode_naddr, encode_nevent, encode_note, encode_nprofile, encode_npub, encode_nsec, NAddr,
82    NEvent, NProfile, Nip19Error,
83};
84pub use nip26::{validate_delegation_tag, Conditions, DelegationTag, DelegationToken, Nip26Error};
85pub use nip90::{
86    is_job_request, is_job_result, parse_job_inputs, DvmCapabilityAd, DvmJobFeedback,
87    DvmJobRequest, DvmJobResult, JobInput, JobStatus, Nip90Error, KIND_HANDLER_INFO,
88    KIND_JOB_FEEDBACK, KIND_JOB_REQUEST_MAX, KIND_JOB_REQUEST_MIN, KIND_JOB_RESULT_MAX,
89    KIND_JOB_RESULT_MIN,
90};
91pub use signer::{PrfSigner, Signer, SignerError};
92
93pub use governance::{
94    extract_d_tag, extract_tag, is_governance_kind, ActionDef, ActionPriority, ActionRequest,
95    ActionResponse, ActionStyle, FieldDef, FieldType, LayoutHint, PanelCapability, PanelDefinition,
96    PanelSchema, RegisteredAgent, GOVERNANCE_KIND_RANGE, KIND_ACTION_REQUEST, KIND_ACTION_RESPONSE,
97    KIND_PANEL_DEFINITION, KIND_PANEL_RETIRED, KIND_PANEL_STATE, KIND_PANEL_UPDATE,
98};