@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.10
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 +18 -17
- package/dist/cjs/bee-debug.js +572 -0
- package/dist/cjs/bee.js +876 -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 +126 -0
- package/dist/cjs/chunk/soc.js +159 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/identifier.js +35 -0
- package/dist/cjs/feed/index.js +116 -0
- package/dist/cjs/feed/json.js +28 -0
- package/dist/cjs/feed/retrievable.js +58 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/modules/bytes.js +61 -0
- package/dist/cjs/modules/bzz.js +125 -0
- package/dist/cjs/modules/chunk.js +48 -0
- package/dist/cjs/modules/debug/balance.js +60 -0
- package/dist/cjs/modules/debug/chequebook.js +142 -0
- package/dist/cjs/modules/debug/chunk.js +38 -0
- package/dist/cjs/modules/debug/connectivity.js +54 -0
- package/dist/cjs/modules/debug/settlements.js +32 -0
- package/dist/cjs/modules/debug/stake.js +57 -0
- package/dist/cjs/modules/debug/stamps.js +68 -0
- package/dist/cjs/modules/debug/states.js +64 -0
- package/dist/cjs/modules/debug/status.js +148 -0
- package/dist/cjs/modules/debug/tag.js +19 -0
- package/dist/cjs/modules/debug/transactions.js +64 -0
- package/dist/cjs/modules/feed.js +66 -0
- package/dist/cjs/modules/pinning.js +63 -0
- package/dist/cjs/modules/pss.js +43 -0
- package/dist/cjs/modules/soc.js +32 -0
- package/dist/cjs/modules/status.js +15 -0
- package/dist/cjs/modules/stewardship.js +28 -0
- package/dist/cjs/modules/tag.js +77 -0
- package/dist/cjs/package.json +8 -0
- package/dist/cjs/types/debug.js +10 -0
- package/dist/cjs/types/index.js +51 -0
- package/dist/cjs/utils/bytes.js +121 -0
- package/dist/cjs/utils/collection.browser.js +23 -0
- package/dist/cjs/utils/collection.js +59 -0
- package/dist/cjs/utils/collection.node.js +71 -0
- package/dist/cjs/utils/data.browser.js +61 -0
- package/dist/cjs/utils/data.js +45 -0
- package/dist/cjs/utils/error.js +16 -0
- package/dist/cjs/utils/eth.js +199 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +38 -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 +40 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/reference.js +36 -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 +434 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.browser.min.js +3 -0
- package/dist/index.browser.min.js.LICENSE.txt +50 -0
- package/dist/index.browser.min.js.map +1 -0
- package/dist/{src → mjs}/bee-debug.js +102 -183
- package/dist/{src → mjs}/bee.js +82 -232
- package/dist/{src → mjs}/chunk/bmt.js +4 -10
- package/dist/{src → mjs}/chunk/cac.js +0 -3
- package/dist/{src → mjs}/chunk/signer.js +1 -18
- package/dist/{src → mjs}/chunk/soc.js +17 -29
- package/dist/{src → mjs}/chunk/span.js +2 -5
- package/dist/{src → mjs}/feed/identifier.js +0 -6
- package/dist/{src → mjs}/feed/index.js +24 -27
- package/dist/{src → mjs}/feed/json.js +2 -5
- package/dist/{src → mjs}/feed/retrievable.js +7 -21
- package/dist/{src → mjs}/feed/topic.js +0 -2
- package/dist/{src → mjs}/index.js +2 -2
- package/dist/{src → mjs}/modules/bytes.js +16 -20
- package/dist/{src → mjs}/modules/bzz.js +33 -40
- package/dist/{src → mjs}/modules/chunk.js +11 -13
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +135 -0
- package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stake.js +51 -0
- package/dist/mjs/modules/debug/stamps.js +61 -0
- package/dist/mjs/modules/debug/states.js +58 -0
- package/dist/{src → mjs}/modules/debug/status.js +46 -37
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +59 -0
- package/dist/{src → mjs}/modules/feed.js +15 -21
- package/dist/mjs/modules/pinning.js +56 -0
- package/dist/{src → mjs}/modules/pss.js +7 -10
- package/dist/{src → mjs}/modules/soc.js +6 -7
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +72 -0
- package/dist/mjs/package.json +8 -0
- package/dist/{src → mjs}/types/debug.js +0 -1
- package/dist/{src → mjs}/types/index.js +0 -4
- package/dist/{src → mjs}/utils/bytes.js +8 -17
- package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
- package/dist/{src → mjs}/utils/collection.js +0 -12
- package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
- package/dist/{src → mjs}/utils/data.browser.js +2 -11
- package/dist/{src → mjs}/utils/data.js +0 -7
- package/dist/mjs/utils/error.js +11 -0
- package/dist/{src → mjs}/utils/eth.js +6 -28
- package/dist/{src → mjs}/utils/expose.js +1 -1
- package/dist/{src → mjs}/utils/file.js +4 -9
- package/dist/{src → mjs}/utils/hash.js +0 -1
- package/dist/{src → mjs}/utils/headers.js +5 -13
- package/dist/{src → mjs}/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +34 -0
- package/dist/{src → mjs}/utils/pss.js +0 -2
- package/dist/{src → mjs}/utils/reference.js +2 -5
- package/dist/{src → mjs}/utils/stream.js +3 -26
- package/dist/{src → mjs}/utils/tar.js +3 -6
- package/dist/{src → mjs}/utils/type.js +23 -80
- package/dist/{src → mjs}/utils/uint64.js +0 -1
- package/dist/{src → mjs}/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +71 -46
- package/dist/types/bee.d.ts +34 -58
- package/dist/types/chunk/bmt.d.ts +1 -1
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +9 -9
- package/dist/types/chunk/span.d.ts +1 -1
- package/dist/types/feed/index.d.ts +10 -10
- package/dist/types/feed/json.d.ts +2 -2
- package/dist/types/feed/retrievable.d.ts +2 -2
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/index.d.ts +13 -2
- package/dist/types/modules/bytes.d.ts +5 -5
- package/dist/types/modules/bzz.d.ts +8 -8
- package/dist/types/modules/chunk.d.ts +4 -4
- package/dist/types/modules/debug/balance.d.ts +9 -9
- package/dist/types/modules/debug/chequebook.d.ts +17 -17
- package/dist/types/modules/debug/chunk.d.ts +5 -5
- package/dist/types/modules/debug/connectivity.d.ts +7 -7
- package/dist/types/modules/debug/settlements.d.ts +5 -5
- package/dist/types/modules/debug/stake.d.ts +21 -0
- package/dist/types/modules/debug/stamps.d.ts +7 -7
- package/dist/types/modules/debug/states.d.ts +7 -7
- package/dist/types/modules/debug/status.d.ts +21 -15
- package/dist/types/modules/debug/tag.d.ts +3 -3
- package/dist/types/modules/debug/transactions.d.ts +5 -5
- package/dist/types/modules/feed.d.ts +3 -3
- package/dist/types/modules/pinning.d.ts +7 -7
- package/dist/types/modules/pss.d.ts +3 -3
- package/dist/types/modules/soc.d.ts +2 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +3 -3
- package/dist/types/modules/tag.d.ts +6 -6
- package/dist/types/types/debug.d.ts +35 -2
- package/dist/types/types/index.d.ts +48 -89
- package/dist/types/utils/error.d.ts +0 -26
- package/dist/types/utils/eth.d.ts +6 -6
- package/dist/types/utils/expose.d.ts +4 -7
- package/dist/types/utils/hash.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/hex.d.ts +4 -4
- package/dist/types/utils/http.d.ts +11 -21
- package/dist/types/utils/stream.d.ts +1 -1
- package/dist/types/utils/type.d.ts +3 -2
- package/dist/types/utils/uint64.d.ts +1 -1
- package/package.json +59 -52
- package/dist/index.browser.js +0 -33
- package/dist/index.browser.js.map +0 -7
- package/dist/src/modules/debug/balance.js +0 -57
- package/dist/src/modules/debug/chequebook.js +0 -150
- package/dist/src/modules/debug/connectivity.js +0 -45
- package/dist/src/modules/debug/settlements.js +0 -29
- package/dist/src/modules/debug/stamps.js +0 -64
- package/dist/src/modules/debug/states.js +0 -46
- package/dist/src/modules/debug/tag.js +0 -16
- package/dist/src/modules/debug/transactions.js +0 -69
- package/dist/src/modules/pinning.js +0 -60
- package/dist/src/modules/status.js +0 -12
- package/dist/src/modules/stewardship.js +0 -24
- package/dist/src/modules/tag.js +0 -77
- package/dist/src/utils/error.js +0 -47
- package/dist/src/utils/http.js +0 -162
- package/dist/src/utils/merge.js +0 -36
- package/dist/src/utils/sleep.js +0 -8
- package/dist/types/utils/merge.d.ts +0 -8
- package/dist/types/utils/sleep.d.ts +0 -6
- /package/dist/{src → mjs}/chunk/serialize.js +0 -0
- /package/dist/{src → mjs}/feed/type.js +0 -0
- /package/dist/{src → mjs}/utils/stamps.js +0 -0
- /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
- /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
|
@@ -13,7 +13,6 @@ export async function makeCollectionFromFS(dir) {
|
|
|
13
13
|
* @param dir the path to the folder to check
|
|
14
14
|
* @returns size in bytes
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
export async function getFolderSize(dir) {
|
|
18
17
|
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
19
18
|
}
|
|
@@ -5,7 +5,6 @@ export function isCollection(data) {
|
|
|
5
5
|
if (!Array.isArray(data)) {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
8
|
return data.every(entry => typeof entry === 'object' && entry.data && entry.path && isUint8Array(entry.data));
|
|
10
9
|
}
|
|
11
10
|
export function assertCollection(data) {
|
|
@@ -13,25 +12,19 @@ export function assertCollection(data) {
|
|
|
13
12
|
throw new BeeArgumentError('invalid collection', data);
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
function makeFilePath(file) {
|
|
18
16
|
if (file.webkitRelativePath && file.webkitRelativePath !== '') {
|
|
19
17
|
return file.webkitRelativePath.replace(/.*?\//i, '');
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
if (file.name) {
|
|
23
20
|
return file.name;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
throw new TypeError('file is not valid File object');
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
export async function makeCollectionFromFileList(fileList) {
|
|
30
25
|
const collection = [];
|
|
31
|
-
|
|
32
26
|
for (let i = 0; i < fileList.length; i++) {
|
|
33
27
|
const file = fileList[i];
|
|
34
|
-
|
|
35
28
|
if (file) {
|
|
36
29
|
collection.push({
|
|
37
30
|
path: makeFilePath(file),
|
|
@@ -39,7 +32,6 @@ export async function makeCollectionFromFileList(fileList) {
|
|
|
39
32
|
});
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
return collection;
|
|
44
36
|
}
|
|
45
37
|
/**
|
|
@@ -48,17 +40,13 @@ export async function makeCollectionFromFileList(fileList) {
|
|
|
48
40
|
* @param fileList list of files to check
|
|
49
41
|
* @returns size in bytes
|
|
50
42
|
*/
|
|
51
|
-
|
|
52
43
|
export function getCollectionSize(fileList) {
|
|
53
44
|
let sum = 0;
|
|
54
|
-
|
|
55
45
|
for (let i = 0; i < fileList.length; i++) {
|
|
56
46
|
const file = fileList[i];
|
|
57
|
-
|
|
58
47
|
if (file) {
|
|
59
48
|
sum += file.size;
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
return sum;
|
|
64
52
|
}
|
|
@@ -6,29 +6,23 @@ import path from 'path';
|
|
|
6
6
|
*
|
|
7
7
|
* @param dir path to the directory
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
export async function makeCollectionFromFS(dir) {
|
|
11
10
|
if (typeof dir !== 'string') {
|
|
12
11
|
throw new TypeError('dir has to be string!');
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
if (dir === '') {
|
|
16
14
|
throw new TypeError('dir must not be empty string!');
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
return buildCollectionRelative(dir, '');
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
async function buildCollectionRelative(dir, relativePath) {
|
|
23
19
|
// Handles case when the dir is not existing or it is a file ==> throws an error
|
|
24
20
|
const dirname = path.join(dir, relativePath);
|
|
25
21
|
const entries = await fs.promises.opendir(dirname);
|
|
26
22
|
let collection = [];
|
|
27
|
-
|
|
28
23
|
for await (const entry of entries) {
|
|
29
24
|
const fullPath = path.join(dir, relativePath, entry.name);
|
|
30
25
|
const entryPath = path.join(relativePath, entry.name);
|
|
31
|
-
|
|
32
26
|
if (entry.isFile()) {
|
|
33
27
|
collection.push({
|
|
34
28
|
path: entryPath,
|
|
@@ -38,7 +32,6 @@ async function buildCollectionRelative(dir, relativePath) {
|
|
|
38
32
|
collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
return collection;
|
|
43
36
|
}
|
|
44
37
|
/**
|
|
@@ -47,20 +40,15 @@ async function buildCollectionRelative(dir, relativePath) {
|
|
|
47
40
|
* @param dir the path to the folder to check
|
|
48
41
|
* @returns size in bytes
|
|
49
42
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
43
|
export async function getFolderSize(dir) {
|
|
53
44
|
if (typeof dir !== 'string') {
|
|
54
45
|
throw new TypeError('dir has to be string!');
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
if (dir === '') {
|
|
58
48
|
throw new TypeError('dir must not be empty string!');
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
const entries = await fs.promises.opendir(dir);
|
|
62
51
|
let size = 0;
|
|
63
|
-
|
|
64
52
|
for await (const entry of entries) {
|
|
65
53
|
if (entry.isFile()) {
|
|
66
54
|
const stats = await fs.promises.stat(path.join(dir, entry.name));
|
|
@@ -69,6 +57,5 @@ export async function getFolderSize(dir) {
|
|
|
69
57
|
size += await getFolderSize(path.join(dir, entry.name));
|
|
70
58
|
}
|
|
71
59
|
}
|
|
72
|
-
|
|
73
60
|
return size;
|
|
74
61
|
}
|
|
@@ -4,26 +4,22 @@ import { isNodeReadable, isReadableStream } from "./stream.js";
|
|
|
4
4
|
*
|
|
5
5
|
* @param data any string, ArrayBuffer or Uint8Array
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
export async function prepareData(data) {
|
|
9
8
|
if (typeof data === 'string') return new Blob([data], {
|
|
10
9
|
type: 'text/plain'
|
|
11
10
|
});
|
|
12
|
-
|
|
13
11
|
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
14
12
|
return new Blob([data], {
|
|
15
13
|
type: 'application/octet-stream'
|
|
16
14
|
});
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
if (data instanceof Blob) {
|
|
20
17
|
return data;
|
|
21
|
-
}
|
|
18
|
+
}
|
|
19
|
+
// Currently it is not possible to stream requests from browsers
|
|
22
20
|
// there are already first experiments on this field (Chromium)
|
|
23
21
|
// but till it is fully implemented across browsers-land we have to
|
|
24
22
|
// buffer the data before sending the requests.
|
|
25
|
-
|
|
26
|
-
|
|
27
23
|
if (isNodeReadable(data)) {
|
|
28
24
|
return new Promise(resolve => {
|
|
29
25
|
const buffers = [];
|
|
@@ -37,31 +33,26 @@ export async function prepareData(data) {
|
|
|
37
33
|
});
|
|
38
34
|
});
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
if (isReadableStream(data)) {
|
|
42
37
|
return new Promise(async resolve => {
|
|
43
38
|
const reader = data.getReader();
|
|
44
39
|
const buffers = [];
|
|
45
40
|
let done, value;
|
|
46
|
-
|
|
47
41
|
do {
|
|
48
42
|
;
|
|
49
43
|
({
|
|
50
44
|
done,
|
|
51
45
|
value
|
|
52
46
|
} = await reader.read());
|
|
53
|
-
|
|
54
47
|
if (!done) {
|
|
55
48
|
buffers.push(value);
|
|
56
49
|
}
|
|
57
50
|
} while (!done);
|
|
58
|
-
|
|
59
51
|
resolve(new Blob(buffers, {
|
|
60
52
|
type: 'application/octet-stream'
|
|
61
53
|
}));
|
|
62
54
|
});
|
|
63
55
|
}
|
|
64
|
-
|
|
65
56
|
throw new TypeError('unknown data type');
|
|
66
57
|
}
|
|
67
58
|
export async function prepareWebsocketData(data) {
|
|
@@ -8,31 +8,24 @@ import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js
|
|
|
8
8
|
*
|
|
9
9
|
* @param data any string, ArrayBuffer, Uint8Array or Readable
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
export async function prepareData(data) {
|
|
13
12
|
if (typeof data === 'string') return new BlobPolyfill([data], {
|
|
14
13
|
type: 'text/plain'
|
|
15
14
|
});
|
|
16
|
-
|
|
17
15
|
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
18
16
|
return new BlobPolyfill([data], {
|
|
19
17
|
type: 'application/octet-stream'
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
if (data instanceof BlobPolyfill || isNodeReadable(data)) return data;
|
|
24
|
-
|
|
25
21
|
if (isReadableStream(data)) {
|
|
26
22
|
return readableWebToNode(data);
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
throw new TypeError('unknown data type');
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
function isBufferArray(buffer) {
|
|
33
27
|
return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
|
|
34
28
|
}
|
|
35
|
-
|
|
36
29
|
export async function prepareWebsocketData(data) {
|
|
37
30
|
if (typeof data === 'string') return new TextEncoder().encode(data);
|
|
38
31
|
if (data instanceof Buffer) return new Uint8Array(data);
|
|
@@ -18,7 +18,6 @@ export function makeEthAddress(address) {
|
|
|
18
18
|
assertBytes(address, ETH_ADDR_BYTES_LENGTH);
|
|
19
19
|
return address;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
throw new TypeError('Invalid EthAddress');
|
|
23
22
|
}
|
|
24
23
|
export function makeHexEthAddress(address) {
|
|
@@ -28,7 +27,6 @@ export function makeHexEthAddress(address) {
|
|
|
28
27
|
if (e instanceof TypeError) {
|
|
29
28
|
e.message = `Invalid HexEthAddress: ${e.message}`;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
throw e;
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -37,7 +35,6 @@ export function makeHexEthAddress(address) {
|
|
|
37
35
|
*
|
|
38
36
|
* @param address Ethereum address as hex string
|
|
39
37
|
*/
|
|
40
|
-
|
|
41
38
|
function isEthAddrCaseIns(address) {
|
|
42
39
|
// Check it's string, all small caps or all all caps hex and 40 chars long without the `0x` prefix
|
|
43
40
|
return typeof address === 'string' && (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address));
|
|
@@ -47,28 +44,23 @@ function isEthAddrCaseIns(address) {
|
|
|
47
44
|
*
|
|
48
45
|
* @param address Ethereum address as hex string
|
|
49
46
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
47
|
function isValidChecksummedEthAddress(address) {
|
|
53
48
|
try {
|
|
54
49
|
// Check for valid case insensitive hex type string, 40 chars
|
|
55
|
-
const addr = makeHexString(address, ETH_ADDR_HEX_LENGTH);
|
|
56
|
-
|
|
50
|
+
const addr = makeHexString(address, ETH_ADDR_HEX_LENGTH);
|
|
51
|
+
// Check the checksum
|
|
57
52
|
const addressHash = keccak256(addr.toLowerCase());
|
|
58
|
-
|
|
59
53
|
for (let i = 0; i < 40; i += 1) {
|
|
60
54
|
// the nth letter should be uppercase if the nth digit of casemap is 1
|
|
61
55
|
if (parseInt(addressHash[i], 16) > 7 && addr[i].toUpperCase() !== addr[i] || parseInt(addressHash[i], 16) <= 7 && addr[i].toLowerCase() !== addr[i]) {
|
|
62
56
|
return false;
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
|
-
|
|
66
59
|
return true;
|
|
67
60
|
} catch (e) {
|
|
68
61
|
if (e instanceof TypeError) {
|
|
69
62
|
return false;
|
|
70
63
|
}
|
|
71
|
-
|
|
72
64
|
throw e;
|
|
73
65
|
}
|
|
74
66
|
}
|
|
@@ -82,8 +74,6 @@ function isValidChecksummedEthAddress(address) {
|
|
|
82
74
|
*
|
|
83
75
|
* @return True if is valid eth address
|
|
84
76
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
77
|
export function isHexEthAddress(address) {
|
|
88
78
|
return isEthAddrCaseIns(address) || isValidChecksummedEthAddress(address);
|
|
89
79
|
}
|
|
@@ -96,18 +86,16 @@ export function isHexEthAddress(address) {
|
|
|
96
86
|
*
|
|
97
87
|
* @return little-endian encoded hexstring
|
|
98
88
|
*/
|
|
99
|
-
|
|
100
89
|
export function toLittleEndian(bigEndian, pad = 2) {
|
|
101
90
|
if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
|
|
102
91
|
throw new TypeError('minimal padding for conversion needs to be positive even integer');
|
|
103
92
|
}
|
|
104
|
-
|
|
105
93
|
let hexRep;
|
|
106
94
|
if (typeof bigEndian === 'string') hexRep = makeHexString(bigEndian);else if (typeof bigEndian === 'number') hexRep = intToHex(bigEndian);else throw new TypeError('incorrect input type');
|
|
107
|
-
hexRep = hexRep.padStart(pad, '0');
|
|
108
|
-
|
|
109
|
-
if (hexRep.length % 2 !== 0) hexRep = hexRep.padStart(hexRep.length + 1, '0');
|
|
110
|
-
|
|
95
|
+
hexRep = hexRep.padStart(pad, '0');
|
|
96
|
+
// Extend to an even length hexstring
|
|
97
|
+
if (hexRep.length % 2 !== 0) hexRep = hexRep.padStart(hexRep.length + 1, '0');
|
|
98
|
+
// Match all two pairs in the hexstring, reverse the pairs and join it again
|
|
111
99
|
const littleEndian = hexRep.match(/../g)?.reverse().join('');
|
|
112
100
|
if (littleEndian) return littleEndian;
|
|
113
101
|
throw new Error('failed to convert');
|
|
@@ -121,16 +109,13 @@ export function toLittleEndian(bigEndian, pad = 2) {
|
|
|
121
109
|
*
|
|
122
110
|
* @return big-endian encoded hexstring
|
|
123
111
|
*/
|
|
124
|
-
|
|
125
112
|
export function fromLittleEndian(littleEndian, pad = 2) {
|
|
126
113
|
// It's a reversible function
|
|
127
114
|
return toLittleEndian(littleEndian, pad);
|
|
128
115
|
}
|
|
129
|
-
|
|
130
116
|
function assertEthAddress(ethAddress) {
|
|
131
117
|
if (!isHexEthAddress(ethAddress)) throw new TypeError('invalid ETH address');
|
|
132
118
|
}
|
|
133
|
-
|
|
134
119
|
function assertSwarmNetworkId(networkId) {
|
|
135
120
|
if (Number.isInteger(networkId && networkId > 0 && networkId < Number.MAX_SAFE_INTEGER)) {
|
|
136
121
|
throw new TypeError('swarm network id must be positive integer');
|
|
@@ -144,8 +129,6 @@ function assertSwarmNetworkId(networkId) {
|
|
|
144
129
|
*
|
|
145
130
|
* @return Swarm overlay address
|
|
146
131
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
132
|
export function ethToSwarmAddress(ethAddress, networkId = 1) {
|
|
150
133
|
assertEthAddress(ethAddress);
|
|
151
134
|
assertSwarmNetworkId(networkId);
|
|
@@ -161,14 +144,11 @@ export function ethToSwarmAddress(ethAddress, networkId = 1) {
|
|
|
161
144
|
* @param provider Injected web3 provider like window.ethereum or other compatible with EIP-1193
|
|
162
145
|
* @param ethAddress Optional address of the account which the data should be signed with. If not specified `eth_requestAccounts` request is used to get the account address.
|
|
163
146
|
*/
|
|
164
|
-
|
|
165
147
|
export async function makeEthereumWalletSigner(provider, ethAddress) {
|
|
166
148
|
let executorFnc;
|
|
167
|
-
|
|
168
149
|
if (typeof provider !== 'object' || provider === null) {
|
|
169
150
|
throw new TypeError('We need JsonRPC provider object!');
|
|
170
151
|
}
|
|
171
|
-
|
|
172
152
|
if (provider.request) {
|
|
173
153
|
executorFnc = provider.request;
|
|
174
154
|
} else if (provider.sendAsync) {
|
|
@@ -176,13 +156,11 @@ export async function makeEthereumWalletSigner(provider, ethAddress) {
|
|
|
176
156
|
} else {
|
|
177
157
|
throw new Error('Incompatible interface of given provider!');
|
|
178
158
|
}
|
|
179
|
-
|
|
180
159
|
if (!ethAddress) {
|
|
181
160
|
ethAddress = (await executorFnc({
|
|
182
161
|
method: 'eth_requestAccounts'
|
|
183
162
|
}))[0];
|
|
184
163
|
}
|
|
185
|
-
|
|
186
164
|
const bytesEthAddress = makeEthAddress(ethAddress);
|
|
187
165
|
const hexEthAddress = makeHexEthAddress(ethAddress);
|
|
188
166
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getCollectionSize } from "./collection.js";
|
|
2
|
-
export { getFolderSize } from "./collection
|
|
2
|
+
export { getFolderSize } from "./collection.node.js";
|
|
3
3
|
export { isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual } from "./bytes.js";
|
|
4
4
|
export { makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString } from "./hex.js";
|
|
5
5
|
export { makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner } from "./eth.js";
|
|
@@ -7,9 +7,8 @@ export function isFile(file) {
|
|
|
7
7
|
// browser
|
|
8
8
|
if (typeof File === 'function') {
|
|
9
9
|
return file instanceof File;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
}
|
|
11
|
+
// node.js
|
|
13
12
|
const f = file;
|
|
14
13
|
return typeof f === 'object' && typeof f.name === 'string' && (typeof f.stream === 'function' || typeof f.arrayBuffer === 'function');
|
|
15
14
|
}
|
|
@@ -19,18 +18,14 @@ export function isFile(file) {
|
|
|
19
18
|
*
|
|
20
19
|
* @param file A File object
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
21
|
export async function fileArrayBuffer(file) {
|
|
24
22
|
if (file.arrayBuffer) {
|
|
25
23
|
return file.arrayBuffer();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
}
|
|
25
|
+
// workaround for Safari where arrayBuffer is not supported on Files
|
|
29
26
|
return new Promise(resolve => {
|
|
30
27
|
const fr = new FileReader();
|
|
31
|
-
|
|
32
28
|
fr.onload = () => resolve(fr.result);
|
|
33
|
-
|
|
34
29
|
fr.readAsArrayBuffer(file);
|
|
35
30
|
});
|
|
36
31
|
}
|
|
@@ -7,35 +7,28 @@ import { BeeError } from "./error.js";
|
|
|
7
7
|
*
|
|
8
8
|
* @returns the filename
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
function readContentDispositionFilename(header) {
|
|
12
11
|
if (!header) {
|
|
13
12
|
throw new BeeError('missing content-disposition header');
|
|
14
|
-
}
|
|
13
|
+
}
|
|
14
|
+
// Regex was found here
|
|
15
15
|
// https://stackoverflow.com/questions/23054475/javascript-regex-for-extracting-filename-from-content-disposition-header
|
|
16
|
-
|
|
17
|
-
|
|
18
16
|
const dispositionMatch = header.match(/filename\*?=['"]?(?:UTF-\d['"]*)?([^;\r\n"']*)['"]?;?/i);
|
|
19
|
-
|
|
20
17
|
if (dispositionMatch && dispositionMatch.length > 0) {
|
|
21
18
|
return dispositionMatch[1];
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
throw new BeeError('invalid content-disposition header');
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
function readTagUid(header) {
|
|
28
23
|
if (!header) {
|
|
29
24
|
return undefined;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
return parseInt(header, 10);
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
export function readFileHeaders(headers) {
|
|
36
|
-
const name = readContentDispositionFilename(headers
|
|
37
|
-
const tagUid = readTagUid(headers
|
|
38
|
-
const contentType = headers
|
|
29
|
+
const name = readContentDispositionFilename(headers['content-disposition']);
|
|
30
|
+
const tagUid = readTagUid(headers['swarm-tag-uid']);
|
|
31
|
+
const contentType = headers['content-type'] || undefined;
|
|
39
32
|
return {
|
|
40
33
|
name,
|
|
41
34
|
tagUid,
|
|
@@ -46,7 +39,6 @@ export function extractUploadHeaders(postageBatchId, options) {
|
|
|
46
39
|
if (!postageBatchId) {
|
|
47
40
|
throw new BeeError('Postage BatchID has to be specified!');
|
|
48
41
|
}
|
|
49
|
-
|
|
50
42
|
const headers = {
|
|
51
43
|
'swarm-postage-batch-id': postageBatchId
|
|
52
44
|
};
|
|
@@ -7,24 +7,19 @@ import { makeBytes } from "./bytes.js";
|
|
|
7
7
|
* @param input
|
|
8
8
|
* @param len of the resulting HexString WITHOUT prefix!
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
export function makeHexString(input, len) {
|
|
12
11
|
if (typeof input === 'number') {
|
|
13
12
|
return intToHex(input, len);
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
if (input instanceof Uint8Array) {
|
|
17
15
|
return bytesToHex(input, len);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
if (typeof input === 'string') {
|
|
21
18
|
if (isPrefixedHexString(input)) {
|
|
22
19
|
const hex = input.slice(2);
|
|
23
|
-
|
|
24
20
|
if (len && hex.length !== len) {
|
|
25
21
|
throw new TypeError(`Length mismatch for valid hex string. Expecting length ${len}: ${hex}`);
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
return hex;
|
|
29
24
|
} else {
|
|
30
25
|
// We use assertHexString() as there might be more reasons why a string is not valid hex string
|
|
@@ -34,7 +29,6 @@ export function makeHexString(input, len) {
|
|
|
34
29
|
return input;
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
throw new TypeError('Not HexString compatible type!');
|
|
39
33
|
}
|
|
40
34
|
/**
|
|
@@ -42,16 +36,13 @@ export function makeHexString(input, len) {
|
|
|
42
36
|
*
|
|
43
37
|
* @param hex string input without 0x prefix!
|
|
44
38
|
*/
|
|
45
|
-
|
|
46
39
|
export function hexToBytes(hex) {
|
|
47
40
|
assertHexString(hex);
|
|
48
41
|
const bytes = makeBytes(hex.length / 2);
|
|
49
|
-
|
|
50
42
|
for (let i = 0; i < bytes.length; i++) {
|
|
51
43
|
const hexByte = hex.substr(i * 2, 2);
|
|
52
44
|
bytes[i] = parseInt(hexByte, 16);
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
return bytes;
|
|
56
47
|
}
|
|
57
48
|
/**
|
|
@@ -60,16 +51,13 @@ export function hexToBytes(hex) {
|
|
|
60
51
|
* @param bytes The input array
|
|
61
52
|
* @param len The length of the non prefixed HexString
|
|
62
53
|
*/
|
|
63
|
-
|
|
64
54
|
export function bytesToHex(bytes, len) {
|
|
65
55
|
const hexByte = n => n.toString(16).padStart(2, '0');
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
const hex = Array.from(bytes, hexByte).join('');
|
|
57
|
+
// TODO: Make Length mandatory: https://github.com/ethersphere/bee-js/issues/208
|
|
69
58
|
if (len && hex.length !== len) {
|
|
70
59
|
throw new TypeError(`Resulting HexString does not have expected length ${len}: ${hex}`);
|
|
71
60
|
}
|
|
72
|
-
|
|
73
61
|
return hex;
|
|
74
62
|
}
|
|
75
63
|
/**
|
|
@@ -80,17 +68,15 @@ export function bytesToHex(bytes, len) {
|
|
|
80
68
|
* @param int The positive integer to be converted
|
|
81
69
|
* @param len The length of the non prefixed HexString
|
|
82
70
|
*/
|
|
83
|
-
|
|
84
71
|
export function intToHex(int, len) {
|
|
85
72
|
if (!Number.isInteger(int)) throw new TypeError('the value provided is not integer');
|
|
86
73
|
if (int > Number.MAX_SAFE_INTEGER) throw new TypeError('the value provided exceeds safe integer');
|
|
87
74
|
if (int < 0) throw new TypeError('the value provided is a negative integer');
|
|
88
|
-
const hex = int.toString(16);
|
|
89
|
-
|
|
75
|
+
const hex = int.toString(16);
|
|
76
|
+
// TODO: Make Length mandatory: https://github.com/ethersphere/bee-js/issues/208
|
|
90
77
|
if (len && hex.length !== len) {
|
|
91
78
|
throw new TypeError(`Resulting HexString does not have expected length ${len}: ${hex}`);
|
|
92
79
|
}
|
|
93
|
-
|
|
94
80
|
return hex;
|
|
95
81
|
}
|
|
96
82
|
/**
|
|
@@ -102,7 +88,6 @@ export function intToHex(int, len) {
|
|
|
102
88
|
* @param s string input
|
|
103
89
|
* @param len expected length of the HexString
|
|
104
90
|
*/
|
|
105
|
-
|
|
106
91
|
export function isHexString(s, len) {
|
|
107
92
|
return typeof s === 'string' && /^[0-9a-f]+$/i.test(s) && (!len || s.length === len);
|
|
108
93
|
}
|
|
@@ -112,7 +97,6 @@ export function isHexString(s, len) {
|
|
|
112
97
|
*
|
|
113
98
|
* @param s string input
|
|
114
99
|
*/
|
|
115
|
-
|
|
116
100
|
export function isPrefixedHexString(s) {
|
|
117
101
|
return typeof s === 'string' && /^0x[0-9a-f]+$/i.test(s);
|
|
118
102
|
}
|
|
@@ -126,14 +110,12 @@ export function isPrefixedHexString(s) {
|
|
|
126
110
|
* @param name optional name for the asserted value
|
|
127
111
|
* @returns HexString or throws error
|
|
128
112
|
*/
|
|
129
|
-
|
|
130
113
|
export function assertHexString(s, len, name = 'value') {
|
|
131
114
|
if (!isHexString(s, len)) {
|
|
132
115
|
if (isPrefixedHexString(s)) {
|
|
133
116
|
throw new TypeError(`${name} not valid non prefixed hex string (has 0x prefix): ${s}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
117
|
+
}
|
|
118
|
+
// Don't display length error if no length specified in order not to confuse user
|
|
137
119
|
const lengthMsg = len ? ` of length ${len}` : '';
|
|
138
120
|
throw new TypeError(`${name} not valid hex string${lengthMsg}: ${s}`);
|
|
139
121
|
}
|
|
@@ -146,7 +128,6 @@ export function assertHexString(s, len, name = 'value') {
|
|
|
146
128
|
* @param name optional name for the asserted value
|
|
147
129
|
* @returns HexString or throws error
|
|
148
130
|
*/
|
|
149
|
-
|
|
150
131
|
export function assertPrefixedHexString(s, name = 'value') {
|
|
151
132
|
if (!isPrefixedHexString(s)) {
|
|
152
133
|
throw new TypeError(`${name} not valid prefixed hex string: ${s}`);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { Objects, Strings } from 'cafe-utility';
|
|
3
|
+
export const DEFAULT_HTTP_CONFIG = {
|
|
4
|
+
headers: {
|
|
5
|
+
accept: 'application/json, text/plain, */*'
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Main function to make HTTP requests.
|
|
10
|
+
* @param options User defined settings
|
|
11
|
+
* @param config Internal settings and/or Bee settings
|
|
12
|
+
*/
|
|
13
|
+
export async function http(options, config) {
|
|
14
|
+
try {
|
|
15
|
+
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
|
|
16
|
+
maybeRunOnRequestHook(options, requestConfig);
|
|
17
|
+
const response = await axios(requestConfig);
|
|
18
|
+
return response;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function maybeRunOnRequestHook(options, requestConfig) {
|
|
24
|
+
if (options.onRequest) {
|
|
25
|
+
options.onRequest({
|
|
26
|
+
method: requestConfig.method || 'GET',
|
|
27
|
+
url: Strings.joinUrl(requestConfig.baseURL, requestConfig.url),
|
|
28
|
+
headers: {
|
|
29
|
+
...requestConfig.headers
|
|
30
|
+
},
|
|
31
|
+
params: requestConfig.params
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -6,11 +6,9 @@ import { PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
|
6
6
|
* @param target is a non-prefixed hex string Bee address
|
|
7
7
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
export function makeMaxTarget(target) {
|
|
11
10
|
if (typeof target !== 'string') {
|
|
12
11
|
throw new TypeError('target has to be an string!');
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
return target.slice(0, PSS_TARGET_HEX_LENGTH_MAX);
|
|
16
14
|
}
|
|
@@ -6,7 +6,6 @@ export function makeBytesReference(reference, offset = 0) {
|
|
|
6
6
|
if (offset) {
|
|
7
7
|
throw new Error('Offset property can be set only for UintArray reference!');
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
try {
|
|
11
10
|
// Non-encrypted chunk hex string reference
|
|
12
11
|
const hexReference = makeHexString(reference, REFERENCE_HEX_LENGTH);
|
|
@@ -14,9 +13,8 @@ export function makeBytesReference(reference, offset = 0) {
|
|
|
14
13
|
} catch (e) {
|
|
15
14
|
if (!(e instanceof TypeError)) {
|
|
16
15
|
throw e;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
}
|
|
17
|
+
// Encrypted chunk hex string reference
|
|
20
18
|
const hexReference = makeHexString(reference, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
21
19
|
return hexToBytes(hexReference);
|
|
22
20
|
}
|
|
@@ -27,6 +25,5 @@ export function makeBytesReference(reference, offset = 0) {
|
|
|
27
25
|
return bytesAtOffset(reference, offset, REFERENCE_BYTES_LENGTH);
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
throw new TypeError('invalid chunk reference');
|
|
32
29
|
}
|