UNPKG

@ethersphere/bee-js

Version:
43 lines (42 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.upload = void 0; const cafe_utility_1 = require("cafe-utility"); const headers_1 = require("../utils/headers"); const http_1 = require("../utils/http"); const type_1 = require("../utils/type"); const typed_bytes_1 = require("../utils/typed-bytes"); const socEndpoint = 'soc'; /** * Upload single owner chunk (SOC) to a Bee node * * @param requestOptions Options for making requests * @param owner Owner's ethereum address in hex * @param identifier Arbitrary identifier in hex * @param signature Signature in hex * @param data Content addressed chunk data to be uploaded * @param postageBatchId Postage BatchId that will be assigned to uploaded data * @param options Additional options like tag, encryption, pinning */ async function upload(requestOptions, owner, identifier, signature, data, stamp, options) { const response = await (0, http_1.http)(requestOptions, { method: 'post', url: `${socEndpoint}/${owner}/${identifier}`, data, headers: { 'content-type': 'application/octet-stream', ...(0, headers_1.prepareRequestHeaders)(stamp, options), }, responseType: 'json', params: { sig: signature.toHex() }, }); const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' }); return { reference: new typed_bytes_1.Reference(cafe_utility_1.Types.asHexString(body.reference)), tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined, historyAddress: response.headers['swarm-act-history-address'] ? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address'])) : cafe_utility_1.Optional.empty(), }; } exports.upload = upload;