1
0
mirror of https://github.com/Yonle/bostr.git synced 2025-03-18 22:02:18 +01:00
Yonle 3be8e325e1 some helper.
Signed-off-by: Yonle <yonle@lecturify.net>
2023-11-16 22:07:07 +07:00

22 lines
610 B
JavaScript

const { getEventHash, getSignature, nip19 } = require("nostr-tools");
module.exports = (relay, pubkey, privkey, challenge) => {
if (!privkey) return;
if (privkey.startsWith("nsec")) privkey = nip19.decode(privkey).data;
let signed_challenge = {
pubkey,
created_at: Math.floor(Date.now() / 1000),
kind: 22242,
tags: [
["relay", relay.url],
["challenge", challenge]
],
content: ""
}
signed_challenge.id = getEventHash(signed_challenge);
signed_challenge.sig = getSignature(signed_challenge, privkey);
relay.send(JSON.stringify(["AUTH", signed_challenge]));
}