-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
39 lines (34 loc) · 1.17 KB
/
main.ts
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
import { cliffy, nostrTools } from "./deps.ts";
import { log } from "./log.ts";
import { repost } from "./validation/repost.ts";
function getOrCreatePrivateKey(maybePrivateKeyNsec?: string) {
if (typeof maybePrivateKeyNsec === "string") {
const decoded = nostrTools.nip19.decode(maybePrivateKeyNsec);
if (decoded.type !== "nsec") {
throw new Error("#5jLJ2W Invalid nsec");
}
return decoded.data;
}
const key = nostrTools.generateSecretKey();
const nsec = nostrTools.nip19.nsecEncode(key);
log.info(`#2yrJza Using random nsec ${nsec}`);
return key;
}
await new cliffy.Command()
.globalEnv("IS_DEV", "Set to true to run in development mode")
.globalEnv(
"PRIVATE_KEY_NSEC=<value:string>",
"Specify the private key in nsec format"
)
.env(
"MAX_AGE_MINUTES=<value:number>",
"How many minutes into the past to check for events to validate"
)
.action((options) => {
const { isDev } = options;
const privateKey = getOrCreatePrivateKey(options.privateKeyNsec);
const maxAgeMinutes = options.maxAgeMinutes;
log.debug(`#PnFUPS Startup isDev ${isDev}`);
repost(privateKey, isDev, maxAgeMinutes);
})
.parse(Deno.args);