"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeFollowRequest = exports.makePOSTAPRequest = void 0;
const tslib_1 = require("tslib");
const activitypub_1 = require("../../helpers/activitypub");
const peertube_crypto_1 = require("../../helpers/peertube-crypto");
const requests_1 = require("../../helpers/requests");
const constants_1 = require("../../initializers/constants");
function makePOSTAPRequest(url, body, httpSignature, headers) {
    const options = {
        method: 'POST',
        json: body,
        httpSignature,
        headers
    };
    return (0, requests_1.doRequest)(url, options);
}
exports.makePOSTAPRequest = makePOSTAPRequest;
function makeFollowRequest(to, by) {
    return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
        const follow = {
            type: 'Follow',
            id: by.url + '/' + new Date().getTime(),
            actor: by.url,
            object: to.url
        };
        const body = (0, activitypub_1.activityPubContextify)(follow);
        const httpSignature = {
            algorithm: constants_1.HTTP_SIGNATURE.ALGORITHM,
            authorizationHeaderName: constants_1.HTTP_SIGNATURE.HEADER_NAME,
            keyId: by.url,
            key: by.privateKey,
            headers: constants_1.HTTP_SIGNATURE.HEADERS_TO_SIGN
        };
        const headers = {
            'digest': (0, peertube_crypto_1.buildDigest)(body),
            'content-type': 'application/activity+json',
            'accept': constants_1.ACTIVITY_PUB.ACCEPT_HEADER
        };
        return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers);
    });
}
exports.makeFollowRequest = makeFollowRequest;
//# sourceMappingURL=requests.js.map