summaryrefslogtreecommitdiff
path: root/desk/lib/json/nostr.hoon
blob: aa5952a06b0290dbfaa450c4f0bb670b36531455 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/-  sur=nostr
/+  common=json-common, sr=sortug
|%
++  en
=,  enjs:format
  |%
  ::  shim comms
  ++  req  |=  =req:shim:sur  ^-  json
    %+  frond  -.req
    ?-  -.req
      %get   (get +.req)
      %post  (post +.req)
    ==
  ++  get  |=  rs=get:shim:sur
    :-  %a  %+  turn  rs  |=  [r=@t fs=(list filter:sur)]
    %:  pairs
    relay+s+r
    filters+a+(turn fs filter)
    ~
    ==
  ::
  ++  post  |=  p=post:shim:sur
    %:  pairs
      event+(event event.p)
      relays+a+(turn relays.p cord:en:common)
      ~
    ==
    ::
  ++  raw-event  |=  raw-event:sur
  :: WTF nostr doesn't want the prefix on the pubkey
    =/  pubkeyt  (scow:sr %ux pubkey)
    ?~  pubkeyt  !!
    =/  pubkeyj  [%s (crip t.pubkeyt)]
    :-  %a  :~
      [%n '0']
      pubkeyj  
      (numb created-at)
      (numb kind)
      a+(turn tags tag)
      s+content
    ==
  ++  event
  |=  e=event:sur  ^-  json
    =/  pubkeyt  (scow:sr %ux pubkey.e)
    ?~  pubkeyt  !!
    =/  pubkeyj  [%s (crip t.pubkeyt)]
    %:  pairs
      id+(hex:en:common id.e)
      :: pubkey+(hex:en:common pubkey.e)
      pubkey+pubkeyj
      sig+(hex:en:common sig.e)
      ['created_at' (numb created-at.e)]
      kind+(numb kind.e)
      content+s+content.e
      tags+a+(turn tags.e tag)
    ~
    ==
  ++  tag
  |=  t=tag:sur  ^-  json  [%a (turn t cord:en:common)]
    :: :-  s+key.t
    :: :-  s+value.t
    :: (turn rest.t |=(tt=@t s+tt))
    :: 
  ++  filter
  |=  f=filter:sur  ^-  json
    =|  l=(list [key=@t jon=json])
    =.  l  ?~  ids.f      l  :_  l  ['ids' [%a (turn ids.f hex:en:common)]]
    =.  l  ?~  authors.f  l  :_  l  ['authors' [%a (turn authors.f hex:en:common)]]
    =.  l  ?~  kinds.f    l  :_  l  ['kinds' [%a (turn kinds.f numb)]]
    =.  l  ?~  since.f    l  :_  l  ['since' (numb u.since.f)]
    =.  l  ?~  until.f    l  :_  l  ['until' (numb u.until.f)]
    =.  l  ?~  limit.f    l  :_  l  ['limit' (numb u.limit.f)]
    %-  pairs  l
  ++  user-meta
  |=  meta=user-meta:sur
    =/  other  %+  turn  ~(tap by other.meta)  |=  [key=@t val=@t]
    [key %s val]
    %:  pairs
        name+s+name.meta
        picture+s+picture.meta
        about+s+about.meta
        other
    ==
  --
++  de
=,  dejs-soft:format
  |%
    :: shim
  ++  msg
    %-  ot  :~
      relay+so
      event+event
    ==
  ++  event
    %-  ot  :~
      id+hex:de:common
      pubkey+hex:de:common
      ['created_at' ni]
      kind+ni
      tags+(ar (ar so))
      content+so
      sig+hex:de:common
    ==
  ++  user-meta  |=  jon=json
    ^-  (unit user-meta:sur)
    =/  all  ((om so) jon)
    ?~  all  ~
    =/  base=(unit [name=@t about=@t picture=@t])  %.  jon  %-  ot  :~
      name+so
      about+so
      picture+so
    ==
    ?~  base  ~
    `[name.u.base about.u.base picture.u.base u.all]
  --
--