@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,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const error_1 = require("./error");
|
|
6
|
+
const file_1 = require("./file");
|
|
7
|
+
const hex_1 = require("./hex");
|
|
8
|
+
const stream_1 = require("./stream");
|
|
9
|
+
function isUint8Array(obj) {
|
|
10
|
+
return obj instanceof Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
exports.isUint8Array = isUint8Array;
|
|
13
|
+
function isInteger(value) {
|
|
14
|
+
return ((typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
|
|
15
|
+
(typeof value === 'number' &&
|
|
16
|
+
value > Number.MIN_SAFE_INTEGER &&
|
|
17
|
+
value < Number.MAX_SAFE_INTEGER &&
|
|
18
|
+
Number.isInteger(value)));
|
|
19
|
+
}
|
|
20
|
+
exports.isInteger = isInteger;
|
|
21
|
+
function isObject(value) {
|
|
22
|
+
return value !== null && typeof value === 'object';
|
|
23
|
+
}
|
|
24
|
+
exports.isObject = isObject;
|
|
25
|
+
/**
|
|
26
|
+
* Generally it is discouraged to use `object` type, but in this case I think
|
|
27
|
+
* it is best to do so as it is possible to easily convert from `object`to other
|
|
28
|
+
* types, which will be usually the case after asserting that the object is
|
|
29
|
+
* strictly object. With for example Record<string, unknown> you have to first
|
|
30
|
+
* cast it to `unknown` which I think bit defeat the purpose.
|
|
31
|
+
*
|
|
32
|
+
* @param value
|
|
33
|
+
*/
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
35
|
+
function isStrictlyObject(value) {
|
|
36
|
+
return isObject(value) && !Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
exports.isStrictlyObject = isStrictlyObject;
|
|
39
|
+
/**
|
|
40
|
+
* Asserts if object is Error
|
|
41
|
+
*
|
|
42
|
+
* @param e
|
|
43
|
+
*/
|
|
44
|
+
function isError(e) {
|
|
45
|
+
return e instanceof Error;
|
|
46
|
+
}
|
|
47
|
+
exports.isError = isError;
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
49
|
+
function assertStrictlyObject(value, name = 'value') {
|
|
50
|
+
if (!isStrictlyObject(value)) {
|
|
51
|
+
throw new TypeError(`${name} has to be an object that is not null nor array!`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.assertStrictlyObject = assertStrictlyObject;
|
|
55
|
+
function assertBoolean(value, name = 'value') {
|
|
56
|
+
if (value !== true && value !== false)
|
|
57
|
+
throw new TypeError(`${name} is not boolean`);
|
|
58
|
+
}
|
|
59
|
+
exports.assertBoolean = assertBoolean;
|
|
60
|
+
function assertInteger(value, name = 'value') {
|
|
61
|
+
if (!isInteger(value))
|
|
62
|
+
throw new TypeError(`${name} is not integer`);
|
|
63
|
+
}
|
|
64
|
+
exports.assertInteger = assertInteger;
|
|
65
|
+
function assertNonNegativeInteger(value, name = 'Value') {
|
|
66
|
+
assertInteger(value, name);
|
|
67
|
+
if (Number(value) < 0)
|
|
68
|
+
throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
69
|
+
}
|
|
70
|
+
exports.assertNonNegativeInteger = assertNonNegativeInteger;
|
|
71
|
+
function assertReference(value) {
|
|
72
|
+
try {
|
|
73
|
+
(0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
(0, hex_1.assertHexString)(value, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.assertReference = assertReference;
|
|
80
|
+
function assertAddress(value) {
|
|
81
|
+
(0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
|
|
82
|
+
}
|
|
83
|
+
exports.assertAddress = assertAddress;
|
|
84
|
+
function assertBatchId(value) {
|
|
85
|
+
(0, hex_1.assertHexString)(value, types_1.BATCH_ID_HEX_LENGTH, 'BatchId');
|
|
86
|
+
}
|
|
87
|
+
exports.assertBatchId = assertBatchId;
|
|
88
|
+
function assertRequestOptions(value, name = 'RequestOptions') {
|
|
89
|
+
if (value === undefined) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!isStrictlyObject(value)) {
|
|
93
|
+
throw new TypeError(`${name} has to be an object!`);
|
|
94
|
+
}
|
|
95
|
+
const options = value;
|
|
96
|
+
if (options.retry) {
|
|
97
|
+
assertNonNegativeInteger(options.retry, `${name}.retry`);
|
|
98
|
+
}
|
|
99
|
+
if (options.timeout) {
|
|
100
|
+
assertNonNegativeInteger(options.timeout, `${name}.timeout`);
|
|
101
|
+
}
|
|
102
|
+
if (options.fetch && typeof options.fetch !== 'function') {
|
|
103
|
+
throw new TypeError(`${name}.fetch has to be a function or undefined!`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.assertRequestOptions = assertRequestOptions;
|
|
107
|
+
function assertUploadOptions(value, name = 'UploadOptions') {
|
|
108
|
+
if (!isStrictlyObject(value)) {
|
|
109
|
+
throw new TypeError(`${name} has to be an object!`);
|
|
110
|
+
}
|
|
111
|
+
assertRequestOptions(value, name);
|
|
112
|
+
const options = value;
|
|
113
|
+
if (options.pin && typeof options.pin !== 'boolean') {
|
|
114
|
+
throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
|
|
115
|
+
}
|
|
116
|
+
if (options.encrypt && typeof options.encrypt !== 'boolean') {
|
|
117
|
+
throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
|
|
118
|
+
}
|
|
119
|
+
if (options.tag) {
|
|
120
|
+
if (typeof options.tag !== 'number') {
|
|
121
|
+
throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
|
|
122
|
+
}
|
|
123
|
+
assertNonNegativeInteger(options.tag, 'options.tag');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.assertUploadOptions = assertUploadOptions;
|
|
127
|
+
function assertFileUploadOptions(value) {
|
|
128
|
+
assertUploadOptions(value, 'FileUploadOptions');
|
|
129
|
+
const options = value;
|
|
130
|
+
if (options.size) {
|
|
131
|
+
if (typeof options.size !== 'number') {
|
|
132
|
+
throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
|
|
133
|
+
}
|
|
134
|
+
assertNonNegativeInteger(options.size, 'options.size');
|
|
135
|
+
}
|
|
136
|
+
if (options.contentType && typeof options.contentType !== 'string') {
|
|
137
|
+
throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.assertFileUploadOptions = assertFileUploadOptions;
|
|
141
|
+
function assertCollectionUploadOptions(value) {
|
|
142
|
+
assertUploadOptions(value, 'CollectionUploadOptions');
|
|
143
|
+
const options = value;
|
|
144
|
+
if (options.indexDocument && typeof options.indexDocument !== 'string') {
|
|
145
|
+
throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
146
|
+
}
|
|
147
|
+
if (options.errorDocument && typeof options.errorDocument !== 'string') {
|
|
148
|
+
throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.assertCollectionUploadOptions = assertCollectionUploadOptions;
|
|
152
|
+
function isTag(value) {
|
|
153
|
+
if (!isStrictlyObject(value)) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
const tag = value;
|
|
157
|
+
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
158
|
+
const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number');
|
|
159
|
+
if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
exports.isTag = isTag;
|
|
165
|
+
function assertTag(value) {
|
|
166
|
+
if (!isStrictlyObject(value)) {
|
|
167
|
+
throw new TypeError('Tag is not an object!');
|
|
168
|
+
}
|
|
169
|
+
const tag = value;
|
|
170
|
+
const numberProperties = ['total', 'processed', 'synced', 'uid'];
|
|
171
|
+
for (const numberProperty of numberProperties) {
|
|
172
|
+
if (!tag[numberProperty]) {
|
|
173
|
+
throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
|
|
174
|
+
}
|
|
175
|
+
if (typeof tag[numberProperty] !== 'number') {
|
|
176
|
+
throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (!tag.startedAt) {
|
|
180
|
+
throw new TypeError("Tag's property 'startedAt' has to be specified!");
|
|
181
|
+
}
|
|
182
|
+
if (typeof tag.startedAt !== 'string') {
|
|
183
|
+
throw new TypeError("Tag's property 'startedAt' has to be string!");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.assertTag = assertTag;
|
|
187
|
+
function assertAddressPrefix(value) {
|
|
188
|
+
(0, hex_1.assertHexString)(value, undefined, 'AddressPrefix');
|
|
189
|
+
if (value.length > types_1.PSS_TARGET_HEX_LENGTH_MAX) {
|
|
190
|
+
throw new error_1.BeeArgumentError(`AddressPrefix must have length of ${types_1.PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`, value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.assertAddressPrefix = assertAddressPrefix;
|
|
194
|
+
function assertPssMessageHandler(value) {
|
|
195
|
+
if (!isStrictlyObject(value)) {
|
|
196
|
+
throw new TypeError('PssMessageHandler has to be object!');
|
|
197
|
+
}
|
|
198
|
+
const handler = value;
|
|
199
|
+
if (typeof handler.onMessage !== 'function') {
|
|
200
|
+
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
201
|
+
}
|
|
202
|
+
if (typeof handler.onError !== 'function') {
|
|
203
|
+
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.assertPssMessageHandler = assertPssMessageHandler;
|
|
207
|
+
function assertPublicKey(value) {
|
|
208
|
+
(0, hex_1.assertHexString)(value, types_1.PUBKEY_HEX_LENGTH, 'PublicKey');
|
|
209
|
+
}
|
|
210
|
+
exports.assertPublicKey = assertPublicKey;
|
|
211
|
+
function assertPostageBatchOptions(value) {
|
|
212
|
+
if (value === undefined) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
assertStrictlyObject(value);
|
|
216
|
+
const options = value;
|
|
217
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
218
|
+
if (options === null || options === void 0 ? void 0 : options.gasPrice) {
|
|
219
|
+
assertNonNegativeInteger(options.gasPrice);
|
|
220
|
+
}
|
|
221
|
+
if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
|
|
222
|
+
assertBoolean(options.immutableFlag);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.assertPostageBatchOptions = assertPostageBatchOptions;
|
|
226
|
+
function assertCashoutOptions(value) {
|
|
227
|
+
if (value === undefined) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
assertStrictlyObject(value);
|
|
231
|
+
const options = value;
|
|
232
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
233
|
+
if (options === null || options === void 0 ? void 0 : options.gasLimit) {
|
|
234
|
+
assertNonNegativeInteger(options.gasLimit);
|
|
235
|
+
}
|
|
236
|
+
if (options === null || options === void 0 ? void 0 : options.gasPrice) {
|
|
237
|
+
assertNonNegativeInteger(options.gasPrice);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.assertCashoutOptions = assertCashoutOptions;
|
|
241
|
+
/**
|
|
242
|
+
* Check whether the given parameter is valid data to upload
|
|
243
|
+
* @param value
|
|
244
|
+
* @throws TypeError if not valid
|
|
245
|
+
*/
|
|
246
|
+
function assertData(value) {
|
|
247
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
|
|
248
|
+
throw new TypeError('Data must be either string or Uint8Array!');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.assertData = assertData;
|
|
252
|
+
/**
|
|
253
|
+
* Check whether the given parameter is a correct file representation to file upload.
|
|
254
|
+
* @param value
|
|
255
|
+
* @throws TypeError if not valid
|
|
256
|
+
*/
|
|
257
|
+
function assertFileData(value) {
|
|
258
|
+
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(0, file_1.isFile)(value) && !(0, stream_1.isReadable)(value)) {
|
|
259
|
+
throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.assertFileData = assertFileData;
|
|
263
|
+
/**
|
|
264
|
+
* Checks whether optional options for AllTags query are valid
|
|
265
|
+
* @param options
|
|
266
|
+
*/
|
|
267
|
+
function assertAllTagsOptions(entry) {
|
|
268
|
+
if (entry !== undefined && !isStrictlyObject(entry)) {
|
|
269
|
+
throw new TypeError('options has to be an object or undefined!');
|
|
270
|
+
}
|
|
271
|
+
assertRequestOptions(entry, 'AllTagsOptions');
|
|
272
|
+
const options = entry;
|
|
273
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
|
|
274
|
+
if (typeof options.limit !== 'number') {
|
|
275
|
+
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
|
|
276
|
+
}
|
|
277
|
+
if (options.limit < types_1.TAGS_LIMIT_MIN) {
|
|
278
|
+
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at least ${types_1.TAGS_LIMIT_MIN}`, options.limit);
|
|
279
|
+
}
|
|
280
|
+
if (options.limit > types_1.TAGS_LIMIT_MAX) {
|
|
281
|
+
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at most ${types_1.TAGS_LIMIT_MAX}`, options.limit);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
|
|
285
|
+
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.assertAllTagsOptions = assertAllTagsOptions;
|
|
289
|
+
/**
|
|
290
|
+
* Utility functions that return Tag UID
|
|
291
|
+
* @param tagUid
|
|
292
|
+
*/
|
|
293
|
+
function makeTagUid(tagUid) {
|
|
294
|
+
if (tagUid === undefined || tagUid === null) {
|
|
295
|
+
throw new TypeError('TagUid was expected but got undefined or null instead!');
|
|
296
|
+
}
|
|
297
|
+
if (isTag(tagUid)) {
|
|
298
|
+
return tagUid.uid;
|
|
299
|
+
}
|
|
300
|
+
else if (typeof tagUid === 'number') {
|
|
301
|
+
assertNonNegativeInteger(tagUid, 'UID');
|
|
302
|
+
return tagUid;
|
|
303
|
+
}
|
|
304
|
+
else if (typeof tagUid === 'string') {
|
|
305
|
+
const int = parseInt(tagUid);
|
|
306
|
+
if (isNaN(int)) {
|
|
307
|
+
throw new TypeError('Passed tagUid string is not valid integer!');
|
|
308
|
+
}
|
|
309
|
+
if (int < 0) {
|
|
310
|
+
throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
|
|
311
|
+
}
|
|
312
|
+
return int;
|
|
313
|
+
}
|
|
314
|
+
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
315
|
+
}
|
|
316
|
+
exports.makeTagUid = makeTagUid;
|
|
317
|
+
function assertTransactionHash(transactionHash) {
|
|
318
|
+
if (typeof transactionHash !== 'string') {
|
|
319
|
+
throw new TypeError('TransactionHash has to be a string!');
|
|
320
|
+
}
|
|
321
|
+
(0, hex_1.assertPrefixedHexString)(transactionHash, 'TransactionHash');
|
|
322
|
+
// Hash is 64 long + '0x' prefix = 66
|
|
323
|
+
if (transactionHash.length !== 66) {
|
|
324
|
+
throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
exports.assertTransactionHash = assertTransactionHash;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUint64BigEndian = exports.writeUint64BigEndian = exports.writeUint64LittleEndian = void 0;
|
|
4
|
+
const bytes_1 = require("./bytes");
|
|
5
|
+
// TODO handle bigger values than 32 bit
|
|
6
|
+
// For now it's good enough because we only use these functions
|
|
7
|
+
// sequential feed indexes.
|
|
8
|
+
function writeUint64LittleEndian(value, bytes = (0, bytes_1.makeBytes)(8)) {
|
|
9
|
+
const dataView = new DataView(bytes.buffer);
|
|
10
|
+
const valueLower32 = value & 0xffffffff;
|
|
11
|
+
const littleEndian = true;
|
|
12
|
+
dataView.setUint32(0, valueLower32, littleEndian);
|
|
13
|
+
dataView.setUint32(4, 0, littleEndian);
|
|
14
|
+
return bytes;
|
|
15
|
+
}
|
|
16
|
+
exports.writeUint64LittleEndian = writeUint64LittleEndian;
|
|
17
|
+
function writeUint64BigEndian(value, bytes = (0, bytes_1.makeBytes)(8)) {
|
|
18
|
+
const dataView = new DataView(bytes.buffer);
|
|
19
|
+
const valueLower32 = value & 0xffffffff;
|
|
20
|
+
dataView.setUint32(0, 0);
|
|
21
|
+
dataView.setUint32(4, valueLower32);
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
24
|
+
exports.writeUint64BigEndian = writeUint64BigEndian;
|
|
25
|
+
function readUint64BigEndian(bytes) {
|
|
26
|
+
const dataView = new DataView(bytes.buffer);
|
|
27
|
+
return dataView.getUint32(4);
|
|
28
|
+
}
|
|
29
|
+
exports.readUint64BigEndian = readUint64BigEndian;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripLastSlash = exports.assertBeeUrl = exports.isValidBeeUrl = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
const type_1 = require("./type");
|
|
6
|
+
function isNodeJsError(e) {
|
|
7
|
+
return (0, type_1.isObject)(e) && typeof e.code === 'string';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Validates that passed string is valid URL of Bee.
|
|
11
|
+
* We support only HTTP and HTTPS protocols.
|
|
12
|
+
*
|
|
13
|
+
* @param url
|
|
14
|
+
*/
|
|
15
|
+
function isValidBeeUrl(url) {
|
|
16
|
+
try {
|
|
17
|
+
if (typeof url !== 'string') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const urlObject = new URL(url);
|
|
21
|
+
// There can be wide range of protocols passed.
|
|
22
|
+
return urlObject.protocol === 'http:' || urlObject.protocol === 'https:';
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
// URL constructor throws TypeError if not valid URL
|
|
26
|
+
// TODO: Drop the `.code` hack for NodeJS environment: https://github.com/ethersphere/bee-js/issues/204
|
|
27
|
+
if (e instanceof TypeError || (isNodeJsError(e) && e.code === 'ERR_INVALID_URL')) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.isValidBeeUrl = isValidBeeUrl;
|
|
34
|
+
/**
|
|
35
|
+
* Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
|
|
36
|
+
* We support only HTTP and HTTPS protocols.
|
|
37
|
+
* @param url
|
|
38
|
+
* @throws BeeArgumentError if non valid URL
|
|
39
|
+
*/
|
|
40
|
+
function assertBeeUrl(url) {
|
|
41
|
+
if (!isValidBeeUrl(url)) {
|
|
42
|
+
throw new error_1.BeeArgumentError('URL is not valid!', url);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.assertBeeUrl = assertBeeUrl;
|
|
46
|
+
/**
|
|
47
|
+
* Removes trailing slash out of the given string.
|
|
48
|
+
* @param url
|
|
49
|
+
*/
|
|
50
|
+
function stripLastSlash(url) {
|
|
51
|
+
if (url.endsWith('/')) {
|
|
52
|
+
return url.slice(0, -1);
|
|
53
|
+
}
|
|
54
|
+
return url;
|
|
55
|
+
}
|
|
56
|
+
exports.stripLastSlash = stripLastSlash;
|