summaryrefslogtreecommitdiff
path: root/shim/ws-shim/src/nostr.ts
blob: f3e5a4708ad97f1d669c5670a4141cece6da952b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 =
    "8224d719fb5a115272f1e63d4c6b65311a3e6bce323189c3094e891369cef715";
  // "d862c25aacfae2f66380448eafdeefeccb970a382f2ff185f3e0c5a538d60e35";
  const sk = hexToBytes(priv);
  const raw = {
    kind: event.kind,
    created_at: event.created_at,
    tags: event.tags,
    content: event.content,
  };
  const jsev = finalizeEvent(raw, sk);
  console.log("js event", jsev);
  console.log("validating my event", event);
}