Warn when NIP-11 pubkey is in incorrect format (#52)

This commit is contained in:
Doug Hoyte
2023-07-20 18:03:40 -04:00
parent 0d21dc3255
commit 42d5101316
3 changed files with 26 additions and 8 deletions

View File

@ -52,15 +52,18 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
auto getServerInfoHttpResponse = [&supportedNips, ver = uint64_t(0), rendered = std::string("")]() mutable {
if (ver != cfg().version()) {
rendered = preGenerateHttpResponse("application/json", tao::json::to_string(tao::json::value({
{ "name", cfg().relay__info__name },
{ "description", cfg().relay__info__description },
{ "pubkey", cfg().relay__info__pubkey },
{ "contact", cfg().relay__info__contact },
tao::json::value nip11 = tao::json::value({
{ "supported_nips", supportedNips },
{ "software", "git+https://github.com/hoytech/strfry.git" },
{ "version", APP_GIT_VERSION },
})));
});
if (cfg().relay__info__name.size()) nip11["name"] = cfg().relay__info__name;
if (cfg().relay__info__description.size()) nip11["description"] = cfg().relay__info__description;
if (cfg().relay__info__contact.size()) nip11["contact"] = cfg().relay__info__contact;
if (cfg().relay__info__pubkey.size()) nip11["pubkey"] = cfg().relay__info__pubkey;
rendered = preGenerateHttpResponse("application/json", tao::json::to_string(nip11));
ver = cfg().version();
}

View File

@ -5,6 +5,18 @@
static void checkConfig() {
if (cfg().relay__info__pubkey.size()) {
try {
auto p = from_hex(cfg().relay__info__pubkey);
if (p.size() != 32) throw herr("bad size");
} catch (std::exception &e) {
LW << "Your relay.info.pubkey is incorrectly formatted. It should be 64 hex digits.";
}
}
}
void cmd_relay(const std::vector<std::string> &subArgs) {
RelayServer s;
s.run();
@ -53,12 +65,15 @@ void RelayServer::run() {
// Monitor for config file reloads
checkConfig();
auto configFileChangeWatcher = hoytech::file_change_monitor(configFile);
configFileChangeWatcher.setDebounce(100);
configFileChangeWatcher.run([&](){
loadConfig(configFile);
checkConfig();
});