@ethersphere/bee-js 3.2.0 → 3.3.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.
- package/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -0
- package/dist/cjs/chunk/bmt.js +50 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +132 -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 +7 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -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 +206 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -0
- package/dist/cjs/utils/hash.js +16 -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 +137 -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.js +28326 -0
- package/dist/index.js.map +1 -0
- package/dist/mjs/bee-debug.js +509 -0
- package/dist/mjs/bee.js +845 -0
- package/dist/mjs/chunk/bmt.js +46 -0
- package/dist/mjs/chunk/cac.js +50 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +112 -0
- package/dist/mjs/chunk/soc.js +127 -0
- package/dist/mjs/chunk/span.js +25 -0
- package/dist/mjs/feed/index.js +136 -0
- package/dist/mjs/feed/json.js +23 -0
- package/dist/mjs/feed/topic.js +20 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +56 -0
- package/dist/mjs/modules/bzz.js +119 -0
- package/dist/mjs/modules/chunk.js +43 -0
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +131 -0
- package/dist/mjs/modules/debug/chunk.js +33 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stamps.js +59 -0
- package/dist/mjs/modules/debug/states.js +29 -0
- package/dist/mjs/modules/debug/status.js +114 -0
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +57 -0
- package/dist/mjs/modules/feed.js +61 -0
- package/dist/mjs/modules/pinning.js +60 -0
- package/dist/mjs/modules/pss.js +36 -0
- package/dist/mjs/modules/soc.js +28 -0
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +69 -0
- package/dist/mjs/package.json +7 -0
- package/dist/mjs/types/debug.js +6 -0
- package/dist/mjs/types/index.js +33 -0
- package/dist/mjs/utils/bytes.js +95 -0
- package/dist/mjs/utils/collection.browser.js +18 -0
- package/dist/mjs/utils/collection.js +52 -0
- package/dist/mjs/utils/collection.node.js +63 -0
- package/dist/mjs/utils/data.browser.js +57 -0
- package/dist/mjs/utils/data.js +39 -0
- package/dist/mjs/utils/error.js +48 -0
- package/dist/mjs/utils/eth.js +184 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +33 -0
- package/dist/mjs/utils/hash.js +12 -0
- package/dist/mjs/utils/headers.js +54 -0
- package/dist/mjs/utils/hex.js +139 -0
- package/dist/mjs/utils/http.js +136 -0
- package/dist/mjs/utils/merge.js +30 -0
- package/dist/mjs/utils/pss.js +14 -0
- package/dist/mjs/utils/stamps.js +13 -0
- package/dist/mjs/utils/stream.js +131 -0
- package/dist/mjs/utils/tar.js +18 -0
- package/dist/mjs/utils/type.js +296 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +50 -0
- package/dist/{src → types}/bee-debug.d.ts +47 -1
- package/dist/{src → types}/bee.d.ts +0 -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 +0 -0
- 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 +8 -0
- package/dist/{src → types}/types/index.d.ts +1 -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/{src → types}/utils/error.d.ts +0 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +2 -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 +0 -0
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/{src → types}/utils/stamps.d.ts +0 -0
- package/dist/{src → types}/utils/stream.d.ts +0 -0
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +0 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +39 -23
- package/dist/index.browser.min.js +0 -3
- package/dist/index.browser.min.js.LICENSE.txt +0 -59
- package/dist/index.browser.min.js.map +0 -1
- 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 -24
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PSS_TARGET_HEX_LENGTH_MAX } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Utility function that for given strings/reference takes the most specific
|
|
4
|
+
* target that Bee node will except.
|
|
5
|
+
*
|
|
6
|
+
* @param target is a non-prefixed hex string Bee address
|
|
7
|
+
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
|
|
8
|
+
*/
|
|
9
|
+
export function makeMaxTarget(target) {
|
|
10
|
+
if (typeof target !== 'string') {
|
|
11
|
+
throw new TypeError('target has to be an string!');
|
|
12
|
+
}
|
|
13
|
+
return target.slice(0, PSS_TARGET_HEX_LENGTH_MAX);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
3
|
+
*
|
|
4
|
+
* Be aware for small depths (17, 18) this does not provide that much information as the provided set of distinct values
|
|
5
|
+
* is small.
|
|
6
|
+
*
|
|
7
|
+
* @param utilization
|
|
8
|
+
* @param depth
|
|
9
|
+
* @param bucketDepth
|
|
10
|
+
*/
|
|
11
|
+
export function getStampUsage({ utilization, depth, bucketDepth }) {
|
|
12
|
+
return utilization / Math.pow(2, depth - bucketDepth);
|
|
13
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isStrictlyObject } from './type';
|
|
2
|
+
import { ReadableStream } from 'web-streams-polyfill/ponyfill';
|
|
3
|
+
import { Readable as NodeReadable } from 'readable-stream';
|
|
4
|
+
/**
|
|
5
|
+
* Validates if passed object is either browser's ReadableStream
|
|
6
|
+
* or Node's Readable.
|
|
7
|
+
*
|
|
8
|
+
* @param entry
|
|
9
|
+
*/
|
|
10
|
+
export function isReadable(entry) {
|
|
11
|
+
return isReadableStream(entry) || isNodeReadable(entry);
|
|
12
|
+
}
|
|
13
|
+
export function isReadableStream(entry) {
|
|
14
|
+
if (!isStrictlyObject(entry)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const browserReadable = entry;
|
|
18
|
+
if (typeof browserReadable.getReader === 'function' &&
|
|
19
|
+
browserReadable.locked !== undefined &&
|
|
20
|
+
typeof browserReadable.cancel === 'function' &&
|
|
21
|
+
typeof browserReadable.pipeTo === 'function' &&
|
|
22
|
+
typeof browserReadable.pipeThrough === 'function') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
export function isNodeReadable(entry) {
|
|
28
|
+
if (!isStrictlyObject(entry)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const nodeReadable = entry;
|
|
32
|
+
if (typeof nodeReadable.pipe === 'function' && nodeReadable.readable && typeof nodeReadable._read === 'function') {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Function that converts Node's Readable into WHATWG ReadableStream
|
|
39
|
+
*
|
|
40
|
+
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
41
|
+
* Because it uses forked web-streams-polyfill that are outdated.
|
|
42
|
+
*
|
|
43
|
+
* @author https://github.com/gwicke
|
|
44
|
+
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
45
|
+
* @param nodeStream
|
|
46
|
+
*/
|
|
47
|
+
export function readableNodeToWeb(nodeStream) {
|
|
48
|
+
return new ReadableStream({
|
|
49
|
+
start(controller) {
|
|
50
|
+
nodeStream.pause();
|
|
51
|
+
nodeStream.on('data', chunk => {
|
|
52
|
+
if (Buffer.isBuffer(chunk)) {
|
|
53
|
+
controller.enqueue(new Uint8Array(chunk.buffer));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
controller.enqueue(chunk);
|
|
57
|
+
}
|
|
58
|
+
nodeStream.pause();
|
|
59
|
+
});
|
|
60
|
+
nodeStream.on('end', () => controller.close());
|
|
61
|
+
nodeStream.on('error', e => controller.error(e));
|
|
62
|
+
},
|
|
63
|
+
pull() {
|
|
64
|
+
nodeStream.resume();
|
|
65
|
+
},
|
|
66
|
+
cancel() {
|
|
67
|
+
nodeStream.pause();
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
73
|
+
* Because it uses forked web-streams-polyfill that are outdated.
|
|
74
|
+
*
|
|
75
|
+
* @author https://github.com/gwicke
|
|
76
|
+
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
77
|
+
*/
|
|
78
|
+
class NodeReadableWrapper extends NodeReadable {
|
|
79
|
+
_webStream;
|
|
80
|
+
_reader;
|
|
81
|
+
_reading;
|
|
82
|
+
constructor(webStream, options) {
|
|
83
|
+
super(options);
|
|
84
|
+
this._webStream = webStream;
|
|
85
|
+
this._reader = webStream.getReader();
|
|
86
|
+
this._reading = false;
|
|
87
|
+
}
|
|
88
|
+
_read() {
|
|
89
|
+
if (this._reading) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this._reading = true;
|
|
93
|
+
const doRead = () => {
|
|
94
|
+
this._reader.read().then(res => {
|
|
95
|
+
if (res.done) {
|
|
96
|
+
this.push(null);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this.push(res.value)) {
|
|
100
|
+
return doRead();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this._reading = false;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
doRead();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Function that converts WHATWG ReadableStream into Node's Readable
|
|
112
|
+
*
|
|
113
|
+
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
114
|
+
* Because it uses forked web-streams-polyfill that are outdated.
|
|
115
|
+
*
|
|
116
|
+
* @author https://github.com/gwicke
|
|
117
|
+
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
118
|
+
* @param webStream
|
|
119
|
+
*/
|
|
120
|
+
export function readableWebToNode(webStream, options) {
|
|
121
|
+
return new NodeReadableWrapper(webStream, options);
|
|
122
|
+
}
|
|
123
|
+
export function normalizeToReadableStream(stream) {
|
|
124
|
+
if (isNodeReadable(stream)) {
|
|
125
|
+
return readableNodeToWeb(stream);
|
|
126
|
+
}
|
|
127
|
+
else if (isReadableStream(stream)) {
|
|
128
|
+
return stream;
|
|
129
|
+
}
|
|
130
|
+
throw new TypeError('Passed stream is not Node Readable nor ReadableStream!');
|
|
131
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Tar from 'tar-js';
|
|
2
|
+
// converts a string to utf8 Uint8Array and returns it as a string-like
|
|
3
|
+
// object that `tar.append` accepts as path
|
|
4
|
+
function fixUnicodePath(path) {
|
|
5
|
+
const codes = new TextEncoder().encode(path);
|
|
6
|
+
return {
|
|
7
|
+
length: codes.length,
|
|
8
|
+
charCodeAt: index => codes[index],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function makeTar(data) {
|
|
12
|
+
const tar = new Tar();
|
|
13
|
+
for (const entry of data) {
|
|
14
|
+
const path = fixUnicodePath(entry.path);
|
|
15
|
+
tar.append(path, entry.data);
|
|
16
|
+
}
|
|
17
|
+
return tar.out;
|
|
18
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX, } from '../types';
|
|
2
|
+
import { BeeArgumentError } from './error';
|
|
3
|
+
import { isFile } from './file';
|
|
4
|
+
import { assertHexString, assertPrefixedHexString } from './hex';
|
|
5
|
+
import { isReadable } from './stream';
|
|
6
|
+
export function isUint8Array(obj) {
|
|
7
|
+
return obj instanceof Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export function isInteger(value) {
|
|
10
|
+
return ((typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
|
|
11
|
+
(typeof value === 'number' &&
|
|
12
|
+
value > Number.MIN_SAFE_INTEGER &&
|
|
13
|
+
value < Number.MAX_SAFE_INTEGER &&
|
|
14
|
+
Number.isInteger(value)));
|
|
15
|
+
}
|
|
16
|
+
export function isObject(value) {
|
|
17
|
+
return value !== null && typeof value === 'object';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generally it is discouraged to use `object` type, but in this case I think
|
|
21
|
+
* it is best to do so as it is possible to easily convert from `object`to other
|
|
22
|
+
* types, which will be usually the case after asserting that the object is
|
|
23
|
+
* strictly object. With for example Record<string, unknown> you have to first
|
|
24
|
+
* cast it to `unknown` which I think bit defeat the purpose.
|
|
25
|
+
*
|
|
26
|
+
* @param value
|
|
27
|
+
*/
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
29
|
+
export function isStrictlyObject(value) {
|
|
30
|
+
return isObject(value) && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Asserts if object is Error
|
|
34
|
+
*
|
|
35
|
+
* @param e
|
|
36
|
+
*/
|
|
37
|
+
export function isError(e) {
|
|
38
|
+
return e instanceof Error;
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
41
|
+
export function assertStrictlyObject(value, name = 'value') {
|
|
42
|
+
if (!isStrictlyObject(value)) {
|
|
43
|
+
throw new TypeError(`${name} has to be an object that is not null nor array!`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function assertBoolean(value, name = 'value') {
|
|
47
|
+
if (value !== true && value !== false)
|
|
48
|
+
throw new TypeError(`${name} is not boolean`);
|
|
49
|
+
}
|
|
50
|
+
export function assertInteger(value, name = 'value') {
|
|
51
|
+
if (!isInteger(value))
|
|
52
|
+
throw new TypeError(`${name} is not integer`);
|
|
53
|
+
}
|
|
54
|
+
export function assertNonNegativeInteger(value, name = 'Value') {
|
|
55
|
+
assertInteger(value, name);
|
|
56
|
+
if (Number(value) < 0)
|
|
57
|
+
throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
58
|
+
}
|
|
59
|
+
export function assertReference(value) {
|
|
60
|
+
try {
|
|
61
|
+
assertHexString(value, REFERENCE_HEX_LENGTH);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function assertAddress(value) {
|
|
68
|
+
assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
|
|
69
|
+
}
|
|
70
|
+
export function assertBatchId(value) {
|
|
71
|
+
assertHexString(value, BATCH_ID_HEX_LENGTH, 'BatchId');
|
|
72
|
+
}
|
|
73
|
+
export function assertRequestOptions(value, name = 'RequestOptions') {
|
|
74
|
+
if (value === undefined) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!isStrictlyObject(value)) {
|
|
78
|
+
throw new TypeError(`${name} has to be an object!`);
|
|
79
|
+
}
|
|
80
|
+
const options = value;
|
|
81
|
+
if (options.retry) {
|
|
82
|
+
assertNonNegativeInteger(options.retry, `${name}.retry`);
|
|
83
|
+
}
|
|
84
|
+
if (options.timeout) {
|
|
85
|
+
assertNonNegativeInteger(options.timeout, `${name}.timeout`);
|
|
86
|
+
}
|
|
87
|
+
if (options.fetch && typeof options.fetch !== 'function') {
|
|
88
|
+
throw new TypeError(`${name}.fetch has to be a function or undefined!`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function assertUploadOptions(value, name = 'UploadOptions') {
|
|
92
|
+
if (!isStrictlyObject(value)) {
|
|
93
|
+
throw new TypeError(`${name} has to be an object!`);
|
|
94
|
+
}
|
|
95
|
+
assertRequestOptions(value, name);
|
|
96
|
+
const options = value;
|
|
97
|
+
if (options.pin && typeof options.pin !== 'boolean') {
|
|
98
|
+
throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
|
|
99
|
+
}
|
|
100
|
+
if (options.encrypt && typeof options.encrypt !== 'boolean') {
|
|
101
|
+
throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
|
|
102
|
+
}
|
|
103
|
+
if (options.tag) {
|
|
104
|
+
if (typeof options.tag !== 'number') {
|
|
105
|
+
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
|
|
106
|
+
}
|
|
107
|
+
assertNonNegativeInteger(options.tag, 'options.tag');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export function assertFileUploadOptions(value) {
|
|
111
|
+
assertUploadOptions(value, 'FileUploadOptions');
|
|
112
|
+
const options = value;
|
|
113
|
+
if (options.size) {
|
|
114
|
+
if (typeof options.size !== 'number') {
|
|
115
|
+
throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
|
|
116
|
+
}
|
|
117
|
+
assertNonNegativeInteger(options.size, 'options.size');
|
|
118
|
+
}
|
|
119
|
+
if (options.contentType && typeof options.contentType !== 'string') {
|
|
120
|
+
throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function assertCollectionUploadOptions(value) {
|
|
124
|
+
assertUploadOptions(value, 'CollectionUploadOptions');
|
|
125
|
+
const options = value;
|
|
126
|
+
if (options.indexDocument && typeof options.indexDocument !== 'string') {
|
|
127
|
+
throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
128
|
+
}
|
|
129
|
+
if (options.errorDocument && typeof options.errorDocument !== 'string') {
|
|
130
|
+
throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export function isTag(value) {
|
|
134
|
+
if (!isStrictlyObject(value)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const tag = value;
|
|
138
|
+
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
139
|
+
const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number');
|
|
140
|
+
if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
export function assertTag(value) {
|
|
146
|
+
if (!isStrictlyObject(value)) {
|
|
147
|
+
throw new TypeError('Tag is not an object!');
|
|
148
|
+
}
|
|
149
|
+
const tag = value;
|
|
150
|
+
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
151
|
+
for (const numberProperty of numberProperties) {
|
|
152
|
+
if (!tag[numberProperty]) {
|
|
153
|
+
throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
|
|
154
|
+
}
|
|
155
|
+
if (typeof tag[numberProperty] !== 'number') {
|
|
156
|
+
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!tag.startedAt) {
|
|
160
|
+
throw new TypeError("Tag's property 'startedAt' has to be specified!");
|
|
161
|
+
}
|
|
162
|
+
if (typeof tag.startedAt !== 'string') {
|
|
163
|
+
throw new TypeError("Tag's property 'startedAt' has to be string!");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export function assertAddressPrefix(value) {
|
|
167
|
+
assertHexString(value, undefined, 'AddressPrefix');
|
|
168
|
+
if (value.length > PSS_TARGET_HEX_LENGTH_MAX) {
|
|
169
|
+
throw new BeeArgumentError(`AddressPrefix must have length of ${PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`, value);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export function assertPssMessageHandler(value) {
|
|
173
|
+
if (!isStrictlyObject(value)) {
|
|
174
|
+
throw new TypeError('PssMessageHandler has to be object!');
|
|
175
|
+
}
|
|
176
|
+
const handler = value;
|
|
177
|
+
if (typeof handler.onMessage !== 'function') {
|
|
178
|
+
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
179
|
+
}
|
|
180
|
+
if (typeof handler.onError !== 'function') {
|
|
181
|
+
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export function assertPublicKey(value) {
|
|
185
|
+
assertHexString(value, PUBKEY_HEX_LENGTH, 'PublicKey');
|
|
186
|
+
}
|
|
187
|
+
export function assertPostageBatchOptions(value) {
|
|
188
|
+
if (value === undefined) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
assertStrictlyObject(value);
|
|
192
|
+
const options = value;
|
|
193
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
194
|
+
if (options?.gasPrice) {
|
|
195
|
+
assertNonNegativeInteger(options.gasPrice);
|
|
196
|
+
}
|
|
197
|
+
if (options?.immutableFlag !== undefined) {
|
|
198
|
+
assertBoolean(options.immutableFlag);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export function assertCashoutOptions(value) {
|
|
202
|
+
if (value === undefined) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
assertStrictlyObject(value);
|
|
206
|
+
const options = value;
|
|
207
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
208
|
+
if (options?.gasLimit) {
|
|
209
|
+
assertNonNegativeInteger(options.gasLimit);
|
|
210
|
+
}
|
|
211
|
+
if (options?.gasPrice) {
|
|
212
|
+
assertNonNegativeInteger(options.gasPrice);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check whether the given parameter is valid data to upload
|
|
217
|
+
* @param value
|
|
218
|
+
* @throws TypeError if not valid
|
|
219
|
+
*/
|
|
220
|
+
export function assertData(value) {
|
|
221
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
222
|
+
throw new TypeError('Data must be either string or Uint8Array!');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Check whether the given parameter is a correct file representation to file upload.
|
|
227
|
+
* @param value
|
|
228
|
+
* @throws TypeError if not valid
|
|
229
|
+
*/
|
|
230
|
+
export function assertFileData(value) {
|
|
231
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !isFile(value) && !isReadable(value)) {
|
|
232
|
+
throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Checks whether optional options for AllTags query are valid
|
|
237
|
+
* @param options
|
|
238
|
+
*/
|
|
239
|
+
export function assertAllTagsOptions(entry) {
|
|
240
|
+
if (entry !== undefined && !isStrictlyObject(entry)) {
|
|
241
|
+
throw new TypeError('options has to be an object or undefined!');
|
|
242
|
+
}
|
|
243
|
+
assertRequestOptions(entry, 'AllTagsOptions');
|
|
244
|
+
const options = entry;
|
|
245
|
+
if (options?.limit !== undefined) {
|
|
246
|
+
if (typeof options.limit !== 'number') {
|
|
247
|
+
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
|
|
248
|
+
}
|
|
249
|
+
if (options.limit < TAGS_LIMIT_MIN) {
|
|
250
|
+
throw new BeeArgumentError(`AllTagsOptions.limit has to be at least ${TAGS_LIMIT_MIN}`, options.limit);
|
|
251
|
+
}
|
|
252
|
+
if (options.limit > TAGS_LIMIT_MAX) {
|
|
253
|
+
throw new BeeArgumentError(`AllTagsOptions.limit has to be at most ${TAGS_LIMIT_MAX}`, options.limit);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (options?.offset !== undefined) {
|
|
257
|
+
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Utility functions that return Tag UID
|
|
262
|
+
* @param tagUid
|
|
263
|
+
*/
|
|
264
|
+
export function makeTagUid(tagUid) {
|
|
265
|
+
if (tagUid === undefined || tagUid === null) {
|
|
266
|
+
throw new TypeError('TagUid was expected but got undefined or null instead!');
|
|
267
|
+
}
|
|
268
|
+
if (isTag(tagUid)) {
|
|
269
|
+
return tagUid.uid;
|
|
270
|
+
}
|
|
271
|
+
else if (typeof tagUid === 'number') {
|
|
272
|
+
assertNonNegativeInteger(tagUid, 'UID');
|
|
273
|
+
return tagUid;
|
|
274
|
+
}
|
|
275
|
+
else if (typeof tagUid === 'string') {
|
|
276
|
+
const int = parseInt(tagUid);
|
|
277
|
+
if (isNaN(int)) {
|
|
278
|
+
throw new TypeError('Passed tagUid string is not valid integer!');
|
|
279
|
+
}
|
|
280
|
+
if (int < 0) {
|
|
281
|
+
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
|
|
282
|
+
}
|
|
283
|
+
return int;
|
|
284
|
+
}
|
|
285
|
+
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
286
|
+
}
|
|
287
|
+
export function assertTransactionHash(transactionHash) {
|
|
288
|
+
if (typeof transactionHash !== 'string') {
|
|
289
|
+
throw new TypeError('TransactionHash has to be a string!');
|
|
290
|
+
}
|
|
291
|
+
assertPrefixedHexString(transactionHash, 'TransactionHash');
|
|
292
|
+
// Hash is 64 long + '0x' prefix = 66
|
|
293
|
+
if (transactionHash.length !== 66) {
|
|
294
|
+
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { makeBytes } from './bytes';
|
|
2
|
+
// TODO handle bigger values than 32 bit
|
|
3
|
+
// For now it's good enough because we only use these functions
|
|
4
|
+
// sequential feed indexes.
|
|
5
|
+
export function writeUint64LittleEndian(value, bytes = makeBytes(8)) {
|
|
6
|
+
const dataView = new DataView(bytes.buffer);
|
|
7
|
+
const valueLower32 = value & 0xffffffff;
|
|
8
|
+
const littleEndian = true;
|
|
9
|
+
dataView.setUint32(0, valueLower32, littleEndian);
|
|
10
|
+
dataView.setUint32(4, 0, littleEndian);
|
|
11
|
+
return bytes;
|
|
12
|
+
}
|
|
13
|
+
export function writeUint64BigEndian(value, bytes = makeBytes(8)) {
|
|
14
|
+
const dataView = new DataView(bytes.buffer);
|
|
15
|
+
const valueLower32 = value & 0xffffffff;
|
|
16
|
+
dataView.setUint32(0, 0);
|
|
17
|
+
dataView.setUint32(4, valueLower32);
|
|
18
|
+
return bytes;
|
|
19
|
+
}
|
|
20
|
+
export function readUint64BigEndian(bytes) {
|
|
21
|
+
const dataView = new DataView(bytes.buffer);
|
|
22
|
+
return dataView.getUint32(4);
|
|
23
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BeeArgumentError } from './error';
|
|
2
|
+
import { isObject } from './type';
|
|
3
|
+
function isNodeJsError(e) {
|
|
4
|
+
return isObject(e) && typeof e.code === 'string';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validates that passed string is valid URL of Bee.
|
|
8
|
+
* We support only HTTP and HTTPS protocols.
|
|
9
|
+
*
|
|
10
|
+
* @param url
|
|
11
|
+
*/
|
|
12
|
+
export function isValidBeeUrl(url) {
|
|
13
|
+
try {
|
|
14
|
+
if (typeof url !== 'string') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const urlObject = new URL(url);
|
|
18
|
+
// There can be wide range of protocols passed.
|
|
19
|
+
return urlObject.protocol === 'http:' || urlObject.protocol === 'https:';
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
// URL constructor throws TypeError if not valid URL
|
|
23
|
+
// TODO: Drop the `.code` hack for NodeJS environment: https://github.com/ethersphere/bee-js/issues/204
|
|
24
|
+
if (e instanceof TypeError || (isNodeJsError(e) && e.code === 'ERR_INVALID_URL')) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
|
|
32
|
+
* We support only HTTP and HTTPS protocols.
|
|
33
|
+
* @param url
|
|
34
|
+
* @throws BeeArgumentError if non valid URL
|
|
35
|
+
*/
|
|
36
|
+
export function assertBeeUrl(url) {
|
|
37
|
+
if (!isValidBeeUrl(url)) {
|
|
38
|
+
throw new BeeArgumentError('URL is not valid!', url);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Removes trailing slash out of the given string.
|
|
43
|
+
* @param url
|
|
44
|
+
*/
|
|
45
|
+
export function stripLastSlash(url) {
|
|
46
|
+
if (url.endsWith('/')) {
|
|
47
|
+
return url.slice(0, -1);
|
|
48
|
+
}
|
|
49
|
+
return url;
|
|
50
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, DebugPostageBatch, TransactionInfo, TransactionHash, NodeInfo } from './types';
|
|
1
|
+
import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, DebugPostageBatch, TransactionInfo, TransactionHash, NodeInfo, BeeVersions } from './types';
|
|
2
2
|
import { BatchId, BeeOptions, CashoutOptions, PostageBatchOptions, RequestOptions, Tag } from './types';
|
|
3
3
|
export declare class BeeDebug {
|
|
4
4
|
/**
|
|
@@ -125,8 +125,54 @@ export declare class BeeDebug {
|
|
|
125
125
|
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
126
126
|
*
|
|
127
127
|
* @returns true if the Bee node version is supported
|
|
128
|
+
* @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
|
|
128
129
|
*/
|
|
129
130
|
isSupportedVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
131
|
+
/**
|
|
132
|
+
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
133
|
+
*
|
|
134
|
+
* Be aware that this is the most strict version check and most probably
|
|
135
|
+
* you will want to use more relaxed API-versions based checks like
|
|
136
|
+
* `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
|
|
137
|
+
* based on your use-case.
|
|
138
|
+
*
|
|
139
|
+
* @param options
|
|
140
|
+
*/
|
|
141
|
+
isSupportedExactVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
142
|
+
/**
|
|
143
|
+
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
144
|
+
*
|
|
145
|
+
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
146
|
+
* and want to make sure about compatibility.
|
|
147
|
+
*
|
|
148
|
+
* @param options
|
|
149
|
+
*/
|
|
150
|
+
isSupportedMainApiVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
151
|
+
/**
|
|
152
|
+
* Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
|
|
153
|
+
*
|
|
154
|
+
* This is useful if you are not using `Bee` class in your application and want to make sure
|
|
155
|
+
* about compatibility.
|
|
156
|
+
*
|
|
157
|
+
* @param options
|
|
158
|
+
*/
|
|
159
|
+
isSupportedDebugApiVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
|
|
163
|
+
*
|
|
164
|
+
* This should be the main way how to check compatibility for your app and Bee node.
|
|
165
|
+
*
|
|
166
|
+
* @param options
|
|
167
|
+
*/
|
|
168
|
+
isSupportedApiVersion(options?: RequestOptions): Promise<boolean> | never;
|
|
169
|
+
/**
|
|
170
|
+
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
171
|
+
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
172
|
+
*
|
|
173
|
+
* @param options
|
|
174
|
+
*/
|
|
175
|
+
getVersions(options?: RequestOptions): Promise<BeeVersions> | never;
|
|
130
176
|
/**
|
|
131
177
|
* Get reserve state
|
|
132
178
|
*/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|