-
Notifications
You must be signed in to change notification settings - Fork 1
/
processor.js
35 lines (29 loc) · 1000 Bytes
/
processor.js
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
const { getPrivateKey, getPublicKey, signEvent } = require('./lib/nostr.js')
const secret = process.env.SECRET;
if (typeof secret !== 'string' || !secret.length) {
throw new Error('SECRET is not set or is empty')
}
function createMessage(context, _events, done) {
const { kind, content, privateKey, tags } = context.vars;
createEvent(context.vars['$uuid'], { kind, content, privateKey, tags }).then((event) => {
context.vars.message = ['EVENT', event]
done()
}, (err) => done(err))
}
async function createEvent(uuid, { kind, content, privateKey, tags }) {
const privkey = privateKey ?? getPrivateKey(uuid, secret)
const pubkey = getPublicKey(privkey)
const created_at = Math.floor(Date.now()/1000)
const event = await signEvent(
{
pubkey,
kind: Number.parseInt(kind),
content: content ?? `Performance test ${Date.now()}`,
created_at,
tags: JSON.parse(tags),
},
privkey,
)
return event
}
module.exports = { createMessage };