summaryrefslogtreecommitdiff
path: root/shim/ws-shim/src/nostr.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shim/ws-shim/src/nostr.ts')
-rw-r--r--shim/ws-shim/src/nostr.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/shim/ws-shim/src/nostr.ts b/shim/ws-shim/src/nostr.ts
new file mode 100644
index 0000000..0b084b6
--- /dev/null
+++ b/shim/ws-shim/src/nostr.ts
@@ -0,0 +1,24 @@
+import { finalizeEvent, validateEvent, verifyEvent } from "nostr-tools";
+import type { NostrEvent } from "./types";
+import { hexToBytes } from "nostr-tools/utils";
+
+export function validate(event: NostrEvent) {
+ console.log("constructing event in js");
+ const priv =
+ "d862c25aacfae2f66380448eafdeefeccb970a382f2ff185f3e0c5a538d60e35";
+ const sk = hexToBytes(priv);
+ const raw = {
+ kind: event.kind,
+ created_at: event.created_at,
+ tags: event.tags,
+ content: event.content,
+ };
+ const ev = finalizeEvent(raw, sk);
+ console.log("js event", ev);
+ 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;
+}