mirror of
https://github.com/Yonle/bostr.git
synced 2025-11-19 10:26:34 +01:00
enable nip42 function for public bouncer.
Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
12
auth.js
12
auth.js
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user