blob: 7da9b91e0fc0bcc698536f21f71a7e18c228f04c (
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
41
42
43
|
// import { generateSecretKey, getPublicKey } from "nostr-tools/pure";
import * as nip19 from "nostr-tools/nip19";
import type { Event } from "@/types/nostr";
export function generateNevent(event: Event) {
const evp: nip19.EventPointer = {
id: event.id,
author: event.pubkey,
kind: event.kind,
};
const nev = nip19.neventEncode(evp);
return nev;
}
export function generateNpub(pubkey: string) {
const npub = nip19.npubEncode(pubkey);
return npub;
}
export function generateNprofile(pubkey: string) {
const prof = { pubkey };
const nprofile = nip19.nprofileEncode(prof);
return nprofile;
}
// let sk = generateSecretKey()
// let nsec = nip19.nsecEncode(sk)
// let { type, data } = nip19.decode(nsec)
// assert(type === 'nsec')
// assert(data === sk)
// let pk = getPublicKey(generateSecretKey())
// let npub = nip19.npubEncode(pk)
// let { type, data } = nip19.decode(npub)
// assert(type === 'npub')
// assert(data === pk)
// let pk = getPublicKey(generateSecretKey())
// let relays = ['wss://relay.nostr.example.mydomain.example.com', 'wss://nostr.banana.com']
// let nprofile = nip19.nprofileEncode({ pubkey: pk, relays })
// let { type, data } = nip19.decode(nprofile)
// assert(type === 'nprofile')
// assert(data.pubkey === pk)
// assert(data.relays.length === 2)
|