@ethersphere/bee-js 3.3.0 → 3.3.2-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 (91) hide show
  1. package/dist/cjs/chunk/bmt.js +7 -2
  2. package/dist/cjs/chunk/signer.js +9 -4
  3. package/dist/cjs/modules/debug/status.js +8 -8
  4. package/dist/cjs/package.json +1 -0
  5. package/dist/cjs/types/debug.js +1 -0
  6. package/dist/cjs/types/ky-options.js +8 -0
  7. package/dist/cjs/types/ky-universal/common.js +8 -0
  8. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  9. package/dist/cjs/types/ky-universal/retry.js +8 -0
  10. package/dist/cjs/utils/eth.js +8 -3
  11. package/dist/cjs/utils/hash.js +7 -2
  12. package/dist/cjs/utils/stream.js +14 -5
  13. package/dist/index.browser.min.js +3 -0
  14. package/dist/index.browser.min.js.LICENSE.txt +60 -0
  15. package/dist/index.browser.min.js.map +1 -0
  16. package/dist/mjs/bee-debug.js +608 -508
  17. package/dist/mjs/bee.js +935 -836
  18. package/dist/mjs/chunk/bmt.js +34 -24
  19. package/dist/mjs/chunk/cac.js +24 -22
  20. package/dist/mjs/chunk/serialize.js +9 -9
  21. package/dist/mjs/chunk/signer.js +92 -73
  22. package/dist/mjs/chunk/soc.js +78 -66
  23. package/dist/mjs/chunk/span.js +19 -16
  24. package/dist/mjs/feed/index.js +110 -101
  25. package/dist/mjs/feed/json.js +21 -17
  26. package/dist/mjs/feed/topic.js +18 -17
  27. package/dist/mjs/feed/type.js +5 -5
  28. package/dist/mjs/index.js +7 -7
  29. package/dist/mjs/modules/bytes.js +33 -30
  30. package/dist/mjs/modules/bzz.js +80 -77
  31. package/dist/mjs/modules/chunk.js +22 -20
  32. package/dist/mjs/modules/debug/balance.js +26 -22
  33. package/dist/mjs/modules/debug/chequebook.js +84 -65
  34. package/dist/mjs/modules/debug/chunk.js +15 -13
  35. package/dist/mjs/modules/debug/connectivity.js +34 -34
  36. package/dist/mjs/modules/debug/settlements.js +14 -12
  37. package/dist/mjs/modules/debug/stamps.js +52 -47
  38. package/dist/mjs/modules/debug/states.js +16 -14
  39. package/dist/mjs/modules/debug/status.js +58 -38
  40. package/dist/mjs/modules/debug/tag.js +8 -7
  41. package/dist/mjs/modules/debug/transactions.js +31 -25
  42. package/dist/mjs/modules/feed.js +39 -33
  43. package/dist/mjs/modules/pinning.js +34 -28
  44. package/dist/mjs/modules/pss.js +18 -14
  45. package/dist/mjs/modules/soc.js +18 -15
  46. package/dist/mjs/modules/status.js +6 -5
  47. package/dist/mjs/modules/stewardship.js +13 -12
  48. package/dist/mjs/modules/tag.js +38 -30
  49. package/dist/mjs/package.json +1 -0
  50. package/dist/mjs/types/debug.js +6 -4
  51. package/dist/mjs/types/index.js +6 -2
  52. package/dist/mjs/types/ky-options.js +7 -0
  53. package/dist/mjs/types/ky-universal/common.js +7 -0
  54. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  55. package/dist/mjs/types/ky-universal/retry.js +7 -0
  56. package/dist/mjs/utils/bytes.js +32 -26
  57. package/dist/mjs/utils/collection.browser.js +4 -3
  58. package/dist/mjs/utils/collection.js +47 -35
  59. package/dist/mjs/utils/collection.node.js +53 -42
  60. package/dist/mjs/utils/data.browser.js +64 -48
  61. package/dist/mjs/utils/data.js +29 -25
  62. package/dist/mjs/utils/error.js +47 -39
  63. package/dist/mjs/utils/eth.js +119 -104
  64. package/dist/mjs/utils/expose.js +9 -9
  65. package/dist/mjs/utils/file.js +22 -19
  66. package/dist/mjs/utils/hash.js +10 -5
  67. package/dist/mjs/utils/headers.js +43 -39
  68. package/dist/mjs/utils/hex.js +78 -63
  69. package/dist/mjs/utils/http.js +119 -100
  70. package/dist/mjs/utils/merge.js +26 -20
  71. package/dist/mjs/utils/pss.js +8 -6
  72. package/dist/mjs/utils/stamps.js +7 -3
  73. package/dist/mjs/utils/stream.js +107 -82
  74. package/dist/mjs/utils/tar.js +17 -14
  75. package/dist/mjs/utils/type.js +249 -209
  76. package/dist/mjs/utils/uint64.js +16 -16
  77. package/dist/mjs/utils/url.js +32 -25
  78. package/dist/types/bee-debug.d.ts +3 -3
  79. package/dist/types/modules/debug/stamps.d.ts +3 -3
  80. package/dist/types/modules/debug/status.d.ts +3 -3
  81. package/dist/types/types/debug.d.ts +1 -0
  82. package/dist/types/types/index.d.ts +2 -2
  83. package/dist/types/types/ky-options.d.ts +221 -0
  84. package/dist/types/types/ky-universal/common.d.ts +13 -0
  85. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  86. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  87. package/dist/types/utils/stamps.d.ts +2 -2
  88. package/dist/types/utils/stream.d.ts +11 -8
  89. package/package.json +22 -19
  90. package/dist/index.js +0 -28326
  91. package/dist/index.js.map +0 -1
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.bmtHash = void 0;
4
- const js_sha3_1 = require("js-sha3");
7
+ // For ESM compatibility
8
+ const js_sha3_1 = __importDefault(require("js-sha3"));
9
+ const { keccak256 } = js_sha3_1.default;
5
10
  const error_1 = require("../utils/error");
6
11
  const hash_1 = require("../utils/hash");
7
12
  const MAX_CHUNK_PAYLOAD_SIZE = 4096;
@@ -41,7 +46,7 @@ function bmtRootHash(payload) {
41
46
  const output = new Uint8Array(input.length / 2);
42
47
  // in each round we hash the segment pairs together
43
48
  for (let offset = 0; offset < input.length; offset += SEGMENT_PAIR_SIZE) {
44
- const hashNumbers = js_sha3_1.keccak256.array(input.slice(offset, offset + SEGMENT_PAIR_SIZE));
49
+ const hashNumbers = keccak256.array(input.slice(offset, offset + SEGMENT_PAIR_SIZE));
45
50
  output.set(hashNumbers, offset / 2);
46
51
  }
47
52
  input = output;
@@ -8,9 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.sign = exports.makeSigner = exports.assertSigner = exports.makePrivateKeySigner = exports.recoverAddress = exports.defaultSign = void 0;
13
- const elliptic_1 = require("elliptic");
16
+ // For ESM compatibility
17
+ const elliptic_1 = __importDefault(require("elliptic"));
18
+ const { ec } = elliptic_1.default;
14
19
  const error_1 = require("../utils/error");
15
20
  const bytes_1 = require("../utils/bytes");
16
21
  const hash_1 = require("../utils/hash");
@@ -31,7 +36,7 @@ function hashWithEthereumPrefix(data) {
31
36
  * @param privateKey The private key used for signing the data
32
37
  */
33
38
  function defaultSign(data, privateKey) {
34
- const curve = new elliptic_1.ec('secp256k1');
39
+ const curve = new ec('secp256k1');
35
40
  const keyPair = curve.keyFromPrivate(privateKey);
36
41
  const hashedDigest = hashWithEthereumPrefix(data);
37
42
  const sigRaw = curve.sign(hashedDigest, keyPair, { canonical: true, pers: undefined });
@@ -62,7 +67,7 @@ function publicKeyToAddress(pubKey) {
62
67
  * @returns the recovered address
63
68
  */
64
69
  function recoverAddress(signature, digest) {
65
- const curve = new elliptic_1.ec('secp256k1');
70
+ const curve = new ec('secp256k1');
66
71
  const sig = {
67
72
  r: signature.slice(0, 32),
68
73
  s: signature.slice(32, 64),
@@ -79,7 +84,7 @@ exports.recoverAddress = recoverAddress;
79
84
  * @param privateKey The private key
80
85
  */
81
86
  function makePrivateKeySigner(privateKey) {
82
- const curve = new elliptic_1.ec('secp256k1');
87
+ const curve = new ec('secp256k1');
83
88
  const keyPair = curve.keyFromPrivate(privateKey);
84
89
  const address = publicKeyToAddress(keyPair.getPublic());
85
90
  return {
@@ -14,12 +14,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedDebugApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getHealth = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_DEBUG_API_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
16
16
  const http_1 = require("../../utils/http");
17
- const major_1 = __importDefault(require("semver/functions/major"));
17
+ const major_js_1 = __importDefault(require("semver/functions/major.js"));
18
18
  // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
19
19
  // so if you are changing anything about them change the `update_bee` action accordingly!
20
- exports.SUPPORTED_BEE_VERSION_EXACT = '1.4.3-1213e063';
21
- exports.SUPPORTED_API_VERSION = '2.0.0';
22
- exports.SUPPORTED_DEBUG_API_VERSION = '1.2.1';
20
+ exports.SUPPORTED_BEE_VERSION_EXACT = '1.5.0-dda5606e';
21
+ exports.SUPPORTED_API_VERSION = '3.0.0';
22
+ exports.SUPPORTED_DEBUG_API_VERSION = '2.0.0';
23
23
  exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.substring(0, exports.SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
24
24
  const NODE_INFO_URL = 'node';
25
25
  const HEALTH_URL = 'health';
@@ -97,7 +97,7 @@ exports.isSupportedExactVersion = isSupportedExactVersion;
97
97
  function isSupportedMainApiVersion(ky) {
98
98
  return __awaiter(this, void 0, void 0, function* () {
99
99
  const { apiVersion } = yield getHealth(ky);
100
- return (0, major_1.default)(apiVersion) === (0, major_1.default)(exports.SUPPORTED_API_VERSION);
100
+ return (0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(exports.SUPPORTED_API_VERSION);
101
101
  });
102
102
  }
103
103
  exports.isSupportedMainApiVersion = isSupportedMainApiVersion;
@@ -112,7 +112,7 @@ exports.isSupportedMainApiVersion = isSupportedMainApiVersion;
112
112
  function isSupportedDebugApiVersion(ky) {
113
113
  return __awaiter(this, void 0, void 0, function* () {
114
114
  const { debugApiVersion } = yield getHealth(ky);
115
- return (0, major_1.default)(debugApiVersion) === (0, major_1.default)(exports.SUPPORTED_DEBUG_API_VERSION);
115
+ return (0, major_js_1.default)(debugApiVersion) === (0, major_js_1.default)(exports.SUPPORTED_DEBUG_API_VERSION);
116
116
  });
117
117
  }
118
118
  exports.isSupportedDebugApiVersion = isSupportedDebugApiVersion;
@@ -126,8 +126,8 @@ exports.isSupportedDebugApiVersion = isSupportedDebugApiVersion;
126
126
  function isSupportedApiVersion(ky) {
127
127
  return __awaiter(this, void 0, void 0, function* () {
128
128
  const { apiVersion, debugApiVersion } = yield getHealth(ky);
129
- return ((0, major_1.default)(apiVersion) === (0, major_1.default)(exports.SUPPORTED_API_VERSION) &&
130
- (0, major_1.default)(debugApiVersion) === (0, major_1.default)(exports.SUPPORTED_DEBUG_API_VERSION));
129
+ return ((0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(exports.SUPPORTED_API_VERSION) &&
130
+ (0, major_js_1.default)(debugApiVersion) === (0, major_js_1.default)(exports.SUPPORTED_DEBUG_API_VERSION));
131
131
  });
132
132
  }
133
133
  exports.isSupportedApiVersion = isSupportedApiVersion;
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "type": "commonjs",
3
3
  "browser": {
4
+ "stream": false,
4
5
  "./utils/data.js": "./utils/data.browser.js",
5
6
  "./utils/collection.node.js": "./utils/collection.browser.js"
6
7
  }
@@ -5,5 +5,6 @@ var BeeModes;
5
5
  (function (BeeModes) {
6
6
  BeeModes["FULL"] = "full";
7
7
  BeeModes["LIGHT"] = "light";
8
+ BeeModes["ULTRA_LIGHT"] = "ultra-light";
8
9
  BeeModes["DEV"] = "dev";
9
10
  })(BeeModes = exports.BeeModes || (exports.BeeModes = {}));
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Types extracted from Ky as a backport for older Ky non-ESM version
4
+ *
5
+ * @author https://github.com/sindresorhus
6
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Types extracted from Ky as a backport for older Ky non-ESM version
4
+ *
5
+ * @author https://github.com/sindresorhus
6
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Types extracted from Ky as a backport for older Ky non-ESM version
4
+ *
5
+ * @author https://github.com/sindresorhus
6
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Types extracted from Ky as a backport for older Ky non-ESM version
4
+ *
5
+ * @author https://github.com/sindresorhus
6
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -8,9 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.makeEthereumWalletSigner = exports.ethToSwarmAddress = exports.fromLittleEndian = exports.toLittleEndian = exports.isHexEthAddress = exports.makeHexEthAddress = exports.makeEthAddress = void 0;
13
- const js_sha3_1 = require("js-sha3");
16
+ // For ESM compatibility
17
+ const js_sha3_1 = __importDefault(require("js-sha3"));
18
+ const { keccak256, sha3_256 } = js_sha3_1.default;
14
19
  const hex_1 = require("./hex");
15
20
  const bytes_1 = require("./bytes");
16
21
  const ETH_ADDR_BYTES_LENGTH = 20;
@@ -60,7 +65,7 @@ function isValidChecksummedEthAddress(address) {
60
65
  // Check for valid case insensitive hex type string, 40 chars
61
66
  const addr = (0, hex_1.makeHexString)(address, ETH_ADDR_HEX_LENGTH);
62
67
  // Check the checksum
63
- const addressHash = (0, js_sha3_1.keccak256)(addr.toLowerCase());
68
+ const addressHash = keccak256(addr.toLowerCase());
64
69
  for (let i = 0; i < 40; i += 1) {
65
70
  // the nth letter should be uppercase if the nth digit of casemap is 1
66
71
  if ((parseInt(addressHash[i], 16) > 7 && addr[i].toUpperCase() !== addr[i]) ||
@@ -159,7 +164,7 @@ function ethToSwarmAddress(ethAddress, networkId = 1) {
159
164
  assertSwarmNetworkId(networkId);
160
165
  const hex = `${(0, hex_1.makeHexString)(ethAddress)}${toLittleEndian(networkId, 16)}`;
161
166
  (0, hex_1.assertHexString)(hex);
162
- const overlayAddress = (0, js_sha3_1.sha3_256)((0, hex_1.hexToBytes)(hex));
167
+ const overlayAddress = sha3_256((0, hex_1.hexToBytes)(hex));
163
168
  return overlayAddress;
164
169
  }
165
170
  exports.ethToSwarmAddress = ethToSwarmAddress;
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.keccak256Hash = void 0;
4
- const js_sha3_1 = require("js-sha3");
7
+ // For ESM compatibility
8
+ const js_sha3_1 = __importDefault(require("js-sha3"));
9
+ const { keccak256 } = js_sha3_1.default;
5
10
  /**
6
11
  * Helper function for calculating the keccak256 hash with
7
12
  * correct types.
@@ -9,7 +14,7 @@ const js_sha3_1 = require("js-sha3");
9
14
  * @param messages Any number of messages (strings, byte arrays etc.)
10
15
  */
11
16
  function keccak256Hash(...messages) {
12
- const hasher = js_sha3_1.keccak256.create();
17
+ const hasher = keccak256.create();
13
18
  messages.forEach(bytes => hasher.update(bytes));
14
19
  return Uint8Array.from(hasher.digest());
15
20
  }
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeToReadableStream = exports.readableWebToNode = exports.readableNodeToWeb = exports.isNodeReadable = exports.isReadableStream = exports.isReadable = void 0;
4
+ const stream_1 = require("stream");
4
5
  const type_1 = require("./type");
5
- const ponyfill_1 = require("web-streams-polyfill/ponyfill");
6
- const readable_stream_1 = require("readable-stream");
6
+ const web_streams_polyfill_1 = require("web-streams-polyfill");
7
+ const NodeReadable = stream_1.Readable || class {
8
+ };
7
9
  /**
8
10
  * Validates if passed object is either browser's ReadableStream
9
11
  * or Node's Readable.
@@ -51,7 +53,7 @@ exports.isNodeReadable = isNodeReadable;
51
53
  * @param nodeStream
52
54
  */
53
55
  function readableNodeToWeb(nodeStream) {
54
- return new ponyfill_1.ReadableStream({
56
+ return new web_streams_polyfill_1.ReadableStream({
55
57
  start(controller) {
56
58
  nodeStream.pause();
57
59
  nodeStream.on('data', chunk => {
@@ -82,7 +84,7 @@ exports.readableNodeToWeb = readableNodeToWeb;
82
84
  * @author https://github.com/gwicke
83
85
  * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
84
86
  */
85
- class NodeReadableWrapper extends readable_stream_1.Readable {
87
+ class NodeReadableWrapper extends NodeReadable {
86
88
  constructor(webStream, options) {
87
89
  super(options);
88
90
  this._webStream = webStream;
@@ -115,13 +117,20 @@ class NodeReadableWrapper extends readable_stream_1.Readable {
115
117
  * Function that converts WHATWG ReadableStream into Node's Readable
116
118
  *
117
119
  * Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
118
- * Because it uses forked web-streams-polyfill that are outdated.
120
+ * Because it uses forked web-streams-polyfill that is outdated.
121
+ *
122
+ * **Warning!**
123
+ * If you want to use this function in browser you have to polyfill `stream` package with your bundler.
119
124
  *
120
125
  * @author https://github.com/gwicke
121
126
  * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
122
127
  * @param webStream
128
+ * @param options
123
129
  */
124
130
  function readableWebToNode(webStream, options) {
131
+ if (!stream_1.Readable) {
132
+ throw new Error("The Node's Readable is not available! If you are running this in browser you have to polyfill 'stream' package!");
133
+ }
125
134
  return new NodeReadableWrapper(webStream, options);
126
135
  }
127
136
  exports.readableWebToNode = readableWebToNode;