@ethersphere/bee-js 4.1.1 → 6.0.0-pre.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 (197) hide show
  1. package/README.md +11 -3
  2. package/dist/index.browser.js +33 -0
  3. package/dist/index.browser.js.map +7 -0
  4. package/dist/src/bee-debug.js +624 -0
  5. package/dist/{mjs → src}/bee.js +243 -338
  6. package/dist/{mjs → src}/chunk/bmt.js +0 -0
  7. package/dist/{mjs → src}/chunk/cac.js +0 -0
  8. package/dist/{mjs → src}/chunk/serialize.js +0 -0
  9. package/dist/{mjs → src}/chunk/signer.js +13 -47
  10. package/dist/{mjs → src}/chunk/soc.js +31 -71
  11. package/dist/{mjs → src}/chunk/span.js +1 -1
  12. package/dist/{mjs → src}/feed/identifier.js +0 -0
  13. package/dist/src/feed/index.js +92 -0
  14. package/dist/src/feed/json.js +27 -0
  15. package/dist/src/feed/retrievable.js +67 -0
  16. package/dist/{mjs → src}/feed/topic.js +0 -0
  17. package/dist/{mjs → src}/feed/type.js +0 -0
  18. package/dist/{mjs → src}/index.js +1 -2
  19. package/dist/src/modules/bytes.js +59 -0
  20. package/dist/src/modules/bzz.js +122 -0
  21. package/dist/src/modules/chunk.js +45 -0
  22. package/dist/src/modules/debug/balance.js +57 -0
  23. package/dist/src/modules/debug/chequebook.js +150 -0
  24. package/dist/src/modules/debug/chunk.js +35 -0
  25. package/dist/src/modules/debug/connectivity.js +45 -0
  26. package/dist/src/modules/debug/settlements.js +29 -0
  27. package/dist/src/modules/debug/stamps.js +64 -0
  28. package/dist/src/modules/debug/states.js +46 -0
  29. package/dist/src/modules/debug/status.js +134 -0
  30. package/dist/src/modules/debug/tag.js +16 -0
  31. package/dist/src/modules/debug/transactions.js +69 -0
  32. package/dist/src/modules/feed.js +67 -0
  33. package/dist/src/modules/pinning.js +60 -0
  34. package/dist/src/modules/pss.js +40 -0
  35. package/dist/src/modules/soc.js +31 -0
  36. package/dist/src/modules/status.js +12 -0
  37. package/dist/src/modules/stewardship.js +24 -0
  38. package/dist/src/modules/tag.js +77 -0
  39. package/dist/{mjs → src}/types/debug.js +0 -0
  40. package/dist/{mjs → src}/types/index.js +0 -0
  41. package/dist/{mjs → src}/utils/bytes.js +3 -2
  42. package/dist/src/utils/collection-browser.js +19 -0
  43. package/dist/src/utils/collection-node.js +74 -0
  44. package/dist/src/utils/collection.js +64 -0
  45. package/dist/src/utils/data.browser.js +72 -0
  46. package/dist/src/utils/data.js +42 -0
  47. package/dist/{mjs → src}/utils/error.js +0 -0
  48. package/dist/{mjs → src}/utils/eth.js +32 -68
  49. package/dist/{mjs → src}/utils/expose.js +1 -1
  50. package/dist/src/utils/file.js +36 -0
  51. package/dist/{mjs → src}/utils/hash.js +0 -0
  52. package/dist/{mjs → src}/utils/headers.js +4 -4
  53. package/dist/{mjs → src}/utils/hex.js +0 -0
  54. package/dist/src/utils/http.js +162 -0
  55. package/dist/{mjs → src}/utils/merge.js +2 -2
  56. package/dist/{mjs → src}/utils/pss.js +0 -0
  57. package/dist/{mjs → src}/utils/reference.js +0 -0
  58. package/dist/src/utils/sleep.js +8 -0
  59. package/dist/{mjs → src}/utils/stamps.js +0 -0
  60. package/dist/{mjs → src}/utils/stream.js +3 -3
  61. package/dist/{mjs → src}/utils/tar.js +0 -0
  62. package/dist/{mjs → src}/utils/type.js +13 -14
  63. package/dist/{mjs → src}/utils/uint64.js +0 -0
  64. package/dist/{mjs → src}/utils/url.js +0 -0
  65. package/dist/types/bee.d.ts +2 -3
  66. package/dist/types/chunk/bmt.d.ts +1 -1
  67. package/dist/types/chunk/soc.d.ts +1 -1
  68. package/dist/types/chunk/span.d.ts +1 -1
  69. package/dist/types/feed/index.d.ts +1 -1
  70. package/dist/types/index.d.ts +0 -13
  71. package/dist/types/modules/bzz.d.ts +1 -1
  72. package/dist/types/modules/debug/status.d.ts +3 -3
  73. package/dist/types/modules/pinning.d.ts +1 -1
  74. package/dist/types/types/debug.d.ts +2 -7
  75. package/dist/types/types/index.d.ts +33 -16
  76. package/dist/types/utils/{collection.browser.d.ts → collection-browser.d.ts} +0 -0
  77. package/dist/types/utils/{collection.node.d.ts → collection-node.d.ts} +0 -0
  78. package/dist/types/utils/error.d.ts +1 -1
  79. package/dist/types/utils/eth.d.ts +3 -3
  80. package/dist/types/utils/expose.d.ts +7 -4
  81. package/dist/types/utils/hash.d.ts +1 -1
  82. package/dist/types/utils/hex.d.ts +2 -2
  83. package/dist/types/utils/http.d.ts +3 -3
  84. package/dist/types/utils/stream.d.ts +1 -1
  85. package/dist/types/utils/type.d.ts +6 -2
  86. package/dist/types/utils/uint64.d.ts +1 -1
  87. package/package.json +50 -65
  88. package/dist/cjs/bee-debug.js +0 -638
  89. package/dist/cjs/bee.js +0 -977
  90. package/dist/cjs/chunk/bmt.js +0 -55
  91. package/dist/cjs/chunk/cac.js +0 -56
  92. package/dist/cjs/chunk/serialize.js +0 -19
  93. package/dist/cjs/chunk/signer.js +0 -137
  94. package/dist/cjs/chunk/soc.js +0 -172
  95. package/dist/cjs/chunk/span.js +0 -29
  96. package/dist/cjs/feed/identifier.js +0 -35
  97. package/dist/cjs/feed/index.js +0 -128
  98. package/dist/cjs/feed/json.js +0 -41
  99. package/dist/cjs/feed/retrievable.js +0 -72
  100. package/dist/cjs/feed/topic.js +0 -25
  101. package/dist/cjs/feed/type.js +0 -15
  102. package/dist/cjs/index.js +0 -35
  103. package/dist/cjs/modules/bytes.js +0 -74
  104. package/dist/cjs/modules/bzz.js +0 -131
  105. package/dist/cjs/modules/chunk.js +0 -58
  106. package/dist/cjs/modules/debug/balance.js +0 -77
  107. package/dist/cjs/modules/debug/chequebook.js +0 -167
  108. package/dist/cjs/modules/debug/chunk.js +0 -51
  109. package/dist/cjs/modules/debug/connectivity.js +0 -75
  110. package/dist/cjs/modules/debug/settlements.js +0 -45
  111. package/dist/cjs/modules/debug/stamps.js +0 -89
  112. package/dist/cjs/modules/debug/states.js +0 -64
  113. package/dist/cjs/modules/debug/status.js +0 -153
  114. package/dist/cjs/modules/debug/tag.js +0 -30
  115. package/dist/cjs/modules/debug/transactions.js +0 -81
  116. package/dist/cjs/modules/feed.js +0 -76
  117. package/dist/cjs/modules/pinning.js +0 -84
  118. package/dist/cjs/modules/pss.js +0 -55
  119. package/dist/cjs/modules/soc.js +0 -40
  120. package/dist/cjs/modules/status.js +0 -26
  121. package/dist/cjs/modules/stewardship.js +0 -41
  122. package/dist/cjs/modules/tag.js +0 -96
  123. package/dist/cjs/package.json +0 -8
  124. package/dist/cjs/types/debug.js +0 -10
  125. package/dist/cjs/types/index.js +0 -47
  126. package/dist/cjs/types/ky-options.js +0 -8
  127. package/dist/cjs/types/ky-universal/common.js +0 -8
  128. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  129. package/dist/cjs/types/ky-universal/retry.js +0 -8
  130. package/dist/cjs/utils/bytes.js +0 -121
  131. package/dist/cjs/utils/collection.browser.js +0 -36
  132. package/dist/cjs/utils/collection.js +0 -70
  133. package/dist/cjs/utils/collection.node.js +0 -115
  134. package/dist/cjs/utils/data.browser.js +0 -74
  135. package/dist/cjs/utils/data.js +0 -58
  136. package/dist/cjs/utils/error.js +0 -50
  137. package/dist/cjs/utils/eth.js +0 -211
  138. package/dist/cjs/utils/expose.js +0 -44
  139. package/dist/cjs/utils/file.js +0 -49
  140. package/dist/cjs/utils/hash.js +0 -21
  141. package/dist/cjs/utils/headers.js +0 -59
  142. package/dist/cjs/utils/hex.js +0 -150
  143. package/dist/cjs/utils/http.js +0 -172
  144. package/dist/cjs/utils/merge.js +0 -34
  145. package/dist/cjs/utils/pss.js +0 -18
  146. package/dist/cjs/utils/reference.js +0 -36
  147. package/dist/cjs/utils/sleep.js +0 -23
  148. package/dist/cjs/utils/stamps.js +0 -17
  149. package/dist/cjs/utils/stream.js +0 -146
  150. package/dist/cjs/utils/tar.js +0 -25
  151. package/dist/cjs/utils/type.js +0 -426
  152. package/dist/cjs/utils/uint64.js +0 -29
  153. package/dist/cjs/utils/url.js +0 -56
  154. package/dist/index.browser.min.js +0 -3
  155. package/dist/index.browser.min.js.LICENSE.txt +0 -60
  156. package/dist/index.browser.min.js.map +0 -1
  157. package/dist/mjs/bee-debug.js +0 -744
  158. package/dist/mjs/feed/index.js +0 -134
  159. package/dist/mjs/feed/json.js +0 -63
  160. package/dist/mjs/feed/retrievable.js +0 -105
  161. package/dist/mjs/modules/bytes.js +0 -96
  162. package/dist/mjs/modules/bzz.js +0 -160
  163. package/dist/mjs/modules/chunk.js +0 -80
  164. package/dist/mjs/modules/debug/balance.js +0 -97
  165. package/dist/mjs/modules/debug/chequebook.js +0 -198
  166. package/dist/mjs/modules/debug/chunk.js +0 -71
  167. package/dist/mjs/modules/debug/connectivity.js +0 -89
  168. package/dist/mjs/modules/debug/settlements.js +0 -65
  169. package/dist/mjs/modules/debug/stamps.js +0 -108
  170. package/dist/mjs/modules/debug/states.js +0 -84
  171. package/dist/mjs/modules/debug/status.js +0 -182
  172. package/dist/mjs/modules/debug/tag.js +0 -50
  173. package/dist/mjs/modules/debug/transactions.js +0 -103
  174. package/dist/mjs/modules/feed.js +0 -101
  175. package/dist/mjs/modules/pinning.js +0 -106
  176. package/dist/mjs/modules/pss.js +0 -74
  177. package/dist/mjs/modules/soc.js +0 -64
  178. package/dist/mjs/modules/status.js +0 -46
  179. package/dist/mjs/modules/stewardship.js +0 -60
  180. package/dist/mjs/modules/tag.js +0 -119
  181. package/dist/mjs/package.json +0 -8
  182. package/dist/mjs/types/ky-options.js +0 -7
  183. package/dist/mjs/types/ky-universal/common.js +0 -7
  184. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  185. package/dist/mjs/types/ky-universal/retry.js +0 -7
  186. package/dist/mjs/utils/collection.browser.js +0 -56
  187. package/dist/mjs/utils/collection.js +0 -98
  188. package/dist/mjs/utils/collection.node.js +0 -169
  189. package/dist/mjs/utils/data.browser.js +0 -108
  190. package/dist/mjs/utils/data.js +0 -78
  191. package/dist/mjs/utils/file.js +0 -70
  192. package/dist/mjs/utils/http.js +0 -208
  193. package/dist/mjs/utils/sleep.js +0 -43
  194. package/dist/types/types/ky-options.d.ts +0 -221
  195. package/dist/types/types/ky-universal/common.d.ts +0 -13
  196. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  197. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getCollectionSize = exports.makeCollectionFromFileList = exports.assertCollection = exports.isCollection = void 0;
13
- const error_1 = require("./error");
14
- const file_1 = require("./file");
15
- const type_1 = require("./type");
16
- function isCollection(data) {
17
- if (!Array.isArray(data)) {
18
- return false;
19
- }
20
- return data.every(entry => typeof entry === 'object' && entry.data && entry.path && (0, type_1.isUint8Array)(entry.data));
21
- }
22
- exports.isCollection = isCollection;
23
- function assertCollection(data) {
24
- if (!isCollection(data)) {
25
- throw new error_1.BeeArgumentError('invalid collection', data);
26
- }
27
- }
28
- exports.assertCollection = assertCollection;
29
- function makeFilePath(file) {
30
- if (file.webkitRelativePath && file.webkitRelativePath !== '') {
31
- return file.webkitRelativePath.replace(/.*?\//i, '');
32
- }
33
- if (file.name) {
34
- return file.name;
35
- }
36
- throw new TypeError('file is not valid File object');
37
- }
38
- function makeCollectionFromFileList(fileList) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const collection = [];
41
- for (let i = 0; i < fileList.length; i++) {
42
- const file = fileList[i];
43
- if (file) {
44
- collection.push({
45
- path: makeFilePath(file),
46
- data: new Uint8Array(yield (0, file_1.fileArrayBuffer)(file)),
47
- });
48
- }
49
- }
50
- return collection;
51
- });
52
- }
53
- exports.makeCollectionFromFileList = makeCollectionFromFileList;
54
- /**
55
- * Calculate cumulative size of files
56
- *
57
- * @param fileList list of files to check
58
- * @returns size in bytes
59
- */
60
- function getCollectionSize(fileList) {
61
- let sum = 0;
62
- for (let i = 0; i < fileList.length; i++) {
63
- const file = fileList[i];
64
- if (file) {
65
- sum += file.size;
66
- }
67
- }
68
- return sum;
69
- }
70
- exports.getCollectionSize = getCollectionSize;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __importDefault = (this && this.__importDefault) || function (mod) {
19
- return (mod && mod.__esModule) ? mod : { "default": mod };
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getFolderSize = exports.makeCollectionFromFS = void 0;
23
- const fs_1 = __importDefault(require("fs"));
24
- const path_1 = __importDefault(require("path"));
25
- /**
26
- * Creates array in the format of Collection with data loaded from directory on filesystem.
27
- * The function loads all the data into memory!
28
- *
29
- * @param dir path to the directory
30
- */
31
- function makeCollectionFromFS(dir) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- if (typeof dir !== 'string') {
34
- throw new TypeError('dir has to be string!');
35
- }
36
- if (dir === '') {
37
- throw new TypeError('dir must not be empty string!');
38
- }
39
- return buildCollectionRelative(dir, '');
40
- });
41
- }
42
- exports.makeCollectionFromFS = makeCollectionFromFS;
43
- function buildCollectionRelative(dir, relativePath) {
44
- var e_1, _a;
45
- return __awaiter(this, void 0, void 0, function* () {
46
- // Handles case when the dir is not existing or it is a file ==> throws an error
47
- const dirname = path_1.default.join(dir, relativePath);
48
- const entries = yield fs_1.default.promises.opendir(dirname);
49
- let collection = [];
50
- try {
51
- for (var entries_1 = __asyncValues(entries), entries_1_1; entries_1_1 = yield entries_1.next(), !entries_1_1.done;) {
52
- const entry = entries_1_1.value;
53
- const fullPath = path_1.default.join(dir, relativePath, entry.name);
54
- const entryPath = path_1.default.join(relativePath, entry.name);
55
- if (entry.isFile()) {
56
- collection.push({
57
- path: entryPath,
58
- data: new Uint8Array(yield fs_1.default.promises.readFile(fullPath)),
59
- });
60
- }
61
- else if (entry.isDirectory()) {
62
- collection = [...(yield buildCollectionRelative(dir, entryPath)), ...collection];
63
- }
64
- }
65
- }
66
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
67
- finally {
68
- try {
69
- if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) yield _a.call(entries_1);
70
- }
71
- finally { if (e_1) throw e_1.error; }
72
- }
73
- return collection;
74
- });
75
- }
76
- /**
77
- * Calculate folder size recursively
78
- *
79
- * @param dir the path to the folder to check
80
- * @returns size in bytes
81
- */
82
- function getFolderSize(dir) {
83
- var e_2, _a;
84
- return __awaiter(this, void 0, void 0, function* () {
85
- if (typeof dir !== 'string') {
86
- throw new TypeError('dir has to be string!');
87
- }
88
- if (dir === '') {
89
- throw new TypeError('dir must not be empty string!');
90
- }
91
- const entries = yield fs_1.default.promises.opendir(dir);
92
- let size = 0;
93
- try {
94
- for (var entries_2 = __asyncValues(entries), entries_2_1; entries_2_1 = yield entries_2.next(), !entries_2_1.done;) {
95
- const entry = entries_2_1.value;
96
- if (entry.isFile()) {
97
- const stats = yield fs_1.default.promises.stat(path_1.default.join(dir, entry.name));
98
- size += stats.size;
99
- }
100
- else if (entry.isDirectory()) {
101
- size += yield getFolderSize(path_1.default.join(dir, entry.name));
102
- }
103
- }
104
- }
105
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
106
- finally {
107
- try {
108
- if (entries_2_1 && !entries_2_1.done && (_a = entries_2.return)) yield _a.call(entries_2);
109
- }
110
- finally { if (e_2) throw e_2.error; }
111
- }
112
- return size;
113
- });
114
- }
115
- exports.getFolderSize = getFolderSize;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.prepareWebsocketData = exports.prepareData = void 0;
13
- const stream_1 = require("./stream");
14
- /**
15
- * Validates input and converts to Uint8Array
16
- *
17
- * @param data any string, ArrayBuffer or Uint8Array
18
- */
19
- function prepareData(data) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- if (typeof data === 'string')
22
- return new Blob([data], { type: 'text/plain' });
23
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
24
- return new Blob([data], { type: 'application/octet-stream' });
25
- }
26
- if (data instanceof Blob) {
27
- return data;
28
- }
29
- // Currently it is not possible to stream requests from browsers
30
- // there are already first experiments on this field (Chromium)
31
- // but till it is fully implemented across browsers-land we have to
32
- // buffer the data before sending the requests.
33
- if ((0, stream_1.isNodeReadable)(data)) {
34
- return new Promise(resolve => {
35
- const buffers = [];
36
- data.on('data', d => {
37
- buffers.push(d);
38
- });
39
- data.on('end', () => {
40
- resolve(new Blob(buffers, { type: 'application/octet-stream' }));
41
- });
42
- });
43
- }
44
- if ((0, stream_1.isReadableStream)(data)) {
45
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
46
- const reader = data.getReader();
47
- const buffers = [];
48
- let done, value;
49
- do {
50
- ;
51
- ({ done, value } = yield reader.read());
52
- if (!done) {
53
- buffers.push(value);
54
- }
55
- } while (!done);
56
- resolve(new Blob(buffers, { type: 'application/octet-stream' }));
57
- }));
58
- }
59
- throw new TypeError('unknown data type');
60
- });
61
- }
62
- exports.prepareData = prepareData;
63
- function prepareWebsocketData(data) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- if (typeof data === 'string')
66
- return new TextEncoder().encode(data);
67
- if (data instanceof ArrayBuffer)
68
- return new Uint8Array(data);
69
- if (data instanceof Blob)
70
- return new Uint8Array(yield new Response(data).arrayBuffer());
71
- throw new TypeError('unknown websocket data type');
72
- });
73
- }
74
- exports.prepareWebsocketData = prepareWebsocketData;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.prepareWebsocketData = exports.prepareData = void 0;
16
- const fetch_blob_1 = __importDefault(require("fetch-blob"));
17
- const stream_1 = require("./stream");
18
- /**
19
- * Prepare data for valid input for node-fetch.
20
- *
21
- * node-fetch is not using WHATWG ReadableStream but NodeJS Readable so we need to convert in case of ReadableStream,
22
- * but the typings are set to use ReadableStream so hence why type conversion here.
23
- *
24
- * @param data any string, ArrayBuffer, Uint8Array or Readable
25
- */
26
- function prepareData(data) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- if (typeof data === 'string')
29
- return new fetch_blob_1.default([data], { type: 'text/plain' });
30
- if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
31
- return new fetch_blob_1.default([data], { type: 'application/octet-stream' });
32
- }
33
- if (data instanceof fetch_blob_1.default || (0, stream_1.isNodeReadable)(data))
34
- return data;
35
- if ((0, stream_1.isReadableStream)(data)) {
36
- return (0, stream_1.readableWebToNode)(data);
37
- }
38
- throw new TypeError('unknown data type');
39
- });
40
- }
41
- exports.prepareData = prepareData;
42
- function isBufferArray(buffer) {
43
- return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
44
- }
45
- function prepareWebsocketData(data) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- if (typeof data === 'string')
48
- return new TextEncoder().encode(data);
49
- if (data instanceof Buffer)
50
- return new Uint8Array(data);
51
- if (data instanceof ArrayBuffer)
52
- return new Uint8Array(data);
53
- if (isBufferArray(data))
54
- return new Uint8Array(Buffer.concat(data));
55
- throw new TypeError('unknown websocket data type');
56
- });
57
- }
58
- exports.prepareWebsocketData = prepareWebsocketData;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BeeNotAJsonError = exports.BeeResponseError = exports.BeeRequestError = exports.BeeArgumentError = exports.BeeError = void 0;
4
- class BeeError extends Error {
5
- constructor(message) {
6
- super(message);
7
- }
8
- }
9
- exports.BeeError = BeeError;
10
- class BeeArgumentError extends BeeError {
11
- constructor(message, value) {
12
- super(message);
13
- this.value = value;
14
- }
15
- }
16
- exports.BeeArgumentError = BeeArgumentError;
17
- class BeeRequestError extends BeeError {
18
- /**
19
- * @param message
20
- * @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
- */
22
- constructor(message, requestOptions) {
23
- super(message);
24
- this.requestOptions = requestOptions;
25
- }
26
- }
27
- exports.BeeRequestError = BeeRequestError;
28
- class BeeResponseError extends BeeError {
29
- /**
30
- * @param status HTTP status code number
31
- * @param response Response returned from the server
32
- * @param responseBody Response body as string which is returned from response.text() call
33
- * @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!
34
- * @param message
35
- */
36
- constructor(status, response, responseBody, requestOptions, message) {
37
- super(message);
38
- this.status = status;
39
- this.response = response;
40
- this.responseBody = responseBody;
41
- this.requestOptions = requestOptions;
42
- }
43
- }
44
- exports.BeeResponseError = BeeResponseError;
45
- class BeeNotAJsonError extends BeeError {
46
- constructor() {
47
- super(`Received response is not valid JSON.`);
48
- }
49
- }
50
- exports.BeeNotAJsonError = BeeNotAJsonError;
@@ -1,211 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.makeEthereumWalletSigner = exports.ethToSwarmAddress = exports.fromLittleEndian = exports.toLittleEndian = exports.isHexEthAddress = exports.makeHexEthAddress = exports.makeEthAddress = void 0;
16
- // For ESM compatibility
17
- const js_sha3_1 = __importDefault(require("js-sha3"));
18
- const { keccak256, sha3_256 } = js_sha3_1.default;
19
- const hex_1 = require("./hex");
20
- const bytes_1 = require("./bytes");
21
- const ETH_ADDR_BYTES_LENGTH = 20;
22
- const ETH_ADDR_HEX_LENGTH = 40;
23
- function makeEthAddress(address) {
24
- if (typeof address === 'string') {
25
- const hexAddr = (0, hex_1.makeHexString)(address, ETH_ADDR_HEX_LENGTH);
26
- const ownerBytes = (0, hex_1.hexToBytes)(hexAddr);
27
- (0, bytes_1.assertBytes)(ownerBytes, ETH_ADDR_BYTES_LENGTH);
28
- return ownerBytes;
29
- }
30
- else if (address instanceof Uint8Array) {
31
- (0, bytes_1.assertBytes)(address, ETH_ADDR_BYTES_LENGTH);
32
- return address;
33
- }
34
- throw new TypeError('Invalid EthAddress');
35
- }
36
- exports.makeEthAddress = makeEthAddress;
37
- function makeHexEthAddress(address) {
38
- try {
39
- return (0, hex_1.makeHexString)(address, ETH_ADDR_HEX_LENGTH);
40
- }
41
- catch (e) {
42
- if (e instanceof TypeError) {
43
- e.message = `Invalid HexEthAddress: ${e.message}`;
44
- }
45
- throw e;
46
- }
47
- }
48
- exports.makeHexEthAddress = makeHexEthAddress;
49
- /**
50
- * Check if this is all caps or small caps eth address (=address without checksum)
51
- *
52
- * @param address Ethereum address as hex string
53
- */
54
- function isEthAddrCaseIns(address) {
55
- // Check it's string, all small caps or all all caps hex and 40 chars long without the `0x` prefix
56
- return (typeof address === 'string' && (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)));
57
- }
58
- /**
59
- * Check if this is checksummed ethereum address
60
- *
61
- * @param address Ethereum address as hex string
62
- */
63
- function isValidChecksummedEthAddress(address) {
64
- try {
65
- // Check for valid case insensitive hex type string, 40 chars
66
- const addr = (0, hex_1.makeHexString)(address, ETH_ADDR_HEX_LENGTH);
67
- // Check the checksum
68
- const addressHash = keccak256(addr.toLowerCase());
69
- for (let i = 0; i < 40; i += 1) {
70
- // the nth letter should be uppercase if the nth digit of casemap is 1
71
- if ((parseInt(addressHash[i], 16) > 7 && addr[i].toUpperCase() !== addr[i]) ||
72
- (parseInt(addressHash[i], 16) <= 7 && addr[i].toLowerCase() !== addr[i])) {
73
- return false;
74
- }
75
- }
76
- return true;
77
- }
78
- catch (e) {
79
- if (e instanceof TypeError) {
80
- return false;
81
- }
82
- throw e;
83
- }
84
- }
85
- /**
86
- * Check if is valid ethereum address
87
- *
88
- * Pretty much typed version from web3js
89
- * https://github.com/ChainSafe/web3.js/blob/1.x/packages/web3-utils/src/utils.js
90
- *
91
- * @param address Ethereum address as hex string
92
- *
93
- * @return True if is valid eth address
94
- */
95
- function isHexEthAddress(address) {
96
- return isEthAddrCaseIns(address) || isValidChecksummedEthAddress(address);
97
- }
98
- exports.isHexEthAddress = isHexEthAddress;
99
- /**
100
- * Convert big-endian hex or number to little-endian.
101
- * Note: Before conversion it is automatically padded to even length hexstring
102
- *
103
- * @param bigEndian Big-endian hex string or number to convert
104
- * @param pad Length to which the string should be padded before conversion (defaul: 2)
105
- *
106
- * @return little-endian encoded hexstring
107
- */
108
- function toLittleEndian(bigEndian, pad = 2) {
109
- var _a;
110
- if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
111
- throw new TypeError('minimal padding for conversion needs to be positive even integer');
112
- }
113
- let hexRep;
114
- if (typeof bigEndian === 'string')
115
- hexRep = (0, hex_1.makeHexString)(bigEndian);
116
- else if (typeof bigEndian === 'number')
117
- hexRep = (0, hex_1.intToHex)(bigEndian);
118
- else
119
- throw new TypeError('incorrect input type');
120
- hexRep = hexRep.padStart(pad, '0');
121
- // Extend to an even length hexstring
122
- if (hexRep.length % 2 !== 0)
123
- hexRep = hexRep.padStart(hexRep.length + 1, '0');
124
- // Match all two pairs in the hexstring, reverse the pairs and join it again
125
- const littleEndian = (_a = hexRep.match(/../g)) === null || _a === void 0 ? void 0 : _a.reverse().join('');
126
- if (littleEndian)
127
- return littleEndian;
128
- throw new Error('failed to convert');
129
- }
130
- exports.toLittleEndian = toLittleEndian;
131
- /**
132
- * Convert little-endian hex or number to big-endian
133
- * Note: Before conversion it is automatically padded to even length hexstring
134
- *
135
- * @param littleEndian Little-endian hex string or number to convert
136
- * @param pad Length to which the string should be padded before conversion (defaul: 2)
137
- *
138
- * @return big-endian encoded hexstring
139
- */
140
- function fromLittleEndian(littleEndian, pad = 2) {
141
- // It's a reversible function
142
- return toLittleEndian(littleEndian, pad);
143
- }
144
- exports.fromLittleEndian = fromLittleEndian;
145
- function assertEthAddress(ethAddress) {
146
- if (!isHexEthAddress(ethAddress))
147
- throw new TypeError('invalid ETH address');
148
- }
149
- function assertSwarmNetworkId(networkId) {
150
- if (Number.isInteger(networkId && networkId > 0 && networkId < Number.MAX_SAFE_INTEGER)) {
151
- throw new TypeError('swarm network id must be positive integer');
152
- }
153
- }
154
- /**
155
- * Get swarm overlay address from public ethereum address and swarm network id
156
- *
157
- * @param ethAddress Public ethereum address
158
- * @param networkId Swarm network id
159
- *
160
- * @return Swarm overlay address
161
- */
162
- function ethToSwarmAddress(ethAddress, networkId = 1) {
163
- assertEthAddress(ethAddress);
164
- assertSwarmNetworkId(networkId);
165
- const hex = `${(0, hex_1.makeHexString)(ethAddress)}${toLittleEndian(networkId, 16)}`;
166
- (0, hex_1.assertHexString)(hex);
167
- const overlayAddress = sha3_256((0, hex_1.hexToBytes)(hex));
168
- return overlayAddress;
169
- }
170
- exports.ethToSwarmAddress = ethToSwarmAddress;
171
- /**
172
- * Function that takes Ethereum EIP-1193 compatible provider and create an Signer instance that
173
- * uses `personal_sign` method to sign requested data.
174
- *
175
- * @param provider Injected web3 provider like window.ethereum or other compatible with EIP-1193
176
- * @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.
177
- */
178
- function makeEthereumWalletSigner(provider, ethAddress) {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- let executorFnc;
181
- if (typeof provider !== 'object' || provider === null) {
182
- throw new TypeError('We need JsonRPC provider object!');
183
- }
184
- if (provider.request) {
185
- executorFnc = provider.request;
186
- }
187
- else if (provider.sendAsync) {
188
- executorFnc = provider.sendAsync;
189
- }
190
- else {
191
- throw new Error('Incompatible interface of given provider!');
192
- }
193
- if (!ethAddress) {
194
- ethAddress = (yield executorFnc({ method: 'eth_requestAccounts' }))[0];
195
- }
196
- const bytesEthAddress = makeEthAddress(ethAddress);
197
- const hexEthAddress = makeHexEthAddress(ethAddress);
198
- return {
199
- address: bytesEthAddress,
200
- sign: (data) => __awaiter(this, void 0, void 0, function* () {
201
- const result = yield executorFnc({
202
- jsonrpc: '2.0',
203
- method: 'personal_sign',
204
- params: ['0x' + data.hex(), '0x' + hexEthAddress],
205
- });
206
- return result;
207
- }),
208
- };
209
- });
210
- }
211
- exports.makeEthereumWalletSigner = makeEthereumWalletSigner;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStampUsage = exports.makeMaxTarget = exports.keccak256Hash = exports.isReadable = exports.normalizeToReadableStream = exports.isNodeReadable = exports.isReadableStream = exports.readableNodeToWeb = exports.readableWebToNode = exports.makeEthereumWalletSigner = exports.fromLittleEndian = exports.toLittleEndian = exports.ethToSwarmAddress = exports.isHexEthAddress = exports.makeHexEthAddress = exports.makeEthAddress = exports.assertPrefixedHexString = exports.assertHexString = exports.isHexString = exports.intToHex = exports.bytesToHex = exports.hexToBytes = exports.makeHexString = exports.bytesEqual = exports.flexBytesAtOffset = exports.bytesAtOffset = exports.assertFlexBytes = exports.isFlexBytes = exports.assertBytes = exports.isBytes = exports.getFolderSize = exports.getCollectionSize = void 0;
4
- var collection_1 = require("./collection");
5
- Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
6
- var collection_node_1 = require("./collection.node");
7
- Object.defineProperty(exports, "getFolderSize", { enumerable: true, get: function () { return collection_node_1.getFolderSize; } });
8
- var bytes_1 = require("./bytes");
9
- Object.defineProperty(exports, "isBytes", { enumerable: true, get: function () { return bytes_1.isBytes; } });
10
- Object.defineProperty(exports, "assertBytes", { enumerable: true, get: function () { return bytes_1.assertBytes; } });
11
- Object.defineProperty(exports, "isFlexBytes", { enumerable: true, get: function () { return bytes_1.isFlexBytes; } });
12
- Object.defineProperty(exports, "assertFlexBytes", { enumerable: true, get: function () { return bytes_1.assertFlexBytes; } });
13
- Object.defineProperty(exports, "bytesAtOffset", { enumerable: true, get: function () { return bytes_1.bytesAtOffset; } });
14
- Object.defineProperty(exports, "flexBytesAtOffset", { enumerable: true, get: function () { return bytes_1.flexBytesAtOffset; } });
15
- Object.defineProperty(exports, "bytesEqual", { enumerable: true, get: function () { return bytes_1.bytesEqual; } });
16
- var hex_1 = require("./hex");
17
- Object.defineProperty(exports, "makeHexString", { enumerable: true, get: function () { return hex_1.makeHexString; } });
18
- Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return hex_1.hexToBytes; } });
19
- Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return hex_1.bytesToHex; } });
20
- Object.defineProperty(exports, "intToHex", { enumerable: true, get: function () { return hex_1.intToHex; } });
21
- Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return hex_1.isHexString; } });
22
- Object.defineProperty(exports, "assertHexString", { enumerable: true, get: function () { return hex_1.assertHexString; } });
23
- Object.defineProperty(exports, "assertPrefixedHexString", { enumerable: true, get: function () { return hex_1.assertPrefixedHexString; } });
24
- var eth_1 = require("./eth");
25
- Object.defineProperty(exports, "makeEthAddress", { enumerable: true, get: function () { return eth_1.makeEthAddress; } });
26
- Object.defineProperty(exports, "makeHexEthAddress", { enumerable: true, get: function () { return eth_1.makeHexEthAddress; } });
27
- Object.defineProperty(exports, "isHexEthAddress", { enumerable: true, get: function () { return eth_1.isHexEthAddress; } });
28
- Object.defineProperty(exports, "ethToSwarmAddress", { enumerable: true, get: function () { return eth_1.ethToSwarmAddress; } });
29
- Object.defineProperty(exports, "toLittleEndian", { enumerable: true, get: function () { return eth_1.toLittleEndian; } });
30
- Object.defineProperty(exports, "fromLittleEndian", { enumerable: true, get: function () { return eth_1.fromLittleEndian; } });
31
- Object.defineProperty(exports, "makeEthereumWalletSigner", { enumerable: true, get: function () { return eth_1.makeEthereumWalletSigner; } });
32
- var stream_1 = require("./stream");
33
- Object.defineProperty(exports, "readableWebToNode", { enumerable: true, get: function () { return stream_1.readableWebToNode; } });
34
- Object.defineProperty(exports, "readableNodeToWeb", { enumerable: true, get: function () { return stream_1.readableNodeToWeb; } });
35
- Object.defineProperty(exports, "isReadableStream", { enumerable: true, get: function () { return stream_1.isReadableStream; } });
36
- Object.defineProperty(exports, "isNodeReadable", { enumerable: true, get: function () { return stream_1.isNodeReadable; } });
37
- Object.defineProperty(exports, "normalizeToReadableStream", { enumerable: true, get: function () { return stream_1.normalizeToReadableStream; } });
38
- Object.defineProperty(exports, "isReadable", { enumerable: true, get: function () { return stream_1.isReadable; } });
39
- var hash_1 = require("./hash");
40
- Object.defineProperty(exports, "keccak256Hash", { enumerable: true, get: function () { return hash_1.keccak256Hash; } });
41
- var pss_1 = require("./pss");
42
- Object.defineProperty(exports, "makeMaxTarget", { enumerable: true, get: function () { return pss_1.makeMaxTarget; } });
43
- var stamps_1 = require("./stamps");
44
- Object.defineProperty(exports, "getStampUsage", { enumerable: true, get: function () { return stamps_1.getStampUsage; } });
@@ -1,49 +0,0 @@
1
- "use strict";
2
- /**
3
- * Compatibility functions for working with File API objects
4
- *
5
- * https://developer.mozilla.org/en-US/docs/Web/API/File
6
- */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.fileArrayBuffer = exports.isFile = void 0;
18
- function isFile(file) {
19
- // browser
20
- if (typeof File === 'function') {
21
- return file instanceof File;
22
- }
23
- // node.js
24
- const f = file;
25
- return (typeof f === 'object' &&
26
- typeof f.name === 'string' &&
27
- (typeof f.stream === 'function' || typeof f.arrayBuffer === 'function'));
28
- }
29
- exports.isFile = isFile;
30
- /**
31
- * Compatibility helper for browsers where the `arrayBuffer function is
32
- * missing from `File` objects.
33
- *
34
- * @param file A File object
35
- */
36
- function fileArrayBuffer(file) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (file.arrayBuffer) {
39
- return file.arrayBuffer();
40
- }
41
- // workaround for Safari where arrayBuffer is not supported on Files
42
- return new Promise(resolve => {
43
- const fr = new FileReader();
44
- fr.onload = () => resolve(fr.result);
45
- fr.readAsArrayBuffer(file);
46
- });
47
- });
48
- }
49
- exports.fileArrayBuffer = fileArrayBuffer;