@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
@@ -0,0 +1,72 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.areAllSequentialFeedsUpdateRetrievable = void 0;
13
+ const index_1 = require("./index");
14
+ const uint64_1 = require("../utils/uint64");
15
+ const hex_1 = require("../utils/hex");
16
+ function makeNumericIndex(index) {
17
+ if (index instanceof Uint8Array) {
18
+ return (0, uint64_1.readUint64BigEndian)(index);
19
+ }
20
+ if (typeof index === 'string') {
21
+ return parseInt(index);
22
+ }
23
+ if (typeof index === 'number') {
24
+ return index;
25
+ }
26
+ throw new TypeError('Unknown type of index!');
27
+ }
28
+ /**
29
+ * Function that checks if a chunk is retrievable by actually downloading it.
30
+ * The /stewardship/{reference} endpoint does not support verification of chunks, but only manifest's references.
31
+ *
32
+ * @param bee
33
+ * @param ref
34
+ * @param options
35
+ */
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;
48
+ }
49
+ });
50
+ }
51
+ /**
52
+ * Creates array of references for all sequence updates chunk up to the given index.
53
+ *
54
+ * @param owner
55
+ * @param topic
56
+ * @param index
57
+ */
58
+ function getAllSequenceUpdateReferences(owner, topic, index) {
59
+ const numIndex = makeNumericIndex(index);
60
+ const updateReferences = new Array(numIndex + 1);
61
+ for (let i = 0; i <= numIndex; i++) {
62
+ updateReferences[i] = (0, hex_1.bytesToHex)((0, index_1.getFeedUpdateChunkReference)(owner, topic, i));
63
+ }
64
+ return updateReferences;
65
+ }
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
+ });
71
+ }
72
+ exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,9 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getChainState = exports.getReserveState = void 0;
12
+ exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
13
13
  const http_1 = require("../../utils/http");
14
14
  const RESERVE_STATE_ENDPOINT = 'reservestate';
15
+ const WALLET_ENDPOINT = 'wallet';
15
16
  const CHAIN_STATE_ENDPOINT = 'chainstate';
16
17
  /**
17
18
  * Get state of reserve
@@ -45,3 +46,19 @@ function getChainState(ky) {
45
46
  });
46
47
  }
47
48
  exports.getChainState = getChainState;
49
+ /**
50
+ * Get wallet balances for xDai and BZZ of the node
51
+ *
52
+ * @param ky Ky debug instance
53
+ */
54
+ function getWalletBalance(ky) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const response = yield (0, http_1.http)(ky, {
57
+ method: 'get',
58
+ path: `${WALLET_ENDPOINT}`,
59
+ responseType: 'json',
60
+ });
61
+ return response.data;
62
+ });
63
+ }
64
+ exports.getWalletBalance = getWalletBalance;
@@ -17,9 +17,9 @@ const http_1 = require("../../utils/http");
17
17
  const major_js_1 = __importDefault(require("semver/functions/major.js"));
18
18
  // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
19
19
  // so if you are changing anything about them change the `update_bee` action accordingly!
20
- exports.SUPPORTED_BEE_VERSION_EXACT = '1.5.1-d0a77598';
21
- exports.SUPPORTED_API_VERSION = '3.0.0';
22
- exports.SUPPORTED_DEBUG_API_VERSION = '2.0.0';
20
+ exports.SUPPORTED_BEE_VERSION_EXACT = '1.6.0-6ceadd35';
21
+ exports.SUPPORTED_API_VERSION = '3.0.1';
22
+ exports.SUPPORTED_DEBUG_API_VERSION = '2.0.1';
23
23
  exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.substring(0, exports.SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
24
24
  const NODE_INFO_URL = 'node';
25
25
  const HEALTH_URL = 'health';
File without changes
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fetchFeedUpdate = exports.createFeedManifest = void 0;
12
+ exports.fetchLatestFeedUpdate = exports.createFeedManifest = void 0;
13
13
  const http_1 = require("../utils/http");
14
14
  const headers_1 = require("../utils/headers");
15
15
  const error_1 = require("../utils/error");
@@ -63,7 +63,7 @@ function readFeedUpdateHeaders(headers) {
63
63
  * @param topic Topic in hex
64
64
  * @param options Additional options, like index, at, type
65
65
  */
66
- function fetchFeedUpdate(ky, owner, topic, options) {
66
+ function fetchLatestFeedUpdate(ky, owner, topic, options) {
67
67
  return __awaiter(this, void 0, void 0, function* () {
68
68
  const response = yield (0, http_1.http)(ky, {
69
69
  responseType: 'json',
@@ -73,4 +73,4 @@ function fetchFeedUpdate(ky, owner, topic, options) {
73
73
  return Object.assign(Object.assign({}, response.data), readFeedUpdateHeaders(response.headers));
74
74
  });
75
75
  }
76
- exports.fetchFeedUpdate = fetchFeedUpdate;
76
+ exports.fetchLatestFeedUpdate = fetchLatestFeedUpdate;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.SIGNATURE_BYTES_LENGTH = exports.SIGNATURE_HEX_LENGTH = exports.TOPIC_HEX_LENGTH = exports.TOPIC_BYTES_LENGTH = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_DEPTH_MIN = exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = exports.REFERENCE_BYTES_LENGTH = exports.ENCRYPTED_REFERENCE_HEX_LENGTH = exports.REFERENCE_HEX_LENGTH = exports.BATCH_ID_HEX_LENGTH = exports.PUBKEY_HEX_LENGTH = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.ADDRESS_HEX_LENGTH = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = exports.SPAN_SIZE = void 0;
13
+ exports.SIGNATURE_BYTES_LENGTH = exports.SIGNATURE_HEX_LENGTH = exports.TOPIC_HEX_LENGTH = exports.TOPIC_BYTES_LENGTH = exports.FEED_INDEX_HEX_LENGTH = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_DEPTH_MIN = exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = exports.REFERENCE_BYTES_LENGTH = exports.ENCRYPTED_REFERENCE_HEX_LENGTH = exports.REFERENCE_HEX_LENGTH = exports.BATCH_ID_HEX_LENGTH = exports.PUBKEY_HEX_LENGTH = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.ADDRESS_HEX_LENGTH = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = exports.SPAN_SIZE = void 0;
14
14
  __exportStar(require("./debug"), exports);
15
15
  exports.SPAN_SIZE = 8;
16
16
  exports.SECTION_SIZE = 32;
@@ -34,6 +34,7 @@ exports.STAMPS_DEPTH_MIN = 17;
34
34
  exports.STAMPS_DEPTH_MAX = 255;
35
35
  exports.TAGS_LIMIT_MIN = 1;
36
36
  exports.TAGS_LIMIT_MAX = 1000;
37
+ exports.FEED_INDEX_HEX_LENGTH = 16;
37
38
  /*********************************************************
38
39
  * Writers and Readers interfaces
39
40
  */
File without changes
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapBytesWithHelpers = exports.makeBytes = exports.bytesEqual = exports.flexBytesAtOffset = exports.bytesAtOffset = exports.assertFlexBytes = exports.isFlexBytes = exports.assertBytes = exports.isBytes = void 0;
3
+ exports.wrapBytesWithHelpers = exports.makeBytes = exports.bytesEqual = exports.flexBytesAtOffset = exports.bytesAtOffset = exports.assertFlexBytes = exports.isFlexBytes = exports.assertBytes = exports.hasBytesAtOffset = exports.isBytes = void 0;
4
4
  const hex_1 = require("./hex");
5
5
  /**
6
6
  * Type guard for `Bytes<T>` type
@@ -12,6 +12,20 @@ function isBytes(b, length) {
12
12
  return b instanceof Uint8Array && b.length === length;
13
13
  }
14
14
  exports.isBytes = isBytes;
15
+ /**
16
+ * Function that verifies if passed data are Bytes and if the array has "length" number of bytes under given offset.
17
+ * @param data
18
+ * @param offset
19
+ * @param length
20
+ */
21
+ function hasBytesAtOffset(data, offset, length) {
22
+ if (!(data instanceof Uint8Array)) {
23
+ throw new TypeError('Data has to an Uint8Array!');
24
+ }
25
+ const offsetBytes = data.slice(offset, offset + length);
26
+ return isBytes(offsetBytes, length);
27
+ }
28
+ exports.hasBytesAtOffset = hasBytesAtOffset;
15
29
  /**
16
30
  * Verifies if a byte array has a certain length
17
31
  *
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -154,6 +154,12 @@ function http(ky, config) {
154
154
  throw new error_1.BeeRequestError(e.message, config);
155
155
  }
156
156
  else {
157
+ // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
158
+ // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
159
+ // expose the underlying problem.
160
+ if (e.cause) {
161
+ throw new error_1.BeeError(e.cause.message);
162
+ }
157
163
  throw new error_1.BeeError(e.message);
158
164
  }
159
165
  }
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBytesReference = void 0;
4
+ const types_1 = require("../types");
5
+ const bytes_1 = require("./bytes");
6
+ const hex_1 = require("./hex");
7
+ function makeBytesReference(reference, offset = 0) {
8
+ if (typeof reference === 'string') {
9
+ if (offset) {
10
+ throw new Error('Offset property can be set only for UintArray reference!');
11
+ }
12
+ try {
13
+ // Non-encrypted chunk hex string reference
14
+ const hexReference = (0, hex_1.makeHexString)(reference, types_1.REFERENCE_HEX_LENGTH);
15
+ return (0, hex_1.hexToBytes)(hexReference);
16
+ }
17
+ catch (e) {
18
+ if (!(e instanceof TypeError)) {
19
+ throw e;
20
+ }
21
+ // Encrypted chunk hex string reference
22
+ const hexReference = (0, hex_1.makeHexString)(reference, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
23
+ return (0, hex_1.hexToBytes)(hexReference);
24
+ }
25
+ }
26
+ else if (reference instanceof Uint8Array) {
27
+ if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH)) {
28
+ return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH);
29
+ }
30
+ else if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH)) {
31
+ return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH);
32
+ }
33
+ }
34
+ throw new TypeError('invalid chunk reference');
35
+ }
36
+ exports.makeBytesReference = makeBytesReference;
File without changes
File without changes
File without changes
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
3
+ exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
4
4
  const types_1 = require("../types");
5
5
  const error_1 = require("./error");
6
6
  const file_1 = require("./file");
7
7
  const hex_1 = require("./hex");
8
8
  const stream_1 = require("./stream");
9
+ const swarm_cid_1 = require("@ethersphere/swarm-cid");
9
10
  function isUint8Array(obj) {
10
11
  return obj instanceof Uint8Array;
11
12
  }
@@ -68,6 +69,12 @@ function assertNonNegativeInteger(value, name = 'Value') {
68
69
  throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
69
70
  }
70
71
  exports.assertNonNegativeInteger = assertNonNegativeInteger;
72
+ function assertPositiveInteger(value, name = 'Value') {
73
+ assertInteger(value, name);
74
+ if (Number(value) <= 0)
75
+ throw new error_1.BeeArgumentError(`${name} has to be bigger then zero`, value);
76
+ }
77
+ exports.assertPositiveInteger = assertPositiveInteger;
71
78
  function assertReference(value) {
72
79
  try {
73
80
  (0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
@@ -77,6 +84,92 @@ function assertReference(value) {
77
84
  }
78
85
  }
79
86
  exports.assertReference = assertReference;
87
+ function assertReferenceOrEns(value) {
88
+ if (typeof value !== 'string') {
89
+ throw new TypeError('ReferenceOrEns has to be a string!');
90
+ }
91
+ if ((0, hex_1.isHexString)(value)) {
92
+ assertReference(value);
93
+ return;
94
+ }
95
+ /**
96
+ * a.asdf - VALID
97
+ * test.eth - VALID
98
+ * ADAM.ETH - VALID
99
+ * ADAM UHLIR.ETH - INVALID
100
+ * test.whatever.eth - VALID
101
+ * -adg.ets - INVALID
102
+ * adg-.ets - INVALID
103
+ * as-a.com - VALID
104
+ * ethswarm.org - VALID
105
+ * http://asdf.asf - INVALID
106
+ * řš+ýí.šě+ř.čě - VALID
107
+ * tsg.asg?asg - INVALID
108
+ * tsg.asg:1599 - INVALID
109
+ * ethswarm.something- - INVALID
110
+ * ethswarm.-something - INVALID
111
+ * ethswarm.some-thing - VALID
112
+ *
113
+ * The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
114
+ *
115
+ * This part matches 2-63 character string that does not start or end with -
116
+ * [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
117
+ *
118
+ * For 1 character long string we use the part after |
119
+ * [^-.\/?:\s] <regexp2>
120
+ *
121
+ * This is terminated in a group with . character an repeated at least once
122
+ * (<regexp1>|<regexp2>\.)+
123
+ *
124
+ * This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
125
+ * ^(<regexp1>|<regexp2>\.)+<regexp1>$
126
+ */
127
+ const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
128
+ // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
129
+ // but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
130
+ // adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
131
+ if (!DOMAIN_REGEX.test(value)) {
132
+ throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
133
+ }
134
+ }
135
+ exports.assertReferenceOrEns = assertReferenceOrEns;
136
+ /**
137
+ * Function that mainly converts Swarm CID into hex encoded Swarm Reference
138
+ *
139
+ * @param value
140
+ * @param expectedCidType
141
+ */
142
+ function makeReferenceOrEns(value, expectedCidType) {
143
+ var _a;
144
+ if (typeof value !== 'string') {
145
+ throw new TypeError('ReferenceCidOrEns has to be a string!');
146
+ }
147
+ try {
148
+ const result = (0, swarm_cid_1.decodeCid)(value);
149
+ if (result.type !== expectedCidType) {
150
+ throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
151
+ }
152
+ return result.reference;
153
+ }
154
+ catch (e) {
155
+ if (e instanceof error_1.BeeError)
156
+ throw e;
157
+ }
158
+ assertReferenceOrEns(value);
159
+ return value;
160
+ }
161
+ exports.makeReferenceOrEns = makeReferenceOrEns;
162
+ /**
163
+ * Function that adds getter which converts the reference into CID base32 encoded string.
164
+ * @param result
165
+ * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
166
+ */
167
+ function addCidConversionFunction(result, cidType) {
168
+ return Object.assign(Object.assign({}, result), { get cid() {
169
+ return (0, swarm_cid_1.encodeReference)(result.reference, cidType).toString();
170
+ } });
171
+ }
172
+ exports.addCidConversionFunction = addCidConversionFunction;
80
173
  function assertAddress(value) {
81
174
  (0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
82
175
  }
@@ -221,6 +314,12 @@ function assertPostageBatchOptions(value) {
221
314
  if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
222
315
  assertBoolean(options.immutableFlag);
223
316
  }
317
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
318
+ assertBoolean(options.waitForUsable);
319
+ }
320
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
321
+ assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
322
+ }
224
323
  }
225
324
  exports.assertPostageBatchOptions = assertPostageBatchOptions;
226
325
  function assertCashoutOptions(value) {
File without changes
File without changes