summaryrefslogtreecommitdiff
path: root/desk/lib/nostr
diff options
context:
space:
mode:
Diffstat (limited to 'desk/lib/nostr')
-rw-r--r--desk/lib/nostr/events.hoon49
-rw-r--r--desk/lib/nostr/keys.hoon51
2 files changed, 100 insertions, 0 deletions
diff --git a/desk/lib/nostr/events.hoon b/desk/lib/nostr/events.hoon
new file mode 100644
index 0000000..2a3e818
--- /dev/null
+++ b/desk/lib/nostr/events.hoon
@@ -0,0 +1,49 @@
+/- sur=nostrill, nsur=nostr, post=trill-post, gate=trill-gate
+/+ js=json-nostr, sr=sortug, trill=trill-post, nostr-keys
+|%
+++ post-to-event |= [=keys:nsur eny=@ p=post:post] ^- event:nsur
+ =/ cl (latest-post-content:trill contents.p)
+ =/ string (crip (content-list-to-md:trill cl))
+ =/ ts (to-unix-secs:jikan:sr id.p)
+ =/ raw=raw-event:nsur [pub.keys ts 1 ~ string]
+ =/ event-id (hash-event:nostr-keys raw)
+ =/ signature (sign-event:nostr-keys priv.keys event-id eny)
+ ~& hash-and-signed=[event-id signature]
+ =/ =event:nsur :*
+ event-id
+ pub.keys
+ created-at.raw
+ kind.raw
+ tags.raw
+ content.raw
+ signature
+ ==
+ event
+
+++ event-to-post
+ |= [=event:nsur profile=(unit user-meta:nsur) relay=(unit @t)]
+ ^- post-wrapper:sur
+
+ =/ cl (tokenize:trill content.event)
+ =/ ts (from-unix:jikan:sr created-at.event)
+ =/ cm=content-map:post (init-content-map:trill cl ts)
+
+ :: TODO more about @ps and stuff
+ =/ p=post:post :*
+ id=ts
+ host=`@p`pubkey.event
+ author=`@p`pubkey.event
+ thread=ts
+ parent=~
+ children=~
+ contents=cm
+ read=*lock:gate
+ write=*lock:gate
+ *engagement:post
+ 0v0
+ *signature:post
+ tags=~
+ ==
+ =/ meta [(some pubkey.event) (some id.event) relay profile]
+ [p meta]
+--
diff --git a/desk/lib/nostr/keys.hoon b/desk/lib/nostr/keys.hoon
new file mode 100644
index 0000000..90eb563
--- /dev/null
+++ b/desk/lib/nostr/keys.hoon
@@ -0,0 +1,51 @@
+/- sur=nostr
+/+ js=json-nostr, sr=sortug
+|%
+++ gen-sub-id |= eny=@ ^- @t
+ %- crip (scag 60 (scow:sr %uw eny))
+++ gen-keys |= eny=@ ^- keys:sur
+ =, secp256k1:secp:crypto
+ =/ privkey
+ |-
+ =/ k (~(rad og eny) (bex 256))
+ ?. (lth k n.t) $ k
+
+ =/ pubkey (priv-to-pub privkey)
+ =/ pub (compress-point pubkey)
+ :: =/ pub (serialize-point pubkey)
+ [pub=pub priv=privkey]
+::
+++ hash-event |= raw=raw-event:sur ^- @ux
+ =/ jon (raw-event:en:js raw)
+ =/ jstring (en:json:html jon)
+ (swp 3 (shax jstring))
+
+++ raws
+ |= [eny=@ bits=@]
+ ^- [@ @]
+ [- +>-]:(~(raws og eny) bits)
+
+++ sign-event |= [priv=@ux hash=@ux eny=@]
+ =^ sed eny (raws eny 256)
+ (sign:schnorr:secp256k1:secp:crypto priv hash sed)
+
+
+::
+++ validate-pubkey |= pubkey=@ux ^- ?
+ =/ tap (scow:sr %ux pubkey)
+ .= (lent tap) 64
+::
+++ diff-filters
+|= [a=filter:sur b=filter:sur] ^- filter:sur
+ =/ ids (unit-set-dif ids.a ids.b)
+ =/ authors (unit-set-dif authors.a authors.b)
+ =/ kinds (unit-set-dif kinds.a kinds.b)
+ =/ tags ~
+ =/ since ~
+ =/ until ~
+ =/ limit ~ :: TODO
+ [ids authors kinds tags since until limit]
+++ unit-set-dif
+ |* [a=(unit) b=(unit)]
+ %^ clap a b |* [x=(set) y=(set)] (~(dif in x) y)
+--