import { getServerActor } from '../../../../helpers/utils'
import { ActorModel } from '../../../../models/activitypub/actor'
import { sha256 } from '../../../../helpers/core-utils'
+import { HTTP_SIGNATURE } from '../../../../initializers'
type Payload = { body: any, signatureActorId?: number }
const keyId = actor.getWebfingerUrl()
return {
- algorithm: 'rsa-sha256',
- authorizationHeaderName: 'Signature',
+ algorithm: HTTP_SIGNATURE.ALGORITHM,
+ authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
keyId,
key: actor.privateKey,
- headers: [ 'date', 'host', 'digest', '(request-target)' ]
+ headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
}
}
-function buildGlobalHeaders (body: object) {
- const digest = 'SHA-256=' + sha256(JSON.stringify(body), 'base64')
-
+function buildGlobalHeaders (body: any) {
return {
- 'Digest': digest
+ 'Digest': buildDigest(body)
}
}
+function buildDigest (body: any) {
+ const rawBody = typeof body === 'string' ? body : JSON.stringify(body)
+
+ return 'SHA-256=' + sha256(rawBody, 'base64')
+}
+
export {
+ buildDigest,
buildGlobalHeaders,
computeBody,
buildSignedRequestOptions