ccxt 4.5.18 → 4.5.20

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.
Files changed (152) hide show
  1. package/README.md +7 -6
  2. package/dist/ccxt.browser.min.js +40 -16
  3. package/dist/cjs/_virtual/index.cjs.js +1459 -9
  4. package/dist/cjs/ccxt.js +8 -2
  5. package/dist/cjs/src/abstract/dydx.js +11 -0
  6. package/dist/cjs/src/base/Exchange.js +164 -10
  7. package/dist/cjs/src/base/ws/Client.js +3 -1
  8. package/dist/cjs/src/binance.js +8 -1
  9. package/dist/cjs/src/bingx.js +20 -0
  10. package/dist/cjs/src/bitget.js +43 -41
  11. package/dist/cjs/src/bybit.js +21 -23
  12. package/dist/cjs/src/deribit.js +6 -0
  13. package/dist/cjs/src/dydx.js +2454 -0
  14. package/dist/cjs/src/gate.js +4 -4
  15. package/dist/cjs/src/hibachi.js +1 -1
  16. package/dist/cjs/src/hyperliquid.js +207 -9
  17. package/dist/cjs/src/kucoin.js +711 -109
  18. package/dist/cjs/src/mexc.js +2 -3
  19. package/dist/cjs/src/pro/binance.js +59 -144
  20. package/dist/cjs/src/pro/dydx.js +418 -0
  21. package/dist/cjs/src/pro/kraken.js +4 -3
  22. package/dist/cjs/src/pro/xt.js +218 -4
  23. package/dist/cjs/src/protobuf/mexc/compiled.cjs.js +1 -0
  24. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.js +56 -0
  25. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.js +56 -0
  26. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.js +48 -0
  27. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.js +343 -0
  28. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.js +717 -0
  29. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.js +60 -0
  30. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.js +45 -0
  31. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.js +380 -0
  32. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.js +72 -0
  33. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.js +211 -0
  34. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.js +195 -0
  35. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.js +49 -0
  36. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.js +57 -0
  37. package/dist/cjs/src/static_dependencies/dydx-v4-client/google/protobuf/any.js +56 -0
  38. package/dist/cjs/src/static_dependencies/dydx-v4-client/helpers.js +79 -0
  39. package/dist/cjs/src/static_dependencies/dydx-v4-client/long/index.cjs.js +9 -0
  40. package/dist/cjs/src/static_dependencies/dydx-v4-client/onboarding.js +59 -0
  41. package/dist/cjs/src/static_dependencies/dydx-v4-client/registry.js +39 -0
  42. package/dist/cjs/src/static_dependencies/noble-hashes/pbkdf2.js +69 -0
  43. package/dist/cjs/src/static_dependencies/noble-hashes/ripemd160.js +108 -0
  44. package/dist/cjs/src/static_dependencies/noble-hashes/utils.js +50 -1
  45. package/dist/cjs/src/static_dependencies/scure-base/index.js +29 -0
  46. package/dist/cjs/src/static_dependencies/scure-bip32/index.js +278 -0
  47. package/dist/cjs/src/static_dependencies/scure-bip39/index.js +97 -0
  48. package/dist/cjs/src/static_dependencies/scure-bip39/wordlists/english.js +2060 -0
  49. package/dist/cjs/src/static_dependencies/zklink/zklink-sdk-web.js +2 -0
  50. package/dist/cjs/src/toobit.js +2 -1
  51. package/js/ccxt.d.ts +8 -2
  52. package/js/ccxt.js +6 -2
  53. package/js/src/abstract/binance.d.ts +7 -0
  54. package/js/src/abstract/binancecoinm.d.ts +7 -0
  55. package/js/src/abstract/binanceus.d.ts +7 -0
  56. package/js/src/abstract/binanceusdm.d.ts +7 -0
  57. package/js/src/abstract/bitget.d.ts +1 -0
  58. package/js/src/abstract/dydx.d.ts +61 -0
  59. package/js/src/abstract/dydx.js +11 -0
  60. package/js/src/abstract/kucoin.d.ts +1 -1
  61. package/js/src/abstract/kucoinfutures.d.ts +1 -1
  62. package/js/src/base/Exchange.d.ts +7 -0
  63. package/js/src/base/Exchange.js +163 -10
  64. package/js/src/base/ws/Client.js +3 -1
  65. package/js/src/binance.js +8 -1
  66. package/js/src/bingx.js +20 -0
  67. package/js/src/bitget.d.ts +3 -3
  68. package/js/src/bitget.js +43 -41
  69. package/js/src/bybit.d.ts +3 -3
  70. package/js/src/bybit.js +21 -23
  71. package/js/src/deribit.js +6 -0
  72. package/js/src/dydx.d.ts +364 -0
  73. package/js/src/dydx.js +2453 -0
  74. package/js/src/gate.d.ts +2 -2
  75. package/js/src/gate.js +4 -4
  76. package/js/src/hibachi.js +1 -1
  77. package/js/src/hyperliquid.d.ts +17 -0
  78. package/js/src/hyperliquid.js +207 -9
  79. package/js/src/kucoin.d.ts +48 -1
  80. package/js/src/kucoin.js +711 -109
  81. package/js/src/mexc.js +2 -3
  82. package/js/src/pro/binance.d.ts +2 -2
  83. package/js/src/pro/binance.js +59 -144
  84. package/js/src/pro/dydx.d.ts +81 -0
  85. package/js/src/pro/dydx.js +417 -0
  86. package/js/src/pro/kraken.js +4 -3
  87. package/js/src/pro/xt.d.ts +85 -2
  88. package/js/src/pro/xt.js +218 -4
  89. package/js/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.d.ts +90 -0
  90. package/js/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.js +163 -0
  91. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/keys.d.ts +26 -0
  92. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/keys.js +51 -0
  93. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.d.ts +48 -0
  94. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.js +85 -0
  95. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.d.ts +40 -0
  96. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.js +77 -0
  97. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.d.ts +162 -0
  98. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.js +329 -0
  99. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.d.ts +460 -0
  100. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.js +698 -0
  101. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.d.ts +127 -0
  102. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.js +286 -0
  103. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/block_rate_limit_config.d.ts +66 -0
  104. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/block_rate_limit_config.js +109 -0
  105. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.d.ts +127 -0
  106. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.js +257 -0
  107. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/equity_tier_limit_config.d.ts +48 -0
  108. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/equity_tier_limit_config.js +93 -0
  109. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/finalize_block.d.ts +23 -0
  110. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/finalize_block.js +43 -0
  111. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations.d.ts +92 -0
  112. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations.js +164 -0
  113. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations_config.d.ts +124 -0
  114. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations_config.js +196 -0
  115. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/matches.d.ts +159 -0
  116. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/matches.js +324 -0
  117. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.d.ts +546 -0
  118. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.js +872 -0
  119. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.d.ts +84 -0
  120. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.js +181 -0
  121. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.d.ts +397 -0
  122. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.js +757 -0
  123. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.d.ts +120 -0
  124. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.js +246 -0
  125. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.d.ts +79 -0
  126. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.js +147 -0
  127. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/asset_position.d.ts +32 -0
  128. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/asset_position.js +59 -0
  129. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/perpetual_position.d.ts +34 -0
  130. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/perpetual_position.js +66 -0
  131. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.d.ts +62 -0
  132. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.js +111 -0
  133. package/js/src/static_dependencies/dydx-v4-client/google/protobuf/any.d.ts +207 -0
  134. package/js/src/static_dependencies/dydx-v4-client/google/protobuf/any.js +50 -0
  135. package/js/src/static_dependencies/dydx-v4-client/helpers.d.ts +82 -0
  136. package/js/src/static_dependencies/dydx-v4-client/helpers.js +172 -0
  137. package/js/src/static_dependencies/dydx-v4-client/long/index.cjs +1473 -0
  138. package/js/src/static_dependencies/dydx-v4-client/long/index.d.cts +2 -0
  139. package/js/src/static_dependencies/dydx-v4-client/onboarding.d.ts +35 -0
  140. package/js/src/static_dependencies/dydx-v4-client/onboarding.js +56 -0
  141. package/js/src/static_dependencies/dydx-v4-client/registry.d.ts +7 -0
  142. package/js/src/static_dependencies/dydx-v4-client/registry.js +36 -0
  143. package/js/src/static_dependencies/noble-hashes/utils.d.ts +1 -0
  144. package/js/src/static_dependencies/noble-hashes/utils.js +4 -0
  145. package/js/src/static_dependencies/scure-bip32/index.d.ts +49 -0
  146. package/js/src/static_dependencies/scure-bip32/index.js +295 -0
  147. package/js/src/static_dependencies/scure-bip39/index.d.ts +54 -0
  148. package/js/src/static_dependencies/scure-bip39/index.js +140 -0
  149. package/js/src/static_dependencies/scure-bip39/wordlists/english.d.ts +1 -0
  150. package/js/src/static_dependencies/scure-bip39/wordlists/english.js +2054 -0
  151. package/js/src/toobit.js +2 -1
  152. package/package.json +9 -3
@@ -0,0 +1,1473 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ "use strict";
8
+ // GENERATED FILE. DO NOT EDIT.
9
+ (function (global, factory) {
10
+ function preferDefault(exports) {
11
+ return exports.default || exports;
12
+ }
13
+ if (typeof define === "function" && define.amd) {
14
+ define([], function () {
15
+ var exports = {};
16
+ factory(exports);
17
+ return preferDefault(exports);
18
+ });
19
+ }
20
+ else if (typeof exports === "object") {
21
+ factory(exports);
22
+ if (typeof module === "object")
23
+ module.exports = preferDefault(exports);
24
+ }
25
+ else {
26
+ (function () {
27
+ var exports = {};
28
+ factory(exports);
29
+ global.Long = preferDefault(exports);
30
+ })();
31
+ }
32
+ })(typeof globalThis !== "undefined"
33
+ ? globalThis
34
+ : typeof self !== "undefined"
35
+ ? self
36
+ : this, function (_exports) {
37
+ "use strict";
38
+ Object.defineProperty(_exports, "__esModule", {
39
+ value: true,
40
+ });
41
+ _exports.default = void 0;
42
+ /**
43
+ * @license
44
+ * Copyright 2009 The Closure Library Authors
45
+ * Copyright 2020 Daniel Wirtz / The long.js Authors.
46
+ *
47
+ * Licensed under the Apache License, Version 2.0 (the "License");
48
+ * you may not use this file except in compliance with the License.
49
+ * You may obtain a copy of the License at
50
+ *
51
+ * http://www.apache.org/licenses/LICENSE-2.0
52
+ *
53
+ * Unless required by applicable law or agreed to in writing, software
54
+ * distributed under the License is distributed on an "AS IS" BASIS,
55
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56
+ * See the License for the specific language governing permissions and
57
+ * limitations under the License.
58
+ *
59
+ * SPDX-License-Identifier: Apache-2.0
60
+ */
61
+ // WebAssembly optimizations to do native i64 multiplication and divide
62
+ var wasm = null;
63
+ try {
64
+ wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
65
+ // \0asm
66
+ 0, 97, 115, 109,
67
+ // version 1
68
+ 1, 0, 0, 0,
69
+ // section "type"
70
+ 1, 13, 2,
71
+ // 0, () => i32
72
+ 96, 0, 1, 127,
73
+ // 1, (i32, i32, i32, i32) => i32
74
+ 96, 4, 127, 127, 127, 127, 1, 127,
75
+ // section "function"
76
+ 3, 7, 6,
77
+ // 0, type 0
78
+ 0,
79
+ // 1, type 1
80
+ 1,
81
+ // 2, type 1
82
+ 1,
83
+ // 3, type 1
84
+ 1,
85
+ // 4, type 1
86
+ 1,
87
+ // 5, type 1
88
+ 1,
89
+ // section "global"
90
+ 6, 6, 1,
91
+ // 0, "high", mutable i32
92
+ 127, 1, 65, 0, 11,
93
+ // section "export"
94
+ 7, 50, 6,
95
+ // 0, "mul"
96
+ 3, 109, 117, 108, 0, 1,
97
+ // 1, "div_s"
98
+ 5, 100, 105, 118, 95, 115, 0, 2,
99
+ // 2, "div_u"
100
+ 5, 100, 105, 118, 95, 117, 0, 3,
101
+ // 3, "rem_s"
102
+ 5, 114, 101, 109, 95, 115, 0, 4,
103
+ // 4, "rem_u"
104
+ 5, 114, 101, 109, 95, 117, 0, 5,
105
+ // 5, "get_high"
106
+ 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0,
107
+ // section "code"
108
+ 10, 191, 1, 6,
109
+ // 0, "get_high"
110
+ 4, 0, 35, 0, 11,
111
+ // 1, "mul"
112
+ 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173,
113
+ 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0,
114
+ 32, 4, 167, 11,
115
+ // 2, "div_s"
116
+ 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173,
117
+ 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0,
118
+ 32, 4, 167, 11,
119
+ // 3, "div_u"
120
+ 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173,
121
+ 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0,
122
+ 32, 4, 167, 11,
123
+ // 4, "rem_s"
124
+ 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173,
125
+ 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0,
126
+ 32, 4, 167, 11,
127
+ // 5, "rem_u"
128
+ 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173,
129
+ 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0,
130
+ 32, 4, 167, 11,
131
+ ])), {}).exports;
132
+ }
133
+ catch {
134
+ // no wasm support :(
135
+ }
136
+ /**
137
+ * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
138
+ * See the from* functions below for more convenient ways of constructing Longs.
139
+ * @exports Long
140
+ * @class A Long class for representing a 64 bit two's-complement integer value.
141
+ * @param {number} low The low (signed) 32 bits of the long
142
+ * @param {number} high The high (signed) 32 bits of the long
143
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
144
+ * @constructor
145
+ */
146
+ function Long(low, high, unsigned) {
147
+ /**
148
+ * The low 32 bits as a signed value.
149
+ * @type {number}
150
+ */
151
+ this.low = low | 0;
152
+ /**
153
+ * The high 32 bits as a signed value.
154
+ * @type {number}
155
+ */
156
+ this.high = high | 0;
157
+ /**
158
+ * Whether unsigned or not.
159
+ * @type {boolean}
160
+ */
161
+ this.unsigned = !!unsigned;
162
+ }
163
+ // The internal representation of a long is the two given signed, 32-bit values.
164
+ // We use 32-bit pieces because these are the size of integers on which
165
+ // Javascript performs bit-operations. For operations like addition and
166
+ // multiplication, we split each number into 16 bit pieces, which can easily be
167
+ // multiplied within Javascript's floating-point representation without overflow
168
+ // or change in sign.
169
+ //
170
+ // In the algorithms below, we frequently reduce the negative case to the
171
+ // positive case by negating the input(s) and then post-processing the result.
172
+ // Note that we must ALWAYS check specially whether those values are MIN_VALUE
173
+ // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
174
+ // a positive number, it overflows back into a negative). Not handling this
175
+ // case would often result in infinite recursion.
176
+ //
177
+ // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
178
+ // methods on which they depend.
179
+ /**
180
+ * An indicator used to reliably determine if an object is a Long or not.
181
+ * @type {boolean}
182
+ * @const
183
+ * @private
184
+ */
185
+ Long.prototype.__isLong__;
186
+ Object.defineProperty(Long.prototype, "__isLong__", {
187
+ value: true,
188
+ });
189
+ /**
190
+ * @function
191
+ * @param {*} obj Object
192
+ * @returns {boolean}
193
+ * @inner
194
+ */
195
+ function isLong(obj) {
196
+ return (obj && obj["__isLong__"]) === true;
197
+ }
198
+ /**
199
+ * @function
200
+ * @param {*} value number
201
+ * @returns {number}
202
+ * @inner
203
+ */
204
+ function ctz32(value) {
205
+ var c = Math.clz32(value & -value);
206
+ return value ? 31 - c : c;
207
+ }
208
+ /**
209
+ * Tests if the specified object is a Long.
210
+ * @function
211
+ * @param {*} obj Object
212
+ * @returns {boolean}
213
+ */
214
+ Long.isLong = isLong;
215
+ /**
216
+ * A cache of the Long representations of small integer values.
217
+ * @type {!Object}
218
+ * @inner
219
+ */
220
+ var INT_CACHE = {};
221
+ /**
222
+ * A cache of the Long representations of small unsigned integer values.
223
+ * @type {!Object}
224
+ * @inner
225
+ */
226
+ var UINT_CACHE = {};
227
+ /**
228
+ * @param {number} value
229
+ * @param {boolean=} unsigned
230
+ * @returns {!Long}
231
+ * @inner
232
+ */
233
+ function fromInt(value, unsigned) {
234
+ var obj, cachedObj, cache;
235
+ if (unsigned) {
236
+ value >>>= 0;
237
+ if ((cache = 0 <= value && value < 256)) {
238
+ cachedObj = UINT_CACHE[value];
239
+ if (cachedObj)
240
+ return cachedObj;
241
+ }
242
+ obj = fromBits(value, 0, true);
243
+ if (cache)
244
+ UINT_CACHE[value] = obj;
245
+ return obj;
246
+ }
247
+ else {
248
+ value |= 0;
249
+ if ((cache = -128 <= value && value < 128)) {
250
+ cachedObj = INT_CACHE[value];
251
+ if (cachedObj)
252
+ return cachedObj;
253
+ }
254
+ obj = fromBits(value, value < 0 ? -1 : 0, false);
255
+ if (cache)
256
+ INT_CACHE[value] = obj;
257
+ return obj;
258
+ }
259
+ }
260
+ /**
261
+ * Returns a Long representing the given 32 bit integer value.
262
+ * @function
263
+ * @param {number} value The 32 bit integer in question
264
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
265
+ * @returns {!Long} The corresponding Long value
266
+ */
267
+ Long.fromInt = fromInt;
268
+ /**
269
+ * @param {number} value
270
+ * @param {boolean=} unsigned
271
+ * @returns {!Long}
272
+ * @inner
273
+ */
274
+ function fromNumber(value, unsigned) {
275
+ if (isNaN(value))
276
+ return unsigned ? UZERO : ZERO;
277
+ if (unsigned) {
278
+ if (value < 0)
279
+ return UZERO;
280
+ if (value >= TWO_PWR_64_DBL)
281
+ return MAX_UNSIGNED_VALUE;
282
+ }
283
+ else {
284
+ if (value <= -TWO_PWR_63_DBL)
285
+ return MIN_VALUE;
286
+ if (value + 1 >= TWO_PWR_63_DBL)
287
+ return MAX_VALUE;
288
+ }
289
+ if (value < 0)
290
+ return fromNumber(-value, unsigned).neg();
291
+ return fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
292
+ }
293
+ /**
294
+ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
295
+ * @function
296
+ * @param {number} value The number in question
297
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
298
+ * @returns {!Long} The corresponding Long value
299
+ */
300
+ Long.fromNumber = fromNumber;
301
+ /**
302
+ * @param {number} lowBits
303
+ * @param {number} highBits
304
+ * @param {boolean=} unsigned
305
+ * @returns {!Long}
306
+ * @inner
307
+ */
308
+ function fromBits(lowBits, highBits, unsigned) {
309
+ return new Long(lowBits, highBits, unsigned);
310
+ }
311
+ /**
312
+ * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
313
+ * assumed to use 32 bits.
314
+ * @function
315
+ * @param {number} lowBits The low 32 bits
316
+ * @param {number} highBits The high 32 bits
317
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
318
+ * @returns {!Long} The corresponding Long value
319
+ */
320
+ Long.fromBits = fromBits;
321
+ /**
322
+ * @function
323
+ * @param {number} base
324
+ * @param {number} exponent
325
+ * @returns {number}
326
+ * @inner
327
+ */
328
+ var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
329
+ /**
330
+ * @param {string} str
331
+ * @param {(boolean|number)=} unsigned
332
+ * @param {number=} radix
333
+ * @returns {!Long}
334
+ * @inner
335
+ */
336
+ function fromString(str, unsigned, radix) {
337
+ if (str.length === 0)
338
+ throw Error("empty string");
339
+ if (typeof unsigned === "number") {
340
+ // For goog.math.long compatibility
341
+ radix = unsigned;
342
+ unsigned = false;
343
+ }
344
+ else {
345
+ unsigned = !!unsigned;
346
+ }
347
+ if (str === "NaN" ||
348
+ str === "Infinity" ||
349
+ str === "+Infinity" ||
350
+ str === "-Infinity")
351
+ return unsigned ? UZERO : ZERO;
352
+ radix = radix || 10;
353
+ if (radix < 2 || 36 < radix)
354
+ throw RangeError("radix");
355
+ var p;
356
+ if ((p = str.indexOf("-")) > 0)
357
+ throw Error("interior hyphen");
358
+ else if (p === 0) {
359
+ return fromString(str.substring(1), unsigned, radix).neg();
360
+ }
361
+ // Do several (8) digits each time through the loop, so as to
362
+ // minimize the calls to the very expensive emulated div.
363
+ var radixToPower = fromNumber(pow_dbl(radix, 8));
364
+ var result = ZERO;
365
+ for (var i = 0; i < str.length; i += 8) {
366
+ var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
367
+ if (size < 8) {
368
+ var power = fromNumber(pow_dbl(radix, size));
369
+ result = result.mul(power).add(fromNumber(value));
370
+ }
371
+ else {
372
+ result = result.mul(radixToPower);
373
+ result = result.add(fromNumber(value));
374
+ }
375
+ }
376
+ result.unsigned = unsigned;
377
+ return result;
378
+ }
379
+ /**
380
+ * Returns a Long representation of the given string, written using the specified radix.
381
+ * @function
382
+ * @param {string} str The textual representation of the Long
383
+ * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
384
+ * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
385
+ * @returns {!Long} The corresponding Long value
386
+ */
387
+ Long.fromString = fromString;
388
+ /**
389
+ * @function
390
+ * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
391
+ * @param {boolean=} unsigned
392
+ * @returns {!Long}
393
+ * @inner
394
+ */
395
+ function fromValue(val, unsigned) {
396
+ if (typeof val === "number")
397
+ return fromNumber(val, unsigned);
398
+ if (typeof val === "string")
399
+ return fromString(val, unsigned);
400
+ // Throws for non-objects, converts non-instanceof Long:
401
+ return fromBits(val.low, val.high, typeof unsigned === "boolean" ? unsigned : val.unsigned);
402
+ }
403
+ /**
404
+ * Converts the specified value to a Long using the appropriate from* function for its type.
405
+ * @function
406
+ * @param {!Long|number|bigint|string|!{low: number, high: number, unsigned: boolean}} val Value
407
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
408
+ * @returns {!Long}
409
+ */
410
+ Long.fromValue = fromValue;
411
+ // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
412
+ // no runtime penalty for these.
413
+ /**
414
+ * @type {number}
415
+ * @const
416
+ * @inner
417
+ */
418
+ var TWO_PWR_16_DBL = 1 << 16;
419
+ /**
420
+ * @type {number}
421
+ * @const
422
+ * @inner
423
+ */
424
+ var TWO_PWR_24_DBL = 1 << 24;
425
+ /**
426
+ * @type {number}
427
+ * @const
428
+ * @inner
429
+ */
430
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
431
+ /**
432
+ * @type {number}
433
+ * @const
434
+ * @inner
435
+ */
436
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
437
+ /**
438
+ * @type {number}
439
+ * @const
440
+ * @inner
441
+ */
442
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
443
+ /**
444
+ * @type {!Long}
445
+ * @const
446
+ * @inner
447
+ */
448
+ var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
449
+ /**
450
+ * @type {!Long}
451
+ * @inner
452
+ */
453
+ var ZERO = fromInt(0);
454
+ /**
455
+ * Signed zero.
456
+ * @type {!Long}
457
+ */
458
+ Long.ZERO = ZERO;
459
+ /**
460
+ * @type {!Long}
461
+ * @inner
462
+ */
463
+ var UZERO = fromInt(0, true);
464
+ /**
465
+ * Unsigned zero.
466
+ * @type {!Long}
467
+ */
468
+ Long.UZERO = UZERO;
469
+ /**
470
+ * @type {!Long}
471
+ * @inner
472
+ */
473
+ var ONE = fromInt(1);
474
+ /**
475
+ * Signed one.
476
+ * @type {!Long}
477
+ */
478
+ Long.ONE = ONE;
479
+ /**
480
+ * @type {!Long}
481
+ * @inner
482
+ */
483
+ var UONE = fromInt(1, true);
484
+ /**
485
+ * Unsigned one.
486
+ * @type {!Long}
487
+ */
488
+ Long.UONE = UONE;
489
+ /**
490
+ * @type {!Long}
491
+ * @inner
492
+ */
493
+ var NEG_ONE = fromInt(-1);
494
+ /**
495
+ * Signed negative one.
496
+ * @type {!Long}
497
+ */
498
+ Long.NEG_ONE = NEG_ONE;
499
+ /**
500
+ * @type {!Long}
501
+ * @inner
502
+ */
503
+ var MAX_VALUE = fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
504
+ /**
505
+ * Maximum signed value.
506
+ * @type {!Long}
507
+ */
508
+ Long.MAX_VALUE = MAX_VALUE;
509
+ /**
510
+ * @type {!Long}
511
+ * @inner
512
+ */
513
+ var MAX_UNSIGNED_VALUE = fromBits(0xffffffff | 0, 0xffffffff | 0, true);
514
+ /**
515
+ * Maximum unsigned value.
516
+ * @type {!Long}
517
+ */
518
+ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
519
+ /**
520
+ * @type {!Long}
521
+ * @inner
522
+ */
523
+ var MIN_VALUE = fromBits(0, 0x80000000 | 0, false);
524
+ /**
525
+ * Minimum signed value.
526
+ * @type {!Long}
527
+ */
528
+ Long.MIN_VALUE = MIN_VALUE;
529
+ /**
530
+ * @alias Long.prototype
531
+ * @inner
532
+ */
533
+ var LongPrototype = Long.prototype;
534
+ /**
535
+ * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
536
+ * @this {!Long}
537
+ * @returns {number}
538
+ */
539
+ LongPrototype.toInt = function toInt() {
540
+ return this.unsigned ? this.low >>> 0 : this.low;
541
+ };
542
+ /**
543
+ * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
544
+ * @this {!Long}
545
+ * @returns {number}
546
+ */
547
+ LongPrototype.toNumber = function toNumber() {
548
+ if (this.unsigned)
549
+ return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
550
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
551
+ };
552
+ /**
553
+ * Converts the Long to a string written in the specified radix.
554
+ * @this {!Long}
555
+ * @param {number=} radix Radix (2-36), defaults to 10
556
+ * @returns {string}
557
+ * @override
558
+ * @throws {RangeError} If `radix` is out of range
559
+ */
560
+ LongPrototype.toString = function toString(radix) {
561
+ radix = radix || 10;
562
+ if (radix < 2 || 36 < radix)
563
+ throw RangeError("radix");
564
+ if (this.isZero())
565
+ return "0";
566
+ if (this.isNegative()) {
567
+ // Unsigned Longs are never negative
568
+ if (this.eq(MIN_VALUE)) {
569
+ // We need to change the Long value before it can be negated, so we remove
570
+ // the bottom-most digit in this base and then recurse to do the rest.
571
+ var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
572
+ return div.toString(radix) + rem1.toInt().toString(radix);
573
+ }
574
+ else
575
+ return "-" + this.neg().toString(radix);
576
+ }
577
+ // Do several (6) digits each time through the loop, so as to
578
+ // minimize the calls to the very expensive emulated div.
579
+ var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this;
580
+ var result = "";
581
+ while (true) {
582
+ var remDiv = rem.div(radixToPower), intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, digits = intval.toString(radix);
583
+ rem = remDiv;
584
+ if (rem.isZero())
585
+ return digits + result;
586
+ else {
587
+ while (digits.length < 6)
588
+ digits = "0" + digits;
589
+ result = "" + digits + result;
590
+ }
591
+ }
592
+ };
593
+ /**
594
+ * Gets the high 32 bits as a signed integer.
595
+ * @this {!Long}
596
+ * @returns {number} Signed high bits
597
+ */
598
+ LongPrototype.getHighBits = function getHighBits() {
599
+ return this.high;
600
+ };
601
+ /**
602
+ * Gets the high 32 bits as an unsigned integer.
603
+ * @this {!Long}
604
+ * @returns {number} Unsigned high bits
605
+ */
606
+ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
607
+ return this.high >>> 0;
608
+ };
609
+ /**
610
+ * Gets the low 32 bits as a signed integer.
611
+ * @this {!Long}
612
+ * @returns {number} Signed low bits
613
+ */
614
+ LongPrototype.getLowBits = function getLowBits() {
615
+ return this.low;
616
+ };
617
+ /**
618
+ * Gets the low 32 bits as an unsigned integer.
619
+ * @this {!Long}
620
+ * @returns {number} Unsigned low bits
621
+ */
622
+ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
623
+ return this.low >>> 0;
624
+ };
625
+ /**
626
+ * Gets the number of bits needed to represent the absolute value of this Long.
627
+ * @this {!Long}
628
+ * @returns {number}
629
+ */
630
+ LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
631
+ if (this.isNegative())
632
+ // Unsigned Longs are never negative
633
+ return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
634
+ var val = this.high != 0 ? this.high : this.low;
635
+ for (var bit = 31; bit > 0; bit--)
636
+ if ((val & (1 << bit)) != 0)
637
+ break;
638
+ return this.high != 0 ? bit + 33 : bit + 1;
639
+ };
640
+ /**
641
+ * Tests if this Long can be safely represented as a JavaScript number.
642
+ * @this {!Long}
643
+ * @returns {boolean}
644
+ */
645
+ LongPrototype.isSafeInteger = function isSafeInteger() {
646
+ // 2^53-1 is the maximum safe value
647
+ var top11Bits = this.high >> 21;
648
+ // [0, 2^53-1]
649
+ if (!top11Bits)
650
+ return true;
651
+ // > 2^53-1
652
+ if (this.unsigned)
653
+ return false;
654
+ // [-2^53, -1] except -2^53
655
+ return top11Bits === -1 && !(this.low === 0 && this.high === -0x200000);
656
+ };
657
+ /**
658
+ * Tests if this Long's value equals zero.
659
+ * @this {!Long}
660
+ * @returns {boolean}
661
+ */
662
+ LongPrototype.isZero = function isZero() {
663
+ return this.high === 0 && this.low === 0;
664
+ };
665
+ /**
666
+ * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
667
+ * @returns {boolean}
668
+ */
669
+ LongPrototype.eqz = LongPrototype.isZero;
670
+ /**
671
+ * Tests if this Long's value is negative.
672
+ * @this {!Long}
673
+ * @returns {boolean}
674
+ */
675
+ LongPrototype.isNegative = function isNegative() {
676
+ return !this.unsigned && this.high < 0;
677
+ };
678
+ /**
679
+ * Tests if this Long's value is positive or zero.
680
+ * @this {!Long}
681
+ * @returns {boolean}
682
+ */
683
+ LongPrototype.isPositive = function isPositive() {
684
+ return this.unsigned || this.high >= 0;
685
+ };
686
+ /**
687
+ * Tests if this Long's value is odd.
688
+ * @this {!Long}
689
+ * @returns {boolean}
690
+ */
691
+ LongPrototype.isOdd = function isOdd() {
692
+ return (this.low & 1) === 1;
693
+ };
694
+ /**
695
+ * Tests if this Long's value is even.
696
+ * @this {!Long}
697
+ * @returns {boolean}
698
+ */
699
+ LongPrototype.isEven = function isEven() {
700
+ return (this.low & 1) === 0;
701
+ };
702
+ /**
703
+ * Tests if this Long's value equals the specified's.
704
+ * @this {!Long}
705
+ * @param {!Long|number|bigint|string} other Other value
706
+ * @returns {boolean}
707
+ */
708
+ LongPrototype.equals = function equals(other) {
709
+ if (!isLong(other))
710
+ other = fromValue(other);
711
+ if (this.unsigned !== other.unsigned &&
712
+ this.high >>> 31 === 1 &&
713
+ other.high >>> 31 === 1)
714
+ return false;
715
+ return this.high === other.high && this.low === other.low;
716
+ };
717
+ /**
718
+ * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
719
+ * @function
720
+ * @param {!Long|number|bigint|string} other Other value
721
+ * @returns {boolean}
722
+ */
723
+ LongPrototype.eq = LongPrototype.equals;
724
+ /**
725
+ * Tests if this Long's value differs from the specified's.
726
+ * @this {!Long}
727
+ * @param {!Long|number|bigint|string} other Other value
728
+ * @returns {boolean}
729
+ */
730
+ LongPrototype.notEquals = function notEquals(other) {
731
+ return !this.eq(/* validates */ other);
732
+ };
733
+ /**
734
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
735
+ * @function
736
+ * @param {!Long|number|bigint|string} other Other value
737
+ * @returns {boolean}
738
+ */
739
+ LongPrototype.neq = LongPrototype.notEquals;
740
+ /**
741
+ * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
742
+ * @function
743
+ * @param {!Long|number|bigint|string} other Other value
744
+ * @returns {boolean}
745
+ */
746
+ LongPrototype.ne = LongPrototype.notEquals;
747
+ /**
748
+ * Tests if this Long's value is less than the specified's.
749
+ * @this {!Long}
750
+ * @param {!Long|number|bigint|string} other Other value
751
+ * @returns {boolean}
752
+ */
753
+ LongPrototype.lessThan = function lessThan(other) {
754
+ return this.comp(/* validates */ other) < 0;
755
+ };
756
+ /**
757
+ * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
758
+ * @function
759
+ * @param {!Long|number|bigint|string} other Other value
760
+ * @returns {boolean}
761
+ */
762
+ LongPrototype.lt = LongPrototype.lessThan;
763
+ /**
764
+ * Tests if this Long's value is less than or equal the specified's.
765
+ * @this {!Long}
766
+ * @param {!Long|number|bigint|string} other Other value
767
+ * @returns {boolean}
768
+ */
769
+ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
770
+ return this.comp(/* validates */ other) <= 0;
771
+ };
772
+ /**
773
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
774
+ * @function
775
+ * @param {!Long|number|bigint|string} other Other value
776
+ * @returns {boolean}
777
+ */
778
+ LongPrototype.lte = LongPrototype.lessThanOrEqual;
779
+ /**
780
+ * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
781
+ * @function
782
+ * @param {!Long|number|bigint|string} other Other value
783
+ * @returns {boolean}
784
+ */
785
+ LongPrototype.le = LongPrototype.lessThanOrEqual;
786
+ /**
787
+ * Tests if this Long's value is greater than the specified's.
788
+ * @this {!Long}
789
+ * @param {!Long|number|bigint|string} other Other value
790
+ * @returns {boolean}
791
+ */
792
+ LongPrototype.greaterThan = function greaterThan(other) {
793
+ return this.comp(/* validates */ other) > 0;
794
+ };
795
+ /**
796
+ * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
797
+ * @function
798
+ * @param {!Long|number|bigint|string} other Other value
799
+ * @returns {boolean}
800
+ */
801
+ LongPrototype.gt = LongPrototype.greaterThan;
802
+ /**
803
+ * Tests if this Long's value is greater than or equal the specified's.
804
+ * @this {!Long}
805
+ * @param {!Long|number|bigint|string} other Other value
806
+ * @returns {boolean}
807
+ */
808
+ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
809
+ return this.comp(/* validates */ other) >= 0;
810
+ };
811
+ /**
812
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
813
+ * @function
814
+ * @param {!Long|number|bigint|string} other Other value
815
+ * @returns {boolean}
816
+ */
817
+ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
818
+ /**
819
+ * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
820
+ * @function
821
+ * @param {!Long|number|bigint|string} other Other value
822
+ * @returns {boolean}
823
+ */
824
+ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
825
+ /**
826
+ * Compares this Long's value with the specified's.
827
+ * @this {!Long}
828
+ * @param {!Long|number|bigint|string} other Other value
829
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
830
+ * if the given one is greater
831
+ */
832
+ LongPrototype.compare = function compare(other) {
833
+ if (!isLong(other))
834
+ other = fromValue(other);
835
+ if (this.eq(other))
836
+ return 0;
837
+ var thisNeg = this.isNegative(), otherNeg = other.isNegative();
838
+ if (thisNeg && !otherNeg)
839
+ return -1;
840
+ if (!thisNeg && otherNeg)
841
+ return 1;
842
+ // At this point the sign bits are the same
843
+ if (!this.unsigned)
844
+ return this.sub(other).isNegative() ? -1 : 1;
845
+ // Both are positive if at least one is unsigned
846
+ return other.high >>> 0 > this.high >>> 0 ||
847
+ (other.high === this.high && other.low >>> 0 > this.low >>> 0)
848
+ ? -1
849
+ : 1;
850
+ };
851
+ /**
852
+ * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
853
+ * @function
854
+ * @param {!Long|number|bigint|string} other Other value
855
+ * @returns {number} 0 if they are the same, 1 if the this is greater and -1
856
+ * if the given one is greater
857
+ */
858
+ LongPrototype.comp = LongPrototype.compare;
859
+ /**
860
+ * Negates this Long's value.
861
+ * @this {!Long}
862
+ * @returns {!Long} Negated Long
863
+ */
864
+ LongPrototype.negate = function negate() {
865
+ if (!this.unsigned && this.eq(MIN_VALUE))
866
+ return MIN_VALUE;
867
+ return this.not().add(ONE);
868
+ };
869
+ /**
870
+ * Negates this Long's value. This is an alias of {@link Long#negate}.
871
+ * @function
872
+ * @returns {!Long} Negated Long
873
+ */
874
+ LongPrototype.neg = LongPrototype.negate;
875
+ /**
876
+ * Returns the sum of this and the specified Long.
877
+ * @this {!Long}
878
+ * @param {!Long|number|bigint|string} addend Addend
879
+ * @returns {!Long} Sum
880
+ */
881
+ LongPrototype.add = function add(addend) {
882
+ if (!isLong(addend))
883
+ addend = fromValue(addend);
884
+ // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
885
+ var a48 = this.high >>> 16;
886
+ var a32 = this.high & 0xffff;
887
+ var a16 = this.low >>> 16;
888
+ var a00 = this.low & 0xffff;
889
+ var b48 = addend.high >>> 16;
890
+ var b32 = addend.high & 0xffff;
891
+ var b16 = addend.low >>> 16;
892
+ var b00 = addend.low & 0xffff;
893
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
894
+ c00 += a00 + b00;
895
+ c16 += c00 >>> 16;
896
+ c00 &= 0xffff;
897
+ c16 += a16 + b16;
898
+ c32 += c16 >>> 16;
899
+ c16 &= 0xffff;
900
+ c32 += a32 + b32;
901
+ c48 += c32 >>> 16;
902
+ c32 &= 0xffff;
903
+ c48 += a48 + b48;
904
+ c48 &= 0xffff;
905
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
906
+ };
907
+ /**
908
+ * Returns the difference of this and the specified Long.
909
+ * @this {!Long}
910
+ * @param {!Long|number|bigint|string} subtrahend Subtrahend
911
+ * @returns {!Long} Difference
912
+ */
913
+ LongPrototype.subtract = function subtract(subtrahend) {
914
+ if (!isLong(subtrahend))
915
+ subtrahend = fromValue(subtrahend);
916
+ return this.add(subtrahend.neg());
917
+ };
918
+ /**
919
+ * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
920
+ * @function
921
+ * @param {!Long|number|bigint|string} subtrahend Subtrahend
922
+ * @returns {!Long} Difference
923
+ */
924
+ LongPrototype.sub = LongPrototype.subtract;
925
+ /**
926
+ * Returns the product of this and the specified Long.
927
+ * @this {!Long}
928
+ * @param {!Long|number|bigint|string} multiplier Multiplier
929
+ * @returns {!Long} Product
930
+ */
931
+ LongPrototype.multiply = function multiply(multiplier) {
932
+ if (this.isZero())
933
+ return this;
934
+ if (!isLong(multiplier))
935
+ multiplier = fromValue(multiplier);
936
+ // use wasm support if present
937
+ if (wasm) {
938
+ var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
939
+ return fromBits(low, wasm["get_high"](), this.unsigned);
940
+ }
941
+ if (multiplier.isZero())
942
+ return this.unsigned ? UZERO : ZERO;
943
+ if (this.eq(MIN_VALUE))
944
+ return multiplier.isOdd() ? MIN_VALUE : ZERO;
945
+ if (multiplier.eq(MIN_VALUE))
946
+ return this.isOdd() ? MIN_VALUE : ZERO;
947
+ if (this.isNegative()) {
948
+ if (multiplier.isNegative())
949
+ return this.neg().mul(multiplier.neg());
950
+ else
951
+ return this.neg().mul(multiplier).neg();
952
+ }
953
+ else if (multiplier.isNegative())
954
+ return this.mul(multiplier.neg()).neg();
955
+ // If both longs are small, use float multiplication
956
+ if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
957
+ return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
958
+ // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
959
+ // We can skip products that would overflow.
960
+ var a48 = this.high >>> 16;
961
+ var a32 = this.high & 0xffff;
962
+ var a16 = this.low >>> 16;
963
+ var a00 = this.low & 0xffff;
964
+ var b48 = multiplier.high >>> 16;
965
+ var b32 = multiplier.high & 0xffff;
966
+ var b16 = multiplier.low >>> 16;
967
+ var b00 = multiplier.low & 0xffff;
968
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
969
+ c00 += a00 * b00;
970
+ c16 += c00 >>> 16;
971
+ c00 &= 0xffff;
972
+ c16 += a16 * b00;
973
+ c32 += c16 >>> 16;
974
+ c16 &= 0xffff;
975
+ c16 += a00 * b16;
976
+ c32 += c16 >>> 16;
977
+ c16 &= 0xffff;
978
+ c32 += a32 * b00;
979
+ c48 += c32 >>> 16;
980
+ c32 &= 0xffff;
981
+ c32 += a16 * b16;
982
+ c48 += c32 >>> 16;
983
+ c32 &= 0xffff;
984
+ c32 += a00 * b32;
985
+ c48 += c32 >>> 16;
986
+ c32 &= 0xffff;
987
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
988
+ c48 &= 0xffff;
989
+ return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
990
+ };
991
+ /**
992
+ * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
993
+ * @function
994
+ * @param {!Long|number|bigint|string} multiplier Multiplier
995
+ * @returns {!Long} Product
996
+ */
997
+ LongPrototype.mul = LongPrototype.multiply;
998
+ /**
999
+ * Returns this Long divided by the specified. The result is signed if this Long is signed or
1000
+ * unsigned if this Long is unsigned.
1001
+ * @this {!Long}
1002
+ * @param {!Long|number|bigint|string} divisor Divisor
1003
+ * @returns {!Long} Quotient
1004
+ */
1005
+ LongPrototype.divide = function divide(divisor) {
1006
+ if (!isLong(divisor))
1007
+ divisor = fromValue(divisor);
1008
+ if (divisor.isZero())
1009
+ throw Error("division by zero");
1010
+ // use wasm support if present
1011
+ if (wasm) {
1012
+ // guard against signed division overflow: the largest
1013
+ // negative number / -1 would be 1 larger than the largest
1014
+ // positive number, due to two's complement.
1015
+ if (!this.unsigned &&
1016
+ this.high === -0x80000000 &&
1017
+ divisor.low === -1 &&
1018
+ divisor.high === -1) {
1019
+ // be consistent with non-wasm code path
1020
+ return this;
1021
+ }
1022
+ var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(this.low, this.high, divisor.low, divisor.high);
1023
+ return fromBits(low, wasm["get_high"](), this.unsigned);
1024
+ }
1025
+ if (this.isZero())
1026
+ return this.unsigned ? UZERO : ZERO;
1027
+ var approx, rem, res;
1028
+ if (!this.unsigned) {
1029
+ // This section is only relevant for signed longs and is derived from the
1030
+ // closure library as a whole.
1031
+ if (this.eq(MIN_VALUE)) {
1032
+ if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
1033
+ return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
1034
+ else if (divisor.eq(MIN_VALUE))
1035
+ return ONE;
1036
+ else {
1037
+ // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
1038
+ var halfThis = this.shr(1);
1039
+ approx = halfThis.div(divisor).shl(1);
1040
+ if (approx.eq(ZERO)) {
1041
+ return divisor.isNegative() ? ONE : NEG_ONE;
1042
+ }
1043
+ else {
1044
+ rem = this.sub(divisor.mul(approx));
1045
+ res = approx.add(rem.div(divisor));
1046
+ return res;
1047
+ }
1048
+ }
1049
+ }
1050
+ else if (divisor.eq(MIN_VALUE))
1051
+ return this.unsigned ? UZERO : ZERO;
1052
+ if (this.isNegative()) {
1053
+ if (divisor.isNegative())
1054
+ return this.neg().div(divisor.neg());
1055
+ return this.neg().div(divisor).neg();
1056
+ }
1057
+ else if (divisor.isNegative())
1058
+ return this.div(divisor.neg()).neg();
1059
+ res = ZERO;
1060
+ }
1061
+ else {
1062
+ // The algorithm below has not been made for unsigned longs. It's therefore
1063
+ // required to take special care of the MSB prior to running it.
1064
+ if (!divisor.unsigned)
1065
+ divisor = divisor.toUnsigned();
1066
+ if (divisor.gt(this))
1067
+ return UZERO;
1068
+ if (divisor.gt(this.shru(1)))
1069
+ // 15 >>> 1 = 7 ; with divisor = 8 ; true
1070
+ return UONE;
1071
+ res = UZERO;
1072
+ }
1073
+ // Repeat the following until the remainder is less than other: find a
1074
+ // floating-point that approximates remainder / other *from below*, add this
1075
+ // into the result, and subtract it from the remainder. It is critical that
1076
+ // the approximate value is less than or equal to the real value so that the
1077
+ // remainder never becomes negative.
1078
+ rem = this;
1079
+ while (rem.gte(divisor)) {
1080
+ // Approximate the result of division. This may be a little greater or
1081
+ // smaller than the actual value.
1082
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
1083
+ // We will tweak the approximate result by changing it in the 48-th digit or
1084
+ // the smallest non-fractional digit, whichever is larger.
1085
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48),
1086
+ // Decrease the approximation until it is smaller than the remainder. Note
1087
+ // that if it is too large, the product overflows and is negative.
1088
+ approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor);
1089
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
1090
+ approx -= delta;
1091
+ approxRes = fromNumber(approx, this.unsigned);
1092
+ approxRem = approxRes.mul(divisor);
1093
+ }
1094
+ // We know the answer can't be zero... and actually, zero would cause
1095
+ // infinite recursion since we would make no progress.
1096
+ if (approxRes.isZero())
1097
+ approxRes = ONE;
1098
+ res = res.add(approxRes);
1099
+ rem = rem.sub(approxRem);
1100
+ }
1101
+ return res;
1102
+ };
1103
+ /**
1104
+ * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
1105
+ * @function
1106
+ * @param {!Long|number|bigint|string} divisor Divisor
1107
+ * @returns {!Long} Quotient
1108
+ */
1109
+ LongPrototype.div = LongPrototype.divide;
1110
+ /**
1111
+ * Returns this Long modulo the specified.
1112
+ * @this {!Long}
1113
+ * @param {!Long|number|bigint|string} divisor Divisor
1114
+ * @returns {!Long} Remainder
1115
+ */
1116
+ LongPrototype.modulo = function modulo(divisor) {
1117
+ if (!isLong(divisor))
1118
+ divisor = fromValue(divisor);
1119
+ // use wasm support if present
1120
+ if (wasm) {
1121
+ var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(this.low, this.high, divisor.low, divisor.high);
1122
+ return fromBits(low, wasm["get_high"](), this.unsigned);
1123
+ }
1124
+ return this.sub(this.div(divisor).mul(divisor));
1125
+ };
1126
+ /**
1127
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
1128
+ * @function
1129
+ * @param {!Long|number|bigint|string} divisor Divisor
1130
+ * @returns {!Long} Remainder
1131
+ */
1132
+ LongPrototype.mod = LongPrototype.modulo;
1133
+ /**
1134
+ * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
1135
+ * @function
1136
+ * @param {!Long|number|bigint|string} divisor Divisor
1137
+ * @returns {!Long} Remainder
1138
+ */
1139
+ LongPrototype.rem = LongPrototype.modulo;
1140
+ /**
1141
+ * Returns the bitwise NOT of this Long.
1142
+ * @this {!Long}
1143
+ * @returns {!Long}
1144
+ */
1145
+ LongPrototype.not = function not() {
1146
+ return fromBits(~this.low, ~this.high, this.unsigned);
1147
+ };
1148
+ /**
1149
+ * Returns count leading zeros of this Long.
1150
+ * @this {!Long}
1151
+ * @returns {!number}
1152
+ */
1153
+ LongPrototype.countLeadingZeros = function countLeadingZeros() {
1154
+ return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
1155
+ };
1156
+ /**
1157
+ * Returns count leading zeros. This is an alias of {@link Long#countLeadingZeros}.
1158
+ * @function
1159
+ * @param {!Long}
1160
+ * @returns {!number}
1161
+ */
1162
+ LongPrototype.clz = LongPrototype.countLeadingZeros;
1163
+ /**
1164
+ * Returns count trailing zeros of this Long.
1165
+ * @this {!Long}
1166
+ * @returns {!number}
1167
+ */
1168
+ LongPrototype.countTrailingZeros = function countTrailingZeros() {
1169
+ return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
1170
+ };
1171
+ /**
1172
+ * Returns count trailing zeros. This is an alias of {@link Long#countTrailingZeros}.
1173
+ * @function
1174
+ * @param {!Long}
1175
+ * @returns {!number}
1176
+ */
1177
+ LongPrototype.ctz = LongPrototype.countTrailingZeros;
1178
+ /**
1179
+ * Returns the bitwise AND of this Long and the specified.
1180
+ * @this {!Long}
1181
+ * @param {!Long|number|bigint|string} other Other Long
1182
+ * @returns {!Long}
1183
+ */
1184
+ LongPrototype.and = function and(other) {
1185
+ if (!isLong(other))
1186
+ other = fromValue(other);
1187
+ return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
1188
+ };
1189
+ /**
1190
+ * Returns the bitwise OR of this Long and the specified.
1191
+ * @this {!Long}
1192
+ * @param {!Long|number|bigint|string} other Other Long
1193
+ * @returns {!Long}
1194
+ */
1195
+ LongPrototype.or = function or(other) {
1196
+ if (!isLong(other))
1197
+ other = fromValue(other);
1198
+ return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
1199
+ };
1200
+ /**
1201
+ * Returns the bitwise XOR of this Long and the given one.
1202
+ * @this {!Long}
1203
+ * @param {!Long|number|bigint|string} other Other Long
1204
+ * @returns {!Long}
1205
+ */
1206
+ LongPrototype.xor = function xor(other) {
1207
+ if (!isLong(other))
1208
+ other = fromValue(other);
1209
+ return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
1210
+ };
1211
+ /**
1212
+ * Returns this Long with bits shifted to the left by the given amount.
1213
+ * @this {!Long}
1214
+ * @param {number|!Long} numBits Number of bits
1215
+ * @returns {!Long} Shifted Long
1216
+ */
1217
+ LongPrototype.shiftLeft = function shiftLeft(numBits) {
1218
+ if (isLong(numBits))
1219
+ numBits = numBits.toInt();
1220
+ if ((numBits &= 63) === 0)
1221
+ return this;
1222
+ else if (numBits < 32)
1223
+ return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
1224
+ else
1225
+ return fromBits(0, this.low << (numBits - 32), this.unsigned);
1226
+ };
1227
+ /**
1228
+ * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
1229
+ * @function
1230
+ * @param {number|!Long} numBits Number of bits
1231
+ * @returns {!Long} Shifted Long
1232
+ */
1233
+ LongPrototype.shl = LongPrototype.shiftLeft;
1234
+ /**
1235
+ * Returns this Long with bits arithmetically shifted to the right by the given amount.
1236
+ * @this {!Long}
1237
+ * @param {number|!Long} numBits Number of bits
1238
+ * @returns {!Long} Shifted Long
1239
+ */
1240
+ LongPrototype.shiftRight = function shiftRight(numBits) {
1241
+ if (isLong(numBits))
1242
+ numBits = numBits.toInt();
1243
+ if ((numBits &= 63) === 0)
1244
+ return this;
1245
+ else if (numBits < 32)
1246
+ return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
1247
+ else
1248
+ return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
1249
+ };
1250
+ /**
1251
+ * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
1252
+ * @function
1253
+ * @param {number|!Long} numBits Number of bits
1254
+ * @returns {!Long} Shifted Long
1255
+ */
1256
+ LongPrototype.shr = LongPrototype.shiftRight;
1257
+ /**
1258
+ * Returns this Long with bits logically shifted to the right by the given amount.
1259
+ * @this {!Long}
1260
+ * @param {number|!Long} numBits Number of bits
1261
+ * @returns {!Long} Shifted Long
1262
+ */
1263
+ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
1264
+ if (isLong(numBits))
1265
+ numBits = numBits.toInt();
1266
+ if ((numBits &= 63) === 0)
1267
+ return this;
1268
+ if (numBits < 32)
1269
+ return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >>> numBits, this.unsigned);
1270
+ if (numBits === 32)
1271
+ return fromBits(this.high, 0, this.unsigned);
1272
+ return fromBits(this.high >>> (numBits - 32), 0, this.unsigned);
1273
+ };
1274
+ /**
1275
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
1276
+ * @function
1277
+ * @param {number|!Long} numBits Number of bits
1278
+ * @returns {!Long} Shifted Long
1279
+ */
1280
+ LongPrototype.shru = LongPrototype.shiftRightUnsigned;
1281
+ /**
1282
+ * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
1283
+ * @function
1284
+ * @param {number|!Long} numBits Number of bits
1285
+ * @returns {!Long} Shifted Long
1286
+ */
1287
+ LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
1288
+ /**
1289
+ * Returns this Long with bits rotated to the left by the given amount.
1290
+ * @this {!Long}
1291
+ * @param {number|!Long} numBits Number of bits
1292
+ * @returns {!Long} Rotated Long
1293
+ */
1294
+ LongPrototype.rotateLeft = function rotateLeft(numBits) {
1295
+ var b;
1296
+ if (isLong(numBits))
1297
+ numBits = numBits.toInt();
1298
+ if ((numBits &= 63) === 0)
1299
+ return this;
1300
+ if (numBits === 32)
1301
+ return fromBits(this.high, this.low, this.unsigned);
1302
+ if (numBits < 32) {
1303
+ b = 32 - numBits;
1304
+ return fromBits((this.low << numBits) | (this.high >>> b), (this.high << numBits) | (this.low >>> b), this.unsigned);
1305
+ }
1306
+ numBits -= 32;
1307
+ b = 32 - numBits;
1308
+ return fromBits((this.high << numBits) | (this.low >>> b), (this.low << numBits) | (this.high >>> b), this.unsigned);
1309
+ };
1310
+ /**
1311
+ * Returns this Long with bits rotated to the left by the given amount. This is an alias of {@link Long#rotateLeft}.
1312
+ * @function
1313
+ * @param {number|!Long} numBits Number of bits
1314
+ * @returns {!Long} Rotated Long
1315
+ */
1316
+ LongPrototype.rotl = LongPrototype.rotateLeft;
1317
+ /**
1318
+ * Returns this Long with bits rotated to the right by the given amount.
1319
+ * @this {!Long}
1320
+ * @param {number|!Long} numBits Number of bits
1321
+ * @returns {!Long} Rotated Long
1322
+ */
1323
+ LongPrototype.rotateRight = function rotateRight(numBits) {
1324
+ var b;
1325
+ if (isLong(numBits))
1326
+ numBits = numBits.toInt();
1327
+ if ((numBits &= 63) === 0)
1328
+ return this;
1329
+ if (numBits === 32)
1330
+ return fromBits(this.high, this.low, this.unsigned);
1331
+ if (numBits < 32) {
1332
+ b = 32 - numBits;
1333
+ return fromBits((this.high << b) | (this.low >>> numBits), (this.low << b) | (this.high >>> numBits), this.unsigned);
1334
+ }
1335
+ numBits -= 32;
1336
+ b = 32 - numBits;
1337
+ return fromBits((this.low << b) | (this.high >>> numBits), (this.high << b) | (this.low >>> numBits), this.unsigned);
1338
+ };
1339
+ /**
1340
+ * Returns this Long with bits rotated to the right by the given amount. This is an alias of {@link Long#rotateRight}.
1341
+ * @function
1342
+ * @param {number|!Long} numBits Number of bits
1343
+ * @returns {!Long} Rotated Long
1344
+ */
1345
+ LongPrototype.rotr = LongPrototype.rotateRight;
1346
+ /**
1347
+ * Converts this Long to signed.
1348
+ * @this {!Long}
1349
+ * @returns {!Long} Signed long
1350
+ */
1351
+ LongPrototype.toSigned = function toSigned() {
1352
+ if (!this.unsigned)
1353
+ return this;
1354
+ return fromBits(this.low, this.high, false);
1355
+ };
1356
+ /**
1357
+ * Converts this Long to unsigned.
1358
+ * @this {!Long}
1359
+ * @returns {!Long} Unsigned long
1360
+ */
1361
+ LongPrototype.toUnsigned = function toUnsigned() {
1362
+ if (this.unsigned)
1363
+ return this;
1364
+ return fromBits(this.low, this.high, true);
1365
+ };
1366
+ /**
1367
+ * Converts this Long to its byte representation.
1368
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
1369
+ * @this {!Long}
1370
+ * @returns {!Array.<number>} Byte representation
1371
+ */
1372
+ LongPrototype.toBytes = function toBytes(le) {
1373
+ return le ? this.toBytesLE() : this.toBytesBE();
1374
+ };
1375
+ /**
1376
+ * Converts this Long to its little endian byte representation.
1377
+ * @this {!Long}
1378
+ * @returns {!Array.<number>} Little endian byte representation
1379
+ */
1380
+ LongPrototype.toBytesLE = function toBytesLE() {
1381
+ var hi = this.high, lo = this.low;
1382
+ return [
1383
+ lo & 0xff,
1384
+ (lo >>> 8) & 0xff,
1385
+ (lo >>> 16) & 0xff,
1386
+ lo >>> 24,
1387
+ hi & 0xff,
1388
+ (hi >>> 8) & 0xff,
1389
+ (hi >>> 16) & 0xff,
1390
+ hi >>> 24,
1391
+ ];
1392
+ };
1393
+ /**
1394
+ * Converts this Long to its big endian byte representation.
1395
+ * @this {!Long}
1396
+ * @returns {!Array.<number>} Big endian byte representation
1397
+ */
1398
+ LongPrototype.toBytesBE = function toBytesBE() {
1399
+ var hi = this.high, lo = this.low;
1400
+ return [
1401
+ hi >>> 24,
1402
+ (hi >>> 16) & 0xff,
1403
+ (hi >>> 8) & 0xff,
1404
+ hi & 0xff,
1405
+ lo >>> 24,
1406
+ (lo >>> 16) & 0xff,
1407
+ (lo >>> 8) & 0xff,
1408
+ lo & 0xff,
1409
+ ];
1410
+ };
1411
+ /**
1412
+ * Creates a Long from its byte representation.
1413
+ * @param {!Array.<number>} bytes Byte representation
1414
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1415
+ * @param {boolean=} le Whether little or big endian, defaults to big endian
1416
+ * @returns {Long} The corresponding Long value
1417
+ */
1418
+ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
1419
+ return le
1420
+ ? Long.fromBytesLE(bytes, unsigned)
1421
+ : Long.fromBytesBE(bytes, unsigned);
1422
+ };
1423
+ /**
1424
+ * Creates a Long from its little endian byte representation.
1425
+ * @param {!Array.<number>} bytes Little endian byte representation
1426
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1427
+ * @returns {Long} The corresponding Long value
1428
+ */
1429
+ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
1430
+ return new Long(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24), bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24), unsigned);
1431
+ };
1432
+ /**
1433
+ * Creates a Long from its big endian byte representation.
1434
+ * @param {!Array.<number>} bytes Big endian byte representation
1435
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1436
+ * @returns {Long} The corresponding Long value
1437
+ */
1438
+ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
1439
+ return new Long((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7], (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3], unsigned);
1440
+ };
1441
+ // Support conversion to/from BigInt where available
1442
+ if (typeof BigInt === "function") {
1443
+ /**
1444
+ * Returns a Long representing the given big integer.
1445
+ * @function
1446
+ * @param {number} value The big integer value
1447
+ * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
1448
+ * @returns {!Long} The corresponding Long value
1449
+ */
1450
+ Long.fromBigInt = function fromBigInt(value, unsigned) {
1451
+ var lowBits = Number(BigInt.asIntN(32, value));
1452
+ var highBits = Number(BigInt.asIntN(32, value >> BigInt(32)));
1453
+ return fromBits(lowBits, highBits, unsigned);
1454
+ };
1455
+ // Override
1456
+ Long.fromValue = function fromValueWithBigInt(value, unsigned) {
1457
+ if (typeof value === "bigint")
1458
+ return Long.fromBigInt(value, unsigned);
1459
+ return fromValue(value, unsigned);
1460
+ };
1461
+ /**
1462
+ * Converts the Long to its big integer representation.
1463
+ * @this {!Long}
1464
+ * @returns {bigint}
1465
+ */
1466
+ LongPrototype.toBigInt = function toBigInt() {
1467
+ var lowBigInt = BigInt(this.low >>> 0);
1468
+ var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high);
1469
+ return (highBigInt << BigInt(32)) | lowBigInt;
1470
+ };
1471
+ }
1472
+ var _default = (_exports.default = Long);
1473
+ });