@ethersphere/bee-js 5.1.1 → 5.1.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 (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -120,18 +111,16 @@ function makeSigner(signer) {
120
111
  return signer;
121
112
  }
122
113
  exports.makeSigner = makeSigner;
123
- function sign(signer, data) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const result = yield signer.sign((0, bytes_1.wrapBytesWithHelpers)(data));
126
- if (typeof result === 'string') {
127
- const hexString = (0, hex_1.makeHexString)(result, types_1.SIGNATURE_HEX_LENGTH);
128
- return (0, hex_1.hexToBytes)(hexString);
129
- }
130
- if (result instanceof Uint8Array) {
131
- (0, bytes_1.assertBytes)(result, types_1.SIGNATURE_BYTES_LENGTH);
132
- return result;
133
- }
134
- throw new TypeError('Invalid output of sign function!');
135
- });
114
+ async function sign(signer, data) {
115
+ const result = await signer.sign((0, bytes_1.wrapBytesWithHelpers)(data));
116
+ if (typeof result === 'string') {
117
+ const hexString = (0, hex_1.makeHexString)(result, types_1.SIGNATURE_HEX_LENGTH);
118
+ return (0, hex_1.hexToBytes)(hexString);
119
+ }
120
+ if (result instanceof Uint8Array) {
121
+ (0, bytes_1.assertBytes)(result, types_1.SIGNATURE_BYTES_LENGTH);
122
+ return result;
123
+ }
124
+ throw new TypeError('Invalid output of sign function!');
136
125
  }
137
126
  exports.sign = sign;
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
36
27
  const bytes_1 = require("../utils/bytes");
@@ -100,24 +91,22 @@ exports.makeSOCAddress = makeSOCAddress;
100
91
  * @param identifier The identifier of the chunk
101
92
  * @param signer The singer interface for signing the chunk
102
93
  */
103
- function makeSingleOwnerChunk(chunk, identifier, signer) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const chunkAddress = chunk.address();
106
- (0, cac_1.assertValidChunkData)(chunk.data, chunkAddress);
107
- const digest = (0, hash_1.keccak256Hash)(identifier, chunkAddress);
108
- const signature = yield (0, signer_1.sign)(signer, digest);
109
- const data = (0, serialize_1.serializeBytes)(identifier, signature, chunk.span(), chunk.payload());
110
- const address = makeSOCAddress(identifier, signer.address);
111
- return {
112
- data,
113
- identifier: () => identifier,
114
- signature: () => signature,
115
- span: () => chunk.span(),
116
- payload: () => chunk.payload(),
117
- address: () => address,
118
- owner: () => signer.address,
119
- };
120
- });
94
+ async function makeSingleOwnerChunk(chunk, identifier, signer) {
95
+ const chunkAddress = chunk.address();
96
+ (0, cac_1.assertValidChunkData)(chunk.data, chunkAddress);
97
+ const digest = (0, hash_1.keccak256Hash)(identifier, chunkAddress);
98
+ const signature = await (0, signer_1.sign)(signer, digest);
99
+ const data = (0, serialize_1.serializeBytes)(identifier, signature, chunk.span(), chunk.payload());
100
+ const address = makeSOCAddress(identifier, signer.address);
101
+ return {
102
+ data,
103
+ identifier: () => identifier,
104
+ signature: () => signature,
105
+ span: () => chunk.span(),
106
+ payload: () => chunk.payload(),
107
+ address: () => address,
108
+ owner: () => signer.address,
109
+ };
121
110
  }
122
111
  exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
123
112
  /**
@@ -125,38 +114,34 @@ exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
125
114
  *
126
115
  * It uses the Chunk API and calculates the address before uploading.
127
116
  *
128
- * @param ky Ky instance
117
+ * @param kyOptions Ky Options for making requests
129
118
  * @param chunk A chunk object
130
119
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
131
120
  * @param options Upload options
132
121
  */
133
- function uploadSingleOwnerChunk(ky, chunk, postageBatchId, options) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- const owner = (0, hex_1.bytesToHex)(chunk.owner());
136
- const identifier = (0, hex_1.bytesToHex)(chunk.identifier());
137
- const signature = (0, hex_1.bytesToHex)(chunk.signature());
138
- const data = (0, serialize_1.serializeBytes)(chunk.span(), chunk.payload());
139
- return socAPI.upload(ky, owner, identifier, signature, data, postageBatchId, options);
140
- });
122
+ async function uploadSingleOwnerChunk(kyOptions, chunk, postageBatchId, options) {
123
+ const owner = (0, hex_1.bytesToHex)(chunk.owner());
124
+ const identifier = (0, hex_1.bytesToHex)(chunk.identifier());
125
+ const signature = (0, hex_1.bytesToHex)(chunk.signature());
126
+ const data = (0, serialize_1.serializeBytes)(chunk.span(), chunk.payload());
127
+ return socAPI.upload(kyOptions, owner, identifier, signature, data, postageBatchId, options);
141
128
  }
142
129
  exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
143
130
  /**
144
131
  * Helper function to create and upload SOC.
145
132
  *
146
- * @param ky Ky instance
133
+ * @param kyOptions Ky Options for making requests
147
134
  * @param signer The singer interface for signing the chunk
148
135
  * @param postageBatchId
149
136
  * @param identifier The identifier of the chunk
150
137
  * @param data The chunk data
151
138
  * @param options
152
139
  */
153
- function uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, data, options) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- (0, type_1.assertAddress)(postageBatchId);
156
- const cac = (0, cac_1.makeContentAddressedChunk)(data);
157
- const soc = yield makeSingleOwnerChunk(cac, identifier, signer);
158
- return uploadSingleOwnerChunk(ky, soc, postageBatchId, options);
159
- });
140
+ async function uploadSingleOwnerChunkData(kyOptions, signer, postageBatchId, identifier, data, options) {
141
+ (0, type_1.assertAddress)(postageBatchId);
142
+ const cac = (0, cac_1.makeContentAddressedChunk)(data);
143
+ const soc = await makeSingleOwnerChunk(cac, identifier, signer);
144
+ return uploadSingleOwnerChunk(kyOptions, soc, postageBatchId, options);
160
145
  }
161
146
  exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
162
147
  /**
@@ -166,11 +151,9 @@ exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
166
151
  * @param ownerAddress The singer interface for signing the chunk
167
152
  * @param identifier The identifier of the chunk
168
153
  */
169
- function downloadSingleOwnerChunk(ky, ownerAddress, identifier) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- const address = makeSOCAddress(identifier, ownerAddress);
172
- const data = yield chunkAPI.download(ky, (0, hex_1.bytesToHex)(address));
173
- return makeSingleOwnerChunkFromData(data, address);
174
- });
154
+ async function downloadSingleOwnerChunk(kyOptions, ownerAddress, identifier) {
155
+ const address = makeSOCAddress(identifier, ownerAddress);
156
+ const data = await chunkAPI.download(kyOptions, (0, hex_1.bytesToHex)(address));
157
+ return makeSingleOwnerChunkFromData(data, address);
175
158
  }
176
159
  exports.downloadSingleOwnerChunk = downloadSingleOwnerChunk;
@@ -4,7 +4,7 @@ exports.makeSpan = exports.SPAN_SIZE = void 0;
4
4
  const error_1 = require("../utils/error");
5
5
  exports.SPAN_SIZE = 8;
6
6
  // we limit the maximum span size in 32 bits to avoid BigInt compatibility issues
7
- const MAX_SPAN_LENGTH = Math.pow(2, 32) - 1;
7
+ const MAX_SPAN_LENGTH = 2 ** 32 - 1;
8
8
  /**
9
9
  * Create a span for storing the length of the chunk
10
10
  *
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeed = exports.findNextIndex = void 0;
36
27
  const hash_1 = require("../utils/hash");
@@ -50,32 +41,27 @@ const reference_1 = require("../utils/reference");
50
41
  const TIMESTAMP_PAYLOAD_OFFSET = 0;
51
42
  const TIMESTAMP_PAYLOAD_SIZE = 8;
52
43
  const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
53
- function findNextIndex(ky, owner, topic, options) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- try {
56
- const feedUpdate = yield (0, feed_1.fetchLatestFeedUpdate)(ky, owner, topic, options);
57
- return (0, hex_1.makeHexString)(feedUpdate.feedIndexNext, types_1.FEED_INDEX_HEX_LENGTH);
58
- }
59
- catch (e) {
60
- if (e instanceof error_1.BeeResponseError && e.status === 404) {
61
- return (0, hex_1.bytesToHex)((0, bytes_1.makeBytes)(8));
62
- }
63
- throw e;
44
+ async function findNextIndex(kyOptions, owner, topic, options) {
45
+ try {
46
+ const feedUpdate = await (0, feed_1.fetchLatestFeedUpdate)(kyOptions, owner, topic, options);
47
+ return (0, hex_1.makeHexString)(feedUpdate.feedIndexNext, types_1.FEED_INDEX_HEX_LENGTH);
48
+ }
49
+ catch (e) {
50
+ if (e instanceof error_1.BeeResponseError && e.status === 404) {
51
+ return (0, hex_1.bytesToHex)((0, bytes_1.makeBytes)(8));
64
52
  }
65
- });
53
+ throw e;
54
+ }
66
55
  }
67
56
  exports.findNextIndex = findNextIndex;
68
- function updateFeed(ky, signer, topic, reference, postageBatchId, options, index = 'latest') {
69
- var _a;
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const ownerHex = (0, eth_1.makeHexEthAddress)(signer.address);
72
- const nextIndex = index === 'latest' ? yield findNextIndex(ky, ownerHex, topic, options) : index;
73
- const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
74
- const at = (_a = options === null || options === void 0 ? void 0 : options.at) !== null && _a !== void 0 ? _a : Date.now() / 1000.0;
75
- const timestamp = (0, uint64_1.writeUint64BigEndian)(at);
76
- const payloadBytes = (0, serialize_1.serializeBytes)(timestamp, reference);
77
- return (0, soc_1.uploadSingleOwnerChunkData)(ky, signer, postageBatchId, identifier, payloadBytes, options);
78
- });
57
+ async function updateFeed(kyOptions, signer, topic, reference, postageBatchId, options, index = 'latest') {
58
+ const ownerHex = (0, eth_1.makeHexEthAddress)(signer.address);
59
+ const nextIndex = index === 'latest' ? await findNextIndex(kyOptions, ownerHex, topic, options) : index;
60
+ const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
61
+ const at = options?.at ?? Date.now() / 1000.0;
62
+ const timestamp = (0, uint64_1.writeUint64BigEndian)(at);
63
+ const payloadBytes = (0, serialize_1.serializeBytes)(timestamp, reference);
64
+ return (0, soc_1.uploadSingleOwnerChunkData)(kyOptions, signer, postageBatchId, identifier, payloadBytes, options);
79
65
  }
80
66
  exports.updateFeed = updateFeed;
81
67
  function getFeedUpdateChunkReference(owner, topic, index) {
@@ -83,50 +69,49 @@ function getFeedUpdateChunkReference(owner, topic, index) {
83
69
  return (0, hash_1.keccak256Hash)(identifier, owner);
84
70
  }
85
71
  exports.getFeedUpdateChunkReference = getFeedUpdateChunkReference;
86
- function downloadFeedUpdate(ky, owner, topic, index) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const address = getFeedUpdateChunkReference(owner, topic, index);
89
- const addressHex = (0, hex_1.bytesToHex)(address);
90
- const data = yield chunkAPI.download(ky, addressHex);
91
- const soc = (0, soc_1.makeSingleOwnerChunkFromData)(data, address);
92
- const payload = soc.payload();
93
- const timestampBytes = (0, bytes_1.bytesAtOffset)(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
94
- const timestamp = (0, uint64_1.readUint64BigEndian)(timestampBytes);
95
- const reference = (0, reference_1.makeBytesReference)(payload, REFERENCE_PAYLOAD_OFFSET);
96
- return {
97
- timestamp,
98
- reference,
99
- };
100
- });
72
+ async function downloadFeedUpdate(kyOptions, owner, topic, index) {
73
+ const address = getFeedUpdateChunkReference(owner, topic, index);
74
+ const addressHex = (0, hex_1.bytesToHex)(address);
75
+ const data = await chunkAPI.download(kyOptions, addressHex);
76
+ const soc = (0, soc_1.makeSingleOwnerChunkFromData)(data, address);
77
+ const payload = soc.payload();
78
+ const timestampBytes = (0, bytes_1.bytesAtOffset)(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
79
+ const timestamp = (0, uint64_1.readUint64BigEndian)(timestampBytes);
80
+ const reference = (0, reference_1.makeBytesReference)(payload, REFERENCE_PAYLOAD_OFFSET);
81
+ return {
82
+ timestamp,
83
+ reference,
84
+ };
101
85
  }
102
86
  exports.downloadFeedUpdate = downloadFeedUpdate;
103
- function makeFeedReader(ky, type, topic, owner) {
87
+ function makeFeedReader(kyOptions, type, topic, owner) {
104
88
  return {
105
89
  type,
106
90
  owner,
107
91
  topic,
108
- download(options) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- if (!(options === null || options === void 0 ? void 0 : options.index)) {
111
- return (0, feed_1.fetchLatestFeedUpdate)(ky, owner, topic, Object.assign(Object.assign({}, options), { type }));
112
- }
113
- const update = yield downloadFeedUpdate(ky, (0, hex_1.hexToBytes)(owner), topic, options.index);
114
- return {
115
- reference: (0, hex_1.bytesToHex)(update.reference),
116
- feedIndex: options.index,
117
- feedIndexNext: '',
118
- };
119
- });
92
+ async download(options) {
93
+ if (!options?.index) {
94
+ return (0, feed_1.fetchLatestFeedUpdate)(kyOptions, owner, topic, { ...options, type });
95
+ }
96
+ const update = await downloadFeedUpdate(kyOptions, (0, hex_1.hexToBytes)(owner), topic, options.index);
97
+ return {
98
+ reference: (0, hex_1.bytesToHex)(update.reference),
99
+ feedIndex: options.index,
100
+ feedIndexNext: '',
101
+ };
120
102
  },
121
103
  };
122
104
  }
123
105
  exports.makeFeedReader = makeFeedReader;
124
- function makeFeedWriter(ky, type, topic, signer) {
125
- const upload = (postageBatchId, reference, options) => __awaiter(this, void 0, void 0, function* () {
106
+ function makeFeedWriter(kyOptions, type, topic, signer) {
107
+ const upload = async (postageBatchId, reference, options) => {
126
108
  (0, type_1.assertAddress)(postageBatchId);
127
109
  const canonicalReference = (0, reference_1.makeBytesReference)(reference);
128
- return updateFeed(ky, signer, topic, canonicalReference, postageBatchId, Object.assign(Object.assign({}, options), { type }));
129
- });
130
- return Object.assign(Object.assign({}, makeFeedReader(ky, type, topic, (0, eth_1.makeHexEthAddress)(signer.address))), { upload });
110
+ return updateFeed(kyOptions, signer, topic, canonicalReference, postageBatchId, { ...options, type });
111
+ };
112
+ return {
113
+ ...makeFeedReader(kyOptions, type, topic, (0, eth_1.makeHexEthAddress)(signer.address)),
114
+ upload,
115
+ };
131
116
  }
132
117
  exports.makeFeedWriter = makeFeedWriter;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.setJsonData = exports.getJsonData = void 0;
13
4
  const type_1 = require("../utils/type");
@@ -23,19 +14,15 @@ function serializeJson(data) {
23
14
  throw e;
24
15
  }
25
16
  }
26
- function getJsonData(bee, reader) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const feedUpdate = yield reader.download();
29
- const retrievedData = yield bee.downloadData(feedUpdate.reference);
30
- return retrievedData.json();
31
- });
17
+ async function getJsonData(bee, reader) {
18
+ const feedUpdate = await reader.download();
19
+ const retrievedData = await bee.downloadData(feedUpdate.reference);
20
+ return retrievedData.json();
32
21
  }
33
22
  exports.getJsonData = getJsonData;
34
- function setJsonData(bee, writer, postageBatchId, data, options) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const serializedData = serializeJson(data);
37
- const { reference } = yield bee.uploadData(postageBatchId, serializedData, options);
38
- return writer.upload(postageBatchId, reference);
39
- });
23
+ async function setJsonData(bee, writer, postageBatchId, data, options) {
24
+ const serializedData = serializeJson(data);
25
+ const { reference } = await bee.uploadData(postageBatchId, serializedData, options);
26
+ return writer.upload(postageBatchId, reference);
40
27
  }
41
28
  exports.setJsonData = setJsonData;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.areAllSequentialFeedsUpdateRetrievable = void 0;
13
4
  const index_1 = require("./index");
@@ -33,20 +24,18 @@ function makeNumericIndex(index) {
33
24
  * @param ref
34
25
  * @param options
35
26
  */
36
- function isChunkRetrievable(bee, ref, options) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- try {
39
- yield bee.downloadChunk(ref, options);
40
- return true;
41
- }
42
- catch (e) {
43
- const err = e;
44
- if (err.status === 404) {
45
- return false;
46
- }
47
- throw e;
27
+ async function isChunkRetrievable(bee, ref, options) {
28
+ try {
29
+ await bee.downloadChunk(ref, options);
30
+ return true;
31
+ }
32
+ catch (e) {
33
+ const err = e;
34
+ if (err.status === 404) {
35
+ return false;
48
36
  }
49
- });
37
+ throw e;
38
+ }
50
39
  }
51
40
  /**
52
41
  * Creates array of references for all sequence updates chunk up to the given index.
@@ -63,10 +52,8 @@ function getAllSequenceUpdateReferences(owner, topic, index) {
63
52
  }
64
53
  return updateReferences;
65
54
  }
66
- function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map((ref) => __awaiter(this, void 0, void 0, function* () { return isChunkRetrievable(bee, ref, options); }));
69
- return (yield Promise.all(chunkRetrievablePromises)).every(result => result);
70
- });
55
+ async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
56
+ const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (ref) => isChunkRetrievable(bee, ref, options));
57
+ return (await Promise.all(chunkRetrievablePromises)).every(result => result);
71
58
  }
72
59
  exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.downloadReadable = exports.download = exports.upload = void 0;
13
4
  const data_1 = require("../utils/data");
@@ -19,25 +10,26 @@ const endpoint = 'bytes';
19
10
  /**
20
11
  * Upload data to a Bee node
21
12
  *
22
- * @param ky Ky instance
13
+ * @param kyOptions Ky Options for making requests
23
14
  * @param data Data to be uploaded
24
15
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
25
16
  * @param options Additional options like tag, encryption, pinning
26
17
  */
27
- function upload(ky, data, postageBatchId, options) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const response = yield (0, http_1.http)(ky, {
30
- path: endpoint,
31
- method: 'post',
32
- responseType: 'json',
33
- body: yield (0, data_1.prepareData)(data),
34
- headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
35
- });
36
- return {
37
- reference: response.data.reference,
38
- tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
39
- };
18
+ async function upload(kyOptions, data, postageBatchId, options) {
19
+ const response = await (0, http_1.http)(kyOptions, {
20
+ path: endpoint,
21
+ method: 'post',
22
+ responseType: 'json',
23
+ body: await (0, data_1.prepareData)(data),
24
+ headers: {
25
+ 'content-type': 'application/octet-stream',
26
+ ...(0, headers_1.extractUploadHeaders)(postageBatchId, options),
27
+ },
40
28
  });
29
+ return {
30
+ reference: response.parsedData.reference,
31
+ tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
32
+ };
41
33
  }
42
34
  exports.upload = upload;
43
35
  /**
@@ -46,14 +38,12 @@ exports.upload = upload;
46
38
  * @param ky
47
39
  * @param hash Bee content reference
48
40
  */
49
- function download(ky, hash) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const response = yield (0, http_1.http)(ky, {
52
- responseType: 'arraybuffer',
53
- path: `${endpoint}/${hash}`,
54
- });
55
- return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
41
+ async function download(kyOptions, hash) {
42
+ const response = await (0, http_1.http)(kyOptions, {
43
+ responseType: 'arraybuffer',
44
+ path: `${endpoint}/${hash}`,
56
45
  });
46
+ return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.parsedData));
57
47
  }
58
48
  exports.download = download;
59
49
  /**
@@ -62,13 +52,11 @@ exports.download = download;
62
52
  * @param ky
63
53
  * @param hash Bee content reference
64
54
  */
65
- function downloadReadable(ky, hash) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const response = yield (0, http_1.http)(ky, {
68
- responseType: 'stream',
69
- path: `${endpoint}/${hash}`,
70
- });
71
- return response.data;
55
+ async function downloadReadable(kyOptions, hash) {
56
+ const response = await (0, http_1.http)(kyOptions, {
57
+ responseType: 'stream',
58
+ path: `${endpoint}/${hash}`,
72
59
  });
60
+ return response.parsedData;
73
61
  }
74
62
  exports.downloadReadable = downloadReadable;