aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHashEngineering <hashengineeringsolutions@gmail.com>2019-08-29 19:55:56 -0700
committerHashEngineering <hashengineeringsolutions@gmail.com>2019-09-13 06:27:59 -0700
commit76120cb0b42530e3a40476272c1edbeac679db35 (patch)
tree11d636d9e8f8708dd5532e449d1e3dec71bd13ea /src
parent5b689bd6e77f047eff37e43f0ffa487cb59edc45 (diff)
downloadBIP39-76120cb0b42530e3a40476272c1edbeac679db35.tar.gz
BIP39-76120cb0b42530e3a40476272c1edbeac679db35.tar.zst
BIP39-76120cb0b42530e3a40476272c1edbeac679db35.zip
Add Groestlcoin
Diffstat (limited to 'src')
-rw-r--r--src/index.html2
-rw-r--r--src/js/bitcoinjs-extensions.js22
-rw-r--r--src/js/groestlcoinjs-3.3.2.js17951
-rw-r--r--src/js/groestlcoinjs-bip38-2.0.2.js28732
-rw-r--r--src/js/index.js135
-rw-r--r--src/js/segwit-parameters.js53
6 files changed, 46892 insertions, 3 deletions
diff --git a/src/index.html b/src/index.html
index 7dd3e9e..95fccc1 100644
--- a/src/index.html
+++ b/src/index.html
@@ -945,5 +945,7 @@
945 <script src="js/entropy.js"></script> 945 <script src="js/entropy.js"></script>
946 <script src="js/stellar-util.js"></script> 946 <script src="js/stellar-util.js"></script>
947 <script src="js/index.js"></script> 947 <script src="js/index.js"></script>
948 <script src="js/groestlcoinjs-3.3.2.js"></script>
949 <script src="js/groestlcoinjs-bip38-2.0.2.js"></script>
948 </body> 950 </body>
949</html> 951</html>
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js
index ac9f315..a9db485 100644
--- a/src/js/bitcoinjs-extensions.js
+++ b/src/js/bitcoinjs-extensions.js
@@ -801,6 +801,28 @@ bitcoinjs.bitcoin.networks.gridcoin = {
801 wif: 0xbe, 801 wif: 0xbe,
802}; 802};
803 803
804bitcoinjs.bitcoin.networks.groestlcoin = {
805 messagePrefix: '\x19GroestlCoin Signed Message:\n',
806 bip32: {
807 public: 0x0488b21e,
808 private: 0x0488ade4
809 },
810 pubKeyHash: 36,
811 scriptHash: 5,
812 wif: 128,
813}
814
815bitcoinjs.bitcoin.networks.groestlcointestnet = {
816 messagePrefix: '\x19GroestlCoin Signed Message:\n',
817 bip32: {
818 public: 0x043587cf,
819 private: 0x04358394
820 },
821 pubKeyHash: 0x6f,
822 scriptHash: 0xc4,
823 wif: 0xef,
824}
825
804bitcoinjs.bitcoin.networks.gulden = { 826bitcoinjs.bitcoin.networks.gulden = {
805 messagePrefix: '\x18Guldencoin Signed Message:\n', 827 messagePrefix: '\x18Guldencoin Signed Message:\n',
806 bip32: { 828 bip32: {
diff --git a/src/js/groestlcoinjs-3.3.2.js b/src/js/groestlcoinjs-3.3.2.js
new file mode 100644
index 0000000..632b7d5
--- /dev/null
+++ b/src/js/groestlcoinjs-3.3.2.js
@@ -0,0 +1,17951 @@
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.groestlcoinjs = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2'use strict'
3// base-x encoding / decoding
4// Copyright (c) 2018 base-x contributors
5// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
6// Distributed under the MIT software license, see the accompanying
7// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8// @ts-ignore
9var _Buffer = require('safe-buffer').Buffer
10function base (ALPHABET) {
11 if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
12 var BASE_MAP = new Uint8Array(256)
13 BASE_MAP.fill(255)
14 for (var i = 0; i < ALPHABET.length; i++) {
15 var x = ALPHABET.charAt(i)
16 var xc = x.charCodeAt(0)
17 if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
18 BASE_MAP[xc] = i
19 }
20 var BASE = ALPHABET.length
21 var LEADER = ALPHABET.charAt(0)
22 var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
23 var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
24 function encode (source) {
25 if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') }
26 if (source.length === 0) { return '' }
27 // Skip & count leading zeroes.
28 var zeroes = 0
29 var length = 0
30 var pbegin = 0
31 var pend = source.length
32 while (pbegin !== pend && source[pbegin] === 0) {
33 pbegin++
34 zeroes++
35 }
36 // Allocate enough space in big-endian base58 representation.
37 var size = ((pend - pbegin) * iFACTOR + 1) >>> 0
38 var b58 = new Uint8Array(size)
39 // Process the bytes.
40 while (pbegin !== pend) {
41 var carry = source[pbegin]
42 // Apply "b58 = b58 * 256 + ch".
43 var i = 0
44 for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
45 carry += (256 * b58[it1]) >>> 0
46 b58[it1] = (carry % BASE) >>> 0
47 carry = (carry / BASE) >>> 0
48 }
49 if (carry !== 0) { throw new Error('Non-zero carry') }
50 length = i
51 pbegin++
52 }
53 // Skip leading zeroes in base58 result.
54 var it2 = size - length
55 while (it2 !== size && b58[it2] === 0) {
56 it2++
57 }
58 // Translate the result into a string.
59 var str = LEADER.repeat(zeroes)
60 for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) }
61 return str
62 }
63 function decodeUnsafe (source) {
64 if (typeof source !== 'string') { throw new TypeError('Expected String') }
65 if (source.length === 0) { return _Buffer.alloc(0) }
66 var psz = 0
67 // Skip leading spaces.
68 if (source[psz] === ' ') { return }
69 // Skip and count leading '1's.
70 var zeroes = 0
71 var length = 0
72 while (source[psz] === LEADER) {
73 zeroes++
74 psz++
75 }
76 // Allocate enough space in big-endian base256 representation.
77 var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
78 var b256 = new Uint8Array(size)
79 // Process the characters.
80 while (source[psz]) {
81 // Decode character
82 var carry = BASE_MAP[source.charCodeAt(psz)]
83 // Invalid character
84 if (carry === 255) { return }
85 var i = 0
86 for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
87 carry += (BASE * b256[it3]) >>> 0
88 b256[it3] = (carry % 256) >>> 0
89 carry = (carry / 256) >>> 0
90 }
91 if (carry !== 0) { throw new Error('Non-zero carry') }
92 length = i
93 psz++
94 }
95 // Skip trailing spaces.
96 if (source[psz] === ' ') { return }
97 // Skip leading zeroes in b256.
98 var it4 = size - length
99 while (it4 !== size && b256[it4] === 0) {
100 it4++
101 }
102 var vch = _Buffer.allocUnsafe(zeroes + (size - it4))
103 vch.fill(0x00, 0, zeroes)
104 var j = zeroes
105 while (it4 !== size) {
106 vch[j++] = b256[it4++]
107 }
108 return vch
109 }
110 function decode (string) {
111 var buffer = decodeUnsafe(string)
112 if (buffer) { return buffer }
113 throw new Error('Non-base' + BASE + ' character')
114 }
115 return {
116 encode: encode,
117 decodeUnsafe: decodeUnsafe,
118 decode: decode
119 }
120}
121module.exports = base
122
123},{"safe-buffer":38}],2:[function(require,module,exports){
124'use strict'
125var ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
126
127// pre-compute lookup table
128var ALPHABET_MAP = {}
129for (var z = 0; z < ALPHABET.length; z++) {
130 var x = ALPHABET.charAt(z)
131
132 if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous')
133 ALPHABET_MAP[x] = z
134}
135
136function polymodStep (pre) {
137 var b = pre >> 25
138 return ((pre & 0x1FFFFFF) << 5) ^
139 (-((b >> 0) & 1) & 0x3b6a57b2) ^
140 (-((b >> 1) & 1) & 0x26508e6d) ^
141 (-((b >> 2) & 1) & 0x1ea119fa) ^
142 (-((b >> 3) & 1) & 0x3d4233dd) ^
143 (-((b >> 4) & 1) & 0x2a1462b3)
144}
145
146function prefixChk (prefix) {
147 var chk = 1
148 for (var i = 0; i < prefix.length; ++i) {
149 var c = prefix.charCodeAt(i)
150 if (c < 33 || c > 126) throw new Error('Invalid prefix (' + prefix + ')')
151
152 chk = polymodStep(chk) ^ (c >> 5)
153 }
154 chk = polymodStep(chk)
155
156 for (i = 0; i < prefix.length; ++i) {
157 var v = prefix.charCodeAt(i)
158 chk = polymodStep(chk) ^ (v & 0x1f)
159 }
160 return chk
161}
162
163function encode (prefix, words, LIMIT) {
164 LIMIT = LIMIT || 90
165 if ((prefix.length + 7 + words.length) > LIMIT) throw new TypeError('Exceeds length limit')
166
167 prefix = prefix.toLowerCase()
168
169 // determine chk mod
170 var chk = prefixChk(prefix)
171 var result = prefix + '1'
172 for (var i = 0; i < words.length; ++i) {
173 var x = words[i]
174 if ((x >> 5) !== 0) throw new Error('Non 5-bit word')
175
176 chk = polymodStep(chk) ^ x
177 result += ALPHABET.charAt(x)
178 }
179
180 for (i = 0; i < 6; ++i) {
181 chk = polymodStep(chk)
182 }
183 chk ^= 1
184
185 for (i = 0; i < 6; ++i) {
186 var v = (chk >> ((5 - i) * 5)) & 0x1f
187 result += ALPHABET.charAt(v)
188 }
189
190 return result
191}
192
193function decode (str, LIMIT) {
194 LIMIT = LIMIT || 90
195 if (str.length < 8) throw new TypeError(str + ' too short')
196 if (str.length > LIMIT) throw new TypeError('Exceeds length limit')
197
198 // don't allow mixed case
199 var lowered = str.toLowerCase()
200 var uppered = str.toUpperCase()
201 if (str !== lowered && str !== uppered) throw new Error('Mixed-case string ' + str)
202 str = lowered
203
204 var split = str.lastIndexOf('1')
205 if (split === -1) throw new Error('No separator character for ' + str)
206 if (split === 0) throw new Error('Missing prefix for ' + str)
207
208 var prefix = str.slice(0, split)
209 var wordChars = str.slice(split + 1)
210 if (wordChars.length < 6) throw new Error('Data too short')
211
212 var chk = prefixChk(prefix)
213 var words = []
214 for (var i = 0; i < wordChars.length; ++i) {
215 var c = wordChars.charAt(i)
216 var v = ALPHABET_MAP[c]
217 if (v === undefined) throw new Error('Unknown character ' + c)
218 chk = polymodStep(chk) ^ v
219
220 // not in the checksum?
221 if (i + 6 >= wordChars.length) continue
222 words.push(v)
223 }
224
225 if (chk !== 1) throw new Error('Invalid checksum for ' + str)
226 return { prefix: prefix, words: words }
227}
228
229function convert (data, inBits, outBits, pad) {
230 var value = 0
231 var bits = 0
232 var maxV = (1 << outBits) - 1
233
234 var result = []
235 for (var i = 0; i < data.length; ++i) {
236 value = (value << inBits) | data[i]
237 bits += inBits
238
239 while (bits >= outBits) {
240 bits -= outBits
241 result.push((value >> bits) & maxV)
242 }
243 }
244
245 if (pad) {
246 if (bits > 0) {
247 result.push((value << (outBits - bits)) & maxV)
248 }
249 } else {
250 if (bits >= inBits) throw new Error('Excess padding')
251 if ((value << (outBits - bits)) & maxV) throw new Error('Non-zero padding')
252 }
253
254 return result
255}
256
257function toWords (bytes) {
258 return convert(bytes, 8, 5, true)
259}
260
261function fromWords (words) {
262 return convert(words, 5, 8, false)
263}
264
265module.exports = {
266 decode: decode,
267 encode: encode,
268 toWords: toWords,
269 fromWords: fromWords
270}
271
272},{}],3:[function(require,module,exports){
273// (public) Constructor
274function BigInteger(a, b, c) {
275 if (!(this instanceof BigInteger))
276 return new BigInteger(a, b, c)
277
278 if (a != null) {
279 if ("number" == typeof a) this.fromNumber(a, b, c)
280 else if (b == null && "string" != typeof a) this.fromString(a, 256)
281 else this.fromString(a, b)
282 }
283}
284
285var proto = BigInteger.prototype
286
287// duck-typed isBigInteger
288proto.__bigi = require('../package.json').version
289BigInteger.isBigInteger = function (obj, check_ver) {
290 return obj && obj.__bigi && (!check_ver || obj.__bigi === proto.__bigi)
291}
292
293// Bits per digit
294var dbits
295
296// am: Compute w_j += (x*this_i), propagate carries,
297// c is initial carry, returns final carry.
298// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
299// We need to select the fastest one that works in this environment.
300
301// am1: use a single mult and divide to get the high bits,
302// max digit bits should be 26 because
303// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
304function am1(i, x, w, j, c, n) {
305 while (--n >= 0) {
306 var v = x * this[i++] + w[j] + c
307 c = Math.floor(v / 0x4000000)
308 w[j++] = v & 0x3ffffff
309 }
310 return c
311}
312// am2 avoids a big mult-and-extract completely.
313// Max digit bits should be <= 30 because we do bitwise ops
314// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
315function am2(i, x, w, j, c, n) {
316 var xl = x & 0x7fff,
317 xh = x >> 15
318 while (--n >= 0) {
319 var l = this[i] & 0x7fff
320 var h = this[i++] >> 15
321 var m = xh * l + h * xl
322 l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff)
323 c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30)
324 w[j++] = l & 0x3fffffff
325 }
326 return c
327}
328// Alternately, set max digit bits to 28 since some
329// browsers slow down when dealing with 32-bit numbers.
330function am3(i, x, w, j, c, n) {
331 var xl = x & 0x3fff,
332 xh = x >> 14
333 while (--n >= 0) {
334 var l = this[i] & 0x3fff
335 var h = this[i++] >> 14
336 var m = xh * l + h * xl
337 l = xl * l + ((m & 0x3fff) << 14) + w[j] + c
338 c = (l >> 28) + (m >> 14) + xh * h
339 w[j++] = l & 0xfffffff
340 }
341 return c
342}
343
344// wtf?
345BigInteger.prototype.am = am1
346dbits = 26
347
348BigInteger.prototype.DB = dbits
349BigInteger.prototype.DM = ((1 << dbits) - 1)
350var DV = BigInteger.prototype.DV = (1 << dbits)
351
352var BI_FP = 52
353BigInteger.prototype.FV = Math.pow(2, BI_FP)
354BigInteger.prototype.F1 = BI_FP - dbits
355BigInteger.prototype.F2 = 2 * dbits - BI_FP
356
357// Digit conversions
358var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"
359var BI_RC = new Array()
360var rr, vv
361rr = "0".charCodeAt(0)
362for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv
363rr = "a".charCodeAt(0)
364for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv
365rr = "A".charCodeAt(0)
366for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv
367
368function int2char(n) {
369 return BI_RM.charAt(n)
370}
371
372function intAt(s, i) {
373 var c = BI_RC[s.charCodeAt(i)]
374 return (c == null) ? -1 : c
375}
376
377// (protected) copy this to r
378function bnpCopyTo(r) {
379 for (var i = this.t - 1; i >= 0; --i) r[i] = this[i]
380 r.t = this.t
381 r.s = this.s
382}
383
384// (protected) set from integer value x, -DV <= x < DV
385function bnpFromInt(x) {
386 this.t = 1
387 this.s = (x < 0) ? -1 : 0
388 if (x > 0) this[0] = x
389 else if (x < -1) this[0] = x + DV
390 else this.t = 0
391}
392
393// return bigint initialized to value
394function nbv(i) {
395 var r = new BigInteger()
396 r.fromInt(i)
397 return r
398}
399
400// (protected) set from string and radix
401function bnpFromString(s, b) {
402 var self = this
403
404 var k
405 if (b == 16) k = 4
406 else if (b == 8) k = 3
407 else if (b == 256) k = 8; // byte array
408 else if (b == 2) k = 1
409 else if (b == 32) k = 5
410 else if (b == 4) k = 2
411 else {
412 self.fromRadix(s, b)
413 return
414 }
415 self.t = 0
416 self.s = 0
417 var i = s.length,
418 mi = false,
419 sh = 0
420 while (--i >= 0) {
421 var x = (k == 8) ? s[i] & 0xff : intAt(s, i)
422 if (x < 0) {
423 if (s.charAt(i) == "-") mi = true
424 continue
425 }
426 mi = false
427 if (sh == 0)
428 self[self.t++] = x
429 else if (sh + k > self.DB) {
430 self[self.t - 1] |= (x & ((1 << (self.DB - sh)) - 1)) << sh
431 self[self.t++] = (x >> (self.DB - sh))
432 } else
433 self[self.t - 1] |= x << sh
434 sh += k
435 if (sh >= self.DB) sh -= self.DB
436 }
437 if (k == 8 && (s[0] & 0x80) != 0) {
438 self.s = -1
439 if (sh > 0) self[self.t - 1] |= ((1 << (self.DB - sh)) - 1) << sh
440 }
441 self.clamp()
442 if (mi) BigInteger.ZERO.subTo(self, self)
443}
444
445// (protected) clamp off excess high words
446function bnpClamp() {
447 var c = this.s & this.DM
448 while (this.t > 0 && this[this.t - 1] == c)--this.t
449}
450
451// (public) return string representation in given radix
452function bnToString(b) {
453 var self = this
454 if (self.s < 0) return "-" + self.negate()
455 .toString(b)
456 var k
457 if (b == 16) k = 4
458 else if (b == 8) k = 3
459 else if (b == 2) k = 1
460 else if (b == 32) k = 5
461 else if (b == 4) k = 2
462 else return self.toRadix(b)
463 var km = (1 << k) - 1,
464 d, m = false,
465 r = "",
466 i = self.t
467 var p = self.DB - (i * self.DB) % k
468 if (i-- > 0) {
469 if (p < self.DB && (d = self[i] >> p) > 0) {
470 m = true
471 r = int2char(d)
472 }
473 while (i >= 0) {
474 if (p < k) {
475 d = (self[i] & ((1 << p) - 1)) << (k - p)
476 d |= self[--i] >> (p += self.DB - k)
477 } else {
478 d = (self[i] >> (p -= k)) & km
479 if (p <= 0) {
480 p += self.DB
481 --i
482 }
483 }
484 if (d > 0) m = true
485 if (m) r += int2char(d)
486 }
487 }
488 return m ? r : "0"
489}
490
491// (public) -this
492function bnNegate() {
493 var r = new BigInteger()
494 BigInteger.ZERO.subTo(this, r)
495 return r
496}
497
498// (public) |this|
499function bnAbs() {
500 return (this.s < 0) ? this.negate() : this
501}
502
503// (public) return + if this > a, - if this < a, 0 if equal
504function bnCompareTo(a) {
505 var r = this.s - a.s
506 if (r != 0) return r
507 var i = this.t
508 r = i - a.t
509 if (r != 0) return (this.s < 0) ? -r : r
510 while (--i >= 0)
511 if ((r = this[i] - a[i]) != 0) return r
512 return 0
513}
514
515// returns bit length of the integer x
516function nbits(x) {
517 var r = 1,
518 t
519 if ((t = x >>> 16) != 0) {
520 x = t
521 r += 16
522 }
523 if ((t = x >> 8) != 0) {
524 x = t
525 r += 8
526 }
527 if ((t = x >> 4) != 0) {
528 x = t
529 r += 4
530 }
531 if ((t = x >> 2) != 0) {
532 x = t
533 r += 2
534 }
535 if ((t = x >> 1) != 0) {
536 x = t
537 r += 1
538 }
539 return r
540}
541
542// (public) return the number of bits in "this"
543function bnBitLength() {
544 if (this.t <= 0) return 0
545 return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM))
546}
547
548// (public) return the number of bytes in "this"
549function bnByteLength() {
550 return this.bitLength() >> 3
551}
552
553// (protected) r = this << n*DB
554function bnpDLShiftTo(n, r) {
555 var i
556 for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i]
557 for (i = n - 1; i >= 0; --i) r[i] = 0
558 r.t = this.t + n
559 r.s = this.s
560}
561
562// (protected) r = this >> n*DB
563function bnpDRShiftTo(n, r) {
564 for (var i = n; i < this.t; ++i) r[i - n] = this[i]
565 r.t = Math.max(this.t - n, 0)
566 r.s = this.s
567}
568
569// (protected) r = this << n
570function bnpLShiftTo(n, r) {
571 var self = this
572 var bs = n % self.DB
573 var cbs = self.DB - bs
574 var bm = (1 << cbs) - 1
575 var ds = Math.floor(n / self.DB),
576 c = (self.s << bs) & self.DM,
577 i
578 for (i = self.t - 1; i >= 0; --i) {
579 r[i + ds + 1] = (self[i] >> cbs) | c
580 c = (self[i] & bm) << bs
581 }
582 for (i = ds - 1; i >= 0; --i) r[i] = 0
583 r[ds] = c
584 r.t = self.t + ds + 1
585 r.s = self.s
586 r.clamp()
587}
588
589// (protected) r = this >> n
590function bnpRShiftTo(n, r) {
591 var self = this
592 r.s = self.s
593 var ds = Math.floor(n / self.DB)
594 if (ds >= self.t) {
595 r.t = 0
596 return
597 }
598 var bs = n % self.DB
599 var cbs = self.DB - bs
600 var bm = (1 << bs) - 1
601 r[0] = self[ds] >> bs
602 for (var i = ds + 1; i < self.t; ++i) {
603 r[i - ds - 1] |= (self[i] & bm) << cbs
604 r[i - ds] = self[i] >> bs
605 }
606 if (bs > 0) r[self.t - ds - 1] |= (self.s & bm) << cbs
607 r.t = self.t - ds
608 r.clamp()
609}
610
611// (protected) r = this - a
612function bnpSubTo(a, r) {
613 var self = this
614 var i = 0,
615 c = 0,
616 m = Math.min(a.t, self.t)
617 while (i < m) {
618 c += self[i] - a[i]
619 r[i++] = c & self.DM
620 c >>= self.DB
621 }
622 if (a.t < self.t) {
623 c -= a.s
624 while (i < self.t) {
625 c += self[i]
626 r[i++] = c & self.DM
627 c >>= self.DB
628 }
629 c += self.s
630 } else {
631 c += self.s
632 while (i < a.t) {
633 c -= a[i]
634 r[i++] = c & self.DM
635 c >>= self.DB
636 }
637 c -= a.s
638 }
639 r.s = (c < 0) ? -1 : 0
640 if (c < -1) r[i++] = self.DV + c
641 else if (c > 0) r[i++] = c
642 r.t = i
643 r.clamp()
644}
645
646// (protected) r = this * a, r != this,a (HAC 14.12)
647// "this" should be the larger one if appropriate.
648function bnpMultiplyTo(a, r) {
649 var x = this.abs(),
650 y = a.abs()
651 var i = x.t
652 r.t = i + y.t
653 while (--i >= 0) r[i] = 0
654 for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t)
655 r.s = 0
656 r.clamp()
657 if (this.s != a.s) BigInteger.ZERO.subTo(r, r)
658}
659
660// (protected) r = this^2, r != this (HAC 14.16)
661function bnpSquareTo(r) {
662 var x = this.abs()
663 var i = r.t = 2 * x.t
664 while (--i >= 0) r[i] = 0
665 for (i = 0; i < x.t - 1; ++i) {
666 var c = x.am(i, x[i], r, 2 * i, 0, 1)
667 if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
668 r[i + x.t] -= x.DV
669 r[i + x.t + 1] = 1
670 }
671 }
672 if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1)
673 r.s = 0
674 r.clamp()
675}
676
677// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
678// r != q, this != m. q or r may be null.
679function bnpDivRemTo(m, q, r) {
680 var self = this
681 var pm = m.abs()
682 if (pm.t <= 0) return
683 var pt = self.abs()
684 if (pt.t < pm.t) {
685 if (q != null) q.fromInt(0)
686 if (r != null) self.copyTo(r)
687 return
688 }
689 if (r == null) r = new BigInteger()
690 var y = new BigInteger(),
691 ts = self.s,
692 ms = m.s
693 var nsh = self.DB - nbits(pm[pm.t - 1]); // normalize modulus
694 if (nsh > 0) {
695 pm.lShiftTo(nsh, y)
696 pt.lShiftTo(nsh, r)
697 } else {
698 pm.copyTo(y)
699 pt.copyTo(r)
700 }
701 var ys = y.t
702 var y0 = y[ys - 1]
703 if (y0 == 0) return
704 var yt = y0 * (1 << self.F1) + ((ys > 1) ? y[ys - 2] >> self.F2 : 0)
705 var d1 = self.FV / yt,
706 d2 = (1 << self.F1) / yt,
707 e = 1 << self.F2
708 var i = r.t,
709 j = i - ys,
710 t = (q == null) ? new BigInteger() : q
711 y.dlShiftTo(j, t)
712 if (r.compareTo(t) >= 0) {
713 r[r.t++] = 1
714 r.subTo(t, r)
715 }
716 BigInteger.ONE.dlShiftTo(ys, t)
717 t.subTo(y, y); // "negative" y so we can replace sub with am later
718 while (y.t < ys) y[y.t++] = 0
719 while (--j >= 0) {
720 // Estimate quotient digit
721 var qd = (r[--i] == y0) ? self.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2)
722 if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
723 y.dlShiftTo(j, t)
724 r.subTo(t, r)
725 while (r[i] < --qd) r.subTo(t, r)
726 }
727 }
728 if (q != null) {
729 r.drShiftTo(ys, q)
730 if (ts != ms) BigInteger.ZERO.subTo(q, q)
731 }
732 r.t = ys
733 r.clamp()
734 if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
735 if (ts < 0) BigInteger.ZERO.subTo(r, r)
736}
737
738// (public) this mod a
739function bnMod(a) {
740 var r = new BigInteger()
741 this.abs()
742 .divRemTo(a, null, r)
743 if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r)
744 return r
745}
746
747// Modular reduction using "classic" algorithm
748function Classic(m) {
749 this.m = m
750}
751
752function cConvert(x) {
753 if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m)
754 else return x
755}
756
757function cRevert(x) {
758 return x
759}
760
761function cReduce(x) {
762 x.divRemTo(this.m, null, x)
763}
764
765function cMulTo(x, y, r) {
766 x.multiplyTo(y, r)
767 this.reduce(r)
768}
769
770function cSqrTo(x, r) {
771 x.squareTo(r)
772 this.reduce(r)
773}
774
775Classic.prototype.convert = cConvert
776Classic.prototype.revert = cRevert
777Classic.prototype.reduce = cReduce
778Classic.prototype.mulTo = cMulTo
779Classic.prototype.sqrTo = cSqrTo
780
781// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
782// justification:
783// xy == 1 (mod m)
784// xy = 1+km
785// xy(2-xy) = (1+km)(1-km)
786// x[y(2-xy)] = 1-k^2m^2
787// x[y(2-xy)] == 1 (mod m^2)
788// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
789// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
790// JS multiply "overflows" differently from C/C++, so care is needed here.
791function bnpInvDigit() {
792 if (this.t < 1) return 0
793 var x = this[0]
794 if ((x & 1) == 0) return 0
795 var y = x & 3; // y == 1/x mod 2^2
796 y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
797 y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
798 y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
799 // last step - calculate inverse mod DV directly
800 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
801 y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
802 // we really want the negative inverse, and -DV < y < DV
803 return (y > 0) ? this.DV - y : -y
804}
805
806// Montgomery reduction
807function Montgomery(m) {
808 this.m = m
809 this.mp = m.invDigit()
810 this.mpl = this.mp & 0x7fff
811 this.mph = this.mp >> 15
812 this.um = (1 << (m.DB - 15)) - 1
813 this.mt2 = 2 * m.t
814}
815
816// xR mod m
817function montConvert(x) {
818 var r = new BigInteger()
819 x.abs()
820 .dlShiftTo(this.m.t, r)
821 r.divRemTo(this.m, null, r)
822 if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r)
823 return r
824}
825
826// x/R mod m
827function montRevert(x) {
828 var r = new BigInteger()
829 x.copyTo(r)
830 this.reduce(r)
831 return r
832}
833
834// x = x/R mod m (HAC 14.32)
835function montReduce(x) {
836 while (x.t <= this.mt2) // pad x so am has enough room later
837 x[x.t++] = 0
838 for (var i = 0; i < this.m.t; ++i) {
839 // faster way of calculating u0 = x[i]*mp mod DV
840 var j = x[i] & 0x7fff
841 var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM
842 // use am to combine the multiply-shift-add into one call
843 j = i + this.m.t
844 x[j] += this.m.am(0, u0, x, i, 0, this.m.t)
845 // propagate carry
846 while (x[j] >= x.DV) {
847 x[j] -= x.DV
848 x[++j]++
849 }
850 }
851 x.clamp()
852 x.drShiftTo(this.m.t, x)
853 if (x.compareTo(this.m) >= 0) x.subTo(this.m, x)
854}
855
856// r = "x^2/R mod m"; x != r
857function montSqrTo(x, r) {
858 x.squareTo(r)
859 this.reduce(r)
860}
861
862// r = "xy/R mod m"; x,y != r
863function montMulTo(x, y, r) {
864 x.multiplyTo(y, r)
865 this.reduce(r)
866}
867
868Montgomery.prototype.convert = montConvert
869Montgomery.prototype.revert = montRevert
870Montgomery.prototype.reduce = montReduce
871Montgomery.prototype.mulTo = montMulTo
872Montgomery.prototype.sqrTo = montSqrTo
873
874// (protected) true iff this is even
875function bnpIsEven() {
876 return ((this.t > 0) ? (this[0] & 1) : this.s) == 0
877}
878
879// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
880function bnpExp(e, z) {
881 if (e > 0xffffffff || e < 1) return BigInteger.ONE
882 var r = new BigInteger(),
883 r2 = new BigInteger(),
884 g = z.convert(this),
885 i = nbits(e) - 1
886 g.copyTo(r)
887 while (--i >= 0) {
888 z.sqrTo(r, r2)
889 if ((e & (1 << i)) > 0) z.mulTo(r2, g, r)
890 else {
891 var t = r
892 r = r2
893 r2 = t
894 }
895 }
896 return z.revert(r)
897}
898
899// (public) this^e % m, 0 <= e < 2^32
900function bnModPowInt(e, m) {
901 var z
902 if (e < 256 || m.isEven()) z = new Classic(m)
903 else z = new Montgomery(m)
904 return this.exp(e, z)
905}
906
907// protected
908proto.copyTo = bnpCopyTo
909proto.fromInt = bnpFromInt
910proto.fromString = bnpFromString
911proto.clamp = bnpClamp
912proto.dlShiftTo = bnpDLShiftTo
913proto.drShiftTo = bnpDRShiftTo
914proto.lShiftTo = bnpLShiftTo
915proto.rShiftTo = bnpRShiftTo
916proto.subTo = bnpSubTo
917proto.multiplyTo = bnpMultiplyTo
918proto.squareTo = bnpSquareTo
919proto.divRemTo = bnpDivRemTo
920proto.invDigit = bnpInvDigit
921proto.isEven = bnpIsEven
922proto.exp = bnpExp
923
924// public
925proto.toString = bnToString
926proto.negate = bnNegate
927proto.abs = bnAbs
928proto.compareTo = bnCompareTo
929proto.bitLength = bnBitLength
930proto.byteLength = bnByteLength
931proto.mod = bnMod
932proto.modPowInt = bnModPowInt
933
934// (public)
935function bnClone() {
936 var r = new BigInteger()
937 this.copyTo(r)
938 return r
939}
940
941// (public) return value as integer
942function bnIntValue() {
943 if (this.s < 0) {
944 if (this.t == 1) return this[0] - this.DV
945 else if (this.t == 0) return -1
946 } else if (this.t == 1) return this[0]
947 else if (this.t == 0) return 0
948 // assumes 16 < DB < 32
949 return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]
950}
951
952// (public) return value as byte
953function bnByteValue() {
954 return (this.t == 0) ? this.s : (this[0] << 24) >> 24
955}
956
957// (public) return value as short (assumes DB>=16)
958function bnShortValue() {
959 return (this.t == 0) ? this.s : (this[0] << 16) >> 16
960}
961
962// (protected) return x s.t. r^x < DV
963function bnpChunkSize(r) {
964 return Math.floor(Math.LN2 * this.DB / Math.log(r))
965}
966
967// (public) 0 if this == 0, 1 if this > 0
968function bnSigNum() {
969 if (this.s < 0) return -1
970 else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0
971 else return 1
972}
973
974// (protected) convert to radix string
975function bnpToRadix(b) {
976 if (b == null) b = 10
977 if (this.signum() == 0 || b < 2 || b > 36) return "0"
978 var cs = this.chunkSize(b)
979 var a = Math.pow(b, cs)
980 var d = nbv(a),
981 y = new BigInteger(),
982 z = new BigInteger(),
983 r = ""
984 this.divRemTo(d, y, z)
985 while (y.signum() > 0) {
986 r = (a + z.intValue())
987 .toString(b)
988 .substr(1) + r
989 y.divRemTo(d, y, z)
990 }
991 return z.intValue()
992 .toString(b) + r
993}
994
995// (protected) convert from radix string
996function bnpFromRadix(s, b) {
997 var self = this
998 self.fromInt(0)
999 if (b == null) b = 10
1000 var cs = self.chunkSize(b)
1001 var d = Math.pow(b, cs),
1002 mi = false,
1003 j = 0,
1004 w = 0
1005 for (var i = 0; i < s.length; ++i) {
1006 var x = intAt(s, i)
1007 if (x < 0) {
1008 if (s.charAt(i) == "-" && self.signum() == 0) mi = true
1009 continue
1010 }
1011 w = b * w + x
1012 if (++j >= cs) {
1013 self.dMultiply(d)
1014 self.dAddOffset(w, 0)
1015 j = 0
1016 w = 0
1017 }
1018 }
1019 if (j > 0) {
1020 self.dMultiply(Math.pow(b, j))
1021 self.dAddOffset(w, 0)
1022 }
1023 if (mi) BigInteger.ZERO.subTo(self, self)
1024}
1025
1026// (protected) alternate constructor
1027function bnpFromNumber(a, b, c) {
1028 var self = this
1029 if ("number" == typeof b) {
1030 // new BigInteger(int,int,RNG)
1031 if (a < 2) self.fromInt(1)
1032 else {
1033 self.fromNumber(a, c)
1034 if (!self.testBit(a - 1)) // force MSB set
1035 self.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, self)
1036 if (self.isEven()) self.dAddOffset(1, 0); // force odd
1037 while (!self.isProbablePrime(b)) {
1038 self.dAddOffset(2, 0)
1039 if (self.bitLength() > a) self.subTo(BigInteger.ONE.shiftLeft(a - 1), self)
1040 }
1041 }
1042 } else {
1043 // new BigInteger(int,RNG)
1044 var x = new Array(),
1045 t = a & 7
1046 x.length = (a >> 3) + 1
1047 b.nextBytes(x)
1048 if (t > 0) x[0] &= ((1 << t) - 1)
1049 else x[0] = 0
1050 self.fromString(x, 256)
1051 }
1052}
1053
1054// (public) convert to bigendian byte array
1055function bnToByteArray() {
1056 var self = this
1057 var i = self.t,
1058 r = new Array()
1059 r[0] = self.s
1060 var p = self.DB - (i * self.DB) % 8,
1061 d, k = 0
1062 if (i-- > 0) {
1063 if (p < self.DB && (d = self[i] >> p) != (self.s & self.DM) >> p)
1064 r[k++] = d | (self.s << (self.DB - p))
1065 while (i >= 0) {
1066 if (p < 8) {
1067 d = (self[i] & ((1 << p) - 1)) << (8 - p)
1068 d |= self[--i] >> (p += self.DB - 8)
1069 } else {
1070 d = (self[i] >> (p -= 8)) & 0xff
1071 if (p <= 0) {
1072 p += self.DB
1073 --i
1074 }
1075 }
1076 if ((d & 0x80) != 0) d |= -256
1077 if (k === 0 && (self.s & 0x80) != (d & 0x80))++k
1078 if (k > 0 || d != self.s) r[k++] = d
1079 }
1080 }
1081 return r
1082}
1083
1084function bnEquals(a) {
1085 return (this.compareTo(a) == 0)
1086}
1087
1088function bnMin(a) {
1089 return (this.compareTo(a) < 0) ? this : a
1090}
1091
1092function bnMax(a) {
1093 return (this.compareTo(a) > 0) ? this : a
1094}
1095
1096// (protected) r = this op a (bitwise)
1097function bnpBitwiseTo(a, op, r) {
1098 var self = this
1099 var i, f, m = Math.min(a.t, self.t)
1100 for (i = 0; i < m; ++i) r[i] = op(self[i], a[i])
1101 if (a.t < self.t) {
1102 f = a.s & self.DM
1103 for (i = m; i < self.t; ++i) r[i] = op(self[i], f)
1104 r.t = self.t
1105 } else {
1106 f = self.s & self.DM
1107 for (i = m; i < a.t; ++i) r[i] = op(f, a[i])
1108 r.t = a.t
1109 }
1110 r.s = op(self.s, a.s)
1111 r.clamp()
1112}
1113
1114// (public) this & a
1115function op_and(x, y) {
1116 return x & y
1117}
1118
1119function bnAnd(a) {
1120 var r = new BigInteger()
1121 this.bitwiseTo(a, op_and, r)
1122 return r
1123}
1124
1125// (public) this | a
1126function op_or(x, y) {
1127 return x | y
1128}
1129
1130function bnOr(a) {
1131 var r = new BigInteger()
1132 this.bitwiseTo(a, op_or, r)
1133 return r
1134}
1135
1136// (public) this ^ a
1137function op_xor(x, y) {
1138 return x ^ y
1139}
1140
1141function bnXor(a) {
1142 var r = new BigInteger()
1143 this.bitwiseTo(a, op_xor, r)
1144 return r
1145}
1146
1147// (public) this & ~a
1148function op_andnot(x, y) {
1149 return x & ~y
1150}
1151
1152function bnAndNot(a) {
1153 var r = new BigInteger()
1154 this.bitwiseTo(a, op_andnot, r)
1155 return r
1156}
1157
1158// (public) ~this
1159function bnNot() {
1160 var r = new BigInteger()
1161 for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i]
1162 r.t = this.t
1163 r.s = ~this.s
1164 return r
1165}
1166
1167// (public) this << n
1168function bnShiftLeft(n) {
1169 var r = new BigInteger()
1170 if (n < 0) this.rShiftTo(-n, r)
1171 else this.lShiftTo(n, r)
1172 return r
1173}
1174
1175// (public) this >> n
1176function bnShiftRight(n) {
1177 var r = new BigInteger()
1178 if (n < 0) this.lShiftTo(-n, r)
1179 else this.rShiftTo(n, r)
1180 return r
1181}
1182
1183// return index of lowest 1-bit in x, x < 2^31
1184function lbit(x) {
1185 if (x == 0) return -1
1186 var r = 0
1187 if ((x & 0xffff) == 0) {
1188 x >>= 16
1189 r += 16
1190 }
1191 if ((x & 0xff) == 0) {
1192 x >>= 8
1193 r += 8
1194 }
1195 if ((x & 0xf) == 0) {
1196 x >>= 4
1197 r += 4
1198 }
1199 if ((x & 3) == 0) {
1200 x >>= 2
1201 r += 2
1202 }
1203 if ((x & 1) == 0)++r
1204 return r
1205}
1206
1207// (public) returns index of lowest 1-bit (or -1 if none)
1208function bnGetLowestSetBit() {
1209 for (var i = 0; i < this.t; ++i)
1210 if (this[i] != 0) return i * this.DB + lbit(this[i])
1211 if (this.s < 0) return this.t * this.DB
1212 return -1
1213}
1214
1215// return number of 1 bits in x
1216function cbit(x) {
1217 var r = 0
1218 while (x != 0) {
1219 x &= x - 1
1220 ++r
1221 }
1222 return r
1223}
1224
1225// (public) return number of set bits
1226function bnBitCount() {
1227 var r = 0,
1228 x = this.s & this.DM
1229 for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x)
1230 return r
1231}
1232
1233// (public) true iff nth bit is set
1234function bnTestBit(n) {
1235 var j = Math.floor(n / this.DB)
1236 if (j >= this.t) return (this.s != 0)
1237 return ((this[j] & (1 << (n % this.DB))) != 0)
1238}
1239
1240// (protected) this op (1<<n)
1241function bnpChangeBit(n, op) {
1242 var r = BigInteger.ONE.shiftLeft(n)
1243 this.bitwiseTo(r, op, r)
1244 return r
1245}
1246
1247// (public) this | (1<<n)
1248function bnSetBit(n) {
1249 return this.changeBit(n, op_or)
1250}
1251
1252// (public) this & ~(1<<n)
1253function bnClearBit(n) {
1254 return this.changeBit(n, op_andnot)
1255}
1256
1257// (public) this ^ (1<<n)
1258function bnFlipBit(n) {
1259 return this.changeBit(n, op_xor)
1260}
1261
1262// (protected) r = this + a
1263function bnpAddTo(a, r) {
1264 var self = this
1265
1266 var i = 0,
1267 c = 0,
1268 m = Math.min(a.t, self.t)
1269 while (i < m) {
1270 c += self[i] + a[i]
1271 r[i++] = c & self.DM
1272 c >>= self.DB
1273 }
1274 if (a.t < self.t) {
1275 c += a.s
1276 while (i < self.t) {
1277 c += self[i]
1278 r[i++] = c & self.DM
1279 c >>= self.DB
1280 }
1281 c += self.s
1282 } else {
1283 c += self.s
1284 while (i < a.t) {
1285 c += a[i]
1286 r[i++] = c & self.DM
1287 c >>= self.DB
1288 }
1289 c += a.s
1290 }
1291 r.s = (c < 0) ? -1 : 0
1292 if (c > 0) r[i++] = c
1293 else if (c < -1) r[i++] = self.DV + c
1294 r.t = i
1295 r.clamp()
1296}
1297
1298// (public) this + a
1299function bnAdd(a) {
1300 var r = new BigInteger()
1301 this.addTo(a, r)
1302 return r
1303}
1304
1305// (public) this - a
1306function bnSubtract(a) {
1307 var r = new BigInteger()
1308 this.subTo(a, r)
1309 return r
1310}
1311
1312// (public) this * a
1313function bnMultiply(a) {
1314 var r = new BigInteger()
1315 this.multiplyTo(a, r)
1316 return r
1317}
1318
1319// (public) this^2
1320function bnSquare() {
1321 var r = new BigInteger()
1322 this.squareTo(r)
1323 return r
1324}
1325
1326// (public) this / a
1327function bnDivide(a) {
1328 var r = new BigInteger()
1329 this.divRemTo(a, r, null)
1330 return r
1331}
1332
1333// (public) this % a
1334function bnRemainder(a) {
1335 var r = new BigInteger()
1336 this.divRemTo(a, null, r)
1337 return r
1338}
1339
1340// (public) [this/a,this%a]
1341function bnDivideAndRemainder(a) {
1342 var q = new BigInteger(),
1343 r = new BigInteger()
1344 this.divRemTo(a, q, r)
1345 return new Array(q, r)
1346}
1347
1348// (protected) this *= n, this >= 0, 1 < n < DV
1349function bnpDMultiply(n) {
1350 this[this.t] = this.am(0, n - 1, this, 0, 0, this.t)
1351 ++this.t
1352 this.clamp()
1353}
1354
1355// (protected) this += n << w words, this >= 0
1356function bnpDAddOffset(n, w) {
1357 if (n == 0) return
1358 while (this.t <= w) this[this.t++] = 0
1359 this[w] += n
1360 while (this[w] >= this.DV) {
1361 this[w] -= this.DV
1362 if (++w >= this.t) this[this.t++] = 0
1363 ++this[w]
1364 }
1365}
1366
1367// A "null" reducer
1368function NullExp() {}
1369
1370function nNop(x) {
1371 return x
1372}
1373
1374function nMulTo(x, y, r) {
1375 x.multiplyTo(y, r)
1376}
1377
1378function nSqrTo(x, r) {
1379 x.squareTo(r)
1380}
1381
1382NullExp.prototype.convert = nNop
1383NullExp.prototype.revert = nNop
1384NullExp.prototype.mulTo = nMulTo
1385NullExp.prototype.sqrTo = nSqrTo
1386
1387// (public) this^e
1388function bnPow(e) {
1389 return this.exp(e, new NullExp())
1390}
1391
1392// (protected) r = lower n words of "this * a", a.t <= n
1393// "this" should be the larger one if appropriate.
1394function bnpMultiplyLowerTo(a, n, r) {
1395 var i = Math.min(this.t + a.t, n)
1396 r.s = 0; // assumes a,this >= 0
1397 r.t = i
1398 while (i > 0) r[--i] = 0
1399 var j
1400 for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t)
1401 for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i)
1402 r.clamp()
1403}
1404
1405// (protected) r = "this * a" without lower n words, n > 0
1406// "this" should be the larger one if appropriate.
1407function bnpMultiplyUpperTo(a, n, r) {
1408 --n
1409 var i = r.t = this.t + a.t - n
1410 r.s = 0; // assumes a,this >= 0
1411 while (--i >= 0) r[i] = 0
1412 for (i = Math.max(n - this.t, 0); i < a.t; ++i)
1413 r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n)
1414 r.clamp()
1415 r.drShiftTo(1, r)
1416}
1417
1418// Barrett modular reduction
1419function Barrett(m) {
1420 // setup Barrett
1421 this.r2 = new BigInteger()
1422 this.q3 = new BigInteger()
1423 BigInteger.ONE.dlShiftTo(2 * m.t, this.r2)
1424 this.mu = this.r2.divide(m)
1425 this.m = m
1426}
1427
1428function barrettConvert(x) {
1429 if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m)
1430 else if (x.compareTo(this.m) < 0) return x
1431 else {
1432 var r = new BigInteger()
1433 x.copyTo(r)
1434 this.reduce(r)
1435 return r
1436 }
1437}
1438
1439function barrettRevert(x) {
1440 return x
1441}
1442
1443// x = x mod m (HAC 14.42)
1444function barrettReduce(x) {
1445 var self = this
1446 x.drShiftTo(self.m.t - 1, self.r2)
1447 if (x.t > self.m.t + 1) {
1448 x.t = self.m.t + 1
1449 x.clamp()
1450 }
1451 self.mu.multiplyUpperTo(self.r2, self.m.t + 1, self.q3)
1452 self.m.multiplyLowerTo(self.q3, self.m.t + 1, self.r2)
1453 while (x.compareTo(self.r2) < 0) x.dAddOffset(1, self.m.t + 1)
1454 x.subTo(self.r2, x)
1455 while (x.compareTo(self.m) >= 0) x.subTo(self.m, x)
1456}
1457
1458// r = x^2 mod m; x != r
1459function barrettSqrTo(x, r) {
1460 x.squareTo(r)
1461 this.reduce(r)
1462}
1463
1464// r = x*y mod m; x,y != r
1465function barrettMulTo(x, y, r) {
1466 x.multiplyTo(y, r)
1467 this.reduce(r)
1468}
1469
1470Barrett.prototype.convert = barrettConvert
1471Barrett.prototype.revert = barrettRevert
1472Barrett.prototype.reduce = barrettReduce
1473Barrett.prototype.mulTo = barrettMulTo
1474Barrett.prototype.sqrTo = barrettSqrTo
1475
1476// (public) this^e % m (HAC 14.85)
1477function bnModPow(e, m) {
1478 var i = e.bitLength(),
1479 k, r = nbv(1),
1480 z
1481 if (i <= 0) return r
1482 else if (i < 18) k = 1
1483 else if (i < 48) k = 3
1484 else if (i < 144) k = 4
1485 else if (i < 768) k = 5
1486 else k = 6
1487 if (i < 8)
1488 z = new Classic(m)
1489 else if (m.isEven())
1490 z = new Barrett(m)
1491 else
1492 z = new Montgomery(m)
1493
1494 // precomputation
1495 var g = new Array(),
1496 n = 3,
1497 k1 = k - 1,
1498 km = (1 << k) - 1
1499 g[1] = z.convert(this)
1500 if (k > 1) {
1501 var g2 = new BigInteger()
1502 z.sqrTo(g[1], g2)
1503 while (n <= km) {
1504 g[n] = new BigInteger()
1505 z.mulTo(g2, g[n - 2], g[n])
1506 n += 2
1507 }
1508 }
1509
1510 var j = e.t - 1,
1511 w, is1 = true,
1512 r2 = new BigInteger(),
1513 t
1514 i = nbits(e[j]) - 1
1515 while (j >= 0) {
1516 if (i >= k1) w = (e[j] >> (i - k1)) & km
1517 else {
1518 w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i)
1519 if (j > 0) w |= e[j - 1] >> (this.DB + i - k1)
1520 }
1521
1522 n = k
1523 while ((w & 1) == 0) {
1524 w >>= 1
1525 --n
1526 }
1527 if ((i -= n) < 0) {
1528 i += this.DB
1529 --j
1530 }
1531 if (is1) { // ret == 1, don't bother squaring or multiplying it
1532 g[w].copyTo(r)
1533 is1 = false
1534 } else {
1535 while (n > 1) {
1536 z.sqrTo(r, r2)
1537 z.sqrTo(r2, r)
1538 n -= 2
1539 }
1540 if (n > 0) z.sqrTo(r, r2)
1541 else {
1542 t = r
1543 r = r2
1544 r2 = t
1545 }
1546 z.mulTo(r2, g[w], r)
1547 }
1548
1549 while (j >= 0 && (e[j] & (1 << i)) == 0) {
1550 z.sqrTo(r, r2)
1551 t = r
1552 r = r2
1553 r2 = t
1554 if (--i < 0) {
1555 i = this.DB - 1
1556 --j
1557 }
1558 }
1559 }
1560 return z.revert(r)
1561}
1562
1563// (public) gcd(this,a) (HAC 14.54)
1564function bnGCD(a) {
1565 var x = (this.s < 0) ? this.negate() : this.clone()
1566 var y = (a.s < 0) ? a.negate() : a.clone()
1567 if (x.compareTo(y) < 0) {
1568 var t = x
1569 x = y
1570 y = t
1571 }
1572 var i = x.getLowestSetBit(),
1573 g = y.getLowestSetBit()
1574 if (g < 0) return x
1575 if (i < g) g = i
1576 if (g > 0) {
1577 x.rShiftTo(g, x)
1578 y.rShiftTo(g, y)
1579 }
1580 while (x.signum() > 0) {
1581 if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x)
1582 if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y)
1583 if (x.compareTo(y) >= 0) {
1584 x.subTo(y, x)
1585 x.rShiftTo(1, x)
1586 } else {
1587 y.subTo(x, y)
1588 y.rShiftTo(1, y)
1589 }
1590 }
1591 if (g > 0) y.lShiftTo(g, y)
1592 return y
1593}
1594
1595// (protected) this % n, n < 2^26
1596function bnpModInt(n) {
1597 if (n <= 0) return 0
1598 var d = this.DV % n,
1599 r = (this.s < 0) ? n - 1 : 0
1600 if (this.t > 0)
1601 if (d == 0) r = this[0] % n
1602 else
1603 for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n
1604 return r
1605}
1606
1607// (public) 1/this % m (HAC 14.61)
1608function bnModInverse(m) {
1609 var ac = m.isEven()
1610 if (this.signum() === 0) throw new Error('division by zero')
1611 if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO
1612 var u = m.clone(),
1613 v = this.clone()
1614 var a = nbv(1),
1615 b = nbv(0),
1616 c = nbv(0),
1617 d = nbv(1)
1618 while (u.signum() != 0) {
1619 while (u.isEven()) {
1620 u.rShiftTo(1, u)
1621 if (ac) {
1622 if (!a.isEven() || !b.isEven()) {
1623 a.addTo(this, a)
1624 b.subTo(m, b)
1625 }
1626 a.rShiftTo(1, a)
1627 } else if (!b.isEven()) b.subTo(m, b)
1628 b.rShiftTo(1, b)
1629 }
1630 while (v.isEven()) {
1631 v.rShiftTo(1, v)
1632 if (ac) {
1633 if (!c.isEven() || !d.isEven()) {
1634 c.addTo(this, c)
1635 d.subTo(m, d)
1636 }
1637 c.rShiftTo(1, c)
1638 } else if (!d.isEven()) d.subTo(m, d)
1639 d.rShiftTo(1, d)
1640 }
1641 if (u.compareTo(v) >= 0) {
1642 u.subTo(v, u)
1643 if (ac) a.subTo(c, a)
1644 b.subTo(d, b)
1645 } else {
1646 v.subTo(u, v)
1647 if (ac) c.subTo(a, c)
1648 d.subTo(b, d)
1649 }
1650 }
1651 if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO
1652 while (d.compareTo(m) >= 0) d.subTo(m, d)
1653 while (d.signum() < 0) d.addTo(m, d)
1654 return d
1655}
1656
1657var lowprimes = [
1658 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
1659 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
1660 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
1661 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
1662 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
1663 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
1664 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
1665 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
1666 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811,
1667 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
1668 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
1669]
1670
1671var lplim = (1 << 26) / lowprimes[lowprimes.length - 1]
1672
1673// (public) test primality with certainty >= 1-.5^t
1674function bnIsProbablePrime(t) {
1675 var i, x = this.abs()
1676 if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
1677 for (i = 0; i < lowprimes.length; ++i)
1678 if (x[0] == lowprimes[i]) return true
1679 return false
1680 }
1681 if (x.isEven()) return false
1682 i = 1
1683 while (i < lowprimes.length) {
1684 var m = lowprimes[i],
1685 j = i + 1
1686 while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]
1687 m = x.modInt(m)
1688 while (i < j) if (m % lowprimes[i++] == 0) return false
1689 }
1690 return x.millerRabin(t)
1691}
1692
1693// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1694function bnpMillerRabin(t) {
1695 var n1 = this.subtract(BigInteger.ONE)
1696 var k = n1.getLowestSetBit()
1697 if (k <= 0) return false
1698 var r = n1.shiftRight(k)
1699 t = (t + 1) >> 1
1700 if (t > lowprimes.length) t = lowprimes.length
1701 var a = new BigInteger(null)
1702 var j, bases = []
1703 for (var i = 0; i < t; ++i) {
1704 for (;;) {
1705 j = lowprimes[Math.floor(Math.random() * lowprimes.length)]
1706 if (bases.indexOf(j) == -1) break
1707 }
1708 bases.push(j)
1709 a.fromInt(j)
1710 var y = a.modPow(r, this)
1711 if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1712 var j = 1
1713 while (j++ < k && y.compareTo(n1) != 0) {
1714 y = y.modPowInt(2, this)
1715 if (y.compareTo(BigInteger.ONE) == 0) return false
1716 }
1717 if (y.compareTo(n1) != 0) return false
1718 }
1719 }
1720 return true
1721}
1722
1723// protected
1724proto.chunkSize = bnpChunkSize
1725proto.toRadix = bnpToRadix
1726proto.fromRadix = bnpFromRadix
1727proto.fromNumber = bnpFromNumber
1728proto.bitwiseTo = bnpBitwiseTo
1729proto.changeBit = bnpChangeBit
1730proto.addTo = bnpAddTo
1731proto.dMultiply = bnpDMultiply
1732proto.dAddOffset = bnpDAddOffset
1733proto.multiplyLowerTo = bnpMultiplyLowerTo
1734proto.multiplyUpperTo = bnpMultiplyUpperTo
1735proto.modInt = bnpModInt
1736proto.millerRabin = bnpMillerRabin
1737
1738// public
1739proto.clone = bnClone
1740proto.intValue = bnIntValue
1741proto.byteValue = bnByteValue
1742proto.shortValue = bnShortValue
1743proto.signum = bnSigNum
1744proto.toByteArray = bnToByteArray
1745proto.equals = bnEquals
1746proto.min = bnMin
1747proto.max = bnMax
1748proto.and = bnAnd
1749proto.or = bnOr
1750proto.xor = bnXor
1751proto.andNot = bnAndNot
1752proto.not = bnNot
1753proto.shiftLeft = bnShiftLeft
1754proto.shiftRight = bnShiftRight
1755proto.getLowestSetBit = bnGetLowestSetBit
1756proto.bitCount = bnBitCount
1757proto.testBit = bnTestBit
1758proto.setBit = bnSetBit
1759proto.clearBit = bnClearBit
1760proto.flipBit = bnFlipBit
1761proto.add = bnAdd
1762proto.subtract = bnSubtract
1763proto.multiply = bnMultiply
1764proto.divide = bnDivide
1765proto.remainder = bnRemainder
1766proto.divideAndRemainder = bnDivideAndRemainder
1767proto.modPow = bnModPow
1768proto.modInverse = bnModInverse
1769proto.pow = bnPow
1770proto.gcd = bnGCD
1771proto.isProbablePrime = bnIsProbablePrime
1772
1773// JSBN-specific extension
1774proto.square = bnSquare
1775
1776// constants
1777BigInteger.ZERO = nbv(0)
1778BigInteger.ONE = nbv(1)
1779BigInteger.valueOf = nbv
1780
1781module.exports = BigInteger
1782
1783},{"../package.json":6}],4:[function(require,module,exports){
1784(function (Buffer){
1785// FIXME: Kind of a weird way to throw exceptions, consider removing
1786var assert = require('assert')
1787var BigInteger = require('./bigi')
1788
1789/**
1790 * Turns a byte array into a big integer.
1791 *
1792 * This function will interpret a byte array as a big integer in big
1793 * endian notation.
1794 */
1795BigInteger.fromByteArrayUnsigned = function(byteArray) {
1796 // BigInteger expects a DER integer conformant byte array
1797 if (byteArray[0] & 0x80) {
1798 return new BigInteger([0].concat(byteArray))
1799 }
1800
1801 return new BigInteger(byteArray)
1802}
1803
1804/**
1805 * Returns a byte array representation of the big integer.
1806 *
1807 * This returns the absolute of the contained value in big endian
1808 * form. A value of zero results in an empty array.
1809 */
1810BigInteger.prototype.toByteArrayUnsigned = function() {
1811 var byteArray = this.toByteArray()
1812 return byteArray[0] === 0 ? byteArray.slice(1) : byteArray
1813}
1814
1815BigInteger.fromDERInteger = function(byteArray) {
1816 return new BigInteger(byteArray)
1817}
1818
1819/*
1820 * Converts BigInteger to a DER integer representation.
1821 *
1822 * The format for this value uses the most significant bit as a sign
1823 * bit. If the most significant bit is already set and the integer is
1824 * positive, a 0x00 is prepended.
1825 *
1826 * Examples:
1827 *
1828 * 0 => 0x00
1829 * 1 => 0x01
1830 * -1 => 0xff
1831 * 127 => 0x7f
1832 * -127 => 0x81
1833 * 128 => 0x0080
1834 * -128 => 0x80
1835 * 255 => 0x00ff
1836 * -255 => 0xff01
1837 * 16300 => 0x3fac
1838 * -16300 => 0xc054
1839 * 62300 => 0x00f35c
1840 * -62300 => 0xff0ca4
1841*/
1842BigInteger.prototype.toDERInteger = BigInteger.prototype.toByteArray
1843
1844BigInteger.fromBuffer = function(buffer) {
1845 // BigInteger expects a DER integer conformant byte array
1846 if (buffer[0] & 0x80) {
1847 var byteArray = Array.prototype.slice.call(buffer)
1848
1849 return new BigInteger([0].concat(byteArray))
1850 }
1851
1852 return new BigInteger(buffer)
1853}
1854
1855BigInteger.fromHex = function(hex) {
1856 if (hex === '') return BigInteger.ZERO
1857
1858 assert.equal(hex, hex.match(/^[A-Fa-f0-9]+/), 'Invalid hex string')
1859 assert.equal(hex.length % 2, 0, 'Incomplete hex')
1860 return new BigInteger(hex, 16)
1861}
1862
1863BigInteger.prototype.toBuffer = function(size) {
1864 var byteArray = this.toByteArrayUnsigned()
1865 var zeros = []
1866
1867 var padding = size - byteArray.length
1868 while (zeros.length < padding) zeros.push(0)
1869
1870 return new Buffer(zeros.concat(byteArray))
1871}
1872
1873BigInteger.prototype.toHex = function(size) {
1874 return this.toBuffer(size).toString('hex')
1875}
1876
1877}).call(this,require("buffer").Buffer)
1878},{"./bigi":3,"assert":90,"buffer":96}],5:[function(require,module,exports){
1879var BigInteger = require('./bigi')
1880
1881//addons
1882require('./convert')
1883
1884module.exports = BigInteger
1885},{"./bigi":3,"./convert":4}],6:[function(require,module,exports){
1886module.exports={
1887 "_args": [
1888 [
1889 "bigi@^1.4.0",
1890 "/home/hashengineering/hashengineering/groestlcoinjs-lib"
1891 ]
1892 ],
1893 "_from": "bigi@>=1.4.0 <2.0.0",
1894 "_id": "bigi@1.4.2",
1895 "_inCache": true,
1896 "_installable": true,
1897 "_location": "/bigi",
1898 "_nodeVersion": "6.1.0",
1899 "_npmOperationalInternal": {
1900 "host": "packages-12-west.internal.npmjs.com",
1901 "tmp": "tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"
1902 },
1903 "_npmUser": {
1904 "email": "jprichardson@gmail.com",
1905 "name": "jprichardson"
1906 },
1907 "_npmVersion": "3.8.6",
1908 "_phantomChildren": {},
1909 "_requested": {
1910 "name": "bigi",
1911 "raw": "bigi@^1.4.0",
1912 "rawSpec": "^1.4.0",
1913 "scope": null,
1914 "spec": ">=1.4.0 <2.0.0",
1915 "type": "range"
1916 },
1917 "_requiredBy": [
1918 "/"
1919 ],
1920 "_resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
1921 "_shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
1922 "_shrinkwrap": null,
1923 "_spec": "bigi@^1.4.0",
1924 "_where": "/home/hashengineering/hashengineering/groestlcoinjs-lib",
1925 "bugs": {
1926 "url": "https://github.com/cryptocoinjs/bigi/issues"
1927 },
1928 "dependencies": {},
1929 "description": "Big integers.",
1930 "devDependencies": {
1931 "coveralls": "^2.11.2",
1932 "istanbul": "^0.3.5",
1933 "jshint": "^2.5.1",
1934 "mocha": "^2.1.0",
1935 "mochify": "^2.1.0"
1936 },
1937 "directories": {},
1938 "dist": {
1939 "shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
1940 "tarball": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"
1941 },
1942 "gitHead": "c25308081c896ff84702303722bf5ecd8b3f78e3",
1943 "homepage": "https://github.com/cryptocoinjs/bigi#readme",
1944 "keywords": [
1945 "arbitrary",
1946 "arithmetic",
1947 "big",
1948 "bigint",
1949 "biginteger",
1950 "bignumber",
1951 "bitcoin",
1952 "cryptography",
1953 "decimal",
1954 "float",
1955 "int",
1956 "integer",
1957 "math",
1958 "number",
1959 "precision"
1960 ],
1961 "main": "./lib/index.js",
1962 "maintainers": [
1963 {
1964 "name": "midnightlightning",
1965 "email": "boydb@midnightdesign.ws"
1966 },
1967 {
1968 "name": "sidazhang",
1969 "email": "sidazhang89@gmail.com"
1970 },
1971 {
1972 "name": "nadav",
1973 "email": "npm@shesek.info"
1974 },
1975 {
1976 "name": "jprichardson",
1977 "email": "jprichardson@gmail.com"
1978 }
1979 ],
1980 "name": "bigi",
1981 "optionalDependencies": {},
1982 "readme": "ERROR: No README data found!",
1983 "repository": {
1984 "type": "git",
1985 "url": "git+https://github.com/cryptocoinjs/bigi.git"
1986 },
1987 "scripts": {
1988 "browser-test": "mochify --wd -R spec",
1989 "coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",
1990 "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",
1991 "jshint": "jshint --config jshint.json lib/*.js ; true",
1992 "test": "_mocha -- test/*.js",
1993 "unit": "mocha"
1994 },
1995 "testling": {
1996 "browsers": [
1997 "android-browser/4.2..latest",
1998 "chrome/latest",
1999 "firefox/latest",
2000 "ie/9..latest",
2001 "iphone/6.0..latest",
2002 "safari/6.0..latest"
2003 ],
2004 "files": "test/*.js",
2005 "harness": "mocha"
2006 },
2007 "version": "1.4.2"
2008}
2009
2010},{}],7:[function(require,module,exports){
2011// Reference https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki
2012// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
2013// NOTE: SIGHASH byte ignored AND restricted, truncate before use
2014
2015var Buffer = require('safe-buffer').Buffer
2016
2017function check (buffer) {
2018 if (buffer.length < 8) return false
2019 if (buffer.length > 72) return false
2020 if (buffer[0] !== 0x30) return false
2021 if (buffer[1] !== buffer.length - 2) return false
2022 if (buffer[2] !== 0x02) return false
2023
2024 var lenR = buffer[3]
2025 if (lenR === 0) return false
2026 if (5 + lenR >= buffer.length) return false
2027 if (buffer[4 + lenR] !== 0x02) return false
2028
2029 var lenS = buffer[5 + lenR]
2030 if (lenS === 0) return false
2031 if ((6 + lenR + lenS) !== buffer.length) return false
2032
2033 if (buffer[4] & 0x80) return false
2034 if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) return false
2035
2036 if (buffer[lenR + 6] & 0x80) return false
2037 if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) return false
2038 return true
2039}
2040
2041function decode (buffer) {
2042 if (buffer.length < 8) throw new Error('DER sequence length is too short')
2043 if (buffer.length > 72) throw new Error('DER sequence length is too long')
2044 if (buffer[0] !== 0x30) throw new Error('Expected DER sequence')
2045 if (buffer[1] !== buffer.length - 2) throw new Error('DER sequence length is invalid')
2046 if (buffer[2] !== 0x02) throw new Error('Expected DER integer')
2047
2048 var lenR = buffer[3]
2049 if (lenR === 0) throw new Error('R length is zero')
2050 if (5 + lenR >= buffer.length) throw new Error('R length is too long')
2051 if (buffer[4 + lenR] !== 0x02) throw new Error('Expected DER integer (2)')
2052
2053 var lenS = buffer[5 + lenR]
2054 if (lenS === 0) throw new Error('S length is zero')
2055 if ((6 + lenR + lenS) !== buffer.length) throw new Error('S length is invalid')
2056
2057 if (buffer[4] & 0x80) throw new Error('R value is negative')
2058 if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) throw new Error('R value excessively padded')
2059
2060 if (buffer[lenR + 6] & 0x80) throw new Error('S value is negative')
2061 if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) throw new Error('S value excessively padded')
2062
2063 // non-BIP66 - extract R, S values
2064 return {
2065 r: buffer.slice(4, 4 + lenR),
2066 s: buffer.slice(6 + lenR)
2067 }
2068}
2069
2070/*
2071 * Expects r and s to be positive DER integers.
2072 *
2073 * The DER format uses the most significant bit as a sign bit (& 0x80).
2074 * If the significant bit is set AND the integer is positive, a 0x00 is prepended.
2075 *
2076 * Examples:
2077 *
2078 * 0 => 0x00
2079 * 1 => 0x01
2080 * -1 => 0xff
2081 * 127 => 0x7f
2082 * -127 => 0x81
2083 * 128 => 0x0080
2084 * -128 => 0x80
2085 * 255 => 0x00ff
2086 * -255 => 0xff01
2087 * 16300 => 0x3fac
2088 * -16300 => 0xc054
2089 * 62300 => 0x00f35c
2090 * -62300 => 0xff0ca4
2091*/
2092function encode (r, s) {
2093 var lenR = r.length
2094 var lenS = s.length
2095 if (lenR === 0) throw new Error('R length is zero')
2096 if (lenS === 0) throw new Error('S length is zero')
2097 if (lenR > 33) throw new Error('R length is too long')
2098 if (lenS > 33) throw new Error('S length is too long')
2099 if (r[0] & 0x80) throw new Error('R value is negative')
2100 if (s[0] & 0x80) throw new Error('S value is negative')
2101 if (lenR > 1 && (r[0] === 0x00) && !(r[1] & 0x80)) throw new Error('R value excessively padded')
2102 if (lenS > 1 && (s[0] === 0x00) && !(s[1] & 0x80)) throw new Error('S value excessively padded')
2103
2104 var signature = Buffer.allocUnsafe(6 + lenR + lenS)
2105
2106 // 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
2107 signature[0] = 0x30
2108 signature[1] = signature.length - 2
2109 signature[2] = 0x02
2110 signature[3] = r.length
2111 r.copy(signature, 4)
2112 signature[4 + lenR] = 0x02
2113 signature[5 + lenR] = s.length
2114 s.copy(signature, 6 + lenR)
2115
2116 return signature
2117}
2118
2119module.exports = {
2120 check: check,
2121 decode: decode,
2122 encode: encode
2123}
2124
2125},{"safe-buffer":38}],8:[function(require,module,exports){
2126module.exports={
2127 "OP_FALSE": 0,
2128 "OP_0": 0,
2129 "OP_PUSHDATA1": 76,
2130 "OP_PUSHDATA2": 77,
2131 "OP_PUSHDATA4": 78,
2132 "OP_1NEGATE": 79,
2133 "OP_RESERVED": 80,
2134 "OP_TRUE": 81,
2135 "OP_1": 81,
2136 "OP_2": 82,
2137 "OP_3": 83,
2138 "OP_4": 84,
2139 "OP_5": 85,
2140 "OP_6": 86,
2141 "OP_7": 87,
2142 "OP_8": 88,
2143 "OP_9": 89,
2144 "OP_10": 90,
2145 "OP_11": 91,
2146 "OP_12": 92,
2147 "OP_13": 93,
2148 "OP_14": 94,
2149 "OP_15": 95,
2150 "OP_16": 96,
2151
2152 "OP_NOP": 97,
2153 "OP_VER": 98,
2154 "OP_IF": 99,
2155 "OP_NOTIF": 100,
2156 "OP_VERIF": 101,
2157 "OP_VERNOTIF": 102,
2158 "OP_ELSE": 103,
2159 "OP_ENDIF": 104,
2160 "OP_VERIFY": 105,
2161 "OP_RETURN": 106,
2162
2163 "OP_TOALTSTACK": 107,
2164 "OP_FROMALTSTACK": 108,
2165 "OP_2DROP": 109,
2166 "OP_2DUP": 110,
2167 "OP_3DUP": 111,
2168 "OP_2OVER": 112,
2169 "OP_2ROT": 113,
2170 "OP_2SWAP": 114,
2171 "OP_IFDUP": 115,
2172 "OP_DEPTH": 116,
2173 "OP_DROP": 117,
2174 "OP_DUP": 118,
2175 "OP_NIP": 119,
2176 "OP_OVER": 120,
2177 "OP_PICK": 121,
2178 "OP_ROLL": 122,
2179 "OP_ROT": 123,
2180 "OP_SWAP": 124,
2181 "OP_TUCK": 125,
2182
2183 "OP_CAT": 126,
2184 "OP_SUBSTR": 127,
2185 "OP_LEFT": 128,
2186 "OP_RIGHT": 129,
2187 "OP_SIZE": 130,
2188
2189 "OP_INVERT": 131,
2190 "OP_AND": 132,
2191 "OP_OR": 133,
2192 "OP_XOR": 134,
2193 "OP_EQUAL": 135,
2194 "OP_EQUALVERIFY": 136,
2195 "OP_RESERVED1": 137,
2196 "OP_RESERVED2": 138,
2197
2198 "OP_1ADD": 139,
2199 "OP_1SUB": 140,
2200 "OP_2MUL": 141,
2201 "OP_2DIV": 142,
2202 "OP_NEGATE": 143,
2203 "OP_ABS": 144,
2204 "OP_NOT": 145,
2205 "OP_0NOTEQUAL": 146,
2206 "OP_ADD": 147,
2207 "OP_SUB": 148,
2208 "OP_MUL": 149,
2209 "OP_DIV": 150,
2210 "OP_MOD": 151,
2211 "OP_LSHIFT": 152,
2212 "OP_RSHIFT": 153,
2213
2214 "OP_BOOLAND": 154,
2215 "OP_BOOLOR": 155,
2216 "OP_NUMEQUAL": 156,
2217 "OP_NUMEQUALVERIFY": 157,
2218 "OP_NUMNOTEQUAL": 158,
2219 "OP_LESSTHAN": 159,
2220 "OP_GREATERTHAN": 160,
2221 "OP_LESSTHANOREQUAL": 161,
2222 "OP_GREATERTHANOREQUAL": 162,
2223 "OP_MIN": 163,
2224 "OP_MAX": 164,
2225
2226 "OP_WITHIN": 165,
2227
2228 "OP_RIPEMD160": 166,
2229 "OP_SHA1": 167,
2230 "OP_SHA256": 168,
2231 "OP_HASH160": 169,
2232 "OP_HASH256": 170,
2233 "OP_CODESEPARATOR": 171,
2234 "OP_CHECKSIG": 172,
2235 "OP_CHECKSIGVERIFY": 173,
2236 "OP_CHECKMULTISIG": 174,
2237 "OP_CHECKMULTISIGVERIFY": 175,
2238
2239 "OP_NOP1": 176,
2240
2241 "OP_NOP2": 177,
2242 "OP_CHECKLOCKTIMEVERIFY": 177,
2243
2244 "OP_NOP3": 178,
2245 "OP_CHECKSEQUENCEVERIFY": 178,
2246
2247 "OP_NOP4": 179,
2248 "OP_NOP5": 180,
2249 "OP_NOP6": 181,
2250 "OP_NOP7": 182,
2251 "OP_NOP8": 183,
2252 "OP_NOP9": 184,
2253 "OP_NOP10": 185,
2254
2255 "OP_PUBKEYHASH": 253,
2256 "OP_PUBKEY": 254,
2257 "OP_INVALIDOPCODE": 255
2258}
2259
2260},{}],9:[function(require,module,exports){
2261var OPS = require('./index.json')
2262
2263var map = {}
2264for (var op in OPS) {
2265 var code = OPS[op]
2266 map[code] = op
2267}
2268
2269module.exports = map
2270
2271},{"./index.json":8}],10:[function(require,module,exports){
2272var basex = require('base-x')
2273var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
2274
2275module.exports = basex(ALPHABET)
2276
2277},{"base-x":1}],11:[function(require,module,exports){
2278'use strict'
2279
2280var base58 = require('bs58')
2281var Buffer = require('safe-buffer').Buffer
2282
2283module.exports = function (checksumFn) {
2284 // Encode a buffer as a base58-check encoded string
2285 function encode (payload) {
2286 var checksum = checksumFn(payload)
2287
2288 return base58.encode(Buffer.concat([
2289 payload,
2290 checksum
2291 ], payload.length + 4))
2292 }
2293
2294 function decodeRaw (buffer) {
2295 var payload = buffer.slice(0, -4)
2296 var checksum = buffer.slice(-4)
2297 var newChecksum = checksumFn(payload)
2298
2299 if (checksum[0] ^ newChecksum[0] |
2300 checksum[1] ^ newChecksum[1] |
2301 checksum[2] ^ newChecksum[2] |
2302 checksum[3] ^ newChecksum[3]) return
2303
2304 return payload
2305 }
2306
2307 // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
2308 function decodeUnsafe (string) {
2309 var buffer = base58.decodeUnsafe(string)
2310 if (!buffer) return
2311
2312 return decodeRaw(buffer)
2313 }
2314
2315 function decode (string) {
2316 var buffer = base58.decode(string)
2317 var payload = decodeRaw(buffer, checksumFn)
2318 if (!payload) throw new Error('Invalid checksum')
2319 return payload
2320 }
2321
2322 return {
2323 encode: encode,
2324 decode: decode,
2325 decodeUnsafe: decodeUnsafe
2326 }
2327}
2328
2329},{"bs58":10,"safe-buffer":38}],12:[function(require,module,exports){
2330(function (Buffer){
2331'use strict'
2332
2333var createHash = require('create-hash')
2334var bs58grscheckBase = require('./base')
2335var groestlhash = require('groestl-hash-js')
2336
2337// GROESTL512(GROESTL512(buffer))
2338function groestl (buffer) {
2339 return Buffer(groestlhash.groestl_2(buffer, 1, 1))
2340}
2341
2342module.exports = bs58grscheckBase(groestl)
2343
2344}).call(this,require("buffer").Buffer)
2345},{"./base":11,"buffer":96,"create-hash":14,"groestl-hash-js":27}],13:[function(require,module,exports){
2346var Buffer = require('safe-buffer').Buffer
2347var Transform = require('stream').Transform
2348var StringDecoder = require('string_decoder').StringDecoder
2349var inherits = require('inherits')
2350
2351function CipherBase (hashMode) {
2352 Transform.call(this)
2353 this.hashMode = typeof hashMode === 'string'
2354 if (this.hashMode) {
2355 this[hashMode] = this._finalOrDigest
2356 } else {
2357 this.final = this._finalOrDigest
2358 }
2359 if (this._final) {
2360 this.__final = this._final
2361 this._final = null
2362 }
2363 this._decoder = null
2364 this._encoding = null
2365}
2366inherits(CipherBase, Transform)
2367
2368CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
2369 if (typeof data === 'string') {
2370 data = Buffer.from(data, inputEnc)
2371 }
2372
2373 var outData = this._update(data)
2374 if (this.hashMode) return this
2375
2376 if (outputEnc) {
2377 outData = this._toString(outData, outputEnc)
2378 }
2379
2380 return outData
2381}
2382
2383CipherBase.prototype.setAutoPadding = function () {}
2384CipherBase.prototype.getAuthTag = function () {
2385 throw new Error('trying to get auth tag in unsupported state')
2386}
2387
2388CipherBase.prototype.setAuthTag = function () {
2389 throw new Error('trying to set auth tag in unsupported state')
2390}
2391
2392CipherBase.prototype.setAAD = function () {
2393 throw new Error('trying to set aad in unsupported state')
2394}
2395
2396CipherBase.prototype._transform = function (data, _, next) {
2397 var err
2398 try {
2399 if (this.hashMode) {
2400 this._update(data)
2401 } else {
2402 this.push(this._update(data))
2403 }
2404 } catch (e) {
2405 err = e
2406 } finally {
2407 next(err)
2408 }
2409}
2410CipherBase.prototype._flush = function (done) {
2411 var err
2412 try {
2413 this.push(this.__final())
2414 } catch (e) {
2415 err = e
2416 }
2417
2418 done(err)
2419}
2420CipherBase.prototype._finalOrDigest = function (outputEnc) {
2421 var outData = this.__final() || Buffer.alloc(0)
2422 if (outputEnc) {
2423 outData = this._toString(outData, outputEnc, true)
2424 }
2425 return outData
2426}
2427
2428CipherBase.prototype._toString = function (value, enc, fin) {
2429 if (!this._decoder) {
2430 this._decoder = new StringDecoder(enc)
2431 this._encoding = enc
2432 }
2433
2434 if (this._encoding !== enc) throw new Error('can\'t switch encodings')
2435
2436 var out = this._decoder.write(value)
2437 if (fin) {
2438 out += this._decoder.end()
2439 }
2440
2441 return out
2442}
2443
2444module.exports = CipherBase
2445
2446},{"inherits":32,"safe-buffer":38,"stream":122,"string_decoder":123}],14:[function(require,module,exports){
2447'use strict'
2448var inherits = require('inherits')
2449var MD5 = require('md5.js')
2450var RIPEMD160 = require('ripemd160')
2451var sha = require('sha.js')
2452var Base = require('cipher-base')
2453
2454function Hash (hash) {
2455 Base.call(this, 'digest')
2456
2457 this._hash = hash
2458}
2459
2460inherits(Hash, Base)
2461
2462Hash.prototype._update = function (data) {
2463 this._hash.update(data)
2464}
2465
2466Hash.prototype._final = function () {
2467 return this._hash.digest()
2468}
2469
2470module.exports = function createHash (alg) {
2471 alg = alg.toLowerCase()
2472 if (alg === 'md5') return new MD5()
2473 if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()
2474
2475 return new Hash(sha(alg))
2476}
2477
2478},{"cipher-base":13,"inherits":32,"md5.js":33,"ripemd160":37,"sha.js":40}],15:[function(require,module,exports){
2479var MD5 = require('md5.js')
2480
2481module.exports = function (buffer) {
2482 return new MD5().update(buffer).digest()
2483}
2484
2485},{"md5.js":33}],16:[function(require,module,exports){
2486'use strict'
2487var inherits = require('inherits')
2488var Legacy = require('./legacy')
2489var Base = require('cipher-base')
2490var Buffer = require('safe-buffer').Buffer
2491var md5 = require('create-hash/md5')
2492var RIPEMD160 = require('ripemd160')
2493
2494var sha = require('sha.js')
2495
2496var ZEROS = Buffer.alloc(128)
2497
2498function Hmac (alg, key) {
2499 Base.call(this, 'digest')
2500 if (typeof key === 'string') {
2501 key = Buffer.from(key)
2502 }
2503
2504 var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
2505
2506 this._alg = alg
2507 this._key = key
2508 if (key.length > blocksize) {
2509 var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
2510 key = hash.update(key).digest()
2511 } else if (key.length < blocksize) {
2512 key = Buffer.concat([key, ZEROS], blocksize)
2513 }
2514
2515 var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
2516 var opad = this._opad = Buffer.allocUnsafe(blocksize)
2517
2518 for (var i = 0; i < blocksize; i++) {
2519 ipad[i] = key[i] ^ 0x36
2520 opad[i] = key[i] ^ 0x5C
2521 }
2522 this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
2523 this._hash.update(ipad)
2524}
2525
2526inherits(Hmac, Base)
2527
2528Hmac.prototype._update = function (data) {
2529 this._hash.update(data)
2530}
2531
2532Hmac.prototype._final = function () {
2533 var h = this._hash.digest()
2534 var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg)
2535 return hash.update(this._opad).update(h).digest()
2536}
2537
2538module.exports = function createHmac (alg, key) {
2539 alg = alg.toLowerCase()
2540 if (alg === 'rmd160' || alg === 'ripemd160') {
2541 return new Hmac('rmd160', key)
2542 }
2543 if (alg === 'md5') {
2544 return new Legacy(md5, key)
2545 }
2546 return new Hmac(alg, key)
2547}
2548
2549},{"./legacy":17,"cipher-base":13,"create-hash/md5":15,"inherits":32,"ripemd160":37,"safe-buffer":38,"sha.js":40}],17:[function(require,module,exports){
2550'use strict'
2551var inherits = require('inherits')
2552var Buffer = require('safe-buffer').Buffer
2553
2554var Base = require('cipher-base')
2555
2556var ZEROS = Buffer.alloc(128)
2557var blocksize = 64
2558
2559function Hmac (alg, key) {
2560 Base.call(this, 'digest')
2561 if (typeof key === 'string') {
2562 key = Buffer.from(key)
2563 }
2564
2565 this._alg = alg
2566 this._key = key
2567
2568 if (key.length > blocksize) {
2569 key = alg(key)
2570 } else if (key.length < blocksize) {
2571 key = Buffer.concat([key, ZEROS], blocksize)
2572 }
2573
2574 var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
2575 var opad = this._opad = Buffer.allocUnsafe(blocksize)
2576
2577 for (var i = 0; i < blocksize; i++) {
2578 ipad[i] = key[i] ^ 0x36
2579 opad[i] = key[i] ^ 0x5C
2580 }
2581
2582 this._hash = [ipad]
2583}
2584
2585inherits(Hmac, Base)
2586
2587Hmac.prototype._update = function (data) {
2588 this._hash.push(data)
2589}
2590
2591Hmac.prototype._final = function () {
2592 var h = this._alg(Buffer.concat(this._hash))
2593 return this._alg(Buffer.concat([this._opad, h]))
2594}
2595module.exports = Hmac
2596
2597},{"cipher-base":13,"inherits":32,"safe-buffer":38}],18:[function(require,module,exports){
2598var assert = require('assert')
2599var BigInteger = require('bigi')
2600
2601var Point = require('./point')
2602
2603function Curve (p, a, b, Gx, Gy, n, h) {
2604 this.p = p
2605 this.a = a
2606 this.b = b
2607 this.G = Point.fromAffine(this, Gx, Gy)
2608 this.n = n
2609 this.h = h
2610
2611 this.infinity = new Point(this, null, null, BigInteger.ZERO)
2612
2613 // result caching
2614 this.pOverFour = p.add(BigInteger.ONE).shiftRight(2)
2615
2616 // determine size of p in bytes
2617 this.pLength = Math.floor((this.p.bitLength() + 7) / 8)
2618}
2619
2620Curve.prototype.pointFromX = function (isOdd, x) {
2621 var alpha = x.pow(3).add(this.a.multiply(x)).add(this.b).mod(this.p)
2622 var beta = alpha.modPow(this.pOverFour, this.p) // XXX: not compatible with all curves
2623
2624 var y = beta
2625 if (beta.isEven() ^ !isOdd) {
2626 y = this.p.subtract(y) // -y % p
2627 }
2628
2629 return Point.fromAffine(this, x, y)
2630}
2631
2632Curve.prototype.isInfinity = function (Q) {
2633 if (Q === this.infinity) return true
2634
2635 return Q.z.signum() === 0 && Q.y.signum() !== 0
2636}
2637
2638Curve.prototype.isOnCurve = function (Q) {
2639 if (this.isInfinity(Q)) return true
2640
2641 var x = Q.affineX
2642 var y = Q.affineY
2643 var a = this.a
2644 var b = this.b
2645 var p = this.p
2646
2647 // Check that xQ and yQ are integers in the interval [0, p - 1]
2648 if (x.signum() < 0 || x.compareTo(p) >= 0) return false
2649 if (y.signum() < 0 || y.compareTo(p) >= 0) return false
2650
2651 // and check that y^2 = x^3 + ax + b (mod p)
2652 var lhs = y.square().mod(p)
2653 var rhs = x.pow(3).add(a.multiply(x)).add(b).mod(p)
2654 return lhs.equals(rhs)
2655}
2656
2657/**
2658 * Validate an elliptic curve point.
2659 *
2660 * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive
2661 */
2662Curve.prototype.validate = function (Q) {
2663 // Check Q != O
2664 assert(!this.isInfinity(Q), 'Point is at infinity')
2665 assert(this.isOnCurve(Q), 'Point is not on the curve')
2666
2667 // Check nQ = O (where Q is a scalar multiple of G)
2668 var nQ = Q.multiply(this.n)
2669 assert(this.isInfinity(nQ), 'Point is not a scalar multiple of G')
2670
2671 return true
2672}
2673
2674module.exports = Curve
2675
2676},{"./point":22,"assert":90,"bigi":25}],19:[function(require,module,exports){
2677module.exports={
2678 "secp128r1": {
2679 "p": "fffffffdffffffffffffffffffffffff",
2680 "a": "fffffffdfffffffffffffffffffffffc",
2681 "b": "e87579c11079f43dd824993c2cee5ed3",
2682 "n": "fffffffe0000000075a30d1b9038a115",
2683 "h": "01",
2684 "Gx": "161ff7528b899b2d0c28607ca52c5b86",
2685 "Gy": "cf5ac8395bafeb13c02da292dded7a83"
2686 },
2687 "secp160k1": {
2688 "p": "fffffffffffffffffffffffffffffffeffffac73",
2689 "a": "00",
2690 "b": "07",
2691 "n": "0100000000000000000001b8fa16dfab9aca16b6b3",
2692 "h": "01",
2693 "Gx": "3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",
2694 "Gy": "938cf935318fdced6bc28286531733c3f03c4fee"
2695 },
2696 "secp160r1": {
2697 "p": "ffffffffffffffffffffffffffffffff7fffffff",
2698 "a": "ffffffffffffffffffffffffffffffff7ffffffc",
2699 "b": "1c97befc54bd7a8b65acf89f81d4d4adc565fa45",
2700 "n": "0100000000000000000001f4c8f927aed3ca752257",
2701 "h": "01",
2702 "Gx": "4a96b5688ef573284664698968c38bb913cbfc82",
2703 "Gy": "23a628553168947d59dcc912042351377ac5fb32"
2704 },
2705 "secp192k1": {
2706 "p": "fffffffffffffffffffffffffffffffffffffffeffffee37",
2707 "a": "00",
2708 "b": "03",
2709 "n": "fffffffffffffffffffffffe26f2fc170f69466a74defd8d",
2710 "h": "01",
2711 "Gx": "db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",
2712 "Gy": "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"
2713 },
2714 "secp192r1": {
2715 "p": "fffffffffffffffffffffffffffffffeffffffffffffffff",
2716 "a": "fffffffffffffffffffffffffffffffefffffffffffffffc",
2717 "b": "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",
2718 "n": "ffffffffffffffffffffffff99def836146bc9b1b4d22831",
2719 "h": "01",
2720 "Gx": "188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
2721 "Gy": "07192b95ffc8da78631011ed6b24cdd573f977a11e794811"
2722 },
2723 "secp256k1": {
2724 "p": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
2725 "a": "00",
2726 "b": "07",
2727 "n": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
2728 "h": "01",
2729 "Gx": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
2730 "Gy": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
2731 },
2732 "secp256r1": {
2733 "p": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
2734 "a": "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",
2735 "b": "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
2736 "n": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
2737 "h": "01",
2738 "Gx": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
2739 "Gy": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
2740 }
2741}
2742
2743},{}],20:[function(require,module,exports){
2744var Point = require('./point')
2745var Curve = require('./curve')
2746
2747var getCurveByName = require('./names')
2748
2749module.exports = {
2750 Curve: Curve,
2751 Point: Point,
2752 getCurveByName: getCurveByName
2753}
2754
2755},{"./curve":18,"./names":21,"./point":22}],21:[function(require,module,exports){
2756var BigInteger = require('bigi')
2757
2758var curves = require('./curves.json')
2759var Curve = require('./curve')
2760
2761function getCurveByName (name) {
2762 var curve = curves[name]
2763 if (!curve) return null
2764
2765 var p = new BigInteger(curve.p, 16)
2766 var a = new BigInteger(curve.a, 16)
2767 var b = new BigInteger(curve.b, 16)
2768 var n = new BigInteger(curve.n, 16)
2769 var h = new BigInteger(curve.h, 16)
2770 var Gx = new BigInteger(curve.Gx, 16)
2771 var Gy = new BigInteger(curve.Gy, 16)
2772
2773 return new Curve(p, a, b, Gx, Gy, n, h)
2774}
2775
2776module.exports = getCurveByName
2777
2778},{"./curve":18,"./curves.json":19,"bigi":25}],22:[function(require,module,exports){
2779var assert = require('assert')
2780var Buffer = require('safe-buffer').Buffer
2781var BigInteger = require('bigi')
2782
2783var THREE = BigInteger.valueOf(3)
2784
2785function Point (curve, x, y, z) {
2786 assert.notStrictEqual(z, undefined, 'Missing Z coordinate')
2787
2788 this.curve = curve
2789 this.x = x
2790 this.y = y
2791 this.z = z
2792 this._zInv = null
2793
2794 this.compressed = true
2795}
2796
2797Object.defineProperty(Point.prototype, 'zInv', {
2798 get: function () {
2799 if (this._zInv === null) {
2800 this._zInv = this.z.modInverse(this.curve.p)
2801 }
2802
2803 return this._zInv
2804 }
2805})
2806
2807Object.defineProperty(Point.prototype, 'affineX', {
2808 get: function () {
2809 return this.x.multiply(this.zInv).mod(this.curve.p)
2810 }
2811})
2812
2813Object.defineProperty(Point.prototype, 'affineY', {
2814 get: function () {
2815 return this.y.multiply(this.zInv).mod(this.curve.p)
2816 }
2817})
2818
2819Point.fromAffine = function (curve, x, y) {
2820 return new Point(curve, x, y, BigInteger.ONE)
2821}
2822
2823Point.prototype.equals = function (other) {
2824 if (other === this) return true
2825 if (this.curve.isInfinity(this)) return this.curve.isInfinity(other)
2826 if (this.curve.isInfinity(other)) return this.curve.isInfinity(this)
2827
2828 // u = Y2 * Z1 - Y1 * Z2
2829 var u = other.y.multiply(this.z).subtract(this.y.multiply(other.z)).mod(this.curve.p)
2830
2831 if (u.signum() !== 0) return false
2832
2833 // v = X2 * Z1 - X1 * Z2
2834 var v = other.x.multiply(this.z).subtract(this.x.multiply(other.z)).mod(this.curve.p)
2835
2836 return v.signum() === 0
2837}
2838
2839Point.prototype.negate = function () {
2840 var y = this.curve.p.subtract(this.y)
2841
2842 return new Point(this.curve, this.x, y, this.z)
2843}
2844
2845Point.prototype.add = function (b) {
2846 if (this.curve.isInfinity(this)) return b
2847 if (this.curve.isInfinity(b)) return this
2848
2849 var x1 = this.x
2850 var y1 = this.y
2851 var x2 = b.x
2852 var y2 = b.y
2853
2854 // u = Y2 * Z1 - Y1 * Z2
2855 var u = y2.multiply(this.z).subtract(y1.multiply(b.z)).mod(this.curve.p)
2856 // v = X2 * Z1 - X1 * Z2
2857 var v = x2.multiply(this.z).subtract(x1.multiply(b.z)).mod(this.curve.p)
2858
2859 if (v.signum() === 0) {
2860 if (u.signum() === 0) {
2861 return this.twice() // this == b, so double
2862 }
2863
2864 return this.curve.infinity // this = -b, so infinity
2865 }
2866
2867 var v2 = v.square()
2868 var v3 = v2.multiply(v)
2869 var x1v2 = x1.multiply(v2)
2870 var zu2 = u.square().multiply(this.z)
2871
2872 // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
2873 var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.p)
2874 // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
2875 var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.p)
2876 // z3 = v^3 * z1 * z2
2877 var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.p)
2878
2879 return new Point(this.curve, x3, y3, z3)
2880}
2881
2882Point.prototype.twice = function () {
2883 if (this.curve.isInfinity(this)) return this
2884 if (this.y.signum() === 0) return this.curve.infinity
2885
2886 var x1 = this.x
2887 var y1 = this.y
2888
2889 var y1z1 = y1.multiply(this.z).mod(this.curve.p)
2890 var y1sqz1 = y1z1.multiply(y1).mod(this.curve.p)
2891 var a = this.curve.a
2892
2893 // w = 3 * x1^2 + a * z1^2
2894 var w = x1.square().multiply(THREE)
2895
2896 if (a.signum() !== 0) {
2897 w = w.add(this.z.square().multiply(a))
2898 }
2899
2900 w = w.mod(this.curve.p)
2901 // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
2902 var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.p)
2903 // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
2904 var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.pow(3)).mod(this.curve.p)
2905 // z3 = 8 * (y1 * z1)^3
2906 var z3 = y1z1.pow(3).shiftLeft(3).mod(this.curve.p)
2907
2908 return new Point(this.curve, x3, y3, z3)
2909}
2910
2911// Simple NAF (Non-Adjacent Form) multiplication algorithm
2912// TODO: modularize the multiplication algorithm
2913Point.prototype.multiply = function (k) {
2914 if (this.curve.isInfinity(this)) return this
2915 if (k.signum() === 0) return this.curve.infinity
2916
2917 var e = k
2918 var h = e.multiply(THREE)
2919
2920 var neg = this.negate()
2921 var R = this
2922
2923 for (var i = h.bitLength() - 2; i > 0; --i) {
2924 var hBit = h.testBit(i)
2925 var eBit = e.testBit(i)
2926
2927 R = R.twice()
2928
2929 if (hBit !== eBit) {
2930 R = R.add(hBit ? this : neg)
2931 }
2932 }
2933
2934 return R
2935}
2936
2937// Compute this*j + x*k (simultaneous multiplication)
2938Point.prototype.multiplyTwo = function (j, x, k) {
2939 var i = Math.max(j.bitLength(), k.bitLength()) - 1
2940 var R = this.curve.infinity
2941 var both = this.add(x)
2942
2943 while (i >= 0) {
2944 var jBit = j.testBit(i)
2945 var kBit = k.testBit(i)
2946
2947 R = R.twice()
2948
2949 if (jBit) {
2950 if (kBit) {
2951 R = R.add(both)
2952 } else {
2953 R = R.add(this)
2954 }
2955 } else if (kBit) {
2956 R = R.add(x)
2957 }
2958 --i
2959 }
2960
2961 return R
2962}
2963
2964Point.prototype.getEncoded = function (compressed) {
2965 if (compressed == null) compressed = this.compressed
2966 if (this.curve.isInfinity(this)) return Buffer.alloc(1, 0) // Infinity point encoded is simply '00'
2967
2968 var x = this.affineX
2969 var y = this.affineY
2970 var byteLength = this.curve.pLength
2971 var buffer
2972
2973 // 0x02/0x03 | X
2974 if (compressed) {
2975 buffer = Buffer.allocUnsafe(1 + byteLength)
2976 buffer.writeUInt8(y.isEven() ? 0x02 : 0x03, 0)
2977
2978 // 0x04 | X | Y
2979 } else {
2980 buffer = Buffer.allocUnsafe(1 + byteLength + byteLength)
2981 buffer.writeUInt8(0x04, 0)
2982
2983 y.toBuffer(byteLength).copy(buffer, 1 + byteLength)
2984 }
2985
2986 x.toBuffer(byteLength).copy(buffer, 1)
2987
2988 return buffer
2989}
2990
2991Point.decodeFrom = function (curve, buffer) {
2992 var type = buffer.readUInt8(0)
2993 var compressed = (type !== 4)
2994
2995 var byteLength = Math.floor((curve.p.bitLength() + 7) / 8)
2996 var x = BigInteger.fromBuffer(buffer.slice(1, 1 + byteLength))
2997
2998 var Q
2999 if (compressed) {
3000 assert.equal(buffer.length, byteLength + 1, 'Invalid sequence length')
3001 assert(type === 0x02 || type === 0x03, 'Invalid sequence tag')
3002
3003 var isOdd = (type === 0x03)
3004 Q = curve.pointFromX(isOdd, x)
3005 } else {
3006 assert.equal(buffer.length, 1 + byteLength + byteLength, 'Invalid sequence length')
3007
3008 var y = BigInteger.fromBuffer(buffer.slice(1 + byteLength))
3009 Q = Point.fromAffine(curve, x, y)
3010 }
3011
3012 Q.compressed = compressed
3013 return Q
3014}
3015
3016Point.prototype.toString = function () {
3017 if (this.curve.isInfinity(this)) return '(INFINITY)'
3018
3019 return '(' + this.affineX.toString() + ',' + this.affineY.toString() + ')'
3020}
3021
3022module.exports = Point
3023
3024},{"assert":90,"bigi":25,"safe-buffer":38}],23:[function(require,module,exports){
3025arguments[4][3][0].apply(exports,arguments)
3026},{"../package.json":26,"dup":3}],24:[function(require,module,exports){
3027arguments[4][4][0].apply(exports,arguments)
3028},{"./bigi":23,"assert":90,"buffer":96,"dup":4}],25:[function(require,module,exports){
3029arguments[4][5][0].apply(exports,arguments)
3030},{"./bigi":23,"./convert":24,"dup":5}],26:[function(require,module,exports){
3031module.exports={
3032 "_args": [
3033 [
3034 "bigi@^1.1.0",
3035 "/home/hashengineering/hashengineering/groestlcoinjs-lib/node_modules/ecurve"
3036 ]
3037 ],
3038 "_from": "bigi@>=1.1.0 <2.0.0",
3039 "_id": "bigi@1.4.2",
3040 "_inCache": true,
3041 "_installable": true,
3042 "_location": "/ecurve/bigi",
3043 "_nodeVersion": "6.1.0",
3044 "_npmOperationalInternal": {
3045 "host": "packages-12-west.internal.npmjs.com",
3046 "tmp": "tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"
3047 },
3048 "_npmUser": {
3049 "email": "jprichardson@gmail.com",
3050 "name": "jprichardson"
3051 },
3052 "_npmVersion": "3.8.6",
3053 "_phantomChildren": {},
3054 "_requested": {
3055 "name": "bigi",
3056 "raw": "bigi@^1.1.0",
3057 "rawSpec": "^1.1.0",
3058 "scope": null,
3059 "spec": ">=1.1.0 <2.0.0",
3060 "type": "range"
3061 },
3062 "_requiredBy": [
3063 "/ecurve"
3064 ],
3065 "_resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
3066 "_shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
3067 "_shrinkwrap": null,
3068 "_spec": "bigi@^1.1.0",
3069 "_where": "/home/hashengineering/hashengineering/groestlcoinjs-lib/node_modules/ecurve",
3070 "bugs": {
3071 "url": "https://github.com/cryptocoinjs/bigi/issues"
3072 },
3073 "dependencies": {},
3074 "description": "Big integers.",
3075 "devDependencies": {
3076 "coveralls": "^2.11.2",
3077 "istanbul": "^0.3.5",
3078 "jshint": "^2.5.1",
3079 "mocha": "^2.1.0",
3080 "mochify": "^2.1.0"
3081 },
3082 "directories": {},
3083 "dist": {
3084 "shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
3085 "tarball": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"
3086 },
3087 "gitHead": "c25308081c896ff84702303722bf5ecd8b3f78e3",
3088 "homepage": "https://github.com/cryptocoinjs/bigi#readme",
3089 "keywords": [
3090 "arbitrary",
3091 "arithmetic",
3092 "big",
3093 "bigint",
3094 "biginteger",
3095 "bignumber",
3096 "bitcoin",
3097 "cryptography",
3098 "decimal",
3099 "float",
3100 "int",
3101 "integer",
3102 "math",
3103 "number",
3104 "precision"
3105 ],
3106 "main": "./lib/index.js",
3107 "maintainers": [
3108 {
3109 "name": "midnightlightning",
3110 "email": "boydb@midnightdesign.ws"
3111 },
3112 {
3113 "name": "sidazhang",
3114 "email": "sidazhang89@gmail.com"
3115 },
3116 {
3117 "name": "nadav",
3118 "email": "npm@shesek.info"
3119 },
3120 {
3121 "name": "jprichardson",
3122 "email": "jprichardson@gmail.com"
3123 }
3124 ],
3125 "name": "bigi",
3126 "optionalDependencies": {},
3127 "readme": "ERROR: No README data found!",
3128 "repository": {
3129 "type": "git",
3130 "url": "git+https://github.com/cryptocoinjs/bigi.git"
3131 },
3132 "scripts": {
3133 "browser-test": "mochify --wd -R spec",
3134 "coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",
3135 "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",
3136 "jshint": "jshint --config jshint.json lib/*.js ; true",
3137 "test": "_mocha -- test/*.js",
3138 "unit": "mocha"
3139 },
3140 "testling": {
3141 "browsers": [
3142 "android-browser/4.2..latest",
3143 "chrome/latest",
3144 "firefox/latest",
3145 "ie/9..latest",
3146 "iphone/6.0..latest",
3147 "safari/6.0..latest"
3148 ],
3149 "files": "test/*.js",
3150 "harness": "mocha"
3151 },
3152 "version": "1.4.2"
3153}
3154
3155},{}],27:[function(require,module,exports){
3156'use strict';
3157
3158var groestl = require('./lib/groestl');
3159var h = require('./lib/helper');
3160
3161var x11hash = module.exports;
3162
3163module.exports.groestl512 = function(str,format, output) {
3164 return groestl(str,format,output);
3165}
3166
3167module.exports.groestl = function(str,format, output) {
3168 var a = groestl(str,format,2);
3169 a = a.slice(0,8);
3170 if (output === 2) {
3171 return a;
3172 }
3173 else if (output === 1) {
3174 return h.int32Buffer2Bytes(a);
3175 }
3176 else {
3177 return h.int32ArrayToHexString(a);
3178 }
3179}
3180
3181module.exports.groestl_2 = function(str,format, output) {
3182 var a = groestl(str,format,2);
3183 a = groestl(a,2,2);
3184 a = a.slice(0,8);
3185 if (output === 2) {
3186 return a;
3187 }
3188 else if (output === 1) {
3189 return h.int32Buffer2Bytes(a);
3190 }
3191 else {
3192 return h.int32ArrayToHexString(a);
3193 }
3194}
3195},{"./lib/groestl":28,"./lib/helper":29}],28:[function(require,module,exports){
3196/////////////////////////////////////
3197//////////// groestl ///////////////
3198
3199//// Written by Quantum Explorer ////
3200////////// Dash Foundation //////////
3201/// Released under the MIT License //
3202/////////////////////////////////////
3203
3204var o = require('./op');
3205var h = require('./helper');
3206
3207var T0 = h.bytes2Int64Buffer(h.b64Decode("xjL0pfSXpcb4b5eEl+uE+O5esJmwx5nu9nqMjYz3jfb/6BcNF+UN/9YK3L3ct73W3hbIscinsd6RbfxU/DlUkWCQ8FDwwFBgAgcFAwUEAwLOLuCp4IepzlbRh32HrH1W58wrGSvVGee1E6ZipnFitU18MeYxmuZN7Fm1mrXDmuyPQM9FzwVFjx+jvJ28Pp0fiUnAQMAJQIn6aJKHku+H+u/QPxU/xRXvspQm6yZ/67KOzkDJQAfJjvvmHQsd7Qv7QW4v7C+C7EGzGqlnqX1ns19DHP0cvv1fRWAl6iWK6kUj+dq/2ka/I1NRAvcCpvdT5EWhlqHTluSbdu1b7S1bm3UoXcJd6sJ14cUkHCTZHOE91Omu6XquPUzyvmq+mGpMbILuWu7YWmx+vcNBw/xBfvXzBgIG8QL1g1LRT9EdT4NojORc5NBcaFFWB/QHovRR0Y1cNFy5NNH54RgIGOkI+eJMrpOu35Piqz6Vc5VNc6til/VT9cRTYiprQT9BVD8qCBwUDBQQDAiVY/ZS9jFSlUbpr2WvjGVGnX/iXuIhXp0wSHgoeGAoMDfP+KH4bqE3ChsRDxEUDwov68S1xF61Lw4VGwkbHAkOJH5aNlpINiQbrbabtjabG9+YRz1HpT3fzadqJmqBJs1O9btpu5xpTn8zTM1M/s1/6lC6n7rPn+oSPy0bLSQbEh2kuZ65Op4dWMScdJywdFg0RnIucmguNDZBdy13bC023BHNss2jsty0nSnuKXPutFtNFvsWtvtbpKUB9gFT9qR2oddN1+xNdrcUo2GjdWG3fTRJzkn6zn1S3417jaR7Ut2fQj5CoT7dXs2TcZO8cV4TsaKXoiaXE6aiBPUEV/WmuQG4aLhpaLkAAAAAAAAAAMG1dCx0mSzBQOCgYKCAYEDjwiEfId0f43k6Q8hD8sh5tpos7Sx37bbUDdm+2bO+1I1HykbKAUaNZxdw2XDO2Wdyr91L3eRLcpTted55M96UmP9n1Gcr1JiwkyPoI3vosIVb3kreEUqFuwa9a71ta7vFu34qfpEqxU97NOU0nuVP7dc6FjrBFu2G0lTFVBfFhpr4YtdiL9eaZpn/Vf/MVWYRtqeUpyKUEYrASs9KD8+K6dkwEDDJEOkEDgoGCggGBP5mmIGY54H+oKsL8Atb8KB4tMxEzPBEeCXw1brVSrolS3U+4z6W40uirA7zDl/zol1EGf4Zuv5dgNtbwFsbwIAFgIWKhQqKBT/T7K3sfq0/If7fvN9CvCFwqNhI2OBIcPH9DAQM+QTxYxl633rG32N3L1jBWO7Bd68wn3WfRXWvQuelY6WEY0IgcFAwUEAwIOXLLhou0Rrl/e8SDhLhDv2/CLdtt2Vtv4FV1EzUGUyBGCQ8FDwwFBgmeV81X0w1JsOycS9xnS/DvoY44Thn4b41yP2i/WqiNYjHT8xPC8yILmVLOUtcOS6TavlX+T1Xk1VYDfINqvJV/GGdgp3jgvx6s8lHyfRHesgn76zvi6zIuogy5zJv57oyT30rfWQrMuZCpJWk15XmwDv7oPuboMAZqrOYszKYGZ72aNFoJ9GeoyKBf4Fdf6NE7qpmqohmRFTWgn6CqH5UO93mq+Z2qzsLlZ6DnhaDC4zJRcpFA8qMx7x7KXuVKcdrBW7TbtbTayhsRDxEUDwopyyLeYtVeae8gT3iPWPivBYxJx0nLB0WrTeadppBdq3blk07Ta0722Se+lb6yFZkdKbSTtLoTnQUNiIeIigeFJLkdtt2P9uSDBIeCh4YCgxI/LRstJBsSLiPN+Q3a+S4n3jnXeclXZ+9D7JusmFuvUNpKu8qhu9DxDXxpvGTpsQ52uOo43KoOTHG96T3YqQx04pZN1m9N9PydIaLhv+L8tWDVjJWsTLVi07FQ8UNQ4tuhetZ69xZbtoYwrfCr7faAY6PjI8CjAGxHaxkrHlksZzxbdJtI9KcSXI74DuS4EnYH8e0x6u02Ky5FfoVQ/qs8/oJBwn9B/PPoG8lb4Ulz8og6q/qj6/K9H2JjonzjvRHZyDpII7pRxA4KBgoIBgQbwtk1WTe1W/wc4OIg/uI8Er7sW+xlG9KXMqWcpa4clw4VGwkbHAkOFdfCPEIrvFXcyFSx1Lmx3OXZPNR8zVRl8uuZSNljSPLoSWEfIRZfKHoV7+cv8uc6D5dYyFjfCE+lup83Xw33ZZhHn/cf8LcYQ2ckYaRGoYND5uUhZQehQ/gS6uQq9uQ4Hy6xkLG+EJ8cSZXxFfixHHMKeWq5YOqzJDjc9hzO9iQBgkPBQ8MBQb39AMBA/UB9xwqNhI2OBIcwjz+o/6fo8Jqi+Ff4dRfaq6+EPkQR/muaQJr0GvS0GkXv6iRqC6RF5lx6FjoKViZOlNpJ2l0Jzon99C50E65J9mRSDhIqTjZ6941EzXNE+sr5c6zzlazKyJ3VTNVRDMi0gTWu9a/u9KpOZBwkElwqQeHgImADokHM8Hyp/JmpzMt7MG2wVq2LTxaZiJmeCI8Fbitkq0qkhXJqWAgYIkgyYdc20nbFUmHqrAa/xpP/6pQ2Ih4iKB4UKUrjnqOUXqlA4mKj4oGjwNZShP4E7L4WQmSm4CbEoAJGiM5Fzk0FxplEHXadcraZdeEUzFTtTHXhNVRxlETxoTQA9O407u40ILcXsNeH8OCKeLLsMtSsClaw5l3mbR3Wh4tMxEzPBEeez1Gy0b2y3uotx/8H0v8qG0MYdZh2tZtLGJOOk5YOiw="));
3208var T1 = h.bytes2Int64Buffer(h.b64Decode("xsYy9KX0l6X4+G+XhJfrhO7uXrCZsMeZ9vZ6jI2M943//+gXDRflDdbWCty93Le93t4WyLHIp7GRkW38VPw5VGBgkPBQ8MBQAgIHBQMFBAPOzi7gqeCHqVZW0Yd9h6x95+fMKxkr1Rm1tROmYqZxYk1NfDHmMZrm7OxZtZq1w5qPj0DPRc8FRR8fo7ydvD6diYlJwEDACUD6+miSh5Lvh+/v0D8VP8UVsrKUJusmf+uOjs5AyUAHyfv75h0LHe0LQUFuL+wvguyzsxqpZ6l9Z19fQxz9HL79RUVgJeoliuojI/nav9pGv1NTUQL3Aqb35ORFoZah05abm3btW+0tW3V1KF3CXerC4eHFJBwk2Rw9PdTprul6rkxM8r5qvphqbGyC7lru2Fp+fr3DQcP8QfX18wYCBvECg4NS0U/RHU9oaIzkXOTQXFFRVgf0B6L00dGNXDRcuTT5+eEYCBjpCOLiTK6Trt+Tq6s+lXOVTXNiYpf1U/XEUyoqa0E/QVQ/CAgcFAwUEAyVlWP2UvYxUkZG6a9lr4xlnZ1/4l7iIV4wMEh4KHhgKDc3z/ih+G6hCgobEQ8RFA8vL+vEtcRetQ4OFRsJGxwJJCR+WjZaSDYbG622m7Y2m9/fmEc9R6U9zc2naiZqgSZOTvW7abucaX9/M0zNTP7N6upQup+6z58SEj8tGy0kGx0dpLmeuTqeWFjEnHScsHQ0NEZyLnJoLjY2QXctd2wt3NwRzbLNo7K0tJ0p7ilz7ltbTRb7Frb7pKSlAfYBU/Z2dqHXTdfsTbe3FKNho3VhfX00Sc5J+s5SUt+Ne42ke93dn0I+QqE+Xl7Nk3GTvHETE7Gil6Iml6amogT1BFf1ubkBuGi4aWgAAAAAAAAAAMHBtXQsdJksQEDgoGCggGDj48IhHyHdH3l5OkPIQ/LItraaLO0sd+3U1A3Zvtmzvo2NR8pGygFGZ2cXcNlwztlycq/dS93kS5SU7XneeTPemJj/Z9RnK9SwsJMj6CN76IWFW95K3hFKu7sGvWu9bWvFxbt+Kn6RKk9PezTlNJ7l7e3XOhY6wRaGhtJUxVQXxZqa+GLXYi/XZmaZ/1X/zFUREbanlKcilIqKwErPSg/P6enZMBAwyRAEBA4KBgoIBv7+ZpiBmOeBoKCrC/ALW/B4eLTMRMzwRCUl8NW61Uq6S0t1PuM+luOioqwO8w5f811dRBn+Gbr+gIDbW8BbG8AFBYCFioUKij8/0+yt7H6tISH+37zfQrxwcKjYSNjgSPHx/QwEDPkEY2MZet96xt93dy9YwVjuwa+vMJ91n0V1QkLnpWOlhGMgIHBQMFBAMOXlyy4aLtEa/f3vEg4S4Q6/vwi3bbdlbYGBVdRM1BlMGBgkPBQ8MBQmJnlfNV9MNcPDsnEvcZ0vvr6GOOE4Z+E1Ncj9ov1qooiIx0/MTwvMLi5lSzlLXDmTk2r5V/k9V1VVWA3yDary/PxhnYKd44J6erPJR8n0R8jIJ++s74usurqIMucyb+cyMk99K31kK+bmQqSVpNeVwMA7+6D7m6AZGaqzmLMymJ6e9mjRaCfRo6MigX+BXX9ERO6qZqqIZlRU1oJ+gqh+Ozvd5qvmdqsLC5Weg54Wg4yMyUXKRQPKx8e8eyl7lSlrawVu027W0ygobEQ8RFA8p6csi3mLVXm8vIE94j1j4hYWMScdJywdra03mnaaQXbb25ZNO02tO2RknvpW+shWdHSm0k7S6E4UFDYiHiIoHpKS5Hbbdj/bDAwSHgoeGApISPy0bLSQbLi4jzfkN2vkn594513nJV29vQ+ybrJhbkNDaSrvKobvxMQ18abxk6Y5OdrjqONyqDExxvek92Kk09OKWTdZvTfy8nSGi4b/i9XVg1YyVrEyi4tOxUPFDUNuboXrWevcWdraGMK3wq+3AQGOj4yPAoyxsR2sZKx5ZJyc8W3SbSPSSUlyO+A7kuDY2B/HtMertKysuRX6FUP68/P6CQcJ/QfPz6BvJW+FJcrKIOqv6o+v9PR9iY6J845HR2cg6SCO6RAQOCgYKCAYb28LZNVk3tXw8HODiIP7iEpK+7FvsZRvXFzKlnKWuHI4OFRsJGxwJFdXXwjxCK7xc3MhUsdS5seXl2TzUfM1UcvLrmUjZY0joaElhHyEWXzo6Fe/nL/LnD4+XWMhY3whlpbqfN18N91hYR5/3H/C3A0NnJGGkRqGDw+blIWUHoXg4EurkKvbkHx8usZCxvhCcXEmV8RX4sTMzCnlquWDqpCQ43PYczvYBgYJDwUPDAX39/QDAQP1ARwcKjYSNjgSwsI8/qP+n6NqaovhX+HUX66uvhD5EEf5aWkCa9Br0tAXF7+okagukZmZcehY6ClYOjpTaSdpdCcnJ/fQudBOudnZkUg4SKk46+veNRM1zRMrK+XOs85WsyIid1UzVUQz0tIE1rvWv7upqTmQcJBJcAcHh4CJgA6JMzPB8qfyZqctLezBtsFatjw8WmYiZngiFRW4rZKtKpLJyalgIGCJIIeHXNtJ2xVJqqqwGv8aT/9QUNiIeIigeKWlK456jlF6AwOJio+KBo9ZWUoT+BOy+AkJkpuAmxKAGhojORc5NBdlZRB12nXK2tfXhFMxU7UxhITVUcZRE8bQ0APTuNO7uIKC3F7DXh/DKSniy7DLUrBaWsOZd5m0dx4eLTMRMzwRe3s9RstG9suoqLcf/B9L/G1tDGHWYdrWLCxiTjpOWDo="));
3209var T2 = h.bytes2Int64Buffer(h.b64Decode("pcbGMvSl9JeE+Phvl4SX65nu7l6wmbDHjfb2eoyNjPcN///oFw0X5b3W1grcvdy3sd7eFsixyKdUkZFt/FT8OVBgYJDwUPDAAwICBwUDBQSpzs4u4Kngh31WVtGHfYesGefnzCsZK9VitbUTpmKmceZNTXwx5jGamuzsWbWatcNFj49Az0XPBZ0fH6O8nbw+QImJScBAwAmH+vpokoeS7xXv79A/FT/F67KylCbrJn/Jjo7OQMlABwv7++YdCx3t7EFBbi/sL4Jns7MaqWepff1fX0Mc/Ry+6kVFYCXqJYq/IyP52r/aRvdTU1EC9wKmluTkRaGWodNbm5t27VvtLcJ1dShdwl3qHOHhxSQcJNmuPT3U6a7pempMTPK+ar6YWmxsgu5a7thBfn69w0HD/AL19fMGAgbxT4ODUtFP0R1caGiM5Fzk0PRRUVYH9AeiNNHRjVw0XLkI+fnhGAgY6ZPi4kyuk67fc6urPpVzlU1TYmKX9VP1xD8qKmtBP0FUDAgIHBQMFBBSlZVj9lL2MWVGRumvZa+MXp2df+Je4iEoMDBIeCh4YKE3N8/4ofhuDwoKGxEPERS1Ly/rxLXEXgkODhUbCRscNiQkflo2WkibGxuttpu2Nj3f35hHPUelJs3Np2omaoFpTk71u2m7nM1/fzNMzUz+n+rqULqfus8bEhI/LRstJJ4dHaS5nrk6dFhYxJx0nLAuNDRGci5yaC02NkF3LXdsstzcEc2yzaPutLSdKe4pc/tbW00W+xa29qSkpQH2AVNNdnah103X7GG3txSjYaN1zn19NEnOSfp7UlLfjXuNpD7d3Z9CPkKhcV5ezZNxk7yXExOxopeiJvWmpqIE9QRXaLm5AbhouGkAAAAAAAAAACzBwbV0LHSZYEBA4KBgoIAf4+PCIR8h3ch5eTpDyEPy7ba2miztLHe+1NQN2b7Zs0aNjUfKRsoB2WdnF3DZcM5LcnKv3Uvd5N6UlO153nkz1JiY/2fUZyvosLCTI+gje0qFhVveSt4Ra7u7Br1rvW0qxcW7fip+keVPT3s05TSeFu3t1zoWOsHFhobSVMVUF9eamvhi12IvVWZmmf9V/8yUERG2p5SnIs+KisBKz0oPEOnp2TAQMMkGBAQOCgYKCIH+/maYgZjn8KCgqwvwC1tEeHi0zETM8LolJfDVutVK40tLdT7jPpbzoqKsDvMOX/5dXUQZ/hm6wICA21vAWxuKBQWAhYqFCq0/P9Psrex+vCEh/t+830JIcHCo2EjY4ATx8f0MBAz532NjGXrfesbBd3cvWMFY7nWvrzCfdZ9FY0JC56VjpYQwICBwUDBQQBrl5csuGi7RDv397xIOEuFtv78It223ZUyBgVXUTNQZFBgYJDwUPDA1JiZ5XzVfTC/Dw7JxL3Gd4b6+hjjhOGeiNTXI/aL9asyIiMdPzE8LOS4uZUs5S1xXk5Nq+Vf5PfJVVVgN8g2qgvz8YZ2CneNHenqzyUfJ9KzIyCfvrO+L57q6iDLnMm8rMjJPfSt9ZJXm5kKklaTXoMDAO/ug+5uYGRmqs5izMtGenvZo0Wgnf6OjIoF/gV1mRETuqmaqiH5UVNaCfoKoqzs73ear5naDCwuVnoOeFsqMjMlFykUDKcfHvHspe5XTa2sFbtNu1jwoKGxEPERQeaenLIt5i1XivLyBPeI9Yx0WFjEnHScsdq2tN5p2mkE729uWTTtNrVZkZJ76VvrITnR0ptJO0ugeFBQ2Ih4iKNuSkuR223Y/CgwMEh4KHhhsSEj8tGy0kOS4uI835DdrXZ+feOdd5yVuvb0Psm6yYe9DQ2kq7yqGpsTENfGm8ZOoOTna46jjcqQxMcb3pPdiN9PTilk3Wb2L8vJ0houG/zLV1YNWMlaxQ4uLTsVDxQ1Zbm6F61nr3Lfa2hjCt8KvjAEBjo+MjwJksbEdrGSsedKcnPFt0m0j4ElJcjvgO5K02Ngfx7THq/qsrLkV+hVDB/Pz+gkHCf0lz8+gbyVvha/KyiDqr+qPjvT0fYmOifPpR0dnIOkgjhgQEDgoGCgg1W9vC2TVZN6I8PBzg4iD+29KSvuxb7GUclxcypZylrgkODhUbCRscPFXV18I8Qiux3NzIVLHUuZRl5dk81HzNSPLy65lI2WNfKGhJYR8hFmc6OhXv5y/yyE+Pl1jIWN83ZaW6nzdfDfcYWEef9x/woYNDZyRhpEahQ8Pm5SFlB6Q4OBLq5Cr20J8fLrGQsb4xHFxJlfEV+KqzMwp5arlg9iQkONz2HM7BQYGCQ8FDwwB9/f0AwED9RIcHCo2EjY4o8LCPP6j/p9famqL4V/h1Pmurr4Q+RBH0GlpAmvQa9KRFxe/qJGoLliZmXHoWOgpJzo6U2knaXS5Jyf30LnQTjjZ2ZFIOEipE+vr3jUTNc2zKyvlzrPOVjMiIndVM1VEu9LSBNa71r9wqak5kHCQSYkHB4eAiYAOpzMzwfKn8ma2LS3swbbBWiI8PFpmImZ4khUVuK2SrSogycmpYCBgiUmHh1zbSdsV/6qqsBr/Gk94UFDYiHiIoHqlpSuOeo5RjwMDiYqPigb4WVlKE/gTsoAJCZKbgJsSFxoaIzkXOTTaZWUQddp1yjHX14RTMVO1xoSE1VHGURO40NAD07jTu8OCgtxew14fsCkp4suwy1J3WlrDmXeZtBEeHi0zETM8y3t7PUbLRvb8qKi3H/wfS9ZtbQxh1mHaOiwsYk46Tlg="));
3210var T3 = h.bytes2Int64Buffer(h.b64Decode("l6XGxjL0pfTrhPj4b5eEl8eZ7u5esJmw94329nqMjYzlDf//6BcNF7e91tYK3L3cp7He3hbIscg5VJGRbfxU/MBQYGCQ8FDwBAMCAgcFAwWHqc7OLuCp4Kx9VlbRh32H1Rnn58wrGStxYrW1E6ZipprmTU18MeYxw5rs7Fm1mrUFRY+PQM9Fzz6dHx+jvJ28CUCJiUnAQMDvh/r6aJKHksUV7+/QPxU/f+uyspQm6yYHyY6OzkDJQO0L+/vmHQsdguxBQW4v7C99Z7OzGqlnqb79X19DHP0ciupFRWAl6iVGvyMj+dq/2qb3U1NRAvcC05bk5EWhlqEtW5ubdu1b7erCdXUoXcJd2Rzh4cUkHCR6rj091Omu6ZhqTEzyvmq+2FpsbILuWu78QX5+vcNBw/EC9fXzBgIGHU+Dg1LRT9HQXGhojORc5KL0UVFWB/QHuTTR0Y1cNFzpCPn54RgIGN+T4uJMrpOuTXOrqz6Vc5XEU2Jil/VT9VQ/KiprQT9BEAwICBwUDBQxUpWVY/ZS9oxlRkbpr2WvIV6dnX/iXuJgKDAwSHgoeG6hNzfP+KH4FA8KChsRDxFetS8v68S1xBwJDg4VGwkbSDYkJH5aNlo2mxsbrbabtqU939+YRz1HgSbNzadqJmqcaU5O9btpu/7Nf38zTM1Mz5/q6lC6n7okGxISPy0bLTqeHR2kuZ65sHRYWMScdJxoLjQ0RnIucmwtNjZBdy13o7Lc3BHNss1z7rS0nSnuKbb7W1tNFvsWU/akpKUB9gHsTXZ2oddN13Vht7cUo2Gj+s59fTRJzkmke1JS3417jaE+3d2fQj5CvHFeXs2TcZMmlxMTsaKXolf1pqaiBPUEaWi5uQG4aLgAAAAAAAAAAJkswcG1dCx0gGBAQOCgYKDdH+PjwiEfIfLIeXk6Q8hDd+22tpos7SyzvtTUDdm+2QFGjY1HykbKztlnZxdw2XDkS3Jyr91L3TPelJTted55K9SYmP9n1Gd76LCwkyPoIxFKhYVb3krebWu7uwa9a72RKsXFu34qfp7lT097NOU0wRbt7dc6FjoXxYaG0lTFVC/Xmpr4YtdizFVmZpn/Vf8ilBERtqeUpw/PiorASs9KyRDp6dkwEDAIBgQEDgoGCueB/v5mmIGYW/CgoKsL8AvwRHh4tMxEzEq6JSXw1brVluNLS3U+4z5f86KirA7zDrr+XV1EGf4ZG8CAgNtbwFsKigUFgIWKhX6tPz/T7K3sQrwhIf7fvN/gSHBwqNhI2PkE8fH9DAQMxt9jYxl633ruwXd3L1jBWEV1r68wn3WfhGNCQuelY6VAMCAgcFAwUNEa5eXLLhou4Q79/e8SDhJlbb+/CLdttxlMgYFV1EzUMBQYGCQ8FDxMNSYmeV81X50vw8OycS9xZ+G+voY44ThqojU1yP2i/QvMiIjHT8xPXDkuLmVLOUs9V5OTavlX+aryVVVYDfIN44L8/GGdgp30R3p6s8lHyYusyMgn76zvb+e6uogy5zJkKzIyT30rfdeV5uZCpJWkm6DAwDv7oPsymBkZqrOYsyfRnp72aNFoXX+joyKBf4GIZkRE7qpmqqh+VFTWgn6Cdqs7O93mq+YWgwsLlZ6DngPKjIzJRcpFlSnHx7x7KXvW02trBW7TblA8KChsRDxEVXmnpyyLeYtj4ry8gT3iPSwdFhYxJx0nQXatrTeadpqtO9vblk07TchWZGSe+lb66E50dKbSTtIoHhQUNiIeIj/bkpLkdtt2GAoMDBIeCh6QbEhI/LRstGvkuLiPN+Q3JV2fn3jnXedhbr29D7JusobvQ0NpKu8qk6bExDXxpvFyqDk52uOo42KkMTHG96T3vTfT04pZN1n/i/LydIaLhrEy1dWDVjJWDUOLi07FQ8XcWW5uhetZ66+32toYwrfCAowBAY6PjI95ZLGxHaxkrCPSnJzxbdJtkuBJSXI74DurtNjYH8e0x0P6rKy5FfoV/Qfz8/oJBwmFJc/PoG8lb4+vysog6q/q84709H2JjomO6UdHZyDpICAYEBA4KBgo3tVvbwtk1WT7iPDwc4OIg5RvSkr7sW+xuHJcXMqWcpZwJDg4VGwkbK7xV1dfCPEI5sdzcyFSx1I1UZeXZPNR840jy8uuZSNlWXyhoSWEfITLnOjoV7+cv3whPj5dYyFjN92Wlup83XzC3GFhHn/cfxqGDQ2ckYaRHoUPD5uUhZTbkODgS6uQq/hCfHy6xkLG4sRxcSZXxFeDqszMKeWq5TvYkJDjc9hzDAUGBgkPBQ/1Aff39AMBAzgSHBwqNhI2n6PCwjz+o/7UX2pqi+Ff4Uf5rq6+EPkQ0tBpaQJr0GsukRcXv6iRqClYmZlx6FjodCc6OlNpJ2lOuScn99C50Kk42dmRSDhIzRPr6941EzVWsysr5c6zzkQzIiJ3VTNVv7vS0gTWu9ZJcKmpOZBwkA6JBweHgImAZqczM8Hyp/Jati0t7MG2wXgiPDxaZiJmKpIVFbitkq2JIMnJqWAgYBVJh4dc20nbT/+qqrAa/xqgeFBQ2Ih4iFF6paUrjnqOBo8DA4mKj4qy+FlZShP4ExKACQmSm4CbNBcaGiM5FznK2mVlEHXadbUx19eEUzFTE8aEhNVRxlG7uNDQA9O40x/DgoLcXsNeUrApKeLLsMu0d1paw5l3mTwRHh4tMxEz9st7ez1Gy0ZL/Kiotx/8H9rWbW0MYdZhWDosLGJOOk4="));
3211var T4 = h.bytes2Int64Buffer(h.b64Decode("9JelxsYy9KWX64T4+G+XhLDHme7uXrCZjPeN9vZ6jI0X5Q3//+gXDdy3vdbWCty9yKex3t4WyLH8OVSRkW38VPDAUGBgkPBQBQQDAgIHBQPgh6nOzi7gqYesfVZW0Yd9K9UZ5+fMKxmmcWK1tROmYjGa5k1NfDHmtcOa7OxZtZrPBUWPj0DPRbw+nR8fo7ydwAlAiYlJwECS74f6+miShz/FFe/v0D8VJn/rsrKUJutAB8mOjs5AyR3tC/v75h0LL4LsQUFuL+ypfWezsxqpZxy+/V9fQxz9JYrqRUVgJeraRr8jI/navwKm91NTUQL3odOW5ORFoZbtLVubm3btW13qwnV1KF3CJNkc4eHFJBzpeq49PdTprr6YakxM8r5q7thabGyC7lrD/EF+fr3DQQbxAvX18wYC0R1Pg4NS0U/k0FxoaIzkXAei9FFRVgf0XLk00dGNXDQY6Qj5+eEYCK7fk+LiTK6TlU1zq6s+lXP1xFNiYpf1U0FUPyoqa0E/FBAMCAgcFAz2MVKVlWP2Uq+MZUZG6a9l4iFenZ1/4l54YCgwMEh4KPhuoTc3z/ihERQPCgobEQ/EXrUvL+vEtRscCQ4OFRsJWkg2JCR+Wja2NpsbG622m0elPd/fmEc9aoEmzc2naia7nGlOTvW7aUz+zX9/M0zNus+f6upQup8tJBsSEj8tG7k6nh0dpLmenLB0WFjEnHRyaC40NEZyLndsLTY2QXctzaOy3NwRzbIpc+60tJ0p7ha2+1tbTRb7AVP2pKSlAfbX7E12dqHXTaN1Ybe3FKNhSfrOfX00Sc6NpHtSUt+Ne0KhPt3dn0I+k7xxXl7Nk3GiJpcTE7GilwRX9aamogT1uGloubkBuGgAAAAAAAAAAHSZLMHBtXQsoIBgQEDgoGAh3R/j48IhH0PyyHl5OkPILHfttraaLO3Zs77U1A3ZvsoBRo2NR8pGcM7ZZ2cXcNnd5Etycq/dS3kz3pSU7XneZyvUmJj/Z9Qje+iwsJMj6N4RSoWFW95KvW1ru7sGvWt+kSrFxbt+KjSe5U9PezTlOsEW7e3XOhZUF8WGhtJUxWIv15qa+GLX/8xVZmaZ/1WnIpQREbanlEoPz4qKwErPMMkQ6enZMBAKCAYEBA4KBpjngf7+ZpiBC1vwoKCrC/DM8ER4eLTMRNVKuiUl8NW6PpbjS0t1PuMOX/OioqwO8xm6/l1dRBn+WxvAgIDbW8CFCooFBYCFiux+rT8/0+yt30K8ISH+37zY4EhwcKjYSAz5BPHx/QwEesbfY2MZet9Y7sF3dy9YwZ9Fda+vMJ91pYRjQkLnpWNQQDAgIHBQMC7RGuXlyy4aEuEO/f3vEg63ZW2/vwi3bdQZTIGBVdRMPDAUGBgkPBRfTDUmJnlfNXGdL8PDsnEvOGfhvr6GOOH9aqI1Ncj9ok8LzIiIx0/MS1w5Li5lSzn5PVeTk2r5Vw2q8lVVWA3yneOC/PxhnYLJ9Ed6erPJR++LrMjIJ++sMm/nurqIMud9ZCsyMk99K6TXlebmQqSV+5ugwMA7+6CzMpgZGaqzmGgn0Z6e9mjRgV1/o6MigX+qiGZERO6qZoKoflRU1oJ+5narOzvd5queFoMLC5Weg0UDyoyMyUXKe5Upx8e8eylu1tNrawVu00RQPCgobEQ8i1V5p6csi3k9Y+K8vIE94icsHRYWMScdmkF2ra03mnZNrTvb25ZNO/rIVmRknvpW0uhOdHSm0k4iKB4UFDYiHnY/25KS5HbbHhgKDAwSHgq0kGxISPy0bDdr5Li4jzfk5yVdn594512yYW69vQ+ybiqG70NDaSrv8ZOmxMQ18abjcqg5OdrjqPdipDExxvekWb0309OKWTeG/4vy8nSGi1axMtXVg1YyxQ1Di4tOxUPr3FluboXrWcKvt9raGMK3jwKMAQGOj4yseWSxsR2sZG0j0pyc8W3SO5LgSUlyO+DHq7TY2B/HtBVD+qysuRX6Cf0H8/P6CQdvhSXPz6BvJeqPr8rKIOqvifOO9PR9iY4gjulHR2cg6SggGBAQOCgYZN7Vb28LZNWD+4jw8HODiLGUb0pK+7FvlrhyXFzKlnJscCQ4OFRsJAiu8VdXXwjxUubHc3MhUsfzNVGXl2TzUWWNI8vLrmUjhFl8oaElhHy/y5zo6Fe/nGN8IT4+XWMhfDfdlpbqfN1/wtxhYR5/3JEahg0NnJGGlB6FDw+blIWr25Dg4EurkMb4Qnx8usZCV+LEcXEmV8Tlg6rMzCnlqnM72JCQ43PYDwwFBgYJDwUD9QH39/QDATY4EhwcKjYS/p+jwsI8/qPh1F9qaovhXxBH+a6uvhD5a9LQaWkCa9CoLpEXF7+okegpWJmZcehYaXQnOjpTaSfQTrknJ/fQuUipONnZkUg4Nc0T6+veNRPOVrMrK+XOs1VEMyIid1Uz1r+70tIE1ruQSXCpqTmQcIAOiQcHh4CJ8manMzPB8qfBWrYtLezBtmZ4Ijw8WmYirSqSFRW4rZJgiSDJyalgINsVSYeHXNtJGk//qqqwGv+IoHhQUNiIeI5ReqWlK456igaPAwOJio8TsvhZWUoT+JsSgAkJkpuAOTQXGhojORd1ytplZRB12lO1MdfXhFMxURPGhITVUcbTu7jQ0APTuF4fw4KC3F7Dy1KwKSniy7CZtHdaWsOZdzM8ER4eLTMRRvbLe3s9RssfS/yoqLcf/GHa1m1tDGHWTlg6LCxiTjo="));
3212var T5 = h.bytes2Int64Buffer(h.b64Decode("pfSXpcbGMvSEl+uE+Phvl5mwx5nu7l6wjYz3jfb2eowNF+UN///oF73ct73W1grcscinsd7eFshU/DlUkZFt/FDwwFBgYJDwAwUEAwICBwWp4Iepzs4u4H2HrH1WVtGHGSvVGefnzCtipnFitbUTpuYxmuZNTXwxmrXDmuzsWbVFzwVFj49Az528Pp0fH6O8QMAJQImJScCHku+H+vpokhU/xRXv79A/6yZ/67KylCbJQAfJjo7OQAsd7Qv7++Yd7C+C7EFBbi9nqX1ns7Maqf0cvv1fX0Mc6iWK6kVFYCW/2ka/IyP52vcCpvdTU1EClqHTluTkRaFb7S1bm5t27cJd6sJ1dShdHCTZHOHhxSSu6XquPT3U6Wq+mGpMTPK+Wu7YWmxsgu5Bw/xBfn69wwIG8QL19fMGT9EdT4ODUtFc5NBcaGiM5PQHovRRUVYHNFy5NNHRjVwIGOkI+fnhGJOu35Pi4kyuc5VNc6urPpVT9cRTYmKX9T9BVD8qKmtBDBQQDAgIHBRS9jFSlZVj9mWvjGVGRumvXuIhXp2df+IoeGAoMDBIeKH4bqE3N8/4DxEUDwoKGxG1xF61Ly/rxAkbHAkODhUbNlpINiQkflqbtjabGxuttj1HpT3f35hHJmqBJs3Np2ppu5xpTk71u81M/s1/fzNMn7rPn+rqULobLSQbEhI/LZ65Op4dHaS5dJywdFhYxJwucmguNDRGci13bC02NkF3ss2jstzcEc3uKXPutLSdKfsWtvtbW00W9gFT9qSkpQFN1+xNdnah12GjdWG3txSjzkn6zn19NEl7jaR7UlLfjT5CoT7d3Z9CcZO8cV5ezZOXoiaXExOxovUEV/WmpqIEaLhpaLm5AbgAAAAAAAAAACx0mSzBwbV0YKCAYEBA4KAfId0f4+PCIchD8sh5eTpD7Sx37ba2miy+2bO+1NQN2UbKAUaNjUfK2XDO2WdnF3BL3eRLcnKv3d55M96UlO151Gcr1JiY/2foI3vosLCTI0reEUqFhVvea71ta7u7Br0qfpEqxcW7fuU0nuVPT3s0FjrBFu3t1zrFVBfFhobSVNdiL9eamvhiVf/MVWZmmf+UpyKUERG2p89KD8+KisBKEDDJEOnp2TAGCggGBAQOCoGY54H+/maY8Atb8KCgqwtEzPBEeHi0zLrVSrolJfDV4z6W40tLdT7zDl/zoqKsDv4Zuv5dXUQZwFsbwICA21uKhQqKBQWAha3sfq0/P9PsvN9CvCEh/t9I2OBIcHCo2AQM+QTx8f0M33rG32NjGXrBWO7Bd3cvWHWfRXWvrzCfY6WEY0JC56UwUEAwICBwUBou0Rrl5csuDhLhDv397xJtt2Vtv78It0zUGUyBgVXUFDwwFBgYJDw1X0w1JiZ5Xy9xnS/Dw7Jx4Thn4b6+hjii/WqiNTXI/cxPC8yIiMdPOUtcOS4uZUtX+T1Xk5Nq+fINqvJVVVgNgp3jgvz8YZ1HyfRHenqzyazvi6zIyCfv5zJv57q6iDIrfWQrMjJPfZWk15Xm5kKkoPuboMDAO/uYszKYGRmqs9FoJ9GenvZof4Fdf6OjIoFmqohmRETuqn6CqH5UVNaCq+Z2qzs73eaDnhaDCwuVnspFA8qMjMlFKXuVKcfHvHvTbtbTa2sFbjxEUDwoKGxEeYtVeaenLIviPWPivLyBPR0nLB0WFjEndppBdq2tN5o7Ta0729uWTVb6yFZkZJ76TtLoTnR0ptIeIigeFBQ2Itt2P9uSkuR2Ch4YCgwMEh5stJBsSEj8tOQ3a+S4uI83XeclXZ+feOdusmFuvb0Psu8qhu9DQ2kqpvGTpsTENfGo43KoOTna46T3YqQxMcb3N1m9N9PTilmLhv+L8vJ0hjJWsTLV1YNWQ8UNQ4uLTsVZ69xZbm6F67fCr7fa2hjCjI8CjAEBjo9krHlksbEdrNJtI9KcnPFt4DuS4ElJcju0x6u02Ngfx/oVQ/qsrLkVBwn9B/Pz+gklb4Ulz8+gb6/qj6/KyiDqjonzjvT0fYnpII7pR0dnIBgoIBgQEDgo1WTe1W9vC2SIg/uI8PBzg2+xlG9KSvuxcpa4clxcypYkbHAkODhUbPEIrvFXV18Ix1Lmx3NzIVJR8zVRl5dk8yNljSPLy65lfIRZfKGhJYScv8uc6OhXvyFjfCE+Pl1j3Xw33ZaW6nzcf8LcYWEef4aRGoYNDZyRhZQehQ8Pm5SQq9uQ4OBLq0LG+EJ8fLrGxFfixHFxJleq5YOqzMwp5dhzO9iQkONzBQ8MBQYGCQ8BA/UB9/f0AxI2OBIcHCo2o/6fo8LCPP5f4dRfamqL4fkQR/murr4Q0GvS0GlpAmuRqC6RFxe/qFjoKViZmXHoJ2l0Jzo6U2m50E65Jyf30DhIqTjZ2ZFIEzXNE+vr3jWzzlazKyvlzjNVRDMiIndVu9a/u9LSBNZwkElwqak5kImADokHB4eAp/JmpzMzwfK2wVq2LS3swSJmeCI8PFpmkq0qkhUVuK0gYIkgycmpYEnbFUmHh1zb/xpP/6qqsBp4iKB4UFDYiHqOUXqlpSuOj4oGjwMDiYr4E7L4WVlKE4CbEoAJCZKbFzk0FxoaIznadcraZWUQdTFTtTHX14RTxlETxoSE1VG407u40NAD08NeH8OCgtxesMtSsCkp4st3mbR3WlrDmREzPBEeHi0zy0b2y3t7PUb8H0v8qKi3H9Zh2tZtbQxhOk5YOiwsYk4="));
3213var T6 = h.bytes2Int64Buffer(h.b64Decode("9KX0l6XGxjKXhJfrhPj4b7CZsMeZ7u5ejI2M94329noXDRflDf//6Ny93Le91tYKyLHIp7He3hb8VPw5VJGRbfBQ8MBQYGCQBQMFBAMCAgfgqeCHqc7OLod9h6x9VlbRKxkr1Rnn58ymYqZxYrW1EzHmMZrmTU18tZq1w5rs7FnPRc8FRY+PQLydvD6dHx+jwEDACUCJiUmSh5Lvh/r6aD8VP8UV7+/QJusmf+uyspRAyUAHyY6Ozh0LHe0L+/vmL+wvguxBQW6pZ6l9Z7OzGhz9HL79X19DJeoliupFRWDav9pGvyMj+QL3Aqb3U1NRoZah05bk5EXtW+0tW5ubdl3CXerCdXUoJBwk2Rzh4cXprul6rj091L5qvphqTEzy7lru2FpsbILDQcP8QX5+vQYCBvEC9fXz0U/RHU+Dg1LkXOTQXGhojAf0B6L0UVFWXDRcuTTR0Y0YCBjpCPn54a6Trt+T4uJMlXOVTXOrqz71U/XEU2Jil0E/QVQ/KiprFAwUEAwICBz2UvYxUpWVY69lr4xlRkbp4l7iIV6dnX94KHhgKDAwSPih+G6hNzfPEQ8RFA8KChvEtcRetS8v6xsJGxwJDg4VWjZaSDYkJH62m7Y2mxsbrUc9R6U939+YaiZqgSbNzae7abucaU5O9UzNTP7Nf38zup+6z5/q6lAtGy0kGxISP7meuTqeHR2knHScsHRYWMRyLnJoLjQ0Rnctd2wtNjZBzbLNo7Lc3BEp7ilz7rS0nRb7Frb7W1tNAfYBU/akpKXXTdfsTXZ2oaNho3Vht7cUSc5J+s59fTSNe42ke1JS30I+QqE+3d2fk3GTvHFeXs2il6ImlxMTsQT1BFf1pqaiuGi4aWi5uQEAAAAAAAAAAHQsdJkswcG1oGCggGBAQOAhHyHdH+PjwkPIQ/LIeXk6LO0sd+22tprZvtmzvtTUDcpGygFGjY1HcNlwztlnZxfdS93kS3Jyr3neeTPelJTtZ9RnK9SYmP8j6CN76LCwk95K3hFKhYVbvWu9bWu7uwZ+Kn6RKsXFuzTlNJ7lT097OhY6wRbt7ddUxVQXxYaG0mLXYi/Xmpr4/1X/zFVmZpmnlKcilBERtkrPSg/PiorAMBAwyRDp6dkKBgoIBgQEDpiBmOeB/v5mC/ALW/CgoKvMRMzwRHh4tNW61Uq6JSXwPuM+luNLS3UO8w5f86KirBn+Gbr+XV1EW8BbG8CAgNuFioUKigUFgOyt7H6tPz/T37zfQrwhIf7YSNjgSHBwqAwEDPkE8fH9et96xt9jYxlYwVjuwXd3L591n0V1r68wpWOlhGNCQudQMFBAMCAgcC4aLtEa5eXLEg4S4Q79/e+3bbdlbb+/CNRM1BlMgYFVPBQ8MBQYGCRfNV9MNSYmeXEvcZ0vw8OyOOE4Z+G+vob9ov1qojU1yE/MTwvMiIjHSzlLXDkuLmX5V/k9V5OTag3yDaryVVVYnYKd44L8/GHJR8n0R3p6s++s74usyMgnMucyb+e6uoh9K31kKzIyT6SVpNeV5uZC+6D7m6DAwDuzmLMymBkZqmjRaCfRnp72gX+BXX+joyKqZqqIZkRE7oJ+gqh+VFTW5qvmdqs7O92eg54WgwsLlUXKRQPKjIzJeyl7lSnHx7xu027W02trBUQ8RFA8KChsi3mLVXmnpyw94j1j4ry8gScdJywdFhYxmnaaQXatrTdNO02tO9vblvpW+shWZGSe0k7S6E50dKYiHiIoHhQUNnbbdj/bkpLkHgoeGAoMDBK0bLSQbEhI/DfkN2vkuLiP513nJV2fn3iybrJhbr29DyrvKobvQ0Np8abxk6bExDXjqONyqDk52vek92KkMTHGWTdZvTfT04qGi4b/i/LydFYyVrEy1dWDxUPFDUOLi07rWevcWW5uhcK3wq+32toYj4yPAowBAY6sZKx5ZLGxHW3SbSPSnJzxO+A7kuBJSXLHtMertNjYHxX6FUP6rKy5CQcJ/Qfz8/pvJW+FJc/PoOqv6o+vysogiY6J84709H0g6SCO6UdHZygYKCAYEBA4ZNVk3tVvbwuDiIP7iPDwc7FvsZRvSkr7lnKWuHJcXMpsJGxwJDg4VAjxCK7xV1dfUsdS5sdzcyHzUfM1UZeXZGUjZY0jy8uuhHyEWXyhoSW/nL/LnOjoV2MhY3whPj5dfN18N92Wlup/3H/C3GFhHpGGkRqGDQ2clIWUHoUPD5urkKvbkODgS8ZCxvhCfHy6V8RX4sRxcSblquWDqszMKXPYczvYkJDjDwUPDAUGBgkDAQP1Aff39DYSNjgSHBwq/qP+n6PCwjzhX+HUX2pqixD5EEf5rq6+a9Br0tBpaQKokagukRcXv+hY6ClYmZlxaSdpdCc6OlPQudBOuScn90g4SKk42dmRNRM1zRPr697Os85Wsysr5VUzVUQzIiJ31rvWv7vS0gSQcJBJcKmpOYCJgA6JBweH8qfyZqczM8HBtsFati0t7GYiZngiPDxarZKtKpIVFbhgIGCJIMnJqdtJ2xVJh4dcGv8aT/+qqrCIeIigeFBQ2I56jlF6paUrio+KBo8DA4kT+BOy+FlZSpuAmxKACQmSORc5NBcaGiN12nXK2mVlEFMxU7Ux19eEUcZRE8aEhNXTuNO7uNDQA17DXh/DgoLcy7DLUrApKeKZd5m0d1pawzMRMzwRHh4tRstG9st7ez0f/B9L/Kiot2HWYdrWbW0MTjpOWDosLGI="));
3214var T7 = h.bytes2Int64Buffer(h.b64Decode("MvSl9JelxsZvl4SX64T4+F6wmbDHme7ueoyNjPeN9vboFw0X5Q3//wrcvdy3vdbWFsixyKex3t5t/FT8OVSRkZDwUPDAUGBgBwUDBQQDAgIu4Kngh6nOztGHfYesfVZWzCsZK9UZ5+cTpmKmcWK1tXwx5jGa5k1NWbWatcOa7OxAz0XPBUWPj6O8nbw+nR8fScBAwAlAiYlokoeS74f6+tA/FT/FFe/vlCbrJn/rsrLOQMlAB8mOjuYdCx3tC/v7bi/sL4LsQUEaqWepfWezs0Mc/Ry+/V9fYCXqJYrqRUX52r/aRr8jI1EC9wKm91NTRaGWodOW5OR27VvtLVubmyhdwl3qwnV1xSQcJNkc4eHU6a7peq49PfK+ar6YakxMgu5a7thabGy9w0HD/EF+fvMGAgbxAvX1UtFP0R1Pg4OM5Fzk0FxoaFYH9Aei9FFRjVw0XLk00dHhGAgY6Qj5+Uyuk67fk+LiPpVzlU1zq6uX9VP1xFNiYmtBP0FUPyoqHBQMFBAMCAhj9lL2MVKVlemvZa+MZUZGf+Je4iFenZ1IeCh4YCgwMM/4ofhuoTc3GxEPERQPCgrrxLXEXrUvLxUbCRscCQ4Oflo2Wkg2JCSttpu2NpsbG5hHPUelPd/fp2omaoEmzc31u2m7nGlOTjNMzUz+zX9/ULqfus+f6uo/LRstJBsSEqS5nrk6nh0dxJx0nLB0WFhGci5yaC40NEF3LXdsLTY2Ec2yzaOy3NydKe4pc+60tE0W+xa2+1tbpQH2AVP2pKSh103X7E12dhSjYaN1Ybe3NEnOSfrOfX3fjXuNpHtSUp9CPkKhPt3dzZNxk7xxXl6xopeiJpcTE6IE9QRX9aamAbhouGloubkAAAAAAAAAALV0LHSZLMHB4KBgoIBgQEDCIR8h3R/j4zpDyEPyyHl5miztLHfttrYN2b7Zs77U1EfKRsoBRo2NF3DZcM7ZZ2ev3Uvd5Etycu153nkz3pSU/2fUZyvUmJiTI+gje+iwsFveSt4RSoWFBr1rvW1ru7u7fip+kSrFxXs05TSe5U9P1zoWOsEW7e3SVMVUF8WGhvhi12Iv15qamf9V/8xVZma2p5SnIpQREcBKz0oPz4qK2TAQMMkQ6ekOCgYKCAYEBGaYgZjngf7+qwvwC1vwoKC0zETM8ER4ePDVutVKuiUldT7jPpbjS0usDvMOX/OiokQZ/hm6/l1d21vAWxvAgICAhYqFCooFBdPsrex+rT8//t+830K8ISGo2EjY4EhwcP0MBAz5BPHxGXrfesbfY2MvWMFY7sF3dzCfdZ9Fda+v56VjpYRjQkJwUDBQQDAgIMsuGi7RGuXl7xIOEuEO/f0It223ZW2/v1XUTNQZTIGBJDwUPDAUGBh5XzVfTDUmJrJxL3GdL8PDhjjhOGfhvr7I/aL9aqI1NcdPzE8LzIiIZUs5S1w5Li5q+Vf5PVeTk1gN8g2q8lVVYZ2CneOC/PyzyUfJ9Ed6eifvrO+LrMjIiDLnMm/nurpPfSt9ZCsyMkKklaTXlebmO/ug+5ugwMCqs5izMpgZGfZo0Wgn0Z6eIoF/gV1/o6PuqmaqiGZERNaCfoKoflRU3ear5narOzuVnoOeFoMLC8lFykUDyoyMvHspe5Upx8cFbtNu1tNra2xEPERQPCgoLIt5i1V5p6eBPeI9Y+K8vDEnHScsHRYWN5p2mkF2ra2WTTtNrTvb2576VvrIVmRkptJO0uhOdHQ2Ih4iKB4UFOR223Y/25KSEh4KHhgKDAz8tGy0kGxISI835Ddr5Li4eOdd5yVdn58Psm6yYW69vWkq7yqG70NDNfGm8ZOmxMTa46jjcqg5Ocb3pPdipDExilk3Wb0309N0houG/4vy8oNWMlaxMtXVTsVDxQ1Di4uF61nr3FlubhjCt8Kvt9rajo+MjwKMAQEdrGSseWSxsfFt0m0j0pyccjvgO5LgSUkfx7THq7TY2LkV+hVD+qys+gkHCf0H8/OgbyVvhSXPzyDqr+qPr8rKfYmOifOO9PRnIOkgjulHRzgoGCggGBAQC2TVZN7Vb29zg4iD+4jw8Puxb7GUb0pKypZylrhyXFxUbCRscCQ4OF8I8Qiu8VdXIVLHUubHc3Nk81HzNVGXl65lI2WNI8vLJYR8hFl8oaFXv5y/y5zo6F1jIWN8IT4+6nzdfDfdlpYef9x/wtxhYZyRhpEahg0Nm5SFlB6FDw9Lq5Cr25Dg4LrGQsb4Qnx8JlfEV+LEcXEp5arlg6rMzONz2HM72JCQCQ8FDwwFBgb0AwED9QH39yo2EjY4EhwcPP6j/p+jwsKL4V/h1F9qar4Q+RBH+a6uAmvQa9LQaWm/qJGoLpEXF3HoWOgpWJmZU2knaXQnOjr30LnQTrknJ5FIOEipONnZ3jUTNc0T6+vlzrPOVrMrK3dVM1VEMyIiBNa71r+70tI5kHCQSXCpqYeAiYAOiQcHwfKn8manMzPswbbBWrYtLVpmImZ4Ijw8uK2SrSqSFRWpYCBgiSDJyVzbSdsVSYeHsBr/Gk//qqrYiHiIoHhQUCuOeo5ReqWliYqPigaPAwNKE/gTsvhZWZKbgJsSgAkJIzkXOTQXGhoQddp1ytplZYRTMVO1MdfX1VHGURPGhIQD07jTu7jQ0Nxew14fw4KC4suwy1KwKSnDmXeZtHdaWi0zETM8ER4ePUbLRvbLe3u3H/wfS/yoqAxh1mHa1m1tYk46Tlg6LCw="));
3215
3216// var T0 = [
3217// o.u(0xc632f4a5, 0xf497a5c6), o.u(0xf86f9784, 0x97eb84f8),
3218// o.u(0xee5eb099, 0xb0c799ee), o.u(0xf67a8c8d, 0x8cf78df6),
3219// o.u(0xffe8170d, 0x17e50dff), o.u(0xd60adcbd, 0xdcb7bdd6),
3220// o.u(0xde16c8b1, 0xc8a7b1de), o.u(0x916dfc54, 0xfc395491),
3221// o.u(0x6090f050, 0xf0c05060), o.u(0x02070503, 0x05040302),
3222// o.u(0xce2ee0a9, 0xe087a9ce), o.u(0x56d1877d, 0x87ac7d56),
3223// o.u(0xe7cc2b19, 0x2bd519e7), o.u(0xb513a662, 0xa67162b5),
3224// o.u(0x4d7c31e6, 0x319ae64d), o.u(0xec59b59a, 0xb5c39aec),
3225// o.u(0x8f40cf45, 0xcf05458f), o.u(0x1fa3bc9d, 0xbc3e9d1f),
3226// o.u(0x8949c040, 0xc0094089), o.u(0xfa689287, 0x92ef87fa),
3227// o.u(0xefd03f15, 0x3fc515ef), o.u(0xb29426eb, 0x267febb2),
3228// o.u(0x8ece40c9, 0x4007c98e), o.u(0xfbe61d0b, 0x1ded0bfb),
3229// o.u(0x416e2fec, 0x2f82ec41), o.u(0xb31aa967, 0xa97d67b3),
3230// o.u(0x5f431cfd, 0x1cbefd5f), o.u(0x456025ea, 0x258aea45),
3231// o.u(0x23f9dabf, 0xda46bf23), o.u(0x535102f7, 0x02a6f753),
3232// o.u(0xe445a196, 0xa1d396e4), o.u(0x9b76ed5b, 0xed2d5b9b),
3233// o.u(0x75285dc2, 0x5deac275), o.u(0xe1c5241c, 0x24d91ce1),
3234// o.u(0x3dd4e9ae, 0xe97aae3d), o.u(0x4cf2be6a, 0xbe986a4c),
3235// o.u(0x6c82ee5a, 0xeed85a6c), o.u(0x7ebdc341, 0xc3fc417e),
3236// o.u(0xf5f30602, 0x06f102f5), o.u(0x8352d14f, 0xd11d4f83),
3237// o.u(0x688ce45c, 0xe4d05c68), o.u(0x515607f4, 0x07a2f451),
3238// o.u(0xd18d5c34, 0x5cb934d1), o.u(0xf9e11808, 0x18e908f9),
3239// o.u(0xe24cae93, 0xaedf93e2), o.u(0xab3e9573, 0x954d73ab),
3240// o.u(0x6297f553, 0xf5c45362), o.u(0x2a6b413f, 0x41543f2a),
3241// o.u(0x081c140c, 0x14100c08), o.u(0x9563f652, 0xf6315295),
3242// o.u(0x46e9af65, 0xaf8c6546), o.u(0x9d7fe25e, 0xe2215e9d),
3243// o.u(0x30487828, 0x78602830), o.u(0x37cff8a1, 0xf86ea137),
3244// o.u(0x0a1b110f, 0x11140f0a), o.u(0x2febc4b5, 0xc45eb52f),
3245// o.u(0x0e151b09, 0x1b1c090e), o.u(0x247e5a36, 0x5a483624),
3246// o.u(0x1badb69b, 0xb6369b1b), o.u(0xdf98473d, 0x47a53ddf),
3247// o.u(0xcda76a26, 0x6a8126cd), o.u(0x4ef5bb69, 0xbb9c694e),
3248// o.u(0x7f334ccd, 0x4cfecd7f), o.u(0xea50ba9f, 0xbacf9fea),
3249// o.u(0x123f2d1b, 0x2d241b12), o.u(0x1da4b99e, 0xb93a9e1d),
3250// o.u(0x58c49c74, 0x9cb07458), o.u(0x3446722e, 0x72682e34),
3251// o.u(0x3641772d, 0x776c2d36), o.u(0xdc11cdb2, 0xcda3b2dc),
3252// o.u(0xb49d29ee, 0x2973eeb4), o.u(0x5b4d16fb, 0x16b6fb5b),
3253// o.u(0xa4a501f6, 0x0153f6a4), o.u(0x76a1d74d, 0xd7ec4d76),
3254// o.u(0xb714a361, 0xa37561b7), o.u(0x7d3449ce, 0x49face7d),
3255// o.u(0x52df8d7b, 0x8da47b52), o.u(0xdd9f423e, 0x42a13edd),
3256// o.u(0x5ecd9371, 0x93bc715e), o.u(0x13b1a297, 0xa2269713),
3257// o.u(0xa6a204f5, 0x0457f5a6), o.u(0xb901b868, 0xb86968b9),
3258// o.u(0x00000000, 0x00000000), o.u(0xc1b5742c, 0x74992cc1),
3259// o.u(0x40e0a060, 0xa0806040), o.u(0xe3c2211f, 0x21dd1fe3),
3260// o.u(0x793a43c8, 0x43f2c879), o.u(0xb69a2ced, 0x2c77edb6),
3261// o.u(0xd40dd9be, 0xd9b3bed4), o.u(0x8d47ca46, 0xca01468d),
3262// o.u(0x671770d9, 0x70ced967), o.u(0x72afdd4b, 0xdde44b72),
3263// o.u(0x94ed79de, 0x7933de94), o.u(0x98ff67d4, 0x672bd498),
3264// o.u(0xb09323e8, 0x237be8b0), o.u(0x855bde4a, 0xde114a85),
3265// o.u(0xbb06bd6b, 0xbd6d6bbb), o.u(0xc5bb7e2a, 0x7e912ac5),
3266// o.u(0x4f7b34e5, 0x349ee54f), o.u(0xedd73a16, 0x3ac116ed),
3267// o.u(0x86d254c5, 0x5417c586), o.u(0x9af862d7, 0x622fd79a),
3268// o.u(0x6699ff55, 0xffcc5566), o.u(0x11b6a794, 0xa7229411),
3269// o.u(0x8ac04acf, 0x4a0fcf8a), o.u(0xe9d93010, 0x30c910e9),
3270// o.u(0x040e0a06, 0x0a080604), o.u(0xfe669881, 0x98e781fe),
3271// o.u(0xa0ab0bf0, 0x0b5bf0a0), o.u(0x78b4cc44, 0xccf04478),
3272// o.u(0x25f0d5ba, 0xd54aba25), o.u(0x4b753ee3, 0x3e96e34b),
3273// o.u(0xa2ac0ef3, 0x0e5ff3a2), o.u(0x5d4419fe, 0x19bafe5d),
3274// o.u(0x80db5bc0, 0x5b1bc080), o.u(0x0580858a, 0x850a8a05),
3275// o.u(0x3fd3ecad, 0xec7ead3f), o.u(0x21fedfbc, 0xdf42bc21),
3276// o.u(0x70a8d848, 0xd8e04870), o.u(0xf1fd0c04, 0x0cf904f1),
3277// o.u(0x63197adf, 0x7ac6df63), o.u(0x772f58c1, 0x58eec177),
3278// o.u(0xaf309f75, 0x9f4575af), o.u(0x42e7a563, 0xa5846342),
3279// o.u(0x20705030, 0x50403020), o.u(0xe5cb2e1a, 0x2ed11ae5),
3280// o.u(0xfdef120e, 0x12e10efd), o.u(0xbf08b76d, 0xb7656dbf),
3281// o.u(0x8155d44c, 0xd4194c81), o.u(0x18243c14, 0x3c301418),
3282// o.u(0x26795f35, 0x5f4c3526), o.u(0xc3b2712f, 0x719d2fc3),
3283// o.u(0xbe8638e1, 0x3867e1be), o.u(0x35c8fda2, 0xfd6aa235),
3284// o.u(0x88c74fcc, 0x4f0bcc88), o.u(0x2e654b39, 0x4b5c392e),
3285// o.u(0x936af957, 0xf93d5793), o.u(0x55580df2, 0x0daaf255),
3286// o.u(0xfc619d82, 0x9de382fc), o.u(0x7ab3c947, 0xc9f4477a),
3287// o.u(0xc827efac, 0xef8bacc8), o.u(0xba8832e7, 0x326fe7ba),
3288// o.u(0x324f7d2b, 0x7d642b32), o.u(0xe642a495, 0xa4d795e6),
3289// o.u(0xc03bfba0, 0xfb9ba0c0), o.u(0x19aab398, 0xb3329819),
3290// o.u(0x9ef668d1, 0x6827d19e), o.u(0xa322817f, 0x815d7fa3),
3291// o.u(0x44eeaa66, 0xaa886644), o.u(0x54d6827e, 0x82a87e54),
3292// o.u(0x3bdde6ab, 0xe676ab3b), o.u(0x0b959e83, 0x9e16830b),
3293// o.u(0x8cc945ca, 0x4503ca8c), o.u(0xc7bc7b29, 0x7b9529c7),
3294// o.u(0x6b056ed3, 0x6ed6d36b), o.u(0x286c443c, 0x44503c28),
3295// o.u(0xa72c8b79, 0x8b5579a7), o.u(0xbc813de2, 0x3d63e2bc),
3296// o.u(0x1631271d, 0x272c1d16), o.u(0xad379a76, 0x9a4176ad),
3297// o.u(0xdb964d3b, 0x4dad3bdb), o.u(0x649efa56, 0xfac85664),
3298// o.u(0x74a6d24e, 0xd2e84e74), o.u(0x1436221e, 0x22281e14),
3299// o.u(0x92e476db, 0x763fdb92), o.u(0x0c121e0a, 0x1e180a0c),
3300// o.u(0x48fcb46c, 0xb4906c48), o.u(0xb88f37e4, 0x376be4b8),
3301// o.u(0x9f78e75d, 0xe7255d9f), o.u(0xbd0fb26e, 0xb2616ebd),
3302// o.u(0x43692aef, 0x2a86ef43), o.u(0xc435f1a6, 0xf193a6c4),
3303// o.u(0x39dae3a8, 0xe372a839), o.u(0x31c6f7a4, 0xf762a431),
3304// o.u(0xd38a5937, 0x59bd37d3), o.u(0xf274868b, 0x86ff8bf2),
3305// o.u(0xd5835632, 0x56b132d5), o.u(0x8b4ec543, 0xc50d438b),
3306// o.u(0x6e85eb59, 0xebdc596e), o.u(0xda18c2b7, 0xc2afb7da),
3307// o.u(0x018e8f8c, 0x8f028c01), o.u(0xb11dac64, 0xac7964b1),
3308// o.u(0x9cf16dd2, 0x6d23d29c), o.u(0x49723be0, 0x3b92e049),
3309// o.u(0xd81fc7b4, 0xc7abb4d8), o.u(0xacb915fa, 0x1543faac),
3310// o.u(0xf3fa0907, 0x09fd07f3), o.u(0xcfa06f25, 0x6f8525cf),
3311// o.u(0xca20eaaf, 0xea8fafca), o.u(0xf47d898e, 0x89f38ef4),
3312// o.u(0x476720e9, 0x208ee947), o.u(0x10382818, 0x28201810),
3313// o.u(0x6f0b64d5, 0x64ded56f), o.u(0xf0738388, 0x83fb88f0),
3314// o.u(0x4afbb16f, 0xb1946f4a), o.u(0x5cca9672, 0x96b8725c),
3315// o.u(0x38546c24, 0x6c702438), o.u(0x575f08f1, 0x08aef157),
3316// o.u(0x732152c7, 0x52e6c773), o.u(0x9764f351, 0xf3355197),
3317// o.u(0xcbae6523, 0x658d23cb), o.u(0xa125847c, 0x84597ca1),
3318// o.u(0xe857bf9c, 0xbfcb9ce8), o.u(0x3e5d6321, 0x637c213e),
3319// o.u(0x96ea7cdd, 0x7c37dd96), o.u(0x611e7fdc, 0x7fc2dc61),
3320// o.u(0x0d9c9186, 0x911a860d), o.u(0x0f9b9485, 0x941e850f),
3321// o.u(0xe04bab90, 0xabdb90e0), o.u(0x7cbac642, 0xc6f8427c),
3322// o.u(0x712657c4, 0x57e2c471), o.u(0xcc29e5aa, 0xe583aacc),
3323// o.u(0x90e373d8, 0x733bd890), o.u(0x06090f05, 0x0f0c0506),
3324// o.u(0xf7f40301, 0x03f501f7), o.u(0x1c2a3612, 0x3638121c),
3325// o.u(0xc23cfea3, 0xfe9fa3c2), o.u(0x6a8be15f, 0xe1d45f6a),
3326// o.u(0xaebe10f9, 0x1047f9ae), o.u(0x69026bd0, 0x6bd2d069),
3327// o.u(0x17bfa891, 0xa82e9117), o.u(0x9971e858, 0xe8295899),
3328// o.u(0x3a536927, 0x6974273a), o.u(0x27f7d0b9, 0xd04eb927),
3329// o.u(0xd9914838, 0x48a938d9), o.u(0xebde3513, 0x35cd13eb),
3330// o.u(0x2be5ceb3, 0xce56b32b), o.u(0x22775533, 0x55443322),
3331// o.u(0xd204d6bb, 0xd6bfbbd2), o.u(0xa9399070, 0x904970a9),
3332// o.u(0x07878089, 0x800e8907), o.u(0x33c1f2a7, 0xf266a733),
3333// o.u(0x2decc1b6, 0xc15ab62d), o.u(0x3c5a6622, 0x6678223c),
3334// o.u(0x15b8ad92, 0xad2a9215), o.u(0xc9a96020, 0x608920c9),
3335// o.u(0x875cdb49, 0xdb154987), o.u(0xaab01aff, 0x1a4fffaa),
3336// o.u(0x50d88878, 0x88a07850), o.u(0xa52b8e7a, 0x8e517aa5),
3337// o.u(0x03898a8f, 0x8a068f03), o.u(0x594a13f8, 0x13b2f859),
3338// o.u(0x09929b80, 0x9b128009), o.u(0x1a233917, 0x3934171a),
3339// o.u(0x651075da, 0x75cada65), o.u(0xd7845331, 0x53b531d7),
3340// o.u(0x84d551c6, 0x5113c684), o.u(0xd003d3b8, 0xd3bbb8d0),
3341// o.u(0x82dc5ec3, 0x5e1fc382), o.u(0x29e2cbb0, 0xcb52b029),
3342// o.u(0x5ac39977, 0x99b4775a), o.u(0x1e2d3311, 0x333c111e),
3343// o.u(0x7b3d46cb, 0x46f6cb7b), o.u(0xa8b71ffc, 0x1f4bfca8),
3344// o.u(0x6d0c61d6, 0x61dad66d), o.u(0x2c624e3a, 0x4e583a2c)
3345// ];
3346
3347// var T1 = [
3348// o.u(0xc6c632f4, 0xa5f497a5), o.u(0xf8f86f97, 0x8497eb84),
3349// o.u(0xeeee5eb0, 0x99b0c799), o.u(0xf6f67a8c, 0x8d8cf78d),
3350// o.u(0xffffe817, 0xd17e50d), o.u(0xd6d60adc, 0xbddcb7bd),
3351// o.u(0xdede16c8, 0xb1c8a7b1), o.u(0x91916dfc, 0x54fc3954),
3352// o.u(0x606090f0, 0x50f0c050), o.u(0x2020705, 0x3050403),
3353// o.u(0xcece2ee0, 0xa9e087a9), o.u(0x5656d187, 0x7d87ac7d),
3354// o.u(0xe7e7cc2b, 0x192bd519), o.u(0xb5b513a6, 0x62a67162),
3355// o.u(0x4d4d7c31, 0xe6319ae6), o.u(0xecec59b5, 0x9ab5c39a),
3356// o.u(0x8f8f40cf, 0x45cf0545), o.u(0x1f1fa3bc, 0x9dbc3e9d),
3357// o.u(0x898949c0, 0x40c00940), o.u(0xfafa6892, 0x8792ef87),
3358// o.u(0xefefd03f, 0x153fc515), o.u(0xb2b29426, 0xeb267feb),
3359// o.u(0x8e8ece40, 0xc94007c9), o.u(0xfbfbe61d, 0xb1ded0b),
3360// o.u(0x41416e2f, 0xec2f82ec), o.u(0xb3b31aa9, 0x67a97d67),
3361// o.u(0x5f5f431c, 0xfd1cbefd), o.u(0x45456025, 0xea258aea),
3362// o.u(0x2323f9da, 0xbfda46bf), o.u(0x53535102, 0xf702a6f7),
3363// o.u(0xe4e445a1, 0x96a1d396), o.u(0x9b9b76ed, 0x5bed2d5b),
3364// o.u(0x7575285d, 0xc25deac2), o.u(0xe1e1c524, 0x1c24d91c),
3365// o.u(0x3d3dd4e9, 0xaee97aae), o.u(0x4c4cf2be, 0x6abe986a),
3366// o.u(0x6c6c82ee, 0x5aeed85a), o.u(0x7e7ebdc3, 0x41c3fc41),
3367// o.u(0xf5f5f306, 0x206f102), o.u(0x838352d1, 0x4fd11d4f),
3368// o.u(0x68688ce4, 0x5ce4d05c), o.u(0x51515607, 0xf407a2f4),
3369// o.u(0xd1d18d5c, 0x345cb934), o.u(0xf9f9e118, 0x818e908),
3370// o.u(0xe2e24cae, 0x93aedf93), o.u(0xabab3e95, 0x73954d73),
3371// o.u(0x626297f5, 0x53f5c453), o.u(0x2a2a6b41, 0x3f41543f),
3372// o.u(0x8081c14, 0xc14100c), o.u(0x959563f6, 0x52f63152),
3373// o.u(0x4646e9af, 0x65af8c65), o.u(0x9d9d7fe2, 0x5ee2215e),
3374// o.u(0x30304878, 0x28786028), o.u(0x3737cff8, 0xa1f86ea1),
3375// o.u(0xa0a1b11, 0xf11140f), o.u(0x2f2febc4, 0xb5c45eb5),
3376// o.u(0xe0e151b, 0x91b1c09), o.u(0x24247e5a, 0x365a4836),
3377// o.u(0x1b1badb6, 0x9bb6369b), o.u(0xdfdf9847, 0x3d47a53d),
3378// o.u(0xcdcda76a, 0x266a8126), o.u(0x4e4ef5bb, 0x69bb9c69),
3379// o.u(0x7f7f334c, 0xcd4cfecd), o.u(0xeaea50ba, 0x9fbacf9f),
3380// o.u(0x12123f2d, 0x1b2d241b), o.u(0x1d1da4b9, 0x9eb93a9e),
3381// o.u(0x5858c49c, 0x749cb074), o.u(0x34344672, 0x2e72682e),
3382// o.u(0x36364177, 0x2d776c2d), o.u(0xdcdc11cd, 0xb2cda3b2),
3383// o.u(0xb4b49d29, 0xee2973ee), o.u(0x5b5b4d16, 0xfb16b6fb),
3384// o.u(0xa4a4a501, 0xf60153f6), o.u(0x7676a1d7, 0x4dd7ec4d),
3385// o.u(0xb7b714a3, 0x61a37561), o.u(0x7d7d3449, 0xce49face),
3386// o.u(0x5252df8d, 0x7b8da47b), o.u(0xdddd9f42, 0x3e42a13e),
3387// o.u(0x5e5ecd93, 0x7193bc71), o.u(0x1313b1a2, 0x97a22697),
3388// o.u(0xa6a6a204, 0xf50457f5), o.u(0xb9b901b8, 0x68b86968),
3389// o.u(0x0, 0x0), o.u(0xc1c1b574, 0x2c74992c),
3390// o.u(0x4040e0a0, 0x60a08060), o.u(0xe3e3c221, 0x1f21dd1f),
3391// o.u(0x79793a43, 0xc843f2c8), o.u(0xb6b69a2c, 0xed2c77ed),
3392// o.u(0xd4d40dd9, 0xbed9b3be), o.u(0x8d8d47ca, 0x46ca0146),
3393// o.u(0x67671770, 0xd970ced9), o.u(0x7272afdd, 0x4bdde44b),
3394// o.u(0x9494ed79, 0xde7933de), o.u(0x9898ff67, 0xd4672bd4),
3395// o.u(0xb0b09323, 0xe8237be8), o.u(0x85855bde, 0x4ade114a),
3396// o.u(0xbbbb06bd, 0x6bbd6d6b), o.u(0xc5c5bb7e, 0x2a7e912a),
3397// o.u(0x4f4f7b34, 0xe5349ee5), o.u(0xededd73a, 0x163ac116),
3398// o.u(0x8686d254, 0xc55417c5), o.u(0x9a9af862, 0xd7622fd7),
3399// o.u(0x666699ff, 0x55ffcc55), o.u(0x1111b6a7, 0x94a72294),
3400// o.u(0x8a8ac04a, 0xcf4a0fcf), o.u(0xe9e9d930, 0x1030c910),
3401// o.u(0x4040e0a, 0x60a0806), o.u(0xfefe6698, 0x8198e781),
3402// o.u(0xa0a0ab0b, 0xf00b5bf0), o.u(0x7878b4cc, 0x44ccf044),
3403// o.u(0x2525f0d5, 0xbad54aba), o.u(0x4b4b753e, 0xe33e96e3),
3404// o.u(0xa2a2ac0e, 0xf30e5ff3), o.u(0x5d5d4419, 0xfe19bafe),
3405// o.u(0x8080db5b, 0xc05b1bc0), o.u(0x5058085, 0x8a850a8a),
3406// o.u(0x3f3fd3ec, 0xadec7ead), o.u(0x2121fedf, 0xbcdf42bc),
3407// o.u(0x7070a8d8, 0x48d8e048), o.u(0xf1f1fd0c, 0x40cf904),
3408// o.u(0x6363197a, 0xdf7ac6df), o.u(0x77772f58, 0xc158eec1),
3409// o.u(0xafaf309f, 0x759f4575), o.u(0x4242e7a5, 0x63a58463),
3410// o.u(0x20207050, 0x30504030), o.u(0xe5e5cb2e, 0x1a2ed11a),
3411// o.u(0xfdfdef12, 0xe12e10e), o.u(0xbfbf08b7, 0x6db7656d),
3412// o.u(0x818155d4, 0x4cd4194c), o.u(0x1818243c, 0x143c3014),
3413// o.u(0x2626795f, 0x355f4c35), o.u(0xc3c3b271, 0x2f719d2f),
3414// o.u(0xbebe8638, 0xe13867e1), o.u(0x3535c8fd, 0xa2fd6aa2),
3415// o.u(0x8888c74f, 0xcc4f0bcc), o.u(0x2e2e654b, 0x394b5c39),
3416// o.u(0x93936af9, 0x57f93d57), o.u(0x5555580d, 0xf20daaf2),
3417// o.u(0xfcfc619d, 0x829de382), o.u(0x7a7ab3c9, 0x47c9f447),
3418// o.u(0xc8c827ef, 0xacef8bac), o.u(0xbaba8832, 0xe7326fe7),
3419// o.u(0x32324f7d, 0x2b7d642b), o.u(0xe6e642a4, 0x95a4d795),
3420// o.u(0xc0c03bfb, 0xa0fb9ba0), o.u(0x1919aab3, 0x98b33298),
3421// o.u(0x9e9ef668, 0xd16827d1), o.u(0xa3a32281, 0x7f815d7f),
3422// o.u(0x4444eeaa, 0x66aa8866), o.u(0x5454d682, 0x7e82a87e),
3423// o.u(0x3b3bdde6, 0xabe676ab), o.u(0xb0b959e, 0x839e1683),
3424// o.u(0x8c8cc945, 0xca4503ca), o.u(0xc7c7bc7b, 0x297b9529),
3425// o.u(0x6b6b056e, 0xd36ed6d3), o.u(0x28286c44, 0x3c44503c),
3426// o.u(0xa7a72c8b, 0x798b5579), o.u(0xbcbc813d, 0xe23d63e2),
3427// o.u(0x16163127, 0x1d272c1d), o.u(0xadad379a, 0x769a4176),
3428// o.u(0xdbdb964d, 0x3b4dad3b), o.u(0x64649efa, 0x56fac856),
3429// o.u(0x7474a6d2, 0x4ed2e84e), o.u(0x14143622, 0x1e22281e),
3430// o.u(0x9292e476, 0xdb763fdb), o.u(0xc0c121e, 0xa1e180a),
3431// o.u(0x4848fcb4, 0x6cb4906c), o.u(0xb8b88f37, 0xe4376be4),
3432// o.u(0x9f9f78e7, 0x5de7255d), o.u(0xbdbd0fb2, 0x6eb2616e),
3433// o.u(0x4343692a, 0xef2a86ef), o.u(0xc4c435f1, 0xa6f193a6),
3434// o.u(0x3939dae3, 0xa8e372a8), o.u(0x3131c6f7, 0xa4f762a4),
3435// o.u(0xd3d38a59, 0x3759bd37), o.u(0xf2f27486, 0x8b86ff8b),
3436// o.u(0xd5d58356, 0x3256b132), o.u(0x8b8b4ec5, 0x43c50d43),
3437// o.u(0x6e6e85eb, 0x59ebdc59), o.u(0xdada18c2, 0xb7c2afb7),
3438// o.u(0x1018e8f, 0x8c8f028c), o.u(0xb1b11dac, 0x64ac7964),
3439// o.u(0x9c9cf16d, 0xd26d23d2), o.u(0x4949723b, 0xe03b92e0),
3440// o.u(0xd8d81fc7, 0xb4c7abb4), o.u(0xacacb915, 0xfa1543fa),
3441// o.u(0xf3f3fa09, 0x709fd07), o.u(0xcfcfa06f, 0x256f8525),
3442// o.u(0xcaca20ea, 0xafea8faf), o.u(0xf4f47d89, 0x8e89f38e),
3443// o.u(0x47476720, 0xe9208ee9), o.u(0x10103828, 0x18282018),
3444// o.u(0x6f6f0b64, 0xd564ded5), o.u(0xf0f07383, 0x8883fb88),
3445// o.u(0x4a4afbb1, 0x6fb1946f), o.u(0x5c5cca96, 0x7296b872),
3446// o.u(0x3838546c, 0x246c7024), o.u(0x57575f08, 0xf108aef1),
3447// o.u(0x73732152, 0xc752e6c7), o.u(0x979764f3, 0x51f33551),
3448// o.u(0xcbcbae65, 0x23658d23), o.u(0xa1a12584, 0x7c84597c),
3449// o.u(0xe8e857bf, 0x9cbfcb9c), o.u(0x3e3e5d63, 0x21637c21),
3450// o.u(0x9696ea7c, 0xdd7c37dd), o.u(0x61611e7f, 0xdc7fc2dc),
3451// o.u(0xd0d9c91, 0x86911a86), o.u(0xf0f9b94, 0x85941e85),
3452// o.u(0xe0e04bab, 0x90abdb90), o.u(0x7c7cbac6, 0x42c6f842),
3453// o.u(0x71712657, 0xc457e2c4), o.u(0xcccc29e5, 0xaae583aa),
3454// o.u(0x9090e373, 0xd8733bd8), o.u(0x606090f, 0x50f0c05),
3455// o.u(0xf7f7f403, 0x103f501), o.u(0x1c1c2a36, 0x12363812),
3456// o.u(0xc2c23cfe, 0xa3fe9fa3), o.u(0x6a6a8be1, 0x5fe1d45f),
3457// o.u(0xaeaebe10, 0xf91047f9), o.u(0x6969026b, 0xd06bd2d0),
3458// o.u(0x1717bfa8, 0x91a82e91), o.u(0x999971e8, 0x58e82958),
3459// o.u(0x3a3a5369, 0x27697427), o.u(0x2727f7d0, 0xb9d04eb9),
3460// o.u(0xd9d99148, 0x3848a938), o.u(0xebebde35, 0x1335cd13),
3461// o.u(0x2b2be5ce, 0xb3ce56b3), o.u(0x22227755, 0x33554433),
3462// o.u(0xd2d204d6, 0xbbd6bfbb), o.u(0xa9a93990, 0x70904970),
3463// o.u(0x7078780, 0x89800e89), o.u(0x3333c1f2, 0xa7f266a7),
3464// o.u(0x2d2decc1, 0xb6c15ab6), o.u(0x3c3c5a66, 0x22667822),
3465// o.u(0x1515b8ad, 0x92ad2a92), o.u(0xc9c9a960, 0x20608920),
3466// o.u(0x87875cdb, 0x49db1549), o.u(0xaaaab01a, 0xff1a4fff),
3467// o.u(0x5050d888, 0x7888a078), o.u(0xa5a52b8e, 0x7a8e517a),
3468// o.u(0x303898a, 0x8f8a068f), o.u(0x59594a13, 0xf813b2f8),
3469// o.u(0x909929b, 0x809b1280), o.u(0x1a1a2339, 0x17393417),
3470// o.u(0x65651075, 0xda75cada), o.u(0xd7d78453, 0x3153b531),
3471// o.u(0x8484d551, 0xc65113c6), o.u(0xd0d003d3, 0xb8d3bbb8),
3472// o.u(0x8282dc5e, 0xc35e1fc3), o.u(0x2929e2cb, 0xb0cb52b0),
3473// o.u(0x5a5ac399, 0x7799b477), o.u(0x1e1e2d33, 0x11333c11),
3474// o.u(0x7b7b3d46, 0xcb46f6cb), o.u(0xa8a8b71f, 0xfc1f4bfc),
3475// o.u(0x6d6d0c61, 0xd661dad6), o.u(0x2c2c624e, 0x3a4e583a)
3476// ];
3477
3478// var T2 = [
3479// o.u(0xa5c6c632, 0xf4a5f497), o.u(0x84f8f86f, 0x978497eb),
3480// o.u(0x99eeee5e, 0xb099b0c7), o.u(0x8df6f67a, 0x8c8d8cf7),
3481// o.u(0xdffffe8, 0x170d17e5), o.u(0xbdd6d60a, 0xdcbddcb7),
3482// o.u(0xb1dede16, 0xc8b1c8a7), o.u(0x5491916d, 0xfc54fc39),
3483// o.u(0x50606090, 0xf050f0c0), o.u(0x3020207, 0x5030504),
3484// o.u(0xa9cece2e, 0xe0a9e087), o.u(0x7d5656d1, 0x877d87ac),
3485// o.u(0x19e7e7cc, 0x2b192bd5), o.u(0x62b5b513, 0xa662a671),
3486// o.u(0xe64d4d7c, 0x31e6319a), o.u(0x9aecec59, 0xb59ab5c3),
3487// o.u(0x458f8f40, 0xcf45cf05), o.u(0x9d1f1fa3, 0xbc9dbc3e),
3488// o.u(0x40898949, 0xc040c009), o.u(0x87fafa68, 0x928792ef),
3489// o.u(0x15efefd0, 0x3f153fc5), o.u(0xebb2b294, 0x26eb267f),
3490// o.u(0xc98e8ece, 0x40c94007), o.u(0xbfbfbe6, 0x1d0b1ded),
3491// o.u(0xec41416e, 0x2fec2f82), o.u(0x67b3b31a, 0xa967a97d),
3492// o.u(0xfd5f5f43, 0x1cfd1cbe), o.u(0xea454560, 0x25ea258a),
3493// o.u(0xbf2323f9, 0xdabfda46), o.u(0xf7535351, 0x2f702a6),
3494// o.u(0x96e4e445, 0xa196a1d3), o.u(0x5b9b9b76, 0xed5bed2d),
3495// o.u(0xc2757528, 0x5dc25dea), o.u(0x1ce1e1c5, 0x241c24d9),
3496// o.u(0xae3d3dd4, 0xe9aee97a), o.u(0x6a4c4cf2, 0xbe6abe98),
3497// o.u(0x5a6c6c82, 0xee5aeed8), o.u(0x417e7ebd, 0xc341c3fc),
3498// o.u(0x2f5f5f3, 0x60206f1), o.u(0x4f838352, 0xd14fd11d),
3499// o.u(0x5c68688c, 0xe45ce4d0), o.u(0xf4515156, 0x7f407a2),
3500// o.u(0x34d1d18d, 0x5c345cb9), o.u(0x8f9f9e1, 0x180818e9),
3501// o.u(0x93e2e24c, 0xae93aedf), o.u(0x73abab3e, 0x9573954d),
3502// o.u(0x53626297, 0xf553f5c4), o.u(0x3f2a2a6b, 0x413f4154),
3503// o.u(0xc08081c, 0x140c1410), o.u(0x52959563, 0xf652f631),
3504// o.u(0x654646e9, 0xaf65af8c), o.u(0x5e9d9d7f, 0xe25ee221),
3505// o.u(0x28303048, 0x78287860), o.u(0xa13737cf, 0xf8a1f86e),
3506// o.u(0xf0a0a1b, 0x110f1114), o.u(0xb52f2feb, 0xc4b5c45e),
3507// o.u(0x90e0e15, 0x1b091b1c), o.u(0x3624247e, 0x5a365a48),
3508// o.u(0x9b1b1bad, 0xb69bb636), o.u(0x3ddfdf98, 0x473d47a5),
3509// o.u(0x26cdcda7, 0x6a266a81), o.u(0x694e4ef5, 0xbb69bb9c),
3510// o.u(0xcd7f7f33, 0x4ccd4cfe), o.u(0x9feaea50, 0xba9fbacf),
3511// o.u(0x1b12123f, 0x2d1b2d24), o.u(0x9e1d1da4, 0xb99eb93a),
3512// o.u(0x745858c4, 0x9c749cb0), o.u(0x2e343446, 0x722e7268),
3513// o.u(0x2d363641, 0x772d776c), o.u(0xb2dcdc11, 0xcdb2cda3),
3514// o.u(0xeeb4b49d, 0x29ee2973), o.u(0xfb5b5b4d, 0x16fb16b6),
3515// o.u(0xf6a4a4a5, 0x1f60153), o.u(0x4d7676a1, 0xd74dd7ec),
3516// o.u(0x61b7b714, 0xa361a375), o.u(0xce7d7d34, 0x49ce49fa),
3517// o.u(0x7b5252df, 0x8d7b8da4), o.u(0x3edddd9f, 0x423e42a1),
3518// o.u(0x715e5ecd, 0x937193bc), o.u(0x971313b1, 0xa297a226),
3519// o.u(0xf5a6a6a2, 0x4f50457), o.u(0x68b9b901, 0xb868b869),
3520// o.u(0x0, 0x0), o.u(0x2cc1c1b5, 0x742c7499),
3521// o.u(0x604040e0, 0xa060a080), o.u(0x1fe3e3c2, 0x211f21dd),
3522// o.u(0xc879793a, 0x43c843f2), o.u(0xedb6b69a, 0x2ced2c77),
3523// o.u(0xbed4d40d, 0xd9bed9b3), o.u(0x468d8d47, 0xca46ca01),
3524// o.u(0xd9676717, 0x70d970ce), o.u(0x4b7272af, 0xdd4bdde4),
3525// o.u(0xde9494ed, 0x79de7933), o.u(0xd49898ff, 0x67d4672b),
3526// o.u(0xe8b0b093, 0x23e8237b), o.u(0x4a85855b, 0xde4ade11),
3527// o.u(0x6bbbbb06, 0xbd6bbd6d), o.u(0x2ac5c5bb, 0x7e2a7e91),
3528// o.u(0xe54f4f7b, 0x34e5349e), o.u(0x16ededd7, 0x3a163ac1),
3529// o.u(0xc58686d2, 0x54c55417), o.u(0xd79a9af8, 0x62d7622f),
3530// o.u(0x55666699, 0xff55ffcc), o.u(0x941111b6, 0xa794a722),
3531// o.u(0xcf8a8ac0, 0x4acf4a0f), o.u(0x10e9e9d9, 0x301030c9),
3532// o.u(0x604040e, 0xa060a08), o.u(0x81fefe66, 0x988198e7),
3533// o.u(0xf0a0a0ab, 0xbf00b5b), o.u(0x447878b4, 0xcc44ccf0),
3534// o.u(0xba2525f0, 0xd5bad54a), o.u(0xe34b4b75, 0x3ee33e96),
3535// o.u(0xf3a2a2ac, 0xef30e5f), o.u(0xfe5d5d44, 0x19fe19ba),
3536// o.u(0xc08080db, 0x5bc05b1b), o.u(0x8a050580, 0x858a850a),
3537// o.u(0xad3f3fd3, 0xecadec7e), o.u(0xbc2121fe, 0xdfbcdf42),
3538// o.u(0x487070a8, 0xd848d8e0), o.u(0x4f1f1fd, 0xc040cf9),
3539// o.u(0xdf636319, 0x7adf7ac6), o.u(0xc177772f, 0x58c158ee),
3540// o.u(0x75afaf30, 0x9f759f45), o.u(0x634242e7, 0xa563a584),
3541// o.u(0x30202070, 0x50305040), o.u(0x1ae5e5cb, 0x2e1a2ed1),
3542// o.u(0xefdfdef, 0x120e12e1), o.u(0x6dbfbf08, 0xb76db765),
3543// o.u(0x4c818155, 0xd44cd419), o.u(0x14181824, 0x3c143c30),
3544// o.u(0x35262679, 0x5f355f4c), o.u(0x2fc3c3b2, 0x712f719d),
3545// o.u(0xe1bebe86, 0x38e13867), o.u(0xa23535c8, 0xfda2fd6a),
3546// o.u(0xcc8888c7, 0x4fcc4f0b), o.u(0x392e2e65, 0x4b394b5c),
3547// o.u(0x5793936a, 0xf957f93d), o.u(0xf2555558, 0xdf20daa),
3548// o.u(0x82fcfc61, 0x9d829de3), o.u(0x477a7ab3, 0xc947c9f4),
3549// o.u(0xacc8c827, 0xefacef8b), o.u(0xe7baba88, 0x32e7326f),
3550// o.u(0x2b32324f, 0x7d2b7d64), o.u(0x95e6e642, 0xa495a4d7),
3551// o.u(0xa0c0c03b, 0xfba0fb9b), o.u(0x981919aa, 0xb398b332),
3552// o.u(0xd19e9ef6, 0x68d16827), o.u(0x7fa3a322, 0x817f815d),
3553// o.u(0x664444ee, 0xaa66aa88), o.u(0x7e5454d6, 0x827e82a8),
3554// o.u(0xab3b3bdd, 0xe6abe676), o.u(0x830b0b95, 0x9e839e16),
3555// o.u(0xca8c8cc9, 0x45ca4503), o.u(0x29c7c7bc, 0x7b297b95),
3556// o.u(0xd36b6b05, 0x6ed36ed6), o.u(0x3c28286c, 0x443c4450),
3557// o.u(0x79a7a72c, 0x8b798b55), o.u(0xe2bcbc81, 0x3de23d63),
3558// o.u(0x1d161631, 0x271d272c), o.u(0x76adad37, 0x9a769a41),
3559// o.u(0x3bdbdb96, 0x4d3b4dad), o.u(0x5664649e, 0xfa56fac8),
3560// o.u(0x4e7474a6, 0xd24ed2e8), o.u(0x1e141436, 0x221e2228),
3561// o.u(0xdb9292e4, 0x76db763f), o.u(0xa0c0c12, 0x1e0a1e18),
3562// o.u(0x6c4848fc, 0xb46cb490), o.u(0xe4b8b88f, 0x37e4376b),
3563// o.u(0x5d9f9f78, 0xe75de725), o.u(0x6ebdbd0f, 0xb26eb261),
3564// o.u(0xef434369, 0x2aef2a86), o.u(0xa6c4c435, 0xf1a6f193),
3565// o.u(0xa83939da, 0xe3a8e372), o.u(0xa43131c6, 0xf7a4f762),
3566// o.u(0x37d3d38a, 0x593759bd), o.u(0x8bf2f274, 0x868b86ff),
3567// o.u(0x32d5d583, 0x563256b1), o.u(0x438b8b4e, 0xc543c50d),
3568// o.u(0x596e6e85, 0xeb59ebdc), o.u(0xb7dada18, 0xc2b7c2af),
3569// o.u(0x8c01018e, 0x8f8c8f02), o.u(0x64b1b11d, 0xac64ac79),
3570// o.u(0xd29c9cf1, 0x6dd26d23), o.u(0xe0494972, 0x3be03b92),
3571// o.u(0xb4d8d81f, 0xc7b4c7ab), o.u(0xfaacacb9, 0x15fa1543),
3572// o.u(0x7f3f3fa, 0x90709fd), o.u(0x25cfcfa0, 0x6f256f85),
3573// o.u(0xafcaca20, 0xeaafea8f), o.u(0x8ef4f47d, 0x898e89f3),
3574// o.u(0xe9474767, 0x20e9208e), o.u(0x18101038, 0x28182820),
3575// o.u(0xd56f6f0b, 0x64d564de), o.u(0x88f0f073, 0x838883fb),
3576// o.u(0x6f4a4afb, 0xb16fb194), o.u(0x725c5cca, 0x967296b8),
3577// o.u(0x24383854, 0x6c246c70), o.u(0xf157575f, 0x8f108ae),
3578// o.u(0xc7737321, 0x52c752e6), o.u(0x51979764, 0xf351f335),
3579// o.u(0x23cbcbae, 0x6523658d), o.u(0x7ca1a125, 0x847c8459),
3580// o.u(0x9ce8e857, 0xbf9cbfcb), o.u(0x213e3e5d, 0x6321637c),
3581// o.u(0xdd9696ea, 0x7cdd7c37), o.u(0xdc61611e, 0x7fdc7fc2),
3582// o.u(0x860d0d9c, 0x9186911a), o.u(0x850f0f9b, 0x9485941e),
3583// o.u(0x90e0e04b, 0xab90abdb), o.u(0x427c7cba, 0xc642c6f8),
3584// o.u(0xc4717126, 0x57c457e2), o.u(0xaacccc29, 0xe5aae583),
3585// o.u(0xd89090e3, 0x73d8733b), o.u(0x5060609, 0xf050f0c),
3586// o.u(0x1f7f7f4, 0x30103f5), o.u(0x121c1c2a, 0x36123638),
3587// o.u(0xa3c2c23c, 0xfea3fe9f), o.u(0x5f6a6a8b, 0xe15fe1d4),
3588// o.u(0xf9aeaebe, 0x10f91047), o.u(0xd0696902, 0x6bd06bd2),
3589// o.u(0x911717bf, 0xa891a82e), o.u(0x58999971, 0xe858e829),
3590// o.u(0x273a3a53, 0x69276974), o.u(0xb92727f7, 0xd0b9d04e),
3591// o.u(0x38d9d991, 0x483848a9), o.u(0x13ebebde, 0x351335cd),
3592// o.u(0xb32b2be5, 0xceb3ce56), o.u(0x33222277, 0x55335544),
3593// o.u(0xbbd2d204, 0xd6bbd6bf), o.u(0x70a9a939, 0x90709049),
3594// o.u(0x89070787, 0x8089800e), o.u(0xa73333c1, 0xf2a7f266),
3595// o.u(0xb62d2dec, 0xc1b6c15a), o.u(0x223c3c5a, 0x66226678),
3596// o.u(0x921515b8, 0xad92ad2a), o.u(0x20c9c9a9, 0x60206089),
3597// o.u(0x4987875c, 0xdb49db15), o.u(0xffaaaab0, 0x1aff1a4f),
3598// o.u(0x785050d8, 0x887888a0), o.u(0x7aa5a52b, 0x8e7a8e51),
3599// o.u(0x8f030389, 0x8a8f8a06), o.u(0xf859594a, 0x13f813b2),
3600// o.u(0x80090992, 0x9b809b12), o.u(0x171a1a23, 0x39173934),
3601// o.u(0xda656510, 0x75da75ca), o.u(0x31d7d784, 0x533153b5),
3602// o.u(0xc68484d5, 0x51c65113), o.u(0xb8d0d003, 0xd3b8d3bb),
3603// o.u(0xc38282dc, 0x5ec35e1f), o.u(0xb02929e2, 0xcbb0cb52),
3604// o.u(0x775a5ac3, 0x997799b4), o.u(0x111e1e2d, 0x3311333c),
3605// o.u(0xcb7b7b3d, 0x46cb46f6), o.u(0xfca8a8b7, 0x1ffc1f4b),
3606// o.u(0xd66d6d0c, 0x61d661da), o.u(0x3a2c2c62, 0x4e3a4e58)
3607// ];
3608
3609// var T3 = [
3610// o.u(0x97a5c6c6, 0x32f4a5f4), o.u(0xeb84f8f8, 0x6f978497),
3611// o.u(0xc799eeee, 0x5eb099b0), o.u(0xf78df6f6, 0x7a8c8d8c),
3612// o.u(0xe50dffff, 0xe8170d17), o.u(0xb7bdd6d6, 0xadcbddc),
3613// o.u(0xa7b1dede, 0x16c8b1c8), o.u(0x39549191, 0x6dfc54fc),
3614// o.u(0xc0506060, 0x90f050f0), o.u(0x4030202, 0x7050305),
3615// o.u(0x87a9cece, 0x2ee0a9e0), o.u(0xac7d5656, 0xd1877d87),
3616// o.u(0xd519e7e7, 0xcc2b192b), o.u(0x7162b5b5, 0x13a662a6),
3617// o.u(0x9ae64d4d, 0x7c31e631), o.u(0xc39aecec, 0x59b59ab5),
3618// o.u(0x5458f8f, 0x40cf45cf), o.u(0x3e9d1f1f, 0xa3bc9dbc),
3619// o.u(0x9408989, 0x49c040c0), o.u(0xef87fafa, 0x68928792),
3620// o.u(0xc515efef, 0xd03f153f), o.u(0x7febb2b2, 0x9426eb26),
3621// o.u(0x7c98e8e, 0xce40c940), o.u(0xed0bfbfb, 0xe61d0b1d),
3622// o.u(0x82ec4141, 0x6e2fec2f), o.u(0x7d67b3b3, 0x1aa967a9),
3623// o.u(0xbefd5f5f, 0x431cfd1c), o.u(0x8aea4545, 0x6025ea25),
3624// o.u(0x46bf2323, 0xf9dabfda), o.u(0xa6f75353, 0x5102f702),
3625// o.u(0xd396e4e4, 0x45a196a1), o.u(0x2d5b9b9b, 0x76ed5bed),
3626// o.u(0xeac27575, 0x285dc25d), o.u(0xd91ce1e1, 0xc5241c24),
3627// o.u(0x7aae3d3d, 0xd4e9aee9), o.u(0x986a4c4c, 0xf2be6abe),
3628// o.u(0xd85a6c6c, 0x82ee5aee), o.u(0xfc417e7e, 0xbdc341c3),
3629// o.u(0xf102f5f5, 0xf3060206), o.u(0x1d4f8383, 0x52d14fd1),
3630// o.u(0xd05c6868, 0x8ce45ce4), o.u(0xa2f45151, 0x5607f407),
3631// o.u(0xb934d1d1, 0x8d5c345c), o.u(0xe908f9f9, 0xe1180818),
3632// o.u(0xdf93e2e2, 0x4cae93ae), o.u(0x4d73abab, 0x3e957395),
3633// o.u(0xc4536262, 0x97f553f5), o.u(0x543f2a2a, 0x6b413f41),
3634// o.u(0x100c0808, 0x1c140c14), o.u(0x31529595, 0x63f652f6),
3635// o.u(0x8c654646, 0xe9af65af), o.u(0x215e9d9d, 0x7fe25ee2),
3636// o.u(0x60283030, 0x48782878), o.u(0x6ea13737, 0xcff8a1f8),
3637// o.u(0x140f0a0a, 0x1b110f11), o.u(0x5eb52f2f, 0xebc4b5c4),
3638// o.u(0x1c090e0e, 0x151b091b), o.u(0x48362424, 0x7e5a365a),
3639// o.u(0x369b1b1b, 0xadb69bb6), o.u(0xa53ddfdf, 0x98473d47),
3640// o.u(0x8126cdcd, 0xa76a266a), o.u(0x9c694e4e, 0xf5bb69bb),
3641// o.u(0xfecd7f7f, 0x334ccd4c), o.u(0xcf9feaea, 0x50ba9fba),
3642// o.u(0x241b1212, 0x3f2d1b2d), o.u(0x3a9e1d1d, 0xa4b99eb9),
3643// o.u(0xb0745858, 0xc49c749c), o.u(0x682e3434, 0x46722e72),
3644// o.u(0x6c2d3636, 0x41772d77), o.u(0xa3b2dcdc, 0x11cdb2cd),
3645// o.u(0x73eeb4b4, 0x9d29ee29), o.u(0xb6fb5b5b, 0x4d16fb16),
3646// o.u(0x53f6a4a4, 0xa501f601), o.u(0xec4d7676, 0xa1d74dd7),
3647// o.u(0x7561b7b7, 0x14a361a3), o.u(0xface7d7d, 0x3449ce49),
3648// o.u(0xa47b5252, 0xdf8d7b8d), o.u(0xa13edddd, 0x9f423e42),
3649// o.u(0xbc715e5e, 0xcd937193), o.u(0x26971313, 0xb1a297a2),
3650// o.u(0x57f5a6a6, 0xa204f504), o.u(0x6968b9b9, 0x1b868b8),
3651// o.u(0x0, 0x0), o.u(0x992cc1c1, 0xb5742c74),
3652// o.u(0x80604040, 0xe0a060a0), o.u(0xdd1fe3e3, 0xc2211f21),
3653// o.u(0xf2c87979, 0x3a43c843), o.u(0x77edb6b6, 0x9a2ced2c),
3654// o.u(0xb3bed4d4, 0xdd9bed9), o.u(0x1468d8d, 0x47ca46ca),
3655// o.u(0xced96767, 0x1770d970), o.u(0xe44b7272, 0xafdd4bdd),
3656// o.u(0x33de9494, 0xed79de79), o.u(0x2bd49898, 0xff67d467),
3657// o.u(0x7be8b0b0, 0x9323e823), o.u(0x114a8585, 0x5bde4ade),
3658// o.u(0x6d6bbbbb, 0x6bd6bbd), o.u(0x912ac5c5, 0xbb7e2a7e),
3659// o.u(0x9ee54f4f, 0x7b34e534), o.u(0xc116eded, 0xd73a163a),
3660// o.u(0x17c58686, 0xd254c554), o.u(0x2fd79a9a, 0xf862d762),
3661// o.u(0xcc556666, 0x99ff55ff), o.u(0x22941111, 0xb6a794a7),
3662// o.u(0xfcf8a8a, 0xc04acf4a), o.u(0xc910e9e9, 0xd9301030),
3663// o.u(0x8060404, 0xe0a060a), o.u(0xe781fefe, 0x66988198),
3664// o.u(0x5bf0a0a0, 0xab0bf00b), o.u(0xf0447878, 0xb4cc44cc),
3665// o.u(0x4aba2525, 0xf0d5bad5), o.u(0x96e34b4b, 0x753ee33e),
3666// o.u(0x5ff3a2a2, 0xac0ef30e), o.u(0xbafe5d5d, 0x4419fe19),
3667// o.u(0x1bc08080, 0xdb5bc05b), o.u(0xa8a0505, 0x80858a85),
3668// o.u(0x7ead3f3f, 0xd3ecadec), o.u(0x42bc2121, 0xfedfbcdf),
3669// o.u(0xe0487070, 0xa8d848d8), o.u(0xf904f1f1, 0xfd0c040c),
3670// o.u(0xc6df6363, 0x197adf7a), o.u(0xeec17777, 0x2f58c158),
3671// o.u(0x4575afaf, 0x309f759f), o.u(0x84634242, 0xe7a563a5),
3672// o.u(0x40302020, 0x70503050), o.u(0xd11ae5e5, 0xcb2e1a2e),
3673// o.u(0xe10efdfd, 0xef120e12), o.u(0x656dbfbf, 0x8b76db7),
3674// o.u(0x194c8181, 0x55d44cd4), o.u(0x30141818, 0x243c143c),
3675// o.u(0x4c352626, 0x795f355f), o.u(0x9d2fc3c3, 0xb2712f71),
3676// o.u(0x67e1bebe, 0x8638e138), o.u(0x6aa23535, 0xc8fda2fd),
3677// o.u(0xbcc8888, 0xc74fcc4f), o.u(0x5c392e2e, 0x654b394b),
3678// o.u(0x3d579393, 0x6af957f9), o.u(0xaaf25555, 0x580df20d),
3679// o.u(0xe382fcfc, 0x619d829d), o.u(0xf4477a7a, 0xb3c947c9),
3680// o.u(0x8bacc8c8, 0x27efacef), o.u(0x6fe7baba, 0x8832e732),
3681// o.u(0x642b3232, 0x4f7d2b7d), o.u(0xd795e6e6, 0x42a495a4),
3682// o.u(0x9ba0c0c0, 0x3bfba0fb), o.u(0x32981919, 0xaab398b3),
3683// o.u(0x27d19e9e, 0xf668d168), o.u(0x5d7fa3a3, 0x22817f81),
3684// o.u(0x88664444, 0xeeaa66aa), o.u(0xa87e5454, 0xd6827e82),
3685// o.u(0x76ab3b3b, 0xdde6abe6), o.u(0x16830b0b, 0x959e839e),
3686// o.u(0x3ca8c8c, 0xc945ca45), o.u(0x9529c7c7, 0xbc7b297b),
3687// o.u(0xd6d36b6b, 0x56ed36e), o.u(0x503c2828, 0x6c443c44),
3688// o.u(0x5579a7a7, 0x2c8b798b), o.u(0x63e2bcbc, 0x813de23d),
3689// o.u(0x2c1d1616, 0x31271d27), o.u(0x4176adad, 0x379a769a),
3690// o.u(0xad3bdbdb, 0x964d3b4d), o.u(0xc8566464, 0x9efa56fa),
3691// o.u(0xe84e7474, 0xa6d24ed2), o.u(0x281e1414, 0x36221e22),
3692// o.u(0x3fdb9292, 0xe476db76), o.u(0x180a0c0c, 0x121e0a1e),
3693// o.u(0x906c4848, 0xfcb46cb4), o.u(0x6be4b8b8, 0x8f37e437),
3694// o.u(0x255d9f9f, 0x78e75de7), o.u(0x616ebdbd, 0xfb26eb2),
3695// o.u(0x86ef4343, 0x692aef2a), o.u(0x93a6c4c4, 0x35f1a6f1),
3696// o.u(0x72a83939, 0xdae3a8e3), o.u(0x62a43131, 0xc6f7a4f7),
3697// o.u(0xbd37d3d3, 0x8a593759), o.u(0xff8bf2f2, 0x74868b86),
3698// o.u(0xb132d5d5, 0x83563256), o.u(0xd438b8b, 0x4ec543c5),
3699// o.u(0xdc596e6e, 0x85eb59eb), o.u(0xafb7dada, 0x18c2b7c2),
3700// o.u(0x28c0101, 0x8e8f8c8f), o.u(0x7964b1b1, 0x1dac64ac),
3701// o.u(0x23d29c9c, 0xf16dd26d), o.u(0x92e04949, 0x723be03b),
3702// o.u(0xabb4d8d8, 0x1fc7b4c7), o.u(0x43faacac, 0xb915fa15),
3703// o.u(0xfd07f3f3, 0xfa090709), o.u(0x8525cfcf, 0xa06f256f),
3704// o.u(0x8fafcaca, 0x20eaafea), o.u(0xf38ef4f4, 0x7d898e89),
3705// o.u(0x8ee94747, 0x6720e920), o.u(0x20181010, 0x38281828),
3706// o.u(0xded56f6f, 0xb64d564), o.u(0xfb88f0f0, 0x73838883),
3707// o.u(0x946f4a4a, 0xfbb16fb1), o.u(0xb8725c5c, 0xca967296),
3708// o.u(0x70243838, 0x546c246c), o.u(0xaef15757, 0x5f08f108),
3709// o.u(0xe6c77373, 0x2152c752), o.u(0x35519797, 0x64f351f3),
3710// o.u(0x8d23cbcb, 0xae652365), o.u(0x597ca1a1, 0x25847c84),
3711// o.u(0xcb9ce8e8, 0x57bf9cbf), o.u(0x7c213e3e, 0x5d632163),
3712// o.u(0x37dd9696, 0xea7cdd7c), o.u(0xc2dc6161, 0x1e7fdc7f),
3713// o.u(0x1a860d0d, 0x9c918691), o.u(0x1e850f0f, 0x9b948594),
3714// o.u(0xdb90e0e0, 0x4bab90ab), o.u(0xf8427c7c, 0xbac642c6),
3715// o.u(0xe2c47171, 0x2657c457), o.u(0x83aacccc, 0x29e5aae5),
3716// o.u(0x3bd89090, 0xe373d873), o.u(0xc050606, 0x90f050f),
3717// o.u(0xf501f7f7, 0xf4030103), o.u(0x38121c1c, 0x2a361236),
3718// o.u(0x9fa3c2c2, 0x3cfea3fe), o.u(0xd45f6a6a, 0x8be15fe1),
3719// o.u(0x47f9aeae, 0xbe10f910), o.u(0xd2d06969, 0x26bd06b),
3720// o.u(0x2e911717, 0xbfa891a8), o.u(0x29589999, 0x71e858e8),
3721// o.u(0x74273a3a, 0x53692769), o.u(0x4eb92727, 0xf7d0b9d0),
3722// o.u(0xa938d9d9, 0x91483848), o.u(0xcd13ebeb, 0xde351335),
3723// o.u(0x56b32b2b, 0xe5ceb3ce), o.u(0x44332222, 0x77553355),
3724// o.u(0xbfbbd2d2, 0x4d6bbd6), o.u(0x4970a9a9, 0x39907090),
3725// o.u(0xe890707, 0x87808980), o.u(0x66a73333, 0xc1f2a7f2),
3726// o.u(0x5ab62d2d, 0xecc1b6c1), o.u(0x78223c3c, 0x5a662266),
3727// o.u(0x2a921515, 0xb8ad92ad), o.u(0x8920c9c9, 0xa9602060),
3728// o.u(0x15498787, 0x5cdb49db), o.u(0x4fffaaaa, 0xb01aff1a),
3729// o.u(0xa0785050, 0xd8887888), o.u(0x517aa5a5, 0x2b8e7a8e),
3730// o.u(0x68f0303, 0x898a8f8a), o.u(0xb2f85959, 0x4a13f813),
3731// o.u(0x12800909, 0x929b809b), o.u(0x34171a1a, 0x23391739),
3732// o.u(0xcada6565, 0x1075da75), o.u(0xb531d7d7, 0x84533153),
3733// o.u(0x13c68484, 0xd551c651), o.u(0xbbb8d0d0, 0x3d3b8d3),
3734// o.u(0x1fc38282, 0xdc5ec35e), o.u(0x52b02929, 0xe2cbb0cb),
3735// o.u(0xb4775a5a, 0xc3997799), o.u(0x3c111e1e, 0x2d331133),
3736// o.u(0xf6cb7b7b, 0x3d46cb46), o.u(0x4bfca8a8, 0xb71ffc1f),
3737// o.u(0xdad66d6d, 0xc61d661), o.u(0x583a2c2c, 0x624e3a4e)
3738// ]
3739
3740// var T4 = [
3741// o.u(0xf497a5c6, 0xc632f4a5), o.u(0x97eb84f8, 0xf86f9784),
3742// o.u(0xb0c799ee, 0xee5eb099), o.u(0x8cf78df6, 0xf67a8c8d),
3743// o.u(0x17e50dff, 0xffe8170d), o.u(0xdcb7bdd6, 0xd60adcbd),
3744// o.u(0xc8a7b1de, 0xde16c8b1), o.u(0xfc395491, 0x916dfc54),
3745// o.u(0xf0c05060, 0x6090f050), o.u(0x05040302, 0x02070503),
3746// o.u(0xe087a9ce, 0xce2ee0a9), o.u(0x87ac7d56, 0x56d1877d),
3747// o.u(0x2bd519e7, 0xe7cc2b19), o.u(0xa67162b5, 0xb513a662),
3748// o.u(0x319ae64d, 0x4d7c31e6), o.u(0xb5c39aec, 0xec59b59a),
3749// o.u(0xcf05458f, 0x8f40cf45), o.u(0xbc3e9d1f, 0x1fa3bc9d),
3750// o.u(0xc0094089, 0x8949c040), o.u(0x92ef87fa, 0xfa689287),
3751// o.u(0x3fc515ef, 0xefd03f15), o.u(0x267febb2, 0xb29426eb),
3752// o.u(0x4007c98e, 0x8ece40c9), o.u(0x1ded0bfb, 0xfbe61d0b),
3753// o.u(0x2f82ec41, 0x416e2fec), o.u(0xa97d67b3, 0xb31aa967),
3754// o.u(0x1cbefd5f, 0x5f431cfd), o.u(0x258aea45, 0x456025ea),
3755// o.u(0xda46bf23, 0x23f9dabf), o.u(0x02a6f753, 0x535102f7),
3756// o.u(0xa1d396e4, 0xe445a196), o.u(0xed2d5b9b, 0x9b76ed5b),
3757// o.u(0x5deac275, 0x75285dc2), o.u(0x24d91ce1, 0xe1c5241c),
3758// o.u(0xe97aae3d, 0x3dd4e9ae), o.u(0xbe986a4c, 0x4cf2be6a),
3759// o.u(0xeed85a6c, 0x6c82ee5a), o.u(0xc3fc417e, 0x7ebdc341),
3760// o.u(0x06f102f5, 0xf5f30602), o.u(0xd11d4f83, 0x8352d14f),
3761// o.u(0xe4d05c68, 0x688ce45c), o.u(0x07a2f451, 0x515607f4),
3762// o.u(0x5cb934d1, 0xd18d5c34), o.u(0x18e908f9, 0xf9e11808),
3763// o.u(0xaedf93e2, 0xe24cae93), o.u(0x954d73ab, 0xab3e9573),
3764// o.u(0xf5c45362, 0x6297f553), o.u(0x41543f2a, 0x2a6b413f),
3765// o.u(0x14100c08, 0x081c140c), o.u(0xf6315295, 0x9563f652),
3766// o.u(0xaf8c6546, 0x46e9af65), o.u(0xe2215e9d, 0x9d7fe25e),
3767// o.u(0x78602830, 0x30487828), o.u(0xf86ea137, 0x37cff8a1),
3768// o.u(0x11140f0a, 0x0a1b110f), o.u(0xc45eb52f, 0x2febc4b5),
3769// o.u(0x1b1c090e, 0x0e151b09), o.u(0x5a483624, 0x247e5a36),
3770// o.u(0xb6369b1b, 0x1badb69b), o.u(0x47a53ddf, 0xdf98473d),
3771// o.u(0x6a8126cd, 0xcda76a26), o.u(0xbb9c694e, 0x4ef5bb69),
3772// o.u(0x4cfecd7f, 0x7f334ccd), o.u(0xbacf9fea, 0xea50ba9f),
3773// o.u(0x2d241b12, 0x123f2d1b), o.u(0xb93a9e1d, 0x1da4b99e),
3774// o.u(0x9cb07458, 0x58c49c74), o.u(0x72682e34, 0x3446722e),
3775// o.u(0x776c2d36, 0x3641772d), o.u(0xcda3b2dc, 0xdc11cdb2),
3776// o.u(0x2973eeb4, 0xb49d29ee), o.u(0x16b6fb5b, 0x5b4d16fb),
3777// o.u(0x0153f6a4, 0xa4a501f6), o.u(0xd7ec4d76, 0x76a1d74d),
3778// o.u(0xa37561b7, 0xb714a361), o.u(0x49face7d, 0x7d3449ce),
3779// o.u(0x8da47b52, 0x52df8d7b), o.u(0x42a13edd, 0xdd9f423e),
3780// o.u(0x93bc715e, 0x5ecd9371), o.u(0xa2269713, 0x13b1a297),
3781// o.u(0x0457f5a6, 0xa6a204f5), o.u(0xb86968b9, 0xb901b868),
3782// o.u(0x00000000, 0x00000000), o.u(0x74992cc1, 0xc1b5742c),
3783// o.u(0xa0806040, 0x40e0a060), o.u(0x21dd1fe3, 0xe3c2211f),
3784// o.u(0x43f2c879, 0x793a43c8), o.u(0x2c77edb6, 0xb69a2ced),
3785// o.u(0xd9b3bed4, 0xd40dd9be), o.u(0xca01468d, 0x8d47ca46),
3786// o.u(0x70ced967, 0x671770d9), o.u(0xdde44b72, 0x72afdd4b),
3787// o.u(0x7933de94, 0x94ed79de), o.u(0x672bd498, 0x98ff67d4),
3788// o.u(0x237be8b0, 0xb09323e8), o.u(0xde114a85, 0x855bde4a),
3789// o.u(0xbd6d6bbb, 0xbb06bd6b), o.u(0x7e912ac5, 0xc5bb7e2a),
3790// o.u(0x349ee54f, 0x4f7b34e5), o.u(0x3ac116ed, 0xedd73a16),
3791// o.u(0x5417c586, 0x86d254c5), o.u(0x622fd79a, 0x9af862d7),
3792// o.u(0xffcc5566, 0x6699ff55), o.u(0xa7229411, 0x11b6a794),
3793// o.u(0x4a0fcf8a, 0x8ac04acf), o.u(0x30c910e9, 0xe9d93010),
3794// o.u(0x0a080604, 0x040e0a06), o.u(0x98e781fe, 0xfe669881),
3795// o.u(0x0b5bf0a0, 0xa0ab0bf0), o.u(0xccf04478, 0x78b4cc44),
3796// o.u(0xd54aba25, 0x25f0d5ba), o.u(0x3e96e34b, 0x4b753ee3),
3797// o.u(0x0e5ff3a2, 0xa2ac0ef3), o.u(0x19bafe5d, 0x5d4419fe),
3798// o.u(0x5b1bc080, 0x80db5bc0), o.u(0x850a8a05, 0x0580858a),
3799// o.u(0xec7ead3f, 0x3fd3ecad), o.u(0xdf42bc21, 0x21fedfbc),
3800// o.u(0xd8e04870, 0x70a8d848), o.u(0x0cf904f1, 0xf1fd0c04),
3801// o.u(0x7ac6df63, 0x63197adf), o.u(0x58eec177, 0x772f58c1),
3802// o.u(0x9f4575af, 0xaf309f75), o.u(0xa5846342, 0x42e7a563),
3803// o.u(0x50403020, 0x20705030), o.u(0x2ed11ae5, 0xe5cb2e1a),
3804// o.u(0x12e10efd, 0xfdef120e), o.u(0xb7656dbf, 0xbf08b76d),
3805// o.u(0xd4194c81, 0x8155d44c), o.u(0x3c301418, 0x18243c14),
3806// o.u(0x5f4c3526, 0x26795f35), o.u(0x719d2fc3, 0xc3b2712f),
3807// o.u(0x3867e1be, 0xbe8638e1), o.u(0xfd6aa235, 0x35c8fda2),
3808// o.u(0x4f0bcc88, 0x88c74fcc), o.u(0x4b5c392e, 0x2e654b39),
3809// o.u(0xf93d5793, 0x936af957), o.u(0x0daaf255, 0x55580df2),
3810// o.u(0x9de382fc, 0xfc619d82), o.u(0xc9f4477a, 0x7ab3c947),
3811// o.u(0xef8bacc8, 0xc827efac), o.u(0x326fe7ba, 0xba8832e7),
3812// o.u(0x7d642b32, 0x324f7d2b), o.u(0xa4d795e6, 0xe642a495),
3813// o.u(0xfb9ba0c0, 0xc03bfba0), o.u(0xb3329819, 0x19aab398),
3814// o.u(0x6827d19e, 0x9ef668d1), o.u(0x815d7fa3, 0xa322817f),
3815// o.u(0xaa886644, 0x44eeaa66), o.u(0x82a87e54, 0x54d6827e),
3816// o.u(0xe676ab3b, 0x3bdde6ab), o.u(0x9e16830b, 0x0b959e83),
3817// o.u(0x4503ca8c, 0x8cc945ca), o.u(0x7b9529c7, 0xc7bc7b29),
3818// o.u(0x6ed6d36b, 0x6b056ed3), o.u(0x44503c28, 0x286c443c),
3819// o.u(0x8b5579a7, 0xa72c8b79), o.u(0x3d63e2bc, 0xbc813de2),
3820// o.u(0x272c1d16, 0x1631271d), o.u(0x9a4176ad, 0xad379a76),
3821// o.u(0x4dad3bdb, 0xdb964d3b), o.u(0xfac85664, 0x649efa56),
3822// o.u(0xd2e84e74, 0x74a6d24e), o.u(0x22281e14, 0x1436221e),
3823// o.u(0x763fdb92, 0x92e476db), o.u(0x1e180a0c, 0x0c121e0a),
3824// o.u(0xb4906c48, 0x48fcb46c), o.u(0x376be4b8, 0xb88f37e4),
3825// o.u(0xe7255d9f, 0x9f78e75d), o.u(0xb2616ebd, 0xbd0fb26e),
3826// o.u(0x2a86ef43, 0x43692aef), o.u(0xf193a6c4, 0xc435f1a6),
3827// o.u(0xe372a839, 0x39dae3a8), o.u(0xf762a431, 0x31c6f7a4),
3828// o.u(0x59bd37d3, 0xd38a5937), o.u(0x86ff8bf2, 0xf274868b),
3829// o.u(0x56b132d5, 0xd5835632), o.u(0xc50d438b, 0x8b4ec543),
3830// o.u(0xebdc596e, 0x6e85eb59), o.u(0xc2afb7da, 0xda18c2b7),
3831// o.u(0x8f028c01, 0x018e8f8c), o.u(0xac7964b1, 0xb11dac64),
3832// o.u(0x6d23d29c, 0x9cf16dd2), o.u(0x3b92e049, 0x49723be0),
3833// o.u(0xc7abb4d8, 0xd81fc7b4), o.u(0x1543faac, 0xacb915fa),
3834// o.u(0x09fd07f3, 0xf3fa0907), o.u(0x6f8525cf, 0xcfa06f25),
3835// o.u(0xea8fafca, 0xca20eaaf), o.u(0x89f38ef4, 0xf47d898e),
3836// o.u(0x208ee947, 0x476720e9), o.u(0x28201810, 0x10382818),
3837// o.u(0x64ded56f, 0x6f0b64d5), o.u(0x83fb88f0, 0xf0738388),
3838// o.u(0xb1946f4a, 0x4afbb16f), o.u(0x96b8725c, 0x5cca9672),
3839// o.u(0x6c702438, 0x38546c24), o.u(0x08aef157, 0x575f08f1),
3840// o.u(0x52e6c773, 0x732152c7), o.u(0xf3355197, 0x9764f351),
3841// o.u(0x658d23cb, 0xcbae6523), o.u(0x84597ca1, 0xa125847c),
3842// o.u(0xbfcb9ce8, 0xe857bf9c), o.u(0x637c213e, 0x3e5d6321),
3843// o.u(0x7c37dd96, 0x96ea7cdd), o.u(0x7fc2dc61, 0x611e7fdc),
3844// o.u(0x911a860d, 0x0d9c9186), o.u(0x941e850f, 0x0f9b9485),
3845// o.u(0xabdb90e0, 0xe04bab90), o.u(0xc6f8427c, 0x7cbac642),
3846// o.u(0x57e2c471, 0x712657c4), o.u(0xe583aacc, 0xcc29e5aa),
3847// o.u(0x733bd890, 0x90e373d8), o.u(0x0f0c0506, 0x06090f05),
3848// o.u(0x03f501f7, 0xf7f40301), o.u(0x3638121c, 0x1c2a3612),
3849// o.u(0xfe9fa3c2, 0xc23cfea3), o.u(0xe1d45f6a, 0x6a8be15f),
3850// o.u(0x1047f9ae, 0xaebe10f9), o.u(0x6bd2d069, 0x69026bd0),
3851// o.u(0xa82e9117, 0x17bfa891), o.u(0xe8295899, 0x9971e858),
3852// o.u(0x6974273a, 0x3a536927), o.u(0xd04eb927, 0x27f7d0b9),
3853// o.u(0x48a938d9, 0xd9914838), o.u(0x35cd13eb, 0xebde3513),
3854// o.u(0xce56b32b, 0x2be5ceb3), o.u(0x55443322, 0x22775533),
3855// o.u(0xd6bfbbd2, 0xd204d6bb), o.u(0x904970a9, 0xa9399070),
3856// o.u(0x800e8907, 0x07878089), o.u(0xf266a733, 0x33c1f2a7),
3857// o.u(0xc15ab62d, 0x2decc1b6), o.u(0x6678223c, 0x3c5a6622),
3858// o.u(0xad2a9215, 0x15b8ad92), o.u(0x608920c9, 0xc9a96020),
3859// o.u(0xdb154987, 0x875cdb49), o.u(0x1a4fffaa, 0xaab01aff),
3860// o.u(0x88a07850, 0x50d88878), o.u(0x8e517aa5, 0xa52b8e7a),
3861// o.u(0x8a068f03, 0x03898a8f), o.u(0x13b2f859, 0x594a13f8),
3862// o.u(0x9b128009, 0x09929b80), o.u(0x3934171a, 0x1a233917),
3863// o.u(0x75cada65, 0x651075da), o.u(0x53b531d7, 0xd7845331),
3864// o.u(0x5113c684, 0x84d551c6), o.u(0xd3bbb8d0, 0xd003d3b8),
3865// o.u(0x5e1fc382, 0x82dc5ec3), o.u(0xcb52b029, 0x29e2cbb0),
3866// o.u(0x99b4775a, 0x5ac39977), o.u(0x333c111e, 0x1e2d3311),
3867// o.u(0x46f6cb7b, 0x7b3d46cb), o.u(0x1f4bfca8, 0xa8b71ffc),
3868// o.u(0x61dad66d, 0x6d0c61d6), o.u(0x4e583a2c, 0x2c624e3a)
3869// ];
3870
3871// var T5 = [
3872// o.u(0xa5f497a5, 0xc6c632f4), o.u(0x8497eb84, 0xf8f86f97),
3873// o.u(0x99b0c799, 0xeeee5eb0), o.u(0x8d8cf78d, 0xf6f67a8c),
3874// o.u(0xd17e50d, 0xffffe817), o.u(0xbddcb7bd, 0xd6d60adc),
3875// o.u(0xb1c8a7b1, 0xdede16c8), o.u(0x54fc3954, 0x91916dfc),
3876// o.u(0x50f0c050, 0x606090f0), o.u(0x3050403, 0x2020705),
3877// o.u(0xa9e087a9, 0xcece2ee0), o.u(0x7d87ac7d, 0x5656d187),
3878// o.u(0x192bd519, 0xe7e7cc2b), o.u(0x62a67162, 0xb5b513a6),
3879// o.u(0xe6319ae6, 0x4d4d7c31), o.u(0x9ab5c39a, 0xecec59b5),
3880// o.u(0x45cf0545, 0x8f8f40cf), o.u(0x9dbc3e9d, 0x1f1fa3bc),
3881// o.u(0x40c00940, 0x898949c0), o.u(0x8792ef87, 0xfafa6892),
3882// o.u(0x153fc515, 0xefefd03f), o.u(0xeb267feb, 0xb2b29426),
3883// o.u(0xc94007c9, 0x8e8ece40), o.u(0xb1ded0b, 0xfbfbe61d),
3884// o.u(0xec2f82ec, 0x41416e2f), o.u(0x67a97d67, 0xb3b31aa9),
3885// o.u(0xfd1cbefd, 0x5f5f431c), o.u(0xea258aea, 0x45456025),
3886// o.u(0xbfda46bf, 0x2323f9da), o.u(0xf702a6f7, 0x53535102),
3887// o.u(0x96a1d396, 0xe4e445a1), o.u(0x5bed2d5b, 0x9b9b76ed),
3888// o.u(0xc25deac2, 0x7575285d), o.u(0x1c24d91c, 0xe1e1c524),
3889// o.u(0xaee97aae, 0x3d3dd4e9), o.u(0x6abe986a, 0x4c4cf2be),
3890// o.u(0x5aeed85a, 0x6c6c82ee), o.u(0x41c3fc41, 0x7e7ebdc3),
3891// o.u(0x206f102, 0xf5f5f306), o.u(0x4fd11d4f, 0x838352d1),
3892// o.u(0x5ce4d05c, 0x68688ce4), o.u(0xf407a2f4, 0x51515607),
3893// o.u(0x345cb934, 0xd1d18d5c), o.u(0x818e908, 0xf9f9e118),
3894// o.u(0x93aedf93, 0xe2e24cae), o.u(0x73954d73, 0xabab3e95),
3895// o.u(0x53f5c453, 0x626297f5), o.u(0x3f41543f, 0x2a2a6b41),
3896// o.u(0xc14100c, 0x8081c14), o.u(0x52f63152, 0x959563f6),
3897// o.u(0x65af8c65, 0x4646e9af), o.u(0x5ee2215e, 0x9d9d7fe2),
3898// o.u(0x28786028, 0x30304878), o.u(0xa1f86ea1, 0x3737cff8),
3899// o.u(0xf11140f, 0xa0a1b11), o.u(0xb5c45eb5, 0x2f2febc4),
3900// o.u(0x91b1c09, 0xe0e151b), o.u(0x365a4836, 0x24247e5a),
3901// o.u(0x9bb6369b, 0x1b1badb6), o.u(0x3d47a53d, 0xdfdf9847),
3902// o.u(0x266a8126, 0xcdcda76a), o.u(0x69bb9c69, 0x4e4ef5bb),
3903// o.u(0xcd4cfecd, 0x7f7f334c), o.u(0x9fbacf9f, 0xeaea50ba),
3904// o.u(0x1b2d241b, 0x12123f2d), o.u(0x9eb93a9e, 0x1d1da4b9),
3905// o.u(0x749cb074, 0x5858c49c), o.u(0x2e72682e, 0x34344672),
3906// o.u(0x2d776c2d, 0x36364177), o.u(0xb2cda3b2, 0xdcdc11cd),
3907// o.u(0xee2973ee, 0xb4b49d29), o.u(0xfb16b6fb, 0x5b5b4d16),
3908// o.u(0xf60153f6, 0xa4a4a501), o.u(0x4dd7ec4d, 0x7676a1d7),
3909// o.u(0x61a37561, 0xb7b714a3), o.u(0xce49face, 0x7d7d3449),
3910// o.u(0x7b8da47b, 0x5252df8d), o.u(0x3e42a13e, 0xdddd9f42),
3911// o.u(0x7193bc71, 0x5e5ecd93), o.u(0x97a22697, 0x1313b1a2),
3912// o.u(0xf50457f5, 0xa6a6a204), o.u(0x68b86968, 0xb9b901b8),
3913// o.u(0x0, 0x0), o.u(0x2c74992c, 0xc1c1b574),
3914// o.u(0x60a08060, 0x4040e0a0), o.u(0x1f21dd1f, 0xe3e3c221),
3915// o.u(0xc843f2c8, 0x79793a43), o.u(0xed2c77ed, 0xb6b69a2c),
3916// o.u(0xbed9b3be, 0xd4d40dd9), o.u(0x46ca0146, 0x8d8d47ca),
3917// o.u(0xd970ced9, 0x67671770), o.u(0x4bdde44b, 0x7272afdd),
3918// o.u(0xde7933de, 0x9494ed79), o.u(0xd4672bd4, 0x9898ff67),
3919// o.u(0xe8237be8, 0xb0b09323), o.u(0x4ade114a, 0x85855bde),
3920// o.u(0x6bbd6d6b, 0xbbbb06bd), o.u(0x2a7e912a, 0xc5c5bb7e),
3921// o.u(0xe5349ee5, 0x4f4f7b34), o.u(0x163ac116, 0xededd73a),
3922// o.u(0xc55417c5, 0x8686d254), o.u(0xd7622fd7, 0x9a9af862),
3923// o.u(0x55ffcc55, 0x666699ff), o.u(0x94a72294, 0x1111b6a7),
3924// o.u(0xcf4a0fcf, 0x8a8ac04a), o.u(0x1030c910, 0xe9e9d930),
3925// o.u(0x60a0806, 0x4040e0a), o.u(0x8198e781, 0xfefe6698),
3926// o.u(0xf00b5bf0, 0xa0a0ab0b), o.u(0x44ccf044, 0x7878b4cc),
3927// o.u(0xbad54aba, 0x2525f0d5), o.u(0xe33e96e3, 0x4b4b753e),
3928// o.u(0xf30e5ff3, 0xa2a2ac0e), o.u(0xfe19bafe, 0x5d5d4419),
3929// o.u(0xc05b1bc0, 0x8080db5b), o.u(0x8a850a8a, 0x5058085),
3930// o.u(0xadec7ead, 0x3f3fd3ec), o.u(0xbcdf42bc, 0x2121fedf),
3931// o.u(0x48d8e048, 0x7070a8d8), o.u(0x40cf904, 0xf1f1fd0c),
3932// o.u(0xdf7ac6df, 0x6363197a), o.u(0xc158eec1, 0x77772f58),
3933// o.u(0x759f4575, 0xafaf309f), o.u(0x63a58463, 0x4242e7a5),
3934// o.u(0x30504030, 0x20207050), o.u(0x1a2ed11a, 0xe5e5cb2e),
3935// o.u(0xe12e10e, 0xfdfdef12), o.u(0x6db7656d, 0xbfbf08b7),
3936// o.u(0x4cd4194c, 0x818155d4), o.u(0x143c3014, 0x1818243c),
3937// o.u(0x355f4c35, 0x2626795f), o.u(0x2f719d2f, 0xc3c3b271),
3938// o.u(0xe13867e1, 0xbebe8638), o.u(0xa2fd6aa2, 0x3535c8fd),
3939// o.u(0xcc4f0bcc, 0x8888c74f), o.u(0x394b5c39, 0x2e2e654b),
3940// o.u(0x57f93d57, 0x93936af9), o.u(0xf20daaf2, 0x5555580d),
3941// o.u(0x829de382, 0xfcfc619d), o.u(0x47c9f447, 0x7a7ab3c9),
3942// o.u(0xacef8bac, 0xc8c827ef), o.u(0xe7326fe7, 0xbaba8832),
3943// o.u(0x2b7d642b, 0x32324f7d), o.u(0x95a4d795, 0xe6e642a4),
3944// o.u(0xa0fb9ba0, 0xc0c03bfb), o.u(0x98b33298, 0x1919aab3),
3945// o.u(0xd16827d1, 0x9e9ef668), o.u(0x7f815d7f, 0xa3a32281),
3946// o.u(0x66aa8866, 0x4444eeaa), o.u(0x7e82a87e, 0x5454d682),
3947// o.u(0xabe676ab, 0x3b3bdde6), o.u(0x839e1683, 0xb0b959e),
3948// o.u(0xca4503ca, 0x8c8cc945), o.u(0x297b9529, 0xc7c7bc7b),
3949// o.u(0xd36ed6d3, 0x6b6b056e), o.u(0x3c44503c, 0x28286c44),
3950// o.u(0x798b5579, 0xa7a72c8b), o.u(0xe23d63e2, 0xbcbc813d),
3951// o.u(0x1d272c1d, 0x16163127), o.u(0x769a4176, 0xadad379a),
3952// o.u(0x3b4dad3b, 0xdbdb964d), o.u(0x56fac856, 0x64649efa),
3953// o.u(0x4ed2e84e, 0x7474a6d2), o.u(0x1e22281e, 0x14143622),
3954// o.u(0xdb763fdb, 0x9292e476), o.u(0xa1e180a, 0xc0c121e),
3955// o.u(0x6cb4906c, 0x4848fcb4), o.u(0xe4376be4, 0xb8b88f37),
3956// o.u(0x5de7255d, 0x9f9f78e7), o.u(0x6eb2616e, 0xbdbd0fb2),
3957// o.u(0xef2a86ef, 0x4343692a), o.u(0xa6f193a6, 0xc4c435f1),
3958// o.u(0xa8e372a8, 0x3939dae3), o.u(0xa4f762a4, 0x3131c6f7),
3959// o.u(0x3759bd37, 0xd3d38a59), o.u(0x8b86ff8b, 0xf2f27486),
3960// o.u(0x3256b132, 0xd5d58356), o.u(0x43c50d43, 0x8b8b4ec5),
3961// o.u(0x59ebdc59, 0x6e6e85eb), o.u(0xb7c2afb7, 0xdada18c2),
3962// o.u(0x8c8f028c, 0x1018e8f), o.u(0x64ac7964, 0xb1b11dac),
3963// o.u(0xd26d23d2, 0x9c9cf16d), o.u(0xe03b92e0, 0x4949723b),
3964// o.u(0xb4c7abb4, 0xd8d81fc7), o.u(0xfa1543fa, 0xacacb915),
3965// o.u(0x709fd07, 0xf3f3fa09), o.u(0x256f8525, 0xcfcfa06f),
3966// o.u(0xafea8faf, 0xcaca20ea), o.u(0x8e89f38e, 0xf4f47d89),
3967// o.u(0xe9208ee9, 0x47476720), o.u(0x18282018, 0x10103828),
3968// o.u(0xd564ded5, 0x6f6f0b64), o.u(0x8883fb88, 0xf0f07383),
3969// o.u(0x6fb1946f, 0x4a4afbb1), o.u(0x7296b872, 0x5c5cca96),
3970// o.u(0x246c7024, 0x3838546c), o.u(0xf108aef1, 0x57575f08),
3971// o.u(0xc752e6c7, 0x73732152), o.u(0x51f33551, 0x979764f3),
3972// o.u(0x23658d23, 0xcbcbae65), o.u(0x7c84597c, 0xa1a12584),
3973// o.u(0x9cbfcb9c, 0xe8e857bf), o.u(0x21637c21, 0x3e3e5d63),
3974// o.u(0xdd7c37dd, 0x9696ea7c), o.u(0xdc7fc2dc, 0x61611e7f),
3975// o.u(0x86911a86, 0xd0d9c91), o.u(0x85941e85, 0xf0f9b94),
3976// o.u(0x90abdb90, 0xe0e04bab), o.u(0x42c6f842, 0x7c7cbac6),
3977// o.u(0xc457e2c4, 0x71712657), o.u(0xaae583aa, 0xcccc29e5),
3978// o.u(0xd8733bd8, 0x9090e373), o.u(0x50f0c05, 0x606090f),
3979// o.u(0x103f501, 0xf7f7f403), o.u(0x12363812, 0x1c1c2a36),
3980// o.u(0xa3fe9fa3, 0xc2c23cfe), o.u(0x5fe1d45f, 0x6a6a8be1),
3981// o.u(0xf91047f9, 0xaeaebe10), o.u(0xd06bd2d0, 0x6969026b),
3982// o.u(0x91a82e91, 0x1717bfa8), o.u(0x58e82958, 0x999971e8),
3983// o.u(0x27697427, 0x3a3a5369), o.u(0xb9d04eb9, 0x2727f7d0),
3984// o.u(0x3848a938, 0xd9d99148), o.u(0x1335cd13, 0xebebde35),
3985// o.u(0xb3ce56b3, 0x2b2be5ce), o.u(0x33554433, 0x22227755),
3986// o.u(0xbbd6bfbb, 0xd2d204d6), o.u(0x70904970, 0xa9a93990),
3987// o.u(0x89800e89, 0x7078780), o.u(0xa7f266a7, 0x3333c1f2),
3988// o.u(0xb6c15ab6, 0x2d2decc1), o.u(0x22667822, 0x3c3c5a66),
3989// o.u(0x92ad2a92, 0x1515b8ad), o.u(0x20608920, 0xc9c9a960),
3990// o.u(0x49db1549, 0x87875cdb), o.u(0xff1a4fff, 0xaaaab01a),
3991// o.u(0x7888a078, 0x5050d888), o.u(0x7a8e517a, 0xa5a52b8e),
3992// o.u(0x8f8a068f, 0x303898a), o.u(0xf813b2f8, 0x59594a13),
3993// o.u(0x809b1280, 0x909929b), o.u(0x17393417, 0x1a1a2339),
3994// o.u(0xda75cada, 0x65651075), o.u(0x3153b531, 0xd7d78453),
3995// o.u(0xc65113c6, 0x8484d551), o.u(0xb8d3bbb8, 0xd0d003d3),
3996// o.u(0xc35e1fc3, 0x8282dc5e), o.u(0xb0cb52b0, 0x2929e2cb),
3997// o.u(0x7799b477, 0x5a5ac399), o.u(0x11333c11, 0x1e1e2d33),
3998// o.u(0xcb46f6cb, 0x7b7b3d46), o.u(0xfc1f4bfc, 0xa8a8b71f),
3999// o.u(0xd661dad6, 0x6d6d0c61), o.u(0x3a4e583a, 0x2c2c624e)
4000// ];
4001
4002// var T6 = [
4003// o.u(0xf4a5f497, 0xa5c6c632), o.u(0x978497eb, 0x84f8f86f),
4004// o.u(0xb099b0c7, 0x99eeee5e), o.u(0x8c8d8cf7, 0x8df6f67a),
4005// o.u(0x170d17e5, 0xdffffe8), o.u(0xdcbddcb7, 0xbdd6d60a),
4006// o.u(0xc8b1c8a7, 0xb1dede16), o.u(0xfc54fc39, 0x5491916d),
4007// o.u(0xf050f0c0, 0x50606090), o.u(0x5030504, 0x3020207),
4008// o.u(0xe0a9e087, 0xa9cece2e), o.u(0x877d87ac, 0x7d5656d1),
4009// o.u(0x2b192bd5, 0x19e7e7cc), o.u(0xa662a671, 0x62b5b513),
4010// o.u(0x31e6319a, 0xe64d4d7c), o.u(0xb59ab5c3, 0x9aecec59),
4011// o.u(0xcf45cf05, 0x458f8f40), o.u(0xbc9dbc3e, 0x9d1f1fa3),
4012// o.u(0xc040c009, 0x40898949), o.u(0x928792ef, 0x87fafa68),
4013// o.u(0x3f153fc5, 0x15efefd0), o.u(0x26eb267f, 0xebb2b294),
4014// o.u(0x40c94007, 0xc98e8ece), o.u(0x1d0b1ded, 0xbfbfbe6),
4015// o.u(0x2fec2f82, 0xec41416e), o.u(0xa967a97d, 0x67b3b31a),
4016// o.u(0x1cfd1cbe, 0xfd5f5f43), o.u(0x25ea258a, 0xea454560),
4017// o.u(0xdabfda46, 0xbf2323f9), o.u(0x2f702a6, 0xf7535351),
4018// o.u(0xa196a1d3, 0x96e4e445), o.u(0xed5bed2d, 0x5b9b9b76),
4019// o.u(0x5dc25dea, 0xc2757528), o.u(0x241c24d9, 0x1ce1e1c5),
4020// o.u(0xe9aee97a, 0xae3d3dd4), o.u(0xbe6abe98, 0x6a4c4cf2),
4021// o.u(0xee5aeed8, 0x5a6c6c82), o.u(0xc341c3fc, 0x417e7ebd),
4022// o.u(0x60206f1, 0x2f5f5f3), o.u(0xd14fd11d, 0x4f838352),
4023// o.u(0xe45ce4d0, 0x5c68688c), o.u(0x7f407a2, 0xf4515156),
4024// o.u(0x5c345cb9, 0x34d1d18d), o.u(0x180818e9, 0x8f9f9e1),
4025// o.u(0xae93aedf, 0x93e2e24c), o.u(0x9573954d, 0x73abab3e),
4026// o.u(0xf553f5c4, 0x53626297), o.u(0x413f4154, 0x3f2a2a6b),
4027// o.u(0x140c1410, 0xc08081c), o.u(0xf652f631, 0x52959563),
4028// o.u(0xaf65af8c, 0x654646e9), o.u(0xe25ee221, 0x5e9d9d7f),
4029// o.u(0x78287860, 0x28303048), o.u(0xf8a1f86e, 0xa13737cf),
4030// o.u(0x110f1114, 0xf0a0a1b), o.u(0xc4b5c45e, 0xb52f2feb),
4031// o.u(0x1b091b1c, 0x90e0e15), o.u(0x5a365a48, 0x3624247e),
4032// o.u(0xb69bb636, 0x9b1b1bad), o.u(0x473d47a5, 0x3ddfdf98),
4033// o.u(0x6a266a81, 0x26cdcda7), o.u(0xbb69bb9c, 0x694e4ef5),
4034// o.u(0x4ccd4cfe, 0xcd7f7f33), o.u(0xba9fbacf, 0x9feaea50),
4035// o.u(0x2d1b2d24, 0x1b12123f), o.u(0xb99eb93a, 0x9e1d1da4),
4036// o.u(0x9c749cb0, 0x745858c4), o.u(0x722e7268, 0x2e343446),
4037// o.u(0x772d776c, 0x2d363641), o.u(0xcdb2cda3, 0xb2dcdc11),
4038// o.u(0x29ee2973, 0xeeb4b49d), o.u(0x16fb16b6, 0xfb5b5b4d),
4039// o.u(0x1f60153, 0xf6a4a4a5), o.u(0xd74dd7ec, 0x4d7676a1),
4040// o.u(0xa361a375, 0x61b7b714), o.u(0x49ce49fa, 0xce7d7d34),
4041// o.u(0x8d7b8da4, 0x7b5252df), o.u(0x423e42a1, 0x3edddd9f),
4042// o.u(0x937193bc, 0x715e5ecd), o.u(0xa297a226, 0x971313b1),
4043// o.u(0x4f50457, 0xf5a6a6a2), o.u(0xb868b869, 0x68b9b901),
4044// o.u(0x0, 0x0), o.u(0x742c7499, 0x2cc1c1b5),
4045// o.u(0xa060a080, 0x604040e0), o.u(0x211f21dd, 0x1fe3e3c2),
4046// o.u(0x43c843f2, 0xc879793a), o.u(0x2ced2c77, 0xedb6b69a),
4047// o.u(0xd9bed9b3, 0xbed4d40d), o.u(0xca46ca01, 0x468d8d47),
4048// o.u(0x70d970ce, 0xd9676717), o.u(0xdd4bdde4, 0x4b7272af),
4049// o.u(0x79de7933, 0xde9494ed), o.u(0x67d4672b, 0xd49898ff),
4050// o.u(0x23e8237b, 0xe8b0b093), o.u(0xde4ade11, 0x4a85855b),
4051// o.u(0xbd6bbd6d, 0x6bbbbb06), o.u(0x7e2a7e91, 0x2ac5c5bb),
4052// o.u(0x34e5349e, 0xe54f4f7b), o.u(0x3a163ac1, 0x16ededd7),
4053// o.u(0x54c55417, 0xc58686d2), o.u(0x62d7622f, 0xd79a9af8),
4054// o.u(0xff55ffcc, 0x55666699), o.u(0xa794a722, 0x941111b6),
4055// o.u(0x4acf4a0f, 0xcf8a8ac0), o.u(0x301030c9, 0x10e9e9d9),
4056// o.u(0xa060a08, 0x604040e), o.u(0x988198e7, 0x81fefe66),
4057// o.u(0xbf00b5b, 0xf0a0a0ab), o.u(0xcc44ccf0, 0x447878b4),
4058// o.u(0xd5bad54a, 0xba2525f0), o.u(0x3ee33e96, 0xe34b4b75),
4059// o.u(0xef30e5f, 0xf3a2a2ac), o.u(0x19fe19ba, 0xfe5d5d44),
4060// o.u(0x5bc05b1b, 0xc08080db), o.u(0x858a850a, 0x8a050580),
4061// o.u(0xecadec7e, 0xad3f3fd3), o.u(0xdfbcdf42, 0xbc2121fe),
4062// o.u(0xd848d8e0, 0x487070a8), o.u(0xc040cf9, 0x4f1f1fd),
4063// o.u(0x7adf7ac6, 0xdf636319), o.u(0x58c158ee, 0xc177772f),
4064// o.u(0x9f759f45, 0x75afaf30), o.u(0xa563a584, 0x634242e7),
4065// o.u(0x50305040, 0x30202070), o.u(0x2e1a2ed1, 0x1ae5e5cb),
4066// o.u(0x120e12e1, 0xefdfdef), o.u(0xb76db765, 0x6dbfbf08),
4067// o.u(0xd44cd419, 0x4c818155), o.u(0x3c143c30, 0x14181824),
4068// o.u(0x5f355f4c, 0x35262679), o.u(0x712f719d, 0x2fc3c3b2),
4069// o.u(0x38e13867, 0xe1bebe86), o.u(0xfda2fd6a, 0xa23535c8),
4070// o.u(0x4fcc4f0b, 0xcc8888c7), o.u(0x4b394b5c, 0x392e2e65),
4071// o.u(0xf957f93d, 0x5793936a), o.u(0xdf20daa, 0xf2555558),
4072// o.u(0x9d829de3, 0x82fcfc61), o.u(0xc947c9f4, 0x477a7ab3),
4073// o.u(0xefacef8b, 0xacc8c827), o.u(0x32e7326f, 0xe7baba88),
4074// o.u(0x7d2b7d64, 0x2b32324f), o.u(0xa495a4d7, 0x95e6e642),
4075// o.u(0xfba0fb9b, 0xa0c0c03b), o.u(0xb398b332, 0x981919aa),
4076// o.u(0x68d16827, 0xd19e9ef6), o.u(0x817f815d, 0x7fa3a322),
4077// o.u(0xaa66aa88, 0x664444ee), o.u(0x827e82a8, 0x7e5454d6),
4078// o.u(0xe6abe676, 0xab3b3bdd), o.u(0x9e839e16, 0x830b0b95),
4079// o.u(0x45ca4503, 0xca8c8cc9), o.u(0x7b297b95, 0x29c7c7bc),
4080// o.u(0x6ed36ed6, 0xd36b6b05), o.u(0x443c4450, 0x3c28286c),
4081// o.u(0x8b798b55, 0x79a7a72c), o.u(0x3de23d63, 0xe2bcbc81),
4082// o.u(0x271d272c, 0x1d161631), o.u(0x9a769a41, 0x76adad37),
4083// o.u(0x4d3b4dad, 0x3bdbdb96), o.u(0xfa56fac8, 0x5664649e),
4084// o.u(0xd24ed2e8, 0x4e7474a6), o.u(0x221e2228, 0x1e141436),
4085// o.u(0x76db763f, 0xdb9292e4), o.u(0x1e0a1e18, 0xa0c0c12),
4086// o.u(0xb46cb490, 0x6c4848fc), o.u(0x37e4376b, 0xe4b8b88f),
4087// o.u(0xe75de725, 0x5d9f9f78), o.u(0xb26eb261, 0x6ebdbd0f),
4088// o.u(0x2aef2a86, 0xef434369), o.u(0xf1a6f193, 0xa6c4c435),
4089// o.u(0xe3a8e372, 0xa83939da), o.u(0xf7a4f762, 0xa43131c6),
4090// o.u(0x593759bd, 0x37d3d38a), o.u(0x868b86ff, 0x8bf2f274),
4091// o.u(0x563256b1, 0x32d5d583), o.u(0xc543c50d, 0x438b8b4e),
4092// o.u(0xeb59ebdc, 0x596e6e85), o.u(0xc2b7c2af, 0xb7dada18),
4093// o.u(0x8f8c8f02, 0x8c01018e), o.u(0xac64ac79, 0x64b1b11d),
4094// o.u(0x6dd26d23, 0xd29c9cf1), o.u(0x3be03b92, 0xe0494972),
4095// o.u(0xc7b4c7ab, 0xb4d8d81f), o.u(0x15fa1543, 0xfaacacb9),
4096// o.u(0x90709fd, 0x7f3f3fa), o.u(0x6f256f85, 0x25cfcfa0),
4097// o.u(0xeaafea8f, 0xafcaca20), o.u(0x898e89f3, 0x8ef4f47d),
4098// o.u(0x20e9208e, 0xe9474767), o.u(0x28182820, 0x18101038),
4099// o.u(0x64d564de, 0xd56f6f0b), o.u(0x838883fb, 0x88f0f073),
4100// o.u(0xb16fb194, 0x6f4a4afb), o.u(0x967296b8, 0x725c5cca),
4101// o.u(0x6c246c70, 0x24383854), o.u(0x8f108ae, 0xf157575f),
4102// o.u(0x52c752e6, 0xc7737321), o.u(0xf351f335, 0x51979764),
4103// o.u(0x6523658d, 0x23cbcbae), o.u(0x847c8459, 0x7ca1a125),
4104// o.u(0xbf9cbfcb, 0x9ce8e857), o.u(0x6321637c, 0x213e3e5d),
4105// o.u(0x7cdd7c37, 0xdd9696ea), o.u(0x7fdc7fc2, 0xdc61611e),
4106// o.u(0x9186911a, 0x860d0d9c), o.u(0x9485941e, 0x850f0f9b),
4107// o.u(0xab90abdb, 0x90e0e04b), o.u(0xc642c6f8, 0x427c7cba),
4108// o.u(0x57c457e2, 0xc4717126), o.u(0xe5aae583, 0xaacccc29),
4109// o.u(0x73d8733b, 0xd89090e3), o.u(0xf050f0c, 0x5060609),
4110// o.u(0x30103f5, 0x1f7f7f4), o.u(0x36123638, 0x121c1c2a),
4111// o.u(0xfea3fe9f, 0xa3c2c23c), o.u(0xe15fe1d4, 0x5f6a6a8b),
4112// o.u(0x10f91047, 0xf9aeaebe), o.u(0x6bd06bd2, 0xd0696902),
4113// o.u(0xa891a82e, 0x911717bf), o.u(0xe858e829, 0x58999971),
4114// o.u(0x69276974, 0x273a3a53), o.u(0xd0b9d04e, 0xb92727f7),
4115// o.u(0x483848a9, 0x38d9d991), o.u(0x351335cd, 0x13ebebde),
4116// o.u(0xceb3ce56, 0xb32b2be5), o.u(0x55335544, 0x33222277),
4117// o.u(0xd6bbd6bf, 0xbbd2d204), o.u(0x90709049, 0x70a9a939),
4118// o.u(0x8089800e, 0x89070787), o.u(0xf2a7f266, 0xa73333c1),
4119// o.u(0xc1b6c15a, 0xb62d2dec), o.u(0x66226678, 0x223c3c5a),
4120// o.u(0xad92ad2a, 0x921515b8), o.u(0x60206089, 0x20c9c9a9),
4121// o.u(0xdb49db15, 0x4987875c), o.u(0x1aff1a4f, 0xffaaaab0),
4122// o.u(0x887888a0, 0x785050d8), o.u(0x8e7a8e51, 0x7aa5a52b),
4123// o.u(0x8a8f8a06, 0x8f030389), o.u(0x13f813b2, 0xf859594a),
4124// o.u(0x9b809b12, 0x80090992), o.u(0x39173934, 0x171a1a23),
4125// o.u(0x75da75ca, 0xda656510), o.u(0x533153b5, 0x31d7d784),
4126// o.u(0x51c65113, 0xc68484d5), o.u(0xd3b8d3bb, 0xb8d0d003),
4127// o.u(0x5ec35e1f, 0xc38282dc), o.u(0xcbb0cb52, 0xb02929e2),
4128// o.u(0x997799b4, 0x775a5ac3), o.u(0x3311333c, 0x111e1e2d),
4129// o.u(0x46cb46f6, 0xcb7b7b3d), o.u(0x1ffc1f4b, 0xfca8a8b7),
4130// o.u(0x61d661da, 0xd66d6d0c), o.u(0x4e3a4e58, 0x3a2c2c62)
4131// ];
4132
4133// var T7 = [
4134// o.u(0x32f4a5f4, 0x97a5c6c6), o.u(0x6f978497, 0xeb84f8f8),
4135// o.u(0x5eb099b0, 0xc799eeee), o.u(0x7a8c8d8c, 0xf78df6f6),
4136// o.u(0xe8170d17, 0xe50dffff), o.u(0xadcbddc, 0xb7bdd6d6),
4137// o.u(0x16c8b1c8, 0xa7b1dede), o.u(0x6dfc54fc, 0x39549191),
4138// o.u(0x90f050f0, 0xc0506060), o.u(0x7050305, 0x4030202),
4139// o.u(0x2ee0a9e0, 0x87a9cece), o.u(0xd1877d87, 0xac7d5656),
4140// o.u(0xcc2b192b, 0xd519e7e7), o.u(0x13a662a6, 0x7162b5b5),
4141// o.u(0x7c31e631, 0x9ae64d4d), o.u(0x59b59ab5, 0xc39aecec),
4142// o.u(0x40cf45cf, 0x5458f8f), o.u(0xa3bc9dbc, 0x3e9d1f1f),
4143// o.u(0x49c040c0, 0x9408989), o.u(0x68928792, 0xef87fafa),
4144// o.u(0xd03f153f, 0xc515efef), o.u(0x9426eb26, 0x7febb2b2),
4145// o.u(0xce40c940, 0x7c98e8e), o.u(0xe61d0b1d, 0xed0bfbfb),
4146// o.u(0x6e2fec2f, 0x82ec4141), o.u(0x1aa967a9, 0x7d67b3b3),
4147// o.u(0x431cfd1c, 0xbefd5f5f), o.u(0x6025ea25, 0x8aea4545),
4148// o.u(0xf9dabfda, 0x46bf2323), o.u(0x5102f702, 0xa6f75353),
4149// o.u(0x45a196a1, 0xd396e4e4), o.u(0x76ed5bed, 0x2d5b9b9b),
4150// o.u(0x285dc25d, 0xeac27575), o.u(0xc5241c24, 0xd91ce1e1),
4151// o.u(0xd4e9aee9, 0x7aae3d3d), o.u(0xf2be6abe, 0x986a4c4c),
4152// o.u(0x82ee5aee, 0xd85a6c6c), o.u(0xbdc341c3, 0xfc417e7e),
4153// o.u(0xf3060206, 0xf102f5f5), o.u(0x52d14fd1, 0x1d4f8383),
4154// o.u(0x8ce45ce4, 0xd05c6868), o.u(0x5607f407, 0xa2f45151),
4155// o.u(0x8d5c345c, 0xb934d1d1), o.u(0xe1180818, 0xe908f9f9),
4156// o.u(0x4cae93ae, 0xdf93e2e2), o.u(0x3e957395, 0x4d73abab),
4157// o.u(0x97f553f5, 0xc4536262), o.u(0x6b413f41, 0x543f2a2a),
4158// o.u(0x1c140c14, 0x100c0808), o.u(0x63f652f6, 0x31529595),
4159// o.u(0xe9af65af, 0x8c654646), o.u(0x7fe25ee2, 0x215e9d9d),
4160// o.u(0x48782878, 0x60283030), o.u(0xcff8a1f8, 0x6ea13737),
4161// o.u(0x1b110f11, 0x140f0a0a), o.u(0xebc4b5c4, 0x5eb52f2f),
4162// o.u(0x151b091b, 0x1c090e0e), o.u(0x7e5a365a, 0x48362424),
4163// o.u(0xadb69bb6, 0x369b1b1b), o.u(0x98473d47, 0xa53ddfdf),
4164// o.u(0xa76a266a, 0x8126cdcd), o.u(0xf5bb69bb, 0x9c694e4e),
4165// o.u(0x334ccd4c, 0xfecd7f7f), o.u(0x50ba9fba, 0xcf9feaea),
4166// o.u(0x3f2d1b2d, 0x241b1212), o.u(0xa4b99eb9, 0x3a9e1d1d),
4167// o.u(0xc49c749c, 0xb0745858), o.u(0x46722e72, 0x682e3434),
4168// o.u(0x41772d77, 0x6c2d3636), o.u(0x11cdb2cd, 0xa3b2dcdc),
4169// o.u(0x9d29ee29, 0x73eeb4b4), o.u(0x4d16fb16, 0xb6fb5b5b),
4170// o.u(0xa501f601, 0x53f6a4a4), o.u(0xa1d74dd7, 0xec4d7676),
4171// o.u(0x14a361a3, 0x7561b7b7), o.u(0x3449ce49, 0xface7d7d),
4172// o.u(0xdf8d7b8d, 0xa47b5252), o.u(0x9f423e42, 0xa13edddd),
4173// o.u(0xcd937193, 0xbc715e5e), o.u(0xb1a297a2, 0x26971313),
4174// o.u(0xa204f504, 0x57f5a6a6), o.u(0x1b868b8, 0x6968b9b9),
4175// o.u(0x0, 0x0), o.u(0xb5742c74, 0x992cc1c1),
4176// o.u(0xe0a060a0, 0x80604040), o.u(0xc2211f21, 0xdd1fe3e3),
4177// o.u(0x3a43c843, 0xf2c87979), o.u(0x9a2ced2c, 0x77edb6b6),
4178// o.u(0xdd9bed9, 0xb3bed4d4), o.u(0x47ca46ca, 0x1468d8d),
4179// o.u(0x1770d970, 0xced96767), o.u(0xafdd4bdd, 0xe44b7272),
4180// o.u(0xed79de79, 0x33de9494), o.u(0xff67d467, 0x2bd49898),
4181// o.u(0x9323e823, 0x7be8b0b0), o.u(0x5bde4ade, 0x114a8585),
4182// o.u(0x6bd6bbd, 0x6d6bbbbb), o.u(0xbb7e2a7e, 0x912ac5c5),
4183// o.u(0x7b34e534, 0x9ee54f4f), o.u(0xd73a163a, 0xc116eded),
4184// o.u(0xd254c554, 0x17c58686), o.u(0xf862d762, 0x2fd79a9a),
4185// o.u(0x99ff55ff, 0xcc556666), o.u(0xb6a794a7, 0x22941111),
4186// o.u(0xc04acf4a, 0xfcf8a8a), o.u(0xd9301030, 0xc910e9e9),
4187// o.u(0xe0a060a, 0x8060404), o.u(0x66988198, 0xe781fefe),
4188// o.u(0xab0bf00b, 0x5bf0a0a0), o.u(0xb4cc44cc, 0xf0447878),
4189// o.u(0xf0d5bad5, 0x4aba2525), o.u(0x753ee33e, 0x96e34b4b),
4190// o.u(0xac0ef30e, 0x5ff3a2a2), o.u(0x4419fe19, 0xbafe5d5d),
4191// o.u(0xdb5bc05b, 0x1bc08080), o.u(0x80858a85, 0xa8a0505),
4192// o.u(0xd3ecadec, 0x7ead3f3f), o.u(0xfedfbcdf, 0x42bc2121),
4193// o.u(0xa8d848d8, 0xe0487070), o.u(0xfd0c040c, 0xf904f1f1),
4194// o.u(0x197adf7a, 0xc6df6363), o.u(0x2f58c158, 0xeec17777),
4195// o.u(0x309f759f, 0x4575afaf), o.u(0xe7a563a5, 0x84634242),
4196// o.u(0x70503050, 0x40302020), o.u(0xcb2e1a2e, 0xd11ae5e5),
4197// o.u(0xef120e12, 0xe10efdfd), o.u(0x8b76db7, 0x656dbfbf),
4198// o.u(0x55d44cd4, 0x194c8181), o.u(0x243c143c, 0x30141818),
4199// o.u(0x795f355f, 0x4c352626), o.u(0xb2712f71, 0x9d2fc3c3),
4200// o.u(0x8638e138, 0x67e1bebe), o.u(0xc8fda2fd, 0x6aa23535),
4201// o.u(0xc74fcc4f, 0xbcc8888), o.u(0x654b394b, 0x5c392e2e),
4202// o.u(0x6af957f9, 0x3d579393), o.u(0x580df20d, 0xaaf25555),
4203// o.u(0x619d829d, 0xe382fcfc), o.u(0xb3c947c9, 0xf4477a7a),
4204// o.u(0x27efacef, 0x8bacc8c8), o.u(0x8832e732, 0x6fe7baba),
4205// o.u(0x4f7d2b7d, 0x642b3232), o.u(0x42a495a4, 0xd795e6e6),
4206// o.u(0x3bfba0fb, 0x9ba0c0c0), o.u(0xaab398b3, 0x32981919),
4207// o.u(0xf668d168, 0x27d19e9e), o.u(0x22817f81, 0x5d7fa3a3),
4208// o.u(0xeeaa66aa, 0x88664444), o.u(0xd6827e82, 0xa87e5454),
4209// o.u(0xdde6abe6, 0x76ab3b3b), o.u(0x959e839e, 0x16830b0b),
4210// o.u(0xc945ca45, 0x3ca8c8c), o.u(0xbc7b297b, 0x9529c7c7),
4211// o.u(0x56ed36e, 0xd6d36b6b), o.u(0x6c443c44, 0x503c2828),
4212// o.u(0x2c8b798b, 0x5579a7a7), o.u(0x813de23d, 0x63e2bcbc),
4213// o.u(0x31271d27, 0x2c1d1616), o.u(0x379a769a, 0x4176adad),
4214// o.u(0x964d3b4d, 0xad3bdbdb), o.u(0x9efa56fa, 0xc8566464),
4215// o.u(0xa6d24ed2, 0xe84e7474), o.u(0x36221e22, 0x281e1414),
4216// o.u(0xe476db76, 0x3fdb9292), o.u(0x121e0a1e, 0x180a0c0c),
4217// o.u(0xfcb46cb4, 0x906c4848), o.u(0x8f37e437, 0x6be4b8b8),
4218// o.u(0x78e75de7, 0x255d9f9f), o.u(0xfb26eb2, 0x616ebdbd),
4219// o.u(0x692aef2a, 0x86ef4343), o.u(0x35f1a6f1, 0x93a6c4c4),
4220// o.u(0xdae3a8e3, 0x72a83939), o.u(0xc6f7a4f7, 0x62a43131),
4221// o.u(0x8a593759, 0xbd37d3d3), o.u(0x74868b86, 0xff8bf2f2),
4222// o.u(0x83563256, 0xb132d5d5), o.u(0x4ec543c5, 0xd438b8b),
4223// o.u(0x85eb59eb, 0xdc596e6e), o.u(0x18c2b7c2, 0xafb7dada),
4224// o.u(0x8e8f8c8f, 0x28c0101), o.u(0x1dac64ac, 0x7964b1b1),
4225// o.u(0xf16dd26d, 0x23d29c9c), o.u(0x723be03b, 0x92e04949),
4226// o.u(0x1fc7b4c7, 0xabb4d8d8), o.u(0xb915fa15, 0x43faacac),
4227// o.u(0xfa090709, 0xfd07f3f3), o.u(0xa06f256f, 0x8525cfcf),
4228// o.u(0x20eaafea, 0x8fafcaca), o.u(0x7d898e89, 0xf38ef4f4),
4229// o.u(0x6720e920, 0x8ee94747), o.u(0x38281828, 0x20181010),
4230// o.u(0xb64d564, 0xded56f6f), o.u(0x73838883, 0xfb88f0f0),
4231// o.u(0xfbb16fb1, 0x946f4a4a), o.u(0xca967296, 0xb8725c5c),
4232// o.u(0x546c246c, 0x70243838), o.u(0x5f08f108, 0xaef15757),
4233// o.u(0x2152c752, 0xe6c77373), o.u(0x64f351f3, 0x35519797),
4234// o.u(0xae652365, 0x8d23cbcb), o.u(0x25847c84, 0x597ca1a1),
4235// o.u(0x57bf9cbf, 0xcb9ce8e8), o.u(0x5d632163, 0x7c213e3e),
4236// o.u(0xea7cdd7c, 0x37dd9696), o.u(0x1e7fdc7f, 0xc2dc6161),
4237// o.u(0x9c918691, 0x1a860d0d), o.u(0x9b948594, 0x1e850f0f),
4238// o.u(0x4bab90ab, 0xdb90e0e0), o.u(0xbac642c6, 0xf8427c7c),
4239// o.u(0x2657c457, 0xe2c47171), o.u(0x29e5aae5, 0x83aacccc),
4240// o.u(0xe373d873, 0x3bd89090), o.u(0x90f050f, 0xc050606),
4241// o.u(0xf4030103, 0xf501f7f7), o.u(0x2a361236, 0x38121c1c),
4242// o.u(0x3cfea3fe, 0x9fa3c2c2), o.u(0x8be15fe1, 0xd45f6a6a),
4243// o.u(0xbe10f910, 0x47f9aeae), o.u(0x26bd06b, 0xd2d06969),
4244// o.u(0xbfa891a8, 0x2e911717), o.u(0x71e858e8, 0x29589999),
4245// o.u(0x53692769, 0x74273a3a), o.u(0xf7d0b9d0, 0x4eb92727),
4246// o.u(0x91483848, 0xa938d9d9), o.u(0xde351335, 0xcd13ebeb),
4247// o.u(0xe5ceb3ce, 0x56b32b2b), o.u(0x77553355, 0x44332222),
4248// o.u(0x4d6bbd6, 0xbfbbd2d2), o.u(0x39907090, 0x4970a9a9),
4249// o.u(0x87808980, 0xe890707), o.u(0xc1f2a7f2, 0x66a73333),
4250// o.u(0xecc1b6c1, 0x5ab62d2d), o.u(0x5a662266, 0x78223c3c),
4251// o.u(0xb8ad92ad, 0x2a921515), o.u(0xa9602060, 0x8920c9c9),
4252// o.u(0x5cdb49db, 0x15498787), o.u(0xb01aff1a, 0x4fffaaaa),
4253// o.u(0xd8887888, 0xa0785050), o.u(0x2b8e7a8e, 0x517aa5a5),
4254// o.u(0x898a8f8a, 0x68f0303), o.u(0x4a13f813, 0xb2f85959),
4255// o.u(0x929b809b, 0x12800909), o.u(0x23391739, 0x34171a1a),
4256// o.u(0x1075da75, 0xcada6565), o.u(0x84533153, 0xb531d7d7),
4257// o.u(0xd551c651, 0x13c68484), o.u(0x3d3b8d3, 0xbbb8d0d0),
4258// o.u(0xdc5ec35e, 0x1fc38282), o.u(0xe2cbb0cb, 0x52b02929),
4259// o.u(0xc3997799, 0xb4775a5a), o.u(0x2d331133, 0x3c111e1e),
4260// o.u(0x3d46cb46, 0xf6cb7b7b), o.u(0xb71ffc1f, 0x4bfca8a8),
4261// o.u(0xc61d661, 0xdad66d6d), o.u(0x624e3a4e, 0x583a2c2c)
4262// ];
4263
4264var B64 = function(n, x) {
4265 if (n === 7) {
4266 return x.lo & 0xFF;
4267 }
4268 var bits = (7 - n) * 8;
4269 if (bits >= 32) { //faster than >= 32
4270 return (x.hi >>> (bits - 32)) & 0xFF;
4271 }
4272 else {
4273 var bitsOff32 = 32 - bits,
4274 toMoveDown = this.hi << bitsOff32 >>> bitsOff32;
4275 return (x.lo >>> bits | (toMoveDown << bitsOff32)) & 0xFF;
4276 }
4277}
4278
4279var j64 = [o.u(0, 0), o.u(0, 0x10), o.u(0, 0x20), o.u(0, 0x30), o.u(0, 0x40), o.u(0, 0x50), o.u(0, 0x60),
4280 o.u(0, 0x70), o.u(0, 0x80), o.u(0, 0x90), o.u(0, 0xA0), o.u(0, 0xB0), o.u(0, 0xC0),
4281 o.u(0, 0xD0), o.u(0, 0xE0), o.u(0, 0xF0)
4282];
4283
4284var nj64 = [o.u(0xFFFFFFFF, 0xFFFFFFFF), o.u(0xFFFFFFFF, 0xFFFFFFEF), o.u(0xFFFFFFFF, 0xFFFFFFDF), o.u(0xFFFFFFFF, 0xFFFFFFCF), o.u(0xFFFFFFFF, 0xFFFFFFBF), o.u(0xFFFFFFFF, 0xFFFFFFAF), o.u(0xFFFFFFFF, 0xFFFFFF9F),
4285 o.u(0xFFFFFFFF, 0xFFFFFF8F), o.u(0xFFFFFFFF, 0xFFFFFF7F), o.u(0xFFFFFFFF, 0xFFFFFF6F), o.u(0xFFFFFFFF, 0xFFFFFF5F), o.u(0xFFFFFFFF, 0xFFFFFF4F), o.u(0xFFFFFFFF, 0xFFFFFF3F),
4286 o.u(0xFFFFFFFF, 0xFFFFFF2F), o.u(0xFFFFFFFF, 0xFFFFFF1F), o.u(0xFFFFFFFF, 0xFFFFFF0F)
4287];
4288
4289var r64 = [o.u(0, 0), o.u(0, 1), o.u(0, 2), o.u(0, 3), o.u(0, 4), o.u(0, 5), o.u(0, 6), o.u(0, 7),
4290 o.u(0, 8), o.u(0, 9), o.u(0, 10), o.u(0, 11), o.u(0, 12), o.u(0, 13)
4291];
4292
4293var compress = function(int64buf, state) {
4294 var g = new Array(16);
4295 var m = new Array(16);
4296 for (var u = 0; u < 16; u++) {
4297 m[u] = int64buf[u];
4298 g[u] = m[u].xor(state[u]);
4299 }
4300 var t = new Array(16);
4301 for (var r = 0; r < 14; r++) {
4302 for (var i = 0; i < 16; i++) {
4303 g[i].setxor64(j64[i].plus(r64[r]).setShiftLeft(56));
4304 }
4305
4306 for (var u = 0; u < 16; u++) {
4307 t[u] = o.xor64(T0[B64(0, g[u])], T1[B64(1, g[(u + 1) & 0xF])], T2[B64(2, g[(u + 2) & 0xF])], T3[B64(3, g[(u + 3) & 0xF])], T4[B64(4, g[(u + 4) & 0xF])], T5[B64(5, g[(u + 5) & 0xF])], T6[B64(6, g[(u + 6) & 0xF])], T7[B64(7, g[(u + 11) & 0xF])]);
4308 }
4309 var temp = g;
4310 g = t;
4311 t = temp;
4312 }
4313 for (var r = 0; r < 14; r++) {
4314 for (var i = 0; i < 16; i++) {
4315 m[i].setxor64(r64[r], nj64[i]);
4316 }
4317 for (var u = 0; u < 16; u++) {
4318 t[u] = o.xor64(T0[B64(0, m[(u + 1) & 0xF])], T1[B64(1, m[(u + 3) & 0xF])], T2[B64(2, m[(u + 5) & 0xF])], T3[B64(3, m[(u + 11) & 0xF])], T4[B64(4, m[(u + 0) & 0xF])], T5[B64(5, m[(u + 2) & 0xF])], T6[B64(6, m[(u + 4) & 0xF])], T7[B64(7, m[(u + 6) & 0xF])]);
4319 }
4320 var temp = m;
4321 m = t;
4322 t = temp;
4323 }
4324 for (var u = 0; u < 16; u++) {
4325 state[u].setxor64(g[u], m[u]);
4326 }
4327}
4328
4329var final = function(state) {
4330 var g = new Array(16);
4331 o.bufferInsert64(g, 0, state, 16);
4332 var t = new Array(16);
4333 for (var r = 0; r < 14; r++) {
4334
4335 for (var i = 0; i < 16; i++) {
4336 g[i].setxor64(j64[i].plus(r64[r]).setShiftLeft(56));
4337 }
4338
4339 for (var u = 0; u < 16; u++) {
4340 t[u] = o.xor64(T0[B64(0, g[u])], T1[B64(1, g[(u + 1) & 0xF])], T2[B64(2, g[(u + 2) & 0xF])], T3[B64(3, g[(u + 3) & 0xF])], T4[B64(4, g[(u + 4) & 0xF])], T5[B64(5, g[(u + 5) & 0xF])], T6[B64(6, g[(u + 6) & 0xF])], T7[B64(7, g[(u + 11) & 0xF])]);
4341 }
4342 var temp = g;
4343 g = t;
4344 t = temp;
4345 }
4346 for (var u = 0; u < 16; u++)
4347 state[u].setxor64(g[u]);
4348}
4349
4350var groestl = function(ctx, data, len) {
4351 var buf, ptr;
4352 //create a local copy of states
4353 var V = new Array(16);
4354 buf = ctx.buffer;
4355 ptr = ctx.ptr;
4356 if (len < ctx.buffer.length - ptr) {
4357 o.bufferInsert(buf, ptr, data, data.length);
4358 ptr += data.length;
4359 ctx.ptr = ptr;
4360 return;
4361 }
4362 //perform a deep copy of current state
4363 o.bufferInsert(V, 0, ctx.state, 16);
4364 while (len > 0) {
4365 var clen = ctx.buffer.length - ptr;
4366 if (clen > len) clen = len;
4367 o.bufferInsert(buf, ptr, data, clen);
4368 ptr += clen;
4369 data = data.slice(clen);
4370 len -= clen;
4371 if (ptr === ctx.buffer.length) {
4372 var int64Buf = h.bytes2Int64Buffer(buf);
4373 compress(int64Buf, V);
4374 ctx.count.addOne();
4375 ptr = 0;
4376 }
4377 }
4378 ctx.state = V;
4379 ctx.ptr = ptr;
4380}
4381
4382var groestlClose = function(ctx) {
4383 var buf = ctx.buffer;
4384 var ptr = ctx.ptr;
4385 var pad = new Array(136);
4386 var len = buf.length;
4387 var padLen;
4388 var count;
4389 pad[0] = 0x80;
4390 if (ptr < 120) {
4391 padLen = 128 - ptr;
4392 count = ctx.count.plus(o.u(0, 1));
4393 }
4394 else {
4395 padLen = 256 - ptr;
4396 count = ctx.count.plus(o.u(0, 2));
4397 }
4398 o.bufferSet(pad, 1, 0, padLen - 9);
4399 h.bufferEncode64(pad, padLen - 8, count);
4400 groestl(ctx, pad, padLen);
4401 final(ctx.state);
4402 var out = new Array(16);
4403 for (var u = 0, v = 8; u < 8; u++, v++) {
4404 out[2 * u] = ctx.state[v].hi;
4405 out[2 * u + 1] = ctx.state[v].lo;
4406 }
4407 return out;
4408}
4409
4410module.exports = function(input, format, output) {
4411 var msg;
4412 if (format === 1) {
4413 msg = input;
4414 }
4415 else if (format === 2) {
4416 msg = h.int32Buffer2Bytes(input);
4417 }
4418 else {
4419 msg = h.string2bytes(input);
4420 }
4421 var ctx = {};
4422 ctx.state = new Array(16);
4423 for (var i = 0; i < 15; i++) {
4424 ctx.state[i] = new o.u64(0, 0);
4425 }
4426 ctx.state[15] = new o.u64(0, 512);
4427 ctx.ptr = 0;
4428 ctx.count = new o.u64(0,0);
4429 ctx.buffer = new Array(128);
4430 groestl(ctx, msg, msg.length);
4431 var r = groestlClose(ctx, 0, 0);
4432 var out;
4433 if (output === 2) {
4434 out = r;
4435 }
4436 else if (output === 1) {
4437 out = h.int32Buffer2Bytes(r)
4438 }
4439 else {
4440 out = h.int32ArrayToHexString(r)
4441 }
4442 return out;
4443}
4444},{"./helper":29,"./op":30}],29:[function(require,module,exports){
4445'use strict';
4446// String functions
4447
4448var op = require('./op.js');
4449
4450module.exports.int8ArrayToHexString = function toString(array) {
4451 var string = '';
4452
4453 for (var i = 0; i < array.length; i++) {
4454 if (array[i] < 16) {
4455 string += '0' + array[i].toString(16);
4456 }
4457 else {
4458 string += array[i].toString(16);
4459 }
4460 }
4461 return string;
4462}
4463
4464module.exports.int32ArrayToHexString = function toString(array) {
4465 var string = '';
4466 var len = array.length;
4467 for (var i = 0; i < len; i++) {
4468 var s = array[i];
4469 if (s < 0) {
4470 s = 0xFFFFFFFF + array[i] + 1;
4471 }
4472 var l = s.toString(16);
4473 var padding = 8;
4474 while (l.length < padding) {
4475 l = "0" + l;
4476 }
4477 string += l;
4478 }
4479 return string;
4480}
4481
4482module.exports.hex2string = function toString(s) {
4483 for (var c = [], len = s.length, i = 0; i < len; i += 2)
4484 c.push(String.fromCharCode(parseInt(s.substring(i, i + 2), 16)));
4485 return c.join('');
4486}
4487
4488module.exports.hex2bytes = function toString(s) {
4489 for (var c = [], len = s.length, i = 0; i < len; i += 2)
4490 c.push(parseInt(s.substring(i, i + 2), 16));
4491 return c;
4492}
4493/*
4494module.exports.string2hex = function toString(s) {
4495
4496 for (var p = [], len = s.length, i = 0; i < len; i++) {
4497 p.push((256 + s.charCodeAt(i)).toString(16).substring(1));
4498 }
4499 return p.join('');
4500}
4501*/
4502module.exports.string2bytes = function(s) {
4503 var len = s.length;
4504 var b = new Array(len);
4505 var i = 0;
4506 while (i < len) {
4507 b[i] = s.charCodeAt(i);
4508 i++;
4509 }
4510 return b;
4511}
4512/*
4513module.exports.bytes2Int16Buffer = function(b) {
4514 var len = b.length;
4515 var bufferLength = len ? (((len - 1) >>> 1) + 1) : 0;
4516 var buffer = new Array(bufferLength);
4517 var i = 0;
4518 var j = 0;
4519 while (i < len) {
4520 buffer[j] = (buffer[j] << 8) | b[i];
4521 i++;
4522 if (!(i % 2)) j++;
4523 }
4524 return buffer;
4525}
4526*/
4527
4528module.exports.bytes2Int32Buffer = function(b) {
4529 if (!b) return [];
4530 var len = b.length ? (((b.length - 1) >>> 2) + 1) : 0;
4531 var buffer = new Array(len);
4532 var j = 0;
4533 while (j < len) {
4534 buffer[j] = (b[j * 4] << 24) | (b[j * 4 + 1] << 16) | (b[j * 4 + 2] << 8) | b[j * 4 + 3];
4535 j++;
4536 }
4537 return buffer;
4538}
4539/*
4540module.exports.bytes2Int32BufferLeAligned = function(b) {
4541 var len = b.length;
4542 if (!len) return [];
4543 var len2 = len ? (((len - 1) >>> 2) + 1) : 0;
4544 var buffer = new Array(len);
4545 var j = 0;
4546 while (j < len2) {
4547 buffer[j] = (b[j * 4 + 3] << 24) | (b[j * 4 + 2] << 16) | (b[j * 4 + 1] << 8) | b[j * 4];
4548 j++;
4549 };
4550 return buffer;
4551}
4552*/
4553module.exports.bytes2Int64Buffer = function(b) {
4554 if (!b) return [];
4555 var len = b.length ? (((b.length - 1) >>> 3) + 1) : 0;
4556 var buffer = new Array(len);
4557 var j = 0;
4558 while (j < len) {
4559 buffer[j] = new op.u64((b[j * 8] << 24) | (b[j * 8 + 1] << 16) | (b[j * 8 + 2] << 8) | b[j * 8 + 3], (b[j * 8 + 4] << 24) | (b[j * 8 + 5] << 16) | (b[j * 8 + 6] << 8) | b[j * 8 + 7]);
4560 j++;
4561 }
4562 return buffer;
4563}
4564
4565module.exports.bytes2Int64BufferLeAligned = function(b) {
4566 if (!b) return [];
4567 var len = b.length ? ((( b.length - 1) >>> 3) + 1) : 0;
4568 var buffer = new Array(len);
4569 var j = 0;
4570 while (j < len) {
4571 buffer[j] = new op.u64((b[j * 8 + 7] << 24) | (b[j * 8 + 6] << 16) | (b[j * 8 + 5] << 8) | b[j * 8 + 4], (b[j * 8 + 3] << 24) | (b[j * 8 + 2] << 16) | (b[j * 8 + 1] << 8) | b[j * 8]);
4572 j++;
4573 }
4574 return buffer;
4575}
4576
4577module.exports.bufferEncode64leAligned = function(buffer, offset, uint64) {
4578 buffer[offset + 7] = uint64.hi >>> 24;
4579 buffer[offset + 6] = uint64.hi >>> 16 & 0xFF;
4580 buffer[offset + 5] = uint64.hi >>> 8 & 0xFF;
4581 buffer[offset + 4] = uint64.hi & 0xFF;
4582 buffer[offset + 3] = uint64.lo >>> 24;
4583 buffer[offset + 2] = uint64.lo >>> 16 & 0xFF;
4584 buffer[offset + 1] = uint64.lo >>> 8 & 0xFF;
4585 buffer[offset + 0] = uint64.lo & 0xFF;
4586}
4587
4588module.exports.bufferEncode64 = function(buffer, offset, uint64) {
4589 buffer[offset] = uint64.hi >>> 24;
4590 buffer[offset + 1] = uint64.hi >>> 16 & 0xFF;
4591 buffer[offset + 2] = uint64.hi >>> 8 & 0xFF;
4592 buffer[offset + 3] = uint64.hi & 0xFF;
4593 buffer[offset + 4] = uint64.lo >>> 24;
4594 buffer[offset + 5] = uint64.lo >>> 16 & 0xFF;
4595 buffer[offset + 6] = uint64.lo >>> 8 & 0xFF;
4596 buffer[offset + 7] = uint64.lo & 0xFF;
4597}
4598
4599module.exports.int32Buffer2Bytes = function(b) {
4600 var buffer = new Array(b.length);
4601 var len = b.length;
4602 var i = 0;
4603 while (i < len) {
4604 buffer[i * 4] = (b[i] & 0xFF000000) >>> 24;
4605 buffer[i * 4 + 1] = (b[i] & 0x00FF0000) >>> 16;
4606 buffer[i * 4 + 2] = (b[i] & 0x0000FF00) >>> 8;
4607 buffer[i * 4 + 3] = (b[i] & 0x000000FF);
4608 i++;
4609 }
4610 return buffer;
4611}
4612/*
4613module.exports.int64Buffer2Bytes = function(b) {
4614 var buffer = new Array(b.length);
4615 var i = 0;
4616 while (i < b.length) {
4617 buffer[i * 8] = (b[i].hi & 0xFF000000) >>> 24;
4618 buffer[i * 8 + 1] = (b[i].hi & 0x00FF0000) >>> 16;
4619 buffer[i * 8 + 2] = (b[i].hi & 0x0000FF00) >>> 8;
4620 buffer[i * 8 + 3] = (b[i].hi & 0x000000FF);
4621 buffer[i * 8 + 4] = (b[i].lo & 0xFF000000) >>> 24;
4622 buffer[i * 8 + 5] = (b[i].lo & 0x00FF0000) >>> 16;
4623 buffer[i * 8 + 6] = (b[i].lo & 0x0000FF00) >>> 8;
4624 buffer[i * 8 + 7] = (b[i].lo & 0x000000FF);
4625 i++;
4626 }
4627 return buffer;
4628}
4629*/
4630
4631module.exports.string2Int32Buffer = function(s) {
4632 return this.bytes2Int32Buffer(this.string2bytes(s));
4633}
4634
4635var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
4636
4637module.exports.b64Encode = function(input) {
4638 var output = "";
4639 var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
4640 var i = 0;
4641
4642 while (i < input.length) {
4643
4644 chr1 = input[i++];
4645 chr2 = input[i++];
4646 chr3 = input[i++];
4647
4648 enc1 = chr1 >> 2;
4649 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
4650 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
4651 enc4 = chr3 & 63;
4652
4653 if (isNaN(chr2)) {
4654 enc3 = enc4 = 64;
4655 }
4656 else if (isNaN(chr3)) {
4657 enc4 = 64;
4658 }
4659
4660 output +=
4661 keyStr.charAt(enc1) + keyStr.charAt(enc2) +
4662 keyStr.charAt(enc3) + keyStr.charAt(enc4);
4663 }
4664
4665 return output;
4666};
4667
4668module.exports.b64Decode = function(input) {
4669 var output = [];
4670 var chr1, chr2, chr3;
4671 var enc1, enc2, enc3, enc4;
4672 var i = 0;
4673
4674 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
4675
4676 while (i < input.length) {
4677
4678 enc1 = keyStr.indexOf(input.charAt(i++));
4679 enc2 = keyStr.indexOf(input.charAt(i++));
4680 enc3 = keyStr.indexOf(input.charAt(i++));
4681 enc4 = keyStr.indexOf(input.charAt(i++));
4682
4683 chr1 = (enc1 << 2) | (enc2 >> 4);
4684 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
4685 chr3 = ((enc3 & 3) << 6) | enc4;
4686
4687 output.push(chr1);
4688
4689 if (enc3 != 64) {
4690 output.push(chr2);
4691 }
4692 if (enc4 != 64) {
4693 output.push(chr3);
4694 }
4695 }
4696 return output;
4697};
4698},{"./op.js":30}],30:[function(require,module,exports){
4699'use strict';
4700//the right shift is important, it has to do with 32 bit operations in javascript, it will make things faster
4701function u64(h, l) {
4702 this.hi = h >>> 0;
4703 this.lo = l >>> 0;
4704}
4705
4706u64.prototype.set = function(oWord) {
4707 this.lo = oWord.lo;
4708 this.hi = oWord.hi;
4709}
4710
4711u64.prototype.add = function(oWord) {
4712 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
4713
4714 //need to add the respective parts from each number and the carry if on is present..
4715 lowest = (this.lo & 0XFFFF) + (oWord.lo & 0XFFFF);
4716 lowMid = (this.lo >>> 16) + (oWord.lo >>> 16) + (lowest >>> 16);
4717 highMid = (this.hi & 0XFFFF) + (oWord.hi & 0XFFFF) + (lowMid >>> 16);
4718 highest = (this.hi >>> 16) + (oWord.hi >>> 16) + (highMid >>> 16);
4719
4720 //now set the hgih and the low accordingly..
4721 this.lo = (lowMid << 16) | (lowest & 0XFFFF);
4722 this.hi = (highest << 16) | (highMid & 0XFFFF);
4723
4724 return this; //for chaining..
4725};
4726
4727u64.prototype.addOne = function() {
4728 if (this.lo === -1 || this.lo === 0xFFFFFFFF) {
4729 this.lo = 0;
4730 this.hi++;
4731 }
4732 else {
4733 this.lo++;
4734 }
4735}
4736
4737u64.prototype.plus = function(oWord) {
4738 var c = new u64(0, 0);
4739 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
4740
4741 //need to add the respective parts from each number and the carry if on is present..
4742 lowest = (this.lo & 0XFFFF) + (oWord.lo & 0XFFFF);
4743 lowMid = (this.lo >>> 16) + (oWord.lo >>> 16) + (lowest >>> 16);
4744 highMid = (this.hi & 0XFFFF) + (oWord.hi & 0XFFFF) + (lowMid >>> 16);
4745 highest = (this.hi >>> 16) + (oWord.hi >>> 16) + (highMid >>> 16);
4746
4747 //now set the hgih and the low accordingly..
4748 c.lo = (lowMid << 16) | (lowest & 0XFFFF);
4749 c.hi = (highest << 16) | (highMid & 0XFFFF);
4750
4751 return c; //for chaining..
4752};
4753
4754u64.prototype.not = function() {
4755 return new u64(~this.hi, ~this.lo);
4756}
4757
4758u64.prototype.one = function() {
4759 return new u64(0x0, 0x1);
4760}
4761
4762u64.prototype.zero = function() {
4763 return new u64(0x0, 0x0);
4764}
4765
4766u64.prototype.neg = function() {
4767 return this.not().plus(this.one());
4768}
4769
4770u64.prototype.minus = function(oWord) {
4771 return this.plus(oWord.neg());
4772};
4773
4774u64.prototype.isZero = function() {
4775 return (this.lo === 0) && (this.hi === 0);
4776}
4777
4778function isLong(obj) {
4779 return (obj && obj["__isLong__"]) === true;
4780}
4781
4782function fromNumber(value) {
4783 if (isNaN(value) || !isFinite(value))
4784 return this.zero();
4785 var pow32 = (1 << 32);
4786 return new u64((value % pow32) | 0, (value / pow32) | 0);
4787}
4788
4789u64.prototype.multiply = function(multiplier) {
4790 if (this.isZero())
4791 return this.zero();
4792 if (!isLong(multiplier))
4793 multiplier = fromNumber(multiplier);
4794 if (multiplier.isZero())
4795 return this.zero();
4796
4797 // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
4798 // We can skip products that would overflow.
4799
4800 var a48 = this.hi >>> 16;
4801 var a32 = this.hi & 0xFFFF;
4802 var a16 = this.lo >>> 16;
4803 var a00 = this.lo & 0xFFFF;
4804
4805 var b48 = multiplier.hi >>> 16;
4806 var b32 = multiplier.hi & 0xFFFF;
4807 var b16 = multiplier.lo >>> 16;
4808 var b00 = multiplier.lo & 0xFFFF;
4809
4810 var c48 = 0,
4811 c32 = 0,
4812 c16 = 0,
4813 c00 = 0;
4814 c00 += a00 * b00;
4815 c16 += c00 >>> 16;
4816 c00 &= 0xFFFF;
4817 c16 += a16 * b00;
4818 c32 += c16 >>> 16;
4819 c16 &= 0xFFFF;
4820 c16 += a00 * b16;
4821 c32 += c16 >>> 16;
4822 c16 &= 0xFFFF;
4823 c32 += a32 * b00;
4824 c48 += c32 >>> 16;
4825 c32 &= 0xFFFF;
4826 c32 += a16 * b16;
4827 c48 += c32 >>> 16;
4828 c32 &= 0xFFFF;
4829 c32 += a00 * b32;
4830 c48 += c32 >>> 16;
4831 c32 &= 0xFFFF;
4832 c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
4833 c48 &= 0xFFFF;
4834 return new u64((c48 << 16) | c32, (c16 << 16) | c00);
4835};
4836
4837u64.prototype.shiftLeft = function(bits) {
4838 bits = bits % 64;
4839 var c = new u64(0, 0);
4840 if (bits === 0) {
4841 return this.clone();
4842 }
4843 else if (bits > 31) {
4844 c.lo = 0;
4845 c.hi = this.lo << (bits - 32);
4846 }
4847 else {
4848 var toMoveUp = this.lo >>> 32 - bits;
4849 c.lo = this.lo << bits;
4850 c.hi = (this.hi << bits) | toMoveUp;
4851 }
4852 return c; //for chaining..
4853};
4854
4855u64.prototype.setShiftLeft = function(bits) {
4856 if (bits === 0) {
4857 return this;
4858 }
4859 if (bits > 63) {
4860 bits = bits % 64;
4861 }
4862
4863 if (bits > 31) {
4864 this.hi = this.lo << (bits - 32);
4865 this.lo = 0;
4866 }
4867 else {
4868 var toMoveUp = this.lo >>> 32 - bits;
4869 this.lo <<= bits;
4870 this.hi = (this.hi << bits) | toMoveUp;
4871 }
4872 return this; //for chaining..
4873};
4874//Shifts this word by the given number of bits to the right (max 32)..
4875u64.prototype.shiftRight = function(bits) {
4876 bits = bits % 64;
4877 var c = new u64(0, 0);
4878 if (bits === 0) {
4879 return this.clone();
4880 }
4881 else if (bits >= 32) {
4882 c.hi = 0;
4883 c.lo = this.hi >>> (bits - 32);
4884 }
4885 else {
4886 var bitsOff32 = 32 - bits,
4887 toMoveDown = this.hi << bitsOff32 >>> bitsOff32;
4888 c.hi = this.hi >>> bits;
4889 c.lo = this.lo >>> bits | (toMoveDown << bitsOff32);
4890 }
4891 return c; //for chaining..
4892};
4893//Rotates the bits of this word round to the left (max 32)..
4894u64.prototype.rotateLeft = function(bits) {
4895 if (bits > 32) {
4896 return this.rotateRight(64 - bits);
4897 }
4898 var c = new u64(0, 0);
4899 if (bits === 0) {
4900 c.lo = this.lo >>> 0;
4901 c.hi = this.hi >>> 0;
4902 }
4903 else if (bits === 32) { //just switch high and low over in this case..
4904 c.lo = this.hi;
4905 c.hi = this.lo;
4906 }
4907 else {
4908 c.lo = (this.lo << bits) | (this.hi >>> (32 - bits));
4909 c.hi = (this.hi << bits) | (this.lo >>> (32 - bits));
4910 }
4911 return c; //for chaining..
4912};
4913
4914u64.prototype.setRotateLeft = function(bits) {
4915 if (bits > 32) {
4916 return this.setRotateRight(64 - bits);
4917 }
4918 var newHigh;
4919 if (bits === 0) {
4920 return this;
4921 }
4922 else if (bits === 32) { //just switch high and low over in this case..
4923 newHigh = this.lo;
4924 this.lo = this.hi;
4925 this.hi = newHigh;
4926 }
4927 else {
4928 newHigh = (this.hi << bits) | (this.lo >>> (32 - bits));
4929 this.lo = (this.lo << bits) | (this.hi >>> (32 - bits));
4930 this.hi = newHigh;
4931 }
4932 return this; //for chaining..
4933};
4934//Rotates the bits of this word round to the right (max 32)..
4935u64.prototype.rotateRight = function(bits) {
4936 if (bits > 32) {
4937 return this.rotateLeft(64 - bits);
4938 }
4939 var c = new u64(0, 0);
4940 if (bits === 0) {
4941 c.lo = this.lo >>> 0;
4942 c.hi = this.hi >>> 0;
4943 }
4944 else if (bits === 32) { //just switch high and low over in this case..
4945 c.lo = this.hi;
4946 c.hi = this.lo;
4947 }
4948 else {
4949 c.lo = (this.hi << (32 - bits)) | (this.lo >>> bits);
4950 c.hi = (this.lo << (32 - bits)) | (this.hi >>> bits);
4951 }
4952 return c; //for chaining..
4953};
4954u64.prototype.setFlip = function() {
4955 var newHigh;
4956 newHigh = this.lo;
4957 this.lo = this.hi;
4958 this.hi = newHigh;
4959 return this;
4960};
4961//Rotates the bits of this word round to the right (max 32)..
4962u64.prototype.setRotateRight = function(bits) {
4963 if (bits > 32) {
4964 return this.setRotateLeft(64 - bits);
4965 }
4966
4967 if (bits === 0) {
4968 return this;
4969 }
4970 else if (bits === 32) { //just switch high and low over in this case..
4971 var newHigh;
4972 newHigh = this.lo;
4973 this.lo = this.hi;
4974 this.hi = newHigh;
4975 }
4976 else {
4977 newHigh = (this.lo << (32 - bits)) | (this.hi >>> bits);
4978 this.lo = (this.hi << (32 - bits)) | (this.lo >>> bits);
4979 this.hi = newHigh;
4980 }
4981 return this; //for chaining..
4982};
4983//Xors this word with the given other..
4984u64.prototype.xor = function(oWord) {
4985 var c = new u64(0, 0);
4986 c.hi = this.hi ^ oWord.hi;
4987 c.lo = this.lo ^ oWord.lo;
4988 return c; //for chaining..
4989};
4990//Xors this word with the given other..
4991u64.prototype.setxorOne = function(oWord) {
4992 this.hi ^= oWord.hi;
4993 this.lo ^= oWord.lo;
4994 return this; //for chaining..
4995};
4996//Ands this word with the given other..
4997u64.prototype.and = function(oWord) {
4998 var c = new u64(0, 0);
4999 c.hi = this.hi & oWord.hi;
5000 c.lo = this.lo & oWord.lo;
5001 return c; //for chaining..
5002};
5003
5004//Creates a deep copy of this Word..
5005u64.prototype.clone = function() {
5006 return new u64(this.hi, this.lo);
5007};
5008
5009u64.prototype.setxor64 = function() {
5010 var a = arguments;
5011 var i = a.length;
5012 while (i--) {
5013 this.hi ^= a[i].hi;
5014 this.lo ^= a[i].lo;
5015 }
5016 return this;
5017}
5018
5019module.exports.u64 = u64;
5020
5021module.exports.u = function(h, l) {
5022 return new u64(h, l);
5023}
5024/*
5025module.exports.add64 = function(a, b) {
5026 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5027
5028 //need to add the respective parts from each number and the carry if on is present..
5029 lowest = (a.lo & 0XFFFF) + (b.lo & 0XFFFF);
5030 lowMid = (a.lo >>> 16) + (b.lo >>> 16) + (lowest >>> 16);
5031 highMid = (a.hi & 0XFFFF) + (b.hi & 0XFFFF) + (lowMid >>> 16);
5032 highest = (a.hi >>> 16) + (b.hi >>> 16) + (highMid >>> 16);
5033
5034 var r = new this.u64((highest << 16) | (highMid & 0XFFFF), (lowMid << 16) | (lowest & 0XFFFF));
5035
5036 return r;
5037};
5038*/
5039module.exports.xor64 = function() {
5040 var a = arguments,
5041 h = a[0].hi,
5042 l = a[0].lo;
5043 var i = a.length-1;
5044 do {
5045 h ^= a[i].hi;
5046 l ^= a[i].lo;
5047 i--;
5048 } while (i>0);
5049 return new this.u64(h, l);
5050}
5051
5052module.exports.clone64Array = function(array) {
5053 var i = 0;
5054 var len = array.length;
5055 var a = new Array(len);
5056 while(i<len) {
5057 a[i] = array[i];
5058 i++;
5059 }
5060 return a;
5061}
5062
5063//this shouldn't be a problem, but who knows in the future javascript might support 64bits
5064module.exports.t32 = function(x) {
5065 return (x & 0xFFFFFFFF)
5066}
5067
5068module.exports.rotl32 = function(x, c) {
5069 return (((x) << (c)) | ((x) >>> (32 - (c)))) & (0xFFFFFFFF);
5070}
5071
5072module.exports.rotr32 = function(x, c) {
5073 return this.rotl32(x, (32 - (c)));
5074}
5075
5076module.exports.swap32 = function(val) {
5077 return ((val & 0xFF) << 24) |
5078 ((val & 0xFF00) << 8) |
5079 ((val >>> 8) & 0xFF00) |
5080 ((val >>> 24) & 0xFF);
5081}
5082
5083module.exports.swap32Array = function(a) {
5084 //can't do this with map because of support for IE8 (Don't hate me plz).
5085 var i = 0, len = a.length;
5086 var r = new Array(i);
5087 while (i<len) {
5088 r[i] = (this.swap32(a[i]));
5089 i++;
5090 }
5091 return r;
5092}
5093
5094module.exports.xnd64 = function(x, y, z) {
5095 return new this.u64(x.hi ^ ((~y.hi) & z.hi), x.lo ^ ((~y.lo) & z.lo));
5096}
5097/*
5098module.exports.load64 = function(x, i) {
5099 var l = x[i] | (x[i + 1] << 8) | (x[i + 2] << 16) | (x[i + 3] << 24);
5100 var h = x[i + 4] | (x[i + 5] << 8) | (x[i + 6] << 16) | (x[i + 7] << 24);
5101 return new this.u64(h, l);
5102}
5103*/
5104module.exports.bufferInsert = function(buffer, bufferOffset, data, len, dataOffset) {
5105 dataOffset = dataOffset | 0;
5106 var i = 0;
5107 while (i < len) {
5108 buffer[i + bufferOffset] = data[i + dataOffset];
5109 i++;
5110 }
5111}
5112
5113module.exports.bufferInsert64 = function(buffer, bufferOffset, data, len) {
5114 var i = 0;
5115 while (i < len) {
5116 buffer[i + bufferOffset] = data[i].clone();
5117 i++;
5118 }
5119}
5120/*
5121module.exports.buffer2Insert = function(buffer, bufferOffset, bufferOffset2, data, len, len2) {
5122 while (len--) {
5123 var j = len2;
5124 while (j--) {
5125 buffer[len + bufferOffset][j + bufferOffset2] = data[len][j];
5126 }
5127 }
5128}
5129*/
5130module.exports.bufferInsertBackwards = function(buffer, bufferOffset, data, len) {
5131 var i = 0;
5132 while (i < len) {
5133 buffer[i + bufferOffset] = data[len - 1 - i];
5134 i++;
5135 }
5136}
5137
5138module.exports.bufferSet = function(buffer, bufferOffset, value, len) {
5139 var i = 0;
5140 while (i < len) {
5141 buffer[i + bufferOffset] = value;
5142 i++;
5143 }
5144}
5145
5146module.exports.bufferXORInsert = function(buffer, bufferOffset, data, dataOffset, len) {
5147 var i = 0;
5148 while (i < len) {
5149 buffer[i + bufferOffset] ^= data[i + dataOffset];
5150 i++;
5151 }
5152}
5153
5154module.exports.xORTable = function(d, s1, s2, len) {
5155 var i = 0;
5156 while (i < len) {
5157 d[i] = s1[i] ^ s2[i];
5158 i++
5159 }
5160}
5161
5162},{}],31:[function(require,module,exports){
5163'use strict'
5164var Buffer = require('safe-buffer').Buffer
5165var Transform = require('stream').Transform
5166var inherits = require('inherits')
5167
5168function throwIfNotStringOrBuffer (val, prefix) {
5169 if (!Buffer.isBuffer(val) && typeof val !== 'string') {
5170 throw new TypeError(prefix + ' must be a string or a buffer')
5171 }
5172}
5173
5174function HashBase (blockSize) {
5175 Transform.call(this)
5176
5177 this._block = Buffer.allocUnsafe(blockSize)
5178 this._blockSize = blockSize
5179 this._blockOffset = 0
5180 this._length = [0, 0, 0, 0]
5181
5182 this._finalized = false
5183}
5184
5185inherits(HashBase, Transform)
5186
5187HashBase.prototype._transform = function (chunk, encoding, callback) {
5188 var error = null
5189 try {
5190 this.update(chunk, encoding)
5191 } catch (err) {
5192 error = err
5193 }
5194
5195 callback(error)
5196}
5197
5198HashBase.prototype._flush = function (callback) {
5199 var error = null
5200 try {
5201 this.push(this.digest())
5202 } catch (err) {
5203 error = err
5204 }
5205
5206 callback(error)
5207}
5208
5209HashBase.prototype.update = function (data, encoding) {
5210 throwIfNotStringOrBuffer(data, 'Data')
5211 if (this._finalized) throw new Error('Digest already called')
5212 if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
5213
5214 // consume data
5215 var block = this._block
5216 var offset = 0
5217 while (this._blockOffset + data.length - offset >= this._blockSize) {
5218 for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
5219 this._update()
5220 this._blockOffset = 0
5221 }
5222 while (offset < data.length) block[this._blockOffset++] = data[offset++]
5223
5224 // update length
5225 for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
5226 this._length[j] += carry
5227 carry = (this._length[j] / 0x0100000000) | 0
5228 if (carry > 0) this._length[j] -= 0x0100000000 * carry
5229 }
5230
5231 return this
5232}
5233
5234HashBase.prototype._update = function () {
5235 throw new Error('_update is not implemented')
5236}
5237
5238HashBase.prototype.digest = function (encoding) {
5239 if (this._finalized) throw new Error('Digest already called')
5240 this._finalized = true
5241
5242 var digest = this._digest()
5243 if (encoding !== undefined) digest = digest.toString(encoding)
5244
5245 // reset state
5246 this._block.fill(0)
5247 this._blockOffset = 0
5248 for (var i = 0; i < 4; ++i) this._length[i] = 0
5249
5250 return digest
5251}
5252
5253HashBase.prototype._digest = function () {
5254 throw new Error('_digest is not implemented')
5255}
5256
5257module.exports = HashBase
5258
5259},{"inherits":32,"safe-buffer":38,"stream":122}],32:[function(require,module,exports){
5260if (typeof Object.create === 'function') {
5261 // implementation from standard node.js 'util' module
5262 module.exports = function inherits(ctor, superCtor) {
5263 if (superCtor) {
5264 ctor.super_ = superCtor
5265 ctor.prototype = Object.create(superCtor.prototype, {
5266 constructor: {
5267 value: ctor,
5268 enumerable: false,
5269 writable: true,
5270 configurable: true
5271 }
5272 })
5273 }
5274 };
5275} else {
5276 // old school shim for old browsers
5277 module.exports = function inherits(ctor, superCtor) {
5278 if (superCtor) {
5279 ctor.super_ = superCtor
5280 var TempCtor = function () {}
5281 TempCtor.prototype = superCtor.prototype
5282 ctor.prototype = new TempCtor()
5283 ctor.prototype.constructor = ctor
5284 }
5285 }
5286}
5287
5288},{}],33:[function(require,module,exports){
5289'use strict'
5290var inherits = require('inherits')
5291var HashBase = require('hash-base')
5292var Buffer = require('safe-buffer').Buffer
5293
5294var ARRAY16 = new Array(16)
5295
5296function MD5 () {
5297 HashBase.call(this, 64)
5298
5299 // state
5300 this._a = 0x67452301
5301 this._b = 0xefcdab89
5302 this._c = 0x98badcfe
5303 this._d = 0x10325476
5304}
5305
5306inherits(MD5, HashBase)
5307
5308MD5.prototype._update = function () {
5309 var M = ARRAY16
5310 for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4)
5311
5312 var a = this._a
5313 var b = this._b
5314 var c = this._c
5315 var d = this._d
5316
5317 a = fnF(a, b, c, d, M[0], 0xd76aa478, 7)
5318 d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12)
5319 c = fnF(c, d, a, b, M[2], 0x242070db, 17)
5320 b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22)
5321 a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7)
5322 d = fnF(d, a, b, c, M[5], 0x4787c62a, 12)
5323 c = fnF(c, d, a, b, M[6], 0xa8304613, 17)
5324 b = fnF(b, c, d, a, M[7], 0xfd469501, 22)
5325 a = fnF(a, b, c, d, M[8], 0x698098d8, 7)
5326 d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12)
5327 c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17)
5328 b = fnF(b, c, d, a, M[11], 0x895cd7be, 22)
5329 a = fnF(a, b, c, d, M[12], 0x6b901122, 7)
5330 d = fnF(d, a, b, c, M[13], 0xfd987193, 12)
5331 c = fnF(c, d, a, b, M[14], 0xa679438e, 17)
5332 b = fnF(b, c, d, a, M[15], 0x49b40821, 22)
5333
5334 a = fnG(a, b, c, d, M[1], 0xf61e2562, 5)
5335 d = fnG(d, a, b, c, M[6], 0xc040b340, 9)
5336 c = fnG(c, d, a, b, M[11], 0x265e5a51, 14)
5337 b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20)
5338 a = fnG(a, b, c, d, M[5], 0xd62f105d, 5)
5339 d = fnG(d, a, b, c, M[10], 0x02441453, 9)
5340 c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14)
5341 b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20)
5342 a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5)
5343 d = fnG(d, a, b, c, M[14], 0xc33707d6, 9)
5344 c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14)
5345 b = fnG(b, c, d, a, M[8], 0x455a14ed, 20)
5346 a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5)
5347 d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9)
5348 c = fnG(c, d, a, b, M[7], 0x676f02d9, 14)
5349 b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20)
5350
5351 a = fnH(a, b, c, d, M[5], 0xfffa3942, 4)
5352 d = fnH(d, a, b, c, M[8], 0x8771f681, 11)
5353 c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16)
5354 b = fnH(b, c, d, a, M[14], 0xfde5380c, 23)
5355 a = fnH(a, b, c, d, M[1], 0xa4beea44, 4)
5356 d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11)
5357 c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16)
5358 b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23)
5359 a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4)
5360 d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11)
5361 c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16)
5362 b = fnH(b, c, d, a, M[6], 0x04881d05, 23)
5363 a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4)
5364 d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11)
5365 c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16)
5366 b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23)
5367
5368 a = fnI(a, b, c, d, M[0], 0xf4292244, 6)
5369 d = fnI(d, a, b, c, M[7], 0x432aff97, 10)
5370 c = fnI(c, d, a, b, M[14], 0xab9423a7, 15)
5371 b = fnI(b, c, d, a, M[5], 0xfc93a039, 21)
5372 a = fnI(a, b, c, d, M[12], 0x655b59c3, 6)
5373 d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10)
5374 c = fnI(c, d, a, b, M[10], 0xffeff47d, 15)
5375 b = fnI(b, c, d, a, M[1], 0x85845dd1, 21)
5376 a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6)
5377 d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10)
5378 c = fnI(c, d, a, b, M[6], 0xa3014314, 15)
5379 b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21)
5380 a = fnI(a, b, c, d, M[4], 0xf7537e82, 6)
5381 d = fnI(d, a, b, c, M[11], 0xbd3af235, 10)
5382 c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15)
5383 b = fnI(b, c, d, a, M[9], 0xeb86d391, 21)
5384
5385 this._a = (this._a + a) | 0
5386 this._b = (this._b + b) | 0
5387 this._c = (this._c + c) | 0
5388 this._d = (this._d + d) | 0
5389}
5390
5391MD5.prototype._digest = function () {
5392 // create padding and handle blocks
5393 this._block[this._blockOffset++] = 0x80
5394 if (this._blockOffset > 56) {
5395 this._block.fill(0, this._blockOffset, 64)
5396 this._update()
5397 this._blockOffset = 0
5398 }
5399
5400 this._block.fill(0, this._blockOffset, 56)
5401 this._block.writeUInt32LE(this._length[0], 56)
5402 this._block.writeUInt32LE(this._length[1], 60)
5403 this._update()
5404
5405 // produce result
5406 var buffer = Buffer.allocUnsafe(16)
5407 buffer.writeInt32LE(this._a, 0)
5408 buffer.writeInt32LE(this._b, 4)
5409 buffer.writeInt32LE(this._c, 8)
5410 buffer.writeInt32LE(this._d, 12)
5411 return buffer
5412}
5413
5414function rotl (x, n) {
5415 return (x << n) | (x >>> (32 - n))
5416}
5417
5418function fnF (a, b, c, d, m, k, s) {
5419 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + b) | 0
5420}
5421
5422function fnG (a, b, c, d, m, k, s) {
5423 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + b) | 0
5424}
5425
5426function fnH (a, b, c, d, m, k, s) {
5427 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + b) | 0
5428}
5429
5430function fnI (a, b, c, d, m, k, s) {
5431 return (rotl((a + ((c ^ (b | (~d)))) + m + k) | 0, s) + b) | 0
5432}
5433
5434module.exports = MD5
5435
5436},{"hash-base":31,"inherits":32,"safe-buffer":38}],34:[function(require,module,exports){
5437(function (Buffer){
5438// constant-space merkle root calculation algorithm
5439module.exports = function fastRoot (values, digestFn) {
5440 if (!Array.isArray(values)) throw TypeError('Expected values Array')
5441 if (typeof digestFn !== 'function') throw TypeError('Expected digest Function')
5442
5443 var length = values.length
5444 var results = values.concat()
5445
5446 while (length > 1) {
5447 var j = 0
5448
5449 for (var i = 0; i < length; i += 2, ++j) {
5450 var left = results[i]
5451 var right = i + 1 === length ? left : results[i + 1]
5452 var data = Buffer.concat([left, right])
5453
5454 results[j] = digestFn(data)
5455 }
5456
5457 length = j
5458 }
5459
5460 return results[0]
5461}
5462
5463}).call(this,require("buffer").Buffer)
5464},{"buffer":96}],35:[function(require,module,exports){
5465var OPS = require('bitcoin-ops')
5466
5467function encodingLength (i) {
5468 return i < OPS.OP_PUSHDATA1 ? 1
5469 : i <= 0xff ? 2
5470 : i <= 0xffff ? 3
5471 : 5
5472}
5473
5474function encode (buffer, number, offset) {
5475 var size = encodingLength(number)
5476
5477 // ~6 bit
5478 if (size === 1) {
5479 buffer.writeUInt8(number, offset)
5480
5481 // 8 bit
5482 } else if (size === 2) {
5483 buffer.writeUInt8(OPS.OP_PUSHDATA1, offset)
5484 buffer.writeUInt8(number, offset + 1)
5485
5486 // 16 bit
5487 } else if (size === 3) {
5488 buffer.writeUInt8(OPS.OP_PUSHDATA2, offset)
5489 buffer.writeUInt16LE(number, offset + 1)
5490
5491 // 32 bit
5492 } else {
5493 buffer.writeUInt8(OPS.OP_PUSHDATA4, offset)
5494 buffer.writeUInt32LE(number, offset + 1)
5495 }
5496
5497 return size
5498}
5499
5500function decode (buffer, offset) {
5501 var opcode = buffer.readUInt8(offset)
5502 var number, size
5503
5504 // ~6 bit
5505 if (opcode < OPS.OP_PUSHDATA1) {
5506 number = opcode
5507 size = 1
5508
5509 // 8 bit
5510 } else if (opcode === OPS.OP_PUSHDATA1) {
5511 if (offset + 2 > buffer.length) return null
5512 number = buffer.readUInt8(offset + 1)
5513 size = 2
5514
5515 // 16 bit
5516 } else if (opcode === OPS.OP_PUSHDATA2) {
5517 if (offset + 3 > buffer.length) return null
5518 number = buffer.readUInt16LE(offset + 1)
5519 size = 3
5520
5521 // 32 bit
5522 } else {
5523 if (offset + 5 > buffer.length) return null
5524 if (opcode !== OPS.OP_PUSHDATA4) throw new Error('Unexpected opcode')
5525
5526 number = buffer.readUInt32LE(offset + 1)
5527 size = 5
5528 }
5529
5530 return {
5531 opcode: opcode,
5532 number: number,
5533 size: size
5534 }
5535}
5536
5537module.exports = {
5538 encodingLength: encodingLength,
5539 encode: encode,
5540 decode: decode
5541}
5542
5543},{"bitcoin-ops":8}],36:[function(require,module,exports){
5544(function (process,global){
5545'use strict'
5546
5547// limit of Crypto.getRandomValues()
5548// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
5549var MAX_BYTES = 65536
5550
5551// Node supports requesting up to this number of bytes
5552// https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
5553var MAX_UINT32 = 4294967295
5554
5555function oldBrowser () {
5556 throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
5557}
5558
5559var Buffer = require('safe-buffer').Buffer
5560var crypto = global.crypto || global.msCrypto
5561
5562if (crypto && crypto.getRandomValues) {
5563 module.exports = randomBytes
5564} else {
5565 module.exports = oldBrowser
5566}
5567
5568function randomBytes (size, cb) {
5569 // phantomjs needs to throw
5570 if (size > MAX_UINT32) throw new RangeError('requested too many random bytes')
5571
5572 var bytes = Buffer.allocUnsafe(size)
5573
5574 if (size > 0) { // getRandomValues fails on IE if size == 0
5575 if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues
5576 // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
5577 for (var generated = 0; generated < size; generated += MAX_BYTES) {
5578 // buffer.slice automatically checks if the end is past the end of
5579 // the buffer so we don't have to here
5580 crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES))
5581 }
5582 } else {
5583 crypto.getRandomValues(bytes)
5584 }
5585 }
5586
5587 if (typeof cb === 'function') {
5588 return process.nextTick(function () {
5589 cb(null, bytes)
5590 })
5591 }
5592
5593 return bytes
5594}
5595
5596}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
5597},{"_process":105,"safe-buffer":38}],37:[function(require,module,exports){
5598'use strict'
5599var Buffer = require('buffer').Buffer
5600var inherits = require('inherits')
5601var HashBase = require('hash-base')
5602
5603var ARRAY16 = new Array(16)
5604
5605var zl = [
5606 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
5607 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
5608 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
5609 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
5610 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
5611]
5612
5613var zr = [
5614 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
5615 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
5616 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
5617 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
5618 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
5619]
5620
5621var sl = [
5622 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
5623 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
5624 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
5625 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
5626 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
5627]
5628
5629var sr = [
5630 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
5631 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
5632 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
5633 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
5634 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
5635]
5636
5637var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]
5638var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]
5639
5640function RIPEMD160 () {
5641 HashBase.call(this, 64)
5642
5643 // state
5644 this._a = 0x67452301
5645 this._b = 0xefcdab89
5646 this._c = 0x98badcfe
5647 this._d = 0x10325476
5648 this._e = 0xc3d2e1f0
5649}
5650
5651inherits(RIPEMD160, HashBase)
5652
5653RIPEMD160.prototype._update = function () {
5654 var words = ARRAY16
5655 for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4)
5656
5657 var al = this._a | 0
5658 var bl = this._b | 0
5659 var cl = this._c | 0
5660 var dl = this._d | 0
5661 var el = this._e | 0
5662
5663 var ar = this._a | 0
5664 var br = this._b | 0
5665 var cr = this._c | 0
5666 var dr = this._d | 0
5667 var er = this._e | 0
5668
5669 // computation
5670 for (var i = 0; i < 80; i += 1) {
5671 var tl
5672 var tr
5673 if (i < 16) {
5674 tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i])
5675 tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i])
5676 } else if (i < 32) {
5677 tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i])
5678 tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i])
5679 } else if (i < 48) {
5680 tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i])
5681 tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i])
5682 } else if (i < 64) {
5683 tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i])
5684 tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i])
5685 } else { // if (i<80) {
5686 tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i])
5687 tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i])
5688 }
5689
5690 al = el
5691 el = dl
5692 dl = rotl(cl, 10)
5693 cl = bl
5694 bl = tl
5695
5696 ar = er
5697 er = dr
5698 dr = rotl(cr, 10)
5699 cr = br
5700 br = tr
5701 }
5702
5703 // update state
5704 var t = (this._b + cl + dr) | 0
5705 this._b = (this._c + dl + er) | 0
5706 this._c = (this._d + el + ar) | 0
5707 this._d = (this._e + al + br) | 0
5708 this._e = (this._a + bl + cr) | 0
5709 this._a = t
5710}
5711
5712RIPEMD160.prototype._digest = function () {
5713 // create padding and handle blocks
5714 this._block[this._blockOffset++] = 0x80
5715 if (this._blockOffset > 56) {
5716 this._block.fill(0, this._blockOffset, 64)
5717 this._update()
5718 this._blockOffset = 0
5719 }
5720
5721 this._block.fill(0, this._blockOffset, 56)
5722 this._block.writeUInt32LE(this._length[0], 56)
5723 this._block.writeUInt32LE(this._length[1], 60)
5724 this._update()
5725
5726 // produce result
5727 var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20)
5728 buffer.writeInt32LE(this._a, 0)
5729 buffer.writeInt32LE(this._b, 4)
5730 buffer.writeInt32LE(this._c, 8)
5731 buffer.writeInt32LE(this._d, 12)
5732 buffer.writeInt32LE(this._e, 16)
5733 return buffer
5734}
5735
5736function rotl (x, n) {
5737 return (x << n) | (x >>> (32 - n))
5738}
5739
5740function fn1 (a, b, c, d, e, m, k, s) {
5741 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0
5742}
5743
5744function fn2 (a, b, c, d, e, m, k, s) {
5745 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0
5746}
5747
5748function fn3 (a, b, c, d, e, m, k, s) {
5749 return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0
5750}
5751
5752function fn4 (a, b, c, d, e, m, k, s) {
5753 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0
5754}
5755
5756function fn5 (a, b, c, d, e, m, k, s) {
5757 return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0
5758}
5759
5760module.exports = RIPEMD160
5761
5762},{"buffer":96,"hash-base":31,"inherits":32}],38:[function(require,module,exports){
5763/* eslint-disable node/no-deprecated-api */
5764var buffer = require('buffer')
5765var Buffer = buffer.Buffer
5766
5767// alternative to using Object.keys for old browsers
5768function copyProps (src, dst) {
5769 for (var key in src) {
5770 dst[key] = src[key]
5771 }
5772}
5773if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
5774 module.exports = buffer
5775} else {
5776 // Copy properties from require('buffer')
5777 copyProps(buffer, exports)
5778 exports.Buffer = SafeBuffer
5779}
5780
5781function SafeBuffer (arg, encodingOrOffset, length) {
5782 return Buffer(arg, encodingOrOffset, length)
5783}
5784
5785SafeBuffer.prototype = Object.create(Buffer.prototype)
5786
5787// Copy static methods from Buffer
5788copyProps(Buffer, SafeBuffer)
5789
5790SafeBuffer.from = function (arg, encodingOrOffset, length) {
5791 if (typeof arg === 'number') {
5792 throw new TypeError('Argument must not be a number')
5793 }
5794 return Buffer(arg, encodingOrOffset, length)
5795}
5796
5797SafeBuffer.alloc = function (size, fill, encoding) {
5798 if (typeof size !== 'number') {
5799 throw new TypeError('Argument must be a number')
5800 }
5801 var buf = Buffer(size)
5802 if (fill !== undefined) {
5803 if (typeof encoding === 'string') {
5804 buf.fill(fill, encoding)
5805 } else {
5806 buf.fill(fill)
5807 }
5808 } else {
5809 buf.fill(0)
5810 }
5811 return buf
5812}
5813
5814SafeBuffer.allocUnsafe = function (size) {
5815 if (typeof size !== 'number') {
5816 throw new TypeError('Argument must be a number')
5817 }
5818 return Buffer(size)
5819}
5820
5821SafeBuffer.allocUnsafeSlow = function (size) {
5822 if (typeof size !== 'number') {
5823 throw new TypeError('Argument must be a number')
5824 }
5825 return buffer.SlowBuffer(size)
5826}
5827
5828},{"buffer":96}],39:[function(require,module,exports){
5829var Buffer = require('safe-buffer').Buffer
5830
5831// prototype class for hash functions
5832function Hash (blockSize, finalSize) {
5833 this._block = Buffer.alloc(blockSize)
5834 this._finalSize = finalSize
5835 this._blockSize = blockSize
5836 this._len = 0
5837}
5838
5839Hash.prototype.update = function (data, enc) {
5840 if (typeof data === 'string') {
5841 enc = enc || 'utf8'
5842 data = Buffer.from(data, enc)
5843 }
5844
5845 var block = this._block
5846 var blockSize = this._blockSize
5847 var length = data.length
5848 var accum = this._len
5849
5850 for (var offset = 0; offset < length;) {
5851 var assigned = accum % blockSize
5852 var remainder = Math.min(length - offset, blockSize - assigned)
5853
5854 for (var i = 0; i < remainder; i++) {
5855 block[assigned + i] = data[offset + i]
5856 }
5857
5858 accum += remainder
5859 offset += remainder
5860
5861 if ((accum % blockSize) === 0) {
5862 this._update(block)
5863 }
5864 }
5865
5866 this._len += length
5867 return this
5868}
5869
5870Hash.prototype.digest = function (enc) {
5871 var rem = this._len % this._blockSize
5872
5873 this._block[rem] = 0x80
5874
5875 // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
5876 // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
5877 this._block.fill(0, rem + 1)
5878
5879 if (rem >= this._finalSize) {
5880 this._update(this._block)
5881 this._block.fill(0)
5882 }
5883
5884 var bits = this._len * 8
5885
5886 // uint32
5887 if (bits <= 0xffffffff) {
5888 this._block.writeUInt32BE(bits, this._blockSize - 4)
5889
5890 // uint64
5891 } else {
5892 var lowBits = (bits & 0xffffffff) >>> 0
5893 var highBits = (bits - lowBits) / 0x100000000
5894
5895 this._block.writeUInt32BE(highBits, this._blockSize - 8)
5896 this._block.writeUInt32BE(lowBits, this._blockSize - 4)
5897 }
5898
5899 this._update(this._block)
5900 var hash = this._hash()
5901
5902 return enc ? hash.toString(enc) : hash
5903}
5904
5905Hash.prototype._update = function () {
5906 throw new Error('_update must be implemented by subclass')
5907}
5908
5909module.exports = Hash
5910
5911},{"safe-buffer":38}],40:[function(require,module,exports){
5912var exports = module.exports = function SHA (algorithm) {
5913 algorithm = algorithm.toLowerCase()
5914
5915 var Algorithm = exports[algorithm]
5916 if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
5917
5918 return new Algorithm()
5919}
5920
5921exports.sha = require('./sha')
5922exports.sha1 = require('./sha1')
5923exports.sha224 = require('./sha224')
5924exports.sha256 = require('./sha256')
5925exports.sha384 = require('./sha384')
5926exports.sha512 = require('./sha512')
5927
5928},{"./sha":41,"./sha1":42,"./sha224":43,"./sha256":44,"./sha384":45,"./sha512":46}],41:[function(require,module,exports){
5929/*
5930 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
5931 * in FIPS PUB 180-1
5932 * This source code is derived from sha1.js of the same repository.
5933 * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
5934 * operation was added.
5935 */
5936
5937var inherits = require('inherits')
5938var Hash = require('./hash')
5939var Buffer = require('safe-buffer').Buffer
5940
5941var K = [
5942 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
5943]
5944
5945var W = new Array(80)
5946
5947function Sha () {
5948 this.init()
5949 this._w = W
5950
5951 Hash.call(this, 64, 56)
5952}
5953
5954inherits(Sha, Hash)
5955
5956Sha.prototype.init = function () {
5957 this._a = 0x67452301
5958 this._b = 0xefcdab89
5959 this._c = 0x98badcfe
5960 this._d = 0x10325476
5961 this._e = 0xc3d2e1f0
5962
5963 return this
5964}
5965
5966function rotl5 (num) {
5967 return (num << 5) | (num >>> 27)
5968}
5969
5970function rotl30 (num) {
5971 return (num << 30) | (num >>> 2)
5972}
5973
5974function ft (s, b, c, d) {
5975 if (s === 0) return (b & c) | ((~b) & d)
5976 if (s === 2) return (b & c) | (b & d) | (c & d)
5977 return b ^ c ^ d
5978}
5979
5980Sha.prototype._update = function (M) {
5981 var W = this._w
5982
5983 var a = this._a | 0
5984 var b = this._b | 0
5985 var c = this._c | 0
5986 var d = this._d | 0
5987 var e = this._e | 0
5988
5989 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
5990 for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
5991
5992 for (var j = 0; j < 80; ++j) {
5993 var s = ~~(j / 20)
5994 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
5995
5996 e = d
5997 d = c
5998 c = rotl30(b)
5999 b = a
6000 a = t
6001 }
6002
6003 this._a = (a + this._a) | 0
6004 this._b = (b + this._b) | 0
6005 this._c = (c + this._c) | 0
6006 this._d = (d + this._d) | 0
6007 this._e = (e + this._e) | 0
6008}
6009
6010Sha.prototype._hash = function () {
6011 var H = Buffer.allocUnsafe(20)
6012
6013 H.writeInt32BE(this._a | 0, 0)
6014 H.writeInt32BE(this._b | 0, 4)
6015 H.writeInt32BE(this._c | 0, 8)
6016 H.writeInt32BE(this._d | 0, 12)
6017 H.writeInt32BE(this._e | 0, 16)
6018
6019 return H
6020}
6021
6022module.exports = Sha
6023
6024},{"./hash":39,"inherits":32,"safe-buffer":38}],42:[function(require,module,exports){
6025/*
6026 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
6027 * in FIPS PUB 180-1
6028 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
6029 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6030 * Distributed under the BSD License
6031 * See http://pajhome.org.uk/crypt/md5 for details.
6032 */
6033
6034var inherits = require('inherits')
6035var Hash = require('./hash')
6036var Buffer = require('safe-buffer').Buffer
6037
6038var K = [
6039 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6040]
6041
6042var W = new Array(80)
6043
6044function Sha1 () {
6045 this.init()
6046 this._w = W
6047
6048 Hash.call(this, 64, 56)
6049}
6050
6051inherits(Sha1, Hash)
6052
6053Sha1.prototype.init = function () {
6054 this._a = 0x67452301
6055 this._b = 0xefcdab89
6056 this._c = 0x98badcfe
6057 this._d = 0x10325476
6058 this._e = 0xc3d2e1f0
6059
6060 return this
6061}
6062
6063function rotl1 (num) {
6064 return (num << 1) | (num >>> 31)
6065}
6066
6067function rotl5 (num) {
6068 return (num << 5) | (num >>> 27)
6069}
6070
6071function rotl30 (num) {
6072 return (num << 30) | (num >>> 2)
6073}
6074
6075function ft (s, b, c, d) {
6076 if (s === 0) return (b & c) | ((~b) & d)
6077 if (s === 2) return (b & c) | (b & d) | (c & d)
6078 return b ^ c ^ d
6079}
6080
6081Sha1.prototype._update = function (M) {
6082 var W = this._w
6083
6084 var a = this._a | 0
6085 var b = this._b | 0
6086 var c = this._c | 0
6087 var d = this._d | 0
6088 var e = this._e | 0
6089
6090 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
6091 for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
6092
6093 for (var j = 0; j < 80; ++j) {
6094 var s = ~~(j / 20)
6095 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
6096
6097 e = d
6098 d = c
6099 c = rotl30(b)
6100 b = a
6101 a = t
6102 }
6103
6104 this._a = (a + this._a) | 0
6105 this._b = (b + this._b) | 0
6106 this._c = (c + this._c) | 0
6107 this._d = (d + this._d) | 0
6108 this._e = (e + this._e) | 0
6109}
6110
6111Sha1.prototype._hash = function () {
6112 var H = Buffer.allocUnsafe(20)
6113
6114 H.writeInt32BE(this._a | 0, 0)
6115 H.writeInt32BE(this._b | 0, 4)
6116 H.writeInt32BE(this._c | 0, 8)
6117 H.writeInt32BE(this._d | 0, 12)
6118 H.writeInt32BE(this._e | 0, 16)
6119
6120 return H
6121}
6122
6123module.exports = Sha1
6124
6125},{"./hash":39,"inherits":32,"safe-buffer":38}],43:[function(require,module,exports){
6126/**
6127 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
6128 * in FIPS 180-2
6129 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
6130 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6131 *
6132 */
6133
6134var inherits = require('inherits')
6135var Sha256 = require('./sha256')
6136var Hash = require('./hash')
6137var Buffer = require('safe-buffer').Buffer
6138
6139var W = new Array(64)
6140
6141function Sha224 () {
6142 this.init()
6143
6144 this._w = W // new Array(64)
6145
6146 Hash.call(this, 64, 56)
6147}
6148
6149inherits(Sha224, Sha256)
6150
6151Sha224.prototype.init = function () {
6152 this._a = 0xc1059ed8
6153 this._b = 0x367cd507
6154 this._c = 0x3070dd17
6155 this._d = 0xf70e5939
6156 this._e = 0xffc00b31
6157 this._f = 0x68581511
6158 this._g = 0x64f98fa7
6159 this._h = 0xbefa4fa4
6160
6161 return this
6162}
6163
6164Sha224.prototype._hash = function () {
6165 var H = Buffer.allocUnsafe(28)
6166
6167 H.writeInt32BE(this._a, 0)
6168 H.writeInt32BE(this._b, 4)
6169 H.writeInt32BE(this._c, 8)
6170 H.writeInt32BE(this._d, 12)
6171 H.writeInt32BE(this._e, 16)
6172 H.writeInt32BE(this._f, 20)
6173 H.writeInt32BE(this._g, 24)
6174
6175 return H
6176}
6177
6178module.exports = Sha224
6179
6180},{"./hash":39,"./sha256":44,"inherits":32,"safe-buffer":38}],44:[function(require,module,exports){
6181/**
6182 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
6183 * in FIPS 180-2
6184 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
6185 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6186 *
6187 */
6188
6189var inherits = require('inherits')
6190var Hash = require('./hash')
6191var Buffer = require('safe-buffer').Buffer
6192
6193var K = [
6194 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
6195 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
6196 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
6197 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
6198 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
6199 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
6200 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
6201 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
6202 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
6203 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
6204 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
6205 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
6206 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
6207 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
6208 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
6209 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
6210]
6211
6212var W = new Array(64)
6213
6214function Sha256 () {
6215 this.init()
6216
6217 this._w = W // new Array(64)
6218
6219 Hash.call(this, 64, 56)
6220}
6221
6222inherits(Sha256, Hash)
6223
6224Sha256.prototype.init = function () {
6225 this._a = 0x6a09e667
6226 this._b = 0xbb67ae85
6227 this._c = 0x3c6ef372
6228 this._d = 0xa54ff53a
6229 this._e = 0x510e527f
6230 this._f = 0x9b05688c
6231 this._g = 0x1f83d9ab
6232 this._h = 0x5be0cd19
6233
6234 return this
6235}
6236
6237function ch (x, y, z) {
6238 return z ^ (x & (y ^ z))
6239}
6240
6241function maj (x, y, z) {
6242 return (x & y) | (z & (x | y))
6243}
6244
6245function sigma0 (x) {
6246 return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
6247}
6248
6249function sigma1 (x) {
6250 return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
6251}
6252
6253function gamma0 (x) {
6254 return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
6255}
6256
6257function gamma1 (x) {
6258 return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
6259}
6260
6261Sha256.prototype._update = function (M) {
6262 var W = this._w
6263
6264 var a = this._a | 0
6265 var b = this._b | 0
6266 var c = this._c | 0
6267 var d = this._d | 0
6268 var e = this._e | 0
6269 var f = this._f | 0
6270 var g = this._g | 0
6271 var h = this._h | 0
6272
6273 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
6274 for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
6275
6276 for (var j = 0; j < 64; ++j) {
6277 var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
6278 var T2 = (sigma0(a) + maj(a, b, c)) | 0
6279
6280 h = g
6281 g = f
6282 f = e
6283 e = (d + T1) | 0
6284 d = c
6285 c = b
6286 b = a
6287 a = (T1 + T2) | 0
6288 }
6289
6290 this._a = (a + this._a) | 0
6291 this._b = (b + this._b) | 0
6292 this._c = (c + this._c) | 0
6293 this._d = (d + this._d) | 0
6294 this._e = (e + this._e) | 0
6295 this._f = (f + this._f) | 0
6296 this._g = (g + this._g) | 0
6297 this._h = (h + this._h) | 0
6298}
6299
6300Sha256.prototype._hash = function () {
6301 var H = Buffer.allocUnsafe(32)
6302
6303 H.writeInt32BE(this._a, 0)
6304 H.writeInt32BE(this._b, 4)
6305 H.writeInt32BE(this._c, 8)
6306 H.writeInt32BE(this._d, 12)
6307 H.writeInt32BE(this._e, 16)
6308 H.writeInt32BE(this._f, 20)
6309 H.writeInt32BE(this._g, 24)
6310 H.writeInt32BE(this._h, 28)
6311
6312 return H
6313}
6314
6315module.exports = Sha256
6316
6317},{"./hash":39,"inherits":32,"safe-buffer":38}],45:[function(require,module,exports){
6318var inherits = require('inherits')
6319var SHA512 = require('./sha512')
6320var Hash = require('./hash')
6321var Buffer = require('safe-buffer').Buffer
6322
6323var W = new Array(160)
6324
6325function Sha384 () {
6326 this.init()
6327 this._w = W
6328
6329 Hash.call(this, 128, 112)
6330}
6331
6332inherits(Sha384, SHA512)
6333
6334Sha384.prototype.init = function () {
6335 this._ah = 0xcbbb9d5d
6336 this._bh = 0x629a292a
6337 this._ch = 0x9159015a
6338 this._dh = 0x152fecd8
6339 this._eh = 0x67332667
6340 this._fh = 0x8eb44a87
6341 this._gh = 0xdb0c2e0d
6342 this._hh = 0x47b5481d
6343
6344 this._al = 0xc1059ed8
6345 this._bl = 0x367cd507
6346 this._cl = 0x3070dd17
6347 this._dl = 0xf70e5939
6348 this._el = 0xffc00b31
6349 this._fl = 0x68581511
6350 this._gl = 0x64f98fa7
6351 this._hl = 0xbefa4fa4
6352
6353 return this
6354}
6355
6356Sha384.prototype._hash = function () {
6357 var H = Buffer.allocUnsafe(48)
6358
6359 function writeInt64BE (h, l, offset) {
6360 H.writeInt32BE(h, offset)
6361 H.writeInt32BE(l, offset + 4)
6362 }
6363
6364 writeInt64BE(this._ah, this._al, 0)
6365 writeInt64BE(this._bh, this._bl, 8)
6366 writeInt64BE(this._ch, this._cl, 16)
6367 writeInt64BE(this._dh, this._dl, 24)
6368 writeInt64BE(this._eh, this._el, 32)
6369 writeInt64BE(this._fh, this._fl, 40)
6370
6371 return H
6372}
6373
6374module.exports = Sha384
6375
6376},{"./hash":39,"./sha512":46,"inherits":32,"safe-buffer":38}],46:[function(require,module,exports){
6377var inherits = require('inherits')
6378var Hash = require('./hash')
6379var Buffer = require('safe-buffer').Buffer
6380
6381var K = [
6382 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
6383 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
6384 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
6385 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
6386 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
6387 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
6388 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
6389 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
6390 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
6391 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
6392 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
6393 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
6394 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
6395 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
6396 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
6397 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
6398 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
6399 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
6400 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
6401 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
6402 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
6403 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
6404 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
6405 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
6406 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
6407 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
6408 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
6409 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
6410 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
6411 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
6412 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
6413 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
6414 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
6415 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
6416 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
6417 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
6418 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
6419 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
6420 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
6421 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
6422]
6423
6424var W = new Array(160)
6425
6426function Sha512 () {
6427 this.init()
6428 this._w = W
6429
6430 Hash.call(this, 128, 112)
6431}
6432
6433inherits(Sha512, Hash)
6434
6435Sha512.prototype.init = function () {
6436 this._ah = 0x6a09e667
6437 this._bh = 0xbb67ae85
6438 this._ch = 0x3c6ef372
6439 this._dh = 0xa54ff53a
6440 this._eh = 0x510e527f
6441 this._fh = 0x9b05688c
6442 this._gh = 0x1f83d9ab
6443 this._hh = 0x5be0cd19
6444
6445 this._al = 0xf3bcc908
6446 this._bl = 0x84caa73b
6447 this._cl = 0xfe94f82b
6448 this._dl = 0x5f1d36f1
6449 this._el = 0xade682d1
6450 this._fl = 0x2b3e6c1f
6451 this._gl = 0xfb41bd6b
6452 this._hl = 0x137e2179
6453
6454 return this
6455}
6456
6457function Ch (x, y, z) {
6458 return z ^ (x & (y ^ z))
6459}
6460
6461function maj (x, y, z) {
6462 return (x & y) | (z & (x | y))
6463}
6464
6465function sigma0 (x, xl) {
6466 return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
6467}
6468
6469function sigma1 (x, xl) {
6470 return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
6471}
6472
6473function Gamma0 (x, xl) {
6474 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
6475}
6476
6477function Gamma0l (x, xl) {
6478 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
6479}
6480
6481function Gamma1 (x, xl) {
6482 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
6483}
6484
6485function Gamma1l (x, xl) {
6486 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
6487}
6488
6489function getCarry (a, b) {
6490 return (a >>> 0) < (b >>> 0) ? 1 : 0
6491}
6492
6493Sha512.prototype._update = function (M) {
6494 var W = this._w
6495
6496 var ah = this._ah | 0
6497 var bh = this._bh | 0
6498 var ch = this._ch | 0
6499 var dh = this._dh | 0
6500 var eh = this._eh | 0
6501 var fh = this._fh | 0
6502 var gh = this._gh | 0
6503 var hh = this._hh | 0
6504
6505 var al = this._al | 0
6506 var bl = this._bl | 0
6507 var cl = this._cl | 0
6508 var dl = this._dl | 0
6509 var el = this._el | 0
6510 var fl = this._fl | 0
6511 var gl = this._gl | 0
6512 var hl = this._hl | 0
6513
6514 for (var i = 0; i < 32; i += 2) {
6515 W[i] = M.readInt32BE(i * 4)
6516 W[i + 1] = M.readInt32BE(i * 4 + 4)
6517 }
6518 for (; i < 160; i += 2) {
6519 var xh = W[i - 15 * 2]
6520 var xl = W[i - 15 * 2 + 1]
6521 var gamma0 = Gamma0(xh, xl)
6522 var gamma0l = Gamma0l(xl, xh)
6523
6524 xh = W[i - 2 * 2]
6525 xl = W[i - 2 * 2 + 1]
6526 var gamma1 = Gamma1(xh, xl)
6527 var gamma1l = Gamma1l(xl, xh)
6528
6529 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
6530 var Wi7h = W[i - 7 * 2]
6531 var Wi7l = W[i - 7 * 2 + 1]
6532
6533 var Wi16h = W[i - 16 * 2]
6534 var Wi16l = W[i - 16 * 2 + 1]
6535
6536 var Wil = (gamma0l + Wi7l) | 0
6537 var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
6538 Wil = (Wil + gamma1l) | 0
6539 Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
6540 Wil = (Wil + Wi16l) | 0
6541 Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
6542
6543 W[i] = Wih
6544 W[i + 1] = Wil
6545 }
6546
6547 for (var j = 0; j < 160; j += 2) {
6548 Wih = W[j]
6549 Wil = W[j + 1]
6550
6551 var majh = maj(ah, bh, ch)
6552 var majl = maj(al, bl, cl)
6553
6554 var sigma0h = sigma0(ah, al)
6555 var sigma0l = sigma0(al, ah)
6556 var sigma1h = sigma1(eh, el)
6557 var sigma1l = sigma1(el, eh)
6558
6559 // t1 = h + sigma1 + ch + K[j] + W[j]
6560 var Kih = K[j]
6561 var Kil = K[j + 1]
6562
6563 var chh = Ch(eh, fh, gh)
6564 var chl = Ch(el, fl, gl)
6565
6566 var t1l = (hl + sigma1l) | 0
6567 var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
6568 t1l = (t1l + chl) | 0
6569 t1h = (t1h + chh + getCarry(t1l, chl)) | 0
6570 t1l = (t1l + Kil) | 0
6571 t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
6572 t1l = (t1l + Wil) | 0
6573 t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
6574
6575 // t2 = sigma0 + maj
6576 var t2l = (sigma0l + majl) | 0
6577 var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
6578
6579 hh = gh
6580 hl = gl
6581 gh = fh
6582 gl = fl
6583 fh = eh
6584 fl = el
6585 el = (dl + t1l) | 0
6586 eh = (dh + t1h + getCarry(el, dl)) | 0
6587 dh = ch
6588 dl = cl
6589 ch = bh
6590 cl = bl
6591 bh = ah
6592 bl = al
6593 al = (t1l + t2l) | 0
6594 ah = (t1h + t2h + getCarry(al, t1l)) | 0
6595 }
6596
6597 this._al = (this._al + al) | 0
6598 this._bl = (this._bl + bl) | 0
6599 this._cl = (this._cl + cl) | 0
6600 this._dl = (this._dl + dl) | 0
6601 this._el = (this._el + el) | 0
6602 this._fl = (this._fl + fl) | 0
6603 this._gl = (this._gl + gl) | 0
6604 this._hl = (this._hl + hl) | 0
6605
6606 this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
6607 this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
6608 this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
6609 this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
6610 this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
6611 this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
6612 this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
6613 this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
6614}
6615
6616Sha512.prototype._hash = function () {
6617 var H = Buffer.allocUnsafe(64)
6618
6619 function writeInt64BE (h, l, offset) {
6620 H.writeInt32BE(h, offset)
6621 H.writeInt32BE(l, offset + 4)
6622 }
6623
6624 writeInt64BE(this._ah, this._al, 0)
6625 writeInt64BE(this._bh, this._bl, 8)
6626 writeInt64BE(this._ch, this._cl, 16)
6627 writeInt64BE(this._dh, this._dl, 24)
6628 writeInt64BE(this._eh, this._el, 32)
6629 writeInt64BE(this._fh, this._fl, 40)
6630 writeInt64BE(this._gh, this._gl, 48)
6631 writeInt64BE(this._hh, this._hl, 56)
6632
6633 return H
6634}
6635
6636module.exports = Sha512
6637
6638},{"./hash":39,"inherits":32,"safe-buffer":38}],47:[function(require,module,exports){
6639var native = require('./native')
6640
6641function getTypeName (fn) {
6642 return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1]
6643}
6644
6645function getValueTypeName (value) {
6646 return native.Nil(value) ? '' : getTypeName(value.constructor)
6647}
6648
6649function getValue (value) {
6650 if (native.Function(value)) return ''
6651 if (native.String(value)) return JSON.stringify(value)
6652 if (value && native.Object(value)) return ''
6653 return value
6654}
6655
6656function captureStackTrace (e, t) {
6657 if (Error.captureStackTrace) {
6658 Error.captureStackTrace(e, t)
6659 }
6660}
6661
6662function tfJSON (type) {
6663 if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type)
6664 if (native.Array(type)) return 'Array'
6665 if (type && native.Object(type)) return 'Object'
6666
6667 return type !== undefined ? type : ''
6668}
6669
6670function tfErrorString (type, value, valueTypeName) {
6671 var valueJson = getValue(value)
6672
6673 return 'Expected ' + tfJSON(type) + ', got' +
6674 (valueTypeName !== '' ? ' ' + valueTypeName : '') +
6675 (valueJson !== '' ? ' ' + valueJson : '')
6676}
6677
6678function TfTypeError (type, value, valueTypeName) {
6679 valueTypeName = valueTypeName || getValueTypeName(value)
6680 this.message = tfErrorString(type, value, valueTypeName)
6681
6682 captureStackTrace(this, TfTypeError)
6683 this.__type = type
6684 this.__value = value
6685 this.__valueTypeName = valueTypeName
6686}
6687
6688TfTypeError.prototype = Object.create(Error.prototype)
6689TfTypeError.prototype.constructor = TfTypeError
6690
6691function tfPropertyErrorString (type, label, name, value, valueTypeName) {
6692 var description = '" of type '
6693 if (label === 'key') description = '" with key type '
6694
6695 return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName)
6696}
6697
6698function TfPropertyTypeError (type, property, label, value, valueTypeName) {
6699 if (type) {
6700 valueTypeName = valueTypeName || getValueTypeName(value)
6701 this.message = tfPropertyErrorString(type, label, property, value, valueTypeName)
6702 } else {
6703 this.message = 'Unexpected property "' + property + '"'
6704 }
6705
6706 captureStackTrace(this, TfTypeError)
6707 this.__label = label
6708 this.__property = property
6709 this.__type = type
6710 this.__value = value
6711 this.__valueTypeName = valueTypeName
6712}
6713
6714TfPropertyTypeError.prototype = Object.create(Error.prototype)
6715TfPropertyTypeError.prototype.constructor = TfTypeError
6716
6717function tfCustomError (expected, actual) {
6718 return new TfTypeError(expected, {}, actual)
6719}
6720
6721function tfSubError (e, property, label) {
6722 // sub child?
6723 if (e instanceof TfPropertyTypeError) {
6724 property = property + '.' + e.__property
6725
6726 e = new TfPropertyTypeError(
6727 e.__type, property, e.__label, e.__value, e.__valueTypeName
6728 )
6729
6730 // child?
6731 } else if (e instanceof TfTypeError) {
6732 e = new TfPropertyTypeError(
6733 e.__type, property, label, e.__value, e.__valueTypeName
6734 )
6735 }
6736
6737 captureStackTrace(e)
6738 return e
6739}
6740
6741module.exports = {
6742 TfTypeError: TfTypeError,
6743 TfPropertyTypeError: TfPropertyTypeError,
6744 tfCustomError: tfCustomError,
6745 tfSubError: tfSubError,
6746 tfJSON: tfJSON,
6747 getValueTypeName: getValueTypeName
6748}
6749
6750},{"./native":50}],48:[function(require,module,exports){
6751(function (Buffer){
6752var NATIVE = require('./native')
6753var ERRORS = require('./errors')
6754
6755function _Buffer (value) {
6756 return Buffer.isBuffer(value)
6757}
6758
6759function Hex (value) {
6760 return typeof value === 'string' && /^([0-9a-f]{2})+$/i.test(value)
6761}
6762
6763function _LengthN (type, length) {
6764 var name = type.toJSON()
6765
6766 function Length (value) {
6767 if (!type(value)) return false
6768 if (value.length === length) return true
6769
6770 throw ERRORS.tfCustomError(name + '(Length: ' + length + ')', name + '(Length: ' + value.length + ')')
6771 }
6772 Length.toJSON = function () { return name }
6773
6774 return Length
6775}
6776
6777var _ArrayN = _LengthN.bind(null, NATIVE.Array)
6778var _BufferN = _LengthN.bind(null, _Buffer)
6779var _HexN = _LengthN.bind(null, Hex)
6780var _StringN = _LengthN.bind(null, NATIVE.String)
6781
6782function Range (a, b, f) {
6783 f = f || NATIVE.Number
6784 function _range (value, strict) {
6785 return f(value, strict) && (value > a) && (value < b)
6786 }
6787 _range.toJSON = function () {
6788 return `${f.toJSON()} between [${a}, ${b}]`
6789 }
6790 return _range
6791}
6792
6793var INT53_MAX = Math.pow(2, 53) - 1
6794
6795function Finite (value) {
6796 return typeof value === 'number' && isFinite(value)
6797}
6798function Int8 (value) { return ((value << 24) >> 24) === value }
6799function Int16 (value) { return ((value << 16) >> 16) === value }
6800function Int32 (value) { return (value | 0) === value }
6801function Int53 (value) {
6802 return typeof value === 'number' &&
6803 value >= -INT53_MAX &&
6804 value <= INT53_MAX &&
6805 Math.floor(value) === value
6806}
6807function UInt8 (value) { return (value & 0xff) === value }
6808function UInt16 (value) { return (value & 0xffff) === value }
6809function UInt32 (value) { return (value >>> 0) === value }
6810function UInt53 (value) {
6811 return typeof value === 'number' &&
6812 value >= 0 &&
6813 value <= INT53_MAX &&
6814 Math.floor(value) === value
6815}
6816
6817var types = {
6818 ArrayN: _ArrayN,
6819 Buffer: _Buffer,
6820 BufferN: _BufferN,
6821 Finite: Finite,
6822 Hex: Hex,
6823 HexN: _HexN,
6824 Int8: Int8,
6825 Int16: Int16,
6826 Int32: Int32,
6827 Int53: Int53,
6828 Range: Range,
6829 StringN: _StringN,
6830 UInt8: UInt8,
6831 UInt16: UInt16,
6832 UInt32: UInt32,
6833 UInt53: UInt53
6834}
6835
6836for (var typeName in types) {
6837 types[typeName].toJSON = function (t) {
6838 return t
6839 }.bind(null, typeName)
6840}
6841
6842module.exports = types
6843
6844}).call(this,{"isBuffer":require("../../../../../../usr/local/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
6845},{"../../../../../../usr/local/lib/node_modules/browserify/node_modules/is-buffer/index.js":101,"./errors":47,"./native":50}],49:[function(require,module,exports){
6846var ERRORS = require('./errors')
6847var NATIVE = require('./native')
6848
6849// short-hand
6850var tfJSON = ERRORS.tfJSON
6851var TfTypeError = ERRORS.TfTypeError
6852var TfPropertyTypeError = ERRORS.TfPropertyTypeError
6853var tfSubError = ERRORS.tfSubError
6854var getValueTypeName = ERRORS.getValueTypeName
6855
6856var TYPES = {
6857 arrayOf: function arrayOf (type, options) {
6858 type = compile(type)
6859 options = options || {}
6860
6861 function _arrayOf (array, strict) {
6862 if (!NATIVE.Array(array)) return false
6863 if (NATIVE.Nil(array)) return false
6864 if (options.minLength !== undefined && array.length < options.minLength) return false
6865 if (options.maxLength !== undefined && array.length > options.maxLength) return false
6866 if (options.length !== undefined && array.length !== options.length) return false
6867
6868 return array.every(function (value, i) {
6869 try {
6870 return typeforce(type, value, strict)
6871 } catch (e) {
6872 throw tfSubError(e, i)
6873 }
6874 })
6875 }
6876 _arrayOf.toJSON = function () {
6877 var str = '[' + tfJSON(type) + ']'
6878 if (options.length !== undefined) {
6879 str += '{' + options.length + '}'
6880 } else if (options.minLength !== undefined || options.maxLength !== undefined) {
6881 str += '{' +
6882 (options.minLength === undefined ? 0 : options.minLength) + ',' +
6883 (options.maxLength === undefined ? Infinity : options.maxLength) + '}'
6884 }
6885 return str
6886 }
6887
6888 return _arrayOf
6889 },
6890
6891 maybe: function maybe (type) {
6892 type = compile(type)
6893
6894 function _maybe (value, strict) {
6895 return NATIVE.Nil(value) || type(value, strict, maybe)
6896 }
6897 _maybe.toJSON = function () { return '?' + tfJSON(type) }
6898
6899 return _maybe
6900 },
6901
6902 map: function map (propertyType, propertyKeyType) {
6903 propertyType = compile(propertyType)
6904 if (propertyKeyType) propertyKeyType = compile(propertyKeyType)
6905
6906 function _map (value, strict) {
6907 if (!NATIVE.Object(value)) return false
6908 if (NATIVE.Nil(value)) return false
6909
6910 for (var propertyName in value) {
6911 try {
6912 if (propertyKeyType) {
6913 typeforce(propertyKeyType, propertyName, strict)
6914 }
6915 } catch (e) {
6916 throw tfSubError(e, propertyName, 'key')
6917 }
6918
6919 try {
6920 var propertyValue = value[propertyName]
6921 typeforce(propertyType, propertyValue, strict)
6922 } catch (e) {
6923 throw tfSubError(e, propertyName)
6924 }
6925 }
6926
6927 return true
6928 }
6929
6930 if (propertyKeyType) {
6931 _map.toJSON = function () {
6932 return '{' + tfJSON(propertyKeyType) + ': ' + tfJSON(propertyType) + '}'
6933 }
6934 } else {
6935 _map.toJSON = function () { return '{' + tfJSON(propertyType) + '}' }
6936 }
6937
6938 return _map
6939 },
6940
6941 object: function object (uncompiled) {
6942 var type = {}
6943
6944 for (var typePropertyName in uncompiled) {
6945 type[typePropertyName] = compile(uncompiled[typePropertyName])
6946 }
6947
6948 function _object (value, strict) {
6949 if (!NATIVE.Object(value)) return false
6950 if (NATIVE.Nil(value)) return false
6951
6952 var propertyName
6953
6954 try {
6955 for (propertyName in type) {
6956 var propertyType = type[propertyName]
6957 var propertyValue = value[propertyName]
6958
6959 typeforce(propertyType, propertyValue, strict)
6960 }
6961 } catch (e) {
6962 throw tfSubError(e, propertyName)
6963 }
6964
6965 if (strict) {
6966 for (propertyName in value) {
6967 if (type[propertyName]) continue
6968
6969 throw new TfPropertyTypeError(undefined, propertyName)
6970 }
6971 }
6972
6973 return true
6974 }
6975 _object.toJSON = function () { return tfJSON(type) }
6976
6977 return _object
6978 },
6979
6980 anyOf: function anyOf () {
6981 var types = [].slice.call(arguments).map(compile)
6982
6983 function _anyOf (value, strict) {
6984 return types.some(function (type) {
6985 try {
6986 return typeforce(type, value, strict)
6987 } catch (e) {
6988 return false
6989 }
6990 })
6991 }
6992 _anyOf.toJSON = function () { return types.map(tfJSON).join('|') }
6993
6994 return _anyOf
6995 },
6996
6997 allOf: function allOf () {
6998 var types = [].slice.call(arguments).map(compile)
6999
7000 function _allOf (value, strict) {
7001 return types.every(function (type) {
7002 try {
7003 return typeforce(type, value, strict)
7004 } catch (e) {
7005 return false
7006 }
7007 })
7008 }
7009 _allOf.toJSON = function () { return types.map(tfJSON).join(' & ') }
7010
7011 return _allOf
7012 },
7013
7014 quacksLike: function quacksLike (type) {
7015 function _quacksLike (value) {
7016 return type === getValueTypeName(value)
7017 }
7018 _quacksLike.toJSON = function () { return type }
7019
7020 return _quacksLike
7021 },
7022
7023 tuple: function tuple () {
7024 var types = [].slice.call(arguments).map(compile)
7025
7026 function _tuple (values, strict) {
7027 if (NATIVE.Nil(values)) return false
7028 if (NATIVE.Nil(values.length)) return false
7029 if (strict && (values.length !== types.length)) return false
7030
7031 return types.every(function (type, i) {
7032 try {
7033 return typeforce(type, values[i], strict)
7034 } catch (e) {
7035 throw tfSubError(e, i)
7036 }
7037 })
7038 }
7039 _tuple.toJSON = function () { return '(' + types.map(tfJSON).join(', ') + ')' }
7040
7041 return _tuple
7042 },
7043
7044 value: function value (expected) {
7045 function _value (actual) {
7046 return actual === expected
7047 }
7048 _value.toJSON = function () { return expected }
7049
7050 return _value
7051 }
7052}
7053
7054// TODO: deprecate
7055TYPES.oneOf = TYPES.anyOf
7056
7057function compile (type) {
7058 if (NATIVE.String(type)) {
7059 if (type[0] === '?') return TYPES.maybe(type.slice(1))
7060
7061 return NATIVE[type] || TYPES.quacksLike(type)
7062 } else if (type && NATIVE.Object(type)) {
7063 if (NATIVE.Array(type)) {
7064 if (type.length !== 1) throw new TypeError('Expected compile() parameter of type Array of length 1')
7065 return TYPES.arrayOf(type[0])
7066 }
7067
7068 return TYPES.object(type)
7069 } else if (NATIVE.Function(type)) {
7070 return type
7071 }
7072
7073 return TYPES.value(type)
7074}
7075
7076function typeforce (type, value, strict, surrogate) {
7077 if (NATIVE.Function(type)) {
7078 if (type(value, strict)) return true
7079
7080 throw new TfTypeError(surrogate || type, value)
7081 }
7082
7083 // JIT
7084 return typeforce(compile(type), value, strict)
7085}
7086
7087// assign types to typeforce function
7088for (var typeName in NATIVE) {
7089 typeforce[typeName] = NATIVE[typeName]
7090}
7091
7092for (typeName in TYPES) {
7093 typeforce[typeName] = TYPES[typeName]
7094}
7095
7096var EXTRA = require('./extra')
7097for (typeName in EXTRA) {
7098 typeforce[typeName] = EXTRA[typeName]
7099}
7100
7101typeforce.compile = compile
7102typeforce.TfTypeError = TfTypeError
7103typeforce.TfPropertyTypeError = TfPropertyTypeError
7104
7105module.exports = typeforce
7106
7107},{"./errors":47,"./extra":48,"./native":50}],50:[function(require,module,exports){
7108var types = {
7109 Array: function (value) { return value !== null && value !== undefined && value.constructor === Array },
7110 Boolean: function (value) { return typeof value === 'boolean' },
7111 Function: function (value) { return typeof value === 'function' },
7112 Nil: function (value) { return value === undefined || value === null },
7113 Number: function (value) { return typeof value === 'number' },
7114 Object: function (value) { return typeof value === 'object' },
7115 String: function (value) { return typeof value === 'string' },
7116 '': function () { return true }
7117}
7118
7119// TODO: deprecate
7120types.Null = types.Nil
7121
7122for (var typeName in types) {
7123 types[typeName].toJSON = function (t) {
7124 return t
7125 }.bind(null, typeName)
7126}
7127
7128module.exports = types
7129
7130},{}],51:[function(require,module,exports){
7131'use strict'
7132var Buffer = require('safe-buffer').Buffer
7133
7134// Number.MAX_SAFE_INTEGER
7135var MAX_SAFE_INTEGER = 9007199254740991
7136
7137function checkUInt53 (n) {
7138 if (n < 0 || n > MAX_SAFE_INTEGER || n % 1 !== 0) throw new RangeError('value out of range')
7139}
7140
7141function encode (number, buffer, offset) {
7142 checkUInt53(number)
7143
7144 if (!buffer) buffer = Buffer.allocUnsafe(encodingLength(number))
7145 if (!Buffer.isBuffer(buffer)) throw new TypeError('buffer must be a Buffer instance')
7146 if (!offset) offset = 0
7147
7148 // 8 bit
7149 if (number < 0xfd) {
7150 buffer.writeUInt8(number, offset)
7151 encode.bytes = 1
7152
7153 // 16 bit
7154 } else if (number <= 0xffff) {
7155 buffer.writeUInt8(0xfd, offset)
7156 buffer.writeUInt16LE(number, offset + 1)
7157 encode.bytes = 3
7158
7159 // 32 bit
7160 } else if (number <= 0xffffffff) {
7161 buffer.writeUInt8(0xfe, offset)
7162 buffer.writeUInt32LE(number, offset + 1)
7163 encode.bytes = 5
7164
7165 // 64 bit
7166 } else {
7167 buffer.writeUInt8(0xff, offset)
7168 buffer.writeUInt32LE(number >>> 0, offset + 1)
7169 buffer.writeUInt32LE((number / 0x100000000) | 0, offset + 5)
7170 encode.bytes = 9
7171 }
7172
7173 return buffer
7174}
7175
7176function decode (buffer, offset) {
7177 if (!Buffer.isBuffer(buffer)) throw new TypeError('buffer must be a Buffer instance')
7178 if (!offset) offset = 0
7179
7180 var first = buffer.readUInt8(offset)
7181
7182 // 8 bit
7183 if (first < 0xfd) {
7184 decode.bytes = 1
7185 return first
7186
7187 // 16 bit
7188 } else if (first === 0xfd) {
7189 decode.bytes = 3
7190 return buffer.readUInt16LE(offset + 1)
7191
7192 // 32 bit
7193 } else if (first === 0xfe) {
7194 decode.bytes = 5
7195 return buffer.readUInt32LE(offset + 1)
7196
7197 // 64 bit
7198 } else {
7199 decode.bytes = 9
7200 var lo = buffer.readUInt32LE(offset + 1)
7201 var hi = buffer.readUInt32LE(offset + 5)
7202 var number = hi * 0x0100000000 + lo
7203 checkUInt53(number)
7204
7205 return number
7206 }
7207}
7208
7209function encodingLength (number) {
7210 checkUInt53(number)
7211
7212 return (
7213 number < 0xfd ? 1
7214 : number <= 0xffff ? 3
7215 : number <= 0xffffffff ? 5
7216 : 9
7217 )
7218}
7219
7220module.exports = { encode: encode, decode: decode, encodingLength: encodingLength }
7221
7222},{"safe-buffer":38}],52:[function(require,module,exports){
7223var bs58grscheck = require('bs58grscheck')
7224var Buffer = require('safe-buffer').Buffer
7225
7226function decodeRaw (buffer, version) {
7227 // check version only if defined
7228 if (version !== undefined && buffer[0] !== version) throw new Error('Invalid network version')
7229
7230 // uncompressed
7231 if (buffer.length === 33) {
7232 return {
7233 version: buffer[0],
7234 privateKey: buffer.slice(1, 33),
7235 compressed: false
7236 }
7237 }
7238
7239 // invalid length
7240 if (buffer.length !== 34) throw new Error('Invalid WIF length')
7241
7242 // invalid compression flag
7243 if (buffer[33] !== 0x01) throw new Error('Invalid compression flag')
7244
7245 return {
7246 version: buffer[0],
7247 privateKey: buffer.slice(1, 33),
7248 compressed: true
7249 }
7250}
7251
7252function encodeRaw (version, privateKey, compressed) {
7253 if (privateKey.length !== 32) throw new TypeError('Invalid privateKey length')
7254
7255 var result = Buffer.alloc(compressed ? 34 : 33)
7256 result.writeUInt8(version, 0)
7257 privateKey.copy(result, 1)
7258
7259 if (compressed) {
7260 result[33] = 0x01
7261 }
7262
7263 return result
7264}
7265
7266function decode (string, version) {
7267 return decodeRaw(bs58grscheck.decode(string), version)
7268}
7269
7270function encode (version, privateKey, compressed) {
7271 if (typeof version === 'number') return bs58grscheck.encode(encodeRaw(version, privateKey, compressed))
7272
7273 return bs58grscheck.encode(
7274 encodeRaw(
7275 version.version,
7276 version.privateKey,
7277 version.compressed
7278 )
7279 )
7280}
7281
7282module.exports = {
7283 decode: decode,
7284 decodeRaw: decodeRaw,
7285 encode: encode,
7286 encodeRaw: encodeRaw
7287}
7288
7289},{"bs58grscheck":12,"safe-buffer":38}],53:[function(require,module,exports){
7290var Buffer = require('safe-buffer').Buffer
7291var bech32 = require('bech32')
7292var bs58grscheck = require('bs58grscheck')
7293var bscript = require('./script')
7294var btemplates = require('./templates')
7295var networks = require('./networks')
7296var typeforce = require('typeforce')
7297var types = require('./types')
7298
7299function fromBase58GrsCheck (address) {
7300 var payload = bs58grscheck.decode(address)
7301
7302 // TODO: 4.0.0, move to "toOutputScript"
7303 if (payload.length < 21) throw new TypeError(address + ' is too short')
7304 if (payload.length > 21) throw new TypeError(address + ' is too long')
7305
7306 var version = payload.readUInt8(0)
7307 var hash = payload.slice(1)
7308
7309 return { version: version, hash: hash }
7310}
7311
7312function fromBech32 (address) {
7313 var result = bech32.decode(address)
7314 var data = bech32.fromWords(result.words.slice(1))
7315
7316 return {
7317 version: result.words[0],
7318 prefix: result.prefix,
7319 data: Buffer.from(data)
7320 }
7321}
7322
7323function toBase58GrsCheck (hash, version) {
7324 typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments)
7325
7326 var payload = Buffer.allocUnsafe(21)
7327 payload.writeUInt8(version, 0)
7328 hash.copy(payload, 1)
7329
7330 return bs58grscheck.encode(payload)
7331}
7332
7333function toBech32 (data, version, prefix) {
7334 var words = bech32.toWords(data)
7335 words.unshift(version)
7336
7337 return bech32.encode(prefix, words)
7338}
7339
7340function fromOutputScript (outputScript, network) {
7341 network = network || networks.bitcoin
7342
7343 if (btemplates.pubKeyHash.output.check(outputScript)) return toBase58GrsCheck(bscript.compile(outputScript).slice(3, 23), network.pubKeyHash)
7344 if (btemplates.scriptHash.output.check(outputScript)) return toBase58GrsCheck(bscript.compile(outputScript).slice(2, 22), network.scriptHash)
7345 if (btemplates.witnessPubKeyHash.output.check(outputScript)) return toBech32(bscript.compile(outputScript).slice(2, 22), 0, network.bech32)
7346 if (btemplates.witnessScriptHash.output.check(outputScript)) return toBech32(bscript.compile(outputScript).slice(2, 34), 0, network.bech32)
7347
7348 throw new Error(bscript.toASM(outputScript) + ' has no matching Address')
7349}
7350
7351function toOutputScript (address, network) {
7352 network = network || networks.bitcoin
7353
7354 var decode
7355 try {
7356 decode = fromBase58GrsCheck(address)
7357 } catch (e) {}
7358
7359 if (decode) {
7360 if (decode.version === network.pubKeyHash) return btemplates.pubKeyHash.output.encode(decode.hash)
7361 if (decode.version === network.scriptHash) return btemplates.scriptHash.output.encode(decode.hash)
7362 } else {
7363 try {
7364 decode = fromBech32(address)
7365 } catch (e) {}
7366
7367 if (decode) {
7368 if (decode.prefix !== network.bech32) throw new Error(address + ' has an invalid prefix')
7369 if (decode.version === 0) {
7370 if (decode.data.length === 20) return btemplates.witnessPubKeyHash.output.encode(decode.data)
7371 if (decode.data.length === 32) return btemplates.witnessScriptHash.output.encode(decode.data)
7372 }
7373 }
7374 }
7375
7376 throw new Error(address + ' has no matching Script')
7377}
7378
7379module.exports = {
7380 fromBase58GrsCheck: fromBase58GrsCheck,
7381 fromBech32: fromBech32,
7382 fromOutputScript: fromOutputScript,
7383 toBase58GrsCheck: toBase58GrsCheck,
7384 toBech32: toBech32,
7385 toOutputScript: toOutputScript
7386}
7387
7388},{"./networks":62,"./script":63,"./templates":65,"./types":89,"bech32":2,"bs58grscheck":12,"safe-buffer":38,"typeforce":49}],54:[function(require,module,exports){
7389var Buffer = require('safe-buffer').Buffer
7390var bcrypto = require('./crypto')
7391var fastMerkleRoot = require('merkle-lib/fastRoot')
7392var typeforce = require('typeforce')
7393var types = require('./types')
7394var varuint = require('varuint-bitcoin')
7395
7396var Transaction = require('./transaction')
7397
7398function Block () {
7399 this.version = 1
7400 this.prevHash = null
7401 this.merkleRoot = null
7402 this.timestamp = 0
7403 this.bits = 0
7404 this.nonce = 0
7405}
7406
7407Block.fromBuffer = function (buffer) {
7408 if (buffer.length < 80) throw new Error('Buffer too small (< 80 bytes)')
7409
7410 var offset = 0
7411 function readSlice (n) {
7412 offset += n
7413 return buffer.slice(offset - n, offset)
7414 }
7415
7416 function readUInt32 () {
7417 var i = buffer.readUInt32LE(offset)
7418 offset += 4
7419 return i
7420 }
7421
7422 function readInt32 () {
7423 var i = buffer.readInt32LE(offset)
7424 offset += 4
7425 return i
7426 }
7427
7428 var block = new Block()
7429 block.version = readInt32()
7430 block.prevHash = readSlice(32)
7431 block.merkleRoot = readSlice(32)
7432 block.timestamp = readUInt32()
7433 block.bits = readUInt32()
7434 block.nonce = readUInt32()
7435
7436 if (buffer.length === 80) return block
7437
7438 function readVarInt () {
7439 var vi = varuint.decode(buffer, offset)
7440 offset += varuint.decode.bytes
7441 return vi
7442 }
7443
7444 function readTransaction () {
7445 var tx = Transaction.fromBuffer(buffer.slice(offset), true)
7446 offset += tx.byteLength()
7447 return tx
7448 }
7449
7450 var nTransactions = readVarInt()
7451 block.transactions = []
7452
7453 for (var i = 0; i < nTransactions; ++i) {
7454 var tx = readTransaction()
7455 block.transactions.push(tx)
7456 }
7457
7458 return block
7459}
7460
7461Block.prototype.byteLength = function (headersOnly) {
7462 if (headersOnly || !this.transactions) return 80
7463
7464 return 80 + varuint.encodingLength(this.transactions.length) + this.transactions.reduce(function (a, x) {
7465 return a + x.byteLength()
7466 }, 0)
7467}
7468
7469Block.fromHex = function (hex) {
7470 return Block.fromBuffer(Buffer.from(hex, 'hex'))
7471}
7472
7473Block.prototype.getHash = function () {
7474 return bcrypto.groestl(this.toBuffer(true))
7475}
7476
7477Block.prototype.getId = function () {
7478 return this.getHash().reverse().toString('hex')
7479}
7480
7481Block.prototype.getUTCDate = function () {
7482 var date = new Date(0) // epoch
7483 date.setUTCSeconds(this.timestamp)
7484
7485 return date
7486}
7487
7488// TODO: buffer, offset compatibility
7489Block.prototype.toBuffer = function (headersOnly) {
7490 var buffer = Buffer.allocUnsafe(this.byteLength(headersOnly))
7491
7492 var offset = 0
7493 function writeSlice (slice) {
7494 slice.copy(buffer, offset)
7495 offset += slice.length
7496 }
7497
7498 function writeInt32 (i) {
7499 buffer.writeInt32LE(i, offset)
7500 offset += 4
7501 }
7502 function writeUInt32 (i) {
7503 buffer.writeUInt32LE(i, offset)
7504 offset += 4
7505 }
7506
7507 writeInt32(this.version)
7508 writeSlice(this.prevHash)
7509 writeSlice(this.merkleRoot)
7510 writeUInt32(this.timestamp)
7511 writeUInt32(this.bits)
7512 writeUInt32(this.nonce)
7513
7514 if (headersOnly || !this.transactions) return buffer
7515
7516 varuint.encode(this.transactions.length, buffer, offset)
7517 offset += varuint.encode.bytes
7518
7519 this.transactions.forEach(function (tx) {
7520 var txSize = tx.byteLength() // TODO: extract from toBuffer?
7521 tx.toBuffer(buffer, offset)
7522 offset += txSize
7523 })
7524
7525 return buffer
7526}
7527
7528Block.prototype.toHex = function (headersOnly) {
7529 return this.toBuffer(headersOnly).toString('hex')
7530}
7531
7532Block.calculateTarget = function (bits) {
7533 var exponent = ((bits & 0xff000000) >> 24) - 3
7534 var mantissa = bits & 0x007fffff
7535 var target = Buffer.alloc(32, 0)
7536 target.writeUInt32BE(mantissa, 28 - exponent)
7537 return target
7538}
7539
7540Block.calculateMerkleRoot = function (transactions) {
7541 typeforce([{ getHash: types.Function }], transactions)
7542 if (transactions.length === 0) throw TypeError('Cannot compute merkle root for zero transactions')
7543
7544 var hashes = transactions.map(function (transaction) {
7545 return transaction.getHash()
7546 })
7547
7548 return fastMerkleRoot(hashes, bcrypto.hash256)
7549}
7550
7551Block.prototype.checkMerkleRoot = function () {
7552 if (!this.transactions) return false
7553
7554 var actualMerkleRoot = Block.calculateMerkleRoot(this.transactions)
7555 return this.merkleRoot.compare(actualMerkleRoot) === 0
7556}
7557
7558Block.prototype.checkProofOfWork = function () {
7559 var hash = this.getHash().reverse()
7560 var target = Block.calculateTarget(this.bits)
7561
7562 return hash.compare(target) <= 0
7563}
7564
7565module.exports = Block
7566
7567},{"./crypto":56,"./transaction":87,"./types":89,"merkle-lib/fastRoot":34,"safe-buffer":38,"typeforce":49,"varuint-bitcoin":51}],55:[function(require,module,exports){
7568var pushdata = require('pushdata-bitcoin')
7569var varuint = require('varuint-bitcoin')
7570
7571// https://github.com/feross/buffer/blob/master/index.js#L1127
7572function verifuint (value, max) {
7573 if (typeof value !== 'number') throw new Error('cannot write a non-number as a number')
7574 if (value < 0) throw new Error('specified a negative value for writing an unsigned value')
7575 if (value > max) throw new Error('RangeError: value out of range')
7576 if (Math.floor(value) !== value) throw new Error('value has a fractional component')
7577}
7578
7579function readUInt64LE (buffer, offset) {
7580 var a = buffer.readUInt32LE(offset)
7581 var b = buffer.readUInt32LE(offset + 4)
7582 b *= 0x100000000
7583
7584 verifuint(b + a, 0x001fffffffffffff)
7585
7586 return b + a
7587}
7588
7589function writeUInt64LE (buffer, value, offset) {
7590 verifuint(value, 0x001fffffffffffff)
7591
7592 buffer.writeInt32LE(value & -1, offset)
7593 buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4)
7594 return offset + 8
7595}
7596
7597// TODO: remove in 4.0.0?
7598function readVarInt (buffer, offset) {
7599 var result = varuint.decode(buffer, offset)
7600
7601 return {
7602 number: result,
7603 size: varuint.decode.bytes
7604 }
7605}
7606
7607// TODO: remove in 4.0.0?
7608function writeVarInt (buffer, number, offset) {
7609 varuint.encode(number, buffer, offset)
7610 return varuint.encode.bytes
7611}
7612
7613module.exports = {
7614 pushDataSize: pushdata.encodingLength,
7615 readPushDataInt: pushdata.decode,
7616 readUInt64LE: readUInt64LE,
7617 readVarInt: readVarInt,
7618 varIntBuffer: varuint.encode,
7619 varIntSize: varuint.encodingLength,
7620 writePushDataInt: pushdata.encode,
7621 writeUInt64LE: writeUInt64LE,
7622 writeVarInt: writeVarInt
7623}
7624
7625},{"pushdata-bitcoin":35,"varuint-bitcoin":51}],56:[function(require,module,exports){
7626(function (Buffer){
7627var createHash = require('create-hash')
7628var groestlhash = require('groestl-hash-js')
7629
7630function ripemd160 (buffer) {
7631 return createHash('rmd160').update(buffer).digest()
7632}
7633
7634function sha1 (buffer) {
7635 return createHash('sha1').update(buffer).digest()
7636}
7637
7638function sha256 (buffer) {
7639 return createHash('sha256').update(buffer).digest()
7640}
7641
7642function hash160 (buffer) {
7643 return ripemd160(sha256(buffer))
7644}
7645
7646function hash256 (buffer) {
7647 return sha256(sha256(buffer))
7648}
7649
7650function groestl (buffer) {
7651 return Buffer(groestlhash.groestl_2(buffer, 1, 1))
7652}
7653
7654module.exports = {
7655 hash160: hash160,
7656 hash256: hash256,
7657 ripemd160: ripemd160,
7658 sha1: sha1,
7659 sha256: sha256,
7660 groestl: groestl
7661}
7662
7663}).call(this,require("buffer").Buffer)
7664},{"buffer":96,"create-hash":14,"groestl-hash-js":27}],57:[function(require,module,exports){
7665var Buffer = require('safe-buffer').Buffer
7666var createHmac = require('create-hmac')
7667var typeforce = require('typeforce')
7668var types = require('./types')
7669
7670var BigInteger = require('bigi')
7671var ECSignature = require('./ecsignature')
7672
7673var ZERO = Buffer.alloc(1, 0)
7674var ONE = Buffer.alloc(1, 1)
7675
7676var ecurve = require('ecurve')
7677var secp256k1 = ecurve.getCurveByName('secp256k1')
7678
7679// https://tools.ietf.org/html/rfc6979#section-3.2
7680function deterministicGenerateK (hash, x, checkSig) {
7681 typeforce(types.tuple(
7682 types.Hash256bit,
7683 types.Buffer256bit,
7684 types.Function
7685 ), arguments)
7686
7687 // Step A, ignored as hash already provided
7688 // Step B
7689 // Step C
7690 var k = Buffer.alloc(32, 0)
7691 var v = Buffer.alloc(32, 1)
7692
7693 // Step D
7694 k = createHmac('sha256', k)
7695 .update(v)
7696 .update(ZERO)
7697 .update(x)
7698 .update(hash)
7699 .digest()
7700
7701 // Step E
7702 v = createHmac('sha256', k).update(v).digest()
7703
7704 // Step F
7705 k = createHmac('sha256', k)
7706 .update(v)
7707 .update(ONE)
7708 .update(x)
7709 .update(hash)
7710 .digest()
7711
7712 // Step G
7713 v = createHmac('sha256', k).update(v).digest()
7714
7715 // Step H1/H2a, ignored as tlen === qlen (256 bit)
7716 // Step H2b
7717 v = createHmac('sha256', k).update(v).digest()
7718
7719 var T = BigInteger.fromBuffer(v)
7720
7721 // Step H3, repeat until T is within the interval [1, n - 1] and is suitable for ECDSA
7722 while (T.signum() <= 0 || T.compareTo(secp256k1.n) >= 0 || !checkSig(T)) {
7723 k = createHmac('sha256', k)
7724 .update(v)
7725 .update(ZERO)
7726 .digest()
7727
7728 v = createHmac('sha256', k).update(v).digest()
7729
7730 // Step H1/H2a, again, ignored as tlen === qlen (256 bit)
7731 // Step H2b again
7732 v = createHmac('sha256', k).update(v).digest()
7733 T = BigInteger.fromBuffer(v)
7734 }
7735
7736 return T
7737}
7738
7739var N_OVER_TWO = secp256k1.n.shiftRight(1)
7740
7741function sign (hash, d) {
7742 typeforce(types.tuple(types.Hash256bit, types.BigInt), arguments)
7743
7744 var x = d.toBuffer(32)
7745 var e = BigInteger.fromBuffer(hash)
7746 var n = secp256k1.n
7747 var G = secp256k1.G
7748
7749 var r, s
7750 deterministicGenerateK(hash, x, function (k) {
7751 var Q = G.multiply(k)
7752
7753 if (secp256k1.isInfinity(Q)) return false
7754
7755 r = Q.affineX.mod(n)
7756 if (r.signum() === 0) return false
7757
7758 s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n)
7759 if (s.signum() === 0) return false
7760
7761 return true
7762 })
7763
7764 // enforce low S values, see bip62: 'low s values in signatures'
7765 if (s.compareTo(N_OVER_TWO) > 0) {
7766 s = n.subtract(s)
7767 }
7768
7769 return new ECSignature(r, s)
7770}
7771
7772function verify (hash, signature, Q) {
7773 typeforce(types.tuple(
7774 types.Hash256bit,
7775 types.ECSignature,
7776 types.ECPoint
7777 ), arguments)
7778
7779 var n = secp256k1.n
7780 var G = secp256k1.G
7781
7782 var r = signature.r
7783 var s = signature.s
7784
7785 // 1.4.1 Enforce r and s are both integers in the interval [1, n − 1]
7786 if (r.signum() <= 0 || r.compareTo(n) >= 0) return false
7787 if (s.signum() <= 0 || s.compareTo(n) >= 0) return false
7788
7789 // 1.4.2 H = Hash(M), already done by the user
7790 // 1.4.3 e = H
7791 var e = BigInteger.fromBuffer(hash)
7792
7793 // Compute s^-1
7794 var sInv = s.modInverse(n)
7795
7796 // 1.4.4 Compute u1 = es^−1 mod n
7797 // u2 = rs^−1 mod n
7798 var u1 = e.multiply(sInv).mod(n)
7799 var u2 = r.multiply(sInv).mod(n)
7800
7801 // 1.4.5 Compute R = (xR, yR)
7802 // R = u1G + u2Q
7803 var R = G.multiplyTwo(u1, Q, u2)
7804
7805 // 1.4.5 (cont.) Enforce R is not at infinity
7806 if (secp256k1.isInfinity(R)) return false
7807
7808 // 1.4.6 Convert the field element R.x to an integer
7809 var xR = R.affineX
7810
7811 // 1.4.7 Set v = xR mod n
7812 var v = xR.mod(n)
7813
7814 // 1.4.8 If v = r, output "valid", and if v != r, output "invalid"
7815 return v.equals(r)
7816}
7817
7818module.exports = {
7819 deterministicGenerateK: deterministicGenerateK,
7820 sign: sign,
7821 verify: verify,
7822
7823 // TODO: remove
7824 __curve: secp256k1
7825}
7826
7827},{"./ecsignature":59,"./types":89,"bigi":5,"create-hmac":16,"ecurve":20,"safe-buffer":38,"typeforce":49}],58:[function(require,module,exports){
7828var baddress = require('./address')
7829var bcrypto = require('./crypto')
7830var ecdsa = require('./ecdsa')
7831var randomBytes = require('randombytes')
7832var typeforce = require('typeforce')
7833var types = require('./types')
7834var wif = require('wifgrs')
7835
7836var NETWORKS = require('./networks')
7837var BigInteger = require('bigi')
7838
7839var ecurve = require('ecurve')
7840var secp256k1 = ecdsa.__curve
7841
7842function ECPair (d, Q, options) {
7843 if (options) {
7844 typeforce({
7845 compressed: types.maybe(types.Boolean),
7846 network: types.maybe(types.Network)
7847 }, options)
7848 }
7849
7850 options = options || {}
7851
7852 if (d) {
7853 if (d.signum() <= 0) throw new Error('Private key must be greater than 0')
7854 if (d.compareTo(secp256k1.n) >= 0) throw new Error('Private key must be less than the curve order')
7855 if (Q) throw new TypeError('Unexpected publicKey parameter')
7856
7857 this.d = d
7858 } else {
7859 typeforce(types.ECPoint, Q)
7860
7861 this.__Q = Q
7862 }
7863
7864 this.compressed = options.compressed === undefined ? true : options.compressed
7865 this.network = options.network || NETWORKS.bitcoin
7866}
7867
7868Object.defineProperty(ECPair.prototype, 'Q', {
7869 get: function () {
7870 if (!this.__Q && this.d) {
7871 this.__Q = secp256k1.G.multiply(this.d)
7872 }
7873
7874 return this.__Q
7875 }
7876})
7877
7878ECPair.fromPublicKeyBuffer = function (buffer, network) {
7879 var Q = ecurve.Point.decodeFrom(secp256k1, buffer)
7880
7881 return new ECPair(null, Q, {
7882 compressed: Q.compressed,
7883 network: network
7884 })
7885}
7886
7887ECPair.fromWIF = function (string, network) {
7888 var decoded = wif.decode(string)
7889 var version = decoded.version
7890
7891 // list of networks?
7892 if (types.Array(network)) {
7893 network = network.filter(function (x) {
7894 return version === x.wif
7895 }).pop()
7896
7897 if (!network) throw new Error('Unknown network version')
7898
7899 // otherwise, assume a network object (or default to bitcoin)
7900 } else {
7901 network = network || NETWORKS.bitcoin
7902
7903 if (version !== network.wif) throw new Error('Invalid network version')
7904 }
7905
7906 var d = BigInteger.fromBuffer(decoded.privateKey)
7907
7908 return new ECPair(d, null, {
7909 compressed: decoded.compressed,
7910 network: network
7911 })
7912}
7913
7914ECPair.makeRandom = function (options) {
7915 options = options || {}
7916
7917 var rng = options.rng || randomBytes
7918
7919 var d
7920 do {
7921 var buffer = rng(32)
7922 typeforce(types.Buffer256bit, buffer)
7923
7924 d = BigInteger.fromBuffer(buffer)
7925 } while (d.signum() <= 0 || d.compareTo(secp256k1.n) >= 0)
7926
7927 return new ECPair(d, null, options)
7928}
7929
7930ECPair.prototype.getAddress = function () {
7931 return baddress.toBase58GrsCheck(bcrypto.hash160(this.getPublicKeyBuffer()), this.getNetwork().pubKeyHash)
7932}
7933
7934ECPair.prototype.getNetwork = function () {
7935 return this.network
7936}
7937
7938ECPair.prototype.getPublicKeyBuffer = function () {
7939 return this.Q.getEncoded(this.compressed)
7940}
7941
7942ECPair.prototype.sign = function (hash) {
7943 if (!this.d) throw new Error('Missing private key')
7944
7945 return ecdsa.sign(hash, this.d)
7946}
7947
7948ECPair.prototype.toWIF = function () {
7949 if (!this.d) throw new Error('Missing private key')
7950
7951 return wif.encode(this.network.wif, this.d.toBuffer(32), this.compressed)
7952}
7953
7954ECPair.prototype.verify = function (hash, signature) {
7955 return ecdsa.verify(hash, signature, this.Q)
7956}
7957
7958module.exports = ECPair
7959
7960},{"./address":53,"./crypto":56,"./ecdsa":57,"./networks":62,"./types":89,"bigi":5,"ecurve":20,"randombytes":36,"typeforce":49,"wifgrs":52}],59:[function(require,module,exports){
7961(function (Buffer){
7962var bip66 = require('bip66')
7963var typeforce = require('typeforce')
7964var types = require('./types')
7965
7966var BigInteger = require('bigi')
7967
7968function ECSignature (r, s) {
7969 typeforce(types.tuple(types.BigInt, types.BigInt), arguments)
7970
7971 this.r = r
7972 this.s = s
7973}
7974
7975ECSignature.parseCompact = function (buffer) {
7976 typeforce(types.BufferN(65), buffer)
7977
7978 var flagByte = buffer.readUInt8(0) - 27
7979 if (flagByte !== (flagByte & 7)) throw new Error('Invalid signature parameter')
7980
7981 var compressed = !!(flagByte & 4)
7982 var recoveryParam = flagByte & 3
7983 var signature = ECSignature.fromRSBuffer(buffer.slice(1))
7984
7985 return {
7986 compressed: compressed,
7987 i: recoveryParam,
7988 signature: signature
7989 }
7990}
7991
7992ECSignature.fromRSBuffer = function (buffer) {
7993 typeforce(types.BufferN(64), buffer)
7994
7995 var r = BigInteger.fromBuffer(buffer.slice(0, 32))
7996 var s = BigInteger.fromBuffer(buffer.slice(32, 64))
7997 return new ECSignature(r, s)
7998}
7999
8000ECSignature.fromDER = function (buffer) {
8001 var decode = bip66.decode(buffer)
8002 var r = BigInteger.fromDERInteger(decode.r)
8003 var s = BigInteger.fromDERInteger(decode.s)
8004
8005 return new ECSignature(r, s)
8006}
8007
8008// BIP62: 1 byte hashType flag (only 0x01, 0x02, 0x03, 0x81, 0x82 and 0x83 are allowed)
8009ECSignature.parseScriptSignature = function (buffer) {
8010 var hashType = buffer.readUInt8(buffer.length - 1)
8011 var hashTypeMod = hashType & ~0x80
8012
8013 if (hashTypeMod <= 0x00 || hashTypeMod >= 0x04) throw new Error('Invalid hashType ' + hashType)
8014
8015 return {
8016 signature: ECSignature.fromDER(buffer.slice(0, -1)),
8017 hashType: hashType
8018 }
8019}
8020
8021ECSignature.prototype.toCompact = function (i, compressed) {
8022 if (compressed) {
8023 i += 4
8024 }
8025
8026 i += 27
8027
8028 var buffer = Buffer.alloc(65)
8029 buffer.writeUInt8(i, 0)
8030 this.toRSBuffer(buffer, 1)
8031 return buffer
8032}
8033
8034ECSignature.prototype.toDER = function () {
8035 var r = Buffer.from(this.r.toDERInteger())
8036 var s = Buffer.from(this.s.toDERInteger())
8037
8038 return bip66.encode(r, s)
8039}
8040
8041ECSignature.prototype.toRSBuffer = function (buffer, offset) {
8042 buffer = buffer || Buffer.alloc(64)
8043 this.r.toBuffer(32).copy(buffer, offset)
8044 this.s.toBuffer(32).copy(buffer, offset + 32)
8045 return buffer
8046}
8047
8048ECSignature.prototype.toScriptSignature = function (hashType) {
8049 var hashTypeMod = hashType & ~0x80
8050 if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType)
8051
8052 var hashTypeBuffer = Buffer.alloc(1)
8053 hashTypeBuffer.writeUInt8(hashType, 0)
8054
8055 return Buffer.concat([this.toDER(), hashTypeBuffer])
8056}
8057
8058module.exports = ECSignature
8059
8060}).call(this,require("buffer").Buffer)
8061},{"./types":89,"bigi":5,"bip66":7,"buffer":96,"typeforce":49}],60:[function(require,module,exports){
8062var Buffer = require('safe-buffer').Buffer
8063var base58grscheck = require('bs58grscheck')
8064var bcrypto = require('./crypto')
8065var createHmac = require('create-hmac')
8066var typeforce = require('typeforce')
8067var types = require('./types')
8068var NETWORKS = require('./networks')
8069
8070var BigInteger = require('bigi')
8071var ECPair = require('./ecpair')
8072
8073var ecurve = require('ecurve')
8074var curve = ecurve.getCurveByName('secp256k1')
8075
8076function HDNode (keyPair, chainCode) {
8077 typeforce(types.tuple('ECPair', types.Buffer256bit), arguments)
8078
8079 if (!keyPair.compressed) throw new TypeError('BIP32 only allows compressed keyPairs')
8080
8081 this.keyPair = keyPair
8082 this.chainCode = chainCode
8083 this.depth = 0
8084 this.index = 0
8085 this.parentFingerprint = 0x00000000
8086}
8087
8088HDNode.HIGHEST_BIT = 0x80000000
8089HDNode.LENGTH = 78
8090HDNode.MASTER_SECRET = Buffer.from('Bitcoin seed', 'utf8')
8091
8092HDNode.fromSeedBuffer = function (seed, network) {
8093 typeforce(types.tuple(types.Buffer, types.maybe(types.Network)), arguments)
8094
8095 if (seed.length < 16) throw new TypeError('Seed should be at least 128 bits')
8096 if (seed.length > 64) throw new TypeError('Seed should be at most 512 bits')
8097
8098 var I = createHmac('sha512', HDNode.MASTER_SECRET).update(seed).digest()
8099 var IL = I.slice(0, 32)
8100 var IR = I.slice(32)
8101
8102 // In case IL is 0 or >= n, the master key is invalid
8103 // This is handled by the ECPair constructor
8104 var pIL = BigInteger.fromBuffer(IL)
8105 var keyPair = new ECPair(pIL, null, {
8106 network: network
8107 })
8108
8109 return new HDNode(keyPair, IR)
8110}
8111
8112HDNode.fromSeedHex = function (hex, network) {
8113 return HDNode.fromSeedBuffer(Buffer.from(hex, 'hex'), network)
8114}
8115
8116HDNode.fromBase58 = function (string, networks) {
8117 var buffer = base58grscheck.decode(string)
8118 if (buffer.length !== 78) throw new Error('Invalid buffer length')
8119
8120 // 4 bytes: version bytes
8121 var version = buffer.readUInt32BE(0)
8122 var network
8123
8124 // list of networks?
8125 if (Array.isArray(networks)) {
8126 network = networks.filter(function (x) {
8127 return version === x.bip32.private ||
8128 version === x.bip32.public
8129 }).pop()
8130
8131 if (!network) throw new Error('Unknown network version')
8132
8133 // otherwise, assume a network object (or default to bitcoin)
8134 } else {
8135 network = networks || NETWORKS.bitcoin
8136 }
8137
8138 if (version !== network.bip32.private &&
8139 version !== network.bip32.public) throw new Error('Invalid network version')
8140
8141 // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ...
8142 var depth = buffer[4]
8143
8144 // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
8145 var parentFingerprint = buffer.readUInt32BE(5)
8146 if (depth === 0) {
8147 if (parentFingerprint !== 0x00000000) throw new Error('Invalid parent fingerprint')
8148 }
8149
8150 // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
8151 // This is encoded in MSB order. (0x00000000 if master key)
8152 var index = buffer.readUInt32BE(9)
8153 if (depth === 0 && index !== 0) throw new Error('Invalid index')
8154
8155 // 32 bytes: the chain code
8156 var chainCode = buffer.slice(13, 45)
8157 var keyPair
8158
8159 // 33 bytes: private key data (0x00 + k)
8160 if (version === network.bip32.private) {
8161 if (buffer.readUInt8(45) !== 0x00) throw new Error('Invalid private key')
8162
8163 var d = BigInteger.fromBuffer(buffer.slice(46, 78))
8164 keyPair = new ECPair(d, null, { network: network })
8165
8166 // 33 bytes: public key data (0x02 + X or 0x03 + X)
8167 } else {
8168 var Q = ecurve.Point.decodeFrom(curve, buffer.slice(45, 78))
8169 // Q.compressed is assumed, if somehow this assumption is broken, `new HDNode` will throw
8170
8171 // Verify that the X coordinate in the public point corresponds to a point on the curve.
8172 // If not, the extended public key is invalid.
8173 curve.validate(Q)
8174
8175 keyPair = new ECPair(null, Q, { network: network })
8176 }
8177
8178 var hd = new HDNode(keyPair, chainCode)
8179 hd.depth = depth
8180 hd.index = index
8181 hd.parentFingerprint = parentFingerprint
8182
8183 return hd
8184}
8185
8186HDNode.prototype.getAddress = function () {
8187 return this.keyPair.getAddress()
8188}
8189
8190HDNode.prototype.getIdentifier = function () {
8191 return bcrypto.hash160(this.keyPair.getPublicKeyBuffer())
8192}
8193
8194HDNode.prototype.getFingerprint = function () {
8195 return this.getIdentifier().slice(0, 4)
8196}
8197
8198HDNode.prototype.getNetwork = function () {
8199 return this.keyPair.getNetwork()
8200}
8201
8202HDNode.prototype.getPublicKeyBuffer = function () {
8203 return this.keyPair.getPublicKeyBuffer()
8204}
8205
8206HDNode.prototype.neutered = function () {
8207 var neuteredKeyPair = new ECPair(null, this.keyPair.Q, {
8208 network: this.keyPair.network
8209 })
8210
8211 var neutered = new HDNode(neuteredKeyPair, this.chainCode)
8212 neutered.depth = this.depth
8213 neutered.index = this.index
8214 neutered.parentFingerprint = this.parentFingerprint
8215
8216 return neutered
8217}
8218
8219HDNode.prototype.sign = function (hash) {
8220 return this.keyPair.sign(hash)
8221}
8222
8223HDNode.prototype.verify = function (hash, signature) {
8224 return this.keyPair.verify(hash, signature)
8225}
8226
8227HDNode.prototype.toBase58 = function (__isPrivate) {
8228 if (__isPrivate !== undefined) throw new TypeError('Unsupported argument in 2.0.0')
8229
8230 // Version
8231 var network = this.keyPair.network
8232 var version = (!this.isNeutered()) ? network.bip32.private : network.bip32.public
8233 var buffer = Buffer.allocUnsafe(78)
8234
8235 // 4 bytes: version bytes
8236 buffer.writeUInt32BE(version, 0)
8237
8238 // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ....
8239 buffer.writeUInt8(this.depth, 4)
8240
8241 // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
8242 buffer.writeUInt32BE(this.parentFingerprint, 5)
8243
8244 // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
8245 // This is encoded in big endian. (0x00000000 if master key)
8246 buffer.writeUInt32BE(this.index, 9)
8247
8248 // 32 bytes: the chain code
8249 this.chainCode.copy(buffer, 13)
8250
8251 // 33 bytes: the public key or private key data
8252 if (!this.isNeutered()) {
8253 // 0x00 + k for private keys
8254 buffer.writeUInt8(0, 45)
8255 this.keyPair.d.toBuffer(32).copy(buffer, 46)
8256
8257 // 33 bytes: the public key
8258 } else {
8259 // X9.62 encoding for public keys
8260 this.keyPair.getPublicKeyBuffer().copy(buffer, 45)
8261 }
8262
8263 return base58grscheck.encode(buffer)
8264}
8265
8266// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
8267HDNode.prototype.derive = function (index) {
8268 typeforce(types.UInt32, index)
8269
8270 var isHardened = index >= HDNode.HIGHEST_BIT
8271 var data = Buffer.allocUnsafe(37)
8272
8273 // Hardened child
8274 if (isHardened) {
8275 if (this.isNeutered()) throw new TypeError('Could not derive hardened child key')
8276
8277 // data = 0x00 || ser256(kpar) || ser32(index)
8278 data[0] = 0x00
8279 this.keyPair.d.toBuffer(32).copy(data, 1)
8280 data.writeUInt32BE(index, 33)
8281
8282 // Normal child
8283 } else {
8284 // data = serP(point(kpar)) || ser32(index)
8285 // = serP(Kpar) || ser32(index)
8286 this.keyPair.getPublicKeyBuffer().copy(data, 0)
8287 data.writeUInt32BE(index, 33)
8288 }
8289
8290 var I = createHmac('sha512', this.chainCode).update(data).digest()
8291 var IL = I.slice(0, 32)
8292 var IR = I.slice(32)
8293
8294 var pIL = BigInteger.fromBuffer(IL)
8295
8296 // In case parse256(IL) >= n, proceed with the next value for i
8297 if (pIL.compareTo(curve.n) >= 0) {
8298 return this.derive(index + 1)
8299 }
8300
8301 // Private parent key -> private child key
8302 var derivedKeyPair
8303 if (!this.isNeutered()) {
8304 // ki = parse256(IL) + kpar (mod n)
8305 var ki = pIL.add(this.keyPair.d).mod(curve.n)
8306
8307 // In case ki == 0, proceed with the next value for i
8308 if (ki.signum() === 0) {
8309 return this.derive(index + 1)
8310 }
8311
8312 derivedKeyPair = new ECPair(ki, null, {
8313 network: this.keyPair.network
8314 })
8315
8316 // Public parent key -> public child key
8317 } else {
8318 // Ki = point(parse256(IL)) + Kpar
8319 // = G*IL + Kpar
8320 var Ki = curve.G.multiply(pIL).add(this.keyPair.Q)
8321
8322 // In case Ki is the point at infinity, proceed with the next value for i
8323 if (curve.isInfinity(Ki)) {
8324 return this.derive(index + 1)
8325 }
8326
8327 derivedKeyPair = new ECPair(null, Ki, {
8328 network: this.keyPair.network
8329 })
8330 }
8331
8332 var hd = new HDNode(derivedKeyPair, IR)
8333 hd.depth = this.depth + 1
8334 hd.index = index
8335 hd.parentFingerprint = this.getFingerprint().readUInt32BE(0)
8336
8337 return hd
8338}
8339
8340HDNode.prototype.deriveHardened = function (index) {
8341 typeforce(types.UInt31, index)
8342
8343 // Only derives hardened private keys by default
8344 return this.derive(index + HDNode.HIGHEST_BIT)
8345}
8346
8347// Private === not neutered
8348// Public === neutered
8349HDNode.prototype.isNeutered = function () {
8350 return !(this.keyPair.d)
8351}
8352
8353HDNode.prototype.derivePath = function (path) {
8354 typeforce(types.BIP32Path, path)
8355
8356 var splitPath = path.split('/')
8357 if (splitPath[0] === 'm') {
8358 if (this.parentFingerprint) {
8359 throw new Error('Not a master node')
8360 }
8361
8362 splitPath = splitPath.slice(1)
8363 }
8364
8365 return splitPath.reduce(function (prevHd, indexStr) {
8366 var index
8367 if (indexStr.slice(-1) === "'") {
8368 index = parseInt(indexStr.slice(0, -1), 10)
8369 return prevHd.deriveHardened(index)
8370 } else {
8371 index = parseInt(indexStr, 10)
8372 return prevHd.derive(index)
8373 }
8374 }, this)
8375}
8376
8377module.exports = HDNode
8378
8379},{"./crypto":56,"./ecpair":58,"./networks":62,"./types":89,"bigi":5,"bs58grscheck":12,"create-hmac":16,"ecurve":20,"safe-buffer":38,"typeforce":49}],61:[function(require,module,exports){
8380var script = require('./script')
8381
8382var templates = require('./templates')
8383for (var key in templates) {
8384 script[key] = templates[key]
8385}
8386
8387module.exports = {
8388 bufferutils: require('./bufferutils'), // TODO: remove in 4.0.0
8389
8390 Block: require('./block'),
8391 ECPair: require('./ecpair'),
8392 ECSignature: require('./ecsignature'),
8393 HDNode: require('./hdnode'),
8394 Transaction: require('./transaction'),
8395 TransactionBuilder: require('./transaction_builder'),
8396
8397 address: require('./address'),
8398 crypto: require('./crypto'),
8399 networks: require('./networks'),
8400 opcodes: require('bitcoin-ops'),
8401 script: script
8402}
8403
8404},{"./address":53,"./block":54,"./bufferutils":55,"./crypto":56,"./ecpair":58,"./ecsignature":59,"./hdnode":60,"./networks":62,"./script":63,"./templates":65,"./transaction":87,"./transaction_builder":88,"bitcoin-ops":8}],62:[function(require,module,exports){
8405// https://en.bitcoin.it/wiki/List_of_address_prefixes
8406// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
8407
8408module.exports = {
8409 bitcoin: {
8410 messagePrefix: '\x1cGroestlCoin Signed Message:\n',
8411 bech32: 'grs',
8412 bip32: {
8413 public: 0x0488b21e,
8414 private: 0x0488ade4
8415 },
8416 pubKeyHash: 0x24,
8417 scriptHash: 0x05,
8418 wif: 0x80
8419 },
8420 testnet: {
8421 messagePrefix: '\x1cGroestlCoin Signed Message:\n',
8422 bech32: 'tgrs',
8423 bip32: {
8424 public: 0x043587cf,
8425 private: 0x04358394
8426 },
8427 pubKeyHash: 0x6f,
8428 scriptHash: 0xc4,
8429 wif: 0xef
8430 },
8431 litecoin: {
8432 messagePrefix: '\x19Litecoin Signed Message:\n',
8433 bip32: {
8434 public: 0x019da462,
8435 private: 0x019d9cfe
8436 },
8437 pubKeyHash: 0x30,
8438 scriptHash: 0x32,
8439 wif: 0xb0
8440 }
8441}
8442
8443},{}],63:[function(require,module,exports){
8444var Buffer = require('safe-buffer').Buffer
8445var bip66 = require('bip66')
8446var pushdata = require('pushdata-bitcoin')
8447var typeforce = require('typeforce')
8448var types = require('./types')
8449var scriptNumber = require('./script_number')
8450
8451var OPS = require('bitcoin-ops')
8452var REVERSE_OPS = require('bitcoin-ops/map')
8453var OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
8454
8455function isOPInt (value) {
8456 return types.Number(value) &&
8457 ((value === OPS.OP_0) ||
8458 (value >= OPS.OP_1 && value <= OPS.OP_16) ||
8459 (value === OPS.OP_1NEGATE))
8460}
8461
8462function isPushOnlyChunk (value) {
8463 return types.Buffer(value) || isOPInt(value)
8464}
8465
8466function isPushOnly (value) {
8467 return types.Array(value) && value.every(isPushOnlyChunk)
8468}
8469
8470function asMinimalOP (buffer) {
8471 if (buffer.length === 0) return OPS.OP_0
8472 if (buffer.length !== 1) return
8473 if (buffer[0] >= 1 && buffer[0] <= 16) return OP_INT_BASE + buffer[0]
8474 if (buffer[0] === 0x81) return OPS.OP_1NEGATE
8475}
8476
8477function compile (chunks) {
8478 // TODO: remove me
8479 if (Buffer.isBuffer(chunks)) return chunks
8480
8481 typeforce(types.Array, chunks)
8482
8483 var bufferSize = chunks.reduce(function (accum, chunk) {
8484 // data chunk
8485 if (Buffer.isBuffer(chunk)) {
8486 // adhere to BIP62.3, minimal push policy
8487 if (chunk.length === 1 && asMinimalOP(chunk) !== undefined) {
8488 return accum + 1
8489 }
8490
8491 return accum + pushdata.encodingLength(chunk.length) + chunk.length
8492 }
8493
8494 // opcode
8495 return accum + 1
8496 }, 0.0)
8497
8498 var buffer = Buffer.allocUnsafe(bufferSize)
8499 var offset = 0
8500
8501 chunks.forEach(function (chunk) {
8502 // data chunk
8503 if (Buffer.isBuffer(chunk)) {
8504 // adhere to BIP62.3, minimal push policy
8505 var opcode = asMinimalOP(chunk)
8506 if (opcode !== undefined) {
8507 buffer.writeUInt8(opcode, offset)
8508 offset += 1
8509 return
8510 }
8511
8512 offset += pushdata.encode(buffer, chunk.length, offset)
8513 chunk.copy(buffer, offset)
8514 offset += chunk.length
8515
8516 // opcode
8517 } else {
8518 buffer.writeUInt8(chunk, offset)
8519 offset += 1
8520 }
8521 })
8522
8523 if (offset !== buffer.length) throw new Error('Could not decode chunks')
8524 return buffer
8525}
8526
8527function decompile (buffer) {
8528 // TODO: remove me
8529 if (types.Array(buffer)) return buffer
8530
8531 typeforce(types.Buffer, buffer)
8532
8533 var chunks = []
8534 var i = 0
8535
8536 while (i < buffer.length) {
8537 var opcode = buffer[i]
8538
8539 // data chunk
8540 if ((opcode > OPS.OP_0) && (opcode <= OPS.OP_PUSHDATA4)) {
8541 var d = pushdata.decode(buffer, i)
8542
8543 // did reading a pushDataInt fail? empty script
8544 if (d === null) return []
8545 i += d.size
8546
8547 // attempt to read too much data? empty script
8548 if (i + d.number > buffer.length) return []
8549
8550 var data = buffer.slice(i, i + d.number)
8551 i += d.number
8552
8553 // decompile minimally
8554 var op = asMinimalOP(data)
8555 if (op !== undefined) {
8556 chunks.push(op)
8557 } else {
8558 chunks.push(data)
8559 }
8560
8561 // opcode
8562 } else {
8563 chunks.push(opcode)
8564
8565 i += 1
8566 }
8567 }
8568
8569 return chunks
8570}
8571
8572function toASM (chunks) {
8573 if (Buffer.isBuffer(chunks)) {
8574 chunks = decompile(chunks)
8575 }
8576
8577 return chunks.map(function (chunk) {
8578 // data?
8579 if (Buffer.isBuffer(chunk)) {
8580 var op = asMinimalOP(chunk)
8581 if (op === undefined) return chunk.toString('hex')
8582 chunk = op
8583 }
8584
8585 // opcode!
8586 return REVERSE_OPS[chunk]
8587 }).join(' ')
8588}
8589
8590function fromASM (asm) {
8591 typeforce(types.String, asm)
8592
8593 return compile(asm.split(' ').map(function (chunkStr) {
8594 // opcode?
8595 if (OPS[chunkStr] !== undefined) return OPS[chunkStr]
8596 typeforce(types.Hex, chunkStr)
8597
8598 // data!
8599 return Buffer.from(chunkStr, 'hex')
8600 }))
8601}
8602
8603function toStack (chunks) {
8604 chunks = decompile(chunks)
8605 typeforce(isPushOnly, chunks)
8606
8607 return chunks.map(function (op) {
8608 if (Buffer.isBuffer(op)) return op
8609 if (op === OPS.OP_0) return Buffer.allocUnsafe(0)
8610
8611 return scriptNumber.encode(op - OP_INT_BASE)
8612 })
8613}
8614
8615function isCanonicalPubKey (buffer) {
8616 if (!Buffer.isBuffer(buffer)) return false
8617 if (buffer.length < 33) return false
8618
8619 switch (buffer[0]) {
8620 case 0x02:
8621 case 0x03:
8622 return buffer.length === 33
8623 case 0x04:
8624 return buffer.length === 65
8625 }
8626
8627 return false
8628}
8629
8630function isDefinedHashType (hashType) {
8631 var hashTypeMod = hashType & ~0x80
8632
8633// return hashTypeMod > SIGHASH_ALL && hashTypeMod < SIGHASH_SINGLE
8634 return hashTypeMod > 0x00 && hashTypeMod < 0x04
8635}
8636
8637function isCanonicalSignature (buffer) {
8638 if (!Buffer.isBuffer(buffer)) return false
8639 if (!isDefinedHashType(buffer[buffer.length - 1])) return false
8640
8641 return bip66.check(buffer.slice(0, -1))
8642}
8643
8644module.exports = {
8645 compile: compile,
8646 decompile: decompile,
8647 fromASM: fromASM,
8648 toASM: toASM,
8649 toStack: toStack,
8650
8651 number: require('./script_number'),
8652
8653 isCanonicalPubKey: isCanonicalPubKey,
8654 isCanonicalSignature: isCanonicalSignature,
8655 isPushOnly: isPushOnly,
8656 isDefinedHashType: isDefinedHashType
8657}
8658
8659},{"./script_number":64,"./types":89,"bip66":7,"bitcoin-ops":8,"bitcoin-ops/map":9,"pushdata-bitcoin":35,"safe-buffer":38,"typeforce":49}],64:[function(require,module,exports){
8660var Buffer = require('safe-buffer').Buffer
8661
8662function decode (buffer, maxLength, minimal) {
8663 maxLength = maxLength || 4
8664 minimal = minimal === undefined ? true : minimal
8665
8666 var length = buffer.length
8667 if (length === 0) return 0
8668 if (length > maxLength) throw new TypeError('Script number overflow')
8669 if (minimal) {
8670 if ((buffer[length - 1] & 0x7f) === 0) {
8671 if (length <= 1 || (buffer[length - 2] & 0x80) === 0) throw new Error('Non-minimally encoded script number')
8672 }
8673 }
8674
8675 // 40-bit
8676 if (length === 5) {
8677 var a = buffer.readUInt32LE(0)
8678 var b = buffer.readUInt8(4)
8679
8680 if (b & 0x80) return -(((b & ~0x80) * 0x100000000) + a)
8681 return (b * 0x100000000) + a
8682 }
8683
8684 var result = 0
8685
8686 // 32-bit / 24-bit / 16-bit / 8-bit
8687 for (var i = 0; i < length; ++i) {
8688 result |= buffer[i] << (8 * i)
8689 }
8690
8691 if (buffer[length - 1] & 0x80) return -(result & ~(0x80 << (8 * (length - 1))))
8692 return result
8693}
8694
8695function scriptNumSize (i) {
8696 return i > 0x7fffffff ? 5
8697 : i > 0x7fffff ? 4
8698 : i > 0x7fff ? 3
8699 : i > 0x7f ? 2
8700 : i > 0x00 ? 1
8701 : 0
8702}
8703
8704function encode (number) {
8705 var value = Math.abs(number)
8706 var size = scriptNumSize(value)
8707 var buffer = Buffer.allocUnsafe(size)
8708 var negative = number < 0
8709
8710 for (var i = 0; i < size; ++i) {
8711 buffer.writeUInt8(value & 0xff, i)
8712 value >>= 8
8713 }
8714
8715 if (buffer[size - 1] & 0x80) {
8716 buffer.writeUInt8(negative ? 0x80 : 0x00, size - 1)
8717 } else if (negative) {
8718 buffer[size - 1] |= 0x80
8719 }
8720
8721 return buffer
8722}
8723
8724module.exports = {
8725 decode: decode,
8726 encode: encode
8727}
8728
8729},{"safe-buffer":38}],65:[function(require,module,exports){
8730var decompile = require('../script').decompile
8731var multisig = require('./multisig')
8732var nullData = require('./nulldata')
8733var pubKey = require('./pubkey')
8734var pubKeyHash = require('./pubkeyhash')
8735var scriptHash = require('./scripthash')
8736var witnessPubKeyHash = require('./witnesspubkeyhash')
8737var witnessScriptHash = require('./witnessscripthash')
8738var witnessCommitment = require('./witnesscommitment')
8739
8740var types = {
8741 MULTISIG: 'multisig',
8742 NONSTANDARD: 'nonstandard',
8743 NULLDATA: 'nulldata',
8744 P2PK: 'pubkey',
8745 P2PKH: 'pubkeyhash',
8746 P2SH: 'scripthash',
8747 P2WPKH: 'witnesspubkeyhash',
8748 P2WSH: 'witnessscripthash',
8749 WITNESS_COMMITMENT: 'witnesscommitment'
8750}
8751
8752function classifyOutput (script) {
8753 if (witnessPubKeyHash.output.check(script)) return types.P2WPKH
8754 if (witnessScriptHash.output.check(script)) return types.P2WSH
8755 if (pubKeyHash.output.check(script)) return types.P2PKH
8756 if (scriptHash.output.check(script)) return types.P2SH
8757
8758 // XXX: optimization, below functions .decompile before use
8759 var chunks = decompile(script)
8760 if (multisig.output.check(chunks)) return types.MULTISIG
8761 if (pubKey.output.check(chunks)) return types.P2PK
8762 if (witnessCommitment.output.check(chunks)) return types.WITNESS_COMMITMENT
8763 if (nullData.output.check(chunks)) return types.NULLDATA
8764
8765 return types.NONSTANDARD
8766}
8767
8768function classifyInput (script, allowIncomplete) {
8769 // XXX: optimization, below functions .decompile before use
8770 var chunks = decompile(script)
8771
8772 if (pubKeyHash.input.check(chunks)) return types.P2PKH
8773 if (scriptHash.input.check(chunks, allowIncomplete)) return types.P2SH
8774 if (multisig.input.check(chunks, allowIncomplete)) return types.MULTISIG
8775 if (pubKey.input.check(chunks)) return types.P2PK
8776
8777 return types.NONSTANDARD
8778}
8779
8780function classifyWitness (script, allowIncomplete) {
8781 // XXX: optimization, below functions .decompile before use
8782 var chunks = decompile(script)
8783
8784 if (witnessPubKeyHash.input.check(chunks)) return types.P2WPKH
8785 if (witnessScriptHash.input.check(chunks, allowIncomplete)) return types.P2WSH
8786
8787 return types.NONSTANDARD
8788}
8789
8790module.exports = {
8791 classifyInput: classifyInput,
8792 classifyOutput: classifyOutput,
8793 classifyWitness: classifyWitness,
8794 multisig: multisig,
8795 nullData: nullData,
8796 pubKey: pubKey,
8797 pubKeyHash: pubKeyHash,
8798 scriptHash: scriptHash,
8799 witnessPubKeyHash: witnessPubKeyHash,
8800 witnessScriptHash: witnessScriptHash,
8801 witnessCommitment: witnessCommitment,
8802 types: types
8803}
8804
8805},{"../script":63,"./multisig":66,"./nulldata":69,"./pubkey":70,"./pubkeyhash":73,"./scripthash":76,"./witnesscommitment":79,"./witnesspubkeyhash":81,"./witnessscripthash":84}],66:[function(require,module,exports){
8806module.exports = {
8807 input: require('./input'),
8808 output: require('./output')
8809}
8810
8811},{"./input":67,"./output":68}],67:[function(require,module,exports){
8812// OP_0 [signatures ...]
8813
8814var Buffer = require('safe-buffer').Buffer
8815var bscript = require('../../script')
8816var p2mso = require('./output')
8817var typeforce = require('typeforce')
8818var OPS = require('bitcoin-ops')
8819
8820function partialSignature (value) {
8821 return value === OPS.OP_0 || bscript.isCanonicalSignature(value)
8822}
8823
8824function check (script, allowIncomplete) {
8825 var chunks = bscript.decompile(script)
8826 if (chunks.length < 2) return false
8827 if (chunks[0] !== OPS.OP_0) return false
8828
8829 if (allowIncomplete) {
8830 return chunks.slice(1).every(partialSignature)
8831 }
8832
8833 return chunks.slice(1).every(bscript.isCanonicalSignature)
8834}
8835check.toJSON = function () { return 'multisig input' }
8836
8837var EMPTY_BUFFER = Buffer.allocUnsafe(0)
8838
8839function encodeStack (signatures, scriptPubKey) {
8840 typeforce([partialSignature], signatures)
8841
8842 if (scriptPubKey) {
8843 var scriptData = p2mso.decode(scriptPubKey)
8844
8845 if (signatures.length < scriptData.m) {
8846 throw new TypeError('Not enough signatures provided')
8847 }
8848
8849 if (signatures.length > scriptData.pubKeys.length) {
8850 throw new TypeError('Too many signatures provided')
8851 }
8852 }
8853
8854 return [].concat(EMPTY_BUFFER, signatures.map(function (sig) {
8855 if (sig === OPS.OP_0) {
8856 return EMPTY_BUFFER
8857 }
8858 return sig
8859 }))
8860}
8861
8862function encode (signatures, scriptPubKey) {
8863 return bscript.compile(encodeStack(signatures, scriptPubKey))
8864}
8865
8866function decodeStack (stack, allowIncomplete) {
8867 typeforce(typeforce.Array, stack)
8868 typeforce(check, stack, allowIncomplete)
8869 return stack.slice(1)
8870}
8871
8872function decode (buffer, allowIncomplete) {
8873 var stack = bscript.decompile(buffer)
8874 return decodeStack(stack, allowIncomplete)
8875}
8876
8877module.exports = {
8878 check: check,
8879 decode: decode,
8880 decodeStack: decodeStack,
8881 encode: encode,
8882 encodeStack: encodeStack
8883}
8884
8885},{"../../script":63,"./output":68,"bitcoin-ops":8,"safe-buffer":38,"typeforce":49}],68:[function(require,module,exports){
8886// m [pubKeys ...] n OP_CHECKMULTISIG
8887
8888var bscript = require('../../script')
8889var types = require('../../types')
8890var typeforce = require('typeforce')
8891var OPS = require('bitcoin-ops')
8892var OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
8893
8894function check (script, allowIncomplete) {
8895 var chunks = bscript.decompile(script)
8896
8897 if (chunks.length < 4) return false
8898 if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false
8899 if (!types.Number(chunks[0])) return false
8900 if (!types.Number(chunks[chunks.length - 2])) return false
8901 var m = chunks[0] - OP_INT_BASE
8902 var n = chunks[chunks.length - 2] - OP_INT_BASE
8903
8904 if (m <= 0) return false
8905 if (n > 16) return false
8906 if (m > n) return false
8907 if (n !== chunks.length - 3) return false
8908 if (allowIncomplete) return true
8909
8910 var keys = chunks.slice(1, -2)
8911 return keys.every(bscript.isCanonicalPubKey)
8912}
8913check.toJSON = function () { return 'multi-sig output' }
8914
8915function encode (m, pubKeys) {
8916 typeforce({
8917 m: types.Number,
8918 pubKeys: [bscript.isCanonicalPubKey]
8919 }, {
8920 m: m,
8921 pubKeys: pubKeys
8922 })
8923
8924 var n = pubKeys.length
8925 if (n < m) throw new TypeError('Not enough pubKeys provided')
8926
8927 return bscript.compile([].concat(
8928 OP_INT_BASE + m,
8929 pubKeys,
8930 OP_INT_BASE + n,
8931 OPS.OP_CHECKMULTISIG
8932 ))
8933}
8934
8935function decode (buffer, allowIncomplete) {
8936 var chunks = bscript.decompile(buffer)
8937 typeforce(check, chunks, allowIncomplete)
8938
8939 return {
8940 m: chunks[0] - OP_INT_BASE,
8941 pubKeys: chunks.slice(1, -2)
8942 }
8943}
8944
8945module.exports = {
8946 check: check,
8947 decode: decode,
8948 encode: encode
8949}
8950
8951},{"../../script":63,"../../types":89,"bitcoin-ops":8,"typeforce":49}],69:[function(require,module,exports){
8952// OP_RETURN {data}
8953
8954var bscript = require('../script')
8955var types = require('../types')
8956var typeforce = require('typeforce')
8957var OPS = require('bitcoin-ops')
8958
8959function check (script) {
8960 var buffer = bscript.compile(script)
8961
8962 return buffer.length > 1 &&
8963 buffer[0] === OPS.OP_RETURN
8964}
8965check.toJSON = function () { return 'null data output' }
8966
8967function encode (data) {
8968 typeforce(types.Buffer, data)
8969
8970 return bscript.compile([OPS.OP_RETURN, data])
8971}
8972
8973function decode (buffer) {
8974 typeforce(check, buffer)
8975
8976 return buffer.slice(2)
8977}
8978
8979module.exports = {
8980 output: {
8981 check: check,
8982 decode: decode,
8983 encode: encode
8984 }
8985}
8986
8987},{"../script":63,"../types":89,"bitcoin-ops":8,"typeforce":49}],70:[function(require,module,exports){
8988arguments[4][66][0].apply(exports,arguments)
8989},{"./input":71,"./output":72,"dup":66}],71:[function(require,module,exports){
8990// {signature}
8991
8992var bscript = require('../../script')
8993var typeforce = require('typeforce')
8994
8995function check (script) {
8996 var chunks = bscript.decompile(script)
8997
8998 return chunks.length === 1 &&
8999 bscript.isCanonicalSignature(chunks[0])
9000}
9001check.toJSON = function () { return 'pubKey input' }
9002
9003function encodeStack (signature) {
9004 typeforce(bscript.isCanonicalSignature, signature)
9005 return [signature]
9006}
9007
9008function encode (signature) {
9009 return bscript.compile(encodeStack(signature))
9010}
9011
9012function decodeStack (stack) {
9013 typeforce(typeforce.Array, stack)
9014 typeforce(check, stack)
9015 return stack[0]
9016}
9017
9018function decode (buffer) {
9019 var stack = bscript.decompile(buffer)
9020 return decodeStack(stack)
9021}
9022
9023module.exports = {
9024 check: check,
9025 decode: decode,
9026 decodeStack: decodeStack,
9027 encode: encode,
9028 encodeStack: encodeStack
9029}
9030
9031},{"../../script":63,"typeforce":49}],72:[function(require,module,exports){
9032// {pubKey} OP_CHECKSIG
9033
9034var bscript = require('../../script')
9035var typeforce = require('typeforce')
9036var OPS = require('bitcoin-ops')
9037
9038function check (script) {
9039 var chunks = bscript.decompile(script)
9040
9041 return chunks.length === 2 &&
9042 bscript.isCanonicalPubKey(chunks[0]) &&
9043 chunks[1] === OPS.OP_CHECKSIG
9044}
9045check.toJSON = function () { return 'pubKey output' }
9046
9047function encode (pubKey) {
9048 typeforce(bscript.isCanonicalPubKey, pubKey)
9049
9050 return bscript.compile([pubKey, OPS.OP_CHECKSIG])
9051}
9052
9053function decode (buffer) {
9054 var chunks = bscript.decompile(buffer)
9055 typeforce(check, chunks)
9056
9057 return chunks[0]
9058}
9059
9060module.exports = {
9061 check: check,
9062 decode: decode,
9063 encode: encode
9064}
9065
9066},{"../../script":63,"bitcoin-ops":8,"typeforce":49}],73:[function(require,module,exports){
9067arguments[4][66][0].apply(exports,arguments)
9068},{"./input":74,"./output":75,"dup":66}],74:[function(require,module,exports){
9069// {signature} {pubKey}
9070
9071var bscript = require('../../script')
9072var typeforce = require('typeforce')
9073
9074function check (script) {
9075 var chunks = bscript.decompile(script)
9076
9077 return chunks.length === 2 &&
9078 bscript.isCanonicalSignature(chunks[0]) &&
9079 bscript.isCanonicalPubKey(chunks[1])
9080}
9081check.toJSON = function () { return 'pubKeyHash input' }
9082
9083function encodeStack (signature, pubKey) {
9084 typeforce({
9085 signature: bscript.isCanonicalSignature,
9086 pubKey: bscript.isCanonicalPubKey
9087 }, {
9088 signature: signature,
9089 pubKey: pubKey
9090 })
9091
9092 return [signature, pubKey]
9093}
9094
9095function encode (signature, pubKey) {
9096 return bscript.compile(encodeStack(signature, pubKey))
9097}
9098
9099function decodeStack (stack) {
9100 typeforce(typeforce.Array, stack)
9101 typeforce(check, stack)
9102
9103 return {
9104 signature: stack[0],
9105 pubKey: stack[1]
9106 }
9107}
9108
9109function decode (buffer) {
9110 var stack = bscript.decompile(buffer)
9111 return decodeStack(stack)
9112}
9113
9114module.exports = {
9115 check: check,
9116 decode: decode,
9117 decodeStack: decodeStack,
9118 encode: encode,
9119 encodeStack: encodeStack
9120}
9121
9122},{"../../script":63,"typeforce":49}],75:[function(require,module,exports){
9123// OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
9124
9125var bscript = require('../../script')
9126var types = require('../../types')
9127var typeforce = require('typeforce')
9128var OPS = require('bitcoin-ops')
9129
9130function check (script) {
9131 var buffer = bscript.compile(script)
9132
9133 return buffer.length === 25 &&
9134 buffer[0] === OPS.OP_DUP &&
9135 buffer[1] === OPS.OP_HASH160 &&
9136 buffer[2] === 0x14 &&
9137 buffer[23] === OPS.OP_EQUALVERIFY &&
9138 buffer[24] === OPS.OP_CHECKSIG
9139}
9140check.toJSON = function () { return 'pubKeyHash output' }
9141
9142function encode (pubKeyHash) {
9143 typeforce(types.Hash160bit, pubKeyHash)
9144
9145 return bscript.compile([
9146 OPS.OP_DUP,
9147 OPS.OP_HASH160,
9148 pubKeyHash,
9149 OPS.OP_EQUALVERIFY,
9150 OPS.OP_CHECKSIG
9151 ])
9152}
9153
9154function decode (buffer) {
9155 typeforce(check, buffer)
9156
9157 return buffer.slice(3, 23)
9158}
9159
9160module.exports = {
9161 check: check,
9162 decode: decode,
9163 encode: encode
9164}
9165
9166},{"../../script":63,"../../types":89,"bitcoin-ops":8,"typeforce":49}],76:[function(require,module,exports){
9167arguments[4][66][0].apply(exports,arguments)
9168},{"./input":77,"./output":78,"dup":66}],77:[function(require,module,exports){
9169// <scriptSig> {serialized scriptPubKey script}
9170
9171var Buffer = require('safe-buffer').Buffer
9172var bscript = require('../../script')
9173var typeforce = require('typeforce')
9174
9175var p2ms = require('../multisig/')
9176var p2pk = require('../pubkey/')
9177var p2pkh = require('../pubkeyhash/')
9178var p2wpkho = require('../witnesspubkeyhash/output')
9179var p2wsho = require('../witnessscripthash/output')
9180
9181function check (script, allowIncomplete) {
9182 var chunks = bscript.decompile(script)
9183 if (chunks.length < 1) return false
9184
9185 var lastChunk = chunks[chunks.length - 1]
9186 if (!Buffer.isBuffer(lastChunk)) return false
9187
9188 var scriptSigChunks = bscript.decompile(bscript.compile(chunks.slice(0, -1)))
9189 var redeemScriptChunks = bscript.decompile(lastChunk)
9190
9191 // is redeemScript a valid script?
9192 if (redeemScriptChunks.length === 0) return false
9193
9194 // is redeemScriptSig push only?
9195 if (!bscript.isPushOnly(scriptSigChunks)) return false
9196
9197 // is witness?
9198 if (chunks.length === 1) {
9199 return p2wsho.check(redeemScriptChunks) ||
9200 p2wpkho.check(redeemScriptChunks)
9201 }
9202
9203 // match types
9204 if (p2pkh.input.check(scriptSigChunks) &&
9205 p2pkh.output.check(redeemScriptChunks)) return true
9206
9207 if (p2ms.input.check(scriptSigChunks, allowIncomplete) &&
9208 p2ms.output.check(redeemScriptChunks)) return true
9209
9210 if (p2pk.input.check(scriptSigChunks) &&
9211 p2pk.output.check(redeemScriptChunks)) return true
9212
9213 return false
9214}
9215check.toJSON = function () { return 'scriptHash input' }
9216
9217function encodeStack (redeemScriptStack, redeemScript) {
9218 var serializedScriptPubKey = bscript.compile(redeemScript)
9219
9220 return [].concat(redeemScriptStack, serializedScriptPubKey)
9221}
9222
9223function encode (redeemScriptSig, redeemScript) {
9224 var redeemScriptStack = bscript.decompile(redeemScriptSig)
9225
9226 return bscript.compile(encodeStack(redeemScriptStack, redeemScript))
9227}
9228
9229function decodeStack (stack) {
9230 typeforce(typeforce.Array, stack)
9231 typeforce(check, stack)
9232
9233 return {
9234 redeemScriptStack: stack.slice(0, -1),
9235 redeemScript: stack[stack.length - 1]
9236 }
9237}
9238
9239function decode (buffer) {
9240 var stack = bscript.decompile(buffer)
9241 var result = decodeStack(stack)
9242 result.redeemScriptSig = bscript.compile(result.redeemScriptStack)
9243 delete result.redeemScriptStack
9244 return result
9245}
9246
9247module.exports = {
9248 check: check,
9249 decode: decode,
9250 decodeStack: decodeStack,
9251 encode: encode,
9252 encodeStack: encodeStack
9253}
9254
9255},{"../../script":63,"../multisig/":66,"../pubkey/":70,"../pubkeyhash/":73,"../witnesspubkeyhash/output":83,"../witnessscripthash/output":86,"safe-buffer":38,"typeforce":49}],78:[function(require,module,exports){
9256// OP_HASH160 {scriptHash} OP_EQUAL
9257
9258var bscript = require('../../script')
9259var types = require('../../types')
9260var typeforce = require('typeforce')
9261var OPS = require('bitcoin-ops')
9262
9263function check (script) {
9264 var buffer = bscript.compile(script)
9265
9266 return buffer.length === 23 &&
9267 buffer[0] === OPS.OP_HASH160 &&
9268 buffer[1] === 0x14 &&
9269 buffer[22] === OPS.OP_EQUAL
9270}
9271check.toJSON = function () { return 'scriptHash output' }
9272
9273function encode (scriptHash) {
9274 typeforce(types.Hash160bit, scriptHash)
9275
9276 return bscript.compile([OPS.OP_HASH160, scriptHash, OPS.OP_EQUAL])
9277}
9278
9279function decode (buffer) {
9280 typeforce(check, buffer)
9281
9282 return buffer.slice(2, 22)
9283}
9284
9285module.exports = {
9286 check: check,
9287 decode: decode,
9288 encode: encode
9289}
9290
9291},{"../../script":63,"../../types":89,"bitcoin-ops":8,"typeforce":49}],79:[function(require,module,exports){
9292module.exports = {
9293 output: require('./output')
9294}
9295
9296},{"./output":80}],80:[function(require,module,exports){
9297// OP_RETURN {aa21a9ed} {commitment}
9298
9299var Buffer = require('safe-buffer').Buffer
9300var bscript = require('../../script')
9301var types = require('../../types')
9302var typeforce = require('typeforce')
9303var OPS = require('bitcoin-ops')
9304
9305var HEADER = Buffer.from('aa21a9ed', 'hex')
9306
9307function check (script) {
9308 var buffer = bscript.compile(script)
9309
9310 return buffer.length > 37 &&
9311 buffer[0] === OPS.OP_RETURN &&
9312 buffer[1] === 0x24 &&
9313 buffer.slice(2, 6).equals(HEADER)
9314}
9315
9316check.toJSON = function () { return 'Witness commitment output' }
9317
9318function encode (commitment) {
9319 typeforce(types.Hash256bit, commitment)
9320
9321 var buffer = Buffer.allocUnsafe(36)
9322 HEADER.copy(buffer, 0)
9323 commitment.copy(buffer, 4)
9324
9325 return bscript.compile([OPS.OP_RETURN, buffer])
9326}
9327
9328function decode (buffer) {
9329 typeforce(check, buffer)
9330
9331 return bscript.decompile(buffer)[1].slice(4, 36)
9332}
9333
9334module.exports = {
9335 check: check,
9336 decode: decode,
9337 encode: encode
9338}
9339
9340},{"../../script":63,"../../types":89,"bitcoin-ops":8,"safe-buffer":38,"typeforce":49}],81:[function(require,module,exports){
9341arguments[4][66][0].apply(exports,arguments)
9342},{"./input":82,"./output":83,"dup":66}],82:[function(require,module,exports){
9343// {signature} {pubKey}
9344
9345var bscript = require('../../script')
9346var typeforce = require('typeforce')
9347
9348function isCompressedCanonicalPubKey (pubKey) {
9349 return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33
9350}
9351
9352function check (script) {
9353 var chunks = bscript.decompile(script)
9354
9355 return chunks.length === 2 &&
9356 bscript.isCanonicalSignature(chunks[0]) &&
9357 isCompressedCanonicalPubKey(chunks[1])
9358}
9359check.toJSON = function () { return 'witnessPubKeyHash input' }
9360
9361function encodeStack (signature, pubKey) {
9362 typeforce({
9363 signature: bscript.isCanonicalSignature,
9364 pubKey: isCompressedCanonicalPubKey
9365 }, {
9366 signature: signature,
9367 pubKey: pubKey
9368 })
9369
9370 return [signature, pubKey]
9371}
9372
9373function decodeStack (stack) {
9374 typeforce(typeforce.Array, stack)
9375 typeforce(check, stack)
9376
9377 return {
9378 signature: stack[0],
9379 pubKey: stack[1]
9380 }
9381}
9382
9383module.exports = {
9384 check: check,
9385 decodeStack: decodeStack,
9386 encodeStack: encodeStack
9387}
9388
9389},{"../../script":63,"typeforce":49}],83:[function(require,module,exports){
9390// OP_0 {pubKeyHash}
9391
9392var bscript = require('../../script')
9393var types = require('../../types')
9394var typeforce = require('typeforce')
9395var OPS = require('bitcoin-ops')
9396
9397function check (script) {
9398 var buffer = bscript.compile(script)
9399
9400 return buffer.length === 22 &&
9401 buffer[0] === OPS.OP_0 &&
9402 buffer[1] === 0x14
9403}
9404check.toJSON = function () { return 'Witness pubKeyHash output' }
9405
9406function encode (pubKeyHash) {
9407 typeforce(types.Hash160bit, pubKeyHash)
9408
9409 return bscript.compile([OPS.OP_0, pubKeyHash])
9410}
9411
9412function decode (buffer) {
9413 typeforce(check, buffer)
9414
9415 return buffer.slice(2)
9416}
9417
9418module.exports = {
9419 check: check,
9420 decode: decode,
9421 encode: encode
9422}
9423
9424},{"../../script":63,"../../types":89,"bitcoin-ops":8,"typeforce":49}],84:[function(require,module,exports){
9425arguments[4][66][0].apply(exports,arguments)
9426},{"./input":85,"./output":86,"dup":66}],85:[function(require,module,exports){
9427(function (Buffer){
9428// <scriptSig> {serialized scriptPubKey script}
9429
9430var bscript = require('../../script')
9431var types = require('../../types')
9432var typeforce = require('typeforce')
9433
9434var p2ms = require('../multisig/')
9435var p2pk = require('../pubkey/')
9436var p2pkh = require('../pubkeyhash/')
9437
9438function check (chunks, allowIncomplete) {
9439 typeforce(types.Array, chunks)
9440 if (chunks.length < 1) return false
9441
9442 var witnessScript = chunks[chunks.length - 1]
9443 if (!Buffer.isBuffer(witnessScript)) return false
9444
9445 var witnessScriptChunks = bscript.decompile(witnessScript)
9446
9447 // is witnessScript a valid script?
9448 if (witnessScriptChunks.length === 0) return false
9449
9450 var witnessRawScriptSig = bscript.compile(chunks.slice(0, -1))
9451
9452 // match types
9453 if (p2pkh.input.check(witnessRawScriptSig) &&
9454 p2pkh.output.check(witnessScriptChunks)) return true
9455
9456 if (p2ms.input.check(witnessRawScriptSig, allowIncomplete) &&
9457 p2ms.output.check(witnessScriptChunks)) return true
9458
9459 if (p2pk.input.check(witnessRawScriptSig) &&
9460 p2pk.output.check(witnessScriptChunks)) return true
9461
9462 return false
9463}
9464check.toJSON = function () { return 'witnessScriptHash input' }
9465
9466function encodeStack (witnessData, witnessScript) {
9467 typeforce({
9468 witnessData: [types.Buffer],
9469 witnessScript: types.Buffer
9470 }, {
9471 witnessData: witnessData,
9472 witnessScript: witnessScript
9473 })
9474
9475 return [].concat(witnessData, witnessScript)
9476}
9477
9478function decodeStack (stack) {
9479 typeforce(typeforce.Array, stack)
9480 typeforce(check, stack)
9481 return {
9482 witnessData: stack.slice(0, -1),
9483 witnessScript: stack[stack.length - 1]
9484 }
9485}
9486
9487module.exports = {
9488 check: check,
9489 decodeStack: decodeStack,
9490 encodeStack: encodeStack
9491}
9492
9493}).call(this,{"isBuffer":require("../../../../../../../usr/local/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
9494},{"../../../../../../../usr/local/lib/node_modules/browserify/node_modules/is-buffer/index.js":101,"../../script":63,"../../types":89,"../multisig/":66,"../pubkey/":70,"../pubkeyhash/":73,"typeforce":49}],86:[function(require,module,exports){
9495// OP_0 {scriptHash}
9496
9497var bscript = require('../../script')
9498var types = require('../../types')
9499var typeforce = require('typeforce')
9500var OPS = require('bitcoin-ops')
9501
9502function check (script) {
9503 var buffer = bscript.compile(script)
9504
9505 return buffer.length === 34 &&
9506 buffer[0] === OPS.OP_0 &&
9507 buffer[1] === 0x20
9508}
9509check.toJSON = function () { return 'Witness scriptHash output' }
9510
9511function encode (scriptHash) {
9512 typeforce(types.Hash256bit, scriptHash)
9513
9514 return bscript.compile([OPS.OP_0, scriptHash])
9515}
9516
9517function decode (buffer) {
9518 typeforce(check, buffer)
9519
9520 return buffer.slice(2)
9521}
9522
9523module.exports = {
9524 check: check,
9525 decode: decode,
9526 encode: encode
9527}
9528
9529},{"../../script":63,"../../types":89,"bitcoin-ops":8,"typeforce":49}],87:[function(require,module,exports){
9530var Buffer = require('safe-buffer').Buffer
9531var bcrypto = require('./crypto')
9532var bscript = require('./script')
9533var bufferutils = require('./bufferutils')
9534var opcodes = require('bitcoin-ops')
9535var typeforce = require('typeforce')
9536var types = require('./types')
9537var varuint = require('varuint-bitcoin')
9538
9539function varSliceSize (someScript) {
9540 var length = someScript.length
9541
9542 return varuint.encodingLength(length) + length
9543}
9544
9545function vectorSize (someVector) {
9546 var length = someVector.length
9547
9548 return varuint.encodingLength(length) + someVector.reduce(function (sum, witness) {
9549 return sum + varSliceSize(witness)
9550 }, 0)
9551}
9552
9553function Transaction () {
9554 this.version = 1
9555 this.locktime = 0
9556 this.ins = []
9557 this.outs = []
9558}
9559
9560Transaction.DEFAULT_SEQUENCE = 0xffffffff
9561Transaction.SIGHASH_ALL = 0x01
9562Transaction.SIGHASH_NONE = 0x02
9563Transaction.SIGHASH_SINGLE = 0x03
9564Transaction.SIGHASH_ANYONECANPAY = 0x80
9565Transaction.ADVANCED_TRANSACTION_MARKER = 0x00
9566Transaction.ADVANCED_TRANSACTION_FLAG = 0x01
9567
9568var EMPTY_SCRIPT = Buffer.allocUnsafe(0)
9569var EMPTY_WITNESS = []
9570var ZERO = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
9571var ONE = Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')
9572var VALUE_UINT64_MAX = Buffer.from('ffffffffffffffff', 'hex')
9573var BLANK_OUTPUT = {
9574 script: EMPTY_SCRIPT,
9575 valueBuffer: VALUE_UINT64_MAX
9576}
9577
9578Transaction.fromBuffer = function (buffer, __noStrict) {
9579 var offset = 0
9580 function readSlice (n) {
9581 offset += n
9582 return buffer.slice(offset - n, offset)
9583 }
9584
9585 function readUInt32 () {
9586 var i = buffer.readUInt32LE(offset)
9587 offset += 4
9588 return i
9589 }
9590
9591 function readInt32 () {
9592 var i = buffer.readInt32LE(offset)
9593 offset += 4
9594 return i
9595 }
9596
9597 function readUInt64 () {
9598 var i = bufferutils.readUInt64LE(buffer, offset)
9599 offset += 8
9600 return i
9601 }
9602
9603 function readVarInt () {
9604 var vi = varuint.decode(buffer, offset)
9605 offset += varuint.decode.bytes
9606 return vi
9607 }
9608
9609 function readVarSlice () {
9610 return readSlice(readVarInt())
9611 }
9612
9613 function readVector () {
9614 var count = readVarInt()
9615 var vector = []
9616 for (var i = 0; i < count; i++) vector.push(readVarSlice())
9617 return vector
9618 }
9619
9620 var tx = new Transaction()
9621 tx.version = readInt32()
9622
9623 var marker = buffer.readUInt8(offset)
9624 var flag = buffer.readUInt8(offset + 1)
9625
9626 var hasWitnesses = false
9627 if (marker === Transaction.ADVANCED_TRANSACTION_MARKER &&
9628 flag === Transaction.ADVANCED_TRANSACTION_FLAG) {
9629 offset += 2
9630 hasWitnesses = true
9631 }
9632
9633 var vinLen = readVarInt()
9634 for (var i = 0; i < vinLen; ++i) {
9635 tx.ins.push({
9636 hash: readSlice(32),
9637 index: readUInt32(),
9638 script: readVarSlice(),
9639 sequence: readUInt32(),
9640 witness: EMPTY_WITNESS
9641 })
9642 }
9643
9644 var voutLen = readVarInt()
9645 for (i = 0; i < voutLen; ++i) {
9646 tx.outs.push({
9647 value: readUInt64(),
9648 script: readVarSlice()
9649 })
9650 }
9651
9652 if (hasWitnesses) {
9653 for (i = 0; i < vinLen; ++i) {
9654 tx.ins[i].witness = readVector()
9655 }
9656
9657 // was this pointless?
9658 if (!tx.hasWitnesses()) throw new Error('Transaction has superfluous witness data')
9659 }
9660
9661 tx.locktime = readUInt32()
9662
9663 if (__noStrict) return tx
9664 if (offset !== buffer.length) throw new Error('Transaction has unexpected data')
9665
9666 return tx
9667}
9668
9669Transaction.fromHex = function (hex) {
9670 return Transaction.fromBuffer(Buffer.from(hex, 'hex'))
9671}
9672
9673Transaction.isCoinbaseHash = function (buffer) {
9674 typeforce(types.Hash256bit, buffer)
9675 for (var i = 0; i < 32; ++i) {
9676 if (buffer[i] !== 0) return false
9677 }
9678 return true
9679}
9680
9681Transaction.prototype.isCoinbase = function () {
9682 return this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash)
9683}
9684
9685Transaction.prototype.addInput = function (hash, index, sequence, scriptSig) {
9686 typeforce(types.tuple(
9687 types.Hash256bit,
9688 types.UInt32,
9689 types.maybe(types.UInt32),
9690 types.maybe(types.Buffer)
9691 ), arguments)
9692
9693 if (types.Null(sequence)) {
9694 sequence = Transaction.DEFAULT_SEQUENCE
9695 }
9696
9697 // Add the input and return the input's index
9698 return (this.ins.push({
9699 hash: hash,
9700 index: index,
9701 script: scriptSig || EMPTY_SCRIPT,
9702 sequence: sequence,
9703 witness: EMPTY_WITNESS
9704 }) - 1)
9705}
9706
9707Transaction.prototype.addOutput = function (scriptPubKey, value) {
9708 typeforce(types.tuple(types.Buffer, types.Satoshi), arguments)
9709
9710 // Add the output and return the output's index
9711 return (this.outs.push({
9712 script: scriptPubKey,
9713 value: value
9714 }) - 1)
9715}
9716
9717Transaction.prototype.hasWitnesses = function () {
9718 return this.ins.some(function (x) {
9719 return x.witness.length !== 0
9720 })
9721}
9722
9723Transaction.prototype.weight = function () {
9724 var base = this.__byteLength(false)
9725 var total = this.__byteLength(true)
9726 return base * 3 + total
9727}
9728
9729Transaction.prototype.virtualSize = function () {
9730 return Math.ceil(this.weight() / 4)
9731}
9732
9733Transaction.prototype.byteLength = function () {
9734 return this.__byteLength(true)
9735}
9736
9737Transaction.prototype.__byteLength = function (__allowWitness) {
9738 var hasWitnesses = __allowWitness && this.hasWitnesses()
9739
9740 return (
9741 (hasWitnesses ? 10 : 8) +
9742 varuint.encodingLength(this.ins.length) +
9743 varuint.encodingLength(this.outs.length) +
9744 this.ins.reduce(function (sum, input) { return sum + 40 + varSliceSize(input.script) }, 0) +
9745 this.outs.reduce(function (sum, output) { return sum + 8 + varSliceSize(output.script) }, 0) +
9746 (hasWitnesses ? this.ins.reduce(function (sum, input) { return sum + vectorSize(input.witness) }, 0) : 0)
9747 )
9748}
9749
9750Transaction.prototype.clone = function () {
9751 var newTx = new Transaction()
9752 newTx.version = this.version
9753 newTx.locktime = this.locktime
9754
9755 newTx.ins = this.ins.map(function (txIn) {
9756 return {
9757 hash: txIn.hash,
9758 index: txIn.index,
9759 script: txIn.script,
9760 sequence: txIn.sequence,
9761 witness: txIn.witness
9762 }
9763 })
9764
9765 newTx.outs = this.outs.map(function (txOut) {
9766 return {
9767 script: txOut.script,
9768 value: txOut.value
9769 }
9770 })
9771
9772 return newTx
9773}
9774
9775/**
9776 * Hash transaction for signing a specific input.
9777 *
9778 * Bitcoin uses a different hash for each signed transaction input.
9779 * This method copies the transaction, makes the necessary changes based on the
9780 * hashType, and then hashes the result.
9781 * This hash can then be used to sign the provided transaction input.
9782 */
9783Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashType) {
9784 typeforce(types.tuple(types.UInt32, types.Buffer, /* types.UInt8 */ types.Number), arguments)
9785
9786 // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L29
9787 if (inIndex >= this.ins.length) return ONE
9788
9789 // ignore OP_CODESEPARATOR
9790 var ourScript = bscript.compile(bscript.decompile(prevOutScript).filter(function (x) {
9791 return x !== opcodes.OP_CODESEPARATOR
9792 }))
9793
9794 var txTmp = this.clone()
9795
9796 // SIGHASH_NONE: ignore all outputs? (wildcard payee)
9797 if ((hashType & 0x1f) === Transaction.SIGHASH_NONE) {
9798 txTmp.outs = []
9799
9800 // ignore sequence numbers (except at inIndex)
9801 txTmp.ins.forEach(function (input, i) {
9802 if (i === inIndex) return
9803
9804 input.sequence = 0
9805 })
9806
9807 // SIGHASH_SINGLE: ignore all outputs, except at the same index?
9808 } else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE) {
9809 // https://github.com/bitcoin/bitcoin/blob/master/src/test/sighash_tests.cpp#L60
9810 if (inIndex >= this.outs.length) return ONE
9811
9812 // truncate outputs after
9813 txTmp.outs.length = inIndex + 1
9814
9815 // "blank" outputs before
9816 for (var i = 0; i < inIndex; i++) {
9817 txTmp.outs[i] = BLANK_OUTPUT
9818 }
9819
9820 // ignore sequence numbers (except at inIndex)
9821 txTmp.ins.forEach(function (input, y) {
9822 if (y === inIndex) return
9823
9824 input.sequence = 0
9825 })
9826 }
9827
9828 // SIGHASH_ANYONECANPAY: ignore inputs entirely?
9829 if (hashType & Transaction.SIGHASH_ANYONECANPAY) {
9830 txTmp.ins = [txTmp.ins[inIndex]]
9831 txTmp.ins[0].script = ourScript
9832
9833 // SIGHASH_ALL: only ignore input scripts
9834 } else {
9835 // "blank" others input scripts
9836 txTmp.ins.forEach(function (input) { input.script = EMPTY_SCRIPT })
9837 txTmp.ins[inIndex].script = ourScript
9838 }
9839
9840 // serialize and hash
9841 var buffer = Buffer.allocUnsafe(txTmp.__byteLength(false) + 4)
9842 buffer.writeInt32LE(hashType, buffer.length - 4)
9843 txTmp.__toBuffer(buffer, 0, false)
9844
9845 return bcrypto.sha256(buffer)
9846}
9847
9848Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, value, hashType) {
9849 typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), arguments)
9850
9851 var tbuffer, toffset
9852 function writeSlice (slice) { toffset += slice.copy(tbuffer, toffset) }
9853 function writeUInt32 (i) { toffset = tbuffer.writeUInt32LE(i, toffset) }
9854 function writeUInt64 (i) { toffset = bufferutils.writeUInt64LE(tbuffer, i, toffset) }
9855 function writeVarInt (i) {
9856 varuint.encode(i, tbuffer, toffset)
9857 toffset += varuint.encode.bytes
9858 }
9859 function writeVarSlice (slice) { writeVarInt(slice.length); writeSlice(slice) }
9860
9861 var hashOutputs = ZERO
9862 var hashPrevouts = ZERO
9863 var hashSequence = ZERO
9864
9865 if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) {
9866 tbuffer = Buffer.allocUnsafe(36 * this.ins.length)
9867 toffset = 0
9868
9869 this.ins.forEach(function (txIn) {
9870 writeSlice(txIn.hash)
9871 writeUInt32(txIn.index)
9872 })
9873
9874 hashPrevouts = bcrypto.sha256(tbuffer)
9875 }
9876
9877 if (!(hashType & Transaction.SIGHASH_ANYONECANPAY) &&
9878 (hashType & 0x1f) !== Transaction.SIGHASH_SINGLE &&
9879 (hashType & 0x1f) !== Transaction.SIGHASH_NONE) {
9880 tbuffer = Buffer.allocUnsafe(4 * this.ins.length)
9881 toffset = 0
9882
9883 this.ins.forEach(function (txIn) {
9884 writeUInt32(txIn.sequence)
9885 })
9886
9887 hashSequence = bcrypto.sha256(tbuffer)
9888 }
9889
9890 if ((hashType & 0x1f) !== Transaction.SIGHASH_SINGLE &&
9891 (hashType & 0x1f) !== Transaction.SIGHASH_NONE) {
9892 var txOutsSize = this.outs.reduce(function (sum, output) {
9893 return sum + 8 + varSliceSize(output.script)
9894 }, 0)
9895
9896 tbuffer = Buffer.allocUnsafe(txOutsSize)
9897 toffset = 0
9898
9899 this.outs.forEach(function (out) {
9900 writeUInt64(out.value)
9901 writeVarSlice(out.script)
9902 })
9903
9904 hashOutputs = bcrypto.sha256(tbuffer)
9905 } else if ((hashType & 0x1f) === Transaction.SIGHASH_SINGLE && inIndex < this.outs.length) {
9906 var output = this.outs[inIndex]
9907
9908 tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script))
9909 toffset = 0
9910 writeUInt64(output.value)
9911 writeVarSlice(output.script)
9912
9913 hashOutputs = bcrypto.sha256(tbuffer)
9914 }
9915
9916 tbuffer = Buffer.allocUnsafe(156 + varSliceSize(prevOutScript))
9917 toffset = 0
9918
9919 var input = this.ins[inIndex]
9920 writeUInt32(this.version)
9921 writeSlice(hashPrevouts)
9922 writeSlice(hashSequence)
9923 writeSlice(input.hash)
9924 writeUInt32(input.index)
9925 writeVarSlice(prevOutScript)
9926 writeUInt64(value)
9927 writeUInt32(input.sequence)
9928 writeSlice(hashOutputs)
9929 writeUInt32(this.locktime)
9930 writeUInt32(hashType)
9931 return bcrypto.sha256(tbuffer)
9932}
9933
9934Transaction.prototype.getHash = function () {
9935 return bcrypto.sha256(this.__toBuffer(undefined, undefined, false))
9936}
9937
9938Transaction.prototype.getId = function () {
9939 // transaction hash's are displayed in reverse order
9940 return this.getHash().reverse().toString('hex')
9941}
9942
9943Transaction.prototype.toBuffer = function (buffer, initialOffset) {
9944 return this.__toBuffer(buffer, initialOffset, true)
9945}
9946
9947Transaction.prototype.__toBuffer = function (buffer, initialOffset, __allowWitness) {
9948 if (!buffer) buffer = Buffer.allocUnsafe(this.__byteLength(__allowWitness))
9949
9950 var offset = initialOffset || 0
9951 function writeSlice (slice) { offset += slice.copy(buffer, offset) }
9952 function writeUInt8 (i) { offset = buffer.writeUInt8(i, offset) }
9953 function writeUInt32 (i) { offset = buffer.writeUInt32LE(i, offset) }
9954 function writeInt32 (i) { offset = buffer.writeInt32LE(i, offset) }
9955 function writeUInt64 (i) { offset = bufferutils.writeUInt64LE(buffer, i, offset) }
9956 function writeVarInt (i) {
9957 varuint.encode(i, buffer, offset)
9958 offset += varuint.encode.bytes
9959 }
9960 function writeVarSlice (slice) { writeVarInt(slice.length); writeSlice(slice) }
9961 function writeVector (vector) { writeVarInt(vector.length); vector.forEach(writeVarSlice) }
9962
9963 writeInt32(this.version)
9964
9965 var hasWitnesses = __allowWitness && this.hasWitnesses()
9966
9967 if (hasWitnesses) {
9968 writeUInt8(Transaction.ADVANCED_TRANSACTION_MARKER)
9969 writeUInt8(Transaction.ADVANCED_TRANSACTION_FLAG)
9970 }
9971
9972 writeVarInt(this.ins.length)
9973
9974 this.ins.forEach(function (txIn) {
9975 writeSlice(txIn.hash)
9976 writeUInt32(txIn.index)
9977 writeVarSlice(txIn.script)
9978 writeUInt32(txIn.sequence)
9979 })
9980
9981 writeVarInt(this.outs.length)
9982 this.outs.forEach(function (txOut) {
9983 if (!txOut.valueBuffer) {
9984 writeUInt64(txOut.value)
9985 } else {
9986 writeSlice(txOut.valueBuffer)
9987 }
9988
9989 writeVarSlice(txOut.script)
9990 })
9991
9992 if (hasWitnesses) {
9993 this.ins.forEach(function (input) {
9994 writeVector(input.witness)
9995 })
9996 }
9997
9998 writeUInt32(this.locktime)
9999
10000 // avoid slicing unless necessary
10001 if (initialOffset !== undefined) return buffer.slice(initialOffset, offset)
10002 return buffer
10003}
10004
10005Transaction.prototype.toHex = function () {
10006 return this.toBuffer().toString('hex')
10007}
10008
10009Transaction.prototype.setInputScript = function (index, scriptSig) {
10010 typeforce(types.tuple(types.Number, types.Buffer), arguments)
10011
10012 this.ins[index].script = scriptSig
10013}
10014
10015Transaction.prototype.setWitness = function (index, witness) {
10016 typeforce(types.tuple(types.Number, [types.Buffer]), arguments)
10017
10018 this.ins[index].witness = witness
10019}
10020
10021module.exports = Transaction
10022
10023},{"./bufferutils":55,"./crypto":56,"./script":63,"./types":89,"bitcoin-ops":8,"safe-buffer":38,"typeforce":49,"varuint-bitcoin":51}],88:[function(require,module,exports){
10024var Buffer = require('safe-buffer').Buffer
10025var baddress = require('./address')
10026var bcrypto = require('./crypto')
10027var bscript = require('./script')
10028var btemplates = require('./templates')
10029var networks = require('./networks')
10030var ops = require('bitcoin-ops')
10031var typeforce = require('typeforce')
10032var types = require('./types')
10033var scriptTypes = btemplates.types
10034var SIGNABLE = [btemplates.types.P2PKH, btemplates.types.P2PK, btemplates.types.MULTISIG]
10035var P2SH = SIGNABLE.concat([btemplates.types.P2WPKH, btemplates.types.P2WSH])
10036
10037var ECPair = require('./ecpair')
10038var ECSignature = require('./ecsignature')
10039var Transaction = require('./transaction')
10040
10041function supportedType (type) {
10042 return SIGNABLE.indexOf(type) !== -1
10043}
10044
10045function supportedP2SHType (type) {
10046 return P2SH.indexOf(type) !== -1
10047}
10048
10049function extractChunks (type, chunks, script) {
10050 var pubKeys = []
10051 var signatures = []
10052 switch (type) {
10053 case scriptTypes.P2PKH:
10054 // if (redeemScript) throw new Error('Nonstandard... P2SH(P2PKH)')
10055 pubKeys = chunks.slice(1)
10056 signatures = chunks.slice(0, 1)
10057 break
10058
10059 case scriptTypes.P2PK:
10060 pubKeys[0] = script ? btemplates.pubKey.output.decode(script) : undefined
10061 signatures = chunks.slice(0, 1)
10062 break
10063
10064 case scriptTypes.MULTISIG:
10065 if (script) {
10066 var multisig = btemplates.multisig.output.decode(script)
10067 pubKeys = multisig.pubKeys
10068 }
10069
10070 signatures = chunks.slice(1).map(function (chunk) {
10071 return chunk.length === 0 ? undefined : chunk
10072 })
10073 break
10074 }
10075
10076 return {
10077 pubKeys: pubKeys,
10078 signatures: signatures
10079 }
10080}
10081function expandInput (scriptSig, witnessStack) {
10082 if (scriptSig.length === 0 && witnessStack.length === 0) return {}
10083
10084 var prevOutScript
10085 var prevOutType
10086 var scriptType
10087 var script
10088 var redeemScript
10089 var witnessScript
10090 var witnessScriptType
10091 var redeemScriptType
10092 var witness = false
10093 var p2wsh = false
10094 var p2sh = false
10095 var witnessProgram
10096 var chunks
10097
10098 var scriptSigChunks = bscript.decompile(scriptSig)
10099 var sigType = btemplates.classifyInput(scriptSigChunks, true)
10100 if (sigType === scriptTypes.P2SH) {
10101 p2sh = true
10102 redeemScript = scriptSigChunks[scriptSigChunks.length - 1]
10103 redeemScriptType = btemplates.classifyOutput(redeemScript)
10104 prevOutScript = btemplates.scriptHash.output.encode(bcrypto.hash160(redeemScript))
10105 prevOutType = scriptTypes.P2SH
10106 script = redeemScript
10107 }
10108
10109 var classifyWitness = btemplates.classifyWitness(witnessStack, true)
10110 if (classifyWitness === scriptTypes.P2WSH) {
10111 witnessScript = witnessStack[witnessStack.length - 1]
10112 witnessScriptType = btemplates.classifyOutput(witnessScript)
10113 p2wsh = true
10114 witness = true
10115 if (scriptSig.length === 0) {
10116 prevOutScript = btemplates.witnessScriptHash.output.encode(bcrypto.sha256(witnessScript))
10117 prevOutType = scriptTypes.P2WSH
10118 if (redeemScript !== undefined) {
10119 throw new Error('Redeem script given when unnecessary')
10120 }
10121 // bare witness
10122 } else {
10123 if (!redeemScript) {
10124 throw new Error('No redeemScript provided for P2WSH, but scriptSig non-empty')
10125 }
10126 witnessProgram = btemplates.witnessScriptHash.output.encode(bcrypto.sha256(witnessScript))
10127 if (!redeemScript.equals(witnessProgram)) {
10128 throw new Error('Redeem script didn\'t match witnessScript')
10129 }
10130 }
10131
10132 if (!supportedType(btemplates.classifyOutput(witnessScript))) {
10133 throw new Error('unsupported witness script')
10134 }
10135
10136 script = witnessScript
10137 scriptType = witnessScriptType
10138 chunks = witnessStack.slice(0, -1)
10139 } else if (classifyWitness === scriptTypes.P2WPKH) {
10140 witness = true
10141 var key = witnessStack[witnessStack.length - 1]
10142 var keyHash = bcrypto.hash160(key)
10143 if (scriptSig.length === 0) {
10144 prevOutScript = btemplates.witnessPubKeyHash.output.encode(keyHash)
10145 prevOutType = scriptTypes.P2WPKH
10146 if (typeof redeemScript !== 'undefined') {
10147 throw new Error('Redeem script given when unnecessary')
10148 }
10149 } else {
10150 if (!redeemScript) {
10151 throw new Error('No redeemScript provided for P2WPKH, but scriptSig wasn\'t empty')
10152 }
10153 witnessProgram = btemplates.witnessPubKeyHash.output.encode(keyHash)
10154 if (!redeemScript.equals(witnessProgram)) {
10155 throw new Error('Redeem script did not have the right witness program')
10156 }
10157 }
10158
10159 scriptType = scriptTypes.P2PKH
10160 chunks = witnessStack
10161 } else if (redeemScript) {
10162 if (!supportedP2SHType(redeemScriptType)) {
10163 throw new Error('Bad redeemscript!')
10164 }
10165
10166 script = redeemScript
10167 scriptType = redeemScriptType
10168 chunks = scriptSigChunks.slice(0, -1)
10169 } else {
10170 prevOutType = scriptType = btemplates.classifyInput(scriptSig)
10171 chunks = scriptSigChunks
10172 }
10173
10174 var expanded = extractChunks(scriptType, chunks, script)
10175
10176 var result = {
10177 pubKeys: expanded.pubKeys,
10178 signatures: expanded.signatures,
10179 prevOutScript: prevOutScript,
10180 prevOutType: prevOutType,
10181 signType: scriptType,
10182 signScript: script,
10183 witness: Boolean(witness)
10184 }
10185
10186 if (p2sh) {
10187 result.redeemScript = redeemScript
10188 result.redeemScriptType = redeemScriptType
10189 }
10190
10191 if (p2wsh) {
10192 result.witnessScript = witnessScript
10193 result.witnessScriptType = witnessScriptType
10194 }
10195
10196 return result
10197}
10198
10199// could be done in expandInput, but requires the original Transaction for hashForSignature
10200function fixMultisigOrder (input, transaction, vin) {
10201 if (input.redeemScriptType !== scriptTypes.MULTISIG || !input.redeemScript) return
10202 if (input.pubKeys.length === input.signatures.length) return
10203
10204 var unmatched = input.signatures.concat()
10205
10206 input.signatures = input.pubKeys.map(function (pubKey) {
10207 var keyPair = ECPair.fromPublicKeyBuffer(pubKey)
10208 var match
10209
10210 // check for a signature
10211 unmatched.some(function (signature, i) {
10212 // skip if undefined || OP_0
10213 if (!signature) return false
10214
10215 // TODO: avoid O(n) hashForSignature
10216 var parsed = ECSignature.parseScriptSignature(signature)
10217 var hash = transaction.hashForSignature(vin, input.redeemScript, parsed.hashType)
10218
10219 // skip if signature does not match pubKey
10220 if (!keyPair.verify(hash, parsed.signature)) return false
10221
10222 // remove matched signature from unmatched
10223 unmatched[i] = undefined
10224 match = signature
10225
10226 return true
10227 })
10228
10229 return match
10230 })
10231}
10232
10233function expandOutput (script, scriptType, ourPubKey) {
10234 typeforce(types.Buffer, script)
10235
10236 var scriptChunks = bscript.decompile(script)
10237 if (!scriptType) {
10238 scriptType = btemplates.classifyOutput(script)
10239 }
10240
10241 var pubKeys = []
10242
10243 switch (scriptType) {
10244 // does our hash160(pubKey) match the output scripts?
10245 case scriptTypes.P2PKH:
10246 if (!ourPubKey) break
10247
10248 var pkh1 = scriptChunks[2]
10249 var pkh2 = bcrypto.hash160(ourPubKey)
10250 if (pkh1.equals(pkh2)) pubKeys = [ourPubKey]
10251 break
10252
10253 // does our hash160(pubKey) match the output scripts?
10254 case scriptTypes.P2WPKH:
10255 if (!ourPubKey) break
10256
10257 var wpkh1 = scriptChunks[1]
10258 var wpkh2 = bcrypto.hash160(ourPubKey)
10259 if (wpkh1.equals(wpkh2)) pubKeys = [ourPubKey]
10260 break
10261
10262 case scriptTypes.P2PK:
10263 pubKeys = scriptChunks.slice(0, 1)
10264 break
10265
10266 case scriptTypes.MULTISIG:
10267 pubKeys = scriptChunks.slice(1, -2)
10268 break
10269
10270 default: return { scriptType: scriptType }
10271 }
10272
10273 return {
10274 pubKeys: pubKeys,
10275 scriptType: scriptType,
10276 signatures: pubKeys.map(function () { return undefined })
10277 }
10278}
10279
10280function checkP2SHInput (input, redeemScriptHash) {
10281 if (input.prevOutType) {
10282 if (input.prevOutType !== scriptTypes.P2SH) throw new Error('PrevOutScript must be P2SH')
10283
10284 var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1]
10285 if (!prevOutScriptScriptHash.equals(redeemScriptHash)) throw new Error('Inconsistent hash160(RedeemScript)')
10286 }
10287}
10288
10289function checkP2WSHInput (input, witnessScriptHash) {
10290 if (input.prevOutType) {
10291 if (input.prevOutType !== scriptTypes.P2WSH) throw new Error('PrevOutScript must be P2WSH')
10292
10293 var scriptHash = bscript.decompile(input.prevOutScript)[1]
10294 if (!scriptHash.equals(witnessScriptHash)) throw new Error('Inconsistent sha25(WitnessScript)')
10295 }
10296}
10297
10298function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScript) {
10299 var expanded
10300 var prevOutType
10301 var prevOutScript
10302
10303 var p2sh = false
10304 var p2shType
10305 var redeemScriptHash
10306
10307 var witness = false
10308 var p2wsh = false
10309 var witnessType
10310 var witnessScriptHash
10311
10312 var signType
10313 var signScript
10314
10315 if (redeemScript && witnessScript) {
10316 redeemScriptHash = bcrypto.hash160(redeemScript)
10317 witnessScriptHash = bcrypto.sha256(witnessScript)
10318 checkP2SHInput(input, redeemScriptHash)
10319
10320 if (!redeemScript.equals(btemplates.witnessScriptHash.output.encode(witnessScriptHash))) throw new Error('Witness script inconsistent with redeem script')
10321
10322 expanded = expandOutput(witnessScript, undefined, kpPubKey)
10323 if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"')
10324
10325 prevOutType = btemplates.types.P2SH
10326 prevOutScript = btemplates.scriptHash.output.encode(redeemScriptHash)
10327 p2sh = witness = p2wsh = true
10328 p2shType = btemplates.types.P2WSH
10329 signType = witnessType = expanded.scriptType
10330 signScript = witnessScript
10331 } else if (redeemScript) {
10332 redeemScriptHash = bcrypto.hash160(redeemScript)
10333 checkP2SHInput(input, redeemScriptHash)
10334
10335 expanded = expandOutput(redeemScript, undefined, kpPubKey)
10336 if (!expanded.pubKeys) throw new Error('RedeemScript not supported "' + bscript.toASM(redeemScript) + '"')
10337
10338 prevOutType = btemplates.types.P2SH
10339 prevOutScript = btemplates.scriptHash.output.encode(redeemScriptHash)
10340 p2sh = true
10341 signType = p2shType = expanded.scriptType
10342 signScript = redeemScript
10343 witness = signType === btemplates.types.P2WPKH
10344 } else if (witnessScript) {
10345 witnessScriptHash = bcrypto.sha256(witnessScript)
10346 checkP2WSHInput(input, witnessScriptHash)
10347
10348 expanded = expandOutput(witnessScript, undefined, kpPubKey)
10349 if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"')
10350
10351 prevOutType = btemplates.types.P2WSH
10352 prevOutScript = btemplates.witnessScriptHash.output.encode(witnessScriptHash)
10353 witness = p2wsh = true
10354 signType = witnessType = expanded.scriptType
10355 signScript = witnessScript
10356 } else if (input.prevOutType) {
10357 // embedded scripts are not possible without a redeemScript
10358 if (input.prevOutType === scriptTypes.P2SH ||
10359 input.prevOutType === scriptTypes.P2WSH) {
10360 throw new Error('PrevOutScript is ' + input.prevOutType + ', requires redeemScript')
10361 }
10362
10363 prevOutType = input.prevOutType
10364 prevOutScript = input.prevOutScript
10365 expanded = expandOutput(input.prevOutScript, input.prevOutType, kpPubKey)
10366 if (!expanded.pubKeys) return
10367
10368 witness = (input.prevOutType === scriptTypes.P2WPKH)
10369 signType = prevOutType
10370 signScript = prevOutScript
10371 } else {
10372 prevOutScript = btemplates.pubKeyHash.output.encode(bcrypto.hash160(kpPubKey))
10373 expanded = expandOutput(prevOutScript, scriptTypes.P2PKH, kpPubKey)
10374
10375 prevOutType = scriptTypes.P2PKH
10376 witness = false
10377 signType = prevOutType
10378 signScript = prevOutScript
10379 }
10380
10381 if (signType === scriptTypes.P2WPKH) {
10382 signScript = btemplates.pubKeyHash.output.encode(btemplates.witnessPubKeyHash.output.decode(signScript))
10383 }
10384
10385 if (p2sh) {
10386 input.redeemScript = redeemScript
10387 input.redeemScriptType = p2shType
10388 }
10389
10390 if (p2wsh) {
10391 input.witnessScript = witnessScript
10392 input.witnessScriptType = witnessType
10393 }
10394
10395 input.pubKeys = expanded.pubKeys
10396 input.signatures = expanded.signatures
10397 input.signScript = signScript
10398 input.signType = signType
10399 input.prevOutScript = prevOutScript
10400 input.prevOutType = prevOutType
10401 input.witness = witness
10402}
10403
10404function buildStack (type, signatures, pubKeys, allowIncomplete) {
10405 if (type === scriptTypes.P2PKH) {
10406 if (signatures.length === 1 && Buffer.isBuffer(signatures[0]) && pubKeys.length === 1) return btemplates.pubKeyHash.input.encodeStack(signatures[0], pubKeys[0])
10407 } else if (type === scriptTypes.P2PK) {
10408 if (signatures.length === 1 && Buffer.isBuffer(signatures[0])) return btemplates.pubKey.input.encodeStack(signatures[0])
10409 } else if (type === scriptTypes.MULTISIG) {
10410 if (signatures.length > 0) {
10411 signatures = signatures.map(function (signature) {
10412 return signature || ops.OP_0
10413 })
10414 if (!allowIncomplete) {
10415 // remove blank signatures
10416 signatures = signatures.filter(function (x) { return x !== ops.OP_0 })
10417 }
10418
10419 return btemplates.multisig.input.encodeStack(signatures)
10420 }
10421 } else {
10422 throw new Error('Not yet supported')
10423 }
10424
10425 if (!allowIncomplete) throw new Error('Not enough signatures provided')
10426 return []
10427}
10428
10429function buildInput (input, allowIncomplete) {
10430 var scriptType = input.prevOutType
10431 var sig = []
10432 var witness = []
10433
10434 if (supportedType(scriptType)) {
10435 sig = buildStack(scriptType, input.signatures, input.pubKeys, allowIncomplete)
10436 }
10437
10438 var p2sh = false
10439 if (scriptType === btemplates.types.P2SH) {
10440 // We can remove this error later when we have a guarantee prepareInput
10441 // rejects unsignable scripts - it MUST be signable at this point.
10442 if (!allowIncomplete && !supportedP2SHType(input.redeemScriptType)) {
10443 throw new Error('Impossible to sign this type')
10444 }
10445
10446 if (supportedType(input.redeemScriptType)) {
10447 sig = buildStack(input.redeemScriptType, input.signatures, input.pubKeys, allowIncomplete)
10448 }
10449
10450 // If it wasn't SIGNABLE, it's witness, defer to that
10451 if (input.redeemScriptType) {
10452 p2sh = true
10453 scriptType = input.redeemScriptType
10454 }
10455 }
10456
10457 switch (scriptType) {
10458 // P2WPKH is a special case of P2PKH
10459 case btemplates.types.P2WPKH:
10460 witness = buildStack(btemplates.types.P2PKH, input.signatures, input.pubKeys, allowIncomplete)
10461 break
10462
10463 case btemplates.types.P2WSH:
10464 // We can remove this check later
10465 if (!allowIncomplete && !supportedType(input.witnessScriptType)) {
10466 throw new Error('Impossible to sign this type')
10467 }
10468
10469 if (supportedType(input.witnessScriptType)) {
10470 witness = buildStack(input.witnessScriptType, input.signatures, input.pubKeys, allowIncomplete)
10471 witness.push(input.witnessScript)
10472 scriptType = input.witnessScriptType
10473 }
10474
10475 break
10476 }
10477
10478 // append redeemScript if necessary
10479 if (p2sh) {
10480 sig.push(input.redeemScript)
10481 }
10482
10483 return {
10484 type: scriptType,
10485 script: bscript.compile(sig),
10486 witness: witness
10487 }
10488}
10489
10490function TransactionBuilder (network, maximumFeeRate) {
10491 this.prevTxMap = {}
10492 this.network = network || networks.bitcoin
10493
10494 // WARNING: This is __NOT__ to be relied on, its just another potential safety mechanism (safety in-depth)
10495 this.maximumFeeRate = maximumFeeRate || 2500
10496
10497 this.inputs = []
10498 this.tx = new Transaction()
10499}
10500
10501TransactionBuilder.prototype.setLockTime = function (locktime) {
10502 typeforce(types.UInt32, locktime)
10503
10504 // if any signatures exist, throw
10505 if (this.inputs.some(function (input) {
10506 if (!input.signatures) return false
10507
10508 return input.signatures.some(function (s) { return s })
10509 })) {
10510 throw new Error('No, this would invalidate signatures')
10511 }
10512
10513 this.tx.locktime = locktime
10514}
10515
10516TransactionBuilder.prototype.setVersion = function (version) {
10517 typeforce(types.UInt32, version)
10518
10519 // XXX: this might eventually become more complex depending on what the versions represent
10520 this.tx.version = version
10521}
10522
10523TransactionBuilder.fromTransaction = function (transaction, network) {
10524 var txb = new TransactionBuilder(network)
10525
10526 // Copy transaction fields
10527 txb.setVersion(transaction.version)
10528 txb.setLockTime(transaction.locktime)
10529
10530 // Copy outputs (done first to avoid signature invalidation)
10531 transaction.outs.forEach(function (txOut) {
10532 txb.addOutput(txOut.script, txOut.value)
10533 })
10534
10535 // Copy inputs
10536 transaction.ins.forEach(function (txIn) {
10537 txb.__addInputUnsafe(txIn.hash, txIn.index, {
10538 sequence: txIn.sequence,
10539 script: txIn.script,
10540 witness: txIn.witness
10541 })
10542 })
10543
10544 // fix some things not possible through the public API
10545 txb.inputs.forEach(function (input, i) {
10546 fixMultisigOrder(input, transaction, i)
10547 })
10548
10549 return txb
10550}
10551
10552TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOutScript) {
10553 if (!this.__canModifyInputs()) {
10554 throw new Error('No, this would invalidate signatures')
10555 }
10556
10557 var value
10558
10559 // is it a hex string?
10560 if (typeof txHash === 'string') {
10561 // transaction hashs's are displayed in reverse order, un-reverse it
10562 txHash = Buffer.from(txHash, 'hex').reverse()
10563
10564 // is it a Transaction object?
10565 } else if (txHash instanceof Transaction) {
10566 var txOut = txHash.outs[vout]
10567 prevOutScript = txOut.script
10568 value = txOut.value
10569
10570 txHash = txHash.getHash()
10571 }
10572
10573 return this.__addInputUnsafe(txHash, vout, {
10574 sequence: sequence,
10575 prevOutScript: prevOutScript,
10576 value: value
10577 })
10578}
10579
10580TransactionBuilder.prototype.__addInputUnsafe = function (txHash, vout, options) {
10581 if (Transaction.isCoinbaseHash(txHash)) {
10582 throw new Error('coinbase inputs not supported')
10583 }
10584
10585 var prevTxOut = txHash.toString('hex') + ':' + vout
10586 if (this.prevTxMap[prevTxOut] !== undefined) throw new Error('Duplicate TxOut: ' + prevTxOut)
10587
10588 var input = {}
10589
10590 // derive what we can from the scriptSig
10591 if (options.script !== undefined) {
10592 input = expandInput(options.script, options.witness || [])
10593 }
10594
10595 // if an input value was given, retain it
10596 if (options.value !== undefined) {
10597 input.value = options.value
10598 }
10599
10600 // derive what we can from the previous transactions output script
10601 if (!input.prevOutScript && options.prevOutScript) {
10602 var prevOutType
10603
10604 if (!input.pubKeys && !input.signatures) {
10605 var expanded = expandOutput(options.prevOutScript)
10606
10607 if (expanded.pubKeys) {
10608 input.pubKeys = expanded.pubKeys
10609 input.signatures = expanded.signatures
10610 }
10611
10612 prevOutType = expanded.scriptType
10613 }
10614
10615 input.prevOutScript = options.prevOutScript
10616 input.prevOutType = prevOutType || btemplates.classifyOutput(options.prevOutScript)
10617 }
10618
10619 var vin = this.tx.addInput(txHash, vout, options.sequence, options.scriptSig)
10620 this.inputs[vin] = input
10621 this.prevTxMap[prevTxOut] = vin
10622 return vin
10623}
10624
10625TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) {
10626 if (!this.__canModifyOutputs()) {
10627 throw new Error('No, this would invalidate signatures')
10628 }
10629
10630 // Attempt to get a script if it's a base58 address string
10631 if (typeof scriptPubKey === 'string') {
10632 scriptPubKey = baddress.toOutputScript(scriptPubKey, this.network)
10633 }
10634
10635 return this.tx.addOutput(scriptPubKey, value)
10636}
10637
10638TransactionBuilder.prototype.build = function () {
10639 return this.__build(false)
10640}
10641TransactionBuilder.prototype.buildIncomplete = function () {
10642 return this.__build(true)
10643}
10644
10645TransactionBuilder.prototype.__build = function (allowIncomplete) {
10646 if (!allowIncomplete) {
10647 if (!this.tx.ins.length) throw new Error('Transaction has no inputs')
10648 if (!this.tx.outs.length) throw new Error('Transaction has no outputs')
10649 }
10650
10651 var tx = this.tx.clone()
10652 // Create script signatures from inputs
10653 this.inputs.forEach(function (input, i) {
10654 var scriptType = input.witnessScriptType || input.redeemScriptType || input.prevOutType
10655 if (!scriptType && !allowIncomplete) throw new Error('Transaction is not complete')
10656 var result = buildInput(input, allowIncomplete)
10657
10658 // skip if no result
10659 if (!allowIncomplete) {
10660 if (!supportedType(result.type) && result.type !== btemplates.types.P2WPKH) {
10661 throw new Error(result.type + ' not supported')
10662 }
10663 }
10664
10665 tx.setInputScript(i, result.script)
10666 tx.setWitness(i, result.witness)
10667 })
10668
10669 if (!allowIncomplete) {
10670 // do not rely on this, its merely a last resort
10671 if (this.__overMaximumFees(tx.virtualSize())) {
10672 throw new Error('Transaction has absurd fees')
10673 }
10674 }
10675
10676 return tx
10677}
10678
10679function canSign (input) {
10680 return input.prevOutScript !== undefined &&
10681 input.signScript !== undefined &&
10682 input.pubKeys !== undefined &&
10683 input.signatures !== undefined &&
10684 input.signatures.length === input.pubKeys.length &&
10685 input.pubKeys.length > 0 &&
10686 (
10687 input.witness === false ||
10688 (input.witness === true && input.value !== undefined)
10689 )
10690}
10691
10692TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType, witnessValue, witnessScript) {
10693 // TODO: remove keyPair.network matching in 4.0.0
10694 if (keyPair.network && keyPair.network !== this.network) throw new TypeError('Inconsistent network')
10695 if (!this.inputs[vin]) throw new Error('No input at index: ' + vin)
10696 hashType = hashType || Transaction.SIGHASH_ALL
10697
10698 var input = this.inputs[vin]
10699
10700 // if redeemScript was previously provided, enforce consistency
10701 if (input.redeemScript !== undefined &&
10702 redeemScript &&
10703 !input.redeemScript.equals(redeemScript)) {
10704 throw new Error('Inconsistent redeemScript')
10705 }
10706
10707 var kpPubKey = keyPair.publicKey || keyPair.getPublicKeyBuffer()
10708 if (!canSign(input)) {
10709 if (witnessValue !== undefined) {
10710 if (input.value !== undefined && input.value !== witnessValue) throw new Error('Input didn\'t match witnessValue')
10711 typeforce(types.Satoshi, witnessValue)
10712 input.value = witnessValue
10713 }
10714
10715 if (!canSign(input)) prepareInput(input, kpPubKey, redeemScript, witnessValue, witnessScript)
10716 if (!canSign(input)) throw Error(input.prevOutType + ' not supported')
10717 }
10718
10719 // ready to sign
10720 var signatureHash
10721 if (input.witness) {
10722 signatureHash = this.tx.hashForWitnessV0(vin, input.signScript, input.value, hashType)
10723 } else {
10724 signatureHash = this.tx.hashForSignature(vin, input.signScript, hashType)
10725 }
10726
10727 // enforce in order signing of public keys
10728 var signed = input.pubKeys.some(function (pubKey, i) {
10729 if (!kpPubKey.equals(pubKey)) return false
10730 if (input.signatures[i]) throw new Error('Signature already exists')
10731 if (kpPubKey.length !== 33 &&
10732 input.signType === scriptTypes.P2WPKH) throw new Error('BIP143 rejects uncompressed public keys in P2WPKH or P2WSH')
10733
10734 var signature = keyPair.sign(signatureHash)
10735 if (Buffer.isBuffer(signature)) signature = ECSignature.fromRSBuffer(signature)
10736
10737 input.signatures[i] = signature.toScriptSignature(hashType)
10738 return true
10739 })
10740
10741 if (!signed) throw new Error('Key pair cannot sign for this input')
10742}
10743
10744function signatureHashType (buffer) {
10745 return buffer.readUInt8(buffer.length - 1)
10746}
10747
10748TransactionBuilder.prototype.__canModifyInputs = function () {
10749 return this.inputs.every(function (input) {
10750 // any signatures?
10751 if (input.signatures === undefined) return true
10752
10753 return input.signatures.every(function (signature) {
10754 if (!signature) return true
10755 var hashType = signatureHashType(signature)
10756
10757 // if SIGHASH_ANYONECANPAY is set, signatures would not
10758 // be invalidated by more inputs
10759 return hashType & Transaction.SIGHASH_ANYONECANPAY
10760 })
10761 })
10762}
10763
10764TransactionBuilder.prototype.__canModifyOutputs = function () {
10765 var nInputs = this.tx.ins.length
10766 var nOutputs = this.tx.outs.length
10767
10768 return this.inputs.every(function (input) {
10769 if (input.signatures === undefined) return true
10770
10771 return input.signatures.every(function (signature) {
10772 if (!signature) return true
10773 var hashType = signatureHashType(signature)
10774
10775 var hashTypeMod = hashType & 0x1f
10776 if (hashTypeMod === Transaction.SIGHASH_NONE) return true
10777 if (hashTypeMod === Transaction.SIGHASH_SINGLE) {
10778 // if SIGHASH_SINGLE is set, and nInputs > nOutputs
10779 // some signatures would be invalidated by the addition
10780 // of more outputs
10781 return nInputs <= nOutputs
10782 }
10783 })
10784 })
10785}
10786
10787TransactionBuilder.prototype.__overMaximumFees = function (bytes) {
10788 // not all inputs will have .value defined
10789 var incoming = this.inputs.reduce(function (a, x) { return a + (x.value >>> 0) }, 0)
10790
10791 // but all outputs do, and if we have any input value
10792 // we can immediately determine if the outputs are too small
10793 var outgoing = this.tx.outs.reduce(function (a, x) { return a + x.value }, 0)
10794 var fee = incoming - outgoing
10795 var feeRate = fee / bytes
10796
10797 return feeRate > this.maximumFeeRate
10798}
10799
10800module.exports = TransactionBuilder
10801
10802},{"./address":53,"./crypto":56,"./ecpair":58,"./ecsignature":59,"./networks":62,"./script":63,"./templates":65,"./transaction":87,"./types":89,"bitcoin-ops":8,"safe-buffer":38,"typeforce":49}],89:[function(require,module,exports){
10803var typeforce = require('typeforce')
10804
10805var UINT31_MAX = Math.pow(2, 31) - 1
10806function UInt31 (value) {
10807 return typeforce.UInt32(value) && value <= UINT31_MAX
10808}
10809
10810function BIP32Path (value) {
10811 return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
10812}
10813BIP32Path.toJSON = function () { return 'BIP32 derivation path' }
10814
10815var SATOSHI_MAX = 105 * 1e14
10816function Satoshi (value) {
10817 return typeforce.UInt53(value) && value <= SATOSHI_MAX
10818}
10819
10820// external dependent types
10821var BigInt = typeforce.quacksLike('BigInteger')
10822var ECPoint = typeforce.quacksLike('Point')
10823
10824// exposed, external API
10825var ECSignature = typeforce.compile({ r: BigInt, s: BigInt })
10826var Network = typeforce.compile({
10827 messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String),
10828 bip32: {
10829 public: typeforce.UInt32,
10830 private: typeforce.UInt32
10831 },
10832 pubKeyHash: typeforce.UInt8,
10833 scriptHash: typeforce.UInt8,
10834 wif: typeforce.UInt8
10835})
10836
10837// extend typeforce types with ours
10838var types = {
10839 BigInt: BigInt,
10840 BIP32Path: BIP32Path,
10841 Buffer256bit: typeforce.BufferN(32),
10842 ECPoint: ECPoint,
10843 ECSignature: ECSignature,
10844 Hash160bit: typeforce.BufferN(20),
10845 Hash256bit: typeforce.BufferN(32),
10846 Network: Network,
10847 Satoshi: Satoshi,
10848 UInt31: UInt31
10849}
10850
10851for (var typeName in typeforce) {
10852 types[typeName] = typeforce[typeName]
10853}
10854
10855module.exports = types
10856
10857},{"typeforce":49}],90:[function(require,module,exports){
10858(function (global){
10859'use strict';
10860
10861var objectAssign = require('object-assign');
10862
10863// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
10864// original notice:
10865
10866/*!
10867 * The buffer module from node.js, for the browser.
10868 *
10869 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
10870 * @license MIT
10871 */
10872function compare(a, b) {
10873 if (a === b) {
10874 return 0;
10875 }
10876
10877 var x = a.length;
10878 var y = b.length;
10879
10880 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
10881 if (a[i] !== b[i]) {
10882 x = a[i];
10883 y = b[i];
10884 break;
10885 }
10886 }
10887
10888 if (x < y) {
10889 return -1;
10890 }
10891 if (y < x) {
10892 return 1;
10893 }
10894 return 0;
10895}
10896function isBuffer(b) {
10897 if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
10898 return global.Buffer.isBuffer(b);
10899 }
10900 return !!(b != null && b._isBuffer);
10901}
10902
10903// based on node assert, original notice:
10904// NB: The URL to the CommonJS spec is kept just for tradition.
10905// node-assert has evolved a lot since then, both in API and behavior.
10906
10907// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
10908//
10909// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
10910//
10911// Originally from narwhal.js (http://narwhaljs.org)
10912// Copyright (c) 2009 Thomas Robinson <280north.com>
10913//
10914// Permission is hereby granted, free of charge, to any person obtaining a copy
10915// of this software and associated documentation files (the 'Software'), to
10916// deal in the Software without restriction, including without limitation the
10917// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10918// sell copies of the Software, and to permit persons to whom the Software is
10919// furnished to do so, subject to the following conditions:
10920//
10921// The above copyright notice and this permission notice shall be included in
10922// all copies or substantial portions of the Software.
10923//
10924// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10925// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10926// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10927// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
10928// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
10929// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10930
10931var util = require('util/');
10932var hasOwn = Object.prototype.hasOwnProperty;
10933var pSlice = Array.prototype.slice;
10934var functionsHaveNames = (function () {
10935 return function foo() {}.name === 'foo';
10936}());
10937function pToString (obj) {
10938 return Object.prototype.toString.call(obj);
10939}
10940function isView(arrbuf) {
10941 if (isBuffer(arrbuf)) {
10942 return false;
10943 }
10944 if (typeof global.ArrayBuffer !== 'function') {
10945 return false;
10946 }
10947 if (typeof ArrayBuffer.isView === 'function') {
10948 return ArrayBuffer.isView(arrbuf);
10949 }
10950 if (!arrbuf) {
10951 return false;
10952 }
10953 if (arrbuf instanceof DataView) {
10954 return true;
10955 }
10956 if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
10957 return true;
10958 }
10959 return false;
10960}
10961// 1. The assert module provides functions that throw
10962// AssertionError's when particular conditions are not met. The
10963// assert module must conform to the following interface.
10964
10965var assert = module.exports = ok;
10966
10967// 2. The AssertionError is defined in assert.
10968// new assert.AssertionError({ message: message,
10969// actual: actual,
10970// expected: expected })
10971
10972var regex = /\s*function\s+([^\(\s]*)\s*/;
10973// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
10974function getName(func) {
10975 if (!util.isFunction(func)) {
10976 return;
10977 }
10978 if (functionsHaveNames) {
10979 return func.name;
10980 }
10981 var str = func.toString();
10982 var match = str.match(regex);
10983 return match && match[1];
10984}
10985assert.AssertionError = function AssertionError(options) {
10986 this.name = 'AssertionError';
10987 this.actual = options.actual;
10988 this.expected = options.expected;
10989 this.operator = options.operator;
10990 if (options.message) {
10991 this.message = options.message;
10992 this.generatedMessage = false;
10993 } else {
10994 this.message = getMessage(this);
10995 this.generatedMessage = true;
10996 }
10997 var stackStartFunction = options.stackStartFunction || fail;
10998 if (Error.captureStackTrace) {
10999 Error.captureStackTrace(this, stackStartFunction);
11000 } else {
11001 // non v8 browsers so we can have a stacktrace
11002 var err = new Error();
11003 if (err.stack) {
11004 var out = err.stack;
11005
11006 // try to strip useless frames
11007 var fn_name = getName(stackStartFunction);
11008 var idx = out.indexOf('\n' + fn_name);
11009 if (idx >= 0) {
11010 // once we have located the function frame
11011 // we need to strip out everything before it (and its line)
11012 var next_line = out.indexOf('\n', idx + 1);
11013 out = out.substring(next_line + 1);
11014 }
11015
11016 this.stack = out;
11017 }
11018 }
11019};
11020
11021// assert.AssertionError instanceof Error
11022util.inherits(assert.AssertionError, Error);
11023
11024function truncate(s, n) {
11025 if (typeof s === 'string') {
11026 return s.length < n ? s : s.slice(0, n);
11027 } else {
11028 return s;
11029 }
11030}
11031function inspect(something) {
11032 if (functionsHaveNames || !util.isFunction(something)) {
11033 return util.inspect(something);
11034 }
11035 var rawname = getName(something);
11036 var name = rawname ? ': ' + rawname : '';
11037 return '[Function' + name + ']';
11038}
11039function getMessage(self) {
11040 return truncate(inspect(self.actual), 128) + ' ' +
11041 self.operator + ' ' +
11042 truncate(inspect(self.expected), 128);
11043}
11044
11045// At present only the three keys mentioned above are used and
11046// understood by the spec. Implementations or sub modules can pass
11047// other keys to the AssertionError's constructor - they will be
11048// ignored.
11049
11050// 3. All of the following functions must throw an AssertionError
11051// when a corresponding condition is not met, with a message that
11052// may be undefined if not provided. All assertion methods provide
11053// both the actual and expected values to the assertion error for
11054// display purposes.
11055
11056function fail(actual, expected, message, operator, stackStartFunction) {
11057 throw new assert.AssertionError({
11058 message: message,
11059 actual: actual,
11060 expected: expected,
11061 operator: operator,
11062 stackStartFunction: stackStartFunction
11063 });
11064}
11065
11066// EXTENSION! allows for well behaved errors defined elsewhere.
11067assert.fail = fail;
11068
11069// 4. Pure assertion tests whether a value is truthy, as determined
11070// by !!guard.
11071// assert.ok(guard, message_opt);
11072// This statement is equivalent to assert.equal(true, !!guard,
11073// message_opt);. To test strictly for the value true, use
11074// assert.strictEqual(true, guard, message_opt);.
11075
11076function ok(value, message) {
11077 if (!value) fail(value, true, message, '==', assert.ok);
11078}
11079assert.ok = ok;
11080
11081// 5. The equality assertion tests shallow, coercive equality with
11082// ==.
11083// assert.equal(actual, expected, message_opt);
11084
11085assert.equal = function equal(actual, expected, message) {
11086 if (actual != expected) fail(actual, expected, message, '==', assert.equal);
11087};
11088
11089// 6. The non-equality assertion tests for whether two objects are not equal
11090// with != assert.notEqual(actual, expected, message_opt);
11091
11092assert.notEqual = function notEqual(actual, expected, message) {
11093 if (actual == expected) {
11094 fail(actual, expected, message, '!=', assert.notEqual);
11095 }
11096};
11097
11098// 7. The equivalence assertion tests a deep equality relation.
11099// assert.deepEqual(actual, expected, message_opt);
11100
11101assert.deepEqual = function deepEqual(actual, expected, message) {
11102 if (!_deepEqual(actual, expected, false)) {
11103 fail(actual, expected, message, 'deepEqual', assert.deepEqual);
11104 }
11105};
11106
11107assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
11108 if (!_deepEqual(actual, expected, true)) {
11109 fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
11110 }
11111};
11112
11113function _deepEqual(actual, expected, strict, memos) {
11114 // 7.1. All identical values are equivalent, as determined by ===.
11115 if (actual === expected) {
11116 return true;
11117 } else if (isBuffer(actual) && isBuffer(expected)) {
11118 return compare(actual, expected) === 0;
11119
11120 // 7.2. If the expected value is a Date object, the actual value is
11121 // equivalent if it is also a Date object that refers to the same time.
11122 } else if (util.isDate(actual) && util.isDate(expected)) {
11123 return actual.getTime() === expected.getTime();
11124
11125 // 7.3 If the expected value is a RegExp object, the actual value is
11126 // equivalent if it is also a RegExp object with the same source and
11127 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
11128 } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
11129 return actual.source === expected.source &&
11130 actual.global === expected.global &&
11131 actual.multiline === expected.multiline &&
11132 actual.lastIndex === expected.lastIndex &&
11133 actual.ignoreCase === expected.ignoreCase;
11134
11135 // 7.4. Other pairs that do not both pass typeof value == 'object',
11136 // equivalence is determined by ==.
11137 } else if ((actual === null || typeof actual !== 'object') &&
11138 (expected === null || typeof expected !== 'object')) {
11139 return strict ? actual === expected : actual == expected;
11140
11141 // If both values are instances of typed arrays, wrap their underlying
11142 // ArrayBuffers in a Buffer each to increase performance
11143 // This optimization requires the arrays to have the same type as checked by
11144 // Object.prototype.toString (aka pToString). Never perform binary
11145 // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
11146 // bit patterns are not identical.
11147 } else if (isView(actual) && isView(expected) &&
11148 pToString(actual) === pToString(expected) &&
11149 !(actual instanceof Float32Array ||
11150 actual instanceof Float64Array)) {
11151 return compare(new Uint8Array(actual.buffer),
11152 new Uint8Array(expected.buffer)) === 0;
11153
11154 // 7.5 For all other Object pairs, including Array objects, equivalence is
11155 // determined by having the same number of owned properties (as verified
11156 // with Object.prototype.hasOwnProperty.call), the same set of keys
11157 // (although not necessarily the same order), equivalent values for every
11158 // corresponding key, and an identical 'prototype' property. Note: this
11159 // accounts for both named and indexed properties on Arrays.
11160 } else if (isBuffer(actual) !== isBuffer(expected)) {
11161 return false;
11162 } else {
11163 memos = memos || {actual: [], expected: []};
11164
11165 var actualIndex = memos.actual.indexOf(actual);
11166 if (actualIndex !== -1) {
11167 if (actualIndex === memos.expected.indexOf(expected)) {
11168 return true;
11169 }
11170 }
11171
11172 memos.actual.push(actual);
11173 memos.expected.push(expected);
11174
11175 return objEquiv(actual, expected, strict, memos);
11176 }
11177}
11178
11179function isArguments(object) {
11180 return Object.prototype.toString.call(object) == '[object Arguments]';
11181}
11182
11183function objEquiv(a, b, strict, actualVisitedObjects) {
11184 if (a === null || a === undefined || b === null || b === undefined)
11185 return false;
11186 // if one is a primitive, the other must be same
11187 if (util.isPrimitive(a) || util.isPrimitive(b))
11188 return a === b;
11189 if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
11190 return false;
11191 var aIsArgs = isArguments(a);
11192 var bIsArgs = isArguments(b);
11193 if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
11194 return false;
11195 if (aIsArgs) {
11196 a = pSlice.call(a);
11197 b = pSlice.call(b);
11198 return _deepEqual(a, b, strict);
11199 }
11200 var ka = objectKeys(a);
11201 var kb = objectKeys(b);
11202 var key, i;
11203 // having the same number of owned properties (keys incorporates
11204 // hasOwnProperty)
11205 if (ka.length !== kb.length)
11206 return false;
11207 //the same set of keys (although not necessarily the same order),
11208 ka.sort();
11209 kb.sort();
11210 //~~~cheap key test
11211 for (i = ka.length - 1; i >= 0; i--) {
11212 if (ka[i] !== kb[i])
11213 return false;
11214 }
11215 //equivalent values for every corresponding key, and
11216 //~~~possibly expensive deep test
11217 for (i = ka.length - 1; i >= 0; i--) {
11218 key = ka[i];
11219 if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
11220 return false;
11221 }
11222 return true;
11223}
11224
11225// 8. The non-equivalence assertion tests for any deep inequality.
11226// assert.notDeepEqual(actual, expected, message_opt);
11227
11228assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
11229 if (_deepEqual(actual, expected, false)) {
11230 fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
11231 }
11232};
11233
11234assert.notDeepStrictEqual = notDeepStrictEqual;
11235function notDeepStrictEqual(actual, expected, message) {
11236 if (_deepEqual(actual, expected, true)) {
11237 fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
11238 }
11239}
11240
11241
11242// 9. The strict equality assertion tests strict equality, as determined by ===.
11243// assert.strictEqual(actual, expected, message_opt);
11244
11245assert.strictEqual = function strictEqual(actual, expected, message) {
11246 if (actual !== expected) {
11247 fail(actual, expected, message, '===', assert.strictEqual);
11248 }
11249};
11250
11251// 10. The strict non-equality assertion tests for strict inequality, as
11252// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
11253
11254assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
11255 if (actual === expected) {
11256 fail(actual, expected, message, '!==', assert.notStrictEqual);
11257 }
11258};
11259
11260function expectedException(actual, expected) {
11261 if (!actual || !expected) {
11262 return false;
11263 }
11264
11265 if (Object.prototype.toString.call(expected) == '[object RegExp]') {
11266 return expected.test(actual);
11267 }
11268
11269 try {
11270 if (actual instanceof expected) {
11271 return true;
11272 }
11273 } catch (e) {
11274 // Ignore. The instanceof check doesn't work for arrow functions.
11275 }
11276
11277 if (Error.isPrototypeOf(expected)) {
11278 return false;
11279 }
11280
11281 return expected.call({}, actual) === true;
11282}
11283
11284function _tryBlock(block) {
11285 var error;
11286 try {
11287 block();
11288 } catch (e) {
11289 error = e;
11290 }
11291 return error;
11292}
11293
11294function _throws(shouldThrow, block, expected, message) {
11295 var actual;
11296
11297 if (typeof block !== 'function') {
11298 throw new TypeError('"block" argument must be a function');
11299 }
11300
11301 if (typeof expected === 'string') {
11302 message = expected;
11303 expected = null;
11304 }
11305
11306 actual = _tryBlock(block);
11307
11308 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
11309 (message ? ' ' + message : '.');
11310
11311 if (shouldThrow && !actual) {
11312 fail(actual, expected, 'Missing expected exception' + message);
11313 }
11314
11315 var userProvidedMessage = typeof message === 'string';
11316 var isUnwantedException = !shouldThrow && util.isError(actual);
11317 var isUnexpectedException = !shouldThrow && actual && !expected;
11318
11319 if ((isUnwantedException &&
11320 userProvidedMessage &&
11321 expectedException(actual, expected)) ||
11322 isUnexpectedException) {
11323 fail(actual, expected, 'Got unwanted exception' + message);
11324 }
11325
11326 if ((shouldThrow && actual && expected &&
11327 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
11328 throw actual;
11329 }
11330}
11331
11332// 11. Expected to throw an error:
11333// assert.throws(block, Error_opt, message_opt);
11334
11335assert.throws = function(block, /*optional*/error, /*optional*/message) {
11336 _throws(true, block, error, message);
11337};
11338
11339// EXTENSION! This is annoying to write outside this module.
11340assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
11341 _throws(false, block, error, message);
11342};
11343
11344assert.ifError = function(err) { if (err) throw err; };
11345
11346// Expose a strict only variant of assert
11347function strict(value, message) {
11348 if (!value) fail(value, true, message, '==', strict);
11349}
11350assert.strict = objectAssign(strict, assert, {
11351 equal: assert.strictEqual,
11352 deepEqual: assert.deepStrictEqual,
11353 notEqual: assert.notStrictEqual,
11354 notDeepEqual: assert.notDeepStrictEqual
11355});
11356assert.strict.strict = assert.strict;
11357
11358var objectKeys = Object.keys || function (obj) {
11359 var keys = [];
11360 for (var key in obj) {
11361 if (hasOwn.call(obj, key)) keys.push(key);
11362 }
11363 return keys;
11364};
11365
11366}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
11367},{"object-assign":103,"util/":93}],91:[function(require,module,exports){
11368if (typeof Object.create === 'function') {
11369 // implementation from standard node.js 'util' module
11370 module.exports = function inherits(ctor, superCtor) {
11371 ctor.super_ = superCtor
11372 ctor.prototype = Object.create(superCtor.prototype, {
11373 constructor: {
11374 value: ctor,
11375 enumerable: false,
11376 writable: true,
11377 configurable: true
11378 }
11379 });
11380 };
11381} else {
11382 // old school shim for old browsers
11383 module.exports = function inherits(ctor, superCtor) {
11384 ctor.super_ = superCtor
11385 var TempCtor = function () {}
11386 TempCtor.prototype = superCtor.prototype
11387 ctor.prototype = new TempCtor()
11388 ctor.prototype.constructor = ctor
11389 }
11390}
11391
11392},{}],92:[function(require,module,exports){
11393module.exports = function isBuffer(arg) {
11394 return arg && typeof arg === 'object'
11395 && typeof arg.copy === 'function'
11396 && typeof arg.fill === 'function'
11397 && typeof arg.readUInt8 === 'function';
11398}
11399},{}],93:[function(require,module,exports){
11400(function (process,global){
11401// Copyright Joyent, Inc. and other Node contributors.
11402//
11403// Permission is hereby granted, free of charge, to any person obtaining a
11404// copy of this software and associated documentation files (the
11405// "Software"), to deal in the Software without restriction, including
11406// without limitation the rights to use, copy, modify, merge, publish,
11407// distribute, sublicense, and/or sell copies of the Software, and to permit
11408// persons to whom the Software is furnished to do so, subject to the
11409// following conditions:
11410//
11411// The above copyright notice and this permission notice shall be included
11412// in all copies or substantial portions of the Software.
11413//
11414// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11415// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11416// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
11417// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
11418// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
11419// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
11420// USE OR OTHER DEALINGS IN THE SOFTWARE.
11421
11422var formatRegExp = /%[sdj%]/g;
11423exports.format = function(f) {
11424 if (!isString(f)) {
11425 var objects = [];
11426 for (var i = 0; i < arguments.length; i++) {
11427 objects.push(inspect(arguments[i]));
11428 }
11429 return objects.join(' ');
11430 }
11431
11432 var i = 1;
11433 var args = arguments;
11434 var len = args.length;
11435 var str = String(f).replace(formatRegExp, function(x) {
11436 if (x === '%%') return '%';
11437 if (i >= len) return x;
11438 switch (x) {
11439 case '%s': return String(args[i++]);
11440 case '%d': return Number(args[i++]);
11441 case '%j':
11442 try {
11443 return JSON.stringify(args[i++]);
11444 } catch (_) {
11445 return '[Circular]';
11446 }
11447 default:
11448 return x;
11449 }
11450 });
11451 for (var x = args[i]; i < len; x = args[++i]) {
11452 if (isNull(x) || !isObject(x)) {
11453 str += ' ' + x;
11454 } else {
11455 str += ' ' + inspect(x);
11456 }
11457 }
11458 return str;
11459};
11460
11461
11462// Mark that a method should not be used.
11463// Returns a modified function which warns once by default.
11464// If --no-deprecation is set, then it is a no-op.
11465exports.deprecate = function(fn, msg) {
11466 // Allow for deprecating things in the process of starting up.
11467 if (isUndefined(global.process)) {
11468 return function() {
11469 return exports.deprecate(fn, msg).apply(this, arguments);
11470 };
11471 }
11472
11473 if (process.noDeprecation === true) {
11474 return fn;
11475 }
11476
11477 var warned = false;
11478 function deprecated() {
11479 if (!warned) {
11480 if (process.throwDeprecation) {
11481 throw new Error(msg);
11482 } else if (process.traceDeprecation) {
11483 console.trace(msg);
11484 } else {
11485 console.error(msg);
11486 }
11487 warned = true;
11488 }
11489 return fn.apply(this, arguments);
11490 }
11491
11492 return deprecated;
11493};
11494
11495
11496var debugs = {};
11497var debugEnviron;
11498exports.debuglog = function(set) {
11499 if (isUndefined(debugEnviron))
11500 debugEnviron = process.env.NODE_DEBUG || '';
11501 set = set.toUpperCase();
11502 if (!debugs[set]) {
11503 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
11504 var pid = process.pid;
11505 debugs[set] = function() {
11506 var msg = exports.format.apply(exports, arguments);
11507 console.error('%s %d: %s', set, pid, msg);
11508 };
11509 } else {
11510 debugs[set] = function() {};
11511 }
11512 }
11513 return debugs[set];
11514};
11515
11516
11517/**
11518 * Echos the value of a value. Trys to print the value out
11519 * in the best way possible given the different types.
11520 *
11521 * @param {Object} obj The object to print out.
11522 * @param {Object} opts Optional options object that alters the output.
11523 */
11524/* legacy: obj, showHidden, depth, colors*/
11525function inspect(obj, opts) {
11526 // default options
11527 var ctx = {
11528 seen: [],
11529 stylize: stylizeNoColor
11530 };
11531 // legacy...
11532 if (arguments.length >= 3) ctx.depth = arguments[2];
11533 if (arguments.length >= 4) ctx.colors = arguments[3];
11534 if (isBoolean(opts)) {
11535 // legacy...
11536 ctx.showHidden = opts;
11537 } else if (opts) {
11538 // got an "options" object
11539 exports._extend(ctx, opts);
11540 }
11541 // set default options
11542 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
11543 if (isUndefined(ctx.depth)) ctx.depth = 2;
11544 if (isUndefined(ctx.colors)) ctx.colors = false;
11545 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
11546 if (ctx.colors) ctx.stylize = stylizeWithColor;
11547 return formatValue(ctx, obj, ctx.depth);
11548}
11549exports.inspect = inspect;
11550
11551
11552// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
11553inspect.colors = {
11554 'bold' : [1, 22],
11555 'italic' : [3, 23],
11556 'underline' : [4, 24],
11557 'inverse' : [7, 27],
11558 'white' : [37, 39],
11559 'grey' : [90, 39],
11560 'black' : [30, 39],
11561 'blue' : [34, 39],
11562 'cyan' : [36, 39],
11563 'green' : [32, 39],
11564 'magenta' : [35, 39],
11565 'red' : [31, 39],
11566 'yellow' : [33, 39]
11567};
11568
11569// Don't use 'blue' not visible on cmd.exe
11570inspect.styles = {
11571 'special': 'cyan',
11572 'number': 'yellow',
11573 'boolean': 'yellow',
11574 'undefined': 'grey',
11575 'null': 'bold',
11576 'string': 'green',
11577 'date': 'magenta',
11578 // "name": intentionally not styling
11579 'regexp': 'red'
11580};
11581
11582
11583function stylizeWithColor(str, styleType) {
11584 var style = inspect.styles[styleType];
11585
11586 if (style) {
11587 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
11588 '\u001b[' + inspect.colors[style][1] + 'm';
11589 } else {
11590 return str;
11591 }
11592}
11593
11594
11595function stylizeNoColor(str, styleType) {
11596 return str;
11597}
11598
11599
11600function arrayToHash(array) {
11601 var hash = {};
11602
11603 array.forEach(function(val, idx) {
11604 hash[val] = true;
11605 });
11606
11607 return hash;
11608}
11609
11610
11611function formatValue(ctx, value, recurseTimes) {
11612 // Provide a hook for user-specified inspect functions.
11613 // Check that value is an object with an inspect function on it
11614 if (ctx.customInspect &&
11615 value &&
11616 isFunction(value.inspect) &&
11617 // Filter out the util module, it's inspect function is special
11618 value.inspect !== exports.inspect &&
11619 // Also filter out any prototype objects using the circular check.
11620 !(value.constructor && value.constructor.prototype === value)) {
11621 var ret = value.inspect(recurseTimes, ctx);
11622 if (!isString(ret)) {
11623 ret = formatValue(ctx, ret, recurseTimes);
11624 }
11625 return ret;
11626 }
11627
11628 // Primitive types cannot have properties
11629 var primitive = formatPrimitive(ctx, value);
11630 if (primitive) {
11631 return primitive;
11632 }
11633
11634 // Look up the keys of the object.
11635 var keys = Object.keys(value);
11636 var visibleKeys = arrayToHash(keys);
11637
11638 if (ctx.showHidden) {
11639 keys = Object.getOwnPropertyNames(value);
11640 }
11641
11642 // IE doesn't make error fields non-enumerable
11643 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
11644 if (isError(value)
11645 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
11646 return formatError(value);
11647 }
11648
11649 // Some type of object without properties can be shortcutted.
11650 if (keys.length === 0) {
11651 if (isFunction(value)) {
11652 var name = value.name ? ': ' + value.name : '';
11653 return ctx.stylize('[Function' + name + ']', 'special');
11654 }
11655 if (isRegExp(value)) {
11656 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
11657 }
11658 if (isDate(value)) {
11659 return ctx.stylize(Date.prototype.toString.call(value), 'date');
11660 }
11661 if (isError(value)) {
11662 return formatError(value);
11663 }
11664 }
11665
11666 var base = '', array = false, braces = ['{', '}'];
11667
11668 // Make Array say that they are Array
11669 if (isArray(value)) {
11670 array = true;
11671 braces = ['[', ']'];
11672 }
11673
11674 // Make functions say that they are functions
11675 if (isFunction(value)) {
11676 var n = value.name ? ': ' + value.name : '';
11677 base = ' [Function' + n + ']';
11678 }
11679
11680 // Make RegExps say that they are RegExps
11681 if (isRegExp(value)) {
11682 base = ' ' + RegExp.prototype.toString.call(value);
11683 }
11684
11685 // Make dates with properties first say the date
11686 if (isDate(value)) {
11687 base = ' ' + Date.prototype.toUTCString.call(value);
11688 }
11689
11690 // Make error with message first say the error
11691 if (isError(value)) {
11692 base = ' ' + formatError(value);
11693 }
11694
11695 if (keys.length === 0 && (!array || value.length == 0)) {
11696 return braces[0] + base + braces[1];
11697 }
11698
11699 if (recurseTimes < 0) {
11700 if (isRegExp(value)) {
11701 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
11702 } else {
11703 return ctx.stylize('[Object]', 'special');
11704 }
11705 }
11706
11707 ctx.seen.push(value);
11708
11709 var output;
11710 if (array) {
11711 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
11712 } else {
11713 output = keys.map(function(key) {
11714 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
11715 });
11716 }
11717
11718 ctx.seen.pop();
11719
11720 return reduceToSingleString(output, base, braces);
11721}
11722
11723
11724function formatPrimitive(ctx, value) {
11725 if (isUndefined(value))
11726 return ctx.stylize('undefined', 'undefined');
11727 if (isString(value)) {
11728 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
11729 .replace(/'/g, "\\'")
11730 .replace(/\\"/g, '"') + '\'';
11731 return ctx.stylize(simple, 'string');
11732 }
11733 if (isNumber(value))
11734 return ctx.stylize('' + value, 'number');
11735 if (isBoolean(value))
11736 return ctx.stylize('' + value, 'boolean');
11737 // For some reason typeof null is "object", so special case here.
11738 if (isNull(value))
11739 return ctx.stylize('null', 'null');
11740}
11741
11742
11743function formatError(value) {
11744 return '[' + Error.prototype.toString.call(value) + ']';
11745}
11746
11747
11748function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
11749 var output = [];
11750 for (var i = 0, l = value.length; i < l; ++i) {
11751 if (hasOwnProperty(value, String(i))) {
11752 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
11753 String(i), true));
11754 } else {
11755 output.push('');
11756 }
11757 }
11758 keys.forEach(function(key) {
11759 if (!key.match(/^\d+$/)) {
11760 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
11761 key, true));
11762 }
11763 });
11764 return output;
11765}
11766
11767
11768function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
11769 var name, str, desc;
11770 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
11771 if (desc.get) {
11772 if (desc.set) {
11773 str = ctx.stylize('[Getter/Setter]', 'special');
11774 } else {
11775 str = ctx.stylize('[Getter]', 'special');
11776 }
11777 } else {
11778 if (desc.set) {
11779 str = ctx.stylize('[Setter]', 'special');
11780 }
11781 }
11782 if (!hasOwnProperty(visibleKeys, key)) {
11783 name = '[' + key + ']';
11784 }
11785 if (!str) {
11786 if (ctx.seen.indexOf(desc.value) < 0) {
11787 if (isNull(recurseTimes)) {
11788 str = formatValue(ctx, desc.value, null);
11789 } else {
11790 str = formatValue(ctx, desc.value, recurseTimes - 1);
11791 }
11792 if (str.indexOf('\n') > -1) {
11793 if (array) {
11794 str = str.split('\n').map(function(line) {
11795 return ' ' + line;
11796 }).join('\n').substr(2);
11797 } else {
11798 str = '\n' + str.split('\n').map(function(line) {
11799 return ' ' + line;
11800 }).join('\n');
11801 }
11802 }
11803 } else {
11804 str = ctx.stylize('[Circular]', 'special');
11805 }
11806 }
11807 if (isUndefined(name)) {
11808 if (array && key.match(/^\d+$/)) {
11809 return str;
11810 }
11811 name = JSON.stringify('' + key);
11812 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
11813 name = name.substr(1, name.length - 2);
11814 name = ctx.stylize(name, 'name');
11815 } else {
11816 name = name.replace(/'/g, "\\'")
11817 .replace(/\\"/g, '"')
11818 .replace(/(^"|"$)/g, "'");
11819 name = ctx.stylize(name, 'string');
11820 }
11821 }
11822
11823 return name + ': ' + str;
11824}
11825
11826
11827function reduceToSingleString(output, base, braces) {
11828 var numLinesEst = 0;
11829 var length = output.reduce(function(prev, cur) {
11830 numLinesEst++;
11831 if (cur.indexOf('\n') >= 0) numLinesEst++;
11832 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
11833 }, 0);
11834
11835 if (length > 60) {
11836 return braces[0] +
11837 (base === '' ? '' : base + '\n ') +
11838 ' ' +
11839 output.join(',\n ') +
11840 ' ' +
11841 braces[1];
11842 }
11843
11844 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
11845}
11846
11847
11848// NOTE: These type checking functions intentionally don't use `instanceof`
11849// because it is fragile and can be easily faked with `Object.create()`.
11850function isArray(ar) {
11851 return Array.isArray(ar);
11852}
11853exports.isArray = isArray;
11854
11855function isBoolean(arg) {
11856 return typeof arg === 'boolean';
11857}
11858exports.isBoolean = isBoolean;
11859
11860function isNull(arg) {
11861 return arg === null;
11862}
11863exports.isNull = isNull;
11864
11865function isNullOrUndefined(arg) {
11866 return arg == null;
11867}
11868exports.isNullOrUndefined = isNullOrUndefined;
11869
11870function isNumber(arg) {
11871 return typeof arg === 'number';
11872}
11873exports.isNumber = isNumber;
11874
11875function isString(arg) {
11876 return typeof arg === 'string';
11877}
11878exports.isString = isString;
11879
11880function isSymbol(arg) {
11881 return typeof arg === 'symbol';
11882}
11883exports.isSymbol = isSymbol;
11884
11885function isUndefined(arg) {
11886 return arg === void 0;
11887}
11888exports.isUndefined = isUndefined;
11889
11890function isRegExp(re) {
11891 return isObject(re) && objectToString(re) === '[object RegExp]';
11892}
11893exports.isRegExp = isRegExp;
11894
11895function isObject(arg) {
11896 return typeof arg === 'object' && arg !== null;
11897}
11898exports.isObject = isObject;
11899
11900function isDate(d) {
11901 return isObject(d) && objectToString(d) === '[object Date]';
11902}
11903exports.isDate = isDate;
11904
11905function isError(e) {
11906 return isObject(e) &&
11907 (objectToString(e) === '[object Error]' || e instanceof Error);
11908}
11909exports.isError = isError;
11910
11911function isFunction(arg) {
11912 return typeof arg === 'function';
11913}
11914exports.isFunction = isFunction;
11915
11916function isPrimitive(arg) {
11917 return arg === null ||
11918 typeof arg === 'boolean' ||
11919 typeof arg === 'number' ||
11920 typeof arg === 'string' ||
11921 typeof arg === 'symbol' || // ES6 symbol
11922 typeof arg === 'undefined';
11923}
11924exports.isPrimitive = isPrimitive;
11925
11926exports.isBuffer = require('./support/isBuffer');
11927
11928function objectToString(o) {
11929 return Object.prototype.toString.call(o);
11930}
11931
11932
11933function pad(n) {
11934 return n < 10 ? '0' + n.toString(10) : n.toString(10);
11935}
11936
11937
11938var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
11939 'Oct', 'Nov', 'Dec'];
11940
11941// 26 Feb 16:19:34
11942function timestamp() {
11943 var d = new Date();
11944 var time = [pad(d.getHours()),
11945 pad(d.getMinutes()),
11946 pad(d.getSeconds())].join(':');
11947 return [d.getDate(), months[d.getMonth()], time].join(' ');
11948}
11949
11950
11951// log is just a thin wrapper to console.log that prepends a timestamp
11952exports.log = function() {
11953 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
11954};
11955
11956
11957/**
11958 * Inherit the prototype methods from one constructor into another.
11959 *
11960 * The Function.prototype.inherits from lang.js rewritten as a standalone
11961 * function (not on Function.prototype). NOTE: If this file is to be loaded
11962 * during bootstrapping this function needs to be rewritten using some native
11963 * functions as prototype setup using normal JavaScript does not work as
11964 * expected during bootstrapping (see mirror.js in r114903).
11965 *
11966 * @param {function} ctor Constructor function which needs to inherit the
11967 * prototype.
11968 * @param {function} superCtor Constructor function to inherit prototype from.
11969 */
11970exports.inherits = require('inherits');
11971
11972exports._extend = function(origin, add) {
11973 // Don't do anything if add isn't an object
11974 if (!add || !isObject(add)) return origin;
11975
11976 var keys = Object.keys(add);
11977 var i = keys.length;
11978 while (i--) {
11979 origin[keys[i]] = add[keys[i]];
11980 }
11981 return origin;
11982};
11983
11984function hasOwnProperty(obj, prop) {
11985 return Object.prototype.hasOwnProperty.call(obj, prop);
11986}
11987
11988}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
11989},{"./support/isBuffer":92,"_process":105,"inherits":91}],94:[function(require,module,exports){
11990'use strict'
11991
11992exports.byteLength = byteLength
11993exports.toByteArray = toByteArray
11994exports.fromByteArray = fromByteArray
11995
11996var lookup = []
11997var revLookup = []
11998var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
11999
12000var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
12001for (var i = 0, len = code.length; i < len; ++i) {
12002 lookup[i] = code[i]
12003 revLookup[code.charCodeAt(i)] = i
12004}
12005
12006// Support decoding URL-safe base64 strings, as Node.js does.
12007// See: https://en.wikipedia.org/wiki/Base64#URL_applications
12008revLookup['-'.charCodeAt(0)] = 62
12009revLookup['_'.charCodeAt(0)] = 63
12010
12011function getLens (b64) {
12012 var len = b64.length
12013
12014 if (len % 4 > 0) {
12015 throw new Error('Invalid string. Length must be a multiple of 4')
12016 }
12017
12018 // Trim off extra bytes after placeholder bytes are found
12019 // See: https://github.com/beatgammit/base64-js/issues/42
12020 var validLen = b64.indexOf('=')
12021 if (validLen === -1) validLen = len
12022
12023 var placeHoldersLen = validLen === len
12024 ? 0
12025 : 4 - (validLen % 4)
12026
12027 return [validLen, placeHoldersLen]
12028}
12029
12030// base64 is 4/3 + up to two characters of the original data
12031function byteLength (b64) {
12032 var lens = getLens(b64)
12033 var validLen = lens[0]
12034 var placeHoldersLen = lens[1]
12035 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
12036}
12037
12038function _byteLength (b64, validLen, placeHoldersLen) {
12039 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
12040}
12041
12042function toByteArray (b64) {
12043 var tmp
12044 var lens = getLens(b64)
12045 var validLen = lens[0]
12046 var placeHoldersLen = lens[1]
12047
12048 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
12049
12050 var curByte = 0
12051
12052 // if there are placeholders, only get up to the last complete 4 chars
12053 var len = placeHoldersLen > 0
12054 ? validLen - 4
12055 : validLen
12056
12057 var i
12058 for (i = 0; i < len; i += 4) {
12059 tmp =
12060 (revLookup[b64.charCodeAt(i)] << 18) |
12061 (revLookup[b64.charCodeAt(i + 1)] << 12) |
12062 (revLookup[b64.charCodeAt(i + 2)] << 6) |
12063 revLookup[b64.charCodeAt(i + 3)]
12064 arr[curByte++] = (tmp >> 16) & 0xFF
12065 arr[curByte++] = (tmp >> 8) & 0xFF
12066 arr[curByte++] = tmp & 0xFF
12067 }
12068
12069 if (placeHoldersLen === 2) {
12070 tmp =
12071 (revLookup[b64.charCodeAt(i)] << 2) |
12072 (revLookup[b64.charCodeAt(i + 1)] >> 4)
12073 arr[curByte++] = tmp & 0xFF
12074 }
12075
12076 if (placeHoldersLen === 1) {
12077 tmp =
12078 (revLookup[b64.charCodeAt(i)] << 10) |
12079 (revLookup[b64.charCodeAt(i + 1)] << 4) |
12080 (revLookup[b64.charCodeAt(i + 2)] >> 2)
12081 arr[curByte++] = (tmp >> 8) & 0xFF
12082 arr[curByte++] = tmp & 0xFF
12083 }
12084
12085 return arr
12086}
12087
12088function tripletToBase64 (num) {
12089 return lookup[num >> 18 & 0x3F] +
12090 lookup[num >> 12 & 0x3F] +
12091 lookup[num >> 6 & 0x3F] +
12092 lookup[num & 0x3F]
12093}
12094
12095function encodeChunk (uint8, start, end) {
12096 var tmp
12097 var output = []
12098 for (var i = start; i < end; i += 3) {
12099 tmp =
12100 ((uint8[i] << 16) & 0xFF0000) +
12101 ((uint8[i + 1] << 8) & 0xFF00) +
12102 (uint8[i + 2] & 0xFF)
12103 output.push(tripletToBase64(tmp))
12104 }
12105 return output.join('')
12106}
12107
12108function fromByteArray (uint8) {
12109 var tmp
12110 var len = uint8.length
12111 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
12112 var parts = []
12113 var maxChunkLength = 16383 // must be multiple of 3
12114
12115 // go through the array every three bytes, we'll deal with trailing stuff later
12116 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
12117 parts.push(encodeChunk(
12118 uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
12119 ))
12120 }
12121
12122 // pad the end with zeros, but make sure to not forget the extra bytes
12123 if (extraBytes === 1) {
12124 tmp = uint8[len - 1]
12125 parts.push(
12126 lookup[tmp >> 2] +
12127 lookup[(tmp << 4) & 0x3F] +
12128 '=='
12129 )
12130 } else if (extraBytes === 2) {
12131 tmp = (uint8[len - 2] << 8) + uint8[len - 1]
12132 parts.push(
12133 lookup[tmp >> 10] +
12134 lookup[(tmp >> 4) & 0x3F] +
12135 lookup[(tmp << 2) & 0x3F] +
12136 '='
12137 )
12138 }
12139
12140 return parts.join('')
12141}
12142
12143},{}],95:[function(require,module,exports){
12144
12145},{}],96:[function(require,module,exports){
12146(function (Buffer){
12147/*!
12148 * The buffer module from node.js, for the browser.
12149 *
12150 * @author Feross Aboukhadijeh <https://feross.org>
12151 * @license MIT
12152 */
12153/* eslint-disable no-proto */
12154
12155'use strict'
12156
12157var base64 = require('base64-js')
12158var ieee754 = require('ieee754')
12159var customInspectSymbol =
12160 (typeof Symbol === 'function' && typeof Symbol.for === 'function')
12161 ? Symbol.for('nodejs.util.inspect.custom')
12162 : null
12163
12164exports.Buffer = Buffer
12165exports.SlowBuffer = SlowBuffer
12166exports.INSPECT_MAX_BYTES = 50
12167
12168var K_MAX_LENGTH = 0x7fffffff
12169exports.kMaxLength = K_MAX_LENGTH
12170
12171/**
12172 * If `Buffer.TYPED_ARRAY_SUPPORT`:
12173 * === true Use Uint8Array implementation (fastest)
12174 * === false Print warning and recommend using `buffer` v4.x which has an Object
12175 * implementation (most compatible, even IE6)
12176 *
12177 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
12178 * Opera 11.6+, iOS 4.2+.
12179 *
12180 * We report that the browser does not support typed arrays if the are not subclassable
12181 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
12182 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
12183 * for __proto__ and has a buggy typed array implementation.
12184 */
12185Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
12186
12187if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
12188 typeof console.error === 'function') {
12189 console.error(
12190 'This browser lacks typed array (Uint8Array) support which is required by ' +
12191 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
12192 )
12193}
12194
12195function typedArraySupport () {
12196 // Can typed array instances can be augmented?
12197 try {
12198 var arr = new Uint8Array(1)
12199 var proto = { foo: function () { return 42 } }
12200 Object.setPrototypeOf(proto, Uint8Array.prototype)
12201 Object.setPrototypeOf(arr, proto)
12202 return arr.foo() === 42
12203 } catch (e) {
12204 return false
12205 }
12206}
12207
12208Object.defineProperty(Buffer.prototype, 'parent', {
12209 enumerable: true,
12210 get: function () {
12211 if (!Buffer.isBuffer(this)) return undefined
12212 return this.buffer
12213 }
12214})
12215
12216Object.defineProperty(Buffer.prototype, 'offset', {
12217 enumerable: true,
12218 get: function () {
12219 if (!Buffer.isBuffer(this)) return undefined
12220 return this.byteOffset
12221 }
12222})
12223
12224function createBuffer (length) {
12225 if (length > K_MAX_LENGTH) {
12226 throw new RangeError('The value "' + length + '" is invalid for option "size"')
12227 }
12228 // Return an augmented `Uint8Array` instance
12229 var buf = new Uint8Array(length)
12230 Object.setPrototypeOf(buf, Buffer.prototype)
12231 return buf
12232}
12233
12234/**
12235 * The Buffer constructor returns instances of `Uint8Array` that have their
12236 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
12237 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
12238 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
12239 * returns a single octet.
12240 *
12241 * The `Uint8Array` prototype remains unmodified.
12242 */
12243
12244function Buffer (arg, encodingOrOffset, length) {
12245 // Common case.
12246 if (typeof arg === 'number') {
12247 if (typeof encodingOrOffset === 'string') {
12248 throw new TypeError(
12249 'The "string" argument must be of type string. Received type number'
12250 )
12251 }
12252 return allocUnsafe(arg)
12253 }
12254 return from(arg, encodingOrOffset, length)
12255}
12256
12257// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
12258if (typeof Symbol !== 'undefined' && Symbol.species != null &&
12259 Buffer[Symbol.species] === Buffer) {
12260 Object.defineProperty(Buffer, Symbol.species, {
12261 value: null,
12262 configurable: true,
12263 enumerable: false,
12264 writable: false
12265 })
12266}
12267
12268Buffer.poolSize = 8192 // not used by this implementation
12269
12270function from (value, encodingOrOffset, length) {
12271 if (typeof value === 'string') {
12272 return fromString(value, encodingOrOffset)
12273 }
12274
12275 if (ArrayBuffer.isView(value)) {
12276 return fromArrayLike(value)
12277 }
12278
12279 if (value == null) {
12280 throw new TypeError(
12281 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
12282 'or Array-like Object. Received type ' + (typeof value)
12283 )
12284 }
12285
12286 if (isInstance(value, ArrayBuffer) ||
12287 (value && isInstance(value.buffer, ArrayBuffer))) {
12288 return fromArrayBuffer(value, encodingOrOffset, length)
12289 }
12290
12291 if (typeof value === 'number') {
12292 throw new TypeError(
12293 'The "value" argument must not be of type number. Received type number'
12294 )
12295 }
12296
12297 var valueOf = value.valueOf && value.valueOf()
12298 if (valueOf != null && valueOf !== value) {
12299 return Buffer.from(valueOf, encodingOrOffset, length)
12300 }
12301
12302 var b = fromObject(value)
12303 if (b) return b
12304
12305 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
12306 typeof value[Symbol.toPrimitive] === 'function') {
12307 return Buffer.from(
12308 value[Symbol.toPrimitive]('string'), encodingOrOffset, length
12309 )
12310 }
12311
12312 throw new TypeError(
12313 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
12314 'or Array-like Object. Received type ' + (typeof value)
12315 )
12316}
12317
12318/**
12319 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
12320 * if value is a number.
12321 * Buffer.from(str[, encoding])
12322 * Buffer.from(array)
12323 * Buffer.from(buffer)
12324 * Buffer.from(arrayBuffer[, byteOffset[, length]])
12325 **/
12326Buffer.from = function (value, encodingOrOffset, length) {
12327 return from(value, encodingOrOffset, length)
12328}
12329
12330// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
12331// https://github.com/feross/buffer/pull/148
12332Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
12333Object.setPrototypeOf(Buffer, Uint8Array)
12334
12335function assertSize (size) {
12336 if (typeof size !== 'number') {
12337 throw new TypeError('"size" argument must be of type number')
12338 } else if (size < 0) {
12339 throw new RangeError('The value "' + size + '" is invalid for option "size"')
12340 }
12341}
12342
12343function alloc (size, fill, encoding) {
12344 assertSize(size)
12345 if (size <= 0) {
12346 return createBuffer(size)
12347 }
12348 if (fill !== undefined) {
12349 // Only pay attention to encoding if it's a string. This
12350 // prevents accidentally sending in a number that would
12351 // be interpretted as a start offset.
12352 return typeof encoding === 'string'
12353 ? createBuffer(size).fill(fill, encoding)
12354 : createBuffer(size).fill(fill)
12355 }
12356 return createBuffer(size)
12357}
12358
12359/**
12360 * Creates a new filled Buffer instance.
12361 * alloc(size[, fill[, encoding]])
12362 **/
12363Buffer.alloc = function (size, fill, encoding) {
12364 return alloc(size, fill, encoding)
12365}
12366
12367function allocUnsafe (size) {
12368 assertSize(size)
12369 return createBuffer(size < 0 ? 0 : checked(size) | 0)
12370}
12371
12372/**
12373 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
12374 * */
12375Buffer.allocUnsafe = function (size) {
12376 return allocUnsafe(size)
12377}
12378/**
12379 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
12380 */
12381Buffer.allocUnsafeSlow = function (size) {
12382 return allocUnsafe(size)
12383}
12384
12385function fromString (string, encoding) {
12386 if (typeof encoding !== 'string' || encoding === '') {
12387 encoding = 'utf8'
12388 }
12389
12390 if (!Buffer.isEncoding(encoding)) {
12391 throw new TypeError('Unknown encoding: ' + encoding)
12392 }
12393
12394 var length = byteLength(string, encoding) | 0
12395 var buf = createBuffer(length)
12396
12397 var actual = buf.write(string, encoding)
12398
12399 if (actual !== length) {
12400 // Writing a hex string, for example, that contains invalid characters will
12401 // cause everything after the first invalid character to be ignored. (e.g.
12402 // 'abxxcd' will be treated as 'ab')
12403 buf = buf.slice(0, actual)
12404 }
12405
12406 return buf
12407}
12408
12409function fromArrayLike (array) {
12410 var length = array.length < 0 ? 0 : checked(array.length) | 0
12411 var buf = createBuffer(length)
12412 for (var i = 0; i < length; i += 1) {
12413 buf[i] = array[i] & 255
12414 }
12415 return buf
12416}
12417
12418function fromArrayBuffer (array, byteOffset, length) {
12419 if (byteOffset < 0 || array.byteLength < byteOffset) {
12420 throw new RangeError('"offset" is outside of buffer bounds')
12421 }
12422
12423 if (array.byteLength < byteOffset + (length || 0)) {
12424 throw new RangeError('"length" is outside of buffer bounds')
12425 }
12426
12427 var buf
12428 if (byteOffset === undefined && length === undefined) {
12429 buf = new Uint8Array(array)
12430 } else if (length === undefined) {
12431 buf = new Uint8Array(array, byteOffset)
12432 } else {
12433 buf = new Uint8Array(array, byteOffset, length)
12434 }
12435
12436 // Return an augmented `Uint8Array` instance
12437 Object.setPrototypeOf(buf, Buffer.prototype)
12438
12439 return buf
12440}
12441
12442function fromObject (obj) {
12443 if (Buffer.isBuffer(obj)) {
12444 var len = checked(obj.length) | 0
12445 var buf = createBuffer(len)
12446
12447 if (buf.length === 0) {
12448 return buf
12449 }
12450
12451 obj.copy(buf, 0, 0, len)
12452 return buf
12453 }
12454
12455 if (obj.length !== undefined) {
12456 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
12457 return createBuffer(0)
12458 }
12459 return fromArrayLike(obj)
12460 }
12461
12462 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
12463 return fromArrayLike(obj.data)
12464 }
12465}
12466
12467function checked (length) {
12468 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
12469 // length is NaN (which is otherwise coerced to zero.)
12470 if (length >= K_MAX_LENGTH) {
12471 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
12472 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
12473 }
12474 return length | 0
12475}
12476
12477function SlowBuffer (length) {
12478 if (+length != length) { // eslint-disable-line eqeqeq
12479 length = 0
12480 }
12481 return Buffer.alloc(+length)
12482}
12483
12484Buffer.isBuffer = function isBuffer (b) {
12485 return b != null && b._isBuffer === true &&
12486 b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
12487}
12488
12489Buffer.compare = function compare (a, b) {
12490 if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
12491 if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
12492 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
12493 throw new TypeError(
12494 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
12495 )
12496 }
12497
12498 if (a === b) return 0
12499
12500 var x = a.length
12501 var y = b.length
12502
12503 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
12504 if (a[i] !== b[i]) {
12505 x = a[i]
12506 y = b[i]
12507 break
12508 }
12509 }
12510
12511 if (x < y) return -1
12512 if (y < x) return 1
12513 return 0
12514}
12515
12516Buffer.isEncoding = function isEncoding (encoding) {
12517 switch (String(encoding).toLowerCase()) {
12518 case 'hex':
12519 case 'utf8':
12520 case 'utf-8':
12521 case 'ascii':
12522 case 'latin1':
12523 case 'binary':
12524 case 'base64':
12525 case 'ucs2':
12526 case 'ucs-2':
12527 case 'utf16le':
12528 case 'utf-16le':
12529 return true
12530 default:
12531 return false
12532 }
12533}
12534
12535Buffer.concat = function concat (list, length) {
12536 if (!Array.isArray(list)) {
12537 throw new TypeError('"list" argument must be an Array of Buffers')
12538 }
12539
12540 if (list.length === 0) {
12541 return Buffer.alloc(0)
12542 }
12543
12544 var i
12545 if (length === undefined) {
12546 length = 0
12547 for (i = 0; i < list.length; ++i) {
12548 length += list[i].length
12549 }
12550 }
12551
12552 var buffer = Buffer.allocUnsafe(length)
12553 var pos = 0
12554 for (i = 0; i < list.length; ++i) {
12555 var buf = list[i]
12556 if (isInstance(buf, Uint8Array)) {
12557 buf = Buffer.from(buf)
12558 }
12559 if (!Buffer.isBuffer(buf)) {
12560 throw new TypeError('"list" argument must be an Array of Buffers')
12561 }
12562 buf.copy(buffer, pos)
12563 pos += buf.length
12564 }
12565 return buffer
12566}
12567
12568function byteLength (string, encoding) {
12569 if (Buffer.isBuffer(string)) {
12570 return string.length
12571 }
12572 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
12573 return string.byteLength
12574 }
12575 if (typeof string !== 'string') {
12576 throw new TypeError(
12577 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
12578 'Received type ' + typeof string
12579 )
12580 }
12581
12582 var len = string.length
12583 var mustMatch = (arguments.length > 2 && arguments[2] === true)
12584 if (!mustMatch && len === 0) return 0
12585
12586 // Use a for loop to avoid recursion
12587 var loweredCase = false
12588 for (;;) {
12589 switch (encoding) {
12590 case 'ascii':
12591 case 'latin1':
12592 case 'binary':
12593 return len
12594 case 'utf8':
12595 case 'utf-8':
12596 return utf8ToBytes(string).length
12597 case 'ucs2':
12598 case 'ucs-2':
12599 case 'utf16le':
12600 case 'utf-16le':
12601 return len * 2
12602 case 'hex':
12603 return len >>> 1
12604 case 'base64':
12605 return base64ToBytes(string).length
12606 default:
12607 if (loweredCase) {
12608 return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
12609 }
12610 encoding = ('' + encoding).toLowerCase()
12611 loweredCase = true
12612 }
12613 }
12614}
12615Buffer.byteLength = byteLength
12616
12617function slowToString (encoding, start, end) {
12618 var loweredCase = false
12619
12620 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
12621 // property of a typed array.
12622
12623 // This behaves neither like String nor Uint8Array in that we set start/end
12624 // to their upper/lower bounds if the value passed is out of range.
12625 // undefined is handled specially as per ECMA-262 6th Edition,
12626 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
12627 if (start === undefined || start < 0) {
12628 start = 0
12629 }
12630 // Return early if start > this.length. Done here to prevent potential uint32
12631 // coercion fail below.
12632 if (start > this.length) {
12633 return ''
12634 }
12635
12636 if (end === undefined || end > this.length) {
12637 end = this.length
12638 }
12639
12640 if (end <= 0) {
12641 return ''
12642 }
12643
12644 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
12645 end >>>= 0
12646 start >>>= 0
12647
12648 if (end <= start) {
12649 return ''
12650 }
12651
12652 if (!encoding) encoding = 'utf8'
12653
12654 while (true) {
12655 switch (encoding) {
12656 case 'hex':
12657 return hexSlice(this, start, end)
12658
12659 case 'utf8':
12660 case 'utf-8':
12661 return utf8Slice(this, start, end)
12662
12663 case 'ascii':
12664 return asciiSlice(this, start, end)
12665
12666 case 'latin1':
12667 case 'binary':
12668 return latin1Slice(this, start, end)
12669
12670 case 'base64':
12671 return base64Slice(this, start, end)
12672
12673 case 'ucs2':
12674 case 'ucs-2':
12675 case 'utf16le':
12676 case 'utf-16le':
12677 return utf16leSlice(this, start, end)
12678
12679 default:
12680 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
12681 encoding = (encoding + '').toLowerCase()
12682 loweredCase = true
12683 }
12684 }
12685}
12686
12687// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
12688// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
12689// reliably in a browserify context because there could be multiple different
12690// copies of the 'buffer' package in use. This method works even for Buffer
12691// instances that were created from another copy of the `buffer` package.
12692// See: https://github.com/feross/buffer/issues/154
12693Buffer.prototype._isBuffer = true
12694
12695function swap (b, n, m) {
12696 var i = b[n]
12697 b[n] = b[m]
12698 b[m] = i
12699}
12700
12701Buffer.prototype.swap16 = function swap16 () {
12702 var len = this.length
12703 if (len % 2 !== 0) {
12704 throw new RangeError('Buffer size must be a multiple of 16-bits')
12705 }
12706 for (var i = 0; i < len; i += 2) {
12707 swap(this, i, i + 1)
12708 }
12709 return this
12710}
12711
12712Buffer.prototype.swap32 = function swap32 () {
12713 var len = this.length
12714 if (len % 4 !== 0) {
12715 throw new RangeError('Buffer size must be a multiple of 32-bits')
12716 }
12717 for (var i = 0; i < len; i += 4) {
12718 swap(this, i, i + 3)
12719 swap(this, i + 1, i + 2)
12720 }
12721 return this
12722}
12723
12724Buffer.prototype.swap64 = function swap64 () {
12725 var len = this.length
12726 if (len % 8 !== 0) {
12727 throw new RangeError('Buffer size must be a multiple of 64-bits')
12728 }
12729 for (var i = 0; i < len; i += 8) {
12730 swap(this, i, i + 7)
12731 swap(this, i + 1, i + 6)
12732 swap(this, i + 2, i + 5)
12733 swap(this, i + 3, i + 4)
12734 }
12735 return this
12736}
12737
12738Buffer.prototype.toString = function toString () {
12739 var length = this.length
12740 if (length === 0) return ''
12741 if (arguments.length === 0) return utf8Slice(this, 0, length)
12742 return slowToString.apply(this, arguments)
12743}
12744
12745Buffer.prototype.toLocaleString = Buffer.prototype.toString
12746
12747Buffer.prototype.equals = function equals (b) {
12748 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
12749 if (this === b) return true
12750 return Buffer.compare(this, b) === 0
12751}
12752
12753Buffer.prototype.inspect = function inspect () {
12754 var str = ''
12755 var max = exports.INSPECT_MAX_BYTES
12756 str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
12757 if (this.length > max) str += ' ... '
12758 return '<Buffer ' + str + '>'
12759}
12760if (customInspectSymbol) {
12761 Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
12762}
12763
12764Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
12765 if (isInstance(target, Uint8Array)) {
12766 target = Buffer.from(target, target.offset, target.byteLength)
12767 }
12768 if (!Buffer.isBuffer(target)) {
12769 throw new TypeError(
12770 'The "target" argument must be one of type Buffer or Uint8Array. ' +
12771 'Received type ' + (typeof target)
12772 )
12773 }
12774
12775 if (start === undefined) {
12776 start = 0
12777 }
12778 if (end === undefined) {
12779 end = target ? target.length : 0
12780 }
12781 if (thisStart === undefined) {
12782 thisStart = 0
12783 }
12784 if (thisEnd === undefined) {
12785 thisEnd = this.length
12786 }
12787
12788 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
12789 throw new RangeError('out of range index')
12790 }
12791
12792 if (thisStart >= thisEnd && start >= end) {
12793 return 0
12794 }
12795 if (thisStart >= thisEnd) {
12796 return -1
12797 }
12798 if (start >= end) {
12799 return 1
12800 }
12801
12802 start >>>= 0
12803 end >>>= 0
12804 thisStart >>>= 0
12805 thisEnd >>>= 0
12806
12807 if (this === target) return 0
12808
12809 var x = thisEnd - thisStart
12810 var y = end - start
12811 var len = Math.min(x, y)
12812
12813 var thisCopy = this.slice(thisStart, thisEnd)
12814 var targetCopy = target.slice(start, end)
12815
12816 for (var i = 0; i < len; ++i) {
12817 if (thisCopy[i] !== targetCopy[i]) {
12818 x = thisCopy[i]
12819 y = targetCopy[i]
12820 break
12821 }
12822 }
12823
12824 if (x < y) return -1
12825 if (y < x) return 1
12826 return 0
12827}
12828
12829// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
12830// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
12831//
12832// Arguments:
12833// - buffer - a Buffer to search
12834// - val - a string, Buffer, or number
12835// - byteOffset - an index into `buffer`; will be clamped to an int32
12836// - encoding - an optional encoding, relevant is val is a string
12837// - dir - true for indexOf, false for lastIndexOf
12838function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
12839 // Empty buffer means no match
12840 if (buffer.length === 0) return -1
12841
12842 // Normalize byteOffset
12843 if (typeof byteOffset === 'string') {
12844 encoding = byteOffset
12845 byteOffset = 0
12846 } else if (byteOffset > 0x7fffffff) {
12847 byteOffset = 0x7fffffff
12848 } else if (byteOffset < -0x80000000) {
12849 byteOffset = -0x80000000
12850 }
12851 byteOffset = +byteOffset // Coerce to Number.
12852 if (numberIsNaN(byteOffset)) {
12853 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
12854 byteOffset = dir ? 0 : (buffer.length - 1)
12855 }
12856
12857 // Normalize byteOffset: negative offsets start from the end of the buffer
12858 if (byteOffset < 0) byteOffset = buffer.length + byteOffset
12859 if (byteOffset >= buffer.length) {
12860 if (dir) return -1
12861 else byteOffset = buffer.length - 1
12862 } else if (byteOffset < 0) {
12863 if (dir) byteOffset = 0
12864 else return -1
12865 }
12866
12867 // Normalize val
12868 if (typeof val === 'string') {
12869 val = Buffer.from(val, encoding)
12870 }
12871
12872 // Finally, search either indexOf (if dir is true) or lastIndexOf
12873 if (Buffer.isBuffer(val)) {
12874 // Special case: looking for empty string/buffer always fails
12875 if (val.length === 0) {
12876 return -1
12877 }
12878 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
12879 } else if (typeof val === 'number') {
12880 val = val & 0xFF // Search for a byte value [0-255]
12881 if (typeof Uint8Array.prototype.indexOf === 'function') {
12882 if (dir) {
12883 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
12884 } else {
12885 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
12886 }
12887 }
12888 return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
12889 }
12890
12891 throw new TypeError('val must be string, number or Buffer')
12892}
12893
12894function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
12895 var indexSize = 1
12896 var arrLength = arr.length
12897 var valLength = val.length
12898
12899 if (encoding !== undefined) {
12900 encoding = String(encoding).toLowerCase()
12901 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
12902 encoding === 'utf16le' || encoding === 'utf-16le') {
12903 if (arr.length < 2 || val.length < 2) {
12904 return -1
12905 }
12906 indexSize = 2
12907 arrLength /= 2
12908 valLength /= 2
12909 byteOffset /= 2
12910 }
12911 }
12912
12913 function read (buf, i) {
12914 if (indexSize === 1) {
12915 return buf[i]
12916 } else {
12917 return buf.readUInt16BE(i * indexSize)
12918 }
12919 }
12920
12921 var i
12922 if (dir) {
12923 var foundIndex = -1
12924 for (i = byteOffset; i < arrLength; i++) {
12925 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
12926 if (foundIndex === -1) foundIndex = i
12927 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
12928 } else {
12929 if (foundIndex !== -1) i -= i - foundIndex
12930 foundIndex = -1
12931 }
12932 }
12933 } else {
12934 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
12935 for (i = byteOffset; i >= 0; i--) {
12936 var found = true
12937 for (var j = 0; j < valLength; j++) {
12938 if (read(arr, i + j) !== read(val, j)) {
12939 found = false
12940 break
12941 }
12942 }
12943 if (found) return i
12944 }
12945 }
12946
12947 return -1
12948}
12949
12950Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
12951 return this.indexOf(val, byteOffset, encoding) !== -1
12952}
12953
12954Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
12955 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
12956}
12957
12958Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
12959 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
12960}
12961
12962function hexWrite (buf, string, offset, length) {
12963 offset = Number(offset) || 0
12964 var remaining = buf.length - offset
12965 if (!length) {
12966 length = remaining
12967 } else {
12968 length = Number(length)
12969 if (length > remaining) {
12970 length = remaining
12971 }
12972 }
12973
12974 var strLen = string.length
12975
12976 if (length > strLen / 2) {
12977 length = strLen / 2
12978 }
12979 for (var i = 0; i < length; ++i) {
12980 var parsed = parseInt(string.substr(i * 2, 2), 16)
12981 if (numberIsNaN(parsed)) return i
12982 buf[offset + i] = parsed
12983 }
12984 return i
12985}
12986
12987function utf8Write (buf, string, offset, length) {
12988 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
12989}
12990
12991function asciiWrite (buf, string, offset, length) {
12992 return blitBuffer(asciiToBytes(string), buf, offset, length)
12993}
12994
12995function latin1Write (buf, string, offset, length) {
12996 return asciiWrite(buf, string, offset, length)
12997}
12998
12999function base64Write (buf, string, offset, length) {
13000 return blitBuffer(base64ToBytes(string), buf, offset, length)
13001}
13002
13003function ucs2Write (buf, string, offset, length) {
13004 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
13005}
13006
13007Buffer.prototype.write = function write (string, offset, length, encoding) {
13008 // Buffer#write(string)
13009 if (offset === undefined) {
13010 encoding = 'utf8'
13011 length = this.length
13012 offset = 0
13013 // Buffer#write(string, encoding)
13014 } else if (length === undefined && typeof offset === 'string') {
13015 encoding = offset
13016 length = this.length
13017 offset = 0
13018 // Buffer#write(string, offset[, length][, encoding])
13019 } else if (isFinite(offset)) {
13020 offset = offset >>> 0
13021 if (isFinite(length)) {
13022 length = length >>> 0
13023 if (encoding === undefined) encoding = 'utf8'
13024 } else {
13025 encoding = length
13026 length = undefined
13027 }
13028 } else {
13029 throw new Error(
13030 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
13031 )
13032 }
13033
13034 var remaining = this.length - offset
13035 if (length === undefined || length > remaining) length = remaining
13036
13037 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
13038 throw new RangeError('Attempt to write outside buffer bounds')
13039 }
13040
13041 if (!encoding) encoding = 'utf8'
13042
13043 var loweredCase = false
13044 for (;;) {
13045 switch (encoding) {
13046 case 'hex':
13047 return hexWrite(this, string, offset, length)
13048
13049 case 'utf8':
13050 case 'utf-8':
13051 return utf8Write(this, string, offset, length)
13052
13053 case 'ascii':
13054 return asciiWrite(this, string, offset, length)
13055
13056 case 'latin1':
13057 case 'binary':
13058 return latin1Write(this, string, offset, length)
13059
13060 case 'base64':
13061 // Warning: maxLength not taken into account in base64Write
13062 return base64Write(this, string, offset, length)
13063
13064 case 'ucs2':
13065 case 'ucs-2':
13066 case 'utf16le':
13067 case 'utf-16le':
13068 return ucs2Write(this, string, offset, length)
13069
13070 default:
13071 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
13072 encoding = ('' + encoding).toLowerCase()
13073 loweredCase = true
13074 }
13075 }
13076}
13077
13078Buffer.prototype.toJSON = function toJSON () {
13079 return {
13080 type: 'Buffer',
13081 data: Array.prototype.slice.call(this._arr || this, 0)
13082 }
13083}
13084
13085function base64Slice (buf, start, end) {
13086 if (start === 0 && end === buf.length) {
13087 return base64.fromByteArray(buf)
13088 } else {
13089 return base64.fromByteArray(buf.slice(start, end))
13090 }
13091}
13092
13093function utf8Slice (buf, start, end) {
13094 end = Math.min(buf.length, end)
13095 var res = []
13096
13097 var i = start
13098 while (i < end) {
13099 var firstByte = buf[i]
13100 var codePoint = null
13101 var bytesPerSequence = (firstByte > 0xEF) ? 4
13102 : (firstByte > 0xDF) ? 3
13103 : (firstByte > 0xBF) ? 2
13104 : 1
13105
13106 if (i + bytesPerSequence <= end) {
13107 var secondByte, thirdByte, fourthByte, tempCodePoint
13108
13109 switch (bytesPerSequence) {
13110 case 1:
13111 if (firstByte < 0x80) {
13112 codePoint = firstByte
13113 }
13114 break
13115 case 2:
13116 secondByte = buf[i + 1]
13117 if ((secondByte & 0xC0) === 0x80) {
13118 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
13119 if (tempCodePoint > 0x7F) {
13120 codePoint = tempCodePoint
13121 }
13122 }
13123 break
13124 case 3:
13125 secondByte = buf[i + 1]
13126 thirdByte = buf[i + 2]
13127 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
13128 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
13129 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
13130 codePoint = tempCodePoint
13131 }
13132 }
13133 break
13134 case 4:
13135 secondByte = buf[i + 1]
13136 thirdByte = buf[i + 2]
13137 fourthByte = buf[i + 3]
13138 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
13139 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
13140 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
13141 codePoint = tempCodePoint
13142 }
13143 }
13144 }
13145 }
13146
13147 if (codePoint === null) {
13148 // we did not generate a valid codePoint so insert a
13149 // replacement char (U+FFFD) and advance only 1 byte
13150 codePoint = 0xFFFD
13151 bytesPerSequence = 1
13152 } else if (codePoint > 0xFFFF) {
13153 // encode to utf16 (surrogate pair dance)
13154 codePoint -= 0x10000
13155 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
13156 codePoint = 0xDC00 | codePoint & 0x3FF
13157 }
13158
13159 res.push(codePoint)
13160 i += bytesPerSequence
13161 }
13162
13163 return decodeCodePointsArray(res)
13164}
13165
13166// Based on http://stackoverflow.com/a/22747272/680742, the browser with
13167// the lowest limit is Chrome, with 0x10000 args.
13168// We go 1 magnitude less, for safety
13169var MAX_ARGUMENTS_LENGTH = 0x1000
13170
13171function decodeCodePointsArray (codePoints) {
13172 var len = codePoints.length
13173 if (len <= MAX_ARGUMENTS_LENGTH) {
13174 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
13175 }
13176
13177 // Decode in chunks to avoid "call stack size exceeded".
13178 var res = ''
13179 var i = 0
13180 while (i < len) {
13181 res += String.fromCharCode.apply(
13182 String,
13183 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
13184 )
13185 }
13186 return res
13187}
13188
13189function asciiSlice (buf, start, end) {
13190 var ret = ''
13191 end = Math.min(buf.length, end)
13192
13193 for (var i = start; i < end; ++i) {
13194 ret += String.fromCharCode(buf[i] & 0x7F)
13195 }
13196 return ret
13197}
13198
13199function latin1Slice (buf, start, end) {
13200 var ret = ''
13201 end = Math.min(buf.length, end)
13202
13203 for (var i = start; i < end; ++i) {
13204 ret += String.fromCharCode(buf[i])
13205 }
13206 return ret
13207}
13208
13209function hexSlice (buf, start, end) {
13210 var len = buf.length
13211
13212 if (!start || start < 0) start = 0
13213 if (!end || end < 0 || end > len) end = len
13214
13215 var out = ''
13216 for (var i = start; i < end; ++i) {
13217 out += toHex(buf[i])
13218 }
13219 return out
13220}
13221
13222function utf16leSlice (buf, start, end) {
13223 var bytes = buf.slice(start, end)
13224 var res = ''
13225 for (var i = 0; i < bytes.length; i += 2) {
13226 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
13227 }
13228 return res
13229}
13230
13231Buffer.prototype.slice = function slice (start, end) {
13232 var len = this.length
13233 start = ~~start
13234 end = end === undefined ? len : ~~end
13235
13236 if (start < 0) {
13237 start += len
13238 if (start < 0) start = 0
13239 } else if (start > len) {
13240 start = len
13241 }
13242
13243 if (end < 0) {
13244 end += len
13245 if (end < 0) end = 0
13246 } else if (end > len) {
13247 end = len
13248 }
13249
13250 if (end < start) end = start
13251
13252 var newBuf = this.subarray(start, end)
13253 // Return an augmented `Uint8Array` instance
13254 Object.setPrototypeOf(newBuf, Buffer.prototype)
13255
13256 return newBuf
13257}
13258
13259/*
13260 * Need to make sure that buffer isn't trying to write out of bounds.
13261 */
13262function checkOffset (offset, ext, length) {
13263 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
13264 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
13265}
13266
13267Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
13268 offset = offset >>> 0
13269 byteLength = byteLength >>> 0
13270 if (!noAssert) checkOffset(offset, byteLength, this.length)
13271
13272 var val = this[offset]
13273 var mul = 1
13274 var i = 0
13275 while (++i < byteLength && (mul *= 0x100)) {
13276 val += this[offset + i] * mul
13277 }
13278
13279 return val
13280}
13281
13282Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
13283 offset = offset >>> 0
13284 byteLength = byteLength >>> 0
13285 if (!noAssert) {
13286 checkOffset(offset, byteLength, this.length)
13287 }
13288
13289 var val = this[offset + --byteLength]
13290 var mul = 1
13291 while (byteLength > 0 && (mul *= 0x100)) {
13292 val += this[offset + --byteLength] * mul
13293 }
13294
13295 return val
13296}
13297
13298Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
13299 offset = offset >>> 0
13300 if (!noAssert) checkOffset(offset, 1, this.length)
13301 return this[offset]
13302}
13303
13304Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
13305 offset = offset >>> 0
13306 if (!noAssert) checkOffset(offset, 2, this.length)
13307 return this[offset] | (this[offset + 1] << 8)
13308}
13309
13310Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
13311 offset = offset >>> 0
13312 if (!noAssert) checkOffset(offset, 2, this.length)
13313 return (this[offset] << 8) | this[offset + 1]
13314}
13315
13316Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
13317 offset = offset >>> 0
13318 if (!noAssert) checkOffset(offset, 4, this.length)
13319
13320 return ((this[offset]) |
13321 (this[offset + 1] << 8) |
13322 (this[offset + 2] << 16)) +
13323 (this[offset + 3] * 0x1000000)
13324}
13325
13326Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
13327 offset = offset >>> 0
13328 if (!noAssert) checkOffset(offset, 4, this.length)
13329
13330 return (this[offset] * 0x1000000) +
13331 ((this[offset + 1] << 16) |
13332 (this[offset + 2] << 8) |
13333 this[offset + 3])
13334}
13335
13336Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
13337 offset = offset >>> 0
13338 byteLength = byteLength >>> 0
13339 if (!noAssert) checkOffset(offset, byteLength, this.length)
13340
13341 var val = this[offset]
13342 var mul = 1
13343 var i = 0
13344 while (++i < byteLength && (mul *= 0x100)) {
13345 val += this[offset + i] * mul
13346 }
13347 mul *= 0x80
13348
13349 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
13350
13351 return val
13352}
13353
13354Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
13355 offset = offset >>> 0
13356 byteLength = byteLength >>> 0
13357 if (!noAssert) checkOffset(offset, byteLength, this.length)
13358
13359 var i = byteLength
13360 var mul = 1
13361 var val = this[offset + --i]
13362 while (i > 0 && (mul *= 0x100)) {
13363 val += this[offset + --i] * mul
13364 }
13365 mul *= 0x80
13366
13367 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
13368
13369 return val
13370}
13371
13372Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
13373 offset = offset >>> 0
13374 if (!noAssert) checkOffset(offset, 1, this.length)
13375 if (!(this[offset] & 0x80)) return (this[offset])
13376 return ((0xff - this[offset] + 1) * -1)
13377}
13378
13379Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
13380 offset = offset >>> 0
13381 if (!noAssert) checkOffset(offset, 2, this.length)
13382 var val = this[offset] | (this[offset + 1] << 8)
13383 return (val & 0x8000) ? val | 0xFFFF0000 : val
13384}
13385
13386Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
13387 offset = offset >>> 0
13388 if (!noAssert) checkOffset(offset, 2, this.length)
13389 var val = this[offset + 1] | (this[offset] << 8)
13390 return (val & 0x8000) ? val | 0xFFFF0000 : val
13391}
13392
13393Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
13394 offset = offset >>> 0
13395 if (!noAssert) checkOffset(offset, 4, this.length)
13396
13397 return (this[offset]) |
13398 (this[offset + 1] << 8) |
13399 (this[offset + 2] << 16) |
13400 (this[offset + 3] << 24)
13401}
13402
13403Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
13404 offset = offset >>> 0
13405 if (!noAssert) checkOffset(offset, 4, this.length)
13406
13407 return (this[offset] << 24) |
13408 (this[offset + 1] << 16) |
13409 (this[offset + 2] << 8) |
13410 (this[offset + 3])
13411}
13412
13413Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
13414 offset = offset >>> 0
13415 if (!noAssert) checkOffset(offset, 4, this.length)
13416 return ieee754.read(this, offset, true, 23, 4)
13417}
13418
13419Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
13420 offset = offset >>> 0
13421 if (!noAssert) checkOffset(offset, 4, this.length)
13422 return ieee754.read(this, offset, false, 23, 4)
13423}
13424
13425Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
13426 offset = offset >>> 0
13427 if (!noAssert) checkOffset(offset, 8, this.length)
13428 return ieee754.read(this, offset, true, 52, 8)
13429}
13430
13431Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
13432 offset = offset >>> 0
13433 if (!noAssert) checkOffset(offset, 8, this.length)
13434 return ieee754.read(this, offset, false, 52, 8)
13435}
13436
13437function checkInt (buf, value, offset, ext, max, min) {
13438 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
13439 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
13440 if (offset + ext > buf.length) throw new RangeError('Index out of range')
13441}
13442
13443Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
13444 value = +value
13445 offset = offset >>> 0
13446 byteLength = byteLength >>> 0
13447 if (!noAssert) {
13448 var maxBytes = Math.pow(2, 8 * byteLength) - 1
13449 checkInt(this, value, offset, byteLength, maxBytes, 0)
13450 }
13451
13452 var mul = 1
13453 var i = 0
13454 this[offset] = value & 0xFF
13455 while (++i < byteLength && (mul *= 0x100)) {
13456 this[offset + i] = (value / mul) & 0xFF
13457 }
13458
13459 return offset + byteLength
13460}
13461
13462Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
13463 value = +value
13464 offset = offset >>> 0
13465 byteLength = byteLength >>> 0
13466 if (!noAssert) {
13467 var maxBytes = Math.pow(2, 8 * byteLength) - 1
13468 checkInt(this, value, offset, byteLength, maxBytes, 0)
13469 }
13470
13471 var i = byteLength - 1
13472 var mul = 1
13473 this[offset + i] = value & 0xFF
13474 while (--i >= 0 && (mul *= 0x100)) {
13475 this[offset + i] = (value / mul) & 0xFF
13476 }
13477
13478 return offset + byteLength
13479}
13480
13481Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
13482 value = +value
13483 offset = offset >>> 0
13484 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
13485 this[offset] = (value & 0xff)
13486 return offset + 1
13487}
13488
13489Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
13490 value = +value
13491 offset = offset >>> 0
13492 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
13493 this[offset] = (value & 0xff)
13494 this[offset + 1] = (value >>> 8)
13495 return offset + 2
13496}
13497
13498Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
13499 value = +value
13500 offset = offset >>> 0
13501 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
13502 this[offset] = (value >>> 8)
13503 this[offset + 1] = (value & 0xff)
13504 return offset + 2
13505}
13506
13507Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
13508 value = +value
13509 offset = offset >>> 0
13510 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
13511 this[offset + 3] = (value >>> 24)
13512 this[offset + 2] = (value >>> 16)
13513 this[offset + 1] = (value >>> 8)
13514 this[offset] = (value & 0xff)
13515 return offset + 4
13516}
13517
13518Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
13519 value = +value
13520 offset = offset >>> 0
13521 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
13522 this[offset] = (value >>> 24)
13523 this[offset + 1] = (value >>> 16)
13524 this[offset + 2] = (value >>> 8)
13525 this[offset + 3] = (value & 0xff)
13526 return offset + 4
13527}
13528
13529Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
13530 value = +value
13531 offset = offset >>> 0
13532 if (!noAssert) {
13533 var limit = Math.pow(2, (8 * byteLength) - 1)
13534
13535 checkInt(this, value, offset, byteLength, limit - 1, -limit)
13536 }
13537
13538 var i = 0
13539 var mul = 1
13540 var sub = 0
13541 this[offset] = value & 0xFF
13542 while (++i < byteLength && (mul *= 0x100)) {
13543 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
13544 sub = 1
13545 }
13546 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
13547 }
13548
13549 return offset + byteLength
13550}
13551
13552Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
13553 value = +value
13554 offset = offset >>> 0
13555 if (!noAssert) {
13556 var limit = Math.pow(2, (8 * byteLength) - 1)
13557
13558 checkInt(this, value, offset, byteLength, limit - 1, -limit)
13559 }
13560
13561 var i = byteLength - 1
13562 var mul = 1
13563 var sub = 0
13564 this[offset + i] = value & 0xFF
13565 while (--i >= 0 && (mul *= 0x100)) {
13566 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
13567 sub = 1
13568 }
13569 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
13570 }
13571
13572 return offset + byteLength
13573}
13574
13575Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
13576 value = +value
13577 offset = offset >>> 0
13578 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
13579 if (value < 0) value = 0xff + value + 1
13580 this[offset] = (value & 0xff)
13581 return offset + 1
13582}
13583
13584Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
13585 value = +value
13586 offset = offset >>> 0
13587 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
13588 this[offset] = (value & 0xff)
13589 this[offset + 1] = (value >>> 8)
13590 return offset + 2
13591}
13592
13593Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
13594 value = +value
13595 offset = offset >>> 0
13596 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
13597 this[offset] = (value >>> 8)
13598 this[offset + 1] = (value & 0xff)
13599 return offset + 2
13600}
13601
13602Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
13603 value = +value
13604 offset = offset >>> 0
13605 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
13606 this[offset] = (value & 0xff)
13607 this[offset + 1] = (value >>> 8)
13608 this[offset + 2] = (value >>> 16)
13609 this[offset + 3] = (value >>> 24)
13610 return offset + 4
13611}
13612
13613Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
13614 value = +value
13615 offset = offset >>> 0
13616 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
13617 if (value < 0) value = 0xffffffff + value + 1
13618 this[offset] = (value >>> 24)
13619 this[offset + 1] = (value >>> 16)
13620 this[offset + 2] = (value >>> 8)
13621 this[offset + 3] = (value & 0xff)
13622 return offset + 4
13623}
13624
13625function checkIEEE754 (buf, value, offset, ext, max, min) {
13626 if (offset + ext > buf.length) throw new RangeError('Index out of range')
13627 if (offset < 0) throw new RangeError('Index out of range')
13628}
13629
13630function writeFloat (buf, value, offset, littleEndian, noAssert) {
13631 value = +value
13632 offset = offset >>> 0
13633 if (!noAssert) {
13634 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
13635 }
13636 ieee754.write(buf, value, offset, littleEndian, 23, 4)
13637 return offset + 4
13638}
13639
13640Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
13641 return writeFloat(this, value, offset, true, noAssert)
13642}
13643
13644Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
13645 return writeFloat(this, value, offset, false, noAssert)
13646}
13647
13648function writeDouble (buf, value, offset, littleEndian, noAssert) {
13649 value = +value
13650 offset = offset >>> 0
13651 if (!noAssert) {
13652 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
13653 }
13654 ieee754.write(buf, value, offset, littleEndian, 52, 8)
13655 return offset + 8
13656}
13657
13658Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
13659 return writeDouble(this, value, offset, true, noAssert)
13660}
13661
13662Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
13663 return writeDouble(this, value, offset, false, noAssert)
13664}
13665
13666// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
13667Buffer.prototype.copy = function copy (target, targetStart, start, end) {
13668 if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
13669 if (!start) start = 0
13670 if (!end && end !== 0) end = this.length
13671 if (targetStart >= target.length) targetStart = target.length
13672 if (!targetStart) targetStart = 0
13673 if (end > 0 && end < start) end = start
13674
13675 // Copy 0 bytes; we're done
13676 if (end === start) return 0
13677 if (target.length === 0 || this.length === 0) return 0
13678
13679 // Fatal error conditions
13680 if (targetStart < 0) {
13681 throw new RangeError('targetStart out of bounds')
13682 }
13683 if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
13684 if (end < 0) throw new RangeError('sourceEnd out of bounds')
13685
13686 // Are we oob?
13687 if (end > this.length) end = this.length
13688 if (target.length - targetStart < end - start) {
13689 end = target.length - targetStart + start
13690 }
13691
13692 var len = end - start
13693
13694 if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
13695 // Use built-in when available, missing from IE11
13696 this.copyWithin(targetStart, start, end)
13697 } else if (this === target && start < targetStart && targetStart < end) {
13698 // descending copy from end
13699 for (var i = len - 1; i >= 0; --i) {
13700 target[i + targetStart] = this[i + start]
13701 }
13702 } else {
13703 Uint8Array.prototype.set.call(
13704 target,
13705 this.subarray(start, end),
13706 targetStart
13707 )
13708 }
13709
13710 return len
13711}
13712
13713// Usage:
13714// buffer.fill(number[, offset[, end]])
13715// buffer.fill(buffer[, offset[, end]])
13716// buffer.fill(string[, offset[, end]][, encoding])
13717Buffer.prototype.fill = function fill (val, start, end, encoding) {
13718 // Handle string cases:
13719 if (typeof val === 'string') {
13720 if (typeof start === 'string') {
13721 encoding = start
13722 start = 0
13723 end = this.length
13724 } else if (typeof end === 'string') {
13725 encoding = end
13726 end = this.length
13727 }
13728 if (encoding !== undefined && typeof encoding !== 'string') {
13729 throw new TypeError('encoding must be a string')
13730 }
13731 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
13732 throw new TypeError('Unknown encoding: ' + encoding)
13733 }
13734 if (val.length === 1) {
13735 var code = val.charCodeAt(0)
13736 if ((encoding === 'utf8' && code < 128) ||
13737 encoding === 'latin1') {
13738 // Fast path: If `val` fits into a single byte, use that numeric value.
13739 val = code
13740 }
13741 }
13742 } else if (typeof val === 'number') {
13743 val = val & 255
13744 } else if (typeof val === 'boolean') {
13745 val = Number(val)
13746 }
13747
13748 // Invalid ranges are not set to a default, so can range check early.
13749 if (start < 0 || this.length < start || this.length < end) {
13750 throw new RangeError('Out of range index')
13751 }
13752
13753 if (end <= start) {
13754 return this
13755 }
13756
13757 start = start >>> 0
13758 end = end === undefined ? this.length : end >>> 0
13759
13760 if (!val) val = 0
13761
13762 var i
13763 if (typeof val === 'number') {
13764 for (i = start; i < end; ++i) {
13765 this[i] = val
13766 }
13767 } else {
13768 var bytes = Buffer.isBuffer(val)
13769 ? val
13770 : Buffer.from(val, encoding)
13771 var len = bytes.length
13772 if (len === 0) {
13773 throw new TypeError('The value "' + val +
13774 '" is invalid for argument "value"')
13775 }
13776 for (i = 0; i < end - start; ++i) {
13777 this[i + start] = bytes[i % len]
13778 }
13779 }
13780
13781 return this
13782}
13783
13784// HELPER FUNCTIONS
13785// ================
13786
13787var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
13788
13789function base64clean (str) {
13790 // Node takes equal signs as end of the Base64 encoding
13791 str = str.split('=')[0]
13792 // Node strips out invalid characters like \n and \t from the string, base64-js does not
13793 str = str.trim().replace(INVALID_BASE64_RE, '')
13794 // Node converts strings with length < 2 to ''
13795 if (str.length < 2) return ''
13796 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
13797 while (str.length % 4 !== 0) {
13798 str = str + '='
13799 }
13800 return str
13801}
13802
13803function toHex (n) {
13804 if (n < 16) return '0' + n.toString(16)
13805 return n.toString(16)
13806}
13807
13808function utf8ToBytes (string, units) {
13809 units = units || Infinity
13810 var codePoint
13811 var length = string.length
13812 var leadSurrogate = null
13813 var bytes = []
13814
13815 for (var i = 0; i < length; ++i) {
13816 codePoint = string.charCodeAt(i)
13817
13818 // is surrogate component
13819 if (codePoint > 0xD7FF && codePoint < 0xE000) {
13820 // last char was a lead
13821 if (!leadSurrogate) {
13822 // no lead yet
13823 if (codePoint > 0xDBFF) {
13824 // unexpected trail
13825 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
13826 continue
13827 } else if (i + 1 === length) {
13828 // unpaired lead
13829 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
13830 continue
13831 }
13832
13833 // valid lead
13834 leadSurrogate = codePoint
13835
13836 continue
13837 }
13838
13839 // 2 leads in a row
13840 if (codePoint < 0xDC00) {
13841 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
13842 leadSurrogate = codePoint
13843 continue
13844 }
13845
13846 // valid surrogate pair
13847 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
13848 } else if (leadSurrogate) {
13849 // valid bmp char, but last char was a lead
13850 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
13851 }
13852
13853 leadSurrogate = null
13854
13855 // encode utf8
13856 if (codePoint < 0x80) {
13857 if ((units -= 1) < 0) break
13858 bytes.push(codePoint)
13859 } else if (codePoint < 0x800) {
13860 if ((units -= 2) < 0) break
13861 bytes.push(
13862 codePoint >> 0x6 | 0xC0,
13863 codePoint & 0x3F | 0x80
13864 )
13865 } else if (codePoint < 0x10000) {
13866 if ((units -= 3) < 0) break
13867 bytes.push(
13868 codePoint >> 0xC | 0xE0,
13869 codePoint >> 0x6 & 0x3F | 0x80,
13870 codePoint & 0x3F | 0x80
13871 )
13872 } else if (codePoint < 0x110000) {
13873 if ((units -= 4) < 0) break
13874 bytes.push(
13875 codePoint >> 0x12 | 0xF0,
13876 codePoint >> 0xC & 0x3F | 0x80,
13877 codePoint >> 0x6 & 0x3F | 0x80,
13878 codePoint & 0x3F | 0x80
13879 )
13880 } else {
13881 throw new Error('Invalid code point')
13882 }
13883 }
13884
13885 return bytes
13886}
13887
13888function asciiToBytes (str) {
13889 var byteArray = []
13890 for (var i = 0; i < str.length; ++i) {
13891 // Node's code seems to be doing this and not & 0x7F..
13892 byteArray.push(str.charCodeAt(i) & 0xFF)
13893 }
13894 return byteArray
13895}
13896
13897function utf16leToBytes (str, units) {
13898 var c, hi, lo
13899 var byteArray = []
13900 for (var i = 0; i < str.length; ++i) {
13901 if ((units -= 2) < 0) break
13902
13903 c = str.charCodeAt(i)
13904 hi = c >> 8
13905 lo = c % 256
13906 byteArray.push(lo)
13907 byteArray.push(hi)
13908 }
13909
13910 return byteArray
13911}
13912
13913function base64ToBytes (str) {
13914 return base64.toByteArray(base64clean(str))
13915}
13916
13917function blitBuffer (src, dst, offset, length) {
13918 for (var i = 0; i < length; ++i) {
13919 if ((i + offset >= dst.length) || (i >= src.length)) break
13920 dst[i + offset] = src[i]
13921 }
13922 return i
13923}
13924
13925// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
13926// the `instanceof` check but they should be treated as of that type.
13927// See: https://github.com/feross/buffer/issues/166
13928function isInstance (obj, type) {
13929 return obj instanceof type ||
13930 (obj != null && obj.constructor != null && obj.constructor.name != null &&
13931 obj.constructor.name === type.name)
13932}
13933function numberIsNaN (obj) {
13934 // For IE11 support
13935 return obj !== obj // eslint-disable-line no-self-compare
13936}
13937
13938}).call(this,require("buffer").Buffer)
13939},{"base64-js":94,"buffer":96,"ieee754":99}],97:[function(require,module,exports){
13940(function (Buffer){
13941// Copyright Joyent, Inc. and other Node contributors.
13942//
13943// Permission is hereby granted, free of charge, to any person obtaining a
13944// copy of this software and associated documentation files (the
13945// "Software"), to deal in the Software without restriction, including
13946// without limitation the rights to use, copy, modify, merge, publish,
13947// distribute, sublicense, and/or sell copies of the Software, and to permit
13948// persons to whom the Software is furnished to do so, subject to the
13949// following conditions:
13950//
13951// The above copyright notice and this permission notice shall be included
13952// in all copies or substantial portions of the Software.
13953//
13954// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13955// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13956// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
13957// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
13958// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
13959// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
13960// USE OR OTHER DEALINGS IN THE SOFTWARE.
13961
13962// NOTE: These type checking functions intentionally don't use `instanceof`
13963// because it is fragile and can be easily faked with `Object.create()`.
13964
13965function isArray(arg) {
13966 if (Array.isArray) {
13967 return Array.isArray(arg);
13968 }
13969 return objectToString(arg) === '[object Array]';
13970}
13971exports.isArray = isArray;
13972
13973function isBoolean(arg) {
13974 return typeof arg === 'boolean';
13975}
13976exports.isBoolean = isBoolean;
13977
13978function isNull(arg) {
13979 return arg === null;
13980}
13981exports.isNull = isNull;
13982
13983function isNullOrUndefined(arg) {
13984 return arg == null;
13985}
13986exports.isNullOrUndefined = isNullOrUndefined;
13987
13988function isNumber(arg) {
13989 return typeof arg === 'number';
13990}
13991exports.isNumber = isNumber;
13992
13993function isString(arg) {
13994 return typeof arg === 'string';
13995}
13996exports.isString = isString;
13997
13998function isSymbol(arg) {
13999 return typeof arg === 'symbol';
14000}
14001exports.isSymbol = isSymbol;
14002
14003function isUndefined(arg) {
14004 return arg === void 0;
14005}
14006exports.isUndefined = isUndefined;
14007
14008function isRegExp(re) {
14009 return objectToString(re) === '[object RegExp]';
14010}
14011exports.isRegExp = isRegExp;
14012
14013function isObject(arg) {
14014 return typeof arg === 'object' && arg !== null;
14015}
14016exports.isObject = isObject;
14017
14018function isDate(d) {
14019 return objectToString(d) === '[object Date]';
14020}
14021exports.isDate = isDate;
14022
14023function isError(e) {
14024 return (objectToString(e) === '[object Error]' || e instanceof Error);
14025}
14026exports.isError = isError;
14027
14028function isFunction(arg) {
14029 return typeof arg === 'function';
14030}
14031exports.isFunction = isFunction;
14032
14033function isPrimitive(arg) {
14034 return arg === null ||
14035 typeof arg === 'boolean' ||
14036 typeof arg === 'number' ||
14037 typeof arg === 'string' ||
14038 typeof arg === 'symbol' || // ES6 symbol
14039 typeof arg === 'undefined';
14040}
14041exports.isPrimitive = isPrimitive;
14042
14043exports.isBuffer = Buffer.isBuffer;
14044
14045function objectToString(o) {
14046 return Object.prototype.toString.call(o);
14047}
14048
14049}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
14050},{"../../is-buffer/index.js":101}],98:[function(require,module,exports){
14051// Copyright Joyent, Inc. and other Node contributors.
14052//
14053// Permission is hereby granted, free of charge, to any person obtaining a
14054// copy of this software and associated documentation files (the
14055// "Software"), to deal in the Software without restriction, including
14056// without limitation the rights to use, copy, modify, merge, publish,
14057// distribute, sublicense, and/or sell copies of the Software, and to permit
14058// persons to whom the Software is furnished to do so, subject to the
14059// following conditions:
14060//
14061// The above copyright notice and this permission notice shall be included
14062// in all copies or substantial portions of the Software.
14063//
14064// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14065// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14066// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
14067// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
14068// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14069// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
14070// USE OR OTHER DEALINGS IN THE SOFTWARE.
14071
14072var objectCreate = Object.create || objectCreatePolyfill
14073var objectKeys = Object.keys || objectKeysPolyfill
14074var bind = Function.prototype.bind || functionBindPolyfill
14075
14076function EventEmitter() {
14077 if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
14078 this._events = objectCreate(null);
14079 this._eventsCount = 0;
14080 }
14081
14082 this._maxListeners = this._maxListeners || undefined;
14083}
14084module.exports = EventEmitter;
14085
14086// Backwards-compat with node 0.10.x
14087EventEmitter.EventEmitter = EventEmitter;
14088
14089EventEmitter.prototype._events = undefined;
14090EventEmitter.prototype._maxListeners = undefined;
14091
14092// By default EventEmitters will print a warning if more than 10 listeners are
14093// added to it. This is a useful default which helps finding memory leaks.
14094var defaultMaxListeners = 10;
14095
14096var hasDefineProperty;
14097try {
14098 var o = {};
14099 if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
14100 hasDefineProperty = o.x === 0;
14101} catch (err) { hasDefineProperty = false }
14102if (hasDefineProperty) {
14103 Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
14104 enumerable: true,
14105 get: function() {
14106 return defaultMaxListeners;
14107 },
14108 set: function(arg) {
14109 // check whether the input is a positive number (whose value is zero or
14110 // greater and not a NaN).
14111 if (typeof arg !== 'number' || arg < 0 || arg !== arg)
14112 throw new TypeError('"defaultMaxListeners" must be a positive number');
14113 defaultMaxListeners = arg;
14114 }
14115 });
14116} else {
14117 EventEmitter.defaultMaxListeners = defaultMaxListeners;
14118}
14119
14120// Obviously not all Emitters should be limited to 10. This function allows
14121// that to be increased. Set to zero for unlimited.
14122EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
14123 if (typeof n !== 'number' || n < 0 || isNaN(n))
14124 throw new TypeError('"n" argument must be a positive number');
14125 this._maxListeners = n;
14126 return this;
14127};
14128
14129function $getMaxListeners(that) {
14130 if (that._maxListeners === undefined)
14131 return EventEmitter.defaultMaxListeners;
14132 return that._maxListeners;
14133}
14134
14135EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
14136 return $getMaxListeners(this);
14137};
14138
14139// These standalone emit* functions are used to optimize calling of event
14140// handlers for fast cases because emit() itself often has a variable number of
14141// arguments and can be deoptimized because of that. These functions always have
14142// the same number of arguments and thus do not get deoptimized, so the code
14143// inside them can execute faster.
14144function emitNone(handler, isFn, self) {
14145 if (isFn)
14146 handler.call(self);
14147 else {
14148 var len = handler.length;
14149 var listeners = arrayClone(handler, len);
14150 for (var i = 0; i < len; ++i)
14151 listeners[i].call(self);
14152 }
14153}
14154function emitOne(handler, isFn, self, arg1) {
14155 if (isFn)
14156 handler.call(self, arg1);
14157 else {
14158 var len = handler.length;
14159 var listeners = arrayClone(handler, len);
14160 for (var i = 0; i < len; ++i)
14161 listeners[i].call(self, arg1);
14162 }
14163}
14164function emitTwo(handler, isFn, self, arg1, arg2) {
14165 if (isFn)
14166 handler.call(self, arg1, arg2);
14167 else {
14168 var len = handler.length;
14169 var listeners = arrayClone(handler, len);
14170 for (var i = 0; i < len; ++i)
14171 listeners[i].call(self, arg1, arg2);
14172 }
14173}
14174function emitThree(handler, isFn, self, arg1, arg2, arg3) {
14175 if (isFn)
14176 handler.call(self, arg1, arg2, arg3);
14177 else {
14178 var len = handler.length;
14179 var listeners = arrayClone(handler, len);
14180 for (var i = 0; i < len; ++i)
14181 listeners[i].call(self, arg1, arg2, arg3);
14182 }
14183}
14184
14185function emitMany(handler, isFn, self, args) {
14186 if (isFn)
14187 handler.apply(self, args);
14188 else {
14189 var len = handler.length;
14190 var listeners = arrayClone(handler, len);
14191 for (var i = 0; i < len; ++i)
14192 listeners[i].apply(self, args);
14193 }
14194}
14195
14196EventEmitter.prototype.emit = function emit(type) {
14197 var er, handler, len, args, i, events;
14198 var doError = (type === 'error');
14199
14200 events = this._events;
14201 if (events)
14202 doError = (doError && events.error == null);
14203 else if (!doError)
14204 return false;
14205
14206 // If there is no 'error' event listener then throw.
14207 if (doError) {
14208 if (arguments.length > 1)
14209 er = arguments[1];
14210 if (er instanceof Error) {
14211 throw er; // Unhandled 'error' event
14212 } else {
14213 // At least give some kind of context to the user
14214 var err = new Error('Unhandled "error" event. (' + er + ')');
14215 err.context = er;
14216 throw err;
14217 }
14218 return false;
14219 }
14220
14221 handler = events[type];
14222
14223 if (!handler)
14224 return false;
14225
14226 var isFn = typeof handler === 'function';
14227 len = arguments.length;
14228 switch (len) {
14229 // fast cases
14230 case 1:
14231 emitNone(handler, isFn, this);
14232 break;
14233 case 2:
14234 emitOne(handler, isFn, this, arguments[1]);
14235 break;
14236 case 3:
14237 emitTwo(handler, isFn, this, arguments[1], arguments[2]);
14238 break;
14239 case 4:
14240 emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
14241 break;
14242 // slower
14243 default:
14244 args = new Array(len - 1);
14245 for (i = 1; i < len; i++)
14246 args[i - 1] = arguments[i];
14247 emitMany(handler, isFn, this, args);
14248 }
14249
14250 return true;
14251};
14252
14253function _addListener(target, type, listener, prepend) {
14254 var m;
14255 var events;
14256 var existing;
14257
14258 if (typeof listener !== 'function')
14259 throw new TypeError('"listener" argument must be a function');
14260
14261 events = target._events;
14262 if (!events) {
14263 events = target._events = objectCreate(null);
14264 target._eventsCount = 0;
14265 } else {
14266 // To avoid recursion in the case that type === "newListener"! Before
14267 // adding it to the listeners, first emit "newListener".
14268 if (events.newListener) {
14269 target.emit('newListener', type,
14270 listener.listener ? listener.listener : listener);
14271
14272 // Re-assign `events` because a newListener handler could have caused the
14273 // this._events to be assigned to a new object
14274 events = target._events;
14275 }
14276 existing = events[type];
14277 }
14278
14279 if (!existing) {
14280 // Optimize the case of one listener. Don't need the extra array object.
14281 existing = events[type] = listener;
14282 ++target._eventsCount;
14283 } else {
14284 if (typeof existing === 'function') {
14285 // Adding the second element, need to change to array.
14286 existing = events[type] =
14287 prepend ? [listener, existing] : [existing, listener];
14288 } else {
14289 // If we've already got an array, just append.
14290 if (prepend) {
14291 existing.unshift(listener);
14292 } else {
14293 existing.push(listener);
14294 }
14295 }
14296
14297 // Check for listener leak
14298 if (!existing.warned) {
14299 m = $getMaxListeners(target);
14300 if (m && m > 0 && existing.length > m) {
14301 existing.warned = true;
14302 var w = new Error('Possible EventEmitter memory leak detected. ' +
14303 existing.length + ' "' + String(type) + '" listeners ' +
14304 'added. Use emitter.setMaxListeners() to ' +
14305 'increase limit.');
14306 w.name = 'MaxListenersExceededWarning';
14307 w.emitter = target;
14308 w.type = type;
14309 w.count = existing.length;
14310 if (typeof console === 'object' && console.warn) {
14311 console.warn('%s: %s', w.name, w.message);
14312 }
14313 }
14314 }
14315 }
14316
14317 return target;
14318}
14319
14320EventEmitter.prototype.addListener = function addListener(type, listener) {
14321 return _addListener(this, type, listener, false);
14322};
14323
14324EventEmitter.prototype.on = EventEmitter.prototype.addListener;
14325
14326EventEmitter.prototype.prependListener =
14327 function prependListener(type, listener) {
14328 return _addListener(this, type, listener, true);
14329 };
14330
14331function onceWrapper() {
14332 if (!this.fired) {
14333 this.target.removeListener(this.type, this.wrapFn);
14334 this.fired = true;
14335 switch (arguments.length) {
14336 case 0:
14337 return this.listener.call(this.target);
14338 case 1:
14339 return this.listener.call(this.target, arguments[0]);
14340 case 2:
14341 return this.listener.call(this.target, arguments[0], arguments[1]);
14342 case 3:
14343 return this.listener.call(this.target, arguments[0], arguments[1],
14344 arguments[2]);
14345 default:
14346 var args = new Array(arguments.length);
14347 for (var i = 0; i < args.length; ++i)
14348 args[i] = arguments[i];
14349 this.listener.apply(this.target, args);
14350 }
14351 }
14352}
14353
14354function _onceWrap(target, type, listener) {
14355 var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
14356 var wrapped = bind.call(onceWrapper, state);
14357 wrapped.listener = listener;
14358 state.wrapFn = wrapped;
14359 return wrapped;
14360}
14361
14362EventEmitter.prototype.once = function once(type, listener) {
14363 if (typeof listener !== 'function')
14364 throw new TypeError('"listener" argument must be a function');
14365 this.on(type, _onceWrap(this, type, listener));
14366 return this;
14367};
14368
14369EventEmitter.prototype.prependOnceListener =
14370 function prependOnceListener(type, listener) {
14371 if (typeof listener !== 'function')
14372 throw new TypeError('"listener" argument must be a function');
14373 this.prependListener(type, _onceWrap(this, type, listener));
14374 return this;
14375 };
14376
14377// Emits a 'removeListener' event if and only if the listener was removed.
14378EventEmitter.prototype.removeListener =
14379 function removeListener(type, listener) {
14380 var list, events, position, i, originalListener;
14381
14382 if (typeof listener !== 'function')
14383 throw new TypeError('"listener" argument must be a function');
14384
14385 events = this._events;
14386 if (!events)
14387 return this;
14388
14389 list = events[type];
14390 if (!list)
14391 return this;
14392
14393 if (list === listener || list.listener === listener) {
14394 if (--this._eventsCount === 0)
14395 this._events = objectCreate(null);
14396 else {
14397 delete events[type];
14398 if (events.removeListener)
14399 this.emit('removeListener', type, list.listener || listener);
14400 }
14401 } else if (typeof list !== 'function') {
14402 position = -1;
14403
14404 for (i = list.length - 1; i >= 0; i--) {
14405 if (list[i] === listener || list[i].listener === listener) {
14406 originalListener = list[i].listener;
14407 position = i;
14408 break;
14409 }
14410 }
14411
14412 if (position < 0)
14413 return this;
14414
14415 if (position === 0)
14416 list.shift();
14417 else
14418 spliceOne(list, position);
14419
14420 if (list.length === 1)
14421 events[type] = list[0];
14422
14423 if (events.removeListener)
14424 this.emit('removeListener', type, originalListener || listener);
14425 }
14426
14427 return this;
14428 };
14429
14430EventEmitter.prototype.removeAllListeners =
14431 function removeAllListeners(type) {
14432 var listeners, events, i;
14433
14434 events = this._events;
14435 if (!events)
14436 return this;
14437
14438 // not listening for removeListener, no need to emit
14439 if (!events.removeListener) {
14440 if (arguments.length === 0) {
14441 this._events = objectCreate(null);
14442 this._eventsCount = 0;
14443 } else if (events[type]) {
14444 if (--this._eventsCount === 0)
14445 this._events = objectCreate(null);
14446 else
14447 delete events[type];
14448 }
14449 return this;
14450 }
14451
14452 // emit removeListener for all listeners on all events
14453 if (arguments.length === 0) {
14454 var keys = objectKeys(events);
14455 var key;
14456 for (i = 0; i < keys.length; ++i) {
14457 key = keys[i];
14458 if (key === 'removeListener') continue;
14459 this.removeAllListeners(key);
14460 }
14461 this.removeAllListeners('removeListener');
14462 this._events = objectCreate(null);
14463 this._eventsCount = 0;
14464 return this;
14465 }
14466
14467 listeners = events[type];
14468
14469 if (typeof listeners === 'function') {
14470 this.removeListener(type, listeners);
14471 } else if (listeners) {
14472 // LIFO order
14473 for (i = listeners.length - 1; i >= 0; i--) {
14474 this.removeListener(type, listeners[i]);
14475 }
14476 }
14477
14478 return this;
14479 };
14480
14481function _listeners(target, type, unwrap) {
14482 var events = target._events;
14483
14484 if (!events)
14485 return [];
14486
14487 var evlistener = events[type];
14488 if (!evlistener)
14489 return [];
14490
14491 if (typeof evlistener === 'function')
14492 return unwrap ? [evlistener.listener || evlistener] : [evlistener];
14493
14494 return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
14495}
14496
14497EventEmitter.prototype.listeners = function listeners(type) {
14498 return _listeners(this, type, true);
14499};
14500
14501EventEmitter.prototype.rawListeners = function rawListeners(type) {
14502 return _listeners(this, type, false);
14503};
14504
14505EventEmitter.listenerCount = function(emitter, type) {
14506 if (typeof emitter.listenerCount === 'function') {
14507 return emitter.listenerCount(type);
14508 } else {
14509 return listenerCount.call(emitter, type);
14510 }
14511};
14512
14513EventEmitter.prototype.listenerCount = listenerCount;
14514function listenerCount(type) {
14515 var events = this._events;
14516
14517 if (events) {
14518 var evlistener = events[type];
14519
14520 if (typeof evlistener === 'function') {
14521 return 1;
14522 } else if (evlistener) {
14523 return evlistener.length;
14524 }
14525 }
14526
14527 return 0;
14528}
14529
14530EventEmitter.prototype.eventNames = function eventNames() {
14531 return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
14532};
14533
14534// About 1.5x faster than the two-arg version of Array#splice().
14535function spliceOne(list, index) {
14536 for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
14537 list[i] = list[k];
14538 list.pop();
14539}
14540
14541function arrayClone(arr, n) {
14542 var copy = new Array(n);
14543 for (var i = 0; i < n; ++i)
14544 copy[i] = arr[i];
14545 return copy;
14546}
14547
14548function unwrapListeners(arr) {
14549 var ret = new Array(arr.length);
14550 for (var i = 0; i < ret.length; ++i) {
14551 ret[i] = arr[i].listener || arr[i];
14552 }
14553 return ret;
14554}
14555
14556function objectCreatePolyfill(proto) {
14557 var F = function() {};
14558 F.prototype = proto;
14559 return new F;
14560}
14561function objectKeysPolyfill(obj) {
14562 var keys = [];
14563 for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
14564 keys.push(k);
14565 }
14566 return k;
14567}
14568function functionBindPolyfill(context) {
14569 var fn = this;
14570 return function () {
14571 return fn.apply(context, arguments);
14572 };
14573}
14574
14575},{}],99:[function(require,module,exports){
14576exports.read = function (buffer, offset, isLE, mLen, nBytes) {
14577 var e, m
14578 var eLen = (nBytes * 8) - mLen - 1
14579 var eMax = (1 << eLen) - 1
14580 var eBias = eMax >> 1
14581 var nBits = -7
14582 var i = isLE ? (nBytes - 1) : 0
14583 var d = isLE ? -1 : 1
14584 var s = buffer[offset + i]
14585
14586 i += d
14587
14588 e = s & ((1 << (-nBits)) - 1)
14589 s >>= (-nBits)
14590 nBits += eLen
14591 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
14592
14593 m = e & ((1 << (-nBits)) - 1)
14594 e >>= (-nBits)
14595 nBits += mLen
14596 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
14597
14598 if (e === 0) {
14599 e = 1 - eBias
14600 } else if (e === eMax) {
14601 return m ? NaN : ((s ? -1 : 1) * Infinity)
14602 } else {
14603 m = m + Math.pow(2, mLen)
14604 e = e - eBias
14605 }
14606 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
14607}
14608
14609exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
14610 var e, m, c
14611 var eLen = (nBytes * 8) - mLen - 1
14612 var eMax = (1 << eLen) - 1
14613 var eBias = eMax >> 1
14614 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
14615 var i = isLE ? 0 : (nBytes - 1)
14616 var d = isLE ? 1 : -1
14617 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
14618
14619 value = Math.abs(value)
14620
14621 if (isNaN(value) || value === Infinity) {
14622 m = isNaN(value) ? 1 : 0
14623 e = eMax
14624 } else {
14625 e = Math.floor(Math.log(value) / Math.LN2)
14626 if (value * (c = Math.pow(2, -e)) < 1) {
14627 e--
14628 c *= 2
14629 }
14630 if (e + eBias >= 1) {
14631 value += rt / c
14632 } else {
14633 value += rt * Math.pow(2, 1 - eBias)
14634 }
14635 if (value * c >= 2) {
14636 e++
14637 c /= 2
14638 }
14639
14640 if (e + eBias >= eMax) {
14641 m = 0
14642 e = eMax
14643 } else if (e + eBias >= 1) {
14644 m = ((value * c) - 1) * Math.pow(2, mLen)
14645 e = e + eBias
14646 } else {
14647 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
14648 e = 0
14649 }
14650 }
14651
14652 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
14653
14654 e = (e << mLen) | m
14655 eLen += mLen
14656 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
14657
14658 buffer[offset + i - d] |= s * 128
14659}
14660
14661},{}],100:[function(require,module,exports){
14662arguments[4][32][0].apply(exports,arguments)
14663},{"dup":32}],101:[function(require,module,exports){
14664/*!
14665 * Determine if an object is a Buffer
14666 *
14667 * @author Feross Aboukhadijeh <https://feross.org>
14668 * @license MIT
14669 */
14670
14671// The _isBuffer check is for Safari 5-7 support, because it's missing
14672// Object.prototype.constructor. Remove this eventually
14673module.exports = function (obj) {
14674 return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
14675}
14676
14677function isBuffer (obj) {
14678 return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
14679}
14680
14681// For Node v0.10 support. Remove this eventually.
14682function isSlowBuffer (obj) {
14683 return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
14684}
14685
14686},{}],102:[function(require,module,exports){
14687var toString = {}.toString;
14688
14689module.exports = Array.isArray || function (arr) {
14690 return toString.call(arr) == '[object Array]';
14691};
14692
14693},{}],103:[function(require,module,exports){
14694/*
14695object-assign
14696(c) Sindre Sorhus
14697@license MIT
14698*/
14699
14700'use strict';
14701/* eslint-disable no-unused-vars */
14702var getOwnPropertySymbols = Object.getOwnPropertySymbols;
14703var hasOwnProperty = Object.prototype.hasOwnProperty;
14704var propIsEnumerable = Object.prototype.propertyIsEnumerable;
14705
14706function toObject(val) {
14707 if (val === null || val === undefined) {
14708 throw new TypeError('Object.assign cannot be called with null or undefined');
14709 }
14710
14711 return Object(val);
14712}
14713
14714function shouldUseNative() {
14715 try {
14716 if (!Object.assign) {
14717 return false;
14718 }
14719
14720 // Detect buggy property enumeration order in older V8 versions.
14721
14722 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
14723 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
14724 test1[5] = 'de';
14725 if (Object.getOwnPropertyNames(test1)[0] === '5') {
14726 return false;
14727 }
14728
14729 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
14730 var test2 = {};
14731 for (var i = 0; i < 10; i++) {
14732 test2['_' + String.fromCharCode(i)] = i;
14733 }
14734 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
14735 return test2[n];
14736 });
14737 if (order2.join('') !== '0123456789') {
14738 return false;
14739 }
14740
14741 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
14742 var test3 = {};
14743 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
14744 test3[letter] = letter;
14745 });
14746 if (Object.keys(Object.assign({}, test3)).join('') !==
14747 'abcdefghijklmnopqrst') {
14748 return false;
14749 }
14750
14751 return true;
14752 } catch (err) {
14753 // We don't expect any of the above to throw, but better to be safe.
14754 return false;
14755 }
14756}
14757
14758module.exports = shouldUseNative() ? Object.assign : function (target, source) {
14759 var from;
14760 var to = toObject(target);
14761 var symbols;
14762
14763 for (var s = 1; s < arguments.length; s++) {
14764 from = Object(arguments[s]);
14765
14766 for (var key in from) {
14767 if (hasOwnProperty.call(from, key)) {
14768 to[key] = from[key];
14769 }
14770 }
14771
14772 if (getOwnPropertySymbols) {
14773 symbols = getOwnPropertySymbols(from);
14774 for (var i = 0; i < symbols.length; i++) {
14775 if (propIsEnumerable.call(from, symbols[i])) {
14776 to[symbols[i]] = from[symbols[i]];
14777 }
14778 }
14779 }
14780 }
14781
14782 return to;
14783};
14784
14785},{}],104:[function(require,module,exports){
14786(function (process){
14787'use strict';
14788
14789if (typeof process === 'undefined' ||
14790 !process.version ||
14791 process.version.indexOf('v0.') === 0 ||
14792 process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
14793 module.exports = { nextTick: nextTick };
14794} else {
14795 module.exports = process
14796}
14797
14798function nextTick(fn, arg1, arg2, arg3) {
14799 if (typeof fn !== 'function') {
14800 throw new TypeError('"callback" argument must be a function');
14801 }
14802 var len = arguments.length;
14803 var args, i;
14804 switch (len) {
14805 case 0:
14806 case 1:
14807 return process.nextTick(fn);
14808 case 2:
14809 return process.nextTick(function afterTickOne() {
14810 fn.call(null, arg1);
14811 });
14812 case 3:
14813 return process.nextTick(function afterTickTwo() {
14814 fn.call(null, arg1, arg2);
14815 });
14816 case 4:
14817 return process.nextTick(function afterTickThree() {
14818 fn.call(null, arg1, arg2, arg3);
14819 });
14820 default:
14821 args = new Array(len - 1);
14822 i = 0;
14823 while (i < args.length) {
14824 args[i++] = arguments[i];
14825 }
14826 return process.nextTick(function afterTick() {
14827 fn.apply(null, args);
14828 });
14829 }
14830}
14831
14832
14833}).call(this,require('_process'))
14834},{"_process":105}],105:[function(require,module,exports){
14835// shim for using process in browser
14836var process = module.exports = {};
14837
14838// cached from whatever global is present so that test runners that stub it
14839// don't break things. But we need to wrap it in a try catch in case it is
14840// wrapped in strict mode code which doesn't define any globals. It's inside a
14841// function because try/catches deoptimize in certain engines.
14842
14843var cachedSetTimeout;
14844var cachedClearTimeout;
14845
14846function defaultSetTimout() {
14847 throw new Error('setTimeout has not been defined');
14848}
14849function defaultClearTimeout () {
14850 throw new Error('clearTimeout has not been defined');
14851}
14852(function () {
14853 try {
14854 if (typeof setTimeout === 'function') {
14855 cachedSetTimeout = setTimeout;
14856 } else {
14857 cachedSetTimeout = defaultSetTimout;
14858 }
14859 } catch (e) {
14860 cachedSetTimeout = defaultSetTimout;
14861 }
14862 try {
14863 if (typeof clearTimeout === 'function') {
14864 cachedClearTimeout = clearTimeout;
14865 } else {
14866 cachedClearTimeout = defaultClearTimeout;
14867 }
14868 } catch (e) {
14869 cachedClearTimeout = defaultClearTimeout;
14870 }
14871} ())
14872function runTimeout(fun) {
14873 if (cachedSetTimeout === setTimeout) {
14874 //normal enviroments in sane situations
14875 return setTimeout(fun, 0);
14876 }
14877 // if setTimeout wasn't available but was latter defined
14878 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
14879 cachedSetTimeout = setTimeout;
14880 return setTimeout(fun, 0);
14881 }
14882 try {
14883 // when when somebody has screwed with setTimeout but no I.E. maddness
14884 return cachedSetTimeout(fun, 0);
14885 } catch(e){
14886 try {
14887 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
14888 return cachedSetTimeout.call(null, fun, 0);
14889 } catch(e){
14890 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
14891 return cachedSetTimeout.call(this, fun, 0);
14892 }
14893 }
14894
14895
14896}
14897function runClearTimeout(marker) {
14898 if (cachedClearTimeout === clearTimeout) {
14899 //normal enviroments in sane situations
14900 return clearTimeout(marker);
14901 }
14902 // if clearTimeout wasn't available but was latter defined
14903 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
14904 cachedClearTimeout = clearTimeout;
14905 return clearTimeout(marker);
14906 }
14907 try {
14908 // when when somebody has screwed with setTimeout but no I.E. maddness
14909 return cachedClearTimeout(marker);
14910 } catch (e){
14911 try {
14912 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
14913 return cachedClearTimeout.call(null, marker);
14914 } catch (e){
14915 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
14916 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
14917 return cachedClearTimeout.call(this, marker);
14918 }
14919 }
14920
14921
14922
14923}
14924var queue = [];
14925var draining = false;
14926var currentQueue;
14927var queueIndex = -1;
14928
14929function cleanUpNextTick() {
14930 if (!draining || !currentQueue) {
14931 return;
14932 }
14933 draining = false;
14934 if (currentQueue.length) {
14935 queue = currentQueue.concat(queue);
14936 } else {
14937 queueIndex = -1;
14938 }
14939 if (queue.length) {
14940 drainQueue();
14941 }
14942}
14943
14944function drainQueue() {
14945 if (draining) {
14946 return;
14947 }
14948 var timeout = runTimeout(cleanUpNextTick);
14949 draining = true;
14950
14951 var len = queue.length;
14952 while(len) {
14953 currentQueue = queue;
14954 queue = [];
14955 while (++queueIndex < len) {
14956 if (currentQueue) {
14957 currentQueue[queueIndex].run();
14958 }
14959 }
14960 queueIndex = -1;
14961 len = queue.length;
14962 }
14963 currentQueue = null;
14964 draining = false;
14965 runClearTimeout(timeout);
14966}
14967
14968process.nextTick = function (fun) {
14969 var args = new Array(arguments.length - 1);
14970 if (arguments.length > 1) {
14971 for (var i = 1; i < arguments.length; i++) {
14972 args[i - 1] = arguments[i];
14973 }
14974 }
14975 queue.push(new Item(fun, args));
14976 if (queue.length === 1 && !draining) {
14977 runTimeout(drainQueue);
14978 }
14979};
14980
14981// v8 likes predictible objects
14982function Item(fun, array) {
14983 this.fun = fun;
14984 this.array = array;
14985}
14986Item.prototype.run = function () {
14987 this.fun.apply(null, this.array);
14988};
14989process.title = 'browser';
14990process.browser = true;
14991process.env = {};
14992process.argv = [];
14993process.version = ''; // empty string to avoid regexp issues
14994process.versions = {};
14995
14996function noop() {}
14997
14998process.on = noop;
14999process.addListener = noop;
15000process.once = noop;
15001process.off = noop;
15002process.removeListener = noop;
15003process.removeAllListeners = noop;
15004process.emit = noop;
15005process.prependListener = noop;
15006process.prependOnceListener = noop;
15007
15008process.listeners = function (name) { return [] }
15009
15010process.binding = function (name) {
15011 throw new Error('process.binding is not supported');
15012};
15013
15014process.cwd = function () { return '/' };
15015process.chdir = function (dir) {
15016 throw new Error('process.chdir is not supported');
15017};
15018process.umask = function() { return 0; };
15019
15020},{}],106:[function(require,module,exports){
15021module.exports = require('./lib/_stream_duplex.js');
15022
15023},{"./lib/_stream_duplex.js":107}],107:[function(require,module,exports){
15024// Copyright Joyent, Inc. and other Node contributors.
15025//
15026// Permission is hereby granted, free of charge, to any person obtaining a
15027// copy of this software and associated documentation files (the
15028// "Software"), to deal in the Software without restriction, including
15029// without limitation the rights to use, copy, modify, merge, publish,
15030// distribute, sublicense, and/or sell copies of the Software, and to permit
15031// persons to whom the Software is furnished to do so, subject to the
15032// following conditions:
15033//
15034// The above copyright notice and this permission notice shall be included
15035// in all copies or substantial portions of the Software.
15036//
15037// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15038// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15039// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
15040// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15041// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15042// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
15043// USE OR OTHER DEALINGS IN THE SOFTWARE.
15044
15045// a duplex stream is just a stream that is both readable and writable.
15046// Since JS doesn't have multiple prototypal inheritance, this class
15047// prototypally inherits from Readable, and then parasitically from
15048// Writable.
15049
15050'use strict';
15051
15052/*<replacement>*/
15053
15054var pna = require('process-nextick-args');
15055/*</replacement>*/
15056
15057/*<replacement>*/
15058var objectKeys = Object.keys || function (obj) {
15059 var keys = [];
15060 for (var key in obj) {
15061 keys.push(key);
15062 }return keys;
15063};
15064/*</replacement>*/
15065
15066module.exports = Duplex;
15067
15068/*<replacement>*/
15069var util = require('core-util-is');
15070util.inherits = require('inherits');
15071/*</replacement>*/
15072
15073var Readable = require('./_stream_readable');
15074var Writable = require('./_stream_writable');
15075
15076util.inherits(Duplex, Readable);
15077
15078{
15079 // avoid scope creep, the keys array can then be collected
15080 var keys = objectKeys(Writable.prototype);
15081 for (var v = 0; v < keys.length; v++) {
15082 var method = keys[v];
15083 if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
15084 }
15085}
15086
15087function Duplex(options) {
15088 if (!(this instanceof Duplex)) return new Duplex(options);
15089
15090 Readable.call(this, options);
15091 Writable.call(this, options);
15092
15093 if (options && options.readable === false) this.readable = false;
15094
15095 if (options && options.writable === false) this.writable = false;
15096
15097 this.allowHalfOpen = true;
15098 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
15099
15100 this.once('end', onend);
15101}
15102
15103Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
15104 // making it explicit this property is not enumerable
15105 // because otherwise some prototype manipulation in
15106 // userland will fail
15107 enumerable: false,
15108 get: function () {
15109 return this._writableState.highWaterMark;
15110 }
15111});
15112
15113// the no-half-open enforcer
15114function onend() {
15115 // if we allow half-open state, or if the writable side ended,
15116 // then we're ok.
15117 if (this.allowHalfOpen || this._writableState.ended) return;
15118
15119 // no more data can be written.
15120 // But allow more writes to happen in this tick.
15121 pna.nextTick(onEndNT, this);
15122}
15123
15124function onEndNT(self) {
15125 self.end();
15126}
15127
15128Object.defineProperty(Duplex.prototype, 'destroyed', {
15129 get: function () {
15130 if (this._readableState === undefined || this._writableState === undefined) {
15131 return false;
15132 }
15133 return this._readableState.destroyed && this._writableState.destroyed;
15134 },
15135 set: function (value) {
15136 // we ignore the value if the stream
15137 // has not been initialized yet
15138 if (this._readableState === undefined || this._writableState === undefined) {
15139 return;
15140 }
15141
15142 // backward compatibility, the user is explicitly
15143 // managing destroyed
15144 this._readableState.destroyed = value;
15145 this._writableState.destroyed = value;
15146 }
15147});
15148
15149Duplex.prototype._destroy = function (err, cb) {
15150 this.push(null);
15151 this.end();
15152
15153 pna.nextTick(cb, err);
15154};
15155},{"./_stream_readable":109,"./_stream_writable":111,"core-util-is":97,"inherits":100,"process-nextick-args":104}],108:[function(require,module,exports){
15156// Copyright Joyent, Inc. and other Node contributors.
15157//
15158// Permission is hereby granted, free of charge, to any person obtaining a
15159// copy of this software and associated documentation files (the
15160// "Software"), to deal in the Software without restriction, including
15161// without limitation the rights to use, copy, modify, merge, publish,
15162// distribute, sublicense, and/or sell copies of the Software, and to permit
15163// persons to whom the Software is furnished to do so, subject to the
15164// following conditions:
15165//
15166// The above copyright notice and this permission notice shall be included
15167// in all copies or substantial portions of the Software.
15168//
15169// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15170// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15171// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
15172// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15173// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15174// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
15175// USE OR OTHER DEALINGS IN THE SOFTWARE.
15176
15177// a passthrough stream.
15178// basically just the most minimal sort of Transform stream.
15179// Every written chunk gets output as-is.
15180
15181'use strict';
15182
15183module.exports = PassThrough;
15184
15185var Transform = require('./_stream_transform');
15186
15187/*<replacement>*/
15188var util = require('core-util-is');
15189util.inherits = require('inherits');
15190/*</replacement>*/
15191
15192util.inherits(PassThrough, Transform);
15193
15194function PassThrough(options) {
15195 if (!(this instanceof PassThrough)) return new PassThrough(options);
15196
15197 Transform.call(this, options);
15198}
15199
15200PassThrough.prototype._transform = function (chunk, encoding, cb) {
15201 cb(null, chunk);
15202};
15203},{"./_stream_transform":110,"core-util-is":97,"inherits":100}],109:[function(require,module,exports){
15204(function (process,global){
15205// Copyright Joyent, Inc. and other Node contributors.
15206//
15207// Permission is hereby granted, free of charge, to any person obtaining a
15208// copy of this software and associated documentation files (the
15209// "Software"), to deal in the Software without restriction, including
15210// without limitation the rights to use, copy, modify, merge, publish,
15211// distribute, sublicense, and/or sell copies of the Software, and to permit
15212// persons to whom the Software is furnished to do so, subject to the
15213// following conditions:
15214//
15215// The above copyright notice and this permission notice shall be included
15216// in all copies or substantial portions of the Software.
15217//
15218// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15219// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15220// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
15221// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15222// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15223// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
15224// USE OR OTHER DEALINGS IN THE SOFTWARE.
15225
15226'use strict';
15227
15228/*<replacement>*/
15229
15230var pna = require('process-nextick-args');
15231/*</replacement>*/
15232
15233module.exports = Readable;
15234
15235/*<replacement>*/
15236var isArray = require('isarray');
15237/*</replacement>*/
15238
15239/*<replacement>*/
15240var Duplex;
15241/*</replacement>*/
15242
15243Readable.ReadableState = ReadableState;
15244
15245/*<replacement>*/
15246var EE = require('events').EventEmitter;
15247
15248var EElistenerCount = function (emitter, type) {
15249 return emitter.listeners(type).length;
15250};
15251/*</replacement>*/
15252
15253/*<replacement>*/
15254var Stream = require('./internal/streams/stream');
15255/*</replacement>*/
15256
15257/*<replacement>*/
15258
15259var Buffer = require('safe-buffer').Buffer;
15260var OurUint8Array = global.Uint8Array || function () {};
15261function _uint8ArrayToBuffer(chunk) {
15262 return Buffer.from(chunk);
15263}
15264function _isUint8Array(obj) {
15265 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
15266}
15267
15268/*</replacement>*/
15269
15270/*<replacement>*/
15271var util = require('core-util-is');
15272util.inherits = require('inherits');
15273/*</replacement>*/
15274
15275/*<replacement>*/
15276var debugUtil = require('util');
15277var debug = void 0;
15278if (debugUtil && debugUtil.debuglog) {
15279 debug = debugUtil.debuglog('stream');
15280} else {
15281 debug = function () {};
15282}
15283/*</replacement>*/
15284
15285var BufferList = require('./internal/streams/BufferList');
15286var destroyImpl = require('./internal/streams/destroy');
15287var StringDecoder;
15288
15289util.inherits(Readable, Stream);
15290
15291var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
15292
15293function prependListener(emitter, event, fn) {
15294 // Sadly this is not cacheable as some libraries bundle their own
15295 // event emitter implementation with them.
15296 if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
15297
15298 // This is a hack to make sure that our error handler is attached before any
15299 // userland ones. NEVER DO THIS. This is here only because this code needs
15300 // to continue to work with older versions of Node.js that do not include
15301 // the prependListener() method. The goal is to eventually remove this hack.
15302 if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
15303}
15304
15305function ReadableState(options, stream) {
15306 Duplex = Duplex || require('./_stream_duplex');
15307
15308 options = options || {};
15309
15310 // Duplex streams are both readable and writable, but share
15311 // the same options object.
15312 // However, some cases require setting options to different
15313 // values for the readable and the writable sides of the duplex stream.
15314 // These options can be provided separately as readableXXX and writableXXX.
15315 var isDuplex = stream instanceof Duplex;
15316
15317 // object stream flag. Used to make read(n) ignore n and to
15318 // make all the buffer merging and length checks go away
15319 this.objectMode = !!options.objectMode;
15320
15321 if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
15322
15323 // the point at which it stops calling _read() to fill the buffer
15324 // Note: 0 is a valid value, means "don't call _read preemptively ever"
15325 var hwm = options.highWaterMark;
15326 var readableHwm = options.readableHighWaterMark;
15327 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
15328
15329 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
15330
15331 // cast to ints.
15332 this.highWaterMark = Math.floor(this.highWaterMark);
15333
15334 // A linked list is used to store data chunks instead of an array because the
15335 // linked list can remove elements from the beginning faster than
15336 // array.shift()
15337 this.buffer = new BufferList();
15338 this.length = 0;
15339 this.pipes = null;
15340 this.pipesCount = 0;
15341 this.flowing = null;
15342 this.ended = false;
15343 this.endEmitted = false;
15344 this.reading = false;
15345
15346 // a flag to be able to tell if the event 'readable'/'data' is emitted
15347 // immediately, or on a later tick. We set this to true at first, because
15348 // any actions that shouldn't happen until "later" should generally also
15349 // not happen before the first read call.
15350 this.sync = true;
15351
15352 // whenever we return null, then we set a flag to say
15353 // that we're awaiting a 'readable' event emission.
15354 this.needReadable = false;
15355 this.emittedReadable = false;
15356 this.readableListening = false;
15357 this.resumeScheduled = false;
15358
15359 // has it been destroyed
15360 this.destroyed = false;
15361
15362 // Crypto is kind of old and crusty. Historically, its default string
15363 // encoding is 'binary' so we have to make this configurable.
15364 // Everything else in the universe uses 'utf8', though.
15365 this.defaultEncoding = options.defaultEncoding || 'utf8';
15366
15367 // the number of writers that are awaiting a drain event in .pipe()s
15368 this.awaitDrain = 0;
15369
15370 // if true, a maybeReadMore has been scheduled
15371 this.readingMore = false;
15372
15373 this.decoder = null;
15374 this.encoding = null;
15375 if (options.encoding) {
15376 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
15377 this.decoder = new StringDecoder(options.encoding);
15378 this.encoding = options.encoding;
15379 }
15380}
15381
15382function Readable(options) {
15383 Duplex = Duplex || require('./_stream_duplex');
15384
15385 if (!(this instanceof Readable)) return new Readable(options);
15386
15387 this._readableState = new ReadableState(options, this);
15388
15389 // legacy
15390 this.readable = true;
15391
15392 if (options) {
15393 if (typeof options.read === 'function') this._read = options.read;
15394
15395 if (typeof options.destroy === 'function') this._destroy = options.destroy;
15396 }
15397
15398 Stream.call(this);
15399}
15400
15401Object.defineProperty(Readable.prototype, 'destroyed', {
15402 get: function () {
15403 if (this._readableState === undefined) {
15404 return false;
15405 }
15406 return this._readableState.destroyed;
15407 },
15408 set: function (value) {
15409 // we ignore the value if the stream
15410 // has not been initialized yet
15411 if (!this._readableState) {
15412 return;
15413 }
15414
15415 // backward compatibility, the user is explicitly
15416 // managing destroyed
15417 this._readableState.destroyed = value;
15418 }
15419});
15420
15421Readable.prototype.destroy = destroyImpl.destroy;
15422Readable.prototype._undestroy = destroyImpl.undestroy;
15423Readable.prototype._destroy = function (err, cb) {
15424 this.push(null);
15425 cb(err);
15426};
15427
15428// Manually shove something into the read() buffer.
15429// This returns true if the highWaterMark has not been hit yet,
15430// similar to how Writable.write() returns true if you should
15431// write() some more.
15432Readable.prototype.push = function (chunk, encoding) {
15433 var state = this._readableState;
15434 var skipChunkCheck;
15435
15436 if (!state.objectMode) {
15437 if (typeof chunk === 'string') {
15438 encoding = encoding || state.defaultEncoding;
15439 if (encoding !== state.encoding) {
15440 chunk = Buffer.from(chunk, encoding);
15441 encoding = '';
15442 }
15443 skipChunkCheck = true;
15444 }
15445 } else {
15446 skipChunkCheck = true;
15447 }
15448
15449 return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
15450};
15451
15452// Unshift should *always* be something directly out of read()
15453Readable.prototype.unshift = function (chunk) {
15454 return readableAddChunk(this, chunk, null, true, false);
15455};
15456
15457function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
15458 var state = stream._readableState;
15459 if (chunk === null) {
15460 state.reading = false;
15461 onEofChunk(stream, state);
15462 } else {
15463 var er;
15464 if (!skipChunkCheck) er = chunkInvalid(state, chunk);
15465 if (er) {
15466 stream.emit('error', er);
15467 } else if (state.objectMode || chunk && chunk.length > 0) {
15468 if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
15469 chunk = _uint8ArrayToBuffer(chunk);
15470 }
15471
15472 if (addToFront) {
15473 if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
15474 } else if (state.ended) {
15475 stream.emit('error', new Error('stream.push() after EOF'));
15476 } else {
15477 state.reading = false;
15478 if (state.decoder && !encoding) {
15479 chunk = state.decoder.write(chunk);
15480 if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
15481 } else {
15482 addChunk(stream, state, chunk, false);
15483 }
15484 }
15485 } else if (!addToFront) {
15486 state.reading = false;
15487 }
15488 }
15489
15490 return needMoreData(state);
15491}
15492
15493function addChunk(stream, state, chunk, addToFront) {
15494 if (state.flowing && state.length === 0 && !state.sync) {
15495 stream.emit('data', chunk);
15496 stream.read(0);
15497 } else {
15498 // update the buffer info.
15499 state.length += state.objectMode ? 1 : chunk.length;
15500 if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
15501
15502 if (state.needReadable) emitReadable(stream);
15503 }
15504 maybeReadMore(stream, state);
15505}
15506
15507function chunkInvalid(state, chunk) {
15508 var er;
15509 if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
15510 er = new TypeError('Invalid non-string/buffer chunk');
15511 }
15512 return er;
15513}
15514
15515// if it's past the high water mark, we can push in some more.
15516// Also, if we have no data yet, we can stand some
15517// more bytes. This is to work around cases where hwm=0,
15518// such as the repl. Also, if the push() triggered a
15519// readable event, and the user called read(largeNumber) such that
15520// needReadable was set, then we ought to push more, so that another
15521// 'readable' event will be triggered.
15522function needMoreData(state) {
15523 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
15524}
15525
15526Readable.prototype.isPaused = function () {
15527 return this._readableState.flowing === false;
15528};
15529
15530// backwards compatibility.
15531Readable.prototype.setEncoding = function (enc) {
15532 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
15533 this._readableState.decoder = new StringDecoder(enc);
15534 this._readableState.encoding = enc;
15535 return this;
15536};
15537
15538// Don't raise the hwm > 8MB
15539var MAX_HWM = 0x800000;
15540function computeNewHighWaterMark(n) {
15541 if (n >= MAX_HWM) {
15542 n = MAX_HWM;
15543 } else {
15544 // Get the next highest power of 2 to prevent increasing hwm excessively in
15545 // tiny amounts
15546 n--;
15547 n |= n >>> 1;
15548 n |= n >>> 2;
15549 n |= n >>> 4;
15550 n |= n >>> 8;
15551 n |= n >>> 16;
15552 n++;
15553 }
15554 return n;
15555}
15556
15557// This function is designed to be inlinable, so please take care when making
15558// changes to the function body.
15559function howMuchToRead(n, state) {
15560 if (n <= 0 || state.length === 0 && state.ended) return 0;
15561 if (state.objectMode) return 1;
15562 if (n !== n) {
15563 // Only flow one buffer at a time
15564 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
15565 }
15566 // If we're asking for more than the current hwm, then raise the hwm.
15567 if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
15568 if (n <= state.length) return n;
15569 // Don't have enough
15570 if (!state.ended) {
15571 state.needReadable = true;
15572 return 0;
15573 }
15574 return state.length;
15575}
15576
15577// you can override either this method, or the async _read(n) below.
15578Readable.prototype.read = function (n) {
15579 debug('read', n);
15580 n = parseInt(n, 10);
15581 var state = this._readableState;
15582 var nOrig = n;
15583
15584 if (n !== 0) state.emittedReadable = false;
15585
15586 // if we're doing read(0) to trigger a readable event, but we
15587 // already have a bunch of data in the buffer, then just trigger
15588 // the 'readable' event and move on.
15589 if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
15590 debug('read: emitReadable', state.length, state.ended);
15591 if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
15592 return null;
15593 }
15594
15595 n = howMuchToRead(n, state);
15596
15597 // if we've ended, and we're now clear, then finish it up.
15598 if (n === 0 && state.ended) {
15599 if (state.length === 0) endReadable(this);
15600 return null;
15601 }
15602
15603 // All the actual chunk generation logic needs to be
15604 // *below* the call to _read. The reason is that in certain
15605 // synthetic stream cases, such as passthrough streams, _read
15606 // may be a completely synchronous operation which may change
15607 // the state of the read buffer, providing enough data when
15608 // before there was *not* enough.
15609 //
15610 // So, the steps are:
15611 // 1. Figure out what the state of things will be after we do
15612 // a read from the buffer.
15613 //
15614 // 2. If that resulting state will trigger a _read, then call _read.
15615 // Note that this may be asynchronous, or synchronous. Yes, it is
15616 // deeply ugly to write APIs this way, but that still doesn't mean
15617 // that the Readable class should behave improperly, as streams are
15618 // designed to be sync/async agnostic.
15619 // Take note if the _read call is sync or async (ie, if the read call
15620 // has returned yet), so that we know whether or not it's safe to emit
15621 // 'readable' etc.
15622 //
15623 // 3. Actually pull the requested chunks out of the buffer and return.
15624
15625 // if we need a readable event, then we need to do some reading.
15626 var doRead = state.needReadable;
15627 debug('need readable', doRead);
15628
15629 // if we currently have less than the highWaterMark, then also read some
15630 if (state.length === 0 || state.length - n < state.highWaterMark) {
15631 doRead = true;
15632 debug('length less than watermark', doRead);
15633 }
15634
15635 // however, if we've ended, then there's no point, and if we're already
15636 // reading, then it's unnecessary.
15637 if (state.ended || state.reading) {
15638 doRead = false;
15639 debug('reading or ended', doRead);
15640 } else if (doRead) {
15641 debug('do read');
15642 state.reading = true;
15643 state.sync = true;
15644 // if the length is currently zero, then we *need* a readable event.
15645 if (state.length === 0) state.needReadable = true;
15646 // call internal read method
15647 this._read(state.highWaterMark);
15648 state.sync = false;
15649 // If _read pushed data synchronously, then `reading` will be false,
15650 // and we need to re-evaluate how much data we can return to the user.
15651 if (!state.reading) n = howMuchToRead(nOrig, state);
15652 }
15653
15654 var ret;
15655 if (n > 0) ret = fromList(n, state);else ret = null;
15656
15657 if (ret === null) {
15658 state.needReadable = true;
15659 n = 0;
15660 } else {
15661 state.length -= n;
15662 }
15663
15664 if (state.length === 0) {
15665 // If we have nothing in the buffer, then we want to know
15666 // as soon as we *do* get something into the buffer.
15667 if (!state.ended) state.needReadable = true;
15668
15669 // If we tried to read() past the EOF, then emit end on the next tick.
15670 if (nOrig !== n && state.ended) endReadable(this);
15671 }
15672
15673 if (ret !== null) this.emit('data', ret);
15674
15675 return ret;
15676};
15677
15678function onEofChunk(stream, state) {
15679 if (state.ended) return;
15680 if (state.decoder) {
15681 var chunk = state.decoder.end();
15682 if (chunk && chunk.length) {
15683 state.buffer.push(chunk);
15684 state.length += state.objectMode ? 1 : chunk.length;
15685 }
15686 }
15687 state.ended = true;
15688
15689 // emit 'readable' now to make sure it gets picked up.
15690 emitReadable(stream);
15691}
15692
15693// Don't emit readable right away in sync mode, because this can trigger
15694// another read() call => stack overflow. This way, it might trigger
15695// a nextTick recursion warning, but that's not so bad.
15696function emitReadable(stream) {
15697 var state = stream._readableState;
15698 state.needReadable = false;
15699 if (!state.emittedReadable) {
15700 debug('emitReadable', state.flowing);
15701 state.emittedReadable = true;
15702 if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
15703 }
15704}
15705
15706function emitReadable_(stream) {
15707 debug('emit readable');
15708 stream.emit('readable');
15709 flow(stream);
15710}
15711
15712// at this point, the user has presumably seen the 'readable' event,
15713// and called read() to consume some data. that may have triggered
15714// in turn another _read(n) call, in which case reading = true if
15715// it's in progress.
15716// However, if we're not ended, or reading, and the length < hwm,
15717// then go ahead and try to read some more preemptively.
15718function maybeReadMore(stream, state) {
15719 if (!state.readingMore) {
15720 state.readingMore = true;
15721 pna.nextTick(maybeReadMore_, stream, state);
15722 }
15723}
15724
15725function maybeReadMore_(stream, state) {
15726 var len = state.length;
15727 while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
15728 debug('maybeReadMore read 0');
15729 stream.read(0);
15730 if (len === state.length)
15731 // didn't get any data, stop spinning.
15732 break;else len = state.length;
15733 }
15734 state.readingMore = false;
15735}
15736
15737// abstract method. to be overridden in specific implementation classes.
15738// call cb(er, data) where data is <= n in length.
15739// for virtual (non-string, non-buffer) streams, "length" is somewhat
15740// arbitrary, and perhaps not very meaningful.
15741Readable.prototype._read = function (n) {
15742 this.emit('error', new Error('_read() is not implemented'));
15743};
15744
15745Readable.prototype.pipe = function (dest, pipeOpts) {
15746 var src = this;
15747 var state = this._readableState;
15748
15749 switch (state.pipesCount) {
15750 case 0:
15751 state.pipes = dest;
15752 break;
15753 case 1:
15754 state.pipes = [state.pipes, dest];
15755 break;
15756 default:
15757 state.pipes.push(dest);
15758 break;
15759 }
15760 state.pipesCount += 1;
15761 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
15762
15763 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
15764
15765 var endFn = doEnd ? onend : unpipe;
15766 if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
15767
15768 dest.on('unpipe', onunpipe);
15769 function onunpipe(readable, unpipeInfo) {
15770 debug('onunpipe');
15771 if (readable === src) {
15772 if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
15773 unpipeInfo.hasUnpiped = true;
15774 cleanup();
15775 }
15776 }
15777 }
15778
15779 function onend() {
15780 debug('onend');
15781 dest.end();
15782 }
15783
15784 // when the dest drains, it reduces the awaitDrain counter
15785 // on the source. This would be more elegant with a .once()
15786 // handler in flow(), but adding and removing repeatedly is
15787 // too slow.
15788 var ondrain = pipeOnDrain(src);
15789 dest.on('drain', ondrain);
15790
15791 var cleanedUp = false;
15792 function cleanup() {
15793 debug('cleanup');
15794 // cleanup event handlers once the pipe is broken
15795 dest.removeListener('close', onclose);
15796 dest.removeListener('finish', onfinish);
15797 dest.removeListener('drain', ondrain);
15798 dest.removeListener('error', onerror);
15799 dest.removeListener('unpipe', onunpipe);
15800 src.removeListener('end', onend);
15801 src.removeListener('end', unpipe);
15802 src.removeListener('data', ondata);
15803
15804 cleanedUp = true;
15805
15806 // if the reader is waiting for a drain event from this
15807 // specific writer, then it would cause it to never start
15808 // flowing again.
15809 // So, if this is awaiting a drain, then we just call it now.
15810 // If we don't know, then assume that we are waiting for one.
15811 if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
15812 }
15813
15814 // If the user pushes more data while we're writing to dest then we'll end up
15815 // in ondata again. However, we only want to increase awaitDrain once because
15816 // dest will only emit one 'drain' event for the multiple writes.
15817 // => Introduce a guard on increasing awaitDrain.
15818 var increasedAwaitDrain = false;
15819 src.on('data', ondata);
15820 function ondata(chunk) {
15821 debug('ondata');
15822 increasedAwaitDrain = false;
15823 var ret = dest.write(chunk);
15824 if (false === ret && !increasedAwaitDrain) {
15825 // If the user unpiped during `dest.write()`, it is possible
15826 // to get stuck in a permanently paused state if that write
15827 // also returned false.
15828 // => Check whether `dest` is still a piping destination.
15829 if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
15830 debug('false write response, pause', src._readableState.awaitDrain);
15831 src._readableState.awaitDrain++;
15832 increasedAwaitDrain = true;
15833 }
15834 src.pause();
15835 }
15836 }
15837
15838 // if the dest has an error, then stop piping into it.
15839 // however, don't suppress the throwing behavior for this.
15840 function onerror(er) {
15841 debug('onerror', er);
15842 unpipe();
15843 dest.removeListener('error', onerror);
15844 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
15845 }
15846
15847 // Make sure our error handler is attached before userland ones.
15848 prependListener(dest, 'error', onerror);
15849
15850 // Both close and finish should trigger unpipe, but only once.
15851 function onclose() {
15852 dest.removeListener('finish', onfinish);
15853 unpipe();
15854 }
15855 dest.once('close', onclose);
15856 function onfinish() {
15857 debug('onfinish');
15858 dest.removeListener('close', onclose);
15859 unpipe();
15860 }
15861 dest.once('finish', onfinish);
15862
15863 function unpipe() {
15864 debug('unpipe');
15865 src.unpipe(dest);
15866 }
15867
15868 // tell the dest that it's being piped to
15869 dest.emit('pipe', src);
15870
15871 // start the flow if it hasn't been started already.
15872 if (!state.flowing) {
15873 debug('pipe resume');
15874 src.resume();
15875 }
15876
15877 return dest;
15878};
15879
15880function pipeOnDrain(src) {
15881 return function () {
15882 var state = src._readableState;
15883 debug('pipeOnDrain', state.awaitDrain);
15884 if (state.awaitDrain) state.awaitDrain--;
15885 if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
15886 state.flowing = true;
15887 flow(src);
15888 }
15889 };
15890}
15891
15892Readable.prototype.unpipe = function (dest) {
15893 var state = this._readableState;
15894 var unpipeInfo = { hasUnpiped: false };
15895
15896 // if we're not piping anywhere, then do nothing.
15897 if (state.pipesCount === 0) return this;
15898
15899 // just one destination. most common case.
15900 if (state.pipesCount === 1) {
15901 // passed in one, but it's not the right one.
15902 if (dest && dest !== state.pipes) return this;
15903
15904 if (!dest) dest = state.pipes;
15905
15906 // got a match.
15907 state.pipes = null;
15908 state.pipesCount = 0;
15909 state.flowing = false;
15910 if (dest) dest.emit('unpipe', this, unpipeInfo);
15911 return this;
15912 }
15913
15914 // slow case. multiple pipe destinations.
15915
15916 if (!dest) {
15917 // remove all.
15918 var dests = state.pipes;
15919 var len = state.pipesCount;
15920 state.pipes = null;
15921 state.pipesCount = 0;
15922 state.flowing = false;
15923
15924 for (var i = 0; i < len; i++) {
15925 dests[i].emit('unpipe', this, unpipeInfo);
15926 }return this;
15927 }
15928
15929 // try to find the right one.
15930 var index = indexOf(state.pipes, dest);
15931 if (index === -1) return this;
15932
15933 state.pipes.splice(index, 1);
15934 state.pipesCount -= 1;
15935 if (state.pipesCount === 1) state.pipes = state.pipes[0];
15936
15937 dest.emit('unpipe', this, unpipeInfo);
15938
15939 return this;
15940};
15941
15942// set up data events if they are asked for
15943// Ensure readable listeners eventually get something
15944Readable.prototype.on = function (ev, fn) {
15945 var res = Stream.prototype.on.call(this, ev, fn);
15946
15947 if (ev === 'data') {
15948 // Start flowing on next tick if stream isn't explicitly paused
15949 if (this._readableState.flowing !== false) this.resume();
15950 } else if (ev === 'readable') {
15951 var state = this._readableState;
15952 if (!state.endEmitted && !state.readableListening) {
15953 state.readableListening = state.needReadable = true;
15954 state.emittedReadable = false;
15955 if (!state.reading) {
15956 pna.nextTick(nReadingNextTick, this);
15957 } else if (state.length) {
15958 emitReadable(this);
15959 }
15960 }
15961 }
15962
15963 return res;
15964};
15965Readable.prototype.addListener = Readable.prototype.on;
15966
15967function nReadingNextTick(self) {
15968 debug('readable nexttick read 0');
15969 self.read(0);
15970}
15971
15972// pause() and resume() are remnants of the legacy readable stream API
15973// If the user uses them, then switch into old mode.
15974Readable.prototype.resume = function () {
15975 var state = this._readableState;
15976 if (!state.flowing) {
15977 debug('resume');
15978 state.flowing = true;
15979 resume(this, state);
15980 }
15981 return this;
15982};
15983
15984function resume(stream, state) {
15985 if (!state.resumeScheduled) {
15986 state.resumeScheduled = true;
15987 pna.nextTick(resume_, stream, state);
15988 }
15989}
15990
15991function resume_(stream, state) {
15992 if (!state.reading) {
15993 debug('resume read 0');
15994 stream.read(0);
15995 }
15996
15997 state.resumeScheduled = false;
15998 state.awaitDrain = 0;
15999 stream.emit('resume');
16000 flow(stream);
16001 if (state.flowing && !state.reading) stream.read(0);
16002}
16003
16004Readable.prototype.pause = function () {
16005 debug('call pause flowing=%j', this._readableState.flowing);
16006 if (false !== this._readableState.flowing) {
16007 debug('pause');
16008 this._readableState.flowing = false;
16009 this.emit('pause');
16010 }
16011 return this;
16012};
16013
16014function flow(stream) {
16015 var state = stream._readableState;
16016 debug('flow', state.flowing);
16017 while (state.flowing && stream.read() !== null) {}
16018}
16019
16020// wrap an old-style stream as the async data source.
16021// This is *not* part of the readable stream interface.
16022// It is an ugly unfortunate mess of history.
16023Readable.prototype.wrap = function (stream) {
16024 var _this = this;
16025
16026 var state = this._readableState;
16027 var paused = false;
16028
16029 stream.on('end', function () {
16030 debug('wrapped end');
16031 if (state.decoder && !state.ended) {
16032 var chunk = state.decoder.end();
16033 if (chunk && chunk.length) _this.push(chunk);
16034 }
16035
16036 _this.push(null);
16037 });
16038
16039 stream.on('data', function (chunk) {
16040 debug('wrapped data');
16041 if (state.decoder) chunk = state.decoder.write(chunk);
16042
16043 // don't skip over falsy values in objectMode
16044 if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
16045
16046 var ret = _this.push(chunk);
16047 if (!ret) {
16048 paused = true;
16049 stream.pause();
16050 }
16051 });
16052
16053 // proxy all the other methods.
16054 // important when wrapping filters and duplexes.
16055 for (var i in stream) {
16056 if (this[i] === undefined && typeof stream[i] === 'function') {
16057 this[i] = function (method) {
16058 return function () {
16059 return stream[method].apply(stream, arguments);
16060 };
16061 }(i);
16062 }
16063 }
16064
16065 // proxy certain important events.
16066 for (var n = 0; n < kProxyEvents.length; n++) {
16067 stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
16068 }
16069
16070 // when we try to consume some more bytes, simply unpause the
16071 // underlying stream.
16072 this._read = function (n) {
16073 debug('wrapped _read', n);
16074 if (paused) {
16075 paused = false;
16076 stream.resume();
16077 }
16078 };
16079
16080 return this;
16081};
16082
16083Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
16084 // making it explicit this property is not enumerable
16085 // because otherwise some prototype manipulation in
16086 // userland will fail
16087 enumerable: false,
16088 get: function () {
16089 return this._readableState.highWaterMark;
16090 }
16091});
16092
16093// exposed for testing purposes only.
16094Readable._fromList = fromList;
16095
16096// Pluck off n bytes from an array of buffers.
16097// Length is the combined lengths of all the buffers in the list.
16098// This function is designed to be inlinable, so please take care when making
16099// changes to the function body.
16100function fromList(n, state) {
16101 // nothing buffered
16102 if (state.length === 0) return null;
16103
16104 var ret;
16105 if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
16106 // read it all, truncate the list
16107 if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
16108 state.buffer.clear();
16109 } else {
16110 // read part of list
16111 ret = fromListPartial(n, state.buffer, state.decoder);
16112 }
16113
16114 return ret;
16115}
16116
16117// Extracts only enough buffered data to satisfy the amount requested.
16118// This function is designed to be inlinable, so please take care when making
16119// changes to the function body.
16120function fromListPartial(n, list, hasStrings) {
16121 var ret;
16122 if (n < list.head.data.length) {
16123 // slice is the same for buffers and strings
16124 ret = list.head.data.slice(0, n);
16125 list.head.data = list.head.data.slice(n);
16126 } else if (n === list.head.data.length) {
16127 // first chunk is a perfect match
16128 ret = list.shift();
16129 } else {
16130 // result spans more than one buffer
16131 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
16132 }
16133 return ret;
16134}
16135
16136// Copies a specified amount of characters from the list of buffered data
16137// chunks.
16138// This function is designed to be inlinable, so please take care when making
16139// changes to the function body.
16140function copyFromBufferString(n, list) {
16141 var p = list.head;
16142 var c = 1;
16143 var ret = p.data;
16144 n -= ret.length;
16145 while (p = p.next) {
16146 var str = p.data;
16147 var nb = n > str.length ? str.length : n;
16148 if (nb === str.length) ret += str;else ret += str.slice(0, n);
16149 n -= nb;
16150 if (n === 0) {
16151 if (nb === str.length) {
16152 ++c;
16153 if (p.next) list.head = p.next;else list.head = list.tail = null;
16154 } else {
16155 list.head = p;
16156 p.data = str.slice(nb);
16157 }
16158 break;
16159 }
16160 ++c;
16161 }
16162 list.length -= c;
16163 return ret;
16164}
16165
16166// Copies a specified amount of bytes from the list of buffered data chunks.
16167// This function is designed to be inlinable, so please take care when making
16168// changes to the function body.
16169function copyFromBuffer(n, list) {
16170 var ret = Buffer.allocUnsafe(n);
16171 var p = list.head;
16172 var c = 1;
16173 p.data.copy(ret);
16174 n -= p.data.length;
16175 while (p = p.next) {
16176 var buf = p.data;
16177 var nb = n > buf.length ? buf.length : n;
16178 buf.copy(ret, ret.length - n, 0, nb);
16179 n -= nb;
16180 if (n === 0) {
16181 if (nb === buf.length) {
16182 ++c;
16183 if (p.next) list.head = p.next;else list.head = list.tail = null;
16184 } else {
16185 list.head = p;
16186 p.data = buf.slice(nb);
16187 }
16188 break;
16189 }
16190 ++c;
16191 }
16192 list.length -= c;
16193 return ret;
16194}
16195
16196function endReadable(stream) {
16197 var state = stream._readableState;
16198
16199 // If we get here before consuming all the bytes, then that is a
16200 // bug in node. Should never happen.
16201 if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
16202
16203 if (!state.endEmitted) {
16204 state.ended = true;
16205 pna.nextTick(endReadableNT, state, stream);
16206 }
16207}
16208
16209function endReadableNT(state, stream) {
16210 // Check that we didn't get one last unshift.
16211 if (!state.endEmitted && state.length === 0) {
16212 state.endEmitted = true;
16213 stream.readable = false;
16214 stream.emit('end');
16215 }
16216}
16217
16218function indexOf(xs, x) {
16219 for (var i = 0, l = xs.length; i < l; i++) {
16220 if (xs[i] === x) return i;
16221 }
16222 return -1;
16223}
16224}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
16225},{"./_stream_duplex":107,"./internal/streams/BufferList":112,"./internal/streams/destroy":113,"./internal/streams/stream":114,"_process":105,"core-util-is":97,"events":98,"inherits":100,"isarray":102,"process-nextick-args":104,"safe-buffer":115,"string_decoder/":116,"util":95}],110:[function(require,module,exports){
16226// Copyright Joyent, Inc. and other Node contributors.
16227//
16228// Permission is hereby granted, free of charge, to any person obtaining a
16229// copy of this software and associated documentation files (the
16230// "Software"), to deal in the Software without restriction, including
16231// without limitation the rights to use, copy, modify, merge, publish,
16232// distribute, sublicense, and/or sell copies of the Software, and to permit
16233// persons to whom the Software is furnished to do so, subject to the
16234// following conditions:
16235//
16236// The above copyright notice and this permission notice shall be included
16237// in all copies or substantial portions of the Software.
16238//
16239// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16240// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16241// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
16242// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16243// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16244// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16245// USE OR OTHER DEALINGS IN THE SOFTWARE.
16246
16247// a transform stream is a readable/writable stream where you do
16248// something with the data. Sometimes it's called a "filter",
16249// but that's not a great name for it, since that implies a thing where
16250// some bits pass through, and others are simply ignored. (That would
16251// be a valid example of a transform, of course.)
16252//
16253// While the output is causally related to the input, it's not a
16254// necessarily symmetric or synchronous transformation. For example,
16255// a zlib stream might take multiple plain-text writes(), and then
16256// emit a single compressed chunk some time in the future.
16257//
16258// Here's how this works:
16259//
16260// The Transform stream has all the aspects of the readable and writable
16261// stream classes. When you write(chunk), that calls _write(chunk,cb)
16262// internally, and returns false if there's a lot of pending writes
16263// buffered up. When you call read(), that calls _read(n) until
16264// there's enough pending readable data buffered up.
16265//
16266// In a transform stream, the written data is placed in a buffer. When
16267// _read(n) is called, it transforms the queued up data, calling the
16268// buffered _write cb's as it consumes chunks. If consuming a single
16269// written chunk would result in multiple output chunks, then the first
16270// outputted bit calls the readcb, and subsequent chunks just go into
16271// the read buffer, and will cause it to emit 'readable' if necessary.
16272//
16273// This way, back-pressure is actually determined by the reading side,
16274// since _read has to be called to start processing a new chunk. However,
16275// a pathological inflate type of transform can cause excessive buffering
16276// here. For example, imagine a stream where every byte of input is
16277// interpreted as an integer from 0-255, and then results in that many
16278// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
16279// 1kb of data being output. In this case, you could write a very small
16280// amount of input, and end up with a very large amount of output. In
16281// such a pathological inflating mechanism, there'd be no way to tell
16282// the system to stop doing the transform. A single 4MB write could
16283// cause the system to run out of memory.
16284//
16285// However, even in such a pathological case, only a single written chunk
16286// would be consumed, and then the rest would wait (un-transformed) until
16287// the results of the previous transformed chunk were consumed.
16288
16289'use strict';
16290
16291module.exports = Transform;
16292
16293var Duplex = require('./_stream_duplex');
16294
16295/*<replacement>*/
16296var util = require('core-util-is');
16297util.inherits = require('inherits');
16298/*</replacement>*/
16299
16300util.inherits(Transform, Duplex);
16301
16302function afterTransform(er, data) {
16303 var ts = this._transformState;
16304 ts.transforming = false;
16305
16306 var cb = ts.writecb;
16307
16308 if (!cb) {
16309 return this.emit('error', new Error('write callback called multiple times'));
16310 }
16311
16312 ts.writechunk = null;
16313 ts.writecb = null;
16314
16315 if (data != null) // single equals check for both `null` and `undefined`
16316 this.push(data);
16317
16318 cb(er);
16319
16320 var rs = this._readableState;
16321 rs.reading = false;
16322 if (rs.needReadable || rs.length < rs.highWaterMark) {
16323 this._read(rs.highWaterMark);
16324 }
16325}
16326
16327function Transform(options) {
16328 if (!(this instanceof Transform)) return new Transform(options);
16329
16330 Duplex.call(this, options);
16331
16332 this._transformState = {
16333 afterTransform: afterTransform.bind(this),
16334 needTransform: false,
16335 transforming: false,
16336 writecb: null,
16337 writechunk: null,
16338 writeencoding: null
16339 };
16340
16341 // start out asking for a readable event once data is transformed.
16342 this._readableState.needReadable = true;
16343
16344 // we have implemented the _read method, and done the other things
16345 // that Readable wants before the first _read call, so unset the
16346 // sync guard flag.
16347 this._readableState.sync = false;
16348
16349 if (options) {
16350 if (typeof options.transform === 'function') this._transform = options.transform;
16351
16352 if (typeof options.flush === 'function') this._flush = options.flush;
16353 }
16354
16355 // When the writable side finishes, then flush out anything remaining.
16356 this.on('prefinish', prefinish);
16357}
16358
16359function prefinish() {
16360 var _this = this;
16361
16362 if (typeof this._flush === 'function') {
16363 this._flush(function (er, data) {
16364 done(_this, er, data);
16365 });
16366 } else {
16367 done(this, null, null);
16368 }
16369}
16370
16371Transform.prototype.push = function (chunk, encoding) {
16372 this._transformState.needTransform = false;
16373 return Duplex.prototype.push.call(this, chunk, encoding);
16374};
16375
16376// This is the part where you do stuff!
16377// override this function in implementation classes.
16378// 'chunk' is an input chunk.
16379//
16380// Call `push(newChunk)` to pass along transformed output
16381// to the readable side. You may call 'push' zero or more times.
16382//
16383// Call `cb(err)` when you are done with this chunk. If you pass
16384// an error, then that'll put the hurt on the whole operation. If you
16385// never call cb(), then you'll never get another chunk.
16386Transform.prototype._transform = function (chunk, encoding, cb) {
16387 throw new Error('_transform() is not implemented');
16388};
16389
16390Transform.prototype._write = function (chunk, encoding, cb) {
16391 var ts = this._transformState;
16392 ts.writecb = cb;
16393 ts.writechunk = chunk;
16394 ts.writeencoding = encoding;
16395 if (!ts.transforming) {
16396 var rs = this._readableState;
16397 if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
16398 }
16399};
16400
16401// Doesn't matter what the args are here.
16402// _transform does all the work.
16403// That we got here means that the readable side wants more data.
16404Transform.prototype._read = function (n) {
16405 var ts = this._transformState;
16406
16407 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
16408 ts.transforming = true;
16409 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
16410 } else {
16411 // mark that we need a transform, so that any data that comes in
16412 // will get processed, now that we've asked for it.
16413 ts.needTransform = true;
16414 }
16415};
16416
16417Transform.prototype._destroy = function (err, cb) {
16418 var _this2 = this;
16419
16420 Duplex.prototype._destroy.call(this, err, function (err2) {
16421 cb(err2);
16422 _this2.emit('close');
16423 });
16424};
16425
16426function done(stream, er, data) {
16427 if (er) return stream.emit('error', er);
16428
16429 if (data != null) // single equals check for both `null` and `undefined`
16430 stream.push(data);
16431
16432 // if there's nothing in the write buffer, then that means
16433 // that nothing more will ever be provided
16434 if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
16435
16436 if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
16437
16438 return stream.push(null);
16439}
16440},{"./_stream_duplex":107,"core-util-is":97,"inherits":100}],111:[function(require,module,exports){
16441(function (process,global,setImmediate){
16442// Copyright Joyent, Inc. and other Node contributors.
16443//
16444// Permission is hereby granted, free of charge, to any person obtaining a
16445// copy of this software and associated documentation files (the
16446// "Software"), to deal in the Software without restriction, including
16447// without limitation the rights to use, copy, modify, merge, publish,
16448// distribute, sublicense, and/or sell copies of the Software, and to permit
16449// persons to whom the Software is furnished to do so, subject to the
16450// following conditions:
16451//
16452// The above copyright notice and this permission notice shall be included
16453// in all copies or substantial portions of the Software.
16454//
16455// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16456// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16457// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
16458// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16459// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16460// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16461// USE OR OTHER DEALINGS IN THE SOFTWARE.
16462
16463// A bit simpler than readable streams.
16464// Implement an async ._write(chunk, encoding, cb), and it'll handle all
16465// the drain event emission and buffering.
16466
16467'use strict';
16468
16469/*<replacement>*/
16470
16471var pna = require('process-nextick-args');
16472/*</replacement>*/
16473
16474module.exports = Writable;
16475
16476/* <replacement> */
16477function WriteReq(chunk, encoding, cb) {
16478 this.chunk = chunk;
16479 this.encoding = encoding;
16480 this.callback = cb;
16481 this.next = null;
16482}
16483
16484// It seems a linked list but it is not
16485// there will be only 2 of these for each stream
16486function CorkedRequest(state) {
16487 var _this = this;
16488
16489 this.next = null;
16490 this.entry = null;
16491 this.finish = function () {
16492 onCorkedFinish(_this, state);
16493 };
16494}
16495/* </replacement> */
16496
16497/*<replacement>*/
16498var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
16499/*</replacement>*/
16500
16501/*<replacement>*/
16502var Duplex;
16503/*</replacement>*/
16504
16505Writable.WritableState = WritableState;
16506
16507/*<replacement>*/
16508var util = require('core-util-is');
16509util.inherits = require('inherits');
16510/*</replacement>*/
16511
16512/*<replacement>*/
16513var internalUtil = {
16514 deprecate: require('util-deprecate')
16515};
16516/*</replacement>*/
16517
16518/*<replacement>*/
16519var Stream = require('./internal/streams/stream');
16520/*</replacement>*/
16521
16522/*<replacement>*/
16523
16524var Buffer = require('safe-buffer').Buffer;
16525var OurUint8Array = global.Uint8Array || function () {};
16526function _uint8ArrayToBuffer(chunk) {
16527 return Buffer.from(chunk);
16528}
16529function _isUint8Array(obj) {
16530 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
16531}
16532
16533/*</replacement>*/
16534
16535var destroyImpl = require('./internal/streams/destroy');
16536
16537util.inherits(Writable, Stream);
16538
16539function nop() {}
16540
16541function WritableState(options, stream) {
16542 Duplex = Duplex || require('./_stream_duplex');
16543
16544 options = options || {};
16545
16546 // Duplex streams are both readable and writable, but share
16547 // the same options object.
16548 // However, some cases require setting options to different
16549 // values for the readable and the writable sides of the duplex stream.
16550 // These options can be provided separately as readableXXX and writableXXX.
16551 var isDuplex = stream instanceof Duplex;
16552
16553 // object stream flag to indicate whether or not this stream
16554 // contains buffers or objects.
16555 this.objectMode = !!options.objectMode;
16556
16557 if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
16558
16559 // the point at which write() starts returning false
16560 // Note: 0 is a valid value, means that we always return false if
16561 // the entire buffer is not flushed immediately on write()
16562 var hwm = options.highWaterMark;
16563 var writableHwm = options.writableHighWaterMark;
16564 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
16565
16566 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
16567
16568 // cast to ints.
16569 this.highWaterMark = Math.floor(this.highWaterMark);
16570
16571 // if _final has been called
16572 this.finalCalled = false;
16573
16574 // drain event flag.
16575 this.needDrain = false;
16576 // at the start of calling end()
16577 this.ending = false;
16578 // when end() has been called, and returned
16579 this.ended = false;
16580 // when 'finish' is emitted
16581 this.finished = false;
16582
16583 // has it been destroyed
16584 this.destroyed = false;
16585
16586 // should we decode strings into buffers before passing to _write?
16587 // this is here so that some node-core streams can optimize string
16588 // handling at a lower level.
16589 var noDecode = options.decodeStrings === false;
16590 this.decodeStrings = !noDecode;
16591
16592 // Crypto is kind of old and crusty. Historically, its default string
16593 // encoding is 'binary' so we have to make this configurable.
16594 // Everything else in the universe uses 'utf8', though.
16595 this.defaultEncoding = options.defaultEncoding || 'utf8';
16596
16597 // not an actual buffer we keep track of, but a measurement
16598 // of how much we're waiting to get pushed to some underlying
16599 // socket or file.
16600 this.length = 0;
16601
16602 // a flag to see when we're in the middle of a write.
16603 this.writing = false;
16604
16605 // when true all writes will be buffered until .uncork() call
16606 this.corked = 0;
16607
16608 // a flag to be able to tell if the onwrite cb is called immediately,
16609 // or on a later tick. We set this to true at first, because any
16610 // actions that shouldn't happen until "later" should generally also
16611 // not happen before the first write call.
16612 this.sync = true;
16613
16614 // a flag to know if we're processing previously buffered items, which
16615 // may call the _write() callback in the same tick, so that we don't
16616 // end up in an overlapped onwrite situation.
16617 this.bufferProcessing = false;
16618
16619 // the callback that's passed to _write(chunk,cb)
16620 this.onwrite = function (er) {
16621 onwrite(stream, er);
16622 };
16623
16624 // the callback that the user supplies to write(chunk,encoding,cb)
16625 this.writecb = null;
16626
16627 // the amount that is being written when _write is called.
16628 this.writelen = 0;
16629
16630 this.bufferedRequest = null;
16631 this.lastBufferedRequest = null;
16632
16633 // number of pending user-supplied write callbacks
16634 // this must be 0 before 'finish' can be emitted
16635 this.pendingcb = 0;
16636
16637 // emit prefinish if the only thing we're waiting for is _write cbs
16638 // This is relevant for synchronous Transform streams
16639 this.prefinished = false;
16640
16641 // True if the error was already emitted and should not be thrown again
16642 this.errorEmitted = false;
16643
16644 // count buffered requests
16645 this.bufferedRequestCount = 0;
16646
16647 // allocate the first CorkedRequest, there is always
16648 // one allocated and free to use, and we maintain at most two
16649 this.corkedRequestsFree = new CorkedRequest(this);
16650}
16651
16652WritableState.prototype.getBuffer = function getBuffer() {
16653 var current = this.bufferedRequest;
16654 var out = [];
16655 while (current) {
16656 out.push(current);
16657 current = current.next;
16658 }
16659 return out;
16660};
16661
16662(function () {
16663 try {
16664 Object.defineProperty(WritableState.prototype, 'buffer', {
16665 get: internalUtil.deprecate(function () {
16666 return this.getBuffer();
16667 }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
16668 });
16669 } catch (_) {}
16670})();
16671
16672// Test _writableState for inheritance to account for Duplex streams,
16673// whose prototype chain only points to Readable.
16674var realHasInstance;
16675if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
16676 realHasInstance = Function.prototype[Symbol.hasInstance];
16677 Object.defineProperty(Writable, Symbol.hasInstance, {
16678 value: function (object) {
16679 if (realHasInstance.call(this, object)) return true;
16680 if (this !== Writable) return false;
16681
16682 return object && object._writableState instanceof WritableState;
16683 }
16684 });
16685} else {
16686 realHasInstance = function (object) {
16687 return object instanceof this;
16688 };
16689}
16690
16691function Writable(options) {
16692 Duplex = Duplex || require('./_stream_duplex');
16693
16694 // Writable ctor is applied to Duplexes, too.
16695 // `realHasInstance` is necessary because using plain `instanceof`
16696 // would return false, as no `_writableState` property is attached.
16697
16698 // Trying to use the custom `instanceof` for Writable here will also break the
16699 // Node.js LazyTransform implementation, which has a non-trivial getter for
16700 // `_writableState` that would lead to infinite recursion.
16701 if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
16702 return new Writable(options);
16703 }
16704
16705 this._writableState = new WritableState(options, this);
16706
16707 // legacy.
16708 this.writable = true;
16709
16710 if (options) {
16711 if (typeof options.write === 'function') this._write = options.write;
16712
16713 if (typeof options.writev === 'function') this._writev = options.writev;
16714
16715 if (typeof options.destroy === 'function') this._destroy = options.destroy;
16716
16717 if (typeof options.final === 'function') this._final = options.final;
16718 }
16719
16720 Stream.call(this);
16721}
16722
16723// Otherwise people can pipe Writable streams, which is just wrong.
16724Writable.prototype.pipe = function () {
16725 this.emit('error', new Error('Cannot pipe, not readable'));
16726};
16727
16728function writeAfterEnd(stream, cb) {
16729 var er = new Error('write after end');
16730 // TODO: defer error events consistently everywhere, not just the cb
16731 stream.emit('error', er);
16732 pna.nextTick(cb, er);
16733}
16734
16735// Checks that a user-supplied chunk is valid, especially for the particular
16736// mode the stream is in. Currently this means that `null` is never accepted
16737// and undefined/non-string values are only allowed in object mode.
16738function validChunk(stream, state, chunk, cb) {
16739 var valid = true;
16740 var er = false;
16741
16742 if (chunk === null) {
16743 er = new TypeError('May not write null values to stream');
16744 } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
16745 er = new TypeError('Invalid non-string/buffer chunk');
16746 }
16747 if (er) {
16748 stream.emit('error', er);
16749 pna.nextTick(cb, er);
16750 valid = false;
16751 }
16752 return valid;
16753}
16754
16755Writable.prototype.write = function (chunk, encoding, cb) {
16756 var state = this._writableState;
16757 var ret = false;
16758 var isBuf = !state.objectMode && _isUint8Array(chunk);
16759
16760 if (isBuf && !Buffer.isBuffer(chunk)) {
16761 chunk = _uint8ArrayToBuffer(chunk);
16762 }
16763
16764 if (typeof encoding === 'function') {
16765 cb = encoding;
16766 encoding = null;
16767 }
16768
16769 if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
16770
16771 if (typeof cb !== 'function') cb = nop;
16772
16773 if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
16774 state.pendingcb++;
16775 ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
16776 }
16777
16778 return ret;
16779};
16780
16781Writable.prototype.cork = function () {
16782 var state = this._writableState;
16783
16784 state.corked++;
16785};
16786
16787Writable.prototype.uncork = function () {
16788 var state = this._writableState;
16789
16790 if (state.corked) {
16791 state.corked--;
16792
16793 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
16794 }
16795};
16796
16797Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
16798 // node::ParseEncoding() requires lower case.
16799 if (typeof encoding === 'string') encoding = encoding.toLowerCase();
16800 if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
16801 this._writableState.defaultEncoding = encoding;
16802 return this;
16803};
16804
16805function decodeChunk(state, chunk, encoding) {
16806 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
16807 chunk = Buffer.from(chunk, encoding);
16808 }
16809 return chunk;
16810}
16811
16812Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
16813 // making it explicit this property is not enumerable
16814 // because otherwise some prototype manipulation in
16815 // userland will fail
16816 enumerable: false,
16817 get: function () {
16818 return this._writableState.highWaterMark;
16819 }
16820});
16821
16822// if we're already writing something, then just put this
16823// in the queue, and wait our turn. Otherwise, call _write
16824// If we return false, then we need a drain event, so set that flag.
16825function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
16826 if (!isBuf) {
16827 var newChunk = decodeChunk(state, chunk, encoding);
16828 if (chunk !== newChunk) {
16829 isBuf = true;
16830 encoding = 'buffer';
16831 chunk = newChunk;
16832 }
16833 }
16834 var len = state.objectMode ? 1 : chunk.length;
16835
16836 state.length += len;
16837
16838 var ret = state.length < state.highWaterMark;
16839 // we must ensure that previous needDrain will not be reset to false.
16840 if (!ret) state.needDrain = true;
16841
16842 if (state.writing || state.corked) {
16843 var last = state.lastBufferedRequest;
16844 state.lastBufferedRequest = {
16845 chunk: chunk,
16846 encoding: encoding,
16847 isBuf: isBuf,
16848 callback: cb,
16849 next: null
16850 };
16851 if (last) {
16852 last.next = state.lastBufferedRequest;
16853 } else {
16854 state.bufferedRequest = state.lastBufferedRequest;
16855 }
16856 state.bufferedRequestCount += 1;
16857 } else {
16858 doWrite(stream, state, false, len, chunk, encoding, cb);
16859 }
16860
16861 return ret;
16862}
16863
16864function doWrite(stream, state, writev, len, chunk, encoding, cb) {
16865 state.writelen = len;
16866 state.writecb = cb;
16867 state.writing = true;
16868 state.sync = true;
16869 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
16870 state.sync = false;
16871}
16872
16873function onwriteError(stream, state, sync, er, cb) {
16874 --state.pendingcb;
16875
16876 if (sync) {
16877 // defer the callback if we are being called synchronously
16878 // to avoid piling up things on the stack
16879 pna.nextTick(cb, er);
16880 // this can emit finish, and it will always happen
16881 // after error
16882 pna.nextTick(finishMaybe, stream, state);
16883 stream._writableState.errorEmitted = true;
16884 stream.emit('error', er);
16885 } else {
16886 // the caller expect this to happen before if
16887 // it is async
16888 cb(er);
16889 stream._writableState.errorEmitted = true;
16890 stream.emit('error', er);
16891 // this can emit finish, but finish must
16892 // always follow error
16893 finishMaybe(stream, state);
16894 }
16895}
16896
16897function onwriteStateUpdate(state) {
16898 state.writing = false;
16899 state.writecb = null;
16900 state.length -= state.writelen;
16901 state.writelen = 0;
16902}
16903
16904function onwrite(stream, er) {
16905 var state = stream._writableState;
16906 var sync = state.sync;
16907 var cb = state.writecb;
16908
16909 onwriteStateUpdate(state);
16910
16911 if (er) onwriteError(stream, state, sync, er, cb);else {
16912 // Check if we're actually ready to finish, but don't emit yet
16913 var finished = needFinish(state);
16914
16915 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
16916 clearBuffer(stream, state);
16917 }
16918
16919 if (sync) {
16920 /*<replacement>*/
16921 asyncWrite(afterWrite, stream, state, finished, cb);
16922 /*</replacement>*/
16923 } else {
16924 afterWrite(stream, state, finished, cb);
16925 }
16926 }
16927}
16928
16929function afterWrite(stream, state, finished, cb) {
16930 if (!finished) onwriteDrain(stream, state);
16931 state.pendingcb--;
16932 cb();
16933 finishMaybe(stream, state);
16934}
16935
16936// Must force callback to be called on nextTick, so that we don't
16937// emit 'drain' before the write() consumer gets the 'false' return
16938// value, and has a chance to attach a 'drain' listener.
16939function onwriteDrain(stream, state) {
16940 if (state.length === 0 && state.needDrain) {
16941 state.needDrain = false;
16942 stream.emit('drain');
16943 }
16944}
16945
16946// if there's something in the buffer waiting, then process it
16947function clearBuffer(stream, state) {
16948 state.bufferProcessing = true;
16949 var entry = state.bufferedRequest;
16950
16951 if (stream._writev && entry && entry.next) {
16952 // Fast case, write everything using _writev()
16953 var l = state.bufferedRequestCount;
16954 var buffer = new Array(l);
16955 var holder = state.corkedRequestsFree;
16956 holder.entry = entry;
16957
16958 var count = 0;
16959 var allBuffers = true;
16960 while (entry) {
16961 buffer[count] = entry;
16962 if (!entry.isBuf) allBuffers = false;
16963 entry = entry.next;
16964 count += 1;
16965 }
16966 buffer.allBuffers = allBuffers;
16967
16968 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
16969
16970 // doWrite is almost always async, defer these to save a bit of time
16971 // as the hot path ends with doWrite
16972 state.pendingcb++;
16973 state.lastBufferedRequest = null;
16974 if (holder.next) {
16975 state.corkedRequestsFree = holder.next;
16976 holder.next = null;
16977 } else {
16978 state.corkedRequestsFree = new CorkedRequest(state);
16979 }
16980 state.bufferedRequestCount = 0;
16981 } else {
16982 // Slow case, write chunks one-by-one
16983 while (entry) {
16984 var chunk = entry.chunk;
16985 var encoding = entry.encoding;
16986 var cb = entry.callback;
16987 var len = state.objectMode ? 1 : chunk.length;
16988
16989 doWrite(stream, state, false, len, chunk, encoding, cb);
16990 entry = entry.next;
16991 state.bufferedRequestCount--;
16992 // if we didn't call the onwrite immediately, then
16993 // it means that we need to wait until it does.
16994 // also, that means that the chunk and cb are currently
16995 // being processed, so move the buffer counter past them.
16996 if (state.writing) {
16997 break;
16998 }
16999 }
17000
17001 if (entry === null) state.lastBufferedRequest = null;
17002 }
17003
17004 state.bufferedRequest = entry;
17005 state.bufferProcessing = false;
17006}
17007
17008Writable.prototype._write = function (chunk, encoding, cb) {
17009 cb(new Error('_write() is not implemented'));
17010};
17011
17012Writable.prototype._writev = null;
17013
17014Writable.prototype.end = function (chunk, encoding, cb) {
17015 var state = this._writableState;
17016
17017 if (typeof chunk === 'function') {
17018 cb = chunk;
17019 chunk = null;
17020 encoding = null;
17021 } else if (typeof encoding === 'function') {
17022 cb = encoding;
17023 encoding = null;
17024 }
17025
17026 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
17027
17028 // .end() fully uncorks
17029 if (state.corked) {
17030 state.corked = 1;
17031 this.uncork();
17032 }
17033
17034 // ignore unnecessary end() calls.
17035 if (!state.ending && !state.finished) endWritable(this, state, cb);
17036};
17037
17038function needFinish(state) {
17039 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
17040}
17041function callFinal(stream, state) {
17042 stream._final(function (err) {
17043 state.pendingcb--;
17044 if (err) {
17045 stream.emit('error', err);
17046 }
17047 state.prefinished = true;
17048 stream.emit('prefinish');
17049 finishMaybe(stream, state);
17050 });
17051}
17052function prefinish(stream, state) {
17053 if (!state.prefinished && !state.finalCalled) {
17054 if (typeof stream._final === 'function') {
17055 state.pendingcb++;
17056 state.finalCalled = true;
17057 pna.nextTick(callFinal, stream, state);
17058 } else {
17059 state.prefinished = true;
17060 stream.emit('prefinish');
17061 }
17062 }
17063}
17064
17065function finishMaybe(stream, state) {
17066 var need = needFinish(state);
17067 if (need) {
17068 prefinish(stream, state);
17069 if (state.pendingcb === 0) {
17070 state.finished = true;
17071 stream.emit('finish');
17072 }
17073 }
17074 return need;
17075}
17076
17077function endWritable(stream, state, cb) {
17078 state.ending = true;
17079 finishMaybe(stream, state);
17080 if (cb) {
17081 if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
17082 }
17083 state.ended = true;
17084 stream.writable = false;
17085}
17086
17087function onCorkedFinish(corkReq, state, err) {
17088 var entry = corkReq.entry;
17089 corkReq.entry = null;
17090 while (entry) {
17091 var cb = entry.callback;
17092 state.pendingcb--;
17093 cb(err);
17094 entry = entry.next;
17095 }
17096 if (state.corkedRequestsFree) {
17097 state.corkedRequestsFree.next = corkReq;
17098 } else {
17099 state.corkedRequestsFree = corkReq;
17100 }
17101}
17102
17103Object.defineProperty(Writable.prototype, 'destroyed', {
17104 get: function () {
17105 if (this._writableState === undefined) {
17106 return false;
17107 }
17108 return this._writableState.destroyed;
17109 },
17110 set: function (value) {
17111 // we ignore the value if the stream
17112 // has not been initialized yet
17113 if (!this._writableState) {
17114 return;
17115 }
17116
17117 // backward compatibility, the user is explicitly
17118 // managing destroyed
17119 this._writableState.destroyed = value;
17120 }
17121});
17122
17123Writable.prototype.destroy = destroyImpl.destroy;
17124Writable.prototype._undestroy = destroyImpl.undestroy;
17125Writable.prototype._destroy = function (err, cb) {
17126 this.end();
17127 cb(err);
17128};
17129}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
17130},{"./_stream_duplex":107,"./internal/streams/destroy":113,"./internal/streams/stream":114,"_process":105,"core-util-is":97,"inherits":100,"process-nextick-args":104,"safe-buffer":115,"timers":124,"util-deprecate":125}],112:[function(require,module,exports){
17131'use strict';
17132
17133function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17134
17135var Buffer = require('safe-buffer').Buffer;
17136var util = require('util');
17137
17138function copyBuffer(src, target, offset) {
17139 src.copy(target, offset);
17140}
17141
17142module.exports = function () {
17143 function BufferList() {
17144 _classCallCheck(this, BufferList);
17145
17146 this.head = null;
17147 this.tail = null;
17148 this.length = 0;
17149 }
17150
17151 BufferList.prototype.push = function push(v) {
17152 var entry = { data: v, next: null };
17153 if (this.length > 0) this.tail.next = entry;else this.head = entry;
17154 this.tail = entry;
17155 ++this.length;
17156 };
17157
17158 BufferList.prototype.unshift = function unshift(v) {
17159 var entry = { data: v, next: this.head };
17160 if (this.length === 0) this.tail = entry;
17161 this.head = entry;
17162 ++this.length;
17163 };
17164
17165 BufferList.prototype.shift = function shift() {
17166 if (this.length === 0) return;
17167 var ret = this.head.data;
17168 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
17169 --this.length;
17170 return ret;
17171 };
17172
17173 BufferList.prototype.clear = function clear() {
17174 this.head = this.tail = null;
17175 this.length = 0;
17176 };
17177
17178 BufferList.prototype.join = function join(s) {
17179 if (this.length === 0) return '';
17180 var p = this.head;
17181 var ret = '' + p.data;
17182 while (p = p.next) {
17183 ret += s + p.data;
17184 }return ret;
17185 };
17186
17187 BufferList.prototype.concat = function concat(n) {
17188 if (this.length === 0) return Buffer.alloc(0);
17189 if (this.length === 1) return this.head.data;
17190 var ret = Buffer.allocUnsafe(n >>> 0);
17191 var p = this.head;
17192 var i = 0;
17193 while (p) {
17194 copyBuffer(p.data, ret, i);
17195 i += p.data.length;
17196 p = p.next;
17197 }
17198 return ret;
17199 };
17200
17201 return BufferList;
17202}();
17203
17204if (util && util.inspect && util.inspect.custom) {
17205 module.exports.prototype[util.inspect.custom] = function () {
17206 var obj = util.inspect({ length: this.length });
17207 return this.constructor.name + ' ' + obj;
17208 };
17209}
17210},{"safe-buffer":115,"util":95}],113:[function(require,module,exports){
17211'use strict';
17212
17213/*<replacement>*/
17214
17215var pna = require('process-nextick-args');
17216/*</replacement>*/
17217
17218// undocumented cb() API, needed for core, not for public API
17219function destroy(err, cb) {
17220 var _this = this;
17221
17222 var readableDestroyed = this._readableState && this._readableState.destroyed;
17223 var writableDestroyed = this._writableState && this._writableState.destroyed;
17224
17225 if (readableDestroyed || writableDestroyed) {
17226 if (cb) {
17227 cb(err);
17228 } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
17229 pna.nextTick(emitErrorNT, this, err);
17230 }
17231 return this;
17232 }
17233
17234 // we set destroyed to true before firing error callbacks in order
17235 // to make it re-entrance safe in case destroy() is called within callbacks
17236
17237 if (this._readableState) {
17238 this._readableState.destroyed = true;
17239 }
17240
17241 // if this is a duplex stream mark the writable part as destroyed as well
17242 if (this._writableState) {
17243 this._writableState.destroyed = true;
17244 }
17245
17246 this._destroy(err || null, function (err) {
17247 if (!cb && err) {
17248 pna.nextTick(emitErrorNT, _this, err);
17249 if (_this._writableState) {
17250 _this._writableState.errorEmitted = true;
17251 }
17252 } else if (cb) {
17253 cb(err);
17254 }
17255 });
17256
17257 return this;
17258}
17259
17260function undestroy() {
17261 if (this._readableState) {
17262 this._readableState.destroyed = false;
17263 this._readableState.reading = false;
17264 this._readableState.ended = false;
17265 this._readableState.endEmitted = false;
17266 }
17267
17268 if (this._writableState) {
17269 this._writableState.destroyed = false;
17270 this._writableState.ended = false;
17271 this._writableState.ending = false;
17272 this._writableState.finished = false;
17273 this._writableState.errorEmitted = false;
17274 }
17275}
17276
17277function emitErrorNT(self, err) {
17278 self.emit('error', err);
17279}
17280
17281module.exports = {
17282 destroy: destroy,
17283 undestroy: undestroy
17284};
17285},{"process-nextick-args":104}],114:[function(require,module,exports){
17286module.exports = require('events').EventEmitter;
17287
17288},{"events":98}],115:[function(require,module,exports){
17289/* eslint-disable node/no-deprecated-api */
17290var buffer = require('buffer')
17291var Buffer = buffer.Buffer
17292
17293// alternative to using Object.keys for old browsers
17294function copyProps (src, dst) {
17295 for (var key in src) {
17296 dst[key] = src[key]
17297 }
17298}
17299if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
17300 module.exports = buffer
17301} else {
17302 // Copy properties from require('buffer')
17303 copyProps(buffer, exports)
17304 exports.Buffer = SafeBuffer
17305}
17306
17307function SafeBuffer (arg, encodingOrOffset, length) {
17308 return Buffer(arg, encodingOrOffset, length)
17309}
17310
17311// Copy static methods from Buffer
17312copyProps(Buffer, SafeBuffer)
17313
17314SafeBuffer.from = function (arg, encodingOrOffset, length) {
17315 if (typeof arg === 'number') {
17316 throw new TypeError('Argument must not be a number')
17317 }
17318 return Buffer(arg, encodingOrOffset, length)
17319}
17320
17321SafeBuffer.alloc = function (size, fill, encoding) {
17322 if (typeof size !== 'number') {
17323 throw new TypeError('Argument must be a number')
17324 }
17325 var buf = Buffer(size)
17326 if (fill !== undefined) {
17327 if (typeof encoding === 'string') {
17328 buf.fill(fill, encoding)
17329 } else {
17330 buf.fill(fill)
17331 }
17332 } else {
17333 buf.fill(0)
17334 }
17335 return buf
17336}
17337
17338SafeBuffer.allocUnsafe = function (size) {
17339 if (typeof size !== 'number') {
17340 throw new TypeError('Argument must be a number')
17341 }
17342 return Buffer(size)
17343}
17344
17345SafeBuffer.allocUnsafeSlow = function (size) {
17346 if (typeof size !== 'number') {
17347 throw new TypeError('Argument must be a number')
17348 }
17349 return buffer.SlowBuffer(size)
17350}
17351
17352},{"buffer":96}],116:[function(require,module,exports){
17353// Copyright Joyent, Inc. and other Node contributors.
17354//
17355// Permission is hereby granted, free of charge, to any person obtaining a
17356// copy of this software and associated documentation files (the
17357// "Software"), to deal in the Software without restriction, including
17358// without limitation the rights to use, copy, modify, merge, publish,
17359// distribute, sublicense, and/or sell copies of the Software, and to permit
17360// persons to whom the Software is furnished to do so, subject to the
17361// following conditions:
17362//
17363// The above copyright notice and this permission notice shall be included
17364// in all copies or substantial portions of the Software.
17365//
17366// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17367// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17368// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17369// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17370// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17371// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17372// USE OR OTHER DEALINGS IN THE SOFTWARE.
17373
17374'use strict';
17375
17376/*<replacement>*/
17377
17378var Buffer = require('safe-buffer').Buffer;
17379/*</replacement>*/
17380
17381var isEncoding = Buffer.isEncoding || function (encoding) {
17382 encoding = '' + encoding;
17383 switch (encoding && encoding.toLowerCase()) {
17384 case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
17385 return true;
17386 default:
17387 return false;
17388 }
17389};
17390
17391function _normalizeEncoding(enc) {
17392 if (!enc) return 'utf8';
17393 var retried;
17394 while (true) {
17395 switch (enc) {
17396 case 'utf8':
17397 case 'utf-8':
17398 return 'utf8';
17399 case 'ucs2':
17400 case 'ucs-2':
17401 case 'utf16le':
17402 case 'utf-16le':
17403 return 'utf16le';
17404 case 'latin1':
17405 case 'binary':
17406 return 'latin1';
17407 case 'base64':
17408 case 'ascii':
17409 case 'hex':
17410 return enc;
17411 default:
17412 if (retried) return; // undefined
17413 enc = ('' + enc).toLowerCase();
17414 retried = true;
17415 }
17416 }
17417};
17418
17419// Do not cache `Buffer.isEncoding` when checking encoding names as some
17420// modules monkey-patch it to support additional encodings
17421function normalizeEncoding(enc) {
17422 var nenc = _normalizeEncoding(enc);
17423 if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
17424 return nenc || enc;
17425}
17426
17427// StringDecoder provides an interface for efficiently splitting a series of
17428// buffers into a series of JS strings without breaking apart multi-byte
17429// characters.
17430exports.StringDecoder = StringDecoder;
17431function StringDecoder(encoding) {
17432 this.encoding = normalizeEncoding(encoding);
17433 var nb;
17434 switch (this.encoding) {
17435 case 'utf16le':
17436 this.text = utf16Text;
17437 this.end = utf16End;
17438 nb = 4;
17439 break;
17440 case 'utf8':
17441 this.fillLast = utf8FillLast;
17442 nb = 4;
17443 break;
17444 case 'base64':
17445 this.text = base64Text;
17446 this.end = base64End;
17447 nb = 3;
17448 break;
17449 default:
17450 this.write = simpleWrite;
17451 this.end = simpleEnd;
17452 return;
17453 }
17454 this.lastNeed = 0;
17455 this.lastTotal = 0;
17456 this.lastChar = Buffer.allocUnsafe(nb);
17457}
17458
17459StringDecoder.prototype.write = function (buf) {
17460 if (buf.length === 0) return '';
17461 var r;
17462 var i;
17463 if (this.lastNeed) {
17464 r = this.fillLast(buf);
17465 if (r === undefined) return '';
17466 i = this.lastNeed;
17467 this.lastNeed = 0;
17468 } else {
17469 i = 0;
17470 }
17471 if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
17472 return r || '';
17473};
17474
17475StringDecoder.prototype.end = utf8End;
17476
17477// Returns only complete characters in a Buffer
17478StringDecoder.prototype.text = utf8Text;
17479
17480// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
17481StringDecoder.prototype.fillLast = function (buf) {
17482 if (this.lastNeed <= buf.length) {
17483 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
17484 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
17485 }
17486 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
17487 this.lastNeed -= buf.length;
17488};
17489
17490// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
17491// continuation byte. If an invalid byte is detected, -2 is returned.
17492function utf8CheckByte(byte) {
17493 if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
17494 return byte >> 6 === 0x02 ? -1 : -2;
17495}
17496
17497// Checks at most 3 bytes at the end of a Buffer in order to detect an
17498// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
17499// needed to complete the UTF-8 character (if applicable) are returned.
17500function utf8CheckIncomplete(self, buf, i) {
17501 var j = buf.length - 1;
17502 if (j < i) return 0;
17503 var nb = utf8CheckByte(buf[j]);
17504 if (nb >= 0) {
17505 if (nb > 0) self.lastNeed = nb - 1;
17506 return nb;
17507 }
17508 if (--j < i || nb === -2) return 0;
17509 nb = utf8CheckByte(buf[j]);
17510 if (nb >= 0) {
17511 if (nb > 0) self.lastNeed = nb - 2;
17512 return nb;
17513 }
17514 if (--j < i || nb === -2) return 0;
17515 nb = utf8CheckByte(buf[j]);
17516 if (nb >= 0) {
17517 if (nb > 0) {
17518 if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
17519 }
17520 return nb;
17521 }
17522 return 0;
17523}
17524
17525// Validates as many continuation bytes for a multi-byte UTF-8 character as
17526// needed or are available. If we see a non-continuation byte where we expect
17527// one, we "replace" the validated continuation bytes we've seen so far with
17528// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
17529// behavior. The continuation byte check is included three times in the case
17530// where all of the continuation bytes for a character exist in the same buffer.
17531// It is also done this way as a slight performance increase instead of using a
17532// loop.
17533function utf8CheckExtraBytes(self, buf, p) {
17534 if ((buf[0] & 0xC0) !== 0x80) {
17535 self.lastNeed = 0;
17536 return '\ufffd';
17537 }
17538 if (self.lastNeed > 1 && buf.length > 1) {
17539 if ((buf[1] & 0xC0) !== 0x80) {
17540 self.lastNeed = 1;
17541 return '\ufffd';
17542 }
17543 if (self.lastNeed > 2 && buf.length > 2) {
17544 if ((buf[2] & 0xC0) !== 0x80) {
17545 self.lastNeed = 2;
17546 return '\ufffd';
17547 }
17548 }
17549 }
17550}
17551
17552// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
17553function utf8FillLast(buf) {
17554 var p = this.lastTotal - this.lastNeed;
17555 var r = utf8CheckExtraBytes(this, buf, p);
17556 if (r !== undefined) return r;
17557 if (this.lastNeed <= buf.length) {
17558 buf.copy(this.lastChar, p, 0, this.lastNeed);
17559 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
17560 }
17561 buf.copy(this.lastChar, p, 0, buf.length);
17562 this.lastNeed -= buf.length;
17563}
17564
17565// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
17566// partial character, the character's bytes are buffered until the required
17567// number of bytes are available.
17568function utf8Text(buf, i) {
17569 var total = utf8CheckIncomplete(this, buf, i);
17570 if (!this.lastNeed) return buf.toString('utf8', i);
17571 this.lastTotal = total;
17572 var end = buf.length - (total - this.lastNeed);
17573 buf.copy(this.lastChar, 0, end);
17574 return buf.toString('utf8', i, end);
17575}
17576
17577// For UTF-8, a replacement character is added when ending on a partial
17578// character.
17579function utf8End(buf) {
17580 var r = buf && buf.length ? this.write(buf) : '';
17581 if (this.lastNeed) return r + '\ufffd';
17582 return r;
17583}
17584
17585// UTF-16LE typically needs two bytes per character, but even if we have an even
17586// number of bytes available, we need to check if we end on a leading/high
17587// surrogate. In that case, we need to wait for the next two bytes in order to
17588// decode the last character properly.
17589function utf16Text(buf, i) {
17590 if ((buf.length - i) % 2 === 0) {
17591 var r = buf.toString('utf16le', i);
17592 if (r) {
17593 var c = r.charCodeAt(r.length - 1);
17594 if (c >= 0xD800 && c <= 0xDBFF) {
17595 this.lastNeed = 2;
17596 this.lastTotal = 4;
17597 this.lastChar[0] = buf[buf.length - 2];
17598 this.lastChar[1] = buf[buf.length - 1];
17599 return r.slice(0, -1);
17600 }
17601 }
17602 return r;
17603 }
17604 this.lastNeed = 1;
17605 this.lastTotal = 2;
17606 this.lastChar[0] = buf[buf.length - 1];
17607 return buf.toString('utf16le', i, buf.length - 1);
17608}
17609
17610// For UTF-16LE we do not explicitly append special replacement characters if we
17611// end on a partial character, we simply let v8 handle that.
17612function utf16End(buf) {
17613 var r = buf && buf.length ? this.write(buf) : '';
17614 if (this.lastNeed) {
17615 var end = this.lastTotal - this.lastNeed;
17616 return r + this.lastChar.toString('utf16le', 0, end);
17617 }
17618 return r;
17619}
17620
17621function base64Text(buf, i) {
17622 var n = (buf.length - i) % 3;
17623 if (n === 0) return buf.toString('base64', i);
17624 this.lastNeed = 3 - n;
17625 this.lastTotal = 3;
17626 if (n === 1) {
17627 this.lastChar[0] = buf[buf.length - 1];
17628 } else {
17629 this.lastChar[0] = buf[buf.length - 2];
17630 this.lastChar[1] = buf[buf.length - 1];
17631 }
17632 return buf.toString('base64', i, buf.length - n);
17633}
17634
17635function base64End(buf) {
17636 var r = buf && buf.length ? this.write(buf) : '';
17637 if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
17638 return r;
17639}
17640
17641// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
17642function simpleWrite(buf) {
17643 return buf.toString(this.encoding);
17644}
17645
17646function simpleEnd(buf) {
17647 return buf && buf.length ? this.write(buf) : '';
17648}
17649},{"safe-buffer":115}],117:[function(require,module,exports){
17650module.exports = require('./readable').PassThrough
17651
17652},{"./readable":118}],118:[function(require,module,exports){
17653exports = module.exports = require('./lib/_stream_readable.js');
17654exports.Stream = exports;
17655exports.Readable = exports;
17656exports.Writable = require('./lib/_stream_writable.js');
17657exports.Duplex = require('./lib/_stream_duplex.js');
17658exports.Transform = require('./lib/_stream_transform.js');
17659exports.PassThrough = require('./lib/_stream_passthrough.js');
17660
17661},{"./lib/_stream_duplex.js":107,"./lib/_stream_passthrough.js":108,"./lib/_stream_readable.js":109,"./lib/_stream_transform.js":110,"./lib/_stream_writable.js":111}],119:[function(require,module,exports){
17662module.exports = require('./readable').Transform
17663
17664},{"./readable":118}],120:[function(require,module,exports){
17665module.exports = require('./lib/_stream_writable.js');
17666
17667},{"./lib/_stream_writable.js":111}],121:[function(require,module,exports){
17668arguments[4][38][0].apply(exports,arguments)
17669},{"buffer":96,"dup":38}],122:[function(require,module,exports){
17670// Copyright Joyent, Inc. and other Node contributors.
17671//
17672// Permission is hereby granted, free of charge, to any person obtaining a
17673// copy of this software and associated documentation files (the
17674// "Software"), to deal in the Software without restriction, including
17675// without limitation the rights to use, copy, modify, merge, publish,
17676// distribute, sublicense, and/or sell copies of the Software, and to permit
17677// persons to whom the Software is furnished to do so, subject to the
17678// following conditions:
17679//
17680// The above copyright notice and this permission notice shall be included
17681// in all copies or substantial portions of the Software.
17682//
17683// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17684// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17685// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17686// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17687// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17688// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
17689// USE OR OTHER DEALINGS IN THE SOFTWARE.
17690
17691module.exports = Stream;
17692
17693var EE = require('events').EventEmitter;
17694var inherits = require('inherits');
17695
17696inherits(Stream, EE);
17697Stream.Readable = require('readable-stream/readable.js');
17698Stream.Writable = require('readable-stream/writable.js');
17699Stream.Duplex = require('readable-stream/duplex.js');
17700Stream.Transform = require('readable-stream/transform.js');
17701Stream.PassThrough = require('readable-stream/passthrough.js');
17702
17703// Backwards-compat with node 0.4.x
17704Stream.Stream = Stream;
17705
17706
17707
17708// old-style streams. Note that the pipe method (the only relevant
17709// part of this class) is overridden in the Readable class.
17710
17711function Stream() {
17712 EE.call(this);
17713}
17714
17715Stream.prototype.pipe = function(dest, options) {
17716 var source = this;
17717
17718 function ondata(chunk) {
17719 if (dest.writable) {
17720 if (false === dest.write(chunk) && source.pause) {
17721 source.pause();
17722 }
17723 }
17724 }
17725
17726 source.on('data', ondata);
17727
17728 function ondrain() {
17729 if (source.readable && source.resume) {
17730 source.resume();
17731 }
17732 }
17733
17734 dest.on('drain', ondrain);
17735
17736 // If the 'end' option is not supplied, dest.end() will be called when
17737 // source gets the 'end' or 'close' events. Only dest.end() once.
17738 if (!dest._isStdio && (!options || options.end !== false)) {
17739 source.on('end', onend);
17740 source.on('close', onclose);
17741 }
17742
17743 var didOnEnd = false;
17744 function onend() {
17745 if (didOnEnd) return;
17746 didOnEnd = true;
17747
17748 dest.end();
17749 }
17750
17751
17752 function onclose() {
17753 if (didOnEnd) return;
17754 didOnEnd = true;
17755
17756 if (typeof dest.destroy === 'function') dest.destroy();
17757 }
17758
17759 // don't leave dangling pipes when there are errors.
17760 function onerror(er) {
17761 cleanup();
17762 if (EE.listenerCount(this, 'error') === 0) {
17763 throw er; // Unhandled stream error in pipe.
17764 }
17765 }
17766
17767 source.on('error', onerror);
17768 dest.on('error', onerror);
17769
17770 // remove all the event listeners that were added.
17771 function cleanup() {
17772 source.removeListener('data', ondata);
17773 dest.removeListener('drain', ondrain);
17774
17775 source.removeListener('end', onend);
17776 source.removeListener('close', onclose);
17777
17778 source.removeListener('error', onerror);
17779 dest.removeListener('error', onerror);
17780
17781 source.removeListener('end', cleanup);
17782 source.removeListener('close', cleanup);
17783
17784 dest.removeListener('close', cleanup);
17785 }
17786
17787 source.on('end', cleanup);
17788 source.on('close', cleanup);
17789
17790 dest.on('close', cleanup);
17791
17792 dest.emit('pipe', source);
17793
17794 // Allow for unix-like usage: A.pipe(B).pipe(C)
17795 return dest;
17796};
17797
17798},{"events":98,"inherits":100,"readable-stream/duplex.js":106,"readable-stream/passthrough.js":117,"readable-stream/readable.js":118,"readable-stream/transform.js":119,"readable-stream/writable.js":120}],123:[function(require,module,exports){
17799arguments[4][116][0].apply(exports,arguments)
17800},{"dup":116,"safe-buffer":121}],124:[function(require,module,exports){
17801(function (setImmediate,clearImmediate){
17802var nextTick = require('process/browser.js').nextTick;
17803var apply = Function.prototype.apply;
17804var slice = Array.prototype.slice;
17805var immediateIds = {};
17806var nextImmediateId = 0;
17807
17808// DOM APIs, for completeness
17809
17810exports.setTimeout = function() {
17811 return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
17812};
17813exports.setInterval = function() {
17814 return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
17815};
17816exports.clearTimeout =
17817exports.clearInterval = function(timeout) { timeout.close(); };
17818
17819function Timeout(id, clearFn) {
17820 this._id = id;
17821 this._clearFn = clearFn;
17822}
17823Timeout.prototype.unref = Timeout.prototype.ref = function() {};
17824Timeout.prototype.close = function() {
17825 this._clearFn.call(window, this._id);
17826};
17827
17828// Does not start the time, just sets up the members needed.
17829exports.enroll = function(item, msecs) {
17830 clearTimeout(item._idleTimeoutId);
17831 item._idleTimeout = msecs;
17832};
17833
17834exports.unenroll = function(item) {
17835 clearTimeout(item._idleTimeoutId);
17836 item._idleTimeout = -1;
17837};
17838
17839exports._unrefActive = exports.active = function(item) {
17840 clearTimeout(item._idleTimeoutId);
17841
17842 var msecs = item._idleTimeout;
17843 if (msecs >= 0) {
17844 item._idleTimeoutId = setTimeout(function onTimeout() {
17845 if (item._onTimeout)
17846 item._onTimeout();
17847 }, msecs);
17848 }
17849};
17850
17851// That's not how node.js implements it but the exposed api is the same.
17852exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
17853 var id = nextImmediateId++;
17854 var args = arguments.length < 2 ? false : slice.call(arguments, 1);
17855
17856 immediateIds[id] = true;
17857
17858 nextTick(function onNextTick() {
17859 if (immediateIds[id]) {
17860 // fn.call() is faster so we optimize for the common use-case
17861 // @see http://jsperf.com/call-apply-segu
17862 if (args) {
17863 fn.apply(null, args);
17864 } else {
17865 fn.call(null);
17866 }
17867 // Prevent ids from leaking
17868 exports.clearImmediate(id);
17869 }
17870 });
17871
17872 return id;
17873};
17874
17875exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
17876 delete immediateIds[id];
17877};
17878}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
17879},{"process/browser.js":105,"timers":124}],125:[function(require,module,exports){
17880(function (global){
17881
17882/**
17883 * Module exports.
17884 */
17885
17886module.exports = deprecate;
17887
17888/**
17889 * Mark that a method should not be used.
17890 * Returns a modified function which warns once by default.
17891 *
17892 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
17893 *
17894 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
17895 * will throw an Error when invoked.
17896 *
17897 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
17898 * will invoke `console.trace()` instead of `console.error()`.
17899 *
17900 * @param {Function} fn - the function to deprecate
17901 * @param {String} msg - the string to print to the console when `fn` is invoked
17902 * @returns {Function} a new "deprecated" version of `fn`
17903 * @api public
17904 */
17905
17906function deprecate (fn, msg) {
17907 if (config('noDeprecation')) {
17908 return fn;
17909 }
17910
17911 var warned = false;
17912 function deprecated() {
17913 if (!warned) {
17914 if (config('throwDeprecation')) {
17915 throw new Error(msg);
17916 } else if (config('traceDeprecation')) {
17917 console.trace(msg);
17918 } else {
17919 console.warn(msg);
17920 }
17921 warned = true;
17922 }
17923 return fn.apply(this, arguments);
17924 }
17925
17926 return deprecated;
17927}
17928
17929/**
17930 * Checks `localStorage` for boolean values for the given `name`.
17931 *
17932 * @param {String} name
17933 * @returns {Boolean}
17934 * @api private
17935 */
17936
17937function config (name) {
17938 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
17939 try {
17940 if (!global.localStorage) return false;
17941 } catch (_) {
17942 return false;
17943 }
17944 var val = global.localStorage[name];
17945 if (null == val) return false;
17946 return String(val).toLowerCase() === 'true';
17947}
17948
17949}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
17950},{}]},{},[61])(61)
17951});
diff --git a/src/js/groestlcoinjs-bip38-2.0.2.js b/src/js/groestlcoinjs-bip38-2.0.2.js
new file mode 100644
index 0000000..073e578
--- /dev/null
+++ b/src/js/groestlcoinjs-bip38-2.0.2.js
@@ -0,0 +1,28732 @@
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.groestlcoinjsBip38 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2var aes = require('browserify-aes')
3var assert = require('assert')
4var Buffer = require('safe-buffer').Buffer
5var bs58check = require('bs58check')
6var bs58grscheck = require('bs58grscheck')
7var createHash = require('create-hash')
8var scrypt = require('scryptsy')
9var xor = require('buffer-xor/inplace')
10
11var ecurve = require('ecurve')
12var curve = ecurve.getCurveByName('secp256k1')
13
14var BigInteger = require('bigi')
15
16// constants
17var SCRYPT_PARAMS = {
18 N: 16384, // specified by BIP38
19 r: 8,
20 p: 8
21}
22var NULL = Buffer.alloc(0)
23
24function hash160 (buffer) {
25 return createHash('rmd160').update(
26 createHash('sha256').update(buffer).digest()
27 ).digest()
28}
29
30function hash256 (buffer) {
31 return createHash('sha256').update(
32 createHash('sha256').update(buffer).digest()
33 ).digest()
34}
35
36function getAddress (d, compressed, testnet) {
37 var Q = curve.G.multiply(d).getEncoded(compressed)
38 var hash = hash160(Q)
39 var payload = Buffer.allocUnsafe(21)
40 payload.writeUInt8(testnet ? 0x6f : 0x24, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38
41 hash.copy(payload, 1)
42
43 return bs58grscheck.encode(payload)
44}
45
46function encryptRaw (buffer, compressed, passphrase, progressCallback, scryptParams, testnet) {
47 if (buffer.length !== 32) throw new Error('Invalid private key length')
48 scryptParams = scryptParams || SCRYPT_PARAMS
49
50 var d = BigInteger.fromBuffer(buffer)
51 var address = getAddress(d, compressed, testnet)
52 var secret = Buffer.from(passphrase, 'utf8')
53 var salt = hash256(address).slice(0, 4)
54
55 var N = scryptParams.N
56 var r = scryptParams.r
57 var p = scryptParams.p
58
59 var scryptBuf = scrypt(secret, salt, N, r, p, 64, progressCallback)
60 var derivedHalf1 = scryptBuf.slice(0, 32)
61 var derivedHalf2 = scryptBuf.slice(32, 64)
62
63 var xorBuf = xor(derivedHalf1, buffer)
64 var cipher = aes.createCipheriv('aes-256-ecb', derivedHalf2, NULL)
65 cipher.setAutoPadding(false)
66 cipher.end(xorBuf)
67
68 var cipherText = cipher.read()
69
70 // 0x01 | 0x42 | flagByte | salt (4) | cipherText (32)
71 var result = Buffer.allocUnsafe(7 + 32)
72 result.writeUInt8(0x01, 0)
73 result.writeUInt8(0x42, 1)
74 result.writeUInt8(compressed ? 0xe0 : 0xc0, 2)
75 salt.copy(result, 3)
76 cipherText.copy(result, 7)
77
78 return result
79}
80
81function encrypt (buffer, compressed, passphrase, progressCallback, scryptParams, testnet) {
82 return bs58check.encode(encryptRaw(buffer, compressed, passphrase, progressCallback, scryptParams, testnet))
83}
84
85// some of the techniques borrowed from: https://github.com/pointbiz/bitaddress.org
86function decryptRaw (buffer, passphrase, progressCallback, scryptParams, testnet) {
87 // 39 bytes: 2 bytes prefix, 37 bytes payload
88 if (buffer.length !== 39) throw new Error('Invalid BIP38 data length')
89 if (buffer.readUInt8(0) !== 0x01) throw new Error('Invalid BIP38 prefix')
90 scryptParams = scryptParams || SCRYPT_PARAMS
91
92 // check if BIP38 EC multiply
93 var type = buffer.readUInt8(1)
94 if (type === 0x43) return decryptECMult(buffer, passphrase, progressCallback, scryptParams)
95 if (type !== 0x42) throw new Error('Invalid BIP38 type')
96
97 passphrase = Buffer.from(passphrase, 'utf8')
98
99 var flagByte = buffer.readUInt8(2)
100 var compressed = flagByte === 0xe0
101 if (!compressed && flagByte !== 0xc0) throw new Error('Invalid BIP38 compression flag')
102
103 var N = scryptParams.N
104 var r = scryptParams.r
105 var p = scryptParams.p
106
107 var salt = buffer.slice(3, 7)
108 var scryptBuf = scrypt(passphrase, salt, N, r, p, 64, progressCallback)
109 var derivedHalf1 = scryptBuf.slice(0, 32)
110 var derivedHalf2 = scryptBuf.slice(32, 64)
111
112 var privKeyBuf = buffer.slice(7, 7 + 32)
113 var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, NULL)
114 decipher.setAutoPadding(false)
115 decipher.end(privKeyBuf)
116
117 var plainText = decipher.read()
118 var privateKey = xor(derivedHalf1, plainText)
119
120 // verify salt matches address
121 var d = BigInteger.fromBuffer(privateKey)
122 var address = getAddress(d, compressed, address)
123 var checksum = hash256(address).slice(0, 4)
124 assert.deepEqual(salt, checksum)
125
126 return {
127 privateKey: privateKey,
128 compressed: compressed
129 }
130}
131
132function decrypt (string, passphrase, progressCallback, scryptParams, testnet) {
133 return decryptRaw(bs58check.decode(string), passphrase, progressCallback, scryptParams, testnet)
134}
135
136function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
137 passphrase = Buffer.from(passphrase, 'utf8')
138 buffer = buffer.slice(1) // FIXME: we can avoid this
139 scryptParams = scryptParams || SCRYPT_PARAMS
140
141 var flag = buffer.readUInt8(1)
142 var compressed = (flag & 0x20) !== 0
143 var hasLotSeq = (flag & 0x04) !== 0
144
145 assert.equal((flag & 0x24), flag, 'Invalid private key.')
146
147 var addressHash = buffer.slice(2, 6)
148 var ownerEntropy = buffer.slice(6, 14)
149 var ownerSalt
150
151 // 4 bytes ownerSalt if 4 bytes lot/sequence
152 if (hasLotSeq) {
153 ownerSalt = ownerEntropy.slice(0, 4)
154
155 // else, 8 bytes ownerSalt
156 } else {
157 ownerSalt = ownerEntropy
158 }
159
160 var encryptedPart1 = buffer.slice(14, 22) // First 8 bytes
161 var encryptedPart2 = buffer.slice(22, 38) // 16 bytes
162
163 var N = scryptParams.N
164 var r = scryptParams.r
165 var p = scryptParams.p
166 var preFactor = scrypt(passphrase, ownerSalt, N, r, p, 32, progressCallback)
167
168 var passFactor
169 if (hasLotSeq) {
170 var hashTarget = Buffer.concat([preFactor, ownerEntropy])
171 passFactor = hash256(hashTarget)
172 } else {
173 passFactor = preFactor
174 }
175
176 var passInt = BigInteger.fromBuffer(passFactor)
177 var passPoint = curve.G.multiply(passInt).getEncoded(true)
178
179 var seedBPass = scrypt(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64)
180 var derivedHalf1 = seedBPass.slice(0, 32)
181 var derivedHalf2 = seedBPass.slice(32, 64)
182
183 var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0))
184 decipher.setAutoPadding(false)
185 decipher.end(encryptedPart2)
186
187 var decryptedPart2 = decipher.read()
188 var tmp = xor(decryptedPart2, derivedHalf1.slice(16, 32))
189 var seedBPart2 = tmp.slice(8, 16)
190
191 var decipher2 = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0))
192 decipher2.setAutoPadding(false)
193 decipher2.write(encryptedPart1) // first 8 bytes
194 decipher2.end(tmp.slice(0, 8)) // last 8 bytes
195
196 var seedBPart1 = xor(decipher2.read(), derivedHalf1.slice(0, 16))
197 var seedB = Buffer.concat([seedBPart1, seedBPart2], 24)
198 var factorB = BigInteger.fromBuffer(hash256(seedB))
199
200 // d = passFactor * factorB (mod n)
201 var d = passInt.multiply(factorB).mod(curve.n)
202
203 return {
204 privateKey: d.toBuffer(32),
205 compressed: compressed
206 }
207}
208
209function verify (string) {
210 var decoded = bs58grscheck.decodeUnsafe(string)
211 if (!decoded) return false
212
213 if (decoded.length !== 39) return false
214 if (decoded.readUInt8(0) !== 0x01) return false
215
216 var type = decoded.readUInt8(1)
217 var flag = decoded.readUInt8(2)
218
219 // encrypted WIF
220 if (type === 0x42) {
221 if (flag !== 0xc0 && flag !== 0xe0) return false
222
223 // EC mult
224 } else if (type === 0x43) {
225 if ((flag & ~0x24)) return false
226 } else {
227 return false
228 }
229
230 return true
231}
232
233module.exports = {
234 decrypt: decrypt,
235 decryptECMult: decryptECMult,
236 decryptRaw: decryptRaw,
237 encrypt: encrypt,
238 encryptRaw: encryptRaw,
239 verify: verify
240}
241
242},{"assert":74,"bigi":5,"browserify-aes":9,"bs58check":26,"bs58grscheck":28,"buffer-xor/inplace":30,"create-hash":32,"ecurve":35,"safe-buffer":47,"scryptsy":48}],2:[function(require,module,exports){
243'use strict'
244// base-x encoding / decoding
245// Copyright (c) 2018 base-x contributors
246// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
247// Distributed under the MIT software license, see the accompanying
248// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
249// @ts-ignore
250var _Buffer = require('safe-buffer').Buffer
251function base (ALPHABET) {
252 if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
253 var BASE_MAP = new Uint8Array(256)
254 BASE_MAP.fill(255)
255 for (var i = 0; i < ALPHABET.length; i++) {
256 var x = ALPHABET.charAt(i)
257 var xc = x.charCodeAt(0)
258 if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
259 BASE_MAP[xc] = i
260 }
261 var BASE = ALPHABET.length
262 var LEADER = ALPHABET.charAt(0)
263 var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
264 var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
265 function encode (source) {
266 if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') }
267 if (source.length === 0) { return '' }
268 // Skip & count leading zeroes.
269 var zeroes = 0
270 var length = 0
271 var pbegin = 0
272 var pend = source.length
273 while (pbegin !== pend && source[pbegin] === 0) {
274 pbegin++
275 zeroes++
276 }
277 // Allocate enough space in big-endian base58 representation.
278 var size = ((pend - pbegin) * iFACTOR + 1) >>> 0
279 var b58 = new Uint8Array(size)
280 // Process the bytes.
281 while (pbegin !== pend) {
282 var carry = source[pbegin]
283 // Apply "b58 = b58 * 256 + ch".
284 var i = 0
285 for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
286 carry += (256 * b58[it1]) >>> 0
287 b58[it1] = (carry % BASE) >>> 0
288 carry = (carry / BASE) >>> 0
289 }
290 if (carry !== 0) { throw new Error('Non-zero carry') }
291 length = i
292 pbegin++
293 }
294 // Skip leading zeroes in base58 result.
295 var it2 = size - length
296 while (it2 !== size && b58[it2] === 0) {
297 it2++
298 }
299 // Translate the result into a string.
300 var str = LEADER.repeat(zeroes)
301 for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) }
302 return str
303 }
304 function decodeUnsafe (source) {
305 if (typeof source !== 'string') { throw new TypeError('Expected String') }
306 if (source.length === 0) { return _Buffer.alloc(0) }
307 var psz = 0
308 // Skip leading spaces.
309 if (source[psz] === ' ') { return }
310 // Skip and count leading '1's.
311 var zeroes = 0
312 var length = 0
313 while (source[psz] === LEADER) {
314 zeroes++
315 psz++
316 }
317 // Allocate enough space in big-endian base256 representation.
318 var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
319 var b256 = new Uint8Array(size)
320 // Process the characters.
321 while (source[psz]) {
322 // Decode character
323 var carry = BASE_MAP[source.charCodeAt(psz)]
324 // Invalid character
325 if (carry === 255) { return }
326 var i = 0
327 for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
328 carry += (BASE * b256[it3]) >>> 0
329 b256[it3] = (carry % 256) >>> 0
330 carry = (carry / 256) >>> 0
331 }
332 if (carry !== 0) { throw new Error('Non-zero carry') }
333 length = i
334 psz++
335 }
336 // Skip trailing spaces.
337 if (source[psz] === ' ') { return }
338 // Skip leading zeroes in b256.
339 var it4 = size - length
340 while (it4 !== size && b256[it4] === 0) {
341 it4++
342 }
343 var vch = _Buffer.allocUnsafe(zeroes + (size - it4))
344 vch.fill(0x00, 0, zeroes)
345 var j = zeroes
346 while (it4 !== size) {
347 vch[j++] = b256[it4++]
348 }
349 return vch
350 }
351 function decode (string) {
352 var buffer = decodeUnsafe(string)
353 if (buffer) { return buffer }
354 throw new Error('Non-base' + BASE + ' character')
355 }
356 return {
357 encode: encode,
358 decodeUnsafe: decodeUnsafe,
359 decode: decode
360 }
361}
362module.exports = base
363
364},{"safe-buffer":47}],3:[function(require,module,exports){
365// (public) Constructor
366function BigInteger(a, b, c) {
367 if (!(this instanceof BigInteger))
368 return new BigInteger(a, b, c)
369
370 if (a != null) {
371 if ("number" == typeof a) this.fromNumber(a, b, c)
372 else if (b == null && "string" != typeof a) this.fromString(a, 256)
373 else this.fromString(a, b)
374 }
375}
376
377var proto = BigInteger.prototype
378
379// duck-typed isBigInteger
380proto.__bigi = require('../package.json').version
381BigInteger.isBigInteger = function (obj, check_ver) {
382 return obj && obj.__bigi && (!check_ver || obj.__bigi === proto.__bigi)
383}
384
385// Bits per digit
386var dbits
387
388// am: Compute w_j += (x*this_i), propagate carries,
389// c is initial carry, returns final carry.
390// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
391// We need to select the fastest one that works in this environment.
392
393// am1: use a single mult and divide to get the high bits,
394// max digit bits should be 26 because
395// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
396function am1(i, x, w, j, c, n) {
397 while (--n >= 0) {
398 var v = x * this[i++] + w[j] + c
399 c = Math.floor(v / 0x4000000)
400 w[j++] = v & 0x3ffffff
401 }
402 return c
403}
404// am2 avoids a big mult-and-extract completely.
405// Max digit bits should be <= 30 because we do bitwise ops
406// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
407function am2(i, x, w, j, c, n) {
408 var xl = x & 0x7fff,
409 xh = x >> 15
410 while (--n >= 0) {
411 var l = this[i] & 0x7fff
412 var h = this[i++] >> 15
413 var m = xh * l + h * xl
414 l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff)
415 c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30)
416 w[j++] = l & 0x3fffffff
417 }
418 return c
419}
420// Alternately, set max digit bits to 28 since some
421// browsers slow down when dealing with 32-bit numbers.
422function am3(i, x, w, j, c, n) {
423 var xl = x & 0x3fff,
424 xh = x >> 14
425 while (--n >= 0) {
426 var l = this[i] & 0x3fff
427 var h = this[i++] >> 14
428 var m = xh * l + h * xl
429 l = xl * l + ((m & 0x3fff) << 14) + w[j] + c
430 c = (l >> 28) + (m >> 14) + xh * h
431 w[j++] = l & 0xfffffff
432 }
433 return c
434}
435
436// wtf?
437BigInteger.prototype.am = am1
438dbits = 26
439
440BigInteger.prototype.DB = dbits
441BigInteger.prototype.DM = ((1 << dbits) - 1)
442var DV = BigInteger.prototype.DV = (1 << dbits)
443
444var BI_FP = 52
445BigInteger.prototype.FV = Math.pow(2, BI_FP)
446BigInteger.prototype.F1 = BI_FP - dbits
447BigInteger.prototype.F2 = 2 * dbits - BI_FP
448
449// Digit conversions
450var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"
451var BI_RC = new Array()
452var rr, vv
453rr = "0".charCodeAt(0)
454for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv
455rr = "a".charCodeAt(0)
456for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv
457rr = "A".charCodeAt(0)
458for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv
459
460function int2char(n) {
461 return BI_RM.charAt(n)
462}
463
464function intAt(s, i) {
465 var c = BI_RC[s.charCodeAt(i)]
466 return (c == null) ? -1 : c
467}
468
469// (protected) copy this to r
470function bnpCopyTo(r) {
471 for (var i = this.t - 1; i >= 0; --i) r[i] = this[i]
472 r.t = this.t
473 r.s = this.s
474}
475
476// (protected) set from integer value x, -DV <= x < DV
477function bnpFromInt(x) {
478 this.t = 1
479 this.s = (x < 0) ? -1 : 0
480 if (x > 0) this[0] = x
481 else if (x < -1) this[0] = x + DV
482 else this.t = 0
483}
484
485// return bigint initialized to value
486function nbv(i) {
487 var r = new BigInteger()
488 r.fromInt(i)
489 return r
490}
491
492// (protected) set from string and radix
493function bnpFromString(s, b) {
494 var self = this
495
496 var k
497 if (b == 16) k = 4
498 else if (b == 8) k = 3
499 else if (b == 256) k = 8; // byte array
500 else if (b == 2) k = 1
501 else if (b == 32) k = 5
502 else if (b == 4) k = 2
503 else {
504 self.fromRadix(s, b)
505 return
506 }
507 self.t = 0
508 self.s = 0
509 var i = s.length,
510 mi = false,
511 sh = 0
512 while (--i >= 0) {
513 var x = (k == 8) ? s[i] & 0xff : intAt(s, i)
514 if (x < 0) {
515 if (s.charAt(i) == "-") mi = true
516 continue
517 }
518 mi = false
519 if (sh == 0)
520 self[self.t++] = x
521 else if (sh + k > self.DB) {
522 self[self.t - 1] |= (x & ((1 << (self.DB - sh)) - 1)) << sh
523 self[self.t++] = (x >> (self.DB - sh))
524 } else
525 self[self.t - 1] |= x << sh
526 sh += k
527 if (sh >= self.DB) sh -= self.DB
528 }
529 if (k == 8 && (s[0] & 0x80) != 0) {
530 self.s = -1
531 if (sh > 0) self[self.t - 1] |= ((1 << (self.DB - sh)) - 1) << sh
532 }
533 self.clamp()
534 if (mi) BigInteger.ZERO.subTo(self, self)
535}
536
537// (protected) clamp off excess high words
538function bnpClamp() {
539 var c = this.s & this.DM
540 while (this.t > 0 && this[this.t - 1] == c)--this.t
541}
542
543// (public) return string representation in given radix
544function bnToString(b) {
545 var self = this
546 if (self.s < 0) return "-" + self.negate()
547 .toString(b)
548 var k
549 if (b == 16) k = 4
550 else if (b == 8) k = 3
551 else if (b == 2) k = 1
552 else if (b == 32) k = 5
553 else if (b == 4) k = 2
554 else return self.toRadix(b)
555 var km = (1 << k) - 1,
556 d, m = false,
557 r = "",
558 i = self.t
559 var p = self.DB - (i * self.DB) % k
560 if (i-- > 0) {
561 if (p < self.DB && (d = self[i] >> p) > 0) {
562 m = true
563 r = int2char(d)
564 }
565 while (i >= 0) {
566 if (p < k) {
567 d = (self[i] & ((1 << p) - 1)) << (k - p)
568 d |= self[--i] >> (p += self.DB - k)
569 } else {
570 d = (self[i] >> (p -= k)) & km
571 if (p <= 0) {
572 p += self.DB
573 --i
574 }
575 }
576 if (d > 0) m = true
577 if (m) r += int2char(d)
578 }
579 }
580 return m ? r : "0"
581}
582
583// (public) -this
584function bnNegate() {
585 var r = new BigInteger()
586 BigInteger.ZERO.subTo(this, r)
587 return r
588}
589
590// (public) |this|
591function bnAbs() {
592 return (this.s < 0) ? this.negate() : this
593}
594
595// (public) return + if this > a, - if this < a, 0 if equal
596function bnCompareTo(a) {
597 var r = this.s - a.s
598 if (r != 0) return r
599 var i = this.t
600 r = i - a.t
601 if (r != 0) return (this.s < 0) ? -r : r
602 while (--i >= 0)
603 if ((r = this[i] - a[i]) != 0) return r
604 return 0
605}
606
607// returns bit length of the integer x
608function nbits(x) {
609 var r = 1,
610 t
611 if ((t = x >>> 16) != 0) {
612 x = t
613 r += 16
614 }
615 if ((t = x >> 8) != 0) {
616 x = t
617 r += 8
618 }
619 if ((t = x >> 4) != 0) {
620 x = t
621 r += 4
622 }
623 if ((t = x >> 2) != 0) {
624 x = t
625 r += 2
626 }
627 if ((t = x >> 1) != 0) {
628 x = t
629 r += 1
630 }
631 return r
632}
633
634// (public) return the number of bits in "this"
635function bnBitLength() {
636 if (this.t <= 0) return 0
637 return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM))
638}
639
640// (public) return the number of bytes in "this"
641function bnByteLength() {
642 return this.bitLength() >> 3
643}
644
645// (protected) r = this << n*DB
646function bnpDLShiftTo(n, r) {
647 var i
648 for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i]
649 for (i = n - 1; i >= 0; --i) r[i] = 0
650 r.t = this.t + n
651 r.s = this.s
652}
653
654// (protected) r = this >> n*DB
655function bnpDRShiftTo(n, r) {
656 for (var i = n; i < this.t; ++i) r[i - n] = this[i]
657 r.t = Math.max(this.t - n, 0)
658 r.s = this.s
659}
660
661// (protected) r = this << n
662function bnpLShiftTo(n, r) {
663 var self = this
664 var bs = n % self.DB
665 var cbs = self.DB - bs
666 var bm = (1 << cbs) - 1
667 var ds = Math.floor(n / self.DB),
668 c = (self.s << bs) & self.DM,
669 i
670 for (i = self.t - 1; i >= 0; --i) {
671 r[i + ds + 1] = (self[i] >> cbs) | c
672 c = (self[i] & bm) << bs
673 }
674 for (i = ds - 1; i >= 0; --i) r[i] = 0
675 r[ds] = c
676 r.t = self.t + ds + 1
677 r.s = self.s
678 r.clamp()
679}
680
681// (protected) r = this >> n
682function bnpRShiftTo(n, r) {
683 var self = this
684 r.s = self.s
685 var ds = Math.floor(n / self.DB)
686 if (ds >= self.t) {
687 r.t = 0
688 return
689 }
690 var bs = n % self.DB
691 var cbs = self.DB - bs
692 var bm = (1 << bs) - 1
693 r[0] = self[ds] >> bs
694 for (var i = ds + 1; i < self.t; ++i) {
695 r[i - ds - 1] |= (self[i] & bm) << cbs
696 r[i - ds] = self[i] >> bs
697 }
698 if (bs > 0) r[self.t - ds - 1] |= (self.s & bm) << cbs
699 r.t = self.t - ds
700 r.clamp()
701}
702
703// (protected) r = this - a
704function bnpSubTo(a, r) {
705 var self = this
706 var i = 0,
707 c = 0,
708 m = Math.min(a.t, self.t)
709 while (i < m) {
710 c += self[i] - a[i]
711 r[i++] = c & self.DM
712 c >>= self.DB
713 }
714 if (a.t < self.t) {
715 c -= a.s
716 while (i < self.t) {
717 c += self[i]
718 r[i++] = c & self.DM
719 c >>= self.DB
720 }
721 c += self.s
722 } else {
723 c += self.s
724 while (i < a.t) {
725 c -= a[i]
726 r[i++] = c & self.DM
727 c >>= self.DB
728 }
729 c -= a.s
730 }
731 r.s = (c < 0) ? -1 : 0
732 if (c < -1) r[i++] = self.DV + c
733 else if (c > 0) r[i++] = c
734 r.t = i
735 r.clamp()
736}
737
738// (protected) r = this * a, r != this,a (HAC 14.12)
739// "this" should be the larger one if appropriate.
740function bnpMultiplyTo(a, r) {
741 var x = this.abs(),
742 y = a.abs()
743 var i = x.t
744 r.t = i + y.t
745 while (--i >= 0) r[i] = 0
746 for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t)
747 r.s = 0
748 r.clamp()
749 if (this.s != a.s) BigInteger.ZERO.subTo(r, r)
750}
751
752// (protected) r = this^2, r != this (HAC 14.16)
753function bnpSquareTo(r) {
754 var x = this.abs()
755 var i = r.t = 2 * x.t
756 while (--i >= 0) r[i] = 0
757 for (i = 0; i < x.t - 1; ++i) {
758 var c = x.am(i, x[i], r, 2 * i, 0, 1)
759 if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
760 r[i + x.t] -= x.DV
761 r[i + x.t + 1] = 1
762 }
763 }
764 if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1)
765 r.s = 0
766 r.clamp()
767}
768
769// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
770// r != q, this != m. q or r may be null.
771function bnpDivRemTo(m, q, r) {
772 var self = this
773 var pm = m.abs()
774 if (pm.t <= 0) return
775 var pt = self.abs()
776 if (pt.t < pm.t) {
777 if (q != null) q.fromInt(0)
778 if (r != null) self.copyTo(r)
779 return
780 }
781 if (r == null) r = new BigInteger()
782 var y = new BigInteger(),
783 ts = self.s,
784 ms = m.s
785 var nsh = self.DB - nbits(pm[pm.t - 1]); // normalize modulus
786 if (nsh > 0) {
787 pm.lShiftTo(nsh, y)
788 pt.lShiftTo(nsh, r)
789 } else {
790 pm.copyTo(y)
791 pt.copyTo(r)
792 }
793 var ys = y.t
794 var y0 = y[ys - 1]
795 if (y0 == 0) return
796 var yt = y0 * (1 << self.F1) + ((ys > 1) ? y[ys - 2] >> self.F2 : 0)
797 var d1 = self.FV / yt,
798 d2 = (1 << self.F1) / yt,
799 e = 1 << self.F2
800 var i = r.t,
801 j = i - ys,
802 t = (q == null) ? new BigInteger() : q
803 y.dlShiftTo(j, t)
804 if (r.compareTo(t) >= 0) {
805 r[r.t++] = 1
806 r.subTo(t, r)
807 }
808 BigInteger.ONE.dlShiftTo(ys, t)
809 t.subTo(y, y); // "negative" y so we can replace sub with am later
810 while (y.t < ys) y[y.t++] = 0
811 while (--j >= 0) {
812 // Estimate quotient digit
813 var qd = (r[--i] == y0) ? self.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2)
814 if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
815 y.dlShiftTo(j, t)
816 r.subTo(t, r)
817 while (r[i] < --qd) r.subTo(t, r)
818 }
819 }
820 if (q != null) {
821 r.drShiftTo(ys, q)
822 if (ts != ms) BigInteger.ZERO.subTo(q, q)
823 }
824 r.t = ys
825 r.clamp()
826 if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
827 if (ts < 0) BigInteger.ZERO.subTo(r, r)
828}
829
830// (public) this mod a
831function bnMod(a) {
832 var r = new BigInteger()
833 this.abs()
834 .divRemTo(a, null, r)
835 if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r)
836 return r
837}
838
839// Modular reduction using "classic" algorithm
840function Classic(m) {
841 this.m = m
842}
843
844function cConvert(x) {
845 if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m)
846 else return x
847}
848
849function cRevert(x) {
850 return x
851}
852
853function cReduce(x) {
854 x.divRemTo(this.m, null, x)
855}
856
857function cMulTo(x, y, r) {
858 x.multiplyTo(y, r)
859 this.reduce(r)
860}
861
862function cSqrTo(x, r) {
863 x.squareTo(r)
864 this.reduce(r)
865}
866
867Classic.prototype.convert = cConvert
868Classic.prototype.revert = cRevert
869Classic.prototype.reduce = cReduce
870Classic.prototype.mulTo = cMulTo
871Classic.prototype.sqrTo = cSqrTo
872
873// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
874// justification:
875// xy == 1 (mod m)
876// xy = 1+km
877// xy(2-xy) = (1+km)(1-km)
878// x[y(2-xy)] = 1-k^2m^2
879// x[y(2-xy)] == 1 (mod m^2)
880// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
881// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
882// JS multiply "overflows" differently from C/C++, so care is needed here.
883function bnpInvDigit() {
884 if (this.t < 1) return 0
885 var x = this[0]
886 if ((x & 1) == 0) return 0
887 var y = x & 3; // y == 1/x mod 2^2
888 y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
889 y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
890 y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
891 // last step - calculate inverse mod DV directly
892 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
893 y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
894 // we really want the negative inverse, and -DV < y < DV
895 return (y > 0) ? this.DV - y : -y
896}
897
898// Montgomery reduction
899function Montgomery(m) {
900 this.m = m
901 this.mp = m.invDigit()
902 this.mpl = this.mp & 0x7fff
903 this.mph = this.mp >> 15
904 this.um = (1 << (m.DB - 15)) - 1
905 this.mt2 = 2 * m.t
906}
907
908// xR mod m
909function montConvert(x) {
910 var r = new BigInteger()
911 x.abs()
912 .dlShiftTo(this.m.t, r)
913 r.divRemTo(this.m, null, r)
914 if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r)
915 return r
916}
917
918// x/R mod m
919function montRevert(x) {
920 var r = new BigInteger()
921 x.copyTo(r)
922 this.reduce(r)
923 return r
924}
925
926// x = x/R mod m (HAC 14.32)
927function montReduce(x) {
928 while (x.t <= this.mt2) // pad x so am has enough room later
929 x[x.t++] = 0
930 for (var i = 0; i < this.m.t; ++i) {
931 // faster way of calculating u0 = x[i]*mp mod DV
932 var j = x[i] & 0x7fff
933 var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM
934 // use am to combine the multiply-shift-add into one call
935 j = i + this.m.t
936 x[j] += this.m.am(0, u0, x, i, 0, this.m.t)
937 // propagate carry
938 while (x[j] >= x.DV) {
939 x[j] -= x.DV
940 x[++j]++
941 }
942 }
943 x.clamp()
944 x.drShiftTo(this.m.t, x)
945 if (x.compareTo(this.m) >= 0) x.subTo(this.m, x)
946}
947
948// r = "x^2/R mod m"; x != r
949function montSqrTo(x, r) {
950 x.squareTo(r)
951 this.reduce(r)
952}
953
954// r = "xy/R mod m"; x,y != r
955function montMulTo(x, y, r) {
956 x.multiplyTo(y, r)
957 this.reduce(r)
958}
959
960Montgomery.prototype.convert = montConvert
961Montgomery.prototype.revert = montRevert
962Montgomery.prototype.reduce = montReduce
963Montgomery.prototype.mulTo = montMulTo
964Montgomery.prototype.sqrTo = montSqrTo
965
966// (protected) true iff this is even
967function bnpIsEven() {
968 return ((this.t > 0) ? (this[0] & 1) : this.s) == 0
969}
970
971// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
972function bnpExp(e, z) {
973 if (e > 0xffffffff || e < 1) return BigInteger.ONE
974 var r = new BigInteger(),
975 r2 = new BigInteger(),
976 g = z.convert(this),
977 i = nbits(e) - 1
978 g.copyTo(r)
979 while (--i >= 0) {
980 z.sqrTo(r, r2)
981 if ((e & (1 << i)) > 0) z.mulTo(r2, g, r)
982 else {
983 var t = r
984 r = r2
985 r2 = t
986 }
987 }
988 return z.revert(r)
989}
990
991// (public) this^e % m, 0 <= e < 2^32
992function bnModPowInt(e, m) {
993 var z
994 if (e < 256 || m.isEven()) z = new Classic(m)
995 else z = new Montgomery(m)
996 return this.exp(e, z)
997}
998
999// protected
1000proto.copyTo = bnpCopyTo
1001proto.fromInt = bnpFromInt
1002proto.fromString = bnpFromString
1003proto.clamp = bnpClamp
1004proto.dlShiftTo = bnpDLShiftTo
1005proto.drShiftTo = bnpDRShiftTo
1006proto.lShiftTo = bnpLShiftTo
1007proto.rShiftTo = bnpRShiftTo
1008proto.subTo = bnpSubTo
1009proto.multiplyTo = bnpMultiplyTo
1010proto.squareTo = bnpSquareTo
1011proto.divRemTo = bnpDivRemTo
1012proto.invDigit = bnpInvDigit
1013proto.isEven = bnpIsEven
1014proto.exp = bnpExp
1015
1016// public
1017proto.toString = bnToString
1018proto.negate = bnNegate
1019proto.abs = bnAbs
1020proto.compareTo = bnCompareTo
1021proto.bitLength = bnBitLength
1022proto.byteLength = bnByteLength
1023proto.mod = bnMod
1024proto.modPowInt = bnModPowInt
1025
1026// (public)
1027function bnClone() {
1028 var r = new BigInteger()
1029 this.copyTo(r)
1030 return r
1031}
1032
1033// (public) return value as integer
1034function bnIntValue() {
1035 if (this.s < 0) {
1036 if (this.t == 1) return this[0] - this.DV
1037 else if (this.t == 0) return -1
1038 } else if (this.t == 1) return this[0]
1039 else if (this.t == 0) return 0
1040 // assumes 16 < DB < 32
1041 return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]
1042}
1043
1044// (public) return value as byte
1045function bnByteValue() {
1046 return (this.t == 0) ? this.s : (this[0] << 24) >> 24
1047}
1048
1049// (public) return value as short (assumes DB>=16)
1050function bnShortValue() {
1051 return (this.t == 0) ? this.s : (this[0] << 16) >> 16
1052}
1053
1054// (protected) return x s.t. r^x < DV
1055function bnpChunkSize(r) {
1056 return Math.floor(Math.LN2 * this.DB / Math.log(r))
1057}
1058
1059// (public) 0 if this == 0, 1 if this > 0
1060function bnSigNum() {
1061 if (this.s < 0) return -1
1062 else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0
1063 else return 1
1064}
1065
1066// (protected) convert to radix string
1067function bnpToRadix(b) {
1068 if (b == null) b = 10
1069 if (this.signum() == 0 || b < 2 || b > 36) return "0"
1070 var cs = this.chunkSize(b)
1071 var a = Math.pow(b, cs)
1072 var d = nbv(a),
1073 y = new BigInteger(),
1074 z = new BigInteger(),
1075 r = ""
1076 this.divRemTo(d, y, z)
1077 while (y.signum() > 0) {
1078 r = (a + z.intValue())
1079 .toString(b)
1080 .substr(1) + r
1081 y.divRemTo(d, y, z)
1082 }
1083 return z.intValue()
1084 .toString(b) + r
1085}
1086
1087// (protected) convert from radix string
1088function bnpFromRadix(s, b) {
1089 var self = this
1090 self.fromInt(0)
1091 if (b == null) b = 10
1092 var cs = self.chunkSize(b)
1093 var d = Math.pow(b, cs),
1094 mi = false,
1095 j = 0,
1096 w = 0
1097 for (var i = 0; i < s.length; ++i) {
1098 var x = intAt(s, i)
1099 if (x < 0) {
1100 if (s.charAt(i) == "-" && self.signum() == 0) mi = true
1101 continue
1102 }
1103 w = b * w + x
1104 if (++j >= cs) {
1105 self.dMultiply(d)
1106 self.dAddOffset(w, 0)
1107 j = 0
1108 w = 0
1109 }
1110 }
1111 if (j > 0) {
1112 self.dMultiply(Math.pow(b, j))
1113 self.dAddOffset(w, 0)
1114 }
1115 if (mi) BigInteger.ZERO.subTo(self, self)
1116}
1117
1118// (protected) alternate constructor
1119function bnpFromNumber(a, b, c) {
1120 var self = this
1121 if ("number" == typeof b) {
1122 // new BigInteger(int,int,RNG)
1123 if (a < 2) self.fromInt(1)
1124 else {
1125 self.fromNumber(a, c)
1126 if (!self.testBit(a - 1)) // force MSB set
1127 self.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, self)
1128 if (self.isEven()) self.dAddOffset(1, 0); // force odd
1129 while (!self.isProbablePrime(b)) {
1130 self.dAddOffset(2, 0)
1131 if (self.bitLength() > a) self.subTo(BigInteger.ONE.shiftLeft(a - 1), self)
1132 }
1133 }
1134 } else {
1135 // new BigInteger(int,RNG)
1136 var x = new Array(),
1137 t = a & 7
1138 x.length = (a >> 3) + 1
1139 b.nextBytes(x)
1140 if (t > 0) x[0] &= ((1 << t) - 1)
1141 else x[0] = 0
1142 self.fromString(x, 256)
1143 }
1144}
1145
1146// (public) convert to bigendian byte array
1147function bnToByteArray() {
1148 var self = this
1149 var i = self.t,
1150 r = new Array()
1151 r[0] = self.s
1152 var p = self.DB - (i * self.DB) % 8,
1153 d, k = 0
1154 if (i-- > 0) {
1155 if (p < self.DB && (d = self[i] >> p) != (self.s & self.DM) >> p)
1156 r[k++] = d | (self.s << (self.DB - p))
1157 while (i >= 0) {
1158 if (p < 8) {
1159 d = (self[i] & ((1 << p) - 1)) << (8 - p)
1160 d |= self[--i] >> (p += self.DB - 8)
1161 } else {
1162 d = (self[i] >> (p -= 8)) & 0xff
1163 if (p <= 0) {
1164 p += self.DB
1165 --i
1166 }
1167 }
1168 if ((d & 0x80) != 0) d |= -256
1169 if (k === 0 && (self.s & 0x80) != (d & 0x80))++k
1170 if (k > 0 || d != self.s) r[k++] = d
1171 }
1172 }
1173 return r
1174}
1175
1176function bnEquals(a) {
1177 return (this.compareTo(a) == 0)
1178}
1179
1180function bnMin(a) {
1181 return (this.compareTo(a) < 0) ? this : a
1182}
1183
1184function bnMax(a) {
1185 return (this.compareTo(a) > 0) ? this : a
1186}
1187
1188// (protected) r = this op a (bitwise)
1189function bnpBitwiseTo(a, op, r) {
1190 var self = this
1191 var i, f, m = Math.min(a.t, self.t)
1192 for (i = 0; i < m; ++i) r[i] = op(self[i], a[i])
1193 if (a.t < self.t) {
1194 f = a.s & self.DM
1195 for (i = m; i < self.t; ++i) r[i] = op(self[i], f)
1196 r.t = self.t
1197 } else {
1198 f = self.s & self.DM
1199 for (i = m; i < a.t; ++i) r[i] = op(f, a[i])
1200 r.t = a.t
1201 }
1202 r.s = op(self.s, a.s)
1203 r.clamp()
1204}
1205
1206// (public) this & a
1207function op_and(x, y) {
1208 return x & y
1209}
1210
1211function bnAnd(a) {
1212 var r = new BigInteger()
1213 this.bitwiseTo(a, op_and, r)
1214 return r
1215}
1216
1217// (public) this | a
1218function op_or(x, y) {
1219 return x | y
1220}
1221
1222function bnOr(a) {
1223 var r = new BigInteger()
1224 this.bitwiseTo(a, op_or, r)
1225 return r
1226}
1227
1228// (public) this ^ a
1229function op_xor(x, y) {
1230 return x ^ y
1231}
1232
1233function bnXor(a) {
1234 var r = new BigInteger()
1235 this.bitwiseTo(a, op_xor, r)
1236 return r
1237}
1238
1239// (public) this & ~a
1240function op_andnot(x, y) {
1241 return x & ~y
1242}
1243
1244function bnAndNot(a) {
1245 var r = new BigInteger()
1246 this.bitwiseTo(a, op_andnot, r)
1247 return r
1248}
1249
1250// (public) ~this
1251function bnNot() {
1252 var r = new BigInteger()
1253 for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i]
1254 r.t = this.t
1255 r.s = ~this.s
1256 return r
1257}
1258
1259// (public) this << n
1260function bnShiftLeft(n) {
1261 var r = new BigInteger()
1262 if (n < 0) this.rShiftTo(-n, r)
1263 else this.lShiftTo(n, r)
1264 return r
1265}
1266
1267// (public) this >> n
1268function bnShiftRight(n) {
1269 var r = new BigInteger()
1270 if (n < 0) this.lShiftTo(-n, r)
1271 else this.rShiftTo(n, r)
1272 return r
1273}
1274
1275// return index of lowest 1-bit in x, x < 2^31
1276function lbit(x) {
1277 if (x == 0) return -1
1278 var r = 0
1279 if ((x & 0xffff) == 0) {
1280 x >>= 16
1281 r += 16
1282 }
1283 if ((x & 0xff) == 0) {
1284 x >>= 8
1285 r += 8
1286 }
1287 if ((x & 0xf) == 0) {
1288 x >>= 4
1289 r += 4
1290 }
1291 if ((x & 3) == 0) {
1292 x >>= 2
1293 r += 2
1294 }
1295 if ((x & 1) == 0)++r
1296 return r
1297}
1298
1299// (public) returns index of lowest 1-bit (or -1 if none)
1300function bnGetLowestSetBit() {
1301 for (var i = 0; i < this.t; ++i)
1302 if (this[i] != 0) return i * this.DB + lbit(this[i])
1303 if (this.s < 0) return this.t * this.DB
1304 return -1
1305}
1306
1307// return number of 1 bits in x
1308function cbit(x) {
1309 var r = 0
1310 while (x != 0) {
1311 x &= x - 1
1312 ++r
1313 }
1314 return r
1315}
1316
1317// (public) return number of set bits
1318function bnBitCount() {
1319 var r = 0,
1320 x = this.s & this.DM
1321 for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x)
1322 return r
1323}
1324
1325// (public) true iff nth bit is set
1326function bnTestBit(n) {
1327 var j = Math.floor(n / this.DB)
1328 if (j >= this.t) return (this.s != 0)
1329 return ((this[j] & (1 << (n % this.DB))) != 0)
1330}
1331
1332// (protected) this op (1<<n)
1333function bnpChangeBit(n, op) {
1334 var r = BigInteger.ONE.shiftLeft(n)
1335 this.bitwiseTo(r, op, r)
1336 return r
1337}
1338
1339// (public) this | (1<<n)
1340function bnSetBit(n) {
1341 return this.changeBit(n, op_or)
1342}
1343
1344// (public) this & ~(1<<n)
1345function bnClearBit(n) {
1346 return this.changeBit(n, op_andnot)
1347}
1348
1349// (public) this ^ (1<<n)
1350function bnFlipBit(n) {
1351 return this.changeBit(n, op_xor)
1352}
1353
1354// (protected) r = this + a
1355function bnpAddTo(a, r) {
1356 var self = this
1357
1358 var i = 0,
1359 c = 0,
1360 m = Math.min(a.t, self.t)
1361 while (i < m) {
1362 c += self[i] + a[i]
1363 r[i++] = c & self.DM
1364 c >>= self.DB
1365 }
1366 if (a.t < self.t) {
1367 c += a.s
1368 while (i < self.t) {
1369 c += self[i]
1370 r[i++] = c & self.DM
1371 c >>= self.DB
1372 }
1373 c += self.s
1374 } else {
1375 c += self.s
1376 while (i < a.t) {
1377 c += a[i]
1378 r[i++] = c & self.DM
1379 c >>= self.DB
1380 }
1381 c += a.s
1382 }
1383 r.s = (c < 0) ? -1 : 0
1384 if (c > 0) r[i++] = c
1385 else if (c < -1) r[i++] = self.DV + c
1386 r.t = i
1387 r.clamp()
1388}
1389
1390// (public) this + a
1391function bnAdd(a) {
1392 var r = new BigInteger()
1393 this.addTo(a, r)
1394 return r
1395}
1396
1397// (public) this - a
1398function bnSubtract(a) {
1399 var r = new BigInteger()
1400 this.subTo(a, r)
1401 return r
1402}
1403
1404// (public) this * a
1405function bnMultiply(a) {
1406 var r = new BigInteger()
1407 this.multiplyTo(a, r)
1408 return r
1409}
1410
1411// (public) this^2
1412function bnSquare() {
1413 var r = new BigInteger()
1414 this.squareTo(r)
1415 return r
1416}
1417
1418// (public) this / a
1419function bnDivide(a) {
1420 var r = new BigInteger()
1421 this.divRemTo(a, r, null)
1422 return r
1423}
1424
1425// (public) this % a
1426function bnRemainder(a) {
1427 var r = new BigInteger()
1428 this.divRemTo(a, null, r)
1429 return r
1430}
1431
1432// (public) [this/a,this%a]
1433function bnDivideAndRemainder(a) {
1434 var q = new BigInteger(),
1435 r = new BigInteger()
1436 this.divRemTo(a, q, r)
1437 return new Array(q, r)
1438}
1439
1440// (protected) this *= n, this >= 0, 1 < n < DV
1441function bnpDMultiply(n) {
1442 this[this.t] = this.am(0, n - 1, this, 0, 0, this.t)
1443 ++this.t
1444 this.clamp()
1445}
1446
1447// (protected) this += n << w words, this >= 0
1448function bnpDAddOffset(n, w) {
1449 if (n == 0) return
1450 while (this.t <= w) this[this.t++] = 0
1451 this[w] += n
1452 while (this[w] >= this.DV) {
1453 this[w] -= this.DV
1454 if (++w >= this.t) this[this.t++] = 0
1455 ++this[w]
1456 }
1457}
1458
1459// A "null" reducer
1460function NullExp() {}
1461
1462function nNop(x) {
1463 return x
1464}
1465
1466function nMulTo(x, y, r) {
1467 x.multiplyTo(y, r)
1468}
1469
1470function nSqrTo(x, r) {
1471 x.squareTo(r)
1472}
1473
1474NullExp.prototype.convert = nNop
1475NullExp.prototype.revert = nNop
1476NullExp.prototype.mulTo = nMulTo
1477NullExp.prototype.sqrTo = nSqrTo
1478
1479// (public) this^e
1480function bnPow(e) {
1481 return this.exp(e, new NullExp())
1482}
1483
1484// (protected) r = lower n words of "this * a", a.t <= n
1485// "this" should be the larger one if appropriate.
1486function bnpMultiplyLowerTo(a, n, r) {
1487 var i = Math.min(this.t + a.t, n)
1488 r.s = 0; // assumes a,this >= 0
1489 r.t = i
1490 while (i > 0) r[--i] = 0
1491 var j
1492 for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t)
1493 for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i)
1494 r.clamp()
1495}
1496
1497// (protected) r = "this * a" without lower n words, n > 0
1498// "this" should be the larger one if appropriate.
1499function bnpMultiplyUpperTo(a, n, r) {
1500 --n
1501 var i = r.t = this.t + a.t - n
1502 r.s = 0; // assumes a,this >= 0
1503 while (--i >= 0) r[i] = 0
1504 for (i = Math.max(n - this.t, 0); i < a.t; ++i)
1505 r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n)
1506 r.clamp()
1507 r.drShiftTo(1, r)
1508}
1509
1510// Barrett modular reduction
1511function Barrett(m) {
1512 // setup Barrett
1513 this.r2 = new BigInteger()
1514 this.q3 = new BigInteger()
1515 BigInteger.ONE.dlShiftTo(2 * m.t, this.r2)
1516 this.mu = this.r2.divide(m)
1517 this.m = m
1518}
1519
1520function barrettConvert(x) {
1521 if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m)
1522 else if (x.compareTo(this.m) < 0) return x
1523 else {
1524 var r = new BigInteger()
1525 x.copyTo(r)
1526 this.reduce(r)
1527 return r
1528 }
1529}
1530
1531function barrettRevert(x) {
1532 return x
1533}
1534
1535// x = x mod m (HAC 14.42)
1536function barrettReduce(x) {
1537 var self = this
1538 x.drShiftTo(self.m.t - 1, self.r2)
1539 if (x.t > self.m.t + 1) {
1540 x.t = self.m.t + 1
1541 x.clamp()
1542 }
1543 self.mu.multiplyUpperTo(self.r2, self.m.t + 1, self.q3)
1544 self.m.multiplyLowerTo(self.q3, self.m.t + 1, self.r2)
1545 while (x.compareTo(self.r2) < 0) x.dAddOffset(1, self.m.t + 1)
1546 x.subTo(self.r2, x)
1547 while (x.compareTo(self.m) >= 0) x.subTo(self.m, x)
1548}
1549
1550// r = x^2 mod m; x != r
1551function barrettSqrTo(x, r) {
1552 x.squareTo(r)
1553 this.reduce(r)
1554}
1555
1556// r = x*y mod m; x,y != r
1557function barrettMulTo(x, y, r) {
1558 x.multiplyTo(y, r)
1559 this.reduce(r)
1560}
1561
1562Barrett.prototype.convert = barrettConvert
1563Barrett.prototype.revert = barrettRevert
1564Barrett.prototype.reduce = barrettReduce
1565Barrett.prototype.mulTo = barrettMulTo
1566Barrett.prototype.sqrTo = barrettSqrTo
1567
1568// (public) this^e % m (HAC 14.85)
1569function bnModPow(e, m) {
1570 var i = e.bitLength(),
1571 k, r = nbv(1),
1572 z
1573 if (i <= 0) return r
1574 else if (i < 18) k = 1
1575 else if (i < 48) k = 3
1576 else if (i < 144) k = 4
1577 else if (i < 768) k = 5
1578 else k = 6
1579 if (i < 8)
1580 z = new Classic(m)
1581 else if (m.isEven())
1582 z = new Barrett(m)
1583 else
1584 z = new Montgomery(m)
1585
1586 // precomputation
1587 var g = new Array(),
1588 n = 3,
1589 k1 = k - 1,
1590 km = (1 << k) - 1
1591 g[1] = z.convert(this)
1592 if (k > 1) {
1593 var g2 = new BigInteger()
1594 z.sqrTo(g[1], g2)
1595 while (n <= km) {
1596 g[n] = new BigInteger()
1597 z.mulTo(g2, g[n - 2], g[n])
1598 n += 2
1599 }
1600 }
1601
1602 var j = e.t - 1,
1603 w, is1 = true,
1604 r2 = new BigInteger(),
1605 t
1606 i = nbits(e[j]) - 1
1607 while (j >= 0) {
1608 if (i >= k1) w = (e[j] >> (i - k1)) & km
1609 else {
1610 w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i)
1611 if (j > 0) w |= e[j - 1] >> (this.DB + i - k1)
1612 }
1613
1614 n = k
1615 while ((w & 1) == 0) {
1616 w >>= 1
1617 --n
1618 }
1619 if ((i -= n) < 0) {
1620 i += this.DB
1621 --j
1622 }
1623 if (is1) { // ret == 1, don't bother squaring or multiplying it
1624 g[w].copyTo(r)
1625 is1 = false
1626 } else {
1627 while (n > 1) {
1628 z.sqrTo(r, r2)
1629 z.sqrTo(r2, r)
1630 n -= 2
1631 }
1632 if (n > 0) z.sqrTo(r, r2)
1633 else {
1634 t = r
1635 r = r2
1636 r2 = t
1637 }
1638 z.mulTo(r2, g[w], r)
1639 }
1640
1641 while (j >= 0 && (e[j] & (1 << i)) == 0) {
1642 z.sqrTo(r, r2)
1643 t = r
1644 r = r2
1645 r2 = t
1646 if (--i < 0) {
1647 i = this.DB - 1
1648 --j
1649 }
1650 }
1651 }
1652 return z.revert(r)
1653}
1654
1655// (public) gcd(this,a) (HAC 14.54)
1656function bnGCD(a) {
1657 var x = (this.s < 0) ? this.negate() : this.clone()
1658 var y = (a.s < 0) ? a.negate() : a.clone()
1659 if (x.compareTo(y) < 0) {
1660 var t = x
1661 x = y
1662 y = t
1663 }
1664 var i = x.getLowestSetBit(),
1665 g = y.getLowestSetBit()
1666 if (g < 0) return x
1667 if (i < g) g = i
1668 if (g > 0) {
1669 x.rShiftTo(g, x)
1670 y.rShiftTo(g, y)
1671 }
1672 while (x.signum() > 0) {
1673 if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x)
1674 if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y)
1675 if (x.compareTo(y) >= 0) {
1676 x.subTo(y, x)
1677 x.rShiftTo(1, x)
1678 } else {
1679 y.subTo(x, y)
1680 y.rShiftTo(1, y)
1681 }
1682 }
1683 if (g > 0) y.lShiftTo(g, y)
1684 return y
1685}
1686
1687// (protected) this % n, n < 2^26
1688function bnpModInt(n) {
1689 if (n <= 0) return 0
1690 var d = this.DV % n,
1691 r = (this.s < 0) ? n - 1 : 0
1692 if (this.t > 0)
1693 if (d == 0) r = this[0] % n
1694 else
1695 for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n
1696 return r
1697}
1698
1699// (public) 1/this % m (HAC 14.61)
1700function bnModInverse(m) {
1701 var ac = m.isEven()
1702 if (this.signum() === 0) throw new Error('division by zero')
1703 if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO
1704 var u = m.clone(),
1705 v = this.clone()
1706 var a = nbv(1),
1707 b = nbv(0),
1708 c = nbv(0),
1709 d = nbv(1)
1710 while (u.signum() != 0) {
1711 while (u.isEven()) {
1712 u.rShiftTo(1, u)
1713 if (ac) {
1714 if (!a.isEven() || !b.isEven()) {
1715 a.addTo(this, a)
1716 b.subTo(m, b)
1717 }
1718 a.rShiftTo(1, a)
1719 } else if (!b.isEven()) b.subTo(m, b)
1720 b.rShiftTo(1, b)
1721 }
1722 while (v.isEven()) {
1723 v.rShiftTo(1, v)
1724 if (ac) {
1725 if (!c.isEven() || !d.isEven()) {
1726 c.addTo(this, c)
1727 d.subTo(m, d)
1728 }
1729 c.rShiftTo(1, c)
1730 } else if (!d.isEven()) d.subTo(m, d)
1731 d.rShiftTo(1, d)
1732 }
1733 if (u.compareTo(v) >= 0) {
1734 u.subTo(v, u)
1735 if (ac) a.subTo(c, a)
1736 b.subTo(d, b)
1737 } else {
1738 v.subTo(u, v)
1739 if (ac) c.subTo(a, c)
1740 d.subTo(b, d)
1741 }
1742 }
1743 if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO
1744 while (d.compareTo(m) >= 0) d.subTo(m, d)
1745 while (d.signum() < 0) d.addTo(m, d)
1746 return d
1747}
1748
1749var lowprimes = [
1750 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
1751 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
1752 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
1753 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
1754 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
1755 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
1756 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
1757 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
1758 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811,
1759 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
1760 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
1761]
1762
1763var lplim = (1 << 26) / lowprimes[lowprimes.length - 1]
1764
1765// (public) test primality with certainty >= 1-.5^t
1766function bnIsProbablePrime(t) {
1767 var i, x = this.abs()
1768 if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
1769 for (i = 0; i < lowprimes.length; ++i)
1770 if (x[0] == lowprimes[i]) return true
1771 return false
1772 }
1773 if (x.isEven()) return false
1774 i = 1
1775 while (i < lowprimes.length) {
1776 var m = lowprimes[i],
1777 j = i + 1
1778 while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]
1779 m = x.modInt(m)
1780 while (i < j) if (m % lowprimes[i++] == 0) return false
1781 }
1782 return x.millerRabin(t)
1783}
1784
1785// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1786function bnpMillerRabin(t) {
1787 var n1 = this.subtract(BigInteger.ONE)
1788 var k = n1.getLowestSetBit()
1789 if (k <= 0) return false
1790 var r = n1.shiftRight(k)
1791 t = (t + 1) >> 1
1792 if (t > lowprimes.length) t = lowprimes.length
1793 var a = new BigInteger(null)
1794 var j, bases = []
1795 for (var i = 0; i < t; ++i) {
1796 for (;;) {
1797 j = lowprimes[Math.floor(Math.random() * lowprimes.length)]
1798 if (bases.indexOf(j) == -1) break
1799 }
1800 bases.push(j)
1801 a.fromInt(j)
1802 var y = a.modPow(r, this)
1803 if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1804 var j = 1
1805 while (j++ < k && y.compareTo(n1) != 0) {
1806 y = y.modPowInt(2, this)
1807 if (y.compareTo(BigInteger.ONE) == 0) return false
1808 }
1809 if (y.compareTo(n1) != 0) return false
1810 }
1811 }
1812 return true
1813}
1814
1815// protected
1816proto.chunkSize = bnpChunkSize
1817proto.toRadix = bnpToRadix
1818proto.fromRadix = bnpFromRadix
1819proto.fromNumber = bnpFromNumber
1820proto.bitwiseTo = bnpBitwiseTo
1821proto.changeBit = bnpChangeBit
1822proto.addTo = bnpAddTo
1823proto.dMultiply = bnpDMultiply
1824proto.dAddOffset = bnpDAddOffset
1825proto.multiplyLowerTo = bnpMultiplyLowerTo
1826proto.multiplyUpperTo = bnpMultiplyUpperTo
1827proto.modInt = bnpModInt
1828proto.millerRabin = bnpMillerRabin
1829
1830// public
1831proto.clone = bnClone
1832proto.intValue = bnIntValue
1833proto.byteValue = bnByteValue
1834proto.shortValue = bnShortValue
1835proto.signum = bnSigNum
1836proto.toByteArray = bnToByteArray
1837proto.equals = bnEquals
1838proto.min = bnMin
1839proto.max = bnMax
1840proto.and = bnAnd
1841proto.or = bnOr
1842proto.xor = bnXor
1843proto.andNot = bnAndNot
1844proto.not = bnNot
1845proto.shiftLeft = bnShiftLeft
1846proto.shiftRight = bnShiftRight
1847proto.getLowestSetBit = bnGetLowestSetBit
1848proto.bitCount = bnBitCount
1849proto.testBit = bnTestBit
1850proto.setBit = bnSetBit
1851proto.clearBit = bnClearBit
1852proto.flipBit = bnFlipBit
1853proto.add = bnAdd
1854proto.subtract = bnSubtract
1855proto.multiply = bnMultiply
1856proto.divide = bnDivide
1857proto.remainder = bnRemainder
1858proto.divideAndRemainder = bnDivideAndRemainder
1859proto.modPow = bnModPow
1860proto.modInverse = bnModInverse
1861proto.pow = bnPow
1862proto.gcd = bnGCD
1863proto.isProbablePrime = bnIsProbablePrime
1864
1865// JSBN-specific extension
1866proto.square = bnSquare
1867
1868// constants
1869BigInteger.ZERO = nbv(0)
1870BigInteger.ONE = nbv(1)
1871BigInteger.valueOf = nbv
1872
1873module.exports = BigInteger
1874
1875},{"../package.json":6}],4:[function(require,module,exports){
1876(function (Buffer){
1877// FIXME: Kind of a weird way to throw exceptions, consider removing
1878var assert = require('assert')
1879var BigInteger = require('./bigi')
1880
1881/**
1882 * Turns a byte array into a big integer.
1883 *
1884 * This function will interpret a byte array as a big integer in big
1885 * endian notation.
1886 */
1887BigInteger.fromByteArrayUnsigned = function(byteArray) {
1888 // BigInteger expects a DER integer conformant byte array
1889 if (byteArray[0] & 0x80) {
1890 return new BigInteger([0].concat(byteArray))
1891 }
1892
1893 return new BigInteger(byteArray)
1894}
1895
1896/**
1897 * Returns a byte array representation of the big integer.
1898 *
1899 * This returns the absolute of the contained value in big endian
1900 * form. A value of zero results in an empty array.
1901 */
1902BigInteger.prototype.toByteArrayUnsigned = function() {
1903 var byteArray = this.toByteArray()
1904 return byteArray[0] === 0 ? byteArray.slice(1) : byteArray
1905}
1906
1907BigInteger.fromDERInteger = function(byteArray) {
1908 return new BigInteger(byteArray)
1909}
1910
1911/*
1912 * Converts BigInteger to a DER integer representation.
1913 *
1914 * The format for this value uses the most significant bit as a sign
1915 * bit. If the most significant bit is already set and the integer is
1916 * positive, a 0x00 is prepended.
1917 *
1918 * Examples:
1919 *
1920 * 0 => 0x00
1921 * 1 => 0x01
1922 * -1 => 0xff
1923 * 127 => 0x7f
1924 * -127 => 0x81
1925 * 128 => 0x0080
1926 * -128 => 0x80
1927 * 255 => 0x00ff
1928 * -255 => 0xff01
1929 * 16300 => 0x3fac
1930 * -16300 => 0xc054
1931 * 62300 => 0x00f35c
1932 * -62300 => 0xff0ca4
1933*/
1934BigInteger.prototype.toDERInteger = BigInteger.prototype.toByteArray
1935
1936BigInteger.fromBuffer = function(buffer) {
1937 // BigInteger expects a DER integer conformant byte array
1938 if (buffer[0] & 0x80) {
1939 var byteArray = Array.prototype.slice.call(buffer)
1940
1941 return new BigInteger([0].concat(byteArray))
1942 }
1943
1944 return new BigInteger(buffer)
1945}
1946
1947BigInteger.fromHex = function(hex) {
1948 if (hex === '') return BigInteger.ZERO
1949
1950 assert.equal(hex, hex.match(/^[A-Fa-f0-9]+/), 'Invalid hex string')
1951 assert.equal(hex.length % 2, 0, 'Incomplete hex')
1952 return new BigInteger(hex, 16)
1953}
1954
1955BigInteger.prototype.toBuffer = function(size) {
1956 var byteArray = this.toByteArrayUnsigned()
1957 var zeros = []
1958
1959 var padding = size - byteArray.length
1960 while (zeros.length < padding) zeros.push(0)
1961
1962 return new Buffer(zeros.concat(byteArray))
1963}
1964
1965BigInteger.prototype.toHex = function(size) {
1966 return this.toBuffer(size).toString('hex')
1967}
1968
1969}).call(this,require("buffer").Buffer)
1970},{"./bigi":3,"assert":74,"buffer":110}],5:[function(require,module,exports){
1971var BigInteger = require('./bigi')
1972
1973//addons
1974require('./convert')
1975
1976module.exports = BigInteger
1977},{"./bigi":3,"./convert":4}],6:[function(require,module,exports){
1978module.exports={
1979 "_args": [
1980 [
1981 "bigi@^1.2.0",
1982 "/home/hashengineering/hashengineering/bip38grs"
1983 ]
1984 ],
1985 "_from": "bigi@>=1.2.0 <2.0.0",
1986 "_id": "bigi@1.4.2",
1987 "_inCache": true,
1988 "_installable": true,
1989 "_location": "/bigi",
1990 "_nodeVersion": "6.1.0",
1991 "_npmOperationalInternal": {
1992 "host": "packages-12-west.internal.npmjs.com",
1993 "tmp": "tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"
1994 },
1995 "_npmUser": {
1996 "email": "jprichardson@gmail.com",
1997 "name": "jprichardson"
1998 },
1999 "_npmVersion": "3.8.6",
2000 "_phantomChildren": {},
2001 "_requested": {
2002 "name": "bigi",
2003 "raw": "bigi@^1.2.0",
2004 "rawSpec": "^1.2.0",
2005 "scope": null,
2006 "spec": ">=1.2.0 <2.0.0",
2007 "type": "range"
2008 },
2009 "_requiredBy": [
2010 "/",
2011 "/ecurve"
2012 ],
2013 "_resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
2014 "_shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
2015 "_shrinkwrap": null,
2016 "_spec": "bigi@^1.2.0",
2017 "_where": "/home/hashengineering/hashengineering/bip38grs",
2018 "bugs": {
2019 "url": "https://github.com/cryptocoinjs/bigi/issues"
2020 },
2021 "dependencies": {},
2022 "description": "Big integers.",
2023 "devDependencies": {
2024 "coveralls": "^2.11.2",
2025 "istanbul": "^0.3.5",
2026 "jshint": "^2.5.1",
2027 "mocha": "^2.1.0",
2028 "mochify": "^2.1.0"
2029 },
2030 "directories": {},
2031 "dist": {
2032 "shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
2033 "tarball": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"
2034 },
2035 "gitHead": "c25308081c896ff84702303722bf5ecd8b3f78e3",
2036 "homepage": "https://github.com/cryptocoinjs/bigi#readme",
2037 "keywords": [
2038 "arbitrary",
2039 "arithmetic",
2040 "big",
2041 "bigint",
2042 "biginteger",
2043 "bignumber",
2044 "bitcoin",
2045 "cryptography",
2046 "decimal",
2047 "float",
2048 "int",
2049 "integer",
2050 "math",
2051 "number",
2052 "precision"
2053 ],
2054 "main": "./lib/index.js",
2055 "maintainers": [
2056 {
2057 "name": "midnightlightning",
2058 "email": "boydb@midnightdesign.ws"
2059 },
2060 {
2061 "name": "sidazhang",
2062 "email": "sidazhang89@gmail.com"
2063 },
2064 {
2065 "name": "nadav",
2066 "email": "npm@shesek.info"
2067 },
2068 {
2069 "name": "jprichardson",
2070 "email": "jprichardson@gmail.com"
2071 }
2072 ],
2073 "name": "bigi",
2074 "optionalDependencies": {},
2075 "readme": "ERROR: No README data found!",
2076 "repository": {
2077 "type": "git",
2078 "url": "git+https://github.com/cryptocoinjs/bigi.git"
2079 },
2080 "scripts": {
2081 "browser-test": "mochify --wd -R spec",
2082 "coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",
2083 "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",
2084 "jshint": "jshint --config jshint.json lib/*.js ; true",
2085 "test": "_mocha -- test/*.js",
2086 "unit": "mocha"
2087 },
2088 "testling": {
2089 "browsers": [
2090 "android-browser/4.2..latest",
2091 "chrome/latest",
2092 "firefox/latest",
2093 "ie/9..latest",
2094 "iphone/6.0..latest",
2095 "safari/6.0..latest"
2096 ],
2097 "files": "test/*.js",
2098 "harness": "mocha"
2099 },
2100 "version": "1.4.2"
2101}
2102
2103},{}],7:[function(require,module,exports){
2104// based on the aes implimentation in triple sec
2105// https://github.com/keybase/triplesec
2106// which is in turn based on the one from crypto-js
2107// https://code.google.com/p/crypto-js/
2108
2109var Buffer = require('safe-buffer').Buffer
2110
2111function asUInt32Array (buf) {
2112 if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf)
2113
2114 var len = (buf.length / 4) | 0
2115 var out = new Array(len)
2116
2117 for (var i = 0; i < len; i++) {
2118 out[i] = buf.readUInt32BE(i * 4)
2119 }
2120
2121 return out
2122}
2123
2124function scrubVec (v) {
2125 for (var i = 0; i < v.length; v++) {
2126 v[i] = 0
2127 }
2128}
2129
2130function cryptBlock (M, keySchedule, SUB_MIX, SBOX, nRounds) {
2131 var SUB_MIX0 = SUB_MIX[0]
2132 var SUB_MIX1 = SUB_MIX[1]
2133 var SUB_MIX2 = SUB_MIX[2]
2134 var SUB_MIX3 = SUB_MIX[3]
2135
2136 var s0 = M[0] ^ keySchedule[0]
2137 var s1 = M[1] ^ keySchedule[1]
2138 var s2 = M[2] ^ keySchedule[2]
2139 var s3 = M[3] ^ keySchedule[3]
2140 var t0, t1, t2, t3
2141 var ksRow = 4
2142
2143 for (var round = 1; round < nRounds; round++) {
2144 t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[(s1 >>> 16) & 0xff] ^ SUB_MIX2[(s2 >>> 8) & 0xff] ^ SUB_MIX3[s3 & 0xff] ^ keySchedule[ksRow++]
2145 t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[(s2 >>> 16) & 0xff] ^ SUB_MIX2[(s3 >>> 8) & 0xff] ^ SUB_MIX3[s0 & 0xff] ^ keySchedule[ksRow++]
2146 t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[(s3 >>> 16) & 0xff] ^ SUB_MIX2[(s0 >>> 8) & 0xff] ^ SUB_MIX3[s1 & 0xff] ^ keySchedule[ksRow++]
2147 t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[(s0 >>> 16) & 0xff] ^ SUB_MIX2[(s1 >>> 8) & 0xff] ^ SUB_MIX3[s2 & 0xff] ^ keySchedule[ksRow++]
2148 s0 = t0
2149 s1 = t1
2150 s2 = t2
2151 s3 = t3
2152 }
2153
2154 t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]
2155 t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]
2156 t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]
2157 t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]
2158 t0 = t0 >>> 0
2159 t1 = t1 >>> 0
2160 t2 = t2 >>> 0
2161 t3 = t3 >>> 0
2162
2163 return [t0, t1, t2, t3]
2164}
2165
2166// AES constants
2167var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]
2168var G = (function () {
2169 // Compute double table
2170 var d = new Array(256)
2171 for (var j = 0; j < 256; j++) {
2172 if (j < 128) {
2173 d[j] = j << 1
2174 } else {
2175 d[j] = (j << 1) ^ 0x11b
2176 }
2177 }
2178
2179 var SBOX = []
2180 var INV_SBOX = []
2181 var SUB_MIX = [[], [], [], []]
2182 var INV_SUB_MIX = [[], [], [], []]
2183
2184 // Walk GF(2^8)
2185 var x = 0
2186 var xi = 0
2187 for (var i = 0; i < 256; ++i) {
2188 // Compute sbox
2189 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4)
2190 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63
2191 SBOX[x] = sx
2192 INV_SBOX[sx] = x
2193
2194 // Compute multiplication
2195 var x2 = d[x]
2196 var x4 = d[x2]
2197 var x8 = d[x4]
2198
2199 // Compute sub bytes, mix columns tables
2200 var t = (d[sx] * 0x101) ^ (sx * 0x1010100)
2201 SUB_MIX[0][x] = (t << 24) | (t >>> 8)
2202 SUB_MIX[1][x] = (t << 16) | (t >>> 16)
2203 SUB_MIX[2][x] = (t << 8) | (t >>> 24)
2204 SUB_MIX[3][x] = t
2205
2206 // Compute inv sub bytes, inv mix columns tables
2207 t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100)
2208 INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8)
2209 INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16)
2210 INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24)
2211 INV_SUB_MIX[3][sx] = t
2212
2213 if (x === 0) {
2214 x = xi = 1
2215 } else {
2216 x = x2 ^ d[d[d[x8 ^ x2]]]
2217 xi ^= d[d[xi]]
2218 }
2219 }
2220
2221 return {
2222 SBOX: SBOX,
2223 INV_SBOX: INV_SBOX,
2224 SUB_MIX: SUB_MIX,
2225 INV_SUB_MIX: INV_SUB_MIX
2226 }
2227})()
2228
2229function AES (key) {
2230 this._key = asUInt32Array(key)
2231 this._reset()
2232}
2233
2234AES.blockSize = 4 * 4
2235AES.keySize = 256 / 8
2236AES.prototype.blockSize = AES.blockSize
2237AES.prototype.keySize = AES.keySize
2238AES.prototype._reset = function () {
2239 var keyWords = this._key
2240 var keySize = keyWords.length
2241 var nRounds = keySize + 6
2242 var ksRows = (nRounds + 1) * 4
2243
2244 var keySchedule = []
2245 for (var k = 0; k < keySize; k++) {
2246 keySchedule[k] = keyWords[k]
2247 }
2248
2249 for (k = keySize; k < ksRows; k++) {
2250 var t = keySchedule[k - 1]
2251
2252 if (k % keySize === 0) {
2253 t = (t << 8) | (t >>> 24)
2254 t =
2255 (G.SBOX[t >>> 24] << 24) |
2256 (G.SBOX[(t >>> 16) & 0xff] << 16) |
2257 (G.SBOX[(t >>> 8) & 0xff] << 8) |
2258 (G.SBOX[t & 0xff])
2259
2260 t ^= RCON[(k / keySize) | 0] << 24
2261 } else if (keySize > 6 && k % keySize === 4) {
2262 t =
2263 (G.SBOX[t >>> 24] << 24) |
2264 (G.SBOX[(t >>> 16) & 0xff] << 16) |
2265 (G.SBOX[(t >>> 8) & 0xff] << 8) |
2266 (G.SBOX[t & 0xff])
2267 }
2268
2269 keySchedule[k] = keySchedule[k - keySize] ^ t
2270 }
2271
2272 var invKeySchedule = []
2273 for (var ik = 0; ik < ksRows; ik++) {
2274 var ksR = ksRows - ik
2275 var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]
2276
2277 if (ik < 4 || ksR <= 4) {
2278 invKeySchedule[ik] = tt
2279 } else {
2280 invKeySchedule[ik] =
2281 G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^
2282 G.INV_SUB_MIX[1][G.SBOX[(tt >>> 16) & 0xff]] ^
2283 G.INV_SUB_MIX[2][G.SBOX[(tt >>> 8) & 0xff]] ^
2284 G.INV_SUB_MIX[3][G.SBOX[tt & 0xff]]
2285 }
2286 }
2287
2288 this._nRounds = nRounds
2289 this._keySchedule = keySchedule
2290 this._invKeySchedule = invKeySchedule
2291}
2292
2293AES.prototype.encryptBlockRaw = function (M) {
2294 M = asUInt32Array(M)
2295 return cryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX, this._nRounds)
2296}
2297
2298AES.prototype.encryptBlock = function (M) {
2299 var out = this.encryptBlockRaw(M)
2300 var buf = Buffer.allocUnsafe(16)
2301 buf.writeUInt32BE(out[0], 0)
2302 buf.writeUInt32BE(out[1], 4)
2303 buf.writeUInt32BE(out[2], 8)
2304 buf.writeUInt32BE(out[3], 12)
2305 return buf
2306}
2307
2308AES.prototype.decryptBlock = function (M) {
2309 M = asUInt32Array(M)
2310
2311 // swap
2312 var m1 = M[1]
2313 M[1] = M[3]
2314 M[3] = m1
2315
2316 var out = cryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, this._nRounds)
2317 var buf = Buffer.allocUnsafe(16)
2318 buf.writeUInt32BE(out[0], 0)
2319 buf.writeUInt32BE(out[3], 4)
2320 buf.writeUInt32BE(out[2], 8)
2321 buf.writeUInt32BE(out[1], 12)
2322 return buf
2323}
2324
2325AES.prototype.scrub = function () {
2326 scrubVec(this._keySchedule)
2327 scrubVec(this._invKeySchedule)
2328 scrubVec(this._key)
2329}
2330
2331module.exports.AES = AES
2332
2333},{"safe-buffer":47}],8:[function(require,module,exports){
2334var aes = require('./aes')
2335var Buffer = require('safe-buffer').Buffer
2336var Transform = require('cipher-base')
2337var inherits = require('inherits')
2338var GHASH = require('./ghash')
2339var xor = require('buffer-xor')
2340var incr32 = require('./incr32')
2341
2342function xorTest (a, b) {
2343 var out = 0
2344 if (a.length !== b.length) out++
2345
2346 var len = Math.min(a.length, b.length)
2347 for (var i = 0; i < len; ++i) {
2348 out += (a[i] ^ b[i])
2349 }
2350
2351 return out
2352}
2353
2354function calcIv (self, iv, ck) {
2355 if (iv.length === 12) {
2356 self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])])
2357 return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])])
2358 }
2359 var ghash = new GHASH(ck)
2360 var len = iv.length
2361 var toPad = len % 16
2362 ghash.update(iv)
2363 if (toPad) {
2364 toPad = 16 - toPad
2365 ghash.update(Buffer.alloc(toPad, 0))
2366 }
2367 ghash.update(Buffer.alloc(8, 0))
2368 var ivBits = len * 8
2369 var tail = Buffer.alloc(8)
2370 tail.writeUIntBE(ivBits, 0, 8)
2371 ghash.update(tail)
2372 self._finID = ghash.state
2373 var out = Buffer.from(self._finID)
2374 incr32(out)
2375 return out
2376}
2377function StreamCipher (mode, key, iv, decrypt) {
2378 Transform.call(this)
2379
2380 var h = Buffer.alloc(4, 0)
2381
2382 this._cipher = new aes.AES(key)
2383 var ck = this._cipher.encryptBlock(h)
2384 this._ghash = new GHASH(ck)
2385 iv = calcIv(this, iv, ck)
2386
2387 this._prev = Buffer.from(iv)
2388 this._cache = Buffer.allocUnsafe(0)
2389 this._secCache = Buffer.allocUnsafe(0)
2390 this._decrypt = decrypt
2391 this._alen = 0
2392 this._len = 0
2393 this._mode = mode
2394
2395 this._authTag = null
2396 this._called = false
2397}
2398
2399inherits(StreamCipher, Transform)
2400
2401StreamCipher.prototype._update = function (chunk) {
2402 if (!this._called && this._alen) {
2403 var rump = 16 - (this._alen % 16)
2404 if (rump < 16) {
2405 rump = Buffer.alloc(rump, 0)
2406 this._ghash.update(rump)
2407 }
2408 }
2409
2410 this._called = true
2411 var out = this._mode.encrypt(this, chunk)
2412 if (this._decrypt) {
2413 this._ghash.update(chunk)
2414 } else {
2415 this._ghash.update(out)
2416 }
2417 this._len += chunk.length
2418 return out
2419}
2420
2421StreamCipher.prototype._final = function () {
2422 if (this._decrypt && !this._authTag) throw new Error('Unsupported state or unable to authenticate data')
2423
2424 var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID))
2425 if (this._decrypt && xorTest(tag, this._authTag)) throw new Error('Unsupported state or unable to authenticate data')
2426
2427 this._authTag = tag
2428 this._cipher.scrub()
2429}
2430
2431StreamCipher.prototype.getAuthTag = function getAuthTag () {
2432 if (this._decrypt || !Buffer.isBuffer(this._authTag)) throw new Error('Attempting to get auth tag in unsupported state')
2433
2434 return this._authTag
2435}
2436
2437StreamCipher.prototype.setAuthTag = function setAuthTag (tag) {
2438 if (!this._decrypt) throw new Error('Attempting to set auth tag in unsupported state')
2439
2440 this._authTag = tag
2441}
2442
2443StreamCipher.prototype.setAAD = function setAAD (buf) {
2444 if (this._called) throw new Error('Attempting to set AAD in unsupported state')
2445
2446 this._ghash.update(buf)
2447 this._alen += buf.length
2448}
2449
2450module.exports = StreamCipher
2451
2452},{"./aes":7,"./ghash":12,"./incr32":13,"buffer-xor":29,"cipher-base":31,"inherits":44,"safe-buffer":47}],9:[function(require,module,exports){
2453var ciphers = require('./encrypter')
2454var deciphers = require('./decrypter')
2455var modes = require('./modes/list.json')
2456
2457function getCiphers () {
2458 return Object.keys(modes)
2459}
2460
2461exports.createCipher = exports.Cipher = ciphers.createCipher
2462exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv
2463exports.createDecipher = exports.Decipher = deciphers.createDecipher
2464exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv
2465exports.listCiphers = exports.getCiphers = getCiphers
2466
2467},{"./decrypter":10,"./encrypter":11,"./modes/list.json":21}],10:[function(require,module,exports){
2468var AuthCipher = require('./authCipher')
2469var Buffer = require('safe-buffer').Buffer
2470var MODES = require('./modes')
2471var StreamCipher = require('./streamCipher')
2472var Transform = require('cipher-base')
2473var aes = require('./aes')
2474var ebtk = require('evp_bytestokey')
2475var inherits = require('inherits')
2476
2477function Decipher (mode, key, iv) {
2478 Transform.call(this)
2479
2480 this._cache = new Splitter()
2481 this._last = void 0
2482 this._cipher = new aes.AES(key)
2483 this._prev = Buffer.from(iv)
2484 this._mode = mode
2485 this._autopadding = true
2486}
2487
2488inherits(Decipher, Transform)
2489
2490Decipher.prototype._update = function (data) {
2491 this._cache.add(data)
2492 var chunk
2493 var thing
2494 var out = []
2495 while ((chunk = this._cache.get(this._autopadding))) {
2496 thing = this._mode.decrypt(this, chunk)
2497 out.push(thing)
2498 }
2499 return Buffer.concat(out)
2500}
2501
2502Decipher.prototype._final = function () {
2503 var chunk = this._cache.flush()
2504 if (this._autopadding) {
2505 return unpad(this._mode.decrypt(this, chunk))
2506 } else if (chunk) {
2507 throw new Error('data not multiple of block length')
2508 }
2509}
2510
2511Decipher.prototype.setAutoPadding = function (setTo) {
2512 this._autopadding = !!setTo
2513 return this
2514}
2515
2516function Splitter () {
2517 this.cache = Buffer.allocUnsafe(0)
2518}
2519
2520Splitter.prototype.add = function (data) {
2521 this.cache = Buffer.concat([this.cache, data])
2522}
2523
2524Splitter.prototype.get = function (autoPadding) {
2525 var out
2526 if (autoPadding) {
2527 if (this.cache.length > 16) {
2528 out = this.cache.slice(0, 16)
2529 this.cache = this.cache.slice(16)
2530 return out
2531 }
2532 } else {
2533 if (this.cache.length >= 16) {
2534 out = this.cache.slice(0, 16)
2535 this.cache = this.cache.slice(16)
2536 return out
2537 }
2538 }
2539
2540 return null
2541}
2542
2543Splitter.prototype.flush = function () {
2544 if (this.cache.length) return this.cache
2545}
2546
2547function unpad (last) {
2548 var padded = last[15]
2549 if (padded < 1 || padded > 16) {
2550 throw new Error('unable to decrypt data')
2551 }
2552 var i = -1
2553 while (++i < padded) {
2554 if (last[(i + (16 - padded))] !== padded) {
2555 throw new Error('unable to decrypt data')
2556 }
2557 }
2558 if (padded === 16) return
2559
2560 return last.slice(0, 16 - padded)
2561}
2562
2563function createDecipheriv (suite, password, iv) {
2564 var config = MODES[suite.toLowerCase()]
2565 if (!config) throw new TypeError('invalid suite type')
2566
2567 if (typeof iv === 'string') iv = Buffer.from(iv)
2568 if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length)
2569
2570 if (typeof password === 'string') password = Buffer.from(password)
2571 if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length)
2572
2573 if (config.type === 'stream') {
2574 return new StreamCipher(config.module, password, iv, true)
2575 } else if (config.type === 'auth') {
2576 return new AuthCipher(config.module, password, iv, true)
2577 }
2578
2579 return new Decipher(config.module, password, iv)
2580}
2581
2582function createDecipher (suite, password) {
2583 var config = MODES[suite.toLowerCase()]
2584 if (!config) throw new TypeError('invalid suite type')
2585
2586 var keys = ebtk(password, false, config.key, config.iv)
2587 return createDecipheriv(suite, keys.key, keys.iv)
2588}
2589
2590exports.createDecipher = createDecipher
2591exports.createDecipheriv = createDecipheriv
2592
2593},{"./aes":7,"./authCipher":8,"./modes":20,"./streamCipher":23,"cipher-base":31,"evp_bytestokey":38,"inherits":44,"safe-buffer":47}],11:[function(require,module,exports){
2594var MODES = require('./modes')
2595var AuthCipher = require('./authCipher')
2596var Buffer = require('safe-buffer').Buffer
2597var StreamCipher = require('./streamCipher')
2598var Transform = require('cipher-base')
2599var aes = require('./aes')
2600var ebtk = require('evp_bytestokey')
2601var inherits = require('inherits')
2602
2603function Cipher (mode, key, iv) {
2604 Transform.call(this)
2605
2606 this._cache = new Splitter()
2607 this._cipher = new aes.AES(key)
2608 this._prev = Buffer.from(iv)
2609 this._mode = mode
2610 this._autopadding = true
2611}
2612
2613inherits(Cipher, Transform)
2614
2615Cipher.prototype._update = function (data) {
2616 this._cache.add(data)
2617 var chunk
2618 var thing
2619 var out = []
2620
2621 while ((chunk = this._cache.get())) {
2622 thing = this._mode.encrypt(this, chunk)
2623 out.push(thing)
2624 }
2625
2626 return Buffer.concat(out)
2627}
2628
2629var PADDING = Buffer.alloc(16, 0x10)
2630
2631Cipher.prototype._final = function () {
2632 var chunk = this._cache.flush()
2633 if (this._autopadding) {
2634 chunk = this._mode.encrypt(this, chunk)
2635 this._cipher.scrub()
2636 return chunk
2637 }
2638
2639 if (!chunk.equals(PADDING)) {
2640 this._cipher.scrub()
2641 throw new Error('data not multiple of block length')
2642 }
2643}
2644
2645Cipher.prototype.setAutoPadding = function (setTo) {
2646 this._autopadding = !!setTo
2647 return this
2648}
2649
2650function Splitter () {
2651 this.cache = Buffer.allocUnsafe(0)
2652}
2653
2654Splitter.prototype.add = function (data) {
2655 this.cache = Buffer.concat([this.cache, data])
2656}
2657
2658Splitter.prototype.get = function () {
2659 if (this.cache.length > 15) {
2660 var out = this.cache.slice(0, 16)
2661 this.cache = this.cache.slice(16)
2662 return out
2663 }
2664 return null
2665}
2666
2667Splitter.prototype.flush = function () {
2668 var len = 16 - this.cache.length
2669 var padBuff = Buffer.allocUnsafe(len)
2670
2671 var i = -1
2672 while (++i < len) {
2673 padBuff.writeUInt8(len, i)
2674 }
2675
2676 return Buffer.concat([this.cache, padBuff])
2677}
2678
2679function createCipheriv (suite, password, iv) {
2680 var config = MODES[suite.toLowerCase()]
2681 if (!config) throw new TypeError('invalid suite type')
2682
2683 if (typeof password === 'string') password = Buffer.from(password)
2684 if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length)
2685
2686 if (typeof iv === 'string') iv = Buffer.from(iv)
2687 if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length)
2688
2689 if (config.type === 'stream') {
2690 return new StreamCipher(config.module, password, iv)
2691 } else if (config.type === 'auth') {
2692 return new AuthCipher(config.module, password, iv)
2693 }
2694
2695 return new Cipher(config.module, password, iv)
2696}
2697
2698function createCipher (suite, password) {
2699 var config = MODES[suite.toLowerCase()]
2700 if (!config) throw new TypeError('invalid suite type')
2701
2702 var keys = ebtk(password, false, config.key, config.iv)
2703 return createCipheriv(suite, keys.key, keys.iv)
2704}
2705
2706exports.createCipheriv = createCipheriv
2707exports.createCipher = createCipher
2708
2709},{"./aes":7,"./authCipher":8,"./modes":20,"./streamCipher":23,"cipher-base":31,"evp_bytestokey":38,"inherits":44,"safe-buffer":47}],12:[function(require,module,exports){
2710var Buffer = require('safe-buffer').Buffer
2711var ZEROES = Buffer.alloc(16, 0)
2712
2713function toArray (buf) {
2714 return [
2715 buf.readUInt32BE(0),
2716 buf.readUInt32BE(4),
2717 buf.readUInt32BE(8),
2718 buf.readUInt32BE(12)
2719 ]
2720}
2721
2722function fromArray (out) {
2723 var buf = Buffer.allocUnsafe(16)
2724 buf.writeUInt32BE(out[0] >>> 0, 0)
2725 buf.writeUInt32BE(out[1] >>> 0, 4)
2726 buf.writeUInt32BE(out[2] >>> 0, 8)
2727 buf.writeUInt32BE(out[3] >>> 0, 12)
2728 return buf
2729}
2730
2731function GHASH (key) {
2732 this.h = key
2733 this.state = Buffer.alloc(16, 0)
2734 this.cache = Buffer.allocUnsafe(0)
2735}
2736
2737// from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
2738// by Juho Vähä-Herttua
2739GHASH.prototype.ghash = function (block) {
2740 var i = -1
2741 while (++i < block.length) {
2742 this.state[i] ^= block[i]
2743 }
2744 this._multiply()
2745}
2746
2747GHASH.prototype._multiply = function () {
2748 var Vi = toArray(this.h)
2749 var Zi = [0, 0, 0, 0]
2750 var j, xi, lsbVi
2751 var i = -1
2752 while (++i < 128) {
2753 xi = (this.state[~~(i / 8)] & (1 << (7 - (i % 8)))) !== 0
2754 if (xi) {
2755 // Z_i+1 = Z_i ^ V_i
2756 Zi[0] ^= Vi[0]
2757 Zi[1] ^= Vi[1]
2758 Zi[2] ^= Vi[2]
2759 Zi[3] ^= Vi[3]
2760 }
2761
2762 // Store the value of LSB(V_i)
2763 lsbVi = (Vi[3] & 1) !== 0
2764
2765 // V_i+1 = V_i >> 1
2766 for (j = 3; j > 0; j--) {
2767 Vi[j] = (Vi[j] >>> 1) | ((Vi[j - 1] & 1) << 31)
2768 }
2769 Vi[0] = Vi[0] >>> 1
2770
2771 // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
2772 if (lsbVi) {
2773 Vi[0] = Vi[0] ^ (0xe1 << 24)
2774 }
2775 }
2776 this.state = fromArray(Zi)
2777}
2778
2779GHASH.prototype.update = function (buf) {
2780 this.cache = Buffer.concat([this.cache, buf])
2781 var chunk
2782 while (this.cache.length >= 16) {
2783 chunk = this.cache.slice(0, 16)
2784 this.cache = this.cache.slice(16)
2785 this.ghash(chunk)
2786 }
2787}
2788
2789GHASH.prototype.final = function (abl, bl) {
2790 if (this.cache.length) {
2791 this.ghash(Buffer.concat([this.cache, ZEROES], 16))
2792 }
2793
2794 this.ghash(fromArray([0, abl, 0, bl]))
2795 return this.state
2796}
2797
2798module.exports = GHASH
2799
2800},{"safe-buffer":47}],13:[function(require,module,exports){
2801function incr32 (iv) {
2802 var len = iv.length
2803 var item
2804 while (len--) {
2805 item = iv.readUInt8(len)
2806 if (item === 255) {
2807 iv.writeUInt8(0, len)
2808 } else {
2809 item++
2810 iv.writeUInt8(item, len)
2811 break
2812 }
2813 }
2814}
2815module.exports = incr32
2816
2817},{}],14:[function(require,module,exports){
2818var xor = require('buffer-xor')
2819
2820exports.encrypt = function (self, block) {
2821 var data = xor(block, self._prev)
2822
2823 self._prev = self._cipher.encryptBlock(data)
2824 return self._prev
2825}
2826
2827exports.decrypt = function (self, block) {
2828 var pad = self._prev
2829
2830 self._prev = block
2831 var out = self._cipher.decryptBlock(block)
2832
2833 return xor(out, pad)
2834}
2835
2836},{"buffer-xor":29}],15:[function(require,module,exports){
2837var Buffer = require('safe-buffer').Buffer
2838var xor = require('buffer-xor')
2839
2840function encryptStart (self, data, decrypt) {
2841 var len = data.length
2842 var out = xor(data, self._cache)
2843 self._cache = self._cache.slice(len)
2844 self._prev = Buffer.concat([self._prev, decrypt ? data : out])
2845 return out
2846}
2847
2848exports.encrypt = function (self, data, decrypt) {
2849 var out = Buffer.allocUnsafe(0)
2850 var len
2851
2852 while (data.length) {
2853 if (self._cache.length === 0) {
2854 self._cache = self._cipher.encryptBlock(self._prev)
2855 self._prev = Buffer.allocUnsafe(0)
2856 }
2857
2858 if (self._cache.length <= data.length) {
2859 len = self._cache.length
2860 out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)])
2861 data = data.slice(len)
2862 } else {
2863 out = Buffer.concat([out, encryptStart(self, data, decrypt)])
2864 break
2865 }
2866 }
2867
2868 return out
2869}
2870
2871},{"buffer-xor":29,"safe-buffer":47}],16:[function(require,module,exports){
2872var Buffer = require('safe-buffer').Buffer
2873
2874function encryptByte (self, byteParam, decrypt) {
2875 var pad
2876 var i = -1
2877 var len = 8
2878 var out = 0
2879 var bit, value
2880 while (++i < len) {
2881 pad = self._cipher.encryptBlock(self._prev)
2882 bit = (byteParam & (1 << (7 - i))) ? 0x80 : 0
2883 value = pad[0] ^ bit
2884 out += ((value & 0x80) >> (i % 8))
2885 self._prev = shiftIn(self._prev, decrypt ? bit : value)
2886 }
2887 return out
2888}
2889
2890function shiftIn (buffer, value) {
2891 var len = buffer.length
2892 var i = -1
2893 var out = Buffer.allocUnsafe(buffer.length)
2894 buffer = Buffer.concat([buffer, Buffer.from([value])])
2895
2896 while (++i < len) {
2897 out[i] = buffer[i] << 1 | buffer[i + 1] >> (7)
2898 }
2899
2900 return out
2901}
2902
2903exports.encrypt = function (self, chunk, decrypt) {
2904 var len = chunk.length
2905 var out = Buffer.allocUnsafe(len)
2906 var i = -1
2907
2908 while (++i < len) {
2909 out[i] = encryptByte(self, chunk[i], decrypt)
2910 }
2911
2912 return out
2913}
2914
2915},{"safe-buffer":47}],17:[function(require,module,exports){
2916var Buffer = require('safe-buffer').Buffer
2917
2918function encryptByte (self, byteParam, decrypt) {
2919 var pad = self._cipher.encryptBlock(self._prev)
2920 var out = pad[0] ^ byteParam
2921
2922 self._prev = Buffer.concat([
2923 self._prev.slice(1),
2924 Buffer.from([decrypt ? byteParam : out])
2925 ])
2926
2927 return out
2928}
2929
2930exports.encrypt = function (self, chunk, decrypt) {
2931 var len = chunk.length
2932 var out = Buffer.allocUnsafe(len)
2933 var i = -1
2934
2935 while (++i < len) {
2936 out[i] = encryptByte(self, chunk[i], decrypt)
2937 }
2938
2939 return out
2940}
2941
2942},{"safe-buffer":47}],18:[function(require,module,exports){
2943var xor = require('buffer-xor')
2944var Buffer = require('safe-buffer').Buffer
2945var incr32 = require('../incr32')
2946
2947function getBlock (self) {
2948 var out = self._cipher.encryptBlockRaw(self._prev)
2949 incr32(self._prev)
2950 return out
2951}
2952
2953var blockSize = 16
2954exports.encrypt = function (self, chunk) {
2955 var chunkNum = Math.ceil(chunk.length / blockSize)
2956 var start = self._cache.length
2957 self._cache = Buffer.concat([
2958 self._cache,
2959 Buffer.allocUnsafe(chunkNum * blockSize)
2960 ])
2961 for (var i = 0; i < chunkNum; i++) {
2962 var out = getBlock(self)
2963 var offset = start + i * blockSize
2964 self._cache.writeUInt32BE(out[0], offset + 0)
2965 self._cache.writeUInt32BE(out[1], offset + 4)
2966 self._cache.writeUInt32BE(out[2], offset + 8)
2967 self._cache.writeUInt32BE(out[3], offset + 12)
2968 }
2969 var pad = self._cache.slice(0, chunk.length)
2970 self._cache = self._cache.slice(chunk.length)
2971 return xor(chunk, pad)
2972}
2973
2974},{"../incr32":13,"buffer-xor":29,"safe-buffer":47}],19:[function(require,module,exports){
2975exports.encrypt = function (self, block) {
2976 return self._cipher.encryptBlock(block)
2977}
2978
2979exports.decrypt = function (self, block) {
2980 return self._cipher.decryptBlock(block)
2981}
2982
2983},{}],20:[function(require,module,exports){
2984var modeModules = {
2985 ECB: require('./ecb'),
2986 CBC: require('./cbc'),
2987 CFB: require('./cfb'),
2988 CFB8: require('./cfb8'),
2989 CFB1: require('./cfb1'),
2990 OFB: require('./ofb'),
2991 CTR: require('./ctr'),
2992 GCM: require('./ctr')
2993}
2994
2995var modes = require('./list.json')
2996
2997for (var key in modes) {
2998 modes[key].module = modeModules[modes[key].mode]
2999}
3000
3001module.exports = modes
3002
3003},{"./cbc":14,"./cfb":15,"./cfb1":16,"./cfb8":17,"./ctr":18,"./ecb":19,"./list.json":21,"./ofb":22}],21:[function(require,module,exports){
3004module.exports={
3005 "aes-128-ecb": {
3006 "cipher": "AES",
3007 "key": 128,
3008 "iv": 0,
3009 "mode": "ECB",
3010 "type": "block"
3011 },
3012 "aes-192-ecb": {
3013 "cipher": "AES",
3014 "key": 192,
3015 "iv": 0,
3016 "mode": "ECB",
3017 "type": "block"
3018 },
3019 "aes-256-ecb": {
3020 "cipher": "AES",
3021 "key": 256,
3022 "iv": 0,
3023 "mode": "ECB",
3024 "type": "block"
3025 },
3026 "aes-128-cbc": {
3027 "cipher": "AES",
3028 "key": 128,
3029 "iv": 16,
3030 "mode": "CBC",
3031 "type": "block"
3032 },
3033 "aes-192-cbc": {
3034 "cipher": "AES",
3035 "key": 192,
3036 "iv": 16,
3037 "mode": "CBC",
3038 "type": "block"
3039 },
3040 "aes-256-cbc": {
3041 "cipher": "AES",
3042 "key": 256,
3043 "iv": 16,
3044 "mode": "CBC",
3045 "type": "block"
3046 },
3047 "aes128": {
3048 "cipher": "AES",
3049 "key": 128,
3050 "iv": 16,
3051 "mode": "CBC",
3052 "type": "block"
3053 },
3054 "aes192": {
3055 "cipher": "AES",
3056 "key": 192,
3057 "iv": 16,
3058 "mode": "CBC",
3059 "type": "block"
3060 },
3061 "aes256": {
3062 "cipher": "AES",
3063 "key": 256,
3064 "iv": 16,
3065 "mode": "CBC",
3066 "type": "block"
3067 },
3068 "aes-128-cfb": {
3069 "cipher": "AES",
3070 "key": 128,
3071 "iv": 16,
3072 "mode": "CFB",
3073 "type": "stream"
3074 },
3075 "aes-192-cfb": {
3076 "cipher": "AES",
3077 "key": 192,
3078 "iv": 16,
3079 "mode": "CFB",
3080 "type": "stream"
3081 },
3082 "aes-256-cfb": {
3083 "cipher": "AES",
3084 "key": 256,
3085 "iv": 16,
3086 "mode": "CFB",
3087 "type": "stream"
3088 },
3089 "aes-128-cfb8": {
3090 "cipher": "AES",
3091 "key": 128,
3092 "iv": 16,
3093 "mode": "CFB8",
3094 "type": "stream"
3095 },
3096 "aes-192-cfb8": {
3097 "cipher": "AES",
3098 "key": 192,
3099 "iv": 16,
3100 "mode": "CFB8",
3101 "type": "stream"
3102 },
3103 "aes-256-cfb8": {
3104 "cipher": "AES",
3105 "key": 256,
3106 "iv": 16,
3107 "mode": "CFB8",
3108 "type": "stream"
3109 },
3110 "aes-128-cfb1": {
3111 "cipher": "AES",
3112 "key": 128,
3113 "iv": 16,
3114 "mode": "CFB1",
3115 "type": "stream"
3116 },
3117 "aes-192-cfb1": {
3118 "cipher": "AES",
3119 "key": 192,
3120 "iv": 16,
3121 "mode": "CFB1",
3122 "type": "stream"
3123 },
3124 "aes-256-cfb1": {
3125 "cipher": "AES",
3126 "key": 256,
3127 "iv": 16,
3128 "mode": "CFB1",
3129 "type": "stream"
3130 },
3131 "aes-128-ofb": {
3132 "cipher": "AES",
3133 "key": 128,
3134 "iv": 16,
3135 "mode": "OFB",
3136 "type": "stream"
3137 },
3138 "aes-192-ofb": {
3139 "cipher": "AES",
3140 "key": 192,
3141 "iv": 16,
3142 "mode": "OFB",
3143 "type": "stream"
3144 },
3145 "aes-256-ofb": {
3146 "cipher": "AES",
3147 "key": 256,
3148 "iv": 16,
3149 "mode": "OFB",
3150 "type": "stream"
3151 },
3152 "aes-128-ctr": {
3153 "cipher": "AES",
3154 "key": 128,
3155 "iv": 16,
3156 "mode": "CTR",
3157 "type": "stream"
3158 },
3159 "aes-192-ctr": {
3160 "cipher": "AES",
3161 "key": 192,
3162 "iv": 16,
3163 "mode": "CTR",
3164 "type": "stream"
3165 },
3166 "aes-256-ctr": {
3167 "cipher": "AES",
3168 "key": 256,
3169 "iv": 16,
3170 "mode": "CTR",
3171 "type": "stream"
3172 },
3173 "aes-128-gcm": {
3174 "cipher": "AES",
3175 "key": 128,
3176 "iv": 12,
3177 "mode": "GCM",
3178 "type": "auth"
3179 },
3180 "aes-192-gcm": {
3181 "cipher": "AES",
3182 "key": 192,
3183 "iv": 12,
3184 "mode": "GCM",
3185 "type": "auth"
3186 },
3187 "aes-256-gcm": {
3188 "cipher": "AES",
3189 "key": 256,
3190 "iv": 12,
3191 "mode": "GCM",
3192 "type": "auth"
3193 }
3194}
3195
3196},{}],22:[function(require,module,exports){
3197(function (Buffer){
3198var xor = require('buffer-xor')
3199
3200function getBlock (self) {
3201 self._prev = self._cipher.encryptBlock(self._prev)
3202 return self._prev
3203}
3204
3205exports.encrypt = function (self, chunk) {
3206 while (self._cache.length < chunk.length) {
3207 self._cache = Buffer.concat([self._cache, getBlock(self)])
3208 }
3209
3210 var pad = self._cache.slice(0, chunk.length)
3211 self._cache = self._cache.slice(chunk.length)
3212 return xor(chunk, pad)
3213}
3214
3215}).call(this,require("buffer").Buffer)
3216},{"buffer":110,"buffer-xor":29}],23:[function(require,module,exports){
3217var aes = require('./aes')
3218var Buffer = require('safe-buffer').Buffer
3219var Transform = require('cipher-base')
3220var inherits = require('inherits')
3221
3222function StreamCipher (mode, key, iv, decrypt) {
3223 Transform.call(this)
3224
3225 this._cipher = new aes.AES(key)
3226 this._prev = Buffer.from(iv)
3227 this._cache = Buffer.allocUnsafe(0)
3228 this._secCache = Buffer.allocUnsafe(0)
3229 this._decrypt = decrypt
3230 this._mode = mode
3231}
3232
3233inherits(StreamCipher, Transform)
3234
3235StreamCipher.prototype._update = function (chunk) {
3236 return this._mode.encrypt(this, chunk, this._decrypt)
3237}
3238
3239StreamCipher.prototype._final = function () {
3240 this._cipher.scrub()
3241}
3242
3243module.exports = StreamCipher
3244
3245},{"./aes":7,"cipher-base":31,"inherits":44,"safe-buffer":47}],24:[function(require,module,exports){
3246var basex = require('base-x')
3247var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
3248
3249module.exports = basex(ALPHABET)
3250
3251},{"base-x":2}],25:[function(require,module,exports){
3252'use strict'
3253
3254var base58 = require('bs58')
3255var Buffer = require('safe-buffer').Buffer
3256
3257module.exports = function (checksumFn) {
3258 // Encode a buffer as a base58-check encoded string
3259 function encode (payload) {
3260 var checksum = checksumFn(payload)
3261
3262 return base58.encode(Buffer.concat([
3263 payload,
3264 checksum
3265 ], payload.length + 4))
3266 }
3267
3268 function decodeRaw (buffer) {
3269 var payload = buffer.slice(0, -4)
3270 var checksum = buffer.slice(-4)
3271 var newChecksum = checksumFn(payload)
3272
3273 if (checksum[0] ^ newChecksum[0] |
3274 checksum[1] ^ newChecksum[1] |
3275 checksum[2] ^ newChecksum[2] |
3276 checksum[3] ^ newChecksum[3]) return
3277
3278 return payload
3279 }
3280
3281 // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
3282 function decodeUnsafe (string) {
3283 var buffer = base58.decodeUnsafe(string)
3284 if (!buffer) return
3285
3286 return decodeRaw(buffer)
3287 }
3288
3289 function decode (string) {
3290 var buffer = base58.decode(string)
3291 var payload = decodeRaw(buffer, checksumFn)
3292 if (!payload) throw new Error('Invalid checksum')
3293 return payload
3294 }
3295
3296 return {
3297 encode: encode,
3298 decode: decode,
3299 decodeUnsafe: decodeUnsafe
3300 }
3301}
3302
3303},{"bs58":24,"safe-buffer":47}],26:[function(require,module,exports){
3304'use strict'
3305
3306var createHash = require('create-hash')
3307var bs58checkBase = require('./base')
3308
3309// SHA256(SHA256(buffer))
3310function sha256x2 (buffer) {
3311 var tmp = createHash('sha256').update(buffer).digest()
3312 return createHash('sha256').update(tmp).digest()
3313}
3314
3315module.exports = bs58checkBase(sha256x2)
3316
3317},{"./base":25,"create-hash":32}],27:[function(require,module,exports){
3318arguments[4][25][0].apply(exports,arguments)
3319},{"bs58":24,"dup":25,"safe-buffer":47}],28:[function(require,module,exports){
3320(function (Buffer){
3321'use strict'
3322
3323var createHash = require('create-hash')
3324var bs58grscheckBase = require('./base')
3325var groestlhash = require('groestl-hash-js')
3326
3327// GROESTL512(GROESTL512(buffer))
3328function groestl (buffer) {
3329 return Buffer(groestlhash.groestl_2(buffer, 1, 1))
3330}
3331
3332module.exports = bs58grscheckBase(groestl)
3333
3334}).call(this,require("buffer").Buffer)
3335},{"./base":27,"buffer":110,"create-hash":32,"groestl-hash-js":39}],29:[function(require,module,exports){
3336(function (Buffer){
3337module.exports = function xor (a, b) {
3338 var length = Math.min(a.length, b.length)
3339 var buffer = new Buffer(length)
3340
3341 for (var i = 0; i < length; ++i) {
3342 buffer[i] = a[i] ^ b[i]
3343 }
3344
3345 return buffer
3346}
3347
3348}).call(this,require("buffer").Buffer)
3349},{"buffer":110}],30:[function(require,module,exports){
3350module.exports = function xorInplace (a, b) {
3351 var length = Math.min(a.length, b.length)
3352
3353 for (var i = 0; i < length; ++i) {
3354 a[i] = a[i] ^ b[i]
3355 }
3356
3357 return a.slice(0, length)
3358}
3359
3360},{}],31:[function(require,module,exports){
3361var Buffer = require('safe-buffer').Buffer
3362var Transform = require('stream').Transform
3363var StringDecoder = require('string_decoder').StringDecoder
3364var inherits = require('inherits')
3365
3366function CipherBase (hashMode) {
3367 Transform.call(this)
3368 this.hashMode = typeof hashMode === 'string'
3369 if (this.hashMode) {
3370 this[hashMode] = this._finalOrDigest
3371 } else {
3372 this.final = this._finalOrDigest
3373 }
3374 if (this._final) {
3375 this.__final = this._final
3376 this._final = null
3377 }
3378 this._decoder = null
3379 this._encoding = null
3380}
3381inherits(CipherBase, Transform)
3382
3383CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
3384 if (typeof data === 'string') {
3385 data = Buffer.from(data, inputEnc)
3386 }
3387
3388 var outData = this._update(data)
3389 if (this.hashMode) return this
3390
3391 if (outputEnc) {
3392 outData = this._toString(outData, outputEnc)
3393 }
3394
3395 return outData
3396}
3397
3398CipherBase.prototype.setAutoPadding = function () {}
3399CipherBase.prototype.getAuthTag = function () {
3400 throw new Error('trying to get auth tag in unsupported state')
3401}
3402
3403CipherBase.prototype.setAuthTag = function () {
3404 throw new Error('trying to set auth tag in unsupported state')
3405}
3406
3407CipherBase.prototype.setAAD = function () {
3408 throw new Error('trying to set aad in unsupported state')
3409}
3410
3411CipherBase.prototype._transform = function (data, _, next) {
3412 var err
3413 try {
3414 if (this.hashMode) {
3415 this._update(data)
3416 } else {
3417 this.push(this._update(data))
3418 }
3419 } catch (e) {
3420 err = e
3421 } finally {
3422 next(err)
3423 }
3424}
3425CipherBase.prototype._flush = function (done) {
3426 var err
3427 try {
3428 this.push(this.__final())
3429 } catch (e) {
3430 err = e
3431 }
3432
3433 done(err)
3434}
3435CipherBase.prototype._finalOrDigest = function (outputEnc) {
3436 var outData = this.__final() || Buffer.alloc(0)
3437 if (outputEnc) {
3438 outData = this._toString(outData, outputEnc, true)
3439 }
3440 return outData
3441}
3442
3443CipherBase.prototype._toString = function (value, enc, fin) {
3444 if (!this._decoder) {
3445 this._decoder = new StringDecoder(enc)
3446 this._encoding = enc
3447 }
3448
3449 if (this._encoding !== enc) throw new Error('can\'t switch encodings')
3450
3451 var out = this._decoder.write(value)
3452 if (fin) {
3453 out += this._decoder.end()
3454 }
3455
3456 return out
3457}
3458
3459module.exports = CipherBase
3460
3461},{"inherits":44,"safe-buffer":47,"stream":215,"string_decoder":216}],32:[function(require,module,exports){
3462'use strict'
3463var inherits = require('inherits')
3464var MD5 = require('md5.js')
3465var RIPEMD160 = require('ripemd160')
3466var sha = require('sha.js')
3467var Base = require('cipher-base')
3468
3469function Hash (hash) {
3470 Base.call(this, 'digest')
3471
3472 this._hash = hash
3473}
3474
3475inherits(Hash, Base)
3476
3477Hash.prototype._update = function (data) {
3478 this._hash.update(data)
3479}
3480
3481Hash.prototype._final = function () {
3482 return this._hash.digest()
3483}
3484
3485module.exports = function createHash (alg) {
3486 alg = alg.toLowerCase()
3487 if (alg === 'md5') return new MD5()
3488 if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()
3489
3490 return new Hash(sha(alg))
3491}
3492
3493},{"cipher-base":31,"inherits":44,"md5.js":45,"ripemd160":46,"sha.js":53}],33:[function(require,module,exports){
3494var assert = require('assert')
3495var BigInteger = require('bigi')
3496
3497var Point = require('./point')
3498
3499function Curve (p, a, b, Gx, Gy, n, h) {
3500 this.p = p
3501 this.a = a
3502 this.b = b
3503 this.G = Point.fromAffine(this, Gx, Gy)
3504 this.n = n
3505 this.h = h
3506
3507 this.infinity = new Point(this, null, null, BigInteger.ZERO)
3508
3509 // result caching
3510 this.pOverFour = p.add(BigInteger.ONE).shiftRight(2)
3511
3512 // determine size of p in bytes
3513 this.pLength = Math.floor((this.p.bitLength() + 7) / 8)
3514}
3515
3516Curve.prototype.pointFromX = function (isOdd, x) {
3517 var alpha = x.pow(3).add(this.a.multiply(x)).add(this.b).mod(this.p)
3518 var beta = alpha.modPow(this.pOverFour, this.p) // XXX: not compatible with all curves
3519
3520 var y = beta
3521 if (beta.isEven() ^ !isOdd) {
3522 y = this.p.subtract(y) // -y % p
3523 }
3524
3525 return Point.fromAffine(this, x, y)
3526}
3527
3528Curve.prototype.isInfinity = function (Q) {
3529 if (Q === this.infinity) return true
3530
3531 return Q.z.signum() === 0 && Q.y.signum() !== 0
3532}
3533
3534Curve.prototype.isOnCurve = function (Q) {
3535 if (this.isInfinity(Q)) return true
3536
3537 var x = Q.affineX
3538 var y = Q.affineY
3539 var a = this.a
3540 var b = this.b
3541 var p = this.p
3542
3543 // Check that xQ and yQ are integers in the interval [0, p - 1]
3544 if (x.signum() < 0 || x.compareTo(p) >= 0) return false
3545 if (y.signum() < 0 || y.compareTo(p) >= 0) return false
3546
3547 // and check that y^2 = x^3 + ax + b (mod p)
3548 var lhs = y.square().mod(p)
3549 var rhs = x.pow(3).add(a.multiply(x)).add(b).mod(p)
3550 return lhs.equals(rhs)
3551}
3552
3553/**
3554 * Validate an elliptic curve point.
3555 *
3556 * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive
3557 */
3558Curve.prototype.validate = function (Q) {
3559 // Check Q != O
3560 assert(!this.isInfinity(Q), 'Point is at infinity')
3561 assert(this.isOnCurve(Q), 'Point is not on the curve')
3562
3563 // Check nQ = O (where Q is a scalar multiple of G)
3564 var nQ = Q.multiply(this.n)
3565 assert(this.isInfinity(nQ), 'Point is not a scalar multiple of G')
3566
3567 return true
3568}
3569
3570module.exports = Curve
3571
3572},{"./point":37,"assert":74,"bigi":5}],34:[function(require,module,exports){
3573module.exports={
3574 "secp128r1": {
3575 "p": "fffffffdffffffffffffffffffffffff",
3576 "a": "fffffffdfffffffffffffffffffffffc",
3577 "b": "e87579c11079f43dd824993c2cee5ed3",
3578 "n": "fffffffe0000000075a30d1b9038a115",
3579 "h": "01",
3580 "Gx": "161ff7528b899b2d0c28607ca52c5b86",
3581 "Gy": "cf5ac8395bafeb13c02da292dded7a83"
3582 },
3583 "secp160k1": {
3584 "p": "fffffffffffffffffffffffffffffffeffffac73",
3585 "a": "00",
3586 "b": "07",
3587 "n": "0100000000000000000001b8fa16dfab9aca16b6b3",
3588 "h": "01",
3589 "Gx": "3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",
3590 "Gy": "938cf935318fdced6bc28286531733c3f03c4fee"
3591 },
3592 "secp160r1": {
3593 "p": "ffffffffffffffffffffffffffffffff7fffffff",
3594 "a": "ffffffffffffffffffffffffffffffff7ffffffc",
3595 "b": "1c97befc54bd7a8b65acf89f81d4d4adc565fa45",
3596 "n": "0100000000000000000001f4c8f927aed3ca752257",
3597 "h": "01",
3598 "Gx": "4a96b5688ef573284664698968c38bb913cbfc82",
3599 "Gy": "23a628553168947d59dcc912042351377ac5fb32"
3600 },
3601 "secp192k1": {
3602 "p": "fffffffffffffffffffffffffffffffffffffffeffffee37",
3603 "a": "00",
3604 "b": "03",
3605 "n": "fffffffffffffffffffffffe26f2fc170f69466a74defd8d",
3606 "h": "01",
3607 "Gx": "db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",
3608 "Gy": "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"
3609 },
3610 "secp192r1": {
3611 "p": "fffffffffffffffffffffffffffffffeffffffffffffffff",
3612 "a": "fffffffffffffffffffffffffffffffefffffffffffffffc",
3613 "b": "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",
3614 "n": "ffffffffffffffffffffffff99def836146bc9b1b4d22831",
3615 "h": "01",
3616 "Gx": "188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
3617 "Gy": "07192b95ffc8da78631011ed6b24cdd573f977a11e794811"
3618 },
3619 "secp256k1": {
3620 "p": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
3621 "a": "00",
3622 "b": "07",
3623 "n": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
3624 "h": "01",
3625 "Gx": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
3626 "Gy": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
3627 },
3628 "secp256r1": {
3629 "p": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
3630 "a": "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",
3631 "b": "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
3632 "n": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
3633 "h": "01",
3634 "Gx": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
3635 "Gy": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
3636 }
3637}
3638
3639},{}],35:[function(require,module,exports){
3640var Point = require('./point')
3641var Curve = require('./curve')
3642
3643var getCurveByName = require('./names')
3644
3645module.exports = {
3646 Curve: Curve,
3647 Point: Point,
3648 getCurveByName: getCurveByName
3649}
3650
3651},{"./curve":33,"./names":36,"./point":37}],36:[function(require,module,exports){
3652var BigInteger = require('bigi')
3653
3654var curves = require('./curves.json')
3655var Curve = require('./curve')
3656
3657function getCurveByName (name) {
3658 var curve = curves[name]
3659 if (!curve) return null
3660
3661 var p = new BigInteger(curve.p, 16)
3662 var a = new BigInteger(curve.a, 16)
3663 var b = new BigInteger(curve.b, 16)
3664 var n = new BigInteger(curve.n, 16)
3665 var h = new BigInteger(curve.h, 16)
3666 var Gx = new BigInteger(curve.Gx, 16)
3667 var Gy = new BigInteger(curve.Gy, 16)
3668
3669 return new Curve(p, a, b, Gx, Gy, n, h)
3670}
3671
3672module.exports = getCurveByName
3673
3674},{"./curve":33,"./curves.json":34,"bigi":5}],37:[function(require,module,exports){
3675var assert = require('assert')
3676var Buffer = require('safe-buffer').Buffer
3677var BigInteger = require('bigi')
3678
3679var THREE = BigInteger.valueOf(3)
3680
3681function Point (curve, x, y, z) {
3682 assert.notStrictEqual(z, undefined, 'Missing Z coordinate')
3683
3684 this.curve = curve
3685 this.x = x
3686 this.y = y
3687 this.z = z
3688 this._zInv = null
3689
3690 this.compressed = true
3691}
3692
3693Object.defineProperty(Point.prototype, 'zInv', {
3694 get: function () {
3695 if (this._zInv === null) {
3696 this._zInv = this.z.modInverse(this.curve.p)
3697 }
3698
3699 return this._zInv
3700 }
3701})
3702
3703Object.defineProperty(Point.prototype, 'affineX', {
3704 get: function () {
3705 return this.x.multiply(this.zInv).mod(this.curve.p)
3706 }
3707})
3708
3709Object.defineProperty(Point.prototype, 'affineY', {
3710 get: function () {
3711 return this.y.multiply(this.zInv).mod(this.curve.p)
3712 }
3713})
3714
3715Point.fromAffine = function (curve, x, y) {
3716 return new Point(curve, x, y, BigInteger.ONE)
3717}
3718
3719Point.prototype.equals = function (other) {
3720 if (other === this) return true
3721 if (this.curve.isInfinity(this)) return this.curve.isInfinity(other)
3722 if (this.curve.isInfinity(other)) return this.curve.isInfinity(this)
3723
3724 // u = Y2 * Z1 - Y1 * Z2
3725 var u = other.y.multiply(this.z).subtract(this.y.multiply(other.z)).mod(this.curve.p)
3726
3727 if (u.signum() !== 0) return false
3728
3729 // v = X2 * Z1 - X1 * Z2
3730 var v = other.x.multiply(this.z).subtract(this.x.multiply(other.z)).mod(this.curve.p)
3731
3732 return v.signum() === 0
3733}
3734
3735Point.prototype.negate = function () {
3736 var y = this.curve.p.subtract(this.y)
3737
3738 return new Point(this.curve, this.x, y, this.z)
3739}
3740
3741Point.prototype.add = function (b) {
3742 if (this.curve.isInfinity(this)) return b
3743 if (this.curve.isInfinity(b)) return this
3744
3745 var x1 = this.x
3746 var y1 = this.y
3747 var x2 = b.x
3748 var y2 = b.y
3749
3750 // u = Y2 * Z1 - Y1 * Z2
3751 var u = y2.multiply(this.z).subtract(y1.multiply(b.z)).mod(this.curve.p)
3752 // v = X2 * Z1 - X1 * Z2
3753 var v = x2.multiply(this.z).subtract(x1.multiply(b.z)).mod(this.curve.p)
3754
3755 if (v.signum() === 0) {
3756 if (u.signum() === 0) {
3757 return this.twice() // this == b, so double
3758 }
3759
3760 return this.curve.infinity // this = -b, so infinity
3761 }
3762
3763 var v2 = v.square()
3764 var v3 = v2.multiply(v)
3765 var x1v2 = x1.multiply(v2)
3766 var zu2 = u.square().multiply(this.z)
3767
3768 // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
3769 var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.p)
3770 // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
3771 var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.p)
3772 // z3 = v^3 * z1 * z2
3773 var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.p)
3774
3775 return new Point(this.curve, x3, y3, z3)
3776}
3777
3778Point.prototype.twice = function () {
3779 if (this.curve.isInfinity(this)) return this
3780 if (this.y.signum() === 0) return this.curve.infinity
3781
3782 var x1 = this.x
3783 var y1 = this.y
3784
3785 var y1z1 = y1.multiply(this.z).mod(this.curve.p)
3786 var y1sqz1 = y1z1.multiply(y1).mod(this.curve.p)
3787 var a = this.curve.a
3788
3789 // w = 3 * x1^2 + a * z1^2
3790 var w = x1.square().multiply(THREE)
3791
3792 if (a.signum() !== 0) {
3793 w = w.add(this.z.square().multiply(a))
3794 }
3795
3796 w = w.mod(this.curve.p)
3797 // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
3798 var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.p)
3799 // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
3800 var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.pow(3)).mod(this.curve.p)
3801 // z3 = 8 * (y1 * z1)^3
3802 var z3 = y1z1.pow(3).shiftLeft(3).mod(this.curve.p)
3803
3804 return new Point(this.curve, x3, y3, z3)
3805}
3806
3807// Simple NAF (Non-Adjacent Form) multiplication algorithm
3808// TODO: modularize the multiplication algorithm
3809Point.prototype.multiply = function (k) {
3810 if (this.curve.isInfinity(this)) return this
3811 if (k.signum() === 0) return this.curve.infinity
3812
3813 var e = k
3814 var h = e.multiply(THREE)
3815
3816 var neg = this.negate()
3817 var R = this
3818
3819 for (var i = h.bitLength() - 2; i > 0; --i) {
3820 var hBit = h.testBit(i)
3821 var eBit = e.testBit(i)
3822
3823 R = R.twice()
3824
3825 if (hBit !== eBit) {
3826 R = R.add(hBit ? this : neg)
3827 }
3828 }
3829
3830 return R
3831}
3832
3833// Compute this*j + x*k (simultaneous multiplication)
3834Point.prototype.multiplyTwo = function (j, x, k) {
3835 var i = Math.max(j.bitLength(), k.bitLength()) - 1
3836 var R = this.curve.infinity
3837 var both = this.add(x)
3838
3839 while (i >= 0) {
3840 var jBit = j.testBit(i)
3841 var kBit = k.testBit(i)
3842
3843 R = R.twice()
3844
3845 if (jBit) {
3846 if (kBit) {
3847 R = R.add(both)
3848 } else {
3849 R = R.add(this)
3850 }
3851 } else if (kBit) {
3852 R = R.add(x)
3853 }
3854 --i
3855 }
3856
3857 return R
3858}
3859
3860Point.prototype.getEncoded = function (compressed) {
3861 if (compressed == null) compressed = this.compressed
3862 if (this.curve.isInfinity(this)) return Buffer.alloc(1, 0) // Infinity point encoded is simply '00'
3863
3864 var x = this.affineX
3865 var y = this.affineY
3866 var byteLength = this.curve.pLength
3867 var buffer
3868
3869 // 0x02/0x03 | X
3870 if (compressed) {
3871 buffer = Buffer.allocUnsafe(1 + byteLength)
3872 buffer.writeUInt8(y.isEven() ? 0x02 : 0x03, 0)
3873
3874 // 0x04 | X | Y
3875 } else {
3876 buffer = Buffer.allocUnsafe(1 + byteLength + byteLength)
3877 buffer.writeUInt8(0x04, 0)
3878
3879 y.toBuffer(byteLength).copy(buffer, 1 + byteLength)
3880 }
3881
3882 x.toBuffer(byteLength).copy(buffer, 1)
3883
3884 return buffer
3885}
3886
3887Point.decodeFrom = function (curve, buffer) {
3888 var type = buffer.readUInt8(0)
3889 var compressed = (type !== 4)
3890
3891 var byteLength = Math.floor((curve.p.bitLength() + 7) / 8)
3892 var x = BigInteger.fromBuffer(buffer.slice(1, 1 + byteLength))
3893
3894 var Q
3895 if (compressed) {
3896 assert.equal(buffer.length, byteLength + 1, 'Invalid sequence length')
3897 assert(type === 0x02 || type === 0x03, 'Invalid sequence tag')
3898
3899 var isOdd = (type === 0x03)
3900 Q = curve.pointFromX(isOdd, x)
3901 } else {
3902 assert.equal(buffer.length, 1 + byteLength + byteLength, 'Invalid sequence length')
3903
3904 var y = BigInteger.fromBuffer(buffer.slice(1 + byteLength))
3905 Q = Point.fromAffine(curve, x, y)
3906 }
3907
3908 Q.compressed = compressed
3909 return Q
3910}
3911
3912Point.prototype.toString = function () {
3913 if (this.curve.isInfinity(this)) return '(INFINITY)'
3914
3915 return '(' + this.affineX.toString() + ',' + this.affineY.toString() + ')'
3916}
3917
3918module.exports = Point
3919
3920},{"assert":74,"bigi":5,"safe-buffer":47}],38:[function(require,module,exports){
3921var Buffer = require('safe-buffer').Buffer
3922var MD5 = require('md5.js')
3923
3924/* eslint-disable camelcase */
3925function EVP_BytesToKey (password, salt, keyBits, ivLen) {
3926 if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary')
3927 if (salt) {
3928 if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary')
3929 if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length')
3930 }
3931
3932 var keyLen = keyBits / 8
3933 var key = Buffer.alloc(keyLen)
3934 var iv = Buffer.alloc(ivLen || 0)
3935 var tmp = Buffer.alloc(0)
3936
3937 while (keyLen > 0 || ivLen > 0) {
3938 var hash = new MD5()
3939 hash.update(tmp)
3940 hash.update(password)
3941 if (salt) hash.update(salt)
3942 tmp = hash.digest()
3943
3944 var used = 0
3945
3946 if (keyLen > 0) {
3947 var keyStart = key.length - keyLen
3948 used = Math.min(keyLen, tmp.length)
3949 tmp.copy(key, keyStart, 0, used)
3950 keyLen -= used
3951 }
3952
3953 if (used < tmp.length && ivLen > 0) {
3954 var ivStart = iv.length - ivLen
3955 var length = Math.min(ivLen, tmp.length - used)
3956 tmp.copy(iv, ivStart, used, used + length)
3957 ivLen -= length
3958 }
3959 }
3960
3961 tmp.fill(0)
3962 return { key: key, iv: iv }
3963}
3964
3965module.exports = EVP_BytesToKey
3966
3967},{"md5.js":45,"safe-buffer":47}],39:[function(require,module,exports){
3968'use strict';
3969
3970var groestl = require('./lib/groestl');
3971var h = require('./lib/helper');
3972
3973var x11hash = module.exports;
3974
3975module.exports.groestl512 = function(str,format, output) {
3976 return groestl(str,format,output);
3977}
3978
3979module.exports.groestl = function(str,format, output) {
3980 var a = groestl(str,format,2);
3981 a = a.slice(0,8);
3982 if (output === 2) {
3983 return a;
3984 }
3985 else if (output === 1) {
3986 return h.int32Buffer2Bytes(a);
3987 }
3988 else {
3989 return h.int32ArrayToHexString(a);
3990 }
3991}
3992
3993module.exports.groestl_2 = function(str,format, output) {
3994 var a = groestl(str,format,2);
3995 a = groestl(a,2,2);
3996 a = a.slice(0,8);
3997 if (output === 2) {
3998 return a;
3999 }
4000 else if (output === 1) {
4001 return h.int32Buffer2Bytes(a);
4002 }
4003 else {
4004 return h.int32ArrayToHexString(a);
4005 }
4006}
4007},{"./lib/groestl":40,"./lib/helper":41}],40:[function(require,module,exports){
4008/////////////////////////////////////
4009//////////// groestl ///////////////
4010
4011//// Written by Quantum Explorer ////
4012////////// Dash Foundation //////////
4013/// Released under the MIT License //
4014/////////////////////////////////////
4015
4016var o = require('./op');
4017var h = require('./helper');
4018
4019var T0 = h.bytes2Int64Buffer(h.b64Decode("xjL0pfSXpcb4b5eEl+uE+O5esJmwx5nu9nqMjYz3jfb/6BcNF+UN/9YK3L3ct73W3hbIscinsd6RbfxU/DlUkWCQ8FDwwFBgAgcFAwUEAwLOLuCp4IepzlbRh32HrH1W58wrGSvVGee1E6ZipnFitU18MeYxmuZN7Fm1mrXDmuyPQM9FzwVFjx+jvJ28Pp0fiUnAQMAJQIn6aJKHku+H+u/QPxU/xRXvspQm6yZ/67KOzkDJQAfJjvvmHQsd7Qv7QW4v7C+C7EGzGqlnqX1ns19DHP0cvv1fRWAl6iWK6kUj+dq/2ka/I1NRAvcCpvdT5EWhlqHTluSbdu1b7S1bm3UoXcJd6sJ14cUkHCTZHOE91Omu6XquPUzyvmq+mGpMbILuWu7YWmx+vcNBw/xBfvXzBgIG8QL1g1LRT9EdT4NojORc5NBcaFFWB/QHovRR0Y1cNFy5NNH54RgIGOkI+eJMrpOu35Piqz6Vc5VNc6til/VT9cRTYiprQT9BVD8qCBwUDBQQDAiVY/ZS9jFSlUbpr2WvjGVGnX/iXuIhXp0wSHgoeGAoMDfP+KH4bqE3ChsRDxEUDwov68S1xF61Lw4VGwkbHAkOJH5aNlpINiQbrbabtjabG9+YRz1HpT3fzadqJmqBJs1O9btpu5xpTn8zTM1M/s1/6lC6n7rPn+oSPy0bLSQbEh2kuZ65Op4dWMScdJywdFg0RnIucmguNDZBdy13bC023BHNss2jsty0nSnuKXPutFtNFvsWtvtbpKUB9gFT9qR2oddN1+xNdrcUo2GjdWG3fTRJzkn6zn1S3417jaR7Ut2fQj5CoT7dXs2TcZO8cV4TsaKXoiaXE6aiBPUEV/WmuQG4aLhpaLkAAAAAAAAAAMG1dCx0mSzBQOCgYKCAYEDjwiEfId0f43k6Q8hD8sh5tpos7Sx37bbUDdm+2bO+1I1HykbKAUaNZxdw2XDO2Wdyr91L3eRLcpTted55M96UmP9n1Gcr1JiwkyPoI3vosIVb3kreEUqFuwa9a71ta7vFu34qfpEqxU97NOU0nuVP7dc6FjrBFu2G0lTFVBfFhpr4YtdiL9eaZpn/Vf/MVWYRtqeUpyKUEYrASs9KD8+K6dkwEDDJEOkEDgoGCggGBP5mmIGY54H+oKsL8Atb8KB4tMxEzPBEeCXw1brVSrolS3U+4z6W40uirA7zDl/zol1EGf4Zuv5dgNtbwFsbwIAFgIWKhQqKBT/T7K3sfq0/If7fvN9CvCFwqNhI2OBIcPH9DAQM+QTxYxl633rG32N3L1jBWO7Bd68wn3WfRXWvQuelY6WEY0IgcFAwUEAwIOXLLhou0Rrl/e8SDhLhDv2/CLdtt2Vtv4FV1EzUGUyBGCQ8FDwwFBgmeV81X0w1JsOycS9xnS/DvoY44Thn4b41yP2i/WqiNYjHT8xPC8yILmVLOUtcOS6TavlX+T1Xk1VYDfINqvJV/GGdgp3jgvx6s8lHyfRHesgn76zvi6zIuogy5zJv57oyT30rfWQrMuZCpJWk15XmwDv7oPuboMAZqrOYszKYGZ72aNFoJ9GeoyKBf4Fdf6NE7qpmqohmRFTWgn6CqH5UO93mq+Z2qzsLlZ6DnhaDC4zJRcpFA8qMx7x7KXuVKcdrBW7TbtbTayhsRDxEUDwopyyLeYtVeae8gT3iPWPivBYxJx0nLB0WrTeadppBdq3blk07Ta0722Se+lb6yFZkdKbSTtLoTnQUNiIeIigeFJLkdtt2P9uSDBIeCh4YCgxI/LRstJBsSLiPN+Q3a+S4n3jnXeclXZ+9D7JusmFuvUNpKu8qhu9DxDXxpvGTpsQ52uOo43KoOTHG96T3YqQx04pZN1m9N9PydIaLhv+L8tWDVjJWsTLVi07FQ8UNQ4tuhetZ69xZbtoYwrfCr7faAY6PjI8CjAGxHaxkrHlksZzxbdJtI9KcSXI74DuS4EnYH8e0x6u02Ky5FfoVQ/qs8/oJBwn9B/PPoG8lb4Ulz8og6q/qj6/K9H2JjonzjvRHZyDpII7pRxA4KBgoIBgQbwtk1WTe1W/wc4OIg/uI8Er7sW+xlG9KXMqWcpa4clw4VGwkbHAkOFdfCPEIrvFXcyFSx1Lmx3OXZPNR8zVRl8uuZSNljSPLoSWEfIRZfKHoV7+cv8uc6D5dYyFjfCE+lup83Xw33ZZhHn/cf8LcYQ2ckYaRGoYND5uUhZQehQ/gS6uQq9uQ4Hy6xkLG+EJ8cSZXxFfixHHMKeWq5YOqzJDjc9hzO9iQBgkPBQ8MBQb39AMBA/UB9xwqNhI2OBIcwjz+o/6fo8Jqi+Ff4dRfaq6+EPkQR/muaQJr0GvS0GkXv6iRqC6RF5lx6FjoKViZOlNpJ2l0Jzon99C50E65J9mRSDhIqTjZ6941EzXNE+sr5c6zzlazKyJ3VTNVRDMi0gTWu9a/u9KpOZBwkElwqQeHgImADokHM8Hyp/JmpzMt7MG2wVq2LTxaZiJmeCI8Fbitkq0qkhXJqWAgYIkgyYdc20nbFUmHqrAa/xpP/6pQ2Ih4iKB4UKUrjnqOUXqlA4mKj4oGjwNZShP4E7L4WQmSm4CbEoAJGiM5Fzk0FxplEHXadcraZdeEUzFTtTHXhNVRxlETxoTQA9O407u40ILcXsNeH8OCKeLLsMtSsClaw5l3mbR3Wh4tMxEzPBEeez1Gy0b2y3uotx/8H0v8qG0MYdZh2tZtLGJOOk5YOiw="));
4020var T1 = h.bytes2Int64Buffer(h.b64Decode("xsYy9KX0l6X4+G+XhJfrhO7uXrCZsMeZ9vZ6jI2M943//+gXDRflDdbWCty93Le93t4WyLHIp7GRkW38VPw5VGBgkPBQ8MBQAgIHBQMFBAPOzi7gqeCHqVZW0Yd9h6x95+fMKxkr1Rm1tROmYqZxYk1NfDHmMZrm7OxZtZq1w5qPj0DPRc8FRR8fo7ydvD6diYlJwEDACUD6+miSh5Lvh+/v0D8VP8UVsrKUJusmf+uOjs5AyUAHyfv75h0LHe0LQUFuL+wvguyzsxqpZ6l9Z19fQxz9HL79RUVgJeoliuojI/nav9pGv1NTUQL3Aqb35ORFoZah05abm3btW+0tW3V1KF3CXerC4eHFJBwk2Rw9PdTprul6rkxM8r5qvphqbGyC7lru2Fp+fr3DQcP8QfX18wYCBvECg4NS0U/RHU9oaIzkXOTQXFFRVgf0B6L00dGNXDRcuTT5+eEYCBjpCOLiTK6Trt+Tq6s+lXOVTXNiYpf1U/XEUyoqa0E/QVQ/CAgcFAwUEAyVlWP2UvYxUkZG6a9lr4xlnZ1/4l7iIV4wMEh4KHhgKDc3z/ih+G6hCgobEQ8RFA8vL+vEtcRetQ4OFRsJGxwJJCR+WjZaSDYbG622m7Y2m9/fmEc9R6U9zc2naiZqgSZOTvW7abucaX9/M0zNTP7N6upQup+6z58SEj8tGy0kGx0dpLmeuTqeWFjEnHScsHQ0NEZyLnJoLjY2QXctd2wt3NwRzbLNo7K0tJ0p7ilz7ltbTRb7Frb7pKSlAfYBU/Z2dqHXTdfsTbe3FKNho3VhfX00Sc5J+s5SUt+Ne42ke93dn0I+QqE+Xl7Nk3GTvHETE7Gil6Iml6amogT1BFf1ubkBuGi4aWgAAAAAAAAAAMHBtXQsdJksQEDgoGCggGDj48IhHyHdH3l5OkPIQ/LItraaLO0sd+3U1A3Zvtmzvo2NR8pGygFGZ2cXcNlwztlycq/dS93kS5SU7XneeTPemJj/Z9RnK9SwsJMj6CN76IWFW95K3hFKu7sGvWu9bWvFxbt+Kn6RKk9PezTlNJ7l7e3XOhY6wRaGhtJUxVQXxZqa+GLXYi/XZmaZ/1X/zFUREbanlKcilIqKwErPSg/P6enZMBAwyRAEBA4KBgoIBv7+ZpiBmOeBoKCrC/ALW/B4eLTMRMzwRCUl8NW61Uq6S0t1PuM+luOioqwO8w5f811dRBn+Gbr+gIDbW8BbG8AFBYCFioUKij8/0+yt7H6tISH+37zfQrxwcKjYSNjgSPHx/QwEDPkEY2MZet96xt93dy9YwVjuwa+vMJ91n0V1QkLnpWOlhGMgIHBQMFBAMOXlyy4aLtEa/f3vEg4S4Q6/vwi3bbdlbYGBVdRM1BlMGBgkPBQ8MBQmJnlfNV9MNcPDsnEvcZ0vvr6GOOE4Z+E1Ncj9ov1qooiIx0/MTwvMLi5lSzlLXDmTk2r5V/k9V1VVWA3yDary/PxhnYKd44J6erPJR8n0R8jIJ++s74usurqIMucyb+cyMk99K31kK+bmQqSVpNeVwMA7+6D7m6AZGaqzmLMymJ6e9mjRaCfRo6MigX+BXX9ERO6qZqqIZlRU1oJ+gqh+Ozvd5qvmdqsLC5Weg54Wg4yMyUXKRQPKx8e8eyl7lSlrawVu027W0ygobEQ8RFA8p6csi3mLVXm8vIE94j1j4hYWMScdJywdra03mnaaQXbb25ZNO02tO2RknvpW+shWdHSm0k7S6E4UFDYiHiIoHpKS5Hbbdj/bDAwSHgoeGApISPy0bLSQbLi4jzfkN2vkn594513nJV29vQ+ybrJhbkNDaSrvKobvxMQ18abxk6Y5OdrjqONyqDExxvek92Kk09OKWTdZvTfy8nSGi4b/i9XVg1YyVrEyi4tOxUPFDUNuboXrWevcWdraGMK3wq+3AQGOj4yPAoyxsR2sZKx5ZJyc8W3SbSPSSUlyO+A7kuDY2B/HtMertKysuRX6FUP68/P6CQcJ/QfPz6BvJW+FJcrKIOqv6o+v9PR9iY6J845HR2cg6SCO6RAQOCgYKCAYb28LZNVk3tXw8HODiIP7iEpK+7FvsZRvXFzKlnKWuHI4OFRsJGxwJFdXXwjxCK7xc3MhUsdS5seXl2TzUfM1UcvLrmUjZY0joaElhHyEWXzo6Fe/nL/LnD4+XWMhY3whlpbqfN18N91hYR5/3H/C3A0NnJGGkRqGDw+blIWUHoXg4EurkKvbkHx8usZCxvhCcXEmV8RX4sTMzCnlquWDqpCQ43PYczvYBgYJDwUPDAX39/QDAQP1ARwcKjYSNjgSwsI8/qP+n6NqaovhX+HUX66uvhD5EEf5aWkCa9Br0tAXF7+okagukZmZcehY6ClYOjpTaSdpdCcnJ/fQudBOudnZkUg4SKk46+veNRM1zRMrK+XOs85WsyIid1UzVUQz0tIE1rvWv7upqTmQcJBJcAcHh4CJgA6JMzPB8qfyZqctLezBtsFatjw8WmYiZngiFRW4rZKtKpLJyalgIGCJIIeHXNtJ2xVJqqqwGv8aT/9QUNiIeIigeKWlK456jlF6AwOJio+KBo9ZWUoT+BOy+AkJkpuAmxKAGhojORc5NBdlZRB12nXK2tfXhFMxU7UxhITVUcZRE8bQ0APTuNO7uIKC3F7DXh/DKSniy7DLUrBaWsOZd5m0dx4eLTMRMzwRe3s9RstG9suoqLcf/B9L/G1tDGHWYdrWLCxiTjpOWDo="));
4021var T2 = h.bytes2Int64Buffer(h.b64Decode("pcbGMvSl9JeE+Phvl4SX65nu7l6wmbDHjfb2eoyNjPcN///oFw0X5b3W1grcvdy3sd7eFsixyKdUkZFt/FT8OVBgYJDwUPDAAwICBwUDBQSpzs4u4Kngh31WVtGHfYesGefnzCsZK9VitbUTpmKmceZNTXwx5jGamuzsWbWatcNFj49Az0XPBZ0fH6O8nbw+QImJScBAwAmH+vpokoeS7xXv79A/FT/F67KylCbrJn/Jjo7OQMlABwv7++YdCx3t7EFBbi/sL4Jns7MaqWepff1fX0Mc/Ry+6kVFYCXqJYq/IyP52r/aRvdTU1EC9wKmluTkRaGWodNbm5t27VvtLcJ1dShdwl3qHOHhxSQcJNmuPT3U6a7pempMTPK+ar6YWmxsgu5a7thBfn69w0HD/AL19fMGAgbxT4ODUtFP0R1caGiM5Fzk0PRRUVYH9AeiNNHRjVw0XLkI+fnhGAgY6ZPi4kyuk67fc6urPpVzlU1TYmKX9VP1xD8qKmtBP0FUDAgIHBQMFBBSlZVj9lL2MWVGRumvZa+MXp2df+Je4iEoMDBIeCh4YKE3N8/4ofhuDwoKGxEPERS1Ly/rxLXEXgkODhUbCRscNiQkflo2WkibGxuttpu2Nj3f35hHPUelJs3Np2omaoFpTk71u2m7nM1/fzNMzUz+n+rqULqfus8bEhI/LRstJJ4dHaS5nrk6dFhYxJx0nLAuNDRGci5yaC02NkF3LXdsstzcEc2yzaPutLSdKe4pc/tbW00W+xa29qSkpQH2AVNNdnah103X7GG3txSjYaN1zn19NEnOSfp7UlLfjXuNpD7d3Z9CPkKhcV5ezZNxk7yXExOxopeiJvWmpqIE9QRXaLm5AbhouGkAAAAAAAAAACzBwbV0LHSZYEBA4KBgoIAf4+PCIR8h3ch5eTpDyEPy7ba2miztLHe+1NQN2b7Zs0aNjUfKRsoB2WdnF3DZcM5LcnKv3Uvd5N6UlO153nkz1JiY/2fUZyvosLCTI+gje0qFhVveSt4Ra7u7Br1rvW0qxcW7fip+keVPT3s05TSeFu3t1zoWOsHFhobSVMVUF9eamvhi12IvVWZmmf9V/8yUERG2p5SnIs+KisBKz0oPEOnp2TAQMMkGBAQOCgYKCIH+/maYgZjn8KCgqwvwC1tEeHi0zETM8LolJfDVutVK40tLdT7jPpbzoqKsDvMOX/5dXUQZ/hm6wICA21vAWxuKBQWAhYqFCq0/P9Psrex+vCEh/t+830JIcHCo2EjY4ATx8f0MBAz532NjGXrfesbBd3cvWMFY7nWvrzCfdZ9FY0JC56VjpYQwICBwUDBQQBrl5csuGi7RDv397xIOEuFtv78It223ZUyBgVXUTNQZFBgYJDwUPDA1JiZ5XzVfTC/Dw7JxL3Gd4b6+hjjhOGeiNTXI/aL9asyIiMdPzE8LOS4uZUs5S1xXk5Nq+Vf5PfJVVVgN8g2qgvz8YZ2CneNHenqzyUfJ9KzIyCfvrO+L57q6iDLnMm8rMjJPfSt9ZJXm5kKklaTXoMDAO/ug+5uYGRmqs5izMtGenvZo0Wgnf6OjIoF/gV1mRETuqmaqiH5UVNaCfoKoqzs73ear5naDCwuVnoOeFsqMjMlFykUDKcfHvHspe5XTa2sFbtNu1jwoKGxEPERQeaenLIt5i1XivLyBPeI9Yx0WFjEnHScsdq2tN5p2mkE729uWTTtNrVZkZJ76VvrITnR0ptJO0ugeFBQ2Ih4iKNuSkuR223Y/CgwMEh4KHhhsSEj8tGy0kOS4uI835DdrXZ+feOdd5yVuvb0Psm6yYe9DQ2kq7yqGpsTENfGm8ZOoOTna46jjcqQxMcb3pPdiN9PTilk3Wb2L8vJ0houG/zLV1YNWMlaxQ4uLTsVDxQ1Zbm6F61nr3Lfa2hjCt8KvjAEBjo+MjwJksbEdrGSsedKcnPFt0m0j4ElJcjvgO5K02Ngfx7THq/qsrLkV+hVDB/Pz+gkHCf0lz8+gbyVvha/KyiDqr+qPjvT0fYmOifPpR0dnIOkgjhgQEDgoGCgg1W9vC2TVZN6I8PBzg4iD+29KSvuxb7GUclxcypZylrgkODhUbCRscPFXV18I8Qiux3NzIVLHUuZRl5dk81HzNSPLy65lI2WNfKGhJYR8hFmc6OhXv5y/yyE+Pl1jIWN83ZaW6nzdfDfcYWEef9x/woYNDZyRhpEahQ8Pm5SFlB6Q4OBLq5Cr20J8fLrGQsb4xHFxJlfEV+KqzMwp5arlg9iQkONz2HM7BQYGCQ8FDwwB9/f0AwED9RIcHCo2EjY4o8LCPP6j/p9famqL4V/h1Pmurr4Q+RBH0GlpAmvQa9KRFxe/qJGoLliZmXHoWOgpJzo6U2knaXS5Jyf30LnQTjjZ2ZFIOEipE+vr3jUTNc2zKyvlzrPOVjMiIndVM1VEu9LSBNa71r9wqak5kHCQSYkHB4eAiYAOpzMzwfKn8ma2LS3swbbBWiI8PFpmImZ4khUVuK2SrSogycmpYCBgiUmHh1zbSdsV/6qqsBr/Gk94UFDYiHiIoHqlpSuOeo5RjwMDiYqPigb4WVlKE/gTsoAJCZKbgJsSFxoaIzkXOTTaZWUQddp1yjHX14RTMVO1xoSE1VHGURO40NAD07jTu8OCgtxew14fsCkp4suwy1J3WlrDmXeZtBEeHi0zETM8y3t7PUbLRvb8qKi3H/wfS9ZtbQxh1mHaOiwsYk46Tlg="));
4022var T3 = h.bytes2Int64Buffer(h.b64Decode("l6XGxjL0pfTrhPj4b5eEl8eZ7u5esJmw94329nqMjYzlDf//6BcNF7e91tYK3L3cp7He3hbIscg5VJGRbfxU/MBQYGCQ8FDwBAMCAgcFAwWHqc7OLuCp4Kx9VlbRh32H1Rnn58wrGStxYrW1E6ZipprmTU18MeYxw5rs7Fm1mrUFRY+PQM9Fzz6dHx+jvJ28CUCJiUnAQMDvh/r6aJKHksUV7+/QPxU/f+uyspQm6yYHyY6OzkDJQO0L+/vmHQsdguxBQW4v7C99Z7OzGqlnqb79X19DHP0ciupFRWAl6iVGvyMj+dq/2qb3U1NRAvcC05bk5EWhlqEtW5ubdu1b7erCdXUoXcJd2Rzh4cUkHCR6rj091Omu6ZhqTEzyvmq+2FpsbILuWu78QX5+vcNBw/EC9fXzBgIGHU+Dg1LRT9HQXGhojORc5KL0UVFWB/QHuTTR0Y1cNFzpCPn54RgIGN+T4uJMrpOuTXOrqz6Vc5XEU2Jil/VT9VQ/KiprQT9BEAwICBwUDBQxUpWVY/ZS9oxlRkbpr2WvIV6dnX/iXuJgKDAwSHgoeG6hNzfP+KH4FA8KChsRDxFetS8v68S1xBwJDg4VGwkbSDYkJH5aNlo2mxsbrbabtqU939+YRz1HgSbNzadqJmqcaU5O9btpu/7Nf38zTM1Mz5/q6lC6n7okGxISPy0bLTqeHR2kuZ65sHRYWMScdJxoLjQ0RnIucmwtNjZBdy13o7Lc3BHNss1z7rS0nSnuKbb7W1tNFvsWU/akpKUB9gHsTXZ2oddN13Vht7cUo2Gj+s59fTRJzkmke1JS3417jaE+3d2fQj5CvHFeXs2TcZMmlxMTsaKXolf1pqaiBPUEaWi5uQG4aLgAAAAAAAAAAJkswcG1dCx0gGBAQOCgYKDdH+PjwiEfIfLIeXk6Q8hDd+22tpos7SyzvtTUDdm+2QFGjY1HykbKztlnZxdw2XDkS3Jyr91L3TPelJTted55K9SYmP9n1Gd76LCwkyPoIxFKhYVb3krebWu7uwa9a72RKsXFu34qfp7lT097NOU0wRbt7dc6FjoXxYaG0lTFVC/Xmpr4YtdizFVmZpn/Vf8ilBERtqeUpw/PiorASs9KyRDp6dkwEDAIBgQEDgoGCueB/v5mmIGYW/CgoKsL8AvwRHh4tMxEzEq6JSXw1brVluNLS3U+4z5f86KirA7zDrr+XV1EGf4ZG8CAgNtbwFsKigUFgIWKhX6tPz/T7K3sQrwhIf7fvN/gSHBwqNhI2PkE8fH9DAQMxt9jYxl633ruwXd3L1jBWEV1r68wn3WfhGNCQuelY6VAMCAgcFAwUNEa5eXLLhou4Q79/e8SDhJlbb+/CLdttxlMgYFV1EzUMBQYGCQ8FDxMNSYmeV81X50vw8OycS9xZ+G+voY44ThqojU1yP2i/QvMiIjHT8xPXDkuLmVLOUs9V5OTavlX+aryVVVYDfIN44L8/GGdgp30R3p6s8lHyYusyMgn76zvb+e6uogy5zJkKzIyT30rfdeV5uZCpJWkm6DAwDv7oPsymBkZqrOYsyfRnp72aNFoXX+joyKBf4GIZkRE7qpmqqh+VFTWgn6Cdqs7O93mq+YWgwsLlZ6DngPKjIzJRcpFlSnHx7x7KXvW02trBW7TblA8KChsRDxEVXmnpyyLeYtj4ry8gT3iPSwdFhYxJx0nQXatrTeadpqtO9vblk07TchWZGSe+lb66E50dKbSTtIoHhQUNiIeIj/bkpLkdtt2GAoMDBIeCh6QbEhI/LRstGvkuLiPN+Q3JV2fn3jnXedhbr29D7JusobvQ0NpKu8qk6bExDXxpvFyqDk52uOo42KkMTHG96T3vTfT04pZN1n/i/LydIaLhrEy1dWDVjJWDUOLi07FQ8XcWW5uhetZ66+32toYwrfCAowBAY6PjI95ZLGxHaxkrCPSnJzxbdJtkuBJSXI74DurtNjYH8e0x0P6rKy5FfoV/Qfz8/oJBwmFJc/PoG8lb4+vysog6q/q84709H2JjomO6UdHZyDpICAYEBA4KBgo3tVvbwtk1WT7iPDwc4OIg5RvSkr7sW+xuHJcXMqWcpZwJDg4VGwkbK7xV1dfCPEI5sdzcyFSx1I1UZeXZPNR840jy8uuZSNlWXyhoSWEfITLnOjoV7+cv3whPj5dYyFjN92Wlup83XzC3GFhHn/cfxqGDQ2ckYaRHoUPD5uUhZTbkODgS6uQq/hCfHy6xkLG4sRxcSZXxFeDqszMKeWq5TvYkJDjc9hzDAUGBgkPBQ/1Aff39AMBAzgSHBwqNhI2n6PCwjz+o/7UX2pqi+Ff4Uf5rq6+EPkQ0tBpaQJr0GsukRcXv6iRqClYmZlx6FjodCc6OlNpJ2lOuScn99C50Kk42dmRSDhIzRPr6941EzVWsysr5c6zzkQzIiJ3VTNVv7vS0gTWu9ZJcKmpOZBwkA6JBweHgImAZqczM8Hyp/Jati0t7MG2wXgiPDxaZiJmKpIVFbitkq2JIMnJqWAgYBVJh4dc20nbT/+qqrAa/xqgeFBQ2Ih4iFF6paUrjnqOBo8DA4mKj4qy+FlZShP4ExKACQmSm4CbNBcaGiM5FznK2mVlEHXadbUx19eEUzFTE8aEhNVRxlG7uNDQA9O40x/DgoLcXsNeUrApKeLLsMu0d1paw5l3mTwRHh4tMxEz9st7ez1Gy0ZL/Kiotx/8H9rWbW0MYdZhWDosLGJOOk4="));
4023var T4 = h.bytes2Int64Buffer(h.b64Decode("9JelxsYy9KWX64T4+G+XhLDHme7uXrCZjPeN9vZ6jI0X5Q3//+gXDdy3vdbWCty9yKex3t4WyLH8OVSRkW38VPDAUGBgkPBQBQQDAgIHBQPgh6nOzi7gqYesfVZW0Yd9K9UZ5+fMKxmmcWK1tROmYjGa5k1NfDHmtcOa7OxZtZrPBUWPj0DPRbw+nR8fo7ydwAlAiYlJwECS74f6+miShz/FFe/v0D8VJn/rsrKUJutAB8mOjs5AyR3tC/v75h0LL4LsQUFuL+ypfWezsxqpZxy+/V9fQxz9JYrqRUVgJeraRr8jI/navwKm91NTUQL3odOW5ORFoZbtLVubm3btW13qwnV1KF3CJNkc4eHFJBzpeq49PdTprr6YakxM8r5q7thabGyC7lrD/EF+fr3DQQbxAvX18wYC0R1Pg4NS0U/k0FxoaIzkXAei9FFRVgf0XLk00dGNXDQY6Qj5+eEYCK7fk+LiTK6TlU1zq6s+lXP1xFNiYpf1U0FUPyoqa0E/FBAMCAgcFAz2MVKVlWP2Uq+MZUZG6a9l4iFenZ1/4l54YCgwMEh4KPhuoTc3z/ihERQPCgobEQ/EXrUvL+vEtRscCQ4OFRsJWkg2JCR+Wja2NpsbG622m0elPd/fmEc9aoEmzc2naia7nGlOTvW7aUz+zX9/M0zNus+f6upQup8tJBsSEj8tG7k6nh0dpLmenLB0WFjEnHRyaC40NEZyLndsLTY2QXctzaOy3NwRzbIpc+60tJ0p7ha2+1tbTRb7AVP2pKSlAfbX7E12dqHXTaN1Ybe3FKNhSfrOfX00Sc6NpHtSUt+Ne0KhPt3dn0I+k7xxXl7Nk3GiJpcTE7GilwRX9aamogT1uGloubkBuGgAAAAAAAAAAHSZLMHBtXQsoIBgQEDgoGAh3R/j48IhH0PyyHl5OkPILHfttraaLO3Zs77U1A3ZvsoBRo2NR8pGcM7ZZ2cXcNnd5Etycq/dS3kz3pSU7XneZyvUmJj/Z9Qje+iwsJMj6N4RSoWFW95KvW1ru7sGvWt+kSrFxbt+KjSe5U9PezTlOsEW7e3XOhZUF8WGhtJUxWIv15qa+GLX/8xVZmaZ/1WnIpQREbanlEoPz4qKwErPMMkQ6enZMBAKCAYEBA4KBpjngf7+ZpiBC1vwoKCrC/DM8ER4eLTMRNVKuiUl8NW6PpbjS0t1PuMOX/OioqwO8xm6/l1dRBn+WxvAgIDbW8CFCooFBYCFiux+rT8/0+yt30K8ISH+37zY4EhwcKjYSAz5BPHx/QwEesbfY2MZet9Y7sF3dy9YwZ9Fda+vMJ91pYRjQkLnpWNQQDAgIHBQMC7RGuXlyy4aEuEO/f3vEg63ZW2/vwi3bdQZTIGBVdRMPDAUGBgkPBRfTDUmJnlfNXGdL8PDsnEvOGfhvr6GOOH9aqI1Ncj9ok8LzIiIx0/MS1w5Li5lSzn5PVeTk2r5Vw2q8lVVWA3yneOC/PxhnYLJ9Ed6erPJR++LrMjIJ++sMm/nurqIMud9ZCsyMk99K6TXlebmQqSV+5ugwMA7+6CzMpgZGaqzmGgn0Z6e9mjRgV1/o6MigX+qiGZERO6qZoKoflRU1oJ+5narOzvd5queFoMLC5Weg0UDyoyMyUXKe5Upx8e8eylu1tNrawVu00RQPCgobEQ8i1V5p6csi3k9Y+K8vIE94icsHRYWMScdmkF2ra03mnZNrTvb25ZNO/rIVmRknvpW0uhOdHSm0k4iKB4UFDYiHnY/25KS5HbbHhgKDAwSHgq0kGxISPy0bDdr5Li4jzfk5yVdn594512yYW69vQ+ybiqG70NDaSrv8ZOmxMQ18abjcqg5OdrjqPdipDExxvekWb0309OKWTeG/4vy8nSGi1axMtXVg1YyxQ1Di4tOxUPr3FluboXrWcKvt9raGMK3jwKMAQGOj4yseWSxsR2sZG0j0pyc8W3SO5LgSUlyO+DHq7TY2B/HtBVD+qysuRX6Cf0H8/P6CQdvhSXPz6BvJeqPr8rKIOqvifOO9PR9iY4gjulHR2cg6SggGBAQOCgYZN7Vb28LZNWD+4jw8HODiLGUb0pK+7FvlrhyXFzKlnJscCQ4OFRsJAiu8VdXXwjxUubHc3MhUsfzNVGXl2TzUWWNI8vLrmUjhFl8oaElhHy/y5zo6Fe/nGN8IT4+XWMhfDfdlpbqfN1/wtxhYR5/3JEahg0NnJGGlB6FDw+blIWr25Dg4EurkMb4Qnx8usZCV+LEcXEmV8Tlg6rMzCnlqnM72JCQ43PYDwwFBgYJDwUD9QH39/QDATY4EhwcKjYS/p+jwsI8/qPh1F9qaovhXxBH+a6uvhD5a9LQaWkCa9CoLpEXF7+okegpWJmZcehYaXQnOjpTaSfQTrknJ/fQuUipONnZkUg4Nc0T6+veNRPOVrMrK+XOs1VEMyIid1Uz1r+70tIE1ruQSXCpqTmQcIAOiQcHh4CJ8manMzPB8qfBWrYtLezBtmZ4Ijw8WmYirSqSFRW4rZJgiSDJyalgINsVSYeHXNtJGk//qqqwGv+IoHhQUNiIeI5ReqWlK456igaPAwOJio8TsvhZWUoT+JsSgAkJkpuAOTQXGhojORd1ytplZRB12lO1MdfXhFMxURPGhITVUcbTu7jQ0APTuF4fw4KC3F7Dy1KwKSniy7CZtHdaWsOZdzM8ER4eLTMRRvbLe3s9RssfS/yoqLcf/GHa1m1tDGHWTlg6LCxiTjo="));
4024var T5 = h.bytes2Int64Buffer(h.b64Decode("pfSXpcbGMvSEl+uE+Phvl5mwx5nu7l6wjYz3jfb2eowNF+UN///oF73ct73W1grcscinsd7eFshU/DlUkZFt/FDwwFBgYJDwAwUEAwICBwWp4Iepzs4u4H2HrH1WVtGHGSvVGefnzCtipnFitbUTpuYxmuZNTXwxmrXDmuzsWbVFzwVFj49Az528Pp0fH6O8QMAJQImJScCHku+H+vpokhU/xRXv79A/6yZ/67KylCbJQAfJjo7OQAsd7Qv7++Yd7C+C7EFBbi9nqX1ns7Maqf0cvv1fX0Mc6iWK6kVFYCW/2ka/IyP52vcCpvdTU1EClqHTluTkRaFb7S1bm5t27cJd6sJ1dShdHCTZHOHhxSSu6XquPT3U6Wq+mGpMTPK+Wu7YWmxsgu5Bw/xBfn69wwIG8QL19fMGT9EdT4ODUtFc5NBcaGiM5PQHovRRUVYHNFy5NNHRjVwIGOkI+fnhGJOu35Pi4kyuc5VNc6urPpVT9cRTYmKX9T9BVD8qKmtBDBQQDAgIHBRS9jFSlZVj9mWvjGVGRumvXuIhXp2df+IoeGAoMDBIeKH4bqE3N8/4DxEUDwoKGxG1xF61Ly/rxAkbHAkODhUbNlpINiQkflqbtjabGxuttj1HpT3f35hHJmqBJs3Np2ppu5xpTk71u81M/s1/fzNMn7rPn+rqULobLSQbEhI/LZ65Op4dHaS5dJywdFhYxJwucmguNDRGci13bC02NkF3ss2jstzcEc3uKXPutLSdKfsWtvtbW00W9gFT9qSkpQFN1+xNdnah12GjdWG3txSjzkn6zn19NEl7jaR7UlLfjT5CoT7d3Z9CcZO8cV5ezZOXoiaXExOxovUEV/WmpqIEaLhpaLm5AbgAAAAAAAAAACx0mSzBwbV0YKCAYEBA4KAfId0f4+PCIchD8sh5eTpD7Sx37ba2miy+2bO+1NQN2UbKAUaNjUfK2XDO2WdnF3BL3eRLcnKv3d55M96UlO151Gcr1JiY/2foI3vosLCTI0reEUqFhVvea71ta7u7Br0qfpEqxcW7fuU0nuVPT3s0FjrBFu3t1zrFVBfFhobSVNdiL9eamvhiVf/MVWZmmf+UpyKUERG2p89KD8+KisBKEDDJEOnp2TAGCggGBAQOCoGY54H+/maY8Atb8KCgqwtEzPBEeHi0zLrVSrolJfDV4z6W40tLdT7zDl/zoqKsDv4Zuv5dXUQZwFsbwICA21uKhQqKBQWAha3sfq0/P9PsvN9CvCEh/t9I2OBIcHCo2AQM+QTx8f0M33rG32NjGXrBWO7Bd3cvWHWfRXWvrzCfY6WEY0JC56UwUEAwICBwUBou0Rrl5csuDhLhDv397xJtt2Vtv78It0zUGUyBgVXUFDwwFBgYJDw1X0w1JiZ5Xy9xnS/Dw7Jx4Thn4b6+hjii/WqiNTXI/cxPC8yIiMdPOUtcOS4uZUtX+T1Xk5Nq+fINqvJVVVgNgp3jgvz8YZ1HyfRHenqzyazvi6zIyCfv5zJv57q6iDIrfWQrMjJPfZWk15Xm5kKkoPuboMDAO/uYszKYGRmqs9FoJ9GenvZof4Fdf6OjIoFmqohmRETuqn6CqH5UVNaCq+Z2qzs73eaDnhaDCwuVnspFA8qMjMlFKXuVKcfHvHvTbtbTa2sFbjxEUDwoKGxEeYtVeaenLIviPWPivLyBPR0nLB0WFjEndppBdq2tN5o7Ta0729uWTVb6yFZkZJ76TtLoTnR0ptIeIigeFBQ2Itt2P9uSkuR2Ch4YCgwMEh5stJBsSEj8tOQ3a+S4uI83XeclXZ+feOdusmFuvb0Psu8qhu9DQ2kqpvGTpsTENfGo43KoOTna46T3YqQxMcb3N1m9N9PTilmLhv+L8vJ0hjJWsTLV1YNWQ8UNQ4uLTsVZ69xZbm6F67fCr7fa2hjCjI8CjAEBjo9krHlksbEdrNJtI9KcnPFt4DuS4ElJcju0x6u02Ngfx/oVQ/qsrLkVBwn9B/Pz+gklb4Ulz8+gb6/qj6/KyiDqjonzjvT0fYnpII7pR0dnIBgoIBgQEDgo1WTe1W9vC2SIg/uI8PBzg2+xlG9KSvuxcpa4clxcypYkbHAkODhUbPEIrvFXV18Ix1Lmx3NzIVJR8zVRl5dk8yNljSPLy65lfIRZfKGhJYScv8uc6OhXvyFjfCE+Pl1j3Xw33ZaW6nzcf8LcYWEef4aRGoYNDZyRhZQehQ8Pm5SQq9uQ4OBLq0LG+EJ8fLrGxFfixHFxJleq5YOqzMwp5dhzO9iQkONzBQ8MBQYGCQ8BA/UB9/f0AxI2OBIcHCo2o/6fo8LCPP5f4dRfamqL4fkQR/murr4Q0GvS0GlpAmuRqC6RFxe/qFjoKViZmXHoJ2l0Jzo6U2m50E65Jyf30DhIqTjZ2ZFIEzXNE+vr3jWzzlazKyvlzjNVRDMiIndVu9a/u9LSBNZwkElwqak5kImADokHB4eAp/JmpzMzwfK2wVq2LS3swSJmeCI8PFpmkq0qkhUVuK0gYIkgycmpYEnbFUmHh1zb/xpP/6qqsBp4iKB4UFDYiHqOUXqlpSuOj4oGjwMDiYr4E7L4WVlKE4CbEoAJCZKbFzk0FxoaIznadcraZWUQdTFTtTHX14RTxlETxoSE1VG407u40NAD08NeH8OCgtxesMtSsCkp4st3mbR3WlrDmREzPBEeHi0zy0b2y3t7PUb8H0v8qKi3H9Zh2tZtbQxhOk5YOiwsYk4="));
4025var T6 = h.bytes2Int64Buffer(h.b64Decode("9KX0l6XGxjKXhJfrhPj4b7CZsMeZ7u5ejI2M94329noXDRflDf//6Ny93Le91tYKyLHIp7He3hb8VPw5VJGRbfBQ8MBQYGCQBQMFBAMCAgfgqeCHqc7OLod9h6x9VlbRKxkr1Rnn58ymYqZxYrW1EzHmMZrmTU18tZq1w5rs7FnPRc8FRY+PQLydvD6dHx+jwEDACUCJiUmSh5Lvh/r6aD8VP8UV7+/QJusmf+uyspRAyUAHyY6Ozh0LHe0L+/vmL+wvguxBQW6pZ6l9Z7OzGhz9HL79X19DJeoliupFRWDav9pGvyMj+QL3Aqb3U1NRoZah05bk5EXtW+0tW5ubdl3CXerCdXUoJBwk2Rzh4cXprul6rj091L5qvphqTEzy7lru2FpsbILDQcP8QX5+vQYCBvEC9fXz0U/RHU+Dg1LkXOTQXGhojAf0B6L0UVFWXDRcuTTR0Y0YCBjpCPn54a6Trt+T4uJMlXOVTXOrqz71U/XEU2Jil0E/QVQ/KiprFAwUEAwICBz2UvYxUpWVY69lr4xlRkbp4l7iIV6dnX94KHhgKDAwSPih+G6hNzfPEQ8RFA8KChvEtcRetS8v6xsJGxwJDg4VWjZaSDYkJH62m7Y2mxsbrUc9R6U939+YaiZqgSbNzae7abucaU5O9UzNTP7Nf38zup+6z5/q6lAtGy0kGxISP7meuTqeHR2knHScsHRYWMRyLnJoLjQ0Rnctd2wtNjZBzbLNo7Lc3BEp7ilz7rS0nRb7Frb7W1tNAfYBU/akpKXXTdfsTXZ2oaNho3Vht7cUSc5J+s59fTSNe42ke1JS30I+QqE+3d2fk3GTvHFeXs2il6ImlxMTsQT1BFf1pqaiuGi4aWi5uQEAAAAAAAAAAHQsdJkswcG1oGCggGBAQOAhHyHdH+PjwkPIQ/LIeXk6LO0sd+22tprZvtmzvtTUDcpGygFGjY1HcNlwztlnZxfdS93kS3Jyr3neeTPelJTtZ9RnK9SYmP8j6CN76LCwk95K3hFKhYVbvWu9bWu7uwZ+Kn6RKsXFuzTlNJ7lT097OhY6wRbt7ddUxVQXxYaG0mLXYi/Xmpr4/1X/zFVmZpmnlKcilBERtkrPSg/PiorAMBAwyRDp6dkKBgoIBgQEDpiBmOeB/v5mC/ALW/CgoKvMRMzwRHh4tNW61Uq6JSXwPuM+luNLS3UO8w5f86KirBn+Gbr+XV1EW8BbG8CAgNuFioUKigUFgOyt7H6tPz/T37zfQrwhIf7YSNjgSHBwqAwEDPkE8fH9et96xt9jYxlYwVjuwXd3L591n0V1r68wpWOlhGNCQudQMFBAMCAgcC4aLtEa5eXLEg4S4Q79/e+3bbdlbb+/CNRM1BlMgYFVPBQ8MBQYGCRfNV9MNSYmeXEvcZ0vw8OyOOE4Z+G+vob9ov1qojU1yE/MTwvMiIjHSzlLXDkuLmX5V/k9V5OTag3yDaryVVVYnYKd44L8/GHJR8n0R3p6s++s74usyMgnMucyb+e6uoh9K31kKzIyT6SVpNeV5uZC+6D7m6DAwDuzmLMymBkZqmjRaCfRnp72gX+BXX+joyKqZqqIZkRE7oJ+gqh+VFTW5qvmdqs7O92eg54WgwsLlUXKRQPKjIzJeyl7lSnHx7xu027W02trBUQ8RFA8KChsi3mLVXmnpyw94j1j4ry8gScdJywdFhYxmnaaQXatrTdNO02tO9vblvpW+shWZGSe0k7S6E50dKYiHiIoHhQUNnbbdj/bkpLkHgoeGAoMDBK0bLSQbEhI/DfkN2vkuLiP513nJV2fn3iybrJhbr29DyrvKobvQ0Np8abxk6bExDXjqONyqDk52vek92KkMTHGWTdZvTfT04qGi4b/i/LydFYyVrEy1dWDxUPFDUOLi07rWevcWW5uhcK3wq+32toYj4yPAowBAY6sZKx5ZLGxHW3SbSPSnJzxO+A7kuBJSXLHtMertNjYHxX6FUP6rKy5CQcJ/Qfz8/pvJW+FJc/PoOqv6o+vysogiY6J84709H0g6SCO6UdHZygYKCAYEBA4ZNVk3tVvbwuDiIP7iPDwc7FvsZRvSkr7lnKWuHJcXMpsJGxwJDg4VAjxCK7xV1dfUsdS5sdzcyHzUfM1UZeXZGUjZY0jy8uuhHyEWXyhoSW/nL/LnOjoV2MhY3whPj5dfN18N92Wlup/3H/C3GFhHpGGkRqGDQ2clIWUHoUPD5urkKvbkODgS8ZCxvhCfHy6V8RX4sRxcSblquWDqszMKXPYczvYkJDjDwUPDAUGBgkDAQP1Aff39DYSNjgSHBwq/qP+n6PCwjzhX+HUX2pqixD5EEf5rq6+a9Br0tBpaQKokagukRcXv+hY6ClYmZlxaSdpdCc6OlPQudBOuScn90g4SKk42dmRNRM1zRPr697Os85Wsysr5VUzVUQzIiJ31rvWv7vS0gSQcJBJcKmpOYCJgA6JBweH8qfyZqczM8HBtsFati0t7GYiZngiPDxarZKtKpIVFbhgIGCJIMnJqdtJ2xVJh4dcGv8aT/+qqrCIeIigeFBQ2I56jlF6paUrio+KBo8DA4kT+BOy+FlZSpuAmxKACQmSORc5NBcaGiN12nXK2mVlEFMxU7Ux19eEUcZRE8aEhNXTuNO7uNDQA17DXh/DgoLcy7DLUrApKeKZd5m0d1pawzMRMzwRHh4tRstG9st7ez0f/B9L/Kiot2HWYdrWbW0MTjpOWDosLGI="));
4026var T7 = h.bytes2Int64Buffer(h.b64Decode("MvSl9JelxsZvl4SX64T4+F6wmbDHme7ueoyNjPeN9vboFw0X5Q3//wrcvdy3vdbWFsixyKex3t5t/FT8OVSRkZDwUPDAUGBgBwUDBQQDAgIu4Kngh6nOztGHfYesfVZWzCsZK9UZ5+cTpmKmcWK1tXwx5jGa5k1NWbWatcOa7OxAz0XPBUWPj6O8nbw+nR8fScBAwAlAiYlokoeS74f6+tA/FT/FFe/vlCbrJn/rsrLOQMlAB8mOjuYdCx3tC/v7bi/sL4LsQUEaqWepfWezs0Mc/Ry+/V9fYCXqJYrqRUX52r/aRr8jI1EC9wKm91NTRaGWodOW5OR27VvtLVubmyhdwl3qwnV1xSQcJNkc4eHU6a7peq49PfK+ar6YakxMgu5a7thabGy9w0HD/EF+fvMGAgbxAvX1UtFP0R1Pg4OM5Fzk0FxoaFYH9Aei9FFRjVw0XLk00dHhGAgY6Qj5+Uyuk67fk+LiPpVzlU1zq6uX9VP1xFNiYmtBP0FUPyoqHBQMFBAMCAhj9lL2MVKVlemvZa+MZUZGf+Je4iFenZ1IeCh4YCgwMM/4ofhuoTc3GxEPERQPCgrrxLXEXrUvLxUbCRscCQ4Oflo2Wkg2JCSttpu2NpsbG5hHPUelPd/fp2omaoEmzc31u2m7nGlOTjNMzUz+zX9/ULqfus+f6uo/LRstJBsSEqS5nrk6nh0dxJx0nLB0WFhGci5yaC40NEF3LXdsLTY2Ec2yzaOy3NydKe4pc+60tE0W+xa2+1tbpQH2AVP2pKSh103X7E12dhSjYaN1Ybe3NEnOSfrOfX3fjXuNpHtSUp9CPkKhPt3dzZNxk7xxXl6xopeiJpcTE6IE9QRX9aamAbhouGloubkAAAAAAAAAALV0LHSZLMHB4KBgoIBgQEDCIR8h3R/j4zpDyEPyyHl5miztLHfttrYN2b7Zs77U1EfKRsoBRo2NF3DZcM7ZZ2ev3Uvd5Etycu153nkz3pSU/2fUZyvUmJiTI+gje+iwsFveSt4RSoWFBr1rvW1ru7u7fip+kSrFxXs05TSe5U9P1zoWOsEW7e3SVMVUF8WGhvhi12Iv15qamf9V/8xVZma2p5SnIpQREcBKz0oPz4qK2TAQMMkQ6ekOCgYKCAYEBGaYgZjngf7+qwvwC1vwoKC0zETM8ER4ePDVutVKuiUldT7jPpbjS0usDvMOX/OiokQZ/hm6/l1d21vAWxvAgICAhYqFCooFBdPsrex+rT8//t+830K8ISGo2EjY4EhwcP0MBAz5BPHxGXrfesbfY2MvWMFY7sF3dzCfdZ9Fda+v56VjpYRjQkJwUDBQQDAgIMsuGi7RGuXl7xIOEuEO/f0It223ZW2/v1XUTNQZTIGBJDwUPDAUGBh5XzVfTDUmJrJxL3GdL8PDhjjhOGfhvr7I/aL9aqI1NcdPzE8LzIiIZUs5S1w5Li5q+Vf5PVeTk1gN8g2q8lVVYZ2CneOC/PyzyUfJ9Ed6eifvrO+LrMjIiDLnMm/nurpPfSt9ZCsyMkKklaTXlebmO/ug+5ugwMCqs5izMpgZGfZo0Wgn0Z6eIoF/gV1/o6PuqmaqiGZERNaCfoKoflRU3ear5narOzuVnoOeFoMLC8lFykUDyoyMvHspe5Upx8cFbtNu1tNra2xEPERQPCgoLIt5i1V5p6eBPeI9Y+K8vDEnHScsHRYWN5p2mkF2ra2WTTtNrTvb2576VvrIVmRkptJO0uhOdHQ2Ih4iKB4UFOR223Y/25KSEh4KHhgKDAz8tGy0kGxISI835Ddr5Li4eOdd5yVdn58Psm6yYW69vWkq7yqG70NDNfGm8ZOmxMTa46jjcqg5Ocb3pPdipDExilk3Wb0309N0houG/4vy8oNWMlaxMtXVTsVDxQ1Di4uF61nr3FlubhjCt8Kvt9rajo+MjwKMAQEdrGSseWSxsfFt0m0j0pyccjvgO5LgSUkfx7THq7TY2LkV+hVD+qys+gkHCf0H8/OgbyVvhSXPzyDqr+qPr8rKfYmOifOO9PRnIOkgjulHRzgoGCggGBAQC2TVZN7Vb29zg4iD+4jw8Puxb7GUb0pKypZylrhyXFxUbCRscCQ4OF8I8Qiu8VdXIVLHUubHc3Nk81HzNVGXl65lI2WNI8vLJYR8hFl8oaFXv5y/y5zo6F1jIWN8IT4+6nzdfDfdlpYef9x/wtxhYZyRhpEahg0Nm5SFlB6FDw9Lq5Cr25Dg4LrGQsb4Qnx8JlfEV+LEcXEp5arlg6rMzONz2HM72JCQCQ8FDwwFBgb0AwED9QH39yo2EjY4EhwcPP6j/p+jwsKL4V/h1F9qar4Q+RBH+a6uAmvQa9LQaWm/qJGoLpEXF3HoWOgpWJmZU2knaXQnOjr30LnQTrknJ5FIOEipONnZ3jUTNc0T6+vlzrPOVrMrK3dVM1VEMyIiBNa71r+70tI5kHCQSXCpqYeAiYAOiQcHwfKn8manMzPswbbBWrYtLVpmImZ4Ijw8uK2SrSqSFRWpYCBgiSDJyVzbSdsVSYeHsBr/Gk//qqrYiHiIoHhQUCuOeo5ReqWliYqPigaPAwNKE/gTsvhZWZKbgJsSgAkJIzkXOTQXGhoQddp1ytplZYRTMVO1MdfX1VHGURPGhIQD07jTu7jQ0Nxew14fw4KC4suwy1KwKSnDmXeZtHdaWi0zETM8ER4ePUbLRvbLe3u3H/wfS/yoqAxh1mHa1m1tYk46Tlg6LCw="));
4027
4028// var T0 = [
4029// o.u(0xc632f4a5, 0xf497a5c6), o.u(0xf86f9784, 0x97eb84f8),
4030// o.u(0xee5eb099, 0xb0c799ee), o.u(0xf67a8c8d, 0x8cf78df6),
4031// o.u(0xffe8170d, 0x17e50dff), o.u(0xd60adcbd, 0xdcb7bdd6),
4032// o.u(0xde16c8b1, 0xc8a7b1de), o.u(0x916dfc54, 0xfc395491),
4033// o.u(0x6090f050, 0xf0c05060), o.u(0x02070503, 0x05040302),
4034// o.u(0xce2ee0a9, 0xe087a9ce), o.u(0x56d1877d, 0x87ac7d56),
4035// o.u(0xe7cc2b19, 0x2bd519e7), o.u(0xb513a662, 0xa67162b5),
4036// o.u(0x4d7c31e6, 0x319ae64d), o.u(0xec59b59a, 0xb5c39aec),
4037// o.u(0x8f40cf45, 0xcf05458f), o.u(0x1fa3bc9d, 0xbc3e9d1f),
4038// o.u(0x8949c040, 0xc0094089), o.u(0xfa689287, 0x92ef87fa),
4039// o.u(0xefd03f15, 0x3fc515ef), o.u(0xb29426eb, 0x267febb2),
4040// o.u(0x8ece40c9, 0x4007c98e), o.u(0xfbe61d0b, 0x1ded0bfb),
4041// o.u(0x416e2fec, 0x2f82ec41), o.u(0xb31aa967, 0xa97d67b3),
4042// o.u(0x5f431cfd, 0x1cbefd5f), o.u(0x456025ea, 0x258aea45),
4043// o.u(0x23f9dabf, 0xda46bf23), o.u(0x535102f7, 0x02a6f753),
4044// o.u(0xe445a196, 0xa1d396e4), o.u(0x9b76ed5b, 0xed2d5b9b),
4045// o.u(0x75285dc2, 0x5deac275), o.u(0xe1c5241c, 0x24d91ce1),
4046// o.u(0x3dd4e9ae, 0xe97aae3d), o.u(0x4cf2be6a, 0xbe986a4c),
4047// o.u(0x6c82ee5a, 0xeed85a6c), o.u(0x7ebdc341, 0xc3fc417e),
4048// o.u(0xf5f30602, 0x06f102f5), o.u(0x8352d14f, 0xd11d4f83),
4049// o.u(0x688ce45c, 0xe4d05c68), o.u(0x515607f4, 0x07a2f451),
4050// o.u(0xd18d5c34, 0x5cb934d1), o.u(0xf9e11808, 0x18e908f9),
4051// o.u(0xe24cae93, 0xaedf93e2), o.u(0xab3e9573, 0x954d73ab),
4052// o.u(0x6297f553, 0xf5c45362), o.u(0x2a6b413f, 0x41543f2a),
4053// o.u(0x081c140c, 0x14100c08), o.u(0x9563f652, 0xf6315295),
4054// o.u(0x46e9af65, 0xaf8c6546), o.u(0x9d7fe25e, 0xe2215e9d),
4055// o.u(0x30487828, 0x78602830), o.u(0x37cff8a1, 0xf86ea137),
4056// o.u(0x0a1b110f, 0x11140f0a), o.u(0x2febc4b5, 0xc45eb52f),
4057// o.u(0x0e151b09, 0x1b1c090e), o.u(0x247e5a36, 0x5a483624),
4058// o.u(0x1badb69b, 0xb6369b1b), o.u(0xdf98473d, 0x47a53ddf),
4059// o.u(0xcda76a26, 0x6a8126cd), o.u(0x4ef5bb69, 0xbb9c694e),
4060// o.u(0x7f334ccd, 0x4cfecd7f), o.u(0xea50ba9f, 0xbacf9fea),
4061// o.u(0x123f2d1b, 0x2d241b12), o.u(0x1da4b99e, 0xb93a9e1d),
4062// o.u(0x58c49c74, 0x9cb07458), o.u(0x3446722e, 0x72682e34),
4063// o.u(0x3641772d, 0x776c2d36), o.u(0xdc11cdb2, 0xcda3b2dc),
4064// o.u(0xb49d29ee, 0x2973eeb4), o.u(0x5b4d16fb, 0x16b6fb5b),
4065// o.u(0xa4a501f6, 0x0153f6a4), o.u(0x76a1d74d, 0xd7ec4d76),
4066// o.u(0xb714a361, 0xa37561b7), o.u(0x7d3449ce, 0x49face7d),
4067// o.u(0x52df8d7b, 0x8da47b52), o.u(0xdd9f423e, 0x42a13edd),
4068// o.u(0x5ecd9371, 0x93bc715e), o.u(0x13b1a297, 0xa2269713),
4069// o.u(0xa6a204f5, 0x0457f5a6), o.u(0xb901b868, 0xb86968b9),
4070// o.u(0x00000000, 0x00000000), o.u(0xc1b5742c, 0x74992cc1),
4071// o.u(0x40e0a060, 0xa0806040), o.u(0xe3c2211f, 0x21dd1fe3),
4072// o.u(0x793a43c8, 0x43f2c879), o.u(0xb69a2ced, 0x2c77edb6),
4073// o.u(0xd40dd9be, 0xd9b3bed4), o.u(0x8d47ca46, 0xca01468d),
4074// o.u(0x671770d9, 0x70ced967), o.u(0x72afdd4b, 0xdde44b72),
4075// o.u(0x94ed79de, 0x7933de94), o.u(0x98ff67d4, 0x672bd498),
4076// o.u(0xb09323e8, 0x237be8b0), o.u(0x855bde4a, 0xde114a85),
4077// o.u(0xbb06bd6b, 0xbd6d6bbb), o.u(0xc5bb7e2a, 0x7e912ac5),
4078// o.u(0x4f7b34e5, 0x349ee54f), o.u(0xedd73a16, 0x3ac116ed),
4079// o.u(0x86d254c5, 0x5417c586), o.u(0x9af862d7, 0x622fd79a),
4080// o.u(0x6699ff55, 0xffcc5566), o.u(0x11b6a794, 0xa7229411),
4081// o.u(0x8ac04acf, 0x4a0fcf8a), o.u(0xe9d93010, 0x30c910e9),
4082// o.u(0x040e0a06, 0x0a080604), o.u(0xfe669881, 0x98e781fe),
4083// o.u(0xa0ab0bf0, 0x0b5bf0a0), o.u(0x78b4cc44, 0xccf04478),
4084// o.u(0x25f0d5ba, 0xd54aba25), o.u(0x4b753ee3, 0x3e96e34b),
4085// o.u(0xa2ac0ef3, 0x0e5ff3a2), o.u(0x5d4419fe, 0x19bafe5d),
4086// o.u(0x80db5bc0, 0x5b1bc080), o.u(0x0580858a, 0x850a8a05),
4087// o.u(0x3fd3ecad, 0xec7ead3f), o.u(0x21fedfbc, 0xdf42bc21),
4088// o.u(0x70a8d848, 0xd8e04870), o.u(0xf1fd0c04, 0x0cf904f1),
4089// o.u(0x63197adf, 0x7ac6df63), o.u(0x772f58c1, 0x58eec177),
4090// o.u(0xaf309f75, 0x9f4575af), o.u(0x42e7a563, 0xa5846342),
4091// o.u(0x20705030, 0x50403020), o.u(0xe5cb2e1a, 0x2ed11ae5),
4092// o.u(0xfdef120e, 0x12e10efd), o.u(0xbf08b76d, 0xb7656dbf),
4093// o.u(0x8155d44c, 0xd4194c81), o.u(0x18243c14, 0x3c301418),
4094// o.u(0x26795f35, 0x5f4c3526), o.u(0xc3b2712f, 0x719d2fc3),
4095// o.u(0xbe8638e1, 0x3867e1be), o.u(0x35c8fda2, 0xfd6aa235),
4096// o.u(0x88c74fcc, 0x4f0bcc88), o.u(0x2e654b39, 0x4b5c392e),
4097// o.u(0x936af957, 0xf93d5793), o.u(0x55580df2, 0x0daaf255),
4098// o.u(0xfc619d82, 0x9de382fc), o.u(0x7ab3c947, 0xc9f4477a),
4099// o.u(0xc827efac, 0xef8bacc8), o.u(0xba8832e7, 0x326fe7ba),
4100// o.u(0x324f7d2b, 0x7d642b32), o.u(0xe642a495, 0xa4d795e6),
4101// o.u(0xc03bfba0, 0xfb9ba0c0), o.u(0x19aab398, 0xb3329819),
4102// o.u(0x9ef668d1, 0x6827d19e), o.u(0xa322817f, 0x815d7fa3),
4103// o.u(0x44eeaa66, 0xaa886644), o.u(0x54d6827e, 0x82a87e54),
4104// o.u(0x3bdde6ab, 0xe676ab3b), o.u(0x0b959e83, 0x9e16830b),
4105// o.u(0x8cc945ca, 0x4503ca8c), o.u(0xc7bc7b29, 0x7b9529c7),
4106// o.u(0x6b056ed3, 0x6ed6d36b), o.u(0x286c443c, 0x44503c28),
4107// o.u(0xa72c8b79, 0x8b5579a7), o.u(0xbc813de2, 0x3d63e2bc),
4108// o.u(0x1631271d, 0x272c1d16), o.u(0xad379a76, 0x9a4176ad),
4109// o.u(0xdb964d3b, 0x4dad3bdb), o.u(0x649efa56, 0xfac85664),
4110// o.u(0x74a6d24e, 0xd2e84e74), o.u(0x1436221e, 0x22281e14),
4111// o.u(0x92e476db, 0x763fdb92), o.u(0x0c121e0a, 0x1e180a0c),
4112// o.u(0x48fcb46c, 0xb4906c48), o.u(0xb88f37e4, 0x376be4b8),
4113// o.u(0x9f78e75d, 0xe7255d9f), o.u(0xbd0fb26e, 0xb2616ebd),
4114// o.u(0x43692aef, 0x2a86ef43), o.u(0xc435f1a6, 0xf193a6c4),
4115// o.u(0x39dae3a8, 0xe372a839), o.u(0x31c6f7a4, 0xf762a431),
4116// o.u(0xd38a5937, 0x59bd37d3), o.u(0xf274868b, 0x86ff8bf2),
4117// o.u(0xd5835632, 0x56b132d5), o.u(0x8b4ec543, 0xc50d438b),
4118// o.u(0x6e85eb59, 0xebdc596e), o.u(0xda18c2b7, 0xc2afb7da),
4119// o.u(0x018e8f8c, 0x8f028c01), o.u(0xb11dac64, 0xac7964b1),
4120// o.u(0x9cf16dd2, 0x6d23d29c), o.u(0x49723be0, 0x3b92e049),
4121// o.u(0xd81fc7b4, 0xc7abb4d8), o.u(0xacb915fa, 0x1543faac),
4122// o.u(0xf3fa0907, 0x09fd07f3), o.u(0xcfa06f25, 0x6f8525cf),
4123// o.u(0xca20eaaf, 0xea8fafca), o.u(0xf47d898e, 0x89f38ef4),
4124// o.u(0x476720e9, 0x208ee947), o.u(0x10382818, 0x28201810),
4125// o.u(0x6f0b64d5, 0x64ded56f), o.u(0xf0738388, 0x83fb88f0),
4126// o.u(0x4afbb16f, 0xb1946f4a), o.u(0x5cca9672, 0x96b8725c),
4127// o.u(0x38546c24, 0x6c702438), o.u(0x575f08f1, 0x08aef157),
4128// o.u(0x732152c7, 0x52e6c773), o.u(0x9764f351, 0xf3355197),
4129// o.u(0xcbae6523, 0x658d23cb), o.u(0xa125847c, 0x84597ca1),
4130// o.u(0xe857bf9c, 0xbfcb9ce8), o.u(0x3e5d6321, 0x637c213e),
4131// o.u(0x96ea7cdd, 0x7c37dd96), o.u(0x611e7fdc, 0x7fc2dc61),
4132// o.u(0x0d9c9186, 0x911a860d), o.u(0x0f9b9485, 0x941e850f),
4133// o.u(0xe04bab90, 0xabdb90e0), o.u(0x7cbac642, 0xc6f8427c),
4134// o.u(0x712657c4, 0x57e2c471), o.u(0xcc29e5aa, 0xe583aacc),
4135// o.u(0x90e373d8, 0x733bd890), o.u(0x06090f05, 0x0f0c0506),
4136// o.u(0xf7f40301, 0x03f501f7), o.u(0x1c2a3612, 0x3638121c),
4137// o.u(0xc23cfea3, 0xfe9fa3c2), o.u(0x6a8be15f, 0xe1d45f6a),
4138// o.u(0xaebe10f9, 0x1047f9ae), o.u(0x69026bd0, 0x6bd2d069),
4139// o.u(0x17bfa891, 0xa82e9117), o.u(0x9971e858, 0xe8295899),
4140// o.u(0x3a536927, 0x6974273a), o.u(0x27f7d0b9, 0xd04eb927),
4141// o.u(0xd9914838, 0x48a938d9), o.u(0xebde3513, 0x35cd13eb),
4142// o.u(0x2be5ceb3, 0xce56b32b), o.u(0x22775533, 0x55443322),
4143// o.u(0xd204d6bb, 0xd6bfbbd2), o.u(0xa9399070, 0x904970a9),
4144// o.u(0x07878089, 0x800e8907), o.u(0x33c1f2a7, 0xf266a733),
4145// o.u(0x2decc1b6, 0xc15ab62d), o.u(0x3c5a6622, 0x6678223c),
4146// o.u(0x15b8ad92, 0xad2a9215), o.u(0xc9a96020, 0x608920c9),
4147// o.u(0x875cdb49, 0xdb154987), o.u(0xaab01aff, 0x1a4fffaa),
4148// o.u(0x50d88878, 0x88a07850), o.u(0xa52b8e7a, 0x8e517aa5),
4149// o.u(0x03898a8f, 0x8a068f03), o.u(0x594a13f8, 0x13b2f859),
4150// o.u(0x09929b80, 0x9b128009), o.u(0x1a233917, 0x3934171a),
4151// o.u(0x651075da, 0x75cada65), o.u(0xd7845331, 0x53b531d7),
4152// o.u(0x84d551c6, 0x5113c684), o.u(0xd003d3b8, 0xd3bbb8d0),
4153// o.u(0x82dc5ec3, 0x5e1fc382), o.u(0x29e2cbb0, 0xcb52b029),
4154// o.u(0x5ac39977, 0x99b4775a), o.u(0x1e2d3311, 0x333c111e),
4155// o.u(0x7b3d46cb, 0x46f6cb7b), o.u(0xa8b71ffc, 0x1f4bfca8),
4156// o.u(0x6d0c61d6, 0x61dad66d), o.u(0x2c624e3a, 0x4e583a2c)
4157// ];
4158
4159// var T1 = [
4160// o.u(0xc6c632f4, 0xa5f497a5), o.u(0xf8f86f97, 0x8497eb84),
4161// o.u(0xeeee5eb0, 0x99b0c799), o.u(0xf6f67a8c, 0x8d8cf78d),
4162// o.u(0xffffe817, 0xd17e50d), o.u(0xd6d60adc, 0xbddcb7bd),
4163// o.u(0xdede16c8, 0xb1c8a7b1), o.u(0x91916dfc, 0x54fc3954),
4164// o.u(0x606090f0, 0x50f0c050), o.u(0x2020705, 0x3050403),
4165// o.u(0xcece2ee0, 0xa9e087a9), o.u(0x5656d187, 0x7d87ac7d),
4166// o.u(0xe7e7cc2b, 0x192bd519), o.u(0xb5b513a6, 0x62a67162),
4167// o.u(0x4d4d7c31, 0xe6319ae6), o.u(0xecec59b5, 0x9ab5c39a),
4168// o.u(0x8f8f40cf, 0x45cf0545), o.u(0x1f1fa3bc, 0x9dbc3e9d),
4169// o.u(0x898949c0, 0x40c00940), o.u(0xfafa6892, 0x8792ef87),
4170// o.u(0xefefd03f, 0x153fc515), o.u(0xb2b29426, 0xeb267feb),
4171// o.u(0x8e8ece40, 0xc94007c9), o.u(0xfbfbe61d, 0xb1ded0b),
4172// o.u(0x41416e2f, 0xec2f82ec), o.u(0xb3b31aa9, 0x67a97d67),
4173// o.u(0x5f5f431c, 0xfd1cbefd), o.u(0x45456025, 0xea258aea),
4174// o.u(0x2323f9da, 0xbfda46bf), o.u(0x53535102, 0xf702a6f7),
4175// o.u(0xe4e445a1, 0x96a1d396), o.u(0x9b9b76ed, 0x5bed2d5b),
4176// o.u(0x7575285d, 0xc25deac2), o.u(0xe1e1c524, 0x1c24d91c),
4177// o.u(0x3d3dd4e9, 0xaee97aae), o.u(0x4c4cf2be, 0x6abe986a),
4178// o.u(0x6c6c82ee, 0x5aeed85a), o.u(0x7e7ebdc3, 0x41c3fc41),
4179// o.u(0xf5f5f306, 0x206f102), o.u(0x838352d1, 0x4fd11d4f),
4180// o.u(0x68688ce4, 0x5ce4d05c), o.u(0x51515607, 0xf407a2f4),
4181// o.u(0xd1d18d5c, 0x345cb934), o.u(0xf9f9e118, 0x818e908),
4182// o.u(0xe2e24cae, 0x93aedf93), o.u(0xabab3e95, 0x73954d73),
4183// o.u(0x626297f5, 0x53f5c453), o.u(0x2a2a6b41, 0x3f41543f),
4184// o.u(0x8081c14, 0xc14100c), o.u(0x959563f6, 0x52f63152),
4185// o.u(0x4646e9af, 0x65af8c65), o.u(0x9d9d7fe2, 0x5ee2215e),
4186// o.u(0x30304878, 0x28786028), o.u(0x3737cff8, 0xa1f86ea1),
4187// o.u(0xa0a1b11, 0xf11140f), o.u(0x2f2febc4, 0xb5c45eb5),
4188// o.u(0xe0e151b, 0x91b1c09), o.u(0x24247e5a, 0x365a4836),
4189// o.u(0x1b1badb6, 0x9bb6369b), o.u(0xdfdf9847, 0x3d47a53d),
4190// o.u(0xcdcda76a, 0x266a8126), o.u(0x4e4ef5bb, 0x69bb9c69),
4191// o.u(0x7f7f334c, 0xcd4cfecd), o.u(0xeaea50ba, 0x9fbacf9f),
4192// o.u(0x12123f2d, 0x1b2d241b), o.u(0x1d1da4b9, 0x9eb93a9e),
4193// o.u(0x5858c49c, 0x749cb074), o.u(0x34344672, 0x2e72682e),
4194// o.u(0x36364177, 0x2d776c2d), o.u(0xdcdc11cd, 0xb2cda3b2),
4195// o.u(0xb4b49d29, 0xee2973ee), o.u(0x5b5b4d16, 0xfb16b6fb),
4196// o.u(0xa4a4a501, 0xf60153f6), o.u(0x7676a1d7, 0x4dd7ec4d),
4197// o.u(0xb7b714a3, 0x61a37561), o.u(0x7d7d3449, 0xce49face),
4198// o.u(0x5252df8d, 0x7b8da47b), o.u(0xdddd9f42, 0x3e42a13e),
4199// o.u(0x5e5ecd93, 0x7193bc71), o.u(0x1313b1a2, 0x97a22697),
4200// o.u(0xa6a6a204, 0xf50457f5), o.u(0xb9b901b8, 0x68b86968),
4201// o.u(0x0, 0x0), o.u(0xc1c1b574, 0x2c74992c),
4202// o.u(0x4040e0a0, 0x60a08060), o.u(0xe3e3c221, 0x1f21dd1f),
4203// o.u(0x79793a43, 0xc843f2c8), o.u(0xb6b69a2c, 0xed2c77ed),
4204// o.u(0xd4d40dd9, 0xbed9b3be), o.u(0x8d8d47ca, 0x46ca0146),
4205// o.u(0x67671770, 0xd970ced9), o.u(0x7272afdd, 0x4bdde44b),
4206// o.u(0x9494ed79, 0xde7933de), o.u(0x9898ff67, 0xd4672bd4),
4207// o.u(0xb0b09323, 0xe8237be8), o.u(0x85855bde, 0x4ade114a),
4208// o.u(0xbbbb06bd, 0x6bbd6d6b), o.u(0xc5c5bb7e, 0x2a7e912a),
4209// o.u(0x4f4f7b34, 0xe5349ee5), o.u(0xededd73a, 0x163ac116),
4210// o.u(0x8686d254, 0xc55417c5), o.u(0x9a9af862, 0xd7622fd7),
4211// o.u(0x666699ff, 0x55ffcc55), o.u(0x1111b6a7, 0x94a72294),
4212// o.u(0x8a8ac04a, 0xcf4a0fcf), o.u(0xe9e9d930, 0x1030c910),
4213// o.u(0x4040e0a, 0x60a0806), o.u(0xfefe6698, 0x8198e781),
4214// o.u(0xa0a0ab0b, 0xf00b5bf0), o.u(0x7878b4cc, 0x44ccf044),
4215// o.u(0x2525f0d5, 0xbad54aba), o.u(0x4b4b753e, 0xe33e96e3),
4216// o.u(0xa2a2ac0e, 0xf30e5ff3), o.u(0x5d5d4419, 0xfe19bafe),
4217// o.u(0x8080db5b, 0xc05b1bc0), o.u(0x5058085, 0x8a850a8a),
4218// o.u(0x3f3fd3ec, 0xadec7ead), o.u(0x2121fedf, 0xbcdf42bc),
4219// o.u(0x7070a8d8, 0x48d8e048), o.u(0xf1f1fd0c, 0x40cf904),
4220// o.u(0x6363197a, 0xdf7ac6df), o.u(0x77772f58, 0xc158eec1),
4221// o.u(0xafaf309f, 0x759f4575), o.u(0x4242e7a5, 0x63a58463),
4222// o.u(0x20207050, 0x30504030), o.u(0xe5e5cb2e, 0x1a2ed11a),
4223// o.u(0xfdfdef12, 0xe12e10e), o.u(0xbfbf08b7, 0x6db7656d),
4224// o.u(0x818155d4, 0x4cd4194c), o.u(0x1818243c, 0x143c3014),
4225// o.u(0x2626795f, 0x355f4c35), o.u(0xc3c3b271, 0x2f719d2f),
4226// o.u(0xbebe8638, 0xe13867e1), o.u(0x3535c8fd, 0xa2fd6aa2),
4227// o.u(0x8888c74f, 0xcc4f0bcc), o.u(0x2e2e654b, 0x394b5c39),
4228// o.u(0x93936af9, 0x57f93d57), o.u(0x5555580d, 0xf20daaf2),
4229// o.u(0xfcfc619d, 0x829de382), o.u(0x7a7ab3c9, 0x47c9f447),
4230// o.u(0xc8c827ef, 0xacef8bac), o.u(0xbaba8832, 0xe7326fe7),
4231// o.u(0x32324f7d, 0x2b7d642b), o.u(0xe6e642a4, 0x95a4d795),
4232// o.u(0xc0c03bfb, 0xa0fb9ba0), o.u(0x1919aab3, 0x98b33298),
4233// o.u(0x9e9ef668, 0xd16827d1), o.u(0xa3a32281, 0x7f815d7f),
4234// o.u(0x4444eeaa, 0x66aa8866), o.u(0x5454d682, 0x7e82a87e),
4235// o.u(0x3b3bdde6, 0xabe676ab), o.u(0xb0b959e, 0x839e1683),
4236// o.u(0x8c8cc945, 0xca4503ca), o.u(0xc7c7bc7b, 0x297b9529),
4237// o.u(0x6b6b056e, 0xd36ed6d3), o.u(0x28286c44, 0x3c44503c),
4238// o.u(0xa7a72c8b, 0x798b5579), o.u(0xbcbc813d, 0xe23d63e2),
4239// o.u(0x16163127, 0x1d272c1d), o.u(0xadad379a, 0x769a4176),
4240// o.u(0xdbdb964d, 0x3b4dad3b), o.u(0x64649efa, 0x56fac856),
4241// o.u(0x7474a6d2, 0x4ed2e84e), o.u(0x14143622, 0x1e22281e),
4242// o.u(0x9292e476, 0xdb763fdb), o.u(0xc0c121e, 0xa1e180a),
4243// o.u(0x4848fcb4, 0x6cb4906c), o.u(0xb8b88f37, 0xe4376be4),
4244// o.u(0x9f9f78e7, 0x5de7255d), o.u(0xbdbd0fb2, 0x6eb2616e),
4245// o.u(0x4343692a, 0xef2a86ef), o.u(0xc4c435f1, 0xa6f193a6),
4246// o.u(0x3939dae3, 0xa8e372a8), o.u(0x3131c6f7, 0xa4f762a4),
4247// o.u(0xd3d38a59, 0x3759bd37), o.u(0xf2f27486, 0x8b86ff8b),
4248// o.u(0xd5d58356, 0x3256b132), o.u(0x8b8b4ec5, 0x43c50d43),
4249// o.u(0x6e6e85eb, 0x59ebdc59), o.u(0xdada18c2, 0xb7c2afb7),
4250// o.u(0x1018e8f, 0x8c8f028c), o.u(0xb1b11dac, 0x64ac7964),
4251// o.u(0x9c9cf16d, 0xd26d23d2), o.u(0x4949723b, 0xe03b92e0),
4252// o.u(0xd8d81fc7, 0xb4c7abb4), o.u(0xacacb915, 0xfa1543fa),
4253// o.u(0xf3f3fa09, 0x709fd07), o.u(0xcfcfa06f, 0x256f8525),
4254// o.u(0xcaca20ea, 0xafea8faf), o.u(0xf4f47d89, 0x8e89f38e),
4255// o.u(0x47476720, 0xe9208ee9), o.u(0x10103828, 0x18282018),
4256// o.u(0x6f6f0b64, 0xd564ded5), o.u(0xf0f07383, 0x8883fb88),
4257// o.u(0x4a4afbb1, 0x6fb1946f), o.u(0x5c5cca96, 0x7296b872),
4258// o.u(0x3838546c, 0x246c7024), o.u(0x57575f08, 0xf108aef1),
4259// o.u(0x73732152, 0xc752e6c7), o.u(0x979764f3, 0x51f33551),
4260// o.u(0xcbcbae65, 0x23658d23), o.u(0xa1a12584, 0x7c84597c),
4261// o.u(0xe8e857bf, 0x9cbfcb9c), o.u(0x3e3e5d63, 0x21637c21),
4262// o.u(0x9696ea7c, 0xdd7c37dd), o.u(0x61611e7f, 0xdc7fc2dc),
4263// o.u(0xd0d9c91, 0x86911a86), o.u(0xf0f9b94, 0x85941e85),
4264// o.u(0xe0e04bab, 0x90abdb90), o.u(0x7c7cbac6, 0x42c6f842),
4265// o.u(0x71712657, 0xc457e2c4), o.u(0xcccc29e5, 0xaae583aa),
4266// o.u(0x9090e373, 0xd8733bd8), o.u(0x606090f, 0x50f0c05),
4267// o.u(0xf7f7f403, 0x103f501), o.u(0x1c1c2a36, 0x12363812),
4268// o.u(0xc2c23cfe, 0xa3fe9fa3), o.u(0x6a6a8be1, 0x5fe1d45f),
4269// o.u(0xaeaebe10, 0xf91047f9), o.u(0x6969026b, 0xd06bd2d0),
4270// o.u(0x1717bfa8, 0x91a82e91), o.u(0x999971e8, 0x58e82958),
4271// o.u(0x3a3a5369, 0x27697427), o.u(0x2727f7d0, 0xb9d04eb9),
4272// o.u(0xd9d99148, 0x3848a938), o.u(0xebebde35, 0x1335cd13),
4273// o.u(0x2b2be5ce, 0xb3ce56b3), o.u(0x22227755, 0x33554433),
4274// o.u(0xd2d204d6, 0xbbd6bfbb), o.u(0xa9a93990, 0x70904970),
4275// o.u(0x7078780, 0x89800e89), o.u(0x3333c1f2, 0xa7f266a7),
4276// o.u(0x2d2decc1, 0xb6c15ab6), o.u(0x3c3c5a66, 0x22667822),
4277// o.u(0x1515b8ad, 0x92ad2a92), o.u(0xc9c9a960, 0x20608920),
4278// o.u(0x87875cdb, 0x49db1549), o.u(0xaaaab01a, 0xff1a4fff),
4279// o.u(0x5050d888, 0x7888a078), o.u(0xa5a52b8e, 0x7a8e517a),
4280// o.u(0x303898a, 0x8f8a068f), o.u(0x59594a13, 0xf813b2f8),
4281// o.u(0x909929b, 0x809b1280), o.u(0x1a1a2339, 0x17393417),
4282// o.u(0x65651075, 0xda75cada), o.u(0xd7d78453, 0x3153b531),
4283// o.u(0x8484d551, 0xc65113c6), o.u(0xd0d003d3, 0xb8d3bbb8),
4284// o.u(0x8282dc5e, 0xc35e1fc3), o.u(0x2929e2cb, 0xb0cb52b0),
4285// o.u(0x5a5ac399, 0x7799b477), o.u(0x1e1e2d33, 0x11333c11),
4286// o.u(0x7b7b3d46, 0xcb46f6cb), o.u(0xa8a8b71f, 0xfc1f4bfc),
4287// o.u(0x6d6d0c61, 0xd661dad6), o.u(0x2c2c624e, 0x3a4e583a)
4288// ];
4289
4290// var T2 = [
4291// o.u(0xa5c6c632, 0xf4a5f497), o.u(0x84f8f86f, 0x978497eb),
4292// o.u(0x99eeee5e, 0xb099b0c7), o.u(0x8df6f67a, 0x8c8d8cf7),
4293// o.u(0xdffffe8, 0x170d17e5), o.u(0xbdd6d60a, 0xdcbddcb7),
4294// o.u(0xb1dede16, 0xc8b1c8a7), o.u(0x5491916d, 0xfc54fc39),
4295// o.u(0x50606090, 0xf050f0c0), o.u(0x3020207, 0x5030504),
4296// o.u(0xa9cece2e, 0xe0a9e087), o.u(0x7d5656d1, 0x877d87ac),
4297// o.u(0x19e7e7cc, 0x2b192bd5), o.u(0x62b5b513, 0xa662a671),
4298// o.u(0xe64d4d7c, 0x31e6319a), o.u(0x9aecec59, 0xb59ab5c3),
4299// o.u(0x458f8f40, 0xcf45cf05), o.u(0x9d1f1fa3, 0xbc9dbc3e),
4300// o.u(0x40898949, 0xc040c009), o.u(0x87fafa68, 0x928792ef),
4301// o.u(0x15efefd0, 0x3f153fc5), o.u(0xebb2b294, 0x26eb267f),
4302// o.u(0xc98e8ece, 0x40c94007), o.u(0xbfbfbe6, 0x1d0b1ded),
4303// o.u(0xec41416e, 0x2fec2f82), o.u(0x67b3b31a, 0xa967a97d),
4304// o.u(0xfd5f5f43, 0x1cfd1cbe), o.u(0xea454560, 0x25ea258a),
4305// o.u(0xbf2323f9, 0xdabfda46), o.u(0xf7535351, 0x2f702a6),
4306// o.u(0x96e4e445, 0xa196a1d3), o.u(0x5b9b9b76, 0xed5bed2d),
4307// o.u(0xc2757528, 0x5dc25dea), o.u(0x1ce1e1c5, 0x241c24d9),
4308// o.u(0xae3d3dd4, 0xe9aee97a), o.u(0x6a4c4cf2, 0xbe6abe98),
4309// o.u(0x5a6c6c82, 0xee5aeed8), o.u(0x417e7ebd, 0xc341c3fc),
4310// o.u(0x2f5f5f3, 0x60206f1), o.u(0x4f838352, 0xd14fd11d),
4311// o.u(0x5c68688c, 0xe45ce4d0), o.u(0xf4515156, 0x7f407a2),
4312// o.u(0x34d1d18d, 0x5c345cb9), o.u(0x8f9f9e1, 0x180818e9),
4313// o.u(0x93e2e24c, 0xae93aedf), o.u(0x73abab3e, 0x9573954d),
4314// o.u(0x53626297, 0xf553f5c4), o.u(0x3f2a2a6b, 0x413f4154),
4315// o.u(0xc08081c, 0x140c1410), o.u(0x52959563, 0xf652f631),
4316// o.u(0x654646e9, 0xaf65af8c), o.u(0x5e9d9d7f, 0xe25ee221),
4317// o.u(0x28303048, 0x78287860), o.u(0xa13737cf, 0xf8a1f86e),
4318// o.u(0xf0a0a1b, 0x110f1114), o.u(0xb52f2feb, 0xc4b5c45e),
4319// o.u(0x90e0e15, 0x1b091b1c), o.u(0x3624247e, 0x5a365a48),
4320// o.u(0x9b1b1bad, 0xb69bb636), o.u(0x3ddfdf98, 0x473d47a5),
4321// o.u(0x26cdcda7, 0x6a266a81), o.u(0x694e4ef5, 0xbb69bb9c),
4322// o.u(0xcd7f7f33, 0x4ccd4cfe), o.u(0x9feaea50, 0xba9fbacf),
4323// o.u(0x1b12123f, 0x2d1b2d24), o.u(0x9e1d1da4, 0xb99eb93a),
4324// o.u(0x745858c4, 0x9c749cb0), o.u(0x2e343446, 0x722e7268),
4325// o.u(0x2d363641, 0x772d776c), o.u(0xb2dcdc11, 0xcdb2cda3),
4326// o.u(0xeeb4b49d, 0x29ee2973), o.u(0xfb5b5b4d, 0x16fb16b6),
4327// o.u(0xf6a4a4a5, 0x1f60153), o.u(0x4d7676a1, 0xd74dd7ec),
4328// o.u(0x61b7b714, 0xa361a375), o.u(0xce7d7d34, 0x49ce49fa),
4329// o.u(0x7b5252df, 0x8d7b8da4), o.u(0x3edddd9f, 0x423e42a1),
4330// o.u(0x715e5ecd, 0x937193bc), o.u(0x971313b1, 0xa297a226),
4331// o.u(0xf5a6a6a2, 0x4f50457), o.u(0x68b9b901, 0xb868b869),
4332// o.u(0x0, 0x0), o.u(0x2cc1c1b5, 0x742c7499),
4333// o.u(0x604040e0, 0xa060a080), o.u(0x1fe3e3c2, 0x211f21dd),
4334// o.u(0xc879793a, 0x43c843f2), o.u(0xedb6b69a, 0x2ced2c77),
4335// o.u(0xbed4d40d, 0xd9bed9b3), o.u(0x468d8d47, 0xca46ca01),
4336// o.u(0xd9676717, 0x70d970ce), o.u(0x4b7272af, 0xdd4bdde4),
4337// o.u(0xde9494ed, 0x79de7933), o.u(0xd49898ff, 0x67d4672b),
4338// o.u(0xe8b0b093, 0x23e8237b), o.u(0x4a85855b, 0xde4ade11),
4339// o.u(0x6bbbbb06, 0xbd6bbd6d), o.u(0x2ac5c5bb, 0x7e2a7e91),
4340// o.u(0xe54f4f7b, 0x34e5349e), o.u(0x16ededd7, 0x3a163ac1),
4341// o.u(0xc58686d2, 0x54c55417), o.u(0xd79a9af8, 0x62d7622f),
4342// o.u(0x55666699, 0xff55ffcc), o.u(0x941111b6, 0xa794a722),
4343// o.u(0xcf8a8ac0, 0x4acf4a0f), o.u(0x10e9e9d9, 0x301030c9),
4344// o.u(0x604040e, 0xa060a08), o.u(0x81fefe66, 0x988198e7),
4345// o.u(0xf0a0a0ab, 0xbf00b5b), o.u(0x447878b4, 0xcc44ccf0),
4346// o.u(0xba2525f0, 0xd5bad54a), o.u(0xe34b4b75, 0x3ee33e96),
4347// o.u(0xf3a2a2ac, 0xef30e5f), o.u(0xfe5d5d44, 0x19fe19ba),
4348// o.u(0xc08080db, 0x5bc05b1b), o.u(0x8a050580, 0x858a850a),
4349// o.u(0xad3f3fd3, 0xecadec7e), o.u(0xbc2121fe, 0xdfbcdf42),
4350// o.u(0x487070a8, 0xd848d8e0), o.u(0x4f1f1fd, 0xc040cf9),
4351// o.u(0xdf636319, 0x7adf7ac6), o.u(0xc177772f, 0x58c158ee),
4352// o.u(0x75afaf30, 0x9f759f45), o.u(0x634242e7, 0xa563a584),
4353// o.u(0x30202070, 0x50305040), o.u(0x1ae5e5cb, 0x2e1a2ed1),
4354// o.u(0xefdfdef, 0x120e12e1), o.u(0x6dbfbf08, 0xb76db765),
4355// o.u(0x4c818155, 0xd44cd419), o.u(0x14181824, 0x3c143c30),
4356// o.u(0x35262679, 0x5f355f4c), o.u(0x2fc3c3b2, 0x712f719d),
4357// o.u(0xe1bebe86, 0x38e13867), o.u(0xa23535c8, 0xfda2fd6a),
4358// o.u(0xcc8888c7, 0x4fcc4f0b), o.u(0x392e2e65, 0x4b394b5c),
4359// o.u(0x5793936a, 0xf957f93d), o.u(0xf2555558, 0xdf20daa),
4360// o.u(0x82fcfc61, 0x9d829de3), o.u(0x477a7ab3, 0xc947c9f4),
4361// o.u(0xacc8c827, 0xefacef8b), o.u(0xe7baba88, 0x32e7326f),
4362// o.u(0x2b32324f, 0x7d2b7d64), o.u(0x95e6e642, 0xa495a4d7),
4363// o.u(0xa0c0c03b, 0xfba0fb9b), o.u(0x981919aa, 0xb398b332),
4364// o.u(0xd19e9ef6, 0x68d16827), o.u(0x7fa3a322, 0x817f815d),
4365// o.u(0x664444ee, 0xaa66aa88), o.u(0x7e5454d6, 0x827e82a8),
4366// o.u(0xab3b3bdd, 0xe6abe676), o.u(0x830b0b95, 0x9e839e16),
4367// o.u(0xca8c8cc9, 0x45ca4503), o.u(0x29c7c7bc, 0x7b297b95),
4368// o.u(0xd36b6b05, 0x6ed36ed6), o.u(0x3c28286c, 0x443c4450),
4369// o.u(0x79a7a72c, 0x8b798b55), o.u(0xe2bcbc81, 0x3de23d63),
4370// o.u(0x1d161631, 0x271d272c), o.u(0x76adad37, 0x9a769a41),
4371// o.u(0x3bdbdb96, 0x4d3b4dad), o.u(0x5664649e, 0xfa56fac8),
4372// o.u(0x4e7474a6, 0xd24ed2e8), o.u(0x1e141436, 0x221e2228),
4373// o.u(0xdb9292e4, 0x76db763f), o.u(0xa0c0c12, 0x1e0a1e18),
4374// o.u(0x6c4848fc, 0xb46cb490), o.u(0xe4b8b88f, 0x37e4376b),
4375// o.u(0x5d9f9f78, 0xe75de725), o.u(0x6ebdbd0f, 0xb26eb261),
4376// o.u(0xef434369, 0x2aef2a86), o.u(0xa6c4c435, 0xf1a6f193),
4377// o.u(0xa83939da, 0xe3a8e372), o.u(0xa43131c6, 0xf7a4f762),
4378// o.u(0x37d3d38a, 0x593759bd), o.u(0x8bf2f274, 0x868b86ff),
4379// o.u(0x32d5d583, 0x563256b1), o.u(0x438b8b4e, 0xc543c50d),
4380// o.u(0x596e6e85, 0xeb59ebdc), o.u(0xb7dada18, 0xc2b7c2af),
4381// o.u(0x8c01018e, 0x8f8c8f02), o.u(0x64b1b11d, 0xac64ac79),
4382// o.u(0xd29c9cf1, 0x6dd26d23), o.u(0xe0494972, 0x3be03b92),
4383// o.u(0xb4d8d81f, 0xc7b4c7ab), o.u(0xfaacacb9, 0x15fa1543),
4384// o.u(0x7f3f3fa, 0x90709fd), o.u(0x25cfcfa0, 0x6f256f85),
4385// o.u(0xafcaca20, 0xeaafea8f), o.u(0x8ef4f47d, 0x898e89f3),
4386// o.u(0xe9474767, 0x20e9208e), o.u(0x18101038, 0x28182820),
4387// o.u(0xd56f6f0b, 0x64d564de), o.u(0x88f0f073, 0x838883fb),
4388// o.u(0x6f4a4afb, 0xb16fb194), o.u(0x725c5cca, 0x967296b8),
4389// o.u(0x24383854, 0x6c246c70), o.u(0xf157575f, 0x8f108ae),
4390// o.u(0xc7737321, 0x52c752e6), o.u(0x51979764, 0xf351f335),
4391// o.u(0x23cbcbae, 0x6523658d), o.u(0x7ca1a125, 0x847c8459),
4392// o.u(0x9ce8e857, 0xbf9cbfcb), o.u(0x213e3e5d, 0x6321637c),
4393// o.u(0xdd9696ea, 0x7cdd7c37), o.u(0xdc61611e, 0x7fdc7fc2),
4394// o.u(0x860d0d9c, 0x9186911a), o.u(0x850f0f9b, 0x9485941e),
4395// o.u(0x90e0e04b, 0xab90abdb), o.u(0x427c7cba, 0xc642c6f8),
4396// o.u(0xc4717126, 0x57c457e2), o.u(0xaacccc29, 0xe5aae583),
4397// o.u(0xd89090e3, 0x73d8733b), o.u(0x5060609, 0xf050f0c),
4398// o.u(0x1f7f7f4, 0x30103f5), o.u(0x121c1c2a, 0x36123638),
4399// o.u(0xa3c2c23c, 0xfea3fe9f), o.u(0x5f6a6a8b, 0xe15fe1d4),
4400// o.u(0xf9aeaebe, 0x10f91047), o.u(0xd0696902, 0x6bd06bd2),
4401// o.u(0x911717bf, 0xa891a82e), o.u(0x58999971, 0xe858e829),
4402// o.u(0x273a3a53, 0x69276974), o.u(0xb92727f7, 0xd0b9d04e),
4403// o.u(0x38d9d991, 0x483848a9), o.u(0x13ebebde, 0x351335cd),
4404// o.u(0xb32b2be5, 0xceb3ce56), o.u(0x33222277, 0x55335544),
4405// o.u(0xbbd2d204, 0xd6bbd6bf), o.u(0x70a9a939, 0x90709049),
4406// o.u(0x89070787, 0x8089800e), o.u(0xa73333c1, 0xf2a7f266),
4407// o.u(0xb62d2dec, 0xc1b6c15a), o.u(0x223c3c5a, 0x66226678),
4408// o.u(0x921515b8, 0xad92ad2a), o.u(0x20c9c9a9, 0x60206089),
4409// o.u(0x4987875c, 0xdb49db15), o.u(0xffaaaab0, 0x1aff1a4f),
4410// o.u(0x785050d8, 0x887888a0), o.u(0x7aa5a52b, 0x8e7a8e51),
4411// o.u(0x8f030389, 0x8a8f8a06), o.u(0xf859594a, 0x13f813b2),
4412// o.u(0x80090992, 0x9b809b12), o.u(0x171a1a23, 0x39173934),
4413// o.u(0xda656510, 0x75da75ca), o.u(0x31d7d784, 0x533153b5),
4414// o.u(0xc68484d5, 0x51c65113), o.u(0xb8d0d003, 0xd3b8d3bb),
4415// o.u(0xc38282dc, 0x5ec35e1f), o.u(0xb02929e2, 0xcbb0cb52),
4416// o.u(0x775a5ac3, 0x997799b4), o.u(0x111e1e2d, 0x3311333c),
4417// o.u(0xcb7b7b3d, 0x46cb46f6), o.u(0xfca8a8b7, 0x1ffc1f4b),
4418// o.u(0xd66d6d0c, 0x61d661da), o.u(0x3a2c2c62, 0x4e3a4e58)
4419// ];
4420
4421// var T3 = [
4422// o.u(0x97a5c6c6, 0x32f4a5f4), o.u(0xeb84f8f8, 0x6f978497),
4423// o.u(0xc799eeee, 0x5eb099b0), o.u(0xf78df6f6, 0x7a8c8d8c),
4424// o.u(0xe50dffff, 0xe8170d17), o.u(0xb7bdd6d6, 0xadcbddc),
4425// o.u(0xa7b1dede, 0x16c8b1c8), o.u(0x39549191, 0x6dfc54fc),
4426// o.u(0xc0506060, 0x90f050f0), o.u(0x4030202, 0x7050305),
4427// o.u(0x87a9cece, 0x2ee0a9e0), o.u(0xac7d5656, 0xd1877d87),
4428// o.u(0xd519e7e7, 0xcc2b192b), o.u(0x7162b5b5, 0x13a662a6),
4429// o.u(0x9ae64d4d, 0x7c31e631), o.u(0xc39aecec, 0x59b59ab5),
4430// o.u(0x5458f8f, 0x40cf45cf), o.u(0x3e9d1f1f, 0xa3bc9dbc),
4431// o.u(0x9408989, 0x49c040c0), o.u(0xef87fafa, 0x68928792),
4432// o.u(0xc515efef, 0xd03f153f), o.u(0x7febb2b2, 0x9426eb26),
4433// o.u(0x7c98e8e, 0xce40c940), o.u(0xed0bfbfb, 0xe61d0b1d),
4434// o.u(0x82ec4141, 0x6e2fec2f), o.u(0x7d67b3b3, 0x1aa967a9),
4435// o.u(0xbefd5f5f, 0x431cfd1c), o.u(0x8aea4545, 0x6025ea25),
4436// o.u(0x46bf2323, 0xf9dabfda), o.u(0xa6f75353, 0x5102f702),
4437// o.u(0xd396e4e4, 0x45a196a1), o.u(0x2d5b9b9b, 0x76ed5bed),
4438// o.u(0xeac27575, 0x285dc25d), o.u(0xd91ce1e1, 0xc5241c24),
4439// o.u(0x7aae3d3d, 0xd4e9aee9), o.u(0x986a4c4c, 0xf2be6abe),
4440// o.u(0xd85a6c6c, 0x82ee5aee), o.u(0xfc417e7e, 0xbdc341c3),
4441// o.u(0xf102f5f5, 0xf3060206), o.u(0x1d4f8383, 0x52d14fd1),
4442// o.u(0xd05c6868, 0x8ce45ce4), o.u(0xa2f45151, 0x5607f407),
4443// o.u(0xb934d1d1, 0x8d5c345c), o.u(0xe908f9f9, 0xe1180818),
4444// o.u(0xdf93e2e2, 0x4cae93ae), o.u(0x4d73abab, 0x3e957395),
4445// o.u(0xc4536262, 0x97f553f5), o.u(0x543f2a2a, 0x6b413f41),
4446// o.u(0x100c0808, 0x1c140c14), o.u(0x31529595, 0x63f652f6),
4447// o.u(0x8c654646, 0xe9af65af), o.u(0x215e9d9d, 0x7fe25ee2),
4448// o.u(0x60283030, 0x48782878), o.u(0x6ea13737, 0xcff8a1f8),
4449// o.u(0x140f0a0a, 0x1b110f11), o.u(0x5eb52f2f, 0xebc4b5c4),
4450// o.u(0x1c090e0e, 0x151b091b), o.u(0x48362424, 0x7e5a365a),
4451// o.u(0x369b1b1b, 0xadb69bb6), o.u(0xa53ddfdf, 0x98473d47),
4452// o.u(0x8126cdcd, 0xa76a266a), o.u(0x9c694e4e, 0xf5bb69bb),
4453// o.u(0xfecd7f7f, 0x334ccd4c), o.u(0xcf9feaea, 0x50ba9fba),
4454// o.u(0x241b1212, 0x3f2d1b2d), o.u(0x3a9e1d1d, 0xa4b99eb9),
4455// o.u(0xb0745858, 0xc49c749c), o.u(0x682e3434, 0x46722e72),
4456// o.u(0x6c2d3636, 0x41772d77), o.u(0xa3b2dcdc, 0x11cdb2cd),
4457// o.u(0x73eeb4b4, 0x9d29ee29), o.u(0xb6fb5b5b, 0x4d16fb16),
4458// o.u(0x53f6a4a4, 0xa501f601), o.u(0xec4d7676, 0xa1d74dd7),
4459// o.u(0x7561b7b7, 0x14a361a3), o.u(0xface7d7d, 0x3449ce49),
4460// o.u(0xa47b5252, 0xdf8d7b8d), o.u(0xa13edddd, 0x9f423e42),
4461// o.u(0xbc715e5e, 0xcd937193), o.u(0x26971313, 0xb1a297a2),
4462// o.u(0x57f5a6a6, 0xa204f504), o.u(0x6968b9b9, 0x1b868b8),
4463// o.u(0x0, 0x0), o.u(0x992cc1c1, 0xb5742c74),
4464// o.u(0x80604040, 0xe0a060a0), o.u(0xdd1fe3e3, 0xc2211f21),
4465// o.u(0xf2c87979, 0x3a43c843), o.u(0x77edb6b6, 0x9a2ced2c),
4466// o.u(0xb3bed4d4, 0xdd9bed9), o.u(0x1468d8d, 0x47ca46ca),
4467// o.u(0xced96767, 0x1770d970), o.u(0xe44b7272, 0xafdd4bdd),
4468// o.u(0x33de9494, 0xed79de79), o.u(0x2bd49898, 0xff67d467),
4469// o.u(0x7be8b0b0, 0x9323e823), o.u(0x114a8585, 0x5bde4ade),
4470// o.u(0x6d6bbbbb, 0x6bd6bbd), o.u(0x912ac5c5, 0xbb7e2a7e),
4471// o.u(0x9ee54f4f, 0x7b34e534), o.u(0xc116eded, 0xd73a163a),
4472// o.u(0x17c58686, 0xd254c554), o.u(0x2fd79a9a, 0xf862d762),
4473// o.u(0xcc556666, 0x99ff55ff), o.u(0x22941111, 0xb6a794a7),
4474// o.u(0xfcf8a8a, 0xc04acf4a), o.u(0xc910e9e9, 0xd9301030),
4475// o.u(0x8060404, 0xe0a060a), o.u(0xe781fefe, 0x66988198),
4476// o.u(0x5bf0a0a0, 0xab0bf00b), o.u(0xf0447878, 0xb4cc44cc),
4477// o.u(0x4aba2525, 0xf0d5bad5), o.u(0x96e34b4b, 0x753ee33e),
4478// o.u(0x5ff3a2a2, 0xac0ef30e), o.u(0xbafe5d5d, 0x4419fe19),
4479// o.u(0x1bc08080, 0xdb5bc05b), o.u(0xa8a0505, 0x80858a85),
4480// o.u(0x7ead3f3f, 0xd3ecadec), o.u(0x42bc2121, 0xfedfbcdf),
4481// o.u(0xe0487070, 0xa8d848d8), o.u(0xf904f1f1, 0xfd0c040c),
4482// o.u(0xc6df6363, 0x197adf7a), o.u(0xeec17777, 0x2f58c158),
4483// o.u(0x4575afaf, 0x309f759f), o.u(0x84634242, 0xe7a563a5),
4484// o.u(0x40302020, 0x70503050), o.u(0xd11ae5e5, 0xcb2e1a2e),
4485// o.u(0xe10efdfd, 0xef120e12), o.u(0x656dbfbf, 0x8b76db7),
4486// o.u(0x194c8181, 0x55d44cd4), o.u(0x30141818, 0x243c143c),
4487// o.u(0x4c352626, 0x795f355f), o.u(0x9d2fc3c3, 0xb2712f71),
4488// o.u(0x67e1bebe, 0x8638e138), o.u(0x6aa23535, 0xc8fda2fd),
4489// o.u(0xbcc8888, 0xc74fcc4f), o.u(0x5c392e2e, 0x654b394b),
4490// o.u(0x3d579393, 0x6af957f9), o.u(0xaaf25555, 0x580df20d),
4491// o.u(0xe382fcfc, 0x619d829d), o.u(0xf4477a7a, 0xb3c947c9),
4492// o.u(0x8bacc8c8, 0x27efacef), o.u(0x6fe7baba, 0x8832e732),
4493// o.u(0x642b3232, 0x4f7d2b7d), o.u(0xd795e6e6, 0x42a495a4),
4494// o.u(0x9ba0c0c0, 0x3bfba0fb), o.u(0x32981919, 0xaab398b3),
4495// o.u(0x27d19e9e, 0xf668d168), o.u(0x5d7fa3a3, 0x22817f81),
4496// o.u(0x88664444, 0xeeaa66aa), o.u(0xa87e5454, 0xd6827e82),
4497// o.u(0x76ab3b3b, 0xdde6abe6), o.u(0x16830b0b, 0x959e839e),
4498// o.u(0x3ca8c8c, 0xc945ca45), o.u(0x9529c7c7, 0xbc7b297b),
4499// o.u(0xd6d36b6b, 0x56ed36e), o.u(0x503c2828, 0x6c443c44),
4500// o.u(0x5579a7a7, 0x2c8b798b), o.u(0x63e2bcbc, 0x813de23d),
4501// o.u(0x2c1d1616, 0x31271d27), o.u(0x4176adad, 0x379a769a),
4502// o.u(0xad3bdbdb, 0x964d3b4d), o.u(0xc8566464, 0x9efa56fa),
4503// o.u(0xe84e7474, 0xa6d24ed2), o.u(0x281e1414, 0x36221e22),
4504// o.u(0x3fdb9292, 0xe476db76), o.u(0x180a0c0c, 0x121e0a1e),
4505// o.u(0x906c4848, 0xfcb46cb4), o.u(0x6be4b8b8, 0x8f37e437),
4506// o.u(0x255d9f9f, 0x78e75de7), o.u(0x616ebdbd, 0xfb26eb2),
4507// o.u(0x86ef4343, 0x692aef2a), o.u(0x93a6c4c4, 0x35f1a6f1),
4508// o.u(0x72a83939, 0xdae3a8e3), o.u(0x62a43131, 0xc6f7a4f7),
4509// o.u(0xbd37d3d3, 0x8a593759), o.u(0xff8bf2f2, 0x74868b86),
4510// o.u(0xb132d5d5, 0x83563256), o.u(0xd438b8b, 0x4ec543c5),
4511// o.u(0xdc596e6e, 0x85eb59eb), o.u(0xafb7dada, 0x18c2b7c2),
4512// o.u(0x28c0101, 0x8e8f8c8f), o.u(0x7964b1b1, 0x1dac64ac),
4513// o.u(0x23d29c9c, 0xf16dd26d), o.u(0x92e04949, 0x723be03b),
4514// o.u(0xabb4d8d8, 0x1fc7b4c7), o.u(0x43faacac, 0xb915fa15),
4515// o.u(0xfd07f3f3, 0xfa090709), o.u(0x8525cfcf, 0xa06f256f),
4516// o.u(0x8fafcaca, 0x20eaafea), o.u(0xf38ef4f4, 0x7d898e89),
4517// o.u(0x8ee94747, 0x6720e920), o.u(0x20181010, 0x38281828),
4518// o.u(0xded56f6f, 0xb64d564), o.u(0xfb88f0f0, 0x73838883),
4519// o.u(0x946f4a4a, 0xfbb16fb1), o.u(0xb8725c5c, 0xca967296),
4520// o.u(0x70243838, 0x546c246c), o.u(0xaef15757, 0x5f08f108),
4521// o.u(0xe6c77373, 0x2152c752), o.u(0x35519797, 0x64f351f3),
4522// o.u(0x8d23cbcb, 0xae652365), o.u(0x597ca1a1, 0x25847c84),
4523// o.u(0xcb9ce8e8, 0x57bf9cbf), o.u(0x7c213e3e, 0x5d632163),
4524// o.u(0x37dd9696, 0xea7cdd7c), o.u(0xc2dc6161, 0x1e7fdc7f),
4525// o.u(0x1a860d0d, 0x9c918691), o.u(0x1e850f0f, 0x9b948594),
4526// o.u(0xdb90e0e0, 0x4bab90ab), o.u(0xf8427c7c, 0xbac642c6),
4527// o.u(0xe2c47171, 0x2657c457), o.u(0x83aacccc, 0x29e5aae5),
4528// o.u(0x3bd89090, 0xe373d873), o.u(0xc050606, 0x90f050f),
4529// o.u(0xf501f7f7, 0xf4030103), o.u(0x38121c1c, 0x2a361236),
4530// o.u(0x9fa3c2c2, 0x3cfea3fe), o.u(0xd45f6a6a, 0x8be15fe1),
4531// o.u(0x47f9aeae, 0xbe10f910), o.u(0xd2d06969, 0x26bd06b),
4532// o.u(0x2e911717, 0xbfa891a8), o.u(0x29589999, 0x71e858e8),
4533// o.u(0x74273a3a, 0x53692769), o.u(0x4eb92727, 0xf7d0b9d0),
4534// o.u(0xa938d9d9, 0x91483848), o.u(0xcd13ebeb, 0xde351335),
4535// o.u(0x56b32b2b, 0xe5ceb3ce), o.u(0x44332222, 0x77553355),
4536// o.u(0xbfbbd2d2, 0x4d6bbd6), o.u(0x4970a9a9, 0x39907090),
4537// o.u(0xe890707, 0x87808980), o.u(0x66a73333, 0xc1f2a7f2),
4538// o.u(0x5ab62d2d, 0xecc1b6c1), o.u(0x78223c3c, 0x5a662266),
4539// o.u(0x2a921515, 0xb8ad92ad), o.u(0x8920c9c9, 0xa9602060),
4540// o.u(0x15498787, 0x5cdb49db), o.u(0x4fffaaaa, 0xb01aff1a),
4541// o.u(0xa0785050, 0xd8887888), o.u(0x517aa5a5, 0x2b8e7a8e),
4542// o.u(0x68f0303, 0x898a8f8a), o.u(0xb2f85959, 0x4a13f813),
4543// o.u(0x12800909, 0x929b809b), o.u(0x34171a1a, 0x23391739),
4544// o.u(0xcada6565, 0x1075da75), o.u(0xb531d7d7, 0x84533153),
4545// o.u(0x13c68484, 0xd551c651), o.u(0xbbb8d0d0, 0x3d3b8d3),
4546// o.u(0x1fc38282, 0xdc5ec35e), o.u(0x52b02929, 0xe2cbb0cb),
4547// o.u(0xb4775a5a, 0xc3997799), o.u(0x3c111e1e, 0x2d331133),
4548// o.u(0xf6cb7b7b, 0x3d46cb46), o.u(0x4bfca8a8, 0xb71ffc1f),
4549// o.u(0xdad66d6d, 0xc61d661), o.u(0x583a2c2c, 0x624e3a4e)
4550// ]
4551
4552// var T4 = [
4553// o.u(0xf497a5c6, 0xc632f4a5), o.u(0x97eb84f8, 0xf86f9784),
4554// o.u(0xb0c799ee, 0xee5eb099), o.u(0x8cf78df6, 0xf67a8c8d),
4555// o.u(0x17e50dff, 0xffe8170d), o.u(0xdcb7bdd6, 0xd60adcbd),
4556// o.u(0xc8a7b1de, 0xde16c8b1), o.u(0xfc395491, 0x916dfc54),
4557// o.u(0xf0c05060, 0x6090f050), o.u(0x05040302, 0x02070503),
4558// o.u(0xe087a9ce, 0xce2ee0a9), o.u(0x87ac7d56, 0x56d1877d),
4559// o.u(0x2bd519e7, 0xe7cc2b19), o.u(0xa67162b5, 0xb513a662),
4560// o.u(0x319ae64d, 0x4d7c31e6), o.u(0xb5c39aec, 0xec59b59a),
4561// o.u(0xcf05458f, 0x8f40cf45), o.u(0xbc3e9d1f, 0x1fa3bc9d),
4562// o.u(0xc0094089, 0x8949c040), o.u(0x92ef87fa, 0xfa689287),
4563// o.u(0x3fc515ef, 0xefd03f15), o.u(0x267febb2, 0xb29426eb),
4564// o.u(0x4007c98e, 0x8ece40c9), o.u(0x1ded0bfb, 0xfbe61d0b),
4565// o.u(0x2f82ec41, 0x416e2fec), o.u(0xa97d67b3, 0xb31aa967),
4566// o.u(0x1cbefd5f, 0x5f431cfd), o.u(0x258aea45, 0x456025ea),
4567// o.u(0xda46bf23, 0x23f9dabf), o.u(0x02a6f753, 0x535102f7),
4568// o.u(0xa1d396e4, 0xe445a196), o.u(0xed2d5b9b, 0x9b76ed5b),
4569// o.u(0x5deac275, 0x75285dc2), o.u(0x24d91ce1, 0xe1c5241c),
4570// o.u(0xe97aae3d, 0x3dd4e9ae), o.u(0xbe986a4c, 0x4cf2be6a),
4571// o.u(0xeed85a6c, 0x6c82ee5a), o.u(0xc3fc417e, 0x7ebdc341),
4572// o.u(0x06f102f5, 0xf5f30602), o.u(0xd11d4f83, 0x8352d14f),
4573// o.u(0xe4d05c68, 0x688ce45c), o.u(0x07a2f451, 0x515607f4),
4574// o.u(0x5cb934d1, 0xd18d5c34), o.u(0x18e908f9, 0xf9e11808),
4575// o.u(0xaedf93e2, 0xe24cae93), o.u(0x954d73ab, 0xab3e9573),
4576// o.u(0xf5c45362, 0x6297f553), o.u(0x41543f2a, 0x2a6b413f),
4577// o.u(0x14100c08, 0x081c140c), o.u(0xf6315295, 0x9563f652),
4578// o.u(0xaf8c6546, 0x46e9af65), o.u(0xe2215e9d, 0x9d7fe25e),
4579// o.u(0x78602830, 0x30487828), o.u(0xf86ea137, 0x37cff8a1),
4580// o.u(0x11140f0a, 0x0a1b110f), o.u(0xc45eb52f, 0x2febc4b5),
4581// o.u(0x1b1c090e, 0x0e151b09), o.u(0x5a483624, 0x247e5a36),
4582// o.u(0xb6369b1b, 0x1badb69b), o.u(0x47a53ddf, 0xdf98473d),
4583// o.u(0x6a8126cd, 0xcda76a26), o.u(0xbb9c694e, 0x4ef5bb69),
4584// o.u(0x4cfecd7f, 0x7f334ccd), o.u(0xbacf9fea, 0xea50ba9f),
4585// o.u(0x2d241b12, 0x123f2d1b), o.u(0xb93a9e1d, 0x1da4b99e),
4586// o.u(0x9cb07458, 0x58c49c74), o.u(0x72682e34, 0x3446722e),
4587// o.u(0x776c2d36, 0x3641772d), o.u(0xcda3b2dc, 0xdc11cdb2),
4588// o.u(0x2973eeb4, 0xb49d29ee), o.u(0x16b6fb5b, 0x5b4d16fb),
4589// o.u(0x0153f6a4, 0xa4a501f6), o.u(0xd7ec4d76, 0x76a1d74d),
4590// o.u(0xa37561b7, 0xb714a361), o.u(0x49face7d, 0x7d3449ce),
4591// o.u(0x8da47b52, 0x52df8d7b), o.u(0x42a13edd, 0xdd9f423e),
4592// o.u(0x93bc715e, 0x5ecd9371), o.u(0xa2269713, 0x13b1a297),
4593// o.u(0x0457f5a6, 0xa6a204f5), o.u(0xb86968b9, 0xb901b868),
4594// o.u(0x00000000, 0x00000000), o.u(0x74992cc1, 0xc1b5742c),
4595// o.u(0xa0806040, 0x40e0a060), o.u(0x21dd1fe3, 0xe3c2211f),
4596// o.u(0x43f2c879, 0x793a43c8), o.u(0x2c77edb6, 0xb69a2ced),
4597// o.u(0xd9b3bed4, 0xd40dd9be), o.u(0xca01468d, 0x8d47ca46),
4598// o.u(0x70ced967, 0x671770d9), o.u(0xdde44b72, 0x72afdd4b),
4599// o.u(0x7933de94, 0x94ed79de), o.u(0x672bd498, 0x98ff67d4),
4600// o.u(0x237be8b0, 0xb09323e8), o.u(0xde114a85, 0x855bde4a),
4601// o.u(0xbd6d6bbb, 0xbb06bd6b), o.u(0x7e912ac5, 0xc5bb7e2a),
4602// o.u(0x349ee54f, 0x4f7b34e5), o.u(0x3ac116ed, 0xedd73a16),
4603// o.u(0x5417c586, 0x86d254c5), o.u(0x622fd79a, 0x9af862d7),
4604// o.u(0xffcc5566, 0x6699ff55), o.u(0xa7229411, 0x11b6a794),
4605// o.u(0x4a0fcf8a, 0x8ac04acf), o.u(0x30c910e9, 0xe9d93010),
4606// o.u(0x0a080604, 0x040e0a06), o.u(0x98e781fe, 0xfe669881),
4607// o.u(0x0b5bf0a0, 0xa0ab0bf0), o.u(0xccf04478, 0x78b4cc44),
4608// o.u(0xd54aba25, 0x25f0d5ba), o.u(0x3e96e34b, 0x4b753ee3),
4609// o.u(0x0e5ff3a2, 0xa2ac0ef3), o.u(0x19bafe5d, 0x5d4419fe),
4610// o.u(0x5b1bc080, 0x80db5bc0), o.u(0x850a8a05, 0x0580858a),
4611// o.u(0xec7ead3f, 0x3fd3ecad), o.u(0xdf42bc21, 0x21fedfbc),
4612// o.u(0xd8e04870, 0x70a8d848), o.u(0x0cf904f1, 0xf1fd0c04),
4613// o.u(0x7ac6df63, 0x63197adf), o.u(0x58eec177, 0x772f58c1),
4614// o.u(0x9f4575af, 0xaf309f75), o.u(0xa5846342, 0x42e7a563),
4615// o.u(0x50403020, 0x20705030), o.u(0x2ed11ae5, 0xe5cb2e1a),
4616// o.u(0x12e10efd, 0xfdef120e), o.u(0xb7656dbf, 0xbf08b76d),
4617// o.u(0xd4194c81, 0x8155d44c), o.u(0x3c301418, 0x18243c14),
4618// o.u(0x5f4c3526, 0x26795f35), o.u(0x719d2fc3, 0xc3b2712f),
4619// o.u(0x3867e1be, 0xbe8638e1), o.u(0xfd6aa235, 0x35c8fda2),
4620// o.u(0x4f0bcc88, 0x88c74fcc), o.u(0x4b5c392e, 0x2e654b39),
4621// o.u(0xf93d5793, 0x936af957), o.u(0x0daaf255, 0x55580df2),
4622// o.u(0x9de382fc, 0xfc619d82), o.u(0xc9f4477a, 0x7ab3c947),
4623// o.u(0xef8bacc8, 0xc827efac), o.u(0x326fe7ba, 0xba8832e7),
4624// o.u(0x7d642b32, 0x324f7d2b), o.u(0xa4d795e6, 0xe642a495),
4625// o.u(0xfb9ba0c0, 0xc03bfba0), o.u(0xb3329819, 0x19aab398),
4626// o.u(0x6827d19e, 0x9ef668d1), o.u(0x815d7fa3, 0xa322817f),
4627// o.u(0xaa886644, 0x44eeaa66), o.u(0x82a87e54, 0x54d6827e),
4628// o.u(0xe676ab3b, 0x3bdde6ab), o.u(0x9e16830b, 0x0b959e83),
4629// o.u(0x4503ca8c, 0x8cc945ca), o.u(0x7b9529c7, 0xc7bc7b29),
4630// o.u(0x6ed6d36b, 0x6b056ed3), o.u(0x44503c28, 0x286c443c),
4631// o.u(0x8b5579a7, 0xa72c8b79), o.u(0x3d63e2bc, 0xbc813de2),
4632// o.u(0x272c1d16, 0x1631271d), o.u(0x9a4176ad, 0xad379a76),
4633// o.u(0x4dad3bdb, 0xdb964d3b), o.u(0xfac85664, 0x649efa56),
4634// o.u(0xd2e84e74, 0x74a6d24e), o.u(0x22281e14, 0x1436221e),
4635// o.u(0x763fdb92, 0x92e476db), o.u(0x1e180a0c, 0x0c121e0a),
4636// o.u(0xb4906c48, 0x48fcb46c), o.u(0x376be4b8, 0xb88f37e4),
4637// o.u(0xe7255d9f, 0x9f78e75d), o.u(0xb2616ebd, 0xbd0fb26e),
4638// o.u(0x2a86ef43, 0x43692aef), o.u(0xf193a6c4, 0xc435f1a6),
4639// o.u(0xe372a839, 0x39dae3a8), o.u(0xf762a431, 0x31c6f7a4),
4640// o.u(0x59bd37d3, 0xd38a5937), o.u(0x86ff8bf2, 0xf274868b),
4641// o.u(0x56b132d5, 0xd5835632), o.u(0xc50d438b, 0x8b4ec543),
4642// o.u(0xebdc596e, 0x6e85eb59), o.u(0xc2afb7da, 0xda18c2b7),
4643// o.u(0x8f028c01, 0x018e8f8c), o.u(0xac7964b1, 0xb11dac64),
4644// o.u(0x6d23d29c, 0x9cf16dd2), o.u(0x3b92e049, 0x49723be0),
4645// o.u(0xc7abb4d8, 0xd81fc7b4), o.u(0x1543faac, 0xacb915fa),
4646// o.u(0x09fd07f3, 0xf3fa0907), o.u(0x6f8525cf, 0xcfa06f25),
4647// o.u(0xea8fafca, 0xca20eaaf), o.u(0x89f38ef4, 0xf47d898e),
4648// o.u(0x208ee947, 0x476720e9), o.u(0x28201810, 0x10382818),
4649// o.u(0x64ded56f, 0x6f0b64d5), o.u(0x83fb88f0, 0xf0738388),
4650// o.u(0xb1946f4a, 0x4afbb16f), o.u(0x96b8725c, 0x5cca9672),
4651// o.u(0x6c702438, 0x38546c24), o.u(0x08aef157, 0x575f08f1),
4652// o.u(0x52e6c773, 0x732152c7), o.u(0xf3355197, 0x9764f351),
4653// o.u(0x658d23cb, 0xcbae6523), o.u(0x84597ca1, 0xa125847c),
4654// o.u(0xbfcb9ce8, 0xe857bf9c), o.u(0x637c213e, 0x3e5d6321),
4655// o.u(0x7c37dd96, 0x96ea7cdd), o.u(0x7fc2dc61, 0x611e7fdc),
4656// o.u(0x911a860d, 0x0d9c9186), o.u(0x941e850f, 0x0f9b9485),
4657// o.u(0xabdb90e0, 0xe04bab90), o.u(0xc6f8427c, 0x7cbac642),
4658// o.u(0x57e2c471, 0x712657c4), o.u(0xe583aacc, 0xcc29e5aa),
4659// o.u(0x733bd890, 0x90e373d8), o.u(0x0f0c0506, 0x06090f05),
4660// o.u(0x03f501f7, 0xf7f40301), o.u(0x3638121c, 0x1c2a3612),
4661// o.u(0xfe9fa3c2, 0xc23cfea3), o.u(0xe1d45f6a, 0x6a8be15f),
4662// o.u(0x1047f9ae, 0xaebe10f9), o.u(0x6bd2d069, 0x69026bd0),
4663// o.u(0xa82e9117, 0x17bfa891), o.u(0xe8295899, 0x9971e858),
4664// o.u(0x6974273a, 0x3a536927), o.u(0xd04eb927, 0x27f7d0b9),
4665// o.u(0x48a938d9, 0xd9914838), o.u(0x35cd13eb, 0xebde3513),
4666// o.u(0xce56b32b, 0x2be5ceb3), o.u(0x55443322, 0x22775533),
4667// o.u(0xd6bfbbd2, 0xd204d6bb), o.u(0x904970a9, 0xa9399070),
4668// o.u(0x800e8907, 0x07878089), o.u(0xf266a733, 0x33c1f2a7),
4669// o.u(0xc15ab62d, 0x2decc1b6), o.u(0x6678223c, 0x3c5a6622),
4670// o.u(0xad2a9215, 0x15b8ad92), o.u(0x608920c9, 0xc9a96020),
4671// o.u(0xdb154987, 0x875cdb49), o.u(0x1a4fffaa, 0xaab01aff),
4672// o.u(0x88a07850, 0x50d88878), o.u(0x8e517aa5, 0xa52b8e7a),
4673// o.u(0x8a068f03, 0x03898a8f), o.u(0x13b2f859, 0x594a13f8),
4674// o.u(0x9b128009, 0x09929b80), o.u(0x3934171a, 0x1a233917),
4675// o.u(0x75cada65, 0x651075da), o.u(0x53b531d7, 0xd7845331),
4676// o.u(0x5113c684, 0x84d551c6), o.u(0xd3bbb8d0, 0xd003d3b8),
4677// o.u(0x5e1fc382, 0x82dc5ec3), o.u(0xcb52b029, 0x29e2cbb0),
4678// o.u(0x99b4775a, 0x5ac39977), o.u(0x333c111e, 0x1e2d3311),
4679// o.u(0x46f6cb7b, 0x7b3d46cb), o.u(0x1f4bfca8, 0xa8b71ffc),
4680// o.u(0x61dad66d, 0x6d0c61d6), o.u(0x4e583a2c, 0x2c624e3a)
4681// ];
4682
4683// var T5 = [
4684// o.u(0xa5f497a5, 0xc6c632f4), o.u(0x8497eb84, 0xf8f86f97),
4685// o.u(0x99b0c799, 0xeeee5eb0), o.u(0x8d8cf78d, 0xf6f67a8c),
4686// o.u(0xd17e50d, 0xffffe817), o.u(0xbddcb7bd, 0xd6d60adc),
4687// o.u(0xb1c8a7b1, 0xdede16c8), o.u(0x54fc3954, 0x91916dfc),
4688// o.u(0x50f0c050, 0x606090f0), o.u(0x3050403, 0x2020705),
4689// o.u(0xa9e087a9, 0xcece2ee0), o.u(0x7d87ac7d, 0x5656d187),
4690// o.u(0x192bd519, 0xe7e7cc2b), o.u(0x62a67162, 0xb5b513a6),
4691// o.u(0xe6319ae6, 0x4d4d7c31), o.u(0x9ab5c39a, 0xecec59b5),
4692// o.u(0x45cf0545, 0x8f8f40cf), o.u(0x9dbc3e9d, 0x1f1fa3bc),
4693// o.u(0x40c00940, 0x898949c0), o.u(0x8792ef87, 0xfafa6892),
4694// o.u(0x153fc515, 0xefefd03f), o.u(0xeb267feb, 0xb2b29426),
4695// o.u(0xc94007c9, 0x8e8ece40), o.u(0xb1ded0b, 0xfbfbe61d),
4696// o.u(0xec2f82ec, 0x41416e2f), o.u(0x67a97d67, 0xb3b31aa9),
4697// o.u(0xfd1cbefd, 0x5f5f431c), o.u(0xea258aea, 0x45456025),
4698// o.u(0xbfda46bf, 0x2323f9da), o.u(0xf702a6f7, 0x53535102),
4699// o.u(0x96a1d396, 0xe4e445a1), o.u(0x5bed2d5b, 0x9b9b76ed),
4700// o.u(0xc25deac2, 0x7575285d), o.u(0x1c24d91c, 0xe1e1c524),
4701// o.u(0xaee97aae, 0x3d3dd4e9), o.u(0x6abe986a, 0x4c4cf2be),
4702// o.u(0x5aeed85a, 0x6c6c82ee), o.u(0x41c3fc41, 0x7e7ebdc3),
4703// o.u(0x206f102, 0xf5f5f306), o.u(0x4fd11d4f, 0x838352d1),
4704// o.u(0x5ce4d05c, 0x68688ce4), o.u(0xf407a2f4, 0x51515607),
4705// o.u(0x345cb934, 0xd1d18d5c), o.u(0x818e908, 0xf9f9e118),
4706// o.u(0x93aedf93, 0xe2e24cae), o.u(0x73954d73, 0xabab3e95),
4707// o.u(0x53f5c453, 0x626297f5), o.u(0x3f41543f, 0x2a2a6b41),
4708// o.u(0xc14100c, 0x8081c14), o.u(0x52f63152, 0x959563f6),
4709// o.u(0x65af8c65, 0x4646e9af), o.u(0x5ee2215e, 0x9d9d7fe2),
4710// o.u(0x28786028, 0x30304878), o.u(0xa1f86ea1, 0x3737cff8),
4711// o.u(0xf11140f, 0xa0a1b11), o.u(0xb5c45eb5, 0x2f2febc4),
4712// o.u(0x91b1c09, 0xe0e151b), o.u(0x365a4836, 0x24247e5a),
4713// o.u(0x9bb6369b, 0x1b1badb6), o.u(0x3d47a53d, 0xdfdf9847),
4714// o.u(0x266a8126, 0xcdcda76a), o.u(0x69bb9c69, 0x4e4ef5bb),
4715// o.u(0xcd4cfecd, 0x7f7f334c), o.u(0x9fbacf9f, 0xeaea50ba),
4716// o.u(0x1b2d241b, 0x12123f2d), o.u(0x9eb93a9e, 0x1d1da4b9),
4717// o.u(0x749cb074, 0x5858c49c), o.u(0x2e72682e, 0x34344672),
4718// o.u(0x2d776c2d, 0x36364177), o.u(0xb2cda3b2, 0xdcdc11cd),
4719// o.u(0xee2973ee, 0xb4b49d29), o.u(0xfb16b6fb, 0x5b5b4d16),
4720// o.u(0xf60153f6, 0xa4a4a501), o.u(0x4dd7ec4d, 0x7676a1d7),
4721// o.u(0x61a37561, 0xb7b714a3), o.u(0xce49face, 0x7d7d3449),
4722// o.u(0x7b8da47b, 0x5252df8d), o.u(0x3e42a13e, 0xdddd9f42),
4723// o.u(0x7193bc71, 0x5e5ecd93), o.u(0x97a22697, 0x1313b1a2),
4724// o.u(0xf50457f5, 0xa6a6a204), o.u(0x68b86968, 0xb9b901b8),
4725// o.u(0x0, 0x0), o.u(0x2c74992c, 0xc1c1b574),
4726// o.u(0x60a08060, 0x4040e0a0), o.u(0x1f21dd1f, 0xe3e3c221),
4727// o.u(0xc843f2c8, 0x79793a43), o.u(0xed2c77ed, 0xb6b69a2c),
4728// o.u(0xbed9b3be, 0xd4d40dd9), o.u(0x46ca0146, 0x8d8d47ca),
4729// o.u(0xd970ced9, 0x67671770), o.u(0x4bdde44b, 0x7272afdd),
4730// o.u(0xde7933de, 0x9494ed79), o.u(0xd4672bd4, 0x9898ff67),
4731// o.u(0xe8237be8, 0xb0b09323), o.u(0x4ade114a, 0x85855bde),
4732// o.u(0x6bbd6d6b, 0xbbbb06bd), o.u(0x2a7e912a, 0xc5c5bb7e),
4733// o.u(0xe5349ee5, 0x4f4f7b34), o.u(0x163ac116, 0xededd73a),
4734// o.u(0xc55417c5, 0x8686d254), o.u(0xd7622fd7, 0x9a9af862),
4735// o.u(0x55ffcc55, 0x666699ff), o.u(0x94a72294, 0x1111b6a7),
4736// o.u(0xcf4a0fcf, 0x8a8ac04a), o.u(0x1030c910, 0xe9e9d930),
4737// o.u(0x60a0806, 0x4040e0a), o.u(0x8198e781, 0xfefe6698),
4738// o.u(0xf00b5bf0, 0xa0a0ab0b), o.u(0x44ccf044, 0x7878b4cc),
4739// o.u(0xbad54aba, 0x2525f0d5), o.u(0xe33e96e3, 0x4b4b753e),
4740// o.u(0xf30e5ff3, 0xa2a2ac0e), o.u(0xfe19bafe, 0x5d5d4419),
4741// o.u(0xc05b1bc0, 0x8080db5b), o.u(0x8a850a8a, 0x5058085),
4742// o.u(0xadec7ead, 0x3f3fd3ec), o.u(0xbcdf42bc, 0x2121fedf),
4743// o.u(0x48d8e048, 0x7070a8d8), o.u(0x40cf904, 0xf1f1fd0c),
4744// o.u(0xdf7ac6df, 0x6363197a), o.u(0xc158eec1, 0x77772f58),
4745// o.u(0x759f4575, 0xafaf309f), o.u(0x63a58463, 0x4242e7a5),
4746// o.u(0x30504030, 0x20207050), o.u(0x1a2ed11a, 0xe5e5cb2e),
4747// o.u(0xe12e10e, 0xfdfdef12), o.u(0x6db7656d, 0xbfbf08b7),
4748// o.u(0x4cd4194c, 0x818155d4), o.u(0x143c3014, 0x1818243c),
4749// o.u(0x355f4c35, 0x2626795f), o.u(0x2f719d2f, 0xc3c3b271),
4750// o.u(0xe13867e1, 0xbebe8638), o.u(0xa2fd6aa2, 0x3535c8fd),
4751// o.u(0xcc4f0bcc, 0x8888c74f), o.u(0x394b5c39, 0x2e2e654b),
4752// o.u(0x57f93d57, 0x93936af9), o.u(0xf20daaf2, 0x5555580d),
4753// o.u(0x829de382, 0xfcfc619d), o.u(0x47c9f447, 0x7a7ab3c9),
4754// o.u(0xacef8bac, 0xc8c827ef), o.u(0xe7326fe7, 0xbaba8832),
4755// o.u(0x2b7d642b, 0x32324f7d), o.u(0x95a4d795, 0xe6e642a4),
4756// o.u(0xa0fb9ba0, 0xc0c03bfb), o.u(0x98b33298, 0x1919aab3),
4757// o.u(0xd16827d1, 0x9e9ef668), o.u(0x7f815d7f, 0xa3a32281),
4758// o.u(0x66aa8866, 0x4444eeaa), o.u(0x7e82a87e, 0x5454d682),
4759// o.u(0xabe676ab, 0x3b3bdde6), o.u(0x839e1683, 0xb0b959e),
4760// o.u(0xca4503ca, 0x8c8cc945), o.u(0x297b9529, 0xc7c7bc7b),
4761// o.u(0xd36ed6d3, 0x6b6b056e), o.u(0x3c44503c, 0x28286c44),
4762// o.u(0x798b5579, 0xa7a72c8b), o.u(0xe23d63e2, 0xbcbc813d),
4763// o.u(0x1d272c1d, 0x16163127), o.u(0x769a4176, 0xadad379a),
4764// o.u(0x3b4dad3b, 0xdbdb964d), o.u(0x56fac856, 0x64649efa),
4765// o.u(0x4ed2e84e, 0x7474a6d2), o.u(0x1e22281e, 0x14143622),
4766// o.u(0xdb763fdb, 0x9292e476), o.u(0xa1e180a, 0xc0c121e),
4767// o.u(0x6cb4906c, 0x4848fcb4), o.u(0xe4376be4, 0xb8b88f37),
4768// o.u(0x5de7255d, 0x9f9f78e7), o.u(0x6eb2616e, 0xbdbd0fb2),
4769// o.u(0xef2a86ef, 0x4343692a), o.u(0xa6f193a6, 0xc4c435f1),
4770// o.u(0xa8e372a8, 0x3939dae3), o.u(0xa4f762a4, 0x3131c6f7),
4771// o.u(0x3759bd37, 0xd3d38a59), o.u(0x8b86ff8b, 0xf2f27486),
4772// o.u(0x3256b132, 0xd5d58356), o.u(0x43c50d43, 0x8b8b4ec5),
4773// o.u(0x59ebdc59, 0x6e6e85eb), o.u(0xb7c2afb7, 0xdada18c2),
4774// o.u(0x8c8f028c, 0x1018e8f), o.u(0x64ac7964, 0xb1b11dac),
4775// o.u(0xd26d23d2, 0x9c9cf16d), o.u(0xe03b92e0, 0x4949723b),
4776// o.u(0xb4c7abb4, 0xd8d81fc7), o.u(0xfa1543fa, 0xacacb915),
4777// o.u(0x709fd07, 0xf3f3fa09), o.u(0x256f8525, 0xcfcfa06f),
4778// o.u(0xafea8faf, 0xcaca20ea), o.u(0x8e89f38e, 0xf4f47d89),
4779// o.u(0xe9208ee9, 0x47476720), o.u(0x18282018, 0x10103828),
4780// o.u(0xd564ded5, 0x6f6f0b64), o.u(0x8883fb88, 0xf0f07383),
4781// o.u(0x6fb1946f, 0x4a4afbb1), o.u(0x7296b872, 0x5c5cca96),
4782// o.u(0x246c7024, 0x3838546c), o.u(0xf108aef1, 0x57575f08),
4783// o.u(0xc752e6c7, 0x73732152), o.u(0x51f33551, 0x979764f3),
4784// o.u(0x23658d23, 0xcbcbae65), o.u(0x7c84597c, 0xa1a12584),
4785// o.u(0x9cbfcb9c, 0xe8e857bf), o.u(0x21637c21, 0x3e3e5d63),
4786// o.u(0xdd7c37dd, 0x9696ea7c), o.u(0xdc7fc2dc, 0x61611e7f),
4787// o.u(0x86911a86, 0xd0d9c91), o.u(0x85941e85, 0xf0f9b94),
4788// o.u(0x90abdb90, 0xe0e04bab), o.u(0x42c6f842, 0x7c7cbac6),
4789// o.u(0xc457e2c4, 0x71712657), o.u(0xaae583aa, 0xcccc29e5),
4790// o.u(0xd8733bd8, 0x9090e373), o.u(0x50f0c05, 0x606090f),
4791// o.u(0x103f501, 0xf7f7f403), o.u(0x12363812, 0x1c1c2a36),
4792// o.u(0xa3fe9fa3, 0xc2c23cfe), o.u(0x5fe1d45f, 0x6a6a8be1),
4793// o.u(0xf91047f9, 0xaeaebe10), o.u(0xd06bd2d0, 0x6969026b),
4794// o.u(0x91a82e91, 0x1717bfa8), o.u(0x58e82958, 0x999971e8),
4795// o.u(0x27697427, 0x3a3a5369), o.u(0xb9d04eb9, 0x2727f7d0),
4796// o.u(0x3848a938, 0xd9d99148), o.u(0x1335cd13, 0xebebde35),
4797// o.u(0xb3ce56b3, 0x2b2be5ce), o.u(0x33554433, 0x22227755),
4798// o.u(0xbbd6bfbb, 0xd2d204d6), o.u(0x70904970, 0xa9a93990),
4799// o.u(0x89800e89, 0x7078780), o.u(0xa7f266a7, 0x3333c1f2),
4800// o.u(0xb6c15ab6, 0x2d2decc1), o.u(0x22667822, 0x3c3c5a66),
4801// o.u(0x92ad2a92, 0x1515b8ad), o.u(0x20608920, 0xc9c9a960),
4802// o.u(0x49db1549, 0x87875cdb), o.u(0xff1a4fff, 0xaaaab01a),
4803// o.u(0x7888a078, 0x5050d888), o.u(0x7a8e517a, 0xa5a52b8e),
4804// o.u(0x8f8a068f, 0x303898a), o.u(0xf813b2f8, 0x59594a13),
4805// o.u(0x809b1280, 0x909929b), o.u(0x17393417, 0x1a1a2339),
4806// o.u(0xda75cada, 0x65651075), o.u(0x3153b531, 0xd7d78453),
4807// o.u(0xc65113c6, 0x8484d551), o.u(0xb8d3bbb8, 0xd0d003d3),
4808// o.u(0xc35e1fc3, 0x8282dc5e), o.u(0xb0cb52b0, 0x2929e2cb),
4809// o.u(0x7799b477, 0x5a5ac399), o.u(0x11333c11, 0x1e1e2d33),
4810// o.u(0xcb46f6cb, 0x7b7b3d46), o.u(0xfc1f4bfc, 0xa8a8b71f),
4811// o.u(0xd661dad6, 0x6d6d0c61), o.u(0x3a4e583a, 0x2c2c624e)
4812// ];
4813
4814// var T6 = [
4815// o.u(0xf4a5f497, 0xa5c6c632), o.u(0x978497eb, 0x84f8f86f),
4816// o.u(0xb099b0c7, 0x99eeee5e), o.u(0x8c8d8cf7, 0x8df6f67a),
4817// o.u(0x170d17e5, 0xdffffe8), o.u(0xdcbddcb7, 0xbdd6d60a),
4818// o.u(0xc8b1c8a7, 0xb1dede16), o.u(0xfc54fc39, 0x5491916d),
4819// o.u(0xf050f0c0, 0x50606090), o.u(0x5030504, 0x3020207),
4820// o.u(0xe0a9e087, 0xa9cece2e), o.u(0x877d87ac, 0x7d5656d1),
4821// o.u(0x2b192bd5, 0x19e7e7cc), o.u(0xa662a671, 0x62b5b513),
4822// o.u(0x31e6319a, 0xe64d4d7c), o.u(0xb59ab5c3, 0x9aecec59),
4823// o.u(0xcf45cf05, 0x458f8f40), o.u(0xbc9dbc3e, 0x9d1f1fa3),
4824// o.u(0xc040c009, 0x40898949), o.u(0x928792ef, 0x87fafa68),
4825// o.u(0x3f153fc5, 0x15efefd0), o.u(0x26eb267f, 0xebb2b294),
4826// o.u(0x40c94007, 0xc98e8ece), o.u(0x1d0b1ded, 0xbfbfbe6),
4827// o.u(0x2fec2f82, 0xec41416e), o.u(0xa967a97d, 0x67b3b31a),
4828// o.u(0x1cfd1cbe, 0xfd5f5f43), o.u(0x25ea258a, 0xea454560),
4829// o.u(0xdabfda46, 0xbf2323f9), o.u(0x2f702a6, 0xf7535351),
4830// o.u(0xa196a1d3, 0x96e4e445), o.u(0xed5bed2d, 0x5b9b9b76),
4831// o.u(0x5dc25dea, 0xc2757528), o.u(0x241c24d9, 0x1ce1e1c5),
4832// o.u(0xe9aee97a, 0xae3d3dd4), o.u(0xbe6abe98, 0x6a4c4cf2),
4833// o.u(0xee5aeed8, 0x5a6c6c82), o.u(0xc341c3fc, 0x417e7ebd),
4834// o.u(0x60206f1, 0x2f5f5f3), o.u(0xd14fd11d, 0x4f838352),
4835// o.u(0xe45ce4d0, 0x5c68688c), o.u(0x7f407a2, 0xf4515156),
4836// o.u(0x5c345cb9, 0x34d1d18d), o.u(0x180818e9, 0x8f9f9e1),
4837// o.u(0xae93aedf, 0x93e2e24c), o.u(0x9573954d, 0x73abab3e),
4838// o.u(0xf553f5c4, 0x53626297), o.u(0x413f4154, 0x3f2a2a6b),
4839// o.u(0x140c1410, 0xc08081c), o.u(0xf652f631, 0x52959563),
4840// o.u(0xaf65af8c, 0x654646e9), o.u(0xe25ee221, 0x5e9d9d7f),
4841// o.u(0x78287860, 0x28303048), o.u(0xf8a1f86e, 0xa13737cf),
4842// o.u(0x110f1114, 0xf0a0a1b), o.u(0xc4b5c45e, 0xb52f2feb),
4843// o.u(0x1b091b1c, 0x90e0e15), o.u(0x5a365a48, 0x3624247e),
4844// o.u(0xb69bb636, 0x9b1b1bad), o.u(0x473d47a5, 0x3ddfdf98),
4845// o.u(0x6a266a81, 0x26cdcda7), o.u(0xbb69bb9c, 0x694e4ef5),
4846// o.u(0x4ccd4cfe, 0xcd7f7f33), o.u(0xba9fbacf, 0x9feaea50),
4847// o.u(0x2d1b2d24, 0x1b12123f), o.u(0xb99eb93a, 0x9e1d1da4),
4848// o.u(0x9c749cb0, 0x745858c4), o.u(0x722e7268, 0x2e343446),
4849// o.u(0x772d776c, 0x2d363641), o.u(0xcdb2cda3, 0xb2dcdc11),
4850// o.u(0x29ee2973, 0xeeb4b49d), o.u(0x16fb16b6, 0xfb5b5b4d),
4851// o.u(0x1f60153, 0xf6a4a4a5), o.u(0xd74dd7ec, 0x4d7676a1),
4852// o.u(0xa361a375, 0x61b7b714), o.u(0x49ce49fa, 0xce7d7d34),
4853// o.u(0x8d7b8da4, 0x7b5252df), o.u(0x423e42a1, 0x3edddd9f),
4854// o.u(0x937193bc, 0x715e5ecd), o.u(0xa297a226, 0x971313b1),
4855// o.u(0x4f50457, 0xf5a6a6a2), o.u(0xb868b869, 0x68b9b901),
4856// o.u(0x0, 0x0), o.u(0x742c7499, 0x2cc1c1b5),
4857// o.u(0xa060a080, 0x604040e0), o.u(0x211f21dd, 0x1fe3e3c2),
4858// o.u(0x43c843f2, 0xc879793a), o.u(0x2ced2c77, 0xedb6b69a),
4859// o.u(0xd9bed9b3, 0xbed4d40d), o.u(0xca46ca01, 0x468d8d47),
4860// o.u(0x70d970ce, 0xd9676717), o.u(0xdd4bdde4, 0x4b7272af),
4861// o.u(0x79de7933, 0xde9494ed), o.u(0x67d4672b, 0xd49898ff),
4862// o.u(0x23e8237b, 0xe8b0b093), o.u(0xde4ade11, 0x4a85855b),
4863// o.u(0xbd6bbd6d, 0x6bbbbb06), o.u(0x7e2a7e91, 0x2ac5c5bb),
4864// o.u(0x34e5349e, 0xe54f4f7b), o.u(0x3a163ac1, 0x16ededd7),
4865// o.u(0x54c55417, 0xc58686d2), o.u(0x62d7622f, 0xd79a9af8),
4866// o.u(0xff55ffcc, 0x55666699), o.u(0xa794a722, 0x941111b6),
4867// o.u(0x4acf4a0f, 0xcf8a8ac0), o.u(0x301030c9, 0x10e9e9d9),
4868// o.u(0xa060a08, 0x604040e), o.u(0x988198e7, 0x81fefe66),
4869// o.u(0xbf00b5b, 0xf0a0a0ab), o.u(0xcc44ccf0, 0x447878b4),
4870// o.u(0xd5bad54a, 0xba2525f0), o.u(0x3ee33e96, 0xe34b4b75),
4871// o.u(0xef30e5f, 0xf3a2a2ac), o.u(0x19fe19ba, 0xfe5d5d44),
4872// o.u(0x5bc05b1b, 0xc08080db), o.u(0x858a850a, 0x8a050580),
4873// o.u(0xecadec7e, 0xad3f3fd3), o.u(0xdfbcdf42, 0xbc2121fe),
4874// o.u(0xd848d8e0, 0x487070a8), o.u(0xc040cf9, 0x4f1f1fd),
4875// o.u(0x7adf7ac6, 0xdf636319), o.u(0x58c158ee, 0xc177772f),
4876// o.u(0x9f759f45, 0x75afaf30), o.u(0xa563a584, 0x634242e7),
4877// o.u(0x50305040, 0x30202070), o.u(0x2e1a2ed1, 0x1ae5e5cb),
4878// o.u(0x120e12e1, 0xefdfdef), o.u(0xb76db765, 0x6dbfbf08),
4879// o.u(0xd44cd419, 0x4c818155), o.u(0x3c143c30, 0x14181824),
4880// o.u(0x5f355f4c, 0x35262679), o.u(0x712f719d, 0x2fc3c3b2),
4881// o.u(0x38e13867, 0xe1bebe86), o.u(0xfda2fd6a, 0xa23535c8),
4882// o.u(0x4fcc4f0b, 0xcc8888c7), o.u(0x4b394b5c, 0x392e2e65),
4883// o.u(0xf957f93d, 0x5793936a), o.u(0xdf20daa, 0xf2555558),
4884// o.u(0x9d829de3, 0x82fcfc61), o.u(0xc947c9f4, 0x477a7ab3),
4885// o.u(0xefacef8b, 0xacc8c827), o.u(0x32e7326f, 0xe7baba88),
4886// o.u(0x7d2b7d64, 0x2b32324f), o.u(0xa495a4d7, 0x95e6e642),
4887// o.u(0xfba0fb9b, 0xa0c0c03b), o.u(0xb398b332, 0x981919aa),
4888// o.u(0x68d16827, 0xd19e9ef6), o.u(0x817f815d, 0x7fa3a322),
4889// o.u(0xaa66aa88, 0x664444ee), o.u(0x827e82a8, 0x7e5454d6),
4890// o.u(0xe6abe676, 0xab3b3bdd), o.u(0x9e839e16, 0x830b0b95),
4891// o.u(0x45ca4503, 0xca8c8cc9), o.u(0x7b297b95, 0x29c7c7bc),
4892// o.u(0x6ed36ed6, 0xd36b6b05), o.u(0x443c4450, 0x3c28286c),
4893// o.u(0x8b798b55, 0x79a7a72c), o.u(0x3de23d63, 0xe2bcbc81),
4894// o.u(0x271d272c, 0x1d161631), o.u(0x9a769a41, 0x76adad37),
4895// o.u(0x4d3b4dad, 0x3bdbdb96), o.u(0xfa56fac8, 0x5664649e),
4896// o.u(0xd24ed2e8, 0x4e7474a6), o.u(0x221e2228, 0x1e141436),
4897// o.u(0x76db763f, 0xdb9292e4), o.u(0x1e0a1e18, 0xa0c0c12),
4898// o.u(0xb46cb490, 0x6c4848fc), o.u(0x37e4376b, 0xe4b8b88f),
4899// o.u(0xe75de725, 0x5d9f9f78), o.u(0xb26eb261, 0x6ebdbd0f),
4900// o.u(0x2aef2a86, 0xef434369), o.u(0xf1a6f193, 0xa6c4c435),
4901// o.u(0xe3a8e372, 0xa83939da), o.u(0xf7a4f762, 0xa43131c6),
4902// o.u(0x593759bd, 0x37d3d38a), o.u(0x868b86ff, 0x8bf2f274),
4903// o.u(0x563256b1, 0x32d5d583), o.u(0xc543c50d, 0x438b8b4e),
4904// o.u(0xeb59ebdc, 0x596e6e85), o.u(0xc2b7c2af, 0xb7dada18),
4905// o.u(0x8f8c8f02, 0x8c01018e), o.u(0xac64ac79, 0x64b1b11d),
4906// o.u(0x6dd26d23, 0xd29c9cf1), o.u(0x3be03b92, 0xe0494972),
4907// o.u(0xc7b4c7ab, 0xb4d8d81f), o.u(0x15fa1543, 0xfaacacb9),
4908// o.u(0x90709fd, 0x7f3f3fa), o.u(0x6f256f85, 0x25cfcfa0),
4909// o.u(0xeaafea8f, 0xafcaca20), o.u(0x898e89f3, 0x8ef4f47d),
4910// o.u(0x20e9208e, 0xe9474767), o.u(0x28182820, 0x18101038),
4911// o.u(0x64d564de, 0xd56f6f0b), o.u(0x838883fb, 0x88f0f073),
4912// o.u(0xb16fb194, 0x6f4a4afb), o.u(0x967296b8, 0x725c5cca),
4913// o.u(0x6c246c70, 0x24383854), o.u(0x8f108ae, 0xf157575f),
4914// o.u(0x52c752e6, 0xc7737321), o.u(0xf351f335, 0x51979764),
4915// o.u(0x6523658d, 0x23cbcbae), o.u(0x847c8459, 0x7ca1a125),
4916// o.u(0xbf9cbfcb, 0x9ce8e857), o.u(0x6321637c, 0x213e3e5d),
4917// o.u(0x7cdd7c37, 0xdd9696ea), o.u(0x7fdc7fc2, 0xdc61611e),
4918// o.u(0x9186911a, 0x860d0d9c), o.u(0x9485941e, 0x850f0f9b),
4919// o.u(0xab90abdb, 0x90e0e04b), o.u(0xc642c6f8, 0x427c7cba),
4920// o.u(0x57c457e2, 0xc4717126), o.u(0xe5aae583, 0xaacccc29),
4921// o.u(0x73d8733b, 0xd89090e3), o.u(0xf050f0c, 0x5060609),
4922// o.u(0x30103f5, 0x1f7f7f4), o.u(0x36123638, 0x121c1c2a),
4923// o.u(0xfea3fe9f, 0xa3c2c23c), o.u(0xe15fe1d4, 0x5f6a6a8b),
4924// o.u(0x10f91047, 0xf9aeaebe), o.u(0x6bd06bd2, 0xd0696902),
4925// o.u(0xa891a82e, 0x911717bf), o.u(0xe858e829, 0x58999971),
4926// o.u(0x69276974, 0x273a3a53), o.u(0xd0b9d04e, 0xb92727f7),
4927// o.u(0x483848a9, 0x38d9d991), o.u(0x351335cd, 0x13ebebde),
4928// o.u(0xceb3ce56, 0xb32b2be5), o.u(0x55335544, 0x33222277),
4929// o.u(0xd6bbd6bf, 0xbbd2d204), o.u(0x90709049, 0x70a9a939),
4930// o.u(0x8089800e, 0x89070787), o.u(0xf2a7f266, 0xa73333c1),
4931// o.u(0xc1b6c15a, 0xb62d2dec), o.u(0x66226678, 0x223c3c5a),
4932// o.u(0xad92ad2a, 0x921515b8), o.u(0x60206089, 0x20c9c9a9),
4933// o.u(0xdb49db15, 0x4987875c), o.u(0x1aff1a4f, 0xffaaaab0),
4934// o.u(0x887888a0, 0x785050d8), o.u(0x8e7a8e51, 0x7aa5a52b),
4935// o.u(0x8a8f8a06, 0x8f030389), o.u(0x13f813b2, 0xf859594a),
4936// o.u(0x9b809b12, 0x80090992), o.u(0x39173934, 0x171a1a23),
4937// o.u(0x75da75ca, 0xda656510), o.u(0x533153b5, 0x31d7d784),
4938// o.u(0x51c65113, 0xc68484d5), o.u(0xd3b8d3bb, 0xb8d0d003),
4939// o.u(0x5ec35e1f, 0xc38282dc), o.u(0xcbb0cb52, 0xb02929e2),
4940// o.u(0x997799b4, 0x775a5ac3), o.u(0x3311333c, 0x111e1e2d),
4941// o.u(0x46cb46f6, 0xcb7b7b3d), o.u(0x1ffc1f4b, 0xfca8a8b7),
4942// o.u(0x61d661da, 0xd66d6d0c), o.u(0x4e3a4e58, 0x3a2c2c62)
4943// ];
4944
4945// var T7 = [
4946// o.u(0x32f4a5f4, 0x97a5c6c6), o.u(0x6f978497, 0xeb84f8f8),
4947// o.u(0x5eb099b0, 0xc799eeee), o.u(0x7a8c8d8c, 0xf78df6f6),
4948// o.u(0xe8170d17, 0xe50dffff), o.u(0xadcbddc, 0xb7bdd6d6),
4949// o.u(0x16c8b1c8, 0xa7b1dede), o.u(0x6dfc54fc, 0x39549191),
4950// o.u(0x90f050f0, 0xc0506060), o.u(0x7050305, 0x4030202),
4951// o.u(0x2ee0a9e0, 0x87a9cece), o.u(0xd1877d87, 0xac7d5656),
4952// o.u(0xcc2b192b, 0xd519e7e7), o.u(0x13a662a6, 0x7162b5b5),
4953// o.u(0x7c31e631, 0x9ae64d4d), o.u(0x59b59ab5, 0xc39aecec),
4954// o.u(0x40cf45cf, 0x5458f8f), o.u(0xa3bc9dbc, 0x3e9d1f1f),
4955// o.u(0x49c040c0, 0x9408989), o.u(0x68928792, 0xef87fafa),
4956// o.u(0xd03f153f, 0xc515efef), o.u(0x9426eb26, 0x7febb2b2),
4957// o.u(0xce40c940, 0x7c98e8e), o.u(0xe61d0b1d, 0xed0bfbfb),
4958// o.u(0x6e2fec2f, 0x82ec4141), o.u(0x1aa967a9, 0x7d67b3b3),
4959// o.u(0x431cfd1c, 0xbefd5f5f), o.u(0x6025ea25, 0x8aea4545),
4960// o.u(0xf9dabfda, 0x46bf2323), o.u(0x5102f702, 0xa6f75353),
4961// o.u(0x45a196a1, 0xd396e4e4), o.u(0x76ed5bed, 0x2d5b9b9b),
4962// o.u(0x285dc25d, 0xeac27575), o.u(0xc5241c24, 0xd91ce1e1),
4963// o.u(0xd4e9aee9, 0x7aae3d3d), o.u(0xf2be6abe, 0x986a4c4c),
4964// o.u(0x82ee5aee, 0xd85a6c6c), o.u(0xbdc341c3, 0xfc417e7e),
4965// o.u(0xf3060206, 0xf102f5f5), o.u(0x52d14fd1, 0x1d4f8383),
4966// o.u(0x8ce45ce4, 0xd05c6868), o.u(0x5607f407, 0xa2f45151),
4967// o.u(0x8d5c345c, 0xb934d1d1), o.u(0xe1180818, 0xe908f9f9),
4968// o.u(0x4cae93ae, 0xdf93e2e2), o.u(0x3e957395, 0x4d73abab),
4969// o.u(0x97f553f5, 0xc4536262), o.u(0x6b413f41, 0x543f2a2a),
4970// o.u(0x1c140c14, 0x100c0808), o.u(0x63f652f6, 0x31529595),
4971// o.u(0xe9af65af, 0x8c654646), o.u(0x7fe25ee2, 0x215e9d9d),
4972// o.u(0x48782878, 0x60283030), o.u(0xcff8a1f8, 0x6ea13737),
4973// o.u(0x1b110f11, 0x140f0a0a), o.u(0xebc4b5c4, 0x5eb52f2f),
4974// o.u(0x151b091b, 0x1c090e0e), o.u(0x7e5a365a, 0x48362424),
4975// o.u(0xadb69bb6, 0x369b1b1b), o.u(0x98473d47, 0xa53ddfdf),
4976// o.u(0xa76a266a, 0x8126cdcd), o.u(0xf5bb69bb, 0x9c694e4e),
4977// o.u(0x334ccd4c, 0xfecd7f7f), o.u(0x50ba9fba, 0xcf9feaea),
4978// o.u(0x3f2d1b2d, 0x241b1212), o.u(0xa4b99eb9, 0x3a9e1d1d),
4979// o.u(0xc49c749c, 0xb0745858), o.u(0x46722e72, 0x682e3434),
4980// o.u(0x41772d77, 0x6c2d3636), o.u(0x11cdb2cd, 0xa3b2dcdc),
4981// o.u(0x9d29ee29, 0x73eeb4b4), o.u(0x4d16fb16, 0xb6fb5b5b),
4982// o.u(0xa501f601, 0x53f6a4a4), o.u(0xa1d74dd7, 0xec4d7676),
4983// o.u(0x14a361a3, 0x7561b7b7), o.u(0x3449ce49, 0xface7d7d),
4984// o.u(0xdf8d7b8d, 0xa47b5252), o.u(0x9f423e42, 0xa13edddd),
4985// o.u(0xcd937193, 0xbc715e5e), o.u(0xb1a297a2, 0x26971313),
4986// o.u(0xa204f504, 0x57f5a6a6), o.u(0x1b868b8, 0x6968b9b9),
4987// o.u(0x0, 0x0), o.u(0xb5742c74, 0x992cc1c1),
4988// o.u(0xe0a060a0, 0x80604040), o.u(0xc2211f21, 0xdd1fe3e3),
4989// o.u(0x3a43c843, 0xf2c87979), o.u(0x9a2ced2c, 0x77edb6b6),
4990// o.u(0xdd9bed9, 0xb3bed4d4), o.u(0x47ca46ca, 0x1468d8d),
4991// o.u(0x1770d970, 0xced96767), o.u(0xafdd4bdd, 0xe44b7272),
4992// o.u(0xed79de79, 0x33de9494), o.u(0xff67d467, 0x2bd49898),
4993// o.u(0x9323e823, 0x7be8b0b0), o.u(0x5bde4ade, 0x114a8585),
4994// o.u(0x6bd6bbd, 0x6d6bbbbb), o.u(0xbb7e2a7e, 0x912ac5c5),
4995// o.u(0x7b34e534, 0x9ee54f4f), o.u(0xd73a163a, 0xc116eded),
4996// o.u(0xd254c554, 0x17c58686), o.u(0xf862d762, 0x2fd79a9a),
4997// o.u(0x99ff55ff, 0xcc556666), o.u(0xb6a794a7, 0x22941111),
4998// o.u(0xc04acf4a, 0xfcf8a8a), o.u(0xd9301030, 0xc910e9e9),
4999// o.u(0xe0a060a, 0x8060404), o.u(0x66988198, 0xe781fefe),
5000// o.u(0xab0bf00b, 0x5bf0a0a0), o.u(0xb4cc44cc, 0xf0447878),
5001// o.u(0xf0d5bad5, 0x4aba2525), o.u(0x753ee33e, 0x96e34b4b),
5002// o.u(0xac0ef30e, 0x5ff3a2a2), o.u(0x4419fe19, 0xbafe5d5d),
5003// o.u(0xdb5bc05b, 0x1bc08080), o.u(0x80858a85, 0xa8a0505),
5004// o.u(0xd3ecadec, 0x7ead3f3f), o.u(0xfedfbcdf, 0x42bc2121),
5005// o.u(0xa8d848d8, 0xe0487070), o.u(0xfd0c040c, 0xf904f1f1),
5006// o.u(0x197adf7a, 0xc6df6363), o.u(0x2f58c158, 0xeec17777),
5007// o.u(0x309f759f, 0x4575afaf), o.u(0xe7a563a5, 0x84634242),
5008// o.u(0x70503050, 0x40302020), o.u(0xcb2e1a2e, 0xd11ae5e5),
5009// o.u(0xef120e12, 0xe10efdfd), o.u(0x8b76db7, 0x656dbfbf),
5010// o.u(0x55d44cd4, 0x194c8181), o.u(0x243c143c, 0x30141818),
5011// o.u(0x795f355f, 0x4c352626), o.u(0xb2712f71, 0x9d2fc3c3),
5012// o.u(0x8638e138, 0x67e1bebe), o.u(0xc8fda2fd, 0x6aa23535),
5013// o.u(0xc74fcc4f, 0xbcc8888), o.u(0x654b394b, 0x5c392e2e),
5014// o.u(0x6af957f9, 0x3d579393), o.u(0x580df20d, 0xaaf25555),
5015// o.u(0x619d829d, 0xe382fcfc), o.u(0xb3c947c9, 0xf4477a7a),
5016// o.u(0x27efacef, 0x8bacc8c8), o.u(0x8832e732, 0x6fe7baba),
5017// o.u(0x4f7d2b7d, 0x642b3232), o.u(0x42a495a4, 0xd795e6e6),
5018// o.u(0x3bfba0fb, 0x9ba0c0c0), o.u(0xaab398b3, 0x32981919),
5019// o.u(0xf668d168, 0x27d19e9e), o.u(0x22817f81, 0x5d7fa3a3),
5020// o.u(0xeeaa66aa, 0x88664444), o.u(0xd6827e82, 0xa87e5454),
5021// o.u(0xdde6abe6, 0x76ab3b3b), o.u(0x959e839e, 0x16830b0b),
5022// o.u(0xc945ca45, 0x3ca8c8c), o.u(0xbc7b297b, 0x9529c7c7),
5023// o.u(0x56ed36e, 0xd6d36b6b), o.u(0x6c443c44, 0x503c2828),
5024// o.u(0x2c8b798b, 0x5579a7a7), o.u(0x813de23d, 0x63e2bcbc),
5025// o.u(0x31271d27, 0x2c1d1616), o.u(0x379a769a, 0x4176adad),
5026// o.u(0x964d3b4d, 0xad3bdbdb), o.u(0x9efa56fa, 0xc8566464),
5027// o.u(0xa6d24ed2, 0xe84e7474), o.u(0x36221e22, 0x281e1414),
5028// o.u(0xe476db76, 0x3fdb9292), o.u(0x121e0a1e, 0x180a0c0c),
5029// o.u(0xfcb46cb4, 0x906c4848), o.u(0x8f37e437, 0x6be4b8b8),
5030// o.u(0x78e75de7, 0x255d9f9f), o.u(0xfb26eb2, 0x616ebdbd),
5031// o.u(0x692aef2a, 0x86ef4343), o.u(0x35f1a6f1, 0x93a6c4c4),
5032// o.u(0xdae3a8e3, 0x72a83939), o.u(0xc6f7a4f7, 0x62a43131),
5033// o.u(0x8a593759, 0xbd37d3d3), o.u(0x74868b86, 0xff8bf2f2),
5034// o.u(0x83563256, 0xb132d5d5), o.u(0x4ec543c5, 0xd438b8b),
5035// o.u(0x85eb59eb, 0xdc596e6e), o.u(0x18c2b7c2, 0xafb7dada),
5036// o.u(0x8e8f8c8f, 0x28c0101), o.u(0x1dac64ac, 0x7964b1b1),
5037// o.u(0xf16dd26d, 0x23d29c9c), o.u(0x723be03b, 0x92e04949),
5038// o.u(0x1fc7b4c7, 0xabb4d8d8), o.u(0xb915fa15, 0x43faacac),
5039// o.u(0xfa090709, 0xfd07f3f3), o.u(0xa06f256f, 0x8525cfcf),
5040// o.u(0x20eaafea, 0x8fafcaca), o.u(0x7d898e89, 0xf38ef4f4),
5041// o.u(0x6720e920, 0x8ee94747), o.u(0x38281828, 0x20181010),
5042// o.u(0xb64d564, 0xded56f6f), o.u(0x73838883, 0xfb88f0f0),
5043// o.u(0xfbb16fb1, 0x946f4a4a), o.u(0xca967296, 0xb8725c5c),
5044// o.u(0x546c246c, 0x70243838), o.u(0x5f08f108, 0xaef15757),
5045// o.u(0x2152c752, 0xe6c77373), o.u(0x64f351f3, 0x35519797),
5046// o.u(0xae652365, 0x8d23cbcb), o.u(0x25847c84, 0x597ca1a1),
5047// o.u(0x57bf9cbf, 0xcb9ce8e8), o.u(0x5d632163, 0x7c213e3e),
5048// o.u(0xea7cdd7c, 0x37dd9696), o.u(0x1e7fdc7f, 0xc2dc6161),
5049// o.u(0x9c918691, 0x1a860d0d), o.u(0x9b948594, 0x1e850f0f),
5050// o.u(0x4bab90ab, 0xdb90e0e0), o.u(0xbac642c6, 0xf8427c7c),
5051// o.u(0x2657c457, 0xe2c47171), o.u(0x29e5aae5, 0x83aacccc),
5052// o.u(0xe373d873, 0x3bd89090), o.u(0x90f050f, 0xc050606),
5053// o.u(0xf4030103, 0xf501f7f7), o.u(0x2a361236, 0x38121c1c),
5054// o.u(0x3cfea3fe, 0x9fa3c2c2), o.u(0x8be15fe1, 0xd45f6a6a),
5055// o.u(0xbe10f910, 0x47f9aeae), o.u(0x26bd06b, 0xd2d06969),
5056// o.u(0xbfa891a8, 0x2e911717), o.u(0x71e858e8, 0x29589999),
5057// o.u(0x53692769, 0x74273a3a), o.u(0xf7d0b9d0, 0x4eb92727),
5058// o.u(0x91483848, 0xa938d9d9), o.u(0xde351335, 0xcd13ebeb),
5059// o.u(0xe5ceb3ce, 0x56b32b2b), o.u(0x77553355, 0x44332222),
5060// o.u(0x4d6bbd6, 0xbfbbd2d2), o.u(0x39907090, 0x4970a9a9),
5061// o.u(0x87808980, 0xe890707), o.u(0xc1f2a7f2, 0x66a73333),
5062// o.u(0xecc1b6c1, 0x5ab62d2d), o.u(0x5a662266, 0x78223c3c),
5063// o.u(0xb8ad92ad, 0x2a921515), o.u(0xa9602060, 0x8920c9c9),
5064// o.u(0x5cdb49db, 0x15498787), o.u(0xb01aff1a, 0x4fffaaaa),
5065// o.u(0xd8887888, 0xa0785050), o.u(0x2b8e7a8e, 0x517aa5a5),
5066// o.u(0x898a8f8a, 0x68f0303), o.u(0x4a13f813, 0xb2f85959),
5067// o.u(0x929b809b, 0x12800909), o.u(0x23391739, 0x34171a1a),
5068// o.u(0x1075da75, 0xcada6565), o.u(0x84533153, 0xb531d7d7),
5069// o.u(0xd551c651, 0x13c68484), o.u(0x3d3b8d3, 0xbbb8d0d0),
5070// o.u(0xdc5ec35e, 0x1fc38282), o.u(0xe2cbb0cb, 0x52b02929),
5071// o.u(0xc3997799, 0xb4775a5a), o.u(0x2d331133, 0x3c111e1e),
5072// o.u(0x3d46cb46, 0xf6cb7b7b), o.u(0xb71ffc1f, 0x4bfca8a8),
5073// o.u(0xc61d661, 0xdad66d6d), o.u(0x624e3a4e, 0x583a2c2c)
5074// ];
5075
5076var B64 = function(n, x) {
5077 if (n === 7) {
5078 return x.lo & 0xFF;
5079 }
5080 var bits = (7 - n) * 8;
5081 if (bits >= 32) { //faster than >= 32
5082 return (x.hi >>> (bits - 32)) & 0xFF;
5083 }
5084 else {
5085 var bitsOff32 = 32 - bits,
5086 toMoveDown = this.hi << bitsOff32 >>> bitsOff32;
5087 return (x.lo >>> bits | (toMoveDown << bitsOff32)) & 0xFF;
5088 }
5089}
5090
5091var j64 = [o.u(0, 0), o.u(0, 0x10), o.u(0, 0x20), o.u(0, 0x30), o.u(0, 0x40), o.u(0, 0x50), o.u(0, 0x60),
5092 o.u(0, 0x70), o.u(0, 0x80), o.u(0, 0x90), o.u(0, 0xA0), o.u(0, 0xB0), o.u(0, 0xC0),
5093 o.u(0, 0xD0), o.u(0, 0xE0), o.u(0, 0xF0)
5094];
5095
5096var nj64 = [o.u(0xFFFFFFFF, 0xFFFFFFFF), o.u(0xFFFFFFFF, 0xFFFFFFEF), o.u(0xFFFFFFFF, 0xFFFFFFDF), o.u(0xFFFFFFFF, 0xFFFFFFCF), o.u(0xFFFFFFFF, 0xFFFFFFBF), o.u(0xFFFFFFFF, 0xFFFFFFAF), o.u(0xFFFFFFFF, 0xFFFFFF9F),
5097 o.u(0xFFFFFFFF, 0xFFFFFF8F), o.u(0xFFFFFFFF, 0xFFFFFF7F), o.u(0xFFFFFFFF, 0xFFFFFF6F), o.u(0xFFFFFFFF, 0xFFFFFF5F), o.u(0xFFFFFFFF, 0xFFFFFF4F), o.u(0xFFFFFFFF, 0xFFFFFF3F),
5098 o.u(0xFFFFFFFF, 0xFFFFFF2F), o.u(0xFFFFFFFF, 0xFFFFFF1F), o.u(0xFFFFFFFF, 0xFFFFFF0F)
5099];
5100
5101var r64 = [o.u(0, 0), o.u(0, 1), o.u(0, 2), o.u(0, 3), o.u(0, 4), o.u(0, 5), o.u(0, 6), o.u(0, 7),
5102 o.u(0, 8), o.u(0, 9), o.u(0, 10), o.u(0, 11), o.u(0, 12), o.u(0, 13)
5103];
5104
5105var compress = function(int64buf, state) {
5106 var g = new Array(16);
5107 var m = new Array(16);
5108 for (var u = 0; u < 16; u++) {
5109 m[u] = int64buf[u];
5110 g[u] = m[u].xor(state[u]);
5111 }
5112 var t = new Array(16);
5113 for (var r = 0; r < 14; r++) {
5114 for (var i = 0; i < 16; i++) {
5115 g[i].setxor64(j64[i].plus(r64[r]).setShiftLeft(56));
5116 }
5117
5118 for (var u = 0; u < 16; u++) {
5119 t[u] = o.xor64(T0[B64(0, g[u])], T1[B64(1, g[(u + 1) & 0xF])], T2[B64(2, g[(u + 2) & 0xF])], T3[B64(3, g[(u + 3) & 0xF])], T4[B64(4, g[(u + 4) & 0xF])], T5[B64(5, g[(u + 5) & 0xF])], T6[B64(6, g[(u + 6) & 0xF])], T7[B64(7, g[(u + 11) & 0xF])]);
5120 }
5121 var temp = g;
5122 g = t;
5123 t = temp;
5124 }
5125 for (var r = 0; r < 14; r++) {
5126 for (var i = 0; i < 16; i++) {
5127 m[i].setxor64(r64[r], nj64[i]);
5128 }
5129 for (var u = 0; u < 16; u++) {
5130 t[u] = o.xor64(T0[B64(0, m[(u + 1) & 0xF])], T1[B64(1, m[(u + 3) & 0xF])], T2[B64(2, m[(u + 5) & 0xF])], T3[B64(3, m[(u + 11) & 0xF])], T4[B64(4, m[(u + 0) & 0xF])], T5[B64(5, m[(u + 2) & 0xF])], T6[B64(6, m[(u + 4) & 0xF])], T7[B64(7, m[(u + 6) & 0xF])]);
5131 }
5132 var temp = m;
5133 m = t;
5134 t = temp;
5135 }
5136 for (var u = 0; u < 16; u++) {
5137 state[u].setxor64(g[u], m[u]);
5138 }
5139}
5140
5141var final = function(state) {
5142 var g = new Array(16);
5143 o.bufferInsert64(g, 0, state, 16);
5144 var t = new Array(16);
5145 for (var r = 0; r < 14; r++) {
5146
5147 for (var i = 0; i < 16; i++) {
5148 g[i].setxor64(j64[i].plus(r64[r]).setShiftLeft(56));
5149 }
5150
5151 for (var u = 0; u < 16; u++) {
5152 t[u] = o.xor64(T0[B64(0, g[u])], T1[B64(1, g[(u + 1) & 0xF])], T2[B64(2, g[(u + 2) & 0xF])], T3[B64(3, g[(u + 3) & 0xF])], T4[B64(4, g[(u + 4) & 0xF])], T5[B64(5, g[(u + 5) & 0xF])], T6[B64(6, g[(u + 6) & 0xF])], T7[B64(7, g[(u + 11) & 0xF])]);
5153 }
5154 var temp = g;
5155 g = t;
5156 t = temp;
5157 }
5158 for (var u = 0; u < 16; u++)
5159 state[u].setxor64(g[u]);
5160}
5161
5162var groestl = function(ctx, data, len) {
5163 var buf, ptr;
5164 //create a local copy of states
5165 var V = new Array(16);
5166 buf = ctx.buffer;
5167 ptr = ctx.ptr;
5168 if (len < ctx.buffer.length - ptr) {
5169 o.bufferInsert(buf, ptr, data, data.length);
5170 ptr += data.length;
5171 ctx.ptr = ptr;
5172 return;
5173 }
5174 //perform a deep copy of current state
5175 o.bufferInsert(V, 0, ctx.state, 16);
5176 while (len > 0) {
5177 var clen = ctx.buffer.length - ptr;
5178 if (clen > len) clen = len;
5179 o.bufferInsert(buf, ptr, data, clen);
5180 ptr += clen;
5181 data = data.slice(clen);
5182 len -= clen;
5183 if (ptr === ctx.buffer.length) {
5184 var int64Buf = h.bytes2Int64Buffer(buf);
5185 compress(int64Buf, V);
5186 ctx.count.addOne();
5187 ptr = 0;
5188 }
5189 }
5190 ctx.state = V;
5191 ctx.ptr = ptr;
5192}
5193
5194var groestlClose = function(ctx) {
5195 var buf = ctx.buffer;
5196 var ptr = ctx.ptr;
5197 var pad = new Array(136);
5198 var len = buf.length;
5199 var padLen;
5200 var count;
5201 pad[0] = 0x80;
5202 if (ptr < 120) {
5203 padLen = 128 - ptr;
5204 count = ctx.count.plus(o.u(0, 1));
5205 }
5206 else {
5207 padLen = 256 - ptr;
5208 count = ctx.count.plus(o.u(0, 2));
5209 }
5210 o.bufferSet(pad, 1, 0, padLen - 9);
5211 h.bufferEncode64(pad, padLen - 8, count);
5212 groestl(ctx, pad, padLen);
5213 final(ctx.state);
5214 var out = new Array(16);
5215 for (var u = 0, v = 8; u < 8; u++, v++) {
5216 out[2 * u] = ctx.state[v].hi;
5217 out[2 * u + 1] = ctx.state[v].lo;
5218 }
5219 return out;
5220}
5221
5222module.exports = function(input, format, output) {
5223 var msg;
5224 if (format === 1) {
5225 msg = input;
5226 }
5227 else if (format === 2) {
5228 msg = h.int32Buffer2Bytes(input);
5229 }
5230 else {
5231 msg = h.string2bytes(input);
5232 }
5233 var ctx = {};
5234 ctx.state = new Array(16);
5235 for (var i = 0; i < 15; i++) {
5236 ctx.state[i] = new o.u64(0, 0);
5237 }
5238 ctx.state[15] = new o.u64(0, 512);
5239 ctx.ptr = 0;
5240 ctx.count = new o.u64(0,0);
5241 ctx.buffer = new Array(128);
5242 groestl(ctx, msg, msg.length);
5243 var r = groestlClose(ctx, 0, 0);
5244 var out;
5245 if (output === 2) {
5246 out = r;
5247 }
5248 else if (output === 1) {
5249 out = h.int32Buffer2Bytes(r)
5250 }
5251 else {
5252 out = h.int32ArrayToHexString(r)
5253 }
5254 return out;
5255}
5256},{"./helper":41,"./op":42}],41:[function(require,module,exports){
5257'use strict';
5258// String functions
5259
5260var op = require('./op.js');
5261
5262module.exports.int8ArrayToHexString = function toString(array) {
5263 var string = '';
5264
5265 for (var i = 0; i < array.length; i++) {
5266 if (array[i] < 16) {
5267 string += '0' + array[i].toString(16);
5268 }
5269 else {
5270 string += array[i].toString(16);
5271 }
5272 }
5273 return string;
5274}
5275
5276module.exports.int32ArrayToHexString = function toString(array) {
5277 var string = '';
5278 var len = array.length;
5279 for (var i = 0; i < len; i++) {
5280 var s = array[i];
5281 if (s < 0) {
5282 s = 0xFFFFFFFF + array[i] + 1;
5283 }
5284 var l = s.toString(16);
5285 var padding = 8;
5286 while (l.length < padding) {
5287 l = "0" + l;
5288 }
5289 string += l;
5290 }
5291 return string;
5292}
5293
5294module.exports.hex2string = function toString(s) {
5295 for (var c = [], len = s.length, i = 0; i < len; i += 2)
5296 c.push(String.fromCharCode(parseInt(s.substring(i, i + 2), 16)));
5297 return c.join('');
5298}
5299
5300module.exports.hex2bytes = function toString(s) {
5301 for (var c = [], len = s.length, i = 0; i < len; i += 2)
5302 c.push(parseInt(s.substring(i, i + 2), 16));
5303 return c;
5304}
5305/*
5306module.exports.string2hex = function toString(s) {
5307
5308 for (var p = [], len = s.length, i = 0; i < len; i++) {
5309 p.push((256 + s.charCodeAt(i)).toString(16).substring(1));
5310 }
5311 return p.join('');
5312}
5313*/
5314module.exports.string2bytes = function(s) {
5315 var len = s.length;
5316 var b = new Array(len);
5317 var i = 0;
5318 while (i < len) {
5319 b[i] = s.charCodeAt(i);
5320 i++;
5321 }
5322 return b;
5323}
5324/*
5325module.exports.bytes2Int16Buffer = function(b) {
5326 var len = b.length;
5327 var bufferLength = len ? (((len - 1) >>> 1) + 1) : 0;
5328 var buffer = new Array(bufferLength);
5329 var i = 0;
5330 var j = 0;
5331 while (i < len) {
5332 buffer[j] = (buffer[j] << 8) | b[i];
5333 i++;
5334 if (!(i % 2)) j++;
5335 }
5336 return buffer;
5337}
5338*/
5339
5340module.exports.bytes2Int32Buffer = function(b) {
5341 if (!b) return [];
5342 var len = b.length ? (((b.length - 1) >>> 2) + 1) : 0;
5343 var buffer = new Array(len);
5344 var j = 0;
5345 while (j < len) {
5346 buffer[j] = (b[j * 4] << 24) | (b[j * 4 + 1] << 16) | (b[j * 4 + 2] << 8) | b[j * 4 + 3];
5347 j++;
5348 }
5349 return buffer;
5350}
5351/*
5352module.exports.bytes2Int32BufferLeAligned = function(b) {
5353 var len = b.length;
5354 if (!len) return [];
5355 var len2 = len ? (((len - 1) >>> 2) + 1) : 0;
5356 var buffer = new Array(len);
5357 var j = 0;
5358 while (j < len2) {
5359 buffer[j] = (b[j * 4 + 3] << 24) | (b[j * 4 + 2] << 16) | (b[j * 4 + 1] << 8) | b[j * 4];
5360 j++;
5361 };
5362 return buffer;
5363}
5364*/
5365module.exports.bytes2Int64Buffer = function(b) {
5366 if (!b) return [];
5367 var len = b.length ? (((b.length - 1) >>> 3) + 1) : 0;
5368 var buffer = new Array(len);
5369 var j = 0;
5370 while (j < len) {
5371 buffer[j] = new op.u64((b[j * 8] << 24) | (b[j * 8 + 1] << 16) | (b[j * 8 + 2] << 8) | b[j * 8 + 3], (b[j * 8 + 4] << 24) | (b[j * 8 + 5] << 16) | (b[j * 8 + 6] << 8) | b[j * 8 + 7]);
5372 j++;
5373 }
5374 return buffer;
5375}
5376
5377module.exports.bytes2Int64BufferLeAligned = function(b) {
5378 if (!b) return [];
5379 var len = b.length ? ((( b.length - 1) >>> 3) + 1) : 0;
5380 var buffer = new Array(len);
5381 var j = 0;
5382 while (j < len) {
5383 buffer[j] = new op.u64((b[j * 8 + 7] << 24) | (b[j * 8 + 6] << 16) | (b[j * 8 + 5] << 8) | b[j * 8 + 4], (b[j * 8 + 3] << 24) | (b[j * 8 + 2] << 16) | (b[j * 8 + 1] << 8) | b[j * 8]);
5384 j++;
5385 }
5386 return buffer;
5387}
5388
5389module.exports.bufferEncode64leAligned = function(buffer, offset, uint64) {
5390 buffer[offset + 7] = uint64.hi >>> 24;
5391 buffer[offset + 6] = uint64.hi >>> 16 & 0xFF;
5392 buffer[offset + 5] = uint64.hi >>> 8 & 0xFF;
5393 buffer[offset + 4] = uint64.hi & 0xFF;
5394 buffer[offset + 3] = uint64.lo >>> 24;
5395 buffer[offset + 2] = uint64.lo >>> 16 & 0xFF;
5396 buffer[offset + 1] = uint64.lo >>> 8 & 0xFF;
5397 buffer[offset + 0] = uint64.lo & 0xFF;
5398}
5399
5400module.exports.bufferEncode64 = function(buffer, offset, uint64) {
5401 buffer[offset] = uint64.hi >>> 24;
5402 buffer[offset + 1] = uint64.hi >>> 16 & 0xFF;
5403 buffer[offset + 2] = uint64.hi >>> 8 & 0xFF;
5404 buffer[offset + 3] = uint64.hi & 0xFF;
5405 buffer[offset + 4] = uint64.lo >>> 24;
5406 buffer[offset + 5] = uint64.lo >>> 16 & 0xFF;
5407 buffer[offset + 6] = uint64.lo >>> 8 & 0xFF;
5408 buffer[offset + 7] = uint64.lo & 0xFF;
5409}
5410
5411module.exports.int32Buffer2Bytes = function(b) {
5412 var buffer = new Array(b.length);
5413 var len = b.length;
5414 var i = 0;
5415 while (i < len) {
5416 buffer[i * 4] = (b[i] & 0xFF000000) >>> 24;
5417 buffer[i * 4 + 1] = (b[i] & 0x00FF0000) >>> 16;
5418 buffer[i * 4 + 2] = (b[i] & 0x0000FF00) >>> 8;
5419 buffer[i * 4 + 3] = (b[i] & 0x000000FF);
5420 i++;
5421 }
5422 return buffer;
5423}
5424/*
5425module.exports.int64Buffer2Bytes = function(b) {
5426 var buffer = new Array(b.length);
5427 var i = 0;
5428 while (i < b.length) {
5429 buffer[i * 8] = (b[i].hi & 0xFF000000) >>> 24;
5430 buffer[i * 8 + 1] = (b[i].hi & 0x00FF0000) >>> 16;
5431 buffer[i * 8 + 2] = (b[i].hi & 0x0000FF00) >>> 8;
5432 buffer[i * 8 + 3] = (b[i].hi & 0x000000FF);
5433 buffer[i * 8 + 4] = (b[i].lo & 0xFF000000) >>> 24;
5434 buffer[i * 8 + 5] = (b[i].lo & 0x00FF0000) >>> 16;
5435 buffer[i * 8 + 6] = (b[i].lo & 0x0000FF00) >>> 8;
5436 buffer[i * 8 + 7] = (b[i].lo & 0x000000FF);
5437 i++;
5438 }
5439 return buffer;
5440}
5441*/
5442
5443module.exports.string2Int32Buffer = function(s) {
5444 return this.bytes2Int32Buffer(this.string2bytes(s));
5445}
5446
5447var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
5448
5449module.exports.b64Encode = function(input) {
5450 var output = "";
5451 var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
5452 var i = 0;
5453
5454 while (i < input.length) {
5455
5456 chr1 = input[i++];
5457 chr2 = input[i++];
5458 chr3 = input[i++];
5459
5460 enc1 = chr1 >> 2;
5461 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
5462 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
5463 enc4 = chr3 & 63;
5464
5465 if (isNaN(chr2)) {
5466 enc3 = enc4 = 64;
5467 }
5468 else if (isNaN(chr3)) {
5469 enc4 = 64;
5470 }
5471
5472 output +=
5473 keyStr.charAt(enc1) + keyStr.charAt(enc2) +
5474 keyStr.charAt(enc3) + keyStr.charAt(enc4);
5475 }
5476
5477 return output;
5478};
5479
5480module.exports.b64Decode = function(input) {
5481 var output = [];
5482 var chr1, chr2, chr3;
5483 var enc1, enc2, enc3, enc4;
5484 var i = 0;
5485
5486 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
5487
5488 while (i < input.length) {
5489
5490 enc1 = keyStr.indexOf(input.charAt(i++));
5491 enc2 = keyStr.indexOf(input.charAt(i++));
5492 enc3 = keyStr.indexOf(input.charAt(i++));
5493 enc4 = keyStr.indexOf(input.charAt(i++));
5494
5495 chr1 = (enc1 << 2) | (enc2 >> 4);
5496 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
5497 chr3 = ((enc3 & 3) << 6) | enc4;
5498
5499 output.push(chr1);
5500
5501 if (enc3 != 64) {
5502 output.push(chr2);
5503 }
5504 if (enc4 != 64) {
5505 output.push(chr3);
5506 }
5507 }
5508 return output;
5509};
5510},{"./op.js":42}],42:[function(require,module,exports){
5511'use strict';
5512//the right shift is important, it has to do with 32 bit operations in javascript, it will make things faster
5513function u64(h, l) {
5514 this.hi = h >>> 0;
5515 this.lo = l >>> 0;
5516}
5517
5518u64.prototype.set = function(oWord) {
5519 this.lo = oWord.lo;
5520 this.hi = oWord.hi;
5521}
5522
5523u64.prototype.add = function(oWord) {
5524 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5525
5526 //need to add the respective parts from each number and the carry if on is present..
5527 lowest = (this.lo & 0XFFFF) + (oWord.lo & 0XFFFF);
5528 lowMid = (this.lo >>> 16) + (oWord.lo >>> 16) + (lowest >>> 16);
5529 highMid = (this.hi & 0XFFFF) + (oWord.hi & 0XFFFF) + (lowMid >>> 16);
5530 highest = (this.hi >>> 16) + (oWord.hi >>> 16) + (highMid >>> 16);
5531
5532 //now set the hgih and the low accordingly..
5533 this.lo = (lowMid << 16) | (lowest & 0XFFFF);
5534 this.hi = (highest << 16) | (highMid & 0XFFFF);
5535
5536 return this; //for chaining..
5537};
5538
5539u64.prototype.addOne = function() {
5540 if (this.lo === -1 || this.lo === 0xFFFFFFFF) {
5541 this.lo = 0;
5542 this.hi++;
5543 }
5544 else {
5545 this.lo++;
5546 }
5547}
5548
5549u64.prototype.plus = function(oWord) {
5550 var c = new u64(0, 0);
5551 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5552
5553 //need to add the respective parts from each number and the carry if on is present..
5554 lowest = (this.lo & 0XFFFF) + (oWord.lo & 0XFFFF);
5555 lowMid = (this.lo >>> 16) + (oWord.lo >>> 16) + (lowest >>> 16);
5556 highMid = (this.hi & 0XFFFF) + (oWord.hi & 0XFFFF) + (lowMid >>> 16);
5557 highest = (this.hi >>> 16) + (oWord.hi >>> 16) + (highMid >>> 16);
5558
5559 //now set the hgih and the low accordingly..
5560 c.lo = (lowMid << 16) | (lowest & 0XFFFF);
5561 c.hi = (highest << 16) | (highMid & 0XFFFF);
5562
5563 return c; //for chaining..
5564};
5565
5566u64.prototype.not = function() {
5567 return new u64(~this.hi, ~this.lo);
5568}
5569
5570u64.prototype.one = function() {
5571 return new u64(0x0, 0x1);
5572}
5573
5574u64.prototype.zero = function() {
5575 return new u64(0x0, 0x0);
5576}
5577
5578u64.prototype.neg = function() {
5579 return this.not().plus(this.one());
5580}
5581
5582u64.prototype.minus = function(oWord) {
5583 return this.plus(oWord.neg());
5584};
5585
5586u64.prototype.isZero = function() {
5587 return (this.lo === 0) && (this.hi === 0);
5588}
5589
5590function isLong(obj) {
5591 return (obj && obj["__isLong__"]) === true;
5592}
5593
5594function fromNumber(value) {
5595 if (isNaN(value) || !isFinite(value))
5596 return this.zero();
5597 var pow32 = (1 << 32);
5598 return new u64((value % pow32) | 0, (value / pow32) | 0);
5599}
5600
5601u64.prototype.multiply = function(multiplier) {
5602 if (this.isZero())
5603 return this.zero();
5604 if (!isLong(multiplier))
5605 multiplier = fromNumber(multiplier);
5606 if (multiplier.isZero())
5607 return this.zero();
5608
5609 // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
5610 // We can skip products that would overflow.
5611
5612 var a48 = this.hi >>> 16;
5613 var a32 = this.hi & 0xFFFF;
5614 var a16 = this.lo >>> 16;
5615 var a00 = this.lo & 0xFFFF;
5616
5617 var b48 = multiplier.hi >>> 16;
5618 var b32 = multiplier.hi & 0xFFFF;
5619 var b16 = multiplier.lo >>> 16;
5620 var b00 = multiplier.lo & 0xFFFF;
5621
5622 var c48 = 0,
5623 c32 = 0,
5624 c16 = 0,
5625 c00 = 0;
5626 c00 += a00 * b00;
5627 c16 += c00 >>> 16;
5628 c00 &= 0xFFFF;
5629 c16 += a16 * b00;
5630 c32 += c16 >>> 16;
5631 c16 &= 0xFFFF;
5632 c16 += a00 * b16;
5633 c32 += c16 >>> 16;
5634 c16 &= 0xFFFF;
5635 c32 += a32 * b00;
5636 c48 += c32 >>> 16;
5637 c32 &= 0xFFFF;
5638 c32 += a16 * b16;
5639 c48 += c32 >>> 16;
5640 c32 &= 0xFFFF;
5641 c32 += a00 * b32;
5642 c48 += c32 >>> 16;
5643 c32 &= 0xFFFF;
5644 c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
5645 c48 &= 0xFFFF;
5646 return new u64((c48 << 16) | c32, (c16 << 16) | c00);
5647};
5648
5649u64.prototype.shiftLeft = function(bits) {
5650 bits = bits % 64;
5651 var c = new u64(0, 0);
5652 if (bits === 0) {
5653 return this.clone();
5654 }
5655 else if (bits > 31) {
5656 c.lo = 0;
5657 c.hi = this.lo << (bits - 32);
5658 }
5659 else {
5660 var toMoveUp = this.lo >>> 32 - bits;
5661 c.lo = this.lo << bits;
5662 c.hi = (this.hi << bits) | toMoveUp;
5663 }
5664 return c; //for chaining..
5665};
5666
5667u64.prototype.setShiftLeft = function(bits) {
5668 if (bits === 0) {
5669 return this;
5670 }
5671 if (bits > 63) {
5672 bits = bits % 64;
5673 }
5674
5675 if (bits > 31) {
5676 this.hi = this.lo << (bits - 32);
5677 this.lo = 0;
5678 }
5679 else {
5680 var toMoveUp = this.lo >>> 32 - bits;
5681 this.lo <<= bits;
5682 this.hi = (this.hi << bits) | toMoveUp;
5683 }
5684 return this; //for chaining..
5685};
5686//Shifts this word by the given number of bits to the right (max 32)..
5687u64.prototype.shiftRight = function(bits) {
5688 bits = bits % 64;
5689 var c = new u64(0, 0);
5690 if (bits === 0) {
5691 return this.clone();
5692 }
5693 else if (bits >= 32) {
5694 c.hi = 0;
5695 c.lo = this.hi >>> (bits - 32);
5696 }
5697 else {
5698 var bitsOff32 = 32 - bits,
5699 toMoveDown = this.hi << bitsOff32 >>> bitsOff32;
5700 c.hi = this.hi >>> bits;
5701 c.lo = this.lo >>> bits | (toMoveDown << bitsOff32);
5702 }
5703 return c; //for chaining..
5704};
5705//Rotates the bits of this word round to the left (max 32)..
5706u64.prototype.rotateLeft = function(bits) {
5707 if (bits > 32) {
5708 return this.rotateRight(64 - bits);
5709 }
5710 var c = new u64(0, 0);
5711 if (bits === 0) {
5712 c.lo = this.lo >>> 0;
5713 c.hi = this.hi >>> 0;
5714 }
5715 else if (bits === 32) { //just switch high and low over in this case..
5716 c.lo = this.hi;
5717 c.hi = this.lo;
5718 }
5719 else {
5720 c.lo = (this.lo << bits) | (this.hi >>> (32 - bits));
5721 c.hi = (this.hi << bits) | (this.lo >>> (32 - bits));
5722 }
5723 return c; //for chaining..
5724};
5725
5726u64.prototype.setRotateLeft = function(bits) {
5727 if (bits > 32) {
5728 return this.setRotateRight(64 - bits);
5729 }
5730 var newHigh;
5731 if (bits === 0) {
5732 return this;
5733 }
5734 else if (bits === 32) { //just switch high and low over in this case..
5735 newHigh = this.lo;
5736 this.lo = this.hi;
5737 this.hi = newHigh;
5738 }
5739 else {
5740 newHigh = (this.hi << bits) | (this.lo >>> (32 - bits));
5741 this.lo = (this.lo << bits) | (this.hi >>> (32 - bits));
5742 this.hi = newHigh;
5743 }
5744 return this; //for chaining..
5745};
5746//Rotates the bits of this word round to the right (max 32)..
5747u64.prototype.rotateRight = function(bits) {
5748 if (bits > 32) {
5749 return this.rotateLeft(64 - bits);
5750 }
5751 var c = new u64(0, 0);
5752 if (bits === 0) {
5753 c.lo = this.lo >>> 0;
5754 c.hi = this.hi >>> 0;
5755 }
5756 else if (bits === 32) { //just switch high and low over in this case..
5757 c.lo = this.hi;
5758 c.hi = this.lo;
5759 }
5760 else {
5761 c.lo = (this.hi << (32 - bits)) | (this.lo >>> bits);
5762 c.hi = (this.lo << (32 - bits)) | (this.hi >>> bits);
5763 }
5764 return c; //for chaining..
5765};
5766u64.prototype.setFlip = function() {
5767 var newHigh;
5768 newHigh = this.lo;
5769 this.lo = this.hi;
5770 this.hi = newHigh;
5771 return this;
5772};
5773//Rotates the bits of this word round to the right (max 32)..
5774u64.prototype.setRotateRight = function(bits) {
5775 if (bits > 32) {
5776 return this.setRotateLeft(64 - bits);
5777 }
5778
5779 if (bits === 0) {
5780 return this;
5781 }
5782 else if (bits === 32) { //just switch high and low over in this case..
5783 var newHigh;
5784 newHigh = this.lo;
5785 this.lo = this.hi;
5786 this.hi = newHigh;
5787 }
5788 else {
5789 newHigh = (this.lo << (32 - bits)) | (this.hi >>> bits);
5790 this.lo = (this.hi << (32 - bits)) | (this.lo >>> bits);
5791 this.hi = newHigh;
5792 }
5793 return this; //for chaining..
5794};
5795//Xors this word with the given other..
5796u64.prototype.xor = function(oWord) {
5797 var c = new u64(0, 0);
5798 c.hi = this.hi ^ oWord.hi;
5799 c.lo = this.lo ^ oWord.lo;
5800 return c; //for chaining..
5801};
5802//Xors this word with the given other..
5803u64.prototype.setxorOne = function(oWord) {
5804 this.hi ^= oWord.hi;
5805 this.lo ^= oWord.lo;
5806 return this; //for chaining..
5807};
5808//Ands this word with the given other..
5809u64.prototype.and = function(oWord) {
5810 var c = new u64(0, 0);
5811 c.hi = this.hi & oWord.hi;
5812 c.lo = this.lo & oWord.lo;
5813 return c; //for chaining..
5814};
5815
5816//Creates a deep copy of this Word..
5817u64.prototype.clone = function() {
5818 return new u64(this.hi, this.lo);
5819};
5820
5821u64.prototype.setxor64 = function() {
5822 var a = arguments;
5823 var i = a.length;
5824 while (i--) {
5825 this.hi ^= a[i].hi;
5826 this.lo ^= a[i].lo;
5827 }
5828 return this;
5829}
5830
5831module.exports.u64 = u64;
5832
5833module.exports.u = function(h, l) {
5834 return new u64(h, l);
5835}
5836/*
5837module.exports.add64 = function(a, b) {
5838 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5839
5840 //need to add the respective parts from each number and the carry if on is present..
5841 lowest = (a.lo & 0XFFFF) + (b.lo & 0XFFFF);
5842 lowMid = (a.lo >>> 16) + (b.lo >>> 16) + (lowest >>> 16);
5843 highMid = (a.hi & 0XFFFF) + (b.hi & 0XFFFF) + (lowMid >>> 16);
5844 highest = (a.hi >>> 16) + (b.hi >>> 16) + (highMid >>> 16);
5845
5846 var r = new this.u64((highest << 16) | (highMid & 0XFFFF), (lowMid << 16) | (lowest & 0XFFFF));
5847
5848 return r;
5849};
5850*/
5851module.exports.xor64 = function() {
5852 var a = arguments,
5853 h = a[0].hi,
5854 l = a[0].lo;
5855 var i = a.length-1;
5856 do {
5857 h ^= a[i].hi;
5858 l ^= a[i].lo;
5859 i--;
5860 } while (i>0);
5861 return new this.u64(h, l);
5862}
5863
5864module.exports.clone64Array = function(array) {
5865 var i = 0;
5866 var len = array.length;
5867 var a = new Array(len);
5868 while(i<len) {
5869 a[i] = array[i];
5870 i++;
5871 }
5872 return a;
5873}
5874
5875//this shouldn't be a problem, but who knows in the future javascript might support 64bits
5876module.exports.t32 = function(x) {
5877 return (x & 0xFFFFFFFF)
5878}
5879
5880module.exports.rotl32 = function(x, c) {
5881 return (((x) << (c)) | ((x) >>> (32 - (c)))) & (0xFFFFFFFF);
5882}
5883
5884module.exports.rotr32 = function(x, c) {
5885 return this.rotl32(x, (32 - (c)));
5886}
5887
5888module.exports.swap32 = function(val) {
5889 return ((val & 0xFF) << 24) |
5890 ((val & 0xFF00) << 8) |
5891 ((val >>> 8) & 0xFF00) |
5892 ((val >>> 24) & 0xFF);
5893}
5894
5895module.exports.swap32Array = function(a) {
5896 //can't do this with map because of support for IE8 (Don't hate me plz).
5897 var i = 0, len = a.length;
5898 var r = new Array(i);
5899 while (i<len) {
5900 r[i] = (this.swap32(a[i]));
5901 i++;
5902 }
5903 return r;
5904}
5905
5906module.exports.xnd64 = function(x, y, z) {
5907 return new this.u64(x.hi ^ ((~y.hi) & z.hi), x.lo ^ ((~y.lo) & z.lo));
5908}
5909/*
5910module.exports.load64 = function(x, i) {
5911 var l = x[i] | (x[i + 1] << 8) | (x[i + 2] << 16) | (x[i + 3] << 24);
5912 var h = x[i + 4] | (x[i + 5] << 8) | (x[i + 6] << 16) | (x[i + 7] << 24);
5913 return new this.u64(h, l);
5914}
5915*/
5916module.exports.bufferInsert = function(buffer, bufferOffset, data, len, dataOffset) {
5917 dataOffset = dataOffset | 0;
5918 var i = 0;
5919 while (i < len) {
5920 buffer[i + bufferOffset] = data[i + dataOffset];
5921 i++;
5922 }
5923}
5924
5925module.exports.bufferInsert64 = function(buffer, bufferOffset, data, len) {
5926 var i = 0;
5927 while (i < len) {
5928 buffer[i + bufferOffset] = data[i].clone();
5929 i++;
5930 }
5931}
5932/*
5933module.exports.buffer2Insert = function(buffer, bufferOffset, bufferOffset2, data, len, len2) {
5934 while (len--) {
5935 var j = len2;
5936 while (j--) {
5937 buffer[len + bufferOffset][j + bufferOffset2] = data[len][j];
5938 }
5939 }
5940}
5941*/
5942module.exports.bufferInsertBackwards = function(buffer, bufferOffset, data, len) {
5943 var i = 0;
5944 while (i < len) {
5945 buffer[i + bufferOffset] = data[len - 1 - i];
5946 i++;
5947 }
5948}
5949
5950module.exports.bufferSet = function(buffer, bufferOffset, value, len) {
5951 var i = 0;
5952 while (i < len) {
5953 buffer[i + bufferOffset] = value;
5954 i++;
5955 }
5956}
5957
5958module.exports.bufferXORInsert = function(buffer, bufferOffset, data, dataOffset, len) {
5959 var i = 0;
5960 while (i < len) {
5961 buffer[i + bufferOffset] ^= data[i + dataOffset];
5962 i++;
5963 }
5964}
5965
5966module.exports.xORTable = function(d, s1, s2, len) {
5967 var i = 0;
5968 while (i < len) {
5969 d[i] = s1[i] ^ s2[i];
5970 i++
5971 }
5972}
5973
5974},{}],43:[function(require,module,exports){
5975'use strict'
5976var Buffer = require('safe-buffer').Buffer
5977var Transform = require('stream').Transform
5978var inherits = require('inherits')
5979
5980function throwIfNotStringOrBuffer (val, prefix) {
5981 if (!Buffer.isBuffer(val) && typeof val !== 'string') {
5982 throw new TypeError(prefix + ' must be a string or a buffer')
5983 }
5984}
5985
5986function HashBase (blockSize) {
5987 Transform.call(this)
5988
5989 this._block = Buffer.allocUnsafe(blockSize)
5990 this._blockSize = blockSize
5991 this._blockOffset = 0
5992 this._length = [0, 0, 0, 0]
5993
5994 this._finalized = false
5995}
5996
5997inherits(HashBase, Transform)
5998
5999HashBase.prototype._transform = function (chunk, encoding, callback) {
6000 var error = null
6001 try {
6002 this.update(chunk, encoding)
6003 } catch (err) {
6004 error = err
6005 }
6006
6007 callback(error)
6008}
6009
6010HashBase.prototype._flush = function (callback) {
6011 var error = null
6012 try {
6013 this.push(this.digest())
6014 } catch (err) {
6015 error = err
6016 }
6017
6018 callback(error)
6019}
6020
6021HashBase.prototype.update = function (data, encoding) {
6022 throwIfNotStringOrBuffer(data, 'Data')
6023 if (this._finalized) throw new Error('Digest already called')
6024 if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
6025
6026 // consume data
6027 var block = this._block
6028 var offset = 0
6029 while (this._blockOffset + data.length - offset >= this._blockSize) {
6030 for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
6031 this._update()
6032 this._blockOffset = 0
6033 }
6034 while (offset < data.length) block[this._blockOffset++] = data[offset++]
6035
6036 // update length
6037 for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
6038 this._length[j] += carry
6039 carry = (this._length[j] / 0x0100000000) | 0
6040 if (carry > 0) this._length[j] -= 0x0100000000 * carry
6041 }
6042
6043 return this
6044}
6045
6046HashBase.prototype._update = function () {
6047 throw new Error('_update is not implemented')
6048}
6049
6050HashBase.prototype.digest = function (encoding) {
6051 if (this._finalized) throw new Error('Digest already called')
6052 this._finalized = true
6053
6054 var digest = this._digest()
6055 if (encoding !== undefined) digest = digest.toString(encoding)
6056
6057 // reset state
6058 this._block.fill(0)
6059 this._blockOffset = 0
6060 for (var i = 0; i < 4; ++i) this._length[i] = 0
6061
6062 return digest
6063}
6064
6065HashBase.prototype._digest = function () {
6066 throw new Error('_digest is not implemented')
6067}
6068
6069module.exports = HashBase
6070
6071},{"inherits":44,"safe-buffer":47,"stream":215}],44:[function(require,module,exports){
6072if (typeof Object.create === 'function') {
6073 // implementation from standard node.js 'util' module
6074 module.exports = function inherits(ctor, superCtor) {
6075 if (superCtor) {
6076 ctor.super_ = superCtor
6077 ctor.prototype = Object.create(superCtor.prototype, {
6078 constructor: {
6079 value: ctor,
6080 enumerable: false,
6081 writable: true,
6082 configurable: true
6083 }
6084 })
6085 }
6086 };
6087} else {
6088 // old school shim for old browsers
6089 module.exports = function inherits(ctor, superCtor) {
6090 if (superCtor) {
6091 ctor.super_ = superCtor
6092 var TempCtor = function () {}
6093 TempCtor.prototype = superCtor.prototype
6094 ctor.prototype = new TempCtor()
6095 ctor.prototype.constructor = ctor
6096 }
6097 }
6098}
6099
6100},{}],45:[function(require,module,exports){
6101'use strict'
6102var inherits = require('inherits')
6103var HashBase = require('hash-base')
6104var Buffer = require('safe-buffer').Buffer
6105
6106var ARRAY16 = new Array(16)
6107
6108function MD5 () {
6109 HashBase.call(this, 64)
6110
6111 // state
6112 this._a = 0x67452301
6113 this._b = 0xefcdab89
6114 this._c = 0x98badcfe
6115 this._d = 0x10325476
6116}
6117
6118inherits(MD5, HashBase)
6119
6120MD5.prototype._update = function () {
6121 var M = ARRAY16
6122 for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4)
6123
6124 var a = this._a
6125 var b = this._b
6126 var c = this._c
6127 var d = this._d
6128
6129 a = fnF(a, b, c, d, M[0], 0xd76aa478, 7)
6130 d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12)
6131 c = fnF(c, d, a, b, M[2], 0x242070db, 17)
6132 b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22)
6133 a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7)
6134 d = fnF(d, a, b, c, M[5], 0x4787c62a, 12)
6135 c = fnF(c, d, a, b, M[6], 0xa8304613, 17)
6136 b = fnF(b, c, d, a, M[7], 0xfd469501, 22)
6137 a = fnF(a, b, c, d, M[8], 0x698098d8, 7)
6138 d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12)
6139 c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17)
6140 b = fnF(b, c, d, a, M[11], 0x895cd7be, 22)
6141 a = fnF(a, b, c, d, M[12], 0x6b901122, 7)
6142 d = fnF(d, a, b, c, M[13], 0xfd987193, 12)
6143 c = fnF(c, d, a, b, M[14], 0xa679438e, 17)
6144 b = fnF(b, c, d, a, M[15], 0x49b40821, 22)
6145
6146 a = fnG(a, b, c, d, M[1], 0xf61e2562, 5)
6147 d = fnG(d, a, b, c, M[6], 0xc040b340, 9)
6148 c = fnG(c, d, a, b, M[11], 0x265e5a51, 14)
6149 b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20)
6150 a = fnG(a, b, c, d, M[5], 0xd62f105d, 5)
6151 d = fnG(d, a, b, c, M[10], 0x02441453, 9)
6152 c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14)
6153 b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20)
6154 a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5)
6155 d = fnG(d, a, b, c, M[14], 0xc33707d6, 9)
6156 c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14)
6157 b = fnG(b, c, d, a, M[8], 0x455a14ed, 20)
6158 a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5)
6159 d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9)
6160 c = fnG(c, d, a, b, M[7], 0x676f02d9, 14)
6161 b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20)
6162
6163 a = fnH(a, b, c, d, M[5], 0xfffa3942, 4)
6164 d = fnH(d, a, b, c, M[8], 0x8771f681, 11)
6165 c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16)
6166 b = fnH(b, c, d, a, M[14], 0xfde5380c, 23)
6167 a = fnH(a, b, c, d, M[1], 0xa4beea44, 4)
6168 d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11)
6169 c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16)
6170 b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23)
6171 a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4)
6172 d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11)
6173 c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16)
6174 b = fnH(b, c, d, a, M[6], 0x04881d05, 23)
6175 a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4)
6176 d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11)
6177 c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16)
6178 b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23)
6179
6180 a = fnI(a, b, c, d, M[0], 0xf4292244, 6)
6181 d = fnI(d, a, b, c, M[7], 0x432aff97, 10)
6182 c = fnI(c, d, a, b, M[14], 0xab9423a7, 15)
6183 b = fnI(b, c, d, a, M[5], 0xfc93a039, 21)
6184 a = fnI(a, b, c, d, M[12], 0x655b59c3, 6)
6185 d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10)
6186 c = fnI(c, d, a, b, M[10], 0xffeff47d, 15)
6187 b = fnI(b, c, d, a, M[1], 0x85845dd1, 21)
6188 a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6)
6189 d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10)
6190 c = fnI(c, d, a, b, M[6], 0xa3014314, 15)
6191 b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21)
6192 a = fnI(a, b, c, d, M[4], 0xf7537e82, 6)
6193 d = fnI(d, a, b, c, M[11], 0xbd3af235, 10)
6194 c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15)
6195 b = fnI(b, c, d, a, M[9], 0xeb86d391, 21)
6196
6197 this._a = (this._a + a) | 0
6198 this._b = (this._b + b) | 0
6199 this._c = (this._c + c) | 0
6200 this._d = (this._d + d) | 0
6201}
6202
6203MD5.prototype._digest = function () {
6204 // create padding and handle blocks
6205 this._block[this._blockOffset++] = 0x80
6206 if (this._blockOffset > 56) {
6207 this._block.fill(0, this._blockOffset, 64)
6208 this._update()
6209 this._blockOffset = 0
6210 }
6211
6212 this._block.fill(0, this._blockOffset, 56)
6213 this._block.writeUInt32LE(this._length[0], 56)
6214 this._block.writeUInt32LE(this._length[1], 60)
6215 this._update()
6216
6217 // produce result
6218 var buffer = Buffer.allocUnsafe(16)
6219 buffer.writeInt32LE(this._a, 0)
6220 buffer.writeInt32LE(this._b, 4)
6221 buffer.writeInt32LE(this._c, 8)
6222 buffer.writeInt32LE(this._d, 12)
6223 return buffer
6224}
6225
6226function rotl (x, n) {
6227 return (x << n) | (x >>> (32 - n))
6228}
6229
6230function fnF (a, b, c, d, m, k, s) {
6231 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + b) | 0
6232}
6233
6234function fnG (a, b, c, d, m, k, s) {
6235 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + b) | 0
6236}
6237
6238function fnH (a, b, c, d, m, k, s) {
6239 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + b) | 0
6240}
6241
6242function fnI (a, b, c, d, m, k, s) {
6243 return (rotl((a + ((c ^ (b | (~d)))) + m + k) | 0, s) + b) | 0
6244}
6245
6246module.exports = MD5
6247
6248},{"hash-base":43,"inherits":44,"safe-buffer":47}],46:[function(require,module,exports){
6249'use strict'
6250var Buffer = require('buffer').Buffer
6251var inherits = require('inherits')
6252var HashBase = require('hash-base')
6253
6254var ARRAY16 = new Array(16)
6255
6256var zl = [
6257 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
6258 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
6259 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
6260 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
6261 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
6262]
6263
6264var zr = [
6265 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
6266 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
6267 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
6268 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
6269 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
6270]
6271
6272var sl = [
6273 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
6274 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
6275 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
6276 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
6277 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
6278]
6279
6280var sr = [
6281 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
6282 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
6283 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
6284 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
6285 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
6286]
6287
6288var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]
6289var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]
6290
6291function RIPEMD160 () {
6292 HashBase.call(this, 64)
6293
6294 // state
6295 this._a = 0x67452301
6296 this._b = 0xefcdab89
6297 this._c = 0x98badcfe
6298 this._d = 0x10325476
6299 this._e = 0xc3d2e1f0
6300}
6301
6302inherits(RIPEMD160, HashBase)
6303
6304RIPEMD160.prototype._update = function () {
6305 var words = ARRAY16
6306 for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4)
6307
6308 var al = this._a | 0
6309 var bl = this._b | 0
6310 var cl = this._c | 0
6311 var dl = this._d | 0
6312 var el = this._e | 0
6313
6314 var ar = this._a | 0
6315 var br = this._b | 0
6316 var cr = this._c | 0
6317 var dr = this._d | 0
6318 var er = this._e | 0
6319
6320 // computation
6321 for (var i = 0; i < 80; i += 1) {
6322 var tl
6323 var tr
6324 if (i < 16) {
6325 tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i])
6326 tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i])
6327 } else if (i < 32) {
6328 tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i])
6329 tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i])
6330 } else if (i < 48) {
6331 tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i])
6332 tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i])
6333 } else if (i < 64) {
6334 tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i])
6335 tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i])
6336 } else { // if (i<80) {
6337 tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i])
6338 tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i])
6339 }
6340
6341 al = el
6342 el = dl
6343 dl = rotl(cl, 10)
6344 cl = bl
6345 bl = tl
6346
6347 ar = er
6348 er = dr
6349 dr = rotl(cr, 10)
6350 cr = br
6351 br = tr
6352 }
6353
6354 // update state
6355 var t = (this._b + cl + dr) | 0
6356 this._b = (this._c + dl + er) | 0
6357 this._c = (this._d + el + ar) | 0
6358 this._d = (this._e + al + br) | 0
6359 this._e = (this._a + bl + cr) | 0
6360 this._a = t
6361}
6362
6363RIPEMD160.prototype._digest = function () {
6364 // create padding and handle blocks
6365 this._block[this._blockOffset++] = 0x80
6366 if (this._blockOffset > 56) {
6367 this._block.fill(0, this._blockOffset, 64)
6368 this._update()
6369 this._blockOffset = 0
6370 }
6371
6372 this._block.fill(0, this._blockOffset, 56)
6373 this._block.writeUInt32LE(this._length[0], 56)
6374 this._block.writeUInt32LE(this._length[1], 60)
6375 this._update()
6376
6377 // produce result
6378 var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20)
6379 buffer.writeInt32LE(this._a, 0)
6380 buffer.writeInt32LE(this._b, 4)
6381 buffer.writeInt32LE(this._c, 8)
6382 buffer.writeInt32LE(this._d, 12)
6383 buffer.writeInt32LE(this._e, 16)
6384 return buffer
6385}
6386
6387function rotl (x, n) {
6388 return (x << n) | (x >>> (32 - n))
6389}
6390
6391function fn1 (a, b, c, d, e, m, k, s) {
6392 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0
6393}
6394
6395function fn2 (a, b, c, d, e, m, k, s) {
6396 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0
6397}
6398
6399function fn3 (a, b, c, d, e, m, k, s) {
6400 return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0
6401}
6402
6403function fn4 (a, b, c, d, e, m, k, s) {
6404 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0
6405}
6406
6407function fn5 (a, b, c, d, e, m, k, s) {
6408 return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0
6409}
6410
6411module.exports = RIPEMD160
6412
6413},{"buffer":110,"hash-base":43,"inherits":44}],47:[function(require,module,exports){
6414/* eslint-disable node/no-deprecated-api */
6415var buffer = require('buffer')
6416var Buffer = buffer.Buffer
6417
6418// alternative to using Object.keys for old browsers
6419function copyProps (src, dst) {
6420 for (var key in src) {
6421 dst[key] = src[key]
6422 }
6423}
6424if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
6425 module.exports = buffer
6426} else {
6427 // Copy properties from require('buffer')
6428 copyProps(buffer, exports)
6429 exports.Buffer = SafeBuffer
6430}
6431
6432function SafeBuffer (arg, encodingOrOffset, length) {
6433 return Buffer(arg, encodingOrOffset, length)
6434}
6435
6436SafeBuffer.prototype = Object.create(Buffer.prototype)
6437
6438// Copy static methods from Buffer
6439copyProps(Buffer, SafeBuffer)
6440
6441SafeBuffer.from = function (arg, encodingOrOffset, length) {
6442 if (typeof arg === 'number') {
6443 throw new TypeError('Argument must not be a number')
6444 }
6445 return Buffer(arg, encodingOrOffset, length)
6446}
6447
6448SafeBuffer.alloc = function (size, fill, encoding) {
6449 if (typeof size !== 'number') {
6450 throw new TypeError('Argument must be a number')
6451 }
6452 var buf = Buffer(size)
6453 if (fill !== undefined) {
6454 if (typeof encoding === 'string') {
6455 buf.fill(fill, encoding)
6456 } else {
6457 buf.fill(fill)
6458 }
6459 } else {
6460 buf.fill(0)
6461 }
6462 return buf
6463}
6464
6465SafeBuffer.allocUnsafe = function (size) {
6466 if (typeof size !== 'number') {
6467 throw new TypeError('Argument must be a number')
6468 }
6469 return Buffer(size)
6470}
6471
6472SafeBuffer.allocUnsafeSlow = function (size) {
6473 if (typeof size !== 'number') {
6474 throw new TypeError('Argument must be a number')
6475 }
6476 return buffer.SlowBuffer(size)
6477}
6478
6479},{"buffer":110}],48:[function(require,module,exports){
6480const scrypt = require('./scryptSync')
6481scrypt.async = require('./scrypt')
6482module.exports = scrypt
6483
6484},{"./scrypt":49,"./scryptSync":50}],49:[function(require,module,exports){
6485const crypto = require('crypto')
6486const {
6487 checkAndInit,
6488 smix
6489} = require('./utils')
6490
6491// N = Cpu cost, r = Memory cost, p = parallelization cost
6492async function scrypt (key, salt, N, r, p, dkLen, progressCallback, promiseInterval) {
6493 const {
6494 XY,
6495 V,
6496 B32,
6497 x,
6498 _X,
6499 B,
6500 tickCallback
6501 } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback)
6502
6503 for (var i = 0; i < p; i++) {
6504 await smix(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval)
6505 }
6506
6507 return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256')
6508}
6509
6510module.exports = scrypt
6511
6512},{"./utils":51,"crypto":118}],50:[function(require,module,exports){
6513const crypto = require('crypto')
6514const {
6515 checkAndInit,
6516 smixSync
6517} = require('./utils')
6518
6519// N = Cpu cost, r = Memory cost, p = parallelization cost
6520function scrypt (key, salt, N, r, p, dkLen, progressCallback) {
6521 const {
6522 XY,
6523 V,
6524 B32,
6525 x,
6526 _X,
6527 B,
6528 tickCallback
6529 } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback)
6530
6531 for (var i = 0; i < p; i++) {
6532 smixSync(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback)
6533 }
6534
6535 return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256')
6536}
6537
6538module.exports = scrypt
6539
6540},{"./utils":51,"crypto":118}],51:[function(require,module,exports){
6541(function (Buffer,setImmediate){
6542const crypto = require('crypto')
6543const MAX_VALUE = 0x7fffffff
6544const DEFAULT_PROMISE_INTERVAL = 5000
6545/* eslint-disable camelcase */
6546
6547function checkAndInit (key, salt, N, r, p, dkLen, progressCallback) {
6548 if (N === 0 || (N & (N - 1)) !== 0) throw Error('N must be > 0 and a power of 2')
6549
6550 if (N > MAX_VALUE / 128 / r) throw Error('Parameter N is too large')
6551 if (r > MAX_VALUE / 128 / p) throw Error('Parameter r is too large')
6552
6553 let XY = Buffer.alloc(256 * r)
6554 let V = Buffer.alloc(128 * r * N)
6555
6556 // pseudo global
6557 let B32 = new Int32Array(16) // salsa20_8
6558 let x = new Int32Array(16) // salsa20_8
6559 let _X = Buffer.alloc(64) // blockmix_salsa8
6560
6561 // pseudo global
6562 let B = crypto.pbkdf2Sync(key, salt, 1, p * 128 * r, 'sha256')
6563
6564 let tickCallback
6565 if (progressCallback) {
6566 let totalOps = p * N * 2
6567 let currentOp = 0
6568
6569 tickCallback = function () {
6570 ++currentOp
6571
6572 // send progress notifications once every 1,000 ops
6573 if (currentOp % 1000 === 0) {
6574 progressCallback({
6575 current: currentOp,
6576 total: totalOps,
6577 percent: (currentOp / totalOps) * 100.0
6578 })
6579 }
6580 }
6581 }
6582 return {
6583 XY,
6584 V,
6585 B32,
6586 x,
6587 _X,
6588 B,
6589 tickCallback
6590 }
6591}
6592
6593async function smix (B, Bi, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) {
6594 promiseInterval = promiseInterval || DEFAULT_PROMISE_INTERVAL
6595 let Xi = 0
6596 let Yi = 128 * r
6597 let i
6598
6599 B.copy(XY, Xi, Bi, Bi + Yi)
6600
6601 for (i = 0; i < N; i++) {
6602 XY.copy(V, i * Yi, Xi, Xi + Yi)
6603 if (i % promiseInterval === 0) {
6604 await new Promise(resolve => setImmediate(resolve))
6605 }
6606 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6607
6608 if (tickCallback) tickCallback()
6609 }
6610
6611 for (i = 0; i < N; i++) {
6612 let offset = Xi + (2 * r - 1) * 64
6613 let j = XY.readUInt32LE(offset) & (N - 1)
6614 blockxor(V, j * Yi, XY, Xi, Yi)
6615 if (i % promiseInterval === 0) {
6616 await new Promise(resolve => setImmediate(resolve))
6617 }
6618 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6619
6620 if (tickCallback) tickCallback()
6621 }
6622
6623 XY.copy(B, Bi, Xi, Xi + Yi)
6624}
6625
6626function smixSync (B, Bi, r, N, V, XY, _X, B32, x, tickCallback) {
6627 let Xi = 0
6628 let Yi = 128 * r
6629 let i
6630
6631 B.copy(XY, Xi, Bi, Bi + Yi)
6632
6633 for (i = 0; i < N; i++) {
6634 XY.copy(V, i * Yi, Xi, Xi + Yi)
6635 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6636
6637 if (tickCallback) tickCallback()
6638 }
6639
6640 for (i = 0; i < N; i++) {
6641 let offset = Xi + (2 * r - 1) * 64
6642 let j = XY.readUInt32LE(offset) & (N - 1)
6643 blockxor(V, j * Yi, XY, Xi, Yi)
6644 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6645
6646 if (tickCallback) tickCallback()
6647 }
6648
6649 XY.copy(B, Bi, Xi, Xi + Yi)
6650}
6651
6652function blockmix_salsa8 (BY, Bi, Yi, r, _X, B32, x) {
6653 let i
6654
6655 arraycopy(BY, Bi + (2 * r - 1) * 64, _X, 0, 64)
6656
6657 for (i = 0; i < 2 * r; i++) {
6658 blockxor(BY, i * 64, _X, 0, 64)
6659 salsa20_8(_X, B32, x)
6660 arraycopy(_X, 0, BY, Yi + (i * 64), 64)
6661 }
6662
6663 for (i = 0; i < r; i++) {
6664 arraycopy(BY, Yi + (i * 2) * 64, BY, Bi + (i * 64), 64)
6665 }
6666
6667 for (i = 0; i < r; i++) {
6668 arraycopy(BY, Yi + (i * 2 + 1) * 64, BY, Bi + (i + r) * 64, 64)
6669 }
6670}
6671
6672function R (a, b) {
6673 return (a << b) | (a >>> (32 - b))
6674}
6675
6676function salsa20_8 (B, B32, x) {
6677 let i
6678
6679 for (i = 0; i < 16; i++) {
6680 B32[i] = (B[i * 4 + 0] & 0xff) << 0
6681 B32[i] |= (B[i * 4 + 1] & 0xff) << 8
6682 B32[i] |= (B[i * 4 + 2] & 0xff) << 16
6683 B32[i] |= (B[i * 4 + 3] & 0xff) << 24
6684 // B32[i] = B.readUInt32LE(i*4) <--- this is signficantly slower even in Node.js
6685 }
6686
6687 arraycopy(B32, 0, x, 0, 16)
6688
6689 for (i = 8; i > 0; i -= 2) {
6690 x[4] ^= R(x[0] + x[12], 7)
6691 x[8] ^= R(x[4] + x[0], 9)
6692 x[12] ^= R(x[8] + x[4], 13)
6693 x[0] ^= R(x[12] + x[8], 18)
6694 x[9] ^= R(x[5] + x[1], 7)
6695 x[13] ^= R(x[9] + x[5], 9)
6696 x[1] ^= R(x[13] + x[9], 13)
6697 x[5] ^= R(x[1] + x[13], 18)
6698 x[14] ^= R(x[10] + x[6], 7)
6699 x[2] ^= R(x[14] + x[10], 9)
6700 x[6] ^= R(x[2] + x[14], 13)
6701 x[10] ^= R(x[6] + x[2], 18)
6702 x[3] ^= R(x[15] + x[11], 7)
6703 x[7] ^= R(x[3] + x[15], 9)
6704 x[11] ^= R(x[7] + x[3], 13)
6705 x[15] ^= R(x[11] + x[7], 18)
6706 x[1] ^= R(x[0] + x[3], 7)
6707 x[2] ^= R(x[1] + x[0], 9)
6708 x[3] ^= R(x[2] + x[1], 13)
6709 x[0] ^= R(x[3] + x[2], 18)
6710 x[6] ^= R(x[5] + x[4], 7)
6711 x[7] ^= R(x[6] + x[5], 9)
6712 x[4] ^= R(x[7] + x[6], 13)
6713 x[5] ^= R(x[4] + x[7], 18)
6714 x[11] ^= R(x[10] + x[9], 7)
6715 x[8] ^= R(x[11] + x[10], 9)
6716 x[9] ^= R(x[8] + x[11], 13)
6717 x[10] ^= R(x[9] + x[8], 18)
6718 x[12] ^= R(x[15] + x[14], 7)
6719 x[13] ^= R(x[12] + x[15], 9)
6720 x[14] ^= R(x[13] + x[12], 13)
6721 x[15] ^= R(x[14] + x[13], 18)
6722 }
6723
6724 for (i = 0; i < 16; ++i) B32[i] = x[i] + B32[i]
6725
6726 for (i = 0; i < 16; i++) {
6727 let bi = i * 4
6728 B[bi + 0] = (B32[i] >> 0 & 0xff)
6729 B[bi + 1] = (B32[i] >> 8 & 0xff)
6730 B[bi + 2] = (B32[i] >> 16 & 0xff)
6731 B[bi + 3] = (B32[i] >> 24 & 0xff)
6732 // B.writeInt32LE(B32[i], i*4) //<--- this is signficantly slower even in Node.js
6733 }
6734}
6735
6736// naive approach... going back to loop unrolling may yield additional performance
6737function blockxor (S, Si, D, Di, len) {
6738 for (let i = 0; i < len; i++) {
6739 D[Di + i] ^= S[Si + i]
6740 }
6741}
6742
6743function arraycopy (src, srcPos, dest, destPos, length) {
6744 if (Buffer.isBuffer(src) && Buffer.isBuffer(dest)) {
6745 src.copy(dest, destPos, srcPos, srcPos + length)
6746 } else {
6747 while (length--) {
6748 dest[destPos++] = src[srcPos++]
6749 }
6750 }
6751}
6752
6753module.exports = {
6754 checkAndInit,
6755 smix,
6756 smixSync
6757}
6758
6759}).call(this,require("buffer").Buffer,require("timers").setImmediate)
6760},{"buffer":110,"crypto":118,"timers":217}],52:[function(require,module,exports){
6761var Buffer = require('safe-buffer').Buffer
6762
6763// prototype class for hash functions
6764function Hash (blockSize, finalSize) {
6765 this._block = Buffer.alloc(blockSize)
6766 this._finalSize = finalSize
6767 this._blockSize = blockSize
6768 this._len = 0
6769}
6770
6771Hash.prototype.update = function (data, enc) {
6772 if (typeof data === 'string') {
6773 enc = enc || 'utf8'
6774 data = Buffer.from(data, enc)
6775 }
6776
6777 var block = this._block
6778 var blockSize = this._blockSize
6779 var length = data.length
6780 var accum = this._len
6781
6782 for (var offset = 0; offset < length;) {
6783 var assigned = accum % blockSize
6784 var remainder = Math.min(length - offset, blockSize - assigned)
6785
6786 for (var i = 0; i < remainder; i++) {
6787 block[assigned + i] = data[offset + i]
6788 }
6789
6790 accum += remainder
6791 offset += remainder
6792
6793 if ((accum % blockSize) === 0) {
6794 this._update(block)
6795 }
6796 }
6797
6798 this._len += length
6799 return this
6800}
6801
6802Hash.prototype.digest = function (enc) {
6803 var rem = this._len % this._blockSize
6804
6805 this._block[rem] = 0x80
6806
6807 // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
6808 // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
6809 this._block.fill(0, rem + 1)
6810
6811 if (rem >= this._finalSize) {
6812 this._update(this._block)
6813 this._block.fill(0)
6814 }
6815
6816 var bits = this._len * 8
6817
6818 // uint32
6819 if (bits <= 0xffffffff) {
6820 this._block.writeUInt32BE(bits, this._blockSize - 4)
6821
6822 // uint64
6823 } else {
6824 var lowBits = (bits & 0xffffffff) >>> 0
6825 var highBits = (bits - lowBits) / 0x100000000
6826
6827 this._block.writeUInt32BE(highBits, this._blockSize - 8)
6828 this._block.writeUInt32BE(lowBits, this._blockSize - 4)
6829 }
6830
6831 this._update(this._block)
6832 var hash = this._hash()
6833
6834 return enc ? hash.toString(enc) : hash
6835}
6836
6837Hash.prototype._update = function () {
6838 throw new Error('_update must be implemented by subclass')
6839}
6840
6841module.exports = Hash
6842
6843},{"safe-buffer":47}],53:[function(require,module,exports){
6844var exports = module.exports = function SHA (algorithm) {
6845 algorithm = algorithm.toLowerCase()
6846
6847 var Algorithm = exports[algorithm]
6848 if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
6849
6850 return new Algorithm()
6851}
6852
6853exports.sha = require('./sha')
6854exports.sha1 = require('./sha1')
6855exports.sha224 = require('./sha224')
6856exports.sha256 = require('./sha256')
6857exports.sha384 = require('./sha384')
6858exports.sha512 = require('./sha512')
6859
6860},{"./sha":54,"./sha1":55,"./sha224":56,"./sha256":57,"./sha384":58,"./sha512":59}],54:[function(require,module,exports){
6861/*
6862 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
6863 * in FIPS PUB 180-1
6864 * This source code is derived from sha1.js of the same repository.
6865 * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
6866 * operation was added.
6867 */
6868
6869var inherits = require('inherits')
6870var Hash = require('./hash')
6871var Buffer = require('safe-buffer').Buffer
6872
6873var K = [
6874 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6875]
6876
6877var W = new Array(80)
6878
6879function Sha () {
6880 this.init()
6881 this._w = W
6882
6883 Hash.call(this, 64, 56)
6884}
6885
6886inherits(Sha, Hash)
6887
6888Sha.prototype.init = function () {
6889 this._a = 0x67452301
6890 this._b = 0xefcdab89
6891 this._c = 0x98badcfe
6892 this._d = 0x10325476
6893 this._e = 0xc3d2e1f0
6894
6895 return this
6896}
6897
6898function rotl5 (num) {
6899 return (num << 5) | (num >>> 27)
6900}
6901
6902function rotl30 (num) {
6903 return (num << 30) | (num >>> 2)
6904}
6905
6906function ft (s, b, c, d) {
6907 if (s === 0) return (b & c) | ((~b) & d)
6908 if (s === 2) return (b & c) | (b & d) | (c & d)
6909 return b ^ c ^ d
6910}
6911
6912Sha.prototype._update = function (M) {
6913 var W = this._w
6914
6915 var a = this._a | 0
6916 var b = this._b | 0
6917 var c = this._c | 0
6918 var d = this._d | 0
6919 var e = this._e | 0
6920
6921 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
6922 for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
6923
6924 for (var j = 0; j < 80; ++j) {
6925 var s = ~~(j / 20)
6926 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
6927
6928 e = d
6929 d = c
6930 c = rotl30(b)
6931 b = a
6932 a = t
6933 }
6934
6935 this._a = (a + this._a) | 0
6936 this._b = (b + this._b) | 0
6937 this._c = (c + this._c) | 0
6938 this._d = (d + this._d) | 0
6939 this._e = (e + this._e) | 0
6940}
6941
6942Sha.prototype._hash = function () {
6943 var H = Buffer.allocUnsafe(20)
6944
6945 H.writeInt32BE(this._a | 0, 0)
6946 H.writeInt32BE(this._b | 0, 4)
6947 H.writeInt32BE(this._c | 0, 8)
6948 H.writeInt32BE(this._d | 0, 12)
6949 H.writeInt32BE(this._e | 0, 16)
6950
6951 return H
6952}
6953
6954module.exports = Sha
6955
6956},{"./hash":52,"inherits":44,"safe-buffer":47}],55:[function(require,module,exports){
6957/*
6958 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
6959 * in FIPS PUB 180-1
6960 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
6961 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6962 * Distributed under the BSD License
6963 * See http://pajhome.org.uk/crypt/md5 for details.
6964 */
6965
6966var inherits = require('inherits')
6967var Hash = require('./hash')
6968var Buffer = require('safe-buffer').Buffer
6969
6970var K = [
6971 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6972]
6973
6974var W = new Array(80)
6975
6976function Sha1 () {
6977 this.init()
6978 this._w = W
6979
6980 Hash.call(this, 64, 56)
6981}
6982
6983inherits(Sha1, Hash)
6984
6985Sha1.prototype.init = function () {
6986 this._a = 0x67452301
6987 this._b = 0xefcdab89
6988 this._c = 0x98badcfe
6989 this._d = 0x10325476
6990 this._e = 0xc3d2e1f0
6991
6992 return this
6993}
6994
6995function rotl1 (num) {
6996 return (num << 1) | (num >>> 31)
6997}
6998
6999function rotl5 (num) {
7000 return (num << 5) | (num >>> 27)
7001}
7002
7003function rotl30 (num) {
7004 return (num << 30) | (num >>> 2)
7005}
7006
7007function ft (s, b, c, d) {
7008 if (s === 0) return (b & c) | ((~b) & d)
7009 if (s === 2) return (b & c) | (b & d) | (c & d)
7010 return b ^ c ^ d
7011}
7012
7013Sha1.prototype._update = function (M) {
7014 var W = this._w
7015
7016 var a = this._a | 0
7017 var b = this._b | 0
7018 var c = this._c | 0
7019 var d = this._d | 0
7020 var e = this._e | 0
7021
7022 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
7023 for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
7024
7025 for (var j = 0; j < 80; ++j) {
7026 var s = ~~(j / 20)
7027 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
7028
7029 e = d
7030 d = c
7031 c = rotl30(b)
7032 b = a
7033 a = t
7034 }
7035
7036 this._a = (a + this._a) | 0
7037 this._b = (b + this._b) | 0
7038 this._c = (c + this._c) | 0
7039 this._d = (d + this._d) | 0
7040 this._e = (e + this._e) | 0
7041}
7042
7043Sha1.prototype._hash = function () {
7044 var H = Buffer.allocUnsafe(20)
7045
7046 H.writeInt32BE(this._a | 0, 0)
7047 H.writeInt32BE(this._b | 0, 4)
7048 H.writeInt32BE(this._c | 0, 8)
7049 H.writeInt32BE(this._d | 0, 12)
7050 H.writeInt32BE(this._e | 0, 16)
7051
7052 return H
7053}
7054
7055module.exports = Sha1
7056
7057},{"./hash":52,"inherits":44,"safe-buffer":47}],56:[function(require,module,exports){
7058/**
7059 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
7060 * in FIPS 180-2
7061 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
7062 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
7063 *
7064 */
7065
7066var inherits = require('inherits')
7067var Sha256 = require('./sha256')
7068var Hash = require('./hash')
7069var Buffer = require('safe-buffer').Buffer
7070
7071var W = new Array(64)
7072
7073function Sha224 () {
7074 this.init()
7075
7076 this._w = W // new Array(64)
7077
7078 Hash.call(this, 64, 56)
7079}
7080
7081inherits(Sha224, Sha256)
7082
7083Sha224.prototype.init = function () {
7084 this._a = 0xc1059ed8
7085 this._b = 0x367cd507
7086 this._c = 0x3070dd17
7087 this._d = 0xf70e5939
7088 this._e = 0xffc00b31
7089 this._f = 0x68581511
7090 this._g = 0x64f98fa7
7091 this._h = 0xbefa4fa4
7092
7093 return this
7094}
7095
7096Sha224.prototype._hash = function () {
7097 var H = Buffer.allocUnsafe(28)
7098
7099 H.writeInt32BE(this._a, 0)
7100 H.writeInt32BE(this._b, 4)
7101 H.writeInt32BE(this._c, 8)
7102 H.writeInt32BE(this._d, 12)
7103 H.writeInt32BE(this._e, 16)
7104 H.writeInt32BE(this._f, 20)
7105 H.writeInt32BE(this._g, 24)
7106
7107 return H
7108}
7109
7110module.exports = Sha224
7111
7112},{"./hash":52,"./sha256":57,"inherits":44,"safe-buffer":47}],57:[function(require,module,exports){
7113/**
7114 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
7115 * in FIPS 180-2
7116 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
7117 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
7118 *
7119 */
7120
7121var inherits = require('inherits')
7122var Hash = require('./hash')
7123var Buffer = require('safe-buffer').Buffer
7124
7125var K = [
7126 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
7127 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
7128 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
7129 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
7130 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
7131 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
7132 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
7133 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
7134 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
7135 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
7136 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
7137 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
7138 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
7139 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
7140 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
7141 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
7142]
7143
7144var W = new Array(64)
7145
7146function Sha256 () {
7147 this.init()
7148
7149 this._w = W // new Array(64)
7150
7151 Hash.call(this, 64, 56)
7152}
7153
7154inherits(Sha256, Hash)
7155
7156Sha256.prototype.init = function () {
7157 this._a = 0x6a09e667
7158 this._b = 0xbb67ae85
7159 this._c = 0x3c6ef372
7160 this._d = 0xa54ff53a
7161 this._e = 0x510e527f
7162 this._f = 0x9b05688c
7163 this._g = 0x1f83d9ab
7164 this._h = 0x5be0cd19
7165
7166 return this
7167}
7168
7169function ch (x, y, z) {
7170 return z ^ (x & (y ^ z))
7171}
7172
7173function maj (x, y, z) {
7174 return (x & y) | (z & (x | y))
7175}
7176
7177function sigma0 (x) {
7178 return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
7179}
7180
7181function sigma1 (x) {
7182 return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
7183}
7184
7185function gamma0 (x) {
7186 return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
7187}
7188
7189function gamma1 (x) {
7190 return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
7191}
7192
7193Sha256.prototype._update = function (M) {
7194 var W = this._w
7195
7196 var a = this._a | 0
7197 var b = this._b | 0
7198 var c = this._c | 0
7199 var d = this._d | 0
7200 var e = this._e | 0
7201 var f = this._f | 0
7202 var g = this._g | 0
7203 var h = this._h | 0
7204
7205 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
7206 for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
7207
7208 for (var j = 0; j < 64; ++j) {
7209 var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
7210 var T2 = (sigma0(a) + maj(a, b, c)) | 0
7211
7212 h = g
7213 g = f
7214 f = e
7215 e = (d + T1) | 0
7216 d = c
7217 c = b
7218 b = a
7219 a = (T1 + T2) | 0
7220 }
7221
7222 this._a = (a + this._a) | 0
7223 this._b = (b + this._b) | 0
7224 this._c = (c + this._c) | 0
7225 this._d = (d + this._d) | 0
7226 this._e = (e + this._e) | 0
7227 this._f = (f + this._f) | 0
7228 this._g = (g + this._g) | 0
7229 this._h = (h + this._h) | 0
7230}
7231
7232Sha256.prototype._hash = function () {
7233 var H = Buffer.allocUnsafe(32)
7234
7235 H.writeInt32BE(this._a, 0)
7236 H.writeInt32BE(this._b, 4)
7237 H.writeInt32BE(this._c, 8)
7238 H.writeInt32BE(this._d, 12)
7239 H.writeInt32BE(this._e, 16)
7240 H.writeInt32BE(this._f, 20)
7241 H.writeInt32BE(this._g, 24)
7242 H.writeInt32BE(this._h, 28)
7243
7244 return H
7245}
7246
7247module.exports = Sha256
7248
7249},{"./hash":52,"inherits":44,"safe-buffer":47}],58:[function(require,module,exports){
7250var inherits = require('inherits')
7251var SHA512 = require('./sha512')
7252var Hash = require('./hash')
7253var Buffer = require('safe-buffer').Buffer
7254
7255var W = new Array(160)
7256
7257function Sha384 () {
7258 this.init()
7259 this._w = W
7260
7261 Hash.call(this, 128, 112)
7262}
7263
7264inherits(Sha384, SHA512)
7265
7266Sha384.prototype.init = function () {
7267 this._ah = 0xcbbb9d5d
7268 this._bh = 0x629a292a
7269 this._ch = 0x9159015a
7270 this._dh = 0x152fecd8
7271 this._eh = 0x67332667
7272 this._fh = 0x8eb44a87
7273 this._gh = 0xdb0c2e0d
7274 this._hh = 0x47b5481d
7275
7276 this._al = 0xc1059ed8
7277 this._bl = 0x367cd507
7278 this._cl = 0x3070dd17
7279 this._dl = 0xf70e5939
7280 this._el = 0xffc00b31
7281 this._fl = 0x68581511
7282 this._gl = 0x64f98fa7
7283 this._hl = 0xbefa4fa4
7284
7285 return this
7286}
7287
7288Sha384.prototype._hash = function () {
7289 var H = Buffer.allocUnsafe(48)
7290
7291 function writeInt64BE (h, l, offset) {
7292 H.writeInt32BE(h, offset)
7293 H.writeInt32BE(l, offset + 4)
7294 }
7295
7296 writeInt64BE(this._ah, this._al, 0)
7297 writeInt64BE(this._bh, this._bl, 8)
7298 writeInt64BE(this._ch, this._cl, 16)
7299 writeInt64BE(this._dh, this._dl, 24)
7300 writeInt64BE(this._eh, this._el, 32)
7301 writeInt64BE(this._fh, this._fl, 40)
7302
7303 return H
7304}
7305
7306module.exports = Sha384
7307
7308},{"./hash":52,"./sha512":59,"inherits":44,"safe-buffer":47}],59:[function(require,module,exports){
7309var inherits = require('inherits')
7310var Hash = require('./hash')
7311var Buffer = require('safe-buffer').Buffer
7312
7313var K = [
7314 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
7315 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
7316 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
7317 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
7318 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
7319 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
7320 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
7321 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
7322 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
7323 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
7324 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
7325 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
7326 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
7327 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
7328 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
7329 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
7330 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
7331 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
7332 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
7333 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
7334 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
7335 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
7336 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
7337 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
7338 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
7339 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
7340 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
7341 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
7342 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
7343 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
7344 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
7345 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
7346 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
7347 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
7348 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
7349 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
7350 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
7351 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
7352 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
7353 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
7354]
7355
7356var W = new Array(160)
7357
7358function Sha512 () {
7359 this.init()
7360 this._w = W
7361
7362 Hash.call(this, 128, 112)
7363}
7364
7365inherits(Sha512, Hash)
7366
7367Sha512.prototype.init = function () {
7368 this._ah = 0x6a09e667
7369 this._bh = 0xbb67ae85
7370 this._ch = 0x3c6ef372
7371 this._dh = 0xa54ff53a
7372 this._eh = 0x510e527f
7373 this._fh = 0x9b05688c
7374 this._gh = 0x1f83d9ab
7375 this._hh = 0x5be0cd19
7376
7377 this._al = 0xf3bcc908
7378 this._bl = 0x84caa73b
7379 this._cl = 0xfe94f82b
7380 this._dl = 0x5f1d36f1
7381 this._el = 0xade682d1
7382 this._fl = 0x2b3e6c1f
7383 this._gl = 0xfb41bd6b
7384 this._hl = 0x137e2179
7385
7386 return this
7387}
7388
7389function Ch (x, y, z) {
7390 return z ^ (x & (y ^ z))
7391}
7392
7393function maj (x, y, z) {
7394 return (x & y) | (z & (x | y))
7395}
7396
7397function sigma0 (x, xl) {
7398 return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
7399}
7400
7401function sigma1 (x, xl) {
7402 return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
7403}
7404
7405function Gamma0 (x, xl) {
7406 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
7407}
7408
7409function Gamma0l (x, xl) {
7410 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
7411}
7412
7413function Gamma1 (x, xl) {
7414 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
7415}
7416
7417function Gamma1l (x, xl) {
7418 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
7419}
7420
7421function getCarry (a, b) {
7422 return (a >>> 0) < (b >>> 0) ? 1 : 0
7423}
7424
7425Sha512.prototype._update = function (M) {
7426 var W = this._w
7427
7428 var ah = this._ah | 0
7429 var bh = this._bh | 0
7430 var ch = this._ch | 0
7431 var dh = this._dh | 0
7432 var eh = this._eh | 0
7433 var fh = this._fh | 0
7434 var gh = this._gh | 0
7435 var hh = this._hh | 0
7436
7437 var al = this._al | 0
7438 var bl = this._bl | 0
7439 var cl = this._cl | 0
7440 var dl = this._dl | 0
7441 var el = this._el | 0
7442 var fl = this._fl | 0
7443 var gl = this._gl | 0
7444 var hl = this._hl | 0
7445
7446 for (var i = 0; i < 32; i += 2) {
7447 W[i] = M.readInt32BE(i * 4)
7448 W[i + 1] = M.readInt32BE(i * 4 + 4)
7449 }
7450 for (; i < 160; i += 2) {
7451 var xh = W[i - 15 * 2]
7452 var xl = W[i - 15 * 2 + 1]
7453 var gamma0 = Gamma0(xh, xl)
7454 var gamma0l = Gamma0l(xl, xh)
7455
7456 xh = W[i - 2 * 2]
7457 xl = W[i - 2 * 2 + 1]
7458 var gamma1 = Gamma1(xh, xl)
7459 var gamma1l = Gamma1l(xl, xh)
7460
7461 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
7462 var Wi7h = W[i - 7 * 2]
7463 var Wi7l = W[i - 7 * 2 + 1]
7464
7465 var Wi16h = W[i - 16 * 2]
7466 var Wi16l = W[i - 16 * 2 + 1]
7467
7468 var Wil = (gamma0l + Wi7l) | 0
7469 var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
7470 Wil = (Wil + gamma1l) | 0
7471 Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
7472 Wil = (Wil + Wi16l) | 0
7473 Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
7474
7475 W[i] = Wih
7476 W[i + 1] = Wil
7477 }
7478
7479 for (var j = 0; j < 160; j += 2) {
7480 Wih = W[j]
7481 Wil = W[j + 1]
7482
7483 var majh = maj(ah, bh, ch)
7484 var majl = maj(al, bl, cl)
7485
7486 var sigma0h = sigma0(ah, al)
7487 var sigma0l = sigma0(al, ah)
7488 var sigma1h = sigma1(eh, el)
7489 var sigma1l = sigma1(el, eh)
7490
7491 // t1 = h + sigma1 + ch + K[j] + W[j]
7492 var Kih = K[j]
7493 var Kil = K[j + 1]
7494
7495 var chh = Ch(eh, fh, gh)
7496 var chl = Ch(el, fl, gl)
7497
7498 var t1l = (hl + sigma1l) | 0
7499 var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
7500 t1l = (t1l + chl) | 0
7501 t1h = (t1h + chh + getCarry(t1l, chl)) | 0
7502 t1l = (t1l + Kil) | 0
7503 t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
7504 t1l = (t1l + Wil) | 0
7505 t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
7506
7507 // t2 = sigma0 + maj
7508 var t2l = (sigma0l + majl) | 0
7509 var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
7510
7511 hh = gh
7512 hl = gl
7513 gh = fh
7514 gl = fl
7515 fh = eh
7516 fl = el
7517 el = (dl + t1l) | 0
7518 eh = (dh + t1h + getCarry(el, dl)) | 0
7519 dh = ch
7520 dl = cl
7521 ch = bh
7522 cl = bl
7523 bh = ah
7524 bl = al
7525 al = (t1l + t2l) | 0
7526 ah = (t1h + t2h + getCarry(al, t1l)) | 0
7527 }
7528
7529 this._al = (this._al + al) | 0
7530 this._bl = (this._bl + bl) | 0
7531 this._cl = (this._cl + cl) | 0
7532 this._dl = (this._dl + dl) | 0
7533 this._el = (this._el + el) | 0
7534 this._fl = (this._fl + fl) | 0
7535 this._gl = (this._gl + gl) | 0
7536 this._hl = (this._hl + hl) | 0
7537
7538 this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
7539 this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
7540 this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
7541 this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
7542 this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
7543 this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
7544 this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
7545 this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
7546}
7547
7548Sha512.prototype._hash = function () {
7549 var H = Buffer.allocUnsafe(64)
7550
7551 function writeInt64BE (h, l, offset) {
7552 H.writeInt32BE(h, offset)
7553 H.writeInt32BE(l, offset + 4)
7554 }
7555
7556 writeInt64BE(this._ah, this._al, 0)
7557 writeInt64BE(this._bh, this._bl, 8)
7558 writeInt64BE(this._ch, this._cl, 16)
7559 writeInt64BE(this._dh, this._dl, 24)
7560 writeInt64BE(this._eh, this._el, 32)
7561 writeInt64BE(this._fh, this._fl, 40)
7562 writeInt64BE(this._gh, this._gl, 48)
7563 writeInt64BE(this._hh, this._hl, 56)
7564
7565 return H
7566}
7567
7568module.exports = Sha512
7569
7570},{"./hash":52,"inherits":44,"safe-buffer":47}],60:[function(require,module,exports){
7571var asn1 = exports;
7572
7573asn1.bignum = require('bn.js');
7574
7575asn1.define = require('./asn1/api').define;
7576asn1.base = require('./asn1/base');
7577asn1.constants = require('./asn1/constants');
7578asn1.decoders = require('./asn1/decoders');
7579asn1.encoders = require('./asn1/encoders');
7580
7581},{"./asn1/api":61,"./asn1/base":63,"./asn1/constants":67,"./asn1/decoders":69,"./asn1/encoders":72,"bn.js":79}],61:[function(require,module,exports){
7582var asn1 = require('../asn1');
7583var inherits = require('inherits');
7584
7585var api = exports;
7586
7587api.define = function define(name, body) {
7588 return new Entity(name, body);
7589};
7590
7591function Entity(name, body) {
7592 this.name = name;
7593 this.body = body;
7594
7595 this.decoders = {};
7596 this.encoders = {};
7597};
7598
7599Entity.prototype._createNamed = function createNamed(base) {
7600 var named;
7601 try {
7602 named = require('vm').runInThisContext(
7603 '(function ' + this.name + '(entity) {\n' +
7604 ' this._initNamed(entity);\n' +
7605 '})'
7606 );
7607 } catch (e) {
7608 named = function (entity) {
7609 this._initNamed(entity);
7610 };
7611 }
7612 inherits(named, base);
7613 named.prototype._initNamed = function initnamed(entity) {
7614 base.call(this, entity);
7615 };
7616
7617 return new named(this);
7618};
7619
7620Entity.prototype._getDecoder = function _getDecoder(enc) {
7621 enc = enc || 'der';
7622 // Lazily create decoder
7623 if (!this.decoders.hasOwnProperty(enc))
7624 this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
7625 return this.decoders[enc];
7626};
7627
7628Entity.prototype.decode = function decode(data, enc, options) {
7629 return this._getDecoder(enc).decode(data, options);
7630};
7631
7632Entity.prototype._getEncoder = function _getEncoder(enc) {
7633 enc = enc || 'der';
7634 // Lazily create encoder
7635 if (!this.encoders.hasOwnProperty(enc))
7636 this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
7637 return this.encoders[enc];
7638};
7639
7640Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
7641 return this._getEncoder(enc).encode(data, reporter);
7642};
7643
7644},{"../asn1":60,"inherits":162,"vm":219}],62:[function(require,module,exports){
7645var inherits = require('inherits');
7646var Reporter = require('../base').Reporter;
7647var Buffer = require('buffer').Buffer;
7648
7649function DecoderBuffer(base, options) {
7650 Reporter.call(this, options);
7651 if (!Buffer.isBuffer(base)) {
7652 this.error('Input not Buffer');
7653 return;
7654 }
7655
7656 this.base = base;
7657 this.offset = 0;
7658 this.length = base.length;
7659}
7660inherits(DecoderBuffer, Reporter);
7661exports.DecoderBuffer = DecoderBuffer;
7662
7663DecoderBuffer.prototype.save = function save() {
7664 return { offset: this.offset, reporter: Reporter.prototype.save.call(this) };
7665};
7666
7667DecoderBuffer.prototype.restore = function restore(save) {
7668 // Return skipped data
7669 var res = new DecoderBuffer(this.base);
7670 res.offset = save.offset;
7671 res.length = this.offset;
7672
7673 this.offset = save.offset;
7674 Reporter.prototype.restore.call(this, save.reporter);
7675
7676 return res;
7677};
7678
7679DecoderBuffer.prototype.isEmpty = function isEmpty() {
7680 return this.offset === this.length;
7681};
7682
7683DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
7684 if (this.offset + 1 <= this.length)
7685 return this.base.readUInt8(this.offset++, true);
7686 else
7687 return this.error(fail || 'DecoderBuffer overrun');
7688}
7689
7690DecoderBuffer.prototype.skip = function skip(bytes, fail) {
7691 if (!(this.offset + bytes <= this.length))
7692 return this.error(fail || 'DecoderBuffer overrun');
7693
7694 var res = new DecoderBuffer(this.base);
7695
7696 // Share reporter state
7697 res._reporterState = this._reporterState;
7698
7699 res.offset = this.offset;
7700 res.length = this.offset + bytes;
7701 this.offset += bytes;
7702 return res;
7703}
7704
7705DecoderBuffer.prototype.raw = function raw(save) {
7706 return this.base.slice(save ? save.offset : this.offset, this.length);
7707}
7708
7709function EncoderBuffer(value, reporter) {
7710 if (Array.isArray(value)) {
7711 this.length = 0;
7712 this.value = value.map(function(item) {
7713 if (!(item instanceof EncoderBuffer))
7714 item = new EncoderBuffer(item, reporter);
7715 this.length += item.length;
7716 return item;
7717 }, this);
7718 } else if (typeof value === 'number') {
7719 if (!(0 <= value && value <= 0xff))
7720 return reporter.error('non-byte EncoderBuffer value');
7721 this.value = value;
7722 this.length = 1;
7723 } else if (typeof value === 'string') {
7724 this.value = value;
7725 this.length = Buffer.byteLength(value);
7726 } else if (Buffer.isBuffer(value)) {
7727 this.value = value;
7728 this.length = value.length;
7729 } else {
7730 return reporter.error('Unsupported type: ' + typeof value);
7731 }
7732}
7733exports.EncoderBuffer = EncoderBuffer;
7734
7735EncoderBuffer.prototype.join = function join(out, offset) {
7736 if (!out)
7737 out = new Buffer(this.length);
7738 if (!offset)
7739 offset = 0;
7740
7741 if (this.length === 0)
7742 return out;
7743
7744 if (Array.isArray(this.value)) {
7745 this.value.forEach(function(item) {
7746 item.join(out, offset);
7747 offset += item.length;
7748 });
7749 } else {
7750 if (typeof this.value === 'number')
7751 out[offset] = this.value;
7752 else if (typeof this.value === 'string')
7753 out.write(this.value, offset);
7754 else if (Buffer.isBuffer(this.value))
7755 this.value.copy(out, offset);
7756 offset += this.length;
7757 }
7758
7759 return out;
7760};
7761
7762},{"../base":63,"buffer":110,"inherits":162}],63:[function(require,module,exports){
7763var base = exports;
7764
7765base.Reporter = require('./reporter').Reporter;
7766base.DecoderBuffer = require('./buffer').DecoderBuffer;
7767base.EncoderBuffer = require('./buffer').EncoderBuffer;
7768base.Node = require('./node');
7769
7770},{"./buffer":62,"./node":64,"./reporter":65}],64:[function(require,module,exports){
7771var Reporter = require('../base').Reporter;
7772var EncoderBuffer = require('../base').EncoderBuffer;
7773var DecoderBuffer = require('../base').DecoderBuffer;
7774var assert = require('minimalistic-assert');
7775
7776// Supported tags
7777var tags = [
7778 'seq', 'seqof', 'set', 'setof', 'objid', 'bool',
7779 'gentime', 'utctime', 'null_', 'enum', 'int', 'objDesc',
7780 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str',
7781 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr'
7782];
7783
7784// Public methods list
7785var methods = [
7786 'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice',
7787 'any', 'contains'
7788].concat(tags);
7789
7790// Overrided methods list
7791var overrided = [
7792 '_peekTag', '_decodeTag', '_use',
7793 '_decodeStr', '_decodeObjid', '_decodeTime',
7794 '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList',
7795
7796 '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime',
7797 '_encodeNull', '_encodeInt', '_encodeBool'
7798];
7799
7800function Node(enc, parent) {
7801 var state = {};
7802 this._baseState = state;
7803
7804 state.enc = enc;
7805
7806 state.parent = parent || null;
7807 state.children = null;
7808
7809 // State
7810 state.tag = null;
7811 state.args = null;
7812 state.reverseArgs = null;
7813 state.choice = null;
7814 state.optional = false;
7815 state.any = false;
7816 state.obj = false;
7817 state.use = null;
7818 state.useDecoder = null;
7819 state.key = null;
7820 state['default'] = null;
7821 state.explicit = null;
7822 state.implicit = null;
7823 state.contains = null;
7824
7825 // Should create new instance on each method
7826 if (!state.parent) {
7827 state.children = [];
7828 this._wrap();
7829 }
7830}
7831module.exports = Node;
7832
7833var stateProps = [
7834 'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice',
7835 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit',
7836 'implicit', 'contains'
7837];
7838
7839Node.prototype.clone = function clone() {
7840 var state = this._baseState;
7841 var cstate = {};
7842 stateProps.forEach(function(prop) {
7843 cstate[prop] = state[prop];
7844 });
7845 var res = new this.constructor(cstate.parent);
7846 res._baseState = cstate;
7847 return res;
7848};
7849
7850Node.prototype._wrap = function wrap() {
7851 var state = this._baseState;
7852 methods.forEach(function(method) {
7853 this[method] = function _wrappedMethod() {
7854 var clone = new this.constructor(this);
7855 state.children.push(clone);
7856 return clone[method].apply(clone, arguments);
7857 };
7858 }, this);
7859};
7860
7861Node.prototype._init = function init(body) {
7862 var state = this._baseState;
7863
7864 assert(state.parent === null);
7865 body.call(this);
7866
7867 // Filter children
7868 state.children = state.children.filter(function(child) {
7869 return child._baseState.parent === this;
7870 }, this);
7871 assert.equal(state.children.length, 1, 'Root node can have only one child');
7872};
7873
7874Node.prototype._useArgs = function useArgs(args) {
7875 var state = this._baseState;
7876
7877 // Filter children and args
7878 var children = args.filter(function(arg) {
7879 return arg instanceof this.constructor;
7880 }, this);
7881 args = args.filter(function(arg) {
7882 return !(arg instanceof this.constructor);
7883 }, this);
7884
7885 if (children.length !== 0) {
7886 assert(state.children === null);
7887 state.children = children;
7888
7889 // Replace parent to maintain backward link
7890 children.forEach(function(child) {
7891 child._baseState.parent = this;
7892 }, this);
7893 }
7894 if (args.length !== 0) {
7895 assert(state.args === null);
7896 state.args = args;
7897 state.reverseArgs = args.map(function(arg) {
7898 if (typeof arg !== 'object' || arg.constructor !== Object)
7899 return arg;
7900
7901 var res = {};
7902 Object.keys(arg).forEach(function(key) {
7903 if (key == (key | 0))
7904 key |= 0;
7905 var value = arg[key];
7906 res[value] = key;
7907 });
7908 return res;
7909 });
7910 }
7911};
7912
7913//
7914// Overrided methods
7915//
7916
7917overrided.forEach(function(method) {
7918 Node.prototype[method] = function _overrided() {
7919 var state = this._baseState;
7920 throw new Error(method + ' not implemented for encoding: ' + state.enc);
7921 };
7922});
7923
7924//
7925// Public methods
7926//
7927
7928tags.forEach(function(tag) {
7929 Node.prototype[tag] = function _tagMethod() {
7930 var state = this._baseState;
7931 var args = Array.prototype.slice.call(arguments);
7932
7933 assert(state.tag === null);
7934 state.tag = tag;
7935
7936 this._useArgs(args);
7937
7938 return this;
7939 };
7940});
7941
7942Node.prototype.use = function use(item) {
7943 assert(item);
7944 var state = this._baseState;
7945
7946 assert(state.use === null);
7947 state.use = item;
7948
7949 return this;
7950};
7951
7952Node.prototype.optional = function optional() {
7953 var state = this._baseState;
7954
7955 state.optional = true;
7956
7957 return this;
7958};
7959
7960Node.prototype.def = function def(val) {
7961 var state = this._baseState;
7962
7963 assert(state['default'] === null);
7964 state['default'] = val;
7965 state.optional = true;
7966
7967 return this;
7968};
7969
7970Node.prototype.explicit = function explicit(num) {
7971 var state = this._baseState;
7972
7973 assert(state.explicit === null && state.implicit === null);
7974 state.explicit = num;
7975
7976 return this;
7977};
7978
7979Node.prototype.implicit = function implicit(num) {
7980 var state = this._baseState;
7981
7982 assert(state.explicit === null && state.implicit === null);
7983 state.implicit = num;
7984
7985 return this;
7986};
7987
7988Node.prototype.obj = function obj() {
7989 var state = this._baseState;
7990 var args = Array.prototype.slice.call(arguments);
7991
7992 state.obj = true;
7993
7994 if (args.length !== 0)
7995 this._useArgs(args);
7996
7997 return this;
7998};
7999
8000Node.prototype.key = function key(newKey) {
8001 var state = this._baseState;
8002
8003 assert(state.key === null);
8004 state.key = newKey;
8005
8006 return this;
8007};
8008
8009Node.prototype.any = function any() {
8010 var state = this._baseState;
8011
8012 state.any = true;
8013
8014 return this;
8015};
8016
8017Node.prototype.choice = function choice(obj) {
8018 var state = this._baseState;
8019
8020 assert(state.choice === null);
8021 state.choice = obj;
8022 this._useArgs(Object.keys(obj).map(function(key) {
8023 return obj[key];
8024 }));
8025
8026 return this;
8027};
8028
8029Node.prototype.contains = function contains(item) {
8030 var state = this._baseState;
8031
8032 assert(state.use === null);
8033 state.contains = item;
8034
8035 return this;
8036};
8037
8038//
8039// Decoding
8040//
8041
8042Node.prototype._decode = function decode(input, options) {
8043 var state = this._baseState;
8044
8045 // Decode root node
8046 if (state.parent === null)
8047 return input.wrapResult(state.children[0]._decode(input, options));
8048
8049 var result = state['default'];
8050 var present = true;
8051
8052 var prevKey = null;
8053 if (state.key !== null)
8054 prevKey = input.enterKey(state.key);
8055
8056 // Check if tag is there
8057 if (state.optional) {
8058 var tag = null;
8059 if (state.explicit !== null)
8060 tag = state.explicit;
8061 else if (state.implicit !== null)
8062 tag = state.implicit;
8063 else if (state.tag !== null)
8064 tag = state.tag;
8065
8066 if (tag === null && !state.any) {
8067 // Trial and Error
8068 var save = input.save();
8069 try {
8070 if (state.choice === null)
8071 this._decodeGeneric(state.tag, input, options);
8072 else
8073 this._decodeChoice(input, options);
8074 present = true;
8075 } catch (e) {
8076 present = false;
8077 }
8078 input.restore(save);
8079 } else {
8080 present = this._peekTag(input, tag, state.any);
8081
8082 if (input.isError(present))
8083 return present;
8084 }
8085 }
8086
8087 // Push object on stack
8088 var prevObj;
8089 if (state.obj && present)
8090 prevObj = input.enterObject();
8091
8092 if (present) {
8093 // Unwrap explicit values
8094 if (state.explicit !== null) {
8095 var explicit = this._decodeTag(input, state.explicit);
8096 if (input.isError(explicit))
8097 return explicit;
8098 input = explicit;
8099 }
8100
8101 var start = input.offset;
8102
8103 // Unwrap implicit and normal values
8104 if (state.use === null && state.choice === null) {
8105 if (state.any)
8106 var save = input.save();
8107 var body = this._decodeTag(
8108 input,
8109 state.implicit !== null ? state.implicit : state.tag,
8110 state.any
8111 );
8112 if (input.isError(body))
8113 return body;
8114
8115 if (state.any)
8116 result = input.raw(save);
8117 else
8118 input = body;
8119 }
8120
8121 if (options && options.track && state.tag !== null)
8122 options.track(input.path(), start, input.length, 'tagged');
8123
8124 if (options && options.track && state.tag !== null)
8125 options.track(input.path(), input.offset, input.length, 'content');
8126
8127 // Select proper method for tag
8128 if (state.any)
8129 result = result;
8130 else if (state.choice === null)
8131 result = this._decodeGeneric(state.tag, input, options);
8132 else
8133 result = this._decodeChoice(input, options);
8134
8135 if (input.isError(result))
8136 return result;
8137
8138 // Decode children
8139 if (!state.any && state.choice === null && state.children !== null) {
8140 state.children.forEach(function decodeChildren(child) {
8141 // NOTE: We are ignoring errors here, to let parser continue with other
8142 // parts of encoded data
8143 child._decode(input, options);
8144 });
8145 }
8146
8147 // Decode contained/encoded by schema, only in bit or octet strings
8148 if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
8149 var data = new DecoderBuffer(result);
8150 result = this._getUse(state.contains, input._reporterState.obj)
8151 ._decode(data, options);
8152 }
8153 }
8154
8155 // Pop object
8156 if (state.obj && present)
8157 result = input.leaveObject(prevObj);
8158
8159 // Set key
8160 if (state.key !== null && (result !== null || present === true))
8161 input.leaveKey(prevKey, state.key, result);
8162 else if (prevKey !== null)
8163 input.exitKey(prevKey);
8164
8165 return result;
8166};
8167
8168Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) {
8169 var state = this._baseState;
8170
8171 if (tag === 'seq' || tag === 'set')
8172 return null;
8173 if (tag === 'seqof' || tag === 'setof')
8174 return this._decodeList(input, tag, state.args[0], options);
8175 else if (/str$/.test(tag))
8176 return this._decodeStr(input, tag, options);
8177 else if (tag === 'objid' && state.args)
8178 return this._decodeObjid(input, state.args[0], state.args[1], options);
8179 else if (tag === 'objid')
8180 return this._decodeObjid(input, null, null, options);
8181 else if (tag === 'gentime' || tag === 'utctime')
8182 return this._decodeTime(input, tag, options);
8183 else if (tag === 'null_')
8184 return this._decodeNull(input, options);
8185 else if (tag === 'bool')
8186 return this._decodeBool(input, options);
8187 else if (tag === 'objDesc')
8188 return this._decodeStr(input, tag, options);
8189 else if (tag === 'int' || tag === 'enum')
8190 return this._decodeInt(input, state.args && state.args[0], options);
8191
8192 if (state.use !== null) {
8193 return this._getUse(state.use, input._reporterState.obj)
8194 ._decode(input, options);
8195 } else {
8196 return input.error('unknown tag: ' + tag);
8197 }
8198};
8199
8200Node.prototype._getUse = function _getUse(entity, obj) {
8201
8202 var state = this._baseState;
8203 // Create altered use decoder if implicit is set
8204 state.useDecoder = this._use(entity, obj);
8205 assert(state.useDecoder._baseState.parent === null);
8206 state.useDecoder = state.useDecoder._baseState.children[0];
8207 if (state.implicit !== state.useDecoder._baseState.implicit) {
8208 state.useDecoder = state.useDecoder.clone();
8209 state.useDecoder._baseState.implicit = state.implicit;
8210 }
8211 return state.useDecoder;
8212};
8213
8214Node.prototype._decodeChoice = function decodeChoice(input, options) {
8215 var state = this._baseState;
8216 var result = null;
8217 var match = false;
8218
8219 Object.keys(state.choice).some(function(key) {
8220 var save = input.save();
8221 var node = state.choice[key];
8222 try {
8223 var value = node._decode(input, options);
8224 if (input.isError(value))
8225 return false;
8226
8227 result = { type: key, value: value };
8228 match = true;
8229 } catch (e) {
8230 input.restore(save);
8231 return false;
8232 }
8233 return true;
8234 }, this);
8235
8236 if (!match)
8237 return input.error('Choice not matched');
8238
8239 return result;
8240};
8241
8242//
8243// Encoding
8244//
8245
8246Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
8247 return new EncoderBuffer(data, this.reporter);
8248};
8249
8250Node.prototype._encode = function encode(data, reporter, parent) {
8251 var state = this._baseState;
8252 if (state['default'] !== null && state['default'] === data)
8253 return;
8254
8255 var result = this._encodeValue(data, reporter, parent);
8256 if (result === undefined)
8257 return;
8258
8259 if (this._skipDefault(result, reporter, parent))
8260 return;
8261
8262 return result;
8263};
8264
8265Node.prototype._encodeValue = function encode(data, reporter, parent) {
8266 var state = this._baseState;
8267
8268 // Decode root node
8269 if (state.parent === null)
8270 return state.children[0]._encode(data, reporter || new Reporter());
8271
8272 var result = null;
8273
8274 // Set reporter to share it with a child class
8275 this.reporter = reporter;
8276
8277 // Check if data is there
8278 if (state.optional && data === undefined) {
8279 if (state['default'] !== null)
8280 data = state['default']
8281 else
8282 return;
8283 }
8284
8285 // Encode children first
8286 var content = null;
8287 var primitive = false;
8288 if (state.any) {
8289 // Anything that was given is translated to buffer
8290 result = this._createEncoderBuffer(data);
8291 } else if (state.choice) {
8292 result = this._encodeChoice(data, reporter);
8293 } else if (state.contains) {
8294 content = this._getUse(state.contains, parent)._encode(data, reporter);
8295 primitive = true;
8296 } else if (state.children) {
8297 content = state.children.map(function(child) {
8298 if (child._baseState.tag === 'null_')
8299 return child._encode(null, reporter, data);
8300
8301 if (child._baseState.key === null)
8302 return reporter.error('Child should have a key');
8303 var prevKey = reporter.enterKey(child._baseState.key);
8304
8305 if (typeof data !== 'object')
8306 return reporter.error('Child expected, but input is not object');
8307
8308 var res = child._encode(data[child._baseState.key], reporter, data);
8309 reporter.leaveKey(prevKey);
8310
8311 return res;
8312 }, this).filter(function(child) {
8313 return child;
8314 });
8315 content = this._createEncoderBuffer(content);
8316 } else {
8317 if (state.tag === 'seqof' || state.tag === 'setof') {
8318 // TODO(indutny): this should be thrown on DSL level
8319 if (!(state.args && state.args.length === 1))
8320 return reporter.error('Too many args for : ' + state.tag);
8321
8322 if (!Array.isArray(data))
8323 return reporter.error('seqof/setof, but data is not Array');
8324
8325 var child = this.clone();
8326 child._baseState.implicit = null;
8327 content = this._createEncoderBuffer(data.map(function(item) {
8328 var state = this._baseState;
8329
8330 return this._getUse(state.args[0], data)._encode(item, reporter);
8331 }, child));
8332 } else if (state.use !== null) {
8333 result = this._getUse(state.use, parent)._encode(data, reporter);
8334 } else {
8335 content = this._encodePrimitive(state.tag, data);
8336 primitive = true;
8337 }
8338 }
8339
8340 // Encode data itself
8341 var result;
8342 if (!state.any && state.choice === null) {
8343 var tag = state.implicit !== null ? state.implicit : state.tag;
8344 var cls = state.implicit === null ? 'universal' : 'context';
8345
8346 if (tag === null) {
8347 if (state.use === null)
8348 reporter.error('Tag could be omitted only for .use()');
8349 } else {
8350 if (state.use === null)
8351 result = this._encodeComposite(tag, primitive, cls, content);
8352 }
8353 }
8354
8355 // Wrap in explicit
8356 if (state.explicit !== null)
8357 result = this._encodeComposite(state.explicit, false, 'context', result);
8358
8359 return result;
8360};
8361
8362Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
8363 var state = this._baseState;
8364
8365 var node = state.choice[data.type];
8366 if (!node) {
8367 assert(
8368 false,
8369 data.type + ' not found in ' +
8370 JSON.stringify(Object.keys(state.choice)));
8371 }
8372 return node._encode(data.value, reporter);
8373};
8374
8375Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
8376 var state = this._baseState;
8377
8378 if (/str$/.test(tag))
8379 return this._encodeStr(data, tag);
8380 else if (tag === 'objid' && state.args)
8381 return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);
8382 else if (tag === 'objid')
8383 return this._encodeObjid(data, null, null);
8384 else if (tag === 'gentime' || tag === 'utctime')
8385 return this._encodeTime(data, tag);
8386 else if (tag === 'null_')
8387 return this._encodeNull();
8388 else if (tag === 'int' || tag === 'enum')
8389 return this._encodeInt(data, state.args && state.reverseArgs[0]);
8390 else if (tag === 'bool')
8391 return this._encodeBool(data);
8392 else if (tag === 'objDesc')
8393 return this._encodeStr(data, tag);
8394 else
8395 throw new Error('Unsupported tag: ' + tag);
8396};
8397
8398Node.prototype._isNumstr = function isNumstr(str) {
8399 return /^[0-9 ]*$/.test(str);
8400};
8401
8402Node.prototype._isPrintstr = function isPrintstr(str) {
8403 return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(str);
8404};
8405
8406},{"../base":63,"minimalistic-assert":167}],65:[function(require,module,exports){
8407var inherits = require('inherits');
8408
8409function Reporter(options) {
8410 this._reporterState = {
8411 obj: null,
8412 path: [],
8413 options: options || {},
8414 errors: []
8415 };
8416}
8417exports.Reporter = Reporter;
8418
8419Reporter.prototype.isError = function isError(obj) {
8420 return obj instanceof ReporterError;
8421};
8422
8423Reporter.prototype.save = function save() {
8424 var state = this._reporterState;
8425
8426 return { obj: state.obj, pathLen: state.path.length };
8427};
8428
8429Reporter.prototype.restore = function restore(data) {
8430 var state = this._reporterState;
8431
8432 state.obj = data.obj;
8433 state.path = state.path.slice(0, data.pathLen);
8434};
8435
8436Reporter.prototype.enterKey = function enterKey(key) {
8437 return this._reporterState.path.push(key);
8438};
8439
8440Reporter.prototype.exitKey = function exitKey(index) {
8441 var state = this._reporterState;
8442
8443 state.path = state.path.slice(0, index - 1);
8444};
8445
8446Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
8447 var state = this._reporterState;
8448
8449 this.exitKey(index);
8450 if (state.obj !== null)
8451 state.obj[key] = value;
8452};
8453
8454Reporter.prototype.path = function path() {
8455 return this._reporterState.path.join('/');
8456};
8457
8458Reporter.prototype.enterObject = function enterObject() {
8459 var state = this._reporterState;
8460
8461 var prev = state.obj;
8462 state.obj = {};
8463 return prev;
8464};
8465
8466Reporter.prototype.leaveObject = function leaveObject(prev) {
8467 var state = this._reporterState;
8468
8469 var now = state.obj;
8470 state.obj = prev;
8471 return now;
8472};
8473
8474Reporter.prototype.error = function error(msg) {
8475 var err;
8476 var state = this._reporterState;
8477
8478 var inherited = msg instanceof ReporterError;
8479 if (inherited) {
8480 err = msg;
8481 } else {
8482 err = new ReporterError(state.path.map(function(elem) {
8483 return '[' + JSON.stringify(elem) + ']';
8484 }).join(''), msg.message || msg, msg.stack);
8485 }
8486
8487 if (!state.options.partial)
8488 throw err;
8489
8490 if (!inherited)
8491 state.errors.push(err);
8492
8493 return err;
8494};
8495
8496Reporter.prototype.wrapResult = function wrapResult(result) {
8497 var state = this._reporterState;
8498 if (!state.options.partial)
8499 return result;
8500
8501 return {
8502 result: this.isError(result) ? null : result,
8503 errors: state.errors
8504 };
8505};
8506
8507function ReporterError(path, msg) {
8508 this.path = path;
8509 this.rethrow(msg);
8510};
8511inherits(ReporterError, Error);
8512
8513ReporterError.prototype.rethrow = function rethrow(msg) {
8514 this.message = msg + ' at: ' + (this.path || '(shallow)');
8515 if (Error.captureStackTrace)
8516 Error.captureStackTrace(this, ReporterError);
8517
8518 if (!this.stack) {
8519 try {
8520 // IE only adds stack when thrown
8521 throw new Error(this.message);
8522 } catch (e) {
8523 this.stack = e.stack;
8524 }
8525 }
8526 return this;
8527};
8528
8529},{"inherits":162}],66:[function(require,module,exports){
8530var constants = require('../constants');
8531
8532exports.tagClass = {
8533 0: 'universal',
8534 1: 'application',
8535 2: 'context',
8536 3: 'private'
8537};
8538exports.tagClassByName = constants._reverse(exports.tagClass);
8539
8540exports.tag = {
8541 0x00: 'end',
8542 0x01: 'bool',
8543 0x02: 'int',
8544 0x03: 'bitstr',
8545 0x04: 'octstr',
8546 0x05: 'null_',
8547 0x06: 'objid',
8548 0x07: 'objDesc',
8549 0x08: 'external',
8550 0x09: 'real',
8551 0x0a: 'enum',
8552 0x0b: 'embed',
8553 0x0c: 'utf8str',
8554 0x0d: 'relativeOid',
8555 0x10: 'seq',
8556 0x11: 'set',
8557 0x12: 'numstr',
8558 0x13: 'printstr',
8559 0x14: 't61str',
8560 0x15: 'videostr',
8561 0x16: 'ia5str',
8562 0x17: 'utctime',
8563 0x18: 'gentime',
8564 0x19: 'graphstr',
8565 0x1a: 'iso646str',
8566 0x1b: 'genstr',
8567 0x1c: 'unistr',
8568 0x1d: 'charstr',
8569 0x1e: 'bmpstr'
8570};
8571exports.tagByName = constants._reverse(exports.tag);
8572
8573},{"../constants":67}],67:[function(require,module,exports){
8574var constants = exports;
8575
8576// Helper
8577constants._reverse = function reverse(map) {
8578 var res = {};
8579
8580 Object.keys(map).forEach(function(key) {
8581 // Convert key to integer if it is stringified
8582 if ((key | 0) == key)
8583 key = key | 0;
8584
8585 var value = map[key];
8586 res[value] = key;
8587 });
8588
8589 return res;
8590};
8591
8592constants.der = require('./der');
8593
8594},{"./der":66}],68:[function(require,module,exports){
8595var inherits = require('inherits');
8596
8597var asn1 = require('../../asn1');
8598var base = asn1.base;
8599var bignum = asn1.bignum;
8600
8601// Import DER constants
8602var der = asn1.constants.der;
8603
8604function DERDecoder(entity) {
8605 this.enc = 'der';
8606 this.name = entity.name;
8607 this.entity = entity;
8608
8609 // Construct base tree
8610 this.tree = new DERNode();
8611 this.tree._init(entity.body);
8612};
8613module.exports = DERDecoder;
8614
8615DERDecoder.prototype.decode = function decode(data, options) {
8616 if (!(data instanceof base.DecoderBuffer))
8617 data = new base.DecoderBuffer(data, options);
8618
8619 return this.tree._decode(data, options);
8620};
8621
8622// Tree methods
8623
8624function DERNode(parent) {
8625 base.Node.call(this, 'der', parent);
8626}
8627inherits(DERNode, base.Node);
8628
8629DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
8630 if (buffer.isEmpty())
8631 return false;
8632
8633 var state = buffer.save();
8634 var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
8635 if (buffer.isError(decodedTag))
8636 return decodedTag;
8637
8638 buffer.restore(state);
8639
8640 return decodedTag.tag === tag || decodedTag.tagStr === tag ||
8641 (decodedTag.tagStr + 'of') === tag || any;
8642};
8643
8644DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
8645 var decodedTag = derDecodeTag(buffer,
8646 'Failed to decode tag of "' + tag + '"');
8647 if (buffer.isError(decodedTag))
8648 return decodedTag;
8649
8650 var len = derDecodeLen(buffer,
8651 decodedTag.primitive,
8652 'Failed to get length of "' + tag + '"');
8653
8654 // Failure
8655 if (buffer.isError(len))
8656 return len;
8657
8658 if (!any &&
8659 decodedTag.tag !== tag &&
8660 decodedTag.tagStr !== tag &&
8661 decodedTag.tagStr + 'of' !== tag) {
8662 return buffer.error('Failed to match tag: "' + tag + '"');
8663 }
8664
8665 if (decodedTag.primitive || len !== null)
8666 return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
8667
8668 // Indefinite length... find END tag
8669 var state = buffer.save();
8670 var res = this._skipUntilEnd(
8671 buffer,
8672 'Failed to skip indefinite length body: "' + this.tag + '"');
8673 if (buffer.isError(res))
8674 return res;
8675
8676 len = buffer.offset - state.offset;
8677 buffer.restore(state);
8678 return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
8679};
8680
8681DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
8682 while (true) {
8683 var tag = derDecodeTag(buffer, fail);
8684 if (buffer.isError(tag))
8685 return tag;
8686 var len = derDecodeLen(buffer, tag.primitive, fail);
8687 if (buffer.isError(len))
8688 return len;
8689
8690 var res;
8691 if (tag.primitive || len !== null)
8692 res = buffer.skip(len)
8693 else
8694 res = this._skipUntilEnd(buffer, fail);
8695
8696 // Failure
8697 if (buffer.isError(res))
8698 return res;
8699
8700 if (tag.tagStr === 'end')
8701 break;
8702 }
8703};
8704
8705DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder,
8706 options) {
8707 var result = [];
8708 while (!buffer.isEmpty()) {
8709 var possibleEnd = this._peekTag(buffer, 'end');
8710 if (buffer.isError(possibleEnd))
8711 return possibleEnd;
8712
8713 var res = decoder.decode(buffer, 'der', options);
8714 if (buffer.isError(res) && possibleEnd)
8715 break;
8716 result.push(res);
8717 }
8718 return result;
8719};
8720
8721DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
8722 if (tag === 'bitstr') {
8723 var unused = buffer.readUInt8();
8724 if (buffer.isError(unused))
8725 return unused;
8726 return { unused: unused, data: buffer.raw() };
8727 } else if (tag === 'bmpstr') {
8728 var raw = buffer.raw();
8729 if (raw.length % 2 === 1)
8730 return buffer.error('Decoding of string type: bmpstr length mismatch');
8731
8732 var str = '';
8733 for (var i = 0; i < raw.length / 2; i++) {
8734 str += String.fromCharCode(raw.readUInt16BE(i * 2));
8735 }
8736 return str;
8737 } else if (tag === 'numstr') {
8738 var numstr = buffer.raw().toString('ascii');
8739 if (!this._isNumstr(numstr)) {
8740 return buffer.error('Decoding of string type: ' +
8741 'numstr unsupported characters');
8742 }
8743 return numstr;
8744 } else if (tag === 'octstr') {
8745 return buffer.raw();
8746 } else if (tag === 'objDesc') {
8747 return buffer.raw();
8748 } else if (tag === 'printstr') {
8749 var printstr = buffer.raw().toString('ascii');
8750 if (!this._isPrintstr(printstr)) {
8751 return buffer.error('Decoding of string type: ' +
8752 'printstr unsupported characters');
8753 }
8754 return printstr;
8755 } else if (/str$/.test(tag)) {
8756 return buffer.raw().toString();
8757 } else {
8758 return buffer.error('Decoding of string type: ' + tag + ' unsupported');
8759 }
8760};
8761
8762DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
8763 var result;
8764 var identifiers = [];
8765 var ident = 0;
8766 while (!buffer.isEmpty()) {
8767 var subident = buffer.readUInt8();
8768 ident <<= 7;
8769 ident |= subident & 0x7f;
8770 if ((subident & 0x80) === 0) {
8771 identifiers.push(ident);
8772 ident = 0;
8773 }
8774 }
8775 if (subident & 0x80)
8776 identifiers.push(ident);
8777
8778 var first = (identifiers[0] / 40) | 0;
8779 var second = identifiers[0] % 40;
8780
8781 if (relative)
8782 result = identifiers;
8783 else
8784 result = [first, second].concat(identifiers.slice(1));
8785
8786 if (values) {
8787 var tmp = values[result.join(' ')];
8788 if (tmp === undefined)
8789 tmp = values[result.join('.')];
8790 if (tmp !== undefined)
8791 result = tmp;
8792 }
8793
8794 return result;
8795};
8796
8797DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
8798 var str = buffer.raw().toString();
8799 if (tag === 'gentime') {
8800 var year = str.slice(0, 4) | 0;
8801 var mon = str.slice(4, 6) | 0;
8802 var day = str.slice(6, 8) | 0;
8803 var hour = str.slice(8, 10) | 0;
8804 var min = str.slice(10, 12) | 0;
8805 var sec = str.slice(12, 14) | 0;
8806 } else if (tag === 'utctime') {
8807 var year = str.slice(0, 2) | 0;
8808 var mon = str.slice(2, 4) | 0;
8809 var day = str.slice(4, 6) | 0;
8810 var hour = str.slice(6, 8) | 0;
8811 var min = str.slice(8, 10) | 0;
8812 var sec = str.slice(10, 12) | 0;
8813 if (year < 70)
8814 year = 2000 + year;
8815 else
8816 year = 1900 + year;
8817 } else {
8818 return buffer.error('Decoding ' + tag + ' time is not supported yet');
8819 }
8820
8821 return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
8822};
8823
8824DERNode.prototype._decodeNull = function decodeNull(buffer) {
8825 return null;
8826};
8827
8828DERNode.prototype._decodeBool = function decodeBool(buffer) {
8829 var res = buffer.readUInt8();
8830 if (buffer.isError(res))
8831 return res;
8832 else
8833 return res !== 0;
8834};
8835
8836DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
8837 // Bigint, return as it is (assume big endian)
8838 var raw = buffer.raw();
8839 var res = new bignum(raw);
8840
8841 if (values)
8842 res = values[res.toString(10)] || res;
8843
8844 return res;
8845};
8846
8847DERNode.prototype._use = function use(entity, obj) {
8848 if (typeof entity === 'function')
8849 entity = entity(obj);
8850 return entity._getDecoder('der').tree;
8851};
8852
8853// Utility methods
8854
8855function derDecodeTag(buf, fail) {
8856 var tag = buf.readUInt8(fail);
8857 if (buf.isError(tag))
8858 return tag;
8859
8860 var cls = der.tagClass[tag >> 6];
8861 var primitive = (tag & 0x20) === 0;
8862
8863 // Multi-octet tag - load
8864 if ((tag & 0x1f) === 0x1f) {
8865 var oct = tag;
8866 tag = 0;
8867 while ((oct & 0x80) === 0x80) {
8868 oct = buf.readUInt8(fail);
8869 if (buf.isError(oct))
8870 return oct;
8871
8872 tag <<= 7;
8873 tag |= oct & 0x7f;
8874 }
8875 } else {
8876 tag &= 0x1f;
8877 }
8878 var tagStr = der.tag[tag];
8879
8880 return {
8881 cls: cls,
8882 primitive: primitive,
8883 tag: tag,
8884 tagStr: tagStr
8885 };
8886}
8887
8888function derDecodeLen(buf, primitive, fail) {
8889 var len = buf.readUInt8(fail);
8890 if (buf.isError(len))
8891 return len;
8892
8893 // Indefinite form
8894 if (!primitive && len === 0x80)
8895 return null;
8896
8897 // Definite form
8898 if ((len & 0x80) === 0) {
8899 // Short form
8900 return len;
8901 }
8902
8903 // Long form
8904 var num = len & 0x7f;
8905 if (num > 4)
8906 return buf.error('length octect is too long');
8907
8908 len = 0;
8909 for (var i = 0; i < num; i++) {
8910 len <<= 8;
8911 var j = buf.readUInt8(fail);
8912 if (buf.isError(j))
8913 return j;
8914 len |= j;
8915 }
8916
8917 return len;
8918}
8919
8920},{"../../asn1":60,"inherits":162}],69:[function(require,module,exports){
8921var decoders = exports;
8922
8923decoders.der = require('./der');
8924decoders.pem = require('./pem');
8925
8926},{"./der":68,"./pem":70}],70:[function(require,module,exports){
8927var inherits = require('inherits');
8928var Buffer = require('buffer').Buffer;
8929
8930var DERDecoder = require('./der');
8931
8932function PEMDecoder(entity) {
8933 DERDecoder.call(this, entity);
8934 this.enc = 'pem';
8935};
8936inherits(PEMDecoder, DERDecoder);
8937module.exports = PEMDecoder;
8938
8939PEMDecoder.prototype.decode = function decode(data, options) {
8940 var lines = data.toString().split(/[\r\n]+/g);
8941
8942 var label = options.label.toUpperCase();
8943
8944 var re = /^-----(BEGIN|END) ([^-]+)-----$/;
8945 var start = -1;
8946 var end = -1;
8947 for (var i = 0; i < lines.length; i++) {
8948 var match = lines[i].match(re);
8949 if (match === null)
8950 continue;
8951
8952 if (match[2] !== label)
8953 continue;
8954
8955 if (start === -1) {
8956 if (match[1] !== 'BEGIN')
8957 break;
8958 start = i;
8959 } else {
8960 if (match[1] !== 'END')
8961 break;
8962 end = i;
8963 break;
8964 }
8965 }
8966 if (start === -1 || end === -1)
8967 throw new Error('PEM section not found for: ' + label);
8968
8969 var base64 = lines.slice(start + 1, end).join('');
8970 // Remove excessive symbols
8971 base64.replace(/[^a-z0-9\+\/=]+/gi, '');
8972
8973 var input = new Buffer(base64, 'base64');
8974 return DERDecoder.prototype.decode.call(this, input, options);
8975};
8976
8977},{"./der":68,"buffer":110,"inherits":162}],71:[function(require,module,exports){
8978var inherits = require('inherits');
8979var Buffer = require('buffer').Buffer;
8980
8981var asn1 = require('../../asn1');
8982var base = asn1.base;
8983
8984// Import DER constants
8985var der = asn1.constants.der;
8986
8987function DEREncoder(entity) {
8988 this.enc = 'der';
8989 this.name = entity.name;
8990 this.entity = entity;
8991
8992 // Construct base tree
8993 this.tree = new DERNode();
8994 this.tree._init(entity.body);
8995};
8996module.exports = DEREncoder;
8997
8998DEREncoder.prototype.encode = function encode(data, reporter) {
8999 return this.tree._encode(data, reporter).join();
9000};
9001
9002// Tree methods
9003
9004function DERNode(parent) {
9005 base.Node.call(this, 'der', parent);
9006}
9007inherits(DERNode, base.Node);
9008
9009DERNode.prototype._encodeComposite = function encodeComposite(tag,
9010 primitive,
9011 cls,
9012 content) {
9013 var encodedTag = encodeTag(tag, primitive, cls, this.reporter);
9014
9015 // Short form
9016 if (content.length < 0x80) {
9017 var header = new Buffer(2);
9018 header[0] = encodedTag;
9019 header[1] = content.length;
9020 return this._createEncoderBuffer([ header, content ]);
9021 }
9022
9023 // Long form
9024 // Count octets required to store length
9025 var lenOctets = 1;
9026 for (var i = content.length; i >= 0x100; i >>= 8)
9027 lenOctets++;
9028
9029 var header = new Buffer(1 + 1 + lenOctets);
9030 header[0] = encodedTag;
9031 header[1] = 0x80 | lenOctets;
9032
9033 for (var i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8)
9034 header[i] = j & 0xff;
9035
9036 return this._createEncoderBuffer([ header, content ]);
9037};
9038
9039DERNode.prototype._encodeStr = function encodeStr(str, tag) {
9040 if (tag === 'bitstr') {
9041 return this._createEncoderBuffer([ str.unused | 0, str.data ]);
9042 } else if (tag === 'bmpstr') {
9043 var buf = new Buffer(str.length * 2);
9044 for (var i = 0; i < str.length; i++) {
9045 buf.writeUInt16BE(str.charCodeAt(i), i * 2);
9046 }
9047 return this._createEncoderBuffer(buf);
9048 } else if (tag === 'numstr') {
9049 if (!this._isNumstr(str)) {
9050 return this.reporter.error('Encoding of string type: numstr supports ' +
9051 'only digits and space');
9052 }
9053 return this._createEncoderBuffer(str);
9054 } else if (tag === 'printstr') {
9055 if (!this._isPrintstr(str)) {
9056 return this.reporter.error('Encoding of string type: printstr supports ' +
9057 'only latin upper and lower case letters, ' +
9058 'digits, space, apostrophe, left and rigth ' +
9059 'parenthesis, plus sign, comma, hyphen, ' +
9060 'dot, slash, colon, equal sign, ' +
9061 'question mark');
9062 }
9063 return this._createEncoderBuffer(str);
9064 } else if (/str$/.test(tag)) {
9065 return this._createEncoderBuffer(str);
9066 } else if (tag === 'objDesc') {
9067 return this._createEncoderBuffer(str);
9068 } else {
9069 return this.reporter.error('Encoding of string type: ' + tag +
9070 ' unsupported');
9071 }
9072};
9073
9074DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
9075 if (typeof id === 'string') {
9076 if (!values)
9077 return this.reporter.error('string objid given, but no values map found');
9078 if (!values.hasOwnProperty(id))
9079 return this.reporter.error('objid not found in values map');
9080 id = values[id].split(/[\s\.]+/g);
9081 for (var i = 0; i < id.length; i++)
9082 id[i] |= 0;
9083 } else if (Array.isArray(id)) {
9084 id = id.slice();
9085 for (var i = 0; i < id.length; i++)
9086 id[i] |= 0;
9087 }
9088
9089 if (!Array.isArray(id)) {
9090 return this.reporter.error('objid() should be either array or string, ' +
9091 'got: ' + JSON.stringify(id));
9092 }
9093
9094 if (!relative) {
9095 if (id[1] >= 40)
9096 return this.reporter.error('Second objid identifier OOB');
9097 id.splice(0, 2, id[0] * 40 + id[1]);
9098 }
9099
9100 // Count number of octets
9101 var size = 0;
9102 for (var i = 0; i < id.length; i++) {
9103 var ident = id[i];
9104 for (size++; ident >= 0x80; ident >>= 7)
9105 size++;
9106 }
9107
9108 var objid = new Buffer(size);
9109 var offset = objid.length - 1;
9110 for (var i = id.length - 1; i >= 0; i--) {
9111 var ident = id[i];
9112 objid[offset--] = ident & 0x7f;
9113 while ((ident >>= 7) > 0)
9114 objid[offset--] = 0x80 | (ident & 0x7f);
9115 }
9116
9117 return this._createEncoderBuffer(objid);
9118};
9119
9120function two(num) {
9121 if (num < 10)
9122 return '0' + num;
9123 else
9124 return num;
9125}
9126
9127DERNode.prototype._encodeTime = function encodeTime(time, tag) {
9128 var str;
9129 var date = new Date(time);
9130
9131 if (tag === 'gentime') {
9132 str = [
9133 two(date.getFullYear()),
9134 two(date.getUTCMonth() + 1),
9135 two(date.getUTCDate()),
9136 two(date.getUTCHours()),
9137 two(date.getUTCMinutes()),
9138 two(date.getUTCSeconds()),
9139 'Z'
9140 ].join('');
9141 } else if (tag === 'utctime') {
9142 str = [
9143 two(date.getFullYear() % 100),
9144 two(date.getUTCMonth() + 1),
9145 two(date.getUTCDate()),
9146 two(date.getUTCHours()),
9147 two(date.getUTCMinutes()),
9148 two(date.getUTCSeconds()),
9149 'Z'
9150 ].join('');
9151 } else {
9152 this.reporter.error('Encoding ' + tag + ' time is not supported yet');
9153 }
9154
9155 return this._encodeStr(str, 'octstr');
9156};
9157
9158DERNode.prototype._encodeNull = function encodeNull() {
9159 return this._createEncoderBuffer('');
9160};
9161
9162DERNode.prototype._encodeInt = function encodeInt(num, values) {
9163 if (typeof num === 'string') {
9164 if (!values)
9165 return this.reporter.error('String int or enum given, but no values map');
9166 if (!values.hasOwnProperty(num)) {
9167 return this.reporter.error('Values map doesn\'t contain: ' +
9168 JSON.stringify(num));
9169 }
9170 num = values[num];
9171 }
9172
9173 // Bignum, assume big endian
9174 if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
9175 var numArray = num.toArray();
9176 if (!num.sign && numArray[0] & 0x80) {
9177 numArray.unshift(0);
9178 }
9179 num = new Buffer(numArray);
9180 }
9181
9182 if (Buffer.isBuffer(num)) {
9183 var size = num.length;
9184 if (num.length === 0)
9185 size++;
9186
9187 var out = new Buffer(size);
9188 num.copy(out);
9189 if (num.length === 0)
9190 out[0] = 0
9191 return this._createEncoderBuffer(out);
9192 }
9193
9194 if (num < 0x80)
9195 return this._createEncoderBuffer(num);
9196
9197 if (num < 0x100)
9198 return this._createEncoderBuffer([0, num]);
9199
9200 var size = 1;
9201 for (var i = num; i >= 0x100; i >>= 8)
9202 size++;
9203
9204 var out = new Array(size);
9205 for (var i = out.length - 1; i >= 0; i--) {
9206 out[i] = num & 0xff;
9207 num >>= 8;
9208 }
9209 if(out[0] & 0x80) {
9210 out.unshift(0);
9211 }
9212
9213 return this._createEncoderBuffer(new Buffer(out));
9214};
9215
9216DERNode.prototype._encodeBool = function encodeBool(value) {
9217 return this._createEncoderBuffer(value ? 0xff : 0);
9218};
9219
9220DERNode.prototype._use = function use(entity, obj) {
9221 if (typeof entity === 'function')
9222 entity = entity(obj);
9223 return entity._getEncoder('der').tree;
9224};
9225
9226DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
9227 var state = this._baseState;
9228 var i;
9229 if (state['default'] === null)
9230 return false;
9231
9232 var data = dataBuffer.join();
9233 if (state.defaultBuffer === undefined)
9234 state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
9235
9236 if (data.length !== state.defaultBuffer.length)
9237 return false;
9238
9239 for (i=0; i < data.length; i++)
9240 if (data[i] !== state.defaultBuffer[i])
9241 return false;
9242
9243 return true;
9244};
9245
9246// Utility methods
9247
9248function encodeTag(tag, primitive, cls, reporter) {
9249 var res;
9250
9251 if (tag === 'seqof')
9252 tag = 'seq';
9253 else if (tag === 'setof')
9254 tag = 'set';
9255
9256 if (der.tagByName.hasOwnProperty(tag))
9257 res = der.tagByName[tag];
9258 else if (typeof tag === 'number' && (tag | 0) === tag)
9259 res = tag;
9260 else
9261 return reporter.error('Unknown tag: ' + tag);
9262
9263 if (res >= 0x1f)
9264 return reporter.error('Multi-octet tag encoding unsupported');
9265
9266 if (!primitive)
9267 res |= 0x20;
9268
9269 res |= (der.tagClassByName[cls || 'universal'] << 6);
9270
9271 return res;
9272}
9273
9274},{"../../asn1":60,"buffer":110,"inherits":162}],72:[function(require,module,exports){
9275var encoders = exports;
9276
9277encoders.der = require('./der');
9278encoders.pem = require('./pem');
9279
9280},{"./der":71,"./pem":73}],73:[function(require,module,exports){
9281var inherits = require('inherits');
9282
9283var DEREncoder = require('./der');
9284
9285function PEMEncoder(entity) {
9286 DEREncoder.call(this, entity);
9287 this.enc = 'pem';
9288};
9289inherits(PEMEncoder, DEREncoder);
9290module.exports = PEMEncoder;
9291
9292PEMEncoder.prototype.encode = function encode(data, options) {
9293 var buf = DEREncoder.prototype.encode.call(this, data);
9294
9295 var p = buf.toString('base64');
9296 var out = [ '-----BEGIN ' + options.label + '-----' ];
9297 for (var i = 0; i < p.length; i += 64)
9298 out.push(p.slice(i, i + 64));
9299 out.push('-----END ' + options.label + '-----');
9300 return out.join('\n');
9301};
9302
9303},{"./der":71,"inherits":162}],74:[function(require,module,exports){
9304(function (global){
9305'use strict';
9306
9307var objectAssign = require('object-assign');
9308
9309// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
9310// original notice:
9311
9312/*!
9313 * The buffer module from node.js, for the browser.
9314 *
9315 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
9316 * @license MIT
9317 */
9318function compare(a, b) {
9319 if (a === b) {
9320 return 0;
9321 }
9322
9323 var x = a.length;
9324 var y = b.length;
9325
9326 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
9327 if (a[i] !== b[i]) {
9328 x = a[i];
9329 y = b[i];
9330 break;
9331 }
9332 }
9333
9334 if (x < y) {
9335 return -1;
9336 }
9337 if (y < x) {
9338 return 1;
9339 }
9340 return 0;
9341}
9342function isBuffer(b) {
9343 if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
9344 return global.Buffer.isBuffer(b);
9345 }
9346 return !!(b != null && b._isBuffer);
9347}
9348
9349// based on node assert, original notice:
9350// NB: The URL to the CommonJS spec is kept just for tradition.
9351// node-assert has evolved a lot since then, both in API and behavior.
9352
9353// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
9354//
9355// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
9356//
9357// Originally from narwhal.js (http://narwhaljs.org)
9358// Copyright (c) 2009 Thomas Robinson <280north.com>
9359//
9360// Permission is hereby granted, free of charge, to any person obtaining a copy
9361// of this software and associated documentation files (the 'Software'), to
9362// deal in the Software without restriction, including without limitation the
9363// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9364// sell copies of the Software, and to permit persons to whom the Software is
9365// furnished to do so, subject to the following conditions:
9366//
9367// The above copyright notice and this permission notice shall be included in
9368// all copies or substantial portions of the Software.
9369//
9370// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9371// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9372// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9373// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
9374// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
9375// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9376
9377var util = require('util/');
9378var hasOwn = Object.prototype.hasOwnProperty;
9379var pSlice = Array.prototype.slice;
9380var functionsHaveNames = (function () {
9381 return function foo() {}.name === 'foo';
9382}());
9383function pToString (obj) {
9384 return Object.prototype.toString.call(obj);
9385}
9386function isView(arrbuf) {
9387 if (isBuffer(arrbuf)) {
9388 return false;
9389 }
9390 if (typeof global.ArrayBuffer !== 'function') {
9391 return false;
9392 }
9393 if (typeof ArrayBuffer.isView === 'function') {
9394 return ArrayBuffer.isView(arrbuf);
9395 }
9396 if (!arrbuf) {
9397 return false;
9398 }
9399 if (arrbuf instanceof DataView) {
9400 return true;
9401 }
9402 if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
9403 return true;
9404 }
9405 return false;
9406}
9407// 1. The assert module provides functions that throw
9408// AssertionError's when particular conditions are not met. The
9409// assert module must conform to the following interface.
9410
9411var assert = module.exports = ok;
9412
9413// 2. The AssertionError is defined in assert.
9414// new assert.AssertionError({ message: message,
9415// actual: actual,
9416// expected: expected })
9417
9418var regex = /\s*function\s+([^\(\s]*)\s*/;
9419// based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
9420function getName(func) {
9421 if (!util.isFunction(func)) {
9422 return;
9423 }
9424 if (functionsHaveNames) {
9425 return func.name;
9426 }
9427 var str = func.toString();
9428 var match = str.match(regex);
9429 return match && match[1];
9430}
9431assert.AssertionError = function AssertionError(options) {
9432 this.name = 'AssertionError';
9433 this.actual = options.actual;
9434 this.expected = options.expected;
9435 this.operator = options.operator;
9436 if (options.message) {
9437 this.message = options.message;
9438 this.generatedMessage = false;
9439 } else {
9440 this.message = getMessage(this);
9441 this.generatedMessage = true;
9442 }
9443 var stackStartFunction = options.stackStartFunction || fail;
9444 if (Error.captureStackTrace) {
9445 Error.captureStackTrace(this, stackStartFunction);
9446 } else {
9447 // non v8 browsers so we can have a stacktrace
9448 var err = new Error();
9449 if (err.stack) {
9450 var out = err.stack;
9451
9452 // try to strip useless frames
9453 var fn_name = getName(stackStartFunction);
9454 var idx = out.indexOf('\n' + fn_name);
9455 if (idx >= 0) {
9456 // once we have located the function frame
9457 // we need to strip out everything before it (and its line)
9458 var next_line = out.indexOf('\n', idx + 1);
9459 out = out.substring(next_line + 1);
9460 }
9461
9462 this.stack = out;
9463 }
9464 }
9465};
9466
9467// assert.AssertionError instanceof Error
9468util.inherits(assert.AssertionError, Error);
9469
9470function truncate(s, n) {
9471 if (typeof s === 'string') {
9472 return s.length < n ? s : s.slice(0, n);
9473 } else {
9474 return s;
9475 }
9476}
9477function inspect(something) {
9478 if (functionsHaveNames || !util.isFunction(something)) {
9479 return util.inspect(something);
9480 }
9481 var rawname = getName(something);
9482 var name = rawname ? ': ' + rawname : '';
9483 return '[Function' + name + ']';
9484}
9485function getMessage(self) {
9486 return truncate(inspect(self.actual), 128) + ' ' +
9487 self.operator + ' ' +
9488 truncate(inspect(self.expected), 128);
9489}
9490
9491// At present only the three keys mentioned above are used and
9492// understood by the spec. Implementations or sub modules can pass
9493// other keys to the AssertionError's constructor - they will be
9494// ignored.
9495
9496// 3. All of the following functions must throw an AssertionError
9497// when a corresponding condition is not met, with a message that
9498// may be undefined if not provided. All assertion methods provide
9499// both the actual and expected values to the assertion error for
9500// display purposes.
9501
9502function fail(actual, expected, message, operator, stackStartFunction) {
9503 throw new assert.AssertionError({
9504 message: message,
9505 actual: actual,
9506 expected: expected,
9507 operator: operator,
9508 stackStartFunction: stackStartFunction
9509 });
9510}
9511
9512// EXTENSION! allows for well behaved errors defined elsewhere.
9513assert.fail = fail;
9514
9515// 4. Pure assertion tests whether a value is truthy, as determined
9516// by !!guard.
9517// assert.ok(guard, message_opt);
9518// This statement is equivalent to assert.equal(true, !!guard,
9519// message_opt);. To test strictly for the value true, use
9520// assert.strictEqual(true, guard, message_opt);.
9521
9522function ok(value, message) {
9523 if (!value) fail(value, true, message, '==', assert.ok);
9524}
9525assert.ok = ok;
9526
9527// 5. The equality assertion tests shallow, coercive equality with
9528// ==.
9529// assert.equal(actual, expected, message_opt);
9530
9531assert.equal = function equal(actual, expected, message) {
9532 if (actual != expected) fail(actual, expected, message, '==', assert.equal);
9533};
9534
9535// 6. The non-equality assertion tests for whether two objects are not equal
9536// with != assert.notEqual(actual, expected, message_opt);
9537
9538assert.notEqual = function notEqual(actual, expected, message) {
9539 if (actual == expected) {
9540 fail(actual, expected, message, '!=', assert.notEqual);
9541 }
9542};
9543
9544// 7. The equivalence assertion tests a deep equality relation.
9545// assert.deepEqual(actual, expected, message_opt);
9546
9547assert.deepEqual = function deepEqual(actual, expected, message) {
9548 if (!_deepEqual(actual, expected, false)) {
9549 fail(actual, expected, message, 'deepEqual', assert.deepEqual);
9550 }
9551};
9552
9553assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
9554 if (!_deepEqual(actual, expected, true)) {
9555 fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
9556 }
9557};
9558
9559function _deepEqual(actual, expected, strict, memos) {
9560 // 7.1. All identical values are equivalent, as determined by ===.
9561 if (actual === expected) {
9562 return true;
9563 } else if (isBuffer(actual) && isBuffer(expected)) {
9564 return compare(actual, expected) === 0;
9565
9566 // 7.2. If the expected value is a Date object, the actual value is
9567 // equivalent if it is also a Date object that refers to the same time.
9568 } else if (util.isDate(actual) && util.isDate(expected)) {
9569 return actual.getTime() === expected.getTime();
9570
9571 // 7.3 If the expected value is a RegExp object, the actual value is
9572 // equivalent if it is also a RegExp object with the same source and
9573 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
9574 } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
9575 return actual.source === expected.source &&
9576 actual.global === expected.global &&
9577 actual.multiline === expected.multiline &&
9578 actual.lastIndex === expected.lastIndex &&
9579 actual.ignoreCase === expected.ignoreCase;
9580
9581 // 7.4. Other pairs that do not both pass typeof value == 'object',
9582 // equivalence is determined by ==.
9583 } else if ((actual === null || typeof actual !== 'object') &&
9584 (expected === null || typeof expected !== 'object')) {
9585 return strict ? actual === expected : actual == expected;
9586
9587 // If both values are instances of typed arrays, wrap their underlying
9588 // ArrayBuffers in a Buffer each to increase performance
9589 // This optimization requires the arrays to have the same type as checked by
9590 // Object.prototype.toString (aka pToString). Never perform binary
9591 // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
9592 // bit patterns are not identical.
9593 } else if (isView(actual) && isView(expected) &&
9594 pToString(actual) === pToString(expected) &&
9595 !(actual instanceof Float32Array ||
9596 actual instanceof Float64Array)) {
9597 return compare(new Uint8Array(actual.buffer),
9598 new Uint8Array(expected.buffer)) === 0;
9599
9600 // 7.5 For all other Object pairs, including Array objects, equivalence is
9601 // determined by having the same number of owned properties (as verified
9602 // with Object.prototype.hasOwnProperty.call), the same set of keys
9603 // (although not necessarily the same order), equivalent values for every
9604 // corresponding key, and an identical 'prototype' property. Note: this
9605 // accounts for both named and indexed properties on Arrays.
9606 } else if (isBuffer(actual) !== isBuffer(expected)) {
9607 return false;
9608 } else {
9609 memos = memos || {actual: [], expected: []};
9610
9611 var actualIndex = memos.actual.indexOf(actual);
9612 if (actualIndex !== -1) {
9613 if (actualIndex === memos.expected.indexOf(expected)) {
9614 return true;
9615 }
9616 }
9617
9618 memos.actual.push(actual);
9619 memos.expected.push(expected);
9620
9621 return objEquiv(actual, expected, strict, memos);
9622 }
9623}
9624
9625function isArguments(object) {
9626 return Object.prototype.toString.call(object) == '[object Arguments]';
9627}
9628
9629function objEquiv(a, b, strict, actualVisitedObjects) {
9630 if (a === null || a === undefined || b === null || b === undefined)
9631 return false;
9632 // if one is a primitive, the other must be same
9633 if (util.isPrimitive(a) || util.isPrimitive(b))
9634 return a === b;
9635 if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
9636 return false;
9637 var aIsArgs = isArguments(a);
9638 var bIsArgs = isArguments(b);
9639 if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
9640 return false;
9641 if (aIsArgs) {
9642 a = pSlice.call(a);
9643 b = pSlice.call(b);
9644 return _deepEqual(a, b, strict);
9645 }
9646 var ka = objectKeys(a);
9647 var kb = objectKeys(b);
9648 var key, i;
9649 // having the same number of owned properties (keys incorporates
9650 // hasOwnProperty)
9651 if (ka.length !== kb.length)
9652 return false;
9653 //the same set of keys (although not necessarily the same order),
9654 ka.sort();
9655 kb.sort();
9656 //~~~cheap key test
9657 for (i = ka.length - 1; i >= 0; i--) {
9658 if (ka[i] !== kb[i])
9659 return false;
9660 }
9661 //equivalent values for every corresponding key, and
9662 //~~~possibly expensive deep test
9663 for (i = ka.length - 1; i >= 0; i--) {
9664 key = ka[i];
9665 if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
9666 return false;
9667 }
9668 return true;
9669}
9670
9671// 8. The non-equivalence assertion tests for any deep inequality.
9672// assert.notDeepEqual(actual, expected, message_opt);
9673
9674assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
9675 if (_deepEqual(actual, expected, false)) {
9676 fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
9677 }
9678};
9679
9680assert.notDeepStrictEqual = notDeepStrictEqual;
9681function notDeepStrictEqual(actual, expected, message) {
9682 if (_deepEqual(actual, expected, true)) {
9683 fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
9684 }
9685}
9686
9687
9688// 9. The strict equality assertion tests strict equality, as determined by ===.
9689// assert.strictEqual(actual, expected, message_opt);
9690
9691assert.strictEqual = function strictEqual(actual, expected, message) {
9692 if (actual !== expected) {
9693 fail(actual, expected, message, '===', assert.strictEqual);
9694 }
9695};
9696
9697// 10. The strict non-equality assertion tests for strict inequality, as
9698// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
9699
9700assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
9701 if (actual === expected) {
9702 fail(actual, expected, message, '!==', assert.notStrictEqual);
9703 }
9704};
9705
9706function expectedException(actual, expected) {
9707 if (!actual || !expected) {
9708 return false;
9709 }
9710
9711 if (Object.prototype.toString.call(expected) == '[object RegExp]') {
9712 return expected.test(actual);
9713 }
9714
9715 try {
9716 if (actual instanceof expected) {
9717 return true;
9718 }
9719 } catch (e) {
9720 // Ignore. The instanceof check doesn't work for arrow functions.
9721 }
9722
9723 if (Error.isPrototypeOf(expected)) {
9724 return false;
9725 }
9726
9727 return expected.call({}, actual) === true;
9728}
9729
9730function _tryBlock(block) {
9731 var error;
9732 try {
9733 block();
9734 } catch (e) {
9735 error = e;
9736 }
9737 return error;
9738}
9739
9740function _throws(shouldThrow, block, expected, message) {
9741 var actual;
9742
9743 if (typeof block !== 'function') {
9744 throw new TypeError('"block" argument must be a function');
9745 }
9746
9747 if (typeof expected === 'string') {
9748 message = expected;
9749 expected = null;
9750 }
9751
9752 actual = _tryBlock(block);
9753
9754 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
9755 (message ? ' ' + message : '.');
9756
9757 if (shouldThrow && !actual) {
9758 fail(actual, expected, 'Missing expected exception' + message);
9759 }
9760
9761 var userProvidedMessage = typeof message === 'string';
9762 var isUnwantedException = !shouldThrow && util.isError(actual);
9763 var isUnexpectedException = !shouldThrow && actual && !expected;
9764
9765 if ((isUnwantedException &&
9766 userProvidedMessage &&
9767 expectedException(actual, expected)) ||
9768 isUnexpectedException) {
9769 fail(actual, expected, 'Got unwanted exception' + message);
9770 }
9771
9772 if ((shouldThrow && actual && expected &&
9773 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
9774 throw actual;
9775 }
9776}
9777
9778// 11. Expected to throw an error:
9779// assert.throws(block, Error_opt, message_opt);
9780
9781assert.throws = function(block, /*optional*/error, /*optional*/message) {
9782 _throws(true, block, error, message);
9783};
9784
9785// EXTENSION! This is annoying to write outside this module.
9786assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
9787 _throws(false, block, error, message);
9788};
9789
9790assert.ifError = function(err) { if (err) throw err; };
9791
9792// Expose a strict only variant of assert
9793function strict(value, message) {
9794 if (!value) fail(value, true, message, '==', strict);
9795}
9796assert.strict = objectAssign(strict, assert, {
9797 equal: assert.strictEqual,
9798 deepEqual: assert.deepStrictEqual,
9799 notEqual: assert.notStrictEqual,
9800 notDeepEqual: assert.notDeepStrictEqual
9801});
9802assert.strict.strict = assert.strict;
9803
9804var objectKeys = Object.keys || function (obj) {
9805 var keys = [];
9806 for (var key in obj) {
9807 if (hasOwn.call(obj, key)) keys.push(key);
9808 }
9809 return keys;
9810};
9811
9812}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
9813},{"object-assign":169,"util/":77}],75:[function(require,module,exports){
9814if (typeof Object.create === 'function') {
9815 // implementation from standard node.js 'util' module
9816 module.exports = function inherits(ctor, superCtor) {
9817 ctor.super_ = superCtor
9818 ctor.prototype = Object.create(superCtor.prototype, {
9819 constructor: {
9820 value: ctor,
9821 enumerable: false,
9822 writable: true,
9823 configurable: true
9824 }
9825 });
9826 };
9827} else {
9828 // old school shim for old browsers
9829 module.exports = function inherits(ctor, superCtor) {
9830 ctor.super_ = superCtor
9831 var TempCtor = function () {}
9832 TempCtor.prototype = superCtor.prototype
9833 ctor.prototype = new TempCtor()
9834 ctor.prototype.constructor = ctor
9835 }
9836}
9837
9838},{}],76:[function(require,module,exports){
9839module.exports = function isBuffer(arg) {
9840 return arg && typeof arg === 'object'
9841 && typeof arg.copy === 'function'
9842 && typeof arg.fill === 'function'
9843 && typeof arg.readUInt8 === 'function';
9844}
9845},{}],77:[function(require,module,exports){
9846(function (process,global){
9847// Copyright Joyent, Inc. and other Node contributors.
9848//
9849// Permission is hereby granted, free of charge, to any person obtaining a
9850// copy of this software and associated documentation files (the
9851// "Software"), to deal in the Software without restriction, including
9852// without limitation the rights to use, copy, modify, merge, publish,
9853// distribute, sublicense, and/or sell copies of the Software, and to permit
9854// persons to whom the Software is furnished to do so, subject to the
9855// following conditions:
9856//
9857// The above copyright notice and this permission notice shall be included
9858// in all copies or substantial portions of the Software.
9859//
9860// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
9861// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9862// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
9863// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9864// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
9865// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
9866// USE OR OTHER DEALINGS IN THE SOFTWARE.
9867
9868var formatRegExp = /%[sdj%]/g;
9869exports.format = function(f) {
9870 if (!isString(f)) {
9871 var objects = [];
9872 for (var i = 0; i < arguments.length; i++) {
9873 objects.push(inspect(arguments[i]));
9874 }
9875 return objects.join(' ');
9876 }
9877
9878 var i = 1;
9879 var args = arguments;
9880 var len = args.length;
9881 var str = String(f).replace(formatRegExp, function(x) {
9882 if (x === '%%') return '%';
9883 if (i >= len) return x;
9884 switch (x) {
9885 case '%s': return String(args[i++]);
9886 case '%d': return Number(args[i++]);
9887 case '%j':
9888 try {
9889 return JSON.stringify(args[i++]);
9890 } catch (_) {
9891 return '[Circular]';
9892 }
9893 default:
9894 return x;
9895 }
9896 });
9897 for (var x = args[i]; i < len; x = args[++i]) {
9898 if (isNull(x) || !isObject(x)) {
9899 str += ' ' + x;
9900 } else {
9901 str += ' ' + inspect(x);
9902 }
9903 }
9904 return str;
9905};
9906
9907
9908// Mark that a method should not be used.
9909// Returns a modified function which warns once by default.
9910// If --no-deprecation is set, then it is a no-op.
9911exports.deprecate = function(fn, msg) {
9912 // Allow for deprecating things in the process of starting up.
9913 if (isUndefined(global.process)) {
9914 return function() {
9915 return exports.deprecate(fn, msg).apply(this, arguments);
9916 };
9917 }
9918
9919 if (process.noDeprecation === true) {
9920 return fn;
9921 }
9922
9923 var warned = false;
9924 function deprecated() {
9925 if (!warned) {
9926 if (process.throwDeprecation) {
9927 throw new Error(msg);
9928 } else if (process.traceDeprecation) {
9929 console.trace(msg);
9930 } else {
9931 console.error(msg);
9932 }
9933 warned = true;
9934 }
9935 return fn.apply(this, arguments);
9936 }
9937
9938 return deprecated;
9939};
9940
9941
9942var debugs = {};
9943var debugEnviron;
9944exports.debuglog = function(set) {
9945 if (isUndefined(debugEnviron))
9946 debugEnviron = process.env.NODE_DEBUG || '';
9947 set = set.toUpperCase();
9948 if (!debugs[set]) {
9949 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
9950 var pid = process.pid;
9951 debugs[set] = function() {
9952 var msg = exports.format.apply(exports, arguments);
9953 console.error('%s %d: %s', set, pid, msg);
9954 };
9955 } else {
9956 debugs[set] = function() {};
9957 }
9958 }
9959 return debugs[set];
9960};
9961
9962
9963/**
9964 * Echos the value of a value. Trys to print the value out
9965 * in the best way possible given the different types.
9966 *
9967 * @param {Object} obj The object to print out.
9968 * @param {Object} opts Optional options object that alters the output.
9969 */
9970/* legacy: obj, showHidden, depth, colors*/
9971function inspect(obj, opts) {
9972 // default options
9973 var ctx = {
9974 seen: [],
9975 stylize: stylizeNoColor
9976 };
9977 // legacy...
9978 if (arguments.length >= 3) ctx.depth = arguments[2];
9979 if (arguments.length >= 4) ctx.colors = arguments[3];
9980 if (isBoolean(opts)) {
9981 // legacy...
9982 ctx.showHidden = opts;
9983 } else if (opts) {
9984 // got an "options" object
9985 exports._extend(ctx, opts);
9986 }
9987 // set default options
9988 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
9989 if (isUndefined(ctx.depth)) ctx.depth = 2;
9990 if (isUndefined(ctx.colors)) ctx.colors = false;
9991 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
9992 if (ctx.colors) ctx.stylize = stylizeWithColor;
9993 return formatValue(ctx, obj, ctx.depth);
9994}
9995exports.inspect = inspect;
9996
9997
9998// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
9999inspect.colors = {
10000 'bold' : [1, 22],
10001 'italic' : [3, 23],
10002 'underline' : [4, 24],
10003 'inverse' : [7, 27],
10004 'white' : [37, 39],
10005 'grey' : [90, 39],
10006 'black' : [30, 39],
10007 'blue' : [34, 39],
10008 'cyan' : [36, 39],
10009 'green' : [32, 39],
10010 'magenta' : [35, 39],
10011 'red' : [31, 39],
10012 'yellow' : [33, 39]
10013};
10014
10015// Don't use 'blue' not visible on cmd.exe
10016inspect.styles = {
10017 'special': 'cyan',
10018 'number': 'yellow',
10019 'boolean': 'yellow',
10020 'undefined': 'grey',
10021 'null': 'bold',
10022 'string': 'green',
10023 'date': 'magenta',
10024 // "name": intentionally not styling
10025 'regexp': 'red'
10026};
10027
10028
10029function stylizeWithColor(str, styleType) {
10030 var style = inspect.styles[styleType];
10031
10032 if (style) {
10033 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
10034 '\u001b[' + inspect.colors[style][1] + 'm';
10035 } else {
10036 return str;
10037 }
10038}
10039
10040
10041function stylizeNoColor(str, styleType) {
10042 return str;
10043}
10044
10045
10046function arrayToHash(array) {
10047 var hash = {};
10048
10049 array.forEach(function(val, idx) {
10050 hash[val] = true;
10051 });
10052
10053 return hash;
10054}
10055
10056
10057function formatValue(ctx, value, recurseTimes) {
10058 // Provide a hook for user-specified inspect functions.
10059 // Check that value is an object with an inspect function on it
10060 if (ctx.customInspect &&
10061 value &&
10062 isFunction(value.inspect) &&
10063 // Filter out the util module, it's inspect function is special
10064 value.inspect !== exports.inspect &&
10065 // Also filter out any prototype objects using the circular check.
10066 !(value.constructor && value.constructor.prototype === value)) {
10067 var ret = value.inspect(recurseTimes, ctx);
10068 if (!isString(ret)) {
10069 ret = formatValue(ctx, ret, recurseTimes);
10070 }
10071 return ret;
10072 }
10073
10074 // Primitive types cannot have properties
10075 var primitive = formatPrimitive(ctx, value);
10076 if (primitive) {
10077 return primitive;
10078 }
10079
10080 // Look up the keys of the object.
10081 var keys = Object.keys(value);
10082 var visibleKeys = arrayToHash(keys);
10083
10084 if (ctx.showHidden) {
10085 keys = Object.getOwnPropertyNames(value);
10086 }
10087
10088 // IE doesn't make error fields non-enumerable
10089 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
10090 if (isError(value)
10091 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
10092 return formatError(value);
10093 }
10094
10095 // Some type of object without properties can be shortcutted.
10096 if (keys.length === 0) {
10097 if (isFunction(value)) {
10098 var name = value.name ? ': ' + value.name : '';
10099 return ctx.stylize('[Function' + name + ']', 'special');
10100 }
10101 if (isRegExp(value)) {
10102 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
10103 }
10104 if (isDate(value)) {
10105 return ctx.stylize(Date.prototype.toString.call(value), 'date');
10106 }
10107 if (isError(value)) {
10108 return formatError(value);
10109 }
10110 }
10111
10112 var base = '', array = false, braces = ['{', '}'];
10113
10114 // Make Array say that they are Array
10115 if (isArray(value)) {
10116 array = true;
10117 braces = ['[', ']'];
10118 }
10119
10120 // Make functions say that they are functions
10121 if (isFunction(value)) {
10122 var n = value.name ? ': ' + value.name : '';
10123 base = ' [Function' + n + ']';
10124 }
10125
10126 // Make RegExps say that they are RegExps
10127 if (isRegExp(value)) {
10128 base = ' ' + RegExp.prototype.toString.call(value);
10129 }
10130
10131 // Make dates with properties first say the date
10132 if (isDate(value)) {
10133 base = ' ' + Date.prototype.toUTCString.call(value);
10134 }
10135
10136 // Make error with message first say the error
10137 if (isError(value)) {
10138 base = ' ' + formatError(value);
10139 }
10140
10141 if (keys.length === 0 && (!array || value.length == 0)) {
10142 return braces[0] + base + braces[1];
10143 }
10144
10145 if (recurseTimes < 0) {
10146 if (isRegExp(value)) {
10147 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
10148 } else {
10149 return ctx.stylize('[Object]', 'special');
10150 }
10151 }
10152
10153 ctx.seen.push(value);
10154
10155 var output;
10156 if (array) {
10157 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
10158 } else {
10159 output = keys.map(function(key) {
10160 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
10161 });
10162 }
10163
10164 ctx.seen.pop();
10165
10166 return reduceToSingleString(output, base, braces);
10167}
10168
10169
10170function formatPrimitive(ctx, value) {
10171 if (isUndefined(value))
10172 return ctx.stylize('undefined', 'undefined');
10173 if (isString(value)) {
10174 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
10175 .replace(/'/g, "\\'")
10176 .replace(/\\"/g, '"') + '\'';
10177 return ctx.stylize(simple, 'string');
10178 }
10179 if (isNumber(value))
10180 return ctx.stylize('' + value, 'number');
10181 if (isBoolean(value))
10182 return ctx.stylize('' + value, 'boolean');
10183 // For some reason typeof null is "object", so special case here.
10184 if (isNull(value))
10185 return ctx.stylize('null', 'null');
10186}
10187
10188
10189function formatError(value) {
10190 return '[' + Error.prototype.toString.call(value) + ']';
10191}
10192
10193
10194function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
10195 var output = [];
10196 for (var i = 0, l = value.length; i < l; ++i) {
10197 if (hasOwnProperty(value, String(i))) {
10198 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
10199 String(i), true));
10200 } else {
10201 output.push('');
10202 }
10203 }
10204 keys.forEach(function(key) {
10205 if (!key.match(/^\d+$/)) {
10206 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
10207 key, true));
10208 }
10209 });
10210 return output;
10211}
10212
10213
10214function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
10215 var name, str, desc;
10216 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
10217 if (desc.get) {
10218 if (desc.set) {
10219 str = ctx.stylize('[Getter/Setter]', 'special');
10220 } else {
10221 str = ctx.stylize('[Getter]', 'special');
10222 }
10223 } else {
10224 if (desc.set) {
10225 str = ctx.stylize('[Setter]', 'special');
10226 }
10227 }
10228 if (!hasOwnProperty(visibleKeys, key)) {
10229 name = '[' + key + ']';
10230 }
10231 if (!str) {
10232 if (ctx.seen.indexOf(desc.value) < 0) {
10233 if (isNull(recurseTimes)) {
10234 str = formatValue(ctx, desc.value, null);
10235 } else {
10236 str = formatValue(ctx, desc.value, recurseTimes - 1);
10237 }
10238 if (str.indexOf('\n') > -1) {
10239 if (array) {
10240 str = str.split('\n').map(function(line) {
10241 return ' ' + line;
10242 }).join('\n').substr(2);
10243 } else {
10244 str = '\n' + str.split('\n').map(function(line) {
10245 return ' ' + line;
10246 }).join('\n');
10247 }
10248 }
10249 } else {
10250 str = ctx.stylize('[Circular]', 'special');
10251 }
10252 }
10253 if (isUndefined(name)) {
10254 if (array && key.match(/^\d+$/)) {
10255 return str;
10256 }
10257 name = JSON.stringify('' + key);
10258 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
10259 name = name.substr(1, name.length - 2);
10260 name = ctx.stylize(name, 'name');
10261 } else {
10262 name = name.replace(/'/g, "\\'")
10263 .replace(/\\"/g, '"')
10264 .replace(/(^"|"$)/g, "'");
10265 name = ctx.stylize(name, 'string');
10266 }
10267 }
10268
10269 return name + ': ' + str;
10270}
10271
10272
10273function reduceToSingleString(output, base, braces) {
10274 var numLinesEst = 0;
10275 var length = output.reduce(function(prev, cur) {
10276 numLinesEst++;
10277 if (cur.indexOf('\n') >= 0) numLinesEst++;
10278 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
10279 }, 0);
10280
10281 if (length > 60) {
10282 return braces[0] +
10283 (base === '' ? '' : base + '\n ') +
10284 ' ' +
10285 output.join(',\n ') +
10286 ' ' +
10287 braces[1];
10288 }
10289
10290 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
10291}
10292
10293
10294// NOTE: These type checking functions intentionally don't use `instanceof`
10295// because it is fragile and can be easily faked with `Object.create()`.
10296function isArray(ar) {
10297 return Array.isArray(ar);
10298}
10299exports.isArray = isArray;
10300
10301function isBoolean(arg) {
10302 return typeof arg === 'boolean';
10303}
10304exports.isBoolean = isBoolean;
10305
10306function isNull(arg) {
10307 return arg === null;
10308}
10309exports.isNull = isNull;
10310
10311function isNullOrUndefined(arg) {
10312 return arg == null;
10313}
10314exports.isNullOrUndefined = isNullOrUndefined;
10315
10316function isNumber(arg) {
10317 return typeof arg === 'number';
10318}
10319exports.isNumber = isNumber;
10320
10321function isString(arg) {
10322 return typeof arg === 'string';
10323}
10324exports.isString = isString;
10325
10326function isSymbol(arg) {
10327 return typeof arg === 'symbol';
10328}
10329exports.isSymbol = isSymbol;
10330
10331function isUndefined(arg) {
10332 return arg === void 0;
10333}
10334exports.isUndefined = isUndefined;
10335
10336function isRegExp(re) {
10337 return isObject(re) && objectToString(re) === '[object RegExp]';
10338}
10339exports.isRegExp = isRegExp;
10340
10341function isObject(arg) {
10342 return typeof arg === 'object' && arg !== null;
10343}
10344exports.isObject = isObject;
10345
10346function isDate(d) {
10347 return isObject(d) && objectToString(d) === '[object Date]';
10348}
10349exports.isDate = isDate;
10350
10351function isError(e) {
10352 return isObject(e) &&
10353 (objectToString(e) === '[object Error]' || e instanceof Error);
10354}
10355exports.isError = isError;
10356
10357function isFunction(arg) {
10358 return typeof arg === 'function';
10359}
10360exports.isFunction = isFunction;
10361
10362function isPrimitive(arg) {
10363 return arg === null ||
10364 typeof arg === 'boolean' ||
10365 typeof arg === 'number' ||
10366 typeof arg === 'string' ||
10367 typeof arg === 'symbol' || // ES6 symbol
10368 typeof arg === 'undefined';
10369}
10370exports.isPrimitive = isPrimitive;
10371
10372exports.isBuffer = require('./support/isBuffer');
10373
10374function objectToString(o) {
10375 return Object.prototype.toString.call(o);
10376}
10377
10378
10379function pad(n) {
10380 return n < 10 ? '0' + n.toString(10) : n.toString(10);
10381}
10382
10383
10384var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
10385 'Oct', 'Nov', 'Dec'];
10386
10387// 26 Feb 16:19:34
10388function timestamp() {
10389 var d = new Date();
10390 var time = [pad(d.getHours()),
10391 pad(d.getMinutes()),
10392 pad(d.getSeconds())].join(':');
10393 return [d.getDate(), months[d.getMonth()], time].join(' ');
10394}
10395
10396
10397// log is just a thin wrapper to console.log that prepends a timestamp
10398exports.log = function() {
10399 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
10400};
10401
10402
10403/**
10404 * Inherit the prototype methods from one constructor into another.
10405 *
10406 * The Function.prototype.inherits from lang.js rewritten as a standalone
10407 * function (not on Function.prototype). NOTE: If this file is to be loaded
10408 * during bootstrapping this function needs to be rewritten using some native
10409 * functions as prototype setup using normal JavaScript does not work as
10410 * expected during bootstrapping (see mirror.js in r114903).
10411 *
10412 * @param {function} ctor Constructor function which needs to inherit the
10413 * prototype.
10414 * @param {function} superCtor Constructor function to inherit prototype from.
10415 */
10416exports.inherits = require('inherits');
10417
10418exports._extend = function(origin, add) {
10419 // Don't do anything if add isn't an object
10420 if (!add || !isObject(add)) return origin;
10421
10422 var keys = Object.keys(add);
10423 var i = keys.length;
10424 while (i--) {
10425 origin[keys[i]] = add[keys[i]];
10426 }
10427 return origin;
10428};
10429
10430function hasOwnProperty(obj, prop) {
10431 return Object.prototype.hasOwnProperty.call(obj, prop);
10432}
10433
10434}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
10435},{"./support/isBuffer":76,"_process":181,"inherits":75}],78:[function(require,module,exports){
10436'use strict'
10437
10438exports.byteLength = byteLength
10439exports.toByteArray = toByteArray
10440exports.fromByteArray = fromByteArray
10441
10442var lookup = []
10443var revLookup = []
10444var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
10445
10446var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
10447for (var i = 0, len = code.length; i < len; ++i) {
10448 lookup[i] = code[i]
10449 revLookup[code.charCodeAt(i)] = i
10450}
10451
10452// Support decoding URL-safe base64 strings, as Node.js does.
10453// See: https://en.wikipedia.org/wiki/Base64#URL_applications
10454revLookup['-'.charCodeAt(0)] = 62
10455revLookup['_'.charCodeAt(0)] = 63
10456
10457function getLens (b64) {
10458 var len = b64.length
10459
10460 if (len % 4 > 0) {
10461 throw new Error('Invalid string. Length must be a multiple of 4')
10462 }
10463
10464 // Trim off extra bytes after placeholder bytes are found
10465 // See: https://github.com/beatgammit/base64-js/issues/42
10466 var validLen = b64.indexOf('=')
10467 if (validLen === -1) validLen = len
10468
10469 var placeHoldersLen = validLen === len
10470 ? 0
10471 : 4 - (validLen % 4)
10472
10473 return [validLen, placeHoldersLen]
10474}
10475
10476// base64 is 4/3 + up to two characters of the original data
10477function byteLength (b64) {
10478 var lens = getLens(b64)
10479 var validLen = lens[0]
10480 var placeHoldersLen = lens[1]
10481 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
10482}
10483
10484function _byteLength (b64, validLen, placeHoldersLen) {
10485 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
10486}
10487
10488function toByteArray (b64) {
10489 var tmp
10490 var lens = getLens(b64)
10491 var validLen = lens[0]
10492 var placeHoldersLen = lens[1]
10493
10494 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
10495
10496 var curByte = 0
10497
10498 // if there are placeholders, only get up to the last complete 4 chars
10499 var len = placeHoldersLen > 0
10500 ? validLen - 4
10501 : validLen
10502
10503 var i
10504 for (i = 0; i < len; i += 4) {
10505 tmp =
10506 (revLookup[b64.charCodeAt(i)] << 18) |
10507 (revLookup[b64.charCodeAt(i + 1)] << 12) |
10508 (revLookup[b64.charCodeAt(i + 2)] << 6) |
10509 revLookup[b64.charCodeAt(i + 3)]
10510 arr[curByte++] = (tmp >> 16) & 0xFF
10511 arr[curByte++] = (tmp >> 8) & 0xFF
10512 arr[curByte++] = tmp & 0xFF
10513 }
10514
10515 if (placeHoldersLen === 2) {
10516 tmp =
10517 (revLookup[b64.charCodeAt(i)] << 2) |
10518 (revLookup[b64.charCodeAt(i + 1)] >> 4)
10519 arr[curByte++] = tmp & 0xFF
10520 }
10521
10522 if (placeHoldersLen === 1) {
10523 tmp =
10524 (revLookup[b64.charCodeAt(i)] << 10) |
10525 (revLookup[b64.charCodeAt(i + 1)] << 4) |
10526 (revLookup[b64.charCodeAt(i + 2)] >> 2)
10527 arr[curByte++] = (tmp >> 8) & 0xFF
10528 arr[curByte++] = tmp & 0xFF
10529 }
10530
10531 return arr
10532}
10533
10534function tripletToBase64 (num) {
10535 return lookup[num >> 18 & 0x3F] +
10536 lookup[num >> 12 & 0x3F] +
10537 lookup[num >> 6 & 0x3F] +
10538 lookup[num & 0x3F]
10539}
10540
10541function encodeChunk (uint8, start, end) {
10542 var tmp
10543 var output = []
10544 for (var i = start; i < end; i += 3) {
10545 tmp =
10546 ((uint8[i] << 16) & 0xFF0000) +
10547 ((uint8[i + 1] << 8) & 0xFF00) +
10548 (uint8[i + 2] & 0xFF)
10549 output.push(tripletToBase64(tmp))
10550 }
10551 return output.join('')
10552}
10553
10554function fromByteArray (uint8) {
10555 var tmp
10556 var len = uint8.length
10557 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
10558 var parts = []
10559 var maxChunkLength = 16383 // must be multiple of 3
10560
10561 // go through the array every three bytes, we'll deal with trailing stuff later
10562 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
10563 parts.push(encodeChunk(
10564 uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
10565 ))
10566 }
10567
10568 // pad the end with zeros, but make sure to not forget the extra bytes
10569 if (extraBytes === 1) {
10570 tmp = uint8[len - 1]
10571 parts.push(
10572 lookup[tmp >> 2] +
10573 lookup[(tmp << 4) & 0x3F] +
10574 '=='
10575 )
10576 } else if (extraBytes === 2) {
10577 tmp = (uint8[len - 2] << 8) + uint8[len - 1]
10578 parts.push(
10579 lookup[tmp >> 10] +
10580 lookup[(tmp >> 4) & 0x3F] +
10581 lookup[(tmp << 2) & 0x3F] +
10582 '='
10583 )
10584 }
10585
10586 return parts.join('')
10587}
10588
10589},{}],79:[function(require,module,exports){
10590(function (module, exports) {
10591 'use strict';
10592
10593 // Utils
10594 function assert (val, msg) {
10595 if (!val) throw new Error(msg || 'Assertion failed');
10596 }
10597
10598 // Could use `inherits` module, but don't want to move from single file
10599 // architecture yet.
10600 function inherits (ctor, superCtor) {
10601 ctor.super_ = superCtor;
10602 var TempCtor = function () {};
10603 TempCtor.prototype = superCtor.prototype;
10604 ctor.prototype = new TempCtor();
10605 ctor.prototype.constructor = ctor;
10606 }
10607
10608 // BN
10609
10610 function BN (number, base, endian) {
10611 if (BN.isBN(number)) {
10612 return number;
10613 }
10614
10615 this.negative = 0;
10616 this.words = null;
10617 this.length = 0;
10618
10619 // Reduction context
10620 this.red = null;
10621
10622 if (number !== null) {
10623 if (base === 'le' || base === 'be') {
10624 endian = base;
10625 base = 10;
10626 }
10627
10628 this._init(number || 0, base || 10, endian || 'be');
10629 }
10630 }
10631 if (typeof module === 'object') {
10632 module.exports = BN;
10633 } else {
10634 exports.BN = BN;
10635 }
10636
10637 BN.BN = BN;
10638 BN.wordSize = 26;
10639
10640 var Buffer;
10641 try {
10642 Buffer = require('buffer').Buffer;
10643 } catch (e) {
10644 }
10645
10646 BN.isBN = function isBN (num) {
10647 if (num instanceof BN) {
10648 return true;
10649 }
10650
10651 return num !== null && typeof num === 'object' &&
10652 num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
10653 };
10654
10655 BN.max = function max (left, right) {
10656 if (left.cmp(right) > 0) return left;
10657 return right;
10658 };
10659
10660 BN.min = function min (left, right) {
10661 if (left.cmp(right) < 0) return left;
10662 return right;
10663 };
10664
10665 BN.prototype._init = function init (number, base, endian) {
10666 if (typeof number === 'number') {
10667 return this._initNumber(number, base, endian);
10668 }
10669
10670 if (typeof number === 'object') {
10671 return this._initArray(number, base, endian);
10672 }
10673
10674 if (base === 'hex') {
10675 base = 16;
10676 }
10677 assert(base === (base | 0) && base >= 2 && base <= 36);
10678
10679 number = number.toString().replace(/\s+/g, '');
10680 var start = 0;
10681 if (number[0] === '-') {
10682 start++;
10683 }
10684
10685 if (base === 16) {
10686 this._parseHex(number, start);
10687 } else {
10688 this._parseBase(number, base, start);
10689 }
10690
10691 if (number[0] === '-') {
10692 this.negative = 1;
10693 }
10694
10695 this.strip();
10696
10697 if (endian !== 'le') return;
10698
10699 this._initArray(this.toArray(), base, endian);
10700 };
10701
10702 BN.prototype._initNumber = function _initNumber (number, base, endian) {
10703 if (number < 0) {
10704 this.negative = 1;
10705 number = -number;
10706 }
10707 if (number < 0x4000000) {
10708 this.words = [ number & 0x3ffffff ];
10709 this.length = 1;
10710 } else if (number < 0x10000000000000) {
10711 this.words = [
10712 number & 0x3ffffff,
10713 (number / 0x4000000) & 0x3ffffff
10714 ];
10715 this.length = 2;
10716 } else {
10717 assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
10718 this.words = [
10719 number & 0x3ffffff,
10720 (number / 0x4000000) & 0x3ffffff,
10721 1
10722 ];
10723 this.length = 3;
10724 }
10725
10726 if (endian !== 'le') return;
10727
10728 // Reverse the bytes
10729 this._initArray(this.toArray(), base, endian);
10730 };
10731
10732 BN.prototype._initArray = function _initArray (number, base, endian) {
10733 // Perhaps a Uint8Array
10734 assert(typeof number.length === 'number');
10735 if (number.length <= 0) {
10736 this.words = [ 0 ];
10737 this.length = 1;
10738 return this;
10739 }
10740
10741 this.length = Math.ceil(number.length / 3);
10742 this.words = new Array(this.length);
10743 for (var i = 0; i < this.length; i++) {
10744 this.words[i] = 0;
10745 }
10746
10747 var j, w;
10748 var off = 0;
10749 if (endian === 'be') {
10750 for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
10751 w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
10752 this.words[j] |= (w << off) & 0x3ffffff;
10753 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
10754 off += 24;
10755 if (off >= 26) {
10756 off -= 26;
10757 j++;
10758 }
10759 }
10760 } else if (endian === 'le') {
10761 for (i = 0, j = 0; i < number.length; i += 3) {
10762 w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
10763 this.words[j] |= (w << off) & 0x3ffffff;
10764 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
10765 off += 24;
10766 if (off >= 26) {
10767 off -= 26;
10768 j++;
10769 }
10770 }
10771 }
10772 return this.strip();
10773 };
10774
10775 function parseHex (str, start, end) {
10776 var r = 0;
10777 var len = Math.min(str.length, end);
10778 for (var i = start; i < len; i++) {
10779 var c = str.charCodeAt(i) - 48;
10780
10781 r <<= 4;
10782
10783 // 'a' - 'f'
10784 if (c >= 49 && c <= 54) {
10785 r |= c - 49 + 0xa;
10786
10787 // 'A' - 'F'
10788 } else if (c >= 17 && c <= 22) {
10789 r |= c - 17 + 0xa;
10790
10791 // '0' - '9'
10792 } else {
10793 r |= c & 0xf;
10794 }
10795 }
10796 return r;
10797 }
10798
10799 BN.prototype._parseHex = function _parseHex (number, start) {
10800 // Create possibly bigger array to ensure that it fits the number
10801 this.length = Math.ceil((number.length - start) / 6);
10802 this.words = new Array(this.length);
10803 for (var i = 0; i < this.length; i++) {
10804 this.words[i] = 0;
10805 }
10806
10807 var j, w;
10808 // Scan 24-bit chunks and add them to the number
10809 var off = 0;
10810 for (i = number.length - 6, j = 0; i >= start; i -= 6) {
10811 w = parseHex(number, i, i + 6);
10812 this.words[j] |= (w << off) & 0x3ffffff;
10813 // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
10814 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
10815 off += 24;
10816 if (off >= 26) {
10817 off -= 26;
10818 j++;
10819 }
10820 }
10821 if (i + 6 !== start) {
10822 w = parseHex(number, start, i + 6);
10823 this.words[j] |= (w << off) & 0x3ffffff;
10824 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
10825 }
10826 this.strip();
10827 };
10828
10829 function parseBase (str, start, end, mul) {
10830 var r = 0;
10831 var len = Math.min(str.length, end);
10832 for (var i = start; i < len; i++) {
10833 var c = str.charCodeAt(i) - 48;
10834
10835 r *= mul;
10836
10837 // 'a'
10838 if (c >= 49) {
10839 r += c - 49 + 0xa;
10840
10841 // 'A'
10842 } else if (c >= 17) {
10843 r += c - 17 + 0xa;
10844
10845 // '0' - '9'
10846 } else {
10847 r += c;
10848 }
10849 }
10850 return r;
10851 }
10852
10853 BN.prototype._parseBase = function _parseBase (number, base, start) {
10854 // Initialize as zero
10855 this.words = [ 0 ];
10856 this.length = 1;
10857
10858 // Find length of limb in base
10859 for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
10860 limbLen++;
10861 }
10862 limbLen--;
10863 limbPow = (limbPow / base) | 0;
10864
10865 var total = number.length - start;
10866 var mod = total % limbLen;
10867 var end = Math.min(total, total - mod) + start;
10868
10869 var word = 0;
10870 for (var i = start; i < end; i += limbLen) {
10871 word = parseBase(number, i, i + limbLen, base);
10872
10873 this.imuln(limbPow);
10874 if (this.words[0] + word < 0x4000000) {
10875 this.words[0] += word;
10876 } else {
10877 this._iaddn(word);
10878 }
10879 }
10880
10881 if (mod !== 0) {
10882 var pow = 1;
10883 word = parseBase(number, i, number.length, base);
10884
10885 for (i = 0; i < mod; i++) {
10886 pow *= base;
10887 }
10888
10889 this.imuln(pow);
10890 if (this.words[0] + word < 0x4000000) {
10891 this.words[0] += word;
10892 } else {
10893 this._iaddn(word);
10894 }
10895 }
10896 };
10897
10898 BN.prototype.copy = function copy (dest) {
10899 dest.words = new Array(this.length);
10900 for (var i = 0; i < this.length; i++) {
10901 dest.words[i] = this.words[i];
10902 }
10903 dest.length = this.length;
10904 dest.negative = this.negative;
10905 dest.red = this.red;
10906 };
10907
10908 BN.prototype.clone = function clone () {
10909 var r = new BN(null);
10910 this.copy(r);
10911 return r;
10912 };
10913
10914 BN.prototype._expand = function _expand (size) {
10915 while (this.length < size) {
10916 this.words[this.length++] = 0;
10917 }
10918 return this;
10919 };
10920
10921 // Remove leading `0` from `this`
10922 BN.prototype.strip = function strip () {
10923 while (this.length > 1 && this.words[this.length - 1] === 0) {
10924 this.length--;
10925 }
10926 return this._normSign();
10927 };
10928
10929 BN.prototype._normSign = function _normSign () {
10930 // -0 = 0
10931 if (this.length === 1 && this.words[0] === 0) {
10932 this.negative = 0;
10933 }
10934 return this;
10935 };
10936
10937 BN.prototype.inspect = function inspect () {
10938 return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
10939 };
10940
10941 /*
10942
10943 var zeros = [];
10944 var groupSizes = [];
10945 var groupBases = [];
10946
10947 var s = '';
10948 var i = -1;
10949 while (++i < BN.wordSize) {
10950 zeros[i] = s;
10951 s += '0';
10952 }
10953 groupSizes[0] = 0;
10954 groupSizes[1] = 0;
10955 groupBases[0] = 0;
10956 groupBases[1] = 0;
10957 var base = 2 - 1;
10958 while (++base < 36 + 1) {
10959 var groupSize = 0;
10960 var groupBase = 1;
10961 while (groupBase < (1 << BN.wordSize) / base) {
10962 groupBase *= base;
10963 groupSize += 1;
10964 }
10965 groupSizes[base] = groupSize;
10966 groupBases[base] = groupBase;
10967 }
10968
10969 */
10970
10971 var zeros = [
10972 '',
10973 '0',
10974 '00',
10975 '000',
10976 '0000',
10977 '00000',
10978 '000000',
10979 '0000000',
10980 '00000000',
10981 '000000000',
10982 '0000000000',
10983 '00000000000',
10984 '000000000000',
10985 '0000000000000',
10986 '00000000000000',
10987 '000000000000000',
10988 '0000000000000000',
10989 '00000000000000000',
10990 '000000000000000000',
10991 '0000000000000000000',
10992 '00000000000000000000',
10993 '000000000000000000000',
10994 '0000000000000000000000',
10995 '00000000000000000000000',
10996 '000000000000000000000000',
10997 '0000000000000000000000000'
10998 ];
10999
11000 var groupSizes = [
11001 0, 0,
11002 25, 16, 12, 11, 10, 9, 8,
11003 8, 7, 7, 7, 7, 6, 6,
11004 6, 6, 6, 6, 6, 5, 5,
11005 5, 5, 5, 5, 5, 5, 5,
11006 5, 5, 5, 5, 5, 5, 5
11007 ];
11008
11009 var groupBases = [
11010 0, 0,
11011 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
11012 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
11013 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
11014 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
11015 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
11016 ];
11017
11018 BN.prototype.toString = function toString (base, padding) {
11019 base = base || 10;
11020 padding = padding | 0 || 1;
11021
11022 var out;
11023 if (base === 16 || base === 'hex') {
11024 out = '';
11025 var off = 0;
11026 var carry = 0;
11027 for (var i = 0; i < this.length; i++) {
11028 var w = this.words[i];
11029 var word = (((w << off) | carry) & 0xffffff).toString(16);
11030 carry = (w >>> (24 - off)) & 0xffffff;
11031 if (carry !== 0 || i !== this.length - 1) {
11032 out = zeros[6 - word.length] + word + out;
11033 } else {
11034 out = word + out;
11035 }
11036 off += 2;
11037 if (off >= 26) {
11038 off -= 26;
11039 i--;
11040 }
11041 }
11042 if (carry !== 0) {
11043 out = carry.toString(16) + out;
11044 }
11045 while (out.length % padding !== 0) {
11046 out = '0' + out;
11047 }
11048 if (this.negative !== 0) {
11049 out = '-' + out;
11050 }
11051 return out;
11052 }
11053
11054 if (base === (base | 0) && base >= 2 && base <= 36) {
11055 // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
11056 var groupSize = groupSizes[base];
11057 // var groupBase = Math.pow(base, groupSize);
11058 var groupBase = groupBases[base];
11059 out = '';
11060 var c = this.clone();
11061 c.negative = 0;
11062 while (!c.isZero()) {
11063 var r = c.modn(groupBase).toString(base);
11064 c = c.idivn(groupBase);
11065
11066 if (!c.isZero()) {
11067 out = zeros[groupSize - r.length] + r + out;
11068 } else {
11069 out = r + out;
11070 }
11071 }
11072 if (this.isZero()) {
11073 out = '0' + out;
11074 }
11075 while (out.length % padding !== 0) {
11076 out = '0' + out;
11077 }
11078 if (this.negative !== 0) {
11079 out = '-' + out;
11080 }
11081 return out;
11082 }
11083
11084 assert(false, 'Base should be between 2 and 36');
11085 };
11086
11087 BN.prototype.toNumber = function toNumber () {
11088 var ret = this.words[0];
11089 if (this.length === 2) {
11090 ret += this.words[1] * 0x4000000;
11091 } else if (this.length === 3 && this.words[2] === 0x01) {
11092 // NOTE: at this stage it is known that the top bit is set
11093 ret += 0x10000000000000 + (this.words[1] * 0x4000000);
11094 } else if (this.length > 2) {
11095 assert(false, 'Number can only safely store up to 53 bits');
11096 }
11097 return (this.negative !== 0) ? -ret : ret;
11098 };
11099
11100 BN.prototype.toJSON = function toJSON () {
11101 return this.toString(16);
11102 };
11103
11104 BN.prototype.toBuffer = function toBuffer (endian, length) {
11105 assert(typeof Buffer !== 'undefined');
11106 return this.toArrayLike(Buffer, endian, length);
11107 };
11108
11109 BN.prototype.toArray = function toArray (endian, length) {
11110 return this.toArrayLike(Array, endian, length);
11111 };
11112
11113 BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
11114 var byteLength = this.byteLength();
11115 var reqLength = length || Math.max(1, byteLength);
11116 assert(byteLength <= reqLength, 'byte array longer than desired length');
11117 assert(reqLength > 0, 'Requested array length <= 0');
11118
11119 this.strip();
11120 var littleEndian = endian === 'le';
11121 var res = new ArrayType(reqLength);
11122
11123 var b, i;
11124 var q = this.clone();
11125 if (!littleEndian) {
11126 // Assume big-endian
11127 for (i = 0; i < reqLength - byteLength; i++) {
11128 res[i] = 0;
11129 }
11130
11131 for (i = 0; !q.isZero(); i++) {
11132 b = q.andln(0xff);
11133 q.iushrn(8);
11134
11135 res[reqLength - i - 1] = b;
11136 }
11137 } else {
11138 for (i = 0; !q.isZero(); i++) {
11139 b = q.andln(0xff);
11140 q.iushrn(8);
11141
11142 res[i] = b;
11143 }
11144
11145 for (; i < reqLength; i++) {
11146 res[i] = 0;
11147 }
11148 }
11149
11150 return res;
11151 };
11152
11153 if (Math.clz32) {
11154 BN.prototype._countBits = function _countBits (w) {
11155 return 32 - Math.clz32(w);
11156 };
11157 } else {
11158 BN.prototype._countBits = function _countBits (w) {
11159 var t = w;
11160 var r = 0;
11161 if (t >= 0x1000) {
11162 r += 13;
11163 t >>>= 13;
11164 }
11165 if (t >= 0x40) {
11166 r += 7;
11167 t >>>= 7;
11168 }
11169 if (t >= 0x8) {
11170 r += 4;
11171 t >>>= 4;
11172 }
11173 if (t >= 0x02) {
11174 r += 2;
11175 t >>>= 2;
11176 }
11177 return r + t;
11178 };
11179 }
11180
11181 BN.prototype._zeroBits = function _zeroBits (w) {
11182 // Short-cut
11183 if (w === 0) return 26;
11184
11185 var t = w;
11186 var r = 0;
11187 if ((t & 0x1fff) === 0) {
11188 r += 13;
11189 t >>>= 13;
11190 }
11191 if ((t & 0x7f) === 0) {
11192 r += 7;
11193 t >>>= 7;
11194 }
11195 if ((t & 0xf) === 0) {
11196 r += 4;
11197 t >>>= 4;
11198 }
11199 if ((t & 0x3) === 0) {
11200 r += 2;
11201 t >>>= 2;
11202 }
11203 if ((t & 0x1) === 0) {
11204 r++;
11205 }
11206 return r;
11207 };
11208
11209 // Return number of used bits in a BN
11210 BN.prototype.bitLength = function bitLength () {
11211 var w = this.words[this.length - 1];
11212 var hi = this._countBits(w);
11213 return (this.length - 1) * 26 + hi;
11214 };
11215
11216 function toBitArray (num) {
11217 var w = new Array(num.bitLength());
11218
11219 for (var bit = 0; bit < w.length; bit++) {
11220 var off = (bit / 26) | 0;
11221 var wbit = bit % 26;
11222
11223 w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
11224 }
11225
11226 return w;
11227 }
11228
11229 // Number of trailing zero bits
11230 BN.prototype.zeroBits = function zeroBits () {
11231 if (this.isZero()) return 0;
11232
11233 var r = 0;
11234 for (var i = 0; i < this.length; i++) {
11235 var b = this._zeroBits(this.words[i]);
11236 r += b;
11237 if (b !== 26) break;
11238 }
11239 return r;
11240 };
11241
11242 BN.prototype.byteLength = function byteLength () {
11243 return Math.ceil(this.bitLength() / 8);
11244 };
11245
11246 BN.prototype.toTwos = function toTwos (width) {
11247 if (this.negative !== 0) {
11248 return this.abs().inotn(width).iaddn(1);
11249 }
11250 return this.clone();
11251 };
11252
11253 BN.prototype.fromTwos = function fromTwos (width) {
11254 if (this.testn(width - 1)) {
11255 return this.notn(width).iaddn(1).ineg();
11256 }
11257 return this.clone();
11258 };
11259
11260 BN.prototype.isNeg = function isNeg () {
11261 return this.negative !== 0;
11262 };
11263
11264 // Return negative clone of `this`
11265 BN.prototype.neg = function neg () {
11266 return this.clone().ineg();
11267 };
11268
11269 BN.prototype.ineg = function ineg () {
11270 if (!this.isZero()) {
11271 this.negative ^= 1;
11272 }
11273
11274 return this;
11275 };
11276
11277 // Or `num` with `this` in-place
11278 BN.prototype.iuor = function iuor (num) {
11279 while (this.length < num.length) {
11280 this.words[this.length++] = 0;
11281 }
11282
11283 for (var i = 0; i < num.length; i++) {
11284 this.words[i] = this.words[i] | num.words[i];
11285 }
11286
11287 return this.strip();
11288 };
11289
11290 BN.prototype.ior = function ior (num) {
11291 assert((this.negative | num.negative) === 0);
11292 return this.iuor(num);
11293 };
11294
11295 // Or `num` with `this`
11296 BN.prototype.or = function or (num) {
11297 if (this.length > num.length) return this.clone().ior(num);
11298 return num.clone().ior(this);
11299 };
11300
11301 BN.prototype.uor = function uor (num) {
11302 if (this.length > num.length) return this.clone().iuor(num);
11303 return num.clone().iuor(this);
11304 };
11305
11306 // And `num` with `this` in-place
11307 BN.prototype.iuand = function iuand (num) {
11308 // b = min-length(num, this)
11309 var b;
11310 if (this.length > num.length) {
11311 b = num;
11312 } else {
11313 b = this;
11314 }
11315
11316 for (var i = 0; i < b.length; i++) {
11317 this.words[i] = this.words[i] & num.words[i];
11318 }
11319
11320 this.length = b.length;
11321
11322 return this.strip();
11323 };
11324
11325 BN.prototype.iand = function iand (num) {
11326 assert((this.negative | num.negative) === 0);
11327 return this.iuand(num);
11328 };
11329
11330 // And `num` with `this`
11331 BN.prototype.and = function and (num) {
11332 if (this.length > num.length) return this.clone().iand(num);
11333 return num.clone().iand(this);
11334 };
11335
11336 BN.prototype.uand = function uand (num) {
11337 if (this.length > num.length) return this.clone().iuand(num);
11338 return num.clone().iuand(this);
11339 };
11340
11341 // Xor `num` with `this` in-place
11342 BN.prototype.iuxor = function iuxor (num) {
11343 // a.length > b.length
11344 var a;
11345 var b;
11346 if (this.length > num.length) {
11347 a = this;
11348 b = num;
11349 } else {
11350 a = num;
11351 b = this;
11352 }
11353
11354 for (var i = 0; i < b.length; i++) {
11355 this.words[i] = a.words[i] ^ b.words[i];
11356 }
11357
11358 if (this !== a) {
11359 for (; i < a.length; i++) {
11360 this.words[i] = a.words[i];
11361 }
11362 }
11363
11364 this.length = a.length;
11365
11366 return this.strip();
11367 };
11368
11369 BN.prototype.ixor = function ixor (num) {
11370 assert((this.negative | num.negative) === 0);
11371 return this.iuxor(num);
11372 };
11373
11374 // Xor `num` with `this`
11375 BN.prototype.xor = function xor (num) {
11376 if (this.length > num.length) return this.clone().ixor(num);
11377 return num.clone().ixor(this);
11378 };
11379
11380 BN.prototype.uxor = function uxor (num) {
11381 if (this.length > num.length) return this.clone().iuxor(num);
11382 return num.clone().iuxor(this);
11383 };
11384
11385 // Not ``this`` with ``width`` bitwidth
11386 BN.prototype.inotn = function inotn (width) {
11387 assert(typeof width === 'number' && width >= 0);
11388
11389 var bytesNeeded = Math.ceil(width / 26) | 0;
11390 var bitsLeft = width % 26;
11391
11392 // Extend the buffer with leading zeroes
11393 this._expand(bytesNeeded);
11394
11395 if (bitsLeft > 0) {
11396 bytesNeeded--;
11397 }
11398
11399 // Handle complete words
11400 for (var i = 0; i < bytesNeeded; i++) {
11401 this.words[i] = ~this.words[i] & 0x3ffffff;
11402 }
11403
11404 // Handle the residue
11405 if (bitsLeft > 0) {
11406 this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
11407 }
11408
11409 // And remove leading zeroes
11410 return this.strip();
11411 };
11412
11413 BN.prototype.notn = function notn (width) {
11414 return this.clone().inotn(width);
11415 };
11416
11417 // Set `bit` of `this`
11418 BN.prototype.setn = function setn (bit, val) {
11419 assert(typeof bit === 'number' && bit >= 0);
11420
11421 var off = (bit / 26) | 0;
11422 var wbit = bit % 26;
11423
11424 this._expand(off + 1);
11425
11426 if (val) {
11427 this.words[off] = this.words[off] | (1 << wbit);
11428 } else {
11429 this.words[off] = this.words[off] & ~(1 << wbit);
11430 }
11431
11432 return this.strip();
11433 };
11434
11435 // Add `num` to `this` in-place
11436 BN.prototype.iadd = function iadd (num) {
11437 var r;
11438
11439 // negative + positive
11440 if (this.negative !== 0 && num.negative === 0) {
11441 this.negative = 0;
11442 r = this.isub(num);
11443 this.negative ^= 1;
11444 return this._normSign();
11445
11446 // positive + negative
11447 } else if (this.negative === 0 && num.negative !== 0) {
11448 num.negative = 0;
11449 r = this.isub(num);
11450 num.negative = 1;
11451 return r._normSign();
11452 }
11453
11454 // a.length > b.length
11455 var a, b;
11456 if (this.length > num.length) {
11457 a = this;
11458 b = num;
11459 } else {
11460 a = num;
11461 b = this;
11462 }
11463
11464 var carry = 0;
11465 for (var i = 0; i < b.length; i++) {
11466 r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
11467 this.words[i] = r & 0x3ffffff;
11468 carry = r >>> 26;
11469 }
11470 for (; carry !== 0 && i < a.length; i++) {
11471 r = (a.words[i] | 0) + carry;
11472 this.words[i] = r & 0x3ffffff;
11473 carry = r >>> 26;
11474 }
11475
11476 this.length = a.length;
11477 if (carry !== 0) {
11478 this.words[this.length] = carry;
11479 this.length++;
11480 // Copy the rest of the words
11481 } else if (a !== this) {
11482 for (; i < a.length; i++) {
11483 this.words[i] = a.words[i];
11484 }
11485 }
11486
11487 return this;
11488 };
11489
11490 // Add `num` to `this`
11491 BN.prototype.add = function add (num) {
11492 var res;
11493 if (num.negative !== 0 && this.negative === 0) {
11494 num.negative = 0;
11495 res = this.sub(num);
11496 num.negative ^= 1;
11497 return res;
11498 } else if (num.negative === 0 && this.negative !== 0) {
11499 this.negative = 0;
11500 res = num.sub(this);
11501 this.negative = 1;
11502 return res;
11503 }
11504
11505 if (this.length > num.length) return this.clone().iadd(num);
11506
11507 return num.clone().iadd(this);
11508 };
11509
11510 // Subtract `num` from `this` in-place
11511 BN.prototype.isub = function isub (num) {
11512 // this - (-num) = this + num
11513 if (num.negative !== 0) {
11514 num.negative = 0;
11515 var r = this.iadd(num);
11516 num.negative = 1;
11517 return r._normSign();
11518
11519 // -this - num = -(this + num)
11520 } else if (this.negative !== 0) {
11521 this.negative = 0;
11522 this.iadd(num);
11523 this.negative = 1;
11524 return this._normSign();
11525 }
11526
11527 // At this point both numbers are positive
11528 var cmp = this.cmp(num);
11529
11530 // Optimization - zeroify
11531 if (cmp === 0) {
11532 this.negative = 0;
11533 this.length = 1;
11534 this.words[0] = 0;
11535 return this;
11536 }
11537
11538 // a > b
11539 var a, b;
11540 if (cmp > 0) {
11541 a = this;
11542 b = num;
11543 } else {
11544 a = num;
11545 b = this;
11546 }
11547
11548 var carry = 0;
11549 for (var i = 0; i < b.length; i++) {
11550 r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
11551 carry = r >> 26;
11552 this.words[i] = r & 0x3ffffff;
11553 }
11554 for (; carry !== 0 && i < a.length; i++) {
11555 r = (a.words[i] | 0) + carry;
11556 carry = r >> 26;
11557 this.words[i] = r & 0x3ffffff;
11558 }
11559
11560 // Copy rest of the words
11561 if (carry === 0 && i < a.length && a !== this) {
11562 for (; i < a.length; i++) {
11563 this.words[i] = a.words[i];
11564 }
11565 }
11566
11567 this.length = Math.max(this.length, i);
11568
11569 if (a !== this) {
11570 this.negative = 1;
11571 }
11572
11573 return this.strip();
11574 };
11575
11576 // Subtract `num` from `this`
11577 BN.prototype.sub = function sub (num) {
11578 return this.clone().isub(num);
11579 };
11580
11581 function smallMulTo (self, num, out) {
11582 out.negative = num.negative ^ self.negative;
11583 var len = (self.length + num.length) | 0;
11584 out.length = len;
11585 len = (len - 1) | 0;
11586
11587 // Peel one iteration (compiler can't do it, because of code complexity)
11588 var a = self.words[0] | 0;
11589 var b = num.words[0] | 0;
11590 var r = a * b;
11591
11592 var lo = r & 0x3ffffff;
11593 var carry = (r / 0x4000000) | 0;
11594 out.words[0] = lo;
11595
11596 for (var k = 1; k < len; k++) {
11597 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
11598 // note that ncarry could be >= 0x3ffffff
11599 var ncarry = carry >>> 26;
11600 var rword = carry & 0x3ffffff;
11601 var maxJ = Math.min(k, num.length - 1);
11602 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
11603 var i = (k - j) | 0;
11604 a = self.words[i] | 0;
11605 b = num.words[j] | 0;
11606 r = a * b + rword;
11607 ncarry += (r / 0x4000000) | 0;
11608 rword = r & 0x3ffffff;
11609 }
11610 out.words[k] = rword | 0;
11611 carry = ncarry | 0;
11612 }
11613 if (carry !== 0) {
11614 out.words[k] = carry | 0;
11615 } else {
11616 out.length--;
11617 }
11618
11619 return out.strip();
11620 }
11621
11622 // TODO(indutny): it may be reasonable to omit it for users who don't need
11623 // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
11624 // multiplication (like elliptic secp256k1).
11625 var comb10MulTo = function comb10MulTo (self, num, out) {
11626 var a = self.words;
11627 var b = num.words;
11628 var o = out.words;
11629 var c = 0;
11630 var lo;
11631 var mid;
11632 var hi;
11633 var a0 = a[0] | 0;
11634 var al0 = a0 & 0x1fff;
11635 var ah0 = a0 >>> 13;
11636 var a1 = a[1] | 0;
11637 var al1 = a1 & 0x1fff;
11638 var ah1 = a1 >>> 13;
11639 var a2 = a[2] | 0;
11640 var al2 = a2 & 0x1fff;
11641 var ah2 = a2 >>> 13;
11642 var a3 = a[3] | 0;
11643 var al3 = a3 & 0x1fff;
11644 var ah3 = a3 >>> 13;
11645 var a4 = a[4] | 0;
11646 var al4 = a4 & 0x1fff;
11647 var ah4 = a4 >>> 13;
11648 var a5 = a[5] | 0;
11649 var al5 = a5 & 0x1fff;
11650 var ah5 = a5 >>> 13;
11651 var a6 = a[6] | 0;
11652 var al6 = a6 & 0x1fff;
11653 var ah6 = a6 >>> 13;
11654 var a7 = a[7] | 0;
11655 var al7 = a7 & 0x1fff;
11656 var ah7 = a7 >>> 13;
11657 var a8 = a[8] | 0;
11658 var al8 = a8 & 0x1fff;
11659 var ah8 = a8 >>> 13;
11660 var a9 = a[9] | 0;
11661 var al9 = a9 & 0x1fff;
11662 var ah9 = a9 >>> 13;
11663 var b0 = b[0] | 0;
11664 var bl0 = b0 & 0x1fff;
11665 var bh0 = b0 >>> 13;
11666 var b1 = b[1] | 0;
11667 var bl1 = b1 & 0x1fff;
11668 var bh1 = b1 >>> 13;
11669 var b2 = b[2] | 0;
11670 var bl2 = b2 & 0x1fff;
11671 var bh2 = b2 >>> 13;
11672 var b3 = b[3] | 0;
11673 var bl3 = b3 & 0x1fff;
11674 var bh3 = b3 >>> 13;
11675 var b4 = b[4] | 0;
11676 var bl4 = b4 & 0x1fff;
11677 var bh4 = b4 >>> 13;
11678 var b5 = b[5] | 0;
11679 var bl5 = b5 & 0x1fff;
11680 var bh5 = b5 >>> 13;
11681 var b6 = b[6] | 0;
11682 var bl6 = b6 & 0x1fff;
11683 var bh6 = b6 >>> 13;
11684 var b7 = b[7] | 0;
11685 var bl7 = b7 & 0x1fff;
11686 var bh7 = b7 >>> 13;
11687 var b8 = b[8] | 0;
11688 var bl8 = b8 & 0x1fff;
11689 var bh8 = b8 >>> 13;
11690 var b9 = b[9] | 0;
11691 var bl9 = b9 & 0x1fff;
11692 var bh9 = b9 >>> 13;
11693
11694 out.negative = self.negative ^ num.negative;
11695 out.length = 19;
11696 /* k = 0 */
11697 lo = Math.imul(al0, bl0);
11698 mid = Math.imul(al0, bh0);
11699 mid = (mid + Math.imul(ah0, bl0)) | 0;
11700 hi = Math.imul(ah0, bh0);
11701 var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11702 c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
11703 w0 &= 0x3ffffff;
11704 /* k = 1 */
11705 lo = Math.imul(al1, bl0);
11706 mid = Math.imul(al1, bh0);
11707 mid = (mid + Math.imul(ah1, bl0)) | 0;
11708 hi = Math.imul(ah1, bh0);
11709 lo = (lo + Math.imul(al0, bl1)) | 0;
11710 mid = (mid + Math.imul(al0, bh1)) | 0;
11711 mid = (mid + Math.imul(ah0, bl1)) | 0;
11712 hi = (hi + Math.imul(ah0, bh1)) | 0;
11713 var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11714 c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
11715 w1 &= 0x3ffffff;
11716 /* k = 2 */
11717 lo = Math.imul(al2, bl0);
11718 mid = Math.imul(al2, bh0);
11719 mid = (mid + Math.imul(ah2, bl0)) | 0;
11720 hi = Math.imul(ah2, bh0);
11721 lo = (lo + Math.imul(al1, bl1)) | 0;
11722 mid = (mid + Math.imul(al1, bh1)) | 0;
11723 mid = (mid + Math.imul(ah1, bl1)) | 0;
11724 hi = (hi + Math.imul(ah1, bh1)) | 0;
11725 lo = (lo + Math.imul(al0, bl2)) | 0;
11726 mid = (mid + Math.imul(al0, bh2)) | 0;
11727 mid = (mid + Math.imul(ah0, bl2)) | 0;
11728 hi = (hi + Math.imul(ah0, bh2)) | 0;
11729 var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11730 c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
11731 w2 &= 0x3ffffff;
11732 /* k = 3 */
11733 lo = Math.imul(al3, bl0);
11734 mid = Math.imul(al3, bh0);
11735 mid = (mid + Math.imul(ah3, bl0)) | 0;
11736 hi = Math.imul(ah3, bh0);
11737 lo = (lo + Math.imul(al2, bl1)) | 0;
11738 mid = (mid + Math.imul(al2, bh1)) | 0;
11739 mid = (mid + Math.imul(ah2, bl1)) | 0;
11740 hi = (hi + Math.imul(ah2, bh1)) | 0;
11741 lo = (lo + Math.imul(al1, bl2)) | 0;
11742 mid = (mid + Math.imul(al1, bh2)) | 0;
11743 mid = (mid + Math.imul(ah1, bl2)) | 0;
11744 hi = (hi + Math.imul(ah1, bh2)) | 0;
11745 lo = (lo + Math.imul(al0, bl3)) | 0;
11746 mid = (mid + Math.imul(al0, bh3)) | 0;
11747 mid = (mid + Math.imul(ah0, bl3)) | 0;
11748 hi = (hi + Math.imul(ah0, bh3)) | 0;
11749 var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11750 c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
11751 w3 &= 0x3ffffff;
11752 /* k = 4 */
11753 lo = Math.imul(al4, bl0);
11754 mid = Math.imul(al4, bh0);
11755 mid = (mid + Math.imul(ah4, bl0)) | 0;
11756 hi = Math.imul(ah4, bh0);
11757 lo = (lo + Math.imul(al3, bl1)) | 0;
11758 mid = (mid + Math.imul(al3, bh1)) | 0;
11759 mid = (mid + Math.imul(ah3, bl1)) | 0;
11760 hi = (hi + Math.imul(ah3, bh1)) | 0;
11761 lo = (lo + Math.imul(al2, bl2)) | 0;
11762 mid = (mid + Math.imul(al2, bh2)) | 0;
11763 mid = (mid + Math.imul(ah2, bl2)) | 0;
11764 hi = (hi + Math.imul(ah2, bh2)) | 0;
11765 lo = (lo + Math.imul(al1, bl3)) | 0;
11766 mid = (mid + Math.imul(al1, bh3)) | 0;
11767 mid = (mid + Math.imul(ah1, bl3)) | 0;
11768 hi = (hi + Math.imul(ah1, bh3)) | 0;
11769 lo = (lo + Math.imul(al0, bl4)) | 0;
11770 mid = (mid + Math.imul(al0, bh4)) | 0;
11771 mid = (mid + Math.imul(ah0, bl4)) | 0;
11772 hi = (hi + Math.imul(ah0, bh4)) | 0;
11773 var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11774 c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
11775 w4 &= 0x3ffffff;
11776 /* k = 5 */
11777 lo = Math.imul(al5, bl0);
11778 mid = Math.imul(al5, bh0);
11779 mid = (mid + Math.imul(ah5, bl0)) | 0;
11780 hi = Math.imul(ah5, bh0);
11781 lo = (lo + Math.imul(al4, bl1)) | 0;
11782 mid = (mid + Math.imul(al4, bh1)) | 0;
11783 mid = (mid + Math.imul(ah4, bl1)) | 0;
11784 hi = (hi + Math.imul(ah4, bh1)) | 0;
11785 lo = (lo + Math.imul(al3, bl2)) | 0;
11786 mid = (mid + Math.imul(al3, bh2)) | 0;
11787 mid = (mid + Math.imul(ah3, bl2)) | 0;
11788 hi = (hi + Math.imul(ah3, bh2)) | 0;
11789 lo = (lo + Math.imul(al2, bl3)) | 0;
11790 mid = (mid + Math.imul(al2, bh3)) | 0;
11791 mid = (mid + Math.imul(ah2, bl3)) | 0;
11792 hi = (hi + Math.imul(ah2, bh3)) | 0;
11793 lo = (lo + Math.imul(al1, bl4)) | 0;
11794 mid = (mid + Math.imul(al1, bh4)) | 0;
11795 mid = (mid + Math.imul(ah1, bl4)) | 0;
11796 hi = (hi + Math.imul(ah1, bh4)) | 0;
11797 lo = (lo + Math.imul(al0, bl5)) | 0;
11798 mid = (mid + Math.imul(al0, bh5)) | 0;
11799 mid = (mid + Math.imul(ah0, bl5)) | 0;
11800 hi = (hi + Math.imul(ah0, bh5)) | 0;
11801 var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11802 c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
11803 w5 &= 0x3ffffff;
11804 /* k = 6 */
11805 lo = Math.imul(al6, bl0);
11806 mid = Math.imul(al6, bh0);
11807 mid = (mid + Math.imul(ah6, bl0)) | 0;
11808 hi = Math.imul(ah6, bh0);
11809 lo = (lo + Math.imul(al5, bl1)) | 0;
11810 mid = (mid + Math.imul(al5, bh1)) | 0;
11811 mid = (mid + Math.imul(ah5, bl1)) | 0;
11812 hi = (hi + Math.imul(ah5, bh1)) | 0;
11813 lo = (lo + Math.imul(al4, bl2)) | 0;
11814 mid = (mid + Math.imul(al4, bh2)) | 0;
11815 mid = (mid + Math.imul(ah4, bl2)) | 0;
11816 hi = (hi + Math.imul(ah4, bh2)) | 0;
11817 lo = (lo + Math.imul(al3, bl3)) | 0;
11818 mid = (mid + Math.imul(al3, bh3)) | 0;
11819 mid = (mid + Math.imul(ah3, bl3)) | 0;
11820 hi = (hi + Math.imul(ah3, bh3)) | 0;
11821 lo = (lo + Math.imul(al2, bl4)) | 0;
11822 mid = (mid + Math.imul(al2, bh4)) | 0;
11823 mid = (mid + Math.imul(ah2, bl4)) | 0;
11824 hi = (hi + Math.imul(ah2, bh4)) | 0;
11825 lo = (lo + Math.imul(al1, bl5)) | 0;
11826 mid = (mid + Math.imul(al1, bh5)) | 0;
11827 mid = (mid + Math.imul(ah1, bl5)) | 0;
11828 hi = (hi + Math.imul(ah1, bh5)) | 0;
11829 lo = (lo + Math.imul(al0, bl6)) | 0;
11830 mid = (mid + Math.imul(al0, bh6)) | 0;
11831 mid = (mid + Math.imul(ah0, bl6)) | 0;
11832 hi = (hi + Math.imul(ah0, bh6)) | 0;
11833 var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11834 c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
11835 w6 &= 0x3ffffff;
11836 /* k = 7 */
11837 lo = Math.imul(al7, bl0);
11838 mid = Math.imul(al7, bh0);
11839 mid = (mid + Math.imul(ah7, bl0)) | 0;
11840 hi = Math.imul(ah7, bh0);
11841 lo = (lo + Math.imul(al6, bl1)) | 0;
11842 mid = (mid + Math.imul(al6, bh1)) | 0;
11843 mid = (mid + Math.imul(ah6, bl1)) | 0;
11844 hi = (hi + Math.imul(ah6, bh1)) | 0;
11845 lo = (lo + Math.imul(al5, bl2)) | 0;
11846 mid = (mid + Math.imul(al5, bh2)) | 0;
11847 mid = (mid + Math.imul(ah5, bl2)) | 0;
11848 hi = (hi + Math.imul(ah5, bh2)) | 0;
11849 lo = (lo + Math.imul(al4, bl3)) | 0;
11850 mid = (mid + Math.imul(al4, bh3)) | 0;
11851 mid = (mid + Math.imul(ah4, bl3)) | 0;
11852 hi = (hi + Math.imul(ah4, bh3)) | 0;
11853 lo = (lo + Math.imul(al3, bl4)) | 0;
11854 mid = (mid + Math.imul(al3, bh4)) | 0;
11855 mid = (mid + Math.imul(ah3, bl4)) | 0;
11856 hi = (hi + Math.imul(ah3, bh4)) | 0;
11857 lo = (lo + Math.imul(al2, bl5)) | 0;
11858 mid = (mid + Math.imul(al2, bh5)) | 0;
11859 mid = (mid + Math.imul(ah2, bl5)) | 0;
11860 hi = (hi + Math.imul(ah2, bh5)) | 0;
11861 lo = (lo + Math.imul(al1, bl6)) | 0;
11862 mid = (mid + Math.imul(al1, bh6)) | 0;
11863 mid = (mid + Math.imul(ah1, bl6)) | 0;
11864 hi = (hi + Math.imul(ah1, bh6)) | 0;
11865 lo = (lo + Math.imul(al0, bl7)) | 0;
11866 mid = (mid + Math.imul(al0, bh7)) | 0;
11867 mid = (mid + Math.imul(ah0, bl7)) | 0;
11868 hi = (hi + Math.imul(ah0, bh7)) | 0;
11869 var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11870 c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
11871 w7 &= 0x3ffffff;
11872 /* k = 8 */
11873 lo = Math.imul(al8, bl0);
11874 mid = Math.imul(al8, bh0);
11875 mid = (mid + Math.imul(ah8, bl0)) | 0;
11876 hi = Math.imul(ah8, bh0);
11877 lo = (lo + Math.imul(al7, bl1)) | 0;
11878 mid = (mid + Math.imul(al7, bh1)) | 0;
11879 mid = (mid + Math.imul(ah7, bl1)) | 0;
11880 hi = (hi + Math.imul(ah7, bh1)) | 0;
11881 lo = (lo + Math.imul(al6, bl2)) | 0;
11882 mid = (mid + Math.imul(al6, bh2)) | 0;
11883 mid = (mid + Math.imul(ah6, bl2)) | 0;
11884 hi = (hi + Math.imul(ah6, bh2)) | 0;
11885 lo = (lo + Math.imul(al5, bl3)) | 0;
11886 mid = (mid + Math.imul(al5, bh3)) | 0;
11887 mid = (mid + Math.imul(ah5, bl3)) | 0;
11888 hi = (hi + Math.imul(ah5, bh3)) | 0;
11889 lo = (lo + Math.imul(al4, bl4)) | 0;
11890 mid = (mid + Math.imul(al4, bh4)) | 0;
11891 mid = (mid + Math.imul(ah4, bl4)) | 0;
11892 hi = (hi + Math.imul(ah4, bh4)) | 0;
11893 lo = (lo + Math.imul(al3, bl5)) | 0;
11894 mid = (mid + Math.imul(al3, bh5)) | 0;
11895 mid = (mid + Math.imul(ah3, bl5)) | 0;
11896 hi = (hi + Math.imul(ah3, bh5)) | 0;
11897 lo = (lo + Math.imul(al2, bl6)) | 0;
11898 mid = (mid + Math.imul(al2, bh6)) | 0;
11899 mid = (mid + Math.imul(ah2, bl6)) | 0;
11900 hi = (hi + Math.imul(ah2, bh6)) | 0;
11901 lo = (lo + Math.imul(al1, bl7)) | 0;
11902 mid = (mid + Math.imul(al1, bh7)) | 0;
11903 mid = (mid + Math.imul(ah1, bl7)) | 0;
11904 hi = (hi + Math.imul(ah1, bh7)) | 0;
11905 lo = (lo + Math.imul(al0, bl8)) | 0;
11906 mid = (mid + Math.imul(al0, bh8)) | 0;
11907 mid = (mid + Math.imul(ah0, bl8)) | 0;
11908 hi = (hi + Math.imul(ah0, bh8)) | 0;
11909 var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11910 c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
11911 w8 &= 0x3ffffff;
11912 /* k = 9 */
11913 lo = Math.imul(al9, bl0);
11914 mid = Math.imul(al9, bh0);
11915 mid = (mid + Math.imul(ah9, bl0)) | 0;
11916 hi = Math.imul(ah9, bh0);
11917 lo = (lo + Math.imul(al8, bl1)) | 0;
11918 mid = (mid + Math.imul(al8, bh1)) | 0;
11919 mid = (mid + Math.imul(ah8, bl1)) | 0;
11920 hi = (hi + Math.imul(ah8, bh1)) | 0;
11921 lo = (lo + Math.imul(al7, bl2)) | 0;
11922 mid = (mid + Math.imul(al7, bh2)) | 0;
11923 mid = (mid + Math.imul(ah7, bl2)) | 0;
11924 hi = (hi + Math.imul(ah7, bh2)) | 0;
11925 lo = (lo + Math.imul(al6, bl3)) | 0;
11926 mid = (mid + Math.imul(al6, bh3)) | 0;
11927 mid = (mid + Math.imul(ah6, bl3)) | 0;
11928 hi = (hi + Math.imul(ah6, bh3)) | 0;
11929 lo = (lo + Math.imul(al5, bl4)) | 0;
11930 mid = (mid + Math.imul(al5, bh4)) | 0;
11931 mid = (mid + Math.imul(ah5, bl4)) | 0;
11932 hi = (hi + Math.imul(ah5, bh4)) | 0;
11933 lo = (lo + Math.imul(al4, bl5)) | 0;
11934 mid = (mid + Math.imul(al4, bh5)) | 0;
11935 mid = (mid + Math.imul(ah4, bl5)) | 0;
11936 hi = (hi + Math.imul(ah4, bh5)) | 0;
11937 lo = (lo + Math.imul(al3, bl6)) | 0;
11938 mid = (mid + Math.imul(al3, bh6)) | 0;
11939 mid = (mid + Math.imul(ah3, bl6)) | 0;
11940 hi = (hi + Math.imul(ah3, bh6)) | 0;
11941 lo = (lo + Math.imul(al2, bl7)) | 0;
11942 mid = (mid + Math.imul(al2, bh7)) | 0;
11943 mid = (mid + Math.imul(ah2, bl7)) | 0;
11944 hi = (hi + Math.imul(ah2, bh7)) | 0;
11945 lo = (lo + Math.imul(al1, bl8)) | 0;
11946 mid = (mid + Math.imul(al1, bh8)) | 0;
11947 mid = (mid + Math.imul(ah1, bl8)) | 0;
11948 hi = (hi + Math.imul(ah1, bh8)) | 0;
11949 lo = (lo + Math.imul(al0, bl9)) | 0;
11950 mid = (mid + Math.imul(al0, bh9)) | 0;
11951 mid = (mid + Math.imul(ah0, bl9)) | 0;
11952 hi = (hi + Math.imul(ah0, bh9)) | 0;
11953 var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11954 c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
11955 w9 &= 0x3ffffff;
11956 /* k = 10 */
11957 lo = Math.imul(al9, bl1);
11958 mid = Math.imul(al9, bh1);
11959 mid = (mid + Math.imul(ah9, bl1)) | 0;
11960 hi = Math.imul(ah9, bh1);
11961 lo = (lo + Math.imul(al8, bl2)) | 0;
11962 mid = (mid + Math.imul(al8, bh2)) | 0;
11963 mid = (mid + Math.imul(ah8, bl2)) | 0;
11964 hi = (hi + Math.imul(ah8, bh2)) | 0;
11965 lo = (lo + Math.imul(al7, bl3)) | 0;
11966 mid = (mid + Math.imul(al7, bh3)) | 0;
11967 mid = (mid + Math.imul(ah7, bl3)) | 0;
11968 hi = (hi + Math.imul(ah7, bh3)) | 0;
11969 lo = (lo + Math.imul(al6, bl4)) | 0;
11970 mid = (mid + Math.imul(al6, bh4)) | 0;
11971 mid = (mid + Math.imul(ah6, bl4)) | 0;
11972 hi = (hi + Math.imul(ah6, bh4)) | 0;
11973 lo = (lo + Math.imul(al5, bl5)) | 0;
11974 mid = (mid + Math.imul(al5, bh5)) | 0;
11975 mid = (mid + Math.imul(ah5, bl5)) | 0;
11976 hi = (hi + Math.imul(ah5, bh5)) | 0;
11977 lo = (lo + Math.imul(al4, bl6)) | 0;
11978 mid = (mid + Math.imul(al4, bh6)) | 0;
11979 mid = (mid + Math.imul(ah4, bl6)) | 0;
11980 hi = (hi + Math.imul(ah4, bh6)) | 0;
11981 lo = (lo + Math.imul(al3, bl7)) | 0;
11982 mid = (mid + Math.imul(al3, bh7)) | 0;
11983 mid = (mid + Math.imul(ah3, bl7)) | 0;
11984 hi = (hi + Math.imul(ah3, bh7)) | 0;
11985 lo = (lo + Math.imul(al2, bl8)) | 0;
11986 mid = (mid + Math.imul(al2, bh8)) | 0;
11987 mid = (mid + Math.imul(ah2, bl8)) | 0;
11988 hi = (hi + Math.imul(ah2, bh8)) | 0;
11989 lo = (lo + Math.imul(al1, bl9)) | 0;
11990 mid = (mid + Math.imul(al1, bh9)) | 0;
11991 mid = (mid + Math.imul(ah1, bl9)) | 0;
11992 hi = (hi + Math.imul(ah1, bh9)) | 0;
11993 var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11994 c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
11995 w10 &= 0x3ffffff;
11996 /* k = 11 */
11997 lo = Math.imul(al9, bl2);
11998 mid = Math.imul(al9, bh2);
11999 mid = (mid + Math.imul(ah9, bl2)) | 0;
12000 hi = Math.imul(ah9, bh2);
12001 lo = (lo + Math.imul(al8, bl3)) | 0;
12002 mid = (mid + Math.imul(al8, bh3)) | 0;
12003 mid = (mid + Math.imul(ah8, bl3)) | 0;
12004 hi = (hi + Math.imul(ah8, bh3)) | 0;
12005 lo = (lo + Math.imul(al7, bl4)) | 0;
12006 mid = (mid + Math.imul(al7, bh4)) | 0;
12007 mid = (mid + Math.imul(ah7, bl4)) | 0;
12008 hi = (hi + Math.imul(ah7, bh4)) | 0;
12009 lo = (lo + Math.imul(al6, bl5)) | 0;
12010 mid = (mid + Math.imul(al6, bh5)) | 0;
12011 mid = (mid + Math.imul(ah6, bl5)) | 0;
12012 hi = (hi + Math.imul(ah6, bh5)) | 0;
12013 lo = (lo + Math.imul(al5, bl6)) | 0;
12014 mid = (mid + Math.imul(al5, bh6)) | 0;
12015 mid = (mid + Math.imul(ah5, bl6)) | 0;
12016 hi = (hi + Math.imul(ah5, bh6)) | 0;
12017 lo = (lo + Math.imul(al4, bl7)) | 0;
12018 mid = (mid + Math.imul(al4, bh7)) | 0;
12019 mid = (mid + Math.imul(ah4, bl7)) | 0;
12020 hi = (hi + Math.imul(ah4, bh7)) | 0;
12021 lo = (lo + Math.imul(al3, bl8)) | 0;
12022 mid = (mid + Math.imul(al3, bh8)) | 0;
12023 mid = (mid + Math.imul(ah3, bl8)) | 0;
12024 hi = (hi + Math.imul(ah3, bh8)) | 0;
12025 lo = (lo + Math.imul(al2, bl9)) | 0;
12026 mid = (mid + Math.imul(al2, bh9)) | 0;
12027 mid = (mid + Math.imul(ah2, bl9)) | 0;
12028 hi = (hi + Math.imul(ah2, bh9)) | 0;
12029 var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12030 c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
12031 w11 &= 0x3ffffff;
12032 /* k = 12 */
12033 lo = Math.imul(al9, bl3);
12034 mid = Math.imul(al9, bh3);
12035 mid = (mid + Math.imul(ah9, bl3)) | 0;
12036 hi = Math.imul(ah9, bh3);
12037 lo = (lo + Math.imul(al8, bl4)) | 0;
12038 mid = (mid + Math.imul(al8, bh4)) | 0;
12039 mid = (mid + Math.imul(ah8, bl4)) | 0;
12040 hi = (hi + Math.imul(ah8, bh4)) | 0;
12041 lo = (lo + Math.imul(al7, bl5)) | 0;
12042 mid = (mid + Math.imul(al7, bh5)) | 0;
12043 mid = (mid + Math.imul(ah7, bl5)) | 0;
12044 hi = (hi + Math.imul(ah7, bh5)) | 0;
12045 lo = (lo + Math.imul(al6, bl6)) | 0;
12046 mid = (mid + Math.imul(al6, bh6)) | 0;
12047 mid = (mid + Math.imul(ah6, bl6)) | 0;
12048 hi = (hi + Math.imul(ah6, bh6)) | 0;
12049 lo = (lo + Math.imul(al5, bl7)) | 0;
12050 mid = (mid + Math.imul(al5, bh7)) | 0;
12051 mid = (mid + Math.imul(ah5, bl7)) | 0;
12052 hi = (hi + Math.imul(ah5, bh7)) | 0;
12053 lo = (lo + Math.imul(al4, bl8)) | 0;
12054 mid = (mid + Math.imul(al4, bh8)) | 0;
12055 mid = (mid + Math.imul(ah4, bl8)) | 0;
12056 hi = (hi + Math.imul(ah4, bh8)) | 0;
12057 lo = (lo + Math.imul(al3, bl9)) | 0;
12058 mid = (mid + Math.imul(al3, bh9)) | 0;
12059 mid = (mid + Math.imul(ah3, bl9)) | 0;
12060 hi = (hi + Math.imul(ah3, bh9)) | 0;
12061 var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12062 c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
12063 w12 &= 0x3ffffff;
12064 /* k = 13 */
12065 lo = Math.imul(al9, bl4);
12066 mid = Math.imul(al9, bh4);
12067 mid = (mid + Math.imul(ah9, bl4)) | 0;
12068 hi = Math.imul(ah9, bh4);
12069 lo = (lo + Math.imul(al8, bl5)) | 0;
12070 mid = (mid + Math.imul(al8, bh5)) | 0;
12071 mid = (mid + Math.imul(ah8, bl5)) | 0;
12072 hi = (hi + Math.imul(ah8, bh5)) | 0;
12073 lo = (lo + Math.imul(al7, bl6)) | 0;
12074 mid = (mid + Math.imul(al7, bh6)) | 0;
12075 mid = (mid + Math.imul(ah7, bl6)) | 0;
12076 hi = (hi + Math.imul(ah7, bh6)) | 0;
12077 lo = (lo + Math.imul(al6, bl7)) | 0;
12078 mid = (mid + Math.imul(al6, bh7)) | 0;
12079 mid = (mid + Math.imul(ah6, bl7)) | 0;
12080 hi = (hi + Math.imul(ah6, bh7)) | 0;
12081 lo = (lo + Math.imul(al5, bl8)) | 0;
12082 mid = (mid + Math.imul(al5, bh8)) | 0;
12083 mid = (mid + Math.imul(ah5, bl8)) | 0;
12084 hi = (hi + Math.imul(ah5, bh8)) | 0;
12085 lo = (lo + Math.imul(al4, bl9)) | 0;
12086 mid = (mid + Math.imul(al4, bh9)) | 0;
12087 mid = (mid + Math.imul(ah4, bl9)) | 0;
12088 hi = (hi + Math.imul(ah4, bh9)) | 0;
12089 var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12090 c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
12091 w13 &= 0x3ffffff;
12092 /* k = 14 */
12093 lo = Math.imul(al9, bl5);
12094 mid = Math.imul(al9, bh5);
12095 mid = (mid + Math.imul(ah9, bl5)) | 0;
12096 hi = Math.imul(ah9, bh5);
12097 lo = (lo + Math.imul(al8, bl6)) | 0;
12098 mid = (mid + Math.imul(al8, bh6)) | 0;
12099 mid = (mid + Math.imul(ah8, bl6)) | 0;
12100 hi = (hi + Math.imul(ah8, bh6)) | 0;
12101 lo = (lo + Math.imul(al7, bl7)) | 0;
12102 mid = (mid + Math.imul(al7, bh7)) | 0;
12103 mid = (mid + Math.imul(ah7, bl7)) | 0;
12104 hi = (hi + Math.imul(ah7, bh7)) | 0;
12105 lo = (lo + Math.imul(al6, bl8)) | 0;
12106 mid = (mid + Math.imul(al6, bh8)) | 0;
12107 mid = (mid + Math.imul(ah6, bl8)) | 0;
12108 hi = (hi + Math.imul(ah6, bh8)) | 0;
12109 lo = (lo + Math.imul(al5, bl9)) | 0;
12110 mid = (mid + Math.imul(al5, bh9)) | 0;
12111 mid = (mid + Math.imul(ah5, bl9)) | 0;
12112 hi = (hi + Math.imul(ah5, bh9)) | 0;
12113 var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12114 c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
12115 w14 &= 0x3ffffff;
12116 /* k = 15 */
12117 lo = Math.imul(al9, bl6);
12118 mid = Math.imul(al9, bh6);
12119 mid = (mid + Math.imul(ah9, bl6)) | 0;
12120 hi = Math.imul(ah9, bh6);
12121 lo = (lo + Math.imul(al8, bl7)) | 0;
12122 mid = (mid + Math.imul(al8, bh7)) | 0;
12123 mid = (mid + Math.imul(ah8, bl7)) | 0;
12124 hi = (hi + Math.imul(ah8, bh7)) | 0;
12125 lo = (lo + Math.imul(al7, bl8)) | 0;
12126 mid = (mid + Math.imul(al7, bh8)) | 0;
12127 mid = (mid + Math.imul(ah7, bl8)) | 0;
12128 hi = (hi + Math.imul(ah7, bh8)) | 0;
12129 lo = (lo + Math.imul(al6, bl9)) | 0;
12130 mid = (mid + Math.imul(al6, bh9)) | 0;
12131 mid = (mid + Math.imul(ah6, bl9)) | 0;
12132 hi = (hi + Math.imul(ah6, bh9)) | 0;
12133 var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12134 c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
12135 w15 &= 0x3ffffff;
12136 /* k = 16 */
12137 lo = Math.imul(al9, bl7);
12138 mid = Math.imul(al9, bh7);
12139 mid = (mid + Math.imul(ah9, bl7)) | 0;
12140 hi = Math.imul(ah9, bh7);
12141 lo = (lo + Math.imul(al8, bl8)) | 0;
12142 mid = (mid + Math.imul(al8, bh8)) | 0;
12143 mid = (mid + Math.imul(ah8, bl8)) | 0;
12144 hi = (hi + Math.imul(ah8, bh8)) | 0;
12145 lo = (lo + Math.imul(al7, bl9)) | 0;
12146 mid = (mid + Math.imul(al7, bh9)) | 0;
12147 mid = (mid + Math.imul(ah7, bl9)) | 0;
12148 hi = (hi + Math.imul(ah7, bh9)) | 0;
12149 var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12150 c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
12151 w16 &= 0x3ffffff;
12152 /* k = 17 */
12153 lo = Math.imul(al9, bl8);
12154 mid = Math.imul(al9, bh8);
12155 mid = (mid + Math.imul(ah9, bl8)) | 0;
12156 hi = Math.imul(ah9, bh8);
12157 lo = (lo + Math.imul(al8, bl9)) | 0;
12158 mid = (mid + Math.imul(al8, bh9)) | 0;
12159 mid = (mid + Math.imul(ah8, bl9)) | 0;
12160 hi = (hi + Math.imul(ah8, bh9)) | 0;
12161 var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12162 c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
12163 w17 &= 0x3ffffff;
12164 /* k = 18 */
12165 lo = Math.imul(al9, bl9);
12166 mid = Math.imul(al9, bh9);
12167 mid = (mid + Math.imul(ah9, bl9)) | 0;
12168 hi = Math.imul(ah9, bh9);
12169 var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12170 c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
12171 w18 &= 0x3ffffff;
12172 o[0] = w0;
12173 o[1] = w1;
12174 o[2] = w2;
12175 o[3] = w3;
12176 o[4] = w4;
12177 o[5] = w5;
12178 o[6] = w6;
12179 o[7] = w7;
12180 o[8] = w8;
12181 o[9] = w9;
12182 o[10] = w10;
12183 o[11] = w11;
12184 o[12] = w12;
12185 o[13] = w13;
12186 o[14] = w14;
12187 o[15] = w15;
12188 o[16] = w16;
12189 o[17] = w17;
12190 o[18] = w18;
12191 if (c !== 0) {
12192 o[19] = c;
12193 out.length++;
12194 }
12195 return out;
12196 };
12197
12198 // Polyfill comb
12199 if (!Math.imul) {
12200 comb10MulTo = smallMulTo;
12201 }
12202
12203 function bigMulTo (self, num, out) {
12204 out.negative = num.negative ^ self.negative;
12205 out.length = self.length + num.length;
12206
12207 var carry = 0;
12208 var hncarry = 0;
12209 for (var k = 0; k < out.length - 1; k++) {
12210 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
12211 // note that ncarry could be >= 0x3ffffff
12212 var ncarry = hncarry;
12213 hncarry = 0;
12214 var rword = carry & 0x3ffffff;
12215 var maxJ = Math.min(k, num.length - 1);
12216 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
12217 var i = k - j;
12218 var a = self.words[i] | 0;
12219 var b = num.words[j] | 0;
12220 var r = a * b;
12221
12222 var lo = r & 0x3ffffff;
12223 ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
12224 lo = (lo + rword) | 0;
12225 rword = lo & 0x3ffffff;
12226 ncarry = (ncarry + (lo >>> 26)) | 0;
12227
12228 hncarry += ncarry >>> 26;
12229 ncarry &= 0x3ffffff;
12230 }
12231 out.words[k] = rword;
12232 carry = ncarry;
12233 ncarry = hncarry;
12234 }
12235 if (carry !== 0) {
12236 out.words[k] = carry;
12237 } else {
12238 out.length--;
12239 }
12240
12241 return out.strip();
12242 }
12243
12244 function jumboMulTo (self, num, out) {
12245 var fftm = new FFTM();
12246 return fftm.mulp(self, num, out);
12247 }
12248
12249 BN.prototype.mulTo = function mulTo (num, out) {
12250 var res;
12251 var len = this.length + num.length;
12252 if (this.length === 10 && num.length === 10) {
12253 res = comb10MulTo(this, num, out);
12254 } else if (len < 63) {
12255 res = smallMulTo(this, num, out);
12256 } else if (len < 1024) {
12257 res = bigMulTo(this, num, out);
12258 } else {
12259 res = jumboMulTo(this, num, out);
12260 }
12261
12262 return res;
12263 };
12264
12265 // Cooley-Tukey algorithm for FFT
12266 // slightly revisited to rely on looping instead of recursion
12267
12268 function FFTM (x, y) {
12269 this.x = x;
12270 this.y = y;
12271 }
12272
12273 FFTM.prototype.makeRBT = function makeRBT (N) {
12274 var t = new Array(N);
12275 var l = BN.prototype._countBits(N) - 1;
12276 for (var i = 0; i < N; i++) {
12277 t[i] = this.revBin(i, l, N);
12278 }
12279
12280 return t;
12281 };
12282
12283 // Returns binary-reversed representation of `x`
12284 FFTM.prototype.revBin = function revBin (x, l, N) {
12285 if (x === 0 || x === N - 1) return x;
12286
12287 var rb = 0;
12288 for (var i = 0; i < l; i++) {
12289 rb |= (x & 1) << (l - i - 1);
12290 x >>= 1;
12291 }
12292
12293 return rb;
12294 };
12295
12296 // Performs "tweedling" phase, therefore 'emulating'
12297 // behaviour of the recursive algorithm
12298 FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
12299 for (var i = 0; i < N; i++) {
12300 rtws[i] = rws[rbt[i]];
12301 itws[i] = iws[rbt[i]];
12302 }
12303 };
12304
12305 FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
12306 this.permute(rbt, rws, iws, rtws, itws, N);
12307
12308 for (var s = 1; s < N; s <<= 1) {
12309 var l = s << 1;
12310
12311 var rtwdf = Math.cos(2 * Math.PI / l);
12312 var itwdf = Math.sin(2 * Math.PI / l);
12313
12314 for (var p = 0; p < N; p += l) {
12315 var rtwdf_ = rtwdf;
12316 var itwdf_ = itwdf;
12317
12318 for (var j = 0; j < s; j++) {
12319 var re = rtws[p + j];
12320 var ie = itws[p + j];
12321
12322 var ro = rtws[p + j + s];
12323 var io = itws[p + j + s];
12324
12325 var rx = rtwdf_ * ro - itwdf_ * io;
12326
12327 io = rtwdf_ * io + itwdf_ * ro;
12328 ro = rx;
12329
12330 rtws[p + j] = re + ro;
12331 itws[p + j] = ie + io;
12332
12333 rtws[p + j + s] = re - ro;
12334 itws[p + j + s] = ie - io;
12335
12336 /* jshint maxdepth : false */
12337 if (j !== l) {
12338 rx = rtwdf * rtwdf_ - itwdf * itwdf_;
12339
12340 itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
12341 rtwdf_ = rx;
12342 }
12343 }
12344 }
12345 }
12346 };
12347
12348 FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
12349 var N = Math.max(m, n) | 1;
12350 var odd = N & 1;
12351 var i = 0;
12352 for (N = N / 2 | 0; N; N = N >>> 1) {
12353 i++;
12354 }
12355
12356 return 1 << i + 1 + odd;
12357 };
12358
12359 FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
12360 if (N <= 1) return;
12361
12362 for (var i = 0; i < N / 2; i++) {
12363 var t = rws[i];
12364
12365 rws[i] = rws[N - i - 1];
12366 rws[N - i - 1] = t;
12367
12368 t = iws[i];
12369
12370 iws[i] = -iws[N - i - 1];
12371 iws[N - i - 1] = -t;
12372 }
12373 };
12374
12375 FFTM.prototype.normalize13b = function normalize13b (ws, N) {
12376 var carry = 0;
12377 for (var i = 0; i < N / 2; i++) {
12378 var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
12379 Math.round(ws[2 * i] / N) +
12380 carry;
12381
12382 ws[i] = w & 0x3ffffff;
12383
12384 if (w < 0x4000000) {
12385 carry = 0;
12386 } else {
12387 carry = w / 0x4000000 | 0;
12388 }
12389 }
12390
12391 return ws;
12392 };
12393
12394 FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
12395 var carry = 0;
12396 for (var i = 0; i < len; i++) {
12397 carry = carry + (ws[i] | 0);
12398
12399 rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
12400 rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
12401 }
12402
12403 // Pad with zeroes
12404 for (i = 2 * len; i < N; ++i) {
12405 rws[i] = 0;
12406 }
12407
12408 assert(carry === 0);
12409 assert((carry & ~0x1fff) === 0);
12410 };
12411
12412 FFTM.prototype.stub = function stub (N) {
12413 var ph = new Array(N);
12414 for (var i = 0; i < N; i++) {
12415 ph[i] = 0;
12416 }
12417
12418 return ph;
12419 };
12420
12421 FFTM.prototype.mulp = function mulp (x, y, out) {
12422 var N = 2 * this.guessLen13b(x.length, y.length);
12423
12424 var rbt = this.makeRBT(N);
12425
12426 var _ = this.stub(N);
12427
12428 var rws = new Array(N);
12429 var rwst = new Array(N);
12430 var iwst = new Array(N);
12431
12432 var nrws = new Array(N);
12433 var nrwst = new Array(N);
12434 var niwst = new Array(N);
12435
12436 var rmws = out.words;
12437 rmws.length = N;
12438
12439 this.convert13b(x.words, x.length, rws, N);
12440 this.convert13b(y.words, y.length, nrws, N);
12441
12442 this.transform(rws, _, rwst, iwst, N, rbt);
12443 this.transform(nrws, _, nrwst, niwst, N, rbt);
12444
12445 for (var i = 0; i < N; i++) {
12446 var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
12447 iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
12448 rwst[i] = rx;
12449 }
12450
12451 this.conjugate(rwst, iwst, N);
12452 this.transform(rwst, iwst, rmws, _, N, rbt);
12453 this.conjugate(rmws, _, N);
12454 this.normalize13b(rmws, N);
12455
12456 out.negative = x.negative ^ y.negative;
12457 out.length = x.length + y.length;
12458 return out.strip();
12459 };
12460
12461 // Multiply `this` by `num`
12462 BN.prototype.mul = function mul (num) {
12463 var out = new BN(null);
12464 out.words = new Array(this.length + num.length);
12465 return this.mulTo(num, out);
12466 };
12467
12468 // Multiply employing FFT
12469 BN.prototype.mulf = function mulf (num) {
12470 var out = new BN(null);
12471 out.words = new Array(this.length + num.length);
12472 return jumboMulTo(this, num, out);
12473 };
12474
12475 // In-place Multiplication
12476 BN.prototype.imul = function imul (num) {
12477 return this.clone().mulTo(num, this);
12478 };
12479
12480 BN.prototype.imuln = function imuln (num) {
12481 assert(typeof num === 'number');
12482 assert(num < 0x4000000);
12483
12484 // Carry
12485 var carry = 0;
12486 for (var i = 0; i < this.length; i++) {
12487 var w = (this.words[i] | 0) * num;
12488 var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
12489 carry >>= 26;
12490 carry += (w / 0x4000000) | 0;
12491 // NOTE: lo is 27bit maximum
12492 carry += lo >>> 26;
12493 this.words[i] = lo & 0x3ffffff;
12494 }
12495
12496 if (carry !== 0) {
12497 this.words[i] = carry;
12498 this.length++;
12499 }
12500
12501 return this;
12502 };
12503
12504 BN.prototype.muln = function muln (num) {
12505 return this.clone().imuln(num);
12506 };
12507
12508 // `this` * `this`
12509 BN.prototype.sqr = function sqr () {
12510 return this.mul(this);
12511 };
12512
12513 // `this` * `this` in-place
12514 BN.prototype.isqr = function isqr () {
12515 return this.imul(this.clone());
12516 };
12517
12518 // Math.pow(`this`, `num`)
12519 BN.prototype.pow = function pow (num) {
12520 var w = toBitArray(num);
12521 if (w.length === 0) return new BN(1);
12522
12523 // Skip leading zeroes
12524 var res = this;
12525 for (var i = 0; i < w.length; i++, res = res.sqr()) {
12526 if (w[i] !== 0) break;
12527 }
12528
12529 if (++i < w.length) {
12530 for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
12531 if (w[i] === 0) continue;
12532
12533 res = res.mul(q);
12534 }
12535 }
12536
12537 return res;
12538 };
12539
12540 // Shift-left in-place
12541 BN.prototype.iushln = function iushln (bits) {
12542 assert(typeof bits === 'number' && bits >= 0);
12543 var r = bits % 26;
12544 var s = (bits - r) / 26;
12545 var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
12546 var i;
12547
12548 if (r !== 0) {
12549 var carry = 0;
12550
12551 for (i = 0; i < this.length; i++) {
12552 var newCarry = this.words[i] & carryMask;
12553 var c = ((this.words[i] | 0) - newCarry) << r;
12554 this.words[i] = c | carry;
12555 carry = newCarry >>> (26 - r);
12556 }
12557
12558 if (carry) {
12559 this.words[i] = carry;
12560 this.length++;
12561 }
12562 }
12563
12564 if (s !== 0) {
12565 for (i = this.length - 1; i >= 0; i--) {
12566 this.words[i + s] = this.words[i];
12567 }
12568
12569 for (i = 0; i < s; i++) {
12570 this.words[i] = 0;
12571 }
12572
12573 this.length += s;
12574 }
12575
12576 return this.strip();
12577 };
12578
12579 BN.prototype.ishln = function ishln (bits) {
12580 // TODO(indutny): implement me
12581 assert(this.negative === 0);
12582 return this.iushln(bits);
12583 };
12584
12585 // Shift-right in-place
12586 // NOTE: `hint` is a lowest bit before trailing zeroes
12587 // NOTE: if `extended` is present - it will be filled with destroyed bits
12588 BN.prototype.iushrn = function iushrn (bits, hint, extended) {
12589 assert(typeof bits === 'number' && bits >= 0);
12590 var h;
12591 if (hint) {
12592 h = (hint - (hint % 26)) / 26;
12593 } else {
12594 h = 0;
12595 }
12596
12597 var r = bits % 26;
12598 var s = Math.min((bits - r) / 26, this.length);
12599 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
12600 var maskedWords = extended;
12601
12602 h -= s;
12603 h = Math.max(0, h);
12604
12605 // Extended mode, copy masked part
12606 if (maskedWords) {
12607 for (var i = 0; i < s; i++) {
12608 maskedWords.words[i] = this.words[i];
12609 }
12610 maskedWords.length = s;
12611 }
12612
12613 if (s === 0) {
12614 // No-op, we should not move anything at all
12615 } else if (this.length > s) {
12616 this.length -= s;
12617 for (i = 0; i < this.length; i++) {
12618 this.words[i] = this.words[i + s];
12619 }
12620 } else {
12621 this.words[0] = 0;
12622 this.length = 1;
12623 }
12624
12625 var carry = 0;
12626 for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
12627 var word = this.words[i] | 0;
12628 this.words[i] = (carry << (26 - r)) | (word >>> r);
12629 carry = word & mask;
12630 }
12631
12632 // Push carried bits as a mask
12633 if (maskedWords && carry !== 0) {
12634 maskedWords.words[maskedWords.length++] = carry;
12635 }
12636
12637 if (this.length === 0) {
12638 this.words[0] = 0;
12639 this.length = 1;
12640 }
12641
12642 return this.strip();
12643 };
12644
12645 BN.prototype.ishrn = function ishrn (bits, hint, extended) {
12646 // TODO(indutny): implement me
12647 assert(this.negative === 0);
12648 return this.iushrn(bits, hint, extended);
12649 };
12650
12651 // Shift-left
12652 BN.prototype.shln = function shln (bits) {
12653 return this.clone().ishln(bits);
12654 };
12655
12656 BN.prototype.ushln = function ushln (bits) {
12657 return this.clone().iushln(bits);
12658 };
12659
12660 // Shift-right
12661 BN.prototype.shrn = function shrn (bits) {
12662 return this.clone().ishrn(bits);
12663 };
12664
12665 BN.prototype.ushrn = function ushrn (bits) {
12666 return this.clone().iushrn(bits);
12667 };
12668
12669 // Test if n bit is set
12670 BN.prototype.testn = function testn (bit) {
12671 assert(typeof bit === 'number' && bit >= 0);
12672 var r = bit % 26;
12673 var s = (bit - r) / 26;
12674 var q = 1 << r;
12675
12676 // Fast case: bit is much higher than all existing words
12677 if (this.length <= s) return false;
12678
12679 // Check bit and return
12680 var w = this.words[s];
12681
12682 return !!(w & q);
12683 };
12684
12685 // Return only lowers bits of number (in-place)
12686 BN.prototype.imaskn = function imaskn (bits) {
12687 assert(typeof bits === 'number' && bits >= 0);
12688 var r = bits % 26;
12689 var s = (bits - r) / 26;
12690
12691 assert(this.negative === 0, 'imaskn works only with positive numbers');
12692
12693 if (this.length <= s) {
12694 return this;
12695 }
12696
12697 if (r !== 0) {
12698 s++;
12699 }
12700 this.length = Math.min(s, this.length);
12701
12702 if (r !== 0) {
12703 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
12704 this.words[this.length - 1] &= mask;
12705 }
12706
12707 return this.strip();
12708 };
12709
12710 // Return only lowers bits of number
12711 BN.prototype.maskn = function maskn (bits) {
12712 return this.clone().imaskn(bits);
12713 };
12714
12715 // Add plain number `num` to `this`
12716 BN.prototype.iaddn = function iaddn (num) {
12717 assert(typeof num === 'number');
12718 assert(num < 0x4000000);
12719 if (num < 0) return this.isubn(-num);
12720
12721 // Possible sign change
12722 if (this.negative !== 0) {
12723 if (this.length === 1 && (this.words[0] | 0) < num) {
12724 this.words[0] = num - (this.words[0] | 0);
12725 this.negative = 0;
12726 return this;
12727 }
12728
12729 this.negative = 0;
12730 this.isubn(num);
12731 this.negative = 1;
12732 return this;
12733 }
12734
12735 // Add without checks
12736 return this._iaddn(num);
12737 };
12738
12739 BN.prototype._iaddn = function _iaddn (num) {
12740 this.words[0] += num;
12741
12742 // Carry
12743 for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
12744 this.words[i] -= 0x4000000;
12745 if (i === this.length - 1) {
12746 this.words[i + 1] = 1;
12747 } else {
12748 this.words[i + 1]++;
12749 }
12750 }
12751 this.length = Math.max(this.length, i + 1);
12752
12753 return this;
12754 };
12755
12756 // Subtract plain number `num` from `this`
12757 BN.prototype.isubn = function isubn (num) {
12758 assert(typeof num === 'number');
12759 assert(num < 0x4000000);
12760 if (num < 0) return this.iaddn(-num);
12761
12762 if (this.negative !== 0) {
12763 this.negative = 0;
12764 this.iaddn(num);
12765 this.negative = 1;
12766 return this;
12767 }
12768
12769 this.words[0] -= num;
12770
12771 if (this.length === 1 && this.words[0] < 0) {
12772 this.words[0] = -this.words[0];
12773 this.negative = 1;
12774 } else {
12775 // Carry
12776 for (var i = 0; i < this.length && this.words[i] < 0; i++) {
12777 this.words[i] += 0x4000000;
12778 this.words[i + 1] -= 1;
12779 }
12780 }
12781
12782 return this.strip();
12783 };
12784
12785 BN.prototype.addn = function addn (num) {
12786 return this.clone().iaddn(num);
12787 };
12788
12789 BN.prototype.subn = function subn (num) {
12790 return this.clone().isubn(num);
12791 };
12792
12793 BN.prototype.iabs = function iabs () {
12794 this.negative = 0;
12795
12796 return this;
12797 };
12798
12799 BN.prototype.abs = function abs () {
12800 return this.clone().iabs();
12801 };
12802
12803 BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
12804 var len = num.length + shift;
12805 var i;
12806
12807 this._expand(len);
12808
12809 var w;
12810 var carry = 0;
12811 for (i = 0; i < num.length; i++) {
12812 w = (this.words[i + shift] | 0) + carry;
12813 var right = (num.words[i] | 0) * mul;
12814 w -= right & 0x3ffffff;
12815 carry = (w >> 26) - ((right / 0x4000000) | 0);
12816 this.words[i + shift] = w & 0x3ffffff;
12817 }
12818 for (; i < this.length - shift; i++) {
12819 w = (this.words[i + shift] | 0) + carry;
12820 carry = w >> 26;
12821 this.words[i + shift] = w & 0x3ffffff;
12822 }
12823
12824 if (carry === 0) return this.strip();
12825
12826 // Subtraction overflow
12827 assert(carry === -1);
12828 carry = 0;
12829 for (i = 0; i < this.length; i++) {
12830 w = -(this.words[i] | 0) + carry;
12831 carry = w >> 26;
12832 this.words[i] = w & 0x3ffffff;
12833 }
12834 this.negative = 1;
12835
12836 return this.strip();
12837 };
12838
12839 BN.prototype._wordDiv = function _wordDiv (num, mode) {
12840 var shift = this.length - num.length;
12841
12842 var a = this.clone();
12843 var b = num;
12844
12845 // Normalize
12846 var bhi = b.words[b.length - 1] | 0;
12847 var bhiBits = this._countBits(bhi);
12848 shift = 26 - bhiBits;
12849 if (shift !== 0) {
12850 b = b.ushln(shift);
12851 a.iushln(shift);
12852 bhi = b.words[b.length - 1] | 0;
12853 }
12854
12855 // Initialize quotient
12856 var m = a.length - b.length;
12857 var q;
12858
12859 if (mode !== 'mod') {
12860 q = new BN(null);
12861 q.length = m + 1;
12862 q.words = new Array(q.length);
12863 for (var i = 0; i < q.length; i++) {
12864 q.words[i] = 0;
12865 }
12866 }
12867
12868 var diff = a.clone()._ishlnsubmul(b, 1, m);
12869 if (diff.negative === 0) {
12870 a = diff;
12871 if (q) {
12872 q.words[m] = 1;
12873 }
12874 }
12875
12876 for (var j = m - 1; j >= 0; j--) {
12877 var qj = (a.words[b.length + j] | 0) * 0x4000000 +
12878 (a.words[b.length + j - 1] | 0);
12879
12880 // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
12881 // (0x7ffffff)
12882 qj = Math.min((qj / bhi) | 0, 0x3ffffff);
12883
12884 a._ishlnsubmul(b, qj, j);
12885 while (a.negative !== 0) {
12886 qj--;
12887 a.negative = 0;
12888 a._ishlnsubmul(b, 1, j);
12889 if (!a.isZero()) {
12890 a.negative ^= 1;
12891 }
12892 }
12893 if (q) {
12894 q.words[j] = qj;
12895 }
12896 }
12897 if (q) {
12898 q.strip();
12899 }
12900 a.strip();
12901
12902 // Denormalize
12903 if (mode !== 'div' && shift !== 0) {
12904 a.iushrn(shift);
12905 }
12906
12907 return {
12908 div: q || null,
12909 mod: a
12910 };
12911 };
12912
12913 // NOTE: 1) `mode` can be set to `mod` to request mod only,
12914 // to `div` to request div only, or be absent to
12915 // request both div & mod
12916 // 2) `positive` is true if unsigned mod is requested
12917 BN.prototype.divmod = function divmod (num, mode, positive) {
12918 assert(!num.isZero());
12919
12920 if (this.isZero()) {
12921 return {
12922 div: new BN(0),
12923 mod: new BN(0)
12924 };
12925 }
12926
12927 var div, mod, res;
12928 if (this.negative !== 0 && num.negative === 0) {
12929 res = this.neg().divmod(num, mode);
12930
12931 if (mode !== 'mod') {
12932 div = res.div.neg();
12933 }
12934
12935 if (mode !== 'div') {
12936 mod = res.mod.neg();
12937 if (positive && mod.negative !== 0) {
12938 mod.iadd(num);
12939 }
12940 }
12941
12942 return {
12943 div: div,
12944 mod: mod
12945 };
12946 }
12947
12948 if (this.negative === 0 && num.negative !== 0) {
12949 res = this.divmod(num.neg(), mode);
12950
12951 if (mode !== 'mod') {
12952 div = res.div.neg();
12953 }
12954
12955 return {
12956 div: div,
12957 mod: res.mod
12958 };
12959 }
12960
12961 if ((this.negative & num.negative) !== 0) {
12962 res = this.neg().divmod(num.neg(), mode);
12963
12964 if (mode !== 'div') {
12965 mod = res.mod.neg();
12966 if (positive && mod.negative !== 0) {
12967 mod.isub(num);
12968 }
12969 }
12970
12971 return {
12972 div: res.div,
12973 mod: mod
12974 };
12975 }
12976
12977 // Both numbers are positive at this point
12978
12979 // Strip both numbers to approximate shift value
12980 if (num.length > this.length || this.cmp(num) < 0) {
12981 return {
12982 div: new BN(0),
12983 mod: this
12984 };
12985 }
12986
12987 // Very short reduction
12988 if (num.length === 1) {
12989 if (mode === 'div') {
12990 return {
12991 div: this.divn(num.words[0]),
12992 mod: null
12993 };
12994 }
12995
12996 if (mode === 'mod') {
12997 return {
12998 div: null,
12999 mod: new BN(this.modn(num.words[0]))
13000 };
13001 }
13002
13003 return {
13004 div: this.divn(num.words[0]),
13005 mod: new BN(this.modn(num.words[0]))
13006 };
13007 }
13008
13009 return this._wordDiv(num, mode);
13010 };
13011
13012 // Find `this` / `num`
13013 BN.prototype.div = function div (num) {
13014 return this.divmod(num, 'div', false).div;
13015 };
13016
13017 // Find `this` % `num`
13018 BN.prototype.mod = function mod (num) {
13019 return this.divmod(num, 'mod', false).mod;
13020 };
13021
13022 BN.prototype.umod = function umod (num) {
13023 return this.divmod(num, 'mod', true).mod;
13024 };
13025
13026 // Find Round(`this` / `num`)
13027 BN.prototype.divRound = function divRound (num) {
13028 var dm = this.divmod(num);
13029
13030 // Fast case - exact division
13031 if (dm.mod.isZero()) return dm.div;
13032
13033 var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
13034
13035 var half = num.ushrn(1);
13036 var r2 = num.andln(1);
13037 var cmp = mod.cmp(half);
13038
13039 // Round down
13040 if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
13041
13042 // Round up
13043 return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
13044 };
13045
13046 BN.prototype.modn = function modn (num) {
13047 assert(num <= 0x3ffffff);
13048 var p = (1 << 26) % num;
13049
13050 var acc = 0;
13051 for (var i = this.length - 1; i >= 0; i--) {
13052 acc = (p * acc + (this.words[i] | 0)) % num;
13053 }
13054
13055 return acc;
13056 };
13057
13058 // In-place division by number
13059 BN.prototype.idivn = function idivn (num) {
13060 assert(num <= 0x3ffffff);
13061
13062 var carry = 0;
13063 for (var i = this.length - 1; i >= 0; i--) {
13064 var w = (this.words[i] | 0) + carry * 0x4000000;
13065 this.words[i] = (w / num) | 0;
13066 carry = w % num;
13067 }
13068
13069 return this.strip();
13070 };
13071
13072 BN.prototype.divn = function divn (num) {
13073 return this.clone().idivn(num);
13074 };
13075
13076 BN.prototype.egcd = function egcd (p) {
13077 assert(p.negative === 0);
13078 assert(!p.isZero());
13079
13080 var x = this;
13081 var y = p.clone();
13082
13083 if (x.negative !== 0) {
13084 x = x.umod(p);
13085 } else {
13086 x = x.clone();
13087 }
13088
13089 // A * x + B * y = x
13090 var A = new BN(1);
13091 var B = new BN(0);
13092
13093 // C * x + D * y = y
13094 var C = new BN(0);
13095 var D = new BN(1);
13096
13097 var g = 0;
13098
13099 while (x.isEven() && y.isEven()) {
13100 x.iushrn(1);
13101 y.iushrn(1);
13102 ++g;
13103 }
13104
13105 var yp = y.clone();
13106 var xp = x.clone();
13107
13108 while (!x.isZero()) {
13109 for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
13110 if (i > 0) {
13111 x.iushrn(i);
13112 while (i-- > 0) {
13113 if (A.isOdd() || B.isOdd()) {
13114 A.iadd(yp);
13115 B.isub(xp);
13116 }
13117
13118 A.iushrn(1);
13119 B.iushrn(1);
13120 }
13121 }
13122
13123 for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
13124 if (j > 0) {
13125 y.iushrn(j);
13126 while (j-- > 0) {
13127 if (C.isOdd() || D.isOdd()) {
13128 C.iadd(yp);
13129 D.isub(xp);
13130 }
13131
13132 C.iushrn(1);
13133 D.iushrn(1);
13134 }
13135 }
13136
13137 if (x.cmp(y) >= 0) {
13138 x.isub(y);
13139 A.isub(C);
13140 B.isub(D);
13141 } else {
13142 y.isub(x);
13143 C.isub(A);
13144 D.isub(B);
13145 }
13146 }
13147
13148 return {
13149 a: C,
13150 b: D,
13151 gcd: y.iushln(g)
13152 };
13153 };
13154
13155 // This is reduced incarnation of the binary EEA
13156 // above, designated to invert members of the
13157 // _prime_ fields F(p) at a maximal speed
13158 BN.prototype._invmp = function _invmp (p) {
13159 assert(p.negative === 0);
13160 assert(!p.isZero());
13161
13162 var a = this;
13163 var b = p.clone();
13164
13165 if (a.negative !== 0) {
13166 a = a.umod(p);
13167 } else {
13168 a = a.clone();
13169 }
13170
13171 var x1 = new BN(1);
13172 var x2 = new BN(0);
13173
13174 var delta = b.clone();
13175
13176 while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
13177 for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
13178 if (i > 0) {
13179 a.iushrn(i);
13180 while (i-- > 0) {
13181 if (x1.isOdd()) {
13182 x1.iadd(delta);
13183 }
13184
13185 x1.iushrn(1);
13186 }
13187 }
13188
13189 for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
13190 if (j > 0) {
13191 b.iushrn(j);
13192 while (j-- > 0) {
13193 if (x2.isOdd()) {
13194 x2.iadd(delta);
13195 }
13196
13197 x2.iushrn(1);
13198 }
13199 }
13200
13201 if (a.cmp(b) >= 0) {
13202 a.isub(b);
13203 x1.isub(x2);
13204 } else {
13205 b.isub(a);
13206 x2.isub(x1);
13207 }
13208 }
13209
13210 var res;
13211 if (a.cmpn(1) === 0) {
13212 res = x1;
13213 } else {
13214 res = x2;
13215 }
13216
13217 if (res.cmpn(0) < 0) {
13218 res.iadd(p);
13219 }
13220
13221 return res;
13222 };
13223
13224 BN.prototype.gcd = function gcd (num) {
13225 if (this.isZero()) return num.abs();
13226 if (num.isZero()) return this.abs();
13227
13228 var a = this.clone();
13229 var b = num.clone();
13230 a.negative = 0;
13231 b.negative = 0;
13232
13233 // Remove common factor of two
13234 for (var shift = 0; a.isEven() && b.isEven(); shift++) {
13235 a.iushrn(1);
13236 b.iushrn(1);
13237 }
13238
13239 do {
13240 while (a.isEven()) {
13241 a.iushrn(1);
13242 }
13243 while (b.isEven()) {
13244 b.iushrn(1);
13245 }
13246
13247 var r = a.cmp(b);
13248 if (r < 0) {
13249 // Swap `a` and `b` to make `a` always bigger than `b`
13250 var t = a;
13251 a = b;
13252 b = t;
13253 } else if (r === 0 || b.cmpn(1) === 0) {
13254 break;
13255 }
13256
13257 a.isub(b);
13258 } while (true);
13259
13260 return b.iushln(shift);
13261 };
13262
13263 // Invert number in the field F(num)
13264 BN.prototype.invm = function invm (num) {
13265 return this.egcd(num).a.umod(num);
13266 };
13267
13268 BN.prototype.isEven = function isEven () {
13269 return (this.words[0] & 1) === 0;
13270 };
13271
13272 BN.prototype.isOdd = function isOdd () {
13273 return (this.words[0] & 1) === 1;
13274 };
13275
13276 // And first word and num
13277 BN.prototype.andln = function andln (num) {
13278 return this.words[0] & num;
13279 };
13280
13281 // Increment at the bit position in-line
13282 BN.prototype.bincn = function bincn (bit) {
13283 assert(typeof bit === 'number');
13284 var r = bit % 26;
13285 var s = (bit - r) / 26;
13286 var q = 1 << r;
13287
13288 // Fast case: bit is much higher than all existing words
13289 if (this.length <= s) {
13290 this._expand(s + 1);
13291 this.words[s] |= q;
13292 return this;
13293 }
13294
13295 // Add bit and propagate, if needed
13296 var carry = q;
13297 for (var i = s; carry !== 0 && i < this.length; i++) {
13298 var w = this.words[i] | 0;
13299 w += carry;
13300 carry = w >>> 26;
13301 w &= 0x3ffffff;
13302 this.words[i] = w;
13303 }
13304 if (carry !== 0) {
13305 this.words[i] = carry;
13306 this.length++;
13307 }
13308 return this;
13309 };
13310
13311 BN.prototype.isZero = function isZero () {
13312 return this.length === 1 && this.words[0] === 0;
13313 };
13314
13315 BN.prototype.cmpn = function cmpn (num) {
13316 var negative = num < 0;
13317
13318 if (this.negative !== 0 && !negative) return -1;
13319 if (this.negative === 0 && negative) return 1;
13320
13321 this.strip();
13322
13323 var res;
13324 if (this.length > 1) {
13325 res = 1;
13326 } else {
13327 if (negative) {
13328 num = -num;
13329 }
13330
13331 assert(num <= 0x3ffffff, 'Number is too big');
13332
13333 var w = this.words[0] | 0;
13334 res = w === num ? 0 : w < num ? -1 : 1;
13335 }
13336 if (this.negative !== 0) return -res | 0;
13337 return res;
13338 };
13339
13340 // Compare two numbers and return:
13341 // 1 - if `this` > `num`
13342 // 0 - if `this` == `num`
13343 // -1 - if `this` < `num`
13344 BN.prototype.cmp = function cmp (num) {
13345 if (this.negative !== 0 && num.negative === 0) return -1;
13346 if (this.negative === 0 && num.negative !== 0) return 1;
13347
13348 var res = this.ucmp(num);
13349 if (this.negative !== 0) return -res | 0;
13350 return res;
13351 };
13352
13353 // Unsigned comparison
13354 BN.prototype.ucmp = function ucmp (num) {
13355 // At this point both numbers have the same sign
13356 if (this.length > num.length) return 1;
13357 if (this.length < num.length) return -1;
13358
13359 var res = 0;
13360 for (var i = this.length - 1; i >= 0; i--) {
13361 var a = this.words[i] | 0;
13362 var b = num.words[i] | 0;
13363
13364 if (a === b) continue;
13365 if (a < b) {
13366 res = -1;
13367 } else if (a > b) {
13368 res = 1;
13369 }
13370 break;
13371 }
13372 return res;
13373 };
13374
13375 BN.prototype.gtn = function gtn (num) {
13376 return this.cmpn(num) === 1;
13377 };
13378
13379 BN.prototype.gt = function gt (num) {
13380 return this.cmp(num) === 1;
13381 };
13382
13383 BN.prototype.gten = function gten (num) {
13384 return this.cmpn(num) >= 0;
13385 };
13386
13387 BN.prototype.gte = function gte (num) {
13388 return this.cmp(num) >= 0;
13389 };
13390
13391 BN.prototype.ltn = function ltn (num) {
13392 return this.cmpn(num) === -1;
13393 };
13394
13395 BN.prototype.lt = function lt (num) {
13396 return this.cmp(num) === -1;
13397 };
13398
13399 BN.prototype.lten = function lten (num) {
13400 return this.cmpn(num) <= 0;
13401 };
13402
13403 BN.prototype.lte = function lte (num) {
13404 return this.cmp(num) <= 0;
13405 };
13406
13407 BN.prototype.eqn = function eqn (num) {
13408 return this.cmpn(num) === 0;
13409 };
13410
13411 BN.prototype.eq = function eq (num) {
13412 return this.cmp(num) === 0;
13413 };
13414
13415 //
13416 // A reduce context, could be using montgomery or something better, depending
13417 // on the `m` itself.
13418 //
13419 BN.red = function red (num) {
13420 return new Red(num);
13421 };
13422
13423 BN.prototype.toRed = function toRed (ctx) {
13424 assert(!this.red, 'Already a number in reduction context');
13425 assert(this.negative === 0, 'red works only with positives');
13426 return ctx.convertTo(this)._forceRed(ctx);
13427 };
13428
13429 BN.prototype.fromRed = function fromRed () {
13430 assert(this.red, 'fromRed works only with numbers in reduction context');
13431 return this.red.convertFrom(this);
13432 };
13433
13434 BN.prototype._forceRed = function _forceRed (ctx) {
13435 this.red = ctx;
13436 return this;
13437 };
13438
13439 BN.prototype.forceRed = function forceRed (ctx) {
13440 assert(!this.red, 'Already a number in reduction context');
13441 return this._forceRed(ctx);
13442 };
13443
13444 BN.prototype.redAdd = function redAdd (num) {
13445 assert(this.red, 'redAdd works only with red numbers');
13446 return this.red.add(this, num);
13447 };
13448
13449 BN.prototype.redIAdd = function redIAdd (num) {
13450 assert(this.red, 'redIAdd works only with red numbers');
13451 return this.red.iadd(this, num);
13452 };
13453
13454 BN.prototype.redSub = function redSub (num) {
13455 assert(this.red, 'redSub works only with red numbers');
13456 return this.red.sub(this, num);
13457 };
13458
13459 BN.prototype.redISub = function redISub (num) {
13460 assert(this.red, 'redISub works only with red numbers');
13461 return this.red.isub(this, num);
13462 };
13463
13464 BN.prototype.redShl = function redShl (num) {
13465 assert(this.red, 'redShl works only with red numbers');
13466 return this.red.shl(this, num);
13467 };
13468
13469 BN.prototype.redMul = function redMul (num) {
13470 assert(this.red, 'redMul works only with red numbers');
13471 this.red._verify2(this, num);
13472 return this.red.mul(this, num);
13473 };
13474
13475 BN.prototype.redIMul = function redIMul (num) {
13476 assert(this.red, 'redMul works only with red numbers');
13477 this.red._verify2(this, num);
13478 return this.red.imul(this, num);
13479 };
13480
13481 BN.prototype.redSqr = function redSqr () {
13482 assert(this.red, 'redSqr works only with red numbers');
13483 this.red._verify1(this);
13484 return this.red.sqr(this);
13485 };
13486
13487 BN.prototype.redISqr = function redISqr () {
13488 assert(this.red, 'redISqr works only with red numbers');
13489 this.red._verify1(this);
13490 return this.red.isqr(this);
13491 };
13492
13493 // Square root over p
13494 BN.prototype.redSqrt = function redSqrt () {
13495 assert(this.red, 'redSqrt works only with red numbers');
13496 this.red._verify1(this);
13497 return this.red.sqrt(this);
13498 };
13499
13500 BN.prototype.redInvm = function redInvm () {
13501 assert(this.red, 'redInvm works only with red numbers');
13502 this.red._verify1(this);
13503 return this.red.invm(this);
13504 };
13505
13506 // Return negative clone of `this` % `red modulo`
13507 BN.prototype.redNeg = function redNeg () {
13508 assert(this.red, 'redNeg works only with red numbers');
13509 this.red._verify1(this);
13510 return this.red.neg(this);
13511 };
13512
13513 BN.prototype.redPow = function redPow (num) {
13514 assert(this.red && !num.red, 'redPow(normalNum)');
13515 this.red._verify1(this);
13516 return this.red.pow(this, num);
13517 };
13518
13519 // Prime numbers with efficient reduction
13520 var primes = {
13521 k256: null,
13522 p224: null,
13523 p192: null,
13524 p25519: null
13525 };
13526
13527 // Pseudo-Mersenne prime
13528 function MPrime (name, p) {
13529 // P = 2 ^ N - K
13530 this.name = name;
13531 this.p = new BN(p, 16);
13532 this.n = this.p.bitLength();
13533 this.k = new BN(1).iushln(this.n).isub(this.p);
13534
13535 this.tmp = this._tmp();
13536 }
13537
13538 MPrime.prototype._tmp = function _tmp () {
13539 var tmp = new BN(null);
13540 tmp.words = new Array(Math.ceil(this.n / 13));
13541 return tmp;
13542 };
13543
13544 MPrime.prototype.ireduce = function ireduce (num) {
13545 // Assumes that `num` is less than `P^2`
13546 // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
13547 var r = num;
13548 var rlen;
13549
13550 do {
13551 this.split(r, this.tmp);
13552 r = this.imulK(r);
13553 r = r.iadd(this.tmp);
13554 rlen = r.bitLength();
13555 } while (rlen > this.n);
13556
13557 var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
13558 if (cmp === 0) {
13559 r.words[0] = 0;
13560 r.length = 1;
13561 } else if (cmp > 0) {
13562 r.isub(this.p);
13563 } else {
13564 r.strip();
13565 }
13566
13567 return r;
13568 };
13569
13570 MPrime.prototype.split = function split (input, out) {
13571 input.iushrn(this.n, 0, out);
13572 };
13573
13574 MPrime.prototype.imulK = function imulK (num) {
13575 return num.imul(this.k);
13576 };
13577
13578 function K256 () {
13579 MPrime.call(
13580 this,
13581 'k256',
13582 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
13583 }
13584 inherits(K256, MPrime);
13585
13586 K256.prototype.split = function split (input, output) {
13587 // 256 = 9 * 26 + 22
13588 var mask = 0x3fffff;
13589
13590 var outLen = Math.min(input.length, 9);
13591 for (var i = 0; i < outLen; i++) {
13592 output.words[i] = input.words[i];
13593 }
13594 output.length = outLen;
13595
13596 if (input.length <= 9) {
13597 input.words[0] = 0;
13598 input.length = 1;
13599 return;
13600 }
13601
13602 // Shift by 9 limbs
13603 var prev = input.words[9];
13604 output.words[output.length++] = prev & mask;
13605
13606 for (i = 10; i < input.length; i++) {
13607 var next = input.words[i] | 0;
13608 input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
13609 prev = next;
13610 }
13611 prev >>>= 22;
13612 input.words[i - 10] = prev;
13613 if (prev === 0 && input.length > 10) {
13614 input.length -= 10;
13615 } else {
13616 input.length -= 9;
13617 }
13618 };
13619
13620 K256.prototype.imulK = function imulK (num) {
13621 // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
13622 num.words[num.length] = 0;
13623 num.words[num.length + 1] = 0;
13624 num.length += 2;
13625
13626 // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
13627 var lo = 0;
13628 for (var i = 0; i < num.length; i++) {
13629 var w = num.words[i] | 0;
13630 lo += w * 0x3d1;
13631 num.words[i] = lo & 0x3ffffff;
13632 lo = w * 0x40 + ((lo / 0x4000000) | 0);
13633 }
13634
13635 // Fast length reduction
13636 if (num.words[num.length - 1] === 0) {
13637 num.length--;
13638 if (num.words[num.length - 1] === 0) {
13639 num.length--;
13640 }
13641 }
13642 return num;
13643 };
13644
13645 function P224 () {
13646 MPrime.call(
13647 this,
13648 'p224',
13649 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
13650 }
13651 inherits(P224, MPrime);
13652
13653 function P192 () {
13654 MPrime.call(
13655 this,
13656 'p192',
13657 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
13658 }
13659 inherits(P192, MPrime);
13660
13661 function P25519 () {
13662 // 2 ^ 255 - 19
13663 MPrime.call(
13664 this,
13665 '25519',
13666 '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
13667 }
13668 inherits(P25519, MPrime);
13669
13670 P25519.prototype.imulK = function imulK (num) {
13671 // K = 0x13
13672 var carry = 0;
13673 for (var i = 0; i < num.length; i++) {
13674 var hi = (num.words[i] | 0) * 0x13 + carry;
13675 var lo = hi & 0x3ffffff;
13676 hi >>>= 26;
13677
13678 num.words[i] = lo;
13679 carry = hi;
13680 }
13681 if (carry !== 0) {
13682 num.words[num.length++] = carry;
13683 }
13684 return num;
13685 };
13686
13687 // Exported mostly for testing purposes, use plain name instead
13688 BN._prime = function prime (name) {
13689 // Cached version of prime
13690 if (primes[name]) return primes[name];
13691
13692 var prime;
13693 if (name === 'k256') {
13694 prime = new K256();
13695 } else if (name === 'p224') {
13696 prime = new P224();
13697 } else if (name === 'p192') {
13698 prime = new P192();
13699 } else if (name === 'p25519') {
13700 prime = new P25519();
13701 } else {
13702 throw new Error('Unknown prime ' + name);
13703 }
13704 primes[name] = prime;
13705
13706 return prime;
13707 };
13708
13709 //
13710 // Base reduction engine
13711 //
13712 function Red (m) {
13713 if (typeof m === 'string') {
13714 var prime = BN._prime(m);
13715 this.m = prime.p;
13716 this.prime = prime;
13717 } else {
13718 assert(m.gtn(1), 'modulus must be greater than 1');
13719 this.m = m;
13720 this.prime = null;
13721 }
13722 }
13723
13724 Red.prototype._verify1 = function _verify1 (a) {
13725 assert(a.negative === 0, 'red works only with positives');
13726 assert(a.red, 'red works only with red numbers');
13727 };
13728
13729 Red.prototype._verify2 = function _verify2 (a, b) {
13730 assert((a.negative | b.negative) === 0, 'red works only with positives');
13731 assert(a.red && a.red === b.red,
13732 'red works only with red numbers');
13733 };
13734
13735 Red.prototype.imod = function imod (a) {
13736 if (this.prime) return this.prime.ireduce(a)._forceRed(this);
13737 return a.umod(this.m)._forceRed(this);
13738 };
13739
13740 Red.prototype.neg = function neg (a) {
13741 if (a.isZero()) {
13742 return a.clone();
13743 }
13744
13745 return this.m.sub(a)._forceRed(this);
13746 };
13747
13748 Red.prototype.add = function add (a, b) {
13749 this._verify2(a, b);
13750
13751 var res = a.add(b);
13752 if (res.cmp(this.m) >= 0) {
13753 res.isub(this.m);
13754 }
13755 return res._forceRed(this);
13756 };
13757
13758 Red.prototype.iadd = function iadd (a, b) {
13759 this._verify2(a, b);
13760
13761 var res = a.iadd(b);
13762 if (res.cmp(this.m) >= 0) {
13763 res.isub(this.m);
13764 }
13765 return res;
13766 };
13767
13768 Red.prototype.sub = function sub (a, b) {
13769 this._verify2(a, b);
13770
13771 var res = a.sub(b);
13772 if (res.cmpn(0) < 0) {
13773 res.iadd(this.m);
13774 }
13775 return res._forceRed(this);
13776 };
13777
13778 Red.prototype.isub = function isub (a, b) {
13779 this._verify2(a, b);
13780
13781 var res = a.isub(b);
13782 if (res.cmpn(0) < 0) {
13783 res.iadd(this.m);
13784 }
13785 return res;
13786 };
13787
13788 Red.prototype.shl = function shl (a, num) {
13789 this._verify1(a);
13790 return this.imod(a.ushln(num));
13791 };
13792
13793 Red.prototype.imul = function imul (a, b) {
13794 this._verify2(a, b);
13795 return this.imod(a.imul(b));
13796 };
13797
13798 Red.prototype.mul = function mul (a, b) {
13799 this._verify2(a, b);
13800 return this.imod(a.mul(b));
13801 };
13802
13803 Red.prototype.isqr = function isqr (a) {
13804 return this.imul(a, a.clone());
13805 };
13806
13807 Red.prototype.sqr = function sqr (a) {
13808 return this.mul(a, a);
13809 };
13810
13811 Red.prototype.sqrt = function sqrt (a) {
13812 if (a.isZero()) return a.clone();
13813
13814 var mod3 = this.m.andln(3);
13815 assert(mod3 % 2 === 1);
13816
13817 // Fast case
13818 if (mod3 === 3) {
13819 var pow = this.m.add(new BN(1)).iushrn(2);
13820 return this.pow(a, pow);
13821 }
13822
13823 // Tonelli-Shanks algorithm (Totally unoptimized and slow)
13824 //
13825 // Find Q and S, that Q * 2 ^ S = (P - 1)
13826 var q = this.m.subn(1);
13827 var s = 0;
13828 while (!q.isZero() && q.andln(1) === 0) {
13829 s++;
13830 q.iushrn(1);
13831 }
13832 assert(!q.isZero());
13833
13834 var one = new BN(1).toRed(this);
13835 var nOne = one.redNeg();
13836
13837 // Find quadratic non-residue
13838 // NOTE: Max is such because of generalized Riemann hypothesis.
13839 var lpow = this.m.subn(1).iushrn(1);
13840 var z = this.m.bitLength();
13841 z = new BN(2 * z * z).toRed(this);
13842
13843 while (this.pow(z, lpow).cmp(nOne) !== 0) {
13844 z.redIAdd(nOne);
13845 }
13846
13847 var c = this.pow(z, q);
13848 var r = this.pow(a, q.addn(1).iushrn(1));
13849 var t = this.pow(a, q);
13850 var m = s;
13851 while (t.cmp(one) !== 0) {
13852 var tmp = t;
13853 for (var i = 0; tmp.cmp(one) !== 0; i++) {
13854 tmp = tmp.redSqr();
13855 }
13856 assert(i < m);
13857 var b = this.pow(c, new BN(1).iushln(m - i - 1));
13858
13859 r = r.redMul(b);
13860 c = b.redSqr();
13861 t = t.redMul(c);
13862 m = i;
13863 }
13864
13865 return r;
13866 };
13867
13868 Red.prototype.invm = function invm (a) {
13869 var inv = a._invmp(this.m);
13870 if (inv.negative !== 0) {
13871 inv.negative = 0;
13872 return this.imod(inv).redNeg();
13873 } else {
13874 return this.imod(inv);
13875 }
13876 };
13877
13878 Red.prototype.pow = function pow (a, num) {
13879 if (num.isZero()) return new BN(1).toRed(this);
13880 if (num.cmpn(1) === 0) return a.clone();
13881
13882 var windowSize = 4;
13883 var wnd = new Array(1 << windowSize);
13884 wnd[0] = new BN(1).toRed(this);
13885 wnd[1] = a;
13886 for (var i = 2; i < wnd.length; i++) {
13887 wnd[i] = this.mul(wnd[i - 1], a);
13888 }
13889
13890 var res = wnd[0];
13891 var current = 0;
13892 var currentLen = 0;
13893 var start = num.bitLength() % 26;
13894 if (start === 0) {
13895 start = 26;
13896 }
13897
13898 for (i = num.length - 1; i >= 0; i--) {
13899 var word = num.words[i];
13900 for (var j = start - 1; j >= 0; j--) {
13901 var bit = (word >> j) & 1;
13902 if (res !== wnd[0]) {
13903 res = this.sqr(res);
13904 }
13905
13906 if (bit === 0 && current === 0) {
13907 currentLen = 0;
13908 continue;
13909 }
13910
13911 current <<= 1;
13912 current |= bit;
13913 currentLen++;
13914 if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
13915
13916 res = this.mul(res, wnd[current]);
13917 currentLen = 0;
13918 current = 0;
13919 }
13920 start = 26;
13921 }
13922
13923 return res;
13924 };
13925
13926 Red.prototype.convertTo = function convertTo (num) {
13927 var r = num.umod(this.m);
13928
13929 return r === num ? r.clone() : r;
13930 };
13931
13932 Red.prototype.convertFrom = function convertFrom (num) {
13933 var res = num.clone();
13934 res.red = null;
13935 return res;
13936 };
13937
13938 //
13939 // Montgomery method engine
13940 //
13941
13942 BN.mont = function mont (num) {
13943 return new Mont(num);
13944 };
13945
13946 function Mont (m) {
13947 Red.call(this, m);
13948
13949 this.shift = this.m.bitLength();
13950 if (this.shift % 26 !== 0) {
13951 this.shift += 26 - (this.shift % 26);
13952 }
13953
13954 this.r = new BN(1).iushln(this.shift);
13955 this.r2 = this.imod(this.r.sqr());
13956 this.rinv = this.r._invmp(this.m);
13957
13958 this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
13959 this.minv = this.minv.umod(this.r);
13960 this.minv = this.r.sub(this.minv);
13961 }
13962 inherits(Mont, Red);
13963
13964 Mont.prototype.convertTo = function convertTo (num) {
13965 return this.imod(num.ushln(this.shift));
13966 };
13967
13968 Mont.prototype.convertFrom = function convertFrom (num) {
13969 var r = this.imod(num.mul(this.rinv));
13970 r.red = null;
13971 return r;
13972 };
13973
13974 Mont.prototype.imul = function imul (a, b) {
13975 if (a.isZero() || b.isZero()) {
13976 a.words[0] = 0;
13977 a.length = 1;
13978 return a;
13979 }
13980
13981 var t = a.imul(b);
13982 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
13983 var u = t.isub(c).iushrn(this.shift);
13984 var res = u;
13985
13986 if (u.cmp(this.m) >= 0) {
13987 res = u.isub(this.m);
13988 } else if (u.cmpn(0) < 0) {
13989 res = u.iadd(this.m);
13990 }
13991
13992 return res._forceRed(this);
13993 };
13994
13995 Mont.prototype.mul = function mul (a, b) {
13996 if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
13997
13998 var t = a.mul(b);
13999 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
14000 var u = t.isub(c).iushrn(this.shift);
14001 var res = u;
14002 if (u.cmp(this.m) >= 0) {
14003 res = u.isub(this.m);
14004 } else if (u.cmpn(0) < 0) {
14005 res = u.iadd(this.m);
14006 }
14007
14008 return res._forceRed(this);
14009 };
14010
14011 Mont.prototype.invm = function invm (a) {
14012 // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
14013 var res = this.imod(a._invmp(this.m).mul(this.r2));
14014 return res._forceRed(this);
14015 };
14016})(typeof module === 'undefined' || module, this);
14017
14018},{"buffer":81}],80:[function(require,module,exports){
14019var r;
14020
14021module.exports = function rand(len) {
14022 if (!r)
14023 r = new Rand(null);
14024
14025 return r.generate(len);
14026};
14027
14028function Rand(rand) {
14029 this.rand = rand;
14030}
14031module.exports.Rand = Rand;
14032
14033Rand.prototype.generate = function generate(len) {
14034 return this._rand(len);
14035};
14036
14037// Emulate crypto API using randy
14038Rand.prototype._rand = function _rand(n) {
14039 if (this.rand.getBytes)
14040 return this.rand.getBytes(n);
14041
14042 var res = new Uint8Array(n);
14043 for (var i = 0; i < res.length; i++)
14044 res[i] = this.rand.getByte();
14045 return res;
14046};
14047
14048if (typeof self === 'object') {
14049 if (self.crypto && self.crypto.getRandomValues) {
14050 // Modern browsers
14051 Rand.prototype._rand = function _rand(n) {
14052 var arr = new Uint8Array(n);
14053 self.crypto.getRandomValues(arr);
14054 return arr;
14055 };
14056 } else if (self.msCrypto && self.msCrypto.getRandomValues) {
14057 // IE
14058 Rand.prototype._rand = function _rand(n) {
14059 var arr = new Uint8Array(n);
14060 self.msCrypto.getRandomValues(arr);
14061 return arr;
14062 };
14063
14064 // Safari's WebWorkers do not have `crypto`
14065 } else if (typeof window === 'object') {
14066 // Old junk
14067 Rand.prototype._rand = function() {
14068 throw new Error('Not implemented yet');
14069 };
14070 }
14071} else {
14072 // Node.js or Web worker with no crypto support
14073 try {
14074 var crypto = require('crypto');
14075 if (typeof crypto.randomBytes !== 'function')
14076 throw new Error('Not supported');
14077
14078 Rand.prototype._rand = function _rand(n) {
14079 return crypto.randomBytes(n);
14080 };
14081 } catch (e) {
14082 }
14083}
14084
14085},{"crypto":81}],81:[function(require,module,exports){
14086
14087},{}],82:[function(require,module,exports){
14088arguments[4][7][0].apply(exports,arguments)
14089},{"dup":7,"safe-buffer":206}],83:[function(require,module,exports){
14090arguments[4][8][0].apply(exports,arguments)
14091},{"./aes":82,"./ghash":87,"./incr32":88,"buffer-xor":109,"cipher-base":111,"dup":8,"inherits":162,"safe-buffer":206}],84:[function(require,module,exports){
14092arguments[4][9][0].apply(exports,arguments)
14093},{"./decrypter":85,"./encrypter":86,"./modes/list.json":96,"dup":9}],85:[function(require,module,exports){
14094arguments[4][10][0].apply(exports,arguments)
14095},{"./aes":82,"./authCipher":83,"./modes":95,"./streamCipher":98,"cipher-base":111,"dup":10,"evp_bytestokey":146,"inherits":162,"safe-buffer":206}],86:[function(require,module,exports){
14096arguments[4][11][0].apply(exports,arguments)
14097},{"./aes":82,"./authCipher":83,"./modes":95,"./streamCipher":98,"cipher-base":111,"dup":11,"evp_bytestokey":146,"inherits":162,"safe-buffer":206}],87:[function(require,module,exports){
14098arguments[4][12][0].apply(exports,arguments)
14099},{"dup":12,"safe-buffer":206}],88:[function(require,module,exports){
14100arguments[4][13][0].apply(exports,arguments)
14101},{"dup":13}],89:[function(require,module,exports){
14102arguments[4][14][0].apply(exports,arguments)
14103},{"buffer-xor":109,"dup":14}],90:[function(require,module,exports){
14104arguments[4][15][0].apply(exports,arguments)
14105},{"buffer-xor":109,"dup":15,"safe-buffer":206}],91:[function(require,module,exports){
14106arguments[4][16][0].apply(exports,arguments)
14107},{"dup":16,"safe-buffer":206}],92:[function(require,module,exports){
14108arguments[4][17][0].apply(exports,arguments)
14109},{"dup":17,"safe-buffer":206}],93:[function(require,module,exports){
14110arguments[4][18][0].apply(exports,arguments)
14111},{"../incr32":88,"buffer-xor":109,"dup":18,"safe-buffer":206}],94:[function(require,module,exports){
14112arguments[4][19][0].apply(exports,arguments)
14113},{"dup":19}],95:[function(require,module,exports){
14114arguments[4][20][0].apply(exports,arguments)
14115},{"./cbc":89,"./cfb":90,"./cfb1":91,"./cfb8":92,"./ctr":93,"./ecb":94,"./list.json":96,"./ofb":97,"dup":20}],96:[function(require,module,exports){
14116arguments[4][21][0].apply(exports,arguments)
14117},{"dup":21}],97:[function(require,module,exports){
14118arguments[4][22][0].apply(exports,arguments)
14119},{"buffer":110,"buffer-xor":109,"dup":22}],98:[function(require,module,exports){
14120arguments[4][23][0].apply(exports,arguments)
14121},{"./aes":82,"cipher-base":111,"dup":23,"inherits":162,"safe-buffer":206}],99:[function(require,module,exports){
14122var DES = require('browserify-des')
14123var aes = require('browserify-aes/browser')
14124var aesModes = require('browserify-aes/modes')
14125var desModes = require('browserify-des/modes')
14126var ebtk = require('evp_bytestokey')
14127
14128function createCipher (suite, password) {
14129 suite = suite.toLowerCase()
14130
14131 var keyLen, ivLen
14132 if (aesModes[suite]) {
14133 keyLen = aesModes[suite].key
14134 ivLen = aesModes[suite].iv
14135 } else if (desModes[suite]) {
14136 keyLen = desModes[suite].key * 8
14137 ivLen = desModes[suite].iv
14138 } else {
14139 throw new TypeError('invalid suite type')
14140 }
14141
14142 var keys = ebtk(password, false, keyLen, ivLen)
14143 return createCipheriv(suite, keys.key, keys.iv)
14144}
14145
14146function createDecipher (suite, password) {
14147 suite = suite.toLowerCase()
14148
14149 var keyLen, ivLen
14150 if (aesModes[suite]) {
14151 keyLen = aesModes[suite].key
14152 ivLen = aesModes[suite].iv
14153 } else if (desModes[suite]) {
14154 keyLen = desModes[suite].key * 8
14155 ivLen = desModes[suite].iv
14156 } else {
14157 throw new TypeError('invalid suite type')
14158 }
14159
14160 var keys = ebtk(password, false, keyLen, ivLen)
14161 return createDecipheriv(suite, keys.key, keys.iv)
14162}
14163
14164function createCipheriv (suite, key, iv) {
14165 suite = suite.toLowerCase()
14166 if (aesModes[suite]) return aes.createCipheriv(suite, key, iv)
14167 if (desModes[suite]) return new DES({ key: key, iv: iv, mode: suite })
14168
14169 throw new TypeError('invalid suite type')
14170}
14171
14172function createDecipheriv (suite, key, iv) {
14173 suite = suite.toLowerCase()
14174 if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv)
14175 if (desModes[suite]) return new DES({ key: key, iv: iv, mode: suite, decrypt: true })
14176
14177 throw new TypeError('invalid suite type')
14178}
14179
14180function getCiphers () {
14181 return Object.keys(desModes).concat(aes.getCiphers())
14182}
14183
14184exports.createCipher = exports.Cipher = createCipher
14185exports.createCipheriv = exports.Cipheriv = createCipheriv
14186exports.createDecipher = exports.Decipher = createDecipher
14187exports.createDecipheriv = exports.Decipheriv = createDecipheriv
14188exports.listCiphers = exports.getCiphers = getCiphers
14189
14190},{"browserify-aes/browser":84,"browserify-aes/modes":95,"browserify-des":100,"browserify-des/modes":101,"evp_bytestokey":146}],100:[function(require,module,exports){
14191var CipherBase = require('cipher-base')
14192var des = require('des.js')
14193var inherits = require('inherits')
14194var Buffer = require('safe-buffer').Buffer
14195
14196var modes = {
14197 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
14198 'des-ede3': des.EDE,
14199 'des-ede-cbc': des.CBC.instantiate(des.EDE),
14200 'des-ede': des.EDE,
14201 'des-cbc': des.CBC.instantiate(des.DES),
14202 'des-ecb': des.DES
14203}
14204modes.des = modes['des-cbc']
14205modes.des3 = modes['des-ede3-cbc']
14206module.exports = DES
14207inherits(DES, CipherBase)
14208function DES (opts) {
14209 CipherBase.call(this)
14210 var modeName = opts.mode.toLowerCase()
14211 var mode = modes[modeName]
14212 var type
14213 if (opts.decrypt) {
14214 type = 'decrypt'
14215 } else {
14216 type = 'encrypt'
14217 }
14218 var key = opts.key
14219 if (!Buffer.isBuffer(key)) {
14220 key = Buffer.from(key)
14221 }
14222 if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
14223 key = Buffer.concat([key, key.slice(0, 8)])
14224 }
14225 var iv = opts.iv
14226 if (!Buffer.isBuffer(iv)) {
14227 iv = Buffer.from(iv)
14228 }
14229 this._des = mode.create({
14230 key: key,
14231 iv: iv,
14232 type: type
14233 })
14234}
14235DES.prototype._update = function (data) {
14236 return Buffer.from(this._des.update(data))
14237}
14238DES.prototype._final = function () {
14239 return Buffer.from(this._des.final())
14240}
14241
14242},{"cipher-base":111,"des.js":119,"inherits":162,"safe-buffer":206}],101:[function(require,module,exports){
14243exports['des-ecb'] = {
14244 key: 8,
14245 iv: 0
14246}
14247exports['des-cbc'] = exports.des = {
14248 key: 8,
14249 iv: 8
14250}
14251exports['des-ede3-cbc'] = exports.des3 = {
14252 key: 24,
14253 iv: 8
14254}
14255exports['des-ede3'] = {
14256 key: 24,
14257 iv: 0
14258}
14259exports['des-ede-cbc'] = {
14260 key: 16,
14261 iv: 8
14262}
14263exports['des-ede'] = {
14264 key: 16,
14265 iv: 0
14266}
14267
14268},{}],102:[function(require,module,exports){
14269(function (Buffer){
14270var bn = require('bn.js');
14271var randomBytes = require('randombytes');
14272module.exports = crt;
14273function blind(priv) {
14274 var r = getr(priv);
14275 var blinder = r.toRed(bn.mont(priv.modulus))
14276 .redPow(new bn(priv.publicExponent)).fromRed();
14277 return {
14278 blinder: blinder,
14279 unblinder:r.invm(priv.modulus)
14280 };
14281}
14282function crt(msg, priv) {
14283 var blinds = blind(priv);
14284 var len = priv.modulus.byteLength();
14285 var mod = bn.mont(priv.modulus);
14286 var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
14287 var c1 = blinded.toRed(bn.mont(priv.prime1));
14288 var c2 = blinded.toRed(bn.mont(priv.prime2));
14289 var qinv = priv.coefficient;
14290 var p = priv.prime1;
14291 var q = priv.prime2;
14292 var m1 = c1.redPow(priv.exponent1);
14293 var m2 = c2.redPow(priv.exponent2);
14294 m1 = m1.fromRed();
14295 m2 = m2.fromRed();
14296 var h = m1.isub(m2).imul(qinv).umod(p);
14297 h.imul(q);
14298 m2.iadd(h);
14299 return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
14300}
14301crt.getr = getr;
14302function getr(priv) {
14303 var len = priv.modulus.byteLength();
14304 var r = new bn(randomBytes(len));
14305 while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
14306 r = new bn(randomBytes(len));
14307 }
14308 return r;
14309}
14310
14311}).call(this,require("buffer").Buffer)
14312},{"bn.js":79,"buffer":110,"randombytes":188}],103:[function(require,module,exports){
14313module.exports = require('./browser/algorithms.json')
14314
14315},{"./browser/algorithms.json":104}],104:[function(require,module,exports){
14316module.exports={
14317 "sha224WithRSAEncryption": {
14318 "sign": "rsa",
14319 "hash": "sha224",
14320 "id": "302d300d06096086480165030402040500041c"
14321 },
14322 "RSA-SHA224": {
14323 "sign": "ecdsa/rsa",
14324 "hash": "sha224",
14325 "id": "302d300d06096086480165030402040500041c"
14326 },
14327 "sha256WithRSAEncryption": {
14328 "sign": "rsa",
14329 "hash": "sha256",
14330 "id": "3031300d060960864801650304020105000420"
14331 },
14332 "RSA-SHA256": {
14333 "sign": "ecdsa/rsa",
14334 "hash": "sha256",
14335 "id": "3031300d060960864801650304020105000420"
14336 },
14337 "sha384WithRSAEncryption": {
14338 "sign": "rsa",
14339 "hash": "sha384",
14340 "id": "3041300d060960864801650304020205000430"
14341 },
14342 "RSA-SHA384": {
14343 "sign": "ecdsa/rsa",
14344 "hash": "sha384",
14345 "id": "3041300d060960864801650304020205000430"
14346 },
14347 "sha512WithRSAEncryption": {
14348 "sign": "rsa",
14349 "hash": "sha512",
14350 "id": "3051300d060960864801650304020305000440"
14351 },
14352 "RSA-SHA512": {
14353 "sign": "ecdsa/rsa",
14354 "hash": "sha512",
14355 "id": "3051300d060960864801650304020305000440"
14356 },
14357 "RSA-SHA1": {
14358 "sign": "rsa",
14359 "hash": "sha1",
14360 "id": "3021300906052b0e03021a05000414"
14361 },
14362 "ecdsa-with-SHA1": {
14363 "sign": "ecdsa",
14364 "hash": "sha1",
14365 "id": ""
14366 },
14367 "sha256": {
14368 "sign": "ecdsa",
14369 "hash": "sha256",
14370 "id": ""
14371 },
14372 "sha224": {
14373 "sign": "ecdsa",
14374 "hash": "sha224",
14375 "id": ""
14376 },
14377 "sha384": {
14378 "sign": "ecdsa",
14379 "hash": "sha384",
14380 "id": ""
14381 },
14382 "sha512": {
14383 "sign": "ecdsa",
14384 "hash": "sha512",
14385 "id": ""
14386 },
14387 "DSA-SHA": {
14388 "sign": "dsa",
14389 "hash": "sha1",
14390 "id": ""
14391 },
14392 "DSA-SHA1": {
14393 "sign": "dsa",
14394 "hash": "sha1",
14395 "id": ""
14396 },
14397 "DSA": {
14398 "sign": "dsa",
14399 "hash": "sha1",
14400 "id": ""
14401 },
14402 "DSA-WITH-SHA224": {
14403 "sign": "dsa",
14404 "hash": "sha224",
14405 "id": ""
14406 },
14407 "DSA-SHA224": {
14408 "sign": "dsa",
14409 "hash": "sha224",
14410 "id": ""
14411 },
14412 "DSA-WITH-SHA256": {
14413 "sign": "dsa",
14414 "hash": "sha256",
14415 "id": ""
14416 },
14417 "DSA-SHA256": {
14418 "sign": "dsa",
14419 "hash": "sha256",
14420 "id": ""
14421 },
14422 "DSA-WITH-SHA384": {
14423 "sign": "dsa",
14424 "hash": "sha384",
14425 "id": ""
14426 },
14427 "DSA-SHA384": {
14428 "sign": "dsa",
14429 "hash": "sha384",
14430 "id": ""
14431 },
14432 "DSA-WITH-SHA512": {
14433 "sign": "dsa",
14434 "hash": "sha512",
14435 "id": ""
14436 },
14437 "DSA-SHA512": {
14438 "sign": "dsa",
14439 "hash": "sha512",
14440 "id": ""
14441 },
14442 "DSA-RIPEMD160": {
14443 "sign": "dsa",
14444 "hash": "rmd160",
14445 "id": ""
14446 },
14447 "ripemd160WithRSA": {
14448 "sign": "rsa",
14449 "hash": "rmd160",
14450 "id": "3021300906052b2403020105000414"
14451 },
14452 "RSA-RIPEMD160": {
14453 "sign": "rsa",
14454 "hash": "rmd160",
14455 "id": "3021300906052b2403020105000414"
14456 },
14457 "md5WithRSAEncryption": {
14458 "sign": "rsa",
14459 "hash": "md5",
14460 "id": "3020300c06082a864886f70d020505000410"
14461 },
14462 "RSA-MD5": {
14463 "sign": "rsa",
14464 "hash": "md5",
14465 "id": "3020300c06082a864886f70d020505000410"
14466 }
14467}
14468
14469},{}],105:[function(require,module,exports){
14470module.exports={
14471 "1.3.132.0.10": "secp256k1",
14472 "1.3.132.0.33": "p224",
14473 "1.2.840.10045.3.1.1": "p192",
14474 "1.2.840.10045.3.1.7": "p256",
14475 "1.3.132.0.34": "p384",
14476 "1.3.132.0.35": "p521"
14477}
14478
14479},{}],106:[function(require,module,exports){
14480(function (Buffer){
14481var createHash = require('create-hash')
14482var stream = require('stream')
14483var inherits = require('inherits')
14484var sign = require('./sign')
14485var verify = require('./verify')
14486
14487var algorithms = require('./algorithms.json')
14488Object.keys(algorithms).forEach(function (key) {
14489 algorithms[key].id = new Buffer(algorithms[key].id, 'hex')
14490 algorithms[key.toLowerCase()] = algorithms[key]
14491})
14492
14493function Sign (algorithm) {
14494 stream.Writable.call(this)
14495
14496 var data = algorithms[algorithm]
14497 if (!data) throw new Error('Unknown message digest')
14498
14499 this._hashType = data.hash
14500 this._hash = createHash(data.hash)
14501 this._tag = data.id
14502 this._signType = data.sign
14503}
14504inherits(Sign, stream.Writable)
14505
14506Sign.prototype._write = function _write (data, _, done) {
14507 this._hash.update(data)
14508 done()
14509}
14510
14511Sign.prototype.update = function update (data, enc) {
14512 if (typeof data === 'string') data = new Buffer(data, enc)
14513
14514 this._hash.update(data)
14515 return this
14516}
14517
14518Sign.prototype.sign = function signMethod (key, enc) {
14519 this.end()
14520 var hash = this._hash.digest()
14521 var sig = sign(hash, key, this._hashType, this._signType, this._tag)
14522
14523 return enc ? sig.toString(enc) : sig
14524}
14525
14526function Verify (algorithm) {
14527 stream.Writable.call(this)
14528
14529 var data = algorithms[algorithm]
14530 if (!data) throw new Error('Unknown message digest')
14531
14532 this._hash = createHash(data.hash)
14533 this._tag = data.id
14534 this._signType = data.sign
14535}
14536inherits(Verify, stream.Writable)
14537
14538Verify.prototype._write = function _write (data, _, done) {
14539 this._hash.update(data)
14540 done()
14541}
14542
14543Verify.prototype.update = function update (data, enc) {
14544 if (typeof data === 'string') data = new Buffer(data, enc)
14545
14546 this._hash.update(data)
14547 return this
14548}
14549
14550Verify.prototype.verify = function verifyMethod (key, sig, enc) {
14551 if (typeof sig === 'string') sig = new Buffer(sig, enc)
14552
14553 this.end()
14554 var hash = this._hash.digest()
14555 return verify(sig, hash, key, this._signType, this._tag)
14556}
14557
14558function createSign (algorithm) {
14559 return new Sign(algorithm)
14560}
14561
14562function createVerify (algorithm) {
14563 return new Verify(algorithm)
14564}
14565
14566module.exports = {
14567 Sign: createSign,
14568 Verify: createVerify,
14569 createSign: createSign,
14570 createVerify: createVerify
14571}
14572
14573}).call(this,require("buffer").Buffer)
14574},{"./algorithms.json":104,"./sign":107,"./verify":108,"buffer":110,"create-hash":114,"inherits":162,"stream":215}],107:[function(require,module,exports){
14575(function (Buffer){
14576// much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
14577var createHmac = require('create-hmac')
14578var crt = require('browserify-rsa')
14579var EC = require('elliptic').ec
14580var BN = require('bn.js')
14581var parseKeys = require('parse-asn1')
14582var curves = require('./curves.json')
14583
14584function sign (hash, key, hashType, signType, tag) {
14585 var priv = parseKeys(key)
14586 if (priv.curve) {
14587 // rsa keys can be interpreted as ecdsa ones in openssl
14588 if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type')
14589 return ecSign(hash, priv)
14590 } else if (priv.type === 'dsa') {
14591 if (signType !== 'dsa') throw new Error('wrong private key type')
14592 return dsaSign(hash, priv, hashType)
14593 } else {
14594 if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type')
14595 }
14596 hash = Buffer.concat([tag, hash])
14597 var len = priv.modulus.byteLength()
14598 var pad = [ 0, 1 ]
14599 while (hash.length + pad.length + 1 < len) pad.push(0xff)
14600 pad.push(0x00)
14601 var i = -1
14602 while (++i < hash.length) pad.push(hash[i])
14603
14604 var out = crt(pad, priv)
14605 return out
14606}
14607
14608function ecSign (hash, priv) {
14609 var curveId = curves[priv.curve.join('.')]
14610 if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'))
14611
14612 var curve = new EC(curveId)
14613 var key = curve.keyFromPrivate(priv.privateKey)
14614 var out = key.sign(hash)
14615
14616 return new Buffer(out.toDER())
14617}
14618
14619function dsaSign (hash, priv, algo) {
14620 var x = priv.params.priv_key
14621 var p = priv.params.p
14622 var q = priv.params.q
14623 var g = priv.params.g
14624 var r = new BN(0)
14625 var k
14626 var H = bits2int(hash, q).mod(q)
14627 var s = false
14628 var kv = getKey(x, q, hash, algo)
14629 while (s === false) {
14630 k = makeKey(q, kv, algo)
14631 r = makeR(g, k, p, q)
14632 s = k.invm(q).imul(H.add(x.mul(r))).mod(q)
14633 if (s.cmpn(0) === 0) {
14634 s = false
14635 r = new BN(0)
14636 }
14637 }
14638 return toDER(r, s)
14639}
14640
14641function toDER (r, s) {
14642 r = r.toArray()
14643 s = s.toArray()
14644
14645 // Pad values
14646 if (r[0] & 0x80) r = [ 0 ].concat(r)
14647 if (s[0] & 0x80) s = [ 0 ].concat(s)
14648
14649 var total = r.length + s.length + 4
14650 var res = [ 0x30, total, 0x02, r.length ]
14651 res = res.concat(r, [ 0x02, s.length ], s)
14652 return new Buffer(res)
14653}
14654
14655function getKey (x, q, hash, algo) {
14656 x = new Buffer(x.toArray())
14657 if (x.length < q.byteLength()) {
14658 var zeros = new Buffer(q.byteLength() - x.length)
14659 zeros.fill(0)
14660 x = Buffer.concat([ zeros, x ])
14661 }
14662 var hlen = hash.length
14663 var hbits = bits2octets(hash, q)
14664 var v = new Buffer(hlen)
14665 v.fill(1)
14666 var k = new Buffer(hlen)
14667 k.fill(0)
14668 k = createHmac(algo, k).update(v).update(new Buffer([ 0 ])).update(x).update(hbits).digest()
14669 v = createHmac(algo, k).update(v).digest()
14670 k = createHmac(algo, k).update(v).update(new Buffer([ 1 ])).update(x).update(hbits).digest()
14671 v = createHmac(algo, k).update(v).digest()
14672 return { k: k, v: v }
14673}
14674
14675function bits2int (obits, q) {
14676 var bits = new BN(obits)
14677 var shift = (obits.length << 3) - q.bitLength()
14678 if (shift > 0) bits.ishrn(shift)
14679 return bits
14680}
14681
14682function bits2octets (bits, q) {
14683 bits = bits2int(bits, q)
14684 bits = bits.mod(q)
14685 var out = new Buffer(bits.toArray())
14686 if (out.length < q.byteLength()) {
14687 var zeros = new Buffer(q.byteLength() - out.length)
14688 zeros.fill(0)
14689 out = Buffer.concat([ zeros, out ])
14690 }
14691 return out
14692}
14693
14694function makeKey (q, kv, algo) {
14695 var t
14696 var k
14697
14698 do {
14699 t = new Buffer(0)
14700
14701 while (t.length * 8 < q.bitLength()) {
14702 kv.v = createHmac(algo, kv.k).update(kv.v).digest()
14703 t = Buffer.concat([ t, kv.v ])
14704 }
14705
14706 k = bits2int(t, q)
14707 kv.k = createHmac(algo, kv.k).update(kv.v).update(new Buffer([ 0 ])).digest()
14708 kv.v = createHmac(algo, kv.k).update(kv.v).digest()
14709 } while (k.cmp(q) !== -1)
14710
14711 return k
14712}
14713
14714function makeR (g, k, p, q) {
14715 return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q)
14716}
14717
14718module.exports = sign
14719module.exports.getKey = getKey
14720module.exports.makeKey = makeKey
14721
14722}).call(this,require("buffer").Buffer)
14723},{"./curves.json":105,"bn.js":79,"browserify-rsa":102,"buffer":110,"create-hmac":116,"elliptic":129,"parse-asn1":174}],108:[function(require,module,exports){
14724(function (Buffer){
14725// much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
14726var BN = require('bn.js')
14727var EC = require('elliptic').ec
14728var parseKeys = require('parse-asn1')
14729var curves = require('./curves.json')
14730
14731function verify (sig, hash, key, signType, tag) {
14732 var pub = parseKeys(key)
14733 if (pub.type === 'ec') {
14734 // rsa keys can be interpreted as ecdsa ones in openssl
14735 if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type')
14736 return ecVerify(sig, hash, pub)
14737 } else if (pub.type === 'dsa') {
14738 if (signType !== 'dsa') throw new Error('wrong public key type')
14739 return dsaVerify(sig, hash, pub)
14740 } else {
14741 if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type')
14742 }
14743 hash = Buffer.concat([tag, hash])
14744 var len = pub.modulus.byteLength()
14745 var pad = [ 1 ]
14746 var padNum = 0
14747 while (hash.length + pad.length + 2 < len) {
14748 pad.push(0xff)
14749 padNum++
14750 }
14751 pad.push(0x00)
14752 var i = -1
14753 while (++i < hash.length) {
14754 pad.push(hash[i])
14755 }
14756 pad = new Buffer(pad)
14757 var red = BN.mont(pub.modulus)
14758 sig = new BN(sig).toRed(red)
14759
14760 sig = sig.redPow(new BN(pub.publicExponent))
14761 sig = new Buffer(sig.fromRed().toArray())
14762 var out = padNum < 8 ? 1 : 0
14763 len = Math.min(sig.length, pad.length)
14764 if (sig.length !== pad.length) out = 1
14765
14766 i = -1
14767 while (++i < len) out |= sig[i] ^ pad[i]
14768 return out === 0
14769}
14770
14771function ecVerify (sig, hash, pub) {
14772 var curveId = curves[pub.data.algorithm.curve.join('.')]
14773 if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'))
14774
14775 var curve = new EC(curveId)
14776 var pubkey = pub.data.subjectPrivateKey.data
14777
14778 return curve.verify(hash, sig, pubkey)
14779}
14780
14781function dsaVerify (sig, hash, pub) {
14782 var p = pub.data.p
14783 var q = pub.data.q
14784 var g = pub.data.g
14785 var y = pub.data.pub_key
14786 var unpacked = parseKeys.signature.decode(sig, 'der')
14787 var s = unpacked.s
14788 var r = unpacked.r
14789 checkValue(s, q)
14790 checkValue(r, q)
14791 var montp = BN.mont(p)
14792 var w = s.invm(q)
14793 var v = g.toRed(montp)
14794 .redPow(new BN(hash).mul(w).mod(q))
14795 .fromRed()
14796 .mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed())
14797 .mod(p)
14798 .mod(q)
14799 return v.cmp(r) === 0
14800}
14801
14802function checkValue (b, q) {
14803 if (b.cmpn(0) <= 0) throw new Error('invalid sig')
14804 if (b.cmp(q) >= q) throw new Error('invalid sig')
14805}
14806
14807module.exports = verify
14808
14809}).call(this,require("buffer").Buffer)
14810},{"./curves.json":105,"bn.js":79,"buffer":110,"elliptic":129,"parse-asn1":174}],109:[function(require,module,exports){
14811arguments[4][29][0].apply(exports,arguments)
14812},{"buffer":110,"dup":29}],110:[function(require,module,exports){
14813(function (Buffer){
14814/*!
14815 * The buffer module from node.js, for the browser.
14816 *
14817 * @author Feross Aboukhadijeh <https://feross.org>
14818 * @license MIT
14819 */
14820/* eslint-disable no-proto */
14821
14822'use strict'
14823
14824var base64 = require('base64-js')
14825var ieee754 = require('ieee754')
14826var customInspectSymbol =
14827 (typeof Symbol === 'function' && typeof Symbol.for === 'function')
14828 ? Symbol.for('nodejs.util.inspect.custom')
14829 : null
14830
14831exports.Buffer = Buffer
14832exports.SlowBuffer = SlowBuffer
14833exports.INSPECT_MAX_BYTES = 50
14834
14835var K_MAX_LENGTH = 0x7fffffff
14836exports.kMaxLength = K_MAX_LENGTH
14837
14838/**
14839 * If `Buffer.TYPED_ARRAY_SUPPORT`:
14840 * === true Use Uint8Array implementation (fastest)
14841 * === false Print warning and recommend using `buffer` v4.x which has an Object
14842 * implementation (most compatible, even IE6)
14843 *
14844 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
14845 * Opera 11.6+, iOS 4.2+.
14846 *
14847 * We report that the browser does not support typed arrays if the are not subclassable
14848 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
14849 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
14850 * for __proto__ and has a buggy typed array implementation.
14851 */
14852Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
14853
14854if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
14855 typeof console.error === 'function') {
14856 console.error(
14857 'This browser lacks typed array (Uint8Array) support which is required by ' +
14858 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
14859 )
14860}
14861
14862function typedArraySupport () {
14863 // Can typed array instances can be augmented?
14864 try {
14865 var arr = new Uint8Array(1)
14866 var proto = { foo: function () { return 42 } }
14867 Object.setPrototypeOf(proto, Uint8Array.prototype)
14868 Object.setPrototypeOf(arr, proto)
14869 return arr.foo() === 42
14870 } catch (e) {
14871 return false
14872 }
14873}
14874
14875Object.defineProperty(Buffer.prototype, 'parent', {
14876 enumerable: true,
14877 get: function () {
14878 if (!Buffer.isBuffer(this)) return undefined
14879 return this.buffer
14880 }
14881})
14882
14883Object.defineProperty(Buffer.prototype, 'offset', {
14884 enumerable: true,
14885 get: function () {
14886 if (!Buffer.isBuffer(this)) return undefined
14887 return this.byteOffset
14888 }
14889})
14890
14891function createBuffer (length) {
14892 if (length > K_MAX_LENGTH) {
14893 throw new RangeError('The value "' + length + '" is invalid for option "size"')
14894 }
14895 // Return an augmented `Uint8Array` instance
14896 var buf = new Uint8Array(length)
14897 Object.setPrototypeOf(buf, Buffer.prototype)
14898 return buf
14899}
14900
14901/**
14902 * The Buffer constructor returns instances of `Uint8Array` that have their
14903 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
14904 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
14905 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
14906 * returns a single octet.
14907 *
14908 * The `Uint8Array` prototype remains unmodified.
14909 */
14910
14911function Buffer (arg, encodingOrOffset, length) {
14912 // Common case.
14913 if (typeof arg === 'number') {
14914 if (typeof encodingOrOffset === 'string') {
14915 throw new TypeError(
14916 'The "string" argument must be of type string. Received type number'
14917 )
14918 }
14919 return allocUnsafe(arg)
14920 }
14921 return from(arg, encodingOrOffset, length)
14922}
14923
14924// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
14925if (typeof Symbol !== 'undefined' && Symbol.species != null &&
14926 Buffer[Symbol.species] === Buffer) {
14927 Object.defineProperty(Buffer, Symbol.species, {
14928 value: null,
14929 configurable: true,
14930 enumerable: false,
14931 writable: false
14932 })
14933}
14934
14935Buffer.poolSize = 8192 // not used by this implementation
14936
14937function from (value, encodingOrOffset, length) {
14938 if (typeof value === 'string') {
14939 return fromString(value, encodingOrOffset)
14940 }
14941
14942 if (ArrayBuffer.isView(value)) {
14943 return fromArrayLike(value)
14944 }
14945
14946 if (value == null) {
14947 throw new TypeError(
14948 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
14949 'or Array-like Object. Received type ' + (typeof value)
14950 )
14951 }
14952
14953 if (isInstance(value, ArrayBuffer) ||
14954 (value && isInstance(value.buffer, ArrayBuffer))) {
14955 return fromArrayBuffer(value, encodingOrOffset, length)
14956 }
14957
14958 if (typeof value === 'number') {
14959 throw new TypeError(
14960 'The "value" argument must not be of type number. Received type number'
14961 )
14962 }
14963
14964 var valueOf = value.valueOf && value.valueOf()
14965 if (valueOf != null && valueOf !== value) {
14966 return Buffer.from(valueOf, encodingOrOffset, length)
14967 }
14968
14969 var b = fromObject(value)
14970 if (b) return b
14971
14972 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
14973 typeof value[Symbol.toPrimitive] === 'function') {
14974 return Buffer.from(
14975 value[Symbol.toPrimitive]('string'), encodingOrOffset, length
14976 )
14977 }
14978
14979 throw new TypeError(
14980 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
14981 'or Array-like Object. Received type ' + (typeof value)
14982 )
14983}
14984
14985/**
14986 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
14987 * if value is a number.
14988 * Buffer.from(str[, encoding])
14989 * Buffer.from(array)
14990 * Buffer.from(buffer)
14991 * Buffer.from(arrayBuffer[, byteOffset[, length]])
14992 **/
14993Buffer.from = function (value, encodingOrOffset, length) {
14994 return from(value, encodingOrOffset, length)
14995}
14996
14997// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
14998// https://github.com/feross/buffer/pull/148
14999Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
15000Object.setPrototypeOf(Buffer, Uint8Array)
15001
15002function assertSize (size) {
15003 if (typeof size !== 'number') {
15004 throw new TypeError('"size" argument must be of type number')
15005 } else if (size < 0) {
15006 throw new RangeError('The value "' + size + '" is invalid for option "size"')
15007 }
15008}
15009
15010function alloc (size, fill, encoding) {
15011 assertSize(size)
15012 if (size <= 0) {
15013 return createBuffer(size)
15014 }
15015 if (fill !== undefined) {
15016 // Only pay attention to encoding if it's a string. This
15017 // prevents accidentally sending in a number that would
15018 // be interpretted as a start offset.
15019 return typeof encoding === 'string'
15020 ? createBuffer(size).fill(fill, encoding)
15021 : createBuffer(size).fill(fill)
15022 }
15023 return createBuffer(size)
15024}
15025
15026/**
15027 * Creates a new filled Buffer instance.
15028 * alloc(size[, fill[, encoding]])
15029 **/
15030Buffer.alloc = function (size, fill, encoding) {
15031 return alloc(size, fill, encoding)
15032}
15033
15034function allocUnsafe (size) {
15035 assertSize(size)
15036 return createBuffer(size < 0 ? 0 : checked(size) | 0)
15037}
15038
15039/**
15040 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
15041 * */
15042Buffer.allocUnsafe = function (size) {
15043 return allocUnsafe(size)
15044}
15045/**
15046 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
15047 */
15048Buffer.allocUnsafeSlow = function (size) {
15049 return allocUnsafe(size)
15050}
15051
15052function fromString (string, encoding) {
15053 if (typeof encoding !== 'string' || encoding === '') {
15054 encoding = 'utf8'
15055 }
15056
15057 if (!Buffer.isEncoding(encoding)) {
15058 throw new TypeError('Unknown encoding: ' + encoding)
15059 }
15060
15061 var length = byteLength(string, encoding) | 0
15062 var buf = createBuffer(length)
15063
15064 var actual = buf.write(string, encoding)
15065
15066 if (actual !== length) {
15067 // Writing a hex string, for example, that contains invalid characters will
15068 // cause everything after the first invalid character to be ignored. (e.g.
15069 // 'abxxcd' will be treated as 'ab')
15070 buf = buf.slice(0, actual)
15071 }
15072
15073 return buf
15074}
15075
15076function fromArrayLike (array) {
15077 var length = array.length < 0 ? 0 : checked(array.length) | 0
15078 var buf = createBuffer(length)
15079 for (var i = 0; i < length; i += 1) {
15080 buf[i] = array[i] & 255
15081 }
15082 return buf
15083}
15084
15085function fromArrayBuffer (array, byteOffset, length) {
15086 if (byteOffset < 0 || array.byteLength < byteOffset) {
15087 throw new RangeError('"offset" is outside of buffer bounds')
15088 }
15089
15090 if (array.byteLength < byteOffset + (length || 0)) {
15091 throw new RangeError('"length" is outside of buffer bounds')
15092 }
15093
15094 var buf
15095 if (byteOffset === undefined && length === undefined) {
15096 buf = new Uint8Array(array)
15097 } else if (length === undefined) {
15098 buf = new Uint8Array(array, byteOffset)
15099 } else {
15100 buf = new Uint8Array(array, byteOffset, length)
15101 }
15102
15103 // Return an augmented `Uint8Array` instance
15104 Object.setPrototypeOf(buf, Buffer.prototype)
15105
15106 return buf
15107}
15108
15109function fromObject (obj) {
15110 if (Buffer.isBuffer(obj)) {
15111 var len = checked(obj.length) | 0
15112 var buf = createBuffer(len)
15113
15114 if (buf.length === 0) {
15115 return buf
15116 }
15117
15118 obj.copy(buf, 0, 0, len)
15119 return buf
15120 }
15121
15122 if (obj.length !== undefined) {
15123 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
15124 return createBuffer(0)
15125 }
15126 return fromArrayLike(obj)
15127 }
15128
15129 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
15130 return fromArrayLike(obj.data)
15131 }
15132}
15133
15134function checked (length) {
15135 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
15136 // length is NaN (which is otherwise coerced to zero.)
15137 if (length >= K_MAX_LENGTH) {
15138 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
15139 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
15140 }
15141 return length | 0
15142}
15143
15144function SlowBuffer (length) {
15145 if (+length != length) { // eslint-disable-line eqeqeq
15146 length = 0
15147 }
15148 return Buffer.alloc(+length)
15149}
15150
15151Buffer.isBuffer = function isBuffer (b) {
15152 return b != null && b._isBuffer === true &&
15153 b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
15154}
15155
15156Buffer.compare = function compare (a, b) {
15157 if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
15158 if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
15159 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
15160 throw new TypeError(
15161 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
15162 )
15163 }
15164
15165 if (a === b) return 0
15166
15167 var x = a.length
15168 var y = b.length
15169
15170 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
15171 if (a[i] !== b[i]) {
15172 x = a[i]
15173 y = b[i]
15174 break
15175 }
15176 }
15177
15178 if (x < y) return -1
15179 if (y < x) return 1
15180 return 0
15181}
15182
15183Buffer.isEncoding = function isEncoding (encoding) {
15184 switch (String(encoding).toLowerCase()) {
15185 case 'hex':
15186 case 'utf8':
15187 case 'utf-8':
15188 case 'ascii':
15189 case 'latin1':
15190 case 'binary':
15191 case 'base64':
15192 case 'ucs2':
15193 case 'ucs-2':
15194 case 'utf16le':
15195 case 'utf-16le':
15196 return true
15197 default:
15198 return false
15199 }
15200}
15201
15202Buffer.concat = function concat (list, length) {
15203 if (!Array.isArray(list)) {
15204 throw new TypeError('"list" argument must be an Array of Buffers')
15205 }
15206
15207 if (list.length === 0) {
15208 return Buffer.alloc(0)
15209 }
15210
15211 var i
15212 if (length === undefined) {
15213 length = 0
15214 for (i = 0; i < list.length; ++i) {
15215 length += list[i].length
15216 }
15217 }
15218
15219 var buffer = Buffer.allocUnsafe(length)
15220 var pos = 0
15221 for (i = 0; i < list.length; ++i) {
15222 var buf = list[i]
15223 if (isInstance(buf, Uint8Array)) {
15224 buf = Buffer.from(buf)
15225 }
15226 if (!Buffer.isBuffer(buf)) {
15227 throw new TypeError('"list" argument must be an Array of Buffers')
15228 }
15229 buf.copy(buffer, pos)
15230 pos += buf.length
15231 }
15232 return buffer
15233}
15234
15235function byteLength (string, encoding) {
15236 if (Buffer.isBuffer(string)) {
15237 return string.length
15238 }
15239 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
15240 return string.byteLength
15241 }
15242 if (typeof string !== 'string') {
15243 throw new TypeError(
15244 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
15245 'Received type ' + typeof string
15246 )
15247 }
15248
15249 var len = string.length
15250 var mustMatch = (arguments.length > 2 && arguments[2] === true)
15251 if (!mustMatch && len === 0) return 0
15252
15253 // Use a for loop to avoid recursion
15254 var loweredCase = false
15255 for (;;) {
15256 switch (encoding) {
15257 case 'ascii':
15258 case 'latin1':
15259 case 'binary':
15260 return len
15261 case 'utf8':
15262 case 'utf-8':
15263 return utf8ToBytes(string).length
15264 case 'ucs2':
15265 case 'ucs-2':
15266 case 'utf16le':
15267 case 'utf-16le':
15268 return len * 2
15269 case 'hex':
15270 return len >>> 1
15271 case 'base64':
15272 return base64ToBytes(string).length
15273 default:
15274 if (loweredCase) {
15275 return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
15276 }
15277 encoding = ('' + encoding).toLowerCase()
15278 loweredCase = true
15279 }
15280 }
15281}
15282Buffer.byteLength = byteLength
15283
15284function slowToString (encoding, start, end) {
15285 var loweredCase = false
15286
15287 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
15288 // property of a typed array.
15289
15290 // This behaves neither like String nor Uint8Array in that we set start/end
15291 // to their upper/lower bounds if the value passed is out of range.
15292 // undefined is handled specially as per ECMA-262 6th Edition,
15293 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
15294 if (start === undefined || start < 0) {
15295 start = 0
15296 }
15297 // Return early if start > this.length. Done here to prevent potential uint32
15298 // coercion fail below.
15299 if (start > this.length) {
15300 return ''
15301 }
15302
15303 if (end === undefined || end > this.length) {
15304 end = this.length
15305 }
15306
15307 if (end <= 0) {
15308 return ''
15309 }
15310
15311 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
15312 end >>>= 0
15313 start >>>= 0
15314
15315 if (end <= start) {
15316 return ''
15317 }
15318
15319 if (!encoding) encoding = 'utf8'
15320
15321 while (true) {
15322 switch (encoding) {
15323 case 'hex':
15324 return hexSlice(this, start, end)
15325
15326 case 'utf8':
15327 case 'utf-8':
15328 return utf8Slice(this, start, end)
15329
15330 case 'ascii':
15331 return asciiSlice(this, start, end)
15332
15333 case 'latin1':
15334 case 'binary':
15335 return latin1Slice(this, start, end)
15336
15337 case 'base64':
15338 return base64Slice(this, start, end)
15339
15340 case 'ucs2':
15341 case 'ucs-2':
15342 case 'utf16le':
15343 case 'utf-16le':
15344 return utf16leSlice(this, start, end)
15345
15346 default:
15347 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
15348 encoding = (encoding + '').toLowerCase()
15349 loweredCase = true
15350 }
15351 }
15352}
15353
15354// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
15355// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
15356// reliably in a browserify context because there could be multiple different
15357// copies of the 'buffer' package in use. This method works even for Buffer
15358// instances that were created from another copy of the `buffer` package.
15359// See: https://github.com/feross/buffer/issues/154
15360Buffer.prototype._isBuffer = true
15361
15362function swap (b, n, m) {
15363 var i = b[n]
15364 b[n] = b[m]
15365 b[m] = i
15366}
15367
15368Buffer.prototype.swap16 = function swap16 () {
15369 var len = this.length
15370 if (len % 2 !== 0) {
15371 throw new RangeError('Buffer size must be a multiple of 16-bits')
15372 }
15373 for (var i = 0; i < len; i += 2) {
15374 swap(this, i, i + 1)
15375 }
15376 return this
15377}
15378
15379Buffer.prototype.swap32 = function swap32 () {
15380 var len = this.length
15381 if (len % 4 !== 0) {
15382 throw new RangeError('Buffer size must be a multiple of 32-bits')
15383 }
15384 for (var i = 0; i < len; i += 4) {
15385 swap(this, i, i + 3)
15386 swap(this, i + 1, i + 2)
15387 }
15388 return this
15389}
15390
15391Buffer.prototype.swap64 = function swap64 () {
15392 var len = this.length
15393 if (len % 8 !== 0) {
15394 throw new RangeError('Buffer size must be a multiple of 64-bits')
15395 }
15396 for (var i = 0; i < len; i += 8) {
15397 swap(this, i, i + 7)
15398 swap(this, i + 1, i + 6)
15399 swap(this, i + 2, i + 5)
15400 swap(this, i + 3, i + 4)
15401 }
15402 return this
15403}
15404
15405Buffer.prototype.toString = function toString () {
15406 var length = this.length
15407 if (length === 0) return ''
15408 if (arguments.length === 0) return utf8Slice(this, 0, length)
15409 return slowToString.apply(this, arguments)
15410}
15411
15412Buffer.prototype.toLocaleString = Buffer.prototype.toString
15413
15414Buffer.prototype.equals = function equals (b) {
15415 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
15416 if (this === b) return true
15417 return Buffer.compare(this, b) === 0
15418}
15419
15420Buffer.prototype.inspect = function inspect () {
15421 var str = ''
15422 var max = exports.INSPECT_MAX_BYTES
15423 str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
15424 if (this.length > max) str += ' ... '
15425 return '<Buffer ' + str + '>'
15426}
15427if (customInspectSymbol) {
15428 Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
15429}
15430
15431Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
15432 if (isInstance(target, Uint8Array)) {
15433 target = Buffer.from(target, target.offset, target.byteLength)
15434 }
15435 if (!Buffer.isBuffer(target)) {
15436 throw new TypeError(
15437 'The "target" argument must be one of type Buffer or Uint8Array. ' +
15438 'Received type ' + (typeof target)
15439 )
15440 }
15441
15442 if (start === undefined) {
15443 start = 0
15444 }
15445 if (end === undefined) {
15446 end = target ? target.length : 0
15447 }
15448 if (thisStart === undefined) {
15449 thisStart = 0
15450 }
15451 if (thisEnd === undefined) {
15452 thisEnd = this.length
15453 }
15454
15455 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
15456 throw new RangeError('out of range index')
15457 }
15458
15459 if (thisStart >= thisEnd && start >= end) {
15460 return 0
15461 }
15462 if (thisStart >= thisEnd) {
15463 return -1
15464 }
15465 if (start >= end) {
15466 return 1
15467 }
15468
15469 start >>>= 0
15470 end >>>= 0
15471 thisStart >>>= 0
15472 thisEnd >>>= 0
15473
15474 if (this === target) return 0
15475
15476 var x = thisEnd - thisStart
15477 var y = end - start
15478 var len = Math.min(x, y)
15479
15480 var thisCopy = this.slice(thisStart, thisEnd)
15481 var targetCopy = target.slice(start, end)
15482
15483 for (var i = 0; i < len; ++i) {
15484 if (thisCopy[i] !== targetCopy[i]) {
15485 x = thisCopy[i]
15486 y = targetCopy[i]
15487 break
15488 }
15489 }
15490
15491 if (x < y) return -1
15492 if (y < x) return 1
15493 return 0
15494}
15495
15496// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
15497// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
15498//
15499// Arguments:
15500// - buffer - a Buffer to search
15501// - val - a string, Buffer, or number
15502// - byteOffset - an index into `buffer`; will be clamped to an int32
15503// - encoding - an optional encoding, relevant is val is a string
15504// - dir - true for indexOf, false for lastIndexOf
15505function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
15506 // Empty buffer means no match
15507 if (buffer.length === 0) return -1
15508
15509 // Normalize byteOffset
15510 if (typeof byteOffset === 'string') {
15511 encoding = byteOffset
15512 byteOffset = 0
15513 } else if (byteOffset > 0x7fffffff) {
15514 byteOffset = 0x7fffffff
15515 } else if (byteOffset < -0x80000000) {
15516 byteOffset = -0x80000000
15517 }
15518 byteOffset = +byteOffset // Coerce to Number.
15519 if (numberIsNaN(byteOffset)) {
15520 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
15521 byteOffset = dir ? 0 : (buffer.length - 1)
15522 }
15523
15524 // Normalize byteOffset: negative offsets start from the end of the buffer
15525 if (byteOffset < 0) byteOffset = buffer.length + byteOffset
15526 if (byteOffset >= buffer.length) {
15527 if (dir) return -1
15528 else byteOffset = buffer.length - 1
15529 } else if (byteOffset < 0) {
15530 if (dir) byteOffset = 0
15531 else return -1
15532 }
15533
15534 // Normalize val
15535 if (typeof val === 'string') {
15536 val = Buffer.from(val, encoding)
15537 }
15538
15539 // Finally, search either indexOf (if dir is true) or lastIndexOf
15540 if (Buffer.isBuffer(val)) {
15541 // Special case: looking for empty string/buffer always fails
15542 if (val.length === 0) {
15543 return -1
15544 }
15545 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
15546 } else if (typeof val === 'number') {
15547 val = val & 0xFF // Search for a byte value [0-255]
15548 if (typeof Uint8Array.prototype.indexOf === 'function') {
15549 if (dir) {
15550 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
15551 } else {
15552 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
15553 }
15554 }
15555 return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
15556 }
15557
15558 throw new TypeError('val must be string, number or Buffer')
15559}
15560
15561function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
15562 var indexSize = 1
15563 var arrLength = arr.length
15564 var valLength = val.length
15565
15566 if (encoding !== undefined) {
15567 encoding = String(encoding).toLowerCase()
15568 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
15569 encoding === 'utf16le' || encoding === 'utf-16le') {
15570 if (arr.length < 2 || val.length < 2) {
15571 return -1
15572 }
15573 indexSize = 2
15574 arrLength /= 2
15575 valLength /= 2
15576 byteOffset /= 2
15577 }
15578 }
15579
15580 function read (buf, i) {
15581 if (indexSize === 1) {
15582 return buf[i]
15583 } else {
15584 return buf.readUInt16BE(i * indexSize)
15585 }
15586 }
15587
15588 var i
15589 if (dir) {
15590 var foundIndex = -1
15591 for (i = byteOffset; i < arrLength; i++) {
15592 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
15593 if (foundIndex === -1) foundIndex = i
15594 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
15595 } else {
15596 if (foundIndex !== -1) i -= i - foundIndex
15597 foundIndex = -1
15598 }
15599 }
15600 } else {
15601 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
15602 for (i = byteOffset; i >= 0; i--) {
15603 var found = true
15604 for (var j = 0; j < valLength; j++) {
15605 if (read(arr, i + j) !== read(val, j)) {
15606 found = false
15607 break
15608 }
15609 }
15610 if (found) return i
15611 }
15612 }
15613
15614 return -1
15615}
15616
15617Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
15618 return this.indexOf(val, byteOffset, encoding) !== -1
15619}
15620
15621Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
15622 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
15623}
15624
15625Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
15626 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
15627}
15628
15629function hexWrite (buf, string, offset, length) {
15630 offset = Number(offset) || 0
15631 var remaining = buf.length - offset
15632 if (!length) {
15633 length = remaining
15634 } else {
15635 length = Number(length)
15636 if (length > remaining) {
15637 length = remaining
15638 }
15639 }
15640
15641 var strLen = string.length
15642
15643 if (length > strLen / 2) {
15644 length = strLen / 2
15645 }
15646 for (var i = 0; i < length; ++i) {
15647 var parsed = parseInt(string.substr(i * 2, 2), 16)
15648 if (numberIsNaN(parsed)) return i
15649 buf[offset + i] = parsed
15650 }
15651 return i
15652}
15653
15654function utf8Write (buf, string, offset, length) {
15655 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
15656}
15657
15658function asciiWrite (buf, string, offset, length) {
15659 return blitBuffer(asciiToBytes(string), buf, offset, length)
15660}
15661
15662function latin1Write (buf, string, offset, length) {
15663 return asciiWrite(buf, string, offset, length)
15664}
15665
15666function base64Write (buf, string, offset, length) {
15667 return blitBuffer(base64ToBytes(string), buf, offset, length)
15668}
15669
15670function ucs2Write (buf, string, offset, length) {
15671 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
15672}
15673
15674Buffer.prototype.write = function write (string, offset, length, encoding) {
15675 // Buffer#write(string)
15676 if (offset === undefined) {
15677 encoding = 'utf8'
15678 length = this.length
15679 offset = 0
15680 // Buffer#write(string, encoding)
15681 } else if (length === undefined && typeof offset === 'string') {
15682 encoding = offset
15683 length = this.length
15684 offset = 0
15685 // Buffer#write(string, offset[, length][, encoding])
15686 } else if (isFinite(offset)) {
15687 offset = offset >>> 0
15688 if (isFinite(length)) {
15689 length = length >>> 0
15690 if (encoding === undefined) encoding = 'utf8'
15691 } else {
15692 encoding = length
15693 length = undefined
15694 }
15695 } else {
15696 throw new Error(
15697 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
15698 )
15699 }
15700
15701 var remaining = this.length - offset
15702 if (length === undefined || length > remaining) length = remaining
15703
15704 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
15705 throw new RangeError('Attempt to write outside buffer bounds')
15706 }
15707
15708 if (!encoding) encoding = 'utf8'
15709
15710 var loweredCase = false
15711 for (;;) {
15712 switch (encoding) {
15713 case 'hex':
15714 return hexWrite(this, string, offset, length)
15715
15716 case 'utf8':
15717 case 'utf-8':
15718 return utf8Write(this, string, offset, length)
15719
15720 case 'ascii':
15721 return asciiWrite(this, string, offset, length)
15722
15723 case 'latin1':
15724 case 'binary':
15725 return latin1Write(this, string, offset, length)
15726
15727 case 'base64':
15728 // Warning: maxLength not taken into account in base64Write
15729 return base64Write(this, string, offset, length)
15730
15731 case 'ucs2':
15732 case 'ucs-2':
15733 case 'utf16le':
15734 case 'utf-16le':
15735 return ucs2Write(this, string, offset, length)
15736
15737 default:
15738 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
15739 encoding = ('' + encoding).toLowerCase()
15740 loweredCase = true
15741 }
15742 }
15743}
15744
15745Buffer.prototype.toJSON = function toJSON () {
15746 return {
15747 type: 'Buffer',
15748 data: Array.prototype.slice.call(this._arr || this, 0)
15749 }
15750}
15751
15752function base64Slice (buf, start, end) {
15753 if (start === 0 && end === buf.length) {
15754 return base64.fromByteArray(buf)
15755 } else {
15756 return base64.fromByteArray(buf.slice(start, end))
15757 }
15758}
15759
15760function utf8Slice (buf, start, end) {
15761 end = Math.min(buf.length, end)
15762 var res = []
15763
15764 var i = start
15765 while (i < end) {
15766 var firstByte = buf[i]
15767 var codePoint = null
15768 var bytesPerSequence = (firstByte > 0xEF) ? 4
15769 : (firstByte > 0xDF) ? 3
15770 : (firstByte > 0xBF) ? 2
15771 : 1
15772
15773 if (i + bytesPerSequence <= end) {
15774 var secondByte, thirdByte, fourthByte, tempCodePoint
15775
15776 switch (bytesPerSequence) {
15777 case 1:
15778 if (firstByte < 0x80) {
15779 codePoint = firstByte
15780 }
15781 break
15782 case 2:
15783 secondByte = buf[i + 1]
15784 if ((secondByte & 0xC0) === 0x80) {
15785 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
15786 if (tempCodePoint > 0x7F) {
15787 codePoint = tempCodePoint
15788 }
15789 }
15790 break
15791 case 3:
15792 secondByte = buf[i + 1]
15793 thirdByte = buf[i + 2]
15794 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
15795 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
15796 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
15797 codePoint = tempCodePoint
15798 }
15799 }
15800 break
15801 case 4:
15802 secondByte = buf[i + 1]
15803 thirdByte = buf[i + 2]
15804 fourthByte = buf[i + 3]
15805 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
15806 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
15807 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
15808 codePoint = tempCodePoint
15809 }
15810 }
15811 }
15812 }
15813
15814 if (codePoint === null) {
15815 // we did not generate a valid codePoint so insert a
15816 // replacement char (U+FFFD) and advance only 1 byte
15817 codePoint = 0xFFFD
15818 bytesPerSequence = 1
15819 } else if (codePoint > 0xFFFF) {
15820 // encode to utf16 (surrogate pair dance)
15821 codePoint -= 0x10000
15822 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
15823 codePoint = 0xDC00 | codePoint & 0x3FF
15824 }
15825
15826 res.push(codePoint)
15827 i += bytesPerSequence
15828 }
15829
15830 return decodeCodePointsArray(res)
15831}
15832
15833// Based on http://stackoverflow.com/a/22747272/680742, the browser with
15834// the lowest limit is Chrome, with 0x10000 args.
15835// We go 1 magnitude less, for safety
15836var MAX_ARGUMENTS_LENGTH = 0x1000
15837
15838function decodeCodePointsArray (codePoints) {
15839 var len = codePoints.length
15840 if (len <= MAX_ARGUMENTS_LENGTH) {
15841 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
15842 }
15843
15844 // Decode in chunks to avoid "call stack size exceeded".
15845 var res = ''
15846 var i = 0
15847 while (i < len) {
15848 res += String.fromCharCode.apply(
15849 String,
15850 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
15851 )
15852 }
15853 return res
15854}
15855
15856function asciiSlice (buf, start, end) {
15857 var ret = ''
15858 end = Math.min(buf.length, end)
15859
15860 for (var i = start; i < end; ++i) {
15861 ret += String.fromCharCode(buf[i] & 0x7F)
15862 }
15863 return ret
15864}
15865
15866function latin1Slice (buf, start, end) {
15867 var ret = ''
15868 end = Math.min(buf.length, end)
15869
15870 for (var i = start; i < end; ++i) {
15871 ret += String.fromCharCode(buf[i])
15872 }
15873 return ret
15874}
15875
15876function hexSlice (buf, start, end) {
15877 var len = buf.length
15878
15879 if (!start || start < 0) start = 0
15880 if (!end || end < 0 || end > len) end = len
15881
15882 var out = ''
15883 for (var i = start; i < end; ++i) {
15884 out += toHex(buf[i])
15885 }
15886 return out
15887}
15888
15889function utf16leSlice (buf, start, end) {
15890 var bytes = buf.slice(start, end)
15891 var res = ''
15892 for (var i = 0; i < bytes.length; i += 2) {
15893 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
15894 }
15895 return res
15896}
15897
15898Buffer.prototype.slice = function slice (start, end) {
15899 var len = this.length
15900 start = ~~start
15901 end = end === undefined ? len : ~~end
15902
15903 if (start < 0) {
15904 start += len
15905 if (start < 0) start = 0
15906 } else if (start > len) {
15907 start = len
15908 }
15909
15910 if (end < 0) {
15911 end += len
15912 if (end < 0) end = 0
15913 } else if (end > len) {
15914 end = len
15915 }
15916
15917 if (end < start) end = start
15918
15919 var newBuf = this.subarray(start, end)
15920 // Return an augmented `Uint8Array` instance
15921 Object.setPrototypeOf(newBuf, Buffer.prototype)
15922
15923 return newBuf
15924}
15925
15926/*
15927 * Need to make sure that buffer isn't trying to write out of bounds.
15928 */
15929function checkOffset (offset, ext, length) {
15930 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
15931 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
15932}
15933
15934Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
15935 offset = offset >>> 0
15936 byteLength = byteLength >>> 0
15937 if (!noAssert) checkOffset(offset, byteLength, this.length)
15938
15939 var val = this[offset]
15940 var mul = 1
15941 var i = 0
15942 while (++i < byteLength && (mul *= 0x100)) {
15943 val += this[offset + i] * mul
15944 }
15945
15946 return val
15947}
15948
15949Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
15950 offset = offset >>> 0
15951 byteLength = byteLength >>> 0
15952 if (!noAssert) {
15953 checkOffset(offset, byteLength, this.length)
15954 }
15955
15956 var val = this[offset + --byteLength]
15957 var mul = 1
15958 while (byteLength > 0 && (mul *= 0x100)) {
15959 val += this[offset + --byteLength] * mul
15960 }
15961
15962 return val
15963}
15964
15965Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
15966 offset = offset >>> 0
15967 if (!noAssert) checkOffset(offset, 1, this.length)
15968 return this[offset]
15969}
15970
15971Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
15972 offset = offset >>> 0
15973 if (!noAssert) checkOffset(offset, 2, this.length)
15974 return this[offset] | (this[offset + 1] << 8)
15975}
15976
15977Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
15978 offset = offset >>> 0
15979 if (!noAssert) checkOffset(offset, 2, this.length)
15980 return (this[offset] << 8) | this[offset + 1]
15981}
15982
15983Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
15984 offset = offset >>> 0
15985 if (!noAssert) checkOffset(offset, 4, this.length)
15986
15987 return ((this[offset]) |
15988 (this[offset + 1] << 8) |
15989 (this[offset + 2] << 16)) +
15990 (this[offset + 3] * 0x1000000)
15991}
15992
15993Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
15994 offset = offset >>> 0
15995 if (!noAssert) checkOffset(offset, 4, this.length)
15996
15997 return (this[offset] * 0x1000000) +
15998 ((this[offset + 1] << 16) |
15999 (this[offset + 2] << 8) |
16000 this[offset + 3])
16001}
16002
16003Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
16004 offset = offset >>> 0
16005 byteLength = byteLength >>> 0
16006 if (!noAssert) checkOffset(offset, byteLength, this.length)
16007
16008 var val = this[offset]
16009 var mul = 1
16010 var i = 0
16011 while (++i < byteLength && (mul *= 0x100)) {
16012 val += this[offset + i] * mul
16013 }
16014 mul *= 0x80
16015
16016 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
16017
16018 return val
16019}
16020
16021Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
16022 offset = offset >>> 0
16023 byteLength = byteLength >>> 0
16024 if (!noAssert) checkOffset(offset, byteLength, this.length)
16025
16026 var i = byteLength
16027 var mul = 1
16028 var val = this[offset + --i]
16029 while (i > 0 && (mul *= 0x100)) {
16030 val += this[offset + --i] * mul
16031 }
16032 mul *= 0x80
16033
16034 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
16035
16036 return val
16037}
16038
16039Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
16040 offset = offset >>> 0
16041 if (!noAssert) checkOffset(offset, 1, this.length)
16042 if (!(this[offset] & 0x80)) return (this[offset])
16043 return ((0xff - this[offset] + 1) * -1)
16044}
16045
16046Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
16047 offset = offset >>> 0
16048 if (!noAssert) checkOffset(offset, 2, this.length)
16049 var val = this[offset] | (this[offset + 1] << 8)
16050 return (val & 0x8000) ? val | 0xFFFF0000 : val
16051}
16052
16053Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
16054 offset = offset >>> 0
16055 if (!noAssert) checkOffset(offset, 2, this.length)
16056 var val = this[offset + 1] | (this[offset] << 8)
16057 return (val & 0x8000) ? val | 0xFFFF0000 : val
16058}
16059
16060Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
16061 offset = offset >>> 0
16062 if (!noAssert) checkOffset(offset, 4, this.length)
16063
16064 return (this[offset]) |
16065 (this[offset + 1] << 8) |
16066 (this[offset + 2] << 16) |
16067 (this[offset + 3] << 24)
16068}
16069
16070Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
16071 offset = offset >>> 0
16072 if (!noAssert) checkOffset(offset, 4, this.length)
16073
16074 return (this[offset] << 24) |
16075 (this[offset + 1] << 16) |
16076 (this[offset + 2] << 8) |
16077 (this[offset + 3])
16078}
16079
16080Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
16081 offset = offset >>> 0
16082 if (!noAssert) checkOffset(offset, 4, this.length)
16083 return ieee754.read(this, offset, true, 23, 4)
16084}
16085
16086Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
16087 offset = offset >>> 0
16088 if (!noAssert) checkOffset(offset, 4, this.length)
16089 return ieee754.read(this, offset, false, 23, 4)
16090}
16091
16092Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
16093 offset = offset >>> 0
16094 if (!noAssert) checkOffset(offset, 8, this.length)
16095 return ieee754.read(this, offset, true, 52, 8)
16096}
16097
16098Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
16099 offset = offset >>> 0
16100 if (!noAssert) checkOffset(offset, 8, this.length)
16101 return ieee754.read(this, offset, false, 52, 8)
16102}
16103
16104function checkInt (buf, value, offset, ext, max, min) {
16105 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
16106 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
16107 if (offset + ext > buf.length) throw new RangeError('Index out of range')
16108}
16109
16110Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
16111 value = +value
16112 offset = offset >>> 0
16113 byteLength = byteLength >>> 0
16114 if (!noAssert) {
16115 var maxBytes = Math.pow(2, 8 * byteLength) - 1
16116 checkInt(this, value, offset, byteLength, maxBytes, 0)
16117 }
16118
16119 var mul = 1
16120 var i = 0
16121 this[offset] = value & 0xFF
16122 while (++i < byteLength && (mul *= 0x100)) {
16123 this[offset + i] = (value / mul) & 0xFF
16124 }
16125
16126 return offset + byteLength
16127}
16128
16129Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
16130 value = +value
16131 offset = offset >>> 0
16132 byteLength = byteLength >>> 0
16133 if (!noAssert) {
16134 var maxBytes = Math.pow(2, 8 * byteLength) - 1
16135 checkInt(this, value, offset, byteLength, maxBytes, 0)
16136 }
16137
16138 var i = byteLength - 1
16139 var mul = 1
16140 this[offset + i] = value & 0xFF
16141 while (--i >= 0 && (mul *= 0x100)) {
16142 this[offset + i] = (value / mul) & 0xFF
16143 }
16144
16145 return offset + byteLength
16146}
16147
16148Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
16149 value = +value
16150 offset = offset >>> 0
16151 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
16152 this[offset] = (value & 0xff)
16153 return offset + 1
16154}
16155
16156Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
16157 value = +value
16158 offset = offset >>> 0
16159 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
16160 this[offset] = (value & 0xff)
16161 this[offset + 1] = (value >>> 8)
16162 return offset + 2
16163}
16164
16165Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
16166 value = +value
16167 offset = offset >>> 0
16168 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
16169 this[offset] = (value >>> 8)
16170 this[offset + 1] = (value & 0xff)
16171 return offset + 2
16172}
16173
16174Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
16175 value = +value
16176 offset = offset >>> 0
16177 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
16178 this[offset + 3] = (value >>> 24)
16179 this[offset + 2] = (value >>> 16)
16180 this[offset + 1] = (value >>> 8)
16181 this[offset] = (value & 0xff)
16182 return offset + 4
16183}
16184
16185Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
16186 value = +value
16187 offset = offset >>> 0
16188 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
16189 this[offset] = (value >>> 24)
16190 this[offset + 1] = (value >>> 16)
16191 this[offset + 2] = (value >>> 8)
16192 this[offset + 3] = (value & 0xff)
16193 return offset + 4
16194}
16195
16196Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
16197 value = +value
16198 offset = offset >>> 0
16199 if (!noAssert) {
16200 var limit = Math.pow(2, (8 * byteLength) - 1)
16201
16202 checkInt(this, value, offset, byteLength, limit - 1, -limit)
16203 }
16204
16205 var i = 0
16206 var mul = 1
16207 var sub = 0
16208 this[offset] = value & 0xFF
16209 while (++i < byteLength && (mul *= 0x100)) {
16210 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
16211 sub = 1
16212 }
16213 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
16214 }
16215
16216 return offset + byteLength
16217}
16218
16219Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
16220 value = +value
16221 offset = offset >>> 0
16222 if (!noAssert) {
16223 var limit = Math.pow(2, (8 * byteLength) - 1)
16224
16225 checkInt(this, value, offset, byteLength, limit - 1, -limit)
16226 }
16227
16228 var i = byteLength - 1
16229 var mul = 1
16230 var sub = 0
16231 this[offset + i] = value & 0xFF
16232 while (--i >= 0 && (mul *= 0x100)) {
16233 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
16234 sub = 1
16235 }
16236 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
16237 }
16238
16239 return offset + byteLength
16240}
16241
16242Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
16243 value = +value
16244 offset = offset >>> 0
16245 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
16246 if (value < 0) value = 0xff + value + 1
16247 this[offset] = (value & 0xff)
16248 return offset + 1
16249}
16250
16251Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
16252 value = +value
16253 offset = offset >>> 0
16254 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
16255 this[offset] = (value & 0xff)
16256 this[offset + 1] = (value >>> 8)
16257 return offset + 2
16258}
16259
16260Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
16261 value = +value
16262 offset = offset >>> 0
16263 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
16264 this[offset] = (value >>> 8)
16265 this[offset + 1] = (value & 0xff)
16266 return offset + 2
16267}
16268
16269Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
16270 value = +value
16271 offset = offset >>> 0
16272 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
16273 this[offset] = (value & 0xff)
16274 this[offset + 1] = (value >>> 8)
16275 this[offset + 2] = (value >>> 16)
16276 this[offset + 3] = (value >>> 24)
16277 return offset + 4
16278}
16279
16280Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
16281 value = +value
16282 offset = offset >>> 0
16283 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
16284 if (value < 0) value = 0xffffffff + value + 1
16285 this[offset] = (value >>> 24)
16286 this[offset + 1] = (value >>> 16)
16287 this[offset + 2] = (value >>> 8)
16288 this[offset + 3] = (value & 0xff)
16289 return offset + 4
16290}
16291
16292function checkIEEE754 (buf, value, offset, ext, max, min) {
16293 if (offset + ext > buf.length) throw new RangeError('Index out of range')
16294 if (offset < 0) throw new RangeError('Index out of range')
16295}
16296
16297function writeFloat (buf, value, offset, littleEndian, noAssert) {
16298 value = +value
16299 offset = offset >>> 0
16300 if (!noAssert) {
16301 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
16302 }
16303 ieee754.write(buf, value, offset, littleEndian, 23, 4)
16304 return offset + 4
16305}
16306
16307Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
16308 return writeFloat(this, value, offset, true, noAssert)
16309}
16310
16311Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
16312 return writeFloat(this, value, offset, false, noAssert)
16313}
16314
16315function writeDouble (buf, value, offset, littleEndian, noAssert) {
16316 value = +value
16317 offset = offset >>> 0
16318 if (!noAssert) {
16319 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
16320 }
16321 ieee754.write(buf, value, offset, littleEndian, 52, 8)
16322 return offset + 8
16323}
16324
16325Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
16326 return writeDouble(this, value, offset, true, noAssert)
16327}
16328
16329Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
16330 return writeDouble(this, value, offset, false, noAssert)
16331}
16332
16333// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
16334Buffer.prototype.copy = function copy (target, targetStart, start, end) {
16335 if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
16336 if (!start) start = 0
16337 if (!end && end !== 0) end = this.length
16338 if (targetStart >= target.length) targetStart = target.length
16339 if (!targetStart) targetStart = 0
16340 if (end > 0 && end < start) end = start
16341
16342 // Copy 0 bytes; we're done
16343 if (end === start) return 0
16344 if (target.length === 0 || this.length === 0) return 0
16345
16346 // Fatal error conditions
16347 if (targetStart < 0) {
16348 throw new RangeError('targetStart out of bounds')
16349 }
16350 if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
16351 if (end < 0) throw new RangeError('sourceEnd out of bounds')
16352
16353 // Are we oob?
16354 if (end > this.length) end = this.length
16355 if (target.length - targetStart < end - start) {
16356 end = target.length - targetStart + start
16357 }
16358
16359 var len = end - start
16360
16361 if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
16362 // Use built-in when available, missing from IE11
16363 this.copyWithin(targetStart, start, end)
16364 } else if (this === target && start < targetStart && targetStart < end) {
16365 // descending copy from end
16366 for (var i = len - 1; i >= 0; --i) {
16367 target[i + targetStart] = this[i + start]
16368 }
16369 } else {
16370 Uint8Array.prototype.set.call(
16371 target,
16372 this.subarray(start, end),
16373 targetStart
16374 )
16375 }
16376
16377 return len
16378}
16379
16380// Usage:
16381// buffer.fill(number[, offset[, end]])
16382// buffer.fill(buffer[, offset[, end]])
16383// buffer.fill(string[, offset[, end]][, encoding])
16384Buffer.prototype.fill = function fill (val, start, end, encoding) {
16385 // Handle string cases:
16386 if (typeof val === 'string') {
16387 if (typeof start === 'string') {
16388 encoding = start
16389 start = 0
16390 end = this.length
16391 } else if (typeof end === 'string') {
16392 encoding = end
16393 end = this.length
16394 }
16395 if (encoding !== undefined && typeof encoding !== 'string') {
16396 throw new TypeError('encoding must be a string')
16397 }
16398 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
16399 throw new TypeError('Unknown encoding: ' + encoding)
16400 }
16401 if (val.length === 1) {
16402 var code = val.charCodeAt(0)
16403 if ((encoding === 'utf8' && code < 128) ||
16404 encoding === 'latin1') {
16405 // Fast path: If `val` fits into a single byte, use that numeric value.
16406 val = code
16407 }
16408 }
16409 } else if (typeof val === 'number') {
16410 val = val & 255
16411 } else if (typeof val === 'boolean') {
16412 val = Number(val)
16413 }
16414
16415 // Invalid ranges are not set to a default, so can range check early.
16416 if (start < 0 || this.length < start || this.length < end) {
16417 throw new RangeError('Out of range index')
16418 }
16419
16420 if (end <= start) {
16421 return this
16422 }
16423
16424 start = start >>> 0
16425 end = end === undefined ? this.length : end >>> 0
16426
16427 if (!val) val = 0
16428
16429 var i
16430 if (typeof val === 'number') {
16431 for (i = start; i < end; ++i) {
16432 this[i] = val
16433 }
16434 } else {
16435 var bytes = Buffer.isBuffer(val)
16436 ? val
16437 : Buffer.from(val, encoding)
16438 var len = bytes.length
16439 if (len === 0) {
16440 throw new TypeError('The value "' + val +
16441 '" is invalid for argument "value"')
16442 }
16443 for (i = 0; i < end - start; ++i) {
16444 this[i + start] = bytes[i % len]
16445 }
16446 }
16447
16448 return this
16449}
16450
16451// HELPER FUNCTIONS
16452// ================
16453
16454var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
16455
16456function base64clean (str) {
16457 // Node takes equal signs as end of the Base64 encoding
16458 str = str.split('=')[0]
16459 // Node strips out invalid characters like \n and \t from the string, base64-js does not
16460 str = str.trim().replace(INVALID_BASE64_RE, '')
16461 // Node converts strings with length < 2 to ''
16462 if (str.length < 2) return ''
16463 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
16464 while (str.length % 4 !== 0) {
16465 str = str + '='
16466 }
16467 return str
16468}
16469
16470function toHex (n) {
16471 if (n < 16) return '0' + n.toString(16)
16472 return n.toString(16)
16473}
16474
16475function utf8ToBytes (string, units) {
16476 units = units || Infinity
16477 var codePoint
16478 var length = string.length
16479 var leadSurrogate = null
16480 var bytes = []
16481
16482 for (var i = 0; i < length; ++i) {
16483 codePoint = string.charCodeAt(i)
16484
16485 // is surrogate component
16486 if (codePoint > 0xD7FF && codePoint < 0xE000) {
16487 // last char was a lead
16488 if (!leadSurrogate) {
16489 // no lead yet
16490 if (codePoint > 0xDBFF) {
16491 // unexpected trail
16492 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16493 continue
16494 } else if (i + 1 === length) {
16495 // unpaired lead
16496 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16497 continue
16498 }
16499
16500 // valid lead
16501 leadSurrogate = codePoint
16502
16503 continue
16504 }
16505
16506 // 2 leads in a row
16507 if (codePoint < 0xDC00) {
16508 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16509 leadSurrogate = codePoint
16510 continue
16511 }
16512
16513 // valid surrogate pair
16514 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
16515 } else if (leadSurrogate) {
16516 // valid bmp char, but last char was a lead
16517 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16518 }
16519
16520 leadSurrogate = null
16521
16522 // encode utf8
16523 if (codePoint < 0x80) {
16524 if ((units -= 1) < 0) break
16525 bytes.push(codePoint)
16526 } else if (codePoint < 0x800) {
16527 if ((units -= 2) < 0) break
16528 bytes.push(
16529 codePoint >> 0x6 | 0xC0,
16530 codePoint & 0x3F | 0x80
16531 )
16532 } else if (codePoint < 0x10000) {
16533 if ((units -= 3) < 0) break
16534 bytes.push(
16535 codePoint >> 0xC | 0xE0,
16536 codePoint >> 0x6 & 0x3F | 0x80,
16537 codePoint & 0x3F | 0x80
16538 )
16539 } else if (codePoint < 0x110000) {
16540 if ((units -= 4) < 0) break
16541 bytes.push(
16542 codePoint >> 0x12 | 0xF0,
16543 codePoint >> 0xC & 0x3F | 0x80,
16544 codePoint >> 0x6 & 0x3F | 0x80,
16545 codePoint & 0x3F | 0x80
16546 )
16547 } else {
16548 throw new Error('Invalid code point')
16549 }
16550 }
16551
16552 return bytes
16553}
16554
16555function asciiToBytes (str) {
16556 var byteArray = []
16557 for (var i = 0; i < str.length; ++i) {
16558 // Node's code seems to be doing this and not & 0x7F..
16559 byteArray.push(str.charCodeAt(i) & 0xFF)
16560 }
16561 return byteArray
16562}
16563
16564function utf16leToBytes (str, units) {
16565 var c, hi, lo
16566 var byteArray = []
16567 for (var i = 0; i < str.length; ++i) {
16568 if ((units -= 2) < 0) break
16569
16570 c = str.charCodeAt(i)
16571 hi = c >> 8
16572 lo = c % 256
16573 byteArray.push(lo)
16574 byteArray.push(hi)
16575 }
16576
16577 return byteArray
16578}
16579
16580function base64ToBytes (str) {
16581 return base64.toByteArray(base64clean(str))
16582}
16583
16584function blitBuffer (src, dst, offset, length) {
16585 for (var i = 0; i < length; ++i) {
16586 if ((i + offset >= dst.length) || (i >= src.length)) break
16587 dst[i + offset] = src[i]
16588 }
16589 return i
16590}
16591
16592// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
16593// the `instanceof` check but they should be treated as of that type.
16594// See: https://github.com/feross/buffer/issues/166
16595function isInstance (obj, type) {
16596 return obj instanceof type ||
16597 (obj != null && obj.constructor != null && obj.constructor.name != null &&
16598 obj.constructor.name === type.name)
16599}
16600function numberIsNaN (obj) {
16601 // For IE11 support
16602 return obj !== obj // eslint-disable-line no-self-compare
16603}
16604
16605}).call(this,require("buffer").Buffer)
16606},{"base64-js":78,"buffer":110,"ieee754":161}],111:[function(require,module,exports){
16607arguments[4][31][0].apply(exports,arguments)
16608},{"dup":31,"inherits":162,"safe-buffer":206,"stream":215,"string_decoder":216}],112:[function(require,module,exports){
16609(function (Buffer){
16610// Copyright Joyent, Inc. and other Node contributors.
16611//
16612// Permission is hereby granted, free of charge, to any person obtaining a
16613// copy of this software and associated documentation files (the
16614// "Software"), to deal in the Software without restriction, including
16615// without limitation the rights to use, copy, modify, merge, publish,
16616// distribute, sublicense, and/or sell copies of the Software, and to permit
16617// persons to whom the Software is furnished to do so, subject to the
16618// following conditions:
16619//
16620// The above copyright notice and this permission notice shall be included
16621// in all copies or substantial portions of the Software.
16622//
16623// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16624// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16625// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
16626// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16627// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16628// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16629// USE OR OTHER DEALINGS IN THE SOFTWARE.
16630
16631// NOTE: These type checking functions intentionally don't use `instanceof`
16632// because it is fragile and can be easily faked with `Object.create()`.
16633
16634function isArray(arg) {
16635 if (Array.isArray) {
16636 return Array.isArray(arg);
16637 }
16638 return objectToString(arg) === '[object Array]';
16639}
16640exports.isArray = isArray;
16641
16642function isBoolean(arg) {
16643 return typeof arg === 'boolean';
16644}
16645exports.isBoolean = isBoolean;
16646
16647function isNull(arg) {
16648 return arg === null;
16649}
16650exports.isNull = isNull;
16651
16652function isNullOrUndefined(arg) {
16653 return arg == null;
16654}
16655exports.isNullOrUndefined = isNullOrUndefined;
16656
16657function isNumber(arg) {
16658 return typeof arg === 'number';
16659}
16660exports.isNumber = isNumber;
16661
16662function isString(arg) {
16663 return typeof arg === 'string';
16664}
16665exports.isString = isString;
16666
16667function isSymbol(arg) {
16668 return typeof arg === 'symbol';
16669}
16670exports.isSymbol = isSymbol;
16671
16672function isUndefined(arg) {
16673 return arg === void 0;
16674}
16675exports.isUndefined = isUndefined;
16676
16677function isRegExp(re) {
16678 return objectToString(re) === '[object RegExp]';
16679}
16680exports.isRegExp = isRegExp;
16681
16682function isObject(arg) {
16683 return typeof arg === 'object' && arg !== null;
16684}
16685exports.isObject = isObject;
16686
16687function isDate(d) {
16688 return objectToString(d) === '[object Date]';
16689}
16690exports.isDate = isDate;
16691
16692function isError(e) {
16693 return (objectToString(e) === '[object Error]' || e instanceof Error);
16694}
16695exports.isError = isError;
16696
16697function isFunction(arg) {
16698 return typeof arg === 'function';
16699}
16700exports.isFunction = isFunction;
16701
16702function isPrimitive(arg) {
16703 return arg === null ||
16704 typeof arg === 'boolean' ||
16705 typeof arg === 'number' ||
16706 typeof arg === 'string' ||
16707 typeof arg === 'symbol' || // ES6 symbol
16708 typeof arg === 'undefined';
16709}
16710exports.isPrimitive = isPrimitive;
16711
16712exports.isBuffer = Buffer.isBuffer;
16713
16714function objectToString(o) {
16715 return Object.prototype.toString.call(o);
16716}
16717
16718}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
16719},{"../../is-buffer/index.js":163}],113:[function(require,module,exports){
16720(function (Buffer){
16721var elliptic = require('elliptic')
16722var BN = require('bn.js')
16723
16724module.exports = function createECDH (curve) {
16725 return new ECDH(curve)
16726}
16727
16728var aliases = {
16729 secp256k1: {
16730 name: 'secp256k1',
16731 byteLength: 32
16732 },
16733 secp224r1: {
16734 name: 'p224',
16735 byteLength: 28
16736 },
16737 prime256v1: {
16738 name: 'p256',
16739 byteLength: 32
16740 },
16741 prime192v1: {
16742 name: 'p192',
16743 byteLength: 24
16744 },
16745 ed25519: {
16746 name: 'ed25519',
16747 byteLength: 32
16748 },
16749 secp384r1: {
16750 name: 'p384',
16751 byteLength: 48
16752 },
16753 secp521r1: {
16754 name: 'p521',
16755 byteLength: 66
16756 }
16757}
16758
16759aliases.p224 = aliases.secp224r1
16760aliases.p256 = aliases.secp256r1 = aliases.prime256v1
16761aliases.p192 = aliases.secp192r1 = aliases.prime192v1
16762aliases.p384 = aliases.secp384r1
16763aliases.p521 = aliases.secp521r1
16764
16765function ECDH (curve) {
16766 this.curveType = aliases[curve]
16767 if (!this.curveType) {
16768 this.curveType = {
16769 name: curve
16770 }
16771 }
16772 this.curve = new elliptic.ec(this.curveType.name) // eslint-disable-line new-cap
16773 this.keys = void 0
16774}
16775
16776ECDH.prototype.generateKeys = function (enc, format) {
16777 this.keys = this.curve.genKeyPair()
16778 return this.getPublicKey(enc, format)
16779}
16780
16781ECDH.prototype.computeSecret = function (other, inenc, enc) {
16782 inenc = inenc || 'utf8'
16783 if (!Buffer.isBuffer(other)) {
16784 other = new Buffer(other, inenc)
16785 }
16786 var otherPub = this.curve.keyFromPublic(other).getPublic()
16787 var out = otherPub.mul(this.keys.getPrivate()).getX()
16788 return formatReturnValue(out, enc, this.curveType.byteLength)
16789}
16790
16791ECDH.prototype.getPublicKey = function (enc, format) {
16792 var key = this.keys.getPublic(format === 'compressed', true)
16793 if (format === 'hybrid') {
16794 if (key[key.length - 1] % 2) {
16795 key[0] = 7
16796 } else {
16797 key[0] = 6
16798 }
16799 }
16800 return formatReturnValue(key, enc)
16801}
16802
16803ECDH.prototype.getPrivateKey = function (enc) {
16804 return formatReturnValue(this.keys.getPrivate(), enc)
16805}
16806
16807ECDH.prototype.setPublicKey = function (pub, enc) {
16808 enc = enc || 'utf8'
16809 if (!Buffer.isBuffer(pub)) {
16810 pub = new Buffer(pub, enc)
16811 }
16812 this.keys._importPublic(pub)
16813 return this
16814}
16815
16816ECDH.prototype.setPrivateKey = function (priv, enc) {
16817 enc = enc || 'utf8'
16818 if (!Buffer.isBuffer(priv)) {
16819 priv = new Buffer(priv, enc)
16820 }
16821
16822 var _priv = new BN(priv)
16823 _priv = _priv.toString(16)
16824 this.keys = this.curve.genKeyPair()
16825 this.keys._importPrivate(_priv)
16826 return this
16827}
16828
16829function formatReturnValue (bn, enc, len) {
16830 if (!Array.isArray(bn)) {
16831 bn = bn.toArray()
16832 }
16833 var buf = new Buffer(bn)
16834 if (len && buf.length < len) {
16835 var zeros = new Buffer(len - buf.length)
16836 zeros.fill(0)
16837 buf = Buffer.concat([zeros, buf])
16838 }
16839 if (!enc) {
16840 return buf
16841 } else {
16842 return buf.toString(enc)
16843 }
16844}
16845
16846}).call(this,require("buffer").Buffer)
16847},{"bn.js":79,"buffer":110,"elliptic":129}],114:[function(require,module,exports){
16848arguments[4][32][0].apply(exports,arguments)
16849},{"cipher-base":111,"dup":32,"inherits":162,"md5.js":165,"ripemd160":205,"sha.js":208}],115:[function(require,module,exports){
16850var MD5 = require('md5.js')
16851
16852module.exports = function (buffer) {
16853 return new MD5().update(buffer).digest()
16854}
16855
16856},{"md5.js":165}],116:[function(require,module,exports){
16857'use strict'
16858var inherits = require('inherits')
16859var Legacy = require('./legacy')
16860var Base = require('cipher-base')
16861var Buffer = require('safe-buffer').Buffer
16862var md5 = require('create-hash/md5')
16863var RIPEMD160 = require('ripemd160')
16864
16865var sha = require('sha.js')
16866
16867var ZEROS = Buffer.alloc(128)
16868
16869function Hmac (alg, key) {
16870 Base.call(this, 'digest')
16871 if (typeof key === 'string') {
16872 key = Buffer.from(key)
16873 }
16874
16875 var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
16876
16877 this._alg = alg
16878 this._key = key
16879 if (key.length > blocksize) {
16880 var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
16881 key = hash.update(key).digest()
16882 } else if (key.length < blocksize) {
16883 key = Buffer.concat([key, ZEROS], blocksize)
16884 }
16885
16886 var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
16887 var opad = this._opad = Buffer.allocUnsafe(blocksize)
16888
16889 for (var i = 0; i < blocksize; i++) {
16890 ipad[i] = key[i] ^ 0x36
16891 opad[i] = key[i] ^ 0x5C
16892 }
16893 this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
16894 this._hash.update(ipad)
16895}
16896
16897inherits(Hmac, Base)
16898
16899Hmac.prototype._update = function (data) {
16900 this._hash.update(data)
16901}
16902
16903Hmac.prototype._final = function () {
16904 var h = this._hash.digest()
16905 var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg)
16906 return hash.update(this._opad).update(h).digest()
16907}
16908
16909module.exports = function createHmac (alg, key) {
16910 alg = alg.toLowerCase()
16911 if (alg === 'rmd160' || alg === 'ripemd160') {
16912 return new Hmac('rmd160', key)
16913 }
16914 if (alg === 'md5') {
16915 return new Legacy(md5, key)
16916 }
16917 return new Hmac(alg, key)
16918}
16919
16920},{"./legacy":117,"cipher-base":111,"create-hash/md5":115,"inherits":162,"ripemd160":205,"safe-buffer":206,"sha.js":208}],117:[function(require,module,exports){
16921'use strict'
16922var inherits = require('inherits')
16923var Buffer = require('safe-buffer').Buffer
16924
16925var Base = require('cipher-base')
16926
16927var ZEROS = Buffer.alloc(128)
16928var blocksize = 64
16929
16930function Hmac (alg, key) {
16931 Base.call(this, 'digest')
16932 if (typeof key === 'string') {
16933 key = Buffer.from(key)
16934 }
16935
16936 this._alg = alg
16937 this._key = key
16938
16939 if (key.length > blocksize) {
16940 key = alg(key)
16941 } else if (key.length < blocksize) {
16942 key = Buffer.concat([key, ZEROS], blocksize)
16943 }
16944
16945 var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
16946 var opad = this._opad = Buffer.allocUnsafe(blocksize)
16947
16948 for (var i = 0; i < blocksize; i++) {
16949 ipad[i] = key[i] ^ 0x36
16950 opad[i] = key[i] ^ 0x5C
16951 }
16952
16953 this._hash = [ipad]
16954}
16955
16956inherits(Hmac, Base)
16957
16958Hmac.prototype._update = function (data) {
16959 this._hash.push(data)
16960}
16961
16962Hmac.prototype._final = function () {
16963 var h = this._alg(Buffer.concat(this._hash))
16964 return this._alg(Buffer.concat([this._opad, h]))
16965}
16966module.exports = Hmac
16967
16968},{"cipher-base":111,"inherits":162,"safe-buffer":206}],118:[function(require,module,exports){
16969'use strict'
16970
16971exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
16972exports.createHash = exports.Hash = require('create-hash')
16973exports.createHmac = exports.Hmac = require('create-hmac')
16974
16975var algos = require('browserify-sign/algos')
16976var algoKeys = Object.keys(algos)
16977var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys)
16978exports.getHashes = function () {
16979 return hashes
16980}
16981
16982var p = require('pbkdf2')
16983exports.pbkdf2 = p.pbkdf2
16984exports.pbkdf2Sync = p.pbkdf2Sync
16985
16986var aes = require('browserify-cipher')
16987
16988exports.Cipher = aes.Cipher
16989exports.createCipher = aes.createCipher
16990exports.Cipheriv = aes.Cipheriv
16991exports.createCipheriv = aes.createCipheriv
16992exports.Decipher = aes.Decipher
16993exports.createDecipher = aes.createDecipher
16994exports.Decipheriv = aes.Decipheriv
16995exports.createDecipheriv = aes.createDecipheriv
16996exports.getCiphers = aes.getCiphers
16997exports.listCiphers = aes.listCiphers
16998
16999var dh = require('diffie-hellman')
17000
17001exports.DiffieHellmanGroup = dh.DiffieHellmanGroup
17002exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup
17003exports.getDiffieHellman = dh.getDiffieHellman
17004exports.createDiffieHellman = dh.createDiffieHellman
17005exports.DiffieHellman = dh.DiffieHellman
17006
17007var sign = require('browserify-sign')
17008
17009exports.createSign = sign.createSign
17010exports.Sign = sign.Sign
17011exports.createVerify = sign.createVerify
17012exports.Verify = sign.Verify
17013
17014exports.createECDH = require('create-ecdh')
17015
17016var publicEncrypt = require('public-encrypt')
17017
17018exports.publicEncrypt = publicEncrypt.publicEncrypt
17019exports.privateEncrypt = publicEncrypt.privateEncrypt
17020exports.publicDecrypt = publicEncrypt.publicDecrypt
17021exports.privateDecrypt = publicEncrypt.privateDecrypt
17022
17023// the least I can do is make error messages for the rest of the node.js/crypto api.
17024// ;[
17025// 'createCredentials'
17026// ].forEach(function (name) {
17027// exports[name] = function () {
17028// throw new Error([
17029// 'sorry, ' + name + ' is not implemented yet',
17030// 'we accept pull requests',
17031// 'https://github.com/crypto-browserify/crypto-browserify'
17032// ].join('\n'))
17033// }
17034// })
17035
17036var rf = require('randomfill')
17037
17038exports.randomFill = rf.randomFill
17039exports.randomFillSync = rf.randomFillSync
17040
17041exports.createCredentials = function () {
17042 throw new Error([
17043 'sorry, createCredentials is not implemented yet',
17044 'we accept pull requests',
17045 'https://github.com/crypto-browserify/crypto-browserify'
17046 ].join('\n'))
17047}
17048
17049exports.constants = {
17050 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
17051 'DH_CHECK_P_NOT_PRIME': 1,
17052 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
17053 'DH_NOT_SUITABLE_GENERATOR': 8,
17054 'NPN_ENABLED': 1,
17055 'ALPN_ENABLED': 1,
17056 'RSA_PKCS1_PADDING': 1,
17057 'RSA_SSLV23_PADDING': 2,
17058 'RSA_NO_PADDING': 3,
17059 'RSA_PKCS1_OAEP_PADDING': 4,
17060 'RSA_X931_PADDING': 5,
17061 'RSA_PKCS1_PSS_PADDING': 6,
17062 'POINT_CONVERSION_COMPRESSED': 2,
17063 'POINT_CONVERSION_UNCOMPRESSED': 4,
17064 'POINT_CONVERSION_HYBRID': 6
17065}
17066
17067},{"browserify-cipher":99,"browserify-sign":106,"browserify-sign/algos":103,"create-ecdh":113,"create-hash":114,"create-hmac":116,"diffie-hellman":125,"pbkdf2":175,"public-encrypt":182,"randombytes":188,"randomfill":189}],119:[function(require,module,exports){
17068'use strict';
17069
17070exports.utils = require('./des/utils');
17071exports.Cipher = require('./des/cipher');
17072exports.DES = require('./des/des');
17073exports.CBC = require('./des/cbc');
17074exports.EDE = require('./des/ede');
17075
17076},{"./des/cbc":120,"./des/cipher":121,"./des/des":122,"./des/ede":123,"./des/utils":124}],120:[function(require,module,exports){
17077'use strict';
17078
17079var assert = require('minimalistic-assert');
17080var inherits = require('inherits');
17081
17082var proto = {};
17083
17084function CBCState(iv) {
17085 assert.equal(iv.length, 8, 'Invalid IV length');
17086
17087 this.iv = new Array(8);
17088 for (var i = 0; i < this.iv.length; i++)
17089 this.iv[i] = iv[i];
17090}
17091
17092function instantiate(Base) {
17093 function CBC(options) {
17094 Base.call(this, options);
17095 this._cbcInit();
17096 }
17097 inherits(CBC, Base);
17098
17099 var keys = Object.keys(proto);
17100 for (var i = 0; i < keys.length; i++) {
17101 var key = keys[i];
17102 CBC.prototype[key] = proto[key];
17103 }
17104
17105 CBC.create = function create(options) {
17106 return new CBC(options);
17107 };
17108
17109 return CBC;
17110}
17111
17112exports.instantiate = instantiate;
17113
17114proto._cbcInit = function _cbcInit() {
17115 var state = new CBCState(this.options.iv);
17116 this._cbcState = state;
17117};
17118
17119proto._update = function _update(inp, inOff, out, outOff) {
17120 var state = this._cbcState;
17121 var superProto = this.constructor.super_.prototype;
17122
17123 var iv = state.iv;
17124 if (this.type === 'encrypt') {
17125 for (var i = 0; i < this.blockSize; i++)
17126 iv[i] ^= inp[inOff + i];
17127
17128 superProto._update.call(this, iv, 0, out, outOff);
17129
17130 for (var i = 0; i < this.blockSize; i++)
17131 iv[i] = out[outOff + i];
17132 } else {
17133 superProto._update.call(this, inp, inOff, out, outOff);
17134
17135 for (var i = 0; i < this.blockSize; i++)
17136 out[outOff + i] ^= iv[i];
17137
17138 for (var i = 0; i < this.blockSize; i++)
17139 iv[i] = inp[inOff + i];
17140 }
17141};
17142
17143},{"inherits":162,"minimalistic-assert":167}],121:[function(require,module,exports){
17144'use strict';
17145
17146var assert = require('minimalistic-assert');
17147
17148function Cipher(options) {
17149 this.options = options;
17150
17151 this.type = this.options.type;
17152 this.blockSize = 8;
17153 this._init();
17154
17155 this.buffer = new Array(this.blockSize);
17156 this.bufferOff = 0;
17157}
17158module.exports = Cipher;
17159
17160Cipher.prototype._init = function _init() {
17161 // Might be overrided
17162};
17163
17164Cipher.prototype.update = function update(data) {
17165 if (data.length === 0)
17166 return [];
17167
17168 if (this.type === 'decrypt')
17169 return this._updateDecrypt(data);
17170 else
17171 return this._updateEncrypt(data);
17172};
17173
17174Cipher.prototype._buffer = function _buffer(data, off) {
17175 // Append data to buffer
17176 var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
17177 for (var i = 0; i < min; i++)
17178 this.buffer[this.bufferOff + i] = data[off + i];
17179 this.bufferOff += min;
17180
17181 // Shift next
17182 return min;
17183};
17184
17185Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
17186 this._update(this.buffer, 0, out, off);
17187 this.bufferOff = 0;
17188 return this.blockSize;
17189};
17190
17191Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
17192 var inputOff = 0;
17193 var outputOff = 0;
17194
17195 var count = ((this.bufferOff + data.length) / this.blockSize) | 0;
17196 var out = new Array(count * this.blockSize);
17197
17198 if (this.bufferOff !== 0) {
17199 inputOff += this._buffer(data, inputOff);
17200
17201 if (this.bufferOff === this.buffer.length)
17202 outputOff += this._flushBuffer(out, outputOff);
17203 }
17204
17205 // Write blocks
17206 var max = data.length - ((data.length - inputOff) % this.blockSize);
17207 for (; inputOff < max; inputOff += this.blockSize) {
17208 this._update(data, inputOff, out, outputOff);
17209 outputOff += this.blockSize;
17210 }
17211
17212 // Queue rest
17213 for (; inputOff < data.length; inputOff++, this.bufferOff++)
17214 this.buffer[this.bufferOff] = data[inputOff];
17215
17216 return out;
17217};
17218
17219Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
17220 var inputOff = 0;
17221 var outputOff = 0;
17222
17223 var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
17224 var out = new Array(count * this.blockSize);
17225
17226 // TODO(indutny): optimize it, this is far from optimal
17227 for (; count > 0; count--) {
17228 inputOff += this._buffer(data, inputOff);
17229 outputOff += this._flushBuffer(out, outputOff);
17230 }
17231
17232 // Buffer rest of the input
17233 inputOff += this._buffer(data, inputOff);
17234
17235 return out;
17236};
17237
17238Cipher.prototype.final = function final(buffer) {
17239 var first;
17240 if (buffer)
17241 first = this.update(buffer);
17242
17243 var last;
17244 if (this.type === 'encrypt')
17245 last = this._finalEncrypt();
17246 else
17247 last = this._finalDecrypt();
17248
17249 if (first)
17250 return first.concat(last);
17251 else
17252 return last;
17253};
17254
17255Cipher.prototype._pad = function _pad(buffer, off) {
17256 if (off === 0)
17257 return false;
17258
17259 while (off < buffer.length)
17260 buffer[off++] = 0;
17261
17262 return true;
17263};
17264
17265Cipher.prototype._finalEncrypt = function _finalEncrypt() {
17266 if (!this._pad(this.buffer, this.bufferOff))
17267 return [];
17268
17269 var out = new Array(this.blockSize);
17270 this._update(this.buffer, 0, out, 0);
17271 return out;
17272};
17273
17274Cipher.prototype._unpad = function _unpad(buffer) {
17275 return buffer;
17276};
17277
17278Cipher.prototype._finalDecrypt = function _finalDecrypt() {
17279 assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
17280 var out = new Array(this.blockSize);
17281 this._flushBuffer(out, 0);
17282
17283 return this._unpad(out);
17284};
17285
17286},{"minimalistic-assert":167}],122:[function(require,module,exports){
17287'use strict';
17288
17289var assert = require('minimalistic-assert');
17290var inherits = require('inherits');
17291
17292var des = require('../des');
17293var utils = des.utils;
17294var Cipher = des.Cipher;
17295
17296function DESState() {
17297 this.tmp = new Array(2);
17298 this.keys = null;
17299}
17300
17301function DES(options) {
17302 Cipher.call(this, options);
17303
17304 var state = new DESState();
17305 this._desState = state;
17306
17307 this.deriveKeys(state, options.key);
17308}
17309inherits(DES, Cipher);
17310module.exports = DES;
17311
17312DES.create = function create(options) {
17313 return new DES(options);
17314};
17315
17316var shiftTable = [
17317 1, 1, 2, 2, 2, 2, 2, 2,
17318 1, 2, 2, 2, 2, 2, 2, 1
17319];
17320
17321DES.prototype.deriveKeys = function deriveKeys(state, key) {
17322 state.keys = new Array(16 * 2);
17323
17324 assert.equal(key.length, this.blockSize, 'Invalid key length');
17325
17326 var kL = utils.readUInt32BE(key, 0);
17327 var kR = utils.readUInt32BE(key, 4);
17328
17329 utils.pc1(kL, kR, state.tmp, 0);
17330 kL = state.tmp[0];
17331 kR = state.tmp[1];
17332 for (var i = 0; i < state.keys.length; i += 2) {
17333 var shift = shiftTable[i >>> 1];
17334 kL = utils.r28shl(kL, shift);
17335 kR = utils.r28shl(kR, shift);
17336 utils.pc2(kL, kR, state.keys, i);
17337 }
17338};
17339
17340DES.prototype._update = function _update(inp, inOff, out, outOff) {
17341 var state = this._desState;
17342
17343 var l = utils.readUInt32BE(inp, inOff);
17344 var r = utils.readUInt32BE(inp, inOff + 4);
17345
17346 // Initial Permutation
17347 utils.ip(l, r, state.tmp, 0);
17348 l = state.tmp[0];
17349 r = state.tmp[1];
17350
17351 if (this.type === 'encrypt')
17352 this._encrypt(state, l, r, state.tmp, 0);
17353 else
17354 this._decrypt(state, l, r, state.tmp, 0);
17355
17356 l = state.tmp[0];
17357 r = state.tmp[1];
17358
17359 utils.writeUInt32BE(out, l, outOff);
17360 utils.writeUInt32BE(out, r, outOff + 4);
17361};
17362
17363DES.prototype._pad = function _pad(buffer, off) {
17364 var value = buffer.length - off;
17365 for (var i = off; i < buffer.length; i++)
17366 buffer[i] = value;
17367
17368 return true;
17369};
17370
17371DES.prototype._unpad = function _unpad(buffer) {
17372 var pad = buffer[buffer.length - 1];
17373 for (var i = buffer.length - pad; i < buffer.length; i++)
17374 assert.equal(buffer[i], pad);
17375
17376 return buffer.slice(0, buffer.length - pad);
17377};
17378
17379DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
17380 var l = lStart;
17381 var r = rStart;
17382
17383 // Apply f() x16 times
17384 for (var i = 0; i < state.keys.length; i += 2) {
17385 var keyL = state.keys[i];
17386 var keyR = state.keys[i + 1];
17387
17388 // f(r, k)
17389 utils.expand(r, state.tmp, 0);
17390
17391 keyL ^= state.tmp[0];
17392 keyR ^= state.tmp[1];
17393 var s = utils.substitute(keyL, keyR);
17394 var f = utils.permute(s);
17395
17396 var t = r;
17397 r = (l ^ f) >>> 0;
17398 l = t;
17399 }
17400
17401 // Reverse Initial Permutation
17402 utils.rip(r, l, out, off);
17403};
17404
17405DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
17406 var l = rStart;
17407 var r = lStart;
17408
17409 // Apply f() x16 times
17410 for (var i = state.keys.length - 2; i >= 0; i -= 2) {
17411 var keyL = state.keys[i];
17412 var keyR = state.keys[i + 1];
17413
17414 // f(r, k)
17415 utils.expand(l, state.tmp, 0);
17416
17417 keyL ^= state.tmp[0];
17418 keyR ^= state.tmp[1];
17419 var s = utils.substitute(keyL, keyR);
17420 var f = utils.permute(s);
17421
17422 var t = l;
17423 l = (r ^ f) >>> 0;
17424 r = t;
17425 }
17426
17427 // Reverse Initial Permutation
17428 utils.rip(l, r, out, off);
17429};
17430
17431},{"../des":119,"inherits":162,"minimalistic-assert":167}],123:[function(require,module,exports){
17432'use strict';
17433
17434var assert = require('minimalistic-assert');
17435var inherits = require('inherits');
17436
17437var des = require('../des');
17438var Cipher = des.Cipher;
17439var DES = des.DES;
17440
17441function EDEState(type, key) {
17442 assert.equal(key.length, 24, 'Invalid key length');
17443
17444 var k1 = key.slice(0, 8);
17445 var k2 = key.slice(8, 16);
17446 var k3 = key.slice(16, 24);
17447
17448 if (type === 'encrypt') {
17449 this.ciphers = [
17450 DES.create({ type: 'encrypt', key: k1 }),
17451 DES.create({ type: 'decrypt', key: k2 }),
17452 DES.create({ type: 'encrypt', key: k3 })
17453 ];
17454 } else {
17455 this.ciphers = [
17456 DES.create({ type: 'decrypt', key: k3 }),
17457 DES.create({ type: 'encrypt', key: k2 }),
17458 DES.create({ type: 'decrypt', key: k1 })
17459 ];
17460 }
17461}
17462
17463function EDE(options) {
17464 Cipher.call(this, options);
17465
17466 var state = new EDEState(this.type, this.options.key);
17467 this._edeState = state;
17468}
17469inherits(EDE, Cipher);
17470
17471module.exports = EDE;
17472
17473EDE.create = function create(options) {
17474 return new EDE(options);
17475};
17476
17477EDE.prototype._update = function _update(inp, inOff, out, outOff) {
17478 var state = this._edeState;
17479
17480 state.ciphers[0]._update(inp, inOff, out, outOff);
17481 state.ciphers[1]._update(out, outOff, out, outOff);
17482 state.ciphers[2]._update(out, outOff, out, outOff);
17483};
17484
17485EDE.prototype._pad = DES.prototype._pad;
17486EDE.prototype._unpad = DES.prototype._unpad;
17487
17488},{"../des":119,"inherits":162,"minimalistic-assert":167}],124:[function(require,module,exports){
17489'use strict';
17490
17491exports.readUInt32BE = function readUInt32BE(bytes, off) {
17492 var res = (bytes[0 + off] << 24) |
17493 (bytes[1 + off] << 16) |
17494 (bytes[2 + off] << 8) |
17495 bytes[3 + off];
17496 return res >>> 0;
17497};
17498
17499exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
17500 bytes[0 + off] = value >>> 24;
17501 bytes[1 + off] = (value >>> 16) & 0xff;
17502 bytes[2 + off] = (value >>> 8) & 0xff;
17503 bytes[3 + off] = value & 0xff;
17504};
17505
17506exports.ip = function ip(inL, inR, out, off) {
17507 var outL = 0;
17508 var outR = 0;
17509
17510 for (var i = 6; i >= 0; i -= 2) {
17511 for (var j = 0; j <= 24; j += 8) {
17512 outL <<= 1;
17513 outL |= (inR >>> (j + i)) & 1;
17514 }
17515 for (var j = 0; j <= 24; j += 8) {
17516 outL <<= 1;
17517 outL |= (inL >>> (j + i)) & 1;
17518 }
17519 }
17520
17521 for (var i = 6; i >= 0; i -= 2) {
17522 for (var j = 1; j <= 25; j += 8) {
17523 outR <<= 1;
17524 outR |= (inR >>> (j + i)) & 1;
17525 }
17526 for (var j = 1; j <= 25; j += 8) {
17527 outR <<= 1;
17528 outR |= (inL >>> (j + i)) & 1;
17529 }
17530 }
17531
17532 out[off + 0] = outL >>> 0;
17533 out[off + 1] = outR >>> 0;
17534};
17535
17536exports.rip = function rip(inL, inR, out, off) {
17537 var outL = 0;
17538 var outR = 0;
17539
17540 for (var i = 0; i < 4; i++) {
17541 for (var j = 24; j >= 0; j -= 8) {
17542 outL <<= 1;
17543 outL |= (inR >>> (j + i)) & 1;
17544 outL <<= 1;
17545 outL |= (inL >>> (j + i)) & 1;
17546 }
17547 }
17548 for (var i = 4; i < 8; i++) {
17549 for (var j = 24; j >= 0; j -= 8) {
17550 outR <<= 1;
17551 outR |= (inR >>> (j + i)) & 1;
17552 outR <<= 1;
17553 outR |= (inL >>> (j + i)) & 1;
17554 }
17555 }
17556
17557 out[off + 0] = outL >>> 0;
17558 out[off + 1] = outR >>> 0;
17559};
17560
17561exports.pc1 = function pc1(inL, inR, out, off) {
17562 var outL = 0;
17563 var outR = 0;
17564
17565 // 7, 15, 23, 31, 39, 47, 55, 63
17566 // 6, 14, 22, 30, 39, 47, 55, 63
17567 // 5, 13, 21, 29, 39, 47, 55, 63
17568 // 4, 12, 20, 28
17569 for (var i = 7; i >= 5; i--) {
17570 for (var j = 0; j <= 24; j += 8) {
17571 outL <<= 1;
17572 outL |= (inR >> (j + i)) & 1;
17573 }
17574 for (var j = 0; j <= 24; j += 8) {
17575 outL <<= 1;
17576 outL |= (inL >> (j + i)) & 1;
17577 }
17578 }
17579 for (var j = 0; j <= 24; j += 8) {
17580 outL <<= 1;
17581 outL |= (inR >> (j + i)) & 1;
17582 }
17583
17584 // 1, 9, 17, 25, 33, 41, 49, 57
17585 // 2, 10, 18, 26, 34, 42, 50, 58
17586 // 3, 11, 19, 27, 35, 43, 51, 59
17587 // 36, 44, 52, 60
17588 for (var i = 1; i <= 3; i++) {
17589 for (var j = 0; j <= 24; j += 8) {
17590 outR <<= 1;
17591 outR |= (inR >> (j + i)) & 1;
17592 }
17593 for (var j = 0; j <= 24; j += 8) {
17594 outR <<= 1;
17595 outR |= (inL >> (j + i)) & 1;
17596 }
17597 }
17598 for (var j = 0; j <= 24; j += 8) {
17599 outR <<= 1;
17600 outR |= (inL >> (j + i)) & 1;
17601 }
17602
17603 out[off + 0] = outL >>> 0;
17604 out[off + 1] = outR >>> 0;
17605};
17606
17607exports.r28shl = function r28shl(num, shift) {
17608 return ((num << shift) & 0xfffffff) | (num >>> (28 - shift));
17609};
17610
17611var pc2table = [
17612 // inL => outL
17613 14, 11, 17, 4, 27, 23, 25, 0,
17614 13, 22, 7, 18, 5, 9, 16, 24,
17615 2, 20, 12, 21, 1, 8, 15, 26,
17616
17617 // inR => outR
17618 15, 4, 25, 19, 9, 1, 26, 16,
17619 5, 11, 23, 8, 12, 7, 17, 0,
17620 22, 3, 10, 14, 6, 20, 27, 24
17621];
17622
17623exports.pc2 = function pc2(inL, inR, out, off) {
17624 var outL = 0;
17625 var outR = 0;
17626
17627 var len = pc2table.length >>> 1;
17628 for (var i = 0; i < len; i++) {
17629 outL <<= 1;
17630 outL |= (inL >>> pc2table[i]) & 0x1;
17631 }
17632 for (var i = len; i < pc2table.length; i++) {
17633 outR <<= 1;
17634 outR |= (inR >>> pc2table[i]) & 0x1;
17635 }
17636
17637 out[off + 0] = outL >>> 0;
17638 out[off + 1] = outR >>> 0;
17639};
17640
17641exports.expand = function expand(r, out, off) {
17642 var outL = 0;
17643 var outR = 0;
17644
17645 outL = ((r & 1) << 5) | (r >>> 27);
17646 for (var i = 23; i >= 15; i -= 4) {
17647 outL <<= 6;
17648 outL |= (r >>> i) & 0x3f;
17649 }
17650 for (var i = 11; i >= 3; i -= 4) {
17651 outR |= (r >>> i) & 0x3f;
17652 outR <<= 6;
17653 }
17654 outR |= ((r & 0x1f) << 1) | (r >>> 31);
17655
17656 out[off + 0] = outL >>> 0;
17657 out[off + 1] = outR >>> 0;
17658};
17659
17660var sTable = [
17661 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1,
17662 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8,
17663 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7,
17664 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13,
17665
17666 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14,
17667 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5,
17668 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2,
17669 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9,
17670
17671 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10,
17672 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1,
17673 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7,
17674 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12,
17675
17676 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3,
17677 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9,
17678 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8,
17679 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14,
17680
17681 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1,
17682 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6,
17683 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13,
17684 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3,
17685
17686 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5,
17687 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8,
17688 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10,
17689 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13,
17690
17691 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10,
17692 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6,
17693 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7,
17694 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12,
17695
17696 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4,
17697 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2,
17698 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13,
17699 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11
17700];
17701
17702exports.substitute = function substitute(inL, inR) {
17703 var out = 0;
17704 for (var i = 0; i < 4; i++) {
17705 var b = (inL >>> (18 - i * 6)) & 0x3f;
17706 var sb = sTable[i * 0x40 + b];
17707
17708 out <<= 4;
17709 out |= sb;
17710 }
17711 for (var i = 0; i < 4; i++) {
17712 var b = (inR >>> (18 - i * 6)) & 0x3f;
17713 var sb = sTable[4 * 0x40 + i * 0x40 + b];
17714
17715 out <<= 4;
17716 out |= sb;
17717 }
17718 return out >>> 0;
17719};
17720
17721var permuteTable = [
17722 16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22,
17723 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7
17724];
17725
17726exports.permute = function permute(num) {
17727 var out = 0;
17728 for (var i = 0; i < permuteTable.length; i++) {
17729 out <<= 1;
17730 out |= (num >>> permuteTable[i]) & 0x1;
17731 }
17732 return out >>> 0;
17733};
17734
17735exports.padSplit = function padSplit(num, size, group) {
17736 var str = num.toString(2);
17737 while (str.length < size)
17738 str = '0' + str;
17739
17740 var out = [];
17741 for (var i = 0; i < size; i += group)
17742 out.push(str.slice(i, i + group));
17743 return out.join(' ');
17744};
17745
17746},{}],125:[function(require,module,exports){
17747(function (Buffer){
17748var generatePrime = require('./lib/generatePrime')
17749var primes = require('./lib/primes.json')
17750
17751var DH = require('./lib/dh')
17752
17753function getDiffieHellman (mod) {
17754 var prime = new Buffer(primes[mod].prime, 'hex')
17755 var gen = new Buffer(primes[mod].gen, 'hex')
17756
17757 return new DH(prime, gen)
17758}
17759
17760var ENCODINGS = {
17761 'binary': true, 'hex': true, 'base64': true
17762}
17763
17764function createDiffieHellman (prime, enc, generator, genc) {
17765 if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
17766 return createDiffieHellman(prime, 'binary', enc, generator)
17767 }
17768
17769 enc = enc || 'binary'
17770 genc = genc || 'binary'
17771 generator = generator || new Buffer([2])
17772
17773 if (!Buffer.isBuffer(generator)) {
17774 generator = new Buffer(generator, genc)
17775 }
17776
17777 if (typeof prime === 'number') {
17778 return new DH(generatePrime(prime, generator), generator, true)
17779 }
17780
17781 if (!Buffer.isBuffer(prime)) {
17782 prime = new Buffer(prime, enc)
17783 }
17784
17785 return new DH(prime, generator, true)
17786}
17787
17788exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
17789exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman
17790
17791}).call(this,require("buffer").Buffer)
17792},{"./lib/dh":126,"./lib/generatePrime":127,"./lib/primes.json":128,"buffer":110}],126:[function(require,module,exports){
17793(function (Buffer){
17794var BN = require('bn.js');
17795var MillerRabin = require('miller-rabin');
17796var millerRabin = new MillerRabin();
17797var TWENTYFOUR = new BN(24);
17798var ELEVEN = new BN(11);
17799var TEN = new BN(10);
17800var THREE = new BN(3);
17801var SEVEN = new BN(7);
17802var primes = require('./generatePrime');
17803var randomBytes = require('randombytes');
17804module.exports = DH;
17805
17806function setPublicKey(pub, enc) {
17807 enc = enc || 'utf8';
17808 if (!Buffer.isBuffer(pub)) {
17809 pub = new Buffer(pub, enc);
17810 }
17811 this._pub = new BN(pub);
17812 return this;
17813}
17814
17815function setPrivateKey(priv, enc) {
17816 enc = enc || 'utf8';
17817 if (!Buffer.isBuffer(priv)) {
17818 priv = new Buffer(priv, enc);
17819 }
17820 this._priv = new BN(priv);
17821 return this;
17822}
17823
17824var primeCache = {};
17825function checkPrime(prime, generator) {
17826 var gen = generator.toString('hex');
17827 var hex = [gen, prime.toString(16)].join('_');
17828 if (hex in primeCache) {
17829 return primeCache[hex];
17830 }
17831 var error = 0;
17832
17833 if (prime.isEven() ||
17834 !primes.simpleSieve ||
17835 !primes.fermatTest(prime) ||
17836 !millerRabin.test(prime)) {
17837 //not a prime so +1
17838 error += 1;
17839
17840 if (gen === '02' || gen === '05') {
17841 // we'd be able to check the generator
17842 // it would fail so +8
17843 error += 8;
17844 } else {
17845 //we wouldn't be able to test the generator
17846 // so +4
17847 error += 4;
17848 }
17849 primeCache[hex] = error;
17850 return error;
17851 }
17852 if (!millerRabin.test(prime.shrn(1))) {
17853 //not a safe prime
17854 error += 2;
17855 }
17856 var rem;
17857 switch (gen) {
17858 case '02':
17859 if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
17860 // unsuidable generator
17861 error += 8;
17862 }
17863 break;
17864 case '05':
17865 rem = prime.mod(TEN);
17866 if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
17867 // prime mod 10 needs to equal 3 or 7
17868 error += 8;
17869 }
17870 break;
17871 default:
17872 error += 4;
17873 }
17874 primeCache[hex] = error;
17875 return error;
17876}
17877
17878function DH(prime, generator, malleable) {
17879 this.setGenerator(generator);
17880 this.__prime = new BN(prime);
17881 this._prime = BN.mont(this.__prime);
17882 this._primeLen = prime.length;
17883 this._pub = undefined;
17884 this._priv = undefined;
17885 this._primeCode = undefined;
17886 if (malleable) {
17887 this.setPublicKey = setPublicKey;
17888 this.setPrivateKey = setPrivateKey;
17889 } else {
17890 this._primeCode = 8;
17891 }
17892}
17893Object.defineProperty(DH.prototype, 'verifyError', {
17894 enumerable: true,
17895 get: function () {
17896 if (typeof this._primeCode !== 'number') {
17897 this._primeCode = checkPrime(this.__prime, this.__gen);
17898 }
17899 return this._primeCode;
17900 }
17901});
17902DH.prototype.generateKeys = function () {
17903 if (!this._priv) {
17904 this._priv = new BN(randomBytes(this._primeLen));
17905 }
17906 this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
17907 return this.getPublicKey();
17908};
17909
17910DH.prototype.computeSecret = function (other) {
17911 other = new BN(other);
17912 other = other.toRed(this._prime);
17913 var secret = other.redPow(this._priv).fromRed();
17914 var out = new Buffer(secret.toArray());
17915 var prime = this.getPrime();
17916 if (out.length < prime.length) {
17917 var front = new Buffer(prime.length - out.length);
17918 front.fill(0);
17919 out = Buffer.concat([front, out]);
17920 }
17921 return out;
17922};
17923
17924DH.prototype.getPublicKey = function getPublicKey(enc) {
17925 return formatReturnValue(this._pub, enc);
17926};
17927
17928DH.prototype.getPrivateKey = function getPrivateKey(enc) {
17929 return formatReturnValue(this._priv, enc);
17930};
17931
17932DH.prototype.getPrime = function (enc) {
17933 return formatReturnValue(this.__prime, enc);
17934};
17935
17936DH.prototype.getGenerator = function (enc) {
17937 return formatReturnValue(this._gen, enc);
17938};
17939
17940DH.prototype.setGenerator = function (gen, enc) {
17941 enc = enc || 'utf8';
17942 if (!Buffer.isBuffer(gen)) {
17943 gen = new Buffer(gen, enc);
17944 }
17945 this.__gen = gen;
17946 this._gen = new BN(gen);
17947 return this;
17948};
17949
17950function formatReturnValue(bn, enc) {
17951 var buf = new Buffer(bn.toArray());
17952 if (!enc) {
17953 return buf;
17954 } else {
17955 return buf.toString(enc);
17956 }
17957}
17958
17959}).call(this,require("buffer").Buffer)
17960},{"./generatePrime":127,"bn.js":79,"buffer":110,"miller-rabin":166,"randombytes":188}],127:[function(require,module,exports){
17961var randomBytes = require('randombytes');
17962module.exports = findPrime;
17963findPrime.simpleSieve = simpleSieve;
17964findPrime.fermatTest = fermatTest;
17965var BN = require('bn.js');
17966var TWENTYFOUR = new BN(24);
17967var MillerRabin = require('miller-rabin');
17968var millerRabin = new MillerRabin();
17969var ONE = new BN(1);
17970var TWO = new BN(2);
17971var FIVE = new BN(5);
17972var SIXTEEN = new BN(16);
17973var EIGHT = new BN(8);
17974var TEN = new BN(10);
17975var THREE = new BN(3);
17976var SEVEN = new BN(7);
17977var ELEVEN = new BN(11);
17978var FOUR = new BN(4);
17979var TWELVE = new BN(12);
17980var primes = null;
17981
17982function _getPrimes() {
17983 if (primes !== null)
17984 return primes;
17985
17986 var limit = 0x100000;
17987 var res = [];
17988 res[0] = 2;
17989 for (var i = 1, k = 3; k < limit; k += 2) {
17990 var sqrt = Math.ceil(Math.sqrt(k));
17991 for (var j = 0; j < i && res[j] <= sqrt; j++)
17992 if (k % res[j] === 0)
17993 break;
17994
17995 if (i !== j && res[j] <= sqrt)
17996 continue;
17997
17998 res[i++] = k;
17999 }
18000 primes = res;
18001 return res;
18002}
18003
18004function simpleSieve(p) {
18005 var primes = _getPrimes();
18006
18007 for (var i = 0; i < primes.length; i++)
18008 if (p.modn(primes[i]) === 0) {
18009 if (p.cmpn(primes[i]) === 0) {
18010 return true;
18011 } else {
18012 return false;
18013 }
18014 }
18015
18016 return true;
18017}
18018
18019function fermatTest(p) {
18020 var red = BN.mont(p);
18021 return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
18022}
18023
18024function findPrime(bits, gen) {
18025 if (bits < 16) {
18026 // this is what openssl does
18027 if (gen === 2 || gen === 5) {
18028 return new BN([0x8c, 0x7b]);
18029 } else {
18030 return new BN([0x8c, 0x27]);
18031 }
18032 }
18033 gen = new BN(gen);
18034
18035 var num, n2;
18036
18037 while (true) {
18038 num = new BN(randomBytes(Math.ceil(bits / 8)));
18039 while (num.bitLength() > bits) {
18040 num.ishrn(1);
18041 }
18042 if (num.isEven()) {
18043 num.iadd(ONE);
18044 }
18045 if (!num.testn(1)) {
18046 num.iadd(TWO);
18047 }
18048 if (!gen.cmp(TWO)) {
18049 while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
18050 num.iadd(FOUR);
18051 }
18052 } else if (!gen.cmp(FIVE)) {
18053 while (num.mod(TEN).cmp(THREE)) {
18054 num.iadd(FOUR);
18055 }
18056 }
18057 n2 = num.shrn(1);
18058 if (simpleSieve(n2) && simpleSieve(num) &&
18059 fermatTest(n2) && fermatTest(num) &&
18060 millerRabin.test(n2) && millerRabin.test(num)) {
18061 return num;
18062 }
18063 }
18064
18065}
18066
18067},{"bn.js":79,"miller-rabin":166,"randombytes":188}],128:[function(require,module,exports){
18068module.exports={
18069 "modp1": {
18070 "gen": "02",
18071 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
18072 },
18073 "modp2": {
18074 "gen": "02",
18075 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
18076 },
18077 "modp5": {
18078 "gen": "02",
18079 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
18080 },
18081 "modp14": {
18082 "gen": "02",
18083 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
18084 },
18085 "modp15": {
18086 "gen": "02",
18087 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
18088 },
18089 "modp16": {
18090 "gen": "02",
18091 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
18092 },
18093 "modp17": {
18094 "gen": "02",
18095 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
18096 },
18097 "modp18": {
18098 "gen": "02",
18099 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
18100 }
18101}
18102},{}],129:[function(require,module,exports){
18103'use strict';
18104
18105var elliptic = exports;
18106
18107elliptic.version = require('../package.json').version;
18108elliptic.utils = require('./elliptic/utils');
18109elliptic.rand = require('brorand');
18110elliptic.curve = require('./elliptic/curve');
18111elliptic.curves = require('./elliptic/curves');
18112
18113// Protocols
18114elliptic.ec = require('./elliptic/ec');
18115elliptic.eddsa = require('./elliptic/eddsa');
18116
18117},{"../package.json":144,"./elliptic/curve":132,"./elliptic/curves":135,"./elliptic/ec":136,"./elliptic/eddsa":139,"./elliptic/utils":143,"brorand":80}],130:[function(require,module,exports){
18118'use strict';
18119
18120var BN = require('bn.js');
18121var utils = require('../utils');
18122var getNAF = utils.getNAF;
18123var getJSF = utils.getJSF;
18124var assert = utils.assert;
18125
18126function BaseCurve(type, conf) {
18127 this.type = type;
18128 this.p = new BN(conf.p, 16);
18129
18130 // Use Montgomery, when there is no fast reduction for the prime
18131 this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
18132
18133 // Useful for many curves
18134 this.zero = new BN(0).toRed(this.red);
18135 this.one = new BN(1).toRed(this.red);
18136 this.two = new BN(2).toRed(this.red);
18137
18138 // Curve configuration, optional
18139 this.n = conf.n && new BN(conf.n, 16);
18140 this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
18141
18142 // Temporary arrays
18143 this._wnafT1 = new Array(4);
18144 this._wnafT2 = new Array(4);
18145 this._wnafT3 = new Array(4);
18146 this._wnafT4 = new Array(4);
18147
18148 // Generalized Greg Maxwell's trick
18149 var adjustCount = this.n && this.p.div(this.n);
18150 if (!adjustCount || adjustCount.cmpn(100) > 0) {
18151 this.redN = null;
18152 } else {
18153 this._maxwellTrick = true;
18154 this.redN = this.n.toRed(this.red);
18155 }
18156}
18157module.exports = BaseCurve;
18158
18159BaseCurve.prototype.point = function point() {
18160 throw new Error('Not implemented');
18161};
18162
18163BaseCurve.prototype.validate = function validate() {
18164 throw new Error('Not implemented');
18165};
18166
18167BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
18168 assert(p.precomputed);
18169 var doubles = p._getDoubles();
18170
18171 var naf = getNAF(k, 1);
18172 var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
18173 I /= 3;
18174
18175 // Translate into more windowed form
18176 var repr = [];
18177 for (var j = 0; j < naf.length; j += doubles.step) {
18178 var nafW = 0;
18179 for (var k = j + doubles.step - 1; k >= j; k--)
18180 nafW = (nafW << 1) + naf[k];
18181 repr.push(nafW);
18182 }
18183
18184 var a = this.jpoint(null, null, null);
18185 var b = this.jpoint(null, null, null);
18186 for (var i = I; i > 0; i--) {
18187 for (var j = 0; j < repr.length; j++) {
18188 var nafW = repr[j];
18189 if (nafW === i)
18190 b = b.mixedAdd(doubles.points[j]);
18191 else if (nafW === -i)
18192 b = b.mixedAdd(doubles.points[j].neg());
18193 }
18194 a = a.add(b);
18195 }
18196 return a.toP();
18197};
18198
18199BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
18200 var w = 4;
18201
18202 // Precompute window
18203 var nafPoints = p._getNAFPoints(w);
18204 w = nafPoints.wnd;
18205 var wnd = nafPoints.points;
18206
18207 // Get NAF form
18208 var naf = getNAF(k, w);
18209
18210 // Add `this`*(N+1) for every w-NAF index
18211 var acc = this.jpoint(null, null, null);
18212 for (var i = naf.length - 1; i >= 0; i--) {
18213 // Count zeroes
18214 for (var k = 0; i >= 0 && naf[i] === 0; i--)
18215 k++;
18216 if (i >= 0)
18217 k++;
18218 acc = acc.dblp(k);
18219
18220 if (i < 0)
18221 break;
18222 var z = naf[i];
18223 assert(z !== 0);
18224 if (p.type === 'affine') {
18225 // J +- P
18226 if (z > 0)
18227 acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
18228 else
18229 acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
18230 } else {
18231 // J +- J
18232 if (z > 0)
18233 acc = acc.add(wnd[(z - 1) >> 1]);
18234 else
18235 acc = acc.add(wnd[(-z - 1) >> 1].neg());
18236 }
18237 }
18238 return p.type === 'affine' ? acc.toP() : acc;
18239};
18240
18241BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
18242 points,
18243 coeffs,
18244 len,
18245 jacobianResult) {
18246 var wndWidth = this._wnafT1;
18247 var wnd = this._wnafT2;
18248 var naf = this._wnafT3;
18249
18250 // Fill all arrays
18251 var max = 0;
18252 for (var i = 0; i < len; i++) {
18253 var p = points[i];
18254 var nafPoints = p._getNAFPoints(defW);
18255 wndWidth[i] = nafPoints.wnd;
18256 wnd[i] = nafPoints.points;
18257 }
18258
18259 // Comb small window NAFs
18260 for (var i = len - 1; i >= 1; i -= 2) {
18261 var a = i - 1;
18262 var b = i;
18263 if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
18264 naf[a] = getNAF(coeffs[a], wndWidth[a]);
18265 naf[b] = getNAF(coeffs[b], wndWidth[b]);
18266 max = Math.max(naf[a].length, max);
18267 max = Math.max(naf[b].length, max);
18268 continue;
18269 }
18270
18271 var comb = [
18272 points[a], /* 1 */
18273 null, /* 3 */
18274 null, /* 5 */
18275 points[b] /* 7 */
18276 ];
18277
18278 // Try to avoid Projective points, if possible
18279 if (points[a].y.cmp(points[b].y) === 0) {
18280 comb[1] = points[a].add(points[b]);
18281 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
18282 } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
18283 comb[1] = points[a].toJ().mixedAdd(points[b]);
18284 comb[2] = points[a].add(points[b].neg());
18285 } else {
18286 comb[1] = points[a].toJ().mixedAdd(points[b]);
18287 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
18288 }
18289
18290 var index = [
18291 -3, /* -1 -1 */
18292 -1, /* -1 0 */
18293 -5, /* -1 1 */
18294 -7, /* 0 -1 */
18295 0, /* 0 0 */
18296 7, /* 0 1 */
18297 5, /* 1 -1 */
18298 1, /* 1 0 */
18299 3 /* 1 1 */
18300 ];
18301
18302 var jsf = getJSF(coeffs[a], coeffs[b]);
18303 max = Math.max(jsf[0].length, max);
18304 naf[a] = new Array(max);
18305 naf[b] = new Array(max);
18306 for (var j = 0; j < max; j++) {
18307 var ja = jsf[0][j] | 0;
18308 var jb = jsf[1][j] | 0;
18309
18310 naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
18311 naf[b][j] = 0;
18312 wnd[a] = comb;
18313 }
18314 }
18315
18316 var acc = this.jpoint(null, null, null);
18317 var tmp = this._wnafT4;
18318 for (var i = max; i >= 0; i--) {
18319 var k = 0;
18320
18321 while (i >= 0) {
18322 var zero = true;
18323 for (var j = 0; j < len; j++) {
18324 tmp[j] = naf[j][i] | 0;
18325 if (tmp[j] !== 0)
18326 zero = false;
18327 }
18328 if (!zero)
18329 break;
18330 k++;
18331 i--;
18332 }
18333 if (i >= 0)
18334 k++;
18335 acc = acc.dblp(k);
18336 if (i < 0)
18337 break;
18338
18339 for (var j = 0; j < len; j++) {
18340 var z = tmp[j];
18341 var p;
18342 if (z === 0)
18343 continue;
18344 else if (z > 0)
18345 p = wnd[j][(z - 1) >> 1];
18346 else if (z < 0)
18347 p = wnd[j][(-z - 1) >> 1].neg();
18348
18349 if (p.type === 'affine')
18350 acc = acc.mixedAdd(p);
18351 else
18352 acc = acc.add(p);
18353 }
18354 }
18355 // Zeroify references
18356 for (var i = 0; i < len; i++)
18357 wnd[i] = null;
18358
18359 if (jacobianResult)
18360 return acc;
18361 else
18362 return acc.toP();
18363};
18364
18365function BasePoint(curve, type) {
18366 this.curve = curve;
18367 this.type = type;
18368 this.precomputed = null;
18369}
18370BaseCurve.BasePoint = BasePoint;
18371
18372BasePoint.prototype.eq = function eq(/*other*/) {
18373 throw new Error('Not implemented');
18374};
18375
18376BasePoint.prototype.validate = function validate() {
18377 return this.curve.validate(this);
18378};
18379
18380BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
18381 bytes = utils.toArray(bytes, enc);
18382
18383 var len = this.p.byteLength();
18384
18385 // uncompressed, hybrid-odd, hybrid-even
18386 if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
18387 bytes.length - 1 === 2 * len) {
18388 if (bytes[0] === 0x06)
18389 assert(bytes[bytes.length - 1] % 2 === 0);
18390 else if (bytes[0] === 0x07)
18391 assert(bytes[bytes.length - 1] % 2 === 1);
18392
18393 var res = this.point(bytes.slice(1, 1 + len),
18394 bytes.slice(1 + len, 1 + 2 * len));
18395
18396 return res;
18397 } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
18398 bytes.length - 1 === len) {
18399 return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
18400 }
18401 throw new Error('Unknown point format');
18402};
18403
18404BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
18405 return this.encode(enc, true);
18406};
18407
18408BasePoint.prototype._encode = function _encode(compact) {
18409 var len = this.curve.p.byteLength();
18410 var x = this.getX().toArray('be', len);
18411
18412 if (compact)
18413 return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
18414
18415 return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
18416};
18417
18418BasePoint.prototype.encode = function encode(enc, compact) {
18419 return utils.encode(this._encode(compact), enc);
18420};
18421
18422BasePoint.prototype.precompute = function precompute(power) {
18423 if (this.precomputed)
18424 return this;
18425
18426 var precomputed = {
18427 doubles: null,
18428 naf: null,
18429 beta: null
18430 };
18431 precomputed.naf = this._getNAFPoints(8);
18432 precomputed.doubles = this._getDoubles(4, power);
18433 precomputed.beta = this._getBeta();
18434 this.precomputed = precomputed;
18435
18436 return this;
18437};
18438
18439BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
18440 if (!this.precomputed)
18441 return false;
18442
18443 var doubles = this.precomputed.doubles;
18444 if (!doubles)
18445 return false;
18446
18447 return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
18448};
18449
18450BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
18451 if (this.precomputed && this.precomputed.doubles)
18452 return this.precomputed.doubles;
18453
18454 var doubles = [ this ];
18455 var acc = this;
18456 for (var i = 0; i < power; i += step) {
18457 for (var j = 0; j < step; j++)
18458 acc = acc.dbl();
18459 doubles.push(acc);
18460 }
18461 return {
18462 step: step,
18463 points: doubles
18464 };
18465};
18466
18467BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
18468 if (this.precomputed && this.precomputed.naf)
18469 return this.precomputed.naf;
18470
18471 var res = [ this ];
18472 var max = (1 << wnd) - 1;
18473 var dbl = max === 1 ? null : this.dbl();
18474 for (var i = 1; i < max; i++)
18475 res[i] = res[i - 1].add(dbl);
18476 return {
18477 wnd: wnd,
18478 points: res
18479 };
18480};
18481
18482BasePoint.prototype._getBeta = function _getBeta() {
18483 return null;
18484};
18485
18486BasePoint.prototype.dblp = function dblp(k) {
18487 var r = this;
18488 for (var i = 0; i < k; i++)
18489 r = r.dbl();
18490 return r;
18491};
18492
18493},{"../utils":143,"bn.js":79}],131:[function(require,module,exports){
18494'use strict';
18495
18496var utils = require('../utils');
18497var BN = require('bn.js');
18498var inherits = require('inherits');
18499var Base = require('./base');
18500
18501var assert = utils.assert;
18502
18503function EdwardsCurve(conf) {
18504 // NOTE: Important as we are creating point in Base.call()
18505 this.twisted = (conf.a | 0) !== 1;
18506 this.mOneA = this.twisted && (conf.a | 0) === -1;
18507 this.extended = this.mOneA;
18508
18509 Base.call(this, 'edwards', conf);
18510
18511 this.a = new BN(conf.a, 16).umod(this.red.m);
18512 this.a = this.a.toRed(this.red);
18513 this.c = new BN(conf.c, 16).toRed(this.red);
18514 this.c2 = this.c.redSqr();
18515 this.d = new BN(conf.d, 16).toRed(this.red);
18516 this.dd = this.d.redAdd(this.d);
18517
18518 assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18519 this.oneC = (conf.c | 0) === 1;
18520}
18521inherits(EdwardsCurve, Base);
18522module.exports = EdwardsCurve;
18523
18524EdwardsCurve.prototype._mulA = function _mulA(num) {
18525 if (this.mOneA)
18526 return num.redNeg();
18527 else
18528 return this.a.redMul(num);
18529};
18530
18531EdwardsCurve.prototype._mulC = function _mulC(num) {
18532 if (this.oneC)
18533 return num;
18534 else
18535 return this.c.redMul(num);
18536};
18537
18538// Just for compatibility with Short curve
18539EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
18540 return this.point(x, y, z, t);
18541};
18542
18543EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
18544 x = new BN(x, 16);
18545 if (!x.red)
18546 x = x.toRed(this.red);
18547
18548 var x2 = x.redSqr();
18549 var rhs = this.c2.redSub(this.a.redMul(x2));
18550 var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
18551
18552 var y2 = rhs.redMul(lhs.redInvm());
18553 var y = y2.redSqrt();
18554 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
18555 throw new Error('invalid point');
18556
18557 var isOdd = y.fromRed().isOdd();
18558 if (odd && !isOdd || !odd && isOdd)
18559 y = y.redNeg();
18560
18561 return this.point(x, y);
18562};
18563
18564EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
18565 y = new BN(y, 16);
18566 if (!y.red)
18567 y = y.toRed(this.red);
18568
18569 // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
18570 var y2 = y.redSqr();
18571 var lhs = y2.redSub(this.c2);
18572 var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
18573 var x2 = lhs.redMul(rhs.redInvm());
18574
18575 if (x2.cmp(this.zero) === 0) {
18576 if (odd)
18577 throw new Error('invalid point');
18578 else
18579 return this.point(this.zero, y);
18580 }
18581
18582 var x = x2.redSqrt();
18583 if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
18584 throw new Error('invalid point');
18585
18586 if (x.fromRed().isOdd() !== odd)
18587 x = x.redNeg();
18588
18589 return this.point(x, y);
18590};
18591
18592EdwardsCurve.prototype.validate = function validate(point) {
18593 if (point.isInfinity())
18594 return true;
18595
18596 // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
18597 point.normalize();
18598
18599 var x2 = point.x.redSqr();
18600 var y2 = point.y.redSqr();
18601 var lhs = x2.redMul(this.a).redAdd(y2);
18602 var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
18603
18604 return lhs.cmp(rhs) === 0;
18605};
18606
18607function Point(curve, x, y, z, t) {
18608 Base.BasePoint.call(this, curve, 'projective');
18609 if (x === null && y === null && z === null) {
18610 this.x = this.curve.zero;
18611 this.y = this.curve.one;
18612 this.z = this.curve.one;
18613 this.t = this.curve.zero;
18614 this.zOne = true;
18615 } else {
18616 this.x = new BN(x, 16);
18617 this.y = new BN(y, 16);
18618 this.z = z ? new BN(z, 16) : this.curve.one;
18619 this.t = t && new BN(t, 16);
18620 if (!this.x.red)
18621 this.x = this.x.toRed(this.curve.red);
18622 if (!this.y.red)
18623 this.y = this.y.toRed(this.curve.red);
18624 if (!this.z.red)
18625 this.z = this.z.toRed(this.curve.red);
18626 if (this.t && !this.t.red)
18627 this.t = this.t.toRed(this.curve.red);
18628 this.zOne = this.z === this.curve.one;
18629
18630 // Use extended coordinates
18631 if (this.curve.extended && !this.t) {
18632 this.t = this.x.redMul(this.y);
18633 if (!this.zOne)
18634 this.t = this.t.redMul(this.z.redInvm());
18635 }
18636 }
18637}
18638inherits(Point, Base.BasePoint);
18639
18640EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
18641 return Point.fromJSON(this, obj);
18642};
18643
18644EdwardsCurve.prototype.point = function point(x, y, z, t) {
18645 return new Point(this, x, y, z, t);
18646};
18647
18648Point.fromJSON = function fromJSON(curve, obj) {
18649 return new Point(curve, obj[0], obj[1], obj[2]);
18650};
18651
18652Point.prototype.inspect = function inspect() {
18653 if (this.isInfinity())
18654 return '<EC Point Infinity>';
18655 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
18656 ' y: ' + this.y.fromRed().toString(16, 2) +
18657 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
18658};
18659
18660Point.prototype.isInfinity = function isInfinity() {
18661 // XXX This code assumes that zero is always zero in red
18662 return this.x.cmpn(0) === 0 &&
18663 (this.y.cmp(this.z) === 0 ||
18664 (this.zOne && this.y.cmp(this.curve.c) === 0));
18665};
18666
18667Point.prototype._extDbl = function _extDbl() {
18668 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
18669 // #doubling-dbl-2008-hwcd
18670 // 4M + 4S
18671
18672 // A = X1^2
18673 var a = this.x.redSqr();
18674 // B = Y1^2
18675 var b = this.y.redSqr();
18676 // C = 2 * Z1^2
18677 var c = this.z.redSqr();
18678 c = c.redIAdd(c);
18679 // D = a * A
18680 var d = this.curve._mulA(a);
18681 // E = (X1 + Y1)^2 - A - B
18682 var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
18683 // G = D + B
18684 var g = d.redAdd(b);
18685 // F = G - C
18686 var f = g.redSub(c);
18687 // H = D - B
18688 var h = d.redSub(b);
18689 // X3 = E * F
18690 var nx = e.redMul(f);
18691 // Y3 = G * H
18692 var ny = g.redMul(h);
18693 // T3 = E * H
18694 var nt = e.redMul(h);
18695 // Z3 = F * G
18696 var nz = f.redMul(g);
18697 return this.curve.point(nx, ny, nz, nt);
18698};
18699
18700Point.prototype._projDbl = function _projDbl() {
18701 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
18702 // #doubling-dbl-2008-bbjlp
18703 // #doubling-dbl-2007-bl
18704 // and others
18705 // Generally 3M + 4S or 2M + 4S
18706
18707 // B = (X1 + Y1)^2
18708 var b = this.x.redAdd(this.y).redSqr();
18709 // C = X1^2
18710 var c = this.x.redSqr();
18711 // D = Y1^2
18712 var d = this.y.redSqr();
18713
18714 var nx;
18715 var ny;
18716 var nz;
18717 if (this.curve.twisted) {
18718 // E = a * C
18719 var e = this.curve._mulA(c);
18720 // F = E + D
18721 var f = e.redAdd(d);
18722 if (this.zOne) {
18723 // X3 = (B - C - D) * (F - 2)
18724 nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
18725 // Y3 = F * (E - D)
18726 ny = f.redMul(e.redSub(d));
18727 // Z3 = F^2 - 2 * F
18728 nz = f.redSqr().redSub(f).redSub(f);
18729 } else {
18730 // H = Z1^2
18731 var h = this.z.redSqr();
18732 // J = F - 2 * H
18733 var j = f.redSub(h).redISub(h);
18734 // X3 = (B-C-D)*J
18735 nx = b.redSub(c).redISub(d).redMul(j);
18736 // Y3 = F * (E - D)
18737 ny = f.redMul(e.redSub(d));
18738 // Z3 = F * J
18739 nz = f.redMul(j);
18740 }
18741 } else {
18742 // E = C + D
18743 var e = c.redAdd(d);
18744 // H = (c * Z1)^2
18745 var h = this.curve._mulC(this.z).redSqr();
18746 // J = E - 2 * H
18747 var j = e.redSub(h).redSub(h);
18748 // X3 = c * (B - E) * J
18749 nx = this.curve._mulC(b.redISub(e)).redMul(j);
18750 // Y3 = c * E * (C - D)
18751 ny = this.curve._mulC(e).redMul(c.redISub(d));
18752 // Z3 = E * J
18753 nz = e.redMul(j);
18754 }
18755 return this.curve.point(nx, ny, nz);
18756};
18757
18758Point.prototype.dbl = function dbl() {
18759 if (this.isInfinity())
18760 return this;
18761
18762 // Double in extended coordinates
18763 if (this.curve.extended)
18764 return this._extDbl();
18765 else
18766 return this._projDbl();
18767};
18768
18769Point.prototype._extAdd = function _extAdd(p) {
18770 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
18771 // #addition-add-2008-hwcd-3
18772 // 8M
18773
18774 // A = (Y1 - X1) * (Y2 - X2)
18775 var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
18776 // B = (Y1 + X1) * (Y2 + X2)
18777 var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
18778 // C = T1 * k * T2
18779 var c = this.t.redMul(this.curve.dd).redMul(p.t);
18780 // D = Z1 * 2 * Z2
18781 var d = this.z.redMul(p.z.redAdd(p.z));
18782 // E = B - A
18783 var e = b.redSub(a);
18784 // F = D - C
18785 var f = d.redSub(c);
18786 // G = D + C
18787 var g = d.redAdd(c);
18788 // H = B + A
18789 var h = b.redAdd(a);
18790 // X3 = E * F
18791 var nx = e.redMul(f);
18792 // Y3 = G * H
18793 var ny = g.redMul(h);
18794 // T3 = E * H
18795 var nt = e.redMul(h);
18796 // Z3 = F * G
18797 var nz = f.redMul(g);
18798 return this.curve.point(nx, ny, nz, nt);
18799};
18800
18801Point.prototype._projAdd = function _projAdd(p) {
18802 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
18803 // #addition-add-2008-bbjlp
18804 // #addition-add-2007-bl
18805 // 10M + 1S
18806
18807 // A = Z1 * Z2
18808 var a = this.z.redMul(p.z);
18809 // B = A^2
18810 var b = a.redSqr();
18811 // C = X1 * X2
18812 var c = this.x.redMul(p.x);
18813 // D = Y1 * Y2
18814 var d = this.y.redMul(p.y);
18815 // E = d * C * D
18816 var e = this.curve.d.redMul(c).redMul(d);
18817 // F = B - E
18818 var f = b.redSub(e);
18819 // G = B + E
18820 var g = b.redAdd(e);
18821 // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
18822 var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
18823 var nx = a.redMul(f).redMul(tmp);
18824 var ny;
18825 var nz;
18826 if (this.curve.twisted) {
18827 // Y3 = A * G * (D - a * C)
18828 ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
18829 // Z3 = F * G
18830 nz = f.redMul(g);
18831 } else {
18832 // Y3 = A * G * (D - C)
18833 ny = a.redMul(g).redMul(d.redSub(c));
18834 // Z3 = c * F * G
18835 nz = this.curve._mulC(f).redMul(g);
18836 }
18837 return this.curve.point(nx, ny, nz);
18838};
18839
18840Point.prototype.add = function add(p) {
18841 if (this.isInfinity())
18842 return p;
18843 if (p.isInfinity())
18844 return this;
18845
18846 if (this.curve.extended)
18847 return this._extAdd(p);
18848 else
18849 return this._projAdd(p);
18850};
18851
18852Point.prototype.mul = function mul(k) {
18853 if (this._hasDoubles(k))
18854 return this.curve._fixedNafMul(this, k);
18855 else
18856 return this.curve._wnafMul(this, k);
18857};
18858
18859Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
18860 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false);
18861};
18862
18863Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
18864 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true);
18865};
18866
18867Point.prototype.normalize = function normalize() {
18868 if (this.zOne)
18869 return this;
18870
18871 // Normalize coordinates
18872 var zi = this.z.redInvm();
18873 this.x = this.x.redMul(zi);
18874 this.y = this.y.redMul(zi);
18875 if (this.t)
18876 this.t = this.t.redMul(zi);
18877 this.z = this.curve.one;
18878 this.zOne = true;
18879 return this;
18880};
18881
18882Point.prototype.neg = function neg() {
18883 return this.curve.point(this.x.redNeg(),
18884 this.y,
18885 this.z,
18886 this.t && this.t.redNeg());
18887};
18888
18889Point.prototype.getX = function getX() {
18890 this.normalize();
18891 return this.x.fromRed();
18892};
18893
18894Point.prototype.getY = function getY() {
18895 this.normalize();
18896 return this.y.fromRed();
18897};
18898
18899Point.prototype.eq = function eq(other) {
18900 return this === other ||
18901 this.getX().cmp(other.getX()) === 0 &&
18902 this.getY().cmp(other.getY()) === 0;
18903};
18904
18905Point.prototype.eqXToP = function eqXToP(x) {
18906 var rx = x.toRed(this.curve.red).redMul(this.z);
18907 if (this.x.cmp(rx) === 0)
18908 return true;
18909
18910 var xc = x.clone();
18911 var t = this.curve.redN.redMul(this.z);
18912 for (;;) {
18913 xc.iadd(this.curve.n);
18914 if (xc.cmp(this.curve.p) >= 0)
18915 return false;
18916
18917 rx.redIAdd(t);
18918 if (this.x.cmp(rx) === 0)
18919 return true;
18920 }
18921};
18922
18923// Compatibility with BaseCurve
18924Point.prototype.toP = Point.prototype.normalize;
18925Point.prototype.mixedAdd = Point.prototype.add;
18926
18927},{"../utils":143,"./base":130,"bn.js":79,"inherits":162}],132:[function(require,module,exports){
18928'use strict';
18929
18930var curve = exports;
18931
18932curve.base = require('./base');
18933curve.short = require('./short');
18934curve.mont = require('./mont');
18935curve.edwards = require('./edwards');
18936
18937},{"./base":130,"./edwards":131,"./mont":133,"./short":134}],133:[function(require,module,exports){
18938'use strict';
18939
18940var BN = require('bn.js');
18941var inherits = require('inherits');
18942var Base = require('./base');
18943
18944var utils = require('../utils');
18945
18946function MontCurve(conf) {
18947 Base.call(this, 'mont', conf);
18948
18949 this.a = new BN(conf.a, 16).toRed(this.red);
18950 this.b = new BN(conf.b, 16).toRed(this.red);
18951 this.i4 = new BN(4).toRed(this.red).redInvm();
18952 this.two = new BN(2).toRed(this.red);
18953 this.a24 = this.i4.redMul(this.a.redAdd(this.two));
18954}
18955inherits(MontCurve, Base);
18956module.exports = MontCurve;
18957
18958MontCurve.prototype.validate = function validate(point) {
18959 var x = point.normalize().x;
18960 var x2 = x.redSqr();
18961 var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
18962 var y = rhs.redSqrt();
18963
18964 return y.redSqr().cmp(rhs) === 0;
18965};
18966
18967function Point(curve, x, z) {
18968 Base.BasePoint.call(this, curve, 'projective');
18969 if (x === null && z === null) {
18970 this.x = this.curve.one;
18971 this.z = this.curve.zero;
18972 } else {
18973 this.x = new BN(x, 16);
18974 this.z = new BN(z, 16);
18975 if (!this.x.red)
18976 this.x = this.x.toRed(this.curve.red);
18977 if (!this.z.red)
18978 this.z = this.z.toRed(this.curve.red);
18979 }
18980}
18981inherits(Point, Base.BasePoint);
18982
18983MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
18984 return this.point(utils.toArray(bytes, enc), 1);
18985};
18986
18987MontCurve.prototype.point = function point(x, z) {
18988 return new Point(this, x, z);
18989};
18990
18991MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
18992 return Point.fromJSON(this, obj);
18993};
18994
18995Point.prototype.precompute = function precompute() {
18996 // No-op
18997};
18998
18999Point.prototype._encode = function _encode() {
19000 return this.getX().toArray('be', this.curve.p.byteLength());
19001};
19002
19003Point.fromJSON = function fromJSON(curve, obj) {
19004 return new Point(curve, obj[0], obj[1] || curve.one);
19005};
19006
19007Point.prototype.inspect = function inspect() {
19008 if (this.isInfinity())
19009 return '<EC Point Infinity>';
19010 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
19011 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
19012};
19013
19014Point.prototype.isInfinity = function isInfinity() {
19015 // XXX This code assumes that zero is always zero in red
19016 return this.z.cmpn(0) === 0;
19017};
19018
19019Point.prototype.dbl = function dbl() {
19020 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
19021 // 2M + 2S + 4A
19022
19023 // A = X1 + Z1
19024 var a = this.x.redAdd(this.z);
19025 // AA = A^2
19026 var aa = a.redSqr();
19027 // B = X1 - Z1
19028 var b = this.x.redSub(this.z);
19029 // BB = B^2
19030 var bb = b.redSqr();
19031 // C = AA - BB
19032 var c = aa.redSub(bb);
19033 // X3 = AA * BB
19034 var nx = aa.redMul(bb);
19035 // Z3 = C * (BB + A24 * C)
19036 var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
19037 return this.curve.point(nx, nz);
19038};
19039
19040Point.prototype.add = function add() {
19041 throw new Error('Not supported on Montgomery curve');
19042};
19043
19044Point.prototype.diffAdd = function diffAdd(p, diff) {
19045 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
19046 // 4M + 2S + 6A
19047
19048 // A = X2 + Z2
19049 var a = this.x.redAdd(this.z);
19050 // B = X2 - Z2
19051 var b = this.x.redSub(this.z);
19052 // C = X3 + Z3
19053 var c = p.x.redAdd(p.z);
19054 // D = X3 - Z3
19055 var d = p.x.redSub(p.z);
19056 // DA = D * A
19057 var da = d.redMul(a);
19058 // CB = C * B
19059 var cb = c.redMul(b);
19060 // X5 = Z1 * (DA + CB)^2
19061 var nx = diff.z.redMul(da.redAdd(cb).redSqr());
19062 // Z5 = X1 * (DA - CB)^2
19063 var nz = diff.x.redMul(da.redISub(cb).redSqr());
19064 return this.curve.point(nx, nz);
19065};
19066
19067Point.prototype.mul = function mul(k) {
19068 var t = k.clone();
19069 var a = this; // (N / 2) * Q + Q
19070 var b = this.curve.point(null, null); // (N / 2) * Q
19071 var c = this; // Q
19072
19073 for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
19074 bits.push(t.andln(1));
19075
19076 for (var i = bits.length - 1; i >= 0; i--) {
19077 if (bits[i] === 0) {
19078 // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
19079 a = a.diffAdd(b, c);
19080 // N * Q = 2 * ((N / 2) * Q + Q))
19081 b = b.dbl();
19082 } else {
19083 // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
19084 b = a.diffAdd(b, c);
19085 // N * Q + Q = 2 * ((N / 2) * Q + Q)
19086 a = a.dbl();
19087 }
19088 }
19089 return b;
19090};
19091
19092Point.prototype.mulAdd = function mulAdd() {
19093 throw new Error('Not supported on Montgomery curve');
19094};
19095
19096Point.prototype.jumlAdd = function jumlAdd() {
19097 throw new Error('Not supported on Montgomery curve');
19098};
19099
19100Point.prototype.eq = function eq(other) {
19101 return this.getX().cmp(other.getX()) === 0;
19102};
19103
19104Point.prototype.normalize = function normalize() {
19105 this.x = this.x.redMul(this.z.redInvm());
19106 this.z = this.curve.one;
19107 return this;
19108};
19109
19110Point.prototype.getX = function getX() {
19111 // Normalize coordinates
19112 this.normalize();
19113
19114 return this.x.fromRed();
19115};
19116
19117},{"../utils":143,"./base":130,"bn.js":79,"inherits":162}],134:[function(require,module,exports){
19118'use strict';
19119
19120var utils = require('../utils');
19121var BN = require('bn.js');
19122var inherits = require('inherits');
19123var Base = require('./base');
19124
19125var assert = utils.assert;
19126
19127function ShortCurve(conf) {
19128 Base.call(this, 'short', conf);
19129
19130 this.a = new BN(conf.a, 16).toRed(this.red);
19131 this.b = new BN(conf.b, 16).toRed(this.red);
19132 this.tinv = this.two.redInvm();
19133
19134 this.zeroA = this.a.fromRed().cmpn(0) === 0;
19135 this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
19136
19137 // If the curve is endomorphic, precalculate beta and lambda
19138 this.endo = this._getEndomorphism(conf);
19139 this._endoWnafT1 = new Array(4);
19140 this._endoWnafT2 = new Array(4);
19141}
19142inherits(ShortCurve, Base);
19143module.exports = ShortCurve;
19144
19145ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
19146 // No efficient endomorphism
19147 if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
19148 return;
19149
19150 // Compute beta and lambda, that lambda * P = (beta * Px; Py)
19151 var beta;
19152 var lambda;
19153 if (conf.beta) {
19154 beta = new BN(conf.beta, 16).toRed(this.red);
19155 } else {
19156 var betas = this._getEndoRoots(this.p);
19157 // Choose the smallest beta
19158 beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
19159 beta = beta.toRed(this.red);
19160 }
19161 if (conf.lambda) {
19162 lambda = new BN(conf.lambda, 16);
19163 } else {
19164 // Choose the lambda that is matching selected beta
19165 var lambdas = this._getEndoRoots(this.n);
19166 if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
19167 lambda = lambdas[0];
19168 } else {
19169 lambda = lambdas[1];
19170 assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
19171 }
19172 }
19173
19174 // Get basis vectors, used for balanced length-two representation
19175 var basis;
19176 if (conf.basis) {
19177 basis = conf.basis.map(function(vec) {
19178 return {
19179 a: new BN(vec.a, 16),
19180 b: new BN(vec.b, 16)
19181 };
19182 });
19183 } else {
19184 basis = this._getEndoBasis(lambda);
19185 }
19186
19187 return {
19188 beta: beta,
19189 lambda: lambda,
19190 basis: basis
19191 };
19192};
19193
19194ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
19195 // Find roots of for x^2 + x + 1 in F
19196 // Root = (-1 +- Sqrt(-3)) / 2
19197 //
19198 var red = num === this.p ? this.red : BN.mont(num);
19199 var tinv = new BN(2).toRed(red).redInvm();
19200 var ntinv = tinv.redNeg();
19201
19202 var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
19203
19204 var l1 = ntinv.redAdd(s).fromRed();
19205 var l2 = ntinv.redSub(s).fromRed();
19206 return [ l1, l2 ];
19207};
19208
19209ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
19210 // aprxSqrt >= sqrt(this.n)
19211 var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
19212
19213 // 3.74
19214 // Run EGCD, until r(L + 1) < aprxSqrt
19215 var u = lambda;
19216 var v = this.n.clone();
19217 var x1 = new BN(1);
19218 var y1 = new BN(0);
19219 var x2 = new BN(0);
19220 var y2 = new BN(1);
19221
19222 // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
19223 var a0;
19224 var b0;
19225 // First vector
19226 var a1;
19227 var b1;
19228 // Second vector
19229 var a2;
19230 var b2;
19231
19232 var prevR;
19233 var i = 0;
19234 var r;
19235 var x;
19236 while (u.cmpn(0) !== 0) {
19237 var q = v.div(u);
19238 r = v.sub(q.mul(u));
19239 x = x2.sub(q.mul(x1));
19240 var y = y2.sub(q.mul(y1));
19241
19242 if (!a1 && r.cmp(aprxSqrt) < 0) {
19243 a0 = prevR.neg();
19244 b0 = x1;
19245 a1 = r.neg();
19246 b1 = x;
19247 } else if (a1 && ++i === 2) {
19248 break;
19249 }
19250 prevR = r;
19251
19252 v = u;
19253 u = r;
19254 x2 = x1;
19255 x1 = x;
19256 y2 = y1;
19257 y1 = y;
19258 }
19259 a2 = r.neg();
19260 b2 = x;
19261
19262 var len1 = a1.sqr().add(b1.sqr());
19263 var len2 = a2.sqr().add(b2.sqr());
19264 if (len2.cmp(len1) >= 0) {
19265 a2 = a0;
19266 b2 = b0;
19267 }
19268
19269 // Normalize signs
19270 if (a1.negative) {
19271 a1 = a1.neg();
19272 b1 = b1.neg();
19273 }
19274 if (a2.negative) {
19275 a2 = a2.neg();
19276 b2 = b2.neg();
19277 }
19278
19279 return [
19280 { a: a1, b: b1 },
19281 { a: a2, b: b2 }
19282 ];
19283};
19284
19285ShortCurve.prototype._endoSplit = function _endoSplit(k) {
19286 var basis = this.endo.basis;
19287 var v1 = basis[0];
19288 var v2 = basis[1];
19289
19290 var c1 = v2.b.mul(k).divRound(this.n);
19291 var c2 = v1.b.neg().mul(k).divRound(this.n);
19292
19293 var p1 = c1.mul(v1.a);
19294 var p2 = c2.mul(v2.a);
19295 var q1 = c1.mul(v1.b);
19296 var q2 = c2.mul(v2.b);
19297
19298 // Calculate answer
19299 var k1 = k.sub(p1).sub(p2);
19300 var k2 = q1.add(q2).neg();
19301 return { k1: k1, k2: k2 };
19302};
19303
19304ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
19305 x = new BN(x, 16);
19306 if (!x.red)
19307 x = x.toRed(this.red);
19308
19309 var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
19310 var y = y2.redSqrt();
19311 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
19312 throw new Error('invalid point');
19313
19314 // XXX Is there any way to tell if the number is odd without converting it
19315 // to non-red form?
19316 var isOdd = y.fromRed().isOdd();
19317 if (odd && !isOdd || !odd && isOdd)
19318 y = y.redNeg();
19319
19320 return this.point(x, y);
19321};
19322
19323ShortCurve.prototype.validate = function validate(point) {
19324 if (point.inf)
19325 return true;
19326
19327 var x = point.x;
19328 var y = point.y;
19329
19330 var ax = this.a.redMul(x);
19331 var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
19332 return y.redSqr().redISub(rhs).cmpn(0) === 0;
19333};
19334
19335ShortCurve.prototype._endoWnafMulAdd =
19336 function _endoWnafMulAdd(points, coeffs, jacobianResult) {
19337 var npoints = this._endoWnafT1;
19338 var ncoeffs = this._endoWnafT2;
19339 for (var i = 0; i < points.length; i++) {
19340 var split = this._endoSplit(coeffs[i]);
19341 var p = points[i];
19342 var beta = p._getBeta();
19343
19344 if (split.k1.negative) {
19345 split.k1.ineg();
19346 p = p.neg(true);
19347 }
19348 if (split.k2.negative) {
19349 split.k2.ineg();
19350 beta = beta.neg(true);
19351 }
19352
19353 npoints[i * 2] = p;
19354 npoints[i * 2 + 1] = beta;
19355 ncoeffs[i * 2] = split.k1;
19356 ncoeffs[i * 2 + 1] = split.k2;
19357 }
19358 var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
19359
19360 // Clean-up references to points and coefficients
19361 for (var j = 0; j < i * 2; j++) {
19362 npoints[j] = null;
19363 ncoeffs[j] = null;
19364 }
19365 return res;
19366};
19367
19368function Point(curve, x, y, isRed) {
19369 Base.BasePoint.call(this, curve, 'affine');
19370 if (x === null && y === null) {
19371 this.x = null;
19372 this.y = null;
19373 this.inf = true;
19374 } else {
19375 this.x = new BN(x, 16);
19376 this.y = new BN(y, 16);
19377 // Force redgomery representation when loading from JSON
19378 if (isRed) {
19379 this.x.forceRed(this.curve.red);
19380 this.y.forceRed(this.curve.red);
19381 }
19382 if (!this.x.red)
19383 this.x = this.x.toRed(this.curve.red);
19384 if (!this.y.red)
19385 this.y = this.y.toRed(this.curve.red);
19386 this.inf = false;
19387 }
19388}
19389inherits(Point, Base.BasePoint);
19390
19391ShortCurve.prototype.point = function point(x, y, isRed) {
19392 return new Point(this, x, y, isRed);
19393};
19394
19395ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
19396 return Point.fromJSON(this, obj, red);
19397};
19398
19399Point.prototype._getBeta = function _getBeta() {
19400 if (!this.curve.endo)
19401 return;
19402
19403 var pre = this.precomputed;
19404 if (pre && pre.beta)
19405 return pre.beta;
19406
19407 var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
19408 if (pre) {
19409 var curve = this.curve;
19410 var endoMul = function(p) {
19411 return curve.point(p.x.redMul(curve.endo.beta), p.y);
19412 };
19413 pre.beta = beta;
19414 beta.precomputed = {
19415 beta: null,
19416 naf: pre.naf && {
19417 wnd: pre.naf.wnd,
19418 points: pre.naf.points.map(endoMul)
19419 },
19420 doubles: pre.doubles && {
19421 step: pre.doubles.step,
19422 points: pre.doubles.points.map(endoMul)
19423 }
19424 };
19425 }
19426 return beta;
19427};
19428
19429Point.prototype.toJSON = function toJSON() {
19430 if (!this.precomputed)
19431 return [ this.x, this.y ];
19432
19433 return [ this.x, this.y, this.precomputed && {
19434 doubles: this.precomputed.doubles && {
19435 step: this.precomputed.doubles.step,
19436 points: this.precomputed.doubles.points.slice(1)
19437 },
19438 naf: this.precomputed.naf && {
19439 wnd: this.precomputed.naf.wnd,
19440 points: this.precomputed.naf.points.slice(1)
19441 }
19442 } ];
19443};
19444
19445Point.fromJSON = function fromJSON(curve, obj, red) {
19446 if (typeof obj === 'string')
19447 obj = JSON.parse(obj);
19448 var res = curve.point(obj[0], obj[1], red);
19449 if (!obj[2])
19450 return res;
19451
19452 function obj2point(obj) {
19453 return curve.point(obj[0], obj[1], red);
19454 }
19455
19456 var pre = obj[2];
19457 res.precomputed = {
19458 beta: null,
19459 doubles: pre.doubles && {
19460 step: pre.doubles.step,
19461 points: [ res ].concat(pre.doubles.points.map(obj2point))
19462 },
19463 naf: pre.naf && {
19464 wnd: pre.naf.wnd,
19465 points: [ res ].concat(pre.naf.points.map(obj2point))
19466 }
19467 };
19468 return res;
19469};
19470
19471Point.prototype.inspect = function inspect() {
19472 if (this.isInfinity())
19473 return '<EC Point Infinity>';
19474 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
19475 ' y: ' + this.y.fromRed().toString(16, 2) + '>';
19476};
19477
19478Point.prototype.isInfinity = function isInfinity() {
19479 return this.inf;
19480};
19481
19482Point.prototype.add = function add(p) {
19483 // O + P = P
19484 if (this.inf)
19485 return p;
19486
19487 // P + O = P
19488 if (p.inf)
19489 return this;
19490
19491 // P + P = 2P
19492 if (this.eq(p))
19493 return this.dbl();
19494
19495 // P + (-P) = O
19496 if (this.neg().eq(p))
19497 return this.curve.point(null, null);
19498
19499 // P + Q = O
19500 if (this.x.cmp(p.x) === 0)
19501 return this.curve.point(null, null);
19502
19503 var c = this.y.redSub(p.y);
19504 if (c.cmpn(0) !== 0)
19505 c = c.redMul(this.x.redSub(p.x).redInvm());
19506 var nx = c.redSqr().redISub(this.x).redISub(p.x);
19507 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
19508 return this.curve.point(nx, ny);
19509};
19510
19511Point.prototype.dbl = function dbl() {
19512 if (this.inf)
19513 return this;
19514
19515 // 2P = O
19516 var ys1 = this.y.redAdd(this.y);
19517 if (ys1.cmpn(0) === 0)
19518 return this.curve.point(null, null);
19519
19520 var a = this.curve.a;
19521
19522 var x2 = this.x.redSqr();
19523 var dyinv = ys1.redInvm();
19524 var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
19525
19526 var nx = c.redSqr().redISub(this.x.redAdd(this.x));
19527 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
19528 return this.curve.point(nx, ny);
19529};
19530
19531Point.prototype.getX = function getX() {
19532 return this.x.fromRed();
19533};
19534
19535Point.prototype.getY = function getY() {
19536 return this.y.fromRed();
19537};
19538
19539Point.prototype.mul = function mul(k) {
19540 k = new BN(k, 16);
19541
19542 if (this._hasDoubles(k))
19543 return this.curve._fixedNafMul(this, k);
19544 else if (this.curve.endo)
19545 return this.curve._endoWnafMulAdd([ this ], [ k ]);
19546 else
19547 return this.curve._wnafMul(this, k);
19548};
19549
19550Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
19551 var points = [ this, p2 ];
19552 var coeffs = [ k1, k2 ];
19553 if (this.curve.endo)
19554 return this.curve._endoWnafMulAdd(points, coeffs);
19555 else
19556 return this.curve._wnafMulAdd(1, points, coeffs, 2);
19557};
19558
19559Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
19560 var points = [ this, p2 ];
19561 var coeffs = [ k1, k2 ];
19562 if (this.curve.endo)
19563 return this.curve._endoWnafMulAdd(points, coeffs, true);
19564 else
19565 return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
19566};
19567
19568Point.prototype.eq = function eq(p) {
19569 return this === p ||
19570 this.inf === p.inf &&
19571 (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
19572};
19573
19574Point.prototype.neg = function neg(_precompute) {
19575 if (this.inf)
19576 return this;
19577
19578 var res = this.curve.point(this.x, this.y.redNeg());
19579 if (_precompute && this.precomputed) {
19580 var pre = this.precomputed;
19581 var negate = function(p) {
19582 return p.neg();
19583 };
19584 res.precomputed = {
19585 naf: pre.naf && {
19586 wnd: pre.naf.wnd,
19587 points: pre.naf.points.map(negate)
19588 },
19589 doubles: pre.doubles && {
19590 step: pre.doubles.step,
19591 points: pre.doubles.points.map(negate)
19592 }
19593 };
19594 }
19595 return res;
19596};
19597
19598Point.prototype.toJ = function toJ() {
19599 if (this.inf)
19600 return this.curve.jpoint(null, null, null);
19601
19602 var res = this.curve.jpoint(this.x, this.y, this.curve.one);
19603 return res;
19604};
19605
19606function JPoint(curve, x, y, z) {
19607 Base.BasePoint.call(this, curve, 'jacobian');
19608 if (x === null && y === null && z === null) {
19609 this.x = this.curve.one;
19610 this.y = this.curve.one;
19611 this.z = new BN(0);
19612 } else {
19613 this.x = new BN(x, 16);
19614 this.y = new BN(y, 16);
19615 this.z = new BN(z, 16);
19616 }
19617 if (!this.x.red)
19618 this.x = this.x.toRed(this.curve.red);
19619 if (!this.y.red)
19620 this.y = this.y.toRed(this.curve.red);
19621 if (!this.z.red)
19622 this.z = this.z.toRed(this.curve.red);
19623
19624 this.zOne = this.z === this.curve.one;
19625}
19626inherits(JPoint, Base.BasePoint);
19627
19628ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
19629 return new JPoint(this, x, y, z);
19630};
19631
19632JPoint.prototype.toP = function toP() {
19633 if (this.isInfinity())
19634 return this.curve.point(null, null);
19635
19636 var zinv = this.z.redInvm();
19637 var zinv2 = zinv.redSqr();
19638 var ax = this.x.redMul(zinv2);
19639 var ay = this.y.redMul(zinv2).redMul(zinv);
19640
19641 return this.curve.point(ax, ay);
19642};
19643
19644JPoint.prototype.neg = function neg() {
19645 return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
19646};
19647
19648JPoint.prototype.add = function add(p) {
19649 // O + P = P
19650 if (this.isInfinity())
19651 return p;
19652
19653 // P + O = P
19654 if (p.isInfinity())
19655 return this;
19656
19657 // 12M + 4S + 7A
19658 var pz2 = p.z.redSqr();
19659 var z2 = this.z.redSqr();
19660 var u1 = this.x.redMul(pz2);
19661 var u2 = p.x.redMul(z2);
19662 var s1 = this.y.redMul(pz2.redMul(p.z));
19663 var s2 = p.y.redMul(z2.redMul(this.z));
19664
19665 var h = u1.redSub(u2);
19666 var r = s1.redSub(s2);
19667 if (h.cmpn(0) === 0) {
19668 if (r.cmpn(0) !== 0)
19669 return this.curve.jpoint(null, null, null);
19670 else
19671 return this.dbl();
19672 }
19673
19674 var h2 = h.redSqr();
19675 var h3 = h2.redMul(h);
19676 var v = u1.redMul(h2);
19677
19678 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
19679 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
19680 var nz = this.z.redMul(p.z).redMul(h);
19681
19682 return this.curve.jpoint(nx, ny, nz);
19683};
19684
19685JPoint.prototype.mixedAdd = function mixedAdd(p) {
19686 // O + P = P
19687 if (this.isInfinity())
19688 return p.toJ();
19689
19690 // P + O = P
19691 if (p.isInfinity())
19692 return this;
19693
19694 // 8M + 3S + 7A
19695 var z2 = this.z.redSqr();
19696 var u1 = this.x;
19697 var u2 = p.x.redMul(z2);
19698 var s1 = this.y;
19699 var s2 = p.y.redMul(z2).redMul(this.z);
19700
19701 var h = u1.redSub(u2);
19702 var r = s1.redSub(s2);
19703 if (h.cmpn(0) === 0) {
19704 if (r.cmpn(0) !== 0)
19705 return this.curve.jpoint(null, null, null);
19706 else
19707 return this.dbl();
19708 }
19709
19710 var h2 = h.redSqr();
19711 var h3 = h2.redMul(h);
19712 var v = u1.redMul(h2);
19713
19714 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
19715 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
19716 var nz = this.z.redMul(h);
19717
19718 return this.curve.jpoint(nx, ny, nz);
19719};
19720
19721JPoint.prototype.dblp = function dblp(pow) {
19722 if (pow === 0)
19723 return this;
19724 if (this.isInfinity())
19725 return this;
19726 if (!pow)
19727 return this.dbl();
19728
19729 if (this.curve.zeroA || this.curve.threeA) {
19730 var r = this;
19731 for (var i = 0; i < pow; i++)
19732 r = r.dbl();
19733 return r;
19734 }
19735
19736 // 1M + 2S + 1A + N * (4S + 5M + 8A)
19737 // N = 1 => 6M + 6S + 9A
19738 var a = this.curve.a;
19739 var tinv = this.curve.tinv;
19740
19741 var jx = this.x;
19742 var jy = this.y;
19743 var jz = this.z;
19744 var jz4 = jz.redSqr().redSqr();
19745
19746 // Reuse results
19747 var jyd = jy.redAdd(jy);
19748 for (var i = 0; i < pow; i++) {
19749 var jx2 = jx.redSqr();
19750 var jyd2 = jyd.redSqr();
19751 var jyd4 = jyd2.redSqr();
19752 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
19753
19754 var t1 = jx.redMul(jyd2);
19755 var nx = c.redSqr().redISub(t1.redAdd(t1));
19756 var t2 = t1.redISub(nx);
19757 var dny = c.redMul(t2);
19758 dny = dny.redIAdd(dny).redISub(jyd4);
19759 var nz = jyd.redMul(jz);
19760 if (i + 1 < pow)
19761 jz4 = jz4.redMul(jyd4);
19762
19763 jx = nx;
19764 jz = nz;
19765 jyd = dny;
19766 }
19767
19768 return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
19769};
19770
19771JPoint.prototype.dbl = function dbl() {
19772 if (this.isInfinity())
19773 return this;
19774
19775 if (this.curve.zeroA)
19776 return this._zeroDbl();
19777 else if (this.curve.threeA)
19778 return this._threeDbl();
19779 else
19780 return this._dbl();
19781};
19782
19783JPoint.prototype._zeroDbl = function _zeroDbl() {
19784 var nx;
19785 var ny;
19786 var nz;
19787 // Z = 1
19788 if (this.zOne) {
19789 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
19790 // #doubling-mdbl-2007-bl
19791 // 1M + 5S + 14A
19792
19793 // XX = X1^2
19794 var xx = this.x.redSqr();
19795 // YY = Y1^2
19796 var yy = this.y.redSqr();
19797 // YYYY = YY^2
19798 var yyyy = yy.redSqr();
19799 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
19800 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
19801 s = s.redIAdd(s);
19802 // M = 3 * XX + a; a = 0
19803 var m = xx.redAdd(xx).redIAdd(xx);
19804 // T = M ^ 2 - 2*S
19805 var t = m.redSqr().redISub(s).redISub(s);
19806
19807 // 8 * YYYY
19808 var yyyy8 = yyyy.redIAdd(yyyy);
19809 yyyy8 = yyyy8.redIAdd(yyyy8);
19810 yyyy8 = yyyy8.redIAdd(yyyy8);
19811
19812 // X3 = T
19813 nx = t;
19814 // Y3 = M * (S - T) - 8 * YYYY
19815 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
19816 // Z3 = 2*Y1
19817 nz = this.y.redAdd(this.y);
19818 } else {
19819 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
19820 // #doubling-dbl-2009-l
19821 // 2M + 5S + 13A
19822
19823 // A = X1^2
19824 var a = this.x.redSqr();
19825 // B = Y1^2
19826 var b = this.y.redSqr();
19827 // C = B^2
19828 var c = b.redSqr();
19829 // D = 2 * ((X1 + B)^2 - A - C)
19830 var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
19831 d = d.redIAdd(d);
19832 // E = 3 * A
19833 var e = a.redAdd(a).redIAdd(a);
19834 // F = E^2
19835 var f = e.redSqr();
19836
19837 // 8 * C
19838 var c8 = c.redIAdd(c);
19839 c8 = c8.redIAdd(c8);
19840 c8 = c8.redIAdd(c8);
19841
19842 // X3 = F - 2 * D
19843 nx = f.redISub(d).redISub(d);
19844 // Y3 = E * (D - X3) - 8 * C
19845 ny = e.redMul(d.redISub(nx)).redISub(c8);
19846 // Z3 = 2 * Y1 * Z1
19847 nz = this.y.redMul(this.z);
19848 nz = nz.redIAdd(nz);
19849 }
19850
19851 return this.curve.jpoint(nx, ny, nz);
19852};
19853
19854JPoint.prototype._threeDbl = function _threeDbl() {
19855 var nx;
19856 var ny;
19857 var nz;
19858 // Z = 1
19859 if (this.zOne) {
19860 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
19861 // #doubling-mdbl-2007-bl
19862 // 1M + 5S + 15A
19863
19864 // XX = X1^2
19865 var xx = this.x.redSqr();
19866 // YY = Y1^2
19867 var yy = this.y.redSqr();
19868 // YYYY = YY^2
19869 var yyyy = yy.redSqr();
19870 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
19871 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
19872 s = s.redIAdd(s);
19873 // M = 3 * XX + a
19874 var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
19875 // T = M^2 - 2 * S
19876 var t = m.redSqr().redISub(s).redISub(s);
19877 // X3 = T
19878 nx = t;
19879 // Y3 = M * (S - T) - 8 * YYYY
19880 var yyyy8 = yyyy.redIAdd(yyyy);
19881 yyyy8 = yyyy8.redIAdd(yyyy8);
19882 yyyy8 = yyyy8.redIAdd(yyyy8);
19883 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
19884 // Z3 = 2 * Y1
19885 nz = this.y.redAdd(this.y);
19886 } else {
19887 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
19888 // 3M + 5S
19889
19890 // delta = Z1^2
19891 var delta = this.z.redSqr();
19892 // gamma = Y1^2
19893 var gamma = this.y.redSqr();
19894 // beta = X1 * gamma
19895 var beta = this.x.redMul(gamma);
19896 // alpha = 3 * (X1 - delta) * (X1 + delta)
19897 var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
19898 alpha = alpha.redAdd(alpha).redIAdd(alpha);
19899 // X3 = alpha^2 - 8 * beta
19900 var beta4 = beta.redIAdd(beta);
19901 beta4 = beta4.redIAdd(beta4);
19902 var beta8 = beta4.redAdd(beta4);
19903 nx = alpha.redSqr().redISub(beta8);
19904 // Z3 = (Y1 + Z1)^2 - gamma - delta
19905 nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
19906 // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
19907 var ggamma8 = gamma.redSqr();
19908 ggamma8 = ggamma8.redIAdd(ggamma8);
19909 ggamma8 = ggamma8.redIAdd(ggamma8);
19910 ggamma8 = ggamma8.redIAdd(ggamma8);
19911 ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
19912 }
19913
19914 return this.curve.jpoint(nx, ny, nz);
19915};
19916
19917JPoint.prototype._dbl = function _dbl() {
19918 var a = this.curve.a;
19919
19920 // 4M + 6S + 10A
19921 var jx = this.x;
19922 var jy = this.y;
19923 var jz = this.z;
19924 var jz4 = jz.redSqr().redSqr();
19925
19926 var jx2 = jx.redSqr();
19927 var jy2 = jy.redSqr();
19928
19929 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
19930
19931 var jxd4 = jx.redAdd(jx);
19932 jxd4 = jxd4.redIAdd(jxd4);
19933 var t1 = jxd4.redMul(jy2);
19934 var nx = c.redSqr().redISub(t1.redAdd(t1));
19935 var t2 = t1.redISub(nx);
19936
19937 var jyd8 = jy2.redSqr();
19938 jyd8 = jyd8.redIAdd(jyd8);
19939 jyd8 = jyd8.redIAdd(jyd8);
19940 jyd8 = jyd8.redIAdd(jyd8);
19941 var ny = c.redMul(t2).redISub(jyd8);
19942 var nz = jy.redAdd(jy).redMul(jz);
19943
19944 return this.curve.jpoint(nx, ny, nz);
19945};
19946
19947JPoint.prototype.trpl = function trpl() {
19948 if (!this.curve.zeroA)
19949 return this.dbl().add(this);
19950
19951 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
19952 // 5M + 10S + ...
19953
19954 // XX = X1^2
19955 var xx = this.x.redSqr();
19956 // YY = Y1^2
19957 var yy = this.y.redSqr();
19958 // ZZ = Z1^2
19959 var zz = this.z.redSqr();
19960 // YYYY = YY^2
19961 var yyyy = yy.redSqr();
19962 // M = 3 * XX + a * ZZ2; a = 0
19963 var m = xx.redAdd(xx).redIAdd(xx);
19964 // MM = M^2
19965 var mm = m.redSqr();
19966 // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
19967 var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
19968 e = e.redIAdd(e);
19969 e = e.redAdd(e).redIAdd(e);
19970 e = e.redISub(mm);
19971 // EE = E^2
19972 var ee = e.redSqr();
19973 // T = 16*YYYY
19974 var t = yyyy.redIAdd(yyyy);
19975 t = t.redIAdd(t);
19976 t = t.redIAdd(t);
19977 t = t.redIAdd(t);
19978 // U = (M + E)^2 - MM - EE - T
19979 var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
19980 // X3 = 4 * (X1 * EE - 4 * YY * U)
19981 var yyu4 = yy.redMul(u);
19982 yyu4 = yyu4.redIAdd(yyu4);
19983 yyu4 = yyu4.redIAdd(yyu4);
19984 var nx = this.x.redMul(ee).redISub(yyu4);
19985 nx = nx.redIAdd(nx);
19986 nx = nx.redIAdd(nx);
19987 // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
19988 var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
19989 ny = ny.redIAdd(ny);
19990 ny = ny.redIAdd(ny);
19991 ny = ny.redIAdd(ny);
19992 // Z3 = (Z1 + E)^2 - ZZ - EE
19993 var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
19994
19995 return this.curve.jpoint(nx, ny, nz);
19996};
19997
19998JPoint.prototype.mul = function mul(k, kbase) {
19999 k = new BN(k, kbase);
20000
20001 return this.curve._wnafMul(this, k);
20002};
20003
20004JPoint.prototype.eq = function eq(p) {
20005 if (p.type === 'affine')
20006 return this.eq(p.toJ());
20007
20008 if (this === p)
20009 return true;
20010
20011 // x1 * z2^2 == x2 * z1^2
20012 var z2 = this.z.redSqr();
20013 var pz2 = p.z.redSqr();
20014 if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
20015 return false;
20016
20017 // y1 * z2^3 == y2 * z1^3
20018 var z3 = z2.redMul(this.z);
20019 var pz3 = pz2.redMul(p.z);
20020 return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
20021};
20022
20023JPoint.prototype.eqXToP = function eqXToP(x) {
20024 var zs = this.z.redSqr();
20025 var rx = x.toRed(this.curve.red).redMul(zs);
20026 if (this.x.cmp(rx) === 0)
20027 return true;
20028
20029 var xc = x.clone();
20030 var t = this.curve.redN.redMul(zs);
20031 for (;;) {
20032 xc.iadd(this.curve.n);
20033 if (xc.cmp(this.curve.p) >= 0)
20034 return false;
20035
20036 rx.redIAdd(t);
20037 if (this.x.cmp(rx) === 0)
20038 return true;
20039 }
20040};
20041
20042JPoint.prototype.inspect = function inspect() {
20043 if (this.isInfinity())
20044 return '<EC JPoint Infinity>';
20045 return '<EC JPoint x: ' + this.x.toString(16, 2) +
20046 ' y: ' + this.y.toString(16, 2) +
20047 ' z: ' + this.z.toString(16, 2) + '>';
20048};
20049
20050JPoint.prototype.isInfinity = function isInfinity() {
20051 // XXX This code assumes that zero is always zero in red
20052 return this.z.cmpn(0) === 0;
20053};
20054
20055},{"../utils":143,"./base":130,"bn.js":79,"inherits":162}],135:[function(require,module,exports){
20056'use strict';
20057
20058var curves = exports;
20059
20060var hash = require('hash.js');
20061var curve = require('./curve');
20062var utils = require('./utils');
20063
20064var assert = utils.assert;
20065
20066function PresetCurve(options) {
20067 if (options.type === 'short')
20068 this.curve = new curve.short(options);
20069 else if (options.type === 'edwards')
20070 this.curve = new curve.edwards(options);
20071 else
20072 this.curve = new curve.mont(options);
20073 this.g = this.curve.g;
20074 this.n = this.curve.n;
20075 this.hash = options.hash;
20076
20077 assert(this.g.validate(), 'Invalid curve');
20078 assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
20079}
20080curves.PresetCurve = PresetCurve;
20081
20082function defineCurve(name, options) {
20083 Object.defineProperty(curves, name, {
20084 configurable: true,
20085 enumerable: true,
20086 get: function() {
20087 var curve = new PresetCurve(options);
20088 Object.defineProperty(curves, name, {
20089 configurable: true,
20090 enumerable: true,
20091 value: curve
20092 });
20093 return curve;
20094 }
20095 });
20096}
20097
20098defineCurve('p192', {
20099 type: 'short',
20100 prime: 'p192',
20101 p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
20102 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
20103 b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
20104 n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
20105 hash: hash.sha256,
20106 gRed: false,
20107 g: [
20108 '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
20109 '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
20110 ]
20111});
20112
20113defineCurve('p224', {
20114 type: 'short',
20115 prime: 'p224',
20116 p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
20117 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
20118 b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
20119 n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
20120 hash: hash.sha256,
20121 gRed: false,
20122 g: [
20123 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
20124 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
20125 ]
20126});
20127
20128defineCurve('p256', {
20129 type: 'short',
20130 prime: null,
20131 p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
20132 a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
20133 b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
20134 n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
20135 hash: hash.sha256,
20136 gRed: false,
20137 g: [
20138 '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
20139 '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
20140 ]
20141});
20142
20143defineCurve('p384', {
20144 type: 'short',
20145 prime: null,
20146 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20147 'fffffffe ffffffff 00000000 00000000 ffffffff',
20148 a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20149 'fffffffe ffffffff 00000000 00000000 fffffffc',
20150 b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
20151 '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
20152 n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
20153 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
20154 hash: hash.sha384,
20155 gRed: false,
20156 g: [
20157 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
20158 '5502f25d bf55296c 3a545e38 72760ab7',
20159 '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
20160 '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
20161 ]
20162});
20163
20164defineCurve('p521', {
20165 type: 'short',
20166 prime: null,
20167 p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20168 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20169 'ffffffff ffffffff ffffffff ffffffff ffffffff',
20170 a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20171 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20172 'ffffffff ffffffff ffffffff ffffffff fffffffc',
20173 b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
20174 '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
20175 '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
20176 n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20177 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
20178 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
20179 hash: hash.sha512,
20180 gRed: false,
20181 g: [
20182 '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
20183 '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
20184 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
20185 '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
20186 '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
20187 '3fad0761 353c7086 a272c240 88be9476 9fd16650'
20188 ]
20189});
20190
20191defineCurve('curve25519', {
20192 type: 'mont',
20193 prime: 'p25519',
20194 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
20195 a: '76d06',
20196 b: '1',
20197 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
20198 hash: hash.sha256,
20199 gRed: false,
20200 g: [
20201 '9'
20202 ]
20203});
20204
20205defineCurve('ed25519', {
20206 type: 'edwards',
20207 prime: 'p25519',
20208 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
20209 a: '-1',
20210 c: '1',
20211 // -121665 * (121666^(-1)) (mod P)
20212 d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
20213 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
20214 hash: hash.sha256,
20215 gRed: false,
20216 g: [
20217 '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
20218
20219 // 4/5
20220 '6666666666666666666666666666666666666666666666666666666666666658'
20221 ]
20222});
20223
20224var pre;
20225try {
20226 pre = require('./precomputed/secp256k1');
20227} catch (e) {
20228 pre = undefined;
20229}
20230
20231defineCurve('secp256k1', {
20232 type: 'short',
20233 prime: 'k256',
20234 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
20235 a: '0',
20236 b: '7',
20237 n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
20238 h: '1',
20239 hash: hash.sha256,
20240
20241 // Precomputed endomorphism
20242 beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
20243 lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
20244 basis: [
20245 {
20246 a: '3086d221a7d46bcde86c90e49284eb15',
20247 b: '-e4437ed6010e88286f547fa90abfe4c3'
20248 },
20249 {
20250 a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
20251 b: '3086d221a7d46bcde86c90e49284eb15'
20252 }
20253 ],
20254
20255 gRed: false,
20256 g: [
20257 '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
20258 '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
20259 pre
20260 ]
20261});
20262
20263},{"./curve":132,"./precomputed/secp256k1":142,"./utils":143,"hash.js":148}],136:[function(require,module,exports){
20264'use strict';
20265
20266var BN = require('bn.js');
20267var HmacDRBG = require('hmac-drbg');
20268var utils = require('../utils');
20269var curves = require('../curves');
20270var rand = require('brorand');
20271var assert = utils.assert;
20272
20273var KeyPair = require('./key');
20274var Signature = require('./signature');
20275
20276function EC(options) {
20277 if (!(this instanceof EC))
20278 return new EC(options);
20279
20280 // Shortcut `elliptic.ec(curve-name)`
20281 if (typeof options === 'string') {
20282 assert(curves.hasOwnProperty(options), 'Unknown curve ' + options);
20283
20284 options = curves[options];
20285 }
20286
20287 // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
20288 if (options instanceof curves.PresetCurve)
20289 options = { curve: options };
20290
20291 this.curve = options.curve.curve;
20292 this.n = this.curve.n;
20293 this.nh = this.n.ushrn(1);
20294 this.g = this.curve.g;
20295
20296 // Point on curve
20297 this.g = options.curve.g;
20298 this.g.precompute(options.curve.n.bitLength() + 1);
20299
20300 // Hash for function for DRBG
20301 this.hash = options.hash || options.curve.hash;
20302}
20303module.exports = EC;
20304
20305EC.prototype.keyPair = function keyPair(options) {
20306 return new KeyPair(this, options);
20307};
20308
20309EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
20310 return KeyPair.fromPrivate(this, priv, enc);
20311};
20312
20313EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
20314 return KeyPair.fromPublic(this, pub, enc);
20315};
20316
20317EC.prototype.genKeyPair = function genKeyPair(options) {
20318 if (!options)
20319 options = {};
20320
20321 // Instantiate Hmac_DRBG
20322 var drbg = new HmacDRBG({
20323 hash: this.hash,
20324 pers: options.pers,
20325 persEnc: options.persEnc || 'utf8',
20326 entropy: options.entropy || rand(this.hash.hmacStrength),
20327 entropyEnc: options.entropy && options.entropyEnc || 'utf8',
20328 nonce: this.n.toArray()
20329 });
20330
20331 var bytes = this.n.byteLength();
20332 var ns2 = this.n.sub(new BN(2));
20333 do {
20334 var priv = new BN(drbg.generate(bytes));
20335 if (priv.cmp(ns2) > 0)
20336 continue;
20337
20338 priv.iaddn(1);
20339 return this.keyFromPrivate(priv);
20340 } while (true);
20341};
20342
20343EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
20344 var delta = msg.byteLength() * 8 - this.n.bitLength();
20345 if (delta > 0)
20346 msg = msg.ushrn(delta);
20347 if (!truncOnly && msg.cmp(this.n) >= 0)
20348 return msg.sub(this.n);
20349 else
20350 return msg;
20351};
20352
20353EC.prototype.sign = function sign(msg, key, enc, options) {
20354 if (typeof enc === 'object') {
20355 options = enc;
20356 enc = null;
20357 }
20358 if (!options)
20359 options = {};
20360
20361 key = this.keyFromPrivate(key, enc);
20362 msg = this._truncateToN(new BN(msg, 16));
20363
20364 // Zero-extend key to provide enough entropy
20365 var bytes = this.n.byteLength();
20366 var bkey = key.getPrivate().toArray('be', bytes);
20367
20368 // Zero-extend nonce to have the same byte size as N
20369 var nonce = msg.toArray('be', bytes);
20370
20371 // Instantiate Hmac_DRBG
20372 var drbg = new HmacDRBG({
20373 hash: this.hash,
20374 entropy: bkey,
20375 nonce: nonce,
20376 pers: options.pers,
20377 persEnc: options.persEnc || 'utf8'
20378 });
20379
20380 // Number of bytes to generate
20381 var ns1 = this.n.sub(new BN(1));
20382
20383 for (var iter = 0; true; iter++) {
20384 var k = options.k ?
20385 options.k(iter) :
20386 new BN(drbg.generate(this.n.byteLength()));
20387 k = this._truncateToN(k, true);
20388 if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
20389 continue;
20390
20391 var kp = this.g.mul(k);
20392 if (kp.isInfinity())
20393 continue;
20394
20395 var kpX = kp.getX();
20396 var r = kpX.umod(this.n);
20397 if (r.cmpn(0) === 0)
20398 continue;
20399
20400 var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
20401 s = s.umod(this.n);
20402 if (s.cmpn(0) === 0)
20403 continue;
20404
20405 var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
20406 (kpX.cmp(r) !== 0 ? 2 : 0);
20407
20408 // Use complement of `s`, if it is > `n / 2`
20409 if (options.canonical && s.cmp(this.nh) > 0) {
20410 s = this.n.sub(s);
20411 recoveryParam ^= 1;
20412 }
20413
20414 return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
20415 }
20416};
20417
20418EC.prototype.verify = function verify(msg, signature, key, enc) {
20419 msg = this._truncateToN(new BN(msg, 16));
20420 key = this.keyFromPublic(key, enc);
20421 signature = new Signature(signature, 'hex');
20422
20423 // Perform primitive values validation
20424 var r = signature.r;
20425 var s = signature.s;
20426 if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
20427 return false;
20428 if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
20429 return false;
20430
20431 // Validate signature
20432 var sinv = s.invm(this.n);
20433 var u1 = sinv.mul(msg).umod(this.n);
20434 var u2 = sinv.mul(r).umod(this.n);
20435
20436 if (!this.curve._maxwellTrick) {
20437 var p = this.g.mulAdd(u1, key.getPublic(), u2);
20438 if (p.isInfinity())
20439 return false;
20440
20441 return p.getX().umod(this.n).cmp(r) === 0;
20442 }
20443
20444 // NOTE: Greg Maxwell's trick, inspired by:
20445 // https://git.io/vad3K
20446
20447 var p = this.g.jmulAdd(u1, key.getPublic(), u2);
20448 if (p.isInfinity())
20449 return false;
20450
20451 // Compare `p.x` of Jacobian point with `r`,
20452 // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
20453 // inverse of `p.z^2`
20454 return p.eqXToP(r);
20455};
20456
20457EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
20458 assert((3 & j) === j, 'The recovery param is more than two bits');
20459 signature = new Signature(signature, enc);
20460
20461 var n = this.n;
20462 var e = new BN(msg);
20463 var r = signature.r;
20464 var s = signature.s;
20465
20466 // A set LSB signifies that the y-coordinate is odd
20467 var isYOdd = j & 1;
20468 var isSecondKey = j >> 1;
20469 if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
20470 throw new Error('Unable to find sencond key candinate');
20471
20472 // 1.1. Let x = r + jn.
20473 if (isSecondKey)
20474 r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
20475 else
20476 r = this.curve.pointFromX(r, isYOdd);
20477
20478 var rInv = signature.r.invm(n);
20479 var s1 = n.sub(e).mul(rInv).umod(n);
20480 var s2 = s.mul(rInv).umod(n);
20481
20482 // 1.6.1 Compute Q = r^-1 (sR - eG)
20483 // Q = r^-1 (sR + -eG)
20484 return this.g.mulAdd(s1, r, s2);
20485};
20486
20487EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
20488 signature = new Signature(signature, enc);
20489 if (signature.recoveryParam !== null)
20490 return signature.recoveryParam;
20491
20492 for (var i = 0; i < 4; i++) {
20493 var Qprime;
20494 try {
20495 Qprime = this.recoverPubKey(e, signature, i);
20496 } catch (e) {
20497 continue;
20498 }
20499
20500 if (Qprime.eq(Q))
20501 return i;
20502 }
20503 throw new Error('Unable to find valid recovery factor');
20504};
20505
20506},{"../curves":135,"../utils":143,"./key":137,"./signature":138,"bn.js":79,"brorand":80,"hmac-drbg":160}],137:[function(require,module,exports){
20507'use strict';
20508
20509var BN = require('bn.js');
20510var utils = require('../utils');
20511var assert = utils.assert;
20512
20513function KeyPair(ec, options) {
20514 this.ec = ec;
20515 this.priv = null;
20516 this.pub = null;
20517
20518 // KeyPair(ec, { priv: ..., pub: ... })
20519 if (options.priv)
20520 this._importPrivate(options.priv, options.privEnc);
20521 if (options.pub)
20522 this._importPublic(options.pub, options.pubEnc);
20523}
20524module.exports = KeyPair;
20525
20526KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
20527 if (pub instanceof KeyPair)
20528 return pub;
20529
20530 return new KeyPair(ec, {
20531 pub: pub,
20532 pubEnc: enc
20533 });
20534};
20535
20536KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
20537 if (priv instanceof KeyPair)
20538 return priv;
20539
20540 return new KeyPair(ec, {
20541 priv: priv,
20542 privEnc: enc
20543 });
20544};
20545
20546KeyPair.prototype.validate = function validate() {
20547 var pub = this.getPublic();
20548
20549 if (pub.isInfinity())
20550 return { result: false, reason: 'Invalid public key' };
20551 if (!pub.validate())
20552 return { result: false, reason: 'Public key is not a point' };
20553 if (!pub.mul(this.ec.curve.n).isInfinity())
20554 return { result: false, reason: 'Public key * N != O' };
20555
20556 return { result: true, reason: null };
20557};
20558
20559KeyPair.prototype.getPublic = function getPublic(compact, enc) {
20560 // compact is optional argument
20561 if (typeof compact === 'string') {
20562 enc = compact;
20563 compact = null;
20564 }
20565
20566 if (!this.pub)
20567 this.pub = this.ec.g.mul(this.priv);
20568
20569 if (!enc)
20570 return this.pub;
20571
20572 return this.pub.encode(enc, compact);
20573};
20574
20575KeyPair.prototype.getPrivate = function getPrivate(enc) {
20576 if (enc === 'hex')
20577 return this.priv.toString(16, 2);
20578 else
20579 return this.priv;
20580};
20581
20582KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
20583 this.priv = new BN(key, enc || 16);
20584
20585 // Ensure that the priv won't be bigger than n, otherwise we may fail
20586 // in fixed multiplication method
20587 this.priv = this.priv.umod(this.ec.curve.n);
20588};
20589
20590KeyPair.prototype._importPublic = function _importPublic(key, enc) {
20591 if (key.x || key.y) {
20592 // Montgomery points only have an `x` coordinate.
20593 // Weierstrass/Edwards points on the other hand have both `x` and
20594 // `y` coordinates.
20595 if (this.ec.curve.type === 'mont') {
20596 assert(key.x, 'Need x coordinate');
20597 } else if (this.ec.curve.type === 'short' ||
20598 this.ec.curve.type === 'edwards') {
20599 assert(key.x && key.y, 'Need both x and y coordinate');
20600 }
20601 this.pub = this.ec.curve.point(key.x, key.y);
20602 return;
20603 }
20604 this.pub = this.ec.curve.decodePoint(key, enc);
20605};
20606
20607// ECDH
20608KeyPair.prototype.derive = function derive(pub) {
20609 return pub.mul(this.priv).getX();
20610};
20611
20612// ECDSA
20613KeyPair.prototype.sign = function sign(msg, enc, options) {
20614 return this.ec.sign(msg, this, enc, options);
20615};
20616
20617KeyPair.prototype.verify = function verify(msg, signature) {
20618 return this.ec.verify(msg, signature, this);
20619};
20620
20621KeyPair.prototype.inspect = function inspect() {
20622 return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
20623 ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
20624};
20625
20626},{"../utils":143,"bn.js":79}],138:[function(require,module,exports){
20627'use strict';
20628
20629var BN = require('bn.js');
20630
20631var utils = require('../utils');
20632var assert = utils.assert;
20633
20634function Signature(options, enc) {
20635 if (options instanceof Signature)
20636 return options;
20637
20638 if (this._importDER(options, enc))
20639 return;
20640
20641 assert(options.r && options.s, 'Signature without r or s');
20642 this.r = new BN(options.r, 16);
20643 this.s = new BN(options.s, 16);
20644 if (options.recoveryParam === undefined)
20645 this.recoveryParam = null;
20646 else
20647 this.recoveryParam = options.recoveryParam;
20648}
20649module.exports = Signature;
20650
20651function Position() {
20652 this.place = 0;
20653}
20654
20655function getLength(buf, p) {
20656 var initial = buf[p.place++];
20657 if (!(initial & 0x80)) {
20658 return initial;
20659 }
20660 var octetLen = initial & 0xf;
20661 var val = 0;
20662 for (var i = 0, off = p.place; i < octetLen; i++, off++) {
20663 val <<= 8;
20664 val |= buf[off];
20665 }
20666 p.place = off;
20667 return val;
20668}
20669
20670function rmPadding(buf) {
20671 var i = 0;
20672 var len = buf.length - 1;
20673 while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
20674 i++;
20675 }
20676 if (i === 0) {
20677 return buf;
20678 }
20679 return buf.slice(i);
20680}
20681
20682Signature.prototype._importDER = function _importDER(data, enc) {
20683 data = utils.toArray(data, enc);
20684 var p = new Position();
20685 if (data[p.place++] !== 0x30) {
20686 return false;
20687 }
20688 var len = getLength(data, p);
20689 if ((len + p.place) !== data.length) {
20690 return false;
20691 }
20692 if (data[p.place++] !== 0x02) {
20693 return false;
20694 }
20695 var rlen = getLength(data, p);
20696 var r = data.slice(p.place, rlen + p.place);
20697 p.place += rlen;
20698 if (data[p.place++] !== 0x02) {
20699 return false;
20700 }
20701 var slen = getLength(data, p);
20702 if (data.length !== slen + p.place) {
20703 return false;
20704 }
20705 var s = data.slice(p.place, slen + p.place);
20706 if (r[0] === 0 && (r[1] & 0x80)) {
20707 r = r.slice(1);
20708 }
20709 if (s[0] === 0 && (s[1] & 0x80)) {
20710 s = s.slice(1);
20711 }
20712
20713 this.r = new BN(r);
20714 this.s = new BN(s);
20715 this.recoveryParam = null;
20716
20717 return true;
20718};
20719
20720function constructLength(arr, len) {
20721 if (len < 0x80) {
20722 arr.push(len);
20723 return;
20724 }
20725 var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
20726 arr.push(octets | 0x80);
20727 while (--octets) {
20728 arr.push((len >>> (octets << 3)) & 0xff);
20729 }
20730 arr.push(len);
20731}
20732
20733Signature.prototype.toDER = function toDER(enc) {
20734 var r = this.r.toArray();
20735 var s = this.s.toArray();
20736
20737 // Pad values
20738 if (r[0] & 0x80)
20739 r = [ 0 ].concat(r);
20740 // Pad values
20741 if (s[0] & 0x80)
20742 s = [ 0 ].concat(s);
20743
20744 r = rmPadding(r);
20745 s = rmPadding(s);
20746
20747 while (!s[0] && !(s[1] & 0x80)) {
20748 s = s.slice(1);
20749 }
20750 var arr = [ 0x02 ];
20751 constructLength(arr, r.length);
20752 arr = arr.concat(r);
20753 arr.push(0x02);
20754 constructLength(arr, s.length);
20755 var backHalf = arr.concat(s);
20756 var res = [ 0x30 ];
20757 constructLength(res, backHalf.length);
20758 res = res.concat(backHalf);
20759 return utils.encode(res, enc);
20760};
20761
20762},{"../utils":143,"bn.js":79}],139:[function(require,module,exports){
20763'use strict';
20764
20765var hash = require('hash.js');
20766var curves = require('../curves');
20767var utils = require('../utils');
20768var assert = utils.assert;
20769var parseBytes = utils.parseBytes;
20770var KeyPair = require('./key');
20771var Signature = require('./signature');
20772
20773function EDDSA(curve) {
20774 assert(curve === 'ed25519', 'only tested with ed25519 so far');
20775
20776 if (!(this instanceof EDDSA))
20777 return new EDDSA(curve);
20778
20779 var curve = curves[curve].curve;
20780 this.curve = curve;
20781 this.g = curve.g;
20782 this.g.precompute(curve.n.bitLength() + 1);
20783
20784 this.pointClass = curve.point().constructor;
20785 this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
20786 this.hash = hash.sha512;
20787}
20788
20789module.exports = EDDSA;
20790
20791/**
20792* @param {Array|String} message - message bytes
20793* @param {Array|String|KeyPair} secret - secret bytes or a keypair
20794* @returns {Signature} - signature
20795*/
20796EDDSA.prototype.sign = function sign(message, secret) {
20797 message = parseBytes(message);
20798 var key = this.keyFromSecret(secret);
20799 var r = this.hashInt(key.messagePrefix(), message);
20800 var R = this.g.mul(r);
20801 var Rencoded = this.encodePoint(R);
20802 var s_ = this.hashInt(Rencoded, key.pubBytes(), message)
20803 .mul(key.priv());
20804 var S = r.add(s_).umod(this.curve.n);
20805 return this.makeSignature({ R: R, S: S, Rencoded: Rencoded });
20806};
20807
20808/**
20809* @param {Array} message - message bytes
20810* @param {Array|String|Signature} sig - sig bytes
20811* @param {Array|String|Point|KeyPair} pub - public key
20812* @returns {Boolean} - true if public key matches sig of message
20813*/
20814EDDSA.prototype.verify = function verify(message, sig, pub) {
20815 message = parseBytes(message);
20816 sig = this.makeSignature(sig);
20817 var key = this.keyFromPublic(pub);
20818 var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
20819 var SG = this.g.mul(sig.S());
20820 var RplusAh = sig.R().add(key.pub().mul(h));
20821 return RplusAh.eq(SG);
20822};
20823
20824EDDSA.prototype.hashInt = function hashInt() {
20825 var hash = this.hash();
20826 for (var i = 0; i < arguments.length; i++)
20827 hash.update(arguments[i]);
20828 return utils.intFromLE(hash.digest()).umod(this.curve.n);
20829};
20830
20831EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
20832 return KeyPair.fromPublic(this, pub);
20833};
20834
20835EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
20836 return KeyPair.fromSecret(this, secret);
20837};
20838
20839EDDSA.prototype.makeSignature = function makeSignature(sig) {
20840 if (sig instanceof Signature)
20841 return sig;
20842 return new Signature(this, sig);
20843};
20844
20845/**
20846* * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
20847*
20848* EDDSA defines methods for encoding and decoding points and integers. These are
20849* helper convenience methods, that pass along to utility functions implied
20850* parameters.
20851*
20852*/
20853EDDSA.prototype.encodePoint = function encodePoint(point) {
20854 var enc = point.getY().toArray('le', this.encodingLength);
20855 enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
20856 return enc;
20857};
20858
20859EDDSA.prototype.decodePoint = function decodePoint(bytes) {
20860 bytes = utils.parseBytes(bytes);
20861
20862 var lastIx = bytes.length - 1;
20863 var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
20864 var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
20865
20866 var y = utils.intFromLE(normed);
20867 return this.curve.pointFromY(y, xIsOdd);
20868};
20869
20870EDDSA.prototype.encodeInt = function encodeInt(num) {
20871 return num.toArray('le', this.encodingLength);
20872};
20873
20874EDDSA.prototype.decodeInt = function decodeInt(bytes) {
20875 return utils.intFromLE(bytes);
20876};
20877
20878EDDSA.prototype.isPoint = function isPoint(val) {
20879 return val instanceof this.pointClass;
20880};
20881
20882},{"../curves":135,"../utils":143,"./key":140,"./signature":141,"hash.js":148}],140:[function(require,module,exports){
20883'use strict';
20884
20885var utils = require('../utils');
20886var assert = utils.assert;
20887var parseBytes = utils.parseBytes;
20888var cachedProperty = utils.cachedProperty;
20889
20890/**
20891* @param {EDDSA} eddsa - instance
20892* @param {Object} params - public/private key parameters
20893*
20894* @param {Array<Byte>} [params.secret] - secret seed bytes
20895* @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
20896* @param {Array<Byte>} [params.pub] - public key point encoded as bytes
20897*
20898*/
20899function KeyPair(eddsa, params) {
20900 this.eddsa = eddsa;
20901 this._secret = parseBytes(params.secret);
20902 if (eddsa.isPoint(params.pub))
20903 this._pub = params.pub;
20904 else
20905 this._pubBytes = parseBytes(params.pub);
20906}
20907
20908KeyPair.fromPublic = function fromPublic(eddsa, pub) {
20909 if (pub instanceof KeyPair)
20910 return pub;
20911 return new KeyPair(eddsa, { pub: pub });
20912};
20913
20914KeyPair.fromSecret = function fromSecret(eddsa, secret) {
20915 if (secret instanceof KeyPair)
20916 return secret;
20917 return new KeyPair(eddsa, { secret: secret });
20918};
20919
20920KeyPair.prototype.secret = function secret() {
20921 return this._secret;
20922};
20923
20924cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
20925 return this.eddsa.encodePoint(this.pub());
20926});
20927
20928cachedProperty(KeyPair, 'pub', function pub() {
20929 if (this._pubBytes)
20930 return this.eddsa.decodePoint(this._pubBytes);
20931 return this.eddsa.g.mul(this.priv());
20932});
20933
20934cachedProperty(KeyPair, 'privBytes', function privBytes() {
20935 var eddsa = this.eddsa;
20936 var hash = this.hash();
20937 var lastIx = eddsa.encodingLength - 1;
20938
20939 var a = hash.slice(0, eddsa.encodingLength);
20940 a[0] &= 248;
20941 a[lastIx] &= 127;
20942 a[lastIx] |= 64;
20943
20944 return a;
20945});
20946
20947cachedProperty(KeyPair, 'priv', function priv() {
20948 return this.eddsa.decodeInt(this.privBytes());
20949});
20950
20951cachedProperty(KeyPair, 'hash', function hash() {
20952 return this.eddsa.hash().update(this.secret()).digest();
20953});
20954
20955cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
20956 return this.hash().slice(this.eddsa.encodingLength);
20957});
20958
20959KeyPair.prototype.sign = function sign(message) {
20960 assert(this._secret, 'KeyPair can only verify');
20961 return this.eddsa.sign(message, this);
20962};
20963
20964KeyPair.prototype.verify = function verify(message, sig) {
20965 return this.eddsa.verify(message, sig, this);
20966};
20967
20968KeyPair.prototype.getSecret = function getSecret(enc) {
20969 assert(this._secret, 'KeyPair is public only');
20970 return utils.encode(this.secret(), enc);
20971};
20972
20973KeyPair.prototype.getPublic = function getPublic(enc) {
20974 return utils.encode(this.pubBytes(), enc);
20975};
20976
20977module.exports = KeyPair;
20978
20979},{"../utils":143}],141:[function(require,module,exports){
20980'use strict';
20981
20982var BN = require('bn.js');
20983var utils = require('../utils');
20984var assert = utils.assert;
20985var cachedProperty = utils.cachedProperty;
20986var parseBytes = utils.parseBytes;
20987
20988/**
20989* @param {EDDSA} eddsa - eddsa instance
20990* @param {Array<Bytes>|Object} sig -
20991* @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
20992* @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
20993* @param {Array<Bytes>} [sig.Rencoded] - R point encoded
20994* @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
20995*/
20996function Signature(eddsa, sig) {
20997 this.eddsa = eddsa;
20998
20999 if (typeof sig !== 'object')
21000 sig = parseBytes(sig);
21001
21002 if (Array.isArray(sig)) {
21003 sig = {
21004 R: sig.slice(0, eddsa.encodingLength),
21005 S: sig.slice(eddsa.encodingLength)
21006 };
21007 }
21008
21009 assert(sig.R && sig.S, 'Signature without R or S');
21010
21011 if (eddsa.isPoint(sig.R))
21012 this._R = sig.R;
21013 if (sig.S instanceof BN)
21014 this._S = sig.S;
21015
21016 this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
21017 this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
21018}
21019
21020cachedProperty(Signature, 'S', function S() {
21021 return this.eddsa.decodeInt(this.Sencoded());
21022});
21023
21024cachedProperty(Signature, 'R', function R() {
21025 return this.eddsa.decodePoint(this.Rencoded());
21026});
21027
21028cachedProperty(Signature, 'Rencoded', function Rencoded() {
21029 return this.eddsa.encodePoint(this.R());
21030});
21031
21032cachedProperty(Signature, 'Sencoded', function Sencoded() {
21033 return this.eddsa.encodeInt(this.S());
21034});
21035
21036Signature.prototype.toBytes = function toBytes() {
21037 return this.Rencoded().concat(this.Sencoded());
21038};
21039
21040Signature.prototype.toHex = function toHex() {
21041 return utils.encode(this.toBytes(), 'hex').toUpperCase();
21042};
21043
21044module.exports = Signature;
21045
21046},{"../utils":143,"bn.js":79}],142:[function(require,module,exports){
21047module.exports = {
21048 doubles: {
21049 step: 4,
21050 points: [
21051 [
21052 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
21053 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
21054 ],
21055 [
21056 '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
21057 '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
21058 ],
21059 [
21060 '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
21061 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
21062 ],
21063 [
21064 '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
21065 '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
21066 ],
21067 [
21068 '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
21069 '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
21070 ],
21071 [
21072 '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
21073 '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
21074 ],
21075 [
21076 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
21077 '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
21078 ],
21079 [
21080 '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
21081 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
21082 ],
21083 [
21084 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
21085 '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
21086 ],
21087 [
21088 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
21089 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
21090 ],
21091 [
21092 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
21093 '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
21094 ],
21095 [
21096 '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
21097 '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
21098 ],
21099 [
21100 '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
21101 '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
21102 ],
21103 [
21104 '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
21105 '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
21106 ],
21107 [
21108 '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
21109 '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
21110 ],
21111 [
21112 '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
21113 '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
21114 ],
21115 [
21116 '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
21117 '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
21118 ],
21119 [
21120 '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
21121 '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
21122 ],
21123 [
21124 '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
21125 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
21126 ],
21127 [
21128 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
21129 '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
21130 ],
21131 [
21132 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
21133 '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
21134 ],
21135 [
21136 '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
21137 '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
21138 ],
21139 [
21140 '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
21141 '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
21142 ],
21143 [
21144 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
21145 '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
21146 ],
21147 [
21148 '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
21149 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
21150 ],
21151 [
21152 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
21153 '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
21154 ],
21155 [
21156 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
21157 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
21158 ],
21159 [
21160 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
21161 '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
21162 ],
21163 [
21164 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
21165 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
21166 ],
21167 [
21168 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
21169 '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
21170 ],
21171 [
21172 '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
21173 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
21174 ],
21175 [
21176 '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
21177 '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
21178 ],
21179 [
21180 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
21181 '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
21182 ],
21183 [
21184 '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
21185 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
21186 ],
21187 [
21188 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
21189 '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
21190 ],
21191 [
21192 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
21193 '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
21194 ],
21195 [
21196 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
21197 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
21198 ],
21199 [
21200 '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
21201 '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
21202 ],
21203 [
21204 '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
21205 '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
21206 ],
21207 [
21208 '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
21209 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
21210 ],
21211 [
21212 '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
21213 '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
21214 ],
21215 [
21216 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
21217 '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
21218 ],
21219 [
21220 '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
21221 '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
21222 ],
21223 [
21224 '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
21225 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
21226 ],
21227 [
21228 '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
21229 '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
21230 ],
21231 [
21232 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
21233 '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
21234 ],
21235 [
21236 '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
21237 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
21238 ],
21239 [
21240 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
21241 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
21242 ],
21243 [
21244 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
21245 '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
21246 ],
21247 [
21248 '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
21249 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
21250 ],
21251 [
21252 '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
21253 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
21254 ],
21255 [
21256 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
21257 '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
21258 ],
21259 [
21260 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
21261 '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
21262 ],
21263 [
21264 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
21265 '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
21266 ],
21267 [
21268 '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
21269 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
21270 ],
21271 [
21272 '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
21273 '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
21274 ],
21275 [
21276 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
21277 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
21278 ],
21279 [
21280 '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
21281 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
21282 ],
21283 [
21284 '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
21285 '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
21286 ],
21287 [
21288 '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
21289 '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
21290 ],
21291 [
21292 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
21293 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
21294 ],
21295 [
21296 '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
21297 '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
21298 ],
21299 [
21300 '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
21301 '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
21302 ],
21303 [
21304 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
21305 '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
21306 ],
21307 [
21308 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
21309 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
21310 ]
21311 ]
21312 },
21313 naf: {
21314 wnd: 7,
21315 points: [
21316 [
21317 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
21318 '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
21319 ],
21320 [
21321 '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
21322 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
21323 ],
21324 [
21325 '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
21326 '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
21327 ],
21328 [
21329 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
21330 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
21331 ],
21332 [
21333 '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
21334 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
21335 ],
21336 [
21337 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
21338 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
21339 ],
21340 [
21341 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
21342 '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
21343 ],
21344 [
21345 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
21346 '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
21347 ],
21348 [
21349 '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
21350 '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
21351 ],
21352 [
21353 '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
21354 '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
21355 ],
21356 [
21357 '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
21358 '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
21359 ],
21360 [
21361 '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
21362 '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
21363 ],
21364 [
21365 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
21366 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
21367 ],
21368 [
21369 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
21370 '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
21371 ],
21372 [
21373 '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
21374 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
21375 ],
21376 [
21377 '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
21378 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
21379 ],
21380 [
21381 '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
21382 '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
21383 ],
21384 [
21385 '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
21386 '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
21387 ],
21388 [
21389 '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
21390 '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
21391 ],
21392 [
21393 '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
21394 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
21395 ],
21396 [
21397 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
21398 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
21399 ],
21400 [
21401 '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
21402 '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
21403 ],
21404 [
21405 '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
21406 '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
21407 ],
21408 [
21409 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
21410 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
21411 ],
21412 [
21413 '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
21414 '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
21415 ],
21416 [
21417 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
21418 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
21419 ],
21420 [
21421 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
21422 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
21423 ],
21424 [
21425 '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
21426 '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
21427 ],
21428 [
21429 '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
21430 '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
21431 ],
21432 [
21433 '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
21434 '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
21435 ],
21436 [
21437 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
21438 '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
21439 ],
21440 [
21441 '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
21442 '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
21443 ],
21444 [
21445 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
21446 '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
21447 ],
21448 [
21449 '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
21450 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
21451 ],
21452 [
21453 '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
21454 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
21455 ],
21456 [
21457 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
21458 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
21459 ],
21460 [
21461 '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
21462 '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
21463 ],
21464 [
21465 '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
21466 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
21467 ],
21468 [
21469 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
21470 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
21471 ],
21472 [
21473 '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
21474 '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
21475 ],
21476 [
21477 '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
21478 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
21479 ],
21480 [
21481 '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
21482 '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
21483 ],
21484 [
21485 '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
21486 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
21487 ],
21488 [
21489 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
21490 '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
21491 ],
21492 [
21493 '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
21494 '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
21495 ],
21496 [
21497 '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
21498 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
21499 ],
21500 [
21501 '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
21502 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
21503 ],
21504 [
21505 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
21506 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
21507 ],
21508 [
21509 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
21510 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
21511 ],
21512 [
21513 '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
21514 '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
21515 ],
21516 [
21517 '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
21518 '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
21519 ],
21520 [
21521 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
21522 '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
21523 ],
21524 [
21525 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
21526 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
21527 ],
21528 [
21529 '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
21530 '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
21531 ],
21532 [
21533 '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
21534 '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
21535 ],
21536 [
21537 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
21538 '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
21539 ],
21540 [
21541 '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
21542 '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
21543 ],
21544 [
21545 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
21546 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
21547 ],
21548 [
21549 '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
21550 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
21551 ],
21552 [
21553 '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
21554 '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
21555 ],
21556 [
21557 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
21558 '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
21559 ],
21560 [
21561 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
21562 '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
21563 ],
21564 [
21565 '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
21566 '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
21567 ],
21568 [
21569 '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
21570 '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
21571 ],
21572 [
21573 '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
21574 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
21575 ],
21576 [
21577 '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
21578 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
21579 ],
21580 [
21581 '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
21582 '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
21583 ],
21584 [
21585 '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
21586 '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
21587 ],
21588 [
21589 '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
21590 '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
21591 ],
21592 [
21593 '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
21594 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
21595 ],
21596 [
21597 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
21598 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
21599 ],
21600 [
21601 '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
21602 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
21603 ],
21604 [
21605 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
21606 '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
21607 ],
21608 [
21609 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
21610 '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
21611 ],
21612 [
21613 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
21614 '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
21615 ],
21616 [
21617 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
21618 '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
21619 ],
21620 [
21621 '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
21622 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
21623 ],
21624 [
21625 '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
21626 '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
21627 ],
21628 [
21629 '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
21630 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
21631 ],
21632 [
21633 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
21634 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
21635 ],
21636 [
21637 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
21638 '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
21639 ],
21640 [
21641 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
21642 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
21643 ],
21644 [
21645 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
21646 '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
21647 ],
21648 [
21649 '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
21650 '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
21651 ],
21652 [
21653 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
21654 '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
21655 ],
21656 [
21657 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
21658 '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
21659 ],
21660 [
21661 '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
21662 '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
21663 ],
21664 [
21665 '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
21666 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
21667 ],
21668 [
21669 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
21670 '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
21671 ],
21672 [
21673 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
21674 '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
21675 ],
21676 [
21677 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
21678 '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
21679 ],
21680 [
21681 '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
21682 '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
21683 ],
21684 [
21685 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
21686 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
21687 ],
21688 [
21689 '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
21690 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
21691 ],
21692 [
21693 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
21694 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
21695 ],
21696 [
21697 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
21698 '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
21699 ],
21700 [
21701 '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
21702 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
21703 ],
21704 [
21705 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
21706 '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
21707 ],
21708 [
21709 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
21710 '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
21711 ],
21712 [
21713 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
21714 '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
21715 ],
21716 [
21717 '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
21718 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
21719 ],
21720 [
21721 '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
21722 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
21723 ],
21724 [
21725 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
21726 '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
21727 ],
21728 [
21729 '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
21730 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
21731 ],
21732 [
21733 '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
21734 '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
21735 ],
21736 [
21737 '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
21738 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
21739 ],
21740 [
21741 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
21742 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
21743 ],
21744 [
21745 '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
21746 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
21747 ],
21748 [
21749 '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
21750 '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
21751 ],
21752 [
21753 '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
21754 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
21755 ],
21756 [
21757 '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
21758 '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
21759 ],
21760 [
21761 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
21762 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
21763 ],
21764 [
21765 '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
21766 '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
21767 ],
21768 [
21769 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
21770 '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
21771 ],
21772 [
21773 '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
21774 '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
21775 ],
21776 [
21777 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
21778 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
21779 ],
21780 [
21781 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
21782 '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
21783 ],
21784 [
21785 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
21786 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
21787 ],
21788 [
21789 '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
21790 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
21791 ],
21792 [
21793 '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
21794 '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
21795 ],
21796 [
21797 '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
21798 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
21799 ],
21800 [
21801 '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
21802 '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
21803 ],
21804 [
21805 '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
21806 '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
21807 ],
21808 [
21809 '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
21810 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
21811 ],
21812 [
21813 '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
21814 '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
21815 ],
21816 [
21817 '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
21818 '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
21819 ],
21820 [
21821 '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
21822 '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
21823 ]
21824 ]
21825 }
21826};
21827
21828},{}],143:[function(require,module,exports){
21829'use strict';
21830
21831var utils = exports;
21832var BN = require('bn.js');
21833var minAssert = require('minimalistic-assert');
21834var minUtils = require('minimalistic-crypto-utils');
21835
21836utils.assert = minAssert;
21837utils.toArray = minUtils.toArray;
21838utils.zero2 = minUtils.zero2;
21839utils.toHex = minUtils.toHex;
21840utils.encode = minUtils.encode;
21841
21842// Represent num in a w-NAF form
21843function getNAF(num, w) {
21844 var naf = [];
21845 var ws = 1 << (w + 1);
21846 var k = num.clone();
21847 while (k.cmpn(1) >= 0) {
21848 var z;
21849 if (k.isOdd()) {
21850 var mod = k.andln(ws - 1);
21851 if (mod > (ws >> 1) - 1)
21852 z = (ws >> 1) - mod;
21853 else
21854 z = mod;
21855 k.isubn(z);
21856 } else {
21857 z = 0;
21858 }
21859 naf.push(z);
21860
21861 // Optimization, shift by word if possible
21862 var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
21863 for (var i = 1; i < shift; i++)
21864 naf.push(0);
21865 k.iushrn(shift);
21866 }
21867
21868 return naf;
21869}
21870utils.getNAF = getNAF;
21871
21872// Represent k1, k2 in a Joint Sparse Form
21873function getJSF(k1, k2) {
21874 var jsf = [
21875 [],
21876 []
21877 ];
21878
21879 k1 = k1.clone();
21880 k2 = k2.clone();
21881 var d1 = 0;
21882 var d2 = 0;
21883 while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
21884
21885 // First phase
21886 var m14 = (k1.andln(3) + d1) & 3;
21887 var m24 = (k2.andln(3) + d2) & 3;
21888 if (m14 === 3)
21889 m14 = -1;
21890 if (m24 === 3)
21891 m24 = -1;
21892 var u1;
21893 if ((m14 & 1) === 0) {
21894 u1 = 0;
21895 } else {
21896 var m8 = (k1.andln(7) + d1) & 7;
21897 if ((m8 === 3 || m8 === 5) && m24 === 2)
21898 u1 = -m14;
21899 else
21900 u1 = m14;
21901 }
21902 jsf[0].push(u1);
21903
21904 var u2;
21905 if ((m24 & 1) === 0) {
21906 u2 = 0;
21907 } else {
21908 var m8 = (k2.andln(7) + d2) & 7;
21909 if ((m8 === 3 || m8 === 5) && m14 === 2)
21910 u2 = -m24;
21911 else
21912 u2 = m24;
21913 }
21914 jsf[1].push(u2);
21915
21916 // Second phase
21917 if (2 * d1 === u1 + 1)
21918 d1 = 1 - d1;
21919 if (2 * d2 === u2 + 1)
21920 d2 = 1 - d2;
21921 k1.iushrn(1);
21922 k2.iushrn(1);
21923 }
21924
21925 return jsf;
21926}
21927utils.getJSF = getJSF;
21928
21929function cachedProperty(obj, name, computer) {
21930 var key = '_' + name;
21931 obj.prototype[name] = function cachedProperty() {
21932 return this[key] !== undefined ? this[key] :
21933 this[key] = computer.call(this);
21934 };
21935}
21936utils.cachedProperty = cachedProperty;
21937
21938function parseBytes(bytes) {
21939 return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
21940 bytes;
21941}
21942utils.parseBytes = parseBytes;
21943
21944function intFromLE(bytes) {
21945 return new BN(bytes, 'hex', 'le');
21946}
21947utils.intFromLE = intFromLE;
21948
21949
21950},{"bn.js":79,"minimalistic-assert":167,"minimalistic-crypto-utils":168}],144:[function(require,module,exports){
21951module.exports={
21952 "_args": [
21953 [
21954 "elliptic@^6.0.0",
21955 "/usr/local/lib/node_modules/browserify/node_modules/browserify-sign"
21956 ]
21957 ],
21958 "_from": "elliptic@>=6.0.0 <7.0.0",
21959 "_hasShrinkwrap": false,
21960 "_id": "elliptic@6.5.0",
21961 "_inCache": true,
21962 "_installable": true,
21963 "_location": "/browserify/elliptic",
21964 "_nodeVersion": "12.2.0",
21965 "_npmOperationalInternal": {
21966 "host": "s3://npm-registry-packages",
21967 "tmp": "tmp/elliptic_6.5.0_1561521826385_0.20848274510512943"
21968 },
21969 "_npmUser": {
21970 "email": "fedor@indutny.com",
21971 "name": "indutny"
21972 },
21973 "_npmVersion": "6.9.0",
21974 "_phantomChildren": {},
21975 "_requested": {
21976 "name": "elliptic",
21977 "raw": "elliptic@^6.0.0",
21978 "rawSpec": "^6.0.0",
21979 "scope": null,
21980 "spec": ">=6.0.0 <7.0.0",
21981 "type": "range"
21982 },
21983 "_requiredBy": [
21984 "/browserify/browserify-sign",
21985 "/browserify/create-ecdh"
21986 ],
21987 "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz",
21988 "_shasum": "2b8ed4c891b7de3200e14412a5b8248c7af505ca",
21989 "_shrinkwrap": null,
21990 "_spec": "elliptic@^6.0.0",
21991 "_where": "/usr/local/lib/node_modules/browserify/node_modules/browserify-sign",
21992 "author": {
21993 "email": "fedor@indutny.com",
21994 "name": "Fedor Indutny"
21995 },
21996 "bugs": {
21997 "url": "https://github.com/indutny/elliptic/issues"
21998 },
21999 "dependencies": {
22000 "bn.js": "^4.4.0",
22001 "brorand": "^1.0.1",
22002 "hash.js": "^1.0.0",
22003 "hmac-drbg": "^1.0.0",
22004 "inherits": "^2.0.1",
22005 "minimalistic-assert": "^1.0.0",
22006 "minimalistic-crypto-utils": "^1.0.0"
22007 },
22008 "description": "EC cryptography",
22009 "devDependencies": {
22010 "brfs": "^1.4.3",
22011 "coveralls": "^2.11.3",
22012 "grunt": "^0.4.5",
22013 "grunt-browserify": "^5.0.0",
22014 "grunt-cli": "^1.2.0",
22015 "grunt-contrib-connect": "^1.0.0",
22016 "grunt-contrib-copy": "^1.0.0",
22017 "grunt-contrib-uglify": "^1.0.1",
22018 "grunt-mocha-istanbul": "^3.0.1",
22019 "grunt-saucelabs": "^8.6.2",
22020 "istanbul": "^0.4.2",
22021 "jscs": "^2.9.0",
22022 "jshint": "^2.6.0",
22023 "mocha": "^2.1.0"
22024 },
22025 "directories": {},
22026 "dist": {
22027 "fileCount": 17,
22028 "integrity": "sha512-eFOJTMyCYb7xtE/caJ6JJu+bhi67WCYNbkGSknu20pmM8Ke/bqOfdnZWxyoGN26JgfxTbXrsCkEw4KheCT/KGg==",
22029 "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdEu6jCRA9TVsSAnZWagAAJh4QAJXJ18MReidNMHrxFJGv\ngSONMB2uz0lWJ7eEUyggaCA/Tr6w4RBA6Ilne0Wou3jTAGou+GClpAde6Hkb\nEq1iq1brx+5gHeY3rGs8GB+T3c1JsVz+2t6934esXGM6IJNmG91TaCMSbuwQ\nTWHD62RxFylLYjffBIWt6KLximZnXcvAES0Qu7VUql1SlfvmGtaHlQAhvtLj\nG+ayBnSnWMcEvDPJdfnKi67PlGMa334spEmWzcqobFySr+y/ufiZRCp+wiSl\ndCwbFNMaH4fue+dhq1m7jGO/euFQvJw2Jf32zT/ToaM768nH8yHrrZ8lMRjs\ngCUymge8kbI5W1WA8wla7+J52Exbo6LbcBqSupVhVw6gXkOdjQCOkywBXa1c\nPiFxwOUSfdFATpkUi3/8serYCgv9NgGzvQ0rjej0//1+he6q7UUyKn9wyrdH\nMntmi18UgyQ8c1NrshKAOCb1oeniCEv7B1adfH2axH9uvMiVP8N5BMfAUNE1\nnkCD3lDXRz/7C+90DiI+h2MS3+az8ciqMTbpKlw3HrmUyCex+KvLq9+wNLGf\nyaJGd/r6NT0pu36v0M2+ul266/RbbY6D1ED/cl8gDZRFTT/SfTCkU+QAn2Mg\nfAlnn9BXogYR1XM1GNrnGUVkY7ngORiAGez5DU7P93jMpdSS9OtwAHHi1Oto\nbZ+X\r\n=LuMF\r\n-----END PGP SIGNATURE-----\r\n",
22030 "shasum": "2b8ed4c891b7de3200e14412a5b8248c7af505ca",
22031 "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz",
22032 "unpackedSize": 118006
22033 },
22034 "gitHead": "475f066aebd14681591f0f0f18a2abc0ded8c390",
22035 "homepage": "https://github.com/indutny/elliptic",
22036 "keywords": [
22037 "Cryptography",
22038 "EC",
22039 "Elliptic",
22040 "curve"
22041 ],
22042 "license": "MIT",
22043 "main": "lib/elliptic.js",
22044 "maintainers": [
22045 {
22046 "name": "indutny",
22047 "email": "fedor@indutny.com"
22048 }
22049 ],
22050 "name": "elliptic",
22051 "optionalDependencies": {},
22052 "readme": "ERROR: No README data found!",
22053 "repository": {
22054 "type": "git",
22055 "url": "git+ssh://git@github.com/indutny/elliptic.git"
22056 },
22057 "scripts": {
22058 "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
22059 "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
22060 "lint": "npm run jscs && npm run jshint",
22061 "test": "npm run lint && npm run unit",
22062 "unit": "istanbul test _mocha --reporter=spec test/index.js",
22063 "version": "grunt dist && git add dist/"
22064 },
22065 "version": "6.5.0"
22066}
22067
22068},{}],145:[function(require,module,exports){
22069// Copyright Joyent, Inc. and other Node contributors.
22070//
22071// Permission is hereby granted, free of charge, to any person obtaining a
22072// copy of this software and associated documentation files (the
22073// "Software"), to deal in the Software without restriction, including
22074// without limitation the rights to use, copy, modify, merge, publish,
22075// distribute, sublicense, and/or sell copies of the Software, and to permit
22076// persons to whom the Software is furnished to do so, subject to the
22077// following conditions:
22078//
22079// The above copyright notice and this permission notice shall be included
22080// in all copies or substantial portions of the Software.
22081//
22082// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22083// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22084// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
22085// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22086// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22087// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22088// USE OR OTHER DEALINGS IN THE SOFTWARE.
22089
22090var objectCreate = Object.create || objectCreatePolyfill
22091var objectKeys = Object.keys || objectKeysPolyfill
22092var bind = Function.prototype.bind || functionBindPolyfill
22093
22094function EventEmitter() {
22095 if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
22096 this._events = objectCreate(null);
22097 this._eventsCount = 0;
22098 }
22099
22100 this._maxListeners = this._maxListeners || undefined;
22101}
22102module.exports = EventEmitter;
22103
22104// Backwards-compat with node 0.10.x
22105EventEmitter.EventEmitter = EventEmitter;
22106
22107EventEmitter.prototype._events = undefined;
22108EventEmitter.prototype._maxListeners = undefined;
22109
22110// By default EventEmitters will print a warning if more than 10 listeners are
22111// added to it. This is a useful default which helps finding memory leaks.
22112var defaultMaxListeners = 10;
22113
22114var hasDefineProperty;
22115try {
22116 var o = {};
22117 if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
22118 hasDefineProperty = o.x === 0;
22119} catch (err) { hasDefineProperty = false }
22120if (hasDefineProperty) {
22121 Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
22122 enumerable: true,
22123 get: function() {
22124 return defaultMaxListeners;
22125 },
22126 set: function(arg) {
22127 // check whether the input is a positive number (whose value is zero or
22128 // greater and not a NaN).
22129 if (typeof arg !== 'number' || arg < 0 || arg !== arg)
22130 throw new TypeError('"defaultMaxListeners" must be a positive number');
22131 defaultMaxListeners = arg;
22132 }
22133 });
22134} else {
22135 EventEmitter.defaultMaxListeners = defaultMaxListeners;
22136}
22137
22138// Obviously not all Emitters should be limited to 10. This function allows
22139// that to be increased. Set to zero for unlimited.
22140EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
22141 if (typeof n !== 'number' || n < 0 || isNaN(n))
22142 throw new TypeError('"n" argument must be a positive number');
22143 this._maxListeners = n;
22144 return this;
22145};
22146
22147function $getMaxListeners(that) {
22148 if (that._maxListeners === undefined)
22149 return EventEmitter.defaultMaxListeners;
22150 return that._maxListeners;
22151}
22152
22153EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
22154 return $getMaxListeners(this);
22155};
22156
22157// These standalone emit* functions are used to optimize calling of event
22158// handlers for fast cases because emit() itself often has a variable number of
22159// arguments and can be deoptimized because of that. These functions always have
22160// the same number of arguments and thus do not get deoptimized, so the code
22161// inside them can execute faster.
22162function emitNone(handler, isFn, self) {
22163 if (isFn)
22164 handler.call(self);
22165 else {
22166 var len = handler.length;
22167 var listeners = arrayClone(handler, len);
22168 for (var i = 0; i < len; ++i)
22169 listeners[i].call(self);
22170 }
22171}
22172function emitOne(handler, isFn, self, arg1) {
22173 if (isFn)
22174 handler.call(self, arg1);
22175 else {
22176 var len = handler.length;
22177 var listeners = arrayClone(handler, len);
22178 for (var i = 0; i < len; ++i)
22179 listeners[i].call(self, arg1);
22180 }
22181}
22182function emitTwo(handler, isFn, self, arg1, arg2) {
22183 if (isFn)
22184 handler.call(self, arg1, arg2);
22185 else {
22186 var len = handler.length;
22187 var listeners = arrayClone(handler, len);
22188 for (var i = 0; i < len; ++i)
22189 listeners[i].call(self, arg1, arg2);
22190 }
22191}
22192function emitThree(handler, isFn, self, arg1, arg2, arg3) {
22193 if (isFn)
22194 handler.call(self, arg1, arg2, arg3);
22195 else {
22196 var len = handler.length;
22197 var listeners = arrayClone(handler, len);
22198 for (var i = 0; i < len; ++i)
22199 listeners[i].call(self, arg1, arg2, arg3);
22200 }
22201}
22202
22203function emitMany(handler, isFn, self, args) {
22204 if (isFn)
22205 handler.apply(self, args);
22206 else {
22207 var len = handler.length;
22208 var listeners = arrayClone(handler, len);
22209 for (var i = 0; i < len; ++i)
22210 listeners[i].apply(self, args);
22211 }
22212}
22213
22214EventEmitter.prototype.emit = function emit(type) {
22215 var er, handler, len, args, i, events;
22216 var doError = (type === 'error');
22217
22218 events = this._events;
22219 if (events)
22220 doError = (doError && events.error == null);
22221 else if (!doError)
22222 return false;
22223
22224 // If there is no 'error' event listener then throw.
22225 if (doError) {
22226 if (arguments.length > 1)
22227 er = arguments[1];
22228 if (er instanceof Error) {
22229 throw er; // Unhandled 'error' event
22230 } else {
22231 // At least give some kind of context to the user
22232 var err = new Error('Unhandled "error" event. (' + er + ')');
22233 err.context = er;
22234 throw err;
22235 }
22236 return false;
22237 }
22238
22239 handler = events[type];
22240
22241 if (!handler)
22242 return false;
22243
22244 var isFn = typeof handler === 'function';
22245 len = arguments.length;
22246 switch (len) {
22247 // fast cases
22248 case 1:
22249 emitNone(handler, isFn, this);
22250 break;
22251 case 2:
22252 emitOne(handler, isFn, this, arguments[1]);
22253 break;
22254 case 3:
22255 emitTwo(handler, isFn, this, arguments[1], arguments[2]);
22256 break;
22257 case 4:
22258 emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
22259 break;
22260 // slower
22261 default:
22262 args = new Array(len - 1);
22263 for (i = 1; i < len; i++)
22264 args[i - 1] = arguments[i];
22265 emitMany(handler, isFn, this, args);
22266 }
22267
22268 return true;
22269};
22270
22271function _addListener(target, type, listener, prepend) {
22272 var m;
22273 var events;
22274 var existing;
22275
22276 if (typeof listener !== 'function')
22277 throw new TypeError('"listener" argument must be a function');
22278
22279 events = target._events;
22280 if (!events) {
22281 events = target._events = objectCreate(null);
22282 target._eventsCount = 0;
22283 } else {
22284 // To avoid recursion in the case that type === "newListener"! Before
22285 // adding it to the listeners, first emit "newListener".
22286 if (events.newListener) {
22287 target.emit('newListener', type,
22288 listener.listener ? listener.listener : listener);
22289
22290 // Re-assign `events` because a newListener handler could have caused the
22291 // this._events to be assigned to a new object
22292 events = target._events;
22293 }
22294 existing = events[type];
22295 }
22296
22297 if (!existing) {
22298 // Optimize the case of one listener. Don't need the extra array object.
22299 existing = events[type] = listener;
22300 ++target._eventsCount;
22301 } else {
22302 if (typeof existing === 'function') {
22303 // Adding the second element, need to change to array.
22304 existing = events[type] =
22305 prepend ? [listener, existing] : [existing, listener];
22306 } else {
22307 // If we've already got an array, just append.
22308 if (prepend) {
22309 existing.unshift(listener);
22310 } else {
22311 existing.push(listener);
22312 }
22313 }
22314
22315 // Check for listener leak
22316 if (!existing.warned) {
22317 m = $getMaxListeners(target);
22318 if (m && m > 0 && existing.length > m) {
22319 existing.warned = true;
22320 var w = new Error('Possible EventEmitter memory leak detected. ' +
22321 existing.length + ' "' + String(type) + '" listeners ' +
22322 'added. Use emitter.setMaxListeners() to ' +
22323 'increase limit.');
22324 w.name = 'MaxListenersExceededWarning';
22325 w.emitter = target;
22326 w.type = type;
22327 w.count = existing.length;
22328 if (typeof console === 'object' && console.warn) {
22329 console.warn('%s: %s', w.name, w.message);
22330 }
22331 }
22332 }
22333 }
22334
22335 return target;
22336}
22337
22338EventEmitter.prototype.addListener = function addListener(type, listener) {
22339 return _addListener(this, type, listener, false);
22340};
22341
22342EventEmitter.prototype.on = EventEmitter.prototype.addListener;
22343
22344EventEmitter.prototype.prependListener =
22345 function prependListener(type, listener) {
22346 return _addListener(this, type, listener, true);
22347 };
22348
22349function onceWrapper() {
22350 if (!this.fired) {
22351 this.target.removeListener(this.type, this.wrapFn);
22352 this.fired = true;
22353 switch (arguments.length) {
22354 case 0:
22355 return this.listener.call(this.target);
22356 case 1:
22357 return this.listener.call(this.target, arguments[0]);
22358 case 2:
22359 return this.listener.call(this.target, arguments[0], arguments[1]);
22360 case 3:
22361 return this.listener.call(this.target, arguments[0], arguments[1],
22362 arguments[2]);
22363 default:
22364 var args = new Array(arguments.length);
22365 for (var i = 0; i < args.length; ++i)
22366 args[i] = arguments[i];
22367 this.listener.apply(this.target, args);
22368 }
22369 }
22370}
22371
22372function _onceWrap(target, type, listener) {
22373 var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
22374 var wrapped = bind.call(onceWrapper, state);
22375 wrapped.listener = listener;
22376 state.wrapFn = wrapped;
22377 return wrapped;
22378}
22379
22380EventEmitter.prototype.once = function once(type, listener) {
22381 if (typeof listener !== 'function')
22382 throw new TypeError('"listener" argument must be a function');
22383 this.on(type, _onceWrap(this, type, listener));
22384 return this;
22385};
22386
22387EventEmitter.prototype.prependOnceListener =
22388 function prependOnceListener(type, listener) {
22389 if (typeof listener !== 'function')
22390 throw new TypeError('"listener" argument must be a function');
22391 this.prependListener(type, _onceWrap(this, type, listener));
22392 return this;
22393 };
22394
22395// Emits a 'removeListener' event if and only if the listener was removed.
22396EventEmitter.prototype.removeListener =
22397 function removeListener(type, listener) {
22398 var list, events, position, i, originalListener;
22399
22400 if (typeof listener !== 'function')
22401 throw new TypeError('"listener" argument must be a function');
22402
22403 events = this._events;
22404 if (!events)
22405 return this;
22406
22407 list = events[type];
22408 if (!list)
22409 return this;
22410
22411 if (list === listener || list.listener === listener) {
22412 if (--this._eventsCount === 0)
22413 this._events = objectCreate(null);
22414 else {
22415 delete events[type];
22416 if (events.removeListener)
22417 this.emit('removeListener', type, list.listener || listener);
22418 }
22419 } else if (typeof list !== 'function') {
22420 position = -1;
22421
22422 for (i = list.length - 1; i >= 0; i--) {
22423 if (list[i] === listener || list[i].listener === listener) {
22424 originalListener = list[i].listener;
22425 position = i;
22426 break;
22427 }
22428 }
22429
22430 if (position < 0)
22431 return this;
22432
22433 if (position === 0)
22434 list.shift();
22435 else
22436 spliceOne(list, position);
22437
22438 if (list.length === 1)
22439 events[type] = list[0];
22440
22441 if (events.removeListener)
22442 this.emit('removeListener', type, originalListener || listener);
22443 }
22444
22445 return this;
22446 };
22447
22448EventEmitter.prototype.removeAllListeners =
22449 function removeAllListeners(type) {
22450 var listeners, events, i;
22451
22452 events = this._events;
22453 if (!events)
22454 return this;
22455
22456 // not listening for removeListener, no need to emit
22457 if (!events.removeListener) {
22458 if (arguments.length === 0) {
22459 this._events = objectCreate(null);
22460 this._eventsCount = 0;
22461 } else if (events[type]) {
22462 if (--this._eventsCount === 0)
22463 this._events = objectCreate(null);
22464 else
22465 delete events[type];
22466 }
22467 return this;
22468 }
22469
22470 // emit removeListener for all listeners on all events
22471 if (arguments.length === 0) {
22472 var keys = objectKeys(events);
22473 var key;
22474 for (i = 0; i < keys.length; ++i) {
22475 key = keys[i];
22476 if (key === 'removeListener') continue;
22477 this.removeAllListeners(key);
22478 }
22479 this.removeAllListeners('removeListener');
22480 this._events = objectCreate(null);
22481 this._eventsCount = 0;
22482 return this;
22483 }
22484
22485 listeners = events[type];
22486
22487 if (typeof listeners === 'function') {
22488 this.removeListener(type, listeners);
22489 } else if (listeners) {
22490 // LIFO order
22491 for (i = listeners.length - 1; i >= 0; i--) {
22492 this.removeListener(type, listeners[i]);
22493 }
22494 }
22495
22496 return this;
22497 };
22498
22499function _listeners(target, type, unwrap) {
22500 var events = target._events;
22501
22502 if (!events)
22503 return [];
22504
22505 var evlistener = events[type];
22506 if (!evlistener)
22507 return [];
22508
22509 if (typeof evlistener === 'function')
22510 return unwrap ? [evlistener.listener || evlistener] : [evlistener];
22511
22512 return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
22513}
22514
22515EventEmitter.prototype.listeners = function listeners(type) {
22516 return _listeners(this, type, true);
22517};
22518
22519EventEmitter.prototype.rawListeners = function rawListeners(type) {
22520 return _listeners(this, type, false);
22521};
22522
22523EventEmitter.listenerCount = function(emitter, type) {
22524 if (typeof emitter.listenerCount === 'function') {
22525 return emitter.listenerCount(type);
22526 } else {
22527 return listenerCount.call(emitter, type);
22528 }
22529};
22530
22531EventEmitter.prototype.listenerCount = listenerCount;
22532function listenerCount(type) {
22533 var events = this._events;
22534
22535 if (events) {
22536 var evlistener = events[type];
22537
22538 if (typeof evlistener === 'function') {
22539 return 1;
22540 } else if (evlistener) {
22541 return evlistener.length;
22542 }
22543 }
22544
22545 return 0;
22546}
22547
22548EventEmitter.prototype.eventNames = function eventNames() {
22549 return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
22550};
22551
22552// About 1.5x faster than the two-arg version of Array#splice().
22553function spliceOne(list, index) {
22554 for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
22555 list[i] = list[k];
22556 list.pop();
22557}
22558
22559function arrayClone(arr, n) {
22560 var copy = new Array(n);
22561 for (var i = 0; i < n; ++i)
22562 copy[i] = arr[i];
22563 return copy;
22564}
22565
22566function unwrapListeners(arr) {
22567 var ret = new Array(arr.length);
22568 for (var i = 0; i < ret.length; ++i) {
22569 ret[i] = arr[i].listener || arr[i];
22570 }
22571 return ret;
22572}
22573
22574function objectCreatePolyfill(proto) {
22575 var F = function() {};
22576 F.prototype = proto;
22577 return new F;
22578}
22579function objectKeysPolyfill(obj) {
22580 var keys = [];
22581 for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
22582 keys.push(k);
22583 }
22584 return k;
22585}
22586function functionBindPolyfill(context) {
22587 var fn = this;
22588 return function () {
22589 return fn.apply(context, arguments);
22590 };
22591}
22592
22593},{}],146:[function(require,module,exports){
22594arguments[4][38][0].apply(exports,arguments)
22595},{"dup":38,"md5.js":165,"safe-buffer":206}],147:[function(require,module,exports){
22596arguments[4][43][0].apply(exports,arguments)
22597},{"dup":43,"inherits":162,"safe-buffer":206,"stream":215}],148:[function(require,module,exports){
22598var hash = exports;
22599
22600hash.utils = require('./hash/utils');
22601hash.common = require('./hash/common');
22602hash.sha = require('./hash/sha');
22603hash.ripemd = require('./hash/ripemd');
22604hash.hmac = require('./hash/hmac');
22605
22606// Proxy hash functions to the main object
22607hash.sha1 = hash.sha.sha1;
22608hash.sha256 = hash.sha.sha256;
22609hash.sha224 = hash.sha.sha224;
22610hash.sha384 = hash.sha.sha384;
22611hash.sha512 = hash.sha.sha512;
22612hash.ripemd160 = hash.ripemd.ripemd160;
22613
22614},{"./hash/common":149,"./hash/hmac":150,"./hash/ripemd":151,"./hash/sha":152,"./hash/utils":159}],149:[function(require,module,exports){
22615'use strict';
22616
22617var utils = require('./utils');
22618var assert = require('minimalistic-assert');
22619
22620function BlockHash() {
22621 this.pending = null;
22622 this.pendingTotal = 0;
22623 this.blockSize = this.constructor.blockSize;
22624 this.outSize = this.constructor.outSize;
22625 this.hmacStrength = this.constructor.hmacStrength;
22626 this.padLength = this.constructor.padLength / 8;
22627 this.endian = 'big';
22628
22629 this._delta8 = this.blockSize / 8;
22630 this._delta32 = this.blockSize / 32;
22631}
22632exports.BlockHash = BlockHash;
22633
22634BlockHash.prototype.update = function update(msg, enc) {
22635 // Convert message to array, pad it, and join into 32bit blocks
22636 msg = utils.toArray(msg, enc);
22637 if (!this.pending)
22638 this.pending = msg;
22639 else
22640 this.pending = this.pending.concat(msg);
22641 this.pendingTotal += msg.length;
22642
22643 // Enough data, try updating
22644 if (this.pending.length >= this._delta8) {
22645 msg = this.pending;
22646
22647 // Process pending data in blocks
22648 var r = msg.length % this._delta8;
22649 this.pending = msg.slice(msg.length - r, msg.length);
22650 if (this.pending.length === 0)
22651 this.pending = null;
22652
22653 msg = utils.join32(msg, 0, msg.length - r, this.endian);
22654 for (var i = 0; i < msg.length; i += this._delta32)
22655 this._update(msg, i, i + this._delta32);
22656 }
22657
22658 return this;
22659};
22660
22661BlockHash.prototype.digest = function digest(enc) {
22662 this.update(this._pad());
22663 assert(this.pending === null);
22664
22665 return this._digest(enc);
22666};
22667
22668BlockHash.prototype._pad = function pad() {
22669 var len = this.pendingTotal;
22670 var bytes = this._delta8;
22671 var k = bytes - ((len + this.padLength) % bytes);
22672 var res = new Array(k + this.padLength);
22673 res[0] = 0x80;
22674 for (var i = 1; i < k; i++)
22675 res[i] = 0;
22676
22677 // Append length
22678 len <<= 3;
22679 if (this.endian === 'big') {
22680 for (var t = 8; t < this.padLength; t++)
22681 res[i++] = 0;
22682
22683 res[i++] = 0;
22684 res[i++] = 0;
22685 res[i++] = 0;
22686 res[i++] = 0;
22687 res[i++] = (len >>> 24) & 0xff;
22688 res[i++] = (len >>> 16) & 0xff;
22689 res[i++] = (len >>> 8) & 0xff;
22690 res[i++] = len & 0xff;
22691 } else {
22692 res[i++] = len & 0xff;
22693 res[i++] = (len >>> 8) & 0xff;
22694 res[i++] = (len >>> 16) & 0xff;
22695 res[i++] = (len >>> 24) & 0xff;
22696 res[i++] = 0;
22697 res[i++] = 0;
22698 res[i++] = 0;
22699 res[i++] = 0;
22700
22701 for (t = 8; t < this.padLength; t++)
22702 res[i++] = 0;
22703 }
22704
22705 return res;
22706};
22707
22708},{"./utils":159,"minimalistic-assert":167}],150:[function(require,module,exports){
22709'use strict';
22710
22711var utils = require('./utils');
22712var assert = require('minimalistic-assert');
22713
22714function Hmac(hash, key, enc) {
22715 if (!(this instanceof Hmac))
22716 return new Hmac(hash, key, enc);
22717 this.Hash = hash;
22718 this.blockSize = hash.blockSize / 8;
22719 this.outSize = hash.outSize / 8;
22720 this.inner = null;
22721 this.outer = null;
22722
22723 this._init(utils.toArray(key, enc));
22724}
22725module.exports = Hmac;
22726
22727Hmac.prototype._init = function init(key) {
22728 // Shorten key, if needed
22729 if (key.length > this.blockSize)
22730 key = new this.Hash().update(key).digest();
22731 assert(key.length <= this.blockSize);
22732
22733 // Add padding to key
22734 for (var i = key.length; i < this.blockSize; i++)
22735 key.push(0);
22736
22737 for (i = 0; i < key.length; i++)
22738 key[i] ^= 0x36;
22739 this.inner = new this.Hash().update(key);
22740
22741 // 0x36 ^ 0x5c = 0x6a
22742 for (i = 0; i < key.length; i++)
22743 key[i] ^= 0x6a;
22744 this.outer = new this.Hash().update(key);
22745};
22746
22747Hmac.prototype.update = function update(msg, enc) {
22748 this.inner.update(msg, enc);
22749 return this;
22750};
22751
22752Hmac.prototype.digest = function digest(enc) {
22753 this.outer.update(this.inner.digest());
22754 return this.outer.digest(enc);
22755};
22756
22757},{"./utils":159,"minimalistic-assert":167}],151:[function(require,module,exports){
22758'use strict';
22759
22760var utils = require('./utils');
22761var common = require('./common');
22762
22763var rotl32 = utils.rotl32;
22764var sum32 = utils.sum32;
22765var sum32_3 = utils.sum32_3;
22766var sum32_4 = utils.sum32_4;
22767var BlockHash = common.BlockHash;
22768
22769function RIPEMD160() {
22770 if (!(this instanceof RIPEMD160))
22771 return new RIPEMD160();
22772
22773 BlockHash.call(this);
22774
22775 this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
22776 this.endian = 'little';
22777}
22778utils.inherits(RIPEMD160, BlockHash);
22779exports.ripemd160 = RIPEMD160;
22780
22781RIPEMD160.blockSize = 512;
22782RIPEMD160.outSize = 160;
22783RIPEMD160.hmacStrength = 192;
22784RIPEMD160.padLength = 64;
22785
22786RIPEMD160.prototype._update = function update(msg, start) {
22787 var A = this.h[0];
22788 var B = this.h[1];
22789 var C = this.h[2];
22790 var D = this.h[3];
22791 var E = this.h[4];
22792 var Ah = A;
22793 var Bh = B;
22794 var Ch = C;
22795 var Dh = D;
22796 var Eh = E;
22797 for (var j = 0; j < 80; j++) {
22798 var T = sum32(
22799 rotl32(
22800 sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
22801 s[j]),
22802 E);
22803 A = E;
22804 E = D;
22805 D = rotl32(C, 10);
22806 C = B;
22807 B = T;
22808 T = sum32(
22809 rotl32(
22810 sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
22811 sh[j]),
22812 Eh);
22813 Ah = Eh;
22814 Eh = Dh;
22815 Dh = rotl32(Ch, 10);
22816 Ch = Bh;
22817 Bh = T;
22818 }
22819 T = sum32_3(this.h[1], C, Dh);
22820 this.h[1] = sum32_3(this.h[2], D, Eh);
22821 this.h[2] = sum32_3(this.h[3], E, Ah);
22822 this.h[3] = sum32_3(this.h[4], A, Bh);
22823 this.h[4] = sum32_3(this.h[0], B, Ch);
22824 this.h[0] = T;
22825};
22826
22827RIPEMD160.prototype._digest = function digest(enc) {
22828 if (enc === 'hex')
22829 return utils.toHex32(this.h, 'little');
22830 else
22831 return utils.split32(this.h, 'little');
22832};
22833
22834function f(j, x, y, z) {
22835 if (j <= 15)
22836 return x ^ y ^ z;
22837 else if (j <= 31)
22838 return (x & y) | ((~x) & z);
22839 else if (j <= 47)
22840 return (x | (~y)) ^ z;
22841 else if (j <= 63)
22842 return (x & z) | (y & (~z));
22843 else
22844 return x ^ (y | (~z));
22845}
22846
22847function K(j) {
22848 if (j <= 15)
22849 return 0x00000000;
22850 else if (j <= 31)
22851 return 0x5a827999;
22852 else if (j <= 47)
22853 return 0x6ed9eba1;
22854 else if (j <= 63)
22855 return 0x8f1bbcdc;
22856 else
22857 return 0xa953fd4e;
22858}
22859
22860function Kh(j) {
22861 if (j <= 15)
22862 return 0x50a28be6;
22863 else if (j <= 31)
22864 return 0x5c4dd124;
22865 else if (j <= 47)
22866 return 0x6d703ef3;
22867 else if (j <= 63)
22868 return 0x7a6d76e9;
22869 else
22870 return 0x00000000;
22871}
22872
22873var r = [
22874 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
22875 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
22876 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
22877 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
22878 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
22879];
22880
22881var rh = [
22882 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
22883 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
22884 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
22885 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
22886 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
22887];
22888
22889var s = [
22890 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
22891 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
22892 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
22893 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
22894 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
22895];
22896
22897var sh = [
22898 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
22899 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
22900 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
22901 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
22902 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
22903];
22904
22905},{"./common":149,"./utils":159}],152:[function(require,module,exports){
22906'use strict';
22907
22908exports.sha1 = require('./sha/1');
22909exports.sha224 = require('./sha/224');
22910exports.sha256 = require('./sha/256');
22911exports.sha384 = require('./sha/384');
22912exports.sha512 = require('./sha/512');
22913
22914},{"./sha/1":153,"./sha/224":154,"./sha/256":155,"./sha/384":156,"./sha/512":157}],153:[function(require,module,exports){
22915'use strict';
22916
22917var utils = require('../utils');
22918var common = require('../common');
22919var shaCommon = require('./common');
22920
22921var rotl32 = utils.rotl32;
22922var sum32 = utils.sum32;
22923var sum32_5 = utils.sum32_5;
22924var ft_1 = shaCommon.ft_1;
22925var BlockHash = common.BlockHash;
22926
22927var sha1_K = [
22928 0x5A827999, 0x6ED9EBA1,
22929 0x8F1BBCDC, 0xCA62C1D6
22930];
22931
22932function SHA1() {
22933 if (!(this instanceof SHA1))
22934 return new SHA1();
22935
22936 BlockHash.call(this);
22937 this.h = [
22938 0x67452301, 0xefcdab89, 0x98badcfe,
22939 0x10325476, 0xc3d2e1f0 ];
22940 this.W = new Array(80);
22941}
22942
22943utils.inherits(SHA1, BlockHash);
22944module.exports = SHA1;
22945
22946SHA1.blockSize = 512;
22947SHA1.outSize = 160;
22948SHA1.hmacStrength = 80;
22949SHA1.padLength = 64;
22950
22951SHA1.prototype._update = function _update(msg, start) {
22952 var W = this.W;
22953
22954 for (var i = 0; i < 16; i++)
22955 W[i] = msg[start + i];
22956
22957 for(; i < W.length; i++)
22958 W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
22959
22960 var a = this.h[0];
22961 var b = this.h[1];
22962 var c = this.h[2];
22963 var d = this.h[3];
22964 var e = this.h[4];
22965
22966 for (i = 0; i < W.length; i++) {
22967 var s = ~~(i / 20);
22968 var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
22969 e = d;
22970 d = c;
22971 c = rotl32(b, 30);
22972 b = a;
22973 a = t;
22974 }
22975
22976 this.h[0] = sum32(this.h[0], a);
22977 this.h[1] = sum32(this.h[1], b);
22978 this.h[2] = sum32(this.h[2], c);
22979 this.h[3] = sum32(this.h[3], d);
22980 this.h[4] = sum32(this.h[4], e);
22981};
22982
22983SHA1.prototype._digest = function digest(enc) {
22984 if (enc === 'hex')
22985 return utils.toHex32(this.h, 'big');
22986 else
22987 return utils.split32(this.h, 'big');
22988};
22989
22990},{"../common":149,"../utils":159,"./common":158}],154:[function(require,module,exports){
22991'use strict';
22992
22993var utils = require('../utils');
22994var SHA256 = require('./256');
22995
22996function SHA224() {
22997 if (!(this instanceof SHA224))
22998 return new SHA224();
22999
23000 SHA256.call(this);
23001 this.h = [
23002 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
23003 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
23004}
23005utils.inherits(SHA224, SHA256);
23006module.exports = SHA224;
23007
23008SHA224.blockSize = 512;
23009SHA224.outSize = 224;
23010SHA224.hmacStrength = 192;
23011SHA224.padLength = 64;
23012
23013SHA224.prototype._digest = function digest(enc) {
23014 // Just truncate output
23015 if (enc === 'hex')
23016 return utils.toHex32(this.h.slice(0, 7), 'big');
23017 else
23018 return utils.split32(this.h.slice(0, 7), 'big');
23019};
23020
23021
23022},{"../utils":159,"./256":155}],155:[function(require,module,exports){
23023'use strict';
23024
23025var utils = require('../utils');
23026var common = require('../common');
23027var shaCommon = require('./common');
23028var assert = require('minimalistic-assert');
23029
23030var sum32 = utils.sum32;
23031var sum32_4 = utils.sum32_4;
23032var sum32_5 = utils.sum32_5;
23033var ch32 = shaCommon.ch32;
23034var maj32 = shaCommon.maj32;
23035var s0_256 = shaCommon.s0_256;
23036var s1_256 = shaCommon.s1_256;
23037var g0_256 = shaCommon.g0_256;
23038var g1_256 = shaCommon.g1_256;
23039
23040var BlockHash = common.BlockHash;
23041
23042var sha256_K = [
23043 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
23044 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
23045 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
23046 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
23047 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
23048 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
23049 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
23050 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
23051 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
23052 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
23053 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
23054 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
23055 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
23056 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
23057 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
23058 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
23059];
23060
23061function SHA256() {
23062 if (!(this instanceof SHA256))
23063 return new SHA256();
23064
23065 BlockHash.call(this);
23066 this.h = [
23067 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
23068 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
23069 ];
23070 this.k = sha256_K;
23071 this.W = new Array(64);
23072}
23073utils.inherits(SHA256, BlockHash);
23074module.exports = SHA256;
23075
23076SHA256.blockSize = 512;
23077SHA256.outSize = 256;
23078SHA256.hmacStrength = 192;
23079SHA256.padLength = 64;
23080
23081SHA256.prototype._update = function _update(msg, start) {
23082 var W = this.W;
23083
23084 for (var i = 0; i < 16; i++)
23085 W[i] = msg[start + i];
23086 for (; i < W.length; i++)
23087 W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
23088
23089 var a = this.h[0];
23090 var b = this.h[1];
23091 var c = this.h[2];
23092 var d = this.h[3];
23093 var e = this.h[4];
23094 var f = this.h[5];
23095 var g = this.h[6];
23096 var h = this.h[7];
23097
23098 assert(this.k.length === W.length);
23099 for (i = 0; i < W.length; i++) {
23100 var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
23101 var T2 = sum32(s0_256(a), maj32(a, b, c));
23102 h = g;
23103 g = f;
23104 f = e;
23105 e = sum32(d, T1);
23106 d = c;
23107 c = b;
23108 b = a;
23109 a = sum32(T1, T2);
23110 }
23111
23112 this.h[0] = sum32(this.h[0], a);
23113 this.h[1] = sum32(this.h[1], b);
23114 this.h[2] = sum32(this.h[2], c);
23115 this.h[3] = sum32(this.h[3], d);
23116 this.h[4] = sum32(this.h[4], e);
23117 this.h[5] = sum32(this.h[5], f);
23118 this.h[6] = sum32(this.h[6], g);
23119 this.h[7] = sum32(this.h[7], h);
23120};
23121
23122SHA256.prototype._digest = function digest(enc) {
23123 if (enc === 'hex')
23124 return utils.toHex32(this.h, 'big');
23125 else
23126 return utils.split32(this.h, 'big');
23127};
23128
23129},{"../common":149,"../utils":159,"./common":158,"minimalistic-assert":167}],156:[function(require,module,exports){
23130'use strict';
23131
23132var utils = require('../utils');
23133
23134var SHA512 = require('./512');
23135
23136function SHA384() {
23137 if (!(this instanceof SHA384))
23138 return new SHA384();
23139
23140 SHA512.call(this);
23141 this.h = [
23142 0xcbbb9d5d, 0xc1059ed8,
23143 0x629a292a, 0x367cd507,
23144 0x9159015a, 0x3070dd17,
23145 0x152fecd8, 0xf70e5939,
23146 0x67332667, 0xffc00b31,
23147 0x8eb44a87, 0x68581511,
23148 0xdb0c2e0d, 0x64f98fa7,
23149 0x47b5481d, 0xbefa4fa4 ];
23150}
23151utils.inherits(SHA384, SHA512);
23152module.exports = SHA384;
23153
23154SHA384.blockSize = 1024;
23155SHA384.outSize = 384;
23156SHA384.hmacStrength = 192;
23157SHA384.padLength = 128;
23158
23159SHA384.prototype._digest = function digest(enc) {
23160 if (enc === 'hex')
23161 return utils.toHex32(this.h.slice(0, 12), 'big');
23162 else
23163 return utils.split32(this.h.slice(0, 12), 'big');
23164};
23165
23166},{"../utils":159,"./512":157}],157:[function(require,module,exports){
23167'use strict';
23168
23169var utils = require('../utils');
23170var common = require('../common');
23171var assert = require('minimalistic-assert');
23172
23173var rotr64_hi = utils.rotr64_hi;
23174var rotr64_lo = utils.rotr64_lo;
23175var shr64_hi = utils.shr64_hi;
23176var shr64_lo = utils.shr64_lo;
23177var sum64 = utils.sum64;
23178var sum64_hi = utils.sum64_hi;
23179var sum64_lo = utils.sum64_lo;
23180var sum64_4_hi = utils.sum64_4_hi;
23181var sum64_4_lo = utils.sum64_4_lo;
23182var sum64_5_hi = utils.sum64_5_hi;
23183var sum64_5_lo = utils.sum64_5_lo;
23184
23185var BlockHash = common.BlockHash;
23186
23187var sha512_K = [
23188 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
23189 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
23190 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
23191 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
23192 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
23193 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
23194 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
23195 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
23196 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
23197 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
23198 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
23199 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
23200 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
23201 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
23202 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
23203 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
23204 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
23205 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
23206 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
23207 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
23208 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
23209 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
23210 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
23211 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
23212 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
23213 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
23214 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
23215 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
23216 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
23217 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
23218 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
23219 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
23220 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
23221 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
23222 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
23223 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
23224 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
23225 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
23226 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
23227 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
23228];
23229
23230function SHA512() {
23231 if (!(this instanceof SHA512))
23232 return new SHA512();
23233
23234 BlockHash.call(this);
23235 this.h = [
23236 0x6a09e667, 0xf3bcc908,
23237 0xbb67ae85, 0x84caa73b,
23238 0x3c6ef372, 0xfe94f82b,
23239 0xa54ff53a, 0x5f1d36f1,
23240 0x510e527f, 0xade682d1,
23241 0x9b05688c, 0x2b3e6c1f,
23242 0x1f83d9ab, 0xfb41bd6b,
23243 0x5be0cd19, 0x137e2179 ];
23244 this.k = sha512_K;
23245 this.W = new Array(160);
23246}
23247utils.inherits(SHA512, BlockHash);
23248module.exports = SHA512;
23249
23250SHA512.blockSize = 1024;
23251SHA512.outSize = 512;
23252SHA512.hmacStrength = 192;
23253SHA512.padLength = 128;
23254
23255SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
23256 var W = this.W;
23257
23258 // 32 x 32bit words
23259 for (var i = 0; i < 32; i++)
23260 W[i] = msg[start + i];
23261 for (; i < W.length; i += 2) {
23262 var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
23263 var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
23264 var c1_hi = W[i - 14]; // i - 7
23265 var c1_lo = W[i - 13];
23266 var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
23267 var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
23268 var c3_hi = W[i - 32]; // i - 16
23269 var c3_lo = W[i - 31];
23270
23271 W[i] = sum64_4_hi(
23272 c0_hi, c0_lo,
23273 c1_hi, c1_lo,
23274 c2_hi, c2_lo,
23275 c3_hi, c3_lo);
23276 W[i + 1] = sum64_4_lo(
23277 c0_hi, c0_lo,
23278 c1_hi, c1_lo,
23279 c2_hi, c2_lo,
23280 c3_hi, c3_lo);
23281 }
23282};
23283
23284SHA512.prototype._update = function _update(msg, start) {
23285 this._prepareBlock(msg, start);
23286
23287 var W = this.W;
23288
23289 var ah = this.h[0];
23290 var al = this.h[1];
23291 var bh = this.h[2];
23292 var bl = this.h[3];
23293 var ch = this.h[4];
23294 var cl = this.h[5];
23295 var dh = this.h[6];
23296 var dl = this.h[7];
23297 var eh = this.h[8];
23298 var el = this.h[9];
23299 var fh = this.h[10];
23300 var fl = this.h[11];
23301 var gh = this.h[12];
23302 var gl = this.h[13];
23303 var hh = this.h[14];
23304 var hl = this.h[15];
23305
23306 assert(this.k.length === W.length);
23307 for (var i = 0; i < W.length; i += 2) {
23308 var c0_hi = hh;
23309 var c0_lo = hl;
23310 var c1_hi = s1_512_hi(eh, el);
23311 var c1_lo = s1_512_lo(eh, el);
23312 var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
23313 var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
23314 var c3_hi = this.k[i];
23315 var c3_lo = this.k[i + 1];
23316 var c4_hi = W[i];
23317 var c4_lo = W[i + 1];
23318
23319 var T1_hi = sum64_5_hi(
23320 c0_hi, c0_lo,
23321 c1_hi, c1_lo,
23322 c2_hi, c2_lo,
23323 c3_hi, c3_lo,
23324 c4_hi, c4_lo);
23325 var T1_lo = sum64_5_lo(
23326 c0_hi, c0_lo,
23327 c1_hi, c1_lo,
23328 c2_hi, c2_lo,
23329 c3_hi, c3_lo,
23330 c4_hi, c4_lo);
23331
23332 c0_hi = s0_512_hi(ah, al);
23333 c0_lo = s0_512_lo(ah, al);
23334 c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
23335 c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
23336
23337 var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
23338 var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
23339
23340 hh = gh;
23341 hl = gl;
23342
23343 gh = fh;
23344 gl = fl;
23345
23346 fh = eh;
23347 fl = el;
23348
23349 eh = sum64_hi(dh, dl, T1_hi, T1_lo);
23350 el = sum64_lo(dl, dl, T1_hi, T1_lo);
23351
23352 dh = ch;
23353 dl = cl;
23354
23355 ch = bh;
23356 cl = bl;
23357
23358 bh = ah;
23359 bl = al;
23360
23361 ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
23362 al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
23363 }
23364
23365 sum64(this.h, 0, ah, al);
23366 sum64(this.h, 2, bh, bl);
23367 sum64(this.h, 4, ch, cl);
23368 sum64(this.h, 6, dh, dl);
23369 sum64(this.h, 8, eh, el);
23370 sum64(this.h, 10, fh, fl);
23371 sum64(this.h, 12, gh, gl);
23372 sum64(this.h, 14, hh, hl);
23373};
23374
23375SHA512.prototype._digest = function digest(enc) {
23376 if (enc === 'hex')
23377 return utils.toHex32(this.h, 'big');
23378 else
23379 return utils.split32(this.h, 'big');
23380};
23381
23382function ch64_hi(xh, xl, yh, yl, zh) {
23383 var r = (xh & yh) ^ ((~xh) & zh);
23384 if (r < 0)
23385 r += 0x100000000;
23386 return r;
23387}
23388
23389function ch64_lo(xh, xl, yh, yl, zh, zl) {
23390 var r = (xl & yl) ^ ((~xl) & zl);
23391 if (r < 0)
23392 r += 0x100000000;
23393 return r;
23394}
23395
23396function maj64_hi(xh, xl, yh, yl, zh) {
23397 var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
23398 if (r < 0)
23399 r += 0x100000000;
23400 return r;
23401}
23402
23403function maj64_lo(xh, xl, yh, yl, zh, zl) {
23404 var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
23405 if (r < 0)
23406 r += 0x100000000;
23407 return r;
23408}
23409
23410function s0_512_hi(xh, xl) {
23411 var c0_hi = rotr64_hi(xh, xl, 28);
23412 var c1_hi = rotr64_hi(xl, xh, 2); // 34
23413 var c2_hi = rotr64_hi(xl, xh, 7); // 39
23414
23415 var r = c0_hi ^ c1_hi ^ c2_hi;
23416 if (r < 0)
23417 r += 0x100000000;
23418 return r;
23419}
23420
23421function s0_512_lo(xh, xl) {
23422 var c0_lo = rotr64_lo(xh, xl, 28);
23423 var c1_lo = rotr64_lo(xl, xh, 2); // 34
23424 var c2_lo = rotr64_lo(xl, xh, 7); // 39
23425
23426 var r = c0_lo ^ c1_lo ^ c2_lo;
23427 if (r < 0)
23428 r += 0x100000000;
23429 return r;
23430}
23431
23432function s1_512_hi(xh, xl) {
23433 var c0_hi = rotr64_hi(xh, xl, 14);
23434 var c1_hi = rotr64_hi(xh, xl, 18);
23435 var c2_hi = rotr64_hi(xl, xh, 9); // 41
23436
23437 var r = c0_hi ^ c1_hi ^ c2_hi;
23438 if (r < 0)
23439 r += 0x100000000;
23440 return r;
23441}
23442
23443function s1_512_lo(xh, xl) {
23444 var c0_lo = rotr64_lo(xh, xl, 14);
23445 var c1_lo = rotr64_lo(xh, xl, 18);
23446 var c2_lo = rotr64_lo(xl, xh, 9); // 41
23447
23448 var r = c0_lo ^ c1_lo ^ c2_lo;
23449 if (r < 0)
23450 r += 0x100000000;
23451 return r;
23452}
23453
23454function g0_512_hi(xh, xl) {
23455 var c0_hi = rotr64_hi(xh, xl, 1);
23456 var c1_hi = rotr64_hi(xh, xl, 8);
23457 var c2_hi = shr64_hi(xh, xl, 7);
23458
23459 var r = c0_hi ^ c1_hi ^ c2_hi;
23460 if (r < 0)
23461 r += 0x100000000;
23462 return r;
23463}
23464
23465function g0_512_lo(xh, xl) {
23466 var c0_lo = rotr64_lo(xh, xl, 1);
23467 var c1_lo = rotr64_lo(xh, xl, 8);
23468 var c2_lo = shr64_lo(xh, xl, 7);
23469
23470 var r = c0_lo ^ c1_lo ^ c2_lo;
23471 if (r < 0)
23472 r += 0x100000000;
23473 return r;
23474}
23475
23476function g1_512_hi(xh, xl) {
23477 var c0_hi = rotr64_hi(xh, xl, 19);
23478 var c1_hi = rotr64_hi(xl, xh, 29); // 61
23479 var c2_hi = shr64_hi(xh, xl, 6);
23480
23481 var r = c0_hi ^ c1_hi ^ c2_hi;
23482 if (r < 0)
23483 r += 0x100000000;
23484 return r;
23485}
23486
23487function g1_512_lo(xh, xl) {
23488 var c0_lo = rotr64_lo(xh, xl, 19);
23489 var c1_lo = rotr64_lo(xl, xh, 29); // 61
23490 var c2_lo = shr64_lo(xh, xl, 6);
23491
23492 var r = c0_lo ^ c1_lo ^ c2_lo;
23493 if (r < 0)
23494 r += 0x100000000;
23495 return r;
23496}
23497
23498},{"../common":149,"../utils":159,"minimalistic-assert":167}],158:[function(require,module,exports){
23499'use strict';
23500
23501var utils = require('../utils');
23502var rotr32 = utils.rotr32;
23503
23504function ft_1(s, x, y, z) {
23505 if (s === 0)
23506 return ch32(x, y, z);
23507 if (s === 1 || s === 3)
23508 return p32(x, y, z);
23509 if (s === 2)
23510 return maj32(x, y, z);
23511}
23512exports.ft_1 = ft_1;
23513
23514function ch32(x, y, z) {
23515 return (x & y) ^ ((~x) & z);
23516}
23517exports.ch32 = ch32;
23518
23519function maj32(x, y, z) {
23520 return (x & y) ^ (x & z) ^ (y & z);
23521}
23522exports.maj32 = maj32;
23523
23524function p32(x, y, z) {
23525 return x ^ y ^ z;
23526}
23527exports.p32 = p32;
23528
23529function s0_256(x) {
23530 return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
23531}
23532exports.s0_256 = s0_256;
23533
23534function s1_256(x) {
23535 return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
23536}
23537exports.s1_256 = s1_256;
23538
23539function g0_256(x) {
23540 return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
23541}
23542exports.g0_256 = g0_256;
23543
23544function g1_256(x) {
23545 return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
23546}
23547exports.g1_256 = g1_256;
23548
23549},{"../utils":159}],159:[function(require,module,exports){
23550'use strict';
23551
23552var assert = require('minimalistic-assert');
23553var inherits = require('inherits');
23554
23555exports.inherits = inherits;
23556
23557function isSurrogatePair(msg, i) {
23558 if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
23559 return false;
23560 }
23561 if (i < 0 || i + 1 >= msg.length) {
23562 return false;
23563 }
23564 return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
23565}
23566
23567function toArray(msg, enc) {
23568 if (Array.isArray(msg))
23569 return msg.slice();
23570 if (!msg)
23571 return [];
23572 var res = [];
23573 if (typeof msg === 'string') {
23574 if (!enc) {
23575 // Inspired by stringToUtf8ByteArray() in closure-library by Google
23576 // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
23577 // Apache License 2.0
23578 // https://github.com/google/closure-library/blob/master/LICENSE
23579 var p = 0;
23580 for (var i = 0; i < msg.length; i++) {
23581 var c = msg.charCodeAt(i);
23582 if (c < 128) {
23583 res[p++] = c;
23584 } else if (c < 2048) {
23585 res[p++] = (c >> 6) | 192;
23586 res[p++] = (c & 63) | 128;
23587 } else if (isSurrogatePair(msg, i)) {
23588 c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
23589 res[p++] = (c >> 18) | 240;
23590 res[p++] = ((c >> 12) & 63) | 128;
23591 res[p++] = ((c >> 6) & 63) | 128;
23592 res[p++] = (c & 63) | 128;
23593 } else {
23594 res[p++] = (c >> 12) | 224;
23595 res[p++] = ((c >> 6) & 63) | 128;
23596 res[p++] = (c & 63) | 128;
23597 }
23598 }
23599 } else if (enc === 'hex') {
23600 msg = msg.replace(/[^a-z0-9]+/ig, '');
23601 if (msg.length % 2 !== 0)
23602 msg = '0' + msg;
23603 for (i = 0; i < msg.length; i += 2)
23604 res.push(parseInt(msg[i] + msg[i + 1], 16));
23605 }
23606 } else {
23607 for (i = 0; i < msg.length; i++)
23608 res[i] = msg[i] | 0;
23609 }
23610 return res;
23611}
23612exports.toArray = toArray;
23613
23614function toHex(msg) {
23615 var res = '';
23616 for (var i = 0; i < msg.length; i++)
23617 res += zero2(msg[i].toString(16));
23618 return res;
23619}
23620exports.toHex = toHex;
23621
23622function htonl(w) {
23623 var res = (w >>> 24) |
23624 ((w >>> 8) & 0xff00) |
23625 ((w << 8) & 0xff0000) |
23626 ((w & 0xff) << 24);
23627 return res >>> 0;
23628}
23629exports.htonl = htonl;
23630
23631function toHex32(msg, endian) {
23632 var res = '';
23633 for (var i = 0; i < msg.length; i++) {
23634 var w = msg[i];
23635 if (endian === 'little')
23636 w = htonl(w);
23637 res += zero8(w.toString(16));
23638 }
23639 return res;
23640}
23641exports.toHex32 = toHex32;
23642
23643function zero2(word) {
23644 if (word.length === 1)
23645 return '0' + word;
23646 else
23647 return word;
23648}
23649exports.zero2 = zero2;
23650
23651function zero8(word) {
23652 if (word.length === 7)
23653 return '0' + word;
23654 else if (word.length === 6)
23655 return '00' + word;
23656 else if (word.length === 5)
23657 return '000' + word;
23658 else if (word.length === 4)
23659 return '0000' + word;
23660 else if (word.length === 3)
23661 return '00000' + word;
23662 else if (word.length === 2)
23663 return '000000' + word;
23664 else if (word.length === 1)
23665 return '0000000' + word;
23666 else
23667 return word;
23668}
23669exports.zero8 = zero8;
23670
23671function join32(msg, start, end, endian) {
23672 var len = end - start;
23673 assert(len % 4 === 0);
23674 var res = new Array(len / 4);
23675 for (var i = 0, k = start; i < res.length; i++, k += 4) {
23676 var w;
23677 if (endian === 'big')
23678 w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
23679 else
23680 w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
23681 res[i] = w >>> 0;
23682 }
23683 return res;
23684}
23685exports.join32 = join32;
23686
23687function split32(msg, endian) {
23688 var res = new Array(msg.length * 4);
23689 for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
23690 var m = msg[i];
23691 if (endian === 'big') {
23692 res[k] = m >>> 24;
23693 res[k + 1] = (m >>> 16) & 0xff;
23694 res[k + 2] = (m >>> 8) & 0xff;
23695 res[k + 3] = m & 0xff;
23696 } else {
23697 res[k + 3] = m >>> 24;
23698 res[k + 2] = (m >>> 16) & 0xff;
23699 res[k + 1] = (m >>> 8) & 0xff;
23700 res[k] = m & 0xff;
23701 }
23702 }
23703 return res;
23704}
23705exports.split32 = split32;
23706
23707function rotr32(w, b) {
23708 return (w >>> b) | (w << (32 - b));
23709}
23710exports.rotr32 = rotr32;
23711
23712function rotl32(w, b) {
23713 return (w << b) | (w >>> (32 - b));
23714}
23715exports.rotl32 = rotl32;
23716
23717function sum32(a, b) {
23718 return (a + b) >>> 0;
23719}
23720exports.sum32 = sum32;
23721
23722function sum32_3(a, b, c) {
23723 return (a + b + c) >>> 0;
23724}
23725exports.sum32_3 = sum32_3;
23726
23727function sum32_4(a, b, c, d) {
23728 return (a + b + c + d) >>> 0;
23729}
23730exports.sum32_4 = sum32_4;
23731
23732function sum32_5(a, b, c, d, e) {
23733 return (a + b + c + d + e) >>> 0;
23734}
23735exports.sum32_5 = sum32_5;
23736
23737function sum64(buf, pos, ah, al) {
23738 var bh = buf[pos];
23739 var bl = buf[pos + 1];
23740
23741 var lo = (al + bl) >>> 0;
23742 var hi = (lo < al ? 1 : 0) + ah + bh;
23743 buf[pos] = hi >>> 0;
23744 buf[pos + 1] = lo;
23745}
23746exports.sum64 = sum64;
23747
23748function sum64_hi(ah, al, bh, bl) {
23749 var lo = (al + bl) >>> 0;
23750 var hi = (lo < al ? 1 : 0) + ah + bh;
23751 return hi >>> 0;
23752}
23753exports.sum64_hi = sum64_hi;
23754
23755function sum64_lo(ah, al, bh, bl) {
23756 var lo = al + bl;
23757 return lo >>> 0;
23758}
23759exports.sum64_lo = sum64_lo;
23760
23761function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
23762 var carry = 0;
23763 var lo = al;
23764 lo = (lo + bl) >>> 0;
23765 carry += lo < al ? 1 : 0;
23766 lo = (lo + cl) >>> 0;
23767 carry += lo < cl ? 1 : 0;
23768 lo = (lo + dl) >>> 0;
23769 carry += lo < dl ? 1 : 0;
23770
23771 var hi = ah + bh + ch + dh + carry;
23772 return hi >>> 0;
23773}
23774exports.sum64_4_hi = sum64_4_hi;
23775
23776function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
23777 var lo = al + bl + cl + dl;
23778 return lo >>> 0;
23779}
23780exports.sum64_4_lo = sum64_4_lo;
23781
23782function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
23783 var carry = 0;
23784 var lo = al;
23785 lo = (lo + bl) >>> 0;
23786 carry += lo < al ? 1 : 0;
23787 lo = (lo + cl) >>> 0;
23788 carry += lo < cl ? 1 : 0;
23789 lo = (lo + dl) >>> 0;
23790 carry += lo < dl ? 1 : 0;
23791 lo = (lo + el) >>> 0;
23792 carry += lo < el ? 1 : 0;
23793
23794 var hi = ah + bh + ch + dh + eh + carry;
23795 return hi >>> 0;
23796}
23797exports.sum64_5_hi = sum64_5_hi;
23798
23799function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
23800 var lo = al + bl + cl + dl + el;
23801
23802 return lo >>> 0;
23803}
23804exports.sum64_5_lo = sum64_5_lo;
23805
23806function rotr64_hi(ah, al, num) {
23807 var r = (al << (32 - num)) | (ah >>> num);
23808 return r >>> 0;
23809}
23810exports.rotr64_hi = rotr64_hi;
23811
23812function rotr64_lo(ah, al, num) {
23813 var r = (ah << (32 - num)) | (al >>> num);
23814 return r >>> 0;
23815}
23816exports.rotr64_lo = rotr64_lo;
23817
23818function shr64_hi(ah, al, num) {
23819 return ah >>> num;
23820}
23821exports.shr64_hi = shr64_hi;
23822
23823function shr64_lo(ah, al, num) {
23824 var r = (ah << (32 - num)) | (al >>> num);
23825 return r >>> 0;
23826}
23827exports.shr64_lo = shr64_lo;
23828
23829},{"inherits":162,"minimalistic-assert":167}],160:[function(require,module,exports){
23830'use strict';
23831
23832var hash = require('hash.js');
23833var utils = require('minimalistic-crypto-utils');
23834var assert = require('minimalistic-assert');
23835
23836function HmacDRBG(options) {
23837 if (!(this instanceof HmacDRBG))
23838 return new HmacDRBG(options);
23839 this.hash = options.hash;
23840 this.predResist = !!options.predResist;
23841
23842 this.outLen = this.hash.outSize;
23843 this.minEntropy = options.minEntropy || this.hash.hmacStrength;
23844
23845 this._reseed = null;
23846 this.reseedInterval = null;
23847 this.K = null;
23848 this.V = null;
23849
23850 var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
23851 var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
23852 var pers = utils.toArray(options.pers, options.persEnc || 'hex');
23853 assert(entropy.length >= (this.minEntropy / 8),
23854 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
23855 this._init(entropy, nonce, pers);
23856}
23857module.exports = HmacDRBG;
23858
23859HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
23860 var seed = entropy.concat(nonce).concat(pers);
23861
23862 this.K = new Array(this.outLen / 8);
23863 this.V = new Array(this.outLen / 8);
23864 for (var i = 0; i < this.V.length; i++) {
23865 this.K[i] = 0x00;
23866 this.V[i] = 0x01;
23867 }
23868
23869 this._update(seed);
23870 this._reseed = 1;
23871 this.reseedInterval = 0x1000000000000; // 2^48
23872};
23873
23874HmacDRBG.prototype._hmac = function hmac() {
23875 return new hash.hmac(this.hash, this.K);
23876};
23877
23878HmacDRBG.prototype._update = function update(seed) {
23879 var kmac = this._hmac()
23880 .update(this.V)
23881 .update([ 0x00 ]);
23882 if (seed)
23883 kmac = kmac.update(seed);
23884 this.K = kmac.digest();
23885 this.V = this._hmac().update(this.V).digest();
23886 if (!seed)
23887 return;
23888
23889 this.K = this._hmac()
23890 .update(this.V)
23891 .update([ 0x01 ])
23892 .update(seed)
23893 .digest();
23894 this.V = this._hmac().update(this.V).digest();
23895};
23896
23897HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
23898 // Optional entropy enc
23899 if (typeof entropyEnc !== 'string') {
23900 addEnc = add;
23901 add = entropyEnc;
23902 entropyEnc = null;
23903 }
23904
23905 entropy = utils.toArray(entropy, entropyEnc);
23906 add = utils.toArray(add, addEnc);
23907
23908 assert(entropy.length >= (this.minEntropy / 8),
23909 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
23910
23911 this._update(entropy.concat(add || []));
23912 this._reseed = 1;
23913};
23914
23915HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
23916 if (this._reseed > this.reseedInterval)
23917 throw new Error('Reseed is required');
23918
23919 // Optional encoding
23920 if (typeof enc !== 'string') {
23921 addEnc = add;
23922 add = enc;
23923 enc = null;
23924 }
23925
23926 // Optional additional data
23927 if (add) {
23928 add = utils.toArray(add, addEnc || 'hex');
23929 this._update(add);
23930 }
23931
23932 var temp = [];
23933 while (temp.length < len) {
23934 this.V = this._hmac().update(this.V).digest();
23935 temp = temp.concat(this.V);
23936 }
23937
23938 var res = temp.slice(0, len);
23939 this._update(add);
23940 this._reseed++;
23941 return utils.encode(res, enc);
23942};
23943
23944},{"hash.js":148,"minimalistic-assert":167,"minimalistic-crypto-utils":168}],161:[function(require,module,exports){
23945exports.read = function (buffer, offset, isLE, mLen, nBytes) {
23946 var e, m
23947 var eLen = (nBytes * 8) - mLen - 1
23948 var eMax = (1 << eLen) - 1
23949 var eBias = eMax >> 1
23950 var nBits = -7
23951 var i = isLE ? (nBytes - 1) : 0
23952 var d = isLE ? -1 : 1
23953 var s = buffer[offset + i]
23954
23955 i += d
23956
23957 e = s & ((1 << (-nBits)) - 1)
23958 s >>= (-nBits)
23959 nBits += eLen
23960 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
23961
23962 m = e & ((1 << (-nBits)) - 1)
23963 e >>= (-nBits)
23964 nBits += mLen
23965 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
23966
23967 if (e === 0) {
23968 e = 1 - eBias
23969 } else if (e === eMax) {
23970 return m ? NaN : ((s ? -1 : 1) * Infinity)
23971 } else {
23972 m = m + Math.pow(2, mLen)
23973 e = e - eBias
23974 }
23975 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
23976}
23977
23978exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
23979 var e, m, c
23980 var eLen = (nBytes * 8) - mLen - 1
23981 var eMax = (1 << eLen) - 1
23982 var eBias = eMax >> 1
23983 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
23984 var i = isLE ? 0 : (nBytes - 1)
23985 var d = isLE ? 1 : -1
23986 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
23987
23988 value = Math.abs(value)
23989
23990 if (isNaN(value) || value === Infinity) {
23991 m = isNaN(value) ? 1 : 0
23992 e = eMax
23993 } else {
23994 e = Math.floor(Math.log(value) / Math.LN2)
23995 if (value * (c = Math.pow(2, -e)) < 1) {
23996 e--
23997 c *= 2
23998 }
23999 if (e + eBias >= 1) {
24000 value += rt / c
24001 } else {
24002 value += rt * Math.pow(2, 1 - eBias)
24003 }
24004 if (value * c >= 2) {
24005 e++
24006 c /= 2
24007 }
24008
24009 if (e + eBias >= eMax) {
24010 m = 0
24011 e = eMax
24012 } else if (e + eBias >= 1) {
24013 m = ((value * c) - 1) * Math.pow(2, mLen)
24014 e = e + eBias
24015 } else {
24016 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
24017 e = 0
24018 }
24019 }
24020
24021 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
24022
24023 e = (e << mLen) | m
24024 eLen += mLen
24025 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
24026
24027 buffer[offset + i - d] |= s * 128
24028}
24029
24030},{}],162:[function(require,module,exports){
24031arguments[4][44][0].apply(exports,arguments)
24032},{"dup":44}],163:[function(require,module,exports){
24033/*!
24034 * Determine if an object is a Buffer
24035 *
24036 * @author Feross Aboukhadijeh <https://feross.org>
24037 * @license MIT
24038 */
24039
24040// The _isBuffer check is for Safari 5-7 support, because it's missing
24041// Object.prototype.constructor. Remove this eventually
24042module.exports = function (obj) {
24043 return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
24044}
24045
24046function isBuffer (obj) {
24047 return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
24048}
24049
24050// For Node v0.10 support. Remove this eventually.
24051function isSlowBuffer (obj) {
24052 return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
24053}
24054
24055},{}],164:[function(require,module,exports){
24056var toString = {}.toString;
24057
24058module.exports = Array.isArray || function (arr) {
24059 return toString.call(arr) == '[object Array]';
24060};
24061
24062},{}],165:[function(require,module,exports){
24063arguments[4][45][0].apply(exports,arguments)
24064},{"dup":45,"hash-base":147,"inherits":162,"safe-buffer":206}],166:[function(require,module,exports){
24065var bn = require('bn.js');
24066var brorand = require('brorand');
24067
24068function MillerRabin(rand) {
24069 this.rand = rand || new brorand.Rand();
24070}
24071module.exports = MillerRabin;
24072
24073MillerRabin.create = function create(rand) {
24074 return new MillerRabin(rand);
24075};
24076
24077MillerRabin.prototype._randbelow = function _randbelow(n) {
24078 var len = n.bitLength();
24079 var min_bytes = Math.ceil(len / 8);
24080
24081 // Generage random bytes until a number less than n is found.
24082 // This ensures that 0..n-1 have an equal probability of being selected.
24083 do
24084 var a = new bn(this.rand.generate(min_bytes));
24085 while (a.cmp(n) >= 0);
24086
24087 return a;
24088};
24089
24090MillerRabin.prototype._randrange = function _randrange(start, stop) {
24091 // Generate a random number greater than or equal to start and less than stop.
24092 var size = stop.sub(start);
24093 return start.add(this._randbelow(size));
24094};
24095
24096MillerRabin.prototype.test = function test(n, k, cb) {
24097 var len = n.bitLength();
24098 var red = bn.mont(n);
24099 var rone = new bn(1).toRed(red);
24100
24101 if (!k)
24102 k = Math.max(1, (len / 48) | 0);
24103
24104 // Find d and s, (n - 1) = (2 ^ s) * d;
24105 var n1 = n.subn(1);
24106 for (var s = 0; !n1.testn(s); s++) {}
24107 var d = n.shrn(s);
24108
24109 var rn1 = n1.toRed(red);
24110
24111 var prime = true;
24112 for (; k > 0; k--) {
24113 var a = this._randrange(new bn(2), n1);
24114 if (cb)
24115 cb(a);
24116
24117 var x = a.toRed(red).redPow(d);
24118 if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
24119 continue;
24120
24121 for (var i = 1; i < s; i++) {
24122 x = x.redSqr();
24123
24124 if (x.cmp(rone) === 0)
24125 return false;
24126 if (x.cmp(rn1) === 0)
24127 break;
24128 }
24129
24130 if (i === s)
24131 return false;
24132 }
24133
24134 return prime;
24135};
24136
24137MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
24138 var len = n.bitLength();
24139 var red = bn.mont(n);
24140 var rone = new bn(1).toRed(red);
24141
24142 if (!k)
24143 k = Math.max(1, (len / 48) | 0);
24144
24145 // Find d and s, (n - 1) = (2 ^ s) * d;
24146 var n1 = n.subn(1);
24147 for (var s = 0; !n1.testn(s); s++) {}
24148 var d = n.shrn(s);
24149
24150 var rn1 = n1.toRed(red);
24151
24152 for (; k > 0; k--) {
24153 var a = this._randrange(new bn(2), n1);
24154
24155 var g = n.gcd(a);
24156 if (g.cmpn(1) !== 0)
24157 return g;
24158
24159 var x = a.toRed(red).redPow(d);
24160 if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
24161 continue;
24162
24163 for (var i = 1; i < s; i++) {
24164 x = x.redSqr();
24165
24166 if (x.cmp(rone) === 0)
24167 return x.fromRed().subn(1).gcd(n);
24168 if (x.cmp(rn1) === 0)
24169 break;
24170 }
24171
24172 if (i === s) {
24173 x = x.redSqr();
24174 return x.fromRed().subn(1).gcd(n);
24175 }
24176 }
24177
24178 return false;
24179};
24180
24181},{"bn.js":79,"brorand":80}],167:[function(require,module,exports){
24182module.exports = assert;
24183
24184function assert(val, msg) {
24185 if (!val)
24186 throw new Error(msg || 'Assertion failed');
24187}
24188
24189assert.equal = function assertEqual(l, r, msg) {
24190 if (l != r)
24191 throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
24192};
24193
24194},{}],168:[function(require,module,exports){
24195'use strict';
24196
24197var utils = exports;
24198
24199function toArray(msg, enc) {
24200 if (Array.isArray(msg))
24201 return msg.slice();
24202 if (!msg)
24203 return [];
24204 var res = [];
24205 if (typeof msg !== 'string') {
24206 for (var i = 0; i < msg.length; i++)
24207 res[i] = msg[i] | 0;
24208 return res;
24209 }
24210 if (enc === 'hex') {
24211 msg = msg.replace(/[^a-z0-9]+/ig, '');
24212 if (msg.length % 2 !== 0)
24213 msg = '0' + msg;
24214 for (var i = 0; i < msg.length; i += 2)
24215 res.push(parseInt(msg[i] + msg[i + 1], 16));
24216 } else {
24217 for (var i = 0; i < msg.length; i++) {
24218 var c = msg.charCodeAt(i);
24219 var hi = c >> 8;
24220 var lo = c & 0xff;
24221 if (hi)
24222 res.push(hi, lo);
24223 else
24224 res.push(lo);
24225 }
24226 }
24227 return res;
24228}
24229utils.toArray = toArray;
24230
24231function zero2(word) {
24232 if (word.length === 1)
24233 return '0' + word;
24234 else
24235 return word;
24236}
24237utils.zero2 = zero2;
24238
24239function toHex(msg) {
24240 var res = '';
24241 for (var i = 0; i < msg.length; i++)
24242 res += zero2(msg[i].toString(16));
24243 return res;
24244}
24245utils.toHex = toHex;
24246
24247utils.encode = function encode(arr, enc) {
24248 if (enc === 'hex')
24249 return toHex(arr);
24250 else
24251 return arr;
24252};
24253
24254},{}],169:[function(require,module,exports){
24255/*
24256object-assign
24257(c) Sindre Sorhus
24258@license MIT
24259*/
24260
24261'use strict';
24262/* eslint-disable no-unused-vars */
24263var getOwnPropertySymbols = Object.getOwnPropertySymbols;
24264var hasOwnProperty = Object.prototype.hasOwnProperty;
24265var propIsEnumerable = Object.prototype.propertyIsEnumerable;
24266
24267function toObject(val) {
24268 if (val === null || val === undefined) {
24269 throw new TypeError('Object.assign cannot be called with null or undefined');
24270 }
24271
24272 return Object(val);
24273}
24274
24275function shouldUseNative() {
24276 try {
24277 if (!Object.assign) {
24278 return false;
24279 }
24280
24281 // Detect buggy property enumeration order in older V8 versions.
24282
24283 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
24284 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
24285 test1[5] = 'de';
24286 if (Object.getOwnPropertyNames(test1)[0] === '5') {
24287 return false;
24288 }
24289
24290 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
24291 var test2 = {};
24292 for (var i = 0; i < 10; i++) {
24293 test2['_' + String.fromCharCode(i)] = i;
24294 }
24295 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
24296 return test2[n];
24297 });
24298 if (order2.join('') !== '0123456789') {
24299 return false;
24300 }
24301
24302 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
24303 var test3 = {};
24304 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
24305 test3[letter] = letter;
24306 });
24307 if (Object.keys(Object.assign({}, test3)).join('') !==
24308 'abcdefghijklmnopqrst') {
24309 return false;
24310 }
24311
24312 return true;
24313 } catch (err) {
24314 // We don't expect any of the above to throw, but better to be safe.
24315 return false;
24316 }
24317}
24318
24319module.exports = shouldUseNative() ? Object.assign : function (target, source) {
24320 var from;
24321 var to = toObject(target);
24322 var symbols;
24323
24324 for (var s = 1; s < arguments.length; s++) {
24325 from = Object(arguments[s]);
24326
24327 for (var key in from) {
24328 if (hasOwnProperty.call(from, key)) {
24329 to[key] = from[key];
24330 }
24331 }
24332
24333 if (getOwnPropertySymbols) {
24334 symbols = getOwnPropertySymbols(from);
24335 for (var i = 0; i < symbols.length; i++) {
24336 if (propIsEnumerable.call(from, symbols[i])) {
24337 to[symbols[i]] = from[symbols[i]];
24338 }
24339 }
24340 }
24341 }
24342
24343 return to;
24344};
24345
24346},{}],170:[function(require,module,exports){
24347module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
24348"2.16.840.1.101.3.4.1.2": "aes-128-cbc",
24349"2.16.840.1.101.3.4.1.3": "aes-128-ofb",
24350"2.16.840.1.101.3.4.1.4": "aes-128-cfb",
24351"2.16.840.1.101.3.4.1.21": "aes-192-ecb",
24352"2.16.840.1.101.3.4.1.22": "aes-192-cbc",
24353"2.16.840.1.101.3.4.1.23": "aes-192-ofb",
24354"2.16.840.1.101.3.4.1.24": "aes-192-cfb",
24355"2.16.840.1.101.3.4.1.41": "aes-256-ecb",
24356"2.16.840.1.101.3.4.1.42": "aes-256-cbc",
24357"2.16.840.1.101.3.4.1.43": "aes-256-ofb",
24358"2.16.840.1.101.3.4.1.44": "aes-256-cfb"
24359}
24360},{}],171:[function(require,module,exports){
24361// from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
24362// Fedor, you are amazing.
24363'use strict'
24364
24365var asn1 = require('asn1.js')
24366
24367exports.certificate = require('./certificate')
24368
24369var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
24370 this.seq().obj(
24371 this.key('version').int(),
24372 this.key('modulus').int(),
24373 this.key('publicExponent').int(),
24374 this.key('privateExponent').int(),
24375 this.key('prime1').int(),
24376 this.key('prime2').int(),
24377 this.key('exponent1').int(),
24378 this.key('exponent2').int(),
24379 this.key('coefficient').int()
24380 )
24381})
24382exports.RSAPrivateKey = RSAPrivateKey
24383
24384var RSAPublicKey = asn1.define('RSAPublicKey', function () {
24385 this.seq().obj(
24386 this.key('modulus').int(),
24387 this.key('publicExponent').int()
24388 )
24389})
24390exports.RSAPublicKey = RSAPublicKey
24391
24392var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
24393 this.seq().obj(
24394 this.key('algorithm').use(AlgorithmIdentifier),
24395 this.key('subjectPublicKey').bitstr()
24396 )
24397})
24398exports.PublicKey = PublicKey
24399
24400var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
24401 this.seq().obj(
24402 this.key('algorithm').objid(),
24403 this.key('none').null_().optional(),
24404 this.key('curve').objid().optional(),
24405 this.key('params').seq().obj(
24406 this.key('p').int(),
24407 this.key('q').int(),
24408 this.key('g').int()
24409 ).optional()
24410 )
24411})
24412
24413var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
24414 this.seq().obj(
24415 this.key('version').int(),
24416 this.key('algorithm').use(AlgorithmIdentifier),
24417 this.key('subjectPrivateKey').octstr()
24418 )
24419})
24420exports.PrivateKey = PrivateKeyInfo
24421var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
24422 this.seq().obj(
24423 this.key('algorithm').seq().obj(
24424 this.key('id').objid(),
24425 this.key('decrypt').seq().obj(
24426 this.key('kde').seq().obj(
24427 this.key('id').objid(),
24428 this.key('kdeparams').seq().obj(
24429 this.key('salt').octstr(),
24430 this.key('iters').int()
24431 )
24432 ),
24433 this.key('cipher').seq().obj(
24434 this.key('algo').objid(),
24435 this.key('iv').octstr()
24436 )
24437 )
24438 ),
24439 this.key('subjectPrivateKey').octstr()
24440 )
24441})
24442
24443exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo
24444
24445var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
24446 this.seq().obj(
24447 this.key('version').int(),
24448 this.key('p').int(),
24449 this.key('q').int(),
24450 this.key('g').int(),
24451 this.key('pub_key').int(),
24452 this.key('priv_key').int()
24453 )
24454})
24455exports.DSAPrivateKey = DSAPrivateKey
24456
24457exports.DSAparam = asn1.define('DSAparam', function () {
24458 this.int()
24459})
24460
24461var ECPrivateKey = asn1.define('ECPrivateKey', function () {
24462 this.seq().obj(
24463 this.key('version').int(),
24464 this.key('privateKey').octstr(),
24465 this.key('parameters').optional().explicit(0).use(ECParameters),
24466 this.key('publicKey').optional().explicit(1).bitstr()
24467 )
24468})
24469exports.ECPrivateKey = ECPrivateKey
24470
24471var ECParameters = asn1.define('ECParameters', function () {
24472 this.choice({
24473 namedCurve: this.objid()
24474 })
24475})
24476
24477exports.signature = asn1.define('signature', function () {
24478 this.seq().obj(
24479 this.key('r').int(),
24480 this.key('s').int()
24481 )
24482})
24483
24484},{"./certificate":172,"asn1.js":60}],172:[function(require,module,exports){
24485// from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
24486// thanks to @Rantanen
24487
24488'use strict'
24489
24490var asn = require('asn1.js')
24491
24492var Time = asn.define('Time', function () {
24493 this.choice({
24494 utcTime: this.utctime(),
24495 generalTime: this.gentime()
24496 })
24497})
24498
24499var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
24500 this.seq().obj(
24501 this.key('type').objid(),
24502 this.key('value').any()
24503 )
24504})
24505
24506var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
24507 this.seq().obj(
24508 this.key('algorithm').objid(),
24509 this.key('parameters').optional(),
24510 this.key('curve').objid().optional()
24511 )
24512})
24513
24514var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
24515 this.seq().obj(
24516 this.key('algorithm').use(AlgorithmIdentifier),
24517 this.key('subjectPublicKey').bitstr()
24518 )
24519})
24520
24521var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
24522 this.setof(AttributeTypeValue)
24523})
24524
24525var RDNSequence = asn.define('RDNSequence', function () {
24526 this.seqof(RelativeDistinguishedName)
24527})
24528
24529var Name = asn.define('Name', function () {
24530 this.choice({
24531 rdnSequence: this.use(RDNSequence)
24532 })
24533})
24534
24535var Validity = asn.define('Validity', function () {
24536 this.seq().obj(
24537 this.key('notBefore').use(Time),
24538 this.key('notAfter').use(Time)
24539 )
24540})
24541
24542var Extension = asn.define('Extension', function () {
24543 this.seq().obj(
24544 this.key('extnID').objid(),
24545 this.key('critical').bool().def(false),
24546 this.key('extnValue').octstr()
24547 )
24548})
24549
24550var TBSCertificate = asn.define('TBSCertificate', function () {
24551 this.seq().obj(
24552 this.key('version').explicit(0).int().optional(),
24553 this.key('serialNumber').int(),
24554 this.key('signature').use(AlgorithmIdentifier),
24555 this.key('issuer').use(Name),
24556 this.key('validity').use(Validity),
24557 this.key('subject').use(Name),
24558 this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo),
24559 this.key('issuerUniqueID').implicit(1).bitstr().optional(),
24560 this.key('subjectUniqueID').implicit(2).bitstr().optional(),
24561 this.key('extensions').explicit(3).seqof(Extension).optional()
24562 )
24563})
24564
24565var X509Certificate = asn.define('X509Certificate', function () {
24566 this.seq().obj(
24567 this.key('tbsCertificate').use(TBSCertificate),
24568 this.key('signatureAlgorithm').use(AlgorithmIdentifier),
24569 this.key('signatureValue').bitstr()
24570 )
24571})
24572
24573module.exports = X509Certificate
24574
24575},{"asn1.js":60}],173:[function(require,module,exports){
24576// adapted from https://github.com/apatil/pemstrip
24577var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r\+\/\=]+)[\n\r]+/m
24578var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m
24579var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r\+\/\=]+)-----END \1-----$/m
24580var evp = require('evp_bytestokey')
24581var ciphers = require('browserify-aes')
24582var Buffer = require('safe-buffer').Buffer
24583module.exports = function (okey, password) {
24584 var key = okey.toString()
24585 var match = key.match(findProc)
24586 var decrypted
24587 if (!match) {
24588 var match2 = key.match(fullRegex)
24589 decrypted = new Buffer(match2[2].replace(/[\r\n]/g, ''), 'base64')
24590 } else {
24591 var suite = 'aes' + match[1]
24592 var iv = Buffer.from(match[2], 'hex')
24593 var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ''), 'base64')
24594 var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key
24595 var out = []
24596 var cipher = ciphers.createDecipheriv(suite, cipherKey, iv)
24597 out.push(cipher.update(cipherText))
24598 out.push(cipher.final())
24599 decrypted = Buffer.concat(out)
24600 }
24601 var tag = key.match(startRegex)[1]
24602 return {
24603 tag: tag,
24604 data: decrypted
24605 }
24606}
24607
24608},{"browserify-aes":84,"evp_bytestokey":146,"safe-buffer":206}],174:[function(require,module,exports){
24609var asn1 = require('./asn1')
24610var aesid = require('./aesid.json')
24611var fixProc = require('./fixProc')
24612var ciphers = require('browserify-aes')
24613var compat = require('pbkdf2')
24614var Buffer = require('safe-buffer').Buffer
24615module.exports = parseKeys
24616
24617function parseKeys (buffer) {
24618 var password
24619 if (typeof buffer === 'object' && !Buffer.isBuffer(buffer)) {
24620 password = buffer.passphrase
24621 buffer = buffer.key
24622 }
24623 if (typeof buffer === 'string') {
24624 buffer = Buffer.from(buffer)
24625 }
24626
24627 var stripped = fixProc(buffer, password)
24628
24629 var type = stripped.tag
24630 var data = stripped.data
24631 var subtype, ndata
24632 switch (type) {
24633 case 'CERTIFICATE':
24634 ndata = asn1.certificate.decode(data, 'der').tbsCertificate.subjectPublicKeyInfo
24635 // falls through
24636 case 'PUBLIC KEY':
24637 if (!ndata) {
24638 ndata = asn1.PublicKey.decode(data, 'der')
24639 }
24640 subtype = ndata.algorithm.algorithm.join('.')
24641 switch (subtype) {
24642 case '1.2.840.113549.1.1.1':
24643 return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der')
24644 case '1.2.840.10045.2.1':
24645 ndata.subjectPrivateKey = ndata.subjectPublicKey
24646 return {
24647 type: 'ec',
24648 data: ndata
24649 }
24650 case '1.2.840.10040.4.1':
24651 ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der')
24652 return {
24653 type: 'dsa',
24654 data: ndata.algorithm.params
24655 }
24656 default: throw new Error('unknown key id ' + subtype)
24657 }
24658 throw new Error('unknown key type ' + type)
24659 case 'ENCRYPTED PRIVATE KEY':
24660 data = asn1.EncryptedPrivateKey.decode(data, 'der')
24661 data = decrypt(data, password)
24662 // falls through
24663 case 'PRIVATE KEY':
24664 ndata = asn1.PrivateKey.decode(data, 'der')
24665 subtype = ndata.algorithm.algorithm.join('.')
24666 switch (subtype) {
24667 case '1.2.840.113549.1.1.1':
24668 return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der')
24669 case '1.2.840.10045.2.1':
24670 return {
24671 curve: ndata.algorithm.curve,
24672 privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
24673 }
24674 case '1.2.840.10040.4.1':
24675 ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der')
24676 return {
24677 type: 'dsa',
24678 params: ndata.algorithm.params
24679 }
24680 default: throw new Error('unknown key id ' + subtype)
24681 }
24682 throw new Error('unknown key type ' + type)
24683 case 'RSA PUBLIC KEY':
24684 return asn1.RSAPublicKey.decode(data, 'der')
24685 case 'RSA PRIVATE KEY':
24686 return asn1.RSAPrivateKey.decode(data, 'der')
24687 case 'DSA PRIVATE KEY':
24688 return {
24689 type: 'dsa',
24690 params: asn1.DSAPrivateKey.decode(data, 'der')
24691 }
24692 case 'EC PRIVATE KEY':
24693 data = asn1.ECPrivateKey.decode(data, 'der')
24694 return {
24695 curve: data.parameters.value,
24696 privateKey: data.privateKey
24697 }
24698 default: throw new Error('unknown key type ' + type)
24699 }
24700}
24701parseKeys.signature = asn1.signature
24702function decrypt (data, password) {
24703 var salt = data.algorithm.decrypt.kde.kdeparams.salt
24704 var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10)
24705 var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')]
24706 var iv = data.algorithm.decrypt.cipher.iv
24707 var cipherText = data.subjectPrivateKey
24708 var keylen = parseInt(algo.split('-')[1], 10) / 8
24709 var key = compat.pbkdf2Sync(password, salt, iters, keylen, 'sha1')
24710 var cipher = ciphers.createDecipheriv(algo, key, iv)
24711 var out = []
24712 out.push(cipher.update(cipherText))
24713 out.push(cipher.final())
24714 return Buffer.concat(out)
24715}
24716
24717},{"./aesid.json":170,"./asn1":171,"./fixProc":173,"browserify-aes":84,"pbkdf2":175,"safe-buffer":206}],175:[function(require,module,exports){
24718exports.pbkdf2 = require('./lib/async')
24719exports.pbkdf2Sync = require('./lib/sync')
24720
24721},{"./lib/async":176,"./lib/sync":179}],176:[function(require,module,exports){
24722(function (process,global){
24723var checkParameters = require('./precondition')
24724var defaultEncoding = require('./default-encoding')
24725var sync = require('./sync')
24726var Buffer = require('safe-buffer').Buffer
24727
24728var ZERO_BUF
24729var subtle = global.crypto && global.crypto.subtle
24730var toBrowser = {
24731 'sha': 'SHA-1',
24732 'sha-1': 'SHA-1',
24733 'sha1': 'SHA-1',
24734 'sha256': 'SHA-256',
24735 'sha-256': 'SHA-256',
24736 'sha384': 'SHA-384',
24737 'sha-384': 'SHA-384',
24738 'sha-512': 'SHA-512',
24739 'sha512': 'SHA-512'
24740}
24741var checks = []
24742function checkNative (algo) {
24743 if (global.process && !global.process.browser) {
24744 return Promise.resolve(false)
24745 }
24746 if (!subtle || !subtle.importKey || !subtle.deriveBits) {
24747 return Promise.resolve(false)
24748 }
24749 if (checks[algo] !== undefined) {
24750 return checks[algo]
24751 }
24752 ZERO_BUF = ZERO_BUF || Buffer.alloc(8)
24753 var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo)
24754 .then(function () {
24755 return true
24756 }).catch(function () {
24757 return false
24758 })
24759 checks[algo] = prom
24760 return prom
24761}
24762
24763function browserPbkdf2 (password, salt, iterations, length, algo) {
24764 return subtle.importKey(
24765 'raw', password, {name: 'PBKDF2'}, false, ['deriveBits']
24766 ).then(function (key) {
24767 return subtle.deriveBits({
24768 name: 'PBKDF2',
24769 salt: salt,
24770 iterations: iterations,
24771 hash: {
24772 name: algo
24773 }
24774 }, key, length << 3)
24775 }).then(function (res) {
24776 return Buffer.from(res)
24777 })
24778}
24779
24780function resolvePromise (promise, callback) {
24781 promise.then(function (out) {
24782 process.nextTick(function () {
24783 callback(null, out)
24784 })
24785 }, function (e) {
24786 process.nextTick(function () {
24787 callback(e)
24788 })
24789 })
24790}
24791module.exports = function (password, salt, iterations, keylen, digest, callback) {
24792 if (typeof digest === 'function') {
24793 callback = digest
24794 digest = undefined
24795 }
24796
24797 digest = digest || 'sha1'
24798 var algo = toBrowser[digest.toLowerCase()]
24799
24800 if (!algo || typeof global.Promise !== 'function') {
24801 return process.nextTick(function () {
24802 var out
24803 try {
24804 out = sync(password, salt, iterations, keylen, digest)
24805 } catch (e) {
24806 return callback(e)
24807 }
24808 callback(null, out)
24809 })
24810 }
24811
24812 checkParameters(password, salt, iterations, keylen)
24813 if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
24814 if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
24815 if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
24816
24817 resolvePromise(checkNative(algo).then(function (resp) {
24818 if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo)
24819
24820 return sync(password, salt, iterations, keylen, digest)
24821 }), callback)
24822}
24823
24824}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
24825},{"./default-encoding":177,"./precondition":178,"./sync":179,"_process":181,"safe-buffer":206}],177:[function(require,module,exports){
24826(function (process){
24827var defaultEncoding
24828/* istanbul ignore next */
24829if (process.browser) {
24830 defaultEncoding = 'utf-8'
24831} else {
24832 var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
24833
24834 defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
24835}
24836module.exports = defaultEncoding
24837
24838}).call(this,require('_process'))
24839},{"_process":181}],178:[function(require,module,exports){
24840(function (Buffer){
24841var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
24842
24843function checkBuffer (buf, name) {
24844 if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
24845 throw new TypeError(name + ' must be a buffer or string')
24846 }
24847}
24848
24849module.exports = function (password, salt, iterations, keylen) {
24850 checkBuffer(password, 'Password')
24851 checkBuffer(salt, 'Salt')
24852
24853 if (typeof iterations !== 'number') {
24854 throw new TypeError('Iterations not a number')
24855 }
24856
24857 if (iterations < 0) {
24858 throw new TypeError('Bad iterations')
24859 }
24860
24861 if (typeof keylen !== 'number') {
24862 throw new TypeError('Key length not a number')
24863 }
24864
24865 if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
24866 throw new TypeError('Bad key length')
24867 }
24868}
24869
24870}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
24871},{"../../is-buffer/index.js":163}],179:[function(require,module,exports){
24872var md5 = require('create-hash/md5')
24873var RIPEMD160 = require('ripemd160')
24874var sha = require('sha.js')
24875
24876var checkParameters = require('./precondition')
24877var defaultEncoding = require('./default-encoding')
24878var Buffer = require('safe-buffer').Buffer
24879var ZEROS = Buffer.alloc(128)
24880var sizes = {
24881 md5: 16,
24882 sha1: 20,
24883 sha224: 28,
24884 sha256: 32,
24885 sha384: 48,
24886 sha512: 64,
24887 rmd160: 20,
24888 ripemd160: 20
24889}
24890
24891function Hmac (alg, key, saltLen) {
24892 var hash = getDigest(alg)
24893 var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
24894
24895 if (key.length > blocksize) {
24896 key = hash(key)
24897 } else if (key.length < blocksize) {
24898 key = Buffer.concat([key, ZEROS], blocksize)
24899 }
24900
24901 var ipad = Buffer.allocUnsafe(blocksize + sizes[alg])
24902 var opad = Buffer.allocUnsafe(blocksize + sizes[alg])
24903 for (var i = 0; i < blocksize; i++) {
24904 ipad[i] = key[i] ^ 0x36
24905 opad[i] = key[i] ^ 0x5C
24906 }
24907
24908 var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4)
24909 ipad.copy(ipad1, 0, 0, blocksize)
24910 this.ipad1 = ipad1
24911 this.ipad2 = ipad
24912 this.opad = opad
24913 this.alg = alg
24914 this.blocksize = blocksize
24915 this.hash = hash
24916 this.size = sizes[alg]
24917}
24918
24919Hmac.prototype.run = function (data, ipad) {
24920 data.copy(ipad, this.blocksize)
24921 var h = this.hash(ipad)
24922 h.copy(this.opad, this.blocksize)
24923 return this.hash(this.opad)
24924}
24925
24926function getDigest (alg) {
24927 function shaFunc (data) {
24928 return sha(alg).update(data).digest()
24929 }
24930 function rmd160Func (data) {
24931 return new RIPEMD160().update(data).digest()
24932 }
24933
24934 if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func
24935 if (alg === 'md5') return md5
24936 return shaFunc
24937}
24938
24939function pbkdf2 (password, salt, iterations, keylen, digest) {
24940 checkParameters(password, salt, iterations, keylen)
24941
24942 if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
24943 if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
24944
24945 digest = digest || 'sha1'
24946
24947 var hmac = new Hmac(digest, password, salt.length)
24948
24949 var DK = Buffer.allocUnsafe(keylen)
24950 var block1 = Buffer.allocUnsafe(salt.length + 4)
24951 salt.copy(block1, 0, 0, salt.length)
24952
24953 var destPos = 0
24954 var hLen = sizes[digest]
24955 var l = Math.ceil(keylen / hLen)
24956
24957 for (var i = 1; i <= l; i++) {
24958 block1.writeUInt32BE(i, salt.length)
24959
24960 var T = hmac.run(block1, hmac.ipad1)
24961 var U = T
24962
24963 for (var j = 1; j < iterations; j++) {
24964 U = hmac.run(U, hmac.ipad2)
24965 for (var k = 0; k < hLen; k++) T[k] ^= U[k]
24966 }
24967
24968 T.copy(DK, destPos)
24969 destPos += hLen
24970 }
24971
24972 return DK
24973}
24974
24975module.exports = pbkdf2
24976
24977},{"./default-encoding":177,"./precondition":178,"create-hash/md5":115,"ripemd160":205,"safe-buffer":206,"sha.js":208}],180:[function(require,module,exports){
24978(function (process){
24979'use strict';
24980
24981if (typeof process === 'undefined' ||
24982 !process.version ||
24983 process.version.indexOf('v0.') === 0 ||
24984 process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
24985 module.exports = { nextTick: nextTick };
24986} else {
24987 module.exports = process
24988}
24989
24990function nextTick(fn, arg1, arg2, arg3) {
24991 if (typeof fn !== 'function') {
24992 throw new TypeError('"callback" argument must be a function');
24993 }
24994 var len = arguments.length;
24995 var args, i;
24996 switch (len) {
24997 case 0:
24998 case 1:
24999 return process.nextTick(fn);
25000 case 2:
25001 return process.nextTick(function afterTickOne() {
25002 fn.call(null, arg1);
25003 });
25004 case 3:
25005 return process.nextTick(function afterTickTwo() {
25006 fn.call(null, arg1, arg2);
25007 });
25008 case 4:
25009 return process.nextTick(function afterTickThree() {
25010 fn.call(null, arg1, arg2, arg3);
25011 });
25012 default:
25013 args = new Array(len - 1);
25014 i = 0;
25015 while (i < args.length) {
25016 args[i++] = arguments[i];
25017 }
25018 return process.nextTick(function afterTick() {
25019 fn.apply(null, args);
25020 });
25021 }
25022}
25023
25024
25025}).call(this,require('_process'))
25026},{"_process":181}],181:[function(require,module,exports){
25027// shim for using process in browser
25028var process = module.exports = {};
25029
25030// cached from whatever global is present so that test runners that stub it
25031// don't break things. But we need to wrap it in a try catch in case it is
25032// wrapped in strict mode code which doesn't define any globals. It's inside a
25033// function because try/catches deoptimize in certain engines.
25034
25035var cachedSetTimeout;
25036var cachedClearTimeout;
25037
25038function defaultSetTimout() {
25039 throw new Error('setTimeout has not been defined');
25040}
25041function defaultClearTimeout () {
25042 throw new Error('clearTimeout has not been defined');
25043}
25044(function () {
25045 try {
25046 if (typeof setTimeout === 'function') {
25047 cachedSetTimeout = setTimeout;
25048 } else {
25049 cachedSetTimeout = defaultSetTimout;
25050 }
25051 } catch (e) {
25052 cachedSetTimeout = defaultSetTimout;
25053 }
25054 try {
25055 if (typeof clearTimeout === 'function') {
25056 cachedClearTimeout = clearTimeout;
25057 } else {
25058 cachedClearTimeout = defaultClearTimeout;
25059 }
25060 } catch (e) {
25061 cachedClearTimeout = defaultClearTimeout;
25062 }
25063} ())
25064function runTimeout(fun) {
25065 if (cachedSetTimeout === setTimeout) {
25066 //normal enviroments in sane situations
25067 return setTimeout(fun, 0);
25068 }
25069 // if setTimeout wasn't available but was latter defined
25070 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
25071 cachedSetTimeout = setTimeout;
25072 return setTimeout(fun, 0);
25073 }
25074 try {
25075 // when when somebody has screwed with setTimeout but no I.E. maddness
25076 return cachedSetTimeout(fun, 0);
25077 } catch(e){
25078 try {
25079 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
25080 return cachedSetTimeout.call(null, fun, 0);
25081 } catch(e){
25082 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
25083 return cachedSetTimeout.call(this, fun, 0);
25084 }
25085 }
25086
25087
25088}
25089function runClearTimeout(marker) {
25090 if (cachedClearTimeout === clearTimeout) {
25091 //normal enviroments in sane situations
25092 return clearTimeout(marker);
25093 }
25094 // if clearTimeout wasn't available but was latter defined
25095 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
25096 cachedClearTimeout = clearTimeout;
25097 return clearTimeout(marker);
25098 }
25099 try {
25100 // when when somebody has screwed with setTimeout but no I.E. maddness
25101 return cachedClearTimeout(marker);
25102 } catch (e){
25103 try {
25104 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
25105 return cachedClearTimeout.call(null, marker);
25106 } catch (e){
25107 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
25108 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
25109 return cachedClearTimeout.call(this, marker);
25110 }
25111 }
25112
25113
25114
25115}
25116var queue = [];
25117var draining = false;
25118var currentQueue;
25119var queueIndex = -1;
25120
25121function cleanUpNextTick() {
25122 if (!draining || !currentQueue) {
25123 return;
25124 }
25125 draining = false;
25126 if (currentQueue.length) {
25127 queue = currentQueue.concat(queue);
25128 } else {
25129 queueIndex = -1;
25130 }
25131 if (queue.length) {
25132 drainQueue();
25133 }
25134}
25135
25136function drainQueue() {
25137 if (draining) {
25138 return;
25139 }
25140 var timeout = runTimeout(cleanUpNextTick);
25141 draining = true;
25142
25143 var len = queue.length;
25144 while(len) {
25145 currentQueue = queue;
25146 queue = [];
25147 while (++queueIndex < len) {
25148 if (currentQueue) {
25149 currentQueue[queueIndex].run();
25150 }
25151 }
25152 queueIndex = -1;
25153 len = queue.length;
25154 }
25155 currentQueue = null;
25156 draining = false;
25157 runClearTimeout(timeout);
25158}
25159
25160process.nextTick = function (fun) {
25161 var args = new Array(arguments.length - 1);
25162 if (arguments.length > 1) {
25163 for (var i = 1; i < arguments.length; i++) {
25164 args[i - 1] = arguments[i];
25165 }
25166 }
25167 queue.push(new Item(fun, args));
25168 if (queue.length === 1 && !draining) {
25169 runTimeout(drainQueue);
25170 }
25171};
25172
25173// v8 likes predictible objects
25174function Item(fun, array) {
25175 this.fun = fun;
25176 this.array = array;
25177}
25178Item.prototype.run = function () {
25179 this.fun.apply(null, this.array);
25180};
25181process.title = 'browser';
25182process.browser = true;
25183process.env = {};
25184process.argv = [];
25185process.version = ''; // empty string to avoid regexp issues
25186process.versions = {};
25187
25188function noop() {}
25189
25190process.on = noop;
25191process.addListener = noop;
25192process.once = noop;
25193process.off = noop;
25194process.removeListener = noop;
25195process.removeAllListeners = noop;
25196process.emit = noop;
25197process.prependListener = noop;
25198process.prependOnceListener = noop;
25199
25200process.listeners = function (name) { return [] }
25201
25202process.binding = function (name) {
25203 throw new Error('process.binding is not supported');
25204};
25205
25206process.cwd = function () { return '/' };
25207process.chdir = function (dir) {
25208 throw new Error('process.chdir is not supported');
25209};
25210process.umask = function() { return 0; };
25211
25212},{}],182:[function(require,module,exports){
25213exports.publicEncrypt = require('./publicEncrypt')
25214exports.privateDecrypt = require('./privateDecrypt')
25215
25216exports.privateEncrypt = function privateEncrypt (key, buf) {
25217 return exports.publicEncrypt(key, buf, true)
25218}
25219
25220exports.publicDecrypt = function publicDecrypt (key, buf) {
25221 return exports.privateDecrypt(key, buf, true)
25222}
25223
25224},{"./privateDecrypt":184,"./publicEncrypt":185}],183:[function(require,module,exports){
25225var createHash = require('create-hash')
25226var Buffer = require('safe-buffer').Buffer
25227
25228module.exports = function (seed, len) {
25229 var t = Buffer.alloc(0)
25230 var i = 0
25231 var c
25232 while (t.length < len) {
25233 c = i2ops(i++)
25234 t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()])
25235 }
25236 return t.slice(0, len)
25237}
25238
25239function i2ops (c) {
25240 var out = Buffer.allocUnsafe(4)
25241 out.writeUInt32BE(c, 0)
25242 return out
25243}
25244
25245},{"create-hash":114,"safe-buffer":206}],184:[function(require,module,exports){
25246var parseKeys = require('parse-asn1')
25247var mgf = require('./mgf')
25248var xor = require('./xor')
25249var BN = require('bn.js')
25250var crt = require('browserify-rsa')
25251var createHash = require('create-hash')
25252var withPublic = require('./withPublic')
25253var Buffer = require('safe-buffer').Buffer
25254
25255module.exports = function privateDecrypt (privateKey, enc, reverse) {
25256 var padding
25257 if (privateKey.padding) {
25258 padding = privateKey.padding
25259 } else if (reverse) {
25260 padding = 1
25261 } else {
25262 padding = 4
25263 }
25264
25265 var key = parseKeys(privateKey)
25266 var k = key.modulus.byteLength()
25267 if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) {
25268 throw new Error('decryption error')
25269 }
25270 var msg
25271 if (reverse) {
25272 msg = withPublic(new BN(enc), key)
25273 } else {
25274 msg = crt(enc, key)
25275 }
25276 var zBuffer = Buffer.alloc(k - msg.length)
25277 msg = Buffer.concat([zBuffer, msg], k)
25278 if (padding === 4) {
25279 return oaep(key, msg)
25280 } else if (padding === 1) {
25281 return pkcs1(key, msg, reverse)
25282 } else if (padding === 3) {
25283 return msg
25284 } else {
25285 throw new Error('unknown padding')
25286 }
25287}
25288
25289function oaep (key, msg) {
25290 var k = key.modulus.byteLength()
25291 var iHash = createHash('sha1').update(Buffer.alloc(0)).digest()
25292 var hLen = iHash.length
25293 if (msg[0] !== 0) {
25294 throw new Error('decryption error')
25295 }
25296 var maskedSeed = msg.slice(1, hLen + 1)
25297 var maskedDb = msg.slice(hLen + 1)
25298 var seed = xor(maskedSeed, mgf(maskedDb, hLen))
25299 var db = xor(maskedDb, mgf(seed, k - hLen - 1))
25300 if (compare(iHash, db.slice(0, hLen))) {
25301 throw new Error('decryption error')
25302 }
25303 var i = hLen
25304 while (db[i] === 0) {
25305 i++
25306 }
25307 if (db[i++] !== 1) {
25308 throw new Error('decryption error')
25309 }
25310 return db.slice(i)
25311}
25312
25313function pkcs1 (key, msg, reverse) {
25314 var p1 = msg.slice(0, 2)
25315 var i = 2
25316 var status = 0
25317 while (msg[i++] !== 0) {
25318 if (i >= msg.length) {
25319 status++
25320 break
25321 }
25322 }
25323 var ps = msg.slice(2, i - 1)
25324
25325 if ((p1.toString('hex') !== '0002' && !reverse) || (p1.toString('hex') !== '0001' && reverse)) {
25326 status++
25327 }
25328 if (ps.length < 8) {
25329 status++
25330 }
25331 if (status) {
25332 throw new Error('decryption error')
25333 }
25334 return msg.slice(i)
25335}
25336function compare (a, b) {
25337 a = Buffer.from(a)
25338 b = Buffer.from(b)
25339 var dif = 0
25340 var len = a.length
25341 if (a.length !== b.length) {
25342 dif++
25343 len = Math.min(a.length, b.length)
25344 }
25345 var i = -1
25346 while (++i < len) {
25347 dif += (a[i] ^ b[i])
25348 }
25349 return dif
25350}
25351
25352},{"./mgf":183,"./withPublic":186,"./xor":187,"bn.js":79,"browserify-rsa":102,"create-hash":114,"parse-asn1":174,"safe-buffer":206}],185:[function(require,module,exports){
25353var parseKeys = require('parse-asn1')
25354var randomBytes = require('randombytes')
25355var createHash = require('create-hash')
25356var mgf = require('./mgf')
25357var xor = require('./xor')
25358var BN = require('bn.js')
25359var withPublic = require('./withPublic')
25360var crt = require('browserify-rsa')
25361var Buffer = require('safe-buffer').Buffer
25362
25363module.exports = function publicEncrypt (publicKey, msg, reverse) {
25364 var padding
25365 if (publicKey.padding) {
25366 padding = publicKey.padding
25367 } else if (reverse) {
25368 padding = 1
25369 } else {
25370 padding = 4
25371 }
25372 var key = parseKeys(publicKey)
25373 var paddedMsg
25374 if (padding === 4) {
25375 paddedMsg = oaep(key, msg)
25376 } else if (padding === 1) {
25377 paddedMsg = pkcs1(key, msg, reverse)
25378 } else if (padding === 3) {
25379 paddedMsg = new BN(msg)
25380 if (paddedMsg.cmp(key.modulus) >= 0) {
25381 throw new Error('data too long for modulus')
25382 }
25383 } else {
25384 throw new Error('unknown padding')
25385 }
25386 if (reverse) {
25387 return crt(paddedMsg, key)
25388 } else {
25389 return withPublic(paddedMsg, key)
25390 }
25391}
25392
25393function oaep (key, msg) {
25394 var k = key.modulus.byteLength()
25395 var mLen = msg.length
25396 var iHash = createHash('sha1').update(Buffer.alloc(0)).digest()
25397 var hLen = iHash.length
25398 var hLen2 = 2 * hLen
25399 if (mLen > k - hLen2 - 2) {
25400 throw new Error('message too long')
25401 }
25402 var ps = Buffer.alloc(k - mLen - hLen2 - 2)
25403 var dblen = k - hLen - 1
25404 var seed = randomBytes(hLen)
25405 var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen))
25406 var maskedSeed = xor(seed, mgf(maskedDb, hLen))
25407 return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k))
25408}
25409function pkcs1 (key, msg, reverse) {
25410 var mLen = msg.length
25411 var k = key.modulus.byteLength()
25412 if (mLen > k - 11) {
25413 throw new Error('message too long')
25414 }
25415 var ps
25416 if (reverse) {
25417 ps = Buffer.alloc(k - mLen - 3, 0xff)
25418 } else {
25419 ps = nonZero(k - mLen - 3)
25420 }
25421 return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k))
25422}
25423function nonZero (len) {
25424 var out = Buffer.allocUnsafe(len)
25425 var i = 0
25426 var cache = randomBytes(len * 2)
25427 var cur = 0
25428 var num
25429 while (i < len) {
25430 if (cur === cache.length) {
25431 cache = randomBytes(len * 2)
25432 cur = 0
25433 }
25434 num = cache[cur++]
25435 if (num) {
25436 out[i++] = num
25437 }
25438 }
25439 return out
25440}
25441
25442},{"./mgf":183,"./withPublic":186,"./xor":187,"bn.js":79,"browserify-rsa":102,"create-hash":114,"parse-asn1":174,"randombytes":188,"safe-buffer":206}],186:[function(require,module,exports){
25443var BN = require('bn.js')
25444var Buffer = require('safe-buffer').Buffer
25445
25446function withPublic (paddedMsg, key) {
25447 return Buffer.from(paddedMsg
25448 .toRed(BN.mont(key.modulus))
25449 .redPow(new BN(key.publicExponent))
25450 .fromRed()
25451 .toArray())
25452}
25453
25454module.exports = withPublic
25455
25456},{"bn.js":79,"safe-buffer":206}],187:[function(require,module,exports){
25457module.exports = function xor (a, b) {
25458 var len = a.length
25459 var i = -1
25460 while (++i < len) {
25461 a[i] ^= b[i]
25462 }
25463 return a
25464}
25465
25466},{}],188:[function(require,module,exports){
25467(function (process,global){
25468'use strict'
25469
25470// limit of Crypto.getRandomValues()
25471// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
25472var MAX_BYTES = 65536
25473
25474// Node supports requesting up to this number of bytes
25475// https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
25476var MAX_UINT32 = 4294967295
25477
25478function oldBrowser () {
25479 throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
25480}
25481
25482var Buffer = require('safe-buffer').Buffer
25483var crypto = global.crypto || global.msCrypto
25484
25485if (crypto && crypto.getRandomValues) {
25486 module.exports = randomBytes
25487} else {
25488 module.exports = oldBrowser
25489}
25490
25491function randomBytes (size, cb) {
25492 // phantomjs needs to throw
25493 if (size > MAX_UINT32) throw new RangeError('requested too many random bytes')
25494
25495 var bytes = Buffer.allocUnsafe(size)
25496
25497 if (size > 0) { // getRandomValues fails on IE if size == 0
25498 if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues
25499 // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
25500 for (var generated = 0; generated < size; generated += MAX_BYTES) {
25501 // buffer.slice automatically checks if the end is past the end of
25502 // the buffer so we don't have to here
25503 crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES))
25504 }
25505 } else {
25506 crypto.getRandomValues(bytes)
25507 }
25508 }
25509
25510 if (typeof cb === 'function') {
25511 return process.nextTick(function () {
25512 cb(null, bytes)
25513 })
25514 }
25515
25516 return bytes
25517}
25518
25519}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
25520},{"_process":181,"safe-buffer":206}],189:[function(require,module,exports){
25521(function (process,global){
25522'use strict'
25523
25524function oldBrowser () {
25525 throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
25526}
25527var safeBuffer = require('safe-buffer')
25528var randombytes = require('randombytes')
25529var Buffer = safeBuffer.Buffer
25530var kBufferMaxLength = safeBuffer.kMaxLength
25531var crypto = global.crypto || global.msCrypto
25532var kMaxUint32 = Math.pow(2, 32) - 1
25533function assertOffset (offset, length) {
25534 if (typeof offset !== 'number' || offset !== offset) { // eslint-disable-line no-self-compare
25535 throw new TypeError('offset must be a number')
25536 }
25537
25538 if (offset > kMaxUint32 || offset < 0) {
25539 throw new TypeError('offset must be a uint32')
25540 }
25541
25542 if (offset > kBufferMaxLength || offset > length) {
25543 throw new RangeError('offset out of range')
25544 }
25545}
25546
25547function assertSize (size, offset, length) {
25548 if (typeof size !== 'number' || size !== size) { // eslint-disable-line no-self-compare
25549 throw new TypeError('size must be a number')
25550 }
25551
25552 if (size > kMaxUint32 || size < 0) {
25553 throw new TypeError('size must be a uint32')
25554 }
25555
25556 if (size + offset > length || size > kBufferMaxLength) {
25557 throw new RangeError('buffer too small')
25558 }
25559}
25560if ((crypto && crypto.getRandomValues) || !process.browser) {
25561 exports.randomFill = randomFill
25562 exports.randomFillSync = randomFillSync
25563} else {
25564 exports.randomFill = oldBrowser
25565 exports.randomFillSync = oldBrowser
25566}
25567function randomFill (buf, offset, size, cb) {
25568 if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
25569 throw new TypeError('"buf" argument must be a Buffer or Uint8Array')
25570 }
25571
25572 if (typeof offset === 'function') {
25573 cb = offset
25574 offset = 0
25575 size = buf.length
25576 } else if (typeof size === 'function') {
25577 cb = size
25578 size = buf.length - offset
25579 } else if (typeof cb !== 'function') {
25580 throw new TypeError('"cb" argument must be a function')
25581 }
25582 assertOffset(offset, buf.length)
25583 assertSize(size, offset, buf.length)
25584 return actualFill(buf, offset, size, cb)
25585}
25586
25587function actualFill (buf, offset, size, cb) {
25588 if (process.browser) {
25589 var ourBuf = buf.buffer
25590 var uint = new Uint8Array(ourBuf, offset, size)
25591 crypto.getRandomValues(uint)
25592 if (cb) {
25593 process.nextTick(function () {
25594 cb(null, buf)
25595 })
25596 return
25597 }
25598 return buf
25599 }
25600 if (cb) {
25601 randombytes(size, function (err, bytes) {
25602 if (err) {
25603 return cb(err)
25604 }
25605 bytes.copy(buf, offset)
25606 cb(null, buf)
25607 })
25608 return
25609 }
25610 var bytes = randombytes(size)
25611 bytes.copy(buf, offset)
25612 return buf
25613}
25614function randomFillSync (buf, offset, size) {
25615 if (typeof offset === 'undefined') {
25616 offset = 0
25617 }
25618 if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
25619 throw new TypeError('"buf" argument must be a Buffer or Uint8Array')
25620 }
25621
25622 assertOffset(offset, buf.length)
25623
25624 if (size === undefined) size = buf.length - offset
25625
25626 assertSize(size, offset, buf.length)
25627
25628 return actualFill(buf, offset, size)
25629}
25630
25631}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
25632},{"_process":181,"randombytes":188,"safe-buffer":206}],190:[function(require,module,exports){
25633module.exports = require('./lib/_stream_duplex.js');
25634
25635},{"./lib/_stream_duplex.js":191}],191:[function(require,module,exports){
25636// Copyright Joyent, Inc. and other Node contributors.
25637//
25638// Permission is hereby granted, free of charge, to any person obtaining a
25639// copy of this software and associated documentation files (the
25640// "Software"), to deal in the Software without restriction, including
25641// without limitation the rights to use, copy, modify, merge, publish,
25642// distribute, sublicense, and/or sell copies of the Software, and to permit
25643// persons to whom the Software is furnished to do so, subject to the
25644// following conditions:
25645//
25646// The above copyright notice and this permission notice shall be included
25647// in all copies or substantial portions of the Software.
25648//
25649// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25650// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25651// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25652// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25653// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25654// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25655// USE OR OTHER DEALINGS IN THE SOFTWARE.
25656
25657// a duplex stream is just a stream that is both readable and writable.
25658// Since JS doesn't have multiple prototypal inheritance, this class
25659// prototypally inherits from Readable, and then parasitically from
25660// Writable.
25661
25662'use strict';
25663
25664/*<replacement>*/
25665
25666var pna = require('process-nextick-args');
25667/*</replacement>*/
25668
25669/*<replacement>*/
25670var objectKeys = Object.keys || function (obj) {
25671 var keys = [];
25672 for (var key in obj) {
25673 keys.push(key);
25674 }return keys;
25675};
25676/*</replacement>*/
25677
25678module.exports = Duplex;
25679
25680/*<replacement>*/
25681var util = require('core-util-is');
25682util.inherits = require('inherits');
25683/*</replacement>*/
25684
25685var Readable = require('./_stream_readable');
25686var Writable = require('./_stream_writable');
25687
25688util.inherits(Duplex, Readable);
25689
25690{
25691 // avoid scope creep, the keys array can then be collected
25692 var keys = objectKeys(Writable.prototype);
25693 for (var v = 0; v < keys.length; v++) {
25694 var method = keys[v];
25695 if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
25696 }
25697}
25698
25699function Duplex(options) {
25700 if (!(this instanceof Duplex)) return new Duplex(options);
25701
25702 Readable.call(this, options);
25703 Writable.call(this, options);
25704
25705 if (options && options.readable === false) this.readable = false;
25706
25707 if (options && options.writable === false) this.writable = false;
25708
25709 this.allowHalfOpen = true;
25710 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
25711
25712 this.once('end', onend);
25713}
25714
25715Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
25716 // making it explicit this property is not enumerable
25717 // because otherwise some prototype manipulation in
25718 // userland will fail
25719 enumerable: false,
25720 get: function () {
25721 return this._writableState.highWaterMark;
25722 }
25723});
25724
25725// the no-half-open enforcer
25726function onend() {
25727 // if we allow half-open state, or if the writable side ended,
25728 // then we're ok.
25729 if (this.allowHalfOpen || this._writableState.ended) return;
25730
25731 // no more data can be written.
25732 // But allow more writes to happen in this tick.
25733 pna.nextTick(onEndNT, this);
25734}
25735
25736function onEndNT(self) {
25737 self.end();
25738}
25739
25740Object.defineProperty(Duplex.prototype, 'destroyed', {
25741 get: function () {
25742 if (this._readableState === undefined || this._writableState === undefined) {
25743 return false;
25744 }
25745 return this._readableState.destroyed && this._writableState.destroyed;
25746 },
25747 set: function (value) {
25748 // we ignore the value if the stream
25749 // has not been initialized yet
25750 if (this._readableState === undefined || this._writableState === undefined) {
25751 return;
25752 }
25753
25754 // backward compatibility, the user is explicitly
25755 // managing destroyed
25756 this._readableState.destroyed = value;
25757 this._writableState.destroyed = value;
25758 }
25759});
25760
25761Duplex.prototype._destroy = function (err, cb) {
25762 this.push(null);
25763 this.end();
25764
25765 pna.nextTick(cb, err);
25766};
25767},{"./_stream_readable":193,"./_stream_writable":195,"core-util-is":112,"inherits":162,"process-nextick-args":180}],192:[function(require,module,exports){
25768// Copyright Joyent, Inc. and other Node contributors.
25769//
25770// Permission is hereby granted, free of charge, to any person obtaining a
25771// copy of this software and associated documentation files (the
25772// "Software"), to deal in the Software without restriction, including
25773// without limitation the rights to use, copy, modify, merge, publish,
25774// distribute, sublicense, and/or sell copies of the Software, and to permit
25775// persons to whom the Software is furnished to do so, subject to the
25776// following conditions:
25777//
25778// The above copyright notice and this permission notice shall be included
25779// in all copies or substantial portions of the Software.
25780//
25781// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25782// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25783// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25784// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25785// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25786// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25787// USE OR OTHER DEALINGS IN THE SOFTWARE.
25788
25789// a passthrough stream.
25790// basically just the most minimal sort of Transform stream.
25791// Every written chunk gets output as-is.
25792
25793'use strict';
25794
25795module.exports = PassThrough;
25796
25797var Transform = require('./_stream_transform');
25798
25799/*<replacement>*/
25800var util = require('core-util-is');
25801util.inherits = require('inherits');
25802/*</replacement>*/
25803
25804util.inherits(PassThrough, Transform);
25805
25806function PassThrough(options) {
25807 if (!(this instanceof PassThrough)) return new PassThrough(options);
25808
25809 Transform.call(this, options);
25810}
25811
25812PassThrough.prototype._transform = function (chunk, encoding, cb) {
25813 cb(null, chunk);
25814};
25815},{"./_stream_transform":194,"core-util-is":112,"inherits":162}],193:[function(require,module,exports){
25816(function (process,global){
25817// Copyright Joyent, Inc. and other Node contributors.
25818//
25819// Permission is hereby granted, free of charge, to any person obtaining a
25820// copy of this software and associated documentation files (the
25821// "Software"), to deal in the Software without restriction, including
25822// without limitation the rights to use, copy, modify, merge, publish,
25823// distribute, sublicense, and/or sell copies of the Software, and to permit
25824// persons to whom the Software is furnished to do so, subject to the
25825// following conditions:
25826//
25827// The above copyright notice and this permission notice shall be included
25828// in all copies or substantial portions of the Software.
25829//
25830// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25831// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25832// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25833// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25834// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25835// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25836// USE OR OTHER DEALINGS IN THE SOFTWARE.
25837
25838'use strict';
25839
25840/*<replacement>*/
25841
25842var pna = require('process-nextick-args');
25843/*</replacement>*/
25844
25845module.exports = Readable;
25846
25847/*<replacement>*/
25848var isArray = require('isarray');
25849/*</replacement>*/
25850
25851/*<replacement>*/
25852var Duplex;
25853/*</replacement>*/
25854
25855Readable.ReadableState = ReadableState;
25856
25857/*<replacement>*/
25858var EE = require('events').EventEmitter;
25859
25860var EElistenerCount = function (emitter, type) {
25861 return emitter.listeners(type).length;
25862};
25863/*</replacement>*/
25864
25865/*<replacement>*/
25866var Stream = require('./internal/streams/stream');
25867/*</replacement>*/
25868
25869/*<replacement>*/
25870
25871var Buffer = require('safe-buffer').Buffer;
25872var OurUint8Array = global.Uint8Array || function () {};
25873function _uint8ArrayToBuffer(chunk) {
25874 return Buffer.from(chunk);
25875}
25876function _isUint8Array(obj) {
25877 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
25878}
25879
25880/*</replacement>*/
25881
25882/*<replacement>*/
25883var util = require('core-util-is');
25884util.inherits = require('inherits');
25885/*</replacement>*/
25886
25887/*<replacement>*/
25888var debugUtil = require('util');
25889var debug = void 0;
25890if (debugUtil && debugUtil.debuglog) {
25891 debug = debugUtil.debuglog('stream');
25892} else {
25893 debug = function () {};
25894}
25895/*</replacement>*/
25896
25897var BufferList = require('./internal/streams/BufferList');
25898var destroyImpl = require('./internal/streams/destroy');
25899var StringDecoder;
25900
25901util.inherits(Readable, Stream);
25902
25903var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
25904
25905function prependListener(emitter, event, fn) {
25906 // Sadly this is not cacheable as some libraries bundle their own
25907 // event emitter implementation with them.
25908 if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
25909
25910 // This is a hack to make sure that our error handler is attached before any
25911 // userland ones. NEVER DO THIS. This is here only because this code needs
25912 // to continue to work with older versions of Node.js that do not include
25913 // the prependListener() method. The goal is to eventually remove this hack.
25914 if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
25915}
25916
25917function ReadableState(options, stream) {
25918 Duplex = Duplex || require('./_stream_duplex');
25919
25920 options = options || {};
25921
25922 // Duplex streams are both readable and writable, but share
25923 // the same options object.
25924 // However, some cases require setting options to different
25925 // values for the readable and the writable sides of the duplex stream.
25926 // These options can be provided separately as readableXXX and writableXXX.
25927 var isDuplex = stream instanceof Duplex;
25928
25929 // object stream flag. Used to make read(n) ignore n and to
25930 // make all the buffer merging and length checks go away
25931 this.objectMode = !!options.objectMode;
25932
25933 if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
25934
25935 // the point at which it stops calling _read() to fill the buffer
25936 // Note: 0 is a valid value, means "don't call _read preemptively ever"
25937 var hwm = options.highWaterMark;
25938 var readableHwm = options.readableHighWaterMark;
25939 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
25940
25941 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
25942
25943 // cast to ints.
25944 this.highWaterMark = Math.floor(this.highWaterMark);
25945
25946 // A linked list is used to store data chunks instead of an array because the
25947 // linked list can remove elements from the beginning faster than
25948 // array.shift()
25949 this.buffer = new BufferList();
25950 this.length = 0;
25951 this.pipes = null;
25952 this.pipesCount = 0;
25953 this.flowing = null;
25954 this.ended = false;
25955 this.endEmitted = false;
25956 this.reading = false;
25957
25958 // a flag to be able to tell if the event 'readable'/'data' is emitted
25959 // immediately, or on a later tick. We set this to true at first, because
25960 // any actions that shouldn't happen until "later" should generally also
25961 // not happen before the first read call.
25962 this.sync = true;
25963
25964 // whenever we return null, then we set a flag to say
25965 // that we're awaiting a 'readable' event emission.
25966 this.needReadable = false;
25967 this.emittedReadable = false;
25968 this.readableListening = false;
25969 this.resumeScheduled = false;
25970
25971 // has it been destroyed
25972 this.destroyed = false;
25973
25974 // Crypto is kind of old and crusty. Historically, its default string
25975 // encoding is 'binary' so we have to make this configurable.
25976 // Everything else in the universe uses 'utf8', though.
25977 this.defaultEncoding = options.defaultEncoding || 'utf8';
25978
25979 // the number of writers that are awaiting a drain event in .pipe()s
25980 this.awaitDrain = 0;
25981
25982 // if true, a maybeReadMore has been scheduled
25983 this.readingMore = false;
25984
25985 this.decoder = null;
25986 this.encoding = null;
25987 if (options.encoding) {
25988 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
25989 this.decoder = new StringDecoder(options.encoding);
25990 this.encoding = options.encoding;
25991 }
25992}
25993
25994function Readable(options) {
25995 Duplex = Duplex || require('./_stream_duplex');
25996
25997 if (!(this instanceof Readable)) return new Readable(options);
25998
25999 this._readableState = new ReadableState(options, this);
26000
26001 // legacy
26002 this.readable = true;
26003
26004 if (options) {
26005 if (typeof options.read === 'function') this._read = options.read;
26006
26007 if (typeof options.destroy === 'function') this._destroy = options.destroy;
26008 }
26009
26010 Stream.call(this);
26011}
26012
26013Object.defineProperty(Readable.prototype, 'destroyed', {
26014 get: function () {
26015 if (this._readableState === undefined) {
26016 return false;
26017 }
26018 return this._readableState.destroyed;
26019 },
26020 set: function (value) {
26021 // we ignore the value if the stream
26022 // has not been initialized yet
26023 if (!this._readableState) {
26024 return;
26025 }
26026
26027 // backward compatibility, the user is explicitly
26028 // managing destroyed
26029 this._readableState.destroyed = value;
26030 }
26031});
26032
26033Readable.prototype.destroy = destroyImpl.destroy;
26034Readable.prototype._undestroy = destroyImpl.undestroy;
26035Readable.prototype._destroy = function (err, cb) {
26036 this.push(null);
26037 cb(err);
26038};
26039
26040// Manually shove something into the read() buffer.
26041// This returns true if the highWaterMark has not been hit yet,
26042// similar to how Writable.write() returns true if you should
26043// write() some more.
26044Readable.prototype.push = function (chunk, encoding) {
26045 var state = this._readableState;
26046 var skipChunkCheck;
26047
26048 if (!state.objectMode) {
26049 if (typeof chunk === 'string') {
26050 encoding = encoding || state.defaultEncoding;
26051 if (encoding !== state.encoding) {
26052 chunk = Buffer.from(chunk, encoding);
26053 encoding = '';
26054 }
26055 skipChunkCheck = true;
26056 }
26057 } else {
26058 skipChunkCheck = true;
26059 }
26060
26061 return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
26062};
26063
26064// Unshift should *always* be something directly out of read()
26065Readable.prototype.unshift = function (chunk) {
26066 return readableAddChunk(this, chunk, null, true, false);
26067};
26068
26069function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
26070 var state = stream._readableState;
26071 if (chunk === null) {
26072 state.reading = false;
26073 onEofChunk(stream, state);
26074 } else {
26075 var er;
26076 if (!skipChunkCheck) er = chunkInvalid(state, chunk);
26077 if (er) {
26078 stream.emit('error', er);
26079 } else if (state.objectMode || chunk && chunk.length > 0) {
26080 if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
26081 chunk = _uint8ArrayToBuffer(chunk);
26082 }
26083
26084 if (addToFront) {
26085 if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
26086 } else if (state.ended) {
26087 stream.emit('error', new Error('stream.push() after EOF'));
26088 } else {
26089 state.reading = false;
26090 if (state.decoder && !encoding) {
26091 chunk = state.decoder.write(chunk);
26092 if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
26093 } else {
26094 addChunk(stream, state, chunk, false);
26095 }
26096 }
26097 } else if (!addToFront) {
26098 state.reading = false;
26099 }
26100 }
26101
26102 return needMoreData(state);
26103}
26104
26105function addChunk(stream, state, chunk, addToFront) {
26106 if (state.flowing && state.length === 0 && !state.sync) {
26107 stream.emit('data', chunk);
26108 stream.read(0);
26109 } else {
26110 // update the buffer info.
26111 state.length += state.objectMode ? 1 : chunk.length;
26112 if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
26113
26114 if (state.needReadable) emitReadable(stream);
26115 }
26116 maybeReadMore(stream, state);
26117}
26118
26119function chunkInvalid(state, chunk) {
26120 var er;
26121 if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
26122 er = new TypeError('Invalid non-string/buffer chunk');
26123 }
26124 return er;
26125}
26126
26127// if it's past the high water mark, we can push in some more.
26128// Also, if we have no data yet, we can stand some
26129// more bytes. This is to work around cases where hwm=0,
26130// such as the repl. Also, if the push() triggered a
26131// readable event, and the user called read(largeNumber) such that
26132// needReadable was set, then we ought to push more, so that another
26133// 'readable' event will be triggered.
26134function needMoreData(state) {
26135 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
26136}
26137
26138Readable.prototype.isPaused = function () {
26139 return this._readableState.flowing === false;
26140};
26141
26142// backwards compatibility.
26143Readable.prototype.setEncoding = function (enc) {
26144 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
26145 this._readableState.decoder = new StringDecoder(enc);
26146 this._readableState.encoding = enc;
26147 return this;
26148};
26149
26150// Don't raise the hwm > 8MB
26151var MAX_HWM = 0x800000;
26152function computeNewHighWaterMark(n) {
26153 if (n >= MAX_HWM) {
26154 n = MAX_HWM;
26155 } else {
26156 // Get the next highest power of 2 to prevent increasing hwm excessively in
26157 // tiny amounts
26158 n--;
26159 n |= n >>> 1;
26160 n |= n >>> 2;
26161 n |= n >>> 4;
26162 n |= n >>> 8;
26163 n |= n >>> 16;
26164 n++;
26165 }
26166 return n;
26167}
26168
26169// This function is designed to be inlinable, so please take care when making
26170// changes to the function body.
26171function howMuchToRead(n, state) {
26172 if (n <= 0 || state.length === 0 && state.ended) return 0;
26173 if (state.objectMode) return 1;
26174 if (n !== n) {
26175 // Only flow one buffer at a time
26176 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
26177 }
26178 // If we're asking for more than the current hwm, then raise the hwm.
26179 if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
26180 if (n <= state.length) return n;
26181 // Don't have enough
26182 if (!state.ended) {
26183 state.needReadable = true;
26184 return 0;
26185 }
26186 return state.length;
26187}
26188
26189// you can override either this method, or the async _read(n) below.
26190Readable.prototype.read = function (n) {
26191 debug('read', n);
26192 n = parseInt(n, 10);
26193 var state = this._readableState;
26194 var nOrig = n;
26195
26196 if (n !== 0) state.emittedReadable = false;
26197
26198 // if we're doing read(0) to trigger a readable event, but we
26199 // already have a bunch of data in the buffer, then just trigger
26200 // the 'readable' event and move on.
26201 if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
26202 debug('read: emitReadable', state.length, state.ended);
26203 if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
26204 return null;
26205 }
26206
26207 n = howMuchToRead(n, state);
26208
26209 // if we've ended, and we're now clear, then finish it up.
26210 if (n === 0 && state.ended) {
26211 if (state.length === 0) endReadable(this);
26212 return null;
26213 }
26214
26215 // All the actual chunk generation logic needs to be
26216 // *below* the call to _read. The reason is that in certain
26217 // synthetic stream cases, such as passthrough streams, _read
26218 // may be a completely synchronous operation which may change
26219 // the state of the read buffer, providing enough data when
26220 // before there was *not* enough.
26221 //
26222 // So, the steps are:
26223 // 1. Figure out what the state of things will be after we do
26224 // a read from the buffer.
26225 //
26226 // 2. If that resulting state will trigger a _read, then call _read.
26227 // Note that this may be asynchronous, or synchronous. Yes, it is
26228 // deeply ugly to write APIs this way, but that still doesn't mean
26229 // that the Readable class should behave improperly, as streams are
26230 // designed to be sync/async agnostic.
26231 // Take note if the _read call is sync or async (ie, if the read call
26232 // has returned yet), so that we know whether or not it's safe to emit
26233 // 'readable' etc.
26234 //
26235 // 3. Actually pull the requested chunks out of the buffer and return.
26236
26237 // if we need a readable event, then we need to do some reading.
26238 var doRead = state.needReadable;
26239 debug('need readable', doRead);
26240
26241 // if we currently have less than the highWaterMark, then also read some
26242 if (state.length === 0 || state.length - n < state.highWaterMark) {
26243 doRead = true;
26244 debug('length less than watermark', doRead);
26245 }
26246
26247 // however, if we've ended, then there's no point, and if we're already
26248 // reading, then it's unnecessary.
26249 if (state.ended || state.reading) {
26250 doRead = false;
26251 debug('reading or ended', doRead);
26252 } else if (doRead) {
26253 debug('do read');
26254 state.reading = true;
26255 state.sync = true;
26256 // if the length is currently zero, then we *need* a readable event.
26257 if (state.length === 0) state.needReadable = true;
26258 // call internal read method
26259 this._read(state.highWaterMark);
26260 state.sync = false;
26261 // If _read pushed data synchronously, then `reading` will be false,
26262 // and we need to re-evaluate how much data we can return to the user.
26263 if (!state.reading) n = howMuchToRead(nOrig, state);
26264 }
26265
26266 var ret;
26267 if (n > 0) ret = fromList(n, state);else ret = null;
26268
26269 if (ret === null) {
26270 state.needReadable = true;
26271 n = 0;
26272 } else {
26273 state.length -= n;
26274 }
26275
26276 if (state.length === 0) {
26277 // If we have nothing in the buffer, then we want to know
26278 // as soon as we *do* get something into the buffer.
26279 if (!state.ended) state.needReadable = true;
26280
26281 // If we tried to read() past the EOF, then emit end on the next tick.
26282 if (nOrig !== n && state.ended) endReadable(this);
26283 }
26284
26285 if (ret !== null) this.emit('data', ret);
26286
26287 return ret;
26288};
26289
26290function onEofChunk(stream, state) {
26291 if (state.ended) return;
26292 if (state.decoder) {
26293 var chunk = state.decoder.end();
26294 if (chunk && chunk.length) {
26295 state.buffer.push(chunk);
26296 state.length += state.objectMode ? 1 : chunk.length;
26297 }
26298 }
26299 state.ended = true;
26300
26301 // emit 'readable' now to make sure it gets picked up.
26302 emitReadable(stream);
26303}
26304
26305// Don't emit readable right away in sync mode, because this can trigger
26306// another read() call => stack overflow. This way, it might trigger
26307// a nextTick recursion warning, but that's not so bad.
26308function emitReadable(stream) {
26309 var state = stream._readableState;
26310 state.needReadable = false;
26311 if (!state.emittedReadable) {
26312 debug('emitReadable', state.flowing);
26313 state.emittedReadable = true;
26314 if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
26315 }
26316}
26317
26318function emitReadable_(stream) {
26319 debug('emit readable');
26320 stream.emit('readable');
26321 flow(stream);
26322}
26323
26324// at this point, the user has presumably seen the 'readable' event,
26325// and called read() to consume some data. that may have triggered
26326// in turn another _read(n) call, in which case reading = true if
26327// it's in progress.
26328// However, if we're not ended, or reading, and the length < hwm,
26329// then go ahead and try to read some more preemptively.
26330function maybeReadMore(stream, state) {
26331 if (!state.readingMore) {
26332 state.readingMore = true;
26333 pna.nextTick(maybeReadMore_, stream, state);
26334 }
26335}
26336
26337function maybeReadMore_(stream, state) {
26338 var len = state.length;
26339 while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
26340 debug('maybeReadMore read 0');
26341 stream.read(0);
26342 if (len === state.length)
26343 // didn't get any data, stop spinning.
26344 break;else len = state.length;
26345 }
26346 state.readingMore = false;
26347}
26348
26349// abstract method. to be overridden in specific implementation classes.
26350// call cb(er, data) where data is <= n in length.
26351// for virtual (non-string, non-buffer) streams, "length" is somewhat
26352// arbitrary, and perhaps not very meaningful.
26353Readable.prototype._read = function (n) {
26354 this.emit('error', new Error('_read() is not implemented'));
26355};
26356
26357Readable.prototype.pipe = function (dest, pipeOpts) {
26358 var src = this;
26359 var state = this._readableState;
26360
26361 switch (state.pipesCount) {
26362 case 0:
26363 state.pipes = dest;
26364 break;
26365 case 1:
26366 state.pipes = [state.pipes, dest];
26367 break;
26368 default:
26369 state.pipes.push(dest);
26370 break;
26371 }
26372 state.pipesCount += 1;
26373 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
26374
26375 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
26376
26377 var endFn = doEnd ? onend : unpipe;
26378 if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
26379
26380 dest.on('unpipe', onunpipe);
26381 function onunpipe(readable, unpipeInfo) {
26382 debug('onunpipe');
26383 if (readable === src) {
26384 if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
26385 unpipeInfo.hasUnpiped = true;
26386 cleanup();
26387 }
26388 }
26389 }
26390
26391 function onend() {
26392 debug('onend');
26393 dest.end();
26394 }
26395
26396 // when the dest drains, it reduces the awaitDrain counter
26397 // on the source. This would be more elegant with a .once()
26398 // handler in flow(), but adding and removing repeatedly is
26399 // too slow.
26400 var ondrain = pipeOnDrain(src);
26401 dest.on('drain', ondrain);
26402
26403 var cleanedUp = false;
26404 function cleanup() {
26405 debug('cleanup');
26406 // cleanup event handlers once the pipe is broken
26407 dest.removeListener('close', onclose);
26408 dest.removeListener('finish', onfinish);
26409 dest.removeListener('drain', ondrain);
26410 dest.removeListener('error', onerror);
26411 dest.removeListener('unpipe', onunpipe);
26412 src.removeListener('end', onend);
26413 src.removeListener('end', unpipe);
26414 src.removeListener('data', ondata);
26415
26416 cleanedUp = true;
26417
26418 // if the reader is waiting for a drain event from this
26419 // specific writer, then it would cause it to never start
26420 // flowing again.
26421 // So, if this is awaiting a drain, then we just call it now.
26422 // If we don't know, then assume that we are waiting for one.
26423 if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
26424 }
26425
26426 // If the user pushes more data while we're writing to dest then we'll end up
26427 // in ondata again. However, we only want to increase awaitDrain once because
26428 // dest will only emit one 'drain' event for the multiple writes.
26429 // => Introduce a guard on increasing awaitDrain.
26430 var increasedAwaitDrain = false;
26431 src.on('data', ondata);
26432 function ondata(chunk) {
26433 debug('ondata');
26434 increasedAwaitDrain = false;
26435 var ret = dest.write(chunk);
26436 if (false === ret && !increasedAwaitDrain) {
26437 // If the user unpiped during `dest.write()`, it is possible
26438 // to get stuck in a permanently paused state if that write
26439 // also returned false.
26440 // => Check whether `dest` is still a piping destination.
26441 if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
26442 debug('false write response, pause', src._readableState.awaitDrain);
26443 src._readableState.awaitDrain++;
26444 increasedAwaitDrain = true;
26445 }
26446 src.pause();
26447 }
26448 }
26449
26450 // if the dest has an error, then stop piping into it.
26451 // however, don't suppress the throwing behavior for this.
26452 function onerror(er) {
26453 debug('onerror', er);
26454 unpipe();
26455 dest.removeListener('error', onerror);
26456 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
26457 }
26458
26459 // Make sure our error handler is attached before userland ones.
26460 prependListener(dest, 'error', onerror);
26461
26462 // Both close and finish should trigger unpipe, but only once.
26463 function onclose() {
26464 dest.removeListener('finish', onfinish);
26465 unpipe();
26466 }
26467 dest.once('close', onclose);
26468 function onfinish() {
26469 debug('onfinish');
26470 dest.removeListener('close', onclose);
26471 unpipe();
26472 }
26473 dest.once('finish', onfinish);
26474
26475 function unpipe() {
26476 debug('unpipe');
26477 src.unpipe(dest);
26478 }
26479
26480 // tell the dest that it's being piped to
26481 dest.emit('pipe', src);
26482
26483 // start the flow if it hasn't been started already.
26484 if (!state.flowing) {
26485 debug('pipe resume');
26486 src.resume();
26487 }
26488
26489 return dest;
26490};
26491
26492function pipeOnDrain(src) {
26493 return function () {
26494 var state = src._readableState;
26495 debug('pipeOnDrain', state.awaitDrain);
26496 if (state.awaitDrain) state.awaitDrain--;
26497 if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
26498 state.flowing = true;
26499 flow(src);
26500 }
26501 };
26502}
26503
26504Readable.prototype.unpipe = function (dest) {
26505 var state = this._readableState;
26506 var unpipeInfo = { hasUnpiped: false };
26507
26508 // if we're not piping anywhere, then do nothing.
26509 if (state.pipesCount === 0) return this;
26510
26511 // just one destination. most common case.
26512 if (state.pipesCount === 1) {
26513 // passed in one, but it's not the right one.
26514 if (dest && dest !== state.pipes) return this;
26515
26516 if (!dest) dest = state.pipes;
26517
26518 // got a match.
26519 state.pipes = null;
26520 state.pipesCount = 0;
26521 state.flowing = false;
26522 if (dest) dest.emit('unpipe', this, unpipeInfo);
26523 return this;
26524 }
26525
26526 // slow case. multiple pipe destinations.
26527
26528 if (!dest) {
26529 // remove all.
26530 var dests = state.pipes;
26531 var len = state.pipesCount;
26532 state.pipes = null;
26533 state.pipesCount = 0;
26534 state.flowing = false;
26535
26536 for (var i = 0; i < len; i++) {
26537 dests[i].emit('unpipe', this, unpipeInfo);
26538 }return this;
26539 }
26540
26541 // try to find the right one.
26542 var index = indexOf(state.pipes, dest);
26543 if (index === -1) return this;
26544
26545 state.pipes.splice(index, 1);
26546 state.pipesCount -= 1;
26547 if (state.pipesCount === 1) state.pipes = state.pipes[0];
26548
26549 dest.emit('unpipe', this, unpipeInfo);
26550
26551 return this;
26552};
26553
26554// set up data events if they are asked for
26555// Ensure readable listeners eventually get something
26556Readable.prototype.on = function (ev, fn) {
26557 var res = Stream.prototype.on.call(this, ev, fn);
26558
26559 if (ev === 'data') {
26560 // Start flowing on next tick if stream isn't explicitly paused
26561 if (this._readableState.flowing !== false) this.resume();
26562 } else if (ev === 'readable') {
26563 var state = this._readableState;
26564 if (!state.endEmitted && !state.readableListening) {
26565 state.readableListening = state.needReadable = true;
26566 state.emittedReadable = false;
26567 if (!state.reading) {
26568 pna.nextTick(nReadingNextTick, this);
26569 } else if (state.length) {
26570 emitReadable(this);
26571 }
26572 }
26573 }
26574
26575 return res;
26576};
26577Readable.prototype.addListener = Readable.prototype.on;
26578
26579function nReadingNextTick(self) {
26580 debug('readable nexttick read 0');
26581 self.read(0);
26582}
26583
26584// pause() and resume() are remnants of the legacy readable stream API
26585// If the user uses them, then switch into old mode.
26586Readable.prototype.resume = function () {
26587 var state = this._readableState;
26588 if (!state.flowing) {
26589 debug('resume');
26590 state.flowing = true;
26591 resume(this, state);
26592 }
26593 return this;
26594};
26595
26596function resume(stream, state) {
26597 if (!state.resumeScheduled) {
26598 state.resumeScheduled = true;
26599 pna.nextTick(resume_, stream, state);
26600 }
26601}
26602
26603function resume_(stream, state) {
26604 if (!state.reading) {
26605 debug('resume read 0');
26606 stream.read(0);
26607 }
26608
26609 state.resumeScheduled = false;
26610 state.awaitDrain = 0;
26611 stream.emit('resume');
26612 flow(stream);
26613 if (state.flowing && !state.reading) stream.read(0);
26614}
26615
26616Readable.prototype.pause = function () {
26617 debug('call pause flowing=%j', this._readableState.flowing);
26618 if (false !== this._readableState.flowing) {
26619 debug('pause');
26620 this._readableState.flowing = false;
26621 this.emit('pause');
26622 }
26623 return this;
26624};
26625
26626function flow(stream) {
26627 var state = stream._readableState;
26628 debug('flow', state.flowing);
26629 while (state.flowing && stream.read() !== null) {}
26630}
26631
26632// wrap an old-style stream as the async data source.
26633// This is *not* part of the readable stream interface.
26634// It is an ugly unfortunate mess of history.
26635Readable.prototype.wrap = function (stream) {
26636 var _this = this;
26637
26638 var state = this._readableState;
26639 var paused = false;
26640
26641 stream.on('end', function () {
26642 debug('wrapped end');
26643 if (state.decoder && !state.ended) {
26644 var chunk = state.decoder.end();
26645 if (chunk && chunk.length) _this.push(chunk);
26646 }
26647
26648 _this.push(null);
26649 });
26650
26651 stream.on('data', function (chunk) {
26652 debug('wrapped data');
26653 if (state.decoder) chunk = state.decoder.write(chunk);
26654
26655 // don't skip over falsy values in objectMode
26656 if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
26657
26658 var ret = _this.push(chunk);
26659 if (!ret) {
26660 paused = true;
26661 stream.pause();
26662 }
26663 });
26664
26665 // proxy all the other methods.
26666 // important when wrapping filters and duplexes.
26667 for (var i in stream) {
26668 if (this[i] === undefined && typeof stream[i] === 'function') {
26669 this[i] = function (method) {
26670 return function () {
26671 return stream[method].apply(stream, arguments);
26672 };
26673 }(i);
26674 }
26675 }
26676
26677 // proxy certain important events.
26678 for (var n = 0; n < kProxyEvents.length; n++) {
26679 stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
26680 }
26681
26682 // when we try to consume some more bytes, simply unpause the
26683 // underlying stream.
26684 this._read = function (n) {
26685 debug('wrapped _read', n);
26686 if (paused) {
26687 paused = false;
26688 stream.resume();
26689 }
26690 };
26691
26692 return this;
26693};
26694
26695Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
26696 // making it explicit this property is not enumerable
26697 // because otherwise some prototype manipulation in
26698 // userland will fail
26699 enumerable: false,
26700 get: function () {
26701 return this._readableState.highWaterMark;
26702 }
26703});
26704
26705// exposed for testing purposes only.
26706Readable._fromList = fromList;
26707
26708// Pluck off n bytes from an array of buffers.
26709// Length is the combined lengths of all the buffers in the list.
26710// This function is designed to be inlinable, so please take care when making
26711// changes to the function body.
26712function fromList(n, state) {
26713 // nothing buffered
26714 if (state.length === 0) return null;
26715
26716 var ret;
26717 if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
26718 // read it all, truncate the list
26719 if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
26720 state.buffer.clear();
26721 } else {
26722 // read part of list
26723 ret = fromListPartial(n, state.buffer, state.decoder);
26724 }
26725
26726 return ret;
26727}
26728
26729// Extracts only enough buffered data to satisfy the amount requested.
26730// This function is designed to be inlinable, so please take care when making
26731// changes to the function body.
26732function fromListPartial(n, list, hasStrings) {
26733 var ret;
26734 if (n < list.head.data.length) {
26735 // slice is the same for buffers and strings
26736 ret = list.head.data.slice(0, n);
26737 list.head.data = list.head.data.slice(n);
26738 } else if (n === list.head.data.length) {
26739 // first chunk is a perfect match
26740 ret = list.shift();
26741 } else {
26742 // result spans more than one buffer
26743 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
26744 }
26745 return ret;
26746}
26747
26748// Copies a specified amount of characters from the list of buffered data
26749// chunks.
26750// This function is designed to be inlinable, so please take care when making
26751// changes to the function body.
26752function copyFromBufferString(n, list) {
26753 var p = list.head;
26754 var c = 1;
26755 var ret = p.data;
26756 n -= ret.length;
26757 while (p = p.next) {
26758 var str = p.data;
26759 var nb = n > str.length ? str.length : n;
26760 if (nb === str.length) ret += str;else ret += str.slice(0, n);
26761 n -= nb;
26762 if (n === 0) {
26763 if (nb === str.length) {
26764 ++c;
26765 if (p.next) list.head = p.next;else list.head = list.tail = null;
26766 } else {
26767 list.head = p;
26768 p.data = str.slice(nb);
26769 }
26770 break;
26771 }
26772 ++c;
26773 }
26774 list.length -= c;
26775 return ret;
26776}
26777
26778// Copies a specified amount of bytes from the list of buffered data chunks.
26779// This function is designed to be inlinable, so please take care when making
26780// changes to the function body.
26781function copyFromBuffer(n, list) {
26782 var ret = Buffer.allocUnsafe(n);
26783 var p = list.head;
26784 var c = 1;
26785 p.data.copy(ret);
26786 n -= p.data.length;
26787 while (p = p.next) {
26788 var buf = p.data;
26789 var nb = n > buf.length ? buf.length : n;
26790 buf.copy(ret, ret.length - n, 0, nb);
26791 n -= nb;
26792 if (n === 0) {
26793 if (nb === buf.length) {
26794 ++c;
26795 if (p.next) list.head = p.next;else list.head = list.tail = null;
26796 } else {
26797 list.head = p;
26798 p.data = buf.slice(nb);
26799 }
26800 break;
26801 }
26802 ++c;
26803 }
26804 list.length -= c;
26805 return ret;
26806}
26807
26808function endReadable(stream) {
26809 var state = stream._readableState;
26810
26811 // If we get here before consuming all the bytes, then that is a
26812 // bug in node. Should never happen.
26813 if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
26814
26815 if (!state.endEmitted) {
26816 state.ended = true;
26817 pna.nextTick(endReadableNT, state, stream);
26818 }
26819}
26820
26821function endReadableNT(state, stream) {
26822 // Check that we didn't get one last unshift.
26823 if (!state.endEmitted && state.length === 0) {
26824 state.endEmitted = true;
26825 stream.readable = false;
26826 stream.emit('end');
26827 }
26828}
26829
26830function indexOf(xs, x) {
26831 for (var i = 0, l = xs.length; i < l; i++) {
26832 if (xs[i] === x) return i;
26833 }
26834 return -1;
26835}
26836}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
26837},{"./_stream_duplex":191,"./internal/streams/BufferList":196,"./internal/streams/destroy":197,"./internal/streams/stream":198,"_process":181,"core-util-is":112,"events":145,"inherits":162,"isarray":164,"process-nextick-args":180,"safe-buffer":199,"string_decoder/":200,"util":81}],194:[function(require,module,exports){
26838// Copyright Joyent, Inc. and other Node contributors.
26839//
26840// Permission is hereby granted, free of charge, to any person obtaining a
26841// copy of this software and associated documentation files (the
26842// "Software"), to deal in the Software without restriction, including
26843// without limitation the rights to use, copy, modify, merge, publish,
26844// distribute, sublicense, and/or sell copies of the Software, and to permit
26845// persons to whom the Software is furnished to do so, subject to the
26846// following conditions:
26847//
26848// The above copyright notice and this permission notice shall be included
26849// in all copies or substantial portions of the Software.
26850//
26851// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26852// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26853// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
26854// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26855// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26856// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26857// USE OR OTHER DEALINGS IN THE SOFTWARE.
26858
26859// a transform stream is a readable/writable stream where you do
26860// something with the data. Sometimes it's called a "filter",
26861// but that's not a great name for it, since that implies a thing where
26862// some bits pass through, and others are simply ignored. (That would
26863// be a valid example of a transform, of course.)
26864//
26865// While the output is causally related to the input, it's not a
26866// necessarily symmetric or synchronous transformation. For example,
26867// a zlib stream might take multiple plain-text writes(), and then
26868// emit a single compressed chunk some time in the future.
26869//
26870// Here's how this works:
26871//
26872// The Transform stream has all the aspects of the readable and writable
26873// stream classes. When you write(chunk), that calls _write(chunk,cb)
26874// internally, and returns false if there's a lot of pending writes
26875// buffered up. When you call read(), that calls _read(n) until
26876// there's enough pending readable data buffered up.
26877//
26878// In a transform stream, the written data is placed in a buffer. When
26879// _read(n) is called, it transforms the queued up data, calling the
26880// buffered _write cb's as it consumes chunks. If consuming a single
26881// written chunk would result in multiple output chunks, then the first
26882// outputted bit calls the readcb, and subsequent chunks just go into
26883// the read buffer, and will cause it to emit 'readable' if necessary.
26884//
26885// This way, back-pressure is actually determined by the reading side,
26886// since _read has to be called to start processing a new chunk. However,
26887// a pathological inflate type of transform can cause excessive buffering
26888// here. For example, imagine a stream where every byte of input is
26889// interpreted as an integer from 0-255, and then results in that many
26890// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
26891// 1kb of data being output. In this case, you could write a very small
26892// amount of input, and end up with a very large amount of output. In
26893// such a pathological inflating mechanism, there'd be no way to tell
26894// the system to stop doing the transform. A single 4MB write could
26895// cause the system to run out of memory.
26896//
26897// However, even in such a pathological case, only a single written chunk
26898// would be consumed, and then the rest would wait (un-transformed) until
26899// the results of the previous transformed chunk were consumed.
26900
26901'use strict';
26902
26903module.exports = Transform;
26904
26905var Duplex = require('./_stream_duplex');
26906
26907/*<replacement>*/
26908var util = require('core-util-is');
26909util.inherits = require('inherits');
26910/*</replacement>*/
26911
26912util.inherits(Transform, Duplex);
26913
26914function afterTransform(er, data) {
26915 var ts = this._transformState;
26916 ts.transforming = false;
26917
26918 var cb = ts.writecb;
26919
26920 if (!cb) {
26921 return this.emit('error', new Error('write callback called multiple times'));
26922 }
26923
26924 ts.writechunk = null;
26925 ts.writecb = null;
26926
26927 if (data != null) // single equals check for both `null` and `undefined`
26928 this.push(data);
26929
26930 cb(er);
26931
26932 var rs = this._readableState;
26933 rs.reading = false;
26934 if (rs.needReadable || rs.length < rs.highWaterMark) {
26935 this._read(rs.highWaterMark);
26936 }
26937}
26938
26939function Transform(options) {
26940 if (!(this instanceof Transform)) return new Transform(options);
26941
26942 Duplex.call(this, options);
26943
26944 this._transformState = {
26945 afterTransform: afterTransform.bind(this),
26946 needTransform: false,
26947 transforming: false,
26948 writecb: null,
26949 writechunk: null,
26950 writeencoding: null
26951 };
26952
26953 // start out asking for a readable event once data is transformed.
26954 this._readableState.needReadable = true;
26955
26956 // we have implemented the _read method, and done the other things
26957 // that Readable wants before the first _read call, so unset the
26958 // sync guard flag.
26959 this._readableState.sync = false;
26960
26961 if (options) {
26962 if (typeof options.transform === 'function') this._transform = options.transform;
26963
26964 if (typeof options.flush === 'function') this._flush = options.flush;
26965 }
26966
26967 // When the writable side finishes, then flush out anything remaining.
26968 this.on('prefinish', prefinish);
26969}
26970
26971function prefinish() {
26972 var _this = this;
26973
26974 if (typeof this._flush === 'function') {
26975 this._flush(function (er, data) {
26976 done(_this, er, data);
26977 });
26978 } else {
26979 done(this, null, null);
26980 }
26981}
26982
26983Transform.prototype.push = function (chunk, encoding) {
26984 this._transformState.needTransform = false;
26985 return Duplex.prototype.push.call(this, chunk, encoding);
26986};
26987
26988// This is the part where you do stuff!
26989// override this function in implementation classes.
26990// 'chunk' is an input chunk.
26991//
26992// Call `push(newChunk)` to pass along transformed output
26993// to the readable side. You may call 'push' zero or more times.
26994//
26995// Call `cb(err)` when you are done with this chunk. If you pass
26996// an error, then that'll put the hurt on the whole operation. If you
26997// never call cb(), then you'll never get another chunk.
26998Transform.prototype._transform = function (chunk, encoding, cb) {
26999 throw new Error('_transform() is not implemented');
27000};
27001
27002Transform.prototype._write = function (chunk, encoding, cb) {
27003 var ts = this._transformState;
27004 ts.writecb = cb;
27005 ts.writechunk = chunk;
27006 ts.writeencoding = encoding;
27007 if (!ts.transforming) {
27008 var rs = this._readableState;
27009 if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
27010 }
27011};
27012
27013// Doesn't matter what the args are here.
27014// _transform does all the work.
27015// That we got here means that the readable side wants more data.
27016Transform.prototype._read = function (n) {
27017 var ts = this._transformState;
27018
27019 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
27020 ts.transforming = true;
27021 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
27022 } else {
27023 // mark that we need a transform, so that any data that comes in
27024 // will get processed, now that we've asked for it.
27025 ts.needTransform = true;
27026 }
27027};
27028
27029Transform.prototype._destroy = function (err, cb) {
27030 var _this2 = this;
27031
27032 Duplex.prototype._destroy.call(this, err, function (err2) {
27033 cb(err2);
27034 _this2.emit('close');
27035 });
27036};
27037
27038function done(stream, er, data) {
27039 if (er) return stream.emit('error', er);
27040
27041 if (data != null) // single equals check for both `null` and `undefined`
27042 stream.push(data);
27043
27044 // if there's nothing in the write buffer, then that means
27045 // that nothing more will ever be provided
27046 if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
27047
27048 if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
27049
27050 return stream.push(null);
27051}
27052},{"./_stream_duplex":191,"core-util-is":112,"inherits":162}],195:[function(require,module,exports){
27053(function (process,global,setImmediate){
27054// Copyright Joyent, Inc. and other Node contributors.
27055//
27056// Permission is hereby granted, free of charge, to any person obtaining a
27057// copy of this software and associated documentation files (the
27058// "Software"), to deal in the Software without restriction, including
27059// without limitation the rights to use, copy, modify, merge, publish,
27060// distribute, sublicense, and/or sell copies of the Software, and to permit
27061// persons to whom the Software is furnished to do so, subject to the
27062// following conditions:
27063//
27064// The above copyright notice and this permission notice shall be included
27065// in all copies or substantial portions of the Software.
27066//
27067// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27068// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27069// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27070// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27071// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27072// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27073// USE OR OTHER DEALINGS IN THE SOFTWARE.
27074
27075// A bit simpler than readable streams.
27076// Implement an async ._write(chunk, encoding, cb), and it'll handle all
27077// the drain event emission and buffering.
27078
27079'use strict';
27080
27081/*<replacement>*/
27082
27083var pna = require('process-nextick-args');
27084/*</replacement>*/
27085
27086module.exports = Writable;
27087
27088/* <replacement> */
27089function WriteReq(chunk, encoding, cb) {
27090 this.chunk = chunk;
27091 this.encoding = encoding;
27092 this.callback = cb;
27093 this.next = null;
27094}
27095
27096// It seems a linked list but it is not
27097// there will be only 2 of these for each stream
27098function CorkedRequest(state) {
27099 var _this = this;
27100
27101 this.next = null;
27102 this.entry = null;
27103 this.finish = function () {
27104 onCorkedFinish(_this, state);
27105 };
27106}
27107/* </replacement> */
27108
27109/*<replacement>*/
27110var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
27111/*</replacement>*/
27112
27113/*<replacement>*/
27114var Duplex;
27115/*</replacement>*/
27116
27117Writable.WritableState = WritableState;
27118
27119/*<replacement>*/
27120var util = require('core-util-is');
27121util.inherits = require('inherits');
27122/*</replacement>*/
27123
27124/*<replacement>*/
27125var internalUtil = {
27126 deprecate: require('util-deprecate')
27127};
27128/*</replacement>*/
27129
27130/*<replacement>*/
27131var Stream = require('./internal/streams/stream');
27132/*</replacement>*/
27133
27134/*<replacement>*/
27135
27136var Buffer = require('safe-buffer').Buffer;
27137var OurUint8Array = global.Uint8Array || function () {};
27138function _uint8ArrayToBuffer(chunk) {
27139 return Buffer.from(chunk);
27140}
27141function _isUint8Array(obj) {
27142 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
27143}
27144
27145/*</replacement>*/
27146
27147var destroyImpl = require('./internal/streams/destroy');
27148
27149util.inherits(Writable, Stream);
27150
27151function nop() {}
27152
27153function WritableState(options, stream) {
27154 Duplex = Duplex || require('./_stream_duplex');
27155
27156 options = options || {};
27157
27158 // Duplex streams are both readable and writable, but share
27159 // the same options object.
27160 // However, some cases require setting options to different
27161 // values for the readable and the writable sides of the duplex stream.
27162 // These options can be provided separately as readableXXX and writableXXX.
27163 var isDuplex = stream instanceof Duplex;
27164
27165 // object stream flag to indicate whether or not this stream
27166 // contains buffers or objects.
27167 this.objectMode = !!options.objectMode;
27168
27169 if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
27170
27171 // the point at which write() starts returning false
27172 // Note: 0 is a valid value, means that we always return false if
27173 // the entire buffer is not flushed immediately on write()
27174 var hwm = options.highWaterMark;
27175 var writableHwm = options.writableHighWaterMark;
27176 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
27177
27178 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
27179
27180 // cast to ints.
27181 this.highWaterMark = Math.floor(this.highWaterMark);
27182
27183 // if _final has been called
27184 this.finalCalled = false;
27185
27186 // drain event flag.
27187 this.needDrain = false;
27188 // at the start of calling end()
27189 this.ending = false;
27190 // when end() has been called, and returned
27191 this.ended = false;
27192 // when 'finish' is emitted
27193 this.finished = false;
27194
27195 // has it been destroyed
27196 this.destroyed = false;
27197
27198 // should we decode strings into buffers before passing to _write?
27199 // this is here so that some node-core streams can optimize string
27200 // handling at a lower level.
27201 var noDecode = options.decodeStrings === false;
27202 this.decodeStrings = !noDecode;
27203
27204 // Crypto is kind of old and crusty. Historically, its default string
27205 // encoding is 'binary' so we have to make this configurable.
27206 // Everything else in the universe uses 'utf8', though.
27207 this.defaultEncoding = options.defaultEncoding || 'utf8';
27208
27209 // not an actual buffer we keep track of, but a measurement
27210 // of how much we're waiting to get pushed to some underlying
27211 // socket or file.
27212 this.length = 0;
27213
27214 // a flag to see when we're in the middle of a write.
27215 this.writing = false;
27216
27217 // when true all writes will be buffered until .uncork() call
27218 this.corked = 0;
27219
27220 // a flag to be able to tell if the onwrite cb is called immediately,
27221 // or on a later tick. We set this to true at first, because any
27222 // actions that shouldn't happen until "later" should generally also
27223 // not happen before the first write call.
27224 this.sync = true;
27225
27226 // a flag to know if we're processing previously buffered items, which
27227 // may call the _write() callback in the same tick, so that we don't
27228 // end up in an overlapped onwrite situation.
27229 this.bufferProcessing = false;
27230
27231 // the callback that's passed to _write(chunk,cb)
27232 this.onwrite = function (er) {
27233 onwrite(stream, er);
27234 };
27235
27236 // the callback that the user supplies to write(chunk,encoding,cb)
27237 this.writecb = null;
27238
27239 // the amount that is being written when _write is called.
27240 this.writelen = 0;
27241
27242 this.bufferedRequest = null;
27243 this.lastBufferedRequest = null;
27244
27245 // number of pending user-supplied write callbacks
27246 // this must be 0 before 'finish' can be emitted
27247 this.pendingcb = 0;
27248
27249 // emit prefinish if the only thing we're waiting for is _write cbs
27250 // This is relevant for synchronous Transform streams
27251 this.prefinished = false;
27252
27253 // True if the error was already emitted and should not be thrown again
27254 this.errorEmitted = false;
27255
27256 // count buffered requests
27257 this.bufferedRequestCount = 0;
27258
27259 // allocate the first CorkedRequest, there is always
27260 // one allocated and free to use, and we maintain at most two
27261 this.corkedRequestsFree = new CorkedRequest(this);
27262}
27263
27264WritableState.prototype.getBuffer = function getBuffer() {
27265 var current = this.bufferedRequest;
27266 var out = [];
27267 while (current) {
27268 out.push(current);
27269 current = current.next;
27270 }
27271 return out;
27272};
27273
27274(function () {
27275 try {
27276 Object.defineProperty(WritableState.prototype, 'buffer', {
27277 get: internalUtil.deprecate(function () {
27278 return this.getBuffer();
27279 }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
27280 });
27281 } catch (_) {}
27282})();
27283
27284// Test _writableState for inheritance to account for Duplex streams,
27285// whose prototype chain only points to Readable.
27286var realHasInstance;
27287if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
27288 realHasInstance = Function.prototype[Symbol.hasInstance];
27289 Object.defineProperty(Writable, Symbol.hasInstance, {
27290 value: function (object) {
27291 if (realHasInstance.call(this, object)) return true;
27292 if (this !== Writable) return false;
27293
27294 return object && object._writableState instanceof WritableState;
27295 }
27296 });
27297} else {
27298 realHasInstance = function (object) {
27299 return object instanceof this;
27300 };
27301}
27302
27303function Writable(options) {
27304 Duplex = Duplex || require('./_stream_duplex');
27305
27306 // Writable ctor is applied to Duplexes, too.
27307 // `realHasInstance` is necessary because using plain `instanceof`
27308 // would return false, as no `_writableState` property is attached.
27309
27310 // Trying to use the custom `instanceof` for Writable here will also break the
27311 // Node.js LazyTransform implementation, which has a non-trivial getter for
27312 // `_writableState` that would lead to infinite recursion.
27313 if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
27314 return new Writable(options);
27315 }
27316
27317 this._writableState = new WritableState(options, this);
27318
27319 // legacy.
27320 this.writable = true;
27321
27322 if (options) {
27323 if (typeof options.write === 'function') this._write = options.write;
27324
27325 if (typeof options.writev === 'function') this._writev = options.writev;
27326
27327 if (typeof options.destroy === 'function') this._destroy = options.destroy;
27328
27329 if (typeof options.final === 'function') this._final = options.final;
27330 }
27331
27332 Stream.call(this);
27333}
27334
27335// Otherwise people can pipe Writable streams, which is just wrong.
27336Writable.prototype.pipe = function () {
27337 this.emit('error', new Error('Cannot pipe, not readable'));
27338};
27339
27340function writeAfterEnd(stream, cb) {
27341 var er = new Error('write after end');
27342 // TODO: defer error events consistently everywhere, not just the cb
27343 stream.emit('error', er);
27344 pna.nextTick(cb, er);
27345}
27346
27347// Checks that a user-supplied chunk is valid, especially for the particular
27348// mode the stream is in. Currently this means that `null` is never accepted
27349// and undefined/non-string values are only allowed in object mode.
27350function validChunk(stream, state, chunk, cb) {
27351 var valid = true;
27352 var er = false;
27353
27354 if (chunk === null) {
27355 er = new TypeError('May not write null values to stream');
27356 } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
27357 er = new TypeError('Invalid non-string/buffer chunk');
27358 }
27359 if (er) {
27360 stream.emit('error', er);
27361 pna.nextTick(cb, er);
27362 valid = false;
27363 }
27364 return valid;
27365}
27366
27367Writable.prototype.write = function (chunk, encoding, cb) {
27368 var state = this._writableState;
27369 var ret = false;
27370 var isBuf = !state.objectMode && _isUint8Array(chunk);
27371
27372 if (isBuf && !Buffer.isBuffer(chunk)) {
27373 chunk = _uint8ArrayToBuffer(chunk);
27374 }
27375
27376 if (typeof encoding === 'function') {
27377 cb = encoding;
27378 encoding = null;
27379 }
27380
27381 if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
27382
27383 if (typeof cb !== 'function') cb = nop;
27384
27385 if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
27386 state.pendingcb++;
27387 ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
27388 }
27389
27390 return ret;
27391};
27392
27393Writable.prototype.cork = function () {
27394 var state = this._writableState;
27395
27396 state.corked++;
27397};
27398
27399Writable.prototype.uncork = function () {
27400 var state = this._writableState;
27401
27402 if (state.corked) {
27403 state.corked--;
27404
27405 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
27406 }
27407};
27408
27409Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
27410 // node::ParseEncoding() requires lower case.
27411 if (typeof encoding === 'string') encoding = encoding.toLowerCase();
27412 if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
27413 this._writableState.defaultEncoding = encoding;
27414 return this;
27415};
27416
27417function decodeChunk(state, chunk, encoding) {
27418 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
27419 chunk = Buffer.from(chunk, encoding);
27420 }
27421 return chunk;
27422}
27423
27424Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
27425 // making it explicit this property is not enumerable
27426 // because otherwise some prototype manipulation in
27427 // userland will fail
27428 enumerable: false,
27429 get: function () {
27430 return this._writableState.highWaterMark;
27431 }
27432});
27433
27434// if we're already writing something, then just put this
27435// in the queue, and wait our turn. Otherwise, call _write
27436// If we return false, then we need a drain event, so set that flag.
27437function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
27438 if (!isBuf) {
27439 var newChunk = decodeChunk(state, chunk, encoding);
27440 if (chunk !== newChunk) {
27441 isBuf = true;
27442 encoding = 'buffer';
27443 chunk = newChunk;
27444 }
27445 }
27446 var len = state.objectMode ? 1 : chunk.length;
27447
27448 state.length += len;
27449
27450 var ret = state.length < state.highWaterMark;
27451 // we must ensure that previous needDrain will not be reset to false.
27452 if (!ret) state.needDrain = true;
27453
27454 if (state.writing || state.corked) {
27455 var last = state.lastBufferedRequest;
27456 state.lastBufferedRequest = {
27457 chunk: chunk,
27458 encoding: encoding,
27459 isBuf: isBuf,
27460 callback: cb,
27461 next: null
27462 };
27463 if (last) {
27464 last.next = state.lastBufferedRequest;
27465 } else {
27466 state.bufferedRequest = state.lastBufferedRequest;
27467 }
27468 state.bufferedRequestCount += 1;
27469 } else {
27470 doWrite(stream, state, false, len, chunk, encoding, cb);
27471 }
27472
27473 return ret;
27474}
27475
27476function doWrite(stream, state, writev, len, chunk, encoding, cb) {
27477 state.writelen = len;
27478 state.writecb = cb;
27479 state.writing = true;
27480 state.sync = true;
27481 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
27482 state.sync = false;
27483}
27484
27485function onwriteError(stream, state, sync, er, cb) {
27486 --state.pendingcb;
27487
27488 if (sync) {
27489 // defer the callback if we are being called synchronously
27490 // to avoid piling up things on the stack
27491 pna.nextTick(cb, er);
27492 // this can emit finish, and it will always happen
27493 // after error
27494 pna.nextTick(finishMaybe, stream, state);
27495 stream._writableState.errorEmitted = true;
27496 stream.emit('error', er);
27497 } else {
27498 // the caller expect this to happen before if
27499 // it is async
27500 cb(er);
27501 stream._writableState.errorEmitted = true;
27502 stream.emit('error', er);
27503 // this can emit finish, but finish must
27504 // always follow error
27505 finishMaybe(stream, state);
27506 }
27507}
27508
27509function onwriteStateUpdate(state) {
27510 state.writing = false;
27511 state.writecb = null;
27512 state.length -= state.writelen;
27513 state.writelen = 0;
27514}
27515
27516function onwrite(stream, er) {
27517 var state = stream._writableState;
27518 var sync = state.sync;
27519 var cb = state.writecb;
27520
27521 onwriteStateUpdate(state);
27522
27523 if (er) onwriteError(stream, state, sync, er, cb);else {
27524 // Check if we're actually ready to finish, but don't emit yet
27525 var finished = needFinish(state);
27526
27527 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
27528 clearBuffer(stream, state);
27529 }
27530
27531 if (sync) {
27532 /*<replacement>*/
27533 asyncWrite(afterWrite, stream, state, finished, cb);
27534 /*</replacement>*/
27535 } else {
27536 afterWrite(stream, state, finished, cb);
27537 }
27538 }
27539}
27540
27541function afterWrite(stream, state, finished, cb) {
27542 if (!finished) onwriteDrain(stream, state);
27543 state.pendingcb--;
27544 cb();
27545 finishMaybe(stream, state);
27546}
27547
27548// Must force callback to be called on nextTick, so that we don't
27549// emit 'drain' before the write() consumer gets the 'false' return
27550// value, and has a chance to attach a 'drain' listener.
27551function onwriteDrain(stream, state) {
27552 if (state.length === 0 && state.needDrain) {
27553 state.needDrain = false;
27554 stream.emit('drain');
27555 }
27556}
27557
27558// if there's something in the buffer waiting, then process it
27559function clearBuffer(stream, state) {
27560 state.bufferProcessing = true;
27561 var entry = state.bufferedRequest;
27562
27563 if (stream._writev && entry && entry.next) {
27564 // Fast case, write everything using _writev()
27565 var l = state.bufferedRequestCount;
27566 var buffer = new Array(l);
27567 var holder = state.corkedRequestsFree;
27568 holder.entry = entry;
27569
27570 var count = 0;
27571 var allBuffers = true;
27572 while (entry) {
27573 buffer[count] = entry;
27574 if (!entry.isBuf) allBuffers = false;
27575 entry = entry.next;
27576 count += 1;
27577 }
27578 buffer.allBuffers = allBuffers;
27579
27580 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
27581
27582 // doWrite is almost always async, defer these to save a bit of time
27583 // as the hot path ends with doWrite
27584 state.pendingcb++;
27585 state.lastBufferedRequest = null;
27586 if (holder.next) {
27587 state.corkedRequestsFree = holder.next;
27588 holder.next = null;
27589 } else {
27590 state.corkedRequestsFree = new CorkedRequest(state);
27591 }
27592 state.bufferedRequestCount = 0;
27593 } else {
27594 // Slow case, write chunks one-by-one
27595 while (entry) {
27596 var chunk = entry.chunk;
27597 var encoding = entry.encoding;
27598 var cb = entry.callback;
27599 var len = state.objectMode ? 1 : chunk.length;
27600
27601 doWrite(stream, state, false, len, chunk, encoding, cb);
27602 entry = entry.next;
27603 state.bufferedRequestCount--;
27604 // if we didn't call the onwrite immediately, then
27605 // it means that we need to wait until it does.
27606 // also, that means that the chunk and cb are currently
27607 // being processed, so move the buffer counter past them.
27608 if (state.writing) {
27609 break;
27610 }
27611 }
27612
27613 if (entry === null) state.lastBufferedRequest = null;
27614 }
27615
27616 state.bufferedRequest = entry;
27617 state.bufferProcessing = false;
27618}
27619
27620Writable.prototype._write = function (chunk, encoding, cb) {
27621 cb(new Error('_write() is not implemented'));
27622};
27623
27624Writable.prototype._writev = null;
27625
27626Writable.prototype.end = function (chunk, encoding, cb) {
27627 var state = this._writableState;
27628
27629 if (typeof chunk === 'function') {
27630 cb = chunk;
27631 chunk = null;
27632 encoding = null;
27633 } else if (typeof encoding === 'function') {
27634 cb = encoding;
27635 encoding = null;
27636 }
27637
27638 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
27639
27640 // .end() fully uncorks
27641 if (state.corked) {
27642 state.corked = 1;
27643 this.uncork();
27644 }
27645
27646 // ignore unnecessary end() calls.
27647 if (!state.ending && !state.finished) endWritable(this, state, cb);
27648};
27649
27650function needFinish(state) {
27651 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
27652}
27653function callFinal(stream, state) {
27654 stream._final(function (err) {
27655 state.pendingcb--;
27656 if (err) {
27657 stream.emit('error', err);
27658 }
27659 state.prefinished = true;
27660 stream.emit('prefinish');
27661 finishMaybe(stream, state);
27662 });
27663}
27664function prefinish(stream, state) {
27665 if (!state.prefinished && !state.finalCalled) {
27666 if (typeof stream._final === 'function') {
27667 state.pendingcb++;
27668 state.finalCalled = true;
27669 pna.nextTick(callFinal, stream, state);
27670 } else {
27671 state.prefinished = true;
27672 stream.emit('prefinish');
27673 }
27674 }
27675}
27676
27677function finishMaybe(stream, state) {
27678 var need = needFinish(state);
27679 if (need) {
27680 prefinish(stream, state);
27681 if (state.pendingcb === 0) {
27682 state.finished = true;
27683 stream.emit('finish');
27684 }
27685 }
27686 return need;
27687}
27688
27689function endWritable(stream, state, cb) {
27690 state.ending = true;
27691 finishMaybe(stream, state);
27692 if (cb) {
27693 if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
27694 }
27695 state.ended = true;
27696 stream.writable = false;
27697}
27698
27699function onCorkedFinish(corkReq, state, err) {
27700 var entry = corkReq.entry;
27701 corkReq.entry = null;
27702 while (entry) {
27703 var cb = entry.callback;
27704 state.pendingcb--;
27705 cb(err);
27706 entry = entry.next;
27707 }
27708 if (state.corkedRequestsFree) {
27709 state.corkedRequestsFree.next = corkReq;
27710 } else {
27711 state.corkedRequestsFree = corkReq;
27712 }
27713}
27714
27715Object.defineProperty(Writable.prototype, 'destroyed', {
27716 get: function () {
27717 if (this._writableState === undefined) {
27718 return false;
27719 }
27720 return this._writableState.destroyed;
27721 },
27722 set: function (value) {
27723 // we ignore the value if the stream
27724 // has not been initialized yet
27725 if (!this._writableState) {
27726 return;
27727 }
27728
27729 // backward compatibility, the user is explicitly
27730 // managing destroyed
27731 this._writableState.destroyed = value;
27732 }
27733});
27734
27735Writable.prototype.destroy = destroyImpl.destroy;
27736Writable.prototype._undestroy = destroyImpl.undestroy;
27737Writable.prototype._destroy = function (err, cb) {
27738 this.end();
27739 cb(err);
27740};
27741}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
27742},{"./_stream_duplex":191,"./internal/streams/destroy":197,"./internal/streams/stream":198,"_process":181,"core-util-is":112,"inherits":162,"process-nextick-args":180,"safe-buffer":199,"timers":217,"util-deprecate":218}],196:[function(require,module,exports){
27743'use strict';
27744
27745function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27746
27747var Buffer = require('safe-buffer').Buffer;
27748var util = require('util');
27749
27750function copyBuffer(src, target, offset) {
27751 src.copy(target, offset);
27752}
27753
27754module.exports = function () {
27755 function BufferList() {
27756 _classCallCheck(this, BufferList);
27757
27758 this.head = null;
27759 this.tail = null;
27760 this.length = 0;
27761 }
27762
27763 BufferList.prototype.push = function push(v) {
27764 var entry = { data: v, next: null };
27765 if (this.length > 0) this.tail.next = entry;else this.head = entry;
27766 this.tail = entry;
27767 ++this.length;
27768 };
27769
27770 BufferList.prototype.unshift = function unshift(v) {
27771 var entry = { data: v, next: this.head };
27772 if (this.length === 0) this.tail = entry;
27773 this.head = entry;
27774 ++this.length;
27775 };
27776
27777 BufferList.prototype.shift = function shift() {
27778 if (this.length === 0) return;
27779 var ret = this.head.data;
27780 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
27781 --this.length;
27782 return ret;
27783 };
27784
27785 BufferList.prototype.clear = function clear() {
27786 this.head = this.tail = null;
27787 this.length = 0;
27788 };
27789
27790 BufferList.prototype.join = function join(s) {
27791 if (this.length === 0) return '';
27792 var p = this.head;
27793 var ret = '' + p.data;
27794 while (p = p.next) {
27795 ret += s + p.data;
27796 }return ret;
27797 };
27798
27799 BufferList.prototype.concat = function concat(n) {
27800 if (this.length === 0) return Buffer.alloc(0);
27801 if (this.length === 1) return this.head.data;
27802 var ret = Buffer.allocUnsafe(n >>> 0);
27803 var p = this.head;
27804 var i = 0;
27805 while (p) {
27806 copyBuffer(p.data, ret, i);
27807 i += p.data.length;
27808 p = p.next;
27809 }
27810 return ret;
27811 };
27812
27813 return BufferList;
27814}();
27815
27816if (util && util.inspect && util.inspect.custom) {
27817 module.exports.prototype[util.inspect.custom] = function () {
27818 var obj = util.inspect({ length: this.length });
27819 return this.constructor.name + ' ' + obj;
27820 };
27821}
27822},{"safe-buffer":199,"util":81}],197:[function(require,module,exports){
27823'use strict';
27824
27825/*<replacement>*/
27826
27827var pna = require('process-nextick-args');
27828/*</replacement>*/
27829
27830// undocumented cb() API, needed for core, not for public API
27831function destroy(err, cb) {
27832 var _this = this;
27833
27834 var readableDestroyed = this._readableState && this._readableState.destroyed;
27835 var writableDestroyed = this._writableState && this._writableState.destroyed;
27836
27837 if (readableDestroyed || writableDestroyed) {
27838 if (cb) {
27839 cb(err);
27840 } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
27841 pna.nextTick(emitErrorNT, this, err);
27842 }
27843 return this;
27844 }
27845
27846 // we set destroyed to true before firing error callbacks in order
27847 // to make it re-entrance safe in case destroy() is called within callbacks
27848
27849 if (this._readableState) {
27850 this._readableState.destroyed = true;
27851 }
27852
27853 // if this is a duplex stream mark the writable part as destroyed as well
27854 if (this._writableState) {
27855 this._writableState.destroyed = true;
27856 }
27857
27858 this._destroy(err || null, function (err) {
27859 if (!cb && err) {
27860 pna.nextTick(emitErrorNT, _this, err);
27861 if (_this._writableState) {
27862 _this._writableState.errorEmitted = true;
27863 }
27864 } else if (cb) {
27865 cb(err);
27866 }
27867 });
27868
27869 return this;
27870}
27871
27872function undestroy() {
27873 if (this._readableState) {
27874 this._readableState.destroyed = false;
27875 this._readableState.reading = false;
27876 this._readableState.ended = false;
27877 this._readableState.endEmitted = false;
27878 }
27879
27880 if (this._writableState) {
27881 this._writableState.destroyed = false;
27882 this._writableState.ended = false;
27883 this._writableState.ending = false;
27884 this._writableState.finished = false;
27885 this._writableState.errorEmitted = false;
27886 }
27887}
27888
27889function emitErrorNT(self, err) {
27890 self.emit('error', err);
27891}
27892
27893module.exports = {
27894 destroy: destroy,
27895 undestroy: undestroy
27896};
27897},{"process-nextick-args":180}],198:[function(require,module,exports){
27898module.exports = require('events').EventEmitter;
27899
27900},{"events":145}],199:[function(require,module,exports){
27901/* eslint-disable node/no-deprecated-api */
27902var buffer = require('buffer')
27903var Buffer = buffer.Buffer
27904
27905// alternative to using Object.keys for old browsers
27906function copyProps (src, dst) {
27907 for (var key in src) {
27908 dst[key] = src[key]
27909 }
27910}
27911if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
27912 module.exports = buffer
27913} else {
27914 // Copy properties from require('buffer')
27915 copyProps(buffer, exports)
27916 exports.Buffer = SafeBuffer
27917}
27918
27919function SafeBuffer (arg, encodingOrOffset, length) {
27920 return Buffer(arg, encodingOrOffset, length)
27921}
27922
27923// Copy static methods from Buffer
27924copyProps(Buffer, SafeBuffer)
27925
27926SafeBuffer.from = function (arg, encodingOrOffset, length) {
27927 if (typeof arg === 'number') {
27928 throw new TypeError('Argument must not be a number')
27929 }
27930 return Buffer(arg, encodingOrOffset, length)
27931}
27932
27933SafeBuffer.alloc = function (size, fill, encoding) {
27934 if (typeof size !== 'number') {
27935 throw new TypeError('Argument must be a number')
27936 }
27937 var buf = Buffer(size)
27938 if (fill !== undefined) {
27939 if (typeof encoding === 'string') {
27940 buf.fill(fill, encoding)
27941 } else {
27942 buf.fill(fill)
27943 }
27944 } else {
27945 buf.fill(0)
27946 }
27947 return buf
27948}
27949
27950SafeBuffer.allocUnsafe = function (size) {
27951 if (typeof size !== 'number') {
27952 throw new TypeError('Argument must be a number')
27953 }
27954 return Buffer(size)
27955}
27956
27957SafeBuffer.allocUnsafeSlow = function (size) {
27958 if (typeof size !== 'number') {
27959 throw new TypeError('Argument must be a number')
27960 }
27961 return buffer.SlowBuffer(size)
27962}
27963
27964},{"buffer":110}],200:[function(require,module,exports){
27965// Copyright Joyent, Inc. and other Node contributors.
27966//
27967// Permission is hereby granted, free of charge, to any person obtaining a
27968// copy of this software and associated documentation files (the
27969// "Software"), to deal in the Software without restriction, including
27970// without limitation the rights to use, copy, modify, merge, publish,
27971// distribute, sublicense, and/or sell copies of the Software, and to permit
27972// persons to whom the Software is furnished to do so, subject to the
27973// following conditions:
27974//
27975// The above copyright notice and this permission notice shall be included
27976// in all copies or substantial portions of the Software.
27977//
27978// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27979// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27980// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27981// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27982// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27983// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27984// USE OR OTHER DEALINGS IN THE SOFTWARE.
27985
27986'use strict';
27987
27988/*<replacement>*/
27989
27990var Buffer = require('safe-buffer').Buffer;
27991/*</replacement>*/
27992
27993var isEncoding = Buffer.isEncoding || function (encoding) {
27994 encoding = '' + encoding;
27995 switch (encoding && encoding.toLowerCase()) {
27996 case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
27997 return true;
27998 default:
27999 return false;
28000 }
28001};
28002
28003function _normalizeEncoding(enc) {
28004 if (!enc) return 'utf8';
28005 var retried;
28006 while (true) {
28007 switch (enc) {
28008 case 'utf8':
28009 case 'utf-8':
28010 return 'utf8';
28011 case 'ucs2':
28012 case 'ucs-2':
28013 case 'utf16le':
28014 case 'utf-16le':
28015 return 'utf16le';
28016 case 'latin1':
28017 case 'binary':
28018 return 'latin1';
28019 case 'base64':
28020 case 'ascii':
28021 case 'hex':
28022 return enc;
28023 default:
28024 if (retried) return; // undefined
28025 enc = ('' + enc).toLowerCase();
28026 retried = true;
28027 }
28028 }
28029};
28030
28031// Do not cache `Buffer.isEncoding` when checking encoding names as some
28032// modules monkey-patch it to support additional encodings
28033function normalizeEncoding(enc) {
28034 var nenc = _normalizeEncoding(enc);
28035 if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
28036 return nenc || enc;
28037}
28038
28039// StringDecoder provides an interface for efficiently splitting a series of
28040// buffers into a series of JS strings without breaking apart multi-byte
28041// characters.
28042exports.StringDecoder = StringDecoder;
28043function StringDecoder(encoding) {
28044 this.encoding = normalizeEncoding(encoding);
28045 var nb;
28046 switch (this.encoding) {
28047 case 'utf16le':
28048 this.text = utf16Text;
28049 this.end = utf16End;
28050 nb = 4;
28051 break;
28052 case 'utf8':
28053 this.fillLast = utf8FillLast;
28054 nb = 4;
28055 break;
28056 case 'base64':
28057 this.text = base64Text;
28058 this.end = base64End;
28059 nb = 3;
28060 break;
28061 default:
28062 this.write = simpleWrite;
28063 this.end = simpleEnd;
28064 return;
28065 }
28066 this.lastNeed = 0;
28067 this.lastTotal = 0;
28068 this.lastChar = Buffer.allocUnsafe(nb);
28069}
28070
28071StringDecoder.prototype.write = function (buf) {
28072 if (buf.length === 0) return '';
28073 var r;
28074 var i;
28075 if (this.lastNeed) {
28076 r = this.fillLast(buf);
28077 if (r === undefined) return '';
28078 i = this.lastNeed;
28079 this.lastNeed = 0;
28080 } else {
28081 i = 0;
28082 }
28083 if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
28084 return r || '';
28085};
28086
28087StringDecoder.prototype.end = utf8End;
28088
28089// Returns only complete characters in a Buffer
28090StringDecoder.prototype.text = utf8Text;
28091
28092// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
28093StringDecoder.prototype.fillLast = function (buf) {
28094 if (this.lastNeed <= buf.length) {
28095 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
28096 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
28097 }
28098 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
28099 this.lastNeed -= buf.length;
28100};
28101
28102// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
28103// continuation byte. If an invalid byte is detected, -2 is returned.
28104function utf8CheckByte(byte) {
28105 if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
28106 return byte >> 6 === 0x02 ? -1 : -2;
28107}
28108
28109// Checks at most 3 bytes at the end of a Buffer in order to detect an
28110// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
28111// needed to complete the UTF-8 character (if applicable) are returned.
28112function utf8CheckIncomplete(self, buf, i) {
28113 var j = buf.length - 1;
28114 if (j < i) return 0;
28115 var nb = utf8CheckByte(buf[j]);
28116 if (nb >= 0) {
28117 if (nb > 0) self.lastNeed = nb - 1;
28118 return nb;
28119 }
28120 if (--j < i || nb === -2) return 0;
28121 nb = utf8CheckByte(buf[j]);
28122 if (nb >= 0) {
28123 if (nb > 0) self.lastNeed = nb - 2;
28124 return nb;
28125 }
28126 if (--j < i || nb === -2) return 0;
28127 nb = utf8CheckByte(buf[j]);
28128 if (nb >= 0) {
28129 if (nb > 0) {
28130 if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
28131 }
28132 return nb;
28133 }
28134 return 0;
28135}
28136
28137// Validates as many continuation bytes for a multi-byte UTF-8 character as
28138// needed or are available. If we see a non-continuation byte where we expect
28139// one, we "replace" the validated continuation bytes we've seen so far with
28140// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
28141// behavior. The continuation byte check is included three times in the case
28142// where all of the continuation bytes for a character exist in the same buffer.
28143// It is also done this way as a slight performance increase instead of using a
28144// loop.
28145function utf8CheckExtraBytes(self, buf, p) {
28146 if ((buf[0] & 0xC0) !== 0x80) {
28147 self.lastNeed = 0;
28148 return '\ufffd';
28149 }
28150 if (self.lastNeed > 1 && buf.length > 1) {
28151 if ((buf[1] & 0xC0) !== 0x80) {
28152 self.lastNeed = 1;
28153 return '\ufffd';
28154 }
28155 if (self.lastNeed > 2 && buf.length > 2) {
28156 if ((buf[2] & 0xC0) !== 0x80) {
28157 self.lastNeed = 2;
28158 return '\ufffd';
28159 }
28160 }
28161 }
28162}
28163
28164// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
28165function utf8FillLast(buf) {
28166 var p = this.lastTotal - this.lastNeed;
28167 var r = utf8CheckExtraBytes(this, buf, p);
28168 if (r !== undefined) return r;
28169 if (this.lastNeed <= buf.length) {
28170 buf.copy(this.lastChar, p, 0, this.lastNeed);
28171 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
28172 }
28173 buf.copy(this.lastChar, p, 0, buf.length);
28174 this.lastNeed -= buf.length;
28175}
28176
28177// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
28178// partial character, the character's bytes are buffered until the required
28179// number of bytes are available.
28180function utf8Text(buf, i) {
28181 var total = utf8CheckIncomplete(this, buf, i);
28182 if (!this.lastNeed) return buf.toString('utf8', i);
28183 this.lastTotal = total;
28184 var end = buf.length - (total - this.lastNeed);
28185 buf.copy(this.lastChar, 0, end);
28186 return buf.toString('utf8', i, end);
28187}
28188
28189// For UTF-8, a replacement character is added when ending on a partial
28190// character.
28191function utf8End(buf) {
28192 var r = buf && buf.length ? this.write(buf) : '';
28193 if (this.lastNeed) return r + '\ufffd';
28194 return r;
28195}
28196
28197// UTF-16LE typically needs two bytes per character, but even if we have an even
28198// number of bytes available, we need to check if we end on a leading/high
28199// surrogate. In that case, we need to wait for the next two bytes in order to
28200// decode the last character properly.
28201function utf16Text(buf, i) {
28202 if ((buf.length - i) % 2 === 0) {
28203 var r = buf.toString('utf16le', i);
28204 if (r) {
28205 var c = r.charCodeAt(r.length - 1);
28206 if (c >= 0xD800 && c <= 0xDBFF) {
28207 this.lastNeed = 2;
28208 this.lastTotal = 4;
28209 this.lastChar[0] = buf[buf.length - 2];
28210 this.lastChar[1] = buf[buf.length - 1];
28211 return r.slice(0, -1);
28212 }
28213 }
28214 return r;
28215 }
28216 this.lastNeed = 1;
28217 this.lastTotal = 2;
28218 this.lastChar[0] = buf[buf.length - 1];
28219 return buf.toString('utf16le', i, buf.length - 1);
28220}
28221
28222// For UTF-16LE we do not explicitly append special replacement characters if we
28223// end on a partial character, we simply let v8 handle that.
28224function utf16End(buf) {
28225 var r = buf && buf.length ? this.write(buf) : '';
28226 if (this.lastNeed) {
28227 var end = this.lastTotal - this.lastNeed;
28228 return r + this.lastChar.toString('utf16le', 0, end);
28229 }
28230 return r;
28231}
28232
28233function base64Text(buf, i) {
28234 var n = (buf.length - i) % 3;
28235 if (n === 0) return buf.toString('base64', i);
28236 this.lastNeed = 3 - n;
28237 this.lastTotal = 3;
28238 if (n === 1) {
28239 this.lastChar[0] = buf[buf.length - 1];
28240 } else {
28241 this.lastChar[0] = buf[buf.length - 2];
28242 this.lastChar[1] = buf[buf.length - 1];
28243 }
28244 return buf.toString('base64', i, buf.length - n);
28245}
28246
28247function base64End(buf) {
28248 var r = buf && buf.length ? this.write(buf) : '';
28249 if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
28250 return r;
28251}
28252
28253// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
28254function simpleWrite(buf) {
28255 return buf.toString(this.encoding);
28256}
28257
28258function simpleEnd(buf) {
28259 return buf && buf.length ? this.write(buf) : '';
28260}
28261},{"safe-buffer":199}],201:[function(require,module,exports){
28262module.exports = require('./readable').PassThrough
28263
28264},{"./readable":202}],202:[function(require,module,exports){
28265exports = module.exports = require('./lib/_stream_readable.js');
28266exports.Stream = exports;
28267exports.Readable = exports;
28268exports.Writable = require('./lib/_stream_writable.js');
28269exports.Duplex = require('./lib/_stream_duplex.js');
28270exports.Transform = require('./lib/_stream_transform.js');
28271exports.PassThrough = require('./lib/_stream_passthrough.js');
28272
28273},{"./lib/_stream_duplex.js":191,"./lib/_stream_passthrough.js":192,"./lib/_stream_readable.js":193,"./lib/_stream_transform.js":194,"./lib/_stream_writable.js":195}],203:[function(require,module,exports){
28274module.exports = require('./readable').Transform
28275
28276},{"./readable":202}],204:[function(require,module,exports){
28277module.exports = require('./lib/_stream_writable.js');
28278
28279},{"./lib/_stream_writable.js":195}],205:[function(require,module,exports){
28280arguments[4][46][0].apply(exports,arguments)
28281},{"buffer":110,"dup":46,"hash-base":147,"inherits":162}],206:[function(require,module,exports){
28282arguments[4][47][0].apply(exports,arguments)
28283},{"buffer":110,"dup":47}],207:[function(require,module,exports){
28284arguments[4][52][0].apply(exports,arguments)
28285},{"dup":52,"safe-buffer":206}],208:[function(require,module,exports){
28286arguments[4][53][0].apply(exports,arguments)
28287},{"./sha":209,"./sha1":210,"./sha224":211,"./sha256":212,"./sha384":213,"./sha512":214,"dup":53}],209:[function(require,module,exports){
28288arguments[4][54][0].apply(exports,arguments)
28289},{"./hash":207,"dup":54,"inherits":162,"safe-buffer":206}],210:[function(require,module,exports){
28290arguments[4][55][0].apply(exports,arguments)
28291},{"./hash":207,"dup":55,"inherits":162,"safe-buffer":206}],211:[function(require,module,exports){
28292arguments[4][56][0].apply(exports,arguments)
28293},{"./hash":207,"./sha256":212,"dup":56,"inherits":162,"safe-buffer":206}],212:[function(require,module,exports){
28294arguments[4][57][0].apply(exports,arguments)
28295},{"./hash":207,"dup":57,"inherits":162,"safe-buffer":206}],213:[function(require,module,exports){
28296arguments[4][58][0].apply(exports,arguments)
28297},{"./hash":207,"./sha512":214,"dup":58,"inherits":162,"safe-buffer":206}],214:[function(require,module,exports){
28298arguments[4][59][0].apply(exports,arguments)
28299},{"./hash":207,"dup":59,"inherits":162,"safe-buffer":206}],215:[function(require,module,exports){
28300// Copyright Joyent, Inc. and other Node contributors.
28301//
28302// Permission is hereby granted, free of charge, to any person obtaining a
28303// copy of this software and associated documentation files (the
28304// "Software"), to deal in the Software without restriction, including
28305// without limitation the rights to use, copy, modify, merge, publish,
28306// distribute, sublicense, and/or sell copies of the Software, and to permit
28307// persons to whom the Software is furnished to do so, subject to the
28308// following conditions:
28309//
28310// The above copyright notice and this permission notice shall be included
28311// in all copies or substantial portions of the Software.
28312//
28313// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28314// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28315// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
28316// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28317// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28318// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28319// USE OR OTHER DEALINGS IN THE SOFTWARE.
28320
28321module.exports = Stream;
28322
28323var EE = require('events').EventEmitter;
28324var inherits = require('inherits');
28325
28326inherits(Stream, EE);
28327Stream.Readable = require('readable-stream/readable.js');
28328Stream.Writable = require('readable-stream/writable.js');
28329Stream.Duplex = require('readable-stream/duplex.js');
28330Stream.Transform = require('readable-stream/transform.js');
28331Stream.PassThrough = require('readable-stream/passthrough.js');
28332
28333// Backwards-compat with node 0.4.x
28334Stream.Stream = Stream;
28335
28336
28337
28338// old-style streams. Note that the pipe method (the only relevant
28339// part of this class) is overridden in the Readable class.
28340
28341function Stream() {
28342 EE.call(this);
28343}
28344
28345Stream.prototype.pipe = function(dest, options) {
28346 var source = this;
28347
28348 function ondata(chunk) {
28349 if (dest.writable) {
28350 if (false === dest.write(chunk) && source.pause) {
28351 source.pause();
28352 }
28353 }
28354 }
28355
28356 source.on('data', ondata);
28357
28358 function ondrain() {
28359 if (source.readable && source.resume) {
28360 source.resume();
28361 }
28362 }
28363
28364 dest.on('drain', ondrain);
28365
28366 // If the 'end' option is not supplied, dest.end() will be called when
28367 // source gets the 'end' or 'close' events. Only dest.end() once.
28368 if (!dest._isStdio && (!options || options.end !== false)) {
28369 source.on('end', onend);
28370 source.on('close', onclose);
28371 }
28372
28373 var didOnEnd = false;
28374 function onend() {
28375 if (didOnEnd) return;
28376 didOnEnd = true;
28377
28378 dest.end();
28379 }
28380
28381
28382 function onclose() {
28383 if (didOnEnd) return;
28384 didOnEnd = true;
28385
28386 if (typeof dest.destroy === 'function') dest.destroy();
28387 }
28388
28389 // don't leave dangling pipes when there are errors.
28390 function onerror(er) {
28391 cleanup();
28392 if (EE.listenerCount(this, 'error') === 0) {
28393 throw er; // Unhandled stream error in pipe.
28394 }
28395 }
28396
28397 source.on('error', onerror);
28398 dest.on('error', onerror);
28399
28400 // remove all the event listeners that were added.
28401 function cleanup() {
28402 source.removeListener('data', ondata);
28403 dest.removeListener('drain', ondrain);
28404
28405 source.removeListener('end', onend);
28406 source.removeListener('close', onclose);
28407
28408 source.removeListener('error', onerror);
28409 dest.removeListener('error', onerror);
28410
28411 source.removeListener('end', cleanup);
28412 source.removeListener('close', cleanup);
28413
28414 dest.removeListener('close', cleanup);
28415 }
28416
28417 source.on('end', cleanup);
28418 source.on('close', cleanup);
28419
28420 dest.on('close', cleanup);
28421
28422 dest.emit('pipe', source);
28423
28424 // Allow for unix-like usage: A.pipe(B).pipe(C)
28425 return dest;
28426};
28427
28428},{"events":145,"inherits":162,"readable-stream/duplex.js":190,"readable-stream/passthrough.js":201,"readable-stream/readable.js":202,"readable-stream/transform.js":203,"readable-stream/writable.js":204}],216:[function(require,module,exports){
28429arguments[4][200][0].apply(exports,arguments)
28430},{"dup":200,"safe-buffer":206}],217:[function(require,module,exports){
28431(function (setImmediate,clearImmediate){
28432var nextTick = require('process/browser.js').nextTick;
28433var apply = Function.prototype.apply;
28434var slice = Array.prototype.slice;
28435var immediateIds = {};
28436var nextImmediateId = 0;
28437
28438// DOM APIs, for completeness
28439
28440exports.setTimeout = function() {
28441 return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
28442};
28443exports.setInterval = function() {
28444 return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
28445};
28446exports.clearTimeout =
28447exports.clearInterval = function(timeout) { timeout.close(); };
28448
28449function Timeout(id, clearFn) {
28450 this._id = id;
28451 this._clearFn = clearFn;
28452}
28453Timeout.prototype.unref = Timeout.prototype.ref = function() {};
28454Timeout.prototype.close = function() {
28455 this._clearFn.call(window, this._id);
28456};
28457
28458// Does not start the time, just sets up the members needed.
28459exports.enroll = function(item, msecs) {
28460 clearTimeout(item._idleTimeoutId);
28461 item._idleTimeout = msecs;
28462};
28463
28464exports.unenroll = function(item) {
28465 clearTimeout(item._idleTimeoutId);
28466 item._idleTimeout = -1;
28467};
28468
28469exports._unrefActive = exports.active = function(item) {
28470 clearTimeout(item._idleTimeoutId);
28471
28472 var msecs = item._idleTimeout;
28473 if (msecs >= 0) {
28474 item._idleTimeoutId = setTimeout(function onTimeout() {
28475 if (item._onTimeout)
28476 item._onTimeout();
28477 }, msecs);
28478 }
28479};
28480
28481// That's not how node.js implements it but the exposed api is the same.
28482exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
28483 var id = nextImmediateId++;
28484 var args = arguments.length < 2 ? false : slice.call(arguments, 1);
28485
28486 immediateIds[id] = true;
28487
28488 nextTick(function onNextTick() {
28489 if (immediateIds[id]) {
28490 // fn.call() is faster so we optimize for the common use-case
28491 // @see http://jsperf.com/call-apply-segu
28492 if (args) {
28493 fn.apply(null, args);
28494 } else {
28495 fn.call(null);
28496 }
28497 // Prevent ids from leaking
28498 exports.clearImmediate(id);
28499 }
28500 });
28501
28502 return id;
28503};
28504
28505exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
28506 delete immediateIds[id];
28507};
28508}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
28509},{"process/browser.js":181,"timers":217}],218:[function(require,module,exports){
28510(function (global){
28511
28512/**
28513 * Module exports.
28514 */
28515
28516module.exports = deprecate;
28517
28518/**
28519 * Mark that a method should not be used.
28520 * Returns a modified function which warns once by default.
28521 *
28522 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
28523 *
28524 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
28525 * will throw an Error when invoked.
28526 *
28527 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
28528 * will invoke `console.trace()` instead of `console.error()`.
28529 *
28530 * @param {Function} fn - the function to deprecate
28531 * @param {String} msg - the string to print to the console when `fn` is invoked
28532 * @returns {Function} a new "deprecated" version of `fn`
28533 * @api public
28534 */
28535
28536function deprecate (fn, msg) {
28537 if (config('noDeprecation')) {
28538 return fn;
28539 }
28540
28541 var warned = false;
28542 function deprecated() {
28543 if (!warned) {
28544 if (config('throwDeprecation')) {
28545 throw new Error(msg);
28546 } else if (config('traceDeprecation')) {
28547 console.trace(msg);
28548 } else {
28549 console.warn(msg);
28550 }
28551 warned = true;
28552 }
28553 return fn.apply(this, arguments);
28554 }
28555
28556 return deprecated;
28557}
28558
28559/**
28560 * Checks `localStorage` for boolean values for the given `name`.
28561 *
28562 * @param {String} name
28563 * @returns {Boolean}
28564 * @api private
28565 */
28566
28567function config (name) {
28568 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
28569 try {
28570 if (!global.localStorage) return false;
28571 } catch (_) {
28572 return false;
28573 }
28574 var val = global.localStorage[name];
28575 if (null == val) return false;
28576 return String(val).toLowerCase() === 'true';
28577}
28578
28579}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
28580},{}],219:[function(require,module,exports){
28581var indexOf = function (xs, item) {
28582 if (xs.indexOf) return xs.indexOf(item);
28583 else for (var i = 0; i < xs.length; i++) {
28584 if (xs[i] === item) return i;
28585 }
28586 return -1;
28587};
28588var Object_keys = function (obj) {
28589 if (Object.keys) return Object.keys(obj)
28590 else {
28591 var res = [];
28592 for (var key in obj) res.push(key)
28593 return res;
28594 }
28595};
28596
28597var forEach = function (xs, fn) {
28598 if (xs.forEach) return xs.forEach(fn)
28599 else for (var i = 0; i < xs.length; i++) {
28600 fn(xs[i], i, xs);
28601 }
28602};
28603
28604var defineProp = (function() {
28605 try {
28606 Object.defineProperty({}, '_', {});
28607 return function(obj, name, value) {
28608 Object.defineProperty(obj, name, {
28609 writable: true,
28610 enumerable: false,
28611 configurable: true,
28612 value: value
28613 })
28614 };
28615 } catch(e) {
28616 return function(obj, name, value) {
28617 obj[name] = value;
28618 };
28619 }
28620}());
28621
28622var globals = ['Array', 'Boolean', 'Date', 'Error', 'EvalError', 'Function',
28623'Infinity', 'JSON', 'Math', 'NaN', 'Number', 'Object', 'RangeError',
28624'ReferenceError', 'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError',
28625'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
28626'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'undefined', 'unescape'];
28627
28628function Context() {}
28629Context.prototype = {};
28630
28631var Script = exports.Script = function NodeScript (code) {
28632 if (!(this instanceof Script)) return new Script(code);
28633 this.code = code;
28634};
28635
28636Script.prototype.runInContext = function (context) {
28637 if (!(context instanceof Context)) {
28638 throw new TypeError("needs a 'context' argument.");
28639 }
28640
28641 var iframe = document.createElement('iframe');
28642 if (!iframe.style) iframe.style = {};
28643 iframe.style.display = 'none';
28644
28645 document.body.appendChild(iframe);
28646
28647 var win = iframe.contentWindow;
28648 var wEval = win.eval, wExecScript = win.execScript;
28649
28650 if (!wEval && wExecScript) {
28651 // win.eval() magically appears when this is called in IE:
28652 wExecScript.call(win, 'null');
28653 wEval = win.eval;
28654 }
28655
28656 forEach(Object_keys(context), function (key) {
28657 win[key] = context[key];
28658 });
28659 forEach(globals, function (key) {
28660 if (context[key]) {
28661 win[key] = context[key];
28662 }
28663 });
28664
28665 var winKeys = Object_keys(win);
28666
28667 var res = wEval.call(win, this.code);
28668
28669 forEach(Object_keys(win), function (key) {
28670 // Avoid copying circular objects like `top` and `window` by only
28671 // updating existing context properties or new properties in the `win`
28672 // that was only introduced after the eval.
28673 if (key in context || indexOf(winKeys, key) === -1) {
28674 context[key] = win[key];
28675 }
28676 });
28677
28678 forEach(globals, function (key) {
28679 if (!(key in context)) {
28680 defineProp(context, key, win[key]);
28681 }
28682 });
28683
28684 document.body.removeChild(iframe);
28685
28686 return res;
28687};
28688
28689Script.prototype.runInThisContext = function () {
28690 return eval(this.code); // maybe...
28691};
28692
28693Script.prototype.runInNewContext = function (context) {
28694 var ctx = Script.createContext(context);
28695 var res = this.runInContext(ctx);
28696
28697 if (context) {
28698 forEach(Object_keys(ctx), function (key) {
28699 context[key] = ctx[key];
28700 });
28701 }
28702
28703 return res;
28704};
28705
28706forEach(Object_keys(Script.prototype), function (name) {
28707 exports[name] = Script[name] = function (code) {
28708 var s = Script(code);
28709 return s[name].apply(s, [].slice.call(arguments, 1));
28710 };
28711});
28712
28713exports.isContext = function (context) {
28714 return context instanceof Context;
28715};
28716
28717exports.createScript = function (code) {
28718 return exports.Script(code);
28719};
28720
28721exports.createContext = Script.createContext = function (context) {
28722 var copy = new Context();
28723 if(typeof context === 'object') {
28724 forEach(Object_keys(context), function (key) {
28725 copy[key] = context[key];
28726 });
28727 }
28728 return copy;
28729};
28730
28731},{}]},{},[1])(1)
28732});
diff --git a/src/js/index.js b/src/js/index.js
index fff1e40..f3302a6 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -488,9 +488,16 @@
488 function calcBip32RootKeyFromSeed(phrase, passphrase) { 488 function calcBip32RootKeyFromSeed(phrase, passphrase) {
489 seed = mnemonic.toSeed(phrase, passphrase); 489 seed = mnemonic.toSeed(phrase, passphrase);
490 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network); 490 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
491 if(isGRS())
492 bip32RootKey = groestlcoinjs.HDNode.fromSeedHex(seed, network);
493
491 } 494 }
492 495
493 function calcBip32RootKeyFromBase58(rootKeyBase58) { 496 function calcBip32RootKeyFromBase58(rootKeyBase58) {
497 if(isGRS()) {
498 calcBip32RootKeyFromBase58GRS(rootKeyBase58);
499 return;
500 }
494 // try parsing with various segwit network params since this extended 501 // try parsing with various segwit network params since this extended
495 // key may be from any one of them. 502 // key may be from any one of them.
496 if (networkHasSegwit()) { 503 if (networkHasSegwit()) {
@@ -525,6 +532,41 @@
525 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network); 532 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
526 } 533 }
527 534
535 function calcBip32RootKeyFromBase58GRS(rootKeyBase58) {
536 // try parsing with various segwit network params since this extended
537 // key may be from any one of them.
538 if (networkHasSegwit()) {
539 var n = network;
540 if ("baseNetwork" in n) {
541 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
542 }
543 // try parsing using base network params
544 try {
545 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
546 return;
547 }
548 catch (e) {}
549 // try parsing using p2wpkh params
550 if ("p2wpkh" in n) {
551 try {
552 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
553 return;
554 }
555 catch (e) {}
556 }
557 // try parsing using p2wpkh-in-p2sh network params
558 if ("p2wpkhInP2sh" in n) {
559 try {
560 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
561 return;
562 }
563 catch (e) {}
564 }
565 }
566 // try the network params as currently specified
567 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
568 }
569
528 function calcBip32ExtendedKey(path) { 570 function calcBip32ExtendedKey(path) {
529 // Check there's a root key to derive from 571 // Check there's a root key to derive from
530 if (!bip32RootKey) { 572 if (!bip32RootKey) {
@@ -595,6 +637,9 @@
595 } 637 }
596 638
597 function validateRootKey(rootKeyBase58) { 639 function validateRootKey(rootKeyBase58) {
640 if(isGRS())
641 return validateRootKeyGRS(rootKeyBase58);
642
598 // try various segwit network params since this extended key may be from 643 // try various segwit network params since this extended key may be from
599 // any one of them. 644 // any one of them.
600 if (networkHasSegwit()) { 645 if (networkHasSegwit()) {
@@ -635,6 +680,47 @@
635 return ""; 680 return "";
636 } 681 }
637 682
683 function validateRootKeyGRS(rootKeyBase58) {
684 // try various segwit network params since this extended key may be from
685 // any one of them.
686 if (networkHasSegwit()) {
687 var n = network;
688 if ("baseNetwork" in n) {
689 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
690 }
691 // try parsing using base network params
692 try {
693 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
694 return "";
695 }
696 catch (e) {}
697 // try parsing using p2wpkh params
698 if ("p2wpkh" in n) {
699 try {
700 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
701 return "";
702 }
703 catch (e) {}
704 }
705 // try parsing using p2wpkh-in-p2sh network params
706 if ("p2wpkhInP2sh" in n) {
707 try {
708 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
709 return "";
710 }
711 catch (e) {}
712 }
713 }
714 // try the network params as currently specified
715 try {
716 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
717 }
718 catch (e) {
719 return "Invalid root key";
720 }
721 return "";
722 }
723
638 function getDerivationPath() { 724 function getDerivationPath() {
639 if (bip44TabSelected()) { 725 if (bip44TabSelected()) {
640 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); 726 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -745,6 +831,10 @@
745 return false; 831 return false;
746 } 832 }
747 833
834 function isGRS() {
835 return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
836 }
837
748 function displayBip44Info() { 838 function displayBip44Info() {
749 // Get the derivation path for the account 839 // Get the derivation path for the account
750 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); 840 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -888,6 +978,9 @@
888 var useUncompressed = useBip38; 978 var useUncompressed = useBip38;
889 if (useUncompressed) { 979 if (useUncompressed) {
890 keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false }); 980 keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false });
981 if(isGRS())
982 keyPair = new groestlcoinjs.ECPair(keyPair.d, null, { network: network, compressed: false });
983
891 } 984 }
892 // get address 985 // get address
893 var address = keyPair.getAddress().toString(); 986 var address = keyPair.getAddress().toString();
@@ -898,9 +991,14 @@
898 privkey = keyPair.toWIF(); 991 privkey = keyPair.toWIF();
899 // BIP38 encode private key if required 992 // BIP38 encode private key if required
900 if (useBip38) { 993 if (useBip38) {
901 privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) { 994 if(isGRS())
902 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index); 995 privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
903 }); 996 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
997 }, null, networks[DOM.network.val()].name.includes("Testnet"));
998 else
999 privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
1000 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
1001 });
904 } 1002 }
905 } 1003 }
906 // get pubkey 1004 // get pubkey
@@ -1010,6 +1108,23 @@
1010 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32)); 1108 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
1011 } 1109 }
1012 1110
1111 //Groestlcoin Addresses are different
1112 if(isGRS()) {
1113
1114 if (isSegwit) {
1115 if (!segwitAvailable) {
1116 return;
1117 }
1118 if (isP2wpkh) {
1119 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1120 }
1121 else if (isP2wpkhInP2sh) {
1122 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1123 }
1124 }
1125 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1126 }
1127
1013 addAddressToList(indexText, address, pubkey, privkey); 1128 addAddressToList(indexText, address, pubkey, privkey);
1014 if (isLast) { 1129 if (isLast) {
1015 hidePending(); 1130 hidePending();
@@ -2192,6 +2307,20 @@
2192 }, 2307 },
2193 }, 2308 },
2194 { 2309 {
2310 name: "GRS - Groestlcoin",
2311 onSelect: function() {
2312 network = bitcoinjs.bitcoin.networks.groestlcoin;
2313 setHdCoin(17);
2314 },
2315 },
2316 {
2317 name: "GRS - Groestlcoin Testnet",
2318 onSelect: function() {
2319 network = bitcoinjs.bitcoin.networks.groestlcointestnet;
2320 setHdCoin(1);
2321 },
2322 },
2323 {
2195 name: "HNC - Helleniccoin", 2324 name: "HNC - Helleniccoin",
2196 onSelect: function() { 2325 onSelect: function() {
2197 network = bitcoinjs.bitcoin.networks.helleniccoin; 2326 network = bitcoinjs.bitcoin.networks.helleniccoin;
diff --git a/src/js/segwit-parameters.js b/src/js/segwit-parameters.js
index 2f729f8..58c9f95 100644
--- a/src/js/segwit-parameters.js
+++ b/src/js/segwit-parameters.js
@@ -262,4 +262,57 @@ bitcoinjs.bitcoin.networks.cpuchain.p2wpkhInP2sh = {
262 scriptHash: 0x1e, 262 scriptHash: 0x1e,
263 wif: 0x80, 263 wif: 0x80,
264}; 264};
265
266bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = {
267 baseNetwork: "groestlcoin",
268 messagePrefix: '\x19GroestlCoin Signed Message:\n',
269 bech32: 'grs',
270 bip32: {
271 public: 0x04b24746,
272 private: 0x04b2430c
273 },
274 pubKeyHash: 0x24,
275 scriptHash: 0x05,
276 wif: 0x80,
277};
278
279bitcoinjs.bitcoin.networks.groestlcointestnet.p2wpkh = {
280 baseNetwork: "groestlcointestnet",
281 messagePrefix: '\x19GroestlCoin Signed Message:\n',
282 bech32: 'tgrs',
283 bip32: {
284 public: 0x045f1cf6,
285 private: 0x045f18bc
286 },
287 pubKeyHash: 0x6f,
288 scriptHash: 0xc4,
289 wif: 0xef
290};
291
292bitcoinjs.bitcoin.networks.groestlcoin.p2wpkhInP2sh = {
293 baseNetwork: "groestlcoin",
294 messagePrefix: '\x19GroestlCoin Signed Message:\n',
295 bech32: 'grs',
296 bip32: {
297 public: 0x049d7cb2,
298 private: 0x049d7878
299 },
300 pubKeyHash: 0x24,
301 scriptHash: 0x05,
302 wif: 0x80,
303};
304
305bitcoinjs.bitcoin.networks.groestlcointestnet.p2wpkhInP2sh = {
306 baseNetwork: "groestlcointestnet",
307 messagePrefix: '\x19GroestlCoin Signed Message:\n',
308 bech32: 'tgrs',
309 bip32: {
310 public: 0x044a5262,
311 private: 0x044a4e28
312 },
313 pubKeyHash: 0x6f,
314 scriptHash: 0xc4,
315 wif: 0xef
316};
317
265})(); 318})();