OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-identity / lib / attested-anchor.js

43 lines · javascript ref:
// Compose the full device-attested atproto anchor — both worlds, from one root + one
// device. See docs/ATPROTO-P2P-BRIDGE.md (device attestation) and §13 (purity firewall).
//
//   atproto (federation-visible): genesis with rotationKeys=[root secp256k1] +
//                                 verificationMethod=[device secp256k1], signed by root.
//   keet   (P2P-verifiable):      root → device(Ed25519) → vouches-for(did).
//
// The ROOT box (holds rootMnemonic) signs the genesis + attests the device. The DEVICE box
// only ever needs `deviceSigningKey` (secp256k1) to run the PDS. In production the device
// derives its own keys and sends only PUBLIC keys to the root — use buildAttestedIdentity
// with `deviceDidKey` for that path; this helper takes both mnemonics for the end-to-end
// (dev / single-operator) case.

import { buildAttestedIdentity } from './device-attestation.js'
import { deviceKeetKeyPair, attestDeviceChain, attestAtprotoBinding } from './device-chain.js'

export async function buildAttestedAnchor ({
  rootMnemonic, rootSeed,
  deviceMnemonic, deviceSeed, devicePath,
  handle, pdsUrl,
  extraRotationDidKeys = []
}) {
  // atproto side — the permanent, PLC-bound genesis
  const atp = buildAttestedIdentity({ rootMnemonic, deviceMnemonic, devicePath, handle, pdsUrl, extraRotationDidKeys })

  // keet side — the P2P attestation binding the DID to the root identity
  const deviceKeet = await deviceKeetKeyPair(deviceMnemonic, deviceSeed)
  const chain = await attestDeviceChain({ rootMnemonic, rootSeed, devicePublicKey: deviceKeet.publicKey })
  const keetProof = attestAtprotoBinding({ deviceKeyPair: deviceKeet, did: atp.did, proof: chain })

  return {
    did: atp.did,
    handle,
    pdsUrl,
    signedOp: atp.signedOp, // → the one irreversible PLC write publishes this
    rootDidKey: atp.rootDidKey, // secp256k1 rotation (authority/recovery — root box)
    deviceDidKey: atp.deviceDidKey, // secp256k1 signing (verificationMethod — device box)
    deviceSigningKey: atp.deviceSigningKey, // { privateKey, … } — all the PDS needs to sign commits
    deviceKeetPublicKey: deviceKeet.publicKey, // Ed25519 device identity (P2P)
    keetProof // P2P-verifiable: chain resolves to root, device vouches for did
  }
}