OverviewFilesCommitsIssuesDocsReleasesPeers

favela-android / lib / hosting.js

37 lines · javascript ref:
// Accepting a bridge's invite, FROM THE PHONE — using the vault mint already sealed.
//
// The ceremony needs the recovery key, and a PLC update must be signed by a current rotation key, which
// for a swarm identity is exactly one: the root recovery key. mint seals that under a passphrase at
// creation time precisely so it can be used again later without anyone re-typing 24 words. This is the
// "later".
//
// ⛔ THE PASSPHRASE IS THE ONLY THING THAT CROSSES THE BRIDGE. The page collects it; the worklet opens
// the vault, derives the key, signs and submits. The mnemonic never reaches React Native, never reaches
// the WebView, and never reaches a log line. Same rule as mint, for the same reason.
//
// ⛔ PREVIEW FIRST, ALWAYS. A PLC append is permanent and public, so the handler previews unless told to
// submit — the shape hosting-cli.js established and the one a web UI needs, because a confirm screen is
// only honest if the thing it describes is the thing that will happen.

import path from 'bare-path'

export { attachHosting, detachHosting } from 'atproto-identity/lib/hosting.js'
export { describeChange, resolveSigner, hostingAttach, hostingDetach, hostingShow } from 'hyper-proto-peer/lib/hosting-cli.js'

/**
 * Where mint sealed this identity's recovery vault.
 *
 * Pure, and separate from the handler, because "can this phone accept an invite at all?" is answerable
 * without opening anything — a UI needs to know whether to offer the control before it asks for a
 * passphrase, and offering a control that cannot work is the bug this whole evening kept producing.
 *
 * Named by the DID's own suffix rather than a single vault.json: one device may hold several identities,
 * and a shared filename silently means "the last one minted".
 */
export function vaultPathFor (hppDir, did) {
  if (!hppDir || !did) throw new Error('vaultPathFor: hppDir and did required')
  const suffix = String(did).split(':').pop()
  if (!suffix) throw new Error('vaultPathFor: malformed did ' + did)
  return path.join(hppDir, 'recovery', suffix + '.vault.json')
}