@xchainjs/xchain-thorchain 0.25.1 → 0.25.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -2944,6 +2944,1330 @@ var bignumber = createCommonjsModule(function (module) {
2944
2944
  })(commonjsGlobal);
2945
2945
  });
2946
2946
 
2947
+ var long_1 = Long;
2948
+
2949
+ /**
2950
+ * wasm optimizations, to do native i64 multiplication and divide
2951
+ */
2952
+ var wasm = null;
2953
+
2954
+ try {
2955
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
2956
+ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11
2957
+ ])), {}).exports;
2958
+ } catch (e) {
2959
+ // no wasm support :(
2960
+ }
2961
+
2962
+ /**
2963
+ * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
2964
+ * See the from* functions below for more convenient ways of constructing Longs.
2965
+ * @exports Long
2966
+ * @class A Long class for representing a 64 bit two's-complement integer value.
2967
+ * @param {number} low The low (signed) 32 bits of the long
2968
+ * @param {number} high The high (signed) 32 bits of the long
2969
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
2970
+ * @constructor
2971
+ */
2972
+ function Long(low, high, unsigned) {
2973
+
2974
+ /**
2975
+ * The low 32 bits as a signed value.
2976
+ * @type {number}
2977
+ */
2978
+ this.low = low | 0;
2979
+
2980
+ /**
2981
+ * The high 32 bits as a signed value.
2982
+ * @type {number}
2983
+ */
2984
+ this.high = high | 0;
2985
+
2986
+ /**
2987
+ * Whether unsigned or not.
2988
+ * @type {boolean}
2989
+ */
2990
+ this.unsigned = !!unsigned;
2991
+ }
2992
+
2993
+ // The internal representation of a long is the two given signed, 32-bit values.
2994
+ // We use 32-bit pieces because these are the size of integers on which
2995
+ // Javascript performs bit-operations. For operations like addition and
2996
+ // multiplication, we split each number into 16 bit pieces, which can easily be
2997
+ // multiplied within Javascript's floating-point representation without overflow
2998
+ // or change in sign.
2999
+ //
3000
+ // In the algorithms below, we frequently reduce the negative case to the
3001
+ // positive case by negating the input(s) and then post-processing the result.
3002
+ // Note that we must ALWAYS check specially whether those values are MIN_VALUE
3003
+ // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
3004
+ // a positive number, it overflows back into a negative). Not handling this
3005
+ // case would often result in infinite recursion.
3006
+ //
3007
+ // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
3008
+ // methods on which they depend.
3009
+
3010
+ /**
3011
+ * An indicator used to reliably determine if an object is a Long or not.
3012
+ * @type {boolean}
3013
+ * @const
3014
+ * @private
3015
+ */
3016
+ Long.prototype.__isLong__;
3017
+
3018
+ Object.defineProperty(Long.prototype, "__isLong__", { value: true });
3019
+
3020
+ /**
3021
+ * @function
3022
+ * @param {*} obj Object
3023
+ * @returns {boolean}
3024
+ * @inner
3025
+ */
3026
+ function isLong(obj) {
3027
+ return (obj && obj["__isLong__"]) === true;
3028
+ }
3029
+
3030
+ /**
3031
+ * Tests if the specified object is a Long.
3032
+ * @function
3033
+ * @param {*} obj Object
3034
+ * @returns {boolean}
3035
+ */
3036
+ Long.isLong = isLong;
3037
+
3038
+ /**
3039
+ * A cache of the Long representations of small integer values.
3040
+ * @type {!Object}
3041
+ * @inner
3042
+ */
3043
+ var INT_CACHE = {};
3044
+
3045
+ /**
3046
+ * A cache of the Long representations of small unsigned integer values.
3047
+ * @type {!Object}
3048
+ * @inner
3049
+ */
3050
+ var UINT_CACHE = {};
3051
+
3052
+ /**
3053
+ * @param {number} value
3054
+ * @param {boolean=} unsigned
3055
+ * @returns {!Long}
3056
+ * @inner
3057
+ */
3058
+ function fromInt(value, unsigned) {
3059
+ var obj, cachedObj, cache;
3060
+ if (unsigned) {
3061
+ value >>>= 0;
3062
+ if (cache = (0 <= value && value < 256)) {
3063
+ cachedObj = UINT_CACHE[value];
3064
+ if (cachedObj)
3065
+ return cachedObj;
3066
+ }
3067
+ obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
3068
+ if (cache)
3069
+ UINT_CACHE[value] = obj;
3070
+ return obj;
3071
+ } else {
3072
+ value |= 0;
3073
+ if (cache = (-128 <= value && value < 128)) {
3074
+ cachedObj = INT_CACHE[value];
3075
+ if (cachedObj)
3076
+ return cachedObj;
3077
+ }
3078
+ obj = fromBits(value, value < 0 ? -1 : 0, false);
3079
+ if (cache)
3080
+ INT_CACHE[value] = obj;
3081
+ return obj;
3082
+ }
3083
+ }
3084
+
3085
+ /**
3086
+ * Returns a Long representing the given 32 bit integer value.
3087
+ * @function
3088
+ * @param {number} value The 32 bit integer in question
3089
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3090
+ * @returns {!Long} The corresponding Long value
3091
+ */
3092
+ Long.fromInt = fromInt;
3093
+
3094
+ /**
3095
+ * @param {number} value
3096
+ * @param {boolean=} unsigned
3097
+ * @returns {!Long}
3098
+ * @inner
3099
+ */
3100
+ function fromNumber(value, unsigned) {
3101
+ if (isNaN(value))
3102
+ return unsigned ? UZERO : ZERO;
3103
+ if (unsigned) {
3104
+ if (value < 0)
3105
+ return UZERO;
3106
+ if (value >= TWO_PWR_64_DBL)
3107
+ return MAX_UNSIGNED_VALUE;
3108
+ } else {
3109
+ if (value <= -TWO_PWR_63_DBL)
3110
+ return MIN_VALUE;
3111
+ if (value + 1 >= TWO_PWR_63_DBL)
3112
+ return MAX_VALUE;
3113
+ }
3114
+ if (value < 0)
3115
+ return fromNumber(-value, unsigned).neg();
3116
+ return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
3117
+ }
3118
+
3119
+ /**
3120
+ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
3121
+ * @function
3122
+ * @param {number} value The number in question
3123
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3124
+ * @returns {!Long} The corresponding Long value
3125
+ */
3126
+ Long.fromNumber = fromNumber;
3127
+
3128
+ /**
3129
+ * @param {number} lowBits
3130
+ * @param {number} highBits
3131
+ * @param {boolean=} unsigned
3132
+ * @returns {!Long}
3133
+ * @inner
3134
+ */
3135
+ function fromBits(lowBits, highBits, unsigned) {
3136
+ return new Long(lowBits, highBits, unsigned);
3137
+ }
3138
+
3139
+ /**
3140
+ * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
3141
+ * assumed to use 32 bits.
3142
+ * @function
3143
+ * @param {number} lowBits The low 32 bits
3144
+ * @param {number} highBits The high 32 bits
3145
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3146
+ * @returns {!Long} The corresponding Long value
3147
+ */
3148
+ Long.fromBits = fromBits;
3149
+
3150
+ /**
3151
+ * @function
3152
+ * @param {number} base
3153
+ * @param {number} exponent
3154
+ * @returns {number}
3155
+ * @inner
3156
+ */
3157
+ var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
3158
+
3159
+ /**
3160
+ * @param {string} str
3161
+ * @param {(boolean|number)=} unsigned
3162
+ * @param {number=} radix
3163
+ * @returns {!Long}
3164
+ * @inner
3165
+ */
3166
+ function fromString(str, unsigned, radix) {
3167
+ if (str.length === 0)
3168
+ throw Error('empty string');
3169
+ if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
3170
+ return ZERO;
3171
+ if (typeof unsigned === 'number') {
3172
+ // For goog.math.long compatibility
3173
+ radix = unsigned,
3174
+ unsigned = false;
3175
+ } else {
3176
+ unsigned = !! unsigned;
3177
+ }
3178
+ radix = radix || 10;
3179
+ if (radix < 2 || 36 < radix)
3180
+ throw RangeError('radix');
3181
+
3182
+ var p;
3183
+ if ((p = str.indexOf('-')) > 0)
3184
+ throw Error('interior hyphen');
3185
+ else if (p === 0) {
3186
+ return fromString(str.substring(1), unsigned, radix).neg();
3187
+ }
3188
+
3189
+ // Do several (8) digits each time through the loop, so as to
3190
+ // minimize the calls to the very expensive emulated div.
3191
+ var radixToPower = fromNumber(pow_dbl(radix, 8));
3192
+
3193
+ var result = ZERO;
3194
+ for (var i = 0; i < str.length; i += 8) {
3195
+ var size = Math.min(8, str.length - i),
3196
+ value = parseInt(str.substring(i, i + size), radix);
3197
+ if (size < 8) {
3198
+ var power = fromNumber(pow_dbl(radix, size));
3199
+ result = result.mul(power).add(fromNumber(value));
3200
+ } else {
3201
+ result = result.mul(radixToPower);
3202
+ result = result.add(fromNumber(value));
3203
+ }
3204
+ }
3205
+ result.unsigned = unsigned;
3206
+ return result;
3207
+ }
3208
+
3209
+ /**
3210
+ * Returns a Long representation of the given string, written using the specified radix.
3211
+ * @function
3212
+ * @param {string} str The textual representation of the Long
3213
+ * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
3214
+ * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
3215
+ * @returns {!Long} The corresponding Long value
3216
+ */
3217
+ Long.fromString = fromString;
3218
+
3219
+ /**
3220
+ * @function
3221
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
3222
+ * @param {boolean=} unsigned
3223
+ * @returns {!Long}
3224
+ * @inner
3225
+ */
3226
+ function fromValue(val, unsigned) {
3227
+ if (typeof val === 'number')
3228
+ return fromNumber(val, unsigned);
3229
+ if (typeof val === 'string')
3230
+ return fromString(val, unsigned);
3231
+ // Throws for non-objects, converts non-instanceof Long:
3232
+ return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
3233
+ }
3234
+
3235
+ /**
3236
+ * Converts the specified value to a Long using the appropriate from* function for its type.
3237
+ * @function
3238
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
3239
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
3240
+ * @returns {!Long}
3241
+ */
3242
+ Long.fromValue = fromValue;
3243
+
3244
+ // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
3245
+ // no runtime penalty for these.
3246
+
3247
+ /**
3248
+ * @type {number}
3249
+ * @const
3250
+ * @inner
3251
+ */
3252
+ var TWO_PWR_16_DBL = 1 << 16;
3253
+
3254
+ /**
3255
+ * @type {number}
3256
+ * @const
3257
+ * @inner
3258
+ */
3259
+ var TWO_PWR_24_DBL = 1 << 24;
3260
+
3261
+ /**
3262
+ * @type {number}
3263
+ * @const
3264
+ * @inner
3265
+ */
3266
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
3267
+
3268
+ /**
3269
+ * @type {number}
3270
+ * @const
3271
+ * @inner
3272
+ */
3273
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
3274
+
3275
+ /**
3276
+ * @type {number}
3277
+ * @const
3278
+ * @inner
3279
+ */
3280
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
3281
+
3282
+ /**
3283
+ * @type {!Long}
3284
+ * @const
3285
+ * @inner
3286
+ */
3287
+ var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
3288
+
3289
+ /**
3290
+ * @type {!Long}
3291
+ * @inner
3292
+ */
3293
+ var ZERO = fromInt(0);
3294
+
3295
+ /**
3296
+ * Signed zero.
3297
+ * @type {!Long}
3298
+ */
3299
+ Long.ZERO = ZERO;
3300
+
3301
+ /**
3302
+ * @type {!Long}
3303
+ * @inner
3304
+ */
3305
+ var UZERO = fromInt(0, true);
3306
+
3307
+ /**
3308
+ * Unsigned zero.
3309
+ * @type {!Long}
3310
+ */
3311
+ Long.UZERO = UZERO;
3312
+
3313
+ /**
3314
+ * @type {!Long}
3315
+ * @inner
3316
+ */
3317
+ var ONE = fromInt(1);
3318
+
3319
+ /**
3320
+ * Signed one.
3321
+ * @type {!Long}
3322
+ */
3323
+ Long.ONE = ONE;
3324
+
3325
+ /**
3326
+ * @type {!Long}
3327
+ * @inner
3328
+ */
3329
+ var UONE = fromInt(1, true);
3330
+
3331
+ /**
3332
+ * Unsigned one.
3333
+ * @type {!Long}
3334
+ */
3335
+ Long.UONE = UONE;
3336
+
3337
+ /**
3338
+ * @type {!Long}
3339
+ * @inner
3340
+ */
3341
+ var NEG_ONE = fromInt(-1);
3342
+
3343
+ /**
3344
+ * Signed negative one.
3345
+ * @type {!Long}
3346
+ */
3347
+ Long.NEG_ONE = NEG_ONE;
3348
+
3349
+ /**
3350
+ * @type {!Long}
3351
+ * @inner
3352
+ */
3353
+ var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false);
3354
+
3355
+ /**
3356
+ * Maximum signed value.
3357
+ * @type {!Long}
3358
+ */
3359
+ Long.MAX_VALUE = MAX_VALUE;
3360
+
3361
+ /**
3362
+ * @type {!Long}
3363
+ * @inner
3364
+ */
3365
+ var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true);
3366
+
3367
+ /**
3368
+ * Maximum unsigned value.
3369
+ * @type {!Long}
3370
+ */
3371
+ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
3372
+
3373
+ /**
3374
+ * @type {!Long}
3375
+ * @inner
3376
+ */
3377
+ var MIN_VALUE = fromBits(0, 0x80000000|0, false);
3378
+
3379
+ /**
3380
+ * Minimum signed value.
3381
+ * @type {!Long}
3382
+ */
3383
+ Long.MIN_VALUE = MIN_VALUE;
3384
+
3385
+ /**
3386
+ * @alias Long.prototype
3387
+ * @inner
3388
+ */
3389
+ var LongPrototype = Long.prototype;
3390
+
3391
+ /**
3392
+ * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
3393
+ * @returns {number}
3394
+ */
3395
+ LongPrototype.toInt = function toInt() {
3396
+ return this.unsigned ? this.low >>> 0 : this.low;
3397
+ };
3398
+
3399
+ /**
3400
+ * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
3401
+ * @returns {number}
3402
+ */
3403
+ LongPrototype.toNumber = function toNumber() {
3404
+ if (this.unsigned)
3405
+ return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
3406
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
3407
+ };
3408
+
3409
+ /**
3410
+ * Converts the Long to a string written in the specified radix.
3411
+ * @param {number=} radix Radix (2-36), defaults to 10
3412
+ * @returns {string}
3413
+ * @override
3414
+ * @throws {RangeError} If `radix` is out of range
3415
+ */
3416
+ LongPrototype.toString = function toString(radix) {
3417
+ radix = radix || 10;
3418
+ if (radix < 2 || 36 < radix)
3419
+ throw RangeError('radix');
3420
+ if (this.isZero())
3421
+ return '0';
3422
+ if (this.isNegative()) { // Unsigned Longs are never negative
3423
+ if (this.eq(MIN_VALUE)) {
3424
+ // We need to change the Long value before it can be negated, so we remove
3425
+ // the bottom-most digit in this base and then recurse to do the rest.
3426
+ var radixLong = fromNumber(radix),
3427
+ div = this.div(radixLong),
3428
+ rem1 = div.mul(radixLong).sub(this);
3429
+ return div.toString(radix) + rem1.toInt().toString(radix);
3430
+ } else
3431
+ return '-' + this.neg().toString(radix);
3432
+ }
3433
+
3434
+ // Do several (6) digits each time through the loop, so as to
3435
+ // minimize the calls to the very expensive emulated div.
3436
+ var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
3437
+ rem = this;
3438
+ var result = '';
3439
+ while (true) {
3440
+ var remDiv = rem.div(radixToPower),
3441
+ intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
3442
+ digits = intval.toString(radix);
3443
+ rem = remDiv;
3444
+ if (rem.isZero())
3445
+ return digits + result;
3446
+ else {
3447
+ while (digits.length < 6)
3448
+ digits = '0' + digits;
3449
+ result = '' + digits + result;
3450
+ }
3451
+ }
3452
+ };
3453
+
3454
+ /**
3455
+ * Gets the high 32 bits as a signed integer.
3456
+ * @returns {number} Signed high bits
3457
+ */
3458
+ LongPrototype.getHighBits = function getHighBits() {
3459
+ return this.high;
3460
+ };
3461
+
3462
+ /**
3463
+ * Gets the high 32 bits as an unsigned integer.
3464
+ * @returns {number} Unsigned high bits
3465
+ */
3466
+ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
3467
+ return this.high >>> 0;
3468
+ };
3469
+
3470
+ /**
3471
+ * Gets the low 32 bits as a signed integer.
3472
+ * @returns {number} Signed low bits
3473
+ */
3474
+ LongPrototype.getLowBits = function getLowBits() {
3475
+ return this.low;
3476
+ };
3477
+
3478
+ /**
3479
+ * Gets the low 32 bits as an unsigned integer.
3480
+ * @returns {number} Unsigned low bits
3481
+ */
3482
+ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
3483
+ return this.low >>> 0;
3484
+ };
3485
+
3486
+ /**
3487
+ * Gets the number of bits needed to represent the absolute value of this Long.
3488
+ * @returns {number}
3489
+ */
3490
+ LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
3491
+ if (this.isNegative()) // Unsigned Longs are never negative
3492
+ return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
3493
+ var val = this.high != 0 ? this.high : this.low;
3494
+ for (var bit = 31; bit > 0; bit--)
3495
+ if ((val & (1 << bit)) != 0)
3496
+ break;
3497
+ return this.high != 0 ? bit + 33 : bit + 1;
3498
+ };
3499
+
3500
+ /**
3501
+ * Tests if this Long's value equals zero.
3502
+ * @returns {boolean}
3503
+ */
3504
+ LongPrototype.isZero = function isZero() {
3505
+ return this.high === 0 && this.low === 0;
3506
+ };
3507
+
3508
+ /**
3509
+ * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
3510
+ * @returns {boolean}
3511
+ */
3512
+ LongPrototype.eqz = LongPrototype.isZero;
3513
+
3514
+ /**
3515
+ * Tests if this Long's value is negative.
3516
+ * @returns {boolean}
3517
+ */
3518
+ LongPrototype.isNegative = function isNegative() {
3519
+ return !this.unsigned && this.high < 0;
3520
+ };
3521
+
3522
+ /**
3523
+ * Tests if this Long's value is positive.
3524
+ * @returns {boolean}
3525
+ */
3526
+ LongPrototype.isPositive = function isPositive() {
3527
+ return this.unsigned || this.high >= 0;
3528
+ };
3529
+
3530
+ /**
3531
+ * Tests if this Long's value is odd.
3532
+ * @returns {boolean}
3533
+ */
3534
+ LongPrototype.isOdd = function isOdd() {
3535
+ return (this.low & 1) === 1;
3536
+ };
3537
+
3538
+ /**
3539
+ * Tests if this Long's value is even.
3540
+ * @returns {boolean}
3541
+ */
3542
+ LongPrototype.isEven = function isEven() {
3543
+ return (this.low & 1) === 0;
3544
+ };
3545
+
3546
+ /**
3547
+ * Tests if this Long's value equals the specified's.
3548
+ * @param {!Long|number|string} other Other value
3549
+ * @returns {boolean}
3550
+ */
3551
+ LongPrototype.equals = function equals(other) {
3552
+ if (!isLong(other))
3553
+ other = fromValue(other);
3554
+ if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
3555
+ return false;
3556
+ return this.high === other.high && this.low === other.low;
3557
+ };
3558
+
3559
+ /**
3560
+ * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
3561
+ * @function
3562
+ * @param {!Long|number|string} other Other value
3563
+ * @returns {boolean}
3564
+ */
3565
+ LongPrototype.eq = LongPrototype.equals;
3566
+
3567
+ /**
3568
+ * Tests if this Long's value differs from the specified's.
3569
+ * @param {!Long|number|string} other Other value
3570
+ * @returns {boolean}
3571
+ */
3572
+ LongPrototype.notEquals = function notEquals(other) {
3573
+ return !this.eq(/* validates */ other);
3574
+ };
3575
+
3576
+ /**
3577
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
3578
+ * @function
3579
+ * @param {!Long|number|string} other Other value
3580
+ * @returns {boolean}
3581
+ */
3582
+ LongPrototype.neq = LongPrototype.notEquals;
3583
+
3584
+ /**
3585
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
3586
+ * @function
3587
+ * @param {!Long|number|string} other Other value
3588
+ * @returns {boolean}
3589
+ */
3590
+ LongPrototype.ne = LongPrototype.notEquals;
3591
+
3592
+ /**
3593
+ * Tests if this Long's value is less than the specified's.
3594
+ * @param {!Long|number|string} other Other value
3595
+ * @returns {boolean}
3596
+ */
3597
+ LongPrototype.lessThan = function lessThan(other) {
3598
+ return this.comp(/* validates */ other) < 0;
3599
+ };
3600
+
3601
+ /**
3602
+ * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
3603
+ * @function
3604
+ * @param {!Long|number|string} other Other value
3605
+ * @returns {boolean}
3606
+ */
3607
+ LongPrototype.lt = LongPrototype.lessThan;
3608
+
3609
+ /**
3610
+ * Tests if this Long's value is less than or equal the specified's.
3611
+ * @param {!Long|number|string} other Other value
3612
+ * @returns {boolean}
3613
+ */
3614
+ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
3615
+ return this.comp(/* validates */ other) <= 0;
3616
+ };
3617
+
3618
+ /**
3619
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
3620
+ * @function
3621
+ * @param {!Long|number|string} other Other value
3622
+ * @returns {boolean}
3623
+ */
3624
+ LongPrototype.lte = LongPrototype.lessThanOrEqual;
3625
+
3626
+ /**
3627
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
3628
+ * @function
3629
+ * @param {!Long|number|string} other Other value
3630
+ * @returns {boolean}
3631
+ */
3632
+ LongPrototype.le = LongPrototype.lessThanOrEqual;
3633
+
3634
+ /**
3635
+ * Tests if this Long's value is greater than the specified's.
3636
+ * @param {!Long|number|string} other Other value
3637
+ * @returns {boolean}
3638
+ */
3639
+ LongPrototype.greaterThan = function greaterThan(other) {
3640
+ return this.comp(/* validates */ other) > 0;
3641
+ };
3642
+
3643
+ /**
3644
+ * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
3645
+ * @function
3646
+ * @param {!Long|number|string} other Other value
3647
+ * @returns {boolean}
3648
+ */
3649
+ LongPrototype.gt = LongPrototype.greaterThan;
3650
+
3651
+ /**
3652
+ * Tests if this Long's value is greater than or equal the specified's.
3653
+ * @param {!Long|number|string} other Other value
3654
+ * @returns {boolean}
3655
+ */
3656
+ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
3657
+ return this.comp(/* validates */ other) >= 0;
3658
+ };
3659
+
3660
+ /**
3661
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
3662
+ * @function
3663
+ * @param {!Long|number|string} other Other value
3664
+ * @returns {boolean}
3665
+ */
3666
+ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
3667
+
3668
+ /**
3669
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
3670
+ * @function
3671
+ * @param {!Long|number|string} other Other value
3672
+ * @returns {boolean}
3673
+ */
3674
+ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
3675
+
3676
+ /**
3677
+ * Compares this Long's value with the specified's.
3678
+ * @param {!Long|number|string} other Other value
3679
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
3680
+ * if the given one is greater
3681
+ */
3682
+ LongPrototype.compare = function compare(other) {
3683
+ if (!isLong(other))
3684
+ other = fromValue(other);
3685
+ if (this.eq(other))
3686
+ return 0;
3687
+ var thisNeg = this.isNegative(),
3688
+ otherNeg = other.isNegative();
3689
+ if (thisNeg && !otherNeg)
3690
+ return -1;
3691
+ if (!thisNeg && otherNeg)
3692
+ return 1;
3693
+ // At this point the sign bits are the same
3694
+ if (!this.unsigned)
3695
+ return this.sub(other).isNegative() ? -1 : 1;
3696
+ // Both are positive if at least one is unsigned
3697
+ return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
3698
+ };
3699
+
3700
+ /**
3701
+ * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
3702
+ * @function
3703
+ * @param {!Long|number|string} other Other value
3704
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
3705
+ * if the given one is greater
3706
+ */
3707
+ LongPrototype.comp = LongPrototype.compare;
3708
+
3709
+ /**
3710
+ * Negates this Long's value.
3711
+ * @returns {!Long} Negated Long
3712
+ */
3713
+ LongPrototype.negate = function negate() {
3714
+ if (!this.unsigned && this.eq(MIN_VALUE))
3715
+ return MIN_VALUE;
3716
+ return this.not().add(ONE);
3717
+ };
3718
+
3719
+ /**
3720
+ * Negates this Long's value. This is an alias of {@link Long#negate}.
3721
+ * @function
3722
+ * @returns {!Long} Negated Long
3723
+ */
3724
+ LongPrototype.neg = LongPrototype.negate;
3725
+
3726
+ /**
3727
+ * Returns the sum of this and the specified Long.
3728
+ * @param {!Long|number|string} addend Addend
3729
+ * @returns {!Long} Sum
3730
+ */
3731
+ LongPrototype.add = function add(addend) {
3732
+ if (!isLong(addend))
3733
+ addend = fromValue(addend);
3734
+
3735
+ // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
3736
+
3737
+ var a48 = this.high >>> 16;
3738
+ var a32 = this.high & 0xFFFF;
3739
+ var a16 = this.low >>> 16;
3740
+ var a00 = this.low & 0xFFFF;
3741
+
3742
+ var b48 = addend.high >>> 16;
3743
+ var b32 = addend.high & 0xFFFF;
3744
+ var b16 = addend.low >>> 16;
3745
+ var b00 = addend.low & 0xFFFF;
3746
+
3747
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
3748
+ c00 += a00 + b00;
3749
+ c16 += c00 >>> 16;
3750
+ c00 &= 0xFFFF;
3751
+ c16 += a16 + b16;
3752
+ c32 += c16 >>> 16;
3753
+ c16 &= 0xFFFF;
3754
+ c32 += a32 + b32;
3755
+ c48 += c32 >>> 16;
3756
+ c32 &= 0xFFFF;
3757
+ c48 += a48 + b48;
3758
+ c48 &= 0xFFFF;
3759
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
3760
+ };
3761
+
3762
+ /**
3763
+ * Returns the difference of this and the specified Long.
3764
+ * @param {!Long|number|string} subtrahend Subtrahend
3765
+ * @returns {!Long} Difference
3766
+ */
3767
+ LongPrototype.subtract = function subtract(subtrahend) {
3768
+ if (!isLong(subtrahend))
3769
+ subtrahend = fromValue(subtrahend);
3770
+ return this.add(subtrahend.neg());
3771
+ };
3772
+
3773
+ /**
3774
+ * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
3775
+ * @function
3776
+ * @param {!Long|number|string} subtrahend Subtrahend
3777
+ * @returns {!Long} Difference
3778
+ */
3779
+ LongPrototype.sub = LongPrototype.subtract;
3780
+
3781
+ /**
3782
+ * Returns the product of this and the specified Long.
3783
+ * @param {!Long|number|string} multiplier Multiplier
3784
+ * @returns {!Long} Product
3785
+ */
3786
+ LongPrototype.multiply = function multiply(multiplier) {
3787
+ if (this.isZero())
3788
+ return ZERO;
3789
+ if (!isLong(multiplier))
3790
+ multiplier = fromValue(multiplier);
3791
+
3792
+ // use wasm support if present
3793
+ if (wasm) {
3794
+ var low = wasm.mul(this.low,
3795
+ this.high,
3796
+ multiplier.low,
3797
+ multiplier.high);
3798
+ return fromBits(low, wasm.get_high(), this.unsigned);
3799
+ }
3800
+
3801
+ if (multiplier.isZero())
3802
+ return ZERO;
3803
+ if (this.eq(MIN_VALUE))
3804
+ return multiplier.isOdd() ? MIN_VALUE : ZERO;
3805
+ if (multiplier.eq(MIN_VALUE))
3806
+ return this.isOdd() ? MIN_VALUE : ZERO;
3807
+
3808
+ if (this.isNegative()) {
3809
+ if (multiplier.isNegative())
3810
+ return this.neg().mul(multiplier.neg());
3811
+ else
3812
+ return this.neg().mul(multiplier).neg();
3813
+ } else if (multiplier.isNegative())
3814
+ return this.mul(multiplier.neg()).neg();
3815
+
3816
+ // If both longs are small, use float multiplication
3817
+ if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
3818
+ return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
3819
+
3820
+ // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
3821
+ // We can skip products that would overflow.
3822
+
3823
+ var a48 = this.high >>> 16;
3824
+ var a32 = this.high & 0xFFFF;
3825
+ var a16 = this.low >>> 16;
3826
+ var a00 = this.low & 0xFFFF;
3827
+
3828
+ var b48 = multiplier.high >>> 16;
3829
+ var b32 = multiplier.high & 0xFFFF;
3830
+ var b16 = multiplier.low >>> 16;
3831
+ var b00 = multiplier.low & 0xFFFF;
3832
+
3833
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
3834
+ c00 += a00 * b00;
3835
+ c16 += c00 >>> 16;
3836
+ c00 &= 0xFFFF;
3837
+ c16 += a16 * b00;
3838
+ c32 += c16 >>> 16;
3839
+ c16 &= 0xFFFF;
3840
+ c16 += a00 * b16;
3841
+ c32 += c16 >>> 16;
3842
+ c16 &= 0xFFFF;
3843
+ c32 += a32 * b00;
3844
+ c48 += c32 >>> 16;
3845
+ c32 &= 0xFFFF;
3846
+ c32 += a16 * b16;
3847
+ c48 += c32 >>> 16;
3848
+ c32 &= 0xFFFF;
3849
+ c32 += a00 * b32;
3850
+ c48 += c32 >>> 16;
3851
+ c32 &= 0xFFFF;
3852
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
3853
+ c48 &= 0xFFFF;
3854
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
3855
+ };
3856
+
3857
+ /**
3858
+ * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
3859
+ * @function
3860
+ * @param {!Long|number|string} multiplier Multiplier
3861
+ * @returns {!Long} Product
3862
+ */
3863
+ LongPrototype.mul = LongPrototype.multiply;
3864
+
3865
+ /**
3866
+ * Returns this Long divided by the specified. The result is signed if this Long is signed or
3867
+ * unsigned if this Long is unsigned.
3868
+ * @param {!Long|number|string} divisor Divisor
3869
+ * @returns {!Long} Quotient
3870
+ */
3871
+ LongPrototype.divide = function divide(divisor) {
3872
+ if (!isLong(divisor))
3873
+ divisor = fromValue(divisor);
3874
+ if (divisor.isZero())
3875
+ throw Error('division by zero');
3876
+
3877
+ // use wasm support if present
3878
+ if (wasm) {
3879
+ // guard against signed division overflow: the largest
3880
+ // negative number / -1 would be 1 larger than the largest
3881
+ // positive number, due to two's complement.
3882
+ if (!this.unsigned &&
3883
+ this.high === -0x80000000 &&
3884
+ divisor.low === -1 && divisor.high === -1) {
3885
+ // be consistent with non-wasm code path
3886
+ return this;
3887
+ }
3888
+ var low = (this.unsigned ? wasm.div_u : wasm.div_s)(
3889
+ this.low,
3890
+ this.high,
3891
+ divisor.low,
3892
+ divisor.high
3893
+ );
3894
+ return fromBits(low, wasm.get_high(), this.unsigned);
3895
+ }
3896
+
3897
+ if (this.isZero())
3898
+ return this.unsigned ? UZERO : ZERO;
3899
+ var approx, rem, res;
3900
+ if (!this.unsigned) {
3901
+ // This section is only relevant for signed longs and is derived from the
3902
+ // closure library as a whole.
3903
+ if (this.eq(MIN_VALUE)) {
3904
+ if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
3905
+ return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
3906
+ else if (divisor.eq(MIN_VALUE))
3907
+ return ONE;
3908
+ else {
3909
+ // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
3910
+ var halfThis = this.shr(1);
3911
+ approx = halfThis.div(divisor).shl(1);
3912
+ if (approx.eq(ZERO)) {
3913
+ return divisor.isNegative() ? ONE : NEG_ONE;
3914
+ } else {
3915
+ rem = this.sub(divisor.mul(approx));
3916
+ res = approx.add(rem.div(divisor));
3917
+ return res;
3918
+ }
3919
+ }
3920
+ } else if (divisor.eq(MIN_VALUE))
3921
+ return this.unsigned ? UZERO : ZERO;
3922
+ if (this.isNegative()) {
3923
+ if (divisor.isNegative())
3924
+ return this.neg().div(divisor.neg());
3925
+ return this.neg().div(divisor).neg();
3926
+ } else if (divisor.isNegative())
3927
+ return this.div(divisor.neg()).neg();
3928
+ res = ZERO;
3929
+ } else {
3930
+ // The algorithm below has not been made for unsigned longs. It's therefore
3931
+ // required to take special care of the MSB prior to running it.
3932
+ if (!divisor.unsigned)
3933
+ divisor = divisor.toUnsigned();
3934
+ if (divisor.gt(this))
3935
+ return UZERO;
3936
+ if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
3937
+ return UONE;
3938
+ res = UZERO;
3939
+ }
3940
+
3941
+ // Repeat the following until the remainder is less than other: find a
3942
+ // floating-point that approximates remainder / other *from below*, add this
3943
+ // into the result, and subtract it from the remainder. It is critical that
3944
+ // the approximate value is less than or equal to the real value so that the
3945
+ // remainder never becomes negative.
3946
+ rem = this;
3947
+ while (rem.gte(divisor)) {
3948
+ // Approximate the result of division. This may be a little greater or
3949
+ // smaller than the actual value.
3950
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
3951
+
3952
+ // We will tweak the approximate result by changing it in the 48-th digit or
3953
+ // the smallest non-fractional digit, whichever is larger.
3954
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2),
3955
+ delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
3956
+
3957
+ // Decrease the approximation until it is smaller than the remainder. Note
3958
+ // that if it is too large, the product overflows and is negative.
3959
+ approxRes = fromNumber(approx),
3960
+ approxRem = approxRes.mul(divisor);
3961
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
3962
+ approx -= delta;
3963
+ approxRes = fromNumber(approx, this.unsigned);
3964
+ approxRem = approxRes.mul(divisor);
3965
+ }
3966
+
3967
+ // We know the answer can't be zero... and actually, zero would cause
3968
+ // infinite recursion since we would make no progress.
3969
+ if (approxRes.isZero())
3970
+ approxRes = ONE;
3971
+
3972
+ res = res.add(approxRes);
3973
+ rem = rem.sub(approxRem);
3974
+ }
3975
+ return res;
3976
+ };
3977
+
3978
+ /**
3979
+ * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
3980
+ * @function
3981
+ * @param {!Long|number|string} divisor Divisor
3982
+ * @returns {!Long} Quotient
3983
+ */
3984
+ LongPrototype.div = LongPrototype.divide;
3985
+
3986
+ /**
3987
+ * Returns this Long modulo the specified.
3988
+ * @param {!Long|number|string} divisor Divisor
3989
+ * @returns {!Long} Remainder
3990
+ */
3991
+ LongPrototype.modulo = function modulo(divisor) {
3992
+ if (!isLong(divisor))
3993
+ divisor = fromValue(divisor);
3994
+
3995
+ // use wasm support if present
3996
+ if (wasm) {
3997
+ var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(
3998
+ this.low,
3999
+ this.high,
4000
+ divisor.low,
4001
+ divisor.high
4002
+ );
4003
+ return fromBits(low, wasm.get_high(), this.unsigned);
4004
+ }
4005
+
4006
+ return this.sub(this.div(divisor).mul(divisor));
4007
+ };
4008
+
4009
+ /**
4010
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
4011
+ * @function
4012
+ * @param {!Long|number|string} divisor Divisor
4013
+ * @returns {!Long} Remainder
4014
+ */
4015
+ LongPrototype.mod = LongPrototype.modulo;
4016
+
4017
+ /**
4018
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
4019
+ * @function
4020
+ * @param {!Long|number|string} divisor Divisor
4021
+ * @returns {!Long} Remainder
4022
+ */
4023
+ LongPrototype.rem = LongPrototype.modulo;
4024
+
4025
+ /**
4026
+ * Returns the bitwise NOT of this Long.
4027
+ * @returns {!Long}
4028
+ */
4029
+ LongPrototype.not = function not() {
4030
+ return fromBits(~this.low, ~this.high, this.unsigned);
4031
+ };
4032
+
4033
+ /**
4034
+ * Returns the bitwise AND of this Long and the specified.
4035
+ * @param {!Long|number|string} other Other Long
4036
+ * @returns {!Long}
4037
+ */
4038
+ LongPrototype.and = function and(other) {
4039
+ if (!isLong(other))
4040
+ other = fromValue(other);
4041
+ return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
4042
+ };
4043
+
4044
+ /**
4045
+ * Returns the bitwise OR of this Long and the specified.
4046
+ * @param {!Long|number|string} other Other Long
4047
+ * @returns {!Long}
4048
+ */
4049
+ LongPrototype.or = function or(other) {
4050
+ if (!isLong(other))
4051
+ other = fromValue(other);
4052
+ return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
4053
+ };
4054
+
4055
+ /**
4056
+ * Returns the bitwise XOR of this Long and the given one.
4057
+ * @param {!Long|number|string} other Other Long
4058
+ * @returns {!Long}
4059
+ */
4060
+ LongPrototype.xor = function xor(other) {
4061
+ if (!isLong(other))
4062
+ other = fromValue(other);
4063
+ return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
4064
+ };
4065
+
4066
+ /**
4067
+ * Returns this Long with bits shifted to the left by the given amount.
4068
+ * @param {number|!Long} numBits Number of bits
4069
+ * @returns {!Long} Shifted Long
4070
+ */
4071
+ LongPrototype.shiftLeft = function shiftLeft(numBits) {
4072
+ if (isLong(numBits))
4073
+ numBits = numBits.toInt();
4074
+ if ((numBits &= 63) === 0)
4075
+ return this;
4076
+ else if (numBits < 32)
4077
+ return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
4078
+ else
4079
+ return fromBits(0, this.low << (numBits - 32), this.unsigned);
4080
+ };
4081
+
4082
+ /**
4083
+ * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
4084
+ * @function
4085
+ * @param {number|!Long} numBits Number of bits
4086
+ * @returns {!Long} Shifted Long
4087
+ */
4088
+ LongPrototype.shl = LongPrototype.shiftLeft;
4089
+
4090
+ /**
4091
+ * Returns this Long with bits arithmetically shifted to the right by the given amount.
4092
+ * @param {number|!Long} numBits Number of bits
4093
+ * @returns {!Long} Shifted Long
4094
+ */
4095
+ LongPrototype.shiftRight = function shiftRight(numBits) {
4096
+ if (isLong(numBits))
4097
+ numBits = numBits.toInt();
4098
+ if ((numBits &= 63) === 0)
4099
+ return this;
4100
+ else if (numBits < 32)
4101
+ return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
4102
+ else
4103
+ return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
4104
+ };
4105
+
4106
+ /**
4107
+ * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
4108
+ * @function
4109
+ * @param {number|!Long} numBits Number of bits
4110
+ * @returns {!Long} Shifted Long
4111
+ */
4112
+ LongPrototype.shr = LongPrototype.shiftRight;
4113
+
4114
+ /**
4115
+ * Returns this Long with bits logically shifted to the right by the given amount.
4116
+ * @param {number|!Long} numBits Number of bits
4117
+ * @returns {!Long} Shifted Long
4118
+ */
4119
+ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
4120
+ if (isLong(numBits))
4121
+ numBits = numBits.toInt();
4122
+ numBits &= 63;
4123
+ if (numBits === 0)
4124
+ return this;
4125
+ else {
4126
+ var high = this.high;
4127
+ if (numBits < 32) {
4128
+ var low = this.low;
4129
+ return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
4130
+ } else if (numBits === 32)
4131
+ return fromBits(high, 0, this.unsigned);
4132
+ else
4133
+ return fromBits(high >>> (numBits - 32), 0, this.unsigned);
4134
+ }
4135
+ };
4136
+
4137
+ /**
4138
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
4139
+ * @function
4140
+ * @param {number|!Long} numBits Number of bits
4141
+ * @returns {!Long} Shifted Long
4142
+ */
4143
+ LongPrototype.shru = LongPrototype.shiftRightUnsigned;
4144
+
4145
+ /**
4146
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
4147
+ * @function
4148
+ * @param {number|!Long} numBits Number of bits
4149
+ * @returns {!Long} Shifted Long
4150
+ */
4151
+ LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
4152
+
4153
+ /**
4154
+ * Converts this Long to signed.
4155
+ * @returns {!Long} Signed long
4156
+ */
4157
+ LongPrototype.toSigned = function toSigned() {
4158
+ if (!this.unsigned)
4159
+ return this;
4160
+ return fromBits(this.low, this.high, false);
4161
+ };
4162
+
4163
+ /**
4164
+ * Converts this Long to unsigned.
4165
+ * @returns {!Long} Unsigned long
4166
+ */
4167
+ LongPrototype.toUnsigned = function toUnsigned() {
4168
+ if (this.unsigned)
4169
+ return this;
4170
+ return fromBits(this.low, this.high, true);
4171
+ };
4172
+
4173
+ /**
4174
+ * Converts this Long to its byte representation.
4175
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
4176
+ * @returns {!Array.<number>} Byte representation
4177
+ */
4178
+ LongPrototype.toBytes = function toBytes(le) {
4179
+ return le ? this.toBytesLE() : this.toBytesBE();
4180
+ };
4181
+
4182
+ /**
4183
+ * Converts this Long to its little endian byte representation.
4184
+ * @returns {!Array.<number>} Little endian byte representation
4185
+ */
4186
+ LongPrototype.toBytesLE = function toBytesLE() {
4187
+ var hi = this.high,
4188
+ lo = this.low;
4189
+ return [
4190
+ lo & 0xff,
4191
+ lo >>> 8 & 0xff,
4192
+ lo >>> 16 & 0xff,
4193
+ lo >>> 24 ,
4194
+ hi & 0xff,
4195
+ hi >>> 8 & 0xff,
4196
+ hi >>> 16 & 0xff,
4197
+ hi >>> 24
4198
+ ];
4199
+ };
4200
+
4201
+ /**
4202
+ * Converts this Long to its big endian byte representation.
4203
+ * @returns {!Array.<number>} Big endian byte representation
4204
+ */
4205
+ LongPrototype.toBytesBE = function toBytesBE() {
4206
+ var hi = this.high,
4207
+ lo = this.low;
4208
+ return [
4209
+ hi >>> 24 ,
4210
+ hi >>> 16 & 0xff,
4211
+ hi >>> 8 & 0xff,
4212
+ hi & 0xff,
4213
+ lo >>> 24 ,
4214
+ lo >>> 16 & 0xff,
4215
+ lo >>> 8 & 0xff,
4216
+ lo & 0xff
4217
+ ];
4218
+ };
4219
+
4220
+ /**
4221
+ * Creates a Long from its byte representation.
4222
+ * @param {!Array.<number>} bytes Byte representation
4223
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
4224
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
4225
+ * @returns {Long} The corresponding Long value
4226
+ */
4227
+ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
4228
+ return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
4229
+ };
4230
+
4231
+ /**
4232
+ * Creates a Long from its little endian byte representation.
4233
+ * @param {!Array.<number>} bytes Little endian byte representation
4234
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
4235
+ * @returns {Long} The corresponding Long value
4236
+ */
4237
+ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
4238
+ return new Long(
4239
+ bytes[0] |
4240
+ bytes[1] << 8 |
4241
+ bytes[2] << 16 |
4242
+ bytes[3] << 24,
4243
+ bytes[4] |
4244
+ bytes[5] << 8 |
4245
+ bytes[6] << 16 |
4246
+ bytes[7] << 24,
4247
+ unsigned
4248
+ );
4249
+ };
4250
+
4251
+ /**
4252
+ * Creates a Long from its big endian byte representation.
4253
+ * @param {!Array.<number>} bytes Big endian byte representation
4254
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
4255
+ * @returns {Long} The corresponding Long value
4256
+ */
4257
+ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
4258
+ return new Long(
4259
+ bytes[4] << 24 |
4260
+ bytes[5] << 16 |
4261
+ bytes[6] << 8 |
4262
+ bytes[7],
4263
+ bytes[0] << 24 |
4264
+ bytes[1] << 16 |
4265
+ bytes[2] << 8 |
4266
+ bytes[3],
4267
+ unsigned
4268
+ );
4269
+ };
4270
+
2947
4271
  var aspromise = asPromise;
2948
4272
 
2949
4273
  /**
@@ -8482,7 +9806,7 @@ const getEstimatedGas = ({ cosmosSDKClient, txBody, privKey, accountNumber, acco
8482
9806
  const txBuilder = buildUnsignedTx({
8483
9807
  cosmosSdk: cosmosSDKClient.sdk,
8484
9808
  txBody: txBody,
8485
- signerPubkey: core.cosmosclient.codec.packAny(pubKey),
9809
+ signerPubkey: core.cosmosclient.codec.instanceToProtoAny(pubKey),
8486
9810
  sequence: accountSequence,
8487
9811
  });
8488
9812
  const signDocBytes = txBuilder.signDocBytes(accountNumber);
@@ -8492,7 +9816,7 @@ const getEstimatedGas = ({ cosmosSDKClient, txBody, privKey, accountNumber, acco
8492
9816
  if (!estimatedGas) {
8493
9817
  throw new Error('Could not get data of estimated gas');
8494
9818
  }
8495
- return core.cosmosclient.Long.fromString(estimatedGas).multiply(multiplier || DEFAULT_GAS_ADJUSTMENT);
9819
+ return long_1.fromString(estimatedGas).multiply(multiplier || DEFAULT_GAS_ADJUSTMENT);
8496
9820
  });
8497
9821
  /**
8498
9822
  * Structure a MsgDeposit
@@ -8519,7 +9843,7 @@ const buildDepositTx = ({ msgNativeTx, nodeUrl, chainId, }) => __awaiter(void 0,
8519
9843
  };
8520
9844
  const depositMsg = MsgCompiled.types.MsgDeposit.fromObject(msgDepositObj);
8521
9845
  return new core.proto.cosmos.tx.v1beta1.TxBody({
8522
- messages: [core.cosmosclient.codec.packAny(depositMsg)],
9846
+ messages: [core.cosmosclient.codec.instanceToProtoAny(depositMsg)],
8523
9847
  memo: msgNativeTx.memo,
8524
9848
  });
8525
9849
  });
@@ -8553,7 +9877,7 @@ const buildTransferTx = ({ fromAddress, toAddress, assetAmount, assetDenom, memo
8553
9877
  };
8554
9878
  const transferMsg = MsgCompiled.types.MsgSend.fromObject(transferObj);
8555
9879
  return new core.proto.cosmos.tx.v1beta1.TxBody({
8556
- messages: [core.cosmosclient.codec.packAny(transferMsg)],
9880
+ messages: [core.cosmosclient.codec.instanceToProtoAny(transferMsg)],
8557
9881
  memo,
8558
9882
  });
8559
9883
  });
@@ -8765,8 +10089,15 @@ class Client extends xchainClient.BaseXChainClient {
8765
10089
  * Thrown if network has not been set before.
8766
10090
  */
8767
10091
  setNetwork(network) {
10092
+ // dirty check to avoid using and re-creation of same data
10093
+ if (network === this.network)
10094
+ return;
8768
10095
  super.setNetwork(network);
8769
- this.cosmosClient.updatePrefix(getPrefix(this.network));
10096
+ this.cosmosClient = new xchainCosmos.CosmosSDKClient({
10097
+ server: this.getClientUrl().node,
10098
+ chainId: this.getChainId(network),
10099
+ prefix: getPrefix(network),
10100
+ });
8770
10101
  }
8771
10102
  /**
8772
10103
  * Set/update the client URL.
@@ -9018,9 +10349,9 @@ class Client extends xchainClient.BaseXChainClient {
9018
10349
  const txBuilder = buildUnsignedTx({
9019
10350
  cosmosSdk: this.getCosmosClient().sdk,
9020
10351
  txBody: depositTxBody,
9021
- signerPubkey: core.cosmosclient.codec.packAny(signerPubkey),
9022
- gasLimit: core.cosmosclient.Long.fromString(gasLimit.toFixed(0)),
9023
- sequence: account.sequence || core.cosmosclient.Long.ZERO,
10352
+ signerPubkey: core.cosmosclient.codec.instanceToProtoAny(signerPubkey),
10353
+ gasLimit: long_1.fromString(gasLimit.toFixed(0)),
10354
+ sequence: account.sequence || long_1.ZERO,
9024
10355
  });
9025
10356
  const txHash = yield this.getCosmosClient().signAndBroadcast(txBuilder, privKey, account);
9026
10357
  if (!txHash)
@@ -9071,12 +10402,12 @@ class Client extends xchainClient.BaseXChainClient {
9071
10402
  nodeUrl: this.getClientUrl().node,
9072
10403
  });
9073
10404
  const account = yield this.getCosmosClient().getAccount(accAddress);
9074
- const accountSequence = account.sequence || core.cosmosclient.Long.ZERO;
10405
+ const accountSequence = account.sequence || long_1.ZERO;
9075
10406
  const txBuilder = buildUnsignedTx({
9076
10407
  cosmosSdk: this.getCosmosClient().sdk,
9077
10408
  txBody: txBody,
9078
- gasLimit: core.cosmosclient.Long.fromString(gasLimit.toString()),
9079
- signerPubkey: core.cosmosclient.codec.packAny(signerPubkey),
10409
+ gasLimit: long_1.fromString(gasLimit.toString()),
10410
+ signerPubkey: core.cosmosclient.codec.instanceToProtoAny(signerPubkey),
9080
10411
  sequence: accountSequence,
9081
10412
  });
9082
10413
  const txHash = yield this.cosmosClient.signAndBroadcast(txBuilder, privKey, account);
@@ -9091,7 +10422,7 @@ class Client extends xchainClient.BaseXChainClient {
9091
10422
  * @param {TxOfflineParams} params The transfer offline options.
9092
10423
  * @returns {string} The signed transaction bytes.
9093
10424
  */
9094
- transferOffline({ walletIndex = 0, asset = xchainUtil.AssetRuneNative, amount, recipient, memo, fromRuneBalance: from_rune_balance, fromAssetBalance: from_asset_balance = xchainUtil.baseAmount(0, DECIMAL), fromAccountNumber = core.cosmosclient.Long.ZERO, fromSequence = core.cosmosclient.Long.ZERO, gasLimit = new bignumber(DEFAULT_GAS_LIMIT_VALUE), }) {
10425
+ transferOffline({ walletIndex = 0, asset = xchainUtil.AssetRuneNative, amount, recipient, memo, fromRuneBalance: from_rune_balance, fromAssetBalance: from_asset_balance = xchainUtil.baseAmount(0, DECIMAL), fromAccountNumber = long_1.ZERO, fromSequence = long_1.ZERO, gasLimit = new bignumber(DEFAULT_GAS_LIMIT_VALUE), }) {
9095
10426
  return __awaiter(this, void 0, void 0, function* () {
9096
10427
  const fee = (yield this.getFees()).average;
9097
10428
  if (isAssetRuneNative(asset)) {
@@ -9119,8 +10450,8 @@ class Client extends xchainClient.BaseXChainClient {
9119
10450
  const txBuilder = buildUnsignedTx({
9120
10451
  cosmosSdk: this.getCosmosClient().sdk,
9121
10452
  txBody: txBody,
9122
- gasLimit: core.cosmosclient.Long.fromString(gasLimit.toFixed(0)),
9123
- signerPubkey: core.cosmosclient.codec.packAny(privKey.pubKey()),
10453
+ gasLimit: long_1.fromString(gasLimit.toFixed(0)),
10454
+ signerPubkey: core.cosmosclient.codec.instanceToProtoAny(privKey.pubKey()),
9124
10455
  sequence: fromSequence,
9125
10456
  });
9126
10457
  const signDocBytes = txBuilder.signDocBytes(fromAccountNumber);