aboutsummaryrefslogtreecommitdiff
path: root/src/js/groestlcoinjs-3.3.2.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/groestlcoinjs-3.3.2.js')
-rw-r--r--src/js/groestlcoinjs-3.3.2.js17951
1 files changed, 17951 insertions, 0 deletions
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});