Delegation
NIP-26 Delegation Support.
The Synvya SDK provides comprehensive support for NIP-26 delegation, allowing merchants to delegate publishing rights to servers or other entities while maintaining control over their identity and content.
Overview
NIP-26 delegation enables a merchant (delegator) to grant specific publishing permissions to another party (delegatee) without sharing their private key. This is particularly useful for: Allowing servers to publish events on behalf of merchants Enabling automated systems to manage marketplace content Implementing secure multi-user merchant management
Key Components
Delegation Class
The Delegation
class wraps and validates NIP-26 delegation events (kind 30078):
Properties
author
: Merchant’s public key (bech32 or hex)conditions
: Raw query string defining delegation constraintssig
: Merchant’s signaturetag
: Complete delegation tag for re-attachmentcreated_at
: Delegation creation timestamp (Unix)expires_at
: Delegation expiry timestamp (Unix)allowed_kinds
: Set of event kinds that can be published
NostrClient with Delegation
The NostrClient
can be initialized with a delegation event to automatically use it for publishing:
Creating a Delegation Event
A merchant creates a delegation event (kind 30078) that includes:
- Delegation tag: [“delegation”, delegatee_pubkey, conditions, delegation_token]
- Conditions: Query string specifying constraints like allowed kinds and expiry
- Signature: Merchant’s signature over the delegation
Example delegation event structure:
Methods
Delegation.parse(raw)
Converts raw JSON (string or dict) of a kind 30078 event into a validated Delegation instance.
- Parameters:
- raw: JSON string or dictionary containing the delegation event
- Returns:
- Delegation: Validated delegation instance
- Raises:
- ValueError: If event is not kind 30078, has invalid signature, or missing delegation tag
delegation.validate_event(event)
Validates that a given event can be published under this delegation.
- Parameters:
- event: Nostr event to validate
- Raises:
- ValueError: If event kind not allowed or delegation expired
delegation.delegation_tag
Property that returns the ready-made delegation tag for attaching to events before publishing.
Usage Examples
Server-Side Merchant Management
Delegation Validation
Security Considerations
- Signature Verification: All delegation events are cryptographically verified
- Time Bounds: Delegations include expiry timestamps for time-limited access
- Kind Restrictions: Only specified event kinds can be published
- Condition Parsing: Delegation conditions are parsed and validated
Error Handling
The delegation system provides specific error messages for common issues:
Best Practices
- Validate Early: Always validate delegation events immediately after parsing
- Check Expiry: Implement regular checks for delegation expiry
- Minimal Permissions: Request only the minimum required event kinds
- Secure Storage: Store delegation events securely on the server side
- Audit Trail: Log all actions performed under delegation for accountability This delegation system enables secure, controlled publishing while maintaining the decentralized nature of Nostr and giving merchants fine-grained control over their digital presence.
References
- NIP-26 - Delegation