]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/groestlcoinjs-bip38-2.0.2.js
Add Groestlcoin
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / groestlcoinjs-bip38-2.0.2.js
1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.groestlcoinjsBip38 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2 var aes = require('browserify-aes')
3 var assert = require('assert')
4 var Buffer = require('safe-buffer').Buffer
5 var bs58check = require('bs58check')
6 var bs58grscheck = require('bs58grscheck')
7 var createHash = require('create-hash')
8 var scrypt = require('scryptsy')
9 var xor = require('buffer-xor/inplace')
10
11 var ecurve = require('ecurve')
12 var curve = ecurve.getCurveByName('secp256k1')
13
14 var BigInteger = require('bigi')
15
16 // constants
17 var SCRYPT_PARAMS = {
18 N: 16384, // specified by BIP38
19 r: 8,
20 p: 8
21 }
22 var NULL = Buffer.alloc(0)
23
24 function hash160 (buffer) {
25 return createHash('rmd160').update(
26 createHash('sha256').update(buffer).digest()
27 ).digest()
28 }
29
30 function hash256 (buffer) {
31 return createHash('sha256').update(
32 createHash('sha256').update(buffer).digest()
33 ).digest()
34 }
35
36 function getAddress (d, compressed, testnet) {
37 var Q = curve.G.multiply(d).getEncoded(compressed)
38 var hash = hash160(Q)
39 var payload = Buffer.allocUnsafe(21)
40 payload.writeUInt8(testnet ? 0x6f : 0x24, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38
41 hash.copy(payload, 1)
42
43 return bs58grscheck.encode(payload)
44 }
45
46 function encryptRaw (buffer, compressed, passphrase, progressCallback, scryptParams, testnet) {
47 if (buffer.length !== 32) throw new Error('Invalid private key length')
48 scryptParams = scryptParams || SCRYPT_PARAMS
49
50 var d = BigInteger.fromBuffer(buffer)
51 var address = getAddress(d, compressed, testnet)
52 var secret = Buffer.from(passphrase, 'utf8')
53 var salt = hash256(address).slice(0, 4)
54
55 var N = scryptParams.N
56 var r = scryptParams.r
57 var p = scryptParams.p
58
59 var scryptBuf = scrypt(secret, salt, N, r, p, 64, progressCallback)
60 var derivedHalf1 = scryptBuf.slice(0, 32)
61 var derivedHalf2 = scryptBuf.slice(32, 64)
62
63 var xorBuf = xor(derivedHalf1, buffer)
64 var cipher = aes.createCipheriv('aes-256-ecb', derivedHalf2, NULL)
65 cipher.setAutoPadding(false)
66 cipher.end(xorBuf)
67
68 var cipherText = cipher.read()
69
70 // 0x01 | 0x42 | flagByte | salt (4) | cipherText (32)
71 var result = Buffer.allocUnsafe(7 + 32)
72 result.writeUInt8(0x01, 0)
73 result.writeUInt8(0x42, 1)
74 result.writeUInt8(compressed ? 0xe0 : 0xc0, 2)
75 salt.copy(result, 3)
76 cipherText.copy(result, 7)
77
78 return result
79 }
80
81 function encrypt (buffer, compressed, passphrase, progressCallback, scryptParams, testnet) {
82 return bs58check.encode(encryptRaw(buffer, compressed, passphrase, progressCallback, scryptParams, testnet))
83 }
84
85 // some of the techniques borrowed from: https://github.com/pointbiz/bitaddress.org
86 function decryptRaw (buffer, passphrase, progressCallback, scryptParams, testnet) {
87 // 39 bytes: 2 bytes prefix, 37 bytes payload
88 if (buffer.length !== 39) throw new Error('Invalid BIP38 data length')
89 if (buffer.readUInt8(0) !== 0x01) throw new Error('Invalid BIP38 prefix')
90 scryptParams = scryptParams || SCRYPT_PARAMS
91
92 // check if BIP38 EC multiply
93 var type = buffer.readUInt8(1)
94 if (type === 0x43) return decryptECMult(buffer, passphrase, progressCallback, scryptParams)
95 if (type !== 0x42) throw new Error('Invalid BIP38 type')
96
97 passphrase = Buffer.from(passphrase, 'utf8')
98
99 var flagByte = buffer.readUInt8(2)
100 var compressed = flagByte === 0xe0
101 if (!compressed && flagByte !== 0xc0) throw new Error('Invalid BIP38 compression flag')
102
103 var N = scryptParams.N
104 var r = scryptParams.r
105 var p = scryptParams.p
106
107 var salt = buffer.slice(3, 7)
108 var scryptBuf = scrypt(passphrase, salt, N, r, p, 64, progressCallback)
109 var derivedHalf1 = scryptBuf.slice(0, 32)
110 var derivedHalf2 = scryptBuf.slice(32, 64)
111
112 var privKeyBuf = buffer.slice(7, 7 + 32)
113 var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, NULL)
114 decipher.setAutoPadding(false)
115 decipher.end(privKeyBuf)
116
117 var plainText = decipher.read()
118 var privateKey = xor(derivedHalf1, plainText)
119
120 // verify salt matches address
121 var d = BigInteger.fromBuffer(privateKey)
122 var address = getAddress(d, compressed, address)
123 var checksum = hash256(address).slice(0, 4)
124 assert.deepEqual(salt, checksum)
125
126 return {
127 privateKey: privateKey,
128 compressed: compressed
129 }
130 }
131
132 function decrypt (string, passphrase, progressCallback, scryptParams, testnet) {
133 return decryptRaw(bs58check.decode(string), passphrase, progressCallback, scryptParams, testnet)
134 }
135
136 function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
137 passphrase = Buffer.from(passphrase, 'utf8')
138 buffer = buffer.slice(1) // FIXME: we can avoid this
139 scryptParams = scryptParams || SCRYPT_PARAMS
140
141 var flag = buffer.readUInt8(1)
142 var compressed = (flag & 0x20) !== 0
143 var hasLotSeq = (flag & 0x04) !== 0
144
145 assert.equal((flag & 0x24), flag, 'Invalid private key.')
146
147 var addressHash = buffer.slice(2, 6)
148 var ownerEntropy = buffer.slice(6, 14)
149 var ownerSalt
150
151 // 4 bytes ownerSalt if 4 bytes lot/sequence
152 if (hasLotSeq) {
153 ownerSalt = ownerEntropy.slice(0, 4)
154
155 // else, 8 bytes ownerSalt
156 } else {
157 ownerSalt = ownerEntropy
158 }
159
160 var encryptedPart1 = buffer.slice(14, 22) // First 8 bytes
161 var encryptedPart2 = buffer.slice(22, 38) // 16 bytes
162
163 var N = scryptParams.N
164 var r = scryptParams.r
165 var p = scryptParams.p
166 var preFactor = scrypt(passphrase, ownerSalt, N, r, p, 32, progressCallback)
167
168 var passFactor
169 if (hasLotSeq) {
170 var hashTarget = Buffer.concat([preFactor, ownerEntropy])
171 passFactor = hash256(hashTarget)
172 } else {
173 passFactor = preFactor
174 }
175
176 var passInt = BigInteger.fromBuffer(passFactor)
177 var passPoint = curve.G.multiply(passInt).getEncoded(true)
178
179 var seedBPass = scrypt(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64)
180 var derivedHalf1 = seedBPass.slice(0, 32)
181 var derivedHalf2 = seedBPass.slice(32, 64)
182
183 var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0))
184 decipher.setAutoPadding(false)
185 decipher.end(encryptedPart2)
186
187 var decryptedPart2 = decipher.read()
188 var tmp = xor(decryptedPart2, derivedHalf1.slice(16, 32))
189 var seedBPart2 = tmp.slice(8, 16)
190
191 var decipher2 = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0))
192 decipher2.setAutoPadding(false)
193 decipher2.write(encryptedPart1) // first 8 bytes
194 decipher2.end(tmp.slice(0, 8)) // last 8 bytes
195
196 var seedBPart1 = xor(decipher2.read(), derivedHalf1.slice(0, 16))
197 var seedB = Buffer.concat([seedBPart1, seedBPart2], 24)
198 var factorB = BigInteger.fromBuffer(hash256(seedB))
199
200 // d = passFactor * factorB (mod n)
201 var d = passInt.multiply(factorB).mod(curve.n)
202
203 return {
204 privateKey: d.toBuffer(32),
205 compressed: compressed
206 }
207 }
208
209 function verify (string) {
210 var decoded = bs58grscheck.decodeUnsafe(string)
211 if (!decoded) return false
212
213 if (decoded.length !== 39) return false
214 if (decoded.readUInt8(0) !== 0x01) return false
215
216 var type = decoded.readUInt8(1)
217 var flag = decoded.readUInt8(2)
218
219 // encrypted WIF
220 if (type === 0x42) {
221 if (flag !== 0xc0 && flag !== 0xe0) return false
222
223 // EC mult
224 } else if (type === 0x43) {
225 if ((flag & ~0x24)) return false
226 } else {
227 return false
228 }
229
230 return true
231 }
232
233 module.exports = {
234 decrypt: decrypt,
235 decryptECMult: decryptECMult,
236 decryptRaw: decryptRaw,
237 encrypt: encrypt,
238 encryptRaw: encryptRaw,
239 verify: verify
240 }
241
242 },{"assert":74,"bigi":5,"browserify-aes":9,"bs58check":26,"bs58grscheck":28,"buffer-xor/inplace":30,"create-hash":32,"ecurve":35,"safe-buffer":47,"scryptsy":48}],2:[function(require,module,exports){
243 'use strict'
244 // base-x encoding / decoding
245 // Copyright (c) 2018 base-x contributors
246 // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
247 // Distributed under the MIT software license, see the accompanying
248 // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
249 // @ts-ignore
250 var _Buffer = require('safe-buffer').Buffer
251 function base (ALPHABET) {
252 if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
253 var BASE_MAP = new Uint8Array(256)
254 BASE_MAP.fill(255)
255 for (var i = 0; i < ALPHABET.length; i++) {
256 var x = ALPHABET.charAt(i)
257 var xc = x.charCodeAt(0)
258 if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
259 BASE_MAP[xc] = i
260 }
261 var BASE = ALPHABET.length
262 var LEADER = ALPHABET.charAt(0)
263 var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
264 var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
265 function encode (source) {
266 if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') }
267 if (source.length === 0) { return '' }
268 // Skip & count leading zeroes.
269 var zeroes = 0
270 var length = 0
271 var pbegin = 0
272 var pend = source.length
273 while (pbegin !== pend && source[pbegin] === 0) {
274 pbegin++
275 zeroes++
276 }
277 // Allocate enough space in big-endian base58 representation.
278 var size = ((pend - pbegin) * iFACTOR + 1) >>> 0
279 var b58 = new Uint8Array(size)
280 // Process the bytes.
281 while (pbegin !== pend) {
282 var carry = source[pbegin]
283 // Apply "b58 = b58 * 256 + ch".
284 var i = 0
285 for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
286 carry += (256 * b58[it1]) >>> 0
287 b58[it1] = (carry % BASE) >>> 0
288 carry = (carry / BASE) >>> 0
289 }
290 if (carry !== 0) { throw new Error('Non-zero carry') }
291 length = i
292 pbegin++
293 }
294 // Skip leading zeroes in base58 result.
295 var it2 = size - length
296 while (it2 !== size && b58[it2] === 0) {
297 it2++
298 }
299 // Translate the result into a string.
300 var str = LEADER.repeat(zeroes)
301 for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) }
302 return str
303 }
304 function decodeUnsafe (source) {
305 if (typeof source !== 'string') { throw new TypeError('Expected String') }
306 if (source.length === 0) { return _Buffer.alloc(0) }
307 var psz = 0
308 // Skip leading spaces.
309 if (source[psz] === ' ') { return }
310 // Skip and count leading '1's.
311 var zeroes = 0
312 var length = 0
313 while (source[psz] === LEADER) {
314 zeroes++
315 psz++
316 }
317 // Allocate enough space in big-endian base256 representation.
318 var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
319 var b256 = new Uint8Array(size)
320 // Process the characters.
321 while (source[psz]) {
322 // Decode character
323 var carry = BASE_MAP[source.charCodeAt(psz)]
324 // Invalid character
325 if (carry === 255) { return }
326 var i = 0
327 for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
328 carry += (BASE * b256[it3]) >>> 0
329 b256[it3] = (carry % 256) >>> 0
330 carry = (carry / 256) >>> 0
331 }
332 if (carry !== 0) { throw new Error('Non-zero carry') }
333 length = i
334 psz++
335 }
336 // Skip trailing spaces.
337 if (source[psz] === ' ') { return }
338 // Skip leading zeroes in b256.
339 var it4 = size - length
340 while (it4 !== size && b256[it4] === 0) {
341 it4++
342 }
343 var vch = _Buffer.allocUnsafe(zeroes + (size - it4))
344 vch.fill(0x00, 0, zeroes)
345 var j = zeroes
346 while (it4 !== size) {
347 vch[j++] = b256[it4++]
348 }
349 return vch
350 }
351 function decode (string) {
352 var buffer = decodeUnsafe(string)
353 if (buffer) { return buffer }
354 throw new Error('Non-base' + BASE + ' character')
355 }
356 return {
357 encode: encode,
358 decodeUnsafe: decodeUnsafe,
359 decode: decode
360 }
361 }
362 module.exports = base
363
364 },{"safe-buffer":47}],3:[function(require,module,exports){
365 // (public) Constructor
366 function BigInteger(a, b, c) {
367 if (!(this instanceof BigInteger))
368 return new BigInteger(a, b, c)
369
370 if (a != null) {
371 if ("number" == typeof a) this.fromNumber(a, b, c)
372 else if (b == null && "string" != typeof a) this.fromString(a, 256)
373 else this.fromString(a, b)
374 }
375 }
376
377 var proto = BigInteger.prototype
378
379 // duck-typed isBigInteger
380 proto.__bigi = require('../package.json').version
381 BigInteger.isBigInteger = function (obj, check_ver) {
382 return obj && obj.__bigi && (!check_ver || obj.__bigi === proto.__bigi)
383 }
384
385 // Bits per digit
386 var dbits
387
388 // am: Compute w_j += (x*this_i), propagate carries,
389 // c is initial carry, returns final carry.
390 // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
391 // We need to select the fastest one that works in this environment.
392
393 // am1: use a single mult and divide to get the high bits,
394 // max digit bits should be 26 because
395 // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
396 function am1(i, x, w, j, c, n) {
397 while (--n >= 0) {
398 var v = x * this[i++] + w[j] + c
399 c = Math.floor(v / 0x4000000)
400 w[j++] = v & 0x3ffffff
401 }
402 return c
403 }
404 // am2 avoids a big mult-and-extract completely.
405 // Max digit bits should be <= 30 because we do bitwise ops
406 // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
407 function am2(i, x, w, j, c, n) {
408 var xl = x & 0x7fff,
409 xh = x >> 15
410 while (--n >= 0) {
411 var l = this[i] & 0x7fff
412 var h = this[i++] >> 15
413 var m = xh * l + h * xl
414 l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff)
415 c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30)
416 w[j++] = l & 0x3fffffff
417 }
418 return c
419 }
420 // Alternately, set max digit bits to 28 since some
421 // browsers slow down when dealing with 32-bit numbers.
422 function am3(i, x, w, j, c, n) {
423 var xl = x & 0x3fff,
424 xh = x >> 14
425 while (--n >= 0) {
426 var l = this[i] & 0x3fff
427 var h = this[i++] >> 14
428 var m = xh * l + h * xl
429 l = xl * l + ((m & 0x3fff) << 14) + w[j] + c
430 c = (l >> 28) + (m >> 14) + xh * h
431 w[j++] = l & 0xfffffff
432 }
433 return c
434 }
435
436 // wtf?
437 BigInteger.prototype.am = am1
438 dbits = 26
439
440 BigInteger.prototype.DB = dbits
441 BigInteger.prototype.DM = ((1 << dbits) - 1)
442 var DV = BigInteger.prototype.DV = (1 << dbits)
443
444 var BI_FP = 52
445 BigInteger.prototype.FV = Math.pow(2, BI_FP)
446 BigInteger.prototype.F1 = BI_FP - dbits
447 BigInteger.prototype.F2 = 2 * dbits - BI_FP
448
449 // Digit conversions
450 var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"
451 var BI_RC = new Array()
452 var rr, vv
453 rr = "0".charCodeAt(0)
454 for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv
455 rr = "a".charCodeAt(0)
456 for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv
457 rr = "A".charCodeAt(0)
458 for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv
459
460 function int2char(n) {
461 return BI_RM.charAt(n)
462 }
463
464 function intAt(s, i) {
465 var c = BI_RC[s.charCodeAt(i)]
466 return (c == null) ? -1 : c
467 }
468
469 // (protected) copy this to r
470 function bnpCopyTo(r) {
471 for (var i = this.t - 1; i >= 0; --i) r[i] = this[i]
472 r.t = this.t
473 r.s = this.s
474 }
475
476 // (protected) set from integer value x, -DV <= x < DV
477 function bnpFromInt(x) {
478 this.t = 1
479 this.s = (x < 0) ? -1 : 0
480 if (x > 0) this[0] = x
481 else if (x < -1) this[0] = x + DV
482 else this.t = 0
483 }
484
485 // return bigint initialized to value
486 function nbv(i) {
487 var r = new BigInteger()
488 r.fromInt(i)
489 return r
490 }
491
492 // (protected) set from string and radix
493 function bnpFromString(s, b) {
494 var self = this
495
496 var k
497 if (b == 16) k = 4
498 else if (b == 8) k = 3
499 else if (b == 256) k = 8; // byte array
500 else if (b == 2) k = 1
501 else if (b == 32) k = 5
502 else if (b == 4) k = 2
503 else {
504 self.fromRadix(s, b)
505 return
506 }
507 self.t = 0
508 self.s = 0
509 var i = s.length,
510 mi = false,
511 sh = 0
512 while (--i >= 0) {
513 var x = (k == 8) ? s[i] & 0xff : intAt(s, i)
514 if (x < 0) {
515 if (s.charAt(i) == "-") mi = true
516 continue
517 }
518 mi = false
519 if (sh == 0)
520 self[self.t++] = x
521 else if (sh + k > self.DB) {
522 self[self.t - 1] |= (x & ((1 << (self.DB - sh)) - 1)) << sh
523 self[self.t++] = (x >> (self.DB - sh))
524 } else
525 self[self.t - 1] |= x << sh
526 sh += k
527 if (sh >= self.DB) sh -= self.DB
528 }
529 if (k == 8 && (s[0] & 0x80) != 0) {
530 self.s = -1
531 if (sh > 0) self[self.t - 1] |= ((1 << (self.DB - sh)) - 1) << sh
532 }
533 self.clamp()
534 if (mi) BigInteger.ZERO.subTo(self, self)
535 }
536
537 // (protected) clamp off excess high words
538 function bnpClamp() {
539 var c = this.s & this.DM
540 while (this.t > 0 && this[this.t - 1] == c)--this.t
541 }
542
543 // (public) return string representation in given radix
544 function bnToString(b) {
545 var self = this
546 if (self.s < 0) return "-" + self.negate()
547 .toString(b)
548 var k
549 if (b == 16) k = 4
550 else if (b == 8) k = 3
551 else if (b == 2) k = 1
552 else if (b == 32) k = 5
553 else if (b == 4) k = 2
554 else return self.toRadix(b)
555 var km = (1 << k) - 1,
556 d, m = false,
557 r = "",
558 i = self.t
559 var p = self.DB - (i * self.DB) % k
560 if (i-- > 0) {
561 if (p < self.DB && (d = self[i] >> p) > 0) {
562 m = true
563 r = int2char(d)
564 }
565 while (i >= 0) {
566 if (p < k) {
567 d = (self[i] & ((1 << p) - 1)) << (k - p)
568 d |= self[--i] >> (p += self.DB - k)
569 } else {
570 d = (self[i] >> (p -= k)) & km
571 if (p <= 0) {
572 p += self.DB
573 --i
574 }
575 }
576 if (d > 0) m = true
577 if (m) r += int2char(d)
578 }
579 }
580 return m ? r : "0"
581 }
582
583 // (public) -this
584 function bnNegate() {
585 var r = new BigInteger()
586 BigInteger.ZERO.subTo(this, r)
587 return r
588 }
589
590 // (public) |this|
591 function bnAbs() {
592 return (this.s < 0) ? this.negate() : this
593 }
594
595 // (public) return + if this > a, - if this < a, 0 if equal
596 function bnCompareTo(a) {
597 var r = this.s - a.s
598 if (r != 0) return r
599 var i = this.t
600 r = i - a.t
601 if (r != 0) return (this.s < 0) ? -r : r
602 while (--i >= 0)
603 if ((r = this[i] - a[i]) != 0) return r
604 return 0
605 }
606
607 // returns bit length of the integer x
608 function nbits(x) {
609 var r = 1,
610 t
611 if ((t = x >>> 16) != 0) {
612 x = t
613 r += 16
614 }
615 if ((t = x >> 8) != 0) {
616 x = t
617 r += 8
618 }
619 if ((t = x >> 4) != 0) {
620 x = t
621 r += 4
622 }
623 if ((t = x >> 2) != 0) {
624 x = t
625 r += 2
626 }
627 if ((t = x >> 1) != 0) {
628 x = t
629 r += 1
630 }
631 return r
632 }
633
634 // (public) return the number of bits in "this"
635 function bnBitLength() {
636 if (this.t <= 0) return 0
637 return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM))
638 }
639
640 // (public) return the number of bytes in "this"
641 function bnByteLength() {
642 return this.bitLength() >> 3
643 }
644
645 // (protected) r = this << n*DB
646 function bnpDLShiftTo(n, r) {
647 var i
648 for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i]
649 for (i = n - 1; i >= 0; --i) r[i] = 0
650 r.t = this.t + n
651 r.s = this.s
652 }
653
654 // (protected) r = this >> n*DB
655 function bnpDRShiftTo(n, r) {
656 for (var i = n; i < this.t; ++i) r[i - n] = this[i]
657 r.t = Math.max(this.t - n, 0)
658 r.s = this.s
659 }
660
661 // (protected) r = this << n
662 function bnpLShiftTo(n, r) {
663 var self = this
664 var bs = n % self.DB
665 var cbs = self.DB - bs
666 var bm = (1 << cbs) - 1
667 var ds = Math.floor(n / self.DB),
668 c = (self.s << bs) & self.DM,
669 i
670 for (i = self.t - 1; i >= 0; --i) {
671 r[i + ds + 1] = (self[i] >> cbs) | c
672 c = (self[i] & bm) << bs
673 }
674 for (i = ds - 1; i >= 0; --i) r[i] = 0
675 r[ds] = c
676 r.t = self.t + ds + 1
677 r.s = self.s
678 r.clamp()
679 }
680
681 // (protected) r = this >> n
682 function bnpRShiftTo(n, r) {
683 var self = this
684 r.s = self.s
685 var ds = Math.floor(n / self.DB)
686 if (ds >= self.t) {
687 r.t = 0
688 return
689 }
690 var bs = n % self.DB
691 var cbs = self.DB - bs
692 var bm = (1 << bs) - 1
693 r[0] = self[ds] >> bs
694 for (var i = ds + 1; i < self.t; ++i) {
695 r[i - ds - 1] |= (self[i] & bm) << cbs
696 r[i - ds] = self[i] >> bs
697 }
698 if (bs > 0) r[self.t - ds - 1] |= (self.s & bm) << cbs
699 r.t = self.t - ds
700 r.clamp()
701 }
702
703 // (protected) r = this - a
704 function bnpSubTo(a, r) {
705 var self = this
706 var i = 0,
707 c = 0,
708 m = Math.min(a.t, self.t)
709 while (i < m) {
710 c += self[i] - a[i]
711 r[i++] = c & self.DM
712 c >>= self.DB
713 }
714 if (a.t < self.t) {
715 c -= a.s
716 while (i < self.t) {
717 c += self[i]
718 r[i++] = c & self.DM
719 c >>= self.DB
720 }
721 c += self.s
722 } else {
723 c += self.s
724 while (i < a.t) {
725 c -= a[i]
726 r[i++] = c & self.DM
727 c >>= self.DB
728 }
729 c -= a.s
730 }
731 r.s = (c < 0) ? -1 : 0
732 if (c < -1) r[i++] = self.DV + c
733 else if (c > 0) r[i++] = c
734 r.t = i
735 r.clamp()
736 }
737
738 // (protected) r = this * a, r != this,a (HAC 14.12)
739 // "this" should be the larger one if appropriate.
740 function bnpMultiplyTo(a, r) {
741 var x = this.abs(),
742 y = a.abs()
743 var i = x.t
744 r.t = i + y.t
745 while (--i >= 0) r[i] = 0
746 for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t)
747 r.s = 0
748 r.clamp()
749 if (this.s != a.s) BigInteger.ZERO.subTo(r, r)
750 }
751
752 // (protected) r = this^2, r != this (HAC 14.16)
753 function bnpSquareTo(r) {
754 var x = this.abs()
755 var i = r.t = 2 * x.t
756 while (--i >= 0) r[i] = 0
757 for (i = 0; i < x.t - 1; ++i) {
758 var c = x.am(i, x[i], r, 2 * i, 0, 1)
759 if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
760 r[i + x.t] -= x.DV
761 r[i + x.t + 1] = 1
762 }
763 }
764 if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1)
765 r.s = 0
766 r.clamp()
767 }
768
769 // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
770 // r != q, this != m. q or r may be null.
771 function bnpDivRemTo(m, q, r) {
772 var self = this
773 var pm = m.abs()
774 if (pm.t <= 0) return
775 var pt = self.abs()
776 if (pt.t < pm.t) {
777 if (q != null) q.fromInt(0)
778 if (r != null) self.copyTo(r)
779 return
780 }
781 if (r == null) r = new BigInteger()
782 var y = new BigInteger(),
783 ts = self.s,
784 ms = m.s
785 var nsh = self.DB - nbits(pm[pm.t - 1]); // normalize modulus
786 if (nsh > 0) {
787 pm.lShiftTo(nsh, y)
788 pt.lShiftTo(nsh, r)
789 } else {
790 pm.copyTo(y)
791 pt.copyTo(r)
792 }
793 var ys = y.t
794 var y0 = y[ys - 1]
795 if (y0 == 0) return
796 var yt = y0 * (1 << self.F1) + ((ys > 1) ? y[ys - 2] >> self.F2 : 0)
797 var d1 = self.FV / yt,
798 d2 = (1 << self.F1) / yt,
799 e = 1 << self.F2
800 var i = r.t,
801 j = i - ys,
802 t = (q == null) ? new BigInteger() : q
803 y.dlShiftTo(j, t)
804 if (r.compareTo(t) >= 0) {
805 r[r.t++] = 1
806 r.subTo(t, r)
807 }
808 BigInteger.ONE.dlShiftTo(ys, t)
809 t.subTo(y, y); // "negative" y so we can replace sub with am later
810 while (y.t < ys) y[y.t++] = 0
811 while (--j >= 0) {
812 // Estimate quotient digit
813 var qd = (r[--i] == y0) ? self.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2)
814 if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
815 y.dlShiftTo(j, t)
816 r.subTo(t, r)
817 while (r[i] < --qd) r.subTo(t, r)
818 }
819 }
820 if (q != null) {
821 r.drShiftTo(ys, q)
822 if (ts != ms) BigInteger.ZERO.subTo(q, q)
823 }
824 r.t = ys
825 r.clamp()
826 if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
827 if (ts < 0) BigInteger.ZERO.subTo(r, r)
828 }
829
830 // (public) this mod a
831 function bnMod(a) {
832 var r = new BigInteger()
833 this.abs()
834 .divRemTo(a, null, r)
835 if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r)
836 return r
837 }
838
839 // Modular reduction using "classic" algorithm
840 function Classic(m) {
841 this.m = m
842 }
843
844 function cConvert(x) {
845 if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m)
846 else return x
847 }
848
849 function cRevert(x) {
850 return x
851 }
852
853 function cReduce(x) {
854 x.divRemTo(this.m, null, x)
855 }
856
857 function cMulTo(x, y, r) {
858 x.multiplyTo(y, r)
859 this.reduce(r)
860 }
861
862 function cSqrTo(x, r) {
863 x.squareTo(r)
864 this.reduce(r)
865 }
866
867 Classic.prototype.convert = cConvert
868 Classic.prototype.revert = cRevert
869 Classic.prototype.reduce = cReduce
870 Classic.prototype.mulTo = cMulTo
871 Classic.prototype.sqrTo = cSqrTo
872
873 // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
874 // justification:
875 // xy == 1 (mod m)
876 // xy = 1+km
877 // xy(2-xy) = (1+km)(1-km)
878 // x[y(2-xy)] = 1-k^2m^2
879 // x[y(2-xy)] == 1 (mod m^2)
880 // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
881 // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
882 // JS multiply "overflows" differently from C/C++, so care is needed here.
883 function bnpInvDigit() {
884 if (this.t < 1) return 0
885 var x = this[0]
886 if ((x & 1) == 0) return 0
887 var y = x & 3; // y == 1/x mod 2^2
888 y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
889 y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
890 y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
891 // last step - calculate inverse mod DV directly
892 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
893 y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
894 // we really want the negative inverse, and -DV < y < DV
895 return (y > 0) ? this.DV - y : -y
896 }
897
898 // Montgomery reduction
899 function Montgomery(m) {
900 this.m = m
901 this.mp = m.invDigit()
902 this.mpl = this.mp & 0x7fff
903 this.mph = this.mp >> 15
904 this.um = (1 << (m.DB - 15)) - 1
905 this.mt2 = 2 * m.t
906 }
907
908 // xR mod m
909 function montConvert(x) {
910 var r = new BigInteger()
911 x.abs()
912 .dlShiftTo(this.m.t, r)
913 r.divRemTo(this.m, null, r)
914 if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r)
915 return r
916 }
917
918 // x/R mod m
919 function montRevert(x) {
920 var r = new BigInteger()
921 x.copyTo(r)
922 this.reduce(r)
923 return r
924 }
925
926 // x = x/R mod m (HAC 14.32)
927 function montReduce(x) {
928 while (x.t <= this.mt2) // pad x so am has enough room later
929 x[x.t++] = 0
930 for (var i = 0; i < this.m.t; ++i) {
931 // faster way of calculating u0 = x[i]*mp mod DV
932 var j = x[i] & 0x7fff
933 var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM
934 // use am to combine the multiply-shift-add into one call
935 j = i + this.m.t
936 x[j] += this.m.am(0, u0, x, i, 0, this.m.t)
937 // propagate carry
938 while (x[j] >= x.DV) {
939 x[j] -= x.DV
940 x[++j]++
941 }
942 }
943 x.clamp()
944 x.drShiftTo(this.m.t, x)
945 if (x.compareTo(this.m) >= 0) x.subTo(this.m, x)
946 }
947
948 // r = "x^2/R mod m"; x != r
949 function montSqrTo(x, r) {
950 x.squareTo(r)
951 this.reduce(r)
952 }
953
954 // r = "xy/R mod m"; x,y != r
955 function montMulTo(x, y, r) {
956 x.multiplyTo(y, r)
957 this.reduce(r)
958 }
959
960 Montgomery.prototype.convert = montConvert
961 Montgomery.prototype.revert = montRevert
962 Montgomery.prototype.reduce = montReduce
963 Montgomery.prototype.mulTo = montMulTo
964 Montgomery.prototype.sqrTo = montSqrTo
965
966 // (protected) true iff this is even
967 function bnpIsEven() {
968 return ((this.t > 0) ? (this[0] & 1) : this.s) == 0
969 }
970
971 // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
972 function bnpExp(e, z) {
973 if (e > 0xffffffff || e < 1) return BigInteger.ONE
974 var r = new BigInteger(),
975 r2 = new BigInteger(),
976 g = z.convert(this),
977 i = nbits(e) - 1
978 g.copyTo(r)
979 while (--i >= 0) {
980 z.sqrTo(r, r2)
981 if ((e & (1 << i)) > 0) z.mulTo(r2, g, r)
982 else {
983 var t = r
984 r = r2
985 r2 = t
986 }
987 }
988 return z.revert(r)
989 }
990
991 // (public) this^e % m, 0 <= e < 2^32
992 function bnModPowInt(e, m) {
993 var z
994 if (e < 256 || m.isEven()) z = new Classic(m)
995 else z = new Montgomery(m)
996 return this.exp(e, z)
997 }
998
999 // protected
1000 proto.copyTo = bnpCopyTo
1001 proto.fromInt = bnpFromInt
1002 proto.fromString = bnpFromString
1003 proto.clamp = bnpClamp
1004 proto.dlShiftTo = bnpDLShiftTo
1005 proto.drShiftTo = bnpDRShiftTo
1006 proto.lShiftTo = bnpLShiftTo
1007 proto.rShiftTo = bnpRShiftTo
1008 proto.subTo = bnpSubTo
1009 proto.multiplyTo = bnpMultiplyTo
1010 proto.squareTo = bnpSquareTo
1011 proto.divRemTo = bnpDivRemTo
1012 proto.invDigit = bnpInvDigit
1013 proto.isEven = bnpIsEven
1014 proto.exp = bnpExp
1015
1016 // public
1017 proto.toString = bnToString
1018 proto.negate = bnNegate
1019 proto.abs = bnAbs
1020 proto.compareTo = bnCompareTo
1021 proto.bitLength = bnBitLength
1022 proto.byteLength = bnByteLength
1023 proto.mod = bnMod
1024 proto.modPowInt = bnModPowInt
1025
1026 // (public)
1027 function bnClone() {
1028 var r = new BigInteger()
1029 this.copyTo(r)
1030 return r
1031 }
1032
1033 // (public) return value as integer
1034 function bnIntValue() {
1035 if (this.s < 0) {
1036 if (this.t == 1) return this[0] - this.DV
1037 else if (this.t == 0) return -1
1038 } else if (this.t == 1) return this[0]
1039 else if (this.t == 0) return 0
1040 // assumes 16 < DB < 32
1041 return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]
1042 }
1043
1044 // (public) return value as byte
1045 function bnByteValue() {
1046 return (this.t == 0) ? this.s : (this[0] << 24) >> 24
1047 }
1048
1049 // (public) return value as short (assumes DB>=16)
1050 function bnShortValue() {
1051 return (this.t == 0) ? this.s : (this[0] << 16) >> 16
1052 }
1053
1054 // (protected) return x s.t. r^x < DV
1055 function bnpChunkSize(r) {
1056 return Math.floor(Math.LN2 * this.DB / Math.log(r))
1057 }
1058
1059 // (public) 0 if this == 0, 1 if this > 0
1060 function bnSigNum() {
1061 if (this.s < 0) return -1
1062 else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0
1063 else return 1
1064 }
1065
1066 // (protected) convert to radix string
1067 function bnpToRadix(b) {
1068 if (b == null) b = 10
1069 if (this.signum() == 0 || b < 2 || b > 36) return "0"
1070 var cs = this.chunkSize(b)
1071 var a = Math.pow(b, cs)
1072 var d = nbv(a),
1073 y = new BigInteger(),
1074 z = new BigInteger(),
1075 r = ""
1076 this.divRemTo(d, y, z)
1077 while (y.signum() > 0) {
1078 r = (a + z.intValue())
1079 .toString(b)
1080 .substr(1) + r
1081 y.divRemTo(d, y, z)
1082 }
1083 return z.intValue()
1084 .toString(b) + r
1085 }
1086
1087 // (protected) convert from radix string
1088 function bnpFromRadix(s, b) {
1089 var self = this
1090 self.fromInt(0)
1091 if (b == null) b = 10
1092 var cs = self.chunkSize(b)
1093 var d = Math.pow(b, cs),
1094 mi = false,
1095 j = 0,
1096 w = 0
1097 for (var i = 0; i < s.length; ++i) {
1098 var x = intAt(s, i)
1099 if (x < 0) {
1100 if (s.charAt(i) == "-" && self.signum() == 0) mi = true
1101 continue
1102 }
1103 w = b * w + x
1104 if (++j >= cs) {
1105 self.dMultiply(d)
1106 self.dAddOffset(w, 0)
1107 j = 0
1108 w = 0
1109 }
1110 }
1111 if (j > 0) {
1112 self.dMultiply(Math.pow(b, j))
1113 self.dAddOffset(w, 0)
1114 }
1115 if (mi) BigInteger.ZERO.subTo(self, self)
1116 }
1117
1118 // (protected) alternate constructor
1119 function bnpFromNumber(a, b, c) {
1120 var self = this
1121 if ("number" == typeof b) {
1122 // new BigInteger(int,int,RNG)
1123 if (a < 2) self.fromInt(1)
1124 else {
1125 self.fromNumber(a, c)
1126 if (!self.testBit(a - 1)) // force MSB set
1127 self.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, self)
1128 if (self.isEven()) self.dAddOffset(1, 0); // force odd
1129 while (!self.isProbablePrime(b)) {
1130 self.dAddOffset(2, 0)
1131 if (self.bitLength() > a) self.subTo(BigInteger.ONE.shiftLeft(a - 1), self)
1132 }
1133 }
1134 } else {
1135 // new BigInteger(int,RNG)
1136 var x = new Array(),
1137 t = a & 7
1138 x.length = (a >> 3) + 1
1139 b.nextBytes(x)
1140 if (t > 0) x[0] &= ((1 << t) - 1)
1141 else x[0] = 0
1142 self.fromString(x, 256)
1143 }
1144 }
1145
1146 // (public) convert to bigendian byte array
1147 function bnToByteArray() {
1148 var self = this
1149 var i = self.t,
1150 r = new Array()
1151 r[0] = self.s
1152 var p = self.DB - (i * self.DB) % 8,
1153 d, k = 0
1154 if (i-- > 0) {
1155 if (p < self.DB && (d = self[i] >> p) != (self.s & self.DM) >> p)
1156 r[k++] = d | (self.s << (self.DB - p))
1157 while (i >= 0) {
1158 if (p < 8) {
1159 d = (self[i] & ((1 << p) - 1)) << (8 - p)
1160 d |= self[--i] >> (p += self.DB - 8)
1161 } else {
1162 d = (self[i] >> (p -= 8)) & 0xff
1163 if (p <= 0) {
1164 p += self.DB
1165 --i
1166 }
1167 }
1168 if ((d & 0x80) != 0) d |= -256
1169 if (k === 0 && (self.s & 0x80) != (d & 0x80))++k
1170 if (k > 0 || d != self.s) r[k++] = d
1171 }
1172 }
1173 return r
1174 }
1175
1176 function bnEquals(a) {
1177 return (this.compareTo(a) == 0)
1178 }
1179
1180 function bnMin(a) {
1181 return (this.compareTo(a) < 0) ? this : a
1182 }
1183
1184 function bnMax(a) {
1185 return (this.compareTo(a) > 0) ? this : a
1186 }
1187
1188 // (protected) r = this op a (bitwise)
1189 function bnpBitwiseTo(a, op, r) {
1190 var self = this
1191 var i, f, m = Math.min(a.t, self.t)
1192 for (i = 0; i < m; ++i) r[i] = op(self[i], a[i])
1193 if (a.t < self.t) {
1194 f = a.s & self.DM
1195 for (i = m; i < self.t; ++i) r[i] = op(self[i], f)
1196 r.t = self.t
1197 } else {
1198 f = self.s & self.DM
1199 for (i = m; i < a.t; ++i) r[i] = op(f, a[i])
1200 r.t = a.t
1201 }
1202 r.s = op(self.s, a.s)
1203 r.clamp()
1204 }
1205
1206 // (public) this & a
1207 function op_and(x, y) {
1208 return x & y
1209 }
1210
1211 function bnAnd(a) {
1212 var r = new BigInteger()
1213 this.bitwiseTo(a, op_and, r)
1214 return r
1215 }
1216
1217 // (public) this | a
1218 function op_or(x, y) {
1219 return x | y
1220 }
1221
1222 function bnOr(a) {
1223 var r = new BigInteger()
1224 this.bitwiseTo(a, op_or, r)
1225 return r
1226 }
1227
1228 // (public) this ^ a
1229 function op_xor(x, y) {
1230 return x ^ y
1231 }
1232
1233 function bnXor(a) {
1234 var r = new BigInteger()
1235 this.bitwiseTo(a, op_xor, r)
1236 return r
1237 }
1238
1239 // (public) this & ~a
1240 function op_andnot(x, y) {
1241 return x & ~y
1242 }
1243
1244 function bnAndNot(a) {
1245 var r = new BigInteger()
1246 this.bitwiseTo(a, op_andnot, r)
1247 return r
1248 }
1249
1250 // (public) ~this
1251 function bnNot() {
1252 var r = new BigInteger()
1253 for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i]
1254 r.t = this.t
1255 r.s = ~this.s
1256 return r
1257 }
1258
1259 // (public) this << n
1260 function bnShiftLeft(n) {
1261 var r = new BigInteger()
1262 if (n < 0) this.rShiftTo(-n, r)
1263 else this.lShiftTo(n, r)
1264 return r
1265 }
1266
1267 // (public) this >> n
1268 function bnShiftRight(n) {
1269 var r = new BigInteger()
1270 if (n < 0) this.lShiftTo(-n, r)
1271 else this.rShiftTo(n, r)
1272 return r
1273 }
1274
1275 // return index of lowest 1-bit in x, x < 2^31
1276 function lbit(x) {
1277 if (x == 0) return -1
1278 var r = 0
1279 if ((x & 0xffff) == 0) {
1280 x >>= 16
1281 r += 16
1282 }
1283 if ((x & 0xff) == 0) {
1284 x >>= 8
1285 r += 8
1286 }
1287 if ((x & 0xf) == 0) {
1288 x >>= 4
1289 r += 4
1290 }
1291 if ((x & 3) == 0) {
1292 x >>= 2
1293 r += 2
1294 }
1295 if ((x & 1) == 0)++r
1296 return r
1297 }
1298
1299 // (public) returns index of lowest 1-bit (or -1 if none)
1300 function bnGetLowestSetBit() {
1301 for (var i = 0; i < this.t; ++i)
1302 if (this[i] != 0) return i * this.DB + lbit(this[i])
1303 if (this.s < 0) return this.t * this.DB
1304 return -1
1305 }
1306
1307 // return number of 1 bits in x
1308 function cbit(x) {
1309 var r = 0
1310 while (x != 0) {
1311 x &= x - 1
1312 ++r
1313 }
1314 return r
1315 }
1316
1317 // (public) return number of set bits
1318 function bnBitCount() {
1319 var r = 0,
1320 x = this.s & this.DM
1321 for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x)
1322 return r
1323 }
1324
1325 // (public) true iff nth bit is set
1326 function bnTestBit(n) {
1327 var j = Math.floor(n / this.DB)
1328 if (j >= this.t) return (this.s != 0)
1329 return ((this[j] & (1 << (n % this.DB))) != 0)
1330 }
1331
1332 // (protected) this op (1<<n)
1333 function bnpChangeBit(n, op) {
1334 var r = BigInteger.ONE.shiftLeft(n)
1335 this.bitwiseTo(r, op, r)
1336 return r
1337 }
1338
1339 // (public) this | (1<<n)
1340 function bnSetBit(n) {
1341 return this.changeBit(n, op_or)
1342 }
1343
1344 // (public) this & ~(1<<n)
1345 function bnClearBit(n) {
1346 return this.changeBit(n, op_andnot)
1347 }
1348
1349 // (public) this ^ (1<<n)
1350 function bnFlipBit(n) {
1351 return this.changeBit(n, op_xor)
1352 }
1353
1354 // (protected) r = this + a
1355 function bnpAddTo(a, r) {
1356 var self = this
1357
1358 var i = 0,
1359 c = 0,
1360 m = Math.min(a.t, self.t)
1361 while (i < m) {
1362 c += self[i] + a[i]
1363 r[i++] = c & self.DM
1364 c >>= self.DB
1365 }
1366 if (a.t < self.t) {
1367 c += a.s
1368 while (i < self.t) {
1369 c += self[i]
1370 r[i++] = c & self.DM
1371 c >>= self.DB
1372 }
1373 c += self.s
1374 } else {
1375 c += self.s
1376 while (i < a.t) {
1377 c += a[i]
1378 r[i++] = c & self.DM
1379 c >>= self.DB
1380 }
1381 c += a.s
1382 }
1383 r.s = (c < 0) ? -1 : 0
1384 if (c > 0) r[i++] = c
1385 else if (c < -1) r[i++] = self.DV + c
1386 r.t = i
1387 r.clamp()
1388 }
1389
1390 // (public) this + a
1391 function bnAdd(a) {
1392 var r = new BigInteger()
1393 this.addTo(a, r)
1394 return r
1395 }
1396
1397 // (public) this - a
1398 function bnSubtract(a) {
1399 var r = new BigInteger()
1400 this.subTo(a, r)
1401 return r
1402 }
1403
1404 // (public) this * a
1405 function bnMultiply(a) {
1406 var r = new BigInteger()
1407 this.multiplyTo(a, r)
1408 return r
1409 }
1410
1411 // (public) this^2
1412 function bnSquare() {
1413 var r = new BigInteger()
1414 this.squareTo(r)
1415 return r
1416 }
1417
1418 // (public) this / a
1419 function bnDivide(a) {
1420 var r = new BigInteger()
1421 this.divRemTo(a, r, null)
1422 return r
1423 }
1424
1425 // (public) this % a
1426 function bnRemainder(a) {
1427 var r = new BigInteger()
1428 this.divRemTo(a, null, r)
1429 return r
1430 }
1431
1432 // (public) [this/a,this%a]
1433 function bnDivideAndRemainder(a) {
1434 var q = new BigInteger(),
1435 r = new BigInteger()
1436 this.divRemTo(a, q, r)
1437 return new Array(q, r)
1438 }
1439
1440 // (protected) this *= n, this >= 0, 1 < n < DV
1441 function bnpDMultiply(n) {
1442 this[this.t] = this.am(0, n - 1, this, 0, 0, this.t)
1443 ++this.t
1444 this.clamp()
1445 }
1446
1447 // (protected) this += n << w words, this >= 0
1448 function bnpDAddOffset(n, w) {
1449 if (n == 0) return
1450 while (this.t <= w) this[this.t++] = 0
1451 this[w] += n
1452 while (this[w] >= this.DV) {
1453 this[w] -= this.DV
1454 if (++w >= this.t) this[this.t++] = 0
1455 ++this[w]
1456 }
1457 }
1458
1459 // A "null" reducer
1460 function NullExp() {}
1461
1462 function nNop(x) {
1463 return x
1464 }
1465
1466 function nMulTo(x, y, r) {
1467 x.multiplyTo(y, r)
1468 }
1469
1470 function nSqrTo(x, r) {
1471 x.squareTo(r)
1472 }
1473
1474 NullExp.prototype.convert = nNop
1475 NullExp.prototype.revert = nNop
1476 NullExp.prototype.mulTo = nMulTo
1477 NullExp.prototype.sqrTo = nSqrTo
1478
1479 // (public) this^e
1480 function bnPow(e) {
1481 return this.exp(e, new NullExp())
1482 }
1483
1484 // (protected) r = lower n words of "this * a", a.t <= n
1485 // "this" should be the larger one if appropriate.
1486 function bnpMultiplyLowerTo(a, n, r) {
1487 var i = Math.min(this.t + a.t, n)
1488 r.s = 0; // assumes a,this >= 0
1489 r.t = i
1490 while (i > 0) r[--i] = 0
1491 var j
1492 for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t)
1493 for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i)
1494 r.clamp()
1495 }
1496
1497 // (protected) r = "this * a" without lower n words, n > 0
1498 // "this" should be the larger one if appropriate.
1499 function bnpMultiplyUpperTo(a, n, r) {
1500 --n
1501 var i = r.t = this.t + a.t - n
1502 r.s = 0; // assumes a,this >= 0
1503 while (--i >= 0) r[i] = 0
1504 for (i = Math.max(n - this.t, 0); i < a.t; ++i)
1505 r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n)
1506 r.clamp()
1507 r.drShiftTo(1, r)
1508 }
1509
1510 // Barrett modular reduction
1511 function Barrett(m) {
1512 // setup Barrett
1513 this.r2 = new BigInteger()
1514 this.q3 = new BigInteger()
1515 BigInteger.ONE.dlShiftTo(2 * m.t, this.r2)
1516 this.mu = this.r2.divide(m)
1517 this.m = m
1518 }
1519
1520 function barrettConvert(x) {
1521 if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m)
1522 else if (x.compareTo(this.m) < 0) return x
1523 else {
1524 var r = new BigInteger()
1525 x.copyTo(r)
1526 this.reduce(r)
1527 return r
1528 }
1529 }
1530
1531 function barrettRevert(x) {
1532 return x
1533 }
1534
1535 // x = x mod m (HAC 14.42)
1536 function barrettReduce(x) {
1537 var self = this
1538 x.drShiftTo(self.m.t - 1, self.r2)
1539 if (x.t > self.m.t + 1) {
1540 x.t = self.m.t + 1
1541 x.clamp()
1542 }
1543 self.mu.multiplyUpperTo(self.r2, self.m.t + 1, self.q3)
1544 self.m.multiplyLowerTo(self.q3, self.m.t + 1, self.r2)
1545 while (x.compareTo(self.r2) < 0) x.dAddOffset(1, self.m.t + 1)
1546 x.subTo(self.r2, x)
1547 while (x.compareTo(self.m) >= 0) x.subTo(self.m, x)
1548 }
1549
1550 // r = x^2 mod m; x != r
1551 function barrettSqrTo(x, r) {
1552 x.squareTo(r)
1553 this.reduce(r)
1554 }
1555
1556 // r = x*y mod m; x,y != r
1557 function barrettMulTo(x, y, r) {
1558 x.multiplyTo(y, r)
1559 this.reduce(r)
1560 }
1561
1562 Barrett.prototype.convert = barrettConvert
1563 Barrett.prototype.revert = barrettRevert
1564 Barrett.prototype.reduce = barrettReduce
1565 Barrett.prototype.mulTo = barrettMulTo
1566 Barrett.prototype.sqrTo = barrettSqrTo
1567
1568 // (public) this^e % m (HAC 14.85)
1569 function bnModPow(e, m) {
1570 var i = e.bitLength(),
1571 k, r = nbv(1),
1572 z
1573 if (i <= 0) return r
1574 else if (i < 18) k = 1
1575 else if (i < 48) k = 3
1576 else if (i < 144) k = 4
1577 else if (i < 768) k = 5
1578 else k = 6
1579 if (i < 8)
1580 z = new Classic(m)
1581 else if (m.isEven())
1582 z = new Barrett(m)
1583 else
1584 z = new Montgomery(m)
1585
1586 // precomputation
1587 var g = new Array(),
1588 n = 3,
1589 k1 = k - 1,
1590 km = (1 << k) - 1
1591 g[1] = z.convert(this)
1592 if (k > 1) {
1593 var g2 = new BigInteger()
1594 z.sqrTo(g[1], g2)
1595 while (n <= km) {
1596 g[n] = new BigInteger()
1597 z.mulTo(g2, g[n - 2], g[n])
1598 n += 2
1599 }
1600 }
1601
1602 var j = e.t - 1,
1603 w, is1 = true,
1604 r2 = new BigInteger(),
1605 t
1606 i = nbits(e[j]) - 1
1607 while (j >= 0) {
1608 if (i >= k1) w = (e[j] >> (i - k1)) & km
1609 else {
1610 w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i)
1611 if (j > 0) w |= e[j - 1] >> (this.DB + i - k1)
1612 }
1613
1614 n = k
1615 while ((w & 1) == 0) {
1616 w >>= 1
1617 --n
1618 }
1619 if ((i -= n) < 0) {
1620 i += this.DB
1621 --j
1622 }
1623 if (is1) { // ret == 1, don't bother squaring or multiplying it
1624 g[w].copyTo(r)
1625 is1 = false
1626 } else {
1627 while (n > 1) {
1628 z.sqrTo(r, r2)
1629 z.sqrTo(r2, r)
1630 n -= 2
1631 }
1632 if (n > 0) z.sqrTo(r, r2)
1633 else {
1634 t = r
1635 r = r2
1636 r2 = t
1637 }
1638 z.mulTo(r2, g[w], r)
1639 }
1640
1641 while (j >= 0 && (e[j] & (1 << i)) == 0) {
1642 z.sqrTo(r, r2)
1643 t = r
1644 r = r2
1645 r2 = t
1646 if (--i < 0) {
1647 i = this.DB - 1
1648 --j
1649 }
1650 }
1651 }
1652 return z.revert(r)
1653 }
1654
1655 // (public) gcd(this,a) (HAC 14.54)
1656 function bnGCD(a) {
1657 var x = (this.s < 0) ? this.negate() : this.clone()
1658 var y = (a.s < 0) ? a.negate() : a.clone()
1659 if (x.compareTo(y) < 0) {
1660 var t = x
1661 x = y
1662 y = t
1663 }
1664 var i = x.getLowestSetBit(),
1665 g = y.getLowestSetBit()
1666 if (g < 0) return x
1667 if (i < g) g = i
1668 if (g > 0) {
1669 x.rShiftTo(g, x)
1670 y.rShiftTo(g, y)
1671 }
1672 while (x.signum() > 0) {
1673 if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x)
1674 if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y)
1675 if (x.compareTo(y) >= 0) {
1676 x.subTo(y, x)
1677 x.rShiftTo(1, x)
1678 } else {
1679 y.subTo(x, y)
1680 y.rShiftTo(1, y)
1681 }
1682 }
1683 if (g > 0) y.lShiftTo(g, y)
1684 return y
1685 }
1686
1687 // (protected) this % n, n < 2^26
1688 function bnpModInt(n) {
1689 if (n <= 0) return 0
1690 var d = this.DV % n,
1691 r = (this.s < 0) ? n - 1 : 0
1692 if (this.t > 0)
1693 if (d == 0) r = this[0] % n
1694 else
1695 for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n
1696 return r
1697 }
1698
1699 // (public) 1/this % m (HAC 14.61)
1700 function bnModInverse(m) {
1701 var ac = m.isEven()
1702 if (this.signum() === 0) throw new Error('division by zero')
1703 if ((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO
1704 var u = m.clone(),
1705 v = this.clone()
1706 var a = nbv(1),
1707 b = nbv(0),
1708 c = nbv(0),
1709 d = nbv(1)
1710 while (u.signum() != 0) {
1711 while (u.isEven()) {
1712 u.rShiftTo(1, u)
1713 if (ac) {
1714 if (!a.isEven() || !b.isEven()) {
1715 a.addTo(this, a)
1716 b.subTo(m, b)
1717 }
1718 a.rShiftTo(1, a)
1719 } else if (!b.isEven()) b.subTo(m, b)
1720 b.rShiftTo(1, b)
1721 }
1722 while (v.isEven()) {
1723 v.rShiftTo(1, v)
1724 if (ac) {
1725 if (!c.isEven() || !d.isEven()) {
1726 c.addTo(this, c)
1727 d.subTo(m, d)
1728 }
1729 c.rShiftTo(1, c)
1730 } else if (!d.isEven()) d.subTo(m, d)
1731 d.rShiftTo(1, d)
1732 }
1733 if (u.compareTo(v) >= 0) {
1734 u.subTo(v, u)
1735 if (ac) a.subTo(c, a)
1736 b.subTo(d, b)
1737 } else {
1738 v.subTo(u, v)
1739 if (ac) c.subTo(a, c)
1740 d.subTo(b, d)
1741 }
1742 }
1743 if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO
1744 while (d.compareTo(m) >= 0) d.subTo(m, d)
1745 while (d.signum() < 0) d.addTo(m, d)
1746 return d
1747 }
1748
1749 var lowprimes = [
1750 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
1751 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
1752 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
1753 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
1754 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
1755 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
1756 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
1757 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
1758 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811,
1759 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
1760 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
1761 ]
1762
1763 var lplim = (1 << 26) / lowprimes[lowprimes.length - 1]
1764
1765 // (public) test primality with certainty >= 1-.5^t
1766 function bnIsProbablePrime(t) {
1767 var i, x = this.abs()
1768 if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
1769 for (i = 0; i < lowprimes.length; ++i)
1770 if (x[0] == lowprimes[i]) return true
1771 return false
1772 }
1773 if (x.isEven()) return false
1774 i = 1
1775 while (i < lowprimes.length) {
1776 var m = lowprimes[i],
1777 j = i + 1
1778 while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]
1779 m = x.modInt(m)
1780 while (i < j) if (m % lowprimes[i++] == 0) return false
1781 }
1782 return x.millerRabin(t)
1783 }
1784
1785 // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1786 function bnpMillerRabin(t) {
1787 var n1 = this.subtract(BigInteger.ONE)
1788 var k = n1.getLowestSetBit()
1789 if (k <= 0) return false
1790 var r = n1.shiftRight(k)
1791 t = (t + 1) >> 1
1792 if (t > lowprimes.length) t = lowprimes.length
1793 var a = new BigInteger(null)
1794 var j, bases = []
1795 for (var i = 0; i < t; ++i) {
1796 for (;;) {
1797 j = lowprimes[Math.floor(Math.random() * lowprimes.length)]
1798 if (bases.indexOf(j) == -1) break
1799 }
1800 bases.push(j)
1801 a.fromInt(j)
1802 var y = a.modPow(r, this)
1803 if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1804 var j = 1
1805 while (j++ < k && y.compareTo(n1) != 0) {
1806 y = y.modPowInt(2, this)
1807 if (y.compareTo(BigInteger.ONE) == 0) return false
1808 }
1809 if (y.compareTo(n1) != 0) return false
1810 }
1811 }
1812 return true
1813 }
1814
1815 // protected
1816 proto.chunkSize = bnpChunkSize
1817 proto.toRadix = bnpToRadix
1818 proto.fromRadix = bnpFromRadix
1819 proto.fromNumber = bnpFromNumber
1820 proto.bitwiseTo = bnpBitwiseTo
1821 proto.changeBit = bnpChangeBit
1822 proto.addTo = bnpAddTo
1823 proto.dMultiply = bnpDMultiply
1824 proto.dAddOffset = bnpDAddOffset
1825 proto.multiplyLowerTo = bnpMultiplyLowerTo
1826 proto.multiplyUpperTo = bnpMultiplyUpperTo
1827 proto.modInt = bnpModInt
1828 proto.millerRabin = bnpMillerRabin
1829
1830 // public
1831 proto.clone = bnClone
1832 proto.intValue = bnIntValue
1833 proto.byteValue = bnByteValue
1834 proto.shortValue = bnShortValue
1835 proto.signum = bnSigNum
1836 proto.toByteArray = bnToByteArray
1837 proto.equals = bnEquals
1838 proto.min = bnMin
1839 proto.max = bnMax
1840 proto.and = bnAnd
1841 proto.or = bnOr
1842 proto.xor = bnXor
1843 proto.andNot = bnAndNot
1844 proto.not = bnNot
1845 proto.shiftLeft = bnShiftLeft
1846 proto.shiftRight = bnShiftRight
1847 proto.getLowestSetBit = bnGetLowestSetBit
1848 proto.bitCount = bnBitCount
1849 proto.testBit = bnTestBit
1850 proto.setBit = bnSetBit
1851 proto.clearBit = bnClearBit
1852 proto.flipBit = bnFlipBit
1853 proto.add = bnAdd
1854 proto.subtract = bnSubtract
1855 proto.multiply = bnMultiply
1856 proto.divide = bnDivide
1857 proto.remainder = bnRemainder
1858 proto.divideAndRemainder = bnDivideAndRemainder
1859 proto.modPow = bnModPow
1860 proto.modInverse = bnModInverse
1861 proto.pow = bnPow
1862 proto.gcd = bnGCD
1863 proto.isProbablePrime = bnIsProbablePrime
1864
1865 // JSBN-specific extension
1866 proto.square = bnSquare
1867
1868 // constants
1869 BigInteger.ZERO = nbv(0)
1870 BigInteger.ONE = nbv(1)
1871 BigInteger.valueOf = nbv
1872
1873 module.exports = BigInteger
1874
1875 },{"../package.json":6}],4:[function(require,module,exports){
1876 (function (Buffer){
1877 // FIXME: Kind of a weird way to throw exceptions, consider removing
1878 var assert = require('assert')
1879 var BigInteger = require('./bigi')
1880
1881 /**
1882 * Turns a byte array into a big integer.
1883 *
1884 * This function will interpret a byte array as a big integer in big
1885 * endian notation.
1886 */
1887 BigInteger.fromByteArrayUnsigned = function(byteArray) {
1888 // BigInteger expects a DER integer conformant byte array
1889 if (byteArray[0] & 0x80) {
1890 return new BigInteger([0].concat(byteArray))
1891 }
1892
1893 return new BigInteger(byteArray)
1894 }
1895
1896 /**
1897 * Returns a byte array representation of the big integer.
1898 *
1899 * This returns the absolute of the contained value in big endian
1900 * form. A value of zero results in an empty array.
1901 */
1902 BigInteger.prototype.toByteArrayUnsigned = function() {
1903 var byteArray = this.toByteArray()
1904 return byteArray[0] === 0 ? byteArray.slice(1) : byteArray
1905 }
1906
1907 BigInteger.fromDERInteger = function(byteArray) {
1908 return new BigInteger(byteArray)
1909 }
1910
1911 /*
1912 * Converts BigInteger to a DER integer representation.
1913 *
1914 * The format for this value uses the most significant bit as a sign
1915 * bit. If the most significant bit is already set and the integer is
1916 * positive, a 0x00 is prepended.
1917 *
1918 * Examples:
1919 *
1920 * 0 => 0x00
1921 * 1 => 0x01
1922 * -1 => 0xff
1923 * 127 => 0x7f
1924 * -127 => 0x81
1925 * 128 => 0x0080
1926 * -128 => 0x80
1927 * 255 => 0x00ff
1928 * -255 => 0xff01
1929 * 16300 => 0x3fac
1930 * -16300 => 0xc054
1931 * 62300 => 0x00f35c
1932 * -62300 => 0xff0ca4
1933 */
1934 BigInteger.prototype.toDERInteger = BigInteger.prototype.toByteArray
1935
1936 BigInteger.fromBuffer = function(buffer) {
1937 // BigInteger expects a DER integer conformant byte array
1938 if (buffer[0] & 0x80) {
1939 var byteArray = Array.prototype.slice.call(buffer)
1940
1941 return new BigInteger([0].concat(byteArray))
1942 }
1943
1944 return new BigInteger(buffer)
1945 }
1946
1947 BigInteger.fromHex = function(hex) {
1948 if (hex === '') return BigInteger.ZERO
1949
1950 assert.equal(hex, hex.match(/^[A-Fa-f0-9]+/), 'Invalid hex string')
1951 assert.equal(hex.length % 2, 0, 'Incomplete hex')
1952 return new BigInteger(hex, 16)
1953 }
1954
1955 BigInteger.prototype.toBuffer = function(size) {
1956 var byteArray = this.toByteArrayUnsigned()
1957 var zeros = []
1958
1959 var padding = size - byteArray.length
1960 while (zeros.length < padding) zeros.push(0)
1961
1962 return new Buffer(zeros.concat(byteArray))
1963 }
1964
1965 BigInteger.prototype.toHex = function(size) {
1966 return this.toBuffer(size).toString('hex')
1967 }
1968
1969 }).call(this,require("buffer").Buffer)
1970 },{"./bigi":3,"assert":74,"buffer":110}],5:[function(require,module,exports){
1971 var BigInteger = require('./bigi')
1972
1973 //addons
1974 require('./convert')
1975
1976 module.exports = BigInteger
1977 },{"./bigi":3,"./convert":4}],6:[function(require,module,exports){
1978 module.exports={
1979 "_args": [
1980 [
1981 "bigi@^1.2.0",
1982 "/home/hashengineering/hashengineering/bip38grs"
1983 ]
1984 ],
1985 "_from": "bigi@>=1.2.0 <2.0.0",
1986 "_id": "bigi@1.4.2",
1987 "_inCache": true,
1988 "_installable": true,
1989 "_location": "/bigi",
1990 "_nodeVersion": "6.1.0",
1991 "_npmOperationalInternal": {
1992 "host": "packages-12-west.internal.npmjs.com",
1993 "tmp": "tmp/bigi-1.4.2.tgz_1469584192413_0.6801238611806184"
1994 },
1995 "_npmUser": {
1996 "email": "jprichardson@gmail.com",
1997 "name": "jprichardson"
1998 },
1999 "_npmVersion": "3.8.6",
2000 "_phantomChildren": {},
2001 "_requested": {
2002 "name": "bigi",
2003 "raw": "bigi@^1.2.0",
2004 "rawSpec": "^1.2.0",
2005 "scope": null,
2006 "spec": ">=1.2.0 <2.0.0",
2007 "type": "range"
2008 },
2009 "_requiredBy": [
2010 "/",
2011 "/ecurve"
2012 ],
2013 "_resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
2014 "_shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
2015 "_shrinkwrap": null,
2016 "_spec": "bigi@^1.2.0",
2017 "_where": "/home/hashengineering/hashengineering/bip38grs",
2018 "bugs": {
2019 "url": "https://github.com/cryptocoinjs/bigi/issues"
2020 },
2021 "dependencies": {},
2022 "description": "Big integers.",
2023 "devDependencies": {
2024 "coveralls": "^2.11.2",
2025 "istanbul": "^0.3.5",
2026 "jshint": "^2.5.1",
2027 "mocha": "^2.1.0",
2028 "mochify": "^2.1.0"
2029 },
2030 "directories": {},
2031 "dist": {
2032 "shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
2033 "tarball": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"
2034 },
2035 "gitHead": "c25308081c896ff84702303722bf5ecd8b3f78e3",
2036 "homepage": "https://github.com/cryptocoinjs/bigi#readme",
2037 "keywords": [
2038 "arbitrary",
2039 "arithmetic",
2040 "big",
2041 "bigint",
2042 "biginteger",
2043 "bignumber",
2044 "bitcoin",
2045 "cryptography",
2046 "decimal",
2047 "float",
2048 "int",
2049 "integer",
2050 "math",
2051 "number",
2052 "precision"
2053 ],
2054 "main": "./lib/index.js",
2055 "maintainers": [
2056 {
2057 "name": "midnightlightning",
2058 "email": "boydb@midnightdesign.ws"
2059 },
2060 {
2061 "name": "sidazhang",
2062 "email": "sidazhang89@gmail.com"
2063 },
2064 {
2065 "name": "nadav",
2066 "email": "npm@shesek.info"
2067 },
2068 {
2069 "name": "jprichardson",
2070 "email": "jprichardson@gmail.com"
2071 }
2072 ],
2073 "name": "bigi",
2074 "optionalDependencies": {},
2075 "readme": "ERROR: No README data found!",
2076 "repository": {
2077 "type": "git",
2078 "url": "git+https://github.com/cryptocoinjs/bigi.git"
2079 },
2080 "scripts": {
2081 "browser-test": "mochify --wd -R spec",
2082 "coverage": "istanbul cover ./node_modules/.bin/_mocha -- --reporter list test/*.js",
2083 "coveralls": "npm run-script coverage && node ./node_modules/.bin/coveralls < coverage/lcov.info",
2084 "jshint": "jshint --config jshint.json lib/*.js ; true",
2085 "test": "_mocha -- test/*.js",
2086 "unit": "mocha"
2087 },
2088 "testling": {
2089 "browsers": [
2090 "android-browser/4.2..latest",
2091 "chrome/latest",
2092 "firefox/latest",
2093 "ie/9..latest",
2094 "iphone/6.0..latest",
2095 "safari/6.0..latest"
2096 ],
2097 "files": "test/*.js",
2098 "harness": "mocha"
2099 },
2100 "version": "1.4.2"
2101 }
2102
2103 },{}],7:[function(require,module,exports){
2104 // based on the aes implimentation in triple sec
2105 // https://github.com/keybase/triplesec
2106 // which is in turn based on the one from crypto-js
2107 // https://code.google.com/p/crypto-js/
2108
2109 var Buffer = require('safe-buffer').Buffer
2110
2111 function asUInt32Array (buf) {
2112 if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf)
2113
2114 var len = (buf.length / 4) | 0
2115 var out = new Array(len)
2116
2117 for (var i = 0; i < len; i++) {
2118 out[i] = buf.readUInt32BE(i * 4)
2119 }
2120
2121 return out
2122 }
2123
2124 function scrubVec (v) {
2125 for (var i = 0; i < v.length; v++) {
2126 v[i] = 0
2127 }
2128 }
2129
2130 function cryptBlock (M, keySchedule, SUB_MIX, SBOX, nRounds) {
2131 var SUB_MIX0 = SUB_MIX[0]
2132 var SUB_MIX1 = SUB_MIX[1]
2133 var SUB_MIX2 = SUB_MIX[2]
2134 var SUB_MIX3 = SUB_MIX[3]
2135
2136 var s0 = M[0] ^ keySchedule[0]
2137 var s1 = M[1] ^ keySchedule[1]
2138 var s2 = M[2] ^ keySchedule[2]
2139 var s3 = M[3] ^ keySchedule[3]
2140 var t0, t1, t2, t3
2141 var ksRow = 4
2142
2143 for (var round = 1; round < nRounds; round++) {
2144 t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[(s1 >>> 16) & 0xff] ^ SUB_MIX2[(s2 >>> 8) & 0xff] ^ SUB_MIX3[s3 & 0xff] ^ keySchedule[ksRow++]
2145 t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[(s2 >>> 16) & 0xff] ^ SUB_MIX2[(s3 >>> 8) & 0xff] ^ SUB_MIX3[s0 & 0xff] ^ keySchedule[ksRow++]
2146 t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[(s3 >>> 16) & 0xff] ^ SUB_MIX2[(s0 >>> 8) & 0xff] ^ SUB_MIX3[s1 & 0xff] ^ keySchedule[ksRow++]
2147 t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[(s0 >>> 16) & 0xff] ^ SUB_MIX2[(s1 >>> 8) & 0xff] ^ SUB_MIX3[s2 & 0xff] ^ keySchedule[ksRow++]
2148 s0 = t0
2149 s1 = t1
2150 s2 = t2
2151 s3 = t3
2152 }
2153
2154 t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]
2155 t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]
2156 t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]
2157 t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]
2158 t0 = t0 >>> 0
2159 t1 = t1 >>> 0
2160 t2 = t2 >>> 0
2161 t3 = t3 >>> 0
2162
2163 return [t0, t1, t2, t3]
2164 }
2165
2166 // AES constants
2167 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]
2168 var G = (function () {
2169 // Compute double table
2170 var d = new Array(256)
2171 for (var j = 0; j < 256; j++) {
2172 if (j < 128) {
2173 d[j] = j << 1
2174 } else {
2175 d[j] = (j << 1) ^ 0x11b
2176 }
2177 }
2178
2179 var SBOX = []
2180 var INV_SBOX = []
2181 var SUB_MIX = [[], [], [], []]
2182 var INV_SUB_MIX = [[], [], [], []]
2183
2184 // Walk GF(2^8)
2185 var x = 0
2186 var xi = 0
2187 for (var i = 0; i < 256; ++i) {
2188 // Compute sbox
2189 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4)
2190 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63
2191 SBOX[x] = sx
2192 INV_SBOX[sx] = x
2193
2194 // Compute multiplication
2195 var x2 = d[x]
2196 var x4 = d[x2]
2197 var x8 = d[x4]
2198
2199 // Compute sub bytes, mix columns tables
2200 var t = (d[sx] * 0x101) ^ (sx * 0x1010100)
2201 SUB_MIX[0][x] = (t << 24) | (t >>> 8)
2202 SUB_MIX[1][x] = (t << 16) | (t >>> 16)
2203 SUB_MIX[2][x] = (t << 8) | (t >>> 24)
2204 SUB_MIX[3][x] = t
2205
2206 // Compute inv sub bytes, inv mix columns tables
2207 t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100)
2208 INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8)
2209 INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16)
2210 INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24)
2211 INV_SUB_MIX[3][sx] = t
2212
2213 if (x === 0) {
2214 x = xi = 1
2215 } else {
2216 x = x2 ^ d[d[d[x8 ^ x2]]]
2217 xi ^= d[d[xi]]
2218 }
2219 }
2220
2221 return {
2222 SBOX: SBOX,
2223 INV_SBOX: INV_SBOX,
2224 SUB_MIX: SUB_MIX,
2225 INV_SUB_MIX: INV_SUB_MIX
2226 }
2227 })()
2228
2229 function AES (key) {
2230 this._key = asUInt32Array(key)
2231 this._reset()
2232 }
2233
2234 AES.blockSize = 4 * 4
2235 AES.keySize = 256 / 8
2236 AES.prototype.blockSize = AES.blockSize
2237 AES.prototype.keySize = AES.keySize
2238 AES.prototype._reset = function () {
2239 var keyWords = this._key
2240 var keySize = keyWords.length
2241 var nRounds = keySize + 6
2242 var ksRows = (nRounds + 1) * 4
2243
2244 var keySchedule = []
2245 for (var k = 0; k < keySize; k++) {
2246 keySchedule[k] = keyWords[k]
2247 }
2248
2249 for (k = keySize; k < ksRows; k++) {
2250 var t = keySchedule[k - 1]
2251
2252 if (k % keySize === 0) {
2253 t = (t << 8) | (t >>> 24)
2254 t =
2255 (G.SBOX[t >>> 24] << 24) |
2256 (G.SBOX[(t >>> 16) & 0xff] << 16) |
2257 (G.SBOX[(t >>> 8) & 0xff] << 8) |
2258 (G.SBOX[t & 0xff])
2259
2260 t ^= RCON[(k / keySize) | 0] << 24
2261 } else if (keySize > 6 && k % keySize === 4) {
2262 t =
2263 (G.SBOX[t >>> 24] << 24) |
2264 (G.SBOX[(t >>> 16) & 0xff] << 16) |
2265 (G.SBOX[(t >>> 8) & 0xff] << 8) |
2266 (G.SBOX[t & 0xff])
2267 }
2268
2269 keySchedule[k] = keySchedule[k - keySize] ^ t
2270 }
2271
2272 var invKeySchedule = []
2273 for (var ik = 0; ik < ksRows; ik++) {
2274 var ksR = ksRows - ik
2275 var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]
2276
2277 if (ik < 4 || ksR <= 4) {
2278 invKeySchedule[ik] = tt
2279 } else {
2280 invKeySchedule[ik] =
2281 G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^
2282 G.INV_SUB_MIX[1][G.SBOX[(tt >>> 16) & 0xff]] ^
2283 G.INV_SUB_MIX[2][G.SBOX[(tt >>> 8) & 0xff]] ^
2284 G.INV_SUB_MIX[3][G.SBOX[tt & 0xff]]
2285 }
2286 }
2287
2288 this._nRounds = nRounds
2289 this._keySchedule = keySchedule
2290 this._invKeySchedule = invKeySchedule
2291 }
2292
2293 AES.prototype.encryptBlockRaw = function (M) {
2294 M = asUInt32Array(M)
2295 return cryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX, this._nRounds)
2296 }
2297
2298 AES.prototype.encryptBlock = function (M) {
2299 var out = this.encryptBlockRaw(M)
2300 var buf = Buffer.allocUnsafe(16)
2301 buf.writeUInt32BE(out[0], 0)
2302 buf.writeUInt32BE(out[1], 4)
2303 buf.writeUInt32BE(out[2], 8)
2304 buf.writeUInt32BE(out[3], 12)
2305 return buf
2306 }
2307
2308 AES.prototype.decryptBlock = function (M) {
2309 M = asUInt32Array(M)
2310
2311 // swap
2312 var m1 = M[1]
2313 M[1] = M[3]
2314 M[3] = m1
2315
2316 var out = cryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, this._nRounds)
2317 var buf = Buffer.allocUnsafe(16)
2318 buf.writeUInt32BE(out[0], 0)
2319 buf.writeUInt32BE(out[3], 4)
2320 buf.writeUInt32BE(out[2], 8)
2321 buf.writeUInt32BE(out[1], 12)
2322 return buf
2323 }
2324
2325 AES.prototype.scrub = function () {
2326 scrubVec(this._keySchedule)
2327 scrubVec(this._invKeySchedule)
2328 scrubVec(this._key)
2329 }
2330
2331 module.exports.AES = AES
2332
2333 },{"safe-buffer":47}],8:[function(require,module,exports){
2334 var aes = require('./aes')
2335 var Buffer = require('safe-buffer').Buffer
2336 var Transform = require('cipher-base')
2337 var inherits = require('inherits')
2338 var GHASH = require('./ghash')
2339 var xor = require('buffer-xor')
2340 var incr32 = require('./incr32')
2341
2342 function xorTest (a, b) {
2343 var out = 0
2344 if (a.length !== b.length) out++
2345
2346 var len = Math.min(a.length, b.length)
2347 for (var i = 0; i < len; ++i) {
2348 out += (a[i] ^ b[i])
2349 }
2350
2351 return out
2352 }
2353
2354 function calcIv (self, iv, ck) {
2355 if (iv.length === 12) {
2356 self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])])
2357 return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])])
2358 }
2359 var ghash = new GHASH(ck)
2360 var len = iv.length
2361 var toPad = len % 16
2362 ghash.update(iv)
2363 if (toPad) {
2364 toPad = 16 - toPad
2365 ghash.update(Buffer.alloc(toPad, 0))
2366 }
2367 ghash.update(Buffer.alloc(8, 0))
2368 var ivBits = len * 8
2369 var tail = Buffer.alloc(8)
2370 tail.writeUIntBE(ivBits, 0, 8)
2371 ghash.update(tail)
2372 self._finID = ghash.state
2373 var out = Buffer.from(self._finID)
2374 incr32(out)
2375 return out
2376 }
2377 function StreamCipher (mode, key, iv, decrypt) {
2378 Transform.call(this)
2379
2380 var h = Buffer.alloc(4, 0)
2381
2382 this._cipher = new aes.AES(key)
2383 var ck = this._cipher.encryptBlock(h)
2384 this._ghash = new GHASH(ck)
2385 iv = calcIv(this, iv, ck)
2386
2387 this._prev = Buffer.from(iv)
2388 this._cache = Buffer.allocUnsafe(0)
2389 this._secCache = Buffer.allocUnsafe(0)
2390 this._decrypt = decrypt
2391 this._alen = 0
2392 this._len = 0
2393 this._mode = mode
2394
2395 this._authTag = null
2396 this._called = false
2397 }
2398
2399 inherits(StreamCipher, Transform)
2400
2401 StreamCipher.prototype._update = function (chunk) {
2402 if (!this._called && this._alen) {
2403 var rump = 16 - (this._alen % 16)
2404 if (rump < 16) {
2405 rump = Buffer.alloc(rump, 0)
2406 this._ghash.update(rump)
2407 }
2408 }
2409
2410 this._called = true
2411 var out = this._mode.encrypt(this, chunk)
2412 if (this._decrypt) {
2413 this._ghash.update(chunk)
2414 } else {
2415 this._ghash.update(out)
2416 }
2417 this._len += chunk.length
2418 return out
2419 }
2420
2421 StreamCipher.prototype._final = function () {
2422 if (this._decrypt && !this._authTag) throw new Error('Unsupported state or unable to authenticate data')
2423
2424 var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID))
2425 if (this._decrypt && xorTest(tag, this._authTag)) throw new Error('Unsupported state or unable to authenticate data')
2426
2427 this._authTag = tag
2428 this._cipher.scrub()
2429 }
2430
2431 StreamCipher.prototype.getAuthTag = function getAuthTag () {
2432 if (this._decrypt || !Buffer.isBuffer(this._authTag)) throw new Error('Attempting to get auth tag in unsupported state')
2433
2434 return this._authTag
2435 }
2436
2437 StreamCipher.prototype.setAuthTag = function setAuthTag (tag) {
2438 if (!this._decrypt) throw new Error('Attempting to set auth tag in unsupported state')
2439
2440 this._authTag = tag
2441 }
2442
2443 StreamCipher.prototype.setAAD = function setAAD (buf) {
2444 if (this._called) throw new Error('Attempting to set AAD in unsupported state')
2445
2446 this._ghash.update(buf)
2447 this._alen += buf.length
2448 }
2449
2450 module.exports = StreamCipher
2451
2452 },{"./aes":7,"./ghash":12,"./incr32":13,"buffer-xor":29,"cipher-base":31,"inherits":44,"safe-buffer":47}],9:[function(require,module,exports){
2453 var ciphers = require('./encrypter')
2454 var deciphers = require('./decrypter')
2455 var modes = require('./modes/list.json')
2456
2457 function getCiphers () {
2458 return Object.keys(modes)
2459 }
2460
2461 exports.createCipher = exports.Cipher = ciphers.createCipher
2462 exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv
2463 exports.createDecipher = exports.Decipher = deciphers.createDecipher
2464 exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv
2465 exports.listCiphers = exports.getCiphers = getCiphers
2466
2467 },{"./decrypter":10,"./encrypter":11,"./modes/list.json":21}],10:[function(require,module,exports){
2468 var AuthCipher = require('./authCipher')
2469 var Buffer = require('safe-buffer').Buffer
2470 var MODES = require('./modes')
2471 var StreamCipher = require('./streamCipher')
2472 var Transform = require('cipher-base')
2473 var aes = require('./aes')
2474 var ebtk = require('evp_bytestokey')
2475 var inherits = require('inherits')
2476
2477 function Decipher (mode, key, iv) {
2478 Transform.call(this)
2479
2480 this._cache = new Splitter()
2481 this._last = void 0
2482 this._cipher = new aes.AES(key)
2483 this._prev = Buffer.from(iv)
2484 this._mode = mode
2485 this._autopadding = true
2486 }
2487
2488 inherits(Decipher, Transform)
2489
2490 Decipher.prototype._update = function (data) {
2491 this._cache.add(data)
2492 var chunk
2493 var thing
2494 var out = []
2495 while ((chunk = this._cache.get(this._autopadding))) {
2496 thing = this._mode.decrypt(this, chunk)
2497 out.push(thing)
2498 }
2499 return Buffer.concat(out)
2500 }
2501
2502 Decipher.prototype._final = function () {
2503 var chunk = this._cache.flush()
2504 if (this._autopadding) {
2505 return unpad(this._mode.decrypt(this, chunk))
2506 } else if (chunk) {
2507 throw new Error('data not multiple of block length')
2508 }
2509 }
2510
2511 Decipher.prototype.setAutoPadding = function (setTo) {
2512 this._autopadding = !!setTo
2513 return this
2514 }
2515
2516 function Splitter () {
2517 this.cache = Buffer.allocUnsafe(0)
2518 }
2519
2520 Splitter.prototype.add = function (data) {
2521 this.cache = Buffer.concat([this.cache, data])
2522 }
2523
2524 Splitter.prototype.get = function (autoPadding) {
2525 var out
2526 if (autoPadding) {
2527 if (this.cache.length > 16) {
2528 out = this.cache.slice(0, 16)
2529 this.cache = this.cache.slice(16)
2530 return out
2531 }
2532 } else {
2533 if (this.cache.length >= 16) {
2534 out = this.cache.slice(0, 16)
2535 this.cache = this.cache.slice(16)
2536 return out
2537 }
2538 }
2539
2540 return null
2541 }
2542
2543 Splitter.prototype.flush = function () {
2544 if (this.cache.length) return this.cache
2545 }
2546
2547 function unpad (last) {
2548 var padded = last[15]
2549 if (padded < 1 || padded > 16) {
2550 throw new Error('unable to decrypt data')
2551 }
2552 var i = -1
2553 while (++i < padded) {
2554 if (last[(i + (16 - padded))] !== padded) {
2555 throw new Error('unable to decrypt data')
2556 }
2557 }
2558 if (padded === 16) return
2559
2560 return last.slice(0, 16 - padded)
2561 }
2562
2563 function createDecipheriv (suite, password, iv) {
2564 var config = MODES[suite.toLowerCase()]
2565 if (!config) throw new TypeError('invalid suite type')
2566
2567 if (typeof iv === 'string') iv = Buffer.from(iv)
2568 if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length)
2569
2570 if (typeof password === 'string') password = Buffer.from(password)
2571 if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length)
2572
2573 if (config.type === 'stream') {
2574 return new StreamCipher(config.module, password, iv, true)
2575 } else if (config.type === 'auth') {
2576 return new AuthCipher(config.module, password, iv, true)
2577 }
2578
2579 return new Decipher(config.module, password, iv)
2580 }
2581
2582 function createDecipher (suite, password) {
2583 var config = MODES[suite.toLowerCase()]
2584 if (!config) throw new TypeError('invalid suite type')
2585
2586 var keys = ebtk(password, false, config.key, config.iv)
2587 return createDecipheriv(suite, keys.key, keys.iv)
2588 }
2589
2590 exports.createDecipher = createDecipher
2591 exports.createDecipheriv = createDecipheriv
2592
2593 },{"./aes":7,"./authCipher":8,"./modes":20,"./streamCipher":23,"cipher-base":31,"evp_bytestokey":38,"inherits":44,"safe-buffer":47}],11:[function(require,module,exports){
2594 var MODES = require('./modes')
2595 var AuthCipher = require('./authCipher')
2596 var Buffer = require('safe-buffer').Buffer
2597 var StreamCipher = require('./streamCipher')
2598 var Transform = require('cipher-base')
2599 var aes = require('./aes')
2600 var ebtk = require('evp_bytestokey')
2601 var inherits = require('inherits')
2602
2603 function Cipher (mode, key, iv) {
2604 Transform.call(this)
2605
2606 this._cache = new Splitter()
2607 this._cipher = new aes.AES(key)
2608 this._prev = Buffer.from(iv)
2609 this._mode = mode
2610 this._autopadding = true
2611 }
2612
2613 inherits(Cipher, Transform)
2614
2615 Cipher.prototype._update = function (data) {
2616 this._cache.add(data)
2617 var chunk
2618 var thing
2619 var out = []
2620
2621 while ((chunk = this._cache.get())) {
2622 thing = this._mode.encrypt(this, chunk)
2623 out.push(thing)
2624 }
2625
2626 return Buffer.concat(out)
2627 }
2628
2629 var PADDING = Buffer.alloc(16, 0x10)
2630
2631 Cipher.prototype._final = function () {
2632 var chunk = this._cache.flush()
2633 if (this._autopadding) {
2634 chunk = this._mode.encrypt(this, chunk)
2635 this._cipher.scrub()
2636 return chunk
2637 }
2638
2639 if (!chunk.equals(PADDING)) {
2640 this._cipher.scrub()
2641 throw new Error('data not multiple of block length')
2642 }
2643 }
2644
2645 Cipher.prototype.setAutoPadding = function (setTo) {
2646 this._autopadding = !!setTo
2647 return this
2648 }
2649
2650 function Splitter () {
2651 this.cache = Buffer.allocUnsafe(0)
2652 }
2653
2654 Splitter.prototype.add = function (data) {
2655 this.cache = Buffer.concat([this.cache, data])
2656 }
2657
2658 Splitter.prototype.get = function () {
2659 if (this.cache.length > 15) {
2660 var out = this.cache.slice(0, 16)
2661 this.cache = this.cache.slice(16)
2662 return out
2663 }
2664 return null
2665 }
2666
2667 Splitter.prototype.flush = function () {
2668 var len = 16 - this.cache.length
2669 var padBuff = Buffer.allocUnsafe(len)
2670
2671 var i = -1
2672 while (++i < len) {
2673 padBuff.writeUInt8(len, i)
2674 }
2675
2676 return Buffer.concat([this.cache, padBuff])
2677 }
2678
2679 function createCipheriv (suite, password, iv) {
2680 var config = MODES[suite.toLowerCase()]
2681 if (!config) throw new TypeError('invalid suite type')
2682
2683 if (typeof password === 'string') password = Buffer.from(password)
2684 if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length)
2685
2686 if (typeof iv === 'string') iv = Buffer.from(iv)
2687 if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length)
2688
2689 if (config.type === 'stream') {
2690 return new StreamCipher(config.module, password, iv)
2691 } else if (config.type === 'auth') {
2692 return new AuthCipher(config.module, password, iv)
2693 }
2694
2695 return new Cipher(config.module, password, iv)
2696 }
2697
2698 function createCipher (suite, password) {
2699 var config = MODES[suite.toLowerCase()]
2700 if (!config) throw new TypeError('invalid suite type')
2701
2702 var keys = ebtk(password, false, config.key, config.iv)
2703 return createCipheriv(suite, keys.key, keys.iv)
2704 }
2705
2706 exports.createCipheriv = createCipheriv
2707 exports.createCipher = createCipher
2708
2709 },{"./aes":7,"./authCipher":8,"./modes":20,"./streamCipher":23,"cipher-base":31,"evp_bytestokey":38,"inherits":44,"safe-buffer":47}],12:[function(require,module,exports){
2710 var Buffer = require('safe-buffer').Buffer
2711 var ZEROES = Buffer.alloc(16, 0)
2712
2713 function toArray (buf) {
2714 return [
2715 buf.readUInt32BE(0),
2716 buf.readUInt32BE(4),
2717 buf.readUInt32BE(8),
2718 buf.readUInt32BE(12)
2719 ]
2720 }
2721
2722 function fromArray (out) {
2723 var buf = Buffer.allocUnsafe(16)
2724 buf.writeUInt32BE(out[0] >>> 0, 0)
2725 buf.writeUInt32BE(out[1] >>> 0, 4)
2726 buf.writeUInt32BE(out[2] >>> 0, 8)
2727 buf.writeUInt32BE(out[3] >>> 0, 12)
2728 return buf
2729 }
2730
2731 function GHASH (key) {
2732 this.h = key
2733 this.state = Buffer.alloc(16, 0)
2734 this.cache = Buffer.allocUnsafe(0)
2735 }
2736
2737 // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
2738 // by Juho Vähä-Herttua
2739 GHASH.prototype.ghash = function (block) {
2740 var i = -1
2741 while (++i < block.length) {
2742 this.state[i] ^= block[i]
2743 }
2744 this._multiply()
2745 }
2746
2747 GHASH.prototype._multiply = function () {
2748 var Vi = toArray(this.h)
2749 var Zi = [0, 0, 0, 0]
2750 var j, xi, lsbVi
2751 var i = -1
2752 while (++i < 128) {
2753 xi = (this.state[~~(i / 8)] & (1 << (7 - (i % 8)))) !== 0
2754 if (xi) {
2755 // Z_i+1 = Z_i ^ V_i
2756 Zi[0] ^= Vi[0]
2757 Zi[1] ^= Vi[1]
2758 Zi[2] ^= Vi[2]
2759 Zi[3] ^= Vi[3]
2760 }
2761
2762 // Store the value of LSB(V_i)
2763 lsbVi = (Vi[3] & 1) !== 0
2764
2765 // V_i+1 = V_i >> 1
2766 for (j = 3; j > 0; j--) {
2767 Vi[j] = (Vi[j] >>> 1) | ((Vi[j - 1] & 1) << 31)
2768 }
2769 Vi[0] = Vi[0] >>> 1
2770
2771 // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
2772 if (lsbVi) {
2773 Vi[0] = Vi[0] ^ (0xe1 << 24)
2774 }
2775 }
2776 this.state = fromArray(Zi)
2777 }
2778
2779 GHASH.prototype.update = function (buf) {
2780 this.cache = Buffer.concat([this.cache, buf])
2781 var chunk
2782 while (this.cache.length >= 16) {
2783 chunk = this.cache.slice(0, 16)
2784 this.cache = this.cache.slice(16)
2785 this.ghash(chunk)
2786 }
2787 }
2788
2789 GHASH.prototype.final = function (abl, bl) {
2790 if (this.cache.length) {
2791 this.ghash(Buffer.concat([this.cache, ZEROES], 16))
2792 }
2793
2794 this.ghash(fromArray([0, abl, 0, bl]))
2795 return this.state
2796 }
2797
2798 module.exports = GHASH
2799
2800 },{"safe-buffer":47}],13:[function(require,module,exports){
2801 function incr32 (iv) {
2802 var len = iv.length
2803 var item
2804 while (len--) {
2805 item = iv.readUInt8(len)
2806 if (item === 255) {
2807 iv.writeUInt8(0, len)
2808 } else {
2809 item++
2810 iv.writeUInt8(item, len)
2811 break
2812 }
2813 }
2814 }
2815 module.exports = incr32
2816
2817 },{}],14:[function(require,module,exports){
2818 var xor = require('buffer-xor')
2819
2820 exports.encrypt = function (self, block) {
2821 var data = xor(block, self._prev)
2822
2823 self._prev = self._cipher.encryptBlock(data)
2824 return self._prev
2825 }
2826
2827 exports.decrypt = function (self, block) {
2828 var pad = self._prev
2829
2830 self._prev = block
2831 var out = self._cipher.decryptBlock(block)
2832
2833 return xor(out, pad)
2834 }
2835
2836 },{"buffer-xor":29}],15:[function(require,module,exports){
2837 var Buffer = require('safe-buffer').Buffer
2838 var xor = require('buffer-xor')
2839
2840 function encryptStart (self, data, decrypt) {
2841 var len = data.length
2842 var out = xor(data, self._cache)
2843 self._cache = self._cache.slice(len)
2844 self._prev = Buffer.concat([self._prev, decrypt ? data : out])
2845 return out
2846 }
2847
2848 exports.encrypt = function (self, data, decrypt) {
2849 var out = Buffer.allocUnsafe(0)
2850 var len
2851
2852 while (data.length) {
2853 if (self._cache.length === 0) {
2854 self._cache = self._cipher.encryptBlock(self._prev)
2855 self._prev = Buffer.allocUnsafe(0)
2856 }
2857
2858 if (self._cache.length <= data.length) {
2859 len = self._cache.length
2860 out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)])
2861 data = data.slice(len)
2862 } else {
2863 out = Buffer.concat([out, encryptStart(self, data, decrypt)])
2864 break
2865 }
2866 }
2867
2868 return out
2869 }
2870
2871 },{"buffer-xor":29,"safe-buffer":47}],16:[function(require,module,exports){
2872 var Buffer = require('safe-buffer').Buffer
2873
2874 function encryptByte (self, byteParam, decrypt) {
2875 var pad
2876 var i = -1
2877 var len = 8
2878 var out = 0
2879 var bit, value
2880 while (++i < len) {
2881 pad = self._cipher.encryptBlock(self._prev)
2882 bit = (byteParam & (1 << (7 - i))) ? 0x80 : 0
2883 value = pad[0] ^ bit
2884 out += ((value & 0x80) >> (i % 8))
2885 self._prev = shiftIn(self._prev, decrypt ? bit : value)
2886 }
2887 return out
2888 }
2889
2890 function shiftIn (buffer, value) {
2891 var len = buffer.length
2892 var i = -1
2893 var out = Buffer.allocUnsafe(buffer.length)
2894 buffer = Buffer.concat([buffer, Buffer.from([value])])
2895
2896 while (++i < len) {
2897 out[i] = buffer[i] << 1 | buffer[i + 1] >> (7)
2898 }
2899
2900 return out
2901 }
2902
2903 exports.encrypt = function (self, chunk, decrypt) {
2904 var len = chunk.length
2905 var out = Buffer.allocUnsafe(len)
2906 var i = -1
2907
2908 while (++i < len) {
2909 out[i] = encryptByte(self, chunk[i], decrypt)
2910 }
2911
2912 return out
2913 }
2914
2915 },{"safe-buffer":47}],17:[function(require,module,exports){
2916 var Buffer = require('safe-buffer').Buffer
2917
2918 function encryptByte (self, byteParam, decrypt) {
2919 var pad = self._cipher.encryptBlock(self._prev)
2920 var out = pad[0] ^ byteParam
2921
2922 self._prev = Buffer.concat([
2923 self._prev.slice(1),
2924 Buffer.from([decrypt ? byteParam : out])
2925 ])
2926
2927 return out
2928 }
2929
2930 exports.encrypt = function (self, chunk, decrypt) {
2931 var len = chunk.length
2932 var out = Buffer.allocUnsafe(len)
2933 var i = -1
2934
2935 while (++i < len) {
2936 out[i] = encryptByte(self, chunk[i], decrypt)
2937 }
2938
2939 return out
2940 }
2941
2942 },{"safe-buffer":47}],18:[function(require,module,exports){
2943 var xor = require('buffer-xor')
2944 var Buffer = require('safe-buffer').Buffer
2945 var incr32 = require('../incr32')
2946
2947 function getBlock (self) {
2948 var out = self._cipher.encryptBlockRaw(self._prev)
2949 incr32(self._prev)
2950 return out
2951 }
2952
2953 var blockSize = 16
2954 exports.encrypt = function (self, chunk) {
2955 var chunkNum = Math.ceil(chunk.length / blockSize)
2956 var start = self._cache.length
2957 self._cache = Buffer.concat([
2958 self._cache,
2959 Buffer.allocUnsafe(chunkNum * blockSize)
2960 ])
2961 for (var i = 0; i < chunkNum; i++) {
2962 var out = getBlock(self)
2963 var offset = start + i * blockSize
2964 self._cache.writeUInt32BE(out[0], offset + 0)
2965 self._cache.writeUInt32BE(out[1], offset + 4)
2966 self._cache.writeUInt32BE(out[2], offset + 8)
2967 self._cache.writeUInt32BE(out[3], offset + 12)
2968 }
2969 var pad = self._cache.slice(0, chunk.length)
2970 self._cache = self._cache.slice(chunk.length)
2971 return xor(chunk, pad)
2972 }
2973
2974 },{"../incr32":13,"buffer-xor":29,"safe-buffer":47}],19:[function(require,module,exports){
2975 exports.encrypt = function (self, block) {
2976 return self._cipher.encryptBlock(block)
2977 }
2978
2979 exports.decrypt = function (self, block) {
2980 return self._cipher.decryptBlock(block)
2981 }
2982
2983 },{}],20:[function(require,module,exports){
2984 var modeModules = {
2985 ECB: require('./ecb'),
2986 CBC: require('./cbc'),
2987 CFB: require('./cfb'),
2988 CFB8: require('./cfb8'),
2989 CFB1: require('./cfb1'),
2990 OFB: require('./ofb'),
2991 CTR: require('./ctr'),
2992 GCM: require('./ctr')
2993 }
2994
2995 var modes = require('./list.json')
2996
2997 for (var key in modes) {
2998 modes[key].module = modeModules[modes[key].mode]
2999 }
3000
3001 module.exports = modes
3002
3003 },{"./cbc":14,"./cfb":15,"./cfb1":16,"./cfb8":17,"./ctr":18,"./ecb":19,"./list.json":21,"./ofb":22}],21:[function(require,module,exports){
3004 module.exports={
3005 "aes-128-ecb": {
3006 "cipher": "AES",
3007 "key": 128,
3008 "iv": 0,
3009 "mode": "ECB",
3010 "type": "block"
3011 },
3012 "aes-192-ecb": {
3013 "cipher": "AES",
3014 "key": 192,
3015 "iv": 0,
3016 "mode": "ECB",
3017 "type": "block"
3018 },
3019 "aes-256-ecb": {
3020 "cipher": "AES",
3021 "key": 256,
3022 "iv": 0,
3023 "mode": "ECB",
3024 "type": "block"
3025 },
3026 "aes-128-cbc": {
3027 "cipher": "AES",
3028 "key": 128,
3029 "iv": 16,
3030 "mode": "CBC",
3031 "type": "block"
3032 },
3033 "aes-192-cbc": {
3034 "cipher": "AES",
3035 "key": 192,
3036 "iv": 16,
3037 "mode": "CBC",
3038 "type": "block"
3039 },
3040 "aes-256-cbc": {
3041 "cipher": "AES",
3042 "key": 256,
3043 "iv": 16,
3044 "mode": "CBC",
3045 "type": "block"
3046 },
3047 "aes128": {
3048 "cipher": "AES",
3049 "key": 128,
3050 "iv": 16,
3051 "mode": "CBC",
3052 "type": "block"
3053 },
3054 "aes192": {
3055 "cipher": "AES",
3056 "key": 192,
3057 "iv": 16,
3058 "mode": "CBC",
3059 "type": "block"
3060 },
3061 "aes256": {
3062 "cipher": "AES",
3063 "key": 256,
3064 "iv": 16,
3065 "mode": "CBC",
3066 "type": "block"
3067 },
3068 "aes-128-cfb": {
3069 "cipher": "AES",
3070 "key": 128,
3071 "iv": 16,
3072 "mode": "CFB",
3073 "type": "stream"
3074 },
3075 "aes-192-cfb": {
3076 "cipher": "AES",
3077 "key": 192,
3078 "iv": 16,
3079 "mode": "CFB",
3080 "type": "stream"
3081 },
3082 "aes-256-cfb": {
3083 "cipher": "AES",
3084 "key": 256,
3085 "iv": 16,
3086 "mode": "CFB",
3087 "type": "stream"
3088 },
3089 "aes-128-cfb8": {
3090 "cipher": "AES",
3091 "key": 128,
3092 "iv": 16,
3093 "mode": "CFB8",
3094 "type": "stream"
3095 },
3096 "aes-192-cfb8": {
3097 "cipher": "AES",
3098 "key": 192,
3099 "iv": 16,
3100 "mode": "CFB8",
3101 "type": "stream"
3102 },
3103 "aes-256-cfb8": {
3104 "cipher": "AES",
3105 "key": 256,
3106 "iv": 16,
3107 "mode": "CFB8",
3108 "type": "stream"
3109 },
3110 "aes-128-cfb1": {
3111 "cipher": "AES",
3112 "key": 128,
3113 "iv": 16,
3114 "mode": "CFB1",
3115 "type": "stream"
3116 },
3117 "aes-192-cfb1": {
3118 "cipher": "AES",
3119 "key": 192,
3120 "iv": 16,
3121 "mode": "CFB1",
3122 "type": "stream"
3123 },
3124 "aes-256-cfb1": {
3125 "cipher": "AES",
3126 "key": 256,
3127 "iv": 16,
3128 "mode": "CFB1",
3129 "type": "stream"
3130 },
3131 "aes-128-ofb": {
3132 "cipher": "AES",
3133 "key": 128,
3134 "iv": 16,
3135 "mode": "OFB",
3136 "type": "stream"
3137 },
3138 "aes-192-ofb": {
3139 "cipher": "AES",
3140 "key": 192,
3141 "iv": 16,
3142 "mode": "OFB",
3143 "type": "stream"
3144 },
3145 "aes-256-ofb": {
3146 "cipher": "AES",
3147 "key": 256,
3148 "iv": 16,
3149 "mode": "OFB",
3150 "type": "stream"
3151 },
3152 "aes-128-ctr": {
3153 "cipher": "AES",
3154 "key": 128,
3155 "iv": 16,
3156 "mode": "CTR",
3157 "type": "stream"
3158 },
3159 "aes-192-ctr": {
3160 "cipher": "AES",
3161 "key": 192,
3162 "iv": 16,
3163 "mode": "CTR",
3164 "type": "stream"
3165 },
3166 "aes-256-ctr": {
3167 "cipher": "AES",
3168 "key": 256,
3169 "iv": 16,
3170 "mode": "CTR",
3171 "type": "stream"
3172 },
3173 "aes-128-gcm": {
3174 "cipher": "AES",
3175 "key": 128,
3176 "iv": 12,
3177 "mode": "GCM",
3178 "type": "auth"
3179 },
3180 "aes-192-gcm": {
3181 "cipher": "AES",
3182 "key": 192,
3183 "iv": 12,
3184 "mode": "GCM",
3185 "type": "auth"
3186 },
3187 "aes-256-gcm": {
3188 "cipher": "AES",
3189 "key": 256,
3190 "iv": 12,
3191 "mode": "GCM",
3192 "type": "auth"
3193 }
3194 }
3195
3196 },{}],22:[function(require,module,exports){
3197 (function (Buffer){
3198 var xor = require('buffer-xor')
3199
3200 function getBlock (self) {
3201 self._prev = self._cipher.encryptBlock(self._prev)
3202 return self._prev
3203 }
3204
3205 exports.encrypt = function (self, chunk) {
3206 while (self._cache.length < chunk.length) {
3207 self._cache = Buffer.concat([self._cache, getBlock(self)])
3208 }
3209
3210 var pad = self._cache.slice(0, chunk.length)
3211 self._cache = self._cache.slice(chunk.length)
3212 return xor(chunk, pad)
3213 }
3214
3215 }).call(this,require("buffer").Buffer)
3216 },{"buffer":110,"buffer-xor":29}],23:[function(require,module,exports){
3217 var aes = require('./aes')
3218 var Buffer = require('safe-buffer').Buffer
3219 var Transform = require('cipher-base')
3220 var inherits = require('inherits')
3221
3222 function StreamCipher (mode, key, iv, decrypt) {
3223 Transform.call(this)
3224
3225 this._cipher = new aes.AES(key)
3226 this._prev = Buffer.from(iv)
3227 this._cache = Buffer.allocUnsafe(0)
3228 this._secCache = Buffer.allocUnsafe(0)
3229 this._decrypt = decrypt
3230 this._mode = mode
3231 }
3232
3233 inherits(StreamCipher, Transform)
3234
3235 StreamCipher.prototype._update = function (chunk) {
3236 return this._mode.encrypt(this, chunk, this._decrypt)
3237 }
3238
3239 StreamCipher.prototype._final = function () {
3240 this._cipher.scrub()
3241 }
3242
3243 module.exports = StreamCipher
3244
3245 },{"./aes":7,"cipher-base":31,"inherits":44,"safe-buffer":47}],24:[function(require,module,exports){
3246 var basex = require('base-x')
3247 var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
3248
3249 module.exports = basex(ALPHABET)
3250
3251 },{"base-x":2}],25:[function(require,module,exports){
3252 'use strict'
3253
3254 var base58 = require('bs58')
3255 var Buffer = require('safe-buffer').Buffer
3256
3257 module.exports = function (checksumFn) {
3258 // Encode a buffer as a base58-check encoded string
3259 function encode (payload) {
3260 var checksum = checksumFn(payload)
3261
3262 return base58.encode(Buffer.concat([
3263 payload,
3264 checksum
3265 ], payload.length + 4))
3266 }
3267
3268 function decodeRaw (buffer) {
3269 var payload = buffer.slice(0, -4)
3270 var checksum = buffer.slice(-4)
3271 var newChecksum = checksumFn(payload)
3272
3273 if (checksum[0] ^ newChecksum[0] |
3274 checksum[1] ^ newChecksum[1] |
3275 checksum[2] ^ newChecksum[2] |
3276 checksum[3] ^ newChecksum[3]) return
3277
3278 return payload
3279 }
3280
3281 // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
3282 function decodeUnsafe (string) {
3283 var buffer = base58.decodeUnsafe(string)
3284 if (!buffer) return
3285
3286 return decodeRaw(buffer)
3287 }
3288
3289 function decode (string) {
3290 var buffer = base58.decode(string)
3291 var payload = decodeRaw(buffer, checksumFn)
3292 if (!payload) throw new Error('Invalid checksum')
3293 return payload
3294 }
3295
3296 return {
3297 encode: encode,
3298 decode: decode,
3299 decodeUnsafe: decodeUnsafe
3300 }
3301 }
3302
3303 },{"bs58":24,"safe-buffer":47}],26:[function(require,module,exports){
3304 'use strict'
3305
3306 var createHash = require('create-hash')
3307 var bs58checkBase = require('./base')
3308
3309 // SHA256(SHA256(buffer))
3310 function sha256x2 (buffer) {
3311 var tmp = createHash('sha256').update(buffer).digest()
3312 return createHash('sha256').update(tmp).digest()
3313 }
3314
3315 module.exports = bs58checkBase(sha256x2)
3316
3317 },{"./base":25,"create-hash":32}],27:[function(require,module,exports){
3318 arguments[4][25][0].apply(exports,arguments)
3319 },{"bs58":24,"dup":25,"safe-buffer":47}],28:[function(require,module,exports){
3320 (function (Buffer){
3321 'use strict'
3322
3323 var createHash = require('create-hash')
3324 var bs58grscheckBase = require('./base')
3325 var groestlhash = require('groestl-hash-js')
3326
3327 // GROESTL512(GROESTL512(buffer))
3328 function groestl (buffer) {
3329 return Buffer(groestlhash.groestl_2(buffer, 1, 1))
3330 }
3331
3332 module.exports = bs58grscheckBase(groestl)
3333
3334 }).call(this,require("buffer").Buffer)
3335 },{"./base":27,"buffer":110,"create-hash":32,"groestl-hash-js":39}],29:[function(require,module,exports){
3336 (function (Buffer){
3337 module.exports = function xor (a, b) {
3338 var length = Math.min(a.length, b.length)
3339 var buffer = new Buffer(length)
3340
3341 for (var i = 0; i < length; ++i) {
3342 buffer[i] = a[i] ^ b[i]
3343 }
3344
3345 return buffer
3346 }
3347
3348 }).call(this,require("buffer").Buffer)
3349 },{"buffer":110}],30:[function(require,module,exports){
3350 module.exports = function xorInplace (a, b) {
3351 var length = Math.min(a.length, b.length)
3352
3353 for (var i = 0; i < length; ++i) {
3354 a[i] = a[i] ^ b[i]
3355 }
3356
3357 return a.slice(0, length)
3358 }
3359
3360 },{}],31:[function(require,module,exports){
3361 var Buffer = require('safe-buffer').Buffer
3362 var Transform = require('stream').Transform
3363 var StringDecoder = require('string_decoder').StringDecoder
3364 var inherits = require('inherits')
3365
3366 function CipherBase (hashMode) {
3367 Transform.call(this)
3368 this.hashMode = typeof hashMode === 'string'
3369 if (this.hashMode) {
3370 this[hashMode] = this._finalOrDigest
3371 } else {
3372 this.final = this._finalOrDigest
3373 }
3374 if (this._final) {
3375 this.__final = this._final
3376 this._final = null
3377 }
3378 this._decoder = null
3379 this._encoding = null
3380 }
3381 inherits(CipherBase, Transform)
3382
3383 CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
3384 if (typeof data === 'string') {
3385 data = Buffer.from(data, inputEnc)
3386 }
3387
3388 var outData = this._update(data)
3389 if (this.hashMode) return this
3390
3391 if (outputEnc) {
3392 outData = this._toString(outData, outputEnc)
3393 }
3394
3395 return outData
3396 }
3397
3398 CipherBase.prototype.setAutoPadding = function () {}
3399 CipherBase.prototype.getAuthTag = function () {
3400 throw new Error('trying to get auth tag in unsupported state')
3401 }
3402
3403 CipherBase.prototype.setAuthTag = function () {
3404 throw new Error('trying to set auth tag in unsupported state')
3405 }
3406
3407 CipherBase.prototype.setAAD = function () {
3408 throw new Error('trying to set aad in unsupported state')
3409 }
3410
3411 CipherBase.prototype._transform = function (data, _, next) {
3412 var err
3413 try {
3414 if (this.hashMode) {
3415 this._update(data)
3416 } else {
3417 this.push(this._update(data))
3418 }
3419 } catch (e) {
3420 err = e
3421 } finally {
3422 next(err)
3423 }
3424 }
3425 CipherBase.prototype._flush = function (done) {
3426 var err
3427 try {
3428 this.push(this.__final())
3429 } catch (e) {
3430 err = e
3431 }
3432
3433 done(err)
3434 }
3435 CipherBase.prototype._finalOrDigest = function (outputEnc) {
3436 var outData = this.__final() || Buffer.alloc(0)
3437 if (outputEnc) {
3438 outData = this._toString(outData, outputEnc, true)
3439 }
3440 return outData
3441 }
3442
3443 CipherBase.prototype._toString = function (value, enc, fin) {
3444 if (!this._decoder) {
3445 this._decoder = new StringDecoder(enc)
3446 this._encoding = enc
3447 }
3448
3449 if (this._encoding !== enc) throw new Error('can\'t switch encodings')
3450
3451 var out = this._decoder.write(value)
3452 if (fin) {
3453 out += this._decoder.end()
3454 }
3455
3456 return out
3457 }
3458
3459 module.exports = CipherBase
3460
3461 },{"inherits":44,"safe-buffer":47,"stream":215,"string_decoder":216}],32:[function(require,module,exports){
3462 'use strict'
3463 var inherits = require('inherits')
3464 var MD5 = require('md5.js')
3465 var RIPEMD160 = require('ripemd160')
3466 var sha = require('sha.js')
3467 var Base = require('cipher-base')
3468
3469 function Hash (hash) {
3470 Base.call(this, 'digest')
3471
3472 this._hash = hash
3473 }
3474
3475 inherits(Hash, Base)
3476
3477 Hash.prototype._update = function (data) {
3478 this._hash.update(data)
3479 }
3480
3481 Hash.prototype._final = function () {
3482 return this._hash.digest()
3483 }
3484
3485 module.exports = function createHash (alg) {
3486 alg = alg.toLowerCase()
3487 if (alg === 'md5') return new MD5()
3488 if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160()
3489
3490 return new Hash(sha(alg))
3491 }
3492
3493 },{"cipher-base":31,"inherits":44,"md5.js":45,"ripemd160":46,"sha.js":53}],33:[function(require,module,exports){
3494 var assert = require('assert')
3495 var BigInteger = require('bigi')
3496
3497 var Point = require('./point')
3498
3499 function Curve (p, a, b, Gx, Gy, n, h) {
3500 this.p = p
3501 this.a = a
3502 this.b = b
3503 this.G = Point.fromAffine(this, Gx, Gy)
3504 this.n = n
3505 this.h = h
3506
3507 this.infinity = new Point(this, null, null, BigInteger.ZERO)
3508
3509 // result caching
3510 this.pOverFour = p.add(BigInteger.ONE).shiftRight(2)
3511
3512 // determine size of p in bytes
3513 this.pLength = Math.floor((this.p.bitLength() + 7) / 8)
3514 }
3515
3516 Curve.prototype.pointFromX = function (isOdd, x) {
3517 var alpha = x.pow(3).add(this.a.multiply(x)).add(this.b).mod(this.p)
3518 var beta = alpha.modPow(this.pOverFour, this.p) // XXX: not compatible with all curves
3519
3520 var y = beta
3521 if (beta.isEven() ^ !isOdd) {
3522 y = this.p.subtract(y) // -y % p
3523 }
3524
3525 return Point.fromAffine(this, x, y)
3526 }
3527
3528 Curve.prototype.isInfinity = function (Q) {
3529 if (Q === this.infinity) return true
3530
3531 return Q.z.signum() === 0 && Q.y.signum() !== 0
3532 }
3533
3534 Curve.prototype.isOnCurve = function (Q) {
3535 if (this.isInfinity(Q)) return true
3536
3537 var x = Q.affineX
3538 var y = Q.affineY
3539 var a = this.a
3540 var b = this.b
3541 var p = this.p
3542
3543 // Check that xQ and yQ are integers in the interval [0, p - 1]
3544 if (x.signum() < 0 || x.compareTo(p) >= 0) return false
3545 if (y.signum() < 0 || y.compareTo(p) >= 0) return false
3546
3547 // and check that y^2 = x^3 + ax + b (mod p)
3548 var lhs = y.square().mod(p)
3549 var rhs = x.pow(3).add(a.multiply(x)).add(b).mod(p)
3550 return lhs.equals(rhs)
3551 }
3552
3553 /**
3554 * Validate an elliptic curve point.
3555 *
3556 * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive
3557 */
3558 Curve.prototype.validate = function (Q) {
3559 // Check Q != O
3560 assert(!this.isInfinity(Q), 'Point is at infinity')
3561 assert(this.isOnCurve(Q), 'Point is not on the curve')
3562
3563 // Check nQ = O (where Q is a scalar multiple of G)
3564 var nQ = Q.multiply(this.n)
3565 assert(this.isInfinity(nQ), 'Point is not a scalar multiple of G')
3566
3567 return true
3568 }
3569
3570 module.exports = Curve
3571
3572 },{"./point":37,"assert":74,"bigi":5}],34:[function(require,module,exports){
3573 module.exports={
3574 "secp128r1": {
3575 "p": "fffffffdffffffffffffffffffffffff",
3576 "a": "fffffffdfffffffffffffffffffffffc",
3577 "b": "e87579c11079f43dd824993c2cee5ed3",
3578 "n": "fffffffe0000000075a30d1b9038a115",
3579 "h": "01",
3580 "Gx": "161ff7528b899b2d0c28607ca52c5b86",
3581 "Gy": "cf5ac8395bafeb13c02da292dded7a83"
3582 },
3583 "secp160k1": {
3584 "p": "fffffffffffffffffffffffffffffffeffffac73",
3585 "a": "00",
3586 "b": "07",
3587 "n": "0100000000000000000001b8fa16dfab9aca16b6b3",
3588 "h": "01",
3589 "Gx": "3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",
3590 "Gy": "938cf935318fdced6bc28286531733c3f03c4fee"
3591 },
3592 "secp160r1": {
3593 "p": "ffffffffffffffffffffffffffffffff7fffffff",
3594 "a": "ffffffffffffffffffffffffffffffff7ffffffc",
3595 "b": "1c97befc54bd7a8b65acf89f81d4d4adc565fa45",
3596 "n": "0100000000000000000001f4c8f927aed3ca752257",
3597 "h": "01",
3598 "Gx": "4a96b5688ef573284664698968c38bb913cbfc82",
3599 "Gy": "23a628553168947d59dcc912042351377ac5fb32"
3600 },
3601 "secp192k1": {
3602 "p": "fffffffffffffffffffffffffffffffffffffffeffffee37",
3603 "a": "00",
3604 "b": "03",
3605 "n": "fffffffffffffffffffffffe26f2fc170f69466a74defd8d",
3606 "h": "01",
3607 "Gx": "db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",
3608 "Gy": "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"
3609 },
3610 "secp192r1": {
3611 "p": "fffffffffffffffffffffffffffffffeffffffffffffffff",
3612 "a": "fffffffffffffffffffffffffffffffefffffffffffffffc",
3613 "b": "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",
3614 "n": "ffffffffffffffffffffffff99def836146bc9b1b4d22831",
3615 "h": "01",
3616 "Gx": "188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
3617 "Gy": "07192b95ffc8da78631011ed6b24cdd573f977a11e794811"
3618 },
3619 "secp256k1": {
3620 "p": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
3621 "a": "00",
3622 "b": "07",
3623 "n": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
3624 "h": "01",
3625 "Gx": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
3626 "Gy": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
3627 },
3628 "secp256r1": {
3629 "p": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
3630 "a": "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",
3631 "b": "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
3632 "n": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
3633 "h": "01",
3634 "Gx": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
3635 "Gy": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
3636 }
3637 }
3638
3639 },{}],35:[function(require,module,exports){
3640 var Point = require('./point')
3641 var Curve = require('./curve')
3642
3643 var getCurveByName = require('./names')
3644
3645 module.exports = {
3646 Curve: Curve,
3647 Point: Point,
3648 getCurveByName: getCurveByName
3649 }
3650
3651 },{"./curve":33,"./names":36,"./point":37}],36:[function(require,module,exports){
3652 var BigInteger = require('bigi')
3653
3654 var curves = require('./curves.json')
3655 var Curve = require('./curve')
3656
3657 function getCurveByName (name) {
3658 var curve = curves[name]
3659 if (!curve) return null
3660
3661 var p = new BigInteger(curve.p, 16)
3662 var a = new BigInteger(curve.a, 16)
3663 var b = new BigInteger(curve.b, 16)
3664 var n = new BigInteger(curve.n, 16)
3665 var h = new BigInteger(curve.h, 16)
3666 var Gx = new BigInteger(curve.Gx, 16)
3667 var Gy = new BigInteger(curve.Gy, 16)
3668
3669 return new Curve(p, a, b, Gx, Gy, n, h)
3670 }
3671
3672 module.exports = getCurveByName
3673
3674 },{"./curve":33,"./curves.json":34,"bigi":5}],37:[function(require,module,exports){
3675 var assert = require('assert')
3676 var Buffer = require('safe-buffer').Buffer
3677 var BigInteger = require('bigi')
3678
3679 var THREE = BigInteger.valueOf(3)
3680
3681 function Point (curve, x, y, z) {
3682 assert.notStrictEqual(z, undefined, 'Missing Z coordinate')
3683
3684 this.curve = curve
3685 this.x = x
3686 this.y = y
3687 this.z = z
3688 this._zInv = null
3689
3690 this.compressed = true
3691 }
3692
3693 Object.defineProperty(Point.prototype, 'zInv', {
3694 get: function () {
3695 if (this._zInv === null) {
3696 this._zInv = this.z.modInverse(this.curve.p)
3697 }
3698
3699 return this._zInv
3700 }
3701 })
3702
3703 Object.defineProperty(Point.prototype, 'affineX', {
3704 get: function () {
3705 return this.x.multiply(this.zInv).mod(this.curve.p)
3706 }
3707 })
3708
3709 Object.defineProperty(Point.prototype, 'affineY', {
3710 get: function () {
3711 return this.y.multiply(this.zInv).mod(this.curve.p)
3712 }
3713 })
3714
3715 Point.fromAffine = function (curve, x, y) {
3716 return new Point(curve, x, y, BigInteger.ONE)
3717 }
3718
3719 Point.prototype.equals = function (other) {
3720 if (other === this) return true
3721 if (this.curve.isInfinity(this)) return this.curve.isInfinity(other)
3722 if (this.curve.isInfinity(other)) return this.curve.isInfinity(this)
3723
3724 // u = Y2 * Z1 - Y1 * Z2
3725 var u = other.y.multiply(this.z).subtract(this.y.multiply(other.z)).mod(this.curve.p)
3726
3727 if (u.signum() !== 0) return false
3728
3729 // v = X2 * Z1 - X1 * Z2
3730 var v = other.x.multiply(this.z).subtract(this.x.multiply(other.z)).mod(this.curve.p)
3731
3732 return v.signum() === 0
3733 }
3734
3735 Point.prototype.negate = function () {
3736 var y = this.curve.p.subtract(this.y)
3737
3738 return new Point(this.curve, this.x, y, this.z)
3739 }
3740
3741 Point.prototype.add = function (b) {
3742 if (this.curve.isInfinity(this)) return b
3743 if (this.curve.isInfinity(b)) return this
3744
3745 var x1 = this.x
3746 var y1 = this.y
3747 var x2 = b.x
3748 var y2 = b.y
3749
3750 // u = Y2 * Z1 - Y1 * Z2
3751 var u = y2.multiply(this.z).subtract(y1.multiply(b.z)).mod(this.curve.p)
3752 // v = X2 * Z1 - X1 * Z2
3753 var v = x2.multiply(this.z).subtract(x1.multiply(b.z)).mod(this.curve.p)
3754
3755 if (v.signum() === 0) {
3756 if (u.signum() === 0) {
3757 return this.twice() // this == b, so double
3758 }
3759
3760 return this.curve.infinity // this = -b, so infinity
3761 }
3762
3763 var v2 = v.square()
3764 var v3 = v2.multiply(v)
3765 var x1v2 = x1.multiply(v2)
3766 var zu2 = u.square().multiply(this.z)
3767
3768 // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
3769 var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.p)
3770 // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
3771 var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.p)
3772 // z3 = v^3 * z1 * z2
3773 var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.p)
3774
3775 return new Point(this.curve, x3, y3, z3)
3776 }
3777
3778 Point.prototype.twice = function () {
3779 if (this.curve.isInfinity(this)) return this
3780 if (this.y.signum() === 0) return this.curve.infinity
3781
3782 var x1 = this.x
3783 var y1 = this.y
3784
3785 var y1z1 = y1.multiply(this.z).mod(this.curve.p)
3786 var y1sqz1 = y1z1.multiply(y1).mod(this.curve.p)
3787 var a = this.curve.a
3788
3789 // w = 3 * x1^2 + a * z1^2
3790 var w = x1.square().multiply(THREE)
3791
3792 if (a.signum() !== 0) {
3793 w = w.add(this.z.square().multiply(a))
3794 }
3795
3796 w = w.mod(this.curve.p)
3797 // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
3798 var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.p)
3799 // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
3800 var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.pow(3)).mod(this.curve.p)
3801 // z3 = 8 * (y1 * z1)^3
3802 var z3 = y1z1.pow(3).shiftLeft(3).mod(this.curve.p)
3803
3804 return new Point(this.curve, x3, y3, z3)
3805 }
3806
3807 // Simple NAF (Non-Adjacent Form) multiplication algorithm
3808 // TODO: modularize the multiplication algorithm
3809 Point.prototype.multiply = function (k) {
3810 if (this.curve.isInfinity(this)) return this
3811 if (k.signum() === 0) return this.curve.infinity
3812
3813 var e = k
3814 var h = e.multiply(THREE)
3815
3816 var neg = this.negate()
3817 var R = this
3818
3819 for (var i = h.bitLength() - 2; i > 0; --i) {
3820 var hBit = h.testBit(i)
3821 var eBit = e.testBit(i)
3822
3823 R = R.twice()
3824
3825 if (hBit !== eBit) {
3826 R = R.add(hBit ? this : neg)
3827 }
3828 }
3829
3830 return R
3831 }
3832
3833 // Compute this*j + x*k (simultaneous multiplication)
3834 Point.prototype.multiplyTwo = function (j, x, k) {
3835 var i = Math.max(j.bitLength(), k.bitLength()) - 1
3836 var R = this.curve.infinity
3837 var both = this.add(x)
3838
3839 while (i >= 0) {
3840 var jBit = j.testBit(i)
3841 var kBit = k.testBit(i)
3842
3843 R = R.twice()
3844
3845 if (jBit) {
3846 if (kBit) {
3847 R = R.add(both)
3848 } else {
3849 R = R.add(this)
3850 }
3851 } else if (kBit) {
3852 R = R.add(x)
3853 }
3854 --i
3855 }
3856
3857 return R
3858 }
3859
3860 Point.prototype.getEncoded = function (compressed) {
3861 if (compressed == null) compressed = this.compressed
3862 if (this.curve.isInfinity(this)) return Buffer.alloc(1, 0) // Infinity point encoded is simply '00'
3863
3864 var x = this.affineX
3865 var y = this.affineY
3866 var byteLength = this.curve.pLength
3867 var buffer
3868
3869 // 0x02/0x03 | X
3870 if (compressed) {
3871 buffer = Buffer.allocUnsafe(1 + byteLength)
3872 buffer.writeUInt8(y.isEven() ? 0x02 : 0x03, 0)
3873
3874 // 0x04 | X | Y
3875 } else {
3876 buffer = Buffer.allocUnsafe(1 + byteLength + byteLength)
3877 buffer.writeUInt8(0x04, 0)
3878
3879 y.toBuffer(byteLength).copy(buffer, 1 + byteLength)
3880 }
3881
3882 x.toBuffer(byteLength).copy(buffer, 1)
3883
3884 return buffer
3885 }
3886
3887 Point.decodeFrom = function (curve, buffer) {
3888 var type = buffer.readUInt8(0)
3889 var compressed = (type !== 4)
3890
3891 var byteLength = Math.floor((curve.p.bitLength() + 7) / 8)
3892 var x = BigInteger.fromBuffer(buffer.slice(1, 1 + byteLength))
3893
3894 var Q
3895 if (compressed) {
3896 assert.equal(buffer.length, byteLength + 1, 'Invalid sequence length')
3897 assert(type === 0x02 || type === 0x03, 'Invalid sequence tag')
3898
3899 var isOdd = (type === 0x03)
3900 Q = curve.pointFromX(isOdd, x)
3901 } else {
3902 assert.equal(buffer.length, 1 + byteLength + byteLength, 'Invalid sequence length')
3903
3904 var y = BigInteger.fromBuffer(buffer.slice(1 + byteLength))
3905 Q = Point.fromAffine(curve, x, y)
3906 }
3907
3908 Q.compressed = compressed
3909 return Q
3910 }
3911
3912 Point.prototype.toString = function () {
3913 if (this.curve.isInfinity(this)) return '(INFINITY)'
3914
3915 return '(' + this.affineX.toString() + ',' + this.affineY.toString() + ')'
3916 }
3917
3918 module.exports = Point
3919
3920 },{"assert":74,"bigi":5,"safe-buffer":47}],38:[function(require,module,exports){
3921 var Buffer = require('safe-buffer').Buffer
3922 var MD5 = require('md5.js')
3923
3924 /* eslint-disable camelcase */
3925 function EVP_BytesToKey (password, salt, keyBits, ivLen) {
3926 if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary')
3927 if (salt) {
3928 if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary')
3929 if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length')
3930 }
3931
3932 var keyLen = keyBits / 8
3933 var key = Buffer.alloc(keyLen)
3934 var iv = Buffer.alloc(ivLen || 0)
3935 var tmp = Buffer.alloc(0)
3936
3937 while (keyLen > 0 || ivLen > 0) {
3938 var hash = new MD5()
3939 hash.update(tmp)
3940 hash.update(password)
3941 if (salt) hash.update(salt)
3942 tmp = hash.digest()
3943
3944 var used = 0
3945
3946 if (keyLen > 0) {
3947 var keyStart = key.length - keyLen
3948 used = Math.min(keyLen, tmp.length)
3949 tmp.copy(key, keyStart, 0, used)
3950 keyLen -= used
3951 }
3952
3953 if (used < tmp.length && ivLen > 0) {
3954 var ivStart = iv.length - ivLen
3955 var length = Math.min(ivLen, tmp.length - used)
3956 tmp.copy(iv, ivStart, used, used + length)
3957 ivLen -= length
3958 }
3959 }
3960
3961 tmp.fill(0)
3962 return { key: key, iv: iv }
3963 }
3964
3965 module.exports = EVP_BytesToKey
3966
3967 },{"md5.js":45,"safe-buffer":47}],39:[function(require,module,exports){
3968 'use strict';
3969
3970 var groestl = require('./lib/groestl');
3971 var h = require('./lib/helper');
3972
3973 var x11hash = module.exports;
3974
3975 module.exports.groestl512 = function(str,format, output) {
3976 return groestl(str,format,output);
3977 }
3978
3979 module.exports.groestl = function(str,format, output) {
3980 var a = groestl(str,format,2);
3981 a = a.slice(0,8);
3982 if (output === 2) {
3983 return a;
3984 }
3985 else if (output === 1) {
3986 return h.int32Buffer2Bytes(a);
3987 }
3988 else {
3989 return h.int32ArrayToHexString(a);
3990 }
3991 }
3992
3993 module.exports.groestl_2 = function(str,format, output) {
3994 var a = groestl(str,format,2);
3995 a = groestl(a,2,2);
3996 a = a.slice(0,8);
3997 if (output === 2) {
3998 return a;
3999 }
4000 else if (output === 1) {
4001 return h.int32Buffer2Bytes(a);
4002 }
4003 else {
4004 return h.int32ArrayToHexString(a);
4005 }
4006 }
4007 },{"./lib/groestl":40,"./lib/helper":41}],40:[function(require,module,exports){
4008 /////////////////////////////////////
4009 //////////// groestl ///////////////
4010
4011 //// Written by Quantum Explorer ////
4012 ////////// Dash Foundation //////////
4013 /// Released under the MIT License //
4014 /////////////////////////////////////
4015
4016 var o = require('./op');
4017 var h = require('./helper');
4018
4019 var 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="));
4020 var 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="));
4021 var 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="));
4022 var 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="));
4023 var 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="));
4024 var 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="));
4025 var 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="));
4026 var T7 = h.bytes2Int64Buffer(h.b64Decode("MvSl9JelxsZvl4SX64T4+F6wmbDHme7ueoyNjPeN9vboFw0X5Q3//wrcvdy3vdbWFsixyKex3t5t/FT8OVSRkZDwUPDAUGBgBwUDBQQDAgIu4Kngh6nOztGHfYesfVZWzCsZK9UZ5+cTpmKmcWK1tXwx5jGa5k1NWbWatcOa7OxAz0XPBUWPj6O8nbw+nR8fScBAwAlAiYlokoeS74f6+tA/FT/FFe/vlCbrJn/rsrLOQMlAB8mOjuYdCx3tC/v7bi/sL4LsQUEaqWepfWezs0Mc/Ry+/V9fYCXqJYrqRUX52r/aRr8jI1EC9wKm91NTRaGWodOW5OR27VvtLVubmyhdwl3qwnV1xSQcJNkc4eHU6a7peq49PfK+ar6YakxMgu5a7thabGy9w0HD/EF+fvMGAgbxAvX1UtFP0R1Pg4OM5Fzk0FxoaFYH9Aei9FFRjVw0XLk00dHhGAgY6Qj5+Uyuk67fk+LiPpVzlU1zq6uX9VP1xFNiYmtBP0FUPyoqHBQMFBAMCAhj9lL2MVKVlemvZa+MZUZGf+Je4iFenZ1IeCh4YCgwMM/4ofhuoTc3GxEPERQPCgrrxLXEXrUvLxUbCRscCQ4Oflo2Wkg2JCSttpu2NpsbG5hHPUelPd/fp2omaoEmzc31u2m7nGlOTjNMzUz+zX9/ULqfus+f6uo/LRstJBsSEqS5nrk6nh0dxJx0nLB0WFhGci5yaC40NEF3LXdsLTY2Ec2yzaOy3NydKe4pc+60tE0W+xa2+1tbpQH2AVP2pKSh103X7E12dhSjYaN1Ybe3NEnOSfrOfX3fjXuNpHtSUp9CPkKhPt3dzZNxk7xxXl6xopeiJpcTE6IE9QRX9aamAbhouGloubkAAAAAAAAAALV0LHSZLMHB4KBgoIBgQEDCIR8h3R/j4zpDyEPyyHl5miztLHfttrYN2b7Zs77U1EfKRsoBRo2NF3DZcM7ZZ2ev3Uvd5Etycu153nkz3pSU/2fUZyvUmJiTI+gje+iwsFveSt4RSoWFBr1rvW1ru7u7fip+kSrFxXs05TSe5U9P1zoWOsEW7e3SVMVUF8WGhvhi12Iv15qamf9V/8xVZma2p5SnIpQREcBKz0oPz4qK2TAQMMkQ6ekOCgYKCAYEBGaYgZjngf7+qwvwC1vwoKC0zETM8ER4ePDVutVKuiUldT7jPpbjS0usDvMOX/OiokQZ/hm6/l1d21vAWxvAgICAhYqFCooFBdPsrex+rT8//t+830K8ISGo2EjY4EhwcP0MBAz5BPHxGXrfesbfY2MvWMFY7sF3dzCfdZ9Fda+v56VjpYRjQkJwUDBQQDAgIMsuGi7RGuXl7xIOEuEO/f0It223ZW2/v1XUTNQZTIGBJDwUPDAUGBh5XzVfTDUmJrJxL3GdL8PDhjjhOGfhvr7I/aL9aqI1NcdPzE8LzIiIZUs5S1w5Li5q+Vf5PVeTk1gN8g2q8lVVYZ2CneOC/PyzyUfJ9Ed6eifvrO+LrMjIiDLnMm/nurpPfSt9ZCsyMkKklaTXlebmO/ug+5ugwMCqs5izMpgZGfZo0Wgn0Z6eIoF/gV1/o6PuqmaqiGZERNaCfoKoflRU3ear5narOzuVnoOeFoMLC8lFykUDyoyMvHspe5Upx8cFbtNu1tNra2xEPERQPCgoLIt5i1V5p6eBPeI9Y+K8vDEnHScsHRYWN5p2mkF2ra2WTTtNrTvb2576VvrIVmRkptJO0uhOdHQ2Ih4iKB4UFOR223Y/25KSEh4KHhgKDAz8tGy0kGxISI835Ddr5Li4eOdd5yVdn58Psm6yYW69vWkq7yqG70NDNfGm8ZOmxMTa46jjcqg5Ocb3pPdipDExilk3Wb0309N0houG/4vy8oNWMlaxMtXVTsVDxQ1Di4uF61nr3FlubhjCt8Kvt9rajo+MjwKMAQEdrGSseWSxsfFt0m0j0pyccjvgO5LgSUkfx7THq7TY2LkV+hVD+qys+gkHCf0H8/OgbyVvhSXPzyDqr+qPr8rKfYmOifOO9PRnIOkgjulHRzgoGCggGBAQC2TVZN7Vb29zg4iD+4jw8Puxb7GUb0pKypZylrhyXFxUbCRscCQ4OF8I8Qiu8VdXIVLHUubHc3Nk81HzNVGXl65lI2WNI8vLJYR8hFl8oaFXv5y/y5zo6F1jIWN8IT4+6nzdfDfdlpYef9x/wtxhYZyRhpEahg0Nm5SFlB6FDw9Lq5Cr25Dg4LrGQsb4Qnx8JlfEV+LEcXEp5arlg6rMzONz2HM72JCQCQ8FDwwFBgb0AwED9QH39yo2EjY4EhwcPP6j/p+jwsKL4V/h1F9qar4Q+RBH+a6uAmvQa9LQaWm/qJGoLpEXF3HoWOgpWJmZU2knaXQnOjr30LnQTrknJ5FIOEipONnZ3jUTNc0T6+vlzrPOVrMrK3dVM1VEMyIiBNa71r+70tI5kHCQSXCpqYeAiYAOiQcHwfKn8manMzPswbbBWrYtLVpmImZ4Ijw8uK2SrSqSFRWpYCBgiSDJyVzbSdsVSYeHsBr/Gk//qqrYiHiIoHhQUCuOeo5ReqWliYqPigaPAwNKE/gTsvhZWZKbgJsSgAkJIzkXOTQXGhoQddp1ytplZYRTMVO1MdfX1VHGURPGhIQD07jTu7jQ0Nxew14fw4KC4suwy1KwKSnDmXeZtHdaWi0zETM8ER4ePUbLRvbLe3u3H/wfS/yoqAxh1mHa1m1tYk46Tlg6LCw="));
4027
4028 // var T0 = [
4029 // o.u(0xc632f4a5, 0xf497a5c6), o.u(0xf86f9784, 0x97eb84f8),
4030 // o.u(0xee5eb099, 0xb0c799ee), o.u(0xf67a8c8d, 0x8cf78df6),
4031 // o.u(0xffe8170d, 0x17e50dff), o.u(0xd60adcbd, 0xdcb7bdd6),
4032 // o.u(0xde16c8b1, 0xc8a7b1de), o.u(0x916dfc54, 0xfc395491),
4033 // o.u(0x6090f050, 0xf0c05060), o.u(0x02070503, 0x05040302),
4034 // o.u(0xce2ee0a9, 0xe087a9ce), o.u(0x56d1877d, 0x87ac7d56),
4035 // o.u(0xe7cc2b19, 0x2bd519e7), o.u(0xb513a662, 0xa67162b5),
4036 // o.u(0x4d7c31e6, 0x319ae64d), o.u(0xec59b59a, 0xb5c39aec),
4037 // o.u(0x8f40cf45, 0xcf05458f), o.u(0x1fa3bc9d, 0xbc3e9d1f),
4038 // o.u(0x8949c040, 0xc0094089), o.u(0xfa689287, 0x92ef87fa),
4039 // o.u(0xefd03f15, 0x3fc515ef), o.u(0xb29426eb, 0x267febb2),
4040 // o.u(0x8ece40c9, 0x4007c98e), o.u(0xfbe61d0b, 0x1ded0bfb),
4041 // o.u(0x416e2fec, 0x2f82ec41), o.u(0xb31aa967, 0xa97d67b3),
4042 // o.u(0x5f431cfd, 0x1cbefd5f), o.u(0x456025ea, 0x258aea45),
4043 // o.u(0x23f9dabf, 0xda46bf23), o.u(0x535102f7, 0x02a6f753),
4044 // o.u(0xe445a196, 0xa1d396e4), o.u(0x9b76ed5b, 0xed2d5b9b),
4045 // o.u(0x75285dc2, 0x5deac275), o.u(0xe1c5241c, 0x24d91ce1),
4046 // o.u(0x3dd4e9ae, 0xe97aae3d), o.u(0x4cf2be6a, 0xbe986a4c),
4047 // o.u(0x6c82ee5a, 0xeed85a6c), o.u(0x7ebdc341, 0xc3fc417e),
4048 // o.u(0xf5f30602, 0x06f102f5), o.u(0x8352d14f, 0xd11d4f83),
4049 // o.u(0x688ce45c, 0xe4d05c68), o.u(0x515607f4, 0x07a2f451),
4050 // o.u(0xd18d5c34, 0x5cb934d1), o.u(0xf9e11808, 0x18e908f9),
4051 // o.u(0xe24cae93, 0xaedf93e2), o.u(0xab3e9573, 0x954d73ab),
4052 // o.u(0x6297f553, 0xf5c45362), o.u(0x2a6b413f, 0x41543f2a),
4053 // o.u(0x081c140c, 0x14100c08), o.u(0x9563f652, 0xf6315295),
4054 // o.u(0x46e9af65, 0xaf8c6546), o.u(0x9d7fe25e, 0xe2215e9d),
4055 // o.u(0x30487828, 0x78602830), o.u(0x37cff8a1, 0xf86ea137),
4056 // o.u(0x0a1b110f, 0x11140f0a), o.u(0x2febc4b5, 0xc45eb52f),
4057 // o.u(0x0e151b09, 0x1b1c090e), o.u(0x247e5a36, 0x5a483624),
4058 // o.u(0x1badb69b, 0xb6369b1b), o.u(0xdf98473d, 0x47a53ddf),
4059 // o.u(0xcda76a26, 0x6a8126cd), o.u(0x4ef5bb69, 0xbb9c694e),
4060 // o.u(0x7f334ccd, 0x4cfecd7f), o.u(0xea50ba9f, 0xbacf9fea),
4061 // o.u(0x123f2d1b, 0x2d241b12), o.u(0x1da4b99e, 0xb93a9e1d),
4062 // o.u(0x58c49c74, 0x9cb07458), o.u(0x3446722e, 0x72682e34),
4063 // o.u(0x3641772d, 0x776c2d36), o.u(0xdc11cdb2, 0xcda3b2dc),
4064 // o.u(0xb49d29ee, 0x2973eeb4), o.u(0x5b4d16fb, 0x16b6fb5b),
4065 // o.u(0xa4a501f6, 0x0153f6a4), o.u(0x76a1d74d, 0xd7ec4d76),
4066 // o.u(0xb714a361, 0xa37561b7), o.u(0x7d3449ce, 0x49face7d),
4067 // o.u(0x52df8d7b, 0x8da47b52), o.u(0xdd9f423e, 0x42a13edd),
4068 // o.u(0x5ecd9371, 0x93bc715e), o.u(0x13b1a297, 0xa2269713),
4069 // o.u(0xa6a204f5, 0x0457f5a6), o.u(0xb901b868, 0xb86968b9),
4070 // o.u(0x00000000, 0x00000000), o.u(0xc1b5742c, 0x74992cc1),
4071 // o.u(0x40e0a060, 0xa0806040), o.u(0xe3c2211f, 0x21dd1fe3),
4072 // o.u(0x793a43c8, 0x43f2c879), o.u(0xb69a2ced, 0x2c77edb6),
4073 // o.u(0xd40dd9be, 0xd9b3bed4), o.u(0x8d47ca46, 0xca01468d),
4074 // o.u(0x671770d9, 0x70ced967), o.u(0x72afdd4b, 0xdde44b72),
4075 // o.u(0x94ed79de, 0x7933de94), o.u(0x98ff67d4, 0x672bd498),
4076 // o.u(0xb09323e8, 0x237be8b0), o.u(0x855bde4a, 0xde114a85),
4077 // o.u(0xbb06bd6b, 0xbd6d6bbb), o.u(0xc5bb7e2a, 0x7e912ac5),
4078 // o.u(0x4f7b34e5, 0x349ee54f), o.u(0xedd73a16, 0x3ac116ed),
4079 // o.u(0x86d254c5, 0x5417c586), o.u(0x9af862d7, 0x622fd79a),
4080 // o.u(0x6699ff55, 0xffcc5566), o.u(0x11b6a794, 0xa7229411),
4081 // o.u(0x8ac04acf, 0x4a0fcf8a), o.u(0xe9d93010, 0x30c910e9),
4082 // o.u(0x040e0a06, 0x0a080604), o.u(0xfe669881, 0x98e781fe),
4083 // o.u(0xa0ab0bf0, 0x0b5bf0a0), o.u(0x78b4cc44, 0xccf04478),
4084 // o.u(0x25f0d5ba, 0xd54aba25), o.u(0x4b753ee3, 0x3e96e34b),
4085 // o.u(0xa2ac0ef3, 0x0e5ff3a2), o.u(0x5d4419fe, 0x19bafe5d),
4086 // o.u(0x80db5bc0, 0x5b1bc080), o.u(0x0580858a, 0x850a8a05),
4087 // o.u(0x3fd3ecad, 0xec7ead3f), o.u(0x21fedfbc, 0xdf42bc21),
4088 // o.u(0x70a8d848, 0xd8e04870), o.u(0xf1fd0c04, 0x0cf904f1),
4089 // o.u(0x63197adf, 0x7ac6df63), o.u(0x772f58c1, 0x58eec177),
4090 // o.u(0xaf309f75, 0x9f4575af), o.u(0x42e7a563, 0xa5846342),
4091 // o.u(0x20705030, 0x50403020), o.u(0xe5cb2e1a, 0x2ed11ae5),
4092 // o.u(0xfdef120e, 0x12e10efd), o.u(0xbf08b76d, 0xb7656dbf),
4093 // o.u(0x8155d44c, 0xd4194c81), o.u(0x18243c14, 0x3c301418),
4094 // o.u(0x26795f35, 0x5f4c3526), o.u(0xc3b2712f, 0x719d2fc3),
4095 // o.u(0xbe8638e1, 0x3867e1be), o.u(0x35c8fda2, 0xfd6aa235),
4096 // o.u(0x88c74fcc, 0x4f0bcc88), o.u(0x2e654b39, 0x4b5c392e),
4097 // o.u(0x936af957, 0xf93d5793), o.u(0x55580df2, 0x0daaf255),
4098 // o.u(0xfc619d82, 0x9de382fc), o.u(0x7ab3c947, 0xc9f4477a),
4099 // o.u(0xc827efac, 0xef8bacc8), o.u(0xba8832e7, 0x326fe7ba),
4100 // o.u(0x324f7d2b, 0x7d642b32), o.u(0xe642a495, 0xa4d795e6),
4101 // o.u(0xc03bfba0, 0xfb9ba0c0), o.u(0x19aab398, 0xb3329819),
4102 // o.u(0x9ef668d1, 0x6827d19e), o.u(0xa322817f, 0x815d7fa3),
4103 // o.u(0x44eeaa66, 0xaa886644), o.u(0x54d6827e, 0x82a87e54),
4104 // o.u(0x3bdde6ab, 0xe676ab3b), o.u(0x0b959e83, 0x9e16830b),
4105 // o.u(0x8cc945ca, 0x4503ca8c), o.u(0xc7bc7b29, 0x7b9529c7),
4106 // o.u(0x6b056ed3, 0x6ed6d36b), o.u(0x286c443c, 0x44503c28),
4107 // o.u(0xa72c8b79, 0x8b5579a7), o.u(0xbc813de2, 0x3d63e2bc),
4108 // o.u(0x1631271d, 0x272c1d16), o.u(0xad379a76, 0x9a4176ad),
4109 // o.u(0xdb964d3b, 0x4dad3bdb), o.u(0x649efa56, 0xfac85664),
4110 // o.u(0x74a6d24e, 0xd2e84e74), o.u(0x1436221e, 0x22281e14),
4111 // o.u(0x92e476db, 0x763fdb92), o.u(0x0c121e0a, 0x1e180a0c),
4112 // o.u(0x48fcb46c, 0xb4906c48), o.u(0xb88f37e4, 0x376be4b8),
4113 // o.u(0x9f78e75d, 0xe7255d9f), o.u(0xbd0fb26e, 0xb2616ebd),
4114 // o.u(0x43692aef, 0x2a86ef43), o.u(0xc435f1a6, 0xf193a6c4),
4115 // o.u(0x39dae3a8, 0xe372a839), o.u(0x31c6f7a4, 0xf762a431),
4116 // o.u(0xd38a5937, 0x59bd37d3), o.u(0xf274868b, 0x86ff8bf2),
4117 // o.u(0xd5835632, 0x56b132d5), o.u(0x8b4ec543, 0xc50d438b),
4118 // o.u(0x6e85eb59, 0xebdc596e), o.u(0xda18c2b7, 0xc2afb7da),
4119 // o.u(0x018e8f8c, 0x8f028c01), o.u(0xb11dac64, 0xac7964b1),
4120 // o.u(0x9cf16dd2, 0x6d23d29c), o.u(0x49723be0, 0x3b92e049),
4121 // o.u(0xd81fc7b4, 0xc7abb4d8), o.u(0xacb915fa, 0x1543faac),
4122 // o.u(0xf3fa0907, 0x09fd07f3), o.u(0xcfa06f25, 0x6f8525cf),
4123 // o.u(0xca20eaaf, 0xea8fafca), o.u(0xf47d898e, 0x89f38ef4),
4124 // o.u(0x476720e9, 0x208ee947), o.u(0x10382818, 0x28201810),
4125 // o.u(0x6f0b64d5, 0x64ded56f), o.u(0xf0738388, 0x83fb88f0),
4126 // o.u(0x4afbb16f, 0xb1946f4a), o.u(0x5cca9672, 0x96b8725c),
4127 // o.u(0x38546c24, 0x6c702438), o.u(0x575f08f1, 0x08aef157),
4128 // o.u(0x732152c7, 0x52e6c773), o.u(0x9764f351, 0xf3355197),
4129 // o.u(0xcbae6523, 0x658d23cb), o.u(0xa125847c, 0x84597ca1),
4130 // o.u(0xe857bf9c, 0xbfcb9ce8), o.u(0x3e5d6321, 0x637c213e),
4131 // o.u(0x96ea7cdd, 0x7c37dd96), o.u(0x611e7fdc, 0x7fc2dc61),
4132 // o.u(0x0d9c9186, 0x911a860d), o.u(0x0f9b9485, 0x941e850f),
4133 // o.u(0xe04bab90, 0xabdb90e0), o.u(0x7cbac642, 0xc6f8427c),
4134 // o.u(0x712657c4, 0x57e2c471), o.u(0xcc29e5aa, 0xe583aacc),
4135 // o.u(0x90e373d8, 0x733bd890), o.u(0x06090f05, 0x0f0c0506),
4136 // o.u(0xf7f40301, 0x03f501f7), o.u(0x1c2a3612, 0x3638121c),
4137 // o.u(0xc23cfea3, 0xfe9fa3c2), o.u(0x6a8be15f, 0xe1d45f6a),
4138 // o.u(0xaebe10f9, 0x1047f9ae), o.u(0x69026bd0, 0x6bd2d069),
4139 // o.u(0x17bfa891, 0xa82e9117), o.u(0x9971e858, 0xe8295899),
4140 // o.u(0x3a536927, 0x6974273a), o.u(0x27f7d0b9, 0xd04eb927),
4141 // o.u(0xd9914838, 0x48a938d9), o.u(0xebde3513, 0x35cd13eb),
4142 // o.u(0x2be5ceb3, 0xce56b32b), o.u(0x22775533, 0x55443322),
4143 // o.u(0xd204d6bb, 0xd6bfbbd2), o.u(0xa9399070, 0x904970a9),
4144 // o.u(0x07878089, 0x800e8907), o.u(0x33c1f2a7, 0xf266a733),
4145 // o.u(0x2decc1b6, 0xc15ab62d), o.u(0x3c5a6622, 0x6678223c),
4146 // o.u(0x15b8ad92, 0xad2a9215), o.u(0xc9a96020, 0x608920c9),
4147 // o.u(0x875cdb49, 0xdb154987), o.u(0xaab01aff, 0x1a4fffaa),
4148 // o.u(0x50d88878, 0x88a07850), o.u(0xa52b8e7a, 0x8e517aa5),
4149 // o.u(0x03898a8f, 0x8a068f03), o.u(0x594a13f8, 0x13b2f859),
4150 // o.u(0x09929b80, 0x9b128009), o.u(0x1a233917, 0x3934171a),
4151 // o.u(0x651075da, 0x75cada65), o.u(0xd7845331, 0x53b531d7),
4152 // o.u(0x84d551c6, 0x5113c684), o.u(0xd003d3b8, 0xd3bbb8d0),
4153 // o.u(0x82dc5ec3, 0x5e1fc382), o.u(0x29e2cbb0, 0xcb52b029),
4154 // o.u(0x5ac39977, 0x99b4775a), o.u(0x1e2d3311, 0x333c111e),
4155 // o.u(0x7b3d46cb, 0x46f6cb7b), o.u(0xa8b71ffc, 0x1f4bfca8),
4156 // o.u(0x6d0c61d6, 0x61dad66d), o.u(0x2c624e3a, 0x4e583a2c)
4157 // ];
4158
4159 // var T1 = [
4160 // o.u(0xc6c632f4, 0xa5f497a5), o.u(0xf8f86f97, 0x8497eb84),
4161 // o.u(0xeeee5eb0, 0x99b0c799), o.u(0xf6f67a8c, 0x8d8cf78d),
4162 // o.u(0xffffe817, 0xd17e50d), o.u(0xd6d60adc, 0xbddcb7bd),
4163 // o.u(0xdede16c8, 0xb1c8a7b1), o.u(0x91916dfc, 0x54fc3954),
4164 // o.u(0x606090f0, 0x50f0c050), o.u(0x2020705, 0x3050403),
4165 // o.u(0xcece2ee0, 0xa9e087a9), o.u(0x5656d187, 0x7d87ac7d),
4166 // o.u(0xe7e7cc2b, 0x192bd519), o.u(0xb5b513a6, 0x62a67162),
4167 // o.u(0x4d4d7c31, 0xe6319ae6), o.u(0xecec59b5, 0x9ab5c39a),
4168 // o.u(0x8f8f40cf, 0x45cf0545), o.u(0x1f1fa3bc, 0x9dbc3e9d),
4169 // o.u(0x898949c0, 0x40c00940), o.u(0xfafa6892, 0x8792ef87),
4170 // o.u(0xefefd03f, 0x153fc515), o.u(0xb2b29426, 0xeb267feb),
4171 // o.u(0x8e8ece40, 0xc94007c9), o.u(0xfbfbe61d, 0xb1ded0b),
4172 // o.u(0x41416e2f, 0xec2f82ec), o.u(0xb3b31aa9, 0x67a97d67),
4173 // o.u(0x5f5f431c, 0xfd1cbefd), o.u(0x45456025, 0xea258aea),
4174 // o.u(0x2323f9da, 0xbfda46bf), o.u(0x53535102, 0xf702a6f7),
4175 // o.u(0xe4e445a1, 0x96a1d396), o.u(0x9b9b76ed, 0x5bed2d5b),
4176 // o.u(0x7575285d, 0xc25deac2), o.u(0xe1e1c524, 0x1c24d91c),
4177 // o.u(0x3d3dd4e9, 0xaee97aae), o.u(0x4c4cf2be, 0x6abe986a),
4178 // o.u(0x6c6c82ee, 0x5aeed85a), o.u(0x7e7ebdc3, 0x41c3fc41),
4179 // o.u(0xf5f5f306, 0x206f102), o.u(0x838352d1, 0x4fd11d4f),
4180 // o.u(0x68688ce4, 0x5ce4d05c), o.u(0x51515607, 0xf407a2f4),
4181 // o.u(0xd1d18d5c, 0x345cb934), o.u(0xf9f9e118, 0x818e908),
4182 // o.u(0xe2e24cae, 0x93aedf93), o.u(0xabab3e95, 0x73954d73),
4183 // o.u(0x626297f5, 0x53f5c453), o.u(0x2a2a6b41, 0x3f41543f),
4184 // o.u(0x8081c14, 0xc14100c), o.u(0x959563f6, 0x52f63152),
4185 // o.u(0x4646e9af, 0x65af8c65), o.u(0x9d9d7fe2, 0x5ee2215e),
4186 // o.u(0x30304878, 0x28786028), o.u(0x3737cff8, 0xa1f86ea1),
4187 // o.u(0xa0a1b11, 0xf11140f), o.u(0x2f2febc4, 0xb5c45eb5),
4188 // o.u(0xe0e151b, 0x91b1c09), o.u(0x24247e5a, 0x365a4836),
4189 // o.u(0x1b1badb6, 0x9bb6369b), o.u(0xdfdf9847, 0x3d47a53d),
4190 // o.u(0xcdcda76a, 0x266a8126), o.u(0x4e4ef5bb, 0x69bb9c69),
4191 // o.u(0x7f7f334c, 0xcd4cfecd), o.u(0xeaea50ba, 0x9fbacf9f),
4192 // o.u(0x12123f2d, 0x1b2d241b), o.u(0x1d1da4b9, 0x9eb93a9e),
4193 // o.u(0x5858c49c, 0x749cb074), o.u(0x34344672, 0x2e72682e),
4194 // o.u(0x36364177, 0x2d776c2d), o.u(0xdcdc11cd, 0xb2cda3b2),
4195 // o.u(0xb4b49d29, 0xee2973ee), o.u(0x5b5b4d16, 0xfb16b6fb),
4196 // o.u(0xa4a4a501, 0xf60153f6), o.u(0x7676a1d7, 0x4dd7ec4d),
4197 // o.u(0xb7b714a3, 0x61a37561), o.u(0x7d7d3449, 0xce49face),
4198 // o.u(0x5252df8d, 0x7b8da47b), o.u(0xdddd9f42, 0x3e42a13e),
4199 // o.u(0x5e5ecd93, 0x7193bc71), o.u(0x1313b1a2, 0x97a22697),
4200 // o.u(0xa6a6a204, 0xf50457f5), o.u(0xb9b901b8, 0x68b86968),
4201 // o.u(0x0, 0x0), o.u(0xc1c1b574, 0x2c74992c),
4202 // o.u(0x4040e0a0, 0x60a08060), o.u(0xe3e3c221, 0x1f21dd1f),
4203 // o.u(0x79793a43, 0xc843f2c8), o.u(0xb6b69a2c, 0xed2c77ed),
4204 // o.u(0xd4d40dd9, 0xbed9b3be), o.u(0x8d8d47ca, 0x46ca0146),
4205 // o.u(0x67671770, 0xd970ced9), o.u(0x7272afdd, 0x4bdde44b),
4206 // o.u(0x9494ed79, 0xde7933de), o.u(0x9898ff67, 0xd4672bd4),
4207 // o.u(0xb0b09323, 0xe8237be8), o.u(0x85855bde, 0x4ade114a),
4208 // o.u(0xbbbb06bd, 0x6bbd6d6b), o.u(0xc5c5bb7e, 0x2a7e912a),
4209 // o.u(0x4f4f7b34, 0xe5349ee5), o.u(0xededd73a, 0x163ac116),
4210 // o.u(0x8686d254, 0xc55417c5), o.u(0x9a9af862, 0xd7622fd7),
4211 // o.u(0x666699ff, 0x55ffcc55), o.u(0x1111b6a7, 0x94a72294),
4212 // o.u(0x8a8ac04a, 0xcf4a0fcf), o.u(0xe9e9d930, 0x1030c910),
4213 // o.u(0x4040e0a, 0x60a0806), o.u(0xfefe6698, 0x8198e781),
4214 // o.u(0xa0a0ab0b, 0xf00b5bf0), o.u(0x7878b4cc, 0x44ccf044),
4215 // o.u(0x2525f0d5, 0xbad54aba), o.u(0x4b4b753e, 0xe33e96e3),
4216 // o.u(0xa2a2ac0e, 0xf30e5ff3), o.u(0x5d5d4419, 0xfe19bafe),
4217 // o.u(0x8080db5b, 0xc05b1bc0), o.u(0x5058085, 0x8a850a8a),
4218 // o.u(0x3f3fd3ec, 0xadec7ead), o.u(0x2121fedf, 0xbcdf42bc),
4219 // o.u(0x7070a8d8, 0x48d8e048), o.u(0xf1f1fd0c, 0x40cf904),
4220 // o.u(0x6363197a, 0xdf7ac6df), o.u(0x77772f58, 0xc158eec1),
4221 // o.u(0xafaf309f, 0x759f4575), o.u(0x4242e7a5, 0x63a58463),
4222 // o.u(0x20207050, 0x30504030), o.u(0xe5e5cb2e, 0x1a2ed11a),
4223 // o.u(0xfdfdef12, 0xe12e10e), o.u(0xbfbf08b7, 0x6db7656d),
4224 // o.u(0x818155d4, 0x4cd4194c), o.u(0x1818243c, 0x143c3014),
4225 // o.u(0x2626795f, 0x355f4c35), o.u(0xc3c3b271, 0x2f719d2f),
4226 // o.u(0xbebe8638, 0xe13867e1), o.u(0x3535c8fd, 0xa2fd6aa2),
4227 // o.u(0x8888c74f, 0xcc4f0bcc), o.u(0x2e2e654b, 0x394b5c39),
4228 // o.u(0x93936af9, 0x57f93d57), o.u(0x5555580d, 0xf20daaf2),
4229 // o.u(0xfcfc619d, 0x829de382), o.u(0x7a7ab3c9, 0x47c9f447),
4230 // o.u(0xc8c827ef, 0xacef8bac), o.u(0xbaba8832, 0xe7326fe7),
4231 // o.u(0x32324f7d, 0x2b7d642b), o.u(0xe6e642a4, 0x95a4d795),
4232 // o.u(0xc0c03bfb, 0xa0fb9ba0), o.u(0x1919aab3, 0x98b33298),
4233 // o.u(0x9e9ef668, 0xd16827d1), o.u(0xa3a32281, 0x7f815d7f),
4234 // o.u(0x4444eeaa, 0x66aa8866), o.u(0x5454d682, 0x7e82a87e),
4235 // o.u(0x3b3bdde6, 0xabe676ab), o.u(0xb0b959e, 0x839e1683),
4236 // o.u(0x8c8cc945, 0xca4503ca), o.u(0xc7c7bc7b, 0x297b9529),
4237 // o.u(0x6b6b056e, 0xd36ed6d3), o.u(0x28286c44, 0x3c44503c),
4238 // o.u(0xa7a72c8b, 0x798b5579), o.u(0xbcbc813d, 0xe23d63e2),
4239 // o.u(0x16163127, 0x1d272c1d), o.u(0xadad379a, 0x769a4176),
4240 // o.u(0xdbdb964d, 0x3b4dad3b), o.u(0x64649efa, 0x56fac856),
4241 // o.u(0x7474a6d2, 0x4ed2e84e), o.u(0x14143622, 0x1e22281e),
4242 // o.u(0x9292e476, 0xdb763fdb), o.u(0xc0c121e, 0xa1e180a),
4243 // o.u(0x4848fcb4, 0x6cb4906c), o.u(0xb8b88f37, 0xe4376be4),
4244 // o.u(0x9f9f78e7, 0x5de7255d), o.u(0xbdbd0fb2, 0x6eb2616e),
4245 // o.u(0x4343692a, 0xef2a86ef), o.u(0xc4c435f1, 0xa6f193a6),
4246 // o.u(0x3939dae3, 0xa8e372a8), o.u(0x3131c6f7, 0xa4f762a4),
4247 // o.u(0xd3d38a59, 0x3759bd37), o.u(0xf2f27486, 0x8b86ff8b),
4248 // o.u(0xd5d58356, 0x3256b132), o.u(0x8b8b4ec5, 0x43c50d43),
4249 // o.u(0x6e6e85eb, 0x59ebdc59), o.u(0xdada18c2, 0xb7c2afb7),
4250 // o.u(0x1018e8f, 0x8c8f028c), o.u(0xb1b11dac, 0x64ac7964),
4251 // o.u(0x9c9cf16d, 0xd26d23d2), o.u(0x4949723b, 0xe03b92e0),
4252 // o.u(0xd8d81fc7, 0xb4c7abb4), o.u(0xacacb915, 0xfa1543fa),
4253 // o.u(0xf3f3fa09, 0x709fd07), o.u(0xcfcfa06f, 0x256f8525),
4254 // o.u(0xcaca20ea, 0xafea8faf), o.u(0xf4f47d89, 0x8e89f38e),
4255 // o.u(0x47476720, 0xe9208ee9), o.u(0x10103828, 0x18282018),
4256 // o.u(0x6f6f0b64, 0xd564ded5), o.u(0xf0f07383, 0x8883fb88),
4257 // o.u(0x4a4afbb1, 0x6fb1946f), o.u(0x5c5cca96, 0x7296b872),
4258 // o.u(0x3838546c, 0x246c7024), o.u(0x57575f08, 0xf108aef1),
4259 // o.u(0x73732152, 0xc752e6c7), o.u(0x979764f3, 0x51f33551),
4260 // o.u(0xcbcbae65, 0x23658d23), o.u(0xa1a12584, 0x7c84597c),
4261 // o.u(0xe8e857bf, 0x9cbfcb9c), o.u(0x3e3e5d63, 0x21637c21),
4262 // o.u(0x9696ea7c, 0xdd7c37dd), o.u(0x61611e7f, 0xdc7fc2dc),
4263 // o.u(0xd0d9c91, 0x86911a86), o.u(0xf0f9b94, 0x85941e85),
4264 // o.u(0xe0e04bab, 0x90abdb90), o.u(0x7c7cbac6, 0x42c6f842),
4265 // o.u(0x71712657, 0xc457e2c4), o.u(0xcccc29e5, 0xaae583aa),
4266 // o.u(0x9090e373, 0xd8733bd8), o.u(0x606090f, 0x50f0c05),
4267 // o.u(0xf7f7f403, 0x103f501), o.u(0x1c1c2a36, 0x12363812),
4268 // o.u(0xc2c23cfe, 0xa3fe9fa3), o.u(0x6a6a8be1, 0x5fe1d45f),
4269 // o.u(0xaeaebe10, 0xf91047f9), o.u(0x6969026b, 0xd06bd2d0),
4270 // o.u(0x1717bfa8, 0x91a82e91), o.u(0x999971e8, 0x58e82958),
4271 // o.u(0x3a3a5369, 0x27697427), o.u(0x2727f7d0, 0xb9d04eb9),
4272 // o.u(0xd9d99148, 0x3848a938), o.u(0xebebde35, 0x1335cd13),
4273 // o.u(0x2b2be5ce, 0xb3ce56b3), o.u(0x22227755, 0x33554433),
4274 // o.u(0xd2d204d6, 0xbbd6bfbb), o.u(0xa9a93990, 0x70904970),
4275 // o.u(0x7078780, 0x89800e89), o.u(0x3333c1f2, 0xa7f266a7),
4276 // o.u(0x2d2decc1, 0xb6c15ab6), o.u(0x3c3c5a66, 0x22667822),
4277 // o.u(0x1515b8ad, 0x92ad2a92), o.u(0xc9c9a960, 0x20608920),
4278 // o.u(0x87875cdb, 0x49db1549), o.u(0xaaaab01a, 0xff1a4fff),
4279 // o.u(0x5050d888, 0x7888a078), o.u(0xa5a52b8e, 0x7a8e517a),
4280 // o.u(0x303898a, 0x8f8a068f), o.u(0x59594a13, 0xf813b2f8),
4281 // o.u(0x909929b, 0x809b1280), o.u(0x1a1a2339, 0x17393417),
4282 // o.u(0x65651075, 0xda75cada), o.u(0xd7d78453, 0x3153b531),
4283 // o.u(0x8484d551, 0xc65113c6), o.u(0xd0d003d3, 0xb8d3bbb8),
4284 // o.u(0x8282dc5e, 0xc35e1fc3), o.u(0x2929e2cb, 0xb0cb52b0),
4285 // o.u(0x5a5ac399, 0x7799b477), o.u(0x1e1e2d33, 0x11333c11),
4286 // o.u(0x7b7b3d46, 0xcb46f6cb), o.u(0xa8a8b71f, 0xfc1f4bfc),
4287 // o.u(0x6d6d0c61, 0xd661dad6), o.u(0x2c2c624e, 0x3a4e583a)
4288 // ];
4289
4290 // var T2 = [
4291 // o.u(0xa5c6c632, 0xf4a5f497), o.u(0x84f8f86f, 0x978497eb),
4292 // o.u(0x99eeee5e, 0xb099b0c7), o.u(0x8df6f67a, 0x8c8d8cf7),
4293 // o.u(0xdffffe8, 0x170d17e5), o.u(0xbdd6d60a, 0xdcbddcb7),
4294 // o.u(0xb1dede16, 0xc8b1c8a7), o.u(0x5491916d, 0xfc54fc39),
4295 // o.u(0x50606090, 0xf050f0c0), o.u(0x3020207, 0x5030504),
4296 // o.u(0xa9cece2e, 0xe0a9e087), o.u(0x7d5656d1, 0x877d87ac),
4297 // o.u(0x19e7e7cc, 0x2b192bd5), o.u(0x62b5b513, 0xa662a671),
4298 // o.u(0xe64d4d7c, 0x31e6319a), o.u(0x9aecec59, 0xb59ab5c3),
4299 // o.u(0x458f8f40, 0xcf45cf05), o.u(0x9d1f1fa3, 0xbc9dbc3e),
4300 // o.u(0x40898949, 0xc040c009), o.u(0x87fafa68, 0x928792ef),
4301 // o.u(0x15efefd0, 0x3f153fc5), o.u(0xebb2b294, 0x26eb267f),
4302 // o.u(0xc98e8ece, 0x40c94007), o.u(0xbfbfbe6, 0x1d0b1ded),
4303 // o.u(0xec41416e, 0x2fec2f82), o.u(0x67b3b31a, 0xa967a97d),
4304 // o.u(0xfd5f5f43, 0x1cfd1cbe), o.u(0xea454560, 0x25ea258a),
4305 // o.u(0xbf2323f9, 0xdabfda46), o.u(0xf7535351, 0x2f702a6),
4306 // o.u(0x96e4e445, 0xa196a1d3), o.u(0x5b9b9b76, 0xed5bed2d),
4307 // o.u(0xc2757528, 0x5dc25dea), o.u(0x1ce1e1c5, 0x241c24d9),
4308 // o.u(0xae3d3dd4, 0xe9aee97a), o.u(0x6a4c4cf2, 0xbe6abe98),
4309 // o.u(0x5a6c6c82, 0xee5aeed8), o.u(0x417e7ebd, 0xc341c3fc),
4310 // o.u(0x2f5f5f3, 0x60206f1), o.u(0x4f838352, 0xd14fd11d),
4311 // o.u(0x5c68688c, 0xe45ce4d0), o.u(0xf4515156, 0x7f407a2),
4312 // o.u(0x34d1d18d, 0x5c345cb9), o.u(0x8f9f9e1, 0x180818e9),
4313 // o.u(0x93e2e24c, 0xae93aedf), o.u(0x73abab3e, 0x9573954d),
4314 // o.u(0x53626297, 0xf553f5c4), o.u(0x3f2a2a6b, 0x413f4154),
4315 // o.u(0xc08081c, 0x140c1410), o.u(0x52959563, 0xf652f631),
4316 // o.u(0x654646e9, 0xaf65af8c), o.u(0x5e9d9d7f, 0xe25ee221),
4317 // o.u(0x28303048, 0x78287860), o.u(0xa13737cf, 0xf8a1f86e),
4318 // o.u(0xf0a0a1b, 0x110f1114), o.u(0xb52f2feb, 0xc4b5c45e),
4319 // o.u(0x90e0e15, 0x1b091b1c), o.u(0x3624247e, 0x5a365a48),
4320 // o.u(0x9b1b1bad, 0xb69bb636), o.u(0x3ddfdf98, 0x473d47a5),
4321 // o.u(0x26cdcda7, 0x6a266a81), o.u(0x694e4ef5, 0xbb69bb9c),
4322 // o.u(0xcd7f7f33, 0x4ccd4cfe), o.u(0x9feaea50, 0xba9fbacf),
4323 // o.u(0x1b12123f, 0x2d1b2d24), o.u(0x9e1d1da4, 0xb99eb93a),
4324 // o.u(0x745858c4, 0x9c749cb0), o.u(0x2e343446, 0x722e7268),
4325 // o.u(0x2d363641, 0x772d776c), o.u(0xb2dcdc11, 0xcdb2cda3),
4326 // o.u(0xeeb4b49d, 0x29ee2973), o.u(0xfb5b5b4d, 0x16fb16b6),
4327 // o.u(0xf6a4a4a5, 0x1f60153), o.u(0x4d7676a1, 0xd74dd7ec),
4328 // o.u(0x61b7b714, 0xa361a375), o.u(0xce7d7d34, 0x49ce49fa),
4329 // o.u(0x7b5252df, 0x8d7b8da4), o.u(0x3edddd9f, 0x423e42a1),
4330 // o.u(0x715e5ecd, 0x937193bc), o.u(0x971313b1, 0xa297a226),
4331 // o.u(0xf5a6a6a2, 0x4f50457), o.u(0x68b9b901, 0xb868b869),
4332 // o.u(0x0, 0x0), o.u(0x2cc1c1b5, 0x742c7499),
4333 // o.u(0x604040e0, 0xa060a080), o.u(0x1fe3e3c2, 0x211f21dd),
4334 // o.u(0xc879793a, 0x43c843f2), o.u(0xedb6b69a, 0x2ced2c77),
4335 // o.u(0xbed4d40d, 0xd9bed9b3), o.u(0x468d8d47, 0xca46ca01),
4336 // o.u(0xd9676717, 0x70d970ce), o.u(0x4b7272af, 0xdd4bdde4),
4337 // o.u(0xde9494ed, 0x79de7933), o.u(0xd49898ff, 0x67d4672b),
4338 // o.u(0xe8b0b093, 0x23e8237b), o.u(0x4a85855b, 0xde4ade11),
4339 // o.u(0x6bbbbb06, 0xbd6bbd6d), o.u(0x2ac5c5bb, 0x7e2a7e91),
4340 // o.u(0xe54f4f7b, 0x34e5349e), o.u(0x16ededd7, 0x3a163ac1),
4341 // o.u(0xc58686d2, 0x54c55417), o.u(0xd79a9af8, 0x62d7622f),
4342 // o.u(0x55666699, 0xff55ffcc), o.u(0x941111b6, 0xa794a722),
4343 // o.u(0xcf8a8ac0, 0x4acf4a0f), o.u(0x10e9e9d9, 0x301030c9),
4344 // o.u(0x604040e, 0xa060a08), o.u(0x81fefe66, 0x988198e7),
4345 // o.u(0xf0a0a0ab, 0xbf00b5b), o.u(0x447878b4, 0xcc44ccf0),
4346 // o.u(0xba2525f0, 0xd5bad54a), o.u(0xe34b4b75, 0x3ee33e96),
4347 // o.u(0xf3a2a2ac, 0xef30e5f), o.u(0xfe5d5d44, 0x19fe19ba),
4348 // o.u(0xc08080db, 0x5bc05b1b), o.u(0x8a050580, 0x858a850a),
4349 // o.u(0xad3f3fd3, 0xecadec7e), o.u(0xbc2121fe, 0xdfbcdf42),
4350 // o.u(0x487070a8, 0xd848d8e0), o.u(0x4f1f1fd, 0xc040cf9),
4351 // o.u(0xdf636319, 0x7adf7ac6), o.u(0xc177772f, 0x58c158ee),
4352 // o.u(0x75afaf30, 0x9f759f45), o.u(0x634242e7, 0xa563a584),
4353 // o.u(0x30202070, 0x50305040), o.u(0x1ae5e5cb, 0x2e1a2ed1),
4354 // o.u(0xefdfdef, 0x120e12e1), o.u(0x6dbfbf08, 0xb76db765),
4355 // o.u(0x4c818155, 0xd44cd419), o.u(0x14181824, 0x3c143c30),
4356 // o.u(0x35262679, 0x5f355f4c), o.u(0x2fc3c3b2, 0x712f719d),
4357 // o.u(0xe1bebe86, 0x38e13867), o.u(0xa23535c8, 0xfda2fd6a),
4358 // o.u(0xcc8888c7, 0x4fcc4f0b), o.u(0x392e2e65, 0x4b394b5c),
4359 // o.u(0x5793936a, 0xf957f93d), o.u(0xf2555558, 0xdf20daa),
4360 // o.u(0x82fcfc61, 0x9d829de3), o.u(0x477a7ab3, 0xc947c9f4),
4361 // o.u(0xacc8c827, 0xefacef8b), o.u(0xe7baba88, 0x32e7326f),
4362 // o.u(0x2b32324f, 0x7d2b7d64), o.u(0x95e6e642, 0xa495a4d7),
4363 // o.u(0xa0c0c03b, 0xfba0fb9b), o.u(0x981919aa, 0xb398b332),
4364 // o.u(0xd19e9ef6, 0x68d16827), o.u(0x7fa3a322, 0x817f815d),
4365 // o.u(0x664444ee, 0xaa66aa88), o.u(0x7e5454d6, 0x827e82a8),
4366 // o.u(0xab3b3bdd, 0xe6abe676), o.u(0x830b0b95, 0x9e839e16),
4367 // o.u(0xca8c8cc9, 0x45ca4503), o.u(0x29c7c7bc, 0x7b297b95),
4368 // o.u(0xd36b6b05, 0x6ed36ed6), o.u(0x3c28286c, 0x443c4450),
4369 // o.u(0x79a7a72c, 0x8b798b55), o.u(0xe2bcbc81, 0x3de23d63),
4370 // o.u(0x1d161631, 0x271d272c), o.u(0x76adad37, 0x9a769a41),
4371 // o.u(0x3bdbdb96, 0x4d3b4dad), o.u(0x5664649e, 0xfa56fac8),
4372 // o.u(0x4e7474a6, 0xd24ed2e8), o.u(0x1e141436, 0x221e2228),
4373 // o.u(0xdb9292e4, 0x76db763f), o.u(0xa0c0c12, 0x1e0a1e18),
4374 // o.u(0x6c4848fc, 0xb46cb490), o.u(0xe4b8b88f, 0x37e4376b),
4375 // o.u(0x5d9f9f78, 0xe75de725), o.u(0x6ebdbd0f, 0xb26eb261),
4376 // o.u(0xef434369, 0x2aef2a86), o.u(0xa6c4c435, 0xf1a6f193),
4377 // o.u(0xa83939da, 0xe3a8e372), o.u(0xa43131c6, 0xf7a4f762),
4378 // o.u(0x37d3d38a, 0x593759bd), o.u(0x8bf2f274, 0x868b86ff),
4379 // o.u(0x32d5d583, 0x563256b1), o.u(0x438b8b4e, 0xc543c50d),
4380 // o.u(0x596e6e85, 0xeb59ebdc), o.u(0xb7dada18, 0xc2b7c2af),
4381 // o.u(0x8c01018e, 0x8f8c8f02), o.u(0x64b1b11d, 0xac64ac79),
4382 // o.u(0xd29c9cf1, 0x6dd26d23), o.u(0xe0494972, 0x3be03b92),
4383 // o.u(0xb4d8d81f, 0xc7b4c7ab), o.u(0xfaacacb9, 0x15fa1543),
4384 // o.u(0x7f3f3fa, 0x90709fd), o.u(0x25cfcfa0, 0x6f256f85),
4385 // o.u(0xafcaca20, 0xeaafea8f), o.u(0x8ef4f47d, 0x898e89f3),
4386 // o.u(0xe9474767, 0x20e9208e), o.u(0x18101038, 0x28182820),
4387 // o.u(0xd56f6f0b, 0x64d564de), o.u(0x88f0f073, 0x838883fb),
4388 // o.u(0x6f4a4afb, 0xb16fb194), o.u(0x725c5cca, 0x967296b8),
4389 // o.u(0x24383854, 0x6c246c70), o.u(0xf157575f, 0x8f108ae),
4390 // o.u(0xc7737321, 0x52c752e6), o.u(0x51979764, 0xf351f335),
4391 // o.u(0x23cbcbae, 0x6523658d), o.u(0x7ca1a125, 0x847c8459),
4392 // o.u(0x9ce8e857, 0xbf9cbfcb), o.u(0x213e3e5d, 0x6321637c),
4393 // o.u(0xdd9696ea, 0x7cdd7c37), o.u(0xdc61611e, 0x7fdc7fc2),
4394 // o.u(0x860d0d9c, 0x9186911a), o.u(0x850f0f9b, 0x9485941e),
4395 // o.u(0x90e0e04b, 0xab90abdb), o.u(0x427c7cba, 0xc642c6f8),
4396 // o.u(0xc4717126, 0x57c457e2), o.u(0xaacccc29, 0xe5aae583),
4397 // o.u(0xd89090e3, 0x73d8733b), o.u(0x5060609, 0xf050f0c),
4398 // o.u(0x1f7f7f4, 0x30103f5), o.u(0x121c1c2a, 0x36123638),
4399 // o.u(0xa3c2c23c, 0xfea3fe9f), o.u(0x5f6a6a8b, 0xe15fe1d4),
4400 // o.u(0xf9aeaebe, 0x10f91047), o.u(0xd0696902, 0x6bd06bd2),
4401 // o.u(0x911717bf, 0xa891a82e), o.u(0x58999971, 0xe858e829),
4402 // o.u(0x273a3a53, 0x69276974), o.u(0xb92727f7, 0xd0b9d04e),
4403 // o.u(0x38d9d991, 0x483848a9), o.u(0x13ebebde, 0x351335cd),
4404 // o.u(0xb32b2be5, 0xceb3ce56), o.u(0x33222277, 0x55335544),
4405 // o.u(0xbbd2d204, 0xd6bbd6bf), o.u(0x70a9a939, 0x90709049),
4406 // o.u(0x89070787, 0x8089800e), o.u(0xa73333c1, 0xf2a7f266),
4407 // o.u(0xb62d2dec, 0xc1b6c15a), o.u(0x223c3c5a, 0x66226678),
4408 // o.u(0x921515b8, 0xad92ad2a), o.u(0x20c9c9a9, 0x60206089),
4409 // o.u(0x4987875c, 0xdb49db15), o.u(0xffaaaab0, 0x1aff1a4f),
4410 // o.u(0x785050d8, 0x887888a0), o.u(0x7aa5a52b, 0x8e7a8e51),
4411 // o.u(0x8f030389, 0x8a8f8a06), o.u(0xf859594a, 0x13f813b2),
4412 // o.u(0x80090992, 0x9b809b12), o.u(0x171a1a23, 0x39173934),
4413 // o.u(0xda656510, 0x75da75ca), o.u(0x31d7d784, 0x533153b5),
4414 // o.u(0xc68484d5, 0x51c65113), o.u(0xb8d0d003, 0xd3b8d3bb),
4415 // o.u(0xc38282dc, 0x5ec35e1f), o.u(0xb02929e2, 0xcbb0cb52),
4416 // o.u(0x775a5ac3, 0x997799b4), o.u(0x111e1e2d, 0x3311333c),
4417 // o.u(0xcb7b7b3d, 0x46cb46f6), o.u(0xfca8a8b7, 0x1ffc1f4b),
4418 // o.u(0xd66d6d0c, 0x61d661da), o.u(0x3a2c2c62, 0x4e3a4e58)
4419 // ];
4420
4421 // var T3 = [
4422 // o.u(0x97a5c6c6, 0x32f4a5f4), o.u(0xeb84f8f8, 0x6f978497),
4423 // o.u(0xc799eeee, 0x5eb099b0), o.u(0xf78df6f6, 0x7a8c8d8c),
4424 // o.u(0xe50dffff, 0xe8170d17), o.u(0xb7bdd6d6, 0xadcbddc),
4425 // o.u(0xa7b1dede, 0x16c8b1c8), o.u(0x39549191, 0x6dfc54fc),
4426 // o.u(0xc0506060, 0x90f050f0), o.u(0x4030202, 0x7050305),
4427 // o.u(0x87a9cece, 0x2ee0a9e0), o.u(0xac7d5656, 0xd1877d87),
4428 // o.u(0xd519e7e7, 0xcc2b192b), o.u(0x7162b5b5, 0x13a662a6),
4429 // o.u(0x9ae64d4d, 0x7c31e631), o.u(0xc39aecec, 0x59b59ab5),
4430 // o.u(0x5458f8f, 0x40cf45cf), o.u(0x3e9d1f1f, 0xa3bc9dbc),
4431 // o.u(0x9408989, 0x49c040c0), o.u(0xef87fafa, 0x68928792),
4432 // o.u(0xc515efef, 0xd03f153f), o.u(0x7febb2b2, 0x9426eb26),
4433 // o.u(0x7c98e8e, 0xce40c940), o.u(0xed0bfbfb, 0xe61d0b1d),
4434 // o.u(0x82ec4141, 0x6e2fec2f), o.u(0x7d67b3b3, 0x1aa967a9),
4435 // o.u(0xbefd5f5f, 0x431cfd1c), o.u(0x8aea4545, 0x6025ea25),
4436 // o.u(0x46bf2323, 0xf9dabfda), o.u(0xa6f75353, 0x5102f702),
4437 // o.u(0xd396e4e4, 0x45a196a1), o.u(0x2d5b9b9b, 0x76ed5bed),
4438 // o.u(0xeac27575, 0x285dc25d), o.u(0xd91ce1e1, 0xc5241c24),
4439 // o.u(0x7aae3d3d, 0xd4e9aee9), o.u(0x986a4c4c, 0xf2be6abe),
4440 // o.u(0xd85a6c6c, 0x82ee5aee), o.u(0xfc417e7e, 0xbdc341c3),
4441 // o.u(0xf102f5f5, 0xf3060206), o.u(0x1d4f8383, 0x52d14fd1),
4442 // o.u(0xd05c6868, 0x8ce45ce4), o.u(0xa2f45151, 0x5607f407),
4443 // o.u(0xb934d1d1, 0x8d5c345c), o.u(0xe908f9f9, 0xe1180818),
4444 // o.u(0xdf93e2e2, 0x4cae93ae), o.u(0x4d73abab, 0x3e957395),
4445 // o.u(0xc4536262, 0x97f553f5), o.u(0x543f2a2a, 0x6b413f41),
4446 // o.u(0x100c0808, 0x1c140c14), o.u(0x31529595, 0x63f652f6),
4447 // o.u(0x8c654646, 0xe9af65af), o.u(0x215e9d9d, 0x7fe25ee2),
4448 // o.u(0x60283030, 0x48782878), o.u(0x6ea13737, 0xcff8a1f8),
4449 // o.u(0x140f0a0a, 0x1b110f11), o.u(0x5eb52f2f, 0xebc4b5c4),
4450 // o.u(0x1c090e0e, 0x151b091b), o.u(0x48362424, 0x7e5a365a),
4451 // o.u(0x369b1b1b, 0xadb69bb6), o.u(0xa53ddfdf, 0x98473d47),
4452 // o.u(0x8126cdcd, 0xa76a266a), o.u(0x9c694e4e, 0xf5bb69bb),
4453 // o.u(0xfecd7f7f, 0x334ccd4c), o.u(0xcf9feaea, 0x50ba9fba),
4454 // o.u(0x241b1212, 0x3f2d1b2d), o.u(0x3a9e1d1d, 0xa4b99eb9),
4455 // o.u(0xb0745858, 0xc49c749c), o.u(0x682e3434, 0x46722e72),
4456 // o.u(0x6c2d3636, 0x41772d77), o.u(0xa3b2dcdc, 0x11cdb2cd),
4457 // o.u(0x73eeb4b4, 0x9d29ee29), o.u(0xb6fb5b5b, 0x4d16fb16),
4458 // o.u(0x53f6a4a4, 0xa501f601), o.u(0xec4d7676, 0xa1d74dd7),
4459 // o.u(0x7561b7b7, 0x14a361a3), o.u(0xface7d7d, 0x3449ce49),
4460 // o.u(0xa47b5252, 0xdf8d7b8d), o.u(0xa13edddd, 0x9f423e42),
4461 // o.u(0xbc715e5e, 0xcd937193), o.u(0x26971313, 0xb1a297a2),
4462 // o.u(0x57f5a6a6, 0xa204f504), o.u(0x6968b9b9, 0x1b868b8),
4463 // o.u(0x0, 0x0), o.u(0x992cc1c1, 0xb5742c74),
4464 // o.u(0x80604040, 0xe0a060a0), o.u(0xdd1fe3e3, 0xc2211f21),
4465 // o.u(0xf2c87979, 0x3a43c843), o.u(0x77edb6b6, 0x9a2ced2c),
4466 // o.u(0xb3bed4d4, 0xdd9bed9), o.u(0x1468d8d, 0x47ca46ca),
4467 // o.u(0xced96767, 0x1770d970), o.u(0xe44b7272, 0xafdd4bdd),
4468 // o.u(0x33de9494, 0xed79de79), o.u(0x2bd49898, 0xff67d467),
4469 // o.u(0x7be8b0b0, 0x9323e823), o.u(0x114a8585, 0x5bde4ade),
4470 // o.u(0x6d6bbbbb, 0x6bd6bbd), o.u(0x912ac5c5, 0xbb7e2a7e),
4471 // o.u(0x9ee54f4f, 0x7b34e534), o.u(0xc116eded, 0xd73a163a),
4472 // o.u(0x17c58686, 0xd254c554), o.u(0x2fd79a9a, 0xf862d762),
4473 // o.u(0xcc556666, 0x99ff55ff), o.u(0x22941111, 0xb6a794a7),
4474 // o.u(0xfcf8a8a, 0xc04acf4a), o.u(0xc910e9e9, 0xd9301030),
4475 // o.u(0x8060404, 0xe0a060a), o.u(0xe781fefe, 0x66988198),
4476 // o.u(0x5bf0a0a0, 0xab0bf00b), o.u(0xf0447878, 0xb4cc44cc),
4477 // o.u(0x4aba2525, 0xf0d5bad5), o.u(0x96e34b4b, 0x753ee33e),
4478 // o.u(0x5ff3a2a2, 0xac0ef30e), o.u(0xbafe5d5d, 0x4419fe19),
4479 // o.u(0x1bc08080, 0xdb5bc05b), o.u(0xa8a0505, 0x80858a85),
4480 // o.u(0x7ead3f3f, 0xd3ecadec), o.u(0x42bc2121, 0xfedfbcdf),
4481 // o.u(0xe0487070, 0xa8d848d8), o.u(0xf904f1f1, 0xfd0c040c),
4482 // o.u(0xc6df6363, 0x197adf7a), o.u(0xeec17777, 0x2f58c158),
4483 // o.u(0x4575afaf, 0x309f759f), o.u(0x84634242, 0xe7a563a5),
4484 // o.u(0x40302020, 0x70503050), o.u(0xd11ae5e5, 0xcb2e1a2e),
4485 // o.u(0xe10efdfd, 0xef120e12), o.u(0x656dbfbf, 0x8b76db7),
4486 // o.u(0x194c8181, 0x55d44cd4), o.u(0x30141818, 0x243c143c),
4487 // o.u(0x4c352626, 0x795f355f), o.u(0x9d2fc3c3, 0xb2712f71),
4488 // o.u(0x67e1bebe, 0x8638e138), o.u(0x6aa23535, 0xc8fda2fd),
4489 // o.u(0xbcc8888, 0xc74fcc4f), o.u(0x5c392e2e, 0x654b394b),
4490 // o.u(0x3d579393, 0x6af957f9), o.u(0xaaf25555, 0x580df20d),
4491 // o.u(0xe382fcfc, 0x619d829d), o.u(0xf4477a7a, 0xb3c947c9),
4492 // o.u(0x8bacc8c8, 0x27efacef), o.u(0x6fe7baba, 0x8832e732),
4493 // o.u(0x642b3232, 0x4f7d2b7d), o.u(0xd795e6e6, 0x42a495a4),
4494 // o.u(0x9ba0c0c0, 0x3bfba0fb), o.u(0x32981919, 0xaab398b3),
4495 // o.u(0x27d19e9e, 0xf668d168), o.u(0x5d7fa3a3, 0x22817f81),
4496 // o.u(0x88664444, 0xeeaa66aa), o.u(0xa87e5454, 0xd6827e82),
4497 // o.u(0x76ab3b3b, 0xdde6abe6), o.u(0x16830b0b, 0x959e839e),
4498 // o.u(0x3ca8c8c, 0xc945ca45), o.u(0x9529c7c7, 0xbc7b297b),
4499 // o.u(0xd6d36b6b, 0x56ed36e), o.u(0x503c2828, 0x6c443c44),
4500 // o.u(0x5579a7a7, 0x2c8b798b), o.u(0x63e2bcbc, 0x813de23d),
4501 // o.u(0x2c1d1616, 0x31271d27), o.u(0x4176adad, 0x379a769a),
4502 // o.u(0xad3bdbdb, 0x964d3b4d), o.u(0xc8566464, 0x9efa56fa),
4503 // o.u(0xe84e7474, 0xa6d24ed2), o.u(0x281e1414, 0x36221e22),
4504 // o.u(0x3fdb9292, 0xe476db76), o.u(0x180a0c0c, 0x121e0a1e),
4505 // o.u(0x906c4848, 0xfcb46cb4), o.u(0x6be4b8b8, 0x8f37e437),
4506 // o.u(0x255d9f9f, 0x78e75de7), o.u(0x616ebdbd, 0xfb26eb2),
4507 // o.u(0x86ef4343, 0x692aef2a), o.u(0x93a6c4c4, 0x35f1a6f1),
4508 // o.u(0x72a83939, 0xdae3a8e3), o.u(0x62a43131, 0xc6f7a4f7),
4509 // o.u(0xbd37d3d3, 0x8a593759), o.u(0xff8bf2f2, 0x74868b86),
4510 // o.u(0xb132d5d5, 0x83563256), o.u(0xd438b8b, 0x4ec543c5),
4511 // o.u(0xdc596e6e, 0x85eb59eb), o.u(0xafb7dada, 0x18c2b7c2),
4512 // o.u(0x28c0101, 0x8e8f8c8f), o.u(0x7964b1b1, 0x1dac64ac),
4513 // o.u(0x23d29c9c, 0xf16dd26d), o.u(0x92e04949, 0x723be03b),
4514 // o.u(0xabb4d8d8, 0x1fc7b4c7), o.u(0x43faacac, 0xb915fa15),
4515 // o.u(0xfd07f3f3, 0xfa090709), o.u(0x8525cfcf, 0xa06f256f),
4516 // o.u(0x8fafcaca, 0x20eaafea), o.u(0xf38ef4f4, 0x7d898e89),
4517 // o.u(0x8ee94747, 0x6720e920), o.u(0x20181010, 0x38281828),
4518 // o.u(0xded56f6f, 0xb64d564), o.u(0xfb88f0f0, 0x73838883),
4519 // o.u(0x946f4a4a, 0xfbb16fb1), o.u(0xb8725c5c, 0xca967296),
4520 // o.u(0x70243838, 0x546c246c), o.u(0xaef15757, 0x5f08f108),
4521 // o.u(0xe6c77373, 0x2152c752), o.u(0x35519797, 0x64f351f3),
4522 // o.u(0x8d23cbcb, 0xae652365), o.u(0x597ca1a1, 0x25847c84),
4523 // o.u(0xcb9ce8e8, 0x57bf9cbf), o.u(0x7c213e3e, 0x5d632163),
4524 // o.u(0x37dd9696, 0xea7cdd7c), o.u(0xc2dc6161, 0x1e7fdc7f),
4525 // o.u(0x1a860d0d, 0x9c918691), o.u(0x1e850f0f, 0x9b948594),
4526 // o.u(0xdb90e0e0, 0x4bab90ab), o.u(0xf8427c7c, 0xbac642c6),
4527 // o.u(0xe2c47171, 0x2657c457), o.u(0x83aacccc, 0x29e5aae5),
4528 // o.u(0x3bd89090, 0xe373d873), o.u(0xc050606, 0x90f050f),
4529 // o.u(0xf501f7f7, 0xf4030103), o.u(0x38121c1c, 0x2a361236),
4530 // o.u(0x9fa3c2c2, 0x3cfea3fe), o.u(0xd45f6a6a, 0x8be15fe1),
4531 // o.u(0x47f9aeae, 0xbe10f910), o.u(0xd2d06969, 0x26bd06b),
4532 // o.u(0x2e911717, 0xbfa891a8), o.u(0x29589999, 0x71e858e8),
4533 // o.u(0x74273a3a, 0x53692769), o.u(0x4eb92727, 0xf7d0b9d0),
4534 // o.u(0xa938d9d9, 0x91483848), o.u(0xcd13ebeb, 0xde351335),
4535 // o.u(0x56b32b2b, 0xe5ceb3ce), o.u(0x44332222, 0x77553355),
4536 // o.u(0xbfbbd2d2, 0x4d6bbd6), o.u(0x4970a9a9, 0x39907090),
4537 // o.u(0xe890707, 0x87808980), o.u(0x66a73333, 0xc1f2a7f2),
4538 // o.u(0x5ab62d2d, 0xecc1b6c1), o.u(0x78223c3c, 0x5a662266),
4539 // o.u(0x2a921515, 0xb8ad92ad), o.u(0x8920c9c9, 0xa9602060),
4540 // o.u(0x15498787, 0x5cdb49db), o.u(0x4fffaaaa, 0xb01aff1a),
4541 // o.u(0xa0785050, 0xd8887888), o.u(0x517aa5a5, 0x2b8e7a8e),
4542 // o.u(0x68f0303, 0x898a8f8a), o.u(0xb2f85959, 0x4a13f813),
4543 // o.u(0x12800909, 0x929b809b), o.u(0x34171a1a, 0x23391739),
4544 // o.u(0xcada6565, 0x1075da75), o.u(0xb531d7d7, 0x84533153),
4545 // o.u(0x13c68484, 0xd551c651), o.u(0xbbb8d0d0, 0x3d3b8d3),
4546 // o.u(0x1fc38282, 0xdc5ec35e), o.u(0x52b02929, 0xe2cbb0cb),
4547 // o.u(0xb4775a5a, 0xc3997799), o.u(0x3c111e1e, 0x2d331133),
4548 // o.u(0xf6cb7b7b, 0x3d46cb46), o.u(0x4bfca8a8, 0xb71ffc1f),
4549 // o.u(0xdad66d6d, 0xc61d661), o.u(0x583a2c2c, 0x624e3a4e)
4550 // ]
4551
4552 // var T4 = [
4553 // o.u(0xf497a5c6, 0xc632f4a5), o.u(0x97eb84f8, 0xf86f9784),
4554 // o.u(0xb0c799ee, 0xee5eb099), o.u(0x8cf78df6, 0xf67a8c8d),
4555 // o.u(0x17e50dff, 0xffe8170d), o.u(0xdcb7bdd6, 0xd60adcbd),
4556 // o.u(0xc8a7b1de, 0xde16c8b1), o.u(0xfc395491, 0x916dfc54),
4557 // o.u(0xf0c05060, 0x6090f050), o.u(0x05040302, 0x02070503),
4558 // o.u(0xe087a9ce, 0xce2ee0a9), o.u(0x87ac7d56, 0x56d1877d),
4559 // o.u(0x2bd519e7, 0xe7cc2b19), o.u(0xa67162b5, 0xb513a662),
4560 // o.u(0x319ae64d, 0x4d7c31e6), o.u(0xb5c39aec, 0xec59b59a),
4561 // o.u(0xcf05458f, 0x8f40cf45), o.u(0xbc3e9d1f, 0x1fa3bc9d),
4562 // o.u(0xc0094089, 0x8949c040), o.u(0x92ef87fa, 0xfa689287),
4563 // o.u(0x3fc515ef, 0xefd03f15), o.u(0x267febb2, 0xb29426eb),
4564 // o.u(0x4007c98e, 0x8ece40c9), o.u(0x1ded0bfb, 0xfbe61d0b),
4565 // o.u(0x2f82ec41, 0x416e2fec), o.u(0xa97d67b3, 0xb31aa967),
4566 // o.u(0x1cbefd5f, 0x5f431cfd), o.u(0x258aea45, 0x456025ea),
4567 // o.u(0xda46bf23, 0x23f9dabf), o.u(0x02a6f753, 0x535102f7),
4568 // o.u(0xa1d396e4, 0xe445a196), o.u(0xed2d5b9b, 0x9b76ed5b),
4569 // o.u(0x5deac275, 0x75285dc2), o.u(0x24d91ce1, 0xe1c5241c),
4570 // o.u(0xe97aae3d, 0x3dd4e9ae), o.u(0xbe986a4c, 0x4cf2be6a),
4571 // o.u(0xeed85a6c, 0x6c82ee5a), o.u(0xc3fc417e, 0x7ebdc341),
4572 // o.u(0x06f102f5, 0xf5f30602), o.u(0xd11d4f83, 0x8352d14f),
4573 // o.u(0xe4d05c68, 0x688ce45c), o.u(0x07a2f451, 0x515607f4),
4574 // o.u(0x5cb934d1, 0xd18d5c34), o.u(0x18e908f9, 0xf9e11808),
4575 // o.u(0xaedf93e2, 0xe24cae93), o.u(0x954d73ab, 0xab3e9573),
4576 // o.u(0xf5c45362, 0x6297f553), o.u(0x41543f2a, 0x2a6b413f),
4577 // o.u(0x14100c08, 0x081c140c), o.u(0xf6315295, 0x9563f652),
4578 // o.u(0xaf8c6546, 0x46e9af65), o.u(0xe2215e9d, 0x9d7fe25e),
4579 // o.u(0x78602830, 0x30487828), o.u(0xf86ea137, 0x37cff8a1),
4580 // o.u(0x11140f0a, 0x0a1b110f), o.u(0xc45eb52f, 0x2febc4b5),
4581 // o.u(0x1b1c090e, 0x0e151b09), o.u(0x5a483624, 0x247e5a36),
4582 // o.u(0xb6369b1b, 0x1badb69b), o.u(0x47a53ddf, 0xdf98473d),
4583 // o.u(0x6a8126cd, 0xcda76a26), o.u(0xbb9c694e, 0x4ef5bb69),
4584 // o.u(0x4cfecd7f, 0x7f334ccd), o.u(0xbacf9fea, 0xea50ba9f),
4585 // o.u(0x2d241b12, 0x123f2d1b), o.u(0xb93a9e1d, 0x1da4b99e),
4586 // o.u(0x9cb07458, 0x58c49c74), o.u(0x72682e34, 0x3446722e),
4587 // o.u(0x776c2d36, 0x3641772d), o.u(0xcda3b2dc, 0xdc11cdb2),
4588 // o.u(0x2973eeb4, 0xb49d29ee), o.u(0x16b6fb5b, 0x5b4d16fb),
4589 // o.u(0x0153f6a4, 0xa4a501f6), o.u(0xd7ec4d76, 0x76a1d74d),
4590 // o.u(0xa37561b7, 0xb714a361), o.u(0x49face7d, 0x7d3449ce),
4591 // o.u(0x8da47b52, 0x52df8d7b), o.u(0x42a13edd, 0xdd9f423e),
4592 // o.u(0x93bc715e, 0x5ecd9371), o.u(0xa2269713, 0x13b1a297),
4593 // o.u(0x0457f5a6, 0xa6a204f5), o.u(0xb86968b9, 0xb901b868),
4594 // o.u(0x00000000, 0x00000000), o.u(0x74992cc1, 0xc1b5742c),
4595 // o.u(0xa0806040, 0x40e0a060), o.u(0x21dd1fe3, 0xe3c2211f),
4596 // o.u(0x43f2c879, 0x793a43c8), o.u(0x2c77edb6, 0xb69a2ced),
4597 // o.u(0xd9b3bed4, 0xd40dd9be), o.u(0xca01468d, 0x8d47ca46),
4598 // o.u(0x70ced967, 0x671770d9), o.u(0xdde44b72, 0x72afdd4b),
4599 // o.u(0x7933de94, 0x94ed79de), o.u(0x672bd498, 0x98ff67d4),
4600 // o.u(0x237be8b0, 0xb09323e8), o.u(0xde114a85, 0x855bde4a),
4601 // o.u(0xbd6d6bbb, 0xbb06bd6b), o.u(0x7e912ac5, 0xc5bb7e2a),
4602 // o.u(0x349ee54f, 0x4f7b34e5), o.u(0x3ac116ed, 0xedd73a16),
4603 // o.u(0x5417c586, 0x86d254c5), o.u(0x622fd79a, 0x9af862d7),
4604 // o.u(0xffcc5566, 0x6699ff55), o.u(0xa7229411, 0x11b6a794),
4605 // o.u(0x4a0fcf8a, 0x8ac04acf), o.u(0x30c910e9, 0xe9d93010),
4606 // o.u(0x0a080604, 0x040e0a06), o.u(0x98e781fe, 0xfe669881),
4607 // o.u(0x0b5bf0a0, 0xa0ab0bf0), o.u(0xccf04478, 0x78b4cc44),
4608 // o.u(0xd54aba25, 0x25f0d5ba), o.u(0x3e96e34b, 0x4b753ee3),
4609 // o.u(0x0e5ff3a2, 0xa2ac0ef3), o.u(0x19bafe5d, 0x5d4419fe),
4610 // o.u(0x5b1bc080, 0x80db5bc0), o.u(0x850a8a05, 0x0580858a),
4611 // o.u(0xec7ead3f, 0x3fd3ecad), o.u(0xdf42bc21, 0x21fedfbc),
4612 // o.u(0xd8e04870, 0x70a8d848), o.u(0x0cf904f1, 0xf1fd0c04),
4613 // o.u(0x7ac6df63, 0x63197adf), o.u(0x58eec177, 0x772f58c1),
4614 // o.u(0x9f4575af, 0xaf309f75), o.u(0xa5846342, 0x42e7a563),
4615 // o.u(0x50403020, 0x20705030), o.u(0x2ed11ae5, 0xe5cb2e1a),
4616 // o.u(0x12e10efd, 0xfdef120e), o.u(0xb7656dbf, 0xbf08b76d),
4617 // o.u(0xd4194c81, 0x8155d44c), o.u(0x3c301418, 0x18243c14),
4618 // o.u(0x5f4c3526, 0x26795f35), o.u(0x719d2fc3, 0xc3b2712f),
4619 // o.u(0x3867e1be, 0xbe8638e1), o.u(0xfd6aa235, 0x35c8fda2),
4620 // o.u(0x4f0bcc88, 0x88c74fcc), o.u(0x4b5c392e, 0x2e654b39),
4621 // o.u(0xf93d5793, 0x936af957), o.u(0x0daaf255, 0x55580df2),
4622 // o.u(0x9de382fc, 0xfc619d82), o.u(0xc9f4477a, 0x7ab3c947),
4623 // o.u(0xef8bacc8, 0xc827efac), o.u(0x326fe7ba, 0xba8832e7),
4624 // o.u(0x7d642b32, 0x324f7d2b), o.u(0xa4d795e6, 0xe642a495),
4625 // o.u(0xfb9ba0c0, 0xc03bfba0), o.u(0xb3329819, 0x19aab398),
4626 // o.u(0x6827d19e, 0x9ef668d1), o.u(0x815d7fa3, 0xa322817f),
4627 // o.u(0xaa886644, 0x44eeaa66), o.u(0x82a87e54, 0x54d6827e),
4628 // o.u(0xe676ab3b, 0x3bdde6ab), o.u(0x9e16830b, 0x0b959e83),
4629 // o.u(0x4503ca8c, 0x8cc945ca), o.u(0x7b9529c7, 0xc7bc7b29),
4630 // o.u(0x6ed6d36b, 0x6b056ed3), o.u(0x44503c28, 0x286c443c),
4631 // o.u(0x8b5579a7, 0xa72c8b79), o.u(0x3d63e2bc, 0xbc813de2),
4632 // o.u(0x272c1d16, 0x1631271d), o.u(0x9a4176ad, 0xad379a76),
4633 // o.u(0x4dad3bdb, 0xdb964d3b), o.u(0xfac85664, 0x649efa56),
4634 // o.u(0xd2e84e74, 0x74a6d24e), o.u(0x22281e14, 0x1436221e),
4635 // o.u(0x763fdb92, 0x92e476db), o.u(0x1e180a0c, 0x0c121e0a),
4636 // o.u(0xb4906c48, 0x48fcb46c), o.u(0x376be4b8, 0xb88f37e4),
4637 // o.u(0xe7255d9f, 0x9f78e75d), o.u(0xb2616ebd, 0xbd0fb26e),
4638 // o.u(0x2a86ef43, 0x43692aef), o.u(0xf193a6c4, 0xc435f1a6),
4639 // o.u(0xe372a839, 0x39dae3a8), o.u(0xf762a431, 0x31c6f7a4),
4640 // o.u(0x59bd37d3, 0xd38a5937), o.u(0x86ff8bf2, 0xf274868b),
4641 // o.u(0x56b132d5, 0xd5835632), o.u(0xc50d438b, 0x8b4ec543),
4642 // o.u(0xebdc596e, 0x6e85eb59), o.u(0xc2afb7da, 0xda18c2b7),
4643 // o.u(0x8f028c01, 0x018e8f8c), o.u(0xac7964b1, 0xb11dac64),
4644 // o.u(0x6d23d29c, 0x9cf16dd2), o.u(0x3b92e049, 0x49723be0),
4645 // o.u(0xc7abb4d8, 0xd81fc7b4), o.u(0x1543faac, 0xacb915fa),
4646 // o.u(0x09fd07f3, 0xf3fa0907), o.u(0x6f8525cf, 0xcfa06f25),
4647 // o.u(0xea8fafca, 0xca20eaaf), o.u(0x89f38ef4, 0xf47d898e),
4648 // o.u(0x208ee947, 0x476720e9), o.u(0x28201810, 0x10382818),
4649 // o.u(0x64ded56f, 0x6f0b64d5), o.u(0x83fb88f0, 0xf0738388),
4650 // o.u(0xb1946f4a, 0x4afbb16f), o.u(0x96b8725c, 0x5cca9672),
4651 // o.u(0x6c702438, 0x38546c24), o.u(0x08aef157, 0x575f08f1),
4652 // o.u(0x52e6c773, 0x732152c7), o.u(0xf3355197, 0x9764f351),
4653 // o.u(0x658d23cb, 0xcbae6523), o.u(0x84597ca1, 0xa125847c),
4654 // o.u(0xbfcb9ce8, 0xe857bf9c), o.u(0x637c213e, 0x3e5d6321),
4655 // o.u(0x7c37dd96, 0x96ea7cdd), o.u(0x7fc2dc61, 0x611e7fdc),
4656 // o.u(0x911a860d, 0x0d9c9186), o.u(0x941e850f, 0x0f9b9485),
4657 // o.u(0xabdb90e0, 0xe04bab90), o.u(0xc6f8427c, 0x7cbac642),
4658 // o.u(0x57e2c471, 0x712657c4), o.u(0xe583aacc, 0xcc29e5aa),
4659 // o.u(0x733bd890, 0x90e373d8), o.u(0x0f0c0506, 0x06090f05),
4660 // o.u(0x03f501f7, 0xf7f40301), o.u(0x3638121c, 0x1c2a3612),
4661 // o.u(0xfe9fa3c2, 0xc23cfea3), o.u(0xe1d45f6a, 0x6a8be15f),
4662 // o.u(0x1047f9ae, 0xaebe10f9), o.u(0x6bd2d069, 0x69026bd0),
4663 // o.u(0xa82e9117, 0x17bfa891), o.u(0xe8295899, 0x9971e858),
4664 // o.u(0x6974273a, 0x3a536927), o.u(0xd04eb927, 0x27f7d0b9),
4665 // o.u(0x48a938d9, 0xd9914838), o.u(0x35cd13eb, 0xebde3513),
4666 // o.u(0xce56b32b, 0x2be5ceb3), o.u(0x55443322, 0x22775533),
4667 // o.u(0xd6bfbbd2, 0xd204d6bb), o.u(0x904970a9, 0xa9399070),
4668 // o.u(0x800e8907, 0x07878089), o.u(0xf266a733, 0x33c1f2a7),
4669 // o.u(0xc15ab62d, 0x2decc1b6), o.u(0x6678223c, 0x3c5a6622),
4670 // o.u(0xad2a9215, 0x15b8ad92), o.u(0x608920c9, 0xc9a96020),
4671 // o.u(0xdb154987, 0x875cdb49), o.u(0x1a4fffaa, 0xaab01aff),
4672 // o.u(0x88a07850, 0x50d88878), o.u(0x8e517aa5, 0xa52b8e7a),
4673 // o.u(0x8a068f03, 0x03898a8f), o.u(0x13b2f859, 0x594a13f8),
4674 // o.u(0x9b128009, 0x09929b80), o.u(0x3934171a, 0x1a233917),
4675 // o.u(0x75cada65, 0x651075da), o.u(0x53b531d7, 0xd7845331),
4676 // o.u(0x5113c684, 0x84d551c6), o.u(0xd3bbb8d0, 0xd003d3b8),
4677 // o.u(0x5e1fc382, 0x82dc5ec3), o.u(0xcb52b029, 0x29e2cbb0),
4678 // o.u(0x99b4775a, 0x5ac39977), o.u(0x333c111e, 0x1e2d3311),
4679 // o.u(0x46f6cb7b, 0x7b3d46cb), o.u(0x1f4bfca8, 0xa8b71ffc),
4680 // o.u(0x61dad66d, 0x6d0c61d6), o.u(0x4e583a2c, 0x2c624e3a)
4681 // ];
4682
4683 // var T5 = [
4684 // o.u(0xa5f497a5, 0xc6c632f4), o.u(0x8497eb84, 0xf8f86f97),
4685 // o.u(0x99b0c799, 0xeeee5eb0), o.u(0x8d8cf78d, 0xf6f67a8c),
4686 // o.u(0xd17e50d, 0xffffe817), o.u(0xbddcb7bd, 0xd6d60adc),
4687 // o.u(0xb1c8a7b1, 0xdede16c8), o.u(0x54fc3954, 0x91916dfc),
4688 // o.u(0x50f0c050, 0x606090f0), o.u(0x3050403, 0x2020705),
4689 // o.u(0xa9e087a9, 0xcece2ee0), o.u(0x7d87ac7d, 0x5656d187),
4690 // o.u(0x192bd519, 0xe7e7cc2b), o.u(0x62a67162, 0xb5b513a6),
4691 // o.u(0xe6319ae6, 0x4d4d7c31), o.u(0x9ab5c39a, 0xecec59b5),
4692 // o.u(0x45cf0545, 0x8f8f40cf), o.u(0x9dbc3e9d, 0x1f1fa3bc),
4693 // o.u(0x40c00940, 0x898949c0), o.u(0x8792ef87, 0xfafa6892),
4694 // o.u(0x153fc515, 0xefefd03f), o.u(0xeb267feb, 0xb2b29426),
4695 // o.u(0xc94007c9, 0x8e8ece40), o.u(0xb1ded0b, 0xfbfbe61d),
4696 // o.u(0xec2f82ec, 0x41416e2f), o.u(0x67a97d67, 0xb3b31aa9),
4697 // o.u(0xfd1cbefd, 0x5f5f431c), o.u(0xea258aea, 0x45456025),
4698 // o.u(0xbfda46bf, 0x2323f9da), o.u(0xf702a6f7, 0x53535102),
4699 // o.u(0x96a1d396, 0xe4e445a1), o.u(0x5bed2d5b, 0x9b9b76ed),
4700 // o.u(0xc25deac2, 0x7575285d), o.u(0x1c24d91c, 0xe1e1c524),
4701 // o.u(0xaee97aae, 0x3d3dd4e9), o.u(0x6abe986a, 0x4c4cf2be),
4702 // o.u(0x5aeed85a, 0x6c6c82ee), o.u(0x41c3fc41, 0x7e7ebdc3),
4703 // o.u(0x206f102, 0xf5f5f306), o.u(0x4fd11d4f, 0x838352d1),
4704 // o.u(0x5ce4d05c, 0x68688ce4), o.u(0xf407a2f4, 0x51515607),
4705 // o.u(0x345cb934, 0xd1d18d5c), o.u(0x818e908, 0xf9f9e118),
4706 // o.u(0x93aedf93, 0xe2e24cae), o.u(0x73954d73, 0xabab3e95),
4707 // o.u(0x53f5c453, 0x626297f5), o.u(0x3f41543f, 0x2a2a6b41),
4708 // o.u(0xc14100c, 0x8081c14), o.u(0x52f63152, 0x959563f6),
4709 // o.u(0x65af8c65, 0x4646e9af), o.u(0x5ee2215e, 0x9d9d7fe2),
4710 // o.u(0x28786028, 0x30304878), o.u(0xa1f86ea1, 0x3737cff8),
4711 // o.u(0xf11140f, 0xa0a1b11), o.u(0xb5c45eb5, 0x2f2febc4),
4712 // o.u(0x91b1c09, 0xe0e151b), o.u(0x365a4836, 0x24247e5a),
4713 // o.u(0x9bb6369b, 0x1b1badb6), o.u(0x3d47a53d, 0xdfdf9847),
4714 // o.u(0x266a8126, 0xcdcda76a), o.u(0x69bb9c69, 0x4e4ef5bb),
4715 // o.u(0xcd4cfecd, 0x7f7f334c), o.u(0x9fbacf9f, 0xeaea50ba),
4716 // o.u(0x1b2d241b, 0x12123f2d), o.u(0x9eb93a9e, 0x1d1da4b9),
4717 // o.u(0x749cb074, 0x5858c49c), o.u(0x2e72682e, 0x34344672),
4718 // o.u(0x2d776c2d, 0x36364177), o.u(0xb2cda3b2, 0xdcdc11cd),
4719 // o.u(0xee2973ee, 0xb4b49d29), o.u(0xfb16b6fb, 0x5b5b4d16),
4720 // o.u(0xf60153f6, 0xa4a4a501), o.u(0x4dd7ec4d, 0x7676a1d7),
4721 // o.u(0x61a37561, 0xb7b714a3), o.u(0xce49face, 0x7d7d3449),
4722 // o.u(0x7b8da47b, 0x5252df8d), o.u(0x3e42a13e, 0xdddd9f42),
4723 // o.u(0x7193bc71, 0x5e5ecd93), o.u(0x97a22697, 0x1313b1a2),
4724 // o.u(0xf50457f5, 0xa6a6a204), o.u(0x68b86968, 0xb9b901b8),
4725 // o.u(0x0, 0x0), o.u(0x2c74992c, 0xc1c1b574),
4726 // o.u(0x60a08060, 0x4040e0a0), o.u(0x1f21dd1f, 0xe3e3c221),
4727 // o.u(0xc843f2c8, 0x79793a43), o.u(0xed2c77ed, 0xb6b69a2c),
4728 // o.u(0xbed9b3be, 0xd4d40dd9), o.u(0x46ca0146, 0x8d8d47ca),
4729 // o.u(0xd970ced9, 0x67671770), o.u(0x4bdde44b, 0x7272afdd),
4730 // o.u(0xde7933de, 0x9494ed79), o.u(0xd4672bd4, 0x9898ff67),
4731 // o.u(0xe8237be8, 0xb0b09323), o.u(0x4ade114a, 0x85855bde),
4732 // o.u(0x6bbd6d6b, 0xbbbb06bd), o.u(0x2a7e912a, 0xc5c5bb7e),
4733 // o.u(0xe5349ee5, 0x4f4f7b34), o.u(0x163ac116, 0xededd73a),
4734 // o.u(0xc55417c5, 0x8686d254), o.u(0xd7622fd7, 0x9a9af862),
4735 // o.u(0x55ffcc55, 0x666699ff), o.u(0x94a72294, 0x1111b6a7),
4736 // o.u(0xcf4a0fcf, 0x8a8ac04a), o.u(0x1030c910, 0xe9e9d930),
4737 // o.u(0x60a0806, 0x4040e0a), o.u(0x8198e781, 0xfefe6698),
4738 // o.u(0xf00b5bf0, 0xa0a0ab0b), o.u(0x44ccf044, 0x7878b4cc),
4739 // o.u(0xbad54aba, 0x2525f0d5), o.u(0xe33e96e3, 0x4b4b753e),
4740 // o.u(0xf30e5ff3, 0xa2a2ac0e), o.u(0xfe19bafe, 0x5d5d4419),
4741 // o.u(0xc05b1bc0, 0x8080db5b), o.u(0x8a850a8a, 0x5058085),
4742 // o.u(0xadec7ead, 0x3f3fd3ec), o.u(0xbcdf42bc, 0x2121fedf),
4743 // o.u(0x48d8e048, 0x7070a8d8), o.u(0x40cf904, 0xf1f1fd0c),
4744 // o.u(0xdf7ac6df, 0x6363197a), o.u(0xc158eec1, 0x77772f58),
4745 // o.u(0x759f4575, 0xafaf309f), o.u(0x63a58463, 0x4242e7a5),
4746 // o.u(0x30504030, 0x20207050), o.u(0x1a2ed11a, 0xe5e5cb2e),
4747 // o.u(0xe12e10e, 0xfdfdef12), o.u(0x6db7656d, 0xbfbf08b7),
4748 // o.u(0x4cd4194c, 0x818155d4), o.u(0x143c3014, 0x1818243c),
4749 // o.u(0x355f4c35, 0x2626795f), o.u(0x2f719d2f, 0xc3c3b271),
4750 // o.u(0xe13867e1, 0xbebe8638), o.u(0xa2fd6aa2, 0x3535c8fd),
4751 // o.u(0xcc4f0bcc, 0x8888c74f), o.u(0x394b5c39, 0x2e2e654b),
4752 // o.u(0x57f93d57, 0x93936af9), o.u(0xf20daaf2, 0x5555580d),
4753 // o.u(0x829de382, 0xfcfc619d), o.u(0x47c9f447, 0x7a7ab3c9),
4754 // o.u(0xacef8bac, 0xc8c827ef), o.u(0xe7326fe7, 0xbaba8832),
4755 // o.u(0x2b7d642b, 0x32324f7d), o.u(0x95a4d795, 0xe6e642a4),
4756 // o.u(0xa0fb9ba0, 0xc0c03bfb), o.u(0x98b33298, 0x1919aab3),
4757 // o.u(0xd16827d1, 0x9e9ef668), o.u(0x7f815d7f, 0xa3a32281),
4758 // o.u(0x66aa8866, 0x4444eeaa), o.u(0x7e82a87e, 0x5454d682),
4759 // o.u(0xabe676ab, 0x3b3bdde6), o.u(0x839e1683, 0xb0b959e),
4760 // o.u(0xca4503ca, 0x8c8cc945), o.u(0x297b9529, 0xc7c7bc7b),
4761 // o.u(0xd36ed6d3, 0x6b6b056e), o.u(0x3c44503c, 0x28286c44),
4762 // o.u(0x798b5579, 0xa7a72c8b), o.u(0xe23d63e2, 0xbcbc813d),
4763 // o.u(0x1d272c1d, 0x16163127), o.u(0x769a4176, 0xadad379a),
4764 // o.u(0x3b4dad3b, 0xdbdb964d), o.u(0x56fac856, 0x64649efa),
4765 // o.u(0x4ed2e84e, 0x7474a6d2), o.u(0x1e22281e, 0x14143622),
4766 // o.u(0xdb763fdb, 0x9292e476), o.u(0xa1e180a, 0xc0c121e),
4767 // o.u(0x6cb4906c, 0x4848fcb4), o.u(0xe4376be4, 0xb8b88f37),
4768 // o.u(0x5de7255d, 0x9f9f78e7), o.u(0x6eb2616e, 0xbdbd0fb2),
4769 // o.u(0xef2a86ef, 0x4343692a), o.u(0xa6f193a6, 0xc4c435f1),
4770 // o.u(0xa8e372a8, 0x3939dae3), o.u(0xa4f762a4, 0x3131c6f7),
4771 // o.u(0x3759bd37, 0xd3d38a59), o.u(0x8b86ff8b, 0xf2f27486),
4772 // o.u(0x3256b132, 0xd5d58356), o.u(0x43c50d43, 0x8b8b4ec5),
4773 // o.u(0x59ebdc59, 0x6e6e85eb), o.u(0xb7c2afb7, 0xdada18c2),
4774 // o.u(0x8c8f028c, 0x1018e8f), o.u(0x64ac7964, 0xb1b11dac),
4775 // o.u(0xd26d23d2, 0x9c9cf16d), o.u(0xe03b92e0, 0x4949723b),
4776 // o.u(0xb4c7abb4, 0xd8d81fc7), o.u(0xfa1543fa, 0xacacb915),
4777 // o.u(0x709fd07, 0xf3f3fa09), o.u(0x256f8525, 0xcfcfa06f),
4778 // o.u(0xafea8faf, 0xcaca20ea), o.u(0x8e89f38e, 0xf4f47d89),
4779 // o.u(0xe9208ee9, 0x47476720), o.u(0x18282018, 0x10103828),
4780 // o.u(0xd564ded5, 0x6f6f0b64), o.u(0x8883fb88, 0xf0f07383),
4781 // o.u(0x6fb1946f, 0x4a4afbb1), o.u(0x7296b872, 0x5c5cca96),
4782 // o.u(0x246c7024, 0x3838546c), o.u(0xf108aef1, 0x57575f08),
4783 // o.u(0xc752e6c7, 0x73732152), o.u(0x51f33551, 0x979764f3),
4784 // o.u(0x23658d23, 0xcbcbae65), o.u(0x7c84597c, 0xa1a12584),
4785 // o.u(0x9cbfcb9c, 0xe8e857bf), o.u(0x21637c21, 0x3e3e5d63),
4786 // o.u(0xdd7c37dd, 0x9696ea7c), o.u(0xdc7fc2dc, 0x61611e7f),
4787 // o.u(0x86911a86, 0xd0d9c91), o.u(0x85941e85, 0xf0f9b94),
4788 // o.u(0x90abdb90, 0xe0e04bab), o.u(0x42c6f842, 0x7c7cbac6),
4789 // o.u(0xc457e2c4, 0x71712657), o.u(0xaae583aa, 0xcccc29e5),
4790 // o.u(0xd8733bd8, 0x9090e373), o.u(0x50f0c05, 0x606090f),
4791 // o.u(0x103f501, 0xf7f7f403), o.u(0x12363812, 0x1c1c2a36),
4792 // o.u(0xa3fe9fa3, 0xc2c23cfe), o.u(0x5fe1d45f, 0x6a6a8be1),
4793 // o.u(0xf91047f9, 0xaeaebe10), o.u(0xd06bd2d0, 0x6969026b),
4794 // o.u(0x91a82e91, 0x1717bfa8), o.u(0x58e82958, 0x999971e8),
4795 // o.u(0x27697427, 0x3a3a5369), o.u(0xb9d04eb9, 0x2727f7d0),
4796 // o.u(0x3848a938, 0xd9d99148), o.u(0x1335cd13, 0xebebde35),
4797 // o.u(0xb3ce56b3, 0x2b2be5ce), o.u(0x33554433, 0x22227755),
4798 // o.u(0xbbd6bfbb, 0xd2d204d6), o.u(0x70904970, 0xa9a93990),
4799 // o.u(0x89800e89, 0x7078780), o.u(0xa7f266a7, 0x3333c1f2),
4800 // o.u(0xb6c15ab6, 0x2d2decc1), o.u(0x22667822, 0x3c3c5a66),
4801 // o.u(0x92ad2a92, 0x1515b8ad), o.u(0x20608920, 0xc9c9a960),
4802 // o.u(0x49db1549, 0x87875cdb), o.u(0xff1a4fff, 0xaaaab01a),
4803 // o.u(0x7888a078, 0x5050d888), o.u(0x7a8e517a, 0xa5a52b8e),
4804 // o.u(0x8f8a068f, 0x303898a), o.u(0xf813b2f8, 0x59594a13),
4805 // o.u(0x809b1280, 0x909929b), o.u(0x17393417, 0x1a1a2339),
4806 // o.u(0xda75cada, 0x65651075), o.u(0x3153b531, 0xd7d78453),
4807 // o.u(0xc65113c6, 0x8484d551), o.u(0xb8d3bbb8, 0xd0d003d3),
4808 // o.u(0xc35e1fc3, 0x8282dc5e), o.u(0xb0cb52b0, 0x2929e2cb),
4809 // o.u(0x7799b477, 0x5a5ac399), o.u(0x11333c11, 0x1e1e2d33),
4810 // o.u(0xcb46f6cb, 0x7b7b3d46), o.u(0xfc1f4bfc, 0xa8a8b71f),
4811 // o.u(0xd661dad6, 0x6d6d0c61), o.u(0x3a4e583a, 0x2c2c624e)
4812 // ];
4813
4814 // var T6 = [
4815 // o.u(0xf4a5f497, 0xa5c6c632), o.u(0x978497eb, 0x84f8f86f),
4816 // o.u(0xb099b0c7, 0x99eeee5e), o.u(0x8c8d8cf7, 0x8df6f67a),
4817 // o.u(0x170d17e5, 0xdffffe8), o.u(0xdcbddcb7, 0xbdd6d60a),
4818 // o.u(0xc8b1c8a7, 0xb1dede16), o.u(0xfc54fc39, 0x5491916d),
4819 // o.u(0xf050f0c0, 0x50606090), o.u(0x5030504, 0x3020207),
4820 // o.u(0xe0a9e087, 0xa9cece2e), o.u(0x877d87ac, 0x7d5656d1),
4821 // o.u(0x2b192bd5, 0x19e7e7cc), o.u(0xa662a671, 0x62b5b513),
4822 // o.u(0x31e6319a, 0xe64d4d7c), o.u(0xb59ab5c3, 0x9aecec59),
4823 // o.u(0xcf45cf05, 0x458f8f40), o.u(0xbc9dbc3e, 0x9d1f1fa3),
4824 // o.u(0xc040c009, 0x40898949), o.u(0x928792ef, 0x87fafa68),
4825 // o.u(0x3f153fc5, 0x15efefd0), o.u(0x26eb267f, 0xebb2b294),
4826 // o.u(0x40c94007, 0xc98e8ece), o.u(0x1d0b1ded, 0xbfbfbe6),
4827 // o.u(0x2fec2f82, 0xec41416e), o.u(0xa967a97d, 0x67b3b31a),
4828 // o.u(0x1cfd1cbe, 0xfd5f5f43), o.u(0x25ea258a, 0xea454560),
4829 // o.u(0xdabfda46, 0xbf2323f9), o.u(0x2f702a6, 0xf7535351),
4830 // o.u(0xa196a1d3, 0x96e4e445), o.u(0xed5bed2d, 0x5b9b9b76),
4831 // o.u(0x5dc25dea, 0xc2757528), o.u(0x241c24d9, 0x1ce1e1c5),
4832 // o.u(0xe9aee97a, 0xae3d3dd4), o.u(0xbe6abe98, 0x6a4c4cf2),
4833 // o.u(0xee5aeed8, 0x5a6c6c82), o.u(0xc341c3fc, 0x417e7ebd),
4834 // o.u(0x60206f1, 0x2f5f5f3), o.u(0xd14fd11d, 0x4f838352),
4835 // o.u(0xe45ce4d0, 0x5c68688c), o.u(0x7f407a2, 0xf4515156),
4836 // o.u(0x5c345cb9, 0x34d1d18d), o.u(0x180818e9, 0x8f9f9e1),
4837 // o.u(0xae93aedf, 0x93e2e24c), o.u(0x9573954d, 0x73abab3e),
4838 // o.u(0xf553f5c4, 0x53626297), o.u(0x413f4154, 0x3f2a2a6b),
4839 // o.u(0x140c1410, 0xc08081c), o.u(0xf652f631, 0x52959563),
4840 // o.u(0xaf65af8c, 0x654646e9), o.u(0xe25ee221, 0x5e9d9d7f),
4841 // o.u(0x78287860, 0x28303048), o.u(0xf8a1f86e, 0xa13737cf),
4842 // o.u(0x110f1114, 0xf0a0a1b), o.u(0xc4b5c45e, 0xb52f2feb),
4843 // o.u(0x1b091b1c, 0x90e0e15), o.u(0x5a365a48, 0x3624247e),
4844 // o.u(0xb69bb636, 0x9b1b1bad), o.u(0x473d47a5, 0x3ddfdf98),
4845 // o.u(0x6a266a81, 0x26cdcda7), o.u(0xbb69bb9c, 0x694e4ef5),
4846 // o.u(0x4ccd4cfe, 0xcd7f7f33), o.u(0xba9fbacf, 0x9feaea50),
4847 // o.u(0x2d1b2d24, 0x1b12123f), o.u(0xb99eb93a, 0x9e1d1da4),
4848 // o.u(0x9c749cb0, 0x745858c4), o.u(0x722e7268, 0x2e343446),
4849 // o.u(0x772d776c, 0x2d363641), o.u(0xcdb2cda3, 0xb2dcdc11),
4850 // o.u(0x29ee2973, 0xeeb4b49d), o.u(0x16fb16b6, 0xfb5b5b4d),
4851 // o.u(0x1f60153, 0xf6a4a4a5), o.u(0xd74dd7ec, 0x4d7676a1),
4852 // o.u(0xa361a375, 0x61b7b714), o.u(0x49ce49fa, 0xce7d7d34),
4853 // o.u(0x8d7b8da4, 0x7b5252df), o.u(0x423e42a1, 0x3edddd9f),
4854 // o.u(0x937193bc, 0x715e5ecd), o.u(0xa297a226, 0x971313b1),
4855 // o.u(0x4f50457, 0xf5a6a6a2), o.u(0xb868b869, 0x68b9b901),
4856 // o.u(0x0, 0x0), o.u(0x742c7499, 0x2cc1c1b5),
4857 // o.u(0xa060a080, 0x604040e0), o.u(0x211f21dd, 0x1fe3e3c2),
4858 // o.u(0x43c843f2, 0xc879793a), o.u(0x2ced2c77, 0xedb6b69a),
4859 // o.u(0xd9bed9b3, 0xbed4d40d), o.u(0xca46ca01, 0x468d8d47),
4860 // o.u(0x70d970ce, 0xd9676717), o.u(0xdd4bdde4, 0x4b7272af),
4861 // o.u(0x79de7933, 0xde9494ed), o.u(0x67d4672b, 0xd49898ff),
4862 // o.u(0x23e8237b, 0xe8b0b093), o.u(0xde4ade11, 0x4a85855b),
4863 // o.u(0xbd6bbd6d, 0x6bbbbb06), o.u(0x7e2a7e91, 0x2ac5c5bb),
4864 // o.u(0x34e5349e, 0xe54f4f7b), o.u(0x3a163ac1, 0x16ededd7),
4865 // o.u(0x54c55417, 0xc58686d2), o.u(0x62d7622f, 0xd79a9af8),
4866 // o.u(0xff55ffcc, 0x55666699), o.u(0xa794a722, 0x941111b6),
4867 // o.u(0x4acf4a0f, 0xcf8a8ac0), o.u(0x301030c9, 0x10e9e9d9),
4868 // o.u(0xa060a08, 0x604040e), o.u(0x988198e7, 0x81fefe66),
4869 // o.u(0xbf00b5b, 0xf0a0a0ab), o.u(0xcc44ccf0, 0x447878b4),
4870 // o.u(0xd5bad54a, 0xba2525f0), o.u(0x3ee33e96, 0xe34b4b75),
4871 // o.u(0xef30e5f, 0xf3a2a2ac), o.u(0x19fe19ba, 0xfe5d5d44),
4872 // o.u(0x5bc05b1b, 0xc08080db), o.u(0x858a850a, 0x8a050580),
4873 // o.u(0xecadec7e, 0xad3f3fd3), o.u(0xdfbcdf42, 0xbc2121fe),
4874 // o.u(0xd848d8e0, 0x487070a8), o.u(0xc040cf9, 0x4f1f1fd),
4875 // o.u(0x7adf7ac6, 0xdf636319), o.u(0x58c158ee, 0xc177772f),
4876 // o.u(0x9f759f45, 0x75afaf30), o.u(0xa563a584, 0x634242e7),
4877 // o.u(0x50305040, 0x30202070), o.u(0x2e1a2ed1, 0x1ae5e5cb),
4878 // o.u(0x120e12e1, 0xefdfdef), o.u(0xb76db765, 0x6dbfbf08),
4879 // o.u(0xd44cd419, 0x4c818155), o.u(0x3c143c30, 0x14181824),
4880 // o.u(0x5f355f4c, 0x35262679), o.u(0x712f719d, 0x2fc3c3b2),
4881 // o.u(0x38e13867, 0xe1bebe86), o.u(0xfda2fd6a, 0xa23535c8),
4882 // o.u(0x4fcc4f0b, 0xcc8888c7), o.u(0x4b394b5c, 0x392e2e65),
4883 // o.u(0xf957f93d, 0x5793936a), o.u(0xdf20daa, 0xf2555558),
4884 // o.u(0x9d829de3, 0x82fcfc61), o.u(0xc947c9f4, 0x477a7ab3),
4885 // o.u(0xefacef8b, 0xacc8c827), o.u(0x32e7326f, 0xe7baba88),
4886 // o.u(0x7d2b7d64, 0x2b32324f), o.u(0xa495a4d7, 0x95e6e642),
4887 // o.u(0xfba0fb9b, 0xa0c0c03b), o.u(0xb398b332, 0x981919aa),
4888 // o.u(0x68d16827, 0xd19e9ef6), o.u(0x817f815d, 0x7fa3a322),
4889 // o.u(0xaa66aa88, 0x664444ee), o.u(0x827e82a8, 0x7e5454d6),
4890 // o.u(0xe6abe676, 0xab3b3bdd), o.u(0x9e839e16, 0x830b0b95),
4891 // o.u(0x45ca4503, 0xca8c8cc9), o.u(0x7b297b95, 0x29c7c7bc),
4892 // o.u(0x6ed36ed6, 0xd36b6b05), o.u(0x443c4450, 0x3c28286c),
4893 // o.u(0x8b798b55, 0x79a7a72c), o.u(0x3de23d63, 0xe2bcbc81),
4894 // o.u(0x271d272c, 0x1d161631), o.u(0x9a769a41, 0x76adad37),
4895 // o.u(0x4d3b4dad, 0x3bdbdb96), o.u(0xfa56fac8, 0x5664649e),
4896 // o.u(0xd24ed2e8, 0x4e7474a6), o.u(0x221e2228, 0x1e141436),
4897 // o.u(0x76db763f, 0xdb9292e4), o.u(0x1e0a1e18, 0xa0c0c12),
4898 // o.u(0xb46cb490, 0x6c4848fc), o.u(0x37e4376b, 0xe4b8b88f),
4899 // o.u(0xe75de725, 0x5d9f9f78), o.u(0xb26eb261, 0x6ebdbd0f),
4900 // o.u(0x2aef2a86, 0xef434369), o.u(0xf1a6f193, 0xa6c4c435),
4901 // o.u(0xe3a8e372, 0xa83939da), o.u(0xf7a4f762, 0xa43131c6),
4902 // o.u(0x593759bd, 0x37d3d38a), o.u(0x868b86ff, 0x8bf2f274),
4903 // o.u(0x563256b1, 0x32d5d583), o.u(0xc543c50d, 0x438b8b4e),
4904 // o.u(0xeb59ebdc, 0x596e6e85), o.u(0xc2b7c2af, 0xb7dada18),
4905 // o.u(0x8f8c8f02, 0x8c01018e), o.u(0xac64ac79, 0x64b1b11d),
4906 // o.u(0x6dd26d23, 0xd29c9cf1), o.u(0x3be03b92, 0xe0494972),
4907 // o.u(0xc7b4c7ab, 0xb4d8d81f), o.u(0x15fa1543, 0xfaacacb9),
4908 // o.u(0x90709fd, 0x7f3f3fa), o.u(0x6f256f85, 0x25cfcfa0),
4909 // o.u(0xeaafea8f, 0xafcaca20), o.u(0x898e89f3, 0x8ef4f47d),
4910 // o.u(0x20e9208e, 0xe9474767), o.u(0x28182820, 0x18101038),
4911 // o.u(0x64d564de, 0xd56f6f0b), o.u(0x838883fb, 0x88f0f073),
4912 // o.u(0xb16fb194, 0x6f4a4afb), o.u(0x967296b8, 0x725c5cca),
4913 // o.u(0x6c246c70, 0x24383854), o.u(0x8f108ae, 0xf157575f),
4914 // o.u(0x52c752e6, 0xc7737321), o.u(0xf351f335, 0x51979764),
4915 // o.u(0x6523658d, 0x23cbcbae), o.u(0x847c8459, 0x7ca1a125),
4916 // o.u(0xbf9cbfcb, 0x9ce8e857), o.u(0x6321637c, 0x213e3e5d),
4917 // o.u(0x7cdd7c37, 0xdd9696ea), o.u(0x7fdc7fc2, 0xdc61611e),
4918 // o.u(0x9186911a, 0x860d0d9c), o.u(0x9485941e, 0x850f0f9b),
4919 // o.u(0xab90abdb, 0x90e0e04b), o.u(0xc642c6f8, 0x427c7cba),
4920 // o.u(0x57c457e2, 0xc4717126), o.u(0xe5aae583, 0xaacccc29),
4921 // o.u(0x73d8733b, 0xd89090e3), o.u(0xf050f0c, 0x5060609),
4922 // o.u(0x30103f5, 0x1f7f7f4), o.u(0x36123638, 0x121c1c2a),
4923 // o.u(0xfea3fe9f, 0xa3c2c23c), o.u(0xe15fe1d4, 0x5f6a6a8b),
4924 // o.u(0x10f91047, 0xf9aeaebe), o.u(0x6bd06bd2, 0xd0696902),
4925 // o.u(0xa891a82e, 0x911717bf), o.u(0xe858e829, 0x58999971),
4926 // o.u(0x69276974, 0x273a3a53), o.u(0xd0b9d04e, 0xb92727f7),
4927 // o.u(0x483848a9, 0x38d9d991), o.u(0x351335cd, 0x13ebebde),
4928 // o.u(0xceb3ce56, 0xb32b2be5), o.u(0x55335544, 0x33222277),
4929 // o.u(0xd6bbd6bf, 0xbbd2d204), o.u(0x90709049, 0x70a9a939),
4930 // o.u(0x8089800e, 0x89070787), o.u(0xf2a7f266, 0xa73333c1),
4931 // o.u(0xc1b6c15a, 0xb62d2dec), o.u(0x66226678, 0x223c3c5a),
4932 // o.u(0xad92ad2a, 0x921515b8), o.u(0x60206089, 0x20c9c9a9),
4933 // o.u(0xdb49db15, 0x4987875c), o.u(0x1aff1a4f, 0xffaaaab0),
4934 // o.u(0x887888a0, 0x785050d8), o.u(0x8e7a8e51, 0x7aa5a52b),
4935 // o.u(0x8a8f8a06, 0x8f030389), o.u(0x13f813b2, 0xf859594a),
4936 // o.u(0x9b809b12, 0x80090992), o.u(0x39173934, 0x171a1a23),
4937 // o.u(0x75da75ca, 0xda656510), o.u(0x533153b5, 0x31d7d784),
4938 // o.u(0x51c65113, 0xc68484d5), o.u(0xd3b8d3bb, 0xb8d0d003),
4939 // o.u(0x5ec35e1f, 0xc38282dc), o.u(0xcbb0cb52, 0xb02929e2),
4940 // o.u(0x997799b4, 0x775a5ac3), o.u(0x3311333c, 0x111e1e2d),
4941 // o.u(0x46cb46f6, 0xcb7b7b3d), o.u(0x1ffc1f4b, 0xfca8a8b7),
4942 // o.u(0x61d661da, 0xd66d6d0c), o.u(0x4e3a4e58, 0x3a2c2c62)
4943 // ];
4944
4945 // var T7 = [
4946 // o.u(0x32f4a5f4, 0x97a5c6c6), o.u(0x6f978497, 0xeb84f8f8),
4947 // o.u(0x5eb099b0, 0xc799eeee), o.u(0x7a8c8d8c, 0xf78df6f6),
4948 // o.u(0xe8170d17, 0xe50dffff), o.u(0xadcbddc, 0xb7bdd6d6),
4949 // o.u(0x16c8b1c8, 0xa7b1dede), o.u(0x6dfc54fc, 0x39549191),
4950 // o.u(0x90f050f0, 0xc0506060), o.u(0x7050305, 0x4030202),
4951 // o.u(0x2ee0a9e0, 0x87a9cece), o.u(0xd1877d87, 0xac7d5656),
4952 // o.u(0xcc2b192b, 0xd519e7e7), o.u(0x13a662a6, 0x7162b5b5),
4953 // o.u(0x7c31e631, 0x9ae64d4d), o.u(0x59b59ab5, 0xc39aecec),
4954 // o.u(0x40cf45cf, 0x5458f8f), o.u(0xa3bc9dbc, 0x3e9d1f1f),
4955 // o.u(0x49c040c0, 0x9408989), o.u(0x68928792, 0xef87fafa),
4956 // o.u(0xd03f153f, 0xc515efef), o.u(0x9426eb26, 0x7febb2b2),
4957 // o.u(0xce40c940, 0x7c98e8e), o.u(0xe61d0b1d, 0xed0bfbfb),
4958 // o.u(0x6e2fec2f, 0x82ec4141), o.u(0x1aa967a9, 0x7d67b3b3),
4959 // o.u(0x431cfd1c, 0xbefd5f5f), o.u(0x6025ea25, 0x8aea4545),
4960 // o.u(0xf9dabfda, 0x46bf2323), o.u(0x5102f702, 0xa6f75353),
4961 // o.u(0x45a196a1, 0xd396e4e4), o.u(0x76ed5bed, 0x2d5b9b9b),
4962 // o.u(0x285dc25d, 0xeac27575), o.u(0xc5241c24, 0xd91ce1e1),
4963 // o.u(0xd4e9aee9, 0x7aae3d3d), o.u(0xf2be6abe, 0x986a4c4c),
4964 // o.u(0x82ee5aee, 0xd85a6c6c), o.u(0xbdc341c3, 0xfc417e7e),
4965 // o.u(0xf3060206, 0xf102f5f5), o.u(0x52d14fd1, 0x1d4f8383),
4966 // o.u(0x8ce45ce4, 0xd05c6868), o.u(0x5607f407, 0xa2f45151),
4967 // o.u(0x8d5c345c, 0xb934d1d1), o.u(0xe1180818, 0xe908f9f9),
4968 // o.u(0x4cae93ae, 0xdf93e2e2), o.u(0x3e957395, 0x4d73abab),
4969 // o.u(0x97f553f5, 0xc4536262), o.u(0x6b413f41, 0x543f2a2a),
4970 // o.u(0x1c140c14, 0x100c0808), o.u(0x63f652f6, 0x31529595),
4971 // o.u(0xe9af65af, 0x8c654646), o.u(0x7fe25ee2, 0x215e9d9d),
4972 // o.u(0x48782878, 0x60283030), o.u(0xcff8a1f8, 0x6ea13737),
4973 // o.u(0x1b110f11, 0x140f0a0a), o.u(0xebc4b5c4, 0x5eb52f2f),
4974 // o.u(0x151b091b, 0x1c090e0e), o.u(0x7e5a365a, 0x48362424),
4975 // o.u(0xadb69bb6, 0x369b1b1b), o.u(0x98473d47, 0xa53ddfdf),
4976 // o.u(0xa76a266a, 0x8126cdcd), o.u(0xf5bb69bb, 0x9c694e4e),
4977 // o.u(0x334ccd4c, 0xfecd7f7f), o.u(0x50ba9fba, 0xcf9feaea),
4978 // o.u(0x3f2d1b2d, 0x241b1212), o.u(0xa4b99eb9, 0x3a9e1d1d),
4979 // o.u(0xc49c749c, 0xb0745858), o.u(0x46722e72, 0x682e3434),
4980 // o.u(0x41772d77, 0x6c2d3636), o.u(0x11cdb2cd, 0xa3b2dcdc),
4981 // o.u(0x9d29ee29, 0x73eeb4b4), o.u(0x4d16fb16, 0xb6fb5b5b),
4982 // o.u(0xa501f601, 0x53f6a4a4), o.u(0xa1d74dd7, 0xec4d7676),
4983 // o.u(0x14a361a3, 0x7561b7b7), o.u(0x3449ce49, 0xface7d7d),
4984 // o.u(0xdf8d7b8d, 0xa47b5252), o.u(0x9f423e42, 0xa13edddd),
4985 // o.u(0xcd937193, 0xbc715e5e), o.u(0xb1a297a2, 0x26971313),
4986 // o.u(0xa204f504, 0x57f5a6a6), o.u(0x1b868b8, 0x6968b9b9),
4987 // o.u(0x0, 0x0), o.u(0xb5742c74, 0x992cc1c1),
4988 // o.u(0xe0a060a0, 0x80604040), o.u(0xc2211f21, 0xdd1fe3e3),
4989 // o.u(0x3a43c843, 0xf2c87979), o.u(0x9a2ced2c, 0x77edb6b6),
4990 // o.u(0xdd9bed9, 0xb3bed4d4), o.u(0x47ca46ca, 0x1468d8d),
4991 // o.u(0x1770d970, 0xced96767), o.u(0xafdd4bdd, 0xe44b7272),
4992 // o.u(0xed79de79, 0x33de9494), o.u(0xff67d467, 0x2bd49898),
4993 // o.u(0x9323e823, 0x7be8b0b0), o.u(0x5bde4ade, 0x114a8585),
4994 // o.u(0x6bd6bbd, 0x6d6bbbbb), o.u(0xbb7e2a7e, 0x912ac5c5),
4995 // o.u(0x7b34e534, 0x9ee54f4f), o.u(0xd73a163a, 0xc116eded),
4996 // o.u(0xd254c554, 0x17c58686), o.u(0xf862d762, 0x2fd79a9a),
4997 // o.u(0x99ff55ff, 0xcc556666), o.u(0xb6a794a7, 0x22941111),
4998 // o.u(0xc04acf4a, 0xfcf8a8a), o.u(0xd9301030, 0xc910e9e9),
4999 // o.u(0xe0a060a, 0x8060404), o.u(0x66988198, 0xe781fefe),
5000 // o.u(0xab0bf00b, 0x5bf0a0a0), o.u(0xb4cc44cc, 0xf0447878),
5001 // o.u(0xf0d5bad5, 0x4aba2525), o.u(0x753ee33e, 0x96e34b4b),
5002 // o.u(0xac0ef30e, 0x5ff3a2a2), o.u(0x4419fe19, 0xbafe5d5d),
5003 // o.u(0xdb5bc05b, 0x1bc08080), o.u(0x80858a85, 0xa8a0505),
5004 // o.u(0xd3ecadec, 0x7ead3f3f), o.u(0xfedfbcdf, 0x42bc2121),
5005 // o.u(0xa8d848d8, 0xe0487070), o.u(0xfd0c040c, 0xf904f1f1),
5006 // o.u(0x197adf7a, 0xc6df6363), o.u(0x2f58c158, 0xeec17777),
5007 // o.u(0x309f759f, 0x4575afaf), o.u(0xe7a563a5, 0x84634242),
5008 // o.u(0x70503050, 0x40302020), o.u(0xcb2e1a2e, 0xd11ae5e5),
5009 // o.u(0xef120e12, 0xe10efdfd), o.u(0x8b76db7, 0x656dbfbf),
5010 // o.u(0x55d44cd4, 0x194c8181), o.u(0x243c143c, 0x30141818),
5011 // o.u(0x795f355f, 0x4c352626), o.u(0xb2712f71, 0x9d2fc3c3),
5012 // o.u(0x8638e138, 0x67e1bebe), o.u(0xc8fda2fd, 0x6aa23535),
5013 // o.u(0xc74fcc4f, 0xbcc8888), o.u(0x654b394b, 0x5c392e2e),
5014 // o.u(0x6af957f9, 0x3d579393), o.u(0x580df20d, 0xaaf25555),
5015 // o.u(0x619d829d, 0xe382fcfc), o.u(0xb3c947c9, 0xf4477a7a),
5016 // o.u(0x27efacef, 0x8bacc8c8), o.u(0x8832e732, 0x6fe7baba),
5017 // o.u(0x4f7d2b7d, 0x642b3232), o.u(0x42a495a4, 0xd795e6e6),
5018 // o.u(0x3bfba0fb, 0x9ba0c0c0), o.u(0xaab398b3, 0x32981919),
5019 // o.u(0xf668d168, 0x27d19e9e), o.u(0x22817f81, 0x5d7fa3a3),
5020 // o.u(0xeeaa66aa, 0x88664444), o.u(0xd6827e82, 0xa87e5454),
5021 // o.u(0xdde6abe6, 0x76ab3b3b), o.u(0x959e839e, 0x16830b0b),
5022 // o.u(0xc945ca45, 0x3ca8c8c), o.u(0xbc7b297b, 0x9529c7c7),
5023 // o.u(0x56ed36e, 0xd6d36b6b), o.u(0x6c443c44, 0x503c2828),
5024 // o.u(0x2c8b798b, 0x5579a7a7), o.u(0x813de23d, 0x63e2bcbc),
5025 // o.u(0x31271d27, 0x2c1d1616), o.u(0x379a769a, 0x4176adad),
5026 // o.u(0x964d3b4d, 0xad3bdbdb), o.u(0x9efa56fa, 0xc8566464),
5027 // o.u(0xa6d24ed2, 0xe84e7474), o.u(0x36221e22, 0x281e1414),
5028 // o.u(0xe476db76, 0x3fdb9292), o.u(0x121e0a1e, 0x180a0c0c),
5029 // o.u(0xfcb46cb4, 0x906c4848), o.u(0x8f37e437, 0x6be4b8b8),
5030 // o.u(0x78e75de7, 0x255d9f9f), o.u(0xfb26eb2, 0x616ebdbd),
5031 // o.u(0x692aef2a, 0x86ef4343), o.u(0x35f1a6f1, 0x93a6c4c4),
5032 // o.u(0xdae3a8e3, 0x72a83939), o.u(0xc6f7a4f7, 0x62a43131),
5033 // o.u(0x8a593759, 0xbd37d3d3), o.u(0x74868b86, 0xff8bf2f2),
5034 // o.u(0x83563256, 0xb132d5d5), o.u(0x4ec543c5, 0xd438b8b),
5035 // o.u(0x85eb59eb, 0xdc596e6e), o.u(0x18c2b7c2, 0xafb7dada),
5036 // o.u(0x8e8f8c8f, 0x28c0101), o.u(0x1dac64ac, 0x7964b1b1),
5037 // o.u(0xf16dd26d, 0x23d29c9c), o.u(0x723be03b, 0x92e04949),
5038 // o.u(0x1fc7b4c7, 0xabb4d8d8), o.u(0xb915fa15, 0x43faacac),
5039 // o.u(0xfa090709, 0xfd07f3f3), o.u(0xa06f256f, 0x8525cfcf),
5040 // o.u(0x20eaafea, 0x8fafcaca), o.u(0x7d898e89, 0xf38ef4f4),
5041 // o.u(0x6720e920, 0x8ee94747), o.u(0x38281828, 0x20181010),
5042 // o.u(0xb64d564, 0xded56f6f), o.u(0x73838883, 0xfb88f0f0),
5043 // o.u(0xfbb16fb1, 0x946f4a4a), o.u(0xca967296, 0xb8725c5c),
5044 // o.u(0x546c246c, 0x70243838), o.u(0x5f08f108, 0xaef15757),
5045 // o.u(0x2152c752, 0xe6c77373), o.u(0x64f351f3, 0x35519797),
5046 // o.u(0xae652365, 0x8d23cbcb), o.u(0x25847c84, 0x597ca1a1),
5047 // o.u(0x57bf9cbf, 0xcb9ce8e8), o.u(0x5d632163, 0x7c213e3e),
5048 // o.u(0xea7cdd7c, 0x37dd9696), o.u(0x1e7fdc7f, 0xc2dc6161),
5049 // o.u(0x9c918691, 0x1a860d0d), o.u(0x9b948594, 0x1e850f0f),
5050 // o.u(0x4bab90ab, 0xdb90e0e0), o.u(0xbac642c6, 0xf8427c7c),
5051 // o.u(0x2657c457, 0xe2c47171), o.u(0x29e5aae5, 0x83aacccc),
5052 // o.u(0xe373d873, 0x3bd89090), o.u(0x90f050f, 0xc050606),
5053 // o.u(0xf4030103, 0xf501f7f7), o.u(0x2a361236, 0x38121c1c),
5054 // o.u(0x3cfea3fe, 0x9fa3c2c2), o.u(0x8be15fe1, 0xd45f6a6a),
5055 // o.u(0xbe10f910, 0x47f9aeae), o.u(0x26bd06b, 0xd2d06969),
5056 // o.u(0xbfa891a8, 0x2e911717), o.u(0x71e858e8, 0x29589999),
5057 // o.u(0x53692769, 0x74273a3a), o.u(0xf7d0b9d0, 0x4eb92727),
5058 // o.u(0x91483848, 0xa938d9d9), o.u(0xde351335, 0xcd13ebeb),
5059 // o.u(0xe5ceb3ce, 0x56b32b2b), o.u(0x77553355, 0x44332222),
5060 // o.u(0x4d6bbd6, 0xbfbbd2d2), o.u(0x39907090, 0x4970a9a9),
5061 // o.u(0x87808980, 0xe890707), o.u(0xc1f2a7f2, 0x66a73333),
5062 // o.u(0xecc1b6c1, 0x5ab62d2d), o.u(0x5a662266, 0x78223c3c),
5063 // o.u(0xb8ad92ad, 0x2a921515), o.u(0xa9602060, 0x8920c9c9),
5064 // o.u(0x5cdb49db, 0x15498787), o.u(0xb01aff1a, 0x4fffaaaa),
5065 // o.u(0xd8887888, 0xa0785050), o.u(0x2b8e7a8e, 0x517aa5a5),
5066 // o.u(0x898a8f8a, 0x68f0303), o.u(0x4a13f813, 0xb2f85959),
5067 // o.u(0x929b809b, 0x12800909), o.u(0x23391739, 0x34171a1a),
5068 // o.u(0x1075da75, 0xcada6565), o.u(0x84533153, 0xb531d7d7),
5069 // o.u(0xd551c651, 0x13c68484), o.u(0x3d3b8d3, 0xbbb8d0d0),
5070 // o.u(0xdc5ec35e, 0x1fc38282), o.u(0xe2cbb0cb, 0x52b02929),
5071 // o.u(0xc3997799, 0xb4775a5a), o.u(0x2d331133, 0x3c111e1e),
5072 // o.u(0x3d46cb46, 0xf6cb7b7b), o.u(0xb71ffc1f, 0x4bfca8a8),
5073 // o.u(0xc61d661, 0xdad66d6d), o.u(0x624e3a4e, 0x583a2c2c)
5074 // ];
5075
5076 var B64 = function(n, x) {
5077 if (n === 7) {
5078 return x.lo & 0xFF;
5079 }
5080 var bits = (7 - n) * 8;
5081 if (bits >= 32) { //faster than >= 32
5082 return (x.hi >>> (bits - 32)) & 0xFF;
5083 }
5084 else {
5085 var bitsOff32 = 32 - bits,
5086 toMoveDown = this.hi << bitsOff32 >>> bitsOff32;
5087 return (x.lo >>> bits | (toMoveDown << bitsOff32)) & 0xFF;
5088 }
5089 }
5090
5091 var j64 = [o.u(0, 0), o.u(0, 0x10), o.u(0, 0x20), o.u(0, 0x30), o.u(0, 0x40), o.u(0, 0x50), o.u(0, 0x60),
5092 o.u(0, 0x70), o.u(0, 0x80), o.u(0, 0x90), o.u(0, 0xA0), o.u(0, 0xB0), o.u(0, 0xC0),
5093 o.u(0, 0xD0), o.u(0, 0xE0), o.u(0, 0xF0)
5094 ];
5095
5096 var nj64 = [o.u(0xFFFFFFFF, 0xFFFFFFFF), o.u(0xFFFFFFFF, 0xFFFFFFEF), o.u(0xFFFFFFFF, 0xFFFFFFDF), o.u(0xFFFFFFFF, 0xFFFFFFCF), o.u(0xFFFFFFFF, 0xFFFFFFBF), o.u(0xFFFFFFFF, 0xFFFFFFAF), o.u(0xFFFFFFFF, 0xFFFFFF9F),
5097 o.u(0xFFFFFFFF, 0xFFFFFF8F), o.u(0xFFFFFFFF, 0xFFFFFF7F), o.u(0xFFFFFFFF, 0xFFFFFF6F), o.u(0xFFFFFFFF, 0xFFFFFF5F), o.u(0xFFFFFFFF, 0xFFFFFF4F), o.u(0xFFFFFFFF, 0xFFFFFF3F),
5098 o.u(0xFFFFFFFF, 0xFFFFFF2F), o.u(0xFFFFFFFF, 0xFFFFFF1F), o.u(0xFFFFFFFF, 0xFFFFFF0F)
5099 ];
5100
5101 var r64 = [o.u(0, 0), o.u(0, 1), o.u(0, 2), o.u(0, 3), o.u(0, 4), o.u(0, 5), o.u(0, 6), o.u(0, 7),
5102 o.u(0, 8), o.u(0, 9), o.u(0, 10), o.u(0, 11), o.u(0, 12), o.u(0, 13)
5103 ];
5104
5105 var compress = function(int64buf, state) {
5106 var g = new Array(16);
5107 var m = new Array(16);
5108 for (var u = 0; u < 16; u++) {
5109 m[u] = int64buf[u];
5110 g[u] = m[u].xor(state[u]);
5111 }
5112 var t = new Array(16);
5113 for (var r = 0; r < 14; r++) {
5114 for (var i = 0; i < 16; i++) {
5115 g[i].setxor64(j64[i].plus(r64[r]).setShiftLeft(56));
5116 }
5117
5118 for (var u = 0; u < 16; u++) {
5119 t[u] = o.xor64(T0[B64(0, g[u])], T1[B64(1, g[(u + 1) & 0xF])], T2[B64(2, g[(u + 2) & 0xF])], T3[B64(3, g[(u + 3) & 0xF])], T4[B64(4, g[(u + 4) & 0xF])], T5[B64(5, g[(u + 5) & 0xF])], T6[B64(6, g[(u + 6) & 0xF])], T7[B64(7, g[(u + 11) & 0xF])]);
5120 }
5121 var temp = g;
5122 g = t;
5123 t = temp;
5124 }
5125 for (var r = 0; r < 14; r++) {
5126 for (var i = 0; i < 16; i++) {
5127 m[i].setxor64(r64[r], nj64[i]);
5128 }
5129 for (var u = 0; u < 16; u++) {
5130 t[u] = o.xor64(T0[B64(0, m[(u + 1) & 0xF])], T1[B64(1, m[(u + 3) & 0xF])], T2[B64(2, m[(u + 5) & 0xF])], T3[B64(3, m[(u + 11) & 0xF])], T4[B64(4, m[(u + 0) & 0xF])], T5[B64(5, m[(u + 2) & 0xF])], T6[B64(6, m[(u + 4) & 0xF])], T7[B64(7, m[(u + 6) & 0xF])]);
5131 }
5132 var temp = m;
5133 m = t;
5134 t = temp;
5135 }
5136 for (var u = 0; u < 16; u++) {
5137 state[u].setxor64(g[u], m[u]);
5138 }
5139 }
5140
5141 var final = function(state) {
5142 var g = new Array(16);
5143 o.bufferInsert64(g, 0, state, 16);
5144 var t = new Array(16);
5145 for (var r = 0; r < 14; r++) {
5146
5147 for (var i = 0; i < 16; i++) {
5148 g[i].setxor64(j64[i].plus(r64[r]).setShiftLeft(56));
5149 }
5150
5151 for (var u = 0; u < 16; u++) {
5152 t[u] = o.xor64(T0[B64(0, g[u])], T1[B64(1, g[(u + 1) & 0xF])], T2[B64(2, g[(u + 2) & 0xF])], T3[B64(3, g[(u + 3) & 0xF])], T4[B64(4, g[(u + 4) & 0xF])], T5[B64(5, g[(u + 5) & 0xF])], T6[B64(6, g[(u + 6) & 0xF])], T7[B64(7, g[(u + 11) & 0xF])]);
5153 }
5154 var temp = g;
5155 g = t;
5156 t = temp;
5157 }
5158 for (var u = 0; u < 16; u++)
5159 state[u].setxor64(g[u]);
5160 }
5161
5162 var groestl = function(ctx, data, len) {
5163 var buf, ptr;
5164 //create a local copy of states
5165 var V = new Array(16);
5166 buf = ctx.buffer;
5167 ptr = ctx.ptr;
5168 if (len < ctx.buffer.length - ptr) {
5169 o.bufferInsert(buf, ptr, data, data.length);
5170 ptr += data.length;
5171 ctx.ptr = ptr;
5172 return;
5173 }
5174 //perform a deep copy of current state
5175 o.bufferInsert(V, 0, ctx.state, 16);
5176 while (len > 0) {
5177 var clen = ctx.buffer.length - ptr;
5178 if (clen > len) clen = len;
5179 o.bufferInsert(buf, ptr, data, clen);
5180 ptr += clen;
5181 data = data.slice(clen);
5182 len -= clen;
5183 if (ptr === ctx.buffer.length) {
5184 var int64Buf = h.bytes2Int64Buffer(buf);
5185 compress(int64Buf, V);
5186 ctx.count.addOne();
5187 ptr = 0;
5188 }
5189 }
5190 ctx.state = V;
5191 ctx.ptr = ptr;
5192 }
5193
5194 var groestlClose = function(ctx) {
5195 var buf = ctx.buffer;
5196 var ptr = ctx.ptr;
5197 var pad = new Array(136);
5198 var len = buf.length;
5199 var padLen;
5200 var count;
5201 pad[0] = 0x80;
5202 if (ptr < 120) {
5203 padLen = 128 - ptr;
5204 count = ctx.count.plus(o.u(0, 1));
5205 }
5206 else {
5207 padLen = 256 - ptr;
5208 count = ctx.count.plus(o.u(0, 2));
5209 }
5210 o.bufferSet(pad, 1, 0, padLen - 9);
5211 h.bufferEncode64(pad, padLen - 8, count);
5212 groestl(ctx, pad, padLen);
5213 final(ctx.state);
5214 var out = new Array(16);
5215 for (var u = 0, v = 8; u < 8; u++, v++) {
5216 out[2 * u] = ctx.state[v].hi;
5217 out[2 * u + 1] = ctx.state[v].lo;
5218 }
5219 return out;
5220 }
5221
5222 module.exports = function(input, format, output) {
5223 var msg;
5224 if (format === 1) {
5225 msg = input;
5226 }
5227 else if (format === 2) {
5228 msg = h.int32Buffer2Bytes(input);
5229 }
5230 else {
5231 msg = h.string2bytes(input);
5232 }
5233 var ctx = {};
5234 ctx.state = new Array(16);
5235 for (var i = 0; i < 15; i++) {
5236 ctx.state[i] = new o.u64(0, 0);
5237 }
5238 ctx.state[15] = new o.u64(0, 512);
5239 ctx.ptr = 0;
5240 ctx.count = new o.u64(0,0);
5241 ctx.buffer = new Array(128);
5242 groestl(ctx, msg, msg.length);
5243 var r = groestlClose(ctx, 0, 0);
5244 var out;
5245 if (output === 2) {
5246 out = r;
5247 }
5248 else if (output === 1) {
5249 out = h.int32Buffer2Bytes(r)
5250 }
5251 else {
5252 out = h.int32ArrayToHexString(r)
5253 }
5254 return out;
5255 }
5256 },{"./helper":41,"./op":42}],41:[function(require,module,exports){
5257 'use strict';
5258 // String functions
5259
5260 var op = require('./op.js');
5261
5262 module.exports.int8ArrayToHexString = function toString(array) {
5263 var string = '';
5264
5265 for (var i = 0; i < array.length; i++) {
5266 if (array[i] < 16) {
5267 string += '0' + array[i].toString(16);
5268 }
5269 else {
5270 string += array[i].toString(16);
5271 }
5272 }
5273 return string;
5274 }
5275
5276 module.exports.int32ArrayToHexString = function toString(array) {
5277 var string = '';
5278 var len = array.length;
5279 for (var i = 0; i < len; i++) {
5280 var s = array[i];
5281 if (s < 0) {
5282 s = 0xFFFFFFFF + array[i] + 1;
5283 }
5284 var l = s.toString(16);
5285 var padding = 8;
5286 while (l.length < padding) {
5287 l = "0" + l;
5288 }
5289 string += l;
5290 }
5291 return string;
5292 }
5293
5294 module.exports.hex2string = function toString(s) {
5295 for (var c = [], len = s.length, i = 0; i < len; i += 2)
5296 c.push(String.fromCharCode(parseInt(s.substring(i, i + 2), 16)));
5297 return c.join('');
5298 }
5299
5300 module.exports.hex2bytes = function toString(s) {
5301 for (var c = [], len = s.length, i = 0; i < len; i += 2)
5302 c.push(parseInt(s.substring(i, i + 2), 16));
5303 return c;
5304 }
5305 /*
5306 module.exports.string2hex = function toString(s) {
5307
5308 for (var p = [], len = s.length, i = 0; i < len; i++) {
5309 p.push((256 + s.charCodeAt(i)).toString(16).substring(1));
5310 }
5311 return p.join('');
5312 }
5313 */
5314 module.exports.string2bytes = function(s) {
5315 var len = s.length;
5316 var b = new Array(len);
5317 var i = 0;
5318 while (i < len) {
5319 b[i] = s.charCodeAt(i);
5320 i++;
5321 }
5322 return b;
5323 }
5324 /*
5325 module.exports.bytes2Int16Buffer = function(b) {
5326 var len = b.length;
5327 var bufferLength = len ? (((len - 1) >>> 1) + 1) : 0;
5328 var buffer = new Array(bufferLength);
5329 var i = 0;
5330 var j = 0;
5331 while (i < len) {
5332 buffer[j] = (buffer[j] << 8) | b[i];
5333 i++;
5334 if (!(i % 2)) j++;
5335 }
5336 return buffer;
5337 }
5338 */
5339
5340 module.exports.bytes2Int32Buffer = function(b) {
5341 if (!b) return [];
5342 var len = b.length ? (((b.length - 1) >>> 2) + 1) : 0;
5343 var buffer = new Array(len);
5344 var j = 0;
5345 while (j < len) {
5346 buffer[j] = (b[j * 4] << 24) | (b[j * 4 + 1] << 16) | (b[j * 4 + 2] << 8) | b[j * 4 + 3];
5347 j++;
5348 }
5349 return buffer;
5350 }
5351 /*
5352 module.exports.bytes2Int32BufferLeAligned = function(b) {
5353 var len = b.length;
5354 if (!len) return [];
5355 var len2 = len ? (((len - 1) >>> 2) + 1) : 0;
5356 var buffer = new Array(len);
5357 var j = 0;
5358 while (j < len2) {
5359 buffer[j] = (b[j * 4 + 3] << 24) | (b[j * 4 + 2] << 16) | (b[j * 4 + 1] << 8) | b[j * 4];
5360 j++;
5361 };
5362 return buffer;
5363 }
5364 */
5365 module.exports.bytes2Int64Buffer = function(b) {
5366 if (!b) return [];
5367 var len = b.length ? (((b.length - 1) >>> 3) + 1) : 0;
5368 var buffer = new Array(len);
5369 var j = 0;
5370 while (j < len) {
5371 buffer[j] = new op.u64((b[j * 8] << 24) | (b[j * 8 + 1] << 16) | (b[j * 8 + 2] << 8) | b[j * 8 + 3], (b[j * 8 + 4] << 24) | (b[j * 8 + 5] << 16) | (b[j * 8 + 6] << 8) | b[j * 8 + 7]);
5372 j++;
5373 }
5374 return buffer;
5375 }
5376
5377 module.exports.bytes2Int64BufferLeAligned = function(b) {
5378 if (!b) return [];
5379 var len = b.length ? ((( b.length - 1) >>> 3) + 1) : 0;
5380 var buffer = new Array(len);
5381 var j = 0;
5382 while (j < len) {
5383 buffer[j] = new op.u64((b[j * 8 + 7] << 24) | (b[j * 8 + 6] << 16) | (b[j * 8 + 5] << 8) | b[j * 8 + 4], (b[j * 8 + 3] << 24) | (b[j * 8 + 2] << 16) | (b[j * 8 + 1] << 8) | b[j * 8]);
5384 j++;
5385 }
5386 return buffer;
5387 }
5388
5389 module.exports.bufferEncode64leAligned = function(buffer, offset, uint64) {
5390 buffer[offset + 7] = uint64.hi >>> 24;
5391 buffer[offset + 6] = uint64.hi >>> 16 & 0xFF;
5392 buffer[offset + 5] = uint64.hi >>> 8 & 0xFF;
5393 buffer[offset + 4] = uint64.hi & 0xFF;
5394 buffer[offset + 3] = uint64.lo >>> 24;
5395 buffer[offset + 2] = uint64.lo >>> 16 & 0xFF;
5396 buffer[offset + 1] = uint64.lo >>> 8 & 0xFF;
5397 buffer[offset + 0] = uint64.lo & 0xFF;
5398 }
5399
5400 module.exports.bufferEncode64 = function(buffer, offset, uint64) {
5401 buffer[offset] = uint64.hi >>> 24;
5402 buffer[offset + 1] = uint64.hi >>> 16 & 0xFF;
5403 buffer[offset + 2] = uint64.hi >>> 8 & 0xFF;
5404 buffer[offset + 3] = uint64.hi & 0xFF;
5405 buffer[offset + 4] = uint64.lo >>> 24;
5406 buffer[offset + 5] = uint64.lo >>> 16 & 0xFF;
5407 buffer[offset + 6] = uint64.lo >>> 8 & 0xFF;
5408 buffer[offset + 7] = uint64.lo & 0xFF;
5409 }
5410
5411 module.exports.int32Buffer2Bytes = function(b) {
5412 var buffer = new Array(b.length);
5413 var len = b.length;
5414 var i = 0;
5415 while (i < len) {
5416 buffer[i * 4] = (b[i] & 0xFF000000) >>> 24;
5417 buffer[i * 4 + 1] = (b[i] & 0x00FF0000) >>> 16;
5418 buffer[i * 4 + 2] = (b[i] & 0x0000FF00) >>> 8;
5419 buffer[i * 4 + 3] = (b[i] & 0x000000FF);
5420 i++;
5421 }
5422 return buffer;
5423 }
5424 /*
5425 module.exports.int64Buffer2Bytes = function(b) {
5426 var buffer = new Array(b.length);
5427 var i = 0;
5428 while (i < b.length) {
5429 buffer[i * 8] = (b[i].hi & 0xFF000000) >>> 24;
5430 buffer[i * 8 + 1] = (b[i].hi & 0x00FF0000) >>> 16;
5431 buffer[i * 8 + 2] = (b[i].hi & 0x0000FF00) >>> 8;
5432 buffer[i * 8 + 3] = (b[i].hi & 0x000000FF);
5433 buffer[i * 8 + 4] = (b[i].lo & 0xFF000000) >>> 24;
5434 buffer[i * 8 + 5] = (b[i].lo & 0x00FF0000) >>> 16;
5435 buffer[i * 8 + 6] = (b[i].lo & 0x0000FF00) >>> 8;
5436 buffer[i * 8 + 7] = (b[i].lo & 0x000000FF);
5437 i++;
5438 }
5439 return buffer;
5440 }
5441 */
5442
5443 module.exports.string2Int32Buffer = function(s) {
5444 return this.bytes2Int32Buffer(this.string2bytes(s));
5445 }
5446
5447 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
5448
5449 module.exports.b64Encode = function(input) {
5450 var output = "";
5451 var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
5452 var i = 0;
5453
5454 while (i < input.length) {
5455
5456 chr1 = input[i++];
5457 chr2 = input[i++];
5458 chr3 = input[i++];
5459
5460 enc1 = chr1 >> 2;
5461 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
5462 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
5463 enc4 = chr3 & 63;
5464
5465 if (isNaN(chr2)) {
5466 enc3 = enc4 = 64;
5467 }
5468 else if (isNaN(chr3)) {
5469 enc4 = 64;
5470 }
5471
5472 output +=
5473 keyStr.charAt(enc1) + keyStr.charAt(enc2) +
5474 keyStr.charAt(enc3) + keyStr.charAt(enc4);
5475 }
5476
5477 return output;
5478 };
5479
5480 module.exports.b64Decode = function(input) {
5481 var output = [];
5482 var chr1, chr2, chr3;
5483 var enc1, enc2, enc3, enc4;
5484 var i = 0;
5485
5486 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
5487
5488 while (i < input.length) {
5489
5490 enc1 = keyStr.indexOf(input.charAt(i++));
5491 enc2 = keyStr.indexOf(input.charAt(i++));
5492 enc3 = keyStr.indexOf(input.charAt(i++));
5493 enc4 = keyStr.indexOf(input.charAt(i++));
5494
5495 chr1 = (enc1 << 2) | (enc2 >> 4);
5496 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
5497 chr3 = ((enc3 & 3) << 6) | enc4;
5498
5499 output.push(chr1);
5500
5501 if (enc3 != 64) {
5502 output.push(chr2);
5503 }
5504 if (enc4 != 64) {
5505 output.push(chr3);
5506 }
5507 }
5508 return output;
5509 };
5510 },{"./op.js":42}],42:[function(require,module,exports){
5511 'use strict';
5512 //the right shift is important, it has to do with 32 bit operations in javascript, it will make things faster
5513 function u64(h, l) {
5514 this.hi = h >>> 0;
5515 this.lo = l >>> 0;
5516 }
5517
5518 u64.prototype.set = function(oWord) {
5519 this.lo = oWord.lo;
5520 this.hi = oWord.hi;
5521 }
5522
5523 u64.prototype.add = function(oWord) {
5524 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5525
5526 //need to add the respective parts from each number and the carry if on is present..
5527 lowest = (this.lo & 0XFFFF) + (oWord.lo & 0XFFFF);
5528 lowMid = (this.lo >>> 16) + (oWord.lo >>> 16) + (lowest >>> 16);
5529 highMid = (this.hi & 0XFFFF) + (oWord.hi & 0XFFFF) + (lowMid >>> 16);
5530 highest = (this.hi >>> 16) + (oWord.hi >>> 16) + (highMid >>> 16);
5531
5532 //now set the hgih and the low accordingly..
5533 this.lo = (lowMid << 16) | (lowest & 0XFFFF);
5534 this.hi = (highest << 16) | (highMid & 0XFFFF);
5535
5536 return this; //for chaining..
5537 };
5538
5539 u64.prototype.addOne = function() {
5540 if (this.lo === -1 || this.lo === 0xFFFFFFFF) {
5541 this.lo = 0;
5542 this.hi++;
5543 }
5544 else {
5545 this.lo++;
5546 }
5547 }
5548
5549 u64.prototype.plus = function(oWord) {
5550 var c = new u64(0, 0);
5551 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5552
5553 //need to add the respective parts from each number and the carry if on is present..
5554 lowest = (this.lo & 0XFFFF) + (oWord.lo & 0XFFFF);
5555 lowMid = (this.lo >>> 16) + (oWord.lo >>> 16) + (lowest >>> 16);
5556 highMid = (this.hi & 0XFFFF) + (oWord.hi & 0XFFFF) + (lowMid >>> 16);
5557 highest = (this.hi >>> 16) + (oWord.hi >>> 16) + (highMid >>> 16);
5558
5559 //now set the hgih and the low accordingly..
5560 c.lo = (lowMid << 16) | (lowest & 0XFFFF);
5561 c.hi = (highest << 16) | (highMid & 0XFFFF);
5562
5563 return c; //for chaining..
5564 };
5565
5566 u64.prototype.not = function() {
5567 return new u64(~this.hi, ~this.lo);
5568 }
5569
5570 u64.prototype.one = function() {
5571 return new u64(0x0, 0x1);
5572 }
5573
5574 u64.prototype.zero = function() {
5575 return new u64(0x0, 0x0);
5576 }
5577
5578 u64.prototype.neg = function() {
5579 return this.not().plus(this.one());
5580 }
5581
5582 u64.prototype.minus = function(oWord) {
5583 return this.plus(oWord.neg());
5584 };
5585
5586 u64.prototype.isZero = function() {
5587 return (this.lo === 0) && (this.hi === 0);
5588 }
5589
5590 function isLong(obj) {
5591 return (obj && obj["__isLong__"]) === true;
5592 }
5593
5594 function fromNumber(value) {
5595 if (isNaN(value) || !isFinite(value))
5596 return this.zero();
5597 var pow32 = (1 << 32);
5598 return new u64((value % pow32) | 0, (value / pow32) | 0);
5599 }
5600
5601 u64.prototype.multiply = function(multiplier) {
5602 if (this.isZero())
5603 return this.zero();
5604 if (!isLong(multiplier))
5605 multiplier = fromNumber(multiplier);
5606 if (multiplier.isZero())
5607 return this.zero();
5608
5609 // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
5610 // We can skip products that would overflow.
5611
5612 var a48 = this.hi >>> 16;
5613 var a32 = this.hi & 0xFFFF;
5614 var a16 = this.lo >>> 16;
5615 var a00 = this.lo & 0xFFFF;
5616
5617 var b48 = multiplier.hi >>> 16;
5618 var b32 = multiplier.hi & 0xFFFF;
5619 var b16 = multiplier.lo >>> 16;
5620 var b00 = multiplier.lo & 0xFFFF;
5621
5622 var c48 = 0,
5623 c32 = 0,
5624 c16 = 0,
5625 c00 = 0;
5626 c00 += a00 * b00;
5627 c16 += c00 >>> 16;
5628 c00 &= 0xFFFF;
5629 c16 += a16 * b00;
5630 c32 += c16 >>> 16;
5631 c16 &= 0xFFFF;
5632 c16 += a00 * b16;
5633 c32 += c16 >>> 16;
5634 c16 &= 0xFFFF;
5635 c32 += a32 * b00;
5636 c48 += c32 >>> 16;
5637 c32 &= 0xFFFF;
5638 c32 += a16 * b16;
5639 c48 += c32 >>> 16;
5640 c32 &= 0xFFFF;
5641 c32 += a00 * b32;
5642 c48 += c32 >>> 16;
5643 c32 &= 0xFFFF;
5644 c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
5645 c48 &= 0xFFFF;
5646 return new u64((c48 << 16) | c32, (c16 << 16) | c00);
5647 };
5648
5649 u64.prototype.shiftLeft = function(bits) {
5650 bits = bits % 64;
5651 var c = new u64(0, 0);
5652 if (bits === 0) {
5653 return this.clone();
5654 }
5655 else if (bits > 31) {
5656 c.lo = 0;
5657 c.hi = this.lo << (bits - 32);
5658 }
5659 else {
5660 var toMoveUp = this.lo >>> 32 - bits;
5661 c.lo = this.lo << bits;
5662 c.hi = (this.hi << bits) | toMoveUp;
5663 }
5664 return c; //for chaining..
5665 };
5666
5667 u64.prototype.setShiftLeft = function(bits) {
5668 if (bits === 0) {
5669 return this;
5670 }
5671 if (bits > 63) {
5672 bits = bits % 64;
5673 }
5674
5675 if (bits > 31) {
5676 this.hi = this.lo << (bits - 32);
5677 this.lo = 0;
5678 }
5679 else {
5680 var toMoveUp = this.lo >>> 32 - bits;
5681 this.lo <<= bits;
5682 this.hi = (this.hi << bits) | toMoveUp;
5683 }
5684 return this; //for chaining..
5685 };
5686 //Shifts this word by the given number of bits to the right (max 32)..
5687 u64.prototype.shiftRight = function(bits) {
5688 bits = bits % 64;
5689 var c = new u64(0, 0);
5690 if (bits === 0) {
5691 return this.clone();
5692 }
5693 else if (bits >= 32) {
5694 c.hi = 0;
5695 c.lo = this.hi >>> (bits - 32);
5696 }
5697 else {
5698 var bitsOff32 = 32 - bits,
5699 toMoveDown = this.hi << bitsOff32 >>> bitsOff32;
5700 c.hi = this.hi >>> bits;
5701 c.lo = this.lo >>> bits | (toMoveDown << bitsOff32);
5702 }
5703 return c; //for chaining..
5704 };
5705 //Rotates the bits of this word round to the left (max 32)..
5706 u64.prototype.rotateLeft = function(bits) {
5707 if (bits > 32) {
5708 return this.rotateRight(64 - bits);
5709 }
5710 var c = new u64(0, 0);
5711 if (bits === 0) {
5712 c.lo = this.lo >>> 0;
5713 c.hi = this.hi >>> 0;
5714 }
5715 else if (bits === 32) { //just switch high and low over in this case..
5716 c.lo = this.hi;
5717 c.hi = this.lo;
5718 }
5719 else {
5720 c.lo = (this.lo << bits) | (this.hi >>> (32 - bits));
5721 c.hi = (this.hi << bits) | (this.lo >>> (32 - bits));
5722 }
5723 return c; //for chaining..
5724 };
5725
5726 u64.prototype.setRotateLeft = function(bits) {
5727 if (bits > 32) {
5728 return this.setRotateRight(64 - bits);
5729 }
5730 var newHigh;
5731 if (bits === 0) {
5732 return this;
5733 }
5734 else if (bits === 32) { //just switch high and low over in this case..
5735 newHigh = this.lo;
5736 this.lo = this.hi;
5737 this.hi = newHigh;
5738 }
5739 else {
5740 newHigh = (this.hi << bits) | (this.lo >>> (32 - bits));
5741 this.lo = (this.lo << bits) | (this.hi >>> (32 - bits));
5742 this.hi = newHigh;
5743 }
5744 return this; //for chaining..
5745 };
5746 //Rotates the bits of this word round to the right (max 32)..
5747 u64.prototype.rotateRight = function(bits) {
5748 if (bits > 32) {
5749 return this.rotateLeft(64 - bits);
5750 }
5751 var c = new u64(0, 0);
5752 if (bits === 0) {
5753 c.lo = this.lo >>> 0;
5754 c.hi = this.hi >>> 0;
5755 }
5756 else if (bits === 32) { //just switch high and low over in this case..
5757 c.lo = this.hi;
5758 c.hi = this.lo;
5759 }
5760 else {
5761 c.lo = (this.hi << (32 - bits)) | (this.lo >>> bits);
5762 c.hi = (this.lo << (32 - bits)) | (this.hi >>> bits);
5763 }
5764 return c; //for chaining..
5765 };
5766 u64.prototype.setFlip = function() {
5767 var newHigh;
5768 newHigh = this.lo;
5769 this.lo = this.hi;
5770 this.hi = newHigh;
5771 return this;
5772 };
5773 //Rotates the bits of this word round to the right (max 32)..
5774 u64.prototype.setRotateRight = function(bits) {
5775 if (bits > 32) {
5776 return this.setRotateLeft(64 - bits);
5777 }
5778
5779 if (bits === 0) {
5780 return this;
5781 }
5782 else if (bits === 32) { //just switch high and low over in this case..
5783 var newHigh;
5784 newHigh = this.lo;
5785 this.lo = this.hi;
5786 this.hi = newHigh;
5787 }
5788 else {
5789 newHigh = (this.lo << (32 - bits)) | (this.hi >>> bits);
5790 this.lo = (this.hi << (32 - bits)) | (this.lo >>> bits);
5791 this.hi = newHigh;
5792 }
5793 return this; //for chaining..
5794 };
5795 //Xors this word with the given other..
5796 u64.prototype.xor = function(oWord) {
5797 var c = new u64(0, 0);
5798 c.hi = this.hi ^ oWord.hi;
5799 c.lo = this.lo ^ oWord.lo;
5800 return c; //for chaining..
5801 };
5802 //Xors this word with the given other..
5803 u64.prototype.setxorOne = function(oWord) {
5804 this.hi ^= oWord.hi;
5805 this.lo ^= oWord.lo;
5806 return this; //for chaining..
5807 };
5808 //Ands this word with the given other..
5809 u64.prototype.and = function(oWord) {
5810 var c = new u64(0, 0);
5811 c.hi = this.hi & oWord.hi;
5812 c.lo = this.lo & oWord.lo;
5813 return c; //for chaining..
5814 };
5815
5816 //Creates a deep copy of this Word..
5817 u64.prototype.clone = function() {
5818 return new u64(this.hi, this.lo);
5819 };
5820
5821 u64.prototype.setxor64 = function() {
5822 var a = arguments;
5823 var i = a.length;
5824 while (i--) {
5825 this.hi ^= a[i].hi;
5826 this.lo ^= a[i].lo;
5827 }
5828 return this;
5829 }
5830
5831 module.exports.u64 = u64;
5832
5833 module.exports.u = function(h, l) {
5834 return new u64(h, l);
5835 }
5836 /*
5837 module.exports.add64 = function(a, b) {
5838 var lowest, lowMid, highMid, highest; //four parts of the whole 64 bit number..
5839
5840 //need to add the respective parts from each number and the carry if on is present..
5841 lowest = (a.lo & 0XFFFF) + (b.lo & 0XFFFF);
5842 lowMid = (a.lo >>> 16) + (b.lo >>> 16) + (lowest >>> 16);
5843 highMid = (a.hi & 0XFFFF) + (b.hi & 0XFFFF) + (lowMid >>> 16);
5844 highest = (a.hi >>> 16) + (b.hi >>> 16) + (highMid >>> 16);
5845
5846 var r = new this.u64((highest << 16) | (highMid & 0XFFFF), (lowMid << 16) | (lowest & 0XFFFF));
5847
5848 return r;
5849 };
5850 */
5851 module.exports.xor64 = function() {
5852 var a = arguments,
5853 h = a[0].hi,
5854 l = a[0].lo;
5855 var i = a.length-1;
5856 do {
5857 h ^= a[i].hi;
5858 l ^= a[i].lo;
5859 i--;
5860 } while (i>0);
5861 return new this.u64(h, l);
5862 }
5863
5864 module.exports.clone64Array = function(array) {
5865 var i = 0;
5866 var len = array.length;
5867 var a = new Array(len);
5868 while(i<len) {
5869 a[i] = array[i];
5870 i++;
5871 }
5872 return a;
5873 }
5874
5875 //this shouldn't be a problem, but who knows in the future javascript might support 64bits
5876 module.exports.t32 = function(x) {
5877 return (x & 0xFFFFFFFF)
5878 }
5879
5880 module.exports.rotl32 = function(x, c) {
5881 return (((x) << (c)) | ((x) >>> (32 - (c)))) & (0xFFFFFFFF);
5882 }
5883
5884 module.exports.rotr32 = function(x, c) {
5885 return this.rotl32(x, (32 - (c)));
5886 }
5887
5888 module.exports.swap32 = function(val) {
5889 return ((val & 0xFF) << 24) |
5890 ((val & 0xFF00) << 8) |
5891 ((val >>> 8) & 0xFF00) |
5892 ((val >>> 24) & 0xFF);
5893 }
5894
5895 module.exports.swap32Array = function(a) {
5896 //can't do this with map because of support for IE8 (Don't hate me plz).
5897 var i = 0, len = a.length;
5898 var r = new Array(i);
5899 while (i<len) {
5900 r[i] = (this.swap32(a[i]));
5901 i++;
5902 }
5903 return r;
5904 }
5905
5906 module.exports.xnd64 = function(x, y, z) {
5907 return new this.u64(x.hi ^ ((~y.hi) & z.hi), x.lo ^ ((~y.lo) & z.lo));
5908 }
5909 /*
5910 module.exports.load64 = function(x, i) {
5911 var l = x[i] | (x[i + 1] << 8) | (x[i + 2] << 16) | (x[i + 3] << 24);
5912 var h = x[i + 4] | (x[i + 5] << 8) | (x[i + 6] << 16) | (x[i + 7] << 24);
5913 return new this.u64(h, l);
5914 }
5915 */
5916 module.exports.bufferInsert = function(buffer, bufferOffset, data, len, dataOffset) {
5917 dataOffset = dataOffset | 0;
5918 var i = 0;
5919 while (i < len) {
5920 buffer[i + bufferOffset] = data[i + dataOffset];
5921 i++;
5922 }
5923 }
5924
5925 module.exports.bufferInsert64 = function(buffer, bufferOffset, data, len) {
5926 var i = 0;
5927 while (i < len) {
5928 buffer[i + bufferOffset] = data[i].clone();
5929 i++;
5930 }
5931 }
5932 /*
5933 module.exports.buffer2Insert = function(buffer, bufferOffset, bufferOffset2, data, len, len2) {
5934 while (len--) {
5935 var j = len2;
5936 while (j--) {
5937 buffer[len + bufferOffset][j + bufferOffset2] = data[len][j];
5938 }
5939 }
5940 }
5941 */
5942 module.exports.bufferInsertBackwards = function(buffer, bufferOffset, data, len) {
5943 var i = 0;
5944 while (i < len) {
5945 buffer[i + bufferOffset] = data[len - 1 - i];
5946 i++;
5947 }
5948 }
5949
5950 module.exports.bufferSet = function(buffer, bufferOffset, value, len) {
5951 var i = 0;
5952 while (i < len) {
5953 buffer[i + bufferOffset] = value;
5954 i++;
5955 }
5956 }
5957
5958 module.exports.bufferXORInsert = function(buffer, bufferOffset, data, dataOffset, len) {
5959 var i = 0;
5960 while (i < len) {
5961 buffer[i + bufferOffset] ^= data[i + dataOffset];
5962 i++;
5963 }
5964 }
5965
5966 module.exports.xORTable = function(d, s1, s2, len) {
5967 var i = 0;
5968 while (i < len) {
5969 d[i] = s1[i] ^ s2[i];
5970 i++
5971 }
5972 }
5973
5974 },{}],43:[function(require,module,exports){
5975 'use strict'
5976 var Buffer = require('safe-buffer').Buffer
5977 var Transform = require('stream').Transform
5978 var inherits = require('inherits')
5979
5980 function throwIfNotStringOrBuffer (val, prefix) {
5981 if (!Buffer.isBuffer(val) && typeof val !== 'string') {
5982 throw new TypeError(prefix + ' must be a string or a buffer')
5983 }
5984 }
5985
5986 function HashBase (blockSize) {
5987 Transform.call(this)
5988
5989 this._block = Buffer.allocUnsafe(blockSize)
5990 this._blockSize = blockSize
5991 this._blockOffset = 0
5992 this._length = [0, 0, 0, 0]
5993
5994 this._finalized = false
5995 }
5996
5997 inherits(HashBase, Transform)
5998
5999 HashBase.prototype._transform = function (chunk, encoding, callback) {
6000 var error = null
6001 try {
6002 this.update(chunk, encoding)
6003 } catch (err) {
6004 error = err
6005 }
6006
6007 callback(error)
6008 }
6009
6010 HashBase.prototype._flush = function (callback) {
6011 var error = null
6012 try {
6013 this.push(this.digest())
6014 } catch (err) {
6015 error = err
6016 }
6017
6018 callback(error)
6019 }
6020
6021 HashBase.prototype.update = function (data, encoding) {
6022 throwIfNotStringOrBuffer(data, 'Data')
6023 if (this._finalized) throw new Error('Digest already called')
6024 if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
6025
6026 // consume data
6027 var block = this._block
6028 var offset = 0
6029 while (this._blockOffset + data.length - offset >= this._blockSize) {
6030 for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
6031 this._update()
6032 this._blockOffset = 0
6033 }
6034 while (offset < data.length) block[this._blockOffset++] = data[offset++]
6035
6036 // update length
6037 for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
6038 this._length[j] += carry
6039 carry = (this._length[j] / 0x0100000000) | 0
6040 if (carry > 0) this._length[j] -= 0x0100000000 * carry
6041 }
6042
6043 return this
6044 }
6045
6046 HashBase.prototype._update = function () {
6047 throw new Error('_update is not implemented')
6048 }
6049
6050 HashBase.prototype.digest = function (encoding) {
6051 if (this._finalized) throw new Error('Digest already called')
6052 this._finalized = true
6053
6054 var digest = this._digest()
6055 if (encoding !== undefined) digest = digest.toString(encoding)
6056
6057 // reset state
6058 this._block.fill(0)
6059 this._blockOffset = 0
6060 for (var i = 0; i < 4; ++i) this._length[i] = 0
6061
6062 return digest
6063 }
6064
6065 HashBase.prototype._digest = function () {
6066 throw new Error('_digest is not implemented')
6067 }
6068
6069 module.exports = HashBase
6070
6071 },{"inherits":44,"safe-buffer":47,"stream":215}],44:[function(require,module,exports){
6072 if (typeof Object.create === 'function') {
6073 // implementation from standard node.js 'util' module
6074 module.exports = function inherits(ctor, superCtor) {
6075 if (superCtor) {
6076 ctor.super_ = superCtor
6077 ctor.prototype = Object.create(superCtor.prototype, {
6078 constructor: {
6079 value: ctor,
6080 enumerable: false,
6081 writable: true,
6082 configurable: true
6083 }
6084 })
6085 }
6086 };
6087 } else {
6088 // old school shim for old browsers
6089 module.exports = function inherits(ctor, superCtor) {
6090 if (superCtor) {
6091 ctor.super_ = superCtor
6092 var TempCtor = function () {}
6093 TempCtor.prototype = superCtor.prototype
6094 ctor.prototype = new TempCtor()
6095 ctor.prototype.constructor = ctor
6096 }
6097 }
6098 }
6099
6100 },{}],45:[function(require,module,exports){
6101 'use strict'
6102 var inherits = require('inherits')
6103 var HashBase = require('hash-base')
6104 var Buffer = require('safe-buffer').Buffer
6105
6106 var ARRAY16 = new Array(16)
6107
6108 function MD5 () {
6109 HashBase.call(this, 64)
6110
6111 // state
6112 this._a = 0x67452301
6113 this._b = 0xefcdab89
6114 this._c = 0x98badcfe
6115 this._d = 0x10325476
6116 }
6117
6118 inherits(MD5, HashBase)
6119
6120 MD5.prototype._update = function () {
6121 var M = ARRAY16
6122 for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4)
6123
6124 var a = this._a
6125 var b = this._b
6126 var c = this._c
6127 var d = this._d
6128
6129 a = fnF(a, b, c, d, M[0], 0xd76aa478, 7)
6130 d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12)
6131 c = fnF(c, d, a, b, M[2], 0x242070db, 17)
6132 b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22)
6133 a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7)
6134 d = fnF(d, a, b, c, M[5], 0x4787c62a, 12)
6135 c = fnF(c, d, a, b, M[6], 0xa8304613, 17)
6136 b = fnF(b, c, d, a, M[7], 0xfd469501, 22)
6137 a = fnF(a, b, c, d, M[8], 0x698098d8, 7)
6138 d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12)
6139 c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17)
6140 b = fnF(b, c, d, a, M[11], 0x895cd7be, 22)
6141 a = fnF(a, b, c, d, M[12], 0x6b901122, 7)
6142 d = fnF(d, a, b, c, M[13], 0xfd987193, 12)
6143 c = fnF(c, d, a, b, M[14], 0xa679438e, 17)
6144 b = fnF(b, c, d, a, M[15], 0x49b40821, 22)
6145
6146 a = fnG(a, b, c, d, M[1], 0xf61e2562, 5)
6147 d = fnG(d, a, b, c, M[6], 0xc040b340, 9)
6148 c = fnG(c, d, a, b, M[11], 0x265e5a51, 14)
6149 b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20)
6150 a = fnG(a, b, c, d, M[5], 0xd62f105d, 5)
6151 d = fnG(d, a, b, c, M[10], 0x02441453, 9)
6152 c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14)
6153 b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20)
6154 a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5)
6155 d = fnG(d, a, b, c, M[14], 0xc33707d6, 9)
6156 c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14)
6157 b = fnG(b, c, d, a, M[8], 0x455a14ed, 20)
6158 a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5)
6159 d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9)
6160 c = fnG(c, d, a, b, M[7], 0x676f02d9, 14)
6161 b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20)
6162
6163 a = fnH(a, b, c, d, M[5], 0xfffa3942, 4)
6164 d = fnH(d, a, b, c, M[8], 0x8771f681, 11)
6165 c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16)
6166 b = fnH(b, c, d, a, M[14], 0xfde5380c, 23)
6167 a = fnH(a, b, c, d, M[1], 0xa4beea44, 4)
6168 d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11)
6169 c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16)
6170 b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23)
6171 a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4)
6172 d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11)
6173 c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16)
6174 b = fnH(b, c, d, a, M[6], 0x04881d05, 23)
6175 a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4)
6176 d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11)
6177 c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16)
6178 b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23)
6179
6180 a = fnI(a, b, c, d, M[0], 0xf4292244, 6)
6181 d = fnI(d, a, b, c, M[7], 0x432aff97, 10)
6182 c = fnI(c, d, a, b, M[14], 0xab9423a7, 15)
6183 b = fnI(b, c, d, a, M[5], 0xfc93a039, 21)
6184 a = fnI(a, b, c, d, M[12], 0x655b59c3, 6)
6185 d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10)
6186 c = fnI(c, d, a, b, M[10], 0xffeff47d, 15)
6187 b = fnI(b, c, d, a, M[1], 0x85845dd1, 21)
6188 a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6)
6189 d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10)
6190 c = fnI(c, d, a, b, M[6], 0xa3014314, 15)
6191 b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21)
6192 a = fnI(a, b, c, d, M[4], 0xf7537e82, 6)
6193 d = fnI(d, a, b, c, M[11], 0xbd3af235, 10)
6194 c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15)
6195 b = fnI(b, c, d, a, M[9], 0xeb86d391, 21)
6196
6197 this._a = (this._a + a) | 0
6198 this._b = (this._b + b) | 0
6199 this._c = (this._c + c) | 0
6200 this._d = (this._d + d) | 0
6201 }
6202
6203 MD5.prototype._digest = function () {
6204 // create padding and handle blocks
6205 this._block[this._blockOffset++] = 0x80
6206 if (this._blockOffset > 56) {
6207 this._block.fill(0, this._blockOffset, 64)
6208 this._update()
6209 this._blockOffset = 0
6210 }
6211
6212 this._block.fill(0, this._blockOffset, 56)
6213 this._block.writeUInt32LE(this._length[0], 56)
6214 this._block.writeUInt32LE(this._length[1], 60)
6215 this._update()
6216
6217 // produce result
6218 var buffer = Buffer.allocUnsafe(16)
6219 buffer.writeInt32LE(this._a, 0)
6220 buffer.writeInt32LE(this._b, 4)
6221 buffer.writeInt32LE(this._c, 8)
6222 buffer.writeInt32LE(this._d, 12)
6223 return buffer
6224 }
6225
6226 function rotl (x, n) {
6227 return (x << n) | (x >>> (32 - n))
6228 }
6229
6230 function fnF (a, b, c, d, m, k, s) {
6231 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + b) | 0
6232 }
6233
6234 function fnG (a, b, c, d, m, k, s) {
6235 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + b) | 0
6236 }
6237
6238 function fnH (a, b, c, d, m, k, s) {
6239 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + b) | 0
6240 }
6241
6242 function fnI (a, b, c, d, m, k, s) {
6243 return (rotl((a + ((c ^ (b | (~d)))) + m + k) | 0, s) + b) | 0
6244 }
6245
6246 module.exports = MD5
6247
6248 },{"hash-base":43,"inherits":44,"safe-buffer":47}],46:[function(require,module,exports){
6249 'use strict'
6250 var Buffer = require('buffer').Buffer
6251 var inherits = require('inherits')
6252 var HashBase = require('hash-base')
6253
6254 var ARRAY16 = new Array(16)
6255
6256 var zl = [
6257 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
6258 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
6259 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
6260 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
6261 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
6262 ]
6263
6264 var zr = [
6265 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
6266 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
6267 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
6268 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
6269 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
6270 ]
6271
6272 var sl = [
6273 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
6274 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
6275 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
6276 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
6277 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
6278 ]
6279
6280 var sr = [
6281 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
6282 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
6283 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
6284 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
6285 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
6286 ]
6287
6288 var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]
6289 var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]
6290
6291 function RIPEMD160 () {
6292 HashBase.call(this, 64)
6293
6294 // state
6295 this._a = 0x67452301
6296 this._b = 0xefcdab89
6297 this._c = 0x98badcfe
6298 this._d = 0x10325476
6299 this._e = 0xc3d2e1f0
6300 }
6301
6302 inherits(RIPEMD160, HashBase)
6303
6304 RIPEMD160.prototype._update = function () {
6305 var words = ARRAY16
6306 for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4)
6307
6308 var al = this._a | 0
6309 var bl = this._b | 0
6310 var cl = this._c | 0
6311 var dl = this._d | 0
6312 var el = this._e | 0
6313
6314 var ar = this._a | 0
6315 var br = this._b | 0
6316 var cr = this._c | 0
6317 var dr = this._d | 0
6318 var er = this._e | 0
6319
6320 // computation
6321 for (var i = 0; i < 80; i += 1) {
6322 var tl
6323 var tr
6324 if (i < 16) {
6325 tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i])
6326 tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i])
6327 } else if (i < 32) {
6328 tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i])
6329 tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i])
6330 } else if (i < 48) {
6331 tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i])
6332 tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i])
6333 } else if (i < 64) {
6334 tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i])
6335 tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i])
6336 } else { // if (i<80) {
6337 tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i])
6338 tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i])
6339 }
6340
6341 al = el
6342 el = dl
6343 dl = rotl(cl, 10)
6344 cl = bl
6345 bl = tl
6346
6347 ar = er
6348 er = dr
6349 dr = rotl(cr, 10)
6350 cr = br
6351 br = tr
6352 }
6353
6354 // update state
6355 var t = (this._b + cl + dr) | 0
6356 this._b = (this._c + dl + er) | 0
6357 this._c = (this._d + el + ar) | 0
6358 this._d = (this._e + al + br) | 0
6359 this._e = (this._a + bl + cr) | 0
6360 this._a = t
6361 }
6362
6363 RIPEMD160.prototype._digest = function () {
6364 // create padding and handle blocks
6365 this._block[this._blockOffset++] = 0x80
6366 if (this._blockOffset > 56) {
6367 this._block.fill(0, this._blockOffset, 64)
6368 this._update()
6369 this._blockOffset = 0
6370 }
6371
6372 this._block.fill(0, this._blockOffset, 56)
6373 this._block.writeUInt32LE(this._length[0], 56)
6374 this._block.writeUInt32LE(this._length[1], 60)
6375 this._update()
6376
6377 // produce result
6378 var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20)
6379 buffer.writeInt32LE(this._a, 0)
6380 buffer.writeInt32LE(this._b, 4)
6381 buffer.writeInt32LE(this._c, 8)
6382 buffer.writeInt32LE(this._d, 12)
6383 buffer.writeInt32LE(this._e, 16)
6384 return buffer
6385 }
6386
6387 function rotl (x, n) {
6388 return (x << n) | (x >>> (32 - n))
6389 }
6390
6391 function fn1 (a, b, c, d, e, m, k, s) {
6392 return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0
6393 }
6394
6395 function fn2 (a, b, c, d, e, m, k, s) {
6396 return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0
6397 }
6398
6399 function fn3 (a, b, c, d, e, m, k, s) {
6400 return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0
6401 }
6402
6403 function fn4 (a, b, c, d, e, m, k, s) {
6404 return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0
6405 }
6406
6407 function fn5 (a, b, c, d, e, m, k, s) {
6408 return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0
6409 }
6410
6411 module.exports = RIPEMD160
6412
6413 },{"buffer":110,"hash-base":43,"inherits":44}],47:[function(require,module,exports){
6414 /* eslint-disable node/no-deprecated-api */
6415 var buffer = require('buffer')
6416 var Buffer = buffer.Buffer
6417
6418 // alternative to using Object.keys for old browsers
6419 function copyProps (src, dst) {
6420 for (var key in src) {
6421 dst[key] = src[key]
6422 }
6423 }
6424 if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
6425 module.exports = buffer
6426 } else {
6427 // Copy properties from require('buffer')
6428 copyProps(buffer, exports)
6429 exports.Buffer = SafeBuffer
6430 }
6431
6432 function SafeBuffer (arg, encodingOrOffset, length) {
6433 return Buffer(arg, encodingOrOffset, length)
6434 }
6435
6436 SafeBuffer.prototype = Object.create(Buffer.prototype)
6437
6438 // Copy static methods from Buffer
6439 copyProps(Buffer, SafeBuffer)
6440
6441 SafeBuffer.from = function (arg, encodingOrOffset, length) {
6442 if (typeof arg === 'number') {
6443 throw new TypeError('Argument must not be a number')
6444 }
6445 return Buffer(arg, encodingOrOffset, length)
6446 }
6447
6448 SafeBuffer.alloc = function (size, fill, encoding) {
6449 if (typeof size !== 'number') {
6450 throw new TypeError('Argument must be a number')
6451 }
6452 var buf = Buffer(size)
6453 if (fill !== undefined) {
6454 if (typeof encoding === 'string') {
6455 buf.fill(fill, encoding)
6456 } else {
6457 buf.fill(fill)
6458 }
6459 } else {
6460 buf.fill(0)
6461 }
6462 return buf
6463 }
6464
6465 SafeBuffer.allocUnsafe = function (size) {
6466 if (typeof size !== 'number') {
6467 throw new TypeError('Argument must be a number')
6468 }
6469 return Buffer(size)
6470 }
6471
6472 SafeBuffer.allocUnsafeSlow = function (size) {
6473 if (typeof size !== 'number') {
6474 throw new TypeError('Argument must be a number')
6475 }
6476 return buffer.SlowBuffer(size)
6477 }
6478
6479 },{"buffer":110}],48:[function(require,module,exports){
6480 const scrypt = require('./scryptSync')
6481 scrypt.async = require('./scrypt')
6482 module.exports = scrypt
6483
6484 },{"./scrypt":49,"./scryptSync":50}],49:[function(require,module,exports){
6485 const crypto = require('crypto')
6486 const {
6487 checkAndInit,
6488 smix
6489 } = require('./utils')
6490
6491 // N = Cpu cost, r = Memory cost, p = parallelization cost
6492 async function scrypt (key, salt, N, r, p, dkLen, progressCallback, promiseInterval) {
6493 const {
6494 XY,
6495 V,
6496 B32,
6497 x,
6498 _X,
6499 B,
6500 tickCallback
6501 } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback)
6502
6503 for (var i = 0; i < p; i++) {
6504 await smix(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval)
6505 }
6506
6507 return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256')
6508 }
6509
6510 module.exports = scrypt
6511
6512 },{"./utils":51,"crypto":118}],50:[function(require,module,exports){
6513 const crypto = require('crypto')
6514 const {
6515 checkAndInit,
6516 smixSync
6517 } = require('./utils')
6518
6519 // N = Cpu cost, r = Memory cost, p = parallelization cost
6520 function scrypt (key, salt, N, r, p, dkLen, progressCallback) {
6521 const {
6522 XY,
6523 V,
6524 B32,
6525 x,
6526 _X,
6527 B,
6528 tickCallback
6529 } = checkAndInit(key, salt, N, r, p, dkLen, progressCallback)
6530
6531 for (var i = 0; i < p; i++) {
6532 smixSync(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback)
6533 }
6534
6535 return crypto.pbkdf2Sync(key, B, 1, dkLen, 'sha256')
6536 }
6537
6538 module.exports = scrypt
6539
6540 },{"./utils":51,"crypto":118}],51:[function(require,module,exports){
6541 (function (Buffer,setImmediate){
6542 const crypto = require('crypto')
6543 const MAX_VALUE = 0x7fffffff
6544 const DEFAULT_PROMISE_INTERVAL = 5000
6545 /* eslint-disable camelcase */
6546
6547 function checkAndInit (key, salt, N, r, p, dkLen, progressCallback) {
6548 if (N === 0 || (N & (N - 1)) !== 0) throw Error('N must be > 0 and a power of 2')
6549
6550 if (N > MAX_VALUE / 128 / r) throw Error('Parameter N is too large')
6551 if (r > MAX_VALUE / 128 / p) throw Error('Parameter r is too large')
6552
6553 let XY = Buffer.alloc(256 * r)
6554 let V = Buffer.alloc(128 * r * N)
6555
6556 // pseudo global
6557 let B32 = new Int32Array(16) // salsa20_8
6558 let x = new Int32Array(16) // salsa20_8
6559 let _X = Buffer.alloc(64) // blockmix_salsa8
6560
6561 // pseudo global
6562 let B = crypto.pbkdf2Sync(key, salt, 1, p * 128 * r, 'sha256')
6563
6564 let tickCallback
6565 if (progressCallback) {
6566 let totalOps = p * N * 2
6567 let currentOp = 0
6568
6569 tickCallback = function () {
6570 ++currentOp
6571
6572 // send progress notifications once every 1,000 ops
6573 if (currentOp % 1000 === 0) {
6574 progressCallback({
6575 current: currentOp,
6576 total: totalOps,
6577 percent: (currentOp / totalOps) * 100.0
6578 })
6579 }
6580 }
6581 }
6582 return {
6583 XY,
6584 V,
6585 B32,
6586 x,
6587 _X,
6588 B,
6589 tickCallback
6590 }
6591 }
6592
6593 async function smix (B, Bi, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) {
6594 promiseInterval = promiseInterval || DEFAULT_PROMISE_INTERVAL
6595 let Xi = 0
6596 let Yi = 128 * r
6597 let i
6598
6599 B.copy(XY, Xi, Bi, Bi + Yi)
6600
6601 for (i = 0; i < N; i++) {
6602 XY.copy(V, i * Yi, Xi, Xi + Yi)
6603 if (i % promiseInterval === 0) {
6604 await new Promise(resolve => setImmediate(resolve))
6605 }
6606 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6607
6608 if (tickCallback) tickCallback()
6609 }
6610
6611 for (i = 0; i < N; i++) {
6612 let offset = Xi + (2 * r - 1) * 64
6613 let j = XY.readUInt32LE(offset) & (N - 1)
6614 blockxor(V, j * Yi, XY, Xi, Yi)
6615 if (i % promiseInterval === 0) {
6616 await new Promise(resolve => setImmediate(resolve))
6617 }
6618 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6619
6620 if (tickCallback) tickCallback()
6621 }
6622
6623 XY.copy(B, Bi, Xi, Xi + Yi)
6624 }
6625
6626 function smixSync (B, Bi, r, N, V, XY, _X, B32, x, tickCallback) {
6627 let Xi = 0
6628 let Yi = 128 * r
6629 let i
6630
6631 B.copy(XY, Xi, Bi, Bi + Yi)
6632
6633 for (i = 0; i < N; i++) {
6634 XY.copy(V, i * Yi, Xi, Xi + Yi)
6635 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6636
6637 if (tickCallback) tickCallback()
6638 }
6639
6640 for (i = 0; i < N; i++) {
6641 let offset = Xi + (2 * r - 1) * 64
6642 let j = XY.readUInt32LE(offset) & (N - 1)
6643 blockxor(V, j * Yi, XY, Xi, Yi)
6644 blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
6645
6646 if (tickCallback) tickCallback()
6647 }
6648
6649 XY.copy(B, Bi, Xi, Xi + Yi)
6650 }
6651
6652 function blockmix_salsa8 (BY, Bi, Yi, r, _X, B32, x) {
6653 let i
6654
6655 arraycopy(BY, Bi + (2 * r - 1) * 64, _X, 0, 64)
6656
6657 for (i = 0; i < 2 * r; i++) {
6658 blockxor(BY, i * 64, _X, 0, 64)
6659 salsa20_8(_X, B32, x)
6660 arraycopy(_X, 0, BY, Yi + (i * 64), 64)
6661 }
6662
6663 for (i = 0; i < r; i++) {
6664 arraycopy(BY, Yi + (i * 2) * 64, BY, Bi + (i * 64), 64)
6665 }
6666
6667 for (i = 0; i < r; i++) {
6668 arraycopy(BY, Yi + (i * 2 + 1) * 64, BY, Bi + (i + r) * 64, 64)
6669 }
6670 }
6671
6672 function R (a, b) {
6673 return (a << b) | (a >>> (32 - b))
6674 }
6675
6676 function salsa20_8 (B, B32, x) {
6677 let i
6678
6679 for (i = 0; i < 16; i++) {
6680 B32[i] = (B[i * 4 + 0] & 0xff) << 0
6681 B32[i] |= (B[i * 4 + 1] & 0xff) << 8
6682 B32[i] |= (B[i * 4 + 2] & 0xff) << 16
6683 B32[i] |= (B[i * 4 + 3] & 0xff) << 24
6684 // B32[i] = B.readUInt32LE(i*4) <--- this is signficantly slower even in Node.js
6685 }
6686
6687 arraycopy(B32, 0, x, 0, 16)
6688
6689 for (i = 8; i > 0; i -= 2) {
6690 x[4] ^= R(x[0] + x[12], 7)
6691 x[8] ^= R(x[4] + x[0], 9)
6692 x[12] ^= R(x[8] + x[4], 13)
6693 x[0] ^= R(x[12] + x[8], 18)
6694 x[9] ^= R(x[5] + x[1], 7)
6695 x[13] ^= R(x[9] + x[5], 9)
6696 x[1] ^= R(x[13] + x[9], 13)
6697 x[5] ^= R(x[1] + x[13], 18)
6698 x[14] ^= R(x[10] + x[6], 7)
6699 x[2] ^= R(x[14] + x[10], 9)
6700 x[6] ^= R(x[2] + x[14], 13)
6701 x[10] ^= R(x[6] + x[2], 18)
6702 x[3] ^= R(x[15] + x[11], 7)
6703 x[7] ^= R(x[3] + x[15], 9)
6704 x[11] ^= R(x[7] + x[3], 13)
6705 x[15] ^= R(x[11] + x[7], 18)
6706 x[1] ^= R(x[0] + x[3], 7)
6707 x[2] ^= R(x[1] + x[0], 9)
6708 x[3] ^= R(x[2] + x[1], 13)
6709 x[0] ^= R(x[3] + x[2], 18)
6710 x[6] ^= R(x[5] + x[4], 7)
6711 x[7] ^= R(x[6] + x[5], 9)
6712 x[4] ^= R(x[7] + x[6], 13)
6713 x[5] ^= R(x[4] + x[7], 18)
6714 x[11] ^= R(x[10] + x[9], 7)
6715 x[8] ^= R(x[11] + x[10], 9)
6716 x[9] ^= R(x[8] + x[11], 13)
6717 x[10] ^= R(x[9] + x[8], 18)
6718 x[12] ^= R(x[15] + x[14], 7)
6719 x[13] ^= R(x[12] + x[15], 9)
6720 x[14] ^= R(x[13] + x[12], 13)
6721 x[15] ^= R(x[14] + x[13], 18)
6722 }
6723
6724 for (i = 0; i < 16; ++i) B32[i] = x[i] + B32[i]
6725
6726 for (i = 0; i < 16; i++) {
6727 let bi = i * 4
6728 B[bi + 0] = (B32[i] >> 0 & 0xff)
6729 B[bi + 1] = (B32[i] >> 8 & 0xff)
6730 B[bi + 2] = (B32[i] >> 16 & 0xff)
6731 B[bi + 3] = (B32[i] >> 24 & 0xff)
6732 // B.writeInt32LE(B32[i], i*4) //<--- this is signficantly slower even in Node.js
6733 }
6734 }
6735
6736 // naive approach... going back to loop unrolling may yield additional performance
6737 function blockxor (S, Si, D, Di, len) {
6738 for (let i = 0; i < len; i++) {
6739 D[Di + i] ^= S[Si + i]
6740 }
6741 }
6742
6743 function arraycopy (src, srcPos, dest, destPos, length) {
6744 if (Buffer.isBuffer(src) && Buffer.isBuffer(dest)) {
6745 src.copy(dest, destPos, srcPos, srcPos + length)
6746 } else {
6747 while (length--) {
6748 dest[destPos++] = src[srcPos++]
6749 }
6750 }
6751 }
6752
6753 module.exports = {
6754 checkAndInit,
6755 smix,
6756 smixSync
6757 }
6758
6759 }).call(this,require("buffer").Buffer,require("timers").setImmediate)
6760 },{"buffer":110,"crypto":118,"timers":217}],52:[function(require,module,exports){
6761 var Buffer = require('safe-buffer').Buffer
6762
6763 // prototype class for hash functions
6764 function Hash (blockSize, finalSize) {
6765 this._block = Buffer.alloc(blockSize)
6766 this._finalSize = finalSize
6767 this._blockSize = blockSize
6768 this._len = 0
6769 }
6770
6771 Hash.prototype.update = function (data, enc) {
6772 if (typeof data === 'string') {
6773 enc = enc || 'utf8'
6774 data = Buffer.from(data, enc)
6775 }
6776
6777 var block = this._block
6778 var blockSize = this._blockSize
6779 var length = data.length
6780 var accum = this._len
6781
6782 for (var offset = 0; offset < length;) {
6783 var assigned = accum % blockSize
6784 var remainder = Math.min(length - offset, blockSize - assigned)
6785
6786 for (var i = 0; i < remainder; i++) {
6787 block[assigned + i] = data[offset + i]
6788 }
6789
6790 accum += remainder
6791 offset += remainder
6792
6793 if ((accum % blockSize) === 0) {
6794 this._update(block)
6795 }
6796 }
6797
6798 this._len += length
6799 return this
6800 }
6801
6802 Hash.prototype.digest = function (enc) {
6803 var rem = this._len % this._blockSize
6804
6805 this._block[rem] = 0x80
6806
6807 // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
6808 // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
6809 this._block.fill(0, rem + 1)
6810
6811 if (rem >= this._finalSize) {
6812 this._update(this._block)
6813 this._block.fill(0)
6814 }
6815
6816 var bits = this._len * 8
6817
6818 // uint32
6819 if (bits <= 0xffffffff) {
6820 this._block.writeUInt32BE(bits, this._blockSize - 4)
6821
6822 // uint64
6823 } else {
6824 var lowBits = (bits & 0xffffffff) >>> 0
6825 var highBits = (bits - lowBits) / 0x100000000
6826
6827 this._block.writeUInt32BE(highBits, this._blockSize - 8)
6828 this._block.writeUInt32BE(lowBits, this._blockSize - 4)
6829 }
6830
6831 this._update(this._block)
6832 var hash = this._hash()
6833
6834 return enc ? hash.toString(enc) : hash
6835 }
6836
6837 Hash.prototype._update = function () {
6838 throw new Error('_update must be implemented by subclass')
6839 }
6840
6841 module.exports = Hash
6842
6843 },{"safe-buffer":47}],53:[function(require,module,exports){
6844 var exports = module.exports = function SHA (algorithm) {
6845 algorithm = algorithm.toLowerCase()
6846
6847 var Algorithm = exports[algorithm]
6848 if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
6849
6850 return new Algorithm()
6851 }
6852
6853 exports.sha = require('./sha')
6854 exports.sha1 = require('./sha1')
6855 exports.sha224 = require('./sha224')
6856 exports.sha256 = require('./sha256')
6857 exports.sha384 = require('./sha384')
6858 exports.sha512 = require('./sha512')
6859
6860 },{"./sha":54,"./sha1":55,"./sha224":56,"./sha256":57,"./sha384":58,"./sha512":59}],54:[function(require,module,exports){
6861 /*
6862 * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
6863 * in FIPS PUB 180-1
6864 * This source code is derived from sha1.js of the same repository.
6865 * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
6866 * operation was added.
6867 */
6868
6869 var inherits = require('inherits')
6870 var Hash = require('./hash')
6871 var Buffer = require('safe-buffer').Buffer
6872
6873 var K = [
6874 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6875 ]
6876
6877 var W = new Array(80)
6878
6879 function Sha () {
6880 this.init()
6881 this._w = W
6882
6883 Hash.call(this, 64, 56)
6884 }
6885
6886 inherits(Sha, Hash)
6887
6888 Sha.prototype.init = function () {
6889 this._a = 0x67452301
6890 this._b = 0xefcdab89
6891 this._c = 0x98badcfe
6892 this._d = 0x10325476
6893 this._e = 0xc3d2e1f0
6894
6895 return this
6896 }
6897
6898 function rotl5 (num) {
6899 return (num << 5) | (num >>> 27)
6900 }
6901
6902 function rotl30 (num) {
6903 return (num << 30) | (num >>> 2)
6904 }
6905
6906 function ft (s, b, c, d) {
6907 if (s === 0) return (b & c) | ((~b) & d)
6908 if (s === 2) return (b & c) | (b & d) | (c & d)
6909 return b ^ c ^ d
6910 }
6911
6912 Sha.prototype._update = function (M) {
6913 var W = this._w
6914
6915 var a = this._a | 0
6916 var b = this._b | 0
6917 var c = this._c | 0
6918 var d = this._d | 0
6919 var e = this._e | 0
6920
6921 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
6922 for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
6923
6924 for (var j = 0; j < 80; ++j) {
6925 var s = ~~(j / 20)
6926 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
6927
6928 e = d
6929 d = c
6930 c = rotl30(b)
6931 b = a
6932 a = t
6933 }
6934
6935 this._a = (a + this._a) | 0
6936 this._b = (b + this._b) | 0
6937 this._c = (c + this._c) | 0
6938 this._d = (d + this._d) | 0
6939 this._e = (e + this._e) | 0
6940 }
6941
6942 Sha.prototype._hash = function () {
6943 var H = Buffer.allocUnsafe(20)
6944
6945 H.writeInt32BE(this._a | 0, 0)
6946 H.writeInt32BE(this._b | 0, 4)
6947 H.writeInt32BE(this._c | 0, 8)
6948 H.writeInt32BE(this._d | 0, 12)
6949 H.writeInt32BE(this._e | 0, 16)
6950
6951 return H
6952 }
6953
6954 module.exports = Sha
6955
6956 },{"./hash":52,"inherits":44,"safe-buffer":47}],55:[function(require,module,exports){
6957 /*
6958 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
6959 * in FIPS PUB 180-1
6960 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
6961 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6962 * Distributed under the BSD License
6963 * See http://pajhome.org.uk/crypt/md5 for details.
6964 */
6965
6966 var inherits = require('inherits')
6967 var Hash = require('./hash')
6968 var Buffer = require('safe-buffer').Buffer
6969
6970 var K = [
6971 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
6972 ]
6973
6974 var W = new Array(80)
6975
6976 function Sha1 () {
6977 this.init()
6978 this._w = W
6979
6980 Hash.call(this, 64, 56)
6981 }
6982
6983 inherits(Sha1, Hash)
6984
6985 Sha1.prototype.init = function () {
6986 this._a = 0x67452301
6987 this._b = 0xefcdab89
6988 this._c = 0x98badcfe
6989 this._d = 0x10325476
6990 this._e = 0xc3d2e1f0
6991
6992 return this
6993 }
6994
6995 function rotl1 (num) {
6996 return (num << 1) | (num >>> 31)
6997 }
6998
6999 function rotl5 (num) {
7000 return (num << 5) | (num >>> 27)
7001 }
7002
7003 function rotl30 (num) {
7004 return (num << 30) | (num >>> 2)
7005 }
7006
7007 function ft (s, b, c, d) {
7008 if (s === 0) return (b & c) | ((~b) & d)
7009 if (s === 2) return (b & c) | (b & d) | (c & d)
7010 return b ^ c ^ d
7011 }
7012
7013 Sha1.prototype._update = function (M) {
7014 var W = this._w
7015
7016 var a = this._a | 0
7017 var b = this._b | 0
7018 var c = this._c | 0
7019 var d = this._d | 0
7020 var e = this._e | 0
7021
7022 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
7023 for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
7024
7025 for (var j = 0; j < 80; ++j) {
7026 var s = ~~(j / 20)
7027 var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
7028
7029 e = d
7030 d = c
7031 c = rotl30(b)
7032 b = a
7033 a = t
7034 }
7035
7036 this._a = (a + this._a) | 0
7037 this._b = (b + this._b) | 0
7038 this._c = (c + this._c) | 0
7039 this._d = (d + this._d) | 0
7040 this._e = (e + this._e) | 0
7041 }
7042
7043 Sha1.prototype._hash = function () {
7044 var H = Buffer.allocUnsafe(20)
7045
7046 H.writeInt32BE(this._a | 0, 0)
7047 H.writeInt32BE(this._b | 0, 4)
7048 H.writeInt32BE(this._c | 0, 8)
7049 H.writeInt32BE(this._d | 0, 12)
7050 H.writeInt32BE(this._e | 0, 16)
7051
7052 return H
7053 }
7054
7055 module.exports = Sha1
7056
7057 },{"./hash":52,"inherits":44,"safe-buffer":47}],56:[function(require,module,exports){
7058 /**
7059 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
7060 * in FIPS 180-2
7061 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
7062 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
7063 *
7064 */
7065
7066 var inherits = require('inherits')
7067 var Sha256 = require('./sha256')
7068 var Hash = require('./hash')
7069 var Buffer = require('safe-buffer').Buffer
7070
7071 var W = new Array(64)
7072
7073 function Sha224 () {
7074 this.init()
7075
7076 this._w = W // new Array(64)
7077
7078 Hash.call(this, 64, 56)
7079 }
7080
7081 inherits(Sha224, Sha256)
7082
7083 Sha224.prototype.init = function () {
7084 this._a = 0xc1059ed8
7085 this._b = 0x367cd507
7086 this._c = 0x3070dd17
7087 this._d = 0xf70e5939
7088 this._e = 0xffc00b31
7089 this._f = 0x68581511
7090 this._g = 0x64f98fa7
7091 this._h = 0xbefa4fa4
7092
7093 return this
7094 }
7095
7096 Sha224.prototype._hash = function () {
7097 var H = Buffer.allocUnsafe(28)
7098
7099 H.writeInt32BE(this._a, 0)
7100 H.writeInt32BE(this._b, 4)
7101 H.writeInt32BE(this._c, 8)
7102 H.writeInt32BE(this._d, 12)
7103 H.writeInt32BE(this._e, 16)
7104 H.writeInt32BE(this._f, 20)
7105 H.writeInt32BE(this._g, 24)
7106
7107 return H
7108 }
7109
7110 module.exports = Sha224
7111
7112 },{"./hash":52,"./sha256":57,"inherits":44,"safe-buffer":47}],57:[function(require,module,exports){
7113 /**
7114 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
7115 * in FIPS 180-2
7116 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
7117 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
7118 *
7119 */
7120
7121 var inherits = require('inherits')
7122 var Hash = require('./hash')
7123 var Buffer = require('safe-buffer').Buffer
7124
7125 var K = [
7126 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
7127 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
7128 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
7129 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
7130 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
7131 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
7132 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
7133 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
7134 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
7135 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
7136 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
7137 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
7138 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
7139 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
7140 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
7141 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
7142 ]
7143
7144 var W = new Array(64)
7145
7146 function Sha256 () {
7147 this.init()
7148
7149 this._w = W // new Array(64)
7150
7151 Hash.call(this, 64, 56)
7152 }
7153
7154 inherits(Sha256, Hash)
7155
7156 Sha256.prototype.init = function () {
7157 this._a = 0x6a09e667
7158 this._b = 0xbb67ae85
7159 this._c = 0x3c6ef372
7160 this._d = 0xa54ff53a
7161 this._e = 0x510e527f
7162 this._f = 0x9b05688c
7163 this._g = 0x1f83d9ab
7164 this._h = 0x5be0cd19
7165
7166 return this
7167 }
7168
7169 function ch (x, y, z) {
7170 return z ^ (x & (y ^ z))
7171 }
7172
7173 function maj (x, y, z) {
7174 return (x & y) | (z & (x | y))
7175 }
7176
7177 function sigma0 (x) {
7178 return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
7179 }
7180
7181 function sigma1 (x) {
7182 return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
7183 }
7184
7185 function gamma0 (x) {
7186 return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
7187 }
7188
7189 function gamma1 (x) {
7190 return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
7191 }
7192
7193 Sha256.prototype._update = function (M) {
7194 var W = this._w
7195
7196 var a = this._a | 0
7197 var b = this._b | 0
7198 var c = this._c | 0
7199 var d = this._d | 0
7200 var e = this._e | 0
7201 var f = this._f | 0
7202 var g = this._g | 0
7203 var h = this._h | 0
7204
7205 for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
7206 for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
7207
7208 for (var j = 0; j < 64; ++j) {
7209 var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
7210 var T2 = (sigma0(a) + maj(a, b, c)) | 0
7211
7212 h = g
7213 g = f
7214 f = e
7215 e = (d + T1) | 0
7216 d = c
7217 c = b
7218 b = a
7219 a = (T1 + T2) | 0
7220 }
7221
7222 this._a = (a + this._a) | 0
7223 this._b = (b + this._b) | 0
7224 this._c = (c + this._c) | 0
7225 this._d = (d + this._d) | 0
7226 this._e = (e + this._e) | 0
7227 this._f = (f + this._f) | 0
7228 this._g = (g + this._g) | 0
7229 this._h = (h + this._h) | 0
7230 }
7231
7232 Sha256.prototype._hash = function () {
7233 var H = Buffer.allocUnsafe(32)
7234
7235 H.writeInt32BE(this._a, 0)
7236 H.writeInt32BE(this._b, 4)
7237 H.writeInt32BE(this._c, 8)
7238 H.writeInt32BE(this._d, 12)
7239 H.writeInt32BE(this._e, 16)
7240 H.writeInt32BE(this._f, 20)
7241 H.writeInt32BE(this._g, 24)
7242 H.writeInt32BE(this._h, 28)
7243
7244 return H
7245 }
7246
7247 module.exports = Sha256
7248
7249 },{"./hash":52,"inherits":44,"safe-buffer":47}],58:[function(require,module,exports){
7250 var inherits = require('inherits')
7251 var SHA512 = require('./sha512')
7252 var Hash = require('./hash')
7253 var Buffer = require('safe-buffer').Buffer
7254
7255 var W = new Array(160)
7256
7257 function Sha384 () {
7258 this.init()
7259 this._w = W
7260
7261 Hash.call(this, 128, 112)
7262 }
7263
7264 inherits(Sha384, SHA512)
7265
7266 Sha384.prototype.init = function () {
7267 this._ah = 0xcbbb9d5d
7268 this._bh = 0x629a292a
7269 this._ch = 0x9159015a
7270 this._dh = 0x152fecd8
7271 this._eh = 0x67332667
7272 this._fh = 0x8eb44a87
7273 this._gh = 0xdb0c2e0d
7274 this._hh = 0x47b5481d
7275
7276 this._al = 0xc1059ed8
7277 this._bl = 0x367cd507
7278 this._cl = 0x3070dd17
7279 this._dl = 0xf70e5939
7280 this._el = 0xffc00b31
7281 this._fl = 0x68581511
7282 this._gl = 0x64f98fa7
7283 this._hl = 0xbefa4fa4
7284
7285 return this
7286 }
7287
7288 Sha384.prototype._hash = function () {
7289 var H = Buffer.allocUnsafe(48)
7290
7291 function writeInt64BE (h, l, offset) {
7292 H.writeInt32BE(h, offset)
7293 H.writeInt32BE(l, offset + 4)
7294 }
7295
7296 writeInt64BE(this._ah, this._al, 0)
7297 writeInt64BE(this._bh, this._bl, 8)
7298 writeInt64BE(this._ch, this._cl, 16)
7299 writeInt64BE(this._dh, this._dl, 24)
7300 writeInt64BE(this._eh, this._el, 32)
7301 writeInt64BE(this._fh, this._fl, 40)
7302
7303 return H
7304 }
7305
7306 module.exports = Sha384
7307
7308 },{"./hash":52,"./sha512":59,"inherits":44,"safe-buffer":47}],59:[function(require,module,exports){
7309 var inherits = require('inherits')
7310 var Hash = require('./hash')
7311 var Buffer = require('safe-buffer').Buffer
7312
7313 var K = [
7314 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
7315 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
7316 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
7317 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
7318 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
7319 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
7320 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
7321 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
7322 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
7323 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
7324 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
7325 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
7326 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
7327 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
7328 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
7329 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
7330 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
7331 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
7332 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
7333 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
7334 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
7335 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
7336 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
7337 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
7338 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
7339 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
7340 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
7341 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
7342 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
7343 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
7344 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
7345 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
7346 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
7347 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
7348 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
7349 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
7350 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
7351 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
7352 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
7353 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
7354 ]
7355
7356 var W = new Array(160)
7357
7358 function Sha512 () {
7359 this.init()
7360 this._w = W
7361
7362 Hash.call(this, 128, 112)
7363 }
7364
7365 inherits(Sha512, Hash)
7366
7367 Sha512.prototype.init = function () {
7368 this._ah = 0x6a09e667
7369 this._bh = 0xbb67ae85
7370 this._ch = 0x3c6ef372
7371 this._dh = 0xa54ff53a
7372 this._eh = 0x510e527f
7373 this._fh = 0x9b05688c
7374 this._gh = 0x1f83d9ab
7375 this._hh = 0x5be0cd19
7376
7377 this._al = 0xf3bcc908
7378 this._bl = 0x84caa73b
7379 this._cl = 0xfe94f82b
7380 this._dl = 0x5f1d36f1
7381 this._el = 0xade682d1
7382 this._fl = 0x2b3e6c1f
7383 this._gl = 0xfb41bd6b
7384 this._hl = 0x137e2179
7385
7386 return this
7387 }
7388
7389 function Ch (x, y, z) {
7390 return z ^ (x & (y ^ z))
7391 }
7392
7393 function maj (x, y, z) {
7394 return (x & y) | (z & (x | y))
7395 }
7396
7397 function sigma0 (x, xl) {
7398 return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
7399 }
7400
7401 function sigma1 (x, xl) {
7402 return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
7403 }
7404
7405 function Gamma0 (x, xl) {
7406 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
7407 }
7408
7409 function Gamma0l (x, xl) {
7410 return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
7411 }
7412
7413 function Gamma1 (x, xl) {
7414 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
7415 }
7416
7417 function Gamma1l (x, xl) {
7418 return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
7419 }
7420
7421 function getCarry (a, b) {
7422 return (a >>> 0) < (b >>> 0) ? 1 : 0
7423 }
7424
7425 Sha512.prototype._update = function (M) {
7426 var W = this._w
7427
7428 var ah = this._ah | 0
7429 var bh = this._bh | 0
7430 var ch = this._ch | 0
7431 var dh = this._dh | 0
7432 var eh = this._eh | 0
7433 var fh = this._fh | 0
7434 var gh = this._gh | 0
7435 var hh = this._hh | 0
7436
7437 var al = this._al | 0
7438 var bl = this._bl | 0
7439 var cl = this._cl | 0
7440 var dl = this._dl | 0
7441 var el = this._el | 0
7442 var fl = this._fl | 0
7443 var gl = this._gl | 0
7444 var hl = this._hl | 0
7445
7446 for (var i = 0; i < 32; i += 2) {
7447 W[i] = M.readInt32BE(i * 4)
7448 W[i + 1] = M.readInt32BE(i * 4 + 4)
7449 }
7450 for (; i < 160; i += 2) {
7451 var xh = W[i - 15 * 2]
7452 var xl = W[i - 15 * 2 + 1]
7453 var gamma0 = Gamma0(xh, xl)
7454 var gamma0l = Gamma0l(xl, xh)
7455
7456 xh = W[i - 2 * 2]
7457 xl = W[i - 2 * 2 + 1]
7458 var gamma1 = Gamma1(xh, xl)
7459 var gamma1l = Gamma1l(xl, xh)
7460
7461 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
7462 var Wi7h = W[i - 7 * 2]
7463 var Wi7l = W[i - 7 * 2 + 1]
7464
7465 var Wi16h = W[i - 16 * 2]
7466 var Wi16l = W[i - 16 * 2 + 1]
7467
7468 var Wil = (gamma0l + Wi7l) | 0
7469 var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
7470 Wil = (Wil + gamma1l) | 0
7471 Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
7472 Wil = (Wil + Wi16l) | 0
7473 Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
7474
7475 W[i] = Wih
7476 W[i + 1] = Wil
7477 }
7478
7479 for (var j = 0; j < 160; j += 2) {
7480 Wih = W[j]
7481 Wil = W[j + 1]
7482
7483 var majh = maj(ah, bh, ch)
7484 var majl = maj(al, bl, cl)
7485
7486 var sigma0h = sigma0(ah, al)
7487 var sigma0l = sigma0(al, ah)
7488 var sigma1h = sigma1(eh, el)
7489 var sigma1l = sigma1(el, eh)
7490
7491 // t1 = h + sigma1 + ch + K[j] + W[j]
7492 var Kih = K[j]
7493 var Kil = K[j + 1]
7494
7495 var chh = Ch(eh, fh, gh)
7496 var chl = Ch(el, fl, gl)
7497
7498 var t1l = (hl + sigma1l) | 0
7499 var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
7500 t1l = (t1l + chl) | 0
7501 t1h = (t1h + chh + getCarry(t1l, chl)) | 0
7502 t1l = (t1l + Kil) | 0
7503 t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
7504 t1l = (t1l + Wil) | 0
7505 t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
7506
7507 // t2 = sigma0 + maj
7508 var t2l = (sigma0l + majl) | 0
7509 var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
7510
7511 hh = gh
7512 hl = gl
7513 gh = fh
7514 gl = fl
7515 fh = eh
7516 fl = el
7517 el = (dl + t1l) | 0
7518 eh = (dh + t1h + getCarry(el, dl)) | 0
7519 dh = ch
7520 dl = cl
7521 ch = bh
7522 cl = bl
7523 bh = ah
7524 bl = al
7525 al = (t1l + t2l) | 0
7526 ah = (t1h + t2h + getCarry(al, t1l)) | 0
7527 }
7528
7529 this._al = (this._al + al) | 0
7530 this._bl = (this._bl + bl) | 0
7531 this._cl = (this._cl + cl) | 0
7532 this._dl = (this._dl + dl) | 0
7533 this._el = (this._el + el) | 0
7534 this._fl = (this._fl + fl) | 0
7535 this._gl = (this._gl + gl) | 0
7536 this._hl = (this._hl + hl) | 0
7537
7538 this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
7539 this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
7540 this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
7541 this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
7542 this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
7543 this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
7544 this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
7545 this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
7546 }
7547
7548 Sha512.prototype._hash = function () {
7549 var H = Buffer.allocUnsafe(64)
7550
7551 function writeInt64BE (h, l, offset) {
7552 H.writeInt32BE(h, offset)
7553 H.writeInt32BE(l, offset + 4)
7554 }
7555
7556 writeInt64BE(this._ah, this._al, 0)
7557 writeInt64BE(this._bh, this._bl, 8)
7558 writeInt64BE(this._ch, this._cl, 16)
7559 writeInt64BE(this._dh, this._dl, 24)
7560 writeInt64BE(this._eh, this._el, 32)
7561 writeInt64BE(this._fh, this._fl, 40)
7562 writeInt64BE(this._gh, this._gl, 48)
7563 writeInt64BE(this._hh, this._hl, 56)
7564
7565 return H
7566 }
7567
7568 module.exports = Sha512
7569
7570 },{"./hash":52,"inherits":44,"safe-buffer":47}],60:[function(require,module,exports){
7571 var asn1 = exports;
7572
7573 asn1.bignum = require('bn.js');
7574
7575 asn1.define = require('./asn1/api').define;
7576 asn1.base = require('./asn1/base');
7577 asn1.constants = require('./asn1/constants');
7578 asn1.decoders = require('./asn1/decoders');
7579 asn1.encoders = require('./asn1/encoders');
7580
7581 },{"./asn1/api":61,"./asn1/base":63,"./asn1/constants":67,"./asn1/decoders":69,"./asn1/encoders":72,"bn.js":79}],61:[function(require,module,exports){
7582 var asn1 = require('../asn1');
7583 var inherits = require('inherits');
7584
7585 var api = exports;
7586
7587 api.define = function define(name, body) {
7588 return new Entity(name, body);
7589 };
7590
7591 function Entity(name, body) {
7592 this.name = name;
7593 this.body = body;
7594
7595 this.decoders = {};
7596 this.encoders = {};
7597 };
7598
7599 Entity.prototype._createNamed = function createNamed(base) {
7600 var named;
7601 try {
7602 named = require('vm').runInThisContext(
7603 '(function ' + this.name + '(entity) {\n' +
7604 ' this._initNamed(entity);\n' +
7605 '})'
7606 );
7607 } catch (e) {
7608 named = function (entity) {
7609 this._initNamed(entity);
7610 };
7611 }
7612 inherits(named, base);
7613 named.prototype._initNamed = function initnamed(entity) {
7614 base.call(this, entity);
7615 };
7616
7617 return new named(this);
7618 };
7619
7620 Entity.prototype._getDecoder = function _getDecoder(enc) {
7621 enc = enc || 'der';
7622 // Lazily create decoder
7623 if (!this.decoders.hasOwnProperty(enc))
7624 this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
7625 return this.decoders[enc];
7626 };
7627
7628 Entity.prototype.decode = function decode(data, enc, options) {
7629 return this._getDecoder(enc).decode(data, options);
7630 };
7631
7632 Entity.prototype._getEncoder = function _getEncoder(enc) {
7633 enc = enc || 'der';
7634 // Lazily create encoder
7635 if (!this.encoders.hasOwnProperty(enc))
7636 this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
7637 return this.encoders[enc];
7638 };
7639
7640 Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
7641 return this._getEncoder(enc).encode(data, reporter);
7642 };
7643
7644 },{"../asn1":60,"inherits":162,"vm":219}],62:[function(require,module,exports){
7645 var inherits = require('inherits');
7646 var Reporter = require('../base').Reporter;
7647 var Buffer = require('buffer').Buffer;
7648
7649 function DecoderBuffer(base, options) {
7650 Reporter.call(this, options);
7651 if (!Buffer.isBuffer(base)) {
7652 this.error('Input not Buffer');
7653 return;
7654 }
7655
7656 this.base = base;
7657 this.offset = 0;
7658 this.length = base.length;
7659 }
7660 inherits(DecoderBuffer, Reporter);
7661 exports.DecoderBuffer = DecoderBuffer;
7662
7663 DecoderBuffer.prototype.save = function save() {
7664 return { offset: this.offset, reporter: Reporter.prototype.save.call(this) };
7665 };
7666
7667 DecoderBuffer.prototype.restore = function restore(save) {
7668 // Return skipped data
7669 var res = new DecoderBuffer(this.base);
7670 res.offset = save.offset;
7671 res.length = this.offset;
7672
7673 this.offset = save.offset;
7674 Reporter.prototype.restore.call(this, save.reporter);
7675
7676 return res;
7677 };
7678
7679 DecoderBuffer.prototype.isEmpty = function isEmpty() {
7680 return this.offset === this.length;
7681 };
7682
7683 DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
7684 if (this.offset + 1 <= this.length)
7685 return this.base.readUInt8(this.offset++, true);
7686 else
7687 return this.error(fail || 'DecoderBuffer overrun');
7688 }
7689
7690 DecoderBuffer.prototype.skip = function skip(bytes, fail) {
7691 if (!(this.offset + bytes <= this.length))
7692 return this.error(fail || 'DecoderBuffer overrun');
7693
7694 var res = new DecoderBuffer(this.base);
7695
7696 // Share reporter state
7697 res._reporterState = this._reporterState;
7698
7699 res.offset = this.offset;
7700 res.length = this.offset + bytes;
7701 this.offset += bytes;
7702 return res;
7703 }
7704
7705 DecoderBuffer.prototype.raw = function raw(save) {
7706 return this.base.slice(save ? save.offset : this.offset, this.length);
7707 }
7708
7709 function EncoderBuffer(value, reporter) {
7710 if (Array.isArray(value)) {
7711 this.length = 0;
7712 this.value = value.map(function(item) {
7713 if (!(item instanceof EncoderBuffer))
7714 item = new EncoderBuffer(item, reporter);
7715 this.length += item.length;
7716 return item;
7717 }, this);
7718 } else if (typeof value === 'number') {
7719 if (!(0 <= value && value <= 0xff))
7720 return reporter.error('non-byte EncoderBuffer value');
7721 this.value = value;
7722 this.length = 1;
7723 } else if (typeof value === 'string') {
7724 this.value = value;
7725 this.length = Buffer.byteLength(value);
7726 } else if (Buffer.isBuffer(value)) {
7727 this.value = value;
7728 this.length = value.length;
7729 } else {
7730 return reporter.error('Unsupported type: ' + typeof value);
7731 }
7732 }
7733 exports.EncoderBuffer = EncoderBuffer;
7734
7735 EncoderBuffer.prototype.join = function join(out, offset) {
7736 if (!out)
7737 out = new Buffer(this.length);
7738 if (!offset)
7739 offset = 0;
7740
7741 if (this.length === 0)
7742 return out;
7743
7744 if (Array.isArray(this.value)) {
7745 this.value.forEach(function(item) {
7746 item.join(out, offset);
7747 offset += item.length;
7748 });
7749 } else {
7750 if (typeof this.value === 'number')
7751 out[offset] = this.value;
7752 else if (typeof this.value === 'string')
7753 out.write(this.value, offset);
7754 else if (Buffer.isBuffer(this.value))
7755 this.value.copy(out, offset);
7756 offset += this.length;
7757 }
7758
7759 return out;
7760 };
7761
7762 },{"../base":63,"buffer":110,"inherits":162}],63:[function(require,module,exports){
7763 var base = exports;
7764
7765 base.Reporter = require('./reporter').Reporter;
7766 base.DecoderBuffer = require('./buffer').DecoderBuffer;
7767 base.EncoderBuffer = require('./buffer').EncoderBuffer;
7768 base.Node = require('./node');
7769
7770 },{"./buffer":62,"./node":64,"./reporter":65}],64:[function(require,module,exports){
7771 var Reporter = require('../base').Reporter;
7772 var EncoderBuffer = require('../base').EncoderBuffer;
7773 var DecoderBuffer = require('../base').DecoderBuffer;
7774 var assert = require('minimalistic-assert');
7775
7776 // Supported tags
7777 var tags = [
7778 'seq', 'seqof', 'set', 'setof', 'objid', 'bool',
7779 'gentime', 'utctime', 'null_', 'enum', 'int', 'objDesc',
7780 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str',
7781 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr'
7782 ];
7783
7784 // Public methods list
7785 var methods = [
7786 'key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice',
7787 'any', 'contains'
7788 ].concat(tags);
7789
7790 // Overrided methods list
7791 var overrided = [
7792 '_peekTag', '_decodeTag', '_use',
7793 '_decodeStr', '_decodeObjid', '_decodeTime',
7794 '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList',
7795
7796 '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime',
7797 '_encodeNull', '_encodeInt', '_encodeBool'
7798 ];
7799
7800 function Node(enc, parent) {
7801 var state = {};
7802 this._baseState = state;
7803
7804 state.enc = enc;
7805
7806 state.parent = parent || null;
7807 state.children = null;
7808
7809 // State
7810 state.tag = null;
7811 state.args = null;
7812 state.reverseArgs = null;
7813 state.choice = null;
7814 state.optional = false;
7815 state.any = false;
7816 state.obj = false;
7817 state.use = null;
7818 state.useDecoder = null;
7819 state.key = null;
7820 state['default'] = null;
7821 state.explicit = null;
7822 state.implicit = null;
7823 state.contains = null;
7824
7825 // Should create new instance on each method
7826 if (!state.parent) {
7827 state.children = [];
7828 this._wrap();
7829 }
7830 }
7831 module.exports = Node;
7832
7833 var stateProps = [
7834 'enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice',
7835 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit',
7836 'implicit', 'contains'
7837 ];
7838
7839 Node.prototype.clone = function clone() {
7840 var state = this._baseState;
7841 var cstate = {};
7842 stateProps.forEach(function(prop) {
7843 cstate[prop] = state[prop];
7844 });
7845 var res = new this.constructor(cstate.parent);
7846 res._baseState = cstate;
7847 return res;
7848 };
7849
7850 Node.prototype._wrap = function wrap() {
7851 var state = this._baseState;
7852 methods.forEach(function(method) {
7853 this[method] = function _wrappedMethod() {
7854 var clone = new this.constructor(this);
7855 state.children.push(clone);
7856 return clone[method].apply(clone, arguments);
7857 };
7858 }, this);
7859 };
7860
7861 Node.prototype._init = function init(body) {
7862 var state = this._baseState;
7863
7864 assert(state.parent === null);
7865 body.call(this);
7866
7867 // Filter children
7868 state.children = state.children.filter(function(child) {
7869 return child._baseState.parent === this;
7870 }, this);
7871 assert.equal(state.children.length, 1, 'Root node can have only one child');
7872 };
7873
7874 Node.prototype._useArgs = function useArgs(args) {
7875 var state = this._baseState;
7876
7877 // Filter children and args
7878 var children = args.filter(function(arg) {
7879 return arg instanceof this.constructor;
7880 }, this);
7881 args = args.filter(function(arg) {
7882 return !(arg instanceof this.constructor);
7883 }, this);
7884
7885 if (children.length !== 0) {
7886 assert(state.children === null);
7887 state.children = children;
7888
7889 // Replace parent to maintain backward link
7890 children.forEach(function(child) {
7891 child._baseState.parent = this;
7892 }, this);
7893 }
7894 if (args.length !== 0) {
7895 assert(state.args === null);
7896 state.args = args;
7897 state.reverseArgs = args.map(function(arg) {
7898 if (typeof arg !== 'object' || arg.constructor !== Object)
7899 return arg;
7900
7901 var res = {};
7902 Object.keys(arg).forEach(function(key) {
7903 if (key == (key | 0))
7904 key |= 0;
7905 var value = arg[key];
7906 res[value] = key;
7907 });
7908 return res;
7909 });
7910 }
7911 };
7912
7913 //
7914 // Overrided methods
7915 //
7916
7917 overrided.forEach(function(method) {
7918 Node.prototype[method] = function _overrided() {
7919 var state = this._baseState;
7920 throw new Error(method + ' not implemented for encoding: ' + state.enc);
7921 };
7922 });
7923
7924 //
7925 // Public methods
7926 //
7927
7928 tags.forEach(function(tag) {
7929 Node.prototype[tag] = function _tagMethod() {
7930 var state = this._baseState;
7931 var args = Array.prototype.slice.call(arguments);
7932
7933 assert(state.tag === null);
7934 state.tag = tag;
7935
7936 this._useArgs(args);
7937
7938 return this;
7939 };
7940 });
7941
7942 Node.prototype.use = function use(item) {
7943 assert(item);
7944 var state = this._baseState;
7945
7946 assert(state.use === null);
7947 state.use = item;
7948
7949 return this;
7950 };
7951
7952 Node.prototype.optional = function optional() {
7953 var state = this._baseState;
7954
7955 state.optional = true;
7956
7957 return this;
7958 };
7959
7960 Node.prototype.def = function def(val) {
7961 var state = this._baseState;
7962
7963 assert(state['default'] === null);
7964 state['default'] = val;
7965 state.optional = true;
7966
7967 return this;
7968 };
7969
7970 Node.prototype.explicit = function explicit(num) {
7971 var state = this._baseState;
7972
7973 assert(state.explicit === null && state.implicit === null);
7974 state.explicit = num;
7975
7976 return this;
7977 };
7978
7979 Node.prototype.implicit = function implicit(num) {
7980 var state = this._baseState;
7981
7982 assert(state.explicit === null && state.implicit === null);
7983 state.implicit = num;
7984
7985 return this;
7986 };
7987
7988 Node.prototype.obj = function obj() {
7989 var state = this._baseState;
7990 var args = Array.prototype.slice.call(arguments);
7991
7992 state.obj = true;
7993
7994 if (args.length !== 0)
7995 this._useArgs(args);
7996
7997 return this;
7998 };
7999
8000 Node.prototype.key = function key(newKey) {
8001 var state = this._baseState;
8002
8003 assert(state.key === null);
8004 state.key = newKey;
8005
8006 return this;
8007 };
8008
8009 Node.prototype.any = function any() {
8010 var state = this._baseState;
8011
8012 state.any = true;
8013
8014 return this;
8015 };
8016
8017 Node.prototype.choice = function choice(obj) {
8018 var state = this._baseState;
8019
8020 assert(state.choice === null);
8021 state.choice = obj;
8022 this._useArgs(Object.keys(obj).map(function(key) {
8023 return obj[key];
8024 }));
8025
8026 return this;
8027 };
8028
8029 Node.prototype.contains = function contains(item) {
8030 var state = this._baseState;
8031
8032 assert(state.use === null);
8033 state.contains = item;
8034
8035 return this;
8036 };
8037
8038 //
8039 // Decoding
8040 //
8041
8042 Node.prototype._decode = function decode(input, options) {
8043 var state = this._baseState;
8044
8045 // Decode root node
8046 if (state.parent === null)
8047 return input.wrapResult(state.children[0]._decode(input, options));
8048
8049 var result = state['default'];
8050 var present = true;
8051
8052 var prevKey = null;
8053 if (state.key !== null)
8054 prevKey = input.enterKey(state.key);
8055
8056 // Check if tag is there
8057 if (state.optional) {
8058 var tag = null;
8059 if (state.explicit !== null)
8060 tag = state.explicit;
8061 else if (state.implicit !== null)
8062 tag = state.implicit;
8063 else if (state.tag !== null)
8064 tag = state.tag;
8065
8066 if (tag === null && !state.any) {
8067 // Trial and Error
8068 var save = input.save();
8069 try {
8070 if (state.choice === null)
8071 this._decodeGeneric(state.tag, input, options);
8072 else
8073 this._decodeChoice(input, options);
8074 present = true;
8075 } catch (e) {
8076 present = false;
8077 }
8078 input.restore(save);
8079 } else {
8080 present = this._peekTag(input, tag, state.any);
8081
8082 if (input.isError(present))
8083 return present;
8084 }
8085 }
8086
8087 // Push object on stack
8088 var prevObj;
8089 if (state.obj && present)
8090 prevObj = input.enterObject();
8091
8092 if (present) {
8093 // Unwrap explicit values
8094 if (state.explicit !== null) {
8095 var explicit = this._decodeTag(input, state.explicit);
8096 if (input.isError(explicit))
8097 return explicit;
8098 input = explicit;
8099 }
8100
8101 var start = input.offset;
8102
8103 // Unwrap implicit and normal values
8104 if (state.use === null && state.choice === null) {
8105 if (state.any)
8106 var save = input.save();
8107 var body = this._decodeTag(
8108 input,
8109 state.implicit !== null ? state.implicit : state.tag,
8110 state.any
8111 );
8112 if (input.isError(body))
8113 return body;
8114
8115 if (state.any)
8116 result = input.raw(save);
8117 else
8118 input = body;
8119 }
8120
8121 if (options && options.track && state.tag !== null)
8122 options.track(input.path(), start, input.length, 'tagged');
8123
8124 if (options && options.track && state.tag !== null)
8125 options.track(input.path(), input.offset, input.length, 'content');
8126
8127 // Select proper method for tag
8128 if (state.any)
8129 result = result;
8130 else if (state.choice === null)
8131 result = this._decodeGeneric(state.tag, input, options);
8132 else
8133 result = this._decodeChoice(input, options);
8134
8135 if (input.isError(result))
8136 return result;
8137
8138 // Decode children
8139 if (!state.any && state.choice === null && state.children !== null) {
8140 state.children.forEach(function decodeChildren(child) {
8141 // NOTE: We are ignoring errors here, to let parser continue with other
8142 // parts of encoded data
8143 child._decode(input, options);
8144 });
8145 }
8146
8147 // Decode contained/encoded by schema, only in bit or octet strings
8148 if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
8149 var data = new DecoderBuffer(result);
8150 result = this._getUse(state.contains, input._reporterState.obj)
8151 ._decode(data, options);
8152 }
8153 }
8154
8155 // Pop object
8156 if (state.obj && present)
8157 result = input.leaveObject(prevObj);
8158
8159 // Set key
8160 if (state.key !== null && (result !== null || present === true))
8161 input.leaveKey(prevKey, state.key, result);
8162 else if (prevKey !== null)
8163 input.exitKey(prevKey);
8164
8165 return result;
8166 };
8167
8168 Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) {
8169 var state = this._baseState;
8170
8171 if (tag === 'seq' || tag === 'set')
8172 return null;
8173 if (tag === 'seqof' || tag === 'setof')
8174 return this._decodeList(input, tag, state.args[0], options);
8175 else if (/str$/.test(tag))
8176 return this._decodeStr(input, tag, options);
8177 else if (tag === 'objid' && state.args)
8178 return this._decodeObjid(input, state.args[0], state.args[1], options);
8179 else if (tag === 'objid')
8180 return this._decodeObjid(input, null, null, options);
8181 else if (tag === 'gentime' || tag === 'utctime')
8182 return this._decodeTime(input, tag, options);
8183 else if (tag === 'null_')
8184 return this._decodeNull(input, options);
8185 else if (tag === 'bool')
8186 return this._decodeBool(input, options);
8187 else if (tag === 'objDesc')
8188 return this._decodeStr(input, tag, options);
8189 else if (tag === 'int' || tag === 'enum')
8190 return this._decodeInt(input, state.args && state.args[0], options);
8191
8192 if (state.use !== null) {
8193 return this._getUse(state.use, input._reporterState.obj)
8194 ._decode(input, options);
8195 } else {
8196 return input.error('unknown tag: ' + tag);
8197 }
8198 };
8199
8200 Node.prototype._getUse = function _getUse(entity, obj) {
8201
8202 var state = this._baseState;
8203 // Create altered use decoder if implicit is set
8204 state.useDecoder = this._use(entity, obj);
8205 assert(state.useDecoder._baseState.parent === null);
8206 state.useDecoder = state.useDecoder._baseState.children[0];
8207 if (state.implicit !== state.useDecoder._baseState.implicit) {
8208 state.useDecoder = state.useDecoder.clone();
8209 state.useDecoder._baseState.implicit = state.implicit;
8210 }
8211 return state.useDecoder;
8212 };
8213
8214 Node.prototype._decodeChoice = function decodeChoice(input, options) {
8215 var state = this._baseState;
8216 var result = null;
8217 var match = false;
8218
8219 Object.keys(state.choice).some(function(key) {
8220 var save = input.save();
8221 var node = state.choice[key];
8222 try {
8223 var value = node._decode(input, options);
8224 if (input.isError(value))
8225 return false;
8226
8227 result = { type: key, value: value };
8228 match = true;
8229 } catch (e) {
8230 input.restore(save);
8231 return false;
8232 }
8233 return true;
8234 }, this);
8235
8236 if (!match)
8237 return input.error('Choice not matched');
8238
8239 return result;
8240 };
8241
8242 //
8243 // Encoding
8244 //
8245
8246 Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
8247 return new EncoderBuffer(data, this.reporter);
8248 };
8249
8250 Node.prototype._encode = function encode(data, reporter, parent) {
8251 var state = this._baseState;
8252 if (state['default'] !== null && state['default'] === data)
8253 return;
8254
8255 var result = this._encodeValue(data, reporter, parent);
8256 if (result === undefined)
8257 return;
8258
8259 if (this._skipDefault(result, reporter, parent))
8260 return;
8261
8262 return result;
8263 };
8264
8265 Node.prototype._encodeValue = function encode(data, reporter, parent) {
8266 var state = this._baseState;
8267
8268 // Decode root node
8269 if (state.parent === null)
8270 return state.children[0]._encode(data, reporter || new Reporter());
8271
8272 var result = null;
8273
8274 // Set reporter to share it with a child class
8275 this.reporter = reporter;
8276
8277 // Check if data is there
8278 if (state.optional && data === undefined) {
8279 if (state['default'] !== null)
8280 data = state['default']
8281 else
8282 return;
8283 }
8284
8285 // Encode children first
8286 var content = null;
8287 var primitive = false;
8288 if (state.any) {
8289 // Anything that was given is translated to buffer
8290 result = this._createEncoderBuffer(data);
8291 } else if (state.choice) {
8292 result = this._encodeChoice(data, reporter);
8293 } else if (state.contains) {
8294 content = this._getUse(state.contains, parent)._encode(data, reporter);
8295 primitive = true;
8296 } else if (state.children) {
8297 content = state.children.map(function(child) {
8298 if (child._baseState.tag === 'null_')
8299 return child._encode(null, reporter, data);
8300
8301 if (child._baseState.key === null)
8302 return reporter.error('Child should have a key');
8303 var prevKey = reporter.enterKey(child._baseState.key);
8304
8305 if (typeof data !== 'object')
8306 return reporter.error('Child expected, but input is not object');
8307
8308 var res = child._encode(data[child._baseState.key], reporter, data);
8309 reporter.leaveKey(prevKey);
8310
8311 return res;
8312 }, this).filter(function(child) {
8313 return child;
8314 });
8315 content = this._createEncoderBuffer(content);
8316 } else {
8317 if (state.tag === 'seqof' || state.tag === 'setof') {
8318 // TODO(indutny): this should be thrown on DSL level
8319 if (!(state.args && state.args.length === 1))
8320 return reporter.error('Too many args for : ' + state.tag);
8321
8322 if (!Array.isArray(data))
8323 return reporter.error('seqof/setof, but data is not Array');
8324
8325 var child = this.clone();
8326 child._baseState.implicit = null;
8327 content = this._createEncoderBuffer(data.map(function(item) {
8328 var state = this._baseState;
8329
8330 return this._getUse(state.args[0], data)._encode(item, reporter);
8331 }, child));
8332 } else if (state.use !== null) {
8333 result = this._getUse(state.use, parent)._encode(data, reporter);
8334 } else {
8335 content = this._encodePrimitive(state.tag, data);
8336 primitive = true;
8337 }
8338 }
8339
8340 // Encode data itself
8341 var result;
8342 if (!state.any && state.choice === null) {
8343 var tag = state.implicit !== null ? state.implicit : state.tag;
8344 var cls = state.implicit === null ? 'universal' : 'context';
8345
8346 if (tag === null) {
8347 if (state.use === null)
8348 reporter.error('Tag could be omitted only for .use()');
8349 } else {
8350 if (state.use === null)
8351 result = this._encodeComposite(tag, primitive, cls, content);
8352 }
8353 }
8354
8355 // Wrap in explicit
8356 if (state.explicit !== null)
8357 result = this._encodeComposite(state.explicit, false, 'context', result);
8358
8359 return result;
8360 };
8361
8362 Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
8363 var state = this._baseState;
8364
8365 var node = state.choice[data.type];
8366 if (!node) {
8367 assert(
8368 false,
8369 data.type + ' not found in ' +
8370 JSON.stringify(Object.keys(state.choice)));
8371 }
8372 return node._encode(data.value, reporter);
8373 };
8374
8375 Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
8376 var state = this._baseState;
8377
8378 if (/str$/.test(tag))
8379 return this._encodeStr(data, tag);
8380 else if (tag === 'objid' && state.args)
8381 return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);
8382 else if (tag === 'objid')
8383 return this._encodeObjid(data, null, null);
8384 else if (tag === 'gentime' || tag === 'utctime')
8385 return this._encodeTime(data, tag);
8386 else if (tag === 'null_')
8387 return this._encodeNull();
8388 else if (tag === 'int' || tag === 'enum')
8389 return this._encodeInt(data, state.args && state.reverseArgs[0]);
8390 else if (tag === 'bool')
8391 return this._encodeBool(data);
8392 else if (tag === 'objDesc')
8393 return this._encodeStr(data, tag);
8394 else
8395 throw new Error('Unsupported tag: ' + tag);
8396 };
8397
8398 Node.prototype._isNumstr = function isNumstr(str) {
8399 return /^[0-9 ]*$/.test(str);
8400 };
8401
8402 Node.prototype._isPrintstr = function isPrintstr(str) {
8403 return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(str);
8404 };
8405
8406 },{"../base":63,"minimalistic-assert":167}],65:[function(require,module,exports){
8407 var inherits = require('inherits');
8408
8409 function Reporter(options) {
8410 this._reporterState = {
8411 obj: null,
8412 path: [],
8413 options: options || {},
8414 errors: []
8415 };
8416 }
8417 exports.Reporter = Reporter;
8418
8419 Reporter.prototype.isError = function isError(obj) {
8420 return obj instanceof ReporterError;
8421 };
8422
8423 Reporter.prototype.save = function save() {
8424 var state = this._reporterState;
8425
8426 return { obj: state.obj, pathLen: state.path.length };
8427 };
8428
8429 Reporter.prototype.restore = function restore(data) {
8430 var state = this._reporterState;
8431
8432 state.obj = data.obj;
8433 state.path = state.path.slice(0, data.pathLen);
8434 };
8435
8436 Reporter.prototype.enterKey = function enterKey(key) {
8437 return this._reporterState.path.push(key);
8438 };
8439
8440 Reporter.prototype.exitKey = function exitKey(index) {
8441 var state = this._reporterState;
8442
8443 state.path = state.path.slice(0, index - 1);
8444 };
8445
8446 Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
8447 var state = this._reporterState;
8448
8449 this.exitKey(index);
8450 if (state.obj !== null)
8451 state.obj[key] = value;
8452 };
8453
8454 Reporter.prototype.path = function path() {
8455 return this._reporterState.path.join('/');
8456 };
8457
8458 Reporter.prototype.enterObject = function enterObject() {
8459 var state = this._reporterState;
8460
8461 var prev = state.obj;
8462 state.obj = {};
8463 return prev;
8464 };
8465
8466 Reporter.prototype.leaveObject = function leaveObject(prev) {
8467 var state = this._reporterState;
8468
8469 var now = state.obj;
8470 state.obj = prev;
8471 return now;
8472 };
8473
8474 Reporter.prototype.error = function error(msg) {
8475 var err;
8476 var state = this._reporterState;
8477
8478 var inherited = msg instanceof ReporterError;
8479 if (inherited) {
8480 err = msg;
8481 } else {
8482 err = new ReporterError(state.path.map(function(elem) {
8483 return '[' + JSON.stringify(elem) + ']';
8484 }).join(''), msg.message || msg, msg.stack);
8485 }
8486
8487 if (!state.options.partial)
8488 throw err;
8489
8490 if (!inherited)
8491 state.errors.push(err);
8492
8493 return err;
8494 };
8495
8496 Reporter.prototype.wrapResult = function wrapResult(result) {
8497 var state = this._reporterState;
8498 if (!state.options.partial)
8499 return result;
8500
8501 return {
8502 result: this.isError(result) ? null : result,
8503 errors: state.errors
8504 };
8505 };
8506
8507 function ReporterError(path, msg) {
8508 this.path = path;
8509 this.rethrow(msg);
8510 };
8511 inherits(ReporterError, Error);
8512
8513 ReporterError.prototype.rethrow = function rethrow(msg) {
8514 this.message = msg + ' at: ' + (this.path || '(shallow)');
8515 if (Error.captureStackTrace)
8516 Error.captureStackTrace(this, ReporterError);
8517
8518 if (!this.stack) {
8519 try {
8520 // IE only adds stack when thrown
8521 throw new Error(this.message);
8522 } catch (e) {
8523 this.stack = e.stack;
8524 }
8525 }
8526 return this;
8527 };
8528
8529 },{"inherits":162}],66:[function(require,module,exports){
8530 var constants = require('../constants');
8531
8532 exports.tagClass = {
8533 0: 'universal',
8534 1: 'application',
8535 2: 'context',
8536 3: 'private'
8537 };
8538 exports.tagClassByName = constants._reverse(exports.tagClass);
8539
8540 exports.tag = {
8541 0x00: 'end',
8542 0x01: 'bool',
8543 0x02: 'int',
8544 0x03: 'bitstr',
8545 0x04: 'octstr',
8546 0x05: 'null_',
8547 0x06: 'objid',
8548 0x07: 'objDesc',
8549 0x08: 'external',
8550 0x09: 'real',
8551 0x0a: 'enum',
8552 0x0b: 'embed',
8553 0x0c: 'utf8str',
8554 0x0d: 'relativeOid',
8555 0x10: 'seq',
8556 0x11: 'set',
8557 0x12: 'numstr',
8558 0x13: 'printstr',
8559 0x14: 't61str',
8560 0x15: 'videostr',
8561 0x16: 'ia5str',
8562 0x17: 'utctime',
8563 0x18: 'gentime',
8564 0x19: 'graphstr',
8565 0x1a: 'iso646str',
8566 0x1b: 'genstr',
8567 0x1c: 'unistr',
8568 0x1d: 'charstr',
8569 0x1e: 'bmpstr'
8570 };
8571 exports.tagByName = constants._reverse(exports.tag);
8572
8573 },{"../constants":67}],67:[function(require,module,exports){
8574 var constants = exports;
8575
8576 // Helper
8577 constants._reverse = function reverse(map) {
8578 var res = {};
8579
8580 Object.keys(map).forEach(function(key) {
8581 // Convert key to integer if it is stringified
8582 if ((key | 0) == key)
8583 key = key | 0;
8584
8585 var value = map[key];
8586 res[value] = key;
8587 });
8588
8589 return res;
8590 };
8591
8592 constants.der = require('./der');
8593
8594 },{"./der":66}],68:[function(require,module,exports){
8595 var inherits = require('inherits');
8596
8597 var asn1 = require('../../asn1');
8598 var base = asn1.base;
8599 var bignum = asn1.bignum;
8600
8601 // Import DER constants
8602 var der = asn1.constants.der;
8603
8604 function DERDecoder(entity) {
8605 this.enc = 'der';
8606 this.name = entity.name;
8607 this.entity = entity;
8608
8609 // Construct base tree
8610 this.tree = new DERNode();
8611 this.tree._init(entity.body);
8612 };
8613 module.exports = DERDecoder;
8614
8615 DERDecoder.prototype.decode = function decode(data, options) {
8616 if (!(data instanceof base.DecoderBuffer))
8617 data = new base.DecoderBuffer(data, options);
8618
8619 return this.tree._decode(data, options);
8620 };
8621
8622 // Tree methods
8623
8624 function DERNode(parent) {
8625 base.Node.call(this, 'der', parent);
8626 }
8627 inherits(DERNode, base.Node);
8628
8629 DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
8630 if (buffer.isEmpty())
8631 return false;
8632
8633 var state = buffer.save();
8634 var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
8635 if (buffer.isError(decodedTag))
8636 return decodedTag;
8637
8638 buffer.restore(state);
8639
8640 return decodedTag.tag === tag || decodedTag.tagStr === tag ||
8641 (decodedTag.tagStr + 'of') === tag || any;
8642 };
8643
8644 DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
8645 var decodedTag = derDecodeTag(buffer,
8646 'Failed to decode tag of "' + tag + '"');
8647 if (buffer.isError(decodedTag))
8648 return decodedTag;
8649
8650 var len = derDecodeLen(buffer,
8651 decodedTag.primitive,
8652 'Failed to get length of "' + tag + '"');
8653
8654 // Failure
8655 if (buffer.isError(len))
8656 return len;
8657
8658 if (!any &&
8659 decodedTag.tag !== tag &&
8660 decodedTag.tagStr !== tag &&
8661 decodedTag.tagStr + 'of' !== tag) {
8662 return buffer.error('Failed to match tag: "' + tag + '"');
8663 }
8664
8665 if (decodedTag.primitive || len !== null)
8666 return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
8667
8668 // Indefinite length... find END tag
8669 var state = buffer.save();
8670 var res = this._skipUntilEnd(
8671 buffer,
8672 'Failed to skip indefinite length body: "' + this.tag + '"');
8673 if (buffer.isError(res))
8674 return res;
8675
8676 len = buffer.offset - state.offset;
8677 buffer.restore(state);
8678 return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
8679 };
8680
8681 DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
8682 while (true) {
8683 var tag = derDecodeTag(buffer, fail);
8684 if (buffer.isError(tag))
8685 return tag;
8686 var len = derDecodeLen(buffer, tag.primitive, fail);
8687 if (buffer.isError(len))
8688 return len;
8689
8690 var res;
8691 if (tag.primitive || len !== null)
8692 res = buffer.skip(len)
8693 else
8694 res = this._skipUntilEnd(buffer, fail);
8695
8696 // Failure
8697 if (buffer.isError(res))
8698 return res;
8699
8700 if (tag.tagStr === 'end')
8701 break;
8702 }
8703 };
8704
8705 DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder,
8706 options) {
8707 var result = [];
8708 while (!buffer.isEmpty()) {
8709 var possibleEnd = this._peekTag(buffer, 'end');
8710 if (buffer.isError(possibleEnd))
8711 return possibleEnd;
8712
8713 var res = decoder.decode(buffer, 'der', options);
8714 if (buffer.isError(res) && possibleEnd)
8715 break;
8716 result.push(res);
8717 }
8718 return result;
8719 };
8720
8721 DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
8722 if (tag === 'bitstr') {
8723 var unused = buffer.readUInt8();
8724 if (buffer.isError(unused))
8725 return unused;
8726 return { unused: unused, data: buffer.raw() };
8727 } else if (tag === 'bmpstr') {
8728 var raw = buffer.raw();
8729 if (raw.length % 2 === 1)
8730 return buffer.error('Decoding of string type: bmpstr length mismatch');
8731
8732 var str = '';
8733 for (var i = 0; i < raw.length / 2; i++) {
8734 str += String.fromCharCode(raw.readUInt16BE(i * 2));
8735 }
8736 return str;
8737 } else if (tag === 'numstr') {
8738 var numstr = buffer.raw().toString('ascii');
8739 if (!this._isNumstr(numstr)) {
8740 return buffer.error('Decoding of string type: ' +
8741 'numstr unsupported characters');
8742 }
8743 return numstr;
8744 } else if (tag === 'octstr') {
8745 return buffer.raw();
8746 } else if (tag === 'objDesc') {
8747 return buffer.raw();
8748 } else if (tag === 'printstr') {
8749 var printstr = buffer.raw().toString('ascii');
8750 if (!this._isPrintstr(printstr)) {
8751 return buffer.error('Decoding of string type: ' +
8752 'printstr unsupported characters');
8753 }
8754 return printstr;
8755 } else if (/str$/.test(tag)) {
8756 return buffer.raw().toString();
8757 } else {
8758 return buffer.error('Decoding of string type: ' + tag + ' unsupported');
8759 }
8760 };
8761
8762 DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
8763 var result;
8764 var identifiers = [];
8765 var ident = 0;
8766 while (!buffer.isEmpty()) {
8767 var subident = buffer.readUInt8();
8768 ident <<= 7;
8769 ident |= subident & 0x7f;
8770 if ((subident & 0x80) === 0) {
8771 identifiers.push(ident);
8772 ident = 0;
8773 }
8774 }
8775 if (subident & 0x80)
8776 identifiers.push(ident);
8777
8778 var first = (identifiers[0] / 40) | 0;
8779 var second = identifiers[0] % 40;
8780
8781 if (relative)
8782 result = identifiers;
8783 else
8784 result = [first, second].concat(identifiers.slice(1));
8785
8786 if (values) {
8787 var tmp = values[result.join(' ')];
8788 if (tmp === undefined)
8789 tmp = values[result.join('.')];
8790 if (tmp !== undefined)
8791 result = tmp;
8792 }
8793
8794 return result;
8795 };
8796
8797 DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
8798 var str = buffer.raw().toString();
8799 if (tag === 'gentime') {
8800 var year = str.slice(0, 4) | 0;
8801 var mon = str.slice(4, 6) | 0;
8802 var day = str.slice(6, 8) | 0;
8803 var hour = str.slice(8, 10) | 0;
8804 var min = str.slice(10, 12) | 0;
8805 var sec = str.slice(12, 14) | 0;
8806 } else if (tag === 'utctime') {
8807 var year = str.slice(0, 2) | 0;
8808 var mon = str.slice(2, 4) | 0;
8809 var day = str.slice(4, 6) | 0;
8810 var hour = str.slice(6, 8) | 0;
8811 var min = str.slice(8, 10) | 0;
8812 var sec = str.slice(10, 12) | 0;
8813 if (year < 70)
8814 year = 2000 + year;
8815 else
8816 year = 1900 + year;
8817 } else {
8818 return buffer.error('Decoding ' + tag + ' time is not supported yet');
8819 }
8820
8821 return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
8822 };
8823
8824 DERNode.prototype._decodeNull = function decodeNull(buffer) {
8825 return null;
8826 };
8827
8828 DERNode.prototype._decodeBool = function decodeBool(buffer) {
8829 var res = buffer.readUInt8();
8830 if (buffer.isError(res))
8831 return res;
8832 else
8833 return res !== 0;
8834 };
8835
8836 DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
8837 // Bigint, return as it is (assume big endian)
8838 var raw = buffer.raw();
8839 var res = new bignum(raw);
8840
8841 if (values)
8842 res = values[res.toString(10)] || res;
8843
8844 return res;
8845 };
8846
8847 DERNode.prototype._use = function use(entity, obj) {
8848 if (typeof entity === 'function')
8849 entity = entity(obj);
8850 return entity._getDecoder('der').tree;
8851 };
8852
8853 // Utility methods
8854
8855 function derDecodeTag(buf, fail) {
8856 var tag = buf.readUInt8(fail);
8857 if (buf.isError(tag))
8858 return tag;
8859
8860 var cls = der.tagClass[tag >> 6];
8861 var primitive = (tag & 0x20) === 0;
8862
8863 // Multi-octet tag - load
8864 if ((tag & 0x1f) === 0x1f) {
8865 var oct = tag;
8866 tag = 0;
8867 while ((oct & 0x80) === 0x80) {
8868 oct = buf.readUInt8(fail);
8869 if (buf.isError(oct))
8870 return oct;
8871
8872 tag <<= 7;
8873 tag |= oct & 0x7f;
8874 }
8875 } else {
8876 tag &= 0x1f;
8877 }
8878 var tagStr = der.tag[tag];
8879
8880 return {
8881 cls: cls,
8882 primitive: primitive,
8883 tag: tag,
8884 tagStr: tagStr
8885 };
8886 }
8887
8888 function derDecodeLen(buf, primitive, fail) {
8889 var len = buf.readUInt8(fail);
8890 if (buf.isError(len))
8891 return len;
8892
8893 // Indefinite form
8894 if (!primitive && len === 0x80)
8895 return null;
8896
8897 // Definite form
8898 if ((len & 0x80) === 0) {
8899 // Short form
8900 return len;
8901 }
8902
8903 // Long form
8904 var num = len & 0x7f;
8905 if (num > 4)
8906 return buf.error('length octect is too long');
8907
8908 len = 0;
8909 for (var i = 0; i < num; i++) {
8910 len <<= 8;
8911 var j = buf.readUInt8(fail);
8912 if (buf.isError(j))
8913 return j;
8914 len |= j;
8915 }
8916
8917 return len;
8918 }
8919
8920 },{"../../asn1":60,"inherits":162}],69:[function(require,module,exports){
8921 var decoders = exports;
8922
8923 decoders.der = require('./der');
8924 decoders.pem = require('./pem');
8925
8926 },{"./der":68,"./pem":70}],70:[function(require,module,exports){
8927 var inherits = require('inherits');
8928 var Buffer = require('buffer').Buffer;
8929
8930 var DERDecoder = require('./der');
8931
8932 function PEMDecoder(entity) {
8933 DERDecoder.call(this, entity);
8934 this.enc = 'pem';
8935 };
8936 inherits(PEMDecoder, DERDecoder);
8937 module.exports = PEMDecoder;
8938
8939 PEMDecoder.prototype.decode = function decode(data, options) {
8940 var lines = data.toString().split(/[\r\n]+/g);
8941
8942 var label = options.label.toUpperCase();
8943
8944 var re = /^-----(BEGIN|END) ([^-]+)-----$/;
8945 var start = -1;
8946 var end = -1;
8947 for (var i = 0; i < lines.length; i++) {
8948 var match = lines[i].match(re);
8949 if (match === null)
8950 continue;
8951
8952 if (match[2] !== label)
8953 continue;
8954
8955 if (start === -1) {
8956 if (match[1] !== 'BEGIN')
8957 break;
8958 start = i;
8959 } else {
8960 if (match[1] !== 'END')
8961 break;
8962 end = i;
8963 break;
8964 }
8965 }
8966 if (start === -1 || end === -1)
8967 throw new Error('PEM section not found for: ' + label);
8968
8969 var base64 = lines.slice(start + 1, end).join('');
8970 // Remove excessive symbols
8971 base64.replace(/[^a-z0-9\+\/=]+/gi, '');
8972
8973 var input = new Buffer(base64, 'base64');
8974 return DERDecoder.prototype.decode.call(this, input, options);
8975 };
8976
8977 },{"./der":68,"buffer":110,"inherits":162}],71:[function(require,module,exports){
8978 var inherits = require('inherits');
8979 var Buffer = require('buffer').Buffer;
8980
8981 var asn1 = require('../../asn1');
8982 var base = asn1.base;
8983
8984 // Import DER constants
8985 var der = asn1.constants.der;
8986
8987 function DEREncoder(entity) {
8988 this.enc = 'der';
8989 this.name = entity.name;
8990 this.entity = entity;
8991
8992 // Construct base tree
8993 this.tree = new DERNode();
8994 this.tree._init(entity.body);
8995 };
8996 module.exports = DEREncoder;
8997
8998 DEREncoder.prototype.encode = function encode(data, reporter) {
8999 return this.tree._encode(data, reporter).join();
9000 };
9001
9002 // Tree methods
9003
9004 function DERNode(parent) {
9005 base.Node.call(this, 'der', parent);
9006 }
9007 inherits(DERNode, base.Node);
9008
9009 DERNode.prototype._encodeComposite = function encodeComposite(tag,
9010 primitive,
9011 cls,
9012 content) {
9013 var encodedTag = encodeTag(tag, primitive, cls, this.reporter);
9014
9015 // Short form
9016 if (content.length < 0x80) {
9017 var header = new Buffer(2);
9018 header[0] = encodedTag;
9019 header[1] = content.length;
9020 return this._createEncoderBuffer([ header, content ]);
9021 }
9022
9023 // Long form
9024 // Count octets required to store length
9025 var lenOctets = 1;
9026 for (var i = content.length; i >= 0x100; i >>= 8)
9027 lenOctets++;
9028
9029 var header = new Buffer(1 + 1 + lenOctets);
9030 header[0] = encodedTag;
9031 header[1] = 0x80 | lenOctets;
9032
9033 for (var i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8)
9034 header[i] = j & 0xff;
9035
9036 return this._createEncoderBuffer([ header, content ]);
9037 };
9038
9039 DERNode.prototype._encodeStr = function encodeStr(str, tag) {
9040 if (tag === 'bitstr') {
9041 return this._createEncoderBuffer([ str.unused | 0, str.data ]);
9042 } else if (tag === 'bmpstr') {
9043 var buf = new Buffer(str.length * 2);
9044 for (var i = 0; i < str.length; i++) {
9045 buf.writeUInt16BE(str.charCodeAt(i), i * 2);
9046 }
9047 return this._createEncoderBuffer(buf);
9048 } else if (tag === 'numstr') {
9049 if (!this._isNumstr(str)) {
9050 return this.reporter.error('Encoding of string type: numstr supports ' +
9051 'only digits and space');
9052 }
9053 return this._createEncoderBuffer(str);
9054 } else if (tag === 'printstr') {
9055 if (!this._isPrintstr(str)) {
9056 return this.reporter.error('Encoding of string type: printstr supports ' +
9057 'only latin upper and lower case letters, ' +
9058 'digits, space, apostrophe, left and rigth ' +
9059 'parenthesis, plus sign, comma, hyphen, ' +
9060 'dot, slash, colon, equal sign, ' +
9061 'question mark');
9062 }
9063 return this._createEncoderBuffer(str);
9064 } else if (/str$/.test(tag)) {
9065 return this._createEncoderBuffer(str);
9066 } else if (tag === 'objDesc') {
9067 return this._createEncoderBuffer(str);
9068 } else {
9069 return this.reporter.error('Encoding of string type: ' + tag +
9070 ' unsupported');
9071 }
9072 };
9073
9074 DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
9075 if (typeof id === 'string') {
9076 if (!values)
9077 return this.reporter.error('string objid given, but no values map found');
9078 if (!values.hasOwnProperty(id))
9079 return this.reporter.error('objid not found in values map');
9080 id = values[id].split(/[\s\.]+/g);
9081 for (var i = 0; i < id.length; i++)
9082 id[i] |= 0;
9083 } else if (Array.isArray(id)) {
9084 id = id.slice();
9085 for (var i = 0; i < id.length; i++)
9086 id[i] |= 0;
9087 }
9088
9089 if (!Array.isArray(id)) {
9090 return this.reporter.error('objid() should be either array or string, ' +
9091 'got: ' + JSON.stringify(id));
9092 }
9093
9094 if (!relative) {
9095 if (id[1] >= 40)
9096 return this.reporter.error('Second objid identifier OOB');
9097 id.splice(0, 2, id[0] * 40 + id[1]);
9098 }
9099
9100 // Count number of octets
9101 var size = 0;
9102 for (var i = 0; i < id.length; i++) {
9103 var ident = id[i];
9104 for (size++; ident >= 0x80; ident >>= 7)
9105 size++;
9106 }
9107
9108 var objid = new Buffer(size);
9109 var offset = objid.length - 1;
9110 for (var i = id.length - 1; i >= 0; i--) {
9111 var ident = id[i];
9112 objid[offset--] = ident & 0x7f;
9113 while ((ident >>= 7) > 0)
9114 objid[offset--] = 0x80 | (ident & 0x7f);
9115 }
9116
9117 return this._createEncoderBuffer(objid);
9118 };
9119
9120 function two(num) {
9121 if (num < 10)
9122 return '0' + num;
9123 else
9124 return num;
9125 }
9126
9127 DERNode.prototype._encodeTime = function encodeTime(time, tag) {
9128 var str;
9129 var date = new Date(time);
9130
9131 if (tag === 'gentime') {
9132 str = [
9133 two(date.getFullYear()),
9134 two(date.getUTCMonth() + 1),
9135 two(date.getUTCDate()),
9136 two(date.getUTCHours()),
9137 two(date.getUTCMinutes()),
9138 two(date.getUTCSeconds()),
9139 'Z'
9140 ].join('');
9141 } else if (tag === 'utctime') {
9142 str = [
9143 two(date.getFullYear() % 100),
9144 two(date.getUTCMonth() + 1),
9145 two(date.getUTCDate()),
9146 two(date.getUTCHours()),
9147 two(date.getUTCMinutes()),
9148 two(date.getUTCSeconds()),
9149 'Z'
9150 ].join('');
9151 } else {
9152 this.reporter.error('Encoding ' + tag + ' time is not supported yet');
9153 }
9154
9155 return this._encodeStr(str, 'octstr');
9156 };
9157
9158 DERNode.prototype._encodeNull = function encodeNull() {
9159 return this._createEncoderBuffer('');
9160 };
9161
9162 DERNode.prototype._encodeInt = function encodeInt(num, values) {
9163 if (typeof num === 'string') {
9164 if (!values)
9165 return this.reporter.error('String int or enum given, but no values map');
9166 if (!values.hasOwnProperty(num)) {
9167 return this.reporter.error('Values map doesn\'t contain: ' +
9168 JSON.stringify(num));
9169 }
9170 num = values[num];
9171 }
9172
9173 // Bignum, assume big endian
9174 if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
9175 var numArray = num.toArray();
9176 if (!num.sign && numArray[0] & 0x80) {
9177 numArray.unshift(0);
9178 }
9179 num = new Buffer(numArray);
9180 }
9181
9182 if (Buffer.isBuffer(num)) {
9183 var size = num.length;
9184 if (num.length === 0)
9185 size++;
9186
9187 var out = new Buffer(size);
9188 num.copy(out);
9189 if (num.length === 0)
9190 out[0] = 0
9191 return this._createEncoderBuffer(out);
9192 }
9193
9194 if (num < 0x80)
9195 return this._createEncoderBuffer(num);
9196
9197 if (num < 0x100)
9198 return this._createEncoderBuffer([0, num]);
9199
9200 var size = 1;
9201 for (var i = num; i >= 0x100; i >>= 8)
9202 size++;
9203
9204 var out = new Array(size);
9205 for (var i = out.length - 1; i >= 0; i--) {
9206 out[i] = num & 0xff;
9207 num >>= 8;
9208 }
9209 if(out[0] & 0x80) {
9210 out.unshift(0);
9211 }
9212
9213 return this._createEncoderBuffer(new Buffer(out));
9214 };
9215
9216 DERNode.prototype._encodeBool = function encodeBool(value) {
9217 return this._createEncoderBuffer(value ? 0xff : 0);
9218 };
9219
9220 DERNode.prototype._use = function use(entity, obj) {
9221 if (typeof entity === 'function')
9222 entity = entity(obj);
9223 return entity._getEncoder('der').tree;
9224 };
9225
9226 DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
9227 var state = this._baseState;
9228 var i;
9229 if (state['default'] === null)
9230 return false;
9231
9232 var data = dataBuffer.join();
9233 if (state.defaultBuffer === undefined)
9234 state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
9235
9236 if (data.length !== state.defaultBuffer.length)
9237 return false;
9238
9239 for (i=0; i < data.length; i++)
9240 if (data[i] !== state.defaultBuffer[i])
9241 return false;
9242
9243 return true;
9244 };
9245
9246 // Utility methods
9247
9248 function encodeTag(tag, primitive, cls, reporter) {
9249 var res;
9250
9251 if (tag === 'seqof')
9252 tag = 'seq';
9253 else if (tag === 'setof')
9254 tag = 'set';
9255
9256 if (der.tagByName.hasOwnProperty(tag))
9257 res = der.tagByName[tag];
9258 else if (typeof tag === 'number' && (tag | 0) === tag)
9259 res = tag;
9260 else
9261 return reporter.error('Unknown tag: ' + tag);
9262
9263 if (res >= 0x1f)
9264 return reporter.error('Multi-octet tag encoding unsupported');
9265
9266 if (!primitive)
9267 res |= 0x20;
9268
9269 res |= (der.tagClassByName[cls || 'universal'] << 6);
9270
9271 return res;
9272 }
9273
9274 },{"../../asn1":60,"buffer":110,"inherits":162}],72:[function(require,module,exports){
9275 var encoders = exports;
9276
9277 encoders.der = require('./der');
9278 encoders.pem = require('./pem');
9279
9280 },{"./der":71,"./pem":73}],73:[function(require,module,exports){
9281 var inherits = require('inherits');
9282
9283 var DEREncoder = require('./der');
9284
9285 function PEMEncoder(entity) {
9286 DEREncoder.call(this, entity);
9287 this.enc = 'pem';
9288 };
9289 inherits(PEMEncoder, DEREncoder);
9290 module.exports = PEMEncoder;
9291
9292 PEMEncoder.prototype.encode = function encode(data, options) {
9293 var buf = DEREncoder.prototype.encode.call(this, data);
9294
9295 var p = buf.toString('base64');
9296 var out = [ '-----BEGIN ' + options.label + '-----' ];
9297 for (var i = 0; i < p.length; i += 64)
9298 out.push(p.slice(i, i + 64));
9299 out.push('-----END ' + options.label + '-----');
9300 return out.join('\n');
9301 };
9302
9303 },{"./der":71,"inherits":162}],74:[function(require,module,exports){
9304 (function (global){
9305 'use strict';
9306
9307 var objectAssign = require('object-assign');
9308
9309 // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
9310 // original notice:
9311
9312 /*!
9313 * The buffer module from node.js, for the browser.
9314 *
9315 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
9316 * @license MIT
9317 */
9318 function compare(a, b) {
9319 if (a === b) {
9320 return 0;
9321 }
9322
9323 var x = a.length;
9324 var y = b.length;
9325
9326 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
9327 if (a[i] !== b[i]) {
9328 x = a[i];
9329 y = b[i];
9330 break;
9331 }
9332 }
9333
9334 if (x < y) {
9335 return -1;
9336 }
9337 if (y < x) {
9338 return 1;
9339 }
9340 return 0;
9341 }
9342 function isBuffer(b) {
9343 if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
9344 return global.Buffer.isBuffer(b);
9345 }
9346 return !!(b != null && b._isBuffer);
9347 }
9348
9349 // based on node assert, original notice:
9350 // NB: The URL to the CommonJS spec is kept just for tradition.
9351 // node-assert has evolved a lot since then, both in API and behavior.
9352
9353 // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
9354 //
9355 // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
9356 //
9357 // Originally from narwhal.js (http://narwhaljs.org)
9358 // Copyright (c) 2009 Thomas Robinson <280north.com>
9359 //
9360 // Permission is hereby granted, free of charge, to any person obtaining a copy
9361 // of this software and associated documentation files (the 'Software'), to
9362 // deal in the Software without restriction, including without limitation the
9363 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9364 // sell copies of the Software, and to permit persons to whom the Software is
9365 // furnished to do so, subject to the following conditions:
9366 //
9367 // The above copyright notice and this permission notice shall be included in
9368 // all copies or substantial portions of the Software.
9369 //
9370 // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9371 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9372 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9373 // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
9374 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
9375 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9376
9377 var util = require('util/');
9378 var hasOwn = Object.prototype.hasOwnProperty;
9379 var pSlice = Array.prototype.slice;
9380 var functionsHaveNames = (function () {
9381 return function foo() {}.name === 'foo';
9382 }());
9383 function pToString (obj) {
9384 return Object.prototype.toString.call(obj);
9385 }
9386 function isView(arrbuf) {
9387 if (isBuffer(arrbuf)) {
9388 return false;
9389 }
9390 if (typeof global.ArrayBuffer !== 'function') {
9391 return false;
9392 }
9393 if (typeof ArrayBuffer.isView === 'function') {
9394 return ArrayBuffer.isView(arrbuf);
9395 }
9396 if (!arrbuf) {
9397 return false;
9398 }
9399 if (arrbuf instanceof DataView) {
9400 return true;
9401 }
9402 if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
9403 return true;
9404 }
9405 return false;
9406 }
9407 // 1. The assert module provides functions that throw
9408 // AssertionError's when particular conditions are not met. The
9409 // assert module must conform to the following interface.
9410
9411 var assert = module.exports = ok;
9412
9413 // 2. The AssertionError is defined in assert.
9414 // new assert.AssertionError({ message: message,
9415 // actual: actual,
9416 // expected: expected })
9417
9418 var regex = /\s*function\s+([^\(\s]*)\s*/;
9419 // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
9420 function getName(func) {
9421 if (!util.isFunction(func)) {
9422 return;
9423 }
9424 if (functionsHaveNames) {
9425 return func.name;
9426 }
9427 var str = func.toString();
9428 var match = str.match(regex);
9429 return match && match[1];
9430 }
9431 assert.AssertionError = function AssertionError(options) {
9432 this.name = 'AssertionError';
9433 this.actual = options.actual;
9434 this.expected = options.expected;
9435 this.operator = options.operator;
9436 if (options.message) {
9437 this.message = options.message;
9438 this.generatedMessage = false;
9439 } else {
9440 this.message = getMessage(this);
9441 this.generatedMessage = true;
9442 }
9443 var stackStartFunction = options.stackStartFunction || fail;
9444 if (Error.captureStackTrace) {
9445 Error.captureStackTrace(this, stackStartFunction);
9446 } else {
9447 // non v8 browsers so we can have a stacktrace
9448 var err = new Error();
9449 if (err.stack) {
9450 var out = err.stack;
9451
9452 // try to strip useless frames
9453 var fn_name = getName(stackStartFunction);
9454 var idx = out.indexOf('\n' + fn_name);
9455 if (idx >= 0) {
9456 // once we have located the function frame
9457 // we need to strip out everything before it (and its line)
9458 var next_line = out.indexOf('\n', idx + 1);
9459 out = out.substring(next_line + 1);
9460 }
9461
9462 this.stack = out;
9463 }
9464 }
9465 };
9466
9467 // assert.AssertionError instanceof Error
9468 util.inherits(assert.AssertionError, Error);
9469
9470 function truncate(s, n) {
9471 if (typeof s === 'string') {
9472 return s.length < n ? s : s.slice(0, n);
9473 } else {
9474 return s;
9475 }
9476 }
9477 function inspect(something) {
9478 if (functionsHaveNames || !util.isFunction(something)) {
9479 return util.inspect(something);
9480 }
9481 var rawname = getName(something);
9482 var name = rawname ? ': ' + rawname : '';
9483 return '[Function' + name + ']';
9484 }
9485 function getMessage(self) {
9486 return truncate(inspect(self.actual), 128) + ' ' +
9487 self.operator + ' ' +
9488 truncate(inspect(self.expected), 128);
9489 }
9490
9491 // At present only the three keys mentioned above are used and
9492 // understood by the spec. Implementations or sub modules can pass
9493 // other keys to the AssertionError's constructor - they will be
9494 // ignored.
9495
9496 // 3. All of the following functions must throw an AssertionError
9497 // when a corresponding condition is not met, with a message that
9498 // may be undefined if not provided. All assertion methods provide
9499 // both the actual and expected values to the assertion error for
9500 // display purposes.
9501
9502 function fail(actual, expected, message, operator, stackStartFunction) {
9503 throw new assert.AssertionError({
9504 message: message,
9505 actual: actual,
9506 expected: expected,
9507 operator: operator,
9508 stackStartFunction: stackStartFunction
9509 });
9510 }
9511
9512 // EXTENSION! allows for well behaved errors defined elsewhere.
9513 assert.fail = fail;
9514
9515 // 4. Pure assertion tests whether a value is truthy, as determined
9516 // by !!guard.
9517 // assert.ok(guard, message_opt);
9518 // This statement is equivalent to assert.equal(true, !!guard,
9519 // message_opt);. To test strictly for the value true, use
9520 // assert.strictEqual(true, guard, message_opt);.
9521
9522 function ok(value, message) {
9523 if (!value) fail(value, true, message, '==', assert.ok);
9524 }
9525 assert.ok = ok;
9526
9527 // 5. The equality assertion tests shallow, coercive equality with
9528 // ==.
9529 // assert.equal(actual, expected, message_opt);
9530
9531 assert.equal = function equal(actual, expected, message) {
9532 if (actual != expected) fail(actual, expected, message, '==', assert.equal);
9533 };
9534
9535 // 6. The non-equality assertion tests for whether two objects are not equal
9536 // with != assert.notEqual(actual, expected, message_opt);
9537
9538 assert.notEqual = function notEqual(actual, expected, message) {
9539 if (actual == expected) {
9540 fail(actual, expected, message, '!=', assert.notEqual);
9541 }
9542 };
9543
9544 // 7. The equivalence assertion tests a deep equality relation.
9545 // assert.deepEqual(actual, expected, message_opt);
9546
9547 assert.deepEqual = function deepEqual(actual, expected, message) {
9548 if (!_deepEqual(actual, expected, false)) {
9549 fail(actual, expected, message, 'deepEqual', assert.deepEqual);
9550 }
9551 };
9552
9553 assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
9554 if (!_deepEqual(actual, expected, true)) {
9555 fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
9556 }
9557 };
9558
9559 function _deepEqual(actual, expected, strict, memos) {
9560 // 7.1. All identical values are equivalent, as determined by ===.
9561 if (actual === expected) {
9562 return true;
9563 } else if (isBuffer(actual) && isBuffer(expected)) {
9564 return compare(actual, expected) === 0;
9565
9566 // 7.2. If the expected value is a Date object, the actual value is
9567 // equivalent if it is also a Date object that refers to the same time.
9568 } else if (util.isDate(actual) && util.isDate(expected)) {
9569 return actual.getTime() === expected.getTime();
9570
9571 // 7.3 If the expected value is a RegExp object, the actual value is
9572 // equivalent if it is also a RegExp object with the same source and
9573 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
9574 } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
9575 return actual.source === expected.source &&
9576 actual.global === expected.global &&
9577 actual.multiline === expected.multiline &&
9578 actual.lastIndex === expected.lastIndex &&
9579 actual.ignoreCase === expected.ignoreCase;
9580
9581 // 7.4. Other pairs that do not both pass typeof value == 'object',
9582 // equivalence is determined by ==.
9583 } else if ((actual === null || typeof actual !== 'object') &&
9584 (expected === null || typeof expected !== 'object')) {
9585 return strict ? actual === expected : actual == expected;
9586
9587 // If both values are instances of typed arrays, wrap their underlying
9588 // ArrayBuffers in a Buffer each to increase performance
9589 // This optimization requires the arrays to have the same type as checked by
9590 // Object.prototype.toString (aka pToString). Never perform binary
9591 // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
9592 // bit patterns are not identical.
9593 } else if (isView(actual) && isView(expected) &&
9594 pToString(actual) === pToString(expected) &&
9595 !(actual instanceof Float32Array ||
9596 actual instanceof Float64Array)) {
9597 return compare(new Uint8Array(actual.buffer),
9598 new Uint8Array(expected.buffer)) === 0;
9599
9600 // 7.5 For all other Object pairs, including Array objects, equivalence is
9601 // determined by having the same number of owned properties (as verified
9602 // with Object.prototype.hasOwnProperty.call), the same set of keys
9603 // (although not necessarily the same order), equivalent values for every
9604 // corresponding key, and an identical 'prototype' property. Note: this
9605 // accounts for both named and indexed properties on Arrays.
9606 } else if (isBuffer(actual) !== isBuffer(expected)) {
9607 return false;
9608 } else {
9609 memos = memos || {actual: [], expected: []};
9610
9611 var actualIndex = memos.actual.indexOf(actual);
9612 if (actualIndex !== -1) {
9613 if (actualIndex === memos.expected.indexOf(expected)) {
9614 return true;
9615 }
9616 }
9617
9618 memos.actual.push(actual);
9619 memos.expected.push(expected);
9620
9621 return objEquiv(actual, expected, strict, memos);
9622 }
9623 }
9624
9625 function isArguments(object) {
9626 return Object.prototype.toString.call(object) == '[object Arguments]';
9627 }
9628
9629 function objEquiv(a, b, strict, actualVisitedObjects) {
9630 if (a === null || a === undefined || b === null || b === undefined)
9631 return false;
9632 // if one is a primitive, the other must be same
9633 if (util.isPrimitive(a) || util.isPrimitive(b))
9634 return a === b;
9635 if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
9636 return false;
9637 var aIsArgs = isArguments(a);
9638 var bIsArgs = isArguments(b);
9639 if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
9640 return false;
9641 if (aIsArgs) {
9642 a = pSlice.call(a);
9643 b = pSlice.call(b);
9644 return _deepEqual(a, b, strict);
9645 }
9646 var ka = objectKeys(a);
9647 var kb = objectKeys(b);
9648 var key, i;
9649 // having the same number of owned properties (keys incorporates
9650 // hasOwnProperty)
9651 if (ka.length !== kb.length)
9652 return false;
9653 //the same set of keys (although not necessarily the same order),
9654 ka.sort();
9655 kb.sort();
9656 //~~~cheap key test
9657 for (i = ka.length - 1; i >= 0; i--) {
9658 if (ka[i] !== kb[i])
9659 return false;
9660 }
9661 //equivalent values for every corresponding key, and
9662 //~~~possibly expensive deep test
9663 for (i = ka.length - 1; i >= 0; i--) {
9664 key = ka[i];
9665 if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
9666 return false;
9667 }
9668 return true;
9669 }
9670
9671 // 8. The non-equivalence assertion tests for any deep inequality.
9672 // assert.notDeepEqual(actual, expected, message_opt);
9673
9674 assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
9675 if (_deepEqual(actual, expected, false)) {
9676 fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
9677 }
9678 };
9679
9680 assert.notDeepStrictEqual = notDeepStrictEqual;
9681 function notDeepStrictEqual(actual, expected, message) {
9682 if (_deepEqual(actual, expected, true)) {
9683 fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
9684 }
9685 }
9686
9687
9688 // 9. The strict equality assertion tests strict equality, as determined by ===.
9689 // assert.strictEqual(actual, expected, message_opt);
9690
9691 assert.strictEqual = function strictEqual(actual, expected, message) {
9692 if (actual !== expected) {
9693 fail(actual, expected, message, '===', assert.strictEqual);
9694 }
9695 };
9696
9697 // 10. The strict non-equality assertion tests for strict inequality, as
9698 // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
9699
9700 assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
9701 if (actual === expected) {
9702 fail(actual, expected, message, '!==', assert.notStrictEqual);
9703 }
9704 };
9705
9706 function expectedException(actual, expected) {
9707 if (!actual || !expected) {
9708 return false;
9709 }
9710
9711 if (Object.prototype.toString.call(expected) == '[object RegExp]') {
9712 return expected.test(actual);
9713 }
9714
9715 try {
9716 if (actual instanceof expected) {
9717 return true;
9718 }
9719 } catch (e) {
9720 // Ignore. The instanceof check doesn't work for arrow functions.
9721 }
9722
9723 if (Error.isPrototypeOf(expected)) {
9724 return false;
9725 }
9726
9727 return expected.call({}, actual) === true;
9728 }
9729
9730 function _tryBlock(block) {
9731 var error;
9732 try {
9733 block();
9734 } catch (e) {
9735 error = e;
9736 }
9737 return error;
9738 }
9739
9740 function _throws(shouldThrow, block, expected, message) {
9741 var actual;
9742
9743 if (typeof block !== 'function') {
9744 throw new TypeError('"block" argument must be a function');
9745 }
9746
9747 if (typeof expected === 'string') {
9748 message = expected;
9749 expected = null;
9750 }
9751
9752 actual = _tryBlock(block);
9753
9754 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
9755 (message ? ' ' + message : '.');
9756
9757 if (shouldThrow && !actual) {
9758 fail(actual, expected, 'Missing expected exception' + message);
9759 }
9760
9761 var userProvidedMessage = typeof message === 'string';
9762 var isUnwantedException = !shouldThrow && util.isError(actual);
9763 var isUnexpectedException = !shouldThrow && actual && !expected;
9764
9765 if ((isUnwantedException &&
9766 userProvidedMessage &&
9767 expectedException(actual, expected)) ||
9768 isUnexpectedException) {
9769 fail(actual, expected, 'Got unwanted exception' + message);
9770 }
9771
9772 if ((shouldThrow && actual && expected &&
9773 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
9774 throw actual;
9775 }
9776 }
9777
9778 // 11. Expected to throw an error:
9779 // assert.throws(block, Error_opt, message_opt);
9780
9781 assert.throws = function(block, /*optional*/error, /*optional*/message) {
9782 _throws(true, block, error, message);
9783 };
9784
9785 // EXTENSION! This is annoying to write outside this module.
9786 assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
9787 _throws(false, block, error, message);
9788 };
9789
9790 assert.ifError = function(err) { if (err) throw err; };
9791
9792 // Expose a strict only variant of assert
9793 function strict(value, message) {
9794 if (!value) fail(value, true, message, '==', strict);
9795 }
9796 assert.strict = objectAssign(strict, assert, {
9797 equal: assert.strictEqual,
9798 deepEqual: assert.deepStrictEqual,
9799 notEqual: assert.notStrictEqual,
9800 notDeepEqual: assert.notDeepStrictEqual
9801 });
9802 assert.strict.strict = assert.strict;
9803
9804 var objectKeys = Object.keys || function (obj) {
9805 var keys = [];
9806 for (var key in obj) {
9807 if (hasOwn.call(obj, key)) keys.push(key);
9808 }
9809 return keys;
9810 };
9811
9812 }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
9813 },{"object-assign":169,"util/":77}],75:[function(require,module,exports){
9814 if (typeof Object.create === 'function') {
9815 // implementation from standard node.js 'util' module
9816 module.exports = function inherits(ctor, superCtor) {
9817 ctor.super_ = superCtor
9818 ctor.prototype = Object.create(superCtor.prototype, {
9819 constructor: {
9820 value: ctor,
9821 enumerable: false,
9822 writable: true,
9823 configurable: true
9824 }
9825 });
9826 };
9827 } else {
9828 // old school shim for old browsers
9829 module.exports = function inherits(ctor, superCtor) {
9830 ctor.super_ = superCtor
9831 var TempCtor = function () {}
9832 TempCtor.prototype = superCtor.prototype
9833 ctor.prototype = new TempCtor()
9834 ctor.prototype.constructor = ctor
9835 }
9836 }
9837
9838 },{}],76:[function(require,module,exports){
9839 module.exports = function isBuffer(arg) {
9840 return arg && typeof arg === 'object'
9841 && typeof arg.copy === 'function'
9842 && typeof arg.fill === 'function'
9843 && typeof arg.readUInt8 === 'function';
9844 }
9845 },{}],77:[function(require,module,exports){
9846 (function (process,global){
9847 // Copyright Joyent, Inc. and other Node contributors.
9848 //
9849 // Permission is hereby granted, free of charge, to any person obtaining a
9850 // copy of this software and associated documentation files (the
9851 // "Software"), to deal in the Software without restriction, including
9852 // without limitation the rights to use, copy, modify, merge, publish,
9853 // distribute, sublicense, and/or sell copies of the Software, and to permit
9854 // persons to whom the Software is furnished to do so, subject to the
9855 // following conditions:
9856 //
9857 // The above copyright notice and this permission notice shall be included
9858 // in all copies or substantial portions of the Software.
9859 //
9860 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
9861 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9862 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
9863 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9864 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
9865 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
9866 // USE OR OTHER DEALINGS IN THE SOFTWARE.
9867
9868 var formatRegExp = /%[sdj%]/g;
9869 exports.format = function(f) {
9870 if (!isString(f)) {
9871 var objects = [];
9872 for (var i = 0; i < arguments.length; i++) {
9873 objects.push(inspect(arguments[i]));
9874 }
9875 return objects.join(' ');
9876 }
9877
9878 var i = 1;
9879 var args = arguments;
9880 var len = args.length;
9881 var str = String(f).replace(formatRegExp, function(x) {
9882 if (x === '%%') return '%';
9883 if (i >= len) return x;
9884 switch (x) {
9885 case '%s': return String(args[i++]);
9886 case '%d': return Number(args[i++]);
9887 case '%j':
9888 try {
9889 return JSON.stringify(args[i++]);
9890 } catch (_) {
9891 return '[Circular]';
9892 }
9893 default:
9894 return x;
9895 }
9896 });
9897 for (var x = args[i]; i < len; x = args[++i]) {
9898 if (isNull(x) || !isObject(x)) {
9899 str += ' ' + x;
9900 } else {
9901 str += ' ' + inspect(x);
9902 }
9903 }
9904 return str;
9905 };
9906
9907
9908 // Mark that a method should not be used.
9909 // Returns a modified function which warns once by default.
9910 // If --no-deprecation is set, then it is a no-op.
9911 exports.deprecate = function(fn, msg) {
9912 // Allow for deprecating things in the process of starting up.
9913 if (isUndefined(global.process)) {
9914 return function() {
9915 return exports.deprecate(fn, msg).apply(this, arguments);
9916 };
9917 }
9918
9919 if (process.noDeprecation === true) {
9920 return fn;
9921 }
9922
9923 var warned = false;
9924 function deprecated() {
9925 if (!warned) {
9926 if (process.throwDeprecation) {
9927 throw new Error(msg);
9928 } else if (process.traceDeprecation) {
9929 console.trace(msg);
9930 } else {
9931 console.error(msg);
9932 }
9933 warned = true;
9934 }
9935 return fn.apply(this, arguments);
9936 }
9937
9938 return deprecated;
9939 };
9940
9941
9942 var debugs = {};
9943 var debugEnviron;
9944 exports.debuglog = function(set) {
9945 if (isUndefined(debugEnviron))
9946 debugEnviron = process.env.NODE_DEBUG || '';
9947 set = set.toUpperCase();
9948 if (!debugs[set]) {
9949 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
9950 var pid = process.pid;
9951 debugs[set] = function() {
9952 var msg = exports.format.apply(exports, arguments);
9953 console.error('%s %d: %s', set, pid, msg);
9954 };
9955 } else {
9956 debugs[set] = function() {};
9957 }
9958 }
9959 return debugs[set];
9960 };
9961
9962
9963 /**
9964 * Echos the value of a value. Trys to print the value out
9965 * in the best way possible given the different types.
9966 *
9967 * @param {Object} obj The object to print out.
9968 * @param {Object} opts Optional options object that alters the output.
9969 */
9970 /* legacy: obj, showHidden, depth, colors*/
9971 function inspect(obj, opts) {
9972 // default options
9973 var ctx = {
9974 seen: [],
9975 stylize: stylizeNoColor
9976 };
9977 // legacy...
9978 if (arguments.length >= 3) ctx.depth = arguments[2];
9979 if (arguments.length >= 4) ctx.colors = arguments[3];
9980 if (isBoolean(opts)) {
9981 // legacy...
9982 ctx.showHidden = opts;
9983 } else if (opts) {
9984 // got an "options" object
9985 exports._extend(ctx, opts);
9986 }
9987 // set default options
9988 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
9989 if (isUndefined(ctx.depth)) ctx.depth = 2;
9990 if (isUndefined(ctx.colors)) ctx.colors = false;
9991 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
9992 if (ctx.colors) ctx.stylize = stylizeWithColor;
9993 return formatValue(ctx, obj, ctx.depth);
9994 }
9995 exports.inspect = inspect;
9996
9997
9998 // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
9999 inspect.colors = {
10000 'bold' : [1, 22],
10001 'italic' : [3, 23],
10002 'underline' : [4, 24],
10003 'inverse' : [7, 27],
10004 'white' : [37, 39],
10005 'grey' : [90, 39],
10006 'black' : [30, 39],
10007 'blue' : [34, 39],
10008 'cyan' : [36, 39],
10009 'green' : [32, 39],
10010 'magenta' : [35, 39],
10011 'red' : [31, 39],
10012 'yellow' : [33, 39]
10013 };
10014
10015 // Don't use 'blue' not visible on cmd.exe
10016 inspect.styles = {
10017 'special': 'cyan',
10018 'number': 'yellow',
10019 'boolean': 'yellow',
10020 'undefined': 'grey',
10021 'null': 'bold',
10022 'string': 'green',
10023 'date': 'magenta',
10024 // "name": intentionally not styling
10025 'regexp': 'red'
10026 };
10027
10028
10029 function stylizeWithColor(str, styleType) {
10030 var style = inspect.styles[styleType];
10031
10032 if (style) {
10033 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
10034 '\u001b[' + inspect.colors[style][1] + 'm';
10035 } else {
10036 return str;
10037 }
10038 }
10039
10040
10041 function stylizeNoColor(str, styleType) {
10042 return str;
10043 }
10044
10045
10046 function arrayToHash(array) {
10047 var hash = {};
10048
10049 array.forEach(function(val, idx) {
10050 hash[val] = true;
10051 });
10052
10053 return hash;
10054 }
10055
10056
10057 function formatValue(ctx, value, recurseTimes) {
10058 // Provide a hook for user-specified inspect functions.
10059 // Check that value is an object with an inspect function on it
10060 if (ctx.customInspect &&
10061 value &&
10062 isFunction(value.inspect) &&
10063 // Filter out the util module, it's inspect function is special
10064 value.inspect !== exports.inspect &&
10065 // Also filter out any prototype objects using the circular check.
10066 !(value.constructor && value.constructor.prototype === value)) {
10067 var ret = value.inspect(recurseTimes, ctx);
10068 if (!isString(ret)) {
10069 ret = formatValue(ctx, ret, recurseTimes);
10070 }
10071 return ret;
10072 }
10073
10074 // Primitive types cannot have properties
10075 var primitive = formatPrimitive(ctx, value);
10076 if (primitive) {
10077 return primitive;
10078 }
10079
10080 // Look up the keys of the object.
10081 var keys = Object.keys(value);
10082 var visibleKeys = arrayToHash(keys);
10083
10084 if (ctx.showHidden) {
10085 keys = Object.getOwnPropertyNames(value);
10086 }
10087
10088 // IE doesn't make error fields non-enumerable
10089 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
10090 if (isError(value)
10091 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
10092 return formatError(value);
10093 }
10094
10095 // Some type of object without properties can be shortcutted.
10096 if (keys.length === 0) {
10097 if (isFunction(value)) {
10098 var name = value.name ? ': ' + value.name : '';
10099 return ctx.stylize('[Function' + name + ']', 'special');
10100 }
10101 if (isRegExp(value)) {
10102 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
10103 }
10104 if (isDate(value)) {
10105 return ctx.stylize(Date.prototype.toString.call(value), 'date');
10106 }
10107 if (isError(value)) {
10108 return formatError(value);
10109 }
10110 }
10111
10112 var base = '', array = false, braces = ['{', '}'];
10113
10114 // Make Array say that they are Array
10115 if (isArray(value)) {
10116 array = true;
10117 braces = ['[', ']'];
10118 }
10119
10120 // Make functions say that they are functions
10121 if (isFunction(value)) {
10122 var n = value.name ? ': ' + value.name : '';
10123 base = ' [Function' + n + ']';
10124 }
10125
10126 // Make RegExps say that they are RegExps
10127 if (isRegExp(value)) {
10128 base = ' ' + RegExp.prototype.toString.call(value);
10129 }
10130
10131 // Make dates with properties first say the date
10132 if (isDate(value)) {
10133 base = ' ' + Date.prototype.toUTCString.call(value);
10134 }
10135
10136 // Make error with message first say the error
10137 if (isError(value)) {
10138 base = ' ' + formatError(value);
10139 }
10140
10141 if (keys.length === 0 && (!array || value.length == 0)) {
10142 return braces[0] + base + braces[1];
10143 }
10144
10145 if (recurseTimes < 0) {
10146 if (isRegExp(value)) {
10147 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
10148 } else {
10149 return ctx.stylize('[Object]', 'special');
10150 }
10151 }
10152
10153 ctx.seen.push(value);
10154
10155 var output;
10156 if (array) {
10157 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
10158 } else {
10159 output = keys.map(function(key) {
10160 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
10161 });
10162 }
10163
10164 ctx.seen.pop();
10165
10166 return reduceToSingleString(output, base, braces);
10167 }
10168
10169
10170 function formatPrimitive(ctx, value) {
10171 if (isUndefined(value))
10172 return ctx.stylize('undefined', 'undefined');
10173 if (isString(value)) {
10174 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
10175 .replace(/'/g, "\\'")
10176 .replace(/\\"/g, '"') + '\'';
10177 return ctx.stylize(simple, 'string');
10178 }
10179 if (isNumber(value))
10180 return ctx.stylize('' + value, 'number');
10181 if (isBoolean(value))
10182 return ctx.stylize('' + value, 'boolean');
10183 // For some reason typeof null is "object", so special case here.
10184 if (isNull(value))
10185 return ctx.stylize('null', 'null');
10186 }
10187
10188
10189 function formatError(value) {
10190 return '[' + Error.prototype.toString.call(value) + ']';
10191 }
10192
10193
10194 function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
10195 var output = [];
10196 for (var i = 0, l = value.length; i < l; ++i) {
10197 if (hasOwnProperty(value, String(i))) {
10198 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
10199 String(i), true));
10200 } else {
10201 output.push('');
10202 }
10203 }
10204 keys.forEach(function(key) {
10205 if (!key.match(/^\d+$/)) {
10206 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
10207 key, true));
10208 }
10209 });
10210 return output;
10211 }
10212
10213
10214 function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
10215 var name, str, desc;
10216 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
10217 if (desc.get) {
10218 if (desc.set) {
10219 str = ctx.stylize('[Getter/Setter]', 'special');
10220 } else {
10221 str = ctx.stylize('[Getter]', 'special');
10222 }
10223 } else {
10224 if (desc.set) {
10225 str = ctx.stylize('[Setter]', 'special');
10226 }
10227 }
10228 if (!hasOwnProperty(visibleKeys, key)) {
10229 name = '[' + key + ']';
10230 }
10231 if (!str) {
10232 if (ctx.seen.indexOf(desc.value) < 0) {
10233 if (isNull(recurseTimes)) {
10234 str = formatValue(ctx, desc.value, null);
10235 } else {
10236 str = formatValue(ctx, desc.value, recurseTimes - 1);
10237 }
10238 if (str.indexOf('\n') > -1) {
10239 if (array) {
10240 str = str.split('\n').map(function(line) {
10241 return ' ' + line;
10242 }).join('\n').substr(2);
10243 } else {
10244 str = '\n' + str.split('\n').map(function(line) {
10245 return ' ' + line;
10246 }).join('\n');
10247 }
10248 }
10249 } else {
10250 str = ctx.stylize('[Circular]', 'special');
10251 }
10252 }
10253 if (isUndefined(name)) {
10254 if (array && key.match(/^\d+$/)) {
10255 return str;
10256 }
10257 name = JSON.stringify('' + key);
10258 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
10259 name = name.substr(1, name.length - 2);
10260 name = ctx.stylize(name, 'name');
10261 } else {
10262 name = name.replace(/'/g, "\\'")
10263 .replace(/\\"/g, '"')
10264 .replace(/(^"|"$)/g, "'");
10265 name = ctx.stylize(name, 'string');
10266 }
10267 }
10268
10269 return name + ': ' + str;
10270 }
10271
10272
10273 function reduceToSingleString(output, base, braces) {
10274 var numLinesEst = 0;
10275 var length = output.reduce(function(prev, cur) {
10276 numLinesEst++;
10277 if (cur.indexOf('\n') >= 0) numLinesEst++;
10278 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
10279 }, 0);
10280
10281 if (length > 60) {
10282 return braces[0] +
10283 (base === '' ? '' : base + '\n ') +
10284 ' ' +
10285 output.join(',\n ') +
10286 ' ' +
10287 braces[1];
10288 }
10289
10290 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
10291 }
10292
10293
10294 // NOTE: These type checking functions intentionally don't use `instanceof`
10295 // because it is fragile and can be easily faked with `Object.create()`.
10296 function isArray(ar) {
10297 return Array.isArray(ar);
10298 }
10299 exports.isArray = isArray;
10300
10301 function isBoolean(arg) {
10302 return typeof arg === 'boolean';
10303 }
10304 exports.isBoolean = isBoolean;
10305
10306 function isNull(arg) {
10307 return arg === null;
10308 }
10309 exports.isNull = isNull;
10310
10311 function isNullOrUndefined(arg) {
10312 return arg == null;
10313 }
10314 exports.isNullOrUndefined = isNullOrUndefined;
10315
10316 function isNumber(arg) {
10317 return typeof arg === 'number';
10318 }
10319 exports.isNumber = isNumber;
10320
10321 function isString(arg) {
10322 return typeof arg === 'string';
10323 }
10324 exports.isString = isString;
10325
10326 function isSymbol(arg) {
10327 return typeof arg === 'symbol';
10328 }
10329 exports.isSymbol = isSymbol;
10330
10331 function isUndefined(arg) {
10332 return arg === void 0;
10333 }
10334 exports.isUndefined = isUndefined;
10335
10336 function isRegExp(re) {
10337 return isObject(re) && objectToString(re) === '[object RegExp]';
10338 }
10339 exports.isRegExp = isRegExp;
10340
10341 function isObject(arg) {
10342 return typeof arg === 'object' && arg !== null;
10343 }
10344 exports.isObject = isObject;
10345
10346 function isDate(d) {
10347 return isObject(d) && objectToString(d) === '[object Date]';
10348 }
10349 exports.isDate = isDate;
10350
10351 function isError(e) {
10352 return isObject(e) &&
10353 (objectToString(e) === '[object Error]' || e instanceof Error);
10354 }
10355 exports.isError = isError;
10356
10357 function isFunction(arg) {
10358 return typeof arg === 'function';
10359 }
10360 exports.isFunction = isFunction;
10361
10362 function isPrimitive(arg) {
10363 return arg === null ||
10364 typeof arg === 'boolean' ||
10365 typeof arg === 'number' ||
10366 typeof arg === 'string' ||
10367 typeof arg === 'symbol' || // ES6 symbol
10368 typeof arg === 'undefined';
10369 }
10370 exports.isPrimitive = isPrimitive;
10371
10372 exports.isBuffer = require('./support/isBuffer');
10373
10374 function objectToString(o) {
10375 return Object.prototype.toString.call(o);
10376 }
10377
10378
10379 function pad(n) {
10380 return n < 10 ? '0' + n.toString(10) : n.toString(10);
10381 }
10382
10383
10384 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
10385 'Oct', 'Nov', 'Dec'];
10386
10387 // 26 Feb 16:19:34
10388 function timestamp() {
10389 var d = new Date();
10390 var time = [pad(d.getHours()),
10391 pad(d.getMinutes()),
10392 pad(d.getSeconds())].join(':');
10393 return [d.getDate(), months[d.getMonth()], time].join(' ');
10394 }
10395
10396
10397 // log is just a thin wrapper to console.log that prepends a timestamp
10398 exports.log = function() {
10399 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
10400 };
10401
10402
10403 /**
10404 * Inherit the prototype methods from one constructor into another.
10405 *
10406 * The Function.prototype.inherits from lang.js rewritten as a standalone
10407 * function (not on Function.prototype). NOTE: If this file is to be loaded
10408 * during bootstrapping this function needs to be rewritten using some native
10409 * functions as prototype setup using normal JavaScript does not work as
10410 * expected during bootstrapping (see mirror.js in r114903).
10411 *
10412 * @param {function} ctor Constructor function which needs to inherit the
10413 * prototype.
10414 * @param {function} superCtor Constructor function to inherit prototype from.
10415 */
10416 exports.inherits = require('inherits');
10417
10418 exports._extend = function(origin, add) {
10419 // Don't do anything if add isn't an object
10420 if (!add || !isObject(add)) return origin;
10421
10422 var keys = Object.keys(add);
10423 var i = keys.length;
10424 while (i--) {
10425 origin[keys[i]] = add[keys[i]];
10426 }
10427 return origin;
10428 };
10429
10430 function hasOwnProperty(obj, prop) {
10431 return Object.prototype.hasOwnProperty.call(obj, prop);
10432 }
10433
10434 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
10435 },{"./support/isBuffer":76,"_process":181,"inherits":75}],78:[function(require,module,exports){
10436 'use strict'
10437
10438 exports.byteLength = byteLength
10439 exports.toByteArray = toByteArray
10440 exports.fromByteArray = fromByteArray
10441
10442 var lookup = []
10443 var revLookup = []
10444 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
10445
10446 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
10447 for (var i = 0, len = code.length; i < len; ++i) {
10448 lookup[i] = code[i]
10449 revLookup[code.charCodeAt(i)] = i
10450 }
10451
10452 // Support decoding URL-safe base64 strings, as Node.js does.
10453 // See: https://en.wikipedia.org/wiki/Base64#URL_applications
10454 revLookup['-'.charCodeAt(0)] = 62
10455 revLookup['_'.charCodeAt(0)] = 63
10456
10457 function getLens (b64) {
10458 var len = b64.length
10459
10460 if (len % 4 > 0) {
10461 throw new Error('Invalid string. Length must be a multiple of 4')
10462 }
10463
10464 // Trim off extra bytes after placeholder bytes are found
10465 // See: https://github.com/beatgammit/base64-js/issues/42
10466 var validLen = b64.indexOf('=')
10467 if (validLen === -1) validLen = len
10468
10469 var placeHoldersLen = validLen === len
10470 ? 0
10471 : 4 - (validLen % 4)
10472
10473 return [validLen, placeHoldersLen]
10474 }
10475
10476 // base64 is 4/3 + up to two characters of the original data
10477 function byteLength (b64) {
10478 var lens = getLens(b64)
10479 var validLen = lens[0]
10480 var placeHoldersLen = lens[1]
10481 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
10482 }
10483
10484 function _byteLength (b64, validLen, placeHoldersLen) {
10485 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
10486 }
10487
10488 function toByteArray (b64) {
10489 var tmp
10490 var lens = getLens(b64)
10491 var validLen = lens[0]
10492 var placeHoldersLen = lens[1]
10493
10494 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
10495
10496 var curByte = 0
10497
10498 // if there are placeholders, only get up to the last complete 4 chars
10499 var len = placeHoldersLen > 0
10500 ? validLen - 4
10501 : validLen
10502
10503 var i
10504 for (i = 0; i < len; i += 4) {
10505 tmp =
10506 (revLookup[b64.charCodeAt(i)] << 18) |
10507 (revLookup[b64.charCodeAt(i + 1)] << 12) |
10508 (revLookup[b64.charCodeAt(i + 2)] << 6) |
10509 revLookup[b64.charCodeAt(i + 3)]
10510 arr[curByte++] = (tmp >> 16) & 0xFF
10511 arr[curByte++] = (tmp >> 8) & 0xFF
10512 arr[curByte++] = tmp & 0xFF
10513 }
10514
10515 if (placeHoldersLen === 2) {
10516 tmp =
10517 (revLookup[b64.charCodeAt(i)] << 2) |
10518 (revLookup[b64.charCodeAt(i + 1)] >> 4)
10519 arr[curByte++] = tmp & 0xFF
10520 }
10521
10522 if (placeHoldersLen === 1) {
10523 tmp =
10524 (revLookup[b64.charCodeAt(i)] << 10) |
10525 (revLookup[b64.charCodeAt(i + 1)] << 4) |
10526 (revLookup[b64.charCodeAt(i + 2)] >> 2)
10527 arr[curByte++] = (tmp >> 8) & 0xFF
10528 arr[curByte++] = tmp & 0xFF
10529 }
10530
10531 return arr
10532 }
10533
10534 function tripletToBase64 (num) {
10535 return lookup[num >> 18 & 0x3F] +
10536 lookup[num >> 12 & 0x3F] +
10537 lookup[num >> 6 & 0x3F] +
10538 lookup[num & 0x3F]
10539 }
10540
10541 function encodeChunk (uint8, start, end) {
10542 var tmp
10543 var output = []
10544 for (var i = start; i < end; i += 3) {
10545 tmp =
10546 ((uint8[i] << 16) & 0xFF0000) +
10547 ((uint8[i + 1] << 8) & 0xFF00) +
10548 (uint8[i + 2] & 0xFF)
10549 output.push(tripletToBase64(tmp))
10550 }
10551 return output.join('')
10552 }
10553
10554 function fromByteArray (uint8) {
10555 var tmp
10556 var len = uint8.length
10557 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
10558 var parts = []
10559 var maxChunkLength = 16383 // must be multiple of 3
10560
10561 // go through the array every three bytes, we'll deal with trailing stuff later
10562 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
10563 parts.push(encodeChunk(
10564 uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
10565 ))
10566 }
10567
10568 // pad the end with zeros, but make sure to not forget the extra bytes
10569 if (extraBytes === 1) {
10570 tmp = uint8[len - 1]
10571 parts.push(
10572 lookup[tmp >> 2] +
10573 lookup[(tmp << 4) & 0x3F] +
10574 '=='
10575 )
10576 } else if (extraBytes === 2) {
10577 tmp = (uint8[len - 2] << 8) + uint8[len - 1]
10578 parts.push(
10579 lookup[tmp >> 10] +
10580 lookup[(tmp >> 4) & 0x3F] +
10581 lookup[(tmp << 2) & 0x3F] +
10582 '='
10583 )
10584 }
10585
10586 return parts.join('')
10587 }
10588
10589 },{}],79:[function(require,module,exports){
10590 (function (module, exports) {
10591 'use strict';
10592
10593 // Utils
10594 function assert (val, msg) {
10595 if (!val) throw new Error(msg || 'Assertion failed');
10596 }
10597
10598 // Could use `inherits` module, but don't want to move from single file
10599 // architecture yet.
10600 function inherits (ctor, superCtor) {
10601 ctor.super_ = superCtor;
10602 var TempCtor = function () {};
10603 TempCtor.prototype = superCtor.prototype;
10604 ctor.prototype = new TempCtor();
10605 ctor.prototype.constructor = ctor;
10606 }
10607
10608 // BN
10609
10610 function BN (number, base, endian) {
10611 if (BN.isBN(number)) {
10612 return number;
10613 }
10614
10615 this.negative = 0;
10616 this.words = null;
10617 this.length = 0;
10618
10619 // Reduction context
10620 this.red = null;
10621
10622 if (number !== null) {
10623 if (base === 'le' || base === 'be') {
10624 endian = base;
10625 base = 10;
10626 }
10627
10628 this._init(number || 0, base || 10, endian || 'be');
10629 }
10630 }
10631 if (typeof module === 'object') {
10632 module.exports = BN;
10633 } else {
10634 exports.BN = BN;
10635 }
10636
10637 BN.BN = BN;
10638 BN.wordSize = 26;
10639
10640 var Buffer;
10641 try {
10642 Buffer = require('buffer').Buffer;
10643 } catch (e) {
10644 }
10645
10646 BN.isBN = function isBN (num) {
10647 if (num instanceof BN) {
10648 return true;
10649 }
10650
10651 return num !== null && typeof num === 'object' &&
10652 num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
10653 };
10654
10655 BN.max = function max (left, right) {
10656 if (left.cmp(right) > 0) return left;
10657 return right;
10658 };
10659
10660 BN.min = function min (left, right) {
10661 if (left.cmp(right) < 0) return left;
10662 return right;
10663 };
10664
10665 BN.prototype._init = function init (number, base, endian) {
10666 if (typeof number === 'number') {
10667 return this._initNumber(number, base, endian);
10668 }
10669
10670 if (typeof number === 'object') {
10671 return this._initArray(number, base, endian);
10672 }
10673
10674 if (base === 'hex') {
10675 base = 16;
10676 }
10677 assert(base === (base | 0) && base >= 2 && base <= 36);
10678
10679 number = number.toString().replace(/\s+/g, '');
10680 var start = 0;
10681 if (number[0] === '-') {
10682 start++;
10683 }
10684
10685 if (base === 16) {
10686 this._parseHex(number, start);
10687 } else {
10688 this._parseBase(number, base, start);
10689 }
10690
10691 if (number[0] === '-') {
10692 this.negative = 1;
10693 }
10694
10695 this.strip();
10696
10697 if (endian !== 'le') return;
10698
10699 this._initArray(this.toArray(), base, endian);
10700 };
10701
10702 BN.prototype._initNumber = function _initNumber (number, base, endian) {
10703 if (number < 0) {
10704 this.negative = 1;
10705 number = -number;
10706 }
10707 if (number < 0x4000000) {
10708 this.words = [ number & 0x3ffffff ];
10709 this.length = 1;
10710 } else if (number < 0x10000000000000) {
10711 this.words = [
10712 number & 0x3ffffff,
10713 (number / 0x4000000) & 0x3ffffff
10714 ];
10715 this.length = 2;
10716 } else {
10717 assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
10718 this.words = [
10719 number & 0x3ffffff,
10720 (number / 0x4000000) & 0x3ffffff,
10721 1
10722 ];
10723 this.length = 3;
10724 }
10725
10726 if (endian !== 'le') return;
10727
10728 // Reverse the bytes
10729 this._initArray(this.toArray(), base, endian);
10730 };
10731
10732 BN.prototype._initArray = function _initArray (number, base, endian) {
10733 // Perhaps a Uint8Array
10734 assert(typeof number.length === 'number');
10735 if (number.length <= 0) {
10736 this.words = [ 0 ];
10737 this.length = 1;
10738 return this;
10739 }
10740
10741 this.length = Math.ceil(number.length / 3);
10742 this.words = new Array(this.length);
10743 for (var i = 0; i < this.length; i++) {
10744 this.words[i] = 0;
10745 }
10746
10747 var j, w;
10748 var off = 0;
10749 if (endian === 'be') {
10750 for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
10751 w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
10752 this.words[j] |= (w << off) & 0x3ffffff;
10753 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
10754 off += 24;
10755 if (off >= 26) {
10756 off -= 26;
10757 j++;
10758 }
10759 }
10760 } else if (endian === 'le') {
10761 for (i = 0, j = 0; i < number.length; i += 3) {
10762 w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
10763 this.words[j] |= (w << off) & 0x3ffffff;
10764 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
10765 off += 24;
10766 if (off >= 26) {
10767 off -= 26;
10768 j++;
10769 }
10770 }
10771 }
10772 return this.strip();
10773 };
10774
10775 function parseHex (str, start, end) {
10776 var r = 0;
10777 var len = Math.min(str.length, end);
10778 for (var i = start; i < len; i++) {
10779 var c = str.charCodeAt(i) - 48;
10780
10781 r <<= 4;
10782
10783 // 'a' - 'f'
10784 if (c >= 49 && c <= 54) {
10785 r |= c - 49 + 0xa;
10786
10787 // 'A' - 'F'
10788 } else if (c >= 17 && c <= 22) {
10789 r |= c - 17 + 0xa;
10790
10791 // '0' - '9'
10792 } else {
10793 r |= c & 0xf;
10794 }
10795 }
10796 return r;
10797 }
10798
10799 BN.prototype._parseHex = function _parseHex (number, start) {
10800 // Create possibly bigger array to ensure that it fits the number
10801 this.length = Math.ceil((number.length - start) / 6);
10802 this.words = new Array(this.length);
10803 for (var i = 0; i < this.length; i++) {
10804 this.words[i] = 0;
10805 }
10806
10807 var j, w;
10808 // Scan 24-bit chunks and add them to the number
10809 var off = 0;
10810 for (i = number.length - 6, j = 0; i >= start; i -= 6) {
10811 w = parseHex(number, i, i + 6);
10812 this.words[j] |= (w << off) & 0x3ffffff;
10813 // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
10814 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
10815 off += 24;
10816 if (off >= 26) {
10817 off -= 26;
10818 j++;
10819 }
10820 }
10821 if (i + 6 !== start) {
10822 w = parseHex(number, start, i + 6);
10823 this.words[j] |= (w << off) & 0x3ffffff;
10824 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
10825 }
10826 this.strip();
10827 };
10828
10829 function parseBase (str, start, end, mul) {
10830 var r = 0;
10831 var len = Math.min(str.length, end);
10832 for (var i = start; i < len; i++) {
10833 var c = str.charCodeAt(i) - 48;
10834
10835 r *= mul;
10836
10837 // 'a'
10838 if (c >= 49) {
10839 r += c - 49 + 0xa;
10840
10841 // 'A'
10842 } else if (c >= 17) {
10843 r += c - 17 + 0xa;
10844
10845 // '0' - '9'
10846 } else {
10847 r += c;
10848 }
10849 }
10850 return r;
10851 }
10852
10853 BN.prototype._parseBase = function _parseBase (number, base, start) {
10854 // Initialize as zero
10855 this.words = [ 0 ];
10856 this.length = 1;
10857
10858 // Find length of limb in base
10859 for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
10860 limbLen++;
10861 }
10862 limbLen--;
10863 limbPow = (limbPow / base) | 0;
10864
10865 var total = number.length - start;
10866 var mod = total % limbLen;
10867 var end = Math.min(total, total - mod) + start;
10868
10869 var word = 0;
10870 for (var i = start; i < end; i += limbLen) {
10871 word = parseBase(number, i, i + limbLen, base);
10872
10873 this.imuln(limbPow);
10874 if (this.words[0] + word < 0x4000000) {
10875 this.words[0] += word;
10876 } else {
10877 this._iaddn(word);
10878 }
10879 }
10880
10881 if (mod !== 0) {
10882 var pow = 1;
10883 word = parseBase(number, i, number.length, base);
10884
10885 for (i = 0; i < mod; i++) {
10886 pow *= base;
10887 }
10888
10889 this.imuln(pow);
10890 if (this.words[0] + word < 0x4000000) {
10891 this.words[0] += word;
10892 } else {
10893 this._iaddn(word);
10894 }
10895 }
10896 };
10897
10898 BN.prototype.copy = function copy (dest) {
10899 dest.words = new Array(this.length);
10900 for (var i = 0; i < this.length; i++) {
10901 dest.words[i] = this.words[i];
10902 }
10903 dest.length = this.length;
10904 dest.negative = this.negative;
10905 dest.red = this.red;
10906 };
10907
10908 BN.prototype.clone = function clone () {
10909 var r = new BN(null);
10910 this.copy(r);
10911 return r;
10912 };
10913
10914 BN.prototype._expand = function _expand (size) {
10915 while (this.length < size) {
10916 this.words[this.length++] = 0;
10917 }
10918 return this;
10919 };
10920
10921 // Remove leading `0` from `this`
10922 BN.prototype.strip = function strip () {
10923 while (this.length > 1 && this.words[this.length - 1] === 0) {
10924 this.length--;
10925 }
10926 return this._normSign();
10927 };
10928
10929 BN.prototype._normSign = function _normSign () {
10930 // -0 = 0
10931 if (this.length === 1 && this.words[0] === 0) {
10932 this.negative = 0;
10933 }
10934 return this;
10935 };
10936
10937 BN.prototype.inspect = function inspect () {
10938 return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
10939 };
10940
10941 /*
10942
10943 var zeros = [];
10944 var groupSizes = [];
10945 var groupBases = [];
10946
10947 var s = '';
10948 var i = -1;
10949 while (++i < BN.wordSize) {
10950 zeros[i] = s;
10951 s += '0';
10952 }
10953 groupSizes[0] = 0;
10954 groupSizes[1] = 0;
10955 groupBases[0] = 0;
10956 groupBases[1] = 0;
10957 var base = 2 - 1;
10958 while (++base < 36 + 1) {
10959 var groupSize = 0;
10960 var groupBase = 1;
10961 while (groupBase < (1 << BN.wordSize) / base) {
10962 groupBase *= base;
10963 groupSize += 1;
10964 }
10965 groupSizes[base] = groupSize;
10966 groupBases[base] = groupBase;
10967 }
10968
10969 */
10970
10971 var zeros = [
10972 '',
10973 '0',
10974 '00',
10975 '000',
10976 '0000',
10977 '00000',
10978 '000000',
10979 '0000000',
10980 '00000000',
10981 '000000000',
10982 '0000000000',
10983 '00000000000',
10984 '000000000000',
10985 '0000000000000',
10986 '00000000000000',
10987 '000000000000000',
10988 '0000000000000000',
10989 '00000000000000000',
10990 '000000000000000000',
10991 '0000000000000000000',
10992 '00000000000000000000',
10993 '000000000000000000000',
10994 '0000000000000000000000',
10995 '00000000000000000000000',
10996 '000000000000000000000000',
10997 '0000000000000000000000000'
10998 ];
10999
11000 var groupSizes = [
11001 0, 0,
11002 25, 16, 12, 11, 10, 9, 8,
11003 8, 7, 7, 7, 7, 6, 6,
11004 6, 6, 6, 6, 6, 5, 5,
11005 5, 5, 5, 5, 5, 5, 5,
11006 5, 5, 5, 5, 5, 5, 5
11007 ];
11008
11009 var groupBases = [
11010 0, 0,
11011 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
11012 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
11013 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
11014 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
11015 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
11016 ];
11017
11018 BN.prototype.toString = function toString (base, padding) {
11019 base = base || 10;
11020 padding = padding | 0 || 1;
11021
11022 var out;
11023 if (base === 16 || base === 'hex') {
11024 out = '';
11025 var off = 0;
11026 var carry = 0;
11027 for (var i = 0; i < this.length; i++) {
11028 var w = this.words[i];
11029 var word = (((w << off) | carry) & 0xffffff).toString(16);
11030 carry = (w >>> (24 - off)) & 0xffffff;
11031 if (carry !== 0 || i !== this.length - 1) {
11032 out = zeros[6 - word.length] + word + out;
11033 } else {
11034 out = word + out;
11035 }
11036 off += 2;
11037 if (off >= 26) {
11038 off -= 26;
11039 i--;
11040 }
11041 }
11042 if (carry !== 0) {
11043 out = carry.toString(16) + out;
11044 }
11045 while (out.length % padding !== 0) {
11046 out = '0' + out;
11047 }
11048 if (this.negative !== 0) {
11049 out = '-' + out;
11050 }
11051 return out;
11052 }
11053
11054 if (base === (base | 0) && base >= 2 && base <= 36) {
11055 // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
11056 var groupSize = groupSizes[base];
11057 // var groupBase = Math.pow(base, groupSize);
11058 var groupBase = groupBases[base];
11059 out = '';
11060 var c = this.clone();
11061 c.negative = 0;
11062 while (!c.isZero()) {
11063 var r = c.modn(groupBase).toString(base);
11064 c = c.idivn(groupBase);
11065
11066 if (!c.isZero()) {
11067 out = zeros[groupSize - r.length] + r + out;
11068 } else {
11069 out = r + out;
11070 }
11071 }
11072 if (this.isZero()) {
11073 out = '0' + out;
11074 }
11075 while (out.length % padding !== 0) {
11076 out = '0' + out;
11077 }
11078 if (this.negative !== 0) {
11079 out = '-' + out;
11080 }
11081 return out;
11082 }
11083
11084 assert(false, 'Base should be between 2 and 36');
11085 };
11086
11087 BN.prototype.toNumber = function toNumber () {
11088 var ret = this.words[0];
11089 if (this.length === 2) {
11090 ret += this.words[1] * 0x4000000;
11091 } else if (this.length === 3 && this.words[2] === 0x01) {
11092 // NOTE: at this stage it is known that the top bit is set
11093 ret += 0x10000000000000 + (this.words[1] * 0x4000000);
11094 } else if (this.length > 2) {
11095 assert(false, 'Number can only safely store up to 53 bits');
11096 }
11097 return (this.negative !== 0) ? -ret : ret;
11098 };
11099
11100 BN.prototype.toJSON = function toJSON () {
11101 return this.toString(16);
11102 };
11103
11104 BN.prototype.toBuffer = function toBuffer (endian, length) {
11105 assert(typeof Buffer !== 'undefined');
11106 return this.toArrayLike(Buffer, endian, length);
11107 };
11108
11109 BN.prototype.toArray = function toArray (endian, length) {
11110 return this.toArrayLike(Array, endian, length);
11111 };
11112
11113 BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
11114 var byteLength = this.byteLength();
11115 var reqLength = length || Math.max(1, byteLength);
11116 assert(byteLength <= reqLength, 'byte array longer than desired length');
11117 assert(reqLength > 0, 'Requested array length <= 0');
11118
11119 this.strip();
11120 var littleEndian = endian === 'le';
11121 var res = new ArrayType(reqLength);
11122
11123 var b, i;
11124 var q = this.clone();
11125 if (!littleEndian) {
11126 // Assume big-endian
11127 for (i = 0; i < reqLength - byteLength; i++) {
11128 res[i] = 0;
11129 }
11130
11131 for (i = 0; !q.isZero(); i++) {
11132 b = q.andln(0xff);
11133 q.iushrn(8);
11134
11135 res[reqLength - i - 1] = b;
11136 }
11137 } else {
11138 for (i = 0; !q.isZero(); i++) {
11139 b = q.andln(0xff);
11140 q.iushrn(8);
11141
11142 res[i] = b;
11143 }
11144
11145 for (; i < reqLength; i++) {
11146 res[i] = 0;
11147 }
11148 }
11149
11150 return res;
11151 };
11152
11153 if (Math.clz32) {
11154 BN.prototype._countBits = function _countBits (w) {
11155 return 32 - Math.clz32(w);
11156 };
11157 } else {
11158 BN.prototype._countBits = function _countBits (w) {
11159 var t = w;
11160 var r = 0;
11161 if (t >= 0x1000) {
11162 r += 13;
11163 t >>>= 13;
11164 }
11165 if (t >= 0x40) {
11166 r += 7;
11167 t >>>= 7;
11168 }
11169 if (t >= 0x8) {
11170 r += 4;
11171 t >>>= 4;
11172 }
11173 if (t >= 0x02) {
11174 r += 2;
11175 t >>>= 2;
11176 }
11177 return r + t;
11178 };
11179 }
11180
11181 BN.prototype._zeroBits = function _zeroBits (w) {
11182 // Short-cut
11183 if (w === 0) return 26;
11184
11185 var t = w;
11186 var r = 0;
11187 if ((t & 0x1fff) === 0) {
11188 r += 13;
11189 t >>>= 13;
11190 }
11191 if ((t & 0x7f) === 0) {
11192 r += 7;
11193 t >>>= 7;
11194 }
11195 if ((t & 0xf) === 0) {
11196 r += 4;
11197 t >>>= 4;
11198 }
11199 if ((t & 0x3) === 0) {
11200 r += 2;
11201 t >>>= 2;
11202 }
11203 if ((t & 0x1) === 0) {
11204 r++;
11205 }
11206 return r;
11207 };
11208
11209 // Return number of used bits in a BN
11210 BN.prototype.bitLength = function bitLength () {
11211 var w = this.words[this.length - 1];
11212 var hi = this._countBits(w);
11213 return (this.length - 1) * 26 + hi;
11214 };
11215
11216 function toBitArray (num) {
11217 var w = new Array(num.bitLength());
11218
11219 for (var bit = 0; bit < w.length; bit++) {
11220 var off = (bit / 26) | 0;
11221 var wbit = bit % 26;
11222
11223 w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
11224 }
11225
11226 return w;
11227 }
11228
11229 // Number of trailing zero bits
11230 BN.prototype.zeroBits = function zeroBits () {
11231 if (this.isZero()) return 0;
11232
11233 var r = 0;
11234 for (var i = 0; i < this.length; i++) {
11235 var b = this._zeroBits(this.words[i]);
11236 r += b;
11237 if (b !== 26) break;
11238 }
11239 return r;
11240 };
11241
11242 BN.prototype.byteLength = function byteLength () {
11243 return Math.ceil(this.bitLength() / 8);
11244 };
11245
11246 BN.prototype.toTwos = function toTwos (width) {
11247 if (this.negative !== 0) {
11248 return this.abs().inotn(width).iaddn(1);
11249 }
11250 return this.clone();
11251 };
11252
11253 BN.prototype.fromTwos = function fromTwos (width) {
11254 if (this.testn(width - 1)) {
11255 return this.notn(width).iaddn(1).ineg();
11256 }
11257 return this.clone();
11258 };
11259
11260 BN.prototype.isNeg = function isNeg () {
11261 return this.negative !== 0;
11262 };
11263
11264 // Return negative clone of `this`
11265 BN.prototype.neg = function neg () {
11266 return this.clone().ineg();
11267 };
11268
11269 BN.prototype.ineg = function ineg () {
11270 if (!this.isZero()) {
11271 this.negative ^= 1;
11272 }
11273
11274 return this;
11275 };
11276
11277 // Or `num` with `this` in-place
11278 BN.prototype.iuor = function iuor (num) {
11279 while (this.length < num.length) {
11280 this.words[this.length++] = 0;
11281 }
11282
11283 for (var i = 0; i < num.length; i++) {
11284 this.words[i] = this.words[i] | num.words[i];
11285 }
11286
11287 return this.strip();
11288 };
11289
11290 BN.prototype.ior = function ior (num) {
11291 assert((this.negative | num.negative) === 0);
11292 return this.iuor(num);
11293 };
11294
11295 // Or `num` with `this`
11296 BN.prototype.or = function or (num) {
11297 if (this.length > num.length) return this.clone().ior(num);
11298 return num.clone().ior(this);
11299 };
11300
11301 BN.prototype.uor = function uor (num) {
11302 if (this.length > num.length) return this.clone().iuor(num);
11303 return num.clone().iuor(this);
11304 };
11305
11306 // And `num` with `this` in-place
11307 BN.prototype.iuand = function iuand (num) {
11308 // b = min-length(num, this)
11309 var b;
11310 if (this.length > num.length) {
11311 b = num;
11312 } else {
11313 b = this;
11314 }
11315
11316 for (var i = 0; i < b.length; i++) {
11317 this.words[i] = this.words[i] & num.words[i];
11318 }
11319
11320 this.length = b.length;
11321
11322 return this.strip();
11323 };
11324
11325 BN.prototype.iand = function iand (num) {
11326 assert((this.negative | num.negative) === 0);
11327 return this.iuand(num);
11328 };
11329
11330 // And `num` with `this`
11331 BN.prototype.and = function and (num) {
11332 if (this.length > num.length) return this.clone().iand(num);
11333 return num.clone().iand(this);
11334 };
11335
11336 BN.prototype.uand = function uand (num) {
11337 if (this.length > num.length) return this.clone().iuand(num);
11338 return num.clone().iuand(this);
11339 };
11340
11341 // Xor `num` with `this` in-place
11342 BN.prototype.iuxor = function iuxor (num) {
11343 // a.length > b.length
11344 var a;
11345 var b;
11346 if (this.length > num.length) {
11347 a = this;
11348 b = num;
11349 } else {
11350 a = num;
11351 b = this;
11352 }
11353
11354 for (var i = 0; i < b.length; i++) {
11355 this.words[i] = a.words[i] ^ b.words[i];
11356 }
11357
11358 if (this !== a) {
11359 for (; i < a.length; i++) {
11360 this.words[i] = a.words[i];
11361 }
11362 }
11363
11364 this.length = a.length;
11365
11366 return this.strip();
11367 };
11368
11369 BN.prototype.ixor = function ixor (num) {
11370 assert((this.negative | num.negative) === 0);
11371 return this.iuxor(num);
11372 };
11373
11374 // Xor `num` with `this`
11375 BN.prototype.xor = function xor (num) {
11376 if (this.length > num.length) return this.clone().ixor(num);
11377 return num.clone().ixor(this);
11378 };
11379
11380 BN.prototype.uxor = function uxor (num) {
11381 if (this.length > num.length) return this.clone().iuxor(num);
11382 return num.clone().iuxor(this);
11383 };
11384
11385 // Not ``this`` with ``width`` bitwidth
11386 BN.prototype.inotn = function inotn (width) {
11387 assert(typeof width === 'number' && width >= 0);
11388
11389 var bytesNeeded = Math.ceil(width / 26) | 0;
11390 var bitsLeft = width % 26;
11391
11392 // Extend the buffer with leading zeroes
11393 this._expand(bytesNeeded);
11394
11395 if (bitsLeft > 0) {
11396 bytesNeeded--;
11397 }
11398
11399 // Handle complete words
11400 for (var i = 0; i < bytesNeeded; i++) {
11401 this.words[i] = ~this.words[i] & 0x3ffffff;
11402 }
11403
11404 // Handle the residue
11405 if (bitsLeft > 0) {
11406 this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
11407 }
11408
11409 // And remove leading zeroes
11410 return this.strip();
11411 };
11412
11413 BN.prototype.notn = function notn (width) {
11414 return this.clone().inotn(width);
11415 };
11416
11417 // Set `bit` of `this`
11418 BN.prototype.setn = function setn (bit, val) {
11419 assert(typeof bit === 'number' && bit >= 0);
11420
11421 var off = (bit / 26) | 0;
11422 var wbit = bit % 26;
11423
11424 this._expand(off + 1);
11425
11426 if (val) {
11427 this.words[off] = this.words[off] | (1 << wbit);
11428 } else {
11429 this.words[off] = this.words[off] & ~(1 << wbit);
11430 }
11431
11432 return this.strip();
11433 };
11434
11435 // Add `num` to `this` in-place
11436 BN.prototype.iadd = function iadd (num) {
11437 var r;
11438
11439 // negative + positive
11440 if (this.negative !== 0 && num.negative === 0) {
11441 this.negative = 0;
11442 r = this.isub(num);
11443 this.negative ^= 1;
11444 return this._normSign();
11445
11446 // positive + negative
11447 } else if (this.negative === 0 && num.negative !== 0) {
11448 num.negative = 0;
11449 r = this.isub(num);
11450 num.negative = 1;
11451 return r._normSign();
11452 }
11453
11454 // a.length > b.length
11455 var a, b;
11456 if (this.length > num.length) {
11457 a = this;
11458 b = num;
11459 } else {
11460 a = num;
11461 b = this;
11462 }
11463
11464 var carry = 0;
11465 for (var i = 0; i < b.length; i++) {
11466 r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
11467 this.words[i] = r & 0x3ffffff;
11468 carry = r >>> 26;
11469 }
11470 for (; carry !== 0 && i < a.length; i++) {
11471 r = (a.words[i] | 0) + carry;
11472 this.words[i] = r & 0x3ffffff;
11473 carry = r >>> 26;
11474 }
11475
11476 this.length = a.length;
11477 if (carry !== 0) {
11478 this.words[this.length] = carry;
11479 this.length++;
11480 // Copy the rest of the words
11481 } else if (a !== this) {
11482 for (; i < a.length; i++) {
11483 this.words[i] = a.words[i];
11484 }
11485 }
11486
11487 return this;
11488 };
11489
11490 // Add `num` to `this`
11491 BN.prototype.add = function add (num) {
11492 var res;
11493 if (num.negative !== 0 && this.negative === 0) {
11494 num.negative = 0;
11495 res = this.sub(num);
11496 num.negative ^= 1;
11497 return res;
11498 } else if (num.negative === 0 && this.negative !== 0) {
11499 this.negative = 0;
11500 res = num.sub(this);
11501 this.negative = 1;
11502 return res;
11503 }
11504
11505 if (this.length > num.length) return this.clone().iadd(num);
11506
11507 return num.clone().iadd(this);
11508 };
11509
11510 // Subtract `num` from `this` in-place
11511 BN.prototype.isub = function isub (num) {
11512 // this - (-num) = this + num
11513 if (num.negative !== 0) {
11514 num.negative = 0;
11515 var r = this.iadd(num);
11516 num.negative = 1;
11517 return r._normSign();
11518
11519 // -this - num = -(this + num)
11520 } else if (this.negative !== 0) {
11521 this.negative = 0;
11522 this.iadd(num);
11523 this.negative = 1;
11524 return this._normSign();
11525 }
11526
11527 // At this point both numbers are positive
11528 var cmp = this.cmp(num);
11529
11530 // Optimization - zeroify
11531 if (cmp === 0) {
11532 this.negative = 0;
11533 this.length = 1;
11534 this.words[0] = 0;
11535 return this;
11536 }
11537
11538 // a > b
11539 var a, b;
11540 if (cmp > 0) {
11541 a = this;
11542 b = num;
11543 } else {
11544 a = num;
11545 b = this;
11546 }
11547
11548 var carry = 0;
11549 for (var i = 0; i < b.length; i++) {
11550 r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
11551 carry = r >> 26;
11552 this.words[i] = r & 0x3ffffff;
11553 }
11554 for (; carry !== 0 && i < a.length; i++) {
11555 r = (a.words[i] | 0) + carry;
11556 carry = r >> 26;
11557 this.words[i] = r & 0x3ffffff;
11558 }
11559
11560 // Copy rest of the words
11561 if (carry === 0 && i < a.length && a !== this) {
11562 for (; i < a.length; i++) {
11563 this.words[i] = a.words[i];
11564 }
11565 }
11566
11567 this.length = Math.max(this.length, i);
11568
11569 if (a !== this) {
11570 this.negative = 1;
11571 }
11572
11573 return this.strip();
11574 };
11575
11576 // Subtract `num` from `this`
11577 BN.prototype.sub = function sub (num) {
11578 return this.clone().isub(num);
11579 };
11580
11581 function smallMulTo (self, num, out) {
11582 out.negative = num.negative ^ self.negative;
11583 var len = (self.length + num.length) | 0;
11584 out.length = len;
11585 len = (len - 1) | 0;
11586
11587 // Peel one iteration (compiler can't do it, because of code complexity)
11588 var a = self.words[0] | 0;
11589 var b = num.words[0] | 0;
11590 var r = a * b;
11591
11592 var lo = r & 0x3ffffff;
11593 var carry = (r / 0x4000000) | 0;
11594 out.words[0] = lo;
11595
11596 for (var k = 1; k < len; k++) {
11597 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
11598 // note that ncarry could be >= 0x3ffffff
11599 var ncarry = carry >>> 26;
11600 var rword = carry & 0x3ffffff;
11601 var maxJ = Math.min(k, num.length - 1);
11602 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
11603 var i = (k - j) | 0;
11604 a = self.words[i] | 0;
11605 b = num.words[j] | 0;
11606 r = a * b + rword;
11607 ncarry += (r / 0x4000000) | 0;
11608 rword = r & 0x3ffffff;
11609 }
11610 out.words[k] = rword | 0;
11611 carry = ncarry | 0;
11612 }
11613 if (carry !== 0) {
11614 out.words[k] = carry | 0;
11615 } else {
11616 out.length--;
11617 }
11618
11619 return out.strip();
11620 }
11621
11622 // TODO(indutny): it may be reasonable to omit it for users who don't need
11623 // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
11624 // multiplication (like elliptic secp256k1).
11625 var comb10MulTo = function comb10MulTo (self, num, out) {
11626 var a = self.words;
11627 var b = num.words;
11628 var o = out.words;
11629 var c = 0;
11630 var lo;
11631 var mid;
11632 var hi;
11633 var a0 = a[0] | 0;
11634 var al0 = a0 & 0x1fff;
11635 var ah0 = a0 >>> 13;
11636 var a1 = a[1] | 0;
11637 var al1 = a1 & 0x1fff;
11638 var ah1 = a1 >>> 13;
11639 var a2 = a[2] | 0;
11640 var al2 = a2 & 0x1fff;
11641 var ah2 = a2 >>> 13;
11642 var a3 = a[3] | 0;
11643 var al3 = a3 & 0x1fff;
11644 var ah3 = a3 >>> 13;
11645 var a4 = a[4] | 0;
11646 var al4 = a4 & 0x1fff;
11647 var ah4 = a4 >>> 13;
11648 var a5 = a[5] | 0;
11649 var al5 = a5 & 0x1fff;
11650 var ah5 = a5 >>> 13;
11651 var a6 = a[6] | 0;
11652 var al6 = a6 & 0x1fff;
11653 var ah6 = a6 >>> 13;
11654 var a7 = a[7] | 0;
11655 var al7 = a7 & 0x1fff;
11656 var ah7 = a7 >>> 13;
11657 var a8 = a[8] | 0;
11658 var al8 = a8 & 0x1fff;
11659 var ah8 = a8 >>> 13;
11660 var a9 = a[9] | 0;
11661 var al9 = a9 & 0x1fff;
11662 var ah9 = a9 >>> 13;
11663 var b0 = b[0] | 0;
11664 var bl0 = b0 & 0x1fff;
11665 var bh0 = b0 >>> 13;
11666 var b1 = b[1] | 0;
11667 var bl1 = b1 & 0x1fff;
11668 var bh1 = b1 >>> 13;
11669 var b2 = b[2] | 0;
11670 var bl2 = b2 & 0x1fff;
11671 var bh2 = b2 >>> 13;
11672 var b3 = b[3] | 0;
11673 var bl3 = b3 & 0x1fff;
11674 var bh3 = b3 >>> 13;
11675 var b4 = b[4] | 0;
11676 var bl4 = b4 & 0x1fff;
11677 var bh4 = b4 >>> 13;
11678 var b5 = b[5] | 0;
11679 var bl5 = b5 & 0x1fff;
11680 var bh5 = b5 >>> 13;
11681 var b6 = b[6] | 0;
11682 var bl6 = b6 & 0x1fff;
11683 var bh6 = b6 >>> 13;
11684 var b7 = b[7] | 0;
11685 var bl7 = b7 & 0x1fff;
11686 var bh7 = b7 >>> 13;
11687 var b8 = b[8] | 0;
11688 var bl8 = b8 & 0x1fff;
11689 var bh8 = b8 >>> 13;
11690 var b9 = b[9] | 0;
11691 var bl9 = b9 & 0x1fff;
11692 var bh9 = b9 >>> 13;
11693
11694 out.negative = self.negative ^ num.negative;
11695 out.length = 19;
11696 /* k = 0 */
11697 lo = Math.imul(al0, bl0);
11698 mid = Math.imul(al0, bh0);
11699 mid = (mid + Math.imul(ah0, bl0)) | 0;
11700 hi = Math.imul(ah0, bh0);
11701 var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11702 c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
11703 w0 &= 0x3ffffff;
11704 /* k = 1 */
11705 lo = Math.imul(al1, bl0);
11706 mid = Math.imul(al1, bh0);
11707 mid = (mid + Math.imul(ah1, bl0)) | 0;
11708 hi = Math.imul(ah1, bh0);
11709 lo = (lo + Math.imul(al0, bl1)) | 0;
11710 mid = (mid + Math.imul(al0, bh1)) | 0;
11711 mid = (mid + Math.imul(ah0, bl1)) | 0;
11712 hi = (hi + Math.imul(ah0, bh1)) | 0;
11713 var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11714 c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
11715 w1 &= 0x3ffffff;
11716 /* k = 2 */
11717 lo = Math.imul(al2, bl0);
11718 mid = Math.imul(al2, bh0);
11719 mid = (mid + Math.imul(ah2, bl0)) | 0;
11720 hi = Math.imul(ah2, bh0);
11721 lo = (lo + Math.imul(al1, bl1)) | 0;
11722 mid = (mid + Math.imul(al1, bh1)) | 0;
11723 mid = (mid + Math.imul(ah1, bl1)) | 0;
11724 hi = (hi + Math.imul(ah1, bh1)) | 0;
11725 lo = (lo + Math.imul(al0, bl2)) | 0;
11726 mid = (mid + Math.imul(al0, bh2)) | 0;
11727 mid = (mid + Math.imul(ah0, bl2)) | 0;
11728 hi = (hi + Math.imul(ah0, bh2)) | 0;
11729 var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11730 c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
11731 w2 &= 0x3ffffff;
11732 /* k = 3 */
11733 lo = Math.imul(al3, bl0);
11734 mid = Math.imul(al3, bh0);
11735 mid = (mid + Math.imul(ah3, bl0)) | 0;
11736 hi = Math.imul(ah3, bh0);
11737 lo = (lo + Math.imul(al2, bl1)) | 0;
11738 mid = (mid + Math.imul(al2, bh1)) | 0;
11739 mid = (mid + Math.imul(ah2, bl1)) | 0;
11740 hi = (hi + Math.imul(ah2, bh1)) | 0;
11741 lo = (lo + Math.imul(al1, bl2)) | 0;
11742 mid = (mid + Math.imul(al1, bh2)) | 0;
11743 mid = (mid + Math.imul(ah1, bl2)) | 0;
11744 hi = (hi + Math.imul(ah1, bh2)) | 0;
11745 lo = (lo + Math.imul(al0, bl3)) | 0;
11746 mid = (mid + Math.imul(al0, bh3)) | 0;
11747 mid = (mid + Math.imul(ah0, bl3)) | 0;
11748 hi = (hi + Math.imul(ah0, bh3)) | 0;
11749 var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11750 c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
11751 w3 &= 0x3ffffff;
11752 /* k = 4 */
11753 lo = Math.imul(al4, bl0);
11754 mid = Math.imul(al4, bh0);
11755 mid = (mid + Math.imul(ah4, bl0)) | 0;
11756 hi = Math.imul(ah4, bh0);
11757 lo = (lo + Math.imul(al3, bl1)) | 0;
11758 mid = (mid + Math.imul(al3, bh1)) | 0;
11759 mid = (mid + Math.imul(ah3, bl1)) | 0;
11760 hi = (hi + Math.imul(ah3, bh1)) | 0;
11761 lo = (lo + Math.imul(al2, bl2)) | 0;
11762 mid = (mid + Math.imul(al2, bh2)) | 0;
11763 mid = (mid + Math.imul(ah2, bl2)) | 0;
11764 hi = (hi + Math.imul(ah2, bh2)) | 0;
11765 lo = (lo + Math.imul(al1, bl3)) | 0;
11766 mid = (mid + Math.imul(al1, bh3)) | 0;
11767 mid = (mid + Math.imul(ah1, bl3)) | 0;
11768 hi = (hi + Math.imul(ah1, bh3)) | 0;
11769 lo = (lo + Math.imul(al0, bl4)) | 0;
11770 mid = (mid + Math.imul(al0, bh4)) | 0;
11771 mid = (mid + Math.imul(ah0, bl4)) | 0;
11772 hi = (hi + Math.imul(ah0, bh4)) | 0;
11773 var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11774 c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
11775 w4 &= 0x3ffffff;
11776 /* k = 5 */
11777 lo = Math.imul(al5, bl0);
11778 mid = Math.imul(al5, bh0);
11779 mid = (mid + Math.imul(ah5, bl0)) | 0;
11780 hi = Math.imul(ah5, bh0);
11781 lo = (lo + Math.imul(al4, bl1)) | 0;
11782 mid = (mid + Math.imul(al4, bh1)) | 0;
11783 mid = (mid + Math.imul(ah4, bl1)) | 0;
11784 hi = (hi + Math.imul(ah4, bh1)) | 0;
11785 lo = (lo + Math.imul(al3, bl2)) | 0;
11786 mid = (mid + Math.imul(al3, bh2)) | 0;
11787 mid = (mid + Math.imul(ah3, bl2)) | 0;
11788 hi = (hi + Math.imul(ah3, bh2)) | 0;
11789 lo = (lo + Math.imul(al2, bl3)) | 0;
11790 mid = (mid + Math.imul(al2, bh3)) | 0;
11791 mid = (mid + Math.imul(ah2, bl3)) | 0;
11792 hi = (hi + Math.imul(ah2, bh3)) | 0;
11793 lo = (lo + Math.imul(al1, bl4)) | 0;
11794 mid = (mid + Math.imul(al1, bh4)) | 0;
11795 mid = (mid + Math.imul(ah1, bl4)) | 0;
11796 hi = (hi + Math.imul(ah1, bh4)) | 0;
11797 lo = (lo + Math.imul(al0, bl5)) | 0;
11798 mid = (mid + Math.imul(al0, bh5)) | 0;
11799 mid = (mid + Math.imul(ah0, bl5)) | 0;
11800 hi = (hi + Math.imul(ah0, bh5)) | 0;
11801 var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11802 c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
11803 w5 &= 0x3ffffff;
11804 /* k = 6 */
11805 lo = Math.imul(al6, bl0);
11806 mid = Math.imul(al6, bh0);
11807 mid = (mid + Math.imul(ah6, bl0)) | 0;
11808 hi = Math.imul(ah6, bh0);
11809 lo = (lo + Math.imul(al5, bl1)) | 0;
11810 mid = (mid + Math.imul(al5, bh1)) | 0;
11811 mid = (mid + Math.imul(ah5, bl1)) | 0;
11812 hi = (hi + Math.imul(ah5, bh1)) | 0;
11813 lo = (lo + Math.imul(al4, bl2)) | 0;
11814 mid = (mid + Math.imul(al4, bh2)) | 0;
11815 mid = (mid + Math.imul(ah4, bl2)) | 0;
11816 hi = (hi + Math.imul(ah4, bh2)) | 0;
11817 lo = (lo + Math.imul(al3, bl3)) | 0;
11818 mid = (mid + Math.imul(al3, bh3)) | 0;
11819 mid = (mid + Math.imul(ah3, bl3)) | 0;
11820 hi = (hi + Math.imul(ah3, bh3)) | 0;
11821 lo = (lo + Math.imul(al2, bl4)) | 0;
11822 mid = (mid + Math.imul(al2, bh4)) | 0;
11823 mid = (mid + Math.imul(ah2, bl4)) | 0;
11824 hi = (hi + Math.imul(ah2, bh4)) | 0;
11825 lo = (lo + Math.imul(al1, bl5)) | 0;
11826 mid = (mid + Math.imul(al1, bh5)) | 0;
11827 mid = (mid + Math.imul(ah1, bl5)) | 0;
11828 hi = (hi + Math.imul(ah1, bh5)) | 0;
11829 lo = (lo + Math.imul(al0, bl6)) | 0;
11830 mid = (mid + Math.imul(al0, bh6)) | 0;
11831 mid = (mid + Math.imul(ah0, bl6)) | 0;
11832 hi = (hi + Math.imul(ah0, bh6)) | 0;
11833 var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11834 c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
11835 w6 &= 0x3ffffff;
11836 /* k = 7 */
11837 lo = Math.imul(al7, bl0);
11838 mid = Math.imul(al7, bh0);
11839 mid = (mid + Math.imul(ah7, bl0)) | 0;
11840 hi = Math.imul(ah7, bh0);
11841 lo = (lo + Math.imul(al6, bl1)) | 0;
11842 mid = (mid + Math.imul(al6, bh1)) | 0;
11843 mid = (mid + Math.imul(ah6, bl1)) | 0;
11844 hi = (hi + Math.imul(ah6, bh1)) | 0;
11845 lo = (lo + Math.imul(al5, bl2)) | 0;
11846 mid = (mid + Math.imul(al5, bh2)) | 0;
11847 mid = (mid + Math.imul(ah5, bl2)) | 0;
11848 hi = (hi + Math.imul(ah5, bh2)) | 0;
11849 lo = (lo + Math.imul(al4, bl3)) | 0;
11850 mid = (mid + Math.imul(al4, bh3)) | 0;
11851 mid = (mid + Math.imul(ah4, bl3)) | 0;
11852 hi = (hi + Math.imul(ah4, bh3)) | 0;
11853 lo = (lo + Math.imul(al3, bl4)) | 0;
11854 mid = (mid + Math.imul(al3, bh4)) | 0;
11855 mid = (mid + Math.imul(ah3, bl4)) | 0;
11856 hi = (hi + Math.imul(ah3, bh4)) | 0;
11857 lo = (lo + Math.imul(al2, bl5)) | 0;
11858 mid = (mid + Math.imul(al2, bh5)) | 0;
11859 mid = (mid + Math.imul(ah2, bl5)) | 0;
11860 hi = (hi + Math.imul(ah2, bh5)) | 0;
11861 lo = (lo + Math.imul(al1, bl6)) | 0;
11862 mid = (mid + Math.imul(al1, bh6)) | 0;
11863 mid = (mid + Math.imul(ah1, bl6)) | 0;
11864 hi = (hi + Math.imul(ah1, bh6)) | 0;
11865 lo = (lo + Math.imul(al0, bl7)) | 0;
11866 mid = (mid + Math.imul(al0, bh7)) | 0;
11867 mid = (mid + Math.imul(ah0, bl7)) | 0;
11868 hi = (hi + Math.imul(ah0, bh7)) | 0;
11869 var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11870 c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
11871 w7 &= 0x3ffffff;
11872 /* k = 8 */
11873 lo = Math.imul(al8, bl0);
11874 mid = Math.imul(al8, bh0);
11875 mid = (mid + Math.imul(ah8, bl0)) | 0;
11876 hi = Math.imul(ah8, bh0);
11877 lo = (lo + Math.imul(al7, bl1)) | 0;
11878 mid = (mid + Math.imul(al7, bh1)) | 0;
11879 mid = (mid + Math.imul(ah7, bl1)) | 0;
11880 hi = (hi + Math.imul(ah7, bh1)) | 0;
11881 lo = (lo + Math.imul(al6, bl2)) | 0;
11882 mid = (mid + Math.imul(al6, bh2)) | 0;
11883 mid = (mid + Math.imul(ah6, bl2)) | 0;
11884 hi = (hi + Math.imul(ah6, bh2)) | 0;
11885 lo = (lo + Math.imul(al5, bl3)) | 0;
11886 mid = (mid + Math.imul(al5, bh3)) | 0;
11887 mid = (mid + Math.imul(ah5, bl3)) | 0;
11888 hi = (hi + Math.imul(ah5, bh3)) | 0;
11889 lo = (lo + Math.imul(al4, bl4)) | 0;
11890 mid = (mid + Math.imul(al4, bh4)) | 0;
11891 mid = (mid + Math.imul(ah4, bl4)) | 0;
11892 hi = (hi + Math.imul(ah4, bh4)) | 0;
11893 lo = (lo + Math.imul(al3, bl5)) | 0;
11894 mid = (mid + Math.imul(al3, bh5)) | 0;
11895 mid = (mid + Math.imul(ah3, bl5)) | 0;
11896 hi = (hi + Math.imul(ah3, bh5)) | 0;
11897 lo = (lo + Math.imul(al2, bl6)) | 0;
11898 mid = (mid + Math.imul(al2, bh6)) | 0;
11899 mid = (mid + Math.imul(ah2, bl6)) | 0;
11900 hi = (hi + Math.imul(ah2, bh6)) | 0;
11901 lo = (lo + Math.imul(al1, bl7)) | 0;
11902 mid = (mid + Math.imul(al1, bh7)) | 0;
11903 mid = (mid + Math.imul(ah1, bl7)) | 0;
11904 hi = (hi + Math.imul(ah1, bh7)) | 0;
11905 lo = (lo + Math.imul(al0, bl8)) | 0;
11906 mid = (mid + Math.imul(al0, bh8)) | 0;
11907 mid = (mid + Math.imul(ah0, bl8)) | 0;
11908 hi = (hi + Math.imul(ah0, bh8)) | 0;
11909 var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11910 c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
11911 w8 &= 0x3ffffff;
11912 /* k = 9 */
11913 lo = Math.imul(al9, bl0);
11914 mid = Math.imul(al9, bh0);
11915 mid = (mid + Math.imul(ah9, bl0)) | 0;
11916 hi = Math.imul(ah9, bh0);
11917 lo = (lo + Math.imul(al8, bl1)) | 0;
11918 mid = (mid + Math.imul(al8, bh1)) | 0;
11919 mid = (mid + Math.imul(ah8, bl1)) | 0;
11920 hi = (hi + Math.imul(ah8, bh1)) | 0;
11921 lo = (lo + Math.imul(al7, bl2)) | 0;
11922 mid = (mid + Math.imul(al7, bh2)) | 0;
11923 mid = (mid + Math.imul(ah7, bl2)) | 0;
11924 hi = (hi + Math.imul(ah7, bh2)) | 0;
11925 lo = (lo + Math.imul(al6, bl3)) | 0;
11926 mid = (mid + Math.imul(al6, bh3)) | 0;
11927 mid = (mid + Math.imul(ah6, bl3)) | 0;
11928 hi = (hi + Math.imul(ah6, bh3)) | 0;
11929 lo = (lo + Math.imul(al5, bl4)) | 0;
11930 mid = (mid + Math.imul(al5, bh4)) | 0;
11931 mid = (mid + Math.imul(ah5, bl4)) | 0;
11932 hi = (hi + Math.imul(ah5, bh4)) | 0;
11933 lo = (lo + Math.imul(al4, bl5)) | 0;
11934 mid = (mid + Math.imul(al4, bh5)) | 0;
11935 mid = (mid + Math.imul(ah4, bl5)) | 0;
11936 hi = (hi + Math.imul(ah4, bh5)) | 0;
11937 lo = (lo + Math.imul(al3, bl6)) | 0;
11938 mid = (mid + Math.imul(al3, bh6)) | 0;
11939 mid = (mid + Math.imul(ah3, bl6)) | 0;
11940 hi = (hi + Math.imul(ah3, bh6)) | 0;
11941 lo = (lo + Math.imul(al2, bl7)) | 0;
11942 mid = (mid + Math.imul(al2, bh7)) | 0;
11943 mid = (mid + Math.imul(ah2, bl7)) | 0;
11944 hi = (hi + Math.imul(ah2, bh7)) | 0;
11945 lo = (lo + Math.imul(al1, bl8)) | 0;
11946 mid = (mid + Math.imul(al1, bh8)) | 0;
11947 mid = (mid + Math.imul(ah1, bl8)) | 0;
11948 hi = (hi + Math.imul(ah1, bh8)) | 0;
11949 lo = (lo + Math.imul(al0, bl9)) | 0;
11950 mid = (mid + Math.imul(al0, bh9)) | 0;
11951 mid = (mid + Math.imul(ah0, bl9)) | 0;
11952 hi = (hi + Math.imul(ah0, bh9)) | 0;
11953 var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11954 c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
11955 w9 &= 0x3ffffff;
11956 /* k = 10 */
11957 lo = Math.imul(al9, bl1);
11958 mid = Math.imul(al9, bh1);
11959 mid = (mid + Math.imul(ah9, bl1)) | 0;
11960 hi = Math.imul(ah9, bh1);
11961 lo = (lo + Math.imul(al8, bl2)) | 0;
11962 mid = (mid + Math.imul(al8, bh2)) | 0;
11963 mid = (mid + Math.imul(ah8, bl2)) | 0;
11964 hi = (hi + Math.imul(ah8, bh2)) | 0;
11965 lo = (lo + Math.imul(al7, bl3)) | 0;
11966 mid = (mid + Math.imul(al7, bh3)) | 0;
11967 mid = (mid + Math.imul(ah7, bl3)) | 0;
11968 hi = (hi + Math.imul(ah7, bh3)) | 0;
11969 lo = (lo + Math.imul(al6, bl4)) | 0;
11970 mid = (mid + Math.imul(al6, bh4)) | 0;
11971 mid = (mid + Math.imul(ah6, bl4)) | 0;
11972 hi = (hi + Math.imul(ah6, bh4)) | 0;
11973 lo = (lo + Math.imul(al5, bl5)) | 0;
11974 mid = (mid + Math.imul(al5, bh5)) | 0;
11975 mid = (mid + Math.imul(ah5, bl5)) | 0;
11976 hi = (hi + Math.imul(ah5, bh5)) | 0;
11977 lo = (lo + Math.imul(al4, bl6)) | 0;
11978 mid = (mid + Math.imul(al4, bh6)) | 0;
11979 mid = (mid + Math.imul(ah4, bl6)) | 0;
11980 hi = (hi + Math.imul(ah4, bh6)) | 0;
11981 lo = (lo + Math.imul(al3, bl7)) | 0;
11982 mid = (mid + Math.imul(al3, bh7)) | 0;
11983 mid = (mid + Math.imul(ah3, bl7)) | 0;
11984 hi = (hi + Math.imul(ah3, bh7)) | 0;
11985 lo = (lo + Math.imul(al2, bl8)) | 0;
11986 mid = (mid + Math.imul(al2, bh8)) | 0;
11987 mid = (mid + Math.imul(ah2, bl8)) | 0;
11988 hi = (hi + Math.imul(ah2, bh8)) | 0;
11989 lo = (lo + Math.imul(al1, bl9)) | 0;
11990 mid = (mid + Math.imul(al1, bh9)) | 0;
11991 mid = (mid + Math.imul(ah1, bl9)) | 0;
11992 hi = (hi + Math.imul(ah1, bh9)) | 0;
11993 var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
11994 c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
11995 w10 &= 0x3ffffff;
11996 /* k = 11 */
11997 lo = Math.imul(al9, bl2);
11998 mid = Math.imul(al9, bh2);
11999 mid = (mid + Math.imul(ah9, bl2)) | 0;
12000 hi = Math.imul(ah9, bh2);
12001 lo = (lo + Math.imul(al8, bl3)) | 0;
12002 mid = (mid + Math.imul(al8, bh3)) | 0;
12003 mid = (mid + Math.imul(ah8, bl3)) | 0;
12004 hi = (hi + Math.imul(ah8, bh3)) | 0;
12005 lo = (lo + Math.imul(al7, bl4)) | 0;
12006 mid = (mid + Math.imul(al7, bh4)) | 0;
12007 mid = (mid + Math.imul(ah7, bl4)) | 0;
12008 hi = (hi + Math.imul(ah7, bh4)) | 0;
12009 lo = (lo + Math.imul(al6, bl5)) | 0;
12010 mid = (mid + Math.imul(al6, bh5)) | 0;
12011 mid = (mid + Math.imul(ah6, bl5)) | 0;
12012 hi = (hi + Math.imul(ah6, bh5)) | 0;
12013 lo = (lo + Math.imul(al5, bl6)) | 0;
12014 mid = (mid + Math.imul(al5, bh6)) | 0;
12015 mid = (mid + Math.imul(ah5, bl6)) | 0;
12016 hi = (hi + Math.imul(ah5, bh6)) | 0;
12017 lo = (lo + Math.imul(al4, bl7)) | 0;
12018 mid = (mid + Math.imul(al4, bh7)) | 0;
12019 mid = (mid + Math.imul(ah4, bl7)) | 0;
12020 hi = (hi + Math.imul(ah4, bh7)) | 0;
12021 lo = (lo + Math.imul(al3, bl8)) | 0;
12022 mid = (mid + Math.imul(al3, bh8)) | 0;
12023 mid = (mid + Math.imul(ah3, bl8)) | 0;
12024 hi = (hi + Math.imul(ah3, bh8)) | 0;
12025 lo = (lo + Math.imul(al2, bl9)) | 0;
12026 mid = (mid + Math.imul(al2, bh9)) | 0;
12027 mid = (mid + Math.imul(ah2, bl9)) | 0;
12028 hi = (hi + Math.imul(ah2, bh9)) | 0;
12029 var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12030 c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
12031 w11 &= 0x3ffffff;
12032 /* k = 12 */
12033 lo = Math.imul(al9, bl3);
12034 mid = Math.imul(al9, bh3);
12035 mid = (mid + Math.imul(ah9, bl3)) | 0;
12036 hi = Math.imul(ah9, bh3);
12037 lo = (lo + Math.imul(al8, bl4)) | 0;
12038 mid = (mid + Math.imul(al8, bh4)) | 0;
12039 mid = (mid + Math.imul(ah8, bl4)) | 0;
12040 hi = (hi + Math.imul(ah8, bh4)) | 0;
12041 lo = (lo + Math.imul(al7, bl5)) | 0;
12042 mid = (mid + Math.imul(al7, bh5)) | 0;
12043 mid = (mid + Math.imul(ah7, bl5)) | 0;
12044 hi = (hi + Math.imul(ah7, bh5)) | 0;
12045 lo = (lo + Math.imul(al6, bl6)) | 0;
12046 mid = (mid + Math.imul(al6, bh6)) | 0;
12047 mid = (mid + Math.imul(ah6, bl6)) | 0;
12048 hi = (hi + Math.imul(ah6, bh6)) | 0;
12049 lo = (lo + Math.imul(al5, bl7)) | 0;
12050 mid = (mid + Math.imul(al5, bh7)) | 0;
12051 mid = (mid + Math.imul(ah5, bl7)) | 0;
12052 hi = (hi + Math.imul(ah5, bh7)) | 0;
12053 lo = (lo + Math.imul(al4, bl8)) | 0;
12054 mid = (mid + Math.imul(al4, bh8)) | 0;
12055 mid = (mid + Math.imul(ah4, bl8)) | 0;
12056 hi = (hi + Math.imul(ah4, bh8)) | 0;
12057 lo = (lo + Math.imul(al3, bl9)) | 0;
12058 mid = (mid + Math.imul(al3, bh9)) | 0;
12059 mid = (mid + Math.imul(ah3, bl9)) | 0;
12060 hi = (hi + Math.imul(ah3, bh9)) | 0;
12061 var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12062 c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
12063 w12 &= 0x3ffffff;
12064 /* k = 13 */
12065 lo = Math.imul(al9, bl4);
12066 mid = Math.imul(al9, bh4);
12067 mid = (mid + Math.imul(ah9, bl4)) | 0;
12068 hi = Math.imul(ah9, bh4);
12069 lo = (lo + Math.imul(al8, bl5)) | 0;
12070 mid = (mid + Math.imul(al8, bh5)) | 0;
12071 mid = (mid + Math.imul(ah8, bl5)) | 0;
12072 hi = (hi + Math.imul(ah8, bh5)) | 0;
12073 lo = (lo + Math.imul(al7, bl6)) | 0;
12074 mid = (mid + Math.imul(al7, bh6)) | 0;
12075 mid = (mid + Math.imul(ah7, bl6)) | 0;
12076 hi = (hi + Math.imul(ah7, bh6)) | 0;
12077 lo = (lo + Math.imul(al6, bl7)) | 0;
12078 mid = (mid + Math.imul(al6, bh7)) | 0;
12079 mid = (mid + Math.imul(ah6, bl7)) | 0;
12080 hi = (hi + Math.imul(ah6, bh7)) | 0;
12081 lo = (lo + Math.imul(al5, bl8)) | 0;
12082 mid = (mid + Math.imul(al5, bh8)) | 0;
12083 mid = (mid + Math.imul(ah5, bl8)) | 0;
12084 hi = (hi + Math.imul(ah5, bh8)) | 0;
12085 lo = (lo + Math.imul(al4, bl9)) | 0;
12086 mid = (mid + Math.imul(al4, bh9)) | 0;
12087 mid = (mid + Math.imul(ah4, bl9)) | 0;
12088 hi = (hi + Math.imul(ah4, bh9)) | 0;
12089 var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12090 c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
12091 w13 &= 0x3ffffff;
12092 /* k = 14 */
12093 lo = Math.imul(al9, bl5);
12094 mid = Math.imul(al9, bh5);
12095 mid = (mid + Math.imul(ah9, bl5)) | 0;
12096 hi = Math.imul(ah9, bh5);
12097 lo = (lo + Math.imul(al8, bl6)) | 0;
12098 mid = (mid + Math.imul(al8, bh6)) | 0;
12099 mid = (mid + Math.imul(ah8, bl6)) | 0;
12100 hi = (hi + Math.imul(ah8, bh6)) | 0;
12101 lo = (lo + Math.imul(al7, bl7)) | 0;
12102 mid = (mid + Math.imul(al7, bh7)) | 0;
12103 mid = (mid + Math.imul(ah7, bl7)) | 0;
12104 hi = (hi + Math.imul(ah7, bh7)) | 0;
12105 lo = (lo + Math.imul(al6, bl8)) | 0;
12106 mid = (mid + Math.imul(al6, bh8)) | 0;
12107 mid = (mid + Math.imul(ah6, bl8)) | 0;
12108 hi = (hi + Math.imul(ah6, bh8)) | 0;
12109 lo = (lo + Math.imul(al5, bl9)) | 0;
12110 mid = (mid + Math.imul(al5, bh9)) | 0;
12111 mid = (mid + Math.imul(ah5, bl9)) | 0;
12112 hi = (hi + Math.imul(ah5, bh9)) | 0;
12113 var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12114 c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
12115 w14 &= 0x3ffffff;
12116 /* k = 15 */
12117 lo = Math.imul(al9, bl6);
12118 mid = Math.imul(al9, bh6);
12119 mid = (mid + Math.imul(ah9, bl6)) | 0;
12120 hi = Math.imul(ah9, bh6);
12121 lo = (lo + Math.imul(al8, bl7)) | 0;
12122 mid = (mid + Math.imul(al8, bh7)) | 0;
12123 mid = (mid + Math.imul(ah8, bl7)) | 0;
12124 hi = (hi + Math.imul(ah8, bh7)) | 0;
12125 lo = (lo + Math.imul(al7, bl8)) | 0;
12126 mid = (mid + Math.imul(al7, bh8)) | 0;
12127 mid = (mid + Math.imul(ah7, bl8)) | 0;
12128 hi = (hi + Math.imul(ah7, bh8)) | 0;
12129 lo = (lo + Math.imul(al6, bl9)) | 0;
12130 mid = (mid + Math.imul(al6, bh9)) | 0;
12131 mid = (mid + Math.imul(ah6, bl9)) | 0;
12132 hi = (hi + Math.imul(ah6, bh9)) | 0;
12133 var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12134 c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
12135 w15 &= 0x3ffffff;
12136 /* k = 16 */
12137 lo = Math.imul(al9, bl7);
12138 mid = Math.imul(al9, bh7);
12139 mid = (mid + Math.imul(ah9, bl7)) | 0;
12140 hi = Math.imul(ah9, bh7);
12141 lo = (lo + Math.imul(al8, bl8)) | 0;
12142 mid = (mid + Math.imul(al8, bh8)) | 0;
12143 mid = (mid + Math.imul(ah8, bl8)) | 0;
12144 hi = (hi + Math.imul(ah8, bh8)) | 0;
12145 lo = (lo + Math.imul(al7, bl9)) | 0;
12146 mid = (mid + Math.imul(al7, bh9)) | 0;
12147 mid = (mid + Math.imul(ah7, bl9)) | 0;
12148 hi = (hi + Math.imul(ah7, bh9)) | 0;
12149 var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12150 c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
12151 w16 &= 0x3ffffff;
12152 /* k = 17 */
12153 lo = Math.imul(al9, bl8);
12154 mid = Math.imul(al9, bh8);
12155 mid = (mid + Math.imul(ah9, bl8)) | 0;
12156 hi = Math.imul(ah9, bh8);
12157 lo = (lo + Math.imul(al8, bl9)) | 0;
12158 mid = (mid + Math.imul(al8, bh9)) | 0;
12159 mid = (mid + Math.imul(ah8, bl9)) | 0;
12160 hi = (hi + Math.imul(ah8, bh9)) | 0;
12161 var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12162 c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
12163 w17 &= 0x3ffffff;
12164 /* k = 18 */
12165 lo = Math.imul(al9, bl9);
12166 mid = Math.imul(al9, bh9);
12167 mid = (mid + Math.imul(ah9, bl9)) | 0;
12168 hi = Math.imul(ah9, bh9);
12169 var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
12170 c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
12171 w18 &= 0x3ffffff;
12172 o[0] = w0;
12173 o[1] = w1;
12174 o[2] = w2;
12175 o[3] = w3;
12176 o[4] = w4;
12177 o[5] = w5;
12178 o[6] = w6;
12179 o[7] = w7;
12180 o[8] = w8;
12181 o[9] = w9;
12182 o[10] = w10;
12183 o[11] = w11;
12184 o[12] = w12;
12185 o[13] = w13;
12186 o[14] = w14;
12187 o[15] = w15;
12188 o[16] = w16;
12189 o[17] = w17;
12190 o[18] = w18;
12191 if (c !== 0) {
12192 o[19] = c;
12193 out.length++;
12194 }
12195 return out;
12196 };
12197
12198 // Polyfill comb
12199 if (!Math.imul) {
12200 comb10MulTo = smallMulTo;
12201 }
12202
12203 function bigMulTo (self, num, out) {
12204 out.negative = num.negative ^ self.negative;
12205 out.length = self.length + num.length;
12206
12207 var carry = 0;
12208 var hncarry = 0;
12209 for (var k = 0; k < out.length - 1; k++) {
12210 // Sum all words with the same `i + j = k` and accumulate `ncarry`,
12211 // note that ncarry could be >= 0x3ffffff
12212 var ncarry = hncarry;
12213 hncarry = 0;
12214 var rword = carry & 0x3ffffff;
12215 var maxJ = Math.min(k, num.length - 1);
12216 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
12217 var i = k - j;
12218 var a = self.words[i] | 0;
12219 var b = num.words[j] | 0;
12220 var r = a * b;
12221
12222 var lo = r & 0x3ffffff;
12223 ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
12224 lo = (lo + rword) | 0;
12225 rword = lo & 0x3ffffff;
12226 ncarry = (ncarry + (lo >>> 26)) | 0;
12227
12228 hncarry += ncarry >>> 26;
12229 ncarry &= 0x3ffffff;
12230 }
12231 out.words[k] = rword;
12232 carry = ncarry;
12233 ncarry = hncarry;
12234 }
12235 if (carry !== 0) {
12236 out.words[k] = carry;
12237 } else {
12238 out.length--;
12239 }
12240
12241 return out.strip();
12242 }
12243
12244 function jumboMulTo (self, num, out) {
12245 var fftm = new FFTM();
12246 return fftm.mulp(self, num, out);
12247 }
12248
12249 BN.prototype.mulTo = function mulTo (num, out) {
12250 var res;
12251 var len = this.length + num.length;
12252 if (this.length === 10 && num.length === 10) {
12253 res = comb10MulTo(this, num, out);
12254 } else if (len < 63) {
12255 res = smallMulTo(this, num, out);
12256 } else if (len < 1024) {
12257 res = bigMulTo(this, num, out);
12258 } else {
12259 res = jumboMulTo(this, num, out);
12260 }
12261
12262 return res;
12263 };
12264
12265 // Cooley-Tukey algorithm for FFT
12266 // slightly revisited to rely on looping instead of recursion
12267
12268 function FFTM (x, y) {
12269 this.x = x;
12270 this.y = y;
12271 }
12272
12273 FFTM.prototype.makeRBT = function makeRBT (N) {
12274 var t = new Array(N);
12275 var l = BN.prototype._countBits(N) - 1;
12276 for (var i = 0; i < N; i++) {
12277 t[i] = this.revBin(i, l, N);
12278 }
12279
12280 return t;
12281 };
12282
12283 // Returns binary-reversed representation of `x`
12284 FFTM.prototype.revBin = function revBin (x, l, N) {
12285 if (x === 0 || x === N - 1) return x;
12286
12287 var rb = 0;
12288 for (var i = 0; i < l; i++) {
12289 rb |= (x & 1) << (l - i - 1);
12290 x >>= 1;
12291 }
12292
12293 return rb;
12294 };
12295
12296 // Performs "tweedling" phase, therefore 'emulating'
12297 // behaviour of the recursive algorithm
12298 FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
12299 for (var i = 0; i < N; i++) {
12300 rtws[i] = rws[rbt[i]];
12301 itws[i] = iws[rbt[i]];
12302 }
12303 };
12304
12305 FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
12306 this.permute(rbt, rws, iws, rtws, itws, N);
12307
12308 for (var s = 1; s < N; s <<= 1) {
12309 var l = s << 1;
12310
12311 var rtwdf = Math.cos(2 * Math.PI / l);
12312 var itwdf = Math.sin(2 * Math.PI / l);
12313
12314 for (var p = 0; p < N; p += l) {
12315 var rtwdf_ = rtwdf;
12316 var itwdf_ = itwdf;
12317
12318 for (var j = 0; j < s; j++) {
12319 var re = rtws[p + j];
12320 var ie = itws[p + j];
12321
12322 var ro = rtws[p + j + s];
12323 var io = itws[p + j + s];
12324
12325 var rx = rtwdf_ * ro - itwdf_ * io;
12326
12327 io = rtwdf_ * io + itwdf_ * ro;
12328 ro = rx;
12329
12330 rtws[p + j] = re + ro;
12331 itws[p + j] = ie + io;
12332
12333 rtws[p + j + s] = re - ro;
12334 itws[p + j + s] = ie - io;
12335
12336 /* jshint maxdepth : false */
12337 if (j !== l) {
12338 rx = rtwdf * rtwdf_ - itwdf * itwdf_;
12339
12340 itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
12341 rtwdf_ = rx;
12342 }
12343 }
12344 }
12345 }
12346 };
12347
12348 FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
12349 var N = Math.max(m, n) | 1;
12350 var odd = N & 1;
12351 var i = 0;
12352 for (N = N / 2 | 0; N; N = N >>> 1) {
12353 i++;
12354 }
12355
12356 return 1 << i + 1 + odd;
12357 };
12358
12359 FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
12360 if (N <= 1) return;
12361
12362 for (var i = 0; i < N / 2; i++) {
12363 var t = rws[i];
12364
12365 rws[i] = rws[N - i - 1];
12366 rws[N - i - 1] = t;
12367
12368 t = iws[i];
12369
12370 iws[i] = -iws[N - i - 1];
12371 iws[N - i - 1] = -t;
12372 }
12373 };
12374
12375 FFTM.prototype.normalize13b = function normalize13b (ws, N) {
12376 var carry = 0;
12377 for (var i = 0; i < N / 2; i++) {
12378 var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
12379 Math.round(ws[2 * i] / N) +
12380 carry;
12381
12382 ws[i] = w & 0x3ffffff;
12383
12384 if (w < 0x4000000) {
12385 carry = 0;
12386 } else {
12387 carry = w / 0x4000000 | 0;
12388 }
12389 }
12390
12391 return ws;
12392 };
12393
12394 FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
12395 var carry = 0;
12396 for (var i = 0; i < len; i++) {
12397 carry = carry + (ws[i] | 0);
12398
12399 rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
12400 rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
12401 }
12402
12403 // Pad with zeroes
12404 for (i = 2 * len; i < N; ++i) {
12405 rws[i] = 0;
12406 }
12407
12408 assert(carry === 0);
12409 assert((carry & ~0x1fff) === 0);
12410 };
12411
12412 FFTM.prototype.stub = function stub (N) {
12413 var ph = new Array(N);
12414 for (var i = 0; i < N; i++) {
12415 ph[i] = 0;
12416 }
12417
12418 return ph;
12419 };
12420
12421 FFTM.prototype.mulp = function mulp (x, y, out) {
12422 var N = 2 * this.guessLen13b(x.length, y.length);
12423
12424 var rbt = this.makeRBT(N);
12425
12426 var _ = this.stub(N);
12427
12428 var rws = new Array(N);
12429 var rwst = new Array(N);
12430 var iwst = new Array(N);
12431
12432 var nrws = new Array(N);
12433 var nrwst = new Array(N);
12434 var niwst = new Array(N);
12435
12436 var rmws = out.words;
12437 rmws.length = N;
12438
12439 this.convert13b(x.words, x.length, rws, N);
12440 this.convert13b(y.words, y.length, nrws, N);
12441
12442 this.transform(rws, _, rwst, iwst, N, rbt);
12443 this.transform(nrws, _, nrwst, niwst, N, rbt);
12444
12445 for (var i = 0; i < N; i++) {
12446 var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
12447 iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
12448 rwst[i] = rx;
12449 }
12450
12451 this.conjugate(rwst, iwst, N);
12452 this.transform(rwst, iwst, rmws, _, N, rbt);
12453 this.conjugate(rmws, _, N);
12454 this.normalize13b(rmws, N);
12455
12456 out.negative = x.negative ^ y.negative;
12457 out.length = x.length + y.length;
12458 return out.strip();
12459 };
12460
12461 // Multiply `this` by `num`
12462 BN.prototype.mul = function mul (num) {
12463 var out = new BN(null);
12464 out.words = new Array(this.length + num.length);
12465 return this.mulTo(num, out);
12466 };
12467
12468 // Multiply employing FFT
12469 BN.prototype.mulf = function mulf (num) {
12470 var out = new BN(null);
12471 out.words = new Array(this.length + num.length);
12472 return jumboMulTo(this, num, out);
12473 };
12474
12475 // In-place Multiplication
12476 BN.prototype.imul = function imul (num) {
12477 return this.clone().mulTo(num, this);
12478 };
12479
12480 BN.prototype.imuln = function imuln (num) {
12481 assert(typeof num === 'number');
12482 assert(num < 0x4000000);
12483
12484 // Carry
12485 var carry = 0;
12486 for (var i = 0; i < this.length; i++) {
12487 var w = (this.words[i] | 0) * num;
12488 var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
12489 carry >>= 26;
12490 carry += (w / 0x4000000) | 0;
12491 // NOTE: lo is 27bit maximum
12492 carry += lo >>> 26;
12493 this.words[i] = lo & 0x3ffffff;
12494 }
12495
12496 if (carry !== 0) {
12497 this.words[i] = carry;
12498 this.length++;
12499 }
12500
12501 return this;
12502 };
12503
12504 BN.prototype.muln = function muln (num) {
12505 return this.clone().imuln(num);
12506 };
12507
12508 // `this` * `this`
12509 BN.prototype.sqr = function sqr () {
12510 return this.mul(this);
12511 };
12512
12513 // `this` * `this` in-place
12514 BN.prototype.isqr = function isqr () {
12515 return this.imul(this.clone());
12516 };
12517
12518 // Math.pow(`this`, `num`)
12519 BN.prototype.pow = function pow (num) {
12520 var w = toBitArray(num);
12521 if (w.length === 0) return new BN(1);
12522
12523 // Skip leading zeroes
12524 var res = this;
12525 for (var i = 0; i < w.length; i++, res = res.sqr()) {
12526 if (w[i] !== 0) break;
12527 }
12528
12529 if (++i < w.length) {
12530 for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
12531 if (w[i] === 0) continue;
12532
12533 res = res.mul(q);
12534 }
12535 }
12536
12537 return res;
12538 };
12539
12540 // Shift-left in-place
12541 BN.prototype.iushln = function iushln (bits) {
12542 assert(typeof bits === 'number' && bits >= 0);
12543 var r = bits % 26;
12544 var s = (bits - r) / 26;
12545 var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
12546 var i;
12547
12548 if (r !== 0) {
12549 var carry = 0;
12550
12551 for (i = 0; i < this.length; i++) {
12552 var newCarry = this.words[i] & carryMask;
12553 var c = ((this.words[i] | 0) - newCarry) << r;
12554 this.words[i] = c | carry;
12555 carry = newCarry >>> (26 - r);
12556 }
12557
12558 if (carry) {
12559 this.words[i] = carry;
12560 this.length++;
12561 }
12562 }
12563
12564 if (s !== 0) {
12565 for (i = this.length - 1; i >= 0; i--) {
12566 this.words[i + s] = this.words[i];
12567 }
12568
12569 for (i = 0; i < s; i++) {
12570 this.words[i] = 0;
12571 }
12572
12573 this.length += s;
12574 }
12575
12576 return this.strip();
12577 };
12578
12579 BN.prototype.ishln = function ishln (bits) {
12580 // TODO(indutny): implement me
12581 assert(this.negative === 0);
12582 return this.iushln(bits);
12583 };
12584
12585 // Shift-right in-place
12586 // NOTE: `hint` is a lowest bit before trailing zeroes
12587 // NOTE: if `extended` is present - it will be filled with destroyed bits
12588 BN.prototype.iushrn = function iushrn (bits, hint, extended) {
12589 assert(typeof bits === 'number' && bits >= 0);
12590 var h;
12591 if (hint) {
12592 h = (hint - (hint % 26)) / 26;
12593 } else {
12594 h = 0;
12595 }
12596
12597 var r = bits % 26;
12598 var s = Math.min((bits - r) / 26, this.length);
12599 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
12600 var maskedWords = extended;
12601
12602 h -= s;
12603 h = Math.max(0, h);
12604
12605 // Extended mode, copy masked part
12606 if (maskedWords) {
12607 for (var i = 0; i < s; i++) {
12608 maskedWords.words[i] = this.words[i];
12609 }
12610 maskedWords.length = s;
12611 }
12612
12613 if (s === 0) {
12614 // No-op, we should not move anything at all
12615 } else if (this.length > s) {
12616 this.length -= s;
12617 for (i = 0; i < this.length; i++) {
12618 this.words[i] = this.words[i + s];
12619 }
12620 } else {
12621 this.words[0] = 0;
12622 this.length = 1;
12623 }
12624
12625 var carry = 0;
12626 for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
12627 var word = this.words[i] | 0;
12628 this.words[i] = (carry << (26 - r)) | (word >>> r);
12629 carry = word & mask;
12630 }
12631
12632 // Push carried bits as a mask
12633 if (maskedWords && carry !== 0) {
12634 maskedWords.words[maskedWords.length++] = carry;
12635 }
12636
12637 if (this.length === 0) {
12638 this.words[0] = 0;
12639 this.length = 1;
12640 }
12641
12642 return this.strip();
12643 };
12644
12645 BN.prototype.ishrn = function ishrn (bits, hint, extended) {
12646 // TODO(indutny): implement me
12647 assert(this.negative === 0);
12648 return this.iushrn(bits, hint, extended);
12649 };
12650
12651 // Shift-left
12652 BN.prototype.shln = function shln (bits) {
12653 return this.clone().ishln(bits);
12654 };
12655
12656 BN.prototype.ushln = function ushln (bits) {
12657 return this.clone().iushln(bits);
12658 };
12659
12660 // Shift-right
12661 BN.prototype.shrn = function shrn (bits) {
12662 return this.clone().ishrn(bits);
12663 };
12664
12665 BN.prototype.ushrn = function ushrn (bits) {
12666 return this.clone().iushrn(bits);
12667 };
12668
12669 // Test if n bit is set
12670 BN.prototype.testn = function testn (bit) {
12671 assert(typeof bit === 'number' && bit >= 0);
12672 var r = bit % 26;
12673 var s = (bit - r) / 26;
12674 var q = 1 << r;
12675
12676 // Fast case: bit is much higher than all existing words
12677 if (this.length <= s) return false;
12678
12679 // Check bit and return
12680 var w = this.words[s];
12681
12682 return !!(w & q);
12683 };
12684
12685 // Return only lowers bits of number (in-place)
12686 BN.prototype.imaskn = function imaskn (bits) {
12687 assert(typeof bits === 'number' && bits >= 0);
12688 var r = bits % 26;
12689 var s = (bits - r) / 26;
12690
12691 assert(this.negative === 0, 'imaskn works only with positive numbers');
12692
12693 if (this.length <= s) {
12694 return this;
12695 }
12696
12697 if (r !== 0) {
12698 s++;
12699 }
12700 this.length = Math.min(s, this.length);
12701
12702 if (r !== 0) {
12703 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
12704 this.words[this.length - 1] &= mask;
12705 }
12706
12707 return this.strip();
12708 };
12709
12710 // Return only lowers bits of number
12711 BN.prototype.maskn = function maskn (bits) {
12712 return this.clone().imaskn(bits);
12713 };
12714
12715 // Add plain number `num` to `this`
12716 BN.prototype.iaddn = function iaddn (num) {
12717 assert(typeof num === 'number');
12718 assert(num < 0x4000000);
12719 if (num < 0) return this.isubn(-num);
12720
12721 // Possible sign change
12722 if (this.negative !== 0) {
12723 if (this.length === 1 && (this.words[0] | 0) < num) {
12724 this.words[0] = num - (this.words[0] | 0);
12725 this.negative = 0;
12726 return this;
12727 }
12728
12729 this.negative = 0;
12730 this.isubn(num);
12731 this.negative = 1;
12732 return this;
12733 }
12734
12735 // Add without checks
12736 return this._iaddn(num);
12737 };
12738
12739 BN.prototype._iaddn = function _iaddn (num) {
12740 this.words[0] += num;
12741
12742 // Carry
12743 for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
12744 this.words[i] -= 0x4000000;
12745 if (i === this.length - 1) {
12746 this.words[i + 1] = 1;
12747 } else {
12748 this.words[i + 1]++;
12749 }
12750 }
12751 this.length = Math.max(this.length, i + 1);
12752
12753 return this;
12754 };
12755
12756 // Subtract plain number `num` from `this`
12757 BN.prototype.isubn = function isubn (num) {
12758 assert(typeof num === 'number');
12759 assert(num < 0x4000000);
12760 if (num < 0) return this.iaddn(-num);
12761
12762 if (this.negative !== 0) {
12763 this.negative = 0;
12764 this.iaddn(num);
12765 this.negative = 1;
12766 return this;
12767 }
12768
12769 this.words[0] -= num;
12770
12771 if (this.length === 1 && this.words[0] < 0) {
12772 this.words[0] = -this.words[0];
12773 this.negative = 1;
12774 } else {
12775 // Carry
12776 for (var i = 0; i < this.length && this.words[i] < 0; i++) {
12777 this.words[i] += 0x4000000;
12778 this.words[i + 1] -= 1;
12779 }
12780 }
12781
12782 return this.strip();
12783 };
12784
12785 BN.prototype.addn = function addn (num) {
12786 return this.clone().iaddn(num);
12787 };
12788
12789 BN.prototype.subn = function subn (num) {
12790 return this.clone().isubn(num);
12791 };
12792
12793 BN.prototype.iabs = function iabs () {
12794 this.negative = 0;
12795
12796 return this;
12797 };
12798
12799 BN.prototype.abs = function abs () {
12800 return this.clone().iabs();
12801 };
12802
12803 BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
12804 var len = num.length + shift;
12805 var i;
12806
12807 this._expand(len);
12808
12809 var w;
12810 var carry = 0;
12811 for (i = 0; i < num.length; i++) {
12812 w = (this.words[i + shift] | 0) + carry;
12813 var right = (num.words[i] | 0) * mul;
12814 w -= right & 0x3ffffff;
12815 carry = (w >> 26) - ((right / 0x4000000) | 0);
12816 this.words[i + shift] = w & 0x3ffffff;
12817 }
12818 for (; i < this.length - shift; i++) {
12819 w = (this.words[i + shift] | 0) + carry;
12820 carry = w >> 26;
12821 this.words[i + shift] = w & 0x3ffffff;
12822 }
12823
12824 if (carry === 0) return this.strip();
12825
12826 // Subtraction overflow
12827 assert(carry === -1);
12828 carry = 0;
12829 for (i = 0; i < this.length; i++) {
12830 w = -(this.words[i] | 0) + carry;
12831 carry = w >> 26;
12832 this.words[i] = w & 0x3ffffff;
12833 }
12834 this.negative = 1;
12835
12836 return this.strip();
12837 };
12838
12839 BN.prototype._wordDiv = function _wordDiv (num, mode) {
12840 var shift = this.length - num.length;
12841
12842 var a = this.clone();
12843 var b = num;
12844
12845 // Normalize
12846 var bhi = b.words[b.length - 1] | 0;
12847 var bhiBits = this._countBits(bhi);
12848 shift = 26 - bhiBits;
12849 if (shift !== 0) {
12850 b = b.ushln(shift);
12851 a.iushln(shift);
12852 bhi = b.words[b.length - 1] | 0;
12853 }
12854
12855 // Initialize quotient
12856 var m = a.length - b.length;
12857 var q;
12858
12859 if (mode !== 'mod') {
12860 q = new BN(null);
12861 q.length = m + 1;
12862 q.words = new Array(q.length);
12863 for (var i = 0; i < q.length; i++) {
12864 q.words[i] = 0;
12865 }
12866 }
12867
12868 var diff = a.clone()._ishlnsubmul(b, 1, m);
12869 if (diff.negative === 0) {
12870 a = diff;
12871 if (q) {
12872 q.words[m] = 1;
12873 }
12874 }
12875
12876 for (var j = m - 1; j >= 0; j--) {
12877 var qj = (a.words[b.length + j] | 0) * 0x4000000 +
12878 (a.words[b.length + j - 1] | 0);
12879
12880 // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
12881 // (0x7ffffff)
12882 qj = Math.min((qj / bhi) | 0, 0x3ffffff);
12883
12884 a._ishlnsubmul(b, qj, j);
12885 while (a.negative !== 0) {
12886 qj--;
12887 a.negative = 0;
12888 a._ishlnsubmul(b, 1, j);
12889 if (!a.isZero()) {
12890 a.negative ^= 1;
12891 }
12892 }
12893 if (q) {
12894 q.words[j] = qj;
12895 }
12896 }
12897 if (q) {
12898 q.strip();
12899 }
12900 a.strip();
12901
12902 // Denormalize
12903 if (mode !== 'div' && shift !== 0) {
12904 a.iushrn(shift);
12905 }
12906
12907 return {
12908 div: q || null,
12909 mod: a
12910 };
12911 };
12912
12913 // NOTE: 1) `mode` can be set to `mod` to request mod only,
12914 // to `div` to request div only, or be absent to
12915 // request both div & mod
12916 // 2) `positive` is true if unsigned mod is requested
12917 BN.prototype.divmod = function divmod (num, mode, positive) {
12918 assert(!num.isZero());
12919
12920 if (this.isZero()) {
12921 return {
12922 div: new BN(0),
12923 mod: new BN(0)
12924 };
12925 }
12926
12927 var div, mod, res;
12928 if (this.negative !== 0 && num.negative === 0) {
12929 res = this.neg().divmod(num, mode);
12930
12931 if (mode !== 'mod') {
12932 div = res.div.neg();
12933 }
12934
12935 if (mode !== 'div') {
12936 mod = res.mod.neg();
12937 if (positive && mod.negative !== 0) {
12938 mod.iadd(num);
12939 }
12940 }
12941
12942 return {
12943 div: div,
12944 mod: mod
12945 };
12946 }
12947
12948 if (this.negative === 0 && num.negative !== 0) {
12949 res = this.divmod(num.neg(), mode);
12950
12951 if (mode !== 'mod') {
12952 div = res.div.neg();
12953 }
12954
12955 return {
12956 div: div,
12957 mod: res.mod
12958 };
12959 }
12960
12961 if ((this.negative & num.negative) !== 0) {
12962 res = this.neg().divmod(num.neg(), mode);
12963
12964 if (mode !== 'div') {
12965 mod = res.mod.neg();
12966 if (positive && mod.negative !== 0) {
12967 mod.isub(num);
12968 }
12969 }
12970
12971 return {
12972 div: res.div,
12973 mod: mod
12974 };
12975 }
12976
12977 // Both numbers are positive at this point
12978
12979 // Strip both numbers to approximate shift value
12980 if (num.length > this.length || this.cmp(num) < 0) {
12981 return {
12982 div: new BN(0),
12983 mod: this
12984 };
12985 }
12986
12987 // Very short reduction
12988 if (num.length === 1) {
12989 if (mode === 'div') {
12990 return {
12991 div: this.divn(num.words[0]),
12992 mod: null
12993 };
12994 }
12995
12996 if (mode === 'mod') {
12997 return {
12998 div: null,
12999 mod: new BN(this.modn(num.words[0]))
13000 };
13001 }
13002
13003 return {
13004 div: this.divn(num.words[0]),
13005 mod: new BN(this.modn(num.words[0]))
13006 };
13007 }
13008
13009 return this._wordDiv(num, mode);
13010 };
13011
13012 // Find `this` / `num`
13013 BN.prototype.div = function div (num) {
13014 return this.divmod(num, 'div', false).div;
13015 };
13016
13017 // Find `this` % `num`
13018 BN.prototype.mod = function mod (num) {
13019 return this.divmod(num, 'mod', false).mod;
13020 };
13021
13022 BN.prototype.umod = function umod (num) {
13023 return this.divmod(num, 'mod', true).mod;
13024 };
13025
13026 // Find Round(`this` / `num`)
13027 BN.prototype.divRound = function divRound (num) {
13028 var dm = this.divmod(num);
13029
13030 // Fast case - exact division
13031 if (dm.mod.isZero()) return dm.div;
13032
13033 var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
13034
13035 var half = num.ushrn(1);
13036 var r2 = num.andln(1);
13037 var cmp = mod.cmp(half);
13038
13039 // Round down
13040 if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
13041
13042 // Round up
13043 return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
13044 };
13045
13046 BN.prototype.modn = function modn (num) {
13047 assert(num <= 0x3ffffff);
13048 var p = (1 << 26) % num;
13049
13050 var acc = 0;
13051 for (var i = this.length - 1; i >= 0; i--) {
13052 acc = (p * acc + (this.words[i] | 0)) % num;
13053 }
13054
13055 return acc;
13056 };
13057
13058 // In-place division by number
13059 BN.prototype.idivn = function idivn (num) {
13060 assert(num <= 0x3ffffff);
13061
13062 var carry = 0;
13063 for (var i = this.length - 1; i >= 0; i--) {
13064 var w = (this.words[i] | 0) + carry * 0x4000000;
13065 this.words[i] = (w / num) | 0;
13066 carry = w % num;
13067 }
13068
13069 return this.strip();
13070 };
13071
13072 BN.prototype.divn = function divn (num) {
13073 return this.clone().idivn(num);
13074 };
13075
13076 BN.prototype.egcd = function egcd (p) {
13077 assert(p.negative === 0);
13078 assert(!p.isZero());
13079
13080 var x = this;
13081 var y = p.clone();
13082
13083 if (x.negative !== 0) {
13084 x = x.umod(p);
13085 } else {
13086 x = x.clone();
13087 }
13088
13089 // A * x + B * y = x
13090 var A = new BN(1);
13091 var B = new BN(0);
13092
13093 // C * x + D * y = y
13094 var C = new BN(0);
13095 var D = new BN(1);
13096
13097 var g = 0;
13098
13099 while (x.isEven() && y.isEven()) {
13100 x.iushrn(1);
13101 y.iushrn(1);
13102 ++g;
13103 }
13104
13105 var yp = y.clone();
13106 var xp = x.clone();
13107
13108 while (!x.isZero()) {
13109 for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
13110 if (i > 0) {
13111 x.iushrn(i);
13112 while (i-- > 0) {
13113 if (A.isOdd() || B.isOdd()) {
13114 A.iadd(yp);
13115 B.isub(xp);
13116 }
13117
13118 A.iushrn(1);
13119 B.iushrn(1);
13120 }
13121 }
13122
13123 for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
13124 if (j > 0) {
13125 y.iushrn(j);
13126 while (j-- > 0) {
13127 if (C.isOdd() || D.isOdd()) {
13128 C.iadd(yp);
13129 D.isub(xp);
13130 }
13131
13132 C.iushrn(1);
13133 D.iushrn(1);
13134 }
13135 }
13136
13137 if (x.cmp(y) >= 0) {
13138 x.isub(y);
13139 A.isub(C);
13140 B.isub(D);
13141 } else {
13142 y.isub(x);
13143 C.isub(A);
13144 D.isub(B);
13145 }
13146 }
13147
13148 return {
13149 a: C,
13150 b: D,
13151 gcd: y.iushln(g)
13152 };
13153 };
13154
13155 // This is reduced incarnation of the binary EEA
13156 // above, designated to invert members of the
13157 // _prime_ fields F(p) at a maximal speed
13158 BN.prototype._invmp = function _invmp (p) {
13159 assert(p.negative === 0);
13160 assert(!p.isZero());
13161
13162 var a = this;
13163 var b = p.clone();
13164
13165 if (a.negative !== 0) {
13166 a = a.umod(p);
13167 } else {
13168 a = a.clone();
13169 }
13170
13171 var x1 = new BN(1);
13172 var x2 = new BN(0);
13173
13174 var delta = b.clone();
13175
13176 while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
13177 for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
13178 if (i > 0) {
13179 a.iushrn(i);
13180 while (i-- > 0) {
13181 if (x1.isOdd()) {
13182 x1.iadd(delta);
13183 }
13184
13185 x1.iushrn(1);
13186 }
13187 }
13188
13189 for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
13190 if (j > 0) {
13191 b.iushrn(j);
13192 while (j-- > 0) {
13193 if (x2.isOdd()) {
13194 x2.iadd(delta);
13195 }
13196
13197 x2.iushrn(1);
13198 }
13199 }
13200
13201 if (a.cmp(b) >= 0) {
13202 a.isub(b);
13203 x1.isub(x2);
13204 } else {
13205 b.isub(a);
13206 x2.isub(x1);
13207 }
13208 }
13209
13210 var res;
13211 if (a.cmpn(1) === 0) {
13212 res = x1;
13213 } else {
13214 res = x2;
13215 }
13216
13217 if (res.cmpn(0) < 0) {
13218 res.iadd(p);
13219 }
13220
13221 return res;
13222 };
13223
13224 BN.prototype.gcd = function gcd (num) {
13225 if (this.isZero()) return num.abs();
13226 if (num.isZero()) return this.abs();
13227
13228 var a = this.clone();
13229 var b = num.clone();
13230 a.negative = 0;
13231 b.negative = 0;
13232
13233 // Remove common factor of two
13234 for (var shift = 0; a.isEven() && b.isEven(); shift++) {
13235 a.iushrn(1);
13236 b.iushrn(1);
13237 }
13238
13239 do {
13240 while (a.isEven()) {
13241 a.iushrn(1);
13242 }
13243 while (b.isEven()) {
13244 b.iushrn(1);
13245 }
13246
13247 var r = a.cmp(b);
13248 if (r < 0) {
13249 // Swap `a` and `b` to make `a` always bigger than `b`
13250 var t = a;
13251 a = b;
13252 b = t;
13253 } else if (r === 0 || b.cmpn(1) === 0) {
13254 break;
13255 }
13256
13257 a.isub(b);
13258 } while (true);
13259
13260 return b.iushln(shift);
13261 };
13262
13263 // Invert number in the field F(num)
13264 BN.prototype.invm = function invm (num) {
13265 return this.egcd(num).a.umod(num);
13266 };
13267
13268 BN.prototype.isEven = function isEven () {
13269 return (this.words[0] & 1) === 0;
13270 };
13271
13272 BN.prototype.isOdd = function isOdd () {
13273 return (this.words[0] & 1) === 1;
13274 };
13275
13276 // And first word and num
13277 BN.prototype.andln = function andln (num) {
13278 return this.words[0] & num;
13279 };
13280
13281 // Increment at the bit position in-line
13282 BN.prototype.bincn = function bincn (bit) {
13283 assert(typeof bit === 'number');
13284 var r = bit % 26;
13285 var s = (bit - r) / 26;
13286 var q = 1 << r;
13287
13288 // Fast case: bit is much higher than all existing words
13289 if (this.length <= s) {
13290 this._expand(s + 1);
13291 this.words[s] |= q;
13292 return this;
13293 }
13294
13295 // Add bit and propagate, if needed
13296 var carry = q;
13297 for (var i = s; carry !== 0 && i < this.length; i++) {
13298 var w = this.words[i] | 0;
13299 w += carry;
13300 carry = w >>> 26;
13301 w &= 0x3ffffff;
13302 this.words[i] = w;
13303 }
13304 if (carry !== 0) {
13305 this.words[i] = carry;
13306 this.length++;
13307 }
13308 return this;
13309 };
13310
13311 BN.prototype.isZero = function isZero () {
13312 return this.length === 1 && this.words[0] === 0;
13313 };
13314
13315 BN.prototype.cmpn = function cmpn (num) {
13316 var negative = num < 0;
13317
13318 if (this.negative !== 0 && !negative) return -1;
13319 if (this.negative === 0 && negative) return 1;
13320
13321 this.strip();
13322
13323 var res;
13324 if (this.length > 1) {
13325 res = 1;
13326 } else {
13327 if (negative) {
13328 num = -num;
13329 }
13330
13331 assert(num <= 0x3ffffff, 'Number is too big');
13332
13333 var w = this.words[0] | 0;
13334 res = w === num ? 0 : w < num ? -1 : 1;
13335 }
13336 if (this.negative !== 0) return -res | 0;
13337 return res;
13338 };
13339
13340 // Compare two numbers and return:
13341 // 1 - if `this` > `num`
13342 // 0 - if `this` == `num`
13343 // -1 - if `this` < `num`
13344 BN.prototype.cmp = function cmp (num) {
13345 if (this.negative !== 0 && num.negative === 0) return -1;
13346 if (this.negative === 0 && num.negative !== 0) return 1;
13347
13348 var res = this.ucmp(num);
13349 if (this.negative !== 0) return -res | 0;
13350 return res;
13351 };
13352
13353 // Unsigned comparison
13354 BN.prototype.ucmp = function ucmp (num) {
13355 // At this point both numbers have the same sign
13356 if (this.length > num.length) return 1;
13357 if (this.length < num.length) return -1;
13358
13359 var res = 0;
13360 for (var i = this.length - 1; i >= 0; i--) {
13361 var a = this.words[i] | 0;
13362 var b = num.words[i] | 0;
13363
13364 if (a === b) continue;
13365 if (a < b) {
13366 res = -1;
13367 } else if (a > b) {
13368 res = 1;
13369 }
13370 break;
13371 }
13372 return res;
13373 };
13374
13375 BN.prototype.gtn = function gtn (num) {
13376 return this.cmpn(num) === 1;
13377 };
13378
13379 BN.prototype.gt = function gt (num) {
13380 return this.cmp(num) === 1;
13381 };
13382
13383 BN.prototype.gten = function gten (num) {
13384 return this.cmpn(num) >= 0;
13385 };
13386
13387 BN.prototype.gte = function gte (num) {
13388 return this.cmp(num) >= 0;
13389 };
13390
13391 BN.prototype.ltn = function ltn (num) {
13392 return this.cmpn(num) === -1;
13393 };
13394
13395 BN.prototype.lt = function lt (num) {
13396 return this.cmp(num) === -1;
13397 };
13398
13399 BN.prototype.lten = function lten (num) {
13400 return this.cmpn(num) <= 0;
13401 };
13402
13403 BN.prototype.lte = function lte (num) {
13404 return this.cmp(num) <= 0;
13405 };
13406
13407 BN.prototype.eqn = function eqn (num) {
13408 return this.cmpn(num) === 0;
13409 };
13410
13411 BN.prototype.eq = function eq (num) {
13412 return this.cmp(num) === 0;
13413 };
13414
13415 //
13416 // A reduce context, could be using montgomery or something better, depending
13417 // on the `m` itself.
13418 //
13419 BN.red = function red (num) {
13420 return new Red(num);
13421 };
13422
13423 BN.prototype.toRed = function toRed (ctx) {
13424 assert(!this.red, 'Already a number in reduction context');
13425 assert(this.negative === 0, 'red works only with positives');
13426 return ctx.convertTo(this)._forceRed(ctx);
13427 };
13428
13429 BN.prototype.fromRed = function fromRed () {
13430 assert(this.red, 'fromRed works only with numbers in reduction context');
13431 return this.red.convertFrom(this);
13432 };
13433
13434 BN.prototype._forceRed = function _forceRed (ctx) {
13435 this.red = ctx;
13436 return this;
13437 };
13438
13439 BN.prototype.forceRed = function forceRed (ctx) {
13440 assert(!this.red, 'Already a number in reduction context');
13441 return this._forceRed(ctx);
13442 };
13443
13444 BN.prototype.redAdd = function redAdd (num) {
13445 assert(this.red, 'redAdd works only with red numbers');
13446 return this.red.add(this, num);
13447 };
13448
13449 BN.prototype.redIAdd = function redIAdd (num) {
13450 assert(this.red, 'redIAdd works only with red numbers');
13451 return this.red.iadd(this, num);
13452 };
13453
13454 BN.prototype.redSub = function redSub (num) {
13455 assert(this.red, 'redSub works only with red numbers');
13456 return this.red.sub(this, num);
13457 };
13458
13459 BN.prototype.redISub = function redISub (num) {
13460 assert(this.red, 'redISub works only with red numbers');
13461 return this.red.isub(this, num);
13462 };
13463
13464 BN.prototype.redShl = function redShl (num) {
13465 assert(this.red, 'redShl works only with red numbers');
13466 return this.red.shl(this, num);
13467 };
13468
13469 BN.prototype.redMul = function redMul (num) {
13470 assert(this.red, 'redMul works only with red numbers');
13471 this.red._verify2(this, num);
13472 return this.red.mul(this, num);
13473 };
13474
13475 BN.prototype.redIMul = function redIMul (num) {
13476 assert(this.red, 'redMul works only with red numbers');
13477 this.red._verify2(this, num);
13478 return this.red.imul(this, num);
13479 };
13480
13481 BN.prototype.redSqr = function redSqr () {
13482 assert(this.red, 'redSqr works only with red numbers');
13483 this.red._verify1(this);
13484 return this.red.sqr(this);
13485 };
13486
13487 BN.prototype.redISqr = function redISqr () {
13488 assert(this.red, 'redISqr works only with red numbers');
13489 this.red._verify1(this);
13490 return this.red.isqr(this);
13491 };
13492
13493 // Square root over p
13494 BN.prototype.redSqrt = function redSqrt () {
13495 assert(this.red, 'redSqrt works only with red numbers');
13496 this.red._verify1(this);
13497 return this.red.sqrt(this);
13498 };
13499
13500 BN.prototype.redInvm = function redInvm () {
13501 assert(this.red, 'redInvm works only with red numbers');
13502 this.red._verify1(this);
13503 return this.red.invm(this);
13504 };
13505
13506 // Return negative clone of `this` % `red modulo`
13507 BN.prototype.redNeg = function redNeg () {
13508 assert(this.red, 'redNeg works only with red numbers');
13509 this.red._verify1(this);
13510 return this.red.neg(this);
13511 };
13512
13513 BN.prototype.redPow = function redPow (num) {
13514 assert(this.red && !num.red, 'redPow(normalNum)');
13515 this.red._verify1(this);
13516 return this.red.pow(this, num);
13517 };
13518
13519 // Prime numbers with efficient reduction
13520 var primes = {
13521 k256: null,
13522 p224: null,
13523 p192: null,
13524 p25519: null
13525 };
13526
13527 // Pseudo-Mersenne prime
13528 function MPrime (name, p) {
13529 // P = 2 ^ N - K
13530 this.name = name;
13531 this.p = new BN(p, 16);
13532 this.n = this.p.bitLength();
13533 this.k = new BN(1).iushln(this.n).isub(this.p);
13534
13535 this.tmp = this._tmp();
13536 }
13537
13538 MPrime.prototype._tmp = function _tmp () {
13539 var tmp = new BN(null);
13540 tmp.words = new Array(Math.ceil(this.n / 13));
13541 return tmp;
13542 };
13543
13544 MPrime.prototype.ireduce = function ireduce (num) {
13545 // Assumes that `num` is less than `P^2`
13546 // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
13547 var r = num;
13548 var rlen;
13549
13550 do {
13551 this.split(r, this.tmp);
13552 r = this.imulK(r);
13553 r = r.iadd(this.tmp);
13554 rlen = r.bitLength();
13555 } while (rlen > this.n);
13556
13557 var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
13558 if (cmp === 0) {
13559 r.words[0] = 0;
13560 r.length = 1;
13561 } else if (cmp > 0) {
13562 r.isub(this.p);
13563 } else {
13564 r.strip();
13565 }
13566
13567 return r;
13568 };
13569
13570 MPrime.prototype.split = function split (input, out) {
13571 input.iushrn(this.n, 0, out);
13572 };
13573
13574 MPrime.prototype.imulK = function imulK (num) {
13575 return num.imul(this.k);
13576 };
13577
13578 function K256 () {
13579 MPrime.call(
13580 this,
13581 'k256',
13582 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
13583 }
13584 inherits(K256, MPrime);
13585
13586 K256.prototype.split = function split (input, output) {
13587 // 256 = 9 * 26 + 22
13588 var mask = 0x3fffff;
13589
13590 var outLen = Math.min(input.length, 9);
13591 for (var i = 0; i < outLen; i++) {
13592 output.words[i] = input.words[i];
13593 }
13594 output.length = outLen;
13595
13596 if (input.length <= 9) {
13597 input.words[0] = 0;
13598 input.length = 1;
13599 return;
13600 }
13601
13602 // Shift by 9 limbs
13603 var prev = input.words[9];
13604 output.words[output.length++] = prev & mask;
13605
13606 for (i = 10; i < input.length; i++) {
13607 var next = input.words[i] | 0;
13608 input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
13609 prev = next;
13610 }
13611 prev >>>= 22;
13612 input.words[i - 10] = prev;
13613 if (prev === 0 && input.length > 10) {
13614 input.length -= 10;
13615 } else {
13616 input.length -= 9;
13617 }
13618 };
13619
13620 K256.prototype.imulK = function imulK (num) {
13621 // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
13622 num.words[num.length] = 0;
13623 num.words[num.length + 1] = 0;
13624 num.length += 2;
13625
13626 // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
13627 var lo = 0;
13628 for (var i = 0; i < num.length; i++) {
13629 var w = num.words[i] | 0;
13630 lo += w * 0x3d1;
13631 num.words[i] = lo & 0x3ffffff;
13632 lo = w * 0x40 + ((lo / 0x4000000) | 0);
13633 }
13634
13635 // Fast length reduction
13636 if (num.words[num.length - 1] === 0) {
13637 num.length--;
13638 if (num.words[num.length - 1] === 0) {
13639 num.length--;
13640 }
13641 }
13642 return num;
13643 };
13644
13645 function P224 () {
13646 MPrime.call(
13647 this,
13648 'p224',
13649 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
13650 }
13651 inherits(P224, MPrime);
13652
13653 function P192 () {
13654 MPrime.call(
13655 this,
13656 'p192',
13657 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
13658 }
13659 inherits(P192, MPrime);
13660
13661 function P25519 () {
13662 // 2 ^ 255 - 19
13663 MPrime.call(
13664 this,
13665 '25519',
13666 '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
13667 }
13668 inherits(P25519, MPrime);
13669
13670 P25519.prototype.imulK = function imulK (num) {
13671 // K = 0x13
13672 var carry = 0;
13673 for (var i = 0; i < num.length; i++) {
13674 var hi = (num.words[i] | 0) * 0x13 + carry;
13675 var lo = hi & 0x3ffffff;
13676 hi >>>= 26;
13677
13678 num.words[i] = lo;
13679 carry = hi;
13680 }
13681 if (carry !== 0) {
13682 num.words[num.length++] = carry;
13683 }
13684 return num;
13685 };
13686
13687 // Exported mostly for testing purposes, use plain name instead
13688 BN._prime = function prime (name) {
13689 // Cached version of prime
13690 if (primes[name]) return primes[name];
13691
13692 var prime;
13693 if (name === 'k256') {
13694 prime = new K256();
13695 } else if (name === 'p224') {
13696 prime = new P224();
13697 } else if (name === 'p192') {
13698 prime = new P192();
13699 } else if (name === 'p25519') {
13700 prime = new P25519();
13701 } else {
13702 throw new Error('Unknown prime ' + name);
13703 }
13704 primes[name] = prime;
13705
13706 return prime;
13707 };
13708
13709 //
13710 // Base reduction engine
13711 //
13712 function Red (m) {
13713 if (typeof m === 'string') {
13714 var prime = BN._prime(m);
13715 this.m = prime.p;
13716 this.prime = prime;
13717 } else {
13718 assert(m.gtn(1), 'modulus must be greater than 1');
13719 this.m = m;
13720 this.prime = null;
13721 }
13722 }
13723
13724 Red.prototype._verify1 = function _verify1 (a) {
13725 assert(a.negative === 0, 'red works only with positives');
13726 assert(a.red, 'red works only with red numbers');
13727 };
13728
13729 Red.prototype._verify2 = function _verify2 (a, b) {
13730 assert((a.negative | b.negative) === 0, 'red works only with positives');
13731 assert(a.red && a.red === b.red,
13732 'red works only with red numbers');
13733 };
13734
13735 Red.prototype.imod = function imod (a) {
13736 if (this.prime) return this.prime.ireduce(a)._forceRed(this);
13737 return a.umod(this.m)._forceRed(this);
13738 };
13739
13740 Red.prototype.neg = function neg (a) {
13741 if (a.isZero()) {
13742 return a.clone();
13743 }
13744
13745 return this.m.sub(a)._forceRed(this);
13746 };
13747
13748 Red.prototype.add = function add (a, b) {
13749 this._verify2(a, b);
13750
13751 var res = a.add(b);
13752 if (res.cmp(this.m) >= 0) {
13753 res.isub(this.m);
13754 }
13755 return res._forceRed(this);
13756 };
13757
13758 Red.prototype.iadd = function iadd (a, b) {
13759 this._verify2(a, b);
13760
13761 var res = a.iadd(b);
13762 if (res.cmp(this.m) >= 0) {
13763 res.isub(this.m);
13764 }
13765 return res;
13766 };
13767
13768 Red.prototype.sub = function sub (a, b) {
13769 this._verify2(a, b);
13770
13771 var res = a.sub(b);
13772 if (res.cmpn(0) < 0) {
13773 res.iadd(this.m);
13774 }
13775 return res._forceRed(this);
13776 };
13777
13778 Red.prototype.isub = function isub (a, b) {
13779 this._verify2(a, b);
13780
13781 var res = a.isub(b);
13782 if (res.cmpn(0) < 0) {
13783 res.iadd(this.m);
13784 }
13785 return res;
13786 };
13787
13788 Red.prototype.shl = function shl (a, num) {
13789 this._verify1(a);
13790 return this.imod(a.ushln(num));
13791 };
13792
13793 Red.prototype.imul = function imul (a, b) {
13794 this._verify2(a, b);
13795 return this.imod(a.imul(b));
13796 };
13797
13798 Red.prototype.mul = function mul (a, b) {
13799 this._verify2(a, b);
13800 return this.imod(a.mul(b));
13801 };
13802
13803 Red.prototype.isqr = function isqr (a) {
13804 return this.imul(a, a.clone());
13805 };
13806
13807 Red.prototype.sqr = function sqr (a) {
13808 return this.mul(a, a);
13809 };
13810
13811 Red.prototype.sqrt = function sqrt (a) {
13812 if (a.isZero()) return a.clone();
13813
13814 var mod3 = this.m.andln(3);
13815 assert(mod3 % 2 === 1);
13816
13817 // Fast case
13818 if (mod3 === 3) {
13819 var pow = this.m.add(new BN(1)).iushrn(2);
13820 return this.pow(a, pow);
13821 }
13822
13823 // Tonelli-Shanks algorithm (Totally unoptimized and slow)
13824 //
13825 // Find Q and S, that Q * 2 ^ S = (P - 1)
13826 var q = this.m.subn(1);
13827 var s = 0;
13828 while (!q.isZero() && q.andln(1) === 0) {
13829 s++;
13830 q.iushrn(1);
13831 }
13832 assert(!q.isZero());
13833
13834 var one = new BN(1).toRed(this);
13835 var nOne = one.redNeg();
13836
13837 // Find quadratic non-residue
13838 // NOTE: Max is such because of generalized Riemann hypothesis.
13839 var lpow = this.m.subn(1).iushrn(1);
13840 var z = this.m.bitLength();
13841 z = new BN(2 * z * z).toRed(this);
13842
13843 while (this.pow(z, lpow).cmp(nOne) !== 0) {
13844 z.redIAdd(nOne);
13845 }
13846
13847 var c = this.pow(z, q);
13848 var r = this.pow(a, q.addn(1).iushrn(1));
13849 var t = this.pow(a, q);
13850 var m = s;
13851 while (t.cmp(one) !== 0) {
13852 var tmp = t;
13853 for (var i = 0; tmp.cmp(one) !== 0; i++) {
13854 tmp = tmp.redSqr();
13855 }
13856 assert(i < m);
13857 var b = this.pow(c, new BN(1).iushln(m - i - 1));
13858
13859 r = r.redMul(b);
13860 c = b.redSqr();
13861 t = t.redMul(c);
13862 m = i;
13863 }
13864
13865 return r;
13866 };
13867
13868 Red.prototype.invm = function invm (a) {
13869 var inv = a._invmp(this.m);
13870 if (inv.negative !== 0) {
13871 inv.negative = 0;
13872 return this.imod(inv).redNeg();
13873 } else {
13874 return this.imod(inv);
13875 }
13876 };
13877
13878 Red.prototype.pow = function pow (a, num) {
13879 if (num.isZero()) return new BN(1).toRed(this);
13880 if (num.cmpn(1) === 0) return a.clone();
13881
13882 var windowSize = 4;
13883 var wnd = new Array(1 << windowSize);
13884 wnd[0] = new BN(1).toRed(this);
13885 wnd[1] = a;
13886 for (var i = 2; i < wnd.length; i++) {
13887 wnd[i] = this.mul(wnd[i - 1], a);
13888 }
13889
13890 var res = wnd[0];
13891 var current = 0;
13892 var currentLen = 0;
13893 var start = num.bitLength() % 26;
13894 if (start === 0) {
13895 start = 26;
13896 }
13897
13898 for (i = num.length - 1; i >= 0; i--) {
13899 var word = num.words[i];
13900 for (var j = start - 1; j >= 0; j--) {
13901 var bit = (word >> j) & 1;
13902 if (res !== wnd[0]) {
13903 res = this.sqr(res);
13904 }
13905
13906 if (bit === 0 && current === 0) {
13907 currentLen = 0;
13908 continue;
13909 }
13910
13911 current <<= 1;
13912 current |= bit;
13913 currentLen++;
13914 if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
13915
13916 res = this.mul(res, wnd[current]);
13917 currentLen = 0;
13918 current = 0;
13919 }
13920 start = 26;
13921 }
13922
13923 return res;
13924 };
13925
13926 Red.prototype.convertTo = function convertTo (num) {
13927 var r = num.umod(this.m);
13928
13929 return r === num ? r.clone() : r;
13930 };
13931
13932 Red.prototype.convertFrom = function convertFrom (num) {
13933 var res = num.clone();
13934 res.red = null;
13935 return res;
13936 };
13937
13938 //
13939 // Montgomery method engine
13940 //
13941
13942 BN.mont = function mont (num) {
13943 return new Mont(num);
13944 };
13945
13946 function Mont (m) {
13947 Red.call(this, m);
13948
13949 this.shift = this.m.bitLength();
13950 if (this.shift % 26 !== 0) {
13951 this.shift += 26 - (this.shift % 26);
13952 }
13953
13954 this.r = new BN(1).iushln(this.shift);
13955 this.r2 = this.imod(this.r.sqr());
13956 this.rinv = this.r._invmp(this.m);
13957
13958 this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
13959 this.minv = this.minv.umod(this.r);
13960 this.minv = this.r.sub(this.minv);
13961 }
13962 inherits(Mont, Red);
13963
13964 Mont.prototype.convertTo = function convertTo (num) {
13965 return this.imod(num.ushln(this.shift));
13966 };
13967
13968 Mont.prototype.convertFrom = function convertFrom (num) {
13969 var r = this.imod(num.mul(this.rinv));
13970 r.red = null;
13971 return r;
13972 };
13973
13974 Mont.prototype.imul = function imul (a, b) {
13975 if (a.isZero() || b.isZero()) {
13976 a.words[0] = 0;
13977 a.length = 1;
13978 return a;
13979 }
13980
13981 var t = a.imul(b);
13982 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
13983 var u = t.isub(c).iushrn(this.shift);
13984 var res = u;
13985
13986 if (u.cmp(this.m) >= 0) {
13987 res = u.isub(this.m);
13988 } else if (u.cmpn(0) < 0) {
13989 res = u.iadd(this.m);
13990 }
13991
13992 return res._forceRed(this);
13993 };
13994
13995 Mont.prototype.mul = function mul (a, b) {
13996 if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
13997
13998 var t = a.mul(b);
13999 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
14000 var u = t.isub(c).iushrn(this.shift);
14001 var res = u;
14002 if (u.cmp(this.m) >= 0) {
14003 res = u.isub(this.m);
14004 } else if (u.cmpn(0) < 0) {
14005 res = u.iadd(this.m);
14006 }
14007
14008 return res._forceRed(this);
14009 };
14010
14011 Mont.prototype.invm = function invm (a) {
14012 // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
14013 var res = this.imod(a._invmp(this.m).mul(this.r2));
14014 return res._forceRed(this);
14015 };
14016 })(typeof module === 'undefined' || module, this);
14017
14018 },{"buffer":81}],80:[function(require,module,exports){
14019 var r;
14020
14021 module.exports = function rand(len) {
14022 if (!r)
14023 r = new Rand(null);
14024
14025 return r.generate(len);
14026 };
14027
14028 function Rand(rand) {
14029 this.rand = rand;
14030 }
14031 module.exports.Rand = Rand;
14032
14033 Rand.prototype.generate = function generate(len) {
14034 return this._rand(len);
14035 };
14036
14037 // Emulate crypto API using randy
14038 Rand.prototype._rand = function _rand(n) {
14039 if (this.rand.getBytes)
14040 return this.rand.getBytes(n);
14041
14042 var res = new Uint8Array(n);
14043 for (var i = 0; i < res.length; i++)
14044 res[i] = this.rand.getByte();
14045 return res;
14046 };
14047
14048 if (typeof self === 'object') {
14049 if (self.crypto && self.crypto.getRandomValues) {
14050 // Modern browsers
14051 Rand.prototype._rand = function _rand(n) {
14052 var arr = new Uint8Array(n);
14053 self.crypto.getRandomValues(arr);
14054 return arr;
14055 };
14056 } else if (self.msCrypto && self.msCrypto.getRandomValues) {
14057 // IE
14058 Rand.prototype._rand = function _rand(n) {
14059 var arr = new Uint8Array(n);
14060 self.msCrypto.getRandomValues(arr);
14061 return arr;
14062 };
14063
14064 // Safari's WebWorkers do not have `crypto`
14065 } else if (typeof window === 'object') {
14066 // Old junk
14067 Rand.prototype._rand = function() {
14068 throw new Error('Not implemented yet');
14069 };
14070 }
14071 } else {
14072 // Node.js or Web worker with no crypto support
14073 try {
14074 var crypto = require('crypto');
14075 if (typeof crypto.randomBytes !== 'function')
14076 throw new Error('Not supported');
14077
14078 Rand.prototype._rand = function _rand(n) {
14079 return crypto.randomBytes(n);
14080 };
14081 } catch (e) {
14082 }
14083 }
14084
14085 },{"crypto":81}],81:[function(require,module,exports){
14086
14087 },{}],82:[function(require,module,exports){
14088 arguments[4][7][0].apply(exports,arguments)
14089 },{"dup":7,"safe-buffer":206}],83:[function(require,module,exports){
14090 arguments[4][8][0].apply(exports,arguments)
14091 },{"./aes":82,"./ghash":87,"./incr32":88,"buffer-xor":109,"cipher-base":111,"dup":8,"inherits":162,"safe-buffer":206}],84:[function(require,module,exports){
14092 arguments[4][9][0].apply(exports,arguments)
14093 },{"./decrypter":85,"./encrypter":86,"./modes/list.json":96,"dup":9}],85:[function(require,module,exports){
14094 arguments[4][10][0].apply(exports,arguments)
14095 },{"./aes":82,"./authCipher":83,"./modes":95,"./streamCipher":98,"cipher-base":111,"dup":10,"evp_bytestokey":146,"inherits":162,"safe-buffer":206}],86:[function(require,module,exports){
14096 arguments[4][11][0].apply(exports,arguments)
14097 },{"./aes":82,"./authCipher":83,"./modes":95,"./streamCipher":98,"cipher-base":111,"dup":11,"evp_bytestokey":146,"inherits":162,"safe-buffer":206}],87:[function(require,module,exports){
14098 arguments[4][12][0].apply(exports,arguments)
14099 },{"dup":12,"safe-buffer":206}],88:[function(require,module,exports){
14100 arguments[4][13][0].apply(exports,arguments)
14101 },{"dup":13}],89:[function(require,module,exports){
14102 arguments[4][14][0].apply(exports,arguments)
14103 },{"buffer-xor":109,"dup":14}],90:[function(require,module,exports){
14104 arguments[4][15][0].apply(exports,arguments)
14105 },{"buffer-xor":109,"dup":15,"safe-buffer":206}],91:[function(require,module,exports){
14106 arguments[4][16][0].apply(exports,arguments)
14107 },{"dup":16,"safe-buffer":206}],92:[function(require,module,exports){
14108 arguments[4][17][0].apply(exports,arguments)
14109 },{"dup":17,"safe-buffer":206}],93:[function(require,module,exports){
14110 arguments[4][18][0].apply(exports,arguments)
14111 },{"../incr32":88,"buffer-xor":109,"dup":18,"safe-buffer":206}],94:[function(require,module,exports){
14112 arguments[4][19][0].apply(exports,arguments)
14113 },{"dup":19}],95:[function(require,module,exports){
14114 arguments[4][20][0].apply(exports,arguments)
14115 },{"./cbc":89,"./cfb":90,"./cfb1":91,"./cfb8":92,"./ctr":93,"./ecb":94,"./list.json":96,"./ofb":97,"dup":20}],96:[function(require,module,exports){
14116 arguments[4][21][0].apply(exports,arguments)
14117 },{"dup":21}],97:[function(require,module,exports){
14118 arguments[4][22][0].apply(exports,arguments)
14119 },{"buffer":110,"buffer-xor":109,"dup":22}],98:[function(require,module,exports){
14120 arguments[4][23][0].apply(exports,arguments)
14121 },{"./aes":82,"cipher-base":111,"dup":23,"inherits":162,"safe-buffer":206}],99:[function(require,module,exports){
14122 var DES = require('browserify-des')
14123 var aes = require('browserify-aes/browser')
14124 var aesModes = require('browserify-aes/modes')
14125 var desModes = require('browserify-des/modes')
14126 var ebtk = require('evp_bytestokey')
14127
14128 function createCipher (suite, password) {
14129 suite = suite.toLowerCase()
14130
14131 var keyLen, ivLen
14132 if (aesModes[suite]) {
14133 keyLen = aesModes[suite].key
14134 ivLen = aesModes[suite].iv
14135 } else if (desModes[suite]) {
14136 keyLen = desModes[suite].key * 8
14137 ivLen = desModes[suite].iv
14138 } else {
14139 throw new TypeError('invalid suite type')
14140 }
14141
14142 var keys = ebtk(password, false, keyLen, ivLen)
14143 return createCipheriv(suite, keys.key, keys.iv)
14144 }
14145
14146 function createDecipher (suite, password) {
14147 suite = suite.toLowerCase()
14148
14149 var keyLen, ivLen
14150 if (aesModes[suite]) {
14151 keyLen = aesModes[suite].key
14152 ivLen = aesModes[suite].iv
14153 } else if (desModes[suite]) {
14154 keyLen = desModes[suite].key * 8
14155 ivLen = desModes[suite].iv
14156 } else {
14157 throw new TypeError('invalid suite type')
14158 }
14159
14160 var keys = ebtk(password, false, keyLen, ivLen)
14161 return createDecipheriv(suite, keys.key, keys.iv)
14162 }
14163
14164 function createCipheriv (suite, key, iv) {
14165 suite = suite.toLowerCase()
14166 if (aesModes[suite]) return aes.createCipheriv(suite, key, iv)
14167 if (desModes[suite]) return new DES({ key: key, iv: iv, mode: suite })
14168
14169 throw new TypeError('invalid suite type')
14170 }
14171
14172 function createDecipheriv (suite, key, iv) {
14173 suite = suite.toLowerCase()
14174 if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv)
14175 if (desModes[suite]) return new DES({ key: key, iv: iv, mode: suite, decrypt: true })
14176
14177 throw new TypeError('invalid suite type')
14178 }
14179
14180 function getCiphers () {
14181 return Object.keys(desModes).concat(aes.getCiphers())
14182 }
14183
14184 exports.createCipher = exports.Cipher = createCipher
14185 exports.createCipheriv = exports.Cipheriv = createCipheriv
14186 exports.createDecipher = exports.Decipher = createDecipher
14187 exports.createDecipheriv = exports.Decipheriv = createDecipheriv
14188 exports.listCiphers = exports.getCiphers = getCiphers
14189
14190 },{"browserify-aes/browser":84,"browserify-aes/modes":95,"browserify-des":100,"browserify-des/modes":101,"evp_bytestokey":146}],100:[function(require,module,exports){
14191 var CipherBase = require('cipher-base')
14192 var des = require('des.js')
14193 var inherits = require('inherits')
14194 var Buffer = require('safe-buffer').Buffer
14195
14196 var modes = {
14197 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
14198 'des-ede3': des.EDE,
14199 'des-ede-cbc': des.CBC.instantiate(des.EDE),
14200 'des-ede': des.EDE,
14201 'des-cbc': des.CBC.instantiate(des.DES),
14202 'des-ecb': des.DES
14203 }
14204 modes.des = modes['des-cbc']
14205 modes.des3 = modes['des-ede3-cbc']
14206 module.exports = DES
14207 inherits(DES, CipherBase)
14208 function DES (opts) {
14209 CipherBase.call(this)
14210 var modeName = opts.mode.toLowerCase()
14211 var mode = modes[modeName]
14212 var type
14213 if (opts.decrypt) {
14214 type = 'decrypt'
14215 } else {
14216 type = 'encrypt'
14217 }
14218 var key = opts.key
14219 if (!Buffer.isBuffer(key)) {
14220 key = Buffer.from(key)
14221 }
14222 if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
14223 key = Buffer.concat([key, key.slice(0, 8)])
14224 }
14225 var iv = opts.iv
14226 if (!Buffer.isBuffer(iv)) {
14227 iv = Buffer.from(iv)
14228 }
14229 this._des = mode.create({
14230 key: key,
14231 iv: iv,
14232 type: type
14233 })
14234 }
14235 DES.prototype._update = function (data) {
14236 return Buffer.from(this._des.update(data))
14237 }
14238 DES.prototype._final = function () {
14239 return Buffer.from(this._des.final())
14240 }
14241
14242 },{"cipher-base":111,"des.js":119,"inherits":162,"safe-buffer":206}],101:[function(require,module,exports){
14243 exports['des-ecb'] = {
14244 key: 8,
14245 iv: 0
14246 }
14247 exports['des-cbc'] = exports.des = {
14248 key: 8,
14249 iv: 8
14250 }
14251 exports['des-ede3-cbc'] = exports.des3 = {
14252 key: 24,
14253 iv: 8
14254 }
14255 exports['des-ede3'] = {
14256 key: 24,
14257 iv: 0
14258 }
14259 exports['des-ede-cbc'] = {
14260 key: 16,
14261 iv: 8
14262 }
14263 exports['des-ede'] = {
14264 key: 16,
14265 iv: 0
14266 }
14267
14268 },{}],102:[function(require,module,exports){
14269 (function (Buffer){
14270 var bn = require('bn.js');
14271 var randomBytes = require('randombytes');
14272 module.exports = crt;
14273 function blind(priv) {
14274 var r = getr(priv);
14275 var blinder = r.toRed(bn.mont(priv.modulus))
14276 .redPow(new bn(priv.publicExponent)).fromRed();
14277 return {
14278 blinder: blinder,
14279 unblinder:r.invm(priv.modulus)
14280 };
14281 }
14282 function crt(msg, priv) {
14283 var blinds = blind(priv);
14284 var len = priv.modulus.byteLength();
14285 var mod = bn.mont(priv.modulus);
14286 var blinded = new bn(msg).mul(blinds.blinder).umod(priv.modulus);
14287 var c1 = blinded.toRed(bn.mont(priv.prime1));
14288 var c2 = blinded.toRed(bn.mont(priv.prime2));
14289 var qinv = priv.coefficient;
14290 var p = priv.prime1;
14291 var q = priv.prime2;
14292 var m1 = c1.redPow(priv.exponent1);
14293 var m2 = c2.redPow(priv.exponent2);
14294 m1 = m1.fromRed();
14295 m2 = m2.fromRed();
14296 var h = m1.isub(m2).imul(qinv).umod(p);
14297 h.imul(q);
14298 m2.iadd(h);
14299 return new Buffer(m2.imul(blinds.unblinder).umod(priv.modulus).toArray(false, len));
14300 }
14301 crt.getr = getr;
14302 function getr(priv) {
14303 var len = priv.modulus.byteLength();
14304 var r = new bn(randomBytes(len));
14305 while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)) {
14306 r = new bn(randomBytes(len));
14307 }
14308 return r;
14309 }
14310
14311 }).call(this,require("buffer").Buffer)
14312 },{"bn.js":79,"buffer":110,"randombytes":188}],103:[function(require,module,exports){
14313 module.exports = require('./browser/algorithms.json')
14314
14315 },{"./browser/algorithms.json":104}],104:[function(require,module,exports){
14316 module.exports={
14317 "sha224WithRSAEncryption": {
14318 "sign": "rsa",
14319 "hash": "sha224",
14320 "id": "302d300d06096086480165030402040500041c"
14321 },
14322 "RSA-SHA224": {
14323 "sign": "ecdsa/rsa",
14324 "hash": "sha224",
14325 "id": "302d300d06096086480165030402040500041c"
14326 },
14327 "sha256WithRSAEncryption": {
14328 "sign": "rsa",
14329 "hash": "sha256",
14330 "id": "3031300d060960864801650304020105000420"
14331 },
14332 "RSA-SHA256": {
14333 "sign": "ecdsa/rsa",
14334 "hash": "sha256",
14335 "id": "3031300d060960864801650304020105000420"
14336 },
14337 "sha384WithRSAEncryption": {
14338 "sign": "rsa",
14339 "hash": "sha384",
14340 "id": "3041300d060960864801650304020205000430"
14341 },
14342 "RSA-SHA384": {
14343 "sign": "ecdsa/rsa",
14344 "hash": "sha384",
14345 "id": "3041300d060960864801650304020205000430"
14346 },
14347 "sha512WithRSAEncryption": {
14348 "sign": "rsa",
14349 "hash": "sha512",
14350 "id": "3051300d060960864801650304020305000440"
14351 },
14352 "RSA-SHA512": {
14353 "sign": "ecdsa/rsa",
14354 "hash": "sha512",
14355 "id": "3051300d060960864801650304020305000440"
14356 },
14357 "RSA-SHA1": {
14358 "sign": "rsa",
14359 "hash": "sha1",
14360 "id": "3021300906052b0e03021a05000414"
14361 },
14362 "ecdsa-with-SHA1": {
14363 "sign": "ecdsa",
14364 "hash": "sha1",
14365 "id": ""
14366 },
14367 "sha256": {
14368 "sign": "ecdsa",
14369 "hash": "sha256",
14370 "id": ""
14371 },
14372 "sha224": {
14373 "sign": "ecdsa",
14374 "hash": "sha224",
14375 "id": ""
14376 },
14377 "sha384": {
14378 "sign": "ecdsa",
14379 "hash": "sha384",
14380 "id": ""
14381 },
14382 "sha512": {
14383 "sign": "ecdsa",
14384 "hash": "sha512",
14385 "id": ""
14386 },
14387 "DSA-SHA": {
14388 "sign": "dsa",
14389 "hash": "sha1",
14390 "id": ""
14391 },
14392 "DSA-SHA1": {
14393 "sign": "dsa",
14394 "hash": "sha1",
14395 "id": ""
14396 },
14397 "DSA": {
14398 "sign": "dsa",
14399 "hash": "sha1",
14400 "id": ""
14401 },
14402 "DSA-WITH-SHA224": {
14403 "sign": "dsa",
14404 "hash": "sha224",
14405 "id": ""
14406 },
14407 "DSA-SHA224": {
14408 "sign": "dsa",
14409 "hash": "sha224",
14410 "id": ""
14411 },
14412 "DSA-WITH-SHA256": {
14413 "sign": "dsa",
14414 "hash": "sha256",
14415 "id": ""
14416 },
14417 "DSA-SHA256": {
14418 "sign": "dsa",
14419 "hash": "sha256",
14420 "id": ""
14421 },
14422 "DSA-WITH-SHA384": {
14423 "sign": "dsa",
14424 "hash": "sha384",
14425 "id": ""
14426 },
14427 "DSA-SHA384": {
14428 "sign": "dsa",
14429 "hash": "sha384",
14430 "id": ""
14431 },
14432 "DSA-WITH-SHA512": {
14433 "sign": "dsa",
14434 "hash": "sha512",
14435 "id": ""
14436 },
14437 "DSA-SHA512": {
14438 "sign": "dsa",
14439 "hash": "sha512",
14440 "id": ""
14441 },
14442 "DSA-RIPEMD160": {
14443 "sign": "dsa",
14444 "hash": "rmd160",
14445 "id": ""
14446 },
14447 "ripemd160WithRSA": {
14448 "sign": "rsa",
14449 "hash": "rmd160",
14450 "id": "3021300906052b2403020105000414"
14451 },
14452 "RSA-RIPEMD160": {
14453 "sign": "rsa",
14454 "hash": "rmd160",
14455 "id": "3021300906052b2403020105000414"
14456 },
14457 "md5WithRSAEncryption": {
14458 "sign": "rsa",
14459 "hash": "md5",
14460 "id": "3020300c06082a864886f70d020505000410"
14461 },
14462 "RSA-MD5": {
14463 "sign": "rsa",
14464 "hash": "md5",
14465 "id": "3020300c06082a864886f70d020505000410"
14466 }
14467 }
14468
14469 },{}],105:[function(require,module,exports){
14470 module.exports={
14471 "1.3.132.0.10": "secp256k1",
14472 "1.3.132.0.33": "p224",
14473 "1.2.840.10045.3.1.1": "p192",
14474 "1.2.840.10045.3.1.7": "p256",
14475 "1.3.132.0.34": "p384",
14476 "1.3.132.0.35": "p521"
14477 }
14478
14479 },{}],106:[function(require,module,exports){
14480 (function (Buffer){
14481 var createHash = require('create-hash')
14482 var stream = require('stream')
14483 var inherits = require('inherits')
14484 var sign = require('./sign')
14485 var verify = require('./verify')
14486
14487 var algorithms = require('./algorithms.json')
14488 Object.keys(algorithms).forEach(function (key) {
14489 algorithms[key].id = new Buffer(algorithms[key].id, 'hex')
14490 algorithms[key.toLowerCase()] = algorithms[key]
14491 })
14492
14493 function Sign (algorithm) {
14494 stream.Writable.call(this)
14495
14496 var data = algorithms[algorithm]
14497 if (!data) throw new Error('Unknown message digest')
14498
14499 this._hashType = data.hash
14500 this._hash = createHash(data.hash)
14501 this._tag = data.id
14502 this._signType = data.sign
14503 }
14504 inherits(Sign, stream.Writable)
14505
14506 Sign.prototype._write = function _write (data, _, done) {
14507 this._hash.update(data)
14508 done()
14509 }
14510
14511 Sign.prototype.update = function update (data, enc) {
14512 if (typeof data === 'string') data = new Buffer(data, enc)
14513
14514 this._hash.update(data)
14515 return this
14516 }
14517
14518 Sign.prototype.sign = function signMethod (key, enc) {
14519 this.end()
14520 var hash = this._hash.digest()
14521 var sig = sign(hash, key, this._hashType, this._signType, this._tag)
14522
14523 return enc ? sig.toString(enc) : sig
14524 }
14525
14526 function Verify (algorithm) {
14527 stream.Writable.call(this)
14528
14529 var data = algorithms[algorithm]
14530 if (!data) throw new Error('Unknown message digest')
14531
14532 this._hash = createHash(data.hash)
14533 this._tag = data.id
14534 this._signType = data.sign
14535 }
14536 inherits(Verify, stream.Writable)
14537
14538 Verify.prototype._write = function _write (data, _, done) {
14539 this._hash.update(data)
14540 done()
14541 }
14542
14543 Verify.prototype.update = function update (data, enc) {
14544 if (typeof data === 'string') data = new Buffer(data, enc)
14545
14546 this._hash.update(data)
14547 return this
14548 }
14549
14550 Verify.prototype.verify = function verifyMethod (key, sig, enc) {
14551 if (typeof sig === 'string') sig = new Buffer(sig, enc)
14552
14553 this.end()
14554 var hash = this._hash.digest()
14555 return verify(sig, hash, key, this._signType, this._tag)
14556 }
14557
14558 function createSign (algorithm) {
14559 return new Sign(algorithm)
14560 }
14561
14562 function createVerify (algorithm) {
14563 return new Verify(algorithm)
14564 }
14565
14566 module.exports = {
14567 Sign: createSign,
14568 Verify: createVerify,
14569 createSign: createSign,
14570 createVerify: createVerify
14571 }
14572
14573 }).call(this,require("buffer").Buffer)
14574 },{"./algorithms.json":104,"./sign":107,"./verify":108,"buffer":110,"create-hash":114,"inherits":162,"stream":215}],107:[function(require,module,exports){
14575 (function (Buffer){
14576 // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
14577 var createHmac = require('create-hmac')
14578 var crt = require('browserify-rsa')
14579 var EC = require('elliptic').ec
14580 var BN = require('bn.js')
14581 var parseKeys = require('parse-asn1')
14582 var curves = require('./curves.json')
14583
14584 function sign (hash, key, hashType, signType, tag) {
14585 var priv = parseKeys(key)
14586 if (priv.curve) {
14587 // rsa keys can be interpreted as ecdsa ones in openssl
14588 if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type')
14589 return ecSign(hash, priv)
14590 } else if (priv.type === 'dsa') {
14591 if (signType !== 'dsa') throw new Error('wrong private key type')
14592 return dsaSign(hash, priv, hashType)
14593 } else {
14594 if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type')
14595 }
14596 hash = Buffer.concat([tag, hash])
14597 var len = priv.modulus.byteLength()
14598 var pad = [ 0, 1 ]
14599 while (hash.length + pad.length + 1 < len) pad.push(0xff)
14600 pad.push(0x00)
14601 var i = -1
14602 while (++i < hash.length) pad.push(hash[i])
14603
14604 var out = crt(pad, priv)
14605 return out
14606 }
14607
14608 function ecSign (hash, priv) {
14609 var curveId = curves[priv.curve.join('.')]
14610 if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'))
14611
14612 var curve = new EC(curveId)
14613 var key = curve.keyFromPrivate(priv.privateKey)
14614 var out = key.sign(hash)
14615
14616 return new Buffer(out.toDER())
14617 }
14618
14619 function dsaSign (hash, priv, algo) {
14620 var x = priv.params.priv_key
14621 var p = priv.params.p
14622 var q = priv.params.q
14623 var g = priv.params.g
14624 var r = new BN(0)
14625 var k
14626 var H = bits2int(hash, q).mod(q)
14627 var s = false
14628 var kv = getKey(x, q, hash, algo)
14629 while (s === false) {
14630 k = makeKey(q, kv, algo)
14631 r = makeR(g, k, p, q)
14632 s = k.invm(q).imul(H.add(x.mul(r))).mod(q)
14633 if (s.cmpn(0) === 0) {
14634 s = false
14635 r = new BN(0)
14636 }
14637 }
14638 return toDER(r, s)
14639 }
14640
14641 function toDER (r, s) {
14642 r = r.toArray()
14643 s = s.toArray()
14644
14645 // Pad values
14646 if (r[0] & 0x80) r = [ 0 ].concat(r)
14647 if (s[0] & 0x80) s = [ 0 ].concat(s)
14648
14649 var total = r.length + s.length + 4
14650 var res = [ 0x30, total, 0x02, r.length ]
14651 res = res.concat(r, [ 0x02, s.length ], s)
14652 return new Buffer(res)
14653 }
14654
14655 function getKey (x, q, hash, algo) {
14656 x = new Buffer(x.toArray())
14657 if (x.length < q.byteLength()) {
14658 var zeros = new Buffer(q.byteLength() - x.length)
14659 zeros.fill(0)
14660 x = Buffer.concat([ zeros, x ])
14661 }
14662 var hlen = hash.length
14663 var hbits = bits2octets(hash, q)
14664 var v = new Buffer(hlen)
14665 v.fill(1)
14666 var k = new Buffer(hlen)
14667 k.fill(0)
14668 k = createHmac(algo, k).update(v).update(new Buffer([ 0 ])).update(x).update(hbits).digest()
14669 v = createHmac(algo, k).update(v).digest()
14670 k = createHmac(algo, k).update(v).update(new Buffer([ 1 ])).update(x).update(hbits).digest()
14671 v = createHmac(algo, k).update(v).digest()
14672 return { k: k, v: v }
14673 }
14674
14675 function bits2int (obits, q) {
14676 var bits = new BN(obits)
14677 var shift = (obits.length << 3) - q.bitLength()
14678 if (shift > 0) bits.ishrn(shift)
14679 return bits
14680 }
14681
14682 function bits2octets (bits, q) {
14683 bits = bits2int(bits, q)
14684 bits = bits.mod(q)
14685 var out = new Buffer(bits.toArray())
14686 if (out.length < q.byteLength()) {
14687 var zeros = new Buffer(q.byteLength() - out.length)
14688 zeros.fill(0)
14689 out = Buffer.concat([ zeros, out ])
14690 }
14691 return out
14692 }
14693
14694 function makeKey (q, kv, algo) {
14695 var t
14696 var k
14697
14698 do {
14699 t = new Buffer(0)
14700
14701 while (t.length * 8 < q.bitLength()) {
14702 kv.v = createHmac(algo, kv.k).update(kv.v).digest()
14703 t = Buffer.concat([ t, kv.v ])
14704 }
14705
14706 k = bits2int(t, q)
14707 kv.k = createHmac(algo, kv.k).update(kv.v).update(new Buffer([ 0 ])).digest()
14708 kv.v = createHmac(algo, kv.k).update(kv.v).digest()
14709 } while (k.cmp(q) !== -1)
14710
14711 return k
14712 }
14713
14714 function makeR (g, k, p, q) {
14715 return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q)
14716 }
14717
14718 module.exports = sign
14719 module.exports.getKey = getKey
14720 module.exports.makeKey = makeKey
14721
14722 }).call(this,require("buffer").Buffer)
14723 },{"./curves.json":105,"bn.js":79,"browserify-rsa":102,"buffer":110,"create-hmac":116,"elliptic":129,"parse-asn1":174}],108:[function(require,module,exports){
14724 (function (Buffer){
14725 // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
14726 var BN = require('bn.js')
14727 var EC = require('elliptic').ec
14728 var parseKeys = require('parse-asn1')
14729 var curves = require('./curves.json')
14730
14731 function verify (sig, hash, key, signType, tag) {
14732 var pub = parseKeys(key)
14733 if (pub.type === 'ec') {
14734 // rsa keys can be interpreted as ecdsa ones in openssl
14735 if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type')
14736 return ecVerify(sig, hash, pub)
14737 } else if (pub.type === 'dsa') {
14738 if (signType !== 'dsa') throw new Error('wrong public key type')
14739 return dsaVerify(sig, hash, pub)
14740 } else {
14741 if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type')
14742 }
14743 hash = Buffer.concat([tag, hash])
14744 var len = pub.modulus.byteLength()
14745 var pad = [ 1 ]
14746 var padNum = 0
14747 while (hash.length + pad.length + 2 < len) {
14748 pad.push(0xff)
14749 padNum++
14750 }
14751 pad.push(0x00)
14752 var i = -1
14753 while (++i < hash.length) {
14754 pad.push(hash[i])
14755 }
14756 pad = new Buffer(pad)
14757 var red = BN.mont(pub.modulus)
14758 sig = new BN(sig).toRed(red)
14759
14760 sig = sig.redPow(new BN(pub.publicExponent))
14761 sig = new Buffer(sig.fromRed().toArray())
14762 var out = padNum < 8 ? 1 : 0
14763 len = Math.min(sig.length, pad.length)
14764 if (sig.length !== pad.length) out = 1
14765
14766 i = -1
14767 while (++i < len) out |= sig[i] ^ pad[i]
14768 return out === 0
14769 }
14770
14771 function ecVerify (sig, hash, pub) {
14772 var curveId = curves[pub.data.algorithm.curve.join('.')]
14773 if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'))
14774
14775 var curve = new EC(curveId)
14776 var pubkey = pub.data.subjectPrivateKey.data
14777
14778 return curve.verify(hash, sig, pubkey)
14779 }
14780
14781 function dsaVerify (sig, hash, pub) {
14782 var p = pub.data.p
14783 var q = pub.data.q
14784 var g = pub.data.g
14785 var y = pub.data.pub_key
14786 var unpacked = parseKeys.signature.decode(sig, 'der')
14787 var s = unpacked.s
14788 var r = unpacked.r
14789 checkValue(s, q)
14790 checkValue(r, q)
14791 var montp = BN.mont(p)
14792 var w = s.invm(q)
14793 var v = g.toRed(montp)
14794 .redPow(new BN(hash).mul(w).mod(q))
14795 .fromRed()
14796 .mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed())
14797 .mod(p)
14798 .mod(q)
14799 return v.cmp(r) === 0
14800 }
14801
14802 function checkValue (b, q) {
14803 if (b.cmpn(0) <= 0) throw new Error('invalid sig')
14804 if (b.cmp(q) >= q) throw new Error('invalid sig')
14805 }
14806
14807 module.exports = verify
14808
14809 }).call(this,require("buffer").Buffer)
14810 },{"./curves.json":105,"bn.js":79,"buffer":110,"elliptic":129,"parse-asn1":174}],109:[function(require,module,exports){
14811 arguments[4][29][0].apply(exports,arguments)
14812 },{"buffer":110,"dup":29}],110:[function(require,module,exports){
14813 (function (Buffer){
14814 /*!
14815 * The buffer module from node.js, for the browser.
14816 *
14817 * @author Feross Aboukhadijeh <https://feross.org>
14818 * @license MIT
14819 */
14820 /* eslint-disable no-proto */
14821
14822 'use strict'
14823
14824 var base64 = require('base64-js')
14825 var ieee754 = require('ieee754')
14826 var customInspectSymbol =
14827 (typeof Symbol === 'function' && typeof Symbol.for === 'function')
14828 ? Symbol.for('nodejs.util.inspect.custom')
14829 : null
14830
14831 exports.Buffer = Buffer
14832 exports.SlowBuffer = SlowBuffer
14833 exports.INSPECT_MAX_BYTES = 50
14834
14835 var K_MAX_LENGTH = 0x7fffffff
14836 exports.kMaxLength = K_MAX_LENGTH
14837
14838 /**
14839 * If `Buffer.TYPED_ARRAY_SUPPORT`:
14840 * === true Use Uint8Array implementation (fastest)
14841 * === false Print warning and recommend using `buffer` v4.x which has an Object
14842 * implementation (most compatible, even IE6)
14843 *
14844 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
14845 * Opera 11.6+, iOS 4.2+.
14846 *
14847 * We report that the browser does not support typed arrays if the are not subclassable
14848 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
14849 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
14850 * for __proto__ and has a buggy typed array implementation.
14851 */
14852 Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
14853
14854 if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
14855 typeof console.error === 'function') {
14856 console.error(
14857 'This browser lacks typed array (Uint8Array) support which is required by ' +
14858 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
14859 )
14860 }
14861
14862 function typedArraySupport () {
14863 // Can typed array instances can be augmented?
14864 try {
14865 var arr = new Uint8Array(1)
14866 var proto = { foo: function () { return 42 } }
14867 Object.setPrototypeOf(proto, Uint8Array.prototype)
14868 Object.setPrototypeOf(arr, proto)
14869 return arr.foo() === 42
14870 } catch (e) {
14871 return false
14872 }
14873 }
14874
14875 Object.defineProperty(Buffer.prototype, 'parent', {
14876 enumerable: true,
14877 get: function () {
14878 if (!Buffer.isBuffer(this)) return undefined
14879 return this.buffer
14880 }
14881 })
14882
14883 Object.defineProperty(Buffer.prototype, 'offset', {
14884 enumerable: true,
14885 get: function () {
14886 if (!Buffer.isBuffer(this)) return undefined
14887 return this.byteOffset
14888 }
14889 })
14890
14891 function createBuffer (length) {
14892 if (length > K_MAX_LENGTH) {
14893 throw new RangeError('The value "' + length + '" is invalid for option "size"')
14894 }
14895 // Return an augmented `Uint8Array` instance
14896 var buf = new Uint8Array(length)
14897 Object.setPrototypeOf(buf, Buffer.prototype)
14898 return buf
14899 }
14900
14901 /**
14902 * The Buffer constructor returns instances of `Uint8Array` that have their
14903 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
14904 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
14905 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
14906 * returns a single octet.
14907 *
14908 * The `Uint8Array` prototype remains unmodified.
14909 */
14910
14911 function Buffer (arg, encodingOrOffset, length) {
14912 // Common case.
14913 if (typeof arg === 'number') {
14914 if (typeof encodingOrOffset === 'string') {
14915 throw new TypeError(
14916 'The "string" argument must be of type string. Received type number'
14917 )
14918 }
14919 return allocUnsafe(arg)
14920 }
14921 return from(arg, encodingOrOffset, length)
14922 }
14923
14924 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
14925 if (typeof Symbol !== 'undefined' && Symbol.species != null &&
14926 Buffer[Symbol.species] === Buffer) {
14927 Object.defineProperty(Buffer, Symbol.species, {
14928 value: null,
14929 configurable: true,
14930 enumerable: false,
14931 writable: false
14932 })
14933 }
14934
14935 Buffer.poolSize = 8192 // not used by this implementation
14936
14937 function from (value, encodingOrOffset, length) {
14938 if (typeof value === 'string') {
14939 return fromString(value, encodingOrOffset)
14940 }
14941
14942 if (ArrayBuffer.isView(value)) {
14943 return fromArrayLike(value)
14944 }
14945
14946 if (value == null) {
14947 throw new TypeError(
14948 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
14949 'or Array-like Object. Received type ' + (typeof value)
14950 )
14951 }
14952
14953 if (isInstance(value, ArrayBuffer) ||
14954 (value && isInstance(value.buffer, ArrayBuffer))) {
14955 return fromArrayBuffer(value, encodingOrOffset, length)
14956 }
14957
14958 if (typeof value === 'number') {
14959 throw new TypeError(
14960 'The "value" argument must not be of type number. Received type number'
14961 )
14962 }
14963
14964 var valueOf = value.valueOf && value.valueOf()
14965 if (valueOf != null && valueOf !== value) {
14966 return Buffer.from(valueOf, encodingOrOffset, length)
14967 }
14968
14969 var b = fromObject(value)
14970 if (b) return b
14971
14972 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
14973 typeof value[Symbol.toPrimitive] === 'function') {
14974 return Buffer.from(
14975 value[Symbol.toPrimitive]('string'), encodingOrOffset, length
14976 )
14977 }
14978
14979 throw new TypeError(
14980 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
14981 'or Array-like Object. Received type ' + (typeof value)
14982 )
14983 }
14984
14985 /**
14986 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
14987 * if value is a number.
14988 * Buffer.from(str[, encoding])
14989 * Buffer.from(array)
14990 * Buffer.from(buffer)
14991 * Buffer.from(arrayBuffer[, byteOffset[, length]])
14992 **/
14993 Buffer.from = function (value, encodingOrOffset, length) {
14994 return from(value, encodingOrOffset, length)
14995 }
14996
14997 // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
14998 // https://github.com/feross/buffer/pull/148
14999 Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
15000 Object.setPrototypeOf(Buffer, Uint8Array)
15001
15002 function assertSize (size) {
15003 if (typeof size !== 'number') {
15004 throw new TypeError('"size" argument must be of type number')
15005 } else if (size < 0) {
15006 throw new RangeError('The value "' + size + '" is invalid for option "size"')
15007 }
15008 }
15009
15010 function alloc (size, fill, encoding) {
15011 assertSize(size)
15012 if (size <= 0) {
15013 return createBuffer(size)
15014 }
15015 if (fill !== undefined) {
15016 // Only pay attention to encoding if it's a string. This
15017 // prevents accidentally sending in a number that would
15018 // be interpretted as a start offset.
15019 return typeof encoding === 'string'
15020 ? createBuffer(size).fill(fill, encoding)
15021 : createBuffer(size).fill(fill)
15022 }
15023 return createBuffer(size)
15024 }
15025
15026 /**
15027 * Creates a new filled Buffer instance.
15028 * alloc(size[, fill[, encoding]])
15029 **/
15030 Buffer.alloc = function (size, fill, encoding) {
15031 return alloc(size, fill, encoding)
15032 }
15033
15034 function allocUnsafe (size) {
15035 assertSize(size)
15036 return createBuffer(size < 0 ? 0 : checked(size) | 0)
15037 }
15038
15039 /**
15040 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
15041 * */
15042 Buffer.allocUnsafe = function (size) {
15043 return allocUnsafe(size)
15044 }
15045 /**
15046 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
15047 */
15048 Buffer.allocUnsafeSlow = function (size) {
15049 return allocUnsafe(size)
15050 }
15051
15052 function fromString (string, encoding) {
15053 if (typeof encoding !== 'string' || encoding === '') {
15054 encoding = 'utf8'
15055 }
15056
15057 if (!Buffer.isEncoding(encoding)) {
15058 throw new TypeError('Unknown encoding: ' + encoding)
15059 }
15060
15061 var length = byteLength(string, encoding) | 0
15062 var buf = createBuffer(length)
15063
15064 var actual = buf.write(string, encoding)
15065
15066 if (actual !== length) {
15067 // Writing a hex string, for example, that contains invalid characters will
15068 // cause everything after the first invalid character to be ignored. (e.g.
15069 // 'abxxcd' will be treated as 'ab')
15070 buf = buf.slice(0, actual)
15071 }
15072
15073 return buf
15074 }
15075
15076 function fromArrayLike (array) {
15077 var length = array.length < 0 ? 0 : checked(array.length) | 0
15078 var buf = createBuffer(length)
15079 for (var i = 0; i < length; i += 1) {
15080 buf[i] = array[i] & 255
15081 }
15082 return buf
15083 }
15084
15085 function fromArrayBuffer (array, byteOffset, length) {
15086 if (byteOffset < 0 || array.byteLength < byteOffset) {
15087 throw new RangeError('"offset" is outside of buffer bounds')
15088 }
15089
15090 if (array.byteLength < byteOffset + (length || 0)) {
15091 throw new RangeError('"length" is outside of buffer bounds')
15092 }
15093
15094 var buf
15095 if (byteOffset === undefined && length === undefined) {
15096 buf = new Uint8Array(array)
15097 } else if (length === undefined) {
15098 buf = new Uint8Array(array, byteOffset)
15099 } else {
15100 buf = new Uint8Array(array, byteOffset, length)
15101 }
15102
15103 // Return an augmented `Uint8Array` instance
15104 Object.setPrototypeOf(buf, Buffer.prototype)
15105
15106 return buf
15107 }
15108
15109 function fromObject (obj) {
15110 if (Buffer.isBuffer(obj)) {
15111 var len = checked(obj.length) | 0
15112 var buf = createBuffer(len)
15113
15114 if (buf.length === 0) {
15115 return buf
15116 }
15117
15118 obj.copy(buf, 0, 0, len)
15119 return buf
15120 }
15121
15122 if (obj.length !== undefined) {
15123 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
15124 return createBuffer(0)
15125 }
15126 return fromArrayLike(obj)
15127 }
15128
15129 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
15130 return fromArrayLike(obj.data)
15131 }
15132 }
15133
15134 function checked (length) {
15135 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
15136 // length is NaN (which is otherwise coerced to zero.)
15137 if (length >= K_MAX_LENGTH) {
15138 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
15139 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
15140 }
15141 return length | 0
15142 }
15143
15144 function SlowBuffer (length) {
15145 if (+length != length) { // eslint-disable-line eqeqeq
15146 length = 0
15147 }
15148 return Buffer.alloc(+length)
15149 }
15150
15151 Buffer.isBuffer = function isBuffer (b) {
15152 return b != null && b._isBuffer === true &&
15153 b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
15154 }
15155
15156 Buffer.compare = function compare (a, b) {
15157 if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
15158 if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
15159 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
15160 throw new TypeError(
15161 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
15162 )
15163 }
15164
15165 if (a === b) return 0
15166
15167 var x = a.length
15168 var y = b.length
15169
15170 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
15171 if (a[i] !== b[i]) {
15172 x = a[i]
15173 y = b[i]
15174 break
15175 }
15176 }
15177
15178 if (x < y) return -1
15179 if (y < x) return 1
15180 return 0
15181 }
15182
15183 Buffer.isEncoding = function isEncoding (encoding) {
15184 switch (String(encoding).toLowerCase()) {
15185 case 'hex':
15186 case 'utf8':
15187 case 'utf-8':
15188 case 'ascii':
15189 case 'latin1':
15190 case 'binary':
15191 case 'base64':
15192 case 'ucs2':
15193 case 'ucs-2':
15194 case 'utf16le':
15195 case 'utf-16le':
15196 return true
15197 default:
15198 return false
15199 }
15200 }
15201
15202 Buffer.concat = function concat (list, length) {
15203 if (!Array.isArray(list)) {
15204 throw new TypeError('"list" argument must be an Array of Buffers')
15205 }
15206
15207 if (list.length === 0) {
15208 return Buffer.alloc(0)
15209 }
15210
15211 var i
15212 if (length === undefined) {
15213 length = 0
15214 for (i = 0; i < list.length; ++i) {
15215 length += list[i].length
15216 }
15217 }
15218
15219 var buffer = Buffer.allocUnsafe(length)
15220 var pos = 0
15221 for (i = 0; i < list.length; ++i) {
15222 var buf = list[i]
15223 if (isInstance(buf, Uint8Array)) {
15224 buf = Buffer.from(buf)
15225 }
15226 if (!Buffer.isBuffer(buf)) {
15227 throw new TypeError('"list" argument must be an Array of Buffers')
15228 }
15229 buf.copy(buffer, pos)
15230 pos += buf.length
15231 }
15232 return buffer
15233 }
15234
15235 function byteLength (string, encoding) {
15236 if (Buffer.isBuffer(string)) {
15237 return string.length
15238 }
15239 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
15240 return string.byteLength
15241 }
15242 if (typeof string !== 'string') {
15243 throw new TypeError(
15244 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
15245 'Received type ' + typeof string
15246 )
15247 }
15248
15249 var len = string.length
15250 var mustMatch = (arguments.length > 2 && arguments[2] === true)
15251 if (!mustMatch && len === 0) return 0
15252
15253 // Use a for loop to avoid recursion
15254 var loweredCase = false
15255 for (;;) {
15256 switch (encoding) {
15257 case 'ascii':
15258 case 'latin1':
15259 case 'binary':
15260 return len
15261 case 'utf8':
15262 case 'utf-8':
15263 return utf8ToBytes(string).length
15264 case 'ucs2':
15265 case 'ucs-2':
15266 case 'utf16le':
15267 case 'utf-16le':
15268 return len * 2
15269 case 'hex':
15270 return len >>> 1
15271 case 'base64':
15272 return base64ToBytes(string).length
15273 default:
15274 if (loweredCase) {
15275 return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
15276 }
15277 encoding = ('' + encoding).toLowerCase()
15278 loweredCase = true
15279 }
15280 }
15281 }
15282 Buffer.byteLength = byteLength
15283
15284 function slowToString (encoding, start, end) {
15285 var loweredCase = false
15286
15287 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
15288 // property of a typed array.
15289
15290 // This behaves neither like String nor Uint8Array in that we set start/end
15291 // to their upper/lower bounds if the value passed is out of range.
15292 // undefined is handled specially as per ECMA-262 6th Edition,
15293 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
15294 if (start === undefined || start < 0) {
15295 start = 0
15296 }
15297 // Return early if start > this.length. Done here to prevent potential uint32
15298 // coercion fail below.
15299 if (start > this.length) {
15300 return ''
15301 }
15302
15303 if (end === undefined || end > this.length) {
15304 end = this.length
15305 }
15306
15307 if (end <= 0) {
15308 return ''
15309 }
15310
15311 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
15312 end >>>= 0
15313 start >>>= 0
15314
15315 if (end <= start) {
15316 return ''
15317 }
15318
15319 if (!encoding) encoding = 'utf8'
15320
15321 while (true) {
15322 switch (encoding) {
15323 case 'hex':
15324 return hexSlice(this, start, end)
15325
15326 case 'utf8':
15327 case 'utf-8':
15328 return utf8Slice(this, start, end)
15329
15330 case 'ascii':
15331 return asciiSlice(this, start, end)
15332
15333 case 'latin1':
15334 case 'binary':
15335 return latin1Slice(this, start, end)
15336
15337 case 'base64':
15338 return base64Slice(this, start, end)
15339
15340 case 'ucs2':
15341 case 'ucs-2':
15342 case 'utf16le':
15343 case 'utf-16le':
15344 return utf16leSlice(this, start, end)
15345
15346 default:
15347 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
15348 encoding = (encoding + '').toLowerCase()
15349 loweredCase = true
15350 }
15351 }
15352 }
15353
15354 // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
15355 // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
15356 // reliably in a browserify context because there could be multiple different
15357 // copies of the 'buffer' package in use. This method works even for Buffer
15358 // instances that were created from another copy of the `buffer` package.
15359 // See: https://github.com/feross/buffer/issues/154
15360 Buffer.prototype._isBuffer = true
15361
15362 function swap (b, n, m) {
15363 var i = b[n]
15364 b[n] = b[m]
15365 b[m] = i
15366 }
15367
15368 Buffer.prototype.swap16 = function swap16 () {
15369 var len = this.length
15370 if (len % 2 !== 0) {
15371 throw new RangeError('Buffer size must be a multiple of 16-bits')
15372 }
15373 for (var i = 0; i < len; i += 2) {
15374 swap(this, i, i + 1)
15375 }
15376 return this
15377 }
15378
15379 Buffer.prototype.swap32 = function swap32 () {
15380 var len = this.length
15381 if (len % 4 !== 0) {
15382 throw new RangeError('Buffer size must be a multiple of 32-bits')
15383 }
15384 for (var i = 0; i < len; i += 4) {
15385 swap(this, i, i + 3)
15386 swap(this, i + 1, i + 2)
15387 }
15388 return this
15389 }
15390
15391 Buffer.prototype.swap64 = function swap64 () {
15392 var len = this.length
15393 if (len % 8 !== 0) {
15394 throw new RangeError('Buffer size must be a multiple of 64-bits')
15395 }
15396 for (var i = 0; i < len; i += 8) {
15397 swap(this, i, i + 7)
15398 swap(this, i + 1, i + 6)
15399 swap(this, i + 2, i + 5)
15400 swap(this, i + 3, i + 4)
15401 }
15402 return this
15403 }
15404
15405 Buffer.prototype.toString = function toString () {
15406 var length = this.length
15407 if (length === 0) return ''
15408 if (arguments.length === 0) return utf8Slice(this, 0, length)
15409 return slowToString.apply(this, arguments)
15410 }
15411
15412 Buffer.prototype.toLocaleString = Buffer.prototype.toString
15413
15414 Buffer.prototype.equals = function equals (b) {
15415 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
15416 if (this === b) return true
15417 return Buffer.compare(this, b) === 0
15418 }
15419
15420 Buffer.prototype.inspect = function inspect () {
15421 var str = ''
15422 var max = exports.INSPECT_MAX_BYTES
15423 str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
15424 if (this.length > max) str += ' ... '
15425 return '<Buffer ' + str + '>'
15426 }
15427 if (customInspectSymbol) {
15428 Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
15429 }
15430
15431 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
15432 if (isInstance(target, Uint8Array)) {
15433 target = Buffer.from(target, target.offset, target.byteLength)
15434 }
15435 if (!Buffer.isBuffer(target)) {
15436 throw new TypeError(
15437 'The "target" argument must be one of type Buffer or Uint8Array. ' +
15438 'Received type ' + (typeof target)
15439 )
15440 }
15441
15442 if (start === undefined) {
15443 start = 0
15444 }
15445 if (end === undefined) {
15446 end = target ? target.length : 0
15447 }
15448 if (thisStart === undefined) {
15449 thisStart = 0
15450 }
15451 if (thisEnd === undefined) {
15452 thisEnd = this.length
15453 }
15454
15455 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
15456 throw new RangeError('out of range index')
15457 }
15458
15459 if (thisStart >= thisEnd && start >= end) {
15460 return 0
15461 }
15462 if (thisStart >= thisEnd) {
15463 return -1
15464 }
15465 if (start >= end) {
15466 return 1
15467 }
15468
15469 start >>>= 0
15470 end >>>= 0
15471 thisStart >>>= 0
15472 thisEnd >>>= 0
15473
15474 if (this === target) return 0
15475
15476 var x = thisEnd - thisStart
15477 var y = end - start
15478 var len = Math.min(x, y)
15479
15480 var thisCopy = this.slice(thisStart, thisEnd)
15481 var targetCopy = target.slice(start, end)
15482
15483 for (var i = 0; i < len; ++i) {
15484 if (thisCopy[i] !== targetCopy[i]) {
15485 x = thisCopy[i]
15486 y = targetCopy[i]
15487 break
15488 }
15489 }
15490
15491 if (x < y) return -1
15492 if (y < x) return 1
15493 return 0
15494 }
15495
15496 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
15497 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
15498 //
15499 // Arguments:
15500 // - buffer - a Buffer to search
15501 // - val - a string, Buffer, or number
15502 // - byteOffset - an index into `buffer`; will be clamped to an int32
15503 // - encoding - an optional encoding, relevant is val is a string
15504 // - dir - true for indexOf, false for lastIndexOf
15505 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
15506 // Empty buffer means no match
15507 if (buffer.length === 0) return -1
15508
15509 // Normalize byteOffset
15510 if (typeof byteOffset === 'string') {
15511 encoding = byteOffset
15512 byteOffset = 0
15513 } else if (byteOffset > 0x7fffffff) {
15514 byteOffset = 0x7fffffff
15515 } else if (byteOffset < -0x80000000) {
15516 byteOffset = -0x80000000
15517 }
15518 byteOffset = +byteOffset // Coerce to Number.
15519 if (numberIsNaN(byteOffset)) {
15520 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
15521 byteOffset = dir ? 0 : (buffer.length - 1)
15522 }
15523
15524 // Normalize byteOffset: negative offsets start from the end of the buffer
15525 if (byteOffset < 0) byteOffset = buffer.length + byteOffset
15526 if (byteOffset >= buffer.length) {
15527 if (dir) return -1
15528 else byteOffset = buffer.length - 1
15529 } else if (byteOffset < 0) {
15530 if (dir) byteOffset = 0
15531 else return -1
15532 }
15533
15534 // Normalize val
15535 if (typeof val === 'string') {
15536 val = Buffer.from(val, encoding)
15537 }
15538
15539 // Finally, search either indexOf (if dir is true) or lastIndexOf
15540 if (Buffer.isBuffer(val)) {
15541 // Special case: looking for empty string/buffer always fails
15542 if (val.length === 0) {
15543 return -1
15544 }
15545 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
15546 } else if (typeof val === 'number') {
15547 val = val & 0xFF // Search for a byte value [0-255]
15548 if (typeof Uint8Array.prototype.indexOf === 'function') {
15549 if (dir) {
15550 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
15551 } else {
15552 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
15553 }
15554 }
15555 return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
15556 }
15557
15558 throw new TypeError('val must be string, number or Buffer')
15559 }
15560
15561 function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
15562 var indexSize = 1
15563 var arrLength = arr.length
15564 var valLength = val.length
15565
15566 if (encoding !== undefined) {
15567 encoding = String(encoding).toLowerCase()
15568 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
15569 encoding === 'utf16le' || encoding === 'utf-16le') {
15570 if (arr.length < 2 || val.length < 2) {
15571 return -1
15572 }
15573 indexSize = 2
15574 arrLength /= 2
15575 valLength /= 2
15576 byteOffset /= 2
15577 }
15578 }
15579
15580 function read (buf, i) {
15581 if (indexSize === 1) {
15582 return buf[i]
15583 } else {
15584 return buf.readUInt16BE(i * indexSize)
15585 }
15586 }
15587
15588 var i
15589 if (dir) {
15590 var foundIndex = -1
15591 for (i = byteOffset; i < arrLength; i++) {
15592 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
15593 if (foundIndex === -1) foundIndex = i
15594 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
15595 } else {
15596 if (foundIndex !== -1) i -= i - foundIndex
15597 foundIndex = -1
15598 }
15599 }
15600 } else {
15601 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
15602 for (i = byteOffset; i >= 0; i--) {
15603 var found = true
15604 for (var j = 0; j < valLength; j++) {
15605 if (read(arr, i + j) !== read(val, j)) {
15606 found = false
15607 break
15608 }
15609 }
15610 if (found) return i
15611 }
15612 }
15613
15614 return -1
15615 }
15616
15617 Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
15618 return this.indexOf(val, byteOffset, encoding) !== -1
15619 }
15620
15621 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
15622 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
15623 }
15624
15625 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
15626 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
15627 }
15628
15629 function hexWrite (buf, string, offset, length) {
15630 offset = Number(offset) || 0
15631 var remaining = buf.length - offset
15632 if (!length) {
15633 length = remaining
15634 } else {
15635 length = Number(length)
15636 if (length > remaining) {
15637 length = remaining
15638 }
15639 }
15640
15641 var strLen = string.length
15642
15643 if (length > strLen / 2) {
15644 length = strLen / 2
15645 }
15646 for (var i = 0; i < length; ++i) {
15647 var parsed = parseInt(string.substr(i * 2, 2), 16)
15648 if (numberIsNaN(parsed)) return i
15649 buf[offset + i] = parsed
15650 }
15651 return i
15652 }
15653
15654 function utf8Write (buf, string, offset, length) {
15655 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
15656 }
15657
15658 function asciiWrite (buf, string, offset, length) {
15659 return blitBuffer(asciiToBytes(string), buf, offset, length)
15660 }
15661
15662 function latin1Write (buf, string, offset, length) {
15663 return asciiWrite(buf, string, offset, length)
15664 }
15665
15666 function base64Write (buf, string, offset, length) {
15667 return blitBuffer(base64ToBytes(string), buf, offset, length)
15668 }
15669
15670 function ucs2Write (buf, string, offset, length) {
15671 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
15672 }
15673
15674 Buffer.prototype.write = function write (string, offset, length, encoding) {
15675 // Buffer#write(string)
15676 if (offset === undefined) {
15677 encoding = 'utf8'
15678 length = this.length
15679 offset = 0
15680 // Buffer#write(string, encoding)
15681 } else if (length === undefined && typeof offset === 'string') {
15682 encoding = offset
15683 length = this.length
15684 offset = 0
15685 // Buffer#write(string, offset[, length][, encoding])
15686 } else if (isFinite(offset)) {
15687 offset = offset >>> 0
15688 if (isFinite(length)) {
15689 length = length >>> 0
15690 if (encoding === undefined) encoding = 'utf8'
15691 } else {
15692 encoding = length
15693 length = undefined
15694 }
15695 } else {
15696 throw new Error(
15697 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
15698 )
15699 }
15700
15701 var remaining = this.length - offset
15702 if (length === undefined || length > remaining) length = remaining
15703
15704 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
15705 throw new RangeError('Attempt to write outside buffer bounds')
15706 }
15707
15708 if (!encoding) encoding = 'utf8'
15709
15710 var loweredCase = false
15711 for (;;) {
15712 switch (encoding) {
15713 case 'hex':
15714 return hexWrite(this, string, offset, length)
15715
15716 case 'utf8':
15717 case 'utf-8':
15718 return utf8Write(this, string, offset, length)
15719
15720 case 'ascii':
15721 return asciiWrite(this, string, offset, length)
15722
15723 case 'latin1':
15724 case 'binary':
15725 return latin1Write(this, string, offset, length)
15726
15727 case 'base64':
15728 // Warning: maxLength not taken into account in base64Write
15729 return base64Write(this, string, offset, length)
15730
15731 case 'ucs2':
15732 case 'ucs-2':
15733 case 'utf16le':
15734 case 'utf-16le':
15735 return ucs2Write(this, string, offset, length)
15736
15737 default:
15738 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
15739 encoding = ('' + encoding).toLowerCase()
15740 loweredCase = true
15741 }
15742 }
15743 }
15744
15745 Buffer.prototype.toJSON = function toJSON () {
15746 return {
15747 type: 'Buffer',
15748 data: Array.prototype.slice.call(this._arr || this, 0)
15749 }
15750 }
15751
15752 function base64Slice (buf, start, end) {
15753 if (start === 0 && end === buf.length) {
15754 return base64.fromByteArray(buf)
15755 } else {
15756 return base64.fromByteArray(buf.slice(start, end))
15757 }
15758 }
15759
15760 function utf8Slice (buf, start, end) {
15761 end = Math.min(buf.length, end)
15762 var res = []
15763
15764 var i = start
15765 while (i < end) {
15766 var firstByte = buf[i]
15767 var codePoint = null
15768 var bytesPerSequence = (firstByte > 0xEF) ? 4
15769 : (firstByte > 0xDF) ? 3
15770 : (firstByte > 0xBF) ? 2
15771 : 1
15772
15773 if (i + bytesPerSequence <= end) {
15774 var secondByte, thirdByte, fourthByte, tempCodePoint
15775
15776 switch (bytesPerSequence) {
15777 case 1:
15778 if (firstByte < 0x80) {
15779 codePoint = firstByte
15780 }
15781 break
15782 case 2:
15783 secondByte = buf[i + 1]
15784 if ((secondByte & 0xC0) === 0x80) {
15785 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
15786 if (tempCodePoint > 0x7F) {
15787 codePoint = tempCodePoint
15788 }
15789 }
15790 break
15791 case 3:
15792 secondByte = buf[i + 1]
15793 thirdByte = buf[i + 2]
15794 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
15795 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
15796 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
15797 codePoint = tempCodePoint
15798 }
15799 }
15800 break
15801 case 4:
15802 secondByte = buf[i + 1]
15803 thirdByte = buf[i + 2]
15804 fourthByte = buf[i + 3]
15805 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
15806 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
15807 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
15808 codePoint = tempCodePoint
15809 }
15810 }
15811 }
15812 }
15813
15814 if (codePoint === null) {
15815 // we did not generate a valid codePoint so insert a
15816 // replacement char (U+FFFD) and advance only 1 byte
15817 codePoint = 0xFFFD
15818 bytesPerSequence = 1
15819 } else if (codePoint > 0xFFFF) {
15820 // encode to utf16 (surrogate pair dance)
15821 codePoint -= 0x10000
15822 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
15823 codePoint = 0xDC00 | codePoint & 0x3FF
15824 }
15825
15826 res.push(codePoint)
15827 i += bytesPerSequence
15828 }
15829
15830 return decodeCodePointsArray(res)
15831 }
15832
15833 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
15834 // the lowest limit is Chrome, with 0x10000 args.
15835 // We go 1 magnitude less, for safety
15836 var MAX_ARGUMENTS_LENGTH = 0x1000
15837
15838 function decodeCodePointsArray (codePoints) {
15839 var len = codePoints.length
15840 if (len <= MAX_ARGUMENTS_LENGTH) {
15841 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
15842 }
15843
15844 // Decode in chunks to avoid "call stack size exceeded".
15845 var res = ''
15846 var i = 0
15847 while (i < len) {
15848 res += String.fromCharCode.apply(
15849 String,
15850 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
15851 )
15852 }
15853 return res
15854 }
15855
15856 function asciiSlice (buf, start, end) {
15857 var ret = ''
15858 end = Math.min(buf.length, end)
15859
15860 for (var i = start; i < end; ++i) {
15861 ret += String.fromCharCode(buf[i] & 0x7F)
15862 }
15863 return ret
15864 }
15865
15866 function latin1Slice (buf, start, end) {
15867 var ret = ''
15868 end = Math.min(buf.length, end)
15869
15870 for (var i = start; i < end; ++i) {
15871 ret += String.fromCharCode(buf[i])
15872 }
15873 return ret
15874 }
15875
15876 function hexSlice (buf, start, end) {
15877 var len = buf.length
15878
15879 if (!start || start < 0) start = 0
15880 if (!end || end < 0 || end > len) end = len
15881
15882 var out = ''
15883 for (var i = start; i < end; ++i) {
15884 out += toHex(buf[i])
15885 }
15886 return out
15887 }
15888
15889 function utf16leSlice (buf, start, end) {
15890 var bytes = buf.slice(start, end)
15891 var res = ''
15892 for (var i = 0; i < bytes.length; i += 2) {
15893 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
15894 }
15895 return res
15896 }
15897
15898 Buffer.prototype.slice = function slice (start, end) {
15899 var len = this.length
15900 start = ~~start
15901 end = end === undefined ? len : ~~end
15902
15903 if (start < 0) {
15904 start += len
15905 if (start < 0) start = 0
15906 } else if (start > len) {
15907 start = len
15908 }
15909
15910 if (end < 0) {
15911 end += len
15912 if (end < 0) end = 0
15913 } else if (end > len) {
15914 end = len
15915 }
15916
15917 if (end < start) end = start
15918
15919 var newBuf = this.subarray(start, end)
15920 // Return an augmented `Uint8Array` instance
15921 Object.setPrototypeOf(newBuf, Buffer.prototype)
15922
15923 return newBuf
15924 }
15925
15926 /*
15927 * Need to make sure that buffer isn't trying to write out of bounds.
15928 */
15929 function checkOffset (offset, ext, length) {
15930 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
15931 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
15932 }
15933
15934 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
15935 offset = offset >>> 0
15936 byteLength = byteLength >>> 0
15937 if (!noAssert) checkOffset(offset, byteLength, this.length)
15938
15939 var val = this[offset]
15940 var mul = 1
15941 var i = 0
15942 while (++i < byteLength && (mul *= 0x100)) {
15943 val += this[offset + i] * mul
15944 }
15945
15946 return val
15947 }
15948
15949 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
15950 offset = offset >>> 0
15951 byteLength = byteLength >>> 0
15952 if (!noAssert) {
15953 checkOffset(offset, byteLength, this.length)
15954 }
15955
15956 var val = this[offset + --byteLength]
15957 var mul = 1
15958 while (byteLength > 0 && (mul *= 0x100)) {
15959 val += this[offset + --byteLength] * mul
15960 }
15961
15962 return val
15963 }
15964
15965 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
15966 offset = offset >>> 0
15967 if (!noAssert) checkOffset(offset, 1, this.length)
15968 return this[offset]
15969 }
15970
15971 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
15972 offset = offset >>> 0
15973 if (!noAssert) checkOffset(offset, 2, this.length)
15974 return this[offset] | (this[offset + 1] << 8)
15975 }
15976
15977 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
15978 offset = offset >>> 0
15979 if (!noAssert) checkOffset(offset, 2, this.length)
15980 return (this[offset] << 8) | this[offset + 1]
15981 }
15982
15983 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
15984 offset = offset >>> 0
15985 if (!noAssert) checkOffset(offset, 4, this.length)
15986
15987 return ((this[offset]) |
15988 (this[offset + 1] << 8) |
15989 (this[offset + 2] << 16)) +
15990 (this[offset + 3] * 0x1000000)
15991 }
15992
15993 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
15994 offset = offset >>> 0
15995 if (!noAssert) checkOffset(offset, 4, this.length)
15996
15997 return (this[offset] * 0x1000000) +
15998 ((this[offset + 1] << 16) |
15999 (this[offset + 2] << 8) |
16000 this[offset + 3])
16001 }
16002
16003 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
16004 offset = offset >>> 0
16005 byteLength = byteLength >>> 0
16006 if (!noAssert) checkOffset(offset, byteLength, this.length)
16007
16008 var val = this[offset]
16009 var mul = 1
16010 var i = 0
16011 while (++i < byteLength && (mul *= 0x100)) {
16012 val += this[offset + i] * mul
16013 }
16014 mul *= 0x80
16015
16016 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
16017
16018 return val
16019 }
16020
16021 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
16022 offset = offset >>> 0
16023 byteLength = byteLength >>> 0
16024 if (!noAssert) checkOffset(offset, byteLength, this.length)
16025
16026 var i = byteLength
16027 var mul = 1
16028 var val = this[offset + --i]
16029 while (i > 0 && (mul *= 0x100)) {
16030 val += this[offset + --i] * mul
16031 }
16032 mul *= 0x80
16033
16034 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
16035
16036 return val
16037 }
16038
16039 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
16040 offset = offset >>> 0
16041 if (!noAssert) checkOffset(offset, 1, this.length)
16042 if (!(this[offset] & 0x80)) return (this[offset])
16043 return ((0xff - this[offset] + 1) * -1)
16044 }
16045
16046 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
16047 offset = offset >>> 0
16048 if (!noAssert) checkOffset(offset, 2, this.length)
16049 var val = this[offset] | (this[offset + 1] << 8)
16050 return (val & 0x8000) ? val | 0xFFFF0000 : val
16051 }
16052
16053 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
16054 offset = offset >>> 0
16055 if (!noAssert) checkOffset(offset, 2, this.length)
16056 var val = this[offset + 1] | (this[offset] << 8)
16057 return (val & 0x8000) ? val | 0xFFFF0000 : val
16058 }
16059
16060 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
16061 offset = offset >>> 0
16062 if (!noAssert) checkOffset(offset, 4, this.length)
16063
16064 return (this[offset]) |
16065 (this[offset + 1] << 8) |
16066 (this[offset + 2] << 16) |
16067 (this[offset + 3] << 24)
16068 }
16069
16070 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
16071 offset = offset >>> 0
16072 if (!noAssert) checkOffset(offset, 4, this.length)
16073
16074 return (this[offset] << 24) |
16075 (this[offset + 1] << 16) |
16076 (this[offset + 2] << 8) |
16077 (this[offset + 3])
16078 }
16079
16080 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
16081 offset = offset >>> 0
16082 if (!noAssert) checkOffset(offset, 4, this.length)
16083 return ieee754.read(this, offset, true, 23, 4)
16084 }
16085
16086 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
16087 offset = offset >>> 0
16088 if (!noAssert) checkOffset(offset, 4, this.length)
16089 return ieee754.read(this, offset, false, 23, 4)
16090 }
16091
16092 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
16093 offset = offset >>> 0
16094 if (!noAssert) checkOffset(offset, 8, this.length)
16095 return ieee754.read(this, offset, true, 52, 8)
16096 }
16097
16098 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
16099 offset = offset >>> 0
16100 if (!noAssert) checkOffset(offset, 8, this.length)
16101 return ieee754.read(this, offset, false, 52, 8)
16102 }
16103
16104 function checkInt (buf, value, offset, ext, max, min) {
16105 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
16106 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
16107 if (offset + ext > buf.length) throw new RangeError('Index out of range')
16108 }
16109
16110 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
16111 value = +value
16112 offset = offset >>> 0
16113 byteLength = byteLength >>> 0
16114 if (!noAssert) {
16115 var maxBytes = Math.pow(2, 8 * byteLength) - 1
16116 checkInt(this, value, offset, byteLength, maxBytes, 0)
16117 }
16118
16119 var mul = 1
16120 var i = 0
16121 this[offset] = value & 0xFF
16122 while (++i < byteLength && (mul *= 0x100)) {
16123 this[offset + i] = (value / mul) & 0xFF
16124 }
16125
16126 return offset + byteLength
16127 }
16128
16129 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
16130 value = +value
16131 offset = offset >>> 0
16132 byteLength = byteLength >>> 0
16133 if (!noAssert) {
16134 var maxBytes = Math.pow(2, 8 * byteLength) - 1
16135 checkInt(this, value, offset, byteLength, maxBytes, 0)
16136 }
16137
16138 var i = byteLength - 1
16139 var mul = 1
16140 this[offset + i] = value & 0xFF
16141 while (--i >= 0 && (mul *= 0x100)) {
16142 this[offset + i] = (value / mul) & 0xFF
16143 }
16144
16145 return offset + byteLength
16146 }
16147
16148 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
16149 value = +value
16150 offset = offset >>> 0
16151 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
16152 this[offset] = (value & 0xff)
16153 return offset + 1
16154 }
16155
16156 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
16157 value = +value
16158 offset = offset >>> 0
16159 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
16160 this[offset] = (value & 0xff)
16161 this[offset + 1] = (value >>> 8)
16162 return offset + 2
16163 }
16164
16165 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
16166 value = +value
16167 offset = offset >>> 0
16168 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
16169 this[offset] = (value >>> 8)
16170 this[offset + 1] = (value & 0xff)
16171 return offset + 2
16172 }
16173
16174 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
16175 value = +value
16176 offset = offset >>> 0
16177 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
16178 this[offset + 3] = (value >>> 24)
16179 this[offset + 2] = (value >>> 16)
16180 this[offset + 1] = (value >>> 8)
16181 this[offset] = (value & 0xff)
16182 return offset + 4
16183 }
16184
16185 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
16186 value = +value
16187 offset = offset >>> 0
16188 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
16189 this[offset] = (value >>> 24)
16190 this[offset + 1] = (value >>> 16)
16191 this[offset + 2] = (value >>> 8)
16192 this[offset + 3] = (value & 0xff)
16193 return offset + 4
16194 }
16195
16196 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
16197 value = +value
16198 offset = offset >>> 0
16199 if (!noAssert) {
16200 var limit = Math.pow(2, (8 * byteLength) - 1)
16201
16202 checkInt(this, value, offset, byteLength, limit - 1, -limit)
16203 }
16204
16205 var i = 0
16206 var mul = 1
16207 var sub = 0
16208 this[offset] = value & 0xFF
16209 while (++i < byteLength && (mul *= 0x100)) {
16210 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
16211 sub = 1
16212 }
16213 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
16214 }
16215
16216 return offset + byteLength
16217 }
16218
16219 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
16220 value = +value
16221 offset = offset >>> 0
16222 if (!noAssert) {
16223 var limit = Math.pow(2, (8 * byteLength) - 1)
16224
16225 checkInt(this, value, offset, byteLength, limit - 1, -limit)
16226 }
16227
16228 var i = byteLength - 1
16229 var mul = 1
16230 var sub = 0
16231 this[offset + i] = value & 0xFF
16232 while (--i >= 0 && (mul *= 0x100)) {
16233 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
16234 sub = 1
16235 }
16236 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
16237 }
16238
16239 return offset + byteLength
16240 }
16241
16242 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
16243 value = +value
16244 offset = offset >>> 0
16245 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
16246 if (value < 0) value = 0xff + value + 1
16247 this[offset] = (value & 0xff)
16248 return offset + 1
16249 }
16250
16251 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
16252 value = +value
16253 offset = offset >>> 0
16254 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
16255 this[offset] = (value & 0xff)
16256 this[offset + 1] = (value >>> 8)
16257 return offset + 2
16258 }
16259
16260 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
16261 value = +value
16262 offset = offset >>> 0
16263 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
16264 this[offset] = (value >>> 8)
16265 this[offset + 1] = (value & 0xff)
16266 return offset + 2
16267 }
16268
16269 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
16270 value = +value
16271 offset = offset >>> 0
16272 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
16273 this[offset] = (value & 0xff)
16274 this[offset + 1] = (value >>> 8)
16275 this[offset + 2] = (value >>> 16)
16276 this[offset + 3] = (value >>> 24)
16277 return offset + 4
16278 }
16279
16280 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
16281 value = +value
16282 offset = offset >>> 0
16283 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
16284 if (value < 0) value = 0xffffffff + value + 1
16285 this[offset] = (value >>> 24)
16286 this[offset + 1] = (value >>> 16)
16287 this[offset + 2] = (value >>> 8)
16288 this[offset + 3] = (value & 0xff)
16289 return offset + 4
16290 }
16291
16292 function checkIEEE754 (buf, value, offset, ext, max, min) {
16293 if (offset + ext > buf.length) throw new RangeError('Index out of range')
16294 if (offset < 0) throw new RangeError('Index out of range')
16295 }
16296
16297 function writeFloat (buf, value, offset, littleEndian, noAssert) {
16298 value = +value
16299 offset = offset >>> 0
16300 if (!noAssert) {
16301 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
16302 }
16303 ieee754.write(buf, value, offset, littleEndian, 23, 4)
16304 return offset + 4
16305 }
16306
16307 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
16308 return writeFloat(this, value, offset, true, noAssert)
16309 }
16310
16311 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
16312 return writeFloat(this, value, offset, false, noAssert)
16313 }
16314
16315 function writeDouble (buf, value, offset, littleEndian, noAssert) {
16316 value = +value
16317 offset = offset >>> 0
16318 if (!noAssert) {
16319 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
16320 }
16321 ieee754.write(buf, value, offset, littleEndian, 52, 8)
16322 return offset + 8
16323 }
16324
16325 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
16326 return writeDouble(this, value, offset, true, noAssert)
16327 }
16328
16329 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
16330 return writeDouble(this, value, offset, false, noAssert)
16331 }
16332
16333 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
16334 Buffer.prototype.copy = function copy (target, targetStart, start, end) {
16335 if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
16336 if (!start) start = 0
16337 if (!end && end !== 0) end = this.length
16338 if (targetStart >= target.length) targetStart = target.length
16339 if (!targetStart) targetStart = 0
16340 if (end > 0 && end < start) end = start
16341
16342 // Copy 0 bytes; we're done
16343 if (end === start) return 0
16344 if (target.length === 0 || this.length === 0) return 0
16345
16346 // Fatal error conditions
16347 if (targetStart < 0) {
16348 throw new RangeError('targetStart out of bounds')
16349 }
16350 if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
16351 if (end < 0) throw new RangeError('sourceEnd out of bounds')
16352
16353 // Are we oob?
16354 if (end > this.length) end = this.length
16355 if (target.length - targetStart < end - start) {
16356 end = target.length - targetStart + start
16357 }
16358
16359 var len = end - start
16360
16361 if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
16362 // Use built-in when available, missing from IE11
16363 this.copyWithin(targetStart, start, end)
16364 } else if (this === target && start < targetStart && targetStart < end) {
16365 // descending copy from end
16366 for (var i = len - 1; i >= 0; --i) {
16367 target[i + targetStart] = this[i + start]
16368 }
16369 } else {
16370 Uint8Array.prototype.set.call(
16371 target,
16372 this.subarray(start, end),
16373 targetStart
16374 )
16375 }
16376
16377 return len
16378 }
16379
16380 // Usage:
16381 // buffer.fill(number[, offset[, end]])
16382 // buffer.fill(buffer[, offset[, end]])
16383 // buffer.fill(string[, offset[, end]][, encoding])
16384 Buffer.prototype.fill = function fill (val, start, end, encoding) {
16385 // Handle string cases:
16386 if (typeof val === 'string') {
16387 if (typeof start === 'string') {
16388 encoding = start
16389 start = 0
16390 end = this.length
16391 } else if (typeof end === 'string') {
16392 encoding = end
16393 end = this.length
16394 }
16395 if (encoding !== undefined && typeof encoding !== 'string') {
16396 throw new TypeError('encoding must be a string')
16397 }
16398 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
16399 throw new TypeError('Unknown encoding: ' + encoding)
16400 }
16401 if (val.length === 1) {
16402 var code = val.charCodeAt(0)
16403 if ((encoding === 'utf8' && code < 128) ||
16404 encoding === 'latin1') {
16405 // Fast path: If `val` fits into a single byte, use that numeric value.
16406 val = code
16407 }
16408 }
16409 } else if (typeof val === 'number') {
16410 val = val & 255
16411 } else if (typeof val === 'boolean') {
16412 val = Number(val)
16413 }
16414
16415 // Invalid ranges are not set to a default, so can range check early.
16416 if (start < 0 || this.length < start || this.length < end) {
16417 throw new RangeError('Out of range index')
16418 }
16419
16420 if (end <= start) {
16421 return this
16422 }
16423
16424 start = start >>> 0
16425 end = end === undefined ? this.length : end >>> 0
16426
16427 if (!val) val = 0
16428
16429 var i
16430 if (typeof val === 'number') {
16431 for (i = start; i < end; ++i) {
16432 this[i] = val
16433 }
16434 } else {
16435 var bytes = Buffer.isBuffer(val)
16436 ? val
16437 : Buffer.from(val, encoding)
16438 var len = bytes.length
16439 if (len === 0) {
16440 throw new TypeError('The value "' + val +
16441 '" is invalid for argument "value"')
16442 }
16443 for (i = 0; i < end - start; ++i) {
16444 this[i + start] = bytes[i % len]
16445 }
16446 }
16447
16448 return this
16449 }
16450
16451 // HELPER FUNCTIONS
16452 // ================
16453
16454 var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
16455
16456 function base64clean (str) {
16457 // Node takes equal signs as end of the Base64 encoding
16458 str = str.split('=')[0]
16459 // Node strips out invalid characters like \n and \t from the string, base64-js does not
16460 str = str.trim().replace(INVALID_BASE64_RE, '')
16461 // Node converts strings with length < 2 to ''
16462 if (str.length < 2) return ''
16463 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
16464 while (str.length % 4 !== 0) {
16465 str = str + '='
16466 }
16467 return str
16468 }
16469
16470 function toHex (n) {
16471 if (n < 16) return '0' + n.toString(16)
16472 return n.toString(16)
16473 }
16474
16475 function utf8ToBytes (string, units) {
16476 units = units || Infinity
16477 var codePoint
16478 var length = string.length
16479 var leadSurrogate = null
16480 var bytes = []
16481
16482 for (var i = 0; i < length; ++i) {
16483 codePoint = string.charCodeAt(i)
16484
16485 // is surrogate component
16486 if (codePoint > 0xD7FF && codePoint < 0xE000) {
16487 // last char was a lead
16488 if (!leadSurrogate) {
16489 // no lead yet
16490 if (codePoint > 0xDBFF) {
16491 // unexpected trail
16492 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16493 continue
16494 } else if (i + 1 === length) {
16495 // unpaired lead
16496 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16497 continue
16498 }
16499
16500 // valid lead
16501 leadSurrogate = codePoint
16502
16503 continue
16504 }
16505
16506 // 2 leads in a row
16507 if (codePoint < 0xDC00) {
16508 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16509 leadSurrogate = codePoint
16510 continue
16511 }
16512
16513 // valid surrogate pair
16514 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
16515 } else if (leadSurrogate) {
16516 // valid bmp char, but last char was a lead
16517 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
16518 }
16519
16520 leadSurrogate = null
16521
16522 // encode utf8
16523 if (codePoint < 0x80) {
16524 if ((units -= 1) < 0) break
16525 bytes.push(codePoint)
16526 } else if (codePoint < 0x800) {
16527 if ((units -= 2) < 0) break
16528 bytes.push(
16529 codePoint >> 0x6 | 0xC0,
16530 codePoint & 0x3F | 0x80
16531 )
16532 } else if (codePoint < 0x10000) {
16533 if ((units -= 3) < 0) break
16534 bytes.push(
16535 codePoint >> 0xC | 0xE0,
16536 codePoint >> 0x6 & 0x3F | 0x80,
16537 codePoint & 0x3F | 0x80
16538 )
16539 } else if (codePoint < 0x110000) {
16540 if ((units -= 4) < 0) break
16541 bytes.push(
16542 codePoint >> 0x12 | 0xF0,
16543 codePoint >> 0xC & 0x3F | 0x80,
16544 codePoint >> 0x6 & 0x3F | 0x80,
16545 codePoint & 0x3F | 0x80
16546 )
16547 } else {
16548 throw new Error('Invalid code point')
16549 }
16550 }
16551
16552 return bytes
16553 }
16554
16555 function asciiToBytes (str) {
16556 var byteArray = []
16557 for (var i = 0; i < str.length; ++i) {
16558 // Node's code seems to be doing this and not & 0x7F..
16559 byteArray.push(str.charCodeAt(i) & 0xFF)
16560 }
16561 return byteArray
16562 }
16563
16564 function utf16leToBytes (str, units) {
16565 var c, hi, lo
16566 var byteArray = []
16567 for (var i = 0; i < str.length; ++i) {
16568 if ((units -= 2) < 0) break
16569
16570 c = str.charCodeAt(i)
16571 hi = c >> 8
16572 lo = c % 256
16573 byteArray.push(lo)
16574 byteArray.push(hi)
16575 }
16576
16577 return byteArray
16578 }
16579
16580 function base64ToBytes (str) {
16581 return base64.toByteArray(base64clean(str))
16582 }
16583
16584 function blitBuffer (src, dst, offset, length) {
16585 for (var i = 0; i < length; ++i) {
16586 if ((i + offset >= dst.length) || (i >= src.length)) break
16587 dst[i + offset] = src[i]
16588 }
16589 return i
16590 }
16591
16592 // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
16593 // the `instanceof` check but they should be treated as of that type.
16594 // See: https://github.com/feross/buffer/issues/166
16595 function isInstance (obj, type) {
16596 return obj instanceof type ||
16597 (obj != null && obj.constructor != null && obj.constructor.name != null &&
16598 obj.constructor.name === type.name)
16599 }
16600 function numberIsNaN (obj) {
16601 // For IE11 support
16602 return obj !== obj // eslint-disable-line no-self-compare
16603 }
16604
16605 }).call(this,require("buffer").Buffer)
16606 },{"base64-js":78,"buffer":110,"ieee754":161}],111:[function(require,module,exports){
16607 arguments[4][31][0].apply(exports,arguments)
16608 },{"dup":31,"inherits":162,"safe-buffer":206,"stream":215,"string_decoder":216}],112:[function(require,module,exports){
16609 (function (Buffer){
16610 // Copyright Joyent, Inc. and other Node contributors.
16611 //
16612 // Permission is hereby granted, free of charge, to any person obtaining a
16613 // copy of this software and associated documentation files (the
16614 // "Software"), to deal in the Software without restriction, including
16615 // without limitation the rights to use, copy, modify, merge, publish,
16616 // distribute, sublicense, and/or sell copies of the Software, and to permit
16617 // persons to whom the Software is furnished to do so, subject to the
16618 // following conditions:
16619 //
16620 // The above copyright notice and this permission notice shall be included
16621 // in all copies or substantial portions of the Software.
16622 //
16623 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16624 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16625 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
16626 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16627 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16628 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
16629 // USE OR OTHER DEALINGS IN THE SOFTWARE.
16630
16631 // NOTE: These type checking functions intentionally don't use `instanceof`
16632 // because it is fragile and can be easily faked with `Object.create()`.
16633
16634 function isArray(arg) {
16635 if (Array.isArray) {
16636 return Array.isArray(arg);
16637 }
16638 return objectToString(arg) === '[object Array]';
16639 }
16640 exports.isArray = isArray;
16641
16642 function isBoolean(arg) {
16643 return typeof arg === 'boolean';
16644 }
16645 exports.isBoolean = isBoolean;
16646
16647 function isNull(arg) {
16648 return arg === null;
16649 }
16650 exports.isNull = isNull;
16651
16652 function isNullOrUndefined(arg) {
16653 return arg == null;
16654 }
16655 exports.isNullOrUndefined = isNullOrUndefined;
16656
16657 function isNumber(arg) {
16658 return typeof arg === 'number';
16659 }
16660 exports.isNumber = isNumber;
16661
16662 function isString(arg) {
16663 return typeof arg === 'string';
16664 }
16665 exports.isString = isString;
16666
16667 function isSymbol(arg) {
16668 return typeof arg === 'symbol';
16669 }
16670 exports.isSymbol = isSymbol;
16671
16672 function isUndefined(arg) {
16673 return arg === void 0;
16674 }
16675 exports.isUndefined = isUndefined;
16676
16677 function isRegExp(re) {
16678 return objectToString(re) === '[object RegExp]';
16679 }
16680 exports.isRegExp = isRegExp;
16681
16682 function isObject(arg) {
16683 return typeof arg === 'object' && arg !== null;
16684 }
16685 exports.isObject = isObject;
16686
16687 function isDate(d) {
16688 return objectToString(d) === '[object Date]';
16689 }
16690 exports.isDate = isDate;
16691
16692 function isError(e) {
16693 return (objectToString(e) === '[object Error]' || e instanceof Error);
16694 }
16695 exports.isError = isError;
16696
16697 function isFunction(arg) {
16698 return typeof arg === 'function';
16699 }
16700 exports.isFunction = isFunction;
16701
16702 function isPrimitive(arg) {
16703 return arg === null ||
16704 typeof arg === 'boolean' ||
16705 typeof arg === 'number' ||
16706 typeof arg === 'string' ||
16707 typeof arg === 'symbol' || // ES6 symbol
16708 typeof arg === 'undefined';
16709 }
16710 exports.isPrimitive = isPrimitive;
16711
16712 exports.isBuffer = Buffer.isBuffer;
16713
16714 function objectToString(o) {
16715 return Object.prototype.toString.call(o);
16716 }
16717
16718 }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
16719 },{"../../is-buffer/index.js":163}],113:[function(require,module,exports){
16720 (function (Buffer){
16721 var elliptic = require('elliptic')
16722 var BN = require('bn.js')
16723
16724 module.exports = function createECDH (curve) {
16725 return new ECDH(curve)
16726 }
16727
16728 var aliases = {
16729 secp256k1: {
16730 name: 'secp256k1',
16731 byteLength: 32
16732 },
16733 secp224r1: {
16734 name: 'p224',
16735 byteLength: 28
16736 },
16737 prime256v1: {
16738 name: 'p256',
16739 byteLength: 32
16740 },
16741 prime192v1: {
16742 name: 'p192',
16743 byteLength: 24
16744 },
16745 ed25519: {
16746 name: 'ed25519',
16747 byteLength: 32
16748 },
16749 secp384r1: {
16750 name: 'p384',
16751 byteLength: 48
16752 },
16753 secp521r1: {
16754 name: 'p521',
16755 byteLength: 66
16756 }
16757 }
16758
16759 aliases.p224 = aliases.secp224r1
16760 aliases.p256 = aliases.secp256r1 = aliases.prime256v1
16761 aliases.p192 = aliases.secp192r1 = aliases.prime192v1
16762 aliases.p384 = aliases.secp384r1
16763 aliases.p521 = aliases.secp521r1
16764
16765 function ECDH (curve) {
16766 this.curveType = aliases[curve]
16767 if (!this.curveType) {
16768 this.curveType = {
16769 name: curve
16770 }
16771 }
16772 this.curve = new elliptic.ec(this.curveType.name) // eslint-disable-line new-cap
16773 this.keys = void 0
16774 }
16775
16776 ECDH.prototype.generateKeys = function (enc, format) {
16777 this.keys = this.curve.genKeyPair()
16778 return this.getPublicKey(enc, format)
16779 }
16780
16781 ECDH.prototype.computeSecret = function (other, inenc, enc) {
16782 inenc = inenc || 'utf8'
16783 if (!Buffer.isBuffer(other)) {
16784 other = new Buffer(other, inenc)
16785 }
16786 var otherPub = this.curve.keyFromPublic(other).getPublic()
16787 var out = otherPub.mul(this.keys.getPrivate()).getX()
16788 return formatReturnValue(out, enc, this.curveType.byteLength)
16789 }
16790
16791 ECDH.prototype.getPublicKey = function (enc, format) {
16792 var key = this.keys.getPublic(format === 'compressed', true)
16793 if (format === 'hybrid') {
16794 if (key[key.length - 1] % 2) {
16795 key[0] = 7
16796 } else {
16797 key[0] = 6
16798 }
16799 }
16800 return formatReturnValue(key, enc)
16801 }
16802
16803 ECDH.prototype.getPrivateKey = function (enc) {
16804 return formatReturnValue(this.keys.getPrivate(), enc)
16805 }
16806
16807 ECDH.prototype.setPublicKey = function (pub, enc) {
16808 enc = enc || 'utf8'
16809 if (!Buffer.isBuffer(pub)) {
16810 pub = new Buffer(pub, enc)
16811 }
16812 this.keys._importPublic(pub)
16813 return this
16814 }
16815
16816 ECDH.prototype.setPrivateKey = function (priv, enc) {
16817 enc = enc || 'utf8'
16818 if (!Buffer.isBuffer(priv)) {
16819 priv = new Buffer(priv, enc)
16820 }
16821
16822 var _priv = new BN(priv)
16823 _priv = _priv.toString(16)
16824 this.keys = this.curve.genKeyPair()
16825 this.keys._importPrivate(_priv)
16826 return this
16827 }
16828
16829 function formatReturnValue (bn, enc, len) {
16830 if (!Array.isArray(bn)) {
16831 bn = bn.toArray()
16832 }
16833 var buf = new Buffer(bn)
16834 if (len && buf.length < len) {
16835 var zeros = new Buffer(len - buf.length)
16836 zeros.fill(0)
16837 buf = Buffer.concat([zeros, buf])
16838 }
16839 if (!enc) {
16840 return buf
16841 } else {
16842 return buf.toString(enc)
16843 }
16844 }
16845
16846 }).call(this,require("buffer").Buffer)
16847 },{"bn.js":79,"buffer":110,"elliptic":129}],114:[function(require,module,exports){
16848 arguments[4][32][0].apply(exports,arguments)
16849 },{"cipher-base":111,"dup":32,"inherits":162,"md5.js":165,"ripemd160":205,"sha.js":208}],115:[function(require,module,exports){
16850 var MD5 = require('md5.js')
16851
16852 module.exports = function (buffer) {
16853 return new MD5().update(buffer).digest()
16854 }
16855
16856 },{"md5.js":165}],116:[function(require,module,exports){
16857 'use strict'
16858 var inherits = require('inherits')
16859 var Legacy = require('./legacy')
16860 var Base = require('cipher-base')
16861 var Buffer = require('safe-buffer').Buffer
16862 var md5 = require('create-hash/md5')
16863 var RIPEMD160 = require('ripemd160')
16864
16865 var sha = require('sha.js')
16866
16867 var ZEROS = Buffer.alloc(128)
16868
16869 function Hmac (alg, key) {
16870 Base.call(this, 'digest')
16871 if (typeof key === 'string') {
16872 key = Buffer.from(key)
16873 }
16874
16875 var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
16876
16877 this._alg = alg
16878 this._key = key
16879 if (key.length > blocksize) {
16880 var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
16881 key = hash.update(key).digest()
16882 } else if (key.length < blocksize) {
16883 key = Buffer.concat([key, ZEROS], blocksize)
16884 }
16885
16886 var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
16887 var opad = this._opad = Buffer.allocUnsafe(blocksize)
16888
16889 for (var i = 0; i < blocksize; i++) {
16890 ipad[i] = key[i] ^ 0x36
16891 opad[i] = key[i] ^ 0x5C
16892 }
16893 this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
16894 this._hash.update(ipad)
16895 }
16896
16897 inherits(Hmac, Base)
16898
16899 Hmac.prototype._update = function (data) {
16900 this._hash.update(data)
16901 }
16902
16903 Hmac.prototype._final = function () {
16904 var h = this._hash.digest()
16905 var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg)
16906 return hash.update(this._opad).update(h).digest()
16907 }
16908
16909 module.exports = function createHmac (alg, key) {
16910 alg = alg.toLowerCase()
16911 if (alg === 'rmd160' || alg === 'ripemd160') {
16912 return new Hmac('rmd160', key)
16913 }
16914 if (alg === 'md5') {
16915 return new Legacy(md5, key)
16916 }
16917 return new Hmac(alg, key)
16918 }
16919
16920 },{"./legacy":117,"cipher-base":111,"create-hash/md5":115,"inherits":162,"ripemd160":205,"safe-buffer":206,"sha.js":208}],117:[function(require,module,exports){
16921 'use strict'
16922 var inherits = require('inherits')
16923 var Buffer = require('safe-buffer').Buffer
16924
16925 var Base = require('cipher-base')
16926
16927 var ZEROS = Buffer.alloc(128)
16928 var blocksize = 64
16929
16930 function Hmac (alg, key) {
16931 Base.call(this, 'digest')
16932 if (typeof key === 'string') {
16933 key = Buffer.from(key)
16934 }
16935
16936 this._alg = alg
16937 this._key = key
16938
16939 if (key.length > blocksize) {
16940 key = alg(key)
16941 } else if (key.length < blocksize) {
16942 key = Buffer.concat([key, ZEROS], blocksize)
16943 }
16944
16945 var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
16946 var opad = this._opad = Buffer.allocUnsafe(blocksize)
16947
16948 for (var i = 0; i < blocksize; i++) {
16949 ipad[i] = key[i] ^ 0x36
16950 opad[i] = key[i] ^ 0x5C
16951 }
16952
16953 this._hash = [ipad]
16954 }
16955
16956 inherits(Hmac, Base)
16957
16958 Hmac.prototype._update = function (data) {
16959 this._hash.push(data)
16960 }
16961
16962 Hmac.prototype._final = function () {
16963 var h = this._alg(Buffer.concat(this._hash))
16964 return this._alg(Buffer.concat([this._opad, h]))
16965 }
16966 module.exports = Hmac
16967
16968 },{"cipher-base":111,"inherits":162,"safe-buffer":206}],118:[function(require,module,exports){
16969 'use strict'
16970
16971 exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
16972 exports.createHash = exports.Hash = require('create-hash')
16973 exports.createHmac = exports.Hmac = require('create-hmac')
16974
16975 var algos = require('browserify-sign/algos')
16976 var algoKeys = Object.keys(algos)
16977 var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys)
16978 exports.getHashes = function () {
16979 return hashes
16980 }
16981
16982 var p = require('pbkdf2')
16983 exports.pbkdf2 = p.pbkdf2
16984 exports.pbkdf2Sync = p.pbkdf2Sync
16985
16986 var aes = require('browserify-cipher')
16987
16988 exports.Cipher = aes.Cipher
16989 exports.createCipher = aes.createCipher
16990 exports.Cipheriv = aes.Cipheriv
16991 exports.createCipheriv = aes.createCipheriv
16992 exports.Decipher = aes.Decipher
16993 exports.createDecipher = aes.createDecipher
16994 exports.Decipheriv = aes.Decipheriv
16995 exports.createDecipheriv = aes.createDecipheriv
16996 exports.getCiphers = aes.getCiphers
16997 exports.listCiphers = aes.listCiphers
16998
16999 var dh = require('diffie-hellman')
17000
17001 exports.DiffieHellmanGroup = dh.DiffieHellmanGroup
17002 exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup
17003 exports.getDiffieHellman = dh.getDiffieHellman
17004 exports.createDiffieHellman = dh.createDiffieHellman
17005 exports.DiffieHellman = dh.DiffieHellman
17006
17007 var sign = require('browserify-sign')
17008
17009 exports.createSign = sign.createSign
17010 exports.Sign = sign.Sign
17011 exports.createVerify = sign.createVerify
17012 exports.Verify = sign.Verify
17013
17014 exports.createECDH = require('create-ecdh')
17015
17016 var publicEncrypt = require('public-encrypt')
17017
17018 exports.publicEncrypt = publicEncrypt.publicEncrypt
17019 exports.privateEncrypt = publicEncrypt.privateEncrypt
17020 exports.publicDecrypt = publicEncrypt.publicDecrypt
17021 exports.privateDecrypt = publicEncrypt.privateDecrypt
17022
17023 // the least I can do is make error messages for the rest of the node.js/crypto api.
17024 // ;[
17025 // 'createCredentials'
17026 // ].forEach(function (name) {
17027 // exports[name] = function () {
17028 // throw new Error([
17029 // 'sorry, ' + name + ' is not implemented yet',
17030 // 'we accept pull requests',
17031 // 'https://github.com/crypto-browserify/crypto-browserify'
17032 // ].join('\n'))
17033 // }
17034 // })
17035
17036 var rf = require('randomfill')
17037
17038 exports.randomFill = rf.randomFill
17039 exports.randomFillSync = rf.randomFillSync
17040
17041 exports.createCredentials = function () {
17042 throw new Error([
17043 'sorry, createCredentials is not implemented yet',
17044 'we accept pull requests',
17045 'https://github.com/crypto-browserify/crypto-browserify'
17046 ].join('\n'))
17047 }
17048
17049 exports.constants = {
17050 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
17051 'DH_CHECK_P_NOT_PRIME': 1,
17052 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
17053 'DH_NOT_SUITABLE_GENERATOR': 8,
17054 'NPN_ENABLED': 1,
17055 'ALPN_ENABLED': 1,
17056 'RSA_PKCS1_PADDING': 1,
17057 'RSA_SSLV23_PADDING': 2,
17058 'RSA_NO_PADDING': 3,
17059 'RSA_PKCS1_OAEP_PADDING': 4,
17060 'RSA_X931_PADDING': 5,
17061 'RSA_PKCS1_PSS_PADDING': 6,
17062 'POINT_CONVERSION_COMPRESSED': 2,
17063 'POINT_CONVERSION_UNCOMPRESSED': 4,
17064 'POINT_CONVERSION_HYBRID': 6
17065 }
17066
17067 },{"browserify-cipher":99,"browserify-sign":106,"browserify-sign/algos":103,"create-ecdh":113,"create-hash":114,"create-hmac":116,"diffie-hellman":125,"pbkdf2":175,"public-encrypt":182,"randombytes":188,"randomfill":189}],119:[function(require,module,exports){
17068 'use strict';
17069
17070 exports.utils = require('./des/utils');
17071 exports.Cipher = require('./des/cipher');
17072 exports.DES = require('./des/des');
17073 exports.CBC = require('./des/cbc');
17074 exports.EDE = require('./des/ede');
17075
17076 },{"./des/cbc":120,"./des/cipher":121,"./des/des":122,"./des/ede":123,"./des/utils":124}],120:[function(require,module,exports){
17077 'use strict';
17078
17079 var assert = require('minimalistic-assert');
17080 var inherits = require('inherits');
17081
17082 var proto = {};
17083
17084 function CBCState(iv) {
17085 assert.equal(iv.length, 8, 'Invalid IV length');
17086
17087 this.iv = new Array(8);
17088 for (var i = 0; i < this.iv.length; i++)
17089 this.iv[i] = iv[i];
17090 }
17091
17092 function instantiate(Base) {
17093 function CBC(options) {
17094 Base.call(this, options);
17095 this._cbcInit();
17096 }
17097 inherits(CBC, Base);
17098
17099 var keys = Object.keys(proto);
17100 for (var i = 0; i < keys.length; i++) {
17101 var key = keys[i];
17102 CBC.prototype[key] = proto[key];
17103 }
17104
17105 CBC.create = function create(options) {
17106 return new CBC(options);
17107 };
17108
17109 return CBC;
17110 }
17111
17112 exports.instantiate = instantiate;
17113
17114 proto._cbcInit = function _cbcInit() {
17115 var state = new CBCState(this.options.iv);
17116 this._cbcState = state;
17117 };
17118
17119 proto._update = function _update(inp, inOff, out, outOff) {
17120 var state = this._cbcState;
17121 var superProto = this.constructor.super_.prototype;
17122
17123 var iv = state.iv;
17124 if (this.type === 'encrypt') {
17125 for (var i = 0; i < this.blockSize; i++)
17126 iv[i] ^= inp[inOff + i];
17127
17128 superProto._update.call(this, iv, 0, out, outOff);
17129
17130 for (var i = 0; i < this.blockSize; i++)
17131 iv[i] = out[outOff + i];
17132 } else {
17133 superProto._update.call(this, inp, inOff, out, outOff);
17134
17135 for (var i = 0; i < this.blockSize; i++)
17136 out[outOff + i] ^= iv[i];
17137
17138 for (var i = 0; i < this.blockSize; i++)
17139 iv[i] = inp[inOff + i];
17140 }
17141 };
17142
17143 },{"inherits":162,"minimalistic-assert":167}],121:[function(require,module,exports){
17144 'use strict';
17145
17146 var assert = require('minimalistic-assert');
17147
17148 function Cipher(options) {
17149 this.options = options;
17150
17151 this.type = this.options.type;
17152 this.blockSize = 8;
17153 this._init();
17154
17155 this.buffer = new Array(this.blockSize);
17156 this.bufferOff = 0;
17157 }
17158 module.exports = Cipher;
17159
17160 Cipher.prototype._init = function _init() {
17161 // Might be overrided
17162 };
17163
17164 Cipher.prototype.update = function update(data) {
17165 if (data.length === 0)
17166 return [];
17167
17168 if (this.type === 'decrypt')
17169 return this._updateDecrypt(data);
17170 else
17171 return this._updateEncrypt(data);
17172 };
17173
17174 Cipher.prototype._buffer = function _buffer(data, off) {
17175 // Append data to buffer
17176 var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
17177 for (var i = 0; i < min; i++)
17178 this.buffer[this.bufferOff + i] = data[off + i];
17179 this.bufferOff += min;
17180
17181 // Shift next
17182 return min;
17183 };
17184
17185 Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
17186 this._update(this.buffer, 0, out, off);
17187 this.bufferOff = 0;
17188 return this.blockSize;
17189 };
17190
17191 Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
17192 var inputOff = 0;
17193 var outputOff = 0;
17194
17195 var count = ((this.bufferOff + data.length) / this.blockSize) | 0;
17196 var out = new Array(count * this.blockSize);
17197
17198 if (this.bufferOff !== 0) {
17199 inputOff += this._buffer(data, inputOff);
17200
17201 if (this.bufferOff === this.buffer.length)
17202 outputOff += this._flushBuffer(out, outputOff);
17203 }
17204
17205 // Write blocks
17206 var max = data.length - ((data.length - inputOff) % this.blockSize);
17207 for (; inputOff < max; inputOff += this.blockSize) {
17208 this._update(data, inputOff, out, outputOff);
17209 outputOff += this.blockSize;
17210 }
17211
17212 // Queue rest
17213 for (; inputOff < data.length; inputOff++, this.bufferOff++)
17214 this.buffer[this.bufferOff] = data[inputOff];
17215
17216 return out;
17217 };
17218
17219 Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
17220 var inputOff = 0;
17221 var outputOff = 0;
17222
17223 var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
17224 var out = new Array(count * this.blockSize);
17225
17226 // TODO(indutny): optimize it, this is far from optimal
17227 for (; count > 0; count--) {
17228 inputOff += this._buffer(data, inputOff);
17229 outputOff += this._flushBuffer(out, outputOff);
17230 }
17231
17232 // Buffer rest of the input
17233 inputOff += this._buffer(data, inputOff);
17234
17235 return out;
17236 };
17237
17238 Cipher.prototype.final = function final(buffer) {
17239 var first;
17240 if (buffer)
17241 first = this.update(buffer);
17242
17243 var last;
17244 if (this.type === 'encrypt')
17245 last = this._finalEncrypt();
17246 else
17247 last = this._finalDecrypt();
17248
17249 if (first)
17250 return first.concat(last);
17251 else
17252 return last;
17253 };
17254
17255 Cipher.prototype._pad = function _pad(buffer, off) {
17256 if (off === 0)
17257 return false;
17258
17259 while (off < buffer.length)
17260 buffer[off++] = 0;
17261
17262 return true;
17263 };
17264
17265 Cipher.prototype._finalEncrypt = function _finalEncrypt() {
17266 if (!this._pad(this.buffer, this.bufferOff))
17267 return [];
17268
17269 var out = new Array(this.blockSize);
17270 this._update(this.buffer, 0, out, 0);
17271 return out;
17272 };
17273
17274 Cipher.prototype._unpad = function _unpad(buffer) {
17275 return buffer;
17276 };
17277
17278 Cipher.prototype._finalDecrypt = function _finalDecrypt() {
17279 assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
17280 var out = new Array(this.blockSize);
17281 this._flushBuffer(out, 0);
17282
17283 return this._unpad(out);
17284 };
17285
17286 },{"minimalistic-assert":167}],122:[function(require,module,exports){
17287 'use strict';
17288
17289 var assert = require('minimalistic-assert');
17290 var inherits = require('inherits');
17291
17292 var des = require('../des');
17293 var utils = des.utils;
17294 var Cipher = des.Cipher;
17295
17296 function DESState() {
17297 this.tmp = new Array(2);
17298 this.keys = null;
17299 }
17300
17301 function DES(options) {
17302 Cipher.call(this, options);
17303
17304 var state = new DESState();
17305 this._desState = state;
17306
17307 this.deriveKeys(state, options.key);
17308 }
17309 inherits(DES, Cipher);
17310 module.exports = DES;
17311
17312 DES.create = function create(options) {
17313 return new DES(options);
17314 };
17315
17316 var shiftTable = [
17317 1, 1, 2, 2, 2, 2, 2, 2,
17318 1, 2, 2, 2, 2, 2, 2, 1
17319 ];
17320
17321 DES.prototype.deriveKeys = function deriveKeys(state, key) {
17322 state.keys = new Array(16 * 2);
17323
17324 assert.equal(key.length, this.blockSize, 'Invalid key length');
17325
17326 var kL = utils.readUInt32BE(key, 0);
17327 var kR = utils.readUInt32BE(key, 4);
17328
17329 utils.pc1(kL, kR, state.tmp, 0);
17330 kL = state.tmp[0];
17331 kR = state.tmp[1];
17332 for (var i = 0; i < state.keys.length; i += 2) {
17333 var shift = shiftTable[i >>> 1];
17334 kL = utils.r28shl(kL, shift);
17335 kR = utils.r28shl(kR, shift);
17336 utils.pc2(kL, kR, state.keys, i);
17337 }
17338 };
17339
17340 DES.prototype._update = function _update(inp, inOff, out, outOff) {
17341 var state = this._desState;
17342
17343 var l = utils.readUInt32BE(inp, inOff);
17344 var r = utils.readUInt32BE(inp, inOff + 4);
17345
17346 // Initial Permutation
17347 utils.ip(l, r, state.tmp, 0);
17348 l = state.tmp[0];
17349 r = state.tmp[1];
17350
17351 if (this.type === 'encrypt')
17352 this._encrypt(state, l, r, state.tmp, 0);
17353 else
17354 this._decrypt(state, l, r, state.tmp, 0);
17355
17356 l = state.tmp[0];
17357 r = state.tmp[1];
17358
17359 utils.writeUInt32BE(out, l, outOff);
17360 utils.writeUInt32BE(out, r, outOff + 4);
17361 };
17362
17363 DES.prototype._pad = function _pad(buffer, off) {
17364 var value = buffer.length - off;
17365 for (var i = off; i < buffer.length; i++)
17366 buffer[i] = value;
17367
17368 return true;
17369 };
17370
17371 DES.prototype._unpad = function _unpad(buffer) {
17372 var pad = buffer[buffer.length - 1];
17373 for (var i = buffer.length - pad; i < buffer.length; i++)
17374 assert.equal(buffer[i], pad);
17375
17376 return buffer.slice(0, buffer.length - pad);
17377 };
17378
17379 DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
17380 var l = lStart;
17381 var r = rStart;
17382
17383 // Apply f() x16 times
17384 for (var i = 0; i < state.keys.length; i += 2) {
17385 var keyL = state.keys[i];
17386 var keyR = state.keys[i + 1];
17387
17388 // f(r, k)
17389 utils.expand(r, state.tmp, 0);
17390
17391 keyL ^= state.tmp[0];
17392 keyR ^= state.tmp[1];
17393 var s = utils.substitute(keyL, keyR);
17394 var f = utils.permute(s);
17395
17396 var t = r;
17397 r = (l ^ f) >>> 0;
17398 l = t;
17399 }
17400
17401 // Reverse Initial Permutation
17402 utils.rip(r, l, out, off);
17403 };
17404
17405 DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
17406 var l = rStart;
17407 var r = lStart;
17408
17409 // Apply f() x16 times
17410 for (var i = state.keys.length - 2; i >= 0; i -= 2) {
17411 var keyL = state.keys[i];
17412 var keyR = state.keys[i + 1];
17413
17414 // f(r, k)
17415 utils.expand(l, state.tmp, 0);
17416
17417 keyL ^= state.tmp[0];
17418 keyR ^= state.tmp[1];
17419 var s = utils.substitute(keyL, keyR);
17420 var f = utils.permute(s);
17421
17422 var t = l;
17423 l = (r ^ f) >>> 0;
17424 r = t;
17425 }
17426
17427 // Reverse Initial Permutation
17428 utils.rip(l, r, out, off);
17429 };
17430
17431 },{"../des":119,"inherits":162,"minimalistic-assert":167}],123:[function(require,module,exports){
17432 'use strict';
17433
17434 var assert = require('minimalistic-assert');
17435 var inherits = require('inherits');
17436
17437 var des = require('../des');
17438 var Cipher = des.Cipher;
17439 var DES = des.DES;
17440
17441 function EDEState(type, key) {
17442 assert.equal(key.length, 24, 'Invalid key length');
17443
17444 var k1 = key.slice(0, 8);
17445 var k2 = key.slice(8, 16);
17446 var k3 = key.slice(16, 24);
17447
17448 if (type === 'encrypt') {
17449 this.ciphers = [
17450 DES.create({ type: 'encrypt', key: k1 }),
17451 DES.create({ type: 'decrypt', key: k2 }),
17452 DES.create({ type: 'encrypt', key: k3 })
17453 ];
17454 } else {
17455 this.ciphers = [
17456 DES.create({ type: 'decrypt', key: k3 }),
17457 DES.create({ type: 'encrypt', key: k2 }),
17458 DES.create({ type: 'decrypt', key: k1 })
17459 ];
17460 }
17461 }
17462
17463 function EDE(options) {
17464 Cipher.call(this, options);
17465
17466 var state = new EDEState(this.type, this.options.key);
17467 this._edeState = state;
17468 }
17469 inherits(EDE, Cipher);
17470
17471 module.exports = EDE;
17472
17473 EDE.create = function create(options) {
17474 return new EDE(options);
17475 };
17476
17477 EDE.prototype._update = function _update(inp, inOff, out, outOff) {
17478 var state = this._edeState;
17479
17480 state.ciphers[0]._update(inp, inOff, out, outOff);
17481 state.ciphers[1]._update(out, outOff, out, outOff);
17482 state.ciphers[2]._update(out, outOff, out, outOff);
17483 };
17484
17485 EDE.prototype._pad = DES.prototype._pad;
17486 EDE.prototype._unpad = DES.prototype._unpad;
17487
17488 },{"../des":119,"inherits":162,"minimalistic-assert":167}],124:[function(require,module,exports){
17489 'use strict';
17490
17491 exports.readUInt32BE = function readUInt32BE(bytes, off) {
17492 var res = (bytes[0 + off] << 24) |
17493 (bytes[1 + off] << 16) |
17494 (bytes[2 + off] << 8) |
17495 bytes[3 + off];
17496 return res >>> 0;
17497 };
17498
17499 exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
17500 bytes[0 + off] = value >>> 24;
17501 bytes[1 + off] = (value >>> 16) & 0xff;
17502 bytes[2 + off] = (value >>> 8) & 0xff;
17503 bytes[3 + off] = value & 0xff;
17504 };
17505
17506 exports.ip = function ip(inL, inR, out, off) {
17507 var outL = 0;
17508 var outR = 0;
17509
17510 for (var i = 6; i >= 0; i -= 2) {
17511 for (var j = 0; j <= 24; j += 8) {
17512 outL <<= 1;
17513 outL |= (inR >>> (j + i)) & 1;
17514 }
17515 for (var j = 0; j <= 24; j += 8) {
17516 outL <<= 1;
17517 outL |= (inL >>> (j + i)) & 1;
17518 }
17519 }
17520
17521 for (var i = 6; i >= 0; i -= 2) {
17522 for (var j = 1; j <= 25; j += 8) {
17523 outR <<= 1;
17524 outR |= (inR >>> (j + i)) & 1;
17525 }
17526 for (var j = 1; j <= 25; j += 8) {
17527 outR <<= 1;
17528 outR |= (inL >>> (j + i)) & 1;
17529 }
17530 }
17531
17532 out[off + 0] = outL >>> 0;
17533 out[off + 1] = outR >>> 0;
17534 };
17535
17536 exports.rip = function rip(inL, inR, out, off) {
17537 var outL = 0;
17538 var outR = 0;
17539
17540 for (var i = 0; i < 4; i++) {
17541 for (var j = 24; j >= 0; j -= 8) {
17542 outL <<= 1;
17543 outL |= (inR >>> (j + i)) & 1;
17544 outL <<= 1;
17545 outL |= (inL >>> (j + i)) & 1;
17546 }
17547 }
17548 for (var i = 4; i < 8; i++) {
17549 for (var j = 24; j >= 0; j -= 8) {
17550 outR <<= 1;
17551 outR |= (inR >>> (j + i)) & 1;
17552 outR <<= 1;
17553 outR |= (inL >>> (j + i)) & 1;
17554 }
17555 }
17556
17557 out[off + 0] = outL >>> 0;
17558 out[off + 1] = outR >>> 0;
17559 };
17560
17561 exports.pc1 = function pc1(inL, inR, out, off) {
17562 var outL = 0;
17563 var outR = 0;
17564
17565 // 7, 15, 23, 31, 39, 47, 55, 63
17566 // 6, 14, 22, 30, 39, 47, 55, 63
17567 // 5, 13, 21, 29, 39, 47, 55, 63
17568 // 4, 12, 20, 28
17569 for (var i = 7; i >= 5; i--) {
17570 for (var j = 0; j <= 24; j += 8) {
17571 outL <<= 1;
17572 outL |= (inR >> (j + i)) & 1;
17573 }
17574 for (var j = 0; j <= 24; j += 8) {
17575 outL <<= 1;
17576 outL |= (inL >> (j + i)) & 1;
17577 }
17578 }
17579 for (var j = 0; j <= 24; j += 8) {
17580 outL <<= 1;
17581 outL |= (inR >> (j + i)) & 1;
17582 }
17583
17584 // 1, 9, 17, 25, 33, 41, 49, 57
17585 // 2, 10, 18, 26, 34, 42, 50, 58
17586 // 3, 11, 19, 27, 35, 43, 51, 59
17587 // 36, 44, 52, 60
17588 for (var i = 1; i <= 3; i++) {
17589 for (var j = 0; j <= 24; j += 8) {
17590 outR <<= 1;
17591 outR |= (inR >> (j + i)) & 1;
17592 }
17593 for (var j = 0; j <= 24; j += 8) {
17594 outR <<= 1;
17595 outR |= (inL >> (j + i)) & 1;
17596 }
17597 }
17598 for (var j = 0; j <= 24; j += 8) {
17599 outR <<= 1;
17600 outR |= (inL >> (j + i)) & 1;
17601 }
17602
17603 out[off + 0] = outL >>> 0;
17604 out[off + 1] = outR >>> 0;
17605 };
17606
17607 exports.r28shl = function r28shl(num, shift) {
17608 return ((num << shift) & 0xfffffff) | (num >>> (28 - shift));
17609 };
17610
17611 var pc2table = [
17612 // inL => outL
17613 14, 11, 17, 4, 27, 23, 25, 0,
17614 13, 22, 7, 18, 5, 9, 16, 24,
17615 2, 20, 12, 21, 1, 8, 15, 26,
17616
17617 // inR => outR
17618 15, 4, 25, 19, 9, 1, 26, 16,
17619 5, 11, 23, 8, 12, 7, 17, 0,
17620 22, 3, 10, 14, 6, 20, 27, 24
17621 ];
17622
17623 exports.pc2 = function pc2(inL, inR, out, off) {
17624 var outL = 0;
17625 var outR = 0;
17626
17627 var len = pc2table.length >>> 1;
17628 for (var i = 0; i < len; i++) {
17629 outL <<= 1;
17630 outL |= (inL >>> pc2table[i]) & 0x1;
17631 }
17632 for (var i = len; i < pc2table.length; i++) {
17633 outR <<= 1;
17634 outR |= (inR >>> pc2table[i]) & 0x1;
17635 }
17636
17637 out[off + 0] = outL >>> 0;
17638 out[off + 1] = outR >>> 0;
17639 };
17640
17641 exports.expand = function expand(r, out, off) {
17642 var outL = 0;
17643 var outR = 0;
17644
17645 outL = ((r & 1) << 5) | (r >>> 27);
17646 for (var i = 23; i >= 15; i -= 4) {
17647 outL <<= 6;
17648 outL |= (r >>> i) & 0x3f;
17649 }
17650 for (var i = 11; i >= 3; i -= 4) {
17651 outR |= (r >>> i) & 0x3f;
17652 outR <<= 6;
17653 }
17654 outR |= ((r & 0x1f) << 1) | (r >>> 31);
17655
17656 out[off + 0] = outL >>> 0;
17657 out[off + 1] = outR >>> 0;
17658 };
17659
17660 var sTable = [
17661 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1,
17662 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8,
17663 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7,
17664 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13,
17665
17666 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14,
17667 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5,
17668 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2,
17669 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9,
17670
17671 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10,
17672 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1,
17673 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7,
17674 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12,
17675
17676 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3,
17677 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9,
17678 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8,
17679 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14,
17680
17681 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1,
17682 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6,
17683 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13,
17684 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3,
17685
17686 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5,
17687 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8,
17688 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10,
17689 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13,
17690
17691 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10,
17692 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6,
17693 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7,
17694 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12,
17695
17696 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4,
17697 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2,
17698 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13,
17699 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11
17700 ];
17701
17702 exports.substitute = function substitute(inL, inR) {
17703 var out = 0;
17704 for (var i = 0; i < 4; i++) {
17705 var b = (inL >>> (18 - i * 6)) & 0x3f;
17706 var sb = sTable[i * 0x40 + b];
17707
17708 out <<= 4;
17709 out |= sb;
17710 }
17711 for (var i = 0; i < 4; i++) {
17712 var b = (inR >>> (18 - i * 6)) & 0x3f;
17713 var sb = sTable[4 * 0x40 + i * 0x40 + b];
17714
17715 out <<= 4;
17716 out |= sb;
17717 }
17718 return out >>> 0;
17719 };
17720
17721 var permuteTable = [
17722 16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22,
17723 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7
17724 ];
17725
17726 exports.permute = function permute(num) {
17727 var out = 0;
17728 for (var i = 0; i < permuteTable.length; i++) {
17729 out <<= 1;
17730 out |= (num >>> permuteTable[i]) & 0x1;
17731 }
17732 return out >>> 0;
17733 };
17734
17735 exports.padSplit = function padSplit(num, size, group) {
17736 var str = num.toString(2);
17737 while (str.length < size)
17738 str = '0' + str;
17739
17740 var out = [];
17741 for (var i = 0; i < size; i += group)
17742 out.push(str.slice(i, i + group));
17743 return out.join(' ');
17744 };
17745
17746 },{}],125:[function(require,module,exports){
17747 (function (Buffer){
17748 var generatePrime = require('./lib/generatePrime')
17749 var primes = require('./lib/primes.json')
17750
17751 var DH = require('./lib/dh')
17752
17753 function getDiffieHellman (mod) {
17754 var prime = new Buffer(primes[mod].prime, 'hex')
17755 var gen = new Buffer(primes[mod].gen, 'hex')
17756
17757 return new DH(prime, gen)
17758 }
17759
17760 var ENCODINGS = {
17761 'binary': true, 'hex': true, 'base64': true
17762 }
17763
17764 function createDiffieHellman (prime, enc, generator, genc) {
17765 if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
17766 return createDiffieHellman(prime, 'binary', enc, generator)
17767 }
17768
17769 enc = enc || 'binary'
17770 genc = genc || 'binary'
17771 generator = generator || new Buffer([2])
17772
17773 if (!Buffer.isBuffer(generator)) {
17774 generator = new Buffer(generator, genc)
17775 }
17776
17777 if (typeof prime === 'number') {
17778 return new DH(generatePrime(prime, generator), generator, true)
17779 }
17780
17781 if (!Buffer.isBuffer(prime)) {
17782 prime = new Buffer(prime, enc)
17783 }
17784
17785 return new DH(prime, generator, true)
17786 }
17787
17788 exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
17789 exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman
17790
17791 }).call(this,require("buffer").Buffer)
17792 },{"./lib/dh":126,"./lib/generatePrime":127,"./lib/primes.json":128,"buffer":110}],126:[function(require,module,exports){
17793 (function (Buffer){
17794 var BN = require('bn.js');
17795 var MillerRabin = require('miller-rabin');
17796 var millerRabin = new MillerRabin();
17797 var TWENTYFOUR = new BN(24);
17798 var ELEVEN = new BN(11);
17799 var TEN = new BN(10);
17800 var THREE = new BN(3);
17801 var SEVEN = new BN(7);
17802 var primes = require('./generatePrime');
17803 var randomBytes = require('randombytes');
17804 module.exports = DH;
17805
17806 function setPublicKey(pub, enc) {
17807 enc = enc || 'utf8';
17808 if (!Buffer.isBuffer(pub)) {
17809 pub = new Buffer(pub, enc);
17810 }
17811 this._pub = new BN(pub);
17812 return this;
17813 }
17814
17815 function setPrivateKey(priv, enc) {
17816 enc = enc || 'utf8';
17817 if (!Buffer.isBuffer(priv)) {
17818 priv = new Buffer(priv, enc);
17819 }
17820 this._priv = new BN(priv);
17821 return this;
17822 }
17823
17824 var primeCache = {};
17825 function checkPrime(prime, generator) {
17826 var gen = generator.toString('hex');
17827 var hex = [gen, prime.toString(16)].join('_');
17828 if (hex in primeCache) {
17829 return primeCache[hex];
17830 }
17831 var error = 0;
17832
17833 if (prime.isEven() ||
17834 !primes.simpleSieve ||
17835 !primes.fermatTest(prime) ||
17836 !millerRabin.test(prime)) {
17837 //not a prime so +1
17838 error += 1;
17839
17840 if (gen === '02' || gen === '05') {
17841 // we'd be able to check the generator
17842 // it would fail so +8
17843 error += 8;
17844 } else {
17845 //we wouldn't be able to test the generator
17846 // so +4
17847 error += 4;
17848 }
17849 primeCache[hex] = error;
17850 return error;
17851 }
17852 if (!millerRabin.test(prime.shrn(1))) {
17853 //not a safe prime
17854 error += 2;
17855 }
17856 var rem;
17857 switch (gen) {
17858 case '02':
17859 if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
17860 // unsuidable generator
17861 error += 8;
17862 }
17863 break;
17864 case '05':
17865 rem = prime.mod(TEN);
17866 if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
17867 // prime mod 10 needs to equal 3 or 7
17868 error += 8;
17869 }
17870 break;
17871 default:
17872 error += 4;
17873 }
17874 primeCache[hex] = error;
17875 return error;
17876 }
17877
17878 function DH(prime, generator, malleable) {
17879 this.setGenerator(generator);
17880 this.__prime = new BN(prime);
17881 this._prime = BN.mont(this.__prime);
17882 this._primeLen = prime.length;
17883 this._pub = undefined;
17884 this._priv = undefined;
17885 this._primeCode = undefined;
17886 if (malleable) {
17887 this.setPublicKey = setPublicKey;
17888 this.setPrivateKey = setPrivateKey;
17889 } else {
17890 this._primeCode = 8;
17891 }
17892 }
17893 Object.defineProperty(DH.prototype, 'verifyError', {
17894 enumerable: true,
17895 get: function () {
17896 if (typeof this._primeCode !== 'number') {
17897 this._primeCode = checkPrime(this.__prime, this.__gen);
17898 }
17899 return this._primeCode;
17900 }
17901 });
17902 DH.prototype.generateKeys = function () {
17903 if (!this._priv) {
17904 this._priv = new BN(randomBytes(this._primeLen));
17905 }
17906 this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
17907 return this.getPublicKey();
17908 };
17909
17910 DH.prototype.computeSecret = function (other) {
17911 other = new BN(other);
17912 other = other.toRed(this._prime);
17913 var secret = other.redPow(this._priv).fromRed();
17914 var out = new Buffer(secret.toArray());
17915 var prime = this.getPrime();
17916 if (out.length < prime.length) {
17917 var front = new Buffer(prime.length - out.length);
17918 front.fill(0);
17919 out = Buffer.concat([front, out]);
17920 }
17921 return out;
17922 };
17923
17924 DH.prototype.getPublicKey = function getPublicKey(enc) {
17925 return formatReturnValue(this._pub, enc);
17926 };
17927
17928 DH.prototype.getPrivateKey = function getPrivateKey(enc) {
17929 return formatReturnValue(this._priv, enc);
17930 };
17931
17932 DH.prototype.getPrime = function (enc) {
17933 return formatReturnValue(this.__prime, enc);
17934 };
17935
17936 DH.prototype.getGenerator = function (enc) {
17937 return formatReturnValue(this._gen, enc);
17938 };
17939
17940 DH.prototype.setGenerator = function (gen, enc) {
17941 enc = enc || 'utf8';
17942 if (!Buffer.isBuffer(gen)) {
17943 gen = new Buffer(gen, enc);
17944 }
17945 this.__gen = gen;
17946 this._gen = new BN(gen);
17947 return this;
17948 };
17949
17950 function formatReturnValue(bn, enc) {
17951 var buf = new Buffer(bn.toArray());
17952 if (!enc) {
17953 return buf;
17954 } else {
17955 return buf.toString(enc);
17956 }
17957 }
17958
17959 }).call(this,require("buffer").Buffer)
17960 },{"./generatePrime":127,"bn.js":79,"buffer":110,"miller-rabin":166,"randombytes":188}],127:[function(require,module,exports){
17961 var randomBytes = require('randombytes');
17962 module.exports = findPrime;
17963 findPrime.simpleSieve = simpleSieve;
17964 findPrime.fermatTest = fermatTest;
17965 var BN = require('bn.js');
17966 var TWENTYFOUR = new BN(24);
17967 var MillerRabin = require('miller-rabin');
17968 var millerRabin = new MillerRabin();
17969 var ONE = new BN(1);
17970 var TWO = new BN(2);
17971 var FIVE = new BN(5);
17972 var SIXTEEN = new BN(16);
17973 var EIGHT = new BN(8);
17974 var TEN = new BN(10);
17975 var THREE = new BN(3);
17976 var SEVEN = new BN(7);
17977 var ELEVEN = new BN(11);
17978 var FOUR = new BN(4);
17979 var TWELVE = new BN(12);
17980 var primes = null;
17981
17982 function _getPrimes() {
17983 if (primes !== null)
17984 return primes;
17985
17986 var limit = 0x100000;
17987 var res = [];
17988 res[0] = 2;
17989 for (var i = 1, k = 3; k < limit; k += 2) {
17990 var sqrt = Math.ceil(Math.sqrt(k));
17991 for (var j = 0; j < i && res[j] <= sqrt; j++)
17992 if (k % res[j] === 0)
17993 break;
17994
17995 if (i !== j && res[j] <= sqrt)
17996 continue;
17997
17998 res[i++] = k;
17999 }
18000 primes = res;
18001 return res;
18002 }
18003
18004 function simpleSieve(p) {
18005 var primes = _getPrimes();
18006
18007 for (var i = 0; i < primes.length; i++)
18008 if (p.modn(primes[i]) === 0) {
18009 if (p.cmpn(primes[i]) === 0) {
18010 return true;
18011 } else {
18012 return false;
18013 }
18014 }
18015
18016 return true;
18017 }
18018
18019 function fermatTest(p) {
18020 var red = BN.mont(p);
18021 return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
18022 }
18023
18024 function findPrime(bits, gen) {
18025 if (bits < 16) {
18026 // this is what openssl does
18027 if (gen === 2 || gen === 5) {
18028 return new BN([0x8c, 0x7b]);
18029 } else {
18030 return new BN([0x8c, 0x27]);
18031 }
18032 }
18033 gen = new BN(gen);
18034
18035 var num, n2;
18036
18037 while (true) {
18038 num = new BN(randomBytes(Math.ceil(bits / 8)));
18039 while (num.bitLength() > bits) {
18040 num.ishrn(1);
18041 }
18042 if (num.isEven()) {
18043 num.iadd(ONE);
18044 }
18045 if (!num.testn(1)) {
18046 num.iadd(TWO);
18047 }
18048 if (!gen.cmp(TWO)) {
18049 while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
18050 num.iadd(FOUR);
18051 }
18052 } else if (!gen.cmp(FIVE)) {
18053 while (num.mod(TEN).cmp(THREE)) {
18054 num.iadd(FOUR);
18055 }
18056 }
18057 n2 = num.shrn(1);
18058 if (simpleSieve(n2) && simpleSieve(num) &&
18059 fermatTest(n2) && fermatTest(num) &&
18060 millerRabin.test(n2) && millerRabin.test(num)) {
18061 return num;
18062 }
18063 }
18064
18065 }
18066
18067 },{"bn.js":79,"miller-rabin":166,"randombytes":188}],128:[function(require,module,exports){
18068 module.exports={
18069 "modp1": {
18070 "gen": "02",
18071 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
18072 },
18073 "modp2": {
18074 "gen": "02",
18075 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
18076 },
18077 "modp5": {
18078 "gen": "02",
18079 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
18080 },
18081 "modp14": {
18082 "gen": "02",
18083 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
18084 },
18085 "modp15": {
18086 "gen": "02",
18087 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
18088 },
18089 "modp16": {
18090 "gen": "02",
18091 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
18092 },
18093 "modp17": {
18094 "gen": "02",
18095 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
18096 },
18097 "modp18": {
18098 "gen": "02",
18099 "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
18100 }
18101 }
18102 },{}],129:[function(require,module,exports){
18103 'use strict';
18104
18105 var elliptic = exports;
18106
18107 elliptic.version = require('../package.json').version;
18108 elliptic.utils = require('./elliptic/utils');
18109 elliptic.rand = require('brorand');
18110 elliptic.curve = require('./elliptic/curve');
18111 elliptic.curves = require('./elliptic/curves');
18112
18113 // Protocols
18114 elliptic.ec = require('./elliptic/ec');
18115 elliptic.eddsa = require('./elliptic/eddsa');
18116
18117 },{"../package.json":144,"./elliptic/curve":132,"./elliptic/curves":135,"./elliptic/ec":136,"./elliptic/eddsa":139,"./elliptic/utils":143,"brorand":80}],130:[function(require,module,exports){
18118 'use strict';
18119
18120 var BN = require('bn.js');
18121 var utils = require('../utils');
18122 var getNAF = utils.getNAF;
18123 var getJSF = utils.getJSF;
18124 var assert = utils.assert;
18125
18126 function BaseCurve(type, conf) {
18127 this.type = type;
18128 this.p = new BN(conf.p, 16);
18129
18130 // Use Montgomery, when there is no fast reduction for the prime
18131 this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
18132
18133 // Useful for many curves
18134 this.zero = new BN(0).toRed(this.red);
18135 this.one = new BN(1).toRed(this.red);
18136 this.two = new BN(2).toRed(this.red);
18137
18138 // Curve configuration, optional
18139 this.n = conf.n && new BN(conf.n, 16);
18140 this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
18141
18142 // Temporary arrays
18143 this._wnafT1 = new Array(4);
18144 this._wnafT2 = new Array(4);
18145 this._wnafT3 = new Array(4);
18146 this._wnafT4 = new Array(4);
18147
18148 // Generalized Greg Maxwell's trick
18149 var adjustCount = this.n && this.p.div(this.n);
18150 if (!adjustCount || adjustCount.cmpn(100) > 0) {
18151 this.redN = null;
18152 } else {
18153 this._maxwellTrick = true;
18154 this.redN = this.n.toRed(this.red);
18155 }
18156 }
18157 module.exports = BaseCurve;
18158
18159 BaseCurve.prototype.point = function point() {
18160 throw new Error('Not implemented');
18161 };
18162
18163 BaseCurve.prototype.validate = function validate() {
18164 throw new Error('Not implemented');
18165 };
18166
18167 BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
18168 assert(p.precomputed);
18169 var doubles = p._getDoubles();
18170
18171 var naf = getNAF(k, 1);
18172 var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
18173 I /= 3;
18174
18175 // Translate into more windowed form
18176 var repr = [];
18177 for (var j = 0; j < naf.length; j += doubles.step) {
18178 var nafW = 0;
18179 for (var k = j + doubles.step - 1; k >= j; k--)
18180 nafW = (nafW << 1) + naf[k];
18181 repr.push(nafW);
18182 }
18183
18184 var a = this.jpoint(null, null, null);
18185 var b = this.jpoint(null, null, null);
18186 for (var i = I; i > 0; i--) {
18187 for (var j = 0; j < repr.length; j++) {
18188 var nafW = repr[j];
18189 if (nafW === i)
18190 b = b.mixedAdd(doubles.points[j]);
18191 else if (nafW === -i)
18192 b = b.mixedAdd(doubles.points[j].neg());
18193 }
18194 a = a.add(b);
18195 }
18196 return a.toP();
18197 };
18198
18199 BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
18200 var w = 4;
18201
18202 // Precompute window
18203 var nafPoints = p._getNAFPoints(w);
18204 w = nafPoints.wnd;
18205 var wnd = nafPoints.points;
18206
18207 // Get NAF form
18208 var naf = getNAF(k, w);
18209
18210 // Add `this`*(N+1) for every w-NAF index
18211 var acc = this.jpoint(null, null, null);
18212 for (var i = naf.length - 1; i >= 0; i--) {
18213 // Count zeroes
18214 for (var k = 0; i >= 0 && naf[i] === 0; i--)
18215 k++;
18216 if (i >= 0)
18217 k++;
18218 acc = acc.dblp(k);
18219
18220 if (i < 0)
18221 break;
18222 var z = naf[i];
18223 assert(z !== 0);
18224 if (p.type === 'affine') {
18225 // J +- P
18226 if (z > 0)
18227 acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
18228 else
18229 acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
18230 } else {
18231 // J +- J
18232 if (z > 0)
18233 acc = acc.add(wnd[(z - 1) >> 1]);
18234 else
18235 acc = acc.add(wnd[(-z - 1) >> 1].neg());
18236 }
18237 }
18238 return p.type === 'affine' ? acc.toP() : acc;
18239 };
18240
18241 BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
18242 points,
18243 coeffs,
18244 len,
18245 jacobianResult) {
18246 var wndWidth = this._wnafT1;
18247 var wnd = this._wnafT2;
18248 var naf = this._wnafT3;
18249
18250 // Fill all arrays
18251 var max = 0;
18252 for (var i = 0; i < len; i++) {
18253 var p = points[i];
18254 var nafPoints = p._getNAFPoints(defW);
18255 wndWidth[i] = nafPoints.wnd;
18256 wnd[i] = nafPoints.points;
18257 }
18258
18259 // Comb small window NAFs
18260 for (var i = len - 1; i >= 1; i -= 2) {
18261 var a = i - 1;
18262 var b = i;
18263 if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
18264 naf[a] = getNAF(coeffs[a], wndWidth[a]);
18265 naf[b] = getNAF(coeffs[b], wndWidth[b]);
18266 max = Math.max(naf[a].length, max);
18267 max = Math.max(naf[b].length, max);
18268 continue;
18269 }
18270
18271 var comb = [
18272 points[a], /* 1 */
18273 null, /* 3 */
18274 null, /* 5 */
18275 points[b] /* 7 */
18276 ];
18277
18278 // Try to avoid Projective points, if possible
18279 if (points[a].y.cmp(points[b].y) === 0) {
18280 comb[1] = points[a].add(points[b]);
18281 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
18282 } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
18283 comb[1] = points[a].toJ().mixedAdd(points[b]);
18284 comb[2] = points[a].add(points[b].neg());
18285 } else {
18286 comb[1] = points[a].toJ().mixedAdd(points[b]);
18287 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
18288 }
18289
18290 var index = [
18291 -3, /* -1 -1 */
18292 -1, /* -1 0 */
18293 -5, /* -1 1 */
18294 -7, /* 0 -1 */
18295 0, /* 0 0 */
18296 7, /* 0 1 */
18297 5, /* 1 -1 */
18298 1, /* 1 0 */
18299 3 /* 1 1 */
18300 ];
18301
18302 var jsf = getJSF(coeffs[a], coeffs[b]);
18303 max = Math.max(jsf[0].length, max);
18304 naf[a] = new Array(max);
18305 naf[b] = new Array(max);
18306 for (var j = 0; j < max; j++) {
18307 var ja = jsf[0][j] | 0;
18308 var jb = jsf[1][j] | 0;
18309
18310 naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
18311 naf[b][j] = 0;
18312 wnd[a] = comb;
18313 }
18314 }
18315
18316 var acc = this.jpoint(null, null, null);
18317 var tmp = this._wnafT4;
18318 for (var i = max; i >= 0; i--) {
18319 var k = 0;
18320
18321 while (i >= 0) {
18322 var zero = true;
18323 for (var j = 0; j < len; j++) {
18324 tmp[j] = naf[j][i] | 0;
18325 if (tmp[j] !== 0)
18326 zero = false;
18327 }
18328 if (!zero)
18329 break;
18330 k++;
18331 i--;
18332 }
18333 if (i >= 0)
18334 k++;
18335 acc = acc.dblp(k);
18336 if (i < 0)
18337 break;
18338
18339 for (var j = 0; j < len; j++) {
18340 var z = tmp[j];
18341 var p;
18342 if (z === 0)
18343 continue;
18344 else if (z > 0)
18345 p = wnd[j][(z - 1) >> 1];
18346 else if (z < 0)
18347 p = wnd[j][(-z - 1) >> 1].neg();
18348
18349 if (p.type === 'affine')
18350 acc = acc.mixedAdd(p);
18351 else
18352 acc = acc.add(p);
18353 }
18354 }
18355 // Zeroify references
18356 for (var i = 0; i < len; i++)
18357 wnd[i] = null;
18358
18359 if (jacobianResult)
18360 return acc;
18361 else
18362 return acc.toP();
18363 };
18364
18365 function BasePoint(curve, type) {
18366 this.curve = curve;
18367 this.type = type;
18368 this.precomputed = null;
18369 }
18370 BaseCurve.BasePoint = BasePoint;
18371
18372 BasePoint.prototype.eq = function eq(/*other*/) {
18373 throw new Error('Not implemented');
18374 };
18375
18376 BasePoint.prototype.validate = function validate() {
18377 return this.curve.validate(this);
18378 };
18379
18380 BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
18381 bytes = utils.toArray(bytes, enc);
18382
18383 var len = this.p.byteLength();
18384
18385 // uncompressed, hybrid-odd, hybrid-even
18386 if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
18387 bytes.length - 1 === 2 * len) {
18388 if (bytes[0] === 0x06)
18389 assert(bytes[bytes.length - 1] % 2 === 0);
18390 else if (bytes[0] === 0x07)
18391 assert(bytes[bytes.length - 1] % 2 === 1);
18392
18393 var res = this.point(bytes.slice(1, 1 + len),
18394 bytes.slice(1 + len, 1 + 2 * len));
18395
18396 return res;
18397 } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
18398 bytes.length - 1 === len) {
18399 return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
18400 }
18401 throw new Error('Unknown point format');
18402 };
18403
18404 BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
18405 return this.encode(enc, true);
18406 };
18407
18408 BasePoint.prototype._encode = function _encode(compact) {
18409 var len = this.curve.p.byteLength();
18410 var x = this.getX().toArray('be', len);
18411
18412 if (compact)
18413 return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
18414
18415 return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
18416 };
18417
18418 BasePoint.prototype.encode = function encode(enc, compact) {
18419 return utils.encode(this._encode(compact), enc);
18420 };
18421
18422 BasePoint.prototype.precompute = function precompute(power) {
18423 if (this.precomputed)
18424 return this;
18425
18426 var precomputed = {
18427 doubles: null,
18428 naf: null,
18429 beta: null
18430 };
18431 precomputed.naf = this._getNAFPoints(8);
18432 precomputed.doubles = this._getDoubles(4, power);
18433 precomputed.beta = this._getBeta();
18434 this.precomputed = precomputed;
18435
18436 return this;
18437 };
18438
18439 BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
18440 if (!this.precomputed)
18441 return false;
18442
18443 var doubles = this.precomputed.doubles;
18444 if (!doubles)
18445 return false;
18446
18447 return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
18448 };
18449
18450 BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
18451 if (this.precomputed && this.precomputed.doubles)
18452 return this.precomputed.doubles;
18453
18454 var doubles = [ this ];
18455 var acc = this;
18456 for (var i = 0; i < power; i += step) {
18457 for (var j = 0; j < step; j++)
18458 acc = acc.dbl();
18459 doubles.push(acc);
18460 }
18461 return {
18462 step: step,
18463 points: doubles
18464 };
18465 };
18466
18467 BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
18468 if (this.precomputed && this.precomputed.naf)
18469 return this.precomputed.naf;
18470
18471 var res = [ this ];
18472 var max = (1 << wnd) - 1;
18473 var dbl = max === 1 ? null : this.dbl();
18474 for (var i = 1; i < max; i++)
18475 res[i] = res[i - 1].add(dbl);
18476 return {
18477 wnd: wnd,
18478 points: res
18479 };
18480 };
18481
18482 BasePoint.prototype._getBeta = function _getBeta() {
18483 return null;
18484 };
18485
18486 BasePoint.prototype.dblp = function dblp(k) {
18487 var r = this;
18488 for (var i = 0; i < k; i++)
18489 r = r.dbl();
18490 return r;
18491 };
18492
18493 },{"../utils":143,"bn.js":79}],131:[function(require,module,exports){
18494 'use strict';
18495
18496 var utils = require('../utils');
18497 var BN = require('bn.js');
18498 var inherits = require('inherits');
18499 var Base = require('./base');
18500
18501 var assert = utils.assert;
18502
18503 function EdwardsCurve(conf) {
18504 // NOTE: Important as we are creating point in Base.call()
18505 this.twisted = (conf.a | 0) !== 1;
18506 this.mOneA = this.twisted && (conf.a | 0) === -1;
18507 this.extended = this.mOneA;
18508
18509 Base.call(this, 'edwards', conf);
18510
18511 this.a = new BN(conf.a, 16).umod(this.red.m);
18512 this.a = this.a.toRed(this.red);
18513 this.c = new BN(conf.c, 16).toRed(this.red);
18514 this.c2 = this.c.redSqr();
18515 this.d = new BN(conf.d, 16).toRed(this.red);
18516 this.dd = this.d.redAdd(this.d);
18517
18518 assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
18519 this.oneC = (conf.c | 0) === 1;
18520 }
18521 inherits(EdwardsCurve, Base);
18522 module.exports = EdwardsCurve;
18523
18524 EdwardsCurve.prototype._mulA = function _mulA(num) {
18525 if (this.mOneA)
18526 return num.redNeg();
18527 else
18528 return this.a.redMul(num);
18529 };
18530
18531 EdwardsCurve.prototype._mulC = function _mulC(num) {
18532 if (this.oneC)
18533 return num;
18534 else
18535 return this.c.redMul(num);
18536 };
18537
18538 // Just for compatibility with Short curve
18539 EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
18540 return this.point(x, y, z, t);
18541 };
18542
18543 EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
18544 x = new BN(x, 16);
18545 if (!x.red)
18546 x = x.toRed(this.red);
18547
18548 var x2 = x.redSqr();
18549 var rhs = this.c2.redSub(this.a.redMul(x2));
18550 var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
18551
18552 var y2 = rhs.redMul(lhs.redInvm());
18553 var y = y2.redSqrt();
18554 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
18555 throw new Error('invalid point');
18556
18557 var isOdd = y.fromRed().isOdd();
18558 if (odd && !isOdd || !odd && isOdd)
18559 y = y.redNeg();
18560
18561 return this.point(x, y);
18562 };
18563
18564 EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
18565 y = new BN(y, 16);
18566 if (!y.red)
18567 y = y.toRed(this.red);
18568
18569 // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
18570 var y2 = y.redSqr();
18571 var lhs = y2.redSub(this.c2);
18572 var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
18573 var x2 = lhs.redMul(rhs.redInvm());
18574
18575 if (x2.cmp(this.zero) === 0) {
18576 if (odd)
18577 throw new Error('invalid point');
18578 else
18579 return this.point(this.zero, y);
18580 }
18581
18582 var x = x2.redSqrt();
18583 if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
18584 throw new Error('invalid point');
18585
18586 if (x.fromRed().isOdd() !== odd)
18587 x = x.redNeg();
18588
18589 return this.point(x, y);
18590 };
18591
18592 EdwardsCurve.prototype.validate = function validate(point) {
18593 if (point.isInfinity())
18594 return true;
18595
18596 // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
18597 point.normalize();
18598
18599 var x2 = point.x.redSqr();
18600 var y2 = point.y.redSqr();
18601 var lhs = x2.redMul(this.a).redAdd(y2);
18602 var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
18603
18604 return lhs.cmp(rhs) === 0;
18605 };
18606
18607 function Point(curve, x, y, z, t) {
18608 Base.BasePoint.call(this, curve, 'projective');
18609 if (x === null && y === null && z === null) {
18610 this.x = this.curve.zero;
18611 this.y = this.curve.one;
18612 this.z = this.curve.one;
18613 this.t = this.curve.zero;
18614 this.zOne = true;
18615 } else {
18616 this.x = new BN(x, 16);
18617 this.y = new BN(y, 16);
18618 this.z = z ? new BN(z, 16) : this.curve.one;
18619 this.t = t && new BN(t, 16);
18620 if (!this.x.red)
18621 this.x = this.x.toRed(this.curve.red);
18622 if (!this.y.red)
18623 this.y = this.y.toRed(this.curve.red);
18624 if (!this.z.red)
18625 this.z = this.z.toRed(this.curve.red);
18626 if (this.t && !this.t.red)
18627 this.t = this.t.toRed(this.curve.red);
18628 this.zOne = this.z === this.curve.one;
18629
18630 // Use extended coordinates
18631 if (this.curve.extended && !this.t) {
18632 this.t = this.x.redMul(this.y);
18633 if (!this.zOne)
18634 this.t = this.t.redMul(this.z.redInvm());
18635 }
18636 }
18637 }
18638 inherits(Point, Base.BasePoint);
18639
18640 EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
18641 return Point.fromJSON(this, obj);
18642 };
18643
18644 EdwardsCurve.prototype.point = function point(x, y, z, t) {
18645 return new Point(this, x, y, z, t);
18646 };
18647
18648 Point.fromJSON = function fromJSON(curve, obj) {
18649 return new Point(curve, obj[0], obj[1], obj[2]);
18650 };
18651
18652 Point.prototype.inspect = function inspect() {
18653 if (this.isInfinity())
18654 return '<EC Point Infinity>';
18655 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
18656 ' y: ' + this.y.fromRed().toString(16, 2) +
18657 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
18658 };
18659
18660 Point.prototype.isInfinity = function isInfinity() {
18661 // XXX This code assumes that zero is always zero in red
18662 return this.x.cmpn(0) === 0 &&
18663 (this.y.cmp(this.z) === 0 ||
18664 (this.zOne && this.y.cmp(this.curve.c) === 0));
18665 };
18666
18667 Point.prototype._extDbl = function _extDbl() {
18668 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
18669 // #doubling-dbl-2008-hwcd
18670 // 4M + 4S
18671
18672 // A = X1^2
18673 var a = this.x.redSqr();
18674 // B = Y1^2
18675 var b = this.y.redSqr();
18676 // C = 2 * Z1^2
18677 var c = this.z.redSqr();
18678 c = c.redIAdd(c);
18679 // D = a * A
18680 var d = this.curve._mulA(a);
18681 // E = (X1 + Y1)^2 - A - B
18682 var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
18683 // G = D + B
18684 var g = d.redAdd(b);
18685 // F = G - C
18686 var f = g.redSub(c);
18687 // H = D - B
18688 var h = d.redSub(b);
18689 // X3 = E * F
18690 var nx = e.redMul(f);
18691 // Y3 = G * H
18692 var ny = g.redMul(h);
18693 // T3 = E * H
18694 var nt = e.redMul(h);
18695 // Z3 = F * G
18696 var nz = f.redMul(g);
18697 return this.curve.point(nx, ny, nz, nt);
18698 };
18699
18700 Point.prototype._projDbl = function _projDbl() {
18701 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
18702 // #doubling-dbl-2008-bbjlp
18703 // #doubling-dbl-2007-bl
18704 // and others
18705 // Generally 3M + 4S or 2M + 4S
18706
18707 // B = (X1 + Y1)^2
18708 var b = this.x.redAdd(this.y).redSqr();
18709 // C = X1^2
18710 var c = this.x.redSqr();
18711 // D = Y1^2
18712 var d = this.y.redSqr();
18713
18714 var nx;
18715 var ny;
18716 var nz;
18717 if (this.curve.twisted) {
18718 // E = a * C
18719 var e = this.curve._mulA(c);
18720 // F = E + D
18721 var f = e.redAdd(d);
18722 if (this.zOne) {
18723 // X3 = (B - C - D) * (F - 2)
18724 nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
18725 // Y3 = F * (E - D)
18726 ny = f.redMul(e.redSub(d));
18727 // Z3 = F^2 - 2 * F
18728 nz = f.redSqr().redSub(f).redSub(f);
18729 } else {
18730 // H = Z1^2
18731 var h = this.z.redSqr();
18732 // J = F - 2 * H
18733 var j = f.redSub(h).redISub(h);
18734 // X3 = (B-C-D)*J
18735 nx = b.redSub(c).redISub(d).redMul(j);
18736 // Y3 = F * (E - D)
18737 ny = f.redMul(e.redSub(d));
18738 // Z3 = F * J
18739 nz = f.redMul(j);
18740 }
18741 } else {
18742 // E = C + D
18743 var e = c.redAdd(d);
18744 // H = (c * Z1)^2
18745 var h = this.curve._mulC(this.z).redSqr();
18746 // J = E - 2 * H
18747 var j = e.redSub(h).redSub(h);
18748 // X3 = c * (B - E) * J
18749 nx = this.curve._mulC(b.redISub(e)).redMul(j);
18750 // Y3 = c * E * (C - D)
18751 ny = this.curve._mulC(e).redMul(c.redISub(d));
18752 // Z3 = E * J
18753 nz = e.redMul(j);
18754 }
18755 return this.curve.point(nx, ny, nz);
18756 };
18757
18758 Point.prototype.dbl = function dbl() {
18759 if (this.isInfinity())
18760 return this;
18761
18762 // Double in extended coordinates
18763 if (this.curve.extended)
18764 return this._extDbl();
18765 else
18766 return this._projDbl();
18767 };
18768
18769 Point.prototype._extAdd = function _extAdd(p) {
18770 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
18771 // #addition-add-2008-hwcd-3
18772 // 8M
18773
18774 // A = (Y1 - X1) * (Y2 - X2)
18775 var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
18776 // B = (Y1 + X1) * (Y2 + X2)
18777 var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
18778 // C = T1 * k * T2
18779 var c = this.t.redMul(this.curve.dd).redMul(p.t);
18780 // D = Z1 * 2 * Z2
18781 var d = this.z.redMul(p.z.redAdd(p.z));
18782 // E = B - A
18783 var e = b.redSub(a);
18784 // F = D - C
18785 var f = d.redSub(c);
18786 // G = D + C
18787 var g = d.redAdd(c);
18788 // H = B + A
18789 var h = b.redAdd(a);
18790 // X3 = E * F
18791 var nx = e.redMul(f);
18792 // Y3 = G * H
18793 var ny = g.redMul(h);
18794 // T3 = E * H
18795 var nt = e.redMul(h);
18796 // Z3 = F * G
18797 var nz = f.redMul(g);
18798 return this.curve.point(nx, ny, nz, nt);
18799 };
18800
18801 Point.prototype._projAdd = function _projAdd(p) {
18802 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
18803 // #addition-add-2008-bbjlp
18804 // #addition-add-2007-bl
18805 // 10M + 1S
18806
18807 // A = Z1 * Z2
18808 var a = this.z.redMul(p.z);
18809 // B = A^2
18810 var b = a.redSqr();
18811 // C = X1 * X2
18812 var c = this.x.redMul(p.x);
18813 // D = Y1 * Y2
18814 var d = this.y.redMul(p.y);
18815 // E = d * C * D
18816 var e = this.curve.d.redMul(c).redMul(d);
18817 // F = B - E
18818 var f = b.redSub(e);
18819 // G = B + E
18820 var g = b.redAdd(e);
18821 // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
18822 var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
18823 var nx = a.redMul(f).redMul(tmp);
18824 var ny;
18825 var nz;
18826 if (this.curve.twisted) {
18827 // Y3 = A * G * (D - a * C)
18828 ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
18829 // Z3 = F * G
18830 nz = f.redMul(g);
18831 } else {
18832 // Y3 = A * G * (D - C)
18833 ny = a.redMul(g).redMul(d.redSub(c));
18834 // Z3 = c * F * G
18835 nz = this.curve._mulC(f).redMul(g);
18836 }
18837 return this.curve.point(nx, ny, nz);
18838 };
18839
18840 Point.prototype.add = function add(p) {
18841 if (this.isInfinity())
18842 return p;
18843 if (p.isInfinity())
18844 return this;
18845
18846 if (this.curve.extended)
18847 return this._extAdd(p);
18848 else
18849 return this._projAdd(p);
18850 };
18851
18852 Point.prototype.mul = function mul(k) {
18853 if (this._hasDoubles(k))
18854 return this.curve._fixedNafMul(this, k);
18855 else
18856 return this.curve._wnafMul(this, k);
18857 };
18858
18859 Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
18860 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false);
18861 };
18862
18863 Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
18864 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true);
18865 };
18866
18867 Point.prototype.normalize = function normalize() {
18868 if (this.zOne)
18869 return this;
18870
18871 // Normalize coordinates
18872 var zi = this.z.redInvm();
18873 this.x = this.x.redMul(zi);
18874 this.y = this.y.redMul(zi);
18875 if (this.t)
18876 this.t = this.t.redMul(zi);
18877 this.z = this.curve.one;
18878 this.zOne = true;
18879 return this;
18880 };
18881
18882 Point.prototype.neg = function neg() {
18883 return this.curve.point(this.x.redNeg(),
18884 this.y,
18885 this.z,
18886 this.t && this.t.redNeg());
18887 };
18888
18889 Point.prototype.getX = function getX() {
18890 this.normalize();
18891 return this.x.fromRed();
18892 };
18893
18894 Point.prototype.getY = function getY() {
18895 this.normalize();
18896 return this.y.fromRed();
18897 };
18898
18899 Point.prototype.eq = function eq(other) {
18900 return this === other ||
18901 this.getX().cmp(other.getX()) === 0 &&
18902 this.getY().cmp(other.getY()) === 0;
18903 };
18904
18905 Point.prototype.eqXToP = function eqXToP(x) {
18906 var rx = x.toRed(this.curve.red).redMul(this.z);
18907 if (this.x.cmp(rx) === 0)
18908 return true;
18909
18910 var xc = x.clone();
18911 var t = this.curve.redN.redMul(this.z);
18912 for (;;) {
18913 xc.iadd(this.curve.n);
18914 if (xc.cmp(this.curve.p) >= 0)
18915 return false;
18916
18917 rx.redIAdd(t);
18918 if (this.x.cmp(rx) === 0)
18919 return true;
18920 }
18921 };
18922
18923 // Compatibility with BaseCurve
18924 Point.prototype.toP = Point.prototype.normalize;
18925 Point.prototype.mixedAdd = Point.prototype.add;
18926
18927 },{"../utils":143,"./base":130,"bn.js":79,"inherits":162}],132:[function(require,module,exports){
18928 'use strict';
18929
18930 var curve = exports;
18931
18932 curve.base = require('./base');
18933 curve.short = require('./short');
18934 curve.mont = require('./mont');
18935 curve.edwards = require('./edwards');
18936
18937 },{"./base":130,"./edwards":131,"./mont":133,"./short":134}],133:[function(require,module,exports){
18938 'use strict';
18939
18940 var BN = require('bn.js');
18941 var inherits = require('inherits');
18942 var Base = require('./base');
18943
18944 var utils = require('../utils');
18945
18946 function MontCurve(conf) {
18947 Base.call(this, 'mont', conf);
18948
18949 this.a = new BN(conf.a, 16).toRed(this.red);
18950 this.b = new BN(conf.b, 16).toRed(this.red);
18951 this.i4 = new BN(4).toRed(this.red).redInvm();
18952 this.two = new BN(2).toRed(this.red);
18953 this.a24 = this.i4.redMul(this.a.redAdd(this.two));
18954 }
18955 inherits(MontCurve, Base);
18956 module.exports = MontCurve;
18957
18958 MontCurve.prototype.validate = function validate(point) {
18959 var x = point.normalize().x;
18960 var x2 = x.redSqr();
18961 var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
18962 var y = rhs.redSqrt();
18963
18964 return y.redSqr().cmp(rhs) === 0;
18965 };
18966
18967 function Point(curve, x, z) {
18968 Base.BasePoint.call(this, curve, 'projective');
18969 if (x === null && z === null) {
18970 this.x = this.curve.one;
18971 this.z = this.curve.zero;
18972 } else {
18973 this.x = new BN(x, 16);
18974 this.z = new BN(z, 16);
18975 if (!this.x.red)
18976 this.x = this.x.toRed(this.curve.red);
18977 if (!this.z.red)
18978 this.z = this.z.toRed(this.curve.red);
18979 }
18980 }
18981 inherits(Point, Base.BasePoint);
18982
18983 MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
18984 return this.point(utils.toArray(bytes, enc), 1);
18985 };
18986
18987 MontCurve.prototype.point = function point(x, z) {
18988 return new Point(this, x, z);
18989 };
18990
18991 MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
18992 return Point.fromJSON(this, obj);
18993 };
18994
18995 Point.prototype.precompute = function precompute() {
18996 // No-op
18997 };
18998
18999 Point.prototype._encode = function _encode() {
19000 return this.getX().toArray('be', this.curve.p.byteLength());
19001 };
19002
19003 Point.fromJSON = function fromJSON(curve, obj) {
19004 return new Point(curve, obj[0], obj[1] || curve.one);
19005 };
19006
19007 Point.prototype.inspect = function inspect() {
19008 if (this.isInfinity())
19009 return '<EC Point Infinity>';
19010 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
19011 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
19012 };
19013
19014 Point.prototype.isInfinity = function isInfinity() {
19015 // XXX This code assumes that zero is always zero in red
19016 return this.z.cmpn(0) === 0;
19017 };
19018
19019 Point.prototype.dbl = function dbl() {
19020 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
19021 // 2M + 2S + 4A
19022
19023 // A = X1 + Z1
19024 var a = this.x.redAdd(this.z);
19025 // AA = A^2
19026 var aa = a.redSqr();
19027 // B = X1 - Z1
19028 var b = this.x.redSub(this.z);
19029 // BB = B^2
19030 var bb = b.redSqr();
19031 // C = AA - BB
19032 var c = aa.redSub(bb);
19033 // X3 = AA * BB
19034 var nx = aa.redMul(bb);
19035 // Z3 = C * (BB + A24 * C)
19036 var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
19037 return this.curve.point(nx, nz);
19038 };
19039
19040 Point.prototype.add = function add() {
19041 throw new Error('Not supported on Montgomery curve');
19042 };
19043
19044 Point.prototype.diffAdd = function diffAdd(p, diff) {
19045 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
19046 // 4M + 2S + 6A
19047
19048 // A = X2 + Z2
19049 var a = this.x.redAdd(this.z);
19050 // B = X2 - Z2
19051 var b = this.x.redSub(this.z);
19052 // C = X3 + Z3
19053 var c = p.x.redAdd(p.z);
19054 // D = X3 - Z3
19055 var d = p.x.redSub(p.z);
19056 // DA = D * A
19057 var da = d.redMul(a);
19058 // CB = C * B
19059 var cb = c.redMul(b);
19060 // X5 = Z1 * (DA + CB)^2
19061 var nx = diff.z.redMul(da.redAdd(cb).redSqr());
19062 // Z5 = X1 * (DA - CB)^2
19063 var nz = diff.x.redMul(da.redISub(cb).redSqr());
19064 return this.curve.point(nx, nz);
19065 };
19066
19067 Point.prototype.mul = function mul(k) {
19068 var t = k.clone();
19069 var a = this; // (N / 2) * Q + Q
19070 var b = this.curve.point(null, null); // (N / 2) * Q
19071 var c = this; // Q
19072
19073 for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
19074 bits.push(t.andln(1));
19075
19076 for (var i = bits.length - 1; i >= 0; i--) {
19077 if (bits[i] === 0) {
19078 // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
19079 a = a.diffAdd(b, c);
19080 // N * Q = 2 * ((N / 2) * Q + Q))
19081 b = b.dbl();
19082 } else {
19083 // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
19084 b = a.diffAdd(b, c);
19085 // N * Q + Q = 2 * ((N / 2) * Q + Q)
19086 a = a.dbl();
19087 }
19088 }
19089 return b;
19090 };
19091
19092 Point.prototype.mulAdd = function mulAdd() {
19093 throw new Error('Not supported on Montgomery curve');
19094 };
19095
19096 Point.prototype.jumlAdd = function jumlAdd() {
19097 throw new Error('Not supported on Montgomery curve');
19098 };
19099
19100 Point.prototype.eq = function eq(other) {
19101 return this.getX().cmp(other.getX()) === 0;
19102 };
19103
19104 Point.prototype.normalize = function normalize() {
19105 this.x = this.x.redMul(this.z.redInvm());
19106 this.z = this.curve.one;
19107 return this;
19108 };
19109
19110 Point.prototype.getX = function getX() {
19111 // Normalize coordinates
19112 this.normalize();
19113
19114 return this.x.fromRed();
19115 };
19116
19117 },{"../utils":143,"./base":130,"bn.js":79,"inherits":162}],134:[function(require,module,exports){
19118 'use strict';
19119
19120 var utils = require('../utils');
19121 var BN = require('bn.js');
19122 var inherits = require('inherits');
19123 var Base = require('./base');
19124
19125 var assert = utils.assert;
19126
19127 function ShortCurve(conf) {
19128 Base.call(this, 'short', conf);
19129
19130 this.a = new BN(conf.a, 16).toRed(this.red);
19131 this.b = new BN(conf.b, 16).toRed(this.red);
19132 this.tinv = this.two.redInvm();
19133
19134 this.zeroA = this.a.fromRed().cmpn(0) === 0;
19135 this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
19136
19137 // If the curve is endomorphic, precalculate beta and lambda
19138 this.endo = this._getEndomorphism(conf);
19139 this._endoWnafT1 = new Array(4);
19140 this._endoWnafT2 = new Array(4);
19141 }
19142 inherits(ShortCurve, Base);
19143 module.exports = ShortCurve;
19144
19145 ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
19146 // No efficient endomorphism
19147 if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
19148 return;
19149
19150 // Compute beta and lambda, that lambda * P = (beta * Px; Py)
19151 var beta;
19152 var lambda;
19153 if (conf.beta) {
19154 beta = new BN(conf.beta, 16).toRed(this.red);
19155 } else {
19156 var betas = this._getEndoRoots(this.p);
19157 // Choose the smallest beta
19158 beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
19159 beta = beta.toRed(this.red);
19160 }
19161 if (conf.lambda) {
19162 lambda = new BN(conf.lambda, 16);
19163 } else {
19164 // Choose the lambda that is matching selected beta
19165 var lambdas = this._getEndoRoots(this.n);
19166 if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
19167 lambda = lambdas[0];
19168 } else {
19169 lambda = lambdas[1];
19170 assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
19171 }
19172 }
19173
19174 // Get basis vectors, used for balanced length-two representation
19175 var basis;
19176 if (conf.basis) {
19177 basis = conf.basis.map(function(vec) {
19178 return {
19179 a: new BN(vec.a, 16),
19180 b: new BN(vec.b, 16)
19181 };
19182 });
19183 } else {
19184 basis = this._getEndoBasis(lambda);
19185 }
19186
19187 return {
19188 beta: beta,
19189 lambda: lambda,
19190 basis: basis
19191 };
19192 };
19193
19194 ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
19195 // Find roots of for x^2 + x + 1 in F
19196 // Root = (-1 +- Sqrt(-3)) / 2
19197 //
19198 var red = num === this.p ? this.red : BN.mont(num);
19199 var tinv = new BN(2).toRed(red).redInvm();
19200 var ntinv = tinv.redNeg();
19201
19202 var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
19203
19204 var l1 = ntinv.redAdd(s).fromRed();
19205 var l2 = ntinv.redSub(s).fromRed();
19206 return [ l1, l2 ];
19207 };
19208
19209 ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
19210 // aprxSqrt >= sqrt(this.n)
19211 var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
19212
19213 // 3.74
19214 // Run EGCD, until r(L + 1) < aprxSqrt
19215 var u = lambda;
19216 var v = this.n.clone();
19217 var x1 = new BN(1);
19218 var y1 = new BN(0);
19219 var x2 = new BN(0);
19220 var y2 = new BN(1);
19221
19222 // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
19223 var a0;
19224 var b0;
19225 // First vector
19226 var a1;
19227 var b1;
19228 // Second vector
19229 var a2;
19230 var b2;
19231
19232 var prevR;
19233 var i = 0;
19234 var r;
19235 var x;
19236 while (u.cmpn(0) !== 0) {
19237 var q = v.div(u);
19238 r = v.sub(q.mul(u));
19239 x = x2.sub(q.mul(x1));
19240 var y = y2.sub(q.mul(y1));
19241
19242 if (!a1 && r.cmp(aprxSqrt) < 0) {
19243 a0 = prevR.neg();
19244 b0 = x1;
19245 a1 = r.neg();
19246 b1 = x;
19247 } else if (a1 && ++i === 2) {
19248 break;
19249 }
19250 prevR = r;
19251
19252 v = u;
19253 u = r;
19254 x2 = x1;
19255 x1 = x;
19256 y2 = y1;
19257 y1 = y;
19258 }
19259 a2 = r.neg();
19260 b2 = x;
19261
19262 var len1 = a1.sqr().add(b1.sqr());
19263 var len2 = a2.sqr().add(b2.sqr());
19264 if (len2.cmp(len1) >= 0) {
19265 a2 = a0;
19266 b2 = b0;
19267 }
19268
19269 // Normalize signs
19270 if (a1.negative) {
19271 a1 = a1.neg();
19272 b1 = b1.neg();
19273 }
19274 if (a2.negative) {
19275 a2 = a2.neg();
19276 b2 = b2.neg();
19277 }
19278
19279 return [
19280 { a: a1, b: b1 },
19281 { a: a2, b: b2 }
19282 ];
19283 };
19284
19285 ShortCurve.prototype._endoSplit = function _endoSplit(k) {
19286 var basis = this.endo.basis;
19287 var v1 = basis[0];
19288 var v2 = basis[1];
19289
19290 var c1 = v2.b.mul(k).divRound(this.n);
19291 var c2 = v1.b.neg().mul(k).divRound(this.n);
19292
19293 var p1 = c1.mul(v1.a);
19294 var p2 = c2.mul(v2.a);
19295 var q1 = c1.mul(v1.b);
19296 var q2 = c2.mul(v2.b);
19297
19298 // Calculate answer
19299 var k1 = k.sub(p1).sub(p2);
19300 var k2 = q1.add(q2).neg();
19301 return { k1: k1, k2: k2 };
19302 };
19303
19304 ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
19305 x = new BN(x, 16);
19306 if (!x.red)
19307 x = x.toRed(this.red);
19308
19309 var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
19310 var y = y2.redSqrt();
19311 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
19312 throw new Error('invalid point');
19313
19314 // XXX Is there any way to tell if the number is odd without converting it
19315 // to non-red form?
19316 var isOdd = y.fromRed().isOdd();
19317 if (odd && !isOdd || !odd && isOdd)
19318 y = y.redNeg();
19319
19320 return this.point(x, y);
19321 };
19322
19323 ShortCurve.prototype.validate = function validate(point) {
19324 if (point.inf)
19325 return true;
19326
19327 var x = point.x;
19328 var y = point.y;
19329
19330 var ax = this.a.redMul(x);
19331 var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
19332 return y.redSqr().redISub(rhs).cmpn(0) === 0;
19333 };
19334
19335 ShortCurve.prototype._endoWnafMulAdd =
19336 function _endoWnafMulAdd(points, coeffs, jacobianResult) {
19337 var npoints = this._endoWnafT1;
19338 var ncoeffs = this._endoWnafT2;
19339 for (var i = 0; i < points.length; i++) {
19340 var split = this._endoSplit(coeffs[i]);
19341 var p = points[i];
19342 var beta = p._getBeta();
19343
19344 if (split.k1.negative) {
19345 split.k1.ineg();
19346 p = p.neg(true);
19347 }
19348 if (split.k2.negative) {
19349 split.k2.ineg();
19350 beta = beta.neg(true);
19351 }
19352
19353 npoints[i * 2] = p;
19354 npoints[i * 2 + 1] = beta;
19355 ncoeffs[i * 2] = split.k1;
19356 ncoeffs[i * 2 + 1] = split.k2;
19357 }
19358 var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
19359
19360 // Clean-up references to points and coefficients
19361 for (var j = 0; j < i * 2; j++) {
19362 npoints[j] = null;
19363 ncoeffs[j] = null;
19364 }
19365 return res;
19366 };
19367
19368 function Point(curve, x, y, isRed) {
19369 Base.BasePoint.call(this, curve, 'affine');
19370 if (x === null && y === null) {
19371 this.x = null;
19372 this.y = null;
19373 this.inf = true;
19374 } else {
19375 this.x = new BN(x, 16);
19376 this.y = new BN(y, 16);
19377 // Force redgomery representation when loading from JSON
19378 if (isRed) {
19379 this.x.forceRed(this.curve.red);
19380 this.y.forceRed(this.curve.red);
19381 }
19382 if (!this.x.red)
19383 this.x = this.x.toRed(this.curve.red);
19384 if (!this.y.red)
19385 this.y = this.y.toRed(this.curve.red);
19386 this.inf = false;
19387 }
19388 }
19389 inherits(Point, Base.BasePoint);
19390
19391 ShortCurve.prototype.point = function point(x, y, isRed) {
19392 return new Point(this, x, y, isRed);
19393 };
19394
19395 ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
19396 return Point.fromJSON(this, obj, red);
19397 };
19398
19399 Point.prototype._getBeta = function _getBeta() {
19400 if (!this.curve.endo)
19401 return;
19402
19403 var pre = this.precomputed;
19404 if (pre && pre.beta)
19405 return pre.beta;
19406
19407 var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
19408 if (pre) {
19409 var curve = this.curve;
19410 var endoMul = function(p) {
19411 return curve.point(p.x.redMul(curve.endo.beta), p.y);
19412 };
19413 pre.beta = beta;
19414 beta.precomputed = {
19415 beta: null,
19416 naf: pre.naf && {
19417 wnd: pre.naf.wnd,
19418 points: pre.naf.points.map(endoMul)
19419 },
19420 doubles: pre.doubles && {
19421 step: pre.doubles.step,
19422 points: pre.doubles.points.map(endoMul)
19423 }
19424 };
19425 }
19426 return beta;
19427 };
19428
19429 Point.prototype.toJSON = function toJSON() {
19430 if (!this.precomputed)
19431 return [ this.x, this.y ];
19432
19433 return [ this.x, this.y, this.precomputed && {
19434 doubles: this.precomputed.doubles && {
19435 step: this.precomputed.doubles.step,
19436 points: this.precomputed.doubles.points.slice(1)
19437 },
19438 naf: this.precomputed.naf && {
19439 wnd: this.precomputed.naf.wnd,
19440 points: this.precomputed.naf.points.slice(1)
19441 }
19442 } ];
19443 };
19444
19445 Point.fromJSON = function fromJSON(curve, obj, red) {
19446 if (typeof obj === 'string')
19447 obj = JSON.parse(obj);
19448 var res = curve.point(obj[0], obj[1], red);
19449 if (!obj[2])
19450 return res;
19451
19452 function obj2point(obj) {
19453 return curve.point(obj[0], obj[1], red);
19454 }
19455
19456 var pre = obj[2];
19457 res.precomputed = {
19458 beta: null,
19459 doubles: pre.doubles && {
19460 step: pre.doubles.step,
19461 points: [ res ].concat(pre.doubles.points.map(obj2point))
19462 },
19463 naf: pre.naf && {
19464 wnd: pre.naf.wnd,
19465 points: [ res ].concat(pre.naf.points.map(obj2point))
19466 }
19467 };
19468 return res;
19469 };
19470
19471 Point.prototype.inspect = function inspect() {
19472 if (this.isInfinity())
19473 return '<EC Point Infinity>';
19474 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
19475 ' y: ' + this.y.fromRed().toString(16, 2) + '>';
19476 };
19477
19478 Point.prototype.isInfinity = function isInfinity() {
19479 return this.inf;
19480 };
19481
19482 Point.prototype.add = function add(p) {
19483 // O + P = P
19484 if (this.inf)
19485 return p;
19486
19487 // P + O = P
19488 if (p.inf)
19489 return this;
19490
19491 // P + P = 2P
19492 if (this.eq(p))
19493 return this.dbl();
19494
19495 // P + (-P) = O
19496 if (this.neg().eq(p))
19497 return this.curve.point(null, null);
19498
19499 // P + Q = O
19500 if (this.x.cmp(p.x) === 0)
19501 return this.curve.point(null, null);
19502
19503 var c = this.y.redSub(p.y);
19504 if (c.cmpn(0) !== 0)
19505 c = c.redMul(this.x.redSub(p.x).redInvm());
19506 var nx = c.redSqr().redISub(this.x).redISub(p.x);
19507 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
19508 return this.curve.point(nx, ny);
19509 };
19510
19511 Point.prototype.dbl = function dbl() {
19512 if (this.inf)
19513 return this;
19514
19515 // 2P = O
19516 var ys1 = this.y.redAdd(this.y);
19517 if (ys1.cmpn(0) === 0)
19518 return this.curve.point(null, null);
19519
19520 var a = this.curve.a;
19521
19522 var x2 = this.x.redSqr();
19523 var dyinv = ys1.redInvm();
19524 var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
19525
19526 var nx = c.redSqr().redISub(this.x.redAdd(this.x));
19527 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
19528 return this.curve.point(nx, ny);
19529 };
19530
19531 Point.prototype.getX = function getX() {
19532 return this.x.fromRed();
19533 };
19534
19535 Point.prototype.getY = function getY() {
19536 return this.y.fromRed();
19537 };
19538
19539 Point.prototype.mul = function mul(k) {
19540 k = new BN(k, 16);
19541
19542 if (this._hasDoubles(k))
19543 return this.curve._fixedNafMul(this, k);
19544 else if (this.curve.endo)
19545 return this.curve._endoWnafMulAdd([ this ], [ k ]);
19546 else
19547 return this.curve._wnafMul(this, k);
19548 };
19549
19550 Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
19551 var points = [ this, p2 ];
19552 var coeffs = [ k1, k2 ];
19553 if (this.curve.endo)
19554 return this.curve._endoWnafMulAdd(points, coeffs);
19555 else
19556 return this.curve._wnafMulAdd(1, points, coeffs, 2);
19557 };
19558
19559 Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
19560 var points = [ this, p2 ];
19561 var coeffs = [ k1, k2 ];
19562 if (this.curve.endo)
19563 return this.curve._endoWnafMulAdd(points, coeffs, true);
19564 else
19565 return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
19566 };
19567
19568 Point.prototype.eq = function eq(p) {
19569 return this === p ||
19570 this.inf === p.inf &&
19571 (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
19572 };
19573
19574 Point.prototype.neg = function neg(_precompute) {
19575 if (this.inf)
19576 return this;
19577
19578 var res = this.curve.point(this.x, this.y.redNeg());
19579 if (_precompute && this.precomputed) {
19580 var pre = this.precomputed;
19581 var negate = function(p) {
19582 return p.neg();
19583 };
19584 res.precomputed = {
19585 naf: pre.naf && {
19586 wnd: pre.naf.wnd,
19587 points: pre.naf.points.map(negate)
19588 },
19589 doubles: pre.doubles && {
19590 step: pre.doubles.step,
19591 points: pre.doubles.points.map(negate)
19592 }
19593 };
19594 }
19595 return res;
19596 };
19597
19598 Point.prototype.toJ = function toJ() {
19599 if (this.inf)
19600 return this.curve.jpoint(null, null, null);
19601
19602 var res = this.curve.jpoint(this.x, this.y, this.curve.one);
19603 return res;
19604 };
19605
19606 function JPoint(curve, x, y, z) {
19607 Base.BasePoint.call(this, curve, 'jacobian');
19608 if (x === null && y === null && z === null) {
19609 this.x = this.curve.one;
19610 this.y = this.curve.one;
19611 this.z = new BN(0);
19612 } else {
19613 this.x = new BN(x, 16);
19614 this.y = new BN(y, 16);
19615 this.z = new BN(z, 16);
19616 }
19617 if (!this.x.red)
19618 this.x = this.x.toRed(this.curve.red);
19619 if (!this.y.red)
19620 this.y = this.y.toRed(this.curve.red);
19621 if (!this.z.red)
19622 this.z = this.z.toRed(this.curve.red);
19623
19624 this.zOne = this.z === this.curve.one;
19625 }
19626 inherits(JPoint, Base.BasePoint);
19627
19628 ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
19629 return new JPoint(this, x, y, z);
19630 };
19631
19632 JPoint.prototype.toP = function toP() {
19633 if (this.isInfinity())
19634 return this.curve.point(null, null);
19635
19636 var zinv = this.z.redInvm();
19637 var zinv2 = zinv.redSqr();
19638 var ax = this.x.redMul(zinv2);
19639 var ay = this.y.redMul(zinv2).redMul(zinv);
19640
19641 return this.curve.point(ax, ay);
19642 };
19643
19644 JPoint.prototype.neg = function neg() {
19645 return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
19646 };
19647
19648 JPoint.prototype.add = function add(p) {
19649 // O + P = P
19650 if (this.isInfinity())
19651 return p;
19652
19653 // P + O = P
19654 if (p.isInfinity())
19655 return this;
19656
19657 // 12M + 4S + 7A
19658 var pz2 = p.z.redSqr();
19659 var z2 = this.z.redSqr();
19660 var u1 = this.x.redMul(pz2);
19661 var u2 = p.x.redMul(z2);
19662 var s1 = this.y.redMul(pz2.redMul(p.z));
19663 var s2 = p.y.redMul(z2.redMul(this.z));
19664
19665 var h = u1.redSub(u2);
19666 var r = s1.redSub(s2);
19667 if (h.cmpn(0) === 0) {
19668 if (r.cmpn(0) !== 0)
19669 return this.curve.jpoint(null, null, null);
19670 else
19671 return this.dbl();
19672 }
19673
19674 var h2 = h.redSqr();
19675 var h3 = h2.redMul(h);
19676 var v = u1.redMul(h2);
19677
19678 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
19679 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
19680 var nz = this.z.redMul(p.z).redMul(h);
19681
19682 return this.curve.jpoint(nx, ny, nz);
19683 };
19684
19685 JPoint.prototype.mixedAdd = function mixedAdd(p) {
19686 // O + P = P
19687 if (this.isInfinity())
19688 return p.toJ();
19689
19690 // P + O = P
19691 if (p.isInfinity())
19692 return this;
19693
19694 // 8M + 3S + 7A
19695 var z2 = this.z.redSqr();
19696 var u1 = this.x;
19697 var u2 = p.x.redMul(z2);
19698 var s1 = this.y;
19699 var s2 = p.y.redMul(z2).redMul(this.z);
19700
19701 var h = u1.redSub(u2);
19702 var r = s1.redSub(s2);
19703 if (h.cmpn(0) === 0) {
19704 if (r.cmpn(0) !== 0)
19705 return this.curve.jpoint(null, null, null);
19706 else
19707 return this.dbl();
19708 }
19709
19710 var h2 = h.redSqr();
19711 var h3 = h2.redMul(h);
19712 var v = u1.redMul(h2);
19713
19714 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
19715 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
19716 var nz = this.z.redMul(h);
19717
19718 return this.curve.jpoint(nx, ny, nz);
19719 };
19720
19721 JPoint.prototype.dblp = function dblp(pow) {
19722 if (pow === 0)
19723 return this;
19724 if (this.isInfinity())
19725 return this;
19726 if (!pow)
19727 return this.dbl();
19728
19729 if (this.curve.zeroA || this.curve.threeA) {
19730 var r = this;
19731 for (var i = 0; i < pow; i++)
19732 r = r.dbl();
19733 return r;
19734 }
19735
19736 // 1M + 2S + 1A + N * (4S + 5M + 8A)
19737 // N = 1 => 6M + 6S + 9A
19738 var a = this.curve.a;
19739 var tinv = this.curve.tinv;
19740
19741 var jx = this.x;
19742 var jy = this.y;
19743 var jz = this.z;
19744 var jz4 = jz.redSqr().redSqr();
19745
19746 // Reuse results
19747 var jyd = jy.redAdd(jy);
19748 for (var i = 0; i < pow; i++) {
19749 var jx2 = jx.redSqr();
19750 var jyd2 = jyd.redSqr();
19751 var jyd4 = jyd2.redSqr();
19752 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
19753
19754 var t1 = jx.redMul(jyd2);
19755 var nx = c.redSqr().redISub(t1.redAdd(t1));
19756 var t2 = t1.redISub(nx);
19757 var dny = c.redMul(t2);
19758 dny = dny.redIAdd(dny).redISub(jyd4);
19759 var nz = jyd.redMul(jz);
19760 if (i + 1 < pow)
19761 jz4 = jz4.redMul(jyd4);
19762
19763 jx = nx;
19764 jz = nz;
19765 jyd = dny;
19766 }
19767
19768 return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
19769 };
19770
19771 JPoint.prototype.dbl = function dbl() {
19772 if (this.isInfinity())
19773 return this;
19774
19775 if (this.curve.zeroA)
19776 return this._zeroDbl();
19777 else if (this.curve.threeA)
19778 return this._threeDbl();
19779 else
19780 return this._dbl();
19781 };
19782
19783 JPoint.prototype._zeroDbl = function _zeroDbl() {
19784 var nx;
19785 var ny;
19786 var nz;
19787 // Z = 1
19788 if (this.zOne) {
19789 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
19790 // #doubling-mdbl-2007-bl
19791 // 1M + 5S + 14A
19792
19793 // XX = X1^2
19794 var xx = this.x.redSqr();
19795 // YY = Y1^2
19796 var yy = this.y.redSqr();
19797 // YYYY = YY^2
19798 var yyyy = yy.redSqr();
19799 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
19800 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
19801 s = s.redIAdd(s);
19802 // M = 3 * XX + a; a = 0
19803 var m = xx.redAdd(xx).redIAdd(xx);
19804 // T = M ^ 2 - 2*S
19805 var t = m.redSqr().redISub(s).redISub(s);
19806
19807 // 8 * YYYY
19808 var yyyy8 = yyyy.redIAdd(yyyy);
19809 yyyy8 = yyyy8.redIAdd(yyyy8);
19810 yyyy8 = yyyy8.redIAdd(yyyy8);
19811
19812 // X3 = T
19813 nx = t;
19814 // Y3 = M * (S - T) - 8 * YYYY
19815 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
19816 // Z3 = 2*Y1
19817 nz = this.y.redAdd(this.y);
19818 } else {
19819 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
19820 // #doubling-dbl-2009-l
19821 // 2M + 5S + 13A
19822
19823 // A = X1^2
19824 var a = this.x.redSqr();
19825 // B = Y1^2
19826 var b = this.y.redSqr();
19827 // C = B^2
19828 var c = b.redSqr();
19829 // D = 2 * ((X1 + B)^2 - A - C)
19830 var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
19831 d = d.redIAdd(d);
19832 // E = 3 * A
19833 var e = a.redAdd(a).redIAdd(a);
19834 // F = E^2
19835 var f = e.redSqr();
19836
19837 // 8 * C
19838 var c8 = c.redIAdd(c);
19839 c8 = c8.redIAdd(c8);
19840 c8 = c8.redIAdd(c8);
19841
19842 // X3 = F - 2 * D
19843 nx = f.redISub(d).redISub(d);
19844 // Y3 = E * (D - X3) - 8 * C
19845 ny = e.redMul(d.redISub(nx)).redISub(c8);
19846 // Z3 = 2 * Y1 * Z1
19847 nz = this.y.redMul(this.z);
19848 nz = nz.redIAdd(nz);
19849 }
19850
19851 return this.curve.jpoint(nx, ny, nz);
19852 };
19853
19854 JPoint.prototype._threeDbl = function _threeDbl() {
19855 var nx;
19856 var ny;
19857 var nz;
19858 // Z = 1
19859 if (this.zOne) {
19860 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
19861 // #doubling-mdbl-2007-bl
19862 // 1M + 5S + 15A
19863
19864 // XX = X1^2
19865 var xx = this.x.redSqr();
19866 // YY = Y1^2
19867 var yy = this.y.redSqr();
19868 // YYYY = YY^2
19869 var yyyy = yy.redSqr();
19870 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
19871 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
19872 s = s.redIAdd(s);
19873 // M = 3 * XX + a
19874 var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
19875 // T = M^2 - 2 * S
19876 var t = m.redSqr().redISub(s).redISub(s);
19877 // X3 = T
19878 nx = t;
19879 // Y3 = M * (S - T) - 8 * YYYY
19880 var yyyy8 = yyyy.redIAdd(yyyy);
19881 yyyy8 = yyyy8.redIAdd(yyyy8);
19882 yyyy8 = yyyy8.redIAdd(yyyy8);
19883 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
19884 // Z3 = 2 * Y1
19885 nz = this.y.redAdd(this.y);
19886 } else {
19887 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
19888 // 3M + 5S
19889
19890 // delta = Z1^2
19891 var delta = this.z.redSqr();
19892 // gamma = Y1^2
19893 var gamma = this.y.redSqr();
19894 // beta = X1 * gamma
19895 var beta = this.x.redMul(gamma);
19896 // alpha = 3 * (X1 - delta) * (X1 + delta)
19897 var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
19898 alpha = alpha.redAdd(alpha).redIAdd(alpha);
19899 // X3 = alpha^2 - 8 * beta
19900 var beta4 = beta.redIAdd(beta);
19901 beta4 = beta4.redIAdd(beta4);
19902 var beta8 = beta4.redAdd(beta4);
19903 nx = alpha.redSqr().redISub(beta8);
19904 // Z3 = (Y1 + Z1)^2 - gamma - delta
19905 nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
19906 // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
19907 var ggamma8 = gamma.redSqr();
19908 ggamma8 = ggamma8.redIAdd(ggamma8);
19909 ggamma8 = ggamma8.redIAdd(ggamma8);
19910 ggamma8 = ggamma8.redIAdd(ggamma8);
19911 ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
19912 }
19913
19914 return this.curve.jpoint(nx, ny, nz);
19915 };
19916
19917 JPoint.prototype._dbl = function _dbl() {
19918 var a = this.curve.a;
19919
19920 // 4M + 6S + 10A
19921 var jx = this.x;
19922 var jy = this.y;
19923 var jz = this.z;
19924 var jz4 = jz.redSqr().redSqr();
19925
19926 var jx2 = jx.redSqr();
19927 var jy2 = jy.redSqr();
19928
19929 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
19930
19931 var jxd4 = jx.redAdd(jx);
19932 jxd4 = jxd4.redIAdd(jxd4);
19933 var t1 = jxd4.redMul(jy2);
19934 var nx = c.redSqr().redISub(t1.redAdd(t1));
19935 var t2 = t1.redISub(nx);
19936
19937 var jyd8 = jy2.redSqr();
19938 jyd8 = jyd8.redIAdd(jyd8);
19939 jyd8 = jyd8.redIAdd(jyd8);
19940 jyd8 = jyd8.redIAdd(jyd8);
19941 var ny = c.redMul(t2).redISub(jyd8);
19942 var nz = jy.redAdd(jy).redMul(jz);
19943
19944 return this.curve.jpoint(nx, ny, nz);
19945 };
19946
19947 JPoint.prototype.trpl = function trpl() {
19948 if (!this.curve.zeroA)
19949 return this.dbl().add(this);
19950
19951 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
19952 // 5M + 10S + ...
19953
19954 // XX = X1^2
19955 var xx = this.x.redSqr();
19956 // YY = Y1^2
19957 var yy = this.y.redSqr();
19958 // ZZ = Z1^2
19959 var zz = this.z.redSqr();
19960 // YYYY = YY^2
19961 var yyyy = yy.redSqr();
19962 // M = 3 * XX + a * ZZ2; a = 0
19963 var m = xx.redAdd(xx).redIAdd(xx);
19964 // MM = M^2
19965 var mm = m.redSqr();
19966 // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
19967 var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
19968 e = e.redIAdd(e);
19969 e = e.redAdd(e).redIAdd(e);
19970 e = e.redISub(mm);
19971 // EE = E^2
19972 var ee = e.redSqr();
19973 // T = 16*YYYY
19974 var t = yyyy.redIAdd(yyyy);
19975 t = t.redIAdd(t);
19976 t = t.redIAdd(t);
19977 t = t.redIAdd(t);
19978 // U = (M + E)^2 - MM - EE - T
19979 var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
19980 // X3 = 4 * (X1 * EE - 4 * YY * U)
19981 var yyu4 = yy.redMul(u);
19982 yyu4 = yyu4.redIAdd(yyu4);
19983 yyu4 = yyu4.redIAdd(yyu4);
19984 var nx = this.x.redMul(ee).redISub(yyu4);
19985 nx = nx.redIAdd(nx);
19986 nx = nx.redIAdd(nx);
19987 // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
19988 var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
19989 ny = ny.redIAdd(ny);
19990 ny = ny.redIAdd(ny);
19991 ny = ny.redIAdd(ny);
19992 // Z3 = (Z1 + E)^2 - ZZ - EE
19993 var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
19994
19995 return this.curve.jpoint(nx, ny, nz);
19996 };
19997
19998 JPoint.prototype.mul = function mul(k, kbase) {
19999 k = new BN(k, kbase);
20000
20001 return this.curve._wnafMul(this, k);
20002 };
20003
20004 JPoint.prototype.eq = function eq(p) {
20005 if (p.type === 'affine')
20006 return this.eq(p.toJ());
20007
20008 if (this === p)
20009 return true;
20010
20011 // x1 * z2^2 == x2 * z1^2
20012 var z2 = this.z.redSqr();
20013 var pz2 = p.z.redSqr();
20014 if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
20015 return false;
20016
20017 // y1 * z2^3 == y2 * z1^3
20018 var z3 = z2.redMul(this.z);
20019 var pz3 = pz2.redMul(p.z);
20020 return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
20021 };
20022
20023 JPoint.prototype.eqXToP = function eqXToP(x) {
20024 var zs = this.z.redSqr();
20025 var rx = x.toRed(this.curve.red).redMul(zs);
20026 if (this.x.cmp(rx) === 0)
20027 return true;
20028
20029 var xc = x.clone();
20030 var t = this.curve.redN.redMul(zs);
20031 for (;;) {
20032 xc.iadd(this.curve.n);
20033 if (xc.cmp(this.curve.p) >= 0)
20034 return false;
20035
20036 rx.redIAdd(t);
20037 if (this.x.cmp(rx) === 0)
20038 return true;
20039 }
20040 };
20041
20042 JPoint.prototype.inspect = function inspect() {
20043 if (this.isInfinity())
20044 return '<EC JPoint Infinity>';
20045 return '<EC JPoint x: ' + this.x.toString(16, 2) +
20046 ' y: ' + this.y.toString(16, 2) +
20047 ' z: ' + this.z.toString(16, 2) + '>';
20048 };
20049
20050 JPoint.prototype.isInfinity = function isInfinity() {
20051 // XXX This code assumes that zero is always zero in red
20052 return this.z.cmpn(0) === 0;
20053 };
20054
20055 },{"../utils":143,"./base":130,"bn.js":79,"inherits":162}],135:[function(require,module,exports){
20056 'use strict';
20057
20058 var curves = exports;
20059
20060 var hash = require('hash.js');
20061 var curve = require('./curve');
20062 var utils = require('./utils');
20063
20064 var assert = utils.assert;
20065
20066 function PresetCurve(options) {
20067 if (options.type === 'short')
20068 this.curve = new curve.short(options);
20069 else if (options.type === 'edwards')
20070 this.curve = new curve.edwards(options);
20071 else
20072 this.curve = new curve.mont(options);
20073 this.g = this.curve.g;
20074 this.n = this.curve.n;
20075 this.hash = options.hash;
20076
20077 assert(this.g.validate(), 'Invalid curve');
20078 assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
20079 }
20080 curves.PresetCurve = PresetCurve;
20081
20082 function defineCurve(name, options) {
20083 Object.defineProperty(curves, name, {
20084 configurable: true,
20085 enumerable: true,
20086 get: function() {
20087 var curve = new PresetCurve(options);
20088 Object.defineProperty(curves, name, {
20089 configurable: true,
20090 enumerable: true,
20091 value: curve
20092 });
20093 return curve;
20094 }
20095 });
20096 }
20097
20098 defineCurve('p192', {
20099 type: 'short',
20100 prime: 'p192',
20101 p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
20102 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
20103 b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
20104 n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
20105 hash: hash.sha256,
20106 gRed: false,
20107 g: [
20108 '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
20109 '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
20110 ]
20111 });
20112
20113 defineCurve('p224', {
20114 type: 'short',
20115 prime: 'p224',
20116 p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
20117 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
20118 b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
20119 n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
20120 hash: hash.sha256,
20121 gRed: false,
20122 g: [
20123 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
20124 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
20125 ]
20126 });
20127
20128 defineCurve('p256', {
20129 type: 'short',
20130 prime: null,
20131 p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
20132 a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
20133 b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
20134 n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
20135 hash: hash.sha256,
20136 gRed: false,
20137 g: [
20138 '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
20139 '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
20140 ]
20141 });
20142
20143 defineCurve('p384', {
20144 type: 'short',
20145 prime: null,
20146 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20147 'fffffffe ffffffff 00000000 00000000 ffffffff',
20148 a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20149 'fffffffe ffffffff 00000000 00000000 fffffffc',
20150 b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
20151 '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
20152 n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
20153 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
20154 hash: hash.sha384,
20155 gRed: false,
20156 g: [
20157 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
20158 '5502f25d bf55296c 3a545e38 72760ab7',
20159 '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
20160 '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
20161 ]
20162 });
20163
20164 defineCurve('p521', {
20165 type: 'short',
20166 prime: null,
20167 p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20168 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20169 'ffffffff ffffffff ffffffff ffffffff ffffffff',
20170 a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20171 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20172 'ffffffff ffffffff ffffffff ffffffff fffffffc',
20173 b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
20174 '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
20175 '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
20176 n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
20177 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
20178 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
20179 hash: hash.sha512,
20180 gRed: false,
20181 g: [
20182 '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
20183 '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
20184 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
20185 '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
20186 '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
20187 '3fad0761 353c7086 a272c240 88be9476 9fd16650'
20188 ]
20189 });
20190
20191 defineCurve('curve25519', {
20192 type: 'mont',
20193 prime: 'p25519',
20194 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
20195 a: '76d06',
20196 b: '1',
20197 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
20198 hash: hash.sha256,
20199 gRed: false,
20200 g: [
20201 '9'
20202 ]
20203 });
20204
20205 defineCurve('ed25519', {
20206 type: 'edwards',
20207 prime: 'p25519',
20208 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
20209 a: '-1',
20210 c: '1',
20211 // -121665 * (121666^(-1)) (mod P)
20212 d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
20213 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
20214 hash: hash.sha256,
20215 gRed: false,
20216 g: [
20217 '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
20218
20219 // 4/5
20220 '6666666666666666666666666666666666666666666666666666666666666658'
20221 ]
20222 });
20223
20224 var pre;
20225 try {
20226 pre = require('./precomputed/secp256k1');
20227 } catch (e) {
20228 pre = undefined;
20229 }
20230
20231 defineCurve('secp256k1', {
20232 type: 'short',
20233 prime: 'k256',
20234 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
20235 a: '0',
20236 b: '7',
20237 n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
20238 h: '1',
20239 hash: hash.sha256,
20240
20241 // Precomputed endomorphism
20242 beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
20243 lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
20244 basis: [
20245 {
20246 a: '3086d221a7d46bcde86c90e49284eb15',
20247 b: '-e4437ed6010e88286f547fa90abfe4c3'
20248 },
20249 {
20250 a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
20251 b: '3086d221a7d46bcde86c90e49284eb15'
20252 }
20253 ],
20254
20255 gRed: false,
20256 g: [
20257 '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
20258 '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
20259 pre
20260 ]
20261 });
20262
20263 },{"./curve":132,"./precomputed/secp256k1":142,"./utils":143,"hash.js":148}],136:[function(require,module,exports){
20264 'use strict';
20265
20266 var BN = require('bn.js');
20267 var HmacDRBG = require('hmac-drbg');
20268 var utils = require('../utils');
20269 var curves = require('../curves');
20270 var rand = require('brorand');
20271 var assert = utils.assert;
20272
20273 var KeyPair = require('./key');
20274 var Signature = require('./signature');
20275
20276 function EC(options) {
20277 if (!(this instanceof EC))
20278 return new EC(options);
20279
20280 // Shortcut `elliptic.ec(curve-name)`
20281 if (typeof options === 'string') {
20282 assert(curves.hasOwnProperty(options), 'Unknown curve ' + options);
20283
20284 options = curves[options];
20285 }
20286
20287 // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
20288 if (options instanceof curves.PresetCurve)
20289 options = { curve: options };
20290
20291 this.curve = options.curve.curve;
20292 this.n = this.curve.n;
20293 this.nh = this.n.ushrn(1);
20294 this.g = this.curve.g;
20295
20296 // Point on curve
20297 this.g = options.curve.g;
20298 this.g.precompute(options.curve.n.bitLength() + 1);
20299
20300 // Hash for function for DRBG
20301 this.hash = options.hash || options.curve.hash;
20302 }
20303 module.exports = EC;
20304
20305 EC.prototype.keyPair = function keyPair(options) {
20306 return new KeyPair(this, options);
20307 };
20308
20309 EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
20310 return KeyPair.fromPrivate(this, priv, enc);
20311 };
20312
20313 EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
20314 return KeyPair.fromPublic(this, pub, enc);
20315 };
20316
20317 EC.prototype.genKeyPair = function genKeyPair(options) {
20318 if (!options)
20319 options = {};
20320
20321 // Instantiate Hmac_DRBG
20322 var drbg = new HmacDRBG({
20323 hash: this.hash,
20324 pers: options.pers,
20325 persEnc: options.persEnc || 'utf8',
20326 entropy: options.entropy || rand(this.hash.hmacStrength),
20327 entropyEnc: options.entropy && options.entropyEnc || 'utf8',
20328 nonce: this.n.toArray()
20329 });
20330
20331 var bytes = this.n.byteLength();
20332 var ns2 = this.n.sub(new BN(2));
20333 do {
20334 var priv = new BN(drbg.generate(bytes));
20335 if (priv.cmp(ns2) > 0)
20336 continue;
20337
20338 priv.iaddn(1);
20339 return this.keyFromPrivate(priv);
20340 } while (true);
20341 };
20342
20343 EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
20344 var delta = msg.byteLength() * 8 - this.n.bitLength();
20345 if (delta > 0)
20346 msg = msg.ushrn(delta);
20347 if (!truncOnly && msg.cmp(this.n) >= 0)
20348 return msg.sub(this.n);
20349 else
20350 return msg;
20351 };
20352
20353 EC.prototype.sign = function sign(msg, key, enc, options) {
20354 if (typeof enc === 'object') {
20355 options = enc;
20356 enc = null;
20357 }
20358 if (!options)
20359 options = {};
20360
20361 key = this.keyFromPrivate(key, enc);
20362 msg = this._truncateToN(new BN(msg, 16));
20363
20364 // Zero-extend key to provide enough entropy
20365 var bytes = this.n.byteLength();
20366 var bkey = key.getPrivate().toArray('be', bytes);
20367
20368 // Zero-extend nonce to have the same byte size as N
20369 var nonce = msg.toArray('be', bytes);
20370
20371 // Instantiate Hmac_DRBG
20372 var drbg = new HmacDRBG({
20373 hash: this.hash,
20374 entropy: bkey,
20375 nonce: nonce,
20376 pers: options.pers,
20377 persEnc: options.persEnc || 'utf8'
20378 });
20379
20380 // Number of bytes to generate
20381 var ns1 = this.n.sub(new BN(1));
20382
20383 for (var iter = 0; true; iter++) {
20384 var k = options.k ?
20385 options.k(iter) :
20386 new BN(drbg.generate(this.n.byteLength()));
20387 k = this._truncateToN(k, true);
20388 if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
20389 continue;
20390
20391 var kp = this.g.mul(k);
20392 if (kp.isInfinity())
20393 continue;
20394
20395 var kpX = kp.getX();
20396 var r = kpX.umod(this.n);
20397 if (r.cmpn(0) === 0)
20398 continue;
20399
20400 var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
20401 s = s.umod(this.n);
20402 if (s.cmpn(0) === 0)
20403 continue;
20404
20405 var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
20406 (kpX.cmp(r) !== 0 ? 2 : 0);
20407
20408 // Use complement of `s`, if it is > `n / 2`
20409 if (options.canonical && s.cmp(this.nh) > 0) {
20410 s = this.n.sub(s);
20411 recoveryParam ^= 1;
20412 }
20413
20414 return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
20415 }
20416 };
20417
20418 EC.prototype.verify = function verify(msg, signature, key, enc) {
20419 msg = this._truncateToN(new BN(msg, 16));
20420 key = this.keyFromPublic(key, enc);
20421 signature = new Signature(signature, 'hex');
20422
20423 // Perform primitive values validation
20424 var r = signature.r;
20425 var s = signature.s;
20426 if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
20427 return false;
20428 if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
20429 return false;
20430
20431 // Validate signature
20432 var sinv = s.invm(this.n);
20433 var u1 = sinv.mul(msg).umod(this.n);
20434 var u2 = sinv.mul(r).umod(this.n);
20435
20436 if (!this.curve._maxwellTrick) {
20437 var p = this.g.mulAdd(u1, key.getPublic(), u2);
20438 if (p.isInfinity())
20439 return false;
20440
20441 return p.getX().umod(this.n).cmp(r) === 0;
20442 }
20443
20444 // NOTE: Greg Maxwell's trick, inspired by:
20445 // https://git.io/vad3K
20446
20447 var p = this.g.jmulAdd(u1, key.getPublic(), u2);
20448 if (p.isInfinity())
20449 return false;
20450
20451 // Compare `p.x` of Jacobian point with `r`,
20452 // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
20453 // inverse of `p.z^2`
20454 return p.eqXToP(r);
20455 };
20456
20457 EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
20458 assert((3 & j) === j, 'The recovery param is more than two bits');
20459 signature = new Signature(signature, enc);
20460
20461 var n = this.n;
20462 var e = new BN(msg);
20463 var r = signature.r;
20464 var s = signature.s;
20465
20466 // A set LSB signifies that the y-coordinate is odd
20467 var isYOdd = j & 1;
20468 var isSecondKey = j >> 1;
20469 if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
20470 throw new Error('Unable to find sencond key candinate');
20471
20472 // 1.1. Let x = r + jn.
20473 if (isSecondKey)
20474 r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
20475 else
20476 r = this.curve.pointFromX(r, isYOdd);
20477
20478 var rInv = signature.r.invm(n);
20479 var s1 = n.sub(e).mul(rInv).umod(n);
20480 var s2 = s.mul(rInv).umod(n);
20481
20482 // 1.6.1 Compute Q = r^-1 (sR - eG)
20483 // Q = r^-1 (sR + -eG)
20484 return this.g.mulAdd(s1, r, s2);
20485 };
20486
20487 EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
20488 signature = new Signature(signature, enc);
20489 if (signature.recoveryParam !== null)
20490 return signature.recoveryParam;
20491
20492 for (var i = 0; i < 4; i++) {
20493 var Qprime;
20494 try {
20495 Qprime = this.recoverPubKey(e, signature, i);
20496 } catch (e) {
20497 continue;
20498 }
20499
20500 if (Qprime.eq(Q))
20501 return i;
20502 }
20503 throw new Error('Unable to find valid recovery factor');
20504 };
20505
20506 },{"../curves":135,"../utils":143,"./key":137,"./signature":138,"bn.js":79,"brorand":80,"hmac-drbg":160}],137:[function(require,module,exports){
20507 'use strict';
20508
20509 var BN = require('bn.js');
20510 var utils = require('../utils');
20511 var assert = utils.assert;
20512
20513 function KeyPair(ec, options) {
20514 this.ec = ec;
20515 this.priv = null;
20516 this.pub = null;
20517
20518 // KeyPair(ec, { priv: ..., pub: ... })
20519 if (options.priv)
20520 this._importPrivate(options.priv, options.privEnc);
20521 if (options.pub)
20522 this._importPublic(options.pub, options.pubEnc);
20523 }
20524 module.exports = KeyPair;
20525
20526 KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
20527 if (pub instanceof KeyPair)
20528 return pub;
20529
20530 return new KeyPair(ec, {
20531 pub: pub,
20532 pubEnc: enc
20533 });
20534 };
20535
20536 KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
20537 if (priv instanceof KeyPair)
20538 return priv;
20539
20540 return new KeyPair(ec, {
20541 priv: priv,
20542 privEnc: enc
20543 });
20544 };
20545
20546 KeyPair.prototype.validate = function validate() {
20547 var pub = this.getPublic();
20548
20549 if (pub.isInfinity())
20550 return { result: false, reason: 'Invalid public key' };
20551 if (!pub.validate())
20552 return { result: false, reason: 'Public key is not a point' };
20553 if (!pub.mul(this.ec.curve.n).isInfinity())
20554 return { result: false, reason: 'Public key * N != O' };
20555
20556 return { result: true, reason: null };
20557 };
20558
20559 KeyPair.prototype.getPublic = function getPublic(compact, enc) {
20560 // compact is optional argument
20561 if (typeof compact === 'string') {
20562 enc = compact;
20563 compact = null;
20564 }
20565
20566 if (!this.pub)
20567 this.pub = this.ec.g.mul(this.priv);
20568
20569 if (!enc)
20570 return this.pub;
20571
20572 return this.pub.encode(enc, compact);
20573 };
20574
20575 KeyPair.prototype.getPrivate = function getPrivate(enc) {
20576 if (enc === 'hex')
20577 return this.priv.toString(16, 2);
20578 else
20579 return this.priv;
20580 };
20581
20582 KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
20583 this.priv = new BN(key, enc || 16);
20584
20585 // Ensure that the priv won't be bigger than n, otherwise we may fail
20586 // in fixed multiplication method
20587 this.priv = this.priv.umod(this.ec.curve.n);
20588 };
20589
20590 KeyPair.prototype._importPublic = function _importPublic(key, enc) {
20591 if (key.x || key.y) {
20592 // Montgomery points only have an `x` coordinate.
20593 // Weierstrass/Edwards points on the other hand have both `x` and
20594 // `y` coordinates.
20595 if (this.ec.curve.type === 'mont') {
20596 assert(key.x, 'Need x coordinate');
20597 } else if (this.ec.curve.type === 'short' ||
20598 this.ec.curve.type === 'edwards') {
20599 assert(key.x && key.y, 'Need both x and y coordinate');
20600 }
20601 this.pub = this.ec.curve.point(key.x, key.y);
20602 return;
20603 }
20604 this.pub = this.ec.curve.decodePoint(key, enc);
20605 };
20606
20607 // ECDH
20608 KeyPair.prototype.derive = function derive(pub) {
20609 return pub.mul(this.priv).getX();
20610 };
20611
20612 // ECDSA
20613 KeyPair.prototype.sign = function sign(msg, enc, options) {
20614 return this.ec.sign(msg, this, enc, options);
20615 };
20616
20617 KeyPair.prototype.verify = function verify(msg, signature) {
20618 return this.ec.verify(msg, signature, this);
20619 };
20620
20621 KeyPair.prototype.inspect = function inspect() {
20622 return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
20623 ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
20624 };
20625
20626 },{"../utils":143,"bn.js":79}],138:[function(require,module,exports){
20627 'use strict';
20628
20629 var BN = require('bn.js');
20630
20631 var utils = require('../utils');
20632 var assert = utils.assert;
20633
20634 function Signature(options, enc) {
20635 if (options instanceof Signature)
20636 return options;
20637
20638 if (this._importDER(options, enc))
20639 return;
20640
20641 assert(options.r && options.s, 'Signature without r or s');
20642 this.r = new BN(options.r, 16);
20643 this.s = new BN(options.s, 16);
20644 if (options.recoveryParam === undefined)
20645 this.recoveryParam = null;
20646 else
20647 this.recoveryParam = options.recoveryParam;
20648 }
20649 module.exports = Signature;
20650
20651 function Position() {
20652 this.place = 0;
20653 }
20654
20655 function getLength(buf, p) {
20656 var initial = buf[p.place++];
20657 if (!(initial & 0x80)) {
20658 return initial;
20659 }
20660 var octetLen = initial & 0xf;
20661 var val = 0;
20662 for (var i = 0, off = p.place; i < octetLen; i++, off++) {
20663 val <<= 8;
20664 val |= buf[off];
20665 }
20666 p.place = off;
20667 return val;
20668 }
20669
20670 function rmPadding(buf) {
20671 var i = 0;
20672 var len = buf.length - 1;
20673 while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
20674 i++;
20675 }
20676 if (i === 0) {
20677 return buf;
20678 }
20679 return buf.slice(i);
20680 }
20681
20682 Signature.prototype._importDER = function _importDER(data, enc) {
20683 data = utils.toArray(data, enc);
20684 var p = new Position();
20685 if (data[p.place++] !== 0x30) {
20686 return false;
20687 }
20688 var len = getLength(data, p);
20689 if ((len + p.place) !== data.length) {
20690 return false;
20691 }
20692 if (data[p.place++] !== 0x02) {
20693 return false;
20694 }
20695 var rlen = getLength(data, p);
20696 var r = data.slice(p.place, rlen + p.place);
20697 p.place += rlen;
20698 if (data[p.place++] !== 0x02) {
20699 return false;
20700 }
20701 var slen = getLength(data, p);
20702 if (data.length !== slen + p.place) {
20703 return false;
20704 }
20705 var s = data.slice(p.place, slen + p.place);
20706 if (r[0] === 0 && (r[1] & 0x80)) {
20707 r = r.slice(1);
20708 }
20709 if (s[0] === 0 && (s[1] & 0x80)) {
20710 s = s.slice(1);
20711 }
20712
20713 this.r = new BN(r);
20714 this.s = new BN(s);
20715 this.recoveryParam = null;
20716
20717 return true;
20718 };
20719
20720 function constructLength(arr, len) {
20721 if (len < 0x80) {
20722 arr.push(len);
20723 return;
20724 }
20725 var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
20726 arr.push(octets | 0x80);
20727 while (--octets) {
20728 arr.push((len >>> (octets << 3)) & 0xff);
20729 }
20730 arr.push(len);
20731 }
20732
20733 Signature.prototype.toDER = function toDER(enc) {
20734 var r = this.r.toArray();
20735 var s = this.s.toArray();
20736
20737 // Pad values
20738 if (r[0] & 0x80)
20739 r = [ 0 ].concat(r);
20740 // Pad values
20741 if (s[0] & 0x80)
20742 s = [ 0 ].concat(s);
20743
20744 r = rmPadding(r);
20745 s = rmPadding(s);
20746
20747 while (!s[0] && !(s[1] & 0x80)) {
20748 s = s.slice(1);
20749 }
20750 var arr = [ 0x02 ];
20751 constructLength(arr, r.length);
20752 arr = arr.concat(r);
20753 arr.push(0x02);
20754 constructLength(arr, s.length);
20755 var backHalf = arr.concat(s);
20756 var res = [ 0x30 ];
20757 constructLength(res, backHalf.length);
20758 res = res.concat(backHalf);
20759 return utils.encode(res, enc);
20760 };
20761
20762 },{"../utils":143,"bn.js":79}],139:[function(require,module,exports){
20763 'use strict';
20764
20765 var hash = require('hash.js');
20766 var curves = require('../curves');
20767 var utils = require('../utils');
20768 var assert = utils.assert;
20769 var parseBytes = utils.parseBytes;
20770 var KeyPair = require('./key');
20771 var Signature = require('./signature');
20772
20773 function EDDSA(curve) {
20774 assert(curve === 'ed25519', 'only tested with ed25519 so far');
20775
20776 if (!(this instanceof EDDSA))
20777 return new EDDSA(curve);
20778
20779 var curve = curves[curve].curve;
20780 this.curve = curve;
20781 this.g = curve.g;
20782 this.g.precompute(curve.n.bitLength() + 1);
20783
20784 this.pointClass = curve.point().constructor;
20785 this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
20786 this.hash = hash.sha512;
20787 }
20788
20789 module.exports = EDDSA;
20790
20791 /**
20792 * @param {Array|String} message - message bytes
20793 * @param {Array|String|KeyPair} secret - secret bytes or a keypair
20794 * @returns {Signature} - signature
20795 */
20796 EDDSA.prototype.sign = function sign(message, secret) {
20797 message = parseBytes(message);
20798 var key = this.keyFromSecret(secret);
20799 var r = this.hashInt(key.messagePrefix(), message);
20800 var R = this.g.mul(r);
20801 var Rencoded = this.encodePoint(R);
20802 var s_ = this.hashInt(Rencoded, key.pubBytes(), message)
20803 .mul(key.priv());
20804 var S = r.add(s_).umod(this.curve.n);
20805 return this.makeSignature({ R: R, S: S, Rencoded: Rencoded });
20806 };
20807
20808 /**
20809 * @param {Array} message - message bytes
20810 * @param {Array|String|Signature} sig - sig bytes
20811 * @param {Array|String|Point|KeyPair} pub - public key
20812 * @returns {Boolean} - true if public key matches sig of message
20813 */
20814 EDDSA.prototype.verify = function verify(message, sig, pub) {
20815 message = parseBytes(message);
20816 sig = this.makeSignature(sig);
20817 var key = this.keyFromPublic(pub);
20818 var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
20819 var SG = this.g.mul(sig.S());
20820 var RplusAh = sig.R().add(key.pub().mul(h));
20821 return RplusAh.eq(SG);
20822 };
20823
20824 EDDSA.prototype.hashInt = function hashInt() {
20825 var hash = this.hash();
20826 for (var i = 0; i < arguments.length; i++)
20827 hash.update(arguments[i]);
20828 return utils.intFromLE(hash.digest()).umod(this.curve.n);
20829 };
20830
20831 EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
20832 return KeyPair.fromPublic(this, pub);
20833 };
20834
20835 EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
20836 return KeyPair.fromSecret(this, secret);
20837 };
20838
20839 EDDSA.prototype.makeSignature = function makeSignature(sig) {
20840 if (sig instanceof Signature)
20841 return sig;
20842 return new Signature(this, sig);
20843 };
20844
20845 /**
20846 * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
20847 *
20848 * EDDSA defines methods for encoding and decoding points and integers. These are
20849 * helper convenience methods, that pass along to utility functions implied
20850 * parameters.
20851 *
20852 */
20853 EDDSA.prototype.encodePoint = function encodePoint(point) {
20854 var enc = point.getY().toArray('le', this.encodingLength);
20855 enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
20856 return enc;
20857 };
20858
20859 EDDSA.prototype.decodePoint = function decodePoint(bytes) {
20860 bytes = utils.parseBytes(bytes);
20861
20862 var lastIx = bytes.length - 1;
20863 var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
20864 var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
20865
20866 var y = utils.intFromLE(normed);
20867 return this.curve.pointFromY(y, xIsOdd);
20868 };
20869
20870 EDDSA.prototype.encodeInt = function encodeInt(num) {
20871 return num.toArray('le', this.encodingLength);
20872 };
20873
20874 EDDSA.prototype.decodeInt = function decodeInt(bytes) {
20875 return utils.intFromLE(bytes);
20876 };
20877
20878 EDDSA.prototype.isPoint = function isPoint(val) {
20879 return val instanceof this.pointClass;
20880 };
20881
20882 },{"../curves":135,"../utils":143,"./key":140,"./signature":141,"hash.js":148}],140:[function(require,module,exports){
20883 'use strict';
20884
20885 var utils = require('../utils');
20886 var assert = utils.assert;
20887 var parseBytes = utils.parseBytes;
20888 var cachedProperty = utils.cachedProperty;
20889
20890 /**
20891 * @param {EDDSA} eddsa - instance
20892 * @param {Object} params - public/private key parameters
20893 *
20894 * @param {Array<Byte>} [params.secret] - secret seed bytes
20895 * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
20896 * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
20897 *
20898 */
20899 function KeyPair(eddsa, params) {
20900 this.eddsa = eddsa;
20901 this._secret = parseBytes(params.secret);
20902 if (eddsa.isPoint(params.pub))
20903 this._pub = params.pub;
20904 else
20905 this._pubBytes = parseBytes(params.pub);
20906 }
20907
20908 KeyPair.fromPublic = function fromPublic(eddsa, pub) {
20909 if (pub instanceof KeyPair)
20910 return pub;
20911 return new KeyPair(eddsa, { pub: pub });
20912 };
20913
20914 KeyPair.fromSecret = function fromSecret(eddsa, secret) {
20915 if (secret instanceof KeyPair)
20916 return secret;
20917 return new KeyPair(eddsa, { secret: secret });
20918 };
20919
20920 KeyPair.prototype.secret = function secret() {
20921 return this._secret;
20922 };
20923
20924 cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
20925 return this.eddsa.encodePoint(this.pub());
20926 });
20927
20928 cachedProperty(KeyPair, 'pub', function pub() {
20929 if (this._pubBytes)
20930 return this.eddsa.decodePoint(this._pubBytes);
20931 return this.eddsa.g.mul(this.priv());
20932 });
20933
20934 cachedProperty(KeyPair, 'privBytes', function privBytes() {
20935 var eddsa = this.eddsa;
20936 var hash = this.hash();
20937 var lastIx = eddsa.encodingLength - 1;
20938
20939 var a = hash.slice(0, eddsa.encodingLength);
20940 a[0] &= 248;
20941 a[lastIx] &= 127;
20942 a[lastIx] |= 64;
20943
20944 return a;
20945 });
20946
20947 cachedProperty(KeyPair, 'priv', function priv() {
20948 return this.eddsa.decodeInt(this.privBytes());
20949 });
20950
20951 cachedProperty(KeyPair, 'hash', function hash() {
20952 return this.eddsa.hash().update(this.secret()).digest();
20953 });
20954
20955 cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
20956 return this.hash().slice(this.eddsa.encodingLength);
20957 });
20958
20959 KeyPair.prototype.sign = function sign(message) {
20960 assert(this._secret, 'KeyPair can only verify');
20961 return this.eddsa.sign(message, this);
20962 };
20963
20964 KeyPair.prototype.verify = function verify(message, sig) {
20965 return this.eddsa.verify(message, sig, this);
20966 };
20967
20968 KeyPair.prototype.getSecret = function getSecret(enc) {
20969 assert(this._secret, 'KeyPair is public only');
20970 return utils.encode(this.secret(), enc);
20971 };
20972
20973 KeyPair.prototype.getPublic = function getPublic(enc) {
20974 return utils.encode(this.pubBytes(), enc);
20975 };
20976
20977 module.exports = KeyPair;
20978
20979 },{"../utils":143}],141:[function(require,module,exports){
20980 'use strict';
20981
20982 var BN = require('bn.js');
20983 var utils = require('../utils');
20984 var assert = utils.assert;
20985 var cachedProperty = utils.cachedProperty;
20986 var parseBytes = utils.parseBytes;
20987
20988 /**
20989 * @param {EDDSA} eddsa - eddsa instance
20990 * @param {Array<Bytes>|Object} sig -
20991 * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
20992 * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
20993 * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
20994 * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
20995 */
20996 function Signature(eddsa, sig) {
20997 this.eddsa = eddsa;
20998
20999 if (typeof sig !== 'object')
21000 sig = parseBytes(sig);
21001
21002 if (Array.isArray(sig)) {
21003 sig = {
21004 R: sig.slice(0, eddsa.encodingLength),
21005 S: sig.slice(eddsa.encodingLength)
21006 };
21007 }
21008
21009 assert(sig.R && sig.S, 'Signature without R or S');
21010
21011 if (eddsa.isPoint(sig.R))
21012 this._R = sig.R;
21013 if (sig.S instanceof BN)
21014 this._S = sig.S;
21015
21016 this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
21017 this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
21018 }
21019
21020 cachedProperty(Signature, 'S', function S() {
21021 return this.eddsa.decodeInt(this.Sencoded());
21022 });
21023
21024 cachedProperty(Signature, 'R', function R() {
21025 return this.eddsa.decodePoint(this.Rencoded());
21026 });
21027
21028 cachedProperty(Signature, 'Rencoded', function Rencoded() {
21029 return this.eddsa.encodePoint(this.R());
21030 });
21031
21032 cachedProperty(Signature, 'Sencoded', function Sencoded() {
21033 return this.eddsa.encodeInt(this.S());
21034 });
21035
21036 Signature.prototype.toBytes = function toBytes() {
21037 return this.Rencoded().concat(this.Sencoded());
21038 };
21039
21040 Signature.prototype.toHex = function toHex() {
21041 return utils.encode(this.toBytes(), 'hex').toUpperCase();
21042 };
21043
21044 module.exports = Signature;
21045
21046 },{"../utils":143,"bn.js":79}],142:[function(require,module,exports){
21047 module.exports = {
21048 doubles: {
21049 step: 4,
21050 points: [
21051 [
21052 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
21053 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
21054 ],
21055 [
21056 '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
21057 '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
21058 ],
21059 [
21060 '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
21061 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
21062 ],
21063 [
21064 '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
21065 '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
21066 ],
21067 [
21068 '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
21069 '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
21070 ],
21071 [
21072 '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
21073 '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
21074 ],
21075 [
21076 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
21077 '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
21078 ],
21079 [
21080 '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
21081 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
21082 ],
21083 [
21084 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
21085 '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
21086 ],
21087 [
21088 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
21089 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
21090 ],
21091 [
21092 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
21093 '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
21094 ],
21095 [
21096 '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
21097 '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
21098 ],
21099 [
21100 '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
21101 '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
21102 ],
21103 [
21104 '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
21105 '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
21106 ],
21107 [
21108 '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
21109 '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
21110 ],
21111 [
21112 '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
21113 '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
21114 ],
21115 [
21116 '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
21117 '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
21118 ],
21119 [
21120 '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
21121 '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
21122 ],
21123 [
21124 '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
21125 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
21126 ],
21127 [
21128 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
21129 '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
21130 ],
21131 [
21132 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
21133 '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
21134 ],
21135 [
21136 '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
21137 '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
21138 ],
21139 [
21140 '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
21141 '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
21142 ],
21143 [
21144 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
21145 '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
21146 ],
21147 [
21148 '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
21149 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
21150 ],
21151 [
21152 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
21153 '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
21154 ],
21155 [
21156 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
21157 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
21158 ],
21159 [
21160 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
21161 '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
21162 ],
21163 [
21164 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
21165 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
21166 ],
21167 [
21168 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
21169 '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
21170 ],
21171 [
21172 '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
21173 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
21174 ],
21175 [
21176 '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
21177 '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
21178 ],
21179 [
21180 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
21181 '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
21182 ],
21183 [
21184 '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
21185 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
21186 ],
21187 [
21188 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
21189 '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
21190 ],
21191 [
21192 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
21193 '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
21194 ],
21195 [
21196 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
21197 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
21198 ],
21199 [
21200 '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
21201 '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
21202 ],
21203 [
21204 '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
21205 '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
21206 ],
21207 [
21208 '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
21209 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
21210 ],
21211 [
21212 '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
21213 '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
21214 ],
21215 [
21216 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
21217 '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
21218 ],
21219 [
21220 '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
21221 '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
21222 ],
21223 [
21224 '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
21225 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
21226 ],
21227 [
21228 '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
21229 '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
21230 ],
21231 [
21232 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
21233 '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
21234 ],
21235 [
21236 '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
21237 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
21238 ],
21239 [
21240 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
21241 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
21242 ],
21243 [
21244 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
21245 '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
21246 ],
21247 [
21248 '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
21249 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
21250 ],
21251 [
21252 '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
21253 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
21254 ],
21255 [
21256 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
21257 '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
21258 ],
21259 [
21260 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
21261 '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
21262 ],
21263 [
21264 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
21265 '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
21266 ],
21267 [
21268 '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
21269 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
21270 ],
21271 [
21272 '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
21273 '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
21274 ],
21275 [
21276 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
21277 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
21278 ],
21279 [
21280 '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
21281 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
21282 ],
21283 [
21284 '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
21285 '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
21286 ],
21287 [
21288 '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
21289 '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
21290 ],
21291 [
21292 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
21293 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
21294 ],
21295 [
21296 '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
21297 '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
21298 ],
21299 [
21300 '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
21301 '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
21302 ],
21303 [
21304 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
21305 '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
21306 ],
21307 [
21308 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
21309 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
21310 ]
21311 ]
21312 },
21313 naf: {
21314 wnd: 7,
21315 points: [
21316 [
21317 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
21318 '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
21319 ],
21320 [
21321 '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
21322 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
21323 ],
21324 [
21325 '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
21326 '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
21327 ],
21328 [
21329 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
21330 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
21331 ],
21332 [
21333 '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
21334 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
21335 ],
21336 [
21337 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
21338 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
21339 ],
21340 [
21341 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
21342 '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
21343 ],
21344 [
21345 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
21346 '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
21347 ],
21348 [
21349 '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
21350 '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
21351 ],
21352 [
21353 '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
21354 '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
21355 ],
21356 [
21357 '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
21358 '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
21359 ],
21360 [
21361 '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
21362 '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
21363 ],
21364 [
21365 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
21366 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
21367 ],
21368 [
21369 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
21370 '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
21371 ],
21372 [
21373 '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
21374 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
21375 ],
21376 [
21377 '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
21378 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
21379 ],
21380 [
21381 '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
21382 '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
21383 ],
21384 [
21385 '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
21386 '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
21387 ],
21388 [
21389 '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
21390 '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
21391 ],
21392 [
21393 '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
21394 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
21395 ],
21396 [
21397 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
21398 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
21399 ],
21400 [
21401 '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
21402 '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
21403 ],
21404 [
21405 '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
21406 '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
21407 ],
21408 [
21409 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
21410 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
21411 ],
21412 [
21413 '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
21414 '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
21415 ],
21416 [
21417 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
21418 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
21419 ],
21420 [
21421 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
21422 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
21423 ],
21424 [
21425 '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
21426 '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
21427 ],
21428 [
21429 '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
21430 '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
21431 ],
21432 [
21433 '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
21434 '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
21435 ],
21436 [
21437 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
21438 '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
21439 ],
21440 [
21441 '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
21442 '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
21443 ],
21444 [
21445 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
21446 '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
21447 ],
21448 [
21449 '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
21450 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
21451 ],
21452 [
21453 '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
21454 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
21455 ],
21456 [
21457 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
21458 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
21459 ],
21460 [
21461 '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
21462 '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
21463 ],
21464 [
21465 '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
21466 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
21467 ],
21468 [
21469 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
21470 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
21471 ],
21472 [
21473 '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
21474 '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
21475 ],
21476 [
21477 '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
21478 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
21479 ],
21480 [
21481 '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
21482 '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
21483 ],
21484 [
21485 '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
21486 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
21487 ],
21488 [
21489 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
21490 '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
21491 ],
21492 [
21493 '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
21494 '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
21495 ],
21496 [
21497 '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
21498 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
21499 ],
21500 [
21501 '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
21502 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
21503 ],
21504 [
21505 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
21506 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
21507 ],
21508 [
21509 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
21510 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
21511 ],
21512 [
21513 '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
21514 '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
21515 ],
21516 [
21517 '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
21518 '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
21519 ],
21520 [
21521 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
21522 '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
21523 ],
21524 [
21525 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
21526 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
21527 ],
21528 [
21529 '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
21530 '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
21531 ],
21532 [
21533 '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
21534 '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
21535 ],
21536 [
21537 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
21538 '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
21539 ],
21540 [
21541 '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
21542 '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
21543 ],
21544 [
21545 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
21546 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
21547 ],
21548 [
21549 '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
21550 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
21551 ],
21552 [
21553 '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
21554 '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
21555 ],
21556 [
21557 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
21558 '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
21559 ],
21560 [
21561 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
21562 '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
21563 ],
21564 [
21565 '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
21566 '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
21567 ],
21568 [
21569 '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
21570 '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
21571 ],
21572 [
21573 '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
21574 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
21575 ],
21576 [
21577 '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
21578 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
21579 ],
21580 [
21581 '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
21582 '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
21583 ],
21584 [
21585 '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
21586 '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
21587 ],
21588 [
21589 '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
21590 '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
21591 ],
21592 [
21593 '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
21594 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
21595 ],
21596 [
21597 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
21598 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
21599 ],
21600 [
21601 '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
21602 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
21603 ],
21604 [
21605 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
21606 '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
21607 ],
21608 [
21609 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
21610 '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
21611 ],
21612 [
21613 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
21614 '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
21615 ],
21616 [
21617 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
21618 '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
21619 ],
21620 [
21621 '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
21622 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
21623 ],
21624 [
21625 '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
21626 '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
21627 ],
21628 [
21629 '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
21630 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
21631 ],
21632 [
21633 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
21634 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
21635 ],
21636 [
21637 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
21638 '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
21639 ],
21640 [
21641 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
21642 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
21643 ],
21644 [
21645 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
21646 '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
21647 ],
21648 [
21649 '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
21650 '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
21651 ],
21652 [
21653 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
21654 '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
21655 ],
21656 [
21657 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
21658 '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
21659 ],
21660 [
21661 '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
21662 '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
21663 ],
21664 [
21665 '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
21666 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
21667 ],
21668 [
21669 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
21670 '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
21671 ],
21672 [
21673 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
21674 '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
21675 ],
21676 [
21677 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
21678 '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
21679 ],
21680 [
21681 '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
21682 '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
21683 ],
21684 [
21685 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
21686 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
21687 ],
21688 [
21689 '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
21690 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
21691 ],
21692 [
21693 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
21694 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
21695 ],
21696 [
21697 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
21698 '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
21699 ],
21700 [
21701 '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
21702 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
21703 ],
21704 [
21705 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
21706 '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
21707 ],
21708 [
21709 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
21710 '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
21711 ],
21712 [
21713 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
21714 '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
21715 ],
21716 [
21717 '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
21718 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
21719 ],
21720 [
21721 '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
21722 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
21723 ],
21724 [
21725 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
21726 '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
21727 ],
21728 [
21729 '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
21730 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
21731 ],
21732 [
21733 '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
21734 '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
21735 ],
21736 [
21737 '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
21738 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
21739 ],
21740 [
21741 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
21742 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
21743 ],
21744 [
21745 '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
21746 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
21747 ],
21748 [
21749 '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
21750 '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
21751 ],
21752 [
21753 '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
21754 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
21755 ],
21756 [
21757 '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
21758 '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
21759 ],
21760 [
21761 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
21762 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
21763 ],
21764 [
21765 '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
21766 '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
21767 ],
21768 [
21769 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
21770 '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
21771 ],
21772 [
21773 '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
21774 '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
21775 ],
21776 [
21777 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
21778 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
21779 ],
21780 [
21781 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
21782 '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
21783 ],
21784 [
21785 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
21786 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
21787 ],
21788 [
21789 '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
21790 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
21791 ],
21792 [
21793 '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
21794 '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
21795 ],
21796 [
21797 '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
21798 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
21799 ],
21800 [
21801 '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
21802 '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
21803 ],
21804 [
21805 '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
21806 '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
21807 ],
21808 [
21809 '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
21810 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
21811 ],
21812 [
21813 '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
21814 '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
21815 ],
21816 [
21817 '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
21818 '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
21819 ],
21820 [
21821 '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
21822 '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
21823 ]
21824 ]
21825 }
21826 };
21827
21828 },{}],143:[function(require,module,exports){
21829 'use strict';
21830
21831 var utils = exports;
21832 var BN = require('bn.js');
21833 var minAssert = require('minimalistic-assert');
21834 var minUtils = require('minimalistic-crypto-utils');
21835
21836 utils.assert = minAssert;
21837 utils.toArray = minUtils.toArray;
21838 utils.zero2 = minUtils.zero2;
21839 utils.toHex = minUtils.toHex;
21840 utils.encode = minUtils.encode;
21841
21842 // Represent num in a w-NAF form
21843 function getNAF(num, w) {
21844 var naf = [];
21845 var ws = 1 << (w + 1);
21846 var k = num.clone();
21847 while (k.cmpn(1) >= 0) {
21848 var z;
21849 if (k.isOdd()) {
21850 var mod = k.andln(ws - 1);
21851 if (mod > (ws >> 1) - 1)
21852 z = (ws >> 1) - mod;
21853 else
21854 z = mod;
21855 k.isubn(z);
21856 } else {
21857 z = 0;
21858 }
21859 naf.push(z);
21860
21861 // Optimization, shift by word if possible
21862 var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
21863 for (var i = 1; i < shift; i++)
21864 naf.push(0);
21865 k.iushrn(shift);
21866 }
21867
21868 return naf;
21869 }
21870 utils.getNAF = getNAF;
21871
21872 // Represent k1, k2 in a Joint Sparse Form
21873 function getJSF(k1, k2) {
21874 var jsf = [
21875 [],
21876 []
21877 ];
21878
21879 k1 = k1.clone();
21880 k2 = k2.clone();
21881 var d1 = 0;
21882 var d2 = 0;
21883 while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
21884
21885 // First phase
21886 var m14 = (k1.andln(3) + d1) & 3;
21887 var m24 = (k2.andln(3) + d2) & 3;
21888 if (m14 === 3)
21889 m14 = -1;
21890 if (m24 === 3)
21891 m24 = -1;
21892 var u1;
21893 if ((m14 & 1) === 0) {
21894 u1 = 0;
21895 } else {
21896 var m8 = (k1.andln(7) + d1) & 7;
21897 if ((m8 === 3 || m8 === 5) && m24 === 2)
21898 u1 = -m14;
21899 else
21900 u1 = m14;
21901 }
21902 jsf[0].push(u1);
21903
21904 var u2;
21905 if ((m24 & 1) === 0) {
21906 u2 = 0;
21907 } else {
21908 var m8 = (k2.andln(7) + d2) & 7;
21909 if ((m8 === 3 || m8 === 5) && m14 === 2)
21910 u2 = -m24;
21911 else
21912 u2 = m24;
21913 }
21914 jsf[1].push(u2);
21915
21916 // Second phase
21917 if (2 * d1 === u1 + 1)
21918 d1 = 1 - d1;
21919 if (2 * d2 === u2 + 1)
21920 d2 = 1 - d2;
21921 k1.iushrn(1);
21922 k2.iushrn(1);
21923 }
21924
21925 return jsf;
21926 }
21927 utils.getJSF = getJSF;
21928
21929 function cachedProperty(obj, name, computer) {
21930 var key = '_' + name;
21931 obj.prototype[name] = function cachedProperty() {
21932 return this[key] !== undefined ? this[key] :
21933 this[key] = computer.call(this);
21934 };
21935 }
21936 utils.cachedProperty = cachedProperty;
21937
21938 function parseBytes(bytes) {
21939 return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
21940 bytes;
21941 }
21942 utils.parseBytes = parseBytes;
21943
21944 function intFromLE(bytes) {
21945 return new BN(bytes, 'hex', 'le');
21946 }
21947 utils.intFromLE = intFromLE;
21948
21949
21950 },{"bn.js":79,"minimalistic-assert":167,"minimalistic-crypto-utils":168}],144:[function(require,module,exports){
21951 module.exports={
21952 "_args": [
21953 [
21954 "elliptic@^6.0.0",
21955 "/usr/local/lib/node_modules/browserify/node_modules/browserify-sign"
21956 ]
21957 ],
21958 "_from": "elliptic@>=6.0.0 <7.0.0",
21959 "_hasShrinkwrap": false,
21960 "_id": "elliptic@6.5.0",
21961 "_inCache": true,
21962 "_installable": true,
21963 "_location": "/browserify/elliptic",
21964 "_nodeVersion": "12.2.0",
21965 "_npmOperationalInternal": {
21966 "host": "s3://npm-registry-packages",
21967 "tmp": "tmp/elliptic_6.5.0_1561521826385_0.20848274510512943"
21968 },
21969 "_npmUser": {
21970 "email": "fedor@indutny.com",
21971 "name": "indutny"
21972 },
21973 "_npmVersion": "6.9.0",
21974 "_phantomChildren": {},
21975 "_requested": {
21976 "name": "elliptic",
21977 "raw": "elliptic@^6.0.0",
21978 "rawSpec": "^6.0.0",
21979 "scope": null,
21980 "spec": ">=6.0.0 <7.0.0",
21981 "type": "range"
21982 },
21983 "_requiredBy": [
21984 "/browserify/browserify-sign",
21985 "/browserify/create-ecdh"
21986 ],
21987 "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz",
21988 "_shasum": "2b8ed4c891b7de3200e14412a5b8248c7af505ca",
21989 "_shrinkwrap": null,
21990 "_spec": "elliptic@^6.0.0",
21991 "_where": "/usr/local/lib/node_modules/browserify/node_modules/browserify-sign",
21992 "author": {
21993 "email": "fedor@indutny.com",
21994 "name": "Fedor Indutny"
21995 },
21996 "bugs": {
21997 "url": "https://github.com/indutny/elliptic/issues"
21998 },
21999 "dependencies": {
22000 "bn.js": "^4.4.0",
22001 "brorand": "^1.0.1",
22002 "hash.js": "^1.0.0",
22003 "hmac-drbg": "^1.0.0",
22004 "inherits": "^2.0.1",
22005 "minimalistic-assert": "^1.0.0",
22006 "minimalistic-crypto-utils": "^1.0.0"
22007 },
22008 "description": "EC cryptography",
22009 "devDependencies": {
22010 "brfs": "^1.4.3",
22011 "coveralls": "^2.11.3",
22012 "grunt": "^0.4.5",
22013 "grunt-browserify": "^5.0.0",
22014 "grunt-cli": "^1.2.0",
22015 "grunt-contrib-connect": "^1.0.0",
22016 "grunt-contrib-copy": "^1.0.0",
22017 "grunt-contrib-uglify": "^1.0.1",
22018 "grunt-mocha-istanbul": "^3.0.1",
22019 "grunt-saucelabs": "^8.6.2",
22020 "istanbul": "^0.4.2",
22021 "jscs": "^2.9.0",
22022 "jshint": "^2.6.0",
22023 "mocha": "^2.1.0"
22024 },
22025 "directories": {},
22026 "dist": {
22027 "fileCount": 17,
22028 "integrity": "sha512-eFOJTMyCYb7xtE/caJ6JJu+bhi67WCYNbkGSknu20pmM8Ke/bqOfdnZWxyoGN26JgfxTbXrsCkEw4KheCT/KGg==",
22029 "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdEu6jCRA9TVsSAnZWagAAJh4QAJXJ18MReidNMHrxFJGv\ngSONMB2uz0lWJ7eEUyggaCA/Tr6w4RBA6Ilne0Wou3jTAGou+GClpAde6Hkb\nEq1iq1brx+5gHeY3rGs8GB+T3c1JsVz+2t6934esXGM6IJNmG91TaCMSbuwQ\nTWHD62RxFylLYjffBIWt6KLximZnXcvAES0Qu7VUql1SlfvmGtaHlQAhvtLj\nG+ayBnSnWMcEvDPJdfnKi67PlGMa334spEmWzcqobFySr+y/ufiZRCp+wiSl\ndCwbFNMaH4fue+dhq1m7jGO/euFQvJw2Jf32zT/ToaM768nH8yHrrZ8lMRjs\ngCUymge8kbI5W1WA8wla7+J52Exbo6LbcBqSupVhVw6gXkOdjQCOkywBXa1c\nPiFxwOUSfdFATpkUi3/8serYCgv9NgGzvQ0rjej0//1+he6q7UUyKn9wyrdH\nMntmi18UgyQ8c1NrshKAOCb1oeniCEv7B1adfH2axH9uvMiVP8N5BMfAUNE1\nnkCD3lDXRz/7C+90DiI+h2MS3+az8ciqMTbpKlw3HrmUyCex+KvLq9+wNLGf\nyaJGd/r6NT0pu36v0M2+ul266/RbbY6D1ED/cl8gDZRFTT/SfTCkU+QAn2Mg\nfAlnn9BXogYR1XM1GNrnGUVkY7ngORiAGez5DU7P93jMpdSS9OtwAHHi1Oto\nbZ+X\r\n=LuMF\r\n-----END PGP SIGNATURE-----\r\n",
22030 "shasum": "2b8ed4c891b7de3200e14412a5b8248c7af505ca",
22031 "tarball": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.0.tgz",
22032 "unpackedSize": 118006
22033 },
22034 "gitHead": "475f066aebd14681591f0f0f18a2abc0ded8c390",
22035 "homepage": "https://github.com/indutny/elliptic",
22036 "keywords": [
22037 "Cryptography",
22038 "EC",
22039 "Elliptic",
22040 "curve"
22041 ],
22042 "license": "MIT",
22043 "main": "lib/elliptic.js",
22044 "maintainers": [
22045 {
22046 "name": "indutny",
22047 "email": "fedor@indutny.com"
22048 }
22049 ],
22050 "name": "elliptic",
22051 "optionalDependencies": {},
22052 "readme": "ERROR: No README data found!",
22053 "repository": {
22054 "type": "git",
22055 "url": "git+ssh://git@github.com/indutny/elliptic.git"
22056 },
22057 "scripts": {
22058 "jscs": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
22059 "jshint": "jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",
22060 "lint": "npm run jscs && npm run jshint",
22061 "test": "npm run lint && npm run unit",
22062 "unit": "istanbul test _mocha --reporter=spec test/index.js",
22063 "version": "grunt dist && git add dist/"
22064 },
22065 "version": "6.5.0"
22066 }
22067
22068 },{}],145:[function(require,module,exports){
22069 // Copyright Joyent, Inc. and other Node contributors.
22070 //
22071 // Permission is hereby granted, free of charge, to any person obtaining a
22072 // copy of this software and associated documentation files (the
22073 // "Software"), to deal in the Software without restriction, including
22074 // without limitation the rights to use, copy, modify, merge, publish,
22075 // distribute, sublicense, and/or sell copies of the Software, and to permit
22076 // persons to whom the Software is furnished to do so, subject to the
22077 // following conditions:
22078 //
22079 // The above copyright notice and this permission notice shall be included
22080 // in all copies or substantial portions of the Software.
22081 //
22082 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22083 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22084 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
22085 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22086 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22087 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22088 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22089
22090 var objectCreate = Object.create || objectCreatePolyfill
22091 var objectKeys = Object.keys || objectKeysPolyfill
22092 var bind = Function.prototype.bind || functionBindPolyfill
22093
22094 function EventEmitter() {
22095 if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
22096 this._events = objectCreate(null);
22097 this._eventsCount = 0;
22098 }
22099
22100 this._maxListeners = this._maxListeners || undefined;
22101 }
22102 module.exports = EventEmitter;
22103
22104 // Backwards-compat with node 0.10.x
22105 EventEmitter.EventEmitter = EventEmitter;
22106
22107 EventEmitter.prototype._events = undefined;
22108 EventEmitter.prototype._maxListeners = undefined;
22109
22110 // By default EventEmitters will print a warning if more than 10 listeners are
22111 // added to it. This is a useful default which helps finding memory leaks.
22112 var defaultMaxListeners = 10;
22113
22114 var hasDefineProperty;
22115 try {
22116 var o = {};
22117 if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
22118 hasDefineProperty = o.x === 0;
22119 } catch (err) { hasDefineProperty = false }
22120 if (hasDefineProperty) {
22121 Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
22122 enumerable: true,
22123 get: function() {
22124 return defaultMaxListeners;
22125 },
22126 set: function(arg) {
22127 // check whether the input is a positive number (whose value is zero or
22128 // greater and not a NaN).
22129 if (typeof arg !== 'number' || arg < 0 || arg !== arg)
22130 throw new TypeError('"defaultMaxListeners" must be a positive number');
22131 defaultMaxListeners = arg;
22132 }
22133 });
22134 } else {
22135 EventEmitter.defaultMaxListeners = defaultMaxListeners;
22136 }
22137
22138 // Obviously not all Emitters should be limited to 10. This function allows
22139 // that to be increased. Set to zero for unlimited.
22140 EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
22141 if (typeof n !== 'number' || n < 0 || isNaN(n))
22142 throw new TypeError('"n" argument must be a positive number');
22143 this._maxListeners = n;
22144 return this;
22145 };
22146
22147 function $getMaxListeners(that) {
22148 if (that._maxListeners === undefined)
22149 return EventEmitter.defaultMaxListeners;
22150 return that._maxListeners;
22151 }
22152
22153 EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
22154 return $getMaxListeners(this);
22155 };
22156
22157 // These standalone emit* functions are used to optimize calling of event
22158 // handlers for fast cases because emit() itself often has a variable number of
22159 // arguments and can be deoptimized because of that. These functions always have
22160 // the same number of arguments and thus do not get deoptimized, so the code
22161 // inside them can execute faster.
22162 function emitNone(handler, isFn, self) {
22163 if (isFn)
22164 handler.call(self);
22165 else {
22166 var len = handler.length;
22167 var listeners = arrayClone(handler, len);
22168 for (var i = 0; i < len; ++i)
22169 listeners[i].call(self);
22170 }
22171 }
22172 function emitOne(handler, isFn, self, arg1) {
22173 if (isFn)
22174 handler.call(self, arg1);
22175 else {
22176 var len = handler.length;
22177 var listeners = arrayClone(handler, len);
22178 for (var i = 0; i < len; ++i)
22179 listeners[i].call(self, arg1);
22180 }
22181 }
22182 function emitTwo(handler, isFn, self, arg1, arg2) {
22183 if (isFn)
22184 handler.call(self, arg1, arg2);
22185 else {
22186 var len = handler.length;
22187 var listeners = arrayClone(handler, len);
22188 for (var i = 0; i < len; ++i)
22189 listeners[i].call(self, arg1, arg2);
22190 }
22191 }
22192 function emitThree(handler, isFn, self, arg1, arg2, arg3) {
22193 if (isFn)
22194 handler.call(self, arg1, arg2, arg3);
22195 else {
22196 var len = handler.length;
22197 var listeners = arrayClone(handler, len);
22198 for (var i = 0; i < len; ++i)
22199 listeners[i].call(self, arg1, arg2, arg3);
22200 }
22201 }
22202
22203 function emitMany(handler, isFn, self, args) {
22204 if (isFn)
22205 handler.apply(self, args);
22206 else {
22207 var len = handler.length;
22208 var listeners = arrayClone(handler, len);
22209 for (var i = 0; i < len; ++i)
22210 listeners[i].apply(self, args);
22211 }
22212 }
22213
22214 EventEmitter.prototype.emit = function emit(type) {
22215 var er, handler, len, args, i, events;
22216 var doError = (type === 'error');
22217
22218 events = this._events;
22219 if (events)
22220 doError = (doError && events.error == null);
22221 else if (!doError)
22222 return false;
22223
22224 // If there is no 'error' event listener then throw.
22225 if (doError) {
22226 if (arguments.length > 1)
22227 er = arguments[1];
22228 if (er instanceof Error) {
22229 throw er; // Unhandled 'error' event
22230 } else {
22231 // At least give some kind of context to the user
22232 var err = new Error('Unhandled "error" event. (' + er + ')');
22233 err.context = er;
22234 throw err;
22235 }
22236 return false;
22237 }
22238
22239 handler = events[type];
22240
22241 if (!handler)
22242 return false;
22243
22244 var isFn = typeof handler === 'function';
22245 len = arguments.length;
22246 switch (len) {
22247 // fast cases
22248 case 1:
22249 emitNone(handler, isFn, this);
22250 break;
22251 case 2:
22252 emitOne(handler, isFn, this, arguments[1]);
22253 break;
22254 case 3:
22255 emitTwo(handler, isFn, this, arguments[1], arguments[2]);
22256 break;
22257 case 4:
22258 emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
22259 break;
22260 // slower
22261 default:
22262 args = new Array(len - 1);
22263 for (i = 1; i < len; i++)
22264 args[i - 1] = arguments[i];
22265 emitMany(handler, isFn, this, args);
22266 }
22267
22268 return true;
22269 };
22270
22271 function _addListener(target, type, listener, prepend) {
22272 var m;
22273 var events;
22274 var existing;
22275
22276 if (typeof listener !== 'function')
22277 throw new TypeError('"listener" argument must be a function');
22278
22279 events = target._events;
22280 if (!events) {
22281 events = target._events = objectCreate(null);
22282 target._eventsCount = 0;
22283 } else {
22284 // To avoid recursion in the case that type === "newListener"! Before
22285 // adding it to the listeners, first emit "newListener".
22286 if (events.newListener) {
22287 target.emit('newListener', type,
22288 listener.listener ? listener.listener : listener);
22289
22290 // Re-assign `events` because a newListener handler could have caused the
22291 // this._events to be assigned to a new object
22292 events = target._events;
22293 }
22294 existing = events[type];
22295 }
22296
22297 if (!existing) {
22298 // Optimize the case of one listener. Don't need the extra array object.
22299 existing = events[type] = listener;
22300 ++target._eventsCount;
22301 } else {
22302 if (typeof existing === 'function') {
22303 // Adding the second element, need to change to array.
22304 existing = events[type] =
22305 prepend ? [listener, existing] : [existing, listener];
22306 } else {
22307 // If we've already got an array, just append.
22308 if (prepend) {
22309 existing.unshift(listener);
22310 } else {
22311 existing.push(listener);
22312 }
22313 }
22314
22315 // Check for listener leak
22316 if (!existing.warned) {
22317 m = $getMaxListeners(target);
22318 if (m && m > 0 && existing.length > m) {
22319 existing.warned = true;
22320 var w = new Error('Possible EventEmitter memory leak detected. ' +
22321 existing.length + ' "' + String(type) + '" listeners ' +
22322 'added. Use emitter.setMaxListeners() to ' +
22323 'increase limit.');
22324 w.name = 'MaxListenersExceededWarning';
22325 w.emitter = target;
22326 w.type = type;
22327 w.count = existing.length;
22328 if (typeof console === 'object' && console.warn) {
22329 console.warn('%s: %s', w.name, w.message);
22330 }
22331 }
22332 }
22333 }
22334
22335 return target;
22336 }
22337
22338 EventEmitter.prototype.addListener = function addListener(type, listener) {
22339 return _addListener(this, type, listener, false);
22340 };
22341
22342 EventEmitter.prototype.on = EventEmitter.prototype.addListener;
22343
22344 EventEmitter.prototype.prependListener =
22345 function prependListener(type, listener) {
22346 return _addListener(this, type, listener, true);
22347 };
22348
22349 function onceWrapper() {
22350 if (!this.fired) {
22351 this.target.removeListener(this.type, this.wrapFn);
22352 this.fired = true;
22353 switch (arguments.length) {
22354 case 0:
22355 return this.listener.call(this.target);
22356 case 1:
22357 return this.listener.call(this.target, arguments[0]);
22358 case 2:
22359 return this.listener.call(this.target, arguments[0], arguments[1]);
22360 case 3:
22361 return this.listener.call(this.target, arguments[0], arguments[1],
22362 arguments[2]);
22363 default:
22364 var args = new Array(arguments.length);
22365 for (var i = 0; i < args.length; ++i)
22366 args[i] = arguments[i];
22367 this.listener.apply(this.target, args);
22368 }
22369 }
22370 }
22371
22372 function _onceWrap(target, type, listener) {
22373 var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
22374 var wrapped = bind.call(onceWrapper, state);
22375 wrapped.listener = listener;
22376 state.wrapFn = wrapped;
22377 return wrapped;
22378 }
22379
22380 EventEmitter.prototype.once = function once(type, listener) {
22381 if (typeof listener !== 'function')
22382 throw new TypeError('"listener" argument must be a function');
22383 this.on(type, _onceWrap(this, type, listener));
22384 return this;
22385 };
22386
22387 EventEmitter.prototype.prependOnceListener =
22388 function prependOnceListener(type, listener) {
22389 if (typeof listener !== 'function')
22390 throw new TypeError('"listener" argument must be a function');
22391 this.prependListener(type, _onceWrap(this, type, listener));
22392 return this;
22393 };
22394
22395 // Emits a 'removeListener' event if and only if the listener was removed.
22396 EventEmitter.prototype.removeListener =
22397 function removeListener(type, listener) {
22398 var list, events, position, i, originalListener;
22399
22400 if (typeof listener !== 'function')
22401 throw new TypeError('"listener" argument must be a function');
22402
22403 events = this._events;
22404 if (!events)
22405 return this;
22406
22407 list = events[type];
22408 if (!list)
22409 return this;
22410
22411 if (list === listener || list.listener === listener) {
22412 if (--this._eventsCount === 0)
22413 this._events = objectCreate(null);
22414 else {
22415 delete events[type];
22416 if (events.removeListener)
22417 this.emit('removeListener', type, list.listener || listener);
22418 }
22419 } else if (typeof list !== 'function') {
22420 position = -1;
22421
22422 for (i = list.length - 1; i >= 0; i--) {
22423 if (list[i] === listener || list[i].listener === listener) {
22424 originalListener = list[i].listener;
22425 position = i;
22426 break;
22427 }
22428 }
22429
22430 if (position < 0)
22431 return this;
22432
22433 if (position === 0)
22434 list.shift();
22435 else
22436 spliceOne(list, position);
22437
22438 if (list.length === 1)
22439 events[type] = list[0];
22440
22441 if (events.removeListener)
22442 this.emit('removeListener', type, originalListener || listener);
22443 }
22444
22445 return this;
22446 };
22447
22448 EventEmitter.prototype.removeAllListeners =
22449 function removeAllListeners(type) {
22450 var listeners, events, i;
22451
22452 events = this._events;
22453 if (!events)
22454 return this;
22455
22456 // not listening for removeListener, no need to emit
22457 if (!events.removeListener) {
22458 if (arguments.length === 0) {
22459 this._events = objectCreate(null);
22460 this._eventsCount = 0;
22461 } else if (events[type]) {
22462 if (--this._eventsCount === 0)
22463 this._events = objectCreate(null);
22464 else
22465 delete events[type];
22466 }
22467 return this;
22468 }
22469
22470 // emit removeListener for all listeners on all events
22471 if (arguments.length === 0) {
22472 var keys = objectKeys(events);
22473 var key;
22474 for (i = 0; i < keys.length; ++i) {
22475 key = keys[i];
22476 if (key === 'removeListener') continue;
22477 this.removeAllListeners(key);
22478 }
22479 this.removeAllListeners('removeListener');
22480 this._events = objectCreate(null);
22481 this._eventsCount = 0;
22482 return this;
22483 }
22484
22485 listeners = events[type];
22486
22487 if (typeof listeners === 'function') {
22488 this.removeListener(type, listeners);
22489 } else if (listeners) {
22490 // LIFO order
22491 for (i = listeners.length - 1; i >= 0; i--) {
22492 this.removeListener(type, listeners[i]);
22493 }
22494 }
22495
22496 return this;
22497 };
22498
22499 function _listeners(target, type, unwrap) {
22500 var events = target._events;
22501
22502 if (!events)
22503 return [];
22504
22505 var evlistener = events[type];
22506 if (!evlistener)
22507 return [];
22508
22509 if (typeof evlistener === 'function')
22510 return unwrap ? [evlistener.listener || evlistener] : [evlistener];
22511
22512 return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
22513 }
22514
22515 EventEmitter.prototype.listeners = function listeners(type) {
22516 return _listeners(this, type, true);
22517 };
22518
22519 EventEmitter.prototype.rawListeners = function rawListeners(type) {
22520 return _listeners(this, type, false);
22521 };
22522
22523 EventEmitter.listenerCount = function(emitter, type) {
22524 if (typeof emitter.listenerCount === 'function') {
22525 return emitter.listenerCount(type);
22526 } else {
22527 return listenerCount.call(emitter, type);
22528 }
22529 };
22530
22531 EventEmitter.prototype.listenerCount = listenerCount;
22532 function listenerCount(type) {
22533 var events = this._events;
22534
22535 if (events) {
22536 var evlistener = events[type];
22537
22538 if (typeof evlistener === 'function') {
22539 return 1;
22540 } else if (evlistener) {
22541 return evlistener.length;
22542 }
22543 }
22544
22545 return 0;
22546 }
22547
22548 EventEmitter.prototype.eventNames = function eventNames() {
22549 return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
22550 };
22551
22552 // About 1.5x faster than the two-arg version of Array#splice().
22553 function spliceOne(list, index) {
22554 for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
22555 list[i] = list[k];
22556 list.pop();
22557 }
22558
22559 function arrayClone(arr, n) {
22560 var copy = new Array(n);
22561 for (var i = 0; i < n; ++i)
22562 copy[i] = arr[i];
22563 return copy;
22564 }
22565
22566 function unwrapListeners(arr) {
22567 var ret = new Array(arr.length);
22568 for (var i = 0; i < ret.length; ++i) {
22569 ret[i] = arr[i].listener || arr[i];
22570 }
22571 return ret;
22572 }
22573
22574 function objectCreatePolyfill(proto) {
22575 var F = function() {};
22576 F.prototype = proto;
22577 return new F;
22578 }
22579 function objectKeysPolyfill(obj) {
22580 var keys = [];
22581 for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
22582 keys.push(k);
22583 }
22584 return k;
22585 }
22586 function functionBindPolyfill(context) {
22587 var fn = this;
22588 return function () {
22589 return fn.apply(context, arguments);
22590 };
22591 }
22592
22593 },{}],146:[function(require,module,exports){
22594 arguments[4][38][0].apply(exports,arguments)
22595 },{"dup":38,"md5.js":165,"safe-buffer":206}],147:[function(require,module,exports){
22596 arguments[4][43][0].apply(exports,arguments)
22597 },{"dup":43,"inherits":162,"safe-buffer":206,"stream":215}],148:[function(require,module,exports){
22598 var hash = exports;
22599
22600 hash.utils = require('./hash/utils');
22601 hash.common = require('./hash/common');
22602 hash.sha = require('./hash/sha');
22603 hash.ripemd = require('./hash/ripemd');
22604 hash.hmac = require('./hash/hmac');
22605
22606 // Proxy hash functions to the main object
22607 hash.sha1 = hash.sha.sha1;
22608 hash.sha256 = hash.sha.sha256;
22609 hash.sha224 = hash.sha.sha224;
22610 hash.sha384 = hash.sha.sha384;
22611 hash.sha512 = hash.sha.sha512;
22612 hash.ripemd160 = hash.ripemd.ripemd160;
22613
22614 },{"./hash/common":149,"./hash/hmac":150,"./hash/ripemd":151,"./hash/sha":152,"./hash/utils":159}],149:[function(require,module,exports){
22615 'use strict';
22616
22617 var utils = require('./utils');
22618 var assert = require('minimalistic-assert');
22619
22620 function BlockHash() {
22621 this.pending = null;
22622 this.pendingTotal = 0;
22623 this.blockSize = this.constructor.blockSize;
22624 this.outSize = this.constructor.outSize;
22625 this.hmacStrength = this.constructor.hmacStrength;
22626 this.padLength = this.constructor.padLength / 8;
22627 this.endian = 'big';
22628
22629 this._delta8 = this.blockSize / 8;
22630 this._delta32 = this.blockSize / 32;
22631 }
22632 exports.BlockHash = BlockHash;
22633
22634 BlockHash.prototype.update = function update(msg, enc) {
22635 // Convert message to array, pad it, and join into 32bit blocks
22636 msg = utils.toArray(msg, enc);
22637 if (!this.pending)
22638 this.pending = msg;
22639 else
22640 this.pending = this.pending.concat(msg);
22641 this.pendingTotal += msg.length;
22642
22643 // Enough data, try updating
22644 if (this.pending.length >= this._delta8) {
22645 msg = this.pending;
22646
22647 // Process pending data in blocks
22648 var r = msg.length % this._delta8;
22649 this.pending = msg.slice(msg.length - r, msg.length);
22650 if (this.pending.length === 0)
22651 this.pending = null;
22652
22653 msg = utils.join32(msg, 0, msg.length - r, this.endian);
22654 for (var i = 0; i < msg.length; i += this._delta32)
22655 this._update(msg, i, i + this._delta32);
22656 }
22657
22658 return this;
22659 };
22660
22661 BlockHash.prototype.digest = function digest(enc) {
22662 this.update(this._pad());
22663 assert(this.pending === null);
22664
22665 return this._digest(enc);
22666 };
22667
22668 BlockHash.prototype._pad = function pad() {
22669 var len = this.pendingTotal;
22670 var bytes = this._delta8;
22671 var k = bytes - ((len + this.padLength) % bytes);
22672 var res = new Array(k + this.padLength);
22673 res[0] = 0x80;
22674 for (var i = 1; i < k; i++)
22675 res[i] = 0;
22676
22677 // Append length
22678 len <<= 3;
22679 if (this.endian === 'big') {
22680 for (var t = 8; t < this.padLength; t++)
22681 res[i++] = 0;
22682
22683 res[i++] = 0;
22684 res[i++] = 0;
22685 res[i++] = 0;
22686 res[i++] = 0;
22687 res[i++] = (len >>> 24) & 0xff;
22688 res[i++] = (len >>> 16) & 0xff;
22689 res[i++] = (len >>> 8) & 0xff;
22690 res[i++] = len & 0xff;
22691 } else {
22692 res[i++] = len & 0xff;
22693 res[i++] = (len >>> 8) & 0xff;
22694 res[i++] = (len >>> 16) & 0xff;
22695 res[i++] = (len >>> 24) & 0xff;
22696 res[i++] = 0;
22697 res[i++] = 0;
22698 res[i++] = 0;
22699 res[i++] = 0;
22700
22701 for (t = 8; t < this.padLength; t++)
22702 res[i++] = 0;
22703 }
22704
22705 return res;
22706 };
22707
22708 },{"./utils":159,"minimalistic-assert":167}],150:[function(require,module,exports){
22709 'use strict';
22710
22711 var utils = require('./utils');
22712 var assert = require('minimalistic-assert');
22713
22714 function Hmac(hash, key, enc) {
22715 if (!(this instanceof Hmac))
22716 return new Hmac(hash, key, enc);
22717 this.Hash = hash;
22718 this.blockSize = hash.blockSize / 8;
22719 this.outSize = hash.outSize / 8;
22720 this.inner = null;
22721 this.outer = null;
22722
22723 this._init(utils.toArray(key, enc));
22724 }
22725 module.exports = Hmac;
22726
22727 Hmac.prototype._init = function init(key) {
22728 // Shorten key, if needed
22729 if (key.length > this.blockSize)
22730 key = new this.Hash().update(key).digest();
22731 assert(key.length <= this.blockSize);
22732
22733 // Add padding to key
22734 for (var i = key.length; i < this.blockSize; i++)
22735 key.push(0);
22736
22737 for (i = 0; i < key.length; i++)
22738 key[i] ^= 0x36;
22739 this.inner = new this.Hash().update(key);
22740
22741 // 0x36 ^ 0x5c = 0x6a
22742 for (i = 0; i < key.length; i++)
22743 key[i] ^= 0x6a;
22744 this.outer = new this.Hash().update(key);
22745 };
22746
22747 Hmac.prototype.update = function update(msg, enc) {
22748 this.inner.update(msg, enc);
22749 return this;
22750 };
22751
22752 Hmac.prototype.digest = function digest(enc) {
22753 this.outer.update(this.inner.digest());
22754 return this.outer.digest(enc);
22755 };
22756
22757 },{"./utils":159,"minimalistic-assert":167}],151:[function(require,module,exports){
22758 'use strict';
22759
22760 var utils = require('./utils');
22761 var common = require('./common');
22762
22763 var rotl32 = utils.rotl32;
22764 var sum32 = utils.sum32;
22765 var sum32_3 = utils.sum32_3;
22766 var sum32_4 = utils.sum32_4;
22767 var BlockHash = common.BlockHash;
22768
22769 function RIPEMD160() {
22770 if (!(this instanceof RIPEMD160))
22771 return new RIPEMD160();
22772
22773 BlockHash.call(this);
22774
22775 this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
22776 this.endian = 'little';
22777 }
22778 utils.inherits(RIPEMD160, BlockHash);
22779 exports.ripemd160 = RIPEMD160;
22780
22781 RIPEMD160.blockSize = 512;
22782 RIPEMD160.outSize = 160;
22783 RIPEMD160.hmacStrength = 192;
22784 RIPEMD160.padLength = 64;
22785
22786 RIPEMD160.prototype._update = function update(msg, start) {
22787 var A = this.h[0];
22788 var B = this.h[1];
22789 var C = this.h[2];
22790 var D = this.h[3];
22791 var E = this.h[4];
22792 var Ah = A;
22793 var Bh = B;
22794 var Ch = C;
22795 var Dh = D;
22796 var Eh = E;
22797 for (var j = 0; j < 80; j++) {
22798 var T = sum32(
22799 rotl32(
22800 sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
22801 s[j]),
22802 E);
22803 A = E;
22804 E = D;
22805 D = rotl32(C, 10);
22806 C = B;
22807 B = T;
22808 T = sum32(
22809 rotl32(
22810 sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
22811 sh[j]),
22812 Eh);
22813 Ah = Eh;
22814 Eh = Dh;
22815 Dh = rotl32(Ch, 10);
22816 Ch = Bh;
22817 Bh = T;
22818 }
22819 T = sum32_3(this.h[1], C, Dh);
22820 this.h[1] = sum32_3(this.h[2], D, Eh);
22821 this.h[2] = sum32_3(this.h[3], E, Ah);
22822 this.h[3] = sum32_3(this.h[4], A, Bh);
22823 this.h[4] = sum32_3(this.h[0], B, Ch);
22824 this.h[0] = T;
22825 };
22826
22827 RIPEMD160.prototype._digest = function digest(enc) {
22828 if (enc === 'hex')
22829 return utils.toHex32(this.h, 'little');
22830 else
22831 return utils.split32(this.h, 'little');
22832 };
22833
22834 function f(j, x, y, z) {
22835 if (j <= 15)
22836 return x ^ y ^ z;
22837 else if (j <= 31)
22838 return (x & y) | ((~x) & z);
22839 else if (j <= 47)
22840 return (x | (~y)) ^ z;
22841 else if (j <= 63)
22842 return (x & z) | (y & (~z));
22843 else
22844 return x ^ (y | (~z));
22845 }
22846
22847 function K(j) {
22848 if (j <= 15)
22849 return 0x00000000;
22850 else if (j <= 31)
22851 return 0x5a827999;
22852 else if (j <= 47)
22853 return 0x6ed9eba1;
22854 else if (j <= 63)
22855 return 0x8f1bbcdc;
22856 else
22857 return 0xa953fd4e;
22858 }
22859
22860 function Kh(j) {
22861 if (j <= 15)
22862 return 0x50a28be6;
22863 else if (j <= 31)
22864 return 0x5c4dd124;
22865 else if (j <= 47)
22866 return 0x6d703ef3;
22867 else if (j <= 63)
22868 return 0x7a6d76e9;
22869 else
22870 return 0x00000000;
22871 }
22872
22873 var r = [
22874 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
22875 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
22876 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
22877 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
22878 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
22879 ];
22880
22881 var rh = [
22882 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
22883 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
22884 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
22885 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
22886 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
22887 ];
22888
22889 var s = [
22890 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
22891 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
22892 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
22893 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
22894 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
22895 ];
22896
22897 var sh = [
22898 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
22899 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
22900 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
22901 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
22902 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
22903 ];
22904
22905 },{"./common":149,"./utils":159}],152:[function(require,module,exports){
22906 'use strict';
22907
22908 exports.sha1 = require('./sha/1');
22909 exports.sha224 = require('./sha/224');
22910 exports.sha256 = require('./sha/256');
22911 exports.sha384 = require('./sha/384');
22912 exports.sha512 = require('./sha/512');
22913
22914 },{"./sha/1":153,"./sha/224":154,"./sha/256":155,"./sha/384":156,"./sha/512":157}],153:[function(require,module,exports){
22915 'use strict';
22916
22917 var utils = require('../utils');
22918 var common = require('../common');
22919 var shaCommon = require('./common');
22920
22921 var rotl32 = utils.rotl32;
22922 var sum32 = utils.sum32;
22923 var sum32_5 = utils.sum32_5;
22924 var ft_1 = shaCommon.ft_1;
22925 var BlockHash = common.BlockHash;
22926
22927 var sha1_K = [
22928 0x5A827999, 0x6ED9EBA1,
22929 0x8F1BBCDC, 0xCA62C1D6
22930 ];
22931
22932 function SHA1() {
22933 if (!(this instanceof SHA1))
22934 return new SHA1();
22935
22936 BlockHash.call(this);
22937 this.h = [
22938 0x67452301, 0xefcdab89, 0x98badcfe,
22939 0x10325476, 0xc3d2e1f0 ];
22940 this.W = new Array(80);
22941 }
22942
22943 utils.inherits(SHA1, BlockHash);
22944 module.exports = SHA1;
22945
22946 SHA1.blockSize = 512;
22947 SHA1.outSize = 160;
22948 SHA1.hmacStrength = 80;
22949 SHA1.padLength = 64;
22950
22951 SHA1.prototype._update = function _update(msg, start) {
22952 var W = this.W;
22953
22954 for (var i = 0; i < 16; i++)
22955 W[i] = msg[start + i];
22956
22957 for(; i < W.length; i++)
22958 W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
22959
22960 var a = this.h[0];
22961 var b = this.h[1];
22962 var c = this.h[2];
22963 var d = this.h[3];
22964 var e = this.h[4];
22965
22966 for (i = 0; i < W.length; i++) {
22967 var s = ~~(i / 20);
22968 var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
22969 e = d;
22970 d = c;
22971 c = rotl32(b, 30);
22972 b = a;
22973 a = t;
22974 }
22975
22976 this.h[0] = sum32(this.h[0], a);
22977 this.h[1] = sum32(this.h[1], b);
22978 this.h[2] = sum32(this.h[2], c);
22979 this.h[3] = sum32(this.h[3], d);
22980 this.h[4] = sum32(this.h[4], e);
22981 };
22982
22983 SHA1.prototype._digest = function digest(enc) {
22984 if (enc === 'hex')
22985 return utils.toHex32(this.h, 'big');
22986 else
22987 return utils.split32(this.h, 'big');
22988 };
22989
22990 },{"../common":149,"../utils":159,"./common":158}],154:[function(require,module,exports){
22991 'use strict';
22992
22993 var utils = require('../utils');
22994 var SHA256 = require('./256');
22995
22996 function SHA224() {
22997 if (!(this instanceof SHA224))
22998 return new SHA224();
22999
23000 SHA256.call(this);
23001 this.h = [
23002 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
23003 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
23004 }
23005 utils.inherits(SHA224, SHA256);
23006 module.exports = SHA224;
23007
23008 SHA224.blockSize = 512;
23009 SHA224.outSize = 224;
23010 SHA224.hmacStrength = 192;
23011 SHA224.padLength = 64;
23012
23013 SHA224.prototype._digest = function digest(enc) {
23014 // Just truncate output
23015 if (enc === 'hex')
23016 return utils.toHex32(this.h.slice(0, 7), 'big');
23017 else
23018 return utils.split32(this.h.slice(0, 7), 'big');
23019 };
23020
23021
23022 },{"../utils":159,"./256":155}],155:[function(require,module,exports){
23023 'use strict';
23024
23025 var utils = require('../utils');
23026 var common = require('../common');
23027 var shaCommon = require('./common');
23028 var assert = require('minimalistic-assert');
23029
23030 var sum32 = utils.sum32;
23031 var sum32_4 = utils.sum32_4;
23032 var sum32_5 = utils.sum32_5;
23033 var ch32 = shaCommon.ch32;
23034 var maj32 = shaCommon.maj32;
23035 var s0_256 = shaCommon.s0_256;
23036 var s1_256 = shaCommon.s1_256;
23037 var g0_256 = shaCommon.g0_256;
23038 var g1_256 = shaCommon.g1_256;
23039
23040 var BlockHash = common.BlockHash;
23041
23042 var sha256_K = [
23043 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
23044 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
23045 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
23046 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
23047 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
23048 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
23049 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
23050 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
23051 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
23052 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
23053 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
23054 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
23055 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
23056 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
23057 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
23058 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
23059 ];
23060
23061 function SHA256() {
23062 if (!(this instanceof SHA256))
23063 return new SHA256();
23064
23065 BlockHash.call(this);
23066 this.h = [
23067 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
23068 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
23069 ];
23070 this.k = sha256_K;
23071 this.W = new Array(64);
23072 }
23073 utils.inherits(SHA256, BlockHash);
23074 module.exports = SHA256;
23075
23076 SHA256.blockSize = 512;
23077 SHA256.outSize = 256;
23078 SHA256.hmacStrength = 192;
23079 SHA256.padLength = 64;
23080
23081 SHA256.prototype._update = function _update(msg, start) {
23082 var W = this.W;
23083
23084 for (var i = 0; i < 16; i++)
23085 W[i] = msg[start + i];
23086 for (; i < W.length; i++)
23087 W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
23088
23089 var a = this.h[0];
23090 var b = this.h[1];
23091 var c = this.h[2];
23092 var d = this.h[3];
23093 var e = this.h[4];
23094 var f = this.h[5];
23095 var g = this.h[6];
23096 var h = this.h[7];
23097
23098 assert(this.k.length === W.length);
23099 for (i = 0; i < W.length; i++) {
23100 var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
23101 var T2 = sum32(s0_256(a), maj32(a, b, c));
23102 h = g;
23103 g = f;
23104 f = e;
23105 e = sum32(d, T1);
23106 d = c;
23107 c = b;
23108 b = a;
23109 a = sum32(T1, T2);
23110 }
23111
23112 this.h[0] = sum32(this.h[0], a);
23113 this.h[1] = sum32(this.h[1], b);
23114 this.h[2] = sum32(this.h[2], c);
23115 this.h[3] = sum32(this.h[3], d);
23116 this.h[4] = sum32(this.h[4], e);
23117 this.h[5] = sum32(this.h[5], f);
23118 this.h[6] = sum32(this.h[6], g);
23119 this.h[7] = sum32(this.h[7], h);
23120 };
23121
23122 SHA256.prototype._digest = function digest(enc) {
23123 if (enc === 'hex')
23124 return utils.toHex32(this.h, 'big');
23125 else
23126 return utils.split32(this.h, 'big');
23127 };
23128
23129 },{"../common":149,"../utils":159,"./common":158,"minimalistic-assert":167}],156:[function(require,module,exports){
23130 'use strict';
23131
23132 var utils = require('../utils');
23133
23134 var SHA512 = require('./512');
23135
23136 function SHA384() {
23137 if (!(this instanceof SHA384))
23138 return new SHA384();
23139
23140 SHA512.call(this);
23141 this.h = [
23142 0xcbbb9d5d, 0xc1059ed8,
23143 0x629a292a, 0x367cd507,
23144 0x9159015a, 0x3070dd17,
23145 0x152fecd8, 0xf70e5939,
23146 0x67332667, 0xffc00b31,
23147 0x8eb44a87, 0x68581511,
23148 0xdb0c2e0d, 0x64f98fa7,
23149 0x47b5481d, 0xbefa4fa4 ];
23150 }
23151 utils.inherits(SHA384, SHA512);
23152 module.exports = SHA384;
23153
23154 SHA384.blockSize = 1024;
23155 SHA384.outSize = 384;
23156 SHA384.hmacStrength = 192;
23157 SHA384.padLength = 128;
23158
23159 SHA384.prototype._digest = function digest(enc) {
23160 if (enc === 'hex')
23161 return utils.toHex32(this.h.slice(0, 12), 'big');
23162 else
23163 return utils.split32(this.h.slice(0, 12), 'big');
23164 };
23165
23166 },{"../utils":159,"./512":157}],157:[function(require,module,exports){
23167 'use strict';
23168
23169 var utils = require('../utils');
23170 var common = require('../common');
23171 var assert = require('minimalistic-assert');
23172
23173 var rotr64_hi = utils.rotr64_hi;
23174 var rotr64_lo = utils.rotr64_lo;
23175 var shr64_hi = utils.shr64_hi;
23176 var shr64_lo = utils.shr64_lo;
23177 var sum64 = utils.sum64;
23178 var sum64_hi = utils.sum64_hi;
23179 var sum64_lo = utils.sum64_lo;
23180 var sum64_4_hi = utils.sum64_4_hi;
23181 var sum64_4_lo = utils.sum64_4_lo;
23182 var sum64_5_hi = utils.sum64_5_hi;
23183 var sum64_5_lo = utils.sum64_5_lo;
23184
23185 var BlockHash = common.BlockHash;
23186
23187 var sha512_K = [
23188 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
23189 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
23190 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
23191 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
23192 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
23193 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
23194 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
23195 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
23196 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
23197 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
23198 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
23199 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
23200 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
23201 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
23202 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
23203 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
23204 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
23205 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
23206 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
23207 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
23208 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
23209 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
23210 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
23211 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
23212 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
23213 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
23214 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
23215 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
23216 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
23217 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
23218 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
23219 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
23220 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
23221 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
23222 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
23223 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
23224 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
23225 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
23226 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
23227 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
23228 ];
23229
23230 function SHA512() {
23231 if (!(this instanceof SHA512))
23232 return new SHA512();
23233
23234 BlockHash.call(this);
23235 this.h = [
23236 0x6a09e667, 0xf3bcc908,
23237 0xbb67ae85, 0x84caa73b,
23238 0x3c6ef372, 0xfe94f82b,
23239 0xa54ff53a, 0x5f1d36f1,
23240 0x510e527f, 0xade682d1,
23241 0x9b05688c, 0x2b3e6c1f,
23242 0x1f83d9ab, 0xfb41bd6b,
23243 0x5be0cd19, 0x137e2179 ];
23244 this.k = sha512_K;
23245 this.W = new Array(160);
23246 }
23247 utils.inherits(SHA512, BlockHash);
23248 module.exports = SHA512;
23249
23250 SHA512.blockSize = 1024;
23251 SHA512.outSize = 512;
23252 SHA512.hmacStrength = 192;
23253 SHA512.padLength = 128;
23254
23255 SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
23256 var W = this.W;
23257
23258 // 32 x 32bit words
23259 for (var i = 0; i < 32; i++)
23260 W[i] = msg[start + i];
23261 for (; i < W.length; i += 2) {
23262 var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
23263 var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
23264 var c1_hi = W[i - 14]; // i - 7
23265 var c1_lo = W[i - 13];
23266 var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
23267 var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
23268 var c3_hi = W[i - 32]; // i - 16
23269 var c3_lo = W[i - 31];
23270
23271 W[i] = sum64_4_hi(
23272 c0_hi, c0_lo,
23273 c1_hi, c1_lo,
23274 c2_hi, c2_lo,
23275 c3_hi, c3_lo);
23276 W[i + 1] = sum64_4_lo(
23277 c0_hi, c0_lo,
23278 c1_hi, c1_lo,
23279 c2_hi, c2_lo,
23280 c3_hi, c3_lo);
23281 }
23282 };
23283
23284 SHA512.prototype._update = function _update(msg, start) {
23285 this._prepareBlock(msg, start);
23286
23287 var W = this.W;
23288
23289 var ah = this.h[0];
23290 var al = this.h[1];
23291 var bh = this.h[2];
23292 var bl = this.h[3];
23293 var ch = this.h[4];
23294 var cl = this.h[5];
23295 var dh = this.h[6];
23296 var dl = this.h[7];
23297 var eh = this.h[8];
23298 var el = this.h[9];
23299 var fh = this.h[10];
23300 var fl = this.h[11];
23301 var gh = this.h[12];
23302 var gl = this.h[13];
23303 var hh = this.h[14];
23304 var hl = this.h[15];
23305
23306 assert(this.k.length === W.length);
23307 for (var i = 0; i < W.length; i += 2) {
23308 var c0_hi = hh;
23309 var c0_lo = hl;
23310 var c1_hi = s1_512_hi(eh, el);
23311 var c1_lo = s1_512_lo(eh, el);
23312 var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
23313 var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
23314 var c3_hi = this.k[i];
23315 var c3_lo = this.k[i + 1];
23316 var c4_hi = W[i];
23317 var c4_lo = W[i + 1];
23318
23319 var T1_hi = sum64_5_hi(
23320 c0_hi, c0_lo,
23321 c1_hi, c1_lo,
23322 c2_hi, c2_lo,
23323 c3_hi, c3_lo,
23324 c4_hi, c4_lo);
23325 var T1_lo = sum64_5_lo(
23326 c0_hi, c0_lo,
23327 c1_hi, c1_lo,
23328 c2_hi, c2_lo,
23329 c3_hi, c3_lo,
23330 c4_hi, c4_lo);
23331
23332 c0_hi = s0_512_hi(ah, al);
23333 c0_lo = s0_512_lo(ah, al);
23334 c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
23335 c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
23336
23337 var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
23338 var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
23339
23340 hh = gh;
23341 hl = gl;
23342
23343 gh = fh;
23344 gl = fl;
23345
23346 fh = eh;
23347 fl = el;
23348
23349 eh = sum64_hi(dh, dl, T1_hi, T1_lo);
23350 el = sum64_lo(dl, dl, T1_hi, T1_lo);
23351
23352 dh = ch;
23353 dl = cl;
23354
23355 ch = bh;
23356 cl = bl;
23357
23358 bh = ah;
23359 bl = al;
23360
23361 ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
23362 al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
23363 }
23364
23365 sum64(this.h, 0, ah, al);
23366 sum64(this.h, 2, bh, bl);
23367 sum64(this.h, 4, ch, cl);
23368 sum64(this.h, 6, dh, dl);
23369 sum64(this.h, 8, eh, el);
23370 sum64(this.h, 10, fh, fl);
23371 sum64(this.h, 12, gh, gl);
23372 sum64(this.h, 14, hh, hl);
23373 };
23374
23375 SHA512.prototype._digest = function digest(enc) {
23376 if (enc === 'hex')
23377 return utils.toHex32(this.h, 'big');
23378 else
23379 return utils.split32(this.h, 'big');
23380 };
23381
23382 function ch64_hi(xh, xl, yh, yl, zh) {
23383 var r = (xh & yh) ^ ((~xh) & zh);
23384 if (r < 0)
23385 r += 0x100000000;
23386 return r;
23387 }
23388
23389 function ch64_lo(xh, xl, yh, yl, zh, zl) {
23390 var r = (xl & yl) ^ ((~xl) & zl);
23391 if (r < 0)
23392 r += 0x100000000;
23393 return r;
23394 }
23395
23396 function maj64_hi(xh, xl, yh, yl, zh) {
23397 var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
23398 if (r < 0)
23399 r += 0x100000000;
23400 return r;
23401 }
23402
23403 function maj64_lo(xh, xl, yh, yl, zh, zl) {
23404 var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
23405 if (r < 0)
23406 r += 0x100000000;
23407 return r;
23408 }
23409
23410 function s0_512_hi(xh, xl) {
23411 var c0_hi = rotr64_hi(xh, xl, 28);
23412 var c1_hi = rotr64_hi(xl, xh, 2); // 34
23413 var c2_hi = rotr64_hi(xl, xh, 7); // 39
23414
23415 var r = c0_hi ^ c1_hi ^ c2_hi;
23416 if (r < 0)
23417 r += 0x100000000;
23418 return r;
23419 }
23420
23421 function s0_512_lo(xh, xl) {
23422 var c0_lo = rotr64_lo(xh, xl, 28);
23423 var c1_lo = rotr64_lo(xl, xh, 2); // 34
23424 var c2_lo = rotr64_lo(xl, xh, 7); // 39
23425
23426 var r = c0_lo ^ c1_lo ^ c2_lo;
23427 if (r < 0)
23428 r += 0x100000000;
23429 return r;
23430 }
23431
23432 function s1_512_hi(xh, xl) {
23433 var c0_hi = rotr64_hi(xh, xl, 14);
23434 var c1_hi = rotr64_hi(xh, xl, 18);
23435 var c2_hi = rotr64_hi(xl, xh, 9); // 41
23436
23437 var r = c0_hi ^ c1_hi ^ c2_hi;
23438 if (r < 0)
23439 r += 0x100000000;
23440 return r;
23441 }
23442
23443 function s1_512_lo(xh, xl) {
23444 var c0_lo = rotr64_lo(xh, xl, 14);
23445 var c1_lo = rotr64_lo(xh, xl, 18);
23446 var c2_lo = rotr64_lo(xl, xh, 9); // 41
23447
23448 var r = c0_lo ^ c1_lo ^ c2_lo;
23449 if (r < 0)
23450 r += 0x100000000;
23451 return r;
23452 }
23453
23454 function g0_512_hi(xh, xl) {
23455 var c0_hi = rotr64_hi(xh, xl, 1);
23456 var c1_hi = rotr64_hi(xh, xl, 8);
23457 var c2_hi = shr64_hi(xh, xl, 7);
23458
23459 var r = c0_hi ^ c1_hi ^ c2_hi;
23460 if (r < 0)
23461 r += 0x100000000;
23462 return r;
23463 }
23464
23465 function g0_512_lo(xh, xl) {
23466 var c0_lo = rotr64_lo(xh, xl, 1);
23467 var c1_lo = rotr64_lo(xh, xl, 8);
23468 var c2_lo = shr64_lo(xh, xl, 7);
23469
23470 var r = c0_lo ^ c1_lo ^ c2_lo;
23471 if (r < 0)
23472 r += 0x100000000;
23473 return r;
23474 }
23475
23476 function g1_512_hi(xh, xl) {
23477 var c0_hi = rotr64_hi(xh, xl, 19);
23478 var c1_hi = rotr64_hi(xl, xh, 29); // 61
23479 var c2_hi = shr64_hi(xh, xl, 6);
23480
23481 var r = c0_hi ^ c1_hi ^ c2_hi;
23482 if (r < 0)
23483 r += 0x100000000;
23484 return r;
23485 }
23486
23487 function g1_512_lo(xh, xl) {
23488 var c0_lo = rotr64_lo(xh, xl, 19);
23489 var c1_lo = rotr64_lo(xl, xh, 29); // 61
23490 var c2_lo = shr64_lo(xh, xl, 6);
23491
23492 var r = c0_lo ^ c1_lo ^ c2_lo;
23493 if (r < 0)
23494 r += 0x100000000;
23495 return r;
23496 }
23497
23498 },{"../common":149,"../utils":159,"minimalistic-assert":167}],158:[function(require,module,exports){
23499 'use strict';
23500
23501 var utils = require('../utils');
23502 var rotr32 = utils.rotr32;
23503
23504 function ft_1(s, x, y, z) {
23505 if (s === 0)
23506 return ch32(x, y, z);
23507 if (s === 1 || s === 3)
23508 return p32(x, y, z);
23509 if (s === 2)
23510 return maj32(x, y, z);
23511 }
23512 exports.ft_1 = ft_1;
23513
23514 function ch32(x, y, z) {
23515 return (x & y) ^ ((~x) & z);
23516 }
23517 exports.ch32 = ch32;
23518
23519 function maj32(x, y, z) {
23520 return (x & y) ^ (x & z) ^ (y & z);
23521 }
23522 exports.maj32 = maj32;
23523
23524 function p32(x, y, z) {
23525 return x ^ y ^ z;
23526 }
23527 exports.p32 = p32;
23528
23529 function s0_256(x) {
23530 return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
23531 }
23532 exports.s0_256 = s0_256;
23533
23534 function s1_256(x) {
23535 return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
23536 }
23537 exports.s1_256 = s1_256;
23538
23539 function g0_256(x) {
23540 return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
23541 }
23542 exports.g0_256 = g0_256;
23543
23544 function g1_256(x) {
23545 return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
23546 }
23547 exports.g1_256 = g1_256;
23548
23549 },{"../utils":159}],159:[function(require,module,exports){
23550 'use strict';
23551
23552 var assert = require('minimalistic-assert');
23553 var inherits = require('inherits');
23554
23555 exports.inherits = inherits;
23556
23557 function isSurrogatePair(msg, i) {
23558 if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
23559 return false;
23560 }
23561 if (i < 0 || i + 1 >= msg.length) {
23562 return false;
23563 }
23564 return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
23565 }
23566
23567 function toArray(msg, enc) {
23568 if (Array.isArray(msg))
23569 return msg.slice();
23570 if (!msg)
23571 return [];
23572 var res = [];
23573 if (typeof msg === 'string') {
23574 if (!enc) {
23575 // Inspired by stringToUtf8ByteArray() in closure-library by Google
23576 // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
23577 // Apache License 2.0
23578 // https://github.com/google/closure-library/blob/master/LICENSE
23579 var p = 0;
23580 for (var i = 0; i < msg.length; i++) {
23581 var c = msg.charCodeAt(i);
23582 if (c < 128) {
23583 res[p++] = c;
23584 } else if (c < 2048) {
23585 res[p++] = (c >> 6) | 192;
23586 res[p++] = (c & 63) | 128;
23587 } else if (isSurrogatePair(msg, i)) {
23588 c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
23589 res[p++] = (c >> 18) | 240;
23590 res[p++] = ((c >> 12) & 63) | 128;
23591 res[p++] = ((c >> 6) & 63) | 128;
23592 res[p++] = (c & 63) | 128;
23593 } else {
23594 res[p++] = (c >> 12) | 224;
23595 res[p++] = ((c >> 6) & 63) | 128;
23596 res[p++] = (c & 63) | 128;
23597 }
23598 }
23599 } else if (enc === 'hex') {
23600 msg = msg.replace(/[^a-z0-9]+/ig, '');
23601 if (msg.length % 2 !== 0)
23602 msg = '0' + msg;
23603 for (i = 0; i < msg.length; i += 2)
23604 res.push(parseInt(msg[i] + msg[i + 1], 16));
23605 }
23606 } else {
23607 for (i = 0; i < msg.length; i++)
23608 res[i] = msg[i] | 0;
23609 }
23610 return res;
23611 }
23612 exports.toArray = toArray;
23613
23614 function toHex(msg) {
23615 var res = '';
23616 for (var i = 0; i < msg.length; i++)
23617 res += zero2(msg[i].toString(16));
23618 return res;
23619 }
23620 exports.toHex = toHex;
23621
23622 function htonl(w) {
23623 var res = (w >>> 24) |
23624 ((w >>> 8) & 0xff00) |
23625 ((w << 8) & 0xff0000) |
23626 ((w & 0xff) << 24);
23627 return res >>> 0;
23628 }
23629 exports.htonl = htonl;
23630
23631 function toHex32(msg, endian) {
23632 var res = '';
23633 for (var i = 0; i < msg.length; i++) {
23634 var w = msg[i];
23635 if (endian === 'little')
23636 w = htonl(w);
23637 res += zero8(w.toString(16));
23638 }
23639 return res;
23640 }
23641 exports.toHex32 = toHex32;
23642
23643 function zero2(word) {
23644 if (word.length === 1)
23645 return '0' + word;
23646 else
23647 return word;
23648 }
23649 exports.zero2 = zero2;
23650
23651 function zero8(word) {
23652 if (word.length === 7)
23653 return '0' + word;
23654 else if (word.length === 6)
23655 return '00' + word;
23656 else if (word.length === 5)
23657 return '000' + word;
23658 else if (word.length === 4)
23659 return '0000' + word;
23660 else if (word.length === 3)
23661 return '00000' + word;
23662 else if (word.length === 2)
23663 return '000000' + word;
23664 else if (word.length === 1)
23665 return '0000000' + word;
23666 else
23667 return word;
23668 }
23669 exports.zero8 = zero8;
23670
23671 function join32(msg, start, end, endian) {
23672 var len = end - start;
23673 assert(len % 4 === 0);
23674 var res = new Array(len / 4);
23675 for (var i = 0, k = start; i < res.length; i++, k += 4) {
23676 var w;
23677 if (endian === 'big')
23678 w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
23679 else
23680 w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
23681 res[i] = w >>> 0;
23682 }
23683 return res;
23684 }
23685 exports.join32 = join32;
23686
23687 function split32(msg, endian) {
23688 var res = new Array(msg.length * 4);
23689 for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
23690 var m = msg[i];
23691 if (endian === 'big') {
23692 res[k] = m >>> 24;
23693 res[k + 1] = (m >>> 16) & 0xff;
23694 res[k + 2] = (m >>> 8) & 0xff;
23695 res[k + 3] = m & 0xff;
23696 } else {
23697 res[k + 3] = m >>> 24;
23698 res[k + 2] = (m >>> 16) & 0xff;
23699 res[k + 1] = (m >>> 8) & 0xff;
23700 res[k] = m & 0xff;
23701 }
23702 }
23703 return res;
23704 }
23705 exports.split32 = split32;
23706
23707 function rotr32(w, b) {
23708 return (w >>> b) | (w << (32 - b));
23709 }
23710 exports.rotr32 = rotr32;
23711
23712 function rotl32(w, b) {
23713 return (w << b) | (w >>> (32 - b));
23714 }
23715 exports.rotl32 = rotl32;
23716
23717 function sum32(a, b) {
23718 return (a + b) >>> 0;
23719 }
23720 exports.sum32 = sum32;
23721
23722 function sum32_3(a, b, c) {
23723 return (a + b + c) >>> 0;
23724 }
23725 exports.sum32_3 = sum32_3;
23726
23727 function sum32_4(a, b, c, d) {
23728 return (a + b + c + d) >>> 0;
23729 }
23730 exports.sum32_4 = sum32_4;
23731
23732 function sum32_5(a, b, c, d, e) {
23733 return (a + b + c + d + e) >>> 0;
23734 }
23735 exports.sum32_5 = sum32_5;
23736
23737 function sum64(buf, pos, ah, al) {
23738 var bh = buf[pos];
23739 var bl = buf[pos + 1];
23740
23741 var lo = (al + bl) >>> 0;
23742 var hi = (lo < al ? 1 : 0) + ah + bh;
23743 buf[pos] = hi >>> 0;
23744 buf[pos + 1] = lo;
23745 }
23746 exports.sum64 = sum64;
23747
23748 function sum64_hi(ah, al, bh, bl) {
23749 var lo = (al + bl) >>> 0;
23750 var hi = (lo < al ? 1 : 0) + ah + bh;
23751 return hi >>> 0;
23752 }
23753 exports.sum64_hi = sum64_hi;
23754
23755 function sum64_lo(ah, al, bh, bl) {
23756 var lo = al + bl;
23757 return lo >>> 0;
23758 }
23759 exports.sum64_lo = sum64_lo;
23760
23761 function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
23762 var carry = 0;
23763 var lo = al;
23764 lo = (lo + bl) >>> 0;
23765 carry += lo < al ? 1 : 0;
23766 lo = (lo + cl) >>> 0;
23767 carry += lo < cl ? 1 : 0;
23768 lo = (lo + dl) >>> 0;
23769 carry += lo < dl ? 1 : 0;
23770
23771 var hi = ah + bh + ch + dh + carry;
23772 return hi >>> 0;
23773 }
23774 exports.sum64_4_hi = sum64_4_hi;
23775
23776 function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
23777 var lo = al + bl + cl + dl;
23778 return lo >>> 0;
23779 }
23780 exports.sum64_4_lo = sum64_4_lo;
23781
23782 function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
23783 var carry = 0;
23784 var lo = al;
23785 lo = (lo + bl) >>> 0;
23786 carry += lo < al ? 1 : 0;
23787 lo = (lo + cl) >>> 0;
23788 carry += lo < cl ? 1 : 0;
23789 lo = (lo + dl) >>> 0;
23790 carry += lo < dl ? 1 : 0;
23791 lo = (lo + el) >>> 0;
23792 carry += lo < el ? 1 : 0;
23793
23794 var hi = ah + bh + ch + dh + eh + carry;
23795 return hi >>> 0;
23796 }
23797 exports.sum64_5_hi = sum64_5_hi;
23798
23799 function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
23800 var lo = al + bl + cl + dl + el;
23801
23802 return lo >>> 0;
23803 }
23804 exports.sum64_5_lo = sum64_5_lo;
23805
23806 function rotr64_hi(ah, al, num) {
23807 var r = (al << (32 - num)) | (ah >>> num);
23808 return r >>> 0;
23809 }
23810 exports.rotr64_hi = rotr64_hi;
23811
23812 function rotr64_lo(ah, al, num) {
23813 var r = (ah << (32 - num)) | (al >>> num);
23814 return r >>> 0;
23815 }
23816 exports.rotr64_lo = rotr64_lo;
23817
23818 function shr64_hi(ah, al, num) {
23819 return ah >>> num;
23820 }
23821 exports.shr64_hi = shr64_hi;
23822
23823 function shr64_lo(ah, al, num) {
23824 var r = (ah << (32 - num)) | (al >>> num);
23825 return r >>> 0;
23826 }
23827 exports.shr64_lo = shr64_lo;
23828
23829 },{"inherits":162,"minimalistic-assert":167}],160:[function(require,module,exports){
23830 'use strict';
23831
23832 var hash = require('hash.js');
23833 var utils = require('minimalistic-crypto-utils');
23834 var assert = require('minimalistic-assert');
23835
23836 function HmacDRBG(options) {
23837 if (!(this instanceof HmacDRBG))
23838 return new HmacDRBG(options);
23839 this.hash = options.hash;
23840 this.predResist = !!options.predResist;
23841
23842 this.outLen = this.hash.outSize;
23843 this.minEntropy = options.minEntropy || this.hash.hmacStrength;
23844
23845 this._reseed = null;
23846 this.reseedInterval = null;
23847 this.K = null;
23848 this.V = null;
23849
23850 var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
23851 var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
23852 var pers = utils.toArray(options.pers, options.persEnc || 'hex');
23853 assert(entropy.length >= (this.minEntropy / 8),
23854 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
23855 this._init(entropy, nonce, pers);
23856 }
23857 module.exports = HmacDRBG;
23858
23859 HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
23860 var seed = entropy.concat(nonce).concat(pers);
23861
23862 this.K = new Array(this.outLen / 8);
23863 this.V = new Array(this.outLen / 8);
23864 for (var i = 0; i < this.V.length; i++) {
23865 this.K[i] = 0x00;
23866 this.V[i] = 0x01;
23867 }
23868
23869 this._update(seed);
23870 this._reseed = 1;
23871 this.reseedInterval = 0x1000000000000; // 2^48
23872 };
23873
23874 HmacDRBG.prototype._hmac = function hmac() {
23875 return new hash.hmac(this.hash, this.K);
23876 };
23877
23878 HmacDRBG.prototype._update = function update(seed) {
23879 var kmac = this._hmac()
23880 .update(this.V)
23881 .update([ 0x00 ]);
23882 if (seed)
23883 kmac = kmac.update(seed);
23884 this.K = kmac.digest();
23885 this.V = this._hmac().update(this.V).digest();
23886 if (!seed)
23887 return;
23888
23889 this.K = this._hmac()
23890 .update(this.V)
23891 .update([ 0x01 ])
23892 .update(seed)
23893 .digest();
23894 this.V = this._hmac().update(this.V).digest();
23895 };
23896
23897 HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
23898 // Optional entropy enc
23899 if (typeof entropyEnc !== 'string') {
23900 addEnc = add;
23901 add = entropyEnc;
23902 entropyEnc = null;
23903 }
23904
23905 entropy = utils.toArray(entropy, entropyEnc);
23906 add = utils.toArray(add, addEnc);
23907
23908 assert(entropy.length >= (this.minEntropy / 8),
23909 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
23910
23911 this._update(entropy.concat(add || []));
23912 this._reseed = 1;
23913 };
23914
23915 HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
23916 if (this._reseed > this.reseedInterval)
23917 throw new Error('Reseed is required');
23918
23919 // Optional encoding
23920 if (typeof enc !== 'string') {
23921 addEnc = add;
23922 add = enc;
23923 enc = null;
23924 }
23925
23926 // Optional additional data
23927 if (add) {
23928 add = utils.toArray(add, addEnc || 'hex');
23929 this._update(add);
23930 }
23931
23932 var temp = [];
23933 while (temp.length < len) {
23934 this.V = this._hmac().update(this.V).digest();
23935 temp = temp.concat(this.V);
23936 }
23937
23938 var res = temp.slice(0, len);
23939 this._update(add);
23940 this._reseed++;
23941 return utils.encode(res, enc);
23942 };
23943
23944 },{"hash.js":148,"minimalistic-assert":167,"minimalistic-crypto-utils":168}],161:[function(require,module,exports){
23945 exports.read = function (buffer, offset, isLE, mLen, nBytes) {
23946 var e, m
23947 var eLen = (nBytes * 8) - mLen - 1
23948 var eMax = (1 << eLen) - 1
23949 var eBias = eMax >> 1
23950 var nBits = -7
23951 var i = isLE ? (nBytes - 1) : 0
23952 var d = isLE ? -1 : 1
23953 var s = buffer[offset + i]
23954
23955 i += d
23956
23957 e = s & ((1 << (-nBits)) - 1)
23958 s >>= (-nBits)
23959 nBits += eLen
23960 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
23961
23962 m = e & ((1 << (-nBits)) - 1)
23963 e >>= (-nBits)
23964 nBits += mLen
23965 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
23966
23967 if (e === 0) {
23968 e = 1 - eBias
23969 } else if (e === eMax) {
23970 return m ? NaN : ((s ? -1 : 1) * Infinity)
23971 } else {
23972 m = m + Math.pow(2, mLen)
23973 e = e - eBias
23974 }
23975 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
23976 }
23977
23978 exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
23979 var e, m, c
23980 var eLen = (nBytes * 8) - mLen - 1
23981 var eMax = (1 << eLen) - 1
23982 var eBias = eMax >> 1
23983 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
23984 var i = isLE ? 0 : (nBytes - 1)
23985 var d = isLE ? 1 : -1
23986 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
23987
23988 value = Math.abs(value)
23989
23990 if (isNaN(value) || value === Infinity) {
23991 m = isNaN(value) ? 1 : 0
23992 e = eMax
23993 } else {
23994 e = Math.floor(Math.log(value) / Math.LN2)
23995 if (value * (c = Math.pow(2, -e)) < 1) {
23996 e--
23997 c *= 2
23998 }
23999 if (e + eBias >= 1) {
24000 value += rt / c
24001 } else {
24002 value += rt * Math.pow(2, 1 - eBias)
24003 }
24004 if (value * c >= 2) {
24005 e++
24006 c /= 2
24007 }
24008
24009 if (e + eBias >= eMax) {
24010 m = 0
24011 e = eMax
24012 } else if (e + eBias >= 1) {
24013 m = ((value * c) - 1) * Math.pow(2, mLen)
24014 e = e + eBias
24015 } else {
24016 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
24017 e = 0
24018 }
24019 }
24020
24021 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
24022
24023 e = (e << mLen) | m
24024 eLen += mLen
24025 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
24026
24027 buffer[offset + i - d] |= s * 128
24028 }
24029
24030 },{}],162:[function(require,module,exports){
24031 arguments[4][44][0].apply(exports,arguments)
24032 },{"dup":44}],163:[function(require,module,exports){
24033 /*!
24034 * Determine if an object is a Buffer
24035 *
24036 * @author Feross Aboukhadijeh <https://feross.org>
24037 * @license MIT
24038 */
24039
24040 // The _isBuffer check is for Safari 5-7 support, because it's missing
24041 // Object.prototype.constructor. Remove this eventually
24042 module.exports = function (obj) {
24043 return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
24044 }
24045
24046 function isBuffer (obj) {
24047 return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
24048 }
24049
24050 // For Node v0.10 support. Remove this eventually.
24051 function isSlowBuffer (obj) {
24052 return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
24053 }
24054
24055 },{}],164:[function(require,module,exports){
24056 var toString = {}.toString;
24057
24058 module.exports = Array.isArray || function (arr) {
24059 return toString.call(arr) == '[object Array]';
24060 };
24061
24062 },{}],165:[function(require,module,exports){
24063 arguments[4][45][0].apply(exports,arguments)
24064 },{"dup":45,"hash-base":147,"inherits":162,"safe-buffer":206}],166:[function(require,module,exports){
24065 var bn = require('bn.js');
24066 var brorand = require('brorand');
24067
24068 function MillerRabin(rand) {
24069 this.rand = rand || new brorand.Rand();
24070 }
24071 module.exports = MillerRabin;
24072
24073 MillerRabin.create = function create(rand) {
24074 return new MillerRabin(rand);
24075 };
24076
24077 MillerRabin.prototype._randbelow = function _randbelow(n) {
24078 var len = n.bitLength();
24079 var min_bytes = Math.ceil(len / 8);
24080
24081 // Generage random bytes until a number less than n is found.
24082 // This ensures that 0..n-1 have an equal probability of being selected.
24083 do
24084 var a = new bn(this.rand.generate(min_bytes));
24085 while (a.cmp(n) >= 0);
24086
24087 return a;
24088 };
24089
24090 MillerRabin.prototype._randrange = function _randrange(start, stop) {
24091 // Generate a random number greater than or equal to start and less than stop.
24092 var size = stop.sub(start);
24093 return start.add(this._randbelow(size));
24094 };
24095
24096 MillerRabin.prototype.test = function test(n, k, cb) {
24097 var len = n.bitLength();
24098 var red = bn.mont(n);
24099 var rone = new bn(1).toRed(red);
24100
24101 if (!k)
24102 k = Math.max(1, (len / 48) | 0);
24103
24104 // Find d and s, (n - 1) = (2 ^ s) * d;
24105 var n1 = n.subn(1);
24106 for (var s = 0; !n1.testn(s); s++) {}
24107 var d = n.shrn(s);
24108
24109 var rn1 = n1.toRed(red);
24110
24111 var prime = true;
24112 for (; k > 0; k--) {
24113 var a = this._randrange(new bn(2), n1);
24114 if (cb)
24115 cb(a);
24116
24117 var x = a.toRed(red).redPow(d);
24118 if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
24119 continue;
24120
24121 for (var i = 1; i < s; i++) {
24122 x = x.redSqr();
24123
24124 if (x.cmp(rone) === 0)
24125 return false;
24126 if (x.cmp(rn1) === 0)
24127 break;
24128 }
24129
24130 if (i === s)
24131 return false;
24132 }
24133
24134 return prime;
24135 };
24136
24137 MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
24138 var len = n.bitLength();
24139 var red = bn.mont(n);
24140 var rone = new bn(1).toRed(red);
24141
24142 if (!k)
24143 k = Math.max(1, (len / 48) | 0);
24144
24145 // Find d and s, (n - 1) = (2 ^ s) * d;
24146 var n1 = n.subn(1);
24147 for (var s = 0; !n1.testn(s); s++) {}
24148 var d = n.shrn(s);
24149
24150 var rn1 = n1.toRed(red);
24151
24152 for (; k > 0; k--) {
24153 var a = this._randrange(new bn(2), n1);
24154
24155 var g = n.gcd(a);
24156 if (g.cmpn(1) !== 0)
24157 return g;
24158
24159 var x = a.toRed(red).redPow(d);
24160 if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
24161 continue;
24162
24163 for (var i = 1; i < s; i++) {
24164 x = x.redSqr();
24165
24166 if (x.cmp(rone) === 0)
24167 return x.fromRed().subn(1).gcd(n);
24168 if (x.cmp(rn1) === 0)
24169 break;
24170 }
24171
24172 if (i === s) {
24173 x = x.redSqr();
24174 return x.fromRed().subn(1).gcd(n);
24175 }
24176 }
24177
24178 return false;
24179 };
24180
24181 },{"bn.js":79,"brorand":80}],167:[function(require,module,exports){
24182 module.exports = assert;
24183
24184 function assert(val, msg) {
24185 if (!val)
24186 throw new Error(msg || 'Assertion failed');
24187 }
24188
24189 assert.equal = function assertEqual(l, r, msg) {
24190 if (l != r)
24191 throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
24192 };
24193
24194 },{}],168:[function(require,module,exports){
24195 'use strict';
24196
24197 var utils = exports;
24198
24199 function toArray(msg, enc) {
24200 if (Array.isArray(msg))
24201 return msg.slice();
24202 if (!msg)
24203 return [];
24204 var res = [];
24205 if (typeof msg !== 'string') {
24206 for (var i = 0; i < msg.length; i++)
24207 res[i] = msg[i] | 0;
24208 return res;
24209 }
24210 if (enc === 'hex') {
24211 msg = msg.replace(/[^a-z0-9]+/ig, '');
24212 if (msg.length % 2 !== 0)
24213 msg = '0' + msg;
24214 for (var i = 0; i < msg.length; i += 2)
24215 res.push(parseInt(msg[i] + msg[i + 1], 16));
24216 } else {
24217 for (var i = 0; i < msg.length; i++) {
24218 var c = msg.charCodeAt(i);
24219 var hi = c >> 8;
24220 var lo = c & 0xff;
24221 if (hi)
24222 res.push(hi, lo);
24223 else
24224 res.push(lo);
24225 }
24226 }
24227 return res;
24228 }
24229 utils.toArray = toArray;
24230
24231 function zero2(word) {
24232 if (word.length === 1)
24233 return '0' + word;
24234 else
24235 return word;
24236 }
24237 utils.zero2 = zero2;
24238
24239 function toHex(msg) {
24240 var res = '';
24241 for (var i = 0; i < msg.length; i++)
24242 res += zero2(msg[i].toString(16));
24243 return res;
24244 }
24245 utils.toHex = toHex;
24246
24247 utils.encode = function encode(arr, enc) {
24248 if (enc === 'hex')
24249 return toHex(arr);
24250 else
24251 return arr;
24252 };
24253
24254 },{}],169:[function(require,module,exports){
24255 /*
24256 object-assign
24257 (c) Sindre Sorhus
24258 @license MIT
24259 */
24260
24261 'use strict';
24262 /* eslint-disable no-unused-vars */
24263 var getOwnPropertySymbols = Object.getOwnPropertySymbols;
24264 var hasOwnProperty = Object.prototype.hasOwnProperty;
24265 var propIsEnumerable = Object.prototype.propertyIsEnumerable;
24266
24267 function toObject(val) {
24268 if (val === null || val === undefined) {
24269 throw new TypeError('Object.assign cannot be called with null or undefined');
24270 }
24271
24272 return Object(val);
24273 }
24274
24275 function shouldUseNative() {
24276 try {
24277 if (!Object.assign) {
24278 return false;
24279 }
24280
24281 // Detect buggy property enumeration order in older V8 versions.
24282
24283 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
24284 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
24285 test1[5] = 'de';
24286 if (Object.getOwnPropertyNames(test1)[0] === '5') {
24287 return false;
24288 }
24289
24290 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
24291 var test2 = {};
24292 for (var i = 0; i < 10; i++) {
24293 test2['_' + String.fromCharCode(i)] = i;
24294 }
24295 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
24296 return test2[n];
24297 });
24298 if (order2.join('') !== '0123456789') {
24299 return false;
24300 }
24301
24302 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
24303 var test3 = {};
24304 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
24305 test3[letter] = letter;
24306 });
24307 if (Object.keys(Object.assign({}, test3)).join('') !==
24308 'abcdefghijklmnopqrst') {
24309 return false;
24310 }
24311
24312 return true;
24313 } catch (err) {
24314 // We don't expect any of the above to throw, but better to be safe.
24315 return false;
24316 }
24317 }
24318
24319 module.exports = shouldUseNative() ? Object.assign : function (target, source) {
24320 var from;
24321 var to = toObject(target);
24322 var symbols;
24323
24324 for (var s = 1; s < arguments.length; s++) {
24325 from = Object(arguments[s]);
24326
24327 for (var key in from) {
24328 if (hasOwnProperty.call(from, key)) {
24329 to[key] = from[key];
24330 }
24331 }
24332
24333 if (getOwnPropertySymbols) {
24334 symbols = getOwnPropertySymbols(from);
24335 for (var i = 0; i < symbols.length; i++) {
24336 if (propIsEnumerable.call(from, symbols[i])) {
24337 to[symbols[i]] = from[symbols[i]];
24338 }
24339 }
24340 }
24341 }
24342
24343 return to;
24344 };
24345
24346 },{}],170:[function(require,module,exports){
24347 module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
24348 "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
24349 "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
24350 "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
24351 "2.16.840.1.101.3.4.1.21": "aes-192-ecb",
24352 "2.16.840.1.101.3.4.1.22": "aes-192-cbc",
24353 "2.16.840.1.101.3.4.1.23": "aes-192-ofb",
24354 "2.16.840.1.101.3.4.1.24": "aes-192-cfb",
24355 "2.16.840.1.101.3.4.1.41": "aes-256-ecb",
24356 "2.16.840.1.101.3.4.1.42": "aes-256-cbc",
24357 "2.16.840.1.101.3.4.1.43": "aes-256-ofb",
24358 "2.16.840.1.101.3.4.1.44": "aes-256-cfb"
24359 }
24360 },{}],171:[function(require,module,exports){
24361 // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
24362 // Fedor, you are amazing.
24363 'use strict'
24364
24365 var asn1 = require('asn1.js')
24366
24367 exports.certificate = require('./certificate')
24368
24369 var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
24370 this.seq().obj(
24371 this.key('version').int(),
24372 this.key('modulus').int(),
24373 this.key('publicExponent').int(),
24374 this.key('privateExponent').int(),
24375 this.key('prime1').int(),
24376 this.key('prime2').int(),
24377 this.key('exponent1').int(),
24378 this.key('exponent2').int(),
24379 this.key('coefficient').int()
24380 )
24381 })
24382 exports.RSAPrivateKey = RSAPrivateKey
24383
24384 var RSAPublicKey = asn1.define('RSAPublicKey', function () {
24385 this.seq().obj(
24386 this.key('modulus').int(),
24387 this.key('publicExponent').int()
24388 )
24389 })
24390 exports.RSAPublicKey = RSAPublicKey
24391
24392 var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
24393 this.seq().obj(
24394 this.key('algorithm').use(AlgorithmIdentifier),
24395 this.key('subjectPublicKey').bitstr()
24396 )
24397 })
24398 exports.PublicKey = PublicKey
24399
24400 var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
24401 this.seq().obj(
24402 this.key('algorithm').objid(),
24403 this.key('none').null_().optional(),
24404 this.key('curve').objid().optional(),
24405 this.key('params').seq().obj(
24406 this.key('p').int(),
24407 this.key('q').int(),
24408 this.key('g').int()
24409 ).optional()
24410 )
24411 })
24412
24413 var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
24414 this.seq().obj(
24415 this.key('version').int(),
24416 this.key('algorithm').use(AlgorithmIdentifier),
24417 this.key('subjectPrivateKey').octstr()
24418 )
24419 })
24420 exports.PrivateKey = PrivateKeyInfo
24421 var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
24422 this.seq().obj(
24423 this.key('algorithm').seq().obj(
24424 this.key('id').objid(),
24425 this.key('decrypt').seq().obj(
24426 this.key('kde').seq().obj(
24427 this.key('id').objid(),
24428 this.key('kdeparams').seq().obj(
24429 this.key('salt').octstr(),
24430 this.key('iters').int()
24431 )
24432 ),
24433 this.key('cipher').seq().obj(
24434 this.key('algo').objid(),
24435 this.key('iv').octstr()
24436 )
24437 )
24438 ),
24439 this.key('subjectPrivateKey').octstr()
24440 )
24441 })
24442
24443 exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo
24444
24445 var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
24446 this.seq().obj(
24447 this.key('version').int(),
24448 this.key('p').int(),
24449 this.key('q').int(),
24450 this.key('g').int(),
24451 this.key('pub_key').int(),
24452 this.key('priv_key').int()
24453 )
24454 })
24455 exports.DSAPrivateKey = DSAPrivateKey
24456
24457 exports.DSAparam = asn1.define('DSAparam', function () {
24458 this.int()
24459 })
24460
24461 var ECPrivateKey = asn1.define('ECPrivateKey', function () {
24462 this.seq().obj(
24463 this.key('version').int(),
24464 this.key('privateKey').octstr(),
24465 this.key('parameters').optional().explicit(0).use(ECParameters),
24466 this.key('publicKey').optional().explicit(1).bitstr()
24467 )
24468 })
24469 exports.ECPrivateKey = ECPrivateKey
24470
24471 var ECParameters = asn1.define('ECParameters', function () {
24472 this.choice({
24473 namedCurve: this.objid()
24474 })
24475 })
24476
24477 exports.signature = asn1.define('signature', function () {
24478 this.seq().obj(
24479 this.key('r').int(),
24480 this.key('s').int()
24481 )
24482 })
24483
24484 },{"./certificate":172,"asn1.js":60}],172:[function(require,module,exports){
24485 // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
24486 // thanks to @Rantanen
24487
24488 'use strict'
24489
24490 var asn = require('asn1.js')
24491
24492 var Time = asn.define('Time', function () {
24493 this.choice({
24494 utcTime: this.utctime(),
24495 generalTime: this.gentime()
24496 })
24497 })
24498
24499 var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
24500 this.seq().obj(
24501 this.key('type').objid(),
24502 this.key('value').any()
24503 )
24504 })
24505
24506 var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
24507 this.seq().obj(
24508 this.key('algorithm').objid(),
24509 this.key('parameters').optional(),
24510 this.key('curve').objid().optional()
24511 )
24512 })
24513
24514 var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
24515 this.seq().obj(
24516 this.key('algorithm').use(AlgorithmIdentifier),
24517 this.key('subjectPublicKey').bitstr()
24518 )
24519 })
24520
24521 var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
24522 this.setof(AttributeTypeValue)
24523 })
24524
24525 var RDNSequence = asn.define('RDNSequence', function () {
24526 this.seqof(RelativeDistinguishedName)
24527 })
24528
24529 var Name = asn.define('Name', function () {
24530 this.choice({
24531 rdnSequence: this.use(RDNSequence)
24532 })
24533 })
24534
24535 var Validity = asn.define('Validity', function () {
24536 this.seq().obj(
24537 this.key('notBefore').use(Time),
24538 this.key('notAfter').use(Time)
24539 )
24540 })
24541
24542 var Extension = asn.define('Extension', function () {
24543 this.seq().obj(
24544 this.key('extnID').objid(),
24545 this.key('critical').bool().def(false),
24546 this.key('extnValue').octstr()
24547 )
24548 })
24549
24550 var TBSCertificate = asn.define('TBSCertificate', function () {
24551 this.seq().obj(
24552 this.key('version').explicit(0).int().optional(),
24553 this.key('serialNumber').int(),
24554 this.key('signature').use(AlgorithmIdentifier),
24555 this.key('issuer').use(Name),
24556 this.key('validity').use(Validity),
24557 this.key('subject').use(Name),
24558 this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo),
24559 this.key('issuerUniqueID').implicit(1).bitstr().optional(),
24560 this.key('subjectUniqueID').implicit(2).bitstr().optional(),
24561 this.key('extensions').explicit(3).seqof(Extension).optional()
24562 )
24563 })
24564
24565 var X509Certificate = asn.define('X509Certificate', function () {
24566 this.seq().obj(
24567 this.key('tbsCertificate').use(TBSCertificate),
24568 this.key('signatureAlgorithm').use(AlgorithmIdentifier),
24569 this.key('signatureValue').bitstr()
24570 )
24571 })
24572
24573 module.exports = X509Certificate
24574
24575 },{"asn1.js":60}],173:[function(require,module,exports){
24576 // adapted from https://github.com/apatil/pemstrip
24577 var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r\+\/\=]+)[\n\r]+/m
24578 var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m
24579 var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r\+\/\=]+)-----END \1-----$/m
24580 var evp = require('evp_bytestokey')
24581 var ciphers = require('browserify-aes')
24582 var Buffer = require('safe-buffer').Buffer
24583 module.exports = function (okey, password) {
24584 var key = okey.toString()
24585 var match = key.match(findProc)
24586 var decrypted
24587 if (!match) {
24588 var match2 = key.match(fullRegex)
24589 decrypted = new Buffer(match2[2].replace(/[\r\n]/g, ''), 'base64')
24590 } else {
24591 var suite = 'aes' + match[1]
24592 var iv = Buffer.from(match[2], 'hex')
24593 var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ''), 'base64')
24594 var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key
24595 var out = []
24596 var cipher = ciphers.createDecipheriv(suite, cipherKey, iv)
24597 out.push(cipher.update(cipherText))
24598 out.push(cipher.final())
24599 decrypted = Buffer.concat(out)
24600 }
24601 var tag = key.match(startRegex)[1]
24602 return {
24603 tag: tag,
24604 data: decrypted
24605 }
24606 }
24607
24608 },{"browserify-aes":84,"evp_bytestokey":146,"safe-buffer":206}],174:[function(require,module,exports){
24609 var asn1 = require('./asn1')
24610 var aesid = require('./aesid.json')
24611 var fixProc = require('./fixProc')
24612 var ciphers = require('browserify-aes')
24613 var compat = require('pbkdf2')
24614 var Buffer = require('safe-buffer').Buffer
24615 module.exports = parseKeys
24616
24617 function parseKeys (buffer) {
24618 var password
24619 if (typeof buffer === 'object' && !Buffer.isBuffer(buffer)) {
24620 password = buffer.passphrase
24621 buffer = buffer.key
24622 }
24623 if (typeof buffer === 'string') {
24624 buffer = Buffer.from(buffer)
24625 }
24626
24627 var stripped = fixProc(buffer, password)
24628
24629 var type = stripped.tag
24630 var data = stripped.data
24631 var subtype, ndata
24632 switch (type) {
24633 case 'CERTIFICATE':
24634 ndata = asn1.certificate.decode(data, 'der').tbsCertificate.subjectPublicKeyInfo
24635 // falls through
24636 case 'PUBLIC KEY':
24637 if (!ndata) {
24638 ndata = asn1.PublicKey.decode(data, 'der')
24639 }
24640 subtype = ndata.algorithm.algorithm.join('.')
24641 switch (subtype) {
24642 case '1.2.840.113549.1.1.1':
24643 return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der')
24644 case '1.2.840.10045.2.1':
24645 ndata.subjectPrivateKey = ndata.subjectPublicKey
24646 return {
24647 type: 'ec',
24648 data: ndata
24649 }
24650 case '1.2.840.10040.4.1':
24651 ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der')
24652 return {
24653 type: 'dsa',
24654 data: ndata.algorithm.params
24655 }
24656 default: throw new Error('unknown key id ' + subtype)
24657 }
24658 throw new Error('unknown key type ' + type)
24659 case 'ENCRYPTED PRIVATE KEY':
24660 data = asn1.EncryptedPrivateKey.decode(data, 'der')
24661 data = decrypt(data, password)
24662 // falls through
24663 case 'PRIVATE KEY':
24664 ndata = asn1.PrivateKey.decode(data, 'der')
24665 subtype = ndata.algorithm.algorithm.join('.')
24666 switch (subtype) {
24667 case '1.2.840.113549.1.1.1':
24668 return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der')
24669 case '1.2.840.10045.2.1':
24670 return {
24671 curve: ndata.algorithm.curve,
24672 privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
24673 }
24674 case '1.2.840.10040.4.1':
24675 ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der')
24676 return {
24677 type: 'dsa',
24678 params: ndata.algorithm.params
24679 }
24680 default: throw new Error('unknown key id ' + subtype)
24681 }
24682 throw new Error('unknown key type ' + type)
24683 case 'RSA PUBLIC KEY':
24684 return asn1.RSAPublicKey.decode(data, 'der')
24685 case 'RSA PRIVATE KEY':
24686 return asn1.RSAPrivateKey.decode(data, 'der')
24687 case 'DSA PRIVATE KEY':
24688 return {
24689 type: 'dsa',
24690 params: asn1.DSAPrivateKey.decode(data, 'der')
24691 }
24692 case 'EC PRIVATE KEY':
24693 data = asn1.ECPrivateKey.decode(data, 'der')
24694 return {
24695 curve: data.parameters.value,
24696 privateKey: data.privateKey
24697 }
24698 default: throw new Error('unknown key type ' + type)
24699 }
24700 }
24701 parseKeys.signature = asn1.signature
24702 function decrypt (data, password) {
24703 var salt = data.algorithm.decrypt.kde.kdeparams.salt
24704 var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10)
24705 var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')]
24706 var iv = data.algorithm.decrypt.cipher.iv
24707 var cipherText = data.subjectPrivateKey
24708 var keylen = parseInt(algo.split('-')[1], 10) / 8
24709 var key = compat.pbkdf2Sync(password, salt, iters, keylen, 'sha1')
24710 var cipher = ciphers.createDecipheriv(algo, key, iv)
24711 var out = []
24712 out.push(cipher.update(cipherText))
24713 out.push(cipher.final())
24714 return Buffer.concat(out)
24715 }
24716
24717 },{"./aesid.json":170,"./asn1":171,"./fixProc":173,"browserify-aes":84,"pbkdf2":175,"safe-buffer":206}],175:[function(require,module,exports){
24718 exports.pbkdf2 = require('./lib/async')
24719 exports.pbkdf2Sync = require('./lib/sync')
24720
24721 },{"./lib/async":176,"./lib/sync":179}],176:[function(require,module,exports){
24722 (function (process,global){
24723 var checkParameters = require('./precondition')
24724 var defaultEncoding = require('./default-encoding')
24725 var sync = require('./sync')
24726 var Buffer = require('safe-buffer').Buffer
24727
24728 var ZERO_BUF
24729 var subtle = global.crypto && global.crypto.subtle
24730 var toBrowser = {
24731 'sha': 'SHA-1',
24732 'sha-1': 'SHA-1',
24733 'sha1': 'SHA-1',
24734 'sha256': 'SHA-256',
24735 'sha-256': 'SHA-256',
24736 'sha384': 'SHA-384',
24737 'sha-384': 'SHA-384',
24738 'sha-512': 'SHA-512',
24739 'sha512': 'SHA-512'
24740 }
24741 var checks = []
24742 function checkNative (algo) {
24743 if (global.process && !global.process.browser) {
24744 return Promise.resolve(false)
24745 }
24746 if (!subtle || !subtle.importKey || !subtle.deriveBits) {
24747 return Promise.resolve(false)
24748 }
24749 if (checks[algo] !== undefined) {
24750 return checks[algo]
24751 }
24752 ZERO_BUF = ZERO_BUF || Buffer.alloc(8)
24753 var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo)
24754 .then(function () {
24755 return true
24756 }).catch(function () {
24757 return false
24758 })
24759 checks[algo] = prom
24760 return prom
24761 }
24762
24763 function browserPbkdf2 (password, salt, iterations, length, algo) {
24764 return subtle.importKey(
24765 'raw', password, {name: 'PBKDF2'}, false, ['deriveBits']
24766 ).then(function (key) {
24767 return subtle.deriveBits({
24768 name: 'PBKDF2',
24769 salt: salt,
24770 iterations: iterations,
24771 hash: {
24772 name: algo
24773 }
24774 }, key, length << 3)
24775 }).then(function (res) {
24776 return Buffer.from(res)
24777 })
24778 }
24779
24780 function resolvePromise (promise, callback) {
24781 promise.then(function (out) {
24782 process.nextTick(function () {
24783 callback(null, out)
24784 })
24785 }, function (e) {
24786 process.nextTick(function () {
24787 callback(e)
24788 })
24789 })
24790 }
24791 module.exports = function (password, salt, iterations, keylen, digest, callback) {
24792 if (typeof digest === 'function') {
24793 callback = digest
24794 digest = undefined
24795 }
24796
24797 digest = digest || 'sha1'
24798 var algo = toBrowser[digest.toLowerCase()]
24799
24800 if (!algo || typeof global.Promise !== 'function') {
24801 return process.nextTick(function () {
24802 var out
24803 try {
24804 out = sync(password, salt, iterations, keylen, digest)
24805 } catch (e) {
24806 return callback(e)
24807 }
24808 callback(null, out)
24809 })
24810 }
24811
24812 checkParameters(password, salt, iterations, keylen)
24813 if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
24814 if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
24815 if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
24816
24817 resolvePromise(checkNative(algo).then(function (resp) {
24818 if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo)
24819
24820 return sync(password, salt, iterations, keylen, digest)
24821 }), callback)
24822 }
24823
24824 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
24825 },{"./default-encoding":177,"./precondition":178,"./sync":179,"_process":181,"safe-buffer":206}],177:[function(require,module,exports){
24826 (function (process){
24827 var defaultEncoding
24828 /* istanbul ignore next */
24829 if (process.browser) {
24830 defaultEncoding = 'utf-8'
24831 } else {
24832 var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10)
24833
24834 defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'
24835 }
24836 module.exports = defaultEncoding
24837
24838 }).call(this,require('_process'))
24839 },{"_process":181}],178:[function(require,module,exports){
24840 (function (Buffer){
24841 var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
24842
24843 function checkBuffer (buf, name) {
24844 if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
24845 throw new TypeError(name + ' must be a buffer or string')
24846 }
24847 }
24848
24849 module.exports = function (password, salt, iterations, keylen) {
24850 checkBuffer(password, 'Password')
24851 checkBuffer(salt, 'Salt')
24852
24853 if (typeof iterations !== 'number') {
24854 throw new TypeError('Iterations not a number')
24855 }
24856
24857 if (iterations < 0) {
24858 throw new TypeError('Bad iterations')
24859 }
24860
24861 if (typeof keylen !== 'number') {
24862 throw new TypeError('Key length not a number')
24863 }
24864
24865 if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */
24866 throw new TypeError('Bad key length')
24867 }
24868 }
24869
24870 }).call(this,{"isBuffer":require("../../is-buffer/index.js")})
24871 },{"../../is-buffer/index.js":163}],179:[function(require,module,exports){
24872 var md5 = require('create-hash/md5')
24873 var RIPEMD160 = require('ripemd160')
24874 var sha = require('sha.js')
24875
24876 var checkParameters = require('./precondition')
24877 var defaultEncoding = require('./default-encoding')
24878 var Buffer = require('safe-buffer').Buffer
24879 var ZEROS = Buffer.alloc(128)
24880 var sizes = {
24881 md5: 16,
24882 sha1: 20,
24883 sha224: 28,
24884 sha256: 32,
24885 sha384: 48,
24886 sha512: 64,
24887 rmd160: 20,
24888 ripemd160: 20
24889 }
24890
24891 function Hmac (alg, key, saltLen) {
24892 var hash = getDigest(alg)
24893 var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
24894
24895 if (key.length > blocksize) {
24896 key = hash(key)
24897 } else if (key.length < blocksize) {
24898 key = Buffer.concat([key, ZEROS], blocksize)
24899 }
24900
24901 var ipad = Buffer.allocUnsafe(blocksize + sizes[alg])
24902 var opad = Buffer.allocUnsafe(blocksize + sizes[alg])
24903 for (var i = 0; i < blocksize; i++) {
24904 ipad[i] = key[i] ^ 0x36
24905 opad[i] = key[i] ^ 0x5C
24906 }
24907
24908 var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4)
24909 ipad.copy(ipad1, 0, 0, blocksize)
24910 this.ipad1 = ipad1
24911 this.ipad2 = ipad
24912 this.opad = opad
24913 this.alg = alg
24914 this.blocksize = blocksize
24915 this.hash = hash
24916 this.size = sizes[alg]
24917 }
24918
24919 Hmac.prototype.run = function (data, ipad) {
24920 data.copy(ipad, this.blocksize)
24921 var h = this.hash(ipad)
24922 h.copy(this.opad, this.blocksize)
24923 return this.hash(this.opad)
24924 }
24925
24926 function getDigest (alg) {
24927 function shaFunc (data) {
24928 return sha(alg).update(data).digest()
24929 }
24930 function rmd160Func (data) {
24931 return new RIPEMD160().update(data).digest()
24932 }
24933
24934 if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func
24935 if (alg === 'md5') return md5
24936 return shaFunc
24937 }
24938
24939 function pbkdf2 (password, salt, iterations, keylen, digest) {
24940 checkParameters(password, salt, iterations, keylen)
24941
24942 if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
24943 if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
24944
24945 digest = digest || 'sha1'
24946
24947 var hmac = new Hmac(digest, password, salt.length)
24948
24949 var DK = Buffer.allocUnsafe(keylen)
24950 var block1 = Buffer.allocUnsafe(salt.length + 4)
24951 salt.copy(block1, 0, 0, salt.length)
24952
24953 var destPos = 0
24954 var hLen = sizes[digest]
24955 var l = Math.ceil(keylen / hLen)
24956
24957 for (var i = 1; i <= l; i++) {
24958 block1.writeUInt32BE(i, salt.length)
24959
24960 var T = hmac.run(block1, hmac.ipad1)
24961 var U = T
24962
24963 for (var j = 1; j < iterations; j++) {
24964 U = hmac.run(U, hmac.ipad2)
24965 for (var k = 0; k < hLen; k++) T[k] ^= U[k]
24966 }
24967
24968 T.copy(DK, destPos)
24969 destPos += hLen
24970 }
24971
24972 return DK
24973 }
24974
24975 module.exports = pbkdf2
24976
24977 },{"./default-encoding":177,"./precondition":178,"create-hash/md5":115,"ripemd160":205,"safe-buffer":206,"sha.js":208}],180:[function(require,module,exports){
24978 (function (process){
24979 'use strict';
24980
24981 if (typeof process === 'undefined' ||
24982 !process.version ||
24983 process.version.indexOf('v0.') === 0 ||
24984 process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
24985 module.exports = { nextTick: nextTick };
24986 } else {
24987 module.exports = process
24988 }
24989
24990 function nextTick(fn, arg1, arg2, arg3) {
24991 if (typeof fn !== 'function') {
24992 throw new TypeError('"callback" argument must be a function');
24993 }
24994 var len = arguments.length;
24995 var args, i;
24996 switch (len) {
24997 case 0:
24998 case 1:
24999 return process.nextTick(fn);
25000 case 2:
25001 return process.nextTick(function afterTickOne() {
25002 fn.call(null, arg1);
25003 });
25004 case 3:
25005 return process.nextTick(function afterTickTwo() {
25006 fn.call(null, arg1, arg2);
25007 });
25008 case 4:
25009 return process.nextTick(function afterTickThree() {
25010 fn.call(null, arg1, arg2, arg3);
25011 });
25012 default:
25013 args = new Array(len - 1);
25014 i = 0;
25015 while (i < args.length) {
25016 args[i++] = arguments[i];
25017 }
25018 return process.nextTick(function afterTick() {
25019 fn.apply(null, args);
25020 });
25021 }
25022 }
25023
25024
25025 }).call(this,require('_process'))
25026 },{"_process":181}],181:[function(require,module,exports){
25027 // shim for using process in browser
25028 var process = module.exports = {};
25029
25030 // cached from whatever global is present so that test runners that stub it
25031 // don't break things. But we need to wrap it in a try catch in case it is
25032 // wrapped in strict mode code which doesn't define any globals. It's inside a
25033 // function because try/catches deoptimize in certain engines.
25034
25035 var cachedSetTimeout;
25036 var cachedClearTimeout;
25037
25038 function defaultSetTimout() {
25039 throw new Error('setTimeout has not been defined');
25040 }
25041 function defaultClearTimeout () {
25042 throw new Error('clearTimeout has not been defined');
25043 }
25044 (function () {
25045 try {
25046 if (typeof setTimeout === 'function') {
25047 cachedSetTimeout = setTimeout;
25048 } else {
25049 cachedSetTimeout = defaultSetTimout;
25050 }
25051 } catch (e) {
25052 cachedSetTimeout = defaultSetTimout;
25053 }
25054 try {
25055 if (typeof clearTimeout === 'function') {
25056 cachedClearTimeout = clearTimeout;
25057 } else {
25058 cachedClearTimeout = defaultClearTimeout;
25059 }
25060 } catch (e) {
25061 cachedClearTimeout = defaultClearTimeout;
25062 }
25063 } ())
25064 function runTimeout(fun) {
25065 if (cachedSetTimeout === setTimeout) {
25066 //normal enviroments in sane situations
25067 return setTimeout(fun, 0);
25068 }
25069 // if setTimeout wasn't available but was latter defined
25070 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
25071 cachedSetTimeout = setTimeout;
25072 return setTimeout(fun, 0);
25073 }
25074 try {
25075 // when when somebody has screwed with setTimeout but no I.E. maddness
25076 return cachedSetTimeout(fun, 0);
25077 } catch(e){
25078 try {
25079 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
25080 return cachedSetTimeout.call(null, fun, 0);
25081 } catch(e){
25082 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
25083 return cachedSetTimeout.call(this, fun, 0);
25084 }
25085 }
25086
25087
25088 }
25089 function runClearTimeout(marker) {
25090 if (cachedClearTimeout === clearTimeout) {
25091 //normal enviroments in sane situations
25092 return clearTimeout(marker);
25093 }
25094 // if clearTimeout wasn't available but was latter defined
25095 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
25096 cachedClearTimeout = clearTimeout;
25097 return clearTimeout(marker);
25098 }
25099 try {
25100 // when when somebody has screwed with setTimeout but no I.E. maddness
25101 return cachedClearTimeout(marker);
25102 } catch (e){
25103 try {
25104 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
25105 return cachedClearTimeout.call(null, marker);
25106 } catch (e){
25107 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
25108 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
25109 return cachedClearTimeout.call(this, marker);
25110 }
25111 }
25112
25113
25114
25115 }
25116 var queue = [];
25117 var draining = false;
25118 var currentQueue;
25119 var queueIndex = -1;
25120
25121 function cleanUpNextTick() {
25122 if (!draining || !currentQueue) {
25123 return;
25124 }
25125 draining = false;
25126 if (currentQueue.length) {
25127 queue = currentQueue.concat(queue);
25128 } else {
25129 queueIndex = -1;
25130 }
25131 if (queue.length) {
25132 drainQueue();
25133 }
25134 }
25135
25136 function drainQueue() {
25137 if (draining) {
25138 return;
25139 }
25140 var timeout = runTimeout(cleanUpNextTick);
25141 draining = true;
25142
25143 var len = queue.length;
25144 while(len) {
25145 currentQueue = queue;
25146 queue = [];
25147 while (++queueIndex < len) {
25148 if (currentQueue) {
25149 currentQueue[queueIndex].run();
25150 }
25151 }
25152 queueIndex = -1;
25153 len = queue.length;
25154 }
25155 currentQueue = null;
25156 draining = false;
25157 runClearTimeout(timeout);
25158 }
25159
25160 process.nextTick = function (fun) {
25161 var args = new Array(arguments.length - 1);
25162 if (arguments.length > 1) {
25163 for (var i = 1; i < arguments.length; i++) {
25164 args[i - 1] = arguments[i];
25165 }
25166 }
25167 queue.push(new Item(fun, args));
25168 if (queue.length === 1 && !draining) {
25169 runTimeout(drainQueue);
25170 }
25171 };
25172
25173 // v8 likes predictible objects
25174 function Item(fun, array) {
25175 this.fun = fun;
25176 this.array = array;
25177 }
25178 Item.prototype.run = function () {
25179 this.fun.apply(null, this.array);
25180 };
25181 process.title = 'browser';
25182 process.browser = true;
25183 process.env = {};
25184 process.argv = [];
25185 process.version = ''; // empty string to avoid regexp issues
25186 process.versions = {};
25187
25188 function noop() {}
25189
25190 process.on = noop;
25191 process.addListener = noop;
25192 process.once = noop;
25193 process.off = noop;
25194 process.removeListener = noop;
25195 process.removeAllListeners = noop;
25196 process.emit = noop;
25197 process.prependListener = noop;
25198 process.prependOnceListener = noop;
25199
25200 process.listeners = function (name) { return [] }
25201
25202 process.binding = function (name) {
25203 throw new Error('process.binding is not supported');
25204 };
25205
25206 process.cwd = function () { return '/' };
25207 process.chdir = function (dir) {
25208 throw new Error('process.chdir is not supported');
25209 };
25210 process.umask = function() { return 0; };
25211
25212 },{}],182:[function(require,module,exports){
25213 exports.publicEncrypt = require('./publicEncrypt')
25214 exports.privateDecrypt = require('./privateDecrypt')
25215
25216 exports.privateEncrypt = function privateEncrypt (key, buf) {
25217 return exports.publicEncrypt(key, buf, true)
25218 }
25219
25220 exports.publicDecrypt = function publicDecrypt (key, buf) {
25221 return exports.privateDecrypt(key, buf, true)
25222 }
25223
25224 },{"./privateDecrypt":184,"./publicEncrypt":185}],183:[function(require,module,exports){
25225 var createHash = require('create-hash')
25226 var Buffer = require('safe-buffer').Buffer
25227
25228 module.exports = function (seed, len) {
25229 var t = Buffer.alloc(0)
25230 var i = 0
25231 var c
25232 while (t.length < len) {
25233 c = i2ops(i++)
25234 t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()])
25235 }
25236 return t.slice(0, len)
25237 }
25238
25239 function i2ops (c) {
25240 var out = Buffer.allocUnsafe(4)
25241 out.writeUInt32BE(c, 0)
25242 return out
25243 }
25244
25245 },{"create-hash":114,"safe-buffer":206}],184:[function(require,module,exports){
25246 var parseKeys = require('parse-asn1')
25247 var mgf = require('./mgf')
25248 var xor = require('./xor')
25249 var BN = require('bn.js')
25250 var crt = require('browserify-rsa')
25251 var createHash = require('create-hash')
25252 var withPublic = require('./withPublic')
25253 var Buffer = require('safe-buffer').Buffer
25254
25255 module.exports = function privateDecrypt (privateKey, enc, reverse) {
25256 var padding
25257 if (privateKey.padding) {
25258 padding = privateKey.padding
25259 } else if (reverse) {
25260 padding = 1
25261 } else {
25262 padding = 4
25263 }
25264
25265 var key = parseKeys(privateKey)
25266 var k = key.modulus.byteLength()
25267 if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) {
25268 throw new Error('decryption error')
25269 }
25270 var msg
25271 if (reverse) {
25272 msg = withPublic(new BN(enc), key)
25273 } else {
25274 msg = crt(enc, key)
25275 }
25276 var zBuffer = Buffer.alloc(k - msg.length)
25277 msg = Buffer.concat([zBuffer, msg], k)
25278 if (padding === 4) {
25279 return oaep(key, msg)
25280 } else if (padding === 1) {
25281 return pkcs1(key, msg, reverse)
25282 } else if (padding === 3) {
25283 return msg
25284 } else {
25285 throw new Error('unknown padding')
25286 }
25287 }
25288
25289 function oaep (key, msg) {
25290 var k = key.modulus.byteLength()
25291 var iHash = createHash('sha1').update(Buffer.alloc(0)).digest()
25292 var hLen = iHash.length
25293 if (msg[0] !== 0) {
25294 throw new Error('decryption error')
25295 }
25296 var maskedSeed = msg.slice(1, hLen + 1)
25297 var maskedDb = msg.slice(hLen + 1)
25298 var seed = xor(maskedSeed, mgf(maskedDb, hLen))
25299 var db = xor(maskedDb, mgf(seed, k - hLen - 1))
25300 if (compare(iHash, db.slice(0, hLen))) {
25301 throw new Error('decryption error')
25302 }
25303 var i = hLen
25304 while (db[i] === 0) {
25305 i++
25306 }
25307 if (db[i++] !== 1) {
25308 throw new Error('decryption error')
25309 }
25310 return db.slice(i)
25311 }
25312
25313 function pkcs1 (key, msg, reverse) {
25314 var p1 = msg.slice(0, 2)
25315 var i = 2
25316 var status = 0
25317 while (msg[i++] !== 0) {
25318 if (i >= msg.length) {
25319 status++
25320 break
25321 }
25322 }
25323 var ps = msg.slice(2, i - 1)
25324
25325 if ((p1.toString('hex') !== '0002' && !reverse) || (p1.toString('hex') !== '0001' && reverse)) {
25326 status++
25327 }
25328 if (ps.length < 8) {
25329 status++
25330 }
25331 if (status) {
25332 throw new Error('decryption error')
25333 }
25334 return msg.slice(i)
25335 }
25336 function compare (a, b) {
25337 a = Buffer.from(a)
25338 b = Buffer.from(b)
25339 var dif = 0
25340 var len = a.length
25341 if (a.length !== b.length) {
25342 dif++
25343 len = Math.min(a.length, b.length)
25344 }
25345 var i = -1
25346 while (++i < len) {
25347 dif += (a[i] ^ b[i])
25348 }
25349 return dif
25350 }
25351
25352 },{"./mgf":183,"./withPublic":186,"./xor":187,"bn.js":79,"browserify-rsa":102,"create-hash":114,"parse-asn1":174,"safe-buffer":206}],185:[function(require,module,exports){
25353 var parseKeys = require('parse-asn1')
25354 var randomBytes = require('randombytes')
25355 var createHash = require('create-hash')
25356 var mgf = require('./mgf')
25357 var xor = require('./xor')
25358 var BN = require('bn.js')
25359 var withPublic = require('./withPublic')
25360 var crt = require('browserify-rsa')
25361 var Buffer = require('safe-buffer').Buffer
25362
25363 module.exports = function publicEncrypt (publicKey, msg, reverse) {
25364 var padding
25365 if (publicKey.padding) {
25366 padding = publicKey.padding
25367 } else if (reverse) {
25368 padding = 1
25369 } else {
25370 padding = 4
25371 }
25372 var key = parseKeys(publicKey)
25373 var paddedMsg
25374 if (padding === 4) {
25375 paddedMsg = oaep(key, msg)
25376 } else if (padding === 1) {
25377 paddedMsg = pkcs1(key, msg, reverse)
25378 } else if (padding === 3) {
25379 paddedMsg = new BN(msg)
25380 if (paddedMsg.cmp(key.modulus) >= 0) {
25381 throw new Error('data too long for modulus')
25382 }
25383 } else {
25384 throw new Error('unknown padding')
25385 }
25386 if (reverse) {
25387 return crt(paddedMsg, key)
25388 } else {
25389 return withPublic(paddedMsg, key)
25390 }
25391 }
25392
25393 function oaep (key, msg) {
25394 var k = key.modulus.byteLength()
25395 var mLen = msg.length
25396 var iHash = createHash('sha1').update(Buffer.alloc(0)).digest()
25397 var hLen = iHash.length
25398 var hLen2 = 2 * hLen
25399 if (mLen > k - hLen2 - 2) {
25400 throw new Error('message too long')
25401 }
25402 var ps = Buffer.alloc(k - mLen - hLen2 - 2)
25403 var dblen = k - hLen - 1
25404 var seed = randomBytes(hLen)
25405 var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen))
25406 var maskedSeed = xor(seed, mgf(maskedDb, hLen))
25407 return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k))
25408 }
25409 function pkcs1 (key, msg, reverse) {
25410 var mLen = msg.length
25411 var k = key.modulus.byteLength()
25412 if (mLen > k - 11) {
25413 throw new Error('message too long')
25414 }
25415 var ps
25416 if (reverse) {
25417 ps = Buffer.alloc(k - mLen - 3, 0xff)
25418 } else {
25419 ps = nonZero(k - mLen - 3)
25420 }
25421 return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k))
25422 }
25423 function nonZero (len) {
25424 var out = Buffer.allocUnsafe(len)
25425 var i = 0
25426 var cache = randomBytes(len * 2)
25427 var cur = 0
25428 var num
25429 while (i < len) {
25430 if (cur === cache.length) {
25431 cache = randomBytes(len * 2)
25432 cur = 0
25433 }
25434 num = cache[cur++]
25435 if (num) {
25436 out[i++] = num
25437 }
25438 }
25439 return out
25440 }
25441
25442 },{"./mgf":183,"./withPublic":186,"./xor":187,"bn.js":79,"browserify-rsa":102,"create-hash":114,"parse-asn1":174,"randombytes":188,"safe-buffer":206}],186:[function(require,module,exports){
25443 var BN = require('bn.js')
25444 var Buffer = require('safe-buffer').Buffer
25445
25446 function withPublic (paddedMsg, key) {
25447 return Buffer.from(paddedMsg
25448 .toRed(BN.mont(key.modulus))
25449 .redPow(new BN(key.publicExponent))
25450 .fromRed()
25451 .toArray())
25452 }
25453
25454 module.exports = withPublic
25455
25456 },{"bn.js":79,"safe-buffer":206}],187:[function(require,module,exports){
25457 module.exports = function xor (a, b) {
25458 var len = a.length
25459 var i = -1
25460 while (++i < len) {
25461 a[i] ^= b[i]
25462 }
25463 return a
25464 }
25465
25466 },{}],188:[function(require,module,exports){
25467 (function (process,global){
25468 'use strict'
25469
25470 // limit of Crypto.getRandomValues()
25471 // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
25472 var MAX_BYTES = 65536
25473
25474 // Node supports requesting up to this number of bytes
25475 // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
25476 var MAX_UINT32 = 4294967295
25477
25478 function oldBrowser () {
25479 throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
25480 }
25481
25482 var Buffer = require('safe-buffer').Buffer
25483 var crypto = global.crypto || global.msCrypto
25484
25485 if (crypto && crypto.getRandomValues) {
25486 module.exports = randomBytes
25487 } else {
25488 module.exports = oldBrowser
25489 }
25490
25491 function randomBytes (size, cb) {
25492 // phantomjs needs to throw
25493 if (size > MAX_UINT32) throw new RangeError('requested too many random bytes')
25494
25495 var bytes = Buffer.allocUnsafe(size)
25496
25497 if (size > 0) { // getRandomValues fails on IE if size == 0
25498 if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues
25499 // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
25500 for (var generated = 0; generated < size; generated += MAX_BYTES) {
25501 // buffer.slice automatically checks if the end is past the end of
25502 // the buffer so we don't have to here
25503 crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES))
25504 }
25505 } else {
25506 crypto.getRandomValues(bytes)
25507 }
25508 }
25509
25510 if (typeof cb === 'function') {
25511 return process.nextTick(function () {
25512 cb(null, bytes)
25513 })
25514 }
25515
25516 return bytes
25517 }
25518
25519 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
25520 },{"_process":181,"safe-buffer":206}],189:[function(require,module,exports){
25521 (function (process,global){
25522 'use strict'
25523
25524 function oldBrowser () {
25525 throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
25526 }
25527 var safeBuffer = require('safe-buffer')
25528 var randombytes = require('randombytes')
25529 var Buffer = safeBuffer.Buffer
25530 var kBufferMaxLength = safeBuffer.kMaxLength
25531 var crypto = global.crypto || global.msCrypto
25532 var kMaxUint32 = Math.pow(2, 32) - 1
25533 function assertOffset (offset, length) {
25534 if (typeof offset !== 'number' || offset !== offset) { // eslint-disable-line no-self-compare
25535 throw new TypeError('offset must be a number')
25536 }
25537
25538 if (offset > kMaxUint32 || offset < 0) {
25539 throw new TypeError('offset must be a uint32')
25540 }
25541
25542 if (offset > kBufferMaxLength || offset > length) {
25543 throw new RangeError('offset out of range')
25544 }
25545 }
25546
25547 function assertSize (size, offset, length) {
25548 if (typeof size !== 'number' || size !== size) { // eslint-disable-line no-self-compare
25549 throw new TypeError('size must be a number')
25550 }
25551
25552 if (size > kMaxUint32 || size < 0) {
25553 throw new TypeError('size must be a uint32')
25554 }
25555
25556 if (size + offset > length || size > kBufferMaxLength) {
25557 throw new RangeError('buffer too small')
25558 }
25559 }
25560 if ((crypto && crypto.getRandomValues) || !process.browser) {
25561 exports.randomFill = randomFill
25562 exports.randomFillSync = randomFillSync
25563 } else {
25564 exports.randomFill = oldBrowser
25565 exports.randomFillSync = oldBrowser
25566 }
25567 function randomFill (buf, offset, size, cb) {
25568 if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
25569 throw new TypeError('"buf" argument must be a Buffer or Uint8Array')
25570 }
25571
25572 if (typeof offset === 'function') {
25573 cb = offset
25574 offset = 0
25575 size = buf.length
25576 } else if (typeof size === 'function') {
25577 cb = size
25578 size = buf.length - offset
25579 } else if (typeof cb !== 'function') {
25580 throw new TypeError('"cb" argument must be a function')
25581 }
25582 assertOffset(offset, buf.length)
25583 assertSize(size, offset, buf.length)
25584 return actualFill(buf, offset, size, cb)
25585 }
25586
25587 function actualFill (buf, offset, size, cb) {
25588 if (process.browser) {
25589 var ourBuf = buf.buffer
25590 var uint = new Uint8Array(ourBuf, offset, size)
25591 crypto.getRandomValues(uint)
25592 if (cb) {
25593 process.nextTick(function () {
25594 cb(null, buf)
25595 })
25596 return
25597 }
25598 return buf
25599 }
25600 if (cb) {
25601 randombytes(size, function (err, bytes) {
25602 if (err) {
25603 return cb(err)
25604 }
25605 bytes.copy(buf, offset)
25606 cb(null, buf)
25607 })
25608 return
25609 }
25610 var bytes = randombytes(size)
25611 bytes.copy(buf, offset)
25612 return buf
25613 }
25614 function randomFillSync (buf, offset, size) {
25615 if (typeof offset === 'undefined') {
25616 offset = 0
25617 }
25618 if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
25619 throw new TypeError('"buf" argument must be a Buffer or Uint8Array')
25620 }
25621
25622 assertOffset(offset, buf.length)
25623
25624 if (size === undefined) size = buf.length - offset
25625
25626 assertSize(size, offset, buf.length)
25627
25628 return actualFill(buf, offset, size)
25629 }
25630
25631 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
25632 },{"_process":181,"randombytes":188,"safe-buffer":206}],190:[function(require,module,exports){
25633 module.exports = require('./lib/_stream_duplex.js');
25634
25635 },{"./lib/_stream_duplex.js":191}],191:[function(require,module,exports){
25636 // Copyright Joyent, Inc. and other Node contributors.
25637 //
25638 // Permission is hereby granted, free of charge, to any person obtaining a
25639 // copy of this software and associated documentation files (the
25640 // "Software"), to deal in the Software without restriction, including
25641 // without limitation the rights to use, copy, modify, merge, publish,
25642 // distribute, sublicense, and/or sell copies of the Software, and to permit
25643 // persons to whom the Software is furnished to do so, subject to the
25644 // following conditions:
25645 //
25646 // The above copyright notice and this permission notice shall be included
25647 // in all copies or substantial portions of the Software.
25648 //
25649 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25650 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25651 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25652 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25653 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25654 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25655 // USE OR OTHER DEALINGS IN THE SOFTWARE.
25656
25657 // a duplex stream is just a stream that is both readable and writable.
25658 // Since JS doesn't have multiple prototypal inheritance, this class
25659 // prototypally inherits from Readable, and then parasitically from
25660 // Writable.
25661
25662 'use strict';
25663
25664 /*<replacement>*/
25665
25666 var pna = require('process-nextick-args');
25667 /*</replacement>*/
25668
25669 /*<replacement>*/
25670 var objectKeys = Object.keys || function (obj) {
25671 var keys = [];
25672 for (var key in obj) {
25673 keys.push(key);
25674 }return keys;
25675 };
25676 /*</replacement>*/
25677
25678 module.exports = Duplex;
25679
25680 /*<replacement>*/
25681 var util = require('core-util-is');
25682 util.inherits = require('inherits');
25683 /*</replacement>*/
25684
25685 var Readable = require('./_stream_readable');
25686 var Writable = require('./_stream_writable');
25687
25688 util.inherits(Duplex, Readable);
25689
25690 {
25691 // avoid scope creep, the keys array can then be collected
25692 var keys = objectKeys(Writable.prototype);
25693 for (var v = 0; v < keys.length; v++) {
25694 var method = keys[v];
25695 if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
25696 }
25697 }
25698
25699 function Duplex(options) {
25700 if (!(this instanceof Duplex)) return new Duplex(options);
25701
25702 Readable.call(this, options);
25703 Writable.call(this, options);
25704
25705 if (options && options.readable === false) this.readable = false;
25706
25707 if (options && options.writable === false) this.writable = false;
25708
25709 this.allowHalfOpen = true;
25710 if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
25711
25712 this.once('end', onend);
25713 }
25714
25715 Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
25716 // making it explicit this property is not enumerable
25717 // because otherwise some prototype manipulation in
25718 // userland will fail
25719 enumerable: false,
25720 get: function () {
25721 return this._writableState.highWaterMark;
25722 }
25723 });
25724
25725 // the no-half-open enforcer
25726 function onend() {
25727 // if we allow half-open state, or if the writable side ended,
25728 // then we're ok.
25729 if (this.allowHalfOpen || this._writableState.ended) return;
25730
25731 // no more data can be written.
25732 // But allow more writes to happen in this tick.
25733 pna.nextTick(onEndNT, this);
25734 }
25735
25736 function onEndNT(self) {
25737 self.end();
25738 }
25739
25740 Object.defineProperty(Duplex.prototype, 'destroyed', {
25741 get: function () {
25742 if (this._readableState === undefined || this._writableState === undefined) {
25743 return false;
25744 }
25745 return this._readableState.destroyed && this._writableState.destroyed;
25746 },
25747 set: function (value) {
25748 // we ignore the value if the stream
25749 // has not been initialized yet
25750 if (this._readableState === undefined || this._writableState === undefined) {
25751 return;
25752 }
25753
25754 // backward compatibility, the user is explicitly
25755 // managing destroyed
25756 this._readableState.destroyed = value;
25757 this._writableState.destroyed = value;
25758 }
25759 });
25760
25761 Duplex.prototype._destroy = function (err, cb) {
25762 this.push(null);
25763 this.end();
25764
25765 pna.nextTick(cb, err);
25766 };
25767 },{"./_stream_readable":193,"./_stream_writable":195,"core-util-is":112,"inherits":162,"process-nextick-args":180}],192:[function(require,module,exports){
25768 // Copyright Joyent, Inc. and other Node contributors.
25769 //
25770 // Permission is hereby granted, free of charge, to any person obtaining a
25771 // copy of this software and associated documentation files (the
25772 // "Software"), to deal in the Software without restriction, including
25773 // without limitation the rights to use, copy, modify, merge, publish,
25774 // distribute, sublicense, and/or sell copies of the Software, and to permit
25775 // persons to whom the Software is furnished to do so, subject to the
25776 // following conditions:
25777 //
25778 // The above copyright notice and this permission notice shall be included
25779 // in all copies or substantial portions of the Software.
25780 //
25781 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25782 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25783 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25784 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25785 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25786 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25787 // USE OR OTHER DEALINGS IN THE SOFTWARE.
25788
25789 // a passthrough stream.
25790 // basically just the most minimal sort of Transform stream.
25791 // Every written chunk gets output as-is.
25792
25793 'use strict';
25794
25795 module.exports = PassThrough;
25796
25797 var Transform = require('./_stream_transform');
25798
25799 /*<replacement>*/
25800 var util = require('core-util-is');
25801 util.inherits = require('inherits');
25802 /*</replacement>*/
25803
25804 util.inherits(PassThrough, Transform);
25805
25806 function PassThrough(options) {
25807 if (!(this instanceof PassThrough)) return new PassThrough(options);
25808
25809 Transform.call(this, options);
25810 }
25811
25812 PassThrough.prototype._transform = function (chunk, encoding, cb) {
25813 cb(null, chunk);
25814 };
25815 },{"./_stream_transform":194,"core-util-is":112,"inherits":162}],193:[function(require,module,exports){
25816 (function (process,global){
25817 // Copyright Joyent, Inc. and other Node contributors.
25818 //
25819 // Permission is hereby granted, free of charge, to any person obtaining a
25820 // copy of this software and associated documentation files (the
25821 // "Software"), to deal in the Software without restriction, including
25822 // without limitation the rights to use, copy, modify, merge, publish,
25823 // distribute, sublicense, and/or sell copies of the Software, and to permit
25824 // persons to whom the Software is furnished to do so, subject to the
25825 // following conditions:
25826 //
25827 // The above copyright notice and this permission notice shall be included
25828 // in all copies or substantial portions of the Software.
25829 //
25830 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25831 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25832 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
25833 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25834 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25835 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25836 // USE OR OTHER DEALINGS IN THE SOFTWARE.
25837
25838 'use strict';
25839
25840 /*<replacement>*/
25841
25842 var pna = require('process-nextick-args');
25843 /*</replacement>*/
25844
25845 module.exports = Readable;
25846
25847 /*<replacement>*/
25848 var isArray = require('isarray');
25849 /*</replacement>*/
25850
25851 /*<replacement>*/
25852 var Duplex;
25853 /*</replacement>*/
25854
25855 Readable.ReadableState = ReadableState;
25856
25857 /*<replacement>*/
25858 var EE = require('events').EventEmitter;
25859
25860 var EElistenerCount = function (emitter, type) {
25861 return emitter.listeners(type).length;
25862 };
25863 /*</replacement>*/
25864
25865 /*<replacement>*/
25866 var Stream = require('./internal/streams/stream');
25867 /*</replacement>*/
25868
25869 /*<replacement>*/
25870
25871 var Buffer = require('safe-buffer').Buffer;
25872 var OurUint8Array = global.Uint8Array || function () {};
25873 function _uint8ArrayToBuffer(chunk) {
25874 return Buffer.from(chunk);
25875 }
25876 function _isUint8Array(obj) {
25877 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
25878 }
25879
25880 /*</replacement>*/
25881
25882 /*<replacement>*/
25883 var util = require('core-util-is');
25884 util.inherits = require('inherits');
25885 /*</replacement>*/
25886
25887 /*<replacement>*/
25888 var debugUtil = require('util');
25889 var debug = void 0;
25890 if (debugUtil && debugUtil.debuglog) {
25891 debug = debugUtil.debuglog('stream');
25892 } else {
25893 debug = function () {};
25894 }
25895 /*</replacement>*/
25896
25897 var BufferList = require('./internal/streams/BufferList');
25898 var destroyImpl = require('./internal/streams/destroy');
25899 var StringDecoder;
25900
25901 util.inherits(Readable, Stream);
25902
25903 var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
25904
25905 function prependListener(emitter, event, fn) {
25906 // Sadly this is not cacheable as some libraries bundle their own
25907 // event emitter implementation with them.
25908 if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
25909
25910 // This is a hack to make sure that our error handler is attached before any
25911 // userland ones. NEVER DO THIS. This is here only because this code needs
25912 // to continue to work with older versions of Node.js that do not include
25913 // the prependListener() method. The goal is to eventually remove this hack.
25914 if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
25915 }
25916
25917 function ReadableState(options, stream) {
25918 Duplex = Duplex || require('./_stream_duplex');
25919
25920 options = options || {};
25921
25922 // Duplex streams are both readable and writable, but share
25923 // the same options object.
25924 // However, some cases require setting options to different
25925 // values for the readable and the writable sides of the duplex stream.
25926 // These options can be provided separately as readableXXX and writableXXX.
25927 var isDuplex = stream instanceof Duplex;
25928
25929 // object stream flag. Used to make read(n) ignore n and to
25930 // make all the buffer merging and length checks go away
25931 this.objectMode = !!options.objectMode;
25932
25933 if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
25934
25935 // the point at which it stops calling _read() to fill the buffer
25936 // Note: 0 is a valid value, means "don't call _read preemptively ever"
25937 var hwm = options.highWaterMark;
25938 var readableHwm = options.readableHighWaterMark;
25939 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
25940
25941 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
25942
25943 // cast to ints.
25944 this.highWaterMark = Math.floor(this.highWaterMark);
25945
25946 // A linked list is used to store data chunks instead of an array because the
25947 // linked list can remove elements from the beginning faster than
25948 // array.shift()
25949 this.buffer = new BufferList();
25950 this.length = 0;
25951 this.pipes = null;
25952 this.pipesCount = 0;
25953 this.flowing = null;
25954 this.ended = false;
25955 this.endEmitted = false;
25956 this.reading = false;
25957
25958 // a flag to be able to tell if the event 'readable'/'data' is emitted
25959 // immediately, or on a later tick. We set this to true at first, because
25960 // any actions that shouldn't happen until "later" should generally also
25961 // not happen before the first read call.
25962 this.sync = true;
25963
25964 // whenever we return null, then we set a flag to say
25965 // that we're awaiting a 'readable' event emission.
25966 this.needReadable = false;
25967 this.emittedReadable = false;
25968 this.readableListening = false;
25969 this.resumeScheduled = false;
25970
25971 // has it been destroyed
25972 this.destroyed = false;
25973
25974 // Crypto is kind of old and crusty. Historically, its default string
25975 // encoding is 'binary' so we have to make this configurable.
25976 // Everything else in the universe uses 'utf8', though.
25977 this.defaultEncoding = options.defaultEncoding || 'utf8';
25978
25979 // the number of writers that are awaiting a drain event in .pipe()s
25980 this.awaitDrain = 0;
25981
25982 // if true, a maybeReadMore has been scheduled
25983 this.readingMore = false;
25984
25985 this.decoder = null;
25986 this.encoding = null;
25987 if (options.encoding) {
25988 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
25989 this.decoder = new StringDecoder(options.encoding);
25990 this.encoding = options.encoding;
25991 }
25992 }
25993
25994 function Readable(options) {
25995 Duplex = Duplex || require('./_stream_duplex');
25996
25997 if (!(this instanceof Readable)) return new Readable(options);
25998
25999 this._readableState = new ReadableState(options, this);
26000
26001 // legacy
26002 this.readable = true;
26003
26004 if (options) {
26005 if (typeof options.read === 'function') this._read = options.read;
26006
26007 if (typeof options.destroy === 'function') this._destroy = options.destroy;
26008 }
26009
26010 Stream.call(this);
26011 }
26012
26013 Object.defineProperty(Readable.prototype, 'destroyed', {
26014 get: function () {
26015 if (this._readableState === undefined) {
26016 return false;
26017 }
26018 return this._readableState.destroyed;
26019 },
26020 set: function (value) {
26021 // we ignore the value if the stream
26022 // has not been initialized yet
26023 if (!this._readableState) {
26024 return;
26025 }
26026
26027 // backward compatibility, the user is explicitly
26028 // managing destroyed
26029 this._readableState.destroyed = value;
26030 }
26031 });
26032
26033 Readable.prototype.destroy = destroyImpl.destroy;
26034 Readable.prototype._undestroy = destroyImpl.undestroy;
26035 Readable.prototype._destroy = function (err, cb) {
26036 this.push(null);
26037 cb(err);
26038 };
26039
26040 // Manually shove something into the read() buffer.
26041 // This returns true if the highWaterMark has not been hit yet,
26042 // similar to how Writable.write() returns true if you should
26043 // write() some more.
26044 Readable.prototype.push = function (chunk, encoding) {
26045 var state = this._readableState;
26046 var skipChunkCheck;
26047
26048 if (!state.objectMode) {
26049 if (typeof chunk === 'string') {
26050 encoding = encoding || state.defaultEncoding;
26051 if (encoding !== state.encoding) {
26052 chunk = Buffer.from(chunk, encoding);
26053 encoding = '';
26054 }
26055 skipChunkCheck = true;
26056 }
26057 } else {
26058 skipChunkCheck = true;
26059 }
26060
26061 return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
26062 };
26063
26064 // Unshift should *always* be something directly out of read()
26065 Readable.prototype.unshift = function (chunk) {
26066 return readableAddChunk(this, chunk, null, true, false);
26067 };
26068
26069 function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
26070 var state = stream._readableState;
26071 if (chunk === null) {
26072 state.reading = false;
26073 onEofChunk(stream, state);
26074 } else {
26075 var er;
26076 if (!skipChunkCheck) er = chunkInvalid(state, chunk);
26077 if (er) {
26078 stream.emit('error', er);
26079 } else if (state.objectMode || chunk && chunk.length > 0) {
26080 if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
26081 chunk = _uint8ArrayToBuffer(chunk);
26082 }
26083
26084 if (addToFront) {
26085 if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
26086 } else if (state.ended) {
26087 stream.emit('error', new Error('stream.push() after EOF'));
26088 } else {
26089 state.reading = false;
26090 if (state.decoder && !encoding) {
26091 chunk = state.decoder.write(chunk);
26092 if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
26093 } else {
26094 addChunk(stream, state, chunk, false);
26095 }
26096 }
26097 } else if (!addToFront) {
26098 state.reading = false;
26099 }
26100 }
26101
26102 return needMoreData(state);
26103 }
26104
26105 function addChunk(stream, state, chunk, addToFront) {
26106 if (state.flowing && state.length === 0 && !state.sync) {
26107 stream.emit('data', chunk);
26108 stream.read(0);
26109 } else {
26110 // update the buffer info.
26111 state.length += state.objectMode ? 1 : chunk.length;
26112 if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
26113
26114 if (state.needReadable) emitReadable(stream);
26115 }
26116 maybeReadMore(stream, state);
26117 }
26118
26119 function chunkInvalid(state, chunk) {
26120 var er;
26121 if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
26122 er = new TypeError('Invalid non-string/buffer chunk');
26123 }
26124 return er;
26125 }
26126
26127 // if it's past the high water mark, we can push in some more.
26128 // Also, if we have no data yet, we can stand some
26129 // more bytes. This is to work around cases where hwm=0,
26130 // such as the repl. Also, if the push() triggered a
26131 // readable event, and the user called read(largeNumber) such that
26132 // needReadable was set, then we ought to push more, so that another
26133 // 'readable' event will be triggered.
26134 function needMoreData(state) {
26135 return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
26136 }
26137
26138 Readable.prototype.isPaused = function () {
26139 return this._readableState.flowing === false;
26140 };
26141
26142 // backwards compatibility.
26143 Readable.prototype.setEncoding = function (enc) {
26144 if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
26145 this._readableState.decoder = new StringDecoder(enc);
26146 this._readableState.encoding = enc;
26147 return this;
26148 };
26149
26150 // Don't raise the hwm > 8MB
26151 var MAX_HWM = 0x800000;
26152 function computeNewHighWaterMark(n) {
26153 if (n >= MAX_HWM) {
26154 n = MAX_HWM;
26155 } else {
26156 // Get the next highest power of 2 to prevent increasing hwm excessively in
26157 // tiny amounts
26158 n--;
26159 n |= n >>> 1;
26160 n |= n >>> 2;
26161 n |= n >>> 4;
26162 n |= n >>> 8;
26163 n |= n >>> 16;
26164 n++;
26165 }
26166 return n;
26167 }
26168
26169 // This function is designed to be inlinable, so please take care when making
26170 // changes to the function body.
26171 function howMuchToRead(n, state) {
26172 if (n <= 0 || state.length === 0 && state.ended) return 0;
26173 if (state.objectMode) return 1;
26174 if (n !== n) {
26175 // Only flow one buffer at a time
26176 if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
26177 }
26178 // If we're asking for more than the current hwm, then raise the hwm.
26179 if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
26180 if (n <= state.length) return n;
26181 // Don't have enough
26182 if (!state.ended) {
26183 state.needReadable = true;
26184 return 0;
26185 }
26186 return state.length;
26187 }
26188
26189 // you can override either this method, or the async _read(n) below.
26190 Readable.prototype.read = function (n) {
26191 debug('read', n);
26192 n = parseInt(n, 10);
26193 var state = this._readableState;
26194 var nOrig = n;
26195
26196 if (n !== 0) state.emittedReadable = false;
26197
26198 // if we're doing read(0) to trigger a readable event, but we
26199 // already have a bunch of data in the buffer, then just trigger
26200 // the 'readable' event and move on.
26201 if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
26202 debug('read: emitReadable', state.length, state.ended);
26203 if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
26204 return null;
26205 }
26206
26207 n = howMuchToRead(n, state);
26208
26209 // if we've ended, and we're now clear, then finish it up.
26210 if (n === 0 && state.ended) {
26211 if (state.length === 0) endReadable(this);
26212 return null;
26213 }
26214
26215 // All the actual chunk generation logic needs to be
26216 // *below* the call to _read. The reason is that in certain
26217 // synthetic stream cases, such as passthrough streams, _read
26218 // may be a completely synchronous operation which may change
26219 // the state of the read buffer, providing enough data when
26220 // before there was *not* enough.
26221 //
26222 // So, the steps are:
26223 // 1. Figure out what the state of things will be after we do
26224 // a read from the buffer.
26225 //
26226 // 2. If that resulting state will trigger a _read, then call _read.
26227 // Note that this may be asynchronous, or synchronous. Yes, it is
26228 // deeply ugly to write APIs this way, but that still doesn't mean
26229 // that the Readable class should behave improperly, as streams are
26230 // designed to be sync/async agnostic.
26231 // Take note if the _read call is sync or async (ie, if the read call
26232 // has returned yet), so that we know whether or not it's safe to emit
26233 // 'readable' etc.
26234 //
26235 // 3. Actually pull the requested chunks out of the buffer and return.
26236
26237 // if we need a readable event, then we need to do some reading.
26238 var doRead = state.needReadable;
26239 debug('need readable', doRead);
26240
26241 // if we currently have less than the highWaterMark, then also read some
26242 if (state.length === 0 || state.length - n < state.highWaterMark) {
26243 doRead = true;
26244 debug('length less than watermark', doRead);
26245 }
26246
26247 // however, if we've ended, then there's no point, and if we're already
26248 // reading, then it's unnecessary.
26249 if (state.ended || state.reading) {
26250 doRead = false;
26251 debug('reading or ended', doRead);
26252 } else if (doRead) {
26253 debug('do read');
26254 state.reading = true;
26255 state.sync = true;
26256 // if the length is currently zero, then we *need* a readable event.
26257 if (state.length === 0) state.needReadable = true;
26258 // call internal read method
26259 this._read(state.highWaterMark);
26260 state.sync = false;
26261 // If _read pushed data synchronously, then `reading` will be false,
26262 // and we need to re-evaluate how much data we can return to the user.
26263 if (!state.reading) n = howMuchToRead(nOrig, state);
26264 }
26265
26266 var ret;
26267 if (n > 0) ret = fromList(n, state);else ret = null;
26268
26269 if (ret === null) {
26270 state.needReadable = true;
26271 n = 0;
26272 } else {
26273 state.length -= n;
26274 }
26275
26276 if (state.length === 0) {
26277 // If we have nothing in the buffer, then we want to know
26278 // as soon as we *do* get something into the buffer.
26279 if (!state.ended) state.needReadable = true;
26280
26281 // If we tried to read() past the EOF, then emit end on the next tick.
26282 if (nOrig !== n && state.ended) endReadable(this);
26283 }
26284
26285 if (ret !== null) this.emit('data', ret);
26286
26287 return ret;
26288 };
26289
26290 function onEofChunk(stream, state) {
26291 if (state.ended) return;
26292 if (state.decoder) {
26293 var chunk = state.decoder.end();
26294 if (chunk && chunk.length) {
26295 state.buffer.push(chunk);
26296 state.length += state.objectMode ? 1 : chunk.length;
26297 }
26298 }
26299 state.ended = true;
26300
26301 // emit 'readable' now to make sure it gets picked up.
26302 emitReadable(stream);
26303 }
26304
26305 // Don't emit readable right away in sync mode, because this can trigger
26306 // another read() call => stack overflow. This way, it might trigger
26307 // a nextTick recursion warning, but that's not so bad.
26308 function emitReadable(stream) {
26309 var state = stream._readableState;
26310 state.needReadable = false;
26311 if (!state.emittedReadable) {
26312 debug('emitReadable', state.flowing);
26313 state.emittedReadable = true;
26314 if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
26315 }
26316 }
26317
26318 function emitReadable_(stream) {
26319 debug('emit readable');
26320 stream.emit('readable');
26321 flow(stream);
26322 }
26323
26324 // at this point, the user has presumably seen the 'readable' event,
26325 // and called read() to consume some data. that may have triggered
26326 // in turn another _read(n) call, in which case reading = true if
26327 // it's in progress.
26328 // However, if we're not ended, or reading, and the length < hwm,
26329 // then go ahead and try to read some more preemptively.
26330 function maybeReadMore(stream, state) {
26331 if (!state.readingMore) {
26332 state.readingMore = true;
26333 pna.nextTick(maybeReadMore_, stream, state);
26334 }
26335 }
26336
26337 function maybeReadMore_(stream, state) {
26338 var len = state.length;
26339 while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
26340 debug('maybeReadMore read 0');
26341 stream.read(0);
26342 if (len === state.length)
26343 // didn't get any data, stop spinning.
26344 break;else len = state.length;
26345 }
26346 state.readingMore = false;
26347 }
26348
26349 // abstract method. to be overridden in specific implementation classes.
26350 // call cb(er, data) where data is <= n in length.
26351 // for virtual (non-string, non-buffer) streams, "length" is somewhat
26352 // arbitrary, and perhaps not very meaningful.
26353 Readable.prototype._read = function (n) {
26354 this.emit('error', new Error('_read() is not implemented'));
26355 };
26356
26357 Readable.prototype.pipe = function (dest, pipeOpts) {
26358 var src = this;
26359 var state = this._readableState;
26360
26361 switch (state.pipesCount) {
26362 case 0:
26363 state.pipes = dest;
26364 break;
26365 case 1:
26366 state.pipes = [state.pipes, dest];
26367 break;
26368 default:
26369 state.pipes.push(dest);
26370 break;
26371 }
26372 state.pipesCount += 1;
26373 debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
26374
26375 var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
26376
26377 var endFn = doEnd ? onend : unpipe;
26378 if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
26379
26380 dest.on('unpipe', onunpipe);
26381 function onunpipe(readable, unpipeInfo) {
26382 debug('onunpipe');
26383 if (readable === src) {
26384 if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
26385 unpipeInfo.hasUnpiped = true;
26386 cleanup();
26387 }
26388 }
26389 }
26390
26391 function onend() {
26392 debug('onend');
26393 dest.end();
26394 }
26395
26396 // when the dest drains, it reduces the awaitDrain counter
26397 // on the source. This would be more elegant with a .once()
26398 // handler in flow(), but adding and removing repeatedly is
26399 // too slow.
26400 var ondrain = pipeOnDrain(src);
26401 dest.on('drain', ondrain);
26402
26403 var cleanedUp = false;
26404 function cleanup() {
26405 debug('cleanup');
26406 // cleanup event handlers once the pipe is broken
26407 dest.removeListener('close', onclose);
26408 dest.removeListener('finish', onfinish);
26409 dest.removeListener('drain', ondrain);
26410 dest.removeListener('error', onerror);
26411 dest.removeListener('unpipe', onunpipe);
26412 src.removeListener('end', onend);
26413 src.removeListener('end', unpipe);
26414 src.removeListener('data', ondata);
26415
26416 cleanedUp = true;
26417
26418 // if the reader is waiting for a drain event from this
26419 // specific writer, then it would cause it to never start
26420 // flowing again.
26421 // So, if this is awaiting a drain, then we just call it now.
26422 // If we don't know, then assume that we are waiting for one.
26423 if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
26424 }
26425
26426 // If the user pushes more data while we're writing to dest then we'll end up
26427 // in ondata again. However, we only want to increase awaitDrain once because
26428 // dest will only emit one 'drain' event for the multiple writes.
26429 // => Introduce a guard on increasing awaitDrain.
26430 var increasedAwaitDrain = false;
26431 src.on('data', ondata);
26432 function ondata(chunk) {
26433 debug('ondata');
26434 increasedAwaitDrain = false;
26435 var ret = dest.write(chunk);
26436 if (false === ret && !increasedAwaitDrain) {
26437 // If the user unpiped during `dest.write()`, it is possible
26438 // to get stuck in a permanently paused state if that write
26439 // also returned false.
26440 // => Check whether `dest` is still a piping destination.
26441 if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
26442 debug('false write response, pause', src._readableState.awaitDrain);
26443 src._readableState.awaitDrain++;
26444 increasedAwaitDrain = true;
26445 }
26446 src.pause();
26447 }
26448 }
26449
26450 // if the dest has an error, then stop piping into it.
26451 // however, don't suppress the throwing behavior for this.
26452 function onerror(er) {
26453 debug('onerror', er);
26454 unpipe();
26455 dest.removeListener('error', onerror);
26456 if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
26457 }
26458
26459 // Make sure our error handler is attached before userland ones.
26460 prependListener(dest, 'error', onerror);
26461
26462 // Both close and finish should trigger unpipe, but only once.
26463 function onclose() {
26464 dest.removeListener('finish', onfinish);
26465 unpipe();
26466 }
26467 dest.once('close', onclose);
26468 function onfinish() {
26469 debug('onfinish');
26470 dest.removeListener('close', onclose);
26471 unpipe();
26472 }
26473 dest.once('finish', onfinish);
26474
26475 function unpipe() {
26476 debug('unpipe');
26477 src.unpipe(dest);
26478 }
26479
26480 // tell the dest that it's being piped to
26481 dest.emit('pipe', src);
26482
26483 // start the flow if it hasn't been started already.
26484 if (!state.flowing) {
26485 debug('pipe resume');
26486 src.resume();
26487 }
26488
26489 return dest;
26490 };
26491
26492 function pipeOnDrain(src) {
26493 return function () {
26494 var state = src._readableState;
26495 debug('pipeOnDrain', state.awaitDrain);
26496 if (state.awaitDrain) state.awaitDrain--;
26497 if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
26498 state.flowing = true;
26499 flow(src);
26500 }
26501 };
26502 }
26503
26504 Readable.prototype.unpipe = function (dest) {
26505 var state = this._readableState;
26506 var unpipeInfo = { hasUnpiped: false };
26507
26508 // if we're not piping anywhere, then do nothing.
26509 if (state.pipesCount === 0) return this;
26510
26511 // just one destination. most common case.
26512 if (state.pipesCount === 1) {
26513 // passed in one, but it's not the right one.
26514 if (dest && dest !== state.pipes) return this;
26515
26516 if (!dest) dest = state.pipes;
26517
26518 // got a match.
26519 state.pipes = null;
26520 state.pipesCount = 0;
26521 state.flowing = false;
26522 if (dest) dest.emit('unpipe', this, unpipeInfo);
26523 return this;
26524 }
26525
26526 // slow case. multiple pipe destinations.
26527
26528 if (!dest) {
26529 // remove all.
26530 var dests = state.pipes;
26531 var len = state.pipesCount;
26532 state.pipes = null;
26533 state.pipesCount = 0;
26534 state.flowing = false;
26535
26536 for (var i = 0; i < len; i++) {
26537 dests[i].emit('unpipe', this, unpipeInfo);
26538 }return this;
26539 }
26540
26541 // try to find the right one.
26542 var index = indexOf(state.pipes, dest);
26543 if (index === -1) return this;
26544
26545 state.pipes.splice(index, 1);
26546 state.pipesCount -= 1;
26547 if (state.pipesCount === 1) state.pipes = state.pipes[0];
26548
26549 dest.emit('unpipe', this, unpipeInfo);
26550
26551 return this;
26552 };
26553
26554 // set up data events if they are asked for
26555 // Ensure readable listeners eventually get something
26556 Readable.prototype.on = function (ev, fn) {
26557 var res = Stream.prototype.on.call(this, ev, fn);
26558
26559 if (ev === 'data') {
26560 // Start flowing on next tick if stream isn't explicitly paused
26561 if (this._readableState.flowing !== false) this.resume();
26562 } else if (ev === 'readable') {
26563 var state = this._readableState;
26564 if (!state.endEmitted && !state.readableListening) {
26565 state.readableListening = state.needReadable = true;
26566 state.emittedReadable = false;
26567 if (!state.reading) {
26568 pna.nextTick(nReadingNextTick, this);
26569 } else if (state.length) {
26570 emitReadable(this);
26571 }
26572 }
26573 }
26574
26575 return res;
26576 };
26577 Readable.prototype.addListener = Readable.prototype.on;
26578
26579 function nReadingNextTick(self) {
26580 debug('readable nexttick read 0');
26581 self.read(0);
26582 }
26583
26584 // pause() and resume() are remnants of the legacy readable stream API
26585 // If the user uses them, then switch into old mode.
26586 Readable.prototype.resume = function () {
26587 var state = this._readableState;
26588 if (!state.flowing) {
26589 debug('resume');
26590 state.flowing = true;
26591 resume(this, state);
26592 }
26593 return this;
26594 };
26595
26596 function resume(stream, state) {
26597 if (!state.resumeScheduled) {
26598 state.resumeScheduled = true;
26599 pna.nextTick(resume_, stream, state);
26600 }
26601 }
26602
26603 function resume_(stream, state) {
26604 if (!state.reading) {
26605 debug('resume read 0');
26606 stream.read(0);
26607 }
26608
26609 state.resumeScheduled = false;
26610 state.awaitDrain = 0;
26611 stream.emit('resume');
26612 flow(stream);
26613 if (state.flowing && !state.reading) stream.read(0);
26614 }
26615
26616 Readable.prototype.pause = function () {
26617 debug('call pause flowing=%j', this._readableState.flowing);
26618 if (false !== this._readableState.flowing) {
26619 debug('pause');
26620 this._readableState.flowing = false;
26621 this.emit('pause');
26622 }
26623 return this;
26624 };
26625
26626 function flow(stream) {
26627 var state = stream._readableState;
26628 debug('flow', state.flowing);
26629 while (state.flowing && stream.read() !== null) {}
26630 }
26631
26632 // wrap an old-style stream as the async data source.
26633 // This is *not* part of the readable stream interface.
26634 // It is an ugly unfortunate mess of history.
26635 Readable.prototype.wrap = function (stream) {
26636 var _this = this;
26637
26638 var state = this._readableState;
26639 var paused = false;
26640
26641 stream.on('end', function () {
26642 debug('wrapped end');
26643 if (state.decoder && !state.ended) {
26644 var chunk = state.decoder.end();
26645 if (chunk && chunk.length) _this.push(chunk);
26646 }
26647
26648 _this.push(null);
26649 });
26650
26651 stream.on('data', function (chunk) {
26652 debug('wrapped data');
26653 if (state.decoder) chunk = state.decoder.write(chunk);
26654
26655 // don't skip over falsy values in objectMode
26656 if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
26657
26658 var ret = _this.push(chunk);
26659 if (!ret) {
26660 paused = true;
26661 stream.pause();
26662 }
26663 });
26664
26665 // proxy all the other methods.
26666 // important when wrapping filters and duplexes.
26667 for (var i in stream) {
26668 if (this[i] === undefined && typeof stream[i] === 'function') {
26669 this[i] = function (method) {
26670 return function () {
26671 return stream[method].apply(stream, arguments);
26672 };
26673 }(i);
26674 }
26675 }
26676
26677 // proxy certain important events.
26678 for (var n = 0; n < kProxyEvents.length; n++) {
26679 stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
26680 }
26681
26682 // when we try to consume some more bytes, simply unpause the
26683 // underlying stream.
26684 this._read = function (n) {
26685 debug('wrapped _read', n);
26686 if (paused) {
26687 paused = false;
26688 stream.resume();
26689 }
26690 };
26691
26692 return this;
26693 };
26694
26695 Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
26696 // making it explicit this property is not enumerable
26697 // because otherwise some prototype manipulation in
26698 // userland will fail
26699 enumerable: false,
26700 get: function () {
26701 return this._readableState.highWaterMark;
26702 }
26703 });
26704
26705 // exposed for testing purposes only.
26706 Readable._fromList = fromList;
26707
26708 // Pluck off n bytes from an array of buffers.
26709 // Length is the combined lengths of all the buffers in the list.
26710 // This function is designed to be inlinable, so please take care when making
26711 // changes to the function body.
26712 function fromList(n, state) {
26713 // nothing buffered
26714 if (state.length === 0) return null;
26715
26716 var ret;
26717 if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
26718 // read it all, truncate the list
26719 if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
26720 state.buffer.clear();
26721 } else {
26722 // read part of list
26723 ret = fromListPartial(n, state.buffer, state.decoder);
26724 }
26725
26726 return ret;
26727 }
26728
26729 // Extracts only enough buffered data to satisfy the amount requested.
26730 // This function is designed to be inlinable, so please take care when making
26731 // changes to the function body.
26732 function fromListPartial(n, list, hasStrings) {
26733 var ret;
26734 if (n < list.head.data.length) {
26735 // slice is the same for buffers and strings
26736 ret = list.head.data.slice(0, n);
26737 list.head.data = list.head.data.slice(n);
26738 } else if (n === list.head.data.length) {
26739 // first chunk is a perfect match
26740 ret = list.shift();
26741 } else {
26742 // result spans more than one buffer
26743 ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
26744 }
26745 return ret;
26746 }
26747
26748 // Copies a specified amount of characters from the list of buffered data
26749 // chunks.
26750 // This function is designed to be inlinable, so please take care when making
26751 // changes to the function body.
26752 function copyFromBufferString(n, list) {
26753 var p = list.head;
26754 var c = 1;
26755 var ret = p.data;
26756 n -= ret.length;
26757 while (p = p.next) {
26758 var str = p.data;
26759 var nb = n > str.length ? str.length : n;
26760 if (nb === str.length) ret += str;else ret += str.slice(0, n);
26761 n -= nb;
26762 if (n === 0) {
26763 if (nb === str.length) {
26764 ++c;
26765 if (p.next) list.head = p.next;else list.head = list.tail = null;
26766 } else {
26767 list.head = p;
26768 p.data = str.slice(nb);
26769 }
26770 break;
26771 }
26772 ++c;
26773 }
26774 list.length -= c;
26775 return ret;
26776 }
26777
26778 // Copies a specified amount of bytes from the list of buffered data chunks.
26779 // This function is designed to be inlinable, so please take care when making
26780 // changes to the function body.
26781 function copyFromBuffer(n, list) {
26782 var ret = Buffer.allocUnsafe(n);
26783 var p = list.head;
26784 var c = 1;
26785 p.data.copy(ret);
26786 n -= p.data.length;
26787 while (p = p.next) {
26788 var buf = p.data;
26789 var nb = n > buf.length ? buf.length : n;
26790 buf.copy(ret, ret.length - n, 0, nb);
26791 n -= nb;
26792 if (n === 0) {
26793 if (nb === buf.length) {
26794 ++c;
26795 if (p.next) list.head = p.next;else list.head = list.tail = null;
26796 } else {
26797 list.head = p;
26798 p.data = buf.slice(nb);
26799 }
26800 break;
26801 }
26802 ++c;
26803 }
26804 list.length -= c;
26805 return ret;
26806 }
26807
26808 function endReadable(stream) {
26809 var state = stream._readableState;
26810
26811 // If we get here before consuming all the bytes, then that is a
26812 // bug in node. Should never happen.
26813 if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
26814
26815 if (!state.endEmitted) {
26816 state.ended = true;
26817 pna.nextTick(endReadableNT, state, stream);
26818 }
26819 }
26820
26821 function endReadableNT(state, stream) {
26822 // Check that we didn't get one last unshift.
26823 if (!state.endEmitted && state.length === 0) {
26824 state.endEmitted = true;
26825 stream.readable = false;
26826 stream.emit('end');
26827 }
26828 }
26829
26830 function indexOf(xs, x) {
26831 for (var i = 0, l = xs.length; i < l; i++) {
26832 if (xs[i] === x) return i;
26833 }
26834 return -1;
26835 }
26836 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
26837 },{"./_stream_duplex":191,"./internal/streams/BufferList":196,"./internal/streams/destroy":197,"./internal/streams/stream":198,"_process":181,"core-util-is":112,"events":145,"inherits":162,"isarray":164,"process-nextick-args":180,"safe-buffer":199,"string_decoder/":200,"util":81}],194:[function(require,module,exports){
26838 // Copyright Joyent, Inc. and other Node contributors.
26839 //
26840 // Permission is hereby granted, free of charge, to any person obtaining a
26841 // copy of this software and associated documentation files (the
26842 // "Software"), to deal in the Software without restriction, including
26843 // without limitation the rights to use, copy, modify, merge, publish,
26844 // distribute, sublicense, and/or sell copies of the Software, and to permit
26845 // persons to whom the Software is furnished to do so, subject to the
26846 // following conditions:
26847 //
26848 // The above copyright notice and this permission notice shall be included
26849 // in all copies or substantial portions of the Software.
26850 //
26851 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26852 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26853 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
26854 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26855 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26856 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26857 // USE OR OTHER DEALINGS IN THE SOFTWARE.
26858
26859 // a transform stream is a readable/writable stream where you do
26860 // something with the data. Sometimes it's called a "filter",
26861 // but that's not a great name for it, since that implies a thing where
26862 // some bits pass through, and others are simply ignored. (That would
26863 // be a valid example of a transform, of course.)
26864 //
26865 // While the output is causally related to the input, it's not a
26866 // necessarily symmetric or synchronous transformation. For example,
26867 // a zlib stream might take multiple plain-text writes(), and then
26868 // emit a single compressed chunk some time in the future.
26869 //
26870 // Here's how this works:
26871 //
26872 // The Transform stream has all the aspects of the readable and writable
26873 // stream classes. When you write(chunk), that calls _write(chunk,cb)
26874 // internally, and returns false if there's a lot of pending writes
26875 // buffered up. When you call read(), that calls _read(n) until
26876 // there's enough pending readable data buffered up.
26877 //
26878 // In a transform stream, the written data is placed in a buffer. When
26879 // _read(n) is called, it transforms the queued up data, calling the
26880 // buffered _write cb's as it consumes chunks. If consuming a single
26881 // written chunk would result in multiple output chunks, then the first
26882 // outputted bit calls the readcb, and subsequent chunks just go into
26883 // the read buffer, and will cause it to emit 'readable' if necessary.
26884 //
26885 // This way, back-pressure is actually determined by the reading side,
26886 // since _read has to be called to start processing a new chunk. However,
26887 // a pathological inflate type of transform can cause excessive buffering
26888 // here. For example, imagine a stream where every byte of input is
26889 // interpreted as an integer from 0-255, and then results in that many
26890 // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
26891 // 1kb of data being output. In this case, you could write a very small
26892 // amount of input, and end up with a very large amount of output. In
26893 // such a pathological inflating mechanism, there'd be no way to tell
26894 // the system to stop doing the transform. A single 4MB write could
26895 // cause the system to run out of memory.
26896 //
26897 // However, even in such a pathological case, only a single written chunk
26898 // would be consumed, and then the rest would wait (un-transformed) until
26899 // the results of the previous transformed chunk were consumed.
26900
26901 'use strict';
26902
26903 module.exports = Transform;
26904
26905 var Duplex = require('./_stream_duplex');
26906
26907 /*<replacement>*/
26908 var util = require('core-util-is');
26909 util.inherits = require('inherits');
26910 /*</replacement>*/
26911
26912 util.inherits(Transform, Duplex);
26913
26914 function afterTransform(er, data) {
26915 var ts = this._transformState;
26916 ts.transforming = false;
26917
26918 var cb = ts.writecb;
26919
26920 if (!cb) {
26921 return this.emit('error', new Error('write callback called multiple times'));
26922 }
26923
26924 ts.writechunk = null;
26925 ts.writecb = null;
26926
26927 if (data != null) // single equals check for both `null` and `undefined`
26928 this.push(data);
26929
26930 cb(er);
26931
26932 var rs = this._readableState;
26933 rs.reading = false;
26934 if (rs.needReadable || rs.length < rs.highWaterMark) {
26935 this._read(rs.highWaterMark);
26936 }
26937 }
26938
26939 function Transform(options) {
26940 if (!(this instanceof Transform)) return new Transform(options);
26941
26942 Duplex.call(this, options);
26943
26944 this._transformState = {
26945 afterTransform: afterTransform.bind(this),
26946 needTransform: false,
26947 transforming: false,
26948 writecb: null,
26949 writechunk: null,
26950 writeencoding: null
26951 };
26952
26953 // start out asking for a readable event once data is transformed.
26954 this._readableState.needReadable = true;
26955
26956 // we have implemented the _read method, and done the other things
26957 // that Readable wants before the first _read call, so unset the
26958 // sync guard flag.
26959 this._readableState.sync = false;
26960
26961 if (options) {
26962 if (typeof options.transform === 'function') this._transform = options.transform;
26963
26964 if (typeof options.flush === 'function') this._flush = options.flush;
26965 }
26966
26967 // When the writable side finishes, then flush out anything remaining.
26968 this.on('prefinish', prefinish);
26969 }
26970
26971 function prefinish() {
26972 var _this = this;
26973
26974 if (typeof this._flush === 'function') {
26975 this._flush(function (er, data) {
26976 done(_this, er, data);
26977 });
26978 } else {
26979 done(this, null, null);
26980 }
26981 }
26982
26983 Transform.prototype.push = function (chunk, encoding) {
26984 this._transformState.needTransform = false;
26985 return Duplex.prototype.push.call(this, chunk, encoding);
26986 };
26987
26988 // This is the part where you do stuff!
26989 // override this function in implementation classes.
26990 // 'chunk' is an input chunk.
26991 //
26992 // Call `push(newChunk)` to pass along transformed output
26993 // to the readable side. You may call 'push' zero or more times.
26994 //
26995 // Call `cb(err)` when you are done with this chunk. If you pass
26996 // an error, then that'll put the hurt on the whole operation. If you
26997 // never call cb(), then you'll never get another chunk.
26998 Transform.prototype._transform = function (chunk, encoding, cb) {
26999 throw new Error('_transform() is not implemented');
27000 };
27001
27002 Transform.prototype._write = function (chunk, encoding, cb) {
27003 var ts = this._transformState;
27004 ts.writecb = cb;
27005 ts.writechunk = chunk;
27006 ts.writeencoding = encoding;
27007 if (!ts.transforming) {
27008 var rs = this._readableState;
27009 if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
27010 }
27011 };
27012
27013 // Doesn't matter what the args are here.
27014 // _transform does all the work.
27015 // That we got here means that the readable side wants more data.
27016 Transform.prototype._read = function (n) {
27017 var ts = this._transformState;
27018
27019 if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
27020 ts.transforming = true;
27021 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
27022 } else {
27023 // mark that we need a transform, so that any data that comes in
27024 // will get processed, now that we've asked for it.
27025 ts.needTransform = true;
27026 }
27027 };
27028
27029 Transform.prototype._destroy = function (err, cb) {
27030 var _this2 = this;
27031
27032 Duplex.prototype._destroy.call(this, err, function (err2) {
27033 cb(err2);
27034 _this2.emit('close');
27035 });
27036 };
27037
27038 function done(stream, er, data) {
27039 if (er) return stream.emit('error', er);
27040
27041 if (data != null) // single equals check for both `null` and `undefined`
27042 stream.push(data);
27043
27044 // if there's nothing in the write buffer, then that means
27045 // that nothing more will ever be provided
27046 if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
27047
27048 if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
27049
27050 return stream.push(null);
27051 }
27052 },{"./_stream_duplex":191,"core-util-is":112,"inherits":162}],195:[function(require,module,exports){
27053 (function (process,global,setImmediate){
27054 // Copyright Joyent, Inc. and other Node contributors.
27055 //
27056 // Permission is hereby granted, free of charge, to any person obtaining a
27057 // copy of this software and associated documentation files (the
27058 // "Software"), to deal in the Software without restriction, including
27059 // without limitation the rights to use, copy, modify, merge, publish,
27060 // distribute, sublicense, and/or sell copies of the Software, and to permit
27061 // persons to whom the Software is furnished to do so, subject to the
27062 // following conditions:
27063 //
27064 // The above copyright notice and this permission notice shall be included
27065 // in all copies or substantial portions of the Software.
27066 //
27067 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27068 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27069 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27070 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27071 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27072 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27073 // USE OR OTHER DEALINGS IN THE SOFTWARE.
27074
27075 // A bit simpler than readable streams.
27076 // Implement an async ._write(chunk, encoding, cb), and it'll handle all
27077 // the drain event emission and buffering.
27078
27079 'use strict';
27080
27081 /*<replacement>*/
27082
27083 var pna = require('process-nextick-args');
27084 /*</replacement>*/
27085
27086 module.exports = Writable;
27087
27088 /* <replacement> */
27089 function WriteReq(chunk, encoding, cb) {
27090 this.chunk = chunk;
27091 this.encoding = encoding;
27092 this.callback = cb;
27093 this.next = null;
27094 }
27095
27096 // It seems a linked list but it is not
27097 // there will be only 2 of these for each stream
27098 function CorkedRequest(state) {
27099 var _this = this;
27100
27101 this.next = null;
27102 this.entry = null;
27103 this.finish = function () {
27104 onCorkedFinish(_this, state);
27105 };
27106 }
27107 /* </replacement> */
27108
27109 /*<replacement>*/
27110 var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
27111 /*</replacement>*/
27112
27113 /*<replacement>*/
27114 var Duplex;
27115 /*</replacement>*/
27116
27117 Writable.WritableState = WritableState;
27118
27119 /*<replacement>*/
27120 var util = require('core-util-is');
27121 util.inherits = require('inherits');
27122 /*</replacement>*/
27123
27124 /*<replacement>*/
27125 var internalUtil = {
27126 deprecate: require('util-deprecate')
27127 };
27128 /*</replacement>*/
27129
27130 /*<replacement>*/
27131 var Stream = require('./internal/streams/stream');
27132 /*</replacement>*/
27133
27134 /*<replacement>*/
27135
27136 var Buffer = require('safe-buffer').Buffer;
27137 var OurUint8Array = global.Uint8Array || function () {};
27138 function _uint8ArrayToBuffer(chunk) {
27139 return Buffer.from(chunk);
27140 }
27141 function _isUint8Array(obj) {
27142 return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
27143 }
27144
27145 /*</replacement>*/
27146
27147 var destroyImpl = require('./internal/streams/destroy');
27148
27149 util.inherits(Writable, Stream);
27150
27151 function nop() {}
27152
27153 function WritableState(options, stream) {
27154 Duplex = Duplex || require('./_stream_duplex');
27155
27156 options = options || {};
27157
27158 // Duplex streams are both readable and writable, but share
27159 // the same options object.
27160 // However, some cases require setting options to different
27161 // values for the readable and the writable sides of the duplex stream.
27162 // These options can be provided separately as readableXXX and writableXXX.
27163 var isDuplex = stream instanceof Duplex;
27164
27165 // object stream flag to indicate whether or not this stream
27166 // contains buffers or objects.
27167 this.objectMode = !!options.objectMode;
27168
27169 if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
27170
27171 // the point at which write() starts returning false
27172 // Note: 0 is a valid value, means that we always return false if
27173 // the entire buffer is not flushed immediately on write()
27174 var hwm = options.highWaterMark;
27175 var writableHwm = options.writableHighWaterMark;
27176 var defaultHwm = this.objectMode ? 16 : 16 * 1024;
27177
27178 if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
27179
27180 // cast to ints.
27181 this.highWaterMark = Math.floor(this.highWaterMark);
27182
27183 // if _final has been called
27184 this.finalCalled = false;
27185
27186 // drain event flag.
27187 this.needDrain = false;
27188 // at the start of calling end()
27189 this.ending = false;
27190 // when end() has been called, and returned
27191 this.ended = false;
27192 // when 'finish' is emitted
27193 this.finished = false;
27194
27195 // has it been destroyed
27196 this.destroyed = false;
27197
27198 // should we decode strings into buffers before passing to _write?
27199 // this is here so that some node-core streams can optimize string
27200 // handling at a lower level.
27201 var noDecode = options.decodeStrings === false;
27202 this.decodeStrings = !noDecode;
27203
27204 // Crypto is kind of old and crusty. Historically, its default string
27205 // encoding is 'binary' so we have to make this configurable.
27206 // Everything else in the universe uses 'utf8', though.
27207 this.defaultEncoding = options.defaultEncoding || 'utf8';
27208
27209 // not an actual buffer we keep track of, but a measurement
27210 // of how much we're waiting to get pushed to some underlying
27211 // socket or file.
27212 this.length = 0;
27213
27214 // a flag to see when we're in the middle of a write.
27215 this.writing = false;
27216
27217 // when true all writes will be buffered until .uncork() call
27218 this.corked = 0;
27219
27220 // a flag to be able to tell if the onwrite cb is called immediately,
27221 // or on a later tick. We set this to true at first, because any
27222 // actions that shouldn't happen until "later" should generally also
27223 // not happen before the first write call.
27224 this.sync = true;
27225
27226 // a flag to know if we're processing previously buffered items, which
27227 // may call the _write() callback in the same tick, so that we don't
27228 // end up in an overlapped onwrite situation.
27229 this.bufferProcessing = false;
27230
27231 // the callback that's passed to _write(chunk,cb)
27232 this.onwrite = function (er) {
27233 onwrite(stream, er);
27234 };
27235
27236 // the callback that the user supplies to write(chunk,encoding,cb)
27237 this.writecb = null;
27238
27239 // the amount that is being written when _write is called.
27240 this.writelen = 0;
27241
27242 this.bufferedRequest = null;
27243 this.lastBufferedRequest = null;
27244
27245 // number of pending user-supplied write callbacks
27246 // this must be 0 before 'finish' can be emitted
27247 this.pendingcb = 0;
27248
27249 // emit prefinish if the only thing we're waiting for is _write cbs
27250 // This is relevant for synchronous Transform streams
27251 this.prefinished = false;
27252
27253 // True if the error was already emitted and should not be thrown again
27254 this.errorEmitted = false;
27255
27256 // count buffered requests
27257 this.bufferedRequestCount = 0;
27258
27259 // allocate the first CorkedRequest, there is always
27260 // one allocated and free to use, and we maintain at most two
27261 this.corkedRequestsFree = new CorkedRequest(this);
27262 }
27263
27264 WritableState.prototype.getBuffer = function getBuffer() {
27265 var current = this.bufferedRequest;
27266 var out = [];
27267 while (current) {
27268 out.push(current);
27269 current = current.next;
27270 }
27271 return out;
27272 };
27273
27274 (function () {
27275 try {
27276 Object.defineProperty(WritableState.prototype, 'buffer', {
27277 get: internalUtil.deprecate(function () {
27278 return this.getBuffer();
27279 }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
27280 });
27281 } catch (_) {}
27282 })();
27283
27284 // Test _writableState for inheritance to account for Duplex streams,
27285 // whose prototype chain only points to Readable.
27286 var realHasInstance;
27287 if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
27288 realHasInstance = Function.prototype[Symbol.hasInstance];
27289 Object.defineProperty(Writable, Symbol.hasInstance, {
27290 value: function (object) {
27291 if (realHasInstance.call(this, object)) return true;
27292 if (this !== Writable) return false;
27293
27294 return object && object._writableState instanceof WritableState;
27295 }
27296 });
27297 } else {
27298 realHasInstance = function (object) {
27299 return object instanceof this;
27300 };
27301 }
27302
27303 function Writable(options) {
27304 Duplex = Duplex || require('./_stream_duplex');
27305
27306 // Writable ctor is applied to Duplexes, too.
27307 // `realHasInstance` is necessary because using plain `instanceof`
27308 // would return false, as no `_writableState` property is attached.
27309
27310 // Trying to use the custom `instanceof` for Writable here will also break the
27311 // Node.js LazyTransform implementation, which has a non-trivial getter for
27312 // `_writableState` that would lead to infinite recursion.
27313 if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
27314 return new Writable(options);
27315 }
27316
27317 this._writableState = new WritableState(options, this);
27318
27319 // legacy.
27320 this.writable = true;
27321
27322 if (options) {
27323 if (typeof options.write === 'function') this._write = options.write;
27324
27325 if (typeof options.writev === 'function') this._writev = options.writev;
27326
27327 if (typeof options.destroy === 'function') this._destroy = options.destroy;
27328
27329 if (typeof options.final === 'function') this._final = options.final;
27330 }
27331
27332 Stream.call(this);
27333 }
27334
27335 // Otherwise people can pipe Writable streams, which is just wrong.
27336 Writable.prototype.pipe = function () {
27337 this.emit('error', new Error('Cannot pipe, not readable'));
27338 };
27339
27340 function writeAfterEnd(stream, cb) {
27341 var er = new Error('write after end');
27342 // TODO: defer error events consistently everywhere, not just the cb
27343 stream.emit('error', er);
27344 pna.nextTick(cb, er);
27345 }
27346
27347 // Checks that a user-supplied chunk is valid, especially for the particular
27348 // mode the stream is in. Currently this means that `null` is never accepted
27349 // and undefined/non-string values are only allowed in object mode.
27350 function validChunk(stream, state, chunk, cb) {
27351 var valid = true;
27352 var er = false;
27353
27354 if (chunk === null) {
27355 er = new TypeError('May not write null values to stream');
27356 } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
27357 er = new TypeError('Invalid non-string/buffer chunk');
27358 }
27359 if (er) {
27360 stream.emit('error', er);
27361 pna.nextTick(cb, er);
27362 valid = false;
27363 }
27364 return valid;
27365 }
27366
27367 Writable.prototype.write = function (chunk, encoding, cb) {
27368 var state = this._writableState;
27369 var ret = false;
27370 var isBuf = !state.objectMode && _isUint8Array(chunk);
27371
27372 if (isBuf && !Buffer.isBuffer(chunk)) {
27373 chunk = _uint8ArrayToBuffer(chunk);
27374 }
27375
27376 if (typeof encoding === 'function') {
27377 cb = encoding;
27378 encoding = null;
27379 }
27380
27381 if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
27382
27383 if (typeof cb !== 'function') cb = nop;
27384
27385 if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
27386 state.pendingcb++;
27387 ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
27388 }
27389
27390 return ret;
27391 };
27392
27393 Writable.prototype.cork = function () {
27394 var state = this._writableState;
27395
27396 state.corked++;
27397 };
27398
27399 Writable.prototype.uncork = function () {
27400 var state = this._writableState;
27401
27402 if (state.corked) {
27403 state.corked--;
27404
27405 if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
27406 }
27407 };
27408
27409 Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
27410 // node::ParseEncoding() requires lower case.
27411 if (typeof encoding === 'string') encoding = encoding.toLowerCase();
27412 if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
27413 this._writableState.defaultEncoding = encoding;
27414 return this;
27415 };
27416
27417 function decodeChunk(state, chunk, encoding) {
27418 if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
27419 chunk = Buffer.from(chunk, encoding);
27420 }
27421 return chunk;
27422 }
27423
27424 Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
27425 // making it explicit this property is not enumerable
27426 // because otherwise some prototype manipulation in
27427 // userland will fail
27428 enumerable: false,
27429 get: function () {
27430 return this._writableState.highWaterMark;
27431 }
27432 });
27433
27434 // if we're already writing something, then just put this
27435 // in the queue, and wait our turn. Otherwise, call _write
27436 // If we return false, then we need a drain event, so set that flag.
27437 function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
27438 if (!isBuf) {
27439 var newChunk = decodeChunk(state, chunk, encoding);
27440 if (chunk !== newChunk) {
27441 isBuf = true;
27442 encoding = 'buffer';
27443 chunk = newChunk;
27444 }
27445 }
27446 var len = state.objectMode ? 1 : chunk.length;
27447
27448 state.length += len;
27449
27450 var ret = state.length < state.highWaterMark;
27451 // we must ensure that previous needDrain will not be reset to false.
27452 if (!ret) state.needDrain = true;
27453
27454 if (state.writing || state.corked) {
27455 var last = state.lastBufferedRequest;
27456 state.lastBufferedRequest = {
27457 chunk: chunk,
27458 encoding: encoding,
27459 isBuf: isBuf,
27460 callback: cb,
27461 next: null
27462 };
27463 if (last) {
27464 last.next = state.lastBufferedRequest;
27465 } else {
27466 state.bufferedRequest = state.lastBufferedRequest;
27467 }
27468 state.bufferedRequestCount += 1;
27469 } else {
27470 doWrite(stream, state, false, len, chunk, encoding, cb);
27471 }
27472
27473 return ret;
27474 }
27475
27476 function doWrite(stream, state, writev, len, chunk, encoding, cb) {
27477 state.writelen = len;
27478 state.writecb = cb;
27479 state.writing = true;
27480 state.sync = true;
27481 if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
27482 state.sync = false;
27483 }
27484
27485 function onwriteError(stream, state, sync, er, cb) {
27486 --state.pendingcb;
27487
27488 if (sync) {
27489 // defer the callback if we are being called synchronously
27490 // to avoid piling up things on the stack
27491 pna.nextTick(cb, er);
27492 // this can emit finish, and it will always happen
27493 // after error
27494 pna.nextTick(finishMaybe, stream, state);
27495 stream._writableState.errorEmitted = true;
27496 stream.emit('error', er);
27497 } else {
27498 // the caller expect this to happen before if
27499 // it is async
27500 cb(er);
27501 stream._writableState.errorEmitted = true;
27502 stream.emit('error', er);
27503 // this can emit finish, but finish must
27504 // always follow error
27505 finishMaybe(stream, state);
27506 }
27507 }
27508
27509 function onwriteStateUpdate(state) {
27510 state.writing = false;
27511 state.writecb = null;
27512 state.length -= state.writelen;
27513 state.writelen = 0;
27514 }
27515
27516 function onwrite(stream, er) {
27517 var state = stream._writableState;
27518 var sync = state.sync;
27519 var cb = state.writecb;
27520
27521 onwriteStateUpdate(state);
27522
27523 if (er) onwriteError(stream, state, sync, er, cb);else {
27524 // Check if we're actually ready to finish, but don't emit yet
27525 var finished = needFinish(state);
27526
27527 if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
27528 clearBuffer(stream, state);
27529 }
27530
27531 if (sync) {
27532 /*<replacement>*/
27533 asyncWrite(afterWrite, stream, state, finished, cb);
27534 /*</replacement>*/
27535 } else {
27536 afterWrite(stream, state, finished, cb);
27537 }
27538 }
27539 }
27540
27541 function afterWrite(stream, state, finished, cb) {
27542 if (!finished) onwriteDrain(stream, state);
27543 state.pendingcb--;
27544 cb();
27545 finishMaybe(stream, state);
27546 }
27547
27548 // Must force callback to be called on nextTick, so that we don't
27549 // emit 'drain' before the write() consumer gets the 'false' return
27550 // value, and has a chance to attach a 'drain' listener.
27551 function onwriteDrain(stream, state) {
27552 if (state.length === 0 && state.needDrain) {
27553 state.needDrain = false;
27554 stream.emit('drain');
27555 }
27556 }
27557
27558 // if there's something in the buffer waiting, then process it
27559 function clearBuffer(stream, state) {
27560 state.bufferProcessing = true;
27561 var entry = state.bufferedRequest;
27562
27563 if (stream._writev && entry && entry.next) {
27564 // Fast case, write everything using _writev()
27565 var l = state.bufferedRequestCount;
27566 var buffer = new Array(l);
27567 var holder = state.corkedRequestsFree;
27568 holder.entry = entry;
27569
27570 var count = 0;
27571 var allBuffers = true;
27572 while (entry) {
27573 buffer[count] = entry;
27574 if (!entry.isBuf) allBuffers = false;
27575 entry = entry.next;
27576 count += 1;
27577 }
27578 buffer.allBuffers = allBuffers;
27579
27580 doWrite(stream, state, true, state.length, buffer, '', holder.finish);
27581
27582 // doWrite is almost always async, defer these to save a bit of time
27583 // as the hot path ends with doWrite
27584 state.pendingcb++;
27585 state.lastBufferedRequest = null;
27586 if (holder.next) {
27587 state.corkedRequestsFree = holder.next;
27588 holder.next = null;
27589 } else {
27590 state.corkedRequestsFree = new CorkedRequest(state);
27591 }
27592 state.bufferedRequestCount = 0;
27593 } else {
27594 // Slow case, write chunks one-by-one
27595 while (entry) {
27596 var chunk = entry.chunk;
27597 var encoding = entry.encoding;
27598 var cb = entry.callback;
27599 var len = state.objectMode ? 1 : chunk.length;
27600
27601 doWrite(stream, state, false, len, chunk, encoding, cb);
27602 entry = entry.next;
27603 state.bufferedRequestCount--;
27604 // if we didn't call the onwrite immediately, then
27605 // it means that we need to wait until it does.
27606 // also, that means that the chunk and cb are currently
27607 // being processed, so move the buffer counter past them.
27608 if (state.writing) {
27609 break;
27610 }
27611 }
27612
27613 if (entry === null) state.lastBufferedRequest = null;
27614 }
27615
27616 state.bufferedRequest = entry;
27617 state.bufferProcessing = false;
27618 }
27619
27620 Writable.prototype._write = function (chunk, encoding, cb) {
27621 cb(new Error('_write() is not implemented'));
27622 };
27623
27624 Writable.prototype._writev = null;
27625
27626 Writable.prototype.end = function (chunk, encoding, cb) {
27627 var state = this._writableState;
27628
27629 if (typeof chunk === 'function') {
27630 cb = chunk;
27631 chunk = null;
27632 encoding = null;
27633 } else if (typeof encoding === 'function') {
27634 cb = encoding;
27635 encoding = null;
27636 }
27637
27638 if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
27639
27640 // .end() fully uncorks
27641 if (state.corked) {
27642 state.corked = 1;
27643 this.uncork();
27644 }
27645
27646 // ignore unnecessary end() calls.
27647 if (!state.ending && !state.finished) endWritable(this, state, cb);
27648 };
27649
27650 function needFinish(state) {
27651 return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
27652 }
27653 function callFinal(stream, state) {
27654 stream._final(function (err) {
27655 state.pendingcb--;
27656 if (err) {
27657 stream.emit('error', err);
27658 }
27659 state.prefinished = true;
27660 stream.emit('prefinish');
27661 finishMaybe(stream, state);
27662 });
27663 }
27664 function prefinish(stream, state) {
27665 if (!state.prefinished && !state.finalCalled) {
27666 if (typeof stream._final === 'function') {
27667 state.pendingcb++;
27668 state.finalCalled = true;
27669 pna.nextTick(callFinal, stream, state);
27670 } else {
27671 state.prefinished = true;
27672 stream.emit('prefinish');
27673 }
27674 }
27675 }
27676
27677 function finishMaybe(stream, state) {
27678 var need = needFinish(state);
27679 if (need) {
27680 prefinish(stream, state);
27681 if (state.pendingcb === 0) {
27682 state.finished = true;
27683 stream.emit('finish');
27684 }
27685 }
27686 return need;
27687 }
27688
27689 function endWritable(stream, state, cb) {
27690 state.ending = true;
27691 finishMaybe(stream, state);
27692 if (cb) {
27693 if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
27694 }
27695 state.ended = true;
27696 stream.writable = false;
27697 }
27698
27699 function onCorkedFinish(corkReq, state, err) {
27700 var entry = corkReq.entry;
27701 corkReq.entry = null;
27702 while (entry) {
27703 var cb = entry.callback;
27704 state.pendingcb--;
27705 cb(err);
27706 entry = entry.next;
27707 }
27708 if (state.corkedRequestsFree) {
27709 state.corkedRequestsFree.next = corkReq;
27710 } else {
27711 state.corkedRequestsFree = corkReq;
27712 }
27713 }
27714
27715 Object.defineProperty(Writable.prototype, 'destroyed', {
27716 get: function () {
27717 if (this._writableState === undefined) {
27718 return false;
27719 }
27720 return this._writableState.destroyed;
27721 },
27722 set: function (value) {
27723 // we ignore the value if the stream
27724 // has not been initialized yet
27725 if (!this._writableState) {
27726 return;
27727 }
27728
27729 // backward compatibility, the user is explicitly
27730 // managing destroyed
27731 this._writableState.destroyed = value;
27732 }
27733 });
27734
27735 Writable.prototype.destroy = destroyImpl.destroy;
27736 Writable.prototype._undestroy = destroyImpl.undestroy;
27737 Writable.prototype._destroy = function (err, cb) {
27738 this.end();
27739 cb(err);
27740 };
27741 }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
27742 },{"./_stream_duplex":191,"./internal/streams/destroy":197,"./internal/streams/stream":198,"_process":181,"core-util-is":112,"inherits":162,"process-nextick-args":180,"safe-buffer":199,"timers":217,"util-deprecate":218}],196:[function(require,module,exports){
27743 'use strict';
27744
27745 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27746
27747 var Buffer = require('safe-buffer').Buffer;
27748 var util = require('util');
27749
27750 function copyBuffer(src, target, offset) {
27751 src.copy(target, offset);
27752 }
27753
27754 module.exports = function () {
27755 function BufferList() {
27756 _classCallCheck(this, BufferList);
27757
27758 this.head = null;
27759 this.tail = null;
27760 this.length = 0;
27761 }
27762
27763 BufferList.prototype.push = function push(v) {
27764 var entry = { data: v, next: null };
27765 if (this.length > 0) this.tail.next = entry;else this.head = entry;
27766 this.tail = entry;
27767 ++this.length;
27768 };
27769
27770 BufferList.prototype.unshift = function unshift(v) {
27771 var entry = { data: v, next: this.head };
27772 if (this.length === 0) this.tail = entry;
27773 this.head = entry;
27774 ++this.length;
27775 };
27776
27777 BufferList.prototype.shift = function shift() {
27778 if (this.length === 0) return;
27779 var ret = this.head.data;
27780 if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
27781 --this.length;
27782 return ret;
27783 };
27784
27785 BufferList.prototype.clear = function clear() {
27786 this.head = this.tail = null;
27787 this.length = 0;
27788 };
27789
27790 BufferList.prototype.join = function join(s) {
27791 if (this.length === 0) return '';
27792 var p = this.head;
27793 var ret = '' + p.data;
27794 while (p = p.next) {
27795 ret += s + p.data;
27796 }return ret;
27797 };
27798
27799 BufferList.prototype.concat = function concat(n) {
27800 if (this.length === 0) return Buffer.alloc(0);
27801 if (this.length === 1) return this.head.data;
27802 var ret = Buffer.allocUnsafe(n >>> 0);
27803 var p = this.head;
27804 var i = 0;
27805 while (p) {
27806 copyBuffer(p.data, ret, i);
27807 i += p.data.length;
27808 p = p.next;
27809 }
27810 return ret;
27811 };
27812
27813 return BufferList;
27814 }();
27815
27816 if (util && util.inspect && util.inspect.custom) {
27817 module.exports.prototype[util.inspect.custom] = function () {
27818 var obj = util.inspect({ length: this.length });
27819 return this.constructor.name + ' ' + obj;
27820 };
27821 }
27822 },{"safe-buffer":199,"util":81}],197:[function(require,module,exports){
27823 'use strict';
27824
27825 /*<replacement>*/
27826
27827 var pna = require('process-nextick-args');
27828 /*</replacement>*/
27829
27830 // undocumented cb() API, needed for core, not for public API
27831 function destroy(err, cb) {
27832 var _this = this;
27833
27834 var readableDestroyed = this._readableState && this._readableState.destroyed;
27835 var writableDestroyed = this._writableState && this._writableState.destroyed;
27836
27837 if (readableDestroyed || writableDestroyed) {
27838 if (cb) {
27839 cb(err);
27840 } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
27841 pna.nextTick(emitErrorNT, this, err);
27842 }
27843 return this;
27844 }
27845
27846 // we set destroyed to true before firing error callbacks in order
27847 // to make it re-entrance safe in case destroy() is called within callbacks
27848
27849 if (this._readableState) {
27850 this._readableState.destroyed = true;
27851 }
27852
27853 // if this is a duplex stream mark the writable part as destroyed as well
27854 if (this._writableState) {
27855 this._writableState.destroyed = true;
27856 }
27857
27858 this._destroy(err || null, function (err) {
27859 if (!cb && err) {
27860 pna.nextTick(emitErrorNT, _this, err);
27861 if (_this._writableState) {
27862 _this._writableState.errorEmitted = true;
27863 }
27864 } else if (cb) {
27865 cb(err);
27866 }
27867 });
27868
27869 return this;
27870 }
27871
27872 function undestroy() {
27873 if (this._readableState) {
27874 this._readableState.destroyed = false;
27875 this._readableState.reading = false;
27876 this._readableState.ended = false;
27877 this._readableState.endEmitted = false;
27878 }
27879
27880 if (this._writableState) {
27881 this._writableState.destroyed = false;
27882 this._writableState.ended = false;
27883 this._writableState.ending = false;
27884 this._writableState.finished = false;
27885 this._writableState.errorEmitted = false;
27886 }
27887 }
27888
27889 function emitErrorNT(self, err) {
27890 self.emit('error', err);
27891 }
27892
27893 module.exports = {
27894 destroy: destroy,
27895 undestroy: undestroy
27896 };
27897 },{"process-nextick-args":180}],198:[function(require,module,exports){
27898 module.exports = require('events').EventEmitter;
27899
27900 },{"events":145}],199:[function(require,module,exports){
27901 /* eslint-disable node/no-deprecated-api */
27902 var buffer = require('buffer')
27903 var Buffer = buffer.Buffer
27904
27905 // alternative to using Object.keys for old browsers
27906 function copyProps (src, dst) {
27907 for (var key in src) {
27908 dst[key] = src[key]
27909 }
27910 }
27911 if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
27912 module.exports = buffer
27913 } else {
27914 // Copy properties from require('buffer')
27915 copyProps(buffer, exports)
27916 exports.Buffer = SafeBuffer
27917 }
27918
27919 function SafeBuffer (arg, encodingOrOffset, length) {
27920 return Buffer(arg, encodingOrOffset, length)
27921 }
27922
27923 // Copy static methods from Buffer
27924 copyProps(Buffer, SafeBuffer)
27925
27926 SafeBuffer.from = function (arg, encodingOrOffset, length) {
27927 if (typeof arg === 'number') {
27928 throw new TypeError('Argument must not be a number')
27929 }
27930 return Buffer(arg, encodingOrOffset, length)
27931 }
27932
27933 SafeBuffer.alloc = function (size, fill, encoding) {
27934 if (typeof size !== 'number') {
27935 throw new TypeError('Argument must be a number')
27936 }
27937 var buf = Buffer(size)
27938 if (fill !== undefined) {
27939 if (typeof encoding === 'string') {
27940 buf.fill(fill, encoding)
27941 } else {
27942 buf.fill(fill)
27943 }
27944 } else {
27945 buf.fill(0)
27946 }
27947 return buf
27948 }
27949
27950 SafeBuffer.allocUnsafe = function (size) {
27951 if (typeof size !== 'number') {
27952 throw new TypeError('Argument must be a number')
27953 }
27954 return Buffer(size)
27955 }
27956
27957 SafeBuffer.allocUnsafeSlow = function (size) {
27958 if (typeof size !== 'number') {
27959 throw new TypeError('Argument must be a number')
27960 }
27961 return buffer.SlowBuffer(size)
27962 }
27963
27964 },{"buffer":110}],200:[function(require,module,exports){
27965 // Copyright Joyent, Inc. and other Node contributors.
27966 //
27967 // Permission is hereby granted, free of charge, to any person obtaining a
27968 // copy of this software and associated documentation files (the
27969 // "Software"), to deal in the Software without restriction, including
27970 // without limitation the rights to use, copy, modify, merge, publish,
27971 // distribute, sublicense, and/or sell copies of the Software, and to permit
27972 // persons to whom the Software is furnished to do so, subject to the
27973 // following conditions:
27974 //
27975 // The above copyright notice and this permission notice shall be included
27976 // in all copies or substantial portions of the Software.
27977 //
27978 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27979 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27980 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27981 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27982 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27983 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
27984 // USE OR OTHER DEALINGS IN THE SOFTWARE.
27985
27986 'use strict';
27987
27988 /*<replacement>*/
27989
27990 var Buffer = require('safe-buffer').Buffer;
27991 /*</replacement>*/
27992
27993 var isEncoding = Buffer.isEncoding || function (encoding) {
27994 encoding = '' + encoding;
27995 switch (encoding && encoding.toLowerCase()) {
27996 case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
27997 return true;
27998 default:
27999 return false;
28000 }
28001 };
28002
28003 function _normalizeEncoding(enc) {
28004 if (!enc) return 'utf8';
28005 var retried;
28006 while (true) {
28007 switch (enc) {
28008 case 'utf8':
28009 case 'utf-8':
28010 return 'utf8';
28011 case 'ucs2':
28012 case 'ucs-2':
28013 case 'utf16le':
28014 case 'utf-16le':
28015 return 'utf16le';
28016 case 'latin1':
28017 case 'binary':
28018 return 'latin1';
28019 case 'base64':
28020 case 'ascii':
28021 case 'hex':
28022 return enc;
28023 default:
28024 if (retried) return; // undefined
28025 enc = ('' + enc).toLowerCase();
28026 retried = true;
28027 }
28028 }
28029 };
28030
28031 // Do not cache `Buffer.isEncoding` when checking encoding names as some
28032 // modules monkey-patch it to support additional encodings
28033 function normalizeEncoding(enc) {
28034 var nenc = _normalizeEncoding(enc);
28035 if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
28036 return nenc || enc;
28037 }
28038
28039 // StringDecoder provides an interface for efficiently splitting a series of
28040 // buffers into a series of JS strings without breaking apart multi-byte
28041 // characters.
28042 exports.StringDecoder = StringDecoder;
28043 function StringDecoder(encoding) {
28044 this.encoding = normalizeEncoding(encoding);
28045 var nb;
28046 switch (this.encoding) {
28047 case 'utf16le':
28048 this.text = utf16Text;
28049 this.end = utf16End;
28050 nb = 4;
28051 break;
28052 case 'utf8':
28053 this.fillLast = utf8FillLast;
28054 nb = 4;
28055 break;
28056 case 'base64':
28057 this.text = base64Text;
28058 this.end = base64End;
28059 nb = 3;
28060 break;
28061 default:
28062 this.write = simpleWrite;
28063 this.end = simpleEnd;
28064 return;
28065 }
28066 this.lastNeed = 0;
28067 this.lastTotal = 0;
28068 this.lastChar = Buffer.allocUnsafe(nb);
28069 }
28070
28071 StringDecoder.prototype.write = function (buf) {
28072 if (buf.length === 0) return '';
28073 var r;
28074 var i;
28075 if (this.lastNeed) {
28076 r = this.fillLast(buf);
28077 if (r === undefined) return '';
28078 i = this.lastNeed;
28079 this.lastNeed = 0;
28080 } else {
28081 i = 0;
28082 }
28083 if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
28084 return r || '';
28085 };
28086
28087 StringDecoder.prototype.end = utf8End;
28088
28089 // Returns only complete characters in a Buffer
28090 StringDecoder.prototype.text = utf8Text;
28091
28092 // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
28093 StringDecoder.prototype.fillLast = function (buf) {
28094 if (this.lastNeed <= buf.length) {
28095 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
28096 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
28097 }
28098 buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
28099 this.lastNeed -= buf.length;
28100 };
28101
28102 // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
28103 // continuation byte. If an invalid byte is detected, -2 is returned.
28104 function utf8CheckByte(byte) {
28105 if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
28106 return byte >> 6 === 0x02 ? -1 : -2;
28107 }
28108
28109 // Checks at most 3 bytes at the end of a Buffer in order to detect an
28110 // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
28111 // needed to complete the UTF-8 character (if applicable) are returned.
28112 function utf8CheckIncomplete(self, buf, i) {
28113 var j = buf.length - 1;
28114 if (j < i) return 0;
28115 var nb = utf8CheckByte(buf[j]);
28116 if (nb >= 0) {
28117 if (nb > 0) self.lastNeed = nb - 1;
28118 return nb;
28119 }
28120 if (--j < i || nb === -2) return 0;
28121 nb = utf8CheckByte(buf[j]);
28122 if (nb >= 0) {
28123 if (nb > 0) self.lastNeed = nb - 2;
28124 return nb;
28125 }
28126 if (--j < i || nb === -2) return 0;
28127 nb = utf8CheckByte(buf[j]);
28128 if (nb >= 0) {
28129 if (nb > 0) {
28130 if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
28131 }
28132 return nb;
28133 }
28134 return 0;
28135 }
28136
28137 // Validates as many continuation bytes for a multi-byte UTF-8 character as
28138 // needed or are available. If we see a non-continuation byte where we expect
28139 // one, we "replace" the validated continuation bytes we've seen so far with
28140 // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
28141 // behavior. The continuation byte check is included three times in the case
28142 // where all of the continuation bytes for a character exist in the same buffer.
28143 // It is also done this way as a slight performance increase instead of using a
28144 // loop.
28145 function utf8CheckExtraBytes(self, buf, p) {
28146 if ((buf[0] & 0xC0) !== 0x80) {
28147 self.lastNeed = 0;
28148 return '\ufffd';
28149 }
28150 if (self.lastNeed > 1 && buf.length > 1) {
28151 if ((buf[1] & 0xC0) !== 0x80) {
28152 self.lastNeed = 1;
28153 return '\ufffd';
28154 }
28155 if (self.lastNeed > 2 && buf.length > 2) {
28156 if ((buf[2] & 0xC0) !== 0x80) {
28157 self.lastNeed = 2;
28158 return '\ufffd';
28159 }
28160 }
28161 }
28162 }
28163
28164 // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
28165 function utf8FillLast(buf) {
28166 var p = this.lastTotal - this.lastNeed;
28167 var r = utf8CheckExtraBytes(this, buf, p);
28168 if (r !== undefined) return r;
28169 if (this.lastNeed <= buf.length) {
28170 buf.copy(this.lastChar, p, 0, this.lastNeed);
28171 return this.lastChar.toString(this.encoding, 0, this.lastTotal);
28172 }
28173 buf.copy(this.lastChar, p, 0, buf.length);
28174 this.lastNeed -= buf.length;
28175 }
28176
28177 // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
28178 // partial character, the character's bytes are buffered until the required
28179 // number of bytes are available.
28180 function utf8Text(buf, i) {
28181 var total = utf8CheckIncomplete(this, buf, i);
28182 if (!this.lastNeed) return buf.toString('utf8', i);
28183 this.lastTotal = total;
28184 var end = buf.length - (total - this.lastNeed);
28185 buf.copy(this.lastChar, 0, end);
28186 return buf.toString('utf8', i, end);
28187 }
28188
28189 // For UTF-8, a replacement character is added when ending on a partial
28190 // character.
28191 function utf8End(buf) {
28192 var r = buf && buf.length ? this.write(buf) : '';
28193 if (this.lastNeed) return r + '\ufffd';
28194 return r;
28195 }
28196
28197 // UTF-16LE typically needs two bytes per character, but even if we have an even
28198 // number of bytes available, we need to check if we end on a leading/high
28199 // surrogate. In that case, we need to wait for the next two bytes in order to
28200 // decode the last character properly.
28201 function utf16Text(buf, i) {
28202 if ((buf.length - i) % 2 === 0) {
28203 var r = buf.toString('utf16le', i);
28204 if (r) {
28205 var c = r.charCodeAt(r.length - 1);
28206 if (c >= 0xD800 && c <= 0xDBFF) {
28207 this.lastNeed = 2;
28208 this.lastTotal = 4;
28209 this.lastChar[0] = buf[buf.length - 2];
28210 this.lastChar[1] = buf[buf.length - 1];
28211 return r.slice(0, -1);
28212 }
28213 }
28214 return r;
28215 }
28216 this.lastNeed = 1;
28217 this.lastTotal = 2;
28218 this.lastChar[0] = buf[buf.length - 1];
28219 return buf.toString('utf16le', i, buf.length - 1);
28220 }
28221
28222 // For UTF-16LE we do not explicitly append special replacement characters if we
28223 // end on a partial character, we simply let v8 handle that.
28224 function utf16End(buf) {
28225 var r = buf && buf.length ? this.write(buf) : '';
28226 if (this.lastNeed) {
28227 var end = this.lastTotal - this.lastNeed;
28228 return r + this.lastChar.toString('utf16le', 0, end);
28229 }
28230 return r;
28231 }
28232
28233 function base64Text(buf, i) {
28234 var n = (buf.length - i) % 3;
28235 if (n === 0) return buf.toString('base64', i);
28236 this.lastNeed = 3 - n;
28237 this.lastTotal = 3;
28238 if (n === 1) {
28239 this.lastChar[0] = buf[buf.length - 1];
28240 } else {
28241 this.lastChar[0] = buf[buf.length - 2];
28242 this.lastChar[1] = buf[buf.length - 1];
28243 }
28244 return buf.toString('base64', i, buf.length - n);
28245 }
28246
28247 function base64End(buf) {
28248 var r = buf && buf.length ? this.write(buf) : '';
28249 if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
28250 return r;
28251 }
28252
28253 // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
28254 function simpleWrite(buf) {
28255 return buf.toString(this.encoding);
28256 }
28257
28258 function simpleEnd(buf) {
28259 return buf && buf.length ? this.write(buf) : '';
28260 }
28261 },{"safe-buffer":199}],201:[function(require,module,exports){
28262 module.exports = require('./readable').PassThrough
28263
28264 },{"./readable":202}],202:[function(require,module,exports){
28265 exports = module.exports = require('./lib/_stream_readable.js');
28266 exports.Stream = exports;
28267 exports.Readable = exports;
28268 exports.Writable = require('./lib/_stream_writable.js');
28269 exports.Duplex = require('./lib/_stream_duplex.js');
28270 exports.Transform = require('./lib/_stream_transform.js');
28271 exports.PassThrough = require('./lib/_stream_passthrough.js');
28272
28273 },{"./lib/_stream_duplex.js":191,"./lib/_stream_passthrough.js":192,"./lib/_stream_readable.js":193,"./lib/_stream_transform.js":194,"./lib/_stream_writable.js":195}],203:[function(require,module,exports){
28274 module.exports = require('./readable').Transform
28275
28276 },{"./readable":202}],204:[function(require,module,exports){
28277 module.exports = require('./lib/_stream_writable.js');
28278
28279 },{"./lib/_stream_writable.js":195}],205:[function(require,module,exports){
28280 arguments[4][46][0].apply(exports,arguments)
28281 },{"buffer":110,"dup":46,"hash-base":147,"inherits":162}],206:[function(require,module,exports){
28282 arguments[4][47][0].apply(exports,arguments)
28283 },{"buffer":110,"dup":47}],207:[function(require,module,exports){
28284 arguments[4][52][0].apply(exports,arguments)
28285 },{"dup":52,"safe-buffer":206}],208:[function(require,module,exports){
28286 arguments[4][53][0].apply(exports,arguments)
28287 },{"./sha":209,"./sha1":210,"./sha224":211,"./sha256":212,"./sha384":213,"./sha512":214,"dup":53}],209:[function(require,module,exports){
28288 arguments[4][54][0].apply(exports,arguments)
28289 },{"./hash":207,"dup":54,"inherits":162,"safe-buffer":206}],210:[function(require,module,exports){
28290 arguments[4][55][0].apply(exports,arguments)
28291 },{"./hash":207,"dup":55,"inherits":162,"safe-buffer":206}],211:[function(require,module,exports){
28292 arguments[4][56][0].apply(exports,arguments)
28293 },{"./hash":207,"./sha256":212,"dup":56,"inherits":162,"safe-buffer":206}],212:[function(require,module,exports){
28294 arguments[4][57][0].apply(exports,arguments)
28295 },{"./hash":207,"dup":57,"inherits":162,"safe-buffer":206}],213:[function(require,module,exports){
28296 arguments[4][58][0].apply(exports,arguments)
28297 },{"./hash":207,"./sha512":214,"dup":58,"inherits":162,"safe-buffer":206}],214:[function(require,module,exports){
28298 arguments[4][59][0].apply(exports,arguments)
28299 },{"./hash":207,"dup":59,"inherits":162,"safe-buffer":206}],215:[function(require,module,exports){
28300 // Copyright Joyent, Inc. and other Node contributors.
28301 //
28302 // Permission is hereby granted, free of charge, to any person obtaining a
28303 // copy of this software and associated documentation files (the
28304 // "Software"), to deal in the Software without restriction, including
28305 // without limitation the rights to use, copy, modify, merge, publish,
28306 // distribute, sublicense, and/or sell copies of the Software, and to permit
28307 // persons to whom the Software is furnished to do so, subject to the
28308 // following conditions:
28309 //
28310 // The above copyright notice and this permission notice shall be included
28311 // in all copies or substantial portions of the Software.
28312 //
28313 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
28314 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28315 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
28316 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28317 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28318 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28319 // USE OR OTHER DEALINGS IN THE SOFTWARE.
28320
28321 module.exports = Stream;
28322
28323 var EE = require('events').EventEmitter;
28324 var inherits = require('inherits');
28325
28326 inherits(Stream, EE);
28327 Stream.Readable = require('readable-stream/readable.js');
28328 Stream.Writable = require('readable-stream/writable.js');
28329 Stream.Duplex = require('readable-stream/duplex.js');
28330 Stream.Transform = require('readable-stream/transform.js');
28331 Stream.PassThrough = require('readable-stream/passthrough.js');
28332
28333 // Backwards-compat with node 0.4.x
28334 Stream.Stream = Stream;
28335
28336
28337
28338 // old-style streams. Note that the pipe method (the only relevant
28339 // part of this class) is overridden in the Readable class.
28340
28341 function Stream() {
28342 EE.call(this);
28343 }
28344
28345 Stream.prototype.pipe = function(dest, options) {
28346 var source = this;
28347
28348 function ondata(chunk) {
28349 if (dest.writable) {
28350 if (false === dest.write(chunk) && source.pause) {
28351 source.pause();
28352 }
28353 }
28354 }
28355
28356 source.on('data', ondata);
28357
28358 function ondrain() {
28359 if (source.readable && source.resume) {
28360 source.resume();
28361 }
28362 }
28363
28364 dest.on('drain', ondrain);
28365
28366 // If the 'end' option is not supplied, dest.end() will be called when
28367 // source gets the 'end' or 'close' events. Only dest.end() once.
28368 if (!dest._isStdio && (!options || options.end !== false)) {
28369 source.on('end', onend);
28370 source.on('close', onclose);
28371 }
28372
28373 var didOnEnd = false;
28374 function onend() {
28375 if (didOnEnd) return;
28376 didOnEnd = true;
28377
28378 dest.end();
28379 }
28380
28381
28382 function onclose() {
28383 if (didOnEnd) return;
28384 didOnEnd = true;
28385
28386 if (typeof dest.destroy === 'function') dest.destroy();
28387 }
28388
28389 // don't leave dangling pipes when there are errors.
28390 function onerror(er) {
28391 cleanup();
28392 if (EE.listenerCount(this, 'error') === 0) {
28393 throw er; // Unhandled stream error in pipe.
28394 }
28395 }
28396
28397 source.on('error', onerror);
28398 dest.on('error', onerror);
28399
28400 // remove all the event listeners that were added.
28401 function cleanup() {
28402 source.removeListener('data', ondata);
28403 dest.removeListener('drain', ondrain);
28404
28405 source.removeListener('end', onend);
28406 source.removeListener('close', onclose);
28407
28408 source.removeListener('error', onerror);
28409 dest.removeListener('error', onerror);
28410
28411 source.removeListener('end', cleanup);
28412 source.removeListener('close', cleanup);
28413
28414 dest.removeListener('close', cleanup);
28415 }
28416
28417 source.on('end', cleanup);
28418 source.on('close', cleanup);
28419
28420 dest.on('close', cleanup);
28421
28422 dest.emit('pipe', source);
28423
28424 // Allow for unix-like usage: A.pipe(B).pipe(C)
28425 return dest;
28426 };
28427
28428 },{"events":145,"inherits":162,"readable-stream/duplex.js":190,"readable-stream/passthrough.js":201,"readable-stream/readable.js":202,"readable-stream/transform.js":203,"readable-stream/writable.js":204}],216:[function(require,module,exports){
28429 arguments[4][200][0].apply(exports,arguments)
28430 },{"dup":200,"safe-buffer":206}],217:[function(require,module,exports){
28431 (function (setImmediate,clearImmediate){
28432 var nextTick = require('process/browser.js').nextTick;
28433 var apply = Function.prototype.apply;
28434 var slice = Array.prototype.slice;
28435 var immediateIds = {};
28436 var nextImmediateId = 0;
28437
28438 // DOM APIs, for completeness
28439
28440 exports.setTimeout = function() {
28441 return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
28442 };
28443 exports.setInterval = function() {
28444 return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
28445 };
28446 exports.clearTimeout =
28447 exports.clearInterval = function(timeout) { timeout.close(); };
28448
28449 function Timeout(id, clearFn) {
28450 this._id = id;
28451 this._clearFn = clearFn;
28452 }
28453 Timeout.prototype.unref = Timeout.prototype.ref = function() {};
28454 Timeout.prototype.close = function() {
28455 this._clearFn.call(window, this._id);
28456 };
28457
28458 // Does not start the time, just sets up the members needed.
28459 exports.enroll = function(item, msecs) {
28460 clearTimeout(item._idleTimeoutId);
28461 item._idleTimeout = msecs;
28462 };
28463
28464 exports.unenroll = function(item) {
28465 clearTimeout(item._idleTimeoutId);
28466 item._idleTimeout = -1;
28467 };
28468
28469 exports._unrefActive = exports.active = function(item) {
28470 clearTimeout(item._idleTimeoutId);
28471
28472 var msecs = item._idleTimeout;
28473 if (msecs >= 0) {
28474 item._idleTimeoutId = setTimeout(function onTimeout() {
28475 if (item._onTimeout)
28476 item._onTimeout();
28477 }, msecs);
28478 }
28479 };
28480
28481 // That's not how node.js implements it but the exposed api is the same.
28482 exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
28483 var id = nextImmediateId++;
28484 var args = arguments.length < 2 ? false : slice.call(arguments, 1);
28485
28486 immediateIds[id] = true;
28487
28488 nextTick(function onNextTick() {
28489 if (immediateIds[id]) {
28490 // fn.call() is faster so we optimize for the common use-case
28491 // @see http://jsperf.com/call-apply-segu
28492 if (args) {
28493 fn.apply(null, args);
28494 } else {
28495 fn.call(null);
28496 }
28497 // Prevent ids from leaking
28498 exports.clearImmediate(id);
28499 }
28500 });
28501
28502 return id;
28503 };
28504
28505 exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
28506 delete immediateIds[id];
28507 };
28508 }).call(this,require("timers").setImmediate,require("timers").clearImmediate)
28509 },{"process/browser.js":181,"timers":217}],218:[function(require,module,exports){
28510 (function (global){
28511
28512 /**
28513 * Module exports.
28514 */
28515
28516 module.exports = deprecate;
28517
28518 /**
28519 * Mark that a method should not be used.
28520 * Returns a modified function which warns once by default.
28521 *
28522 * If `localStorage.noDeprecation = true` is set, then it is a no-op.
28523 *
28524 * If `localStorage.throwDeprecation = true` is set, then deprecated functions
28525 * will throw an Error when invoked.
28526 *
28527 * If `localStorage.traceDeprecation = true` is set, then deprecated functions
28528 * will invoke `console.trace()` instead of `console.error()`.
28529 *
28530 * @param {Function} fn - the function to deprecate
28531 * @param {String} msg - the string to print to the console when `fn` is invoked
28532 * @returns {Function} a new "deprecated" version of `fn`
28533 * @api public
28534 */
28535
28536 function deprecate (fn, msg) {
28537 if (config('noDeprecation')) {
28538 return fn;
28539 }
28540
28541 var warned = false;
28542 function deprecated() {
28543 if (!warned) {
28544 if (config('throwDeprecation')) {
28545 throw new Error(msg);
28546 } else if (config('traceDeprecation')) {
28547 console.trace(msg);
28548 } else {
28549 console.warn(msg);
28550 }
28551 warned = true;
28552 }
28553 return fn.apply(this, arguments);
28554 }
28555
28556 return deprecated;
28557 }
28558
28559 /**
28560 * Checks `localStorage` for boolean values for the given `name`.
28561 *
28562 * @param {String} name
28563 * @returns {Boolean}
28564 * @api private
28565 */
28566
28567 function config (name) {
28568 // accessing global.localStorage can trigger a DOMException in sandboxed iframes
28569 try {
28570 if (!global.localStorage) return false;
28571 } catch (_) {
28572 return false;
28573 }
28574 var val = global.localStorage[name];
28575 if (null == val) return false;
28576 return String(val).toLowerCase() === 'true';
28577 }
28578
28579 }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
28580 },{}],219:[function(require,module,exports){
28581 var indexOf = function (xs, item) {
28582 if (xs.indexOf) return xs.indexOf(item);
28583 else for (var i = 0; i < xs.length; i++) {
28584 if (xs[i] === item) return i;
28585 }
28586 return -1;
28587 };
28588 var Object_keys = function (obj) {
28589 if (Object.keys) return Object.keys(obj)
28590 else {
28591 var res = [];
28592 for (var key in obj) res.push(key)
28593 return res;
28594 }
28595 };
28596
28597 var forEach = function (xs, fn) {
28598 if (xs.forEach) return xs.forEach(fn)
28599 else for (var i = 0; i < xs.length; i++) {
28600 fn(xs[i], i, xs);
28601 }
28602 };
28603
28604 var defineProp = (function() {
28605 try {
28606 Object.defineProperty({}, '_', {});
28607 return function(obj, name, value) {
28608 Object.defineProperty(obj, name, {
28609 writable: true,
28610 enumerable: false,
28611 configurable: true,
28612 value: value
28613 })
28614 };
28615 } catch(e) {
28616 return function(obj, name, value) {
28617 obj[name] = value;
28618 };
28619 }
28620 }());
28621
28622 var globals = ['Array', 'Boolean', 'Date', 'Error', 'EvalError', 'Function',
28623 'Infinity', 'JSON', 'Math', 'NaN', 'Number', 'Object', 'RangeError',
28624 'ReferenceError', 'RegExp', 'String', 'SyntaxError', 'TypeError', 'URIError',
28625 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
28626 'eval', 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'undefined', 'unescape'];
28627
28628 function Context() {}
28629 Context.prototype = {};
28630
28631 var Script = exports.Script = function NodeScript (code) {
28632 if (!(this instanceof Script)) return new Script(code);
28633 this.code = code;
28634 };
28635
28636 Script.prototype.runInContext = function (context) {
28637 if (!(context instanceof Context)) {
28638 throw new TypeError("needs a 'context' argument.");
28639 }
28640
28641 var iframe = document.createElement('iframe');
28642 if (!iframe.style) iframe.style = {};
28643 iframe.style.display = 'none';
28644
28645 document.body.appendChild(iframe);
28646
28647 var win = iframe.contentWindow;
28648 var wEval = win.eval, wExecScript = win.execScript;
28649
28650 if (!wEval && wExecScript) {
28651 // win.eval() magically appears when this is called in IE:
28652 wExecScript.call(win, 'null');
28653 wEval = win.eval;
28654 }
28655
28656 forEach(Object_keys(context), function (key) {
28657 win[key] = context[key];
28658 });
28659 forEach(globals, function (key) {
28660 if (context[key]) {
28661 win[key] = context[key];
28662 }
28663 });
28664
28665 var winKeys = Object_keys(win);
28666
28667 var res = wEval.call(win, this.code);
28668
28669 forEach(Object_keys(win), function (key) {
28670 // Avoid copying circular objects like `top` and `window` by only
28671 // updating existing context properties or new properties in the `win`
28672 // that was only introduced after the eval.
28673 if (key in context || indexOf(winKeys, key) === -1) {
28674 context[key] = win[key];
28675 }
28676 });
28677
28678 forEach(globals, function (key) {
28679 if (!(key in context)) {
28680 defineProp(context, key, win[key]);
28681 }
28682 });
28683
28684 document.body.removeChild(iframe);
28685
28686 return res;
28687 };
28688
28689 Script.prototype.runInThisContext = function () {
28690 return eval(this.code); // maybe...
28691 };
28692
28693 Script.prototype.runInNewContext = function (context) {
28694 var ctx = Script.createContext(context);
28695 var res = this.runInContext(ctx);
28696
28697 if (context) {
28698 forEach(Object_keys(ctx), function (key) {
28699 context[key] = ctx[key];
28700 });
28701 }
28702
28703 return res;
28704 };
28705
28706 forEach(Object_keys(Script.prototype), function (name) {
28707 exports[name] = Script[name] = function (code) {
28708 var s = Script(code);
28709 return s[name].apply(s, [].slice.call(arguments, 1));
28710 };
28711 });
28712
28713 exports.isContext = function (context) {
28714 return context instanceof Context;
28715 };
28716
28717 exports.createScript = function (code) {
28718 return exports.Script(code);
28719 };
28720
28721 exports.createContext = Script.createContext = function (context) {
28722 var copy = new Context();
28723 if(typeof context === 'object') {
28724 forEach(Object_keys(context), function (key) {
28725 copy[key] = context[key];
28726 });
28727 }
28728 return copy;
28729 };
28730
28731 },{}]},{},[1])(1)
28732 });