"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildIPFSClient = buildIPFSClient;
exports.retrieveValueFromIPFS = retrieveValueFromIPFS;
exports.storeValueInIPFS = storeValueInIPFS;
var tslib_1 = require("tslib");
var sdk_1 = tslib_1.__importDefault(require("@pinata/sdk"));
var axios_1 = tslib_1.__importDefault(require("axios"));
function buildIPFSClient(APIKey, secretAPIKey) {
    return new sdk_1.default(APIKey, secretAPIKey);
}
function retrieveValueFromIPFS(contentHash, publicGatewayURL) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var result;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, axios_1.default.get("".concat(publicGatewayURL, "/ipfs/").concat(contentHash), {
                        headers: {
                            Accept: "text/plain",
                        },
                        transformResponse: function (r) { return r; },
                    })];
                case 1:
                    result = _a.sent();
                    return [2, result.data];
            }
        });
    });
}
function storeValueInIPFS(key, content, client) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var result;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, client.pinJSONToIPFS(JSON.parse(content), {
                        pinataMetadata: {
                            name: key,
                        },
                    })];
                case 1:
                    result = _a.sent();
                    return [2, result.IpfsHash];
            }
        });
    });
}
//# sourceMappingURL=IPFSUtils.js.map