introduce nip42 and public/personal usage

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle
2023-11-16 21:53:58 +07:00
parent 5f13300734
commit dd1da10b8a
8 changed files with 156 additions and 8 deletions

19
nip42.js Normal file
View File

@@ -0,0 +1,19 @@
const { getEventHash, getSignature } = require("nostr-tools");
module.exports = (relay, pubkey, privkey, challenge) => {
if (!privkey) return;
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]));
}