enable nip42 function for public bouncer.

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle
2023-11-20 21:21:22 +07:00
parent 8a189bcd2e
commit b8c720aa8a
3 changed files with 25 additions and 15 deletions

12
auth.js
View File

@@ -1,6 +1,7 @@
const { validateEvent, verifySignature } = require("nostr-tools");
const { authorized_keys, private_keys } = require("./config");
module.exports = (authKey, authorized, authorized_keys, data, ws, req) => {
module.exports = (authKey, data, ws, req) => {
if (!validateEvent(data)) {
ws.send(JSON.stringify(["NOTICE", "error: invalid challenge response."]));
return false;
@@ -11,7 +12,7 @@ module.exports = (authKey, authorized, authorized_keys, data, ws, req) => {
return false;
}
if (!authorized_keys.includes(data.pubkey)) {
if (!authorized_keys?.includes(data.pubkey) && !(private_keys && private_keys[data.pubkey])) {
ws.send(JSON.stringify(["OK", data.id, false, "unauthorized."]));
return false;
}
@@ -21,11 +22,6 @@ module.exports = (authKey, authorized, authorized_keys, data, ws, req) => {
return false;
}
if (authorized) {
ws.send(JSON.stringify(["OK", data.id, false, "already authorized."]));
return false;
}
const tags = new Map(data.tags);
if (!tags.get("relay").includes(req.headers.host)) {
ws.send(JSON.stringify(["OK", data.id, false, "unmatched relay url."]));
@@ -37,6 +33,6 @@ module.exports = (authKey, authorized, authorized_keys, data, ws, req) => {
return false;
}
ws.send(JSON.stringify(["OK", data.id, true, `Welcome ${data.pubkey}`]));
ws.send(JSON.stringify(["OK", data.id, true, `Hello ${data.pubkey}`]));
return true;
}