@ethersphere/bee-js 4.0.0 → 4.1.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 (199) hide show
  1. package/README.md +3 -14
  2. package/dist/cjs/{bee-debug.js → src/bee-debug.js} +31 -8
  3. package/dist/cjs/{bee.js → src/bee.js} +12 -10
  4. package/dist/cjs/{chunk → src/chunk}/bmt.js +0 -0
  5. package/dist/cjs/{chunk → src/chunk}/cac.js +0 -0
  6. package/dist/cjs/{chunk → src/chunk}/serialize.js +0 -0
  7. package/dist/cjs/{chunk → src/chunk}/signer.js +0 -0
  8. package/dist/cjs/{chunk → src/chunk}/soc.js +0 -0
  9. package/dist/cjs/{chunk → src/chunk}/span.js +0 -0
  10. package/dist/cjs/{feed → src/feed}/identifier.js +0 -0
  11. package/dist/cjs/{feed → src/feed}/index.js +0 -0
  12. package/dist/cjs/{feed → src/feed}/json.js +0 -0
  13. package/dist/cjs/{feed → src/feed}/retrievable.js +0 -0
  14. package/dist/cjs/{feed → src/feed}/topic.js +0 -0
  15. package/dist/cjs/{feed → src/feed}/type.js +0 -0
  16. package/dist/cjs/{index.js → src/index.js} +0 -0
  17. package/dist/cjs/{modules → src/modules}/bytes.js +0 -0
  18. package/dist/cjs/{modules → src/modules}/bzz.js +0 -0
  19. package/dist/cjs/{modules → src/modules}/chunk.js +0 -0
  20. package/dist/cjs/{modules → src/modules}/debug/balance.js +0 -0
  21. package/dist/cjs/{modules → src/modules}/debug/chequebook.js +0 -0
  22. package/dist/cjs/{modules → src/modules}/debug/chunk.js +0 -0
  23. package/dist/cjs/{modules → src/modules}/debug/connectivity.js +0 -0
  24. package/dist/cjs/{modules → src/modules}/debug/settlements.js +0 -0
  25. package/dist/cjs/{modules → src/modules}/debug/stamps.js +0 -0
  26. package/dist/cjs/{modules → src/modules}/debug/states.js +18 -1
  27. package/dist/cjs/{modules → src/modules}/debug/status.js +0 -0
  28. package/dist/cjs/{modules → src/modules}/debug/tag.js +0 -0
  29. package/dist/cjs/{modules → src/modules}/debug/transactions.js +0 -0
  30. package/dist/cjs/{modules → src/modules}/feed.js +0 -0
  31. package/dist/cjs/{modules → src/modules}/pinning.js +0 -0
  32. package/dist/cjs/{modules → src/modules}/pss.js +0 -0
  33. package/dist/cjs/{modules → src/modules}/soc.js +0 -0
  34. package/dist/cjs/{modules → src/modules}/status.js +0 -0
  35. package/dist/cjs/{modules → src/modules}/stewardship.js +0 -0
  36. package/dist/cjs/{modules → src/modules}/tag.js +0 -0
  37. package/dist/cjs/{types → src/types}/debug.js +0 -0
  38. package/dist/cjs/{types → src/types}/index.js +0 -0
  39. package/dist/cjs/{types → src/types}/ky-options.js +0 -0
  40. package/dist/cjs/{types → src/types}/ky-universal/common.js +0 -0
  41. package/dist/cjs/{types → src/types}/ky-universal/hooks.js +0 -0
  42. package/dist/cjs/{types → src/types}/ky-universal/retry.js +0 -0
  43. package/dist/cjs/{utils → src/utils}/bytes.js +0 -0
  44. package/dist/cjs/{utils → src/utils}/collection.browser.js +0 -0
  45. package/dist/cjs/{utils → src/utils}/collection.js +0 -0
  46. package/dist/cjs/{utils → src/utils}/collection.node.js +0 -0
  47. package/dist/cjs/{utils → src/utils}/data.browser.js +0 -0
  48. package/dist/cjs/{utils → src/utils}/data.js +0 -0
  49. package/dist/cjs/{utils → src/utils}/error.js +0 -0
  50. package/dist/cjs/{utils → src/utils}/eth.js +0 -0
  51. package/dist/cjs/{utils → src/utils}/expose.js +0 -0
  52. package/dist/cjs/{utils → src/utils}/file.js +0 -0
  53. package/dist/cjs/{utils → src/utils}/hash.js +0 -0
  54. package/dist/cjs/{utils → src/utils}/headers.js +0 -0
  55. package/dist/cjs/{utils → src/utils}/hex.js +0 -0
  56. package/dist/cjs/{utils → src/utils}/http.js +6 -0
  57. package/dist/cjs/{utils → src/utils}/merge.js +0 -0
  58. package/dist/cjs/{utils → src/utils}/pss.js +0 -0
  59. package/dist/cjs/{utils → src/utils}/reference.js +0 -0
  60. package/dist/cjs/{utils → src/utils}/stamps.js +0 -0
  61. package/dist/cjs/{utils → src/utils}/stream.js +0 -0
  62. package/dist/cjs/{utils → src/utils}/tar.js +0 -0
  63. package/dist/cjs/{utils → src/utils}/type.js +66 -2
  64. package/dist/cjs/{utils → src/utils}/uint64.js +0 -0
  65. package/dist/cjs/{utils → src/utils}/url.js +0 -0
  66. package/dist/cjs/test/utils.js +419 -0
  67. package/dist/index.browser.min.js +1 -1
  68. package/dist/index.browser.min.js.map +1 -1
  69. package/dist/mjs/{bee-debug.js → src/bee-debug.js} +40 -10
  70. package/dist/mjs/{bee.js → src/bee.js} +15 -13
  71. package/dist/mjs/{chunk → src/chunk}/bmt.js +0 -0
  72. package/dist/mjs/{chunk → src/chunk}/cac.js +0 -0
  73. package/dist/mjs/{chunk → src/chunk}/serialize.js +0 -0
  74. package/dist/mjs/{chunk → src/chunk}/signer.js +0 -0
  75. package/dist/mjs/{chunk → src/chunk}/soc.js +0 -0
  76. package/dist/mjs/{chunk → src/chunk}/span.js +0 -0
  77. package/dist/mjs/{feed → src/feed}/identifier.js +0 -0
  78. package/dist/mjs/{feed → src/feed}/index.js +0 -0
  79. package/dist/mjs/{feed → src/feed}/json.js +0 -0
  80. package/dist/mjs/{feed → src/feed}/retrievable.js +0 -0
  81. package/dist/mjs/{feed → src/feed}/topic.js +0 -0
  82. package/dist/mjs/{feed → src/feed}/type.js +0 -0
  83. package/dist/mjs/{index.js → src/index.js} +0 -0
  84. package/dist/mjs/{modules → src/modules}/bytes.js +0 -0
  85. package/dist/mjs/{modules → src/modules}/bzz.js +0 -0
  86. package/dist/mjs/{modules → src/modules}/chunk.js +0 -0
  87. package/dist/mjs/{modules → src/modules}/debug/balance.js +0 -0
  88. package/dist/mjs/{modules → src/modules}/debug/chequebook.js +0 -0
  89. package/dist/mjs/{modules → src/modules}/debug/chunk.js +0 -0
  90. package/dist/mjs/{modules → src/modules}/debug/connectivity.js +0 -0
  91. package/dist/mjs/{modules → src/modules}/debug/settlements.js +0 -0
  92. package/dist/mjs/{modules → src/modules}/debug/stamps.js +0 -0
  93. package/dist/mjs/{modules → src/modules}/debug/states.js +17 -0
  94. package/dist/mjs/{modules → src/modules}/debug/status.js +0 -0
  95. package/dist/mjs/{modules → src/modules}/debug/tag.js +0 -0
  96. package/dist/mjs/{modules → src/modules}/debug/transactions.js +0 -0
  97. package/dist/mjs/{modules → src/modules}/feed.js +0 -0
  98. package/dist/mjs/{modules → src/modules}/pinning.js +0 -0
  99. package/dist/mjs/{modules → src/modules}/pss.js +0 -0
  100. package/dist/mjs/{modules → src/modules}/soc.js +0 -0
  101. package/dist/mjs/{modules → src/modules}/status.js +0 -0
  102. package/dist/mjs/{modules → src/modules}/stewardship.js +0 -0
  103. package/dist/mjs/{modules → src/modules}/tag.js +0 -0
  104. package/dist/mjs/{types → src/types}/debug.js +0 -0
  105. package/dist/mjs/{types → src/types}/index.js +0 -0
  106. package/dist/mjs/{types → src/types}/ky-options.js +0 -0
  107. package/dist/mjs/{types → src/types}/ky-universal/common.js +0 -0
  108. package/dist/mjs/{types → src/types}/ky-universal/hooks.js +0 -0
  109. package/dist/mjs/{types → src/types}/ky-universal/retry.js +0 -0
  110. package/dist/mjs/{utils → src/utils}/bytes.js +0 -0
  111. package/dist/mjs/{utils → src/utils}/collection.browser.js +0 -0
  112. package/dist/mjs/{utils → src/utils}/collection.js +0 -0
  113. package/dist/mjs/{utils → src/utils}/collection.node.js +0 -0
  114. package/dist/mjs/{utils → src/utils}/data.browser.js +0 -0
  115. package/dist/mjs/{utils → src/utils}/data.js +0 -0
  116. package/dist/mjs/{utils → src/utils}/error.js +0 -0
  117. package/dist/mjs/{utils → src/utils}/eth.js +0 -0
  118. package/dist/mjs/{utils → src/utils}/expose.js +0 -0
  119. package/dist/mjs/{utils → src/utils}/file.js +0 -0
  120. package/dist/mjs/{utils → src/utils}/hash.js +0 -0
  121. package/dist/mjs/{utils → src/utils}/headers.js +0 -0
  122. package/dist/mjs/{utils → src/utils}/hex.js +0 -0
  123. package/dist/mjs/{utils → src/utils}/http.js +7 -0
  124. package/dist/mjs/{utils → src/utils}/merge.js +0 -0
  125. package/dist/mjs/{utils → src/utils}/pss.js +0 -0
  126. package/dist/mjs/{utils → src/utils}/reference.js +0 -0
  127. package/dist/mjs/{utils → src/utils}/stamps.js +0 -0
  128. package/dist/mjs/{utils → src/utils}/stream.js +0 -0
  129. package/dist/mjs/{utils → src/utils}/tar.js +0 -0
  130. package/dist/mjs/{utils → src/utils}/type.js +72 -2
  131. package/dist/mjs/{utils → src/utils}/uint64.js +0 -0
  132. package/dist/mjs/{utils → src/utils}/url.js +0 -0
  133. package/dist/mjs/test/utils.js +458 -0
  134. package/dist/types/{bee-debug.d.ts → src/bee-debug.d.ts} +8 -1
  135. package/dist/types/{bee.d.ts → src/bee.d.ts} +11 -10
  136. package/dist/types/{chunk → src/chunk}/bmt.d.ts +0 -0
  137. package/dist/types/{chunk → src/chunk}/cac.d.ts +0 -0
  138. package/dist/types/{chunk → src/chunk}/serialize.d.ts +0 -0
  139. package/dist/types/{chunk → src/chunk}/signer.d.ts +0 -0
  140. package/dist/types/{chunk → src/chunk}/soc.d.ts +0 -0
  141. package/dist/types/{chunk → src/chunk}/span.d.ts +0 -0
  142. package/dist/types/{feed → src/feed}/identifier.d.ts +0 -0
  143. package/dist/types/{feed → src/feed}/index.d.ts +0 -0
  144. package/dist/types/{feed → src/feed}/json.d.ts +0 -0
  145. package/dist/types/{feed → src/feed}/retrievable.d.ts +0 -0
  146. package/dist/types/{feed → src/feed}/topic.d.ts +0 -0
  147. package/dist/types/{feed → src/feed}/type.d.ts +0 -0
  148. package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
  149. package/dist/types/{modules → src/modules}/bytes.d.ts +0 -0
  150. package/dist/types/{modules → src/modules}/bzz.d.ts +0 -0
  151. package/dist/types/{modules → src/modules}/chunk.d.ts +0 -0
  152. package/dist/types/{modules → src/modules}/debug/balance.d.ts +0 -0
  153. package/dist/types/{modules → src/modules}/debug/chequebook.d.ts +0 -0
  154. package/dist/types/{modules → src/modules}/debug/chunk.d.ts +0 -0
  155. package/dist/types/{modules → src/modules}/debug/connectivity.d.ts +0 -0
  156. package/dist/types/{modules → src/modules}/debug/settlements.d.ts +0 -0
  157. package/dist/types/{modules → src/modules}/debug/stamps.d.ts +0 -0
  158. package/dist/types/{modules → src/modules}/debug/states.d.ts +7 -1
  159. package/dist/types/{modules → src/modules}/debug/status.d.ts +0 -0
  160. package/dist/types/{modules → src/modules}/debug/tag.d.ts +0 -0
  161. package/dist/types/{modules → src/modules}/debug/transactions.d.ts +0 -0
  162. package/dist/types/{modules → src/modules}/feed.d.ts +0 -0
  163. package/dist/types/{modules → src/modules}/pinning.d.ts +0 -0
  164. package/dist/types/{modules → src/modules}/pss.d.ts +0 -0
  165. package/dist/types/{modules → src/modules}/soc.d.ts +0 -0
  166. package/dist/types/{modules → src/modules}/status.d.ts +0 -0
  167. package/dist/types/{modules → src/modules}/stewardship.d.ts +0 -0
  168. package/dist/types/{modules → src/modules}/tag.d.ts +0 -0
  169. package/dist/types/{types → src/types}/debug.d.ts +18 -0
  170. package/dist/types/{types → src/types}/index.d.ts +23 -1
  171. package/dist/types/{types → src/types}/ky-options.d.ts +0 -0
  172. package/dist/types/{types → src/types}/ky-universal/common.d.ts +0 -0
  173. package/dist/types/{types → src/types}/ky-universal/hooks.d.ts +0 -0
  174. package/dist/types/{types → src/types}/ky-universal/retry.d.ts +0 -0
  175. package/dist/types/{utils → src/utils}/bytes.d.ts +0 -0
  176. package/dist/types/{utils → src/utils}/collection.browser.d.ts +0 -0
  177. package/dist/types/{utils → src/utils}/collection.d.ts +0 -0
  178. package/dist/types/{utils → src/utils}/collection.node.d.ts +0 -0
  179. package/dist/types/{utils → src/utils}/data.browser.d.ts +0 -0
  180. package/dist/types/{utils → src/utils}/data.d.ts +0 -0
  181. package/dist/types/{utils → src/utils}/error.d.ts +0 -0
  182. package/dist/types/{utils → src/utils}/eth.d.ts +0 -0
  183. package/dist/types/{utils → src/utils}/expose.d.ts +0 -0
  184. package/dist/types/{utils → src/utils}/file.d.ts +0 -0
  185. package/dist/types/{utils → src/utils}/hash.d.ts +0 -0
  186. package/dist/types/{utils → src/utils}/headers.d.ts +0 -0
  187. package/dist/types/{utils → src/utils}/hex.d.ts +0 -0
  188. package/dist/types/{utils → src/utils}/http.d.ts +0 -0
  189. package/dist/types/{utils → src/utils}/merge.d.ts +0 -0
  190. package/dist/types/{utils → src/utils}/pss.d.ts +0 -0
  191. package/dist/types/{utils → src/utils}/reference.d.ts +0 -0
  192. package/dist/types/{utils → src/utils}/stamps.d.ts +0 -0
  193. package/dist/types/{utils → src/utils}/stream.d.ts +0 -0
  194. package/dist/types/{utils → src/utils}/tar.d.ts +0 -0
  195. package/dist/types/{utils → src/utils}/type.d.ts +16 -1
  196. package/dist/types/{utils → src/utils}/uint64.d.ts +0 -0
  197. package/dist/types/{utils → src/utils}/url.d.ts +0 -0
  198. package/dist/types/test/utils.d.ts +119 -0
  199. package/package.json +5 -4
@@ -0,0 +1,458 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+
33
+ import { Readable } from 'stream';
34
+ import { ReadableStream as ReadableStreamPolyfill } from 'web-streams-polyfill';
35
+ import ky from 'ky-universal';
36
+ import { bytesToHex } from "../src/utils/hex.js";
37
+ import { deleteChunkFromLocalStorage } from "../src/modules/debug/chunk.js";
38
+ import { BeeResponseError } from "../src/index.js";
39
+ import { assertBytes } from "../src/utils/bytes.js";
40
+ import * as stamps from "../src/modules/debug/stamps.js";
41
+ /**
42
+ * Load common own Jest Matchers which can be used to check particular return values.
43
+ */
44
+
45
+ export function commonMatchers() {
46
+ expect.extend({
47
+ toBeHashReference(received) {
48
+ const result = {
49
+ pass: false,
50
+ message: () => 'Given input is not a Swarm hash reference'
51
+ };
52
+
53
+ if (typeof received === 'string' && /^[0-9a-fA-F]{64}$/.test(received)) {
54
+ result.pass = true;
55
+
56
+ result.message = () => 'Given string is semantically valid Swarm hash reference';
57
+ }
58
+
59
+ return result;
60
+ },
61
+
62
+ toBeBeeResponse(received, expectedStatusCode) {
63
+ const result = {
64
+ pass: false,
65
+ message: () => `Bee response does not have status code ${expectedStatusCode}. Got: ${received.code}\nResponse message: ${received.message}`
66
+ };
67
+
68
+ if (received.code === expectedStatusCode) {
69
+ result.pass = true;
70
+
71
+ result.message = () => 'Bee response meets with its requirements';
72
+ }
73
+
74
+ return result;
75
+ },
76
+
77
+ toBeOneOf(received, argument) {
78
+ const validValues = Array.isArray(argument) ? argument : [argument];
79
+ let containsValidValue = false;
80
+
81
+ for (const validValue of validValues) {
82
+ try {
83
+ expect(received).toEqual(validValue);
84
+ containsValidValue = true; // eslint-disable-next-line no-empty
85
+ } catch (e) {}
86
+ }
87
+
88
+ if (containsValidValue) {
89
+ return {
90
+ message: () => `expected ${JSON.stringify(received)} not to be one of [${validValues.join(', ')}]`,
91
+ pass: true
92
+ };
93
+ }
94
+
95
+ return {
96
+ message: () => `expected ${JSON.stringify(received)} to be one of [${validValues.join(', ')}]`,
97
+ pass: false
98
+ };
99
+ },
100
+
101
+ toBeType(received, argument) {
102
+ const initialType = typeof received;
103
+ const isArray = Array.isArray(received) ? 'array' : initialType;
104
+ const type = initialType === 'object' ? isArray : initialType;
105
+ return type === argument ? {
106
+ message: () => `expected ${received} to be type ${argument}`,
107
+ pass: true
108
+ } : {
109
+ message: () => `expected ${received} to be type ${argument}`,
110
+ pass: false
111
+ };
112
+ },
113
+
114
+ toBeNumberString(received) {
115
+ const message = () => `expected ${received} to be a number in a string type`;
116
+
117
+ return /^-?(0|[1-9][0-9]*)$/g.test(received) ? {
118
+ message,
119
+ pass: true
120
+ } : {
121
+ message,
122
+ pass: false
123
+ };
124
+ }
125
+
126
+ });
127
+ }
128
+ /**
129
+ * Sleep for N miliseconds
130
+ *
131
+ * @param ms Number of miliseconds to sleep
132
+ */
133
+
134
+ export function sleep(ms) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return new Promise(resolve => setTimeout(() => resolve(), ms));
137
+ });
138
+ }
139
+ /**
140
+ * Helper function that reads whole content of ReadableStream
141
+ * @param stream
142
+ */
143
+
144
+ export function readWholeUint8ArrayReadableStream(stream) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const reader = stream.getReader();
147
+ let buff = [];
148
+ let readResult;
149
+
150
+ do {
151
+ readResult = yield reader.read();
152
+ if (readResult.value) buff = [...buff, ...readResult.value];
153
+ } while (!readResult.done);
154
+
155
+ return new Uint8Array(buff);
156
+ });
157
+ }
158
+ export function createRandomNodeReadable(totalSize, chunkSize = 1000) {
159
+ if (totalSize % chunkSize !== 0) {
160
+ throw new Error(`totalSize ${totalSize} is not dividable without remainder by chunkSize ${chunkSize}`);
161
+ }
162
+
163
+ const stream = new Readable(); // eslint-disable-next-line @typescript-eslint/no-empty-function
164
+
165
+ stream._read = () => {};
166
+
167
+ for (let i = 0; i < totalSize / chunkSize; i++) {
168
+ stream.push(randomByteArray(chunkSize));
169
+ }
170
+
171
+ stream.push(null);
172
+ return stream;
173
+ }
174
+ export function createReadableStream(iterable) {
175
+ const iter = iterable[Symbol.iterator]();
176
+ return new ReadableStreamPolyfill({
177
+ pull(controller) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ const result = iter.next();
180
+
181
+ if (result.done) {
182
+ controller.close();
183
+ return;
184
+ }
185
+
186
+ controller.enqueue(result.value);
187
+ });
188
+ }
189
+
190
+ });
191
+ }
192
+ /**
193
+ * Lehmer random number generator with seed (minstd_rand in C++11)
194
+ * !!! Very fast but not well distributed pseudo-random function !!!
195
+ *
196
+ * @param seed Seed for the pseudo-random generator
197
+ */
198
+
199
+ function lrng(seed) {
200
+ return () => (Math.pow(2, 31) - 1 & (seed = Math.imul(48271, seed))) / Math.pow(2, 31);
201
+ }
202
+ /**
203
+ * Utility function for generating random Buffer
204
+ * !!! IT IS NOT CRYPTO SAFE !!!
205
+ * For that use `crypto.randomBytes()`
206
+ *
207
+ * @param length Number of bytes to generate
208
+ * @param seed Seed for the pseudo-random generator
209
+ */
210
+
211
+
212
+ export function randomByteArray(length, seed = 500) {
213
+ const rand = lrng(seed);
214
+ const buf = new Uint8Array(length);
215
+
216
+ for (let i = 0; i < length; ++i) {
217
+ buf[i] = rand() * 0xff << 0;
218
+ }
219
+
220
+ return buf;
221
+ }
222
+ /**
223
+ * Returns a url for testing the Bee public API
224
+ */
225
+
226
+ export function beeUrl() {
227
+ return process.env.BEE_API_URL || 'http://127.0.0.1:1633';
228
+ }
229
+ export function beeKy() {
230
+ return ky.create({
231
+ prefixUrl: beeUrl(),
232
+ timeout: false
233
+ });
234
+ }
235
+ /**
236
+ * Returns a url of another peer for testing the Bee public API
237
+ */
238
+
239
+ export function beePeerUrl() {
240
+ return process.env.BEE_PEER_API_URL || 'http://127.0.0.1:11633';
241
+ }
242
+ export function beePeerKy() {
243
+ return ky.create({
244
+ prefixUrl: beePeerUrl(),
245
+ timeout: false
246
+ });
247
+ }
248
+ /**
249
+ * Helper function that create monster batch for all the tests.
250
+ * There is semaphore mechanism that allows only creation of one batch across all the
251
+ * parallel running tests that have to wait until it is created.
252
+ */
253
+
254
+ export function getPostageBatch(url = beeDebugUrl()) {
255
+ let stamp;
256
+
257
+ switch (url) {
258
+ case beeDebugUrl():
259
+ stamp = process.env.BEE_POSTAGE;
260
+ break;
261
+
262
+ case beePeerDebugUrl():
263
+ stamp = process.env.BEE_PEER_POSTAGE;
264
+ break;
265
+
266
+ default:
267
+ throw new Error('Unknown URL ' + url);
268
+ }
269
+
270
+ if (!stamp) {
271
+ throw new Error('There is no postage stamp configured for URL ' + url);
272
+ }
273
+
274
+ return stamp;
275
+ }
276
+ /**
277
+ * Returns a url for testing the Bee Debug API
278
+ */
279
+
280
+ export function beeDebugUrl() {
281
+ return process.env.BEE_DEBUG_API_URL || 'http://127.0.0.1:1635';
282
+ }
283
+ export function beeDebugKy() {
284
+ return ky.create({
285
+ prefixUrl: beeDebugUrl(),
286
+ timeout: false
287
+ });
288
+ }
289
+ /**
290
+ * Returns a url for testing the Bee Debug API
291
+ */
292
+
293
+ export function beePeerDebugUrl() {
294
+ return process.env.BEE_PEER_DEBUG_API_URL || 'http://127.0.0.1:11635';
295
+ }
296
+ export function beePeerDebugKy() {
297
+ return ky.create({
298
+ prefixUrl: beePeerDebugUrl(),
299
+ timeout: false
300
+ });
301
+ }
302
+ /**
303
+ * Try to delete a chunk from local storage, ignoring all errors
304
+ *
305
+ * @param address Swarm address of chunk
306
+ */
307
+
308
+ export function tryDeleteChunkFromLocalStorage(address) {
309
+ return __awaiter(this, void 0, void 0, function* () {
310
+ if (typeof address !== 'string') {
311
+ assertBytes(address, 32);
312
+ address = bytesToHex(address);
313
+ }
314
+
315
+ try {
316
+ yield deleteChunkFromLocalStorage(beeDebugKy(), address);
317
+ } catch (e) {
318
+ // ignore not found errors
319
+ if (e instanceof BeeResponseError && e.status === 404) {
320
+ return;
321
+ }
322
+
323
+ throw e;
324
+ }
325
+ });
326
+ }
327
+ /**
328
+ * Formatting utility for displaying long strings like hexstrings.
329
+ *
330
+ * @param inputStr
331
+ * @param len
332
+ */
333
+
334
+ export function shorten(inputStr, len = 17) {
335
+ const str = typeof inputStr === 'string' ? inputStr : inputStr.toString();
336
+
337
+ if (str.length <= len) {
338
+ return str;
339
+ }
340
+
341
+ return `${str.slice(0, 6)}...${str.slice(-6)} (length: ${str.length})`;
342
+ }
343
+
344
+ function timeout(ms, message = 'Execution reached timeout!') {
345
+ return __awaiter(this, void 0, void 0, function* () {
346
+ yield sleep(ms);
347
+ throw new Error(message);
348
+ });
349
+ }
350
+
351
+ export function waitForBatchToBeUsable(batchId, pollingInterval = 200) {
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ yield Promise.race([timeout(USABLE_TIMEOUT, 'Awaiting of usable postage batch timed out!'), () => __awaiter(this, void 0, void 0, function* () {
354
+ let stamp;
355
+
356
+ do {
357
+ yield sleep(pollingInterval);
358
+ stamp = yield stamps.getPostageBatch(beeDebugKy(), batchId);
359
+ } while (!stamp.usable);
360
+ })]);
361
+ });
362
+ }
363
+ const DEFAULT_BATCH_AMOUNT = '1';
364
+ const DEFAULT_BATCH_DEPTH = 17;
365
+ /**
366
+ * Returns already existing batch or will create one.
367
+ *
368
+ * If some specification is passed then it is guaranteed that the batch will have this property(ies)
369
+ *
370
+ * @param amount
371
+ * @param depth
372
+ * @param immutable
373
+ */
374
+
375
+ export function getOrCreatePostageBatch(amount, depth, immutable) {
376
+ return __awaiter(this, void 0, void 0, function* () {
377
+ // Non-usable stamps are ignored by Bee
378
+ const allUsableStamps = (yield stamps.getAllPostageBatches(beeDebugKy())).filter(stamp => stamp.usable);
379
+
380
+ if (allUsableStamps.length === 0) {
381
+ const batchId = yield stamps.createPostageBatch(beeDebugKy(), amount !== null && amount !== void 0 ? amount : DEFAULT_BATCH_AMOUNT, depth !== null && depth !== void 0 ? depth : DEFAULT_BATCH_DEPTH);
382
+ yield waitForBatchToBeUsable(batchId);
383
+ return stamps.getPostageBatch(beeDebugKy(), batchId);
384
+ } // User does not want any specific batch, lets give him the first one
385
+
386
+
387
+ if (amount === undefined && depth === undefined && immutable === undefined) {
388
+ return allUsableStamps[0];
389
+ } // User wants some specific batch
390
+
391
+
392
+ for (const stamp of allUsableStamps) {
393
+ let meetingAllCriteria = false;
394
+
395
+ if (amount !== undefined) {
396
+ meetingAllCriteria = amount === stamp.amount;
397
+ } else {
398
+ meetingAllCriteria = true;
399
+ }
400
+
401
+ if (depth !== undefined) {
402
+ meetingAllCriteria = meetingAllCriteria && depth === stamp.depth;
403
+ }
404
+
405
+ if (immutable !== undefined) {
406
+ meetingAllCriteria = meetingAllCriteria && immutable === stamp.immutableFlag;
407
+ }
408
+
409
+ if (meetingAllCriteria) {
410
+ return stamp;
411
+ }
412
+ } // No stamp meeting the criteria was found ==> we need to create a new one
413
+
414
+
415
+ const batchId = yield stamps.createPostageBatch(beeDebugKy(), amount !== null && amount !== void 0 ? amount : DEFAULT_BATCH_AMOUNT, depth !== null && depth !== void 0 ? depth : DEFAULT_BATCH_DEPTH);
416
+ yield waitForBatchToBeUsable(batchId);
417
+ return stamps.getPostageBatch(beeDebugKy(), batchId);
418
+ });
419
+ }
420
+ export function makeTestTarget(target) {
421
+ return target.slice(0, 2);
422
+ }
423
+ export const invalidReference = '0000000000000000000000000000000000000000000000000000000000000000';
424
+ export const okResponse = {
425
+ code: 200,
426
+ message: 'OK'
427
+ };
428
+ export const createdResponse = {
429
+ code: 201,
430
+ message: 'Created'
431
+ };
432
+ const USABLE_TIMEOUT = 7000;
433
+ export const ERR_TIMEOUT = 40000;
434
+ export const BIG_FILE_TIMEOUT = 100000;
435
+ export const PSS_TIMEOUT = 120000;
436
+ export const FEED_TIMEOUT = 120000;
437
+ export const BLOCKCHAIN_TRANSACTION_TIMEOUT = 40000;
438
+ export const WAITING_USABLE_STAMP_TIMEOUT = 130000;
439
+ export const testChunkPayload = new Uint8Array([1, 2, 3]); // span is the payload length encoded as uint64 little endian
440
+
441
+ export const testChunkSpan = new Uint8Array([testChunkPayload.length, 0, 0, 0, 0, 0, 0, 0]);
442
+ export const testChunkData = new Uint8Array([...testChunkSpan, ...testChunkPayload]); // the hash is hardcoded because we would need the bmt hasher otherwise
443
+
444
+ export const testChunkHash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
445
+ export const testAddress = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
446
+ export const testBatchId = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
447
+ export const testJsonPayload = [{
448
+ some: 'object'
449
+ }];
450
+ export const testJsonStringPayload = JSON.stringify(testJsonPayload);
451
+ export const testJsonHash = '872a858115b8bee4408b1427b49e472883fdc2512d5a8f2d428b97ecc8f7ccfa';
452
+ export const testJsonCid = 'bah5acgzaq4vilaivxc7oiqelcqt3jhshfcb73qsrfvni6lkcrol6zshxzt5a';
453
+ export const testJsonEns = 'testing.eth';
454
+ export const testIdentity = {
455
+ privateKey: '634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
456
+ publicKey: '03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4',
457
+ address: '8d3766440f0d7b949a5e32995d09619a7f86e632'
458
+ };
@@ -1,4 +1,4 @@
1
- import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, PostageBatch, TransactionInfo, TransactionHash, NodeInfo, BeeVersions } from './types';
1
+ import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, PostageBatch, TransactionInfo, TransactionHash, NodeInfo, BeeVersions, WalletBalance } from './types';
2
2
  import { BatchId, BeeOptions, CashoutOptions, PostageBatchOptions, RequestOptions, Tag } from './types';
3
3
  export declare class BeeDebug {
4
4
  /**
@@ -181,6 +181,12 @@ export declare class BeeDebug {
181
181
  * Get chain state
182
182
  */
183
183
  getChainState(options?: RequestOptions): Promise<ChainState>;
184
+ /**
185
+ * Get wallet balances for xDai and BZZ of the Bee node
186
+ *
187
+ * @param options
188
+ */
189
+ getWalletBalance(options?: RequestOptions): Promise<WalletBalance>;
184
190
  /**
185
191
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
186
192
  *
@@ -279,5 +285,6 @@ export declare class BeeDebug {
279
285
  * @param gasPrice
280
286
  */
281
287
  cancelPendingTransaction(transactionHash: TransactionHash | string, gasPrice?: NumberString, options?: RequestOptions): Promise<TransactionHash>;
288
+ private waitForUsablePostageStamp;
282
289
  private getKy;
283
290
  }
@@ -1,8 +1,8 @@
1
1
  import { Index, IndexBytes } from './feed';
2
2
  import { FeedType } from './feed/type';
3
3
  import { EthAddress } from './utils/eth';
4
- import { AllTagsOptions, Collection, Readable, ReferenceOrEns, RequestOptions, UploadResult } from './types';
5
- import type { Tag, FileData, Reference, UploadOptions, PublicKey, AddressPrefix, PssMessageHandler, PssSubscription, CollectionUploadOptions, FileUploadOptions, Data, Signer, FeedReader, FeedWriter, SOCWriter, SOCReader, Topic, BeeOptions, JsonFeedOptions, AnyJson, Pin, BatchId } from './types';
4
+ import type { AddressPrefix, AnyJson, BatchId, BeeOptions, CollectionUploadOptions, Data, FeedReader, FeedWriter, FileData, FileUploadOptions, JsonFeedOptions, Pin, PssMessageHandler, PssSubscription, PublicKey, Reference, Signer, SOCReader, SOCWriter, Tag, Topic, UploadOptions, UploadResultWithCid } from './types';
5
+ import { AllTagsOptions, Collection, Readable, ReferenceCidOrEns, ReferenceOrEns, RequestOptions, UploadResult } from './types';
6
6
  /**
7
7
  * The main component that abstracts operations available on the main Bee API.
8
8
  *
@@ -101,11 +101,11 @@ export declare class Bee {
101
101
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File/paths/~1bzz/post)
102
102
  * @returns reference is a content hash of the file
103
103
  */
104
- uploadFile(postageBatchId: string | BatchId, data: string | Uint8Array | Readable | File, name?: string, options?: FileUploadOptions): Promise<UploadResult>;
104
+ uploadFile(postageBatchId: string | BatchId, data: string | Uint8Array | Readable | File, name?: string, options?: FileUploadOptions): Promise<UploadResultWithCid>;
105
105
  /**
106
106
  * Download single file.
107
107
  *
108
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
108
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
109
109
  * @param path If reference points to manifest, then this parameter defines path to the file
110
110
  * @param options Options that affects the request behavior
111
111
  * @throws TypeError if some of the input parameters is not expected type
@@ -114,11 +114,11 @@ export declare class Bee {
114
114
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
115
115
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
116
116
  */
117
- downloadFile(reference: ReferenceOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<Data>>;
117
+ downloadFile(reference: ReferenceCidOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<Data>>;
118
118
  /**
119
119
  * Download single file as a readable stream
120
120
  *
121
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
121
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
122
122
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
123
123
  * @param options Options that affects the request behavior
124
124
  * @throws TypeError if some of the input parameters is not expected type
@@ -127,7 +127,7 @@ export declare class Bee {
127
127
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
128
128
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
129
129
  */
130
- downloadReadableFile(reference: ReferenceOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<ReadableStream<Uint8Array>>>;
130
+ downloadReadableFile(reference: ReferenceCidOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<ReadableStream<Uint8Array>>>;
131
131
  /**
132
132
  * Upload collection of files to a Bee node
133
133
  *
@@ -144,7 +144,7 @@ export declare class Bee {
144
144
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
145
145
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
146
146
  */
147
- uploadFiles(postageBatchId: string | BatchId, fileList: FileList | File[], options?: CollectionUploadOptions): Promise<UploadResult>;
147
+ uploadFiles(postageBatchId: string | BatchId, fileList: FileList | File[], options?: CollectionUploadOptions): Promise<UploadResultWithCid>;
148
148
  /**
149
149
  * Upload Collection that you can assembly yourself.
150
150
  *
@@ -155,7 +155,7 @@ export declare class Bee {
155
155
  * @param collection
156
156
  * @param options Collections and request options
157
157
  */
158
- uploadCollection(postageBatchId: string | BatchId, collection: Collection<Uint8Array | Readable>, options?: CollectionUploadOptions): Promise<UploadResult>;
158
+ uploadCollection(postageBatchId: string | BatchId, collection: Collection<Uint8Array | Readable>, options?: CollectionUploadOptions): Promise<UploadResultWithCid>;
159
159
  /**
160
160
  * Upload collection of files.
161
161
  *
@@ -172,7 +172,7 @@ export declare class Bee {
172
172
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
173
173
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
174
174
  */
175
- uploadFilesFromDirectory(postageBatchId: string | BatchId, dir: string, options?: CollectionUploadOptions): Promise<UploadResult>;
175
+ uploadFilesFromDirectory(postageBatchId: string | BatchId, dir: string, options?: CollectionUploadOptions): Promise<UploadResultWithCid>;
176
176
  /**
177
177
  * Create a new Tag which is meant for tracking progres of syncing data across network.
178
178
  *
@@ -411,6 +411,7 @@ export declare class Bee {
411
411
  *
412
412
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
413
413
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
414
+ * TODO: Once breaking add support for Feed CID
414
415
  */
415
416
  createFeedManifest(postageBatchId: string | BatchId, type: FeedType, topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: RequestOptions): Promise<Reference>;
416
417
  /**
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import { ChainState, Ky, ReserveState } from '../../types';
1
+ import { ChainState, Ky, ReserveState, WalletBalance } from '../../types';
2
2
  /**
3
3
  * Get state of reserve
4
4
  *
@@ -11,3 +11,9 @@ export declare function getReserveState(ky: Ky): Promise<ReserveState>;
11
11
  * @param ky Ky debug instance
12
12
  */
13
13
  export declare function getChainState(ky: Ky): Promise<ChainState>;
14
+ /**
15
+ * Get wallet balances for xDai and BZZ of the node
16
+ *
17
+ * @param ky Ky debug instance
18
+ */
19
+ export declare function getWalletBalance(ky: Ky): Promise<WalletBalance>;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes