@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.10

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 (193) hide show
  1. package/README.md +18 -17
  2. package/dist/cjs/bee-debug.js +572 -0
  3. package/dist/cjs/bee.js +876 -0
  4. package/dist/cjs/chunk/bmt.js +55 -0
  5. package/dist/cjs/chunk/cac.js +56 -0
  6. package/dist/cjs/chunk/serialize.js +19 -0
  7. package/dist/cjs/chunk/signer.js +126 -0
  8. package/dist/cjs/chunk/soc.js +159 -0
  9. package/dist/cjs/chunk/span.js +29 -0
  10. package/dist/cjs/feed/identifier.js +35 -0
  11. package/dist/cjs/feed/index.js +116 -0
  12. package/dist/cjs/feed/json.js +28 -0
  13. package/dist/cjs/feed/retrievable.js +58 -0
  14. package/dist/cjs/feed/topic.js +25 -0
  15. package/dist/cjs/feed/type.js +15 -0
  16. package/dist/cjs/index.js +39 -0
  17. package/dist/cjs/modules/bytes.js +61 -0
  18. package/dist/cjs/modules/bzz.js +125 -0
  19. package/dist/cjs/modules/chunk.js +48 -0
  20. package/dist/cjs/modules/debug/balance.js +60 -0
  21. package/dist/cjs/modules/debug/chequebook.js +142 -0
  22. package/dist/cjs/modules/debug/chunk.js +38 -0
  23. package/dist/cjs/modules/debug/connectivity.js +54 -0
  24. package/dist/cjs/modules/debug/settlements.js +32 -0
  25. package/dist/cjs/modules/debug/stake.js +57 -0
  26. package/dist/cjs/modules/debug/stamps.js +68 -0
  27. package/dist/cjs/modules/debug/states.js +64 -0
  28. package/dist/cjs/modules/debug/status.js +148 -0
  29. package/dist/cjs/modules/debug/tag.js +19 -0
  30. package/dist/cjs/modules/debug/transactions.js +64 -0
  31. package/dist/cjs/modules/feed.js +66 -0
  32. package/dist/cjs/modules/pinning.js +63 -0
  33. package/dist/cjs/modules/pss.js +43 -0
  34. package/dist/cjs/modules/soc.js +32 -0
  35. package/dist/cjs/modules/status.js +15 -0
  36. package/dist/cjs/modules/stewardship.js +28 -0
  37. package/dist/cjs/modules/tag.js +77 -0
  38. package/dist/cjs/package.json +8 -0
  39. package/dist/cjs/types/debug.js +10 -0
  40. package/dist/cjs/types/index.js +51 -0
  41. package/dist/cjs/utils/bytes.js +121 -0
  42. package/dist/cjs/utils/collection.browser.js +23 -0
  43. package/dist/cjs/utils/collection.js +59 -0
  44. package/dist/cjs/utils/collection.node.js +71 -0
  45. package/dist/cjs/utils/data.browser.js +61 -0
  46. package/dist/cjs/utils/data.js +45 -0
  47. package/dist/cjs/utils/error.js +16 -0
  48. package/dist/cjs/utils/eth.js +199 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +38 -0
  51. package/dist/cjs/utils/hash.js +21 -0
  52. package/dist/cjs/utils/headers.js +59 -0
  53. package/dist/cjs/utils/hex.js +150 -0
  54. package/dist/cjs/utils/http.js +40 -0
  55. package/dist/cjs/utils/pss.js +18 -0
  56. package/dist/cjs/utils/reference.js +36 -0
  57. package/dist/cjs/utils/stamps.js +17 -0
  58. package/dist/cjs/utils/stream.js +146 -0
  59. package/dist/cjs/utils/tar.js +25 -0
  60. package/dist/cjs/utils/type.js +434 -0
  61. package/dist/cjs/utils/uint64.js +29 -0
  62. package/dist/cjs/utils/url.js +56 -0
  63. package/dist/index.browser.min.js +3 -0
  64. package/dist/index.browser.min.js.LICENSE.txt +50 -0
  65. package/dist/index.browser.min.js.map +1 -0
  66. package/dist/{src → mjs}/bee-debug.js +102 -183
  67. package/dist/{src → mjs}/bee.js +82 -232
  68. package/dist/{src → mjs}/chunk/bmt.js +4 -10
  69. package/dist/{src → mjs}/chunk/cac.js +0 -3
  70. package/dist/{src → mjs}/chunk/signer.js +1 -18
  71. package/dist/{src → mjs}/chunk/soc.js +17 -29
  72. package/dist/{src → mjs}/chunk/span.js +2 -5
  73. package/dist/{src → mjs}/feed/identifier.js +0 -6
  74. package/dist/{src → mjs}/feed/index.js +24 -27
  75. package/dist/{src → mjs}/feed/json.js +2 -5
  76. package/dist/{src → mjs}/feed/retrievable.js +7 -21
  77. package/dist/{src → mjs}/feed/topic.js +0 -2
  78. package/dist/{src → mjs}/index.js +2 -2
  79. package/dist/{src → mjs}/modules/bytes.js +16 -20
  80. package/dist/{src → mjs}/modules/bzz.js +33 -40
  81. package/dist/{src → mjs}/modules/chunk.js +11 -13
  82. package/dist/mjs/modules/debug/balance.js +53 -0
  83. package/dist/mjs/modules/debug/chequebook.js +135 -0
  84. package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +27 -0
  87. package/dist/mjs/modules/debug/stake.js +51 -0
  88. package/dist/mjs/modules/debug/stamps.js +61 -0
  89. package/dist/mjs/modules/debug/states.js +58 -0
  90. package/dist/{src → mjs}/modules/debug/status.js +46 -37
  91. package/dist/mjs/modules/debug/tag.js +15 -0
  92. package/dist/mjs/modules/debug/transactions.js +59 -0
  93. package/dist/{src → mjs}/modules/feed.js +15 -21
  94. package/dist/mjs/modules/pinning.js +56 -0
  95. package/dist/{src → mjs}/modules/pss.js +7 -10
  96. package/dist/{src → mjs}/modules/soc.js +6 -7
  97. package/dist/mjs/modules/status.js +11 -0
  98. package/dist/mjs/modules/stewardship.js +23 -0
  99. package/dist/mjs/modules/tag.js +72 -0
  100. package/dist/mjs/package.json +8 -0
  101. package/dist/{src → mjs}/types/debug.js +0 -1
  102. package/dist/{src → mjs}/types/index.js +0 -4
  103. package/dist/{src → mjs}/utils/bytes.js +8 -17
  104. package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
  105. package/dist/{src → mjs}/utils/collection.js +0 -12
  106. package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
  107. package/dist/{src → mjs}/utils/data.browser.js +2 -11
  108. package/dist/{src → mjs}/utils/data.js +0 -7
  109. package/dist/mjs/utils/error.js +11 -0
  110. package/dist/{src → mjs}/utils/eth.js +6 -28
  111. package/dist/{src → mjs}/utils/expose.js +1 -1
  112. package/dist/{src → mjs}/utils/file.js +4 -9
  113. package/dist/{src → mjs}/utils/hash.js +0 -1
  114. package/dist/{src → mjs}/utils/headers.js +5 -13
  115. package/dist/{src → mjs}/utils/hex.js +6 -25
  116. package/dist/mjs/utils/http.js +34 -0
  117. package/dist/{src → mjs}/utils/pss.js +0 -2
  118. package/dist/{src → mjs}/utils/reference.js +2 -5
  119. package/dist/{src → mjs}/utils/stream.js +3 -26
  120. package/dist/{src → mjs}/utils/tar.js +3 -6
  121. package/dist/{src → mjs}/utils/type.js +23 -80
  122. package/dist/{src → mjs}/utils/uint64.js +0 -1
  123. package/dist/{src → mjs}/utils/url.js +2 -10
  124. package/dist/types/bee-debug.d.ts +71 -46
  125. package/dist/types/bee.d.ts +34 -58
  126. package/dist/types/chunk/bmt.d.ts +1 -1
  127. package/dist/types/chunk/cac.d.ts +1 -1
  128. package/dist/types/chunk/soc.d.ts +9 -9
  129. package/dist/types/chunk/span.d.ts +1 -1
  130. package/dist/types/feed/index.d.ts +10 -10
  131. package/dist/types/feed/json.d.ts +2 -2
  132. package/dist/types/feed/retrievable.d.ts +2 -2
  133. package/dist/types/feed/type.d.ts +1 -1
  134. package/dist/types/index.d.ts +13 -2
  135. package/dist/types/modules/bytes.d.ts +5 -5
  136. package/dist/types/modules/bzz.d.ts +8 -8
  137. package/dist/types/modules/chunk.d.ts +4 -4
  138. package/dist/types/modules/debug/balance.d.ts +9 -9
  139. package/dist/types/modules/debug/chequebook.d.ts +17 -17
  140. package/dist/types/modules/debug/chunk.d.ts +5 -5
  141. package/dist/types/modules/debug/connectivity.d.ts +7 -7
  142. package/dist/types/modules/debug/settlements.d.ts +5 -5
  143. package/dist/types/modules/debug/stake.d.ts +21 -0
  144. package/dist/types/modules/debug/stamps.d.ts +7 -7
  145. package/dist/types/modules/debug/states.d.ts +7 -7
  146. package/dist/types/modules/debug/status.d.ts +21 -15
  147. package/dist/types/modules/debug/tag.d.ts +3 -3
  148. package/dist/types/modules/debug/transactions.d.ts +5 -5
  149. package/dist/types/modules/feed.d.ts +3 -3
  150. package/dist/types/modules/pinning.d.ts +7 -7
  151. package/dist/types/modules/pss.d.ts +3 -3
  152. package/dist/types/modules/soc.d.ts +2 -2
  153. package/dist/types/modules/status.d.ts +3 -3
  154. package/dist/types/modules/stewardship.d.ts +3 -3
  155. package/dist/types/modules/tag.d.ts +6 -6
  156. package/dist/types/types/debug.d.ts +35 -2
  157. package/dist/types/types/index.d.ts +48 -89
  158. package/dist/types/utils/error.d.ts +0 -26
  159. package/dist/types/utils/eth.d.ts +6 -6
  160. package/dist/types/utils/expose.d.ts +4 -7
  161. package/dist/types/utils/hash.d.ts +1 -1
  162. package/dist/types/utils/headers.d.ts +1 -1
  163. package/dist/types/utils/hex.d.ts +4 -4
  164. package/dist/types/utils/http.d.ts +11 -21
  165. package/dist/types/utils/stream.d.ts +1 -1
  166. package/dist/types/utils/type.d.ts +3 -2
  167. package/dist/types/utils/uint64.d.ts +1 -1
  168. package/package.json +59 -52
  169. package/dist/index.browser.js +0 -33
  170. package/dist/index.browser.js.map +0 -7
  171. package/dist/src/modules/debug/balance.js +0 -57
  172. package/dist/src/modules/debug/chequebook.js +0 -150
  173. package/dist/src/modules/debug/connectivity.js +0 -45
  174. package/dist/src/modules/debug/settlements.js +0 -29
  175. package/dist/src/modules/debug/stamps.js +0 -64
  176. package/dist/src/modules/debug/states.js +0 -46
  177. package/dist/src/modules/debug/tag.js +0 -16
  178. package/dist/src/modules/debug/transactions.js +0 -69
  179. package/dist/src/modules/pinning.js +0 -60
  180. package/dist/src/modules/status.js +0 -12
  181. package/dist/src/modules/stewardship.js +0 -24
  182. package/dist/src/modules/tag.js +0 -77
  183. package/dist/src/utils/error.js +0 -47
  184. package/dist/src/utils/http.js +0 -162
  185. package/dist/src/utils/merge.js +0 -36
  186. package/dist/src/utils/sleep.js +0 -8
  187. package/dist/types/utils/merge.d.ts +0 -8
  188. package/dist/types/utils/sleep.d.ts +0 -6
  189. /package/dist/{src → mjs}/chunk/serialize.js +0 -0
  190. /package/dist/{src → mjs}/feed/type.js +0 -0
  191. /package/dist/{src → mjs}/utils/stamps.js +0 -0
  192. /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
  193. /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllSettlements = exports.getSettlements = void 0;
4
+ const http_1 = require("../../utils/http");
5
+ const settlementsEndpoint = 'settlements';
6
+ /**
7
+ * Get amount of sent and received from settlements with a peer
8
+ *
9
+ * @param kyOptions Ky Options for making requests
10
+ * @param peer Swarm address of peer
11
+ */
12
+ async function getSettlements(requestOptions, peer) {
13
+ const response = await (0, http_1.http)(requestOptions, {
14
+ url: `${settlementsEndpoint}/${peer}`,
15
+ responseType: 'json',
16
+ });
17
+ return response.data;
18
+ }
19
+ exports.getSettlements = getSettlements;
20
+ /**
21
+ * Get settlements with all known peers and total amount sent or received
22
+ *
23
+ * @param kyOptions Ky Options for making requests
24
+ */
25
+ async function getAllSettlements(requestOptions) {
26
+ const response = await (0, http_1.http)(requestOptions, {
27
+ url: settlementsEndpoint,
28
+ responseType: 'json',
29
+ });
30
+ return response.data;
31
+ }
32
+ exports.getAllSettlements = getAllSettlements;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRedistributionState = exports.stake = exports.getStake = void 0;
4
+ const http_1 = require("../../utils/http");
5
+ const STAKE_ENDPOINT = 'stake';
6
+ const REDISTRIBUTION_ENDPOINT = 'redistributionstate';
7
+ /**
8
+ * Gets the staked amount
9
+ *
10
+ * @param kyOptions Ky Options for making requests
11
+ */
12
+ async function getStake(requestOptions) {
13
+ const response = await (0, http_1.http)(requestOptions, {
14
+ method: 'get',
15
+ responseType: 'json',
16
+ url: `${STAKE_ENDPOINT}`,
17
+ });
18
+ return response.data.stakedAmount.toString();
19
+ }
20
+ exports.getStake = getStake;
21
+ /**
22
+ * Stake given amount of tokens.
23
+ *
24
+ * @param ky
25
+ * @param amount
26
+ * @param options
27
+ */
28
+ async function stake(requestOptions, amount, options) {
29
+ const headers = {};
30
+ if (options?.gasPrice) {
31
+ headers['gas-price'] = options.gasPrice.toString();
32
+ }
33
+ if (options?.gasLimit) {
34
+ headers['gas-limit'] = options.gasLimit.toString();
35
+ }
36
+ await (0, http_1.http)(requestOptions, {
37
+ method: 'post',
38
+ responseType: 'json',
39
+ url: `${STAKE_ENDPOINT}/${amount}`,
40
+ headers,
41
+ });
42
+ }
43
+ exports.stake = stake;
44
+ /**
45
+ * Get current status of node in redistribution game
46
+ *
47
+ * @param kyOptions Ky Options for making requests
48
+ */
49
+ async function getRedistributionState(requestOptions) {
50
+ const response = await (0, http_1.http)(requestOptions, {
51
+ method: 'get',
52
+ responseType: 'json',
53
+ url: REDISTRIBUTION_ENDPOINT,
54
+ });
55
+ return response.data;
56
+ }
57
+ exports.getRedistributionState = getRedistributionState;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.diluteBatch = exports.topUpBatch = exports.createPostageBatch = exports.getPostageBatchBuckets = exports.getPostageBatch = exports.getAllPostageBatches = void 0;
4
+ const http_1 = require("../../utils/http");
5
+ const STAMPS_ENDPOINT = 'stamps';
6
+ async function getAllPostageBatches(requestOptions) {
7
+ const response = await (0, http_1.http)(requestOptions, {
8
+ method: 'get',
9
+ url: `${STAMPS_ENDPOINT}`,
10
+ responseType: 'json',
11
+ });
12
+ return response.data.stamps;
13
+ }
14
+ exports.getAllPostageBatches = getAllPostageBatches;
15
+ async function getPostageBatch(requestOptions, postageBatchId) {
16
+ const response = await (0, http_1.http)(requestOptions, {
17
+ method: 'get',
18
+ url: `${STAMPS_ENDPOINT}/${postageBatchId}`,
19
+ responseType: 'json',
20
+ });
21
+ return response.data;
22
+ }
23
+ exports.getPostageBatch = getPostageBatch;
24
+ async function getPostageBatchBuckets(requestOptions, postageBatchId) {
25
+ const response = await (0, http_1.http)(requestOptions, {
26
+ method: 'get',
27
+ url: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
28
+ responseType: 'json',
29
+ });
30
+ return response.data;
31
+ }
32
+ exports.getPostageBatchBuckets = getPostageBatchBuckets;
33
+ async function createPostageBatch(requestOptions, amount, depth, options) {
34
+ const headers = {};
35
+ if (options?.gasPrice) {
36
+ headers['gas-price'] = options.gasPrice.toString();
37
+ }
38
+ if (options?.immutableFlag !== undefined) {
39
+ headers.immutable = String(options.immutableFlag);
40
+ }
41
+ const response = await (0, http_1.http)(requestOptions, {
42
+ method: 'post',
43
+ url: `${STAMPS_ENDPOINT}/${amount}/${depth}`,
44
+ responseType: 'json',
45
+ params: { label: options?.label },
46
+ headers,
47
+ });
48
+ return response.data.batchID;
49
+ }
50
+ exports.createPostageBatch = createPostageBatch;
51
+ async function topUpBatch(requestOptions, id, amount) {
52
+ const response = await (0, http_1.http)(requestOptions, {
53
+ method: 'patch',
54
+ url: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
55
+ responseType: 'json',
56
+ });
57
+ return response.data.batchID;
58
+ }
59
+ exports.topUpBatch = topUpBatch;
60
+ async function diluteBatch(requestOptions, id, depth) {
61
+ const response = await (0, http_1.http)(requestOptions, {
62
+ method: 'patch',
63
+ url: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
64
+ responseType: 'json',
65
+ });
66
+ return response.data.batchID;
67
+ }
68
+ exports.diluteBatch = diluteBatch;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
4
+ const http_1 = require("../../utils/http");
5
+ const RESERVE_STATE_ENDPOINT = 'reservestate';
6
+ const WALLET_ENDPOINT = 'wallet';
7
+ const CHAIN_STATE_ENDPOINT = 'chainstate';
8
+ /**
9
+ * Get state of reserve
10
+ *
11
+ * @param kyOptions Ky Options for making requests
12
+ */
13
+ async function getReserveState(requestOptions) {
14
+ const response = await (0, http_1.http)(requestOptions, {
15
+ method: 'get',
16
+ url: `${RESERVE_STATE_ENDPOINT}`,
17
+ responseType: 'json',
18
+ });
19
+ return response.data;
20
+ }
21
+ exports.getReserveState = getReserveState;
22
+ /**
23
+ * Get state of reserve
24
+ *
25
+ * @param kyOptions Ky Options for making requests
26
+ */
27
+ async function getChainState(requestOptions) {
28
+ const response = await (0, http_1.http)(requestOptions, {
29
+ method: 'get',
30
+ url: `${CHAIN_STATE_ENDPOINT}`,
31
+ responseType: 'json',
32
+ });
33
+ return response.data;
34
+ }
35
+ exports.getChainState = getChainState;
36
+ /**
37
+ * Get wallet balances for xDai and BZZ of the node
38
+ *
39
+ * @param kyOptions Ky Options for making requests
40
+ */
41
+ async function getWalletBalance(requestOptions) {
42
+ const response = await (0, http_1.http)(requestOptions, {
43
+ method: 'get',
44
+ url: `${WALLET_ENDPOINT}`,
45
+ responseType: 'json',
46
+ });
47
+ return mapWalletProperties(response.data);
48
+ }
49
+ exports.getWalletBalance = getWalletBalance;
50
+ /**
51
+ * TODO: Remove on next break
52
+ * @param data
53
+ */
54
+ function mapWalletProperties(data) {
55
+ return {
56
+ // @ts-ignore: Needed for backward compatibility mapping
57
+ bzz: data.bzzBalance,
58
+ // @ts-ignore: Needed for backward compatibility mapping
59
+ xDai: data.nativeTokenBalance,
60
+ // @ts-ignore: Needed for backward compatibility mapping
61
+ contractAddress: data.chequebookContractAddress,
62
+ ...data,
63
+ };
64
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedDebugApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getReadiness = exports.getHealth = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_DEBUG_API_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
7
+ const major_js_1 = __importDefault(require("semver/functions/major.js"));
8
+ const http_1 = require("../../utils/http");
9
+ // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
10
+ // so if you are changing anything about them change the `update_bee` action accordingly!
11
+ exports.SUPPORTED_BEE_VERSION_EXACT = '1.13.0-f1067884';
12
+ exports.SUPPORTED_API_VERSION = '4.0.0';
13
+ exports.SUPPORTED_DEBUG_API_VERSION = '4.0.0';
14
+ exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.substring(0, exports.SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
15
+ const NODE_INFO_URL = 'node';
16
+ const HEALTH_URL = 'health';
17
+ const READINESS_URL = 'readiness';
18
+ /**
19
+ * Get health of node
20
+ *
21
+ * @param kyOptions Ky Options for making requests
22
+ */
23
+ async function getHealth(requestOptions) {
24
+ const response = await (0, http_1.http)(requestOptions, {
25
+ method: 'get',
26
+ url: HEALTH_URL,
27
+ responseType: 'json',
28
+ });
29
+ return response.data;
30
+ }
31
+ exports.getHealth = getHealth;
32
+ /**
33
+ * Get readiness of node
34
+ *
35
+ * @param kyOptions Ky Options for making requests
36
+ */
37
+ async function getReadiness(requestOptions) {
38
+ try {
39
+ const response = await (0, http_1.http)(requestOptions, {
40
+ method: 'get',
41
+ url: READINESS_URL,
42
+ });
43
+ return response.status === 200;
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ }
49
+ exports.getReadiness = getReadiness;
50
+ /**
51
+ * Get information about Bee node
52
+ *
53
+ * @param kyOptions Ky Options for making requests
54
+ */
55
+ async function getNodeInfo(requestOptions) {
56
+ const response = await (0, http_1.http)(requestOptions, {
57
+ method: 'get',
58
+ url: NODE_INFO_URL,
59
+ responseType: 'json',
60
+ });
61
+ return response.data;
62
+ }
63
+ exports.getNodeInfo = getNodeInfo;
64
+ /**
65
+ * Connects to a node and checks if it is a supported Bee version by the bee-js
66
+ *
67
+ * @param kyOptions Ky Options for making requests
68
+ *
69
+ * @returns true if the Bee node version is supported
70
+ * @deprecated Use `isSupportedExactVersion` instead
71
+ */
72
+ // TODO: Remove on break
73
+ async function isSupportedVersion(requestOptions) {
74
+ return isSupportedExactVersion(requestOptions);
75
+ }
76
+ exports.isSupportedVersion = isSupportedVersion;
77
+ /**
78
+ * Connects to a node and checks if its version matches with the one that bee-js supports.
79
+ *
80
+ * Be aware that this is the most strict version check and most probably
81
+ * you will want to use more relaxed API-versions based checks like
82
+ * `isSupportedApiVersion`, `isSupportedMainApiVersion` or `isSupportedDebugApiVersion`
83
+ * based on your use-case.
84
+ *
85
+ * @param ky
86
+ */
87
+ async function isSupportedExactVersion(requestOptions) {
88
+ const { version } = await getHealth(requestOptions);
89
+ return version === exports.SUPPORTED_BEE_VERSION_EXACT;
90
+ }
91
+ exports.isSupportedExactVersion = isSupportedExactVersion;
92
+ /**
93
+ * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
94
+ *
95
+ * This is useful if you are not using `BeeDebug` class (for anything else then this check)
96
+ * and want to make sure about compatibility.
97
+ *
98
+ * @param ky
99
+ */
100
+ async function isSupportedMainApiVersion(requestOptions) {
101
+ const { apiVersion } = await getHealth(requestOptions);
102
+ return (0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(exports.SUPPORTED_API_VERSION);
103
+ }
104
+ exports.isSupportedMainApiVersion = isSupportedMainApiVersion;
105
+ /**
106
+ * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
107
+ *
108
+ * This is useful if you are not using `Bee` class in your application and want to make sure
109
+ * about compatibility.
110
+ *
111
+ * @param ky
112
+ */
113
+ async function isSupportedDebugApiVersion(requestOptions) {
114
+ const { debugApiVersion } = await getHealth(requestOptions);
115
+ return (0, major_js_1.default)(debugApiVersion) === (0, major_js_1.default)(exports.SUPPORTED_DEBUG_API_VERSION);
116
+ }
117
+ exports.isSupportedDebugApiVersion = isSupportedDebugApiVersion;
118
+ /**
119
+ * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
120
+ *
121
+ * This should be the main way how to check compatibility for your app and Bee node.
122
+ *
123
+ * @param ky
124
+ */
125
+ async function isSupportedApiVersion(requestOptions) {
126
+ const { apiVersion, debugApiVersion } = await getHealth(requestOptions);
127
+ return ((0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(exports.SUPPORTED_API_VERSION) &&
128
+ (0, major_js_1.default)(debugApiVersion) === (0, major_js_1.default)(exports.SUPPORTED_DEBUG_API_VERSION));
129
+ }
130
+ exports.isSupportedApiVersion = isSupportedApiVersion;
131
+ /**
132
+ * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
133
+ * and versions that bee-js supports (properties prefixed with `supported*`).
134
+ *
135
+ * @param ky
136
+ */
137
+ async function getVersions(requestOptions) {
138
+ const { version, apiVersion, debugApiVersion } = await getHealth(requestOptions);
139
+ return {
140
+ supportedBeeVersion: exports.SUPPORTED_BEE_VERSION_EXACT,
141
+ supportedBeeApiVersion: exports.SUPPORTED_API_VERSION,
142
+ supportedBeeDebugApiVersion: exports.SUPPORTED_DEBUG_API_VERSION,
143
+ beeVersion: version,
144
+ beeApiVersion: apiVersion,
145
+ beeDebugApiVersion: debugApiVersion,
146
+ };
147
+ }
148
+ exports.getVersions = getVersions;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveExtendedTag = void 0;
4
+ const http_1 = require("../../utils/http");
5
+ const endpoint = 'tags';
6
+ /**
7
+ * Retrieve tag with extended information from Bee node
8
+ *
9
+ * @param kyOptions Ky Options for making requests
10
+ * @param uid UID of tag to be retrieved
11
+ */
12
+ async function retrieveExtendedTag(requestOptions, uid) {
13
+ const response = await (0, http_1.http)(requestOptions, {
14
+ url: `${endpoint}/${uid}`,
15
+ responseType: 'json',
16
+ });
17
+ return response.data;
18
+ }
19
+ exports.retrieveExtendedTag = retrieveExtendedTag;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cancelTransaction = exports.rebroadcastTransaction = exports.getTransaction = exports.getAllTransactions = void 0;
4
+ const http_1 = require("../../utils/http");
5
+ const transactionsEndpoint = 'transactions';
6
+ /**
7
+ * Get list of all pending transactions
8
+ *
9
+ * @param ky Debug Ky instance
10
+ */
11
+ async function getAllTransactions(requestOptions) {
12
+ const response = await (0, http_1.http)(requestOptions, {
13
+ url: transactionsEndpoint,
14
+ responseType: 'json',
15
+ });
16
+ return response.data.pendingTransactions;
17
+ }
18
+ exports.getAllTransactions = getAllTransactions;
19
+ /**
20
+ * Get information for specific pending transactions
21
+ *
22
+ * @param ky Debug Ky instance
23
+ * @param transactionHash Hash of the transaction
24
+ */
25
+ async function getTransaction(requestOptions, transactionHash) {
26
+ const response = await (0, http_1.http)(requestOptions, {
27
+ url: `${transactionsEndpoint}/${transactionHash}`,
28
+ responseType: 'json',
29
+ });
30
+ return response.data;
31
+ }
32
+ exports.getTransaction = getTransaction;
33
+ /**
34
+ * Rebroadcast existing transaction
35
+ *
36
+ * @param ky Debug Ky instance
37
+ * @param transactionHash Hash of the transaction
38
+ */
39
+ async function rebroadcastTransaction(requestOptions, transactionHash) {
40
+ const response = await (0, http_1.http)(requestOptions, {
41
+ method: 'post',
42
+ url: `${transactionsEndpoint}/${transactionHash}`,
43
+ responseType: 'json',
44
+ });
45
+ return response.data.transactionHash;
46
+ }
47
+ exports.rebroadcastTransaction = rebroadcastTransaction;
48
+ /**
49
+ * Cancel existing transaction
50
+ *
51
+ * @param ky Debug Ky instance
52
+ * @param transactionHash Hash of the transaction
53
+ * @param gasPrice Optional gas price
54
+ */
55
+ async function cancelTransaction(requestOptions, transactionHash, gasPrice) {
56
+ const response = await (0, http_1.http)(requestOptions, {
57
+ method: 'delete',
58
+ headers: { 'gas-price': gasPrice },
59
+ url: `${transactionsEndpoint}/${transactionHash}`,
60
+ responseType: 'json',
61
+ });
62
+ return response.data.transactionHash;
63
+ }
64
+ exports.cancelTransaction = cancelTransaction;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchLatestFeedUpdate = exports.createFeedManifest = void 0;
4
+ const error_1 = require("../utils/error");
5
+ const headers_1 = require("../utils/headers");
6
+ const http_1 = require("../utils/http");
7
+ const feedEndpoint = 'feeds';
8
+ /**
9
+ * Create an initial feed root manifest
10
+ *
11
+ * @param ky Ky instance
12
+ * @param owner Owner's ethereum address in hex
13
+ * @param topic Topic in hex
14
+ * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
15
+ * @param options Additional options, like type (default: 'sequence')
16
+ */
17
+ async function createFeedManifest(requestOptions, owner, topic, postageBatchId, options) {
18
+ const response = await (0, http_1.http)(requestOptions, {
19
+ method: 'post',
20
+ responseType: 'json',
21
+ url: `${feedEndpoint}/${owner}/${topic}`,
22
+ params: options,
23
+ headers: (0, headers_1.extractUploadHeaders)(postageBatchId),
24
+ });
25
+ return response.data.reference;
26
+ }
27
+ exports.createFeedManifest = createFeedManifest;
28
+ function readFeedUpdateHeaders(headers) {
29
+ const feedIndex = headers['swarm-feed-index'];
30
+ const feedIndexNext = headers['swarm-feed-index-next'];
31
+ if (!feedIndex) {
32
+ throw new error_1.BeeError('Response did not contain expected swarm-feed-index!');
33
+ }
34
+ if (!feedIndexNext) {
35
+ throw new error_1.BeeError('Response did not contain expected swarm-feed-index-next!');
36
+ }
37
+ return {
38
+ feedIndex,
39
+ feedIndexNext,
40
+ };
41
+ }
42
+ /**
43
+ * Find and retrieve feed update
44
+ *
45
+ * The feed consists of updates. This endpoint looks up an
46
+ * update that matches the provided parameters and returns
47
+ * the reference it contains along with its index and the
48
+ * index of the subsequent update.
49
+ *
50
+ * @param ky Ky instance
51
+ * @param owner Owner's ethereum address in hex
52
+ * @param topic Topic in hex
53
+ * @param options Additional options, like index, at, type
54
+ */
55
+ async function fetchLatestFeedUpdate(requestOptions, owner, topic, options) {
56
+ const response = await (0, http_1.http)(requestOptions, {
57
+ responseType: 'json',
58
+ url: `${feedEndpoint}/${owner}/${topic}`,
59
+ params: options,
60
+ });
61
+ return {
62
+ ...response.data,
63
+ ...readFeedUpdateHeaders(response.headers),
64
+ };
65
+ }
66
+ exports.fetchLatestFeedUpdate = fetchLatestFeedUpdate;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAllPins = exports.getPin = exports.unpin = exports.pin = void 0;
4
+ const http_1 = require("../utils/http");
5
+ const PINNING_ENDPOINT = 'pins';
6
+ /**
7
+ * Pin data with given reference
8
+ *
9
+ * @param kyOptions Ky Options for making requests
10
+ * @param reference Bee data reference
11
+ */
12
+ async function pin(requestOptions, reference) {
13
+ await (0, http_1.http)(requestOptions, {
14
+ method: 'post',
15
+ responseType: 'json',
16
+ url: `${PINNING_ENDPOINT}/${reference}`,
17
+ });
18
+ }
19
+ exports.pin = pin;
20
+ /**
21
+ * Unpin data with given reference
22
+ *
23
+ * @param kyOptions Ky Options for making requests
24
+ * @param reference Bee data reference
25
+ */
26
+ async function unpin(requestOptions, reference) {
27
+ await (0, http_1.http)(requestOptions, {
28
+ method: 'delete',
29
+ responseType: 'json',
30
+ url: `${PINNING_ENDPOINT}/${reference}`,
31
+ });
32
+ }
33
+ exports.unpin = unpin;
34
+ /**
35
+ * Get pin status for specific address.
36
+ *
37
+ * @param ky Ky instance
38
+ * @param reference
39
+ * @throws Error if given address is not pinned
40
+ */
41
+ async function getPin(requestOptions, reference) {
42
+ const response = await (0, http_1.http)(requestOptions, {
43
+ method: 'get',
44
+ responseType: 'json',
45
+ url: `${PINNING_ENDPOINT}/${reference}`,
46
+ });
47
+ return response.data;
48
+ }
49
+ exports.getPin = getPin;
50
+ /**
51
+ * Get list of all pins
52
+ *
53
+ * @param ky Ky instance
54
+ */
55
+ async function getAllPins(requestOptions) {
56
+ const response = await (0, http_1.http)(requestOptions, {
57
+ method: 'get',
58
+ responseType: 'json',
59
+ url: `${PINNING_ENDPOINT}`,
60
+ });
61
+ return response.data.references;
62
+ }
63
+ exports.getAllPins = getAllPins;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.subscribe = exports.send = void 0;
7
+ const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
8
+ const headers_1 = require("../utils/headers");
9
+ const http_1 = require("../utils/http");
10
+ const endpoint = 'pss';
11
+ /**
12
+ * Send to recipient or target with Postal Service for Swarm
13
+ *
14
+ * @param kyOptions Ky Options for making requests
15
+ * @param topic Topic name
16
+ * @param target Target message address prefix
17
+ * @param data
18
+ * @param postageBatchId Postage BatchId that will be assigned to sent message
19
+ * @param recipient Recipient public key
20
+ *
21
+ */
22
+ async function send(requestOptions, topic, target, data, postageBatchId, recipient) {
23
+ await (0, http_1.http)(requestOptions, {
24
+ method: 'post',
25
+ url: `${endpoint}/send/${topic}/${target}`,
26
+ data,
27
+ responseType: 'json',
28
+ params: { recipient },
29
+ headers: (0, headers_1.extractUploadHeaders)(postageBatchId),
30
+ });
31
+ }
32
+ exports.send = send;
33
+ /**
34
+ * Subscribe for messages on the given topic
35
+ *
36
+ * @param url Bee node URL
37
+ * @param topic Topic name
38
+ */
39
+ function subscribe(url, topic) {
40
+ const wsUrl = url.replace(/^http/i, 'ws');
41
+ return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${topic}`);
42
+ }
43
+ exports.subscribe = subscribe;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upload = void 0;
4
+ const headers_1 = require("../utils/headers");
5
+ const http_1 = require("../utils/http");
6
+ const socEndpoint = 'soc';
7
+ /**
8
+ * Upload single owner chunk (SOC) to a Bee node
9
+ *
10
+ * @param ky Ky instance
11
+ * @param owner Owner's ethereum address in hex
12
+ * @param identifier Arbitrary identifier in hex
13
+ * @param signature Signature in hex
14
+ * @param data Content addressed chunk data to be uploaded
15
+ * @param postageBatchId Postage BatchId that will be assigned to uploaded data
16
+ * @param options Additional options like tag, encryption, pinning
17
+ */
18
+ async function upload(requestOptions, owner, identifier, signature, data, postageBatchId, options) {
19
+ const response = await (0, http_1.http)(requestOptions, {
20
+ method: 'post',
21
+ url: `${socEndpoint}/${owner}/${identifier}`,
22
+ data,
23
+ headers: {
24
+ 'content-type': 'application/octet-stream',
25
+ ...(0, headers_1.extractUploadHeaders)(postageBatchId, options),
26
+ },
27
+ responseType: 'json',
28
+ params: { sig: signature },
29
+ });
30
+ return response.data.reference;
31
+ }
32
+ exports.upload = upload;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkConnection = void 0;
4
+ const http_1 = require("../utils/http");
5
+ /**
6
+ * Ping the base bee URL. If connection was not successful throw error
7
+ *
8
+ * @param kyOptions Ky instance for given Bee class instance
9
+ */
10
+ async function checkConnection(requestOptions) {
11
+ await (0, http_1.http)(requestOptions, {
12
+ url: '',
13
+ });
14
+ }
15
+ exports.checkConnection = checkConnection;