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

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 +62 -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 +44 -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 -19
  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 -9
  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
@@ -1,59 +1,41 @@
1
- import * as connectivity from "./modules/debug/connectivity.js";
2
1
  import * as balance from "./modules/debug/balance.js";
3
2
  import * as chequebook from "./modules/debug/chequebook.js";
3
+ import * as connectivity from "./modules/debug/connectivity.js";
4
4
  import * as settlements from "./modules/debug/settlements.js";
5
+ import * as stake from "./modules/debug/stake.js";
6
+ import * as states from "./modules/debug/states.js";
5
7
  import * as status from "./modules/debug/status.js";
6
8
  import * as transactions from "./modules/debug/transactions.js";
7
- import * as states from "./modules/debug/states.js";
9
+ import { Objects, System } from 'cafe-utility';
10
+ import * as stamps from "./modules/debug/stamps.js";
11
+ import * as tag from "./modules/debug/tag.js";
12
+ import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
8
13
  import { BeeArgumentError, BeeError } from "./utils/error.js";
14
+ import { assertAddress, assertBatchId, assertCashoutOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertRequestOptions, assertTransactionHash, assertTransactionOptions, isTag } from "./utils/type.js";
9
15
  import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
10
- import { assertAddress, assertBatchId, assertCashoutOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertRequestOptions, assertTransactionHash, isTag } from "./utils/type.js";
11
- import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
12
- import * as tag from "./modules/debug/tag.js";
13
- import * as stamps from "./modules/debug/stamps.js";
14
- import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
15
- import { sleep } from "./utils/sleep.js";
16
16
  export class BeeDebug {
17
17
  constructor(url, options) {
18
- assertBeeUrl(url); // Remove last slash if present, as our endpoint strings starts with `/...`
18
+ assertBeeUrl(url);
19
+ // Remove last slash if present, as our endpoint strings starts with `/...`
19
20
  // which could lead to double slash in URL to which Bee responds with
20
21
  // unnecessary redirects.
21
-
22
22
  this.url = stripLastSlash(url);
23
- const kyOptions = {
24
- prefixUrl: this.url,
25
- timeout: options?.timeout ?? false,
26
- retry: options?.retry,
27
- fetch: options?.fetch,
28
- hooks: {
29
- beforeRequest: [],
30
- afterResponse: []
31
- }
23
+ const requestOptions = {
24
+ baseURL: this.url,
25
+ timeout: options?.timeout ?? false
32
26
  };
33
-
34
- if (options?.defaultHeaders) {
35
- kyOptions.headers = options.defaultHeaders;
36
- }
37
-
38
- if (options?.onRequest) {
39
- kyOptions.hooks.beforeRequest.push(wrapRequestClosure(options.onRequest));
40
- }
41
-
42
- if (options?.onResponse) {
43
- kyOptions.hooks.afterResponse.push(wrapResponseClosure(options.onResponse));
27
+ if (options?.headers) {
28
+ requestOptions.headers = options.headers;
44
29
  }
45
-
46
- this.ky = makeDefaultKy(kyOptions);
30
+ this.requestOptions = requestOptions;
47
31
  }
48
-
49
32
  async getNodeAddresses(options) {
50
33
  assertRequestOptions(options);
51
- return connectivity.getNodeAddresses(this.getKy(options));
34
+ return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
52
35
  }
53
-
54
36
  async getBlocklist(options) {
55
37
  assertRequestOptions(options);
56
- return connectivity.getBlocklist(this.getKy(options));
38
+ return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
57
39
  }
58
40
  /**
59
41
  * Retrieve tag extended information from Bee node
@@ -65,11 +47,8 @@ export class BeeDebug {
65
47
  * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
66
48
  *
67
49
  */
68
-
69
-
70
50
  async retrieveExtendedTag(tagUid, options) {
71
51
  assertRequestOptions(options);
72
-
73
52
  if (isTag(tagUid)) {
74
53
  tagUid = tagUid.uid;
75
54
  } else if (typeof tagUid === 'number') {
@@ -77,138 +56,112 @@ export class BeeDebug {
77
56
  } else {
78
57
  throw new TypeError('tagUid has to be either Tag or a number (UID)!');
79
58
  }
80
-
81
- return tag.retrieveExtendedTag(this.getKy(options), tagUid);
59
+ return tag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
82
60
  }
83
61
  /**
84
62
  * Get list of peers for this node
85
63
  */
86
-
87
-
88
64
  async getPeers(options) {
89
65
  assertRequestOptions(options);
90
- return connectivity.getPeers(this.getKy(options));
66
+ return connectivity.getPeers(this.getRequestOptionsForCall(options));
91
67
  }
92
-
93
68
  async removePeer(peer, options) {
94
69
  assertRequestOptions(options);
95
70
  assertAddress(peer);
96
- return connectivity.removePeer(this.getKy(options), peer);
71
+ return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
97
72
  }
98
-
99
73
  async getTopology(options) {
100
74
  assertRequestOptions(options);
101
- return connectivity.getTopology(this.getKy(options));
75
+ return connectivity.getTopology(this.getRequestOptionsForCall(options));
102
76
  }
103
-
104
77
  async pingPeer(peer, options) {
105
78
  assertRequestOptions(options);
106
79
  assertAddress(peer);
107
- return connectivity.pingPeer(this.getKy(options), peer);
80
+ return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
108
81
  }
109
82
  /*
110
83
  * Balance endpoints
111
84
  */
112
-
113
85
  /**
114
86
  * Get the balances with all known peers including prepaid services
115
87
  */
116
-
117
-
118
88
  async getAllBalances(options) {
119
89
  assertRequestOptions(options);
120
- return balance.getAllBalances(this.getKy(options));
90
+ return balance.getAllBalances(this.getRequestOptionsForCall(options));
121
91
  }
122
92
  /**
123
93
  * Get the balances with a specific peer including prepaid services
124
94
  *
125
95
  * @param address Swarm address of peer
126
96
  */
127
-
128
-
129
97
  async getPeerBalance(address, options) {
130
98
  assertRequestOptions(options);
131
99
  assertAddress(address);
132
- return balance.getPeerBalance(this.getKy(options), address);
100
+ return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
133
101
  }
134
102
  /**
135
103
  * Get the past due consumption balances with all known peers
136
104
  */
137
-
138
-
139
105
  async getPastDueConsumptionBalances(options) {
140
106
  assertRequestOptions(options);
141
- return balance.getPastDueConsumptionBalances(this.getKy(options));
107
+ return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
142
108
  }
143
109
  /**
144
110
  * Get the past due consumption balance with a specific peer
145
111
  *
146
112
  * @param address Swarm address of peer
147
113
  */
148
-
149
-
150
114
  async getPastDueConsumptionPeerBalance(address, options) {
151
115
  assertRequestOptions(options);
152
116
  assertAddress(address);
153
- return balance.getPastDueConsumptionPeerBalance(this.getKy(options), address);
117
+ return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
154
118
  }
155
119
  /*
156
120
  * Chequebook endpoints
157
121
  */
158
-
159
122
  /**
160
123
  * Get the address of the chequebook contract used.
161
124
  *
162
125
  * **Warning:** The address is returned with 0x prefix unlike all other calls.
163
126
  * https://github.com/ethersphere/bee/issues/1443
164
127
  */
165
-
166
-
167
128
  async getChequebookAddress(options) {
168
129
  assertRequestOptions(options);
169
- return chequebook.getChequebookAddress(this.getKy(options));
130
+ return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
170
131
  }
171
132
  /**
172
133
  * Get the balance of the chequebook
173
134
  */
174
-
175
-
176
135
  async getChequebookBalance(options) {
177
136
  assertRequestOptions(options);
178
- return chequebook.getChequebookBalance(this.getKy(options));
137
+ return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
179
138
  }
180
139
  /**
181
140
  * Get last cheques for all peers
182
141
  */
183
-
184
-
185
142
  async getLastCheques(options) {
186
143
  assertRequestOptions(options);
187
- return chequebook.getLastCheques(this.getKy(options));
144
+ return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
188
145
  }
189
146
  /**
190
147
  * Get last cheques for the peer
191
148
  *
192
149
  * @param address Swarm address of peer
193
150
  */
194
-
195
-
196
151
  async getLastChequesForPeer(address, options) {
197
152
  assertRequestOptions(options);
198
153
  assertAddress(address);
199
- return chequebook.getLastChequesForPeer(this.getKy(options), address);
154
+ return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
200
155
  }
201
156
  /**
202
157
  * Get last cashout action for the peer
203
158
  *
204
159
  * @param address Swarm address of peer
205
160
  */
206
-
207
-
208
161
  async getLastCashoutAction(address, options) {
209
162
  assertRequestOptions(options);
210
163
  assertAddress(address);
211
- return chequebook.getLastCashoutAction(this.getKy(options), address);
164
+ return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
212
165
  }
213
166
  /**
214
167
  * Cashout the last cheque for the peer
@@ -218,12 +171,10 @@ export class BeeDebug {
218
171
  * @param options.gasPrice Gas price for the cashout transaction in WEI
219
172
  * @param options.gasLimit Gas limit for the cashout transaction in WEI
220
173
  */
221
-
222
-
223
- async cashoutLastCheque(address, options) {
174
+ async cashoutLastCheque(address, options, requestOptions) {
224
175
  assertCashoutOptions(options);
225
176
  assertAddress(address);
226
- return chequebook.cashoutLastCheque(this.getKy(options), address, options);
177
+ return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
227
178
  }
228
179
  /**
229
180
  * Deposit tokens from overlay address into chequebook
@@ -232,17 +183,13 @@ export class BeeDebug {
232
183
  * @param gasPrice Gas Price in WEI for the transaction call
233
184
  * @return string Hash of the transaction
234
185
  */
235
-
236
-
237
186
  async depositTokens(amount, gasPrice, options) {
238
187
  assertRequestOptions(options);
239
188
  assertNonNegativeInteger(amount);
240
-
241
189
  if (gasPrice) {
242
190
  assertNonNegativeInteger(gasPrice);
243
191
  }
244
-
245
- return chequebook.depositTokens(this.getKy(options), amount, gasPrice);
192
+ return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
246
193
  }
247
194
  /**
248
195
  * Withdraw tokens from the chequebook to the overlay address
@@ -251,60 +198,54 @@ export class BeeDebug {
251
198
  * @param gasPrice Gas Price in WEI for the transaction call
252
199
  * @return string Hash of the transaction
253
200
  */
254
-
255
-
256
201
  async withdrawTokens(amount, gasPrice, options) {
257
202
  assertRequestOptions(options);
258
203
  assertNonNegativeInteger(amount);
259
-
260
204
  if (gasPrice) {
261
205
  assertNonNegativeInteger(gasPrice);
262
206
  }
263
-
264
- return chequebook.withdrawTokens(this.getKy(options), amount, gasPrice);
207
+ return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
265
208
  }
266
209
  /*
267
210
  * Settlements endpoint
268
211
  */
269
-
270
212
  /**
271
213
  * Get amount of sent and received from settlements with a peer
272
214
  *
273
215
  * @param address Swarm address of peer
274
216
  */
275
-
276
-
277
217
  async getSettlements(address, options) {
278
218
  assertRequestOptions(options);
279
219
  assertAddress(address);
280
- return settlements.getSettlements(this.getKy(options), address);
220
+ return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
281
221
  }
282
222
  /**
283
223
  * Get settlements with all known peers and total amount sent or received
284
224
  */
285
-
286
-
287
225
  async getAllSettlements(options) {
288
226
  assertRequestOptions(options);
289
- return settlements.getAllSettlements(this.getKy(options));
227
+ return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
290
228
  }
291
229
  /**
292
230
  * Get health of node
293
231
  */
294
-
295
-
296
232
  async getHealth(options) {
297
233
  assertRequestOptions(options);
298
- return status.getHealth(this.getKy(options));
234
+ return status.getHealth(this.getRequestOptionsForCall(options));
235
+ }
236
+ /**
237
+ * Get readiness of node
238
+ */
239
+ async getReadiness(options) {
240
+ assertRequestOptions(options);
241
+ return status.getReadiness(this.getRequestOptionsForCall(options));
299
242
  }
300
243
  /**
301
244
  * Get mode information of node
302
245
  */
303
-
304
-
305
246
  async getNodeInfo(options) {
306
247
  assertRequestOptions(options);
307
- return status.getNodeInfo(this.getKy(options));
248
+ return status.getNodeInfo(this.getRequestOptionsForCall(options));
308
249
  }
309
250
  /**
310
251
  * Connnects to a node and checks if it is a supported Bee version by the bee-js
@@ -312,11 +253,9 @@ export class BeeDebug {
312
253
  * @returns true if the Bee node version is supported
313
254
  * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
314
255
  */
315
-
316
-
317
256
  async isSupportedVersion(options) {
318
257
  assertRequestOptions(options);
319
- return status.isSupportedVersion(this.getKy(options));
258
+ return status.isSupportedVersion(this.getRequestOptionsForCall(options));
320
259
  }
321
260
  /**
322
261
  * Connects to a node and checks if its version matches with the one that bee-js supports.
@@ -328,11 +267,9 @@ export class BeeDebug {
328
267
  *
329
268
  * @param options
330
269
  */
331
-
332
-
333
270
  async isSupportedExactVersion(options) {
334
271
  assertRequestOptions(options);
335
- return status.isSupportedExactVersion(this.getKy(options));
272
+ return status.isSupportedExactVersion(this.getRequestOptionsForCall(options));
336
273
  }
337
274
  /**
338
275
  * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
@@ -342,11 +279,9 @@ export class BeeDebug {
342
279
  *
343
280
  * @param options
344
281
  */
345
-
346
-
347
282
  async isSupportedMainApiVersion(options) {
348
283
  assertRequestOptions(options);
349
- return status.isSupportedMainApiVersion(this.getKy(options));
284
+ return status.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
350
285
  }
351
286
  /**
352
287
  * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
@@ -356,11 +291,9 @@ export class BeeDebug {
356
291
  *
357
292
  * @param options
358
293
  */
359
-
360
-
361
294
  async isSupportedDebugApiVersion(options) {
362
295
  assertRequestOptions(options);
363
- return status.isSupportedDebugApiVersion(this.getKy(options));
296
+ return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
364
297
  }
365
298
  /**
366
299
  *
@@ -370,11 +303,9 @@ export class BeeDebug {
370
303
  *
371
304
  * @param options
372
305
  */
373
-
374
-
375
306
  async isSupportedApiVersion(options) {
376
307
  assertRequestOptions(options);
377
- return status.isSupportedDebugApiVersion(this.getKy(options));
308
+ return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
378
309
  }
379
310
  /**
380
311
  * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
@@ -382,40 +313,32 @@ export class BeeDebug {
382
313
  *
383
314
  * @param options
384
315
  */
385
-
386
-
387
316
  async getVersions(options) {
388
317
  assertRequestOptions(options);
389
- return status.getVersions(this.getKy(options));
318
+ return status.getVersions(this.getRequestOptionsForCall(options));
390
319
  }
391
320
  /**
392
321
  * Get reserve state
393
322
  */
394
-
395
-
396
323
  async getReserveState(options) {
397
324
  assertRequestOptions(options);
398
- return states.getReserveState(this.getKy(options));
325
+ return states.getReserveState(this.getRequestOptionsForCall(options));
399
326
  }
400
327
  /**
401
328
  * Get chain state
402
329
  */
403
-
404
-
405
330
  async getChainState(options) {
406
331
  assertRequestOptions(options);
407
- return states.getChainState(this.getKy(options));
332
+ return states.getChainState(this.getRequestOptionsForCall(options));
408
333
  }
409
334
  /**
410
335
  * Get wallet balances for xDai and BZZ of the Bee node
411
336
  *
412
337
  * @param options
413
338
  */
414
-
415
-
416
339
  async getWalletBalance(options) {
417
340
  assertRequestOptions(options);
418
- return states.getWalletBalance(this.getKy(options));
341
+ return states.getWalletBalance(this.getRequestOptionsForCall(options));
419
342
  }
420
343
  /**
421
344
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
@@ -434,27 +357,20 @@ export class BeeDebug {
434
357
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
435
358
  * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
436
359
  */
437
-
438
-
439
- async createPostageBatch(amount, depth, options) {
360
+ async createPostageBatch(amount, depth, options, requestOptions) {
440
361
  assertPostageBatchOptions(options);
441
362
  assertPositiveInteger(amount);
442
363
  assertNonNegativeInteger(depth);
443
-
444
364
  if (depth < STAMPS_DEPTH_MIN) {
445
365
  throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth);
446
366
  }
447
-
448
367
  if (depth > STAMPS_DEPTH_MAX) {
449
368
  throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth);
450
369
  }
451
-
452
- const stamp = await stamps.createPostageBatch(this.getKy(options), amount, depth, options);
453
-
370
+ const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
454
371
  if (options?.waitForUsable !== false) {
455
372
  await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
456
373
  }
457
-
458
374
  return stamp;
459
375
  }
460
376
  /**
@@ -472,13 +388,11 @@ export class BeeDebug {
472
388
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
473
389
  * @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)
474
390
  */
475
-
476
-
477
391
  async topUpBatch(postageBatchId, amount, options) {
478
392
  assertRequestOptions(options);
479
393
  assertNonNegativeInteger(amount, 'Amount');
480
394
  assertBatchId(postageBatchId);
481
- await stamps.topUpBatch(this.getKy(options), postageBatchId, amount);
395
+ await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
482
396
  }
483
397
  /**
484
398
  * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
@@ -496,13 +410,11 @@ export class BeeDebug {
496
410
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
497
411
  * @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)
498
412
  */
499
-
500
-
501
413
  async diluteBatch(postageBatchId, depth, options) {
502
414
  assertRequestOptions(options);
503
415
  assertNonNegativeInteger(depth, 'Depth');
504
416
  assertBatchId(postageBatchId);
505
- await stamps.diluteBatch(this.getKy(options), postageBatchId, depth);
417
+ await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
506
418
  }
507
419
  /**
508
420
  * Return details for specific postage batch.
@@ -512,12 +424,10 @@ export class BeeDebug {
512
424
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
513
425
  * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
514
426
  */
515
-
516
-
517
427
  async getPostageBatch(postageBatchId, options) {
518
428
  assertRequestOptions(options);
519
429
  assertBatchId(postageBatchId);
520
- return stamps.getPostageBatch(this.getKy(options), postageBatchId);
430
+ return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
521
431
  }
522
432
  /**
523
433
  * Return detailed information related to buckets for specific postage batch.
@@ -527,12 +437,10 @@ export class BeeDebug {
527
437
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
528
438
  * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
529
439
  */
530
-
531
-
532
440
  async getPostageBatchBuckets(postageBatchId, options) {
533
441
  assertRequestOptions(options);
534
442
  assertBatchId(postageBatchId);
535
- return stamps.getPostageBatchBuckets(this.getKy(options), postageBatchId);
443
+ return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
536
444
  }
537
445
  /**
538
446
  * Return all postage batches that has the node available.
@@ -540,31 +448,25 @@ export class BeeDebug {
540
448
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
541
449
  * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
542
450
  */
543
-
544
-
545
451
  async getAllPostageBatch(options) {
546
452
  assertRequestOptions(options);
547
- return stamps.getAllPostageBatches(this.getKy(options));
453
+ return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
548
454
  }
549
455
  /**
550
456
  * Return lists of all current pending transactions that the Bee made
551
457
  */
552
-
553
-
554
458
  async getAllPendingTransactions(options) {
555
459
  assertRequestOptions(options);
556
- return transactions.getAllTransactions(this.getKy(options));
460
+ return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
557
461
  }
558
462
  /**
559
463
  * Return transaction information for specific transaction
560
464
  * @param transactionHash
561
465
  */
562
-
563
-
564
466
  async getPendingTransaction(transactionHash, options) {
565
467
  assertRequestOptions(options);
566
468
  assertTransactionHash(transactionHash);
567
- return transactions.getTransaction(this.getKy(options), transactionHash);
469
+ return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
568
470
  }
569
471
  /**
570
472
  * Rebroadcast already created transaction.
@@ -572,53 +474,67 @@ export class BeeDebug {
572
474
  *
573
475
  * @param transactionHash
574
476
  */
575
-
576
-
577
477
  async rebroadcastPendingTransaction(transactionHash, options) {
578
478
  assertRequestOptions(options);
579
479
  assertTransactionHash(transactionHash);
580
- return transactions.rebroadcastTransaction(this.getKy(options), transactionHash);
480
+ return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
581
481
  }
582
482
  /**
583
483
  * Cancel currently pending transaction
584
484
  * @param transactionHash
585
485
  * @param gasPrice
586
486
  */
587
-
588
-
589
487
  async cancelPendingTransaction(transactionHash, gasPrice, options) {
590
488
  assertRequestOptions(options);
591
489
  assertTransactionHash(transactionHash);
592
-
593
490
  if (gasPrice) {
594
491
  assertNonNegativeInteger(gasPrice);
595
492
  }
596
-
597
- return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
493
+ return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
494
+ }
495
+ /**
496
+ * Gets the staked amount of BZZ (in PLUR unit) as number string.
497
+ *
498
+ * @param options
499
+ */
500
+ async getStake(options) {
501
+ assertRequestOptions(options);
502
+ return stake.getStake(this.getRequestOptionsForCall(options));
503
+ }
504
+ /**
505
+ * Deposits given amount of BZZ token (in PLUR unit).
506
+ *
507
+ * Be aware that staked BZZ tokens can **not** be withdrawn.
508
+ *
509
+ * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
510
+ * @param options
511
+ */
512
+ async depositStake(amount, options, requestOptions) {
513
+ assertRequestOptions(options);
514
+ assertTransactionOptions(options);
515
+ await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
516
+ }
517
+ /**
518
+ * Get current status of node in redistribution game
519
+ *
520
+ * @param options
521
+ */
522
+ async getRedistributionState(options) {
523
+ assertRequestOptions(options);
524
+ return stake.getRedistributionState(this.getRequestOptionsForCall(options));
598
525
  }
599
-
600
526
  async waitForUsablePostageStamp(id, timeout = 120000) {
601
527
  const TIME_STEP = 1500;
602
-
603
528
  for (let time = 0; time < timeout; time += TIME_STEP) {
604
529
  const stamp = await this.getPostageBatch(id);
605
-
606
530
  if (stamp.usable) {
607
531
  return;
608
532
  }
609
-
610
- await sleep(TIME_STEP);
533
+ await System.sleepMillis(TIME_STEP);
611
534
  }
612
-
613
535
  throw new BeeError('Timeout on waiting for postage stamp to become usable');
614
536
  }
615
-
616
- getKy(options) {
617
- if (!options) {
618
- return this.ky;
619
- }
620
-
621
- return this.ky.extend(options);
537
+ getRequestOptionsForCall(options) {
538
+ return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
622
539
  }
623
-
624
540
  }