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