{"modulePath":"github.com/FelineStateMachine/tinyrelay","version":"v0.0.0-20260923223823-92682824e566","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package auth\n\nPackage 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.\n\nConstruct 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.\n\nNIP-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.\n\nPayload validation after streaming does not consume the proof again. It must follow request authentication and does not replace host authorization.\n\n## Variables\n\n```go\nvar ErrGRASP08Unauthorized = errors.New(\"auth-required:\")\n```\nErrGRASP08Unauthorized is the detail-free GRASP-08 authentication error returned for every failed repository proof.\n\n```go\nvar ErrMissingAuthorization = errors.New(\"auth-required: missing Nostr Authorization header\")\n```\n\n## Functions\n\n```go\nfunc GRASP08RepositoryRoot(raw string) (string, bool)\n```\nGRASP08RepositoryRoot returns the canonical repository URL for a supported Smart HTTP request beneath a .git path.\n\n```go\nfunc IsBlossomAuthorization(header string) bool\n```\nIsBlossomAuthorization 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.\n\n## Types\n\n```go\ntype ChallengeManager struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewChallengeManager(relayURL string, now func() time.Time) *ChallengeManager\n```\nNewChallengeManager creates a NIP-42 challenge store for relayURL. Issued challenges are single-use and expire with the validator replay window.\n\n```go\nfunc (m *ChallengeManager) Issue() (string, error)\n```\nIssue creates and stores a cryptographically random NIP-42 challenge.\n\n```go\nfunc (m *ChallengeManager) Verify(e nostr.Event) error\n```\nVerify validates and consumes a NIP-42 AUTH event for the configured relay.\n\n```go\ntype Session struct {\n\tPubKeys  []string\n\tRelayURL string\n\tRemoteIP string\n}\n```\nSession 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.\n\n```go\ntype Validator struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewValidator(now func() time.Time) *Validator\n```\nNewValidator uses now to check proof freshness and track replay windows. A nil clock selects the system clock.\n\n```go\nfunc (v *Validator) ValidateBlobPayload(header, actualSHA string) error\n```\nValidateBlobPayload 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.\n\n```go\nfunc (v *Validator) ValidateBlossomPayload(header, action, actualSHA string) error\n```\nValidateBlossomPayload 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.\n\n```go\nfunc (v *Validator) VerifyBlossom(header, action string) (nostr.Event, error)\n```\nVerifyBlossom validates a BUD-11 authorization for action. It accepts the protocol's reusable authorization form and checks its action and expiry.\n\n```go\nfunc (v *Validator) VerifyBlossomRequest(header, action, server, blobHash string) (nostr.Event, error)\n```\nVerifyBlossomRequest 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.\n\n```go\nfunc (v *Validator) VerifyGRASP08(header, rawURL string) (nostr.Event, error)\n```\nVerifyGRASP08 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.\n\n```go\nfunc (v *Validator) VerifyNIP98(header, rawURL, method, body string) (nostr.Event, error)\n```\nVerifyNIP98 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.\n\n```go\nfunc (v *Validator) VerifyNIP98Deferred(header, rawURL, method string) (nostr.Event, error)\n```\nVerifyNIP98Deferred 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.\n\n```go\nfunc (v *Validator) WhoAsks(header, rawURL, method, body, action, blobHash string) ([]string, error)\n```\n\n","path":"github.com/FelineStateMachine/tinyrelay/protocol/auth","name":"auth","synopsis":"Package auth verifies Nostr request proofs without deciding host access.","isRedistributable":true}
