summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-09-18 05:08:24 +0700
committerpolwex <polwex@sortug.com>2025-09-18 05:08:24 +0700
commit0549cfd01f1feed9c313a84a3884328d08887caf (patch)
tree5017ce328f058bf9efa5bc1de60c18b09082a93c
parentad7ebd1756956724e0b167d88f924e707401a9aa (diff)
nostr keys as annoying as usual, but this works reliably
-rw-r--r--desk/app/nostrill.hoon13
-rw-r--r--desk/lib/json/nostr.hoon26
-rw-r--r--shim/ws-shim/src/nostr.ts40
3 files changed, 48 insertions, 31 deletions
diff --git a/desk/app/nostrill.hoon b/desk/app/nostrill.hoon
index 611830f..37aaf06 100644
--- a/desk/app/nostrill.hoon
+++ b/desk/app/nostrill.hoon
@@ -163,13 +163,16 @@
`this
%genkey
=/ keys (gen-keys:nlib eny.bowl)
- ~& keys=keys
+ ~& pub=(scow:sr %ux -.keys)
+ ~& priv=(scow:sr %ux +.keys)
`this
%printkey
- =/ key i.keys
- ~& pub=(scow:sr %ux -.key)
- ~& priv=(scow:sr %ux +.key)
- `this
+ =/ ks `(list keys:nsur)`keys
+ |- ?~ ks `this
+ =/ key i.ks
+ ~& pub=(scow:sr %ux -.key)
+ ~& priv=(scow:sr %ux +.key)
+ $(ks t.ks)
%feed
=/ lol debug-own-feed:mutat
`this
diff --git a/desk/lib/json/nostr.hoon b/desk/lib/json/nostr.hoon
index 6f93c1c..cb10c1d 100644
--- a/desk/lib/json/nostr.hoon
+++ b/desk/lib/json/nostr.hoon
@@ -22,11 +22,12 @@
~
==
++ req |= =req:shim:sur ^- json
+ =/ en-ev event
:- %a :- s+(crip (cuss (trip -.req)))
?- -.req
%req (enreq +.req)
- %event :_ ~ (event +.req)
- %auth :_ ~ (event +.req)
+ %event :_ ~ (en-ev(nostr .y) +.req)
+ %auth :_ ~ (en-ev(nostr .y) +.req)
%close :_ ~ [%s +.req]
==
++ enreq
@@ -38,11 +39,12 @@
::
++ raw-event |= raw-event:sur
:: WTF nostr doesn't want the prefix on the pubkey
- =/ scw scow:sr
- =/ pubkeyt (scw(min-chars 64) %ux pubkey)
+ :: =/ scw scow:sr
+ :: =/ pubkeyt (scw(min-chars 64) %ux pubkey)
+ =/ pubkeyt (scow:sr %ux pubkey)
?~ pubkeyt !!
- :: =/ pubkeyj [%s (crip t.pubkeyt)]
- =/ pubkeyj [%s (crip pubkeyt)]
+ =/ pubkeyj [%s (crip t.pubkeyt)]
+ :: =/ pubkeyj [%s (crip pubkeyt)]
:- %a :~
[%n '0']
pubkeyj
@@ -52,14 +54,16 @@
s+content
==
++ event
+ =/ nostr=? .n
|= e=event:sur ^- json
- :: =/ pubkeyt (scow:sr %ux pubkey.e)
- :: ?~ pubkeyt !!
- :: =/ pubkeyj [%s (crip t.pubkeyt)]
+ =/ pubkey ?. nostr
+ (hex:en:common pubkey.e)
+ =/ pubkeyt (scow:sr %ux pubkey.e)
+ ?~ pubkeyt !!
+ [%s (crip t.pubkeyt)]
%: pairs
id+(hex:en:common id.e)
- pubkey+(hex:en:common pubkey.e)
- :: pubkey+pubkeyj
+ pubkey+pubkey
sig+(hex:en:common sig.e)
['created_at' (numb created-at.e)]
kind+(numb kind.e)
diff --git a/shim/ws-shim/src/nostr.ts b/shim/ws-shim/src/nostr.ts
index b123bc8..f3e5a47 100644
--- a/shim/ws-shim/src/nostr.ts
+++ b/shim/ws-shim/src/nostr.ts
@@ -1,11 +1,32 @@
-import { finalizeEvent, nip19, validateEvent, verifyEvent } from "nostr-tools";
+import {
+ finalizeEvent,
+ getPublicKey,
+ nip19,
+ validateEvent,
+ verifyEvent,
+} from "nostr-tools";
import type { NostrEvent } from "./types";
import { hexToBytes } from "nostr-tools/utils";
export function validate(event: NostrEvent) {
+ const ok = validateEvent(event);
+ const ok2 = verifyEvent(event);
+ return ok && ok2;
+}
+
+export function checkPubkey(pubkey: string): boolean {
+ const npub = nip19.npubEncode(pubkey);
+ console.log({ npub, hex: pubkey });
+ return false;
+}
+
+function testKeys(event: NostrEvent) {
console.log("constructing event in js");
+ // pub="3f4dd2220bdeeb153eea8908932d83756a488ee77dbd38cec4fd4bbe03997f333"
+ // priv="8224d719fb5a115272f1e63d4c6b65311a3e6bce323189c3094e891369cef715"
const priv =
- "d862c25aacfae2f66380448eafdeefeccb970a382f2ff185f3e0c5a538d60e35";
+ "8224d719fb5a115272f1e63d4c6b65311a3e6bce323189c3094e891369cef715";
+ // "d862c25aacfae2f66380448eafdeefeccb970a382f2ff185f3e0c5a538d60e35";
const sk = hexToBytes(priv);
const raw = {
kind: event.kind,
@@ -13,18 +34,7 @@ export function validate(event: NostrEvent) {
tags: event.tags,
content: event.content,
};
- const ev = finalizeEvent(raw, sk);
- console.log("js event", ev);
+ const jsev = finalizeEvent(raw, sk);
+ console.log("js event", jsev);
console.log("validating my event", event);
- const ok = validateEvent(event);
- console.log("is valid?", ok);
- const ok2 = verifyEvent(event);
- console.log("is verified?", ok2);
- return ok && ok2;
-}
-
-export function checkPubkey(pubkey: string): boolean {
- const npub = nip19.npubEncode(pubkey);
- console.log({ npub, hex: pubkey });
- return false;
}