tool-db 2.0.2 → 2.1.2
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/bundle.js +1 -109743
- package/dist/chain/Block.d.ts +16 -8
- package/dist/chain/Block.js +81 -20
- package/dist/chain/Block.js.map +1 -1
- package/dist/chain/ToolChain.d.ts +18 -3
- package/dist/chain/ToolChain.js +191 -24
- package/dist/chain/ToolChain.js.map +1 -1
- package/dist/chain/Tx.d.ts +46 -30
- package/dist/chain/Tx.js +47 -104
- package/dist/chain/Tx.js.map +1 -1
- package/dist/chain/isValidChain.d.ts +1 -2
- package/dist/chain/isValidChain.js +24 -7
- package/dist/chain/isValidChain.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/{test-verify-a/000182.log → dist/infuraFilecoin.d.ts} +0 -0
- package/dist/infuraFilecoin.js +2 -0
- package/dist/infuraFilecoin.js.map +1 -0
- package/dist/makeTx.d.ts +1 -0
- package/dist/makeTx.js +27 -0
- package/dist/makeTx.js.map +1 -0
- package/dist/messageHandlers/handleCrdtGet.js +7 -12
- package/dist/messageHandlers/handleCrdtGet.js.map +1 -1
- package/dist/messageHandlers/handleCrdtPut.js +32 -16
- package/dist/messageHandlers/handleCrdtPut.js.map +1 -1
- package/dist/messageHandlers/handleGet.js +6 -12
- package/dist/messageHandlers/handleGet.js.map +1 -1
- package/dist/messageHandlers/handleJoin.js +1 -1
- package/dist/messageHandlers/handleJoin.js.map +1 -1
- package/dist/messageHandlers/handlePut.js +13 -22
- package/dist/messageHandlers/handlePut.js.map +1 -1
- package/dist/messageHandlers/handleServers.js +1 -1
- package/dist/messageHandlers/handleServers.js.map +1 -1
- package/dist/messageHandlers/handleSubscribe.js +14 -14
- package/dist/messageHandlers/handleSubscribe.js.map +1 -1
- package/dist/test.d.ts +1 -0
- package/dist/test.js +17 -0
- package/dist/test.js.map +1 -0
- package/dist/toolChainServer.d.ts +8 -0
- package/dist/toolChainServer.js +60 -0
- package/dist/toolChainServer.js.map +1 -0
- package/dist/toolDbAnonSignIn.js +1 -1
- package/dist/toolDbAnonSignIn.js.map +1 -1
- package/dist/toolDbClientOnMessage.js +3 -1
- package/dist/toolDbClientOnMessage.js.map +1 -1
- package/dist/toolDbCrdtGet.js +3 -1
- package/dist/toolDbCrdtGet.js.map +1 -1
- package/dist/toolDbCrdtPut.js +7 -12
- package/dist/toolDbCrdtPut.js.map +1 -1
- package/dist/toolDbGet.js +5 -2
- package/dist/toolDbGet.js.map +1 -1
- package/dist/toolDbKeysSignIn.js +1 -1
- package/dist/toolDbKeysSignIn.js.map +1 -1
- package/dist/toolDbNetwork.js +4 -4
- package/dist/toolDbNetwork.js.map +1 -1
- package/dist/toolDbPut.js +7 -12
- package/dist/toolDbPut.js.map +1 -1
- package/dist/toolDbSignIn.js +10 -16
- package/dist/toolDbSignIn.js.map +1 -1
- package/dist/toolDbSignUp.js +33 -52
- package/dist/toolDbSignUp.js.map +1 -1
- package/dist/toolDbVerificationWrapper.d.ts +2 -2
- package/dist/toolDbVerificationWrapper.js.map +1 -1
- package/dist/toolchain.d.ts +1 -0
- package/dist/toolchain.js +8 -0
- package/dist/toolchain.js.map +1 -0
- package/dist/tooldb.d.ts +14 -10
- package/dist/tooldb.js +24 -5
- package/dist/tooldb.js.map +1 -1
- package/dist/types/message.d.ts +8 -6
- package/dist/types/message.js.map +1 -1
- package/dist/types/tooldb.d.ts +0 -19
- package/dist/utils/verifyMessage.js +3 -2
- package/dist/utils/verifyMessage.js.map +1 -1
- package/dist/utils/verifyPeer.d.ts +2 -2
- package/dist/utils/verifyPeer.js +2 -2
- package/dist/utils/verifyPeer.js.map +1 -1
- package/package.json +5 -5
- package/test-alice/000425.ldb +0 -0
- package/test-alice/000427.ldb +0 -0
- package/test-alice/000430.ldb +0 -0
- package/test-alice/000431.log +0 -0
- package/test-alice/CURRENT +1 -1
- package/test-alice/LOG +5 -5
- package/test-alice/LOG.old +5 -5
- package/test-alice/MANIFEST-000429 +0 -0
- package/test-alice-speed/000236.log +0 -0
- package/test-alice-speed/000237.ldb +0 -0
- package/test-alice-speed/CURRENT +1 -1
- package/test-alice-speed/LOG +14 -5
- package/test-alice-speed/LOG.old +5 -14
- package/test-alice-speed/MANIFEST-000234 +0 -0
- package/test-bob/000425.ldb +0 -0
- package/test-bob/000427.ldb +0 -0
- package/test-bob/000430.ldb +0 -0
- package/test-bob/000431.log +0 -0
- package/test-bob/CURRENT +1 -1
- package/test-bob/LOG +5 -5
- package/test-bob/LOG.old +5 -5
- package/test-bob/MANIFEST-000429 +0 -0
- package/test-node-a/000425.ldb +0 -0
- package/test-node-a/000427.ldb +0 -0
- package/test-node-a/000430.ldb +0 -0
- package/test-node-a/000431.log +0 -0
- package/test-node-a/CURRENT +1 -1
- package/test-node-a/LOG +5 -5
- package/test-node-a/LOG.old +5 -5
- package/test-node-a/MANIFEST-000429 +0 -0
- package/test-node-b/000425.ldb +0 -0
- package/test-node-b/000427.ldb +0 -0
- package/test-node-b/000430.ldb +0 -0
- package/test-node-b/000431.log +0 -0
- package/test-node-b/CURRENT +1 -1
- package/test-node-b/LOG +5 -5
- package/test-node-b/LOG.old +5 -5
- package/test-node-b/MANIFEST-000429 +0 -0
- package/test-verify-a/000212.log +0 -0
- package/test-verify-a/CURRENT +1 -1
- package/test-verify-a/LOG +3 -3
- package/test-verify-a/LOG.old +3 -3
- package/test-verify-a/{MANIFEST-000181 → MANIFEST-000211} +0 -0
- package/pvutils-tests-replacement.js +0 -777
- package/test-alice/000269.ldb +0 -0
- package/test-alice/000271.ldb +0 -0
- package/test-alice/000274.ldb +0 -0
- package/test-alice/000277.ldb +0 -0
- package/test-alice/000278.log +0 -0
- package/test-alice/MANIFEST-000276 +0 -0
- package/test-alice-speed/000185.ldb +0 -0
- package/test-alice-speed/000187.ldb +0 -0
- package/test-alice-speed/000188.log +0 -0
- package/test-alice-speed/MANIFEST-000186 +0 -0
- package/test-bob/000269.ldb +0 -0
- package/test-bob/000271.ldb +0 -0
- package/test-bob/000274.ldb +0 -0
- package/test-bob/000277.ldb +0 -0
- package/test-bob/000278.log +0 -0
- package/test-bob/MANIFEST-000276 +0 -0
- package/test-node-a/000269.ldb +0 -0
- package/test-node-a/000271.ldb +0 -0
- package/test-node-a/000274.ldb +0 -0
- package/test-node-a/000277.ldb +0 -0
- package/test-node-a/000278.log +0 -0
- package/test-node-a/MANIFEST-000276 +0 -0
- package/test-node-b/000269.ldb +0 -0
- package/test-node-b/000271.ldb +0 -0
- package/test-node-b/000274.ldb +0 -0
- package/test-node-b/000277.ldb +0 -0
- package/test-node-b/000278.log +0 -0
- package/test-node-b/MANIFEST-000276 +0 -0
|
@@ -1,777 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getUTCDate = getUTCDate;
|
|
7
|
-
exports.getParametersValue = getParametersValue;
|
|
8
|
-
exports.bufferToHexCodes = bufferToHexCodes;
|
|
9
|
-
exports.checkBufferParams = checkBufferParams;
|
|
10
|
-
exports.utilFromBase = utilFromBase;
|
|
11
|
-
exports.utilToBase = utilToBase;
|
|
12
|
-
exports.utilConcatBuf = utilConcatBuf;
|
|
13
|
-
exports.utilConcatView = utilConcatView;
|
|
14
|
-
exports.utilDecodeTC = utilDecodeTC;
|
|
15
|
-
exports.utilEncodeTC = utilEncodeTC;
|
|
16
|
-
exports.isEqualBuffer = isEqualBuffer;
|
|
17
|
-
exports.padNumber = padNumber;
|
|
18
|
-
exports.toBase64 = toBase64;
|
|
19
|
-
exports.fromBase64 = fromBase64;
|
|
20
|
-
exports.arrayBufferToString = arrayBufferToString;
|
|
21
|
-
exports.stringToArrayBuffer = stringToArrayBuffer;
|
|
22
|
-
exports.nearestPowerOf2 = nearestPowerOf2;
|
|
23
|
-
exports.clearProps = clearProps;
|
|
24
|
-
//**************************************************************************************
|
|
25
|
-
/**
|
|
26
|
-
* Making UTC date from local date
|
|
27
|
-
* @param {Date} date Date to convert from
|
|
28
|
-
* @returns {Date}
|
|
29
|
-
*/
|
|
30
|
-
function getUTCDate(date) {
|
|
31
|
-
// noinspection NestedFunctionCallJS, MagicNumberJS
|
|
32
|
-
return new Date(date.getTime() + date.getTimezoneOffset() * 60000);
|
|
33
|
-
}
|
|
34
|
-
//**************************************************************************************
|
|
35
|
-
// noinspection FunctionWithMultipleReturnPointsJS
|
|
36
|
-
/**
|
|
37
|
-
* Get value for input parameters, or set a default value
|
|
38
|
-
* @param {Object} parameters
|
|
39
|
-
* @param {string} name
|
|
40
|
-
* @param defaultValue
|
|
41
|
-
*/
|
|
42
|
-
function getParametersValue(parameters, name, defaultValue) {
|
|
43
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS
|
|
44
|
-
if (parameters instanceof Object === false) return defaultValue;
|
|
45
|
-
|
|
46
|
-
// noinspection NonBlockStatementBodyJS
|
|
47
|
-
if (name in parameters) return parameters[name];
|
|
48
|
-
|
|
49
|
-
return defaultValue;
|
|
50
|
-
}
|
|
51
|
-
//**************************************************************************************
|
|
52
|
-
/**
|
|
53
|
-
* Converts "ArrayBuffer" into a hexdecimal string
|
|
54
|
-
* @param {ArrayBuffer} inputBuffer
|
|
55
|
-
* @param {number} [inputOffset=0]
|
|
56
|
-
* @param {number} [inputLength=inputBuffer.byteLength]
|
|
57
|
-
* @param {boolean} [insertSpace=false]
|
|
58
|
-
* @returns {string}
|
|
59
|
-
*/
|
|
60
|
-
function bufferToHexCodes(inputBuffer, inputOffset = 0, inputLength = inputBuffer.byteLength - inputOffset, insertSpace = false) {
|
|
61
|
-
let result = "";
|
|
62
|
-
|
|
63
|
-
var _iteratorNormalCompletion = true;
|
|
64
|
-
var _didIteratorError = false;
|
|
65
|
-
var _iteratorError = undefined;
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
for (var _iterator = new Uint8Array(inputBuffer, inputOffset, inputLength)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
69
|
-
const item = _step.value;
|
|
70
|
-
|
|
71
|
-
// noinspection ChainedFunctionCallJS
|
|
72
|
-
const str = item.toString(16).toUpperCase();
|
|
73
|
-
|
|
74
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS
|
|
75
|
-
if (str.length === 1) result += "0";
|
|
76
|
-
|
|
77
|
-
result += str;
|
|
78
|
-
|
|
79
|
-
// noinspection NonBlockStatementBodyJS
|
|
80
|
-
if (insertSpace) result += " ";
|
|
81
|
-
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
_didIteratorError = true;
|
|
84
|
-
_iteratorError = err;
|
|
85
|
-
} finally {
|
|
86
|
-
try {
|
|
87
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
88
|
-
_iterator.return();
|
|
89
|
-
}
|
|
90
|
-
} finally {
|
|
91
|
-
if (_didIteratorError) {
|
|
92
|
-
throw _iteratorError;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return result.trim();
|
|
98
|
-
}
|
|
99
|
-
//**************************************************************************************
|
|
100
|
-
// noinspection JSValidateJSDoc, FunctionWithMultipleReturnPointsJS
|
|
101
|
-
/**
|
|
102
|
-
* Check input "ArrayBuffer" for common functions
|
|
103
|
-
* @param {LocalBaseBlock} baseBlock
|
|
104
|
-
* @param {ArrayBuffer} inputBuffer
|
|
105
|
-
* @param {number} inputOffset
|
|
106
|
-
* @param {number} inputLength
|
|
107
|
-
* @returns {boolean}
|
|
108
|
-
*/
|
|
109
|
-
function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) {
|
|
110
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
111
|
-
// if (inputBuffer instanceof ArrayBuffer === false) {
|
|
112
|
-
// noinspection JSUndefinedPropertyAssignment
|
|
113
|
-
// baseBlock.error = "Wrong parameter: inputBuffer must be \"ArrayBuffer\"";
|
|
114
|
-
// return false;
|
|
115
|
-
// }
|
|
116
|
-
|
|
117
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
118
|
-
if (inputBuffer.byteLength === 0) {
|
|
119
|
-
// noinspection JSUndefinedPropertyAssignment
|
|
120
|
-
baseBlock.error = "Wrong parameter: inputBuffer has zero length";
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
125
|
-
if (inputOffset < 0) {
|
|
126
|
-
// noinspection JSUndefinedPropertyAssignment
|
|
127
|
-
baseBlock.error = "Wrong parameter: inputOffset less than zero";
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
132
|
-
if (inputLength < 0) {
|
|
133
|
-
// noinspection JSUndefinedPropertyAssignment
|
|
134
|
-
baseBlock.error = "Wrong parameter: inputLength less than zero";
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
139
|
-
if (inputBuffer.byteLength - inputOffset - inputLength < 0) {
|
|
140
|
-
// noinspection JSUndefinedPropertyAssignment
|
|
141
|
-
baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)";
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
//**************************************************************************************
|
|
148
|
-
// noinspection FunctionWithMultipleReturnPointsJS
|
|
149
|
-
/**
|
|
150
|
-
* Convert number from 2^base to 2^10
|
|
151
|
-
* @param {Uint8Array} inputBuffer
|
|
152
|
-
* @param {number} inputBase
|
|
153
|
-
* @returns {number}
|
|
154
|
-
*/
|
|
155
|
-
function utilFromBase(inputBuffer, inputBase) {
|
|
156
|
-
let result = 0;
|
|
157
|
-
|
|
158
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS
|
|
159
|
-
if (inputBuffer.length === 1) return inputBuffer[0];
|
|
160
|
-
|
|
161
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS
|
|
162
|
-
for (let i = inputBuffer.length - 1; i >= 0; i--) result += inputBuffer[inputBuffer.length - 1 - i] * Math.pow(2, inputBase * i);
|
|
163
|
-
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
//**************************************************************************************
|
|
167
|
-
// noinspection FunctionWithMultipleLoopsJS, FunctionWithMultipleReturnPointsJS
|
|
168
|
-
/**
|
|
169
|
-
* Convert number from 2^10 to 2^base
|
|
170
|
-
* @param {!number} value The number to convert
|
|
171
|
-
* @param {!number} base The base for 2^base
|
|
172
|
-
* @param {number} [reserved=0] Pre-defined number of bytes in output array (-1 = limited by function itself)
|
|
173
|
-
* @returns {ArrayBuffer}
|
|
174
|
-
*/
|
|
175
|
-
function utilToBase(value, base, reserved = -1) {
|
|
176
|
-
const internalReserved = reserved;
|
|
177
|
-
let internalValue = value;
|
|
178
|
-
|
|
179
|
-
let result = 0;
|
|
180
|
-
let biggest = Math.pow(2, base);
|
|
181
|
-
|
|
182
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
183
|
-
for (let i = 1; i < 8; i++) {
|
|
184
|
-
if (value < biggest) {
|
|
185
|
-
let retBuf;
|
|
186
|
-
|
|
187
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
188
|
-
if (internalReserved < 0) {
|
|
189
|
-
retBuf = new ArrayBuffer(i);
|
|
190
|
-
result = i;
|
|
191
|
-
} else {
|
|
192
|
-
// noinspection NonBlockStatementBodyJS
|
|
193
|
-
if (internalReserved < i) return new ArrayBuffer(0);
|
|
194
|
-
|
|
195
|
-
retBuf = new ArrayBuffer(internalReserved);
|
|
196
|
-
|
|
197
|
-
result = internalReserved;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const retView = new Uint8Array(retBuf);
|
|
201
|
-
|
|
202
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
203
|
-
for (let j = i - 1; j >= 0; j--) {
|
|
204
|
-
const basis = Math.pow(2, j * base);
|
|
205
|
-
|
|
206
|
-
retView[result - j - 1] = Math.floor(internalValue / basis);
|
|
207
|
-
internalValue -= retView[result - j - 1] * basis;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return retBuf;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
biggest *= Math.pow(2, base);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return new ArrayBuffer(0);
|
|
217
|
-
}
|
|
218
|
-
//**************************************************************************************
|
|
219
|
-
// noinspection FunctionWithMultipleLoopsJS
|
|
220
|
-
/**
|
|
221
|
-
* Concatenate two ArrayBuffers
|
|
222
|
-
* @param {...ArrayBuffer} buffers Set of ArrayBuffer
|
|
223
|
-
*/
|
|
224
|
-
function utilConcatBuf(...buffers) {
|
|
225
|
-
//region Initial variables
|
|
226
|
-
let outputLength = 0;
|
|
227
|
-
let prevLength = 0;
|
|
228
|
-
//endregion
|
|
229
|
-
|
|
230
|
-
//region Calculate output length
|
|
231
|
-
|
|
232
|
-
// noinspection NonBlockStatementBodyJS
|
|
233
|
-
var _iteratorNormalCompletion2 = true;
|
|
234
|
-
var _didIteratorError2 = false;
|
|
235
|
-
var _iteratorError2 = undefined;
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
for (var _iterator2 = buffers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
239
|
-
const buffer = _step2.value;
|
|
240
|
-
|
|
241
|
-
outputLength += buffer.byteLength;
|
|
242
|
-
} //endregion
|
|
243
|
-
} catch (err) {
|
|
244
|
-
_didIteratorError2 = true;
|
|
245
|
-
_iteratorError2 = err;
|
|
246
|
-
} finally {
|
|
247
|
-
try {
|
|
248
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
249
|
-
_iterator2.return();
|
|
250
|
-
}
|
|
251
|
-
} finally {
|
|
252
|
-
if (_didIteratorError2) {
|
|
253
|
-
throw _iteratorError2;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const retBuf = new ArrayBuffer(outputLength);
|
|
259
|
-
const retView = new Uint8Array(retBuf);
|
|
260
|
-
|
|
261
|
-
var _iteratorNormalCompletion3 = true;
|
|
262
|
-
var _didIteratorError3 = false;
|
|
263
|
-
var _iteratorError3 = undefined;
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
for (var _iterator3 = buffers[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
267
|
-
const buffer = _step3.value;
|
|
268
|
-
|
|
269
|
-
// noinspection NestedFunctionCallJS
|
|
270
|
-
retView.set(new Uint8Array(buffer), prevLength);
|
|
271
|
-
prevLength += buffer.byteLength;
|
|
272
|
-
}
|
|
273
|
-
} catch (err) {
|
|
274
|
-
_didIteratorError3 = true;
|
|
275
|
-
_iteratorError3 = err;
|
|
276
|
-
} finally {
|
|
277
|
-
try {
|
|
278
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
|
279
|
-
_iterator3.return();
|
|
280
|
-
}
|
|
281
|
-
} finally {
|
|
282
|
-
if (_didIteratorError3) {
|
|
283
|
-
throw _iteratorError3;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
return retBuf;
|
|
289
|
-
}
|
|
290
|
-
//**************************************************************************************
|
|
291
|
-
// noinspection FunctionWithMultipleLoopsJS
|
|
292
|
-
/**
|
|
293
|
-
* Concatenate two Uint8Array
|
|
294
|
-
* @param {...Uint8Array} views Set of Uint8Array
|
|
295
|
-
*/
|
|
296
|
-
function utilConcatView(...views) {
|
|
297
|
-
//region Initial variables
|
|
298
|
-
let outputLength = 0;
|
|
299
|
-
let prevLength = 0;
|
|
300
|
-
//endregion
|
|
301
|
-
|
|
302
|
-
//region Calculate output length
|
|
303
|
-
// noinspection NonBlockStatementBodyJS
|
|
304
|
-
var _iteratorNormalCompletion4 = true;
|
|
305
|
-
var _didIteratorError4 = false;
|
|
306
|
-
var _iteratorError4 = undefined;
|
|
307
|
-
|
|
308
|
-
try {
|
|
309
|
-
for (var _iterator4 = views[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
310
|
-
const view = _step4.value;
|
|
311
|
-
|
|
312
|
-
outputLength += view.length;
|
|
313
|
-
} //endregion
|
|
314
|
-
} catch (err) {
|
|
315
|
-
_didIteratorError4 = true;
|
|
316
|
-
_iteratorError4 = err;
|
|
317
|
-
} finally {
|
|
318
|
-
try {
|
|
319
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
|
320
|
-
_iterator4.return();
|
|
321
|
-
}
|
|
322
|
-
} finally {
|
|
323
|
-
if (_didIteratorError4) {
|
|
324
|
-
throw _iteratorError4;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const retBuf = new ArrayBuffer(outputLength);
|
|
330
|
-
const retView = new Uint8Array(retBuf);
|
|
331
|
-
|
|
332
|
-
var _iteratorNormalCompletion5 = true;
|
|
333
|
-
var _didIteratorError5 = false;
|
|
334
|
-
var _iteratorError5 = undefined;
|
|
335
|
-
|
|
336
|
-
try {
|
|
337
|
-
for (var _iterator5 = views[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
338
|
-
const view = _step5.value;
|
|
339
|
-
|
|
340
|
-
retView.set(view, prevLength);
|
|
341
|
-
prevLength += view.length;
|
|
342
|
-
}
|
|
343
|
-
} catch (err) {
|
|
344
|
-
_didIteratorError5 = true;
|
|
345
|
-
_iteratorError5 = err;
|
|
346
|
-
} finally {
|
|
347
|
-
try {
|
|
348
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
|
349
|
-
_iterator5.return();
|
|
350
|
-
}
|
|
351
|
-
} finally {
|
|
352
|
-
if (_didIteratorError5) {
|
|
353
|
-
throw _iteratorError5;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return retView;
|
|
359
|
-
}
|
|
360
|
-
//**************************************************************************************
|
|
361
|
-
// noinspection FunctionWithMultipleLoopsJS
|
|
362
|
-
/**
|
|
363
|
-
* Decoding of "two complement" values
|
|
364
|
-
* The function must be called in scope of instance of "hexBlock" class ("valueHex" and "warnings" properties must be present)
|
|
365
|
-
* @returns {number}
|
|
366
|
-
*/
|
|
367
|
-
function utilDecodeTC() {
|
|
368
|
-
const buf = new Uint8Array(this.valueHex);
|
|
369
|
-
|
|
370
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
371
|
-
if (this.valueHex.byteLength >= 2) {
|
|
372
|
-
//noinspection JSBitwiseOperatorUsage, ConstantOnRightSideOfComparisonJS, LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
373
|
-
const condition1 = buf[0] === 0xFF && buf[1] & 0x80;
|
|
374
|
-
// noinspection ConstantOnRightSideOfComparisonJS, LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
375
|
-
const condition2 = buf[0] === 0x00 && (buf[1] & 0x80) === 0x00;
|
|
376
|
-
|
|
377
|
-
// noinspection NonBlockStatementBodyJS
|
|
378
|
-
if (condition1 || condition2) this.warnings.push("Needlessly long format");
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
//region Create big part of the integer
|
|
382
|
-
const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
|
383
|
-
const bigIntView = new Uint8Array(bigIntBuffer);
|
|
384
|
-
// noinspection NonBlockStatementBodyJS
|
|
385
|
-
for (let i = 0; i < this.valueHex.byteLength; i++) bigIntView[i] = 0;
|
|
386
|
-
|
|
387
|
-
// noinspection MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
388
|
-
bigIntView[0] = buf[0] & 0x80; // mask only the biggest bit
|
|
389
|
-
|
|
390
|
-
const bigInt = utilFromBase(bigIntView, 8);
|
|
391
|
-
//endregion
|
|
392
|
-
|
|
393
|
-
//region Create small part of the integer
|
|
394
|
-
const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength);
|
|
395
|
-
const smallIntView = new Uint8Array(smallIntBuffer);
|
|
396
|
-
// noinspection NonBlockStatementBodyJS
|
|
397
|
-
for (let j = 0; j < this.valueHex.byteLength; j++) smallIntView[j] = buf[j];
|
|
398
|
-
|
|
399
|
-
// noinspection MagicNumberJS
|
|
400
|
-
smallIntView[0] &= 0x7F; // mask biggest bit
|
|
401
|
-
|
|
402
|
-
const smallInt = utilFromBase(smallIntView, 8);
|
|
403
|
-
//endregion
|
|
404
|
-
|
|
405
|
-
return smallInt - bigInt;
|
|
406
|
-
}
|
|
407
|
-
//**************************************************************************************
|
|
408
|
-
// noinspection FunctionWithMultipleLoopsJS, FunctionWithMultipleReturnPointsJS
|
|
409
|
-
/**
|
|
410
|
-
* Encode integer value to "two complement" format
|
|
411
|
-
* @param {number} value Value to encode
|
|
412
|
-
* @returns {ArrayBuffer}
|
|
413
|
-
*/
|
|
414
|
-
function utilEncodeTC(value) {
|
|
415
|
-
// noinspection ConstantOnRightSideOfComparisonJS, ConditionalExpressionJS
|
|
416
|
-
const modValue = value < 0 ? value * -1 : value;
|
|
417
|
-
let bigInt = 128;
|
|
418
|
-
|
|
419
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
420
|
-
for (let i = 1; i < 8; i++) {
|
|
421
|
-
if (modValue <= bigInt) {
|
|
422
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
423
|
-
if (value < 0) {
|
|
424
|
-
const smallInt = bigInt - modValue;
|
|
425
|
-
|
|
426
|
-
const retBuf = utilToBase(smallInt, 8, i);
|
|
427
|
-
const retView = new Uint8Array(retBuf);
|
|
428
|
-
|
|
429
|
-
// noinspection MagicNumberJS
|
|
430
|
-
retView[0] |= 0x80;
|
|
431
|
-
|
|
432
|
-
return retBuf;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
let retBuf = utilToBase(modValue, 8, i);
|
|
436
|
-
let retView = new Uint8Array(retBuf);
|
|
437
|
-
|
|
438
|
-
//noinspection JSBitwiseOperatorUsage, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
439
|
-
if (retView[0] & 0x80) {
|
|
440
|
-
//noinspection JSCheckFunctionSignatures
|
|
441
|
-
const tempBuf = retBuf.slice(0);
|
|
442
|
-
const tempView = new Uint8Array(tempBuf);
|
|
443
|
-
|
|
444
|
-
retBuf = new ArrayBuffer(retBuf.byteLength + 1);
|
|
445
|
-
// noinspection ReuseOfLocalVariableJS
|
|
446
|
-
retView = new Uint8Array(retBuf);
|
|
447
|
-
|
|
448
|
-
// noinspection NonBlockStatementBodyJS
|
|
449
|
-
for (let k = 0; k < tempBuf.byteLength; k++) retView[k + 1] = tempView[k];
|
|
450
|
-
|
|
451
|
-
// noinspection MagicNumberJS
|
|
452
|
-
retView[0] = 0x00;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return retBuf;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
bigInt *= Math.pow(2, 8);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return new ArrayBuffer(0);
|
|
462
|
-
}
|
|
463
|
-
//**************************************************************************************
|
|
464
|
-
// noinspection FunctionWithMultipleReturnPointsJS, ParameterNamingConventionJS
|
|
465
|
-
/**
|
|
466
|
-
* Compare two array buffers
|
|
467
|
-
* @param {!ArrayBuffer} inputBuffer1
|
|
468
|
-
* @param {!ArrayBuffer} inputBuffer2
|
|
469
|
-
* @returns {boolean}
|
|
470
|
-
*/
|
|
471
|
-
function isEqualBuffer(inputBuffer1, inputBuffer2) {
|
|
472
|
-
// noinspection NonBlockStatementBodyJS
|
|
473
|
-
if (inputBuffer1.byteLength !== inputBuffer2.byteLength) return false;
|
|
474
|
-
|
|
475
|
-
// noinspection LocalVariableNamingConventionJS
|
|
476
|
-
const view1 = new Uint8Array(inputBuffer1);
|
|
477
|
-
// noinspection LocalVariableNamingConventionJS
|
|
478
|
-
const view2 = new Uint8Array(inputBuffer2);
|
|
479
|
-
|
|
480
|
-
for (let i = 0; i < view1.length; i++) {
|
|
481
|
-
// noinspection NonBlockStatementBodyJS
|
|
482
|
-
if (view1[i] !== view2[i]) return false;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
return true;
|
|
486
|
-
}
|
|
487
|
-
//**************************************************************************************
|
|
488
|
-
// noinspection FunctionWithMultipleReturnPointsJS
|
|
489
|
-
/**
|
|
490
|
-
* Pad input number with leade "0" if needed
|
|
491
|
-
* @returns {string}
|
|
492
|
-
* @param {number} inputNumber
|
|
493
|
-
* @param {number} fullLength
|
|
494
|
-
*/
|
|
495
|
-
function padNumber(inputNumber, fullLength) {
|
|
496
|
-
const str = inputNumber.toString(10);
|
|
497
|
-
|
|
498
|
-
// noinspection NonBlockStatementBodyJS
|
|
499
|
-
if (fullLength < str.length) return "";
|
|
500
|
-
|
|
501
|
-
const dif = fullLength - str.length;
|
|
502
|
-
|
|
503
|
-
const padding = new Array(dif);
|
|
504
|
-
// noinspection NonBlockStatementBodyJS
|
|
505
|
-
for (let i = 0; i < dif; i++) padding[i] = "0";
|
|
506
|
-
|
|
507
|
-
const paddingString = padding.join("");
|
|
508
|
-
|
|
509
|
-
return paddingString.concat(str);
|
|
510
|
-
}
|
|
511
|
-
//**************************************************************************************
|
|
512
|
-
const base64Template = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
513
|
-
const base64UrlTemplate = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
|
|
514
|
-
//**************************************************************************************
|
|
515
|
-
// noinspection FunctionWithMultipleLoopsJS, OverlyComplexFunctionJS, FunctionTooLongJS, FunctionNamingConventionJS
|
|
516
|
-
/**
|
|
517
|
-
* Encode string into BASE64 (or "base64url")
|
|
518
|
-
* @param {string} input
|
|
519
|
-
* @param {boolean} useUrlTemplate If "true" then output would be encoded using "base64url"
|
|
520
|
-
* @param {boolean} skipPadding Skip BASE-64 padding or not
|
|
521
|
-
* @param {boolean} skipLeadingZeros Skip leading zeros in input data or not
|
|
522
|
-
* @returns {string}
|
|
523
|
-
*/
|
|
524
|
-
function toBase64(input, useUrlTemplate = false, skipPadding = false, skipLeadingZeros = false) {
|
|
525
|
-
let i = 0;
|
|
526
|
-
|
|
527
|
-
// noinspection LocalVariableNamingConventionJS
|
|
528
|
-
let flag1 = 0;
|
|
529
|
-
// noinspection LocalVariableNamingConventionJS
|
|
530
|
-
let flag2 = 0;
|
|
531
|
-
|
|
532
|
-
let output = "";
|
|
533
|
-
|
|
534
|
-
// noinspection ConditionalExpressionJS
|
|
535
|
-
const template = useUrlTemplate ? base64UrlTemplate : base64Template;
|
|
536
|
-
|
|
537
|
-
if (skipLeadingZeros) {
|
|
538
|
-
let nonZeroPosition = 0;
|
|
539
|
-
|
|
540
|
-
for (let i = 0; i < input.length; i++) {
|
|
541
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
542
|
-
if (input.charCodeAt(i) !== 0) {
|
|
543
|
-
nonZeroPosition = i;
|
|
544
|
-
// noinspection BreakStatementJS
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// noinspection AssignmentToFunctionParameterJS
|
|
550
|
-
input = input.slice(nonZeroPosition);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
while (i < input.length) {
|
|
554
|
-
// noinspection LocalVariableNamingConventionJS, IncrementDecrementResultUsedJS
|
|
555
|
-
const chr1 = input.charCodeAt(i++);
|
|
556
|
-
// noinspection NonBlockStatementBodyJS
|
|
557
|
-
if (i >= input.length) flag1 = 1;
|
|
558
|
-
// noinspection LocalVariableNamingConventionJS, IncrementDecrementResultUsedJS
|
|
559
|
-
const chr2 = input.charCodeAt(i++);
|
|
560
|
-
// noinspection NonBlockStatementBodyJS
|
|
561
|
-
if (i >= input.length) flag2 = 1;
|
|
562
|
-
// noinspection LocalVariableNamingConventionJS, IncrementDecrementResultUsedJS
|
|
563
|
-
const chr3 = input.charCodeAt(i++);
|
|
564
|
-
|
|
565
|
-
// noinspection LocalVariableNamingConventionJS
|
|
566
|
-
const enc1 = chr1 >> 2;
|
|
567
|
-
// noinspection LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
568
|
-
const enc2 = (chr1 & 0x03) << 4 | chr2 >> 4;
|
|
569
|
-
// noinspection LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
570
|
-
let enc3 = (chr2 & 0x0F) << 2 | chr3 >> 6;
|
|
571
|
-
// noinspection LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
572
|
-
let enc4 = chr3 & 0x3F;
|
|
573
|
-
|
|
574
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
575
|
-
if (flag1 === 1) {
|
|
576
|
-
// noinspection NestedAssignmentJS, AssignmentResultUsedJS, MagicNumberJS
|
|
577
|
-
enc3 = enc4 = 64;
|
|
578
|
-
} else {
|
|
579
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
580
|
-
if (flag2 === 1) {
|
|
581
|
-
// noinspection MagicNumberJS
|
|
582
|
-
enc4 = 64;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// noinspection NonBlockStatementBodyJS
|
|
587
|
-
if (skipPadding) {
|
|
588
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS, MagicNumberJS
|
|
589
|
-
if (enc3 === 64) output += `${template.charAt(enc1)}${template.charAt(enc2)}`;else {
|
|
590
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS, MagicNumberJS
|
|
591
|
-
if (enc4 === 64) output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}`;else output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
|
|
592
|
-
}
|
|
593
|
-
} else output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return output;
|
|
597
|
-
}
|
|
598
|
-
//**************************************************************************************
|
|
599
|
-
// noinspection FunctionWithMoreThanThreeNegationsJS, FunctionWithMultipleLoopsJS, OverlyComplexFunctionJS, FunctionNamingConventionJS
|
|
600
|
-
/**
|
|
601
|
-
* Decode string from BASE64 (or "base64url")
|
|
602
|
-
* @param {string} input
|
|
603
|
-
* @param {boolean} [useUrlTemplate=false] If "true" then output would be encoded using "base64url"
|
|
604
|
-
* @param {boolean} [cutTailZeros=false] If "true" then cut tailing zeroz from function result
|
|
605
|
-
* @returns {string}
|
|
606
|
-
*/
|
|
607
|
-
function fromBase64(input, useUrlTemplate = false, cutTailZeros = false) {
|
|
608
|
-
// noinspection ConditionalExpressionJS
|
|
609
|
-
const template = useUrlTemplate ? base64UrlTemplate : base64Template;
|
|
610
|
-
|
|
611
|
-
//region Aux functions
|
|
612
|
-
// noinspection FunctionWithMultipleReturnPointsJS, NestedFunctionJS
|
|
613
|
-
function indexof(toSearch) {
|
|
614
|
-
// noinspection ConstantOnRightSideOfComparisonJS, MagicNumberJS
|
|
615
|
-
for (let i = 0; i < 64; i++) {
|
|
616
|
-
// noinspection NonBlockStatementBodyJS
|
|
617
|
-
if (template.charAt(i) === toSearch) return i;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
// noinspection MagicNumberJS
|
|
621
|
-
return 64;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// noinspection NestedFunctionJS
|
|
625
|
-
function test(incoming) {
|
|
626
|
-
// noinspection ConstantOnRightSideOfComparisonJS, ConditionalExpressionJS, MagicNumberJS
|
|
627
|
-
return incoming === 64 ? 0x00 : incoming;
|
|
628
|
-
}
|
|
629
|
-
//endregion
|
|
630
|
-
|
|
631
|
-
let i = 0;
|
|
632
|
-
|
|
633
|
-
let output = "";
|
|
634
|
-
|
|
635
|
-
while (i < input.length) {
|
|
636
|
-
// noinspection NestedFunctionCallJS, LocalVariableNamingConventionJS, IncrementDecrementResultUsedJS
|
|
637
|
-
const enc1 = indexof(input.charAt(i++));
|
|
638
|
-
// noinspection NestedFunctionCallJS, LocalVariableNamingConventionJS, ConditionalExpressionJS, MagicNumberJS, IncrementDecrementResultUsedJS
|
|
639
|
-
const enc2 = i >= input.length ? 0x00 : indexof(input.charAt(i++));
|
|
640
|
-
// noinspection NestedFunctionCallJS, LocalVariableNamingConventionJS, ConditionalExpressionJS, MagicNumberJS, IncrementDecrementResultUsedJS
|
|
641
|
-
const enc3 = i >= input.length ? 0x00 : indexof(input.charAt(i++));
|
|
642
|
-
// noinspection NestedFunctionCallJS, LocalVariableNamingConventionJS, ConditionalExpressionJS, MagicNumberJS, IncrementDecrementResultUsedJS
|
|
643
|
-
const enc4 = i >= input.length ? 0x00 : indexof(input.charAt(i++));
|
|
644
|
-
|
|
645
|
-
// noinspection LocalVariableNamingConventionJS, NonShortCircuitBooleanExpressionJS
|
|
646
|
-
const chr1 = test(enc1) << 2 | test(enc2) >> 4;
|
|
647
|
-
// noinspection LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
648
|
-
const chr2 = (test(enc2) & 0x0F) << 4 | test(enc3) >> 2;
|
|
649
|
-
// noinspection LocalVariableNamingConventionJS, MagicNumberJS, NonShortCircuitBooleanExpressionJS
|
|
650
|
-
const chr3 = (test(enc3) & 0x03) << 6 | test(enc4);
|
|
651
|
-
|
|
652
|
-
output += String.fromCharCode(chr1);
|
|
653
|
-
|
|
654
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS, MagicNumberJS
|
|
655
|
-
if (enc3 !== 64) output += String.fromCharCode(chr2);
|
|
656
|
-
|
|
657
|
-
// noinspection ConstantOnRightSideOfComparisonJS, NonBlockStatementBodyJS, MagicNumberJS
|
|
658
|
-
if (enc4 !== 64) output += String.fromCharCode(chr3);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (cutTailZeros) {
|
|
662
|
-
const outputLength = output.length;
|
|
663
|
-
let nonZeroStart = -1;
|
|
664
|
-
|
|
665
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
666
|
-
for (let i = outputLength - 1; i >= 0; i--) {
|
|
667
|
-
// noinspection ConstantOnRightSideOfComparisonJS
|
|
668
|
-
if (output.charCodeAt(i) !== 0) {
|
|
669
|
-
nonZeroStart = i;
|
|
670
|
-
// noinspection BreakStatementJS
|
|
671
|
-
break;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
// noinspection NonBlockStatementBodyJS, NegatedIfStatementJS
|
|
676
|
-
if (nonZeroStart !== -1) output = output.slice(0, nonZeroStart + 1);else output = "";
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
return output;
|
|
680
|
-
}
|
|
681
|
-
//**************************************************************************************
|
|
682
|
-
function arrayBufferToString(buffer) {
|
|
683
|
-
let resultString = "";
|
|
684
|
-
const view = new Uint8Array(buffer);
|
|
685
|
-
|
|
686
|
-
// noinspection NonBlockStatementBodyJS
|
|
687
|
-
var _iteratorNormalCompletion6 = true;
|
|
688
|
-
var _didIteratorError6 = false;
|
|
689
|
-
var _iteratorError6 = undefined;
|
|
690
|
-
|
|
691
|
-
try {
|
|
692
|
-
for (var _iterator6 = view[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
693
|
-
const element = _step6.value;
|
|
694
|
-
|
|
695
|
-
resultString += String.fromCharCode(element);
|
|
696
|
-
}
|
|
697
|
-
} catch (err) {
|
|
698
|
-
_didIteratorError6 = true;
|
|
699
|
-
_iteratorError6 = err;
|
|
700
|
-
} finally {
|
|
701
|
-
try {
|
|
702
|
-
if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
|
703
|
-
_iterator6.return();
|
|
704
|
-
}
|
|
705
|
-
} finally {
|
|
706
|
-
if (_didIteratorError6) {
|
|
707
|
-
throw _iteratorError6;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return resultString;
|
|
713
|
-
}
|
|
714
|
-
//**************************************************************************************
|
|
715
|
-
function stringToArrayBuffer(str) {
|
|
716
|
-
const stringLength = str.length;
|
|
717
|
-
|
|
718
|
-
const resultBuffer = new ArrayBuffer(stringLength);
|
|
719
|
-
const resultView = new Uint8Array(resultBuffer);
|
|
720
|
-
|
|
721
|
-
// noinspection NonBlockStatementBodyJS
|
|
722
|
-
for (let i = 0; i < stringLength; i++) resultView[i] = str.charCodeAt(i);
|
|
723
|
-
|
|
724
|
-
return resultBuffer;
|
|
725
|
-
}
|
|
726
|
-
//**************************************************************************************
|
|
727
|
-
const log2 = Math.log(2);
|
|
728
|
-
//**************************************************************************************
|
|
729
|
-
// noinspection FunctionNamingConventionJS
|
|
730
|
-
/**
|
|
731
|
-
* Get nearest to input length power of 2
|
|
732
|
-
* @param {number} length Current length of existing array
|
|
733
|
-
* @returns {number}
|
|
734
|
-
*/
|
|
735
|
-
function nearestPowerOf2(length) {
|
|
736
|
-
const base = Math.log(length) / log2;
|
|
737
|
-
|
|
738
|
-
const floor = Math.floor(base);
|
|
739
|
-
const round = Math.round(base);
|
|
740
|
-
|
|
741
|
-
// noinspection ConditionalExpressionJS
|
|
742
|
-
return floor === round ? floor : round;
|
|
743
|
-
}
|
|
744
|
-
//**************************************************************************************
|
|
745
|
-
/**
|
|
746
|
-
* Delete properties by name from specified object
|
|
747
|
-
* @param {Object} object Object to delete properties from
|
|
748
|
-
* @param {Array.<string>} propsArray Array of properties names
|
|
749
|
-
*/
|
|
750
|
-
function clearProps(object, propsArray) {
|
|
751
|
-
var _iteratorNormalCompletion7 = true;
|
|
752
|
-
var _didIteratorError7 = false;
|
|
753
|
-
var _iteratorError7 = undefined;
|
|
754
|
-
|
|
755
|
-
try {
|
|
756
|
-
for (var _iterator7 = propsArray[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
|
|
757
|
-
const prop = _step7.value;
|
|
758
|
-
|
|
759
|
-
delete object[prop];
|
|
760
|
-
}
|
|
761
|
-
} catch (err) {
|
|
762
|
-
_didIteratorError7 = true;
|
|
763
|
-
_iteratorError7 = err;
|
|
764
|
-
} finally {
|
|
765
|
-
try {
|
|
766
|
-
if (!_iteratorNormalCompletion7 && _iterator7.return) {
|
|
767
|
-
_iterator7.return();
|
|
768
|
-
}
|
|
769
|
-
} finally {
|
|
770
|
-
if (_didIteratorError7) {
|
|
771
|
-
throw _iteratorError7;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
//**************************************************************************************
|
|
777
|
-
//# sourceMappingURL=utils.js.map
|