@xchainjs/xchain-thorchain 0.28.3 → 0.28.4
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/lib/client.d.ts +1 -1
- package/lib/index.esm.js +793 -819
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +793 -819
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -4382,838 +4382,783 @@ var indexMinimal = {};
|
|
|
4382
4382
|
|
|
4383
4383
|
var minimal$1 = {};
|
|
4384
4384
|
|
|
4385
|
-
var aspromise;
|
|
4386
|
-
var hasRequiredAspromise;
|
|
4387
|
-
|
|
4388
|
-
function requireAspromise () {
|
|
4389
|
-
if (hasRequiredAspromise) return aspromise;
|
|
4390
|
-
hasRequiredAspromise = 1;
|
|
4391
|
-
aspromise = asPromise;
|
|
4385
|
+
var aspromise = asPromise;
|
|
4392
4386
|
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4387
|
+
/**
|
|
4388
|
+
* Callback as used by {@link util.asPromise}.
|
|
4389
|
+
* @typedef asPromiseCallback
|
|
4390
|
+
* @type {function}
|
|
4391
|
+
* @param {Error|null} error Error, if any
|
|
4392
|
+
* @param {...*} params Additional arguments
|
|
4393
|
+
* @returns {undefined}
|
|
4394
|
+
*/
|
|
4401
4395
|
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
}
|
|
4442
|
-
return aspromise;
|
|
4396
|
+
/**
|
|
4397
|
+
* Returns a promise from a node-style callback function.
|
|
4398
|
+
* @memberof util
|
|
4399
|
+
* @param {asPromiseCallback} fn Function to call
|
|
4400
|
+
* @param {*} ctx Function context
|
|
4401
|
+
* @param {...*} params Function arguments
|
|
4402
|
+
* @returns {Promise<*>} Promisified function
|
|
4403
|
+
*/
|
|
4404
|
+
function asPromise(fn, ctx/*, varargs */) {
|
|
4405
|
+
var params = new Array(arguments.length - 1),
|
|
4406
|
+
offset = 0,
|
|
4407
|
+
index = 2,
|
|
4408
|
+
pending = true;
|
|
4409
|
+
while (index < arguments.length)
|
|
4410
|
+
params[offset++] = arguments[index++];
|
|
4411
|
+
return new Promise(function executor(resolve, reject) {
|
|
4412
|
+
params[offset] = function callback(err/*, varargs */) {
|
|
4413
|
+
if (pending) {
|
|
4414
|
+
pending = false;
|
|
4415
|
+
if (err)
|
|
4416
|
+
reject(err);
|
|
4417
|
+
else {
|
|
4418
|
+
var params = new Array(arguments.length - 1),
|
|
4419
|
+
offset = 0;
|
|
4420
|
+
while (offset < params.length)
|
|
4421
|
+
params[offset++] = arguments[offset];
|
|
4422
|
+
resolve.apply(null, params);
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
};
|
|
4426
|
+
try {
|
|
4427
|
+
fn.apply(ctx || null, params);
|
|
4428
|
+
} catch (err) {
|
|
4429
|
+
if (pending) {
|
|
4430
|
+
pending = false;
|
|
4431
|
+
reject(err);
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
});
|
|
4443
4435
|
}
|
|
4444
4436
|
|
|
4445
4437
|
var base64$1 = {};
|
|
4446
4438
|
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
function requireBase64 () {
|
|
4450
|
-
if (hasRequiredBase64) return base64$1;
|
|
4451
|
-
hasRequiredBase64 = 1;
|
|
4452
|
-
(function (exports) {
|
|
4453
|
-
|
|
4454
|
-
/**
|
|
4455
|
-
* A minimal base64 implementation for number arrays.
|
|
4456
|
-
* @memberof util
|
|
4457
|
-
* @namespace
|
|
4458
|
-
*/
|
|
4459
|
-
var base64 = exports;
|
|
4460
|
-
|
|
4461
|
-
/**
|
|
4462
|
-
* Calculates the byte length of a base64 encoded string.
|
|
4463
|
-
* @param {string} string Base64 encoded string
|
|
4464
|
-
* @returns {number} Byte length
|
|
4465
|
-
*/
|
|
4466
|
-
base64.length = function length(string) {
|
|
4467
|
-
var p = string.length;
|
|
4468
|
-
if (!p)
|
|
4469
|
-
return 0;
|
|
4470
|
-
var n = 0;
|
|
4471
|
-
while (--p % 4 > 1 && string.charAt(p) === "=")
|
|
4472
|
-
++n;
|
|
4473
|
-
return Math.ceil(string.length * 3) / 4 - n;
|
|
4474
|
-
};
|
|
4475
|
-
|
|
4476
|
-
// Base64 encoding table
|
|
4477
|
-
var b64 = new Array(64);
|
|
4478
|
-
|
|
4479
|
-
// Base64 decoding table
|
|
4480
|
-
var s64 = new Array(123);
|
|
4481
|
-
|
|
4482
|
-
// 65..90, 97..122, 48..57, 43, 47
|
|
4483
|
-
for (var i = 0; i < 64;)
|
|
4484
|
-
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
4485
|
-
|
|
4486
|
-
/**
|
|
4487
|
-
* Encodes a buffer to a base64 encoded string.
|
|
4488
|
-
* @param {Uint8Array} buffer Source buffer
|
|
4489
|
-
* @param {number} start Source start
|
|
4490
|
-
* @param {number} end Source end
|
|
4491
|
-
* @returns {string} Base64 encoded string
|
|
4492
|
-
*/
|
|
4493
|
-
base64.encode = function encode(buffer, start, end) {
|
|
4494
|
-
var parts = null,
|
|
4495
|
-
chunk = [];
|
|
4496
|
-
var i = 0, // output index
|
|
4497
|
-
j = 0, // goto index
|
|
4498
|
-
t; // temporary
|
|
4499
|
-
while (start < end) {
|
|
4500
|
-
var b = buffer[start++];
|
|
4501
|
-
switch (j) {
|
|
4502
|
-
case 0:
|
|
4503
|
-
chunk[i++] = b64[b >> 2];
|
|
4504
|
-
t = (b & 3) << 4;
|
|
4505
|
-
j = 1;
|
|
4506
|
-
break;
|
|
4507
|
-
case 1:
|
|
4508
|
-
chunk[i++] = b64[t | b >> 4];
|
|
4509
|
-
t = (b & 15) << 2;
|
|
4510
|
-
j = 2;
|
|
4511
|
-
break;
|
|
4512
|
-
case 2:
|
|
4513
|
-
chunk[i++] = b64[t | b >> 6];
|
|
4514
|
-
chunk[i++] = b64[b & 63];
|
|
4515
|
-
j = 0;
|
|
4516
|
-
break;
|
|
4517
|
-
}
|
|
4518
|
-
if (i > 8191) {
|
|
4519
|
-
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
4520
|
-
i = 0;
|
|
4521
|
-
}
|
|
4522
|
-
}
|
|
4523
|
-
if (j) {
|
|
4524
|
-
chunk[i++] = b64[t];
|
|
4525
|
-
chunk[i++] = 61;
|
|
4526
|
-
if (j === 1)
|
|
4527
|
-
chunk[i++] = 61;
|
|
4528
|
-
}
|
|
4529
|
-
if (parts) {
|
|
4530
|
-
if (i)
|
|
4531
|
-
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
4532
|
-
return parts.join("");
|
|
4533
|
-
}
|
|
4534
|
-
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
4535
|
-
};
|
|
4536
|
-
|
|
4537
|
-
var invalidEncoding = "invalid encoding";
|
|
4538
|
-
|
|
4539
|
-
/**
|
|
4540
|
-
* Decodes a base64 encoded string to a buffer.
|
|
4541
|
-
* @param {string} string Source string
|
|
4542
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
4543
|
-
* @param {number} offset Destination offset
|
|
4544
|
-
* @returns {number} Number of bytes written
|
|
4545
|
-
* @throws {Error} If encoding is invalid
|
|
4546
|
-
*/
|
|
4547
|
-
base64.decode = function decode(string, buffer, offset) {
|
|
4548
|
-
var start = offset;
|
|
4549
|
-
var j = 0, // goto index
|
|
4550
|
-
t; // temporary
|
|
4551
|
-
for (var i = 0; i < string.length;) {
|
|
4552
|
-
var c = string.charCodeAt(i++);
|
|
4553
|
-
if (c === 61 && j > 1)
|
|
4554
|
-
break;
|
|
4555
|
-
if ((c = s64[c]) === undefined)
|
|
4556
|
-
throw Error(invalidEncoding);
|
|
4557
|
-
switch (j) {
|
|
4558
|
-
case 0:
|
|
4559
|
-
t = c;
|
|
4560
|
-
j = 1;
|
|
4561
|
-
break;
|
|
4562
|
-
case 1:
|
|
4563
|
-
buffer[offset++] = t << 2 | (c & 48) >> 4;
|
|
4564
|
-
t = c;
|
|
4565
|
-
j = 2;
|
|
4566
|
-
break;
|
|
4567
|
-
case 2:
|
|
4568
|
-
buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
|
|
4569
|
-
t = c;
|
|
4570
|
-
j = 3;
|
|
4571
|
-
break;
|
|
4572
|
-
case 3:
|
|
4573
|
-
buffer[offset++] = (t & 3) << 6 | c;
|
|
4574
|
-
j = 0;
|
|
4575
|
-
break;
|
|
4576
|
-
}
|
|
4577
|
-
}
|
|
4578
|
-
if (j === 1)
|
|
4579
|
-
throw Error(invalidEncoding);
|
|
4580
|
-
return offset - start;
|
|
4581
|
-
};
|
|
4582
|
-
|
|
4583
|
-
/**
|
|
4584
|
-
* Tests if the specified string appears to be base64 encoded.
|
|
4585
|
-
* @param {string} string String to test
|
|
4586
|
-
* @returns {boolean} `true` if probably base64 encoded, otherwise false
|
|
4587
|
-
*/
|
|
4588
|
-
base64.test = function test(string) {
|
|
4589
|
-
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
|
|
4590
|
-
};
|
|
4591
|
-
} (base64$1));
|
|
4592
|
-
return base64$1;
|
|
4593
|
-
}
|
|
4594
|
-
|
|
4595
|
-
var eventemitter;
|
|
4596
|
-
var hasRequiredEventemitter;
|
|
4597
|
-
|
|
4598
|
-
function requireEventemitter () {
|
|
4599
|
-
if (hasRequiredEventemitter) return eventemitter;
|
|
4600
|
-
hasRequiredEventemitter = 1;
|
|
4601
|
-
eventemitter = EventEmitter;
|
|
4439
|
+
(function (exports) {
|
|
4602
4440
|
|
|
4603
4441
|
/**
|
|
4604
|
-
*
|
|
4605
|
-
* @classdesc A minimal event emitter.
|
|
4442
|
+
* A minimal base64 implementation for number arrays.
|
|
4606
4443
|
* @memberof util
|
|
4607
|
-
* @
|
|
4444
|
+
* @namespace
|
|
4608
4445
|
*/
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
/**
|
|
4612
|
-
* Registered listeners.
|
|
4613
|
-
* @type {Object.<string,*>}
|
|
4614
|
-
* @private
|
|
4615
|
-
*/
|
|
4616
|
-
this._listeners = {};
|
|
4617
|
-
}
|
|
4446
|
+
var base64 = exports;
|
|
4618
4447
|
|
|
4619
4448
|
/**
|
|
4620
|
-
*
|
|
4621
|
-
* @param {string}
|
|
4622
|
-
* @
|
|
4623
|
-
* @param {*} [ctx] Listener context
|
|
4624
|
-
* @returns {util.EventEmitter} `this`
|
|
4449
|
+
* Calculates the byte length of a base64 encoded string.
|
|
4450
|
+
* @param {string} string Base64 encoded string
|
|
4451
|
+
* @returns {number} Byte length
|
|
4625
4452
|
*/
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4453
|
+
base64.length = function length(string) {
|
|
4454
|
+
var p = string.length;
|
|
4455
|
+
if (!p)
|
|
4456
|
+
return 0;
|
|
4457
|
+
var n = 0;
|
|
4458
|
+
while (--p % 4 > 1 && string.charAt(p) === "=")
|
|
4459
|
+
++n;
|
|
4460
|
+
return Math.ceil(string.length * 3) / 4 - n;
|
|
4632
4461
|
};
|
|
4633
4462
|
|
|
4463
|
+
// Base64 encoding table
|
|
4464
|
+
var b64 = new Array(64);
|
|
4465
|
+
|
|
4466
|
+
// Base64 decoding table
|
|
4467
|
+
var s64 = new Array(123);
|
|
4468
|
+
|
|
4469
|
+
// 65..90, 97..122, 48..57, 43, 47
|
|
4470
|
+
for (var i = 0; i < 64;)
|
|
4471
|
+
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
4472
|
+
|
|
4634
4473
|
/**
|
|
4635
|
-
*
|
|
4636
|
-
* @param {
|
|
4637
|
-
* @param {
|
|
4638
|
-
* @
|
|
4474
|
+
* Encodes a buffer to a base64 encoded string.
|
|
4475
|
+
* @param {Uint8Array} buffer Source buffer
|
|
4476
|
+
* @param {number} start Source start
|
|
4477
|
+
* @param {number} end Source end
|
|
4478
|
+
* @returns {string} Base64 encoded string
|
|
4639
4479
|
*/
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4480
|
+
base64.encode = function encode(buffer, start, end) {
|
|
4481
|
+
var parts = null,
|
|
4482
|
+
chunk = [];
|
|
4483
|
+
var i = 0, // output index
|
|
4484
|
+
j = 0, // goto index
|
|
4485
|
+
t; // temporary
|
|
4486
|
+
while (start < end) {
|
|
4487
|
+
var b = buffer[start++];
|
|
4488
|
+
switch (j) {
|
|
4489
|
+
case 0:
|
|
4490
|
+
chunk[i++] = b64[b >> 2];
|
|
4491
|
+
t = (b & 3) << 4;
|
|
4492
|
+
j = 1;
|
|
4493
|
+
break;
|
|
4494
|
+
case 1:
|
|
4495
|
+
chunk[i++] = b64[t | b >> 4];
|
|
4496
|
+
t = (b & 15) << 2;
|
|
4497
|
+
j = 2;
|
|
4498
|
+
break;
|
|
4499
|
+
case 2:
|
|
4500
|
+
chunk[i++] = b64[t | b >> 6];
|
|
4501
|
+
chunk[i++] = b64[b & 63];
|
|
4502
|
+
j = 0;
|
|
4503
|
+
break;
|
|
4653
4504
|
}
|
|
4505
|
+
if (i > 8191) {
|
|
4506
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
4507
|
+
i = 0;
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
4510
|
+
if (j) {
|
|
4511
|
+
chunk[i++] = b64[t];
|
|
4512
|
+
chunk[i++] = 61;
|
|
4513
|
+
if (j === 1)
|
|
4514
|
+
chunk[i++] = 61;
|
|
4515
|
+
}
|
|
4516
|
+
if (parts) {
|
|
4517
|
+
if (i)
|
|
4518
|
+
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
4519
|
+
return parts.join("");
|
|
4654
4520
|
}
|
|
4655
|
-
return
|
|
4521
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
4656
4522
|
};
|
|
4657
4523
|
|
|
4524
|
+
var invalidEncoding = "invalid encoding";
|
|
4525
|
+
|
|
4658
4526
|
/**
|
|
4659
|
-
*
|
|
4660
|
-
* @param {string}
|
|
4661
|
-
* @param {
|
|
4662
|
-
* @
|
|
4527
|
+
* Decodes a base64 encoded string to a buffer.
|
|
4528
|
+
* @param {string} string Source string
|
|
4529
|
+
* @param {Uint8Array} buffer Destination buffer
|
|
4530
|
+
* @param {number} offset Destination offset
|
|
4531
|
+
* @returns {number} Number of bytes written
|
|
4532
|
+
* @throws {Error} If encoding is invalid
|
|
4663
4533
|
*/
|
|
4664
|
-
|
|
4665
|
-
var
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4534
|
+
base64.decode = function decode(string, buffer, offset) {
|
|
4535
|
+
var start = offset;
|
|
4536
|
+
var j = 0, // goto index
|
|
4537
|
+
t; // temporary
|
|
4538
|
+
for (var i = 0; i < string.length;) {
|
|
4539
|
+
var c = string.charCodeAt(i++);
|
|
4540
|
+
if (c === 61 && j > 1)
|
|
4541
|
+
break;
|
|
4542
|
+
if ((c = s64[c]) === undefined)
|
|
4543
|
+
throw Error(invalidEncoding);
|
|
4544
|
+
switch (j) {
|
|
4545
|
+
case 0:
|
|
4546
|
+
t = c;
|
|
4547
|
+
j = 1;
|
|
4548
|
+
break;
|
|
4549
|
+
case 1:
|
|
4550
|
+
buffer[offset++] = t << 2 | (c & 48) >> 4;
|
|
4551
|
+
t = c;
|
|
4552
|
+
j = 2;
|
|
4553
|
+
break;
|
|
4554
|
+
case 2:
|
|
4555
|
+
buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
|
|
4556
|
+
t = c;
|
|
4557
|
+
j = 3;
|
|
4558
|
+
break;
|
|
4559
|
+
case 3:
|
|
4560
|
+
buffer[offset++] = (t & 3) << 6 | c;
|
|
4561
|
+
j = 0;
|
|
4562
|
+
break;
|
|
4563
|
+
}
|
|
4673
4564
|
}
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
}
|
|
4565
|
+
if (j === 1)
|
|
4566
|
+
throw Error(invalidEncoding);
|
|
4567
|
+
return offset - start;
|
|
4568
|
+
};
|
|
4569
|
+
|
|
4570
|
+
/**
|
|
4571
|
+
* Tests if the specified string appears to be base64 encoded.
|
|
4572
|
+
* @param {string} string String to test
|
|
4573
|
+
* @returns {boolean} `true` if probably base64 encoded, otherwise false
|
|
4574
|
+
*/
|
|
4575
|
+
base64.test = function test(string) {
|
|
4576
|
+
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
|
|
4577
|
+
};
|
|
4578
|
+
} (base64$1));
|
|
4678
4579
|
|
|
4679
|
-
var
|
|
4680
|
-
|
|
4580
|
+
var eventemitter = EventEmitter;
|
|
4581
|
+
|
|
4582
|
+
/**
|
|
4583
|
+
* Constructs a new event emitter instance.
|
|
4584
|
+
* @classdesc A minimal event emitter.
|
|
4585
|
+
* @memberof util
|
|
4586
|
+
* @constructor
|
|
4587
|
+
*/
|
|
4588
|
+
function EventEmitter() {
|
|
4589
|
+
|
|
4590
|
+
/**
|
|
4591
|
+
* Registered listeners.
|
|
4592
|
+
* @type {Object.<string,*>}
|
|
4593
|
+
* @private
|
|
4594
|
+
*/
|
|
4595
|
+
this._listeners = {};
|
|
4596
|
+
}
|
|
4597
|
+
|
|
4598
|
+
/**
|
|
4599
|
+
* Registers an event listener.
|
|
4600
|
+
* @param {string} evt Event name
|
|
4601
|
+
* @param {function} fn Listener
|
|
4602
|
+
* @param {*} [ctx] Listener context
|
|
4603
|
+
* @returns {util.EventEmitter} `this`
|
|
4604
|
+
*/
|
|
4605
|
+
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
4606
|
+
(this._listeners[evt] || (this._listeners[evt] = [])).push({
|
|
4607
|
+
fn : fn,
|
|
4608
|
+
ctx : ctx || this
|
|
4609
|
+
});
|
|
4610
|
+
return this;
|
|
4611
|
+
};
|
|
4612
|
+
|
|
4613
|
+
/**
|
|
4614
|
+
* Removes an event listener or any matching listeners if arguments are omitted.
|
|
4615
|
+
* @param {string} [evt] Event name. Removes all listeners if omitted.
|
|
4616
|
+
* @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
|
|
4617
|
+
* @returns {util.EventEmitter} `this`
|
|
4618
|
+
*/
|
|
4619
|
+
EventEmitter.prototype.off = function off(evt, fn) {
|
|
4620
|
+
if (evt === undefined)
|
|
4621
|
+
this._listeners = {};
|
|
4622
|
+
else {
|
|
4623
|
+
if (fn === undefined)
|
|
4624
|
+
this._listeners[evt] = [];
|
|
4625
|
+
else {
|
|
4626
|
+
var listeners = this._listeners[evt];
|
|
4627
|
+
for (var i = 0; i < listeners.length;)
|
|
4628
|
+
if (listeners[i].fn === fn)
|
|
4629
|
+
listeners.splice(i, 1);
|
|
4630
|
+
else
|
|
4631
|
+
++i;
|
|
4632
|
+
}
|
|
4633
|
+
}
|
|
4634
|
+
return this;
|
|
4635
|
+
};
|
|
4636
|
+
|
|
4637
|
+
/**
|
|
4638
|
+
* Emits an event by calling its listeners with the specified arguments.
|
|
4639
|
+
* @param {string} evt Event name
|
|
4640
|
+
* @param {...*} args Arguments
|
|
4641
|
+
* @returns {util.EventEmitter} `this`
|
|
4642
|
+
*/
|
|
4643
|
+
EventEmitter.prototype.emit = function emit(evt) {
|
|
4644
|
+
var listeners = this._listeners[evt];
|
|
4645
|
+
if (listeners) {
|
|
4646
|
+
var args = [],
|
|
4647
|
+
i = 1;
|
|
4648
|
+
for (; i < arguments.length;)
|
|
4649
|
+
args.push(arguments[i++]);
|
|
4650
|
+
for (i = 0; i < listeners.length;)
|
|
4651
|
+
listeners[i].fn.apply(listeners[i++].ctx, args);
|
|
4652
|
+
}
|
|
4653
|
+
return this;
|
|
4654
|
+
};
|
|
4681
4655
|
|
|
4682
|
-
|
|
4683
|
-
if (hasRequiredFloat) return float;
|
|
4684
|
-
hasRequiredFloat = 1;
|
|
4656
|
+
var float = factory(factory);
|
|
4685
4657
|
|
|
4686
|
-
|
|
4658
|
+
/**
|
|
4659
|
+
* Reads / writes floats / doubles from / to buffers.
|
|
4660
|
+
* @name util.float
|
|
4661
|
+
* @namespace
|
|
4662
|
+
*/
|
|
4687
4663
|
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4664
|
+
/**
|
|
4665
|
+
* Writes a 32 bit float to a buffer using little endian byte order.
|
|
4666
|
+
* @name util.float.writeFloatLE
|
|
4667
|
+
* @function
|
|
4668
|
+
* @param {number} val Value to write
|
|
4669
|
+
* @param {Uint8Array} buf Target buffer
|
|
4670
|
+
* @param {number} pos Target buffer offset
|
|
4671
|
+
* @returns {undefined}
|
|
4672
|
+
*/
|
|
4693
4673
|
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4674
|
+
/**
|
|
4675
|
+
* Writes a 32 bit float to a buffer using big endian byte order.
|
|
4676
|
+
* @name util.float.writeFloatBE
|
|
4677
|
+
* @function
|
|
4678
|
+
* @param {number} val Value to write
|
|
4679
|
+
* @param {Uint8Array} buf Target buffer
|
|
4680
|
+
* @param {number} pos Target buffer offset
|
|
4681
|
+
* @returns {undefined}
|
|
4682
|
+
*/
|
|
4703
4683
|
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
*/
|
|
4684
|
+
/**
|
|
4685
|
+
* Reads a 32 bit float from a buffer using little endian byte order.
|
|
4686
|
+
* @name util.float.readFloatLE
|
|
4687
|
+
* @function
|
|
4688
|
+
* @param {Uint8Array} buf Source buffer
|
|
4689
|
+
* @param {number} pos Source buffer offset
|
|
4690
|
+
* @returns {number} Value read
|
|
4691
|
+
*/
|
|
4713
4692
|
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4693
|
+
/**
|
|
4694
|
+
* Reads a 32 bit float from a buffer using big endian byte order.
|
|
4695
|
+
* @name util.float.readFloatBE
|
|
4696
|
+
* @function
|
|
4697
|
+
* @param {Uint8Array} buf Source buffer
|
|
4698
|
+
* @param {number} pos Source buffer offset
|
|
4699
|
+
* @returns {number} Value read
|
|
4700
|
+
*/
|
|
4722
4701
|
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4702
|
+
/**
|
|
4703
|
+
* Writes a 64 bit double to a buffer using little endian byte order.
|
|
4704
|
+
* @name util.float.writeDoubleLE
|
|
4705
|
+
* @function
|
|
4706
|
+
* @param {number} val Value to write
|
|
4707
|
+
* @param {Uint8Array} buf Target buffer
|
|
4708
|
+
* @param {number} pos Target buffer offset
|
|
4709
|
+
* @returns {undefined}
|
|
4710
|
+
*/
|
|
4731
4711
|
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4712
|
+
/**
|
|
4713
|
+
* Writes a 64 bit double to a buffer using big endian byte order.
|
|
4714
|
+
* @name util.float.writeDoubleBE
|
|
4715
|
+
* @function
|
|
4716
|
+
* @param {number} val Value to write
|
|
4717
|
+
* @param {Uint8Array} buf Target buffer
|
|
4718
|
+
* @param {number} pos Target buffer offset
|
|
4719
|
+
* @returns {undefined}
|
|
4720
|
+
*/
|
|
4741
4721
|
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
*/
|
|
4722
|
+
/**
|
|
4723
|
+
* Reads a 64 bit double from a buffer using little endian byte order.
|
|
4724
|
+
* @name util.float.readDoubleLE
|
|
4725
|
+
* @function
|
|
4726
|
+
* @param {Uint8Array} buf Source buffer
|
|
4727
|
+
* @param {number} pos Source buffer offset
|
|
4728
|
+
* @returns {number} Value read
|
|
4729
|
+
*/
|
|
4751
4730
|
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4731
|
+
/**
|
|
4732
|
+
* Reads a 64 bit double from a buffer using big endian byte order.
|
|
4733
|
+
* @name util.float.readDoubleBE
|
|
4734
|
+
* @function
|
|
4735
|
+
* @param {Uint8Array} buf Source buffer
|
|
4736
|
+
* @param {number} pos Source buffer offset
|
|
4737
|
+
* @returns {number} Value read
|
|
4738
|
+
*/
|
|
4760
4739
|
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
* @name util.float.readDoubleBE
|
|
4764
|
-
* @function
|
|
4765
|
-
* @param {Uint8Array} buf Source buffer
|
|
4766
|
-
* @param {number} pos Source buffer offset
|
|
4767
|
-
* @returns {number} Value read
|
|
4768
|
-
*/
|
|
4740
|
+
// Factory function for the purpose of node-based testing in modified global environments
|
|
4741
|
+
function factory(exports) {
|
|
4769
4742
|
|
|
4770
|
-
|
|
4771
|
-
|
|
4743
|
+
// float: typed array
|
|
4744
|
+
if (typeof Float32Array !== "undefined") (function() {
|
|
4772
4745
|
|
|
4773
|
-
|
|
4774
|
-
|
|
4746
|
+
var f32 = new Float32Array([ -0 ]),
|
|
4747
|
+
f8b = new Uint8Array(f32.buffer),
|
|
4748
|
+
le = f8b[3] === 128;
|
|
4775
4749
|
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4750
|
+
function writeFloat_f32_cpy(val, buf, pos) {
|
|
4751
|
+
f32[0] = val;
|
|
4752
|
+
buf[pos ] = f8b[0];
|
|
4753
|
+
buf[pos + 1] = f8b[1];
|
|
4754
|
+
buf[pos + 2] = f8b[2];
|
|
4755
|
+
buf[pos + 3] = f8b[3];
|
|
4756
|
+
}
|
|
4779
4757
|
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4758
|
+
function writeFloat_f32_rev(val, buf, pos) {
|
|
4759
|
+
f32[0] = val;
|
|
4760
|
+
buf[pos ] = f8b[3];
|
|
4761
|
+
buf[pos + 1] = f8b[2];
|
|
4762
|
+
buf[pos + 2] = f8b[1];
|
|
4763
|
+
buf[pos + 3] = f8b[0];
|
|
4764
|
+
}
|
|
4787
4765
|
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4766
|
+
/* istanbul ignore next */
|
|
4767
|
+
exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
|
|
4768
|
+
/* istanbul ignore next */
|
|
4769
|
+
exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
|
|
4770
|
+
|
|
4771
|
+
function readFloat_f32_cpy(buf, pos) {
|
|
4772
|
+
f8b[0] = buf[pos ];
|
|
4773
|
+
f8b[1] = buf[pos + 1];
|
|
4774
|
+
f8b[2] = buf[pos + 2];
|
|
4775
|
+
f8b[3] = buf[pos + 3];
|
|
4776
|
+
return f32[0];
|
|
4777
|
+
}
|
|
4795
4778
|
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
f8b[1] = buf[pos + 1];
|
|
4804
|
-
f8b[2] = buf[pos + 2];
|
|
4805
|
-
f8b[3] = buf[pos + 3];
|
|
4806
|
-
return f32[0];
|
|
4807
|
-
}
|
|
4779
|
+
function readFloat_f32_rev(buf, pos) {
|
|
4780
|
+
f8b[3] = buf[pos ];
|
|
4781
|
+
f8b[2] = buf[pos + 1];
|
|
4782
|
+
f8b[1] = buf[pos + 2];
|
|
4783
|
+
f8b[0] = buf[pos + 3];
|
|
4784
|
+
return f32[0];
|
|
4785
|
+
}
|
|
4808
4786
|
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4787
|
+
/* istanbul ignore next */
|
|
4788
|
+
exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
|
|
4789
|
+
/* istanbul ignore next */
|
|
4790
|
+
exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
|
|
4791
|
+
|
|
4792
|
+
// float: ieee754
|
|
4793
|
+
})(); else (function() {
|
|
4794
|
+
|
|
4795
|
+
function writeFloat_ieee754(writeUint, val, buf, pos) {
|
|
4796
|
+
var sign = val < 0 ? 1 : 0;
|
|
4797
|
+
if (sign)
|
|
4798
|
+
val = -val;
|
|
4799
|
+
if (val === 0)
|
|
4800
|
+
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
|
|
4801
|
+
else if (isNaN(val))
|
|
4802
|
+
writeUint(2143289344, buf, pos);
|
|
4803
|
+
else if (val > 3.4028234663852886e+38) // +-Infinity
|
|
4804
|
+
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
|
|
4805
|
+
else if (val < 1.1754943508222875e-38) // denormal
|
|
4806
|
+
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
|
|
4807
|
+
else {
|
|
4808
|
+
var exponent = Math.floor(Math.log(val) / Math.LN2),
|
|
4809
|
+
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
|
|
4810
|
+
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4816
4813
|
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
else if (val > 3.4028234663852886e+38) // +-Infinity
|
|
4834
|
-
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
|
|
4835
|
-
else if (val < 1.1754943508222875e-38) // denormal
|
|
4836
|
-
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
|
|
4837
|
-
else {
|
|
4838
|
-
var exponent = Math.floor(Math.log(val) / Math.LN2),
|
|
4839
|
-
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
|
|
4840
|
-
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
|
|
4841
|
-
}
|
|
4842
|
-
}
|
|
4814
|
+
exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
|
|
4815
|
+
exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
|
|
4816
|
+
|
|
4817
|
+
function readFloat_ieee754(readUint, buf, pos) {
|
|
4818
|
+
var uint = readUint(buf, pos),
|
|
4819
|
+
sign = (uint >> 31) * 2 + 1,
|
|
4820
|
+
exponent = uint >>> 23 & 255,
|
|
4821
|
+
mantissa = uint & 8388607;
|
|
4822
|
+
return exponent === 255
|
|
4823
|
+
? mantissa
|
|
4824
|
+
? NaN
|
|
4825
|
+
: sign * Infinity
|
|
4826
|
+
: exponent === 0 // denormal
|
|
4827
|
+
? sign * 1.401298464324817e-45 * mantissa
|
|
4828
|
+
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
|
|
4829
|
+
}
|
|
4843
4830
|
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
function readFloat_ieee754(readUint, buf, pos) {
|
|
4848
|
-
var uint = readUint(buf, pos),
|
|
4849
|
-
sign = (uint >> 31) * 2 + 1,
|
|
4850
|
-
exponent = uint >>> 23 & 255,
|
|
4851
|
-
mantissa = uint & 8388607;
|
|
4852
|
-
return exponent === 255
|
|
4853
|
-
? mantissa
|
|
4854
|
-
? NaN
|
|
4855
|
-
: sign * Infinity
|
|
4856
|
-
: exponent === 0 // denormal
|
|
4857
|
-
? sign * 1.401298464324817e-45 * mantissa
|
|
4858
|
-
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
|
|
4859
|
-
}
|
|
4831
|
+
exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
|
|
4832
|
+
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
|
|
4860
4833
|
|
|
4861
|
-
|
|
4862
|
-
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
|
|
4834
|
+
})();
|
|
4863
4835
|
|
|
4864
|
-
|
|
4836
|
+
// double: typed array
|
|
4837
|
+
if (typeof Float64Array !== "undefined") (function() {
|
|
4865
4838
|
|
|
4866
|
-
|
|
4867
|
-
|
|
4839
|
+
var f64 = new Float64Array([-0]),
|
|
4840
|
+
f8b = new Uint8Array(f64.buffer),
|
|
4841
|
+
le = f8b[7] === 128;
|
|
4868
4842
|
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4843
|
+
function writeDouble_f64_cpy(val, buf, pos) {
|
|
4844
|
+
f64[0] = val;
|
|
4845
|
+
buf[pos ] = f8b[0];
|
|
4846
|
+
buf[pos + 1] = f8b[1];
|
|
4847
|
+
buf[pos + 2] = f8b[2];
|
|
4848
|
+
buf[pos + 3] = f8b[3];
|
|
4849
|
+
buf[pos + 4] = f8b[4];
|
|
4850
|
+
buf[pos + 5] = f8b[5];
|
|
4851
|
+
buf[pos + 6] = f8b[6];
|
|
4852
|
+
buf[pos + 7] = f8b[7];
|
|
4853
|
+
}
|
|
4872
4854
|
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4855
|
+
function writeDouble_f64_rev(val, buf, pos) {
|
|
4856
|
+
f64[0] = val;
|
|
4857
|
+
buf[pos ] = f8b[7];
|
|
4858
|
+
buf[pos + 1] = f8b[6];
|
|
4859
|
+
buf[pos + 2] = f8b[5];
|
|
4860
|
+
buf[pos + 3] = f8b[4];
|
|
4861
|
+
buf[pos + 4] = f8b[3];
|
|
4862
|
+
buf[pos + 5] = f8b[2];
|
|
4863
|
+
buf[pos + 6] = f8b[1];
|
|
4864
|
+
buf[pos + 7] = f8b[0];
|
|
4865
|
+
}
|
|
4884
4866
|
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4867
|
+
/* istanbul ignore next */
|
|
4868
|
+
exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
|
|
4869
|
+
/* istanbul ignore next */
|
|
4870
|
+
exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
|
|
4871
|
+
|
|
4872
|
+
function readDouble_f64_cpy(buf, pos) {
|
|
4873
|
+
f8b[0] = buf[pos ];
|
|
4874
|
+
f8b[1] = buf[pos + 1];
|
|
4875
|
+
f8b[2] = buf[pos + 2];
|
|
4876
|
+
f8b[3] = buf[pos + 3];
|
|
4877
|
+
f8b[4] = buf[pos + 4];
|
|
4878
|
+
f8b[5] = buf[pos + 5];
|
|
4879
|
+
f8b[6] = buf[pos + 6];
|
|
4880
|
+
f8b[7] = buf[pos + 7];
|
|
4881
|
+
return f64[0];
|
|
4882
|
+
}
|
|
4896
4883
|
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
f8b[5] = buf[pos + 5];
|
|
4909
|
-
f8b[6] = buf[pos + 6];
|
|
4910
|
-
f8b[7] = buf[pos + 7];
|
|
4911
|
-
return f64[0];
|
|
4912
|
-
}
|
|
4884
|
+
function readDouble_f64_rev(buf, pos) {
|
|
4885
|
+
f8b[7] = buf[pos ];
|
|
4886
|
+
f8b[6] = buf[pos + 1];
|
|
4887
|
+
f8b[5] = buf[pos + 2];
|
|
4888
|
+
f8b[4] = buf[pos + 3];
|
|
4889
|
+
f8b[3] = buf[pos + 4];
|
|
4890
|
+
f8b[2] = buf[pos + 5];
|
|
4891
|
+
f8b[1] = buf[pos + 6];
|
|
4892
|
+
f8b[0] = buf[pos + 7];
|
|
4893
|
+
return f64[0];
|
|
4894
|
+
}
|
|
4913
4895
|
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4896
|
+
/* istanbul ignore next */
|
|
4897
|
+
exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
|
|
4898
|
+
/* istanbul ignore next */
|
|
4899
|
+
exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
|
|
4900
|
+
|
|
4901
|
+
// double: ieee754
|
|
4902
|
+
})(); else (function() {
|
|
4903
|
+
|
|
4904
|
+
function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
|
|
4905
|
+
var sign = val < 0 ? 1 : 0;
|
|
4906
|
+
if (sign)
|
|
4907
|
+
val = -val;
|
|
4908
|
+
if (val === 0) {
|
|
4909
|
+
writeUint(0, buf, pos + off0);
|
|
4910
|
+
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
|
|
4911
|
+
} else if (isNaN(val)) {
|
|
4912
|
+
writeUint(0, buf, pos + off0);
|
|
4913
|
+
writeUint(2146959360, buf, pos + off1);
|
|
4914
|
+
} else if (val > 1.7976931348623157e+308) { // +-Infinity
|
|
4915
|
+
writeUint(0, buf, pos + off0);
|
|
4916
|
+
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
|
|
4917
|
+
} else {
|
|
4918
|
+
var mantissa;
|
|
4919
|
+
if (val < 2.2250738585072014e-308) { // denormal
|
|
4920
|
+
mantissa = val / 5e-324;
|
|
4921
|
+
writeUint(mantissa >>> 0, buf, pos + off0);
|
|
4922
|
+
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
|
|
4923
|
+
} else {
|
|
4924
|
+
var exponent = Math.floor(Math.log(val) / Math.LN2);
|
|
4925
|
+
if (exponent === 1024)
|
|
4926
|
+
exponent = 1023;
|
|
4927
|
+
mantissa = val * Math.pow(2, -exponent);
|
|
4928
|
+
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
|
|
4929
|
+
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
|
|
4930
|
+
}
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4925
4933
|
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
writeUint(2146959360, buf, pos + off1);
|
|
4944
|
-
} else if (val > 1.7976931348623157e+308) { // +-Infinity
|
|
4945
|
-
writeUint(0, buf, pos + off0);
|
|
4946
|
-
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
|
|
4947
|
-
} else {
|
|
4948
|
-
var mantissa;
|
|
4949
|
-
if (val < 2.2250738585072014e-308) { // denormal
|
|
4950
|
-
mantissa = val / 5e-324;
|
|
4951
|
-
writeUint(mantissa >>> 0, buf, pos + off0);
|
|
4952
|
-
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
|
|
4953
|
-
} else {
|
|
4954
|
-
var exponent = Math.floor(Math.log(val) / Math.LN2);
|
|
4955
|
-
if (exponent === 1024)
|
|
4956
|
-
exponent = 1023;
|
|
4957
|
-
mantissa = val * Math.pow(2, -exponent);
|
|
4958
|
-
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
|
|
4959
|
-
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
|
|
4960
|
-
}
|
|
4961
|
-
}
|
|
4962
|
-
}
|
|
4934
|
+
exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
|
|
4935
|
+
exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
|
|
4936
|
+
|
|
4937
|
+
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
|
|
4938
|
+
var lo = readUint(buf, pos + off0),
|
|
4939
|
+
hi = readUint(buf, pos + off1);
|
|
4940
|
+
var sign = (hi >> 31) * 2 + 1,
|
|
4941
|
+
exponent = hi >>> 20 & 2047,
|
|
4942
|
+
mantissa = 4294967296 * (hi & 1048575) + lo;
|
|
4943
|
+
return exponent === 2047
|
|
4944
|
+
? mantissa
|
|
4945
|
+
? NaN
|
|
4946
|
+
: sign * Infinity
|
|
4947
|
+
: exponent === 0 // denormal
|
|
4948
|
+
? sign * 5e-324 * mantissa
|
|
4949
|
+
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
|
|
4950
|
+
}
|
|
4963
4951
|
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
|
|
4968
|
-
var lo = readUint(buf, pos + off0),
|
|
4969
|
-
hi = readUint(buf, pos + off1);
|
|
4970
|
-
var sign = (hi >> 31) * 2 + 1,
|
|
4971
|
-
exponent = hi >>> 20 & 2047,
|
|
4972
|
-
mantissa = 4294967296 * (hi & 1048575) + lo;
|
|
4973
|
-
return exponent === 2047
|
|
4974
|
-
? mantissa
|
|
4975
|
-
? NaN
|
|
4976
|
-
: sign * Infinity
|
|
4977
|
-
: exponent === 0 // denormal
|
|
4978
|
-
? sign * 5e-324 * mantissa
|
|
4979
|
-
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
|
|
4980
|
-
}
|
|
4952
|
+
exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
|
|
4953
|
+
exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
|
|
4981
4954
|
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
| buf[pos + 1] << 16
|
|
5016
|
-
| buf[pos + 2] << 8
|
|
5017
|
-
| buf[pos + 3]) >>> 0;
|
|
5018
|
-
}
|
|
5019
|
-
return float;
|
|
4955
|
+
})();
|
|
4956
|
+
|
|
4957
|
+
return exports;
|
|
4958
|
+
}
|
|
4959
|
+
|
|
4960
|
+
// uint helpers
|
|
4961
|
+
|
|
4962
|
+
function writeUintLE(val, buf, pos) {
|
|
4963
|
+
buf[pos ] = val & 255;
|
|
4964
|
+
buf[pos + 1] = val >>> 8 & 255;
|
|
4965
|
+
buf[pos + 2] = val >>> 16 & 255;
|
|
4966
|
+
buf[pos + 3] = val >>> 24;
|
|
4967
|
+
}
|
|
4968
|
+
|
|
4969
|
+
function writeUintBE(val, buf, pos) {
|
|
4970
|
+
buf[pos ] = val >>> 24;
|
|
4971
|
+
buf[pos + 1] = val >>> 16 & 255;
|
|
4972
|
+
buf[pos + 2] = val >>> 8 & 255;
|
|
4973
|
+
buf[pos + 3] = val & 255;
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4976
|
+
function readUintLE(buf, pos) {
|
|
4977
|
+
return (buf[pos ]
|
|
4978
|
+
| buf[pos + 1] << 8
|
|
4979
|
+
| buf[pos + 2] << 16
|
|
4980
|
+
| buf[pos + 3] << 24) >>> 0;
|
|
4981
|
+
}
|
|
4982
|
+
|
|
4983
|
+
function readUintBE(buf, pos) {
|
|
4984
|
+
return (buf[pos ] << 24
|
|
4985
|
+
| buf[pos + 1] << 16
|
|
4986
|
+
| buf[pos + 2] << 8
|
|
4987
|
+
| buf[pos + 3]) >>> 0;
|
|
5020
4988
|
}
|
|
5021
4989
|
|
|
5022
|
-
var inquire_1;
|
|
5023
|
-
var hasRequiredInquire;
|
|
5024
|
-
|
|
5025
|
-
function requireInquire () {
|
|
5026
|
-
if (hasRequiredInquire) return inquire_1;
|
|
5027
|
-
hasRequiredInquire = 1;
|
|
5028
|
-
inquire_1 = inquire;
|
|
4990
|
+
var inquire_1 = inquire;
|
|
5029
4991
|
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
}
|
|
5044
|
-
return inquire_1;
|
|
4992
|
+
/**
|
|
4993
|
+
* Requires a module only if available.
|
|
4994
|
+
* @memberof util
|
|
4995
|
+
* @param {string} moduleName Module to require
|
|
4996
|
+
* @returns {?Object} Required module if available and not empty, otherwise `null`
|
|
4997
|
+
*/
|
|
4998
|
+
function inquire(moduleName) {
|
|
4999
|
+
try {
|
|
5000
|
+
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
|
|
5001
|
+
if (mod && (mod.length || Object.keys(mod).length))
|
|
5002
|
+
return mod;
|
|
5003
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
5004
|
+
return null;
|
|
5045
5005
|
}
|
|
5046
5006
|
|
|
5047
5007
|
var utf8$2 = {};
|
|
5048
5008
|
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
function requireUtf8 () {
|
|
5052
|
-
if (hasRequiredUtf8) return utf8$2;
|
|
5053
|
-
hasRequiredUtf8 = 1;
|
|
5054
|
-
(function (exports) {
|
|
5009
|
+
(function (exports) {
|
|
5055
5010
|
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
/**
|
|
5064
|
-
* Calculates the UTF8 byte length of a string.
|
|
5065
|
-
* @param {string} string String
|
|
5066
|
-
* @returns {number} Byte length
|
|
5067
|
-
*/
|
|
5068
|
-
utf8.length = function utf8_length(string) {
|
|
5069
|
-
var len = 0,
|
|
5070
|
-
c = 0;
|
|
5071
|
-
for (var i = 0; i < string.length; ++i) {
|
|
5072
|
-
c = string.charCodeAt(i);
|
|
5073
|
-
if (c < 128)
|
|
5074
|
-
len += 1;
|
|
5075
|
-
else if (c < 2048)
|
|
5076
|
-
len += 2;
|
|
5077
|
-
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
5078
|
-
++i;
|
|
5079
|
-
len += 4;
|
|
5080
|
-
} else
|
|
5081
|
-
len += 3;
|
|
5082
|
-
}
|
|
5083
|
-
return len;
|
|
5084
|
-
};
|
|
5085
|
-
|
|
5086
|
-
/**
|
|
5087
|
-
* Reads UTF8 bytes as a string.
|
|
5088
|
-
* @param {Uint8Array} buffer Source buffer
|
|
5089
|
-
* @param {number} start Source start
|
|
5090
|
-
* @param {number} end Source end
|
|
5091
|
-
* @returns {string} String read
|
|
5092
|
-
*/
|
|
5093
|
-
utf8.read = function utf8_read(buffer, start, end) {
|
|
5094
|
-
var len = end - start;
|
|
5095
|
-
if (len < 1)
|
|
5096
|
-
return "";
|
|
5097
|
-
var parts = null,
|
|
5098
|
-
chunk = [],
|
|
5099
|
-
i = 0, // char offset
|
|
5100
|
-
t; // temporary
|
|
5101
|
-
while (start < end) {
|
|
5102
|
-
t = buffer[start++];
|
|
5103
|
-
if (t < 128)
|
|
5104
|
-
chunk[i++] = t;
|
|
5105
|
-
else if (t > 191 && t < 224)
|
|
5106
|
-
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
5107
|
-
else if (t > 239 && t < 365) {
|
|
5108
|
-
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
5109
|
-
chunk[i++] = 0xD800 + (t >> 10);
|
|
5110
|
-
chunk[i++] = 0xDC00 + (t & 1023);
|
|
5111
|
-
} else
|
|
5112
|
-
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
5113
|
-
if (i > 8191) {
|
|
5114
|
-
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
5115
|
-
i = 0;
|
|
5116
|
-
}
|
|
5117
|
-
}
|
|
5118
|
-
if (parts) {
|
|
5119
|
-
if (i)
|
|
5120
|
-
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
5121
|
-
return parts.join("");
|
|
5122
|
-
}
|
|
5123
|
-
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
5124
|
-
};
|
|
5125
|
-
|
|
5126
|
-
/**
|
|
5127
|
-
* Writes a string as UTF8 bytes.
|
|
5128
|
-
* @param {string} string Source string
|
|
5129
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
5130
|
-
* @param {number} offset Destination offset
|
|
5131
|
-
* @returns {number} Bytes written
|
|
5132
|
-
*/
|
|
5133
|
-
utf8.write = function utf8_write(string, buffer, offset) {
|
|
5134
|
-
var start = offset,
|
|
5135
|
-
c1, // character 1
|
|
5136
|
-
c2; // character 2
|
|
5137
|
-
for (var i = 0; i < string.length; ++i) {
|
|
5138
|
-
c1 = string.charCodeAt(i);
|
|
5139
|
-
if (c1 < 128) {
|
|
5140
|
-
buffer[offset++] = c1;
|
|
5141
|
-
} else if (c1 < 2048) {
|
|
5142
|
-
buffer[offset++] = c1 >> 6 | 192;
|
|
5143
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
5144
|
-
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
5145
|
-
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
5146
|
-
++i;
|
|
5147
|
-
buffer[offset++] = c1 >> 18 | 240;
|
|
5148
|
-
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
5149
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
5150
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
5151
|
-
} else {
|
|
5152
|
-
buffer[offset++] = c1 >> 12 | 224;
|
|
5153
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
5154
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
5155
|
-
}
|
|
5156
|
-
}
|
|
5157
|
-
return offset - start;
|
|
5158
|
-
};
|
|
5159
|
-
} (utf8$2));
|
|
5160
|
-
return utf8$2;
|
|
5161
|
-
}
|
|
5162
|
-
|
|
5163
|
-
var pool_1;
|
|
5164
|
-
var hasRequiredPool;
|
|
5165
|
-
|
|
5166
|
-
function requirePool () {
|
|
5167
|
-
if (hasRequiredPool) return pool_1;
|
|
5168
|
-
hasRequiredPool = 1;
|
|
5169
|
-
pool_1 = pool;
|
|
5011
|
+
/**
|
|
5012
|
+
* A minimal UTF8 implementation for number arrays.
|
|
5013
|
+
* @memberof util
|
|
5014
|
+
* @namespace
|
|
5015
|
+
*/
|
|
5016
|
+
var utf8 = exports;
|
|
5170
5017
|
|
|
5171
5018
|
/**
|
|
5172
|
-
*
|
|
5173
|
-
* @
|
|
5174
|
-
* @
|
|
5175
|
-
* @param {number} size Buffer size
|
|
5176
|
-
* @returns {Uint8Array} Buffer
|
|
5019
|
+
* Calculates the UTF8 byte length of a string.
|
|
5020
|
+
* @param {string} string String
|
|
5021
|
+
* @returns {number} Byte length
|
|
5177
5022
|
*/
|
|
5023
|
+
utf8.length = function utf8_length(string) {
|
|
5024
|
+
var len = 0,
|
|
5025
|
+
c = 0;
|
|
5026
|
+
for (var i = 0; i < string.length; ++i) {
|
|
5027
|
+
c = string.charCodeAt(i);
|
|
5028
|
+
if (c < 128)
|
|
5029
|
+
len += 1;
|
|
5030
|
+
else if (c < 2048)
|
|
5031
|
+
len += 2;
|
|
5032
|
+
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
5033
|
+
++i;
|
|
5034
|
+
len += 4;
|
|
5035
|
+
} else
|
|
5036
|
+
len += 3;
|
|
5037
|
+
}
|
|
5038
|
+
return len;
|
|
5039
|
+
};
|
|
5178
5040
|
|
|
5179
5041
|
/**
|
|
5180
|
-
*
|
|
5181
|
-
* @
|
|
5182
|
-
* @
|
|
5183
|
-
* @param {number}
|
|
5184
|
-
* @
|
|
5185
|
-
* @returns {Uint8Array} Buffer slice
|
|
5186
|
-
* @this {Uint8Array}
|
|
5042
|
+
* Reads UTF8 bytes as a string.
|
|
5043
|
+
* @param {Uint8Array} buffer Source buffer
|
|
5044
|
+
* @param {number} start Source start
|
|
5045
|
+
* @param {number} end Source end
|
|
5046
|
+
* @returns {string} String read
|
|
5187
5047
|
*/
|
|
5048
|
+
utf8.read = function utf8_read(buffer, start, end) {
|
|
5049
|
+
var len = end - start;
|
|
5050
|
+
if (len < 1)
|
|
5051
|
+
return "";
|
|
5052
|
+
var parts = null,
|
|
5053
|
+
chunk = [],
|
|
5054
|
+
i = 0, // char offset
|
|
5055
|
+
t; // temporary
|
|
5056
|
+
while (start < end) {
|
|
5057
|
+
t = buffer[start++];
|
|
5058
|
+
if (t < 128)
|
|
5059
|
+
chunk[i++] = t;
|
|
5060
|
+
else if (t > 191 && t < 224)
|
|
5061
|
+
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
5062
|
+
else if (t > 239 && t < 365) {
|
|
5063
|
+
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
5064
|
+
chunk[i++] = 0xD800 + (t >> 10);
|
|
5065
|
+
chunk[i++] = 0xDC00 + (t & 1023);
|
|
5066
|
+
} else
|
|
5067
|
+
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
5068
|
+
if (i > 8191) {
|
|
5069
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
5070
|
+
i = 0;
|
|
5071
|
+
}
|
|
5072
|
+
}
|
|
5073
|
+
if (parts) {
|
|
5074
|
+
if (i)
|
|
5075
|
+
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
5076
|
+
return parts.join("");
|
|
5077
|
+
}
|
|
5078
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
5079
|
+
};
|
|
5188
5080
|
|
|
5189
5081
|
/**
|
|
5190
|
-
*
|
|
5191
|
-
* @
|
|
5192
|
-
* @
|
|
5193
|
-
* @param {
|
|
5194
|
-
* @
|
|
5195
|
-
* @param {number} [size=8192] Slab size
|
|
5196
|
-
* @returns {PoolAllocator} Pooled allocator
|
|
5082
|
+
* Writes a string as UTF8 bytes.
|
|
5083
|
+
* @param {string} string Source string
|
|
5084
|
+
* @param {Uint8Array} buffer Destination buffer
|
|
5085
|
+
* @param {number} offset Destination offset
|
|
5086
|
+
* @returns {number} Bytes written
|
|
5197
5087
|
*/
|
|
5198
|
-
function
|
|
5199
|
-
var
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
var
|
|
5203
|
-
|
|
5204
|
-
if (
|
|
5205
|
-
|
|
5206
|
-
if (
|
|
5207
|
-
|
|
5208
|
-
offset =
|
|
5088
|
+
utf8.write = function utf8_write(string, buffer, offset) {
|
|
5089
|
+
var start = offset,
|
|
5090
|
+
c1, // character 1
|
|
5091
|
+
c2; // character 2
|
|
5092
|
+
for (var i = 0; i < string.length; ++i) {
|
|
5093
|
+
c1 = string.charCodeAt(i);
|
|
5094
|
+
if (c1 < 128) {
|
|
5095
|
+
buffer[offset++] = c1;
|
|
5096
|
+
} else if (c1 < 2048) {
|
|
5097
|
+
buffer[offset++] = c1 >> 6 | 192;
|
|
5098
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
5099
|
+
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
5100
|
+
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
5101
|
+
++i;
|
|
5102
|
+
buffer[offset++] = c1 >> 18 | 240;
|
|
5103
|
+
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
5104
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
5105
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
5106
|
+
} else {
|
|
5107
|
+
buffer[offset++] = c1 >> 12 | 224;
|
|
5108
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
5109
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
5209
5110
|
}
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5111
|
+
}
|
|
5112
|
+
return offset - start;
|
|
5113
|
+
};
|
|
5114
|
+
} (utf8$2));
|
|
5115
|
+
|
|
5116
|
+
var pool_1 = pool;
|
|
5117
|
+
|
|
5118
|
+
/**
|
|
5119
|
+
* An allocator as used by {@link util.pool}.
|
|
5120
|
+
* @typedef PoolAllocator
|
|
5121
|
+
* @type {function}
|
|
5122
|
+
* @param {number} size Buffer size
|
|
5123
|
+
* @returns {Uint8Array} Buffer
|
|
5124
|
+
*/
|
|
5125
|
+
|
|
5126
|
+
/**
|
|
5127
|
+
* A slicer as used by {@link util.pool}.
|
|
5128
|
+
* @typedef PoolSlicer
|
|
5129
|
+
* @type {function}
|
|
5130
|
+
* @param {number} start Start offset
|
|
5131
|
+
* @param {number} end End offset
|
|
5132
|
+
* @returns {Uint8Array} Buffer slice
|
|
5133
|
+
* @this {Uint8Array}
|
|
5134
|
+
*/
|
|
5135
|
+
|
|
5136
|
+
/**
|
|
5137
|
+
* A general purpose buffer pool.
|
|
5138
|
+
* @memberof util
|
|
5139
|
+
* @function
|
|
5140
|
+
* @param {PoolAllocator} alloc Allocator
|
|
5141
|
+
* @param {PoolSlicer} slice Slicer
|
|
5142
|
+
* @param {number} [size=8192] Slab size
|
|
5143
|
+
* @returns {PoolAllocator} Pooled allocator
|
|
5144
|
+
*/
|
|
5145
|
+
function pool(alloc, slice, size) {
|
|
5146
|
+
var SIZE = size || 8192;
|
|
5147
|
+
var MAX = SIZE >>> 1;
|
|
5148
|
+
var slab = null;
|
|
5149
|
+
var offset = SIZE;
|
|
5150
|
+
return function pool_alloc(size) {
|
|
5151
|
+
if (size < 1 || size > MAX)
|
|
5152
|
+
return alloc(size);
|
|
5153
|
+
if (offset + size > SIZE) {
|
|
5154
|
+
slab = alloc(SIZE);
|
|
5155
|
+
offset = 0;
|
|
5156
|
+
}
|
|
5157
|
+
var buf = slice.call(slab, offset, offset += size);
|
|
5158
|
+
if (offset & 7) // align to 32 bit
|
|
5159
|
+
offset = (offset | 7) + 1;
|
|
5160
|
+
return buf;
|
|
5161
|
+
};
|
|
5217
5162
|
}
|
|
5218
5163
|
|
|
5219
5164
|
var longbits;
|
|
@@ -5433,25 +5378,25 @@ function requireMinimal () {
|
|
|
5433
5378
|
var util = exports;
|
|
5434
5379
|
|
|
5435
5380
|
// used to return a Promise where callback is omitted
|
|
5436
|
-
util.asPromise =
|
|
5381
|
+
util.asPromise = aspromise;
|
|
5437
5382
|
|
|
5438
5383
|
// converts to / from base64 encoded strings
|
|
5439
|
-
util.base64 =
|
|
5384
|
+
util.base64 = base64$1;
|
|
5440
5385
|
|
|
5441
5386
|
// base class of rpc.Service
|
|
5442
|
-
util.EventEmitter =
|
|
5387
|
+
util.EventEmitter = eventemitter;
|
|
5443
5388
|
|
|
5444
5389
|
// float handling accross browsers
|
|
5445
|
-
util.float =
|
|
5390
|
+
util.float = float;
|
|
5446
5391
|
|
|
5447
5392
|
// requires modules optionally and hides the call from bundlers
|
|
5448
|
-
util.inquire =
|
|
5393
|
+
util.inquire = inquire_1;
|
|
5449
5394
|
|
|
5450
5395
|
// converts to / from utf8 encoded strings
|
|
5451
|
-
util.utf8 =
|
|
5396
|
+
util.utf8 = utf8$2;
|
|
5452
5397
|
|
|
5453
5398
|
// provides a node-like buffer pool in the browser
|
|
5454
|
-
util.pool =
|
|
5399
|
+
util.pool = pool_1;
|
|
5455
5400
|
|
|
5456
5401
|
// utility to work with the low and high bits of a 64 bit value
|
|
5457
5402
|
util.LongBits = requireLongbits();
|
|
@@ -10236,7 +10181,10 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10236
10181
|
const txs = [];
|
|
10237
10182
|
for (let i = 0; i < history.length; i += 10) {
|
|
10238
10183
|
const batch = history.slice(i, i + 10);
|
|
10239
|
-
const result = yield Promise.all(batch.map(({ hash }) => this
|
|
10184
|
+
const result = yield Promise.all(batch.map(({ hash }) => __awaiter(this, void 0, void 0, function* () {
|
|
10185
|
+
const data = yield this.getTransactionData(hash, address);
|
|
10186
|
+
return data;
|
|
10187
|
+
})));
|
|
10240
10188
|
txs.push(...result);
|
|
10241
10189
|
xchainUtil.delay(2000); // Delay to avoid 503 from ninerealms server
|
|
10242
10190
|
}
|
|
@@ -10469,65 +10417,91 @@ class Client extends xchainClient.BaseXChainClient {
|
|
|
10469
10417
|
* @returns {Tx} The transaction details of the given transaction id.
|
|
10470
10418
|
*/
|
|
10471
10419
|
getTransactionData(txId, address) {
|
|
10472
|
-
var _a, _b, _c;
|
|
10420
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10473
10421
|
return __awaiter(this, void 0, void 0, function* () {
|
|
10474
|
-
const
|
|
10475
|
-
if (
|
|
10476
|
-
|
|
10477
|
-
const
|
|
10478
|
-
const
|
|
10479
|
-
if (!
|
|
10480
|
-
throw new Error(
|
|
10481
|
-
|
|
10482
|
-
const
|
|
10483
|
-
const
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
const
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
const
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10422
|
+
const txResult = yield this.fetchTransaction(txId);
|
|
10423
|
+
if (txResult && txResult.logs) {
|
|
10424
|
+
// extract values from the response
|
|
10425
|
+
const transferEvent = (_a = txResult.logs[0].events) === null || _a === void 0 ? void 0 : _a.find((event) => event.type === 'transfer');
|
|
10426
|
+
const messageEvent = (_b = txResult.logs[0].events) === null || _b === void 0 ? void 0 : _b.find((event) => event.type === 'message');
|
|
10427
|
+
if (!transferEvent || !messageEvent) {
|
|
10428
|
+
throw new Error('Invalid transaction data');
|
|
10429
|
+
}
|
|
10430
|
+
const attributeGroups = {};
|
|
10431
|
+
for (const attr of transferEvent.attributes) {
|
|
10432
|
+
if (!attributeGroups[attr.key]) {
|
|
10433
|
+
attributeGroups[attr.key] = [];
|
|
10434
|
+
}
|
|
10435
|
+
attributeGroups[attr.key].push(attr.value);
|
|
10436
|
+
}
|
|
10437
|
+
const assetAmount = attributeGroups['amount'][1]
|
|
10438
|
+
? attributeGroups['amount'][1].split(/(?<=\d)(?=\D)/).filter(Boolean)[0]
|
|
10439
|
+
: attributeGroups['amount'][0].split(/(?<=\d)(?=\D)/).filter(Boolean)[0];
|
|
10440
|
+
const assetString = attributeGroups['amount'][1]
|
|
10441
|
+
? attributeGroups['amount'][1]
|
|
10442
|
+
.split(/(?<=\d)(?=\D)/)
|
|
10443
|
+
.filter(Boolean)[1]
|
|
10444
|
+
.replace(/[a-z]/g, (letter) => letter.toUpperCase())
|
|
10445
|
+
: attributeGroups['amount'][0]
|
|
10446
|
+
.split(/(?<=\d)(?=\D)/)
|
|
10447
|
+
.filter(Boolean)[1]
|
|
10448
|
+
.replace(/[a-z]/g, (letter) => letter.toUpperCase());
|
|
10449
|
+
const fromAddress = ((_c = transferEvent.attributes.find((attr) => attr.key === 'sender')) === null || _c === void 0 ? void 0 : _c.value)
|
|
10450
|
+
? (_d = transferEvent.attributes.find((attr) => attr.key === 'sender')) === null || _d === void 0 ? void 0 : _d.value
|
|
10451
|
+
: address;
|
|
10452
|
+
const memo = ((_e = txResult.tx) === null || _e === void 0 ? void 0 : _e.body) ? txResult.tx.body.memo.split(':') : '';
|
|
10453
|
+
const toAddress = memo[2] ? memo[2] : '';
|
|
10454
|
+
const toAsset = memo[1] ? xchainUtil.assetFromStringEx(memo[1]) : AssetRuneNative;
|
|
10455
|
+
const date = new Date(txResult.timestamp);
|
|
10456
|
+
const typeString = (_f = messageEvent.attributes.find((attr) => attr.key === 'action')) === null || _f === void 0 ? void 0 : _f.value;
|
|
10457
|
+
const hash = txResult.txhash;
|
|
10458
|
+
if (assetString && hash && fromAddress && typeString) {
|
|
10459
|
+
const fromAsset = assetString === 'RUNE' ? AssetRuneNative : xchainUtil.assetFromStringEx(assetString);
|
|
10460
|
+
const txData = txResult && txResult.raw_log
|
|
10461
|
+
? getDepositTxDataFromLogs(txResult.logs, `${fromAddress}`, fromAsset, toAsset)
|
|
10500
10462
|
: null;
|
|
10501
|
-
//console.log(JSON.stringify(txData, null, 2))
|
|
10502
10463
|
if (!txData)
|
|
10503
10464
|
throw new Error(`Failed to get transaction data (tx-hash: ${txId})`);
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10465
|
+
if (isAssetRuneNative(toAsset) || toAsset.synth) {
|
|
10466
|
+
const { from, to, type } = txData;
|
|
10467
|
+
const tx = {
|
|
10468
|
+
asset: fromAsset,
|
|
10469
|
+
from: from,
|
|
10470
|
+
to: to,
|
|
10471
|
+
date: date,
|
|
10472
|
+
type: type,
|
|
10473
|
+
hash: hash,
|
|
10474
|
+
};
|
|
10475
|
+
return tx;
|
|
10476
|
+
}
|
|
10477
|
+
else {
|
|
10478
|
+
const tx = {
|
|
10479
|
+
asset: fromAsset,
|
|
10480
|
+
from: [{ from: fromAddress, amount: xchainUtil.baseAmount(assetAmount), asset: fromAsset }],
|
|
10481
|
+
to: [{ to: toAddress, amount: xchainUtil.baseAmount(memo[3]), asset: toAsset }],
|
|
10482
|
+
date: date,
|
|
10483
|
+
type: xchainClient.TxType.Transfer,
|
|
10484
|
+
hash: hash,
|
|
10485
|
+
};
|
|
10486
|
+
return tx;
|
|
10487
|
+
}
|
|
10488
|
+
}
|
|
10489
|
+
else {
|
|
10490
|
+
const tx = {
|
|
10491
|
+
asset: {
|
|
10492
|
+
chain: '',
|
|
10493
|
+
symbol: '',
|
|
10494
|
+
ticker: '',
|
|
10495
|
+
synth: false,
|
|
10496
|
+
},
|
|
10497
|
+
from: [],
|
|
10498
|
+
to: [],
|
|
10499
|
+
date: new Date(),
|
|
10500
|
+
type: xchainClient.TxType.Transfer,
|
|
10501
|
+
hash: '',
|
|
10512
10502
|
};
|
|
10503
|
+
return tx;
|
|
10513
10504
|
}
|
|
10514
|
-
// synths and other tx types
|
|
10515
|
-
const messageBody = JSON.stringify((_c = txResult.tx) === null || _c === void 0 ? void 0 : _c.body.messages).split(':');
|
|
10516
|
-
const assetTo = xchainUtil.assetFromStringEx(messageBody[7]);
|
|
10517
|
-
const txData = txResult && txResult.logs
|
|
10518
|
-
? getDepositTxDataFromLogs(txResult.logs, `${senderAddress}`, senderAsset, assetTo)
|
|
10519
|
-
: null;
|
|
10520
|
-
if (!txData)
|
|
10521
|
-
throw new Error(`Failed to get transaction data (tx-hash: ${txId})`);
|
|
10522
|
-
const { from, to, type } = txData;
|
|
10523
|
-
return {
|
|
10524
|
-
hash: txId,
|
|
10525
|
-
asset: senderAsset,
|
|
10526
|
-
from,
|
|
10527
|
-
to,
|
|
10528
|
-
date: new Date(txResult.timestamp),
|
|
10529
|
-
type,
|
|
10530
|
-
};
|
|
10531
10505
|
}
|
|
10532
10506
|
else {
|
|
10533
10507
|
return yield this.getTransactionDataThornode(txId);
|