diff --git a/CHANGES.md b/CHANGES.md index 51e4d299..e8cbdcbf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -34,6 +34,9 @@ To be released. - `Context.sendActivity()` method now throws `TypeError` instead of silently failing when the given `Activity` object lacks the actor property. + - `Context.sendActivity()` method now uses an authenticated document + loader under the hood. + - Added outbox error handler to `Federation`. - Added `onOutboxError` option to `new Federation()` constructor. diff --git a/federation/middleware.ts b/federation/middleware.ts index 2105b74b..24b252cd 100644 --- a/federation/middleware.ts +++ b/federation/middleware.ts @@ -198,15 +198,20 @@ export class Federation { async #listenQueue(message: OutboxMessage): Promise { let activity: Activity | null = null; try { + const keyId = new URL(message.keyId); + const privateKey = await importJwk(message.privateKey, "private"); + const documentLoader = this.#authenticatedDocumentLoaderFactory( + { keyId, privateKey }, + ); activity = await Activity.fromJsonLd(message.activity, { - documentLoader: this.#documentLoader, + documentLoader, }); await sendActivity({ - keyId: new URL(message.keyId), - privateKey: await importJwk(message.privateKey, "private"), + keyId, + privateKey, activity, inbox: new URL(message.inbox), - documentLoader: this.#documentLoader, + documentLoader, }); } catch (e) { try { @@ -721,6 +726,9 @@ export class Federation { preferSharedInbox, }); if (immediate || this.#queue == null) { + const documentLoader = this.#authenticatedDocumentLoaderFactory( + { keyId, privateKey }, + ); const promises: Promise[] = []; for (const inbox of inboxes) { promises.push( @@ -729,7 +737,7 @@ export class Federation { privateKey, activity, inbox, - documentLoader: this.#documentLoader, + documentLoader, }), ); }