Skip to content

Commit

Permalink
add recovery key to migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Feb 22, 2024
1 parent 3810cfb commit 2402759
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ACCOUNT_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ It does also not handle some of the more advanced steps such as verifying a full

```ts
import AtpAgent from '@atproto/api'
import { Secp256k1Keypair } from '@atproto/crypto'
import * as ui8 from 'uint8arrays'

const OLD_PDS_URL = 'https://bsky.social'
const NEW_PDS_URL = 'https://example.com'
Expand Down Expand Up @@ -158,19 +160,35 @@ const migrateAccount = async () => {
// Migrate Identity
// ------------------

const recoveryKey = await Secp256k1Keypair.create({ exportable: true })
const privateKeyBytes = await recoveryKey.export()
const privateKey = ui8.toString(privateKeyBytes, 'hex')

await oldAgent.com.atproto.identity.requestPlcOperationSignature()

const getDidCredentials =
await newAgent.com.atproto.identity.getRecommendedDidCredentials()
const rotationKeys = getDidCredentials.data.rotationKeys ?? []
if (!rotationKeys) {
throw new Error('No rotation key provided')
}
const credentials = {
...getDidCredentials.data,
rotationKeys: [recoveryKey.did(), ...rotationKeys],
}

// @NOTE, this token will need to come from the email from the previous step
const TOKEN = ''

const plcOp = await oldAgent.com.atproto.identity.signPlcOperation({
token: TOKEN,
...getDidCredentials.data,
...credentials,
})

console.log(
`❗ Your private recovery key is: ${privateKey}. Please store this in a secure location! ❗`,
)

await newAgent.com.atproto.identity.submitPlcOperation({
operation: plcOp.data.operation,
})
Expand All @@ -181,4 +199,5 @@ const migrateAccount = async () => {
await newAgent.com.atproto.server.activateAccount()
await oldAgent.com.atproto.server.deactivateAccount({})
}

```

0 comments on commit 2402759

Please sign in to comment.