@ethersphere/bee-js 8.3.1 → 9.0.2

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 (224) hide show
  1. package/README.md +192 -50
  2. package/dist/cjs/bee-dev.js +78 -0
  3. package/dist/cjs/bee.js +341 -417
  4. package/dist/cjs/chunk/bmt.js +15 -32
  5. package/dist/cjs/chunk/cac.js +26 -36
  6. package/dist/cjs/chunk/soc.js +56 -51
  7. package/dist/cjs/feed/identifier.js +3 -28
  8. package/dist/cjs/feed/index.js +95 -44
  9. package/dist/cjs/feed/retrievable.js +11 -22
  10. package/dist/cjs/index.js +17 -1
  11. package/dist/cjs/manifest/manifest.js +369 -0
  12. package/dist/cjs/modules/bytes.js +24 -12
  13. package/dist/cjs/modules/bzz.js +24 -34
  14. package/dist/cjs/modules/chunk.js +13 -7
  15. package/dist/cjs/modules/debug/balance.js +29 -4
  16. package/dist/cjs/modules/debug/chequebook.js +60 -16
  17. package/dist/cjs/modules/debug/connectivity.js +82 -4
  18. package/dist/cjs/modules/debug/settlements.js +22 -2
  19. package/dist/cjs/modules/debug/stake.js +29 -11
  20. package/dist/cjs/modules/debug/stamps.js +88 -7
  21. package/dist/cjs/modules/debug/states.js +25 -3
  22. package/dist/cjs/modules/debug/status.js +45 -47
  23. package/dist/cjs/modules/debug/transactions.js +27 -5
  24. package/dist/cjs/modules/envelope.js +8 -6
  25. package/dist/cjs/modules/feed.js +25 -10
  26. package/dist/cjs/modules/grantee.js +18 -12
  27. package/dist/cjs/modules/gsoc.js +24 -0
  28. package/dist/cjs/modules/pinning.js +13 -2
  29. package/dist/cjs/modules/pss.js +9 -3
  30. package/dist/cjs/modules/soc.js +9 -4
  31. package/dist/cjs/modules/stewardship.js +7 -3
  32. package/dist/cjs/modules/tag.js +35 -3
  33. package/dist/cjs/package.json +1 -0
  34. package/dist/cjs/stamper/stamper.js +43 -0
  35. package/dist/cjs/types/debug.js +16 -1
  36. package/dist/cjs/types/index.js +2 -24
  37. package/dist/cjs/utils/bytes.js +67 -115
  38. package/dist/cjs/utils/chunk-size.js +17 -0
  39. package/dist/cjs/utils/chunk-stream.browser.js +85 -0
  40. package/dist/cjs/utils/chunk-stream.js +84 -0
  41. package/dist/cjs/utils/cid.js +5 -6
  42. package/dist/cjs/utils/collection.browser.js +2 -2
  43. package/dist/cjs/utils/collection.js +3 -2
  44. package/dist/cjs/utils/collection.node.js +0 -2
  45. package/dist/cjs/utils/constants.js +7 -3
  46. package/dist/cjs/utils/data.browser.js +6 -3
  47. package/dist/cjs/utils/data.js +8 -4
  48. package/dist/cjs/utils/duration.js +51 -0
  49. package/dist/cjs/utils/expose.js +11 -40
  50. package/dist/cjs/utils/headers.js +79 -52
  51. package/dist/cjs/utils/http.js +34 -10
  52. package/dist/cjs/utils/mime.js +78 -0
  53. package/dist/cjs/utils/pss.js +3 -4
  54. package/dist/cjs/utils/redundancy.js +18 -14
  55. package/dist/cjs/utils/resource-locator.js +17 -0
  56. package/dist/cjs/utils/size.js +35 -0
  57. package/dist/cjs/utils/stamps.js +67 -51
  58. package/dist/cjs/utils/tar-uploader.browser.js +2 -2
  59. package/dist/cjs/utils/tar-uploader.js +2 -2
  60. package/dist/cjs/utils/tokens.js +144 -0
  61. package/dist/cjs/utils/type.js +142 -350
  62. package/dist/cjs/utils/typed-bytes.js +179 -0
  63. package/dist/cjs/utils/upload-progress.js +2 -0
  64. package/dist/cjs/utils/url.js +0 -4
  65. package/dist/cjs/utils/workaround.js +27 -0
  66. package/dist/index.browser.min.js +1 -2
  67. package/dist/index.browser.min.js.map +1 -1
  68. package/dist/mjs/bee-dev.js +98 -0
  69. package/dist/mjs/bee.js +367 -411
  70. package/dist/mjs/chunk/bmt.js +13 -29
  71. package/dist/mjs/chunk/cac.js +26 -34
  72. package/dist/mjs/chunk/soc.js +57 -53
  73. package/dist/mjs/feed/identifier.js +3 -26
  74. package/dist/mjs/feed/index.js +98 -51
  75. package/dist/mjs/feed/retrievable.js +12 -23
  76. package/dist/mjs/index.js +10 -1
  77. package/dist/mjs/manifest/manifest.js +371 -0
  78. package/dist/mjs/modules/bytes.js +27 -15
  79. package/dist/mjs/modules/bzz.js +25 -32
  80. package/dist/mjs/modules/chunk.js +16 -8
  81. package/dist/mjs/modules/debug/balance.js +61 -4
  82. package/dist/mjs/modules/debug/chequebook.js +116 -16
  83. package/dist/mjs/modules/debug/connectivity.js +144 -3
  84. package/dist/mjs/modules/debug/settlements.js +46 -2
  85. package/dist/mjs/modules/debug/stake.js +69 -11
  86. package/dist/mjs/modules/debug/stamps.js +184 -7
  87. package/dist/mjs/modules/debug/states.js +55 -3
  88. package/dist/mjs/modules/debug/status.js +97 -45
  89. package/dist/mjs/modules/debug/transactions.js +61 -5
  90. package/dist/mjs/modules/envelope.js +11 -9
  91. package/dist/mjs/modules/feed.js +26 -10
  92. package/dist/mjs/modules/grantee.js +35 -13
  93. package/dist/mjs/modules/gsoc.js +16 -0
  94. package/dist/mjs/modules/pinning.js +23 -2
  95. package/dist/mjs/modules/pss.js +10 -4
  96. package/dist/mjs/modules/soc.js +10 -5
  97. package/dist/mjs/modules/stewardship.js +14 -4
  98. package/dist/mjs/modules/tag.js +93 -3
  99. package/dist/mjs/package.json +2 -1
  100. package/dist/mjs/stamper/stamper.js +39 -0
  101. package/dist/mjs/types/debug.js +15 -1
  102. package/dist/mjs/types/index.js +2 -24
  103. package/dist/mjs/utils/bytes.js +63 -104
  104. package/dist/mjs/utils/chunk-size.js +13 -0
  105. package/dist/mjs/utils/chunk-stream.browser.js +85 -0
  106. package/dist/mjs/utils/chunk-stream.js +87 -0
  107. package/dist/mjs/utils/cid.js +5 -6
  108. package/dist/mjs/utils/collection.browser.js +2 -2
  109. package/dist/mjs/utils/collection.js +2 -2
  110. package/dist/mjs/utils/collection.node.js +0 -2
  111. package/dist/mjs/utils/constants.js +6 -2
  112. package/dist/mjs/utils/data.browser.js +9 -3
  113. package/dist/mjs/utils/data.js +12 -4
  114. package/dist/mjs/utils/duration.js +47 -0
  115. package/dist/mjs/utils/expose.js +2 -7
  116. package/dist/mjs/utils/headers.js +73 -48
  117. package/dist/mjs/utils/http.js +33 -11
  118. package/dist/mjs/utils/mime.js +75 -0
  119. package/dist/mjs/utils/pss.js +3 -4
  120. package/dist/mjs/utils/redundancy.js +18 -8
  121. package/dist/mjs/utils/resource-locator.js +13 -0
  122. package/dist/mjs/utils/size.js +31 -0
  123. package/dist/mjs/utils/stamps.js +47 -44
  124. package/dist/mjs/utils/tar-uploader.browser.js +2 -2
  125. package/dist/mjs/utils/tar-uploader.js +2 -2
  126. package/dist/mjs/utils/tokens.js +139 -0
  127. package/dist/mjs/utils/type.js +216 -310
  128. package/dist/mjs/utils/typed-bytes.js +160 -0
  129. package/dist/mjs/utils/upload-progress.js +1 -0
  130. package/dist/mjs/utils/url.js +0 -4
  131. package/dist/mjs/utils/workaround.js +22 -0
  132. package/dist/types/bee-dev.d.ts +5 -0
  133. package/dist/types/bee.d.ts +88 -165
  134. package/dist/types/chunk/bmt.d.ts +2 -2
  135. package/dist/types/chunk/cac.d.ts +7 -24
  136. package/dist/types/chunk/soc.d.ts +15 -15
  137. package/dist/types/feed/identifier.d.ts +2 -4
  138. package/dist/types/feed/index.d.ts +14 -18
  139. package/dist/types/feed/retrievable.d.ts +3 -4
  140. package/dist/types/index.d.ts +28 -1
  141. package/dist/types/manifest/manifest.d.ts +106 -0
  142. package/dist/types/modules/bytes.d.ts +8 -5
  143. package/dist/types/modules/bzz.d.ts +8 -10
  144. package/dist/types/modules/chunk.d.ts +4 -3
  145. package/dist/types/modules/debug/balance.d.ts +3 -2
  146. package/dist/types/modules/debug/chequebook.d.ts +7 -6
  147. package/dist/types/modules/debug/connectivity.d.ts +5 -3
  148. package/dist/types/modules/debug/settlements.d.ts +2 -1
  149. package/dist/types/modules/debug/stake.d.ts +4 -2
  150. package/dist/types/modules/debug/stamps.d.ts +5 -4
  151. package/dist/types/modules/debug/status.d.ts +6 -25
  152. package/dist/types/modules/debug/transactions.d.ts +5 -4
  153. package/dist/types/modules/envelope.d.ts +3 -2
  154. package/dist/types/modules/feed.d.ts +20 -16
  155. package/dist/types/modules/grantee.d.ts +7 -6
  156. package/dist/types/modules/gsoc.d.ts +7 -0
  157. package/dist/types/modules/pinning.d.ts +2 -4
  158. package/dist/types/modules/pss.d.ts +4 -3
  159. package/dist/types/modules/soc.d.ts +3 -2
  160. package/dist/types/modules/stewardship.d.ts +4 -4
  161. package/dist/types/modules/tag.d.ts +2 -1
  162. package/dist/types/stamper/stamper.d.ts +15 -0
  163. package/dist/types/types/debug.d.ts +63 -115
  164. package/dist/types/types/index.d.ts +103 -204
  165. package/dist/types/utils/bytes.d.ts +16 -90
  166. package/dist/types/utils/chunk-size.d.ts +1 -0
  167. package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
  168. package/dist/types/utils/chunk-stream.d.ts +6 -0
  169. package/dist/types/utils/cid.d.ts +3 -2
  170. package/dist/types/utils/collection.browser.d.ts +2 -2
  171. package/dist/types/utils/collection.d.ts +2 -1
  172. package/dist/types/utils/collection.node.d.ts +0 -1
  173. package/dist/types/utils/constants.d.ts +4 -1
  174. package/dist/types/utils/duration.d.ts +17 -0
  175. package/dist/types/utils/error.d.ts +2 -2
  176. package/dist/types/utils/expose.d.ts +2 -7
  177. package/dist/types/utils/headers.d.ts +3 -4
  178. package/dist/types/utils/mime.d.ts +1 -0
  179. package/dist/types/utils/pss.d.ts +2 -2
  180. package/dist/types/utils/resource-locator.d.ts +6 -0
  181. package/dist/types/utils/size.d.ts +16 -0
  182. package/dist/types/utils/stamps.d.ts +27 -33
  183. package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
  184. package/dist/types/utils/tar-uploader.d.ts +3 -4
  185. package/dist/types/utils/tokens.d.ts +77 -0
  186. package/dist/types/utils/type.d.ts +20 -52
  187. package/dist/types/utils/typed-bytes.d.ts +68 -0
  188. package/dist/types/utils/upload-progress.d.ts +4 -0
  189. package/dist/types/utils/workaround.d.ts +2 -0
  190. package/package.json +11 -17
  191. package/dist/cjs/chunk/signer.js +0 -126
  192. package/dist/cjs/chunk/span.js +0 -25
  193. package/dist/cjs/feed/json.js +0 -28
  194. package/dist/cjs/feed/topic.js +0 -25
  195. package/dist/cjs/feed/type.js +0 -15
  196. package/dist/cjs/modules/debug/chunk.js +0 -21
  197. package/dist/cjs/modules/debug/tag.js +0 -19
  198. package/dist/cjs/utils/eth.js +0 -216
  199. package/dist/cjs/utils/hash.js +0 -21
  200. package/dist/cjs/utils/hex.js +0 -150
  201. package/dist/cjs/utils/reference.js +0 -36
  202. package/dist/index.browser.min.js.LICENSE.txt +0 -8
  203. package/dist/mjs/chunk/signer.js +0 -114
  204. package/dist/mjs/chunk/span.js +0 -21
  205. package/dist/mjs/feed/json.js +0 -26
  206. package/dist/mjs/feed/topic.js +0 -19
  207. package/dist/mjs/feed/type.js +0 -10
  208. package/dist/mjs/modules/debug/chunk.js +0 -17
  209. package/dist/mjs/modules/debug/tag.js +0 -15
  210. package/dist/mjs/utils/eth.js +0 -192
  211. package/dist/mjs/utils/hash.js +0 -16
  212. package/dist/mjs/utils/hex.js +0 -135
  213. package/dist/mjs/utils/reference.js +0 -29
  214. package/dist/types/chunk/signer.d.ts +0 -31
  215. package/dist/types/chunk/span.d.ts +0 -10
  216. package/dist/types/feed/json.d.ts +0 -4
  217. package/dist/types/feed/topic.d.ts +0 -3
  218. package/dist/types/feed/type.d.ts +0 -6
  219. package/dist/types/modules/debug/chunk.d.ts +0 -10
  220. package/dist/types/modules/debug/tag.d.ts +0 -8
  221. package/dist/types/utils/eth.d.ts +0 -67
  222. package/dist/types/utils/hash.d.ts +0 -9
  223. package/dist/types/utils/hex.d.ts +0 -86
  224. package/dist/types/utils/reference.d.ts +0 -2
@@ -1,18 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bmtHash = void 0;
7
- // For ESM compatibility
8
- const js_sha3_1 = __importDefault(require("js-sha3"));
9
- const { keccak256 } = js_sha3_1.default;
3
+ exports.calculateChunkAddress = void 0;
4
+ const cafe_utility_1 = require("cafe-utility");
10
5
  const error_1 = require("../utils/error");
11
- const hash_1 = require("../utils/hash");
6
+ const typed_bytes_1 = require("../utils/typed-bytes");
12
7
  const MAX_CHUNK_PAYLOAD_SIZE = 4096;
13
8
  const SEGMENT_SIZE = 32;
14
- const SEGMENT_PAIR_SIZE = 2 * SEGMENT_SIZE;
15
- const HASH_SIZE = 32;
16
9
  /**
17
10
  * Calculate a Binary Merkle Tree hash for a chunk
18
11
  *
@@ -27,29 +20,19 @@ const HASH_SIZE = 32;
27
20
  *
28
21
  * @returns the keccak256 hash in a byte array
29
22
  */
30
- function bmtHash(chunkContent) {
31
- const span = chunkContent.slice(0, 8);
32
- const payload = chunkContent.slice(8);
33
- const rootHash = bmtRootHash(payload);
34
- const chunkHashInput = new Uint8Array([...span, ...rootHash]);
35
- const chunkHash = (0, hash_1.keccak256Hash)(chunkHashInput);
36
- return chunkHash;
23
+ function calculateChunkAddress(chunkContent) {
24
+ const span = chunkContent.slice(0, typed_bytes_1.Span.LENGTH);
25
+ const payload = chunkContent.slice(typed_bytes_1.Span.LENGTH);
26
+ const rootHash = calculateBmtRootHash(payload);
27
+ const chunkHash = cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(span, rootHash));
28
+ return new typed_bytes_1.Reference(chunkHash);
37
29
  }
38
- exports.bmtHash = bmtHash;
39
- function bmtRootHash(payload) {
30
+ exports.calculateChunkAddress = calculateChunkAddress;
31
+ function calculateBmtRootHash(payload) {
40
32
  if (payload.length > MAX_CHUNK_PAYLOAD_SIZE) {
41
- throw new error_1.BeeArgumentError('invalid data length', payload);
33
+ throw new error_1.BeeArgumentError(`payload size ${payload.length} exceeds maximum chunk payload size ${MAX_CHUNK_PAYLOAD_SIZE}`, payload);
42
34
  }
43
- // create an input buffer padded with zeros
44
- let input = new Uint8Array([...payload, ...new Uint8Array(MAX_CHUNK_PAYLOAD_SIZE - payload.length)]);
45
- while (input.length !== HASH_SIZE) {
46
- const output = new Uint8Array(input.length / 2);
47
- // in each round we hash the segment pairs together
48
- for (let offset = 0; offset < input.length; offset += SEGMENT_PAIR_SIZE) {
49
- const hashNumbers = keccak256.array(input.slice(offset, offset + SEGMENT_PAIR_SIZE));
50
- output.set(hashNumbers, offset / 2);
51
- }
52
- input = output;
53
- }
54
- return input;
35
+ const input = new Uint8Array(MAX_CHUNK_PAYLOAD_SIZE);
36
+ input.set(payload);
37
+ return cafe_utility_1.Binary.log2Reduce(cafe_utility_1.Binary.partition(input, SEGMENT_SIZE), (a, b) => cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(a, b)));
55
38
  }
@@ -1,56 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertValidChunkData = exports.isValidChunkData = exports.makeContentAddressedChunk = exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
3
+ exports.asContentAddressedChunk = exports.makeContentAddressedChunk = exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const bytes_1 = require("../utils/bytes");
6
- const error_1 = require("../utils/error");
6
+ const typed_bytes_1 = require("../utils/typed-bytes");
7
7
  const bmt_1 = require("./bmt");
8
- const span_1 = require("./span");
9
8
  exports.MIN_PAYLOAD_SIZE = 1;
10
9
  exports.MAX_PAYLOAD_SIZE = 4096;
11
- const CAC_SPAN_OFFSET = 0;
12
- const CAC_PAYLOAD_OFFSET = CAC_SPAN_OFFSET + span_1.SPAN_SIZE;
10
+ const ENCODER = new TextEncoder();
13
11
  /**
14
12
  * Creates a content addressed chunk and verifies the payload size.
15
13
  *
16
14
  * @param payloadBytes the data to be stored in the chunk
17
15
  */
18
16
  function makeContentAddressedChunk(payloadBytes) {
19
- const span = (0, span_1.makeSpan)(payloadBytes.length);
20
- (0, bytes_1.assertFlexBytes)(payloadBytes, exports.MIN_PAYLOAD_SIZE, exports.MAX_PAYLOAD_SIZE);
21
- const data = cafe_utility_1.Binary.concatBytes(span, payloadBytes);
17
+ if (!(payloadBytes instanceof Uint8Array)) {
18
+ payloadBytes = ENCODER.encode(payloadBytes);
19
+ }
20
+ if (payloadBytes.length < exports.MIN_PAYLOAD_SIZE || payloadBytes.length > exports.MAX_PAYLOAD_SIZE) {
21
+ throw new RangeError(`payload size ${payloadBytes.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE}, ${exports.MAX_PAYLOAD_SIZE}]`);
22
+ }
23
+ const span = typed_bytes_1.Span.fromBigInt(BigInt(payloadBytes.length));
24
+ const data = cafe_utility_1.Binary.concatBytes(span.toUint8Array(), payloadBytes);
22
25
  return {
23
26
  data,
24
- span: () => span,
25
- payload: () => (0, bytes_1.flexBytesAtOffset)(data, CAC_PAYLOAD_OFFSET, exports.MIN_PAYLOAD_SIZE, exports.MAX_PAYLOAD_SIZE),
26
- address: () => (0, bmt_1.bmtHash)(data),
27
+ span,
28
+ payload: bytes_1.Bytes.fromSlice(data, typed_bytes_1.Span.LENGTH),
29
+ address: (0, bmt_1.calculateChunkAddress)(data),
27
30
  };
28
31
  }
29
32
  exports.makeContentAddressedChunk = makeContentAddressedChunk;
30
- /**
31
- * Type guard for valid content addressed chunk data
32
- *
33
- * @param data The chunk data
34
- * @param chunkAddress The address of the chunk
35
- */
36
- function isValidChunkData(data, chunkAddress) {
37
- if (!(data instanceof Uint8Array))
38
- return false;
39
- const address = (0, bmt_1.bmtHash)(data);
40
- return (0, bytes_1.bytesEqual)(address, chunkAddress);
41
- }
42
- exports.isValidChunkData = isValidChunkData;
43
- /**
44
- * Asserts if data are representing given address of its chunk.
45
- *
46
- * @param data The chunk data
47
- * @param chunkAddress The address of the chunk
48
- *
49
- * @returns a valid content addressed chunk or throws error
50
- */
51
- function assertValidChunkData(data, chunkAddress) {
52
- if (!isValidChunkData(data, chunkAddress)) {
53
- throw new error_1.BeeError('Address of content address chunk does not match given data!');
33
+ function asContentAddressedChunk(chunkBytes) {
34
+ if (chunkBytes.length < exports.MIN_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH || chunkBytes.length > exports.MAX_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH) {
35
+ throw new RangeError(`chunk size ${chunkBytes.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH}, ${typed_bytes_1.Span.LENGTH}]`);
54
36
  }
37
+ const span = typed_bytes_1.Span.fromSlice(chunkBytes, 0);
38
+ const data = cafe_utility_1.Binary.concatBytes(span.toUint8Array(), chunkBytes.slice(typed_bytes_1.Span.LENGTH));
39
+ return {
40
+ data,
41
+ span,
42
+ payload: bytes_1.Bytes.fromSlice(data, typed_bytes_1.Span.LENGTH),
43
+ address: (0, bmt_1.calculateChunkAddress)(data),
44
+ };
55
45
  }
56
- exports.assertValidChunkData = assertValidChunkData;
46
+ exports.asContentAddressedChunk = asContentAddressedChunk;
@@ -23,31 +23,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
26
+ exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkWithWrappedChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
27
27
  const cafe_utility_1 = require("cafe-utility");
28
28
  const chunkAPI = __importStar(require("../modules/chunk"));
29
29
  const socAPI = __importStar(require("../modules/soc"));
30
30
  const bytes_1 = require("../utils/bytes");
31
31
  const error_1 = require("../utils/error");
32
- const hash_1 = require("../utils/hash");
33
- const hex_1 = require("../utils/hex");
32
+ const typed_bytes_1 = require("../utils/typed-bytes");
34
33
  const bmt_1 = require("./bmt");
35
34
  const cac_1 = require("./cac");
36
- const signer_1 = require("./signer");
37
- const span_1 = require("./span");
38
- const IDENTIFIER_SIZE = 32;
39
- const SIGNATURE_SIZE = 65;
40
- const SOC_IDENTIFIER_OFFSET = 0;
41
- const SOC_SIGNATURE_OFFSET = SOC_IDENTIFIER_OFFSET + IDENTIFIER_SIZE;
42
- const SOC_SPAN_OFFSET = SOC_SIGNATURE_OFFSET + SIGNATURE_SIZE;
43
- const SOC_PAYLOAD_OFFSET = SOC_SPAN_OFFSET + span_1.SPAN_SIZE;
35
+ const SOC_SIGNATURE_OFFSET = typed_bytes_1.Identifier.LENGTH;
36
+ const SOC_SPAN_OFFSET = SOC_SIGNATURE_OFFSET + typed_bytes_1.Signature.LENGTH;
37
+ const SOC_PAYLOAD_OFFSET = SOC_SPAN_OFFSET + typed_bytes_1.Span.LENGTH;
44
38
  function recoverChunkOwner(data) {
45
39
  const cacData = data.slice(SOC_SPAN_OFFSET);
46
- const chunkAddress = (0, bmt_1.bmtHash)(cacData);
47
- const signature = (0, bytes_1.bytesAtOffset)(data, SOC_SIGNATURE_OFFSET, SIGNATURE_SIZE);
48
- const identifier = (0, bytes_1.bytesAtOffset)(data, SOC_IDENTIFIER_OFFSET, IDENTIFIER_SIZE);
49
- const digest = (0, hash_1.keccak256Hash)(identifier, chunkAddress);
50
- const ownerAddress = (0, signer_1.recoverAddress)(signature, digest);
40
+ const chunkAddress = (0, bmt_1.calculateChunkAddress)(cacData);
41
+ const signature = typed_bytes_1.Signature.fromSlice(data, SOC_SIGNATURE_OFFSET);
42
+ const identifier = bytes_1.Bytes.fromSlice(data, 0, typed_bytes_1.Identifier.LENGTH);
43
+ const digest = cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), chunkAddress.toUint8Array());
44
+ const ownerAddress = signature.recoverPublicKey(digest).address();
51
45
  return ownerAddress;
52
46
  }
53
47
  /**
@@ -59,28 +53,30 @@ function recoverChunkOwner(data) {
59
53
  * @returns a single owner chunk or throws error
60
54
  */
61
55
  function makeSingleOwnerChunkFromData(data, address) {
56
+ data = data instanceof bytes_1.Bytes ? data.toUint8Array() : data;
57
+ address = new typed_bytes_1.Reference(address);
62
58
  const ownerAddress = recoverChunkOwner(data);
63
- const identifier = (0, bytes_1.bytesAtOffset)(data, SOC_IDENTIFIER_OFFSET, IDENTIFIER_SIZE);
64
- const socAddress = (0, hash_1.keccak256Hash)(identifier, ownerAddress);
65
- if (!(0, bytes_1.bytesEqual)(address, socAddress)) {
59
+ const identifier = bytes_1.Bytes.fromSlice(data, 0, typed_bytes_1.Identifier.LENGTH);
60
+ const socAddress = new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), ownerAddress.toUint8Array())));
61
+ if (!cafe_utility_1.Binary.equals(address.toUint8Array(), socAddress.toUint8Array())) {
66
62
  throw new error_1.BeeError('SOC Data does not match given address!');
67
63
  }
68
- const signature = () => (0, bytes_1.bytesAtOffset)(data, SOC_SIGNATURE_OFFSET, SIGNATURE_SIZE);
69
- const span = () => (0, bytes_1.bytesAtOffset)(data, SOC_SPAN_OFFSET, span_1.SPAN_SIZE);
70
- const payload = () => (0, bytes_1.flexBytesAtOffset)(data, SOC_PAYLOAD_OFFSET, cac_1.MIN_PAYLOAD_SIZE, cac_1.MAX_PAYLOAD_SIZE);
64
+ const signature = typed_bytes_1.Signature.fromSlice(data, SOC_SIGNATURE_OFFSET);
65
+ const span = typed_bytes_1.Span.fromSlice(data, SOC_SPAN_OFFSET);
66
+ const payload = bytes_1.Bytes.fromSlice(data, SOC_PAYLOAD_OFFSET);
71
67
  return {
72
68
  data,
73
- identifier: () => identifier,
69
+ identifier,
74
70
  signature,
75
71
  span,
76
72
  payload,
77
- address: () => socAddress,
78
- owner: () => ownerAddress,
73
+ address: socAddress,
74
+ owner: ownerAddress,
79
75
  };
80
76
  }
81
77
  exports.makeSingleOwnerChunkFromData = makeSingleOwnerChunkFromData;
82
78
  function makeSOCAddress(identifier, address) {
83
- return (0, hash_1.keccak256Hash)(identifier, address);
79
+ return new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), address.toUint8Array())));
84
80
  }
85
81
  exports.makeSOCAddress = makeSOCAddress;
86
82
  /**
@@ -88,23 +84,24 @@ exports.makeSOCAddress = makeSOCAddress;
88
84
  *
89
85
  * @param chunk A chunk object used for the span and payload
90
86
  * @param identifier The identifier of the chunk
91
- * @param signer The singer interface for signing the chunk
87
+ * @param signer The signer interface for signing the chunk
92
88
  */
93
- async function makeSingleOwnerChunk(chunk, identifier, signer) {
94
- const chunkAddress = chunk.address();
95
- (0, cac_1.assertValidChunkData)(chunk.data, chunkAddress);
96
- const digest = (0, hash_1.keccak256Hash)(identifier, chunkAddress);
97
- const signature = await (0, signer_1.sign)(signer, digest);
98
- const data = cafe_utility_1.Binary.concatBytes(identifier, signature, chunk.span(), chunk.payload());
99
- const address = makeSOCAddress(identifier, signer.address);
89
+ function makeSingleOwnerChunk(chunk, identifier, signer) {
90
+ identifier = new typed_bytes_1.Identifier(identifier);
91
+ signer = new typed_bytes_1.PrivateKey(signer);
92
+ const address = makeSOCAddress(identifier, signer.publicKey().address());
93
+ const signature = signer.sign(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), chunk.address.toUint8Array()));
94
+ const data = cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), signature.toUint8Array(), chunk.data);
95
+ const span = typed_bytes_1.Span.fromSlice(chunk.data, 0);
96
+ const payload = bytes_1.Bytes.fromSlice(chunk.data, typed_bytes_1.Span.LENGTH);
100
97
  return {
101
98
  data,
102
- identifier: () => identifier,
103
- signature: () => signature,
104
- span: () => chunk.span(),
105
- payload: () => chunk.payload(),
106
- address: () => address,
107
- owner: () => signer.address,
99
+ identifier,
100
+ signature,
101
+ span,
102
+ payload,
103
+ address,
104
+ owner: signer.publicKey().address(),
108
105
  };
109
106
  }
110
107
  exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
@@ -115,43 +112,51 @@ exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
115
112
  *
116
113
  * @param requestOptions Options for making requests
117
114
  * @param chunk A chunk object
118
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
115
+ * @param stamp Postage BatchId that will be assigned to uploaded data
119
116
  * @param options Upload options
120
117
  */
121
118
  async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
122
- const owner = (0, hex_1.bytesToHex)(chunk.owner());
123
- const identifier = (0, hex_1.bytesToHex)(chunk.identifier());
124
- const signature = (0, hex_1.bytesToHex)(chunk.signature());
125
- const data = cafe_utility_1.Binary.concatBytes(chunk.span(), chunk.payload());
126
- return socAPI.upload(requestOptions, owner, identifier, signature, data, stamp, options);
119
+ const data = cafe_utility_1.Binary.concatBytes(chunk.span.toUint8Array(), chunk.payload.toUint8Array());
120
+ return socAPI.upload(requestOptions, chunk.owner, chunk.identifier, chunk.signature, data, stamp, options);
127
121
  }
128
122
  exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
129
123
  /**
130
124
  * Helper function to create and upload SOC.
131
125
  *
132
126
  * @param requestOptions Options for making requests
133
- * @param signer The singer interface for signing the chunk
127
+ * @param signer The signer interface for signing the chunk
134
128
  * @param postageBatchId
135
129
  * @param identifier The identifier of the chunk
136
130
  * @param data The chunk data
137
131
  * @param options
138
132
  */
139
133
  async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identifier, data, options) {
134
+ signer = new typed_bytes_1.PrivateKey(signer);
135
+ identifier = new typed_bytes_1.Identifier(identifier);
140
136
  const cac = (0, cac_1.makeContentAddressedChunk)(data);
141
- const soc = await makeSingleOwnerChunk(cac, identifier, signer);
137
+ const soc = makeSingleOwnerChunk(cac, identifier, signer);
142
138
  return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
143
139
  }
144
140
  exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
141
+ async function uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, stamp, identifier, rootChunk, options) {
142
+ signer = new typed_bytes_1.PrivateKey(signer);
143
+ identifier = new typed_bytes_1.Identifier(identifier);
144
+ const soc = makeSingleOwnerChunk((0, cac_1.asContentAddressedChunk)(rootChunk), identifier, signer);
145
+ return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
146
+ }
147
+ exports.uploadSingleOwnerChunkWithWrappedChunk = uploadSingleOwnerChunkWithWrappedChunk;
145
148
  /**
146
149
  * Helper function to download SOC.
147
150
  *
148
151
  * @param url The url of the Bee service
149
- * @param ownerAddress The singer interface for signing the chunk
152
+ * @param ownerAddress The signer interface for signing the chunk
150
153
  * @param identifier The identifier of the chunk
151
154
  */
152
155
  async function downloadSingleOwnerChunk(requestOptions, ownerAddress, identifier) {
156
+ identifier = new typed_bytes_1.Identifier(identifier);
157
+ ownerAddress = new typed_bytes_1.EthAddress(ownerAddress);
153
158
  const address = makeSOCAddress(identifier, ownerAddress);
154
- const data = await chunkAPI.download(requestOptions, (0, hex_1.bytesToHex)(address));
155
- return makeSingleOwnerChunkFromData(data, address);
159
+ const cac = await chunkAPI.download(requestOptions, address.toHex());
160
+ return makeSingleOwnerChunkFromData(cac, address);
156
161
  }
157
162
  exports.downloadSingleOwnerChunk = downloadSingleOwnerChunk;
@@ -2,34 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeFeedIdentifier = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
- const types_1 = require("../types");
6
- const hash_1 = require("../utils/hash");
7
- const hex_1 = require("../utils/hex");
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 = cafe_utility_1.Binary.numberToUint64BE(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
- }
5
+ const typed_bytes_1 = require("../utils/typed-bytes");
22
6
  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);
7
+ index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
8
+ return new typed_bytes_1.Identifier(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(topic.toUint8Array(), index.toUint8Array())));
34
9
  }
35
10
  exports.makeFeedIdentifier = makeFeedIdentifier;
@@ -23,94 +23,145 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeed = exports.findNextIndex = void 0;
26
+ exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdateAsCAC = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeedWithPayload = exports.updateFeedWithReference = exports.findNextIndex = void 0;
27
27
  const cafe_utility_1 = require("cafe-utility");
28
+ const cac_1 = require("../chunk/cac");
28
29
  const soc_1 = require("../chunk/soc");
30
+ const bytes = __importStar(require("../modules/bytes"));
29
31
  const chunkAPI = __importStar(require("../modules/chunk"));
30
32
  const feed_1 = require("../modules/feed");
31
- const types_1 = require("../types");
32
33
  const bytes_1 = require("../utils/bytes");
33
34
  const error_1 = require("../utils/error");
34
- const eth_1 = require("../utils/eth");
35
- const hash_1 = require("../utils/hash");
36
- const hex_1 = require("../utils/hex");
37
- const reference_1 = require("../utils/reference");
38
- const type_1 = require("../utils/type");
35
+ const resource_locator_1 = require("../utils/resource-locator");
36
+ const typed_bytes_1 = require("../utils/typed-bytes");
39
37
  const identifier_1 = require("./identifier");
40
38
  const TIMESTAMP_PAYLOAD_OFFSET = 0;
41
39
  const TIMESTAMP_PAYLOAD_SIZE = 8;
42
40
  const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
43
- async function findNextIndex(requestOptions, owner, topic, options) {
41
+ async function findNextIndex(requestOptions, owner, topic) {
44
42
  try {
45
- const feedUpdate = await (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic, options);
46
- return (0, hex_1.makeHexString)(feedUpdate.feedIndexNext, types_1.FEED_INDEX_HEX_LENGTH);
43
+ const feedUpdate = await (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic);
44
+ if (!feedUpdate.feedIndexNext) {
45
+ throw Error('Feed index next is not defined. This should happen when fetching an exact index.');
46
+ }
47
+ return feedUpdate.feedIndexNext;
47
48
  }
48
49
  catch (e) {
49
50
  if (e instanceof error_1.BeeResponseError) {
50
- return (0, hex_1.bytesToHex)((0, bytes_1.makeBytes)(8));
51
+ return typed_bytes_1.FeedIndex.fromBigInt(0n);
51
52
  }
52
53
  throw e;
53
54
  }
54
55
  }
55
56
  exports.findNextIndex = findNextIndex;
56
- async function updateFeed(requestOptions, signer, topic, reference, postageBatchId, options) {
57
- const ownerHex = (0, eth_1.makeHexEthAddress)(signer.address);
58
- const nextIndex = options?.index ?? (await findNextIndex(requestOptions, ownerHex, topic, options));
57
+ async function updateFeedWithReference(requestOptions, signer, topic, reference, postageBatchId, options) {
58
+ reference = new typed_bytes_1.Reference(reference);
59
+ const nextIndex = options?.index ?? (await findNextIndex(requestOptions, signer.publicKey().address(), topic));
59
60
  const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
60
61
  const at = options?.at ?? Date.now() / 1000.0;
61
- const timestamp = cafe_utility_1.Binary.numberToUint64BE(Math.floor(at));
62
- const payloadBytes = cafe_utility_1.Binary.concatBytes(timestamp, reference);
62
+ const timestamp = cafe_utility_1.Binary.numberToUint64(BigInt(Math.floor(at)), 'BE');
63
+ const payloadBytes = cafe_utility_1.Binary.concatBytes(timestamp, reference.toUint8Array());
63
64
  return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, payloadBytes, options);
64
65
  }
65
- exports.updateFeed = updateFeed;
66
+ exports.updateFeedWithReference = updateFeedWithReference;
67
+ async function updateFeedWithPayload(requestOptions, signer, topic, data, postageBatchId, options) {
68
+ const nextIndex = options?.index ?? (await findNextIndex(requestOptions, signer.publicKey().address(), topic));
69
+ const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
70
+ if (data.length > 4096) {
71
+ const uploadResult = await bytes.upload(requestOptions, data, postageBatchId, options);
72
+ const rootChunk = await chunkAPI.download(requestOptions, uploadResult.reference);
73
+ return (0, soc_1.uploadSingleOwnerChunkWithWrappedChunk)(requestOptions, signer, postageBatchId, identifier, rootChunk, options);
74
+ }
75
+ return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, cafe_utility_1.Types.isString(data) ? bytes_1.Bytes.fromUtf8(data).toUint8Array() : data, options);
76
+ }
77
+ exports.updateFeedWithPayload = updateFeedWithPayload;
66
78
  function getFeedUpdateChunkReference(owner, topic, index) {
67
79
  const identifier = (0, identifier_1.makeFeedIdentifier)(topic, index);
68
- return (0, hash_1.keccak256Hash)(identifier, owner);
80
+ return new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), owner.toUint8Array())));
69
81
  }
70
82
  exports.getFeedUpdateChunkReference = getFeedUpdateChunkReference;
71
- async function downloadFeedUpdate(requestOptions, owner, topic, index) {
83
+ async function downloadFeedUpdate(requestOptions, owner, topic, index, hasTimestamp = false) {
84
+ index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
72
85
  const address = getFeedUpdateChunkReference(owner, topic, index);
73
- const addressHex = (0, hex_1.bytesToHex)(address);
74
- const data = await chunkAPI.download(requestOptions, addressHex);
86
+ const data = await chunkAPI.download(requestOptions, address.toHex());
75
87
  const soc = (0, soc_1.makeSingleOwnerChunkFromData)(data, address);
76
- const payload = soc.payload();
77
- const timestampBytes = (0, bytes_1.bytesAtOffset)(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
78
- const timestamp = cafe_utility_1.Binary.uint64BEToNumber(timestampBytes);
79
- const reference = (0, reference_1.makeBytesReference)(payload, REFERENCE_PAYLOAD_OFFSET);
88
+ let timestamp = cafe_utility_1.Optional.empty();
89
+ if (hasTimestamp) {
90
+ const timestampBytes = bytes_1.Bytes.fromSlice(soc.payload.toUint8Array(), TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
91
+ timestamp = cafe_utility_1.Optional.of(Number(cafe_utility_1.Binary.uint64ToNumber(timestampBytes.toUint8Array(), 'BE')));
92
+ }
80
93
  return {
81
94
  timestamp,
82
- reference,
95
+ payload: new bytes_1.Bytes(soc.payload.offset(hasTimestamp ? REFERENCE_PAYLOAD_OFFSET : 0)),
83
96
  };
84
97
  }
85
98
  exports.downloadFeedUpdate = downloadFeedUpdate;
86
- function makeFeedReader(requestOptions, type, topic, owner) {
99
+ async function downloadFeedUpdateAsCAC(requestOptions, owner, topic, index) {
100
+ index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
101
+ const address = getFeedUpdateChunkReference(owner, topic, index);
102
+ const data = await chunkAPI.download(requestOptions, address);
103
+ return (0, cac_1.asContentAddressedChunk)(data.slice(typed_bytes_1.Identifier.LENGTH + typed_bytes_1.Signature.LENGTH));
104
+ }
105
+ exports.downloadFeedUpdateAsCAC = downloadFeedUpdateAsCAC;
106
+ function makeFeedReader(requestOptions, topic, owner) {
107
+ // TODO: remove after enough time has passed in deprecated version
108
+ const download = async (options) => {
109
+ if (options?.index === undefined) {
110
+ return (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic);
111
+ }
112
+ const update = await downloadFeedUpdate(requestOptions, owner, topic, options.index, options.hasTimestamp ?? true);
113
+ const feedIndex = typeof options.index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
114
+ return {
115
+ payload: update.payload,
116
+ feedIndex,
117
+ };
118
+ };
119
+ const downloadPayload = async (options) => {
120
+ if (options?.index === undefined) {
121
+ return (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic);
122
+ }
123
+ const cac = await downloadFeedUpdateAsCAC(requestOptions, owner, topic, options.index);
124
+ const payload = cac.span.toBigInt() <= 4096n
125
+ ? cac.payload
126
+ : await bytes.download(requestOptions, new resource_locator_1.ResourceLocator(cac.address));
127
+ const feedIndex = typeof options.index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
128
+ return {
129
+ payload,
130
+ feedIndex,
131
+ };
132
+ };
133
+ const downloadReference = async (options) => {
134
+ let index = options?.index;
135
+ if (index === undefined) {
136
+ index = (await (0, feed_1.probeFeed)(requestOptions, owner, topic)).feedIndex;
137
+ }
138
+ const payload = await download({ ...options, index: index });
139
+ return {
140
+ reference: new typed_bytes_1.Reference(payload.payload.toUint8Array()),
141
+ feedIndex: payload.feedIndex,
142
+ };
143
+ };
87
144
  return {
88
- type,
145
+ download,
146
+ downloadPayload,
147
+ downloadReference,
89
148
  owner,
90
149
  topic,
91
- async download(options) {
92
- if (!options?.index && options?.index !== 0) {
93
- return (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic);
94
- }
95
- const update = await downloadFeedUpdate(requestOptions, (0, hex_1.hexToBytes)(owner), topic, options.index);
96
- return {
97
- reference: (0, hex_1.bytesToHex)(update.reference),
98
- feedIndex: options.index,
99
- feedIndexNext: '',
100
- };
101
- },
102
150
  };
103
151
  }
104
152
  exports.makeFeedReader = makeFeedReader;
105
- function makeFeedWriter(requestOptions, type, topic, signer) {
153
+ function makeFeedWriter(requestOptions, topic, signer) {
106
154
  const upload = async (postageBatchId, reference, options) => {
107
- (0, type_1.assertAddress)(postageBatchId);
108
- const canonicalReference = (0, reference_1.makeBytesReference)(reference);
109
- return updateFeed(requestOptions, signer, topic, canonicalReference, postageBatchId, { ...options, type });
155
+ return updateFeedWithReference(requestOptions, signer, topic, reference, postageBatchId, options);
156
+ };
157
+ const uploadPayload = async (postageBatchId, data, options) => {
158
+ return updateFeedWithPayload(requestOptions, signer, topic, data, postageBatchId, options);
110
159
  };
111
160
  return {
112
- ...makeFeedReader(requestOptions, type, topic, (0, eth_1.makeHexEthAddress)(signer.address)),
161
+ ...makeFeedReader(requestOptions, topic, signer.publicKey().address()),
113
162
  upload,
163
+ uploadReference: upload,
164
+ uploadPayload,
114
165
  };
115
166
  }
116
167
  exports.makeFeedWriter = makeFeedWriter;
@@ -2,20 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.areAllSequentialFeedsUpdateRetrievable = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
- const hex_1 = require("../utils/hex");
5
+ const typed_bytes_1 = require("../utils/typed-bytes");
6
6
  const index_1 = require("./index");
7
- function makeNumericIndex(index) {
8
- if (index instanceof Uint8Array) {
9
- return cafe_utility_1.Binary.uint64BEToNumber(index);
10
- }
11
- if (typeof index === 'string') {
12
- return parseInt(index);
13
- }
14
- if (typeof index === 'number') {
15
- return index;
16
- }
17
- throw new TypeError('Unknown type of index!');
18
- }
19
7
  /**
20
8
  * Function that checks if a chunk is retrievable by actually downloading it.
21
9
  * The /stewardship/{reference} endpoint does not support verification of chunks, but only manifest's references.
@@ -24,13 +12,14 @@ function makeNumericIndex(index) {
24
12
  * @param ref
25
13
  * @param options
26
14
  */
27
- async function isChunkRetrievable(bee, ref, requestOptions) {
15
+ async function isChunkRetrievable(bee, reference, options, requestOptions) {
28
16
  try {
29
- await bee.downloadChunk(ref, requestOptions);
17
+ await bee.downloadChunk(reference, options, requestOptions);
30
18
  return true;
31
19
  }
32
20
  catch (e) {
33
- if (e?.status === 404 || e?.status === 500) {
21
+ const status = cafe_utility_1.Objects.getDeep(e, 'status');
22
+ if (status === 404 || status === 500) {
34
23
  return false;
35
24
  }
36
25
  throw e;
@@ -44,15 +33,15 @@ async function isChunkRetrievable(bee, ref, requestOptions) {
44
33
  * @param index
45
34
  */
46
35
  function getAllSequenceUpdateReferences(owner, topic, index) {
47
- const numIndex = makeNumericIndex(index);
48
- const updateReferences = new Array(numIndex + 1);
49
- for (let i = 0; i <= numIndex; i++) {
50
- updateReferences[i] = (0, hex_1.bytesToHex)((0, index_1.getFeedUpdateChunkReference)(owner, topic, i));
36
+ const count = index.toBigInt();
37
+ const updateReferences = [];
38
+ for (let i = 0n; i <= count; i++) {
39
+ updateReferences.push((0, index_1.getFeedUpdateChunkReference)(owner, topic, typed_bytes_1.FeedIndex.fromBigInt(i)));
51
40
  }
52
41
  return updateReferences;
53
42
  }
54
- async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, requestOptions) {
55
- const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (ref) => isChunkRetrievable(bee, ref, requestOptions));
43
+ async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options, requestOptions) {
44
+ const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (reference) => isChunkRetrievable(bee, reference, options, requestOptions));
56
45
  return (await Promise.all(chunkRetrievablePromises)).every(result => result);
57
46
  }
58
47
  exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;