OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-proto-peer / test / onboard.test.js

35 lines · javascript ref:
// Onboarding invariants (bin/hpp-onboard.js core): a hyperident-rooted account provisions a
// DETERMINISTIC, device-INDEPENDENT DID (so N devices share one DID), each device gets its OWN
// keet attestation, and the device bundle NEVER carries the root mnemonic (recovery stays with root).

import '../lib/bare-globals.js'
import test from 'brittle'
import b4a from 'b4a'
import IdentityKey from 'keet-identity-key'
import { provisionDevice } from '../lib/device-node.js'
import { deviceKeetKeyPair } from 'atproto-room/lib/membership.js'

// standard BIP39 test vector (valid checksum) — never a real identity
const ROOT = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
const HANDLE = 'x.7rnx.net'
const PDS = 'https://pds.7rnx.net'

async function provisionFreshDevice () {
  const deviceMnemonic = IdentityKey.generateMnemonic()
  const dk = await deviceKeetKeyPair(deviceMnemonic)
  const bundle = await provisionDevice({ rootMnemonic: ROOT, devicePublicKey: b4a.toString(dk.publicKey, 'hex'), handle: HANDLE, pdsUrl: PDS })
  return bundle
}

test('onboard: DID is deterministic + device-independent; bundle omits the root', async (t) => {
  const b1 = await provisionFreshDevice()
  t.ok(b1.did.startsWith('did:plc:'), 'mints a did:plc')
  t.ok(b1.signingKey && b1.deviceProof && b1.rootIdentityKey && b1.signedOp, 'bundle carries signing key + attestation + genesis op')
  t.absent(b1.rootMnemonic, 'bundle NEVER carries the root mnemonic (device cannot derive recovery)')

  const b2 = await provisionFreshDevice()
  t.is(b2.did, b1.did, 'same root+handle+pds → SAME DID (device-independent) — one DID across N devices')
  t.is(b2.signingKey, b1.signingKey, 'shared #atproto signing key is the same across devices')
  t.not(b2.deviceProof, b1.deviceProof, 'but each device gets its OWN keet attestation')
})