OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-base / lib / label.js

22 lines · javascript ref:
// The LABEL projection — a group/team labeler is just atproto-base projecting com.atproto.label
// instead of repo commits (see DESIGN.md §labeler). A label is a standalone DAG-CBOR-signed object
// (no prev-chain, no MST — easier than commits); the only determinism risk is `cts`, which MUST be
// deterministic (log-derived, like `rev`) so co-owner mods produce byte-identical labels. Retraction
// is a `neg:true` label, never a delete (ozone model).

import { signObject, verifyObject } from './sign.js'

// Project + sign one label deterministically from a moderation decision in the shared view.
// `cts` is a deterministic ISO datetime derived from the mod-event's log position (NOT wall-clock).
export async function projectLabel ({ src, uri, val, cts, neg = false, cid = null, ver = 1, privateKey }) {
  const unsigned = { ver, src, uri, val, cts }
  if (cid) unsigned.cid = cid
  if (neg) unsigned.neg = true
  return { ...unsigned, sig: await signObject(unsigned, privateKey) }
}

export async function verifyLabel (label, publicKey) {
  const { sig, ...unsigned } = label
  return verifyObject(unsigned, sig, publicKey)
}