/ rules / simple_types.py
simple_types.py
 1  from typing import Literal, TypedDict, Union
 2  
 3  # -----------------------------
 4  # Tags NIP-35 pour kind=2003
 5  # -----------------------------
 6  # D'après l'implémentation NIP-35 (nostr crate) :
 7  # - Tag::title(...)            => ["title", <title>]
 8  # - TagKind::x()               => ["x", <info_hash>]
 9  # - TagKind::File              => ["file", <name>, <size_as_string>]
10  # - TagKind::Tracker           => ["tracker", <url>]
11  # - TagKind::i() with tcat:...  => ["i", "tcat:<category>"]
12  # - Tag::hashtag(...)          => ["t", <hashtag>]
13  # :contentReference[oaicite:1]{index=1}
14  
15  TitleTag = tuple[Literal["title"], str]
16  XTag = tuple[Literal["x"], str]
17  FileTag = tuple[Literal["file"], str, str]  # size est encodée en string dans le tag
18  TrackerTag = tuple[Literal["tracker"], str]
19  ICatTag = tuple[Literal["i"], str]  # attendu: "tcat:<...>" (validation runtime)
20  HashtagTag = tuple[Literal["t"], str]
21  
22  Nip35Kind2003Tag = Union[
23      TitleTag,
24      XTag,
25      FileTag,
26      TrackerTag,
27      ICatTag,
28      HashtagTag,
29  ]
30  
31  
32  # -----------------------------
33  # Event Nostr kind=2003 (wire)
34  # -----------------------------
35  class Nip35Kind2003Event(TypedDict):
36      id: str
37      pubkey: str
38      created_at: int
39      kind: Literal[2003]
40      tags: list[Nip35Kind2003Tag]
41      content: str  # description (longue) du torrent
42      sig: str
43  
44  
45  # === Results
46  
47  class BinaryRuleResult(TypedDict):
48      passed: bool
49  
50  
51  class ProbabilityRuleResult(TypedDict):
52      score: float
53  
54  
55  RuleResult = Union[BinaryRuleResult, ProbabilityRuleResult]