@leofcoin/chain 1.4.21 → 1.4.23
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/LICENSE +88 -88
- package/README.md +4 -4
- package/exports/chain.js +1071 -0
- package/exports/node.js +23 -0
- package/exports/typings/chain.d.ts +83 -0
- package/exports/typings/config/config.d.ts +1 -0
- package/exports/typings/config/main.d.ts +5 -0
- package/exports/typings/config/protocol.d.ts +6 -0
- package/exports/typings/contract.d.ts +29 -0
- package/exports/typings/fee/config.d.ts +4 -0
- package/exports/typings/machine.d.ts +26 -0
- package/exports/typings/node.d.ts +9 -0
- package/exports/typings/protocol.d.ts +4 -0
- package/exports/typings/state.d.ts +5 -0
- package/exports/typings/transaction.d.ts +47 -0
- package/exports/typings/typer.d.ts +6 -0
- package/package.json +77 -75
- package/CHANGELOG.md +0 -14
- package/block-worker.js +0 -1
- package/demo/865.browser.js +0 -10
- package/demo/chain.browser.js +0 -66842
- package/demo/generate-account.browser.js +0 -50
- package/demo/index.html +0 -25
- package/demo/messages.browser.js +0 -328
- package/demo/multi-wallet.browser.js +0 -15
- package/demo/node.browser.js +0 -9858
- package/demo/pako.browser.js +0 -6900
- package/demo/peernet-swarm.browser.js +0 -839
- package/demo/storage.browser.js +0 -3724
- package/demo/workers/865.js +0 -10
- package/demo/workers/block-worker.js +0 -13175
- package/demo/workers/machine-worker.js +0 -13385
- package/demo/workers/pool-worker.js +0 -8503
- package/demo/workers/transaction-worker.js +0 -8495
- package/demo/wrtc.browser.js +0 -28
- package/dist/browser/workers/865.js +0 -10
- package/dist/browser/workers/block-worker.js +0 -9460
- package/dist/browser/workers/machine-worker.js +0 -9670
- package/dist/browser/workers/pool-worker.js +0 -4608
- package/dist/browser/workers/transaction-worker.js +0 -4600
- package/dist/chain.js +0 -10128
- package/dist/client-80bc8156.js +0 -491
- package/dist/commonjs-7fe3c381.js +0 -270
- package/dist/contracts/factory.js +0 -1
- package/dist/contracts/name-service.js +0 -1
- package/dist/contracts/native-token.js +0 -1
- package/dist/contracts/validators.js +0 -1
- package/dist/generate-account-445db122.js +0 -46
- package/dist/index-57f93805.js +0 -718
- package/dist/messages-bce1b91d-81af3b00.js +0 -315
- package/dist/module/chain.js +0 -10091
- package/dist/module/client-8031ec88.js +0 -489
- package/dist/module/commonjs-9005d5c0.js +0 -268
- package/dist/module/generate-account-489552b6.js +0 -44
- package/dist/module/index-ac2285c4.js +0 -688
- package/dist/module/messages-bce1b91d-eaf75d83.js +0 -302
- package/dist/module/node.js +0 -7049
- package/dist/module/workers/block-worker.js +0 -94
- package/dist/module/workers/machine-worker.js +0 -304
- package/dist/module/workers/pool-worker.js +0 -55
- package/dist/module/workers/transaction-worker.js +0 -47
- package/dist/node.js +0 -7061
- package/dist/standards/token.js +0 -1
- package/dist/workers/machine-worker.js +0 -1
- package/dist/workers/pool-worker.js +0 -1
- package/dist/workers/transaction-worker.js +0 -1
- package/examples/contracts/token.js +0 -7
- package/plugins/bundle.js +0 -18
- package/rollup.config.js +0 -15
- package/src/chain.ts +0 -710
- package/src/config/config.js +0 -14
- package/src/config/main.js +0 -4
- package/src/config/protocol.js +0 -5
- package/src/contract.js +0 -52
- package/src/fee/config.js +0 -3
- package/src/machine.js +0 -215
- package/src/node.ts +0 -24
- package/src/protocol.js +0 -4
- package/src/state.js +0 -31
- package/src/transaction.ts +0 -182
- package/src/type.index.d.ts +0 -21
- package/src/typer.js +0 -19
- package/test/chain.js +0 -150
- package/test/contracts/token.js +0 -40
- package/test/create-genesis.js +0 -66
- package/test/index.js +0 -1
- package/tsconfig.json +0 -17
- package/workers/block-worker.js +0 -40
- package/workers/machine-worker.js +0 -219
- package/workers/pool-worker.js +0 -28
- package/workers/transaction-worker.js +0 -20
- package/workers/workers.js +0 -9
|
@@ -1,4608 +0,0 @@
|
|
|
1
|
-
/******/ var __webpack_modules__ = ({
|
|
2
|
-
|
|
3
|
-
/***/ 742:
|
|
4
|
-
/***/ (function(__unused_webpack_module, exports) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.byteLength = byteLength
|
|
9
|
-
exports.toByteArray = toByteArray
|
|
10
|
-
exports.fromByteArray = fromByteArray
|
|
11
|
-
|
|
12
|
-
var lookup = []
|
|
13
|
-
var revLookup = []
|
|
14
|
-
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
|
15
|
-
|
|
16
|
-
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
17
|
-
for (var i = 0, len = code.length; i < len; ++i) {
|
|
18
|
-
lookup[i] = code[i]
|
|
19
|
-
revLookup[code.charCodeAt(i)] = i
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
23
|
-
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
24
|
-
revLookup['-'.charCodeAt(0)] = 62
|
|
25
|
-
revLookup['_'.charCodeAt(0)] = 63
|
|
26
|
-
|
|
27
|
-
function getLens (b64) {
|
|
28
|
-
var len = b64.length
|
|
29
|
-
|
|
30
|
-
if (len % 4 > 0) {
|
|
31
|
-
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Trim off extra bytes after placeholder bytes are found
|
|
35
|
-
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
36
|
-
var validLen = b64.indexOf('=')
|
|
37
|
-
if (validLen === -1) validLen = len
|
|
38
|
-
|
|
39
|
-
var placeHoldersLen = validLen === len
|
|
40
|
-
? 0
|
|
41
|
-
: 4 - (validLen % 4)
|
|
42
|
-
|
|
43
|
-
return [validLen, placeHoldersLen]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// base64 is 4/3 + up to two characters of the original data
|
|
47
|
-
function byteLength (b64) {
|
|
48
|
-
var lens = getLens(b64)
|
|
49
|
-
var validLen = lens[0]
|
|
50
|
-
var placeHoldersLen = lens[1]
|
|
51
|
-
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function _byteLength (b64, validLen, placeHoldersLen) {
|
|
55
|
-
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function toByteArray (b64) {
|
|
59
|
-
var tmp
|
|
60
|
-
var lens = getLens(b64)
|
|
61
|
-
var validLen = lens[0]
|
|
62
|
-
var placeHoldersLen = lens[1]
|
|
63
|
-
|
|
64
|
-
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
|
65
|
-
|
|
66
|
-
var curByte = 0
|
|
67
|
-
|
|
68
|
-
// if there are placeholders, only get up to the last complete 4 chars
|
|
69
|
-
var len = placeHoldersLen > 0
|
|
70
|
-
? validLen - 4
|
|
71
|
-
: validLen
|
|
72
|
-
|
|
73
|
-
var i
|
|
74
|
-
for (i = 0; i < len; i += 4) {
|
|
75
|
-
tmp =
|
|
76
|
-
(revLookup[b64.charCodeAt(i)] << 18) |
|
|
77
|
-
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
78
|
-
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
79
|
-
revLookup[b64.charCodeAt(i + 3)]
|
|
80
|
-
arr[curByte++] = (tmp >> 16) & 0xFF
|
|
81
|
-
arr[curByte++] = (tmp >> 8) & 0xFF
|
|
82
|
-
arr[curByte++] = tmp & 0xFF
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (placeHoldersLen === 2) {
|
|
86
|
-
tmp =
|
|
87
|
-
(revLookup[b64.charCodeAt(i)] << 2) |
|
|
88
|
-
(revLookup[b64.charCodeAt(i + 1)] >> 4)
|
|
89
|
-
arr[curByte++] = tmp & 0xFF
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (placeHoldersLen === 1) {
|
|
93
|
-
tmp =
|
|
94
|
-
(revLookup[b64.charCodeAt(i)] << 10) |
|
|
95
|
-
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
96
|
-
(revLookup[b64.charCodeAt(i + 2)] >> 2)
|
|
97
|
-
arr[curByte++] = (tmp >> 8) & 0xFF
|
|
98
|
-
arr[curByte++] = tmp & 0xFF
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return arr
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function tripletToBase64 (num) {
|
|
105
|
-
return lookup[num >> 18 & 0x3F] +
|
|
106
|
-
lookup[num >> 12 & 0x3F] +
|
|
107
|
-
lookup[num >> 6 & 0x3F] +
|
|
108
|
-
lookup[num & 0x3F]
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function encodeChunk (uint8, start, end) {
|
|
112
|
-
var tmp
|
|
113
|
-
var output = []
|
|
114
|
-
for (var i = start; i < end; i += 3) {
|
|
115
|
-
tmp =
|
|
116
|
-
((uint8[i] << 16) & 0xFF0000) +
|
|
117
|
-
((uint8[i + 1] << 8) & 0xFF00) +
|
|
118
|
-
(uint8[i + 2] & 0xFF)
|
|
119
|
-
output.push(tripletToBase64(tmp))
|
|
120
|
-
}
|
|
121
|
-
return output.join('')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function fromByteArray (uint8) {
|
|
125
|
-
var tmp
|
|
126
|
-
var len = uint8.length
|
|
127
|
-
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
|
|
128
|
-
var parts = []
|
|
129
|
-
var maxChunkLength = 16383 // must be multiple of 3
|
|
130
|
-
|
|
131
|
-
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
132
|
-
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
133
|
-
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
137
|
-
if (extraBytes === 1) {
|
|
138
|
-
tmp = uint8[len - 1]
|
|
139
|
-
parts.push(
|
|
140
|
-
lookup[tmp >> 2] +
|
|
141
|
-
lookup[(tmp << 4) & 0x3F] +
|
|
142
|
-
'=='
|
|
143
|
-
)
|
|
144
|
-
} else if (extraBytes === 2) {
|
|
145
|
-
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
|
146
|
-
parts.push(
|
|
147
|
-
lookup[tmp >> 10] +
|
|
148
|
-
lookup[(tmp >> 4) & 0x3F] +
|
|
149
|
-
lookup[(tmp << 2) & 0x3F] +
|
|
150
|
-
'='
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return parts.join('')
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
/***/ }),
|
|
159
|
-
|
|
160
|
-
/***/ 764:
|
|
161
|
-
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
162
|
-
|
|
163
|
-
var __webpack_unused_export__;
|
|
164
|
-
/*!
|
|
165
|
-
* The buffer module from node.js, for the browser.
|
|
166
|
-
*
|
|
167
|
-
* @author Feross Aboukhadijeh <https://feross.org>
|
|
168
|
-
* @license MIT
|
|
169
|
-
*/
|
|
170
|
-
/* eslint-disable no-proto */
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const base64 = __webpack_require__(742)
|
|
175
|
-
const ieee754 = __webpack_require__(645)
|
|
176
|
-
const customInspectSymbol =
|
|
177
|
-
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
178
|
-
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
179
|
-
: null
|
|
180
|
-
|
|
181
|
-
exports.Buffer = Buffer
|
|
182
|
-
__webpack_unused_export__ = SlowBuffer
|
|
183
|
-
exports.INSPECT_MAX_BYTES = 50
|
|
184
|
-
|
|
185
|
-
const K_MAX_LENGTH = 0x7fffffff
|
|
186
|
-
__webpack_unused_export__ = K_MAX_LENGTH
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
190
|
-
* === true Use Uint8Array implementation (fastest)
|
|
191
|
-
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
192
|
-
* implementation (most compatible, even IE6)
|
|
193
|
-
*
|
|
194
|
-
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
195
|
-
* Opera 11.6+, iOS 4.2+.
|
|
196
|
-
*
|
|
197
|
-
* We report that the browser does not support typed arrays if the are not subclassable
|
|
198
|
-
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
199
|
-
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
200
|
-
* for __proto__ and has a buggy typed array implementation.
|
|
201
|
-
*/
|
|
202
|
-
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
|
|
203
|
-
|
|
204
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
205
|
-
typeof console.error === 'function') {
|
|
206
|
-
console.error(
|
|
207
|
-
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
208
|
-
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function typedArraySupport () {
|
|
213
|
-
// Can typed array instances can be augmented?
|
|
214
|
-
try {
|
|
215
|
-
const arr = new Uint8Array(1)
|
|
216
|
-
const proto = { foo: function () { return 42 } }
|
|
217
|
-
Object.setPrototypeOf(proto, Uint8Array.prototype)
|
|
218
|
-
Object.setPrototypeOf(arr, proto)
|
|
219
|
-
return arr.foo() === 42
|
|
220
|
-
} catch (e) {
|
|
221
|
-
return false
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
226
|
-
enumerable: true,
|
|
227
|
-
get: function () {
|
|
228
|
-
if (!Buffer.isBuffer(this)) return undefined
|
|
229
|
-
return this.buffer
|
|
230
|
-
}
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
234
|
-
enumerable: true,
|
|
235
|
-
get: function () {
|
|
236
|
-
if (!Buffer.isBuffer(this)) return undefined
|
|
237
|
-
return this.byteOffset
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
function createBuffer (length) {
|
|
242
|
-
if (length > K_MAX_LENGTH) {
|
|
243
|
-
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
244
|
-
}
|
|
245
|
-
// Return an augmented `Uint8Array` instance
|
|
246
|
-
const buf = new Uint8Array(length)
|
|
247
|
-
Object.setPrototypeOf(buf, Buffer.prototype)
|
|
248
|
-
return buf
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
253
|
-
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
254
|
-
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
255
|
-
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
256
|
-
* returns a single octet.
|
|
257
|
-
*
|
|
258
|
-
* The `Uint8Array` prototype remains unmodified.
|
|
259
|
-
*/
|
|
260
|
-
|
|
261
|
-
function Buffer (arg, encodingOrOffset, length) {
|
|
262
|
-
// Common case.
|
|
263
|
-
if (typeof arg === 'number') {
|
|
264
|
-
if (typeof encodingOrOffset === 'string') {
|
|
265
|
-
throw new TypeError(
|
|
266
|
-
'The "string" argument must be of type string. Received type number'
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
return allocUnsafe(arg)
|
|
270
|
-
}
|
|
271
|
-
return from(arg, encodingOrOffset, length)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
Buffer.poolSize = 8192 // not used by this implementation
|
|
275
|
-
|
|
276
|
-
function from (value, encodingOrOffset, length) {
|
|
277
|
-
if (typeof value === 'string') {
|
|
278
|
-
return fromString(value, encodingOrOffset)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (ArrayBuffer.isView(value)) {
|
|
282
|
-
return fromArrayView(value)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (value == null) {
|
|
286
|
-
throw new TypeError(
|
|
287
|
-
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
288
|
-
'or Array-like Object. Received type ' + (typeof value)
|
|
289
|
-
)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (isInstance(value, ArrayBuffer) ||
|
|
293
|
-
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
294
|
-
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
298
|
-
(isInstance(value, SharedArrayBuffer) ||
|
|
299
|
-
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
300
|
-
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (typeof value === 'number') {
|
|
304
|
-
throw new TypeError(
|
|
305
|
-
'The "value" argument must not be of type number. Received type number'
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const valueOf = value.valueOf && value.valueOf()
|
|
310
|
-
if (valueOf != null && valueOf !== value) {
|
|
311
|
-
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const b = fromObject(value)
|
|
315
|
-
if (b) return b
|
|
316
|
-
|
|
317
|
-
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
318
|
-
typeof value[Symbol.toPrimitive] === 'function') {
|
|
319
|
-
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
throw new TypeError(
|
|
323
|
-
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
324
|
-
'or Array-like Object. Received type ' + (typeof value)
|
|
325
|
-
)
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
330
|
-
* if value is a number.
|
|
331
|
-
* Buffer.from(str[, encoding])
|
|
332
|
-
* Buffer.from(array)
|
|
333
|
-
* Buffer.from(buffer)
|
|
334
|
-
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
335
|
-
**/
|
|
336
|
-
Buffer.from = function (value, encodingOrOffset, length) {
|
|
337
|
-
return from(value, encodingOrOffset, length)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
341
|
-
// https://github.com/feross/buffer/pull/148
|
|
342
|
-
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
|
|
343
|
-
Object.setPrototypeOf(Buffer, Uint8Array)
|
|
344
|
-
|
|
345
|
-
function assertSize (size) {
|
|
346
|
-
if (typeof size !== 'number') {
|
|
347
|
-
throw new TypeError('"size" argument must be of type number')
|
|
348
|
-
} else if (size < 0) {
|
|
349
|
-
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function alloc (size, fill, encoding) {
|
|
354
|
-
assertSize(size)
|
|
355
|
-
if (size <= 0) {
|
|
356
|
-
return createBuffer(size)
|
|
357
|
-
}
|
|
358
|
-
if (fill !== undefined) {
|
|
359
|
-
// Only pay attention to encoding if it's a string. This
|
|
360
|
-
// prevents accidentally sending in a number that would
|
|
361
|
-
// be interpreted as a start offset.
|
|
362
|
-
return typeof encoding === 'string'
|
|
363
|
-
? createBuffer(size).fill(fill, encoding)
|
|
364
|
-
: createBuffer(size).fill(fill)
|
|
365
|
-
}
|
|
366
|
-
return createBuffer(size)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Creates a new filled Buffer instance.
|
|
371
|
-
* alloc(size[, fill[, encoding]])
|
|
372
|
-
**/
|
|
373
|
-
Buffer.alloc = function (size, fill, encoding) {
|
|
374
|
-
return alloc(size, fill, encoding)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function allocUnsafe (size) {
|
|
378
|
-
assertSize(size)
|
|
379
|
-
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
384
|
-
* */
|
|
385
|
-
Buffer.allocUnsafe = function (size) {
|
|
386
|
-
return allocUnsafe(size)
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
390
|
-
*/
|
|
391
|
-
Buffer.allocUnsafeSlow = function (size) {
|
|
392
|
-
return allocUnsafe(size)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function fromString (string, encoding) {
|
|
396
|
-
if (typeof encoding !== 'string' || encoding === '') {
|
|
397
|
-
encoding = 'utf8'
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (!Buffer.isEncoding(encoding)) {
|
|
401
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
const length = byteLength(string, encoding) | 0
|
|
405
|
-
let buf = createBuffer(length)
|
|
406
|
-
|
|
407
|
-
const actual = buf.write(string, encoding)
|
|
408
|
-
|
|
409
|
-
if (actual !== length) {
|
|
410
|
-
// Writing a hex string, for example, that contains invalid characters will
|
|
411
|
-
// cause everything after the first invalid character to be ignored. (e.g.
|
|
412
|
-
// 'abxxcd' will be treated as 'ab')
|
|
413
|
-
buf = buf.slice(0, actual)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return buf
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function fromArrayLike (array) {
|
|
420
|
-
const length = array.length < 0 ? 0 : checked(array.length) | 0
|
|
421
|
-
const buf = createBuffer(length)
|
|
422
|
-
for (let i = 0; i < length; i += 1) {
|
|
423
|
-
buf[i] = array[i] & 255
|
|
424
|
-
}
|
|
425
|
-
return buf
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
function fromArrayView (arrayView) {
|
|
429
|
-
if (isInstance(arrayView, Uint8Array)) {
|
|
430
|
-
const copy = new Uint8Array(arrayView)
|
|
431
|
-
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
432
|
-
}
|
|
433
|
-
return fromArrayLike(arrayView)
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function fromArrayBuffer (array, byteOffset, length) {
|
|
437
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
438
|
-
throw new RangeError('"offset" is outside of buffer bounds')
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
|
442
|
-
throw new RangeError('"length" is outside of buffer bounds')
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
let buf
|
|
446
|
-
if (byteOffset === undefined && length === undefined) {
|
|
447
|
-
buf = new Uint8Array(array)
|
|
448
|
-
} else if (length === undefined) {
|
|
449
|
-
buf = new Uint8Array(array, byteOffset)
|
|
450
|
-
} else {
|
|
451
|
-
buf = new Uint8Array(array, byteOffset, length)
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// Return an augmented `Uint8Array` instance
|
|
455
|
-
Object.setPrototypeOf(buf, Buffer.prototype)
|
|
456
|
-
|
|
457
|
-
return buf
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function fromObject (obj) {
|
|
461
|
-
if (Buffer.isBuffer(obj)) {
|
|
462
|
-
const len = checked(obj.length) | 0
|
|
463
|
-
const buf = createBuffer(len)
|
|
464
|
-
|
|
465
|
-
if (buf.length === 0) {
|
|
466
|
-
return buf
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
obj.copy(buf, 0, 0, len)
|
|
470
|
-
return buf
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (obj.length !== undefined) {
|
|
474
|
-
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
475
|
-
return createBuffer(0)
|
|
476
|
-
}
|
|
477
|
-
return fromArrayLike(obj)
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
481
|
-
return fromArrayLike(obj.data)
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function checked (length) {
|
|
486
|
-
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
487
|
-
// length is NaN (which is otherwise coerced to zero.)
|
|
488
|
-
if (length >= K_MAX_LENGTH) {
|
|
489
|
-
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
490
|
-
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
491
|
-
}
|
|
492
|
-
return length | 0
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function SlowBuffer (length) {
|
|
496
|
-
if (+length != length) { // eslint-disable-line eqeqeq
|
|
497
|
-
length = 0
|
|
498
|
-
}
|
|
499
|
-
return Buffer.alloc(+length)
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
Buffer.isBuffer = function isBuffer (b) {
|
|
503
|
-
return b != null && b._isBuffer === true &&
|
|
504
|
-
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
Buffer.compare = function compare (a, b) {
|
|
508
|
-
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
|
|
509
|
-
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
|
|
510
|
-
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
511
|
-
throw new TypeError(
|
|
512
|
-
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
513
|
-
)
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (a === b) return 0
|
|
517
|
-
|
|
518
|
-
let x = a.length
|
|
519
|
-
let y = b.length
|
|
520
|
-
|
|
521
|
-
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
522
|
-
if (a[i] !== b[i]) {
|
|
523
|
-
x = a[i]
|
|
524
|
-
y = b[i]
|
|
525
|
-
break
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (x < y) return -1
|
|
530
|
-
if (y < x) return 1
|
|
531
|
-
return 0
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
Buffer.isEncoding = function isEncoding (encoding) {
|
|
535
|
-
switch (String(encoding).toLowerCase()) {
|
|
536
|
-
case 'hex':
|
|
537
|
-
case 'utf8':
|
|
538
|
-
case 'utf-8':
|
|
539
|
-
case 'ascii':
|
|
540
|
-
case 'latin1':
|
|
541
|
-
case 'binary':
|
|
542
|
-
case 'base64':
|
|
543
|
-
case 'ucs2':
|
|
544
|
-
case 'ucs-2':
|
|
545
|
-
case 'utf16le':
|
|
546
|
-
case 'utf-16le':
|
|
547
|
-
return true
|
|
548
|
-
default:
|
|
549
|
-
return false
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
Buffer.concat = function concat (list, length) {
|
|
554
|
-
if (!Array.isArray(list)) {
|
|
555
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (list.length === 0) {
|
|
559
|
-
return Buffer.alloc(0)
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
let i
|
|
563
|
-
if (length === undefined) {
|
|
564
|
-
length = 0
|
|
565
|
-
for (i = 0; i < list.length; ++i) {
|
|
566
|
-
length += list[i].length
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const buffer = Buffer.allocUnsafe(length)
|
|
571
|
-
let pos = 0
|
|
572
|
-
for (i = 0; i < list.length; ++i) {
|
|
573
|
-
let buf = list[i]
|
|
574
|
-
if (isInstance(buf, Uint8Array)) {
|
|
575
|
-
if (pos + buf.length > buffer.length) {
|
|
576
|
-
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf)
|
|
577
|
-
buf.copy(buffer, pos)
|
|
578
|
-
} else {
|
|
579
|
-
Uint8Array.prototype.set.call(
|
|
580
|
-
buffer,
|
|
581
|
-
buf,
|
|
582
|
-
pos
|
|
583
|
-
)
|
|
584
|
-
}
|
|
585
|
-
} else if (!Buffer.isBuffer(buf)) {
|
|
586
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
587
|
-
} else {
|
|
588
|
-
buf.copy(buffer, pos)
|
|
589
|
-
}
|
|
590
|
-
pos += buf.length
|
|
591
|
-
}
|
|
592
|
-
return buffer
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
function byteLength (string, encoding) {
|
|
596
|
-
if (Buffer.isBuffer(string)) {
|
|
597
|
-
return string.length
|
|
598
|
-
}
|
|
599
|
-
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
600
|
-
return string.byteLength
|
|
601
|
-
}
|
|
602
|
-
if (typeof string !== 'string') {
|
|
603
|
-
throw new TypeError(
|
|
604
|
-
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
605
|
-
'Received type ' + typeof string
|
|
606
|
-
)
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
const len = string.length
|
|
610
|
-
const mustMatch = (arguments.length > 2 && arguments[2] === true)
|
|
611
|
-
if (!mustMatch && len === 0) return 0
|
|
612
|
-
|
|
613
|
-
// Use a for loop to avoid recursion
|
|
614
|
-
let loweredCase = false
|
|
615
|
-
for (;;) {
|
|
616
|
-
switch (encoding) {
|
|
617
|
-
case 'ascii':
|
|
618
|
-
case 'latin1':
|
|
619
|
-
case 'binary':
|
|
620
|
-
return len
|
|
621
|
-
case 'utf8':
|
|
622
|
-
case 'utf-8':
|
|
623
|
-
return utf8ToBytes(string).length
|
|
624
|
-
case 'ucs2':
|
|
625
|
-
case 'ucs-2':
|
|
626
|
-
case 'utf16le':
|
|
627
|
-
case 'utf-16le':
|
|
628
|
-
return len * 2
|
|
629
|
-
case 'hex':
|
|
630
|
-
return len >>> 1
|
|
631
|
-
case 'base64':
|
|
632
|
-
return base64ToBytes(string).length
|
|
633
|
-
default:
|
|
634
|
-
if (loweredCase) {
|
|
635
|
-
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
636
|
-
}
|
|
637
|
-
encoding = ('' + encoding).toLowerCase()
|
|
638
|
-
loweredCase = true
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
Buffer.byteLength = byteLength
|
|
643
|
-
|
|
644
|
-
function slowToString (encoding, start, end) {
|
|
645
|
-
let loweredCase = false
|
|
646
|
-
|
|
647
|
-
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
648
|
-
// property of a typed array.
|
|
649
|
-
|
|
650
|
-
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
651
|
-
// to their upper/lower bounds if the value passed is out of range.
|
|
652
|
-
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
653
|
-
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
654
|
-
if (start === undefined || start < 0) {
|
|
655
|
-
start = 0
|
|
656
|
-
}
|
|
657
|
-
// Return early if start > this.length. Done here to prevent potential uint32
|
|
658
|
-
// coercion fail below.
|
|
659
|
-
if (start > this.length) {
|
|
660
|
-
return ''
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
if (end === undefined || end > this.length) {
|
|
664
|
-
end = this.length
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
if (end <= 0) {
|
|
668
|
-
return ''
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
672
|
-
end >>>= 0
|
|
673
|
-
start >>>= 0
|
|
674
|
-
|
|
675
|
-
if (end <= start) {
|
|
676
|
-
return ''
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
if (!encoding) encoding = 'utf8'
|
|
680
|
-
|
|
681
|
-
while (true) {
|
|
682
|
-
switch (encoding) {
|
|
683
|
-
case 'hex':
|
|
684
|
-
return hexSlice(this, start, end)
|
|
685
|
-
|
|
686
|
-
case 'utf8':
|
|
687
|
-
case 'utf-8':
|
|
688
|
-
return utf8Slice(this, start, end)
|
|
689
|
-
|
|
690
|
-
case 'ascii':
|
|
691
|
-
return asciiSlice(this, start, end)
|
|
692
|
-
|
|
693
|
-
case 'latin1':
|
|
694
|
-
case 'binary':
|
|
695
|
-
return latin1Slice(this, start, end)
|
|
696
|
-
|
|
697
|
-
case 'base64':
|
|
698
|
-
return base64Slice(this, start, end)
|
|
699
|
-
|
|
700
|
-
case 'ucs2':
|
|
701
|
-
case 'ucs-2':
|
|
702
|
-
case 'utf16le':
|
|
703
|
-
case 'utf-16le':
|
|
704
|
-
return utf16leSlice(this, start, end)
|
|
705
|
-
|
|
706
|
-
default:
|
|
707
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
708
|
-
encoding = (encoding + '').toLowerCase()
|
|
709
|
-
loweredCase = true
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
715
|
-
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
716
|
-
// reliably in a browserify context because there could be multiple different
|
|
717
|
-
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
718
|
-
// instances that were created from another copy of the `buffer` package.
|
|
719
|
-
// See: https://github.com/feross/buffer/issues/154
|
|
720
|
-
Buffer.prototype._isBuffer = true
|
|
721
|
-
|
|
722
|
-
function swap (b, n, m) {
|
|
723
|
-
const i = b[n]
|
|
724
|
-
b[n] = b[m]
|
|
725
|
-
b[m] = i
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
Buffer.prototype.swap16 = function swap16 () {
|
|
729
|
-
const len = this.length
|
|
730
|
-
if (len % 2 !== 0) {
|
|
731
|
-
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
732
|
-
}
|
|
733
|
-
for (let i = 0; i < len; i += 2) {
|
|
734
|
-
swap(this, i, i + 1)
|
|
735
|
-
}
|
|
736
|
-
return this
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
Buffer.prototype.swap32 = function swap32 () {
|
|
740
|
-
const len = this.length
|
|
741
|
-
if (len % 4 !== 0) {
|
|
742
|
-
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
743
|
-
}
|
|
744
|
-
for (let i = 0; i < len; i += 4) {
|
|
745
|
-
swap(this, i, i + 3)
|
|
746
|
-
swap(this, i + 1, i + 2)
|
|
747
|
-
}
|
|
748
|
-
return this
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
Buffer.prototype.swap64 = function swap64 () {
|
|
752
|
-
const len = this.length
|
|
753
|
-
if (len % 8 !== 0) {
|
|
754
|
-
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
755
|
-
}
|
|
756
|
-
for (let i = 0; i < len; i += 8) {
|
|
757
|
-
swap(this, i, i + 7)
|
|
758
|
-
swap(this, i + 1, i + 6)
|
|
759
|
-
swap(this, i + 2, i + 5)
|
|
760
|
-
swap(this, i + 3, i + 4)
|
|
761
|
-
}
|
|
762
|
-
return this
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
Buffer.prototype.toString = function toString () {
|
|
766
|
-
const length = this.length
|
|
767
|
-
if (length === 0) return ''
|
|
768
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
769
|
-
return slowToString.apply(this, arguments)
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
Buffer.prototype.toLocaleString = Buffer.prototype.toString
|
|
773
|
-
|
|
774
|
-
Buffer.prototype.equals = function equals (b) {
|
|
775
|
-
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
776
|
-
if (this === b) return true
|
|
777
|
-
return Buffer.compare(this, b) === 0
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
Buffer.prototype.inspect = function inspect () {
|
|
781
|
-
let str = ''
|
|
782
|
-
const max = exports.INSPECT_MAX_BYTES
|
|
783
|
-
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
|
|
784
|
-
if (this.length > max) str += ' ... '
|
|
785
|
-
return '<Buffer ' + str + '>'
|
|
786
|
-
}
|
|
787
|
-
if (customInspectSymbol) {
|
|
788
|
-
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
792
|
-
if (isInstance(target, Uint8Array)) {
|
|
793
|
-
target = Buffer.from(target, target.offset, target.byteLength)
|
|
794
|
-
}
|
|
795
|
-
if (!Buffer.isBuffer(target)) {
|
|
796
|
-
throw new TypeError(
|
|
797
|
-
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
798
|
-
'Received type ' + (typeof target)
|
|
799
|
-
)
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
if (start === undefined) {
|
|
803
|
-
start = 0
|
|
804
|
-
}
|
|
805
|
-
if (end === undefined) {
|
|
806
|
-
end = target ? target.length : 0
|
|
807
|
-
}
|
|
808
|
-
if (thisStart === undefined) {
|
|
809
|
-
thisStart = 0
|
|
810
|
-
}
|
|
811
|
-
if (thisEnd === undefined) {
|
|
812
|
-
thisEnd = this.length
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
816
|
-
throw new RangeError('out of range index')
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
820
|
-
return 0
|
|
821
|
-
}
|
|
822
|
-
if (thisStart >= thisEnd) {
|
|
823
|
-
return -1
|
|
824
|
-
}
|
|
825
|
-
if (start >= end) {
|
|
826
|
-
return 1
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
start >>>= 0
|
|
830
|
-
end >>>= 0
|
|
831
|
-
thisStart >>>= 0
|
|
832
|
-
thisEnd >>>= 0
|
|
833
|
-
|
|
834
|
-
if (this === target) return 0
|
|
835
|
-
|
|
836
|
-
let x = thisEnd - thisStart
|
|
837
|
-
let y = end - start
|
|
838
|
-
const len = Math.min(x, y)
|
|
839
|
-
|
|
840
|
-
const thisCopy = this.slice(thisStart, thisEnd)
|
|
841
|
-
const targetCopy = target.slice(start, end)
|
|
842
|
-
|
|
843
|
-
for (let i = 0; i < len; ++i) {
|
|
844
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
845
|
-
x = thisCopy[i]
|
|
846
|
-
y = targetCopy[i]
|
|
847
|
-
break
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
if (x < y) return -1
|
|
852
|
-
if (y < x) return 1
|
|
853
|
-
return 0
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
857
|
-
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
858
|
-
//
|
|
859
|
-
// Arguments:
|
|
860
|
-
// - buffer - a Buffer to search
|
|
861
|
-
// - val - a string, Buffer, or number
|
|
862
|
-
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
863
|
-
// - encoding - an optional encoding, relevant is val is a string
|
|
864
|
-
// - dir - true for indexOf, false for lastIndexOf
|
|
865
|
-
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
866
|
-
// Empty buffer means no match
|
|
867
|
-
if (buffer.length === 0) return -1
|
|
868
|
-
|
|
869
|
-
// Normalize byteOffset
|
|
870
|
-
if (typeof byteOffset === 'string') {
|
|
871
|
-
encoding = byteOffset
|
|
872
|
-
byteOffset = 0
|
|
873
|
-
} else if (byteOffset > 0x7fffffff) {
|
|
874
|
-
byteOffset = 0x7fffffff
|
|
875
|
-
} else if (byteOffset < -0x80000000) {
|
|
876
|
-
byteOffset = -0x80000000
|
|
877
|
-
}
|
|
878
|
-
byteOffset = +byteOffset // Coerce to Number.
|
|
879
|
-
if (numberIsNaN(byteOffset)) {
|
|
880
|
-
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
881
|
-
byteOffset = dir ? 0 : (buffer.length - 1)
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
885
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
|
886
|
-
if (byteOffset >= buffer.length) {
|
|
887
|
-
if (dir) return -1
|
|
888
|
-
else byteOffset = buffer.length - 1
|
|
889
|
-
} else if (byteOffset < 0) {
|
|
890
|
-
if (dir) byteOffset = 0
|
|
891
|
-
else return -1
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
// Normalize val
|
|
895
|
-
if (typeof val === 'string') {
|
|
896
|
-
val = Buffer.from(val, encoding)
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
900
|
-
if (Buffer.isBuffer(val)) {
|
|
901
|
-
// Special case: looking for empty string/buffer always fails
|
|
902
|
-
if (val.length === 0) {
|
|
903
|
-
return -1
|
|
904
|
-
}
|
|
905
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
906
|
-
} else if (typeof val === 'number') {
|
|
907
|
-
val = val & 0xFF // Search for a byte value [0-255]
|
|
908
|
-
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
909
|
-
if (dir) {
|
|
910
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
911
|
-
} else {
|
|
912
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
throw new TypeError('val must be string, number or Buffer')
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
922
|
-
let indexSize = 1
|
|
923
|
-
let arrLength = arr.length
|
|
924
|
-
let valLength = val.length
|
|
925
|
-
|
|
926
|
-
if (encoding !== undefined) {
|
|
927
|
-
encoding = String(encoding).toLowerCase()
|
|
928
|
-
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
929
|
-
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
930
|
-
if (arr.length < 2 || val.length < 2) {
|
|
931
|
-
return -1
|
|
932
|
-
}
|
|
933
|
-
indexSize = 2
|
|
934
|
-
arrLength /= 2
|
|
935
|
-
valLength /= 2
|
|
936
|
-
byteOffset /= 2
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
function read (buf, i) {
|
|
941
|
-
if (indexSize === 1) {
|
|
942
|
-
return buf[i]
|
|
943
|
-
} else {
|
|
944
|
-
return buf.readUInt16BE(i * indexSize)
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
let i
|
|
949
|
-
if (dir) {
|
|
950
|
-
let foundIndex = -1
|
|
951
|
-
for (i = byteOffset; i < arrLength; i++) {
|
|
952
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
953
|
-
if (foundIndex === -1) foundIndex = i
|
|
954
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
955
|
-
} else {
|
|
956
|
-
if (foundIndex !== -1) i -= i - foundIndex
|
|
957
|
-
foundIndex = -1
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
} else {
|
|
961
|
-
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
|
962
|
-
for (i = byteOffset; i >= 0; i--) {
|
|
963
|
-
let found = true
|
|
964
|
-
for (let j = 0; j < valLength; j++) {
|
|
965
|
-
if (read(arr, i + j) !== read(val, j)) {
|
|
966
|
-
found = false
|
|
967
|
-
break
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
if (found) return i
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
return -1
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
978
|
-
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
982
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
986
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
function hexWrite (buf, string, offset, length) {
|
|
990
|
-
offset = Number(offset) || 0
|
|
991
|
-
const remaining = buf.length - offset
|
|
992
|
-
if (!length) {
|
|
993
|
-
length = remaining
|
|
994
|
-
} else {
|
|
995
|
-
length = Number(length)
|
|
996
|
-
if (length > remaining) {
|
|
997
|
-
length = remaining
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
const strLen = string.length
|
|
1002
|
-
|
|
1003
|
-
if (length > strLen / 2) {
|
|
1004
|
-
length = strLen / 2
|
|
1005
|
-
}
|
|
1006
|
-
let i
|
|
1007
|
-
for (i = 0; i < length; ++i) {
|
|
1008
|
-
const parsed = parseInt(string.substr(i * 2, 2), 16)
|
|
1009
|
-
if (numberIsNaN(parsed)) return i
|
|
1010
|
-
buf[offset + i] = parsed
|
|
1011
|
-
}
|
|
1012
|
-
return i
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
function utf8Write (buf, string, offset, length) {
|
|
1016
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function asciiWrite (buf, string, offset, length) {
|
|
1020
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
function base64Write (buf, string, offset, length) {
|
|
1024
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
function ucs2Write (buf, string, offset, length) {
|
|
1028
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
1032
|
-
// Buffer#write(string)
|
|
1033
|
-
if (offset === undefined) {
|
|
1034
|
-
encoding = 'utf8'
|
|
1035
|
-
length = this.length
|
|
1036
|
-
offset = 0
|
|
1037
|
-
// Buffer#write(string, encoding)
|
|
1038
|
-
} else if (length === undefined && typeof offset === 'string') {
|
|
1039
|
-
encoding = offset
|
|
1040
|
-
length = this.length
|
|
1041
|
-
offset = 0
|
|
1042
|
-
// Buffer#write(string, offset[, length][, encoding])
|
|
1043
|
-
} else if (isFinite(offset)) {
|
|
1044
|
-
offset = offset >>> 0
|
|
1045
|
-
if (isFinite(length)) {
|
|
1046
|
-
length = length >>> 0
|
|
1047
|
-
if (encoding === undefined) encoding = 'utf8'
|
|
1048
|
-
} else {
|
|
1049
|
-
encoding = length
|
|
1050
|
-
length = undefined
|
|
1051
|
-
}
|
|
1052
|
-
} else {
|
|
1053
|
-
throw new Error(
|
|
1054
|
-
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
1055
|
-
)
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
const remaining = this.length - offset
|
|
1059
|
-
if (length === undefined || length > remaining) length = remaining
|
|
1060
|
-
|
|
1061
|
-
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
1062
|
-
throw new RangeError('Attempt to write outside buffer bounds')
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
if (!encoding) encoding = 'utf8'
|
|
1066
|
-
|
|
1067
|
-
let loweredCase = false
|
|
1068
|
-
for (;;) {
|
|
1069
|
-
switch (encoding) {
|
|
1070
|
-
case 'hex':
|
|
1071
|
-
return hexWrite(this, string, offset, length)
|
|
1072
|
-
|
|
1073
|
-
case 'utf8':
|
|
1074
|
-
case 'utf-8':
|
|
1075
|
-
return utf8Write(this, string, offset, length)
|
|
1076
|
-
|
|
1077
|
-
case 'ascii':
|
|
1078
|
-
case 'latin1':
|
|
1079
|
-
case 'binary':
|
|
1080
|
-
return asciiWrite(this, string, offset, length)
|
|
1081
|
-
|
|
1082
|
-
case 'base64':
|
|
1083
|
-
// Warning: maxLength not taken into account in base64Write
|
|
1084
|
-
return base64Write(this, string, offset, length)
|
|
1085
|
-
|
|
1086
|
-
case 'ucs2':
|
|
1087
|
-
case 'ucs-2':
|
|
1088
|
-
case 'utf16le':
|
|
1089
|
-
case 'utf-16le':
|
|
1090
|
-
return ucs2Write(this, string, offset, length)
|
|
1091
|
-
|
|
1092
|
-
default:
|
|
1093
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
1094
|
-
encoding = ('' + encoding).toLowerCase()
|
|
1095
|
-
loweredCase = true
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
Buffer.prototype.toJSON = function toJSON () {
|
|
1101
|
-
return {
|
|
1102
|
-
type: 'Buffer',
|
|
1103
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
function base64Slice (buf, start, end) {
|
|
1108
|
-
if (start === 0 && end === buf.length) {
|
|
1109
|
-
return base64.fromByteArray(buf)
|
|
1110
|
-
} else {
|
|
1111
|
-
return base64.fromByteArray(buf.slice(start, end))
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
function utf8Slice (buf, start, end) {
|
|
1116
|
-
end = Math.min(buf.length, end)
|
|
1117
|
-
const res = []
|
|
1118
|
-
|
|
1119
|
-
let i = start
|
|
1120
|
-
while (i < end) {
|
|
1121
|
-
const firstByte = buf[i]
|
|
1122
|
-
let codePoint = null
|
|
1123
|
-
let bytesPerSequence = (firstByte > 0xEF)
|
|
1124
|
-
? 4
|
|
1125
|
-
: (firstByte > 0xDF)
|
|
1126
|
-
? 3
|
|
1127
|
-
: (firstByte > 0xBF)
|
|
1128
|
-
? 2
|
|
1129
|
-
: 1
|
|
1130
|
-
|
|
1131
|
-
if (i + bytesPerSequence <= end) {
|
|
1132
|
-
let secondByte, thirdByte, fourthByte, tempCodePoint
|
|
1133
|
-
|
|
1134
|
-
switch (bytesPerSequence) {
|
|
1135
|
-
case 1:
|
|
1136
|
-
if (firstByte < 0x80) {
|
|
1137
|
-
codePoint = firstByte
|
|
1138
|
-
}
|
|
1139
|
-
break
|
|
1140
|
-
case 2:
|
|
1141
|
-
secondByte = buf[i + 1]
|
|
1142
|
-
if ((secondByte & 0xC0) === 0x80) {
|
|
1143
|
-
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
|
1144
|
-
if (tempCodePoint > 0x7F) {
|
|
1145
|
-
codePoint = tempCodePoint
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
break
|
|
1149
|
-
case 3:
|
|
1150
|
-
secondByte = buf[i + 1]
|
|
1151
|
-
thirdByte = buf[i + 2]
|
|
1152
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
1153
|
-
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
|
1154
|
-
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
1155
|
-
codePoint = tempCodePoint
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
break
|
|
1159
|
-
case 4:
|
|
1160
|
-
secondByte = buf[i + 1]
|
|
1161
|
-
thirdByte = buf[i + 2]
|
|
1162
|
-
fourthByte = buf[i + 3]
|
|
1163
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
1164
|
-
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
|
1165
|
-
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
1166
|
-
codePoint = tempCodePoint
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
if (codePoint === null) {
|
|
1173
|
-
// we did not generate a valid codePoint so insert a
|
|
1174
|
-
// replacement char (U+FFFD) and advance only 1 byte
|
|
1175
|
-
codePoint = 0xFFFD
|
|
1176
|
-
bytesPerSequence = 1
|
|
1177
|
-
} else if (codePoint > 0xFFFF) {
|
|
1178
|
-
// encode to utf16 (surrogate pair dance)
|
|
1179
|
-
codePoint -= 0x10000
|
|
1180
|
-
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
|
1181
|
-
codePoint = 0xDC00 | codePoint & 0x3FF
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
res.push(codePoint)
|
|
1185
|
-
i += bytesPerSequence
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
return decodeCodePointsArray(res)
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1192
|
-
// the lowest limit is Chrome, with 0x10000 args.
|
|
1193
|
-
// We go 1 magnitude less, for safety
|
|
1194
|
-
const MAX_ARGUMENTS_LENGTH = 0x1000
|
|
1195
|
-
|
|
1196
|
-
function decodeCodePointsArray (codePoints) {
|
|
1197
|
-
const len = codePoints.length
|
|
1198
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1199
|
-
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
// Decode in chunks to avoid "call stack size exceeded".
|
|
1203
|
-
let res = ''
|
|
1204
|
-
let i = 0
|
|
1205
|
-
while (i < len) {
|
|
1206
|
-
res += String.fromCharCode.apply(
|
|
1207
|
-
String,
|
|
1208
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
1209
|
-
)
|
|
1210
|
-
}
|
|
1211
|
-
return res
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
function asciiSlice (buf, start, end) {
|
|
1215
|
-
let ret = ''
|
|
1216
|
-
end = Math.min(buf.length, end)
|
|
1217
|
-
|
|
1218
|
-
for (let i = start; i < end; ++i) {
|
|
1219
|
-
ret += String.fromCharCode(buf[i] & 0x7F)
|
|
1220
|
-
}
|
|
1221
|
-
return ret
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
function latin1Slice (buf, start, end) {
|
|
1225
|
-
let ret = ''
|
|
1226
|
-
end = Math.min(buf.length, end)
|
|
1227
|
-
|
|
1228
|
-
for (let i = start; i < end; ++i) {
|
|
1229
|
-
ret += String.fromCharCode(buf[i])
|
|
1230
|
-
}
|
|
1231
|
-
return ret
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
function hexSlice (buf, start, end) {
|
|
1235
|
-
const len = buf.length
|
|
1236
|
-
|
|
1237
|
-
if (!start || start < 0) start = 0
|
|
1238
|
-
if (!end || end < 0 || end > len) end = len
|
|
1239
|
-
|
|
1240
|
-
let out = ''
|
|
1241
|
-
for (let i = start; i < end; ++i) {
|
|
1242
|
-
out += hexSliceLookupTable[buf[i]]
|
|
1243
|
-
}
|
|
1244
|
-
return out
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
function utf16leSlice (buf, start, end) {
|
|
1248
|
-
const bytes = buf.slice(start, end)
|
|
1249
|
-
let res = ''
|
|
1250
|
-
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
1251
|
-
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1252
|
-
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
|
|
1253
|
-
}
|
|
1254
|
-
return res
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
Buffer.prototype.slice = function slice (start, end) {
|
|
1258
|
-
const len = this.length
|
|
1259
|
-
start = ~~start
|
|
1260
|
-
end = end === undefined ? len : ~~end
|
|
1261
|
-
|
|
1262
|
-
if (start < 0) {
|
|
1263
|
-
start += len
|
|
1264
|
-
if (start < 0) start = 0
|
|
1265
|
-
} else if (start > len) {
|
|
1266
|
-
start = len
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
if (end < 0) {
|
|
1270
|
-
end += len
|
|
1271
|
-
if (end < 0) end = 0
|
|
1272
|
-
} else if (end > len) {
|
|
1273
|
-
end = len
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
if (end < start) end = start
|
|
1277
|
-
|
|
1278
|
-
const newBuf = this.subarray(start, end)
|
|
1279
|
-
// Return an augmented `Uint8Array` instance
|
|
1280
|
-
Object.setPrototypeOf(newBuf, Buffer.prototype)
|
|
1281
|
-
|
|
1282
|
-
return newBuf
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
/*
|
|
1286
|
-
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1287
|
-
*/
|
|
1288
|
-
function checkOffset (offset, ext, length) {
|
|
1289
|
-
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
1290
|
-
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
Buffer.prototype.readUintLE =
|
|
1294
|
-
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
1295
|
-
offset = offset >>> 0
|
|
1296
|
-
byteLength = byteLength >>> 0
|
|
1297
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
|
1298
|
-
|
|
1299
|
-
let val = this[offset]
|
|
1300
|
-
let mul = 1
|
|
1301
|
-
let i = 0
|
|
1302
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
1303
|
-
val += this[offset + i] * mul
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
return val
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
Buffer.prototype.readUintBE =
|
|
1310
|
-
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
1311
|
-
offset = offset >>> 0
|
|
1312
|
-
byteLength = byteLength >>> 0
|
|
1313
|
-
if (!noAssert) {
|
|
1314
|
-
checkOffset(offset, byteLength, this.length)
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
let val = this[offset + --byteLength]
|
|
1318
|
-
let mul = 1
|
|
1319
|
-
while (byteLength > 0 && (mul *= 0x100)) {
|
|
1320
|
-
val += this[offset + --byteLength] * mul
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
return val
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
Buffer.prototype.readUint8 =
|
|
1327
|
-
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
1328
|
-
offset = offset >>> 0
|
|
1329
|
-
if (!noAssert) checkOffset(offset, 1, this.length)
|
|
1330
|
-
return this[offset]
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
Buffer.prototype.readUint16LE =
|
|
1334
|
-
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
1335
|
-
offset = offset >>> 0
|
|
1336
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1337
|
-
return this[offset] | (this[offset + 1] << 8)
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
Buffer.prototype.readUint16BE =
|
|
1341
|
-
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
1342
|
-
offset = offset >>> 0
|
|
1343
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1344
|
-
return (this[offset] << 8) | this[offset + 1]
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
Buffer.prototype.readUint32LE =
|
|
1348
|
-
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
1349
|
-
offset = offset >>> 0
|
|
1350
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1351
|
-
|
|
1352
|
-
return ((this[offset]) |
|
|
1353
|
-
(this[offset + 1] << 8) |
|
|
1354
|
-
(this[offset + 2] << 16)) +
|
|
1355
|
-
(this[offset + 3] * 0x1000000)
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
Buffer.prototype.readUint32BE =
|
|
1359
|
-
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
1360
|
-
offset = offset >>> 0
|
|
1361
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1362
|
-
|
|
1363
|
-
return (this[offset] * 0x1000000) +
|
|
1364
|
-
((this[offset + 1] << 16) |
|
|
1365
|
-
(this[offset + 2] << 8) |
|
|
1366
|
-
this[offset + 3])
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
|
|
1370
|
-
offset = offset >>> 0
|
|
1371
|
-
validateNumber(offset, 'offset')
|
|
1372
|
-
const first = this[offset]
|
|
1373
|
-
const last = this[offset + 7]
|
|
1374
|
-
if (first === undefined || last === undefined) {
|
|
1375
|
-
boundsError(offset, this.length - 8)
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
const lo = first +
|
|
1379
|
-
this[++offset] * 2 ** 8 +
|
|
1380
|
-
this[++offset] * 2 ** 16 +
|
|
1381
|
-
this[++offset] * 2 ** 24
|
|
1382
|
-
|
|
1383
|
-
const hi = this[++offset] +
|
|
1384
|
-
this[++offset] * 2 ** 8 +
|
|
1385
|
-
this[++offset] * 2 ** 16 +
|
|
1386
|
-
last * 2 ** 24
|
|
1387
|
-
|
|
1388
|
-
return BigInt(lo) + (BigInt(hi) << BigInt(32))
|
|
1389
|
-
})
|
|
1390
|
-
|
|
1391
|
-
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
|
|
1392
|
-
offset = offset >>> 0
|
|
1393
|
-
validateNumber(offset, 'offset')
|
|
1394
|
-
const first = this[offset]
|
|
1395
|
-
const last = this[offset + 7]
|
|
1396
|
-
if (first === undefined || last === undefined) {
|
|
1397
|
-
boundsError(offset, this.length - 8)
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
const hi = first * 2 ** 24 +
|
|
1401
|
-
this[++offset] * 2 ** 16 +
|
|
1402
|
-
this[++offset] * 2 ** 8 +
|
|
1403
|
-
this[++offset]
|
|
1404
|
-
|
|
1405
|
-
const lo = this[++offset] * 2 ** 24 +
|
|
1406
|
-
this[++offset] * 2 ** 16 +
|
|
1407
|
-
this[++offset] * 2 ** 8 +
|
|
1408
|
-
last
|
|
1409
|
-
|
|
1410
|
-
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
|
|
1411
|
-
})
|
|
1412
|
-
|
|
1413
|
-
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
1414
|
-
offset = offset >>> 0
|
|
1415
|
-
byteLength = byteLength >>> 0
|
|
1416
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
|
1417
|
-
|
|
1418
|
-
let val = this[offset]
|
|
1419
|
-
let mul = 1
|
|
1420
|
-
let i = 0
|
|
1421
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
1422
|
-
val += this[offset + i] * mul
|
|
1423
|
-
}
|
|
1424
|
-
mul *= 0x80
|
|
1425
|
-
|
|
1426
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
|
1427
|
-
|
|
1428
|
-
return val
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
1432
|
-
offset = offset >>> 0
|
|
1433
|
-
byteLength = byteLength >>> 0
|
|
1434
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
|
1435
|
-
|
|
1436
|
-
let i = byteLength
|
|
1437
|
-
let mul = 1
|
|
1438
|
-
let val = this[offset + --i]
|
|
1439
|
-
while (i > 0 && (mul *= 0x100)) {
|
|
1440
|
-
val += this[offset + --i] * mul
|
|
1441
|
-
}
|
|
1442
|
-
mul *= 0x80
|
|
1443
|
-
|
|
1444
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
|
1445
|
-
|
|
1446
|
-
return val
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
1450
|
-
offset = offset >>> 0
|
|
1451
|
-
if (!noAssert) checkOffset(offset, 1, this.length)
|
|
1452
|
-
if (!(this[offset] & 0x80)) return (this[offset])
|
|
1453
|
-
return ((0xff - this[offset] + 1) * -1)
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
1457
|
-
offset = offset >>> 0
|
|
1458
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1459
|
-
const val = this[offset] | (this[offset + 1] << 8)
|
|
1460
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
1464
|
-
offset = offset >>> 0
|
|
1465
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
|
1466
|
-
const val = this[offset + 1] | (this[offset] << 8)
|
|
1467
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
1471
|
-
offset = offset >>> 0
|
|
1472
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1473
|
-
|
|
1474
|
-
return (this[offset]) |
|
|
1475
|
-
(this[offset + 1] << 8) |
|
|
1476
|
-
(this[offset + 2] << 16) |
|
|
1477
|
-
(this[offset + 3] << 24)
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
1481
|
-
offset = offset >>> 0
|
|
1482
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1483
|
-
|
|
1484
|
-
return (this[offset] << 24) |
|
|
1485
|
-
(this[offset + 1] << 16) |
|
|
1486
|
-
(this[offset + 2] << 8) |
|
|
1487
|
-
(this[offset + 3])
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
|
|
1491
|
-
offset = offset >>> 0
|
|
1492
|
-
validateNumber(offset, 'offset')
|
|
1493
|
-
const first = this[offset]
|
|
1494
|
-
const last = this[offset + 7]
|
|
1495
|
-
if (first === undefined || last === undefined) {
|
|
1496
|
-
boundsError(offset, this.length - 8)
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
const val = this[offset + 4] +
|
|
1500
|
-
this[offset + 5] * 2 ** 8 +
|
|
1501
|
-
this[offset + 6] * 2 ** 16 +
|
|
1502
|
-
(last << 24) // Overflow
|
|
1503
|
-
|
|
1504
|
-
return (BigInt(val) << BigInt(32)) +
|
|
1505
|
-
BigInt(first +
|
|
1506
|
-
this[++offset] * 2 ** 8 +
|
|
1507
|
-
this[++offset] * 2 ** 16 +
|
|
1508
|
-
this[++offset] * 2 ** 24)
|
|
1509
|
-
})
|
|
1510
|
-
|
|
1511
|
-
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
|
|
1512
|
-
offset = offset >>> 0
|
|
1513
|
-
validateNumber(offset, 'offset')
|
|
1514
|
-
const first = this[offset]
|
|
1515
|
-
const last = this[offset + 7]
|
|
1516
|
-
if (first === undefined || last === undefined) {
|
|
1517
|
-
boundsError(offset, this.length - 8)
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
const val = (first << 24) + // Overflow
|
|
1521
|
-
this[++offset] * 2 ** 16 +
|
|
1522
|
-
this[++offset] * 2 ** 8 +
|
|
1523
|
-
this[++offset]
|
|
1524
|
-
|
|
1525
|
-
return (BigInt(val) << BigInt(32)) +
|
|
1526
|
-
BigInt(this[++offset] * 2 ** 24 +
|
|
1527
|
-
this[++offset] * 2 ** 16 +
|
|
1528
|
-
this[++offset] * 2 ** 8 +
|
|
1529
|
-
last)
|
|
1530
|
-
})
|
|
1531
|
-
|
|
1532
|
-
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
1533
|
-
offset = offset >>> 0
|
|
1534
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1535
|
-
return ieee754.read(this, offset, true, 23, 4)
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
1539
|
-
offset = offset >>> 0
|
|
1540
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
|
1541
|
-
return ieee754.read(this, offset, false, 23, 4)
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
1545
|
-
offset = offset >>> 0
|
|
1546
|
-
if (!noAssert) checkOffset(offset, 8, this.length)
|
|
1547
|
-
return ieee754.read(this, offset, true, 52, 8)
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
1551
|
-
offset = offset >>> 0
|
|
1552
|
-
if (!noAssert) checkOffset(offset, 8, this.length)
|
|
1553
|
-
return ieee754.read(this, offset, false, 52, 8)
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
function checkInt (buf, value, offset, ext, max, min) {
|
|
1557
|
-
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
1558
|
-
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
1559
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
Buffer.prototype.writeUintLE =
|
|
1563
|
-
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
1564
|
-
value = +value
|
|
1565
|
-
offset = offset >>> 0
|
|
1566
|
-
byteLength = byteLength >>> 0
|
|
1567
|
-
if (!noAssert) {
|
|
1568
|
-
const maxBytes = Math.pow(2, 8 * byteLength) - 1
|
|
1569
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
let mul = 1
|
|
1573
|
-
let i = 0
|
|
1574
|
-
this[offset] = value & 0xFF
|
|
1575
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
1576
|
-
this[offset + i] = (value / mul) & 0xFF
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
return offset + byteLength
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
Buffer.prototype.writeUintBE =
|
|
1583
|
-
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
1584
|
-
value = +value
|
|
1585
|
-
offset = offset >>> 0
|
|
1586
|
-
byteLength = byteLength >>> 0
|
|
1587
|
-
if (!noAssert) {
|
|
1588
|
-
const maxBytes = Math.pow(2, 8 * byteLength) - 1
|
|
1589
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
let i = byteLength - 1
|
|
1593
|
-
let mul = 1
|
|
1594
|
-
this[offset + i] = value & 0xFF
|
|
1595
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
1596
|
-
this[offset + i] = (value / mul) & 0xFF
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
return offset + byteLength
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
Buffer.prototype.writeUint8 =
|
|
1603
|
-
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
1604
|
-
value = +value
|
|
1605
|
-
offset = offset >>> 0
|
|
1606
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
|
1607
|
-
this[offset] = (value & 0xff)
|
|
1608
|
-
return offset + 1
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
Buffer.prototype.writeUint16LE =
|
|
1612
|
-
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
1613
|
-
value = +value
|
|
1614
|
-
offset = offset >>> 0
|
|
1615
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
|
1616
|
-
this[offset] = (value & 0xff)
|
|
1617
|
-
this[offset + 1] = (value >>> 8)
|
|
1618
|
-
return offset + 2
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
Buffer.prototype.writeUint16BE =
|
|
1622
|
-
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
1623
|
-
value = +value
|
|
1624
|
-
offset = offset >>> 0
|
|
1625
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
|
1626
|
-
this[offset] = (value >>> 8)
|
|
1627
|
-
this[offset + 1] = (value & 0xff)
|
|
1628
|
-
return offset + 2
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
Buffer.prototype.writeUint32LE =
|
|
1632
|
-
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
1633
|
-
value = +value
|
|
1634
|
-
offset = offset >>> 0
|
|
1635
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
|
1636
|
-
this[offset + 3] = (value >>> 24)
|
|
1637
|
-
this[offset + 2] = (value >>> 16)
|
|
1638
|
-
this[offset + 1] = (value >>> 8)
|
|
1639
|
-
this[offset] = (value & 0xff)
|
|
1640
|
-
return offset + 4
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
Buffer.prototype.writeUint32BE =
|
|
1644
|
-
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
1645
|
-
value = +value
|
|
1646
|
-
offset = offset >>> 0
|
|
1647
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
|
1648
|
-
this[offset] = (value >>> 24)
|
|
1649
|
-
this[offset + 1] = (value >>> 16)
|
|
1650
|
-
this[offset + 2] = (value >>> 8)
|
|
1651
|
-
this[offset + 3] = (value & 0xff)
|
|
1652
|
-
return offset + 4
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
function wrtBigUInt64LE (buf, value, offset, min, max) {
|
|
1656
|
-
checkIntBI(value, min, max, buf, offset, 7)
|
|
1657
|
-
|
|
1658
|
-
let lo = Number(value & BigInt(0xffffffff))
|
|
1659
|
-
buf[offset++] = lo
|
|
1660
|
-
lo = lo >> 8
|
|
1661
|
-
buf[offset++] = lo
|
|
1662
|
-
lo = lo >> 8
|
|
1663
|
-
buf[offset++] = lo
|
|
1664
|
-
lo = lo >> 8
|
|
1665
|
-
buf[offset++] = lo
|
|
1666
|
-
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
|
|
1667
|
-
buf[offset++] = hi
|
|
1668
|
-
hi = hi >> 8
|
|
1669
|
-
buf[offset++] = hi
|
|
1670
|
-
hi = hi >> 8
|
|
1671
|
-
buf[offset++] = hi
|
|
1672
|
-
hi = hi >> 8
|
|
1673
|
-
buf[offset++] = hi
|
|
1674
|
-
return offset
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
function wrtBigUInt64BE (buf, value, offset, min, max) {
|
|
1678
|
-
checkIntBI(value, min, max, buf, offset, 7)
|
|
1679
|
-
|
|
1680
|
-
let lo = Number(value & BigInt(0xffffffff))
|
|
1681
|
-
buf[offset + 7] = lo
|
|
1682
|
-
lo = lo >> 8
|
|
1683
|
-
buf[offset + 6] = lo
|
|
1684
|
-
lo = lo >> 8
|
|
1685
|
-
buf[offset + 5] = lo
|
|
1686
|
-
lo = lo >> 8
|
|
1687
|
-
buf[offset + 4] = lo
|
|
1688
|
-
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
|
|
1689
|
-
buf[offset + 3] = hi
|
|
1690
|
-
hi = hi >> 8
|
|
1691
|
-
buf[offset + 2] = hi
|
|
1692
|
-
hi = hi >> 8
|
|
1693
|
-
buf[offset + 1] = hi
|
|
1694
|
-
hi = hi >> 8
|
|
1695
|
-
buf[offset] = hi
|
|
1696
|
-
return offset + 8
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
1700
|
-
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
1701
|
-
})
|
|
1702
|
-
|
|
1703
|
-
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
1704
|
-
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
1705
|
-
})
|
|
1706
|
-
|
|
1707
|
-
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
1708
|
-
value = +value
|
|
1709
|
-
offset = offset >>> 0
|
|
1710
|
-
if (!noAssert) {
|
|
1711
|
-
const limit = Math.pow(2, (8 * byteLength) - 1)
|
|
1712
|
-
|
|
1713
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
let i = 0
|
|
1717
|
-
let mul = 1
|
|
1718
|
-
let sub = 0
|
|
1719
|
-
this[offset] = value & 0xFF
|
|
1720
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
1721
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
1722
|
-
sub = 1
|
|
1723
|
-
}
|
|
1724
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
return offset + byteLength
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
1731
|
-
value = +value
|
|
1732
|
-
offset = offset >>> 0
|
|
1733
|
-
if (!noAssert) {
|
|
1734
|
-
const limit = Math.pow(2, (8 * byteLength) - 1)
|
|
1735
|
-
|
|
1736
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
let i = byteLength - 1
|
|
1740
|
-
let mul = 1
|
|
1741
|
-
let sub = 0
|
|
1742
|
-
this[offset + i] = value & 0xFF
|
|
1743
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
1744
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
1745
|
-
sub = 1
|
|
1746
|
-
}
|
|
1747
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
return offset + byteLength
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
1754
|
-
value = +value
|
|
1755
|
-
offset = offset >>> 0
|
|
1756
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
|
1757
|
-
if (value < 0) value = 0xff + value + 1
|
|
1758
|
-
this[offset] = (value & 0xff)
|
|
1759
|
-
return offset + 1
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
1763
|
-
value = +value
|
|
1764
|
-
offset = offset >>> 0
|
|
1765
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
|
1766
|
-
this[offset] = (value & 0xff)
|
|
1767
|
-
this[offset + 1] = (value >>> 8)
|
|
1768
|
-
return offset + 2
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
1772
|
-
value = +value
|
|
1773
|
-
offset = offset >>> 0
|
|
1774
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
|
1775
|
-
this[offset] = (value >>> 8)
|
|
1776
|
-
this[offset + 1] = (value & 0xff)
|
|
1777
|
-
return offset + 2
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
1781
|
-
value = +value
|
|
1782
|
-
offset = offset >>> 0
|
|
1783
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
|
1784
|
-
this[offset] = (value & 0xff)
|
|
1785
|
-
this[offset + 1] = (value >>> 8)
|
|
1786
|
-
this[offset + 2] = (value >>> 16)
|
|
1787
|
-
this[offset + 3] = (value >>> 24)
|
|
1788
|
-
return offset + 4
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
1792
|
-
value = +value
|
|
1793
|
-
offset = offset >>> 0
|
|
1794
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
|
1795
|
-
if (value < 0) value = 0xffffffff + value + 1
|
|
1796
|
-
this[offset] = (value >>> 24)
|
|
1797
|
-
this[offset + 1] = (value >>> 16)
|
|
1798
|
-
this[offset + 2] = (value >>> 8)
|
|
1799
|
-
this[offset + 3] = (value & 0xff)
|
|
1800
|
-
return offset + 4
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
1804
|
-
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
1805
|
-
})
|
|
1806
|
-
|
|
1807
|
-
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
1808
|
-
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
1809
|
-
})
|
|
1810
|
-
|
|
1811
|
-
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
1812
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
1813
|
-
if (offset < 0) throw new RangeError('Index out of range')
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
1817
|
-
value = +value
|
|
1818
|
-
offset = offset >>> 0
|
|
1819
|
-
if (!noAssert) {
|
|
1820
|
-
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
|
1821
|
-
}
|
|
1822
|
-
ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
|
1823
|
-
return offset + 4
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
1827
|
-
return writeFloat(this, value, offset, true, noAssert)
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
|
-
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
1831
|
-
return writeFloat(this, value, offset, false, noAssert)
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
1835
|
-
value = +value
|
|
1836
|
-
offset = offset >>> 0
|
|
1837
|
-
if (!noAssert) {
|
|
1838
|
-
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
|
1839
|
-
}
|
|
1840
|
-
ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
|
1841
|
-
return offset + 8
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
1845
|
-
return writeDouble(this, value, offset, true, noAssert)
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
1849
|
-
return writeDouble(this, value, offset, false, noAssert)
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
1853
|
-
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
1854
|
-
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
1855
|
-
if (!start) start = 0
|
|
1856
|
-
if (!end && end !== 0) end = this.length
|
|
1857
|
-
if (targetStart >= target.length) targetStart = target.length
|
|
1858
|
-
if (!targetStart) targetStart = 0
|
|
1859
|
-
if (end > 0 && end < start) end = start
|
|
1860
|
-
|
|
1861
|
-
// Copy 0 bytes; we're done
|
|
1862
|
-
if (end === start) return 0
|
|
1863
|
-
if (target.length === 0 || this.length === 0) return 0
|
|
1864
|
-
|
|
1865
|
-
// Fatal error conditions
|
|
1866
|
-
if (targetStart < 0) {
|
|
1867
|
-
throw new RangeError('targetStart out of bounds')
|
|
1868
|
-
}
|
|
1869
|
-
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
1870
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
1871
|
-
|
|
1872
|
-
// Are we oob?
|
|
1873
|
-
if (end > this.length) end = this.length
|
|
1874
|
-
if (target.length - targetStart < end - start) {
|
|
1875
|
-
end = target.length - targetStart + start
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
const len = end - start
|
|
1879
|
-
|
|
1880
|
-
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
1881
|
-
// Use built-in when available, missing from IE11
|
|
1882
|
-
this.copyWithin(targetStart, start, end)
|
|
1883
|
-
} else {
|
|
1884
|
-
Uint8Array.prototype.set.call(
|
|
1885
|
-
target,
|
|
1886
|
-
this.subarray(start, end),
|
|
1887
|
-
targetStart
|
|
1888
|
-
)
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
return len
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
// Usage:
|
|
1895
|
-
// buffer.fill(number[, offset[, end]])
|
|
1896
|
-
// buffer.fill(buffer[, offset[, end]])
|
|
1897
|
-
// buffer.fill(string[, offset[, end]][, encoding])
|
|
1898
|
-
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
1899
|
-
// Handle string cases:
|
|
1900
|
-
if (typeof val === 'string') {
|
|
1901
|
-
if (typeof start === 'string') {
|
|
1902
|
-
encoding = start
|
|
1903
|
-
start = 0
|
|
1904
|
-
end = this.length
|
|
1905
|
-
} else if (typeof end === 'string') {
|
|
1906
|
-
encoding = end
|
|
1907
|
-
end = this.length
|
|
1908
|
-
}
|
|
1909
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
1910
|
-
throw new TypeError('encoding must be a string')
|
|
1911
|
-
}
|
|
1912
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
1913
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
|
1914
|
-
}
|
|
1915
|
-
if (val.length === 1) {
|
|
1916
|
-
const code = val.charCodeAt(0)
|
|
1917
|
-
if ((encoding === 'utf8' && code < 128) ||
|
|
1918
|
-
encoding === 'latin1') {
|
|
1919
|
-
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
1920
|
-
val = code
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
} else if (typeof val === 'number') {
|
|
1924
|
-
val = val & 255
|
|
1925
|
-
} else if (typeof val === 'boolean') {
|
|
1926
|
-
val = Number(val)
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
// Invalid ranges are not set to a default, so can range check early.
|
|
1930
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
1931
|
-
throw new RangeError('Out of range index')
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
if (end <= start) {
|
|
1935
|
-
return this
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
|
-
start = start >>> 0
|
|
1939
|
-
end = end === undefined ? this.length : end >>> 0
|
|
1940
|
-
|
|
1941
|
-
if (!val) val = 0
|
|
1942
|
-
|
|
1943
|
-
let i
|
|
1944
|
-
if (typeof val === 'number') {
|
|
1945
|
-
for (i = start; i < end; ++i) {
|
|
1946
|
-
this[i] = val
|
|
1947
|
-
}
|
|
1948
|
-
} else {
|
|
1949
|
-
const bytes = Buffer.isBuffer(val)
|
|
1950
|
-
? val
|
|
1951
|
-
: Buffer.from(val, encoding)
|
|
1952
|
-
const len = bytes.length
|
|
1953
|
-
if (len === 0) {
|
|
1954
|
-
throw new TypeError('The value "' + val +
|
|
1955
|
-
'" is invalid for argument "value"')
|
|
1956
|
-
}
|
|
1957
|
-
for (i = 0; i < end - start; ++i) {
|
|
1958
|
-
this[i + start] = bytes[i % len]
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
return this
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
// CUSTOM ERRORS
|
|
1966
|
-
// =============
|
|
1967
|
-
|
|
1968
|
-
// Simplified versions from Node, changed for Buffer-only usage
|
|
1969
|
-
const errors = {}
|
|
1970
|
-
function E (sym, getMessage, Base) {
|
|
1971
|
-
errors[sym] = class NodeError extends Base {
|
|
1972
|
-
constructor () {
|
|
1973
|
-
super()
|
|
1974
|
-
|
|
1975
|
-
Object.defineProperty(this, 'message', {
|
|
1976
|
-
value: getMessage.apply(this, arguments),
|
|
1977
|
-
writable: true,
|
|
1978
|
-
configurable: true
|
|
1979
|
-
})
|
|
1980
|
-
|
|
1981
|
-
// Add the error code to the name to include it in the stack trace.
|
|
1982
|
-
this.name = `${this.name} [${sym}]`
|
|
1983
|
-
// Access the stack to generate the error message including the error code
|
|
1984
|
-
// from the name.
|
|
1985
|
-
this.stack // eslint-disable-line no-unused-expressions
|
|
1986
|
-
// Reset the name to the actual name.
|
|
1987
|
-
delete this.name
|
|
1988
|
-
}
|
|
1989
|
-
|
|
1990
|
-
get code () {
|
|
1991
|
-
return sym
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
set code (value) {
|
|
1995
|
-
Object.defineProperty(this, 'code', {
|
|
1996
|
-
configurable: true,
|
|
1997
|
-
enumerable: true,
|
|
1998
|
-
value,
|
|
1999
|
-
writable: true
|
|
2000
|
-
})
|
|
2001
|
-
}
|
|
2002
|
-
|
|
2003
|
-
toString () {
|
|
2004
|
-
return `${this.name} [${sym}]: ${this.message}`
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
2010
|
-
function (name) {
|
|
2011
|
-
if (name) {
|
|
2012
|
-
return `${name} is outside of buffer bounds`
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
return 'Attempt to access memory outside buffer bounds'
|
|
2016
|
-
}, RangeError)
|
|
2017
|
-
E('ERR_INVALID_ARG_TYPE',
|
|
2018
|
-
function (name, actual) {
|
|
2019
|
-
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
2020
|
-
}, TypeError)
|
|
2021
|
-
E('ERR_OUT_OF_RANGE',
|
|
2022
|
-
function (str, range, input) {
|
|
2023
|
-
let msg = `The value of "${str}" is out of range.`
|
|
2024
|
-
let received = input
|
|
2025
|
-
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
2026
|
-
received = addNumericalSeparator(String(input))
|
|
2027
|
-
} else if (typeof input === 'bigint') {
|
|
2028
|
-
received = String(input)
|
|
2029
|
-
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
2030
|
-
received = addNumericalSeparator(received)
|
|
2031
|
-
}
|
|
2032
|
-
received += 'n'
|
|
2033
|
-
}
|
|
2034
|
-
msg += ` It must be ${range}. Received ${received}`
|
|
2035
|
-
return msg
|
|
2036
|
-
}, RangeError)
|
|
2037
|
-
|
|
2038
|
-
function addNumericalSeparator (val) {
|
|
2039
|
-
let res = ''
|
|
2040
|
-
let i = val.length
|
|
2041
|
-
const start = val[0] === '-' ? 1 : 0
|
|
2042
|
-
for (; i >= start + 4; i -= 3) {
|
|
2043
|
-
res = `_${val.slice(i - 3, i)}${res}`
|
|
2044
|
-
}
|
|
2045
|
-
return `${val.slice(0, i)}${res}`
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
// CHECK FUNCTIONS
|
|
2049
|
-
// ===============
|
|
2050
|
-
|
|
2051
|
-
function checkBounds (buf, offset, byteLength) {
|
|
2052
|
-
validateNumber(offset, 'offset')
|
|
2053
|
-
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
2054
|
-
boundsError(offset, buf.length - (byteLength + 1))
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
2059
|
-
if (value > max || value < min) {
|
|
2060
|
-
const n = typeof min === 'bigint' ? 'n' : ''
|
|
2061
|
-
let range
|
|
2062
|
-
if (byteLength > 3) {
|
|
2063
|
-
if (min === 0 || min === BigInt(0)) {
|
|
2064
|
-
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`
|
|
2065
|
-
} else {
|
|
2066
|
-
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
2067
|
-
`${(byteLength + 1) * 8 - 1}${n}`
|
|
2068
|
-
}
|
|
2069
|
-
} else {
|
|
2070
|
-
range = `>= ${min}${n} and <= ${max}${n}`
|
|
2071
|
-
}
|
|
2072
|
-
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
2073
|
-
}
|
|
2074
|
-
checkBounds(buf, offset, byteLength)
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
function validateNumber (value, name) {
|
|
2078
|
-
if (typeof value !== 'number') {
|
|
2079
|
-
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
function boundsError (value, length, type) {
|
|
2084
|
-
if (Math.floor(value) !== value) {
|
|
2085
|
-
validateNumber(value, type)
|
|
2086
|
-
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
if (length < 0) {
|
|
2090
|
-
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
|
-
throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
|
|
2094
|
-
`>= ${type ? 1 : 0} and <= ${length}`,
|
|
2095
|
-
value)
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
// HELPER FUNCTIONS
|
|
2099
|
-
// ================
|
|
2100
|
-
|
|
2101
|
-
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
|
|
2102
|
-
|
|
2103
|
-
function base64clean (str) {
|
|
2104
|
-
// Node takes equal signs as end of the Base64 encoding
|
|
2105
|
-
str = str.split('=')[0]
|
|
2106
|
-
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
2107
|
-
str = str.trim().replace(INVALID_BASE64_RE, '')
|
|
2108
|
-
// Node converts strings with length < 2 to ''
|
|
2109
|
-
if (str.length < 2) return ''
|
|
2110
|
-
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
2111
|
-
while (str.length % 4 !== 0) {
|
|
2112
|
-
str = str + '='
|
|
2113
|
-
}
|
|
2114
|
-
return str
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
function utf8ToBytes (string, units) {
|
|
2118
|
-
units = units || Infinity
|
|
2119
|
-
let codePoint
|
|
2120
|
-
const length = string.length
|
|
2121
|
-
let leadSurrogate = null
|
|
2122
|
-
const bytes = []
|
|
2123
|
-
|
|
2124
|
-
for (let i = 0; i < length; ++i) {
|
|
2125
|
-
codePoint = string.charCodeAt(i)
|
|
2126
|
-
|
|
2127
|
-
// is surrogate component
|
|
2128
|
-
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
2129
|
-
// last char was a lead
|
|
2130
|
-
if (!leadSurrogate) {
|
|
2131
|
-
// no lead yet
|
|
2132
|
-
if (codePoint > 0xDBFF) {
|
|
2133
|
-
// unexpected trail
|
|
2134
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
2135
|
-
continue
|
|
2136
|
-
} else if (i + 1 === length) {
|
|
2137
|
-
// unpaired lead
|
|
2138
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
2139
|
-
continue
|
|
2140
|
-
}
|
|
2141
|
-
|
|
2142
|
-
// valid lead
|
|
2143
|
-
leadSurrogate = codePoint
|
|
2144
|
-
|
|
2145
|
-
continue
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
// 2 leads in a row
|
|
2149
|
-
if (codePoint < 0xDC00) {
|
|
2150
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
2151
|
-
leadSurrogate = codePoint
|
|
2152
|
-
continue
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
// valid surrogate pair
|
|
2156
|
-
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
|
2157
|
-
} else if (leadSurrogate) {
|
|
2158
|
-
// valid bmp char, but last char was a lead
|
|
2159
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
|
-
leadSurrogate = null
|
|
2163
|
-
|
|
2164
|
-
// encode utf8
|
|
2165
|
-
if (codePoint < 0x80) {
|
|
2166
|
-
if ((units -= 1) < 0) break
|
|
2167
|
-
bytes.push(codePoint)
|
|
2168
|
-
} else if (codePoint < 0x800) {
|
|
2169
|
-
if ((units -= 2) < 0) break
|
|
2170
|
-
bytes.push(
|
|
2171
|
-
codePoint >> 0x6 | 0xC0,
|
|
2172
|
-
codePoint & 0x3F | 0x80
|
|
2173
|
-
)
|
|
2174
|
-
} else if (codePoint < 0x10000) {
|
|
2175
|
-
if ((units -= 3) < 0) break
|
|
2176
|
-
bytes.push(
|
|
2177
|
-
codePoint >> 0xC | 0xE0,
|
|
2178
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
2179
|
-
codePoint & 0x3F | 0x80
|
|
2180
|
-
)
|
|
2181
|
-
} else if (codePoint < 0x110000) {
|
|
2182
|
-
if ((units -= 4) < 0) break
|
|
2183
|
-
bytes.push(
|
|
2184
|
-
codePoint >> 0x12 | 0xF0,
|
|
2185
|
-
codePoint >> 0xC & 0x3F | 0x80,
|
|
2186
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
|
2187
|
-
codePoint & 0x3F | 0x80
|
|
2188
|
-
)
|
|
2189
|
-
} else {
|
|
2190
|
-
throw new Error('Invalid code point')
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
return bytes
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
|
-
function asciiToBytes (str) {
|
|
2198
|
-
const byteArray = []
|
|
2199
|
-
for (let i = 0; i < str.length; ++i) {
|
|
2200
|
-
// Node's code seems to be doing this and not & 0x7F..
|
|
2201
|
-
byteArray.push(str.charCodeAt(i) & 0xFF)
|
|
2202
|
-
}
|
|
2203
|
-
return byteArray
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
|
-
function utf16leToBytes (str, units) {
|
|
2207
|
-
let c, hi, lo
|
|
2208
|
-
const byteArray = []
|
|
2209
|
-
for (let i = 0; i < str.length; ++i) {
|
|
2210
|
-
if ((units -= 2) < 0) break
|
|
2211
|
-
|
|
2212
|
-
c = str.charCodeAt(i)
|
|
2213
|
-
hi = c >> 8
|
|
2214
|
-
lo = c % 256
|
|
2215
|
-
byteArray.push(lo)
|
|
2216
|
-
byteArray.push(hi)
|
|
2217
|
-
}
|
|
2218
|
-
|
|
2219
|
-
return byteArray
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
function base64ToBytes (str) {
|
|
2223
|
-
return base64.toByteArray(base64clean(str))
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
function blitBuffer (src, dst, offset, length) {
|
|
2227
|
-
let i
|
|
2228
|
-
for (i = 0; i < length; ++i) {
|
|
2229
|
-
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
2230
|
-
dst[i + offset] = src[i]
|
|
2231
|
-
}
|
|
2232
|
-
return i
|
|
2233
|
-
}
|
|
2234
|
-
|
|
2235
|
-
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
2236
|
-
// the `instanceof` check but they should be treated as of that type.
|
|
2237
|
-
// See: https://github.com/feross/buffer/issues/166
|
|
2238
|
-
function isInstance (obj, type) {
|
|
2239
|
-
return obj instanceof type ||
|
|
2240
|
-
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
2241
|
-
obj.constructor.name === type.name)
|
|
2242
|
-
}
|
|
2243
|
-
function numberIsNaN (obj) {
|
|
2244
|
-
// For IE11 support
|
|
2245
|
-
return obj !== obj // eslint-disable-line no-self-compare
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2248
|
-
// Create lookup table for `toString('hex')`
|
|
2249
|
-
// See: https://github.com/feross/buffer/issues/219
|
|
2250
|
-
const hexSliceLookupTable = (function () {
|
|
2251
|
-
const alphabet = '0123456789abcdef'
|
|
2252
|
-
const table = new Array(256)
|
|
2253
|
-
for (let i = 0; i < 16; ++i) {
|
|
2254
|
-
const i16 = i * 16
|
|
2255
|
-
for (let j = 0; j < 16; ++j) {
|
|
2256
|
-
table[i16 + j] = alphabet[i] + alphabet[j]
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
return table
|
|
2260
|
-
})()
|
|
2261
|
-
|
|
2262
|
-
// Return not function with Error if BigInt not supported
|
|
2263
|
-
function defineBigIntMethod (fn) {
|
|
2264
|
-
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
function BufferBigIntNotDefined () {
|
|
2268
|
-
throw new Error('BigInt not supported')
|
|
2269
|
-
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
/***/ }),
|
|
2273
|
-
|
|
2274
|
-
/***/ 645:
|
|
2275
|
-
/***/ (function(__unused_webpack_module, exports) {
|
|
2276
|
-
|
|
2277
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
2278
|
-
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
2279
|
-
var e, m
|
|
2280
|
-
var eLen = (nBytes * 8) - mLen - 1
|
|
2281
|
-
var eMax = (1 << eLen) - 1
|
|
2282
|
-
var eBias = eMax >> 1
|
|
2283
|
-
var nBits = -7
|
|
2284
|
-
var i = isLE ? (nBytes - 1) : 0
|
|
2285
|
-
var d = isLE ? -1 : 1
|
|
2286
|
-
var s = buffer[offset + i]
|
|
2287
|
-
|
|
2288
|
-
i += d
|
|
2289
|
-
|
|
2290
|
-
e = s & ((1 << (-nBits)) - 1)
|
|
2291
|
-
s >>= (-nBits)
|
|
2292
|
-
nBits += eLen
|
|
2293
|
-
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
2294
|
-
|
|
2295
|
-
m = e & ((1 << (-nBits)) - 1)
|
|
2296
|
-
e >>= (-nBits)
|
|
2297
|
-
nBits += mLen
|
|
2298
|
-
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
2299
|
-
|
|
2300
|
-
if (e === 0) {
|
|
2301
|
-
e = 1 - eBias
|
|
2302
|
-
} else if (e === eMax) {
|
|
2303
|
-
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
2304
|
-
} else {
|
|
2305
|
-
m = m + Math.pow(2, mLen)
|
|
2306
|
-
e = e - eBias
|
|
2307
|
-
}
|
|
2308
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
2312
|
-
var e, m, c
|
|
2313
|
-
var eLen = (nBytes * 8) - mLen - 1
|
|
2314
|
-
var eMax = (1 << eLen) - 1
|
|
2315
|
-
var eBias = eMax >> 1
|
|
2316
|
-
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
|
2317
|
-
var i = isLE ? 0 : (nBytes - 1)
|
|
2318
|
-
var d = isLE ? 1 : -1
|
|
2319
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
|
2320
|
-
|
|
2321
|
-
value = Math.abs(value)
|
|
2322
|
-
|
|
2323
|
-
if (isNaN(value) || value === Infinity) {
|
|
2324
|
-
m = isNaN(value) ? 1 : 0
|
|
2325
|
-
e = eMax
|
|
2326
|
-
} else {
|
|
2327
|
-
e = Math.floor(Math.log(value) / Math.LN2)
|
|
2328
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
2329
|
-
e--
|
|
2330
|
-
c *= 2
|
|
2331
|
-
}
|
|
2332
|
-
if (e + eBias >= 1) {
|
|
2333
|
-
value += rt / c
|
|
2334
|
-
} else {
|
|
2335
|
-
value += rt * Math.pow(2, 1 - eBias)
|
|
2336
|
-
}
|
|
2337
|
-
if (value * c >= 2) {
|
|
2338
|
-
e++
|
|
2339
|
-
c /= 2
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
|
-
if (e + eBias >= eMax) {
|
|
2343
|
-
m = 0
|
|
2344
|
-
e = eMax
|
|
2345
|
-
} else if (e + eBias >= 1) {
|
|
2346
|
-
m = ((value * c) - 1) * Math.pow(2, mLen)
|
|
2347
|
-
e = e + eBias
|
|
2348
|
-
} else {
|
|
2349
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
|
2350
|
-
e = 0
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
|
|
2354
|
-
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
2355
|
-
|
|
2356
|
-
e = (e << mLen) | m
|
|
2357
|
-
eLen += mLen
|
|
2358
|
-
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
2359
|
-
|
|
2360
|
-
buffer[offset + i - d] |= s * 128
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
/***/ }),
|
|
2365
|
-
|
|
2366
|
-
/***/ 155:
|
|
2367
|
-
/***/ (function(module) {
|
|
2368
|
-
|
|
2369
|
-
// shim for using process in browser
|
|
2370
|
-
var process = module.exports = {};
|
|
2371
|
-
|
|
2372
|
-
// cached from whatever global is present so that test runners that stub it
|
|
2373
|
-
// don't break things. But we need to wrap it in a try catch in case it is
|
|
2374
|
-
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
|
2375
|
-
// function because try/catches deoptimize in certain engines.
|
|
2376
|
-
|
|
2377
|
-
var cachedSetTimeout;
|
|
2378
|
-
var cachedClearTimeout;
|
|
2379
|
-
|
|
2380
|
-
function defaultSetTimout() {
|
|
2381
|
-
throw new Error('setTimeout has not been defined');
|
|
2382
|
-
}
|
|
2383
|
-
function defaultClearTimeout () {
|
|
2384
|
-
throw new Error('clearTimeout has not been defined');
|
|
2385
|
-
}
|
|
2386
|
-
(function () {
|
|
2387
|
-
try {
|
|
2388
|
-
if (typeof setTimeout === 'function') {
|
|
2389
|
-
cachedSetTimeout = setTimeout;
|
|
2390
|
-
} else {
|
|
2391
|
-
cachedSetTimeout = defaultSetTimout;
|
|
2392
|
-
}
|
|
2393
|
-
} catch (e) {
|
|
2394
|
-
cachedSetTimeout = defaultSetTimout;
|
|
2395
|
-
}
|
|
2396
|
-
try {
|
|
2397
|
-
if (typeof clearTimeout === 'function') {
|
|
2398
|
-
cachedClearTimeout = clearTimeout;
|
|
2399
|
-
} else {
|
|
2400
|
-
cachedClearTimeout = defaultClearTimeout;
|
|
2401
|
-
}
|
|
2402
|
-
} catch (e) {
|
|
2403
|
-
cachedClearTimeout = defaultClearTimeout;
|
|
2404
|
-
}
|
|
2405
|
-
} ())
|
|
2406
|
-
function runTimeout(fun) {
|
|
2407
|
-
if (cachedSetTimeout === setTimeout) {
|
|
2408
|
-
//normal enviroments in sane situations
|
|
2409
|
-
return setTimeout(fun, 0);
|
|
2410
|
-
}
|
|
2411
|
-
// if setTimeout wasn't available but was latter defined
|
|
2412
|
-
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
2413
|
-
cachedSetTimeout = setTimeout;
|
|
2414
|
-
return setTimeout(fun, 0);
|
|
2415
|
-
}
|
|
2416
|
-
try {
|
|
2417
|
-
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
2418
|
-
return cachedSetTimeout(fun, 0);
|
|
2419
|
-
} catch(e){
|
|
2420
|
-
try {
|
|
2421
|
-
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
2422
|
-
return cachedSetTimeout.call(null, fun, 0);
|
|
2423
|
-
} catch(e){
|
|
2424
|
-
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
|
2425
|
-
return cachedSetTimeout.call(this, fun, 0);
|
|
2426
|
-
}
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
}
|
|
2431
|
-
function runClearTimeout(marker) {
|
|
2432
|
-
if (cachedClearTimeout === clearTimeout) {
|
|
2433
|
-
//normal enviroments in sane situations
|
|
2434
|
-
return clearTimeout(marker);
|
|
2435
|
-
}
|
|
2436
|
-
// if clearTimeout wasn't available but was latter defined
|
|
2437
|
-
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
2438
|
-
cachedClearTimeout = clearTimeout;
|
|
2439
|
-
return clearTimeout(marker);
|
|
2440
|
-
}
|
|
2441
|
-
try {
|
|
2442
|
-
// when when somebody has screwed with setTimeout but no I.E. maddness
|
|
2443
|
-
return cachedClearTimeout(marker);
|
|
2444
|
-
} catch (e){
|
|
2445
|
-
try {
|
|
2446
|
-
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
|
2447
|
-
return cachedClearTimeout.call(null, marker);
|
|
2448
|
-
} catch (e){
|
|
2449
|
-
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
|
2450
|
-
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
|
2451
|
-
return cachedClearTimeout.call(this, marker);
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
}
|
|
2458
|
-
var queue = [];
|
|
2459
|
-
var draining = false;
|
|
2460
|
-
var currentQueue;
|
|
2461
|
-
var queueIndex = -1;
|
|
2462
|
-
|
|
2463
|
-
function cleanUpNextTick() {
|
|
2464
|
-
if (!draining || !currentQueue) {
|
|
2465
|
-
return;
|
|
2466
|
-
}
|
|
2467
|
-
draining = false;
|
|
2468
|
-
if (currentQueue.length) {
|
|
2469
|
-
queue = currentQueue.concat(queue);
|
|
2470
|
-
} else {
|
|
2471
|
-
queueIndex = -1;
|
|
2472
|
-
}
|
|
2473
|
-
if (queue.length) {
|
|
2474
|
-
drainQueue();
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
function drainQueue() {
|
|
2479
|
-
if (draining) {
|
|
2480
|
-
return;
|
|
2481
|
-
}
|
|
2482
|
-
var timeout = runTimeout(cleanUpNextTick);
|
|
2483
|
-
draining = true;
|
|
2484
|
-
|
|
2485
|
-
var len = queue.length;
|
|
2486
|
-
while(len) {
|
|
2487
|
-
currentQueue = queue;
|
|
2488
|
-
queue = [];
|
|
2489
|
-
while (++queueIndex < len) {
|
|
2490
|
-
if (currentQueue) {
|
|
2491
|
-
currentQueue[queueIndex].run();
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
queueIndex = -1;
|
|
2495
|
-
len = queue.length;
|
|
2496
|
-
}
|
|
2497
|
-
currentQueue = null;
|
|
2498
|
-
draining = false;
|
|
2499
|
-
runClearTimeout(timeout);
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
process.nextTick = function (fun) {
|
|
2503
|
-
var args = new Array(arguments.length - 1);
|
|
2504
|
-
if (arguments.length > 1) {
|
|
2505
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
2506
|
-
args[i - 1] = arguments[i];
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
queue.push(new Item(fun, args));
|
|
2510
|
-
if (queue.length === 1 && !draining) {
|
|
2511
|
-
runTimeout(drainQueue);
|
|
2512
|
-
}
|
|
2513
|
-
};
|
|
2514
|
-
|
|
2515
|
-
// v8 likes predictible objects
|
|
2516
|
-
function Item(fun, array) {
|
|
2517
|
-
this.fun = fun;
|
|
2518
|
-
this.array = array;
|
|
2519
|
-
}
|
|
2520
|
-
Item.prototype.run = function () {
|
|
2521
|
-
this.fun.apply(null, this.array);
|
|
2522
|
-
};
|
|
2523
|
-
process.title = 'browser';
|
|
2524
|
-
process.browser = true;
|
|
2525
|
-
process.env = {};
|
|
2526
|
-
process.argv = [];
|
|
2527
|
-
process.version = ''; // empty string to avoid regexp issues
|
|
2528
|
-
process.versions = {};
|
|
2529
|
-
|
|
2530
|
-
function noop() {}
|
|
2531
|
-
|
|
2532
|
-
process.on = noop;
|
|
2533
|
-
process.addListener = noop;
|
|
2534
|
-
process.once = noop;
|
|
2535
|
-
process.off = noop;
|
|
2536
|
-
process.removeListener = noop;
|
|
2537
|
-
process.removeAllListeners = noop;
|
|
2538
|
-
process.emit = noop;
|
|
2539
|
-
process.prependListener = noop;
|
|
2540
|
-
process.prependOnceListener = noop;
|
|
2541
|
-
|
|
2542
|
-
process.listeners = function (name) { return [] }
|
|
2543
|
-
|
|
2544
|
-
process.binding = function (name) {
|
|
2545
|
-
throw new Error('process.binding is not supported');
|
|
2546
|
-
};
|
|
2547
|
-
|
|
2548
|
-
process.cwd = function () { return '/' };
|
|
2549
|
-
process.chdir = function (dir) {
|
|
2550
|
-
throw new Error('process.chdir is not supported');
|
|
2551
|
-
};
|
|
2552
|
-
process.umask = function() { return 0; };
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
/***/ })
|
|
2556
|
-
|
|
2557
|
-
/******/ });
|
|
2558
|
-
/************************************************************************/
|
|
2559
|
-
/******/ // The module cache
|
|
2560
|
-
/******/ var __webpack_module_cache__ = {};
|
|
2561
|
-
/******/
|
|
2562
|
-
/******/ // The require function
|
|
2563
|
-
/******/ function __webpack_require__(moduleId) {
|
|
2564
|
-
/******/ // Check if module is in cache
|
|
2565
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
2566
|
-
/******/ if (cachedModule !== undefined) {
|
|
2567
|
-
/******/ return cachedModule.exports;
|
|
2568
|
-
/******/ }
|
|
2569
|
-
/******/ // Create a new module (and put it into the cache)
|
|
2570
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
2571
|
-
/******/ // no module.id needed
|
|
2572
|
-
/******/ // no module.loaded needed
|
|
2573
|
-
/******/ exports: {}
|
|
2574
|
-
/******/ };
|
|
2575
|
-
/******/
|
|
2576
|
-
/******/ // Execute the module function
|
|
2577
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
2578
|
-
/******/
|
|
2579
|
-
/******/ // Return the exports of the module
|
|
2580
|
-
/******/ return module.exports;
|
|
2581
|
-
/******/ }
|
|
2582
|
-
/******/
|
|
2583
|
-
/******/ // expose the modules object (__webpack_modules__)
|
|
2584
|
-
/******/ __webpack_require__.m = __webpack_modules__;
|
|
2585
|
-
/******/
|
|
2586
|
-
/************************************************************************/
|
|
2587
|
-
/******/ /* webpack/runtime/create fake namespace object */
|
|
2588
|
-
/******/ !function() {
|
|
2589
|
-
/******/ var getProto = Object.getPrototypeOf ? function(obj) { return Object.getPrototypeOf(obj); } : function(obj) { return obj.__proto__; };
|
|
2590
|
-
/******/ var leafPrototypes;
|
|
2591
|
-
/******/ // create a fake namespace object
|
|
2592
|
-
/******/ // mode & 1: value is a module id, require it
|
|
2593
|
-
/******/ // mode & 2: merge all properties of value into the ns
|
|
2594
|
-
/******/ // mode & 4: return value when already ns object
|
|
2595
|
-
/******/ // mode & 16: return value when it's Promise-like
|
|
2596
|
-
/******/ // mode & 8|1: behave like require
|
|
2597
|
-
/******/ __webpack_require__.t = function(value, mode) {
|
|
2598
|
-
/******/ if(mode & 1) value = this(value);
|
|
2599
|
-
/******/ if(mode & 8) return value;
|
|
2600
|
-
/******/ if(typeof value === 'object' && value) {
|
|
2601
|
-
/******/ if((mode & 4) && value.__esModule) return value;
|
|
2602
|
-
/******/ if((mode & 16) && typeof value.then === 'function') return value;
|
|
2603
|
-
/******/ }
|
|
2604
|
-
/******/ var ns = Object.create(null);
|
|
2605
|
-
/******/ __webpack_require__.r(ns);
|
|
2606
|
-
/******/ var def = {};
|
|
2607
|
-
/******/ leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
|
|
2608
|
-
/******/ for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {
|
|
2609
|
-
/******/ Object.getOwnPropertyNames(current).forEach(function(key) { def[key] = function() { return value[key]; }; });
|
|
2610
|
-
/******/ }
|
|
2611
|
-
/******/ def['default'] = function() { return value; };
|
|
2612
|
-
/******/ __webpack_require__.d(ns, def);
|
|
2613
|
-
/******/ return ns;
|
|
2614
|
-
/******/ };
|
|
2615
|
-
/******/ }();
|
|
2616
|
-
/******/
|
|
2617
|
-
/******/ /* webpack/runtime/define property getters */
|
|
2618
|
-
/******/ !function() {
|
|
2619
|
-
/******/ // define getter functions for harmony exports
|
|
2620
|
-
/******/ __webpack_require__.d = function(exports, definition) {
|
|
2621
|
-
/******/ for(var key in definition) {
|
|
2622
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
2623
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
2624
|
-
/******/ }
|
|
2625
|
-
/******/ }
|
|
2626
|
-
/******/ };
|
|
2627
|
-
/******/ }();
|
|
2628
|
-
/******/
|
|
2629
|
-
/******/ /* webpack/runtime/ensure chunk */
|
|
2630
|
-
/******/ !function() {
|
|
2631
|
-
/******/ __webpack_require__.f = {};
|
|
2632
|
-
/******/ // This file contains only the entry chunk.
|
|
2633
|
-
/******/ // The chunk loading function for additional chunks
|
|
2634
|
-
/******/ __webpack_require__.e = function(chunkId) {
|
|
2635
|
-
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
2636
|
-
/******/ __webpack_require__.f[key](chunkId, promises);
|
|
2637
|
-
/******/ return promises;
|
|
2638
|
-
/******/ }, []));
|
|
2639
|
-
/******/ };
|
|
2640
|
-
/******/ }();
|
|
2641
|
-
/******/
|
|
2642
|
-
/******/ /* webpack/runtime/get javascript chunk filename */
|
|
2643
|
-
/******/ !function() {
|
|
2644
|
-
/******/ // This function allow to reference async chunks
|
|
2645
|
-
/******/ __webpack_require__.u = function(chunkId) {
|
|
2646
|
-
/******/ // return url for filenames based on template
|
|
2647
|
-
/******/ return "" + chunkId + ".js";
|
|
2648
|
-
/******/ };
|
|
2649
|
-
/******/ }();
|
|
2650
|
-
/******/
|
|
2651
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
2652
|
-
/******/ !function() {
|
|
2653
|
-
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
2654
|
-
/******/ }();
|
|
2655
|
-
/******/
|
|
2656
|
-
/******/ /* webpack/runtime/load script */
|
|
2657
|
-
/******/ !function() {
|
|
2658
|
-
/******/ var inProgress = {};
|
|
2659
|
-
/******/ var dataWebpackPrefix = "@leofcoin/chain:";
|
|
2660
|
-
/******/ // loadScript function to load a script via script tag
|
|
2661
|
-
/******/ __webpack_require__.l = function(url, done, key, chunkId) {
|
|
2662
|
-
/******/ if(inProgress[url]) { inProgress[url].push(done); return; }
|
|
2663
|
-
/******/ var script, needAttach;
|
|
2664
|
-
/******/ if(key !== undefined) {
|
|
2665
|
-
/******/ var scripts = document.getElementsByTagName("script");
|
|
2666
|
-
/******/ for(var i = 0; i < scripts.length; i++) {
|
|
2667
|
-
/******/ var s = scripts[i];
|
|
2668
|
-
/******/ if(s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key) { script = s; break; }
|
|
2669
|
-
/******/ }
|
|
2670
|
-
/******/ }
|
|
2671
|
-
/******/ if(!script) {
|
|
2672
|
-
/******/ needAttach = true;
|
|
2673
|
-
/******/ script = document.createElement('script');
|
|
2674
|
-
/******/ script.type = "module";
|
|
2675
|
-
/******/ script.charset = 'utf-8';
|
|
2676
|
-
/******/ script.timeout = 120;
|
|
2677
|
-
/******/ if (__webpack_require__.nc) {
|
|
2678
|
-
/******/ script.setAttribute("nonce", __webpack_require__.nc);
|
|
2679
|
-
/******/ }
|
|
2680
|
-
/******/ script.setAttribute("data-webpack", dataWebpackPrefix + key);
|
|
2681
|
-
/******/ script.src = url;
|
|
2682
|
-
/******/ }
|
|
2683
|
-
/******/ inProgress[url] = [done];
|
|
2684
|
-
/******/ var onScriptComplete = function(prev, event) {
|
|
2685
|
-
/******/ // avoid mem leaks in IE.
|
|
2686
|
-
/******/ script.onerror = script.onload = null;
|
|
2687
|
-
/******/ clearTimeout(timeout);
|
|
2688
|
-
/******/ var doneFns = inProgress[url];
|
|
2689
|
-
/******/ delete inProgress[url];
|
|
2690
|
-
/******/ script.parentNode && script.parentNode.removeChild(script);
|
|
2691
|
-
/******/ doneFns && doneFns.forEach(function(fn) { return fn(event); });
|
|
2692
|
-
/******/ if(prev) return prev(event);
|
|
2693
|
-
/******/ };
|
|
2694
|
-
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
|
|
2695
|
-
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
2696
|
-
/******/ script.onload = onScriptComplete.bind(null, script.onload);
|
|
2697
|
-
/******/ needAttach && document.head.appendChild(script);
|
|
2698
|
-
/******/ };
|
|
2699
|
-
/******/ }();
|
|
2700
|
-
/******/
|
|
2701
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
2702
|
-
/******/ !function() {
|
|
2703
|
-
/******/ // define __esModule on exports
|
|
2704
|
-
/******/ __webpack_require__.r = function(exports) {
|
|
2705
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
2706
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2707
|
-
/******/ }
|
|
2708
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
2709
|
-
/******/ };
|
|
2710
|
-
/******/ }();
|
|
2711
|
-
/******/
|
|
2712
|
-
/******/ /* webpack/runtime/publicPath */
|
|
2713
|
-
/******/ !function() {
|
|
2714
|
-
/******/ __webpack_require__.p = "";
|
|
2715
|
-
/******/ }();
|
|
2716
|
-
/******/
|
|
2717
|
-
/******/ /* webpack/runtime/jsonp chunk loading */
|
|
2718
|
-
/******/ !function() {
|
|
2719
|
-
/******/ // no baseURI
|
|
2720
|
-
/******/
|
|
2721
|
-
/******/ // object to store loaded and loading chunks
|
|
2722
|
-
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
|
2723
|
-
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
|
|
2724
|
-
/******/ var installedChunks = {
|
|
2725
|
-
/******/ 775: 0
|
|
2726
|
-
/******/ };
|
|
2727
|
-
/******/
|
|
2728
|
-
/******/ __webpack_require__.f.j = function(chunkId, promises) {
|
|
2729
|
-
/******/ // JSONP chunk loading for javascript
|
|
2730
|
-
/******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
|
|
2731
|
-
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
|
|
2732
|
-
/******/
|
|
2733
|
-
/******/ // a Promise means "currently loading".
|
|
2734
|
-
/******/ if(installedChunkData) {
|
|
2735
|
-
/******/ promises.push(installedChunkData[2]);
|
|
2736
|
-
/******/ } else {
|
|
2737
|
-
/******/ if(true) { // all chunks have JS
|
|
2738
|
-
/******/ // setup Promise in chunk cache
|
|
2739
|
-
/******/ var promise = new Promise(function(resolve, reject) { installedChunkData = installedChunks[chunkId] = [resolve, reject]; });
|
|
2740
|
-
/******/ promises.push(installedChunkData[2] = promise);
|
|
2741
|
-
/******/
|
|
2742
|
-
/******/ // start chunk loading
|
|
2743
|
-
/******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
|
|
2744
|
-
/******/ // create error before stack unwound to get useful stacktrace later
|
|
2745
|
-
/******/ var error = new Error();
|
|
2746
|
-
/******/ var loadingEnded = function(event) {
|
|
2747
|
-
/******/ if(__webpack_require__.o(installedChunks, chunkId)) {
|
|
2748
|
-
/******/ installedChunkData = installedChunks[chunkId];
|
|
2749
|
-
/******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
|
|
2750
|
-
/******/ if(installedChunkData) {
|
|
2751
|
-
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
|
|
2752
|
-
/******/ var realSrc = event && event.target && event.target.src;
|
|
2753
|
-
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
|
|
2754
|
-
/******/ error.name = 'ChunkLoadError';
|
|
2755
|
-
/******/ error.type = errorType;
|
|
2756
|
-
/******/ error.request = realSrc;
|
|
2757
|
-
/******/ installedChunkData[1](error);
|
|
2758
|
-
/******/ }
|
|
2759
|
-
/******/ }
|
|
2760
|
-
/******/ };
|
|
2761
|
-
/******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId);
|
|
2762
|
-
/******/ } else installedChunks[chunkId] = 0;
|
|
2763
|
-
/******/ }
|
|
2764
|
-
/******/ }
|
|
2765
|
-
/******/ };
|
|
2766
|
-
/******/
|
|
2767
|
-
/******/ // no prefetching
|
|
2768
|
-
/******/
|
|
2769
|
-
/******/ // no preloaded
|
|
2770
|
-
/******/
|
|
2771
|
-
/******/ // no HMR
|
|
2772
|
-
/******/
|
|
2773
|
-
/******/ // no HMR manifest
|
|
2774
|
-
/******/
|
|
2775
|
-
/******/ // no on chunks loaded
|
|
2776
|
-
/******/
|
|
2777
|
-
/******/ // install a JSONP callback for chunk loading
|
|
2778
|
-
/******/ var webpackJsonpCallback = function(parentChunkLoadingFunction, data) {
|
|
2779
|
-
/******/ var chunkIds = data[0];
|
|
2780
|
-
/******/ var moreModules = data[1];
|
|
2781
|
-
/******/ var runtime = data[2];
|
|
2782
|
-
/******/ // add "moreModules" to the modules object,
|
|
2783
|
-
/******/ // then flag all "chunkIds" as loaded and fire callback
|
|
2784
|
-
/******/ var moduleId, chunkId, i = 0;
|
|
2785
|
-
/******/ if(chunkIds.some(function(id) { return installedChunks[id] !== 0; })) {
|
|
2786
|
-
/******/ for(moduleId in moreModules) {
|
|
2787
|
-
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
|
|
2788
|
-
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
2789
|
-
/******/ }
|
|
2790
|
-
/******/ }
|
|
2791
|
-
/******/ if(runtime) var result = runtime(__webpack_require__);
|
|
2792
|
-
/******/ }
|
|
2793
|
-
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
|
|
2794
|
-
/******/ for(;i < chunkIds.length; i++) {
|
|
2795
|
-
/******/ chunkId = chunkIds[i];
|
|
2796
|
-
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
|
|
2797
|
-
/******/ installedChunks[chunkId][0]();
|
|
2798
|
-
/******/ }
|
|
2799
|
-
/******/ installedChunks[chunkId] = 0;
|
|
2800
|
-
/******/ }
|
|
2801
|
-
/******/
|
|
2802
|
-
/******/ }
|
|
2803
|
-
/******/
|
|
2804
|
-
/******/ var chunkLoadingGlobal = self["webpackChunk_leofcoin_chain"] = self["webpackChunk_leofcoin_chain"] || [];
|
|
2805
|
-
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
|
|
2806
|
-
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
|
|
2807
|
-
/******/ }();
|
|
2808
|
-
/******/
|
|
2809
|
-
/************************************************************************/
|
|
2810
|
-
var __webpack_exports__ = {};
|
|
2811
|
-
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
2812
|
-
!function() {
|
|
2813
|
-
|
|
2814
|
-
;// CONCATENATED MODULE: ./node_modules/@leofcoin/codec-format-interface/dist/index.js
|
|
2815
|
-
/* provided dependency */ var Buffer = __webpack_require__(764)["Buffer"];
|
|
2816
|
-
/******************************************************************************
|
|
2817
|
-
Copyright (c) Microsoft Corporation.
|
|
2818
|
-
|
|
2819
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
2820
|
-
purpose with or without fee is hereby granted.
|
|
2821
|
-
|
|
2822
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2823
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2824
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2825
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2826
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2827
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2828
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
2829
|
-
***************************************************************************** */
|
|
2830
|
-
/* global Reflect, Promise */
|
|
2831
|
-
|
|
2832
|
-
var extendStatics = function(d, b) {
|
|
2833
|
-
extendStatics = Object.setPrototypeOf ||
|
|
2834
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
2835
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
2836
|
-
return extendStatics(d, b);
|
|
2837
|
-
};
|
|
2838
|
-
|
|
2839
|
-
function __extends(d, b) {
|
|
2840
|
-
if (typeof b !== "function" && b !== null)
|
|
2841
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
2842
|
-
extendStatics(d, b);
|
|
2843
|
-
function __() { this.constructor = d; }
|
|
2844
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2845
|
-
}
|
|
2846
|
-
|
|
2847
|
-
var __assign = function() {
|
|
2848
|
-
__assign = Object.assign || function __assign(t) {
|
|
2849
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2850
|
-
s = arguments[i];
|
|
2851
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
2852
|
-
}
|
|
2853
|
-
return t;
|
|
2854
|
-
};
|
|
2855
|
-
return __assign.apply(this, arguments);
|
|
2856
|
-
};
|
|
2857
|
-
|
|
2858
|
-
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
2859
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2860
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2861
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2862
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2863
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2864
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2865
|
-
});
|
|
2866
|
-
}
|
|
2867
|
-
|
|
2868
|
-
function __generator(thisArg, body) {
|
|
2869
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
2870
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2871
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2872
|
-
function step(op) {
|
|
2873
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
2874
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
2875
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
2876
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2877
|
-
switch (op[0]) {
|
|
2878
|
-
case 0: case 1: t = op; break;
|
|
2879
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
2880
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2881
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2882
|
-
default:
|
|
2883
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2884
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2885
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2886
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2887
|
-
if (t[2]) _.ops.pop();
|
|
2888
|
-
_.trys.pop(); continue;
|
|
2889
|
-
}
|
|
2890
|
-
op = body.call(thisArg, _);
|
|
2891
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2892
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2893
|
-
}
|
|
2894
|
-
}
|
|
2895
|
-
|
|
2896
|
-
function __values(o) {
|
|
2897
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
2898
|
-
if (m) return m.call(o);
|
|
2899
|
-
if (o && typeof o.length === "number") return {
|
|
2900
|
-
next: function () {
|
|
2901
|
-
if (o && i >= o.length) o = void 0;
|
|
2902
|
-
return { value: o && o[i++], done: !o };
|
|
2903
|
-
}
|
|
2904
|
-
};
|
|
2905
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
2906
|
-
}
|
|
2907
|
-
|
|
2908
|
-
function __spreadArray(to, from, pack) {
|
|
2909
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
2910
|
-
if (ar || !(i in from)) {
|
|
2911
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
2912
|
-
ar[i] = from[i];
|
|
2913
|
-
}
|
|
2914
|
-
}
|
|
2915
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
2916
|
-
}
|
|
2917
|
-
|
|
2918
|
-
function __asyncValues(o) {
|
|
2919
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
2920
|
-
var m = o[Symbol.asyncIterator], i;
|
|
2921
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
2922
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
2923
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
2924
|
-
}
|
|
2925
|
-
|
|
2926
|
-
// base-x encoding / decoding
|
|
2927
|
-
// Copyright (c) 2018 base-x contributors
|
|
2928
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
2929
|
-
// Distributed under the MIT software license, see the accompanying
|
|
2930
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
2931
|
-
var base$1 = function (ALPHABET) {
|
|
2932
|
-
if (ALPHABET.length >= 255) {
|
|
2933
|
-
throw new TypeError('Alphabet too long');
|
|
2934
|
-
}
|
|
2935
|
-
var BASE_MAP = new Uint8Array(256);
|
|
2936
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
2937
|
-
BASE_MAP[j] = 255;
|
|
2938
|
-
}
|
|
2939
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
2940
|
-
var x = ALPHABET.charAt(i);
|
|
2941
|
-
var xc = x.charCodeAt(0);
|
|
2942
|
-
if (BASE_MAP[xc] !== 255) {
|
|
2943
|
-
throw new TypeError(x + ' is ambiguous');
|
|
2944
|
-
}
|
|
2945
|
-
BASE_MAP[xc] = i;
|
|
2946
|
-
}
|
|
2947
|
-
var BASE = ALPHABET.length;
|
|
2948
|
-
var LEADER = ALPHABET.charAt(0);
|
|
2949
|
-
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
2950
|
-
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
2951
|
-
var encode = function (source) {
|
|
2952
|
-
if (source instanceof Uint8Array) ;
|
|
2953
|
-
else if (ArrayBuffer.isView(source)) {
|
|
2954
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
2955
|
-
}
|
|
2956
|
-
else if (Array.isArray(source)) {
|
|
2957
|
-
source = Uint8Array.from(source);
|
|
2958
|
-
}
|
|
2959
|
-
if (!(source instanceof Uint8Array)) {
|
|
2960
|
-
throw new TypeError('Expected Uint8Array');
|
|
2961
|
-
}
|
|
2962
|
-
if (source.length === 0) {
|
|
2963
|
-
return '';
|
|
2964
|
-
}
|
|
2965
|
-
// Skip & count leading zeroes.
|
|
2966
|
-
var zeroes = 0;
|
|
2967
|
-
var length = 0;
|
|
2968
|
-
var pbegin = 0;
|
|
2969
|
-
var pend = source.length;
|
|
2970
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
2971
|
-
pbegin++;
|
|
2972
|
-
zeroes++;
|
|
2973
|
-
}
|
|
2974
|
-
// Allocate enough space in big-endian base58 representation.
|
|
2975
|
-
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
2976
|
-
var b58 = new Uint8Array(size);
|
|
2977
|
-
// Process the bytes.
|
|
2978
|
-
while (pbegin !== pend) {
|
|
2979
|
-
var carry = source[pbegin];
|
|
2980
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
2981
|
-
var i = 0;
|
|
2982
|
-
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
2983
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
2984
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
2985
|
-
carry = (carry / BASE) >>> 0;
|
|
2986
|
-
}
|
|
2987
|
-
if (carry !== 0) {
|
|
2988
|
-
throw new Error('Non-zero carry');
|
|
2989
|
-
}
|
|
2990
|
-
length = i;
|
|
2991
|
-
pbegin++;
|
|
2992
|
-
}
|
|
2993
|
-
// Skip leading zeroes in base58 result.
|
|
2994
|
-
var it2 = size - length;
|
|
2995
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
2996
|
-
it2++;
|
|
2997
|
-
}
|
|
2998
|
-
// Translate the result into a string.
|
|
2999
|
-
var str = LEADER.repeat(zeroes);
|
|
3000
|
-
for (; it2 < size; ++it2) {
|
|
3001
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
3002
|
-
}
|
|
3003
|
-
return str;
|
|
3004
|
-
};
|
|
3005
|
-
var decodeUnsafe = function (source) {
|
|
3006
|
-
if (typeof source !== 'string') {
|
|
3007
|
-
throw new TypeError('Expected String');
|
|
3008
|
-
}
|
|
3009
|
-
if (source.length === 0) {
|
|
3010
|
-
return new Uint8Array();
|
|
3011
|
-
}
|
|
3012
|
-
var psz = 0;
|
|
3013
|
-
// Skip and count leading '1's.
|
|
3014
|
-
var zeroes = 0;
|
|
3015
|
-
var length = 0;
|
|
3016
|
-
while (source[psz] === LEADER) {
|
|
3017
|
-
zeroes++;
|
|
3018
|
-
psz++;
|
|
3019
|
-
}
|
|
3020
|
-
// Allocate enough space in big-endian base256 representation.
|
|
3021
|
-
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
3022
|
-
var b256 = new Uint8Array(size);
|
|
3023
|
-
// Process the characters.
|
|
3024
|
-
while (source[psz]) {
|
|
3025
|
-
// Decode character
|
|
3026
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
3027
|
-
// Invalid character
|
|
3028
|
-
if (carry === 255) {
|
|
3029
|
-
return;
|
|
3030
|
-
}
|
|
3031
|
-
var i = 0;
|
|
3032
|
-
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
3033
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
3034
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
3035
|
-
carry = (carry / 256) >>> 0;
|
|
3036
|
-
}
|
|
3037
|
-
if (carry !== 0) {
|
|
3038
|
-
throw new Error('Non-zero carry');
|
|
3039
|
-
}
|
|
3040
|
-
length = i;
|
|
3041
|
-
psz++;
|
|
3042
|
-
}
|
|
3043
|
-
// Skip leading zeroes in b256.
|
|
3044
|
-
var it4 = size - length;
|
|
3045
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
3046
|
-
it4++;
|
|
3047
|
-
}
|
|
3048
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3049
|
-
var j = zeroes;
|
|
3050
|
-
while (it4 !== size) {
|
|
3051
|
-
vch[j++] = b256[it4++];
|
|
3052
|
-
}
|
|
3053
|
-
return vch;
|
|
3054
|
-
};
|
|
3055
|
-
var decode = function (string) {
|
|
3056
|
-
var buffer = decodeUnsafe(string);
|
|
3057
|
-
if (buffer) {
|
|
3058
|
-
return buffer;
|
|
3059
|
-
}
|
|
3060
|
-
throw new Error('Non-base' + BASE + ' character');
|
|
3061
|
-
};
|
|
3062
|
-
return {
|
|
3063
|
-
encode: encode,
|
|
3064
|
-
decodeUnsafe: decodeUnsafe,
|
|
3065
|
-
decode: decode
|
|
3066
|
-
};
|
|
3067
|
-
};
|
|
3068
|
-
|
|
3069
|
-
var base32 = 'abcdefghijklmnopqrstuvwxyz234567';
|
|
3070
|
-
var base32Hex = '0123456789abcdefghijklmnopqrstuv';
|
|
3071
|
-
var decode$2 = function (string, hex) {
|
|
3072
|
-
if (hex === void 0) { hex = false; }
|
|
3073
|
-
var decoder = hex ? base$1(base32Hex) : base$1(base32);
|
|
3074
|
-
return decoder.decode(string);
|
|
3075
|
-
};
|
|
3076
|
-
var base32$1 = {
|
|
3077
|
-
encode: function (uint8Array, hex) {
|
|
3078
|
-
if (hex === void 0) { hex = false; }
|
|
3079
|
-
var encoder = hex ? base$1(base32Hex) : base$1(base32);
|
|
3080
|
-
return encoder.encode(uint8Array);
|
|
3081
|
-
},
|
|
3082
|
-
decode: decode$2,
|
|
3083
|
-
isBase32: function (string, hex) {
|
|
3084
|
-
if (hex === void 0) { hex = false; }
|
|
3085
|
-
try {
|
|
3086
|
-
decode$2(string, hex);
|
|
3087
|
-
return true;
|
|
3088
|
-
}
|
|
3089
|
-
catch (e) {
|
|
3090
|
-
return false;
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
|
-
};
|
|
3094
|
-
|
|
3095
|
-
// base-x encoding / decoding
|
|
3096
|
-
// Copyright (c) 2018 base-x contributors
|
|
3097
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
3098
|
-
// Distributed under the MIT software license, see the accompanying
|
|
3099
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
3100
|
-
var base = function (ALPHABET) {
|
|
3101
|
-
if (ALPHABET.length >= 255) {
|
|
3102
|
-
throw new TypeError('Alphabet too long');
|
|
3103
|
-
}
|
|
3104
|
-
var BASE_MAP = new Uint8Array(256);
|
|
3105
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3106
|
-
BASE_MAP[j] = 255;
|
|
3107
|
-
}
|
|
3108
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3109
|
-
var x = ALPHABET.charAt(i);
|
|
3110
|
-
var xc = x.charCodeAt(0);
|
|
3111
|
-
if (BASE_MAP[xc] !== 255) {
|
|
3112
|
-
throw new TypeError(x + ' is ambiguous');
|
|
3113
|
-
}
|
|
3114
|
-
BASE_MAP[xc] = i;
|
|
3115
|
-
}
|
|
3116
|
-
var BASE = ALPHABET.length;
|
|
3117
|
-
var LEADER = ALPHABET.charAt(0);
|
|
3118
|
-
var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
3119
|
-
var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
3120
|
-
var encode = function (source) {
|
|
3121
|
-
if (source instanceof Uint8Array) ;
|
|
3122
|
-
else if (ArrayBuffer.isView(source)) {
|
|
3123
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
3124
|
-
}
|
|
3125
|
-
else if (Array.isArray(source)) {
|
|
3126
|
-
source = Uint8Array.from(source);
|
|
3127
|
-
}
|
|
3128
|
-
if (!(source instanceof Uint8Array)) {
|
|
3129
|
-
throw new TypeError('Expected Uint8Array');
|
|
3130
|
-
}
|
|
3131
|
-
if (source.length === 0) {
|
|
3132
|
-
return '';
|
|
3133
|
-
}
|
|
3134
|
-
// Skip & count leading zeroes.
|
|
3135
|
-
var zeroes = 0;
|
|
3136
|
-
var length = 0;
|
|
3137
|
-
var pbegin = 0;
|
|
3138
|
-
var pend = source.length;
|
|
3139
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3140
|
-
pbegin++;
|
|
3141
|
-
zeroes++;
|
|
3142
|
-
}
|
|
3143
|
-
// Allocate enough space in big-endian base58 representation.
|
|
3144
|
-
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
3145
|
-
var b58 = new Uint8Array(size);
|
|
3146
|
-
// Process the bytes.
|
|
3147
|
-
while (pbegin !== pend) {
|
|
3148
|
-
var carry = source[pbegin];
|
|
3149
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
3150
|
-
var i = 0;
|
|
3151
|
-
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
3152
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
3153
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
3154
|
-
carry = (carry / BASE) >>> 0;
|
|
3155
|
-
}
|
|
3156
|
-
if (carry !== 0) {
|
|
3157
|
-
throw new Error('Non-zero carry');
|
|
3158
|
-
}
|
|
3159
|
-
length = i;
|
|
3160
|
-
pbegin++;
|
|
3161
|
-
}
|
|
3162
|
-
// Skip leading zeroes in base58 result.
|
|
3163
|
-
var it2 = size - length;
|
|
3164
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
3165
|
-
it2++;
|
|
3166
|
-
}
|
|
3167
|
-
// Translate the result into a string.
|
|
3168
|
-
var str = LEADER.repeat(zeroes);
|
|
3169
|
-
for (; it2 < size; ++it2) {
|
|
3170
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
3171
|
-
}
|
|
3172
|
-
return str;
|
|
3173
|
-
};
|
|
3174
|
-
var decodeUnsafe = function (source) {
|
|
3175
|
-
if (typeof source !== 'string') {
|
|
3176
|
-
throw new TypeError('Expected String');
|
|
3177
|
-
}
|
|
3178
|
-
if (source.length === 0) {
|
|
3179
|
-
return new Uint8Array();
|
|
3180
|
-
}
|
|
3181
|
-
var psz = 0;
|
|
3182
|
-
// Skip and count leading '1's.
|
|
3183
|
-
var zeroes = 0;
|
|
3184
|
-
var length = 0;
|
|
3185
|
-
while (source[psz] === LEADER) {
|
|
3186
|
-
zeroes++;
|
|
3187
|
-
psz++;
|
|
3188
|
-
}
|
|
3189
|
-
// Allocate enough space in big-endian base256 representation.
|
|
3190
|
-
var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
3191
|
-
var b256 = new Uint8Array(size);
|
|
3192
|
-
// Process the characters.
|
|
3193
|
-
while (source[psz]) {
|
|
3194
|
-
// Decode character
|
|
3195
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
3196
|
-
// Invalid character
|
|
3197
|
-
if (carry === 255) {
|
|
3198
|
-
return;
|
|
3199
|
-
}
|
|
3200
|
-
var i = 0;
|
|
3201
|
-
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
3202
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
3203
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
3204
|
-
carry = (carry / 256) >>> 0;
|
|
3205
|
-
}
|
|
3206
|
-
if (carry !== 0) {
|
|
3207
|
-
throw new Error('Non-zero carry');
|
|
3208
|
-
}
|
|
3209
|
-
length = i;
|
|
3210
|
-
psz++;
|
|
3211
|
-
}
|
|
3212
|
-
// Skip leading zeroes in b256.
|
|
3213
|
-
var it4 = size - length;
|
|
3214
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
3215
|
-
it4++;
|
|
3216
|
-
}
|
|
3217
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
3218
|
-
var j = zeroes;
|
|
3219
|
-
while (it4 !== size) {
|
|
3220
|
-
vch[j++] = b256[it4++];
|
|
3221
|
-
}
|
|
3222
|
-
return vch;
|
|
3223
|
-
};
|
|
3224
|
-
var decode = function (string) {
|
|
3225
|
-
var buffer = decodeUnsafe(string);
|
|
3226
|
-
if (buffer) {
|
|
3227
|
-
return buffer;
|
|
3228
|
-
}
|
|
3229
|
-
throw new Error('Non-base' + BASE + ' character');
|
|
3230
|
-
};
|
|
3231
|
-
return {
|
|
3232
|
-
encode: encode,
|
|
3233
|
-
decodeUnsafe: decodeUnsafe,
|
|
3234
|
-
decode: decode
|
|
3235
|
-
};
|
|
3236
|
-
};
|
|
3237
|
-
|
|
3238
|
-
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
3239
|
-
var base58 = base(ALPHABET);
|
|
3240
|
-
var decode$1 = function (string) { return base58.decode(string); };
|
|
3241
|
-
var base58$1 = {
|
|
3242
|
-
encode: function (uint8Array) { return base58.encode(uint8Array); },
|
|
3243
|
-
decode: decode$1,
|
|
3244
|
-
isBase58: function (string) {
|
|
3245
|
-
try {
|
|
3246
|
-
decode$1(string);
|
|
3247
|
-
return true;
|
|
3248
|
-
}
|
|
3249
|
-
catch (e) {
|
|
3250
|
-
return false;
|
|
3251
|
-
}
|
|
3252
|
-
}
|
|
3253
|
-
};
|
|
3254
|
-
|
|
3255
|
-
/**
|
|
3256
|
-
* @param {string}
|
|
3257
|
-
*/
|
|
3258
|
-
var isHex = (function (string) { return /^[A-F0-9]+$/i.test(string); });
|
|
3259
|
-
|
|
3260
|
-
var BasicInterface$1 = /** @class */ (function () {
|
|
3261
|
-
function BasicInterface() {
|
|
3262
|
-
}
|
|
3263
|
-
// get Codec(): Codec {}
|
|
3264
|
-
BasicInterface.prototype.protoEncode = function (data) {
|
|
3265
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
3266
|
-
return __generator(this, function (_a) {
|
|
3267
|
-
// check schema
|
|
3268
|
-
return [2 /*return*/, new TextEncoder().encode(data)];
|
|
3269
|
-
});
|
|
3270
|
-
});
|
|
3271
|
-
};
|
|
3272
|
-
BasicInterface.prototype.protoDecode = function (data) {
|
|
3273
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
3274
|
-
return __generator(this, function (_a) {
|
|
3275
|
-
// check schema
|
|
3276
|
-
return [2 /*return*/, new TextDecoder().decode(data)];
|
|
3277
|
-
});
|
|
3278
|
-
});
|
|
3279
|
-
};
|
|
3280
|
-
BasicInterface.prototype.isHex = function (string) {
|
|
3281
|
-
return isHex(string);
|
|
3282
|
-
};
|
|
3283
|
-
BasicInterface.prototype.isBase32 = function (string) {
|
|
3284
|
-
return base32$1.isBase32(string);
|
|
3285
|
-
};
|
|
3286
|
-
BasicInterface.prototype.isBase58 = function (string) {
|
|
3287
|
-
return base58$1.isBase58(string);
|
|
3288
|
-
};
|
|
3289
|
-
BasicInterface.prototype.fromBs32 = function (encoded) {
|
|
3290
|
-
this.encoded = base32$1.decode(encoded);
|
|
3291
|
-
return this.decode();
|
|
3292
|
-
};
|
|
3293
|
-
BasicInterface.prototype.fromBs58 = function (encoded) {
|
|
3294
|
-
this.encoded = base58$1.decode(encoded);
|
|
3295
|
-
return this.decode();
|
|
3296
|
-
};
|
|
3297
|
-
BasicInterface.prototype.toArray = function () {
|
|
3298
|
-
var _a, e_1, _b, _c;
|
|
3299
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
3300
|
-
var array, _d, _e, _f, value, e_1_1;
|
|
3301
|
-
return __generator(this, function (_g) {
|
|
3302
|
-
switch (_g.label) {
|
|
3303
|
-
case 0:
|
|
3304
|
-
array = [];
|
|
3305
|
-
_g.label = 1;
|
|
3306
|
-
case 1:
|
|
3307
|
-
_g.trys.push([1, 6, 7, 12]);
|
|
3308
|
-
_d = true, _e = __asyncValues(this.encoded.values());
|
|
3309
|
-
_g.label = 2;
|
|
3310
|
-
case 2: return [4 /*yield*/, _e.next()];
|
|
3311
|
-
case 3:
|
|
3312
|
-
if (!(_f = _g.sent(), _a = _f.done, !_a)) return [3 /*break*/, 5];
|
|
3313
|
-
_c = _f.value;
|
|
3314
|
-
_d = false;
|
|
3315
|
-
try {
|
|
3316
|
-
value = _c;
|
|
3317
|
-
array.push(value);
|
|
3318
|
-
}
|
|
3319
|
-
finally {
|
|
3320
|
-
_d = true;
|
|
3321
|
-
}
|
|
3322
|
-
_g.label = 4;
|
|
3323
|
-
case 4: return [3 /*break*/, 2];
|
|
3324
|
-
case 5: return [3 /*break*/, 12];
|
|
3325
|
-
case 6:
|
|
3326
|
-
e_1_1 = _g.sent();
|
|
3327
|
-
e_1 = { error: e_1_1 };
|
|
3328
|
-
return [3 /*break*/, 12];
|
|
3329
|
-
case 7:
|
|
3330
|
-
_g.trys.push([7, , 10, 11]);
|
|
3331
|
-
if (!(!_d && !_a && (_b = _e["return"]))) return [3 /*break*/, 9];
|
|
3332
|
-
return [4 /*yield*/, _b.call(_e)];
|
|
3333
|
-
case 8:
|
|
3334
|
-
_g.sent();
|
|
3335
|
-
_g.label = 9;
|
|
3336
|
-
case 9: return [3 /*break*/, 11];
|
|
3337
|
-
case 10:
|
|
3338
|
-
if (e_1) throw e_1.error;
|
|
3339
|
-
return [7 /*endfinally*/];
|
|
3340
|
-
case 11: return [7 /*endfinally*/];
|
|
3341
|
-
case 12: return [2 /*return*/, array];
|
|
3342
|
-
}
|
|
3343
|
-
});
|
|
3344
|
-
});
|
|
3345
|
-
};
|
|
3346
|
-
BasicInterface.prototype.fromString = function (string) {
|
|
3347
|
-
var array = string.split(',');
|
|
3348
|
-
var arrayLike = array.map(function (string) { return Number(string); });
|
|
3349
|
-
this.encoded = Uint8Array.from(arrayLike);
|
|
3350
|
-
return this.decode();
|
|
3351
|
-
};
|
|
3352
|
-
BasicInterface.prototype.fromArray = function (array) {
|
|
3353
|
-
this.encoded = Uint8Array.from(__spreadArray([], array, true));
|
|
3354
|
-
return this.decode();
|
|
3355
|
-
};
|
|
3356
|
-
BasicInterface.prototype.fromEncoded = function (encoded) {
|
|
3357
|
-
this.encoded = encoded;
|
|
3358
|
-
return this.decode();
|
|
3359
|
-
};
|
|
3360
|
-
BasicInterface.prototype.fromHex = function (encoded) {
|
|
3361
|
-
this.encoded = Buffer.from(encoded, 'hex');
|
|
3362
|
-
return this.decode();
|
|
3363
|
-
};
|
|
3364
|
-
BasicInterface.prototype.toString = function (encoding) {
|
|
3365
|
-
if (encoding === void 0) { encoding = 'utf8'; }
|
|
3366
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
3367
|
-
return __generator(this, function (_a) {
|
|
3368
|
-
switch (_a.label) {
|
|
3369
|
-
case 0:
|
|
3370
|
-
if (!!this.encoded) return [3 /*break*/, 2];
|
|
3371
|
-
return [4 /*yield*/, this.encode()];
|
|
3372
|
-
case 1:
|
|
3373
|
-
_a.sent();
|
|
3374
|
-
_a.label = 2;
|
|
3375
|
-
case 2: return [2 /*return*/, this.encoded.toString(encoding)];
|
|
3376
|
-
}
|
|
3377
|
-
});
|
|
3378
|
-
});
|
|
3379
|
-
};
|
|
3380
|
-
/**
|
|
3381
|
-
* @return {String} encoded
|
|
3382
|
-
*/
|
|
3383
|
-
BasicInterface.prototype.toHex = function () {
|
|
3384
|
-
return this.toString('hex');
|
|
3385
|
-
};
|
|
3386
|
-
/**
|
|
3387
|
-
* @return {String} encoded
|
|
3388
|
-
*/
|
|
3389
|
-
BasicInterface.prototype.toBs32 = function () {
|
|
3390
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
3391
|
-
return __generator(this, function (_a) {
|
|
3392
|
-
switch (_a.label) {
|
|
3393
|
-
case 0:
|
|
3394
|
-
if (!!this.encoded) return [3 /*break*/, 2];
|
|
3395
|
-
return [4 /*yield*/, this.encode()];
|
|
3396
|
-
case 1:
|
|
3397
|
-
_a.sent();
|
|
3398
|
-
_a.label = 2;
|
|
3399
|
-
case 2: return [2 /*return*/, base32$1.encode(this.encoded)];
|
|
3400
|
-
}
|
|
3401
|
-
});
|
|
3402
|
-
});
|
|
3403
|
-
};
|
|
3404
|
-
/**
|
|
3405
|
-
* @return {String} encoded
|
|
3406
|
-
*/
|
|
3407
|
-
BasicInterface.prototype.toBs58 = function () {
|
|
3408
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
3409
|
-
return __generator(this, function (_a) {
|
|
3410
|
-
switch (_a.label) {
|
|
3411
|
-
case 0:
|
|
3412
|
-
if (!!this.encoded) return [3 /*break*/, 2];
|
|
3413
|
-
return [4 /*yield*/, this.encode()];
|
|
3414
|
-
case 1:
|
|
3415
|
-
_a.sent();
|
|
3416
|
-
_a.label = 2;
|
|
3417
|
-
case 2: return [2 /*return*/, base58$1.encode(this.encoded)];
|
|
3418
|
-
}
|
|
3419
|
-
});
|
|
3420
|
-
});
|
|
3421
|
-
};
|
|
3422
|
-
/**
|
|
3423
|
-
* @param {Object} data
|
|
3424
|
-
*/
|
|
3425
|
-
BasicInterface.prototype.create = function (data) {
|
|
3426
|
-
var _a;
|
|
3427
|
-
var decoded = {};
|
|
3428
|
-
if (((_a = this.keys) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
3429
|
-
var _loop_1 = function (key) {
|
|
3430
|
-
var _c;
|
|
3431
|
-
Object.defineProperties(decoded, (_c = {},
|
|
3432
|
-
_c[key] = {
|
|
3433
|
-
enumerable: true,
|
|
3434
|
-
configurable: true,
|
|
3435
|
-
set: function (value) { return data[key]; },
|
|
3436
|
-
get: function () { return data[key]; }
|
|
3437
|
-
},
|
|
3438
|
-
_c));
|
|
3439
|
-
};
|
|
3440
|
-
for (var _i = 0, _b = this.keys; _i < _b.length; _i++) {
|
|
3441
|
-
var key = _b[_i];
|
|
3442
|
-
_loop_1(key);
|
|
3443
|
-
}
|
|
3444
|
-
this.decoded = decoded;
|
|
3445
|
-
return this.encode();
|
|
3446
|
-
}
|
|
3447
|
-
};
|
|
3448
|
-
return BasicInterface;
|
|
3449
|
-
}());
|
|
3450
|
-
|
|
3451
|
-
/*!
|
|
3452
|
-
* hash-wasm (https://www.npmjs.com/package/hash-wasm)
|
|
3453
|
-
* (c) Dani Biro
|
|
3454
|
-
* @license MIT
|
|
3455
|
-
*/
|
|
3456
|
-
|
|
3457
|
-
/*! *****************************************************************************
|
|
3458
|
-
Copyright (c) Microsoft Corporation.
|
|
3459
|
-
|
|
3460
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
3461
|
-
purpose with or without fee is hereby granted.
|
|
3462
|
-
|
|
3463
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
3464
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
3465
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
3466
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
3467
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
3468
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
3469
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
3470
|
-
***************************************************************************** */
|
|
3471
|
-
|
|
3472
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
3473
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3474
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3475
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3476
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3477
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3478
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3479
|
-
});
|
|
3480
|
-
}
|
|
3481
|
-
|
|
3482
|
-
class Mutex {
|
|
3483
|
-
constructor() {
|
|
3484
|
-
this.mutex = Promise.resolve();
|
|
3485
|
-
}
|
|
3486
|
-
lock() {
|
|
3487
|
-
let begin = () => { };
|
|
3488
|
-
this.mutex = this.mutex.then(() => new Promise(begin));
|
|
3489
|
-
return new Promise((res) => {
|
|
3490
|
-
begin = res;
|
|
3491
|
-
});
|
|
3492
|
-
}
|
|
3493
|
-
dispatch(fn) {
|
|
3494
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3495
|
-
const unlock = yield this.lock();
|
|
3496
|
-
try {
|
|
3497
|
-
return yield Promise.resolve(fn());
|
|
3498
|
-
}
|
|
3499
|
-
finally {
|
|
3500
|
-
unlock();
|
|
3501
|
-
}
|
|
3502
|
-
});
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
|
|
3506
|
-
/* eslint-disable import/prefer-default-export */
|
|
3507
|
-
/* eslint-disable no-bitwise */
|
|
3508
|
-
var _a;
|
|
3509
|
-
function getGlobal() {
|
|
3510
|
-
if (typeof globalThis !== 'undefined')
|
|
3511
|
-
return globalThis;
|
|
3512
|
-
// eslint-disable-next-line no-restricted-globals
|
|
3513
|
-
if (typeof self !== 'undefined')
|
|
3514
|
-
return self;
|
|
3515
|
-
if (typeof window !== 'undefined')
|
|
3516
|
-
return window;
|
|
3517
|
-
return global;
|
|
3518
|
-
}
|
|
3519
|
-
const globalObject = getGlobal();
|
|
3520
|
-
const nodeBuffer = (_a = globalObject.Buffer) !== null && _a !== void 0 ? _a : null;
|
|
3521
|
-
const textEncoder = globalObject.TextEncoder ? new globalObject.TextEncoder() : null;
|
|
3522
|
-
function hexCharCodesToInt(a, b) {
|
|
3523
|
-
return (((a & 0xF) + ((a >> 6) | ((a >> 3) & 0x8))) << 4) | ((b & 0xF) + ((b >> 6) | ((b >> 3) & 0x8)));
|
|
3524
|
-
}
|
|
3525
|
-
function writeHexToUInt8(buf, str) {
|
|
3526
|
-
const size = str.length >> 1;
|
|
3527
|
-
for (let i = 0; i < size; i++) {
|
|
3528
|
-
const index = i << 1;
|
|
3529
|
-
buf[i] = hexCharCodesToInt(str.charCodeAt(index), str.charCodeAt(index + 1));
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
function hexStringEqualsUInt8(str, buf) {
|
|
3533
|
-
if (str.length !== buf.length * 2) {
|
|
3534
|
-
return false;
|
|
3535
|
-
}
|
|
3536
|
-
for (let i = 0; i < buf.length; i++) {
|
|
3537
|
-
const strIndex = i << 1;
|
|
3538
|
-
if (buf[i] !== hexCharCodesToInt(str.charCodeAt(strIndex), str.charCodeAt(strIndex + 1))) {
|
|
3539
|
-
return false;
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
return true;
|
|
3543
|
-
}
|
|
3544
|
-
const alpha = 'a'.charCodeAt(0) - 10;
|
|
3545
|
-
const digit = '0'.charCodeAt(0);
|
|
3546
|
-
function getDigestHex(tmpBuffer, input, hashLength) {
|
|
3547
|
-
let p = 0;
|
|
3548
|
-
/* eslint-disable no-plusplus */
|
|
3549
|
-
for (let i = 0; i < hashLength; i++) {
|
|
3550
|
-
let nibble = input[i] >>> 4;
|
|
3551
|
-
tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
|
|
3552
|
-
nibble = input[i] & 0xF;
|
|
3553
|
-
tmpBuffer[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
|
|
3554
|
-
}
|
|
3555
|
-
/* eslint-enable no-plusplus */
|
|
3556
|
-
return String.fromCharCode.apply(null, tmpBuffer);
|
|
3557
|
-
}
|
|
3558
|
-
const getUInt8Buffer = nodeBuffer !== null
|
|
3559
|
-
? (data) => {
|
|
3560
|
-
if (typeof data === 'string') {
|
|
3561
|
-
const buf = nodeBuffer.from(data, 'utf8');
|
|
3562
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
|
|
3563
|
-
}
|
|
3564
|
-
if (nodeBuffer.isBuffer(data)) {
|
|
3565
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.length);
|
|
3566
|
-
}
|
|
3567
|
-
if (ArrayBuffer.isView(data)) {
|
|
3568
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
3569
|
-
}
|
|
3570
|
-
throw new Error('Invalid data type!');
|
|
3571
|
-
}
|
|
3572
|
-
: (data) => {
|
|
3573
|
-
if (typeof data === 'string') {
|
|
3574
|
-
return textEncoder.encode(data);
|
|
3575
|
-
}
|
|
3576
|
-
if (ArrayBuffer.isView(data)) {
|
|
3577
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
3578
|
-
}
|
|
3579
|
-
throw new Error('Invalid data type!');
|
|
3580
|
-
};
|
|
3581
|
-
const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3582
|
-
const base64Lookup = new Uint8Array(256);
|
|
3583
|
-
for (let i = 0; i < base64Chars.length; i++) {
|
|
3584
|
-
base64Lookup[base64Chars.charCodeAt(i)] = i;
|
|
3585
|
-
}
|
|
3586
|
-
function getDecodeBase64Length(data) {
|
|
3587
|
-
let bufferLength = Math.floor(data.length * 0.75);
|
|
3588
|
-
const len = data.length;
|
|
3589
|
-
if (data[len - 1] === '=') {
|
|
3590
|
-
bufferLength -= 1;
|
|
3591
|
-
if (data[len - 2] === '=') {
|
|
3592
|
-
bufferLength -= 1;
|
|
3593
|
-
}
|
|
3594
|
-
}
|
|
3595
|
-
return bufferLength;
|
|
3596
|
-
}
|
|
3597
|
-
function decodeBase64(data) {
|
|
3598
|
-
const bufferLength = getDecodeBase64Length(data);
|
|
3599
|
-
const len = data.length;
|
|
3600
|
-
const bytes = new Uint8Array(bufferLength);
|
|
3601
|
-
let p = 0;
|
|
3602
|
-
for (let i = 0; i < len; i += 4) {
|
|
3603
|
-
const encoded1 = base64Lookup[data.charCodeAt(i)];
|
|
3604
|
-
const encoded2 = base64Lookup[data.charCodeAt(i + 1)];
|
|
3605
|
-
const encoded3 = base64Lookup[data.charCodeAt(i + 2)];
|
|
3606
|
-
const encoded4 = base64Lookup[data.charCodeAt(i + 3)];
|
|
3607
|
-
bytes[p] = (encoded1 << 2) | (encoded2 >> 4);
|
|
3608
|
-
p += 1;
|
|
3609
|
-
bytes[p] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
3610
|
-
p += 1;
|
|
3611
|
-
bytes[p] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
3612
|
-
p += 1;
|
|
3613
|
-
}
|
|
3614
|
-
return bytes;
|
|
3615
|
-
}
|
|
3616
|
-
|
|
3617
|
-
const MAX_HEAP = 16 * 1024;
|
|
3618
|
-
const WASM_FUNC_HASH_LENGTH = 4;
|
|
3619
|
-
const wasmMutex = new Mutex();
|
|
3620
|
-
const wasmModuleCache = new Map();
|
|
3621
|
-
function WASMInterface(binary, hashLength) {
|
|
3622
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3623
|
-
let wasmInstance = null;
|
|
3624
|
-
let memoryView = null;
|
|
3625
|
-
let initialized = false;
|
|
3626
|
-
if (typeof WebAssembly === 'undefined') {
|
|
3627
|
-
throw new Error('WebAssembly is not supported in this environment!');
|
|
3628
|
-
}
|
|
3629
|
-
const writeMemory = (data, offset = 0) => {
|
|
3630
|
-
memoryView.set(data, offset);
|
|
3631
|
-
};
|
|
3632
|
-
const getMemory = () => memoryView;
|
|
3633
|
-
const getExports = () => wasmInstance.exports;
|
|
3634
|
-
const setMemorySize = (totalSize) => {
|
|
3635
|
-
wasmInstance.exports.Hash_SetMemorySize(totalSize);
|
|
3636
|
-
const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
|
|
3637
|
-
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
3638
|
-
memoryView = new Uint8Array(memoryBuffer, arrayOffset, totalSize);
|
|
3639
|
-
};
|
|
3640
|
-
const getStateSize = () => {
|
|
3641
|
-
const view = new DataView(wasmInstance.exports.memory.buffer);
|
|
3642
|
-
const stateSize = view.getUint32(wasmInstance.exports.STATE_SIZE, true);
|
|
3643
|
-
return stateSize;
|
|
3644
|
-
};
|
|
3645
|
-
const loadWASMPromise = wasmMutex.dispatch(() => __awaiter(this, void 0, void 0, function* () {
|
|
3646
|
-
if (!wasmModuleCache.has(binary.name)) {
|
|
3647
|
-
const asm = decodeBase64(binary.data);
|
|
3648
|
-
const promise = WebAssembly.compile(asm);
|
|
3649
|
-
wasmModuleCache.set(binary.name, promise);
|
|
3650
|
-
}
|
|
3651
|
-
const module = yield wasmModuleCache.get(binary.name);
|
|
3652
|
-
wasmInstance = yield WebAssembly.instantiate(module, {
|
|
3653
|
-
// env: {
|
|
3654
|
-
// emscripten_memcpy_big: (dest, src, num) => {
|
|
3655
|
-
// const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
3656
|
-
// const memView = new Uint8Array(memoryBuffer, 0);
|
|
3657
|
-
// memView.set(memView.subarray(src, src + num), dest);
|
|
3658
|
-
// },
|
|
3659
|
-
// print_memory: (offset, len) => {
|
|
3660
|
-
// const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
3661
|
-
// const memView = new Uint8Array(memoryBuffer, 0);
|
|
3662
|
-
// console.log('print_int32', memView.subarray(offset, offset + len));
|
|
3663
|
-
// },
|
|
3664
|
-
// },
|
|
3665
|
-
});
|
|
3666
|
-
// wasmInstance.exports._start();
|
|
3667
|
-
}));
|
|
3668
|
-
const setupInterface = () => __awaiter(this, void 0, void 0, function* () {
|
|
3669
|
-
if (!wasmInstance) {
|
|
3670
|
-
yield loadWASMPromise;
|
|
3671
|
-
}
|
|
3672
|
-
const arrayOffset = wasmInstance.exports.Hash_GetBuffer();
|
|
3673
|
-
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
3674
|
-
memoryView = new Uint8Array(memoryBuffer, arrayOffset, MAX_HEAP);
|
|
3675
|
-
});
|
|
3676
|
-
const init = (bits = null) => {
|
|
3677
|
-
initialized = true;
|
|
3678
|
-
wasmInstance.exports.Hash_Init(bits);
|
|
3679
|
-
};
|
|
3680
|
-
const updateUInt8Array = (data) => {
|
|
3681
|
-
let read = 0;
|
|
3682
|
-
while (read < data.length) {
|
|
3683
|
-
const chunk = data.subarray(read, read + MAX_HEAP);
|
|
3684
|
-
read += chunk.length;
|
|
3685
|
-
memoryView.set(chunk);
|
|
3686
|
-
wasmInstance.exports.Hash_Update(chunk.length);
|
|
3687
|
-
}
|
|
3688
|
-
};
|
|
3689
|
-
const update = (data) => {
|
|
3690
|
-
if (!initialized) {
|
|
3691
|
-
throw new Error('update() called before init()');
|
|
3692
|
-
}
|
|
3693
|
-
const Uint8Buffer = getUInt8Buffer(data);
|
|
3694
|
-
updateUInt8Array(Uint8Buffer);
|
|
3695
|
-
};
|
|
3696
|
-
const digestChars = new Uint8Array(hashLength * 2);
|
|
3697
|
-
const digest = (outputType, padding = null) => {
|
|
3698
|
-
if (!initialized) {
|
|
3699
|
-
throw new Error('digest() called before init()');
|
|
3700
|
-
}
|
|
3701
|
-
initialized = false;
|
|
3702
|
-
wasmInstance.exports.Hash_Final(padding);
|
|
3703
|
-
if (outputType === 'binary') {
|
|
3704
|
-
// the data is copied to allow GC of the original memory object
|
|
3705
|
-
return memoryView.slice(0, hashLength);
|
|
3706
|
-
}
|
|
3707
|
-
return getDigestHex(digestChars, memoryView, hashLength);
|
|
3708
|
-
};
|
|
3709
|
-
const save = () => {
|
|
3710
|
-
if (!initialized) {
|
|
3711
|
-
throw new Error('save() can only be called after init() and before digest()');
|
|
3712
|
-
}
|
|
3713
|
-
const stateOffset = wasmInstance.exports.Hash_GetState();
|
|
3714
|
-
const stateLength = getStateSize();
|
|
3715
|
-
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
3716
|
-
const internalState = new Uint8Array(memoryBuffer, stateOffset, stateLength);
|
|
3717
|
-
// prefix is 4 bytes from SHA1 hash of the WASM binary
|
|
3718
|
-
// it is used to detect incompatible internal states between different versions of hash-wasm
|
|
3719
|
-
const prefixedState = new Uint8Array(WASM_FUNC_HASH_LENGTH + stateLength);
|
|
3720
|
-
writeHexToUInt8(prefixedState, binary.hash);
|
|
3721
|
-
prefixedState.set(internalState, WASM_FUNC_HASH_LENGTH);
|
|
3722
|
-
return prefixedState;
|
|
3723
|
-
};
|
|
3724
|
-
const load = (state) => {
|
|
3725
|
-
if (!(state instanceof Uint8Array)) {
|
|
3726
|
-
throw new Error('load() expects an Uint8Array generated by save()');
|
|
3727
|
-
}
|
|
3728
|
-
const stateOffset = wasmInstance.exports.Hash_GetState();
|
|
3729
|
-
const stateLength = getStateSize();
|
|
3730
|
-
const overallLength = WASM_FUNC_HASH_LENGTH + stateLength;
|
|
3731
|
-
const memoryBuffer = wasmInstance.exports.memory.buffer;
|
|
3732
|
-
if (state.length !== overallLength) {
|
|
3733
|
-
throw new Error(`Bad state length (expected ${overallLength} bytes, got ${state.length})`);
|
|
3734
|
-
}
|
|
3735
|
-
if (!hexStringEqualsUInt8(binary.hash, state.subarray(0, WASM_FUNC_HASH_LENGTH))) {
|
|
3736
|
-
throw new Error('This state was written by an incompatible hash implementation');
|
|
3737
|
-
}
|
|
3738
|
-
const internalState = state.subarray(WASM_FUNC_HASH_LENGTH);
|
|
3739
|
-
new Uint8Array(memoryBuffer, stateOffset, stateLength).set(internalState);
|
|
3740
|
-
initialized = true;
|
|
3741
|
-
};
|
|
3742
|
-
const isDataShort = (data) => {
|
|
3743
|
-
if (typeof data === 'string') {
|
|
3744
|
-
// worst case is 4 bytes / char
|
|
3745
|
-
return data.length < MAX_HEAP / 4;
|
|
3746
|
-
}
|
|
3747
|
-
return data.byteLength < MAX_HEAP;
|
|
3748
|
-
};
|
|
3749
|
-
let canSimplify = isDataShort;
|
|
3750
|
-
switch (binary.name) {
|
|
3751
|
-
case 'argon2':
|
|
3752
|
-
case 'scrypt':
|
|
3753
|
-
canSimplify = () => true;
|
|
3754
|
-
break;
|
|
3755
|
-
case 'blake2b':
|
|
3756
|
-
case 'blake2s':
|
|
3757
|
-
// if there is a key at blake2 then cannot simplify
|
|
3758
|
-
canSimplify = (data, initParam) => initParam <= 512 && isDataShort(data);
|
|
3759
|
-
break;
|
|
3760
|
-
case 'blake3':
|
|
3761
|
-
// if there is a key at blake3 then cannot simplify
|
|
3762
|
-
canSimplify = (data, initParam) => initParam === 0 && isDataShort(data);
|
|
3763
|
-
break;
|
|
3764
|
-
case 'xxhash64': // cannot simplify
|
|
3765
|
-
case 'xxhash3':
|
|
3766
|
-
case 'xxhash128':
|
|
3767
|
-
canSimplify = () => false;
|
|
3768
|
-
break;
|
|
3769
|
-
}
|
|
3770
|
-
// shorthand for (init + update + digest) for better performance
|
|
3771
|
-
const calculate = (data, initParam = null, digestParam = null) => {
|
|
3772
|
-
if (!canSimplify(data, initParam)) {
|
|
3773
|
-
init(initParam);
|
|
3774
|
-
update(data);
|
|
3775
|
-
return digest('hex', digestParam);
|
|
3776
|
-
}
|
|
3777
|
-
const buffer = getUInt8Buffer(data);
|
|
3778
|
-
memoryView.set(buffer);
|
|
3779
|
-
wasmInstance.exports.Hash_Calculate(buffer.length, initParam, digestParam);
|
|
3780
|
-
return getDigestHex(digestChars, memoryView, hashLength);
|
|
3781
|
-
};
|
|
3782
|
-
yield setupInterface();
|
|
3783
|
-
return {
|
|
3784
|
-
getMemory,
|
|
3785
|
-
writeMemory,
|
|
3786
|
-
getExports,
|
|
3787
|
-
setMemorySize,
|
|
3788
|
-
init,
|
|
3789
|
-
update,
|
|
3790
|
-
digest,
|
|
3791
|
-
save,
|
|
3792
|
-
load,
|
|
3793
|
-
calculate,
|
|
3794
|
-
hashLength,
|
|
3795
|
-
};
|
|
3796
|
-
});
|
|
3797
|
-
}
|
|
3798
|
-
|
|
3799
|
-
new Mutex();
|
|
3800
|
-
|
|
3801
|
-
new Mutex();
|
|
3802
|
-
|
|
3803
|
-
new Mutex();
|
|
3804
|
-
|
|
3805
|
-
new Mutex();
|
|
3806
|
-
|
|
3807
|
-
new Mutex();
|
|
3808
|
-
|
|
3809
|
-
new Mutex();
|
|
3810
|
-
|
|
3811
|
-
new Mutex();
|
|
3812
|
-
|
|
3813
|
-
new Mutex();
|
|
3814
|
-
|
|
3815
|
-
new Mutex();
|
|
3816
|
-
|
|
3817
|
-
var name$b = "sha3";
|
|
3818
|
-
var data$b = "AGFzbQEAAAABDwNgAAF/YAF/AGADf39/AAMIBwABAQIBAAIEBQFwAQEBBQQBAQICBg4CfwFBkI0FC38AQcAJCwdwCAZtZW1vcnkCAA5IYXNoX0dldEJ1ZmZlcgAACUhhc2hfSW5pdAABC0hhc2hfVXBkYXRlAAIKSGFzaF9GaW5hbAAEDUhhc2hfR2V0U3RhdGUABQ5IYXNoX0NhbGN1bGF0ZQAGClNUQVRFX1NJWkUDAQrLFwcFAEGACgvXAwBBAEIANwOAjQFBAEIANwP4jAFBAEIANwPwjAFBAEIANwPojAFBAEIANwPgjAFBAEIANwPYjAFBAEIANwPQjAFBAEIANwPIjAFBAEIANwPAjAFBAEIANwO4jAFBAEIANwOwjAFBAEIANwOojAFBAEIANwOgjAFBAEIANwOYjAFBAEIANwOQjAFBAEIANwOIjAFBAEIANwOAjAFBAEIANwP4iwFBAEIANwPwiwFBAEIANwPoiwFBAEIANwPgiwFBAEIANwPYiwFBAEIANwPQiwFBAEIANwPIiwFBAEIANwPAiwFBAEIANwO4iwFBAEIANwOwiwFBAEIANwOoiwFBAEIANwOgiwFBAEIANwOYiwFBAEIANwOQiwFBAEIANwOIiwFBAEIANwOAiwFBAEIANwP4igFBAEIANwPwigFBAEIANwPoigFBAEIANwPgigFBAEIANwPYigFBAEIANwPQigFBAEIANwPIigFBAEIANwPAigFBAEIANwO4igFBAEIANwOwigFBAEIANwOoigFBAEIANwOgigFBAEIANwOYigFBAEIANwOQigFBAEIANwOIigFBAEIANwOAigFBAEHADCAAQQF0a0EDdjYCjI0BQQBBADYCiI0BC/8BAQZ/AkBBACgCiI0BIgFBAEgNAEEAIAEgAGpBACgCjI0BIgJwNgKIjQECQAJAIAENAEGACiEBDAELAkAgACACIAFrIgMgAyAASyIEGyIFRQ0AIAFByIsBaiEGQQAhAQNAIAYgAWogAUGACmotAAA6AAAgBSABQQFqIgFHDQALCyAEDQFBgIoBQciLASACEAMgACADayEAIANBgApqIQELAkAgACACSQ0AA0BBgIoBIAEgAhADIAEgAmohASAAIAJrIgAgAk8NAAsLIABFDQBBACECQQAhBQNAIAJByIsBaiABIAJqLQAAOgAAIAAgBUEBaiIFQf8BcSICSw0ACwsLyAoBKH4gACAAKQMAIAEpAwCFIgM3AwAgACAAKQMIIAEpAwiFIgQ3AwggACAAKQMQIAEpAxCFIgU3AxAgACAAKQMYIAEpAxiFIgY3AxggACAAKQMgIAEpAyCFIgc3AyAgACAAKQMoIAEpAyiFIgg3AyggACAAKQMwIAEpAzCFIgk3AzAgACAAKQM4IAEpAziFIgo3AzggACAAKQNAIAEpA0CFIgs3A0ACQAJAIAJByABLDQAgACkDUCEMIAApA2AhDSAAKQNIIQ4gACkDWCEPDAELIAAgACkDSCABKQNIhSIONwNIIAAgACkDUCABKQNQhSIMNwNQIAAgACkDWCABKQNYhSIPNwNYIAAgACkDYCABKQNghSINNwNgIAJB6QBJDQAgACAAKQNoIAEpA2iFNwNoIAAgACkDcCABKQNwhTcDcCAAIAApA3ggASkDeIU3A3ggACAAKQOAASABKQOAAYU3A4ABIAJBiQFJDQAgACAAKQOIASABKQOIAYU3A4gBCyAAKQO4ASEQIAApA5ABIREgACkDaCESIAApA6ABIRMgACkDeCEUIAApA7ABIRUgACkDiAEhFiAAKQPAASEXIAApA5gBIRggACkDcCEZIAApA6gBIRogACkDgAEhG0HAfiEBA0AgFCAThSAIIAyFIAOFhSIcIBYgFYUgCiANhSAFhYUiHUIBiYUiHiAahSEfIBsgGoUgD4UgCYUgBIUiICARIBCFIAsgEoUgBoWFIhpCAYmFIiEgBYUhIiAYIBeFIA4gGYUgB4WFIiMgIEIBiYUiICAUhUIpiSIkIBogHEIBiYUiBSAZhUIniSIcQn+FgyAdICNCAYmFIhQgC4VCN4kiHYUhGiAHIAWFISUgICAIhSEmIBQgEIVCOIkiIyAhIBaFQg+JIidCf4WDIB4gD4VCCokiGYUhFiAhIAqFQgaJIiggBSAYhUIIiSIYIBQgEoVCGYkiKUJ/hYOFIQ8gBCAehSESICEgFYVCPYkiCiAFIA6FQhSJIhAgFCAGhUIciSIEQn+Fg4UhDiAEIApCf4WDIB4gG4VCLYkiKoUhCyAgIAyFQgOJIgwgEEJ/hYMgBIUhCCAeIAmFQiyJIh4gICADhSIDQn+FgyAFIBeFQg6JIgWFIQcgAyAFQn+FgyAUIBGFQhWJIhSFIQYgISANhUIriSIhIAUgFEJ/hYOFIQUgFCAhQn+FgyAehSEEIB9CAokiFyAkQn+FgyAchSEVIBkgJkIkiSIfQn+FgyAlQhuJIiWFIRQgEkIBiSINICAgE4VCEokiIEJ/hYMgGIUhEiAqIAxCf4WDIBCFIQkgJCAiQj6JIiIgF0J/hYOFIRAgHyAnIBlCf4WDhSEbICAgKCANQn+Fg4UhGSAMIAogKkJ/hYOFIQogISAeQn+FgyABQcAJaikDAIUgA4UhAyAnICUgI0J/hYOFIh4hESAiIBwgHUJ/hYOFIiEhEyApIChCf4WDIA2FIiQhDCAgIBhCf4WDICmFIiAhDSAdICJCf4WDIBeFIhwhFyAfICVCf4WDICOFIh0hGCABQQhqIgENAAsgACAaNwOoASAAIBs3A4ABIAAgDzcDWCAAIAk3AzAgACAENwMIIAAgHDcDwAEgACAdNwOYASAAIBk3A3AgACAONwNIIAAgBzcDICAAIBU3A7ABIAAgFjcDiAEgACAgNwNgIAAgCjcDOCAAIAU3AxAgACAhNwOgASAAIBQ3A3ggACAkNwNQIAAgCDcDKCAAIAM3AwAgACAQNwO4ASAAIB43A5ABIAAgEjcDaCAAIAs3A0AgACAGNwMYC94BAQV/QeQAQQAoAoyNASIBQQF2ayECAkBBACgCiI0BIgNBAEgNACABIQQCQCABIANGDQAgA0HIiwFqIQVBACEDA0AgBSADakEAOgAAIANBAWoiAyABQQAoAoiNASIEa0kNAAsLIARByIsBaiIDIAMtAAAgAHI6AAAgAUHHiwFqIgMgAy0AAEGAAXI6AABBgIoBQciLASABEANBAEGAgICAeDYCiI0BCwJAIAJBAnYiAUUNAEEAIQMDQCADQYAKaiADQYCKAWooAgA2AgAgA0EEaiEDIAFBf2oiAQ0ACwsLBgBBgIoBC7cFAQN/QQBCADcDgI0BQQBCADcD+IwBQQBCADcD8IwBQQBCADcD6IwBQQBCADcD4IwBQQBCADcD2IwBQQBCADcD0IwBQQBCADcDyIwBQQBCADcDwIwBQQBCADcDuIwBQQBCADcDsIwBQQBCADcDqIwBQQBCADcDoIwBQQBCADcDmIwBQQBCADcDkIwBQQBCADcDiIwBQQBCADcDgIwBQQBCADcD+IsBQQBCADcD8IsBQQBCADcD6IsBQQBCADcD4IsBQQBCADcD2IsBQQBCADcD0IsBQQBCADcDyIsBQQBCADcDwIsBQQBCADcDuIsBQQBCADcDsIsBQQBCADcDqIsBQQBCADcDoIsBQQBCADcDmIsBQQBCADcDkIsBQQBCADcDiIsBQQBCADcDgIsBQQBCADcD+IoBQQBCADcD8IoBQQBCADcD6IoBQQBCADcD4IoBQQBCADcD2IoBQQBCADcD0IoBQQBCADcDyIoBQQBCADcDwIoBQQBCADcDuIoBQQBCADcDsIoBQQBCADcDqIoBQQBCADcDoIoBQQBCADcDmIoBQQBCADcDkIoBQQBCADcDiIoBQQBCADcDgIoBQQBBwAwgAUEBdGtBA3Y2AoyNAUEAQQA2AoiNASAAEAJB5ABBACgCjI0BIgFBAXZrIQMCQEEAKAKIjQEiAEEASA0AIAEhBAJAIAEgAEYNACAAQciLAWohBUEAIQADQCAFIABqQQA6AAAgAEEBaiIAIAFBACgCiI0BIgRrSQ0ACwsgBEHIiwFqIgAgAC0AACACcjoAACABQceLAWoiACAALQAAQYABcjoAAEGAigFByIsBIAEQA0EAQYCAgIB4NgKIjQELAkAgA0ECdiIBRQ0AQQAhAANAIABBgApqIABBgIoBaigCADYCACAAQQRqIQAgAUF/aiIBDQALCwsLzAEBAEGACAvEAQEAAAAAAAAAgoAAAAAAAACKgAAAAAAAgACAAIAAAACAi4AAAAAAAAABAACAAAAAAIGAAIAAAACACYAAAAAAAICKAAAAAAAAAIgAAAAAAAAACYAAgAAAAAAKAACAAAAAAIuAAIAAAAAAiwAAAAAAAICJgAAAAAAAgAOAAAAAAACAAoAAAAAAAICAAAAAAAAAgAqAAAAAAAAACgAAgAAAAICBgACAAAAAgICAAAAAAACAAQAAgAAAAAAIgACAAAAAgJABAAA=";
|
|
3819
|
-
var hash$b = "ec266d91";
|
|
3820
|
-
var wasmJson$b = {
|
|
3821
|
-
name: name$b,
|
|
3822
|
-
data: data$b,
|
|
3823
|
-
hash: hash$b
|
|
3824
|
-
};
|
|
3825
|
-
|
|
3826
|
-
new Mutex();
|
|
3827
|
-
|
|
3828
|
-
new Mutex();
|
|
3829
|
-
function validateBits(bits) {
|
|
3830
|
-
if (![224, 256, 384, 512].includes(bits)) {
|
|
3831
|
-
return new Error('Invalid variant! Valid values: 224, 256, 384, 512');
|
|
3832
|
-
}
|
|
3833
|
-
return null;
|
|
3834
|
-
}
|
|
3835
|
-
/**
|
|
3836
|
-
* Creates a new Keccak hash instance
|
|
3837
|
-
* @param bits Number of output bits. Valid values: 224, 256, 384, 512
|
|
3838
|
-
*/
|
|
3839
|
-
function createKeccak(bits = 512) {
|
|
3840
|
-
if (validateBits(bits)) {
|
|
3841
|
-
return Promise.reject(validateBits(bits));
|
|
3842
|
-
}
|
|
3843
|
-
const outputSize = bits / 8;
|
|
3844
|
-
return WASMInterface(wasmJson$b, outputSize).then((wasm) => {
|
|
3845
|
-
wasm.init(bits);
|
|
3846
|
-
const obj = {
|
|
3847
|
-
init: () => { wasm.init(bits); return obj; },
|
|
3848
|
-
update: (data) => { wasm.update(data); return obj; },
|
|
3849
|
-
digest: (outputType) => wasm.digest(outputType, 0x01),
|
|
3850
|
-
save: () => wasm.save(),
|
|
3851
|
-
load: (data) => { wasm.load(data); return obj; },
|
|
3852
|
-
blockSize: 200 - 2 * outputSize,
|
|
3853
|
-
digestSize: outputSize,
|
|
3854
|
-
};
|
|
3855
|
-
return obj;
|
|
3856
|
-
});
|
|
3857
|
-
}
|
|
3858
|
-
|
|
3859
|
-
new Mutex();
|
|
3860
|
-
|
|
3861
|
-
new Mutex();
|
|
3862
|
-
|
|
3863
|
-
new Mutex();
|
|
3864
|
-
|
|
3865
|
-
new Mutex();
|
|
3866
|
-
|
|
3867
|
-
new Mutex();
|
|
3868
|
-
|
|
3869
|
-
new Mutex();
|
|
3870
|
-
|
|
3871
|
-
new Mutex();
|
|
3872
|
-
|
|
3873
|
-
new Mutex();
|
|
3874
|
-
|
|
3875
|
-
new Mutex();
|
|
3876
|
-
|
|
3877
|
-
new Mutex();
|
|
3878
|
-
|
|
3879
|
-
new Mutex();
|
|
3880
|
-
|
|
3881
|
-
var encode_1 = encode;
|
|
3882
|
-
|
|
3883
|
-
var MSB$1 = 0x80
|
|
3884
|
-
, REST$1 = 0x7F
|
|
3885
|
-
, MSBALL = ~REST$1
|
|
3886
|
-
, INT = Math.pow(2, 31);
|
|
3887
|
-
|
|
3888
|
-
function encode(num, out, offset) {
|
|
3889
|
-
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
3890
|
-
encode.bytes = 0;
|
|
3891
|
-
throw new RangeError('Could not encode varint')
|
|
3892
|
-
}
|
|
3893
|
-
out = out || [];
|
|
3894
|
-
offset = offset || 0;
|
|
3895
|
-
var oldOffset = offset;
|
|
3896
|
-
|
|
3897
|
-
while(num >= INT) {
|
|
3898
|
-
out[offset++] = (num & 0xFF) | MSB$1;
|
|
3899
|
-
num /= 128;
|
|
3900
|
-
}
|
|
3901
|
-
while(num & MSBALL) {
|
|
3902
|
-
out[offset++] = (num & 0xFF) | MSB$1;
|
|
3903
|
-
num >>>= 7;
|
|
3904
|
-
}
|
|
3905
|
-
out[offset] = num | 0;
|
|
3906
|
-
|
|
3907
|
-
encode.bytes = offset - oldOffset + 1;
|
|
3908
|
-
|
|
3909
|
-
return out
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
var decode = read;
|
|
3913
|
-
|
|
3914
|
-
var MSB = 0x80
|
|
3915
|
-
, REST = 0x7F;
|
|
3916
|
-
|
|
3917
|
-
function read(buf, offset) {
|
|
3918
|
-
var res = 0
|
|
3919
|
-
, offset = offset || 0
|
|
3920
|
-
, shift = 0
|
|
3921
|
-
, counter = offset
|
|
3922
|
-
, b
|
|
3923
|
-
, l = buf.length;
|
|
3924
|
-
|
|
3925
|
-
do {
|
|
3926
|
-
if (counter >= l || shift > 49) {
|
|
3927
|
-
read.bytes = 0;
|
|
3928
|
-
throw new RangeError('Could not decode varint')
|
|
3929
|
-
}
|
|
3930
|
-
b = buf[counter++];
|
|
3931
|
-
res += shift < 28
|
|
3932
|
-
? (b & REST) << shift
|
|
3933
|
-
: (b & REST) * Math.pow(2, shift);
|
|
3934
|
-
shift += 7;
|
|
3935
|
-
} while (b >= MSB)
|
|
3936
|
-
|
|
3937
|
-
read.bytes = counter - offset;
|
|
3938
|
-
|
|
3939
|
-
return res
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
var N1 = Math.pow(2, 7);
|
|
3943
|
-
var N2 = Math.pow(2, 14);
|
|
3944
|
-
var N3 = Math.pow(2, 21);
|
|
3945
|
-
var N4 = Math.pow(2, 28);
|
|
3946
|
-
var N5 = Math.pow(2, 35);
|
|
3947
|
-
var N6 = Math.pow(2, 42);
|
|
3948
|
-
var N7 = Math.pow(2, 49);
|
|
3949
|
-
var N8 = Math.pow(2, 56);
|
|
3950
|
-
var N9 = Math.pow(2, 63);
|
|
3951
|
-
|
|
3952
|
-
var dist_length = function (value) {
|
|
3953
|
-
return (
|
|
3954
|
-
value < N1 ? 1
|
|
3955
|
-
: value < N2 ? 2
|
|
3956
|
-
: value < N3 ? 3
|
|
3957
|
-
: value < N4 ? 4
|
|
3958
|
-
: value < N5 ? 5
|
|
3959
|
-
: value < N6 ? 6
|
|
3960
|
-
: value < N7 ? 7
|
|
3961
|
-
: value < N8 ? 8
|
|
3962
|
-
: value < N9 ? 9
|
|
3963
|
-
: 10
|
|
3964
|
-
)
|
|
3965
|
-
};
|
|
3966
|
-
|
|
3967
|
-
var varint = {
|
|
3968
|
-
encode: encode_1
|
|
3969
|
-
, decode: decode
|
|
3970
|
-
, encodingLength: dist_length
|
|
3971
|
-
};
|
|
3972
|
-
|
|
3973
|
-
var codecs = {
|
|
3974
|
-
// just a hash
|
|
3975
|
-
'disco-hash': {
|
|
3976
|
-
codec: parseInt('30', 16),
|
|
3977
|
-
hashAlg: 'dbl-keccak-256', // ,
|
|
3978
|
-
// testnet: 'olivia'
|
|
3979
|
-
},
|
|
3980
|
-
'peernet-peer-response': {
|
|
3981
|
-
codec: parseInt('707072', 16),
|
|
3982
|
-
hashAlg: 'keccak-256',
|
|
3983
|
-
},
|
|
3984
|
-
'peernet-peer': {
|
|
3985
|
-
codec: parseInt('7070', 16),
|
|
3986
|
-
hashAlg: 'keccak-256',
|
|
3987
|
-
},
|
|
3988
|
-
'peernet-dht': {
|
|
3989
|
-
codec: parseInt('706468', 16),
|
|
3990
|
-
hashAlg: 'keccak-256',
|
|
3991
|
-
},
|
|
3992
|
-
'peernet-dht-response': {
|
|
3993
|
-
codec: parseInt('706472', 16),
|
|
3994
|
-
hashAlg: 'keccak-256',
|
|
3995
|
-
},
|
|
3996
|
-
// data
|
|
3997
|
-
'peernet-data': {
|
|
3998
|
-
codec: parseInt('706461', 16),
|
|
3999
|
-
hashAlg: 'keccak-256',
|
|
4000
|
-
},
|
|
4001
|
-
'peernet-data-response': {
|
|
4002
|
-
codec: parseInt('70646172', 16),
|
|
4003
|
-
hashAlg: 'keccak-256',
|
|
4004
|
-
},
|
|
4005
|
-
// message
|
|
4006
|
-
'peernet-message': {
|
|
4007
|
-
codec: parseInt('706d65', 16),
|
|
4008
|
-
hashAlg: 'keccak-256',
|
|
4009
|
-
},
|
|
4010
|
-
// pubsub
|
|
4011
|
-
'peernet-ps': {
|
|
4012
|
-
codec: parseInt('707073', 16),
|
|
4013
|
-
hashAlg: 'keccak-256',
|
|
4014
|
-
},
|
|
4015
|
-
'peernet-response': {
|
|
4016
|
-
codec: parseInt('7072', 16),
|
|
4017
|
-
hashAlg: 'keccak-256',
|
|
4018
|
-
},
|
|
4019
|
-
'peernet-request': {
|
|
4020
|
-
codec: parseInt('707271', 16),
|
|
4021
|
-
hashAlg: 'keccak-256',
|
|
4022
|
-
},
|
|
4023
|
-
// normal block
|
|
4024
|
-
'leofcoin-block': {
|
|
4025
|
-
codec: parseInt('6c62', 16),
|
|
4026
|
-
hashAlg: 'dbl-keccak-512', // ,
|
|
4027
|
-
// testnet: 'olivia'
|
|
4028
|
-
},
|
|
4029
|
-
'leofcoin-tx': {
|
|
4030
|
-
codec: parseInt('6c74', 16),
|
|
4031
|
-
hashAlg: 'dbl-keccak-512', // ,
|
|
4032
|
-
// testnet: 'olivia'
|
|
4033
|
-
},
|
|
4034
|
-
// itx
|
|
4035
|
-
'leofcoin-itx': {
|
|
4036
|
-
codec: parseInt('6c69', 16),
|
|
4037
|
-
hashAlg: 'keccak-512', // ,
|
|
4038
|
-
// testnet: 'olivia'
|
|
4039
|
-
},
|
|
4040
|
-
// peer reputation
|
|
4041
|
-
'leofcoin-pr': {
|
|
4042
|
-
codec: parseInt('6c70', 16),
|
|
4043
|
-
hashAlg: 'keccak-256', // ,
|
|
4044
|
-
// testnet: 'olivia'
|
|
4045
|
-
},
|
|
4046
|
-
// chat message
|
|
4047
|
-
'chat-message': {
|
|
4048
|
-
codec: parseInt('70636d', 16),
|
|
4049
|
-
hashAlg: 'dbl-keccak-256',
|
|
4050
|
-
},
|
|
4051
|
-
'peernet-file' : {
|
|
4052
|
-
codec: parseInt('7066', 16),
|
|
4053
|
-
hashAlg: 'keccak-256',
|
|
4054
|
-
},
|
|
4055
|
-
'peernet-file-response' : {
|
|
4056
|
-
codec: parseInt('706672', 16),
|
|
4057
|
-
hashAlg: 'keccak-256',
|
|
4058
|
-
}
|
|
4059
|
-
};
|
|
4060
|
-
|
|
4061
|
-
var Codec$1 = /** @class */ (function (_super) {
|
|
4062
|
-
__extends(Codec, _super);
|
|
4063
|
-
function Codec(buffer) {
|
|
4064
|
-
var _this = _super.call(this) || this;
|
|
4065
|
-
if (buffer) {
|
|
4066
|
-
if (buffer instanceof Uint8Array) {
|
|
4067
|
-
var codec = varint.decode(buffer);
|
|
4068
|
-
var name_1 = _this.getCodecName(codec);
|
|
4069
|
-
if (name_1) {
|
|
4070
|
-
_this.name = name_1;
|
|
4071
|
-
_this.encoded = buffer;
|
|
4072
|
-
_this.decode(buffer);
|
|
4073
|
-
}
|
|
4074
|
-
else {
|
|
4075
|
-
_this.encode(buffer);
|
|
4076
|
-
}
|
|
4077
|
-
}
|
|
4078
|
-
else if (buffer instanceof ArrayBuffer) {
|
|
4079
|
-
var encoded = new Uint8Array(buffer.byteLength);
|
|
4080
|
-
for (var i = 0; i < buffer.byteLength; i++) {
|
|
4081
|
-
encoded[i] = buffer[i];
|
|
4082
|
-
}
|
|
4083
|
-
_this.encoded = encoded;
|
|
4084
|
-
// this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength)
|
|
4085
|
-
_this.decode(buffer);
|
|
4086
|
-
return _this;
|
|
4087
|
-
}
|
|
4088
|
-
if (typeof buffer === 'string') {
|
|
4089
|
-
if (_this.codecs[buffer])
|
|
4090
|
-
_this.fromName(buffer);
|
|
4091
|
-
else if (_this.isHex(buffer))
|
|
4092
|
-
_this.fromHex(buffer);
|
|
4093
|
-
else if (_this.isBase32(buffer))
|
|
4094
|
-
_this.fromBs32(buffer);
|
|
4095
|
-
else if (_this.isBase58(buffer))
|
|
4096
|
-
_this.fromBs58(buffer);
|
|
4097
|
-
else
|
|
4098
|
-
throw new Error("unsupported string ".concat(buffer));
|
|
4099
|
-
}
|
|
4100
|
-
if (!isNaN(buffer))
|
|
4101
|
-
if (_this.codecs[_this.getCodecName(buffer)])
|
|
4102
|
-
_this.fromCodec(buffer);
|
|
4103
|
-
}
|
|
4104
|
-
return _this;
|
|
4105
|
-
}
|
|
4106
|
-
Object.defineProperty(Codec.prototype, "codecs", {
|
|
4107
|
-
get: function () {
|
|
4108
|
-
return __assign(__assign({}, globalThis.peernet.codecs), codecs);
|
|
4109
|
-
},
|
|
4110
|
-
enumerable: false,
|
|
4111
|
-
configurable: true
|
|
4112
|
-
});
|
|
4113
|
-
Codec.prototype.fromEncoded = function (encoded) {
|
|
4114
|
-
var codec = varint.decode(encoded);
|
|
4115
|
-
var name = this.getCodecName(codec);
|
|
4116
|
-
this.name = name;
|
|
4117
|
-
this.encoded = encoded;
|
|
4118
|
-
this.decode(encoded);
|
|
4119
|
-
};
|
|
4120
|
-
Codec.prototype.getCodec = function (name) {
|
|
4121
|
-
return this.codecs[name].codec;
|
|
4122
|
-
};
|
|
4123
|
-
Codec.prototype.getCodecName = function (codec) {
|
|
4124
|
-
var _this = this;
|
|
4125
|
-
return Object.keys(this.codecs).reduce(function (p, c) {
|
|
4126
|
-
var item = _this.codecs[c];
|
|
4127
|
-
if (item.codec === codec)
|
|
4128
|
-
return c;
|
|
4129
|
-
else
|
|
4130
|
-
return p;
|
|
4131
|
-
}, undefined);
|
|
4132
|
-
};
|
|
4133
|
-
Codec.prototype.getHashAlg = function (name) {
|
|
4134
|
-
return this.codecs[name].hashAlg;
|
|
4135
|
-
};
|
|
4136
|
-
Codec.prototype.fromCodec = function (codec) {
|
|
4137
|
-
this.name = this.getCodecName(codec);
|
|
4138
|
-
this.hashAlg = this.getHashAlg(this.name);
|
|
4139
|
-
this.codec = this.getCodec(this.name);
|
|
4140
|
-
this.codecBuffer = varint.encode(codec);
|
|
4141
|
-
};
|
|
4142
|
-
Codec.prototype.fromName = function (name) {
|
|
4143
|
-
var codec = this.getCodec(name);
|
|
4144
|
-
this.name = name;
|
|
4145
|
-
this.codec = codec;
|
|
4146
|
-
this.hashAlg = this.getHashAlg(name);
|
|
4147
|
-
this.codecBuffer = varint.encode(codec);
|
|
4148
|
-
};
|
|
4149
|
-
Codec.prototype.decode = function () {
|
|
4150
|
-
var codec = varint.decode(this.encoded);
|
|
4151
|
-
this.fromCodec(codec);
|
|
4152
|
-
};
|
|
4153
|
-
Codec.prototype.encode = function () {
|
|
4154
|
-
var codec = varint.encode(this.decoded);
|
|
4155
|
-
this.encoded = codec;
|
|
4156
|
-
return this.encoded;
|
|
4157
|
-
};
|
|
4158
|
-
return Codec;
|
|
4159
|
-
}(BasicInterface$1));
|
|
4160
|
-
|
|
4161
|
-
let CodecHash$1 = class CodecHash extends BasicInterface$1 {
|
|
4162
|
-
constructor(buffer, options = {}) {
|
|
4163
|
-
super();
|
|
4164
|
-
if (options.name) this.name = options.name;
|
|
4165
|
-
else this.name = 'disco-hash';
|
|
4166
|
-
if (options.codecs) this.codecs = options.codecs;
|
|
4167
|
-
return this.init(buffer)
|
|
4168
|
-
}
|
|
4169
|
-
|
|
4170
|
-
async init(uint8Array) {
|
|
4171
|
-
if (uint8Array) {
|
|
4172
|
-
if (uint8Array instanceof Uint8Array) {
|
|
4173
|
-
this.discoCodec = new Codec$1(uint8Array, this.codecs);
|
|
4174
|
-
const name = this.discoCodec.name;
|
|
4175
|
-
|
|
4176
|
-
if (name) {
|
|
4177
|
-
this.name = name;
|
|
4178
|
-
this.decode(uint8Array);
|
|
4179
|
-
} else {
|
|
4180
|
-
await this.encode(uint8Array);
|
|
4181
|
-
}
|
|
4182
|
-
}
|
|
4183
|
-
|
|
4184
|
-
if (typeof uint8Array === 'string') {
|
|
4185
|
-
if (this.isHex(uint8Array)) await this.fromHex(uint8Array);
|
|
4186
|
-
if (this.isBase32(uint8Array)) await this.fromBs32(uint8Array);
|
|
4187
|
-
else if (this.isBase58(uint8Array)) await this.fromBs58(uint8Array);
|
|
4188
|
-
else throw new Error(`unsupported string ${uint8Array}`)
|
|
4189
|
-
} else if (typeof uint8Array === 'object') await this.fromJSON(uint8Array);
|
|
4190
|
-
}
|
|
4191
|
-
return this
|
|
4192
|
-
}
|
|
4193
|
-
get prefix() {
|
|
4194
|
-
const length = this.length;
|
|
4195
|
-
const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
|
|
4196
|
-
uint8Array.set(length);
|
|
4197
|
-
uint8Array.set(this.discoCodec.codecBuffer, length.length);
|
|
4198
|
-
|
|
4199
|
-
return uint8Array
|
|
4200
|
-
}
|
|
4201
|
-
|
|
4202
|
-
get length() {
|
|
4203
|
-
return varint.encode(this.size)
|
|
4204
|
-
}
|
|
4205
|
-
|
|
4206
|
-
get buffer() {
|
|
4207
|
-
return this.encoded
|
|
4208
|
-
}
|
|
4209
|
-
|
|
4210
|
-
get hash() {
|
|
4211
|
-
return this.encoded
|
|
4212
|
-
}
|
|
4213
|
-
|
|
4214
|
-
fromJSON(json) {
|
|
4215
|
-
return this.encode(Buffer.from(JSON.stringify(json)))
|
|
4216
|
-
}
|
|
4217
|
-
|
|
4218
|
-
async encode(buffer, name) {
|
|
4219
|
-
if (!this.name && name) this.name = name;
|
|
4220
|
-
if (!buffer) buffer = this.buffer;
|
|
4221
|
-
this.discoCodec = new Codec$1(this.name, this.codecs);
|
|
4222
|
-
this.discoCodec.fromName(this.name);
|
|
4223
|
-
let hashAlg = this.discoCodec.hashAlg;
|
|
4224
|
-
const hashVariant = Number(hashAlg.split('-')[hashAlg.split('-').length - 1]);
|
|
4225
|
-
|
|
4226
|
-
if (hashAlg.includes('dbl')) {
|
|
4227
|
-
hashAlg = hashAlg.replace('dbl-', '');
|
|
4228
|
-
const hasher = await createKeccak(hashVariant);
|
|
4229
|
-
await hasher.init();
|
|
4230
|
-
hasher.update(buffer);
|
|
4231
|
-
buffer = hasher.digest('binary');
|
|
4232
|
-
}
|
|
4233
|
-
const hasher = await createKeccak(hashVariant);
|
|
4234
|
-
await hasher.init();
|
|
4235
|
-
hasher.update(buffer);
|
|
4236
|
-
this.digest = hasher.digest('binary');
|
|
4237
|
-
this.size = this.digest.length;
|
|
4238
|
-
|
|
4239
|
-
this.codec = this.discoCodec.encode();
|
|
4240
|
-
this.codec = this.discoCodec.codecBuffer;
|
|
4241
|
-
const uint8Array = new Uint8Array(this.digest.length + this.prefix.length);
|
|
4242
|
-
uint8Array.set(this.prefix);
|
|
4243
|
-
uint8Array.set(this.digest, this.prefix.length);
|
|
4244
|
-
|
|
4245
|
-
this.encoded = uint8Array;
|
|
4246
|
-
|
|
4247
|
-
return this.encoded
|
|
4248
|
-
}
|
|
4249
|
-
|
|
4250
|
-
async validate(buffer) {
|
|
4251
|
-
if (Buffer.isBuffer(buffer)) {
|
|
4252
|
-
const codec = varint.decode(buffer);
|
|
4253
|
-
if (this.codecs[codec]) {
|
|
4254
|
-
this.decode(buffer);
|
|
4255
|
-
} else {
|
|
4256
|
-
await this.encode(buffer);
|
|
4257
|
-
}
|
|
4258
|
-
}
|
|
4259
|
-
if (typeof buffer === 'string') {
|
|
4260
|
-
if (this.isHex(buffer)) this.fromHex(buffer);
|
|
4261
|
-
if (this.isBase32(buffer)) this.fromBs32(buffer);
|
|
4262
|
-
}
|
|
4263
|
-
if (typeof buffer === 'object') this.fromJSON(buffer);
|
|
4264
|
-
}
|
|
4265
|
-
|
|
4266
|
-
decode(buffer) {
|
|
4267
|
-
this.encoded = buffer;
|
|
4268
|
-
const codec = varint.decode(buffer);
|
|
4269
|
-
|
|
4270
|
-
this.discoCodec = new Codec$1(codec, this.codecs);
|
|
4271
|
-
// TODO: validate codec
|
|
4272
|
-
buffer = buffer.slice(varint.decode.bytes);
|
|
4273
|
-
this.size = varint.decode(buffer);
|
|
4274
|
-
this.digest = buffer.slice(varint.decode.bytes);
|
|
4275
|
-
if (this.digest.length !== this.size) {
|
|
4276
|
-
throw new Error(`hash length inconsistent: 0x${this.encoded.toString('hex')}`)
|
|
4277
|
-
}
|
|
4278
|
-
|
|
4279
|
-
// const discoCodec = new Codec(codec, this.codecs)
|
|
4280
|
-
|
|
4281
|
-
this.name = this.discoCodec.name;
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
this.size = this.digest.length;
|
|
4285
|
-
|
|
4286
|
-
return {
|
|
4287
|
-
codec: this.codec,
|
|
4288
|
-
name: this.name,
|
|
4289
|
-
size: this.size,
|
|
4290
|
-
length: this.length,
|
|
4291
|
-
digest: this.digest,
|
|
4292
|
-
}
|
|
4293
|
-
}
|
|
4294
|
-
};
|
|
4295
|
-
|
|
4296
|
-
var FormatInterface$1 = /** @class */ (function (_super) {
|
|
4297
|
-
__extends(FormatInterface, _super);
|
|
4298
|
-
/**
|
|
4299
|
-
* @param {Buffer|String|Object} buffer - data - The data needed to create the desired message
|
|
4300
|
-
* @param {Object} proto - {encode, decode}
|
|
4301
|
-
* @param {Object} options - {hashFormat, name}
|
|
4302
|
-
*/
|
|
4303
|
-
function FormatInterface(buffer, proto, options) {
|
|
4304
|
-
if (options === void 0) { options = {}; }
|
|
4305
|
-
var _this = _super.call(this) || this;
|
|
4306
|
-
_this.proto = proto;
|
|
4307
|
-
_this.hashFormat = options.hashFormat || 'bs32';
|
|
4308
|
-
if (options.name)
|
|
4309
|
-
_this.name = options.name;
|
|
4310
|
-
return _this.init(buffer);
|
|
4311
|
-
}
|
|
4312
|
-
FormatInterface.prototype.init = function (buffer) {
|
|
4313
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
4314
|
-
return __generator(this, function (_a) {
|
|
4315
|
-
switch (_a.label) {
|
|
4316
|
-
case 0:
|
|
4317
|
-
if (!(buffer instanceof Uint8Array)) return [3 /*break*/, 2];
|
|
4318
|
-
return [4 /*yield*/, this.fromUint8Array(buffer)];
|
|
4319
|
-
case 1:
|
|
4320
|
-
_a.sent();
|
|
4321
|
-
return [3 /*break*/, 15];
|
|
4322
|
-
case 2:
|
|
4323
|
-
if (!(buffer instanceof ArrayBuffer)) return [3 /*break*/, 4];
|
|
4324
|
-
return [4 /*yield*/, this.fromArrayBuffer(buffer)];
|
|
4325
|
-
case 3:
|
|
4326
|
-
_a.sent();
|
|
4327
|
-
return [3 /*break*/, 15];
|
|
4328
|
-
case 4:
|
|
4329
|
-
if (!((buffer === null || buffer === void 0 ? void 0 : buffer.name) === this.name)) return [3 /*break*/, 5];
|
|
4330
|
-
return [2 /*return*/, buffer];
|
|
4331
|
-
case 5:
|
|
4332
|
-
if (!(buffer instanceof String)) return [3 /*break*/, 13];
|
|
4333
|
-
if (!this.isHex(buffer)) return [3 /*break*/, 7];
|
|
4334
|
-
return [4 /*yield*/, this.fromHex(buffer)];
|
|
4335
|
-
case 6:
|
|
4336
|
-
_a.sent();
|
|
4337
|
-
return [3 /*break*/, 12];
|
|
4338
|
-
case 7:
|
|
4339
|
-
if (!this.isBase32(buffer)) return [3 /*break*/, 9];
|
|
4340
|
-
return [4 /*yield*/, this.fromBs32(buffer)];
|
|
4341
|
-
case 8:
|
|
4342
|
-
_a.sent();
|
|
4343
|
-
return [3 /*break*/, 12];
|
|
4344
|
-
case 9:
|
|
4345
|
-
if (!this.isBase58(buffer)) return [3 /*break*/, 11];
|
|
4346
|
-
return [4 /*yield*/, this.fromBs58(buffer)];
|
|
4347
|
-
case 10:
|
|
4348
|
-
_a.sent();
|
|
4349
|
-
return [3 /*break*/, 12];
|
|
4350
|
-
case 11: throw new Error("unsupported string ".concat(buffer));
|
|
4351
|
-
case 12: return [3 /*break*/, 15];
|
|
4352
|
-
case 13: return [4 /*yield*/, this.create(buffer)];
|
|
4353
|
-
case 14:
|
|
4354
|
-
_a.sent();
|
|
4355
|
-
_a.label = 15;
|
|
4356
|
-
case 15: return [2 /*return*/, this];
|
|
4357
|
-
}
|
|
4358
|
-
});
|
|
4359
|
-
});
|
|
4360
|
-
};
|
|
4361
|
-
FormatInterface.prototype.hasCodec = function () {
|
|
4362
|
-
if (!this.encoded)
|
|
4363
|
-
return false;
|
|
4364
|
-
var codec = new Codec$1(this.encoded);
|
|
4365
|
-
if (codec.name)
|
|
4366
|
-
return true;
|
|
4367
|
-
};
|
|
4368
|
-
FormatInterface.prototype.decode = function () {
|
|
4369
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
4370
|
-
var encoded, codec, _a;
|
|
4371
|
-
return __generator(this, function (_b) {
|
|
4372
|
-
switch (_b.label) {
|
|
4373
|
-
case 0:
|
|
4374
|
-
encoded = this.encoded;
|
|
4375
|
-
codec = new Codec$1(this.encoded);
|
|
4376
|
-
if (!codec.codecBuffer) return [3 /*break*/, 2];
|
|
4377
|
-
encoded = encoded.slice(codec.codecBuffer.length);
|
|
4378
|
-
this.name = codec.name;
|
|
4379
|
-
_a = this;
|
|
4380
|
-
return [4 /*yield*/, this.protoDecode(encoded)];
|
|
4381
|
-
case 1:
|
|
4382
|
-
_a.decoded = _b.sent();
|
|
4383
|
-
try {
|
|
4384
|
-
this.decoded = JSON.parse(this.decoded);
|
|
4385
|
-
}
|
|
4386
|
-
catch (_c) {
|
|
4387
|
-
}
|
|
4388
|
-
return [3 /*break*/, 3];
|
|
4389
|
-
case 2: throw new Error("no codec found");
|
|
4390
|
-
case 3: return [2 /*return*/, this.decoded];
|
|
4391
|
-
}
|
|
4392
|
-
});
|
|
4393
|
-
});
|
|
4394
|
-
};
|
|
4395
|
-
FormatInterface.prototype.encode = function (decoded) {
|
|
4396
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
4397
|
-
var encoded, codec, uint8Array;
|
|
4398
|
-
return __generator(this, function (_a) {
|
|
4399
|
-
switch (_a.label) {
|
|
4400
|
-
case 0:
|
|
4401
|
-
if (!decoded)
|
|
4402
|
-
decoded = this.decoded;
|
|
4403
|
-
codec = new Codec$1(this.name);
|
|
4404
|
-
if (!(decoded instanceof Uint8Array)) return [3 /*break*/, 1];
|
|
4405
|
-
encoded = decoded;
|
|
4406
|
-
return [3 /*break*/, 3];
|
|
4407
|
-
case 1: return [4 /*yield*/, this.protoEncode(typeof decoded === 'object' ? JSON.stringify(decoded) : decoded)];
|
|
4408
|
-
case 2:
|
|
4409
|
-
encoded = _a.sent();
|
|
4410
|
-
_a.label = 3;
|
|
4411
|
-
case 3:
|
|
4412
|
-
if (codec.codecBuffer) {
|
|
4413
|
-
uint8Array = new Uint8Array(encoded.length + codec.codecBuffer.length);
|
|
4414
|
-
uint8Array.set(codec.codecBuffer);
|
|
4415
|
-
uint8Array.set(encoded, codec.codecBuffer.length);
|
|
4416
|
-
this.encoded = uint8Array;
|
|
4417
|
-
}
|
|
4418
|
-
else {
|
|
4419
|
-
throw new Error("invalid codec");
|
|
4420
|
-
}
|
|
4421
|
-
return [2 /*return*/, this.encoded];
|
|
4422
|
-
}
|
|
4423
|
-
});
|
|
4424
|
-
});
|
|
4425
|
-
};
|
|
4426
|
-
Object.defineProperty(FormatInterface.prototype, "peernetHash", {
|
|
4427
|
-
/**
|
|
4428
|
-
* @return {PeernetHash}
|
|
4429
|
-
*/
|
|
4430
|
-
get: function () {
|
|
4431
|
-
return new CodecHash$1(this.decoded, { name: this.name });
|
|
4432
|
-
},
|
|
4433
|
-
enumerable: false,
|
|
4434
|
-
configurable: true
|
|
4435
|
-
});
|
|
4436
|
-
/**
|
|
4437
|
-
* @return {peernetHash}
|
|
4438
|
-
*/
|
|
4439
|
-
FormatInterface.prototype.hash = function () {
|
|
4440
|
-
return __awaiter$1(this, void 0, void 0, function () {
|
|
4441
|
-
var upper, format;
|
|
4442
|
-
return __generator(this, function (_a) {
|
|
4443
|
-
switch (_a.label) {
|
|
4444
|
-
case 0:
|
|
4445
|
-
upper = this.hashFormat.charAt(0).toUpperCase();
|
|
4446
|
-
format = "".concat(upper).concat(this.hashFormat.substring(1, this.hashFormat.length));
|
|
4447
|
-
return [4 /*yield*/, this.peernetHash];
|
|
4448
|
-
case 1: return [2 /*return*/, (_a.sent())["to".concat(format)]()];
|
|
4449
|
-
}
|
|
4450
|
-
});
|
|
4451
|
-
});
|
|
4452
|
-
};
|
|
4453
|
-
FormatInterface.prototype.fromUint8Array = function (buffer) {
|
|
4454
|
-
this.encoded = buffer;
|
|
4455
|
-
return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
|
|
4456
|
-
};
|
|
4457
|
-
FormatInterface.prototype.fromArrayBuffer = function (buffer) {
|
|
4458
|
-
this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
|
|
4459
|
-
return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
|
|
4460
|
-
};
|
|
4461
|
-
return FormatInterface;
|
|
4462
|
-
}(BasicInterface$1));
|
|
4463
|
-
|
|
4464
|
-
var BasicInterface = (/* unused pure expression or super */ null && (BasicInterface$1));
|
|
4465
|
-
var FormatInterface = FormatInterface$1;
|
|
4466
|
-
var CodecHash = CodecHash$1;
|
|
4467
|
-
var Codec = (/* unused pure expression or super */ null && (Codec$1));
|
|
4468
|
-
var Codecs = (/* unused pure expression or super */ null && (codecs));
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
;// CONCATENATED MODULE: ./node_modules/@vandeurenglenn/easy-worker/src/worker.js
|
|
4473
|
-
/* provided dependency */ var process = __webpack_require__(155);
|
|
4474
|
-
class EasyWorker {
|
|
4475
|
-
#messageEvent = 'message'
|
|
4476
|
-
#errorEvent = 'error'
|
|
4477
|
-
#isBrowser = false
|
|
4478
|
-
#isWorker = false
|
|
4479
|
-
|
|
4480
|
-
get isWorker() {
|
|
4481
|
-
return this.#isWorker
|
|
4482
|
-
}
|
|
4483
|
-
constructor(url, options) {
|
|
4484
|
-
return this.#init(url, options)
|
|
4485
|
-
}
|
|
4486
|
-
|
|
4487
|
-
#init(url, options = {}) {
|
|
4488
|
-
if (url) {
|
|
4489
|
-
if (globalThis.Worker) {
|
|
4490
|
-
this.#isBrowser = true
|
|
4491
|
-
this.worker = new Worker(url, {...options})
|
|
4492
|
-
} else {
|
|
4493
|
-
return new Promise(async (resolve, reject) => {
|
|
4494
|
-
const {fork} = await __webpack_require__.e(/* import() */ 865).then(__webpack_require__.t.bind(__webpack_require__, 865, 23))
|
|
4495
|
-
this.worker = fork(url, ['easy-worker-child'], options)
|
|
4496
|
-
resolve(this)
|
|
4497
|
-
})
|
|
4498
|
-
}
|
|
4499
|
-
} else {
|
|
4500
|
-
this.#isWorker = true
|
|
4501
|
-
if (globalThis.process?.argv[2] === 'easy-worker-child') {
|
|
4502
|
-
this.worker = process
|
|
4503
|
-
} else {
|
|
4504
|
-
this.#isBrowser = true
|
|
4505
|
-
this.worker = globalThis
|
|
4506
|
-
}
|
|
4507
|
-
}
|
|
4508
|
-
|
|
4509
|
-
return this
|
|
4510
|
-
}
|
|
4511
|
-
|
|
4512
|
-
onmessage(fn) {
|
|
4513
|
-
if (this.#isBrowser) this.worker.onmessage = ({data}) => fn(data)
|
|
4514
|
-
else this.worker.on(this.#messageEvent, fn)
|
|
4515
|
-
}
|
|
4516
|
-
|
|
4517
|
-
postMessage(message) {
|
|
4518
|
-
if (this.#isBrowser) this.worker.postMessage(message);
|
|
4519
|
-
else this.worker.send(message)
|
|
4520
|
-
}
|
|
4521
|
-
|
|
4522
|
-
terminate() {
|
|
4523
|
-
if (this.#isBrowser) this.worker.terminate()
|
|
4524
|
-
else this.worker.kill()
|
|
4525
|
-
}
|
|
4526
|
-
|
|
4527
|
-
onerror(fn) {
|
|
4528
|
-
if (this.#isBrowser) this.worker.onerror = fn
|
|
4529
|
-
else this.worker.on(this.#errorEvent, fn)
|
|
4530
|
-
}
|
|
4531
|
-
|
|
4532
|
-
/**
|
|
4533
|
-
*
|
|
4534
|
-
* @param {*} data
|
|
4535
|
-
* @returns {Promise} resolves result onmessage & rejects on error
|
|
4536
|
-
*/
|
|
4537
|
-
once(data) {
|
|
4538
|
-
return new Promise((resolve, reject) => {
|
|
4539
|
-
this.onmessage(message => {
|
|
4540
|
-
resolve(message)
|
|
4541
|
-
this.terminate()
|
|
4542
|
-
})
|
|
4543
|
-
this.onerror(error => {
|
|
4544
|
-
reject(error)
|
|
4545
|
-
this.terminate()
|
|
4546
|
-
})
|
|
4547
|
-
this.postMessage(data)
|
|
4548
|
-
})
|
|
4549
|
-
}
|
|
4550
|
-
}
|
|
4551
|
-
;// CONCATENATED MODULE: ./dist/module/workers/pool-worker.js
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
var proto = `
|
|
4556
|
-
|
|
4557
|
-
message TransactionMessage {
|
|
4558
|
-
required uint64 timestamp = 1;
|
|
4559
|
-
required string from = 2;
|
|
4560
|
-
required string to = 3;
|
|
4561
|
-
required uint64 nonce = 4;
|
|
4562
|
-
required string method = 5;
|
|
4563
|
-
repeated string params = 6;
|
|
4564
|
-
required string signature = 7;
|
|
4565
|
-
}
|
|
4566
|
-
`;
|
|
4567
|
-
|
|
4568
|
-
class TransactionMessage extends FormatInterface {
|
|
4569
|
-
get keys() {
|
|
4570
|
-
return ['timestamp', 'from', 'to', 'nonce', 'method', 'params', 'signature']
|
|
4571
|
-
}
|
|
4572
|
-
|
|
4573
|
-
get messageName() {
|
|
4574
|
-
return 'TransactionMessage'
|
|
4575
|
-
}
|
|
4576
|
-
|
|
4577
|
-
constructor(buffer) {
|
|
4578
|
-
const name = 'transaction-message';
|
|
4579
|
-
super(buffer, proto, {name});
|
|
4580
|
-
}
|
|
4581
|
-
}
|
|
4582
|
-
|
|
4583
|
-
globalThis.peernet = globalThis.peernet || {};
|
|
4584
|
-
globalThis.contracts = {};
|
|
4585
|
-
|
|
4586
|
-
const worker = new EasyWorker();
|
|
4587
|
-
|
|
4588
|
-
const tasks = async transactions => {
|
|
4589
|
-
|
|
4590
|
-
globalThis.peernet.codecs = {
|
|
4591
|
-
'transaction-message': {
|
|
4592
|
-
codec: parseInt('746d', 16),
|
|
4593
|
-
hashAlg: 'keccak-256'
|
|
4594
|
-
}
|
|
4595
|
-
};
|
|
4596
|
-
|
|
4597
|
-
transactions = await Promise.all(transactions.map(async message => {
|
|
4598
|
-
message = await new TransactionMessage(message);
|
|
4599
|
-
|
|
4600
|
-
return {...message.decoded, hash: await message.hash, size: message.encoded.length}
|
|
4601
|
-
}));
|
|
4602
|
-
|
|
4603
|
-
worker.postMessage(transactions);
|
|
4604
|
-
|
|
4605
|
-
};
|
|
4606
|
-
worker.onmessage(data => tasks(data));
|
|
4607
|
-
|
|
4608
|
-
}();
|