diff options
Diffstat (limited to 'desk/lib/json/nostr.hoon')
-rw-r--r-- | desk/lib/json/nostr.hoon | 141 |
1 files changed, 108 insertions, 33 deletions
diff --git a/desk/lib/json/nostr.hoon b/desk/lib/json/nostr.hoon index aa5952a..9c36eb0 100644 --- a/desk/lib/json/nostr.hoon +++ b/desk/lib/json/nostr.hoon @@ -2,29 +2,39 @@ /+ common=json-common, sr=sortug |% ++ en -=, enjs:format +=, 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)] + ++ bulk-req |= [relays=(list @t) r=req:shim:sur] ^- json + %+ frond %ws %: pairs - relay+s+r - filters+a+(turn fs filter) + relays+a+(turn relays cord:en:common) + req+(req r) ~ == - :: - ++ post |= p=post:shim:sur + ++ http-req |= [relay=@t delay=@ud sub-id=@t fs=(list filter:sur)] + %+ frond %http %: pairs - event+(event event.p) - relays+a+(turn relays.p cord:en:common) - ~ + relay+s+relay + delay+(numb delay) + ['subscription_id' %s sub-id] + filters+a+(turn fs filter) + ~ == + ++ req |= =req:shim:sur ^- json + :- %a :- s+(crip (cuss (trip -.req))) + ?- -.req + %req (enreq +.req) + %event :_ ~ (event +.req) + %auth :_ ~ (event +.req) + %close :_ ~ [%s +.req] + == +++ enreq + |= [sub-id=@t fs=(list filter:sur)] + ^- (list json) + :- [%s sub-id] + %+ turn fs filter + :: ++ raw-event |= raw-event:sur :: WTF nostr doesn't want the prefix on the pubkey @@ -64,33 +74,82 @@ ++ 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 ?~ ids.f l :_ l ['ids' %a (turn ~(tap in u.ids.f) hex:en:common)] + =. l ?~ authors.f l :_ l ['authors' %a (turn ~(tap in u.authors.f) hex:en:common)] + =. l ?~ kinds.f l :_ l ['kinds' %a (turn ~(tap in u.kinds.f) numb)] + =. l ?~ tags.f l %+ weld l (tags u.tags.f) + + =. l ?~ since.f l :_ l ['since' (sect u.since.f)] + =. l ?~ until.f l :_ l ['until' (sect u.until.f)] =. l ?~ limit.f l :_ l ['limit' (numb u.limit.f)] + :: %- pairs l + + + ++ tags + |= tm=(map @t (set @t)) ^- (list [@t json]) :: entries to the filter obeject + %+ turn ~(tap by tm) |= [key=@t values=(set @t)] + =/ nkey (cat 3 '#' key) + [nkey %a (turn ~(tap in values) cord:en:common)] + ++ 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 + other+o+other.meta + ~ == -- ++ de =, dejs-soft:format |% :: shim + ++ shim-res + %- of :~ + http+(ar relay-msg) + ws+msg + == ++ msg %- ot :~ relay+so + msg+relay-msg + == + ++ relay-msg + %- of :~ + event+event-sub + ok+relay-ok + eose+so + closed+closed + notice+so + error+so + == + + + :: | { event: { subscription_id: string; event: NostrEvent } } + :: | { ok: { event_id: string; accepted: boolean; message: string } } + :: | { eose: string } + :: | { closed: { subscription_id: string; message: string } } + :: | { notice: string } + :: // this is ours + :: | { error: string }; + ++ event-sub + %- ot :~ + ['subscription_id' so] event+event == + ++ relay-ok + %- ot :~ + ['event_id' hex:de:common] + accepted+bo + message+so + == + ++ closed + %- ot :~ + ['subscription_id' so] + message+so + == ++ event %- ot :~ id+hex:de:common @@ -103,14 +162,30 @@ == ++ 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] + ?. ?=(%o -.jon) ~ + =| um=user-meta:sur + =/ fields ~(tap by p.jon) + |- ?~ fields (some um) + =/ k -.i.fields + =/ jn=json +.i.fields + ?+ k + =/ ot (~(put by other.um) k jn) + =. um um(other ot) $(fields t.fields) + %'name' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(name u.crd)) + %'display_name' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(name u.crd)) + %'displayName' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(name u.crd)) + %'about' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(picture u.crd)) + %'picture' + =/ crd (so jn) + ?~ crd $(fields t.fields) $(fields t.fields, um um(picture u.crd)) + == -- -- |