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