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