OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-base / test / labeler.test.mjs

32 lines · javascript ref:
// TEST 7 — a group/team labeler as atproto-base projecting labels: two co-owner MODS, given the same
// moderation decision (from the shared view), produce a BYTE-IDENTICAL signed label. Same guarantee
// as commits (test 1) — deterministic projection + RFC6979 → no signer election, no fork — applied to
// com.atproto.label. This is the P2P analog of ozone's central team-labeler.

import test from 'brittle'
import { deriveAtprotoKey, createAtprotoIdentity } from 'atproto-identity'
import { projectLabel, verifyLabel } from '../lib/label.js'

const MNEMONIC = 'test test test test test test test test test test test junk'

test('two co-owner mods project a byte-identical signed label (labeler = atproto-base projecting labels)', async (t) => {
  const id = createAtprotoIdentity(MNEMONIC, { handle: 'mod.7rnx.net', pdsUrl: 'https://pds.7rnx.net' })
  const key = deriveAtprotoKey(MNEMONIC) // the shared #atproto_label key

  // A moderation decision folded from the shared view: label a post "spam" at a deterministic cts.
  const decision = { src: id.did, uri: 'at://did:plc:target/app.bsky.feed.post/3xxx', val: 'spam', cts: '2026-07-23T00:00:00.000Z' }

  const A = await projectLabel({ ...decision, privateKey: key.privateKey })
  const B = await projectLabel({ ...decision, privateKey: key.privateKey })

  t.is(Buffer.compare(Buffer.from(A.sig), Buffer.from(B.sig)), 0, 'label signature byte-identical across co-owner mods (RFC6979)')
  t.alike({ ...A, sig: null }, { ...B, sig: null }, 'label fields identical')
  t.ok(await verifyLabel(A, key.publicKey), 'label verifies against the #atproto_label key (consumer would accept)')

  // Retraction = a neg label, never a delete; distinct from the positive label.
  const neg = await projectLabel({ ...decision, neg: true, cts: '2026-07-23T01:00:00.000Z', privateKey: key.privateKey })
  t.ok(neg.neg === true, 'retraction is a neg:true label (append-only, no delete)')
  t.not(Buffer.from(A.sig).toString('hex'), Buffer.from(neg.sig).toString('hex'), 'neg label is a distinct signed object')
  t.ok(await verifyLabel(neg, key.publicKey), 'neg label also verifies')
})