@ethersphere/bee-js 8.0.2 → 8.2.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 (53) hide show
  1. package/dist/cjs/bee.js +50 -22
  2. package/dist/cjs/chunk/soc.js +4 -6
  3. package/dist/cjs/feed/json.js +1 -1
  4. package/dist/cjs/feed/retrievable.js +1 -1
  5. package/dist/cjs/modules/bytes.js +18 -1
  6. package/dist/cjs/modules/chunk.js +4 -4
  7. package/dist/cjs/modules/debug/status.js +3 -4
  8. package/dist/cjs/modules/envelope.js +23 -0
  9. package/dist/cjs/modules/feed.js +2 -2
  10. package/dist/cjs/modules/pinning.js +1 -1
  11. package/dist/cjs/modules/soc.js +2 -2
  12. package/dist/cjs/utils/error.js +4 -1
  13. package/dist/cjs/utils/expose.js +3 -1
  14. package/dist/cjs/utils/file.js +2 -2
  15. package/dist/cjs/utils/headers.js +11 -6
  16. package/dist/cjs/utils/http.js +1 -1
  17. package/dist/cjs/utils/stamps.js +22 -1
  18. package/dist/cjs/utils/type.js +1 -8
  19. package/dist/index.browser.min.js +1 -1
  20. package/dist/index.browser.min.js.map +1 -1
  21. package/dist/mjs/bee.js +54 -22
  22. package/dist/mjs/chunk/soc.js +4 -6
  23. package/dist/mjs/feed/json.js +3 -1
  24. package/dist/mjs/feed/retrievable.js +1 -1
  25. package/dist/mjs/modules/bytes.js +16 -0
  26. package/dist/mjs/modules/chunk.js +4 -4
  27. package/dist/mjs/modules/debug/status.js +2 -3
  28. package/dist/mjs/modules/envelope.js +33 -0
  29. package/dist/mjs/modules/feed.js +2 -2
  30. package/dist/mjs/modules/pinning.js +1 -1
  31. package/dist/mjs/modules/soc.js +2 -2
  32. package/dist/mjs/utils/error.js +4 -1
  33. package/dist/mjs/utils/expose.js +3 -1
  34. package/dist/mjs/utils/file.js +2 -2
  35. package/dist/mjs/utils/headers.js +10 -6
  36. package/dist/mjs/utils/http.js +1 -1
  37. package/dist/mjs/utils/stamps.js +19 -0
  38. package/dist/mjs/utils/type.js +0 -6
  39. package/dist/types/bee.d.ts +14 -7
  40. package/dist/types/chunk/soc.d.ts +2 -2
  41. package/dist/types/modules/bytes.d.ts +8 -1
  42. package/dist/types/modules/chunk.d.ts +3 -3
  43. package/dist/types/modules/debug/status.d.ts +2 -3
  44. package/dist/types/modules/envelope.d.ts +2 -0
  45. package/dist/types/modules/feed.d.ts +1 -1
  46. package/dist/types/modules/soc.d.ts +1 -1
  47. package/dist/types/types/index.d.ts +10 -2
  48. package/dist/types/utils/error.d.ts +4 -1
  49. package/dist/types/utils/expose.d.ts +6 -3
  50. package/dist/types/utils/headers.d.ts +1 -1
  51. package/dist/types/utils/stamps.d.ts +3 -1
  52. package/dist/types/utils/type.d.ts +0 -1
  53. package/package.json +13 -16
package/dist/mjs/bee.js CHANGED
@@ -20,6 +20,7 @@ import * as states from "./modules/debug/states.js";
20
20
  import * as debugStatus from "./modules/debug/status.js";
21
21
  import * as debugTag from "./modules/debug/tag.js";
22
22
  import * as transactions from "./modules/debug/transactions.js";
23
+ import { postEnvelope } from "./modules/envelope.js";
23
24
  import { createFeedManifest } from "./modules/feed.js";
24
25
  import * as grantee from "./modules/grantee.js";
25
26
  import * as pinning from "./modules/pinning.js";
@@ -78,9 +79,22 @@ export class Bee {
78
79
  async uploadData(postageBatchId, data, options, requestOptions) {
79
80
  assertBatchId(postageBatchId);
80
81
  assertData(data);
81
- if (options) assertUploadOptions(options);
82
+ assertRequestOptions(requestOptions);
83
+ if (options) {
84
+ assertUploadOptions(options);
85
+ }
82
86
  return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
83
87
  }
88
+ /**
89
+ * Requests content length for a `/bytes` reference
90
+ *
91
+ * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
92
+ */
93
+ async probeData(reference, options) {
94
+ assertRequestOptions(options);
95
+ assertReferenceOrEns(reference);
96
+ return bytes.head(this.getRequestOptionsForCall(options), reference);
97
+ }
84
98
  /**
85
99
  * Download data as a byte array
86
100
  *
@@ -122,8 +136,8 @@ export class Bee {
122
136
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
123
137
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
124
138
  */
125
- async uploadChunk(postageBatchId, data, options, requestOptions) {
126
- assertBatchId(postageBatchId);
139
+ async uploadChunk(stamp, data, options, requestOptions) {
140
+ assertRequestOptions(requestOptions);
127
141
  if (!(data instanceof Uint8Array)) {
128
142
  throw new TypeError('Data has to be Uint8Array instance!');
129
143
  }
@@ -133,8 +147,10 @@ export class Bee {
133
147
  if (data.length > CHUNK_SIZE + SPAN_SIZE) {
134
148
  throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
135
149
  }
136
- if (options) assertUploadOptions(options);
137
- return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
150
+ if (options) {
151
+ assertUploadOptions(options);
152
+ }
153
+ return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
138
154
  }
139
155
  /**
140
156
  * Download chunk as a byte array
@@ -162,6 +178,7 @@ export class Bee {
162
178
  * @returns A promise that resolves to a `GranteesResult` object.
163
179
  */
164
180
  async createGrantees(postageBatchId, grantees, requestOptions) {
181
+ assertRequestOptions(requestOptions);
165
182
  assertBatchId(postageBatchId);
166
183
  return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
167
184
  }
@@ -173,6 +190,7 @@ export class Bee {
173
190
  * @returns A promise that resolves to a `GetGranteesResult` object.
174
191
  */
175
192
  async getGrantees(reference, requestOptions) {
193
+ assertRequestOptions(requestOptions);
176
194
  return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
177
195
  }
178
196
  /**
@@ -186,6 +204,7 @@ export class Bee {
186
204
  * @returns A Promise that resolves to to a `GranteesResult` object.
187
205
  */
188
206
  async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
207
+ assertRequestOptions(requestOptions);
189
208
  assertBatchId(postageBatchId);
190
209
  return grantee.patchGrantees(postageBatchId, reference, history, {
191
210
  add: grantees.add || [],
@@ -209,9 +228,12 @@ export class Bee {
209
228
  * @returns reference is a content hash of the file
210
229
  */
211
230
  async uploadFile(postageBatchId, data, name, options, requestOptions) {
231
+ assertRequestOptions(requestOptions);
212
232
  assertBatchId(postageBatchId);
213
233
  assertFileData(data);
214
- if (options) assertFileUploadOptions(options);
234
+ if (options) {
235
+ assertFileUploadOptions(options);
236
+ }
215
237
  if (name && typeof name !== 'string') {
216
238
  throw new TypeError('name has to be string or undefined!');
217
239
  }
@@ -284,8 +306,11 @@ export class Bee {
284
306
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
285
307
  */
286
308
  async uploadFiles(postageBatchId, fileList, options, requestOptions) {
309
+ assertRequestOptions(requestOptions);
287
310
  assertBatchId(postageBatchId);
288
- if (options) assertCollectionUploadOptions(options);
311
+ if (options) {
312
+ assertCollectionUploadOptions(options);
313
+ }
289
314
  const data = await makeCollectionFromFileList(fileList);
290
315
  return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
291
316
  }
@@ -299,11 +324,12 @@ export class Bee {
299
324
  * @param collection
300
325
  * @param options Collections and request options
301
326
  */
302
- async uploadCollection(postageBatchId, collection, options) {
327
+ async uploadCollection(postageBatchId, collection, options, requestOptions) {
328
+ assertRequestOptions(requestOptions);
303
329
  assertBatchId(postageBatchId);
304
330
  assertCollection(collection);
305
331
  if (options) assertCollectionUploadOptions(options);
306
- return addCidConversionFunction(await bzz.uploadCollection(this.requestOptions, collection, postageBatchId, options), ReferenceType.MANIFEST);
332
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), ReferenceType.MANIFEST);
307
333
  }
308
334
  /**
309
335
  * Upload collection of files.
@@ -323,6 +349,7 @@ export class Bee {
323
349
  */
324
350
  async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
325
351
  assertBatchId(postageBatchId);
352
+ assertRequestOptions(requestOptions);
326
353
  if (options) assertCollectionUploadOptions(options);
327
354
  const data = await makeCollectionFromFS(dir);
328
355
  return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
@@ -350,10 +377,10 @@ export class Bee {
350
377
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
351
378
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
352
379
  */
353
- async getAllTags(options) {
354
- assertRequestOptions(options);
380
+ async getAllTags(options, requestOptions) {
381
+ assertRequestOptions(requestOptions);
355
382
  assertAllTagsOptions(options);
356
- return tag.getAllTags(this.getRequestOptionsForCall(options), options?.offset, options?.limit);
383
+ return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
357
384
  }
358
385
  /**
359
386
  * Retrieve tag information from Bee node
@@ -515,7 +542,7 @@ export class Bee {
515
542
  await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
516
543
  return true;
517
544
  } catch (e) {
518
- if (e?.response?.status === 404) {
545
+ if (e?.status === 404 || e?.status === 500) {
519
546
  return false;
520
547
  }
521
548
  throw e;
@@ -681,13 +708,12 @@ export class Bee {
681
708
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
682
709
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
683
710
  */
684
- async createFeedManifest(postageBatchId, type, topic, owner, options) {
711
+ async createFeedManifest(stamp, type, topic, owner, options) {
685
712
  assertRequestOptions(options);
686
713
  assertFeedType(type);
687
- assertBatchId(postageBatchId);
688
714
  const canonicalTopic = makeTopic(topic);
689
715
  const canonicalOwner = makeHexEthAddress(owner);
690
- const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId);
716
+ const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, stamp);
691
717
  return addCidConversionFunction({
692
718
  reference
693
719
  }, ReferenceType.FEED);
@@ -745,7 +771,7 @@ export class Bee {
745
771
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
746
772
  */
747
773
  async setJsonFeed(postageBatchId, topic, data, options, requestOptions) {
748
- assertRequestOptions(options, 'JsonFeedOptions');
774
+ assertRequestOptions(requestOptions, 'JsonFeedOptions');
749
775
  assertBatchId(postageBatchId);
750
776
  const hashedTopic = this.makeFeedTopic(topic);
751
777
  const feedType = options?.type ?? DEFAULT_FEED_TYPE;
@@ -771,8 +797,8 @@ export class Bee {
771
797
  *
772
798
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
773
799
  */
774
- async getJsonFeed(topic, options) {
775
- assertRequestOptions(options, 'JsonFeedOptions');
800
+ async getJsonFeed(topic, options, requestOptions) {
801
+ assertRequestOptions(requestOptions);
776
802
  const hashedTopic = this.makeFeedTopic(topic);
777
803
  const feedType = options?.type ?? DEFAULT_FEED_TYPE;
778
804
  if (options?.signer && options?.address) {
@@ -792,7 +818,7 @@ export class Bee {
792
818
  }
793
819
  }
794
820
  }
795
- const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
821
+ const reader = this.makeFeedReader(feedType, hashedTopic, address, requestOptions);
796
822
  return getJsonData(this, reader);
797
823
  }
798
824
  /**
@@ -836,6 +862,10 @@ export class Bee {
836
862
  upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), canonicalSigner)
837
863
  };
838
864
  }
865
+ async createEnvelope(postageBatchId, reference, options) {
866
+ assertRequestOptions(options);
867
+ return postEnvelope(this.getRequestOptionsForCall(options), postageBatchId, reference);
868
+ }
839
869
  /**
840
870
  * Ping the Bee node to see if there is a live Bee node on the given URL.
841
871
  *
@@ -1007,6 +1037,7 @@ export class Bee {
1007
1037
  async cashoutLastCheque(address, options, requestOptions) {
1008
1038
  assertCashoutOptions(options);
1009
1039
  assertAddress(address);
1040
+ assertRequestOptions(requestOptions);
1010
1041
  return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
1011
1042
  }
1012
1043
  /**
@@ -1189,6 +1220,7 @@ export class Bee {
1189
1220
  assertPostageBatchOptions(options);
1190
1221
  assertPositiveInteger(amount);
1191
1222
  assertNonNegativeInteger(depth);
1223
+ assertRequestOptions(requestOptions);
1192
1224
  if (depth < STAMPS_DEPTH_MIN) {
1193
1225
  throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth);
1194
1226
  }
@@ -1348,8 +1380,8 @@ export class Bee {
1348
1380
  * @param options
1349
1381
  */
1350
1382
  async depositStake(amount, options, requestOptions) {
1351
- assertRequestOptions(options);
1352
1383
  assertTransactionOptions(options);
1384
+ assertRequestOptions(requestOptions);
1353
1385
  await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
1354
1386
  }
1355
1387
  /**
@@ -1386,7 +1418,7 @@ export class Bee {
1386
1418
  if (this.signer) {
1387
1419
  return this.signer;
1388
1420
  }
1389
- throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.');
1421
+ throw new TypeError('You have to pass Signer as property to either the method call or constructor! Non found.');
1390
1422
  }
1391
1423
  getRequestOptionsForCall(options) {
1392
1424
  return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
@@ -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.
@@ -20,5 +20,7 @@ export async function setJsonData(bee, writer, postageBatchId, data, options, re
20
20
  const {
21
21
  reference
22
22
  } = await bee.uploadData(postageBatchId, serializedData, options, requestOptions);
23
- return writer.upload(postageBatchId, reference);
23
+ return writer.upload(postageBatchId, reference, {
24
+ pin: options?.pin
25
+ });
24
26
  }
@@ -26,7 +26,7 @@ async function isChunkRetrievable(bee, ref, requestOptions) {
26
26
  await bee.downloadChunk(ref, requestOptions);
27
27
  return true;
28
28
  } catch (e) {
29
- if (e?.response?.status === 404) {
29
+ if (e?.status === 404 || e?.status === 500) {
30
30
  return false;
31
31
  }
32
32
  throw e;
@@ -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
  });
@@ -1,9 +1,8 @@
1
1
  import getMajorSemver from 'semver/functions/major.js';
2
2
  import { http } from "../../utils/http.js"; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
3
3
  // so if you are changing anything about them change the `update_bee` action accordingly!
4
- export const SUPPORTED_BEE_VERSION_EXACT = '1.18.2-759f56f';
5
- export const SUPPORTED_API_VERSION = '4.0.0';
6
- export const SUPPORTED_DEBUG_API_VERSION = '4.0.0';
4
+ export const SUPPORTED_BEE_VERSION_EXACT = '2.2.0-06a0aca7';
5
+ export const SUPPORTED_API_VERSION = '7.1.0';
7
6
  export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
8
7
  const NODE_INFO_URL = 'node';
9
8
  const STATUS_URL = 'status';
@@ -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
  }
@@ -52,5 +52,5 @@ export async function getAllPins(requestOptions) {
52
52
  responseType: 'json',
53
53
  url: `${PINNING_ENDPOINT}`
54
54
  });
55
- return response.data.references;
55
+ return response.data.references || [];
56
56
  }
@@ -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: {
@@ -10,8 +10,11 @@ export class BeeArgumentError extends BeeError {
10
10
  }
11
11
  }
12
12
  export class BeeResponseError extends BeeError {
13
- constructor(message, status, statusText) {
13
+ constructor(method, url, message, responseBody, status, statusText) {
14
14
  super(message);
15
+ this.method = method;
16
+ this.url = url;
17
+ this.responseBody = responseBody;
15
18
  this.status = status;
16
19
  this.statusText = statusText;
17
20
  }
@@ -6,4 +6,6 @@ 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 const NULL_STAMP = '0000000000000000000000000000000000000000000000000000000000000000';
11
+ export const NULL_TOPIC = '0000000000000000000000000000000000000000000000000000000000000000';
@@ -5,8 +5,8 @@
5
5
  */
6
6
  export function isFile(file) {
7
7
  // browser
8
- if (typeof File === 'function') {
9
- return file instanceof File;
8
+ if (typeof File === 'function' && file instanceof File) {
9
+ return true;
10
10
  }
11
11
  // node.js
12
12
  const f = file;
@@ -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
  }
@@ -32,7 +32,7 @@ export async function http(options, config) {
32
32
  return response;
33
33
  } catch (e) {
34
34
  if (e instanceof AxiosError) {
35
- throw new BeeResponseError(e.message, e.status, e.code);
35
+ throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code);
36
36
  }
37
37
  throw e;
38
38
  }
@@ -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
  }
@@ -7,9 +7,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
  }
@@ -151,9 +148,6 @@ export function assertRequestOptions(value, name = 'RequestOptions') {
151
148
  throw new TypeError(`${name} has to be an object!`);
152
149
  }
153
150
  const options = value;
154
- if (options.retry) {
155
- assertNonNegativeInteger(options.retry, `${name}.retry`);
156
- }
157
151
  if (options.timeout) {
158
152
  assertNonNegativeInteger(options.timeout, `${name}.timeout`);
159
153
  }
@@ -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
  *
@@ -190,7 +196,7 @@ export declare class Bee {
190
196
  * @param collection
191
197
  * @param options Collections and request options
192
198
  */
193
- uploadCollection(postageBatchId: string | BatchId, collection: Collection, options?: CollectionUploadOptions & UploadRedundancyOptions): Promise<UploadResultWithCid>;
199
+ uploadCollection(postageBatchId: string | BatchId, collection: Collection, options?: CollectionUploadOptions & UploadRedundancyOptions, requestOptions?: BeeRequestOptions): Promise<UploadResultWithCid>;
194
200
  /**
195
201
  * Upload collection of files.
196
202
  *
@@ -228,7 +234,7 @@ export declare class Bee {
228
234
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
229
235
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
230
236
  */
231
- getAllTags(options?: AllTagsOptions): Promise<Tag[]>;
237
+ getAllTags(options?: AllTagsOptions, requestOptions?: BeeRequestOptions): Promise<Tag[]>;
232
238
  /**
233
239
  * Retrieve tag information from Bee node
234
240
  *
@@ -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
  *
@@ -464,7 +470,7 @@ export declare class Bee {
464
470
  *
465
471
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
466
472
  */
467
- setJsonFeed<T extends AnyJson>(postageBatchId: string | BatchId, topic: string, data: T, options?: JsonFeedOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
473
+ setJsonFeed<T extends AnyJson>(postageBatchId: string | BatchId, topic: string, data: T, options?: JsonFeedOptions & UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
468
474
  /**
469
475
  * High-level function that allows you to easily get data from feed.
470
476
  * Returned data are parsed using JSON.parse().
@@ -484,7 +490,7 @@ export declare class Bee {
484
490
  *
485
491
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
486
492
  */
487
- getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions): Promise<T>;
493
+ getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions, requestOptions?: BeeRequestOptions): Promise<T>;
488
494
  /**
489
495
  * Make a new feed topic from a string
490
496
  *
@@ -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
  *