mirror of
https://github.com/Yonle/bostr.git
synced 2025-11-19 18:36:26 +01:00
code: renaming & reworking as per nostr-tools
Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
10
auth.js
10
auth.js
@@ -1,17 +1,12 @@
|
||||
const { validateEvent, verifySignature } = require("nostr-tools");
|
||||
const { verifyEvent } = require("nostr-tools");
|
||||
const { authorized_keys, private_keys } = require("./config");
|
||||
|
||||
module.exports = (authKey, data, ws, req) => {
|
||||
if (!validateEvent(data)) {
|
||||
if (!verifyEvent(data)) {
|
||||
ws.send(JSON.stringify(["NOTICE", "error: invalid challenge response."]));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!verifySignature(data)) {
|
||||
ws.send(JSON.stringify(["OK", data.id, false, "signature verification failed."]));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!authorized_keys?.includes(data.pubkey) && !(private_keys && private_keys[data.pubkey])) {
|
||||
ws.send(JSON.stringify(["OK", data.id, false, "unauthorized."]));
|
||||
return false;
|
||||
@@ -23,6 +18,7 @@ module.exports = (authKey, data, ws, req) => {
|
||||
}
|
||||
|
||||
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."]));
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user