package policy import ( "git.smesh.lol/orly/pkg/nostr/encoders/event" "git.smesh.lol/orly/pkg/nostr/encoders/kind" ) // CheckMusiquayWrite enforces the musiquay rule that private artifacts never // appear as plain events. // // Purchase orders (3222), entitlement deeds (3223), and delivery receipts // (32218) are only ever carried inside a NIP-59 kind 1059 gift wrap. The relay // sees the wrap; it must never see the payload. A public event of one of those // kinds is refused. Every other musiquay kind is accepted here and remains // subject to the operator's ordinary policy. // // It returns allowed=true for kinds it does not own, so it can be called from a // generic pipeline without suppressing unrelated events. func CheckMusiquayWrite(ev *event.E) (allowed bool, reason string) { if ev == nil { return false, "nil event" } if kind.IsMusiquayPrivate(ev.Kind) { return false, "musiquay private kind must travel inside a NIP-59 gift wrap" } return true, "" } // MusiquayWhitelist returns the kind numbers an operator must add to a kind // whitelist to accept the musiquay block. Gift wrap is included because it is // the transport for orders, deeds, and receipts. func MusiquayWhitelist() []int { out := make([]int, 0, len(kind.MusiquayAll)+1) for _, k := range kind.MusiquayAll { out = append(out, k.ToInt()) } out = append(out, kind.GiftWrap.ToInt()) return out } // MusiquayWrapRecipientOnly reports whether a kind's read access is restricted // to the keys named in its p tags regardless of the server's global auth // configuration. Gift wraps always are: a wrap is addressed to one recipient // and serving it to anyone else leaks the artifact. func MusiquayWrapRecipientOnly(k uint16) bool { return k == kind.GiftWrap.ToU16() } // NIP-32 label namespaces used by musiquay. const ( // LabelKind is the NIP-32 label event kind. LabelKind = 1985 // RevocationNamespace labels a revoked deed. RevocationNamespace = "musiquay.revocation" // RevocationLabel is the revocation label value. RevocationLabel = "revoked" // AttestNamespace labels scene attestations. AttestNamespace = "musiquay.attest" // CreditNamespace labels credit confirmations. CreditNamespace = "musiquay.credit" ) // HasNIP32Label reports whether an event carries a NIP-32 namespace and value. // A host uses it to read revocation, credit, and attestation labels without // trusting an event kind alone. func HasNIP32Label(ev *event.E, namespace, value string) bool { if ev == nil || ev.Tags == nil { return false } okNamespace := false for _, t := range ev.Tags.GetAll([]byte("L")) { if string(t.Value()) == namespace { okNamespace = true break } } if !okNamespace { return false } for _, t := range ev.Tags.GetAll([]byte("l")) { if string(t.Value()) != value { continue } if len(t.T) >= 3 && string(t.T[2]) != namespace { continue } return true } return false }