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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/README.md +9 -1
  2. package/dist/index.browser.js +33 -0
  3. package/dist/index.browser.js.map +7 -0
  4. package/dist/src/bee-debug.js +624 -0
  5. package/dist/{mjs → src}/bee.js +243 -340
  6. package/dist/{mjs → src}/chunk/bmt.js +0 -0
  7. package/dist/{mjs → src}/chunk/cac.js +0 -0
  8. package/dist/{mjs → src}/chunk/serialize.js +0 -0
  9. package/dist/{mjs → src}/chunk/signer.js +13 -47
  10. package/dist/{mjs → src}/chunk/soc.js +31 -71
  11. package/dist/{mjs → src}/chunk/span.js +1 -1
  12. package/dist/{mjs → src}/feed/identifier.js +0 -0
  13. package/dist/src/feed/index.js +92 -0
  14. package/dist/src/feed/json.js +27 -0
  15. package/dist/src/feed/retrievable.js +67 -0
  16. package/dist/{mjs → src}/feed/topic.js +0 -0
  17. package/dist/{mjs → src}/feed/type.js +0 -0
  18. package/dist/{mjs → src}/index.js +1 -2
  19. package/dist/src/modules/bytes.js +59 -0
  20. package/dist/src/modules/bzz.js +122 -0
  21. package/dist/src/modules/chunk.js +45 -0
  22. package/dist/src/modules/debug/balance.js +57 -0
  23. package/dist/src/modules/debug/chequebook.js +150 -0
  24. package/dist/src/modules/debug/chunk.js +35 -0
  25. package/dist/src/modules/debug/connectivity.js +45 -0
  26. package/dist/src/modules/debug/settlements.js +29 -0
  27. package/dist/src/modules/debug/stamps.js +64 -0
  28. package/dist/src/modules/debug/states.js +46 -0
  29. package/dist/src/modules/debug/status.js +134 -0
  30. package/dist/src/modules/debug/tag.js +16 -0
  31. package/dist/src/modules/debug/transactions.js +69 -0
  32. package/dist/src/modules/feed.js +67 -0
  33. package/dist/src/modules/pinning.js +60 -0
  34. package/dist/src/modules/pss.js +40 -0
  35. package/dist/src/modules/soc.js +31 -0
  36. package/dist/src/modules/status.js +12 -0
  37. package/dist/src/modules/stewardship.js +24 -0
  38. package/dist/src/modules/tag.js +77 -0
  39. package/dist/{mjs → src}/types/debug.js +0 -0
  40. package/dist/{mjs → src}/types/index.js +0 -0
  41. package/dist/{mjs → src}/utils/bytes.js +3 -2
  42. package/dist/src/utils/collection-browser.js +19 -0
  43. package/dist/src/utils/collection-node.js +74 -0
  44. package/dist/src/utils/collection.js +64 -0
  45. package/dist/src/utils/data.browser.js +72 -0
  46. package/dist/src/utils/data.js +42 -0
  47. package/dist/{mjs → src}/utils/error.js +0 -0
  48. package/dist/{mjs → src}/utils/eth.js +32 -68
  49. package/dist/{mjs → src}/utils/expose.js +1 -1
  50. package/dist/src/utils/file.js +36 -0
  51. package/dist/{mjs → src}/utils/hash.js +0 -0
  52. package/dist/{mjs → src}/utils/headers.js +4 -4
  53. package/dist/{mjs → src}/utils/hex.js +0 -0
  54. package/dist/src/utils/http.js +162 -0
  55. package/dist/{mjs → src}/utils/merge.js +2 -2
  56. package/dist/{mjs → src}/utils/pss.js +0 -0
  57. package/dist/{mjs → src}/utils/reference.js +0 -0
  58. package/dist/src/utils/sleep.js +8 -0
  59. package/dist/{mjs → src}/utils/stamps.js +0 -0
  60. package/dist/{mjs → src}/utils/stream.js +3 -3
  61. package/dist/{mjs → src}/utils/tar.js +0 -0
  62. package/dist/{mjs → src}/utils/type.js +12 -13
  63. package/dist/{mjs → src}/utils/uint64.js +0 -0
  64. package/dist/{mjs → src}/utils/url.js +0 -0
  65. package/dist/types/chunk/bmt.d.ts +1 -1
  66. package/dist/types/chunk/soc.d.ts +1 -1
  67. package/dist/types/chunk/span.d.ts +1 -1
  68. package/dist/types/feed/index.d.ts +1 -1
  69. package/dist/types/index.d.ts +0 -13
  70. package/dist/types/modules/bzz.d.ts +1 -1
  71. package/dist/types/types/index.d.ts +8 -8
  72. package/dist/types/utils/{collection.browser.d.ts → collection-browser.d.ts} +0 -0
  73. package/dist/types/utils/{collection.node.d.ts → collection-node.d.ts} +0 -0
  74. package/dist/types/utils/error.d.ts +1 -1
  75. package/dist/types/utils/eth.d.ts +3 -3
  76. package/dist/types/utils/expose.d.ts +7 -4
  77. package/dist/types/utils/hash.d.ts +1 -1
  78. package/dist/types/utils/hex.d.ts +2 -2
  79. package/dist/types/utils/http.d.ts +3 -3
  80. package/dist/types/utils/stream.d.ts +1 -1
  81. package/dist/types/utils/uint64.d.ts +1 -1
  82. package/package.json +44 -59
  83. package/dist/cjs/bee-debug.js +0 -642
  84. package/dist/cjs/bee.js +0 -983
  85. package/dist/cjs/chunk/bmt.js +0 -55
  86. package/dist/cjs/chunk/cac.js +0 -56
  87. package/dist/cjs/chunk/serialize.js +0 -19
  88. package/dist/cjs/chunk/signer.js +0 -137
  89. package/dist/cjs/chunk/soc.js +0 -176
  90. package/dist/cjs/chunk/span.js +0 -29
  91. package/dist/cjs/feed/identifier.js +0 -35
  92. package/dist/cjs/feed/index.js +0 -132
  93. package/dist/cjs/feed/json.js +0 -41
  94. package/dist/cjs/feed/retrievable.js +0 -72
  95. package/dist/cjs/feed/topic.js +0 -25
  96. package/dist/cjs/feed/type.js +0 -15
  97. package/dist/cjs/index.js +0 -39
  98. package/dist/cjs/modules/bytes.js +0 -74
  99. package/dist/cjs/modules/bzz.js +0 -131
  100. package/dist/cjs/modules/chunk.js +0 -58
  101. package/dist/cjs/modules/debug/balance.js +0 -77
  102. package/dist/cjs/modules/debug/chequebook.js +0 -167
  103. package/dist/cjs/modules/debug/chunk.js +0 -51
  104. package/dist/cjs/modules/debug/connectivity.js +0 -75
  105. package/dist/cjs/modules/debug/settlements.js +0 -45
  106. package/dist/cjs/modules/debug/stamps.js +0 -89
  107. package/dist/cjs/modules/debug/states.js +0 -64
  108. package/dist/cjs/modules/debug/status.js +0 -153
  109. package/dist/cjs/modules/debug/tag.js +0 -30
  110. package/dist/cjs/modules/debug/transactions.js +0 -81
  111. package/dist/cjs/modules/feed.js +0 -76
  112. package/dist/cjs/modules/pinning.js +0 -80
  113. package/dist/cjs/modules/pss.js +0 -55
  114. package/dist/cjs/modules/soc.js +0 -40
  115. package/dist/cjs/modules/status.js +0 -26
  116. package/dist/cjs/modules/stewardship.js +0 -41
  117. package/dist/cjs/modules/tag.js +0 -96
  118. package/dist/cjs/package.json +0 -8
  119. package/dist/cjs/types/debug.js +0 -10
  120. package/dist/cjs/types/index.js +0 -51
  121. package/dist/cjs/types/ky-options.js +0 -8
  122. package/dist/cjs/types/ky-universal/common.js +0 -8
  123. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  124. package/dist/cjs/types/ky-universal/retry.js +0 -8
  125. package/dist/cjs/utils/bytes.js +0 -121
  126. package/dist/cjs/utils/collection.browser.js +0 -36
  127. package/dist/cjs/utils/collection.js +0 -70
  128. package/dist/cjs/utils/collection.node.js +0 -115
  129. package/dist/cjs/utils/data.browser.js +0 -74
  130. package/dist/cjs/utils/data.js +0 -58
  131. package/dist/cjs/utils/error.js +0 -50
  132. package/dist/cjs/utils/eth.js +0 -211
  133. package/dist/cjs/utils/expose.js +0 -44
  134. package/dist/cjs/utils/file.js +0 -49
  135. package/dist/cjs/utils/hash.js +0 -21
  136. package/dist/cjs/utils/headers.js +0 -59
  137. package/dist/cjs/utils/hex.js +0 -150
  138. package/dist/cjs/utils/http.js +0 -172
  139. package/dist/cjs/utils/merge.js +0 -34
  140. package/dist/cjs/utils/pss.js +0 -18
  141. package/dist/cjs/utils/reference.js +0 -36
  142. package/dist/cjs/utils/sleep.js +0 -23
  143. package/dist/cjs/utils/stamps.js +0 -17
  144. package/dist/cjs/utils/stream.js +0 -146
  145. package/dist/cjs/utils/tar.js +0 -25
  146. package/dist/cjs/utils/type.js +0 -426
  147. package/dist/cjs/utils/uint64.js +0 -29
  148. package/dist/cjs/utils/url.js +0 -56
  149. package/dist/index.browser.min.js +0 -3
  150. package/dist/index.browser.min.js.LICENSE.txt +0 -60
  151. package/dist/index.browser.min.js.map +0 -1
  152. package/dist/mjs/bee-debug.js +0 -744
  153. package/dist/mjs/feed/index.js +0 -134
  154. package/dist/mjs/feed/json.js +0 -63
  155. package/dist/mjs/feed/retrievable.js +0 -105
  156. package/dist/mjs/modules/bytes.js +0 -96
  157. package/dist/mjs/modules/bzz.js +0 -160
  158. package/dist/mjs/modules/chunk.js +0 -80
  159. package/dist/mjs/modules/debug/balance.js +0 -97
  160. package/dist/mjs/modules/debug/chequebook.js +0 -198
  161. package/dist/mjs/modules/debug/chunk.js +0 -71
  162. package/dist/mjs/modules/debug/connectivity.js +0 -89
  163. package/dist/mjs/modules/debug/settlements.js +0 -65
  164. package/dist/mjs/modules/debug/stamps.js +0 -108
  165. package/dist/mjs/modules/debug/states.js +0 -84
  166. package/dist/mjs/modules/debug/status.js +0 -182
  167. package/dist/mjs/modules/debug/tag.js +0 -50
  168. package/dist/mjs/modules/debug/transactions.js +0 -103
  169. package/dist/mjs/modules/feed.js +0 -101
  170. package/dist/mjs/modules/pinning.js +0 -100
  171. package/dist/mjs/modules/pss.js +0 -74
  172. package/dist/mjs/modules/soc.js +0 -64
  173. package/dist/mjs/modules/status.js +0 -46
  174. package/dist/mjs/modules/stewardship.js +0 -60
  175. package/dist/mjs/modules/tag.js +0 -119
  176. package/dist/mjs/package.json +0 -8
  177. package/dist/mjs/types/ky-options.js +0 -7
  178. package/dist/mjs/types/ky-universal/common.js +0 -7
  179. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  180. package/dist/mjs/types/ky-universal/retry.js +0 -7
  181. package/dist/mjs/utils/collection.browser.js +0 -56
  182. package/dist/mjs/utils/collection.js +0 -98
  183. package/dist/mjs/utils/collection.node.js +0 -169
  184. package/dist/mjs/utils/data.browser.js +0 -108
  185. package/dist/mjs/utils/data.js +0 -78
  186. package/dist/mjs/utils/file.js +0 -70
  187. package/dist/mjs/utils/http.js +0 -208
  188. package/dist/mjs/utils/sleep.js +0 -43
  189. package/dist/types/types/ky-options.d.ts +0 -221
  190. package/dist/types/types/ky-universal/common.d.ts +0 -13
  191. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  192. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,642 +0,0 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.BeeDebug = void 0;
36
- const connectivity = __importStar(require("./modules/debug/connectivity"));
37
- const balance = __importStar(require("./modules/debug/balance"));
38
- const chequebook = __importStar(require("./modules/debug/chequebook"));
39
- const settlements = __importStar(require("./modules/debug/settlements"));
40
- const status = __importStar(require("./modules/debug/status"));
41
- const transactions = __importStar(require("./modules/debug/transactions"));
42
- const states = __importStar(require("./modules/debug/states"));
43
- const error_1 = require("./utils/error");
44
- const url_1 = require("./utils/url");
45
- const type_1 = require("./utils/type");
46
- const types_1 = require("./types");
47
- const tag = __importStar(require("./modules/debug/tag"));
48
- const stamps = __importStar(require("./modules/debug/stamps"));
49
- const http_1 = require("./utils/http");
50
- const sleep_1 = require("./utils/sleep");
51
- class BeeDebug {
52
- constructor(url, options) {
53
- var _a;
54
- (0, url_1.assertBeeUrl)(url);
55
- // Remove last slash if present, as our endpoint strings starts with `/...`
56
- // which could lead to double slash in URL to which Bee responds with
57
- // unnecessary redirects.
58
- this.url = (0, url_1.stripLastSlash)(url);
59
- const kyOptions = {
60
- prefixUrl: this.url,
61
- timeout: (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : false,
62
- retry: options === null || options === void 0 ? void 0 : options.retry,
63
- fetch: options === null || options === void 0 ? void 0 : options.fetch,
64
- hooks: {
65
- beforeRequest: [],
66
- afterResponse: [],
67
- },
68
- };
69
- if (options === null || options === void 0 ? void 0 : options.defaultHeaders) {
70
- kyOptions.headers = options.defaultHeaders;
71
- }
72
- if (options === null || options === void 0 ? void 0 : options.onRequest) {
73
- kyOptions.hooks.beforeRequest.push((0, http_1.wrapRequestClosure)(options.onRequest));
74
- }
75
- if (options === null || options === void 0 ? void 0 : options.onResponse) {
76
- kyOptions.hooks.afterResponse.push((0, http_1.wrapResponseClosure)(options.onResponse));
77
- }
78
- this.ky = (0, http_1.makeDefaultKy)(kyOptions);
79
- }
80
- getNodeAddresses(options) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- (0, type_1.assertRequestOptions)(options);
83
- return connectivity.getNodeAddresses(this.getKy(options));
84
- });
85
- }
86
- getBlocklist(options) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- (0, type_1.assertRequestOptions)(options);
89
- return connectivity.getBlocklist(this.getKy(options));
90
- });
91
- }
92
- /**
93
- * Retrieve tag extended information from Bee node
94
- *
95
- * @param tagUid UID or tag object to be retrieved
96
- * @throws TypeError if tagUid is in not correct format
97
- *
98
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
99
- * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
100
- *
101
- */
102
- retrieveExtendedTag(tagUid, options) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- (0, type_1.assertRequestOptions)(options);
105
- if ((0, type_1.isTag)(tagUid)) {
106
- tagUid = tagUid.uid;
107
- }
108
- else if (typeof tagUid === 'number') {
109
- (0, type_1.assertNonNegativeInteger)(tagUid, 'UID');
110
- }
111
- else {
112
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
113
- }
114
- return tag.retrieveExtendedTag(this.getKy(options), tagUid);
115
- });
116
- }
117
- /**
118
- * Get list of peers for this node
119
- */
120
- getPeers(options) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- (0, type_1.assertRequestOptions)(options);
123
- return connectivity.getPeers(this.getKy(options));
124
- });
125
- }
126
- removePeer(peer, options) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- (0, type_1.assertRequestOptions)(options);
129
- (0, type_1.assertAddress)(peer);
130
- return connectivity.removePeer(this.getKy(options), peer);
131
- });
132
- }
133
- getTopology(options) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- (0, type_1.assertRequestOptions)(options);
136
- return connectivity.getTopology(this.getKy(options));
137
- });
138
- }
139
- pingPeer(peer, options) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- (0, type_1.assertRequestOptions)(options);
142
- (0, type_1.assertAddress)(peer);
143
- return connectivity.pingPeer(this.getKy(options), peer);
144
- });
145
- }
146
- /*
147
- * Balance endpoints
148
- */
149
- /**
150
- * Get the balances with all known peers including prepaid services
151
- */
152
- getAllBalances(options) {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- (0, type_1.assertRequestOptions)(options);
155
- return balance.getAllBalances(this.getKy(options));
156
- });
157
- }
158
- /**
159
- * Get the balances with a specific peer including prepaid services
160
- *
161
- * @param address Swarm address of peer
162
- */
163
- getPeerBalance(address, options) {
164
- return __awaiter(this, void 0, void 0, function* () {
165
- (0, type_1.assertRequestOptions)(options);
166
- (0, type_1.assertAddress)(address);
167
- return balance.getPeerBalance(this.getKy(options), address);
168
- });
169
- }
170
- /**
171
- * Get the past due consumption balances with all known peers
172
- */
173
- getPastDueConsumptionBalances(options) {
174
- return __awaiter(this, void 0, void 0, function* () {
175
- (0, type_1.assertRequestOptions)(options);
176
- return balance.getPastDueConsumptionBalances(this.getKy(options));
177
- });
178
- }
179
- /**
180
- * Get the past due consumption balance with a specific peer
181
- *
182
- * @param address Swarm address of peer
183
- */
184
- getPastDueConsumptionPeerBalance(address, options) {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- (0, type_1.assertRequestOptions)(options);
187
- (0, type_1.assertAddress)(address);
188
- return balance.getPastDueConsumptionPeerBalance(this.getKy(options), address);
189
- });
190
- }
191
- /*
192
- * Chequebook endpoints
193
- */
194
- /**
195
- * Get the address of the chequebook contract used.
196
- *
197
- * **Warning:** The address is returned with 0x prefix unlike all other calls.
198
- * https://github.com/ethersphere/bee/issues/1443
199
- */
200
- getChequebookAddress(options) {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- (0, type_1.assertRequestOptions)(options);
203
- return chequebook.getChequebookAddress(this.getKy(options));
204
- });
205
- }
206
- /**
207
- * Get the balance of the chequebook
208
- */
209
- getChequebookBalance(options) {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- (0, type_1.assertRequestOptions)(options);
212
- return chequebook.getChequebookBalance(this.getKy(options));
213
- });
214
- }
215
- /**
216
- * Get last cheques for all peers
217
- */
218
- getLastCheques(options) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- (0, type_1.assertRequestOptions)(options);
221
- return chequebook.getLastCheques(this.getKy(options));
222
- });
223
- }
224
- /**
225
- * Get last cheques for the peer
226
- *
227
- * @param address Swarm address of peer
228
- */
229
- getLastChequesForPeer(address, options) {
230
- return __awaiter(this, void 0, void 0, function* () {
231
- (0, type_1.assertRequestOptions)(options);
232
- (0, type_1.assertAddress)(address);
233
- return chequebook.getLastChequesForPeer(this.getKy(options), address);
234
- });
235
- }
236
- /**
237
- * Get last cashout action for the peer
238
- *
239
- * @param address Swarm address of peer
240
- */
241
- getLastCashoutAction(address, options) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- (0, type_1.assertRequestOptions)(options);
244
- (0, type_1.assertAddress)(address);
245
- return chequebook.getLastCashoutAction(this.getKy(options), address);
246
- });
247
- }
248
- /**
249
- * Cashout the last cheque for the peer
250
- *
251
- * @param address Swarm address of peer
252
- * @param options
253
- * @param options.gasPrice Gas price for the cashout transaction in WEI
254
- * @param options.gasLimit Gas limit for the cashout transaction in WEI
255
- */
256
- cashoutLastCheque(address, options) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- (0, type_1.assertCashoutOptions)(options);
259
- (0, type_1.assertAddress)(address);
260
- return chequebook.cashoutLastCheque(this.getKy(options), address, options);
261
- });
262
- }
263
- /**
264
- * Deposit tokens from overlay address into chequebook
265
- *
266
- * @param amount Amount of tokens to deposit (must be positive integer)
267
- * @param gasPrice Gas Price in WEI for the transaction call
268
- * @return string Hash of the transaction
269
- */
270
- depositTokens(amount, gasPrice, options) {
271
- return __awaiter(this, void 0, void 0, function* () {
272
- (0, type_1.assertRequestOptions)(options);
273
- (0, type_1.assertNonNegativeInteger)(amount);
274
- if (gasPrice) {
275
- (0, type_1.assertNonNegativeInteger)(gasPrice);
276
- }
277
- return chequebook.depositTokens(this.getKy(options), amount, gasPrice);
278
- });
279
- }
280
- /**
281
- * Withdraw tokens from the chequebook to the overlay address
282
- *
283
- * @param amount Amount of tokens to withdraw (must be positive integer)
284
- * @param gasPrice Gas Price in WEI for the transaction call
285
- * @return string Hash of the transaction
286
- */
287
- withdrawTokens(amount, gasPrice, options) {
288
- return __awaiter(this, void 0, void 0, function* () {
289
- (0, type_1.assertRequestOptions)(options);
290
- (0, type_1.assertNonNegativeInteger)(amount);
291
- if (gasPrice) {
292
- (0, type_1.assertNonNegativeInteger)(gasPrice);
293
- }
294
- return chequebook.withdrawTokens(this.getKy(options), amount, gasPrice);
295
- });
296
- }
297
- /*
298
- * Settlements endpoint
299
- */
300
- /**
301
- * Get amount of sent and received from settlements with a peer
302
- *
303
- * @param address Swarm address of peer
304
- */
305
- getSettlements(address, options) {
306
- return __awaiter(this, void 0, void 0, function* () {
307
- (0, type_1.assertRequestOptions)(options);
308
- (0, type_1.assertAddress)(address);
309
- return settlements.getSettlements(this.getKy(options), address);
310
- });
311
- }
312
- /**
313
- * Get settlements with all known peers and total amount sent or received
314
- */
315
- getAllSettlements(options) {
316
- return __awaiter(this, void 0, void 0, function* () {
317
- (0, type_1.assertRequestOptions)(options);
318
- return settlements.getAllSettlements(this.getKy(options));
319
- });
320
- }
321
- /**
322
- * Get health of node
323
- */
324
- getHealth(options) {
325
- return __awaiter(this, void 0, void 0, function* () {
326
- (0, type_1.assertRequestOptions)(options);
327
- return status.getHealth(this.getKy(options));
328
- });
329
- }
330
- /**
331
- * Get mode information of node
332
- */
333
- getNodeInfo(options) {
334
- return __awaiter(this, void 0, void 0, function* () {
335
- (0, type_1.assertRequestOptions)(options);
336
- return status.getNodeInfo(this.getKy(options));
337
- });
338
- }
339
- /**
340
- * Connnects to a node and checks if it is a supported Bee version by the bee-js
341
- *
342
- * @returns true if the Bee node version is supported
343
- * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
344
- */
345
- isSupportedVersion(options) {
346
- return __awaiter(this, void 0, void 0, function* () {
347
- (0, type_1.assertRequestOptions)(options);
348
- return status.isSupportedVersion(this.getKy(options));
349
- });
350
- }
351
- /**
352
- * Connects to a node and checks if its version matches with the one that bee-js supports.
353
- *
354
- * Be aware that this is the most strict version check and most probably
355
- * you will want to use more relaxed API-versions based checks like
356
- * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
357
- * based on your use-case.
358
- *
359
- * @param options
360
- */
361
- isSupportedExactVersion(options) {
362
- return __awaiter(this, void 0, void 0, function* () {
363
- (0, type_1.assertRequestOptions)(options);
364
- return status.isSupportedExactVersion(this.getKy(options));
365
- });
366
- }
367
- /**
368
- * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
369
- *
370
- * This is useful if you are not using `BeeDebug` class (for anything else then this check)
371
- * and want to make sure about compatibility.
372
- *
373
- * @param options
374
- */
375
- isSupportedMainApiVersion(options) {
376
- return __awaiter(this, void 0, void 0, function* () {
377
- (0, type_1.assertRequestOptions)(options);
378
- return status.isSupportedMainApiVersion(this.getKy(options));
379
- });
380
- }
381
- /**
382
- * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
383
- *
384
- * This is useful if you are not using `Bee` class in your application and want to make sure
385
- * about compatibility.
386
- *
387
- * @param options
388
- */
389
- isSupportedDebugApiVersion(options) {
390
- return __awaiter(this, void 0, void 0, function* () {
391
- (0, type_1.assertRequestOptions)(options);
392
- return status.isSupportedDebugApiVersion(this.getKy(options));
393
- });
394
- }
395
- /**
396
- *
397
- * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
398
- *
399
- * This should be the main way how to check compatibility for your app and Bee node.
400
- *
401
- * @param options
402
- */
403
- isSupportedApiVersion(options) {
404
- return __awaiter(this, void 0, void 0, function* () {
405
- (0, type_1.assertRequestOptions)(options);
406
- return status.isSupportedDebugApiVersion(this.getKy(options));
407
- });
408
- }
409
- /**
410
- * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
411
- * and versions that bee-js supports (properties prefixed with `supported*`).
412
- *
413
- * @param options
414
- */
415
- getVersions(options) {
416
- return __awaiter(this, void 0, void 0, function* () {
417
- (0, type_1.assertRequestOptions)(options);
418
- return status.getVersions(this.getKy(options));
419
- });
420
- }
421
- /**
422
- * Get reserve state
423
- */
424
- getReserveState(options) {
425
- return __awaiter(this, void 0, void 0, function* () {
426
- (0, type_1.assertRequestOptions)(options);
427
- return states.getReserveState(this.getKy(options));
428
- });
429
- }
430
- /**
431
- * Get chain state
432
- */
433
- getChainState(options) {
434
- return __awaiter(this, void 0, void 0, function* () {
435
- (0, type_1.assertRequestOptions)(options);
436
- return states.getChainState(this.getKy(options));
437
- });
438
- }
439
- /**
440
- * Get wallet balances for xDai and BZZ of the Bee node
441
- *
442
- * @param options
443
- */
444
- getWalletBalance(options) {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- (0, type_1.assertRequestOptions)(options);
447
- return states.getWalletBalance(this.getKy(options));
448
- });
449
- }
450
- /**
451
- * Creates new postage batch from the funds that the node has available in its Ethereum account.
452
- *
453
- * For better understanding what each parameter means and what are the optimal values please see
454
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
455
- *
456
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
457
- *
458
- * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
459
- * @param depth Logarithm of the number of chunks that can be stamped with the batch.
460
- * @param options Options for creation of postage batch
461
- * @throws BeeArgumentError when negative amount or depth is specified
462
- * @throws TypeError if non-integer value is passed to amount or depth
463
- *
464
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
465
- * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
466
- */
467
- createPostageBatch(amount, depth, options) {
468
- return __awaiter(this, void 0, void 0, function* () {
469
- (0, type_1.assertPostageBatchOptions)(options);
470
- (0, type_1.assertPositiveInteger)(amount);
471
- (0, type_1.assertNonNegativeInteger)(depth);
472
- if (depth < types_1.STAMPS_DEPTH_MIN) {
473
- throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
474
- }
475
- if (depth > types_1.STAMPS_DEPTH_MAX) {
476
- throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
477
- }
478
- const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
479
- if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== false) {
480
- yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
481
- }
482
- return stamp;
483
- });
484
- }
485
- /**
486
- * Topup a fresh amount of BZZ to given Postage Batch.
487
- *
488
- * For better understanding what each parameter means and what are the optimal values please see
489
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
490
- *
491
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
492
- *
493
- * @param postageBatchId Batch ID
494
- * @param amount Amount to be added to the batch
495
- * @param options Request options
496
- *
497
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
498
- * @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)
499
- */
500
- topUpBatch(postageBatchId, amount, options) {
501
- return __awaiter(this, void 0, void 0, function* () {
502
- (0, type_1.assertRequestOptions)(options);
503
- (0, type_1.assertNonNegativeInteger)(amount, 'Amount');
504
- (0, type_1.assertBatchId)(postageBatchId);
505
- yield stamps.topUpBatch(this.getKy(options), postageBatchId, amount);
506
- });
507
- }
508
- /**
509
- * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
510
- * the Postage Batch to be used for more chunks.
511
- *
512
- * For better understanding what each parameter means and what are the optimal values please see
513
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
514
- *
515
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
516
- *
517
- * @param postageBatchId Batch ID
518
- * @param depth Amount to be added to the batch
519
- * @param options Request options
520
- *
521
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
522
- * @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)
523
- */
524
- diluteBatch(postageBatchId, depth, options) {
525
- return __awaiter(this, void 0, void 0, function* () {
526
- (0, type_1.assertRequestOptions)(options);
527
- (0, type_1.assertNonNegativeInteger)(depth, 'Depth');
528
- (0, type_1.assertBatchId)(postageBatchId);
529
- yield stamps.diluteBatch(this.getKy(options), postageBatchId, depth);
530
- });
531
- }
532
- /**
533
- * Return details for specific postage batch.
534
- *
535
- * @param postageBatchId Batch ID
536
- *
537
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
538
- * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
539
- */
540
- getPostageBatch(postageBatchId, options) {
541
- return __awaiter(this, void 0, void 0, function* () {
542
- (0, type_1.assertRequestOptions)(options);
543
- (0, type_1.assertBatchId)(postageBatchId);
544
- return stamps.getPostageBatch(this.getKy(options), postageBatchId);
545
- });
546
- }
547
- /**
548
- * Return detailed information related to buckets for specific postage batch.
549
- *
550
- * @param postageBatchId Batch ID
551
- *
552
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
553
- * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
554
- */
555
- getPostageBatchBuckets(postageBatchId, options) {
556
- return __awaiter(this, void 0, void 0, function* () {
557
- (0, type_1.assertRequestOptions)(options);
558
- (0, type_1.assertBatchId)(postageBatchId);
559
- return stamps.getPostageBatchBuckets(this.getKy(options), postageBatchId);
560
- });
561
- }
562
- /**
563
- * Return all postage batches that has the node available.
564
- *
565
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
566
- * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
567
- */
568
- getAllPostageBatch(options) {
569
- return __awaiter(this, void 0, void 0, function* () {
570
- (0, type_1.assertRequestOptions)(options);
571
- return stamps.getAllPostageBatches(this.getKy(options));
572
- });
573
- }
574
- /**
575
- * Return lists of all current pending transactions that the Bee made
576
- */
577
- getAllPendingTransactions(options) {
578
- return __awaiter(this, void 0, void 0, function* () {
579
- (0, type_1.assertRequestOptions)(options);
580
- return transactions.getAllTransactions(this.getKy(options));
581
- });
582
- }
583
- /**
584
- * Return transaction information for specific transaction
585
- * @param transactionHash
586
- */
587
- getPendingTransaction(transactionHash, options) {
588
- return __awaiter(this, void 0, void 0, function* () {
589
- (0, type_1.assertRequestOptions)(options);
590
- (0, type_1.assertTransactionHash)(transactionHash);
591
- return transactions.getTransaction(this.getKy(options), transactionHash);
592
- });
593
- }
594
- /**
595
- * Rebroadcast already created transaction.
596
- * This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
597
- *
598
- * @param transactionHash
599
- */
600
- rebroadcastPendingTransaction(transactionHash, options) {
601
- return __awaiter(this, void 0, void 0, function* () {
602
- (0, type_1.assertRequestOptions)(options);
603
- (0, type_1.assertTransactionHash)(transactionHash);
604
- return transactions.rebroadcastTransaction(this.getKy(options), transactionHash);
605
- });
606
- }
607
- /**
608
- * Cancel currently pending transaction
609
- * @param transactionHash
610
- * @param gasPrice
611
- */
612
- cancelPendingTransaction(transactionHash, gasPrice, options) {
613
- return __awaiter(this, void 0, void 0, function* () {
614
- (0, type_1.assertRequestOptions)(options);
615
- (0, type_1.assertTransactionHash)(transactionHash);
616
- if (gasPrice) {
617
- (0, type_1.assertNonNegativeInteger)(gasPrice);
618
- }
619
- return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
620
- });
621
- }
622
- waitForUsablePostageStamp(id, timeout = 120000) {
623
- return __awaiter(this, void 0, void 0, function* () {
624
- const TIME_STEP = 1500;
625
- for (let time = 0; time < timeout; time += TIME_STEP) {
626
- const stamp = yield this.getPostageBatch(id);
627
- if (stamp.usable) {
628
- return;
629
- }
630
- yield (0, sleep_1.sleep)(TIME_STEP);
631
- }
632
- throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
633
- });
634
- }
635
- getKy(options) {
636
- if (!options) {
637
- return this.ky;
638
- }
639
- return this.ky.extend(options);
640
- }
641
- }
642
- exports.BeeDebug = BeeDebug;