+async function buildSignedRequestOptions (payload: ActivityPubHttpPayload) {
+ let actor: ActorModel
+ if (payload.signatureActorId) {
+ actor = await ActorModel.load(payload.signatureActorId)
+ if (!actor) throw new Error('Unknown signature actor id.')
+ } else {
+ // We need to sign the request, so use the server
+ actor = await getServerActor()
+ }
+
+ const keyId = actor.getWebfingerUrl()
+ return {
+ algorithm: 'rsa-sha256',
+ authorizationHeaderName: 'Signature',
+ keyId,
+ key: actor.privateKey
+ }
+}
+