From 2d4ac7a81a0a2e65a510951921630ed27a58ed75 Mon Sep 17 00:00:00 2001 From: dholms Date: Tue, 12 Mar 2024 15:15:44 -0500 Subject: [PATCH 1/2] clean up plc op submission --- .../api/com/atproto/identity/submitPlcOperation.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/pds/src/api/com/atproto/identity/submitPlcOperation.ts b/packages/pds/src/api/com/atproto/identity/submitPlcOperation.ts index 66db47fe482..13ba7bc07da 100644 --- a/packages/pds/src/api/com/atproto/identity/submitPlcOperation.ts +++ b/packages/pds/src/api/com/atproto/identity/submitPlcOperation.ts @@ -3,6 +3,7 @@ import AppContext from '../../../../context' import * as plc from '@did-plc/lib' import { check } from '@atproto/common' import { InvalidRequestError } from '@atproto/xrpc-server' +import { httpLogger as log } from '../../../../logger' export default function (server: Server, ctx: AppContext) { server.com.atproto.identity.submitPlcOperation({ @@ -15,7 +16,9 @@ export default function (server: Server, ctx: AppContext) { throw new InvalidRequestError('Invalid operation') } - if (!op.rotationKeys.includes(ctx.plcRotationKey.did())) { + const rotationKey = + ctx.cfg.entryway?.plcRotationKey ?? ctx.plcRotationKey.did() + if (!op.rotationKeys.includes(rotationKey)) { throw new InvalidRequestError( "Rotation keys do not include server's rotation key", ) @@ -43,6 +46,15 @@ export default function (server: Server, ctx: AppContext) { } await ctx.plcClient.sendOperation(requester, op) + await ctx.sequencer.sequenceIdentityEvt(requester) + try { + await ctx.idResolver.did.resolve(requester, true) + } catch (err) { + log.error( + { err, did: requester }, + 'failed to refresh did after plc update', + ) + } }, }) } From 70317de82ef6a666311fd05dba6a9cd743cf04fb Mon Sep 17 00:00:00 2001 From: dholms Date: Tue, 12 Mar 2024 15:22:06 -0500 Subject: [PATCH 2/2] test --- packages/pds/tests/plc-operations.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/pds/tests/plc-operations.test.ts b/packages/pds/tests/plc-operations.test.ts index 9c4ed9002cb..9c90b3482ff 100644 --- a/packages/pds/tests/plc-operations.test.ts +++ b/packages/pds/tests/plc-operations.test.ts @@ -223,4 +223,16 @@ describe('plc operations', () => { const didData = await ctx.plcClient.getDocumentData(alice) expect(didData.rotationKeys).toEqual([sampleKey, ctx.plcRotationKey.did()]) }) + + it('emits an identity event after a valid operation', async () => { + const lastEvt = await ctx.sequencer.db.db + .selectFrom('repo_seq') + .selectAll() + .orderBy('repo_seq.seq', 'desc') + .limit(1) + .executeTakeFirst() + assert(lastEvt) + expect(lastEvt.did).toBe(alice) + expect(lastEvt.eventType).toBe('identity') + }) })