auth

package
v0.0.0-...-9268282 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var ErrGRASP08Unauthorized = errors.New("auth-required:")

ErrGRASP08Unauthorized is the detail-free GRASP-08 authentication error returned for every failed repository proof.

View Source
var ErrMissingAuthorization = errors.New("auth-required: missing Nostr Authorization header")

Functions

func GRASP08RepositoryRoot

func GRASP08RepositoryRoot(raw string) (string, bool)

GRASP08RepositoryRoot returns the canonical repository URL for a supported Smart HTTP request beneath a .git path.

func IsBlossomAuthorization

func IsBlossomAuthorization(header string) bool

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.

func (*ChallengeManager) Verify

func (m *ChallengeManager) Verify(e nostr.Event) error

Verify validates and consumes a NIP-42 AUTH event for the configured relay.

type Session

type Session struct {
	PubKeys  []string
	RelayURL string
	RemoteIP string
}

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

func NewValidator(now func() time.Time) *Validator

NewValidator uses now to check proof freshness and track replay windows. A nil clock selects the system clock.

func (*Validator) ValidateBlobPayload

func (v *Validator) ValidateBlobPayload(header, actualSHA string) error

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

func (v *Validator) ValidateBlossomPayload(header, action, actualSHA string) error

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

func (v *Validator) VerifyBlossom(header, action string) (nostr.Event, error)

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

func (v *Validator) VerifyGRASP08(header, rawURL string) (nostr.Event, error)

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

func (v *Validator) VerifyNIP98(header, rawURL, method, body string) (nostr.Event, error)

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

func (v *Validator) VerifyNIP98Deferred(header, rawURL, method string) (nostr.Event, error)

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.

func (*Validator) WhoAsks

func (v *Validator) WhoAsks(header, rawURL, method, body, action, blobHash string) ([]string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL