@ethersphere/bee-js 3.0.0 → 3.3.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.
- package/README.md +2 -2
- package/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -0
- package/dist/cjs/chunk/bmt.js +55 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +137 -0
- package/dist/cjs/chunk/soc.js +172 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/index.js +184 -0
- package/dist/cjs/feed/json.js +41 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/modules/bytes.js +74 -0
- package/dist/cjs/modules/bzz.js +131 -0
- package/dist/cjs/modules/chunk.js +58 -0
- package/dist/cjs/modules/debug/balance.js +77 -0
- package/dist/cjs/modules/debug/chequebook.js +167 -0
- package/dist/cjs/modules/debug/chunk.js +51 -0
- package/dist/cjs/modules/debug/connectivity.js +75 -0
- package/dist/cjs/modules/debug/settlements.js +45 -0
- package/dist/cjs/modules/debug/stamps.js +89 -0
- package/dist/cjs/modules/debug/states.js +47 -0
- package/dist/cjs/modules/debug/status.js +153 -0
- package/dist/cjs/modules/debug/tag.js +30 -0
- package/dist/cjs/modules/debug/transactions.js +81 -0
- package/dist/cjs/modules/feed.js +76 -0
- package/dist/cjs/modules/pinning.js +84 -0
- package/dist/cjs/modules/pss.js +55 -0
- package/dist/cjs/modules/soc.js +40 -0
- package/dist/cjs/modules/status.js +26 -0
- package/dist/cjs/modules/stewardship.js +41 -0
- package/dist/cjs/modules/tag.js +96 -0
- package/dist/cjs/package.json +8 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -0
- package/dist/cjs/types/ky-options.js +8 -0
- package/dist/cjs/types/ky-universal/common.js +8 -0
- package/dist/cjs/types/ky-universal/hooks.js +8 -0
- package/dist/cjs/types/ky-universal/retry.js +8 -0
- package/dist/cjs/utils/bytes.js +107 -0
- package/dist/cjs/utils/collection.browser.js +36 -0
- package/dist/cjs/utils/collection.js +70 -0
- package/dist/cjs/utils/collection.node.js +115 -0
- package/dist/cjs/utils/data.browser.js +78 -0
- package/dist/cjs/utils/data.js +60 -0
- package/dist/cjs/utils/error.js +50 -0
- package/dist/cjs/utils/eth.js +211 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -0
- package/dist/cjs/utils/hash.js +21 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +166 -0
- package/dist/cjs/utils/merge.js +34 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +146 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +327 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +5 -12
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +609 -0
- package/dist/mjs/bee.js +944 -0
- package/dist/mjs/chunk/bmt.js +56 -0
- package/dist/mjs/chunk/cac.js +52 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +131 -0
- package/dist/mjs/chunk/soc.js +139 -0
- package/dist/mjs/chunk/span.js +28 -0
- package/dist/mjs/feed/index.js +145 -0
- package/dist/mjs/feed/json.js +27 -0
- package/dist/mjs/feed/topic.js +21 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +59 -0
- package/dist/mjs/modules/bzz.js +122 -0
- package/dist/mjs/modules/chunk.js +45 -0
- package/dist/mjs/modules/debug/balance.js +57 -0
- package/dist/mjs/modules/debug/chequebook.js +150 -0
- package/dist/mjs/modules/debug/chunk.js +35 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +29 -0
- package/dist/mjs/modules/debug/stamps.js +64 -0
- package/dist/mjs/modules/debug/states.js +31 -0
- package/dist/mjs/modules/debug/status.js +134 -0
- package/dist/mjs/modules/debug/tag.js +16 -0
- package/dist/mjs/modules/debug/transactions.js +63 -0
- package/dist/mjs/modules/feed.js +67 -0
- package/dist/mjs/modules/pinning.js +66 -0
- package/dist/mjs/modules/pss.js +40 -0
- package/dist/mjs/modules/soc.js +31 -0
- package/dist/mjs/modules/status.js +12 -0
- package/dist/mjs/modules/stewardship.js +24 -0
- package/dist/mjs/modules/tag.js +77 -0
- package/dist/mjs/package.json +8 -0
- package/dist/mjs/types/debug.js +7 -0
- package/dist/mjs/types/index.js +37 -0
- package/dist/mjs/types/ky-options.js +7 -0
- package/dist/mjs/types/ky-universal/common.js +7 -0
- package/dist/mjs/types/ky-universal/hooks.js +7 -0
- package/dist/mjs/types/ky-universal/retry.js +7 -0
- package/dist/mjs/utils/bytes.js +101 -0
- package/dist/mjs/utils/collection.browser.js +19 -0
- package/dist/mjs/utils/collection.js +64 -0
- package/dist/mjs/utils/collection.node.js +74 -0
- package/dist/mjs/utils/data.browser.js +73 -0
- package/dist/mjs/utils/data.js +43 -0
- package/dist/mjs/utils/error.js +56 -0
- package/dist/mjs/utils/eth.js +199 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +36 -0
- package/dist/mjs/utils/hash.js +17 -0
- package/dist/mjs/utils/headers.js +58 -0
- package/dist/mjs/utils/hex.js +154 -0
- package/dist/mjs/utils/http.js +155 -0
- package/dist/mjs/utils/merge.js +36 -0
- package/dist/mjs/utils/pss.js +16 -0
- package/dist/mjs/utils/stamps.js +17 -0
- package/dist/mjs/utils/stream.js +156 -0
- package/dist/mjs/utils/tar.js +21 -0
- package/dist/mjs/utils/type.js +336 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +57 -0
- package/dist/{src → types}/bee-debug.d.ts +51 -1
- package/dist/{src → types}/bee.d.ts +21 -0
- package/dist/{src → types}/chunk/bmt.d.ts +0 -0
- package/dist/{src → types}/chunk/cac.d.ts +0 -0
- package/dist/{src → types}/chunk/serialize.d.ts +0 -0
- package/dist/{src → types}/chunk/signer.d.ts +0 -0
- package/dist/{src → types}/chunk/soc.d.ts +0 -0
- package/dist/{src → types}/chunk/span.d.ts +0 -0
- package/dist/{src → types}/feed/index.d.ts +0 -0
- package/dist/{src → types}/feed/json.d.ts +0 -0
- package/dist/{src → types}/feed/topic.d.ts +0 -0
- package/dist/{src → types}/feed/type.d.ts +0 -0
- package/dist/{src → types}/index.d.ts +0 -0
- package/dist/{src → types}/modules/bytes.d.ts +0 -0
- package/dist/{src → types}/modules/bzz.d.ts +0 -0
- package/dist/{src → types}/modules/chunk.d.ts +2 -10
- package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
- package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
- package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
- package/dist/{src → types}/modules/debug/states.d.ts +0 -0
- package/dist/types/modules/debug/status.d.ts +72 -0
- package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
- package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
- package/dist/{src → types}/modules/feed.d.ts +0 -0
- package/dist/{src → types}/modules/pinning.d.ts +0 -0
- package/dist/{src → types}/modules/pss.d.ts +0 -0
- package/dist/{src → types}/modules/soc.d.ts +0 -0
- package/dist/{src → types}/modules/status.d.ts +0 -0
- package/dist/{src → types}/modules/stewardship.d.ts +0 -0
- package/dist/{src → types}/modules/tag.d.ts +0 -0
- package/dist/{src → types}/types/debug.d.ts +25 -0
- package/dist/{src → types}/types/index.d.ts +32 -2
- package/dist/types/types/ky-options.d.ts +221 -0
- package/dist/types/types/ky-universal/common.d.ts +13 -0
- package/dist/types/types/ky-universal/hooks.d.ts +92 -0
- package/dist/types/types/ky-universal/retry.d.ts +38 -0
- package/dist/{src → types}/utils/bytes.d.ts +0 -0
- package/dist/types/utils/collection.browser.d.ts +15 -0
- package/dist/{src → types}/utils/collection.d.ts +0 -14
- package/dist/types/utils/collection.node.d.ts +15 -0
- package/dist/{src → types}/utils/data.browser.d.ts +0 -0
- package/dist/{src → types}/utils/data.d.ts +0 -0
- package/dist/types/utils/error.d.ts +33 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +3 -1
- package/dist/{src → types}/utils/file.d.ts +0 -0
- package/dist/{src → types}/utils/hash.d.ts +0 -0
- package/dist/{src → types}/utils/headers.d.ts +0 -0
- package/dist/{src → types}/utils/hex.d.ts +0 -0
- package/dist/{src → types}/utils/http.d.ts +7 -9
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/types/utils/stamps.d.ts +12 -0
- package/dist/{src → types}/utils/stream.d.ts +11 -8
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +6 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +61 -43
- package/CHANGELOG.md +0 -546
- package/dist/index.min.js +0 -3
- package/dist/index.min.js.LICENSE.txt +0 -50
- package/dist/index.min.js.map +0 -1
- package/dist/src/modules/debug/status.d.ts +0 -18
- package/dist/src/utils/error.d.ts +0 -14
|
@@ -0,0 +1,115 @@
|
|
|
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;
|
|
@@ -0,0 +1,78 @@
|
|
|
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 stream_1 = require("./stream");
|
|
17
|
+
const cross_blob_1 = __importDefault(require("cross-blob"));
|
|
18
|
+
/**
|
|
19
|
+
* Validates input and converts to Uint8Array
|
|
20
|
+
*
|
|
21
|
+
* @param data any string, ArrayBuffer or Uint8Array
|
|
22
|
+
*/
|
|
23
|
+
function prepareData(data) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (typeof data === 'string')
|
|
26
|
+
return new cross_blob_1.default([data], { type: 'text/plain' });
|
|
27
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
28
|
+
return new cross_blob_1.default([data], { type: 'application/octet-stream' });
|
|
29
|
+
}
|
|
30
|
+
if (data instanceof cross_blob_1.default) {
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
// Currently it is not possible to stream requests from browsers
|
|
34
|
+
// there are already first experiments on this field (Chromium)
|
|
35
|
+
// but till it is fully implemented across browsers-land we have to
|
|
36
|
+
// buffer the data before sending the requests.
|
|
37
|
+
if ((0, stream_1.isNodeReadable)(data)) {
|
|
38
|
+
return new Promise(resolve => {
|
|
39
|
+
const buffers = [];
|
|
40
|
+
data.on('data', d => {
|
|
41
|
+
buffers.push(d);
|
|
42
|
+
});
|
|
43
|
+
data.on('end', () => {
|
|
44
|
+
resolve(new cross_blob_1.default(buffers, { type: 'application/octet-stream' }));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if ((0, stream_1.isReadableStream)(data)) {
|
|
49
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const reader = data.getReader();
|
|
51
|
+
const buffers = [];
|
|
52
|
+
let done, value;
|
|
53
|
+
do {
|
|
54
|
+
;
|
|
55
|
+
({ done, value } = yield reader.read());
|
|
56
|
+
if (!done) {
|
|
57
|
+
buffers.push(value);
|
|
58
|
+
}
|
|
59
|
+
} while (!done);
|
|
60
|
+
resolve(new cross_blob_1.default(buffers, { type: 'application/octet-stream' }));
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
throw new TypeError('unknown data type');
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.prepareData = prepareData;
|
|
67
|
+
function prepareWebsocketData(data) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (typeof data === 'string')
|
|
70
|
+
return new TextEncoder().encode(data);
|
|
71
|
+
if (data instanceof ArrayBuffer)
|
|
72
|
+
return new Uint8Array(data);
|
|
73
|
+
if (data instanceof cross_blob_1.default)
|
|
74
|
+
return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
75
|
+
throw new TypeError('unknown websocket data type');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.prepareWebsocketData = prepareWebsocketData;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 cross_blob_1 = __importDefault(require("cross-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 cross_blob_1.default([data], { type: 'text/plain' });
|
|
30
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
31
|
+
return new cross_blob_1.default([data], { type: 'application/octet-stream' });
|
|
32
|
+
}
|
|
33
|
+
if (data instanceof cross_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 (data instanceof cross_blob_1.default)
|
|
54
|
+
return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
55
|
+
if (isBufferArray(data))
|
|
56
|
+
return new Uint8Array(Buffer.concat(data));
|
|
57
|
+
throw new TypeError('unknown websocket data type');
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.prepareWebsocketData = prepareWebsocketData;
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
|
@@ -0,0 +1,211 @@
|
|
|
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;
|
|
@@ -0,0 +1,44 @@
|
|
|
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; } });
|
|
@@ -0,0 +1,49 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.keccak256Hash = void 0;
|
|
7
|
+
// For ESM compatibility
|
|
8
|
+
const js_sha3_1 = __importDefault(require("js-sha3"));
|
|
9
|
+
const { keccak256 } = js_sha3_1.default;
|
|
10
|
+
/**
|
|
11
|
+
* Helper function for calculating the keccak256 hash with
|
|
12
|
+
* correct types.
|
|
13
|
+
*
|
|
14
|
+
* @param messages Any number of messages (strings, byte arrays etc.)
|
|
15
|
+
*/
|
|
16
|
+
function keccak256Hash(...messages) {
|
|
17
|
+
const hasher = keccak256.create();
|
|
18
|
+
messages.forEach(bytes => hasher.update(bytes));
|
|
19
|
+
return Uint8Array.from(hasher.digest());
|
|
20
|
+
}
|
|
21
|
+
exports.keccak256Hash = keccak256Hash;
|