[Feature] Initial NIP-26 support (#25)

* adds initial NIP-26 support

* Update README.md

* Update README.md
This commit is contained in:
kdmukai
2023-01-11 16:54:17 -06:00
committed by GitHub
parent 181c1efa23
commit 3a903b77ab
4 changed files with 78 additions and 0 deletions

32
nostr/delegation.py Normal file
View File

@@ -0,0 +1,32 @@
import time
from dataclasses import dataclass
@dataclass
class Delegation:
delegator_pubkey: str
delegatee_pubkey: str
event_kind: int
duration_secs: int = 30*24*60 # default to 30 days
signature: str = None # set in PrivateKey.sign_delegation
@property
def expires(self) -> int:
return int(time.time()) + self.duration_secs
@property
def conditions(self) -> str:
return f"kind={self.event_kind}&created_at<{self.expires}"
@property
def delegation_token(self) -> str:
return f"nostr:delegation:{self.delegatee_pubkey}:{self.conditions}"
def get_tag(self) -> list[str]:
""" Called by Event """
return [
"delegation",
self.delegator_pubkey,
self.conditions,
self.signature,
]