fix authorized_keys don't work on npub string & make private_keys accept npub string

Signed-off-by: Yonle <yonle@lecturify.net>
This commit is contained in:
Yonle 2024-05-16 18:34:07 +07:00
parent 34ab5f6013
commit 8665374a66
3 changed files with 21 additions and 10 deletions

13
auth.js
View File

@ -1,6 +1,15 @@
"use strict";
const { validateEvent, verifyEvent } = require("nostr-tools");
const { authorized_keys, private_keys, noscraper } = require(process.env.BOSTR_CONFIG_PATH || "./config");
let { validateEvent, verifyEvent, nip19 } = require("nostr-tools");
let { authorized_keys, private_keys, noscraper } = require(process.env.BOSTR_CONFIG_PATH || "./config");
authorized_keys = authorized_keys?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);
for (const key in private_keys) {
if (!key.startsWith("npub")) continue;
private_keys[nip19.decode(key).data] = private_keys[key];
delete private_keys[key];
}
module.exports = (authKey, data, ws, req) => {
if (!authorized_keys?.length && !Object.keys(private_keys).length && !noscraper) return; // do nothing

View File

@ -14,6 +14,13 @@ authorized_keys = authorized_keys?.map(i => i.startsWith("npub") ? nip19.decode(
allowed_publishers = allowed_publishers?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);
blocked_publishers = blocked_publishers?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);
for (const key in private_keys) {
if (!key.startsWith("npub")) continue;
private_keys[nip19.decode(key).data] = private_keys[key];
delete private_keys[key];
}
// The following warning will be removed in the next 2 stable release
if (approved_publishers?.length) {
allowed_publishers = approved_publishers?.map(i => i.startsWith("npub") ? nip19.decode(i).data : i);

View File

@ -129,15 +129,10 @@ module.exports = {
// NOTE: - Require NIP-42 compatible nostr client
private_keys: {
// "pubkey-in-hex": "privatekey-in-hex",
// "pubkey-in-hex": "nsec ...."
// "pubkey-in-hex": "nsec ....",
// "npub ....": "privatekey-in-hex",
// "npub ....": "nsec ...."
},
// Tip: If you want to convert your pubkey/privatekey to hex,
// You could run the following command:
// $ node hexconverter.js npub....
// $ node hexconverter.js nsec....
// or
// $ bostr hexconverter npub....
// $ bostr hexconverter nsec....
// Server information.
// Only for when nostr client requesting server information.