summaryrefslogtreecommitdiff
path: root/nostr/event.py
blob: 3dfe638fbb195f73c26276f2c571c1d465d9137d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import hashlib
import json

from enum import Enum
from time import time


class EventKind(Enum):
    SET_METADATA = 0
    TEXT_NOTE = 1
    RECOMMEND_SERVER = 2
    CONTACT_LIST = 3
    ENCRYPTED_DIRECT_MESSAGE = 4
    DELETION = 5


class Event:
    def __init__(self, pubkey, content, tags=None, created_at=None):
        self.pubkey = pubkey.lower()
        self.created_at = created_at or int(time())
        self.kind = 0
        self.tags = tags or []
        self.content = content
        self.sig = 0

    @property
    def id(self):
        data = [0, self.pubkey, self.created_at, self.kind, self.tags, self.content]
        jd = json.dumps(data).encode("utf-8")
        print(jd)
        return hashlib.sha256(jd).hexdigest()