Add configurable public key server usage

Persist per-server enablement, search enabled servers, and require an explicit publication target. Update documentation and tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-10-10 20:28:24 +03:00
co-authored by Copilot
parent 04cd4117fe
commit f3e68b10bd
11 changed files with 196 additions and 42 deletions
+38 -4
View File
@@ -40,10 +40,14 @@ function normalizeCustomServer(input) {
};
}
function listServers(customServers = []) {
function listServers(customServers = [], enabledServerIds = []) {
const enabled = new Set(enabledServerIds);
return [
...BUILTIN_SERVERS.map(server => ({ ...server })),
...customServers.map(server => normalizeCustomServer(server))
...BUILTIN_SERVERS.map(server => ({ ...server, enabled: enabled.has(server.id) })),
...customServers.map(server => {
const normalized = normalizeCustomServer(server);
return { ...normalized, enabled: enabled.has(normalized.id) };
})
];
}
@@ -160,6 +164,36 @@ function createKeyServerService({ fetchImpl = globalThis.fetch } = {}) {
return parsePublicKeys(armored, email);
}
async function lookupEnabled(serverInputs, emailInput) {
const servers = serverInputs.filter(server => server.enabled === true);
if (!servers.length) throw new Error('Enable at least one key server before searching.');
const email = validateEmail(emailInput);
const lookups = await Promise.all(servers.map(async server => {
try {
return { server, keys: await lookup(server, email), error: null };
} catch (error) {
return { server, keys: [], error: error.message };
}
}));
const keysByFingerprint = new Map();
for (const result of lookups) {
for (const key of result.keys) {
const existing = keysByFingerprint.get(key.fingerprint);
if (existing) existing.sources.push(result.server.name);
else keysByFingerprint.set(key.fingerprint, { ...key, sources: [result.server.name] });
}
}
return {
keys: [...keysByFingerprint.values()],
searchedServers: lookups.map(({ server }) => ({ id: server.id, name: server.name })),
errors: lookups.filter(result => result.error).map(({ server, error }) => ({
id: server.id,
name: server.name,
message: error
}))
};
}
async function publishVks(server, email, armoredKey, expectedFingerprint) {
const { response, text } = await request(server, endpoint(server, 'vks/v1/upload'), {
method: 'POST',
@@ -230,7 +264,7 @@ function createKeyServerService({ fetchImpl = globalThis.fetch } = {}) {
return publishHkp(server, keys[0].armoredKey);
}
return { lookup, publish };
return { lookup, lookupEnabled, publish };
}
module.exports = {