From 2def9b867539524f23a9c779cdfe6d3bd947554f Mon Sep 17 00:00:00 2001 From: "casey.nstar.social" Date: Mon, 15 Sep 2025 12:20:15 -0700 Subject: [PATCH] Implement merging of existing services, verification methods, and alt handles for plc operations --- src/pdsmoover.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/pdsmoover.js b/src/pdsmoover.js index 303184f..2ee7b6c 100644 --- a/src/pdsmoover.js +++ b/src/pdsmoover.js @@ -249,19 +249,50 @@ class Migrator { async signPlcOperation(token) { const getDidCredentials = await this.newAgent.com.atproto.identity.getRecommendedDidCredentials(); - const rotationKeys = getDidCredentials.data.rotationKeys ?? []; + const rotationKeys = getDidCredentials.data.rotationKeys; if (!rotationKeys) { throw new Error('No rotation key provided from the new PDS'); } - const credentials = { - ...getDidCredentials.data, - rotationKeys: rotationKeys, + const oldDidDoc = await docResolver.resolve(this.oldAgent.did); + + // Format the service(s) in the user's DidDocument into the operation syntax + let oldServices = {}; + for(const service of oldDidDoc.service) { + const idComponents = service.id.split('#'); + oldServices[idComponents[idComponents.length - 1]] = { + type: service.type, + endpoint: service.serviceEndpoint + }; + }; + // Combine old & new suggested services + const services = { + ...oldServices, // Existing services in the user's DidDocument + ...getDidCredentials.data.services // Service(s) suggested by the new PDS + }; + + // Format the verification method(s) in the user's DidDocument into the operation syntax + let oldVerificationMethods = {}; + for(const verificationMethod of oldDidDoc.verificationMethod) { + const idComponents = verificationMethod.id.split('#'); + oldVerificationMethods[idComponents[idComponents.length - 1]] = `did:key:${verificationMethod.publicKeyMultibase}` // PLC Operation verification methods are did:keys + }; + // Combine old & new suggested verification methods + const verificationMethods = { + ...oldVerificationMethods, // Existing verification methods in the user's DidDocument + ...getDidCredentials.data.verificationMethods // Verification method(s) suggested by the new PDS }; - + const alsoKnownAs = [ + ...getDidCredentials.data.alsoKnownAs, // Suggested alsoKnownAs goes first (the first entry is the user's primary handle) + ...oldDidDoc.alsoKnownAs.slice(1) // Pre-existing alsoKnownAs, minus the old primary handle + ]; + const plcOp = await this.oldAgent.com.atproto.identity.signPlcOperation({ token: token, - ...credentials, + rotationKeys: rotationKeys, // Replace rotation keys + alsoKnownAs: alsoKnownAs, // Merged alsoKnownAs + services: services, // Merged services + verificationMethods: verificationMethods, // Merged verification methods }); await this.newAgent.com.atproto.identity.submitPlcOperation({ -- 2.43.0