Documentation
¶
Index ¶
- Variables
- func IsPartyInvolved(ev *event.E, userPubkey []byte) bool
- func ValidateOwnerPolicy(policy *P) error
- func ValidatePolicyAdminContribution(ownerPolicy *P, contribution *PolicyAdminContribution, ...) error
- type AccessControl
- type ComposedPolicy
- type Constraints
- type Kinds
- type P
- func (p *P) CheckPolicy(access string, ev *event.E, loggedInPubkey []byte, ipAddress string) (allowed bool, err error)
- func (p *P) ConfigPath() string
- func (p *P) GetAllFollowsWhitelistAdmins() []string
- func (p *P) GetAllFollowsWhitelistPubkeys() []string
- func (p *P) GetAllReadFollowsWhitelistPubkeys() []string
- func (p *P) GetAllWriteFollowsWhitelistPubkeys() []string
- func (p *P) GetGlobalRule() *Rule
- func (p *P) GetOwners() []string
- func (p *P) GetOwnersBin() [][]byte
- func (p *P) GetPolicyAdminsBin() [][]byte
- func (p *P) GetRuleForKind(kind int) *Rule
- func (p *P) GetRulesKinds() []int
- func (p *P) IsEnabled() bool
- func (p *P) IsOwner(pubkey []byte) bool
- func (p *P) IsOwnerOrPolicyAdmin(pubkey []byte) bool
- func (p *P) IsPolicyAdmin(pubkey []byte) bool
- func (p *P) IsPolicyFollow(pubkey []byte) bool
- func (p *P) IsPolicyFollowWhitelistEnabled() bool
- func (p *P) LoadFromFile(configPath string) error
- func (p *P) Pause() error
- func (p *P) Reload(policyJSON []byte, configPath string) error
- func (p *P) ReloadAsOwner(policyJSON []byte, configPath string) error
- func (p *P) ReloadAsPolicyAdmin(policyJSON []byte, configPath string, adminPubkey []byte) error
- func (p *P) Resume() error
- func (p *P) SaveToFile(configPath string) error
- func (p *P) UnmarshalJSON(data []byte) error
- func (p *P) UpdateGlobalFollowsWhitelist(follows [][]byte)
- func (p *P) UpdateGlobalReadFollowsWhitelist(follows [][]byte)
- func (p *P) UpdateGlobalWriteFollowsWhitelist(follows [][]byte)
- func (p *P) UpdatePolicyFollows(follows [][]byte)
- func (p *P) UpdateRuleFollowsWhitelist(kind int, follows [][]byte)
- func (p *P) UpdateRuleReadFollowsWhitelist(kind int, follows [][]byte)
- func (p *P) UpdateRuleWriteFollowsWhitelist(kind int, follows [][]byte)
- func (p *P) ValidateJSON(policyJSON []byte) error
- func (p *P) ValidateOwnerPolicyUpdate(policyJSON []byte) error
- func (p *P) ValidatePolicyAdminUpdate(policyJSON []byte, adminPubkey []byte) error
- type PolicyAdminContribution
- type PolicyEvent
- type PolicyManager
- type PolicyResponse
- type Rule
- func (r *Rule) GetFollowsWhitelistAdminsBin() [][]byte
- func (r *Rule) GetReadFollowsWhitelistBin() [][]byte
- func (r *Rule) GetWriteFollowsWhitelistBin() [][]byte
- func (r *Rule) HasFollowsWhitelistAdmins() bool
- func (r *Rule) HasReadFollowsWhitelist() bool
- func (r *Rule) HasWriteFollowsWhitelist() bool
- func (r *Rule) IsInFollowsWhitelist(pubkey []byte) bool
- func (r *Rule) IsInReadFollowsWhitelist(pubkey []byte) bool
- func (r *Rule) IsInWriteFollowsWhitelist(pubkey []byte) bool
- func (r *Rule) UpdateFollowsWhitelist(follows [][]byte)
- func (r *Rule) UpdateReadFollowsWhitelist(follows [][]byte)
- func (r *Rule) UpdateWriteFollowsWhitelist(follows [][]byte)
- type RuleExtension
- type ScriptRunner
- type TagValidationConfig
Constants ¶
This section is empty.
Variables ¶
var ProtectedFields = []string{"owners", "policy_admins"}
ProtectedFields are fields that only owners can modify
Functions ¶
func IsPartyInvolved ¶ added in v0.29.9
IsPartyInvolved checks if the given pubkey is a party involved in the event. A party is involved if they are either: 1. The author of the event (ev.Pubkey == userPubkey) 2. Mentioned in a p-tag of the event
Both ev.Pubkey and userPubkey must be binary ([]byte), not hex-encoded. P-tags may be stored in either binary-optimized format (33 bytes) or hex format.
This is the single source of truth for "parties_involved" / "privileged" checks.
func ValidateOwnerPolicy ¶ added in v0.31.4
ValidateOwnerPolicy validates a policy update from an owner. Ensures owners list is non-empty.
func ValidatePolicyAdminContribution ¶ added in v0.31.4
func ValidatePolicyAdminContribution( ownerPolicy *P, contribution *PolicyAdminContribution, existingContributions map[string]*PolicyAdminContribution, ) error
ValidatePolicyAdminContribution validates a contribution from a policy admin. Ensures no protected fields are modified and extensions are valid.
Types ¶
type AccessControl ¶ added in v0.56.8
type AccessControl struct {
// WriteAllow is a list of pubkeys allowed to write. If any present, all others denied.
WriteAllow []string `json:"write_allow,omitempty"`
// WriteDeny is a list of pubkeys denied write. Only effective without WriteAllow.
WriteDeny []string `json:"write_deny,omitempty"`
// ReadAllow is a list of pubkeys allowed to read. If any present, all others denied.
ReadAllow []string `json:"read_allow,omitempty"`
// ReadDeny is a list of pubkeys denied read. Only effective without ReadAllow.
ReadDeny []string `json:"read_deny,omitempty"`
// WriteAllowFollows grants access to policy admin follows when enabled.
WriteAllowFollows bool `json:"write_allow_follows,omitempty"`
// FollowsWhitelistAdmins specifies admin pubkeys whose follows are whitelisted.
// DEPRECATED: Use ReadFollowsWhitelist and WriteFollowsWhitelist instead.
FollowsWhitelistAdmins []string `json:"follows_whitelist_admins,omitempty"`
// ReadFollowsWhitelist specifies pubkeys whose follows can READ events.
ReadFollowsWhitelist []string `json:"read_follows_whitelist,omitempty"`
// WriteFollowsWhitelist specifies pubkeys whose follows can WRITE events.
WriteFollowsWhitelist []string `json:"write_follows_whitelist,omitempty"`
// ReadAllowPermissive allows read access for ALL kinds on GLOBAL rule.
ReadAllowPermissive bool `json:"read_allow_permissive,omitempty"`
// WriteAllowPermissive allows write access bypassing kind whitelist on GLOBAL rule.
WriteAllowPermissive bool `json:"write_allow_permissive,omitempty"`
// contains filtered or unexported fields
}
AccessControl defines who can read/write events. This is a value object that encapsulates access control configuration.
type ComposedPolicy ¶ added in v0.31.4
type ComposedPolicy struct {
// OwnerPolicy is the base policy set by owners
OwnerPolicy *P
// Contributions is a map of event ID -> contribution for deduplication
Contributions map[string]*PolicyAdminContribution
// contains filtered or unexported fields
}
ComposedPolicy manages the base owner policy and policy admin contributions. It computes an effective merged policy at runtime.
func NewComposedPolicy ¶ added in v0.31.4
func NewComposedPolicy(ownerPolicy *P, configDir string) *ComposedPolicy
NewComposedPolicy creates a new composed policy from an owner policy.
func (*ComposedPolicy) AddContribution ¶ added in v0.31.4
func (cp *ComposedPolicy) AddContribution(contribution *PolicyAdminContribution) error
AddContribution adds a policy admin contribution. Returns error if validation fails.
func (*ComposedPolicy) GetEffectivePolicy ¶ added in v0.31.4
func (cp *ComposedPolicy) GetEffectivePolicy() *P
GetEffectivePolicy computes the merged effective policy. Composition rules: - Whitelists are unioned (OR) - Blacklists are unioned and override whitelists - Limits use the most permissive value - Conflicts between PAs: oldest created_at wins (except deny always wins)
func (*ComposedPolicy) LoadContributions ¶ added in v0.31.4
func (cp *ComposedPolicy) LoadContributions() error
LoadContributions loads all contributions from disk.
func (*ComposedPolicy) RemoveContribution ¶ added in v0.31.4
func (cp *ComposedPolicy) RemoveContribution(eventID string)
RemoveContribution removes a policy admin contribution by event ID.
type Constraints ¶ added in v0.56.8
type Constraints struct {
// MaxExpiry is the maximum expiry time in seconds.
// Deprecated: Use MaxExpiryDuration instead.
MaxExpiry *int64 `json:"max_expiry,omitempty"` //nolint:staticcheck
// MaxExpiryDuration is the max expiry in ISO-8601 duration format.
MaxExpiryDuration string `json:"max_expiry_duration,omitempty"`
// SizeLimit is the maximum total serialized size in bytes.
SizeLimit *int64 `json:"size_limit,omitempty"`
// ContentLimit is the maximum content field size in bytes.
ContentLimit *int64 `json:"content_limit,omitempty"`
// RateLimit is the write rate limit in bytes per second.
RateLimit *int64 `json:"rate_limit,omitempty"`
// MaxAgeOfEvent is the max age in seconds for created_at timestamps.
MaxAgeOfEvent *int64 `json:"max_age_of_event,omitempty"`
// MaxAgeEventInFuture is the max future offset for created_at timestamps.
MaxAgeEventInFuture *int64 `json:"max_age_event_in_future,omitempty"`
// ProtectedRequired requires events to have a "-" tag (NIP-70).
ProtectedRequired bool `json:"protected_required,omitempty"`
// Privileged means event is only sent to authenticated parties.
Privileged bool `json:"privileged,omitempty"`
// contains filtered or unexported fields
}
Constraints defines limits and restrictions on events. This is a value object that encapsulates event constraints.
type Kinds ¶
type Kinds struct {
// Whitelist is a list of event kinds that are allowed to be written to the relay. If any are present, implicitly all others are denied.
Whitelist []int `json:"whitelist,omitempty"`
// Blacklist is a list of event kinds that are not allowed to be written to the relay. If any are present, implicitly all others are allowed. Only takes effect in the absence of a Whitelist.
Blacklist []int `json:"blacklist,omitempty"`
}
Kinds defines whitelist and blacklist policies for event kinds. Whitelist takes precedence over blacklist - if whitelist is present, only whitelisted kinds are allowed. If only blacklist is present, all kinds except blacklisted ones are allowed.
type P ¶
type P struct {
// Kind is policies for accepting or rejecting events by kind number.
Kind Kinds `json:"kind"`
// Global is a rule set that applies to all events.
Global Rule `json:"global"`
// DefaultPolicy determines the default behavior when no rules deny an event ("allow" or "deny", defaults to "allow")
DefaultPolicy string `json:"default_policy"`
// PolicyAdmins is a list of hex-encoded pubkeys that can update policy configuration via kind 12345 events.
// These are SEPARATE from ACL relay admins - policy admins manage policy only.
PolicyAdmins []string `json:"policy_admins,omitempty"`
// PolicyFollowWhitelistEnabled enables automatic whitelisting of pubkeys followed by policy admins.
// When true and a rule has WriteAllowFollows=true, policy admin follows get read+write access.
PolicyFollowWhitelistEnabled bool `json:"policy_follow_whitelist_enabled,omitempty"`
// Owners is a list of hex-encoded pubkeys that have full control of the relay.
// These are merged with owners from the ORLY_OWNERS environment variable.
// Useful for cloud deployments where environment variables cannot be modified.
Owners []string `json:"owners,omitempty"`
// contains filtered or unexported fields
}
P represents a complete policy configuration for a Nostr relay. It defines access control rules, kind filtering, and default behavior. Policies are evaluated in order: global rules, kind filtering, specific rules, then default policy.
func New ¶
New creates a new policy from JSON configuration. If policyJSON is empty, returns a policy with default settings. The default_policy field defaults to "allow" if not specified. Returns an error if the policy JSON contains invalid values (e.g., invalid ISO-8601 duration format for max_expiry_duration, invalid regex patterns, etc.).
func NewWithManager ¶
NewWithManager creates a new policy with a policy manager for script execution. It initializes the policy manager, loads configuration from files, and starts background processes for script management and periodic health checks.
The customPolicyPath parameter allows overriding the default policy file location. If empty, uses the default path: $HOME/.config/{appName}/policy.json If provided, it MUST be an absolute path (starting with /) or the function will panic.
func (*P) CheckPolicy ¶
func (p *P) CheckPolicy( access string, ev *event.E, loggedInPubkey []byte, ipAddress string, ) (allowed bool, err error)
CheckPolicy checks if an event is allowed based on the policy configuration. The access parameter should be "write" for accepting events or "read" for filtering events. Returns true if the event is allowed, false if denied, and an error if validation fails.
Policy evaluation order (more specific rules take precedence): 1. Kinds whitelist/blacklist - if kind is blocked, deny immediately 2. Kind-specific rule - if exists for this kind, use it exclusively 3. Global rule - fallback if no kind-specific rule exists 4. Default policy - fallback if no rules apply
Thread-safety: Uses followsMx.RLock to protect reads of follows whitelists during policy checks. Write operations (Update*) acquire the write lock, which blocks concurrent reads.
func (*P) ConfigPath ¶ added in v0.35.3
ConfigPath returns the path to the policy configuration file. Delegates to the internal PolicyManager.
func (*P) GetAllFollowsWhitelistAdmins ¶ added in v0.31.2
GetAllFollowsWhitelistAdmins returns all unique admin pubkeys from FollowsWhitelistAdmins across all rules (including global). Returns hex-encoded pubkeys. This is used at startup to validate that kind 3 events exist for these admins.
func (*P) GetAllFollowsWhitelistPubkeys ¶ added in v0.32.4
GetAllFollowsWhitelistPubkeys returns all unique pubkeys from both ReadFollowsWhitelist and WriteFollowsWhitelist across all rules (including global). Returns hex-encoded pubkeys. This is a convenience method for startup validation to check all required kind 3 events.
func (*P) GetAllReadFollowsWhitelistPubkeys ¶ added in v0.32.4
GetAllReadFollowsWhitelistPubkeys returns all unique pubkeys from ReadFollowsWhitelist across all rules (including global). Returns hex-encoded pubkeys. This is used at startup to validate that kind 3 events exist for these pubkeys.
func (*P) GetAllWriteFollowsWhitelistPubkeys ¶ added in v0.32.4
GetAllWriteFollowsWhitelistPubkeys returns all unique pubkeys from WriteFollowsWhitelist across all rules (including global). Returns hex-encoded pubkeys. This is used at startup to validate that kind 3 events exist for these pubkeys.
func (*P) GetGlobalRule ¶ added in v0.31.2
GetGlobalRule returns a pointer to the global rule for modification.
func (*P) GetOwners ¶ added in v0.31.3
GetOwners returns the hex-encoded owner pubkeys defined in the policy. These are merged with environment-defined owners by the application layer.
func (*P) GetOwnersBin ¶ added in v0.31.3
GetOwnersBin returns a copy of the binary owner pubkeys defined in the policy. These are merged with environment-defined owners by the application layer. Useful for cloud deployments where environment variables cannot be modified.
func (*P) GetPolicyAdminsBin ¶ added in v0.31.1
GetPolicyAdminsBin returns a copy of the binary policy admin pubkeys. Used for checking if an event author is a policy admin.
func (*P) GetRuleForKind ¶ added in v0.31.2
GetRuleForKind returns the Rule for a specific kind, or nil if no rule exists. This allows external code to access and modify rule-specific follows whitelists.
func (*P) GetRulesKinds ¶ added in v0.31.2
GetRules returns the rules map for iteration. Note: Returns a copy of the map keys to prevent modification.
func (*P) IsEnabled ¶ added in v0.30.1
IsEnabled returns whether the policy system is enabled and ready to process events. This is the public API for checking if policy filtering should be applied.
func (*P) IsOwner ¶ added in v0.31.4
IsOwner checks if the given pubkey is an owner. The pubkey parameter should be binary ([]byte), not hex-encoded.
func (*P) IsOwnerOrPolicyAdmin ¶ added in v0.31.4
IsOwnerOrPolicyAdmin checks if the given pubkey is an owner or policy admin. The pubkey parameter should be binary ([]byte), not hex-encoded.
func (*P) IsPolicyAdmin ¶ added in v0.31.1
IsPolicyAdmin checks if the given pubkey is in the policy_admins list. The pubkey parameter should be binary ([]byte), not hex-encoded.
func (*P) IsPolicyFollow ¶ added in v0.31.1
IsPolicyFollow checks if the given pubkey is in the policy admin follows list. The pubkey parameter should be binary ([]byte), not hex-encoded.
func (*P) IsPolicyFollowWhitelistEnabled ¶ added in v0.31.1
IsPolicyFollowWhitelistEnabled returns whether the policy follow whitelist feature is enabled. When enabled, pubkeys followed by policy admins are automatically whitelisted for access when rules have WriteAllowFollows=true.
func (*P) LoadFromFile ¶
LoadFromFile loads policy configuration from a JSON file. Returns an error if the file doesn't exist, can't be read, or contains invalid JSON.
func (*P) Pause ¶ added in v0.31.1
Pause pauses the policy manager and stops all script runners.
func (*P) Reload ¶ added in v0.31.1
Reload loads policy from JSON bytes and applies it to the existing policy instance. This validates JSON FIRST, then pauses the policy manager, updates configuration, and resumes. Returns error if validation fails - no changes are made on validation failure.
func (*P) ReloadAsOwner ¶ added in v0.31.4
ReloadAsOwner reloads the policy from an owner's kind 12345 event. Owners can modify all fields but the owners list must be non-empty.
func (*P) ReloadAsPolicyAdmin ¶ added in v0.31.4
ReloadAsPolicyAdmin reloads the policy from a policy admin's kind 12345 event. Policy admins cannot modify protected fields (owners, policy_admins) and cannot reduce owner-granted permissions.
func (*P) Resume ¶ added in v0.31.1
Resume resumes the policy manager and restarts script runners.
func (*P) SaveToFile ¶ added in v0.31.1
SaveToFile persists the current policy configuration to disk using atomic write. Uses temp file + rename pattern to ensure atomic writes.
func (*P) UnmarshalJSON ¶ added in v0.30.1
UnmarshalJSON implements custom JSON unmarshalling to handle unexported fields.
func (*P) UpdateGlobalFollowsWhitelist ¶ added in v0.31.2
UpdateGlobalFollowsWhitelist updates the follows whitelist for the global rule. The follows should be binary pubkeys ([]byte), not hex-encoded. Note: We directly modify p.Global's unexported field because Global is a value type (not *Rule), so calling p.Global.UpdateFollowsWhitelist() would operate on a copy and discard changes. Thread-safe: uses followsMx to protect concurrent access.
func (*P) UpdateGlobalReadFollowsWhitelist ¶ added in v0.32.4
UpdateGlobalReadFollowsWhitelist updates the read follows whitelist for the global rule. The follows should be binary pubkeys ([]byte), not hex-encoded. Note: We directly modify p.Global's unexported field because Global is a value type (not *Rule), so calling p.Global.UpdateReadFollowsWhitelist() would operate on a copy and discard changes. Thread-safe: uses followsMx to protect concurrent access.
func (*P) UpdateGlobalWriteFollowsWhitelist ¶ added in v0.32.4
UpdateGlobalWriteFollowsWhitelist updates the write follows whitelist for the global rule. The follows should be binary pubkeys ([]byte), not hex-encoded. Note: We directly modify p.Global's unexported field because Global is a value type (not *Rule), so calling p.Global.UpdateWriteFollowsWhitelist() would operate on a copy and discard changes. Thread-safe: uses followsMx to protect concurrent access.
func (*P) UpdatePolicyFollows ¶ added in v0.31.1
UpdatePolicyFollows replaces the policy follows list with a new set of pubkeys. This is called when policy admins update their follow lists (kind 3 events). The pubkeys should be binary ([]byte), not hex-encoded.
func (*P) UpdateRuleFollowsWhitelist ¶ added in v0.31.2
UpdateRuleFollowsWhitelist updates the follows whitelist for a specific kind's rule. The follows should be binary pubkeys ([]byte), not hex-encoded. Thread-safe: uses followsMx to protect concurrent access.
func (*P) UpdateRuleReadFollowsWhitelist ¶ added in v0.32.4
UpdateRuleReadFollowsWhitelist updates the read follows whitelist for a specific kind's rule. The follows should be binary pubkeys ([]byte), not hex-encoded. Thread-safe: uses followsMx to protect concurrent access.
func (*P) UpdateRuleWriteFollowsWhitelist ¶ added in v0.32.4
UpdateRuleWriteFollowsWhitelist updates the write follows whitelist for a specific kind's rule. The follows should be binary pubkeys ([]byte), not hex-encoded. Thread-safe: uses followsMx to protect concurrent access.
func (*P) ValidateJSON ¶ added in v0.31.1
ValidateJSON validates policy JSON without applying changes. This is called BEFORE any modifications to ensure JSON is valid. Returns error if validation fails - no changes are made to current policy.
func (*P) ValidateOwnerPolicyUpdate ¶ added in v0.31.4
ValidateOwnerPolicyUpdate validates a full policy update from an owner. Owners can modify all fields but the owners list must be non-empty.
func (*P) ValidatePolicyAdminUpdate ¶ added in v0.31.4
ValidatePolicyAdminUpdate validates a policy update from a policy admin. Policy admins CANNOT modify: owners, policy_admins Policy admins CAN: extend rules, add blacklists, add new kind rules
type PolicyAdminContribution ¶ added in v0.31.4
type PolicyAdminContribution struct {
// AdminPubkey is the hex-encoded pubkey of the policy admin who made this contribution
AdminPubkey string `json:"admin_pubkey"`
// CreatedAt is the Unix timestamp when this contribution was created
CreatedAt int64 `json:"created_at"`
// EventID is the Nostr event ID that created this contribution (for audit trail)
EventID string `json:"event_id,omitempty"`
// KindWhitelistAdd adds kinds to the whitelist (OR with owner's whitelist)
KindWhitelistAdd []int `json:"kind_whitelist_add,omitempty"`
// KindBlacklistAdd adds kinds to the blacklist (overrides whitelist)
KindBlacklistAdd []int `json:"kind_blacklist_add,omitempty"`
// RulesExtend extends existing rules defined by the owner
RulesExtend map[int]RuleExtension `json:"rules_extend,omitempty"`
// RulesAdd adds new rules for kinds not defined by the owner
RulesAdd map[int]Rule `json:"rules_add,omitempty"`
// GlobalExtend extends the global rule
GlobalExtend *RuleExtension `json:"global_extend,omitempty"`
}
PolicyAdminContribution represents extensions/additions from a policy admin. Policy admins can extend the base owner policy but cannot modify protected fields (owners, policy_admins) or reduce owner-granted permissions.
type PolicyEvent ¶
type PolicyEvent struct {
*event.E
LoggedInPubkey string `json:"logged_in_pubkey,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
AccessType string `json:"access_type,omitempty"` // "read" or "write"
}
PolicyEvent represents an event with additional context for policy scripts. It embeds the Nostr event and adds authentication and network context.
func (*PolicyEvent) MarshalJSON ¶
func (pe *PolicyEvent) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for PolicyEvent. It safely serializes the embedded event and additional context fields.
type PolicyManager ¶
type PolicyManager struct {
// contains filtered or unexported fields
}
PolicyManager handles multiple policy script runners. It manages the lifecycle of policy scripts, handles communication with them, and provides resilient operation with automatic restart capabilities. Each unique script path gets its own ScriptRunner instance.
func (*PolicyManager) ConfigPath ¶ added in v0.35.3
func (pm *PolicyManager) ConfigPath() string
ConfigPath returns the path to the policy configuration file. This is used by hot-reload handlers to know where to save updated policy.
func (*PolicyManager) GetScriptPath ¶ added in v0.20.3
func (pm *PolicyManager) GetScriptPath() string
GetScriptPath returns the default script path.
func (*PolicyManager) IsEnabled ¶
func (pm *PolicyManager) IsEnabled() bool
IsEnabled returns whether the policy manager is enabled.
func (*PolicyManager) IsRunning ¶
func (pm *PolicyManager) IsRunning() bool
IsRunning returns whether the default policy script is currently running. Deprecated: Use getOrCreateRunner(scriptPath).IsRunning() for specific scripts.
func (*PolicyManager) Shutdown ¶
func (pm *PolicyManager) Shutdown()
Shutdown gracefully shuts down the policy manager and all running scripts.
type PolicyResponse ¶
type PolicyResponse struct {
ID string `json:"id"`
Action string `json:"action"` // accept, reject, or shadowReject
Msg string `json:"msg"` // NIP-20 response message (only used for reject)
}
PolicyResponse represents a response from the policy script. The script should return JSON with these fields to indicate its decision.
type Rule ¶
type Rule struct {
// Description is a human-readable description of the rule.
Description string `json:"description"`
// Script is a path to a validation script.
Script string `json:"script,omitempty"`
// Embedded sub-components (fields are flattened in JSON for backward compatibility)
AccessControl
Constraints
TagValidationConfig
}
Rule defines policies for a specific event kind or as a global default. It is composed of sub-value objects for cleaner organization.
func (*Rule) GetFollowsWhitelistAdminsBin ¶ added in v0.31.2
GetFollowsWhitelistAdminsBin returns the binary-encoded admin pubkeys for this rule.
func (*Rule) GetReadFollowsWhitelistBin ¶ added in v0.32.4
GetReadFollowsWhitelistBin returns the binary-encoded pubkeys for ReadFollowsWhitelist.
func (*Rule) GetWriteFollowsWhitelistBin ¶ added in v0.32.4
GetWriteFollowsWhitelistBin returns the binary-encoded pubkeys for WriteFollowsWhitelist.
func (*Rule) HasFollowsWhitelistAdmins ¶ added in v0.31.2
HasFollowsWhitelistAdmins returns true if this rule has FollowsWhitelistAdmins configured. DEPRECATED: Use HasReadFollowsWhitelist and HasWriteFollowsWhitelist instead.
func (*Rule) HasReadFollowsWhitelist ¶ added in v0.32.4
HasReadFollowsWhitelist returns true if this rule has ReadFollowsWhitelist configured.
func (*Rule) HasWriteFollowsWhitelist ¶ added in v0.32.4
HasWriteFollowsWhitelist returns true if this rule has WriteFollowsWhitelist configured.
func (*Rule) IsInFollowsWhitelist ¶ added in v0.31.2
IsInFollowsWhitelist checks if the given pubkey is in this rule's follows whitelist. The pubkey parameter should be binary ([]byte), not hex-encoded.
func (*Rule) IsInReadFollowsWhitelist ¶ added in v0.32.4
IsInReadFollowsWhitelist checks if the given pubkey is in this rule's read follows whitelist. The pubkey parameter should be binary ([]byte), not hex-encoded. Returns true if either: 1. The pubkey is one of the ReadFollowsWhitelist pubkeys themselves, OR 2. The pubkey is in the follows list of the ReadFollowsWhitelist pubkeys.
func (*Rule) IsInWriteFollowsWhitelist ¶ added in v0.32.4
IsInWriteFollowsWhitelist checks if the given pubkey is in this rule's write follows whitelist. The pubkey parameter should be binary ([]byte), not hex-encoded. Returns true if either: 1. The pubkey is one of the WriteFollowsWhitelist pubkeys themselves, OR 2. The pubkey is in the follows list of the WriteFollowsWhitelist pubkeys.
func (*Rule) UpdateFollowsWhitelist ¶ added in v0.31.2
UpdateFollowsWhitelist sets the follows list for this rule's FollowsWhitelistAdmins. The follows should be binary pubkeys ([]byte), not hex-encoded.
func (*Rule) UpdateReadFollowsWhitelist ¶ added in v0.32.4
UpdateReadFollowsWhitelist sets the follows list for this rule's ReadFollowsWhitelist. The follows should be binary pubkeys ([]byte), not hex-encoded.
type RuleExtension ¶ added in v0.31.4
type RuleExtension struct {
// WriteAllowAdd adds pubkeys to the write allow list
WriteAllowAdd []string `json:"write_allow_add,omitempty"`
// WriteDenyAdd adds pubkeys to the write deny list (overrides allow)
WriteDenyAdd []string `json:"write_deny_add,omitempty"`
// ReadAllowAdd adds pubkeys to the read allow list
ReadAllowAdd []string `json:"read_allow_add,omitempty"`
// ReadDenyAdd adds pubkeys to the read deny list (overrides allow)
ReadDenyAdd []string `json:"read_deny_add,omitempty"`
// SizeLimitOverride can only make the limit MORE permissive (larger)
SizeLimitOverride *int64 `json:"size_limit_override,omitempty"`
// ContentLimitOverride can only make the limit MORE permissive (larger)
ContentLimitOverride *int64 `json:"content_limit_override,omitempty"`
// MaxAgeOfEventOverride can only make the limit MORE permissive (older allowed)
MaxAgeOfEventOverride *int64 `json:"max_age_of_event_override,omitempty"`
// MaxAgeEventInFutureOverride can only make the limit MORE permissive (further future allowed)
MaxAgeEventInFutureOverride *int64 `json:"max_age_event_in_future_override,omitempty"`
// WriteAllowFollows extends the follow whitelist feature
WriteAllowFollows *bool `json:"write_allow_follows,omitempty"`
// FollowsWhitelistAdminsAdd adds admin pubkeys whose follows are whitelisted
FollowsWhitelistAdminsAdd []string `json:"follows_whitelist_admins_add,omitempty"`
}
RuleExtension defines how a policy admin can extend an existing owner rule. All fields are additive - they extend, not replace, the owner's configuration.
type ScriptRunner ¶ added in v0.27.1
type ScriptRunner struct {
// contains filtered or unexported fields
}
ScriptRunner manages a single policy script process. Each unique script path gets its own independent runner with its own goroutine.
func (*ScriptRunner) IsRunning ¶ added in v0.27.1
func (sr *ScriptRunner) IsRunning() bool
IsRunning returns whether the script is currently running.
func (*ScriptRunner) ProcessEvent ¶ added in v0.27.1
func (sr *ScriptRunner) ProcessEvent(evt *PolicyEvent) ( *PolicyResponse, error, )
ProcessEvent sends an event to the script and waits for a response.
func (*ScriptRunner) Start ¶ added in v0.27.1
func (sr *ScriptRunner) Start() error
Start starts the script process.
func (*ScriptRunner) Stop ¶ added in v0.27.1
func (sr *ScriptRunner) Stop() error
Stop stops the script gracefully.
type TagValidationConfig ¶ added in v0.56.8
type TagValidationConfig struct {
// MustHaveTags is a list of tag key letters that must be present.
MustHaveTags []string `json:"must_have_tags,omitempty"`
// TagValidation is a map of tag_name -> regex pattern for validation.
TagValidation map[string]string `json:"tag_validation,omitempty"`
// IdentifierRegex is a regex pattern for "d" tag identifiers.
IdentifierRegex string `json:"identifier_regex,omitempty"`
// contains filtered or unexported fields
}
TagValidationConfig defines tag validation rules. This is a value object that encapsulates tag validation configuration.
Source Files
¶
- composition.go
- policy.go