@ethersphere/bee-js 3.3.4 → 4.1.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 (200) hide show
  1. package/README.md +3 -22
  2. package/dist/cjs/{bee-debug.js → src/bee-debug.js} +31 -8
  3. package/dist/cjs/{bee.js → src/bee.js} +79 -24
  4. package/dist/cjs/{chunk → src/chunk}/bmt.js +0 -0
  5. package/dist/cjs/{chunk → src/chunk}/cac.js +0 -0
  6. package/dist/cjs/{chunk → src/chunk}/serialize.js +0 -0
  7. package/dist/cjs/{chunk → src/chunk}/signer.js +0 -0
  8. package/dist/cjs/{chunk → src/chunk}/soc.js +0 -0
  9. package/dist/cjs/{chunk → src/chunk}/span.js +0 -0
  10. package/dist/cjs/src/feed/identifier.js +35 -0
  11. package/dist/cjs/{feed → src/feed}/index.js +34 -90
  12. package/dist/cjs/{feed → src/feed}/json.js +0 -0
  13. package/dist/cjs/src/feed/retrievable.js +72 -0
  14. package/dist/cjs/{feed → src/feed}/topic.js +0 -0
  15. package/dist/cjs/{feed → src/feed}/type.js +0 -0
  16. package/dist/cjs/{index.js → src/index.js} +0 -0
  17. package/dist/cjs/{modules → src/modules}/bytes.js +0 -0
  18. package/dist/cjs/{modules → src/modules}/bzz.js +0 -0
  19. package/dist/cjs/{modules → src/modules}/chunk.js +0 -0
  20. package/dist/cjs/{modules → src/modules}/debug/balance.js +0 -0
  21. package/dist/cjs/{modules → src/modules}/debug/chequebook.js +0 -0
  22. package/dist/cjs/{modules → src/modules}/debug/chunk.js +0 -0
  23. package/dist/cjs/{modules → src/modules}/debug/connectivity.js +0 -0
  24. package/dist/cjs/{modules → src/modules}/debug/settlements.js +0 -0
  25. package/dist/cjs/{modules → src/modules}/debug/stamps.js +0 -0
  26. package/dist/cjs/{modules → src/modules}/debug/states.js +18 -1
  27. package/dist/cjs/{modules → src/modules}/debug/status.js +3 -3
  28. package/dist/cjs/{modules → src/modules}/debug/tag.js +0 -0
  29. package/dist/cjs/{modules → src/modules}/debug/transactions.js +0 -0
  30. package/dist/cjs/{modules → src/modules}/feed.js +3 -3
  31. package/dist/cjs/{modules → src/modules}/pinning.js +0 -0
  32. package/dist/cjs/{modules → src/modules}/pss.js +0 -0
  33. package/dist/cjs/{modules → src/modules}/soc.js +0 -0
  34. package/dist/cjs/{modules → src/modules}/status.js +0 -0
  35. package/dist/cjs/{modules → src/modules}/stewardship.js +0 -0
  36. package/dist/cjs/{modules → src/modules}/tag.js +0 -0
  37. package/dist/cjs/{types → src/types}/debug.js +0 -0
  38. package/dist/cjs/{types → src/types}/index.js +2 -1
  39. package/dist/cjs/{types → src/types}/ky-options.js +0 -0
  40. package/dist/cjs/{types → src/types}/ky-universal/common.js +0 -0
  41. package/dist/cjs/{types → src/types}/ky-universal/hooks.js +0 -0
  42. package/dist/cjs/{types → src/types}/ky-universal/retry.js +0 -0
  43. package/dist/cjs/{utils → src/utils}/bytes.js +15 -1
  44. package/dist/cjs/{utils → src/utils}/collection.browser.js +0 -0
  45. package/dist/cjs/{utils → src/utils}/collection.js +0 -0
  46. package/dist/cjs/{utils → src/utils}/collection.node.js +0 -0
  47. package/dist/cjs/{utils → src/utils}/data.browser.js +0 -0
  48. package/dist/cjs/{utils → src/utils}/data.js +0 -0
  49. package/dist/cjs/{utils → src/utils}/error.js +0 -0
  50. package/dist/cjs/{utils → src/utils}/eth.js +0 -0
  51. package/dist/cjs/{utils → src/utils}/expose.js +0 -0
  52. package/dist/cjs/{utils → src/utils}/file.js +0 -0
  53. package/dist/cjs/{utils → src/utils}/hash.js +0 -0
  54. package/dist/cjs/{utils → src/utils}/headers.js +0 -0
  55. package/dist/cjs/{utils → src/utils}/hex.js +0 -0
  56. package/dist/cjs/{utils → src/utils}/http.js +6 -0
  57. package/dist/cjs/{utils → src/utils}/merge.js +0 -0
  58. package/dist/cjs/{utils → src/utils}/pss.js +0 -0
  59. package/dist/cjs/src/utils/reference.js +36 -0
  60. package/dist/cjs/{utils → src/utils}/stamps.js +0 -0
  61. package/dist/cjs/{utils → src/utils}/stream.js +0 -0
  62. package/dist/cjs/{utils → src/utils}/tar.js +0 -0
  63. package/dist/cjs/{utils → src/utils}/type.js +100 -1
  64. package/dist/cjs/{utils → src/utils}/uint64.js +0 -0
  65. package/dist/cjs/{utils → src/utils}/url.js +0 -0
  66. package/dist/cjs/test/utils.js +419 -0
  67. package/dist/index.browser.min.js +1 -1
  68. package/dist/index.browser.min.js.map +1 -1
  69. package/dist/mjs/{bee-debug.js → src/bee-debug.js} +40 -10
  70. package/dist/mjs/{bee.js → src/bee.js} +87 -27
  71. package/dist/mjs/{chunk → src/chunk}/bmt.js +0 -0
  72. package/dist/mjs/{chunk → src/chunk}/cac.js +1 -1
  73. package/dist/mjs/{chunk → src/chunk}/serialize.js +0 -0
  74. package/dist/mjs/{chunk → src/chunk}/signer.js +0 -0
  75. package/dist/mjs/{chunk → src/chunk}/soc.js +0 -0
  76. package/dist/mjs/{chunk → src/chunk}/span.js +0 -0
  77. package/dist/mjs/src/feed/identifier.js +35 -0
  78. package/dist/mjs/{feed → src/feed}/index.js +39 -94
  79. package/dist/mjs/{feed → src/feed}/json.js +0 -0
  80. package/dist/mjs/src/feed/retrievable.js +105 -0
  81. package/dist/mjs/{feed → src/feed}/topic.js +0 -0
  82. package/dist/mjs/{feed → src/feed}/type.js +0 -0
  83. package/dist/mjs/{index.js → src/index.js} +0 -0
  84. package/dist/mjs/{modules → src/modules}/bytes.js +0 -0
  85. package/dist/mjs/{modules → src/modules}/bzz.js +0 -0
  86. package/dist/mjs/{modules → src/modules}/chunk.js +0 -0
  87. package/dist/mjs/{modules → src/modules}/debug/balance.js +0 -0
  88. package/dist/mjs/{modules → src/modules}/debug/chequebook.js +0 -0
  89. package/dist/mjs/{modules → src/modules}/debug/chunk.js +0 -0
  90. package/dist/mjs/{modules → src/modules}/debug/connectivity.js +0 -0
  91. package/dist/mjs/{modules → src/modules}/debug/settlements.js +0 -0
  92. package/dist/mjs/{modules → src/modules}/debug/stamps.js +0 -0
  93. package/dist/mjs/{modules → src/modules}/debug/states.js +17 -0
  94. package/dist/mjs/{modules → src/modules}/debug/status.js +3 -3
  95. package/dist/mjs/{modules → src/modules}/debug/tag.js +0 -0
  96. package/dist/mjs/{modules → src/modules}/debug/transactions.js +0 -0
  97. package/dist/mjs/{modules → src/modules}/feed.js +1 -1
  98. package/dist/mjs/{modules → src/modules}/pinning.js +0 -0
  99. package/dist/mjs/{modules → src/modules}/pss.js +0 -0
  100. package/dist/mjs/{modules → src/modules}/soc.js +0 -0
  101. package/dist/mjs/{modules → src/modules}/status.js +0 -0
  102. package/dist/mjs/{modules → src/modules}/stewardship.js +0 -0
  103. package/dist/mjs/{modules → src/modules}/tag.js +0 -0
  104. package/dist/mjs/{types → src/types}/debug.js +0 -0
  105. package/dist/mjs/{types → src/types}/index.js +1 -0
  106. package/dist/mjs/{types → src/types}/ky-options.js +0 -0
  107. package/dist/mjs/{types → src/types}/ky-universal/common.js +0 -0
  108. package/dist/mjs/{types → src/types}/ky-universal/hooks.js +0 -0
  109. package/dist/mjs/{types → src/types}/ky-universal/retry.js +0 -0
  110. package/dist/mjs/{utils → src/utils}/bytes.js +15 -0
  111. package/dist/mjs/{utils → src/utils}/collection.browser.js +0 -0
  112. package/dist/mjs/{utils → src/utils}/collection.js +0 -0
  113. package/dist/mjs/{utils → src/utils}/collection.node.js +0 -0
  114. package/dist/mjs/{utils → src/utils}/data.browser.js +0 -0
  115. package/dist/mjs/{utils → src/utils}/data.js +0 -0
  116. package/dist/mjs/{utils → src/utils}/error.js +0 -0
  117. package/dist/mjs/{utils → src/utils}/eth.js +0 -0
  118. package/dist/mjs/{utils → src/utils}/expose.js +0 -0
  119. package/dist/mjs/{utils → src/utils}/file.js +0 -0
  120. package/dist/mjs/{utils → src/utils}/hash.js +0 -0
  121. package/dist/mjs/{utils → src/utils}/headers.js +0 -0
  122. package/dist/mjs/{utils → src/utils}/hex.js +0 -0
  123. package/dist/mjs/{utils → src/utils}/http.js +7 -0
  124. package/dist/mjs/{utils → src/utils}/merge.js +0 -0
  125. package/dist/mjs/{utils → src/utils}/pss.js +0 -0
  126. package/dist/mjs/src/utils/reference.js +32 -0
  127. package/dist/mjs/{utils → src/utils}/stamps.js +0 -0
  128. package/dist/mjs/{utils → src/utils}/stream.js +0 -0
  129. package/dist/mjs/{utils → src/utils}/tar.js +0 -0
  130. package/dist/mjs/{utils → src/utils}/type.js +109 -2
  131. package/dist/mjs/{utils → src/utils}/uint64.js +0 -0
  132. package/dist/mjs/{utils → src/utils}/url.js +0 -0
  133. package/dist/mjs/test/utils.js +458 -0
  134. package/dist/types/{bee-debug.d.ts → src/bee-debug.d.ts} +8 -1
  135. package/dist/types/{bee.d.ts → src/bee.d.ts} +55 -24
  136. package/dist/types/{chunk → src/chunk}/bmt.d.ts +0 -0
  137. package/dist/types/{chunk → src/chunk}/cac.d.ts +4 -5
  138. package/dist/types/{chunk → src/chunk}/serialize.d.ts +0 -0
  139. package/dist/types/{chunk → src/chunk}/signer.d.ts +0 -0
  140. package/dist/types/{chunk → src/chunk}/soc.d.ts +4 -4
  141. package/dist/types/{chunk → src/chunk}/span.d.ts +0 -0
  142. package/dist/types/src/feed/identifier.d.ts +4 -0
  143. package/dist/types/src/feed/index.d.ts +28 -0
  144. package/dist/types/{feed → src/feed}/json.d.ts +0 -0
  145. package/dist/types/src/feed/retrievable.d.ts +5 -0
  146. package/dist/types/{feed → src/feed}/topic.d.ts +0 -0
  147. package/dist/types/{feed → src/feed}/type.d.ts +0 -0
  148. package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
  149. package/dist/types/{modules → src/modules}/bytes.d.ts +3 -3
  150. package/dist/types/{modules → src/modules}/bzz.d.ts +3 -3
  151. package/dist/types/{modules → src/modules}/chunk.d.ts +2 -2
  152. package/dist/types/{modules → src/modules}/debug/balance.d.ts +0 -0
  153. package/dist/types/{modules → src/modules}/debug/chequebook.d.ts +0 -0
  154. package/dist/types/{modules → src/modules}/debug/chunk.d.ts +0 -0
  155. package/dist/types/{modules → src/modules}/debug/connectivity.d.ts +0 -0
  156. package/dist/types/{modules → src/modules}/debug/settlements.d.ts +0 -0
  157. package/dist/types/{modules → src/modules}/debug/stamps.d.ts +0 -0
  158. package/dist/types/{modules → src/modules}/debug/states.d.ts +7 -1
  159. package/dist/types/{modules → src/modules}/debug/status.d.ts +3 -3
  160. package/dist/types/{modules → src/modules}/debug/tag.d.ts +0 -0
  161. package/dist/types/{modules → src/modules}/debug/transactions.d.ts +0 -0
  162. package/dist/types/{modules → src/modules}/feed.d.ts +12 -1
  163. package/dist/types/{modules → src/modules}/pinning.d.ts +0 -0
  164. package/dist/types/{modules → src/modules}/pss.d.ts +0 -0
  165. package/dist/types/{modules → src/modules}/soc.d.ts +0 -0
  166. package/dist/types/{modules → src/modules}/status.d.ts +0 -0
  167. package/dist/types/{modules → src/modules}/stewardship.d.ts +3 -3
  168. package/dist/types/{modules → src/modules}/tag.d.ts +0 -0
  169. package/dist/types/{types → src/types}/debug.d.ts +19 -3
  170. package/dist/types/{types → src/types}/index.d.ts +33 -2
  171. package/dist/types/{types → src/types}/ky-options.d.ts +0 -0
  172. package/dist/types/{types → src/types}/ky-universal/common.d.ts +0 -0
  173. package/dist/types/{types → src/types}/ky-universal/hooks.d.ts +0 -0
  174. package/dist/types/{types → src/types}/ky-universal/retry.d.ts +0 -0
  175. package/dist/types/{utils → src/utils}/bytes.d.ts +7 -0
  176. package/dist/types/{utils → src/utils}/collection.browser.d.ts +0 -0
  177. package/dist/types/{utils → src/utils}/collection.d.ts +0 -0
  178. package/dist/types/{utils → src/utils}/collection.node.d.ts +0 -0
  179. package/dist/types/{utils → src/utils}/data.browser.d.ts +0 -0
  180. package/dist/types/{utils → src/utils}/data.d.ts +0 -0
  181. package/dist/types/{utils → src/utils}/error.d.ts +0 -0
  182. package/dist/types/{utils → src/utils}/eth.d.ts +0 -0
  183. package/dist/types/{utils → src/utils}/expose.d.ts +0 -0
  184. package/dist/types/{utils → src/utils}/file.d.ts +0 -0
  185. package/dist/types/{utils → src/utils}/hash.d.ts +0 -0
  186. package/dist/types/{utils → src/utils}/headers.d.ts +0 -0
  187. package/dist/types/{utils → src/utils}/hex.d.ts +0 -0
  188. package/dist/types/{utils → src/utils}/http.d.ts +0 -0
  189. package/dist/types/{utils → src/utils}/merge.d.ts +0 -0
  190. package/dist/types/{utils → src/utils}/pss.d.ts +0 -0
  191. package/dist/types/src/utils/reference.d.ts +2 -0
  192. package/dist/types/{utils → src/utils}/stamps.d.ts +0 -0
  193. package/dist/types/{utils → src/utils}/stream.d.ts +0 -0
  194. package/dist/types/{utils → src/utils}/tar.d.ts +0 -0
  195. package/dist/types/{utils → src/utils}/type.d.ts +17 -1
  196. package/dist/types/{utils → src/utils}/uint64.d.ts +0 -0
  197. package/dist/types/{utils → src/utils}/url.d.ts +0 -0
  198. package/dist/types/test/utils.d.ts +119 -0
  199. package/package.json +24 -24
  200. package/dist/types/feed/index.d.ts +0 -35
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Bee-js
2
2
 
3
3
  [![Tests](https://github.com/ethersphere/bee-js/actions/workflows/tests.yaml/badge.svg)](https://github.com/ethersphere/bee-js/actions/workflows/tests.yaml)
4
- [![Dependency Status](https://david-dm.org/ethersphere/bee-js.svg?style=flat-square)](https://david-dm.org/ethersphere/bee-js)
5
4
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_shield)
6
5
  [![](https://img.shields.io/badge/made%20by-Swarm-blue.svg?style=flat-square)](https://swarm.ethereum.org/)
7
6
  [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
@@ -90,14 +89,6 @@ console.log(data.text()) // prints 'Bee is awesome!'
90
89
 
91
90
  You can find the full documentation [here](https://bee-js.ethswarm.org/docs). The API reference documentation can be found [here](https://bee-js.ethswarm.org/docs/api).
92
91
 
93
- You can generate API docs locally with:
94
-
95
- ```sh
96
- npm run docs
97
- ```
98
-
99
- The generated docs can be viewed in browser by opening `./docs/index.html`
100
-
101
92
  ## Contribute
102
93
 
103
94
  There are some ways you can make this module better:
@@ -118,25 +109,15 @@ npm i
118
109
 
119
110
  The tests run in both context: node and dom with Jest.
120
111
 
121
- To run the integration tests, you need to use our [`bee-factory`](https://github.com/ethersphere/bee-factory/) project. Clone the repo, you can use our prebuilt Docker images with setting env. variables like:
122
-
123
- ```bash
124
- export BEE_VERSION="1.0.0-2572fa48"
125
- export BLOCKCHAIN_VERSION="1.2.0"
126
- export BEE_ENV_PREFIX="swarm-test"
127
- export BEE_IMAGE_PREFIX="docker.pkg.github.com/ethersphere/bee-factory"
128
- ```
129
-
130
- Customize these values based on which Bee version you want to run. After the env. variables are set use the `./scripts/environment.sh` script with `start` parameter.
112
+ To run the integration tests, you need to spin up local Bee cluster using our [`bee-factory`](https://github.com/ethersphere/bee-factory/) project.
113
+ In order to do that you have to have locally Docker running on your machine, but afterwards you can just simply run `npm run bee`, which spins up the
114
+ cluster and display Queen's logs. If you want to exit hit `CTRL+C`.
131
115
 
132
116
  If you want to skip creation of postage stamps every run of integration tests you can create stamps for both nodes and set them under env. variables `BEE_POSTAGE` and `BEE_PEER_POSTAGE`.
133
117
 
134
118
  By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633` and `http://localhost:11633`. These are the default values for the `bee-factory` script.
135
119
  If you want to use custom setup, you can change the behavior of tests to different addresses using environment variables `BEE_API_URL`, `BEE_DEBUG_API_URL`, `BEE_PEER_DEBUG_API_URL` and `BEE_PEER_API_URL`.
136
120
 
137
- In Visual Studio environment, the tests have been set up to run against your local bee node on `http://localhost:1633`
138
- To run Jest tests, choose the `vscode-jest-tests` CI job under the Run tab.
139
-
140
121
  There are also browser tests by Puppeteer, which also provide integrity testing.
141
122
  ```sh
142
123
  npm run test:browser
@@ -43,6 +43,7 @@ const types_1 = require("./types");
43
43
  const tag = __importStar(require("./modules/debug/tag"));
44
44
  const stamps = __importStar(require("./modules/debug/stamps"));
45
45
  const http_1 = require("./utils/http");
46
+ const utils_1 = require("../test/utils");
46
47
  class BeeDebug {
47
48
  constructor(url, options) {
48
49
  var _a;
@@ -431,6 +432,17 @@ class BeeDebug {
431
432
  return states.getChainState(this.getKy(options));
432
433
  });
433
434
  }
435
+ /**
436
+ * Get wallet balances for xDai and BZZ of the Bee node
437
+ *
438
+ * @param options
439
+ */
440
+ getWalletBalance(options) {
441
+ return __awaiter(this, void 0, void 0, function* () {
442
+ (0, type_1.assertRequestOptions)(options);
443
+ return states.getWalletBalance(this.getKy(options));
444
+ });
445
+ }
434
446
  /**
435
447
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
436
448
  *
@@ -450,8 +462,8 @@ class BeeDebug {
450
462
  */
451
463
  createPostageBatch(amount, depth, options) {
452
464
  return __awaiter(this, void 0, void 0, function* () {
453
- (0, type_1.assertRequestOptions)(options);
454
- (0, type_1.assertNonNegativeInteger)(amount);
465
+ (0, type_1.assertPostageBatchOptions)(options);
466
+ (0, type_1.assertPositiveInteger)(amount);
455
467
  (0, type_1.assertNonNegativeInteger)(depth);
456
468
  if (depth < types_1.STAMPS_DEPTH_MIN) {
457
469
  throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
@@ -459,13 +471,11 @@ class BeeDebug {
459
471
  if (depth > types_1.STAMPS_DEPTH_MAX) {
460
472
  throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
461
473
  }
462
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
463
- (0, type_1.assertNonNegativeInteger)(options.gasPrice);
474
+ const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
475
+ if (options === null || options === void 0 ? void 0 : options.waitForUsable) {
476
+ yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
464
477
  }
465
- if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
466
- (0, type_1.assertBoolean)(options.immutableFlag);
467
- }
468
- return stamps.createPostageBatch(this.getKy(options), amount, depth, options);
478
+ return stamp;
469
479
  });
470
480
  }
471
481
  /**
@@ -605,6 +615,19 @@ class BeeDebug {
605
615
  return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
606
616
  });
607
617
  }
618
+ waitForUsablePostageStamp(id, timeout = 120000) {
619
+ return __awaiter(this, void 0, void 0, function* () {
620
+ const TIME_STEP = 1500;
621
+ for (let time = 0; time < timeout; time += TIME_STEP) {
622
+ const stamp = yield this.getPostageBatch(id);
623
+ if (stamp.usable) {
624
+ return;
625
+ }
626
+ yield (0, utils_1.sleep)(TIME_STEP);
627
+ }
628
+ throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
629
+ });
630
+ }
608
631
  getKy(options) {
609
632
  if (!options) {
610
633
  return this.ky;
@@ -56,6 +56,8 @@ const collection_node_1 = require("./utils/collection.node");
56
56
  const types_1 = require("./types");
57
57
  const http_1 = require("./utils/http");
58
58
  const stream_1 = require("./utils/stream");
59
+ const retrievable_1 = require("./feed/retrievable");
60
+ const swarm_cid_1 = require("@ethersphere/swarm-cid");
59
61
  /**
60
62
  * The main component that abstracts operations available on the main Bee API.
61
63
  *
@@ -121,30 +123,34 @@ class Bee {
121
123
  /**
122
124
  * Download data as a byte array
123
125
  *
124
- * @param reference Bee data reference
126
+ * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
125
127
  * @param options Options that affects the request behavior
128
+ * @throws TypeError if some of the input parameters is not expected type
129
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
126
130
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
127
131
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
128
132
  */
129
133
  downloadData(reference, options) {
130
134
  return __awaiter(this, void 0, void 0, function* () {
131
135
  (0, type_2.assertRequestOptions)(options);
132
- (0, type_2.assertReference)(reference);
136
+ (0, type_2.assertReferenceOrEns)(reference);
133
137
  return bytes.download(this.getKy(options), reference);
134
138
  });
135
139
  }
136
140
  /**
137
141
  * Download data as a Readable stream
138
142
  *
139
- * @param reference Bee data reference
143
+ * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
140
144
  * @param options Options that affects the request behavior
145
+ * @throws TypeError if some of the input parameters is not expected type
146
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
141
147
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
142
148
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
143
149
  */
144
150
  downloadReadableData(reference, options) {
145
151
  return __awaiter(this, void 0, void 0, function* () {
146
152
  (0, type_2.assertRequestOptions)(options);
147
- (0, type_2.assertReference)(reference);
153
+ (0, type_2.assertReferenceOrEns)(reference);
148
154
  return bytes.downloadReadable(this.getKy(options), reference);
149
155
  });
150
156
  }
@@ -179,15 +185,17 @@ class Bee {
179
185
  /**
180
186
  * Download chunk as a byte array
181
187
  *
182
- * @param reference Bee chunk reference
188
+ * @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
183
189
  * @param options Options that affects the request behavior
190
+ * @throws TypeError if some of the input parameters is not expected type
191
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
184
192
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
185
193
  * @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
186
194
  */
187
195
  downloadChunk(reference, options) {
188
196
  return __awaiter(this, void 0, void 0, function* () {
189
197
  (0, type_2.assertRequestOptions)(options);
190
- (0, type_2.assertReference)(reference);
198
+ (0, type_2.assertReferenceOrEns)(reference);
191
199
  return chunk.download(this.getKy(options), reference);
192
200
  });
193
201
  }
@@ -221,26 +229,27 @@ class Bee {
221
229
  const fileName = name !== null && name !== void 0 ? name : data.name;
222
230
  const contentType = data.type;
223
231
  const fileOptions = Object.assign({ contentType }, options);
224
- return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
232
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), swarm_cid_1.ReferenceType.MANIFEST);
225
233
  }
226
234
  else if ((0, stream_1.isReadable)(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
227
235
  // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
228
236
  const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
229
237
  yield this.updateTag(options.tag, result.reference);
230
- return result;
238
+ return (0, type_2.addCidConversionFunction)(result, swarm_cid_1.ReferenceType.MANIFEST);
231
239
  }
232
240
  else {
233
- return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
241
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), swarm_cid_1.ReferenceType.MANIFEST);
234
242
  }
235
243
  });
236
244
  }
237
245
  /**
238
246
  * Download single file.
239
247
  *
240
- * @param reference Bee file reference
248
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
241
249
  * @param path If reference points to manifest, then this parameter defines path to the file
242
250
  * @param options Options that affects the request behavior
243
- *
251
+ * @throws TypeError if some of the input parameters is not expected type
252
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
244
253
  * @see Data
245
254
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
246
255
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
@@ -248,16 +257,18 @@ class Bee {
248
257
  downloadFile(reference, path = '', options) {
249
258
  return __awaiter(this, void 0, void 0, function* () {
250
259
  (0, type_2.assertRequestOptions)(options);
251
- (0, type_2.assertReference)(reference);
260
+ reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
252
261
  return bzz.downloadFile(this.getKy(options), reference, path);
253
262
  });
254
263
  }
255
264
  /**
256
265
  * Download single file as a readable stream
257
266
  *
258
- * @param reference Hash reference to file
267
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
259
268
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
260
269
  * @param options Options that affects the request behavior
270
+ * @throws TypeError if some of the input parameters is not expected type
271
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
261
272
  *
262
273
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
263
274
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
@@ -265,7 +276,7 @@ class Bee {
265
276
  downloadReadableFile(reference, path = '', options) {
266
277
  return __awaiter(this, void 0, void 0, function* () {
267
278
  (0, type_2.assertRequestOptions)(options);
268
- (0, type_2.assertReference)(reference);
279
+ reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
269
280
  return bzz.downloadFileReadable(this.getKy(options), reference, path);
270
281
  });
271
282
  }
@@ -291,7 +302,7 @@ class Bee {
291
302
  if (options)
292
303
  (0, type_2.assertCollectionUploadOptions)(options);
293
304
  const data = yield (0, collection_1.makeCollectionFromFileList)(fileList);
294
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
305
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
295
306
  });
296
307
  }
297
308
  /**
@@ -310,7 +321,7 @@ class Bee {
310
321
  (0, collection_1.assertCollection)(collection);
311
322
  if (options)
312
323
  (0, type_2.assertCollectionUploadOptions)(options);
313
- return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
324
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
314
325
  });
315
326
  }
316
327
  /**
@@ -335,7 +346,7 @@ class Bee {
335
346
  if (options)
336
347
  (0, type_2.assertCollectionUploadOptions)(options);
337
348
  const data = yield (0, collection_node_1.makeCollectionFromFS)(dir);
338
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
349
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
339
350
  });
340
351
  }
341
352
  /**
@@ -494,9 +505,10 @@ class Bee {
494
505
  *
495
506
  * **Warning! Not allowed when node is in Gateway mode!**
496
507
  *
497
- * @param reference Bee data reference
508
+ * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
498
509
  * @param options Options that affects the request behavior
499
- * @throws TypeError if reference is in not correct format
510
+ * @throws TypeError if some of the input parameters is not expected type
511
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
500
512
  *
501
513
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
502
514
  */
@@ -510,35 +522,77 @@ class Bee {
510
522
  /**
511
523
  * Instructs the Bee node to reupload a locally pinned data into the network.
512
524
  *
513
- * @param reference
525
+ * @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
514
526
  * @param options Options that affects the request behavior
515
527
  * @throws BeeArgumentError if the reference is not locally pinned
516
- * @throws TypeError if reference is in not correct format
528
+ * @throws TypeError if some of the input parameters is not expected type
529
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
517
530
  *
518
531
  * @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
519
532
  */
520
533
  reuploadPinnedData(reference, options) {
521
534
  return __awaiter(this, void 0, void 0, function* () {
522
535
  (0, type_2.assertRequestOptions)(options);
523
- (0, type_2.assertReference)(reference);
536
+ (0, type_2.assertReferenceOrEns)(reference);
524
537
  yield stewardship.reupload(this.getKy(options), reference);
525
538
  });
526
539
  }
527
540
  /**
528
541
  * Checks if content specified by reference is retrievable from the network.
529
542
  *
530
- * @param reference The checked content
543
+ * @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
531
544
  * @param options Options that affects the request behavior
545
+ * @throws TypeError if some of the input parameters is not expected type
546
+ * @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
532
547
  *
533
548
  * @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
534
549
  */
535
550
  isReferenceRetrievable(reference, options) {
536
551
  return __awaiter(this, void 0, void 0, function* () {
537
552
  (0, type_2.assertRequestOptions)(options);
538
- (0, type_2.assertReference)(reference);
553
+ (0, type_2.assertReferenceOrEns)(reference);
539
554
  return stewardship.isRetrievable(this.getKy(options), reference);
540
555
  });
541
556
  }
557
+ /**
558
+ * Functions that validates if feed is retrievable in the network.
559
+ *
560
+ * If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
561
+ * sure what is the "latest" update.
562
+ *
563
+ * If index is passed then it validates all previous sequence index chunks if they are available as they are required
564
+ * to correctly resolve the feed upto the given index update.
565
+ *
566
+ * @param type
567
+ * @param owner
568
+ * @param topic
569
+ * @param index
570
+ * @param options
571
+ */
572
+ isFeedRetrievable(type, owner, topic, index, options) {
573
+ return __awaiter(this, void 0, void 0, function* () {
574
+ const canonicalOwner = (0, eth_1.makeEthAddress)(owner);
575
+ const canonicalTopic = (0, topic_1.makeTopic)(topic);
576
+ if (!index) {
577
+ try {
578
+ yield this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
579
+ return true;
580
+ }
581
+ catch (e) {
582
+ const err = e;
583
+ // Only if the error is "not-found" then we return false otherwise we re-throw the error
584
+ if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
585
+ return false;
586
+ }
587
+ throw e;
588
+ }
589
+ }
590
+ if (type !== 'sequence') {
591
+ throw new error_1.BeeError('Only Sequence type of Feeds is supported at the moment');
592
+ }
593
+ return (0, retrievable_1.areAllSequentialFeedsUpdateRetrievable)(this, canonicalOwner, canonicalTopic, index, options);
594
+ });
595
+ }
542
596
  /**
543
597
  * Send data to recipient or target with Postal Service for Swarm.
544
598
  *
@@ -707,6 +761,7 @@ class Bee {
707
761
  *
708
762
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
709
763
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
764
+ * TODO: Once breaking add support for Feed CID
710
765
  */
711
766
  createFeedManifest(postageBatchId, type, topic, owner, options) {
712
767
  return __awaiter(this, void 0, void 0, function* () {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeFeedIdentifier = void 0;
4
+ const types_1 = require("../types");
5
+ const hash_1 = require("../utils/hash");
6
+ const hex_1 = require("../utils/hex");
7
+ const uint64_1 = require("../utils/uint64");
8
+ function isEpoch(epoch) {
9
+ return typeof epoch === 'object' && epoch !== null && 'time' in epoch && 'level' in epoch;
10
+ }
11
+ function hashFeedIdentifier(topic, index) {
12
+ return (0, hash_1.keccak256Hash)((0, hex_1.hexToBytes)(topic), index);
13
+ }
14
+ function makeSequentialFeedIdentifier(topic, index) {
15
+ const indexBytes = (0, uint64_1.writeUint64BigEndian)(index);
16
+ return hashFeedIdentifier(topic, indexBytes);
17
+ }
18
+ function makeFeedIndexBytes(s) {
19
+ const hex = (0, hex_1.makeHexString)(s, types_1.FEED_INDEX_HEX_LENGTH);
20
+ return (0, hex_1.hexToBytes)(hex);
21
+ }
22
+ function makeFeedIdentifier(topic, index) {
23
+ if (typeof index === 'number') {
24
+ return makeSequentialFeedIdentifier(topic, index);
25
+ }
26
+ else if (typeof index === 'string') {
27
+ const indexBytes = makeFeedIndexBytes(index);
28
+ return hashFeedIdentifier(topic, indexBytes);
29
+ }
30
+ else if (isEpoch(index)) {
31
+ throw new TypeError('epoch is not yet implemented');
32
+ }
33
+ return hashFeedIdentifier(topic, index);
34
+ }
35
+ exports.makeFeedIdentifier = makeFeedIdentifier;
@@ -28,11 +28,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28
28
  });
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdate = exports.verifyChunkReference = exports.updateFeed = exports.findNextIndex = exports.uploadFeedUpdate = exports.makeFeedIdentifier = exports.makeFeedIndexBytes = exports.makeSequentialFeedIdentifier = exports.isEpoch = void 0;
31
+ exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeed = exports.findNextIndex = void 0;
32
32
  const hash_1 = require("../utils/hash");
33
33
  const serialize_1 = require("../chunk/serialize");
34
- const soc_1 = require("../chunk/soc");
35
34
  const feed_1 = require("../modules/feed");
35
+ const soc_1 = require("../chunk/soc");
36
36
  const types_1 = require("../types");
37
37
  const bytes_1 = require("../utils/bytes");
38
38
  const error_1 = require("../utils/error");
@@ -41,59 +41,16 @@ const uint64_1 = require("../utils/uint64");
41
41
  const chunkAPI = __importStar(require("../modules/chunk"));
42
42
  const eth_1 = require("../utils/eth");
43
43
  const type_1 = require("../utils/type");
44
+ const identifier_1 = require("./identifier");
45
+ const reference_1 = require("../utils/reference");
44
46
  const TIMESTAMP_PAYLOAD_OFFSET = 0;
45
47
  const TIMESTAMP_PAYLOAD_SIZE = 8;
46
48
  const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
47
- const REFERENCE_PAYLOAD_MIN_SIZE = 32;
48
- const REFERENCE_PAYLOAD_MAX_SIZE = 64;
49
- const INDEX_HEX_LENGTH = 16;
50
- function isEpoch(epoch) {
51
- return typeof epoch === 'object' && epoch !== null && 'time' in epoch && 'level' in epoch;
52
- }
53
- exports.isEpoch = isEpoch;
54
- function hashFeedIdentifier(topic, index) {
55
- return (0, hash_1.keccak256Hash)((0, hex_1.hexToBytes)(topic), index);
56
- }
57
- function makeSequentialFeedIdentifier(topic, index) {
58
- const indexBytes = (0, uint64_1.writeUint64BigEndian)(index);
59
- return hashFeedIdentifier(topic, indexBytes);
60
- }
61
- exports.makeSequentialFeedIdentifier = makeSequentialFeedIdentifier;
62
- function makeFeedIndexBytes(s) {
63
- const hex = (0, hex_1.makeHexString)(s, INDEX_HEX_LENGTH);
64
- return (0, hex_1.hexToBytes)(hex);
65
- }
66
- exports.makeFeedIndexBytes = makeFeedIndexBytes;
67
- function makeFeedIdentifier(topic, index) {
68
- if (typeof index === 'number') {
69
- return makeSequentialFeedIdentifier(topic, index);
70
- }
71
- else if (typeof index === 'string') {
72
- const indexBytes = makeFeedIndexBytes(index);
73
- return hashFeedIdentifier(topic, indexBytes);
74
- }
75
- else if (isEpoch(index)) {
76
- throw new TypeError('epoch is not yet implemented');
77
- }
78
- return hashFeedIdentifier(topic, index);
79
- }
80
- exports.makeFeedIdentifier = makeFeedIdentifier;
81
- function uploadFeedUpdate(ky, signer, topic, index, reference, postageBatchId, options) {
82
- var _a;
83
- return __awaiter(this, void 0, void 0, function* () {
84
- const identifier = makeFeedIdentifier(topic, index);
85
- const at = (_a = options === null || options === void 0 ? void 0 : options.at) !== null && _a !== void 0 ? _a : Date.now() / 1000.0;
86
- const timestamp = (0, uint64_1.writeUint64BigEndian)(at);
87
- const payloadBytes = (0, serialize_1.serializeBytes)(timestamp, reference);
88
- return (0, soc_1.uploadSingleOwnerChunkData)(ky, signer, postageBatchId, identifier, payloadBytes, options);
89
- });
90
- }
91
- exports.uploadFeedUpdate = uploadFeedUpdate;
92
49
  function findNextIndex(ky, owner, topic, options) {
93
50
  return __awaiter(this, void 0, void 0, function* () {
94
51
  try {
95
- const feedUpdate = yield (0, feed_1.fetchFeedUpdate)(ky, owner, topic, options);
96
- return (0, hex_1.makeHexString)(feedUpdate.feedIndexNext, INDEX_HEX_LENGTH);
52
+ const feedUpdate = yield (0, feed_1.fetchLatestFeedUpdate)(ky, owner, topic, options);
53
+ return (0, hex_1.makeHexString)(feedUpdate.feedIndexNext, types_1.FEED_INDEX_HEX_LENGTH);
97
54
  }
98
55
  catch (e) {
99
56
  if (e instanceof error_1.BeeResponseError && e.status === 404) {
@@ -104,37 +61,34 @@ function findNextIndex(ky, owner, topic, options) {
104
61
  });
105
62
  }
106
63
  exports.findNextIndex = findNextIndex;
107
- function updateFeed(ky, signer, topic, reference, postageBatchId, options) {
64
+ function updateFeed(ky, signer, topic, reference, postageBatchId, options, index = 'latest') {
65
+ var _a;
108
66
  return __awaiter(this, void 0, void 0, function* () {
109
67
  const ownerHex = (0, eth_1.makeHexEthAddress)(signer.address);
110
- const nextIndex = yield findNextIndex(ky, ownerHex, topic, options);
111
- return uploadFeedUpdate(ky, signer, topic, nextIndex, reference, postageBatchId, options);
68
+ const nextIndex = index === 'latest' ? yield findNextIndex(ky, ownerHex, topic, options) : index;
69
+ const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
70
+ const at = (_a = options === null || options === void 0 ? void 0 : options.at) !== null && _a !== void 0 ? _a : Date.now() / 1000.0;
71
+ const timestamp = (0, uint64_1.writeUint64BigEndian)(at);
72
+ const payloadBytes = (0, serialize_1.serializeBytes)(timestamp, reference);
73
+ return (0, soc_1.uploadSingleOwnerChunkData)(ky, signer, postageBatchId, identifier, payloadBytes, options);
112
74
  });
113
75
  }
114
76
  exports.updateFeed = updateFeed;
115
- function verifyChunkReferenceAtOffset(offset, data) {
116
- try {
117
- return (0, bytes_1.bytesAtOffset)(data, offset, REFERENCE_PAYLOAD_MAX_SIZE);
118
- }
119
- catch (e) {
120
- return (0, bytes_1.bytesAtOffset)(data, offset, REFERENCE_PAYLOAD_MIN_SIZE);
121
- }
122
- }
123
- function verifyChunkReference(data) {
124
- return verifyChunkReferenceAtOffset(0, data);
77
+ function getFeedUpdateChunkReference(owner, topic, index) {
78
+ const identifier = (0, identifier_1.makeFeedIdentifier)(topic, index);
79
+ return (0, hash_1.keccak256Hash)(identifier, owner);
125
80
  }
126
- exports.verifyChunkReference = verifyChunkReference;
81
+ exports.getFeedUpdateChunkReference = getFeedUpdateChunkReference;
127
82
  function downloadFeedUpdate(ky, owner, topic, index) {
128
83
  return __awaiter(this, void 0, void 0, function* () {
129
- const identifier = makeFeedIdentifier(topic, index);
130
- const address = (0, hash_1.keccak256Hash)(identifier, owner);
84
+ const address = getFeedUpdateChunkReference(owner, topic, index);
131
85
  const addressHex = (0, hex_1.bytesToHex)(address);
132
86
  const data = yield chunkAPI.download(ky, addressHex);
133
87
  const soc = (0, soc_1.makeSingleOwnerChunkFromData)(data, address);
134
88
  const payload = soc.payload();
135
89
  const timestampBytes = (0, bytes_1.bytesAtOffset)(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
136
90
  const timestamp = (0, uint64_1.readUint64BigEndian)(timestampBytes);
137
- const reference = verifyChunkReferenceAtOffset(REFERENCE_PAYLOAD_OFFSET, payload);
91
+ const reference = (0, reference_1.makeBytesReference)(payload, REFERENCE_PAYLOAD_OFFSET);
138
92
  return {
139
93
  timestamp,
140
94
  reference,
@@ -143,40 +97,30 @@ function downloadFeedUpdate(ky, owner, topic, index) {
143
97
  }
144
98
  exports.downloadFeedUpdate = downloadFeedUpdate;
145
99
  function makeFeedReader(ky, type, topic, owner) {
146
- const download = (options) => __awaiter(this, void 0, void 0, function* () { return (0, feed_1.fetchFeedUpdate)(ky, owner, topic, Object.assign(Object.assign({}, options), { type })); });
147
100
  return {
148
101
  type,
149
102
  owner,
150
103
  topic,
151
- download,
104
+ download(options) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ if (!(options === null || options === void 0 ? void 0 : options.index)) {
107
+ return (0, feed_1.fetchLatestFeedUpdate)(ky, owner, topic, Object.assign(Object.assign({}, options), { type }));
108
+ }
109
+ const update = yield downloadFeedUpdate(ky, (0, hex_1.hexToBytes)(owner), topic, options.index);
110
+ return {
111
+ reference: (0, hex_1.bytesToHex)(update.reference),
112
+ feedIndex: options.index,
113
+ feedIndexNext: '',
114
+ };
115
+ });
116
+ },
152
117
  };
153
118
  }
154
119
  exports.makeFeedReader = makeFeedReader;
155
- function makeChunkReference(reference) {
156
- if (typeof reference === 'string') {
157
- try {
158
- // Non-encrypted chunk hex string reference
159
- const hexReference = (0, hex_1.makeHexString)(reference, types_1.REFERENCE_HEX_LENGTH);
160
- return (0, hex_1.hexToBytes)(hexReference);
161
- }
162
- catch (e) {
163
- if (!(e instanceof TypeError)) {
164
- throw e;
165
- }
166
- // Encrypted chunk hex string reference
167
- const hexReference = (0, hex_1.makeHexString)(reference, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
168
- return (0, hex_1.hexToBytes)(hexReference);
169
- }
170
- }
171
- else if (reference instanceof Uint8Array) {
172
- return verifyChunkReference(reference);
173
- }
174
- throw new TypeError('invalid chunk reference');
175
- }
176
120
  function makeFeedWriter(ky, type, topic, signer) {
177
121
  const upload = (postageBatchId, reference, options) => __awaiter(this, void 0, void 0, function* () {
178
122
  (0, type_1.assertAddress)(postageBatchId);
179
- const canonicalReference = makeChunkReference(reference);
123
+ const canonicalReference = (0, reference_1.makeBytesReference)(reference);
180
124
  return updateFeed(ky, signer, topic, canonicalReference, postageBatchId, Object.assign(Object.assign({}, options), { type }));
181
125
  });
182
126
  return Object.assign(Object.assign({}, makeFeedReader(ky, type, topic, (0, eth_1.makeHexEthAddress)(signer.address))), { upload });
File without changes