OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-identity / test / lens-export-services.test.js

47 lines · javascript ref:
// Lens-export service entries in the did:plc genesis op — a self-custody feed-generator + labeler
// (e.g. a favela community DID) declares #bsky_fg / #atproto_labeler services + a #atproto_label VM at
// genesis. The PLC op's services/verificationMethods KEYS project to DID-doc fragments. Offline only —
// no PLC submit. (favela-web/spec/lens-export.md §2/§5.)
import test from 'brittle'
import { createSwarmIdentity } from '../lib/atproto-identity.js'
import { checkGenesisOp } from '../lib/plc-directory.js'

const MNEMONIC = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
const HANDLE = 'catlovers.7rnx.net'
const PDS = 'https://pds.7rnx.net'
const MEMBRANE = 'https://pds.7rnx.net'

test('genesis with feed-gen + labeler service entries', (t) => {
  const id = createSwarmIdentity(MNEMONIC, { handle: HANDLE, pdsUrl: PDS, feedGenEndpoint: MEMBRANE, labelerEndpoint: MEMBRANE })
  const op = id.signedOp

  // the PDS service + #atproto VM are unchanged
  t.is(op.services.atproto_pds.type, 'AtprotoPersonalDataServer', 'atproto_pds service preserved')
  t.is(op.verificationMethods.atproto, id.signingKey.didKey, '#atproto VM = the signing key')

  // NEW: feed generator + labeler services (keys → #bsky_fg / #atproto_labeler in the DID doc)
  t.alike(op.services.bsky_fg, { type: 'BskyFeedGenerator', endpoint: MEMBRANE }, '#bsky_fg service points at the membrane')
  t.alike(op.services.atproto_labeler, { type: 'AtprotoLabeler', endpoint: MEMBRANE }, '#atproto_labeler service points at the membrane')
  t.is(op.verificationMethods.atproto_label, id.signingKey.didKey, '#atproto_label VM defaults to the shared #atproto signing key')

  // the op is still a valid, self-consistent genesis (did derives from it)
  t.is(checkGenesisOp(op, id.did).ok, true, 'genesis op still valid with the extra services')
  t.ok(/^did:plc:/.test(id.did), 'did:plc derives')
})

test('a distinct #atproto_label key can be supplied', (t) => {
  const other = createSwarmIdentity('legal winner thank year wave sausage worth useful legal winner thank yellow', { handle: 'x.7rnx.net', pdsUrl: PDS })
  const id = createSwarmIdentity(MNEMONIC, { handle: HANDLE, pdsUrl: PDS, feedGenEndpoint: MEMBRANE, labelerEndpoint: MEMBRANE, labelDidKey: other.signingKey.didKey })
  t.is(id.signedOp.verificationMethods.atproto_label, other.signingKey.didKey, '#atproto_label VM = the supplied distinct key')
})

test('backward-compatible: no extras → plain genesis', (t) => {
  const id = createSwarmIdentity(MNEMONIC, { handle: HANDLE, pdsUrl: PDS })
  const op = id.signedOp
  t.absent(op.services.bsky_fg, 'no #bsky_fg without an endpoint')
  t.absent(op.services.atproto_labeler, 'no #atproto_labeler without an endpoint')
  t.absent(op.verificationMethods.atproto_label, 'no #atproto_label without a labeler/key')
  t.is(Object.keys(op.services).length, 1, 'only the atproto_pds service')
  t.is(checkGenesisOp(op, id.did).ok, true, 'plain genesis still valid')
})