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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +18 -17
  2. package/dist/cjs/bee-debug.js +569 -0
  3. package/dist/cjs/bee.js +873 -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 +30 -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 +101 -185
  67. package/dist/{src → mjs}/bee.js +81 -234
  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 +22 -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 +2 -5
  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 +45 -88
  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 +12 -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 -49
  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.12.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,569 @@
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
+ this.requestOptions = requestOptions;
57
+ }
58
+ async getNodeAddresses(options) {
59
+ (0, type_1.assertRequestOptions)(options);
60
+ return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
61
+ }
62
+ async getBlocklist(options) {
63
+ (0, type_1.assertRequestOptions)(options);
64
+ return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
65
+ }
66
+ /**
67
+ * Retrieve tag extended information from Bee node
68
+ *
69
+ * @param tagUid UID or tag object to be retrieved
70
+ * @throws TypeError if tagUid is in not correct format
71
+ *
72
+ * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
73
+ * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
74
+ *
75
+ */
76
+ async retrieveExtendedTag(tagUid, options) {
77
+ (0, type_1.assertRequestOptions)(options);
78
+ if ((0, type_1.isTag)(tagUid)) {
79
+ tagUid = tagUid.uid;
80
+ }
81
+ else if (typeof tagUid === 'number') {
82
+ (0, type_1.assertNonNegativeInteger)(tagUid, 'UID');
83
+ }
84
+ else {
85
+ throw new TypeError('tagUid has to be either Tag or a number (UID)!');
86
+ }
87
+ return tag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
88
+ }
89
+ /**
90
+ * Get list of peers for this node
91
+ */
92
+ async getPeers(options) {
93
+ (0, type_1.assertRequestOptions)(options);
94
+ return connectivity.getPeers(this.getRequestOptionsForCall(options));
95
+ }
96
+ async removePeer(peer, options) {
97
+ (0, type_1.assertRequestOptions)(options);
98
+ (0, type_1.assertAddress)(peer);
99
+ return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
100
+ }
101
+ async getTopology(options) {
102
+ (0, type_1.assertRequestOptions)(options);
103
+ return connectivity.getTopology(this.getRequestOptionsForCall(options));
104
+ }
105
+ async pingPeer(peer, options) {
106
+ (0, type_1.assertRequestOptions)(options);
107
+ (0, type_1.assertAddress)(peer);
108
+ return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
109
+ }
110
+ /*
111
+ * Balance endpoints
112
+ */
113
+ /**
114
+ * Get the balances with all known peers including prepaid services
115
+ */
116
+ async getAllBalances(options) {
117
+ (0, type_1.assertRequestOptions)(options);
118
+ return balance.getAllBalances(this.getRequestOptionsForCall(options));
119
+ }
120
+ /**
121
+ * Get the balances with a specific peer including prepaid services
122
+ *
123
+ * @param address Swarm address of peer
124
+ */
125
+ async getPeerBalance(address, options) {
126
+ (0, type_1.assertRequestOptions)(options);
127
+ (0, type_1.assertAddress)(address);
128
+ return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
129
+ }
130
+ /**
131
+ * Get the past due consumption balances with all known peers
132
+ */
133
+ async getPastDueConsumptionBalances(options) {
134
+ (0, type_1.assertRequestOptions)(options);
135
+ return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
136
+ }
137
+ /**
138
+ * Get the past due consumption balance with a specific peer
139
+ *
140
+ * @param address Swarm address of peer
141
+ */
142
+ async getPastDueConsumptionPeerBalance(address, options) {
143
+ (0, type_1.assertRequestOptions)(options);
144
+ (0, type_1.assertAddress)(address);
145
+ return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
146
+ }
147
+ /*
148
+ * Chequebook endpoints
149
+ */
150
+ /**
151
+ * Get the address of the chequebook contract used.
152
+ *
153
+ * **Warning:** The address is returned with 0x prefix unlike all other calls.
154
+ * https://github.com/ethersphere/bee/issues/1443
155
+ */
156
+ async getChequebookAddress(options) {
157
+ (0, type_1.assertRequestOptions)(options);
158
+ return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
159
+ }
160
+ /**
161
+ * Get the balance of the chequebook
162
+ */
163
+ async getChequebookBalance(options) {
164
+ (0, type_1.assertRequestOptions)(options);
165
+ return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
166
+ }
167
+ /**
168
+ * Get last cheques for all peers
169
+ */
170
+ async getLastCheques(options) {
171
+ (0, type_1.assertRequestOptions)(options);
172
+ return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
173
+ }
174
+ /**
175
+ * Get last cheques for the peer
176
+ *
177
+ * @param address Swarm address of peer
178
+ */
179
+ async getLastChequesForPeer(address, options) {
180
+ (0, type_1.assertRequestOptions)(options);
181
+ (0, type_1.assertAddress)(address);
182
+ return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
183
+ }
184
+ /**
185
+ * Get last cashout action for the peer
186
+ *
187
+ * @param address Swarm address of peer
188
+ */
189
+ async getLastCashoutAction(address, options) {
190
+ (0, type_1.assertRequestOptions)(options);
191
+ (0, type_1.assertAddress)(address);
192
+ return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
193
+ }
194
+ /**
195
+ * Cashout the last cheque for the peer
196
+ *
197
+ * @param address Swarm address of peer
198
+ * @param options
199
+ * @param options.gasPrice Gas price for the cashout transaction in WEI
200
+ * @param options.gasLimit Gas limit for the cashout transaction in WEI
201
+ */
202
+ async cashoutLastCheque(address, options, requestOptions) {
203
+ (0, type_1.assertCashoutOptions)(options);
204
+ (0, type_1.assertAddress)(address);
205
+ return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
206
+ }
207
+ /**
208
+ * Deposit tokens from overlay address into chequebook
209
+ *
210
+ * @param amount Amount of tokens to deposit (must be positive integer)
211
+ * @param gasPrice Gas Price in WEI for the transaction call
212
+ * @return string Hash of the transaction
213
+ */
214
+ async depositTokens(amount, gasPrice, options) {
215
+ (0, type_1.assertRequestOptions)(options);
216
+ (0, type_1.assertNonNegativeInteger)(amount);
217
+ if (gasPrice) {
218
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
219
+ }
220
+ return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
221
+ }
222
+ /**
223
+ * Withdraw tokens from the chequebook to the overlay address
224
+ *
225
+ * @param amount Amount of tokens to withdraw (must be positive integer)
226
+ * @param gasPrice Gas Price in WEI for the transaction call
227
+ * @return string Hash of the transaction
228
+ */
229
+ async withdrawTokens(amount, gasPrice, options) {
230
+ (0, type_1.assertRequestOptions)(options);
231
+ (0, type_1.assertNonNegativeInteger)(amount);
232
+ if (gasPrice) {
233
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
234
+ }
235
+ return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
236
+ }
237
+ /*
238
+ * Settlements endpoint
239
+ */
240
+ /**
241
+ * Get amount of sent and received from settlements with a peer
242
+ *
243
+ * @param address Swarm address of peer
244
+ */
245
+ async getSettlements(address, options) {
246
+ (0, type_1.assertRequestOptions)(options);
247
+ (0, type_1.assertAddress)(address);
248
+ return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
249
+ }
250
+ /**
251
+ * Get settlements with all known peers and total amount sent or received
252
+ */
253
+ async getAllSettlements(options) {
254
+ (0, type_1.assertRequestOptions)(options);
255
+ return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
256
+ }
257
+ /**
258
+ * Get health of node
259
+ */
260
+ async getHealth(options) {
261
+ (0, type_1.assertRequestOptions)(options);
262
+ return status.getHealth(this.getRequestOptionsForCall(options));
263
+ }
264
+ /**
265
+ * Get readiness of node
266
+ */
267
+ async getReadiness(options) {
268
+ (0, type_1.assertRequestOptions)(options);
269
+ return status.getReadiness(this.getRequestOptionsForCall(options));
270
+ }
271
+ /**
272
+ * Get mode information of node
273
+ */
274
+ async getNodeInfo(options) {
275
+ (0, type_1.assertRequestOptions)(options);
276
+ return status.getNodeInfo(this.getRequestOptionsForCall(options));
277
+ }
278
+ /**
279
+ * Connnects to a node and checks if it is a supported Bee version by the bee-js
280
+ *
281
+ * @returns true if the Bee node version is supported
282
+ * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
283
+ */
284
+ async isSupportedVersion(options) {
285
+ (0, type_1.assertRequestOptions)(options);
286
+ return status.isSupportedVersion(this.getRequestOptionsForCall(options));
287
+ }
288
+ /**
289
+ * Connects to a node and checks if its version matches with the one that bee-js supports.
290
+ *
291
+ * Be aware that this is the most strict version check and most probably
292
+ * you will want to use more relaxed API-versions based checks like
293
+ * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
294
+ * based on your use-case.
295
+ *
296
+ * @param options
297
+ */
298
+ async isSupportedExactVersion(options) {
299
+ (0, type_1.assertRequestOptions)(options);
300
+ return status.isSupportedExactVersion(this.getRequestOptionsForCall(options));
301
+ }
302
+ /**
303
+ * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
304
+ *
305
+ * This is useful if you are not using `BeeDebug` class (for anything else then this check)
306
+ * and want to make sure about compatibility.
307
+ *
308
+ * @param options
309
+ */
310
+ async isSupportedMainApiVersion(options) {
311
+ (0, type_1.assertRequestOptions)(options);
312
+ return status.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
313
+ }
314
+ /**
315
+ * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
316
+ *
317
+ * This is useful if you are not using `Bee` class in your application and want to make sure
318
+ * about compatibility.
319
+ *
320
+ * @param options
321
+ */
322
+ async isSupportedDebugApiVersion(options) {
323
+ (0, type_1.assertRequestOptions)(options);
324
+ return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
325
+ }
326
+ /**
327
+ *
328
+ * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
329
+ *
330
+ * This should be the main way how to check compatibility for your app and Bee node.
331
+ *
332
+ * @param options
333
+ */
334
+ async isSupportedApiVersion(options) {
335
+ (0, type_1.assertRequestOptions)(options);
336
+ return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
337
+ }
338
+ /**
339
+ * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
340
+ * and versions that bee-js supports (properties prefixed with `supported*`).
341
+ *
342
+ * @param options
343
+ */
344
+ async getVersions(options) {
345
+ (0, type_1.assertRequestOptions)(options);
346
+ return status.getVersions(this.getRequestOptionsForCall(options));
347
+ }
348
+ /**
349
+ * Get reserve state
350
+ */
351
+ async getReserveState(options) {
352
+ (0, type_1.assertRequestOptions)(options);
353
+ return states.getReserveState(this.getRequestOptionsForCall(options));
354
+ }
355
+ /**
356
+ * Get chain state
357
+ */
358
+ async getChainState(options) {
359
+ (0, type_1.assertRequestOptions)(options);
360
+ return states.getChainState(this.getRequestOptionsForCall(options));
361
+ }
362
+ /**
363
+ * Get wallet balances for xDai and BZZ of the Bee node
364
+ *
365
+ * @param options
366
+ */
367
+ async getWalletBalance(options) {
368
+ (0, type_1.assertRequestOptions)(options);
369
+ return states.getWalletBalance(this.getRequestOptionsForCall(options));
370
+ }
371
+ /**
372
+ * Creates new postage batch from the funds that the node has available in its Ethereum account.
373
+ *
374
+ * For better understanding what each parameter means and what are the optimal values please see
375
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
376
+ *
377
+ * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
378
+ *
379
+ * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
380
+ * @param depth Logarithm of the number of chunks that can be stamped with the batch.
381
+ * @param options Options for creation of postage batch
382
+ * @throws BeeArgumentError when negative amount or depth is specified
383
+ * @throws TypeError if non-integer value is passed to amount or depth
384
+ *
385
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
386
+ * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
387
+ */
388
+ async createPostageBatch(amount, depth, options, requestOptions) {
389
+ (0, type_1.assertPostageBatchOptions)(options);
390
+ (0, type_1.assertPositiveInteger)(amount);
391
+ (0, type_1.assertNonNegativeInteger)(depth);
392
+ if (depth < types_1.STAMPS_DEPTH_MIN) {
393
+ throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
394
+ }
395
+ if (depth > types_1.STAMPS_DEPTH_MAX) {
396
+ throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
397
+ }
398
+ const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
399
+ if (options?.waitForUsable !== false) {
400
+ await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
401
+ }
402
+ return stamp;
403
+ }
404
+ /**
405
+ * Topup a fresh amount of BZZ to given Postage Batch.
406
+ *
407
+ * For better understanding what each parameter means and what are the optimal values please see
408
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
409
+ *
410
+ * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
411
+ *
412
+ * @param postageBatchId Batch ID
413
+ * @param amount Amount to be added to the batch
414
+ * @param options Request options
415
+ *
416
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
417
+ * @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)
418
+ */
419
+ async topUpBatch(postageBatchId, amount, options) {
420
+ (0, type_1.assertRequestOptions)(options);
421
+ (0, type_1.assertNonNegativeInteger)(amount, 'Amount');
422
+ (0, type_1.assertBatchId)(postageBatchId);
423
+ await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
424
+ }
425
+ /**
426
+ * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
427
+ * the Postage Batch to be used for more chunks.
428
+ *
429
+ * For better understanding what each parameter means and what are the optimal values please see
430
+ * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
431
+ *
432
+ * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
433
+ *
434
+ * @param postageBatchId Batch ID
435
+ * @param depth Amount to be added to the batch
436
+ * @param options Request options
437
+ *
438
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
439
+ * @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)
440
+ */
441
+ async diluteBatch(postageBatchId, depth, options) {
442
+ (0, type_1.assertRequestOptions)(options);
443
+ (0, type_1.assertNonNegativeInteger)(depth, 'Depth');
444
+ (0, type_1.assertBatchId)(postageBatchId);
445
+ await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
446
+ }
447
+ /**
448
+ * Return details for specific postage batch.
449
+ *
450
+ * @param postageBatchId Batch ID
451
+ *
452
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
453
+ * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
454
+ */
455
+ async getPostageBatch(postageBatchId, options) {
456
+ (0, type_1.assertRequestOptions)(options);
457
+ (0, type_1.assertBatchId)(postageBatchId);
458
+ return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
459
+ }
460
+ /**
461
+ * Return detailed information related to buckets for specific postage batch.
462
+ *
463
+ * @param postageBatchId Batch ID
464
+ *
465
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
466
+ * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
467
+ */
468
+ async getPostageBatchBuckets(postageBatchId, options) {
469
+ (0, type_1.assertRequestOptions)(options);
470
+ (0, type_1.assertBatchId)(postageBatchId);
471
+ return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
472
+ }
473
+ /**
474
+ * Return all postage batches that has the node available.
475
+ *
476
+ * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
477
+ * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
478
+ */
479
+ async getAllPostageBatch(options) {
480
+ (0, type_1.assertRequestOptions)(options);
481
+ return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
482
+ }
483
+ /**
484
+ * Return lists of all current pending transactions that the Bee made
485
+ */
486
+ async getAllPendingTransactions(options) {
487
+ (0, type_1.assertRequestOptions)(options);
488
+ return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
489
+ }
490
+ /**
491
+ * Return transaction information for specific transaction
492
+ * @param transactionHash
493
+ */
494
+ async getPendingTransaction(transactionHash, options) {
495
+ (0, type_1.assertRequestOptions)(options);
496
+ (0, type_1.assertTransactionHash)(transactionHash);
497
+ return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
498
+ }
499
+ /**
500
+ * Rebroadcast already created transaction.
501
+ * This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
502
+ *
503
+ * @param transactionHash
504
+ */
505
+ async rebroadcastPendingTransaction(transactionHash, options) {
506
+ (0, type_1.assertRequestOptions)(options);
507
+ (0, type_1.assertTransactionHash)(transactionHash);
508
+ return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
509
+ }
510
+ /**
511
+ * Cancel currently pending transaction
512
+ * @param transactionHash
513
+ * @param gasPrice
514
+ */
515
+ async cancelPendingTransaction(transactionHash, gasPrice, options) {
516
+ (0, type_1.assertRequestOptions)(options);
517
+ (0, type_1.assertTransactionHash)(transactionHash);
518
+ if (gasPrice) {
519
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
520
+ }
521
+ return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
522
+ }
523
+ /**
524
+ * Gets the staked amount of BZZ (in PLUR unit) as number string.
525
+ *
526
+ * @param options
527
+ */
528
+ async getStake(options) {
529
+ (0, type_1.assertRequestOptions)(options);
530
+ return stake.getStake(this.getRequestOptionsForCall(options));
531
+ }
532
+ /**
533
+ * Deposits given amount of BZZ token (in PLUR unit).
534
+ *
535
+ * Be aware that staked BZZ tokens can **not** be withdrawn.
536
+ *
537
+ * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
538
+ * @param options
539
+ */
540
+ async depositStake(amount, options, requestOptions) {
541
+ (0, type_1.assertRequestOptions)(options);
542
+ (0, type_1.assertTransactionOptions)(options);
543
+ await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
544
+ }
545
+ /**
546
+ * Get current status of node in redistribution game
547
+ *
548
+ * @param options
549
+ */
550
+ async getRedistributionState(options) {
551
+ (0, type_1.assertRequestOptions)(options);
552
+ return stake.getRedistributionState(this.getRequestOptionsForCall(options));
553
+ }
554
+ async waitForUsablePostageStamp(id, timeout = 120000) {
555
+ const TIME_STEP = 1500;
556
+ for (let time = 0; time < timeout; time += TIME_STEP) {
557
+ const stamp = await this.getPostageBatch(id);
558
+ if (stamp.usable) {
559
+ return;
560
+ }
561
+ await cafe_utility_1.System.sleepMillis(TIME_STEP);
562
+ }
563
+ throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
564
+ }
565
+ getRequestOptionsForCall(options) {
566
+ return options ? cafe_utility_1.Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
567
+ }
568
+ }
569
+ exports.BeeDebug = BeeDebug;