Documentation
¶
Overview ¶
Package auth verifies Nostr request proofs without deciding host access. It supports NIP-98 HTTP request proofs, NIP-42 relay challenges, BUD-11 Blossom authorization and GRASP-08 repository proofs. Successful proof verification identifies a signer; callers must separately authorize that signer and apply resource, tenant, storage and hosting policy.
Construct validators and challenge managers with their constructors. A nil clock uses time.Now. Their replay and challenge stores are in memory and scoped to each instance; reuse an instance across requests that share a replay boundary. The stores are protected for concurrent use. They do not persist across restarts or coordinate across processes.
NIP-98 proofs are single-use within the one-minute replay window. Their URL binding preserves path escaping, port and query while ignoring scheme and hostname case. Methods compare case-insensitively. A nonempty body requires the matching payload hash. NIP-42 challenges are single-use and expire after one minute; relay URLs match exactly. Blossom proofs are reusable until their expiration and cannot be issued in the future. GRASP-08 GET proofs are reusable for supported Smart HTTP requests beneath the signed repository root, within the existing one-minute timestamp skew. Unlike NIP-98, GRASP-08 requires an uppercase GET method and returns a uniform authentication error.
Payload validation after streaming does not consume the proof again. It must follow request authentication and does not replace host authorization.
Index ¶
- Variables
- func GRASP08RepositoryRoot(raw string) (string, bool)
- func IsBlossomAuthorization(header string) bool
- type ChallengeManager
- type Session
- type Validator
- func (v *Validator) ValidateBlobPayload(header, actualSHA string) error
- func (v *Validator) ValidateBlossomPayload(header, action, actualSHA string) error
- func (v *Validator) VerifyBlossom(header, action string) (nostr.Event, error)
- func (v *Validator) VerifyBlossomRequest(header, action, server, blobHash string) (nostr.Event, error)
- func (v *Validator) VerifyGRASP08(header, rawURL string) (nostr.Event, error)
- func (v *Validator) VerifyNIP98(header, rawURL, method, body string) (nostr.Event, error)
- func (v *Validator) VerifyNIP98Deferred(header, rawURL, method string) (nostr.Event, error)
- func (v *Validator) WhoAsks(header, rawURL, method, body, action, blobHash string) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
ErrGRASP08Unauthorized is the detail-free GRASP-08 authentication error returned for every failed repository proof.
var ErrMissingAuthorization = errors.New("auth-required: missing Nostr Authorization header")
Functions ¶
func GRASP08RepositoryRoot ¶
GRASP08RepositoryRoot returns the canonical repository URL for a supported Smart HTTP request beneath a .git path.
func IsBlossomAuthorization ¶
IsBlossomAuthorization reports whether an Authorization header contains a signed BUD-11 event. Malformed tokens return false so callers can produce their normal authentication error through the protocol-specific verifier.
Types ¶
type ChallengeManager ¶
type ChallengeManager struct {
// contains filtered or unexported fields
}
func NewChallengeManager ¶
func NewChallengeManager(relayURL string, now func() time.Time) *ChallengeManager
NewChallengeManager creates a NIP-42 challenge store for relayURL. Issued challenges are single-use and expire with the validator replay window.
func (*ChallengeManager) Issue ¶
func (m *ChallengeManager) Issue() (string, error)
Issue creates and stores a cryptographically random NIP-42 challenge.
type Session ¶
Session carries the principals authenticated on a relay connection and the relay identity against which their proofs were checked. RemoteIP is supplied by the serving transport, not by signed event content.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶
NewValidator uses now to check proof freshness and track replay windows. A nil clock selects the system clock.
func (*Validator) ValidateBlobPayload ¶
ValidateBlobPayload checks the hash binding on a token that was already authenticated by WhoAsks. It deliberately does not mark the event as seen a second time: upload authorization and the streamed body validator inspect the same proof at two different points in the request.
func (*Validator) ValidateBlossomPayload ¶
ValidateBlossomPayload rechecks the content hash for a Blossom-authenticated operation after a streaming body has been materialized. It does not mark the authorization event as seen a second time.
func (*Validator) VerifyBlossom ¶
VerifyBlossom validates a BUD-11 authorization for action. It accepts the protocol's reusable authorization form and checks its action and expiry.
func (*Validator) VerifyBlossomRequest ¶
func (v *Validator) VerifyBlossomRequest(header, action, server, blobHash string) (nostr.Event, error)
VerifyBlossomRequest validates a BUD-11 authorization with optional server and blob-hash scope. Upload, delete, mirror and media actions require an x tag when this scoped form is used.
func (*Validator) VerifyGRASP08 ¶
VerifyGRASP08 validates a reusable kind 27235 GET proof for the repository root named by a GRASP-08 Smart HTTP request. The proof remains valid for one minute across the repository's supported Git requests.
func (*Validator) VerifyNIP98 ¶
VerifyNIP98 validates a kind 27235 request proof against the exact URL, method and body supplied by the caller. A payload tag must match even when the body is empty. Successfully verified event IDs are retained for the one-minute replay window.
func (*Validator) VerifyNIP98Deferred ¶
VerifyNIP98Deferred authenticates a proof before a streamed body is read. Callers must check the payload tag against the resulting content hash before accepting the body, such as with ValidateBlobPayload for uploads.