attestationsFor

tcmts.cli.attest.attestationsFor · #qemce6rp · term · runs on the server

uses tcmts.cli.style.dim, which uses node:util

The attestations to show for some code: its author's (theirs alone count as yanks), and those of the people the codebase trusts. One who can't be read is said, and skipped.

import { resolveIdentity } from "#codebase/tcmts/atproto";
import { attestationsBy, trustedIn } from "#codebase/tcmts/cli/attest";
import type { FoundAttestation } from "#codebase/tcmts/cli/attest";
import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { dim } from "#codebase/tcmts/cli/style";

export async function attestationsFor(
  cb: Codebase,
  namespaces: string[],
  author: string | undefined,
): Promise<FoundAttestation[]> {
  const dids = [...new Set([...(author ? [author] : []), ...trustedIn(cb).map((t) => t.did)])];
  const out: FoundAttestation[] = [];
  for (const did of dids) {
    try {
      out.push(...(await attestationsBy(await resolveIdentity(did), new Set(namespaces))));
    } catch (e) {
      console.log(
        dim(`  couldn't read ${did}'s attestations: ${(e as Error).message.split("\n")[0]}`),
      );
    }
  }
  return out.filter(
    (a) =>
      a.kind !== "yank" ||
      (author !== undefined && a.did === author && a.subject.author === author),
  );
}

uses

used by