Include whitelist in trusted seed bootstrap

This commit is contained in:
thePR0M3TH3AN committed 2025-10-24 23:01:24 -04:00
1 parent c3c87b810f
commit 1fc4624596
3 files changed
+134 -6

No files matched your search

+54 -6
View File
@@ -5,23 +5,71 @@ import {
DEFAULT_TRUST_SEED_NPUBS,
FEATURE_TRUST_SEEDS,
} from "./constants.js";
import { accessControl } from "./accessControl.js";
import moderationService from "./services/moderationService.js";
import nostrService from "./services/nostrService.js";
import r2Service from "./services/r2Service.js";
import { loadView } from "./viewManager.js";
if (
FEATURE_TRUST_SEEDS &&
moderationService &&
typeof moderationService.setTrustedSeeds === "function"
) {
function mergeSeedsWithWhitelist(source) {
const seeds = new Set(DEFAULT_TRUST_SEED_NPUBS);
if (source && typeof source[Symbol.iterator] === "function") {
for (const value of source) {
if (typeof value !== "string") {
continue;
}
const trimmed = value.trim();
if (trimmed) {
seeds.add(trimmed);
}
}
}
return seeds;
}
async function bootstrapTrustedSeeds() {
if (
!(
FEATURE_TRUST_SEEDS &&
moderationService &&
typeof moderationService.setTrustedSeeds === "function"
)
) {
return;
}
const applySeeds = (whitelist = null) => {
try {
const merged = mergeSeedsWithWhitelist(
whitelist ?? accessControl?.getWhitelist?.()
);
moderationService.setTrustedSeeds(merged);
} catch {
// Swallow bootstrap errors so login flow can continue; flag enables quick rollback.
}
};
try {
moderationService.setTrustedSeeds(DEFAULT_TRUST_SEED_NPUBS);
if (accessControl && typeof accessControl.ensureReady === "function") {
await accessControl.ensureReady();
}
} catch {
// Swallow bootstrap errors so login flow can continue; flag enables quick rollback.
}
applySeeds();
if (accessControl && typeof accessControl.onWhitelistChange === "function") {
accessControl.onWhitelistChange((nextWhitelist) => {
applySeeds(nextWhitelist);
});
}
}
bootstrapTrustedSeeds();
function mergeServices(overrides = {}) {
const merged = { nostrService, r2Service };