Client side atproto account migrator in your web browser, along with services for backups and adversarial migrations. pdsmoover.com
README.md

@pds-moover/moover #

cow

This is the core logic that runs PDS MOOver. With this you should be able to create your own "PDS MOOver" without having to figure out the atproto logic.

It is platform agnostic: plain TypeScript on top of fetch and WebCrypto, so it runs in a browser, in Node (19+) or anywhere else that has those. It never stores anything and never signs anyone in on its own. You hand it sessions, and it tells you when there is something worth saving.

pnpm add @pds-moover/moover

ESM only.

What is in the box #

Bring your own session #

Anything that acts on the user's current account takes an AccountAgent:

interface AccountAgent {
  readonly did: string
  fetchHandler(pathname: string, init?: RequestInit): Promise<Response>
}

An OAuth session from @atproto/oauth-client-browser (or -node) is one, and so is a PasswordSession from @atproto/lex-password-session. The package does not care which.

import { Migrator } from '@pds-moover/moover'
import { PasswordSession } from '@atproto/lex-password-session'

// In the PDS MOOver web ui this is the user's OAuth session. A password session works the same.
const current = await PasswordSession.login({
  service: 'https://old.pds.example',
  identifier: 'alice.old.pds.example',
  password: '...',
})

const migrator = new Migrator()
migrator.useOldSession(current)

// Persist the destination session if you want to resume after a restart
migrator.onSessionUpdate = data => save(data)

await migrator.migrate({
  newPdsUrl: 'https://new.pds.example',
  newEmail: 'alice@example.com',
  newHandle: 'alice.new.pds.example',
  newPassword: '...',
  statusUpdateHandler: status => console.log(status),
})

// migrate() asked the old PDS to email a PLC token. Once the user has it:
const keys = await migrator.getRotationKeyContext()
await migrator.signPlcOperation(token, [...myOwnKeys, ...keys.newPdsKeys])

// The move is done. Turning the old account off is its own, best-effort step.
await migrator.tryDeactivateOldAccount()

The destination account is always a password session the migrator creates itself (it is the one creating the account).

Other things you can plug in #

  • Where Restore keeps its temporary key. Restore puts a temporary verification key on the identity while it recovers an account. Pass a TempKeyStore as the third constructor argument to keep that key across restarts, so a retry reuses it. The default (MemoryTempKeyStore) only lasts as long as the object.
  • Which network services it talks to. setEndpoints({ plcDirectoryUrl, slingshotUrl, dohUrl, publicApiUrl }) points the package at a private PLC directory, your own slingshot, or a mock. Call it before creating services.

Upgrading from 1.x #

2.0 is a breaking release.

  • No more handle and password for the current account. Migrator.loginPreflight and migrate no longer log in to the old PDS. Call useOldSession(agent) first. BackupService.loginAndStatus is replaced by useSession(agent) and getRepoStatusOrNull(); MissingBlobs gains useCurrentSession(agent).
  • migrate() takes an options object instead of 12 positional parameters.
  • signPlcOperation(token, rotationKeys) takes the complete rotation key list, in priority order, instead of extra keys to add. Build it from getRotationKeyContext() so keys already on the identity are not dropped by accident.
  • signPlcOperation no longer deactivates the old account. Call tryDeactivateOldAccount() afterwards (or deactivateOldAccount() with the old password). Do it only once no blobs are left behind: countBlobsLeftBehind() tells you.
  • restoreSessions(old, new) is now restoreNewSession(new). Only the destination session is the package's to restore.
  • ESM only. The UMD/CommonJS bundle is gone, and dependencies are no longer bundled into the output.