@e280/authlocal
Version:
User-sovereign login system for everybody
44 lines • 1.55 kB
JavaScript
import { signal } from "@benev/slate";
import { Tabby } from "../../common/tabby/view.js";
import { okErr, problematize } from "../../../../tools/errors.js";
import { dedupeIdentities, seedRecover } from "../../../../trust/exports/authority.js";
export class Intake {
tabby = new Tabby(0);
problems = signal([]);
identities = signal([]);
constructor() {
this.tabby.on(() => this.clear());
}
clear() {
this.problems.value = [];
this.identities.value = [];
}
addProblems(...probs) {
this.problems.value = [...this.problems.value, ...probs];
}
async #hydrate(seedtext) {
const promises = seedRecover(seedtext);
const { ok, err } = await okErr(promises);
this.addProblems(...err.map(problematize));
return ok;
}
async ingestFiles(files) {
this.clear();
this.tabby.goto(0); // upload tab
const identities = [];
for (const file of files) {
const seedtext = await file.text();
const idents = await this.#hydrate(seedtext);
identities.push(...idents);
}
this.identities.value = dedupeIdentities(identities);
}
async ingestSeedText(seedtext) {
this.clear();
const identities = await this.#hydrate(seedtext);
this.identities.value = dedupeIdentities(identities);
if (seedtext.length > 0 && this.identities.value.length === 0)
this.addProblems("No valid seeds detected");
}
}
//# sourceMappingURL=intake.js.map