summaryrefslogtreecommitdiff
path: root/desk/lib/nostr.hoon
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-09-11 01:48:14 +0700
committerpolwex <polwex@sortug.com>2025-09-11 01:48:14 +0700
commitb1d68ac307ed87d63e83820cbdf843fff0fd9f7f (patch)
treed6a684a70a80509e68ff667b842aa4e4c091906f /desk/lib/nostr.hoon
init
Diffstat (limited to 'desk/lib/nostr.hoon')
-rw-r--r--desk/lib/nostr.hoon29
1 files changed, 29 insertions, 0 deletions
diff --git a/desk/lib/nostr.hoon b/desk/lib/nostr.hoon
new file mode 100644
index 0000000..c05b0eb
--- /dev/null
+++ b/desk/lib/nostr.hoon
@@ -0,0 +1,29 @@
+/- sur=nostr
+/+ js=json-nostr
+|%
+++ 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)
+--