1 import { buildDigest } from '@server/helpers/peertube-crypto'
2 import { doRequest } from '@server/helpers/requests'
3 import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants'
4 import { activityPubContextify } from '@server/lib/activitypub/context'
6 export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
8 method: 'POST' as 'POST',
14 return doRequest(url, options)
17 export async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
20 id: by.url + '/' + new Date().getTime(),
25 const body = activityPubContextify(follow, 'Follow')
27 const httpSignature = {
28 algorithm: HTTP_SIGNATURE.ALGORITHM,
29 authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
32 headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
35 'digest': buildDigest(body),
36 'content-type': 'application/activity+json',
37 'accept': ACTIVITY_PUB.ACCEPT_HEADER
40 return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers)