···
async signPlcOperation(token) {
const getDidCredentials =
await this.newAgent.com.atproto.identity.getRecommendedDidCredentials();
252
-
const rotationKeys = getDidCredentials.data.rotationKeys ?? [];
252
+
const rotationKeys = getDidCredentials.data.rotationKeys;
throw new Error('No rotation key provided from the new PDS');
256
-
const credentials = {
257
-
...getDidCredentials.data,
258
-
rotationKeys: rotationKeys,
256
+
const oldDidDoc = await docResolver.resolve(this.oldAgent.did);
258
+
// Format the service(s) in the user's DidDocument into the operation syntax
259
+
let oldServices = {};
260
+
for(const service of oldDidDoc.service) {
261
+
const idComponents = service.id.split('#');
262
+
oldServices[idComponents[idComponents.length - 1]] = {
263
+
type: service.type,
264
+
endpoint: service.serviceEndpoint
267
+
// Combine old & new suggested services
269
+
...oldServices, // Existing services in the user's DidDocument
270
+
...getDidCredentials.data.services // Service(s) suggested by the new PDS
273
+
// Format the verification method(s) in the user's DidDocument into the operation syntax
274
+
let oldVerificationMethods = {};
275
+
for(const verificationMethod of oldDidDoc.verificationMethod) {
276
+
const idComponents = verificationMethod.id.split('#');
277
+
oldVerificationMethods[idComponents[idComponents.length - 1]] = `did:key:${verificationMethod.publicKeyMultibase}` // PLC Operation verification methods are did:keys
279
+
// Combine old & new suggested verification methods
280
+
const verificationMethods = {
281
+
...oldVerificationMethods, // Existing verification methods in the user's DidDocument
282
+
...getDidCredentials.data.verificationMethods // Verification method(s) suggested by the new PDS
285
+
const alsoKnownAs = [
286
+
...getDidCredentials.data.alsoKnownAs, // Suggested alsoKnownAs goes first (the first entry is the user's primary handle)
287
+
...oldDidDoc.alsoKnownAs.slice(1) // Pre-existing alsoKnownAs, minus the old primary handle
const plcOp = await this.oldAgent.com.atproto.identity.signPlcOperation({
292
+
rotationKeys: rotationKeys, // Replace rotation keys
293
+
alsoKnownAs: alsoKnownAs, // Merged alsoKnownAs
294
+
services: services, // Merged services
295
+
verificationMethods: verificationMethods, // Merged verification methods
await this.newAgent.com.atproto.identity.submitPlcOperation({