@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
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  **Warning: This project is in beta state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.**
15
15
 
16
- This project is intended to be used with **Bee version <!-- SUPPORTED_BEE_START -->1.7.0<!-- SUPPORTED_BEE_END -->**. Using it with older or newer Bee versions is not recommended and may not work. Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the [releases tab](https://github.com/ethersphere/bee-js/releases).
16
+ This project is intended to be used with **Bee version <!-- SUPPORTED_BEE_START -->1.13.0<!-- SUPPORTED_BEE_END -->**. Using it with older or newer Bee versions is not recommended and may not work. Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the [releases tab](https://github.com/ethersphere/bee-js/releases).
17
17
 
18
18
  ## Table of Contents
19
19
 
@@ -71,14 +71,15 @@ Loading this module through a script tag will make the `BeeJs` object available
71
71
  ## Usage
72
72
 
73
73
  ```js
74
- import { Bee } from "@ethersphere/bee-js"
74
+ import { Bee, BeeDebug } from '@ethersphere/bee-js'
75
75
 
76
- bee = new Bee("http://localhost:1633")
76
+ const bee = new Bee('http://localhost:1633')
77
+ const beeDebug = new BeeDebug('http://localhost:1635')
77
78
 
78
79
  // Be aware, this creates on-chain transactions that spend Eth and BZZ!
79
- const batchId = await bee.createPostageBatch('100', 17)
80
- const fileHash = await bee.uploadData(batchId, "Bee is awesome!")
81
- const data = await bee.downloadData(fileHash)
80
+ const batchId = await bee.createPostageBatch('2000', 20)
81
+ const uploadResult = await bee.uploadData(batchId, "Bee is awesome!")
82
+ const data = await bee.downloadData(uploadResult.reference)
82
83
 
83
84
  console.log(data.text()) // prints 'Bee is awesome!'
84
85
  ```
@@ -105,6 +106,16 @@ Install project dependencies with
105
106
  npm i
106
107
  ```
107
108
 
109
+ ### Node 18
110
+
111
+ Node 18 came with its own fetch's native implementation called Undici. If you want to run bee-js tests under Node 18, then disable
112
+ the native's fetch implementation otherwise unit tests will fail as they capture HTTP calls with library called `nock` that does
113
+ not support native fetch yet.
114
+
115
+ ```
116
+ export NODE_OPTIONS='--no-experimental-fetch'
117
+ ```
118
+
108
119
  ### Test
109
120
 
110
121
  The tests run in both context: node and dom with Jest.
@@ -123,15 +134,7 @@ There are also browser tests by Puppeteer, which also provide integrity testing.
123
134
  npm run test:browser
124
135
  ```
125
136
  The test HTML file which Puppeteer uses is the [test/testpage/testpage.html](test/testpage/testpage.html).
126
- To open and manually test BeeJS with developer console, it is necessary to build the library first with `npm run build:browser` (running the browser tests `npm run test:browser` also builds the library).
127
-
128
- #### Node 18
129
-
130
- In order to run tests on Node 18 you have to disable the experimental Node's Udici/Fetch implementation. Use the `NODE_OPTIONS` env. variable like this:
131
-
132
- ```shell
133
- $ export NODE_OPTIONS='--experimental-vm-modules --no-experimental-fetch'
134
- ```
137
+ To open and manually test BeeJS with developer console, it is necessary to build the library first with `npm run compile:browser` (running the browser tests `npm run test:browser` also builds the library).
135
138
 
136
139
  ### Compile code
137
140
 
@@ -145,8 +148,6 @@ or for Browsers
145
148
 
146
149
  ## Maintainers
147
150
 
148
- - [auhau](https://github.com/auhau)
149
- - [vojtechsimetka](https://github.com/vojtechsimetka)
150
151
 
151
152
  ## License
152
153
 
@@ -0,0 +1,572 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.BeeDebug = void 0;
27
+ const balance = __importStar(require("./modules/debug/balance"));
28
+ const chequebook = __importStar(require("./modules/debug/chequebook"));
29
+ const connectivity = __importStar(require("./modules/debug/connectivity"));
30
+ const settlements = __importStar(require("./modules/debug/settlements"));
31
+ const stake = __importStar(require("./modules/debug/stake"));
32
+ const states = __importStar(require("./modules/debug/states"));
33
+ const status = __importStar(require("./modules/debug/status"));
34
+ const transactions = __importStar(require("./modules/debug/transactions"));
35
+ const cafe_utility_1 = require("cafe-utility");
36
+ const stamps = __importStar(require("./modules/debug/stamps"));
37
+ const tag = __importStar(require("./modules/debug/tag"));
38
+ const types_1 = require("./types");
39
+ const error_1 = require("./utils/error");
40
+ const type_1 = require("./utils/type");
41
+ const url_1 = require("./utils/url");
42
+ class BeeDebug {
43
+ constructor(url, options) {
44
+ (0, url_1.assertBeeUrl)(url);
45
+ // Remove last slash if present, as our endpoint strings starts with `/...`
46
+ // which could lead to double slash in URL to which Bee responds with
47
+ // unnecessary redirects.
48
+ this.url = (0, url_1.stripLastSlash)(url);
49
+ const requestOptions = {
50
+ baseURL: this.url,
51
+ timeout: options?.timeout ?? false,
52
+ };
53
+ if (options?.headers) {
54
+ requestOptions.headers = options.headers;
55
+ }
56
+ if (options?.onRequest) {
57
+ requestOptions.onRequest = options.onRequest;
58
+ }
59
+ this.requestOptions = requestOptions;
60
+ }
61
+ async getNodeAddresses(options) {
62
+ (0, type_1.assertRequestOptions)(options);
63
+ return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
64
+ }
65
+ async getBlocklist(options) {
66
+ (0, type_1.assertRequestOptions)(options);
67
+ return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
68
+ }
69
+ /**
70
+ * Retrieve tag extended information from Bee node
71
+ *
72
+ * @param tagUid UID or tag object to be retrieved
73
+ * @throws TypeError if tagUid is in not correct format
74
+ *
75
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
76
+ * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
77
+ *
78
+ */
79
+ async retrieveExtendedTag(tagUid, options) {
80
+ (0, type_1.assertRequestOptions)(options);
81
+ if ((0, type_1.isTag)(tagUid)) {
82
+ tagUid = tagUid.uid;
83
+ }
84
+ else if (typeof tagUid === 'number') {
85
+ (0, type_1.assertNonNegativeInteger)(tagUid, 'UID');
86
+ }
87
+ else {
88
+ throw new TypeError('tagUid has to be either Tag or a number (UID)!');
89
+ }
90
+ return tag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
91
+ }
92
+ /**
93
+ * Get list of peers for this node
94
+ */
95
+ async getPeers(options) {
96
+ (0, type_1.assertRequestOptions)(options);
97
+ return connectivity.getPeers(this.getRequestOptionsForCall(options));
98
+ }
99
+ async removePeer(peer, options) {
100
+ (0, type_1.assertRequestOptions)(options);
101
+ (0, type_1.assertAddress)(peer);
102
+ return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
103
+ }
104
+ async getTopology(options) {
105
+ (0, type_1.assertRequestOptions)(options);
106
+ return connectivity.getTopology(this.getRequestOptionsForCall(options));
107
+ }
108
+ async pingPeer(peer, options) {
109
+ (0, type_1.assertRequestOptions)(options);
110
+ (0, type_1.assertAddress)(peer);
111
+ return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
112
+ }
113
+ /*
114
+ * Balance endpoints
115
+ */
116
+ /**
117
+ * Get the balances with all known peers including prepaid services
118
+ */
119
+ async getAllBalances(options) {
120
+ (0, type_1.assertRequestOptions)(options);
121
+ return balance.getAllBalances(this.getRequestOptionsForCall(options));
122
+ }
123
+ /**
124
+ * Get the balances with a specific peer including prepaid services
125
+ *
126
+ * @param address Swarm address of peer
127
+ */
128
+ async getPeerBalance(address, options) {
129
+ (0, type_1.assertRequestOptions)(options);
130
+ (0, type_1.assertAddress)(address);
131
+ return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
132
+ }
133
+ /**
134
+ * Get the past due consumption balances with all known peers
135
+ */
136
+ async getPastDueConsumptionBalances(options) {
137
+ (0, type_1.assertRequestOptions)(options);
138
+ return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
139
+ }
140
+ /**
141
+ * Get the past due consumption balance with a specific peer
142
+ *
143
+ * @param address Swarm address of peer
144
+ */
145
+ async getPastDueConsumptionPeerBalance(address, options) {
146
+ (0, type_1.assertRequestOptions)(options);
147
+ (0, type_1.assertAddress)(address);
148
+ return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
149
+ }
150
+ /*
151
+ * Chequebook endpoints
152
+ */
153
+ /**
154
+ * Get the address of the chequebook contract used.
155
+ *
156
+ * **Warning:** The address is returned with 0x prefix unlike all other calls.
157
+ * https://github.com/ethersphere/bee/issues/1443
158
+ */
159
+ async getChequebookAddress(options) {
160
+ (0, type_1.assertRequestOptions)(options);
161
+ return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
162
+ }
163
+ /**
164
+ * Get the balance of the chequebook
165
+ */
166
+ async getChequebookBalance(options) {
167
+ (0, type_1.assertRequestOptions)(options);
168
+ return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
169
+ }
170
+ /**
171
+ * Get last cheques for all peers
172
+ */
173
+ async getLastCheques(options) {
174
+ (0, type_1.assertRequestOptions)(options);
175
+ return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
176
+ }
177
+ /**
178
+ * Get last cheques for the peer
179
+ *
180
+ * @param address Swarm address of peer
181
+ */
182
+ async getLastChequesForPeer(address, options) {
183
+ (0, type_1.assertRequestOptions)(options);
184
+ (0, type_1.assertAddress)(address);
185
+ return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
186
+ }
187
+ /**
188
+ * Get last cashout action for the peer
189
+ *
190
+ * @param address Swarm address of peer
191
+ */
192
+ async getLastCashoutAction(address, options) {
193
+ (0, type_1.assertRequestOptions)(options);
194
+ (0, type_1.assertAddress)(address);
195
+ return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
196
+ }
197
+ /**
198
+ * Cashout the last cheque for the peer
199
+ *
200
+ * @param address Swarm address of peer
201
+ * @param options
202
+ * @param options.gasPrice Gas price for the cashout transaction in WEI
203
+ * @param options.gasLimit Gas limit for the cashout transaction in WEI
204
+ */
205
+ async cashoutLastCheque(address, options, requestOptions) {
206
+ (0, type_1.assertCashoutOptions)(options);
207
+ (0, type_1.assertAddress)(address);
208
+ return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
209
+ }
210
+ /**
211
+ * Deposit tokens from overlay address into chequebook
212
+ *
213
+ * @param amount Amount of tokens to deposit (must be positive integer)
214
+ * @param gasPrice Gas Price in WEI for the transaction call
215
+ * @return string Hash of the transaction
216
+ */
217
+ async depositTokens(amount, gasPrice, options) {
218
+ (0, type_1.assertRequestOptions)(options);
219
+ (0, type_1.assertNonNegativeInteger)(amount);
220
+ if (gasPrice) {
221
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
222
+ }
223
+ return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
224
+ }
225
+ /**
226
+ * Withdraw tokens from the chequebook to the overlay address
227
+ *
228
+ * @param amount Amount of tokens to withdraw (must be positive integer)
229
+ * @param gasPrice Gas Price in WEI for the transaction call
230
+ * @return string Hash of the transaction
231
+ */
232
+ async withdrawTokens(amount, gasPrice, options) {
233
+ (0, type_1.assertRequestOptions)(options);
234
+ (0, type_1.assertNonNegativeInteger)(amount);
235
+ if (gasPrice) {
236
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
237
+ }
238
+ return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
239
+ }
240
+ /*
241
+ * Settlements endpoint
242
+ */
243
+ /**
244
+ * Get amount of sent and received from settlements with a peer
245
+ *
246
+ * @param address Swarm address of peer
247
+ */
248
+ async getSettlements(address, options) {
249
+ (0, type_1.assertRequestOptions)(options);
250
+ (0, type_1.assertAddress)(address);
251
+ return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
252
+ }
253
+ /**
254
+ * Get settlements with all known peers and total amount sent or received
255
+ */
256
+ async getAllSettlements(options) {
257
+ (0, type_1.assertRequestOptions)(options);
258
+ return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
259
+ }
260
+ /**
261
+ * Get health of node
262
+ */
263
+ async getHealth(options) {
264
+ (0, type_1.assertRequestOptions)(options);
265
+ return status.getHealth(this.getRequestOptionsForCall(options));
266
+ }
267
+ /**
268
+ * Get readiness of node
269
+ */
270
+ async getReadiness(options) {
271
+ (0, type_1.assertRequestOptions)(options);
272
+ return status.getReadiness(this.getRequestOptionsForCall(options));
273
+ }
274
+ /**
275
+ * Get mode information of node
276
+ */
277
+ async getNodeInfo(options) {
278
+ (0, type_1.assertRequestOptions)(options);
279
+ return status.getNodeInfo(this.getRequestOptionsForCall(options));
280
+ }
281
+ /**
282
+ * Connnects to a node and checks if it is a supported Bee version by the bee-js
283
+ *
284
+ * @returns true if the Bee node version is supported
285
+ * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
286
+ */
287
+ async isSupportedVersion(options) {
288
+ (0, type_1.assertRequestOptions)(options);
289
+ return status.isSupportedVersion(this.getRequestOptionsForCall(options));
290
+ }
291
+ /**
292
+ * Connects to a node and checks if its version matches with the one that bee-js supports.
293
+ *
294
+ * Be aware that this is the most strict version check and most probably
295
+ * you will want to use more relaxed API-versions based checks like
296
+ * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
297
+ * based on your use-case.
298
+ *
299
+ * @param options
300
+ */
301
+ async isSupportedExactVersion(options) {
302
+ (0, type_1.assertRequestOptions)(options);
303
+ return status.isSupportedExactVersion(this.getRequestOptionsForCall(options));
304
+ }
305
+ /**
306
+ * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
307
+ *
308
+ * This is useful if you are not using `BeeDebug` class (for anything else then this check)
309
+ * and want to make sure about compatibility.
310
+ *
311
+ * @param options
312
+ */
313
+ async isSupportedMainApiVersion(options) {
314
+ (0, type_1.assertRequestOptions)(options);
315
+ return status.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
316
+ }
317
+ /**
318
+ * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
319
+ *
320
+ * This is useful if you are not using `Bee` class in your application and want to make sure
321
+ * about compatibility.
322
+ *
323
+ * @param options
324
+ */
325
+ async isSupportedDebugApiVersion(options) {
326
+ (0, type_1.assertRequestOptions)(options);
327
+ return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
328
+ }
329
+ /**
330
+ *
331
+ * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
332
+ *
333
+ * This should be the main way how to check compatibility for your app and Bee node.
334
+ *
335
+ * @param options
336
+ */
337
+ async isSupportedApiVersion(options) {
338
+ (0, type_1.assertRequestOptions)(options);
339
+ return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
340
+ }
341
+ /**
342
+ * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
343
+ * and versions that bee-js supports (properties prefixed with `supported*`).
344
+ *
345
+ * @param options
346
+ */
347
+ async getVersions(options) {
348
+ (0, type_1.assertRequestOptions)(options);
349
+ return status.getVersions(this.getRequestOptionsForCall(options));
350
+ }
351
+ /**
352
+ * Get reserve state
353
+ */
354
+ async getReserveState(options) {
355
+ (0, type_1.assertRequestOptions)(options);
356
+ return states.getReserveState(this.getRequestOptionsForCall(options));
357
+ }
358
+ /**
359
+ * Get chain state
360
+ */
361
+ async getChainState(options) {
362
+ (0, type_1.assertRequestOptions)(options);
363
+ return states.getChainState(this.getRequestOptionsForCall(options));
364
+ }
365
+ /**
366
+ * Get wallet balances for xDai and BZZ of the Bee node
367
+ *
368
+ * @param options
369
+ */
370
+ async getWalletBalance(options) {
371
+ (0, type_1.assertRequestOptions)(options);
372
+ return states.getWalletBalance(this.getRequestOptionsForCall(options));
373
+ }
374
+ /**
375
+ * Creates new postage batch from the funds that the node has available in its Ethereum account.
376
+ *
377
+ * For better understanding what each parameter means and what are the optimal values please see
378
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
379
+ *
380
+ * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
381
+ *
382
+ * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
383
+ * @param depth Logarithm of the number of chunks that can be stamped with the batch.
384
+ * @param options Options for creation of postage batch
385
+ * @throws BeeArgumentError when negative amount or depth is specified
386
+ * @throws TypeError if non-integer value is passed to amount or depth
387
+ *
388
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
389
+ * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
390
+ */
391
+ async createPostageBatch(amount, depth, options, requestOptions) {
392
+ (0, type_1.assertPostageBatchOptions)(options);
393
+ (0, type_1.assertPositiveInteger)(amount);
394
+ (0, type_1.assertNonNegativeInteger)(depth);
395
+ if (depth < types_1.STAMPS_DEPTH_MIN) {
396
+ throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
397
+ }
398
+ if (depth > types_1.STAMPS_DEPTH_MAX) {
399
+ throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
400
+ }
401
+ const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
402
+ if (options?.waitForUsable !== false) {
403
+ await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
404
+ }
405
+ return stamp;
406
+ }
407
+ /**
408
+ * Topup a fresh amount of BZZ to given Postage Batch.
409
+ *
410
+ * For better understanding what each parameter means and what are the optimal values please see
411
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
412
+ *
413
+ * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
414
+ *
415
+ * @param postageBatchId Batch ID
416
+ * @param amount Amount to be added to the batch
417
+ * @param options Request options
418
+ *
419
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
420
+ * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
421
+ */
422
+ async topUpBatch(postageBatchId, amount, options) {
423
+ (0, type_1.assertRequestOptions)(options);
424
+ (0, type_1.assertNonNegativeInteger)(amount, 'Amount');
425
+ (0, type_1.assertBatchId)(postageBatchId);
426
+ await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
427
+ }
428
+ /**
429
+ * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
430
+ * the Postage Batch to be used for more chunks.
431
+ *
432
+ * For better understanding what each parameter means and what are the optimal values please see
433
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
434
+ *
435
+ * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
436
+ *
437
+ * @param postageBatchId Batch ID
438
+ * @param depth Amount to be added to the batch
439
+ * @param options Request options
440
+ *
441
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
442
+ * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
443
+ */
444
+ async diluteBatch(postageBatchId, depth, options) {
445
+ (0, type_1.assertRequestOptions)(options);
446
+ (0, type_1.assertNonNegativeInteger)(depth, 'Depth');
447
+ (0, type_1.assertBatchId)(postageBatchId);
448
+ await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
449
+ }
450
+ /**
451
+ * Return details for specific postage batch.
452
+ *
453
+ * @param postageBatchId Batch ID
454
+ *
455
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
456
+ * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
457
+ */
458
+ async getPostageBatch(postageBatchId, options) {
459
+ (0, type_1.assertRequestOptions)(options);
460
+ (0, type_1.assertBatchId)(postageBatchId);
461
+ return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
462
+ }
463
+ /**
464
+ * Return detailed information related to buckets for specific postage batch.
465
+ *
466
+ * @param postageBatchId Batch ID
467
+ *
468
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
469
+ * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
470
+ */
471
+ async getPostageBatchBuckets(postageBatchId, options) {
472
+ (0, type_1.assertRequestOptions)(options);
473
+ (0, type_1.assertBatchId)(postageBatchId);
474
+ return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
475
+ }
476
+ /**
477
+ * Return all postage batches that has the node available.
478
+ *
479
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
480
+ * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
481
+ */
482
+ async getAllPostageBatch(options) {
483
+ (0, type_1.assertRequestOptions)(options);
484
+ return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
485
+ }
486
+ /**
487
+ * Return lists of all current pending transactions that the Bee made
488
+ */
489
+ async getAllPendingTransactions(options) {
490
+ (0, type_1.assertRequestOptions)(options);
491
+ return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
492
+ }
493
+ /**
494
+ * Return transaction information for specific transaction
495
+ * @param transactionHash
496
+ */
497
+ async getPendingTransaction(transactionHash, options) {
498
+ (0, type_1.assertRequestOptions)(options);
499
+ (0, type_1.assertTransactionHash)(transactionHash);
500
+ return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
501
+ }
502
+ /**
503
+ * Rebroadcast already created transaction.
504
+ * This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
505
+ *
506
+ * @param transactionHash
507
+ */
508
+ async rebroadcastPendingTransaction(transactionHash, options) {
509
+ (0, type_1.assertRequestOptions)(options);
510
+ (0, type_1.assertTransactionHash)(transactionHash);
511
+ return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
512
+ }
513
+ /**
514
+ * Cancel currently pending transaction
515
+ * @param transactionHash
516
+ * @param gasPrice
517
+ */
518
+ async cancelPendingTransaction(transactionHash, gasPrice, options) {
519
+ (0, type_1.assertRequestOptions)(options);
520
+ (0, type_1.assertTransactionHash)(transactionHash);
521
+ if (gasPrice) {
522
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
523
+ }
524
+ return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
525
+ }
526
+ /**
527
+ * Gets the staked amount of BZZ (in PLUR unit) as number string.
528
+ *
529
+ * @param options
530
+ */
531
+ async getStake(options) {
532
+ (0, type_1.assertRequestOptions)(options);
533
+ return stake.getStake(this.getRequestOptionsForCall(options));
534
+ }
535
+ /**
536
+ * Deposits given amount of BZZ token (in PLUR unit).
537
+ *
538
+ * Be aware that staked BZZ tokens can **not** be withdrawn.
539
+ *
540
+ * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
541
+ * @param options
542
+ */
543
+ async depositStake(amount, options, requestOptions) {
544
+ (0, type_1.assertRequestOptions)(options);
545
+ (0, type_1.assertTransactionOptions)(options);
546
+ await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
547
+ }
548
+ /**
549
+ * Get current status of node in redistribution game
550
+ *
551
+ * @param options
552
+ */
553
+ async getRedistributionState(options) {
554
+ (0, type_1.assertRequestOptions)(options);
555
+ return stake.getRedistributionState(this.getRequestOptionsForCall(options));
556
+ }
557
+ async waitForUsablePostageStamp(id, timeout = 120000) {
558
+ const TIME_STEP = 1500;
559
+ for (let time = 0; time < timeout; time += TIME_STEP) {
560
+ const stamp = await this.getPostageBatch(id);
561
+ if (stamp.usable) {
562
+ return;
563
+ }
564
+ await cafe_utility_1.System.sleepMillis(TIME_STEP);
565
+ }
566
+ throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
567
+ }
568
+ getRequestOptionsForCall(options) {
569
+ return options ? cafe_utility_1.Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
570
+ }
571
+ }
572
+ exports.BeeDebug = BeeDebug;