@ethersphere/bee-js 8.1.0 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +27 -1
  2. package/dist/cjs/bee.js +30 -16
  3. package/dist/cjs/chunk/soc.js +4 -6
  4. package/dist/cjs/index.js +1 -0
  5. package/dist/cjs/modules/bytes.js +18 -1
  6. package/dist/cjs/modules/chunk.js +4 -4
  7. package/dist/cjs/modules/envelope.js +23 -0
  8. package/dist/cjs/modules/feed.js +2 -2
  9. package/dist/cjs/modules/grantee.js +2 -2
  10. package/dist/cjs/modules/soc.js +2 -2
  11. package/dist/cjs/utils/cid.js +38 -0
  12. package/dist/cjs/utils/constants.js +6 -0
  13. package/dist/cjs/utils/expose.js +4 -1
  14. package/dist/cjs/utils/headers.js +11 -6
  15. package/dist/cjs/utils/http.js +0 -5
  16. package/dist/cjs/utils/stamps.js +22 -1
  17. package/dist/cjs/utils/tar.browser.js +3 -0
  18. package/dist/cjs/utils/tar.js +3 -0
  19. package/dist/cjs/utils/type.js +5 -9
  20. package/dist/index.browser.min.js +1 -1
  21. package/dist/index.browser.min.js.map +1 -1
  22. package/dist/mjs/bee.js +31 -17
  23. package/dist/mjs/chunk/soc.js +4 -6
  24. package/dist/mjs/index.js +1 -0
  25. package/dist/mjs/modules/bytes.js +16 -0
  26. package/dist/mjs/modules/chunk.js +4 -4
  27. package/dist/mjs/modules/envelope.js +33 -0
  28. package/dist/mjs/modules/feed.js +2 -2
  29. package/dist/mjs/modules/grantee.js +2 -2
  30. package/dist/mjs/modules/soc.js +2 -2
  31. package/dist/mjs/utils/cid.js +33 -0
  32. package/dist/mjs/utils/constants.js +3 -0
  33. package/dist/mjs/utils/expose.js +2 -1
  34. package/dist/mjs/utils/headers.js +10 -6
  35. package/dist/mjs/utils/http.js +0 -7
  36. package/dist/mjs/utils/stamps.js +19 -0
  37. package/dist/mjs/utils/tar.browser.js +3 -0
  38. package/dist/mjs/utils/tar.js +3 -0
  39. package/dist/mjs/utils/type.js +4 -7
  40. package/dist/types/bee.d.ts +10 -3
  41. package/dist/types/chunk/soc.d.ts +2 -2
  42. package/dist/types/index.d.ts +1 -0
  43. package/dist/types/modules/bytes.d.ts +8 -1
  44. package/dist/types/modules/chunk.d.ts +3 -3
  45. package/dist/types/modules/envelope.d.ts +2 -0
  46. package/dist/types/modules/feed.d.ts +1 -1
  47. package/dist/types/modules/soc.d.ts +1 -1
  48. package/dist/types/types/index.d.ts +12 -8
  49. package/dist/types/utils/cid.d.ts +9 -0
  50. package/dist/types/utils/constants.d.ts +4 -0
  51. package/dist/types/utils/expose.d.ts +1 -0
  52. package/dist/types/utils/headers.d.ts +1 -1
  53. package/dist/types/utils/stamps.d.ts +3 -1
  54. package/dist/types/utils/type.d.ts +3 -5
  55. package/package.json +2 -5
package/dist/mjs/bee.js CHANGED
@@ -1,4 +1,3 @@
1
- import { ReferenceType } from '@ethersphere/swarm-cid';
2
1
  import { Objects, System } from 'cafe-utility';
3
2
  import { makeSigner } from "./chunk/signer.js";
4
3
  import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
@@ -20,6 +19,7 @@ import * as states from "./modules/debug/states.js";
20
19
  import * as debugStatus from "./modules/debug/status.js";
21
20
  import * as debugTag from "./modules/debug/tag.js";
22
21
  import * as transactions from "./modules/debug/transactions.js";
22
+ import { postEnvelope } from "./modules/envelope.js";
23
23
  import { createFeedManifest } from "./modules/feed.js";
24
24
  import * as grantee from "./modules/grantee.js";
25
25
  import * as pinning from "./modules/pinning.js";
@@ -61,7 +61,9 @@ export class Bee {
61
61
  baseURL: this.url,
62
62
  timeout: options?.timeout ?? false,
63
63
  headers: options?.headers,
64
- onRequest: options?.onRequest
64
+ onRequest: options?.onRequest,
65
+ httpAgent: options?.httpAgent,
66
+ httpsAgent: options?.httpsAgent
65
67
  };
66
68
  }
67
69
  /**
@@ -84,6 +86,16 @@ export class Bee {
84
86
  }
85
87
  return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
86
88
  }
89
+ /**
90
+ * Requests content length for a `/bytes` reference
91
+ *
92
+ * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
93
+ */
94
+ async probeData(reference, options) {
95
+ assertRequestOptions(options);
96
+ assertReferenceOrEns(reference);
97
+ return bytes.head(this.getRequestOptionsForCall(options), reference);
98
+ }
87
99
  /**
88
100
  * Download data as a byte array
89
101
  *
@@ -125,8 +137,7 @@ export class Bee {
125
137
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
126
138
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
127
139
  */
128
- async uploadChunk(postageBatchId, data, options, requestOptions) {
129
- assertBatchId(postageBatchId);
140
+ async uploadChunk(stamp, data, options, requestOptions) {
130
141
  assertRequestOptions(requestOptions);
131
142
  if (!(data instanceof Uint8Array)) {
132
143
  throw new TypeError('Data has to be Uint8Array instance!');
@@ -140,7 +151,7 @@ export class Bee {
140
151
  if (options) {
141
152
  assertUploadOptions(options);
142
153
  }
143
- return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
154
+ return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
144
155
  }
145
156
  /**
146
157
  * Download chunk as a byte array
@@ -235,14 +246,14 @@ export class Bee {
235
246
  contentType,
236
247
  ...options
237
248
  };
238
- return addCidConversionFunction(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
249
+ return addCidConversionFunction(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions), 'manifest');
239
250
  } else if (isReadable(data) && options?.tag && !options.size) {
240
251
  // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
241
252
  const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
242
253
  await this.updateTag(options.tag, result.reference);
243
- return addCidConversionFunction(result, ReferenceType.MANIFEST);
254
+ return addCidConversionFunction(result, 'manifest');
244
255
  } else {
245
- return addCidConversionFunction(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options), ReferenceType.MANIFEST);
256
+ return addCidConversionFunction(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options), 'manifest');
246
257
  }
247
258
  }
248
259
  /**
@@ -259,7 +270,7 @@ export class Bee {
259
270
  */
260
271
  async downloadFile(reference, path = '', options) {
261
272
  assertRequestOptions(options);
262
- reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
273
+ reference = makeReferenceOrEns(reference, 'manifest');
263
274
  return bzz.downloadFile(this.getRequestOptionsForCall(options), reference, path);
264
275
  }
265
276
  /**
@@ -276,7 +287,7 @@ export class Bee {
276
287
  */
277
288
  async downloadReadableFile(reference, path = '', options) {
278
289
  assertRequestOptions(options);
279
- reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
290
+ reference = makeReferenceOrEns(reference, 'manifest');
280
291
  return bzz.downloadFileReadable(this.getRequestOptionsForCall(options), reference, path);
281
292
  }
282
293
  /**
@@ -302,7 +313,7 @@ export class Bee {
302
313
  assertCollectionUploadOptions(options);
303
314
  }
304
315
  const data = await makeCollectionFromFileList(fileList);
305
- return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
316
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), 'manifest');
306
317
  }
307
318
  /**
308
319
  * Upload Collection that you can assembly yourself.
@@ -319,7 +330,7 @@ export class Bee {
319
330
  assertBatchId(postageBatchId);
320
331
  assertCollection(collection);
321
332
  if (options) assertCollectionUploadOptions(options);
322
- return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), ReferenceType.MANIFEST);
333
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), 'manifest');
323
334
  }
324
335
  /**
325
336
  * Upload collection of files.
@@ -342,7 +353,7 @@ export class Bee {
342
353
  assertRequestOptions(requestOptions);
343
354
  if (options) assertCollectionUploadOptions(options);
344
355
  const data = await makeCollectionFromFS(dir);
345
- return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
356
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), 'manifest');
346
357
  }
347
358
  /**
348
359
  * Create a new Tag which is meant for tracking progres of syncing data across network.
@@ -698,16 +709,15 @@ export class Bee {
698
709
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
699
710
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
700
711
  */
701
- async createFeedManifest(postageBatchId, type, topic, owner, options) {
712
+ async createFeedManifest(stamp, type, topic, owner, options) {
702
713
  assertRequestOptions(options);
703
714
  assertFeedType(type);
704
- assertBatchId(postageBatchId);
705
715
  const canonicalTopic = makeTopic(topic);
706
716
  const canonicalOwner = makeHexEthAddress(owner);
707
- const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId);
717
+ const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, stamp);
708
718
  return addCidConversionFunction({
709
719
  reference
710
- }, ReferenceType.FEED);
720
+ }, 'feed');
711
721
  }
712
722
  /**
713
723
  * Make a new feed reader for downloading feed updates.
@@ -853,6 +863,10 @@ export class Bee {
853
863
  upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), canonicalSigner)
854
864
  };
855
865
  }
866
+ async createEnvelope(postageBatchId, reference, options) {
867
+ assertRequestOptions(options);
868
+ return postEnvelope(this.getRequestOptionsForCall(options), postageBatchId, reference);
869
+ }
856
870
  /**
857
871
  * Ping the Bee node to see if there is a live Bee node on the given URL.
858
872
  *
@@ -5,7 +5,6 @@ import { bytesAtOffset, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js"
5
5
  import { BeeError } from "../utils/error.js";
6
6
  import { keccak256Hash } from "../utils/hash.js";
7
7
  import { bytesToHex } from "../utils/hex.js";
8
- import { assertAddress } from "../utils/type.js";
9
8
  import { bmtHash } from "./bmt.js";
10
9
  import { MAX_PAYLOAD_SIZE, MIN_PAYLOAD_SIZE, assertValidChunkData, makeContentAddressedChunk } from "./cac.js";
11
10
  import { recoverAddress, sign } from "./signer.js";
@@ -90,12 +89,12 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
90
89
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
91
90
  * @param options Upload options
92
91
  */
93
- export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatchId, options) {
92
+ export async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
94
93
  const owner = bytesToHex(chunk.owner());
95
94
  const identifier = bytesToHex(chunk.identifier());
96
95
  const signature = bytesToHex(chunk.signature());
97
96
  const data = Binary.concatBytes(chunk.span(), chunk.payload());
98
- return socAPI.upload(requestOptions, owner, identifier, signature, data, postageBatchId, options);
97
+ return socAPI.upload(requestOptions, owner, identifier, signature, data, stamp, options);
99
98
  }
100
99
  /**
101
100
  * Helper function to create and upload SOC.
@@ -107,11 +106,10 @@ export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatch
107
106
  * @param data The chunk data
108
107
  * @param options
109
108
  */
110
- export async function uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, data, options) {
111
- assertAddress(postageBatchId);
109
+ export async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identifier, data, options) {
112
110
  const cac = makeContentAddressedChunk(data);
113
111
  const soc = await makeSingleOwnerChunk(cac, identifier, signer);
114
- return uploadSingleOwnerChunk(requestOptions, soc, postageBatchId, options);
112
+ return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
115
113
  }
116
114
  /**
117
115
  * Helper function to download SOC.
package/dist/mjs/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Bee } from "./bee.js";
2
2
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from "./modules/debug/status.js";
3
3
  export * from "./types/index.js";
4
+ export * from "./utils/constants.js";
4
5
  export * from "./utils/error.js";
5
6
  export * as Utils from "./utils/expose.js";
6
7
  export { Bee };
@@ -28,6 +28,22 @@ export async function upload(requestOptions, data, postageBatchId, options) {
28
28
  historyAddress: response.headers['swarm-act-history-address'] || ''
29
29
  };
30
30
  }
31
+ /**
32
+ * Requests content length for a reference
33
+ *
34
+ * @param requestOptions Options for making requests
35
+ * @param hash Bee content reference
36
+ */
37
+ export async function head(requestOptions, hash) {
38
+ const response = await http(requestOptions, {
39
+ url: `${endpoint}/${hash}`,
40
+ method: 'head',
41
+ responseType: 'json'
42
+ });
43
+ return {
44
+ contentLength: parseInt(response.headers['content-length'])
45
+ };
46
+ }
31
47
  /**
32
48
  * Download data as a byte array
33
49
  *
@@ -11,18 +11,18 @@ const endpoint = 'chunks';
11
11
  * Upload expects the chuck data to be set accordingly.
12
12
  *
13
13
  * @param requestOptions Options for making requests
14
- * @param data Chunk data to be uploaded
15
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
14
+ * @param data Chunk data to be uploaded
15
+ * @param stamp BatchId or marshaled stamp to be used for the upload
16
16
  * @param options Additional options like tag, encryption, pinning
17
17
  */
18
- export async function upload(requestOptions, data, postageBatchId, options) {
18
+ export async function upload(requestOptions, data, stamp, options) {
19
19
  const response = await http(requestOptions, {
20
20
  method: 'post',
21
21
  url: `${endpoint}`,
22
22
  data,
23
23
  headers: {
24
24
  'content-type': 'application/octet-stream',
25
- ...extractUploadHeaders(postageBatchId, options)
25
+ ...extractUploadHeaders(stamp, options)
26
26
  },
27
27
  responseType: 'json'
28
28
  });
@@ -0,0 +1,33 @@
1
+ import { Binary, Types } from 'cafe-utility';
2
+ import { http } from "../utils/http.js";
3
+ const ENVELOPE_ENDPOINT = 'envelope';
4
+ export async function postEnvelope(requestOptions, postageBatchId, reference) {
5
+ const {
6
+ data
7
+ } = await http(requestOptions, {
8
+ method: 'post',
9
+ responseType: 'json',
10
+ url: `${ENVELOPE_ENDPOINT}/${reference}`,
11
+ headers: {
12
+ 'swarm-postage-batch-id': postageBatchId
13
+ }
14
+ });
15
+ return {
16
+ issuer: Binary.hexToUint8Array(Types.asHexString(data.issuer, {
17
+ name: 'issuer',
18
+ byteLength: 20
19
+ })),
20
+ index: Binary.hexToUint8Array(Types.asHexString(data.index, {
21
+ name: 'index',
22
+ byteLength: 8
23
+ })),
24
+ timestamp: Binary.hexToUint8Array(Types.asHexString(data.timestamp, {
25
+ name: 'timestamp',
26
+ byteLength: 8
27
+ })),
28
+ signature: Binary.hexToUint8Array(Types.asHexString(data.signature, {
29
+ name: 'signature',
30
+ byteLength: 65
31
+ }))
32
+ };
33
+ }
@@ -11,12 +11,12 @@ const feedEndpoint = 'feeds';
11
11
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
12
12
  * @param options Additional options, like type (default: 'sequence')
13
13
  */
14
- export async function createFeedManifest(requestOptions, owner, topic, postageBatchId) {
14
+ export async function createFeedManifest(requestOptions, owner, topic, stamp) {
15
15
  const response = await http(requestOptions, {
16
16
  method: 'post',
17
17
  responseType: 'json',
18
18
  url: `${feedEndpoint}/${owner}/${topic}`,
19
- headers: extractUploadHeaders(postageBatchId)
19
+ headers: extractUploadHeaders(stamp)
20
20
  });
21
21
  return response.data.reference;
22
22
  }
@@ -10,7 +10,7 @@ export async function getGrantees(reference, requestOptions) {
10
10
  return {
11
11
  status: response.status,
12
12
  statusText: response.statusText,
13
- data: response.data.data
13
+ data: response.data
14
14
  };
15
15
  }
16
16
  export async function createGrantees(requestOptions, postageBatchId, grantees) {
@@ -18,7 +18,7 @@ export async function createGrantees(requestOptions, postageBatchId, grantees) {
18
18
  method: 'post',
19
19
  url: granteeEndpoint,
20
20
  data: {
21
- grantees: grantees
21
+ grantees
22
22
  },
23
23
  headers: {
24
24
  ...extractRedundantUploadHeaders(postageBatchId)
@@ -13,14 +13,14 @@ const socEndpoint = 'soc';
13
13
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
14
14
  * @param options Additional options like tag, encryption, pinning
15
15
  */
16
- export async function upload(requestOptions, owner, identifier, signature, data, postageBatchId, options) {
16
+ export async function upload(requestOptions, owner, identifier, signature, data, stamp, options) {
17
17
  const response = await http(requestOptions, {
18
18
  method: 'post',
19
19
  url: `${socEndpoint}/${owner}/${identifier}`,
20
20
  data,
21
21
  headers: {
22
22
  'content-type': 'application/octet-stream',
23
- ...extractUploadHeaders(postageBatchId, options)
23
+ ...extractUploadHeaders(stamp, options)
24
24
  },
25
25
  responseType: 'json',
26
26
  params: {
@@ -0,0 +1,33 @@
1
+ import { Binary } from 'cafe-utility';
2
+ export const SWARM_MANIFEST_CODEC = 0xfa;
3
+ export const SWARM_FEED_CODEC = 0xfb;
4
+ const CODEC_TABLE = {
5
+ [SWARM_MANIFEST_CODEC]: 'manifest',
6
+ [SWARM_FEED_CODEC]: 'feed'
7
+ };
8
+ export function convertReferenceToCid(reference, type) {
9
+ if (reference.length !== 64) {
10
+ throw TypeError('Only 32-byte, non-encrypted references are supported');
11
+ }
12
+ const base32 = 'b';
13
+ const version = new Uint8Array([1]);
14
+ const codec = new Uint8Array([type === 'feed' ? SWARM_FEED_CODEC : SWARM_MANIFEST_CODEC]);
15
+ const unknown = new Uint8Array([1]);
16
+ const sha256 = new Uint8Array([27]);
17
+ const size = new Uint8Array([32]);
18
+ const header = Binary.uint8ArrayToBase32(Binary.concatBytes(version, codec, unknown, sha256, size)).replace(/\=+$/, '');
19
+ const hash = Binary.uint8ArrayToBase32(Binary.hexToUint8Array(reference)).replace(/\=+$/, '');
20
+ return `${base32}${header}${hash}`.toLowerCase();
21
+ }
22
+ export function convertCidToReference(cid) {
23
+ const bytes = Binary.base32ToUint8Array(cid.toUpperCase().slice(1));
24
+ const codec = bytes[1];
25
+ if (!CODEC_TABLE[codec]) {
26
+ throw new Error('Unknown codec');
27
+ }
28
+ const reference = bytes.slice(-32);
29
+ return {
30
+ type: CODEC_TABLE[codec],
31
+ reference: Binary.uint8ArrayToHex(reference)
32
+ };
33
+ }
@@ -0,0 +1,3 @@
1
+ export const SWARM_GATEWAY_URL = 'https://api.gateway.ethswarm.org';
2
+ export const NULL_STAMP = '0000000000000000000000000000000000000000000000000000000000000000';
3
+ export const NULL_TOPIC = '0000000000000000000000000000000000000000000000000000000000000000';
@@ -6,4 +6,5 @@ export { capitalizeAddressERC55, ethToSwarmAddress, fromLittleEndian, isHexEthAd
6
6
  export { keccak256Hash } from "./hash.js";
7
7
  export { makeMaxTarget } from "./pss.js";
8
8
  export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampEffectiveBytes, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
9
- export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from "./redundancy.js";
9
+ export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from "./redundancy.js";
10
+ export { convertCidToReference, convertReferenceToCid } from "./cid.js";
@@ -1,3 +1,4 @@
1
+ import { Binary } from 'cafe-utility';
1
2
  import { BeeError } from "./error.js";
2
3
  /**
3
4
  * Read the filename from the content-disposition header
@@ -35,13 +36,16 @@ export function readFileHeaders(headers) {
35
36
  contentType
36
37
  };
37
38
  }
38
- export function extractUploadHeaders(postageBatchId, options) {
39
- if (!postageBatchId) {
40
- throw new BeeError('Postage BatchID has to be specified!');
39
+ export function extractUploadHeaders(stamp, options) {
40
+ if (!stamp) {
41
+ throw new BeeError('Stamp has to be specified!');
42
+ }
43
+ const headers = {};
44
+ if (stamp instanceof Uint8Array) {
45
+ headers['swarm-postage-stamp'] = Binary.uint8ArrayToHex(stamp);
46
+ } else {
47
+ headers['swarm-postage-batch-id'] = stamp;
41
48
  }
42
- const headers = {
43
- 'swarm-postage-batch-id': postageBatchId
44
- };
45
49
  if (options?.act) {
46
50
  headers['swarm-act'] = String(options.act);
47
51
  }
@@ -21,13 +21,6 @@ export async function http(options, config) {
21
21
  const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
22
22
  maybeRunOnRequestHook(options, requestConfig);
23
23
  const response = await axios(requestConfig);
24
- // Axios does not parse array of strings as JSON
25
- if (Array.isArray(response.data) && response.data.every(element => typeof element === 'string')) {
26
- const array = response.data;
27
- response.data = {
28
- data: array
29
- };
30
- }
31
24
  // TODO: https://github.com/axios/axios/pull/6253
32
25
  return response;
33
26
  } catch (e) {
@@ -1,3 +1,4 @@
1
+ import { Binary } from 'cafe-utility';
1
2
  /**
2
3
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
3
4
  *
@@ -100,4 +101,22 @@ export function getAmountForTtl(days) {
100
101
  */
101
102
  export function getDepthForCapacity(gigabytes) {
102
103
  return gigabytes <= 1 ? 18 : Math.ceil(Math.log2(Math.ceil(gigabytes)) + 18);
104
+ }
105
+ export function convertEnvelopeToMarshaledStamp(batchID, envelope) {
106
+ return marshalStamp(envelope.signature, Binary.hexToUint8Array(batchID), envelope.timestamp, envelope.index);
107
+ }
108
+ export function marshalStamp(signature, batchID, timestamp, index) {
109
+ if (signature.length !== 65) {
110
+ throw Error('invalid signature length');
111
+ }
112
+ if (batchID.length !== 32) {
113
+ throw Error('invalid batch ID length');
114
+ }
115
+ if (timestamp.length !== 8) {
116
+ throw Error('invalid timestamp length');
117
+ }
118
+ if (index.length !== 8) {
119
+ throw Error('invalid index length');
120
+ }
121
+ return Binary.concatBytes(batchID, index, timestamp, signature);
103
122
  }
@@ -12,6 +12,9 @@ export class TarStream {
12
12
  });
13
13
  }
14
14
  beginFile(path, size) {
15
+ if (path.length > 100) {
16
+ throw new Error(`File name too long: ${path}`);
17
+ }
15
18
  const header = createHeader(path, size);
16
19
  this.pieces.push(header);
17
20
  this.currentFileSize = 0;
@@ -5,6 +5,9 @@ export class TarStream {
5
5
  this.currentFileSize = 0;
6
6
  }
7
7
  beginFile(path, size) {
8
+ if (path.length > 100) {
9
+ throw new Error(`File name too long: ${path}`);
10
+ }
8
11
  const header = createHeader(path, size);
9
12
  this.output.write(header);
10
13
  this.currentFileSize = 0;
@@ -1,15 +1,12 @@
1
- import { decodeCid, encodeReference } from '@ethersphere/swarm-cid';
2
1
  import { Readable } from 'stream';
3
2
  import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PSS_TARGET_HEX_LENGTH_MAX, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN } from "../types/index.js";
3
+ import { convertCidToReference, convertReferenceToCid } from "./cid.js";
4
4
  import { BeeArgumentError, BeeError } from "./error.js";
5
5
  import { isFile } from "./file.js";
6
6
  import { assertHexString, assertPrefixedHexString, isHexString } from "./hex.js";
7
7
  export function isReadable(obj) {
8
8
  return typeof Readable !== 'undefined' && obj instanceof Readable;
9
9
  }
10
- export function isUint8Array(obj) {
11
- return obj instanceof Uint8Array;
12
- }
13
10
  export function isInteger(value) {
14
11
  return typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value) || typeof value === 'number' && value > Number.MIN_SAFE_INTEGER && value < Number.MAX_SAFE_INTEGER && Number.isInteger(value);
15
12
  }
@@ -113,7 +110,7 @@ export function makeReferenceOrEns(value, expectedCidType) {
113
110
  throw new TypeError('ReferenceCidOrEns has to be a string!');
114
111
  }
115
112
  try {
116
- const result = decodeCid(value);
113
+ const result = convertCidToReference(value);
117
114
  if (result.type !== expectedCidType) {
118
115
  throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
119
116
  }
@@ -127,13 +124,13 @@ export function makeReferenceOrEns(value, expectedCidType) {
127
124
  /**
128
125
  * Function that adds getter which converts the reference into CID base32 encoded string.
129
126
  * @param result
130
- * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
127
+ * @param cidType feed or manifest
131
128
  */
132
129
  export function addCidConversionFunction(result, cidType) {
133
130
  return {
134
131
  ...result,
135
132
  cid() {
136
- return encodeReference(result.reference, cidType).toString();
133
+ return convertReferenceToCid(result.reference, cidType);
137
134
  }
138
135
  };
139
136
  }
@@ -2,7 +2,7 @@
2
2
  import { Readable } from 'stream';
3
3
  import { Index, IndexBytes } from './feed';
4
4
  import { FeedType } from './feed/type';
5
- import type { Address, AddressPrefix, AllSettlements, AnyJson, BalanceResponse, BatchId, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, Data, DebugStatus, ExtendedTag, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GranteesResult, Health, JsonFeedOptions, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, PublicKey, RedistributionState, Reference, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Signer, Tag, Topic, Topology, TransactionHash, TransactionInfo, UploadOptions, UploadRedundancyOptions, UploadResultWithCid, WalletBalance } from './types';
5
+ import type { Address, AddressPrefix, AllSettlements, AnyJson, BalanceResponse, BatchId, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, Data, DebugStatus, Envelope, ExtendedTag, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GranteesResult, Health, JsonFeedOptions, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, PublicKey, RedistributionState, Reference, ReferenceInformation, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Signer, Tag, Topic, Topology, TransactionHash, TransactionInfo, UploadOptions, UploadRedundancyOptions, UploadResultWithCid, WalletBalance } from './types';
6
6
  import { AllTagsOptions, CashoutOptions, Collection, FeedManifestResult, PostageBatchOptions, ReferenceCidOrEns, ReferenceOrEns, TransactionOptions, UploadResult } from './types';
7
7
  import { EthAddress } from './utils/eth';
8
8
  /**
@@ -42,6 +42,12 @@ export declare class Bee {
42
42
  * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
43
43
  */
44
44
  uploadData(postageBatchId: string | BatchId, data: string | Uint8Array, options?: UploadOptions & UploadRedundancyOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
45
+ /**
46
+ * Requests content length for a `/bytes` reference
47
+ *
48
+ * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
49
+ */
50
+ probeData(reference: ReferenceOrEns | string, options?: BeeRequestOptions): Promise<ReferenceInformation>;
45
51
  /**
46
52
  * Download data as a byte array
47
53
  *
@@ -75,7 +81,7 @@ export declare class Bee {
75
81
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
76
82
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
77
83
  */
78
- uploadChunk(postageBatchId: string | BatchId, data: Uint8Array, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
84
+ uploadChunk(stamp: BatchId | Uint8Array | string, data: Uint8Array, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
79
85
  /**
80
86
  * Download chunk as a byte array
81
87
  *
@@ -423,7 +429,7 @@ export declare class Bee {
423
429
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
424
430
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
425
431
  */
426
- createFeedManifest(postageBatchId: string | BatchId, type: FeedType, topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: BeeRequestOptions): Promise<FeedManifestResult>;
432
+ createFeedManifest(stamp: BatchId | Uint8Array | string, type: FeedType, topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: BeeRequestOptions): Promise<FeedManifestResult>;
427
433
  /**
428
434
  * Make a new feed reader for downloading feed updates.
429
435
  *
@@ -510,6 +516,7 @@ export declare class Bee {
510
516
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
511
517
  */
512
518
  makeSOCWriter(signer?: Signer | Uint8Array | string, options?: BeeRequestOptions): SOCWriter;
519
+ createEnvelope(postageBatchId: BatchId, reference: Reference, options?: BeeRequestOptions): Promise<Envelope>;
513
520
  /**
514
521
  * Ping the Bee node to see if there is a live Bee node on the given URL.
515
522
  *
@@ -44,7 +44,7 @@ export declare function makeSingleOwnerChunk(chunk: Chunk, identifier: Identifie
44
44
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
45
45
  * @param options Upload options
46
46
  */
47
- export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
47
+ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
48
48
  /**
49
49
  * Helper function to create and upload SOC.
50
50
  *
@@ -55,7 +55,7 @@ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions
55
55
  * @param data The chunk data
56
56
  * @param options
57
57
  */
58
- export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: Signer, postageBatchId: BatchId | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
58
+ export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: Signer, stamp: BatchId | Uint8Array | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
59
59
  /**
60
60
  * Helper function to download SOC.
61
61
  *
@@ -1,6 +1,7 @@
1
1
  import { Bee } from './bee';
2
2
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from './modules/debug/status';
3
3
  export * from './types';
4
+ export * from './utils/constants';
4
5
  export * from './utils/error';
5
6
  export * as Utils from './utils/expose';
6
7
  export { Bee };
@@ -1,4 +1,4 @@
1
- import type { BatchId, BeeRequestOptions, Data, DownloadRedundancyOptions, ReferenceOrEns, UploadOptions, UploadRedundancyOptions } from '../types';
1
+ import type { BatchId, BeeRequestOptions, Data, DownloadRedundancyOptions, ReferenceInformation, ReferenceOrEns, UploadOptions, UploadRedundancyOptions } from '../types';
2
2
  import { UploadResult } from '../types';
3
3
  /**
4
4
  * Upload data to a Bee node
@@ -9,6 +9,13 @@ import { UploadResult } from '../types';
9
9
  * @param options Additional options like tag, encryption, pinning
10
10
  */
11
11
  export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array, postageBatchId: BatchId, options?: UploadOptions & UploadRedundancyOptions): Promise<UploadResult>;
12
+ /**
13
+ * Requests content length for a reference
14
+ *
15
+ * @param requestOptions Options for making requests
16
+ * @param hash Bee content reference
17
+ */
18
+ export declare function head(requestOptions: BeeRequestOptions, hash: ReferenceOrEns): Promise<ReferenceInformation>;
12
19
  /**
13
20
  * Download data as a byte array
14
21
  *
@@ -7,11 +7,11 @@ import type { BatchId, BeeRequestOptions, Data, ReferenceOrEns, UploadOptions, U
7
7
  * Upload expects the chuck data to be set accordingly.
8
8
  *
9
9
  * @param requestOptions Options for making requests
10
- * @param data Chunk data to be uploaded
11
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
10
+ * @param data Chunk data to be uploaded
11
+ * @param stamp BatchId or marshaled stamp to be used for the upload
12
12
  * @param options Additional options like tag, encryption, pinning
13
13
  */
14
- export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
14
+ export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
15
15
  /**
16
16
  * Download chunk data as a byte array
17
17
  *
@@ -0,0 +1,2 @@
1
+ import type { BatchId, BeeRequestOptions, Envelope, Reference } from '../types';
2
+ export declare function postEnvelope(requestOptions: BeeRequestOptions, postageBatchId: BatchId, reference: Reference): Promise<Envelope>;
@@ -38,7 +38,7 @@ export interface FetchFeedUpdateResponse extends ReferenceResponse, FeedUpdateHe
38
38
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
39
39
  * @param options Additional options, like type (default: 'sequence')
40
40
  */
41
- export declare function createFeedManifest(requestOptions: BeeRequestOptions, owner: HexEthAddress, topic: Topic, postageBatchId: BatchId): Promise<Reference>;
41
+ export declare function createFeedManifest(requestOptions: BeeRequestOptions, owner: HexEthAddress, topic: Topic, stamp: BatchId | Uint8Array | string): Promise<Reference>;
42
42
  /**
43
43
  * Find and retrieve feed update
44
44
  *