@ethersphere/bee-js 3.3.2-pre.1 → 3.3.3

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 (42) hide show
  1. package/dist/mjs/bee-debug.js +294 -189
  2. package/dist/mjs/bee.js +316 -237
  3. package/dist/mjs/chunk/signer.js +46 -12
  4. package/dist/mjs/chunk/soc.js +71 -31
  5. package/dist/mjs/chunk/span.js +1 -1
  6. package/dist/mjs/feed/index.js +86 -42
  7. package/dist/mjs/feed/json.js +46 -10
  8. package/dist/mjs/index.js +2 -1
  9. package/dist/mjs/modules/bytes.js +61 -24
  10. package/dist/mjs/modules/bzz.js +96 -58
  11. package/dist/mjs/modules/chunk.js +51 -16
  12. package/dist/mjs/modules/debug/balance.js +60 -20
  13. package/dist/mjs/modules/debug/chequebook.js +115 -67
  14. package/dist/mjs/modules/debug/chunk.js +47 -11
  15. package/dist/mjs/modules/debug/connectivity.js +76 -32
  16. package/dist/mjs/modules/debug/settlements.js +46 -10
  17. package/dist/mjs/modules/debug/stamps.js +91 -47
  18. package/dist/mjs/modules/debug/states.js +48 -12
  19. package/dist/mjs/modules/debug/status.js +97 -49
  20. package/dist/mjs/modules/debug/tag.js +39 -5
  21. package/dist/mjs/modules/debug/transactions.js +65 -25
  22. package/dist/mjs/modules/feed.js +50 -16
  23. package/dist/mjs/modules/pinning.js +67 -27
  24. package/dist/mjs/modules/pss.js +44 -10
  25. package/dist/mjs/modules/soc.js +47 -14
  26. package/dist/mjs/modules/status.js +37 -3
  27. package/dist/mjs/modules/stewardship.js +46 -10
  28. package/dist/mjs/modules/tag.js +73 -31
  29. package/dist/mjs/utils/collection.browser.js +41 -4
  30. package/dist/mjs/utils/collection.js +45 -11
  31. package/dist/mjs/utils/collection.node.js +137 -42
  32. package/dist/mjs/utils/data.browser.js +88 -52
  33. package/dist/mjs/utils/data.js +57 -21
  34. package/dist/mjs/utils/error.js +0 -9
  35. package/dist/mjs/utils/eth.js +68 -32
  36. package/dist/mjs/utils/file.js +42 -8
  37. package/dist/mjs/utils/headers.js +4 -4
  38. package/dist/mjs/utils/http.js +110 -64
  39. package/dist/mjs/utils/merge.js +2 -2
  40. package/dist/mjs/utils/stream.js +0 -4
  41. package/dist/mjs/utils/type.js +6 -6
  42. package/package.json +2 -2
@@ -1,3 +1,35 @@
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
+
1
33
  import { isNodeReadable, isReadableStream } from "./stream.js";
2
34
  import Blob from 'cross-blob';
3
35
  /**
@@ -6,68 +38,72 @@ import Blob from 'cross-blob';
6
38
  * @param data any string, ArrayBuffer or Uint8Array
7
39
  */
8
40
 
9
- export async function prepareData(data) {
10
- if (typeof data === 'string') return new Blob([data], {
11
- type: 'text/plain'
12
- });
13
-
14
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
15
- return new Blob([data], {
16
- type: 'application/octet-stream'
41
+ export function prepareData(data) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ if (typeof data === 'string') return new Blob([data], {
44
+ type: 'text/plain'
17
45
  });
18
- }
19
46
 
20
- if (data instanceof Blob) {
21
- return data;
22
- } // Currently it is not possible to stream requests from browsers
23
- // there are already first experiments on this field (Chromium)
24
- // but till it is fully implemented across browsers-land we have to
25
- // buffer the data before sending the requests.
47
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
48
+ return new Blob([data], {
49
+ type: 'application/octet-stream'
50
+ });
51
+ }
26
52
 
53
+ if (data instanceof Blob) {
54
+ return data;
55
+ } // Currently it is not possible to stream requests from browsers
56
+ // there are already first experiments on this field (Chromium)
57
+ // but till it is fully implemented across browsers-land we have to
58
+ // buffer the data before sending the requests.
27
59
 
28
- if (isNodeReadable(data)) {
29
- return new Promise(resolve => {
30
- const buffers = [];
31
- data.on('data', d => {
32
- buffers.push(d);
33
- });
34
- data.on('end', () => {
35
- resolve(new Blob(buffers, {
36
- type: 'application/octet-stream'
37
- }));
60
+
61
+ if (isNodeReadable(data)) {
62
+ return new Promise(resolve => {
63
+ const buffers = [];
64
+ data.on('data', d => {
65
+ buffers.push(d);
66
+ });
67
+ data.on('end', () => {
68
+ resolve(new Blob(buffers, {
69
+ type: 'application/octet-stream'
70
+ }));
71
+ });
38
72
  });
39
- });
40
- }
73
+ }
41
74
 
42
- if (isReadableStream(data)) {
43
- return new Promise(async resolve => {
44
- const reader = data.getReader();
45
- const buffers = [];
46
- let done, value;
75
+ if (isReadableStream(data)) {
76
+ return new Promise(resolve => __awaiter(this, void 0, void 0, function* () {
77
+ const reader = data.getReader();
78
+ const buffers = [];
79
+ let done, value;
47
80
 
48
- do {
49
- ;
50
- ({
51
- done,
52
- value
53
- } = await reader.read());
81
+ do {
82
+ ;
83
+ ({
84
+ done,
85
+ value
86
+ } = yield reader.read());
54
87
 
55
- if (!done) {
56
- buffers.push(value);
57
- }
58
- } while (!done);
88
+ if (!done) {
89
+ buffers.push(value);
90
+ }
91
+ } while (!done);
59
92
 
60
- resolve(new Blob(buffers, {
61
- type: 'application/octet-stream'
93
+ resolve(new Blob(buffers, {
94
+ type: 'application/octet-stream'
95
+ }));
62
96
  }));
63
- });
64
- }
97
+ }
65
98
 
66
- throw new TypeError('unknown data type');
99
+ throw new TypeError('unknown data type');
100
+ });
67
101
  }
68
- export async function prepareWebsocketData(data) {
69
- if (typeof data === 'string') return new TextEncoder().encode(data);
70
- if (data instanceof ArrayBuffer) return new Uint8Array(data);
71
- if (data instanceof Blob) return new Uint8Array(await new Response(data).arrayBuffer());
72
- throw new TypeError('unknown websocket data type');
102
+ export function prepareWebsocketData(data) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ if (typeof data === 'string') return new TextEncoder().encode(data);
105
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
106
+ if (data instanceof Blob) return new Uint8Array(yield new Response(data).arrayBuffer());
107
+ throw new TypeError('unknown websocket data type');
108
+ });
73
109
  }
@@ -1,3 +1,35 @@
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
+
1
33
  import Blob from 'cross-blob';
2
34
  import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js";
3
35
  /**
@@ -9,35 +41,39 @@ import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js
9
41
  * @param data any string, ArrayBuffer, Uint8Array or Readable
10
42
  */
11
43
 
12
- export async function prepareData(data) {
13
- if (typeof data === 'string') return new Blob([data], {
14
- type: 'text/plain'
15
- });
16
-
17
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
18
- return new Blob([data], {
19
- type: 'application/octet-stream'
44
+ export function prepareData(data) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (typeof data === 'string') return new Blob([data], {
47
+ type: 'text/plain'
20
48
  });
21
- }
22
49
 
23
- if (data instanceof Blob || isNodeReadable(data)) return data;
50
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
51
+ return new Blob([data], {
52
+ type: 'application/octet-stream'
53
+ });
54
+ }
24
55
 
25
- if (isReadableStream(data)) {
26
- return readableWebToNode(data);
27
- }
56
+ if (data instanceof Blob || isNodeReadable(data)) return data;
28
57
 
29
- throw new TypeError('unknown data type');
58
+ if (isReadableStream(data)) {
59
+ return readableWebToNode(data);
60
+ }
61
+
62
+ throw new TypeError('unknown data type');
63
+ });
30
64
  }
31
65
 
32
66
  function isBufferArray(buffer) {
33
67
  return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
34
68
  }
35
69
 
36
- export async function prepareWebsocketData(data) {
37
- if (typeof data === 'string') return new TextEncoder().encode(data);
38
- if (data instanceof Buffer) return new Uint8Array(data);
39
- if (data instanceof ArrayBuffer) return new Uint8Array(data);
40
- if (data instanceof Blob) return new Uint8Array(await new Response(data).arrayBuffer());
41
- if (isBufferArray(data)) return new Uint8Array(Buffer.concat(data));
42
- throw new TypeError('unknown websocket data type');
70
+ export function prepareWebsocketData(data) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (typeof data === 'string') return new TextEncoder().encode(data);
73
+ if (data instanceof Buffer) return new Uint8Array(data);
74
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
75
+ if (data instanceof Blob) return new Uint8Array(yield new Response(data).arrayBuffer());
76
+ if (isBufferArray(data)) return new Uint8Array(Buffer.concat(data));
77
+ throw new TypeError('unknown websocket data type');
78
+ });
43
79
  }
@@ -5,8 +5,6 @@ export class BeeError extends Error {
5
5
 
6
6
  }
7
7
  export class BeeArgumentError extends BeeError {
8
- value;
9
-
10
8
  constructor(message, value) {
11
9
  super(message);
12
10
  this.value = value;
@@ -14,12 +12,10 @@ export class BeeArgumentError extends BeeError {
14
12
 
15
13
  }
16
14
  export class BeeRequestError extends BeeError {
17
- requestOptions;
18
15
  /**
19
16
  * @param message
20
17
  * @param requestOptions KyOptions that were used to assemble the request. THIS MIGHT NOT BE COMPLETE! If custom Ky instance was used that has set defaults then these defaults are not visible in this object!
21
18
  */
22
-
23
19
  constructor(message, requestOptions) {
24
20
  super(message);
25
21
  this.requestOptions = requestOptions;
@@ -27,10 +23,6 @@ export class BeeRequestError extends BeeError {
27
23
 
28
24
  }
29
25
  export class BeeResponseError extends BeeError {
30
- status;
31
- response;
32
- responseBody;
33
- requestOptions;
34
26
  /**
35
27
  * @param status HTTP status code number
36
28
  * @param response Response returned from the server
@@ -38,7 +30,6 @@ export class BeeResponseError extends BeeError {
38
30
  * @param requestOptions KyOptions that were used to assemble the request. THIS MIGHT NOT BE COMPLETE! If custom Ky instance was used that has set defaults then these defaults are not visible in this object!
39
31
  * @param message
40
32
  */
41
-
42
33
  constructor(status, response, responseBody, requestOptions, message) {
43
34
  super(message);
44
35
  this.status = status;
@@ -1,4 +1,36 @@
1
- // For ESM compatibility
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
+ }; // For ESM compatibility
32
+
33
+
2
34
  import pkg from 'js-sha3';
3
35
  const {
4
36
  keccak256,
@@ -98,6 +130,8 @@ export function isHexEthAddress(address) {
98
130
  */
99
131
 
100
132
  export function toLittleEndian(bigEndian, pad = 2) {
133
+ var _a;
134
+
101
135
  if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
102
136
  throw new TypeError('minimal padding for conversion needs to be positive even integer');
103
137
  }
@@ -108,7 +142,7 @@ export function toLittleEndian(bigEndian, pad = 2) {
108
142
 
109
143
  if (hexRep.length % 2 !== 0) hexRep = hexRep.padStart(hexRep.length + 1, '0'); // Match all two pairs in the hexstring, reverse the pairs and join it again
110
144
 
111
- const littleEndian = hexRep.match(/../g)?.reverse().join('');
145
+ const littleEndian = (_a = hexRep.match(/../g)) === null || _a === void 0 ? void 0 : _a.reverse().join('');
112
146
  if (littleEndian) return littleEndian;
113
147
  throw new Error('failed to convert');
114
148
  }
@@ -162,38 +196,40 @@ export function ethToSwarmAddress(ethAddress, networkId = 1) {
162
196
  * @param ethAddress Optional address of the account which the data should be signed with. If not specified `eth_requestAccounts` request is used to get the account address.
163
197
  */
164
198
 
165
- export async function makeEthereumWalletSigner(provider, ethAddress) {
166
- let executorFnc;
167
-
168
- if (typeof provider !== 'object' || provider === null) {
169
- throw new TypeError('We need JsonRPC provider object!');
170
- }
199
+ export function makeEthereumWalletSigner(provider, ethAddress) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ let executorFnc;
171
202
 
172
- if (provider.request) {
173
- executorFnc = provider.request;
174
- } else if (provider.sendAsync) {
175
- executorFnc = provider.sendAsync;
176
- } else {
177
- throw new Error('Incompatible interface of given provider!');
178
- }
203
+ if (typeof provider !== 'object' || provider === null) {
204
+ throw new TypeError('We need JsonRPC provider object!');
205
+ }
179
206
 
180
- if (!ethAddress) {
181
- ethAddress = (await executorFnc({
182
- method: 'eth_requestAccounts'
183
- }))[0];
184
- }
207
+ if (provider.request) {
208
+ executorFnc = provider.request;
209
+ } else if (provider.sendAsync) {
210
+ executorFnc = provider.sendAsync;
211
+ } else {
212
+ throw new Error('Incompatible interface of given provider!');
213
+ }
185
214
 
186
- const bytesEthAddress = makeEthAddress(ethAddress);
187
- const hexEthAddress = makeHexEthAddress(ethAddress);
188
- return {
189
- address: bytesEthAddress,
190
- sign: async data => {
191
- const result = await executorFnc({
192
- jsonrpc: '2.0',
193
- method: 'personal_sign',
194
- params: ['0x' + data.hex(), '0x' + hexEthAddress]
195
- });
196
- return result;
215
+ if (!ethAddress) {
216
+ ethAddress = (yield executorFnc({
217
+ method: 'eth_requestAccounts'
218
+ }))[0];
197
219
  }
198
- };
220
+
221
+ const bytesEthAddress = makeEthAddress(ethAddress);
222
+ const hexEthAddress = makeHexEthAddress(ethAddress);
223
+ return {
224
+ address: bytesEthAddress,
225
+ sign: data => __awaiter(this, void 0, void 0, function* () {
226
+ const result = yield executorFnc({
227
+ jsonrpc: '2.0',
228
+ method: 'personal_sign',
229
+ params: ['0x' + data.hex(), '0x' + hexEthAddress]
230
+ });
231
+ return result;
232
+ })
233
+ };
234
+ });
199
235
  }
@@ -3,6 +3,38 @@
3
3
  *
4
4
  * https://developer.mozilla.org/en-US/docs/Web/API/File
5
5
  */
6
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) {
8
+ return value instanceof P ? value : new P(function (resolve) {
9
+ resolve(value);
10
+ });
11
+ }
12
+
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) {
15
+ try {
16
+ step(generator.next(value));
17
+ } catch (e) {
18
+ reject(e);
19
+ }
20
+ }
21
+
22
+ function rejected(value) {
23
+ try {
24
+ step(generator["throw"](value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ }
29
+
30
+ function step(result) {
31
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
32
+ }
33
+
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+
6
38
  export function isFile(file) {
7
39
  // browser
8
40
  if (typeof File === 'function') {
@@ -20,17 +52,19 @@ export function isFile(file) {
20
52
  * @param file A File object
21
53
  */
22
54
 
23
- export async function fileArrayBuffer(file) {
24
- if (file.arrayBuffer) {
25
- return file.arrayBuffer();
26
- } // workaround for Safari where arrayBuffer is not supported on Files
55
+ export function fileArrayBuffer(file) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ if (file.arrayBuffer) {
58
+ return file.arrayBuffer();
59
+ } // workaround for Safari where arrayBuffer is not supported on Files
27
60
 
28
61
 
29
- return new Promise(resolve => {
30
- const fr = new FileReader();
62
+ return new Promise(resolve => {
63
+ const fr = new FileReader();
31
64
 
32
- fr.onload = () => resolve(fr.result);
65
+ fr.onload = () => resolve(fr.result);
33
66
 
34
- fr.readAsArrayBuffer(file);
67
+ fr.readAsArrayBuffer(file);
68
+ });
35
69
  });
36
70
  }
@@ -50,9 +50,9 @@ export function extractUploadHeaders(postageBatchId, options) {
50
50
  const headers = {
51
51
  'swarm-postage-batch-id': postageBatchId
52
52
  };
53
- if (options?.pin) headers['swarm-pin'] = String(options.pin);
54
- if (options?.encrypt) headers['swarm-encrypt'] = String(options.encrypt);
55
- if (options?.tag) headers['swarm-tag'] = String(options.tag);
56
- if (typeof options?.deferred === 'boolean') headers['swarm-deferred-upload'] = options.deferred.toString();
53
+ if (options === null || options === void 0 ? void 0 : options.pin) headers['swarm-pin'] = String(options.pin);
54
+ if (options === null || options === void 0 ? void 0 : options.encrypt) headers['swarm-encrypt'] = String(options.encrypt);
55
+ if (options === null || options === void 0 ? void 0 : options.tag) headers['swarm-tag'] = String(options.tag);
56
+ if (typeof (options === null || options === void 0 ? void 0 : options.deferred) === 'boolean') headers['swarm-deferred-upload'] = options.deferred.toString();
57
57
  return headers;
58
58
  }