attestationSubject

tcmts.cli.attest.attestationSubject · #rsqmsfbk · term · runs anywhere

What what is, to attest: a library here (its name or mount), a release announced by someone (@alice.dev/geo@1.2.0), a release of this codebase (geo@1.2.0), or a namespace by its whole hash (#…).

import { resolveAnnounced } from "#codebase/tcmts/cli/announce";
import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { libraryNamed, releaseNamespace } from "#codebase/tcmts/cli/libraries";
import { UsageError } from "#codebase/tcmts/cli/ui";
import type { AttestationSubject } from "#codebase/tcmts/records";

export async function attestationSubject(cb: Codebase, what: string): Promise<AttestationSubject> {
  if (what.startsWith("#")) return { namespace: what.replace(/^#+/, "") };
  if (what.startsWith("@")) {
    const slash = what.indexOf("/");
    if (slash < 0)
      throw new UsageError(`'${what}' names no release: @<handle>/<package>@<version>`);
    const { id, record } = await resolveAnnounced(what.slice(1, slash), what.slice(slash + 1));
    return {
      namespace: record.namespace,
      release: `${record.package}@${record.version}`,
      author: id.did,
    };
  }
  const at = what.lastIndexOf("@");
  const own = at > 0 ? cb.store.release(what.slice(0, at), what.slice(at + 1)) : undefined;
  if (own)
    return {
      namespace: await releaseNamespace(cb.store, own),
      release: `${own.package}@${own.version}`,
    };
  const lib = libraryNamed(cb.store, what);
  return {
    namespace: lib.namespace,
    ...(lib.release ? { release: lib.release } : {}),
    ...(lib.did ? { author: lib.did } : {}),
  };
}

uses

used by