-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-receive-payment.ts
More file actions
36 lines (28 loc) · 1.13 KB
/
06-receive-payment.ts
File metadata and controls
36 lines (28 loc) · 1.13 KB
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
import {nip04, nip19, SimplePool} from 'nostr-tools';
import {finalizeEvent} from "nostr-tools";
import {nsec, npub, relays, publicKey, secretKey} from "./00-defaults";
import {EventTemplate} from "nostr-tools/lib/types/core";
const pool = new SimplePool();
const paymentId = 'a37e307c80ee987d0d392761596e60a1360aeabddffc2e02759ed3579b7defff';
{
const eventTemplate = {
kind: 4,
pubkey: publicKey,
created_at: Math.floor(Date.now() / 1000),
tags: [
['p', 'adf1c23ec4e667a87ac676d681dca38677d8c940f25600f82c4b66230917bcd5']
],
content: await nip04.encrypt(secretKey, 'adf1c23ec4e667a87ac676d681dca38677d8c940f25600f82c4b66230917bcd5', JSON.stringify({
"id": paymentId,
"type": 2,
"message": "Děkujeme, že jste u nás povečeřel",
"paid": true,
shipped: true,
})),
} satisfies EventTemplate;
const signedEvent = finalizeEvent(eventTemplate, secretKey);
console.log(signedEvent);
const result = await Promise.all(pool.publish(relays, signedEvent));
console.log(result);
}
pool.close(relays);