UNPKG

@lighthouse-web3/sdk

Version:

NPM package and CLI tool to interact with lighthouse protocol

25 lines (24 loc) 956 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* istanbul ignore file */ const encryptionNode_1 = require("../encryptionNode"); const lighthouse_config_1 = require("../../../lighthouse.config"); const util_1 = require("../../utils/util"); exports.default = async (cid, fileEncryptionKey) => { try { const response = await (0, util_1.fetchWithTimeout)(lighthouse_config_1.lighthouseConfig.lighthouseGateway + '/api/v0/cat/' + cid, { method: 'POST', timeout: 7200000, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const arrayBuffer = await response.arrayBuffer(); const result = Buffer.from(arrayBuffer); const decrypted = await (0, encryptionNode_1.decryptFile)(result, fileEncryptionKey); return decrypted; } catch (error) { throw new Error(error.message); } };