UNPKG

@ethersphere/bee-js

Version:
40 lines 1.62 kB
import { Optional, Types } from 'cafe-utility'; import { prepareRequestHeaders } from "../utils/headers.js"; import { http } from "../utils/http.js"; import { makeTagUid } from "../utils/type.js"; import { Reference } from "../utils/typed-bytes.js"; 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 */ export async function upload(requestOptions, owner, identifier, signature, data, stamp, options) { const response = await http(requestOptions, { method: 'post', url: `${socEndpoint}/${owner}/${identifier}`, data, headers: { 'content-type': 'application/octet-stream', ...prepareRequestHeaders(stamp, options) }, responseType: 'json', params: { sig: signature.toHex() } }); const body = Types.asObject(response.data, { name: 'response.data' }); return { reference: new Reference(Types.asHexString(body.reference)), tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined, historyAddress: response.headers['swarm-act-history-address'] ? Optional.of(new Reference(response.headers['swarm-act-history-address'])) : Optional.empty() }; }