@ethersphere/bee-js 5.1.1 → 5.1.2

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 (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,108 +1,63 @@
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
1
  import { isNodeReadable, isReadableStream } from "./stream.js";
34
2
  /**
35
3
  * Validates input and converts to Uint8Array
36
4
  *
37
5
  * @param data any string, ArrayBuffer or Uint8Array
38
6
  */
39
-
40
- export function prepareData(data) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (typeof data === 'string') return new Blob([data], {
43
- type: 'text/plain'
7
+ export async function prepareData(data) {
8
+ if (typeof data === 'string') return new Blob([data], {
9
+ type: 'text/plain'
10
+ });
11
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
12
+ return new Blob([data], {
13
+ type: 'application/octet-stream'
44
14
  });
45
-
46
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
47
- return new Blob([data], {
48
- type: 'application/octet-stream'
49
- });
50
- }
51
-
52
- if (data instanceof Blob) {
53
- return data;
54
- } // Currently it is not possible to stream requests from browsers
55
- // there are already first experiments on this field (Chromium)
56
- // but till it is fully implemented across browsers-land we have to
57
- // buffer the data before sending the requests.
58
-
59
-
60
- if (isNodeReadable(data)) {
61
- return new Promise(resolve => {
62
- const buffers = [];
63
- data.on('data', d => {
64
- buffers.push(d);
65
- });
66
- data.on('end', () => {
67
- resolve(new Blob(buffers, {
68
- type: 'application/octet-stream'
69
- }));
70
- });
15
+ }
16
+ if (data instanceof Blob) {
17
+ return data;
18
+ }
19
+ // Currently it is not possible to stream requests from browsers
20
+ // there are already first experiments on this field (Chromium)
21
+ // but till it is fully implemented across browsers-land we have to
22
+ // buffer the data before sending the requests.
23
+ if (isNodeReadable(data)) {
24
+ return new Promise(resolve => {
25
+ const buffers = [];
26
+ data.on('data', d => {
27
+ buffers.push(d);
71
28
  });
72
- }
73
-
74
- if (isReadableStream(data)) {
75
- return new Promise(resolve => __awaiter(this, void 0, void 0, function* () {
76
- const reader = data.getReader();
77
- const buffers = [];
78
- let done, value;
79
-
80
- do {
81
- ;
82
- ({
83
- done,
84
- value
85
- } = yield reader.read());
86
-
87
- if (!done) {
88
- buffers.push(value);
89
- }
90
- } while (!done);
91
-
29
+ data.on('end', () => {
92
30
  resolve(new Blob(buffers, {
93
31
  type: 'application/octet-stream'
94
32
  }));
33
+ });
34
+ });
35
+ }
36
+ if (isReadableStream(data)) {
37
+ return new Promise(async resolve => {
38
+ const reader = data.getReader();
39
+ const buffers = [];
40
+ let done, value;
41
+ do {
42
+ ;
43
+ ({
44
+ done,
45
+ value
46
+ } = await reader.read());
47
+ if (!done) {
48
+ buffers.push(value);
49
+ }
50
+ } while (!done);
51
+ resolve(new Blob(buffers, {
52
+ type: 'application/octet-stream'
95
53
  }));
96
- }
97
-
98
- throw new TypeError('unknown data type');
99
- });
54
+ });
55
+ }
56
+ throw new TypeError('unknown data type');
100
57
  }
101
- export function prepareWebsocketData(data) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- if (typeof data === 'string') return new TextEncoder().encode(data);
104
- if (data instanceof ArrayBuffer) return new Uint8Array(data);
105
- if (data instanceof Blob) return new Uint8Array(yield new Response(data).arrayBuffer());
106
- throw new TypeError('unknown websocket data type');
107
- });
58
+ export async function prepareWebsocketData(data) {
59
+ if (typeof data === 'string') return new TextEncoder().encode(data);
60
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
61
+ if (data instanceof Blob) return new Uint8Array(await new Response(data).arrayBuffer());
62
+ throw new TypeError('unknown websocket data type');
108
63
  }
@@ -1,35 +1,3 @@
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
1
  import BlobPolyfill from 'fetch-blob';
34
2
  import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js";
35
3
  /**
@@ -40,39 +8,28 @@ import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js
40
8
  *
41
9
  * @param data any string, ArrayBuffer, Uint8Array or Readable
42
10
  */
43
-
44
- export function prepareData(data) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (typeof data === 'string') return new BlobPolyfill([data], {
47
- type: 'text/plain'
48
- });
49
-
50
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
51
- return new BlobPolyfill([data], {
52
- type: 'application/octet-stream'
53
- });
54
- }
55
-
56
- if (data instanceof BlobPolyfill || isNodeReadable(data)) return data;
57
-
58
- if (isReadableStream(data)) {
59
- return readableWebToNode(data);
60
- }
61
-
62
- throw new TypeError('unknown data type');
11
+ export async function prepareData(data) {
12
+ if (typeof data === 'string') return new BlobPolyfill([data], {
13
+ type: 'text/plain'
63
14
  });
15
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
16
+ return new BlobPolyfill([data], {
17
+ type: 'application/octet-stream'
18
+ });
19
+ }
20
+ if (data instanceof BlobPolyfill || isNodeReadable(data)) return data;
21
+ if (isReadableStream(data)) {
22
+ return readableWebToNode(data);
23
+ }
24
+ throw new TypeError('unknown data type');
64
25
  }
65
-
66
26
  function isBufferArray(buffer) {
67
27
  return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
68
28
  }
69
-
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 (isBufferArray(data)) return new Uint8Array(Buffer.concat(data));
76
- throw new TypeError('unknown websocket data type');
77
- });
29
+ export async function prepareWebsocketData(data) {
30
+ if (typeof data === 'string') return new TextEncoder().encode(data);
31
+ if (data instanceof Buffer) return new Uint8Array(data);
32
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
33
+ if (isBufferArray(data)) return new Uint8Array(Buffer.concat(data));
34
+ throw new TypeError('unknown websocket data type');
78
35
  }
@@ -2,14 +2,12 @@ export class BeeError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
4
  }
5
-
6
5
  }
7
6
  export class BeeArgumentError extends BeeError {
8
7
  constructor(message, value) {
9
8
  super(message);
10
9
  this.value = value;
11
10
  }
12
-
13
11
  }
14
12
  export class BeeRequestError extends BeeError {
15
13
  /**
@@ -20,7 +18,6 @@ export class BeeRequestError extends BeeError {
20
18
  super(message);
21
19
  this.requestOptions = requestOptions;
22
20
  }
23
-
24
21
  }
25
22
  export class BeeResponseError extends BeeError {
26
23
  /**
@@ -37,11 +34,9 @@ export class BeeResponseError extends BeeError {
37
34
  this.responseBody = responseBody;
38
35
  this.requestOptions = requestOptions;
39
36
  }
40
-
41
37
  }
42
38
  export class BeeNotAJsonError extends BeeError {
43
39
  constructor() {
44
40
  super(`Received response is not valid JSON.`);
45
41
  }
46
-
47
42
  }
@@ -1,36 +1,4 @@
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
-
1
+ // For ESM compatibility
34
2
  import pkg from 'js-sha3';
35
3
  const {
36
4
  keccak256,
@@ -50,7 +18,6 @@ export function makeEthAddress(address) {
50
18
  assertBytes(address, ETH_ADDR_BYTES_LENGTH);
51
19
  return address;
52
20
  }
53
-
54
21
  throw new TypeError('Invalid EthAddress');
55
22
  }
56
23
  export function makeHexEthAddress(address) {
@@ -60,7 +27,6 @@ export function makeHexEthAddress(address) {
60
27
  if (e instanceof TypeError) {
61
28
  e.message = `Invalid HexEthAddress: ${e.message}`;
62
29
  }
63
-
64
30
  throw e;
65
31
  }
66
32
  }
@@ -69,7 +35,6 @@ export function makeHexEthAddress(address) {
69
35
  *
70
36
  * @param address Ethereum address as hex string
71
37
  */
72
-
73
38
  function isEthAddrCaseIns(address) {
74
39
  // Check it's string, all small caps or all all caps hex and 40 chars long without the `0x` prefix
75
40
  return typeof address === 'string' && (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address));
@@ -79,28 +44,23 @@ function isEthAddrCaseIns(address) {
79
44
  *
80
45
  * @param address Ethereum address as hex string
81
46
  */
82
-
83
-
84
47
  function isValidChecksummedEthAddress(address) {
85
48
  try {
86
49
  // Check for valid case insensitive hex type string, 40 chars
87
- const addr = makeHexString(address, ETH_ADDR_HEX_LENGTH); // Check the checksum
88
-
50
+ const addr = makeHexString(address, ETH_ADDR_HEX_LENGTH);
51
+ // Check the checksum
89
52
  const addressHash = keccak256(addr.toLowerCase());
90
-
91
53
  for (let i = 0; i < 40; i += 1) {
92
54
  // the nth letter should be uppercase if the nth digit of casemap is 1
93
55
  if (parseInt(addressHash[i], 16) > 7 && addr[i].toUpperCase() !== addr[i] || parseInt(addressHash[i], 16) <= 7 && addr[i].toLowerCase() !== addr[i]) {
94
56
  return false;
95
57
  }
96
58
  }
97
-
98
59
  return true;
99
60
  } catch (e) {
100
61
  if (e instanceof TypeError) {
101
62
  return false;
102
63
  }
103
-
104
64
  throw e;
105
65
  }
106
66
  }
@@ -114,8 +74,6 @@ function isValidChecksummedEthAddress(address) {
114
74
  *
115
75
  * @return True if is valid eth address
116
76
  */
117
-
118
-
119
77
  export function isHexEthAddress(address) {
120
78
  return isEthAddrCaseIns(address) || isValidChecksummedEthAddress(address);
121
79
  }
@@ -128,21 +86,17 @@ export function isHexEthAddress(address) {
128
86
  *
129
87
  * @return little-endian encoded hexstring
130
88
  */
131
-
132
89
  export function toLittleEndian(bigEndian, pad = 2) {
133
- var _a;
134
-
135
90
  if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
136
91
  throw new TypeError('minimal padding for conversion needs to be positive even integer');
137
92
  }
138
-
139
93
  let hexRep;
140
94
  if (typeof bigEndian === 'string') hexRep = makeHexString(bigEndian);else if (typeof bigEndian === 'number') hexRep = intToHex(bigEndian);else throw new TypeError('incorrect input type');
141
- hexRep = hexRep.padStart(pad, '0'); // Extend to an even length hexstring
142
-
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
144
-
145
- const littleEndian = (_a = hexRep.match(/../g)) === null || _a === void 0 ? void 0 : _a.reverse().join('');
95
+ hexRep = hexRep.padStart(pad, '0');
96
+ // Extend to an even length hexstring
97
+ if (hexRep.length % 2 !== 0) hexRep = hexRep.padStart(hexRep.length + 1, '0');
98
+ // Match all two pairs in the hexstring, reverse the pairs and join it again
99
+ const littleEndian = hexRep.match(/../g)?.reverse().join('');
146
100
  if (littleEndian) return littleEndian;
147
101
  throw new Error('failed to convert');
148
102
  }
@@ -155,16 +109,13 @@ export function toLittleEndian(bigEndian, pad = 2) {
155
109
  *
156
110
  * @return big-endian encoded hexstring
157
111
  */
158
-
159
112
  export function fromLittleEndian(littleEndian, pad = 2) {
160
113
  // It's a reversible function
161
114
  return toLittleEndian(littleEndian, pad);
162
115
  }
163
-
164
116
  function assertEthAddress(ethAddress) {
165
117
  if (!isHexEthAddress(ethAddress)) throw new TypeError('invalid ETH address');
166
118
  }
167
-
168
119
  function assertSwarmNetworkId(networkId) {
169
120
  if (Number.isInteger(networkId && networkId > 0 && networkId < Number.MAX_SAFE_INTEGER)) {
170
121
  throw new TypeError('swarm network id must be positive integer');
@@ -178,8 +129,6 @@ function assertSwarmNetworkId(networkId) {
178
129
  *
179
130
  * @return Swarm overlay address
180
131
  */
181
-
182
-
183
132
  export function ethToSwarmAddress(ethAddress, networkId = 1) {
184
133
  assertEthAddress(ethAddress);
185
134
  assertSwarmNetworkId(networkId);
@@ -195,41 +144,34 @@ export function ethToSwarmAddress(ethAddress, networkId = 1) {
195
144
  * @param provider Injected web3 provider like window.ethereum or other compatible with EIP-1193
196
145
  * @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.
197
146
  */
198
-
199
- export function makeEthereumWalletSigner(provider, ethAddress) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- let executorFnc;
202
-
203
- if (typeof provider !== 'object' || provider === null) {
204
- throw new TypeError('We need JsonRPC provider object!');
205
- }
206
-
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
- }
214
-
215
- if (!ethAddress) {
216
- ethAddress = (yield executorFnc({
217
- method: 'eth_requestAccounts'
218
- }))[0];
147
+ export async function makeEthereumWalletSigner(provider, ethAddress) {
148
+ let executorFnc;
149
+ if (typeof provider !== 'object' || provider === null) {
150
+ throw new TypeError('We need JsonRPC provider object!');
151
+ }
152
+ if (provider.request) {
153
+ executorFnc = provider.request;
154
+ } else if (provider.sendAsync) {
155
+ executorFnc = provider.sendAsync;
156
+ } else {
157
+ throw new Error('Incompatible interface of given provider!');
158
+ }
159
+ if (!ethAddress) {
160
+ ethAddress = (await executorFnc({
161
+ method: 'eth_requestAccounts'
162
+ }))[0];
163
+ }
164
+ const bytesEthAddress = makeEthAddress(ethAddress);
165
+ const hexEthAddress = makeHexEthAddress(ethAddress);
166
+ return {
167
+ address: bytesEthAddress,
168
+ sign: async data => {
169
+ const result = await executorFnc({
170
+ jsonrpc: '2.0',
171
+ method: 'personal_sign',
172
+ params: ['0x' + data.hex(), '0x' + hexEthAddress]
173
+ });
174
+ return result;
219
175
  }
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
- });
176
+ };
235
177
  }
@@ -3,45 +3,12 @@
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
-
38
6
  export function isFile(file) {
39
7
  // browser
40
8
  if (typeof File === 'function') {
41
9
  return file instanceof File;
42
- } // node.js
43
-
44
-
10
+ }
11
+ // node.js
45
12
  const f = file;
46
13
  return typeof f === 'object' && typeof f.name === 'string' && (typeof f.stream === 'function' || typeof f.arrayBuffer === 'function');
47
14
  }
@@ -51,20 +18,14 @@ export function isFile(file) {
51
18
  *
52
19
  * @param file A File object
53
20
  */
54
-
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
60
-
61
-
62
- return new Promise(resolve => {
63
- const fr = new FileReader();
64
-
65
- fr.onload = () => resolve(fr.result);
66
-
67
- fr.readAsArrayBuffer(file);
68
- });
21
+ export async function fileArrayBuffer(file) {
22
+ if (file.arrayBuffer) {
23
+ return file.arrayBuffer();
24
+ }
25
+ // workaround for Safari where arrayBuffer is not supported on Files
26
+ return new Promise(resolve => {
27
+ const fr = new FileReader();
28
+ fr.onload = () => resolve(fr.result);
29
+ fr.readAsArrayBuffer(file);
69
30
  });
70
31
  }
@@ -9,7 +9,6 @@ const {
9
9
  *
10
10
  * @param messages Any number of messages (strings, byte arrays etc.)
11
11
  */
12
-
13
12
  export function keccak256Hash(...messages) {
14
13
  const hasher = keccak256.create();
15
14
  messages.forEach(bytes => hasher.update(bytes));
@@ -7,31 +7,24 @@ import { BeeError } from "./error.js";
7
7
  *
8
8
  * @returns the filename
9
9
  */
10
-
11
10
  function readContentDispositionFilename(header) {
12
11
  if (!header) {
13
12
  throw new BeeError('missing content-disposition header');
14
- } // Regex was found here
13
+ }
14
+ // Regex was found here
15
15
  // https://stackoverflow.com/questions/23054475/javascript-regex-for-extracting-filename-from-content-disposition-header
16
-
17
-
18
16
  const dispositionMatch = header.match(/filename\*?=['"]?(?:UTF-\d['"]*)?([^;\r\n"']*)['"]?;?/i);
19
-
20
17
  if (dispositionMatch && dispositionMatch.length > 0) {
21
18
  return dispositionMatch[1];
22
19
  }
23
-
24
20
  throw new BeeError('invalid content-disposition header');
25
21
  }
26
-
27
22
  function readTagUid(header) {
28
23
  if (!header) {
29
24
  return undefined;
30
25
  }
31
-
32
26
  return parseInt(header, 10);
33
27
  }
34
-
35
28
  export function readFileHeaders(headers) {
36
29
  const name = readContentDispositionFilename(headers.get('content-disposition'));
37
30
  const tagUid = readTagUid(headers.get('swarm-tag-uid'));
@@ -46,13 +39,12 @@ export function extractUploadHeaders(postageBatchId, options) {
46
39
  if (!postageBatchId) {
47
40
  throw new BeeError('Postage BatchID has to be specified!');
48
41
  }
49
-
50
42
  const headers = {
51
43
  'swarm-postage-batch-id': postageBatchId
52
44
  };
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();
45
+ if (options?.pin) headers['swarm-pin'] = String(options.pin);
46
+ if (options?.encrypt) headers['swarm-encrypt'] = String(options.encrypt);
47
+ if (options?.tag) headers['swarm-tag'] = String(options.tag);
48
+ if (typeof options?.deferred === 'boolean') headers['swarm-deferred-upload'] = options.deferred.toString();
57
49
  return headers;
58
50
  }