diff --git a/CHANGELOG.md b/CHANGELOG.md index 073b1f3df..86e94a9fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## 6.0.0 (2020-04-27) + +[CHANGED] The default builds for web and worker no longer support encrypted +channels. To use encrypted channels in web/worker you must import +`pusher-js/with-encryption` or use the +`pusher-with-encryption.js`/`pusher-with-encryption.min.js` bundles + +[CHANGED] `forceTLS` now defaults to `true` + +[REMOVED] the `encrypted` option - this was deprecated in `4.3.0`. The library +defaults to TLS anyway. Setting `encrypted` to `false` will **NOT** change +behaviour + +[FIXED] `activityTimeout` and `pongTimeout` options now work as described in +the docs. + +[NEW] Typescript declarations for react-native + +[NEW] Support for encrypted-channels in react-native and workers + ## 5.1.1 (2020-02-12) [FIXED] An issue with typescript declarations which caused builds to fail on diff --git a/README.md b/README.md index 6db93d9a6..383b0b972 100644 --- a/README.md +++ b/README.md @@ -101,13 +101,13 @@ const Pusher = require('pusher-js/with-encryption'); #### CDN ```html - + ``` If you'd like to use encrypted channels: ```html - + ``` You can also use [cdnjs.com](https://cdnjs.com/libraries/pusher) if you prefer @@ -172,13 +172,13 @@ Notes: You can import the worker script (`pusher.worker.js`, not `pusher.js`) from the CDN: ```javascript -importScripts('https://js.pusher.com/5.1/pusher.worker.min.js'); +importScripts('https://js.pusher.com/6.0/pusher.worker.min.js'); ``` If you'd like to use encrypted channels: ```javascript -importScripts('https://js.pusher.com/5.1/pusher-with-encryption.worker.min.js'); +importScripts('https://js.pusher.com/6.0/pusher-with-encryption.worker.min.js'); ``` ### Node.js @@ -600,17 +600,17 @@ First, clone this repository and run `npm install && git submodule init && git s In the `dist/web` folder, you should see the files you need: `pusher.js`, `pusher.min.js`, `json2.js`, `json.min.js`, `sockjs.js` and `sockjs.min.js`. `pusher.js` should be built referencing your URLs as the dependency hosts. -First, make sure you expose all files from the `dist` directory. They need to be in a directory with named after the version number. For example, if you're hosting version 5.1.0 under `http://example.com/pusher-js` (and https for SSL), files should be accessible under following URL's: +First, make sure you expose all files from the `dist` directory. They need to be in a directory with named after the version number. For example, if you're hosting version 6.0.0 under `http://example.com/pusher-js` (and https for SSL), files should be accessible under following URL's: - http://example.com/pusher-js/5.1.0/pusher.js - http://example.com/pusher-js/5.1.0/json2.js - http://example.com/pusher-js/5.1.0/sockjs.js + http://example.com/pusher-js/6.0.0/pusher.js + http://example.com/pusher-js/6.0.0/json2.js + http://example.com/pusher-js/6.0.0/sockjs.js Minified files should have `.min` in their names, as in the `dist/web` directory: - http://example.com/pusher-js/5.1.0/pusher.min.js - http://example.com/pusher-js/5.1.0/json2.min.js - http://example.com/pusher-js/5.1.0/sockjs.min.js + http://example.com/pusher-js/6.0.0/pusher.min.js + http://example.com/pusher-js/6.0.0/json2.min.js + http://example.com/pusher-js/6.0.0/sockjs.min.js ## SockJS compatibility diff --git a/dist/node/pusher.js b/dist/node/pusher.js index c6d04401d..16a89acd6 100644 --- a/dist/node/pusher.js +++ b/dist/node/pusher.js @@ -1,5 +1,5 @@ /*! - * Pusher JavaScript Library v5.0.3 + * Pusher JavaScript Library v6.0.0 * https://pusher.com/ * * Copyright 2017, Pusher @@ -90,7 +90,7 @@ module.exports = /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 20); +/******/ return __webpack_require__(__webpack_require__.s = 21); /******/ }) /************************************************************************/ /******/ ([ @@ -104,7 +104,7 @@ module.exports = require("util"); /***/ (function(module, exports, __webpack_require__) { /* eslint-disable node/no-deprecated-api */ -var buffer = __webpack_require__(21) +var buffer = __webpack_require__(22) var Buffer = buffer.Buffer // alternative to using Object.keys for old browsers @@ -125,8 +125,6 @@ function SafeBuffer (arg, encodingOrOffset, length) { return Buffer(arg, encodingOrOffset, length) } -SafeBuffer.prototype = Object.create(Buffer.prototype) - // Copy static methods from Buffer copyProps(Buffer, SafeBuffer) @@ -177,11 +175,11 @@ SafeBuffer.allocUnsafeSlow = function (size) { var Buffer = __webpack_require__(1).Buffer, - Emitter = __webpack_require__(22).EventEmitter, + Emitter = __webpack_require__(23).EventEmitter, util = __webpack_require__(0), - streams = __webpack_require__(23), - Headers = __webpack_require__(10), - Reader = __webpack_require__(24); + streams = __webpack_require__(24), + Headers = __webpack_require__(9), + Reader = __webpack_require__(25); var Base = function(request, url, options) { Emitter.call(this); @@ -371,4406 +369,4775 @@ module.exports = Base; /***/ }), /* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -(function(nacl) { -'use strict'; - -// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -// -// Implementation derived from TweetNaCl version 20140427. -// See for details: http://tweetnacl.cr.yp.to/ +/***/ (function(module, exports) { -var gf = function(init) { - var i, r = new Float64Array(16); - if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; - return r; -}; +module.exports = require("crypto"); -// Pluggable, initialized in high-level API below. -var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { -var _0 = new Uint8Array(16); -var _9 = new Uint8Array(32); _9[0] = 9; +"use strict"; -var gf0 = gf(), - gf1 = gf([1]), - _121665 = gf([0xdb41, 1]), - D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), - D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), - X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), - Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), - I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); -function ts64(x, i, h, l) { - x[i] = (h >> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} +// Protocol references: +// +// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 +// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 +// * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} +var Base = __webpack_require__(2), + Client = __webpack_require__(26), + Server = __webpack_require__(37); -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} +var Driver = { + client: function(url, options) { + options = options || {}; + if (options.masking === undefined) options.masking = true; + return new Client(url, options); + }, -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} + server: function(options) { + options = options || {}; + if (options.requireMasking === undefined) options.requireMasking = true; + return new Server(options); + }, -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + http: function() { + return Server.http.apply(Server, arguments); + }, - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; + isSecureRequest: function(request) { + return Server.isSecureRequest(request); + }, - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); + isWebSocket: function(request) { + return Base.isWebSocket(request); + }, - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); + validateOptions: function(options, validKeys) { + Base.validateOptions(options, validKeys); + } +}; - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); +module.exports = Driver; - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); +/***/ }), +/* 5 */ +/***/ (function(module, exports) { - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); +module.exports = require("stream"); - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); +/***/ }), +/* 6 */ +/***/ (function(module, exports) { - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; +module.exports = require("url"); - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; +/***/ }), +/* 7 */ +/***/ (function(module, exports) { - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; +var Event = function(eventType, options) { + this.type = eventType; + for (var key in options) + this[key] = options[key]; +}; - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; +Event.prototype.initEvent = function(eventType, canBubble, cancelable) { + this.type = eventType; + this.bubbles = canBubble; + this.cancelable = cancelable; +}; - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; +Event.prototype.stopPropagation = function() {}; +Event.prototype.preventDefault = function() {}; - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; +Event.CAPTURING_PHASE = 1; +Event.AT_TARGET = 2; +Event.BUBBLING_PHASE = 3; - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; +module.exports = Event; - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; +"use strict"; - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package base64 implements Base64 encoding and decoding. + */ +// Invalid character used in decoding to indicate +// that the character to decode is out of range of +// alphabet and cannot be decoded. +var INVALID_BYTE = 256; +/** + * Implements standard Base64 encoding. + * + * Operates in constant time. + */ +var Coder = /** @class */ (function () { + // TODO(dchest): methods to encode chunk-by-chunk. + function Coder(_paddingCharacter) { + if (_paddingCharacter === void 0) { _paddingCharacter = "="; } + this._paddingCharacter = _paddingCharacter; + } + Coder.prototype.encodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 8 + 5) / 6 | 0; + } + return (length + 2) / 3 * 4 | 0; + }; + Coder.prototype.encode = function (data) { + var out = ""; + var i = 0; + for (; i < data.length - 2; i += 3) { + var c = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + out += this._encodeByte((c >>> 1 * 6) & 63); + out += this._encodeByte((c >>> 0 * 6) & 63); + } + var left = data.length - i; + if (left > 0) { + var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + if (left === 2) { + out += this._encodeByte((c >>> 1 * 6) & 63); + } + else { + out += this._paddingCharacter || ""; + } + out += this._paddingCharacter || ""; + } + return out; + }; + Coder.prototype.maxDecodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 6 + 7) / 8 | 0; + } + return length / 4 * 3 | 0; + }; + Coder.prototype.decodedLength = function (s) { + return this.maxDecodedLength(s.length - this._getPaddingLength(s)); + }; + Coder.prototype.decode = function (s) { + if (s.length === 0) { + return new Uint8Array(0); + } + var paddingLength = this._getPaddingLength(s); + var length = s.length - paddingLength; + var out = new Uint8Array(this.maxDecodedLength(length)); + var op = 0; + var i = 0; + var haveBad = 0; + var v0 = 0, v1 = 0, v2 = 0, v3 = 0; + for (; i < length - 4; i += 4) { + v0 = this._decodeChar(s.charCodeAt(i + 0)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + v2 = this._decodeChar(s.charCodeAt(i + 2)); + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v0 << 2) | (v1 >>> 4); + out[op++] = (v1 << 4) | (v2 >>> 2); + out[op++] = (v2 << 6) | v3; + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + haveBad |= v2 & INVALID_BYTE; + haveBad |= v3 & INVALID_BYTE; + } + if (i < length - 1) { + v0 = this._decodeChar(s.charCodeAt(i)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + out[op++] = (v0 << 2) | (v1 >>> 4); + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + } + if (i < length - 2) { + v2 = this._decodeChar(s.charCodeAt(i + 2)); + out[op++] = (v1 << 4) | (v2 >>> 2); + haveBad |= v2 & INVALID_BYTE; + } + if (i < length - 3) { + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v2 << 6) | v3; + haveBad |= v3 & INVALID_BYTE; + } + if (haveBad !== 0) { + throw new Error("Base64Coder: incorrect characters for decoding"); + } + return out; + }; + // Standard encoding have the following encoded/decoded ranges, + // which we need to convert between. + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + / + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 43 47 + // + // Encode 6 bits in b into a new character. + Coder.prototype._encodeByte = function (b) { + // Encoding uses constant time operations as follows: + // + // 1. Define comparison of A with B using (A - B) >>> 8: + // if A > B, then result is positive integer + // if A <= B, then result is 0 + // + // 2. Define selection of C or 0 using bitwise AND: X & C: + // if X == 0, then result is 0 + // if X != 0, then result is C + // + // 3. Start with the smallest comparison (b >= 0), which is always + // true, so set the result to the starting ASCII value (65). + // + // 4. Continue comparing b to higher ASCII values, and selecting + // zero if comparison isn't true, otherwise selecting a value + // to add to result, which: + // + // a) undoes the previous addition + // b) provides new value to add + // + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47); + return String.fromCharCode(result); + }; + // Decode a character code into a byte. + // Must return 256 if character is out of alphabet range. + Coder.prototype._decodeChar = function (c) { + // Decoding works similar to encoding: using the same comparison + // function, but now it works on ranges: result is always incremented + // by value, but this value becomes zero if the range is not + // satisfied. + // + // Decoding starts with invalid value, 256, which is then + // subtracted when the range is satisfied. If none of the ranges + // apply, the function returns 256, which is then checked by + // the caller to throw error. + var result = INVALID_BYTE; // start with invalid character + // c == 43 (c > 42 and c < 44) + result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62); + // c == 47 (c > 46 and c < 48) + result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + Coder.prototype._getPaddingLength = function (s) { + var paddingLength = 0; + if (this._paddingCharacter) { + for (var i = s.length - 1; i >= 0; i--) { + if (s[i] !== this._paddingCharacter) { + break; + } + paddingLength++; + } + if (s.length < 4 || paddingLength > 2) { + throw new Error("Base64Coder: incorrect padding"); + } + } + return paddingLength; + }; + return Coder; +}()); +exports.Coder = Coder; +var stdCoder = new Coder(); +function encode(data) { + return stdCoder.encode(data); +} +exports.encode = encode; +function decode(s) { + return stdCoder.decode(s); +} +exports.decode = decode; +/** + * Implements URL-safe Base64 encoding. + * (Same as Base64, but '+' is replaced with '-', and '/' with '_'). + * + * Operates in constant time. + */ +var URLSafeCoder = /** @class */ (function (_super) { + __extends(URLSafeCoder, _super); + function URLSafeCoder() { + return _super !== null && _super.apply(this, arguments) || this; + } + // URL-safe encoding have the following encoded/decoded ranges: + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _ + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 45 95 + // + URLSafeCoder.prototype._encodeByte = function (b) { + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95); + return String.fromCharCode(result); + }; + URLSafeCoder.prototype._decodeChar = function (c) { + var result = INVALID_BYTE; + // c == 45 (c > 44 and c < 46) + result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62); + // c == 95 (c > 94 and c < 96) + result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + return URLSafeCoder; +}(Coder)); +exports.URLSafeCoder = URLSafeCoder; +var urlSafeCoder = new URLSafeCoder(); +function encodeURLSafe(data) { + return urlSafeCoder.encode(data); +} +exports.encodeURLSafe = encodeURLSafe; +function decodeURLSafe(s) { + return urlSafeCoder.decode(s); +} +exports.decodeURLSafe = decodeURLSafe; +exports.encodedLength = function (length) { + return stdCoder.encodedLength(length); +}; +exports.maxDecodedLength = function (length) { + return stdCoder.maxDecodedLength(length); +}; +exports.decodedLength = function (s) { + return stdCoder.decodedLength(s); +}; +//# sourceMappingURL=base64.js.map - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; +/***/ }), +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; +"use strict"; - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; +var Headers = function() { + this.clear(); +}; - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; +Headers.prototype.ALLOWED_DUPLICATES = ['set-cookie', 'set-cookie2', 'warning', 'www-authenticate']; - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} +Headers.prototype.clear = function() { + this._sent = {}; + this._lines = []; +}; -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; +Headers.prototype.set = function(name, value) { + if (value === undefined) return; - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; + name = this._strip(name); + value = this._strip(value); - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); + var key = name.toLowerCase(); + if (!this._sent.hasOwnProperty(key) || this.ALLOWED_DUPLICATES.indexOf(key) >= 0) { + this._sent[key] = true; + this._lines.push(name + ': ' + value + '\r\n'); + } +}; - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); +Headers.prototype.toString = function() { + return this._lines.join(''); +}; - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); +Headers.prototype._strip = function(string) { + return string.toString().replace(/^ */, '').replace(/ *$/, ''); +}; - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); +module.exports = Headers; - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); +/***/ }), +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); +"use strict"; - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; +var NodeHTTPParser = __webpack_require__(27).HTTPParser, + Buffer = __webpack_require__(1).Buffer; - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; +var TYPES = { + request: NodeHTTPParser.REQUEST || 'request', + response: NodeHTTPParser.RESPONSE || 'response' +}; - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; +var HttpParser = function(type) { + this._type = type; + this._parser = new NodeHTTPParser(TYPES[type]); + this._complete = false; + this.headers = {}; - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; + var current = null, + self = this; - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; + this._parser.onHeaderField = function(b, start, length) { + current = b.toString('utf8', start, start + length).toLowerCase(); + }; - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; + this._parser.onHeaderValue = function(b, start, length) { + var value = b.toString('utf8', start, start + length); - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; + if (self.headers.hasOwnProperty(current)) + self.headers[current] += ', ' + value; + else + self.headers[current] = value; + }; - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} + this._parser.onHeadersComplete = this._parser[NodeHTTPParser.kOnHeadersComplete] = + function(majorVersion, minorVersion, headers, method, pathname, statusCode) { + var info = arguments[0]; -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} + if (typeof info === 'object') { + method = info.method; + pathname = info.url; + statusCode = info.statusCode; + headers = info.headers; + } -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} + self.method = (typeof method === 'number') ? HttpParser.METHODS[method] : method; + self.statusCode = statusCode; + self.url = pathname; -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" + if (!headers) return; -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; + for (var i = 0, n = headers.length, key, value; i < n; i += 2) { + key = headers[i].toLowerCase(); + value = headers[i+1]; + if (self.headers.hasOwnProperty(key)) + self.headers[key] += ', ' + value; + else + self.headers[key] = value; } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; -} -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; -} + self._complete = true; + }; +}; -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); -} +HttpParser.METHODS = { + 0: 'DELETE', + 1: 'GET', + 2: 'HEAD', + 3: 'POST', + 4: 'PUT', + 5: 'CONNECT', + 6: 'OPTIONS', + 7: 'TRACE', + 8: 'COPY', + 9: 'LOCK', + 10: 'MKCOL', + 11: 'MOVE', + 12: 'PROPFIND', + 13: 'PROPPATCH', + 14: 'SEARCH', + 15: 'UNLOCK', + 16: 'BIND', + 17: 'REBIND', + 18: 'UNBIND', + 19: 'ACL', + 20: 'REPORT', + 21: 'MKACTIVITY', + 22: 'CHECKOUT', + 23: 'MERGE', + 24: 'M-SEARCH', + 25: 'NOTIFY', + 26: 'SUBSCRIBE', + 27: 'UNSUBSCRIBE', + 28: 'PATCH', + 29: 'PURGE', + 30: 'MKCALENDAR', + 31: 'LINK', + 32: 'UNLINK' +}; -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); -} +var VERSION = (process.version || '') + .match(/[0-9]+/g) + .map(function(n) { return parseInt(n, 10) }); -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ +if (VERSION[0] === 0 && VERSION[1] === 12) { + HttpParser.METHODS[16] = 'REPORT'; + HttpParser.METHODS[17] = 'MKACTIVITY'; + HttpParser.METHODS[18] = 'CHECKOUT'; + HttpParser.METHODS[19] = 'MERGE'; + HttpParser.METHODS[20] = 'M-SEARCH'; + HttpParser.METHODS[21] = 'NOTIFY'; + HttpParser.METHODS[22] = 'SUBSCRIBE'; + HttpParser.METHODS[23] = 'UNSUBSCRIBE'; + HttpParser.METHODS[24] = 'PATCH'; + HttpParser.METHODS[25] = 'PURGE'; +} -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; +HttpParser.prototype.isComplete = function() { + return this._complete; +}; - var t0, t1, t2, t3, t4, t5, t6, t7; +HttpParser.prototype.parse = function(chunk) { + var consumed = this._parser.execute(chunk, 0, chunk.length); - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; + if (typeof consumed !== 'number') { + this.error = consumed; + this._complete = true; + return; + } - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; + if (this._complete) + this.body = (consumed < chunk.length) + ? chunk.slice(consumed) + : Buffer.alloc(0); }; -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; +module.exports = HttpParser; - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; +/***/ }), +/* 11 */ +/***/ (function(module, exports, __webpack_require__) { - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; +var Stream = __webpack_require__(5).Stream, + util = __webpack_require__(0), + driver = __webpack_require__(4), + EventTarget = __webpack_require__(17), + Event = __webpack_require__(7); - c = 0; +var API = function(options) { + options = options || {}; + driver.validateOptions(options, ['headers', 'extensions', 'maxLength', 'ping', 'proxy', 'tls', 'ca']); - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; + this.readable = this.writable = true; - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; + var headers = options.headers; + if (headers) { + for (var name in headers) this._driver.setHeader(name, headers[name]); + } - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; - - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; - - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; + var extensions = options.extensions; + if (extensions) { + [].concat(extensions).forEach(this._driver.addExtension, this._driver); + } - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; + this._ping = options.ping; + this._pingId = 0; + this.readyState = API.CONNECTING; + this.bufferedAmount = 0; + this.protocol = ''; + this.url = this._driver.url; + this.version = this._driver.version; - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; + var self = this; - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; + this._driver.on('open', function(e) { self._open() }); + this._driver.on('message', function(e) { self._receiveMessage(e.data) }); + this._driver.on('close', function(e) { self._beginClose(e.reason, e.code) }); - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; + this._driver.on('error', function(error) { + self._emitError(error.message); + }); + this.on('error', function() {}); - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; + this._driver.messages.on('drain', function() { + self.emit('drain'); + }); - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; + if (this._ping) + this._pingTimer = setInterval(function() { + self._pingId += 1; + self.ping(self._pingId.toString()); + }, this._ping * 1000); - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; + this._configureStream(); - mpos += 16; - bytes -= 16; + if (!this._proxy) { + this._stream.pipe(this._driver.io); + this._driver.io.pipe(this._stream); } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; }; +util.inherits(API, Stream); -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; +API.CONNECTING = 0; +API.OPEN = 1; +API.CLOSING = 2; +API.CLOSED = 3; - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } +var instance = { + write: function(data) { + return this.send(data); + }, - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; + end: function(data) { + if (data !== undefined) this.send(data); + this.close(); + }, - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); + pause: function() { + return this._driver.messages.pause(); + }, - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; + resume: function() { + return this._driver.messages.resume(); + }, - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; + send: function(data) { + if (this.readyState > API.OPEN) return false; + if (!(data instanceof Buffer)) data = String(data); + return this._driver.messages.write(data); + }, - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } + ping: function(message, callback) { + if (this.readyState > API.OPEN) return false; + return this._driver.ping(message, callback); + }, - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; -}; + close: function() { + if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING; + this._driver.close(); + }, -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; + _configureStream: function() { + var self = this; - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } + this._stream.setTimeout(0); + this._stream.setNoDelay(true); - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } + ['close', 'end'].forEach(function(event) { + this._stream.on(event, function() { self._finalizeClose() }); + }, this); - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; - } -}; + this._stream.on('error', function(error) { + self._emitError('Network error: ' + self.url + ': ' + error.message); + self._finalizeClose(); + }); + }, -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; -} + _open: function() { + if (this.readyState !== API.CONNECTING) return; -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} + this.readyState = API.OPEN; + this.protocol = this._driver.protocol || ''; -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} + var event = new Event('open'); + event.initEvent('open', false, false); + this.dispatchEvent(event); + }, -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} + _receiveMessage: function(data) { + if (this.readyState > API.OPEN) return false; -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} + if (this.readable) this.emit('data', data); -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} + var event = new Event('message', {data: data}); + event.initEvent('message', false, false); + this.dispatchEvent(event); + }, -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} + _emitError: function(message) { + if (this.readyState >= API.CLOSING) return; -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; + var event = new Event('error', {message: message}); + event.initEvent('error', false, false); + this.dispatchEvent(event); + }, + + _beginClose: function(reason, code) { + if (this.readyState === API.CLOSED) return; + this.readyState = API.CLOSING; + + if (this._stream) { + this._stream.end(); + if (!this._stream.readable) this._finalizeClose(); } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; + this._closeParams = [reason, code]; + }, + + _finalizeClose: function() { + if (this.readyState === API.CLOSED) return; + this.readyState = API.CLOSED; + + if (this._pingTimer) clearInterval(this._pingTimer); + if (this._stream) this._stream.end(); + + if (this.readable) this.emit('end'); + this.readable = this.writable = false; + + var reason = this._closeParams ? this._closeParams[0] : '', + code = this._closeParams ? this._closeParams[1] : 1006; + + var event = new Event('close', {code: code, reason: reason}); + event.initEvent('close', false, false); + this.dispatchEvent(event); } -} +}; -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} +for (var method in instance) API.prototype[method] = instance[method]; +for (var key in EventTarget) API.prototype[key] = EventTarget[key]; -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; -} +module.exports = API; -function unpack25519(o, n) { - var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; -} -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; -} +/***/ }), +/* 12 */ +/***/ (function(module, exports, __webpack_require__) { -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +"use strict"; + +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package utf8 implements UTF-8 encoding and decoding. + */ +var INVALID_UTF16 = "utf8: invalid string"; +var INVALID_UTF8 = "utf8: invalid source encoding"; +/** + * Encodes the given string into UTF-8 byte array. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encode(s) { + // Calculate result length and allocate output array. + // encodedLength() also validates string and throws errors, + // so we don't need repeat validation here. + var arr = new Uint8Array(encodedLength(s)); + var pos = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + arr[pos++] = c; + } + else if (c < 0x800) { + arr[pos++] = 0xc0 | c >> 6; + arr[pos++] = 0x80 | c & 0x3f; + } + else if (c < 0xd800) { + arr[pos++] = 0xe0 | c >> 12; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + else { + i++; // get one more character + c = (c & 0x3ff) << 10; + c |= s.charCodeAt(i) & 0x3ff; + c += 0x10000; + arr[pos++] = 0xf0 | c >> 18; + arr[pos++] = 0x80 | (c >> 12) & 0x3f; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + } + return arr; +} +exports.encode = encode; +/** + * Returns the number of bytes required to encode the given string into UTF-8. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encodedLength(s) { + var result = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + result += 1; + } + else if (c < 0x800) { + result += 2; + } + else if (c < 0xd800) { + result += 3; + } + else if (c <= 0xdfff) { + if (i >= s.length - 1) { + throw new Error(INVALID_UTF16); + } + i++; // "eat" next character + result += 4; + } + else { + throw new Error(INVALID_UTF16); + } + } + return result; +} +exports.encodedLength = encodedLength; +/** + * Decodes the given byte array from UTF-8 into a string. + * Throws if encoding is invalid. + */ +function decode(arr) { + var chars = []; + for (var i = 0; i < arr.length; i++) { + var b = arr[i]; + if (b & 0x80) { + var min = void 0; + if (b < 0xe0) { + // Need 1 more byte. + if (i >= arr.length) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + if ((n1 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x1f) << 6 | (n1 & 0x3f); + min = 0x80; + } + else if (b < 0xf0) { + // Need 2 more bytes. + if (i >= arr.length - 1) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 12 | (n1 & 0x3f) << 6 | (n2 & 0x3f); + min = 0x800; + } + else if (b < 0xf8) { + // Need 3 more bytes. + if (i >= arr.length - 2) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + var n3 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80 || (n3 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 18 | (n1 & 0x3f) << 12 | (n2 & 0x3f) << 6 | (n3 & 0x3f); + min = 0x10000; + } + else { + throw new Error(INVALID_UTF8); + } + if (b < min || (b >= 0xd800 && b <= 0xdfff)) { + throw new Error(INVALID_UTF8); + } + if (b >= 0x10000) { + // Surrogate pair. + if (b > 0x10ffff) { + throw new Error(INVALID_UTF8); + } + b -= 0x10000; + chars.push(String.fromCharCode(0xd800 | (b >> 10))); + b = 0xdc00 | (b & 0x3ff); + } + } + chars.push(String.fromCharCode(b)); + } + return chars.join(""); } +exports.decode = decode; +//# sourceMappingURL=utf8.js.map -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; +/***/ }), +/* 13 */ +/***/ (function(module, exports, __webpack_require__) { - v = a[0]; - t0 += v * b0; - t1 += v * b1; - t2 += v * b2; - t3 += v * b3; - t4 += v * b4; - t5 += v * b5; - t6 += v * b6; - t7 += v * b7; - t8 += v * b8; - t9 += v * b9; - t10 += v * b10; - t11 += v * b11; - t12 += v * b12; - t13 += v * b13; - t14 += v * b14; - t15 += v * b15; - v = a[1]; - t1 += v * b0; - t2 += v * b1; - t3 += v * b2; - t4 += v * b3; - t5 += v * b4; - t6 += v * b5; - t7 += v * b6; - t8 += v * b7; - t9 += v * b8; - t10 += v * b9; - t11 += v * b10; - t12 += v * b11; - t13 += v * b12; - t14 += v * b13; - t15 += v * b14; - t16 += v * b15; - v = a[2]; - t2 += v * b0; - t3 += v * b1; - t4 += v * b2; - t5 += v * b3; - t6 += v * b4; - t7 += v * b5; - t8 += v * b6; - t9 += v * b7; - t10 += v * b8; - t11 += v * b9; - t12 += v * b10; - t13 += v * b11; - t14 += v * b12; - t15 += v * b13; - t16 += v * b14; - t17 += v * b15; - v = a[3]; - t3 += v * b0; - t4 += v * b1; - t5 += v * b2; - t6 += v * b3; - t7 += v * b4; - t8 += v * b5; - t9 += v * b6; - t10 += v * b7; - t11 += v * b8; - t12 += v * b9; - t13 += v * b10; - t14 += v * b11; - t15 += v * b12; - t16 += v * b13; - t17 += v * b14; - t18 += v * b15; - v = a[4]; - t4 += v * b0; - t5 += v * b1; - t6 += v * b2; - t7 += v * b3; - t8 += v * b4; - t9 += v * b5; - t10 += v * b6; - t11 += v * b7; - t12 += v * b8; - t13 += v * b9; - t14 += v * b10; - t15 += v * b11; - t16 += v * b12; - t17 += v * b13; - t18 += v * b14; - t19 += v * b15; - v = a[5]; - t5 += v * b0; - t6 += v * b1; - t7 += v * b2; - t8 += v * b3; - t9 += v * b4; - t10 += v * b5; - t11 += v * b6; - t12 += v * b7; - t13 += v * b8; - t14 += v * b9; - t15 += v * b10; - t16 += v * b11; - t17 += v * b12; - t18 += v * b13; - t19 += v * b14; - t20 += v * b15; - v = a[6]; - t6 += v * b0; - t7 += v * b1; - t8 += v * b2; - t9 += v * b3; - t10 += v * b4; - t11 += v * b5; - t12 += v * b6; - t13 += v * b7; - t14 += v * b8; - t15 += v * b9; - t16 += v * b10; - t17 += v * b11; - t18 += v * b12; - t19 += v * b13; - t20 += v * b14; - t21 += v * b15; - v = a[7]; - t7 += v * b0; - t8 += v * b1; - t9 += v * b2; - t10 += v * b3; - t11 += v * b4; - t12 += v * b5; - t13 += v * b6; - t14 += v * b7; - t15 += v * b8; - t16 += v * b9; - t17 += v * b10; - t18 += v * b11; - t19 += v * b12; - t20 += v * b13; - t21 += v * b14; - t22 += v * b15; - v = a[8]; - t8 += v * b0; - t9 += v * b1; - t10 += v * b2; - t11 += v * b3; - t12 += v * b4; - t13 += v * b5; - t14 += v * b6; - t15 += v * b7; - t16 += v * b8; - t17 += v * b9; - t18 += v * b10; - t19 += v * b11; - t20 += v * b12; - t21 += v * b13; - t22 += v * b14; - t23 += v * b15; - v = a[9]; - t9 += v * b0; - t10 += v * b1; - t11 += v * b2; - t12 += v * b3; - t13 += v * b4; - t14 += v * b5; - t15 += v * b6; - t16 += v * b7; - t17 += v * b8; - t18 += v * b9; - t19 += v * b10; - t20 += v * b11; - t21 += v * b12; - t22 += v * b13; - t23 += v * b14; - t24 += v * b15; - v = a[10]; - t10 += v * b0; - t11 += v * b1; - t12 += v * b2; - t13 += v * b3; - t14 += v * b4; - t15 += v * b5; - t16 += v * b6; - t17 += v * b7; - t18 += v * b8; - t19 += v * b9; - t20 += v * b10; - t21 += v * b11; - t22 += v * b12; - t23 += v * b13; - t24 += v * b14; - t25 += v * b15; - v = a[11]; - t11 += v * b0; - t12 += v * b1; - t13 += v * b2; - t14 += v * b3; - t15 += v * b4; - t16 += v * b5; - t17 += v * b6; - t18 += v * b7; - t19 += v * b8; - t20 += v * b9; - t21 += v * b10; - t22 += v * b11; - t23 += v * b12; - t24 += v * b13; - t25 += v * b14; - t26 += v * b15; - v = a[12]; - t12 += v * b0; - t13 += v * b1; - t14 += v * b2; - t15 += v * b3; - t16 += v * b4; - t17 += v * b5; - t18 += v * b6; - t19 += v * b7; - t20 += v * b8; - t21 += v * b9; - t22 += v * b10; - t23 += v * b11; - t24 += v * b12; - t25 += v * b13; - t26 += v * b14; - t27 += v * b15; - v = a[13]; - t13 += v * b0; - t14 += v * b1; - t15 += v * b2; - t16 += v * b3; - t17 += v * b4; - t18 += v * b5; - t19 += v * b6; - t20 += v * b7; - t21 += v * b8; - t22 += v * b9; - t23 += v * b10; - t24 += v * b11; - t25 += v * b12; - t26 += v * b13; - t27 += v * b14; - t28 += v * b15; - v = a[14]; - t14 += v * b0; - t15 += v * b1; - t16 += v * b2; - t17 += v * b3; - t18 += v * b4; - t19 += v * b5; - t20 += v * b6; - t21 += v * b7; - t22 += v * b8; - t23 += v * b9; - t24 += v * b10; - t25 += v * b11; - t26 += v * b12; - t27 += v * b13; - t28 += v * b14; - t29 += v * b15; - v = a[15]; - t15 += v * b0; - t16 += v * b1; - t17 += v * b2; - t18 += v * b3; - t19 += v * b4; - t20 += v * b5; - t21 += v * b6; - t22 += v * b7; - t23 += v * b8; - t24 += v * b9; - t25 += v * b10; - t26 += v * b11; - t27 += v * b12; - t28 += v * b13; - t29 += v * b14; - t30 += v * b15; - - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is - - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); - - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); - - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; -} - -function S(o, a) { - M(o, a, a); -} - -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} - -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} - -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; - } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); - } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; - } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); - return 0; -} - -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); -} - -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); -} - -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); -} - -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; - -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); -} - -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); -} - -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; - -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; - - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], - - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; - - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; - } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; - - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; - - // add - h = ah7; - l = al7; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // K - h = K[i*2]; - l = K[i*2+1]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // w - h = wh[i%16]; - l = wl[i%16]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; - - // add - h = th; - l = tl; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +"use strict"; - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +var Buffer = __webpack_require__(1).Buffer, + crypto = __webpack_require__(3), + util = __webpack_require__(0), + Extensions = __webpack_require__(29), + Base = __webpack_require__(2), + Frame = __webpack_require__(34), + Message = __webpack_require__(35); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +var Hybi = function(request, url, options) { + Base.apply(this, arguments); - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); + this._extensions = new Extensions(); + this._stage = 0; + this._masking = this._options.masking; + this._protocols = this._options.protocols || []; + this._requireMasking = this._options.requireMasking; + this._pingCallbacks = {}; - // add - h = bh3; - l = bl3; + if (typeof this._protocols === 'string') + this._protocols = this._protocols.split(/ *, */); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (!this._request) return; - h = th; - l = tl; + var protos = this._request.headers['sec-websocket-protocol'], + supported = this._protocols; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (protos !== undefined) { + if (typeof protos === 'string') protos = protos.split(/ *, */); + this.protocol = protos.filter(function(p) { return supported.indexOf(p) >= 0 })[0]; + } - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + this.version = 'hybi-' + Hybi.VERSION; +}; +util.inherits(Hybi, Base); - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); +Hybi.VERSION = '13'; - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; +Hybi.mask = function(payload, mask, offset) { + if (!mask || mask.length === 0) return payload; + offset = offset || 0; - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; + for (var i = 0, n = payload.length - offset; i < n; i++) { + payload[offset + i] = payload[offset + i] ^ mask[i % 4]; + } + return payload; +}; - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; +Hybi.generateAccept = function(key) { + var sha1 = crypto.createHash('sha1'); + sha1.update(key + Hybi.GUID); + return sha1.digest('base64'); +}; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; +Hybi.GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; +var instance = { + FIN: 0x80, + MASK: 0x80, + RSV1: 0x40, + RSV2: 0x20, + RSV3: 0x10, + OPCODE: 0x0F, + LENGTH: 0x7F, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + OPCODES: { + continuation: 0, + text: 1, + binary: 2, + close: 8, + ping: 9, + pong: 10 + }, - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + OPCODE_CODES: [0, 1, 2, 8, 9, 10], + MESSAGE_OPCODES: [0, 1, 2], + OPENING_OPCODES: [1, 2], - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + ERRORS: { + normal_closure: 1000, + going_away: 1001, + protocol_error: 1002, + unacceptable: 1003, + encoding_error: 1007, + policy_violation: 1008, + too_large: 1009, + extension_error: 1010, + unexpected_condition: 1011 + }, - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + ERROR_CODES: [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011], + DEFAULT_ERROR_CODE: 1000, + MIN_RESERVED_ERROR: 3000, + MAX_RESERVED_ERROR: 4999, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + // http://www.w3.org/International/questions/qa-forms-utf-8.en.php + UTF8_MATCH: /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/, - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + addExtension: function(extension) { + this._extensions.add(extension); + return true; + }, - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); - } - } - } + parse: function(chunk) { + this._reader.put(chunk); + var buffer = true; + while (buffer) { + switch (this._stage) { + case 0: + buffer = this._reader.read(1); + if (buffer) this._parseOpcode(buffer[0]); + break; - // add - h = ah0; - l = al0; + case 1: + buffer = this._reader.read(1); + if (buffer) this._parseLength(buffer[0]); + break; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + case 2: + buffer = this._reader.read(this._frame.lengthBytes); + if (buffer) this._parseExtendedLength(buffer); + break; - h = hh[0]; - l = hl[0]; + case 3: + buffer = this._reader.read(4); + if (buffer) { + this._stage = 4; + this._frame.maskingKey = buffer; + } + break; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + case 4: + buffer = this._reader.read(this._frame.length); + if (buffer) { + this._stage = 0; + this._emitFrame(buffer); + } + break; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + default: + buffer = null; + } + } + }, - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); + text: function(message) { + if (this.readyState > 1) return false; + return this.frame(message, 'text'); + }, - h = ah1; - l = al1; + binary: function(message) { + if (this.readyState > 1) return false; + return this.frame(message, 'binary'); + }, - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + ping: function(message, callback) { + if (this.readyState > 1) return false; + message = message || ''; + if (callback) this._pingCallbacks[message] = callback; + return this.frame(message, 'ping'); + }, - h = hh[1]; - l = hl[1]; + pong: function(message) { + if (this.readyState > 1) return false; + message = message ||''; + return this.frame(message, 'pong'); + }, - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + close: function(reason, code) { + reason = reason || ''; + code = code || this.ERRORS.normal_closure; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (this.readyState <= 0) { + this.readyState = 3; + this.emit('close', new Base.CloseEvent(code, reason)); + return true; + } else if (this.readyState === 1) { + this.readyState = 2; + this._extensions.close(function() { this.frame(reason, 'close', code) }, this); + return true; + } else { + return false; + } + }, - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); + frame: function(buffer, type, code) { + if (this.readyState <= 0) return this._queue([buffer, type, code]); + if (this.readyState > 2) return false; - h = ah2; - l = al2; + if (buffer instanceof Array) buffer = Buffer.from(buffer); + if (typeof buffer === 'number') buffer = buffer.toString(); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + var message = new Message(), + isText = (typeof buffer === 'string'), + payload, copy; - h = hh[2]; - l = hl[2]; + message.rsv1 = message.rsv2 = message.rsv3 = false; + message.opcode = this.OPCODES[type || (isText ? 'text' : 'binary')]; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + payload = isText ? Buffer.from(buffer, 'utf8') : buffer; - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (code) { + copy = payload; + payload = Buffer.allocUnsafe(2 + copy.length); + payload.writeUInt16BE(code, 0); + copy.copy(payload, 2); + } + message.data = payload; - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); + var onMessageReady = function(message) { + var frame = new Frame(); - h = ah3; - l = al3; + frame.final = true; + frame.rsv1 = message.rsv1; + frame.rsv2 = message.rsv2; + frame.rsv3 = message.rsv3; + frame.opcode = message.opcode; + frame.masked = !!this._masking; + frame.length = message.data.length; + frame.payload = message.data; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (frame.masked) frame.maskingKey = crypto.randomBytes(4); - h = hh[3]; - l = hl[3]; + this._sendFrame(frame); + }; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (this.MESSAGE_OPCODES.indexOf(message.opcode) >= 0) + this._extensions.processOutgoingMessage(message, function(error, message) { + if (error) return this._fail('extension_error', error.message); + onMessageReady.call(this, message); + }, this); + else + onMessageReady.call(this, message); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + return true; + }, - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); + _sendFrame: function(frame) { + var length = frame.length, + header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10), + offset = header + (frame.masked ? 4 : 0), + buffer = Buffer.allocUnsafe(offset + length), + masked = frame.masked ? this.MASK : 0; - h = ah4; - l = al4; + buffer[0] = (frame.final ? this.FIN : 0) | + (frame.rsv1 ? this.RSV1 : 0) | + (frame.rsv2 ? this.RSV2 : 0) | + (frame.rsv3 ? this.RSV3 : 0) | + frame.opcode; - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (length <= 125) { + buffer[1] = masked | length; + } else if (length <= 65535) { + buffer[1] = masked | 126; + buffer.writeUInt16BE(length, 2); + } else { + buffer[1] = masked | 127; + buffer.writeUInt32BE(Math.floor(length / 0x100000000), 2); + buffer.writeUInt32BE(length % 0x100000000, 6); + } - h = hh[4]; - l = hl[4]; + frame.payload.copy(buffer, offset); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (frame.masked) { + frame.maskingKey.copy(buffer, header); + Hybi.mask(buffer, frame.maskingKey, offset); + } - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + this._write(buffer); + }, - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); + _handshakeResponse: function() { + var secKey = this._request.headers['sec-websocket-key'], + version = this._request.headers['sec-websocket-version']; - h = ah5; - l = al5; + if (version !== Hybi.VERSION) + throw new Error('Unsupported WebSocket version: ' + version); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + if (typeof secKey !== 'string') + throw new Error('Missing handshake request header: Sec-WebSocket-Key'); - h = hh[5]; - l = hl[5]; + this._headers.set('Upgrade', 'websocket'); + this._headers.set('Connection', 'Upgrade'); + this._headers.set('Sec-WebSocket-Accept', Hybi.generateAccept(secKey)); - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (this.protocol) this._headers.set('Sec-WebSocket-Protocol', this.protocol); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + var extensions = this._extensions.generateResponse(this._request.headers['sec-websocket-extensions']); + if (extensions) this._headers.set('Sec-WebSocket-Extensions', extensions); - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); + var start = 'HTTP/1.1 101 Switching Protocols', + headers = [start, this._headers.toString(), '']; - h = ah6; - l = al6; + return Buffer.from(headers.join('\r\n'), 'utf8'); + }, - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + _shutdown: function(code, reason, error) { + delete this._frame; + delete this._message; + this._stage = 5; - h = hh[6]; - l = hl[6]; + var sendCloseFrame = (this.readyState === 1); + this.readyState = 2; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + this._extensions.close(function() { + if (sendCloseFrame) this.frame(reason, 'close', code); + this.readyState = 3; + if (error) this.emit('error', new Error(reason)); + this.emit('close', new Base.CloseEvent(code, reason)); + }, this); + }, - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + _fail: function(type, message) { + if (this.readyState > 1) return; + this._shutdown(this.ERRORS[type], message, true); + }, - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); + _parseOpcode: function(octet) { + var rsvs = [this.RSV1, this.RSV2, this.RSV3].map(function(rsv) { + return (octet & rsv) === rsv; + }); - h = ah7; - l = al7; + var frame = this._frame = new Frame(); - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; + frame.final = (octet & this.FIN) === this.FIN; + frame.rsv1 = rsvs[0]; + frame.rsv2 = rsvs[1]; + frame.rsv3 = rsvs[2]; + frame.opcode = (octet & this.OPCODE); - h = hh[7]; - l = hl[7]; + this._stage = 1; - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; + if (!this._extensions.validFrameRsv(frame)) + return this._fail('protocol_error', + 'One or more reserved bits are on: reserved1 = ' + (frame.rsv1 ? 1 : 0) + + ', reserved2 = ' + (frame.rsv2 ? 1 : 0) + + ', reserved3 = ' + (frame.rsv3 ? 1 : 0)); - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; + if (this.OPCODE_CODES.indexOf(frame.opcode) < 0) + return this._fail('protocol_error', 'Unrecognized frame opcode: ' + frame.opcode); - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); + if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && !frame.final) + return this._fail('protocol_error', 'Received fragmented control frame: opcode = ' + frame.opcode); - pos += 128; - n -= 128; - } + if (this._message && this.OPENING_OPCODES.indexOf(frame.opcode) >= 0) + return this._fail('protocol_error', 'Received new data frame but previous continuous frame is unfinished'); + }, - return n; -} + _parseLength: function(octet) { + var frame = this._frame; + frame.masked = (octet & this.MASK) === this.MASK; + frame.length = (octet & this.LENGTH); -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; + if (frame.length >= 0 && frame.length <= 125) { + this._stage = frame.masked ? 3 : 4; + if (!this._checkFrameLength()) return; + } else { + this._stage = 2; + frame.lengthBytes = (frame.length === 126 ? 2 : 8); + } - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; + if (this._requireMasking && !frame.masked) + return this._fail('unacceptable', 'Received unmasked frame but masking is required'); + }, - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; + _parseExtendedLength: function(buffer) { + var frame = this._frame; + frame.length = this._readUInt(buffer); - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; + this._stage = frame.masked ? 3 : 4; - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; + if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && frame.length > 125) + return this._fail('protocol_error', 'Received control frame having too long payload: ' + frame.length); - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); + if (!this._checkFrameLength()) return; + }, - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + _checkFrameLength: function() { + var length = this._message ? this._message.length : 0; - return 0; -} + if (length + this._frame.length > this._maxLength) { + this._fail('too_large', 'WebSocket frame length too large'); + return false; + } else { + return true; + } + }, -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); + _emitFrame: function(buffer) { + var frame = this._frame, + payload = frame.payload = Hybi.mask(buffer, frame.maskingKey), + opcode = frame.opcode, + message, + code, reason, + callbacks, callback; - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); + delete this._frame; - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); -} + if (opcode === this.OPCODES.continuation) { + if (!this._message) return this._fail('protocol_error', 'Received unexpected continuation frame'); + this._message.pushFrame(frame); + } -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } -} + if (opcode === this.OPCODES.text || opcode === this.OPCODES.binary) { + this._message = new Message(); + this._message.pushFrame(frame); + } -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; -} + if (frame.final && this.MESSAGE_OPCODES.indexOf(opcode) >= 0) + return this._emitMessage(this._message); -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); - } -} + if (opcode === this.OPCODES.close) { + code = (payload.length >= 2) ? payload.readUInt16BE(0) : null; + reason = (payload.length > 2) ? this._encode(payload.slice(2)) : null; -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -} + if (!(payload.length === 0) && + !(code !== null && code >= this.MIN_RESERVED_ERROR && code <= this.MAX_RESERVED_ERROR) && + this.ERROR_CODES.indexOf(code) < 0) + code = this.ERRORS.protocol_error; -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; + if (payload.length > 125 || (payload.length > 2 && !reason)) + code = this.ERRORS.protocol_error; - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; + this._shutdown(code || this.DEFAULT_ERROR_CODE, reason || ''); + } - scalarbase(p, d); - pack(pk, p); + if (opcode === this.OPCODES.ping) { + this.frame(payload, 'pong'); + this.emit('ping', new Base.PingEvent(payload.toString())) + } - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; -} + if (opcode === this.OPCODES.pong) { + callbacks = this._pingCallbacks; + message = this._encode(payload); + callback = callbacks[message]; -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); + delete callbacks[message]; + if (callback) callback() -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; + this.emit('pong', new Base.PongEvent(payload.toString())) } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; - } -} + }, -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); -} + _emitMessage: function(message) { + var message = this._message; + message.read(); -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; + delete this._message; - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; + this._extensions.processIncomingMessage(message, function(error, message) { + if (error) return this._fail('extension_error', error.message); - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; + var payload = message.data; + if (message.opcode === this.OPCODES.text) payload = this._encode(payload); - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); + if (payload === null) + return this._fail('encoding_error', 'Could not decode a text frame as UTF-8'); + else + this.emit('message', new Base.MessageEvent(payload)); + }, this); + }, + + _encode: function(buffer) { + try { + var string = buffer.toString('binary', 0, buffer.length); + if (!this.UTF8_MATCH.test(string)) return null; + } catch (e) {} + return buffer.toString('utf8', 0, buffer.length); + }, - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); + _readUInt: function(buffer) { + if (buffer.length === 2) return buffer.readUInt16BE(0); - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; - } + return buffer.readUInt32BE(0) * 0x100000000 + + buffer.readUInt32BE(4); } +}; - modL(sm.subarray(32), x); - return smlen; -} +for (var key in instance) + Hybi.prototype[key] = instance[key]; -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); +module.exports = Hybi; - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); +"use strict"; - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; +var RingBuffer = function(bufferSize) { + this._bufferSize = bufferSize; + this.clear(); +}; - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); +RingBuffer.prototype.clear = function() { + this._buffer = new Array(this._bufferSize); + this._ringOffset = 0; + this._ringSize = this._bufferSize; + this._head = 0; + this._tail = 0; + this.length = 0; +}; - M(r[3], r[0], r[1]); - return 0; -} +RingBuffer.prototype.push = function(value) { + var expandBuffer = false, + expandRing = false; -function crypto_sign_open(m, sm, n, pk) { - var i, mlen; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; + if (this._ringSize < this._bufferSize) { + expandBuffer = (this._tail === 0); + } else if (this._ringOffset === this._ringSize) { + expandBuffer = true; + expandRing = (this._tail === 0); + } - mlen = -1; - if (n < 64) return -1; + if (expandBuffer) { + this._tail = this._bufferSize; + this._buffer = this._buffer.concat(new Array(this._bufferSize)); + this._bufferSize = this._buffer.length; - if (unpackneg(q, pk)) return -1; + if (expandRing) + this._ringSize = this._bufferSize; + } - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); + this._buffer[this._tail] = value; + this.length += 1; + if (this._tail < this._ringSize) this._ringOffset += 1; + this._tail = (this._tail + 1) % this._bufferSize; +}; - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); +RingBuffer.prototype.peek = function() { + if (this.length === 0) return void 0; + return this._buffer[this._head]; +}; - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; +RingBuffer.prototype.shift = function() { + if (this.length === 0) return void 0; + + var value = this._buffer[this._head]; + this._buffer[this._head] = void 0; + this.length -= 1; + this._ringOffset -= 1; + + if (this._ringOffset === 0 && this.length > 0) { + this._head = this._ringSize; + this._ringOffset = this.length; + this._ringSize = this._bufferSize; + } else { + this._head = (this._head + 1) % this._ringSize; } + return value; +}; - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - mlen = n; - return mlen; -} +module.exports = RingBuffer; -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES -}; +"use strict"; -/* High-level API */ -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} +var RingBuffer = __webpack_require__(14); -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} +var Pledge = function() { + this._complete = false; + this._callbacks = new RingBuffer(Pledge.QUEUE_SIZE); +}; -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} +Pledge.QUEUE_SIZE = 4; -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} +Pledge.all = function(list) { + var pledge = new Pledge(), + pending = list.length, + n = pending; -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; + if (pending === 0) pledge.done(); + + while (n--) list[n].then(function() { + pending -= 1; + if (pending === 0) pledge.done(); + }); + return pledge; }; -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); +Pledge.prototype.then = function(callback) { + if (this._complete) callback(); + else this._callbacks.push(callback); }; -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); +Pledge.prototype.done = function() { + this._complete = true; + var callbacks = this._callbacks, callback; + while (callback = callbacks.shift()) callback(); }; -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; +module.exports = Pledge; -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; +/***/ }), +/* 16 */ +/***/ (function(module, exports, __webpack_require__) { -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; +"use strict"; -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); -}; -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; +var Buffer = __webpack_require__(1).Buffer, + Base = __webpack_require__(2), + util = __webpack_require__(0); -nacl.box.after = nacl.secretbox; +var Draft75 = function(request, url, options) { + Base.apply(this, arguments); + this._stage = 0; + this.version = 'hixie-75'; -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); + this._headers.set('Upgrade', 'WebSocket'); + this._headers.set('Connection', 'Upgrade'); + this._headers.set('WebSocket-Origin', this._request.headers.origin); + this._headers.set('WebSocket-Location', this.url); }; +util.inherits(Draft75, Base); -nacl.box.open.after = nacl.secretbox.open; +var instance = { + close: function() { + if (this.readyState === 3) return false; + this.readyState = 3; + this.emit('close', new Base.CloseEvent(null, null)); + return true; + }, -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; + parse: function(chunk) { + if (this.readyState > 1) return; -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; + this._reader.put(chunk); -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; + this._reader.eachByte(function(octet) { + var message; -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; + switch (this._stage) { + case -1: + this._body.push(octet); + this._sendHandshakeBody(); + break; -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; + case 0: + this._parseLeadingByte(octet); + break; -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; + case 1: + this._length = (octet & 0x7F) + 128 * this._length; -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; + if (this._closing && this._length === 0) { + return this.close(); + } + else if ((octet & 0x80) !== 0x80) { + if (this._length === 0) { + this._stage = 0; + } + else { + this._skipped = 0; + this._stage = 2; + } + } + break; -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; + case 2: + if (octet === 0xFF) { + this._stage = 0; + message = Buffer.from(this._buffer).toString('utf8', 0, this._buffer.length); + this.emit('message', new Base.MessageEvent(message)); + } + else { + if (this._length) { + this._skipped += 1; + if (this._skipped === this._length) + this._stage = 0; + } else { + this._buffer.push(octet); + if (this._buffer.length > this._maxLength) return this.close(); + } + } + break; + } + }, this); + }, -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; + frame: function(buffer) { + if (this.readyState === 0) return this._queue([buffer]); + if (this.readyState > 1) return false; -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; -}; + if (typeof buffer !== 'string') buffer = buffer.toString(); -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; + var length = Buffer.byteLength(buffer), + frame = Buffer.allocUnsafe(length + 2); -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; + frame[0] = 0x00; + frame.write(buffer, 1); + frame[frame.length - 1] = 0xFF; -nacl.hash.hashLength = crypto_hash_BYTES; + this._write(frame); + return true; + }, -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; + _handshakeResponse: function() { + var start = 'HTTP/1.1 101 Web Socket Protocol Handshake', + headers = [start, this._headers.toString(), '']; -nacl.setPRNG = function(fn) { - randombytes = fn; -}; + return Buffer.from(headers.join('\r\n'), 'utf8'); + }, -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); - } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (true) { - // Node.js. - crypto = __webpack_require__(5); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); + _parseLeadingByte: function(octet) { + if ((octet & 0x80) === 0x80) { + this._length = 0; + this._stage = 1; + } else { + delete this._length; + delete this._skipped; + this._buffer = []; + this._stage = 2; } } -})(); +}; -})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); +for (var key in instance) + Draft75.prototype[key] = instance[key]; + +module.exports = Draft75; /***/ }), -/* 4 */ +/* 17 */ /***/ (function(module, exports, __webpack_require__) { -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if ( true && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; +var Event = __webpack_require__(7); - var util = {}; +var EventTarget = { + onopen: null, + onmessage: null, + onerror: null, + onclose: null, - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); - } + addEventListener: function(eventType, listener, useCapture) { + this.on(eventType, listener); + }, + + removeEventListener: function(eventType, listener, useCapture) { + this.removeListener(eventType, listener); + }, + + dispatchEvent: function(event) { + event.target = event.currentTarget = this; + event.eventPhase = Event.AT_TARGET; + + if (this['on' + event.type]) + this['on' + event.type](event); + + this.emit(event.type, event); } +}; - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; +module.exports = EventTarget; - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; - if (typeof atob === 'undefined') { - // Node.js +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; +// API references: +// +// * http://dev.w3.org/html5/websockets/ +// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget +// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; +var util = __webpack_require__(0), + driver = __webpack_require__(4), + API = __webpack_require__(11); - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; +var WebSocket = function(request, socket, body, protocols, options) { + options = options || {}; - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; - } + this._stream = socket; + this._driver = driver.http(request, {maxLength: options.maxLength, protocols: protocols}); - } else { - // Browsers + var self = this; + if (!this._stream || !this._stream.writable) return; + if (!this._stream.readable) return this._stream.end(); - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - }; + var catchup = function() { self._stream.removeListener('data', catchup) }; + this._stream.on('data', catchup); - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; + API.call(this, options); - } + process.nextTick(function() { + self._driver.start(); + self._driver.io.write(body); + }); +}; +util.inherits(WebSocket, API); - return util; +WebSocket.isWebSocket = function(request) { + return driver.isWebSocket(request); +}; -})); +WebSocket.validateOptions = function(options, validKeys) { + driver.validateOptions(options, validKeys); +}; +WebSocket.WebSocket = WebSocket; +WebSocket.Client = __webpack_require__(39); +WebSocket.EventSource = __webpack_require__(42); -/***/ }), -/* 5 */ -/***/ (function(module, exports) { +module.exports = WebSocket; -module.exports = require("crypto"); /***/ }), -/* 6 */ +/* 19 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +/** + * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object. + * + * This can be used with JS designed for browsers to improve reuse of code and + * allow the use of existing libraries. + * + * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs. + * + * @author Dan DeFelippi + * @contributor David Ellis + * @license MIT + */ +var Url = __webpack_require__(6); +var spawn = __webpack_require__(43).spawn; +var fs = __webpack_require__(44); -// Protocol references: -// -// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 -// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 -// * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 +exports.XMLHttpRequest = function() { + "use strict"; -var Base = __webpack_require__(2), - Client = __webpack_require__(25), - Server = __webpack_require__(36); + /** + * Private variables + */ + var self = this; + var http = __webpack_require__(45); + var https = __webpack_require__(46); -var Driver = { - client: function(url, options) { - options = options || {}; - if (options.masking === undefined) options.masking = true; - return new Client(url, options); - }, + // Holds http.js objects + var request; + var response; - server: function(options) { - options = options || {}; - if (options.requireMasking === undefined) options.requireMasking = true; - return new Server(options); - }, + // Request settings + var settings = {}; - http: function() { - return Server.http.apply(Server, arguments); - }, + // Disable header blacklist. + // Not part of XHR specs. + var disableHeaderCheck = false; - isSecureRequest: function(request) { - return Server.isSecureRequest(request); - }, + // Set some default headers + var defaultHeaders = { + "User-Agent": "node-XMLHttpRequest", + "Accept": "*/*", + }; - isWebSocket: function(request) { - return Base.isWebSocket(request); - }, + var headers = {}; + var headersCase = {}; - validateOptions: function(options, validKeys) { - Base.validateOptions(options, validKeys); - } -}; + // These headers are not user setable. + // The following are allowed but banned in the spec: + // * user-agent + var forbiddenRequestHeaders = [ + "accept-charset", + "accept-encoding", + "access-control-request-headers", + "access-control-request-method", + "connection", + "content-length", + "content-transfer-encoding", + "cookie", + "cookie2", + "date", + "expect", + "host", + "keep-alive", + "origin", + "referer", + "te", + "trailer", + "transfer-encoding", + "upgrade", + "via" + ]; -module.exports = Driver; + // These request methods are not allowed + var forbiddenRequestMethods = [ + "TRACE", + "TRACK", + "CONNECT" + ]; + // Send flag + var sendFlag = false; + // Error flag, used when errors occur or abort is called + var errorFlag = false; -/***/ }), -/* 7 */ -/***/ (function(module, exports) { + // Event listeners + var listeners = {}; -module.exports = require("stream"); + /** + * Constants + */ -/***/ }), -/* 8 */ -/***/ (function(module, exports) { + this.UNSENT = 0; + this.OPENED = 1; + this.HEADERS_RECEIVED = 2; + this.LOADING = 3; + this.DONE = 4; + + /** + * Public vars + */ + + // Current state + this.readyState = this.UNSENT; + + // default ready state change handler in case one is not set or is set late + this.onreadystatechange = null; + + // Result & response + this.responseText = ""; + this.responseXML = ""; + this.status = null; + this.statusText = null; + + // Whether cross-site Access-Control requests should be made using + // credentials such as cookies or authorization headers + this.withCredentials = false; + + /** + * Private methods + */ + + /** + * Check if the specified header is allowed. + * + * @param string header Header to validate + * @return boolean False if not allowed, otherwise true + */ + var isAllowedHttpHeader = function(header) { + return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1); + }; + + /** + * Check if the specified method is allowed. + * + * @param string method Request method to validate + * @return boolean False if not allowed, otherwise true + */ + var isAllowedHttpMethod = function(method) { + return (method && forbiddenRequestMethods.indexOf(method) === -1); + }; + + /** + * Public methods + */ -module.exports = require("url"); + /** + * Open the connection. Currently supports local server requests. + * + * @param string method Connection method (eg GET, POST) + * @param string url URL for the connection. + * @param boolean async Asynchronous connection. Default is true. + * @param string user Username for basic authentication (optional) + * @param string password Password for basic authentication (optional) + */ + this.open = function(method, url, async, user, password) { + this.abort(); + errorFlag = false; -/***/ }), -/* 9 */ -/***/ (function(module, exports) { + // Check for valid request method + if (!isAllowedHttpMethod(method)) { + throw new Error("SecurityError: Request method not allowed"); + } -var Event = function(eventType, options) { - this.type = eventType; - for (var key in options) - this[key] = options[key]; -}; + settings = { + "method": method, + "url": url.toString(), + "async": (typeof async !== "boolean" ? true : async), + "user": user || null, + "password": password || null + }; -Event.prototype.initEvent = function(eventType, canBubble, cancelable) { - this.type = eventType; - this.bubbles = canBubble; - this.cancelable = cancelable; -}; + setState(this.OPENED); + }; -Event.prototype.stopPropagation = function() {}; -Event.prototype.preventDefault = function() {}; + /** + * Disables or enables isAllowedHttpHeader() check the request. Enabled by default. + * This does not conform to the W3C spec. + * + * @param boolean state Enable or disable header checking. + */ + this.setDisableHeaderCheck = function(state) { + disableHeaderCheck = state; + }; -Event.CAPTURING_PHASE = 1; -Event.AT_TARGET = 2; -Event.BUBBLING_PHASE = 3; + /** + * Sets a header for the request or appends the value if one is already set. + * + * @param string header Header name + * @param string value Header value + */ + this.setRequestHeader = function(header, value) { + if (this.readyState !== this.OPENED) { + throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN"); + } + if (!isAllowedHttpHeader(header)) { + console.warn("Refused to set unsafe header \"" + header + "\""); + return; + } + if (sendFlag) { + throw new Error("INVALID_STATE_ERR: send flag is true"); + } + header = headersCase[header.toLowerCase()] || header; + headersCase[header.toLowerCase()] = header; + headers[header] = headers[header] ? headers[header] + ', ' + value : value; + }; -module.exports = Event; + /** + * Gets a header from the server response. + * + * @param string header Name of header to get. + * @return string Text of the header or null if it doesn't exist. + */ + this.getResponseHeader = function(header) { + if (typeof header === "string" + && this.readyState > this.OPENED + && response + && response.headers + && response.headers[header.toLowerCase()] + && !errorFlag + ) { + return response.headers[header.toLowerCase()]; + } + return null; + }; -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { + /** + * Gets all the response headers. + * + * @return string A string with all response headers separated by CR+LF + */ + this.getAllResponseHeaders = function() { + if (this.readyState < this.HEADERS_RECEIVED || errorFlag) { + return ""; + } + var result = ""; -"use strict"; + for (var i in response.headers) { + // Cookie headers are excluded + if (i !== "set-cookie" && i !== "set-cookie2") { + result += i + ": " + response.headers[i] + "\r\n"; + } + } + return result.substr(0, result.length - 2); + }; + /** + * Gets a request header + * + * @param string name Name of header to get + * @return string Returns the request header or empty string if not set + */ + this.getRequestHeader = function(name) { + if (typeof name === "string" && headersCase[name.toLowerCase()]) { + return headers[headersCase[name.toLowerCase()]]; + } -var Headers = function() { - this.clear(); -}; + return ""; + }; -Headers.prototype.ALLOWED_DUPLICATES = ['set-cookie', 'set-cookie2', 'warning', 'www-authenticate']; + /** + * Sends the request to the server. + * + * @param string data Optional data to send as request body. + */ + this.send = function(data) { + if (this.readyState !== this.OPENED) { + throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called"); + } -Headers.prototype.clear = function() { - this._sent = {}; - this._lines = []; -}; + if (sendFlag) { + throw new Error("INVALID_STATE_ERR: send has already been called"); + } -Headers.prototype.set = function(name, value) { - if (value === undefined) return; + var ssl = false, local = false; + var url = Url.parse(settings.url); + var host; + // Determine the server + switch (url.protocol) { + case "https:": + ssl = true; + // SSL & non-SSL both need host, no break here. + case "http:": + host = url.hostname; + break; - name = this._strip(name); - value = this._strip(value); + case "file:": + local = true; + break; - var key = name.toLowerCase(); - if (!this._sent.hasOwnProperty(key) || this.ALLOWED_DUPLICATES.indexOf(key) >= 0) { - this._sent[key] = true; - this._lines.push(name + ': ' + value + '\r\n'); - } -}; + case undefined: + case null: + case "": + host = "localhost"; + break; -Headers.prototype.toString = function() { - return this._lines.join(''); -}; + default: + throw new Error("Protocol not supported."); + } -Headers.prototype._strip = function(string) { - return string.toString().replace(/^ */, '').replace(/ *$/, ''); -}; + // Load files off the local filesystem (file://) + if (local) { + if (settings.method !== "GET") { + throw new Error("XMLHttpRequest: Only GET method is supported"); + } -module.exports = Headers; + if (settings.async) { + fs.readFile(url.pathname, "utf8", function(error, data) { + if (error) { + self.handleError(error); + } else { + self.status = 200; + self.responseText = data; + setState(self.DONE); + } + }); + } else { + try { + this.responseText = fs.readFileSync(url.pathname, "utf8"); + this.status = 200; + setState(self.DONE); + } catch(e) { + this.handleError(e); + } + } + return; + } -/***/ }), -/* 11 */ -/***/ (function(module, exports, __webpack_require__) { + // Default to port 80. If accessing localhost on another port be sure + // to use http://localhost:port/path + var port = url.port || (ssl ? 443 : 80); + // Add query string if one is used + var uri = url.pathname + (url.search ? url.search : ""); -"use strict"; + // Set the defaults if they haven't been set + for (var name in defaultHeaders) { + if (!headersCase[name.toLowerCase()]) { + headers[name] = defaultHeaders[name]; + } + } + // Set the Host header or the server may reject the request + headers.Host = host; + if (!((ssl && port === 443) || port === 80)) { + headers.Host += ":" + url.port; + } -var NodeHTTPParser = __webpack_require__(26).HTTPParser, - Buffer = __webpack_require__(1).Buffer; + // Set Basic Auth if necessary + if (settings.user) { + if (typeof settings.password === "undefined") { + settings.password = ""; + } + var authBuf = new Buffer(settings.user + ":" + settings.password); + headers.Authorization = "Basic " + authBuf.toString("base64"); + } -var TYPES = { - request: NodeHTTPParser.REQUEST || 'request', - response: NodeHTTPParser.RESPONSE || 'response' -}; + // Set content length header + if (settings.method === "GET" || settings.method === "HEAD") { + data = null; + } else if (data) { + headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data); + + if (!headers["Content-Type"]) { + headers["Content-Type"] = "text/plain;charset=UTF-8"; + } + } else if (settings.method === "POST") { + // For a post with no data set Content-Length: 0. + // This is required by buggy servers that don't meet the specs. + headers["Content-Length"] = 0; + } -var HttpParser = function(type) { - this._type = type; - this._parser = new NodeHTTPParser(TYPES[type]); - this._complete = false; - this.headers = {}; + var options = { + host: host, + port: port, + path: uri, + method: settings.method, + headers: headers, + agent: false, + withCredentials: self.withCredentials + }; - var current = null, - self = this; + // Reset error flag + errorFlag = false; - this._parser.onHeaderField = function(b, start, length) { - current = b.toString('utf8', start, start + length).toLowerCase(); - }; + // Handle async requests + if (settings.async) { + // Use the proper protocol + var doRequest = ssl ? https.request : http.request; - this._parser.onHeaderValue = function(b, start, length) { - var value = b.toString('utf8', start, start + length); + // Request is being sent, set send flag + sendFlag = true; - if (self.headers.hasOwnProperty(current)) - self.headers[current] += ', ' + value; - else - self.headers[current] = value; - }; + // As per spec, this is called here for historical reasons. + self.dispatchEvent("readystatechange"); - this._parser.onHeadersComplete = this._parser[NodeHTTPParser.kOnHeadersComplete] = - function(majorVersion, minorVersion, headers, method, pathname, statusCode) { - var info = arguments[0]; + // Handler for the response + var responseHandler = function responseHandler(resp) { + // Set response var to the response we got back + // This is so it remains accessable outside this scope + response = resp; + // Check for redirect + // @TODO Prevent looped redirects + if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { + // Change URL to the redirect location + settings.url = response.headers.location; + var url = Url.parse(settings.url); + // Set host var in case it's used later + host = url.hostname; + // Options for the new request + var newOptions = { + hostname: url.hostname, + port: url.port, + path: url.path, + method: response.statusCode === 303 ? "GET" : settings.method, + headers: headers, + withCredentials: self.withCredentials + }; - if (typeof info === 'object') { - method = info.method; - pathname = info.url; - statusCode = info.statusCode; - headers = info.headers; - } + // Issue the new request + request = doRequest(newOptions, responseHandler).on("error", errorHandler); + request.end(); + // @TODO Check if an XHR event needs to be fired here + return; + } - self.method = (typeof method === 'number') ? HttpParser.METHODS[method] : method; - self.statusCode = statusCode; - self.url = pathname; + response.setEncoding("utf8"); - if (!headers) return; + setState(self.HEADERS_RECEIVED); + self.status = response.statusCode; - for (var i = 0, n = headers.length, key, value; i < n; i += 2) { - key = headers[i].toLowerCase(); - value = headers[i+1]; - if (self.headers.hasOwnProperty(key)) - self.headers[key] += ', ' + value; - else - self.headers[key] = value; - } + response.on("data", function(chunk) { + // Make sure there's some data + if (chunk) { + self.responseText += chunk; + } + // Don't emit state changes if the connection has been aborted. + if (sendFlag) { + setState(self.LOADING); + } + }); - self._complete = true; - }; -}; + response.on("end", function() { + if (sendFlag) { + // Discard the end event if the connection has been aborted + setState(self.DONE); + sendFlag = false; + } + }); -HttpParser.METHODS = { - 0: 'DELETE', - 1: 'GET', - 2: 'HEAD', - 3: 'POST', - 4: 'PUT', - 5: 'CONNECT', - 6: 'OPTIONS', - 7: 'TRACE', - 8: 'COPY', - 9: 'LOCK', - 10: 'MKCOL', - 11: 'MOVE', - 12: 'PROPFIND', - 13: 'PROPPATCH', - 14: 'SEARCH', - 15: 'UNLOCK', - 16: 'BIND', - 17: 'REBIND', - 18: 'UNBIND', - 19: 'ACL', - 20: 'REPORT', - 21: 'MKACTIVITY', - 22: 'CHECKOUT', - 23: 'MERGE', - 24: 'M-SEARCH', - 25: 'NOTIFY', - 26: 'SUBSCRIBE', - 27: 'UNSUBSCRIBE', - 28: 'PATCH', - 29: 'PURGE', - 30: 'MKCALENDAR', - 31: 'LINK', - 32: 'UNLINK' -}; + response.on("error", function(error) { + self.handleError(error); + }); + }; -var VERSION = (process.version || '') - .match(/[0-9]+/g) - .map(function(n) { return parseInt(n, 10) }); + // Error handler for the request + var errorHandler = function errorHandler(error) { + self.handleError(error); + }; -if (VERSION[0] === 0 && VERSION[1] === 12) { - HttpParser.METHODS[16] = 'REPORT'; - HttpParser.METHODS[17] = 'MKACTIVITY'; - HttpParser.METHODS[18] = 'CHECKOUT'; - HttpParser.METHODS[19] = 'MERGE'; - HttpParser.METHODS[20] = 'M-SEARCH'; - HttpParser.METHODS[21] = 'NOTIFY'; - HttpParser.METHODS[22] = 'SUBSCRIBE'; - HttpParser.METHODS[23] = 'UNSUBSCRIBE'; - HttpParser.METHODS[24] = 'PATCH'; - HttpParser.METHODS[25] = 'PURGE'; -} + // Create the request + request = doRequest(options, responseHandler).on("error", errorHandler); -HttpParser.prototype.isComplete = function() { - return this._complete; -}; + // Node 0.4 and later won't accept empty data. Make sure it's needed. + if (data) { + request.write(data); + } -HttpParser.prototype.parse = function(chunk) { - var consumed = this._parser.execute(chunk, 0, chunk.length); + request.end(); - if (typeof consumed !== 'number') { - this.error = consumed; - this._complete = true; - return; - } + self.dispatchEvent("loadstart"); + } else { // Synchronous + // Create a temporary file for communication with the other Node process + var contentFile = ".node-xmlhttprequest-content-" + process.pid; + var syncFile = ".node-xmlhttprequest-sync-" + process.pid; + fs.writeFileSync(syncFile, "", "utf8"); + // The async request the other Node process executes + var execString = "var http = require('http'), https = require('https'), fs = require('fs');" + + "var doRequest = http" + (ssl ? "s" : "") + ".request;" + + "var options = " + JSON.stringify(options) + ";" + + "var responseText = '';" + + "var req = doRequest(options, function(response) {" + + "response.setEncoding('utf8');" + + "response.on('data', function(chunk) {" + + " responseText += chunk;" + + "});" + + "response.on('end', function() {" + + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}), 'utf8');" + + "fs.unlinkSync('" + syncFile + "');" + + "});" + + "response.on('error', function(error) {" + + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" + + "fs.unlinkSync('" + syncFile + "');" + + "});" + + "}).on('error', function(error) {" + + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" + + "fs.unlinkSync('" + syncFile + "');" + + "});" + + (data ? "req.write('" + JSON.stringify(data).slice(1,-1).replace(/'/g, "\\'") + "');":"") + + "req.end();"; + // Start the other Node Process, executing this string + var syncProc = spawn(process.argv[0], ["-e", execString]); + while(fs.existsSync(syncFile)) { + // Wait while the sync file is empty + } + var resp = JSON.parse(fs.readFileSync(contentFile, 'utf8')); + // Kill the child process once the file has data + syncProc.stdin.end(); + // Remove the temporary file + fs.unlinkSync(contentFile); - if (this._complete) - this.body = (consumed < chunk.length) - ? chunk.slice(consumed) - : Buffer.alloc(0); -}; + if (resp.err) { + self.handleError(resp.err); + } else { + response = resp.data; + self.status = resp.data.statusCode; + self.responseText = resp.data.text; + setState(self.DONE); + } + } + }; -module.exports = HttpParser; + /** + * Called when an error is encountered to deal with it. + */ + this.handleError = function(error) { + this.status = 0; + this.statusText = error; + this.responseText = error.stack; + errorFlag = true; + setState(this.DONE); + this.dispatchEvent('error'); + }; + /** + * Aborts a request. + */ + this.abort = function() { + if (request) { + request.abort(); + request = null; + } -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { + headers = defaultHeaders; + this.status = 0; + this.responseText = ""; + this.responseXML = ""; -var Stream = __webpack_require__(7).Stream, - util = __webpack_require__(0), - driver = __webpack_require__(6), - EventTarget = __webpack_require__(17), - Event = __webpack_require__(9); + errorFlag = true; -var API = function(options) { - options = options || {}; - driver.validateOptions(options, ['headers', 'extensions', 'maxLength', 'ping', 'proxy', 'tls', 'ca']); + if (this.readyState !== this.UNSENT + && (this.readyState !== this.OPENED || sendFlag) + && this.readyState !== this.DONE) { + sendFlag = false; + setState(this.DONE); + } + this.readyState = this.UNSENT; + this.dispatchEvent('abort'); + }; - this.readable = this.writable = true; + /** + * Adds an event listener. Preferred method of binding to events. + */ + this.addEventListener = function(event, callback) { + if (!(event in listeners)) { + listeners[event] = []; + } + // Currently allows duplicate callbacks. Should it? + listeners[event].push(callback); + }; - var headers = options.headers; - if (headers) { - for (var name in headers) this._driver.setHeader(name, headers[name]); - } + /** + * Remove an event callback that has already been bound. + * Only works on the matching funciton, cannot be a copy. + */ + this.removeEventListener = function(event, callback) { + if (event in listeners) { + // Filter will return a new array with the callback removed + listeners[event] = listeners[event].filter(function(ev) { + return ev !== callback; + }); + } + }; - var extensions = options.extensions; - if (extensions) { - [].concat(extensions).forEach(this._driver.addExtension, this._driver); - } + /** + * Dispatch any events, including both "on" methods and events attached using addEventListener. + */ + this.dispatchEvent = function(event) { + if (typeof self["on" + event] === "function") { + self["on" + event](); + } + if (event in listeners) { + for (var i = 0, len = listeners[event].length; i < len; i++) { + listeners[event][i].call(self); + } + } + }; - this._ping = options.ping; - this._pingId = 0; - this.readyState = API.CONNECTING; - this.bufferedAmount = 0; - this.protocol = ''; - this.url = this._driver.url; - this.version = this._driver.version; + /** + * Changes readyState and calls onreadystatechange. + * + * @param int state New state + */ + var setState = function(state) { + if (state == self.LOADING || self.readyState !== state) { + self.readyState = state; - var self = this; + if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { + self.dispatchEvent("readystatechange"); + } - this._driver.on('open', function(e) { self._open() }); - this._driver.on('message', function(e) { self._receiveMessage(e.data) }); - this._driver.on('close', function(e) { self._beginClose(e.reason, e.code) }); + if (self.readyState === self.DONE && !errorFlag) { + self.dispatchEvent("load"); + // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie) + self.dispatchEvent("loadend"); + } + } + }; +}; - this._driver.on('error', function(error) { - self._emitError(error.message); - }); - this.on('error', function() {}); - this._driver.messages.on('drain', function() { - self.emit('drain'); - }); +/***/ }), +/* 20 */ +/***/ (function(module, exports, __webpack_require__) { - if (this._ping) - this._pingTimer = setInterval(function() { - self._pingId += 1; - self.ping(self._pingId.toString()); - }, this._ping * 1000); +(function(nacl) { +'use strict'; - this._configureStream(); +// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +// +// Implementation derived from TweetNaCl version 20140427. +// See for details: http://tweetnacl.cr.yp.to/ - if (!this._proxy) { - this._stream.pipe(this._driver.io); - this._driver.io.pipe(this._stream); - } +var gf = function(init) { + var i, r = new Float64Array(16); + if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; + return r; }; -util.inherits(API, Stream); - -API.CONNECTING = 0; -API.OPEN = 1; -API.CLOSING = 2; -API.CLOSED = 3; -var instance = { - write: function(data) { - return this.send(data); - }, +// Pluggable, initialized in high-level API below. +var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; - end: function(data) { - if (data !== undefined) this.send(data); - this.close(); - }, +var _0 = new Uint8Array(16); +var _9 = new Uint8Array(32); _9[0] = 9; - pause: function() { - return this._driver.messages.pause(); - }, +var gf0 = gf(), + gf1 = gf([1]), + _121665 = gf([0xdb41, 1]), + D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), + D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), + X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), + Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), + I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); - resume: function() { - return this._driver.messages.resume(); - }, +function ts64(x, i, h, l) { + x[i] = (h >> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; +} - send: function(data) { - if (this.readyState > API.OPEN) return false; - if (!(data instanceof Buffer)) data = String(data); - return this._driver.messages.write(data); - }, +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; +} - ping: function(message, callback) { - if (this.readyState > API.OPEN) return false; - return this._driver.ping(message, callback); - }, +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); +} - close: function() { - if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING; - this._driver.close(); - }, +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); +} - _configureStream: function() { - var self = this; +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - this._stream.setTimeout(0); - this._stream.setNoDelay(true); + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; - ['close', 'end'].forEach(function(event) { - this._stream.on(event, function() { self._finalizeClose() }); - }, this); + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); - this._stream.on('error', function(error) { - self._emitError('Network error: ' + self.url + ': ' + error.message); - self._finalizeClose(); - }); - }, + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); - _open: function() { - if (this.readyState !== API.CONNECTING) return; + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); - this.readyState = API.OPEN; - this.protocol = this._driver.protocol || ''; + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); - var event = new Event('open'); - event.initEvent('open', false, false); - this.dispatchEvent(event); - }, + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); - _receiveMessage: function(data) { - if (this.readyState > API.OPEN) return false; + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); - if (this.readable) this.emit('data', data); + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); - var event = new Event('message', {data: data}); - event.initEvent('message', false, false); - this.dispatchEvent(event); - }, + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; - _emitError: function(message) { - if (this.readyState >= API.CLOSING) return; + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; - var event = new Event('error', {message: message}); - event.initEvent('error', false, false); - this.dispatchEvent(event); - }, + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; - _beginClose: function(reason, code) { - if (this.readyState === API.CLOSED) return; - this.readyState = API.CLOSING; + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; - if (this._stream) { - this._stream.end(); - if (!this._stream.readable) this._finalizeClose(); - } - this._closeParams = [reason, code]; - }, + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; - _finalizeClose: function() { - if (this.readyState === API.CLOSED) return; - this.readyState = API.CLOSED; + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; - if (this._pingTimer) clearInterval(this._pingTimer); - if (this._stream) this._stream.end(); + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; - if (this.readable) this.emit('end'); - this.readable = this.writable = false; + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; - var reason = this._closeParams ? this._closeParams[0] : '', - code = this._closeParams ? this._closeParams[1] : 1006; + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; - var event = new Event('close', {code: code, reason: reason}); - event.initEvent('close', false, false); - this.dispatchEvent(event); - } -}; + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; -for (var method in instance) API.prototype[method] = instance[method]; -for (var key in EventTarget) API.prototype[key] = EventTarget[key]; + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; -module.exports = API; + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; -/***/ }), -/* 13 */ -/***/ (function(module, exports, __webpack_require__) { + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; -"use strict"; + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; -var Buffer = __webpack_require__(1).Buffer, - crypto = __webpack_require__(5), - util = __webpack_require__(0), - Extensions = __webpack_require__(28), - Base = __webpack_require__(2), - Frame = __webpack_require__(33), - Message = __webpack_require__(34); + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} -var Hybi = function(request, url, options) { - Base.apply(this, arguments); +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - this._extensions = new Extensions(); - this._stage = 0; - this._masking = this._options.masking; - this._protocols = this._options.protocols || []; - this._requireMasking = this._options.requireMasking; - this._pingCallbacks = {}; + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; - if (typeof this._protocols === 'string') - this._protocols = this._protocols.split(/ *, */); + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); - if (!this._request) return; + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); - var protos = this._request.headers['sec-websocket-protocol'], - supported = this._protocols; + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); - if (protos !== undefined) { - if (typeof protos === 'string') protos = protos.split(/ *, */); - this.protocol = protos.filter(function(p) { return supported.indexOf(p) >= 0 })[0]; - } + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); - this.version = 'hybi-' + Hybi.VERSION; -}; -util.inherits(Hybi, Base); + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); -Hybi.VERSION = '13'; + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); -Hybi.mask = function(payload, mask, offset) { - if (!mask || mask.length === 0) return payload; - offset = offset || 0; + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); - for (var i = 0, n = payload.length - offset; i < n; i++) { - payload[offset + i] = payload[offset + i] ^ mask[i % 4]; + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); } - return payload; -}; -Hybi.generateAccept = function(key) { - var sha1 = crypto.createHash('sha1'); - sha1.update(key + Hybi.GUID); - return sha1.digest('base64'); -}; - -Hybi.GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; - -var instance = { - FIN: 0x80, - MASK: 0x80, - RSV1: 0x40, - RSV2: 0x20, - RSV3: 0x10, - OPCODE: 0x0F, - LENGTH: 0x7F, - - OPCODES: { - continuation: 0, - text: 1, - binary: 2, - close: 8, - ping: 9, - pong: 10 - }, + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; - OPCODE_CODES: [0, 1, 2, 8, 9, 10], - MESSAGE_OPCODES: [0, 1, 2], - OPENING_OPCODES: [1, 2], + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; - ERRORS: { - normal_closure: 1000, - going_away: 1001, - protocol_error: 1002, - unacceptable: 1003, - encoding_error: 1007, - policy_violation: 1008, - too_large: 1009, - extension_error: 1010, - unexpected_condition: 1011 - }, + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; - ERROR_CODES: [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011], - DEFAULT_ERROR_CODE: 1000, - MIN_RESERVED_ERROR: 3000, - MAX_RESERVED_ERROR: 4999, + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; - // http://www.w3.org/International/questions/qa-forms-utf-8.en.php - UTF8_MATCH: /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/, + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; - addExtension: function(extension) { - this._extensions.add(extension); - return true; - }, + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; - parse: function(chunk) { - this._reader.put(chunk); - var buffer = true; - while (buffer) { - switch (this._stage) { - case 0: - buffer = this._reader.read(1); - if (buffer) this._parseOpcode(buffer[0]); - break; + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; - case 1: - buffer = this._reader.read(1); - if (buffer) this._parseLength(buffer[0]); - break; + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} - case 2: - buffer = this._reader.read(this._frame.lengthBytes); - if (buffer) this._parseExtendedLength(buffer); - break; +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} - case 3: - buffer = this._reader.read(4); - if (buffer) { - this._stage = 4; - this._frame.maskingKey = buffer; - } - break; +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} - case 4: - buffer = this._reader.read(this._frame.length); - if (buffer) { - this._stage = 0; - this._emitFrame(buffer); - } - break; +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" - default: - buffer = null; - } +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; } - }, - - text: function(message) { - if (this.readyState > 1) return false; - return this.frame(message, 'text'); - }, - - binary: function(message) { - if (this.readyState > 1) return false; - return this.frame(message, 'binary'); - }, + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; +} - ping: function(message, callback) { - if (this.readyState > 1) return false; - message = message || ''; - if (callback) this._pingCallbacks[message] = callback; - return this.frame(message, 'ping'); - }, +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} - pong: function(message) { - if (this.readyState > 1) return false; - message = message ||''; - return this.frame(message, 'pong'); - }, +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); +} - close: function(reason, code) { - reason = reason || ''; - code = code || this.ERRORS.normal_closure; +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +} - if (this.readyState <= 0) { - this.readyState = 3; - this.emit('close', new Base.CloseEvent(code, reason)); - return true; - } else if (this.readyState === 1) { - this.readyState = 2; - this._extensions.close(function() { this.frame(reason, 'close', code) }, this); - return true; - } else { - return false; - } - }, +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ - frame: function(buffer, type, code) { - if (this.readyState <= 0) return this._queue([buffer, type, code]); - if (this.readyState > 2) return false; +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; - if (buffer instanceof Array) buffer = Buffer.from(buffer); - if (typeof buffer === 'number') buffer = buffer.toString(); + var t0, t1, t2, t3, t4, t5, t6, t7; - var message = new Message(), - isText = (typeof buffer === 'string'), - payload, copy; + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; - message.rsv1 = message.rsv2 = message.rsv3 = false; - message.opcode = this.OPCODES[type || (isText ? 'text' : 'binary')]; + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; +}; - payload = isText ? Buffer.from(buffer, 'utf8') : buffer; +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - if (code) { - copy = payload; - payload = Buffer.allocUnsafe(2 + copy.length); - payload.writeUInt16BE(code, 0); - copy.copy(payload, 2); - } - message.data = payload; + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; - var onMessageReady = function(message) { - var frame = new Frame(); + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; - frame.final = true; - frame.rsv1 = message.rsv1; - frame.rsv2 = message.rsv2; - frame.rsv3 = message.rsv3; - frame.opcode = message.opcode; - frame.masked = !!this._masking; - frame.length = message.data.length; - frame.payload = message.data; + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; - if (frame.masked) frame.maskingKey = crypto.randomBytes(4); + c = 0; - this._sendFrame(frame); - }; + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; - if (this.MESSAGE_OPCODES.indexOf(message.opcode) >= 0) - this._extensions.processOutgoingMessage(message, function(error, message) { - if (error) return this._fail('extension_error', error.message); - onMessageReady.call(this, message); - }, this); - else - onMessageReady.call(this, message); + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; - return true; - }, + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; - _sendFrame: function(frame) { - var length = frame.length, - header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10), - offset = header + (frame.masked ? 4 : 0), - buffer = Buffer.allocUnsafe(offset + length), - masked = frame.masked ? this.MASK : 0; + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; - buffer[0] = (frame.final ? this.FIN : 0) | - (frame.rsv1 ? this.RSV1 : 0) | - (frame.rsv2 ? this.RSV2 : 0) | - (frame.rsv3 ? this.RSV3 : 0) | - frame.opcode; + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; - if (length <= 125) { - buffer[1] = masked | length; - } else if (length <= 65535) { - buffer[1] = masked | 126; - buffer.writeUInt16BE(length, 2); - } else { - buffer[1] = masked | 127; - buffer.writeUInt32BE(Math.floor(length / 0x100000000), 2); - buffer.writeUInt32BE(length % 0x100000000, 6); - } + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; - frame.payload.copy(buffer, offset); + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; - if (frame.masked) { - frame.maskingKey.copy(buffer, header); - Hybi.mask(buffer, frame.maskingKey, offset); - } + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; + + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; + + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; - this._write(buffer); - }, + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; - _handshakeResponse: function() { - var secKey = this._request.headers['sec-websocket-key'], - version = this._request.headers['sec-websocket-version']; + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; - if (version !== Hybi.VERSION) - throw new Error('Unsupported WebSocket version: ' + version); + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; +}; - if (typeof secKey !== 'string') - throw new Error('Missing handshake request header: Sec-WebSocket-Key'); +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; - this._headers.set('Upgrade', 'websocket'); - this._headers.set('Connection', 'Upgrade'); - this._headers.set('Sec-WebSocket-Accept', Hybi.generateAccept(secKey)); + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } - if (this.protocol) this._headers.set('Sec-WebSocket-Protocol', this.protocol); + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; + } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; - var extensions = this._extensions.generateResponse(this._request.headers['sec-websocket-extensions']); - if (extensions) this._headers.set('Sec-WebSocket-Extensions', extensions); + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; + } + g[9] -= (1 << 13); - var start = 'HTTP/1.1 101 Switching Protocols', - headers = [start, this._headers.toString(), '']; + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - return Buffer.from(headers.join('\r\n'), 'utf8'); - }, + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - _shutdown: function(code, reason, error) { - delete this._frame; - delete this._message; - this._stage = 5; + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } - var sendCloseFrame = (this.readyState === 1); - this.readyState = 2; + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +}; - this._extensions.close(function() { - if (sendCloseFrame) this.frame(reason, 'close', code); - this.readyState = 3; - if (error) this.emit('error', new Error(reason)); - this.emit('close', new Base.CloseEvent(code, reason)); - }, this); - }, +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; - _fail: function(type, message) { - if (this.readyState > 1) return; - this._shutdown(this.ERRORS[type], message, true); - }, + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } - _parseOpcode: function(octet) { - var rsvs = [this.RSV1, this.RSV2, this.RSV3].map(function(rsv) { - return (octet & rsv) === rsv; - }); + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } - var frame = this._frame = new Frame(); + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; + } +}; - frame.final = (octet & this.FIN) === this.FIN; - frame.rsv1 = rsvs[0]; - frame.rsv2 = rsvs[1]; - frame.rsv3 = rsvs[2]; - frame.opcode = (octet & this.OPCODE); +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} - this._stage = 1; +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} - if (!this._extensions.validFrameRsv(frame)) - return this._fail('protocol_error', - 'One or more reserved bits are on: reserved1 = ' + (frame.rsv1 ? 1 : 0) + - ', reserved2 = ' + (frame.rsv2 ? 1 : 0) + - ', reserved3 = ' + (frame.rsv3 ? 1 : 0)); +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} - if (this.OPCODE_CODES.indexOf(frame.opcode) < 0) - return this._fail('protocol_error', 'Unrecognized frame opcode: ' + frame.opcode); +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} - if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && !frame.final) - return this._fail('protocol_error', 'Received fragmented control frame: opcode = ' + frame.opcode); +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} - if (this._message && this.OPENING_OPCODES.indexOf(frame.opcode) >= 0) - return this._fail('protocol_error', 'Received new data frame but previous continuous frame is unfinished'); - }, +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} - _parseLength: function(octet) { - var frame = this._frame; - frame.masked = (octet & this.MASK) === this.MASK; - frame.length = (octet & this.LENGTH); +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} - if (frame.length >= 0 && frame.length <= 125) { - this._stage = frame.masked ? 3 : 4; - if (!this._checkFrameLength()) return; - } else { - this._stage = 2; - frame.lengthBytes = (frame.length === 126 ? 2 : 8); +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; } + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} - if (this._requireMasking && !frame.masked) - return this._fail('unacceptable', 'Received unmasked frame but masking is required'); - }, - - _parseExtendedLength: function(buffer) { - var frame = this._frame; - frame.length = this._readUInt(buffer); +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} - this._stage = frame.masked ? 3 : 4; +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} - if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && frame.length > 125) - return this._fail('protocol_error', 'Received control frame having too long payload: ' + frame.length); +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} - if (!this._checkFrameLength()) return; - }, +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +} - _checkFrameLength: function() { - var length = this._message ? this._message.length : 0; +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} - if (length + this._frame.length > this._maxLength) { - this._fail('too_large', 'WebSocket frame length too large'); - return false; - } else { - return true; - } - }, +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; - _emitFrame: function(buffer) { - var frame = this._frame, - payload = frame.payload = Hybi.mask(buffer, frame.maskingKey), - opcode = frame.opcode, - message, - code, reason, - callbacks, callback; + v = a[0]; + t0 += v * b0; + t1 += v * b1; + t2 += v * b2; + t3 += v * b3; + t4 += v * b4; + t5 += v * b5; + t6 += v * b6; + t7 += v * b7; + t8 += v * b8; + t9 += v * b9; + t10 += v * b10; + t11 += v * b11; + t12 += v * b12; + t13 += v * b13; + t14 += v * b14; + t15 += v * b15; + v = a[1]; + t1 += v * b0; + t2 += v * b1; + t3 += v * b2; + t4 += v * b3; + t5 += v * b4; + t6 += v * b5; + t7 += v * b6; + t8 += v * b7; + t9 += v * b8; + t10 += v * b9; + t11 += v * b10; + t12 += v * b11; + t13 += v * b12; + t14 += v * b13; + t15 += v * b14; + t16 += v * b15; + v = a[2]; + t2 += v * b0; + t3 += v * b1; + t4 += v * b2; + t5 += v * b3; + t6 += v * b4; + t7 += v * b5; + t8 += v * b6; + t9 += v * b7; + t10 += v * b8; + t11 += v * b9; + t12 += v * b10; + t13 += v * b11; + t14 += v * b12; + t15 += v * b13; + t16 += v * b14; + t17 += v * b15; + v = a[3]; + t3 += v * b0; + t4 += v * b1; + t5 += v * b2; + t6 += v * b3; + t7 += v * b4; + t8 += v * b5; + t9 += v * b6; + t10 += v * b7; + t11 += v * b8; + t12 += v * b9; + t13 += v * b10; + t14 += v * b11; + t15 += v * b12; + t16 += v * b13; + t17 += v * b14; + t18 += v * b15; + v = a[4]; + t4 += v * b0; + t5 += v * b1; + t6 += v * b2; + t7 += v * b3; + t8 += v * b4; + t9 += v * b5; + t10 += v * b6; + t11 += v * b7; + t12 += v * b8; + t13 += v * b9; + t14 += v * b10; + t15 += v * b11; + t16 += v * b12; + t17 += v * b13; + t18 += v * b14; + t19 += v * b15; + v = a[5]; + t5 += v * b0; + t6 += v * b1; + t7 += v * b2; + t8 += v * b3; + t9 += v * b4; + t10 += v * b5; + t11 += v * b6; + t12 += v * b7; + t13 += v * b8; + t14 += v * b9; + t15 += v * b10; + t16 += v * b11; + t17 += v * b12; + t18 += v * b13; + t19 += v * b14; + t20 += v * b15; + v = a[6]; + t6 += v * b0; + t7 += v * b1; + t8 += v * b2; + t9 += v * b3; + t10 += v * b4; + t11 += v * b5; + t12 += v * b6; + t13 += v * b7; + t14 += v * b8; + t15 += v * b9; + t16 += v * b10; + t17 += v * b11; + t18 += v * b12; + t19 += v * b13; + t20 += v * b14; + t21 += v * b15; + v = a[7]; + t7 += v * b0; + t8 += v * b1; + t9 += v * b2; + t10 += v * b3; + t11 += v * b4; + t12 += v * b5; + t13 += v * b6; + t14 += v * b7; + t15 += v * b8; + t16 += v * b9; + t17 += v * b10; + t18 += v * b11; + t19 += v * b12; + t20 += v * b13; + t21 += v * b14; + t22 += v * b15; + v = a[8]; + t8 += v * b0; + t9 += v * b1; + t10 += v * b2; + t11 += v * b3; + t12 += v * b4; + t13 += v * b5; + t14 += v * b6; + t15 += v * b7; + t16 += v * b8; + t17 += v * b9; + t18 += v * b10; + t19 += v * b11; + t20 += v * b12; + t21 += v * b13; + t22 += v * b14; + t23 += v * b15; + v = a[9]; + t9 += v * b0; + t10 += v * b1; + t11 += v * b2; + t12 += v * b3; + t13 += v * b4; + t14 += v * b5; + t15 += v * b6; + t16 += v * b7; + t17 += v * b8; + t18 += v * b9; + t19 += v * b10; + t20 += v * b11; + t21 += v * b12; + t22 += v * b13; + t23 += v * b14; + t24 += v * b15; + v = a[10]; + t10 += v * b0; + t11 += v * b1; + t12 += v * b2; + t13 += v * b3; + t14 += v * b4; + t15 += v * b5; + t16 += v * b6; + t17 += v * b7; + t18 += v * b8; + t19 += v * b9; + t20 += v * b10; + t21 += v * b11; + t22 += v * b12; + t23 += v * b13; + t24 += v * b14; + t25 += v * b15; + v = a[11]; + t11 += v * b0; + t12 += v * b1; + t13 += v * b2; + t14 += v * b3; + t15 += v * b4; + t16 += v * b5; + t17 += v * b6; + t18 += v * b7; + t19 += v * b8; + t20 += v * b9; + t21 += v * b10; + t22 += v * b11; + t23 += v * b12; + t24 += v * b13; + t25 += v * b14; + t26 += v * b15; + v = a[12]; + t12 += v * b0; + t13 += v * b1; + t14 += v * b2; + t15 += v * b3; + t16 += v * b4; + t17 += v * b5; + t18 += v * b6; + t19 += v * b7; + t20 += v * b8; + t21 += v * b9; + t22 += v * b10; + t23 += v * b11; + t24 += v * b12; + t25 += v * b13; + t26 += v * b14; + t27 += v * b15; + v = a[13]; + t13 += v * b0; + t14 += v * b1; + t15 += v * b2; + t16 += v * b3; + t17 += v * b4; + t18 += v * b5; + t19 += v * b6; + t20 += v * b7; + t21 += v * b8; + t22 += v * b9; + t23 += v * b10; + t24 += v * b11; + t25 += v * b12; + t26 += v * b13; + t27 += v * b14; + t28 += v * b15; + v = a[14]; + t14 += v * b0; + t15 += v * b1; + t16 += v * b2; + t17 += v * b3; + t18 += v * b4; + t19 += v * b5; + t20 += v * b6; + t21 += v * b7; + t22 += v * b8; + t23 += v * b9; + t24 += v * b10; + t25 += v * b11; + t26 += v * b12; + t27 += v * b13; + t28 += v * b14; + t29 += v * b15; + v = a[15]; + t15 += v * b0; + t16 += v * b1; + t17 += v * b2; + t18 += v * b3; + t19 += v * b4; + t20 += v * b5; + t21 += v * b6; + t22 += v * b7; + t23 += v * b8; + t24 += v * b9; + t25 += v * b10; + t26 += v * b11; + t27 += v * b12; + t28 += v * b13; + t29 += v * b14; + t30 += v * b15; - delete this._frame; + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is - if (opcode === this.OPCODES.continuation) { - if (!this._message) return this._fail('protocol_error', 'Received unexpected continuation frame'); - this._message.pushFrame(frame); - } + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); - if (opcode === this.OPCODES.text || opcode === this.OPCODES.binary) { - this._message = new Message(); - this._message.pushFrame(frame); - } + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); - if (frame.final && this.MESSAGE_OPCODES.indexOf(opcode) >= 0) - return this._emitMessage(this._message); + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} - if (opcode === this.OPCODES.close) { - code = (payload.length >= 2) ? payload.readUInt16BE(0) : null; - reason = (payload.length > 2) ? this._encode(payload.slice(2)) : null; +function S(o, a) { + M(o, a, a); +} - if (!(payload.length === 0) && - !(code !== null && code >= this.MIN_RESERVED_ERROR && code <= this.MAX_RESERVED_ERROR) && - this.ERROR_CODES.indexOf(code) < 0) - code = this.ERRORS.protocol_error; +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} - if (payload.length > 125 || (payload.length > 2 && !reason)) - code = this.ERRORS.protocol_error; +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} - this._shutdown(code || this.DEFAULT_ERROR_CODE, reason || ''); - } +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; +} - if (opcode === this.OPCODES.ping) { - this.frame(payload, 'pong'); - this.emit('ping', new Base.PingEvent(payload.toString())) - } +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); +} - if (opcode === this.OPCODES.pong) { - callbacks = this._pingCallbacks; - message = this._encode(payload); - callback = callbacks[message]; +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); +} - delete callbacks[message]; - if (callback) callback() +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); +} - this.emit('pong', new Base.PongEvent(payload.toString())) - } - }, +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; - _emitMessage: function(message) { - var message = this._message; - message.read(); +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); +} - delete this._message; +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} - this._extensions.processIncomingMessage(message, function(error, message) { - if (error) return this._fail('extension_error', error.message); +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; - var payload = message.data; - if (message.opcode === this.OPCODES.text) payload = this._encode(payload); +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; - if (payload === null) - return this._fail('encoding_error', 'Could not decode a text frame as UTF-8'); - else - this.emit('message', new Base.MessageEvent(payload)); - }, this); - }, + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], - _encode: function(buffer) { - try { - var string = buffer.toString('binary', 0, buffer.length); - if (!this.UTF8_MATCH.test(string)) return null; - } catch (e) {} - return buffer.toString('utf8', 0, buffer.length); - }, + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; - _readUInt: function(buffer) { - if (buffer.length === 2) return buffer.readUInt16BE(0); + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; - return buffer.readUInt32BE(0) * 0x100000000 + - buffer.readUInt32BE(4); - } -}; + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; -for (var key in instance) - Hybi.prototype[key] = instance[key]; + // add + h = ah7; + l = al7; -module.exports = Hybi; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); -/***/ }), -/* 14 */ -/***/ (function(module, exports, __webpack_require__) { + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -"use strict"; + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -var RingBuffer = function(bufferSize) { - this._bufferSize = bufferSize; - this.clear(); -}; + // K + h = K[i*2]; + l = K[i*2+1]; -RingBuffer.prototype.clear = function() { - this._buffer = new Array(this._bufferSize); - this._ringOffset = 0; - this._ringSize = this._bufferSize; - this._head = 0; - this._tail = 0; - this.length = 0; -}; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -RingBuffer.prototype.push = function(value) { - var expandBuffer = false, - expandRing = false; + // w + h = wh[i%16]; + l = wl[i%16]; - if (this._ringSize < this._bufferSize) { - expandBuffer = (this._tail === 0); - } else if (this._ringOffset === this._ringSize) { - expandBuffer = true; - expandRing = (this._tail === 0); - } + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - if (expandBuffer) { - this._tail = this._bufferSize; - this._buffer = this._buffer.concat(new Array(this._bufferSize)); - this._bufferSize = this._buffer.length; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - if (expandRing) - this._ringSize = this._bufferSize; - } + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; - this._buffer[this._tail] = value; - this.length += 1; - if (this._tail < this._ringSize) this._ringOffset += 1; - this._tail = (this._tail + 1) % this._bufferSize; -}; + // add + h = th; + l = tl; -RingBuffer.prototype.peek = function() { - if (this.length === 0) return void 0; - return this._buffer[this._head]; -}; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -RingBuffer.prototype.shift = function() { - if (this.length === 0) return void 0; + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); - var value = this._buffer[this._head]; - this._buffer[this._head] = void 0; - this.length -= 1; - this._ringOffset -= 1; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - if (this._ringOffset === 0 && this.length > 0) { - this._head = this._ringSize; - this._ringOffset = this.length; - this._ringSize = this._bufferSize; - } else { - this._head = (this._head + 1) % this._ringSize; - } - return value; -}; + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); -module.exports = RingBuffer; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -/***/ }), -/* 15 */ -/***/ (function(module, exports, __webpack_require__) { + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); -"use strict"; + // add + h = bh3; + l = bl3; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -var RingBuffer = __webpack_require__(14); + h = th; + l = tl; -var Pledge = function() { - this._complete = false; - this._callbacks = new RingBuffer(Pledge.QUEUE_SIZE); -}; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -Pledge.QUEUE_SIZE = 4; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -Pledge.all = function(list) { - var pledge = new Pledge(), - pending = list.length, - n = pending; + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); - if (pending === 0) pledge.done(); + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; - while (n--) list[n].then(function() { - pending -= 1; - if (pending === 0) pledge.done(); - }); - return pledge; -}; + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; -Pledge.prototype.then = function(callback) { - if (this._complete) callback(); - else this._callbacks.push(callback); -}; + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; -Pledge.prototype.done = function() { - this._complete = true; - var callbacks = this._callbacks, callback; - while (callback = callbacks.shift()) callback(); -}; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -module.exports = Pledge; + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -/***/ }), -/* 16 */ -/***/ (function(module, exports, __webpack_require__) { + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); -"use strict"; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); -var Buffer = __webpack_require__(1).Buffer, - Base = __webpack_require__(2), - util = __webpack_require__(0); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -var Draft75 = function(request, url, options) { - Base.apply(this, arguments); - this._stage = 0; - this.version = 'hixie-75'; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - this._headers.set('Upgrade', 'WebSocket'); - this._headers.set('Connection', 'Upgrade'); - this._headers.set('WebSocket-Origin', this._request.headers.origin); - this._headers.set('WebSocket-Location', this.url); -}; -util.inherits(Draft75, Base); + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } -var instance = { - close: function() { - if (this.readyState === 3) return false; - this.readyState = 3; - this.emit('close', new Base.CloseEvent(null, null)); - return true; - }, + // add + h = ah0; + l = al0; - parse: function(chunk) { - if (this.readyState > 1) return; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - this._reader.put(chunk); + h = hh[0]; + l = hl[0]; - this._reader.eachByte(function(octet) { - var message; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - switch (this._stage) { - case -1: - this._body.push(octet); - this._sendHandshakeBody(); - break; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - case 0: - this._parseLeadingByte(octet); - break; + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); - case 1: - this._length = (octet & 0x7F) + 128 * this._length; + h = ah1; + l = al1; - if (this._closing && this._length === 0) { - return this.close(); - } - else if ((octet & 0x80) !== 0x80) { - if (this._length === 0) { - this._stage = 0; - } - else { - this._skipped = 0; - this._stage = 2; - } - } - break; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - case 2: - if (octet === 0xFF) { - this._stage = 0; - message = Buffer.from(this._buffer).toString('utf8', 0, this._buffer.length); - this.emit('message', new Base.MessageEvent(message)); - } - else { - if (this._length) { - this._skipped += 1; - if (this._skipped === this._length) - this._stage = 0; - } else { - this._buffer.push(octet); - if (this._buffer.length > this._maxLength) return this.close(); - } - } - break; - } - }, this); - }, + h = hh[1]; + l = hl[1]; - frame: function(buffer) { - if (this.readyState === 0) return this._queue([buffer]); - if (this.readyState > 1) return false; + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - if (typeof buffer !== 'string') buffer = buffer.toString(); + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - var length = Buffer.byteLength(buffer), - frame = Buffer.allocUnsafe(length + 2); + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); - frame[0] = 0x00; - frame.write(buffer, 1); - frame[frame.length - 1] = 0xFF; + h = ah2; + l = al2; - this._write(frame); - return true; - }, + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - _handshakeResponse: function() { - var start = 'HTTP/1.1 101 Web Socket Protocol Handshake', - headers = [start, this._headers.toString(), '']; + h = hh[2]; + l = hl[2]; - return Buffer.from(headers.join('\r\n'), 'utf8'); - }, + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - _parseLeadingByte: function(octet) { - if ((octet & 0x80) === 0x80) { - this._length = 0; - this._stage = 1; - } else { - delete this._length; - delete this._skipped; - this._buffer = []; - this._stage = 2; - } - } -}; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); -for (var key in instance) - Draft75.prototype[key] = instance[key]; + h = ah3; + l = al3; -module.exports = Draft75; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + h = hh[3]; + l = hl[3]; -/***/ }), -/* 17 */ -/***/ (function(module, exports, __webpack_require__) { + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -var Event = __webpack_require__(9); + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -var EventTarget = { - onopen: null, - onmessage: null, - onerror: null, - onclose: null, + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); - addEventListener: function(eventType, listener, useCapture) { - this.on(eventType, listener); - }, + h = ah4; + l = al4; - removeEventListener: function(eventType, listener, useCapture) { - this.removeListener(eventType, listener); - }, + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - dispatchEvent: function(event) { - event.target = event.currentTarget = this; - event.eventPhase = Event.AT_TARGET; + h = hh[4]; + l = hl[4]; - if (this['on' + event.type]) - this['on' + event.type](event); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; - this.emit(event.type, event); - } -}; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -module.exports = EventTarget; + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); + h = ah5; + l = al5; -/***/ }), -/* 18 */ -/***/ (function(module, exports, __webpack_require__) { + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; -// API references: -// -// * http://dev.w3.org/html5/websockets/ -// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-eventtarget -// * http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#interface-event + h = hh[5]; + l = hl[5]; -var util = __webpack_require__(0), - driver = __webpack_require__(6), - API = __webpack_require__(12); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -var WebSocket = function(request, socket, body, protocols, options) { - options = options || {}; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; - this._stream = socket; - this._driver = driver.http(request, {maxLength: options.maxLength, protocols: protocols}); + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); - var self = this; - if (!this._stream || !this._stream.writable) return; - if (!this._stream.readable) return this._stream.end(); + h = ah6; + l = al6; - var catchup = function() { self._stream.removeListener('data', catchup) }; - this._stream.on('data', catchup); + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; - API.call(this, options); + h = hh[6]; + l = hl[6]; - process.nextTick(function() { - self._driver.start(); - self._driver.io.write(body); - }); -}; -util.inherits(WebSocket, API); + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -WebSocket.isWebSocket = function(request) { - return driver.isWebSocket(request); -}; + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -WebSocket.validateOptions = function(options, validKeys) { - driver.validateOptions(options, validKeys); -}; + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); -WebSocket.WebSocket = WebSocket; -WebSocket.Client = __webpack_require__(38); -WebSocket.EventSource = __webpack_require__(41); + h = ah7; + l = al7; -module.exports = WebSocket; + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + h = hh[7]; + l = hl[7]; -/***/ }), -/* 19 */ -/***/ (function(module, exports, __webpack_require__) { + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; -/** - * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object. - * - * This can be used with JS designed for browsers to improve reuse of code and - * allow the use of existing libraries. - * - * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs. - * - * @author Dan DeFelippi - * @contributor David Ellis - * @license MIT - */ + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; -var Url = __webpack_require__(8); -var spawn = __webpack_require__(42).spawn; -var fs = __webpack_require__(43); + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); -exports.XMLHttpRequest = function() { - "use strict"; + pos += 128; + n -= 128; + } - /** - * Private variables - */ - var self = this; - var http = __webpack_require__(44); - var https = __webpack_require__(45); + return n; +} - // Holds http.js objects - var request; - var response; +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; - // Request settings - var settings = {}; + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; - // Disable header blacklist. - // Not part of XHR specs. - var disableHeaderCheck = false; + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; - // Set some default headers - var defaultHeaders = { - "User-Agent": "node-XMLHttpRequest", - "Accept": "*/*", - }; + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; - var headers = {}; - var headersCase = {}; + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; - // These headers are not user setable. - // The following are allowed but banned in the spec: - // * user-agent - var forbiddenRequestHeaders = [ - "accept-charset", - "accept-encoding", - "access-control-request-headers", - "access-control-request-method", - "connection", - "content-length", - "content-transfer-encoding", - "cookie", - "cookie2", - "date", - "expect", - "host", - "keep-alive", - "origin", - "referer", - "te", - "trailer", - "transfer-encoding", - "upgrade", - "via" - ]; + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); - // These request methods are not allowed - var forbiddenRequestMethods = [ - "TRACE", - "TRACK", - "CONNECT" - ]; + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); - // Send flag - var sendFlag = false; - // Error flag, used when errors occur or abort is called - var errorFlag = false; + return 0; +} + +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); + + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); +} - // Event listeners - var listeners = {}; +function cswap(p, q, b) { + var i; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); + } +} - /** - * Constants - */ +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; +} - this.UNSENT = 0; - this.OPENED = 1; - this.HEADERS_RECEIVED = 2; - this.LOADING = 3; - this.DONE = 4; +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); + } +} - /** - * Public vars - */ +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); +} - // Current state - this.readyState = this.UNSENT; +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; - // default ready state change handler in case one is not set or is set late - this.onreadystatechange = null; + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; - // Result & response - this.responseText = ""; - this.responseXML = ""; - this.status = null; - this.statusText = null; - - // Whether cross-site Access-Control requests should be made using - // credentials such as cookies or authorization headers - this.withCredentials = false; + scalarbase(p, d); + pack(pk, p); - /** - * Private methods - */ + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; +} - /** - * Check if the specified header is allowed. - * - * @param string header Header to validate - * @return boolean False if not allowed, otherwise true - */ - var isAllowedHttpHeader = function(header) { - return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1); - }; +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); - /** - * Check if the specified method is allowed. - * - * @param string method Request method to validate - * @return boolean False if not allowed, otherwise true - */ - var isAllowedHttpMethod = function(method) { - return (method && forbiddenRequestMethods.indexOf(method) === -1); - }; +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = Math.floor((x[j] + 128) / 256); + x[j] -= carry * 256; + } + x[j] += carry; + x[i] = 0; + } + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; + } + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; + } +} - /** - * Public methods - */ +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); +} - /** - * Open the connection. Currently supports local server requests. - * - * @param string method Connection method (eg GET, POST) - * @param string url URL for the connection. - * @param boolean async Asynchronous connection. Default is true. - * @param string user Username for basic authentication (optional) - * @param string password Password for basic authentication (optional) - */ - this.open = function(method, url, async, user, password) { - this.abort(); - errorFlag = false; +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; - // Check for valid request method - if (!isAllowedHttpMethod(method)) { - throw new Error("SecurityError: Request method not allowed"); - } + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; - settings = { - "method": method, - "url": url.toString(), - "async": (typeof async !== "boolean" ? true : async), - "user": user || null, - "password": password || null - }; + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; - setState(this.OPENED); - }; + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); - /** - * Disables or enables isAllowedHttpHeader() check the request. Enabled by default. - * This does not conform to the W3C spec. - * - * @param boolean state Enable or disable header checking. - */ - this.setDisableHeaderCheck = function(state) { - disableHeaderCheck = state; - }; + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); - /** - * Sets a header for the request or appends the value if one is already set. - * - * @param string header Header name - * @param string value Header value - */ - this.setRequestHeader = function(header, value) { - if (this.readyState !== this.OPENED) { - throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN"); - } - if (!isAllowedHttpHeader(header)) { - console.warn("Refused to set unsafe header \"" + header + "\""); - return; - } - if (sendFlag) { - throw new Error("INVALID_STATE_ERR: send flag is true"); + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; } - header = headersCase[header.toLowerCase()] || header; - headersCase[header.toLowerCase()] = header; - headers[header] = headers[header] ? headers[header] + ', ' + value : value; - }; + } - /** - * Gets a header from the server response. - * - * @param string header Name of header to get. - * @return string Text of the header or null if it doesn't exist. - */ - this.getResponseHeader = function(header) { - if (typeof header === "string" - && this.readyState > this.OPENED - && response - && response.headers - && response.headers[header.toLowerCase()] - && !errorFlag - ) { - return response.headers[header.toLowerCase()]; - } + modL(sm.subarray(32), x); + return smlen; +} - return null; - }; +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); - /** - * Gets all the response headers. - * - * @return string A string with all response headers separated by CR+LF - */ - this.getAllResponseHeaders = function() { - if (this.readyState < this.HEADERS_RECEIVED || errorFlag) { - return ""; - } - var result = ""; + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); + + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); - for (var i in response.headers) { - // Cookie headers are excluded - if (i !== "set-cookie" && i !== "set-cookie2") { - result += i + ": " + response.headers[i] + "\r\n"; - } - } - return result.substr(0, result.length - 2); - }; + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); - /** - * Gets a request header - * - * @param string name Name of header to get - * @return string Returns the request header or empty string if not set - */ - this.getRequestHeader = function(name) { - if (typeof name === "string" && headersCase[name.toLowerCase()]) { - return headers[headersCase[name.toLowerCase()]]; - } + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); - return ""; - }; + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; - /** - * Sends the request to the server. - * - * @param string data Optional data to send as request body. - */ - this.send = function(data) { - if (this.readyState !== this.OPENED) { - throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called"); - } + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); - if (sendFlag) { - throw new Error("INVALID_STATE_ERR: send has already been called"); - } + M(r[3], r[0], r[1]); + return 0; +} - var ssl = false, local = false; - var url = Url.parse(settings.url); - var host; - // Determine the server - switch (url.protocol) { - case "https:": - ssl = true; - // SSL & non-SSL both need host, no break here. - case "http:": - host = url.hostname; - break; +function crypto_sign_open(m, sm, n, pk) { + var i; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; - case "file:": - local = true; - break; + if (n < 64) return -1; - case undefined: - case null: - case "": - host = "localhost"; - break; + if (unpackneg(q, pk)) return -1; - default: - throw new Error("Protocol not supported."); - } + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); - // Load files off the local filesystem (file://) - if (local) { - if (settings.method !== "GET") { - throw new Error("XMLHttpRequest: Only GET method is supported"); - } + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); - if (settings.async) { - fs.readFile(url.pathname, "utf8", function(error, data) { - if (error) { - self.handleError(error); - } else { - self.status = 200; - self.responseText = data; - setState(self.DONE); - } - }); - } else { - try { - this.responseText = fs.readFileSync(url.pathname, "utf8"); - this.status = 200; - setState(self.DONE); - } catch(e) { - this.handleError(e); - } - } + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } - return; - } + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + return n; +} - // Default to port 80. If accessing localhost on another port be sure - // to use http://localhost:port/path - var port = url.port || (ssl ? 443 : 80); - // Add query string if one is used - var uri = url.pathname + (url.search ? url.search : ""); +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; - // Set the defaults if they haven't been set - for (var name in defaultHeaders) { - if (!headersCase[name.toLowerCase()]) { - headers[name] = defaultHeaders[name]; - } - } +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, - // Set the Host header or the server may reject the request - headers.Host = host; - if (!((ssl && port === 443) || port === 80)) { - headers.Host += ":" + url.port; - } + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES, + + gf: gf, + D: D, + L: L, + pack25519: pack25519, + unpack25519: unpack25519, + M: M, + A: A, + S: S, + Z: Z, + pow2523: pow2523, + add: add, + set25519: set25519, + modL: modL, + scalarmult: scalarmult, + scalarbase: scalarbase, +}; - // Set Basic Auth if necessary - if (settings.user) { - if (typeof settings.password === "undefined") { - settings.password = ""; - } - var authBuf = new Buffer(settings.user + ":" + settings.password); - headers.Authorization = "Basic " + authBuf.toString("base64"); - } +/* High-level API */ - // Set content length header - if (settings.method === "GET" || settings.method === "HEAD") { - data = null; - } else if (data) { - headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data); +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); +} - if (!headers["Content-Type"]) { - headers["Content-Type"] = "text/plain;charset=UTF-8"; - } - } else if (settings.method === "POST") { - // For a post with no data set Content-Length: 0. - // This is required by buggy servers that don't meet the specs. - headers["Content-Length"] = 0; - } +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} - var options = { - host: host, - port: port, - path: uri, - method: settings.method, - headers: headers, - agent: false, - withCredentials: self.withCredentials - }; +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} - // Reset error flag - errorFlag = false; +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} - // Handle async requests - if (settings.async) { - // Use the proper protocol - var doRequest = ssl ? https.request : http.request; +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; + +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; - // Request is being sent, set send flag - sendFlag = true; +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; - // As per spec, this is called here for historical reasons. - self.dispatchEvent("readystatechange"); +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; - // Handler for the response - var responseHandler = function responseHandler(resp) { - // Set response var to the response we got back - // This is so it remains accessable outside this scope - response = resp; - // Check for redirect - // @TODO Prevent looped redirects - if (response.statusCode === 301 || response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) { - // Change URL to the redirect location - settings.url = response.headers.location; - var url = Url.parse(settings.url); - // Set host var in case it's used later - host = url.hostname; - // Options for the new request - var newOptions = { - hostname: url.hostname, - port: url.port, - path: url.path, - method: response.statusCode === 303 ? "GET" : settings.method, - headers: headers, - withCredentials: self.withCredentials - }; +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; - // Issue the new request - request = doRequest(newOptions, responseHandler).on("error", errorHandler); - request.end(); - // @TODO Check if an XHR event needs to be fired here - return; - } +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; - response.setEncoding("utf8"); +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; - setState(self.HEADERS_RECEIVED); - self.status = response.statusCode; +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; - response.on("data", function(chunk) { - // Make sure there's some data - if (chunk) { - self.responseText += chunk; - } - // Don't emit state changes if the connection has been aborted. - if (sendFlag) { - setState(self.LOADING); - } - }); +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; - response.on("end", function() { - if (sendFlag) { - // Discard the end event if the connection has been aborted - setState(self.DONE); - sendFlag = false; - } - }); +nacl.box.after = nacl.secretbox; - response.on("error", function(error) { - self.handleError(error); - }); - }; +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; - // Error handler for the request - var errorHandler = function errorHandler(error) { - self.handleError(error); - }; +nacl.box.open.after = nacl.secretbox.open; - // Create the request - request = doRequest(options, responseHandler).on("error", errorHandler); +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - // Node 0.4 and later won't accept empty data. Make sure it's needed. - if (data) { - request.write(data); - } +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - request.end(); +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; - self.dispatchEvent("loadstart"); - } else { // Synchronous - // Create a temporary file for communication with the other Node process - var contentFile = ".node-xmlhttprequest-content-" + process.pid; - var syncFile = ".node-xmlhttprequest-sync-" + process.pid; - fs.writeFileSync(syncFile, "", "utf8"); - // The async request the other Node process executes - var execString = "var http = require('http'), https = require('https'), fs = require('fs');" - + "var doRequest = http" + (ssl ? "s" : "") + ".request;" - + "var options = " + JSON.stringify(options) + ";" - + "var responseText = '';" - + "var req = doRequest(options, function(response) {" - + "response.setEncoding('utf8');" - + "response.on('data', function(chunk) {" - + " responseText += chunk;" - + "});" - + "response.on('end', function() {" - + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: null, data: {statusCode: response.statusCode, headers: response.headers, text: responseText}}), 'utf8');" - + "fs.unlinkSync('" + syncFile + "');" - + "});" - + "response.on('error', function(error) {" - + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" - + "fs.unlinkSync('" + syncFile + "');" - + "});" - + "}).on('error', function(error) {" - + "fs.writeFileSync('" + contentFile + "', JSON.stringify({err: error}), 'utf8');" - + "fs.unlinkSync('" + syncFile + "');" - + "});" - + (data ? "req.write('" + JSON.stringify(data).slice(1,-1).replace(/'/g, "\\'") + "');":"") - + "req.end();"; - // Start the other Node Process, executing this string - var syncProc = spawn(process.argv[0], ["-e", execString]); - while(fs.existsSync(syncFile)) { - // Wait while the sync file is empty - } - var resp = JSON.parse(fs.readFileSync(contentFile, 'utf8')); - // Kill the child process once the file has data - syncProc.stdin.end(); - // Remove the temporary file - fs.unlinkSync(contentFile); +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; - if (resp.err) { - self.handleError(resp.err); - } else { - response = resp.data; - self.status = resp.data.statusCode; - self.responseText = resp.data.text; - setState(self.DONE); - } - } - }; +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; - /** - * Called when an error is encountered to deal with it. - */ - this.handleError = function(error) { - this.status = 0; - this.statusText = error; - this.responseText = error.stack; - errorFlag = true; - setState(this.DONE); - this.dispatchEvent('error'); - }; +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; - /** - * Aborts a request. - */ - this.abort = function() { - if (request) { - request.abort(); - request = null; - } +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; - headers = defaultHeaders; - this.status = 0; - this.responseText = ""; - this.responseXML = ""; +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; - errorFlag = true; +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; - if (this.readyState !== this.UNSENT - && (this.readyState !== this.OPENED || sendFlag) - && this.readyState !== this.DONE) { - sendFlag = false; - setState(this.DONE); - } - this.readyState = this.UNSENT; - this.dispatchEvent('abort'); - }; +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; - /** - * Adds an event listener. Preferred method of binding to events. - */ - this.addEventListener = function(event, callback) { - if (!(event in listeners)) { - listeners[event] = []; - } - // Currently allows duplicate callbacks. Should it? - listeners[event].push(callback); - }; +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; - /** - * Remove an event callback that has already been bound. - * Only works on the matching funciton, cannot be a copy. - */ - this.removeEventListener = function(event, callback) { - if (event in listeners) { - // Filter will return a new array with the callback removed - listeners[event] = listeners[event].filter(function(ev) { - return ev !== callback; - }); - } - }; +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; - /** - * Dispatch any events, including both "on" methods and events attached using addEventListener. - */ - this.dispatchEvent = function(event) { - if (typeof self["on" + event] === "function") { - self["on" + event](); - } - if (event in listeners) { - for (var i = 0, len = listeners[event].length; i < len; i++) { - listeners[event][i].call(self); - } - } - }; +nacl.hash.hashLength = crypto_hash_BYTES; - /** - * Changes readyState and calls onreadystatechange. - * - * @param int state New state - */ - var setState = function(state) { - if (state == self.LOADING || self.readyState !== state) { - self.readyState = state; +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; - if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) { - self.dispatchEvent("readystatechange"); - } +nacl.setPRNG = function(fn) { + randombytes = fn; +}; - if (self.readyState === self.DONE && !errorFlag) { - self.dispatchEvent("load"); - // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie) - self.dispatchEvent("loadend"); +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (true) { + // Node.js. + crypto = __webpack_require__(3); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); } - }; -}; + } +})(); + +})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); /***/ }), -/* 20 */ +/* 21 */ /***/ (function(module, exports, __webpack_require__) { -// required so we don't have to do require('pusher').default etc. -module.exports = __webpack_require__(46).default; +module.exports = __webpack_require__(47).default; /***/ }), -/* 21 */ +/* 22 */ /***/ (function(module, exports) { module.exports = require("buffer"); /***/ }), -/* 22 */ +/* 23 */ /***/ (function(module, exports) { module.exports = require("events"); /***/ }), -/* 23 */ +/* 24 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -4819,7 +5186,7 @@ driver having these two methods. **/ -var Stream = __webpack_require__(7).Stream, +var Stream = __webpack_require__(5).Stream, util = __webpack_require__(0); @@ -4923,7 +5290,7 @@ exports.Messages = Messages; /***/ }), -/* 24 */ +/* 25 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -4999,20 +5366,20 @@ module.exports = StreamReader; /***/ }), -/* 25 */ +/* 26 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var Buffer = __webpack_require__(1).Buffer, - crypto = __webpack_require__(5), - url = __webpack_require__(8), + crypto = __webpack_require__(3), + url = __webpack_require__(6), util = __webpack_require__(0), - HttpParser = __webpack_require__(11), + HttpParser = __webpack_require__(10), Base = __webpack_require__(2), Hybi = __webpack_require__(13), - Proxy = __webpack_require__(35); + Proxy = __webpack_require__(36); var Client = function(_url, options) { this.version = 'hybi-' + Hybi.VERSION; @@ -5148,12 +5515,12 @@ module.exports = Client; /***/ }), -/* 26 */ +/* 27 */ /***/ (function(module, exports, __webpack_require__) { /*jshint node:true */ -var assert = __webpack_require__(27); +var assert = __webpack_require__(28); exports.HTTPParser = HTTPParser; function HTTPParser(type) { @@ -5579,20 +5946,20 @@ function parseErrorCode(code) { /***/ }), -/* 27 */ +/* 28 */ /***/ (function(module, exports) { module.exports = require("assert"); /***/ }), -/* 28 */ +/* 29 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var Parser = __webpack_require__(29), - Pipeline = __webpack_require__(30); +var Parser = __webpack_require__(30), + Pipeline = __webpack_require__(31); var Extensions = function() { this._rsv1 = this._rsv2 = this._rsv3 = null; @@ -5754,7 +6121,7 @@ module.exports = Extensions; /***/ }), -/* 29 */ +/* 30 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5864,13 +6231,13 @@ module.exports = Parser; /***/ }), -/* 30 */ +/* 31 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var Cell = __webpack_require__(31), +var Cell = __webpack_require__(32), Pledge = __webpack_require__(15); var Pipeline = function(sessions) { @@ -5918,13 +6285,13 @@ module.exports = Pipeline; /***/ }), -/* 31 */ +/* 32 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var Functor = __webpack_require__(32), +var Functor = __webpack_require__(33), Pledge = __webpack_require__(15); var Cell = function(tuple) { @@ -5978,7 +6345,7 @@ module.exports = Cell; /***/ }), -/* 32 */ +/* 33 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6057,7 +6424,7 @@ module.exports = Functor; /***/ }), -/* 33 */ +/* 34 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6085,7 +6452,7 @@ module.exports = Frame; /***/ }), -/* 34 */ +/* 35 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6126,19 +6493,19 @@ module.exports = Message; /***/ }), -/* 35 */ +/* 36 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var Buffer = __webpack_require__(1).Buffer, - Stream = __webpack_require__(7).Stream, - url = __webpack_require__(8), + Stream = __webpack_require__(5).Stream, + url = __webpack_require__(6), util = __webpack_require__(0), Base = __webpack_require__(2), - Headers = __webpack_require__(10), - HttpParser = __webpack_require__(11); + Headers = __webpack_require__(9), + HttpParser = __webpack_require__(10); var PORTS = { 'ws:': 80, 'wss:': 443 }; @@ -6232,17 +6599,17 @@ module.exports = Proxy; /***/ }), -/* 36 */ +/* 37 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var util = __webpack_require__(0), - HttpParser = __webpack_require__(11), + HttpParser = __webpack_require__(10), Base = __webpack_require__(2), Draft75 = __webpack_require__(16), - Draft76 = __webpack_require__(37), + Draft76 = __webpack_require__(38), Hybi = __webpack_require__(13); var Server = function(options) { @@ -6351,7 +6718,7 @@ module.exports = Server; /***/ }), -/* 37 */ +/* 38 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6360,7 +6727,7 @@ module.exports = Server; var Buffer = __webpack_require__(1).Buffer, Base = __webpack_require__(2), Draft75 = __webpack_require__(16), - crypto = __webpack_require__(5), + crypto = __webpack_require__(3), util = __webpack_require__(0); @@ -6475,17 +6842,17 @@ module.exports = Draft76; /***/ }), -/* 38 */ +/* 39 */ /***/ (function(module, exports, __webpack_require__) { var util = __webpack_require__(0), - net = __webpack_require__(39), - tls = __webpack_require__(40), - crypto = __webpack_require__(5), - url = __webpack_require__(8), - driver = __webpack_require__(6), - API = __webpack_require__(12), - Event = __webpack_require__(9); + net = __webpack_require__(40), + tls = __webpack_require__(41), + crypto = __webpack_require__(3), + url = __webpack_require__(6), + driver = __webpack_require__(4), + API = __webpack_require__(11), + Event = __webpack_require__(7); var DEFAULT_PORTS = {'http:': 80, 'https:': 443, 'ws:':80, 'wss:': 443}, SECURE_PROTOCOLS = ['https:', 'wss:']; @@ -6565,28 +6932,28 @@ module.exports = Client; /***/ }), -/* 39 */ +/* 40 */ /***/ (function(module, exports) { module.exports = require("net"); /***/ }), -/* 40 */ +/* 41 */ /***/ (function(module, exports) { module.exports = require("tls"); /***/ }), -/* 41 */ +/* 42 */ /***/ (function(module, exports, __webpack_require__) { -var Stream = __webpack_require__(7).Stream, +var Stream = __webpack_require__(5).Stream, util = __webpack_require__(0), - driver = __webpack_require__(6), - Headers = __webpack_require__(10), - API = __webpack_require__(12), + driver = __webpack_require__(4), + Headers = __webpack_require__(9), + API = __webpack_require__(11), EventTarget = __webpack_require__(17), - Event = __webpack_require__(9); + Event = __webpack_require__(7); var EventSource = function(request, response, options) { this.writable = true; @@ -6714,31 +7081,31 @@ module.exports = EventSource; /***/ }), -/* 42 */ +/* 43 */ /***/ (function(module, exports) { module.exports = require("child_process"); /***/ }), -/* 43 */ +/* 44 */ /***/ (function(module, exports) { module.exports = require("fs"); /***/ }), -/* 44 */ +/* 45 */ /***/ (function(module, exports) { module.exports = require("http"); /***/ }), -/* 45 */ +/* 46 */ /***/ (function(module, exports) { module.exports = require("https"); /***/ }), -/* 46 */ +/* 47 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -6891,7 +7258,8 @@ function extend(target) { for (var i = 0; i < sources.length; i++) { var extensions = sources[i]; for (var property in extensions) { - if (extensions[property] && extensions[property].constructor && + if (extensions[property] && + extensions[property].constructor && extensions[property].constructor === Object) { target[property] = extend(target[property] || {}, extensions[property]); } @@ -6903,16 +7271,16 @@ function extend(target) { return target; } function stringify() { - var m = ["Pusher"]; + var m = ['Pusher']; for (var i = 0; i < arguments.length; i++) { - if (typeof arguments[i] === "string") { + if (typeof arguments[i] === 'string') { m.push(arguments[i]); } else { m.push(safeJSONStringify(arguments[i])); } } - return m.join(" : "); + return m.join(' : '); } function arrayIndexOf(array, item) { var nativeIndexOf = Array.prototype.indexOf; @@ -6970,7 +7338,11 @@ function mapObject(object, f) { return result; } function filter(array, test) { - test = test || function (value) { return !!value; }; + test = + test || + function (value) { + return !!value; + }; var result = []; for (var i = 0; i < array.length; i++) { if (test(array[i], i, array, result)) { @@ -7013,7 +7385,7 @@ function collections_all(array, test) { } function encodeParamsObject(data) { return mapObject(data, function (value) { - if (typeof value === "object") { + if (typeof value === 'object') { value = safeJSONStringify(value); } return encodeURIComponent(encode(value.toString())); @@ -7023,7 +7395,7 @@ function buildQueryString(data) { var params = filterObject(data, function (value) { return value !== undefined; }); - var query = map(flatten(encodeParamsObject(params)), util.method("join", "=")).join("&"); + var query = map(flatten(encodeParamsObject(params)), util.method('join', '=')).join('&'); return query; } function decycleObject(object) { @@ -7062,7 +7434,7 @@ function decycleObject(object) { case 'boolean': return value; } - }(object, '$')); + })(object, '$'); } function safeJSONStringify(source) { try { @@ -7075,22 +7447,22 @@ function safeJSONStringify(source) { // CONCATENATED MODULE: ./src/core/defaults.ts var Defaults = { - VERSION: "5.0.3", + VERSION: "6.0.0", PROTOCOL: 7, - host: 'ws.pusherapp.com', - ws_port: 80, - wss_port: 443, - ws_path: '', - sockjs_host: 'sockjs.pusher.com', - sockjs_http_port: 80, - sockjs_https_port: 443, - sockjs_path: '/pusher', + wsPort: 80, + wssPort: 443, + wsPath: '', + httpHost: 'sockjs.pusher.com', + httpPort: 80, + httpsPort: 443, + httpPath: '/pusher', stats_host: 'stats.pusher.com', - channel_auth_endpoint: '/pusher/auth', - channel_auth_transport: 'ajax', - activity_timeout: 120000, - pong_timeout: 30000, - unavailable_timeout: 10000, + authEndpoint: '/pusher/auth', + authTransport: 'ajax', + activityTimeout: 120000, + pongTimeout: 30000, + unavailableTimeout: 10000, + cluster: 'mt1', cdn_http: "http://js.pusher.com", cdn_https: "https://js.pusher.com", dependency_suffix: "" @@ -7100,33 +7472,35 @@ var Defaults = { // CONCATENATED MODULE: ./src/core/transports/url_schemes.ts function getGenericURL(baseScheme, params, path) { - var scheme = baseScheme + (params.useTLS ? "s" : ""); + var scheme = baseScheme + (params.useTLS ? 's' : ''); var host = params.useTLS ? params.hostTLS : params.hostNonTLS; - return scheme + "://" + host + path; + return scheme + '://' + host + path; } function getGenericPath(key, queryString) { - var path = "/app/" + key; - var query = "?protocol=" + defaults.PROTOCOL + - "&client=js" + - "&version=" + defaults.VERSION + - (queryString ? ("&" + queryString) : ""); + var path = '/app/' + key; + var query = '?protocol=' + + defaults.PROTOCOL + + '&client=js' + + '&version=' + + defaults.VERSION + + (queryString ? '&' + queryString : ''); return path + query; } var ws = { getInitial: function (key, params) { - var path = (params.httpPath || "") + getGenericPath(key, "flash=false"); - return getGenericURL("ws", params, path); + var path = (params.httpPath || '') + getGenericPath(key, 'flash=false'); + return getGenericURL('ws', params, path); } }; var http = { getInitial: function (key, params) { - var path = (params.httpPath || "/pusher") + getGenericPath(key); - return getGenericURL("http", params, path); + var path = (params.httpPath || '/pusher') + getGenericPath(key); + return getGenericURL('http', params, path); } }; var sockjs = { getInitial: function (key, params) { - return getGenericURL("http", params, params.httpPath || "/pusher"); + return getGenericURL('http', params, params.httpPath || '/pusher'); }, getPath: function (key, params) { return getGenericPath(key); @@ -7144,7 +7518,8 @@ var callback_registry_CallbackRegistry = (function () { }; CallbackRegistry.prototype.add = function (name, callback, context) { var prefixedEventName = prefix(name); - this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || []; + this._callbacks[prefixedEventName] = + this._callbacks[prefixedEventName] || []; this._callbacks[prefixedEventName].push({ fn: callback, context: context @@ -7166,8 +7541,8 @@ var callback_registry_CallbackRegistry = (function () { CallbackRegistry.prototype.removeCallback = function (names, callback, context) { apply(names, function (name) { this._callbacks[name] = filter(this._callbacks[name] || [], function (binding) { - return (callback && callback !== binding.fn) || - (context && context !== binding.context); + return ((callback && callback !== binding.fn) || + (context && context !== binding.context)); }); if (this._callbacks[name].length === 0) { delete this._callbacks[name]; @@ -7183,7 +7558,7 @@ var callback_registry_CallbackRegistry = (function () { }()); /* harmony default export */ var callback_registry = (callback_registry_CallbackRegistry); function prefix(name) { - return "_" + name; + return '_' + name; } // CONCATENATED MODULE: ./src/core/events/dispatcher.ts @@ -7341,7 +7716,7 @@ var transport_connection_TransportConnection = (function (_super) { _this.priority = priority; _this.key = key; _this.options = options; - _this.state = "new"; + _this.state = 'new'; _this.timeline = options.timeline; _this.activityTimeout = options.activityTimeout; _this.id = _this.timeline.generateUniqueID(); @@ -7355,7 +7730,7 @@ var transport_connection_TransportConnection = (function (_super) { }; TransportConnection.prototype.connect = function () { var _this = this; - if (this.socket || this.state !== "initialized") { + if (this.socket || this.state !== 'initialized') { return false; } var url = this.hooks.urls.getInitial(this.key, this.options); @@ -7365,13 +7740,13 @@ var transport_connection_TransportConnection = (function (_super) { catch (e) { util.defer(function () { _this.onError(e); - _this.changeState("closed"); + _this.changeState('closed'); }); return false; } this.bindListeners(); - logger.debug("Connecting", { transport: this.name, url: url }); - this.changeState("connecting"); + logger.debug('Connecting', { transport: this.name, url: url }); + this.changeState('connecting'); return true; }; TransportConnection.prototype.close = function () { @@ -7385,7 +7760,7 @@ var transport_connection_TransportConnection = (function (_super) { }; TransportConnection.prototype.send = function (data) { var _this = this; - if (this.state === "open") { + if (this.state === 'open') { util.defer(function () { if (_this.socket) { _this.socket.send(data); @@ -7398,7 +7773,7 @@ var transport_connection_TransportConnection = (function (_super) { } }; TransportConnection.prototype.ping = function () { - if (this.state === "open" && this.supportsPing()) { + if (this.state === 'open' && this.supportsPing()) { this.socket.ping(); } }; @@ -7406,32 +7781,32 @@ var transport_connection_TransportConnection = (function (_super) { if (this.hooks.beforeOpen) { this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); } - this.changeState("open"); + this.changeState('open'); this.socket.onopen = undefined; }; TransportConnection.prototype.onError = function (error) { - this.emit("error", { type: 'WebSocketError', error: error }); + this.emit('error', { type: 'WebSocketError', error: error }); this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); }; TransportConnection.prototype.onClose = function (closeEvent) { if (closeEvent) { - this.changeState("closed", { + this.changeState('closed', { code: closeEvent.code, reason: closeEvent.reason, wasClean: closeEvent.wasClean }); } else { - this.changeState("closed"); + this.changeState('closed'); } this.unbindListeners(); this.socket = undefined; }; TransportConnection.prototype.onMessage = function (message) { - this.emit("message", message); + this.emit('message', message); }; TransportConnection.prototype.onActivity = function () { - this.emit("activity"); + this.emit('activity'); }; TransportConnection.prototype.bindListeners = function () { var _this = this; @@ -7448,7 +7823,9 @@ var transport_connection_TransportConnection = (function (_super) { _this.onMessage(message); }; if (this.supportsPing()) { - this.socket.onactivity = function () { _this.onActivity(); }; + this.socket.onactivity = function () { + _this.onActivity(); + }; } }; TransportConnection.prototype.unbindListeners = function () { @@ -7520,11 +7897,13 @@ var httpConfiguration = { return true; } }; -var streamingConfiguration = extend({ getSocket: function (url) { +var streamingConfiguration = extend({ + getSocket: function (url) { return node_runtime.HTTPFactory.createStreamingSocket(url); } }, httpConfiguration); -var pollingConfiguration = extend({ getSocket: function (url) { +var pollingConfiguration = extend({ + getSocket: function (url) { return node_runtime.HTTPFactory.createPollingSocket(url); } }, httpConfiguration); @@ -7533,7 +7912,7 @@ var xhrConfiguration = { return node_runtime.isXHRSupported(); } }; -var XHRStreamingTransport = new transports_transport(extend({}, streamingConfiguration, xhrConfiguration)); +var XHRStreamingTransport = new transports_transport((extend({}, streamingConfiguration, xhrConfiguration))); var XHRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xhrConfiguration)); var Transports = { ws: WSTransport, @@ -7561,12 +7940,12 @@ var assistant_to_the_transport_manager_AssistantToTheTransportManager = (functio var connection = this.transport.createConnection(name, priority, key, options); var openTimestamp = null; var onOpen = function () { - connection.unbind("open", onOpen); - connection.bind("closed", onClosed); + connection.unbind('open', onOpen); + connection.bind('closed', onClosed); openTimestamp = util.now(); }; var onClosed = function (closeEvent) { - connection.unbind("closed", onClosed); + connection.unbind('closed', onClosed); if (closeEvent.code === 1002 || closeEvent.code === 1003) { _this.manager.reportDeath(); } @@ -7578,7 +7957,7 @@ var assistant_to_the_transport_manager_AssistantToTheTransportManager = (functio } } }; - connection.bind("open", onOpen); + connection.bind('open', onOpen); return connection; }; AssistantToTheTransportManager.prototype.isSupported = function (environment) { @@ -7603,7 +7982,7 @@ var Protocol = { var pusherEvent = { event: messageData.event, channel: messageData.channel, - data: pusherEventData, + data: pusherEventData }; if (messageData.user_id) { pusherEvent.user_id = messageData.user_id; @@ -7619,49 +7998,49 @@ var Protocol = { }, processHandshake: function (messageEvent) { var message = Protocol.decodeMessage(messageEvent); - if (message.event === "pusher:connection_established") { + if (message.event === 'pusher:connection_established') { if (!message.data.activity_timeout) { - throw "No activity timeout specified in handshake"; + throw 'No activity timeout specified in handshake'; } return { - action: "connected", + action: 'connected', id: message.data.socket_id, activityTimeout: message.data.activity_timeout * 1000 }; } - else if (message.event === "pusher:error") { + else if (message.event === 'pusher:error') { return { action: this.getCloseAction(message.data), error: this.getCloseError(message.data) }; } else { - throw "Invalid handshake"; + throw 'Invalid handshake'; } }, getCloseAction: function (closeEvent) { if (closeEvent.code < 4000) { if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { - return "backoff"; + return 'backoff'; } else { return null; } } else if (closeEvent.code === 4000) { - return "tls_only"; + return 'tls_only'; } else if (closeEvent.code < 4100) { - return "refused"; + return 'refused'; } else if (closeEvent.code < 4200) { - return "backoff"; + return 'backoff'; } else if (closeEvent.code < 4300) { - return "retry"; + return 'retry'; } else { - return "refused"; + return 'refused'; } }, getCloseError: function (closeEvent) { @@ -7753,23 +8132,26 @@ var connection_Connection = (function (_super) { logger.debug('Event recd', pusherEvent); switch (pusherEvent.event) { case 'pusher:error': - _this.emit('error', { type: 'PusherError', data: pusherEvent.data }); + _this.emit('error', { + type: 'PusherError', + data: pusherEvent.data + }); break; case 'pusher:ping': - _this.emit("ping"); + _this.emit('ping'); break; case 'pusher:pong': - _this.emit("pong"); + _this.emit('pong'); break; } _this.emit('message', pusherEvent); } }, activity: function () { - _this.emit("activity"); + _this.emit('activity'); }, error: function (error) { - _this.emit("error", { type: "WebSocketError", error: error }); + _this.emit('error', { type: 'WebSocketError', error: error }); }, closed: function (closeEvent) { unbindListeners(); @@ -7777,7 +8159,7 @@ var connection_Connection = (function (_super) { _this.handleCloseEvent(closeEvent); } _this.transport = null; - _this.emit("closed"); + _this.emit('closed'); } }; var unbindListeners = function () { @@ -7826,12 +8208,12 @@ var handshake_Handshake = (function () { result = protocol.processHandshake(m); } catch (e) { - _this.finish("error", { error: e }); + _this.finish('error', { error: e }); _this.transport.close(); return; } - if (result.action === "connected") { - _this.finish("connected", { + if (result.action === 'connected') { + _this.finish('connected', { connection: new connection_connection(result.id, _this.transport), activityTimeout: result.activityTimeout }); @@ -7843,16 +8225,16 @@ var handshake_Handshake = (function () { }; this.onClosed = function (closeEvent) { _this.unbindListeners(); - var action = protocol.getCloseAction(closeEvent) || "backoff"; + var action = protocol.getCloseAction(closeEvent) || 'backoff'; var error = protocol.getCloseError(closeEvent); _this.finish(action, { error: error }); }; - this.transport.bind("message", this.onMessage); - this.transport.bind("closed", this.onClosed); + this.transport.bind('message', this.onMessage); + this.transport.bind('closed', this.onClosed); }; Handshake.prototype.unbindListeners = function () { - this.transport.unbind("message", this.onMessage); - this.transport.unbind("closed", this.onClosed); + this.transport.unbind('message', this.onMessage); + this.transport.unbind('closed', this.onClosed); }; Handshake.prototype.finish = function (action, params) { this.callback(extend({ transport: this.transport, action: action }, params)); @@ -7867,24 +8249,31 @@ var pusher_authorizer_PusherAuthorizer = (function () { function PusherAuthorizer(channel, options) { this.channel = channel; var authTransport = options.authTransport; - if (typeof node_runtime.getAuthorizers()[authTransport] === "undefined") { + if (typeof node_runtime.getAuthorizers()[authTransport] === 'undefined') { throw "'" + authTransport + "' is not a recognized auth transport"; } this.type = authTransport; this.options = options; - this.authOptions = (options || {}).auth || {}; + this.authOptions = options.auth || {}; } PusherAuthorizer.prototype.composeQuery = function (socketId) { - var query = 'socket_id=' + encodeURIComponent(socketId) + - '&channel_name=' + encodeURIComponent(this.channel.name); + var query = 'socket_id=' + + encodeURIComponent(socketId) + + '&channel_name=' + + encodeURIComponent(this.channel.name); for (var i in this.authOptions.params) { - query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]); + query += + '&' + + encodeURIComponent(i) + + '=' + + encodeURIComponent(this.authOptions.params[i]); } return query; }; PusherAuthorizer.prototype.authorize = function (socketId, callback) { - PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || node_runtime.getAuthorizers(); - return PusherAuthorizer.authorizers[this.type].call(this, node_runtime, socketId, callback); + PusherAuthorizer.authorizers = + PusherAuthorizer.authorizers || node_runtime.getAuthorizers(); + PusherAuthorizer.authorizers[this.type].call(this, node_runtime, socketId, callback); }; return PusherAuthorizer; }()); @@ -8001,24 +8390,27 @@ var UnsupportedStrategy = (function (_super) { // CONCATENATED MODULE: ./src/core/utils/url_store.ts var urlStore = { - baseUrl: "https://pusher.com", + baseUrl: 'https://pusher.com', urls: { authenticationEndpoint: { - path: "/docs/authenticating_users", + path: '/docs/authenticating_users' }, javascriptQuickStart: { - path: "/docs/javascript_quick_start" + path: '/docs/javascript_quick_start' }, triggeringClientEvents: { - path: "/docs/client_api_guide/client_events#trigger-events" + path: '/docs/client_api_guide/client_events#trigger-events' + }, + encryptedChannelSupport: { + fullUrl: 'https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support' } } }; var buildLogSuffix = function (key) { - var urlPrefix = "See:"; + var urlPrefix = 'See:'; var urlObj = urlStore.urls[key]; if (!urlObj) - return ""; + return ''; var url; if (urlObj.fullUrl) { url = urlObj.fullUrl; @@ -8027,7 +8419,7 @@ var buildLogSuffix = function (key) { url = urlStore.baseUrl + urlObj.path; } if (!url) - return ""; + return ''; return urlPrefix + " " + url; }; /* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix }); @@ -8064,14 +8456,14 @@ var channel_Channel = (function (_super) { return _this; } Channel.prototype.authorize = function (socketId, callback) { - return callback(false, {}); + return callback(false, { auth: '' }); }; Channel.prototype.trigger = function (event, data) { - if (event.indexOf("client-") !== 0) { + if (event.indexOf('client-') !== 0) { throw new BadEventName("Event '" + event + "' does not start with 'client-'"); } if (!this.subscribed) { - var suffix = url_store.buildLogSuffix("triggeringClientEvents"); + var suffix = url_store.buildLogSuffix('triggeringClientEvents'); logger.warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); } return this.pusher.send_event(event, data, this.name); @@ -8083,10 +8475,10 @@ var channel_Channel = (function (_super) { Channel.prototype.handleEvent = function (event) { var eventName = event.event; var data = event.data; - if (eventName === "pusher_internal:subscription_succeeded") { + if (eventName === 'pusher_internal:subscription_succeeded') { this.handleSubscriptionSucceededEvent(event); } - else if (eventName.indexOf("pusher_internal:") !== 0) { + else if (eventName.indexOf('pusher_internal:') !== 0) { var metadata = {}; this.emit(eventName, data, metadata); } @@ -8098,7 +8490,7 @@ var channel_Channel = (function (_super) { this.pusher.unsubscribe(this.name); } else { - this.emit("pusher:subscription_succeeded", event.data); + this.emit('pusher:subscription_succeeded', event.data); } }; Channel.prototype.subscribe = function () { @@ -8114,6 +8506,7 @@ var channel_Channel = (function (_super) { _this.emit('pusher:subscription_error', data); } else { + data = data; _this.pusher.send_event('pusher:subscribe', { auth: data.auth, channel_data: data.channel_data, @@ -8252,11 +8645,12 @@ var presence_channel_PresenceChannel = (function (_super) { var _this = this; _super.prototype.authorize.call(this, socketId, function (error, authData) { if (!error) { + authData = authData; if (authData.channel_data === undefined) { - var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + var suffix = url_store.buildLogSuffix('authenticationEndpoint'); logger.error("Invalid auth response for channel '" + _this.name + "'," + ("expected 'channel_data' field. " + suffix)); - callback("Invalid auth response"); + callback('Invalid auth response'); return; } var channelData = JSON.parse(authData.channel_data); @@ -8267,7 +8661,7 @@ var presence_channel_PresenceChannel = (function (_super) { }; PresenceChannel.prototype.handleEvent = function (event) { var eventName = event.event; - if (eventName.indexOf("pusher_internal:") === 0) { + if (eventName.indexOf('pusher_internal:') === 0) { this.handleInternalEvent(event); } else { @@ -8283,14 +8677,14 @@ var presence_channel_PresenceChannel = (function (_super) { var eventName = event.event; var data = event.data; switch (eventName) { - case "pusher_internal:subscription_succeeded": + case 'pusher_internal:subscription_succeeded': this.handleSubscriptionSucceededEvent(event); break; - case "pusher_internal:member_added": + case 'pusher_internal:member_added': var addedMember = this.members.addMember(data); this.emit('pusher:member_added', addedMember); break; - case "pusher_internal:member_removed": + case 'pusher_internal:member_removed': var removedMember = this.members.removeMember(data); if (removedMember) { this.emit('pusher:member_removed', removedMember); @@ -8306,7 +8700,7 @@ var presence_channel_PresenceChannel = (function (_super) { } else { this.members.onSubscription(event.data); - this.emit("pusher:subscription_succeeded", this.members); + this.emit('pusher:subscription_succeeded', this.members); } }; PresenceChannel.prototype.disconnect = function () { @@ -8317,11 +8711,11 @@ var presence_channel_PresenceChannel = (function (_super) { }(private_channel)); /* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); -// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js -var nacl_fast = __webpack_require__(3); +// EXTERNAL MODULE: ./node_modules/@stablelib/utf8/lib/utf8.js +var utf8 = __webpack_require__(12); -// EXTERNAL MODULE: ./node_modules/tweetnacl-util/nacl-util.js -var nacl_util = __webpack_require__(4); +// EXTERNAL MODULE: ./node_modules/@stablelib/base64/lib/base64.js +var base64 = __webpack_require__(8); // CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { @@ -8344,9 +8738,10 @@ var encrypted_channel_extends = (undefined && undefined.__extends) || (function var encrypted_channel_EncryptedChannel = (function (_super) { encrypted_channel_extends(EncryptedChannel, _super); - function EncryptedChannel() { - var _this = _super !== null && _super.apply(this, arguments) || this; + function EncryptedChannel(name, pusher, nacl) { + var _this = _super.call(this, name, pusher) || this; _this.key = null; + _this.nacl = nacl; return _this; } EncryptedChannel.prototype.authorize = function (socketId, callback) { @@ -8356,14 +8751,14 @@ var encrypted_channel_EncryptedChannel = (function (_super) { callback(true, authData); return; } - var sharedSecret = authData["shared_secret"]; + var sharedSecret = authData['shared_secret']; if (!sharedSecret) { var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; callback(true, errorMsg); return; } - _this.key = Object(nacl_util["decodeBase64"])(sharedSecret); - delete authData["shared_secret"]; + _this.key = Object(base64["decode"])(sharedSecret); + delete authData['shared_secret']; callback(false, authData); }); }; @@ -8373,7 +8768,8 @@ var encrypted_channel_EncryptedChannel = (function (_super) { EncryptedChannel.prototype.handleEvent = function (event) { var eventName = event.event; var data = event.data; - if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) { + if (eventName.indexOf('pusher_internal:') === 0 || + eventName.indexOf('pusher:') === 0) { _super.prototype.handleEvent.call(this, event); return; } @@ -8386,20 +8782,21 @@ var encrypted_channel_EncryptedChannel = (function (_super) { return; } if (!data.ciphertext || !data.nonce) { - logger.error('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + data); + logger.error('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + + data); return; } - var cipherText = Object(nacl_util["decodeBase64"])(data.ciphertext); - if (cipherText.length < nacl_fast["secretbox"].overheadLength) { - logger.error("Expected encrypted event ciphertext length to be " + nacl_fast["secretbox"].overheadLength + ", got: " + cipherText.length); + var cipherText = Object(base64["decode"])(data.ciphertext); + if (cipherText.length < this.nacl.secretbox.overheadLength) { + logger.error("Expected encrypted event ciphertext length to be " + this.nacl.secretbox.overheadLength + ", got: " + cipherText.length); return; } - var nonce = Object(nacl_util["decodeBase64"])(data.nonce); - if (nonce.length < nacl_fast["secretbox"].nonceLength) { - logger.error("Expected encrypted event nonce length to be " + nacl_fast["secretbox"].nonceLength + ", got: " + nonce.length); + var nonce = Object(base64["decode"])(data.nonce); + if (nonce.length < this.nacl.secretbox.nonceLength) { + logger.error("Expected encrypted event nonce length to be " + this.nacl.secretbox.nonceLength + ", got: " + nonce.length); return; } - var bytes = nacl_fast["secretbox"].open(cipherText, nonce, this.key); + var bytes = this.nacl.secretbox.open(cipherText, nonce, this.key); if (bytes === null) { logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); this.authorize(this.pusher.connection.socket_id, function (error, authData) { @@ -8407,17 +8804,17 @@ var encrypted_channel_EncryptedChannel = (function (_super) { logger.error("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); return; } - bytes = nacl_fast["secretbox"].open(cipherText, nonce, _this.key); + bytes = _this.nacl.secretbox.open(cipherText, nonce, _this.key); if (bytes === null) { logger.error("Failed to decrypt event with new key. Dropping encrypted event"); return; } - _this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + _this.emitJSON(event, Object(utf8["decode"])(bytes)); return; }); return; } - this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + this.emitJSON(event, Object(utf8["decode"])(bytes)); }; EncryptedChannel.prototype.emitJSON = function (eventName, data) { try { @@ -8455,24 +8852,24 @@ var connection_manager_ConnectionManager = (function (_super) { connection_manager_extends(ConnectionManager, _super); function ConnectionManager(key, options) { var _this = _super.call(this) || this; - _this.key = key; - _this.options = options || {}; - _this.state = "initialized"; + _this.state = 'initialized'; _this.connection = null; - _this.usingTLS = !!options.useTLS; + _this.key = key; + _this.options = options; _this.timeline = _this.options.timeline; + _this.usingTLS = _this.options.useTLS; _this.errorCallbacks = _this.buildErrorCallbacks(); _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); var Network = node_runtime.getNetwork(); - Network.bind("online", function () { - _this.timeline.info({ netinfo: "online" }); - if (_this.state === "connecting" || _this.state === "unavailable") { + Network.bind('online', function () { + _this.timeline.info({ netinfo: 'online' }); + if (_this.state === 'connecting' || _this.state === 'unavailable') { _this.retryIn(0); } }); - Network.bind("offline", function () { - _this.timeline.info({ netinfo: "offline" }); + Network.bind('offline', function () { + _this.timeline.info({ netinfo: 'offline' }); if (_this.connection) { _this.sendActivityCheck(); } @@ -8485,14 +8882,13 @@ var connection_manager_ConnectionManager = (function (_super) { return; } if (!this.strategy.isSupported()) { - this.updateState("failed"); + this.updateState('failed'); return; } - this.updateState("connecting"); + this.updateState('connecting'); this.startConnecting(); this.setUnavailableTimer(); }; - ; ConnectionManager.prototype.send = function (data) { if (this.connection) { return this.connection.send(data); @@ -8501,7 +8897,6 @@ var connection_manager_ConnectionManager = (function (_super) { return false; } }; - ; ConnectionManager.prototype.send_event = function (name, data, channel) { if (this.connection) { return this.connection.send_event(name, data, channel); @@ -8510,16 +8905,13 @@ var connection_manager_ConnectionManager = (function (_super) { return false; } }; - ; ConnectionManager.prototype.disconnect = function () { this.disconnectInternally(); - this.updateState("disconnected"); + this.updateState('disconnected'); }; - ; ConnectionManager.prototype.isUsingTLS = function () { return this.usingTLS; }; - ; ConnectionManager.prototype.startConnecting = function () { var _this = this; var callback = function (error, handshake) { @@ -8527,8 +8919,11 @@ var connection_manager_ConnectionManager = (function (_super) { _this.runner = _this.strategy.connect(0, callback); } else { - if (handshake.action === "error") { - _this.emit("error", { type: "HandshakeError", error: handshake.error }); + if (handshake.action === 'error') { + _this.emit('error', { + type: 'HandshakeError', + error: handshake.error + }); _this.timeline.error({ handshakeError: handshake.error }); } else { @@ -8539,14 +8934,12 @@ var connection_manager_ConnectionManager = (function (_super) { }; this.runner = this.strategy.connect(0, callback); }; - ; ConnectionManager.prototype.abortConnecting = function () { if (this.runner) { this.runner.abort(); this.runner = null; } }; - ; ConnectionManager.prototype.disconnectInternally = function () { this.abortConnecting(); this.clearRetryTimer(); @@ -8556,7 +8949,6 @@ var connection_manager_ConnectionManager = (function (_super) { connection.close(); } }; - ; ConnectionManager.prototype.updateStrategy = function () { this.strategy = this.options.getStrategy({ key: this.key, @@ -8564,39 +8956,34 @@ var connection_manager_ConnectionManager = (function (_super) { useTLS: this.usingTLS }); }; - ; ConnectionManager.prototype.retryIn = function (delay) { var _this = this; - this.timeline.info({ action: "retry", delay: delay }); + this.timeline.info({ action: 'retry', delay: delay }); if (delay > 0) { - this.emit("connecting_in", Math.round(delay / 1000)); + this.emit('connecting_in', Math.round(delay / 1000)); } this.retryTimer = new OneOffTimer(delay || 0, function () { _this.disconnectInternally(); _this.connect(); }); }; - ; ConnectionManager.prototype.clearRetryTimer = function () { if (this.retryTimer) { this.retryTimer.ensureAborted(); this.retryTimer = null; } }; - ; ConnectionManager.prototype.setUnavailableTimer = function () { var _this = this; this.unavailableTimer = new OneOffTimer(this.options.unavailableTimeout, function () { - _this.updateState("unavailable"); + _this.updateState('unavailable'); }); }; - ; ConnectionManager.prototype.clearUnavailableTimer = function () { if (this.unavailableTimer) { this.unavailableTimer.ensureAborted(); } }; - ; ConnectionManager.prototype.sendActivityCheck = function () { var _this = this; this.stopActivityCheck(); @@ -8606,7 +8993,6 @@ var connection_manager_ConnectionManager = (function (_super) { _this.retryIn(0); }); }; - ; ConnectionManager.prototype.resetActivityCheck = function () { var _this = this; this.stopActivityCheck(); @@ -8616,13 +9002,11 @@ var connection_manager_ConnectionManager = (function (_super) { }); } }; - ; ConnectionManager.prototype.stopActivityCheck = function () { if (this.activityTimer) { this.activityTimer.ensureAborted(); } }; - ; ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { var _this = this; return extend({}, errorCallbacks, { @@ -8637,7 +9021,7 @@ var connection_manager_ConnectionManager = (function (_super) { _this.resetActivityCheck(); }, error: function (error) { - _this.emit("error", { type: "WebSocketError", error: error }); + _this.emit('error', { type: 'WebSocketError', error: error }); }, closed: function () { _this.abandonConnection(); @@ -8647,7 +9031,6 @@ var connection_manager_ConnectionManager = (function (_super) { } }); }; - ; ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { var _this = this; return extend({}, errorCallbacks, { @@ -8656,17 +9039,16 @@ var connection_manager_ConnectionManager = (function (_super) { _this.clearUnavailableTimer(); _this.setConnection(handshake.connection); _this.socket_id = _this.connection.id; - _this.updateState("connected", { socket_id: _this.socket_id }); + _this.updateState('connected', { socket_id: _this.socket_id }); } }); }; - ; ConnectionManager.prototype.buildErrorCallbacks = function () { var _this = this; var withErrorEmitted = function (callback) { return function (result) { if (result.error) { - _this.emit("error", { type: "WebSocketError", error: result.error }); + _this.emit('error', { type: 'WebSocketError', error: result.error }); } callback(result); }; @@ -8688,7 +9070,6 @@ var connection_manager_ConnectionManager = (function (_super) { }) }; }; - ; ConnectionManager.prototype.setConnection = function (connection) { this.connection = connection; for (var event in this.connectionCallbacks) { @@ -8696,7 +9077,6 @@ var connection_manager_ConnectionManager = (function (_super) { } this.resetActivityCheck(); }; - ; ConnectionManager.prototype.abandonConnection = function () { if (!this.connection) { return; @@ -8714,8 +9094,8 @@ var connection_manager_ConnectionManager = (function (_super) { this.state = newState; if (previousState !== newState) { var newStateDescription = newState; - if (newStateDescription === "connected") { - newStateDescription += " with new socket ID " + data.socket_id; + if (newStateDescription === 'connected') { + newStateDescription += ' with new socket ID ' + data.socket_id; } logger.debug('State changed', previousState + ' -> ' + newStateDescription); this.timeline.info({ state: newState, params: data }); @@ -8724,7 +9104,7 @@ var connection_manager_ConnectionManager = (function (_super) { } }; ConnectionManager.prototype.shouldRetry = function () { - return this.state === "connecting" || this.state === "connected"; + return this.state === 'connecting' || this.state === 'connected'; }; return ConnectionManager; }(dispatcher)); @@ -8734,6 +9114,7 @@ var connection_manager_ConnectionManager = (function (_super) { + var channels_Channels = (function () { function Channels() { this.channels = {}; @@ -8765,8 +9146,12 @@ var channels_Channels = (function () { /* harmony default export */ var channels = (channels_Channels); function createChannel(name, pusher) { if (name.indexOf('private-encrypted-') === 0) { - if (false) { var errorMsg; } - return factory.createEncryptedChannel(name, pusher); + if (pusher.config.nacl) { + return factory.createEncryptedChannel(name, pusher, pusher.config.nacl); + } + var errMsg = 'Tried to subscribe to a private-encrypted- channel but no nacl implementation available'; + var suffix = url_store.buildLogSuffix('encryptedChannelSupport'); + throw new UnsupportedFeature(errMsg + ". " + suffix); } else if (name.indexOf('private-') === 0) { return factory.createPrivateChannel(name, pusher); @@ -8806,8 +9191,8 @@ var Factory = { createPresenceChannel: function (name, pusher) { return new presence_channel(name, pusher); }, - createEncryptedChannel: function (name, pusher) { - return new encrypted_channel(name, pusher); + createEncryptedChannel: function (name, pusher, nacl) { + return new encrypted_channel(name, pusher, nacl); }, createTimelineSender: function (timeline, options) { return new timeline_sender(timeline, options); @@ -8863,7 +9248,7 @@ var sequential_strategy_SequentialStrategy = (function () { this.timeoutLimit = options.timeoutLimit; } SequentialStrategy.prototype.isSupported = function () { - return any(this.strategies, util.method("isSupported")); + return any(this.strategies, util.method('isSupported')); }; SequentialStrategy.prototype.connect = function (minPriority, callback) { var _this = this; @@ -8949,7 +9334,7 @@ var best_connected_ever_strategy_BestConnectedEverStrategy = (function () { this.strategies = strategies; } BestConnectedEverStrategy.prototype.isSupported = function () { - return any(this.strategies, util.method("isSupported")); + return any(this.strategies, util.method('isSupported')); }; BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { return connect(this.strategies, minPriority, function (i, runners) { @@ -9033,7 +9418,9 @@ var cached_strategy_CachedStrategy = (function () { } } var startTimestamp = util.now(); - var runner = strategies.pop().connect(minPriority, function cb(error, handshake) { + var runner = strategies + .pop() + .connect(minPriority, function cb(error, handshake) { if (error) { flushTransportCache(usingTLS); if (strategies.length > 0) { @@ -9065,7 +9452,7 @@ var cached_strategy_CachedStrategy = (function () { }()); /* harmony default export */ var cached_strategy = (cached_strategy_CachedStrategy); function getTransportCacheKey(usingTLS) { - return "pusherTransport" + (usingTLS ? "TLS" : "NonTLS"); + return 'pusherTransport' + (usingTLS ? 'TLS' : 'NonTLS'); } function fetchTransportCache(usingTLS) { var storage = node_runtime.getLocalStorage(); @@ -9197,26 +9584,26 @@ function testSupportsStrategy(strategy) { return strategy.isSupported(); }; } -var getDefaultStrategy = function (config, defineTransport) { +var getDefaultStrategy = function (config, baseOptions, defineTransport) { var definedTransports = {}; function defineTransportStrategy(name, type, priority, options, manager) { var transport = defineTransport(config, name, type, priority, options, manager); definedTransports[name] = transport; return transport; } - var ws_options = { - hostNonTLS: config.wsHost + ":" + config.wsPort, - hostTLS: config.wsHost + ":" + config.wssPort, + var ws_options = Object.assign({}, baseOptions, { + hostNonTLS: config.wsHost + ':' + config.wsPort, + hostTLS: config.wsHost + ':' + config.wssPort, httpPath: config.wsPath - }; + }); var wss_options = extend({}, ws_options, { useTLS: true }); - var http_options = { - hostNonTLS: config.httpHost + ":" + config.httpPort, - hostTLS: config.httpHost + ":" + config.httpsPort, + var http_options = Object.assign({}, baseOptions, { + hostNonTLS: config.httpHost + ':' + config.httpPort, + hostTLS: config.httpHost + ':' + config.httpsPort, httpPath: config.httpPath - }; + }); var timeouts = { loop: true, timeout: 15000, @@ -9225,25 +9612,33 @@ var getDefaultStrategy = function (config, defineTransport) { var ws_manager = new transport_manager({ lives: 2, minPingDelay: 10000, - maxPingDelay: config.activity_timeout + maxPingDelay: config.activityTimeout }); var streaming_manager = new transport_manager({ lives: 2, minPingDelay: 10000, - maxPingDelay: config.activity_timeout + maxPingDelay: config.activityTimeout }); - var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager); - var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager); - var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, http_options, streaming_manager); - var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, http_options); + var ws_transport = defineTransportStrategy('ws', 'ws', 3, ws_options, ws_manager); + var wss_transport = defineTransportStrategy('wss', 'ws', 3, wss_options, ws_manager); + var xhr_streaming_transport = defineTransportStrategy('xhr_streaming', 'xhr_streaming', 1, http_options, streaming_manager); + var xhr_polling_transport = defineTransportStrategy('xhr_polling', 'xhr_polling', 1, http_options); var ws_loop = new sequential_strategy([ws_transport], timeouts); var wss_loop = new sequential_strategy([wss_transport], timeouts); var streaming_loop = new sequential_strategy([xhr_streaming_transport], timeouts); var polling_loop = new sequential_strategy([xhr_polling_transport], timeouts); - var http_loop = new sequential_strategy([new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([streaming_loop, new delayed_strategy(polling_loop, { delay: 4000 })]), polling_loop)], timeouts); + var http_loop = new sequential_strategy([ + new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([ + streaming_loop, + new delayed_strategy(polling_loop, { delay: 4000 }) + ]), polling_loop) + ], timeouts); var wsStrategy; - if (config.useTLS) { - wsStrategy = new best_connected_ever_strategy([ws_loop, new delayed_strategy(http_loop, { delay: 2000 })]); + if (baseOptions.useTLS) { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(http_loop, { delay: 2000 }) + ]); } else { wsStrategy = new best_connected_ever_strategy([ @@ -9254,8 +9649,8 @@ var getDefaultStrategy = function (config, defineTransport) { } return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { ttl: 1800000, - timeline: config.timeline, - useTLS: config.useTLS + timeline: baseOptions.timeline, + useTLS: baseOptions.useTLS }); }; /* harmony default export */ var default_strategy = (getDefaultStrategy); @@ -9264,10 +9659,10 @@ var getDefaultStrategy = function (config, defineTransport) { /* harmony default export */ var transport_connection_initializer = (function () { var self = this; self.timeline.info(self.buildTimelineMessage({ - transport: self.name + (self.options.useTLS ? "s" : "") + transport: self.name + (self.options.useTLS ? 's' : '') })); if (self.hooks.isInitialized()) { - self.changeState("initialized"); + self.changeState('initialized'); } else { self.onClose(); @@ -9310,7 +9705,7 @@ var http_request_HTTPRequest = (function (_super) { node_runtime.addUnloadListener(this.unloader); this.xhr.open(this.method, this.url, true); if (this.xhr.setRequestHeader) { - this.xhr.setRequestHeader("Content-Type", "application/json"); + this.xhr.setRequestHeader('Content-Type', 'application/json'); } this.xhr.send(payload); }; @@ -9328,19 +9723,19 @@ var http_request_HTTPRequest = (function (_super) { while (true) { var chunk = this.advanceBuffer(data); if (chunk) { - this.emit("chunk", { status: status, data: chunk }); + this.emit('chunk', { status: status, data: chunk }); } else { break; } } if (this.isBufferTooLong(data)) { - this.emit("buffer_too_long"); + this.emit('buffer_too_long'); } }; HTTPRequest.prototype.advanceBuffer = function (buffer) { var unreadData = buffer.slice(this.position); - var endOfLinePosition = unreadData.indexOf("\n"); + var endOfLinePosition = unreadData.indexOf('\n'); if (endOfLinePosition !== -1) { this.position += endOfLinePosition + 1; return unreadData.slice(0, endOfLinePosition); @@ -9373,7 +9768,7 @@ var autoIncrement = 1; var http_socket_HTTPSocket = (function () { function HTTPSocket(hooks, url) { this.hooks = hooks; - this.session = randomNumber(1000) + "/" + randomString(8); + this.session = randomNumber(1000) + '/' + randomString(8); this.location = getLocation(url); this.readyState = state.CONNECTING; this.openStream(); @@ -9390,7 +9785,7 @@ var http_socket_HTTPSocket = (function () { HTTPSocket.prototype.sendRaw = function (payload) { if (this.readyState === state.OPEN) { try { - node_runtime.createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload); + node_runtime.createSocketRequest('POST', getUniqueURL(getSendURL(this.location, this.session))).start(payload); return true; } catch (e) { @@ -9405,7 +9800,6 @@ var http_socket_HTTPSocket = (function () { this.closeStream(); this.openStream(); }; - ; HTTPSocket.prototype.onClose = function (code, reason, wasClean) { this.closeStream(); this.readyState = state.CLOSED; @@ -9461,7 +9855,7 @@ var http_socket_HTTPSocket = (function () { } } else { - this.onClose(1006, "Server lost session", true); + this.onClose(1006, 'Server lost session', true); } }; HTTPSocket.prototype.onEvent = function (event) { @@ -9481,14 +9875,14 @@ var http_socket_HTTPSocket = (function () { }; HTTPSocket.prototype.openStream = function () { var _this = this; - this.stream = node_runtime.createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); - this.stream.bind("chunk", function (chunk) { + this.stream = node_runtime.createSocketRequest('POST', getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); + this.stream.bind('chunk', function (chunk) { _this.onChunk(chunk); }); - this.stream.bind("finished", function (status) { + this.stream.bind('finished', function (status) { _this.hooks.onFinished(_this, status); }); - this.stream.bind("buffer_too_long", function () { + this.stream.bind('buffer_too_long', function () { _this.reconnect(); }); try { @@ -9497,7 +9891,7 @@ var http_socket_HTTPSocket = (function () { catch (error) { util.defer(function () { _this.onError(error); - _this.onClose(1006, "Could not start streaming", false); + _this.onClose(1006, 'Could not start streaming', false); }); } }; @@ -9518,11 +9912,11 @@ function getLocation(url) { }; } function getSendURL(url, session) { - return url.base + "/" + session + "/xhr_send"; + return url.base + '/' + session + '/xhr_send'; } function getUniqueURL(url) { - var separator = (url.indexOf('?') === -1) ? "?" : "&"; - return url + separator + "t=" + (+new Date()) + "&n=" + autoIncrement++; + var separator = url.indexOf('?') === -1 ? '?' : '&'; + return url + separator + 't=' + +new Date() + '&n=' + autoIncrement++; } function replaceHost(url, hostname) { var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url); @@ -9543,16 +9937,16 @@ function randomString(length) { // CONCATENATED MODULE: ./src/core/http/http_streaming_socket.ts var http_streaming_socket_hooks = { getReceiveURL: function (url, session) { - return url.base + "/" + session + "/xhr_streaming" + url.queryString; + return url.base + '/' + session + '/xhr_streaming' + url.queryString; }, onHeartbeat: function (socket) { - socket.sendRaw("[]"); + socket.sendRaw('[]'); }, sendHeartbeat: function (socket) { - socket.sendRaw("[]"); + socket.sendRaw('[]'); }, onFinished: function (socket, status) { - socket.onClose(1006, "Connection interrupted (" + status + ")", false); + socket.onClose(1006, 'Connection interrupted (' + status + ')', false); } }; /* harmony default export */ var http_streaming_socket = (http_streaming_socket_hooks); @@ -9560,19 +9954,19 @@ var http_streaming_socket_hooks = { // CONCATENATED MODULE: ./src/core/http/http_polling_socket.ts var http_polling_socket_hooks = { getReceiveURL: function (url, session) { - return url.base + "/" + session + "/xhr" + url.queryString; + return url.base + '/' + session + '/xhr' + url.queryString; }, onHeartbeat: function () { }, sendHeartbeat: function (socket) { - socket.sendRaw("[]"); + socket.sendRaw('[]'); }, onFinished: function (socket, status) { if (status === 200) { socket.reconnect(); } else { - socket.onClose(1006, "Connection interrupted (" + status + ")", false); + socket.onClose(1006, 'Connection interrupted (' + status + ')', false); } } }; @@ -9595,7 +9989,7 @@ var http_xhr_request_hooks = { if (xhr.responseText && xhr.responseText.length > 0) { socket.onChunk(xhr.status, xhr.responseText); } - socket.emit("finished", xhr.status); + socket.emit('finished', xhr.status); socket.close(); break; } @@ -9652,10 +10046,12 @@ var Isomorphic = { return undefined; }, getClientFeatures: function () { - return keys(filterObject({ "ws": transports.ws }, function (t) { return t.isSupported({}); })); + return keys(filterObject({ ws: transports.ws }, function (t) { + return t.isSupported({}); + })); }, getProtocol: function () { - return "http:"; + return 'http:'; }, isXHRSupported: function () { return true; @@ -9665,7 +10061,7 @@ var Isomorphic = { return this.HTTPFactory.createXHR(method, url); } else { - throw "Cross-origin HTTP requests are not supported"; + throw 'Cross-origin HTTP requests are not supported'; } }, createXHR: function () { @@ -9722,8 +10118,8 @@ var net_info_Network = new NetInfo(); var ajax = function (context, socketId, callback) { var self = this, xhr; xhr = node_runtime.createXHR(); - xhr.open("POST", self.options.authEndpoint, true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.open('POST', self.options.authEndpoint, true); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); for (var headerName in this.authOptions.headers) { xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]); } @@ -9736,14 +10132,15 @@ var ajax = function (context, socketId, callback) { parsed = true; } catch (e) { - callback(true, 'JSON returned from auth endpoint was invalid, yet status code was 200. Data was: ' + xhr.responseText); + callback(true, 'JSON returned from auth endpoint was invalid, yet status code was 200. Data was: ' + + xhr.responseText); } if (parsed) { callback(false, data); } } else { - var suffix = url_store.buildLogSuffix("authenticationEndpoint"); + var suffix = url_store.buildLogSuffix('authenticationEndpoint'); logger.error('Unable to retrieve auth string from auth endpoint - ' + ("received status " + xhr.status + " from " + self.options.authEndpoint + ". ") + ("Clients must be authenticated to join private or presence channels. " + suffix)); @@ -9762,12 +10159,12 @@ var ajax = function (context, socketId, callback) { var getAgent = function (sender, useTLS) { return function (data, callback) { - var scheme = "http" + (useTLS ? "s" : "") + "://"; + var scheme = 'http' + (useTLS ? 's' : '') + '://'; var url = scheme + (sender.host || sender.options.host) + sender.options.path; var query = buildQueryString(data); - url += ("/" + 2 + "?" + query); + url += '/' + 2 + '?' + query; var xhr = node_runtime.createXHR(); - xhr.open("GET", url, true); + xhr.open('GET', url, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { var status_1 = xhr.status, responseText = xhr.responseText; @@ -9881,7 +10278,7 @@ var timeline_Timeline = (function () { session: this.session, bundle: this.sent + 1, key: this.key, - lib: "js", + lib: 'js', version: this.options.version, cluster: this.options.cluster, features: this.options.features, @@ -9935,7 +10332,7 @@ var transport_strategy_TransportStrategy = (function () { var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options); var handshake = null; var onInitialized = function () { - transport.unbind("initialized", onInitialized); + transport.unbind('initialized', onInitialized); transport.connect(); }; var onOpen = function () { @@ -9956,15 +10353,15 @@ var transport_strategy_TransportStrategy = (function () { callback(new TransportClosed(serializedTransport)); }; var unbindListeners = function () { - transport.unbind("initialized", onInitialized); - transport.unbind("open", onOpen); - transport.unbind("error", onError); - transport.unbind("closed", onClosed); + transport.unbind('initialized', onInitialized); + transport.unbind('open', onOpen); + transport.unbind('error', onError); + transport.unbind('closed', onClosed); }; - transport.bind("initialized", onInitialized); - transport.bind("open", onOpen); - transport.bind("error", onError); - transport.bind("closed", onClosed); + transport.bind('initialized', onInitialized); + transport.bind('open', onOpen); + transport.bind('error', onError); + transport.bind('closed', onClosed); transport.initialize(); return { abort: function () { @@ -10025,12 +10422,8 @@ var strategy_builder_defineTransport = function (config, name, type, priority, o arrayIndexOf(config.disabledTransports, name) === -1); var transport; if (enabled) { - transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, extend({ - key: config.key, - useTLS: config.useTLS, - timeline: config.timeline, - ignoreNullOrigin: config.ignoreNullOrigin - }, options)); + options = Object.assign({ ignoreNullOrigin: config.ignoreNullOrigin }, options); + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options); } else { transport = strategy_builder_UnsupportedStrategy; @@ -10056,30 +10449,83 @@ var strategy_builder_UnsupportedStrategy = { // CONCATENATED MODULE: ./src/core/config.ts -var getGlobalConfig = function () { - return { - wsHost: defaults.host, - wsPort: defaults.ws_port, - wssPort: defaults.wss_port, - wsPath: defaults.ws_path, - httpHost: defaults.sockjs_host, - httpPort: defaults.sockjs_http_port, - httpsPort: defaults.sockjs_https_port, - httpPath: defaults.sockjs_path, - statsHost: defaults.stats_host, - authEndpoint: defaults.channel_auth_endpoint, - authTransport: defaults.channel_auth_transport, - activity_timeout: defaults.activity_timeout, - pong_timeout: defaults.pong_timeout, - unavailable_timeout: defaults.unavailable_timeout - }; -}; -var getClusterConfig = function (clusterName) { - return { - wsHost: 'ws-' + clusterName + '.pusher.com', - httpHost: 'sockjs-' + clusterName + '.pusher.com' - }; -}; + +function getConfig(opts) { + var config = { + activityTimeout: opts.activityTimeout || defaults.activityTimeout, + authEndpoint: opts.authEndpoint || defaults.authEndpoint, + authTransport: opts.authTransport || defaults.authTransport, + cluster: opts.cluster || defaults.cluster, + httpPath: opts.httpPath || defaults.httpPath, + httpPort: opts.httpPort || defaults.httpPort, + httpsPort: opts.httpsPort || defaults.httpsPort, + pongTimeout: opts.pongTimeout || defaults.pongTimeout, + statsHost: opts.statsHost || defaults.stats_host, + unavailableTimeout: opts.unavailableTimeout || defaults.unavailableTimeout, + wsPath: opts.wsPath || defaults.wsPath, + wsPort: opts.wsPort || defaults.wsPort, + wssPort: opts.wssPort || defaults.wssPort, + enableStats: getEnableStatsConfig(opts), + httpHost: getHttpHost(opts), + useTLS: shouldUseTLS(opts), + wsHost: getWebsocketHost(opts) + }; + if ('auth' in opts) + config.auth = opts.auth; + if ('authorizer' in opts) + config.authorizer = opts.authorizer; + if ('disabledTransports' in opts) + config.disabledTransports = opts.disabledTransports; + if ('enabledTransports' in opts) + config.enabledTransports = opts.enabledTransports; + if ('ignoreNullOrigin' in opts) + config.ignoreNullOrigin = opts.ignoreNullOrigin; + if ('timelineParams' in opts) + config.timelineParams = opts.timelineParams; + if ('nacl' in opts) { + config.nacl = opts.nacl; + } + return config; +} +function getHttpHost(opts) { + if (opts.httpHost) { + return opts.httpHost; + } + if (opts.cluster) { + return "sockjs-" + opts.cluster + ".pusher.com"; + } + return defaults.httpHost; +} +function getWebsocketHost(opts) { + if (opts.wsHost) { + return opts.wsHost; + } + if (opts.cluster) { + return getWebsocketHostFromCluster(opts.cluster); + } + return getWebsocketHostFromCluster(defaults.cluster); +} +function getWebsocketHostFromCluster(cluster) { + return "ws-" + cluster + ".pusher.com"; +} +function shouldUseTLS(opts) { + if (node_runtime.getProtocol() === 'https:') { + return true; + } + else if (opts.forceTLS === false) { + return false; + } + return true; +} +function getEnableStatsConfig(opts) { + if ('enableStats' in opts) { + return opts.enableStats; + } + if ('disableStats' in opts) { + return !opts.disableStats; + } + return false; +} // CONCATENATED MODULE: ./src/core/pusher.ts @@ -10103,8 +10549,11 @@ var pusher_Pusher = (function () { var suffix = url_store.buildLogSuffix('javascriptQuickStart'); logger.warn("You should always specify a cluster when connecting. " + suffix); } + if ('disableStats' in options) { + logger.warn('The disableStats option is deprecated in favor of enableStats'); + } this.key = app_key; - this.config = extend(getGlobalConfig(), options.cluster ? getClusterConfig(options.cluster) : {}, options); + this.config = getConfig(options); this.channels = factory.createChannels(); this.global_emitter = new dispatcher(); this.sessionID = Math.floor(Math.random() * 1000000000); @@ -10116,23 +10565,23 @@ var pusher_Pusher = (function () { level: timeline_level.INFO, version: defaults.VERSION }); - if (!this.config.disableStats) { + if (this.config.enableStats) { this.timelineSender = factory.createTimelineSender(this.timeline, { host: this.config.statsHost, path: '/timeline/v2/' + node_runtime.TimelineTransport.name }); } var getStrategy = function (options) { - var config = extend({}, _this.config, options); - return node_runtime.getDefaultStrategy(config, strategy_builder_defineTransport); + return node_runtime.getDefaultStrategy(_this.config, options, strategy_builder_defineTransport); }; - this.connection = factory.createConnectionManager(this.key, extend({ + this.connection = factory.createConnectionManager(this.key, { getStrategy: getStrategy, timeline: this.timeline, - activityTimeout: this.config.activity_timeout, - pongTimeout: this.config.pong_timeout, - unavailableTimeout: this.config.unavailable_timeout - }, this.config, { useTLS: this.shouldUseTLS() })); + activityTimeout: this.config.activityTimeout, + pongTimeout: this.config.pongTimeout, + unavailableTimeout: this.config.unavailableTimeout, + useTLS: Boolean(this.config.useTLS) + }); this.connection.bind('connected', function () { _this.subscribeAll(); if (_this.timelineSender) { @@ -10258,15 +10707,7 @@ var pusher_Pusher = (function () { return this.connection.send_event(event_name, data, channel); }; Pusher.prototype.shouldUseTLS = function () { - if (node_runtime.getProtocol() === 'https:') { - return true; - } - else if (this.config.forceTLS === true) { - return true; - } - else { - return Boolean(this.config.encrypted); - } + return this.config.useTLS; }; Pusher.instances = []; Pusher.isReady = false; @@ -10277,7 +10718,7 @@ var pusher_Pusher = (function () { Pusher.auth_callbacks = node_runtime.auth_callbacks; return Pusher; }()); -/* harmony default export */ var core_pusher = __webpack_exports__["default"] = (pusher_Pusher); +/* harmony default export */ var core_pusher = (pusher_Pusher); function checkAppKey(key) { if (key === null || key === undefined) { throw 'You must pass your app key when you instantiate Pusher.'; @@ -10285,6 +10726,40 @@ function checkAppKey(key) { } node_runtime.setup(pusher_Pusher); +// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js +var nacl_fast = __webpack_require__(20); + +// CONCATENATED MODULE: ./src/core/pusher-with-encryption.ts +var pusher_with_encryption_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var pusher_with_encryption_PusherWithEncryption = (function (_super) { + pusher_with_encryption_extends(PusherWithEncryption, _super); + function PusherWithEncryption(app_key, options) { + var _this = this; + core_pusher.logToConsole = PusherWithEncryption.logToConsole; + core_pusher.log = PusherWithEncryption.log; + options = options || {}; + options.nacl = nacl_fast; + _this = _super.call(this, app_key, options) || this; + return _this; + } + return PusherWithEncryption; +}(core_pusher)); +/* harmony default export */ var pusher_with_encryption = __webpack_exports__["default"] = (pusher_with_encryption_PusherWithEncryption); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/dist/react-native/pusher.js b/dist/react-native/pusher.js index 5e1732974..055cd0f57 100644 --- a/dist/react-native/pusher.js +++ b/dist/react-native/pusher.js @@ -1,8 +1,8 @@ /*! - * Pusher JavaScript Library v5.1.1 + * Pusher JavaScript Library v6.0.0 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -module.exports=function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e){t.exports=require("@react-native-community/netinfo")},function(t,e,n){t.exports=n(2).default},function(t,e,n){"use strict";n.r(e);for(var o=String.fromCharCode,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={},s=0,c=i.length;s>>6)+o(128|63&e):o(224|e>>>12&15)+o(128|e>>>6&63)+o(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},p=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[i.charAt(n>>>18),i.charAt(n>>>12&63),e>=2?"=":i.charAt(n>>>6&63),e>=1?"=":i.charAt(63&n)].join("")},l=global.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,p)},f=function(){function t(t,e,n,o){var i=this;this.clear=e,this.timer=t((function(){i.timer&&(i.timer=o(i.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),d=(a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function y(t){global.clearTimeout(t)}function b(t){global.clearInterval(t)}var g=function(t){function e(e,n){return t.call(this,setTimeout,y,e,(function(t){return n(),null}))||this}return d(e,t),e}(f),v=function(t){function e(e,n){return t.call(this,setInterval,b,e,(function(t){return n(),t}))||this}return d(e,t),e}(f),m={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new g(0,t)},method:function(t){for(var e=[],n=1;n0)for(o=0;o=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},Z=K,tt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),et=function(t){function e(e,n){var o=t.call(this)||this;return o.id=e,o.transport=n,o.activityTimeout=n.activityTimeout,o.bindListeners(),o}return tt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var o={event:t,data:e};return n&&(o.channel=n),F.debug("Event sent",o),this.send(Z.encodeMessage(o))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=Z.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(F.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){w(e,(function(e,n){t.transport.unbind(n,e)}))};w(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=Z.getCloseAction(t),n=Z.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(z),nt=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=Z.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new et(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=Z.getCloseAction(e)||"backoff",o=Z.getCloseError(e);t.finish(n,{error:o})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(_({transport:this.transport,action:t},e))},t}(),ot=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===ie.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||ie.getAuthorizers(),t.authorizers[this.type].call(this,ie,e,n)},t}(),it=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(ie.TimelineTransport.getAgent(this,t),e)},t}(),rt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),st=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),ct=(function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}rt(e,t)}(Error),function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error)),at=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),ut=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),ht=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),pt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return rt(e,t),e}(Error),lt={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"}}},ft=function(t){var e,n=lt.urls[t];return n?(n.fullUrl?e=n.fullUrl:n.path&&(e=lt.baseUrl+n.path),e?"See: "+e:""):""},dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),yt=function(t){function e(e,n){var o=t.call(this,(function(t,n){F.debug("No callbacks on "+e+" for "+t)}))||this;return o.name=e,o.pusher=n,o.subscribed=!1,o.subscriptionPending=!1,o.subscriptionCancelled=!1,o}return dt(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new st("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=ft("triggeringClientEvents");F.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(F.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(z),bt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),gt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return bt(e,t),e.prototype.authorize=function(t,e){return Ct.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(yt),vt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;w(this.members,(function(n,o){t(e.get(o))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),mt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),_t=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.members=new vt,o}return mt(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var i=ft("authenticationEndpoint");return F.error("Invalid auth response for channel '"+o.name+"',expected 'channel_data' field. "+i),void n("Invalid auth response")}var r=JSON.parse(e.channel_data);o.members.setMyID(r.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,o={};t.user_id&&(o.user_id=t.user_id),this.emit(e,n,o)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var o=this.members.addMember(n);this.emit("pusher:member_added",o);break;case"pusher_internal:member_removed":var i=this.members.removeMember(n);i&&this.emit("pusher:member_removed",i)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(gt),St=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),kt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return St(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var i=e.shared_secret;if(i)o.key=(void 0)(i),delete e.shared_secret,n(!1,e);else{var r="No shared_secret key in auth payload for encrypted channel: "+o.name;n(!0,r)}}}))},e.prototype.trigger=function(t,e){throw new ut("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,o=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,o):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var o=(void 0)(e.ciphertext);if(o.length<(void 0).overheadLength)F.error("Expected encrypted event ciphertext length to be "+(void 0).overheadLength+", got: "+o.length);else{var i=(void 0)(e.nonce);if(i.length<(void 0).nonceLength)F.error("Expected encrypted event nonce length to be "+(void 0).nonceLength+", got: "+i.length);else{var r=(void 0).open(o,i,this.key);if(null===r)return F.debug("Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint..."),void this.authorize(this.pusher.connection.socket_id,(function(e,s){e?F.error("Failed to make a request to the authEndpoint: "+s+". Unable to fetch new key, so dropping encrypted event"):null!==(r=(void 0).open(o,i,n.key))?n.emitJSON(t,(void 0)(r)):F.error("Failed to decrypt event with new key. Dropping encrypted event")}));this.emitJSON(t,(void 0)(r))}}}else F.error("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: "+e);else F.debug("Received encrypted event before key has been retrieved from the authEndpoint")},e.prototype.emitJSON=function(t,e){try{this.emit(t,JSON.parse(e))}catch(n){this.emit(t,e)}return this},e}(gt),wt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Tt=function(t){function e(e,n){var o=t.call(this)||this;o.key=e,o.options=n||{},o.state="initialized",o.connection=null,o.usingTLS=!!n.useTLS,o.timeline=o.options.timeline,o.errorCallbacks=o.buildErrorCallbacks(),o.connectionCallbacks=o.buildConnectionCallbacks(o.errorCallbacks),o.handshakeCallbacks=o.buildHandshakeCallbacks(o.errorCallbacks);var i=ie.getNetwork();return i.bind("online",(function(){o.timeline.info({netinfo:"online"}),"connecting"!==o.state&&"unavailable"!==o.state||o.retryIn(0)})),i.bind("offline",(function(){o.timeline.info({netinfo:"offline"}),o.connection&&o.sendActivityCheck()})),o.updateStrategy(),o}return wt(e,t),e.prototype.connect=function(){this.connection||this.runner||(this.strategy.isSupported()?(this.updateState("connecting"),this.startConnecting(),this.setUnavailableTimer()):this.updateState("failed"))},e.prototype.send=function(t){return!!this.connection&&this.connection.send(t)},e.prototype.send_event=function(t,e,n){return!!this.connection&&this.connection.send_event(t,e,n)},e.prototype.disconnect=function(){this.disconnectInternally(),this.updateState("disconnected")},e.prototype.isUsingTLS=function(){return this.usingTLS},e.prototype.startConnecting=function(){var t=this,e=function(n,o){n?t.runner=t.strategy.connect(0,e):"error"===o.action?(t.emit("error",{type:"HandshakeError",error:o.error}),t.timeline.error({handshakeError:o.error})):(t.abortConnecting(),t.handshakeCallbacks[o.action](o))};this.runner=this.strategy.connect(0,e)},e.prototype.abortConnecting=function(){this.runner&&(this.runner.abort(),this.runner=null)},e.prototype.disconnectInternally=function(){(this.abortConnecting(),this.clearRetryTimer(),this.clearUnavailableTimer(),this.connection)&&this.abandonConnection().close()},e.prototype.updateStrategy=function(){this.strategy=this.options.getStrategy({key:this.key,timeline:this.timeline,useTLS:this.usingTLS})},e.prototype.retryIn=function(t){var e=this;this.timeline.info({action:"retry",delay:t}),t>0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new g(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new g(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new g(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new g(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return _({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return _({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var o=t;"connected"===o&&(o+=" with new socket ID "+e.socket_id),F.debug("State changed",n+" -> "+o),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(z),Ot=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){throw new ut("Encrypted channels are not yet supported when using React Native builds.")}return 0===t.indexOf("private-")?Ct.createPrivateChannel(t,e):0===t.indexOf("presence-")?Ct.createPresenceChannel(t,e):Ct.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return w(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){w(this.channels,(function(t){t.disconnect()}))},t}();var Ct={createChannels:function(){return new Ot},createConnectionManager:function(t,e){return new Tt(t,e)},createChannel:function(t,e){return new yt(t,e)},createPrivateChannel:function(t,e){return new gt(t,e)},createPresenceChannel:function(t,e){return new _t(t,e)},createEncryptedChannel:function(t,e){return new kt(t,e)},createTimelineSender:function(t,e){return new it(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new ot(t,e)},createHandshake:function(t,e){return new nt(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new $(t,e,n)}},Pt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Ct.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),Et=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return L(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,o=this.strategies,i=0,r=this.timeout,s=null,c=function(a,u){u?e(null,u):(i+=1,n.loop&&(i%=o.length),i0&&(i=new g(n.timeout,(function(){r.abort(),o(!0)}))),r=t.connect(e,(function(t,e){t&&i&&i.isRunning()&&!n.failFast||(i&&i.ensureAborted(),o(t,e))})),{abort:function(){i&&i.ensureAborted(),r.abort()},forceMinPriority:function(t){r.forceMinPriority(t)}}},t}(),Lt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return L(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var o=C(t,(function(t,o,i,r){return t.connect(e,n(o,r))}));return{abort:function(){O(o,At)},forceMinPriority:function(t){O(o,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(o,i){n[t].error=o,o?function(t){return function(t,e){for(var n=0;n=m.now()){var r=this.transports[o.transport];r&&(this.timeline.info({cached:!0,transport:o.transport,latency:o.latency}),i.push(new Et([r],{timeout:2*o.latency+1e3,failFast:!0})))}var s=m.now(),c=i.pop().connect(t,(function o(r,a){r?(jt(n),i.length>0?(s=m.now(),c=i.pop().connect(t,o)):e(r)):(!function(t,e,n){var o=ie.getLocalStorage();if(o)try{o[Rt(t)]=R({timestamp:m.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,m.now()-s),e(null,a))}));return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function Rt(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function jt(t){var e=ie.getLocalStorage();if(e)try{delete e[Rt(t)]}catch(t){}}var It=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,o=this.strategy,i=new g(this.options.delay,(function(){n=o.connect(t,e)}));return{abort:function(){i.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),Nt=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),Mt=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,o){o&&n.abort(),e(t,o)}));return n},t}();function Ht(t){return function(){return t.isSupported()}}var Dt,Ut=function(t,e){var n={};function o(o,i,r,s,c){var a=e(t,o,i,r,s,c);return n[o]=a,a}var i,r={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},s=_({},r,{useTLS:!0}),c={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},a={loop:!0,timeout:15e3,timeoutLimit:6e4},u=new Pt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),h=new Pt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),p=o("ws","ws",3,r,u),l=o("wss","ws",3,s,u),f=o("xhr_streaming","xhr_streaming",1,c,h),d=o("xhr_polling","xhr_polling",1,c),y=new Et([p],a),b=new Et([l],a),g=new Et([f],a),v=new Et([d],a),m=new Et([new Nt(Ht(g),new Lt([g,new It(v,{delay:4e3})]),v)],a);return i=t.useTLS?new Lt([y,new It(m,{delay:2e3})]):new Lt([y,new It(b,{delay:2e3}),new It(m,{delay:5e3})]),new xt(new Mt(new Nt(Ht(p),i,m)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})},zt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Ft=function(t){function e(e,n,o){var i=t.call(this)||this;return i.hooks=e,i.method=n,i.url=o,i}return zt(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},ie.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(ie.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(z);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(Dt||(Dt={}));var qt=Dt,Bt=1;function Jt(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+Bt++}function Wt(t){return Math.floor(Math.random()*t)}var Xt=function(){function t(t,e){this.hooks=t,this.session=Wt(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},Yt={getDefaultStrategy:Ut,Transports:Y,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(Gt,t)},createPollingSocket:function(t){return this.createSocket(Qt,t)},createSocket:function(t,e){return new Xt(t,e)},createXHR:function(t,e){return this.createRequest(Vt,t,e)},createRequest:function(t,e,n){return new Ft(t,e,n)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return T(E({ws:Y.ws},(function(t){return t.isSupported({})})))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},$t=n(0),Kt=n.n($t),Zt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}();function te(t){return"none"!==t.type.toLowerCase()}var ee,ne=new(function(t){function e(){var e=t.call(this)||this;return e.online=!0,Kt.a.fetch().then((function(t){e.online=te(t)})),Kt.a.addEventListener((function(t){var n=te(t);e.online!==n&&(e.online=n,e.online?e.emit("online"):e.emit("offline"))})),e}return Zt(e,t),e.prototype.isOnline=function(){return this.online},e}(z)),oe=function(t,e,n){var o,i=this;for(var r in(o=ie.createXHR()).open("POST",i.options.authEndpoint,!0),o.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)o.setRequestHeader(r,this.authOptions.headers[r]);return o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status){var t,e=!1;try{t=JSON.parse(o.responseText),e=!0}catch(t){n(!0,"JSON returned from auth endpoint was invalid, yet status code was 200. Data was: "+o.responseText)}e&&n(!1,t)}else{var r=ft("authenticationEndpoint");F.error("Unable to retrieve auth string from auth endpoint - received status "+o.status+" from "+i.options.authEndpoint+". Clients must be authenticated to join private or presence channels. "+r),n(!0,o.status)}},o.send(this.composeQuery(e)),o},ie={getDefaultStrategy:Yt.getDefaultStrategy,Transports:Yt.Transports,setup:Yt.setup,getProtocol:Yt.getProtocol,isXHRSupported:Yt.isXHRSupported,getLocalStorage:Yt.getLocalStorage,createXHR:Yt.createXHR,createWebSocket:Yt.createWebSocket,addUnloadListener:Yt.addUnloadListener,removeUnloadListener:Yt.removeUnloadListener,transportConnectionInitializer:Yt.transportConnectionInitializer,createSocketRequest:Yt.createSocketRequest,HTTPFactory:Yt.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,e){return function(n,o){var i="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path;i+="/2?"+x(n);var r=ie.createXHR();r.open("GET",i,!0),r.onreadystatechange=function(){if(4===r.readyState){var e=r.status,n=r.responseText;if(200!==e)return void F.debug("TimelineSender Error: received "+e+" from stats.pusher.com");try{var o=JSON.parse(n).host}catch(t){F.debug("TimelineSenderError: invalid response "+n)}o&&(t.host=o)}},r.send()}}},getAuthorizers:function(){return{ajax:oe}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return ne}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(ee||(ee={}));var re=ee,se=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(_({},e,{timestamp:m.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(re.ERROR,t)},t.prototype.info=function(t){this.log(re.INFO,t)},t.prototype.debug=function(t){this.log(re.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,o=_({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,(function(t,o){t||n.sent++,e&&e(t,o)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),ce=function(){function t(t,e,n,o){this.name=t,this.priority=e,this.transport=n,this.options=o||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return ae(new pt,e);if(this.priority0)for(o=0;o=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},T=k,C=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),O=function(t){function n(n,e){var r=t.call(this)||this;return r.id=n,r.transport=e,r.activityTimeout=e.activityTimeout,r.bindListeners(),r}return C(n,t),n.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},n.prototype.send=function(t){return this.transport.send(t)},n.prototype.send_event=function(t,n,e){var r={event:t,data:n};return e&&(r.channel=e),p.a.debug("Event sent",r),this.send(T.encodeMessage(r))},n.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},n.prototype.close=function(){this.transport.close()},n.prototype.bindListeners=function(){var t=this,n={message:function(n){var e;try{e=T.decodeMessage(n)}catch(e){t.emit("error",{type:"MessageParseError",error:e,data:n.data})}if(void 0!==e){switch(p.a.debug("Event recd",e),e.event){case"pusher:error":t.emit("error",{type:"PusherError",data:e.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",e)}},activity:function(){t.emit("activity")},error:function(n){t.emit("error",{type:"WebSocketError",error:n})},closed:function(n){e(),n&&n.code&&t.handleCloseEvent(n),t.transport=null,t.emit("closed")}},e=function(){r.k(n,(function(n,e){t.transport.unbind(e,n)}))};r.k(n,(function(n,e){t.transport.bind(e,n)}))},n.prototype.handleCloseEvent=function(t){var n=T.getCloseAction(t),e=T.getCloseError(t);e&&this.emit("error",e),n&&this.emit(n,{action:n,error:e})},n}(f.a),P=function(){function t(t,n){this.transport=t,this.callback=n,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(n){var e;t.unbindListeners();try{e=T.processHandshake(n)}catch(n){return t.finish("error",{error:n}),void t.transport.close()}"connected"===e.action?t.finish("connected",{connection:new O(e.id,t.transport),activityTimeout:e.activityTimeout}):(t.finish(e.action,{error:e.error}),t.transport.close())},this.onClosed=function(n){t.unbindListeners();var e=T.getCloseAction(n)||"backoff",r=T.getCloseError(n);t.finish(e,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,n){this.callback(r.f({transport:this.transport,action:t},n))},t}(),A=function(){function t(t,n){this.channel=t;var e=n.authTransport;if(void 0===Ut.getAuthorizers()[e])throw"'"+e+"' is not a recognized auth transport";this.type=e,this.options=n,this.authOptions=n.auth||{}}return t.prototype.composeQuery=function(t){var n="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var e in this.authOptions.params)n+="&"+encodeURIComponent(e)+"="+encodeURIComponent(this.authOptions.params[e]);return n},t.prototype.authorize=function(n,e){t.authorizers=t.authorizers||Ut.getAuthorizers(),t.authorizers[this.type].call(this,Ut,n,e)},t}(),E=function(){function t(t,n){this.timeline=t,this.options=n||{}}return t.prototype.send=function(t,n){this.timeline.isEmpty()||this.timeline.send(Ut.TimelineTransport.getAgent(this,t),n)},t}(),x=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),L=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return x(n,t),n}(Error),U=(function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}x(n,t)}(Error),function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return x(n,t),n}(Error)),M=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return x(n,t),n}(Error),R=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return x(n,t),n}(Error),j=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return x(n,t),n}(Error),I=function(t){function n(n){var e=this.constructor,r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return x(n,t),n}(Error),N={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"},encryptedChannelSupport:{fullUrl:"https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support"}}},B=function(t){var n,e=N.urls[t];return e?(e.fullUrl?n=e.fullUrl:e.path&&(n=N.baseUrl+e.path),n?"See: "+n:""):""},D=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),H=function(t){function n(n,e){var r=t.call(this,(function(t,e){p.a.debug("No callbacks on "+n+" for "+t)}))||this;return r.name=n,r.pusher=e,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return D(n,t),n.prototype.authorize=function(t,n){return n(!1,{auth:""})},n.prototype.trigger=function(t,n){if(0!==t.indexOf("client-"))throw new L("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var e=B("triggeringClientEvents");p.a.warn("Client event triggered before channel 'subscription_succeeded' event . "+e)}return this.pusher.send_event(t,n,this.name)},n.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},n.prototype.handleEvent=function(t){var n=t.event,e=t.data;if("pusher_internal:subscription_succeeded"===n)this.handleSubscriptionSucceededEvent(t);else if(0!==n.indexOf("pusher_internal:")){this.emit(n,e,{})}},n.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},n.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(n,e){n?(p.a.error(e),t.emit("pusher:subscription_error",e)):(e=e,t.pusher.send_event("pusher:subscribe",{auth:e.auth,channel_data:e.channel_data,channel:t.name}))})))},n.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},n.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},n.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},n}(f.a),z=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),F=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return z(n,t),n.prototype.authorize=function(t,n){return tt.createAuthorizer(this,this.pusher.config).authorize(t,n)},n}(H),q=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var n=this;r.k(this.members,(function(e,r){t(n.get(r))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var n=this.get(t.user_id);return n&&(delete this.members[t.user_id],this.count--),n},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),Y=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),K=function(t){function n(n,e){var r=t.call(this,n,e)||this;return r.members=new q,r}return Y(n,t),n.prototype.authorize=function(n,e){var r=this;t.prototype.authorize.call(this,n,(function(t,n){if(!t){if(void 0===(n=n).channel_data){var o=B("authenticationEndpoint");return p.a.error("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void e("Invalid auth response")}var i=JSON.parse(n.channel_data);r.members.setMyID(i.user_id)}e(t,n)}))},n.prototype.handleEvent=function(t){var n=t.event;if(0===n.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var e=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(n,e,r)}},n.prototype.handleInternalEvent=function(t){var n=t.event,e=t.data;switch(n){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(e);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(e);o&&this.emit("pusher:member_removed",o)}},n.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},n.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},n}(F),J=e(9),X=e(7),W=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),G=function(t){function n(n,e,r){var o=t.call(this,n,e)||this;return o.key=null,o.nacl=r,o}return W(n,t),n.prototype.authorize=function(n,e){var r=this;t.prototype.authorize.call(this,n,(function(t,n){if(t)e(!0,n);else{var o=n.shared_secret;if(o)r.key=Object(X.decode)(o),delete n.shared_secret,e(!1,n);else{var i="No shared_secret key in auth payload for encrypted channel: "+r.name;e(!0,i)}}}))},n.prototype.trigger=function(t,n){throw new R("Client events are not currently supported for encrypted channels")},n.prototype.handleEvent=function(n){var e=n.event,r=n.data;0!==e.indexOf("pusher_internal:")&&0!==e.indexOf("pusher:")?this.handleEncryptedEvent(e,r):t.prototype.handleEvent.call(this,n)},n.prototype.handleEncryptedEvent=function(t,n){var e=this;if(this.key)if(n.ciphertext&&n.nonce){var r=Object(X.decode)(n.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new V.a(t||0,(function(){n.disconnectInternally(),n.connect()}))},n.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},n.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new V.a(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},n.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},n.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new V.a(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},n.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new V.a(this.activityTimeout,(function(){t.sendActivityCheck()})))},n.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},n.prototype.buildConnectionCallbacks=function(t){var n=this;return r.f({},t,{message:function(t){n.resetActivityCheck(),n.emit("message",t)},ping:function(){n.send_event("pusher:pong",{})},activity:function(){n.resetActivityCheck()},error:function(t){n.emit("error",{type:"WebSocketError",error:t})},closed:function(){n.abandonConnection(),n.shouldRetry()&&n.retryIn(1e3)}})},n.prototype.buildHandshakeCallbacks=function(t){var n=this;return r.f({},t,{connected:function(t){n.activityTimeout=Math.min(n.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),n.clearUnavailableTimer(),n.setConnection(t.connection),n.socket_id=n.connection.id,n.updateState("connected",{socket_id:n.socket_id})}})},n.prototype.buildErrorCallbacks=function(){var t=this,n=function(n){return function(e){e.error&&t.emit("error",{type:"WebSocketError",error:e.error}),n(e)}};return{tls_only:n((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:n((function(){t.disconnect()})),backoff:n((function(){t.retryIn(1e3)})),retry:n((function(){t.retryIn(0)}))}},n.prototype.setConnection=function(t){for(var n in this.connection=t,this.connectionCallbacks)this.connection.bind(n,this.connectionCallbacks[n]);this.resetActivityCheck()},n.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var n=this.connection;return this.connection=null,n}},n.prototype.updateState=function(t,n){var e=this.state;if(this.state=t,e!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+n.socket_id),p.a.debug("State changed",e+" -> "+r),this.timeline.info({state:t,params:n}),this.emit("state_change",{previous:e,current:t}),this.emit(t,n)}},n.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},n}(f.a),$=function(){function t(){this.channels={}}return t.prototype.add=function(t,n){return this.channels[t]||(this.channels[t]=function(t,n){if(0===t.indexOf("private-encrypted-")){if(n.config.nacl)return tt.createEncryptedChannel(t,n,n.config.nacl);var e=B("encryptedChannelSupport");throw new R("Tried to subscribe to a private-encrypted- channel but no nacl implementation available. "+e)}return 0===t.indexOf("private-")?tt.createPrivateChannel(t,n):0===t.indexOf("presence-")?tt.createPresenceChannel(t,n):tt.createChannel(t,n)}(t,n)),this.channels[t]},t.prototype.all=function(){return r.n(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var n=this.channels[t];return delete this.channels[t],n},t.prototype.disconnect=function(){r.k(this.channels,(function(t){t.disconnect()}))},t}();var tt={createChannels:function(){return new $},createConnectionManager:function(t,n){return new Q(t,n)},createChannel:function(t,n){return new H(t,n)},createPrivateChannel:function(t,n){return new F(t,n)},createPresenceChannel:function(t,n){return new K(t,n)},createEncryptedChannel:function(t,n,e){return new G(t,n,e)},createTimelineSender:function(t,n){return new E(t,n)},createAuthorizer:function(t,n){return n.authorizer?n.authorizer(t,n):new A(t,n)},createHandshake:function(t,n){return new P(t,n)},createAssistantToTheTransportManager:function(t,n,e){return new S(t,n,e)}},nt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return tt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),et=function(){function t(t,n){this.strategies=t,this.loop=Boolean(n.loop),this.failFast=Boolean(n.failFast),this.timeout=n.timeout,this.timeoutLimit=n.timeoutLimit}return t.prototype.isSupported=function(){return r.b(this.strategies,h.a.method("isSupported"))},t.prototype.connect=function(t,n){var e=this,r=this.strategies,o=0,i=this.timeout,s=null,a=function(c,u){u?n(null,u):(o+=1,e.loop&&(o%=r.length),o0&&(o=new V.a(e.timeout,(function(){i.abort(),r(!0)}))),i=t.connect(n,(function(t,n){t&&o&&o.isRunning()&&!e.failFast||(o&&o.ensureAborted(),r(t,n))})),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),rt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return r.b(this.strategies,h.a.method("isSupported"))},t.prototype.connect=function(t,n){return function(t,n,e){var o=r.j(t,(function(t,r,o,i){return t.connect(n,e(r,i))}));return{abort:function(){r.c(o,ot)},forceMinPriority:function(t){r.c(o,(function(n){n.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,e){return function(o,i){e[t].error=o,o?function(t){return r.a(t,(function(t){return Boolean(t.error)}))}(e)&&n(!0):(r.c(e,(function(t){t.forceMinPriority(i.transport.priority)})),n(null,i))}}))},t}();function ot(t){t.error||t.aborted||(t.abort(),t.aborted=!0)}var it=function(){function t(t,n,e){this.strategy=t,this.transports=n,this.ttl=e.ttl||18e5,this.usingTLS=e.useTLS,this.timeline=e.timeline}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,n){var e=this.usingTLS,o=function(t){var n=Ut.getLocalStorage();if(n)try{var e=n[st(t)];if(e)return JSON.parse(e)}catch(n){at(t)}return null}(e),i=[this.strategy];if(o&&o.timestamp+this.ttl>=h.a.now()){var s=this.transports[o.transport];s&&(this.timeline.info({cached:!0,transport:o.transport,latency:o.latency}),i.push(new et([s],{timeout:2*o.latency+1e3,failFast:!0})))}var a=h.a.now(),c=i.pop().connect(t,(function o(s,u){s?(at(e),i.length>0?(a=h.a.now(),c=i.pop().connect(t,o)):n(s)):(!function(t,n,e){var o=Ut.getLocalStorage();if(o)try{o[st(t)]=r.l({timestamp:h.a.now(),transport:n,latency:e})}catch(t){}}(e,u.transport.name,h.a.now()-a),n(null,u))}));return{abort:function(){c.abort()},forceMinPriority:function(n){t=n,c&&c.forceMinPriority(n)}}},t}();function st(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function at(t){var n=Ut.getLocalStorage();if(n)try{delete n[st(t)]}catch(t){}}var ct=function(){function t(t,n){var e=n.delay;this.strategy=t,this.options={delay:e}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,n){var e,r=this.strategy,o=new V.a(this.options.delay,(function(){e=r.connect(t,n)}));return{abort:function(){o.ensureAborted(),e&&e.abort()},forceMinPriority:function(n){t=n,e&&e.forceMinPriority(n)}}},t}(),ut=function(){function t(t,n,e){this.test=t,this.trueBranch=n,this.falseBranch=e}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,n){return(this.test()?this.trueBranch:this.falseBranch).connect(t,n)},t}(),ht=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,n){var e=this.strategy.connect(t,(function(t,r){r&&e.abort(),n(t,r)}));return e},t}();function ft(t){return function(){return t.isSupported()}}var pt,lt=function(t,n,e){var o={};function i(n,r,i,s,a){var c=e(t,n,r,i,s,a);return o[n]=c,c}var s,a=Object.assign({},n,{hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath}),c=r.f({},a,{useTLS:!0}),u=Object.assign({},n,{hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath}),h={loop:!0,timeout:15e3,timeoutLimit:6e4},f=new nt({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),p=new nt({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),l=i("ws","ws",3,a,f),d=i("wss","ws",3,c,f),y=i("xhr_streaming","xhr_streaming",1,u,p),g=i("xhr_polling","xhr_polling",1,u),v=new et([l],h),b=new et([d],h),m=new et([y],h),_=new et([g],h),w=new et([new ut(ft(m),new rt([m,new ct(_,{delay:4e3})]),_)],h);return s=n.useTLS?new rt([v,new ct(w,{delay:2e3})]):new rt([v,new ct(b,{delay:2e3}),new ct(w,{delay:5e3})]),new it(new ht(new ut(ft(l),s,w)),o,{ttl:18e5,timeline:n.timeline,useTLS:n.useTLS})},dt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),yt=function(t){function n(n,e,r){var o=t.call(this)||this;return o.hooks=n,o.method=e,o.url=r,o}return dt(n,t),n.prototype.start=function(t){var n=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){n.close()},Ut.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},n.prototype.close=function(){this.unloader&&(Ut.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},n.prototype.onChunk=function(t,n){for(;;){var e=this.advanceBuffer(n);if(!e)break;this.emit("chunk",{status:t,data:e})}this.isBufferTooLong(n)&&this.emit("buffer_too_long")},n.prototype.advanceBuffer=function(t){var n=t.slice(this.position),e=n.indexOf("\n");return-1!==e?(this.position+=e+1,n.slice(0,e)):null},n.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},n}(f.a);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(pt||(pt={}));var gt=pt,vt=1;function bt(t){var n=-1===t.indexOf("?")?"?":"&";return t+n+"t="+ +new Date+"&n="+vt++}function mt(t){return Math.floor(Math.random()*t)}var _t=function(){function t(t,n){this.hooks=t,this.session=mt(1e3)+"/"+function(t){for(var n=[],e=0;e0&&t.onChunk(n.status,n.responseText);break;case 4:n.responseText&&n.responseText.length>0&&t.onChunk(n.status,n.responseText),t.emit("finished",n.status),t.close()}},n},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},Tt={getDefaultStrategy:lt,Transports:w,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(wt,t)},createPollingSocket:function(t){return this.createSocket(St,t)},createSocket:function(t,n){return new _t(t,n)},createXHR:function(t,n){return this.createRequest(kt,t,n)},createRequest:function(t,n,e){return new yt(t,n,e)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return r.i(r.h({ws:w.ws},(function(t){return t.isSupported({})})))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,n){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,n);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},Ct=e(10),Ot=e.n(Ct),Pt=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}();function At(t){return"none"!==t.type.toLowerCase()}var Et,xt=new(function(t){function n(){var n=t.call(this)||this;return n.online=!0,Ot.a.fetch().then((function(t){n.online=At(t)})),Ot.a.addEventListener((function(t){var e=At(t);n.online!==e&&(n.online=e,n.online?n.emit("online"):n.emit("offline"))})),n}return Pt(n,t),n.prototype.isOnline=function(){return this.online},n}(f.a)),Lt=function(t,n,e){var r,o=this;for(var i in(r=Ut.createXHR()).open("POST",o.options.authEndpoint,!0),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)r.setRequestHeader(i,this.authOptions.headers[i]);return r.onreadystatechange=function(){if(4===r.readyState)if(200===r.status){var t,n=!1;try{t=JSON.parse(r.responseText),n=!0}catch(t){e(!0,"JSON returned from auth endpoint was invalid, yet status code was 200. Data was: "+r.responseText)}n&&e(!1,t)}else{var i=B("authenticationEndpoint");p.a.error("Unable to retrieve auth string from auth endpoint - received status "+r.status+" from "+o.options.authEndpoint+". Clients must be authenticated to join private or presence channels. "+i),e(!0,r.status)}},r.send(this.composeQuery(n)),r},Ut={getDefaultStrategy:Tt.getDefaultStrategy,Transports:Tt.Transports,setup:Tt.setup,getProtocol:Tt.getProtocol,isXHRSupported:Tt.isXHRSupported,getLocalStorage:Tt.getLocalStorage,createXHR:Tt.createXHR,createWebSocket:Tt.createWebSocket,addUnloadListener:Tt.addUnloadListener,removeUnloadListener:Tt.removeUnloadListener,transportConnectionInitializer:Tt.transportConnectionInitializer,createSocketRequest:Tt.createSocketRequest,HTTPFactory:Tt.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,n){return function(e,o){var i="http"+(n?"s":"")+"://"+(t.host||t.options.host)+t.options.path;i+="/2?"+r.e(e);var s=Ut.createXHR();s.open("GET",i,!0),s.onreadystatechange=function(){if(4===s.readyState){var n=s.status,e=s.responseText;if(200!==n)return void p.a.debug("TimelineSender Error: received "+n+" from stats.pusher.com");try{var r=JSON.parse(e).host}catch(t){p.a.debug("TimelineSenderError: invalid response "+e)}r&&(t.host=r)}},s.send()}}},getAuthorizers:function(){return{ajax:Lt}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return xt}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(Et||(Et={}));var Mt=Et,Rt=function(){function t(t,n,e){this.key=t,this.session=n,this.events=[],this.options=e||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,n){t<=this.options.level&&(this.events.push(r.f({},n,{timestamp:h.a.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(Mt.ERROR,t)},t.prototype.info=function(t){this.log(Mt.INFO,t)},t.prototype.debug=function(t){this.log(Mt.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,n){var e=this,o=r.f({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,(function(t,r){t||e.sent++,n&&n(t,r)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),jt=function(){function t(t,n,e,r){this.name=t,this.priority=n,this.transport=e,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,n){var e=this;if(!this.isSupported())return It(new I,n);if(this.priority>>18&63),n+=this._encodeByte(r>>>12&63),n+=this._encodeByte(r>>>6&63),n+=this._encodeByte(r>>>0&63)}var o=t.length-e;if(o>0){r=t[e]<<16|(2===o?t[e+1]<<8:0);n+=this._encodeByte(r>>>18&63),n+=this._encodeByte(r>>>12&63),n+=2===o?this._encodeByte(r>>>6&63):this._paddingCharacter||"",n+=this._paddingCharacter||""}return n},t.prototype.maxDecodedLength=function(t){return this._paddingCharacter?t/4*3|0:(6*t+7)/8|0},t.prototype.decodedLength=function(t){return this.maxDecodedLength(t.length-this._getPaddingLength(t))},t.prototype.decode=function(t){if(0===t.length)return new Uint8Array(0);for(var n=this._getPaddingLength(t),e=t.length-n,r=new Uint8Array(this.maxDecodedLength(e)),o=0,i=0,s=0,a=0,c=0,u=0,h=0;i>>4,r[o++]=c<<4|u>>>2,r[o++]=u<<6|h,s|=256&a,s|=256&c,s|=256&u,s|=256&h;if(i>>4,s|=256&a,s|=256&c),i>>2,s|=256&u),i>>8&6,n+=51-t>>>8&-75,n+=61-t>>>8&-15,n+=62-t>>>8&3,String.fromCharCode(n)},t.prototype._decodeChar=function(t){var n=256;return n+=(42-t&t-44)>>>8&-256+t-43+62,n+=(46-t&t-48)>>>8&-256+t-47+63,n+=(47-t&t-58)>>>8&-256+t-48+52,n+=(64-t&t-91)>>>8&-256+t-65+0,n+=(96-t&t-123)>>>8&-256+t-97+26},t.prototype._getPaddingLength=function(t){var n=0;if(this._paddingCharacter){for(var e=t.length-1;e>=0&&t[e]===this._paddingCharacter;e--)n++;if(t.length<4||n>2)throw new Error("Base64Coder: incorrect padding")}return n},t}();n.Coder=i;var s=new i;n.encode=function(t){return s.encode(t)},n.decode=function(t){return s.decode(t)};var a=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return o(n,t),n.prototype._encodeByte=function(t){var n=t;return n+=65,n+=25-t>>>8&6,n+=51-t>>>8&-75,n+=61-t>>>8&-13,n+=62-t>>>8&49,String.fromCharCode(n)},n.prototype._decodeChar=function(t){var n=256;return n+=(44-t&t-46)>>>8&-256+t-45+62,n+=(94-t&t-96)>>>8&-256+t-95+63,n+=(47-t&t-58)>>>8&-256+t-48+52,n+=(64-t&t-91)>>>8&-256+t-65+0,n+=(96-t&t-123)>>>8&-256+t-97+26},n}(i);n.URLSafeCoder=a;var c=new a;n.encodeURLSafe=function(t){return c.encode(t)},n.decodeURLSafe=function(t){return c.decode(t)},n.encodedLength=function(t){return s.encodedLength(t)},n.maxDecodedLength=function(t){return s.maxDecodedLength(t)},n.decodedLength=function(t){return s.decodedLength(t)}},function(t,n,e){"use strict";var r=function(){function t(t,n,e,r){var o=this;this.clear=n,this.timer=t((function(){o.timer&&(o.timer=r(o.timer))}),e)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}();n.a=r},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="utf8: invalid source encoding";function o(t){for(var n=0,e=0;e=t.length-1)throw new Error("utf8: invalid string");e++,n+=4}}return n}n.encode=function(t){for(var n=new Uint8Array(o(t)),e=0,r=0;r>6,n[e++]=128|63&i):i<55296?(n[e++]=224|i>>12,n[e++]=128|i>>6&63,n[e++]=128|63&i):(r++,i=(1023&i)<<10,i|=1023&t.charCodeAt(r),i+=65536,n[e++]=240|i>>18,n[e++]=128|i>>12&63,n[e++]=128|i>>6&63,n[e++]=128|63&i)}return n},n.encodedLength=o,n.decode=function(t){for(var n=[],e=0;e=t.length)throw new Error(r);if(128!=(192&(s=t[++e])))throw new Error(r);o=(31&o)<<6|63&s,i=128}else if(o<240){if(e>=t.length-1)throw new Error(r);var s=t[++e],a=t[++e];if(128!=(192&s)||128!=(192&a))throw new Error(r);o=(15&o)<<12|(63&s)<<6|63&a,i=2048}else{if(!(o<248))throw new Error(r);if(e>=t.length-2)throw new Error(r);s=t[++e],a=t[++e];var c=t[++e];if(128!=(192&s)||128!=(192&a)||128!=(192&c))throw new Error(r);o=(15&o)<<18|(63&s)<<12|(63&a)<<6|63&c,i=65536}if(o=55296&&o<=57343)throw new Error(r);if(o>=65536){if(o>1114111)throw new Error(r);o-=65536,n.push(String.fromCharCode(55296|o>>10)),o=56320|1023&o}}n.push(String.fromCharCode(o))}return n.join("")}},function(t,n){t.exports=require("@react-native-community/netinfo")},function(t,n,e){"use strict";(function(t){function r(t){return p(h(t))}e.d(n,"a",(function(){return r}));for(var o=String.fromCharCode,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={},a=0,c=i.length;a>>6)+o(128|63&n):o(224|n>>>12&15)+o(128|n>>>6&63)+o(128|63&n)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},f=function(t){var n=[0,2,1][t.length%3],e=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[i.charAt(e>>>18),i.charAt(e>>>12&63),n>=2?"=":i.charAt(e>>>6&63),n>=1?"=":i.charAt(63&e)].join("")},p=t.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)}}).call(this,e(6))},function(t,n,e){"use strict";var r=e(0),o=function(){function t(){this._callbacks={}}return t.prototype.get=function(t){return this._callbacks[i(t)]},t.prototype.add=function(t,n,e){var r=i(t);this._callbacks[r]=this._callbacks[r]||[],this._callbacks[r].push({fn:n,context:e})},t.prototype.remove=function(t,n,e){if(t||n||e){var o=t?[i(t)]:r.i(this._callbacks);n||e?this.removeCallback(o,n,e):this.removeAllCallbacks(o)}else this._callbacks={}},t.prototype.removeCallback=function(t,n,e){r.c(t,(function(t){this._callbacks[t]=r.g(this._callbacks[t]||[],(function(t){return n&&n!==t.fn||e&&e!==t.context})),0===this._callbacks[t].length&&delete this._callbacks[t]}),this)},t.prototype.removeAllCallbacks=function(t){r.c(t,(function(t){delete this._callbacks[t]}),this)},t}();function i(t){return"_"+t}n.a=o},function(t,n,e){!function(t){"use strict";var n=function(t){var n,e=new Float64Array(16);if(t)for(n=0;n>24&255,t[n+1]=e>>16&255,t[n+2]=e>>8&255,t[n+3]=255&e,t[n+4]=r>>24&255,t[n+5]=r>>16&255,t[n+6]=r>>8&255,t[n+7]=255&r}function y(t,n,e,r,o){var i,s=0;for(i=0;i>>8)-1}function g(t,n,e,r){return y(t,n,e,r,16)}function v(t,n,e,r){return y(t,n,e,r,32)}function b(t,n,e,r){!function(t,n,e,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,a=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,u=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,p=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,l=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,d=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,g=255&e[16]|(255&e[17])<<8|(255&e[18])<<16|(255&e[19])<<24,v=255&e[20]|(255&e[21])<<8|(255&e[22])<<16|(255&e[23])<<24,b=255&e[24]|(255&e[25])<<8|(255&e[26])<<16|(255&e[27])<<24,m=255&e[28]|(255&e[29])<<8|(255&e[30])<<16|(255&e[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=i,S=s,k=a,T=c,C=u,O=h,P=f,A=p,E=l,x=d,L=y,U=g,M=v,R=b,j=m,I=_,N=0;N<20;N+=2)w^=(o=(M^=(o=(E^=(o=(C^=(o=w+M|0)<<7|o>>>25)+w|0)<<9|o>>>23)+C|0)<<13|o>>>19)+E|0)<<18|o>>>14,O^=(o=(S^=(o=(R^=(o=(x^=(o=O+S|0)<<7|o>>>25)+O|0)<<9|o>>>23)+x|0)<<13|o>>>19)+R|0)<<18|o>>>14,L^=(o=(P^=(o=(k^=(o=(j^=(o=L+P|0)<<7|o>>>25)+L|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(U^=(o=(A^=(o=(T^=(o=I+U|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+A|0)<<18|o>>>14,w^=(o=(T^=(o=(k^=(o=(S^=(o=w+T|0)<<7|o>>>25)+w|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,O^=(o=(C^=(o=(A^=(o=(P^=(o=O+C|0)<<7|o>>>25)+O|0)<<9|o>>>23)+P|0)<<13|o>>>19)+A|0)<<18|o>>>14,L^=(o=(x^=(o=(E^=(o=(U^=(o=L+x|0)<<7|o>>>25)+L|0)<<9|o>>>23)+U|0)<<13|o>>>19)+E|0)<<18|o>>>14,I^=(o=(j^=(o=(R^=(o=(M^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+M|0)<<13|o>>>19)+R|0)<<18|o>>>14;w=w+i|0,S=S+s|0,k=k+a|0,T=T+c|0,C=C+u|0,O=O+h|0,P=P+f|0,A=A+p|0,E=E+l|0,x=x+d|0,L=L+y|0,U=U+g|0,M=M+v|0,R=R+b|0,j=j+m|0,I=I+_|0,t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=C>>>0&255,t[17]=C>>>8&255,t[18]=C>>>16&255,t[19]=C>>>24&255,t[20]=O>>>0&255,t[21]=O>>>8&255,t[22]=O>>>16&255,t[23]=O>>>24&255,t[24]=P>>>0&255,t[25]=P>>>8&255,t[26]=P>>>16&255,t[27]=P>>>24&255,t[28]=A>>>0&255,t[29]=A>>>8&255,t[30]=A>>>16&255,t[31]=A>>>24&255,t[32]=E>>>0&255,t[33]=E>>>8&255,t[34]=E>>>16&255,t[35]=E>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=L>>>0&255,t[41]=L>>>8&255,t[42]=L>>>16&255,t[43]=L>>>24&255,t[44]=U>>>0&255,t[45]=U>>>8&255,t[46]=U>>>16&255,t[47]=U>>>24&255,t[48]=M>>>0&255,t[49]=M>>>8&255,t[50]=M>>>16&255,t[51]=M>>>24&255,t[52]=R>>>0&255,t[53]=R>>>8&255,t[54]=R>>>16&255,t[55]=R>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,n,e,r)}function m(t,n,e,r){!function(t,n,e,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,a=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,u=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,p=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,l=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,d=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,g=255&e[16]|(255&e[17])<<8|(255&e[18])<<16|(255&e[19])<<24,v=255&e[20]|(255&e[21])<<8|(255&e[22])<<16|(255&e[23])<<24,b=255&e[24]|(255&e[25])<<8|(255&e[26])<<16|(255&e[27])<<24,m=255&e[28]|(255&e[29])<<8|(255&e[30])<<16|(255&e[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=0;w<20;w+=2)i^=(o=(v^=(o=(l^=(o=(u^=(o=i+v|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(f^=(o=(a^=(o=(m^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+a|0)<<18|o>>>14,_^=(o=(g^=(o=(p^=(o=(c^=(o=_+g|0)<<7|o>>>25)+_|0)<<9|o>>>23)+c|0)<<13|o>>>19)+p|0)<<18|o>>>14,i^=(o=(c^=(o=(a^=(o=(s^=(o=i+c|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+a|0)<<18|o>>>14,h^=(o=(u^=(o=(p^=(o=(f^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+f|0)<<13|o>>>19)+p|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(g^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+g|0)<<13|o>>>19)+l|0)<<18|o>>>14,_^=(o=(m^=(o=(b^=(o=(v^=(o=_+m|0)<<7|o>>>25)+_|0)<<9|o>>>23)+v|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=_>>>0&255,t[13]=_>>>8&255,t[14]=_>>>16&255,t[15]=_>>>24&255,t[16]=f>>>0&255,t[17]=f>>>8&255,t[18]=f>>>16&255,t[19]=f>>>24&255,t[20]=p>>>0&255,t[21]=p>>>8&255,t[22]=p>>>16&255,t[23]=p>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,n,e,r)}var _=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(t,n,e,r,o,i,s){var a,c,u=new Uint8Array(16),h=new Uint8Array(64);for(c=0;c<16;c++)u[c]=0;for(c=0;c<8;c++)u[c]=i[c];for(;o>=64;){for(b(h,u,s,_),c=0;c<64;c++)t[n+c]=e[r+c]^h[c];for(a=1,c=8;c<16;c++)a=a+(255&u[c])|0,u[c]=255&a,a>>>=8;o-=64,n+=64,r+=64}if(o>0)for(b(h,u,s,_),c=0;c=64;){for(b(c,a,o,_),s=0;s<64;s++)t[n+s]=c[s];for(i=1,s=8;s<16;s++)i=i+(255&a[s])|0,a[s]=255&i,i>>>=8;e-=64,n+=64}if(e>0)for(b(c,a,o,_),s=0;s>>13|e<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(e>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),a=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|a<<5),c=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(a>>>8|c<<8),this.r[9]=c>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function O(t,n,e,r,o,i){var s=new C(i);return s.update(e,r,o),s.finish(t,n),0}function P(t,n,e,r,o,i){var s=new Uint8Array(16);return O(s,0,e,r,o,i),g(t,n,s,0)}function A(t,n,e,r,o){var i;if(e<32)return-1;for(T(t,0,n,0,e,r,o),O(t,16,t,32,e-32,t),i=0;i<16;i++)t[i]=0;return 0}function E(t,n,e,r,o){var i,s=new Uint8Array(32);if(e<32)return-1;if(k(s,0,32,r,o),0!==P(n,16,n,32,e-32,s))return-1;for(T(t,0,n,0,e,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,n){var e;for(e=0;e<16;e++)t[e]=0|n[e]}function L(t){var n,e,r=1;for(n=0;n<16;n++)e=t[n]+r+65535,r=Math.floor(e/65536),t[n]=e-65536*r;t[0]+=r-1+37*(r-1)}function U(t,n,e){for(var r,o=~(e-1),i=0;i<16;i++)r=o&(t[i]^n[i]),t[i]^=r,n[i]^=r}function M(t,e){var r,o,i,s=n(),a=n();for(r=0;r<16;r++)a[r]=e[r];for(L(a),L(a),L(a),o=0;o<2;o++){for(s[0]=a[0]-65517,r=1;r<15;r++)s[r]=a[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=a[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,U(a,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&a[r],t[2*r+1]=a[r]>>8}function R(t,n){var e=new Uint8Array(32),r=new Uint8Array(32);return M(e,t),M(r,n),v(e,0,r,0)}function j(t){var n=new Uint8Array(32);return M(n,t),1&n[0]}function I(t,n){var e;for(e=0;e<16;e++)t[e]=n[2*e]+(n[2*e+1]<<8);t[15]&=32767}function N(t,n,e){for(var r=0;r<16;r++)t[r]=n[r]+e[r]}function B(t,n,e){for(var r=0;r<16;r++)t[r]=n[r]-e[r]}function D(t,n,e){var r,o,i=0,s=0,a=0,c=0,u=0,h=0,f=0,p=0,l=0,d=0,y=0,g=0,v=0,b=0,m=0,_=0,w=0,S=0,k=0,T=0,C=0,O=0,P=0,A=0,E=0,x=0,L=0,U=0,M=0,R=0,j=0,I=e[0],N=e[1],B=e[2],D=e[3],H=e[4],z=e[5],F=e[6],q=e[7],Y=e[8],K=e[9],J=e[10],X=e[11],W=e[12],G=e[13],V=e[14],Z=e[15];i+=(r=n[0])*I,s+=r*N,a+=r*B,c+=r*D,u+=r*H,h+=r*z,f+=r*F,p+=r*q,l+=r*Y,d+=r*K,y+=r*J,g+=r*X,v+=r*W,b+=r*G,m+=r*V,_+=r*Z,s+=(r=n[1])*I,a+=r*N,c+=r*B,u+=r*D,h+=r*H,f+=r*z,p+=r*F,l+=r*q,d+=r*Y,y+=r*K,g+=r*J,v+=r*X,b+=r*W,m+=r*G,_+=r*V,w+=r*Z,a+=(r=n[2])*I,c+=r*N,u+=r*B,h+=r*D,f+=r*H,p+=r*z,l+=r*F,d+=r*q,y+=r*Y,g+=r*K,v+=r*J,b+=r*X,m+=r*W,_+=r*G,w+=r*V,S+=r*Z,c+=(r=n[3])*I,u+=r*N,h+=r*B,f+=r*D,p+=r*H,l+=r*z,d+=r*F,y+=r*q,g+=r*Y,v+=r*K,b+=r*J,m+=r*X,_+=r*W,w+=r*G,S+=r*V,k+=r*Z,u+=(r=n[4])*I,h+=r*N,f+=r*B,p+=r*D,l+=r*H,d+=r*z,y+=r*F,g+=r*q,v+=r*Y,b+=r*K,m+=r*J,_+=r*X,w+=r*W,S+=r*G,k+=r*V,T+=r*Z,h+=(r=n[5])*I,f+=r*N,p+=r*B,l+=r*D,d+=r*H,y+=r*z,g+=r*F,v+=r*q,b+=r*Y,m+=r*K,_+=r*J,w+=r*X,S+=r*W,k+=r*G,T+=r*V,C+=r*Z,f+=(r=n[6])*I,p+=r*N,l+=r*B,d+=r*D,y+=r*H,g+=r*z,v+=r*F,b+=r*q,m+=r*Y,_+=r*K,w+=r*J,S+=r*X,k+=r*W,T+=r*G,C+=r*V,O+=r*Z,p+=(r=n[7])*I,l+=r*N,d+=r*B,y+=r*D,g+=r*H,v+=r*z,b+=r*F,m+=r*q,_+=r*Y,w+=r*K,S+=r*J,k+=r*X,T+=r*W,C+=r*G,O+=r*V,P+=r*Z,l+=(r=n[8])*I,d+=r*N,y+=r*B,g+=r*D,v+=r*H,b+=r*z,m+=r*F,_+=r*q,w+=r*Y,S+=r*K,k+=r*J,T+=r*X,C+=r*W,O+=r*G,P+=r*V,A+=r*Z,d+=(r=n[9])*I,y+=r*N,g+=r*B,v+=r*D,b+=r*H,m+=r*z,_+=r*F,w+=r*q,S+=r*Y,k+=r*K,T+=r*J,C+=r*X,O+=r*W,P+=r*G,A+=r*V,E+=r*Z,y+=(r=n[10])*I,g+=r*N,v+=r*B,b+=r*D,m+=r*H,_+=r*z,w+=r*F,S+=r*q,k+=r*Y,T+=r*K,C+=r*J,O+=r*X,P+=r*W,A+=r*G,E+=r*V,x+=r*Z,g+=(r=n[11])*I,v+=r*N,b+=r*B,m+=r*D,_+=r*H,w+=r*z,S+=r*F,k+=r*q,T+=r*Y,C+=r*K,O+=r*J,P+=r*X,A+=r*W,E+=r*G,x+=r*V,L+=r*Z,v+=(r=n[12])*I,b+=r*N,m+=r*B,_+=r*D,w+=r*H,S+=r*z,k+=r*F,T+=r*q,C+=r*Y,O+=r*K,P+=r*J,A+=r*X,E+=r*W,x+=r*G,L+=r*V,U+=r*Z,b+=(r=n[13])*I,m+=r*N,_+=r*B,w+=r*D,S+=r*H,k+=r*z,T+=r*F,C+=r*q,O+=r*Y,P+=r*K,A+=r*J,E+=r*X,x+=r*W,L+=r*G,U+=r*V,M+=r*Z,m+=(r=n[14])*I,_+=r*N,w+=r*B,S+=r*D,k+=r*H,T+=r*z,C+=r*F,O+=r*q,P+=r*Y,A+=r*K,E+=r*J,x+=r*X,L+=r*W,U+=r*G,M+=r*V,R+=r*Z,_+=(r=n[15])*I,s+=38*(S+=r*B),a+=38*(k+=r*D),c+=38*(T+=r*H),u+=38*(C+=r*z),h+=38*(O+=r*F),f+=38*(P+=r*q),p+=38*(A+=r*Y),l+=38*(E+=r*K),d+=38*(x+=r*J),y+=38*(L+=r*X),g+=38*(U+=r*W),v+=38*(M+=r*G),b+=38*(R+=r*V),m+=38*(j+=r*Z),i=(r=(i+=38*(w+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=a,t[3]=c,t[4]=u,t[5]=h,t[6]=f,t[7]=p,t[8]=l,t[9]=d,t[10]=y,t[11]=g,t[12]=v,t[13]=b,t[14]=m,t[15]=_}function H(t,n){D(t,n,n)}function z(t,e){var r,o=n();for(r=0;r<16;r++)o[r]=e[r];for(r=253;r>=0;r--)H(o,o),2!==r&&4!==r&&D(o,o,e);for(r=0;r<16;r++)t[r]=o[r]}function F(t,e){var r,o=n();for(r=0;r<16;r++)o[r]=e[r];for(r=250;r>=0;r--)H(o,o),1!==r&&D(o,o,e);for(r=0;r<16;r++)t[r]=o[r]}function q(t,e,r){var o,i,s=new Uint8Array(32),a=new Float64Array(80),u=n(),h=n(),f=n(),p=n(),l=n(),d=n();for(i=0;i<31;i++)s[i]=e[i];for(s[31]=127&e[31]|64,s[0]&=248,I(a,r),i=0;i<16;i++)h[i]=a[i],p[i]=u[i]=f[i]=0;for(u[0]=p[0]=1,i=254;i>=0;--i)U(u,h,o=s[i>>>3]>>>(7&i)&1),U(f,p,o),N(l,u,f),B(u,u,f),N(f,h,p),B(h,h,p),H(p,l),H(d,u),D(u,f,u),D(f,h,l),N(l,u,f),B(u,u,f),H(h,u),B(f,p,d),D(u,f,c),N(u,u,p),D(f,f,u),D(u,p,d),D(p,h,a),H(h,l),U(u,h,o),U(f,p,o);for(i=0;i<16;i++)a[i+16]=u[i],a[i+32]=f[i],a[i+48]=h[i],a[i+64]=p[i];var y=a.subarray(32),g=a.subarray(16);return z(y,y),D(g,g,y),M(t,g),0}function Y(t,n){return q(t,n,i)}function K(t,n){return r(n,32),Y(t,n)}function J(t,n,e){var r=new Uint8Array(32);return q(r,e,n),m(t,o,r,_)}C.prototype.blocks=function(t,n,e){for(var r,o,i,s,a,c,u,h,f,p,l,d,y,g,v,b,m,_,w,S=this.fin?0:2048,k=this.h[0],T=this.h[1],C=this.h[2],O=this.h[3],P=this.h[4],A=this.h[5],E=this.h[6],x=this.h[7],L=this.h[8],U=this.h[9],M=this.r[0],R=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],D=this.r[6],H=this.r[7],z=this.r[8],F=this.r[9];e>=16;)p=f=0,p+=(k+=8191&(r=255&t[n+0]|(255&t[n+1])<<8))*M,p+=(T+=8191&(r>>>13|(o=255&t[n+2]|(255&t[n+3])<<8)<<3))*(5*F),p+=(C+=8191&(o>>>10|(i=255&t[n+4]|(255&t[n+5])<<8)<<6))*(5*z),p+=(O+=8191&(i>>>7|(s=255&t[n+6]|(255&t[n+7])<<8)<<9))*(5*H),f=(p+=(P+=8191&(s>>>4|(a=255&t[n+8]|(255&t[n+9])<<8)<<12))*(5*D))>>>13,p&=8191,p+=(A+=a>>>1&8191)*(5*B),p+=(E+=8191&(a>>>14|(c=255&t[n+10]|(255&t[n+11])<<8)<<2))*(5*N),p+=(x+=8191&(c>>>11|(u=255&t[n+12]|(255&t[n+13])<<8)<<5))*(5*I),p+=(L+=8191&(u>>>8|(h=255&t[n+14]|(255&t[n+15])<<8)<<8))*(5*j),l=f+=(p+=(U+=h>>>5|S)*(5*R))>>>13,l+=k*R,l+=T*M,l+=C*(5*F),l+=O*(5*z),f=(l+=P*(5*H))>>>13,l&=8191,l+=A*(5*D),l+=E*(5*B),l+=x*(5*N),l+=L*(5*I),f+=(l+=U*(5*j))>>>13,l&=8191,d=f,d+=k*j,d+=T*R,d+=C*M,d+=O*(5*F),f=(d+=P*(5*z))>>>13,d&=8191,d+=A*(5*H),d+=E*(5*D),d+=x*(5*B),d+=L*(5*N),y=f+=(d+=U*(5*I))>>>13,y+=k*I,y+=T*j,y+=C*R,y+=O*M,f=(y+=P*(5*F))>>>13,y&=8191,y+=A*(5*z),y+=E*(5*H),y+=x*(5*D),y+=L*(5*B),g=f+=(y+=U*(5*N))>>>13,g+=k*N,g+=T*I,g+=C*j,g+=O*R,f=(g+=P*M)>>>13,g&=8191,g+=A*(5*F),g+=E*(5*z),g+=x*(5*H),g+=L*(5*D),v=f+=(g+=U*(5*B))>>>13,v+=k*B,v+=T*N,v+=C*I,v+=O*j,f=(v+=P*R)>>>13,v&=8191,v+=A*M,v+=E*(5*F),v+=x*(5*z),v+=L*(5*H),b=f+=(v+=U*(5*D))>>>13,b+=k*D,b+=T*B,b+=C*N,b+=O*I,f=(b+=P*j)>>>13,b&=8191,b+=A*R,b+=E*M,b+=x*(5*F),b+=L*(5*z),m=f+=(b+=U*(5*H))>>>13,m+=k*H,m+=T*D,m+=C*B,m+=O*N,f=(m+=P*I)>>>13,m&=8191,m+=A*j,m+=E*R,m+=x*M,m+=L*(5*F),_=f+=(m+=U*(5*z))>>>13,_+=k*z,_+=T*H,_+=C*D,_+=O*B,f=(_+=P*N)>>>13,_&=8191,_+=A*I,_+=E*j,_+=x*R,_+=L*M,w=f+=(_+=U*(5*F))>>>13,w+=k*F,w+=T*z,w+=C*H,w+=O*D,f=(w+=P*B)>>>13,w&=8191,w+=A*N,w+=E*I,w+=x*j,w+=L*R,k=p=8191&(f=(f=((f+=(w+=U*M)>>>13)<<2)+f|0)+(p&=8191)|0),T=l+=f>>>=13,C=d&=8191,O=y&=8191,P=g&=8191,A=v&=8191,E=b&=8191,x=m&=8191,L=_&=8191,U=w&=8191,n+=16,e-=16;this.h[0]=k,this.h[1]=T,this.h[2]=C,this.h[3]=O,this.h[4]=P,this.h[5]=A,this.h[6]=E,this.h[7]=x,this.h[8]=L,this.h[9]=U},C.prototype.finish=function(t,n){var e,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(e=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=e,e=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*e,e=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=e,e=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=e,s[0]=this.h[0]+5,e=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+e,e=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^e)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[n+0]=this.h[0]>>>0&255,t[n+1]=this.h[0]>>>8&255,t[n+2]=this.h[1]>>>0&255,t[n+3]=this.h[1]>>>8&255,t[n+4]=this.h[2]>>>0&255,t[n+5]=this.h[2]>>>8&255,t[n+6]=this.h[3]>>>0&255,t[n+7]=this.h[3]>>>8&255,t[n+8]=this.h[4]>>>0&255,t[n+9]=this.h[4]>>>8&255,t[n+10]=this.h[5]>>>0&255,t[n+11]=this.h[5]>>>8&255,t[n+12]=this.h[6]>>>0&255,t[n+13]=this.h[6]>>>8&255,t[n+14]=this.h[7]>>>0&255,t[n+15]=this.h[7]>>>8&255},C.prototype.update=function(t,n,e){var r,o;if(this.leftover){for((o=16-this.leftover)>e&&(o=e),r=0;r=16&&(o=e-e%16,this.blocks(t,n,o),n+=o,e-=o),e){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+W,x[S]=e[k+0]<<24|e[k+1]<<16|e[k+2]<<8|e[k+3],L[S]=e[k+4]<<24|e[k+5]<<16|e[k+6]<<8|e[k+7];for(S=0;S<80;S++)if(o=U,i=M,s=R,a=j,c=I,u=N,h=B,D,p=H,l=z,d=F,y=q,g=Y,v=K,b=J,X,O=65535&(C=X),P=C>>>16,A=65535&(T=D),E=T>>>16,O+=65535&(C=(Y>>>14|I<<18)^(Y>>>18|I<<14)^(I>>>9|Y<<23)),P+=C>>>16,A+=65535&(T=(I>>>14|Y<<18)^(I>>>18|Y<<14)^(Y>>>9|I<<23)),E+=T>>>16,O+=65535&(C=Y&K^~Y&J),P+=C>>>16,A+=65535&(T=I&N^~I&B),E+=T>>>16,O+=65535&(C=G[2*S+1]),P+=C>>>16,A+=65535&(T=G[2*S]),E+=T>>>16,T=x[S%16],P+=(C=L[S%16])>>>16,A+=65535&T,E+=T>>>16,A+=(P+=(O+=65535&C)>>>16)>>>16,O=65535&(C=w=65535&O|P<<16),P=C>>>16,A=65535&(T=_=65535&A|(E+=A>>>16)<<16),E=T>>>16,O+=65535&(C=(H>>>28|U<<4)^(U>>>2|H<<30)^(U>>>7|H<<25)),P+=C>>>16,A+=65535&(T=(U>>>28|H<<4)^(H>>>2|U<<30)^(H>>>7|U<<25)),E+=T>>>16,P+=(C=H&z^H&F^z&F)>>>16,A+=65535&(T=U&M^U&R^M&R),E+=T>>>16,f=65535&(A+=(P+=(O+=65535&C)>>>16)>>>16)|(E+=A>>>16)<<16,m=65535&O|P<<16,O=65535&(C=y),P=C>>>16,A=65535&(T=a),E=T>>>16,P+=(C=w)>>>16,A+=65535&(T=_),E+=T>>>16,M=o,R=i,j=s,I=a=65535&(A+=(P+=(O+=65535&C)>>>16)>>>16)|(E+=A>>>16)<<16,N=c,B=u,D=h,U=f,z=p,F=l,q=d,Y=y=65535&O|P<<16,K=g,J=v,X=b,H=m,S%16==15)for(k=0;k<16;k++)T=x[k],O=65535&(C=L[k]),P=C>>>16,A=65535&T,E=T>>>16,T=x[(k+9)%16],O+=65535&(C=L[(k+9)%16]),P+=C>>>16,A+=65535&T,E+=T>>>16,_=x[(k+1)%16],O+=65535&(C=((w=L[(k+1)%16])>>>1|_<<31)^(w>>>8|_<<24)^(w>>>7|_<<25)),P+=C>>>16,A+=65535&(T=(_>>>1|w<<31)^(_>>>8|w<<24)^_>>>7),E+=T>>>16,_=x[(k+14)%16],P+=(C=((w=L[(k+14)%16])>>>19|_<<13)^(_>>>29|w<<3)^(w>>>6|_<<26))>>>16,A+=65535&(T=(_>>>19|w<<13)^(w>>>29|_<<3)^_>>>6),E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,x[k]=65535&A|E<<16,L[k]=65535&O|P<<16;O=65535&(C=H),P=C>>>16,A=65535&(T=U),E=T>>>16,T=t[0],P+=(C=n[0])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[0]=U=65535&A|E<<16,n[0]=H=65535&O|P<<16,O=65535&(C=z),P=C>>>16,A=65535&(T=M),E=T>>>16,T=t[1],P+=(C=n[1])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[1]=M=65535&A|E<<16,n[1]=z=65535&O|P<<16,O=65535&(C=F),P=C>>>16,A=65535&(T=R),E=T>>>16,T=t[2],P+=(C=n[2])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[2]=R=65535&A|E<<16,n[2]=F=65535&O|P<<16,O=65535&(C=q),P=C>>>16,A=65535&(T=j),E=T>>>16,T=t[3],P+=(C=n[3])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[3]=j=65535&A|E<<16,n[3]=q=65535&O|P<<16,O=65535&(C=Y),P=C>>>16,A=65535&(T=I),E=T>>>16,T=t[4],P+=(C=n[4])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[4]=I=65535&A|E<<16,n[4]=Y=65535&O|P<<16,O=65535&(C=K),P=C>>>16,A=65535&(T=N),E=T>>>16,T=t[5],P+=(C=n[5])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[5]=N=65535&A|E<<16,n[5]=K=65535&O|P<<16,O=65535&(C=J),P=C>>>16,A=65535&(T=B),E=T>>>16,T=t[6],P+=(C=n[6])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[6]=B=65535&A|E<<16,n[6]=J=65535&O|P<<16,O=65535&(C=X),P=C>>>16,A=65535&(T=D),E=T>>>16,T=t[7],P+=(C=n[7])>>>16,A+=65535&T,E+=T>>>16,E+=(A+=(P+=(O+=65535&C)>>>16)>>>16)>>>16,t[7]=D=65535&A|E<<16,n[7]=X=65535&O|P<<16,W+=128,r-=128}return r}function Z(t,n,e){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),a=e;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,V(o,i,n,e),e%=128,r=0;r=0;--o)$(t,n,r=e[o/8|0]>>(7&o)&1),Q(n,t),Q(t,t),$(t,n,r)}function et(t,e){var r=[n(),n(),n(),n()];x(r[0],f),x(r[1],p),x(r[2],a),D(r[3],f,p),nt(t,r,e)}function rt(t,e,o){var i,s=new Uint8Array(64),a=[n(),n(),n(),n()];for(o||r(e,32),Z(s,e,32),s[0]&=248,s[31]&=127,s[31]|=64,et(a,s),tt(t,a),i=0;i<32;i++)e[i+32]=t[i];return 0}var ot=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function it(t,n){var e,r,o,i;for(r=63;r>=32;--r){for(e=0,o=r-32,i=r-12;o>4)*ot[o],e=n[o]>>8,n[o]&=255;for(o=0;o<32;o++)n[o]-=e*ot[o];for(r=0;r<32;r++)n[r+1]+=n[r]>>8,t[r]=255&n[r]}function st(t){var n,e=new Float64Array(64);for(n=0;n<64;n++)e[n]=t[n];for(n=0;n<64;n++)t[n]=0;it(t,e)}function at(t,e,r,o){var i,s,a=new Uint8Array(64),c=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),f=[n(),n(),n(),n()];Z(a,o,32),a[0]&=248,a[31]&=127,a[31]|=64;var p=r+64;for(i=0;i>7&&B(t[0],s,t[0]),D(t[3],t[0],t[1]),0)}(p,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),n=new Uint8Array(64);return rt(t,n),{publicKey:t,secretKey:n}},t.sign.keyPair.fromSecretKey=function(t){if(ht(t),64!==t.length)throw new Error("bad secret key size");for(var n=new Uint8Array(32),e=0;e>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + out += this._encodeByte((c >>> 1 * 6) & 63); + out += this._encodeByte((c >>> 0 * 6) & 63); + } + var left = data.length - i; + if (left > 0) { + var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + if (left === 2) { + out += this._encodeByte((c >>> 1 * 6) & 63); + } + else { + out += this._paddingCharacter || ""; + } + out += this._paddingCharacter || ""; + } + return out; + }; + Coder.prototype.maxDecodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 6 + 7) / 8 | 0; + } + return length / 4 * 3 | 0; + }; + Coder.prototype.decodedLength = function (s) { + return this.maxDecodedLength(s.length - this._getPaddingLength(s)); + }; + Coder.prototype.decode = function (s) { + if (s.length === 0) { + return new Uint8Array(0); + } + var paddingLength = this._getPaddingLength(s); + var length = s.length - paddingLength; + var out = new Uint8Array(this.maxDecodedLength(length)); + var op = 0; + var i = 0; + var haveBad = 0; + var v0 = 0, v1 = 0, v2 = 0, v3 = 0; + for (; i < length - 4; i += 4) { + v0 = this._decodeChar(s.charCodeAt(i + 0)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + v2 = this._decodeChar(s.charCodeAt(i + 2)); + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v0 << 2) | (v1 >>> 4); + out[op++] = (v1 << 4) | (v2 >>> 2); + out[op++] = (v2 << 6) | v3; + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + haveBad |= v2 & INVALID_BYTE; + haveBad |= v3 & INVALID_BYTE; + } + if (i < length - 1) { + v0 = this._decodeChar(s.charCodeAt(i)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + out[op++] = (v0 << 2) | (v1 >>> 4); + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + } + if (i < length - 2) { + v2 = this._decodeChar(s.charCodeAt(i + 2)); + out[op++] = (v1 << 4) | (v2 >>> 2); + haveBad |= v2 & INVALID_BYTE; + } + if (i < length - 3) { + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v2 << 6) | v3; + haveBad |= v3 & INVALID_BYTE; + } + if (haveBad !== 0) { + throw new Error("Base64Coder: incorrect characters for decoding"); + } + return out; + }; + // Standard encoding have the following encoded/decoded ranges, + // which we need to convert between. + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + / + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 43 47 + // + // Encode 6 bits in b into a new character. + Coder.prototype._encodeByte = function (b) { + // Encoding uses constant time operations as follows: + // + // 1. Define comparison of A with B using (A - B) >>> 8: + // if A > B, then result is positive integer + // if A <= B, then result is 0 + // + // 2. Define selection of C or 0 using bitwise AND: X & C: + // if X == 0, then result is 0 + // if X != 0, then result is C + // + // 3. Start with the smallest comparison (b >= 0), which is always + // true, so set the result to the starting ASCII value (65). + // + // 4. Continue comparing b to higher ASCII values, and selecting + // zero if comparison isn't true, otherwise selecting a value + // to add to result, which: + // + // a) undoes the previous addition + // b) provides new value to add + // + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47); + return String.fromCharCode(result); + }; + // Decode a character code into a byte. + // Must return 256 if character is out of alphabet range. + Coder.prototype._decodeChar = function (c) { + // Decoding works similar to encoding: using the same comparison + // function, but now it works on ranges: result is always incremented + // by value, but this value becomes zero if the range is not + // satisfied. + // + // Decoding starts with invalid value, 256, which is then + // subtracted when the range is satisfied. If none of the ranges + // apply, the function returns 256, which is then checked by + // the caller to throw error. + var result = INVALID_BYTE; // start with invalid character + // c == 43 (c > 42 and c < 44) + result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62); + // c == 47 (c > 46 and c < 48) + result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + Coder.prototype._getPaddingLength = function (s) { + var paddingLength = 0; + if (this._paddingCharacter) { + for (var i = s.length - 1; i >= 0; i--) { + if (s[i] !== this._paddingCharacter) { + break; + } + paddingLength++; + } + if (s.length < 4 || paddingLength > 2) { + throw new Error("Base64Coder: incorrect padding"); + } + } + return paddingLength; + }; + return Coder; +}()); +exports.Coder = Coder; +var stdCoder = new Coder(); +function encode(data) { + return stdCoder.encode(data); +} +exports.encode = encode; +function decode(s) { + return stdCoder.decode(s); +} +exports.decode = decode; +/** + * Implements URL-safe Base64 encoding. + * (Same as Base64, but '+' is replaced with '-', and '/' with '_'). + * + * Operates in constant time. + */ +var URLSafeCoder = /** @class */ (function (_super) { + __extends(URLSafeCoder, _super); + function URLSafeCoder() { + return _super !== null && _super.apply(this, arguments) || this; + } + // URL-safe encoding have the following encoded/decoded ranges: + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _ + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 45 95 + // + URLSafeCoder.prototype._encodeByte = function (b) { + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95); + return String.fromCharCode(result); + }; + URLSafeCoder.prototype._decodeChar = function (c) { + var result = INVALID_BYTE; + // c == 45 (c > 44 and c < 46) + result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62); + // c == 95 (c > 94 and c < 96) + result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + return URLSafeCoder; +}(Coder)); +exports.URLSafeCoder = URLSafeCoder; +var urlSafeCoder = new URLSafeCoder(); +function encodeURLSafe(data) { + return urlSafeCoder.encode(data); +} +exports.encodeURLSafe = encodeURLSafe; +function decodeURLSafe(s) { + return urlSafeCoder.decode(s); +} +exports.decodeURLSafe = decodeURLSafe; +exports.encodedLength = function (length) { + return stdCoder.encodedLength(length); +}; +exports.maxDecodedLength = function (length) { + return stdCoder.maxDecodedLength(length); +}; +exports.decodedLength = function (s) { + return stdCoder.decodedLength(s); +}; +//# sourceMappingURL=base64.js.map + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package utf8 implements UTF-8 encoding and decoding. + */ +var INVALID_UTF16 = "utf8: invalid string"; +var INVALID_UTF8 = "utf8: invalid source encoding"; +/** + * Encodes the given string into UTF-8 byte array. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encode(s) { + // Calculate result length and allocate output array. + // encodedLength() also validates string and throws errors, + // so we don't need repeat validation here. + var arr = new Uint8Array(encodedLength(s)); + var pos = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + arr[pos++] = c; + } + else if (c < 0x800) { + arr[pos++] = 0xc0 | c >> 6; + arr[pos++] = 0x80 | c & 0x3f; + } + else if (c < 0xd800) { + arr[pos++] = 0xe0 | c >> 12; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + else { + i++; // get one more character + c = (c & 0x3ff) << 10; + c |= s.charCodeAt(i) & 0x3ff; + c += 0x10000; + arr[pos++] = 0xf0 | c >> 18; + arr[pos++] = 0x80 | (c >> 12) & 0x3f; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + } + return arr; +} +exports.encode = encode; +/** + * Returns the number of bytes required to encode the given string into UTF-8. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encodedLength(s) { + var result = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + result += 1; + } + else if (c < 0x800) { + result += 2; + } + else if (c < 0xd800) { + result += 3; + } + else if (c <= 0xdfff) { + if (i >= s.length - 1) { + throw new Error(INVALID_UTF16); + } + i++; // "eat" next character + result += 4; + } + else { + throw new Error(INVALID_UTF16); + } + } + return result; +} +exports.encodedLength = encodedLength; +/** + * Decodes the given byte array from UTF-8 into a string. + * Throws if encoding is invalid. + */ +function decode(arr) { + var chars = []; + for (var i = 0; i < arr.length; i++) { + var b = arr[i]; + if (b & 0x80) { + var min = void 0; + if (b < 0xe0) { + // Need 1 more byte. + if (i >= arr.length) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + if ((n1 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x1f) << 6 | (n1 & 0x3f); + min = 0x80; + } + else if (b < 0xf0) { + // Need 2 more bytes. + if (i >= arr.length - 1) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 12 | (n1 & 0x3f) << 6 | (n2 & 0x3f); + min = 0x800; + } + else if (b < 0xf8) { + // Need 3 more bytes. + if (i >= arr.length - 2) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + var n3 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80 || (n3 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 18 | (n1 & 0x3f) << 12 | (n2 & 0x3f) << 6 | (n3 & 0x3f); + min = 0x10000; + } + else { + throw new Error(INVALID_UTF8); + } + if (b < min || (b >= 0xd800 && b <= 0xdfff)) { + throw new Error(INVALID_UTF8); + } + if (b >= 0x10000) { + // Surrogate pair. + if (b > 0x10ffff) { + throw new Error(INVALID_UTF8); + } + b -= 0x10000; + chars.push(String.fromCharCode(0xd800 | (b >> 10))); + b = 0xdc00 | (b & 0x3ff); + } + } + chars.push(String.fromCharCode(b)); + } + return chars.join(""); +} +exports.decode = decode; +//# sourceMappingURL=utf8.js.map + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +(function(nacl) { +'use strict'; + +// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +// +// Implementation derived from TweetNaCl version 20140427. +// See for details: http://tweetnacl.cr.yp.to/ + +var gf = function(init) { + var i, r = new Float64Array(16); + if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; + return r; +}; + +// Pluggable, initialized in high-level API below. +var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; + +var _0 = new Uint8Array(16); +var _9 = new Uint8Array(32); _9[0] = 9; + +var gf0 = gf(), + gf1 = gf([1]), + _121665 = gf([0xdb41, 1]), + D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), + D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), + X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), + Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), + I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); + +function ts64(x, i, h, l) { + x[i] = (h >> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; +} + +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; +} + +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); +} + +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); +} + +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; + + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; + + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; + + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; + + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; + + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; + + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; + + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; + + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; + + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; + + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; + + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; + + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; + + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; + + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; + + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} + +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; + + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; + + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; + + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; + + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; + + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; + + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} + +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} + +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} + +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" + +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; +} + +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} + +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); +} + +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +} + +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ + +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; + + var t0, t1, t2, t3, t4, t5, t6, t7; + + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; + + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; +}; + +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; + + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; + + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; + + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; + + c = 0; + + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; + + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; + + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; + + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; + + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; + + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; + + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; + + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; + + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; + + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; + + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; + + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; + + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; +}; + +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; + + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } + + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; + } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; + + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; + } + g[9] -= (1 << 13); + + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; + + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; + + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } + + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +}; + +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; + + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } + + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } + + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; + } +}; + +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} + +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} + +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} + +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} + +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} + +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} + +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} + +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; + } + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} + +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} + +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} + +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} + +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +} + +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} + +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; + + v = a[0]; + t0 += v * b0; + t1 += v * b1; + t2 += v * b2; + t3 += v * b3; + t4 += v * b4; + t5 += v * b5; + t6 += v * b6; + t7 += v * b7; + t8 += v * b8; + t9 += v * b9; + t10 += v * b10; + t11 += v * b11; + t12 += v * b12; + t13 += v * b13; + t14 += v * b14; + t15 += v * b15; + v = a[1]; + t1 += v * b0; + t2 += v * b1; + t3 += v * b2; + t4 += v * b3; + t5 += v * b4; + t6 += v * b5; + t7 += v * b6; + t8 += v * b7; + t9 += v * b8; + t10 += v * b9; + t11 += v * b10; + t12 += v * b11; + t13 += v * b12; + t14 += v * b13; + t15 += v * b14; + t16 += v * b15; + v = a[2]; + t2 += v * b0; + t3 += v * b1; + t4 += v * b2; + t5 += v * b3; + t6 += v * b4; + t7 += v * b5; + t8 += v * b6; + t9 += v * b7; + t10 += v * b8; + t11 += v * b9; + t12 += v * b10; + t13 += v * b11; + t14 += v * b12; + t15 += v * b13; + t16 += v * b14; + t17 += v * b15; + v = a[3]; + t3 += v * b0; + t4 += v * b1; + t5 += v * b2; + t6 += v * b3; + t7 += v * b4; + t8 += v * b5; + t9 += v * b6; + t10 += v * b7; + t11 += v * b8; + t12 += v * b9; + t13 += v * b10; + t14 += v * b11; + t15 += v * b12; + t16 += v * b13; + t17 += v * b14; + t18 += v * b15; + v = a[4]; + t4 += v * b0; + t5 += v * b1; + t6 += v * b2; + t7 += v * b3; + t8 += v * b4; + t9 += v * b5; + t10 += v * b6; + t11 += v * b7; + t12 += v * b8; + t13 += v * b9; + t14 += v * b10; + t15 += v * b11; + t16 += v * b12; + t17 += v * b13; + t18 += v * b14; + t19 += v * b15; + v = a[5]; + t5 += v * b0; + t6 += v * b1; + t7 += v * b2; + t8 += v * b3; + t9 += v * b4; + t10 += v * b5; + t11 += v * b6; + t12 += v * b7; + t13 += v * b8; + t14 += v * b9; + t15 += v * b10; + t16 += v * b11; + t17 += v * b12; + t18 += v * b13; + t19 += v * b14; + t20 += v * b15; + v = a[6]; + t6 += v * b0; + t7 += v * b1; + t8 += v * b2; + t9 += v * b3; + t10 += v * b4; + t11 += v * b5; + t12 += v * b6; + t13 += v * b7; + t14 += v * b8; + t15 += v * b9; + t16 += v * b10; + t17 += v * b11; + t18 += v * b12; + t19 += v * b13; + t20 += v * b14; + t21 += v * b15; + v = a[7]; + t7 += v * b0; + t8 += v * b1; + t9 += v * b2; + t10 += v * b3; + t11 += v * b4; + t12 += v * b5; + t13 += v * b6; + t14 += v * b7; + t15 += v * b8; + t16 += v * b9; + t17 += v * b10; + t18 += v * b11; + t19 += v * b12; + t20 += v * b13; + t21 += v * b14; + t22 += v * b15; + v = a[8]; + t8 += v * b0; + t9 += v * b1; + t10 += v * b2; + t11 += v * b3; + t12 += v * b4; + t13 += v * b5; + t14 += v * b6; + t15 += v * b7; + t16 += v * b8; + t17 += v * b9; + t18 += v * b10; + t19 += v * b11; + t20 += v * b12; + t21 += v * b13; + t22 += v * b14; + t23 += v * b15; + v = a[9]; + t9 += v * b0; + t10 += v * b1; + t11 += v * b2; + t12 += v * b3; + t13 += v * b4; + t14 += v * b5; + t15 += v * b6; + t16 += v * b7; + t17 += v * b8; + t18 += v * b9; + t19 += v * b10; + t20 += v * b11; + t21 += v * b12; + t22 += v * b13; + t23 += v * b14; + t24 += v * b15; + v = a[10]; + t10 += v * b0; + t11 += v * b1; + t12 += v * b2; + t13 += v * b3; + t14 += v * b4; + t15 += v * b5; + t16 += v * b6; + t17 += v * b7; + t18 += v * b8; + t19 += v * b9; + t20 += v * b10; + t21 += v * b11; + t22 += v * b12; + t23 += v * b13; + t24 += v * b14; + t25 += v * b15; + v = a[11]; + t11 += v * b0; + t12 += v * b1; + t13 += v * b2; + t14 += v * b3; + t15 += v * b4; + t16 += v * b5; + t17 += v * b6; + t18 += v * b7; + t19 += v * b8; + t20 += v * b9; + t21 += v * b10; + t22 += v * b11; + t23 += v * b12; + t24 += v * b13; + t25 += v * b14; + t26 += v * b15; + v = a[12]; + t12 += v * b0; + t13 += v * b1; + t14 += v * b2; + t15 += v * b3; + t16 += v * b4; + t17 += v * b5; + t18 += v * b6; + t19 += v * b7; + t20 += v * b8; + t21 += v * b9; + t22 += v * b10; + t23 += v * b11; + t24 += v * b12; + t25 += v * b13; + t26 += v * b14; + t27 += v * b15; + v = a[13]; + t13 += v * b0; + t14 += v * b1; + t15 += v * b2; + t16 += v * b3; + t17 += v * b4; + t18 += v * b5; + t19 += v * b6; + t20 += v * b7; + t21 += v * b8; + t22 += v * b9; + t23 += v * b10; + t24 += v * b11; + t25 += v * b12; + t26 += v * b13; + t27 += v * b14; + t28 += v * b15; + v = a[14]; + t14 += v * b0; + t15 += v * b1; + t16 += v * b2; + t17 += v * b3; + t18 += v * b4; + t19 += v * b5; + t20 += v * b6; + t21 += v * b7; + t22 += v * b8; + t23 += v * b9; + t24 += v * b10; + t25 += v * b11; + t26 += v * b12; + t27 += v * b13; + t28 += v * b14; + t29 += v * b15; + v = a[15]; + t15 += v * b0; + t16 += v * b1; + t17 += v * b2; + t18 += v * b3; + t19 += v * b4; + t20 += v * b5; + t21 += v * b6; + t22 += v * b7; + t23 += v * b8; + t24 += v * b9; + t25 += v * b10; + t26 += v * b11; + t27 += v * b12; + t28 += v * b13; + t29 += v * b14; + t30 += v * b15; + + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is + + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} + +function S(o, a) { + M(o, a, a); +} + +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; +} + +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); +} + +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); +} + +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); +} + +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; + +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); +} + +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} + +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; + +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; + + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], + + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; + + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; + + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; + + // add + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // K + h = K[i*2]; + l = K[i*2+1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // w + h = wh[i%16]; + l = wl[i%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; + + // add + h = th; + l = tl; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); + + // add + h = bh3; + l = bl3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = th; + l = tl; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); + + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; + + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; + + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } + + // add + h = ah0; + l = al0; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[0]; + l = hl[0]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); + + h = ah1; + l = al1; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[1]; + l = hl[1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); + + h = ah2; + l = al2; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[2]; + l = hl[2]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); + + h = ah3; + l = al3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[3]; + l = hl[3]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); + + h = ah4; + l = al4; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[4]; + l = hl[4]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); + + h = ah5; + l = al5; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[5]; + l = hl[5]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); + + h = ah6; + l = al6; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[6]; + l = hl[6]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); + + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[7]; + l = hl[7]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); + + pos += 128; + n -= 128; + } + + return n; +} + +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; + + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; + + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; + + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; + + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); + + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + + return 0; +} + +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); + + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); +} + +function cswap(p, q, b) { + var i; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); + } +} + +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; +} + +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); + } +} + +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); +} + +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; + + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + scalarbase(p, d); + pack(pk, p); + + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; +} + +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); + +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = Math.floor((x[j] + 128) / 256); + x[j] -= carry * 256; + } + x[j] += carry; + x[i] = 0; + } + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; + } + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; + } +} + +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); +} + +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; + + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; + + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); + + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); + + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; + } + } + + modL(sm.subarray(32), x); + return smlen; +} + +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); + + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); + + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); + + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; + + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); + + M(r[3], r[0], r[1]); + return 0; +} + +function crypto_sign_open(m, sm, n, pk) { + var i; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; + + if (n < 64) return -1; + + if (unpackneg(q, pk)) return -1; + + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); + + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); + + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } + + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + return n; +} + +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; + +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, + + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES, + + gf: gf, + D: D, + L: L, + pack25519: pack25519, + unpack25519: unpack25519, + M: M, + A: A, + S: S, + Z: Z, + pow2523: pow2523, + add: add, + set25519: set25519, + modL: modL, + scalarmult: scalarmult, + scalarbase: scalarbase, +}; + +/* High-level API */ + +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); +} + +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} + +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} + +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} + +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; + +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; + +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; + +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; + +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; + +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; + +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; + +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; + +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; + +nacl.box.after = nacl.secretbox; + +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; + +nacl.box.open.after = nacl.secretbox.open; + +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; + +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; + +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; + +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; + +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; + +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; + +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; + +nacl.hash.hashLength = crypto_hash_BYTES; + +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; + +nacl.setPRNG = function(fn) { + randombytes = fn; +}; + +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); + } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (true) { + // Node.js. + crypto = __webpack_require__(4); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } + } +})(); + +})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); + + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__(5).default; + + +/***/ }), +/* 4 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 5 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); + +// CONCATENATED MODULE: ./src/runtimes/web/dom/script_receiver_factory.ts +var ScriptReceiverFactory = (function () { + function ScriptReceiverFactory(prefix, name) { + this.lastId = 0; + this.prefix = prefix; + this.name = name; + } + ScriptReceiverFactory.prototype.create = function (callback) { + this.lastId++; + var number = this.lastId; + var id = this.prefix + number; + var name = this.name + '[' + number + ']'; + var called = false; + var callbackWrapper = function () { + if (!called) { + callback.apply(null, arguments); + called = true; + } + }; + this[number] = callbackWrapper; + return { number: number, id: id, name: name, callback: callbackWrapper }; + }; + ScriptReceiverFactory.prototype.remove = function (receiver) { + delete this[receiver.number]; + }; + return ScriptReceiverFactory; +}()); + +var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.ScriptReceivers'); + +// CONCATENATED MODULE: ./src/core/defaults.ts +var Defaults = { + VERSION: "6.0.0", + PROTOCOL: 7, + wsPort: 80, + wssPort: 443, + wsPath: '', + httpHost: 'sockjs.pusher.com', + httpPort: 80, + httpsPort: 443, + httpPath: '/pusher', + stats_host: 'stats.pusher.com', + authEndpoint: '/pusher/auth', + authTransport: 'ajax', + activityTimeout: 120000, + pongTimeout: 30000, + unavailableTimeout: 10000, + cluster: 'mt1', + cdn_http: "http://js.pusher.com", + cdn_https: "https://js.pusher.com", + dependency_suffix: "" +}; +/* harmony default export */ var defaults = (Defaults); + +// CONCATENATED MODULE: ./src/runtimes/web/dom/dependency_loader.ts + + +var dependency_loader_DependencyLoader = (function () { + function DependencyLoader(options) { + this.options = options; + this.receivers = options.receivers || ScriptReceivers; + this.loading = {}; + } + DependencyLoader.prototype.load = function (name, options, callback) { + var self = this; + if (self.loading[name] && self.loading[name].length > 0) { + self.loading[name].push(callback); + } + else { + self.loading[name] = [callback]; + var request = runtime.createScriptRequest(self.getPath(name, options)); + var receiver = self.receivers.create(function (error) { + self.receivers.remove(receiver); + if (self.loading[name]) { + var callbacks = self.loading[name]; + delete self.loading[name]; + var successCallback = function (wasSuccessful) { + if (!wasSuccessful) { + request.cleanup(); + } + }; + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](error, successCallback); + } + } + }); + request.send(receiver); + } + }; + DependencyLoader.prototype.getRoot = function (options) { + var cdn; + var protocol = runtime.getDocument().location.protocol; + if ((options && options.useTLS) || protocol === 'https:') { + cdn = this.options.cdn_https; + } + else { + cdn = this.options.cdn_http; + } + return cdn.replace(/\/*$/, '') + '/' + this.options.version; + }; + DependencyLoader.prototype.getPath = function (name, options) { + return this.getRoot(options) + '/' + name + this.options.suffix + '.js'; + }; + return DependencyLoader; +}()); +/* harmony default export */ var dependency_loader = (dependency_loader_DependencyLoader); + +// CONCATENATED MODULE: ./src/runtimes/web/dom/dependencies.ts + + + +var DependenciesReceivers = new ScriptReceiverFactory('_pusher_dependencies', 'Pusher.DependenciesReceivers'); +var Dependencies = new dependency_loader({ + cdn_http: defaults.cdn_http, + cdn_https: defaults.cdn_https, + version: defaults.VERSION, + suffix: defaults.dependency_suffix, + receivers: DependenciesReceivers +}); + +// CONCATENATED MODULE: ./src/core/base64.ts +function encode(s) { + return btoa(utob(s)); +} +var fromCharCode = String.fromCharCode; +var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +var b64tab = {}; +for (var base64_i = 0, l = b64chars.length; base64_i < l; base64_i++) { + b64tab[b64chars.charAt(base64_i)] = base64_i; +} +var cb_utob = function (c) { + var cc = c.charCodeAt(0); + return cc < 0x80 + ? c + : cc < 0x800 + ? fromCharCode(0xc0 | (cc >>> 6)) + fromCharCode(0x80 | (cc & 0x3f)) + : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + + fromCharCode(0x80 | (cc & 0x3f)); +}; +var utob = function (u) { + return u.replace(/[^\x00-\x7F]/g, cb_utob); +}; +var cb_encode = function (ccc) { + var padlen = [0, 2, 1][ccc.length % 3]; + var ord = (ccc.charCodeAt(0) << 16) | + ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) | + (ccc.length > 2 ? ccc.charCodeAt(2) : 0); + var chars = [ + b64chars.charAt(ord >>> 18), + b64chars.charAt((ord >>> 12) & 63), + padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), + padlen >= 1 ? '=' : b64chars.charAt(ord & 63) + ]; + return chars.join(''); +}; +var btoa = window.btoa || + function (b) { + return b.replace(/[\s\S]{1,3}/g, cb_encode); + }; + +// CONCATENATED MODULE: ./src/core/utils/timers/abstract_timer.ts +var Timer = (function () { + function Timer(set, clear, delay, callback) { + var _this = this; + this.clear = clear; + this.timer = set(function () { + if (_this.timer) { + _this.timer = callback(_this.timer); + } + }, delay); + } + Timer.prototype.isRunning = function () { + return this.timer !== null; + }; + Timer.prototype.ensureAborted = function () { + if (this.timer) { + this.clear(this.timer); + this.timer = null; + } + }; + return Timer; +}()); +/* harmony default export */ var abstract_timer = (Timer); + +// CONCATENATED MODULE: ./src/core/utils/timers/index.ts +var __extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + +function timers_clearTimeout(timer) { + window.clearTimeout(timer); +} +function timers_clearInterval(timer) { + window.clearInterval(timer); +} +var OneOffTimer = (function (_super) { + __extends(OneOffTimer, _super); + function OneOffTimer(delay, callback) { + return _super.call(this, setTimeout, timers_clearTimeout, delay, function (timer) { + callback(); + return null; + }) || this; + } + return OneOffTimer; +}(abstract_timer)); + +var PeriodicTimer = (function (_super) { + __extends(PeriodicTimer, _super); + function PeriodicTimer(delay, callback) { + return _super.call(this, setInterval, timers_clearInterval, delay, function (timer) { + callback(); + return timer; + }) || this; + } + return PeriodicTimer; +}(abstract_timer)); + + +// CONCATENATED MODULE: ./src/core/util.ts + +var Util = { + now: function () { + if (Date.now) { + return Date.now(); + } + else { + return new Date().valueOf(); + } + }, + defer: function (callback) { + return new OneOffTimer(0, callback); + }, + method: function (name) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var boundArguments = Array.prototype.slice.call(arguments, 1); + return function (object) { + return object[name].apply(object, boundArguments.concat(arguments)); + }; + } +}; +/* harmony default export */ var util = (Util); + +// CONCATENATED MODULE: ./src/core/utils/collections.ts + + +function extend(target) { + var sources = []; + for (var _i = 1; _i < arguments.length; _i++) { + sources[_i - 1] = arguments[_i]; + } + for (var i = 0; i < sources.length; i++) { + var extensions = sources[i]; + for (var property in extensions) { + if (extensions[property] && + extensions[property].constructor && + extensions[property].constructor === Object) { + target[property] = extend(target[property] || {}, extensions[property]); + } + else { + target[property] = extensions[property]; + } + } + } + return target; +} +function stringify() { + var m = ['Pusher']; + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] === 'string') { + m.push(arguments[i]); + } + else { + m.push(safeJSONStringify(arguments[i])); + } + } + return m.join(' : '); +} +function arrayIndexOf(array, item) { + var nativeIndexOf = Array.prototype.indexOf; + if (array === null) { + return -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) { + return array.indexOf(item); + } + for (var i = 0, l = array.length; i < l; i++) { + if (array[i] === item) { + return i; + } + } + return -1; +} +function objectApply(object, f) { + for (var key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + f(object[key], key, object); + } + } +} +function keys(object) { + var keys = []; + objectApply(object, function (_, key) { + keys.push(key); + }); + return keys; +} +function values(object) { + var values = []; + objectApply(object, function (value) { + values.push(value); + }); + return values; +} +function apply(array, f, context) { + for (var i = 0; i < array.length; i++) { + f.call(context || window, array[i], i, array); + } +} +function map(array, f) { + var result = []; + for (var i = 0; i < array.length; i++) { + result.push(f(array[i], i, array, result)); + } + return result; +} +function mapObject(object, f) { + var result = {}; + objectApply(object, function (value, key) { + result[key] = f(value); + }); + return result; +} +function filter(array, test) { + test = + test || + function (value) { + return !!value; + }; + var result = []; + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array, result)) { + result.push(array[i]); + } + } + return result; +} +function filterObject(object, test) { + var result = {}; + objectApply(object, function (value, key) { + if ((test && test(value, key, object, result)) || Boolean(value)) { + result[key] = value; + } + }); + return result; +} +function flatten(object) { + var result = []; + objectApply(object, function (value, key) { + result.push([key, value]); + }); + return result; +} +function any(array, test) { + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array)) { + return true; + } + } + return false; +} +function collections_all(array, test) { + for (var i = 0; i < array.length; i++) { + if (!test(array[i], i, array)) { + return false; + } + } + return true; +} +function encodeParamsObject(data) { + return mapObject(data, function (value) { + if (typeof value === 'object') { + value = safeJSONStringify(value); + } + return encodeURIComponent(encode(value.toString())); + }); +} +function buildQueryString(data) { + var params = filterObject(data, function (value) { + return value !== undefined; + }); + var query = map(flatten(encodeParamsObject(params)), util.method('join', '=')).join('&'); + return query; +} +function decycleObject(object) { + var objects = [], paths = []; + return (function derez(value, path) { + var i, name, nu; + switch (typeof value) { + case 'object': + if (!value) { + return null; + } + for (i = 0; i < objects.length; i += 1) { + if (objects[i] === value) { + return { $ref: paths[i] }; + } + } + objects.push(value); + paths.push(path); + if (Object.prototype.toString.apply(value) === '[object Array]') { + nu = []; + for (i = 0; i < value.length; i += 1) { + nu[i] = derez(value[i], path + '[' + i + ']'); + } + } + else { + nu = {}; + for (name in value) { + if (Object.prototype.hasOwnProperty.call(value, name)) { + nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); + } + } + } + return nu; + case 'number': + case 'string': + case 'boolean': + return value; + } + })(object, '$'); +} +function safeJSONStringify(source) { + try { + return JSON.stringify(source); + } + catch (e) { + return JSON.stringify(decycleObject(source)); + } +} + +// CONCATENATED MODULE: ./src/core/logger.ts + + +var logger_Logger = (function () { + function Logger() { + this.globalLog = function (message) { + if (window.console && window.console.log) { + window.console.log(message); + } + }; + } + Logger.prototype.debug = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.log(this.globalLog, args); + }; + Logger.prototype.warn = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.log(this.globalLogWarn, args); + }; + Logger.prototype.error = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.log(this.globalLogError, args); + }; + Logger.prototype.globalLogWarn = function (message) { + if (window.console && window.console.warn) { + window.console.warn(message); + } + else { + this.globalLog(message); + } + }; + Logger.prototype.globalLogError = function (message) { + if (window.console && window.console.error) { + window.console.error(message); + } + else { + this.globalLogWarn(message); + } + }; + Logger.prototype.log = function (defaultLoggingFunction) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var message = stringify.apply(this, arguments); + if (core_pusher.log) { + core_pusher.log(message); + } + else if (core_pusher.logToConsole) { + var log = defaultLoggingFunction.bind(this); + log(message); + } + }; + return Logger; +}()); +/* harmony default export */ var logger = (new logger_Logger()); + +// CONCATENATED MODULE: ./src/core/utils/url_store.ts +var urlStore = { + baseUrl: 'https://pusher.com', + urls: { + authenticationEndpoint: { + path: '/docs/authenticating_users' + }, + javascriptQuickStart: { + path: '/docs/javascript_quick_start' + }, + triggeringClientEvents: { + path: '/docs/client_api_guide/client_events#trigger-events' + }, + encryptedChannelSupport: { + fullUrl: 'https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support' + } + } +}; +var buildLogSuffix = function (key) { + var urlPrefix = 'See:'; + var urlObj = urlStore.urls[key]; + if (!urlObj) + return ''; + var url; + if (urlObj.fullUrl) { + url = urlObj.fullUrl; + } + else if (urlObj.path) { + url = urlStore.baseUrl + urlObj.path; + } + if (!url) + return ''; + return urlPrefix + " " + url; +}; +/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix }); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/auth/xhr_auth.ts + + + +var ajax = function (context, socketId, callback) { + var self = this, xhr; + xhr = runtime.createXHR(); + xhr.open('POST', self.options.authEndpoint, true); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + for (var headerName in this.authOptions.headers) { + xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]); + } + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + var data, parsed = false; + try { + data = JSON.parse(xhr.responseText); + parsed = true; + } + catch (e) { + callback(true, 'JSON returned from auth endpoint was invalid, yet status code was 200. Data was: ' + + xhr.responseText); + } + if (parsed) { + callback(false, data); + } + } + else { + var suffix = url_store.buildLogSuffix('authenticationEndpoint'); + logger.error('Unable to retrieve auth string from auth endpoint - ' + + ("received status " + xhr.status + " from " + self.options.authEndpoint + ". ") + + ("Clients must be authenticated to join private or presence channels. " + suffix)); + callback(true, xhr.status); + } + } + }; + xhr.send(this.composeQuery(socketId)); + return xhr; +}; +/* harmony default export */ var xhr_auth = (ajax); + +// CONCATENATED MODULE: ./src/runtimes/web/auth/jsonp_auth.ts + +var jsonp = function (context, socketId, callback) { + if (this.authOptions.headers !== undefined) { + logger.warn('To send headers with the auth request, you must use AJAX, rather than JSONP.'); + } + var callbackName = context.nextAuthCallbackID.toString(); + context.nextAuthCallbackID++; + var document = context.getDocument(); + var script = document.createElement('script'); + context.auth_callbacks[callbackName] = function (data) { + callback(false, data); + }; + var callback_name = "Pusher.auth_callbacks['" + callbackName + "']"; + script.src = + this.options.authEndpoint + + '?callback=' + + encodeURIComponent(callback_name) + + '&' + + this.composeQuery(socketId); + var head = document.getElementsByTagName('head')[0] || document.documentElement; + head.insertBefore(script, head.firstChild); +}; +/* harmony default export */ var jsonp_auth = (jsonp); + +// CONCATENATED MODULE: ./src/runtimes/web/dom/script_request.ts +var ScriptRequest = (function () { + function ScriptRequest(src) { + this.src = src; + } + ScriptRequest.prototype.send = function (receiver) { + var self = this; + var errorString = 'Error loading ' + self.src; + self.script = document.createElement('script'); + self.script.id = receiver.id; + self.script.src = self.src; + self.script.type = 'text/javascript'; + self.script.charset = 'UTF-8'; + if (self.script.addEventListener) { + self.script.onerror = function () { + receiver.callback(errorString); + }; + self.script.onload = function () { + receiver.callback(null); + }; + } + else { + self.script.onreadystatechange = function () { + if (self.script.readyState === 'loaded' || + self.script.readyState === 'complete') { + receiver.callback(null); + } + }; + } + if (self.script.async === undefined && + document.attachEvent && + /opera/i.test(navigator.userAgent)) { + self.errorScript = document.createElement('script'); + self.errorScript.id = receiver.id + '_error'; + self.errorScript.text = receiver.name + "('" + errorString + "');"; + self.script.async = self.errorScript.async = false; + } + else { + self.script.async = true; + } + var head = document.getElementsByTagName('head')[0]; + head.insertBefore(self.script, head.firstChild); + if (self.errorScript) { + head.insertBefore(self.errorScript, self.script.nextSibling); + } + }; + ScriptRequest.prototype.cleanup = function () { + if (this.script) { + this.script.onload = this.script.onerror = null; + this.script.onreadystatechange = null; + } + if (this.script && this.script.parentNode) { + this.script.parentNode.removeChild(this.script); + } + if (this.errorScript && this.errorScript.parentNode) { + this.errorScript.parentNode.removeChild(this.errorScript); + } + this.script = null; + this.errorScript = null; + }; + return ScriptRequest; +}()); +/* harmony default export */ var script_request = (ScriptRequest); + +// CONCATENATED MODULE: ./src/runtimes/web/dom/jsonp_request.ts + + +var jsonp_request_JSONPRequest = (function () { + function JSONPRequest(url, data) { + this.url = url; + this.data = data; + } + JSONPRequest.prototype.send = function (receiver) { + if (this.request) { + return; + } + var query = buildQueryString(this.data); + var url = this.url + '/' + receiver.number + '?' + query; + this.request = runtime.createScriptRequest(url); + this.request.send(receiver); + }; + JSONPRequest.prototype.cleanup = function () { + if (this.request) { + this.request.cleanup(); + } + }; + return JSONPRequest; +}()); +/* harmony default export */ var jsonp_request = (jsonp_request_JSONPRequest); + +// CONCATENATED MODULE: ./src/runtimes/web/timeline/jsonp_timeline.ts + + +var getAgent = function (sender, useTLS) { + return function (data, callback) { + var scheme = 'http' + (useTLS ? 's' : '') + '://'; + var url = scheme + (sender.host || sender.options.host) + sender.options.path; + var request = runtime.createJSONPRequest(url, data); + var receiver = runtime.ScriptReceivers.create(function (error, result) { + ScriptReceivers.remove(receiver); + request.cleanup(); + if (result && result.host) { + sender.host = result.host; + } + if (callback) { + callback(error, result); + } + }); + request.send(receiver); + }; +}; +var jsonp_timeline_jsonp = { + name: 'jsonp', + getAgent: getAgent +}; +/* harmony default export */ var jsonp_timeline = (jsonp_timeline_jsonp); + +// CONCATENATED MODULE: ./src/core/transports/url_schemes.ts + +function getGenericURL(baseScheme, params, path) { + var scheme = baseScheme + (params.useTLS ? 's' : ''); + var host = params.useTLS ? params.hostTLS : params.hostNonTLS; + return scheme + '://' + host + path; +} +function getGenericPath(key, queryString) { + var path = '/app/' + key; + var query = '?protocol=' + + defaults.PROTOCOL + + '&client=js' + + '&version=' + + defaults.VERSION + + (queryString ? '&' + queryString : ''); + return path + query; +} +var ws = { + getInitial: function (key, params) { + var path = (params.httpPath || '') + getGenericPath(key, 'flash=false'); + return getGenericURL('ws', params, path); + } +}; +var http = { + getInitial: function (key, params) { + var path = (params.httpPath || '/pusher') + getGenericPath(key); + return getGenericURL('http', params, path); + } +}; +var sockjs = { + getInitial: function (key, params) { + return getGenericURL('http', params, params.httpPath || '/pusher'); + }, + getPath: function (key, params) { + return getGenericPath(key); + } +}; + +// CONCATENATED MODULE: ./src/core/events/callback_registry.ts + +var callback_registry_CallbackRegistry = (function () { + function CallbackRegistry() { + this._callbacks = {}; + } + CallbackRegistry.prototype.get = function (name) { + return this._callbacks[prefix(name)]; + }; + CallbackRegistry.prototype.add = function (name, callback, context) { + var prefixedEventName = prefix(name); + this._callbacks[prefixedEventName] = + this._callbacks[prefixedEventName] || []; + this._callbacks[prefixedEventName].push({ + fn: callback, + context: context + }); + }; + CallbackRegistry.prototype.remove = function (name, callback, context) { + if (!name && !callback && !context) { + this._callbacks = {}; + return; + } + var names = name ? [prefix(name)] : keys(this._callbacks); + if (callback || context) { + this.removeCallback(names, callback, context); + } + else { + this.removeAllCallbacks(names); + } + }; + CallbackRegistry.prototype.removeCallback = function (names, callback, context) { + apply(names, function (name) { + this._callbacks[name] = filter(this._callbacks[name] || [], function (binding) { + return ((callback && callback !== binding.fn) || + (context && context !== binding.context)); + }); + if (this._callbacks[name].length === 0) { + delete this._callbacks[name]; + } + }, this); + }; + CallbackRegistry.prototype.removeAllCallbacks = function (names) { + apply(names, function (name) { + delete this._callbacks[name]; + }, this); + }; + return CallbackRegistry; +}()); +/* harmony default export */ var callback_registry = (callback_registry_CallbackRegistry); +function prefix(name) { + return '_' + name; +} + +// CONCATENATED MODULE: ./src/core/events/dispatcher.ts + + +var dispatcher_Dispatcher = (function () { + function Dispatcher(failThrough) { + this.callbacks = new callback_registry(); + this.global_callbacks = []; + this.failThrough = failThrough; + } + Dispatcher.prototype.bind = function (eventName, callback, context) { + this.callbacks.add(eventName, callback, context); + return this; + }; + Dispatcher.prototype.bind_global = function (callback) { + this.global_callbacks.push(callback); + return this; + }; + Dispatcher.prototype.unbind = function (eventName, callback, context) { + this.callbacks.remove(eventName, callback, context); + return this; + }; + Dispatcher.prototype.unbind_global = function (callback) { + if (!callback) { + this.global_callbacks = []; + return this; + } + this.global_callbacks = filter(this.global_callbacks || [], function (c) { return c !== callback; }); + return this; + }; + Dispatcher.prototype.unbind_all = function () { + this.unbind(); + this.unbind_global(); + return this; + }; + Dispatcher.prototype.emit = function (eventName, data, metadata) { + for (var i = 0; i < this.global_callbacks.length; i++) { + this.global_callbacks[i](eventName, data); + } + var callbacks = this.callbacks.get(eventName); + var args = []; + if (metadata) { + args.push(data, metadata); + } + else if (data) { + args.push(data); + } + if (callbacks && callbacks.length > 0) { + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || window, args); + } + } + else if (this.failThrough) { + this.failThrough(eventName, data); + } + return this; + }; + return Dispatcher; +}()); +/* harmony default export */ var dispatcher = (dispatcher_Dispatcher); + +// CONCATENATED MODULE: ./src/core/transports/transport_connection.ts +var transport_connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + + +var transport_connection_TransportConnection = (function (_super) { + transport_connection_extends(TransportConnection, _super); + function TransportConnection(hooks, name, priority, key, options) { + var _this = _super.call(this) || this; + _this.initialize = runtime.transportConnectionInitializer; + _this.hooks = hooks; + _this.name = name; + _this.priority = priority; + _this.key = key; + _this.options = options; + _this.state = 'new'; + _this.timeline = options.timeline; + _this.activityTimeout = options.activityTimeout; + _this.id = _this.timeline.generateUniqueID(); + return _this; + } + TransportConnection.prototype.handlesActivityChecks = function () { + return Boolean(this.hooks.handlesActivityChecks); + }; + TransportConnection.prototype.supportsPing = function () { + return Boolean(this.hooks.supportsPing); + }; + TransportConnection.prototype.connect = function () { + var _this = this; + if (this.socket || this.state !== 'initialized') { + return false; + } + var url = this.hooks.urls.getInitial(this.key, this.options); + try { + this.socket = this.hooks.getSocket(url, this.options); + } + catch (e) { + util.defer(function () { + _this.onError(e); + _this.changeState('closed'); + }); + return false; + } + this.bindListeners(); + logger.debug('Connecting', { transport: this.name, url: url }); + this.changeState('connecting'); + return true; + }; + TransportConnection.prototype.close = function () { + if (this.socket) { + this.socket.close(); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.send = function (data) { + var _this = this; + if (this.state === 'open') { + util.defer(function () { + if (_this.socket) { + _this.socket.send(data); + } + }); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.ping = function () { + if (this.state === 'open' && this.supportsPing()) { + this.socket.ping(); + } + }; + TransportConnection.prototype.onOpen = function () { + if (this.hooks.beforeOpen) { + this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); + } + this.changeState('open'); + this.socket.onopen = undefined; + }; + TransportConnection.prototype.onError = function (error) { + this.emit('error', { type: 'WebSocketError', error: error }); + this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); + }; + TransportConnection.prototype.onClose = function (closeEvent) { + if (closeEvent) { + this.changeState('closed', { + code: closeEvent.code, + reason: closeEvent.reason, + wasClean: closeEvent.wasClean + }); + } + else { + this.changeState('closed'); + } + this.unbindListeners(); + this.socket = undefined; + }; + TransportConnection.prototype.onMessage = function (message) { + this.emit('message', message); + }; + TransportConnection.prototype.onActivity = function () { + this.emit('activity'); + }; + TransportConnection.prototype.bindListeners = function () { + var _this = this; + this.socket.onopen = function () { + _this.onOpen(); + }; + this.socket.onerror = function (error) { + _this.onError(error); + }; + this.socket.onclose = function (closeEvent) { + _this.onClose(closeEvent); + }; + this.socket.onmessage = function (message) { + _this.onMessage(message); + }; + if (this.supportsPing()) { + this.socket.onactivity = function () { + _this.onActivity(); + }; + } + }; + TransportConnection.prototype.unbindListeners = function () { + if (this.socket) { + this.socket.onopen = undefined; + this.socket.onerror = undefined; + this.socket.onclose = undefined; + this.socket.onmessage = undefined; + if (this.supportsPing()) { + this.socket.onactivity = undefined; + } + } + }; + TransportConnection.prototype.changeState = function (state, params) { + this.state = state; + this.timeline.info(this.buildTimelineMessage({ + state: state, + params: params + })); + this.emit(state, params); + }; + TransportConnection.prototype.buildTimelineMessage = function (message) { + return extend({ cid: this.id }, message); + }; + return TransportConnection; +}(dispatcher)); +/* harmony default export */ var transport_connection = (transport_connection_TransportConnection); + +// CONCATENATED MODULE: ./src/core/transports/transport.ts + +var transport_Transport = (function () { + function Transport(hooks) { + this.hooks = hooks; + } + Transport.prototype.isSupported = function (environment) { + return this.hooks.isSupported(environment); + }; + Transport.prototype.createConnection = function (name, priority, key, options) { + return new transport_connection(this.hooks, name, priority, key, options); + }; + return Transport; +}()); +/* harmony default export */ var transports_transport = (transport_Transport); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transports.ts + + + + +var WSTransport = new transports_transport({ + urls: ws, + handlesActivityChecks: false, + supportsPing: false, + isInitialized: function () { + return Boolean(runtime.getWebSocketAPI()); + }, + isSupported: function () { + return Boolean(runtime.getWebSocketAPI()); + }, + getSocket: function (url) { + return runtime.createWebSocket(url); + } +}); +var httpConfiguration = { + urls: http, + handlesActivityChecks: false, + supportsPing: true, + isInitialized: function () { + return true; + } +}; +var streamingConfiguration = extend({ + getSocket: function (url) { + return runtime.HTTPFactory.createStreamingSocket(url); + } +}, httpConfiguration); +var pollingConfiguration = extend({ + getSocket: function (url) { + return runtime.HTTPFactory.createPollingSocket(url); + } +}, httpConfiguration); +var xhrConfiguration = { + isSupported: function () { + return runtime.isXHRSupported(); + } +}; +var XHRStreamingTransport = new transports_transport((extend({}, streamingConfiguration, xhrConfiguration))); +var XHRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xhrConfiguration)); +var Transports = { + ws: WSTransport, + xhr_streaming: XHRStreamingTransport, + xhr_polling: XHRPollingTransport +}; +/* harmony default export */ var transports = (Transports); + +// CONCATENATED MODULE: ./src/runtimes/web/transports/transports.ts + + + + + + +var SockJSTransport = new transports_transport({ + file: 'sockjs', + urls: sockjs, + handlesActivityChecks: true, + supportsPing: false, + isSupported: function () { + return true; + }, + isInitialized: function () { + return window.SockJS !== undefined; + }, + getSocket: function (url, options) { + return new window.SockJS(url, null, { + js_path: Dependencies.getPath('sockjs', { + useTLS: options.useTLS + }), + ignore_null_origin: options.ignoreNullOrigin + }); + }, + beforeOpen: function (socket, path) { + socket.send(JSON.stringify({ + path: path + })); + } +}); +var xdrConfiguration = { + isSupported: function (environment) { + var yes = runtime.isXDRSupported(environment.useTLS); + return yes; + } +}; +var XDRStreamingTransport = new transports_transport((extend({}, streamingConfiguration, xdrConfiguration))); +var XDRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xdrConfiguration)); +transports.xdr_streaming = XDRStreamingTransport; +transports.xdr_polling = XDRPollingTransport; +transports.sockjs = SockJSTransport; +/* harmony default export */ var transports_transports = (transports); + +// CONCATENATED MODULE: ./src/runtimes/web/net_info.ts +var net_info_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + +var NetInfo = (function (_super) { + net_info_extends(NetInfo, _super); + function NetInfo() { + var _this = _super.call(this) || this; + var self = _this; + if (window.addEventListener !== undefined) { + window.addEventListener('online', function () { + self.emit('online'); + }, false); + window.addEventListener('offline', function () { + self.emit('offline'); + }, false); + } + return _this; + } + NetInfo.prototype.isOnline = function () { + if (window.navigator.onLine === undefined) { + return true; + } + else { + return window.navigator.onLine; + } + }; + return NetInfo; +}(dispatcher)); + +var net_info_Network = new NetInfo(); + +// CONCATENATED MODULE: ./src/core/transports/assistant_to_the_transport_manager.ts + + +var assistant_to_the_transport_manager_AssistantToTheTransportManager = (function () { + function AssistantToTheTransportManager(manager, transport, options) { + this.manager = manager; + this.transport = transport; + this.minPingDelay = options.minPingDelay; + this.maxPingDelay = options.maxPingDelay; + this.pingDelay = undefined; + } + AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { + var _this = this; + options = extend({}, options, { + activityTimeout: this.pingDelay + }); + var connection = this.transport.createConnection(name, priority, key, options); + var openTimestamp = null; + var onOpen = function () { + connection.unbind('open', onOpen); + connection.bind('closed', onClosed); + openTimestamp = util.now(); + }; + var onClosed = function (closeEvent) { + connection.unbind('closed', onClosed); + if (closeEvent.code === 1002 || closeEvent.code === 1003) { + _this.manager.reportDeath(); + } + else if (!closeEvent.wasClean && openTimestamp) { + var lifespan = util.now() - openTimestamp; + if (lifespan < 2 * _this.maxPingDelay) { + _this.manager.reportDeath(); + _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); + } + } + }; + connection.bind('open', onOpen); + return connection; + }; + AssistantToTheTransportManager.prototype.isSupported = function (environment) { + return this.manager.isAlive() && this.transport.isSupported(environment); + }; + return AssistantToTheTransportManager; +}()); +/* harmony default export */ var assistant_to_the_transport_manager = (assistant_to_the_transport_manager_AssistantToTheTransportManager); + +// CONCATENATED MODULE: ./src/core/connection/protocol/protocol.ts +var Protocol = { + decodeMessage: function (messageEvent) { + try { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { + try { + pusherEventData = JSON.parse(messageData.data); + } + catch (e) { } + } + var pusherEvent = { + event: messageData.event, + channel: messageData.channel, + data: pusherEventData + }; + if (messageData.user_id) { + pusherEvent.user_id = messageData.user_id; + } + return pusherEvent; + } + catch (e) { + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; + } + }, + encodeMessage: function (event) { + return JSON.stringify(event); + }, + processHandshake: function (messageEvent) { + var message = Protocol.decodeMessage(messageEvent); + if (message.event === 'pusher:connection_established') { + if (!message.data.activity_timeout) { + throw 'No activity timeout specified in handshake'; + } + return { + action: 'connected', + id: message.data.socket_id, + activityTimeout: message.data.activity_timeout * 1000 + }; + } + else if (message.event === 'pusher:error') { + return { + action: this.getCloseAction(message.data), + error: this.getCloseError(message.data) + }; + } + else { + throw 'Invalid handshake'; + } + }, + getCloseAction: function (closeEvent) { + if (closeEvent.code < 4000) { + if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { + return 'backoff'; + } + else { + return null; + } + } + else if (closeEvent.code === 4000) { + return 'tls_only'; + } + else if (closeEvent.code < 4100) { + return 'refused'; + } + else if (closeEvent.code < 4200) { + return 'backoff'; + } + else if (closeEvent.code < 4300) { + return 'retry'; + } + else { + return 'refused'; + } + }, + getCloseError: function (closeEvent) { + if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { + return { + type: 'PusherError', + data: { + code: closeEvent.code, + message: closeEvent.reason || closeEvent.message + } + }; + } + else { + return null; + } + } +}; +/* harmony default export */ var protocol_protocol = (Protocol); + +// CONCATENATED MODULE: ./src/core/connection/connection.ts +var connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + +var connection_Connection = (function (_super) { + connection_extends(Connection, _super); + function Connection(id, transport) { + var _this = _super.call(this) || this; + _this.id = id; + _this.transport = transport; + _this.activityTimeout = transport.activityTimeout; + _this.bindListeners(); + return _this; + } + Connection.prototype.handlesActivityChecks = function () { + return this.transport.handlesActivityChecks(); + }; + Connection.prototype.send = function (data) { + return this.transport.send(data); + }; + Connection.prototype.send_event = function (name, data, channel) { + var event = { event: name, data: data }; + if (channel) { + event.channel = channel; + } + logger.debug('Event sent', event); + return this.send(protocol_protocol.encodeMessage(event)); + }; + Connection.prototype.ping = function () { + if (this.transport.supportsPing()) { + this.transport.ping(); + } + else { + this.send_event('pusher:ping', {}); + } + }; + Connection.prototype.close = function () { + this.transport.close(); + }; + Connection.prototype.bindListeners = function () { + var _this = this; + var listeners = { + message: function (messageEvent) { + var pusherEvent; + try { + pusherEvent = protocol_protocol.decodeMessage(messageEvent); + } + catch (e) { + _this.emit('error', { + type: 'MessageParseError', + error: e, + data: messageEvent.data + }); + } + if (pusherEvent !== undefined) { + logger.debug('Event recd', pusherEvent); + switch (pusherEvent.event) { + case 'pusher:error': + _this.emit('error', { + type: 'PusherError', + data: pusherEvent.data + }); + break; + case 'pusher:ping': + _this.emit('ping'); + break; + case 'pusher:pong': + _this.emit('pong'); + break; + } + _this.emit('message', pusherEvent); + } + }, + activity: function () { + _this.emit('activity'); + }, + error: function (error) { + _this.emit('error', { type: 'WebSocketError', error: error }); + }, + closed: function (closeEvent) { + unbindListeners(); + if (closeEvent && closeEvent.code) { + _this.handleCloseEvent(closeEvent); + } + _this.transport = null; + _this.emit('closed'); + } + }; + var unbindListeners = function () { + objectApply(listeners, function (listener, event) { + _this.transport.unbind(event, listener); + }); + }; + objectApply(listeners, function (listener, event) { + _this.transport.bind(event, listener); + }); + }; + Connection.prototype.handleCloseEvent = function (closeEvent) { + var action = protocol_protocol.getCloseAction(closeEvent); + var error = protocol_protocol.getCloseError(closeEvent); + if (error) { + this.emit('error', error); + } + if (action) { + this.emit(action, { action: action, error: error }); + } + }; + return Connection; +}(dispatcher)); +/* harmony default export */ var connection_connection = (connection_Connection); + +// CONCATENATED MODULE: ./src/core/connection/handshake/index.ts + + + +var handshake_Handshake = (function () { + function Handshake(transport, callback) { + this.transport = transport; + this.callback = callback; + this.bindListeners(); + } + Handshake.prototype.close = function () { + this.unbindListeners(); + this.transport.close(); + }; + Handshake.prototype.bindListeners = function () { + var _this = this; + this.onMessage = function (m) { + _this.unbindListeners(); + var result; + try { + result = protocol_protocol.processHandshake(m); + } + catch (e) { + _this.finish('error', { error: e }); + _this.transport.close(); + return; + } + if (result.action === 'connected') { + _this.finish('connected', { + connection: new connection_connection(result.id, _this.transport), + activityTimeout: result.activityTimeout + }); + } + else { + _this.finish(result.action, { error: result.error }); + _this.transport.close(); + } + }; + this.onClosed = function (closeEvent) { + _this.unbindListeners(); + var action = protocol_protocol.getCloseAction(closeEvent) || 'backoff'; + var error = protocol_protocol.getCloseError(closeEvent); + _this.finish(action, { error: error }); + }; + this.transport.bind('message', this.onMessage); + this.transport.bind('closed', this.onClosed); + }; + Handshake.prototype.unbindListeners = function () { + this.transport.unbind('message', this.onMessage); + this.transport.unbind('closed', this.onClosed); + }; + Handshake.prototype.finish = function (action, params) { + this.callback(extend({ transport: this.transport, action: action }, params)); + }; + return Handshake; +}()); +/* harmony default export */ var connection_handshake = (handshake_Handshake); + +// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts + +var pusher_authorizer_PusherAuthorizer = (function () { + function PusherAuthorizer(channel, options) { + this.channel = channel; + var authTransport = options.authTransport; + if (typeof runtime.getAuthorizers()[authTransport] === 'undefined') { + throw "'" + authTransport + "' is not a recognized auth transport"; + } + this.type = authTransport; + this.options = options; + this.authOptions = options.auth || {}; + } + PusherAuthorizer.prototype.composeQuery = function (socketId) { + var query = 'socket_id=' + + encodeURIComponent(socketId) + + '&channel_name=' + + encodeURIComponent(this.channel.name); + for (var i in this.authOptions.params) { + query += + '&' + + encodeURIComponent(i) + + '=' + + encodeURIComponent(this.authOptions.params[i]); + } + return query; + }; + PusherAuthorizer.prototype.authorize = function (socketId, callback) { + PusherAuthorizer.authorizers = + PusherAuthorizer.authorizers || runtime.getAuthorizers(); + PusherAuthorizer.authorizers[this.type].call(this, runtime, socketId, callback); + }; + return PusherAuthorizer; +}()); +/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer); + +// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts + +var timeline_sender_TimelineSender = (function () { + function TimelineSender(timeline, options) { + this.timeline = timeline; + this.options = options || {}; + } + TimelineSender.prototype.send = function (useTLS, callback) { + if (this.timeline.isEmpty()) { + return; + } + this.timeline.send(runtime.TimelineTransport.getAgent(this, useTLS), callback); + }; + return TimelineSender; +}()); +/* harmony default export */ var timeline_sender = (timeline_sender_TimelineSender); + +// CONCATENATED MODULE: ./src/core/errors.ts +var errors_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var BadEventName = (function (_super) { + errors_extends(BadEventName, _super); + function BadEventName(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return BadEventName; +}(Error)); + +var RequestTimedOut = (function (_super) { + errors_extends(RequestTimedOut, _super); + function RequestTimedOut(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return RequestTimedOut; +}(Error)); + +var TransportPriorityTooLow = (function (_super) { + errors_extends(TransportPriorityTooLow, _super); + function TransportPriorityTooLow(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportPriorityTooLow; +}(Error)); + +var TransportClosed = (function (_super) { + errors_extends(TransportClosed, _super); + function TransportClosed(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportClosed; +}(Error)); + +var UnsupportedFeature = (function (_super) { + errors_extends(UnsupportedFeature, _super); + function UnsupportedFeature(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedFeature; +}(Error)); + +var UnsupportedTransport = (function (_super) { + errors_extends(UnsupportedTransport, _super); + function UnsupportedTransport(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedTransport; +}(Error)); + +var UnsupportedStrategy = (function (_super) { + errors_extends(UnsupportedStrategy, _super); + function UnsupportedStrategy(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedStrategy; +}(Error)); + + +// CONCATENATED MODULE: ./src/core/channels/channel.ts +var channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + +var channel_Channel = (function (_super) { + channel_extends(Channel, _super); + function Channel(name, pusher) { + var _this = _super.call(this, function (event, data) { + logger.debug('No callbacks on ' + name + ' for ' + event); + }) || this; + _this.name = name; + _this.pusher = pusher; + _this.subscribed = false; + _this.subscriptionPending = false; + _this.subscriptionCancelled = false; + return _this; + } + Channel.prototype.authorize = function (socketId, callback) { + return callback(false, { auth: '' }); + }; + Channel.prototype.trigger = function (event, data) { + if (event.indexOf('client-') !== 0) { + throw new BadEventName("Event '" + event + "' does not start with 'client-'"); + } + if (!this.subscribed) { + var suffix = url_store.buildLogSuffix('triggeringClientEvents'); + logger.warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); + } + return this.pusher.send_event(event, data, this.name); + }; + Channel.prototype.disconnect = function () { + this.subscribed = false; + this.subscriptionPending = false; + }; + Channel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName === 'pusher_internal:subscription_succeeded') { + this.handleSubscriptionSucceededEvent(event); + } + else if (eventName.indexOf('pusher_internal:') !== 0) { + var metadata = {}; + this.emit(eventName, data, metadata); + } + }; + Channel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.emit('pusher:subscription_succeeded', event.data); + } + }; + Channel.prototype.subscribe = function () { + var _this = this; + if (this.subscribed) { + return; + } + this.subscriptionPending = true; + this.subscriptionCancelled = false; + this.authorize(this.pusher.connection.socket_id, function (error, data) { + if (error) { + logger.error(data); + _this.emit('pusher:subscription_error', data); + } + else { + data = data; + _this.pusher.send_event('pusher:subscribe', { + auth: data.auth, + channel_data: data.channel_data, + channel: _this.name + }); + } + }); + }; + Channel.prototype.unsubscribe = function () { + this.subscribed = false; + this.pusher.send_event('pusher:unsubscribe', { + channel: this.name + }); + }; + Channel.prototype.cancelSubscription = function () { + this.subscriptionCancelled = true; + }; + Channel.prototype.reinstateSubscription = function () { + this.subscriptionCancelled = false; + }; + return Channel; +}(dispatcher)); +/* harmony default export */ var channels_channel = (channel_Channel); + +// CONCATENATED MODULE: ./src/core/channels/private_channel.ts +var private_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var private_channel_PrivateChannel = (function (_super) { + private_channel_extends(PrivateChannel, _super); + function PrivateChannel() { + return _super !== null && _super.apply(this, arguments) || this; + } + PrivateChannel.prototype.authorize = function (socketId, callback) { + var authorizer = factory.createAuthorizer(this, this.pusher.config); + return authorizer.authorize(socketId, callback); + }; + return PrivateChannel; +}(channels_channel)); +/* harmony default export */ var private_channel = (private_channel_PrivateChannel); + +// CONCATENATED MODULE: ./src/core/channels/members.ts + +var members_Members = (function () { + function Members() { + this.reset(); + } + Members.prototype.get = function (id) { + if (Object.prototype.hasOwnProperty.call(this.members, id)) { + return { + id: id, + info: this.members[id] + }; + } + else { + return null; + } + }; + Members.prototype.each = function (callback) { + var _this = this; + objectApply(this.members, function (member, id) { + callback(_this.get(id)); + }); + }; + Members.prototype.setMyID = function (id) { + this.myID = id; + }; + Members.prototype.onSubscription = function (subscriptionData) { + this.members = subscriptionData.presence.hash; + this.count = subscriptionData.presence.count; + this.me = this.get(this.myID); + }; + Members.prototype.addMember = function (memberData) { + if (this.get(memberData.user_id) === null) { + this.count++; + } + this.members[memberData.user_id] = memberData.user_info; + return this.get(memberData.user_id); + }; + Members.prototype.removeMember = function (memberData) { + var member = this.get(memberData.user_id); + if (member) { + delete this.members[memberData.user_id]; + this.count--; + } + return member; + }; + Members.prototype.reset = function () { + this.members = {}; + this.count = 0; + this.myID = null; + this.me = null; + }; + return Members; +}()); +/* harmony default export */ var members = (members_Members); + +// CONCATENATED MODULE: ./src/core/channels/presence_channel.ts +var presence_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + +var presence_channel_PresenceChannel = (function (_super) { + presence_channel_extends(PresenceChannel, _super); + function PresenceChannel(name, pusher) { + var _this = _super.call(this, name, pusher) || this; + _this.members = new members(); + return _this; + } + PresenceChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (!error) { + authData = authData; + if (authData.channel_data === undefined) { + var suffix = url_store.buildLogSuffix('authenticationEndpoint'); + logger.error("Invalid auth response for channel '" + _this.name + "'," + + ("expected 'channel_data' field. " + suffix)); + callback('Invalid auth response'); + return; + } + var channelData = JSON.parse(authData.channel_data); + _this.members.setMyID(channelData.user_id); + } + callback(error, authData); + }); + }; + PresenceChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + if (eventName.indexOf('pusher_internal:') === 0) { + this.handleInternalEvent(event); + } + else { + var data = event.data; + var metadata = {}; + if (event.user_id) { + metadata.user_id = event.user_id; + } + this.emit(eventName, data, metadata); + } + }; + PresenceChannel.prototype.handleInternalEvent = function (event) { + var eventName = event.event; + var data = event.data; + switch (eventName) { + case 'pusher_internal:subscription_succeeded': + this.handleSubscriptionSucceededEvent(event); + break; + case 'pusher_internal:member_added': + var addedMember = this.members.addMember(data); + this.emit('pusher:member_added', addedMember); + break; + case 'pusher_internal:member_removed': + var removedMember = this.members.removeMember(data); + if (removedMember) { + this.emit('pusher:member_removed', removedMember); + } + break; + } + }; + PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.members.onSubscription(event.data); + this.emit('pusher:subscription_succeeded', this.members); + } + }; + PresenceChannel.prototype.disconnect = function () { + this.members.reset(); + _super.prototype.disconnect.call(this); + }; + return PresenceChannel; +}(private_channel)); +/* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); + +// EXTERNAL MODULE: ./node_modules/@stablelib/utf8/lib/utf8.js +var utf8 = __webpack_require__(1); + +// EXTERNAL MODULE: ./node_modules/@stablelib/base64/lib/base64.js +var base64 = __webpack_require__(0); + +// CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts +var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + + +var encrypted_channel_EncryptedChannel = (function (_super) { + encrypted_channel_extends(EncryptedChannel, _super); + function EncryptedChannel(name, pusher, nacl) { + var _this = _super.call(this, name, pusher) || this; + _this.key = null; + _this.nacl = nacl; + return _this; + } + EncryptedChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (error) { + callback(true, authData); + return; + } + var sharedSecret = authData['shared_secret']; + if (!sharedSecret) { + var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; + callback(true, errorMsg); + return; + } + _this.key = Object(base64["decode"])(sharedSecret); + delete authData['shared_secret']; + callback(false, authData); + }); + }; + EncryptedChannel.prototype.trigger = function (event, data) { + throw new UnsupportedFeature('Client events are not currently supported for encrypted channels'); + }; + EncryptedChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName.indexOf('pusher_internal:') === 0 || + eventName.indexOf('pusher:') === 0) { + _super.prototype.handleEvent.call(this, event); + return; + } + this.handleEncryptedEvent(eventName, data); + }; + EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { + var _this = this; + if (!this.key) { + logger.debug('Received encrypted event before key has been retrieved from the authEndpoint'); + return; + } + if (!data.ciphertext || !data.nonce) { + logger.error('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + + data); + return; + } + var cipherText = Object(base64["decode"])(data.ciphertext); + if (cipherText.length < this.nacl.secretbox.overheadLength) { + logger.error("Expected encrypted event ciphertext length to be " + this.nacl.secretbox.overheadLength + ", got: " + cipherText.length); + return; + } + var nonce = Object(base64["decode"])(data.nonce); + if (nonce.length < this.nacl.secretbox.nonceLength) { + logger.error("Expected encrypted event nonce length to be " + this.nacl.secretbox.nonceLength + ", got: " + nonce.length); + return; + } + var bytes = this.nacl.secretbox.open(cipherText, nonce, this.key); + if (bytes === null) { + logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); + this.authorize(this.pusher.connection.socket_id, function (error, authData) { + if (error) { + logger.error("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); + return; + } + bytes = _this.nacl.secretbox.open(cipherText, nonce, _this.key); + if (bytes === null) { + logger.error("Failed to decrypt event with new key. Dropping encrypted event"); + return; + } + _this.emitJSON(event, Object(utf8["decode"])(bytes)); + return; + }); + return; + } + this.emitJSON(event, Object(utf8["decode"])(bytes)); + }; + EncryptedChannel.prototype.emitJSON = function (eventName, data) { + try { + this.emit(eventName, JSON.parse(data)); + } + catch (e) { + this.emit(eventName, data); + } + return this; + }; + return EncryptedChannel; +}(private_channel)); +/* harmony default export */ var encrypted_channel = (encrypted_channel_EncryptedChannel); + +// CONCATENATED MODULE: ./src/core/connection/connection_manager.ts +var connection_manager_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + + +var connection_manager_ConnectionManager = (function (_super) { + connection_manager_extends(ConnectionManager, _super); + function ConnectionManager(key, options) { + var _this = _super.call(this) || this; + _this.state = 'initialized'; + _this.connection = null; + _this.key = key; + _this.options = options; + _this.timeline = _this.options.timeline; + _this.usingTLS = _this.options.useTLS; + _this.errorCallbacks = _this.buildErrorCallbacks(); + _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); + _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); + var Network = runtime.getNetwork(); + Network.bind('online', function () { + _this.timeline.info({ netinfo: 'online' }); + if (_this.state === 'connecting' || _this.state === 'unavailable') { + _this.retryIn(0); + } + }); + Network.bind('offline', function () { + _this.timeline.info({ netinfo: 'offline' }); + if (_this.connection) { + _this.sendActivityCheck(); + } + }); + _this.updateStrategy(); + return _this; + } + ConnectionManager.prototype.connect = function () { + if (this.connection || this.runner) { + return; + } + if (!this.strategy.isSupported()) { + this.updateState('failed'); + return; + } + this.updateState('connecting'); + this.startConnecting(); + this.setUnavailableTimer(); + }; + ConnectionManager.prototype.send = function (data) { + if (this.connection) { + return this.connection.send(data); + } + else { + return false; + } + }; + ConnectionManager.prototype.send_event = function (name, data, channel) { + if (this.connection) { + return this.connection.send_event(name, data, channel); + } + else { + return false; + } + }; + ConnectionManager.prototype.disconnect = function () { + this.disconnectInternally(); + this.updateState('disconnected'); + }; + ConnectionManager.prototype.isUsingTLS = function () { + return this.usingTLS; + }; + ConnectionManager.prototype.startConnecting = function () { + var _this = this; + var callback = function (error, handshake) { + if (error) { + _this.runner = _this.strategy.connect(0, callback); + } + else { + if (handshake.action === 'error') { + _this.emit('error', { + type: 'HandshakeError', + error: handshake.error + }); + _this.timeline.error({ handshakeError: handshake.error }); + } + else { + _this.abortConnecting(); + _this.handshakeCallbacks[handshake.action](handshake); + } + } + }; + this.runner = this.strategy.connect(0, callback); + }; + ConnectionManager.prototype.abortConnecting = function () { + if (this.runner) { + this.runner.abort(); + this.runner = null; + } + }; + ConnectionManager.prototype.disconnectInternally = function () { + this.abortConnecting(); + this.clearRetryTimer(); + this.clearUnavailableTimer(); + if (this.connection) { + var connection = this.abandonConnection(); + connection.close(); + } + }; + ConnectionManager.prototype.updateStrategy = function () { + this.strategy = this.options.getStrategy({ + key: this.key, + timeline: this.timeline, + useTLS: this.usingTLS + }); + }; + ConnectionManager.prototype.retryIn = function (delay) { + var _this = this; + this.timeline.info({ action: 'retry', delay: delay }); + if (delay > 0) { + this.emit('connecting_in', Math.round(delay / 1000)); + } + this.retryTimer = new OneOffTimer(delay || 0, function () { + _this.disconnectInternally(); + _this.connect(); + }); + }; + ConnectionManager.prototype.clearRetryTimer = function () { + if (this.retryTimer) { + this.retryTimer.ensureAborted(); + this.retryTimer = null; + } + }; + ConnectionManager.prototype.setUnavailableTimer = function () { + var _this = this; + this.unavailableTimer = new OneOffTimer(this.options.unavailableTimeout, function () { + _this.updateState('unavailable'); + }); + }; + ConnectionManager.prototype.clearUnavailableTimer = function () { + if (this.unavailableTimer) { + this.unavailableTimer.ensureAborted(); + } + }; + ConnectionManager.prototype.sendActivityCheck = function () { + var _this = this; + this.stopActivityCheck(); + this.connection.ping(); + this.activityTimer = new OneOffTimer(this.options.pongTimeout, function () { + _this.timeline.error({ pong_timed_out: _this.options.pongTimeout }); + _this.retryIn(0); + }); + }; + ConnectionManager.prototype.resetActivityCheck = function () { + var _this = this; + this.stopActivityCheck(); + if (this.connection && !this.connection.handlesActivityChecks()) { + this.activityTimer = new OneOffTimer(this.activityTimeout, function () { + _this.sendActivityCheck(); + }); + } + }; + ConnectionManager.prototype.stopActivityCheck = function () { + if (this.activityTimer) { + this.activityTimer.ensureAborted(); + } + }; + ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { + var _this = this; + return extend({}, errorCallbacks, { + message: function (message) { + _this.resetActivityCheck(); + _this.emit('message', message); + }, + ping: function () { + _this.send_event('pusher:pong', {}); + }, + activity: function () { + _this.resetActivityCheck(); + }, + error: function (error) { + _this.emit('error', { type: 'WebSocketError', error: error }); + }, + closed: function () { + _this.abandonConnection(); + if (_this.shouldRetry()) { + _this.retryIn(1000); + } + } + }); + }; + ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { + var _this = this; + return extend({}, errorCallbacks, { + connected: function (handshake) { + _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity); + _this.clearUnavailableTimer(); + _this.setConnection(handshake.connection); + _this.socket_id = _this.connection.id; + _this.updateState('connected', { socket_id: _this.socket_id }); + } + }); + }; + ConnectionManager.prototype.buildErrorCallbacks = function () { + var _this = this; + var withErrorEmitted = function (callback) { + return function (result) { + if (result.error) { + _this.emit('error', { type: 'WebSocketError', error: result.error }); + } + callback(result); + }; + }; + return { + tls_only: withErrorEmitted(function () { + _this.usingTLS = true; + _this.updateStrategy(); + _this.retryIn(0); + }), + refused: withErrorEmitted(function () { + _this.disconnect(); + }), + backoff: withErrorEmitted(function () { + _this.retryIn(1000); + }), + retry: withErrorEmitted(function () { + _this.retryIn(0); + }) + }; + }; + ConnectionManager.prototype.setConnection = function (connection) { + this.connection = connection; + for (var event in this.connectionCallbacks) { + this.connection.bind(event, this.connectionCallbacks[event]); + } + this.resetActivityCheck(); + }; + ConnectionManager.prototype.abandonConnection = function () { + if (!this.connection) { + return; + } + this.stopActivityCheck(); + for (var event in this.connectionCallbacks) { + this.connection.unbind(event, this.connectionCallbacks[event]); + } + var connection = this.connection; + this.connection = null; + return connection; + }; + ConnectionManager.prototype.updateState = function (newState, data) { + var previousState = this.state; + this.state = newState; + if (previousState !== newState) { + var newStateDescription = newState; + if (newStateDescription === 'connected') { + newStateDescription += ' with new socket ID ' + data.socket_id; + } + logger.debug('State changed', previousState + ' -> ' + newStateDescription); + this.timeline.info({ state: newState, params: data }); + this.emit('state_change', { previous: previousState, current: newState }); + this.emit(newState, data); + } + }; + ConnectionManager.prototype.shouldRetry = function () { + return this.state === 'connecting' || this.state === 'connected'; + }; + return ConnectionManager; +}(dispatcher)); +/* harmony default export */ var connection_manager = (connection_manager_ConnectionManager); + +// CONCATENATED MODULE: ./src/core/channels/channels.ts + + + + +var channels_Channels = (function () { + function Channels() { + this.channels = {}; + } + Channels.prototype.add = function (name, pusher) { + if (!this.channels[name]) { + this.channels[name] = createChannel(name, pusher); + } + return this.channels[name]; + }; + Channels.prototype.all = function () { + return values(this.channels); + }; + Channels.prototype.find = function (name) { + return this.channels[name]; + }; + Channels.prototype.remove = function (name) { + var channel = this.channels[name]; + delete this.channels[name]; + return channel; + }; + Channels.prototype.disconnect = function () { + objectApply(this.channels, function (channel) { + channel.disconnect(); + }); + }; + return Channels; +}()); +/* harmony default export */ var channels = (channels_Channels); +function createChannel(name, pusher) { + if (name.indexOf('private-encrypted-') === 0) { + if (pusher.config.nacl) { + return factory.createEncryptedChannel(name, pusher, pusher.config.nacl); + } + var errMsg = 'Tried to subscribe to a private-encrypted- channel but no nacl implementation available'; + var suffix = url_store.buildLogSuffix('encryptedChannelSupport'); + throw new UnsupportedFeature(errMsg + ". " + suffix); + } + else if (name.indexOf('private-') === 0) { + return factory.createPrivateChannel(name, pusher); + } + else if (name.indexOf('presence-') === 0) { + return factory.createPresenceChannel(name, pusher); + } + else { + return factory.createChannel(name, pusher); + } +} + +// CONCATENATED MODULE: ./src/core/utils/factory.ts + + + + + + + + + + +var Factory = { + createChannels: function () { + return new channels(); + }, + createConnectionManager: function (key, options) { + return new connection_manager(key, options); + }, + createChannel: function (name, pusher) { + return new channels_channel(name, pusher); + }, + createPrivateChannel: function (name, pusher) { + return new private_channel(name, pusher); + }, + createPresenceChannel: function (name, pusher) { + return new presence_channel(name, pusher); + }, + createEncryptedChannel: function (name, pusher, nacl) { + return new encrypted_channel(name, pusher, nacl); + }, + createTimelineSender: function (timeline, options) { + return new timeline_sender(timeline, options); + }, + createAuthorizer: function (channel, options) { + if (options.authorizer) { + return options.authorizer(channel, options); + } + return new pusher_authorizer(channel, options); + }, + createHandshake: function (transport, callback) { + return new connection_handshake(transport, callback); + }, + createAssistantToTheTransportManager: function (manager, transport, options) { + return new assistant_to_the_transport_manager(manager, transport, options); + } +}; +/* harmony default export */ var factory = (Factory); + +// CONCATENATED MODULE: ./src/core/transports/transport_manager.ts + +var transport_manager_TransportManager = (function () { + function TransportManager(options) { + this.options = options || {}; + this.livesLeft = this.options.lives || Infinity; + } + TransportManager.prototype.getAssistant = function (transport) { + return factory.createAssistantToTheTransportManager(this, transport, { + minPingDelay: this.options.minPingDelay, + maxPingDelay: this.options.maxPingDelay + }); + }; + TransportManager.prototype.isAlive = function () { + return this.livesLeft > 0; + }; + TransportManager.prototype.reportDeath = function () { + this.livesLeft -= 1; + }; + return TransportManager; +}()); +/* harmony default export */ var transport_manager = (transport_manager_TransportManager); + +// CONCATENATED MODULE: ./src/core/strategies/sequential_strategy.ts + + + +var sequential_strategy_SequentialStrategy = (function () { + function SequentialStrategy(strategies, options) { + this.strategies = strategies; + this.loop = Boolean(options.loop); + this.failFast = Boolean(options.failFast); + this.timeout = options.timeout; + this.timeoutLimit = options.timeoutLimit; + } + SequentialStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method('isSupported')); + }; + SequentialStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + var strategies = this.strategies; + var current = 0; + var timeout = this.timeout; + var runner = null; + var tryNextStrategy = function (error, handshake) { + if (handshake) { + callback(null, handshake); + } + else { + current = current + 1; + if (_this.loop) { + current = current % strategies.length; + } + if (current < strategies.length) { + if (timeout) { + timeout = timeout * 2; + if (_this.timeoutLimit) { + timeout = Math.min(timeout, _this.timeoutLimit); + } + } + runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); + } + else { + callback(true); + } + } + }; + runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { + var timer = null; + var runner = null; + if (options.timeout > 0) { + timer = new OneOffTimer(options.timeout, function () { + runner.abort(); + callback(true); + }); + } + runner = strategy.connect(minPriority, function (error, handshake) { + if (error && timer && timer.isRunning() && !options.failFast) { + return; + } + if (timer) { + timer.ensureAborted(); + } + callback(error, handshake); + }); + return { + abort: function () { + if (timer) { + timer.ensureAborted(); + } + runner.abort(); + }, + forceMinPriority: function (p) { + runner.forceMinPriority(p); + } + }; + }; + return SequentialStrategy; +}()); +/* harmony default export */ var sequential_strategy = (sequential_strategy_SequentialStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/best_connected_ever_strategy.ts + + +var best_connected_ever_strategy_BestConnectedEverStrategy = (function () { + function BestConnectedEverStrategy(strategies) { + this.strategies = strategies; + } + BestConnectedEverStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method('isSupported')); + }; + BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { + return connect(this.strategies, minPriority, function (i, runners) { + return function (error, handshake) { + runners[i].error = error; + if (error) { + if (allRunnersFailed(runners)) { + callback(true); + } + return; + } + apply(runners, function (runner) { + runner.forceMinPriority(handshake.transport.priority); + }); + callback(null, handshake); + }; + }); + }; + return BestConnectedEverStrategy; +}()); +/* harmony default export */ var best_connected_ever_strategy = (best_connected_ever_strategy_BestConnectedEverStrategy); +function connect(strategies, minPriority, callbackBuilder) { + var runners = map(strategies, function (strategy, i, _, rs) { + return strategy.connect(minPriority, callbackBuilder(i, rs)); + }); + return { + abort: function () { + apply(runners, abortRunner); + }, + forceMinPriority: function (p) { + apply(runners, function (runner) { + runner.forceMinPriority(p); + }); + } + }; +} +function allRunnersFailed(runners) { + return collections_all(runners, function (runner) { + return Boolean(runner.error); + }); +} +function abortRunner(runner) { + if (!runner.error && !runner.aborted) { + runner.abort(); + runner.aborted = true; + } +} + +// CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts + + + + +var cached_strategy_CachedStrategy = (function () { + function CachedStrategy(strategy, transports, options) { + this.strategy = strategy; + this.transports = transports; + this.ttl = options.ttl || 1800 * 1000; + this.usingTLS = options.useTLS; + this.timeline = options.timeline; + } + CachedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + CachedStrategy.prototype.connect = function (minPriority, callback) { + var usingTLS = this.usingTLS; + var info = fetchTransportCache(usingTLS); + var strategies = [this.strategy]; + if (info && info.timestamp + this.ttl >= util.now()) { + var transport = this.transports[info.transport]; + if (transport) { + this.timeline.info({ + cached: true, + transport: info.transport, + latency: info.latency + }); + strategies.push(new sequential_strategy([transport], { + timeout: info.latency * 2 + 1000, + failFast: true + })); + } + } + var startTimestamp = util.now(); + var runner = strategies + .pop() + .connect(minPriority, function cb(error, handshake) { + if (error) { + flushTransportCache(usingTLS); + if (strategies.length > 0) { + startTimestamp = util.now(); + runner = strategies.pop().connect(minPriority, cb); + } + else { + callback(error); + } + } + else { + storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp); + callback(null, handshake); + } + }); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + return CachedStrategy; +}()); +/* harmony default export */ var cached_strategy = (cached_strategy_CachedStrategy); +function getTransportCacheKey(usingTLS) { + return 'pusherTransport' + (usingTLS ? 'TLS' : 'NonTLS'); +} +function fetchTransportCache(usingTLS) { + var storage = runtime.getLocalStorage(); + if (storage) { + try { + var serializedCache = storage[getTransportCacheKey(usingTLS)]; + if (serializedCache) { + return JSON.parse(serializedCache); + } + } + catch (e) { + flushTransportCache(usingTLS); + } + } + return null; +} +function storeTransportCache(usingTLS, transport, latency) { + var storage = runtime.getLocalStorage(); + if (storage) { + try { + storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({ + timestamp: util.now(), + transport: transport, + latency: latency + }); + } + catch (e) { + } + } +} +function flushTransportCache(usingTLS) { + var storage = runtime.getLocalStorage(); + if (storage) { + try { + delete storage[getTransportCacheKey(usingTLS)]; + } + catch (e) { + } + } +} + +// CONCATENATED MODULE: ./src/core/strategies/delayed_strategy.ts + +var delayed_strategy_DelayedStrategy = (function () { + function DelayedStrategy(strategy, _a) { + var number = _a.delay; + this.strategy = strategy; + this.options = { delay: number }; + } + DelayedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + DelayedStrategy.prototype.connect = function (minPriority, callback) { + var strategy = this.strategy; + var runner; + var timer = new OneOffTimer(this.options.delay, function () { + runner = strategy.connect(minPriority, callback); + }); + return { + abort: function () { + timer.ensureAborted(); + if (runner) { + runner.abort(); + } + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + return DelayedStrategy; +}()); +/* harmony default export */ var delayed_strategy = (delayed_strategy_DelayedStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/if_strategy.ts +var IfStrategy = (function () { + function IfStrategy(test, trueBranch, falseBranch) { + this.test = test; + this.trueBranch = trueBranch; + this.falseBranch = falseBranch; + } + IfStrategy.prototype.isSupported = function () { + var branch = this.test() ? this.trueBranch : this.falseBranch; + return branch.isSupported(); + }; + IfStrategy.prototype.connect = function (minPriority, callback) { + var branch = this.test() ? this.trueBranch : this.falseBranch; + return branch.connect(minPriority, callback); + }; + return IfStrategy; +}()); +/* harmony default export */ var if_strategy = (IfStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/first_connected_strategy.ts +var FirstConnectedStrategy = (function () { + function FirstConnectedStrategy(strategy) { + this.strategy = strategy; + } + FirstConnectedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + FirstConnectedStrategy.prototype.connect = function (minPriority, callback) { + var runner = this.strategy.connect(minPriority, function (error, handshake) { + if (handshake) { + runner.abort(); + } + callback(error, handshake); + }); + return runner; + }; + return FirstConnectedStrategy; +}()); +/* harmony default export */ var first_connected_strategy = (FirstConnectedStrategy); + +// CONCATENATED MODULE: ./src/runtimes/web/default_strategy.ts + + + + + + + +function testSupportsStrategy(strategy) { + return function () { + return strategy.isSupported(); + }; +} +var getDefaultStrategy = function (config, baseOptions, defineTransport) { + var definedTransports = {}; + function defineTransportStrategy(name, type, priority, options, manager) { + var transport = defineTransport(config, name, type, priority, options, manager); + definedTransports[name] = transport; + return transport; + } + var ws_options = Object.assign({}, baseOptions, { + hostNonTLS: config.wsHost + ':' + config.wsPort, + hostTLS: config.wsHost + ':' + config.wssPort, + httpPath: config.wsPath + }); + var wss_options = Object.assign({}, ws_options, { + useTLS: true + }); + var sockjs_options = Object.assign({}, baseOptions, { + hostNonTLS: config.httpHost + ':' + config.httpPort, + hostTLS: config.httpHost + ':' + config.httpsPort, + httpPath: config.httpPath + }); + var timeouts = { + loop: true, + timeout: 15000, + timeoutLimit: 60000 + }; + var ws_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activityTimeout + }); + var streaming_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activityTimeout + }); + var ws_transport = defineTransportStrategy('ws', 'ws', 3, ws_options, ws_manager); + var wss_transport = defineTransportStrategy('wss', 'ws', 3, wss_options, ws_manager); + var sockjs_transport = defineTransportStrategy('sockjs', 'sockjs', 1, sockjs_options); + var xhr_streaming_transport = defineTransportStrategy('xhr_streaming', 'xhr_streaming', 1, sockjs_options, streaming_manager); + var xdr_streaming_transport = defineTransportStrategy('xdr_streaming', 'xdr_streaming', 1, sockjs_options, streaming_manager); + var xhr_polling_transport = defineTransportStrategy('xhr_polling', 'xhr_polling', 1, sockjs_options); + var xdr_polling_transport = defineTransportStrategy('xdr_polling', 'xdr_polling', 1, sockjs_options); + var ws_loop = new sequential_strategy([ws_transport], timeouts); + var wss_loop = new sequential_strategy([wss_transport], timeouts); + var sockjs_loop = new sequential_strategy([sockjs_transport], timeouts); + var streaming_loop = new sequential_strategy([ + new if_strategy(testSupportsStrategy(xhr_streaming_transport), xhr_streaming_transport, xdr_streaming_transport) + ], timeouts); + var polling_loop = new sequential_strategy([ + new if_strategy(testSupportsStrategy(xhr_polling_transport), xhr_polling_transport, xdr_polling_transport) + ], timeouts); + var http_loop = new sequential_strategy([ + new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([ + streaming_loop, + new delayed_strategy(polling_loop, { delay: 4000 }) + ]), polling_loop) + ], timeouts); + var http_fallback_loop = new if_strategy(testSupportsStrategy(http_loop), http_loop, sockjs_loop); + var wsStrategy; + if (baseOptions.useTLS) { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(http_fallback_loop, { delay: 2000 }) + ]); + } + else { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(wss_loop, { delay: 2000 }), + new delayed_strategy(http_fallback_loop, { delay: 5000 }) + ]); + } + return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, { + ttl: 1800000, + timeline: baseOptions.timeline, + useTLS: baseOptions.useTLS + }); +}; +/* harmony default export */ var default_strategy = (getDefaultStrategy); + +// CONCATENATED MODULE: ./src/runtimes/web/transports/transport_connection_initializer.ts + +/* harmony default export */ var transport_connection_initializer = (function () { + var self = this; + self.timeline.info(self.buildTimelineMessage({ + transport: self.name + (self.options.useTLS ? 's' : '') + })); + if (self.hooks.isInitialized()) { + self.changeState('initialized'); + } + else if (self.hooks.file) { + self.changeState('initializing'); + Dependencies.load(self.hooks.file, { useTLS: self.options.useTLS }, function (error, callback) { + if (self.hooks.isInitialized()) { + self.changeState('initialized'); + callback(true); + } + else { + if (error) { + self.onError(error); + } + self.onClose(); + callback(false); + } + }); + } + else { + self.onClose(); + } +}); + +// CONCATENATED MODULE: ./src/runtimes/web/http/http_xdomain_request.ts + +var http_xdomain_request_hooks = { + getRequest: function (socket) { + var xdr = new window.XDomainRequest(); + xdr.ontimeout = function () { + socket.emit('error', new RequestTimedOut()); + socket.close(); + }; + xdr.onerror = function (e) { + socket.emit('error', e); + socket.close(); + }; + xdr.onprogress = function () { + if (xdr.responseText && xdr.responseText.length > 0) { + socket.onChunk(200, xdr.responseText); + } + }; + xdr.onload = function () { + if (xdr.responseText && xdr.responseText.length > 0) { + socket.onChunk(200, xdr.responseText); + } + socket.emit('finished', 200); + socket.close(); + }; + return xdr; + }, + abortRequest: function (xdr) { + xdr.ontimeout = xdr.onerror = xdr.onprogress = xdr.onload = null; + xdr.abort(); + } +}; +/* harmony default export */ var http_xdomain_request = (http_xdomain_request_hooks); + +// CONCATENATED MODULE: ./src/core/http/http_request.ts +var http_request_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var MAX_BUFFER_LENGTH = 256 * 1024; +var http_request_HTTPRequest = (function (_super) { + http_request_extends(HTTPRequest, _super); + function HTTPRequest(hooks, method, url) { + var _this = _super.call(this) || this; + _this.hooks = hooks; + _this.method = method; + _this.url = url; + return _this; + } + HTTPRequest.prototype.start = function (payload) { + var _this = this; + this.position = 0; + this.xhr = this.hooks.getRequest(this); + this.unloader = function () { + _this.close(); + }; + runtime.addUnloadListener(this.unloader); + this.xhr.open(this.method, this.url, true); + if (this.xhr.setRequestHeader) { + this.xhr.setRequestHeader('Content-Type', 'application/json'); + } + this.xhr.send(payload); + }; + HTTPRequest.prototype.close = function () { + if (this.unloader) { + runtime.removeUnloadListener(this.unloader); + this.unloader = null; + } + if (this.xhr) { + this.hooks.abortRequest(this.xhr); + this.xhr = null; + } + }; + HTTPRequest.prototype.onChunk = function (status, data) { + while (true) { + var chunk = this.advanceBuffer(data); + if (chunk) { + this.emit('chunk', { status: status, data: chunk }); + } + else { + break; + } + } + if (this.isBufferTooLong(data)) { + this.emit('buffer_too_long'); + } + }; + HTTPRequest.prototype.advanceBuffer = function (buffer) { + var unreadData = buffer.slice(this.position); + var endOfLinePosition = unreadData.indexOf('\n'); + if (endOfLinePosition !== -1) { + this.position += endOfLinePosition + 1; + return unreadData.slice(0, endOfLinePosition); + } + else { + return null; + } + }; + HTTPRequest.prototype.isBufferTooLong = function (buffer) { + return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH; + }; + return HTTPRequest; +}(dispatcher)); +/* harmony default export */ var http_request = (http_request_HTTPRequest); + +// CONCATENATED MODULE: ./src/core/http/state.ts +var State; +(function (State) { + State[State["CONNECTING"] = 0] = "CONNECTING"; + State[State["OPEN"] = 1] = "OPEN"; + State[State["CLOSED"] = 3] = "CLOSED"; +})(State || (State = {})); +/* harmony default export */ var state = (State); + +// CONCATENATED MODULE: ./src/core/http/http_socket.ts + + + +var autoIncrement = 1; +var http_socket_HTTPSocket = (function () { + function HTTPSocket(hooks, url) { + this.hooks = hooks; + this.session = randomNumber(1000) + '/' + randomString(8); + this.location = getLocation(url); + this.readyState = state.CONNECTING; + this.openStream(); + } + HTTPSocket.prototype.send = function (payload) { + return this.sendRaw(JSON.stringify([payload])); + }; + HTTPSocket.prototype.ping = function () { + this.hooks.sendHeartbeat(this); + }; + HTTPSocket.prototype.close = function (code, reason) { + this.onClose(code, reason, true); + }; + HTTPSocket.prototype.sendRaw = function (payload) { + if (this.readyState === state.OPEN) { + try { + runtime.createSocketRequest('POST', getUniqueURL(getSendURL(this.location, this.session))).start(payload); + return true; + } + catch (e) { + return false; + } + } + else { + return false; + } + }; + HTTPSocket.prototype.reconnect = function () { + this.closeStream(); + this.openStream(); + }; + HTTPSocket.prototype.onClose = function (code, reason, wasClean) { + this.closeStream(); + this.readyState = state.CLOSED; + if (this.onclose) { + this.onclose({ + code: code, + reason: reason, + wasClean: wasClean + }); + } + }; + HTTPSocket.prototype.onChunk = function (chunk) { + if (chunk.status !== 200) { + return; + } + if (this.readyState === state.OPEN) { + this.onActivity(); + } + var payload; + var type = chunk.data.slice(0, 1); + switch (type) { + case 'o': + payload = JSON.parse(chunk.data.slice(1) || '{}'); + this.onOpen(payload); + break; + case 'a': + payload = JSON.parse(chunk.data.slice(1) || '[]'); + for (var i = 0; i < payload.length; i++) { + this.onEvent(payload[i]); + } + break; + case 'm': + payload = JSON.parse(chunk.data.slice(1) || 'null'); + this.onEvent(payload); + break; + case 'h': + this.hooks.onHeartbeat(this); + break; + case 'c': + payload = JSON.parse(chunk.data.slice(1) || '[]'); + this.onClose(payload[0], payload[1], true); + break; + } + }; + HTTPSocket.prototype.onOpen = function (options) { + if (this.readyState === state.CONNECTING) { + if (options && options.hostname) { + this.location.base = replaceHost(this.location.base, options.hostname); + } + this.readyState = state.OPEN; + if (this.onopen) { + this.onopen(); + } + } + else { + this.onClose(1006, 'Server lost session', true); + } + }; + HTTPSocket.prototype.onEvent = function (event) { + if (this.readyState === state.OPEN && this.onmessage) { + this.onmessage({ data: event }); + } + }; + HTTPSocket.prototype.onActivity = function () { + if (this.onactivity) { + this.onactivity(); + } + }; + HTTPSocket.prototype.onError = function (error) { + if (this.onerror) { + this.onerror(error); + } + }; + HTTPSocket.prototype.openStream = function () { + var _this = this; + this.stream = runtime.createSocketRequest('POST', getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); + this.stream.bind('chunk', function (chunk) { + _this.onChunk(chunk); + }); + this.stream.bind('finished', function (status) { + _this.hooks.onFinished(_this, status); + }); + this.stream.bind('buffer_too_long', function () { + _this.reconnect(); + }); + try { + this.stream.start(); + } + catch (error) { + util.defer(function () { + _this.onError(error); + _this.onClose(1006, 'Could not start streaming', false); + }); + } + }; + HTTPSocket.prototype.closeStream = function () { + if (this.stream) { + this.stream.unbind_all(); + this.stream.close(); + this.stream = null; + } + }; + return HTTPSocket; +}()); +function getLocation(url) { + var parts = /([^\?]*)\/*(\??.*)/.exec(url); + return { + base: parts[1], + queryString: parts[2] + }; +} +function getSendURL(url, session) { + return url.base + '/' + session + '/xhr_send'; +} +function getUniqueURL(url) { + var separator = url.indexOf('?') === -1 ? '?' : '&'; + return url + separator + 't=' + +new Date() + '&n=' + autoIncrement++; +} +function replaceHost(url, hostname) { + var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url); + return urlParts[1] + hostname + urlParts[3]; +} +function randomNumber(max) { + return Math.floor(Math.random() * max); +} +function randomString(length) { + var result = []; + for (var i = 0; i < length; i++) { + result.push(randomNumber(32).toString(32)); + } + return result.join(''); +} +/* harmony default export */ var http_socket = (http_socket_HTTPSocket); + +// CONCATENATED MODULE: ./src/core/http/http_streaming_socket.ts +var http_streaming_socket_hooks = { + getReceiveURL: function (url, session) { + return url.base + '/' + session + '/xhr_streaming' + url.queryString; + }, + onHeartbeat: function (socket) { + socket.sendRaw('[]'); + }, + sendHeartbeat: function (socket) { + socket.sendRaw('[]'); + }, + onFinished: function (socket, status) { + socket.onClose(1006, 'Connection interrupted (' + status + ')', false); + } +}; +/* harmony default export */ var http_streaming_socket = (http_streaming_socket_hooks); + +// CONCATENATED MODULE: ./src/core/http/http_polling_socket.ts +var http_polling_socket_hooks = { + getReceiveURL: function (url, session) { + return url.base + '/' + session + '/xhr' + url.queryString; + }, + onHeartbeat: function () { + }, + sendHeartbeat: function (socket) { + socket.sendRaw('[]'); + }, + onFinished: function (socket, status) { + if (status === 200) { + socket.reconnect(); + } + else { + socket.onClose(1006, 'Connection interrupted (' + status + ')', false); + } + } +}; +/* harmony default export */ var http_polling_socket = (http_polling_socket_hooks); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http_xhr_request.ts + +var http_xhr_request_hooks = { + getRequest: function (socket) { + var Constructor = runtime.getXHRAPI(); + var xhr = new Constructor(); + xhr.onreadystatechange = xhr.onprogress = function () { + switch (xhr.readyState) { + case 3: + if (xhr.responseText && xhr.responseText.length > 0) { + socket.onChunk(xhr.status, xhr.responseText); + } + break; + case 4: + if (xhr.responseText && xhr.responseText.length > 0) { + socket.onChunk(xhr.status, xhr.responseText); + } + socket.emit('finished', xhr.status); + socket.close(); + break; + } + }; + return xhr; + }, + abortRequest: function (xhr) { + xhr.onreadystatechange = null; + xhr.abort(); + } +}; +/* harmony default export */ var http_xhr_request = (http_xhr_request_hooks); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http.ts + + + + + +var HTTP = { + createStreamingSocket: function (url) { + return this.createSocket(http_streaming_socket, url); + }, + createPollingSocket: function (url) { + return this.createSocket(http_polling_socket, url); + }, + createSocket: function (hooks, url) { + return new http_socket(hooks, url); + }, + createXHR: function (method, url) { + return this.createRequest(http_xhr_request, method, url); + }, + createRequest: function (hooks, method, url) { + return new http_request(hooks, method, url); + } +}; +/* harmony default export */ var http_http = (HTTP); + +// CONCATENATED MODULE: ./src/runtimes/web/http/http.ts + + +http_http.createXDR = function (method, url) { + return this.createRequest(http_xdomain_request, method, url); +}; +/* harmony default export */ var web_http_http = (http_http); + +// CONCATENATED MODULE: ./src/runtimes/web/runtime.ts + + + + + + + + + + + + +var Runtime = { + nextAuthCallbackID: 1, + auth_callbacks: {}, + ScriptReceivers: ScriptReceivers, + DependenciesReceivers: DependenciesReceivers, + getDefaultStrategy: default_strategy, + Transports: transports_transports, + transportConnectionInitializer: transport_connection_initializer, + HTTPFactory: web_http_http, + TimelineTransport: jsonp_timeline, + getXHRAPI: function () { + return window.XMLHttpRequest; + }, + getWebSocketAPI: function () { + return window.WebSocket || window.MozWebSocket; + }, + setup: function (PusherClass) { + var _this = this; + window.Pusher = PusherClass; + var initializeOnDocumentBody = function () { + _this.onDocumentBody(PusherClass.ready); + }; + if (!window.JSON) { + Dependencies.load('json2', {}, initializeOnDocumentBody); + } + else { + initializeOnDocumentBody(); + } + }, + getDocument: function () { + return document; + }, + getProtocol: function () { + return this.getDocument().location.protocol; + }, + getAuthorizers: function () { + return { ajax: xhr_auth, jsonp: jsonp_auth }; + }, + onDocumentBody: function (callback) { + var _this = this; + if (document.body) { + callback(); + } + else { + setTimeout(function () { + _this.onDocumentBody(callback); + }, 0); + } + }, + createJSONPRequest: function (url, data) { + return new jsonp_request(url, data); + }, + createScriptRequest: function (src) { + return new script_request(src); + }, + getLocalStorage: function () { + try { + return window.localStorage; + } + catch (e) { + return undefined; + } + }, + createXHR: function () { + if (this.getXHRAPI()) { + return this.createXMLHttpRequest(); + } + else { + return this.createMicrosoftXHR(); + } + }, + createXMLHttpRequest: function () { + var Constructor = this.getXHRAPI(); + return new Constructor(); + }, + createMicrosoftXHR: function () { + return new ActiveXObject('Microsoft.XMLHTTP'); + }, + getNetwork: function () { + return net_info_Network; + }, + createWebSocket: function (url) { + var Constructor = this.getWebSocketAPI(); + return new Constructor(url); + }, + createSocketRequest: function (method, url) { + if (this.isXHRSupported()) { + return this.HTTPFactory.createXHR(method, url); + } + else if (this.isXDRSupported(url.indexOf('https:') === 0)) { + return this.HTTPFactory.createXDR(method, url); + } + else { + throw 'Cross-origin HTTP requests are not supported'; + } + }, + isXHRSupported: function () { + var Constructor = this.getXHRAPI(); + return (Boolean(Constructor) && new Constructor().withCredentials !== undefined); + }, + isXDRSupported: function (useTLS) { + var protocol = useTLS ? 'https:' : 'http:'; + var documentProtocol = this.getProtocol(); + return (Boolean(window['XDomainRequest']) && documentProtocol === protocol); + }, + addUnloadListener: function (listener) { + if (window.addEventListener !== undefined) { + window.addEventListener('unload', listener, false); + } + else if (window.attachEvent !== undefined) { + window.attachEvent('onunload', listener); + } + }, + removeUnloadListener: function (listener) { + if (window.addEventListener !== undefined) { + window.removeEventListener('unload', listener, false); + } + else if (window.detachEvent !== undefined) { + window.detachEvent('onunload', listener); + } + } +}; +/* harmony default export */ var runtime = (Runtime); + +// CONCATENATED MODULE: ./src/core/timeline/level.ts +var TimelineLevel; +(function (TimelineLevel) { + TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; + TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; + TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; +})(TimelineLevel || (TimelineLevel = {})); +/* harmony default export */ var timeline_level = (TimelineLevel); + +// CONCATENATED MODULE: ./src/core/timeline/timeline.ts + + + +var timeline_Timeline = (function () { + function Timeline(key, session, options) { + this.key = key; + this.session = session; + this.events = []; + this.options = options || {}; + this.sent = 0; + this.uniqueID = 0; + } + Timeline.prototype.log = function (level, event) { + if (level <= this.options.level) { + this.events.push(extend({}, event, { timestamp: util.now() })); + if (this.options.limit && this.events.length > this.options.limit) { + this.events.shift(); + } + } + }; + Timeline.prototype.error = function (event) { + this.log(timeline_level.ERROR, event); + }; + Timeline.prototype.info = function (event) { + this.log(timeline_level.INFO, event); + }; + Timeline.prototype.debug = function (event) { + this.log(timeline_level.DEBUG, event); + }; + Timeline.prototype.isEmpty = function () { + return this.events.length === 0; + }; + Timeline.prototype.send = function (sendfn, callback) { + var _this = this; + var data = extend({ + session: this.session, + bundle: this.sent + 1, + key: this.key, + lib: 'js', + version: this.options.version, + cluster: this.options.cluster, + features: this.options.features, + timeline: this.events + }, this.options.params); + this.events = []; + sendfn(data, function (error, result) { + if (!error) { + _this.sent++; + } + if (callback) { + callback(error, result); + } + }); + return true; + }; + Timeline.prototype.generateUniqueID = function () { + this.uniqueID++; + return this.uniqueID; + }; + return Timeline; +}()); +/* harmony default export */ var timeline_timeline = (timeline_Timeline); + +// CONCATENATED MODULE: ./src/core/strategies/transport_strategy.ts + + + + +var transport_strategy_TransportStrategy = (function () { + function TransportStrategy(name, priority, transport, options) { + this.name = name; + this.priority = priority; + this.transport = transport; + this.options = options || {}; + } + TransportStrategy.prototype.isSupported = function () { + return this.transport.isSupported({ + useTLS: this.options.useTLS + }); + }; + TransportStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + if (!this.isSupported()) { + return failAttempt(new UnsupportedStrategy(), callback); + } + else if (this.priority < minPriority) { + return failAttempt(new TransportPriorityTooLow(), callback); + } + var connected = false; + var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options); + var handshake = null; + var onInitialized = function () { + transport.unbind('initialized', onInitialized); + transport.connect(); + }; + var onOpen = function () { + handshake = factory.createHandshake(transport, function (result) { + connected = true; + unbindListeners(); + callback(null, result); + }); + }; + var onError = function (error) { + unbindListeners(); + callback(error); + }; + var onClosed = function () { + unbindListeners(); + var serializedTransport; + serializedTransport = safeJSONStringify(transport); + callback(new TransportClosed(serializedTransport)); + }; + var unbindListeners = function () { + transport.unbind('initialized', onInitialized); + transport.unbind('open', onOpen); + transport.unbind('error', onError); + transport.unbind('closed', onClosed); + }; + transport.bind('initialized', onInitialized); + transport.bind('open', onOpen); + transport.bind('error', onError); + transport.bind('closed', onClosed); + transport.initialize(); + return { + abort: function () { + if (connected) { + return; + } + unbindListeners(); + if (handshake) { + handshake.close(); + } + else { + transport.close(); + } + }, + forceMinPriority: function (p) { + if (connected) { + return; + } + if (_this.priority < p) { + if (handshake) { + handshake.close(); + } + else { + transport.close(); + } + } + } + }; + }; + return TransportStrategy; +}()); +/* harmony default export */ var transport_strategy = (transport_strategy_TransportStrategy); +function failAttempt(error, callback) { + util.defer(function () { + callback(error); + }); + return { + abort: function () { }, + forceMinPriority: function () { } + }; +} + +// CONCATENATED MODULE: ./src/core/strategies/strategy_builder.ts + + + + + +var strategy_builder_Transports = runtime.Transports; +var strategy_builder_defineTransport = function (config, name, type, priority, options, manager) { + var transportClass = strategy_builder_Transports[type]; + if (!transportClass) { + throw new UnsupportedTransport(type); + } + var enabled = (!config.enabledTransports || + arrayIndexOf(config.enabledTransports, name) !== -1) && + (!config.disabledTransports || + arrayIndexOf(config.disabledTransports, name) === -1); + var transport; + if (enabled) { + options = Object.assign({ ignoreNullOrigin: config.ignoreNullOrigin }, options); + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options); + } + else { + transport = strategy_builder_UnsupportedStrategy; + } + return transport; +}; +var strategy_builder_UnsupportedStrategy = { + isSupported: function () { + return false; + }, + connect: function (_, callback) { + var deferred = util.defer(function () { + callback(new UnsupportedStrategy()); + }); + return { + abort: function () { + deferred.ensureAborted(); + }, + forceMinPriority: function () { } + }; + } +}; + +// CONCATENATED MODULE: ./src/core/config.ts + + +function getConfig(opts) { + var config = { + activityTimeout: opts.activityTimeout || defaults.activityTimeout, + authEndpoint: opts.authEndpoint || defaults.authEndpoint, + authTransport: opts.authTransport || defaults.authTransport, + cluster: opts.cluster || defaults.cluster, + httpPath: opts.httpPath || defaults.httpPath, + httpPort: opts.httpPort || defaults.httpPort, + httpsPort: opts.httpsPort || defaults.httpsPort, + pongTimeout: opts.pongTimeout || defaults.pongTimeout, + statsHost: opts.statsHost || defaults.stats_host, + unavailableTimeout: opts.unavailableTimeout || defaults.unavailableTimeout, + wsPath: opts.wsPath || defaults.wsPath, + wsPort: opts.wsPort || defaults.wsPort, + wssPort: opts.wssPort || defaults.wssPort, + enableStats: getEnableStatsConfig(opts), + httpHost: getHttpHost(opts), + useTLS: shouldUseTLS(opts), + wsHost: getWebsocketHost(opts) + }; + if ('auth' in opts) + config.auth = opts.auth; + if ('authorizer' in opts) + config.authorizer = opts.authorizer; + if ('disabledTransports' in opts) + config.disabledTransports = opts.disabledTransports; + if ('enabledTransports' in opts) + config.enabledTransports = opts.enabledTransports; + if ('ignoreNullOrigin' in opts) + config.ignoreNullOrigin = opts.ignoreNullOrigin; + if ('timelineParams' in opts) + config.timelineParams = opts.timelineParams; + if ('nacl' in opts) { + config.nacl = opts.nacl; + } + return config; +} +function getHttpHost(opts) { + if (opts.httpHost) { + return opts.httpHost; + } + if (opts.cluster) { + return "sockjs-" + opts.cluster + ".pusher.com"; + } + return defaults.httpHost; +} +function getWebsocketHost(opts) { + if (opts.wsHost) { + return opts.wsHost; + } + if (opts.cluster) { + return getWebsocketHostFromCluster(opts.cluster); + } + return getWebsocketHostFromCluster(defaults.cluster); +} +function getWebsocketHostFromCluster(cluster) { + return "ws-" + cluster + ".pusher.com"; +} +function shouldUseTLS(opts) { + if (runtime.getProtocol() === 'https:') { + return true; + } + else if (opts.forceTLS === false) { + return false; + } + return true; +} +function getEnableStatsConfig(opts) { + if ('enableStats' in opts) { + return opts.enableStats; + } + if ('disableStats' in opts) { + return !opts.disableStats; + } + return false; +} + +// CONCATENATED MODULE: ./src/core/pusher.ts + + + + + + + + + + + + +var pusher_Pusher = (function () { + function Pusher(app_key, options) { + var _this = this; + checkAppKey(app_key); + options = options || {}; + if (!options.cluster && !(options.wsHost || options.httpHost)) { + var suffix = url_store.buildLogSuffix('javascriptQuickStart'); + logger.warn("You should always specify a cluster when connecting. " + suffix); + } + if ('disableStats' in options) { + logger.warn('The disableStats option is deprecated in favor of enableStats'); + } + this.key = app_key; + this.config = getConfig(options); + this.channels = factory.createChannels(); + this.global_emitter = new dispatcher(); + this.sessionID = Math.floor(Math.random() * 1000000000); + this.timeline = new timeline_timeline(this.key, this.sessionID, { + cluster: this.config.cluster, + features: Pusher.getClientFeatures(), + params: this.config.timelineParams || {}, + limit: 50, + level: timeline_level.INFO, + version: defaults.VERSION + }); + if (this.config.enableStats) { + this.timelineSender = factory.createTimelineSender(this.timeline, { + host: this.config.statsHost, + path: '/timeline/v2/' + runtime.TimelineTransport.name + }); + } + var getStrategy = function (options) { + return runtime.getDefaultStrategy(_this.config, options, strategy_builder_defineTransport); + }; + this.connection = factory.createConnectionManager(this.key, { + getStrategy: getStrategy, + timeline: this.timeline, + activityTimeout: this.config.activityTimeout, + pongTimeout: this.config.pongTimeout, + unavailableTimeout: this.config.unavailableTimeout, + useTLS: Boolean(this.config.useTLS) + }); + this.connection.bind('connected', function () { + _this.subscribeAll(); + if (_this.timelineSender) { + _this.timelineSender.send(_this.connection.isUsingTLS()); + } + }); + this.connection.bind('message', function (event) { + var eventName = event.event; + var internal = eventName.indexOf('pusher_internal:') === 0; + if (event.channel) { + var channel = _this.channel(event.channel); + if (channel) { + channel.handleEvent(event); + } + } + if (!internal) { + _this.global_emitter.emit(event.event, event.data); + } + }); + this.connection.bind('connecting', function () { + _this.channels.disconnect(); + }); + this.connection.bind('disconnected', function () { + _this.channels.disconnect(); + }); + this.connection.bind('error', function (err) { + logger.warn(err); + }); + Pusher.instances.push(this); + this.timeline.info({ instances: Pusher.instances.length }); + if (Pusher.isReady) { + this.connect(); + } + } + Pusher.ready = function () { + Pusher.isReady = true; + for (var i = 0, l = Pusher.instances.length; i < l; i++) { + Pusher.instances[i].connect(); + } + }; + Pusher.getClientFeatures = function () { + return keys(filterObject({ ws: runtime.Transports.ws }, function (t) { + return t.isSupported({}); + })); + }; + Pusher.prototype.channel = function (name) { + return this.channels.find(name); + }; + Pusher.prototype.allChannels = function () { + return this.channels.all(); + }; + Pusher.prototype.connect = function () { + this.connection.connect(); + if (this.timelineSender) { + if (!this.timelineSenderTimer) { + var usingTLS = this.connection.isUsingTLS(); + var timelineSender = this.timelineSender; + this.timelineSenderTimer = new PeriodicTimer(60000, function () { + timelineSender.send(usingTLS); + }); + } + } + }; + Pusher.prototype.disconnect = function () { + this.connection.disconnect(); + if (this.timelineSenderTimer) { + this.timelineSenderTimer.ensureAborted(); + this.timelineSenderTimer = null; + } + }; + Pusher.prototype.bind = function (event_name, callback, context) { + this.global_emitter.bind(event_name, callback, context); + return this; + }; + Pusher.prototype.unbind = function (event_name, callback, context) { + this.global_emitter.unbind(event_name, callback, context); + return this; + }; + Pusher.prototype.bind_global = function (callback) { + this.global_emitter.bind_global(callback); + return this; + }; + Pusher.prototype.unbind_global = function (callback) { + this.global_emitter.unbind_global(callback); + return this; + }; + Pusher.prototype.unbind_all = function (callback) { + this.global_emitter.unbind_all(); + return this; + }; + Pusher.prototype.subscribeAll = function () { + var channelName; + for (channelName in this.channels.channels) { + if (this.channels.channels.hasOwnProperty(channelName)) { + this.subscribe(channelName); + } + } + }; + Pusher.prototype.subscribe = function (channel_name) { + var channel = this.channels.add(channel_name, this); + if (channel.subscriptionPending && channel.subscriptionCancelled) { + channel.reinstateSubscription(); + } + else if (!channel.subscriptionPending && + this.connection.state === 'connected') { + channel.subscribe(); + } + return channel; + }; + Pusher.prototype.unsubscribe = function (channel_name) { + var channel = this.channels.find(channel_name); + if (channel && channel.subscriptionPending) { + channel.cancelSubscription(); + } + else { + channel = this.channels.remove(channel_name); + if (channel && this.connection.state === 'connected') { + channel.unsubscribe(); + } + } + }; + Pusher.prototype.send_event = function (event_name, data, channel) { + return this.connection.send_event(event_name, data, channel); + }; + Pusher.prototype.shouldUseTLS = function () { + return this.config.useTLS; + }; + Pusher.instances = []; + Pusher.isReady = false; + Pusher.logToConsole = false; + Pusher.Runtime = runtime; + Pusher.ScriptReceivers = runtime.ScriptReceivers; + Pusher.DependenciesReceivers = runtime.DependenciesReceivers; + Pusher.auth_callbacks = runtime.auth_callbacks; + return Pusher; +}()); +/* harmony default export */ var core_pusher = (pusher_Pusher); +function checkAppKey(key) { + if (key === null || key === undefined) { + throw 'You must pass your app key when you instantiate Pusher.'; + } +} +runtime.setup(pusher_Pusher); + +// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js +var nacl_fast = __webpack_require__(2); + +// CONCATENATED MODULE: ./src/core/pusher-with-encryption.ts +var pusher_with_encryption_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var pusher_with_encryption_PusherWithEncryption = (function (_super) { + pusher_with_encryption_extends(PusherWithEncryption, _super); + function PusherWithEncryption(app_key, options) { + var _this = this; + core_pusher.logToConsole = PusherWithEncryption.logToConsole; + core_pusher.log = PusherWithEncryption.log; + options = options || {}; + options.nacl = nacl_fast; + _this = _super.call(this, app_key, options) || this; + return _this; + } + return PusherWithEncryption; +}(core_pusher)); +/* harmony default export */ var pusher_with_encryption = __webpack_exports__["default"] = (pusher_with_encryption_PusherWithEncryption); + + +/***/ }) +/******/ ]); +}); \ No newline at end of file diff --git a/dist/web/pusher-with-encryption.min.js b/dist/web/pusher-with-encryption.min.js new file mode 100644 index 000000000..022434bd6 --- /dev/null +++ b/dist/web/pusher-with-encryption.min.js @@ -0,0 +1,8 @@ +/*! + * Pusher JavaScript Library v6.0.0 + * https://pusher.com/ + * + * Copyright 2017, Pusher + * Released under the MIT licence. + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Pusher=e():t.Pusher=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t){void 0===t&&(t="="),this._paddingCharacter=t}return t.prototype.encodedLength=function(t){return this._paddingCharacter?(t+2)/3*4|0:(8*t+5)/6|0},t.prototype.encode=function(t){for(var e="",n=0;n>>18&63),e+=this._encodeByte(r>>>12&63),e+=this._encodeByte(r>>>6&63),e+=this._encodeByte(r>>>0&63)}var o=t.length-n;if(o>0){r=t[n]<<16|(2===o?t[n+1]<<8:0);e+=this._encodeByte(r>>>18&63),e+=this._encodeByte(r>>>12&63),e+=2===o?this._encodeByte(r>>>6&63):this._paddingCharacter||"",e+=this._paddingCharacter||""}return e},t.prototype.maxDecodedLength=function(t){return this._paddingCharacter?t/4*3|0:(6*t+7)/8|0},t.prototype.decodedLength=function(t){return this.maxDecodedLength(t.length-this._getPaddingLength(t))},t.prototype.decode=function(t){if(0===t.length)return new Uint8Array(0);for(var e=this._getPaddingLength(t),n=t.length-e,r=new Uint8Array(this.maxDecodedLength(n)),o=0,i=0,s=0,c=0,a=0,u=0,h=0;i>>4,r[o++]=a<<4|u>>>2,r[o++]=u<<6|h,s|=256&c,s|=256&a,s|=256&u,s|=256&h;if(i>>4,s|=256&c,s|=256&a),i>>2,s|=256&u),i>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-15,e+=62-t>>>8&3,String.fromCharCode(e)},t.prototype._decodeChar=function(t){var e=256;return e+=(42-t&t-44)>>>8&-256+t-43+62,e+=(46-t&t-48)>>>8&-256+t-47+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},t.prototype._getPaddingLength=function(t){var e=0;if(this._paddingCharacter){for(var n=t.length-1;n>=0&&t[n]===this._paddingCharacter;n--)e++;if(t.length<4||e>2)throw new Error("Base64Coder: incorrect padding")}return e},t}();e.Coder=i;var s=new i;e.encode=function(t){return s.encode(t)},e.decode=function(t){return s.decode(t)};var c=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype._encodeByte=function(t){var e=t;return e+=65,e+=25-t>>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-13,e+=62-t>>>8&49,String.fromCharCode(e)},e.prototype._decodeChar=function(t){var e=256;return e+=(44-t&t-46)>>>8&-256+t-45+62,e+=(94-t&t-96)>>>8&-256+t-95+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},e}(i);e.URLSafeCoder=c;var a=new c;e.encodeURLSafe=function(t){return a.encode(t)},e.decodeURLSafe=function(t){return a.decode(t)},e.encodedLength=function(t){return s.encodedLength(t)},e.maxDecodedLength=function(t){return s.maxDecodedLength(t)},e.decodedLength=function(t){return s.decodedLength(t)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r="utf8: invalid source encoding";function o(t){for(var e=0,n=0;n=t.length-1)throw new Error("utf8: invalid string");n++,e+=4}}return e}e.encode=function(t){for(var e=new Uint8Array(o(t)),n=0,r=0;r>6,e[n++]=128|63&i):i<55296?(e[n++]=224|i>>12,e[n++]=128|i>>6&63,e[n++]=128|63&i):(r++,i=(1023&i)<<10,i|=1023&t.charCodeAt(r),i+=65536,e[n++]=240|i>>18,e[n++]=128|i>>12&63,e[n++]=128|i>>6&63,e[n++]=128|63&i)}return e},e.encodedLength=o,e.decode=function(t){for(var e=[],n=0;n=t.length)throw new Error(r);if(128!=(192&(s=t[++n])))throw new Error(r);o=(31&o)<<6|63&s,i=128}else if(o<240){if(n>=t.length-1)throw new Error(r);var s=t[++n],c=t[++n];if(128!=(192&s)||128!=(192&c))throw new Error(r);o=(15&o)<<12|(63&s)<<6|63&c,i=2048}else{if(!(o<248))throw new Error(r);if(n>=t.length-2)throw new Error(r);s=t[++n],c=t[++n];var a=t[++n];if(128!=(192&s)||128!=(192&c)||128!=(192&a))throw new Error(r);o=(15&o)<<18|(63&s)<<12|(63&c)<<6|63&a,i=65536}if(o=55296&&o<=57343)throw new Error(r);if(o>=65536){if(o>1114111)throw new Error(r);o-=65536,e.push(String.fromCharCode(55296|o>>10)),o=56320|1023&o}}e.push(String.fromCharCode(o))}return e.join("")}},function(t,e,n){!function(t){"use strict";var e=function(t){var e,n=new Float64Array(16);if(t)for(e=0;e>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function g(t,e,n,r){return y(t,e,n,r,16)}function v(t,e,n,r){return y(t,e,n,r,32)}function b(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,p=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,w=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,_=i,S=s,k=c,T=a,C=u,P=h,O=p,E=f,A=l,x=d,L=y,R=g,U=v,M=b,j=m,I=w,N=0;N<20;N+=2)_^=(o=(U^=(o=(A^=(o=(C^=(o=_+U|0)<<7|o>>>25)+_|0)<<9|o>>>23)+C|0)<<13|o>>>19)+A|0)<<18|o>>>14,P^=(o=(S^=(o=(M^=(o=(x^=(o=P+S|0)<<7|o>>>25)+P|0)<<9|o>>>23)+x|0)<<13|o>>>19)+M|0)<<18|o>>>14,L^=(o=(O^=(o=(k^=(o=(j^=(o=L+O|0)<<7|o>>>25)+L|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(R^=(o=(E^=(o=(T^=(o=I+R|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+E|0)<<18|o>>>14,_^=(o=(T^=(o=(k^=(o=(S^=(o=_+T|0)<<7|o>>>25)+_|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,P^=(o=(C^=(o=(E^=(o=(O^=(o=P+C|0)<<7|o>>>25)+P|0)<<9|o>>>23)+O|0)<<13|o>>>19)+E|0)<<18|o>>>14,L^=(o=(x^=(o=(A^=(o=(R^=(o=L+x|0)<<7|o>>>25)+L|0)<<9|o>>>23)+R|0)<<13|o>>>19)+A|0)<<18|o>>>14,I^=(o=(j^=(o=(M^=(o=(U^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+U|0)<<13|o>>>19)+M|0)<<18|o>>>14;_=_+i|0,S=S+s|0,k=k+c|0,T=T+a|0,C=C+u|0,P=P+h|0,O=O+p|0,E=E+f|0,A=A+l|0,x=x+d|0,L=L+y|0,R=R+g|0,U=U+v|0,M=M+b|0,j=j+m|0,I=I+w|0,t[0]=_>>>0&255,t[1]=_>>>8&255,t[2]=_>>>16&255,t[3]=_>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=C>>>0&255,t[17]=C>>>8&255,t[18]=C>>>16&255,t[19]=C>>>24&255,t[20]=P>>>0&255,t[21]=P>>>8&255,t[22]=P>>>16&255,t[23]=P>>>24&255,t[24]=O>>>0&255,t[25]=O>>>8&255,t[26]=O>>>16&255,t[27]=O>>>24&255,t[28]=E>>>0&255,t[29]=E>>>8&255,t[30]=E>>>16&255,t[31]=E>>>24&255,t[32]=A>>>0&255,t[33]=A>>>8&255,t[34]=A>>>16&255,t[35]=A>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=L>>>0&255,t[41]=L>>>8&255,t[42]=L>>>16&255,t[43]=L>>>24&255,t[44]=R>>>0&255,t[45]=R>>>8&255,t[46]=R>>>16&255,t[47]=R>>>24&255,t[48]=U>>>0&255,t[49]=U>>>8&255,t[50]=U>>>16&255,t[51]=U>>>24&255,t[52]=M>>>0&255,t[53]=M>>>8&255,t[54]=M>>>16&255,t[55]=M>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function m(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,p=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,w=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,_=0;_<20;_+=2)i^=(o=(v^=(o=(l^=(o=(u^=(o=i+v|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(p^=(o=(c^=(o=(m^=(o=y+p|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+c|0)<<18|o>>>14,w^=(o=(g^=(o=(f^=(o=(a^=(o=w+g|0)<<7|o>>>25)+w|0)<<9|o>>>23)+a|0)<<13|o>>>19)+f|0)<<18|o>>>14,i^=(o=(a^=(o=(c^=(o=(s^=(o=i+a|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+c|0)<<18|o>>>14,h^=(o=(u^=(o=(f^=(o=(p^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+p|0)<<13|o>>>19)+f|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(g^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+g|0)<<13|o>>>19)+l|0)<<18|o>>>14,w^=(o=(m^=(o=(b^=(o=(v^=(o=w+m|0)<<7|o>>>25)+w|0)<<9|o>>>23)+v|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=w>>>0&255,t[13]=w>>>8&255,t[14]=w>>>16&255,t[15]=w>>>24&255,t[16]=p>>>0&255,t[17]=p>>>8&255,t[18]=p>>>16&255,t[19]=p>>>24&255,t[20]=f>>>0&255,t[21]=f>>>8&255,t[22]=f>>>16&255,t[23]=f>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var w=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function _(t,e,n,r,o,i,s){var c,a,u=new Uint8Array(16),h=new Uint8Array(64);for(a=0;a<16;a++)u[a]=0;for(a=0;a<8;a++)u[a]=i[a];for(;o>=64;){for(b(h,u,s,w),a=0;a<64;a++)t[e+a]=n[r+a]^h[a];for(c=1,a=8;a<16;a++)c=c+(255&u[a])|0,u[a]=255&c,c>>>=8;o-=64,e+=64,r+=64}if(o>0)for(b(h,u,s,w),a=0;a=64;){for(b(a,c,o,w),s=0;s<64;s++)t[e+s]=a[s];for(i=1,s=8;s<16;s++)i=i+(255&c[s])|0,c[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(b(a,c,o,w),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),c=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|c<<5),a=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(c>>>8|a<<8),this.r[9]=a>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function P(t,e,n,r,o,i){var s=new C(i);return s.update(n,r,o),s.finish(t,e),0}function O(t,e,n,r,o,i){var s=new Uint8Array(16);return P(s,0,n,r,o,i),g(t,e,s,0)}function E(t,e,n,r,o){var i;if(n<32)return-1;for(T(t,0,e,0,n,r,o),P(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function A(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==O(e,16,e,32,n-32,s))return-1;for(T(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function L(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function R(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function U(t,n){var r,o,i,s=e(),c=e();for(r=0;r<16;r++)c[r]=n[r];for(L(c),L(c),L(c),o=0;o<2;o++){for(s[0]=c[0]-65517,r=1;r<15;r++)s[r]=c[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=c[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,R(c,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&c[r],t[2*r+1]=c[r]>>8}function M(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return U(n,t),U(r,e),v(n,0,r,0)}function j(t){var e=new Uint8Array(32);return U(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function D(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function B(t,e,n){var r,o,i=0,s=0,c=0,a=0,u=0,h=0,p=0,f=0,l=0,d=0,y=0,g=0,v=0,b=0,m=0,w=0,_=0,S=0,k=0,T=0,C=0,P=0,O=0,E=0,A=0,x=0,L=0,R=0,U=0,M=0,j=0,I=n[0],N=n[1],D=n[2],B=n[3],H=n[4],z=n[5],q=n[6],F=n[7],X=n[8],J=n[9],Y=n[10],K=n[11],W=n[12],G=n[13],V=n[14],Q=n[15];i+=(r=e[0])*I,s+=r*N,c+=r*D,a+=r*B,u+=r*H,h+=r*z,p+=r*q,f+=r*F,l+=r*X,d+=r*J,y+=r*Y,g+=r*K,v+=r*W,b+=r*G,m+=r*V,w+=r*Q,s+=(r=e[1])*I,c+=r*N,a+=r*D,u+=r*B,h+=r*H,p+=r*z,f+=r*q,l+=r*F,d+=r*X,y+=r*J,g+=r*Y,v+=r*K,b+=r*W,m+=r*G,w+=r*V,_+=r*Q,c+=(r=e[2])*I,a+=r*N,u+=r*D,h+=r*B,p+=r*H,f+=r*z,l+=r*q,d+=r*F,y+=r*X,g+=r*J,v+=r*Y,b+=r*K,m+=r*W,w+=r*G,_+=r*V,S+=r*Q,a+=(r=e[3])*I,u+=r*N,h+=r*D,p+=r*B,f+=r*H,l+=r*z,d+=r*q,y+=r*F,g+=r*X,v+=r*J,b+=r*Y,m+=r*K,w+=r*W,_+=r*G,S+=r*V,k+=r*Q,u+=(r=e[4])*I,h+=r*N,p+=r*D,f+=r*B,l+=r*H,d+=r*z,y+=r*q,g+=r*F,v+=r*X,b+=r*J,m+=r*Y,w+=r*K,_+=r*W,S+=r*G,k+=r*V,T+=r*Q,h+=(r=e[5])*I,p+=r*N,f+=r*D,l+=r*B,d+=r*H,y+=r*z,g+=r*q,v+=r*F,b+=r*X,m+=r*J,w+=r*Y,_+=r*K,S+=r*W,k+=r*G,T+=r*V,C+=r*Q,p+=(r=e[6])*I,f+=r*N,l+=r*D,d+=r*B,y+=r*H,g+=r*z,v+=r*q,b+=r*F,m+=r*X,w+=r*J,_+=r*Y,S+=r*K,k+=r*W,T+=r*G,C+=r*V,P+=r*Q,f+=(r=e[7])*I,l+=r*N,d+=r*D,y+=r*B,g+=r*H,v+=r*z,b+=r*q,m+=r*F,w+=r*X,_+=r*J,S+=r*Y,k+=r*K,T+=r*W,C+=r*G,P+=r*V,O+=r*Q,l+=(r=e[8])*I,d+=r*N,y+=r*D,g+=r*B,v+=r*H,b+=r*z,m+=r*q,w+=r*F,_+=r*X,S+=r*J,k+=r*Y,T+=r*K,C+=r*W,P+=r*G,O+=r*V,E+=r*Q,d+=(r=e[9])*I,y+=r*N,g+=r*D,v+=r*B,b+=r*H,m+=r*z,w+=r*q,_+=r*F,S+=r*X,k+=r*J,T+=r*Y,C+=r*K,P+=r*W,O+=r*G,E+=r*V,A+=r*Q,y+=(r=e[10])*I,g+=r*N,v+=r*D,b+=r*B,m+=r*H,w+=r*z,_+=r*q,S+=r*F,k+=r*X,T+=r*J,C+=r*Y,P+=r*K,O+=r*W,E+=r*G,A+=r*V,x+=r*Q,g+=(r=e[11])*I,v+=r*N,b+=r*D,m+=r*B,w+=r*H,_+=r*z,S+=r*q,k+=r*F,T+=r*X,C+=r*J,P+=r*Y,O+=r*K,E+=r*W,A+=r*G,x+=r*V,L+=r*Q,v+=(r=e[12])*I,b+=r*N,m+=r*D,w+=r*B,_+=r*H,S+=r*z,k+=r*q,T+=r*F,C+=r*X,P+=r*J,O+=r*Y,E+=r*K,A+=r*W,x+=r*G,L+=r*V,R+=r*Q,b+=(r=e[13])*I,m+=r*N,w+=r*D,_+=r*B,S+=r*H,k+=r*z,T+=r*q,C+=r*F,P+=r*X,O+=r*J,E+=r*Y,A+=r*K,x+=r*W,L+=r*G,R+=r*V,U+=r*Q,m+=(r=e[14])*I,w+=r*N,_+=r*D,S+=r*B,k+=r*H,T+=r*z,C+=r*q,P+=r*F,O+=r*X,E+=r*J,A+=r*Y,x+=r*K,L+=r*W,R+=r*G,U+=r*V,M+=r*Q,w+=(r=e[15])*I,s+=38*(S+=r*D),c+=38*(k+=r*B),a+=38*(T+=r*H),u+=38*(C+=r*z),h+=38*(P+=r*q),p+=38*(O+=r*F),f+=38*(E+=r*X),l+=38*(A+=r*J),d+=38*(x+=r*Y),y+=38*(L+=r*K),g+=38*(R+=r*W),v+=38*(U+=r*G),b+=38*(M+=r*V),m+=38*(j+=r*Q),i=(r=(i+=38*(_+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=c,t[3]=a,t[4]=u,t[5]=h,t[6]=p,t[7]=f,t[8]=l,t[9]=d,t[10]=y,t[11]=g,t[12]=v,t[13]=b,t[14]=m,t[15]=w}function H(t,e){B(t,e,e)}function z(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)H(o,o),2!==r&&4!==r&&B(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function q(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=250;r>=0;r--)H(o,o),1!==r&&B(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function F(t,n,r){var o,i,s=new Uint8Array(32),c=new Float64Array(80),u=e(),h=e(),p=e(),f=e(),l=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(c,r),i=0;i<16;i++)h[i]=c[i],f[i]=u[i]=p[i]=0;for(u[0]=f[0]=1,i=254;i>=0;--i)R(u,h,o=s[i>>>3]>>>(7&i)&1),R(p,f,o),N(l,u,p),D(u,u,p),N(p,h,f),D(h,h,f),H(f,l),H(d,u),B(u,p,u),B(p,h,l),N(l,u,p),D(u,u,p),H(h,u),D(p,f,d),B(u,p,a),N(u,u,f),B(p,p,u),B(u,f,d),B(f,h,c),H(h,l),R(u,h,o),R(p,f,o);for(i=0;i<16;i++)c[i+16]=u[i],c[i+32]=p[i],c[i+48]=h[i],c[i+64]=f[i];var y=c.subarray(32),g=c.subarray(16);return z(y,y),B(g,g,y),U(t,g),0}function X(t,e){return F(t,e,i)}function J(t,e){return r(e,32),X(t,e)}function Y(t,e,n){var r=new Uint8Array(32);return F(r,n,e),m(t,o,r,w)}C.prototype.blocks=function(t,e,n){for(var r,o,i,s,c,a,u,h,p,f,l,d,y,g,v,b,m,w,_,S=this.fin?0:2048,k=this.h[0],T=this.h[1],C=this.h[2],P=this.h[3],O=this.h[4],E=this.h[5],A=this.h[6],x=this.h[7],L=this.h[8],R=this.h[9],U=this.r[0],M=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],D=this.r[5],B=this.r[6],H=this.r[7],z=this.r[8],q=this.r[9];n>=16;)f=p=0,f+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*U,f+=(T+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*q),f+=(C+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*z),f+=(P+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*H),p=(f+=(O+=8191&(s>>>4|(c=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*B))>>>13,f&=8191,f+=(E+=c>>>1&8191)*(5*D),f+=(A+=8191&(c>>>14|(a=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),f+=(x+=8191&(a>>>11|(u=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),f+=(L+=8191&(u>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),l=p+=(f+=(R+=h>>>5|S)*(5*M))>>>13,l+=k*M,l+=T*U,l+=C*(5*q),l+=P*(5*z),p=(l+=O*(5*H))>>>13,l&=8191,l+=E*(5*B),l+=A*(5*D),l+=x*(5*N),l+=L*(5*I),p+=(l+=R*(5*j))>>>13,l&=8191,d=p,d+=k*j,d+=T*M,d+=C*U,d+=P*(5*q),p=(d+=O*(5*z))>>>13,d&=8191,d+=E*(5*H),d+=A*(5*B),d+=x*(5*D),d+=L*(5*N),y=p+=(d+=R*(5*I))>>>13,y+=k*I,y+=T*j,y+=C*M,y+=P*U,p=(y+=O*(5*q))>>>13,y&=8191,y+=E*(5*z),y+=A*(5*H),y+=x*(5*B),y+=L*(5*D),g=p+=(y+=R*(5*N))>>>13,g+=k*N,g+=T*I,g+=C*j,g+=P*M,p=(g+=O*U)>>>13,g&=8191,g+=E*(5*q),g+=A*(5*z),g+=x*(5*H),g+=L*(5*B),v=p+=(g+=R*(5*D))>>>13,v+=k*D,v+=T*N,v+=C*I,v+=P*j,p=(v+=O*M)>>>13,v&=8191,v+=E*U,v+=A*(5*q),v+=x*(5*z),v+=L*(5*H),b=p+=(v+=R*(5*B))>>>13,b+=k*B,b+=T*D,b+=C*N,b+=P*I,p=(b+=O*j)>>>13,b&=8191,b+=E*M,b+=A*U,b+=x*(5*q),b+=L*(5*z),m=p+=(b+=R*(5*H))>>>13,m+=k*H,m+=T*B,m+=C*D,m+=P*N,p=(m+=O*I)>>>13,m&=8191,m+=E*j,m+=A*M,m+=x*U,m+=L*(5*q),w=p+=(m+=R*(5*z))>>>13,w+=k*z,w+=T*H,w+=C*B,w+=P*D,p=(w+=O*N)>>>13,w&=8191,w+=E*I,w+=A*j,w+=x*M,w+=L*U,_=p+=(w+=R*(5*q))>>>13,_+=k*q,_+=T*z,_+=C*H,_+=P*B,p=(_+=O*D)>>>13,_&=8191,_+=E*N,_+=A*I,_+=x*j,_+=L*M,k=f=8191&(p=(p=((p+=(_+=R*U)>>>13)<<2)+p|0)+(f&=8191)|0),T=l+=p>>>=13,C=d&=8191,P=y&=8191,O=g&=8191,E=v&=8191,A=b&=8191,x=m&=8191,L=w&=8191,R=_&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=C,this.h[3]=P,this.h[4]=O,this.h[5]=E,this.h[6]=A,this.h[7]=x,this.h[8]=L,this.h[9]=R},C.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},C.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+W,x[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],L[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=R,i=U,s=M,c=j,a=I,u=N,h=D,B,f=H,l=z,d=q,y=F,g=X,v=J,b=Y,K,P=65535&(C=K),O=C>>>16,E=65535&(T=B),A=T>>>16,P+=65535&(C=(X>>>14|I<<18)^(X>>>18|I<<14)^(I>>>9|X<<23)),O+=C>>>16,E+=65535&(T=(I>>>14|X<<18)^(I>>>18|X<<14)^(X>>>9|I<<23)),A+=T>>>16,P+=65535&(C=X&J^~X&Y),O+=C>>>16,E+=65535&(T=I&N^~I&D),A+=T>>>16,P+=65535&(C=G[2*S+1]),O+=C>>>16,E+=65535&(T=G[2*S]),A+=T>>>16,T=x[S%16],O+=(C=L[S%16])>>>16,E+=65535&T,A+=T>>>16,E+=(O+=(P+=65535&C)>>>16)>>>16,P=65535&(C=_=65535&P|O<<16),O=C>>>16,E=65535&(T=w=65535&E|(A+=E>>>16)<<16),A=T>>>16,P+=65535&(C=(H>>>28|R<<4)^(R>>>2|H<<30)^(R>>>7|H<<25)),O+=C>>>16,E+=65535&(T=(R>>>28|H<<4)^(H>>>2|R<<30)^(H>>>7|R<<25)),A+=T>>>16,O+=(C=H&z^H&q^z&q)>>>16,E+=65535&(T=R&U^R&M^U&M),A+=T>>>16,p=65535&(E+=(O+=(P+=65535&C)>>>16)>>>16)|(A+=E>>>16)<<16,m=65535&P|O<<16,P=65535&(C=y),O=C>>>16,E=65535&(T=c),A=T>>>16,O+=(C=_)>>>16,E+=65535&(T=w),A+=T>>>16,U=o,M=i,j=s,I=c=65535&(E+=(O+=(P+=65535&C)>>>16)>>>16)|(A+=E>>>16)<<16,N=a,D=u,B=h,R=p,z=f,q=l,F=d,X=y=65535&P|O<<16,J=g,Y=v,K=b,H=m,S%16==15)for(k=0;k<16;k++)T=x[k],P=65535&(C=L[k]),O=C>>>16,E=65535&T,A=T>>>16,T=x[(k+9)%16],P+=65535&(C=L[(k+9)%16]),O+=C>>>16,E+=65535&T,A+=T>>>16,w=x[(k+1)%16],P+=65535&(C=((_=L[(k+1)%16])>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25)),O+=C>>>16,E+=65535&(T=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7),A+=T>>>16,w=x[(k+14)%16],O+=(C=((_=L[(k+14)%16])>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26))>>>16,E+=65535&(T=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6),A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,x[k]=65535&E|A<<16,L[k]=65535&P|O<<16;P=65535&(C=H),O=C>>>16,E=65535&(T=R),A=T>>>16,T=t[0],O+=(C=e[0])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[0]=R=65535&E|A<<16,e[0]=H=65535&P|O<<16,P=65535&(C=z),O=C>>>16,E=65535&(T=U),A=T>>>16,T=t[1],O+=(C=e[1])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[1]=U=65535&E|A<<16,e[1]=z=65535&P|O<<16,P=65535&(C=q),O=C>>>16,E=65535&(T=M),A=T>>>16,T=t[2],O+=(C=e[2])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[2]=M=65535&E|A<<16,e[2]=q=65535&P|O<<16,P=65535&(C=F),O=C>>>16,E=65535&(T=j),A=T>>>16,T=t[3],O+=(C=e[3])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[3]=j=65535&E|A<<16,e[3]=F=65535&P|O<<16,P=65535&(C=X),O=C>>>16,E=65535&(T=I),A=T>>>16,T=t[4],O+=(C=e[4])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[4]=I=65535&E|A<<16,e[4]=X=65535&P|O<<16,P=65535&(C=J),O=C>>>16,E=65535&(T=N),A=T>>>16,T=t[5],O+=(C=e[5])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[5]=N=65535&E|A<<16,e[5]=J=65535&P|O<<16,P=65535&(C=Y),O=C>>>16,E=65535&(T=D),A=T>>>16,T=t[6],O+=(C=e[6])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[6]=D=65535&E|A<<16,e[6]=Y=65535&P|O<<16,P=65535&(C=K),O=C>>>16,E=65535&(T=B),A=T>>>16,T=t[7],O+=(C=e[7])>>>16,E+=65535&T,A+=T>>>16,A+=(E+=(O+=(P+=65535&C)>>>16)>>>16)>>>16,t[7]=B=65535&E|A<<16,e[7]=K=65535&P|O<<16,W+=128,r-=128}return r}function Q(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),c=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,V(o,i,e,n),n%=128,r=0;r=0;--o)$(t,e,r=n[o/8|0]>>(7&o)&1),Z(e,t),Z(t,t),$(t,e,r)}function nt(t,n){var r=[e(),e(),e(),e()];x(r[0],p),x(r[1],f),x(r[2],c),B(r[3],p,f),et(t,r,n)}function rt(t,n,o){var i,s=new Uint8Array(64),c=[e(),e(),e(),e()];for(o||r(n,32),Q(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,nt(c,s),tt(t,c),i=0;i<32;i++)n[i+32]=t[i];return 0}var ot=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function it(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>4)*ot[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*ot[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function st(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;it(t,n)}function ct(t,n,r,o){var i,s,c=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),p=[e(),e(),e(),e()];Q(c,o,32),c[0]&=248,c[31]&=127,c[31]|=64;var f=r+64;for(i=0;i>7&&D(t[0],s,t[0]),B(t[3],t[0],t[1]),0)}(f,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return rt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(ht(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n0)r.loading[t].push(n);else{r.loading[t]=[n];var o=we.createScriptRequest(r.getPath(t,e)),i=r.receivers.create((function(e){if(r.receivers.remove(i),r.loading[t]){var n=r.loading[t];delete r.loading[t];for(var s=function(t){t||o.cleanup()},c=0;c>>6)+u(128|63&e):u(224|e>>>12&15)+u(128|e>>>6&63)+u(128|63&e)},g=function(t){return t.replace(/[^\x00-\x7F]/g,y)},v=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[h.charAt(n>>>18),h.charAt(n>>>12&63),e>=2?"=":h.charAt(n>>>6&63),e>=1?"=":h.charAt(63&n)].join("")},b=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,v)},m=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t((function(){o.timer&&(o.timer=r(o.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),w=(d=function(t,e){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function _(t){window.clearTimeout(t)}function S(t){window.clearInterval(t)}var k=function(t){function e(e,n){return t.call(this,setTimeout,_,e,(function(t){return n(),null}))||this}return w(e,t),e}(m),T=function(t){function e(e,n){return t.call(this,setInterval,S,e,(function(t){return n(),t}))||this}return w(e,t),e}(m),C={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new k(0,t)},method:function(t){for(var e=[],n=1;n0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},mt=bt,wt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),_t=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return wt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),B.debug("Event sent",r),this.send(mt.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=mt.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(B.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){A(e,(function(e,n){t.transport.unbind(n,e)}))};A(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=mt.getCloseAction(t),n=mt.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(tt),St=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=mt.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new _t(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=mt.getCloseAction(e)||"backoff",r=mt.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(P({transport:this.transport,action:t},e))},t}(),kt=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===we.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=e.auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||we.getAuthorizers(),t.authorizers[this.type].call(this,we,e,n)},t}(),Tt=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(we.TimelineTransport.getAgent(this,t),e)},t}(),Ct=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Pt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),Ot=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),Et=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),At=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),xt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),Lt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),Rt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ct(e,t),e}(Error),Ut=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Mt=function(t){function e(e,n){var r=t.call(this,(function(t,n){B.debug("No callbacks on "+e+" for "+t)}))||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return Ut(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new Pt("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=z("triggeringClientEvents");B.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(B.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(tt),jt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),It=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return jt(e,t),e.prototype.authorize=function(t,e){return Kt.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(Mt),Nt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;A(this.members,(function(n,r){t(e.get(r))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),Dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Bt=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new Nt,r}return Dt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var o=z("authenticationEndpoint");return B.error("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(It),Ht=n(1),zt=n(0),qt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ft=function(t){function e(e,n,r){var o=t.call(this,e,n)||this;return o.key=null,o.nacl=r,o}return qt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(o)r.key=Object(zt.decode)(o),delete e.shared_secret,n(!1,e);else{var i="No shared_secret key in auth payload for encrypted channel: "+r.name;n(!0,i)}}}))},e.prototype.trigger=function(t,e){throw new xt("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=Object(zt.decode)(e.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new k(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new k(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new k(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new k(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return P({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return P({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),B.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(tt),Yt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){if(e.config.nacl)return Kt.createEncryptedChannel(t,e,e.config.nacl);var n=z("encryptedChannelSupport");throw new xt("Tried to subscribe to a private-encrypted- channel but no nacl implementation available. "+n)}return 0===t.indexOf("private-")?Kt.createPrivateChannel(t,e):0===t.indexOf("presence-")?Kt.createPresenceChannel(t,e):Kt.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return A(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){A(this.channels,(function(t){t.disconnect()}))},t}();var Kt={createChannels:function(){return new Yt},createConnectionManager:function(t,e){return new Jt(t,e)},createChannel:function(t,e){return new Mt(t,e)},createPrivateChannel:function(t,e){return new It(t,e)},createPresenceChannel:function(t,e){return new Bt(t,e)},createEncryptedChannel:function(t,e,n){return new Ft(t,e,n)},createTimelineSender:function(t,e){return new Tt(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new kt(t,e)},createHandshake:function(t,e){return new St(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new vt(t,e,n)}},Wt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Kt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),Gt=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return j(this.strategies,C.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,c=function(a,u){u?e(null,u):(o+=1,n.loop&&(o%=r.length),o0&&(o=new k(n.timeout,(function(){i.abort(),r(!0)}))),i=t.connect(e,(function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))})),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Vt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return j(this.strategies,C.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var r=R(t,(function(t,r,o,i){return t.connect(e,n(r,i))}));return{abort:function(){L(r,Qt)},forceMinPriority:function(t){L(r,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(r,o){n[t].error=r,r?function(t){return function(t,e){for(var n=0;n=C.now()){var i=this.transports[r.transport];i&&(this.timeline.info({cached:!0,transport:r.transport,latency:r.latency}),o.push(new Gt([i],{timeout:2*r.latency+1e3,failFast:!0})))}var s=C.now(),c=o.pop().connect(t,(function r(i,a){i?(te(n),o.length>0?(s=C.now(),c=o.pop().connect(t,r)):e(i)):(!function(t,e,n){var r=we.getLocalStorage();if(r)try{r[$t(t)]=D({timestamp:C.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,C.now()-s),e(null,a))}));return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function $t(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function te(t){var e=we.getLocalStorage();if(e)try{delete e[$t(t)]}catch(t){}}var ee=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,r=this.strategy,o=new k(this.options.delay,(function(){n=r.connect(t,e)}));return{abort:function(){o.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),ne=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),re=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,r){r&&n.abort(),e(t,r)}));return n},t}();function oe(t){return function(){return t.isSupported()}}var ie,se=function(t,e,n){var r={};function o(e,o,i,s,c){var a=n(t,e,o,i,s,c);return r[e]=a,a}var i,s=Object.assign({},e,{hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath}),c=Object.assign({},s,{useTLS:!0}),a=Object.assign({},e,{hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath}),u={loop:!0,timeout:15e3,timeoutLimit:6e4},h=new Wt({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),p=new Wt({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),f=o("ws","ws",3,s,h),l=o("wss","ws",3,c,h),d=o("sockjs","sockjs",1,a),y=o("xhr_streaming","xhr_streaming",1,a,p),g=o("xdr_streaming","xdr_streaming",1,a,p),v=o("xhr_polling","xhr_polling",1,a),b=o("xdr_polling","xdr_polling",1,a),m=new Gt([f],u),w=new Gt([l],u),_=new Gt([d],u),S=new Gt([new ne(oe(y),y,g)],u),k=new Gt([new ne(oe(v),v,b)],u),T=new Gt([new ne(oe(S),new Vt([S,new ee(k,{delay:4e3})]),k)],u),C=new ne(oe(T),T,_);return i=e.useTLS?new Vt([m,new ee(C,{delay:2e3})]):new Vt([m,new ee(w,{delay:2e3}),new ee(C,{delay:5e3})]),new Zt(new re(new ne(oe(f),i,C)),r,{ttl:18e5,timeline:e.timeline,useTLS:e.useTLS})},ce={getRequest:function(t){var e=new window.XDomainRequest;return e.ontimeout=function(){t.emit("error",new Ot),t.close()},e.onerror=function(e){t.emit("error",e),t.close()},e.onprogress=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText)},e.onload=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText),t.emit("finished",200),t.close()},e},abortRequest:function(t){t.ontimeout=t.onerror=t.onprogress=t.onload=null,t.abort()}},ae=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ue=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return ae(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},we.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(we.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(tt);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(ie||(ie={}));var he=ie,pe=1;function fe(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+pe++}function le(t){return Math.floor(Math.random()*t)}var de,ye=function(){function t(t,e){this.hooks=t,this.session=le(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},me={createStreamingSocket:function(t){return this.createSocket(ge,t)},createPollingSocket:function(t){return this.createSocket(ve,t)},createSocket:function(t,e){return new ye(t,e)},createXHR:function(t,e){return this.createRequest(be,t,e)},createRequest:function(t,e,n){return new ue(t,e,n)},createXDR:function(t,e){return this.createRequest(ce,t,e)}},we={nextAuthCallbackID:1,auth_callbacks:{},ScriptReceivers:o,DependenciesReceivers:c,getDefaultStrategy:se,Transports:dt,transportConnectionInitializer:function(){var t=this;t.timeline.info(t.buildTimelineMessage({transport:t.name+(t.options.useTLS?"s":"")})),t.hooks.isInitialized()?t.changeState("initialized"):t.hooks.file?(t.changeState("initializing"),a.load(t.hooks.file,{useTLS:t.options.useTLS},(function(e,n){t.hooks.isInitialized()?(t.changeState("initialized"),n(!0)):(e&&t.onError(e),t.onClose(),n(!1))}))):t.onClose()},HTTPFactory:me,TimelineTransport:Y,getXHRAPI:function(){return window.XMLHttpRequest},getWebSocketAPI:function(){return window.WebSocket||window.MozWebSocket},setup:function(t){var e=this;window.Pusher=t;var n=function(){e.onDocumentBody(t.ready)};window.JSON?n():a.load("json2",{},n)},getDocument:function(){return document},getProtocol:function(){return this.getDocument().location.protocol},getAuthorizers:function(){return{ajax:q,jsonp:F}},onDocumentBody:function(t){var e=this;document.body?t():setTimeout((function(){e.onDocumentBody(t)}),0)},createJSONPRequest:function(t,e){return new J(t,e)},createScriptRequest:function(t){return new X(t)},getLocalStorage:function(){try{return window.localStorage}catch(t){return}},createXHR:function(){return this.getXHRAPI()?this.createXMLHttpRequest():this.createMicrosoftXHR()},createXMLHttpRequest:function(){return new(this.getXHRAPI())},createMicrosoftXHR:function(){return new ActiveXObject("Microsoft.XMLHTTP")},getNetwork:function(){return gt},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);if(this.isXDRSupported(0===e.indexOf("https:")))return this.HTTPFactory.createXDR(t,e);throw"Cross-origin HTTP requests are not supported"},isXHRSupported:function(){var t=this.getXHRAPI();return Boolean(t)&&void 0!==(new t).withCredentials},isXDRSupported:function(t){var e=t?"https:":"http:",n=this.getProtocol();return Boolean(window.XDomainRequest)&&n===e},addUnloadListener:function(t){void 0!==window.addEventListener?window.addEventListener("unload",t,!1):void 0!==window.attachEvent&&window.attachEvent("onunload",t)},removeUnloadListener:function(t){void 0!==window.addEventListener?window.removeEventListener("unload",t,!1):void 0!==window.detachEvent&&window.detachEvent("onunload",t)}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(de||(de={}));var _e=de,Se=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(P({},e,{timestamp:C.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(_e.ERROR,t)},t.prototype.info=function(t){this.log(_e.INFO,t)},t.prototype.debug=function(t){this.log(_e.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,r=P({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(r,(function(t,r){t||n.sent++,e&&e(t,r)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),ke=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return Te(new Rt,e);if(this.priority> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} - -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} - -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} - -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} - -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; - - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; - - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; - - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; - - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; - - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; - - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; - - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; - - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; - - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; - - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; - - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; - - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; - - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; - - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} - -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; - - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; - - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; - - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; - - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; - - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; - - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} - -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} - -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} +"use strict"; -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" - -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package base64 implements Base64 encoding and decoding. + */ +// Invalid character used in decoding to indicate +// that the character to decode is out of range of +// alphabet and cannot be decoded. +var INVALID_BYTE = 256; +/** + * Implements standard Base64 encoding. + * + * Operates in constant time. + */ +var Coder = /** @class */ (function () { + // TODO(dchest): methods to encode chunk-by-chunk. + function Coder(_paddingCharacter) { + if (_paddingCharacter === void 0) { _paddingCharacter = "="; } + this._paddingCharacter = _paddingCharacter; } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; + Coder.prototype.encodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 8 + 5) / 6 | 0; + } + return (length + 2) / 3 * 4 | 0; + }; + Coder.prototype.encode = function (data) { + var out = ""; + var i = 0; + for (; i < data.length - 2; i += 3) { + var c = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + out += this._encodeByte((c >>> 1 * 6) & 63); + out += this._encodeByte((c >>> 0 * 6) & 63); + } + var left = data.length - i; + if (left > 0) { + var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + if (left === 2) { + out += this._encodeByte((c >>> 1 * 6) & 63); + } + else { + out += this._paddingCharacter || ""; + } + out += this._paddingCharacter || ""; + } + return out; + }; + Coder.prototype.maxDecodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 6 + 7) / 8 | 0; + } + return length / 4 * 3 | 0; + }; + Coder.prototype.decodedLength = function (s) { + return this.maxDecodedLength(s.length - this._getPaddingLength(s)); + }; + Coder.prototype.decode = function (s) { + if (s.length === 0) { + return new Uint8Array(0); + } + var paddingLength = this._getPaddingLength(s); + var length = s.length - paddingLength; + var out = new Uint8Array(this.maxDecodedLength(length)); + var op = 0; + var i = 0; + var haveBad = 0; + var v0 = 0, v1 = 0, v2 = 0, v3 = 0; + for (; i < length - 4; i += 4) { + v0 = this._decodeChar(s.charCodeAt(i + 0)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + v2 = this._decodeChar(s.charCodeAt(i + 2)); + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v0 << 2) | (v1 >>> 4); + out[op++] = (v1 << 4) | (v2 >>> 2); + out[op++] = (v2 << 6) | v3; + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + haveBad |= v2 & INVALID_BYTE; + haveBad |= v3 & INVALID_BYTE; + } + if (i < length - 1) { + v0 = this._decodeChar(s.charCodeAt(i)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + out[op++] = (v0 << 2) | (v1 >>> 4); + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + } + if (i < length - 2) { + v2 = this._decodeChar(s.charCodeAt(i + 2)); + out[op++] = (v1 << 4) | (v2 >>> 2); + haveBad |= v2 & INVALID_BYTE; + } + if (i < length - 3) { + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v2 << 6) | v3; + haveBad |= v3 & INVALID_BYTE; + } + if (haveBad !== 0) { + throw new Error("Base64Coder: incorrect characters for decoding"); + } + return out; + }; + // Standard encoding have the following encoded/decoded ranges, + // which we need to convert between. + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + / + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 43 47 + // + // Encode 6 bits in b into a new character. + Coder.prototype._encodeByte = function (b) { + // Encoding uses constant time operations as follows: + // + // 1. Define comparison of A with B using (A - B) >>> 8: + // if A > B, then result is positive integer + // if A <= B, then result is 0 + // + // 2. Define selection of C or 0 using bitwise AND: X & C: + // if X == 0, then result is 0 + // if X != 0, then result is C + // + // 3. Start with the smallest comparison (b >= 0), which is always + // true, so set the result to the starting ASCII value (65). + // + // 4. Continue comparing b to higher ASCII values, and selecting + // zero if comparison isn't true, otherwise selecting a value + // to add to result, which: + // + // a) undoes the previous addition + // b) provides new value to add + // + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47); + return String.fromCharCode(result); + }; + // Decode a character code into a byte. + // Must return 256 if character is out of alphabet range. + Coder.prototype._decodeChar = function (c) { + // Decoding works similar to encoding: using the same comparison + // function, but now it works on ranges: result is always incremented + // by value, but this value becomes zero if the range is not + // satisfied. + // + // Decoding starts with invalid value, 256, which is then + // subtracted when the range is satisfied. If none of the ranges + // apply, the function returns 256, which is then checked by + // the caller to throw error. + var result = INVALID_BYTE; // start with invalid character + // c == 43 (c > 42 and c < 44) + result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62); + // c == 47 (c > 46 and c < 48) + result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + Coder.prototype._getPaddingLength = function (s) { + var paddingLength = 0; + if (this._paddingCharacter) { + for (var i = s.length - 1; i >= 0; i--) { + if (s[i] !== this._paddingCharacter) { + break; + } + paddingLength++; + } + if (s.length < 4 || paddingLength > 2) { + throw new Error("Base64Coder: incorrect padding"); + } + } + return paddingLength; + }; + return Coder; +}()); +exports.Coder = Coder; +var stdCoder = new Coder(); +function encode(data) { + return stdCoder.encode(data); } - -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; +exports.encode = encode; +function decode(s) { + return stdCoder.decode(s); } - -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); +exports.decode = decode; +/** + * Implements URL-safe Base64 encoding. + * (Same as Base64, but '+' is replaced with '-', and '/' with '_'). + * + * Operates in constant time. + */ +var URLSafeCoder = /** @class */ (function (_super) { + __extends(URLSafeCoder, _super); + function URLSafeCoder() { + return _super !== null && _super.apply(this, arguments) || this; + } + // URL-safe encoding have the following encoded/decoded ranges: + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _ + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 45 95 + // + URLSafeCoder.prototype._encodeByte = function (b) { + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95); + return String.fromCharCode(result); + }; + URLSafeCoder.prototype._decodeChar = function (c) { + var result = INVALID_BYTE; + // c == 45 (c > 44 and c < 46) + result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62); + // c == 95 (c > 94 and c < 96) + result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + return URLSafeCoder; +}(Coder)); +exports.URLSafeCoder = URLSafeCoder; +var urlSafeCoder = new URLSafeCoder(); +function encodeURLSafe(data) { + return urlSafeCoder.encode(data); } - -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +exports.encodeURLSafe = encodeURLSafe; +function decodeURLSafe(s) { + return urlSafeCoder.decode(s); } - -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ - -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; - - var t0, t1, t2, t3, t4, t5, t6, t7; - - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; - - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; -}; - -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; - - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; - - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; - - c = 0; - - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; - - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; - - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; - - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; - - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; - - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; - - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; - - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; - - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; - - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; - - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; - - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; - - mpos += 16; - bytes -= 16; - } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; +exports.decodeURLSafe = decodeURLSafe; +exports.encodedLength = function (length) { + return stdCoder.encodedLength(length); }; - -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; - - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } - - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; - - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); - - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } - - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +exports.maxDecodedLength = function (length) { + return stdCoder.maxDecodedLength(length); }; - -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; - - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } - - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } - - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; - } +exports.decodedLength = function (s) { + return stdCoder.decodedLength(s); }; +//# sourceMappingURL=base64.js.map -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; -} - -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} - -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} - -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} - -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} - -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} - -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} - -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; - } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; - } -} - -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} - -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; -} - -function unpack25519(o, n) { - var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; -} - -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; -} - -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; -} - -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; - - v = a[0]; - t0 += v * b0; - t1 += v * b1; - t2 += v * b2; - t3 += v * b3; - t4 += v * b4; - t5 += v * b5; - t6 += v * b6; - t7 += v * b7; - t8 += v * b8; - t9 += v * b9; - t10 += v * b10; - t11 += v * b11; - t12 += v * b12; - t13 += v * b13; - t14 += v * b14; - t15 += v * b15; - v = a[1]; - t1 += v * b0; - t2 += v * b1; - t3 += v * b2; - t4 += v * b3; - t5 += v * b4; - t6 += v * b5; - t7 += v * b6; - t8 += v * b7; - t9 += v * b8; - t10 += v * b9; - t11 += v * b10; - t12 += v * b11; - t13 += v * b12; - t14 += v * b13; - t15 += v * b14; - t16 += v * b15; - v = a[2]; - t2 += v * b0; - t3 += v * b1; - t4 += v * b2; - t5 += v * b3; - t6 += v * b4; - t7 += v * b5; - t8 += v * b6; - t9 += v * b7; - t10 += v * b8; - t11 += v * b9; - t12 += v * b10; - t13 += v * b11; - t14 += v * b12; - t15 += v * b13; - t16 += v * b14; - t17 += v * b15; - v = a[3]; - t3 += v * b0; - t4 += v * b1; - t5 += v * b2; - t6 += v * b3; - t7 += v * b4; - t8 += v * b5; - t9 += v * b6; - t10 += v * b7; - t11 += v * b8; - t12 += v * b9; - t13 += v * b10; - t14 += v * b11; - t15 += v * b12; - t16 += v * b13; - t17 += v * b14; - t18 += v * b15; - v = a[4]; - t4 += v * b0; - t5 += v * b1; - t6 += v * b2; - t7 += v * b3; - t8 += v * b4; - t9 += v * b5; - t10 += v * b6; - t11 += v * b7; - t12 += v * b8; - t13 += v * b9; - t14 += v * b10; - t15 += v * b11; - t16 += v * b12; - t17 += v * b13; - t18 += v * b14; - t19 += v * b15; - v = a[5]; - t5 += v * b0; - t6 += v * b1; - t7 += v * b2; - t8 += v * b3; - t9 += v * b4; - t10 += v * b5; - t11 += v * b6; - t12 += v * b7; - t13 += v * b8; - t14 += v * b9; - t15 += v * b10; - t16 += v * b11; - t17 += v * b12; - t18 += v * b13; - t19 += v * b14; - t20 += v * b15; - v = a[6]; - t6 += v * b0; - t7 += v * b1; - t8 += v * b2; - t9 += v * b3; - t10 += v * b4; - t11 += v * b5; - t12 += v * b6; - t13 += v * b7; - t14 += v * b8; - t15 += v * b9; - t16 += v * b10; - t17 += v * b11; - t18 += v * b12; - t19 += v * b13; - t20 += v * b14; - t21 += v * b15; - v = a[7]; - t7 += v * b0; - t8 += v * b1; - t9 += v * b2; - t10 += v * b3; - t11 += v * b4; - t12 += v * b5; - t13 += v * b6; - t14 += v * b7; - t15 += v * b8; - t16 += v * b9; - t17 += v * b10; - t18 += v * b11; - t19 += v * b12; - t20 += v * b13; - t21 += v * b14; - t22 += v * b15; - v = a[8]; - t8 += v * b0; - t9 += v * b1; - t10 += v * b2; - t11 += v * b3; - t12 += v * b4; - t13 += v * b5; - t14 += v * b6; - t15 += v * b7; - t16 += v * b8; - t17 += v * b9; - t18 += v * b10; - t19 += v * b11; - t20 += v * b12; - t21 += v * b13; - t22 += v * b14; - t23 += v * b15; - v = a[9]; - t9 += v * b0; - t10 += v * b1; - t11 += v * b2; - t12 += v * b3; - t13 += v * b4; - t14 += v * b5; - t15 += v * b6; - t16 += v * b7; - t17 += v * b8; - t18 += v * b9; - t19 += v * b10; - t20 += v * b11; - t21 += v * b12; - t22 += v * b13; - t23 += v * b14; - t24 += v * b15; - v = a[10]; - t10 += v * b0; - t11 += v * b1; - t12 += v * b2; - t13 += v * b3; - t14 += v * b4; - t15 += v * b5; - t16 += v * b6; - t17 += v * b7; - t18 += v * b8; - t19 += v * b9; - t20 += v * b10; - t21 += v * b11; - t22 += v * b12; - t23 += v * b13; - t24 += v * b14; - t25 += v * b15; - v = a[11]; - t11 += v * b0; - t12 += v * b1; - t13 += v * b2; - t14 += v * b3; - t15 += v * b4; - t16 += v * b5; - t17 += v * b6; - t18 += v * b7; - t19 += v * b8; - t20 += v * b9; - t21 += v * b10; - t22 += v * b11; - t23 += v * b12; - t24 += v * b13; - t25 += v * b14; - t26 += v * b15; - v = a[12]; - t12 += v * b0; - t13 += v * b1; - t14 += v * b2; - t15 += v * b3; - t16 += v * b4; - t17 += v * b5; - t18 += v * b6; - t19 += v * b7; - t20 += v * b8; - t21 += v * b9; - t22 += v * b10; - t23 += v * b11; - t24 += v * b12; - t25 += v * b13; - t26 += v * b14; - t27 += v * b15; - v = a[13]; - t13 += v * b0; - t14 += v * b1; - t15 += v * b2; - t16 += v * b3; - t17 += v * b4; - t18 += v * b5; - t19 += v * b6; - t20 += v * b7; - t21 += v * b8; - t22 += v * b9; - t23 += v * b10; - t24 += v * b11; - t25 += v * b12; - t26 += v * b13; - t27 += v * b14; - t28 += v * b15; - v = a[14]; - t14 += v * b0; - t15 += v * b1; - t16 += v * b2; - t17 += v * b3; - t18 += v * b4; - t19 += v * b5; - t20 += v * b6; - t21 += v * b7; - t22 += v * b8; - t23 += v * b9; - t24 += v * b10; - t25 += v * b11; - t26 += v * b12; - t27 += v * b13; - t28 += v * b14; - t29 += v * b15; - v = a[15]; - t15 += v * b0; - t16 += v * b1; - t17 += v * b2; - t18 += v * b3; - t19 += v * b4; - t20 += v * b5; - t21 += v * b6; - t22 += v * b7; - t23 += v * b8; - t24 += v * b9; - t25 += v * b10; - t26 += v * b11; - t27 += v * b12; - t28 += v * b13; - t29 += v * b14; - t30 += v * b15; - - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is - - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); - - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); - - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; -} - -function S(o, a) { - M(o, a, a); -} - -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} - -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} - -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; - } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); - } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; - } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); - return 0; -} - -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); -} - -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); -} - -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); -} - -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; - -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); -} - -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); -} - -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; - -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; - - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], - - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; - - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; - } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; - - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; - - // add - h = ah7; - l = al7; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // K - h = K[i*2]; - l = K[i*2+1]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // w - h = wh[i%16]; - l = wl[i%16]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; - - // add - h = th; - l = tl; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); - - // add - h = bh3; - l = bl3; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = th; - l = tl; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); - - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; - - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; - - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +"use strict"; - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package utf8 implements UTF-8 encoding and decoding. + */ +var INVALID_UTF16 = "utf8: invalid string"; +var INVALID_UTF8 = "utf8: invalid source encoding"; +/** + * Encodes the given string into UTF-8 byte array. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encode(s) { + // Calculate result length and allocate output array. + // encodedLength() also validates string and throws errors, + // so we don't need repeat validation here. + var arr = new Uint8Array(encodedLength(s)); + var pos = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + arr[pos++] = c; + } + else if (c < 0x800) { + arr[pos++] = 0xc0 | c >> 6; + arr[pos++] = 0x80 | c & 0x3f; + } + else if (c < 0xd800) { + arr[pos++] = 0xe0 | c >> 12; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + else { + i++; // get one more character + c = (c & 0x3ff) << 10; + c |= s.charCodeAt(i) & 0x3ff; + c += 0x10000; + arr[pos++] = 0xf0 | c >> 18; + arr[pos++] = 0x80 | (c >> 12) & 0x3f; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; } - } } - - // add - h = ah0; - l = al0; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[0]; - l = hl[0]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); - - h = ah1; - l = al1; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[1]; - l = hl[1]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); - - h = ah2; - l = al2; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[2]; - l = hl[2]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); - - h = ah3; - l = al3; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[3]; - l = hl[3]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); - - h = ah4; - l = al4; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[4]; - l = hl[4]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); - - h = ah5; - l = al5; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[5]; - l = hl[5]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); - - h = ah6; - l = al6; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[6]; - l = hl[6]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); - - h = ah7; - l = al7; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[7]; - l = hl[7]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); - - pos += 128; - n -= 128; - } - - return n; -} - -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; - - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; - - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; - - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; - - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; - - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); - - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); - - return 0; + return arr; } - -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); - - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); - - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); -} - -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } -} - -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; -} - -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); - } -} - -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -} - -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; - - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - scalarbase(p, d); - pack(pk, p); - - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; -} - -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); - -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; +exports.encode = encode; +/** + * Returns the number of bytes required to encode the given string into UTF-8. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encodedLength(s) { + var result = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + result += 1; + } + else if (c < 0x800) { + result += 2; + } + else if (c < 0xd800) { + result += 3; + } + else if (c <= 0xdfff) { + if (i >= s.length - 1) { + throw new Error(INVALID_UTF16); + } + i++; // "eat" next character + result += 4; + } + else { + throw new Error(INVALID_UTF16); + } } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; - } -} - -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); + return result; } - -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; - - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; - - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); - - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); - - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; +exports.encodedLength = encodedLength; +/** + * Decodes the given byte array from UTF-8 into a string. + * Throws if encoding is invalid. + */ +function decode(arr) { + var chars = []; + for (var i = 0; i < arr.length; i++) { + var b = arr[i]; + if (b & 0x80) { + var min = void 0; + if (b < 0xe0) { + // Need 1 more byte. + if (i >= arr.length) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + if ((n1 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x1f) << 6 | (n1 & 0x3f); + min = 0x80; + } + else if (b < 0xf0) { + // Need 2 more bytes. + if (i >= arr.length - 1) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 12 | (n1 & 0x3f) << 6 | (n2 & 0x3f); + min = 0x800; + } + else if (b < 0xf8) { + // Need 3 more bytes. + if (i >= arr.length - 2) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + var n3 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80 || (n3 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 18 | (n1 & 0x3f) << 12 | (n2 & 0x3f) << 6 | (n3 & 0x3f); + min = 0x10000; + } + else { + throw new Error(INVALID_UTF8); + } + if (b < min || (b >= 0xd800 && b <= 0xdfff)) { + throw new Error(INVALID_UTF8); + } + if (b >= 0x10000) { + // Surrogate pair. + if (b > 0x10ffff) { + throw new Error(INVALID_UTF8); + } + b -= 0x10000; + chars.push(String.fromCharCode(0xd800 | (b >> 10))); + b = 0xdc00 | (b & 0x3ff); + } + } + chars.push(String.fromCharCode(b)); } - } - - modL(sm.subarray(32), x); - return smlen; + return chars.join(""); } - -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); - - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); - - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); - - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); - - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; - - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); - - M(r[3], r[0], r[1]); - return 0; -} - -function crypto_sign_open(m, sm, n, pk) { - var i; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; - - if (n < 64) return -1; - - if (unpackneg(q, pk)) return -1; - - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); - - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); - - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; - } - - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - return n; -} - -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; - -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, - - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES, - - gf: gf, - D: D, - L: L, - pack25519: pack25519, - unpack25519: unpack25519, - M: M, - A: A, - S: S, - Z: Z, - pow2523: pow2523, - add: add, - set25519: set25519, - modL: modL, - scalarmult: scalarmult, - scalarbase: scalarbase, -}; - -/* High-level API */ - -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} - -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} - -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} - -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} - -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; -}; - -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); -}; - -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); -}; - -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; - -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; - -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; - -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; - -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); -}; - -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; - -nacl.box.after = nacl.secretbox; - -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); -}; - -nacl.box.open.after = nacl.secretbox.open; - -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; - -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; - -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; - -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; - -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; - -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; - -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; - -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; - -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; - -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; -}; - -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; - -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; - -nacl.hash.hashLength = crypto_hash_BYTES; - -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; - -nacl.setPRNG = function(fn) { - randombytes = fn; -}; - -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); - } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (true) { - // Node.js. - crypto = __webpack_require__(3); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } - } -})(); - -})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if ( true && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; - - var util = {}; - - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); - } - } - - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; - - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; - - if (typeof atob === 'undefined') { - // Node.js - - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; - - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; - - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; - - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; - } - - } else { - // Browsers - - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - }; - - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; - - } - - return util; - -})); - +exports.decode = decode; +//# sourceMappingURL=utf8.js.map /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { // required so we don't have to do require('pusher').default etc. -module.exports = __webpack_require__(4).default; +module.exports = __webpack_require__(3).default; /***/ }), /* 3 */ -/***/ (function(module, exports) { - -/* (ignored) */ - -/***/ }), -/* 4 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2639,22 +592,22 @@ var ScriptReceivers = new ScriptReceiverFactory('_pusher_script_', 'Pusher.Scrip // CONCATENATED MODULE: ./src/core/defaults.ts var Defaults = { - VERSION: "5.1.1", + VERSION: "6.0.0", PROTOCOL: 7, - host: 'ws.pusherapp.com', - ws_port: 80, - wss_port: 443, - ws_path: '', - sockjs_host: 'sockjs.pusher.com', - sockjs_http_port: 80, - sockjs_https_port: 443, - sockjs_path: '/pusher', + wsPort: 80, + wssPort: 443, + wsPath: '', + httpHost: 'sockjs.pusher.com', + httpPort: 80, + httpsPort: 443, + httpPath: '/pusher', stats_host: 'stats.pusher.com', - channel_auth_endpoint: '/pusher/auth', - channel_auth_transport: 'ajax', - activity_timeout: 120000, - pong_timeout: 30000, - unavailable_timeout: 10000, + authEndpoint: '/pusher/auth', + authTransport: 'ajax', + activityTimeout: 120000, + pongTimeout: 30000, + unavailableTimeout: 10000, + cluster: 'mt1', cdn_http: "http://js.pusher.com", cdn_https: "https://js.pusher.com", dependency_suffix: "" @@ -3139,6 +1092,9 @@ var urlStore = { }, triggeringClientEvents: { path: '/docs/client_api_guide/client_events#trigger-events' + }, + encryptedChannelSupport: { + fullUrl: 'https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support' } } }; @@ -4151,7 +2107,7 @@ var pusher_authorizer_PusherAuthorizer = (function () { } this.type = authTransport; this.options = options; - this.authOptions = (options || {}).auth || {}; + this.authOptions = options.auth || {}; } PusherAuthorizer.prototype.composeQuery = function (socketId) { var query = 'socket_id=' + @@ -4572,11 +2528,11 @@ var presence_channel_PresenceChannel = (function (_super) { }(private_channel)); /* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); -// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js -var nacl_fast = __webpack_require__(0); +// EXTERNAL MODULE: ./node_modules/@stablelib/utf8/lib/utf8.js +var utf8 = __webpack_require__(1); -// EXTERNAL MODULE: ./node_modules/tweetnacl-util/nacl-util.js -var nacl_util = __webpack_require__(1); +// EXTERNAL MODULE: ./node_modules/@stablelib/base64/lib/base64.js +var base64 = __webpack_require__(0); // CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { @@ -4599,9 +2555,10 @@ var encrypted_channel_extends = (undefined && undefined.__extends) || (function var encrypted_channel_EncryptedChannel = (function (_super) { encrypted_channel_extends(EncryptedChannel, _super); - function EncryptedChannel() { - var _this = _super !== null && _super.apply(this, arguments) || this; + function EncryptedChannel(name, pusher, nacl) { + var _this = _super.call(this, name, pusher) || this; _this.key = null; + _this.nacl = nacl; return _this; } EncryptedChannel.prototype.authorize = function (socketId, callback) { @@ -4617,7 +2574,7 @@ var encrypted_channel_EncryptedChannel = (function (_super) { callback(true, errorMsg); return; } - _this.key = Object(nacl_util["decodeBase64"])(sharedSecret); + _this.key = Object(base64["decode"])(sharedSecret); delete authData['shared_secret']; callback(false, authData); }); @@ -4646,17 +2603,17 @@ var encrypted_channel_EncryptedChannel = (function (_super) { data); return; } - var cipherText = Object(nacl_util["decodeBase64"])(data.ciphertext); - if (cipherText.length < nacl_fast["secretbox"].overheadLength) { - logger.error("Expected encrypted event ciphertext length to be " + nacl_fast["secretbox"].overheadLength + ", got: " + cipherText.length); + var cipherText = Object(base64["decode"])(data.ciphertext); + if (cipherText.length < this.nacl.secretbox.overheadLength) { + logger.error("Expected encrypted event ciphertext length to be " + this.nacl.secretbox.overheadLength + ", got: " + cipherText.length); return; } - var nonce = Object(nacl_util["decodeBase64"])(data.nonce); - if (nonce.length < nacl_fast["secretbox"].nonceLength) { - logger.error("Expected encrypted event nonce length to be " + nacl_fast["secretbox"].nonceLength + ", got: " + nonce.length); + var nonce = Object(base64["decode"])(data.nonce); + if (nonce.length < this.nacl.secretbox.nonceLength) { + logger.error("Expected encrypted event nonce length to be " + this.nacl.secretbox.nonceLength + ", got: " + nonce.length); return; } - var bytes = nacl_fast["secretbox"].open(cipherText, nonce, this.key); + var bytes = this.nacl.secretbox.open(cipherText, nonce, this.key); if (bytes === null) { logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); this.authorize(this.pusher.connection.socket_id, function (error, authData) { @@ -4664,17 +2621,17 @@ var encrypted_channel_EncryptedChannel = (function (_super) { logger.error("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); return; } - bytes = nacl_fast["secretbox"].open(cipherText, nonce, _this.key); + bytes = _this.nacl.secretbox.open(cipherText, nonce, _this.key); if (bytes === null) { logger.error("Failed to decrypt event with new key. Dropping encrypted event"); return; } - _this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + _this.emitJSON(event, Object(utf8["decode"])(bytes)); return; }); return; } - this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + this.emitJSON(event, Object(utf8["decode"])(bytes)); }; EncryptedChannel.prototype.emitJSON = function (eventName, data) { try { @@ -4712,12 +2669,12 @@ var connection_manager_ConnectionManager = (function (_super) { connection_manager_extends(ConnectionManager, _super); function ConnectionManager(key, options) { var _this = _super.call(this) || this; - _this.key = key; - _this.options = options || {}; _this.state = 'initialized'; _this.connection = null; - _this.usingTLS = !!options.useTLS; + _this.key = key; + _this.options = options; _this.timeline = _this.options.timeline; + _this.usingTLS = _this.options.useTLS; _this.errorCallbacks = _this.buildErrorCallbacks(); _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); @@ -4974,6 +2931,7 @@ var connection_manager_ConnectionManager = (function (_super) { + var channels_Channels = (function () { function Channels() { this.channels = {}; @@ -5005,8 +2963,12 @@ var channels_Channels = (function () { /* harmony default export */ var channels = (channels_Channels); function createChannel(name, pusher) { if (name.indexOf('private-encrypted-') === 0) { - if (false) { var errorMsg; } - return factory.createEncryptedChannel(name, pusher); + if (pusher.config.nacl) { + return factory.createEncryptedChannel(name, pusher, pusher.config.nacl); + } + var errMsg = 'Tried to subscribe to a private-encrypted- channel but no nacl implementation available'; + var suffix = url_store.buildLogSuffix('encryptedChannelSupport'); + throw new UnsupportedFeature(errMsg + ". " + suffix); } else if (name.indexOf('private-') === 0) { return factory.createPrivateChannel(name, pusher); @@ -5046,8 +3008,8 @@ var Factory = { createPresenceChannel: function (name, pusher) { return new presence_channel(name, pusher); }, - createEncryptedChannel: function (name, pusher) { - return new encrypted_channel(name, pusher); + createEncryptedChannel: function (name, pusher, nacl) { + return new encrypted_channel(name, pusher, nacl); }, createTimelineSender: function (timeline, options) { return new timeline_sender(timeline, options); @@ -5433,32 +3395,31 @@ var FirstConnectedStrategy = (function () { - function testSupportsStrategy(strategy) { return function () { return strategy.isSupported(); }; } -var getDefaultStrategy = function (config, defineTransport) { +var getDefaultStrategy = function (config, baseOptions, defineTransport) { var definedTransports = {}; function defineTransportStrategy(name, type, priority, options, manager) { var transport = defineTransport(config, name, type, priority, options, manager); definedTransports[name] = transport; return transport; } - var ws_options = { + var ws_options = Object.assign({}, baseOptions, { hostNonTLS: config.wsHost + ':' + config.wsPort, hostTLS: config.wsHost + ':' + config.wssPort, httpPath: config.wsPath - }; - var wss_options = extend({}, ws_options, { + }); + var wss_options = Object.assign({}, ws_options, { useTLS: true }); - var sockjs_options = { + var sockjs_options = Object.assign({}, baseOptions, { hostNonTLS: config.httpHost + ':' + config.httpPort, hostTLS: config.httpHost + ':' + config.httpsPort, httpPath: config.httpPath - }; + }); var timeouts = { loop: true, timeout: 15000, @@ -5467,12 +3428,12 @@ var getDefaultStrategy = function (config, defineTransport) { var ws_manager = new transport_manager({ lives: 2, minPingDelay: 10000, - maxPingDelay: config.activity_timeout + maxPingDelay: config.activityTimeout }); var streaming_manager = new transport_manager({ lives: 2, minPingDelay: 10000, - maxPingDelay: config.activity_timeout + maxPingDelay: config.activityTimeout }); var ws_transport = defineTransportStrategy('ws', 'ws', 3, ws_options, ws_manager); var wss_transport = defineTransportStrategy('wss', 'ws', 3, wss_options, ws_manager); @@ -5498,7 +3459,7 @@ var getDefaultStrategy = function (config, defineTransport) { ], timeouts); var http_fallback_loop = new if_strategy(testSupportsStrategy(http_loop), http_loop, sockjs_loop); var wsStrategy; - if (config.useTLS) { + if (baseOptions.useTLS) { wsStrategy = new best_connected_ever_strategy([ ws_loop, new delayed_strategy(http_fallback_loop, { delay: 2000 }) @@ -5513,8 +3474,8 @@ var getDefaultStrategy = function (config, defineTransport) { } return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, { ttl: 1800000, - timeline: config.timeline, - useTLS: config.useTLS + timeline: baseOptions.timeline, + useTLS: baseOptions.useTLS }); }; /* harmony default export */ var default_strategy = (getDefaultStrategy); @@ -6280,12 +4241,8 @@ var strategy_builder_defineTransport = function (config, name, type, priority, o arrayIndexOf(config.disabledTransports, name) === -1); var transport; if (enabled) { - transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, extend({ - key: config.key, - useTLS: config.useTLS, - timeline: config.timeline, - ignoreNullOrigin: config.ignoreNullOrigin - }, options)); + options = Object.assign({ ignoreNullOrigin: config.ignoreNullOrigin }, options); + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options); } else { transport = strategy_builder_UnsupportedStrategy; @@ -6311,30 +4268,83 @@ var strategy_builder_UnsupportedStrategy = { // CONCATENATED MODULE: ./src/core/config.ts -var getGlobalConfig = function () { - return { - wsHost: defaults.host, - wsPort: defaults.ws_port, - wssPort: defaults.wss_port, - wsPath: defaults.ws_path, - httpHost: defaults.sockjs_host, - httpPort: defaults.sockjs_http_port, - httpsPort: defaults.sockjs_https_port, - httpPath: defaults.sockjs_path, - statsHost: defaults.stats_host, - authEndpoint: defaults.channel_auth_endpoint, - authTransport: defaults.channel_auth_transport, - activity_timeout: defaults.activity_timeout, - pong_timeout: defaults.pong_timeout, - unavailable_timeout: defaults.unavailable_timeout - }; -}; -var getClusterConfig = function (clusterName) { - return { - wsHost: 'ws-' + clusterName + '.pusher.com', - httpHost: 'sockjs-' + clusterName + '.pusher.com' - }; -}; + +function getConfig(opts) { + var config = { + activityTimeout: opts.activityTimeout || defaults.activityTimeout, + authEndpoint: opts.authEndpoint || defaults.authEndpoint, + authTransport: opts.authTransport || defaults.authTransport, + cluster: opts.cluster || defaults.cluster, + httpPath: opts.httpPath || defaults.httpPath, + httpPort: opts.httpPort || defaults.httpPort, + httpsPort: opts.httpsPort || defaults.httpsPort, + pongTimeout: opts.pongTimeout || defaults.pongTimeout, + statsHost: opts.statsHost || defaults.stats_host, + unavailableTimeout: opts.unavailableTimeout || defaults.unavailableTimeout, + wsPath: opts.wsPath || defaults.wsPath, + wsPort: opts.wsPort || defaults.wsPort, + wssPort: opts.wssPort || defaults.wssPort, + enableStats: getEnableStatsConfig(opts), + httpHost: getHttpHost(opts), + useTLS: shouldUseTLS(opts), + wsHost: getWebsocketHost(opts) + }; + if ('auth' in opts) + config.auth = opts.auth; + if ('authorizer' in opts) + config.authorizer = opts.authorizer; + if ('disabledTransports' in opts) + config.disabledTransports = opts.disabledTransports; + if ('enabledTransports' in opts) + config.enabledTransports = opts.enabledTransports; + if ('ignoreNullOrigin' in opts) + config.ignoreNullOrigin = opts.ignoreNullOrigin; + if ('timelineParams' in opts) + config.timelineParams = opts.timelineParams; + if ('nacl' in opts) { + config.nacl = opts.nacl; + } + return config; +} +function getHttpHost(opts) { + if (opts.httpHost) { + return opts.httpHost; + } + if (opts.cluster) { + return "sockjs-" + opts.cluster + ".pusher.com"; + } + return defaults.httpHost; +} +function getWebsocketHost(opts) { + if (opts.wsHost) { + return opts.wsHost; + } + if (opts.cluster) { + return getWebsocketHostFromCluster(opts.cluster); + } + return getWebsocketHostFromCluster(defaults.cluster); +} +function getWebsocketHostFromCluster(cluster) { + return "ws-" + cluster + ".pusher.com"; +} +function shouldUseTLS(opts) { + if (runtime.getProtocol() === 'https:') { + return true; + } + else if (opts.forceTLS === false) { + return false; + } + return true; +} +function getEnableStatsConfig(opts) { + if ('enableStats' in opts) { + return opts.enableStats; + } + if ('disableStats' in opts) { + return !opts.disableStats; + } + return false; +} // CONCATENATED MODULE: ./src/core/pusher.ts @@ -6360,12 +4370,9 @@ var pusher_Pusher = (function () { } if ('disableStats' in options) { logger.warn('The disableStats option is deprecated in favor of enableStats'); - if (!('enableStats' in options)) { - options.enableStats = !options.disableStats; - } } this.key = app_key; - this.config = extend(getGlobalConfig(), options.cluster ? getClusterConfig(options.cluster) : {}, options); + this.config = getConfig(options); this.channels = factory.createChannels(); this.global_emitter = new dispatcher(); this.sessionID = Math.floor(Math.random() * 1000000000); @@ -6384,16 +4391,16 @@ var pusher_Pusher = (function () { }); } var getStrategy = function (options) { - var config = extend({}, _this.config, options); - return runtime.getDefaultStrategy(config, strategy_builder_defineTransport); + return runtime.getDefaultStrategy(_this.config, options, strategy_builder_defineTransport); }; - this.connection = factory.createConnectionManager(this.key, extend({ + this.connection = factory.createConnectionManager(this.key, { getStrategy: getStrategy, timeline: this.timeline, - activityTimeout: this.config.activity_timeout, - pongTimeout: this.config.pong_timeout, - unavailableTimeout: this.config.unavailable_timeout - }, this.config, { useTLS: this.shouldUseTLS() })); + activityTimeout: this.config.activityTimeout, + pongTimeout: this.config.pongTimeout, + unavailableTimeout: this.config.unavailableTimeout, + useTLS: Boolean(this.config.useTLS) + }); this.connection.bind('connected', function () { _this.subscribeAll(); if (_this.timelineSender) { @@ -6519,15 +4526,7 @@ var pusher_Pusher = (function () { return this.connection.send_event(event_name, data, channel); }; Pusher.prototype.shouldUseTLS = function () { - if (runtime.getProtocol() === 'https:') { - return true; - } - else if (this.config.forceTLS === true) { - return true; - } - else { - return Boolean(this.config.encrypted); - } + return this.config.useTLS; }; Pusher.instances = []; Pusher.isReady = false; diff --git a/dist/web/pusher.min.js b/dist/web/pusher.min.js index e3f497dcc..5573a54a0 100644 --- a/dist/web/pusher.min.js +++ b/dist/web/pusher.min.js @@ -1,8 +1,8 @@ /*! - * Pusher JavaScript Library v5.1.1 + * Pusher JavaScript Library v6.0.0 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Pusher=e():t.Pusher=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){!function(t){"use strict";var e=function(t){var e,n=new Float64Array(16);if(t)for(e=0;e>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function v(t,e,n,r){return y(t,e,n,r,16)}function g(t,e,n,r){return y(t,e,n,r,32)}function b(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,p=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,w=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,_=i,S=s,k=c,T=a,O=u,C=h,A=p,E=f,P=l,x=d,L=y,R=v,U=g,M=b,j=m,I=w,N=0;N<20;N+=2)_^=(o=(U^=(o=(P^=(o=(O^=(o=_+U|0)<<7|o>>>25)+_|0)<<9|o>>>23)+O|0)<<13|o>>>19)+P|0)<<18|o>>>14,C^=(o=(S^=(o=(M^=(o=(x^=(o=C+S|0)<<7|o>>>25)+C|0)<<9|o>>>23)+x|0)<<13|o>>>19)+M|0)<<18|o>>>14,L^=(o=(A^=(o=(k^=(o=(j^=(o=L+A|0)<<7|o>>>25)+L|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(R^=(o=(E^=(o=(T^=(o=I+R|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+E|0)<<18|o>>>14,_^=(o=(T^=(o=(k^=(o=(S^=(o=_+T|0)<<7|o>>>25)+_|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,C^=(o=(O^=(o=(E^=(o=(A^=(o=C+O|0)<<7|o>>>25)+C|0)<<9|o>>>23)+A|0)<<13|o>>>19)+E|0)<<18|o>>>14,L^=(o=(x^=(o=(P^=(o=(R^=(o=L+x|0)<<7|o>>>25)+L|0)<<9|o>>>23)+R|0)<<13|o>>>19)+P|0)<<18|o>>>14,I^=(o=(j^=(o=(M^=(o=(U^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+U|0)<<13|o>>>19)+M|0)<<18|o>>>14;_=_+i|0,S=S+s|0,k=k+c|0,T=T+a|0,O=O+u|0,C=C+h|0,A=A+p|0,E=E+f|0,P=P+l|0,x=x+d|0,L=L+y|0,R=R+v|0,U=U+g|0,M=M+b|0,j=j+m|0,I=I+w|0,t[0]=_>>>0&255,t[1]=_>>>8&255,t[2]=_>>>16&255,t[3]=_>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=O>>>0&255,t[17]=O>>>8&255,t[18]=O>>>16&255,t[19]=O>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=A>>>0&255,t[25]=A>>>8&255,t[26]=A>>>16&255,t[27]=A>>>24&255,t[28]=E>>>0&255,t[29]=E>>>8&255,t[30]=E>>>16&255,t[31]=E>>>24&255,t[32]=P>>>0&255,t[33]=P>>>8&255,t[34]=P>>>16&255,t[35]=P>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=L>>>0&255,t[41]=L>>>8&255,t[42]=L>>>16&255,t[43]=L>>>24&255,t[44]=R>>>0&255,t[45]=R>>>8&255,t[46]=R>>>16&255,t[47]=R>>>24&255,t[48]=U>>>0&255,t[49]=U>>>8&255,t[50]=U>>>16&255,t[51]=U>>>24&255,t[52]=M>>>0&255,t[53]=M>>>8&255,t[54]=M>>>16&255,t[55]=M>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function m(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,p=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,g=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,w=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,_=0;_<20;_+=2)i^=(o=(g^=(o=(l^=(o=(u^=(o=i+g|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(p^=(o=(c^=(o=(m^=(o=y+p|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+c|0)<<18|o>>>14,w^=(o=(v^=(o=(f^=(o=(a^=(o=w+v|0)<<7|o>>>25)+w|0)<<9|o>>>23)+a|0)<<13|o>>>19)+f|0)<<18|o>>>14,i^=(o=(a^=(o=(c^=(o=(s^=(o=i+a|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+c|0)<<18|o>>>14,h^=(o=(u^=(o=(f^=(o=(p^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+p|0)<<13|o>>>19)+f|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(v^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+v|0)<<13|o>>>19)+l|0)<<18|o>>>14,w^=(o=(m^=(o=(b^=(o=(g^=(o=w+m|0)<<7|o>>>25)+w|0)<<9|o>>>23)+g|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=w>>>0&255,t[13]=w>>>8&255,t[14]=w>>>16&255,t[15]=w>>>24&255,t[16]=p>>>0&255,t[17]=p>>>8&255,t[18]=p>>>16&255,t[19]=p>>>24&255,t[20]=f>>>0&255,t[21]=f>>>8&255,t[22]=f>>>16&255,t[23]=f>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var w=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function _(t,e,n,r,o,i,s){var c,a,u=new Uint8Array(16),h=new Uint8Array(64);for(a=0;a<16;a++)u[a]=0;for(a=0;a<8;a++)u[a]=i[a];for(;o>=64;){for(b(h,u,s,w),a=0;a<64;a++)t[e+a]=n[r+a]^h[a];for(c=1,a=8;a<16;a++)c=c+(255&u[a])|0,u[a]=255&c,c>>>=8;o-=64,e+=64,r+=64}if(o>0)for(b(h,u,s,w),a=0;a=64;){for(b(a,c,o,w),s=0;s<64;s++)t[e+s]=a[s];for(i=1,s=8;s<16;s++)i=i+(255&c[s])|0,c[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(b(a,c,o,w),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),c=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|c<<5),a=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(c>>>8|a<<8),this.r[9]=a>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function C(t,e,n,r,o,i){var s=new O(i);return s.update(n,r,o),s.finish(t,e),0}function A(t,e,n,r,o,i){var s=new Uint8Array(16);return C(s,0,n,r,o,i),v(t,e,s,0)}function E(t,e,n,r,o){var i;if(n<32)return-1;for(T(t,0,e,0,n,r,o),C(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function P(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==A(e,16,e,32,n-32,s))return-1;for(T(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function L(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function R(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function U(t,n){var r,o,i,s=e(),c=e();for(r=0;r<16;r++)c[r]=n[r];for(L(c),L(c),L(c),o=0;o<2;o++){for(s[0]=c[0]-65517,r=1;r<15;r++)s[r]=c[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=c[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,R(c,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&c[r],t[2*r+1]=c[r]>>8}function M(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return U(n,t),U(r,e),g(n,0,r,0)}function j(t){var e=new Uint8Array(32);return U(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function B(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function D(t,e,n){var r,o,i=0,s=0,c=0,a=0,u=0,h=0,p=0,f=0,l=0,d=0,y=0,v=0,g=0,b=0,m=0,w=0,_=0,S=0,k=0,T=0,O=0,C=0,A=0,E=0,P=0,x=0,L=0,R=0,U=0,M=0,j=0,I=n[0],N=n[1],B=n[2],D=n[3],z=n[4],H=n[5],q=n[6],F=n[7],X=n[8],J=n[9],Y=n[10],K=n[11],W=n[12],G=n[13],Z=n[14],V=n[15];i+=(r=e[0])*I,s+=r*N,c+=r*B,a+=r*D,u+=r*z,h+=r*H,p+=r*q,f+=r*F,l+=r*X,d+=r*J,y+=r*Y,v+=r*K,g+=r*W,b+=r*G,m+=r*Z,w+=r*V,s+=(r=e[1])*I,c+=r*N,a+=r*B,u+=r*D,h+=r*z,p+=r*H,f+=r*q,l+=r*F,d+=r*X,y+=r*J,v+=r*Y,g+=r*K,b+=r*W,m+=r*G,w+=r*Z,_+=r*V,c+=(r=e[2])*I,a+=r*N,u+=r*B,h+=r*D,p+=r*z,f+=r*H,l+=r*q,d+=r*F,y+=r*X,v+=r*J,g+=r*Y,b+=r*K,m+=r*W,w+=r*G,_+=r*Z,S+=r*V,a+=(r=e[3])*I,u+=r*N,h+=r*B,p+=r*D,f+=r*z,l+=r*H,d+=r*q,y+=r*F,v+=r*X,g+=r*J,b+=r*Y,m+=r*K,w+=r*W,_+=r*G,S+=r*Z,k+=r*V,u+=(r=e[4])*I,h+=r*N,p+=r*B,f+=r*D,l+=r*z,d+=r*H,y+=r*q,v+=r*F,g+=r*X,b+=r*J,m+=r*Y,w+=r*K,_+=r*W,S+=r*G,k+=r*Z,T+=r*V,h+=(r=e[5])*I,p+=r*N,f+=r*B,l+=r*D,d+=r*z,y+=r*H,v+=r*q,g+=r*F,b+=r*X,m+=r*J,w+=r*Y,_+=r*K,S+=r*W,k+=r*G,T+=r*Z,O+=r*V,p+=(r=e[6])*I,f+=r*N,l+=r*B,d+=r*D,y+=r*z,v+=r*H,g+=r*q,b+=r*F,m+=r*X,w+=r*J,_+=r*Y,S+=r*K,k+=r*W,T+=r*G,O+=r*Z,C+=r*V,f+=(r=e[7])*I,l+=r*N,d+=r*B,y+=r*D,v+=r*z,g+=r*H,b+=r*q,m+=r*F,w+=r*X,_+=r*J,S+=r*Y,k+=r*K,T+=r*W,O+=r*G,C+=r*Z,A+=r*V,l+=(r=e[8])*I,d+=r*N,y+=r*B,v+=r*D,g+=r*z,b+=r*H,m+=r*q,w+=r*F,_+=r*X,S+=r*J,k+=r*Y,T+=r*K,O+=r*W,C+=r*G,A+=r*Z,E+=r*V,d+=(r=e[9])*I,y+=r*N,v+=r*B,g+=r*D,b+=r*z,m+=r*H,w+=r*q,_+=r*F,S+=r*X,k+=r*J,T+=r*Y,O+=r*K,C+=r*W,A+=r*G,E+=r*Z,P+=r*V,y+=(r=e[10])*I,v+=r*N,g+=r*B,b+=r*D,m+=r*z,w+=r*H,_+=r*q,S+=r*F,k+=r*X,T+=r*J,O+=r*Y,C+=r*K,A+=r*W,E+=r*G,P+=r*Z,x+=r*V,v+=(r=e[11])*I,g+=r*N,b+=r*B,m+=r*D,w+=r*z,_+=r*H,S+=r*q,k+=r*F,T+=r*X,O+=r*J,C+=r*Y,A+=r*K,E+=r*W,P+=r*G,x+=r*Z,L+=r*V,g+=(r=e[12])*I,b+=r*N,m+=r*B,w+=r*D,_+=r*z,S+=r*H,k+=r*q,T+=r*F,O+=r*X,C+=r*J,A+=r*Y,E+=r*K,P+=r*W,x+=r*G,L+=r*Z,R+=r*V,b+=(r=e[13])*I,m+=r*N,w+=r*B,_+=r*D,S+=r*z,k+=r*H,T+=r*q,O+=r*F,C+=r*X,A+=r*J,E+=r*Y,P+=r*K,x+=r*W,L+=r*G,R+=r*Z,U+=r*V,m+=(r=e[14])*I,w+=r*N,_+=r*B,S+=r*D,k+=r*z,T+=r*H,O+=r*q,C+=r*F,A+=r*X,E+=r*J,P+=r*Y,x+=r*K,L+=r*W,R+=r*G,U+=r*Z,M+=r*V,w+=(r=e[15])*I,s+=38*(S+=r*B),c+=38*(k+=r*D),a+=38*(T+=r*z),u+=38*(O+=r*H),h+=38*(C+=r*q),p+=38*(A+=r*F),f+=38*(E+=r*X),l+=38*(P+=r*J),d+=38*(x+=r*Y),y+=38*(L+=r*K),v+=38*(R+=r*W),g+=38*(U+=r*G),b+=38*(M+=r*Z),m+=38*(j+=r*V),i=(r=(i+=38*(_+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),w=(r=w+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=c,t[3]=a,t[4]=u,t[5]=h,t[6]=p,t[7]=f,t[8]=l,t[9]=d,t[10]=y,t[11]=v,t[12]=g,t[13]=b,t[14]=m,t[15]=w}function z(t,e){D(t,e,e)}function H(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)z(o,o),2!==r&&4!==r&&D(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function q(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=250;r>=0;r--)z(o,o),1!==r&&D(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function F(t,n,r){var o,i,s=new Uint8Array(32),c=new Float64Array(80),u=e(),h=e(),p=e(),f=e(),l=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(c,r),i=0;i<16;i++)h[i]=c[i],f[i]=u[i]=p[i]=0;for(u[0]=f[0]=1,i=254;i>=0;--i)R(u,h,o=s[i>>>3]>>>(7&i)&1),R(p,f,o),N(l,u,p),B(u,u,p),N(p,h,f),B(h,h,f),z(f,l),z(d,u),D(u,p,u),D(p,h,l),N(l,u,p),B(u,u,p),z(h,u),B(p,f,d),D(u,p,a),N(u,u,f),D(p,p,u),D(u,f,d),D(f,h,c),z(h,l),R(u,h,o),R(p,f,o);for(i=0;i<16;i++)c[i+16]=u[i],c[i+32]=p[i],c[i+48]=h[i],c[i+64]=f[i];var y=c.subarray(32),v=c.subarray(16);return H(y,y),D(v,v,y),U(t,v),0}function X(t,e){return F(t,e,i)}function J(t,e){return r(e,32),X(t,e)}function Y(t,e,n){var r=new Uint8Array(32);return F(r,n,e),m(t,o,r,w)}O.prototype.blocks=function(t,e,n){for(var r,o,i,s,c,a,u,h,p,f,l,d,y,v,g,b,m,w,_,S=this.fin?0:2048,k=this.h[0],T=this.h[1],O=this.h[2],C=this.h[3],A=this.h[4],E=this.h[5],P=this.h[6],x=this.h[7],L=this.h[8],R=this.h[9],U=this.r[0],M=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],D=this.r[6],z=this.r[7],H=this.r[8],q=this.r[9];n>=16;)f=p=0,f+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*U,f+=(T+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*q),f+=(O+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*H),f+=(C+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*z),p=(f+=(A+=8191&(s>>>4|(c=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*D))>>>13,f&=8191,f+=(E+=c>>>1&8191)*(5*B),f+=(P+=8191&(c>>>14|(a=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),f+=(x+=8191&(a>>>11|(u=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),f+=(L+=8191&(u>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),l=p+=(f+=(R+=h>>>5|S)*(5*M))>>>13,l+=k*M,l+=T*U,l+=O*(5*q),l+=C*(5*H),p=(l+=A*(5*z))>>>13,l&=8191,l+=E*(5*D),l+=P*(5*B),l+=x*(5*N),l+=L*(5*I),p+=(l+=R*(5*j))>>>13,l&=8191,d=p,d+=k*j,d+=T*M,d+=O*U,d+=C*(5*q),p=(d+=A*(5*H))>>>13,d&=8191,d+=E*(5*z),d+=P*(5*D),d+=x*(5*B),d+=L*(5*N),y=p+=(d+=R*(5*I))>>>13,y+=k*I,y+=T*j,y+=O*M,y+=C*U,p=(y+=A*(5*q))>>>13,y&=8191,y+=E*(5*H),y+=P*(5*z),y+=x*(5*D),y+=L*(5*B),v=p+=(y+=R*(5*N))>>>13,v+=k*N,v+=T*I,v+=O*j,v+=C*M,p=(v+=A*U)>>>13,v&=8191,v+=E*(5*q),v+=P*(5*H),v+=x*(5*z),v+=L*(5*D),g=p+=(v+=R*(5*B))>>>13,g+=k*B,g+=T*N,g+=O*I,g+=C*j,p=(g+=A*M)>>>13,g&=8191,g+=E*U,g+=P*(5*q),g+=x*(5*H),g+=L*(5*z),b=p+=(g+=R*(5*D))>>>13,b+=k*D,b+=T*B,b+=O*N,b+=C*I,p=(b+=A*j)>>>13,b&=8191,b+=E*M,b+=P*U,b+=x*(5*q),b+=L*(5*H),m=p+=(b+=R*(5*z))>>>13,m+=k*z,m+=T*D,m+=O*B,m+=C*N,p=(m+=A*I)>>>13,m&=8191,m+=E*j,m+=P*M,m+=x*U,m+=L*(5*q),w=p+=(m+=R*(5*H))>>>13,w+=k*H,w+=T*z,w+=O*D,w+=C*B,p=(w+=A*N)>>>13,w&=8191,w+=E*I,w+=P*j,w+=x*M,w+=L*U,_=p+=(w+=R*(5*q))>>>13,_+=k*q,_+=T*H,_+=O*z,_+=C*D,p=(_+=A*B)>>>13,_&=8191,_+=E*N,_+=P*I,_+=x*j,_+=L*M,k=f=8191&(p=(p=((p+=(_+=R*U)>>>13)<<2)+p|0)+(f&=8191)|0),T=l+=p>>>=13,O=d&=8191,C=y&=8191,A=v&=8191,E=g&=8191,P=b&=8191,x=m&=8191,L=w&=8191,R=_&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=O,this.h[3]=C,this.h[4]=A,this.h[5]=E,this.h[6]=P,this.h[7]=x,this.h[8]=L,this.h[9]=R},O.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},O.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+W,x[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],L[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=R,i=U,s=M,c=j,a=I,u=N,h=B,D,f=z,l=H,d=q,y=F,v=X,g=J,b=Y,K,C=65535&(O=K),A=O>>>16,E=65535&(T=D),P=T>>>16,C+=65535&(O=(X>>>14|I<<18)^(X>>>18|I<<14)^(I>>>9|X<<23)),A+=O>>>16,E+=65535&(T=(I>>>14|X<<18)^(I>>>18|X<<14)^(X>>>9|I<<23)),P+=T>>>16,C+=65535&(O=X&J^~X&Y),A+=O>>>16,E+=65535&(T=I&N^~I&B),P+=T>>>16,C+=65535&(O=G[2*S+1]),A+=O>>>16,E+=65535&(T=G[2*S]),P+=T>>>16,T=x[S%16],A+=(O=L[S%16])>>>16,E+=65535&T,P+=T>>>16,E+=(A+=(C+=65535&O)>>>16)>>>16,C=65535&(O=_=65535&C|A<<16),A=O>>>16,E=65535&(T=w=65535&E|(P+=E>>>16)<<16),P=T>>>16,C+=65535&(O=(z>>>28|R<<4)^(R>>>2|z<<30)^(R>>>7|z<<25)),A+=O>>>16,E+=65535&(T=(R>>>28|z<<4)^(z>>>2|R<<30)^(z>>>7|R<<25)),P+=T>>>16,A+=(O=z&H^z&q^H&q)>>>16,E+=65535&(T=R&U^R&M^U&M),P+=T>>>16,p=65535&(E+=(A+=(C+=65535&O)>>>16)>>>16)|(P+=E>>>16)<<16,m=65535&C|A<<16,C=65535&(O=y),A=O>>>16,E=65535&(T=c),P=T>>>16,A+=(O=_)>>>16,E+=65535&(T=w),P+=T>>>16,U=o,M=i,j=s,I=c=65535&(E+=(A+=(C+=65535&O)>>>16)>>>16)|(P+=E>>>16)<<16,N=a,B=u,D=h,R=p,H=f,q=l,F=d,X=y=65535&C|A<<16,J=v,Y=g,K=b,z=m,S%16==15)for(k=0;k<16;k++)T=x[k],C=65535&(O=L[k]),A=O>>>16,E=65535&T,P=T>>>16,T=x[(k+9)%16],C+=65535&(O=L[(k+9)%16]),A+=O>>>16,E+=65535&T,P+=T>>>16,w=x[(k+1)%16],C+=65535&(O=((_=L[(k+1)%16])>>>1|w<<31)^(_>>>8|w<<24)^(_>>>7|w<<25)),A+=O>>>16,E+=65535&(T=(w>>>1|_<<31)^(w>>>8|_<<24)^w>>>7),P+=T>>>16,w=x[(k+14)%16],A+=(O=((_=L[(k+14)%16])>>>19|w<<13)^(w>>>29|_<<3)^(_>>>6|w<<26))>>>16,E+=65535&(T=(w>>>19|_<<13)^(_>>>29|w<<3)^w>>>6),P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,x[k]=65535&E|P<<16,L[k]=65535&C|A<<16;C=65535&(O=z),A=O>>>16,E=65535&(T=R),P=T>>>16,T=t[0],A+=(O=e[0])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[0]=R=65535&E|P<<16,e[0]=z=65535&C|A<<16,C=65535&(O=H),A=O>>>16,E=65535&(T=U),P=T>>>16,T=t[1],A+=(O=e[1])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[1]=U=65535&E|P<<16,e[1]=H=65535&C|A<<16,C=65535&(O=q),A=O>>>16,E=65535&(T=M),P=T>>>16,T=t[2],A+=(O=e[2])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[2]=M=65535&E|P<<16,e[2]=q=65535&C|A<<16,C=65535&(O=F),A=O>>>16,E=65535&(T=j),P=T>>>16,T=t[3],A+=(O=e[3])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[3]=j=65535&E|P<<16,e[3]=F=65535&C|A<<16,C=65535&(O=X),A=O>>>16,E=65535&(T=I),P=T>>>16,T=t[4],A+=(O=e[4])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[4]=I=65535&E|P<<16,e[4]=X=65535&C|A<<16,C=65535&(O=J),A=O>>>16,E=65535&(T=N),P=T>>>16,T=t[5],A+=(O=e[5])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[5]=N=65535&E|P<<16,e[5]=J=65535&C|A<<16,C=65535&(O=Y),A=O>>>16,E=65535&(T=B),P=T>>>16,T=t[6],A+=(O=e[6])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[6]=B=65535&E|P<<16,e[6]=Y=65535&C|A<<16,C=65535&(O=K),A=O>>>16,E=65535&(T=D),P=T>>>16,T=t[7],A+=(O=e[7])>>>16,E+=65535&T,P+=T>>>16,P+=(E+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[7]=D=65535&E|P<<16,e[7]=K=65535&C|A<<16,W+=128,r-=128}return r}function V(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),c=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,Z(o,i,e,n),n%=128,r=0;r=0;--o)$(t,e,r=n[o/8|0]>>(7&o)&1),Q(e,t),Q(t,t),$(t,e,r)}function nt(t,n){var r=[e(),e(),e(),e()];x(r[0],p),x(r[1],f),x(r[2],c),D(r[3],p,f),et(t,r,n)}function rt(t,n,o){var i,s=new Uint8Array(64),c=[e(),e(),e(),e()];for(o||r(n,32),V(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,nt(c,s),tt(t,c),i=0;i<32;i++)n[i+32]=t[i];return 0}var ot=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function it(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>8,e[o]-=256*n;e[o]+=n,e[r]=0}for(n=0,o=0;o<32;o++)e[o]+=n-(e[31]>>4)*ot[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*ot[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function st(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;it(t,n)}function ct(t,n,r,o){var i,s,c=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),p=[e(),e(),e(),e()];V(c,o,32),c[0]&=248,c[31]&=127,c[31]|=64;var f=r+64;for(i=0;i>7&&B(t[0],s,t[0]),D(t[3],t[0],t[1]),0)}(f,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return rt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(ht(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n0)r.loading[t].push(n);else{r.loading[t]=[n];var o=we.createScriptRequest(r.getPath(t,e)),i=r.receivers.create((function(e){if(r.receivers.remove(i),r.loading[t]){var n=r.loading[t];delete r.loading[t];for(var s=function(t){t||o.cleanup()},c=0;c>>6)+u(128|63&e):u(224|e>>>12&15)+u(128|e>>>6&63)+u(128|63&e)},v=function(t){return t.replace(/[^\x00-\x7F]/g,y)},g=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[h.charAt(n>>>18),h.charAt(n>>>12&63),e>=2?"=":h.charAt(n>>>6&63),e>=1?"=":h.charAt(63&n)].join("")},b=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,g)},m=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t((function(){o.timer&&(o.timer=r(o.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),w=(d=function(t,e){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function _(t){window.clearTimeout(t)}function S(t){window.clearInterval(t)}var k=function(t){function e(e,n){return t.call(this,setTimeout,_,e,(function(t){return n(),null}))||this}return w(e,t),e}(m),T=function(t){function e(e,n){return t.call(this,setInterval,S,e,(function(t){return n(),t}))||this}return w(e,t),e}(m),O={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new k(0,t)},method:function(t){for(var e=[],n=1;n0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},mt=bt,wt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),_t=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return wt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),D.debug("Event sent",r),this.send(mt.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=mt.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(D.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){P(e,(function(e,n){t.transport.unbind(n,e)}))};P(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=mt.getCloseAction(t),n=mt.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(tt),St=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=mt.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new _t(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=mt.getCloseAction(e)||"backoff",r=mt.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(C({transport:this.transport,action:t},e))},t}(),kt=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===we.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||we.getAuthorizers(),t.authorizers[this.type].call(this,we,e,n)},t}(),Tt=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(we.TimelineTransport.getAgent(this,t),e)},t}(),Ot=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ct=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),At=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Et=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Pt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),xt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Lt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Rt=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return Ot(e,t),e}(Error),Ut=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Mt=function(t){function e(e,n){var r=t.call(this,(function(t,n){D.debug("No callbacks on "+e+" for "+t)}))||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return Ut(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new Ct("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=H("triggeringClientEvents");D.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(D.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(tt),jt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),It=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return jt(e,t),e.prototype.authorize=function(t,e){return Kt.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(Mt),Nt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;P(this.members,(function(n,r){t(e.get(r))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),Bt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Dt=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new Nt,r}return Bt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var o=H("authenticationEndpoint");return D.error("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(It),zt=n(0),Ht=n(1),qt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ft=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return qt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(o)r.key=Object(Ht.decodeBase64)(o),delete e.shared_secret,n(!1,e);else{var i="No shared_secret key in auth payload for encrypted channel: "+r.name;n(!0,i)}}}))},e.prototype.trigger=function(t,e){throw new xt("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=Object(Ht.decodeBase64)(e.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new k(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new k(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new k(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new k(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return C({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return C({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),D.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(tt),Yt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){return 0===t.indexOf("private-encrypted-")?Kt.createEncryptedChannel(t,e):0===t.indexOf("private-")?Kt.createPrivateChannel(t,e):0===t.indexOf("presence-")?Kt.createPresenceChannel(t,e):Kt.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return P(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){P(this.channels,(function(t){t.disconnect()}))},t}();var Kt={createChannels:function(){return new Yt},createConnectionManager:function(t,e){return new Jt(t,e)},createChannel:function(t,e){return new Mt(t,e)},createPrivateChannel:function(t,e){return new It(t,e)},createPresenceChannel:function(t,e){return new Dt(t,e)},createEncryptedChannel:function(t,e){return new Ft(t,e)},createTimelineSender:function(t,e){return new Tt(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new kt(t,e)},createHandshake:function(t,e){return new St(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new gt(t,e,n)}},Wt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Kt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),Gt=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return j(this.strategies,O.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,c=function(a,u){u?e(null,u):(o+=1,n.loop&&(o%=r.length),o0&&(o=new k(n.timeout,(function(){i.abort(),r(!0)}))),i=t.connect(e,(function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))})),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Zt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return j(this.strategies,O.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var r=R(t,(function(t,r,o,i){return t.connect(e,n(r,i))}));return{abort:function(){L(r,Vt)},forceMinPriority:function(t){L(r,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(r,o){n[t].error=r,r?function(t){return function(t,e){for(var n=0;n=O.now()){var i=this.transports[r.transport];i&&(this.timeline.info({cached:!0,transport:r.transport,latency:r.latency}),o.push(new Gt([i],{timeout:2*r.latency+1e3,failFast:!0})))}var s=O.now(),c=o.pop().connect(t,(function r(i,a){i?(te(n),o.length>0?(s=O.now(),c=o.pop().connect(t,r)):e(i)):(!function(t,e,n){var r=we.getLocalStorage();if(r)try{r[$t(t)]=B({timestamp:O.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,O.now()-s),e(null,a))}));return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function $t(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function te(t){var e=we.getLocalStorage();if(e)try{delete e[$t(t)]}catch(t){}}var ee=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,r=this.strategy,o=new k(this.options.delay,(function(){n=r.connect(t,e)}));return{abort:function(){o.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),ne=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),re=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,r){r&&n.abort(),e(t,r)}));return n},t}();function oe(t){return function(){return t.isSupported()}}var ie,se=function(t,e){var n={};function r(r,o,i,s,c){var a=e(t,r,o,i,s,c);return n[r]=a,a}var o,i={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},s=C({},i,{useTLS:!0}),c={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},a={loop:!0,timeout:15e3,timeoutLimit:6e4},u=new Wt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),h=new Wt({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),p=r("ws","ws",3,i,u),f=r("wss","ws",3,s,u),l=r("sockjs","sockjs",1,c),d=r("xhr_streaming","xhr_streaming",1,c,h),y=r("xdr_streaming","xdr_streaming",1,c,h),v=r("xhr_polling","xhr_polling",1,c),g=r("xdr_polling","xdr_polling",1,c),b=new Gt([p],a),m=new Gt([f],a),w=new Gt([l],a),_=new Gt([new ne(oe(d),d,y)],a),S=new Gt([new ne(oe(v),v,g)],a),k=new Gt([new ne(oe(_),new Zt([_,new ee(S,{delay:4e3})]),S)],a),T=new ne(oe(k),k,w);return o=t.useTLS?new Zt([b,new ee(T,{delay:2e3})]):new Zt([b,new ee(m,{delay:2e3}),new ee(T,{delay:5e3})]),new Qt(new re(new ne(oe(p),o,T)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})},ce={getRequest:function(t){var e=new window.XDomainRequest;return e.ontimeout=function(){t.emit("error",new At),t.close()},e.onerror=function(e){t.emit("error",e),t.close()},e.onprogress=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText)},e.onload=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText),t.emit("finished",200),t.close()},e},abortRequest:function(t){t.ontimeout=t.onerror=t.onprogress=t.onload=null,t.abort()}},ae=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ue=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return ae(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},we.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(we.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(tt);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(ie||(ie={}));var he=ie,pe=1;function fe(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+pe++}function le(t){return Math.floor(Math.random()*t)}var de,ye=function(){function t(t,e){this.hooks=t,this.session=le(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},me={createStreamingSocket:function(t){return this.createSocket(ve,t)},createPollingSocket:function(t){return this.createSocket(ge,t)},createSocket:function(t,e){return new ye(t,e)},createXHR:function(t,e){return this.createRequest(be,t,e)},createRequest:function(t,e,n){return new ue(t,e,n)},createXDR:function(t,e){return this.createRequest(ce,t,e)}},we={nextAuthCallbackID:1,auth_callbacks:{},ScriptReceivers:o,DependenciesReceivers:c,getDefaultStrategy:se,Transports:dt,transportConnectionInitializer:function(){var t=this;t.timeline.info(t.buildTimelineMessage({transport:t.name+(t.options.useTLS?"s":"")})),t.hooks.isInitialized()?t.changeState("initialized"):t.hooks.file?(t.changeState("initializing"),a.load(t.hooks.file,{useTLS:t.options.useTLS},(function(e,n){t.hooks.isInitialized()?(t.changeState("initialized"),n(!0)):(e&&t.onError(e),t.onClose(),n(!1))}))):t.onClose()},HTTPFactory:me,TimelineTransport:Y,getXHRAPI:function(){return window.XMLHttpRequest},getWebSocketAPI:function(){return window.WebSocket||window.MozWebSocket},setup:function(t){var e=this;window.Pusher=t;var n=function(){e.onDocumentBody(t.ready)};window.JSON?n():a.load("json2",{},n)},getDocument:function(){return document},getProtocol:function(){return this.getDocument().location.protocol},getAuthorizers:function(){return{ajax:q,jsonp:F}},onDocumentBody:function(t){var e=this;document.body?t():setTimeout((function(){e.onDocumentBody(t)}),0)},createJSONPRequest:function(t,e){return new J(t,e)},createScriptRequest:function(t){return new X(t)},getLocalStorage:function(){try{return window.localStorage}catch(t){return}},createXHR:function(){return this.getXHRAPI()?this.createXMLHttpRequest():this.createMicrosoftXHR()},createXMLHttpRequest:function(){return new(this.getXHRAPI())},createMicrosoftXHR:function(){return new ActiveXObject("Microsoft.XMLHTTP")},getNetwork:function(){return vt},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);if(this.isXDRSupported(0===e.indexOf("https:")))return this.HTTPFactory.createXDR(t,e);throw"Cross-origin HTTP requests are not supported"},isXHRSupported:function(){var t=this.getXHRAPI();return Boolean(t)&&void 0!==(new t).withCredentials},isXDRSupported:function(t){var e=t?"https:":"http:",n=this.getProtocol();return Boolean(window.XDomainRequest)&&n===e},addUnloadListener:function(t){void 0!==window.addEventListener?window.addEventListener("unload",t,!1):void 0!==window.attachEvent&&window.attachEvent("onunload",t)},removeUnloadListener:function(t){void 0!==window.addEventListener?window.removeEventListener("unload",t,!1):void 0!==window.detachEvent&&window.detachEvent("onunload",t)}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(de||(de={}));var _e=de,Se=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(C({},e,{timestamp:O.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(_e.ERROR,t)},t.prototype.info=function(t){this.log(_e.INFO,t)},t.prototype.debug=function(t){this.log(_e.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,r=C({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(r,(function(t,r){t||n.sent++,e&&e(t,r)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),ke=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return Te(new Rt,e);if(this.priority>>18&63),e+=this._encodeByte(o>>>12&63),e+=this._encodeByte(o>>>6&63),e+=this._encodeByte(o>>>0&63)}var r=t.length-n;if(r>0){o=t[n]<<16|(2===r?t[n+1]<<8:0);e+=this._encodeByte(o>>>18&63),e+=this._encodeByte(o>>>12&63),e+=2===r?this._encodeByte(o>>>6&63):this._paddingCharacter||"",e+=this._paddingCharacter||""}return e},t.prototype.maxDecodedLength=function(t){return this._paddingCharacter?t/4*3|0:(6*t+7)/8|0},t.prototype.decodedLength=function(t){return this.maxDecodedLength(t.length-this._getPaddingLength(t))},t.prototype.decode=function(t){if(0===t.length)return new Uint8Array(0);for(var e=this._getPaddingLength(t),n=t.length-e,o=new Uint8Array(this.maxDecodedLength(n)),r=0,i=0,s=0,c=0,a=0,u=0,h=0;i>>4,o[r++]=a<<4|u>>>2,o[r++]=u<<6|h,s|=256&c,s|=256&a,s|=256&u,s|=256&h;if(i>>4,s|=256&c,s|=256&a),i>>2,s|=256&u),i>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-15,e+=62-t>>>8&3,String.fromCharCode(e)},t.prototype._decodeChar=function(t){var e=256;return e+=(42-t&t-44)>>>8&-256+t-43+62,e+=(46-t&t-48)>>>8&-256+t-47+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},t.prototype._getPaddingLength=function(t){var e=0;if(this._paddingCharacter){for(var n=t.length-1;n>=0&&t[n]===this._paddingCharacter;n--)e++;if(t.length<4||e>2)throw new Error("Base64Coder: incorrect padding")}return e},t}();e.Coder=i;var s=new i;e.encode=function(t){return s.encode(t)},e.decode=function(t){return s.decode(t)};var c=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype._encodeByte=function(t){var e=t;return e+=65,e+=25-t>>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-13,e+=62-t>>>8&49,String.fromCharCode(e)},e.prototype._decodeChar=function(t){var e=256;return e+=(44-t&t-46)>>>8&-256+t-45+62,e+=(94-t&t-96)>>>8&-256+t-95+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},e}(i);e.URLSafeCoder=c;var a=new c;e.encodeURLSafe=function(t){return a.encode(t)},e.decodeURLSafe=function(t){return a.decode(t)},e.encodedLength=function(t){return s.encodedLength(t)},e.maxDecodedLength=function(t){return s.maxDecodedLength(t)},e.decodedLength=function(t){return s.decodedLength(t)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o="utf8: invalid source encoding";function r(t){for(var e=0,n=0;n=t.length-1)throw new Error("utf8: invalid string");n++,e+=4}}return e}e.encode=function(t){for(var e=new Uint8Array(r(t)),n=0,o=0;o>6,e[n++]=128|63&i):i<55296?(e[n++]=224|i>>12,e[n++]=128|i>>6&63,e[n++]=128|63&i):(o++,i=(1023&i)<<10,i|=1023&t.charCodeAt(o),i+=65536,e[n++]=240|i>>18,e[n++]=128|i>>12&63,e[n++]=128|i>>6&63,e[n++]=128|63&i)}return e},e.encodedLength=r,e.decode=function(t){for(var e=[],n=0;n=t.length)throw new Error(o);if(128!=(192&(s=t[++n])))throw new Error(o);r=(31&r)<<6|63&s,i=128}else if(r<240){if(n>=t.length-1)throw new Error(o);var s=t[++n],c=t[++n];if(128!=(192&s)||128!=(192&c))throw new Error(o);r=(15&r)<<12|(63&s)<<6|63&c,i=2048}else{if(!(r<248))throw new Error(o);if(n>=t.length-2)throw new Error(o);s=t[++n],c=t[++n];var a=t[++n];if(128!=(192&s)||128!=(192&c)||128!=(192&a))throw new Error(o);r=(15&r)<<18|(63&s)<<12|(63&c)<<6|63&a,i=65536}if(r=55296&&r<=57343)throw new Error(o);if(r>=65536){if(r>1114111)throw new Error(o);r-=65536,e.push(String.fromCharCode(55296|r>>10)),r=56320|1023&r}}e.push(String.fromCharCode(r))}return e.join("")}},function(t,e,n){t.exports=n(3).default},function(t,e,n){"use strict";n.r(e);var o=function(){function t(t,e){this.lastId=0,this.prefix=t,this.name=e}return t.prototype.create=function(t){this.lastId++;var e=this.lastId,n=this.prefix+e,o=this.name+"["+e+"]",r=!1,i=function(){r||(t.apply(null,arguments),r=!0)};return this[e]=i,{number:e,id:n,name:o,callback:i}},t.prototype.remove=function(t){delete this[t.number]},t}(),r=new o("_pusher_script_","Pusher.ScriptReceivers"),i={VERSION:"6.0.0",PROTOCOL:7,wsPort:80,wssPort:443,wsPath:"",httpHost:"sockjs.pusher.com",httpPort:80,httpsPort:443,httpPath:"/pusher",stats_host:"stats.pusher.com",authEndpoint:"/pusher/auth",authTransport:"ajax",activityTimeout:12e4,pongTimeout:3e4,unavailableTimeout:1e4,cluster:"mt1",cdn_http:"http://js.pusher.com",cdn_https:"https://js.pusher.com",dependency_suffix:""},s=function(){function t(t){this.options=t,this.receivers=t.receivers||r,this.loading={}}return t.prototype.load=function(t,e,n){var o=this;if(o.loading[t]&&o.loading[t].length>0)o.loading[t].push(n);else{o.loading[t]=[n];var r=we.createScriptRequest(o.getPath(t,e)),i=o.receivers.create((function(e){if(o.receivers.remove(i),o.loading[t]){var n=o.loading[t];delete o.loading[t];for(var s=function(t){t||r.cleanup()},c=0;c>>6)+u(128|63&e):u(224|e>>>12&15)+u(128|e>>>6&63)+u(128|63&e)},g=function(t){return t.replace(/[^\x00-\x7F]/g,y)},v=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[h.charAt(n>>>18),h.charAt(n>>>12&63),e>=2?"=":h.charAt(n>>>6&63),e>=1?"=":h.charAt(63&n)].join("")},b=window.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,v)},m=function(){function t(t,e,n,o){var r=this;this.clear=e,this.timer=t((function(){r.timer&&(r.timer=o(r.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),w=(d=function(t,e){return(d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function _(t){window.clearTimeout(t)}function S(t){window.clearInterval(t)}var k=function(t){function e(e,n){return t.call(this,setTimeout,_,e,(function(t){return n(),null}))||this}return w(e,t),e}(m),C=function(t){function e(e,n){return t.call(this,setInterval,S,e,(function(t){return n(),t}))||this}return w(e,t),e}(m),T={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new k(0,t)},method:function(t){for(var e=[],n=1;n0)for(o=0;o=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},mt=bt,wt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),_t=function(t){function e(e,n){var o=t.call(this)||this;return o.id=e,o.transport=n,o.activityTimeout=n.activityTimeout,o.bindListeners(),o}return wt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var o={event:t,data:e};return n&&(o.channel=n),q.debug("Event sent",o),this.send(mt.encodeMessage(o))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=mt.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(q.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){L(e,(function(e,n){t.transport.unbind(n,e)}))};L(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=mt.getCloseAction(t),n=mt.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(tt),St=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=mt.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new _t(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=mt.getCloseAction(e)||"backoff",o=mt.getCloseError(e);t.finish(n,{error:o})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(P({transport:this.transport,action:t},e))},t}(),kt=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===we.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=e.auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||we.getAuthorizers(),t.authorizers[this.type].call(this,we,e,n)},t}(),Ct=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(we.TimelineTransport.getAgent(this,t),e)},t}(),Tt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Pt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),Ot=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),Et=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),Lt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),xt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),At=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),Rt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return Tt(e,t),e}(Error),jt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),It=function(t){function e(e,n){var o=t.call(this,(function(t,n){q.debug("No callbacks on "+e+" for "+t)}))||this;return o.name=e,o.pusher=n,o.subscribed=!1,o.subscriptionPending=!1,o.subscriptionCancelled=!1,o}return jt(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new Pt("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=z("triggeringClientEvents");q.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(q.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(tt),Dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Nt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Dt(e,t),e.prototype.authorize=function(t,e){return Gt.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(It),Mt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;L(this.members,(function(n,o){t(e.get(o))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),Ht=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),qt=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.members=new Mt,o}return Ht(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var r=z("authenticationEndpoint");return q.error("Invalid auth response for channel '"+o.name+"',expected 'channel_data' field. "+r),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);o.members.setMyID(i.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,o={};t.user_id&&(o.user_id=t.user_id),this.emit(e,n,o)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var o=this.members.addMember(n);this.emit("pusher:member_added",o);break;case"pusher_internal:member_removed":var r=this.members.removeMember(n);r&&this.emit("pusher:member_removed",r)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(Nt),Bt=n(1),zt=n(0),Ut=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Ft=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;return r.key=null,r.nacl=o,r}return Ut(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var r=e.shared_secret;if(r)o.key=Object(zt.decode)(r),delete e.shared_secret,n(!1,e);else{var i="No shared_secret key in auth payload for encrypted channel: "+o.name;n(!0,i)}}}))},e.prototype.trigger=function(t,e){throw new xt("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,o=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,o):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var o=Object(zt.decode)(e.ciphertext);if(o.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new k(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new k(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new k(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new k(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return P({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return P({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var o=t;"connected"===o&&(o+=" with new socket ID "+e.socket_id),q.debug("State changed",n+" -> "+o),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(tt),Wt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){if(e.config.nacl)return Gt.createEncryptedChannel(t,e,e.config.nacl);var n=z("encryptedChannelSupport");throw new xt("Tried to subscribe to a private-encrypted- channel but no nacl implementation available. "+n)}return 0===t.indexOf("private-")?Gt.createPrivateChannel(t,e):0===t.indexOf("presence-")?Gt.createPresenceChannel(t,e):Gt.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return L(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){L(this.channels,(function(t){t.disconnect()}))},t}();var Gt={createChannels:function(){return new Wt},createConnectionManager:function(t,e){return new Xt(t,e)},createChannel:function(t,e){return new It(t,e)},createPrivateChannel:function(t,e){return new Nt(t,e)},createPresenceChannel:function(t,e){return new qt(t,e)},createEncryptedChannel:function(t,e,n){return new Ft(t,e,n)},createTimelineSender:function(t,e){return new Ct(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new kt(t,e)},createHandshake:function(t,e){return new St(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new vt(t,e,n)}},Qt=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Gt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),Vt=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return D(this.strategies,T.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,o=this.strategies,r=0,i=this.timeout,s=null,c=function(a,u){u?e(null,u):(r+=1,n.loop&&(r%=o.length),r0&&(r=new k(n.timeout,(function(){i.abort(),o(!0)}))),i=t.connect(e,(function(t,e){t&&r&&r.isRunning()&&!n.failFast||(r&&r.ensureAborted(),o(t,e))})),{abort:function(){r&&r.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Yt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return D(this.strategies,T.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var o=R(t,(function(t,o,r,i){return t.connect(e,n(o,i))}));return{abort:function(){A(o,$t)},forceMinPriority:function(t){A(o,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(o,r){n[t].error=o,o?function(t){return function(t,e){for(var n=0;n=T.now()){var i=this.transports[o.transport];i&&(this.timeline.info({cached:!0,transport:o.transport,latency:o.latency}),r.push(new Vt([i],{timeout:2*o.latency+1e3,failFast:!0})))}var s=T.now(),c=r.pop().connect(t,(function o(i,a){i?(te(n),r.length>0?(s=T.now(),c=r.pop().connect(t,o)):e(i)):(!function(t,e,n){var o=we.getLocalStorage();if(o)try{o[Zt(t)]=H({timestamp:T.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,T.now()-s),e(null,a))}));return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function Zt(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function te(t){var e=we.getLocalStorage();if(e)try{delete e[Zt(t)]}catch(t){}}var ee=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,o=this.strategy,r=new k(this.options.delay,(function(){n=o.connect(t,e)}));return{abort:function(){r.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),ne=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),oe=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,o){o&&n.abort(),e(t,o)}));return n},t}();function re(t){return function(){return t.isSupported()}}var ie,se=function(t,e,n){var o={};function r(e,r,i,s,c){var a=n(t,e,r,i,s,c);return o[e]=a,a}var i,s=Object.assign({},e,{hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath}),c=Object.assign({},s,{useTLS:!0}),a=Object.assign({},e,{hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath}),u={loop:!0,timeout:15e3,timeoutLimit:6e4},h=new Qt({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),p=new Qt({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),l=r("ws","ws",3,s,h),f=r("wss","ws",3,c,h),d=r("sockjs","sockjs",1,a),y=r("xhr_streaming","xhr_streaming",1,a,p),g=r("xdr_streaming","xdr_streaming",1,a,p),v=r("xhr_polling","xhr_polling",1,a),b=r("xdr_polling","xdr_polling",1,a),m=new Vt([l],u),w=new Vt([f],u),_=new Vt([d],u),S=new Vt([new ne(re(y),y,g)],u),k=new Vt([new ne(re(v),v,b)],u),C=new Vt([new ne(re(S),new Yt([S,new ee(k,{delay:4e3})]),k)],u),T=new ne(re(C),C,_);return i=e.useTLS?new Yt([m,new ee(T,{delay:2e3})]):new Yt([m,new ee(w,{delay:2e3}),new ee(T,{delay:5e3})]),new Kt(new oe(new ne(re(l),i,T)),o,{ttl:18e5,timeline:e.timeline,useTLS:e.useTLS})},ce={getRequest:function(t){var e=new window.XDomainRequest;return e.ontimeout=function(){t.emit("error",new Ot),t.close()},e.onerror=function(e){t.emit("error",e),t.close()},e.onprogress=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText)},e.onload=function(){e.responseText&&e.responseText.length>0&&t.onChunk(200,e.responseText),t.emit("finished",200),t.close()},e},abortRequest:function(t){t.ontimeout=t.onerror=t.onprogress=t.onload=null,t.abort()}},ae=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),ue=function(t){function e(e,n,o){var r=t.call(this)||this;return r.hooks=e,r.method=n,r.url=o,r}return ae(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},we.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(we.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(tt);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(ie||(ie={}));var he=ie,pe=1;function le(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+pe++}function fe(t){return Math.floor(Math.random()*t)}var de,ye=function(){function t(t,e){this.hooks=t,this.session=fe(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},me={createStreamingSocket:function(t){return this.createSocket(ge,t)},createPollingSocket:function(t){return this.createSocket(ve,t)},createSocket:function(t,e){return new ye(t,e)},createXHR:function(t,e){return this.createRequest(be,t,e)},createRequest:function(t,e,n){return new ue(t,e,n)},createXDR:function(t,e){return this.createRequest(ce,t,e)}},we={nextAuthCallbackID:1,auth_callbacks:{},ScriptReceivers:r,DependenciesReceivers:c,getDefaultStrategy:se,Transports:dt,transportConnectionInitializer:function(){var t=this;t.timeline.info(t.buildTimelineMessage({transport:t.name+(t.options.useTLS?"s":"")})),t.hooks.isInitialized()?t.changeState("initialized"):t.hooks.file?(t.changeState("initializing"),a.load(t.hooks.file,{useTLS:t.options.useTLS},(function(e,n){t.hooks.isInitialized()?(t.changeState("initialized"),n(!0)):(e&&t.onError(e),t.onClose(),n(!1))}))):t.onClose()},HTTPFactory:me,TimelineTransport:W,getXHRAPI:function(){return window.XMLHttpRequest},getWebSocketAPI:function(){return window.WebSocket||window.MozWebSocket},setup:function(t){var e=this;window.Pusher=t;var n=function(){e.onDocumentBody(t.ready)};window.JSON?n():a.load("json2",{},n)},getDocument:function(){return document},getProtocol:function(){return this.getDocument().location.protocol},getAuthorizers:function(){return{ajax:U,jsonp:F}},onDocumentBody:function(t){var e=this;document.body?t():setTimeout((function(){e.onDocumentBody(t)}),0)},createJSONPRequest:function(t,e){return new X(t,e)},createScriptRequest:function(t){return new J(t)},getLocalStorage:function(){try{return window.localStorage}catch(t){return}},createXHR:function(){return this.getXHRAPI()?this.createXMLHttpRequest():this.createMicrosoftXHR()},createXMLHttpRequest:function(){return new(this.getXHRAPI())},createMicrosoftXHR:function(){return new ActiveXObject("Microsoft.XMLHTTP")},getNetwork:function(){return gt},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);if(this.isXDRSupported(0===e.indexOf("https:")))return this.HTTPFactory.createXDR(t,e);throw"Cross-origin HTTP requests are not supported"},isXHRSupported:function(){var t=this.getXHRAPI();return Boolean(t)&&void 0!==(new t).withCredentials},isXDRSupported:function(t){var e=t?"https:":"http:",n=this.getProtocol();return Boolean(window.XDomainRequest)&&n===e},addUnloadListener:function(t){void 0!==window.addEventListener?window.addEventListener("unload",t,!1):void 0!==window.attachEvent&&window.attachEvent("onunload",t)},removeUnloadListener:function(t){void 0!==window.addEventListener?window.removeEventListener("unload",t,!1):void 0!==window.detachEvent&&window.detachEvent("onunload",t)}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(de||(de={}));var _e=de,Se=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(P({},e,{timestamp:T.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(_e.ERROR,t)},t.prototype.info=function(t){this.log(_e.INFO,t)},t.prototype.debug=function(t){this.log(_e.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,o=P({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,(function(t,o){t||n.sent++,e&&e(t,o)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),ke=function(){function t(t,e,n,o){this.name=t,this.priority=e,this.transport=n,this.options=o||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return Ce(new Rt,e);if(this.priority>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + out += this._encodeByte((c >>> 1 * 6) & 63); + out += this._encodeByte((c >>> 0 * 6) & 63); + } + var left = data.length - i; + if (left > 0) { + var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + if (left === 2) { + out += this._encodeByte((c >>> 1 * 6) & 63); + } + else { + out += this._paddingCharacter || ""; + } + out += this._paddingCharacter || ""; + } + return out; + }; + Coder.prototype.maxDecodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 6 + 7) / 8 | 0; + } + return length / 4 * 3 | 0; + }; + Coder.prototype.decodedLength = function (s) { + return this.maxDecodedLength(s.length - this._getPaddingLength(s)); + }; + Coder.prototype.decode = function (s) { + if (s.length === 0) { + return new Uint8Array(0); + } + var paddingLength = this._getPaddingLength(s); + var length = s.length - paddingLength; + var out = new Uint8Array(this.maxDecodedLength(length)); + var op = 0; + var i = 0; + var haveBad = 0; + var v0 = 0, v1 = 0, v2 = 0, v3 = 0; + for (; i < length - 4; i += 4) { + v0 = this._decodeChar(s.charCodeAt(i + 0)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + v2 = this._decodeChar(s.charCodeAt(i + 2)); + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v0 << 2) | (v1 >>> 4); + out[op++] = (v1 << 4) | (v2 >>> 2); + out[op++] = (v2 << 6) | v3; + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + haveBad |= v2 & INVALID_BYTE; + haveBad |= v3 & INVALID_BYTE; + } + if (i < length - 1) { + v0 = this._decodeChar(s.charCodeAt(i)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + out[op++] = (v0 << 2) | (v1 >>> 4); + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + } + if (i < length - 2) { + v2 = this._decodeChar(s.charCodeAt(i + 2)); + out[op++] = (v1 << 4) | (v2 >>> 2); + haveBad |= v2 & INVALID_BYTE; + } + if (i < length - 3) { + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v2 << 6) | v3; + haveBad |= v3 & INVALID_BYTE; + } + if (haveBad !== 0) { + throw new Error("Base64Coder: incorrect characters for decoding"); + } + return out; + }; + // Standard encoding have the following encoded/decoded ranges, + // which we need to convert between. + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + / + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 43 47 + // + // Encode 6 bits in b into a new character. + Coder.prototype._encodeByte = function (b) { + // Encoding uses constant time operations as follows: + // + // 1. Define comparison of A with B using (A - B) >>> 8: + // if A > B, then result is positive integer + // if A <= B, then result is 0 + // + // 2. Define selection of C or 0 using bitwise AND: X & C: + // if X == 0, then result is 0 + // if X != 0, then result is C + // + // 3. Start with the smallest comparison (b >= 0), which is always + // true, so set the result to the starting ASCII value (65). + // + // 4. Continue comparing b to higher ASCII values, and selecting + // zero if comparison isn't true, otherwise selecting a value + // to add to result, which: + // + // a) undoes the previous addition + // b) provides new value to add + // + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47); + return String.fromCharCode(result); + }; + // Decode a character code into a byte. + // Must return 256 if character is out of alphabet range. + Coder.prototype._decodeChar = function (c) { + // Decoding works similar to encoding: using the same comparison + // function, but now it works on ranges: result is always incremented + // by value, but this value becomes zero if the range is not + // satisfied. + // + // Decoding starts with invalid value, 256, which is then + // subtracted when the range is satisfied. If none of the ranges + // apply, the function returns 256, which is then checked by + // the caller to throw error. + var result = INVALID_BYTE; // start with invalid character + // c == 43 (c > 42 and c < 44) + result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62); + // c == 47 (c > 46 and c < 48) + result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + Coder.prototype._getPaddingLength = function (s) { + var paddingLength = 0; + if (this._paddingCharacter) { + for (var i = s.length - 1; i >= 0; i--) { + if (s[i] !== this._paddingCharacter) { + break; + } + paddingLength++; + } + if (s.length < 4 || paddingLength > 2) { + throw new Error("Base64Coder: incorrect padding"); + } + } + return paddingLength; + }; + return Coder; +}()); +exports.Coder = Coder; +var stdCoder = new Coder(); +function encode(data) { + return stdCoder.encode(data); +} +exports.encode = encode; +function decode(s) { + return stdCoder.decode(s); +} +exports.decode = decode; +/** + * Implements URL-safe Base64 encoding. + * (Same as Base64, but '+' is replaced with '-', and '/' with '_'). + * + * Operates in constant time. + */ +var URLSafeCoder = /** @class */ (function (_super) { + __extends(URLSafeCoder, _super); + function URLSafeCoder() { + return _super !== null && _super.apply(this, arguments) || this; + } + // URL-safe encoding have the following encoded/decoded ranges: + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _ + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 45 95 + // + URLSafeCoder.prototype._encodeByte = function (b) { + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95); + return String.fromCharCode(result); + }; + URLSafeCoder.prototype._decodeChar = function (c) { + var result = INVALID_BYTE; + // c == 45 (c > 44 and c < 46) + result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62); + // c == 95 (c > 94 and c < 96) + result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + return URLSafeCoder; +}(Coder)); +exports.URLSafeCoder = URLSafeCoder; +var urlSafeCoder = new URLSafeCoder(); +function encodeURLSafe(data) { + return urlSafeCoder.encode(data); +} +exports.encodeURLSafe = encodeURLSafe; +function decodeURLSafe(s) { + return urlSafeCoder.decode(s); +} +exports.decodeURLSafe = decodeURLSafe; +exports.encodedLength = function (length) { + return stdCoder.encodedLength(length); +}; +exports.maxDecodedLength = function (length) { + return stdCoder.maxDecodedLength(length); +}; +exports.decodedLength = function (s) { + return stdCoder.decodedLength(s); +}; +//# sourceMappingURL=base64.js.map + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package utf8 implements UTF-8 encoding and decoding. + */ +var INVALID_UTF16 = "utf8: invalid string"; +var INVALID_UTF8 = "utf8: invalid source encoding"; +/** + * Encodes the given string into UTF-8 byte array. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encode(s) { + // Calculate result length and allocate output array. + // encodedLength() also validates string and throws errors, + // so we don't need repeat validation here. + var arr = new Uint8Array(encodedLength(s)); + var pos = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + arr[pos++] = c; + } + else if (c < 0x800) { + arr[pos++] = 0xc0 | c >> 6; + arr[pos++] = 0x80 | c & 0x3f; + } + else if (c < 0xd800) { + arr[pos++] = 0xe0 | c >> 12; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + else { + i++; // get one more character + c = (c & 0x3ff) << 10; + c |= s.charCodeAt(i) & 0x3ff; + c += 0x10000; + arr[pos++] = 0xf0 | c >> 18; + arr[pos++] = 0x80 | (c >> 12) & 0x3f; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + } + return arr; +} +exports.encode = encode; +/** + * Returns the number of bytes required to encode the given string into UTF-8. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encodedLength(s) { + var result = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + result += 1; + } + else if (c < 0x800) { + result += 2; + } + else if (c < 0xd800) { + result += 3; + } + else if (c <= 0xdfff) { + if (i >= s.length - 1) { + throw new Error(INVALID_UTF16); + } + i++; // "eat" next character + result += 4; + } + else { + throw new Error(INVALID_UTF16); + } + } + return result; +} +exports.encodedLength = encodedLength; +/** + * Decodes the given byte array from UTF-8 into a string. + * Throws if encoding is invalid. + */ +function decode(arr) { + var chars = []; + for (var i = 0; i < arr.length; i++) { + var b = arr[i]; + if (b & 0x80) { + var min = void 0; + if (b < 0xe0) { + // Need 1 more byte. + if (i >= arr.length) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + if ((n1 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x1f) << 6 | (n1 & 0x3f); + min = 0x80; + } + else if (b < 0xf0) { + // Need 2 more bytes. + if (i >= arr.length - 1) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 12 | (n1 & 0x3f) << 6 | (n2 & 0x3f); + min = 0x800; + } + else if (b < 0xf8) { + // Need 3 more bytes. + if (i >= arr.length - 2) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + var n3 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80 || (n3 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 18 | (n1 & 0x3f) << 12 | (n2 & 0x3f) << 6 | (n3 & 0x3f); + min = 0x10000; + } + else { + throw new Error(INVALID_UTF8); + } + if (b < min || (b >= 0xd800 && b <= 0xdfff)) { + throw new Error(INVALID_UTF8); + } + if (b >= 0x10000) { + // Surrogate pair. + if (b > 0x10ffff) { + throw new Error(INVALID_UTF8); + } + b -= 0x10000; + chars.push(String.fromCharCode(0xd800 | (b >> 10))); + b = 0xdc00 | (b & 0x3ff); + } + } + chars.push(String.fromCharCode(b)); + } + return chars.join(""); +} +exports.decode = decode; +//# sourceMappingURL=utf8.js.map + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +(function(nacl) { +'use strict'; + +// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. +// Public domain. +// +// Implementation derived from TweetNaCl version 20140427. +// See for details: http://tweetnacl.cr.yp.to/ + +var gf = function(init) { + var i, r = new Float64Array(16); + if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; + return r; +}; + +// Pluggable, initialized in high-level API below. +var randombytes = function(/* x, n */) { throw new Error('no PRNG'); }; + +var _0 = new Uint8Array(16); +var _9 = new Uint8Array(32); _9[0] = 9; + +var gf0 = gf(), + gf1 = gf([1]), + _121665 = gf([0xdb41, 1]), + D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]), + D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]), + X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]), + Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]), + I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]); + +function ts64(x, i, h, l) { + x[i] = (h >> 24) & 0xff; + x[i+1] = (h >> 16) & 0xff; + x[i+2] = (h >> 8) & 0xff; + x[i+3] = h & 0xff; + x[i+4] = (l >> 24) & 0xff; + x[i+5] = (l >> 16) & 0xff; + x[i+6] = (l >> 8) & 0xff; + x[i+7] = l & 0xff; +} + +function vn(x, xi, y, yi, n) { + var i,d = 0; + for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; + return (1 & ((d - 1) >>> 8)) - 1; +} + +function crypto_verify_16(x, xi, y, yi) { + return vn(x,xi,y,yi,16); +} + +function crypto_verify_32(x, xi, y, yi) { + return vn(x,xi,y,yi,32); +} + +function core_salsa20(o, p, k, c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + x0 = x0 + j0 | 0; + x1 = x1 + j1 | 0; + x2 = x2 + j2 | 0; + x3 = x3 + j3 | 0; + x4 = x4 + j4 | 0; + x5 = x5 + j5 | 0; + x6 = x6 + j6 | 0; + x7 = x7 + j7 | 0; + x8 = x8 + j8 | 0; + x9 = x9 + j9 | 0; + x10 = x10 + j10 | 0; + x11 = x11 + j11 | 0; + x12 = x12 + j12 | 0; + x13 = x13 + j13 | 0; + x14 = x14 + j14 | 0; + x15 = x15 + j15 | 0; + + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + + o[ 4] = x1 >>> 0 & 0xff; + o[ 5] = x1 >>> 8 & 0xff; + o[ 6] = x1 >>> 16 & 0xff; + o[ 7] = x1 >>> 24 & 0xff; + + o[ 8] = x2 >>> 0 & 0xff; + o[ 9] = x2 >>> 8 & 0xff; + o[10] = x2 >>> 16 & 0xff; + o[11] = x2 >>> 24 & 0xff; + + o[12] = x3 >>> 0 & 0xff; + o[13] = x3 >>> 8 & 0xff; + o[14] = x3 >>> 16 & 0xff; + o[15] = x3 >>> 24 & 0xff; + + o[16] = x4 >>> 0 & 0xff; + o[17] = x4 >>> 8 & 0xff; + o[18] = x4 >>> 16 & 0xff; + o[19] = x4 >>> 24 & 0xff; + + o[20] = x5 >>> 0 & 0xff; + o[21] = x5 >>> 8 & 0xff; + o[22] = x5 >>> 16 & 0xff; + o[23] = x5 >>> 24 & 0xff; + + o[24] = x6 >>> 0 & 0xff; + o[25] = x6 >>> 8 & 0xff; + o[26] = x6 >>> 16 & 0xff; + o[27] = x6 >>> 24 & 0xff; + + o[28] = x7 >>> 0 & 0xff; + o[29] = x7 >>> 8 & 0xff; + o[30] = x7 >>> 16 & 0xff; + o[31] = x7 >>> 24 & 0xff; + + o[32] = x8 >>> 0 & 0xff; + o[33] = x8 >>> 8 & 0xff; + o[34] = x8 >>> 16 & 0xff; + o[35] = x8 >>> 24 & 0xff; + + o[36] = x9 >>> 0 & 0xff; + o[37] = x9 >>> 8 & 0xff; + o[38] = x9 >>> 16 & 0xff; + o[39] = x9 >>> 24 & 0xff; + + o[40] = x10 >>> 0 & 0xff; + o[41] = x10 >>> 8 & 0xff; + o[42] = x10 >>> 16 & 0xff; + o[43] = x10 >>> 24 & 0xff; + + o[44] = x11 >>> 0 & 0xff; + o[45] = x11 >>> 8 & 0xff; + o[46] = x11 >>> 16 & 0xff; + o[47] = x11 >>> 24 & 0xff; + + o[48] = x12 >>> 0 & 0xff; + o[49] = x12 >>> 8 & 0xff; + o[50] = x12 >>> 16 & 0xff; + o[51] = x12 >>> 24 & 0xff; + + o[52] = x13 >>> 0 & 0xff; + o[53] = x13 >>> 8 & 0xff; + o[54] = x13 >>> 16 & 0xff; + o[55] = x13 >>> 24 & 0xff; + + o[56] = x14 >>> 0 & 0xff; + o[57] = x14 >>> 8 & 0xff; + o[58] = x14 >>> 16 & 0xff; + o[59] = x14 >>> 24 & 0xff; + + o[60] = x15 >>> 0 & 0xff; + o[61] = x15 >>> 8 & 0xff; + o[62] = x15 >>> 16 & 0xff; + o[63] = x15 >>> 24 & 0xff; +} + +function core_hsalsa20(o,p,k,c) { + var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, + j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, + j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, + j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, + j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, + j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, + j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, + j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, + j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, + j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, + j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, + j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, + j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, + j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, + j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, + j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; + + var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, + x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, + x15 = j15, u; + + for (var i = 0; i < 20; i += 2) { + u = x0 + x12 | 0; + x4 ^= u<<7 | u>>>(32-7); + u = x4 + x0 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x4 | 0; + x12 ^= u<<13 | u>>>(32-13); + u = x12 + x8 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x1 | 0; + x9 ^= u<<7 | u>>>(32-7); + u = x9 + x5 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x9 | 0; + x1 ^= u<<13 | u>>>(32-13); + u = x1 + x13 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x6 | 0; + x14 ^= u<<7 | u>>>(32-7); + u = x14 + x10 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x14 | 0; + x6 ^= u<<13 | u>>>(32-13); + u = x6 + x2 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x11 | 0; + x3 ^= u<<7 | u>>>(32-7); + u = x3 + x15 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x3 | 0; + x11 ^= u<<13 | u>>>(32-13); + u = x11 + x7 | 0; + x15 ^= u<<18 | u>>>(32-18); + + u = x0 + x3 | 0; + x1 ^= u<<7 | u>>>(32-7); + u = x1 + x0 | 0; + x2 ^= u<<9 | u>>>(32-9); + u = x2 + x1 | 0; + x3 ^= u<<13 | u>>>(32-13); + u = x3 + x2 | 0; + x0 ^= u<<18 | u>>>(32-18); + + u = x5 + x4 | 0; + x6 ^= u<<7 | u>>>(32-7); + u = x6 + x5 | 0; + x7 ^= u<<9 | u>>>(32-9); + u = x7 + x6 | 0; + x4 ^= u<<13 | u>>>(32-13); + u = x4 + x7 | 0; + x5 ^= u<<18 | u>>>(32-18); + + u = x10 + x9 | 0; + x11 ^= u<<7 | u>>>(32-7); + u = x11 + x10 | 0; + x8 ^= u<<9 | u>>>(32-9); + u = x8 + x11 | 0; + x9 ^= u<<13 | u>>>(32-13); + u = x9 + x8 | 0; + x10 ^= u<<18 | u>>>(32-18); + + u = x15 + x14 | 0; + x12 ^= u<<7 | u>>>(32-7); + u = x12 + x15 | 0; + x13 ^= u<<9 | u>>>(32-9); + u = x13 + x12 | 0; + x14 ^= u<<13 | u>>>(32-13); + u = x14 + x13 | 0; + x15 ^= u<<18 | u>>>(32-18); + } + + o[ 0] = x0 >>> 0 & 0xff; + o[ 1] = x0 >>> 8 & 0xff; + o[ 2] = x0 >>> 16 & 0xff; + o[ 3] = x0 >>> 24 & 0xff; + + o[ 4] = x5 >>> 0 & 0xff; + o[ 5] = x5 >>> 8 & 0xff; + o[ 6] = x5 >>> 16 & 0xff; + o[ 7] = x5 >>> 24 & 0xff; + + o[ 8] = x10 >>> 0 & 0xff; + o[ 9] = x10 >>> 8 & 0xff; + o[10] = x10 >>> 16 & 0xff; + o[11] = x10 >>> 24 & 0xff; + + o[12] = x15 >>> 0 & 0xff; + o[13] = x15 >>> 8 & 0xff; + o[14] = x15 >>> 16 & 0xff; + o[15] = x15 >>> 24 & 0xff; + + o[16] = x6 >>> 0 & 0xff; + o[17] = x6 >>> 8 & 0xff; + o[18] = x6 >>> 16 & 0xff; + o[19] = x6 >>> 24 & 0xff; + + o[20] = x7 >>> 0 & 0xff; + o[21] = x7 >>> 8 & 0xff; + o[22] = x7 >>> 16 & 0xff; + o[23] = x7 >>> 24 & 0xff; + + o[24] = x8 >>> 0 & 0xff; + o[25] = x8 >>> 8 & 0xff; + o[26] = x8 >>> 16 & 0xff; + o[27] = x8 >>> 24 & 0xff; + + o[28] = x9 >>> 0 & 0xff; + o[29] = x9 >>> 8 & 0xff; + o[30] = x9 >>> 16 & 0xff; + o[31] = x9 >>> 24 & 0xff; +} + +function crypto_core_salsa20(out,inp,k,c) { + core_salsa20(out,inp,k,c); +} + +function crypto_core_hsalsa20(out,inp,k,c) { + core_hsalsa20(out,inp,k,c); +} + +var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); + // "expand 32-byte k" + +function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + mpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; + } + return 0; +} + +function crypto_stream_salsa20(c,cpos,b,n,k) { + var z = new Uint8Array(16), x = new Uint8Array(64); + var u, i; + for (i = 0; i < 16; i++) z[i] = 0; + for (i = 0; i < 8; i++) z[i] = n[i]; + while (b >= 64) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < 64; i++) c[cpos+i] = x[i]; + u = 1; + for (i = 8; i < 16; i++) { + u = u + (z[i] & 0xff) | 0; + z[i] = u & 0xff; + u >>>= 8; + } + b -= 64; + cpos += 64; + } + if (b > 0) { + crypto_core_salsa20(x,z,k,sigma); + for (i = 0; i < b; i++) c[cpos+i] = x[i]; + } + return 0; +} + +function crypto_stream(c,cpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20(c,cpos,d,sn,s); +} + +function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { + var s = new Uint8Array(32); + crypto_core_hsalsa20(s,n,k,sigma); + var sn = new Uint8Array(8); + for (var i = 0; i < 8; i++) sn[i] = n[i+16]; + return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +} + +/* +* Port of Andrew Moon's Poly1305-donna-16. Public domain. +* https://github.com/floodyberry/poly1305-donna +*/ + +var poly1305 = function(key) { + this.buffer = new Uint8Array(16); + this.r = new Uint16Array(10); + this.h = new Uint16Array(10); + this.pad = new Uint16Array(8); + this.leftover = 0; + this.fin = 0; + + var t0, t1, t2, t3, t4, t5, t6, t7; + + t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; + t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; + t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; + this.r[5] = ((t4 >>> 1)) & 0x1ffe; + t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; + t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + this.r[9] = ((t7 >>> 5)) & 0x007f; + + this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; + this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; + this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; + this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; + this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; + this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; + this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; + this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; +}; + +poly1305.prototype.blocks = function(m, mpos, bytes) { + var hibit = this.fin ? 0 : (1 << 11); + var t0, t1, t2, t3, t4, t5, t6, t7, c; + var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; + + var h0 = this.h[0], + h1 = this.h[1], + h2 = this.h[2], + h3 = this.h[3], + h4 = this.h[4], + h5 = this.h[5], + h6 = this.h[6], + h7 = this.h[7], + h8 = this.h[8], + h9 = this.h[9]; + + var r0 = this.r[0], + r1 = this.r[1], + r2 = this.r[2], + r3 = this.r[3], + r4 = this.r[4], + r5 = this.r[5], + r6 = this.r[6], + r7 = this.r[7], + r8 = this.r[8], + r9 = this.r[9]; + + while (bytes >= 16) { + t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; + t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; + t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; + t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; + t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; + h5 += ((t4 >>> 1)) & 0x1fff; + t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; + t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; + t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; + h9 += ((t7 >>> 5)) | hibit; + + c = 0; + + d0 = c; + d0 += h0 * r0; + d0 += h1 * (5 * r9); + d0 += h2 * (5 * r8); + d0 += h3 * (5 * r7); + d0 += h4 * (5 * r6); + c = (d0 >>> 13); d0 &= 0x1fff; + d0 += h5 * (5 * r5); + d0 += h6 * (5 * r4); + d0 += h7 * (5 * r3); + d0 += h8 * (5 * r2); + d0 += h9 * (5 * r1); + c += (d0 >>> 13); d0 &= 0x1fff; + + d1 = c; + d1 += h0 * r1; + d1 += h1 * r0; + d1 += h2 * (5 * r9); + d1 += h3 * (5 * r8); + d1 += h4 * (5 * r7); + c = (d1 >>> 13); d1 &= 0x1fff; + d1 += h5 * (5 * r6); + d1 += h6 * (5 * r5); + d1 += h7 * (5 * r4); + d1 += h8 * (5 * r3); + d1 += h9 * (5 * r2); + c += (d1 >>> 13); d1 &= 0x1fff; + + d2 = c; + d2 += h0 * r2; + d2 += h1 * r1; + d2 += h2 * r0; + d2 += h3 * (5 * r9); + d2 += h4 * (5 * r8); + c = (d2 >>> 13); d2 &= 0x1fff; + d2 += h5 * (5 * r7); + d2 += h6 * (5 * r6); + d2 += h7 * (5 * r5); + d2 += h8 * (5 * r4); + d2 += h9 * (5 * r3); + c += (d2 >>> 13); d2 &= 0x1fff; + + d3 = c; + d3 += h0 * r3; + d3 += h1 * r2; + d3 += h2 * r1; + d3 += h3 * r0; + d3 += h4 * (5 * r9); + c = (d3 >>> 13); d3 &= 0x1fff; + d3 += h5 * (5 * r8); + d3 += h6 * (5 * r7); + d3 += h7 * (5 * r6); + d3 += h8 * (5 * r5); + d3 += h9 * (5 * r4); + c += (d3 >>> 13); d3 &= 0x1fff; + + d4 = c; + d4 += h0 * r4; + d4 += h1 * r3; + d4 += h2 * r2; + d4 += h3 * r1; + d4 += h4 * r0; + c = (d4 >>> 13); d4 &= 0x1fff; + d4 += h5 * (5 * r9); + d4 += h6 * (5 * r8); + d4 += h7 * (5 * r7); + d4 += h8 * (5 * r6); + d4 += h9 * (5 * r5); + c += (d4 >>> 13); d4 &= 0x1fff; + + d5 = c; + d5 += h0 * r5; + d5 += h1 * r4; + d5 += h2 * r3; + d5 += h3 * r2; + d5 += h4 * r1; + c = (d5 >>> 13); d5 &= 0x1fff; + d5 += h5 * r0; + d5 += h6 * (5 * r9); + d5 += h7 * (5 * r8); + d5 += h8 * (5 * r7); + d5 += h9 * (5 * r6); + c += (d5 >>> 13); d5 &= 0x1fff; + + d6 = c; + d6 += h0 * r6; + d6 += h1 * r5; + d6 += h2 * r4; + d6 += h3 * r3; + d6 += h4 * r2; + c = (d6 >>> 13); d6 &= 0x1fff; + d6 += h5 * r1; + d6 += h6 * r0; + d6 += h7 * (5 * r9); + d6 += h8 * (5 * r8); + d6 += h9 * (5 * r7); + c += (d6 >>> 13); d6 &= 0x1fff; + + d7 = c; + d7 += h0 * r7; + d7 += h1 * r6; + d7 += h2 * r5; + d7 += h3 * r4; + d7 += h4 * r3; + c = (d7 >>> 13); d7 &= 0x1fff; + d7 += h5 * r2; + d7 += h6 * r1; + d7 += h7 * r0; + d7 += h8 * (5 * r9); + d7 += h9 * (5 * r8); + c += (d7 >>> 13); d7 &= 0x1fff; + + d8 = c; + d8 += h0 * r8; + d8 += h1 * r7; + d8 += h2 * r6; + d8 += h3 * r5; + d8 += h4 * r4; + c = (d8 >>> 13); d8 &= 0x1fff; + d8 += h5 * r3; + d8 += h6 * r2; + d8 += h7 * r1; + d8 += h8 * r0; + d8 += h9 * (5 * r9); + c += (d8 >>> 13); d8 &= 0x1fff; + + d9 = c; + d9 += h0 * r9; + d9 += h1 * r8; + d9 += h2 * r7; + d9 += h3 * r6; + d9 += h4 * r5; + c = (d9 >>> 13); d9 &= 0x1fff; + d9 += h5 * r4; + d9 += h6 * r3; + d9 += h7 * r2; + d9 += h8 * r1; + d9 += h9 * r0; + c += (d9 >>> 13); d9 &= 0x1fff; + + c = (((c << 2) + c)) | 0; + c = (c + d0) | 0; + d0 = c & 0x1fff; + c = (c >>> 13); + d1 += c; + + h0 = d0; + h1 = d1; + h2 = d2; + h3 = d3; + h4 = d4; + h5 = d5; + h6 = d6; + h7 = d7; + h8 = d8; + h9 = d9; + + mpos += 16; + bytes -= 16; + } + this.h[0] = h0; + this.h[1] = h1; + this.h[2] = h2; + this.h[3] = h3; + this.h[4] = h4; + this.h[5] = h5; + this.h[6] = h6; + this.h[7] = h7; + this.h[8] = h8; + this.h[9] = h9; +}; + +poly1305.prototype.finish = function(mac, macpos) { + var g = new Uint16Array(10); + var c, mask, f, i; + + if (this.leftover) { + i = this.leftover; + this.buffer[i++] = 1; + for (; i < 16; i++) this.buffer[i] = 0; + this.fin = 1; + this.blocks(this.buffer, 0, 16); + } + + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + for (i = 2; i < 10; i++) { + this.h[i] += c; + c = this.h[i] >>> 13; + this.h[i] &= 0x1fff; + } + this.h[0] += (c * 5); + c = this.h[0] >>> 13; + this.h[0] &= 0x1fff; + this.h[1] += c; + c = this.h[1] >>> 13; + this.h[1] &= 0x1fff; + this.h[2] += c; + + g[0] = this.h[0] + 5; + c = g[0] >>> 13; + g[0] &= 0x1fff; + for (i = 1; i < 10; i++) { + g[i] = this.h[i] + c; + c = g[i] >>> 13; + g[i] &= 0x1fff; + } + g[9] -= (1 << 13); + + mask = (c ^ 1) - 1; + for (i = 0; i < 10; i++) g[i] &= mask; + mask = ~mask; + for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; + + this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; + this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; + this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; + this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; + this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; + this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; + this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; + this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; + + f = this.h[0] + this.pad[0]; + this.h[0] = f & 0xffff; + for (i = 1; i < 8; i++) { + f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; + this.h[i] = f & 0xffff; + } + + mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; + mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; + mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; + mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; + mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; + mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; + mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; + mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; + mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; + mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; + mac[macpos+10] = (this.h[5] >>> 0) & 0xff; + mac[macpos+11] = (this.h[5] >>> 8) & 0xff; + mac[macpos+12] = (this.h[6] >>> 0) & 0xff; + mac[macpos+13] = (this.h[6] >>> 8) & 0xff; + mac[macpos+14] = (this.h[7] >>> 0) & 0xff; + mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +}; + +poly1305.prototype.update = function(m, mpos, bytes) { + var i, want; + + if (this.leftover) { + want = (16 - this.leftover); + if (want > bytes) + want = bytes; + for (i = 0; i < want; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + bytes -= want; + mpos += want; + this.leftover += want; + if (this.leftover < 16) + return; + this.blocks(this.buffer, 0, 16); + this.leftover = 0; + } + + if (bytes >= 16) { + want = bytes - (bytes % 16); + this.blocks(m, mpos, want); + mpos += want; + bytes -= want; + } + + if (bytes) { + for (i = 0; i < bytes; i++) + this.buffer[this.leftover + i] = m[mpos+i]; + this.leftover += bytes; + } +}; + +function crypto_onetimeauth(out, outpos, m, mpos, n, k) { + var s = new poly1305(k); + s.update(m, mpos, n); + s.finish(out, outpos); + return 0; +} + +function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { + var x = new Uint8Array(16); + crypto_onetimeauth(x,0,m,mpos,n,k); + return crypto_verify_16(h,hpos,x,0); +} + +function crypto_secretbox(c,m,d,n,k) { + var i; + if (d < 32) return -1; + crypto_stream_xor(c,0,m,0,d,n,k); + crypto_onetimeauth(c, 16, c, 32, d - 32, c); + for (i = 0; i < 16; i++) c[i] = 0; + return 0; +} + +function crypto_secretbox_open(m,c,d,n,k) { + var i; + var x = new Uint8Array(32); + if (d < 32) return -1; + crypto_stream(x,0,32,n,k); + if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; + crypto_stream_xor(m,0,c,0,d,n,k); + for (i = 0; i < 32; i++) m[i] = 0; + return 0; +} + +function set25519(r, a) { + var i; + for (i = 0; i < 16; i++) r[i] = a[i]|0; +} + +function car25519(o) { + var i, v, c = 1; + for (i = 0; i < 16; i++) { + v = o[i] + c + 65535; + c = Math.floor(v / 65536); + o[i] = v - c * 65536; + } + o[0] += c-1 + 37 * (c-1); +} + +function sel25519(p, q, b) { + var t, c = ~(b-1); + for (var i = 0; i < 16; i++) { + t = c & (p[i] ^ q[i]); + p[i] ^= t; + q[i] ^= t; + } +} + +function pack25519(o, n) { + var i, j, b; + var m = gf(), t = gf(); + for (i = 0; i < 16; i++) t[i] = n[i]; + car25519(t); + car25519(t); + car25519(t); + for (j = 0; j < 2; j++) { + m[0] = t[0] - 0xffed; + for (i = 1; i < 15; i++) { + m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); + m[i-1] &= 0xffff; + } + m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); + b = (m[15]>>16) & 1; + m[14] &= 0xffff; + sel25519(t, m, 1-b); + } + for (i = 0; i < 16; i++) { + o[2*i] = t[i] & 0xff; + o[2*i+1] = t[i]>>8; + } +} + +function neq25519(a, b) { + var c = new Uint8Array(32), d = new Uint8Array(32); + pack25519(c, a); + pack25519(d, b); + return crypto_verify_32(c, 0, d, 0); +} + +function par25519(a) { + var d = new Uint8Array(32); + pack25519(d, a); + return d[0] & 1; +} + +function unpack25519(o, n) { + var i; + for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); + o[15] &= 0x7fff; +} + +function A(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; +} + +function Z(o, a, b) { + for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; +} + +function M(o, a, b) { + var v, c, + t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, + t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, + t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, + t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, + b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3], + b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7], + b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11], + b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; + + v = a[0]; + t0 += v * b0; + t1 += v * b1; + t2 += v * b2; + t3 += v * b3; + t4 += v * b4; + t5 += v * b5; + t6 += v * b6; + t7 += v * b7; + t8 += v * b8; + t9 += v * b9; + t10 += v * b10; + t11 += v * b11; + t12 += v * b12; + t13 += v * b13; + t14 += v * b14; + t15 += v * b15; + v = a[1]; + t1 += v * b0; + t2 += v * b1; + t3 += v * b2; + t4 += v * b3; + t5 += v * b4; + t6 += v * b5; + t7 += v * b6; + t8 += v * b7; + t9 += v * b8; + t10 += v * b9; + t11 += v * b10; + t12 += v * b11; + t13 += v * b12; + t14 += v * b13; + t15 += v * b14; + t16 += v * b15; + v = a[2]; + t2 += v * b0; + t3 += v * b1; + t4 += v * b2; + t5 += v * b3; + t6 += v * b4; + t7 += v * b5; + t8 += v * b6; + t9 += v * b7; + t10 += v * b8; + t11 += v * b9; + t12 += v * b10; + t13 += v * b11; + t14 += v * b12; + t15 += v * b13; + t16 += v * b14; + t17 += v * b15; + v = a[3]; + t3 += v * b0; + t4 += v * b1; + t5 += v * b2; + t6 += v * b3; + t7 += v * b4; + t8 += v * b5; + t9 += v * b6; + t10 += v * b7; + t11 += v * b8; + t12 += v * b9; + t13 += v * b10; + t14 += v * b11; + t15 += v * b12; + t16 += v * b13; + t17 += v * b14; + t18 += v * b15; + v = a[4]; + t4 += v * b0; + t5 += v * b1; + t6 += v * b2; + t7 += v * b3; + t8 += v * b4; + t9 += v * b5; + t10 += v * b6; + t11 += v * b7; + t12 += v * b8; + t13 += v * b9; + t14 += v * b10; + t15 += v * b11; + t16 += v * b12; + t17 += v * b13; + t18 += v * b14; + t19 += v * b15; + v = a[5]; + t5 += v * b0; + t6 += v * b1; + t7 += v * b2; + t8 += v * b3; + t9 += v * b4; + t10 += v * b5; + t11 += v * b6; + t12 += v * b7; + t13 += v * b8; + t14 += v * b9; + t15 += v * b10; + t16 += v * b11; + t17 += v * b12; + t18 += v * b13; + t19 += v * b14; + t20 += v * b15; + v = a[6]; + t6 += v * b0; + t7 += v * b1; + t8 += v * b2; + t9 += v * b3; + t10 += v * b4; + t11 += v * b5; + t12 += v * b6; + t13 += v * b7; + t14 += v * b8; + t15 += v * b9; + t16 += v * b10; + t17 += v * b11; + t18 += v * b12; + t19 += v * b13; + t20 += v * b14; + t21 += v * b15; + v = a[7]; + t7 += v * b0; + t8 += v * b1; + t9 += v * b2; + t10 += v * b3; + t11 += v * b4; + t12 += v * b5; + t13 += v * b6; + t14 += v * b7; + t15 += v * b8; + t16 += v * b9; + t17 += v * b10; + t18 += v * b11; + t19 += v * b12; + t20 += v * b13; + t21 += v * b14; + t22 += v * b15; + v = a[8]; + t8 += v * b0; + t9 += v * b1; + t10 += v * b2; + t11 += v * b3; + t12 += v * b4; + t13 += v * b5; + t14 += v * b6; + t15 += v * b7; + t16 += v * b8; + t17 += v * b9; + t18 += v * b10; + t19 += v * b11; + t20 += v * b12; + t21 += v * b13; + t22 += v * b14; + t23 += v * b15; + v = a[9]; + t9 += v * b0; + t10 += v * b1; + t11 += v * b2; + t12 += v * b3; + t13 += v * b4; + t14 += v * b5; + t15 += v * b6; + t16 += v * b7; + t17 += v * b8; + t18 += v * b9; + t19 += v * b10; + t20 += v * b11; + t21 += v * b12; + t22 += v * b13; + t23 += v * b14; + t24 += v * b15; + v = a[10]; + t10 += v * b0; + t11 += v * b1; + t12 += v * b2; + t13 += v * b3; + t14 += v * b4; + t15 += v * b5; + t16 += v * b6; + t17 += v * b7; + t18 += v * b8; + t19 += v * b9; + t20 += v * b10; + t21 += v * b11; + t22 += v * b12; + t23 += v * b13; + t24 += v * b14; + t25 += v * b15; + v = a[11]; + t11 += v * b0; + t12 += v * b1; + t13 += v * b2; + t14 += v * b3; + t15 += v * b4; + t16 += v * b5; + t17 += v * b6; + t18 += v * b7; + t19 += v * b8; + t20 += v * b9; + t21 += v * b10; + t22 += v * b11; + t23 += v * b12; + t24 += v * b13; + t25 += v * b14; + t26 += v * b15; + v = a[12]; + t12 += v * b0; + t13 += v * b1; + t14 += v * b2; + t15 += v * b3; + t16 += v * b4; + t17 += v * b5; + t18 += v * b6; + t19 += v * b7; + t20 += v * b8; + t21 += v * b9; + t22 += v * b10; + t23 += v * b11; + t24 += v * b12; + t25 += v * b13; + t26 += v * b14; + t27 += v * b15; + v = a[13]; + t13 += v * b0; + t14 += v * b1; + t15 += v * b2; + t16 += v * b3; + t17 += v * b4; + t18 += v * b5; + t19 += v * b6; + t20 += v * b7; + t21 += v * b8; + t22 += v * b9; + t23 += v * b10; + t24 += v * b11; + t25 += v * b12; + t26 += v * b13; + t27 += v * b14; + t28 += v * b15; + v = a[14]; + t14 += v * b0; + t15 += v * b1; + t16 += v * b2; + t17 += v * b3; + t18 += v * b4; + t19 += v * b5; + t20 += v * b6; + t21 += v * b7; + t22 += v * b8; + t23 += v * b9; + t24 += v * b10; + t25 += v * b11; + t26 += v * b12; + t27 += v * b13; + t28 += v * b14; + t29 += v * b15; + v = a[15]; + t15 += v * b0; + t16 += v * b1; + t17 += v * b2; + t18 += v * b3; + t19 += v * b4; + t20 += v * b5; + t21 += v * b6; + t22 += v * b7; + t23 += v * b8; + t24 += v * b9; + t25 += v * b10; + t26 += v * b11; + t27 += v * b12; + t28 += v * b13; + t29 += v * b14; + t30 += v * b15; + + t0 += 38 * t16; + t1 += 38 * t17; + t2 += 38 * t18; + t3 += 38 * t19; + t4 += 38 * t20; + t5 += 38 * t21; + t6 += 38 * t22; + t7 += 38 * t23; + t8 += 38 * t24; + t9 += 38 * t25; + t10 += 38 * t26; + t11 += 38 * t27; + t12 += 38 * t28; + t13 += 38 * t29; + t14 += 38 * t30; + // t15 left as is + + // first car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + // second car + c = 1; + v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; + v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; + v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; + v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; + v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; + v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; + v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; + v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; + v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; + v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; + v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; + v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; + v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; + v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; + v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; + v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; + t0 += c-1 + 37 * (c-1); + + o[ 0] = t0; + o[ 1] = t1; + o[ 2] = t2; + o[ 3] = t3; + o[ 4] = t4; + o[ 5] = t5; + o[ 6] = t6; + o[ 7] = t7; + o[ 8] = t8; + o[ 9] = t9; + o[10] = t10; + o[11] = t11; + o[12] = t12; + o[13] = t13; + o[14] = t14; + o[15] = t15; +} + +function S(o, a) { + M(o, a, a); +} + +function inv25519(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 253; a >= 0; a--) { + S(c, c); + if(a !== 2 && a !== 4) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function pow2523(o, i) { + var c = gf(); + var a; + for (a = 0; a < 16; a++) c[a] = i[a]; + for (a = 250; a >= 0; a--) { + S(c, c); + if(a !== 1) M(c, c, i); + } + for (a = 0; a < 16; a++) o[a] = c[a]; +} + +function crypto_scalarmult(q, n, p) { + var z = new Uint8Array(32); + var x = new Float64Array(80), r, i; + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(); + for (i = 0; i < 31; i++) z[i] = n[i]; + z[31]=(n[31]&127)|64; + z[0]&=248; + unpack25519(x,p); + for (i = 0; i < 16; i++) { + b[i]=x[i]; + d[i]=a[i]=c[i]=0; + } + a[0]=d[0]=1; + for (i=254; i>=0; --i) { + r=(z[i>>>3]>>>(i&7))&1; + sel25519(a,b,r); + sel25519(c,d,r); + A(e,a,c); + Z(a,a,c); + A(c,b,d); + Z(b,b,d); + S(d,e); + S(f,a); + M(a,c,a); + M(c,b,e); + A(e,a,c); + Z(a,a,c); + S(b,a); + Z(c,d,f); + M(a,c,_121665); + A(a,a,d); + M(c,c,a); + M(a,d,f); + M(d,b,x); + S(b,e); + sel25519(a,b,r); + sel25519(c,d,r); + } + for (i = 0; i < 16; i++) { + x[i+16]=a[i]; + x[i+32]=c[i]; + x[i+48]=b[i]; + x[i+64]=d[i]; + } + var x32 = x.subarray(32); + var x16 = x.subarray(16); + inv25519(x32,x32); + M(x16,x16,x32); + pack25519(q,x16); + return 0; +} + +function crypto_scalarmult_base(q, n) { + return crypto_scalarmult(q, n, _9); +} + +function crypto_box_keypair(y, x) { + randombytes(x, 32); + return crypto_scalarmult_base(y, x); +} + +function crypto_box_beforenm(k, y, x) { + var s = new Uint8Array(32); + crypto_scalarmult(s, x, y); + return crypto_core_hsalsa20(k, _0, s, sigma); +} + +var crypto_box_afternm = crypto_secretbox; +var crypto_box_open_afternm = crypto_secretbox_open; + +function crypto_box(c, m, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_afternm(c, m, d, n, k); +} + +function crypto_box_open(m, c, d, n, y, x) { + var k = new Uint8Array(32); + crypto_box_beforenm(k, y, x); + return crypto_box_open_afternm(m, c, d, n, k); +} + +var K = [ + 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, + 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, + 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, + 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, + 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, + 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, + 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, + 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, + 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, + 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, + 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, + 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, + 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, + 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, + 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, + 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, + 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, + 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, + 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, + 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, + 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, + 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, + 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, + 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, + 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, + 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, + 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, + 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, + 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, + 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, + 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, + 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, + 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, + 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, + 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, + 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, + 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, + 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, + 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, + 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 +]; + +function crypto_hashblocks_hl(hh, hl, m, n) { + var wh = new Int32Array(16), wl = new Int32Array(16), + bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, + bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, + th, tl, i, j, h, l, a, b, c, d; + + var ah0 = hh[0], + ah1 = hh[1], + ah2 = hh[2], + ah3 = hh[3], + ah4 = hh[4], + ah5 = hh[5], + ah6 = hh[6], + ah7 = hh[7], + + al0 = hl[0], + al1 = hl[1], + al2 = hl[2], + al3 = hl[3], + al4 = hl[4], + al5 = hl[5], + al6 = hl[6], + al7 = hl[7]; + + var pos = 0; + while (n >= 128) { + for (i = 0; i < 16; i++) { + j = 8 * i + pos; + wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; + wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; + } + for (i = 0; i < 80; i++) { + bh0 = ah0; + bh1 = ah1; + bh2 = ah2; + bh3 = ah3; + bh4 = ah4; + bh5 = ah5; + bh6 = ah6; + bh7 = ah7; + + bl0 = al0; + bl1 = al1; + bl2 = al2; + bl3 = al3; + bl4 = al4; + bl5 = al5; + bl6 = al6; + bl7 = al7; + + // add + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma1 + h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); + l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Ch + h = (ah4 & ah5) ^ (~ah4 & ah6); + l = (al4 & al5) ^ (~al4 & al6); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // K + h = K[i*2]; + l = K[i*2+1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // w + h = wh[i%16]; + l = wl[i%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + th = c & 0xffff | d << 16; + tl = a & 0xffff | b << 16; + + // add + h = th; + l = tl; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + // Sigma0 + h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); + l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // Maj + h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); + l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh7 = (c & 0xffff) | (d << 16); + bl7 = (a & 0xffff) | (b << 16); + + // add + h = bh3; + l = bl3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = th; + l = tl; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + bh3 = (c & 0xffff) | (d << 16); + bl3 = (a & 0xffff) | (b << 16); + + ah1 = bh0; + ah2 = bh1; + ah3 = bh2; + ah4 = bh3; + ah5 = bh4; + ah6 = bh5; + ah7 = bh6; + ah0 = bh7; + + al1 = bl0; + al2 = bl1; + al3 = bl2; + al4 = bl3; + al5 = bl4; + al6 = bl5; + al7 = bl6; + al0 = bl7; + + if (i%16 === 15) { + for (j = 0; j < 16; j++) { + // add + h = wh[j]; + l = wl[j]; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = wh[(j+9)%16]; + l = wl[(j+9)%16]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma0 + th = wh[(j+1)%16]; + tl = wl[(j+1)%16]; + h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); + l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + // sigma1 + th = wh[(j+14)%16]; + tl = wl[(j+14)%16]; + h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); + l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + wh[j] = (c & 0xffff) | (d << 16); + wl[j] = (a & 0xffff) | (b << 16); + } + } + } + + // add + h = ah0; + l = al0; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[0]; + l = hl[0]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[0] = ah0 = (c & 0xffff) | (d << 16); + hl[0] = al0 = (a & 0xffff) | (b << 16); + + h = ah1; + l = al1; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[1]; + l = hl[1]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[1] = ah1 = (c & 0xffff) | (d << 16); + hl[1] = al1 = (a & 0xffff) | (b << 16); + + h = ah2; + l = al2; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[2]; + l = hl[2]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[2] = ah2 = (c & 0xffff) | (d << 16); + hl[2] = al2 = (a & 0xffff) | (b << 16); + + h = ah3; + l = al3; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[3]; + l = hl[3]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[3] = ah3 = (c & 0xffff) | (d << 16); + hl[3] = al3 = (a & 0xffff) | (b << 16); + + h = ah4; + l = al4; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[4]; + l = hl[4]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[4] = ah4 = (c & 0xffff) | (d << 16); + hl[4] = al4 = (a & 0xffff) | (b << 16); + + h = ah5; + l = al5; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[5]; + l = hl[5]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[5] = ah5 = (c & 0xffff) | (d << 16); + hl[5] = al5 = (a & 0xffff) | (b << 16); + + h = ah6; + l = al6; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[6]; + l = hl[6]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[6] = ah6 = (c & 0xffff) | (d << 16); + hl[6] = al6 = (a & 0xffff) | (b << 16); + + h = ah7; + l = al7; + + a = l & 0xffff; b = l >>> 16; + c = h & 0xffff; d = h >>> 16; + + h = hh[7]; + l = hl[7]; + + a += l & 0xffff; b += l >>> 16; + c += h & 0xffff; d += h >>> 16; + + b += a >>> 16; + c += b >>> 16; + d += c >>> 16; + + hh[7] = ah7 = (c & 0xffff) | (d << 16); + hl[7] = al7 = (a & 0xffff) | (b << 16); + + pos += 128; + n -= 128; + } + + return n; +} + +function crypto_hash(out, m, n) { + var hh = new Int32Array(8), + hl = new Int32Array(8), + x = new Uint8Array(256), + i, b = n; + + hh[0] = 0x6a09e667; + hh[1] = 0xbb67ae85; + hh[2] = 0x3c6ef372; + hh[3] = 0xa54ff53a; + hh[4] = 0x510e527f; + hh[5] = 0x9b05688c; + hh[6] = 0x1f83d9ab; + hh[7] = 0x5be0cd19; + + hl[0] = 0xf3bcc908; + hl[1] = 0x84caa73b; + hl[2] = 0xfe94f82b; + hl[3] = 0x5f1d36f1; + hl[4] = 0xade682d1; + hl[5] = 0x2b3e6c1f; + hl[6] = 0xfb41bd6b; + hl[7] = 0x137e2179; + + crypto_hashblocks_hl(hh, hl, m, n); + n %= 128; + + for (i = 0; i < n; i++) x[i] = m[b-n+i]; + x[n] = 128; + + n = 256-128*(n<112?1:0); + x[n-9] = 0; + ts64(x, n-8, (b / 0x20000000) | 0, b << 3); + crypto_hashblocks_hl(hh, hl, x, n); + + for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); + + return 0; +} + +function add(p, q) { + var a = gf(), b = gf(), c = gf(), + d = gf(), e = gf(), f = gf(), + g = gf(), h = gf(), t = gf(); + + Z(a, p[1], p[0]); + Z(t, q[1], q[0]); + M(a, a, t); + A(b, p[0], p[1]); + A(t, q[0], q[1]); + M(b, b, t); + M(c, p[3], q[3]); + M(c, c, D2); + M(d, p[2], q[2]); + A(d, d, d); + Z(e, b, a); + Z(f, d, c); + A(g, d, c); + A(h, b, a); + + M(p[0], e, f); + M(p[1], h, g); + M(p[2], g, f); + M(p[3], e, h); +} + +function cswap(p, q, b) { + var i; + for (i = 0; i < 4; i++) { + sel25519(p[i], q[i], b); + } +} + +function pack(r, p) { + var tx = gf(), ty = gf(), zi = gf(); + inv25519(zi, p[2]); + M(tx, p[0], zi); + M(ty, p[1], zi); + pack25519(r, ty); + r[31] ^= par25519(tx) << 7; +} + +function scalarmult(p, q, s) { + var b, i; + set25519(p[0], gf0); + set25519(p[1], gf1); + set25519(p[2], gf1); + set25519(p[3], gf0); + for (i = 255; i >= 0; --i) { + b = (s[(i/8)|0] >> (i&7)) & 1; + cswap(p, q, b); + add(q, p); + add(p, p); + cswap(p, q, b); + } +} + +function scalarbase(p, s) { + var q = [gf(), gf(), gf(), gf()]; + set25519(q[0], X); + set25519(q[1], Y); + set25519(q[2], gf1); + M(q[3], X, Y); + scalarmult(p, q, s); +} + +function crypto_sign_keypair(pk, sk, seeded) { + var d = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()]; + var i; + + if (!seeded) randombytes(sk, 32); + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + scalarbase(p, d); + pack(pk, p); + + for (i = 0; i < 32; i++) sk[i+32] = pk[i]; + return 0; +} + +var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); + +function modL(r, x) { + var carry, i, j, k; + for (i = 63; i >= 32; --i) { + carry = 0; + for (j = i - 32, k = i - 12; j < k; ++j) { + x[j] += carry - 16 * x[i] * L[j - (i - 32)]; + carry = Math.floor((x[j] + 128) / 256); + x[j] -= carry * 256; + } + x[j] += carry; + x[i] = 0; + } + carry = 0; + for (j = 0; j < 32; j++) { + x[j] += carry - (x[31] >> 4) * L[j]; + carry = x[j] >> 8; + x[j] &= 255; + } + for (j = 0; j < 32; j++) x[j] -= carry * L[j]; + for (i = 0; i < 32; i++) { + x[i+1] += x[i] >> 8; + r[i] = x[i] & 255; + } +} + +function reduce(r) { + var x = new Float64Array(64), i; + for (i = 0; i < 64; i++) x[i] = r[i]; + for (i = 0; i < 64; i++) r[i] = 0; + modL(r, x); +} + +// Note: difference from C - smlen returned, not passed as argument. +function crypto_sign(sm, m, n, sk) { + var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); + var i, j, x = new Float64Array(64); + var p = [gf(), gf(), gf(), gf()]; + + crypto_hash(d, sk, 32); + d[0] &= 248; + d[31] &= 127; + d[31] |= 64; + + var smlen = n + 64; + for (i = 0; i < n; i++) sm[64 + i] = m[i]; + for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; + + crypto_hash(r, sm.subarray(32), n+32); + reduce(r); + scalarbase(p, r); + pack(sm, p); + + for (i = 32; i < 64; i++) sm[i] = sk[i]; + crypto_hash(h, sm, n + 64); + reduce(h); + + for (i = 0; i < 64; i++) x[i] = 0; + for (i = 0; i < 32; i++) x[i] = r[i]; + for (i = 0; i < 32; i++) { + for (j = 0; j < 32; j++) { + x[i+j] += h[i] * d[j]; + } + } + + modL(sm.subarray(32), x); + return smlen; +} + +function unpackneg(r, p) { + var t = gf(), chk = gf(), num = gf(), + den = gf(), den2 = gf(), den4 = gf(), + den6 = gf(); + + set25519(r[2], gf1); + unpack25519(r[1], p); + S(num, r[1]); + M(den, num, D); + Z(num, num, r[2]); + A(den, r[2], den); + + S(den2, den); + S(den4, den2); + M(den6, den4, den2); + M(t, den6, num); + M(t, t, den); + + pow2523(t, t); + M(t, t, num); + M(t, t, den); + M(t, t, den); + M(r[0], t, den); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) M(r[0], r[0], I); + + S(chk, r[0]); + M(chk, chk, den); + if (neq25519(chk, num)) return -1; + + if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); + + M(r[3], r[0], r[1]); + return 0; +} + +function crypto_sign_open(m, sm, n, pk) { + var i; + var t = new Uint8Array(32), h = new Uint8Array(64); + var p = [gf(), gf(), gf(), gf()], + q = [gf(), gf(), gf(), gf()]; + + if (n < 64) return -1; + + if (unpackneg(q, pk)) return -1; + + for (i = 0; i < n; i++) m[i] = sm[i]; + for (i = 0; i < 32; i++) m[i+32] = pk[i]; + crypto_hash(h, m, n); + reduce(h); + scalarmult(p, q, h); + + scalarbase(q, sm.subarray(32)); + add(p, q); + pack(t, p); + + n -= 64; + if (crypto_verify_32(sm, 0, t, 0)) { + for (i = 0; i < n; i++) m[i] = 0; + return -1; + } + + for (i = 0; i < n; i++) m[i] = sm[i + 64]; + return n; +} + +var crypto_secretbox_KEYBYTES = 32, + crypto_secretbox_NONCEBYTES = 24, + crypto_secretbox_ZEROBYTES = 32, + crypto_secretbox_BOXZEROBYTES = 16, + crypto_scalarmult_BYTES = 32, + crypto_scalarmult_SCALARBYTES = 32, + crypto_box_PUBLICKEYBYTES = 32, + crypto_box_SECRETKEYBYTES = 32, + crypto_box_BEFORENMBYTES = 32, + crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, + crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, + crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, + crypto_sign_BYTES = 64, + crypto_sign_PUBLICKEYBYTES = 32, + crypto_sign_SECRETKEYBYTES = 64, + crypto_sign_SEEDBYTES = 32, + crypto_hash_BYTES = 64; + +nacl.lowlevel = { + crypto_core_hsalsa20: crypto_core_hsalsa20, + crypto_stream_xor: crypto_stream_xor, + crypto_stream: crypto_stream, + crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, + crypto_stream_salsa20: crypto_stream_salsa20, + crypto_onetimeauth: crypto_onetimeauth, + crypto_onetimeauth_verify: crypto_onetimeauth_verify, + crypto_verify_16: crypto_verify_16, + crypto_verify_32: crypto_verify_32, + crypto_secretbox: crypto_secretbox, + crypto_secretbox_open: crypto_secretbox_open, + crypto_scalarmult: crypto_scalarmult, + crypto_scalarmult_base: crypto_scalarmult_base, + crypto_box_beforenm: crypto_box_beforenm, + crypto_box_afternm: crypto_box_afternm, + crypto_box: crypto_box, + crypto_box_open: crypto_box_open, + crypto_box_keypair: crypto_box_keypair, + crypto_hash: crypto_hash, + crypto_sign: crypto_sign, + crypto_sign_keypair: crypto_sign_keypair, + crypto_sign_open: crypto_sign_open, + + crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, + crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, + crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, + crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, + crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, + crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, + crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, + crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, + crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, + crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, + crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, + crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, + crypto_sign_BYTES: crypto_sign_BYTES, + crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, + crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, + crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, + crypto_hash_BYTES: crypto_hash_BYTES, + + gf: gf, + D: D, + L: L, + pack25519: pack25519, + unpack25519: unpack25519, + M: M, + A: A, + S: S, + Z: Z, + pow2523: pow2523, + add: add, + set25519: set25519, + modL: modL, + scalarmult: scalarmult, + scalarbase: scalarbase, +}; + +/* High-level API */ + +function checkLengths(k, n) { + if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); + if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); +} + +function checkBoxLengths(pk, sk) { + if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); + if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); +} + +function checkArrayTypes() { + for (var i = 0; i < arguments.length; i++) { + if (!(arguments[i] instanceof Uint8Array)) + throw new TypeError('unexpected type, use Uint8Array'); + } +} + +function cleanup(arr) { + for (var i = 0; i < arr.length; i++) arr[i] = 0; +} + +nacl.randomBytes = function(n) { + var b = new Uint8Array(n); + randombytes(b, n); + return b; +}; + +nacl.secretbox = function(msg, nonce, key) { + checkArrayTypes(msg, nonce, key); + checkLengths(key, nonce); + var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); + var c = new Uint8Array(m.length); + for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; + crypto_secretbox(c, m, m.length, nonce, key); + return c.subarray(crypto_secretbox_BOXZEROBYTES); +}; + +nacl.secretbox.open = function(box, nonce, key) { + checkArrayTypes(box, nonce, key); + checkLengths(key, nonce); + var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); + var m = new Uint8Array(c.length); + for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; + if (c.length < 32) return null; + if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; + return m.subarray(crypto_secretbox_ZEROBYTES); +}; + +nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; +nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; +nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; + +nacl.scalarMult = function(n, p) { + checkArrayTypes(n, p); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult(q, n, p); + return q; +}; + +nacl.scalarMult.base = function(n) { + checkArrayTypes(n); + if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); + var q = new Uint8Array(crypto_scalarmult_BYTES); + crypto_scalarmult_base(q, n); + return q; +}; + +nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; +nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; + +nacl.box = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox(msg, nonce, k); +}; + +nacl.box.before = function(publicKey, secretKey) { + checkArrayTypes(publicKey, secretKey); + checkBoxLengths(publicKey, secretKey); + var k = new Uint8Array(crypto_box_BEFORENMBYTES); + crypto_box_beforenm(k, publicKey, secretKey); + return k; +}; + +nacl.box.after = nacl.secretbox; + +nacl.box.open = function(msg, nonce, publicKey, secretKey) { + var k = nacl.box.before(publicKey, secretKey); + return nacl.secretbox.open(msg, nonce, k); +}; + +nacl.box.open.after = nacl.secretbox.open; + +nacl.box.keyPair = function() { + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); + crypto_box_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.box.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_box_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); + crypto_scalarmult_base(pk, secretKey); + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; +nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; +nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; +nacl.box.nonceLength = crypto_box_NONCEBYTES; +nacl.box.overheadLength = nacl.secretbox.overheadLength; + +nacl.sign = function(msg, secretKey) { + checkArrayTypes(msg, secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); + crypto_sign(signedMsg, msg, msg.length, secretKey); + return signedMsg; +}; + +nacl.sign.open = function(signedMsg, publicKey) { + checkArrayTypes(signedMsg, publicKey); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var tmp = new Uint8Array(signedMsg.length); + var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); + if (mlen < 0) return null; + var m = new Uint8Array(mlen); + for (var i = 0; i < m.length; i++) m[i] = tmp[i]; + return m; +}; + +nacl.sign.detached = function(msg, secretKey) { + var signedMsg = nacl.sign(msg, secretKey); + var sig = new Uint8Array(crypto_sign_BYTES); + for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; + return sig; +}; + +nacl.sign.detached.verify = function(msg, sig, publicKey) { + checkArrayTypes(msg, sig, publicKey); + if (sig.length !== crypto_sign_BYTES) + throw new Error('bad signature size'); + if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) + throw new Error('bad public key size'); + var sm = new Uint8Array(crypto_sign_BYTES + msg.length); + var m = new Uint8Array(crypto_sign_BYTES + msg.length); + var i; + for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; + for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; + return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); +}; + +nacl.sign.keyPair = function() { + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + crypto_sign_keypair(pk, sk); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.sign.keyPair.fromSecretKey = function(secretKey) { + checkArrayTypes(secretKey); + if (secretKey.length !== crypto_sign_SECRETKEYBYTES) + throw new Error('bad secret key size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; + return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; +}; + +nacl.sign.keyPair.fromSeed = function(seed) { + checkArrayTypes(seed); + if (seed.length !== crypto_sign_SEEDBYTES) + throw new Error('bad seed size'); + var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); + var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); + for (var i = 0; i < 32; i++) sk[i] = seed[i]; + crypto_sign_keypair(pk, sk, true); + return {publicKey: pk, secretKey: sk}; +}; + +nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; +nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; +nacl.sign.seedLength = crypto_sign_SEEDBYTES; +nacl.sign.signatureLength = crypto_sign_BYTES; + +nacl.hash = function(msg) { + checkArrayTypes(msg); + var h = new Uint8Array(crypto_hash_BYTES); + crypto_hash(h, msg, msg.length); + return h; +}; + +nacl.hash.hashLength = crypto_hash_BYTES; + +nacl.verify = function(x, y) { + checkArrayTypes(x, y); + // Zero length arguments are considered not equal. + if (x.length === 0 || y.length === 0) return false; + if (x.length !== y.length) return false; + return (vn(x, 0, y, 0, x.length) === 0) ? true : false; +}; + +nacl.setPRNG = function(fn) { + randombytes = fn; +}; + +(function() { + // Initialize PRNG if environment provides CSPRNG. + // If not, methods calling randombytes will throw. + var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; + if (crypto && crypto.getRandomValues) { + // Browsers. + var QUOTA = 65536; + nacl.setPRNG(function(x, n) { + var i, v = new Uint8Array(n); + for (i = 0; i < n; i += QUOTA) { + crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); + } + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } else if (true) { + // Node.js. + crypto = __webpack_require__(4); + if (crypto && crypto.randomBytes) { + nacl.setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } + } +})(); + +})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); + + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__(5).default; + + +/***/ }), +/* 4 */ +/***/ (function(module, exports) { + +/* (ignored) */ + +/***/ }), +/* 5 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); + +// CONCATENATED MODULE: ./src/core/base64.ts +function encode(s) { + return btoa(utob(s)); +} +var fromCharCode = String.fromCharCode; +var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; +var b64tab = {}; +for (var base64_i = 0, l = b64chars.length; base64_i < l; base64_i++) { + b64tab[b64chars.charAt(base64_i)] = base64_i; +} +var cb_utob = function (c) { + var cc = c.charCodeAt(0); + return cc < 0x80 + ? c + : cc < 0x800 + ? fromCharCode(0xc0 | (cc >>> 6)) + fromCharCode(0x80 | (cc & 0x3f)) + : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) + + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) + + fromCharCode(0x80 | (cc & 0x3f)); +}; +var utob = function (u) { + return u.replace(/[^\x00-\x7F]/g, cb_utob); +}; +var cb_encode = function (ccc) { + var padlen = [0, 2, 1][ccc.length % 3]; + var ord = (ccc.charCodeAt(0) << 16) | + ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) | + (ccc.length > 2 ? ccc.charCodeAt(2) : 0); + var chars = [ + b64chars.charAt(ord >>> 18), + b64chars.charAt((ord >>> 12) & 63), + padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), + padlen >= 1 ? '=' : b64chars.charAt(ord & 63) + ]; + return chars.join(''); +}; +var btoa = self.btoa || + function (b) { + return b.replace(/[\s\S]{1,3}/g, cb_encode); + }; + +// CONCATENATED MODULE: ./src/core/utils/timers/abstract_timer.ts +var Timer = (function () { + function Timer(set, clear, delay, callback) { + var _this = this; + this.clear = clear; + this.timer = set(function () { + if (_this.timer) { + _this.timer = callback(_this.timer); + } + }, delay); + } + Timer.prototype.isRunning = function () { + return this.timer !== null; + }; + Timer.prototype.ensureAborted = function () { + if (this.timer) { + this.clear(this.timer); + this.timer = null; + } + }; + return Timer; +}()); +/* harmony default export */ var abstract_timer = (Timer); + +// CONCATENATED MODULE: ./src/core/utils/timers/index.ts +var __extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + +function timers_clearTimeout(timer) { + self.clearTimeout(timer); +} +function timers_clearInterval(timer) { + self.clearInterval(timer); +} +var OneOffTimer = (function (_super) { + __extends(OneOffTimer, _super); + function OneOffTimer(delay, callback) { + return _super.call(this, setTimeout, timers_clearTimeout, delay, function (timer) { + callback(); + return null; + }) || this; + } + return OneOffTimer; +}(abstract_timer)); + +var PeriodicTimer = (function (_super) { + __extends(PeriodicTimer, _super); + function PeriodicTimer(delay, callback) { + return _super.call(this, setInterval, timers_clearInterval, delay, function (timer) { + callback(); + return timer; + }) || this; + } + return PeriodicTimer; +}(abstract_timer)); + + +// CONCATENATED MODULE: ./src/core/util.ts + +var Util = { + now: function () { + if (Date.now) { + return Date.now(); + } + else { + return new Date().valueOf(); + } + }, + defer: function (callback) { + return new OneOffTimer(0, callback); + }, + method: function (name) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var boundArguments = Array.prototype.slice.call(arguments, 1); + return function (object) { + return object[name].apply(object, boundArguments.concat(arguments)); + }; + } +}; +/* harmony default export */ var util = (Util); + +// CONCATENATED MODULE: ./src/core/utils/collections.ts + + +function extend(target) { + var sources = []; + for (var _i = 1; _i < arguments.length; _i++) { + sources[_i - 1] = arguments[_i]; + } + for (var i = 0; i < sources.length; i++) { + var extensions = sources[i]; + for (var property in extensions) { + if (extensions[property] && + extensions[property].constructor && + extensions[property].constructor === Object) { + target[property] = extend(target[property] || {}, extensions[property]); + } + else { + target[property] = extensions[property]; + } + } + } + return target; +} +function stringify() { + var m = ['Pusher']; + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] === 'string') { + m.push(arguments[i]); + } + else { + m.push(safeJSONStringify(arguments[i])); + } + } + return m.join(' : '); +} +function arrayIndexOf(array, item) { + var nativeIndexOf = Array.prototype.indexOf; + if (array === null) { + return -1; + } + if (nativeIndexOf && array.indexOf === nativeIndexOf) { + return array.indexOf(item); + } + for (var i = 0, l = array.length; i < l; i++) { + if (array[i] === item) { + return i; + } + } + return -1; +} +function objectApply(object, f) { + for (var key in object) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + f(object[key], key, object); + } + } +} +function keys(object) { + var keys = []; + objectApply(object, function (_, key) { + keys.push(key); + }); + return keys; +} +function values(object) { + var values = []; + objectApply(object, function (value) { + values.push(value); + }); + return values; +} +function apply(array, f, context) { + for (var i = 0; i < array.length; i++) { + f.call(context || self, array[i], i, array); + } +} +function map(array, f) { + var result = []; + for (var i = 0; i < array.length; i++) { + result.push(f(array[i], i, array, result)); + } + return result; +} +function mapObject(object, f) { + var result = {}; + objectApply(object, function (value, key) { + result[key] = f(value); + }); + return result; +} +function filter(array, test) { + test = + test || + function (value) { + return !!value; + }; + var result = []; + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array, result)) { + result.push(array[i]); + } + } + return result; +} +function filterObject(object, test) { + var result = {}; + objectApply(object, function (value, key) { + if ((test && test(value, key, object, result)) || Boolean(value)) { + result[key] = value; + } + }); + return result; +} +function flatten(object) { + var result = []; + objectApply(object, function (value, key) { + result.push([key, value]); + }); + return result; +} +function any(array, test) { + for (var i = 0; i < array.length; i++) { + if (test(array[i], i, array)) { + return true; + } + } + return false; +} +function collections_all(array, test) { + for (var i = 0; i < array.length; i++) { + if (!test(array[i], i, array)) { + return false; + } + } + return true; +} +function encodeParamsObject(data) { + return mapObject(data, function (value) { + if (typeof value === 'object') { + value = safeJSONStringify(value); + } + return encodeURIComponent(encode(value.toString())); + }); +} +function buildQueryString(data) { + var params = filterObject(data, function (value) { + return value !== undefined; + }); + var query = map(flatten(encodeParamsObject(params)), util.method('join', '=')).join('&'); + return query; +} +function decycleObject(object) { + var objects = [], paths = []; + return (function derez(value, path) { + var i, name, nu; + switch (typeof value) { + case 'object': + if (!value) { + return null; + } + for (i = 0; i < objects.length; i += 1) { + if (objects[i] === value) { + return { $ref: paths[i] }; + } + } + objects.push(value); + paths.push(path); + if (Object.prototype.toString.apply(value) === '[object Array]') { + nu = []; + for (i = 0; i < value.length; i += 1) { + nu[i] = derez(value[i], path + '[' + i + ']'); + } + } + else { + nu = {}; + for (name in value) { + if (Object.prototype.hasOwnProperty.call(value, name)) { + nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']'); + } + } + } + return nu; + case 'number': + case 'string': + case 'boolean': + return value; + } + })(object, '$'); +} +function safeJSONStringify(source) { + try { + return JSON.stringify(source); + } + catch (e) { + return JSON.stringify(decycleObject(source)); + } +} + +// CONCATENATED MODULE: ./src/core/defaults.ts +var Defaults = { + VERSION: "6.0.0", + PROTOCOL: 7, + wsPort: 80, + wssPort: 443, + wsPath: '', + httpHost: 'sockjs.pusher.com', + httpPort: 80, + httpsPort: 443, + httpPath: '/pusher', + stats_host: 'stats.pusher.com', + authEndpoint: '/pusher/auth', + authTransport: 'ajax', + activityTimeout: 120000, + pongTimeout: 30000, + unavailableTimeout: 10000, + cluster: 'mt1', + cdn_http: "http://js.pusher.com", + cdn_https: "https://js.pusher.com", + dependency_suffix: "" +}; +/* harmony default export */ var defaults = (Defaults); + +// CONCATENATED MODULE: ./src/core/transports/url_schemes.ts + +function getGenericURL(baseScheme, params, path) { + var scheme = baseScheme + (params.useTLS ? 's' : ''); + var host = params.useTLS ? params.hostTLS : params.hostNonTLS; + return scheme + '://' + host + path; +} +function getGenericPath(key, queryString) { + var path = '/app/' + key; + var query = '?protocol=' + + defaults.PROTOCOL + + '&client=js' + + '&version=' + + defaults.VERSION + + (queryString ? '&' + queryString : ''); + return path + query; +} +var ws = { + getInitial: function (key, params) { + var path = (params.httpPath || '') + getGenericPath(key, 'flash=false'); + return getGenericURL('ws', params, path); + } +}; +var http = { + getInitial: function (key, params) { + var path = (params.httpPath || '/pusher') + getGenericPath(key); + return getGenericURL('http', params, path); + } +}; +var sockjs = { + getInitial: function (key, params) { + return getGenericURL('http', params, params.httpPath || '/pusher'); + }, + getPath: function (key, params) { + return getGenericPath(key); + } +}; + +// CONCATENATED MODULE: ./src/core/events/callback_registry.ts + +var callback_registry_CallbackRegistry = (function () { + function CallbackRegistry() { + this._callbacks = {}; + } + CallbackRegistry.prototype.get = function (name) { + return this._callbacks[prefix(name)]; + }; + CallbackRegistry.prototype.add = function (name, callback, context) { + var prefixedEventName = prefix(name); + this._callbacks[prefixedEventName] = + this._callbacks[prefixedEventName] || []; + this._callbacks[prefixedEventName].push({ + fn: callback, + context: context + }); + }; + CallbackRegistry.prototype.remove = function (name, callback, context) { + if (!name && !callback && !context) { + this._callbacks = {}; + return; + } + var names = name ? [prefix(name)] : keys(this._callbacks); + if (callback || context) { + this.removeCallback(names, callback, context); + } + else { + this.removeAllCallbacks(names); + } + }; + CallbackRegistry.prototype.removeCallback = function (names, callback, context) { + apply(names, function (name) { + this._callbacks[name] = filter(this._callbacks[name] || [], function (binding) { + return ((callback && callback !== binding.fn) || + (context && context !== binding.context)); + }); + if (this._callbacks[name].length === 0) { + delete this._callbacks[name]; + } + }, this); + }; + CallbackRegistry.prototype.removeAllCallbacks = function (names) { + apply(names, function (name) { + delete this._callbacks[name]; + }, this); + }; + return CallbackRegistry; +}()); +/* harmony default export */ var callback_registry = (callback_registry_CallbackRegistry); +function prefix(name) { + return '_' + name; +} + +// CONCATENATED MODULE: ./src/core/events/dispatcher.ts + + +var dispatcher_Dispatcher = (function () { + function Dispatcher(failThrough) { + this.callbacks = new callback_registry(); + this.global_callbacks = []; + this.failThrough = failThrough; + } + Dispatcher.prototype.bind = function (eventName, callback, context) { + this.callbacks.add(eventName, callback, context); + return this; + }; + Dispatcher.prototype.bind_global = function (callback) { + this.global_callbacks.push(callback); + return this; + }; + Dispatcher.prototype.unbind = function (eventName, callback, context) { + this.callbacks.remove(eventName, callback, context); + return this; + }; + Dispatcher.prototype.unbind_global = function (callback) { + if (!callback) { + this.global_callbacks = []; + return this; + } + this.global_callbacks = filter(this.global_callbacks || [], function (c) { return c !== callback; }); + return this; + }; + Dispatcher.prototype.unbind_all = function () { + this.unbind(); + this.unbind_global(); + return this; + }; + Dispatcher.prototype.emit = function (eventName, data, metadata) { + for (var i = 0; i < this.global_callbacks.length; i++) { + this.global_callbacks[i](eventName, data); + } + var callbacks = this.callbacks.get(eventName); + var args = []; + if (metadata) { + args.push(data, metadata); + } + else if (data) { + args.push(data); + } + if (callbacks && callbacks.length > 0) { + for (var i = 0; i < callbacks.length; i++) { + callbacks[i].fn.apply(callbacks[i].context || self, args); + } + } + else if (this.failThrough) { + this.failThrough(eventName, data); + } + return this; + }; + return Dispatcher; +}()); +/* harmony default export */ var dispatcher = (dispatcher_Dispatcher); + +// CONCATENATED MODULE: ./src/core/logger.ts + + +var logger_Logger = (function () { + function Logger() { + this.globalLog = function (message) { + if (self.console && self.console.log) { + self.console.log(message); + } + }; + } + Logger.prototype.debug = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.log(this.globalLog, args); + }; + Logger.prototype.warn = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.log(this.globalLogWarn, args); + }; + Logger.prototype.error = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + this.log(this.globalLogError, args); + }; + Logger.prototype.globalLogWarn = function (message) { + if (self.console && self.console.warn) { + self.console.warn(message); + } + else { + this.globalLog(message); + } + }; + Logger.prototype.globalLogError = function (message) { + if (self.console && self.console.error) { + self.console.error(message); + } + else { + this.globalLogWarn(message); + } + }; + Logger.prototype.log = function (defaultLoggingFunction) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var message = stringify.apply(this, arguments); + if (core_pusher.log) { + core_pusher.log(message); + } + else if (core_pusher.logToConsole) { + var log = defaultLoggingFunction.bind(this); + log(message); + } + }; + return Logger; +}()); +/* harmony default export */ var logger = (new logger_Logger()); + +// CONCATENATED MODULE: ./src/core/transports/transport_connection.ts +var transport_connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + + +var transport_connection_TransportConnection = (function (_super) { + transport_connection_extends(TransportConnection, _super); + function TransportConnection(hooks, name, priority, key, options) { + var _this = _super.call(this) || this; + _this.initialize = worker_runtime.transportConnectionInitializer; + _this.hooks = hooks; + _this.name = name; + _this.priority = priority; + _this.key = key; + _this.options = options; + _this.state = 'new'; + _this.timeline = options.timeline; + _this.activityTimeout = options.activityTimeout; + _this.id = _this.timeline.generateUniqueID(); + return _this; + } + TransportConnection.prototype.handlesActivityChecks = function () { + return Boolean(this.hooks.handlesActivityChecks); + }; + TransportConnection.prototype.supportsPing = function () { + return Boolean(this.hooks.supportsPing); + }; + TransportConnection.prototype.connect = function () { + var _this = this; + if (this.socket || this.state !== 'initialized') { + return false; + } + var url = this.hooks.urls.getInitial(this.key, this.options); + try { + this.socket = this.hooks.getSocket(url, this.options); + } + catch (e) { + util.defer(function () { + _this.onError(e); + _this.changeState('closed'); + }); + return false; + } + this.bindListeners(); + logger.debug('Connecting', { transport: this.name, url: url }); + this.changeState('connecting'); + return true; + }; + TransportConnection.prototype.close = function () { + if (this.socket) { + this.socket.close(); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.send = function (data) { + var _this = this; + if (this.state === 'open') { + util.defer(function () { + if (_this.socket) { + _this.socket.send(data); + } + }); + return true; + } + else { + return false; + } + }; + TransportConnection.prototype.ping = function () { + if (this.state === 'open' && this.supportsPing()) { + this.socket.ping(); + } + }; + TransportConnection.prototype.onOpen = function () { + if (this.hooks.beforeOpen) { + this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)); + } + this.changeState('open'); + this.socket.onopen = undefined; + }; + TransportConnection.prototype.onError = function (error) { + this.emit('error', { type: 'WebSocketError', error: error }); + this.timeline.error(this.buildTimelineMessage({ error: error.toString() })); + }; + TransportConnection.prototype.onClose = function (closeEvent) { + if (closeEvent) { + this.changeState('closed', { + code: closeEvent.code, + reason: closeEvent.reason, + wasClean: closeEvent.wasClean + }); + } + else { + this.changeState('closed'); + } + this.unbindListeners(); + this.socket = undefined; + }; + TransportConnection.prototype.onMessage = function (message) { + this.emit('message', message); + }; + TransportConnection.prototype.onActivity = function () { + this.emit('activity'); + }; + TransportConnection.prototype.bindListeners = function () { + var _this = this; + this.socket.onopen = function () { + _this.onOpen(); + }; + this.socket.onerror = function (error) { + _this.onError(error); + }; + this.socket.onclose = function (closeEvent) { + _this.onClose(closeEvent); + }; + this.socket.onmessage = function (message) { + _this.onMessage(message); + }; + if (this.supportsPing()) { + this.socket.onactivity = function () { + _this.onActivity(); + }; + } + }; + TransportConnection.prototype.unbindListeners = function () { + if (this.socket) { + this.socket.onopen = undefined; + this.socket.onerror = undefined; + this.socket.onclose = undefined; + this.socket.onmessage = undefined; + if (this.supportsPing()) { + this.socket.onactivity = undefined; + } + } + }; + TransportConnection.prototype.changeState = function (state, params) { + this.state = state; + this.timeline.info(this.buildTimelineMessage({ + state: state, + params: params + })); + this.emit(state, params); + }; + TransportConnection.prototype.buildTimelineMessage = function (message) { + return extend({ cid: this.id }, message); + }; + return TransportConnection; +}(dispatcher)); +/* harmony default export */ var transport_connection = (transport_connection_TransportConnection); + +// CONCATENATED MODULE: ./src/core/transports/transport.ts + +var transport_Transport = (function () { + function Transport(hooks) { + this.hooks = hooks; + } + Transport.prototype.isSupported = function (environment) { + return this.hooks.isSupported(environment); + }; + Transport.prototype.createConnection = function (name, priority, key, options) { + return new transport_connection(this.hooks, name, priority, key, options); + }; + return Transport; +}()); +/* harmony default export */ var transports_transport = (transport_Transport); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transports.ts + + + + +var WSTransport = new transports_transport({ + urls: ws, + handlesActivityChecks: false, + supportsPing: false, + isInitialized: function () { + return Boolean(worker_runtime.getWebSocketAPI()); + }, + isSupported: function () { + return Boolean(worker_runtime.getWebSocketAPI()); + }, + getSocket: function (url) { + return worker_runtime.createWebSocket(url); + } +}); +var httpConfiguration = { + urls: http, + handlesActivityChecks: false, + supportsPing: true, + isInitialized: function () { + return true; + } +}; +var streamingConfiguration = extend({ + getSocket: function (url) { + return worker_runtime.HTTPFactory.createStreamingSocket(url); + } +}, httpConfiguration); +var pollingConfiguration = extend({ + getSocket: function (url) { + return worker_runtime.HTTPFactory.createPollingSocket(url); + } +}, httpConfiguration); +var xhrConfiguration = { + isSupported: function () { + return worker_runtime.isXHRSupported(); + } +}; +var XHRStreamingTransport = new transports_transport((extend({}, streamingConfiguration, xhrConfiguration))); +var XHRPollingTransport = new transports_transport(extend({}, pollingConfiguration, xhrConfiguration)); +var Transports = { + ws: WSTransport, + xhr_streaming: XHRStreamingTransport, + xhr_polling: XHRPollingTransport +}; +/* harmony default export */ var transports = (Transports); + +// CONCATENATED MODULE: ./src/core/transports/assistant_to_the_transport_manager.ts + + +var assistant_to_the_transport_manager_AssistantToTheTransportManager = (function () { + function AssistantToTheTransportManager(manager, transport, options) { + this.manager = manager; + this.transport = transport; + this.minPingDelay = options.minPingDelay; + this.maxPingDelay = options.maxPingDelay; + this.pingDelay = undefined; + } + AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) { + var _this = this; + options = extend({}, options, { + activityTimeout: this.pingDelay + }); + var connection = this.transport.createConnection(name, priority, key, options); + var openTimestamp = null; + var onOpen = function () { + connection.unbind('open', onOpen); + connection.bind('closed', onClosed); + openTimestamp = util.now(); + }; + var onClosed = function (closeEvent) { + connection.unbind('closed', onClosed); + if (closeEvent.code === 1002 || closeEvent.code === 1003) { + _this.manager.reportDeath(); + } + else if (!closeEvent.wasClean && openTimestamp) { + var lifespan = util.now() - openTimestamp; + if (lifespan < 2 * _this.maxPingDelay) { + _this.manager.reportDeath(); + _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay); + } + } + }; + connection.bind('open', onOpen); + return connection; + }; + AssistantToTheTransportManager.prototype.isSupported = function (environment) { + return this.manager.isAlive() && this.transport.isSupported(environment); + }; + return AssistantToTheTransportManager; +}()); +/* harmony default export */ var assistant_to_the_transport_manager = (assistant_to_the_transport_manager_AssistantToTheTransportManager); + +// CONCATENATED MODULE: ./src/core/connection/protocol/protocol.ts +var Protocol = { + decodeMessage: function (messageEvent) { + try { + var messageData = JSON.parse(messageEvent.data); + var pusherEventData = messageData.data; + if (typeof pusherEventData === 'string') { + try { + pusherEventData = JSON.parse(messageData.data); + } + catch (e) { } + } + var pusherEvent = { + event: messageData.event, + channel: messageData.channel, + data: pusherEventData + }; + if (messageData.user_id) { + pusherEvent.user_id = messageData.user_id; + } + return pusherEvent; + } + catch (e) { + throw { type: 'MessageParseError', error: e, data: messageEvent.data }; + } + }, + encodeMessage: function (event) { + return JSON.stringify(event); + }, + processHandshake: function (messageEvent) { + var message = Protocol.decodeMessage(messageEvent); + if (message.event === 'pusher:connection_established') { + if (!message.data.activity_timeout) { + throw 'No activity timeout specified in handshake'; + } + return { + action: 'connected', + id: message.data.socket_id, + activityTimeout: message.data.activity_timeout * 1000 + }; + } + else if (message.event === 'pusher:error') { + return { + action: this.getCloseAction(message.data), + error: this.getCloseError(message.data) + }; + } + else { + throw 'Invalid handshake'; + } + }, + getCloseAction: function (closeEvent) { + if (closeEvent.code < 4000) { + if (closeEvent.code >= 1002 && closeEvent.code <= 1004) { + return 'backoff'; + } + else { + return null; + } + } + else if (closeEvent.code === 4000) { + return 'tls_only'; + } + else if (closeEvent.code < 4100) { + return 'refused'; + } + else if (closeEvent.code < 4200) { + return 'backoff'; + } + else if (closeEvent.code < 4300) { + return 'retry'; + } + else { + return 'refused'; + } + }, + getCloseError: function (closeEvent) { + if (closeEvent.code !== 1000 && closeEvent.code !== 1001) { + return { + type: 'PusherError', + data: { + code: closeEvent.code, + message: closeEvent.reason || closeEvent.message + } + }; + } + else { + return null; + } + } +}; +/* harmony default export */ var protocol = (Protocol); + +// CONCATENATED MODULE: ./src/core/connection/connection.ts +var connection_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + +var connection_Connection = (function (_super) { + connection_extends(Connection, _super); + function Connection(id, transport) { + var _this = _super.call(this) || this; + _this.id = id; + _this.transport = transport; + _this.activityTimeout = transport.activityTimeout; + _this.bindListeners(); + return _this; + } + Connection.prototype.handlesActivityChecks = function () { + return this.transport.handlesActivityChecks(); + }; + Connection.prototype.send = function (data) { + return this.transport.send(data); + }; + Connection.prototype.send_event = function (name, data, channel) { + var event = { event: name, data: data }; + if (channel) { + event.channel = channel; + } + logger.debug('Event sent', event); + return this.send(protocol.encodeMessage(event)); + }; + Connection.prototype.ping = function () { + if (this.transport.supportsPing()) { + this.transport.ping(); + } + else { + this.send_event('pusher:ping', {}); + } + }; + Connection.prototype.close = function () { + this.transport.close(); + }; + Connection.prototype.bindListeners = function () { + var _this = this; + var listeners = { + message: function (messageEvent) { + var pusherEvent; + try { + pusherEvent = protocol.decodeMessage(messageEvent); + } + catch (e) { + _this.emit('error', { + type: 'MessageParseError', + error: e, + data: messageEvent.data + }); + } + if (pusherEvent !== undefined) { + logger.debug('Event recd', pusherEvent); + switch (pusherEvent.event) { + case 'pusher:error': + _this.emit('error', { + type: 'PusherError', + data: pusherEvent.data + }); + break; + case 'pusher:ping': + _this.emit('ping'); + break; + case 'pusher:pong': + _this.emit('pong'); + break; + } + _this.emit('message', pusherEvent); + } + }, + activity: function () { + _this.emit('activity'); + }, + error: function (error) { + _this.emit('error', { type: 'WebSocketError', error: error }); + }, + closed: function (closeEvent) { + unbindListeners(); + if (closeEvent && closeEvent.code) { + _this.handleCloseEvent(closeEvent); + } + _this.transport = null; + _this.emit('closed'); + } + }; + var unbindListeners = function () { + objectApply(listeners, function (listener, event) { + _this.transport.unbind(event, listener); + }); + }; + objectApply(listeners, function (listener, event) { + _this.transport.bind(event, listener); + }); + }; + Connection.prototype.handleCloseEvent = function (closeEvent) { + var action = protocol.getCloseAction(closeEvent); + var error = protocol.getCloseError(closeEvent); + if (error) { + this.emit('error', error); + } + if (action) { + this.emit(action, { action: action, error: error }); + } + }; + return Connection; +}(dispatcher)); +/* harmony default export */ var connection_connection = (connection_Connection); + +// CONCATENATED MODULE: ./src/core/connection/handshake/index.ts + + + +var handshake_Handshake = (function () { + function Handshake(transport, callback) { + this.transport = transport; + this.callback = callback; + this.bindListeners(); + } + Handshake.prototype.close = function () { + this.unbindListeners(); + this.transport.close(); + }; + Handshake.prototype.bindListeners = function () { + var _this = this; + this.onMessage = function (m) { + _this.unbindListeners(); + var result; + try { + result = protocol.processHandshake(m); + } + catch (e) { + _this.finish('error', { error: e }); + _this.transport.close(); + return; + } + if (result.action === 'connected') { + _this.finish('connected', { + connection: new connection_connection(result.id, _this.transport), + activityTimeout: result.activityTimeout + }); + } + else { + _this.finish(result.action, { error: result.error }); + _this.transport.close(); + } + }; + this.onClosed = function (closeEvent) { + _this.unbindListeners(); + var action = protocol.getCloseAction(closeEvent) || 'backoff'; + var error = protocol.getCloseError(closeEvent); + _this.finish(action, { error: error }); + }; + this.transport.bind('message', this.onMessage); + this.transport.bind('closed', this.onClosed); + }; + Handshake.prototype.unbindListeners = function () { + this.transport.unbind('message', this.onMessage); + this.transport.unbind('closed', this.onClosed); + }; + Handshake.prototype.finish = function (action, params) { + this.callback(extend({ transport: this.transport, action: action }, params)); + }; + return Handshake; +}()); +/* harmony default export */ var connection_handshake = (handshake_Handshake); + +// CONCATENATED MODULE: ./src/core/auth/pusher_authorizer.ts + +var pusher_authorizer_PusherAuthorizer = (function () { + function PusherAuthorizer(channel, options) { + this.channel = channel; + var authTransport = options.authTransport; + if (typeof worker_runtime.getAuthorizers()[authTransport] === 'undefined') { + throw "'" + authTransport + "' is not a recognized auth transport"; + } + this.type = authTransport; + this.options = options; + this.authOptions = options.auth || {}; + } + PusherAuthorizer.prototype.composeQuery = function (socketId) { + var query = 'socket_id=' + + encodeURIComponent(socketId) + + '&channel_name=' + + encodeURIComponent(this.channel.name); + for (var i in this.authOptions.params) { + query += + '&' + + encodeURIComponent(i) + + '=' + + encodeURIComponent(this.authOptions.params[i]); + } + return query; + }; + PusherAuthorizer.prototype.authorize = function (socketId, callback) { + PusherAuthorizer.authorizers = + PusherAuthorizer.authorizers || worker_runtime.getAuthorizers(); + PusherAuthorizer.authorizers[this.type].call(this, worker_runtime, socketId, callback); + }; + return PusherAuthorizer; +}()); +/* harmony default export */ var pusher_authorizer = (pusher_authorizer_PusherAuthorizer); + +// CONCATENATED MODULE: ./src/core/timeline/timeline_sender.ts + +var timeline_sender_TimelineSender = (function () { + function TimelineSender(timeline, options) { + this.timeline = timeline; + this.options = options || {}; + } + TimelineSender.prototype.send = function (useTLS, callback) { + if (this.timeline.isEmpty()) { + return; + } + this.timeline.send(worker_runtime.TimelineTransport.getAgent(this, useTLS), callback); + }; + return TimelineSender; +}()); +/* harmony default export */ var timeline_sender = (timeline_sender_TimelineSender); + +// CONCATENATED MODULE: ./src/core/errors.ts +var errors_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var BadEventName = (function (_super) { + errors_extends(BadEventName, _super); + function BadEventName(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return BadEventName; +}(Error)); + +var RequestTimedOut = (function (_super) { + errors_extends(RequestTimedOut, _super); + function RequestTimedOut(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return RequestTimedOut; +}(Error)); + +var TransportPriorityTooLow = (function (_super) { + errors_extends(TransportPriorityTooLow, _super); + function TransportPriorityTooLow(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportPriorityTooLow; +}(Error)); + +var TransportClosed = (function (_super) { + errors_extends(TransportClosed, _super); + function TransportClosed(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return TransportClosed; +}(Error)); + +var UnsupportedFeature = (function (_super) { + errors_extends(UnsupportedFeature, _super); + function UnsupportedFeature(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedFeature; +}(Error)); + +var UnsupportedTransport = (function (_super) { + errors_extends(UnsupportedTransport, _super); + function UnsupportedTransport(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedTransport; +}(Error)); + +var UnsupportedStrategy = (function (_super) { + errors_extends(UnsupportedStrategy, _super); + function UnsupportedStrategy(msg) { + var _newTarget = this.constructor; + var _this = _super.call(this, msg) || this; + Object.setPrototypeOf(_this, _newTarget.prototype); + return _this; + } + return UnsupportedStrategy; +}(Error)); + + +// CONCATENATED MODULE: ./src/core/utils/url_store.ts +var urlStore = { + baseUrl: 'https://pusher.com', + urls: { + authenticationEndpoint: { + path: '/docs/authenticating_users' + }, + javascriptQuickStart: { + path: '/docs/javascript_quick_start' + }, + triggeringClientEvents: { + path: '/docs/client_api_guide/client_events#trigger-events' + }, + encryptedChannelSupport: { + fullUrl: 'https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support' + } + } +}; +var buildLogSuffix = function (key) { + var urlPrefix = 'See:'; + var urlObj = urlStore.urls[key]; + if (!urlObj) + return ''; + var url; + if (urlObj.fullUrl) { + url = urlObj.fullUrl; + } + else if (urlObj.path) { + url = urlStore.baseUrl + urlObj.path; + } + if (!url) + return ''; + return urlPrefix + " " + url; +}; +/* harmony default export */ var url_store = ({ buildLogSuffix: buildLogSuffix }); + +// CONCATENATED MODULE: ./src/core/channels/channel.ts +var channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + +var channel_Channel = (function (_super) { + channel_extends(Channel, _super); + function Channel(name, pusher) { + var _this = _super.call(this, function (event, data) { + logger.debug('No callbacks on ' + name + ' for ' + event); + }) || this; + _this.name = name; + _this.pusher = pusher; + _this.subscribed = false; + _this.subscriptionPending = false; + _this.subscriptionCancelled = false; + return _this; + } + Channel.prototype.authorize = function (socketId, callback) { + return callback(false, { auth: '' }); + }; + Channel.prototype.trigger = function (event, data) { + if (event.indexOf('client-') !== 0) { + throw new BadEventName("Event '" + event + "' does not start with 'client-'"); + } + if (!this.subscribed) { + var suffix = url_store.buildLogSuffix('triggeringClientEvents'); + logger.warn("Client event triggered before channel 'subscription_succeeded' event . " + suffix); + } + return this.pusher.send_event(event, data, this.name); + }; + Channel.prototype.disconnect = function () { + this.subscribed = false; + this.subscriptionPending = false; + }; + Channel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName === 'pusher_internal:subscription_succeeded') { + this.handleSubscriptionSucceededEvent(event); + } + else if (eventName.indexOf('pusher_internal:') !== 0) { + var metadata = {}; + this.emit(eventName, data, metadata); + } + }; + Channel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.emit('pusher:subscription_succeeded', event.data); + } + }; + Channel.prototype.subscribe = function () { + var _this = this; + if (this.subscribed) { + return; + } + this.subscriptionPending = true; + this.subscriptionCancelled = false; + this.authorize(this.pusher.connection.socket_id, function (error, data) { + if (error) { + logger.error(data); + _this.emit('pusher:subscription_error', data); + } + else { + data = data; + _this.pusher.send_event('pusher:subscribe', { + auth: data.auth, + channel_data: data.channel_data, + channel: _this.name + }); + } + }); + }; + Channel.prototype.unsubscribe = function () { + this.subscribed = false; + this.pusher.send_event('pusher:unsubscribe', { + channel: this.name + }); + }; + Channel.prototype.cancelSubscription = function () { + this.subscriptionCancelled = true; + }; + Channel.prototype.reinstateSubscription = function () { + this.subscriptionCancelled = false; + }; + return Channel; +}(dispatcher)); +/* harmony default export */ var channels_channel = (channel_Channel); + +// CONCATENATED MODULE: ./src/core/channels/private_channel.ts +var private_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var private_channel_PrivateChannel = (function (_super) { + private_channel_extends(PrivateChannel, _super); + function PrivateChannel() { + return _super !== null && _super.apply(this, arguments) || this; + } + PrivateChannel.prototype.authorize = function (socketId, callback) { + var authorizer = factory.createAuthorizer(this, this.pusher.config); + return authorizer.authorize(socketId, callback); + }; + return PrivateChannel; +}(channels_channel)); +/* harmony default export */ var private_channel = (private_channel_PrivateChannel); + +// CONCATENATED MODULE: ./src/core/channels/members.ts + +var members_Members = (function () { + function Members() { + this.reset(); + } + Members.prototype.get = function (id) { + if (Object.prototype.hasOwnProperty.call(this.members, id)) { + return { + id: id, + info: this.members[id] + }; + } + else { + return null; + } + }; + Members.prototype.each = function (callback) { + var _this = this; + objectApply(this.members, function (member, id) { + callback(_this.get(id)); + }); + }; + Members.prototype.setMyID = function (id) { + this.myID = id; + }; + Members.prototype.onSubscription = function (subscriptionData) { + this.members = subscriptionData.presence.hash; + this.count = subscriptionData.presence.count; + this.me = this.get(this.myID); + }; + Members.prototype.addMember = function (memberData) { + if (this.get(memberData.user_id) === null) { + this.count++; + } + this.members[memberData.user_id] = memberData.user_info; + return this.get(memberData.user_id); + }; + Members.prototype.removeMember = function (memberData) { + var member = this.get(memberData.user_id); + if (member) { + delete this.members[memberData.user_id]; + this.count--; + } + return member; + }; + Members.prototype.reset = function () { + this.members = {}; + this.count = 0; + this.myID = null; + this.me = null; + }; + return Members; +}()); +/* harmony default export */ var members = (members_Members); + +// CONCATENATED MODULE: ./src/core/channels/presence_channel.ts +var presence_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + +var presence_channel_PresenceChannel = (function (_super) { + presence_channel_extends(PresenceChannel, _super); + function PresenceChannel(name, pusher) { + var _this = _super.call(this, name, pusher) || this; + _this.members = new members(); + return _this; + } + PresenceChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (!error) { + authData = authData; + if (authData.channel_data === undefined) { + var suffix = url_store.buildLogSuffix('authenticationEndpoint'); + logger.error("Invalid auth response for channel '" + _this.name + "'," + + ("expected 'channel_data' field. " + suffix)); + callback('Invalid auth response'); + return; + } + var channelData = JSON.parse(authData.channel_data); + _this.members.setMyID(channelData.user_id); + } + callback(error, authData); + }); + }; + PresenceChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + if (eventName.indexOf('pusher_internal:') === 0) { + this.handleInternalEvent(event); + } + else { + var data = event.data; + var metadata = {}; + if (event.user_id) { + metadata.user_id = event.user_id; + } + this.emit(eventName, data, metadata); + } + }; + PresenceChannel.prototype.handleInternalEvent = function (event) { + var eventName = event.event; + var data = event.data; + switch (eventName) { + case 'pusher_internal:subscription_succeeded': + this.handleSubscriptionSucceededEvent(event); + break; + case 'pusher_internal:member_added': + var addedMember = this.members.addMember(data); + this.emit('pusher:member_added', addedMember); + break; + case 'pusher_internal:member_removed': + var removedMember = this.members.removeMember(data); + if (removedMember) { + this.emit('pusher:member_removed', removedMember); + } + break; + } + }; + PresenceChannel.prototype.handleSubscriptionSucceededEvent = function (event) { + this.subscriptionPending = false; + this.subscribed = true; + if (this.subscriptionCancelled) { + this.pusher.unsubscribe(this.name); + } + else { + this.members.onSubscription(event.data); + this.emit('pusher:subscription_succeeded', this.members); + } + }; + PresenceChannel.prototype.disconnect = function () { + this.members.reset(); + _super.prototype.disconnect.call(this); + }; + return PresenceChannel; +}(private_channel)); +/* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); + +// EXTERNAL MODULE: ./node_modules/@stablelib/utf8/lib/utf8.js +var utf8 = __webpack_require__(1); + +// EXTERNAL MODULE: ./node_modules/@stablelib/base64/lib/base64.js +var base64 = __webpack_require__(0); + +// CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts +var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + + +var encrypted_channel_EncryptedChannel = (function (_super) { + encrypted_channel_extends(EncryptedChannel, _super); + function EncryptedChannel(name, pusher, nacl) { + var _this = _super.call(this, name, pusher) || this; + _this.key = null; + _this.nacl = nacl; + return _this; + } + EncryptedChannel.prototype.authorize = function (socketId, callback) { + var _this = this; + _super.prototype.authorize.call(this, socketId, function (error, authData) { + if (error) { + callback(true, authData); + return; + } + var sharedSecret = authData['shared_secret']; + if (!sharedSecret) { + var errorMsg = "No shared_secret key in auth payload for encrypted channel: " + _this.name; + callback(true, errorMsg); + return; + } + _this.key = Object(base64["decode"])(sharedSecret); + delete authData['shared_secret']; + callback(false, authData); + }); + }; + EncryptedChannel.prototype.trigger = function (event, data) { + throw new UnsupportedFeature('Client events are not currently supported for encrypted channels'); + }; + EncryptedChannel.prototype.handleEvent = function (event) { + var eventName = event.event; + var data = event.data; + if (eventName.indexOf('pusher_internal:') === 0 || + eventName.indexOf('pusher:') === 0) { + _super.prototype.handleEvent.call(this, event); + return; + } + this.handleEncryptedEvent(eventName, data); + }; + EncryptedChannel.prototype.handleEncryptedEvent = function (event, data) { + var _this = this; + if (!this.key) { + logger.debug('Received encrypted event before key has been retrieved from the authEndpoint'); + return; + } + if (!data.ciphertext || !data.nonce) { + logger.error('Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: ' + + data); + return; + } + var cipherText = Object(base64["decode"])(data.ciphertext); + if (cipherText.length < this.nacl.secretbox.overheadLength) { + logger.error("Expected encrypted event ciphertext length to be " + this.nacl.secretbox.overheadLength + ", got: " + cipherText.length); + return; + } + var nonce = Object(base64["decode"])(data.nonce); + if (nonce.length < this.nacl.secretbox.nonceLength) { + logger.error("Expected encrypted event nonce length to be " + this.nacl.secretbox.nonceLength + ", got: " + nonce.length); + return; + } + var bytes = this.nacl.secretbox.open(cipherText, nonce, this.key); + if (bytes === null) { + logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); + this.authorize(this.pusher.connection.socket_id, function (error, authData) { + if (error) { + logger.error("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); + return; + } + bytes = _this.nacl.secretbox.open(cipherText, nonce, _this.key); + if (bytes === null) { + logger.error("Failed to decrypt event with new key. Dropping encrypted event"); + return; + } + _this.emitJSON(event, Object(utf8["decode"])(bytes)); + return; + }); + return; + } + this.emitJSON(event, Object(utf8["decode"])(bytes)); + }; + EncryptedChannel.prototype.emitJSON = function (eventName, data) { + try { + this.emit(eventName, JSON.parse(data)); + } + catch (e) { + this.emit(eventName, data); + } + return this; + }; + return EncryptedChannel; +}(private_channel)); +/* harmony default export */ var encrypted_channel = (encrypted_channel_EncryptedChannel); + +// CONCATENATED MODULE: ./src/core/connection/connection_manager.ts +var connection_manager_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + + + + +var connection_manager_ConnectionManager = (function (_super) { + connection_manager_extends(ConnectionManager, _super); + function ConnectionManager(key, options) { + var _this = _super.call(this) || this; + _this.state = 'initialized'; + _this.connection = null; + _this.key = key; + _this.options = options; + _this.timeline = _this.options.timeline; + _this.usingTLS = _this.options.useTLS; + _this.errorCallbacks = _this.buildErrorCallbacks(); + _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); + _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); + var Network = worker_runtime.getNetwork(); + Network.bind('online', function () { + _this.timeline.info({ netinfo: 'online' }); + if (_this.state === 'connecting' || _this.state === 'unavailable') { + _this.retryIn(0); + } + }); + Network.bind('offline', function () { + _this.timeline.info({ netinfo: 'offline' }); + if (_this.connection) { + _this.sendActivityCheck(); + } + }); + _this.updateStrategy(); + return _this; + } + ConnectionManager.prototype.connect = function () { + if (this.connection || this.runner) { + return; + } + if (!this.strategy.isSupported()) { + this.updateState('failed'); + return; + } + this.updateState('connecting'); + this.startConnecting(); + this.setUnavailableTimer(); + }; + ConnectionManager.prototype.send = function (data) { + if (this.connection) { + return this.connection.send(data); + } + else { + return false; + } + }; + ConnectionManager.prototype.send_event = function (name, data, channel) { + if (this.connection) { + return this.connection.send_event(name, data, channel); + } + else { + return false; + } + }; + ConnectionManager.prototype.disconnect = function () { + this.disconnectInternally(); + this.updateState('disconnected'); + }; + ConnectionManager.prototype.isUsingTLS = function () { + return this.usingTLS; + }; + ConnectionManager.prototype.startConnecting = function () { + var _this = this; + var callback = function (error, handshake) { + if (error) { + _this.runner = _this.strategy.connect(0, callback); + } + else { + if (handshake.action === 'error') { + _this.emit('error', { + type: 'HandshakeError', + error: handshake.error + }); + _this.timeline.error({ handshakeError: handshake.error }); + } + else { + _this.abortConnecting(); + _this.handshakeCallbacks[handshake.action](handshake); + } + } + }; + this.runner = this.strategy.connect(0, callback); + }; + ConnectionManager.prototype.abortConnecting = function () { + if (this.runner) { + this.runner.abort(); + this.runner = null; + } + }; + ConnectionManager.prototype.disconnectInternally = function () { + this.abortConnecting(); + this.clearRetryTimer(); + this.clearUnavailableTimer(); + if (this.connection) { + var connection = this.abandonConnection(); + connection.close(); + } + }; + ConnectionManager.prototype.updateStrategy = function () { + this.strategy = this.options.getStrategy({ + key: this.key, + timeline: this.timeline, + useTLS: this.usingTLS + }); + }; + ConnectionManager.prototype.retryIn = function (delay) { + var _this = this; + this.timeline.info({ action: 'retry', delay: delay }); + if (delay > 0) { + this.emit('connecting_in', Math.round(delay / 1000)); + } + this.retryTimer = new OneOffTimer(delay || 0, function () { + _this.disconnectInternally(); + _this.connect(); + }); + }; + ConnectionManager.prototype.clearRetryTimer = function () { + if (this.retryTimer) { + this.retryTimer.ensureAborted(); + this.retryTimer = null; + } + }; + ConnectionManager.prototype.setUnavailableTimer = function () { + var _this = this; + this.unavailableTimer = new OneOffTimer(this.options.unavailableTimeout, function () { + _this.updateState('unavailable'); + }); + }; + ConnectionManager.prototype.clearUnavailableTimer = function () { + if (this.unavailableTimer) { + this.unavailableTimer.ensureAborted(); + } + }; + ConnectionManager.prototype.sendActivityCheck = function () { + var _this = this; + this.stopActivityCheck(); + this.connection.ping(); + this.activityTimer = new OneOffTimer(this.options.pongTimeout, function () { + _this.timeline.error({ pong_timed_out: _this.options.pongTimeout }); + _this.retryIn(0); + }); + }; + ConnectionManager.prototype.resetActivityCheck = function () { + var _this = this; + this.stopActivityCheck(); + if (this.connection && !this.connection.handlesActivityChecks()) { + this.activityTimer = new OneOffTimer(this.activityTimeout, function () { + _this.sendActivityCheck(); + }); + } + }; + ConnectionManager.prototype.stopActivityCheck = function () { + if (this.activityTimer) { + this.activityTimer.ensureAborted(); + } + }; + ConnectionManager.prototype.buildConnectionCallbacks = function (errorCallbacks) { + var _this = this; + return extend({}, errorCallbacks, { + message: function (message) { + _this.resetActivityCheck(); + _this.emit('message', message); + }, + ping: function () { + _this.send_event('pusher:pong', {}); + }, + activity: function () { + _this.resetActivityCheck(); + }, + error: function (error) { + _this.emit('error', { type: 'WebSocketError', error: error }); + }, + closed: function () { + _this.abandonConnection(); + if (_this.shouldRetry()) { + _this.retryIn(1000); + } + } + }); + }; + ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) { + var _this = this; + return extend({}, errorCallbacks, { + connected: function (handshake) { + _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity); + _this.clearUnavailableTimer(); + _this.setConnection(handshake.connection); + _this.socket_id = _this.connection.id; + _this.updateState('connected', { socket_id: _this.socket_id }); + } + }); + }; + ConnectionManager.prototype.buildErrorCallbacks = function () { + var _this = this; + var withErrorEmitted = function (callback) { + return function (result) { + if (result.error) { + _this.emit('error', { type: 'WebSocketError', error: result.error }); + } + callback(result); + }; + }; + return { + tls_only: withErrorEmitted(function () { + _this.usingTLS = true; + _this.updateStrategy(); + _this.retryIn(0); + }), + refused: withErrorEmitted(function () { + _this.disconnect(); + }), + backoff: withErrorEmitted(function () { + _this.retryIn(1000); + }), + retry: withErrorEmitted(function () { + _this.retryIn(0); + }) + }; + }; + ConnectionManager.prototype.setConnection = function (connection) { + this.connection = connection; + for (var event in this.connectionCallbacks) { + this.connection.bind(event, this.connectionCallbacks[event]); + } + this.resetActivityCheck(); + }; + ConnectionManager.prototype.abandonConnection = function () { + if (!this.connection) { + return; + } + this.stopActivityCheck(); + for (var event in this.connectionCallbacks) { + this.connection.unbind(event, this.connectionCallbacks[event]); + } + var connection = this.connection; + this.connection = null; + return connection; + }; + ConnectionManager.prototype.updateState = function (newState, data) { + var previousState = this.state; + this.state = newState; + if (previousState !== newState) { + var newStateDescription = newState; + if (newStateDescription === 'connected') { + newStateDescription += ' with new socket ID ' + data.socket_id; + } + logger.debug('State changed', previousState + ' -> ' + newStateDescription); + this.timeline.info({ state: newState, params: data }); + this.emit('state_change', { previous: previousState, current: newState }); + this.emit(newState, data); + } + }; + ConnectionManager.prototype.shouldRetry = function () { + return this.state === 'connecting' || this.state === 'connected'; + }; + return ConnectionManager; +}(dispatcher)); +/* harmony default export */ var connection_manager = (connection_manager_ConnectionManager); + +// CONCATENATED MODULE: ./src/core/channels/channels.ts + + + + +var channels_Channels = (function () { + function Channels() { + this.channels = {}; + } + Channels.prototype.add = function (name, pusher) { + if (!this.channels[name]) { + this.channels[name] = createChannel(name, pusher); + } + return this.channels[name]; + }; + Channels.prototype.all = function () { + return values(this.channels); + }; + Channels.prototype.find = function (name) { + return this.channels[name]; + }; + Channels.prototype.remove = function (name) { + var channel = this.channels[name]; + delete this.channels[name]; + return channel; + }; + Channels.prototype.disconnect = function () { + objectApply(this.channels, function (channel) { + channel.disconnect(); + }); + }; + return Channels; +}()); +/* harmony default export */ var channels = (channels_Channels); +function createChannel(name, pusher) { + if (name.indexOf('private-encrypted-') === 0) { + if (pusher.config.nacl) { + return factory.createEncryptedChannel(name, pusher, pusher.config.nacl); + } + var errMsg = 'Tried to subscribe to a private-encrypted- channel but no nacl implementation available'; + var suffix = url_store.buildLogSuffix('encryptedChannelSupport'); + throw new UnsupportedFeature(errMsg + ". " + suffix); + } + else if (name.indexOf('private-') === 0) { + return factory.createPrivateChannel(name, pusher); + } + else if (name.indexOf('presence-') === 0) { + return factory.createPresenceChannel(name, pusher); + } + else { + return factory.createChannel(name, pusher); + } +} + +// CONCATENATED MODULE: ./src/core/utils/factory.ts + + + + + + + + + + +var Factory = { + createChannels: function () { + return new channels(); + }, + createConnectionManager: function (key, options) { + return new connection_manager(key, options); + }, + createChannel: function (name, pusher) { + return new channels_channel(name, pusher); + }, + createPrivateChannel: function (name, pusher) { + return new private_channel(name, pusher); + }, + createPresenceChannel: function (name, pusher) { + return new presence_channel(name, pusher); + }, + createEncryptedChannel: function (name, pusher, nacl) { + return new encrypted_channel(name, pusher, nacl); + }, + createTimelineSender: function (timeline, options) { + return new timeline_sender(timeline, options); + }, + createAuthorizer: function (channel, options) { + if (options.authorizer) { + return options.authorizer(channel, options); + } + return new pusher_authorizer(channel, options); + }, + createHandshake: function (transport, callback) { + return new connection_handshake(transport, callback); + }, + createAssistantToTheTransportManager: function (manager, transport, options) { + return new assistant_to_the_transport_manager(manager, transport, options); + } +}; +/* harmony default export */ var factory = (Factory); + +// CONCATENATED MODULE: ./src/core/transports/transport_manager.ts + +var transport_manager_TransportManager = (function () { + function TransportManager(options) { + this.options = options || {}; + this.livesLeft = this.options.lives || Infinity; + } + TransportManager.prototype.getAssistant = function (transport) { + return factory.createAssistantToTheTransportManager(this, transport, { + minPingDelay: this.options.minPingDelay, + maxPingDelay: this.options.maxPingDelay + }); + }; + TransportManager.prototype.isAlive = function () { + return this.livesLeft > 0; + }; + TransportManager.prototype.reportDeath = function () { + this.livesLeft -= 1; + }; + return TransportManager; +}()); +/* harmony default export */ var transport_manager = (transport_manager_TransportManager); + +// CONCATENATED MODULE: ./src/core/strategies/sequential_strategy.ts + + + +var sequential_strategy_SequentialStrategy = (function () { + function SequentialStrategy(strategies, options) { + this.strategies = strategies; + this.loop = Boolean(options.loop); + this.failFast = Boolean(options.failFast); + this.timeout = options.timeout; + this.timeoutLimit = options.timeoutLimit; + } + SequentialStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method('isSupported')); + }; + SequentialStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + var strategies = this.strategies; + var current = 0; + var timeout = this.timeout; + var runner = null; + var tryNextStrategy = function (error, handshake) { + if (handshake) { + callback(null, handshake); + } + else { + current = current + 1; + if (_this.loop) { + current = current % strategies.length; + } + if (current < strategies.length) { + if (timeout) { + timeout = timeout * 2; + if (_this.timeoutLimit) { + timeout = Math.min(timeout, _this.timeoutLimit); + } + } + runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy); + } + else { + callback(true); + } + } + }; + runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) { + var timer = null; + var runner = null; + if (options.timeout > 0) { + timer = new OneOffTimer(options.timeout, function () { + runner.abort(); + callback(true); + }); + } + runner = strategy.connect(minPriority, function (error, handshake) { + if (error && timer && timer.isRunning() && !options.failFast) { + return; + } + if (timer) { + timer.ensureAborted(); + } + callback(error, handshake); + }); + return { + abort: function () { + if (timer) { + timer.ensureAborted(); + } + runner.abort(); + }, + forceMinPriority: function (p) { + runner.forceMinPriority(p); + } + }; + }; + return SequentialStrategy; +}()); +/* harmony default export */ var sequential_strategy = (sequential_strategy_SequentialStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/best_connected_ever_strategy.ts + + +var best_connected_ever_strategy_BestConnectedEverStrategy = (function () { + function BestConnectedEverStrategy(strategies) { + this.strategies = strategies; + } + BestConnectedEverStrategy.prototype.isSupported = function () { + return any(this.strategies, util.method('isSupported')); + }; + BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) { + return connect(this.strategies, minPriority, function (i, runners) { + return function (error, handshake) { + runners[i].error = error; + if (error) { + if (allRunnersFailed(runners)) { + callback(true); + } + return; + } + apply(runners, function (runner) { + runner.forceMinPriority(handshake.transport.priority); + }); + callback(null, handshake); + }; + }); + }; + return BestConnectedEverStrategy; +}()); +/* harmony default export */ var best_connected_ever_strategy = (best_connected_ever_strategy_BestConnectedEverStrategy); +function connect(strategies, minPriority, callbackBuilder) { + var runners = map(strategies, function (strategy, i, _, rs) { + return strategy.connect(minPriority, callbackBuilder(i, rs)); + }); + return { + abort: function () { + apply(runners, abortRunner); + }, + forceMinPriority: function (p) { + apply(runners, function (runner) { + runner.forceMinPriority(p); + }); + } + }; +} +function allRunnersFailed(runners) { + return collections_all(runners, function (runner) { + return Boolean(runner.error); + }); +} +function abortRunner(runner) { + if (!runner.error && !runner.aborted) { + runner.abort(); + runner.aborted = true; + } +} + +// CONCATENATED MODULE: ./src/core/strategies/cached_strategy.ts + + + + +var cached_strategy_CachedStrategy = (function () { + function CachedStrategy(strategy, transports, options) { + this.strategy = strategy; + this.transports = transports; + this.ttl = options.ttl || 1800 * 1000; + this.usingTLS = options.useTLS; + this.timeline = options.timeline; + } + CachedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + CachedStrategy.prototype.connect = function (minPriority, callback) { + var usingTLS = this.usingTLS; + var info = fetchTransportCache(usingTLS); + var strategies = [this.strategy]; + if (info && info.timestamp + this.ttl >= util.now()) { + var transport = this.transports[info.transport]; + if (transport) { + this.timeline.info({ + cached: true, + transport: info.transport, + latency: info.latency + }); + strategies.push(new sequential_strategy([transport], { + timeout: info.latency * 2 + 1000, + failFast: true + })); + } + } + var startTimestamp = util.now(); + var runner = strategies + .pop() + .connect(minPriority, function cb(error, handshake) { + if (error) { + flushTransportCache(usingTLS); + if (strategies.length > 0) { + startTimestamp = util.now(); + runner = strategies.pop().connect(minPriority, cb); + } + else { + callback(error); + } + } + else { + storeTransportCache(usingTLS, handshake.transport.name, util.now() - startTimestamp); + callback(null, handshake); + } + }); + return { + abort: function () { + runner.abort(); + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + return CachedStrategy; +}()); +/* harmony default export */ var cached_strategy = (cached_strategy_CachedStrategy); +function getTransportCacheKey(usingTLS) { + return 'pusherTransport' + (usingTLS ? 'TLS' : 'NonTLS'); +} +function fetchTransportCache(usingTLS) { + var storage = worker_runtime.getLocalStorage(); + if (storage) { + try { + var serializedCache = storage[getTransportCacheKey(usingTLS)]; + if (serializedCache) { + return JSON.parse(serializedCache); + } + } + catch (e) { + flushTransportCache(usingTLS); + } + } + return null; +} +function storeTransportCache(usingTLS, transport, latency) { + var storage = worker_runtime.getLocalStorage(); + if (storage) { + try { + storage[getTransportCacheKey(usingTLS)] = safeJSONStringify({ + timestamp: util.now(), + transport: transport, + latency: latency + }); + } + catch (e) { + } + } +} +function flushTransportCache(usingTLS) { + var storage = worker_runtime.getLocalStorage(); + if (storage) { + try { + delete storage[getTransportCacheKey(usingTLS)]; + } + catch (e) { + } + } +} + +// CONCATENATED MODULE: ./src/core/strategies/delayed_strategy.ts + +var delayed_strategy_DelayedStrategy = (function () { + function DelayedStrategy(strategy, _a) { + var number = _a.delay; + this.strategy = strategy; + this.options = { delay: number }; + } + DelayedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + DelayedStrategy.prototype.connect = function (minPriority, callback) { + var strategy = this.strategy; + var runner; + var timer = new OneOffTimer(this.options.delay, function () { + runner = strategy.connect(minPriority, callback); + }); + return { + abort: function () { + timer.ensureAborted(); + if (runner) { + runner.abort(); + } + }, + forceMinPriority: function (p) { + minPriority = p; + if (runner) { + runner.forceMinPriority(p); + } + } + }; + }; + return DelayedStrategy; +}()); +/* harmony default export */ var delayed_strategy = (delayed_strategy_DelayedStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/if_strategy.ts +var IfStrategy = (function () { + function IfStrategy(test, trueBranch, falseBranch) { + this.test = test; + this.trueBranch = trueBranch; + this.falseBranch = falseBranch; + } + IfStrategy.prototype.isSupported = function () { + var branch = this.test() ? this.trueBranch : this.falseBranch; + return branch.isSupported(); + }; + IfStrategy.prototype.connect = function (minPriority, callback) { + var branch = this.test() ? this.trueBranch : this.falseBranch; + return branch.connect(minPriority, callback); + }; + return IfStrategy; +}()); +/* harmony default export */ var if_strategy = (IfStrategy); + +// CONCATENATED MODULE: ./src/core/strategies/first_connected_strategy.ts +var FirstConnectedStrategy = (function () { + function FirstConnectedStrategy(strategy) { + this.strategy = strategy; + } + FirstConnectedStrategy.prototype.isSupported = function () { + return this.strategy.isSupported(); + }; + FirstConnectedStrategy.prototype.connect = function (minPriority, callback) { + var runner = this.strategy.connect(minPriority, function (error, handshake) { + if (handshake) { + runner.abort(); + } + callback(error, handshake); + }); + return runner; + }; + return FirstConnectedStrategy; +}()); +/* harmony default export */ var first_connected_strategy = (FirstConnectedStrategy); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/default_strategy.ts + + + + + + + + +function testSupportsStrategy(strategy) { + return function () { + return strategy.isSupported(); + }; +} +var getDefaultStrategy = function (config, baseOptions, defineTransport) { + var definedTransports = {}; + function defineTransportStrategy(name, type, priority, options, manager) { + var transport = defineTransport(config, name, type, priority, options, manager); + definedTransports[name] = transport; + return transport; + } + var ws_options = Object.assign({}, baseOptions, { + hostNonTLS: config.wsHost + ':' + config.wsPort, + hostTLS: config.wsHost + ':' + config.wssPort, + httpPath: config.wsPath + }); + var wss_options = extend({}, ws_options, { + useTLS: true + }); + var http_options = Object.assign({}, baseOptions, { + hostNonTLS: config.httpHost + ':' + config.httpPort, + hostTLS: config.httpHost + ':' + config.httpsPort, + httpPath: config.httpPath + }); + var timeouts = { + loop: true, + timeout: 15000, + timeoutLimit: 60000 + }; + var ws_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activityTimeout + }); + var streaming_manager = new transport_manager({ + lives: 2, + minPingDelay: 10000, + maxPingDelay: config.activityTimeout + }); + var ws_transport = defineTransportStrategy('ws', 'ws', 3, ws_options, ws_manager); + var wss_transport = defineTransportStrategy('wss', 'ws', 3, wss_options, ws_manager); + var xhr_streaming_transport = defineTransportStrategy('xhr_streaming', 'xhr_streaming', 1, http_options, streaming_manager); + var xhr_polling_transport = defineTransportStrategy('xhr_polling', 'xhr_polling', 1, http_options); + var ws_loop = new sequential_strategy([ws_transport], timeouts); + var wss_loop = new sequential_strategy([wss_transport], timeouts); + var streaming_loop = new sequential_strategy([xhr_streaming_transport], timeouts); + var polling_loop = new sequential_strategy([xhr_polling_transport], timeouts); + var http_loop = new sequential_strategy([ + new if_strategy(testSupportsStrategy(streaming_loop), new best_connected_ever_strategy([ + streaming_loop, + new delayed_strategy(polling_loop, { delay: 4000 }) + ]), polling_loop) + ], timeouts); + var wsStrategy; + if (baseOptions.useTLS) { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(http_loop, { delay: 2000 }) + ]); + } + else { + wsStrategy = new best_connected_ever_strategy([ + ws_loop, + new delayed_strategy(wss_loop, { delay: 2000 }), + new delayed_strategy(http_loop, { delay: 5000 }) + ]); + } + return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { + ttl: 1800000, + timeline: baseOptions.timeline, + useTLS: baseOptions.useTLS + }); +}; +/* harmony default export */ var default_strategy = (getDefaultStrategy); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/transports/transport_connection_initializer.ts +/* harmony default export */ var transport_connection_initializer = (function () { + var self = this; + self.timeline.info(self.buildTimelineMessage({ + transport: self.name + (self.options.useTLS ? 's' : '') + })); + if (self.hooks.isInitialized()) { + self.changeState('initialized'); + } + else { + self.onClose(); + } +}); + +// CONCATENATED MODULE: ./src/core/http/http_request.ts +var http_request_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var MAX_BUFFER_LENGTH = 256 * 1024; +var http_request_HTTPRequest = (function (_super) { + http_request_extends(HTTPRequest, _super); + function HTTPRequest(hooks, method, url) { + var _this = _super.call(this) || this; + _this.hooks = hooks; + _this.method = method; + _this.url = url; + return _this; + } + HTTPRequest.prototype.start = function (payload) { + var _this = this; + this.position = 0; + this.xhr = this.hooks.getRequest(this); + this.unloader = function () { + _this.close(); + }; + worker_runtime.addUnloadListener(this.unloader); + this.xhr.open(this.method, this.url, true); + if (this.xhr.setRequestHeader) { + this.xhr.setRequestHeader('Content-Type', 'application/json'); + } + this.xhr.send(payload); + }; + HTTPRequest.prototype.close = function () { + if (this.unloader) { + worker_runtime.removeUnloadListener(this.unloader); + this.unloader = null; + } + if (this.xhr) { + this.hooks.abortRequest(this.xhr); + this.xhr = null; + } + }; + HTTPRequest.prototype.onChunk = function (status, data) { + while (true) { + var chunk = this.advanceBuffer(data); + if (chunk) { + this.emit('chunk', { status: status, data: chunk }); + } + else { + break; + } + } + if (this.isBufferTooLong(data)) { + this.emit('buffer_too_long'); + } + }; + HTTPRequest.prototype.advanceBuffer = function (buffer) { + var unreadData = buffer.slice(this.position); + var endOfLinePosition = unreadData.indexOf('\n'); + if (endOfLinePosition !== -1) { + this.position += endOfLinePosition + 1; + return unreadData.slice(0, endOfLinePosition); + } + else { + return null; + } + }; + HTTPRequest.prototype.isBufferTooLong = function (buffer) { + return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH; + }; + return HTTPRequest; +}(dispatcher)); +/* harmony default export */ var http_request = (http_request_HTTPRequest); + +// CONCATENATED MODULE: ./src/core/http/state.ts +var State; +(function (State) { + State[State["CONNECTING"] = 0] = "CONNECTING"; + State[State["OPEN"] = 1] = "OPEN"; + State[State["CLOSED"] = 3] = "CLOSED"; +})(State || (State = {})); +/* harmony default export */ var state = (State); + +// CONCATENATED MODULE: ./src/core/http/http_socket.ts + + + +var autoIncrement = 1; +var http_socket_HTTPSocket = (function () { + function HTTPSocket(hooks, url) { + this.hooks = hooks; + this.session = randomNumber(1000) + '/' + randomString(8); + this.location = getLocation(url); + this.readyState = state.CONNECTING; + this.openStream(); + } + HTTPSocket.prototype.send = function (payload) { + return this.sendRaw(JSON.stringify([payload])); + }; + HTTPSocket.prototype.ping = function () { + this.hooks.sendHeartbeat(this); + }; + HTTPSocket.prototype.close = function (code, reason) { + this.onClose(code, reason, true); + }; + HTTPSocket.prototype.sendRaw = function (payload) { + if (this.readyState === state.OPEN) { + try { + worker_runtime.createSocketRequest('POST', getUniqueURL(getSendURL(this.location, this.session))).start(payload); + return true; + } + catch (e) { + return false; + } + } + else { + return false; + } + }; + HTTPSocket.prototype.reconnect = function () { + this.closeStream(); + this.openStream(); + }; + HTTPSocket.prototype.onClose = function (code, reason, wasClean) { + this.closeStream(); + this.readyState = state.CLOSED; + if (this.onclose) { + this.onclose({ + code: code, + reason: reason, + wasClean: wasClean + }); + } + }; + HTTPSocket.prototype.onChunk = function (chunk) { + if (chunk.status !== 200) { + return; + } + if (this.readyState === state.OPEN) { + this.onActivity(); + } + var payload; + var type = chunk.data.slice(0, 1); + switch (type) { + case 'o': + payload = JSON.parse(chunk.data.slice(1) || '{}'); + this.onOpen(payload); + break; + case 'a': + payload = JSON.parse(chunk.data.slice(1) || '[]'); + for (var i = 0; i < payload.length; i++) { + this.onEvent(payload[i]); + } + break; + case 'm': + payload = JSON.parse(chunk.data.slice(1) || 'null'); + this.onEvent(payload); + break; + case 'h': + this.hooks.onHeartbeat(this); + break; + case 'c': + payload = JSON.parse(chunk.data.slice(1) || '[]'); + this.onClose(payload[0], payload[1], true); + break; + } + }; + HTTPSocket.prototype.onOpen = function (options) { + if (this.readyState === state.CONNECTING) { + if (options && options.hostname) { + this.location.base = replaceHost(this.location.base, options.hostname); + } + this.readyState = state.OPEN; + if (this.onopen) { + this.onopen(); + } + } + else { + this.onClose(1006, 'Server lost session', true); + } + }; + HTTPSocket.prototype.onEvent = function (event) { + if (this.readyState === state.OPEN && this.onmessage) { + this.onmessage({ data: event }); + } + }; + HTTPSocket.prototype.onActivity = function () { + if (this.onactivity) { + this.onactivity(); + } + }; + HTTPSocket.prototype.onError = function (error) { + if (this.onerror) { + this.onerror(error); + } + }; + HTTPSocket.prototype.openStream = function () { + var _this = this; + this.stream = worker_runtime.createSocketRequest('POST', getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))); + this.stream.bind('chunk', function (chunk) { + _this.onChunk(chunk); + }); + this.stream.bind('finished', function (status) { + _this.hooks.onFinished(_this, status); + }); + this.stream.bind('buffer_too_long', function () { + _this.reconnect(); + }); + try { + this.stream.start(); + } + catch (error) { + util.defer(function () { + _this.onError(error); + _this.onClose(1006, 'Could not start streaming', false); + }); + } + }; + HTTPSocket.prototype.closeStream = function () { + if (this.stream) { + this.stream.unbind_all(); + this.stream.close(); + this.stream = null; + } + }; + return HTTPSocket; +}()); +function getLocation(url) { + var parts = /([^\?]*)\/*(\??.*)/.exec(url); + return { + base: parts[1], + queryString: parts[2] + }; +} +function getSendURL(url, session) { + return url.base + '/' + session + '/xhr_send'; +} +function getUniqueURL(url) { + var separator = url.indexOf('?') === -1 ? '?' : '&'; + return url + separator + 't=' + +new Date() + '&n=' + autoIncrement++; +} +function replaceHost(url, hostname) { + var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url); + return urlParts[1] + hostname + urlParts[3]; +} +function randomNumber(max) { + return Math.floor(Math.random() * max); +} +function randomString(length) { + var result = []; + for (var i = 0; i < length; i++) { + result.push(randomNumber(32).toString(32)); + } + return result.join(''); +} +/* harmony default export */ var http_socket = (http_socket_HTTPSocket); + +// CONCATENATED MODULE: ./src/core/http/http_streaming_socket.ts +var http_streaming_socket_hooks = { + getReceiveURL: function (url, session) { + return url.base + '/' + session + '/xhr_streaming' + url.queryString; + }, + onHeartbeat: function (socket) { + socket.sendRaw('[]'); + }, + sendHeartbeat: function (socket) { + socket.sendRaw('[]'); + }, + onFinished: function (socket, status) { + socket.onClose(1006, 'Connection interrupted (' + status + ')', false); + } +}; +/* harmony default export */ var http_streaming_socket = (http_streaming_socket_hooks); + +// CONCATENATED MODULE: ./src/core/http/http_polling_socket.ts +var http_polling_socket_hooks = { + getReceiveURL: function (url, session) { + return url.base + '/' + session + '/xhr' + url.queryString; + }, + onHeartbeat: function () { + }, + sendHeartbeat: function (socket) { + socket.sendRaw('[]'); + }, + onFinished: function (socket, status) { + if (status === 200) { + socket.reconnect(); + } + else { + socket.onClose(1006, 'Connection interrupted (' + status + ')', false); + } + } +}; +/* harmony default export */ var http_polling_socket = (http_polling_socket_hooks); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http_xhr_request.ts + +var http_xhr_request_hooks = { + getRequest: function (socket) { + var Constructor = worker_runtime.getXHRAPI(); + var xhr = new Constructor(); + xhr.onreadystatechange = xhr.onprogress = function () { + switch (xhr.readyState) { + case 3: + if (xhr.responseText && xhr.responseText.length > 0) { + socket.onChunk(xhr.status, xhr.responseText); + } + break; + case 4: + if (xhr.responseText && xhr.responseText.length > 0) { + socket.onChunk(xhr.status, xhr.responseText); + } + socket.emit('finished', xhr.status); + socket.close(); + break; + } + }; + return xhr; + }, + abortRequest: function (xhr) { + xhr.onreadystatechange = null; + xhr.abort(); + } +}; +/* harmony default export */ var http_xhr_request = (http_xhr_request_hooks); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/http/http.ts + + + + + +var HTTP = { + createStreamingSocket: function (url) { + return this.createSocket(http_streaming_socket, url); + }, + createPollingSocket: function (url) { + return this.createSocket(http_polling_socket, url); + }, + createSocket: function (hooks, url) { + return new http_socket(hooks, url); + }, + createXHR: function (method, url) { + return this.createRequest(http_xhr_request, method, url); + }, + createRequest: function (hooks, method, url) { + return new http_request(hooks, method, url); + } +}; +/* harmony default export */ var http_http = (HTTP); + +// CONCATENATED MODULE: ./src/runtimes/isomorphic/runtime.ts + + + + + +var Isomorphic = { + getDefaultStrategy: default_strategy, + Transports: transports, + transportConnectionInitializer: transport_connection_initializer, + HTTPFactory: http_http, + setup: function (PusherClass) { + PusherClass.ready(); + }, + getLocalStorage: function () { + return undefined; + }, + getClientFeatures: function () { + return keys(filterObject({ ws: transports.ws }, function (t) { + return t.isSupported({}); + })); + }, + getProtocol: function () { + return 'http:'; + }, + isXHRSupported: function () { + return true; + }, + createSocketRequest: function (method, url) { + if (this.isXHRSupported()) { + return this.HTTPFactory.createXHR(method, url); + } + else { + throw 'Cross-origin HTTP requests are not supported'; + } + }, + createXHR: function () { + var Constructor = this.getXHRAPI(); + return new Constructor(); + }, + createWebSocket: function (url) { + var Constructor = this.getWebSocketAPI(); + return new Constructor(url); + }, + addUnloadListener: function (listener) { }, + removeUnloadListener: function (listener) { } +}; +/* harmony default export */ var runtime = (Isomorphic); + +// CONCATENATED MODULE: ./src/runtimes/worker/net_info.ts +var net_info_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + +var NetInfo = (function (_super) { + net_info_extends(NetInfo, _super); + function NetInfo() { + return _super !== null && _super.apply(this, arguments) || this; + } + NetInfo.prototype.isOnline = function () { + return true; + }; + return NetInfo; +}(dispatcher)); + +var net_info_Network = new NetInfo(); + +// CONCATENATED MODULE: ./src/runtimes/worker/auth/fetch_auth.ts + +var fetchAuth = function (context, socketId, callback) { + var headers = new Headers(); + headers.set('Content-Type', 'application/x-www-form-urlencoded'); + for (var headerName in this.authOptions.headers) { + headers.set(headerName, this.authOptions.headers[headerName]); + } + var body = this.composeQuery(socketId); + var request = new Request(this.options.authEndpoint, { + headers: headers, + body: body, + credentials: 'same-origin', + method: 'POST' + }); + return fetch(request) + .then(function (response) { + var status = response.status; + if (status === 200) { + return response.text(); + } + else { + logger.error("Couldn't get auth info from your auth endpoint", status); + throw status; + } + }) + .then(function (data) { + try { + data = JSON.parse(data); + } + catch (e) { + var message = 'JSON returned from auth endpoint was invalid, yet status code was 200. Data was: ' + + data; + logger.error(message); + throw message; + } + callback(false, data); + })["catch"](function (err) { + callback(true, err); + }); +}; +/* harmony default export */ var fetch_auth = (fetchAuth); + +// CONCATENATED MODULE: ./src/runtimes/worker/timeline/fetch_timeline.ts + + +var getAgent = function (sender, useTLS) { + return function (data, callback) { + var scheme = 'http' + (useTLS ? 's' : '') + '://'; + var url = scheme + (sender.host || sender.options.host) + sender.options.path; + var query = buildQueryString(data); + url += '/' + 2 + '?' + query; + fetch(url) + .then(function (response) { + if (response.status !== 200) { + throw "received " + response.status + " from stats.pusher.com"; + } + return response.json(); + }) + .then(function (_a) { + var host = _a.host; + if (host) { + sender.host = host; + } + })["catch"](function (err) { + logger.debug('TimelineSender Error: ', err); + }); + }; +}; +var fetchTimeline = { + name: 'xhr', + getAgent: getAgent +}; +/* harmony default export */ var fetch_timeline = (fetchTimeline); + +// CONCATENATED MODULE: ./src/runtimes/worker/runtime.ts + + + + +var runtime_getDefaultStrategy = runtime.getDefaultStrategy, runtime_Transports = runtime.Transports, setup = runtime.setup, getProtocol = runtime.getProtocol, isXHRSupported = runtime.isXHRSupported, getLocalStorage = runtime.getLocalStorage, createXHR = runtime.createXHR, createWebSocket = runtime.createWebSocket, addUnloadListener = runtime.addUnloadListener, removeUnloadListener = runtime.removeUnloadListener, transportConnectionInitializer = runtime.transportConnectionInitializer, createSocketRequest = runtime.createSocketRequest, HTTPFactory = runtime.HTTPFactory; +var Worker = { + getDefaultStrategy: runtime_getDefaultStrategy, + Transports: runtime_Transports, + setup: setup, + getProtocol: getProtocol, + isXHRSupported: isXHRSupported, + getLocalStorage: getLocalStorage, + createXHR: createXHR, + createWebSocket: createWebSocket, + addUnloadListener: addUnloadListener, + removeUnloadListener: removeUnloadListener, + transportConnectionInitializer: transportConnectionInitializer, + createSocketRequest: createSocketRequest, + HTTPFactory: HTTPFactory, + TimelineTransport: fetch_timeline, + getAuthorizers: function () { + return { ajax: fetch_auth }; + }, + getWebSocketAPI: function () { + return WebSocket; + }, + getXHRAPI: function () { + return XMLHttpRequest; + }, + getNetwork: function () { + return net_info_Network; + } +}; +/* harmony default export */ var worker_runtime = (Worker); + +// CONCATENATED MODULE: ./src/core/timeline/level.ts +var TimelineLevel; +(function (TimelineLevel) { + TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR"; + TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO"; + TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG"; +})(TimelineLevel || (TimelineLevel = {})); +/* harmony default export */ var timeline_level = (TimelineLevel); + +// CONCATENATED MODULE: ./src/core/timeline/timeline.ts + + + +var timeline_Timeline = (function () { + function Timeline(key, session, options) { + this.key = key; + this.session = session; + this.events = []; + this.options = options || {}; + this.sent = 0; + this.uniqueID = 0; + } + Timeline.prototype.log = function (level, event) { + if (level <= this.options.level) { + this.events.push(extend({}, event, { timestamp: util.now() })); + if (this.options.limit && this.events.length > this.options.limit) { + this.events.shift(); + } + } + }; + Timeline.prototype.error = function (event) { + this.log(timeline_level.ERROR, event); + }; + Timeline.prototype.info = function (event) { + this.log(timeline_level.INFO, event); + }; + Timeline.prototype.debug = function (event) { + this.log(timeline_level.DEBUG, event); + }; + Timeline.prototype.isEmpty = function () { + return this.events.length === 0; + }; + Timeline.prototype.send = function (sendfn, callback) { + var _this = this; + var data = extend({ + session: this.session, + bundle: this.sent + 1, + key: this.key, + lib: 'js', + version: this.options.version, + cluster: this.options.cluster, + features: this.options.features, + timeline: this.events + }, this.options.params); + this.events = []; + sendfn(data, function (error, result) { + if (!error) { + _this.sent++; + } + if (callback) { + callback(error, result); + } + }); + return true; + }; + Timeline.prototype.generateUniqueID = function () { + this.uniqueID++; + return this.uniqueID; + }; + return Timeline; +}()); +/* harmony default export */ var timeline_timeline = (timeline_Timeline); + +// CONCATENATED MODULE: ./src/core/strategies/transport_strategy.ts + + + + +var transport_strategy_TransportStrategy = (function () { + function TransportStrategy(name, priority, transport, options) { + this.name = name; + this.priority = priority; + this.transport = transport; + this.options = options || {}; + } + TransportStrategy.prototype.isSupported = function () { + return this.transport.isSupported({ + useTLS: this.options.useTLS + }); + }; + TransportStrategy.prototype.connect = function (minPriority, callback) { + var _this = this; + if (!this.isSupported()) { + return failAttempt(new UnsupportedStrategy(), callback); + } + else if (this.priority < minPriority) { + return failAttempt(new TransportPriorityTooLow(), callback); + } + var connected = false; + var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options); + var handshake = null; + var onInitialized = function () { + transport.unbind('initialized', onInitialized); + transport.connect(); + }; + var onOpen = function () { + handshake = factory.createHandshake(transport, function (result) { + connected = true; + unbindListeners(); + callback(null, result); + }); + }; + var onError = function (error) { + unbindListeners(); + callback(error); + }; + var onClosed = function () { + unbindListeners(); + var serializedTransport; + serializedTransport = safeJSONStringify(transport); + callback(new TransportClosed(serializedTransport)); + }; + var unbindListeners = function () { + transport.unbind('initialized', onInitialized); + transport.unbind('open', onOpen); + transport.unbind('error', onError); + transport.unbind('closed', onClosed); + }; + transport.bind('initialized', onInitialized); + transport.bind('open', onOpen); + transport.bind('error', onError); + transport.bind('closed', onClosed); + transport.initialize(); + return { + abort: function () { + if (connected) { + return; + } + unbindListeners(); + if (handshake) { + handshake.close(); + } + else { + transport.close(); + } + }, + forceMinPriority: function (p) { + if (connected) { + return; + } + if (_this.priority < p) { + if (handshake) { + handshake.close(); + } + else { + transport.close(); + } + } + } + }; + }; + return TransportStrategy; +}()); +/* harmony default export */ var transport_strategy = (transport_strategy_TransportStrategy); +function failAttempt(error, callback) { + util.defer(function () { + callback(error); + }); + return { + abort: function () { }, + forceMinPriority: function () { } + }; +} + +// CONCATENATED MODULE: ./src/core/strategies/strategy_builder.ts + + + + + +var strategy_builder_Transports = worker_runtime.Transports; +var strategy_builder_defineTransport = function (config, name, type, priority, options, manager) { + var transportClass = strategy_builder_Transports[type]; + if (!transportClass) { + throw new UnsupportedTransport(type); + } + var enabled = (!config.enabledTransports || + arrayIndexOf(config.enabledTransports, name) !== -1) && + (!config.disabledTransports || + arrayIndexOf(config.disabledTransports, name) === -1); + var transport; + if (enabled) { + options = Object.assign({ ignoreNullOrigin: config.ignoreNullOrigin }, options); + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options); + } + else { + transport = strategy_builder_UnsupportedStrategy; + } + return transport; +}; +var strategy_builder_UnsupportedStrategy = { + isSupported: function () { + return false; + }, + connect: function (_, callback) { + var deferred = util.defer(function () { + callback(new UnsupportedStrategy()); + }); + return { + abort: function () { + deferred.ensureAborted(); + }, + forceMinPriority: function () { } + }; + } +}; + +// CONCATENATED MODULE: ./src/core/config.ts + + +function getConfig(opts) { + var config = { + activityTimeout: opts.activityTimeout || defaults.activityTimeout, + authEndpoint: opts.authEndpoint || defaults.authEndpoint, + authTransport: opts.authTransport || defaults.authTransport, + cluster: opts.cluster || defaults.cluster, + httpPath: opts.httpPath || defaults.httpPath, + httpPort: opts.httpPort || defaults.httpPort, + httpsPort: opts.httpsPort || defaults.httpsPort, + pongTimeout: opts.pongTimeout || defaults.pongTimeout, + statsHost: opts.statsHost || defaults.stats_host, + unavailableTimeout: opts.unavailableTimeout || defaults.unavailableTimeout, + wsPath: opts.wsPath || defaults.wsPath, + wsPort: opts.wsPort || defaults.wsPort, + wssPort: opts.wssPort || defaults.wssPort, + enableStats: getEnableStatsConfig(opts), + httpHost: getHttpHost(opts), + useTLS: shouldUseTLS(opts), + wsHost: getWebsocketHost(opts) + }; + if ('auth' in opts) + config.auth = opts.auth; + if ('authorizer' in opts) + config.authorizer = opts.authorizer; + if ('disabledTransports' in opts) + config.disabledTransports = opts.disabledTransports; + if ('enabledTransports' in opts) + config.enabledTransports = opts.enabledTransports; + if ('ignoreNullOrigin' in opts) + config.ignoreNullOrigin = opts.ignoreNullOrigin; + if ('timelineParams' in opts) + config.timelineParams = opts.timelineParams; + if ('nacl' in opts) { + config.nacl = opts.nacl; + } + return config; +} +function getHttpHost(opts) { + if (opts.httpHost) { + return opts.httpHost; + } + if (opts.cluster) { + return "sockjs-" + opts.cluster + ".pusher.com"; + } + return defaults.httpHost; +} +function getWebsocketHost(opts) { + if (opts.wsHost) { + return opts.wsHost; + } + if (opts.cluster) { + return getWebsocketHostFromCluster(opts.cluster); + } + return getWebsocketHostFromCluster(defaults.cluster); +} +function getWebsocketHostFromCluster(cluster) { + return "ws-" + cluster + ".pusher.com"; +} +function shouldUseTLS(opts) { + if (worker_runtime.getProtocol() === 'https:') { + return true; + } + else if (opts.forceTLS === false) { + return false; + } + return true; +} +function getEnableStatsConfig(opts) { + if ('enableStats' in opts) { + return opts.enableStats; + } + if ('disableStats' in opts) { + return !opts.disableStats; + } + return false; +} + +// CONCATENATED MODULE: ./src/core/pusher.ts + + + + + + + + + + + + +var pusher_Pusher = (function () { + function Pusher(app_key, options) { + var _this = this; + checkAppKey(app_key); + options = options || {}; + if (!options.cluster && !(options.wsHost || options.httpHost)) { + var suffix = url_store.buildLogSuffix('javascriptQuickStart'); + logger.warn("You should always specify a cluster when connecting. " + suffix); + } + if ('disableStats' in options) { + logger.warn('The disableStats option is deprecated in favor of enableStats'); + } + this.key = app_key; + this.config = getConfig(options); + this.channels = factory.createChannels(); + this.global_emitter = new dispatcher(); + this.sessionID = Math.floor(Math.random() * 1000000000); + this.timeline = new timeline_timeline(this.key, this.sessionID, { + cluster: this.config.cluster, + features: Pusher.getClientFeatures(), + params: this.config.timelineParams || {}, + limit: 50, + level: timeline_level.INFO, + version: defaults.VERSION + }); + if (this.config.enableStats) { + this.timelineSender = factory.createTimelineSender(this.timeline, { + host: this.config.statsHost, + path: '/timeline/v2/' + worker_runtime.TimelineTransport.name + }); + } + var getStrategy = function (options) { + return worker_runtime.getDefaultStrategy(_this.config, options, strategy_builder_defineTransport); + }; + this.connection = factory.createConnectionManager(this.key, { + getStrategy: getStrategy, + timeline: this.timeline, + activityTimeout: this.config.activityTimeout, + pongTimeout: this.config.pongTimeout, + unavailableTimeout: this.config.unavailableTimeout, + useTLS: Boolean(this.config.useTLS) + }); + this.connection.bind('connected', function () { + _this.subscribeAll(); + if (_this.timelineSender) { + _this.timelineSender.send(_this.connection.isUsingTLS()); + } + }); + this.connection.bind('message', function (event) { + var eventName = event.event; + var internal = eventName.indexOf('pusher_internal:') === 0; + if (event.channel) { + var channel = _this.channel(event.channel); + if (channel) { + channel.handleEvent(event); + } + } + if (!internal) { + _this.global_emitter.emit(event.event, event.data); + } + }); + this.connection.bind('connecting', function () { + _this.channels.disconnect(); + }); + this.connection.bind('disconnected', function () { + _this.channels.disconnect(); + }); + this.connection.bind('error', function (err) { + logger.warn(err); + }); + Pusher.instances.push(this); + this.timeline.info({ instances: Pusher.instances.length }); + if (Pusher.isReady) { + this.connect(); + } + } + Pusher.ready = function () { + Pusher.isReady = true; + for (var i = 0, l = Pusher.instances.length; i < l; i++) { + Pusher.instances[i].connect(); + } + }; + Pusher.getClientFeatures = function () { + return keys(filterObject({ ws: worker_runtime.Transports.ws }, function (t) { + return t.isSupported({}); + })); + }; + Pusher.prototype.channel = function (name) { + return this.channels.find(name); + }; + Pusher.prototype.allChannels = function () { + return this.channels.all(); + }; + Pusher.prototype.connect = function () { + this.connection.connect(); + if (this.timelineSender) { + if (!this.timelineSenderTimer) { + var usingTLS = this.connection.isUsingTLS(); + var timelineSender = this.timelineSender; + this.timelineSenderTimer = new PeriodicTimer(60000, function () { + timelineSender.send(usingTLS); + }); + } + } + }; + Pusher.prototype.disconnect = function () { + this.connection.disconnect(); + if (this.timelineSenderTimer) { + this.timelineSenderTimer.ensureAborted(); + this.timelineSenderTimer = null; + } + }; + Pusher.prototype.bind = function (event_name, callback, context) { + this.global_emitter.bind(event_name, callback, context); + return this; + }; + Pusher.prototype.unbind = function (event_name, callback, context) { + this.global_emitter.unbind(event_name, callback, context); + return this; + }; + Pusher.prototype.bind_global = function (callback) { + this.global_emitter.bind_global(callback); + return this; + }; + Pusher.prototype.unbind_global = function (callback) { + this.global_emitter.unbind_global(callback); + return this; + }; + Pusher.prototype.unbind_all = function (callback) { + this.global_emitter.unbind_all(); + return this; + }; + Pusher.prototype.subscribeAll = function () { + var channelName; + for (channelName in this.channels.channels) { + if (this.channels.channels.hasOwnProperty(channelName)) { + this.subscribe(channelName); + } + } + }; + Pusher.prototype.subscribe = function (channel_name) { + var channel = this.channels.add(channel_name, this); + if (channel.subscriptionPending && channel.subscriptionCancelled) { + channel.reinstateSubscription(); + } + else if (!channel.subscriptionPending && + this.connection.state === 'connected') { + channel.subscribe(); + } + return channel; + }; + Pusher.prototype.unsubscribe = function (channel_name) { + var channel = this.channels.find(channel_name); + if (channel && channel.subscriptionPending) { + channel.cancelSubscription(); + } + else { + channel = this.channels.remove(channel_name); + if (channel && this.connection.state === 'connected') { + channel.unsubscribe(); + } + } + }; + Pusher.prototype.send_event = function (event_name, data, channel) { + return this.connection.send_event(event_name, data, channel); + }; + Pusher.prototype.shouldUseTLS = function () { + return this.config.useTLS; + }; + Pusher.instances = []; + Pusher.isReady = false; + Pusher.logToConsole = false; + Pusher.Runtime = worker_runtime; + Pusher.ScriptReceivers = worker_runtime.ScriptReceivers; + Pusher.DependenciesReceivers = worker_runtime.DependenciesReceivers; + Pusher.auth_callbacks = worker_runtime.auth_callbacks; + return Pusher; +}()); +/* harmony default export */ var core_pusher = (pusher_Pusher); +function checkAppKey(key) { + if (key === null || key === undefined) { + throw 'You must pass your app key when you instantiate Pusher.'; + } +} +worker_runtime.setup(pusher_Pusher); + +// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js +var nacl_fast = __webpack_require__(2); + +// CONCATENATED MODULE: ./src/core/pusher-with-encryption.ts +var pusher_with_encryption_extends = (undefined && undefined.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); + + +var pusher_with_encryption_PusherWithEncryption = (function (_super) { + pusher_with_encryption_extends(PusherWithEncryption, _super); + function PusherWithEncryption(app_key, options) { + var _this = this; + core_pusher.logToConsole = PusherWithEncryption.logToConsole; + core_pusher.log = PusherWithEncryption.log; + options = options || {}; + options.nacl = nacl_fast; + _this = _super.call(this, app_key, options) || this; + return _this; + } + return PusherWithEncryption; +}(core_pusher)); +/* harmony default export */ var pusher_with_encryption = __webpack_exports__["default"] = (pusher_with_encryption_PusherWithEncryption); + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/dist/worker/pusher-with-encryption.worker.min.js b/dist/worker/pusher-with-encryption.worker.min.js new file mode 100644 index 000000000..45cfb0430 --- /dev/null +++ b/dist/worker/pusher-with-encryption.worker.min.js @@ -0,0 +1,8 @@ +/*! + * Pusher JavaScript Library v6.0.0 + * https://pusher.com/ + * + * Copyright 2017, Pusher + * Released under the MIT licence. + */ +var Pusher=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t){void 0===t&&(t="="),this._paddingCharacter=t}return t.prototype.encodedLength=function(t){return this._paddingCharacter?(t+2)/3*4|0:(8*t+5)/6|0},t.prototype.encode=function(t){for(var e="",n=0;n>>18&63),e+=this._encodeByte(r>>>12&63),e+=this._encodeByte(r>>>6&63),e+=this._encodeByte(r>>>0&63)}var o=t.length-n;if(o>0){r=t[n]<<16|(2===o?t[n+1]<<8:0);e+=this._encodeByte(r>>>18&63),e+=this._encodeByte(r>>>12&63),e+=2===o?this._encodeByte(r>>>6&63):this._paddingCharacter||"",e+=this._paddingCharacter||""}return e},t.prototype.maxDecodedLength=function(t){return this._paddingCharacter?t/4*3|0:(6*t+7)/8|0},t.prototype.decodedLength=function(t){return this.maxDecodedLength(t.length-this._getPaddingLength(t))},t.prototype.decode=function(t){if(0===t.length)return new Uint8Array(0);for(var e=this._getPaddingLength(t),n=t.length-e,r=new Uint8Array(this.maxDecodedLength(n)),o=0,i=0,s=0,a=0,c=0,u=0,h=0;i>>4,r[o++]=c<<4|u>>>2,r[o++]=u<<6|h,s|=256&a,s|=256&c,s|=256&u,s|=256&h;if(i>>4,s|=256&a,s|=256&c),i>>2,s|=256&u),i>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-15,e+=62-t>>>8&3,String.fromCharCode(e)},t.prototype._decodeChar=function(t){var e=256;return e+=(42-t&t-44)>>>8&-256+t-43+62,e+=(46-t&t-48)>>>8&-256+t-47+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},t.prototype._getPaddingLength=function(t){var e=0;if(this._paddingCharacter){for(var n=t.length-1;n>=0&&t[n]===this._paddingCharacter;n--)e++;if(t.length<4||e>2)throw new Error("Base64Coder: incorrect padding")}return e},t}();e.Coder=i;var s=new i;e.encode=function(t){return s.encode(t)},e.decode=function(t){return s.decode(t)};var a=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype._encodeByte=function(t){var e=t;return e+=65,e+=25-t>>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-13,e+=62-t>>>8&49,String.fromCharCode(e)},e.prototype._decodeChar=function(t){var e=256;return e+=(44-t&t-46)>>>8&-256+t-45+62,e+=(94-t&t-96)>>>8&-256+t-95+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},e}(i);e.URLSafeCoder=a;var c=new a;e.encodeURLSafe=function(t){return c.encode(t)},e.decodeURLSafe=function(t){return c.decode(t)},e.encodedLength=function(t){return s.encodedLength(t)},e.maxDecodedLength=function(t){return s.maxDecodedLength(t)},e.decodedLength=function(t){return s.decodedLength(t)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r="utf8: invalid source encoding";function o(t){for(var e=0,n=0;n=t.length-1)throw new Error("utf8: invalid string");n++,e+=4}}return e}e.encode=function(t){for(var e=new Uint8Array(o(t)),n=0,r=0;r>6,e[n++]=128|63&i):i<55296?(e[n++]=224|i>>12,e[n++]=128|i>>6&63,e[n++]=128|63&i):(r++,i=(1023&i)<<10,i|=1023&t.charCodeAt(r),i+=65536,e[n++]=240|i>>18,e[n++]=128|i>>12&63,e[n++]=128|i>>6&63,e[n++]=128|63&i)}return e},e.encodedLength=o,e.decode=function(t){for(var e=[],n=0;n=t.length)throw new Error(r);if(128!=(192&(s=t[++n])))throw new Error(r);o=(31&o)<<6|63&s,i=128}else if(o<240){if(n>=t.length-1)throw new Error(r);var s=t[++n],a=t[++n];if(128!=(192&s)||128!=(192&a))throw new Error(r);o=(15&o)<<12|(63&s)<<6|63&a,i=2048}else{if(!(o<248))throw new Error(r);if(n>=t.length-2)throw new Error(r);s=t[++n],a=t[++n];var c=t[++n];if(128!=(192&s)||128!=(192&a)||128!=(192&c))throw new Error(r);o=(15&o)<<18|(63&s)<<12|(63&a)<<6|63&c,i=65536}if(o=55296&&o<=57343)throw new Error(r);if(o>=65536){if(o>1114111)throw new Error(r);o-=65536,e.push(String.fromCharCode(55296|o>>10)),o=56320|1023&o}}e.push(String.fromCharCode(o))}return e.join("")}},function(t,e,n){!function(t){"use strict";var e=function(t){var e,n=new Float64Array(16);if(t)for(e=0;e>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function g(t,e,n,r){return y(t,e,n,r,16)}function v(t,e,n,r){return y(t,e,n,r,32)}function b(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,c=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,p=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=i,S=s,k=a,C=c,T=u,O=h,P=f,A=p,E=l,x=d,L=y,U=g,M=v,R=b,j=m,I=_,N=0;N<20;N+=2)w^=(o=(M^=(o=(E^=(o=(T^=(o=w+M|0)<<7|o>>>25)+w|0)<<9|o>>>23)+T|0)<<13|o>>>19)+E|0)<<18|o>>>14,O^=(o=(S^=(o=(R^=(o=(x^=(o=O+S|0)<<7|o>>>25)+O|0)<<9|o>>>23)+x|0)<<13|o>>>19)+R|0)<<18|o>>>14,L^=(o=(P^=(o=(k^=(o=(j^=(o=L+P|0)<<7|o>>>25)+L|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(U^=(o=(A^=(o=(C^=(o=I+U|0)<<7|o>>>25)+I|0)<<9|o>>>23)+C|0)<<13|o>>>19)+A|0)<<18|o>>>14,w^=(o=(C^=(o=(k^=(o=(S^=(o=w+C|0)<<7|o>>>25)+w|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,O^=(o=(T^=(o=(A^=(o=(P^=(o=O+T|0)<<7|o>>>25)+O|0)<<9|o>>>23)+P|0)<<13|o>>>19)+A|0)<<18|o>>>14,L^=(o=(x^=(o=(E^=(o=(U^=(o=L+x|0)<<7|o>>>25)+L|0)<<9|o>>>23)+U|0)<<13|o>>>19)+E|0)<<18|o>>>14,I^=(o=(j^=(o=(R^=(o=(M^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+M|0)<<13|o>>>19)+R|0)<<18|o>>>14;w=w+i|0,S=S+s|0,k=k+a|0,C=C+c|0,T=T+u|0,O=O+h|0,P=P+f|0,A=A+p|0,E=E+l|0,x=x+d|0,L=L+y|0,U=U+g|0,M=M+v|0,R=R+b|0,j=j+m|0,I=I+_|0,t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=C>>>0&255,t[13]=C>>>8&255,t[14]=C>>>16&255,t[15]=C>>>24&255,t[16]=T>>>0&255,t[17]=T>>>8&255,t[18]=T>>>16&255,t[19]=T>>>24&255,t[20]=O>>>0&255,t[21]=O>>>8&255,t[22]=O>>>16&255,t[23]=O>>>24&255,t[24]=P>>>0&255,t[25]=P>>>8&255,t[26]=P>>>16&255,t[27]=P>>>24&255,t[28]=A>>>0&255,t[29]=A>>>8&255,t[30]=A>>>16&255,t[31]=A>>>24&255,t[32]=E>>>0&255,t[33]=E>>>8&255,t[34]=E>>>16&255,t[35]=E>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=L>>>0&255,t[41]=L>>>8&255,t[42]=L>>>16&255,t[43]=L>>>24&255,t[44]=U>>>0&255,t[45]=U>>>8&255,t[46]=U>>>16&255,t[47]=U>>>24&255,t[48]=M>>>0&255,t[49]=M>>>8&255,t[50]=M>>>16&255,t[51]=M>>>24&255,t[52]=R>>>0&255,t[53]=R>>>8&255,t[54]=R>>>16&255,t[55]=R>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function m(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,c=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,p=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,g=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,b=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=0;w<20;w+=2)i^=(o=(v^=(o=(l^=(o=(u^=(o=i+v|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(b^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+b|0)<<18|o>>>14,y^=(o=(f^=(o=(a^=(o=(m^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+a|0)<<18|o>>>14,_^=(o=(g^=(o=(p^=(o=(c^=(o=_+g|0)<<7|o>>>25)+_|0)<<9|o>>>23)+c|0)<<13|o>>>19)+p|0)<<18|o>>>14,i^=(o=(c^=(o=(a^=(o=(s^=(o=i+c|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+a|0)<<18|o>>>14,h^=(o=(u^=(o=(p^=(o=(f^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+f|0)<<13|o>>>19)+p|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(g^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+g|0)<<13|o>>>19)+l|0)<<18|o>>>14,_^=(o=(m^=(o=(b^=(o=(v^=(o=_+m|0)<<7|o>>>25)+_|0)<<9|o>>>23)+v|0)<<13|o>>>19)+b|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=_>>>0&255,t[13]=_>>>8&255,t[14]=_>>>16&255,t[15]=_>>>24&255,t[16]=f>>>0&255,t[17]=f>>>8&255,t[18]=f>>>16&255,t[19]=f>>>24&255,t[20]=p>>>0&255,t[21]=p>>>8&255,t[22]=p>>>16&255,t[23]=p>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var _=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(t,e,n,r,o,i,s){var a,c,u=new Uint8Array(16),h=new Uint8Array(64);for(c=0;c<16;c++)u[c]=0;for(c=0;c<8;c++)u[c]=i[c];for(;o>=64;){for(b(h,u,s,_),c=0;c<64;c++)t[e+c]=n[r+c]^h[c];for(a=1,c=8;c<16;c++)a=a+(255&u[c])|0,u[c]=255&a,a>>>=8;o-=64,e+=64,r+=64}if(o>0)for(b(h,u,s,_),c=0;c=64;){for(b(c,a,o,_),s=0;s<64;s++)t[e+s]=c[s];for(i=1,s=8;s<16;s++)i=i+(255&a[s])|0,a[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(b(c,a,o,_),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),a=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|a<<5),c=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(a>>>8|c<<8),this.r[9]=c>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function O(t,e,n,r,o,i){var s=new T(i);return s.update(n,r,o),s.finish(t,e),0}function P(t,e,n,r,o,i){var s=new Uint8Array(16);return O(s,0,n,r,o,i),g(t,e,s,0)}function A(t,e,n,r,o){var i;if(n<32)return-1;for(C(t,0,e,0,n,r,o),O(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function E(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==P(e,16,e,32,n-32,s))return-1;for(C(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function L(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function U(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function M(t,n){var r,o,i,s=e(),a=e();for(r=0;r<16;r++)a[r]=n[r];for(L(a),L(a),L(a),o=0;o<2;o++){for(s[0]=a[0]-65517,r=1;r<15;r++)s[r]=a[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=a[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,U(a,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&a[r],t[2*r+1]=a[r]>>8}function R(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return M(n,t),M(r,e),v(n,0,r,0)}function j(t){var e=new Uint8Array(32);return M(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function B(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function D(t,e,n){var r,o,i=0,s=0,a=0,c=0,u=0,h=0,f=0,p=0,l=0,d=0,y=0,g=0,v=0,b=0,m=0,_=0,w=0,S=0,k=0,C=0,T=0,O=0,P=0,A=0,E=0,x=0,L=0,U=0,M=0,R=0,j=0,I=n[0],N=n[1],B=n[2],D=n[3],H=n[4],z=n[5],F=n[6],q=n[7],Y=n[8],K=n[9],J=n[10],W=n[11],X=n[12],G=n[13],V=n[14],Z=n[15];i+=(r=e[0])*I,s+=r*N,a+=r*B,c+=r*D,u+=r*H,h+=r*z,f+=r*F,p+=r*q,l+=r*Y,d+=r*K,y+=r*J,g+=r*W,v+=r*X,b+=r*G,m+=r*V,_+=r*Z,s+=(r=e[1])*I,a+=r*N,c+=r*B,u+=r*D,h+=r*H,f+=r*z,p+=r*F,l+=r*q,d+=r*Y,y+=r*K,g+=r*J,v+=r*W,b+=r*X,m+=r*G,_+=r*V,w+=r*Z,a+=(r=e[2])*I,c+=r*N,u+=r*B,h+=r*D,f+=r*H,p+=r*z,l+=r*F,d+=r*q,y+=r*Y,g+=r*K,v+=r*J,b+=r*W,m+=r*X,_+=r*G,w+=r*V,S+=r*Z,c+=(r=e[3])*I,u+=r*N,h+=r*B,f+=r*D,p+=r*H,l+=r*z,d+=r*F,y+=r*q,g+=r*Y,v+=r*K,b+=r*J,m+=r*W,_+=r*X,w+=r*G,S+=r*V,k+=r*Z,u+=(r=e[4])*I,h+=r*N,f+=r*B,p+=r*D,l+=r*H,d+=r*z,y+=r*F,g+=r*q,v+=r*Y,b+=r*K,m+=r*J,_+=r*W,w+=r*X,S+=r*G,k+=r*V,C+=r*Z,h+=(r=e[5])*I,f+=r*N,p+=r*B,l+=r*D,d+=r*H,y+=r*z,g+=r*F,v+=r*q,b+=r*Y,m+=r*K,_+=r*J,w+=r*W,S+=r*X,k+=r*G,C+=r*V,T+=r*Z,f+=(r=e[6])*I,p+=r*N,l+=r*B,d+=r*D,y+=r*H,g+=r*z,v+=r*F,b+=r*q,m+=r*Y,_+=r*K,w+=r*J,S+=r*W,k+=r*X,C+=r*G,T+=r*V,O+=r*Z,p+=(r=e[7])*I,l+=r*N,d+=r*B,y+=r*D,g+=r*H,v+=r*z,b+=r*F,m+=r*q,_+=r*Y,w+=r*K,S+=r*J,k+=r*W,C+=r*X,T+=r*G,O+=r*V,P+=r*Z,l+=(r=e[8])*I,d+=r*N,y+=r*B,g+=r*D,v+=r*H,b+=r*z,m+=r*F,_+=r*q,w+=r*Y,S+=r*K,k+=r*J,C+=r*W,T+=r*X,O+=r*G,P+=r*V,A+=r*Z,d+=(r=e[9])*I,y+=r*N,g+=r*B,v+=r*D,b+=r*H,m+=r*z,_+=r*F,w+=r*q,S+=r*Y,k+=r*K,C+=r*J,T+=r*W,O+=r*X,P+=r*G,A+=r*V,E+=r*Z,y+=(r=e[10])*I,g+=r*N,v+=r*B,b+=r*D,m+=r*H,_+=r*z,w+=r*F,S+=r*q,k+=r*Y,C+=r*K,T+=r*J,O+=r*W,P+=r*X,A+=r*G,E+=r*V,x+=r*Z,g+=(r=e[11])*I,v+=r*N,b+=r*B,m+=r*D,_+=r*H,w+=r*z,S+=r*F,k+=r*q,C+=r*Y,T+=r*K,O+=r*J,P+=r*W,A+=r*X,E+=r*G,x+=r*V,L+=r*Z,v+=(r=e[12])*I,b+=r*N,m+=r*B,_+=r*D,w+=r*H,S+=r*z,k+=r*F,C+=r*q,T+=r*Y,O+=r*K,P+=r*J,A+=r*W,E+=r*X,x+=r*G,L+=r*V,U+=r*Z,b+=(r=e[13])*I,m+=r*N,_+=r*B,w+=r*D,S+=r*H,k+=r*z,C+=r*F,T+=r*q,O+=r*Y,P+=r*K,A+=r*J,E+=r*W,x+=r*X,L+=r*G,U+=r*V,M+=r*Z,m+=(r=e[14])*I,_+=r*N,w+=r*B,S+=r*D,k+=r*H,C+=r*z,T+=r*F,O+=r*q,P+=r*Y,A+=r*K,E+=r*J,x+=r*W,L+=r*X,U+=r*G,M+=r*V,R+=r*Z,_+=(r=e[15])*I,s+=38*(S+=r*B),a+=38*(k+=r*D),c+=38*(C+=r*H),u+=38*(T+=r*z),h+=38*(O+=r*F),f+=38*(P+=r*q),p+=38*(A+=r*Y),l+=38*(E+=r*K),d+=38*(x+=r*J),y+=38*(L+=r*W),g+=38*(U+=r*X),v+=38*(M+=r*G),b+=38*(R+=r*V),m+=38*(j+=r*Z),i=(r=(i+=38*(w+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=a,t[3]=c,t[4]=u,t[5]=h,t[6]=f,t[7]=p,t[8]=l,t[9]=d,t[10]=y,t[11]=g,t[12]=v,t[13]=b,t[14]=m,t[15]=_}function H(t,e){D(t,e,e)}function z(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)H(o,o),2!==r&&4!==r&&D(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function F(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=250;r>=0;r--)H(o,o),1!==r&&D(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function q(t,n,r){var o,i,s=new Uint8Array(32),a=new Float64Array(80),u=e(),h=e(),f=e(),p=e(),l=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(a,r),i=0;i<16;i++)h[i]=a[i],p[i]=u[i]=f[i]=0;for(u[0]=p[0]=1,i=254;i>=0;--i)U(u,h,o=s[i>>>3]>>>(7&i)&1),U(f,p,o),N(l,u,f),B(u,u,f),N(f,h,p),B(h,h,p),H(p,l),H(d,u),D(u,f,u),D(f,h,l),N(l,u,f),B(u,u,f),H(h,u),B(f,p,d),D(u,f,c),N(u,u,p),D(f,f,u),D(u,p,d),D(p,h,a),H(h,l),U(u,h,o),U(f,p,o);for(i=0;i<16;i++)a[i+16]=u[i],a[i+32]=f[i],a[i+48]=h[i],a[i+64]=p[i];var y=a.subarray(32),g=a.subarray(16);return z(y,y),D(g,g,y),M(t,g),0}function Y(t,e){return q(t,e,i)}function K(t,e){return r(e,32),Y(t,e)}function J(t,e,n){var r=new Uint8Array(32);return q(r,n,e),m(t,o,r,_)}T.prototype.blocks=function(t,e,n){for(var r,o,i,s,a,c,u,h,f,p,l,d,y,g,v,b,m,_,w,S=this.fin?0:2048,k=this.h[0],C=this.h[1],T=this.h[2],O=this.h[3],P=this.h[4],A=this.h[5],E=this.h[6],x=this.h[7],L=this.h[8],U=this.h[9],M=this.r[0],R=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],D=this.r[6],H=this.r[7],z=this.r[8],F=this.r[9];n>=16;)p=f=0,p+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*M,p+=(C+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*F),p+=(T+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*z),p+=(O+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*H),f=(p+=(P+=8191&(s>>>4|(a=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*D))>>>13,p&=8191,p+=(A+=a>>>1&8191)*(5*B),p+=(E+=8191&(a>>>14|(c=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),p+=(x+=8191&(c>>>11|(u=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),p+=(L+=8191&(u>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),l=f+=(p+=(U+=h>>>5|S)*(5*R))>>>13,l+=k*R,l+=C*M,l+=T*(5*F),l+=O*(5*z),f=(l+=P*(5*H))>>>13,l&=8191,l+=A*(5*D),l+=E*(5*B),l+=x*(5*N),l+=L*(5*I),f+=(l+=U*(5*j))>>>13,l&=8191,d=f,d+=k*j,d+=C*R,d+=T*M,d+=O*(5*F),f=(d+=P*(5*z))>>>13,d&=8191,d+=A*(5*H),d+=E*(5*D),d+=x*(5*B),d+=L*(5*N),y=f+=(d+=U*(5*I))>>>13,y+=k*I,y+=C*j,y+=T*R,y+=O*M,f=(y+=P*(5*F))>>>13,y&=8191,y+=A*(5*z),y+=E*(5*H),y+=x*(5*D),y+=L*(5*B),g=f+=(y+=U*(5*N))>>>13,g+=k*N,g+=C*I,g+=T*j,g+=O*R,f=(g+=P*M)>>>13,g&=8191,g+=A*(5*F),g+=E*(5*z),g+=x*(5*H),g+=L*(5*D),v=f+=(g+=U*(5*B))>>>13,v+=k*B,v+=C*N,v+=T*I,v+=O*j,f=(v+=P*R)>>>13,v&=8191,v+=A*M,v+=E*(5*F),v+=x*(5*z),v+=L*(5*H),b=f+=(v+=U*(5*D))>>>13,b+=k*D,b+=C*B,b+=T*N,b+=O*I,f=(b+=P*j)>>>13,b&=8191,b+=A*R,b+=E*M,b+=x*(5*F),b+=L*(5*z),m=f+=(b+=U*(5*H))>>>13,m+=k*H,m+=C*D,m+=T*B,m+=O*N,f=(m+=P*I)>>>13,m&=8191,m+=A*j,m+=E*R,m+=x*M,m+=L*(5*F),_=f+=(m+=U*(5*z))>>>13,_+=k*z,_+=C*H,_+=T*D,_+=O*B,f=(_+=P*N)>>>13,_&=8191,_+=A*I,_+=E*j,_+=x*R,_+=L*M,w=f+=(_+=U*(5*F))>>>13,w+=k*F,w+=C*z,w+=T*H,w+=O*D,f=(w+=P*B)>>>13,w&=8191,w+=A*N,w+=E*I,w+=x*j,w+=L*R,k=p=8191&(f=(f=((f+=(w+=U*M)>>>13)<<2)+f|0)+(p&=8191)|0),C=l+=f>>>=13,T=d&=8191,O=y&=8191,P=g&=8191,A=v&=8191,E=b&=8191,x=m&=8191,L=_&=8191,U=w&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=C,this.h[2]=T,this.h[3]=O,this.h[4]=P,this.h[5]=A,this.h[6]=E,this.h[7]=x,this.h[8]=L,this.h[9]=U},T.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},T.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+X,x[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],L[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=U,i=M,s=R,a=j,c=I,u=N,h=B,D,p=H,l=z,d=F,y=q,g=Y,v=K,b=J,W,O=65535&(T=W),P=T>>>16,A=65535&(C=D),E=C>>>16,O+=65535&(T=(Y>>>14|I<<18)^(Y>>>18|I<<14)^(I>>>9|Y<<23)),P+=T>>>16,A+=65535&(C=(I>>>14|Y<<18)^(I>>>18|Y<<14)^(Y>>>9|I<<23)),E+=C>>>16,O+=65535&(T=Y&K^~Y&J),P+=T>>>16,A+=65535&(C=I&N^~I&B),E+=C>>>16,O+=65535&(T=G[2*S+1]),P+=T>>>16,A+=65535&(C=G[2*S]),E+=C>>>16,C=x[S%16],P+=(T=L[S%16])>>>16,A+=65535&C,E+=C>>>16,A+=(P+=(O+=65535&T)>>>16)>>>16,O=65535&(T=w=65535&O|P<<16),P=T>>>16,A=65535&(C=_=65535&A|(E+=A>>>16)<<16),E=C>>>16,O+=65535&(T=(H>>>28|U<<4)^(U>>>2|H<<30)^(U>>>7|H<<25)),P+=T>>>16,A+=65535&(C=(U>>>28|H<<4)^(H>>>2|U<<30)^(H>>>7|U<<25)),E+=C>>>16,P+=(T=H&z^H&F^z&F)>>>16,A+=65535&(C=U&M^U&R^M&R),E+=C>>>16,f=65535&(A+=(P+=(O+=65535&T)>>>16)>>>16)|(E+=A>>>16)<<16,m=65535&O|P<<16,O=65535&(T=y),P=T>>>16,A=65535&(C=a),E=C>>>16,P+=(T=w)>>>16,A+=65535&(C=_),E+=C>>>16,M=o,R=i,j=s,I=a=65535&(A+=(P+=(O+=65535&T)>>>16)>>>16)|(E+=A>>>16)<<16,N=c,B=u,D=h,U=f,z=p,F=l,q=d,Y=y=65535&O|P<<16,K=g,J=v,W=b,H=m,S%16==15)for(k=0;k<16;k++)C=x[k],O=65535&(T=L[k]),P=T>>>16,A=65535&C,E=C>>>16,C=x[(k+9)%16],O+=65535&(T=L[(k+9)%16]),P+=T>>>16,A+=65535&C,E+=C>>>16,_=x[(k+1)%16],O+=65535&(T=((w=L[(k+1)%16])>>>1|_<<31)^(w>>>8|_<<24)^(w>>>7|_<<25)),P+=T>>>16,A+=65535&(C=(_>>>1|w<<31)^(_>>>8|w<<24)^_>>>7),E+=C>>>16,_=x[(k+14)%16],P+=(T=((w=L[(k+14)%16])>>>19|_<<13)^(_>>>29|w<<3)^(w>>>6|_<<26))>>>16,A+=65535&(C=(_>>>19|w<<13)^(w>>>29|_<<3)^_>>>6),E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,x[k]=65535&A|E<<16,L[k]=65535&O|P<<16;O=65535&(T=H),P=T>>>16,A=65535&(C=U),E=C>>>16,C=t[0],P+=(T=e[0])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[0]=U=65535&A|E<<16,e[0]=H=65535&O|P<<16,O=65535&(T=z),P=T>>>16,A=65535&(C=M),E=C>>>16,C=t[1],P+=(T=e[1])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[1]=M=65535&A|E<<16,e[1]=z=65535&O|P<<16,O=65535&(T=F),P=T>>>16,A=65535&(C=R),E=C>>>16,C=t[2],P+=(T=e[2])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[2]=R=65535&A|E<<16,e[2]=F=65535&O|P<<16,O=65535&(T=q),P=T>>>16,A=65535&(C=j),E=C>>>16,C=t[3],P+=(T=e[3])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[3]=j=65535&A|E<<16,e[3]=q=65535&O|P<<16,O=65535&(T=Y),P=T>>>16,A=65535&(C=I),E=C>>>16,C=t[4],P+=(T=e[4])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[4]=I=65535&A|E<<16,e[4]=Y=65535&O|P<<16,O=65535&(T=K),P=T>>>16,A=65535&(C=N),E=C>>>16,C=t[5],P+=(T=e[5])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[5]=N=65535&A|E<<16,e[5]=K=65535&O|P<<16,O=65535&(T=J),P=T>>>16,A=65535&(C=B),E=C>>>16,C=t[6],P+=(T=e[6])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[6]=B=65535&A|E<<16,e[6]=J=65535&O|P<<16,O=65535&(T=W),P=T>>>16,A=65535&(C=D),E=C>>>16,C=t[7],P+=(T=e[7])>>>16,A+=65535&C,E+=C>>>16,E+=(A+=(P+=(O+=65535&T)>>>16)>>>16)>>>16,t[7]=D=65535&A|E<<16,e[7]=W=65535&O|P<<16,X+=128,r-=128}return r}function Z(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),a=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,V(o,i,e,n),n%=128,r=0;r=0;--o)$(t,e,r=n[o/8|0]>>(7&o)&1),Q(e,t),Q(t,t),$(t,e,r)}function nt(t,n){var r=[e(),e(),e(),e()];x(r[0],f),x(r[1],p),x(r[2],a),D(r[3],f,p),et(t,r,n)}function rt(t,n,o){var i,s=new Uint8Array(64),a=[e(),e(),e(),e()];for(o||r(n,32),Z(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,nt(a,s),tt(t,a),i=0;i<32;i++)n[i+32]=t[i];return 0}var ot=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function it(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>4)*ot[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*ot[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function st(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;it(t,n)}function at(t,n,r,o){var i,s,a=new Uint8Array(64),c=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),f=[e(),e(),e(),e()];Z(a,o,32),a[0]&=248,a[31]&=127,a[31]|=64;var p=r+64;for(i=0;i>7&&B(t[0],s,t[0]),D(t[3],t[0],t[1]),0)}(p,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return rt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(ht(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n>>6)+r(128|63&e):r(224|e>>>12&15)+r(128|e>>>6&63)+r(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},f=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)].join("")},p=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)},l=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t((function(){o.timer&&(o.timer=r(o.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),d=(c=function(t,e){return(c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function y(t){self.clearTimeout(t)}function g(t){self.clearInterval(t)}var v=function(t){function e(e,n){return t.call(this,setTimeout,y,e,(function(t){return n(),null}))||this}return d(e,t),e}(l),b=function(t){function e(e,n){return t.call(this,setInterval,g,e,(function(t){return n(),t}))||this}return d(e,t),e}(l),m={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new v(0,t)},method:function(t){for(var e=[],n=1;n0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},$=Q,tt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),et=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return tt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),z.debug("Event sent",r),this.send($.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=$.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(z.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){k(e,(function(e,n){t.transport.unbind(n,e)}))};k(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=$.getCloseAction(t),n=$.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(H),nt=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=$.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new et(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=$.getCloseAction(e)||"backoff",r=$.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(_({transport:this.transport,action:t},e))},t}(),rt=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===re.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=e.auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||re.getAuthorizers(),t.authorizers[this.type].call(this,re,e,n)},t}(),ot=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(re.TimelineTransport.getAgent(this,t),e)},t}(),it=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),st=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),at=(function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}it(e,t)}(Error),function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error)),ct=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ut=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ht=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ft=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),pt={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"},encryptedChannelSupport:{fullUrl:"https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support"}}},lt=function(t){var e,n=pt.urls[t];return n?(n.fullUrl?e=n.fullUrl:n.path&&(e=pt.baseUrl+n.path),e?"See: "+e:""):""},dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),yt=function(t){function e(e,n){var r=t.call(this,(function(t,n){z.debug("No callbacks on "+e+" for "+t)}))||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return dt(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new st("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=lt("triggeringClientEvents");z.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(z.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(H),gt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),vt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return gt(e,t),e.prototype.authorize=function(t,e){return At.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(yt),bt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;k(this.members,(function(n,r){t(e.get(r))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),mt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),_t=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new bt,r}return mt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var o=lt("authenticationEndpoint");return z.error("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(vt),wt=n(1),St=n(0),kt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Ct=function(t){function e(e,n,r){var o=t.call(this,e,n)||this;return o.key=null,o.nacl=r,o}return kt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(o)r.key=Object(St.decode)(o),delete e.shared_secret,n(!1,e);else{var i="No shared_secret key in auth payload for encrypted channel: "+r.name;n(!0,i)}}}))},e.prototype.trigger=function(t,e){throw new ut("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=Object(St.decode)(e.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new v(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new v(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new v(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new v(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return _({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return _({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),z.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(H),Pt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){if(e.config.nacl)return At.createEncryptedChannel(t,e,e.config.nacl);var n=lt("encryptedChannelSupport");throw new ut("Tried to subscribe to a private-encrypted- channel but no nacl implementation available. "+n)}return 0===t.indexOf("private-")?At.createPrivateChannel(t,e):0===t.indexOf("presence-")?At.createPresenceChannel(t,e):At.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return k(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){k(this.channels,(function(t){t.disconnect()}))},t}();var At={createChannels:function(){return new Pt},createConnectionManager:function(t,e){return new Ot(t,e)},createChannel:function(t,e){return new yt(t,e)},createPrivateChannel:function(t,e){return new vt(t,e)},createPresenceChannel:function(t,e){return new _t(t,e)},createEncryptedChannel:function(t,e,n){return new Ct(t,e,n)},createTimelineSender:function(t,e){return new ot(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new rt(t,e)},createHandshake:function(t,e){return new nt(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new Z(t,e,n)}},Et=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return At.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),xt=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,a=function(c,u){u?e(null,u):(o+=1,n.loop&&(o%=r.length),o0&&(o=new v(n.timeout,(function(){i.abort(),r(!0)}))),i=t.connect(e,(function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))})),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Lt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var r=O(t,(function(t,r,o,i){return t.connect(e,n(r,i))}));return{abort:function(){T(r,Ut)},forceMinPriority:function(t){T(r,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(r,o){n[t].error=r,r?function(t){return function(t,e){for(var n=0;n=m.now()){var i=this.transports[r.transport];i&&(this.timeline.info({cached:!0,transport:r.transport,latency:r.latency}),o.push(new xt([i],{timeout:2*r.latency+1e3,failFast:!0})))}var s=m.now(),a=o.pop().connect(t,(function r(i,c){i?(jt(n),o.length>0?(s=m.now(),a=o.pop().connect(t,r)):e(i)):(!function(t,e,n){var r=re.getLocalStorage();if(r)try{r[Rt(t)]=U({timestamp:m.now(),transport:e,latency:n})}catch(t){}}(n,c.transport.name,m.now()-s),e(null,c))}));return{abort:function(){a.abort()},forceMinPriority:function(e){t=e,a&&a.forceMinPriority(e)}}},t}();function Rt(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function jt(t){var e=re.getLocalStorage();if(e)try{delete e[Rt(t)]}catch(t){}}var It=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,r=this.strategy,o=new v(this.options.delay,(function(){n=r.connect(t,e)}));return{abort:function(){o.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),Nt=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),Bt=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,r){r&&n.abort(),e(t,r)}));return n},t}();function Dt(t){return function(){return t.isSupported()}}var Ht,zt=function(t,e,n){var r={};function o(e,o,i,s,a){var c=n(t,e,o,i,s,a);return r[e]=c,c}var i,s=Object.assign({},e,{hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath}),a=_({},s,{useTLS:!0}),c=Object.assign({},e,{hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath}),u={loop:!0,timeout:15e3,timeoutLimit:6e4},h=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),f=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),p=o("ws","ws",3,s,h),l=o("wss","ws",3,a,h),d=o("xhr_streaming","xhr_streaming",1,c,f),y=o("xhr_polling","xhr_polling",1,c),g=new xt([p],u),v=new xt([l],u),b=new xt([d],u),m=new xt([y],u),w=new xt([new Nt(Dt(b),new Lt([b,new It(m,{delay:4e3})]),m)],u);return i=e.useTLS?new Lt([g,new It(w,{delay:2e3})]):new Lt([g,new It(v,{delay:2e3}),new It(w,{delay:5e3})]),new Mt(new Bt(new Nt(Dt(p),i,w)),r,{ttl:18e5,timeline:e.timeline,useTLS:e.useTLS})},Ft=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),qt=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return Ft(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},re.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(re.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(H);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(Ht||(Ht={}));var Yt=Ht,Kt=1;function Jt(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+Kt++}function Wt(t){return Math.floor(Math.random()*t)}var Xt,Gt=function(){function t(t,e){this.hooks=t,this.session=Wt(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},$t={getDefaultStrategy:zt,Transports:V,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(Vt,t)},createPollingSocket:function(t){return this.createSocket(Zt,t)},createSocket:function(t,e){return new Gt(t,e)},createXHR:function(t,e){return this.createRequest(Qt,t,e)},createRequest:function(t,e,n){return new qt(t,e,n)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return C(A({ws:V.ws},(function(t){return t.isSupported({})})))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},te=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ee=new(function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return te(e,t),e.prototype.isOnline=function(){return!0},e}(H)),ne=function(t,e,n){var r=new Headers;for(var o in r.set("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)r.set(o,this.authOptions.headers[o]);var i=this.composeQuery(e),s=new Request(this.options.authEndpoint,{headers:r,body:i,credentials:"same-origin",method:"POST"});return fetch(s).then((function(t){var e=t.status;if(200===e)return t.text();throw z.error("Couldn't get auth info from your auth endpoint",e),e})).then((function(t){try{t=JSON.parse(t)}catch(n){var e="JSON returned from auth endpoint was invalid, yet status code was 200. Data was: "+t;throw z.error(e),e}n(!1,t)})).catch((function(t){n(!0,t)}))},re={getDefaultStrategy:$t.getDefaultStrategy,Transports:$t.Transports,setup:$t.setup,getProtocol:$t.getProtocol,isXHRSupported:$t.isXHRSupported,getLocalStorage:$t.getLocalStorage,createXHR:$t.createXHR,createWebSocket:$t.createWebSocket,addUnloadListener:$t.addUnloadListener,removeUnloadListener:$t.removeUnloadListener,transportConnectionInitializer:$t.transportConnectionInitializer,createSocketRequest:$t.createSocketRequest,HTTPFactory:$t.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,e){return function(n,r){var o="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path,i=L(n);fetch(o+="/2?"+i).then((function(t){if(200!==t.status)throw"received "+t.status+" from stats.pusher.com";return t.json()})).then((function(e){var n=e.host;n&&(t.host=n)})).catch((function(t){z.debug("TimelineSender Error: ",t)}))}}},getAuthorizers:function(){return{ajax:ne}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return ee}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(Xt||(Xt={}));var oe=Xt,ie=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(_({},e,{timestamp:m.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(oe.ERROR,t)},t.prototype.info=function(t){this.log(oe.INFO,t)},t.prototype.debug=function(t){this.log(oe.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,r=_({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(r,(function(t,r){t||n.sent++,e&&e(t,r)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),se=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return ae(new ft,e);if(this.priority> 24) & 0xff; - x[i+1] = (h >> 16) & 0xff; - x[i+2] = (h >> 8) & 0xff; - x[i+3] = h & 0xff; - x[i+4] = (l >> 24) & 0xff; - x[i+5] = (l >> 16) & 0xff; - x[i+6] = (l >> 8) & 0xff; - x[i+7] = l & 0xff; -} - -function vn(x, xi, y, yi, n) { - var i,d = 0; - for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i]; - return (1 & ((d - 1) >>> 8)) - 1; -} - -function crypto_verify_16(x, xi, y, yi) { - return vn(x,xi,y,yi,16); -} - -function crypto_verify_32(x, xi, y, yi) { - return vn(x,xi,y,yi,32); -} - -function core_salsa20(o, p, k, c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - x0 = x0 + j0 | 0; - x1 = x1 + j1 | 0; - x2 = x2 + j2 | 0; - x3 = x3 + j3 | 0; - x4 = x4 + j4 | 0; - x5 = x5 + j5 | 0; - x6 = x6 + j6 | 0; - x7 = x7 + j7 | 0; - x8 = x8 + j8 | 0; - x9 = x9 + j9 | 0; - x10 = x10 + j10 | 0; - x11 = x11 + j11 | 0; - x12 = x12 + j12 | 0; - x13 = x13 + j13 | 0; - x14 = x14 + j14 | 0; - x15 = x15 + j15 | 0; - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x1 >>> 0 & 0xff; - o[ 5] = x1 >>> 8 & 0xff; - o[ 6] = x1 >>> 16 & 0xff; - o[ 7] = x1 >>> 24 & 0xff; - - o[ 8] = x2 >>> 0 & 0xff; - o[ 9] = x2 >>> 8 & 0xff; - o[10] = x2 >>> 16 & 0xff; - o[11] = x2 >>> 24 & 0xff; - - o[12] = x3 >>> 0 & 0xff; - o[13] = x3 >>> 8 & 0xff; - o[14] = x3 >>> 16 & 0xff; - o[15] = x3 >>> 24 & 0xff; - - o[16] = x4 >>> 0 & 0xff; - o[17] = x4 >>> 8 & 0xff; - o[18] = x4 >>> 16 & 0xff; - o[19] = x4 >>> 24 & 0xff; - - o[20] = x5 >>> 0 & 0xff; - o[21] = x5 >>> 8 & 0xff; - o[22] = x5 >>> 16 & 0xff; - o[23] = x5 >>> 24 & 0xff; - - o[24] = x6 >>> 0 & 0xff; - o[25] = x6 >>> 8 & 0xff; - o[26] = x6 >>> 16 & 0xff; - o[27] = x6 >>> 24 & 0xff; - - o[28] = x7 >>> 0 & 0xff; - o[29] = x7 >>> 8 & 0xff; - o[30] = x7 >>> 16 & 0xff; - o[31] = x7 >>> 24 & 0xff; - - o[32] = x8 >>> 0 & 0xff; - o[33] = x8 >>> 8 & 0xff; - o[34] = x8 >>> 16 & 0xff; - o[35] = x8 >>> 24 & 0xff; - - o[36] = x9 >>> 0 & 0xff; - o[37] = x9 >>> 8 & 0xff; - o[38] = x9 >>> 16 & 0xff; - o[39] = x9 >>> 24 & 0xff; - - o[40] = x10 >>> 0 & 0xff; - o[41] = x10 >>> 8 & 0xff; - o[42] = x10 >>> 16 & 0xff; - o[43] = x10 >>> 24 & 0xff; - - o[44] = x11 >>> 0 & 0xff; - o[45] = x11 >>> 8 & 0xff; - o[46] = x11 >>> 16 & 0xff; - o[47] = x11 >>> 24 & 0xff; - - o[48] = x12 >>> 0 & 0xff; - o[49] = x12 >>> 8 & 0xff; - o[50] = x12 >>> 16 & 0xff; - o[51] = x12 >>> 24 & 0xff; - - o[52] = x13 >>> 0 & 0xff; - o[53] = x13 >>> 8 & 0xff; - o[54] = x13 >>> 16 & 0xff; - o[55] = x13 >>> 24 & 0xff; - - o[56] = x14 >>> 0 & 0xff; - o[57] = x14 >>> 8 & 0xff; - o[58] = x14 >>> 16 & 0xff; - o[59] = x14 >>> 24 & 0xff; - - o[60] = x15 >>> 0 & 0xff; - o[61] = x15 >>> 8 & 0xff; - o[62] = x15 >>> 16 & 0xff; - o[63] = x15 >>> 24 & 0xff; -} - -function core_hsalsa20(o,p,k,c) { - var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24, - j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24, - j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24, - j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24, - j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24, - j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24, - j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24, - j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24, - j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24, - j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24, - j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24, - j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24, - j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24, - j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24, - j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24, - j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24; - - var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, - x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, - x15 = j15, u; - - for (var i = 0; i < 20; i += 2) { - u = x0 + x12 | 0; - x4 ^= u<<7 | u>>>(32-7); - u = x4 + x0 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x4 | 0; - x12 ^= u<<13 | u>>>(32-13); - u = x12 + x8 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x1 | 0; - x9 ^= u<<7 | u>>>(32-7); - u = x9 + x5 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x9 | 0; - x1 ^= u<<13 | u>>>(32-13); - u = x1 + x13 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x6 | 0; - x14 ^= u<<7 | u>>>(32-7); - u = x14 + x10 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x14 | 0; - x6 ^= u<<13 | u>>>(32-13); - u = x6 + x2 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x11 | 0; - x3 ^= u<<7 | u>>>(32-7); - u = x3 + x15 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x3 | 0; - x11 ^= u<<13 | u>>>(32-13); - u = x11 + x7 | 0; - x15 ^= u<<18 | u>>>(32-18); - - u = x0 + x3 | 0; - x1 ^= u<<7 | u>>>(32-7); - u = x1 + x0 | 0; - x2 ^= u<<9 | u>>>(32-9); - u = x2 + x1 | 0; - x3 ^= u<<13 | u>>>(32-13); - u = x3 + x2 | 0; - x0 ^= u<<18 | u>>>(32-18); - - u = x5 + x4 | 0; - x6 ^= u<<7 | u>>>(32-7); - u = x6 + x5 | 0; - x7 ^= u<<9 | u>>>(32-9); - u = x7 + x6 | 0; - x4 ^= u<<13 | u>>>(32-13); - u = x4 + x7 | 0; - x5 ^= u<<18 | u>>>(32-18); - - u = x10 + x9 | 0; - x11 ^= u<<7 | u>>>(32-7); - u = x11 + x10 | 0; - x8 ^= u<<9 | u>>>(32-9); - u = x8 + x11 | 0; - x9 ^= u<<13 | u>>>(32-13); - u = x9 + x8 | 0; - x10 ^= u<<18 | u>>>(32-18); - - u = x15 + x14 | 0; - x12 ^= u<<7 | u>>>(32-7); - u = x12 + x15 | 0; - x13 ^= u<<9 | u>>>(32-9); - u = x13 + x12 | 0; - x14 ^= u<<13 | u>>>(32-13); - u = x14 + x13 | 0; - x15 ^= u<<18 | u>>>(32-18); - } - - o[ 0] = x0 >>> 0 & 0xff; - o[ 1] = x0 >>> 8 & 0xff; - o[ 2] = x0 >>> 16 & 0xff; - o[ 3] = x0 >>> 24 & 0xff; - - o[ 4] = x5 >>> 0 & 0xff; - o[ 5] = x5 >>> 8 & 0xff; - o[ 6] = x5 >>> 16 & 0xff; - o[ 7] = x5 >>> 24 & 0xff; - - o[ 8] = x10 >>> 0 & 0xff; - o[ 9] = x10 >>> 8 & 0xff; - o[10] = x10 >>> 16 & 0xff; - o[11] = x10 >>> 24 & 0xff; - - o[12] = x15 >>> 0 & 0xff; - o[13] = x15 >>> 8 & 0xff; - o[14] = x15 >>> 16 & 0xff; - o[15] = x15 >>> 24 & 0xff; - - o[16] = x6 >>> 0 & 0xff; - o[17] = x6 >>> 8 & 0xff; - o[18] = x6 >>> 16 & 0xff; - o[19] = x6 >>> 24 & 0xff; - - o[20] = x7 >>> 0 & 0xff; - o[21] = x7 >>> 8 & 0xff; - o[22] = x7 >>> 16 & 0xff; - o[23] = x7 >>> 24 & 0xff; - - o[24] = x8 >>> 0 & 0xff; - o[25] = x8 >>> 8 & 0xff; - o[26] = x8 >>> 16 & 0xff; - o[27] = x8 >>> 24 & 0xff; - - o[28] = x9 >>> 0 & 0xff; - o[29] = x9 >>> 8 & 0xff; - o[30] = x9 >>> 16 & 0xff; - o[31] = x9 >>> 24 & 0xff; -} - -function crypto_core_salsa20(out,inp,k,c) { - core_salsa20(out,inp,k,c); -} - -function crypto_core_hsalsa20(out,inp,k,c) { - core_hsalsa20(out,inp,k,c); -} +"use strict"; -var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]); - // "expand 32-byte k" - -function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package base64 implements Base64 encoding and decoding. + */ +// Invalid character used in decoding to indicate +// that the character to decode is out of range of +// alphabet and cannot be decoded. +var INVALID_BYTE = 256; +/** + * Implements standard Base64 encoding. + * + * Operates in constant time. + */ +var Coder = /** @class */ (function () { + // TODO(dchest): methods to encode chunk-by-chunk. + function Coder(_paddingCharacter) { + if (_paddingCharacter === void 0) { _paddingCharacter = "="; } + this._paddingCharacter = _paddingCharacter; } - b -= 64; - cpos += 64; - mpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i]; - } - return 0; + Coder.prototype.encodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 8 + 5) / 6 | 0; + } + return (length + 2) / 3 * 4 | 0; + }; + Coder.prototype.encode = function (data) { + var out = ""; + var i = 0; + for (; i < data.length - 2; i += 3) { + var c = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + out += this._encodeByte((c >>> 1 * 6) & 63); + out += this._encodeByte((c >>> 0 * 6) & 63); + } + var left = data.length - i; + if (left > 0) { + var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0); + out += this._encodeByte((c >>> 3 * 6) & 63); + out += this._encodeByte((c >>> 2 * 6) & 63); + if (left === 2) { + out += this._encodeByte((c >>> 1 * 6) & 63); + } + else { + out += this._paddingCharacter || ""; + } + out += this._paddingCharacter || ""; + } + return out; + }; + Coder.prototype.maxDecodedLength = function (length) { + if (!this._paddingCharacter) { + return (length * 6 + 7) / 8 | 0; + } + return length / 4 * 3 | 0; + }; + Coder.prototype.decodedLength = function (s) { + return this.maxDecodedLength(s.length - this._getPaddingLength(s)); + }; + Coder.prototype.decode = function (s) { + if (s.length === 0) { + return new Uint8Array(0); + } + var paddingLength = this._getPaddingLength(s); + var length = s.length - paddingLength; + var out = new Uint8Array(this.maxDecodedLength(length)); + var op = 0; + var i = 0; + var haveBad = 0; + var v0 = 0, v1 = 0, v2 = 0, v3 = 0; + for (; i < length - 4; i += 4) { + v0 = this._decodeChar(s.charCodeAt(i + 0)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + v2 = this._decodeChar(s.charCodeAt(i + 2)); + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v0 << 2) | (v1 >>> 4); + out[op++] = (v1 << 4) | (v2 >>> 2); + out[op++] = (v2 << 6) | v3; + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + haveBad |= v2 & INVALID_BYTE; + haveBad |= v3 & INVALID_BYTE; + } + if (i < length - 1) { + v0 = this._decodeChar(s.charCodeAt(i)); + v1 = this._decodeChar(s.charCodeAt(i + 1)); + out[op++] = (v0 << 2) | (v1 >>> 4); + haveBad |= v0 & INVALID_BYTE; + haveBad |= v1 & INVALID_BYTE; + } + if (i < length - 2) { + v2 = this._decodeChar(s.charCodeAt(i + 2)); + out[op++] = (v1 << 4) | (v2 >>> 2); + haveBad |= v2 & INVALID_BYTE; + } + if (i < length - 3) { + v3 = this._decodeChar(s.charCodeAt(i + 3)); + out[op++] = (v2 << 6) | v3; + haveBad |= v3 & INVALID_BYTE; + } + if (haveBad !== 0) { + throw new Error("Base64Coder: incorrect characters for decoding"); + } + return out; + }; + // Standard encoding have the following encoded/decoded ranges, + // which we need to convert between. + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + / + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 43 47 + // + // Encode 6 bits in b into a new character. + Coder.prototype._encodeByte = function (b) { + // Encoding uses constant time operations as follows: + // + // 1. Define comparison of A with B using (A - B) >>> 8: + // if A > B, then result is positive integer + // if A <= B, then result is 0 + // + // 2. Define selection of C or 0 using bitwise AND: X & C: + // if X == 0, then result is 0 + // if X != 0, then result is C + // + // 3. Start with the smallest comparison (b >= 0), which is always + // true, so set the result to the starting ASCII value (65). + // + // 4. Continue comparing b to higher ASCII values, and selecting + // zero if comparison isn't true, otherwise selecting a value + // to add to result, which: + // + // a) undoes the previous addition + // b) provides new value to add + // + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47); + return String.fromCharCode(result); + }; + // Decode a character code into a byte. + // Must return 256 if character is out of alphabet range. + Coder.prototype._decodeChar = function (c) { + // Decoding works similar to encoding: using the same comparison + // function, but now it works on ranges: result is always incremented + // by value, but this value becomes zero if the range is not + // satisfied. + // + // Decoding starts with invalid value, 256, which is then + // subtracted when the range is satisfied. If none of the ranges + // apply, the function returns 256, which is then checked by + // the caller to throw error. + var result = INVALID_BYTE; // start with invalid character + // c == 43 (c > 42 and c < 44) + result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62); + // c == 47 (c > 46 and c < 48) + result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + Coder.prototype._getPaddingLength = function (s) { + var paddingLength = 0; + if (this._paddingCharacter) { + for (var i = s.length - 1; i >= 0; i--) { + if (s[i] !== this._paddingCharacter) { + break; + } + paddingLength++; + } + if (s.length < 4 || paddingLength > 2) { + throw new Error("Base64Coder: incorrect padding"); + } + } + return paddingLength; + }; + return Coder; +}()); +exports.Coder = Coder; +var stdCoder = new Coder(); +function encode(data) { + return stdCoder.encode(data); } - -function crypto_stream_salsa20(c,cpos,b,n,k) { - var z = new Uint8Array(16), x = new Uint8Array(64); - var u, i; - for (i = 0; i < 16; i++) z[i] = 0; - for (i = 0; i < 8; i++) z[i] = n[i]; - while (b >= 64) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < 64; i++) c[cpos+i] = x[i]; - u = 1; - for (i = 8; i < 16; i++) { - u = u + (z[i] & 0xff) | 0; - z[i] = u & 0xff; - u >>>= 8; - } - b -= 64; - cpos += 64; - } - if (b > 0) { - crypto_core_salsa20(x,z,k,sigma); - for (i = 0; i < b; i++) c[cpos+i] = x[i]; - } - return 0; +exports.encode = encode; +function decode(s) { + return stdCoder.decode(s); } - -function crypto_stream(c,cpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20(c,cpos,d,sn,s); +exports.decode = decode; +/** + * Implements URL-safe Base64 encoding. + * (Same as Base64, but '+' is replaced with '-', and '/' with '_'). + * + * Operates in constant time. + */ +var URLSafeCoder = /** @class */ (function (_super) { + __extends(URLSafeCoder, _super); + function URLSafeCoder() { + return _super !== null && _super.apply(this, arguments) || this; + } + // URL-safe encoding have the following encoded/decoded ranges: + // + // ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _ + // Index: 0 - 25 26 - 51 52 - 61 62 63 + // ASCII: 65 - 90 97 - 122 48 - 57 45 95 + // + URLSafeCoder.prototype._encodeByte = function (b) { + var result = b; + // b >= 0 + result += 65; + // b > 25 + result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97); + // b > 51 + result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48); + // b > 61 + result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45); + // b > 62 + result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95); + return String.fromCharCode(result); + }; + URLSafeCoder.prototype._decodeChar = function (c) { + var result = INVALID_BYTE; + // c == 45 (c > 44 and c < 46) + result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62); + // c == 95 (c > 94 and c < 96) + result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63); + // c > 47 and c < 58 + result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52); + // c > 64 and c < 91 + result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0); + // c > 96 and c < 123 + result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26); + return result; + }; + return URLSafeCoder; +}(Coder)); +exports.URLSafeCoder = URLSafeCoder; +var urlSafeCoder = new URLSafeCoder(); +function encodeURLSafe(data) { + return urlSafeCoder.encode(data); } - -function crypto_stream_xor(c,cpos,m,mpos,d,n,k) { - var s = new Uint8Array(32); - crypto_core_hsalsa20(s,n,k,sigma); - var sn = new Uint8Array(8); - for (var i = 0; i < 8; i++) sn[i] = n[i+16]; - return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s); +exports.encodeURLSafe = encodeURLSafe; +function decodeURLSafe(s) { + return urlSafeCoder.decode(s); } - -/* -* Port of Andrew Moon's Poly1305-donna-16. Public domain. -* https://github.com/floodyberry/poly1305-donna -*/ - -var poly1305 = function(key) { - this.buffer = new Uint8Array(16); - this.r = new Uint16Array(10); - this.h = new Uint16Array(10); - this.pad = new Uint16Array(8); - this.leftover = 0; - this.fin = 0; - - var t0, t1, t2, t3, t4, t5, t6, t7; - - t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff; - t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03; - t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff; - this.r[5] = ((t4 >>> 1)) & 0x1ffe; - t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81; - t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - this.r[9] = ((t7 >>> 5)) & 0x007f; - - this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8; - this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8; - this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8; - this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8; - this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8; - this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8; - this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8; - this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8; -}; - -poly1305.prototype.blocks = function(m, mpos, bytes) { - var hibit = this.fin ? 0 : (1 << 11); - var t0, t1, t2, t3, t4, t5, t6, t7, c; - var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9; - - var h0 = this.h[0], - h1 = this.h[1], - h2 = this.h[2], - h3 = this.h[3], - h4 = this.h[4], - h5 = this.h[5], - h6 = this.h[6], - h7 = this.h[7], - h8 = this.h[8], - h9 = this.h[9]; - - var r0 = this.r[0], - r1 = this.r[1], - r2 = this.r[2], - r3 = this.r[3], - r4 = this.r[4], - r5 = this.r[5], - r6 = this.r[6], - r7 = this.r[7], - r8 = this.r[8], - r9 = this.r[9]; - - while (bytes >= 16) { - t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff; - t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff; - t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff; - t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff; - t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff; - h5 += ((t4 >>> 1)) & 0x1fff; - t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff; - t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff; - t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff; - h9 += ((t7 >>> 5)) | hibit; - - c = 0; - - d0 = c; - d0 += h0 * r0; - d0 += h1 * (5 * r9); - d0 += h2 * (5 * r8); - d0 += h3 * (5 * r7); - d0 += h4 * (5 * r6); - c = (d0 >>> 13); d0 &= 0x1fff; - d0 += h5 * (5 * r5); - d0 += h6 * (5 * r4); - d0 += h7 * (5 * r3); - d0 += h8 * (5 * r2); - d0 += h9 * (5 * r1); - c += (d0 >>> 13); d0 &= 0x1fff; - - d1 = c; - d1 += h0 * r1; - d1 += h1 * r0; - d1 += h2 * (5 * r9); - d1 += h3 * (5 * r8); - d1 += h4 * (5 * r7); - c = (d1 >>> 13); d1 &= 0x1fff; - d1 += h5 * (5 * r6); - d1 += h6 * (5 * r5); - d1 += h7 * (5 * r4); - d1 += h8 * (5 * r3); - d1 += h9 * (5 * r2); - c += (d1 >>> 13); d1 &= 0x1fff; - - d2 = c; - d2 += h0 * r2; - d2 += h1 * r1; - d2 += h2 * r0; - d2 += h3 * (5 * r9); - d2 += h4 * (5 * r8); - c = (d2 >>> 13); d2 &= 0x1fff; - d2 += h5 * (5 * r7); - d2 += h6 * (5 * r6); - d2 += h7 * (5 * r5); - d2 += h8 * (5 * r4); - d2 += h9 * (5 * r3); - c += (d2 >>> 13); d2 &= 0x1fff; - - d3 = c; - d3 += h0 * r3; - d3 += h1 * r2; - d3 += h2 * r1; - d3 += h3 * r0; - d3 += h4 * (5 * r9); - c = (d3 >>> 13); d3 &= 0x1fff; - d3 += h5 * (5 * r8); - d3 += h6 * (5 * r7); - d3 += h7 * (5 * r6); - d3 += h8 * (5 * r5); - d3 += h9 * (5 * r4); - c += (d3 >>> 13); d3 &= 0x1fff; - - d4 = c; - d4 += h0 * r4; - d4 += h1 * r3; - d4 += h2 * r2; - d4 += h3 * r1; - d4 += h4 * r0; - c = (d4 >>> 13); d4 &= 0x1fff; - d4 += h5 * (5 * r9); - d4 += h6 * (5 * r8); - d4 += h7 * (5 * r7); - d4 += h8 * (5 * r6); - d4 += h9 * (5 * r5); - c += (d4 >>> 13); d4 &= 0x1fff; - - d5 = c; - d5 += h0 * r5; - d5 += h1 * r4; - d5 += h2 * r3; - d5 += h3 * r2; - d5 += h4 * r1; - c = (d5 >>> 13); d5 &= 0x1fff; - d5 += h5 * r0; - d5 += h6 * (5 * r9); - d5 += h7 * (5 * r8); - d5 += h8 * (5 * r7); - d5 += h9 * (5 * r6); - c += (d5 >>> 13); d5 &= 0x1fff; - - d6 = c; - d6 += h0 * r6; - d6 += h1 * r5; - d6 += h2 * r4; - d6 += h3 * r3; - d6 += h4 * r2; - c = (d6 >>> 13); d6 &= 0x1fff; - d6 += h5 * r1; - d6 += h6 * r0; - d6 += h7 * (5 * r9); - d6 += h8 * (5 * r8); - d6 += h9 * (5 * r7); - c += (d6 >>> 13); d6 &= 0x1fff; - - d7 = c; - d7 += h0 * r7; - d7 += h1 * r6; - d7 += h2 * r5; - d7 += h3 * r4; - d7 += h4 * r3; - c = (d7 >>> 13); d7 &= 0x1fff; - d7 += h5 * r2; - d7 += h6 * r1; - d7 += h7 * r0; - d7 += h8 * (5 * r9); - d7 += h9 * (5 * r8); - c += (d7 >>> 13); d7 &= 0x1fff; - - d8 = c; - d8 += h0 * r8; - d8 += h1 * r7; - d8 += h2 * r6; - d8 += h3 * r5; - d8 += h4 * r4; - c = (d8 >>> 13); d8 &= 0x1fff; - d8 += h5 * r3; - d8 += h6 * r2; - d8 += h7 * r1; - d8 += h8 * r0; - d8 += h9 * (5 * r9); - c += (d8 >>> 13); d8 &= 0x1fff; - - d9 = c; - d9 += h0 * r9; - d9 += h1 * r8; - d9 += h2 * r7; - d9 += h3 * r6; - d9 += h4 * r5; - c = (d9 >>> 13); d9 &= 0x1fff; - d9 += h5 * r4; - d9 += h6 * r3; - d9 += h7 * r2; - d9 += h8 * r1; - d9 += h9 * r0; - c += (d9 >>> 13); d9 &= 0x1fff; - - c = (((c << 2) + c)) | 0; - c = (c + d0) | 0; - d0 = c & 0x1fff; - c = (c >>> 13); - d1 += c; - - h0 = d0; - h1 = d1; - h2 = d2; - h3 = d3; - h4 = d4; - h5 = d5; - h6 = d6; - h7 = d7; - h8 = d8; - h9 = d9; - - mpos += 16; - bytes -= 16; - } - this.h[0] = h0; - this.h[1] = h1; - this.h[2] = h2; - this.h[3] = h3; - this.h[4] = h4; - this.h[5] = h5; - this.h[6] = h6; - this.h[7] = h7; - this.h[8] = h8; - this.h[9] = h9; +exports.decodeURLSafe = decodeURLSafe; +exports.encodedLength = function (length) { + return stdCoder.encodedLength(length); }; - -poly1305.prototype.finish = function(mac, macpos) { - var g = new Uint16Array(10); - var c, mask, f, i; - - if (this.leftover) { - i = this.leftover; - this.buffer[i++] = 1; - for (; i < 16; i++) this.buffer[i] = 0; - this.fin = 1; - this.blocks(this.buffer, 0, 16); - } - - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - for (i = 2; i < 10; i++) { - this.h[i] += c; - c = this.h[i] >>> 13; - this.h[i] &= 0x1fff; - } - this.h[0] += (c * 5); - c = this.h[0] >>> 13; - this.h[0] &= 0x1fff; - this.h[1] += c; - c = this.h[1] >>> 13; - this.h[1] &= 0x1fff; - this.h[2] += c; - - g[0] = this.h[0] + 5; - c = g[0] >>> 13; - g[0] &= 0x1fff; - for (i = 1; i < 10; i++) { - g[i] = this.h[i] + c; - c = g[i] >>> 13; - g[i] &= 0x1fff; - } - g[9] -= (1 << 13); - - mask = (c ^ 1) - 1; - for (i = 0; i < 10; i++) g[i] &= mask; - mask = ~mask; - for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]; - - this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff; - this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff; - this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff; - this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff; - this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff; - this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff; - this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff; - this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff; - - f = this.h[0] + this.pad[0]; - this.h[0] = f & 0xffff; - for (i = 1; i < 8; i++) { - f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0; - this.h[i] = f & 0xffff; - } - - mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff; - mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff; - mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff; - mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff; - mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff; - mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff; - mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff; - mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff; - mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff; - mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff; - mac[macpos+10] = (this.h[5] >>> 0) & 0xff; - mac[macpos+11] = (this.h[5] >>> 8) & 0xff; - mac[macpos+12] = (this.h[6] >>> 0) & 0xff; - mac[macpos+13] = (this.h[6] >>> 8) & 0xff; - mac[macpos+14] = (this.h[7] >>> 0) & 0xff; - mac[macpos+15] = (this.h[7] >>> 8) & 0xff; +exports.maxDecodedLength = function (length) { + return stdCoder.maxDecodedLength(length); }; - -poly1305.prototype.update = function(m, mpos, bytes) { - var i, want; - - if (this.leftover) { - want = (16 - this.leftover); - if (want > bytes) - want = bytes; - for (i = 0; i < want; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - bytes -= want; - mpos += want; - this.leftover += want; - if (this.leftover < 16) - return; - this.blocks(this.buffer, 0, 16); - this.leftover = 0; - } - - if (bytes >= 16) { - want = bytes - (bytes % 16); - this.blocks(m, mpos, want); - mpos += want; - bytes -= want; - } - - if (bytes) { - for (i = 0; i < bytes; i++) - this.buffer[this.leftover + i] = m[mpos+i]; - this.leftover += bytes; - } +exports.decodedLength = function (s) { + return stdCoder.decodedLength(s); }; +//# sourceMappingURL=base64.js.map -function crypto_onetimeauth(out, outpos, m, mpos, n, k) { - var s = new poly1305(k); - s.update(m, mpos, n); - s.finish(out, outpos); - return 0; -} - -function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) { - var x = new Uint8Array(16); - crypto_onetimeauth(x,0,m,mpos,n,k); - return crypto_verify_16(h,hpos,x,0); -} - -function crypto_secretbox(c,m,d,n,k) { - var i; - if (d < 32) return -1; - crypto_stream_xor(c,0,m,0,d,n,k); - crypto_onetimeauth(c, 16, c, 32, d - 32, c); - for (i = 0; i < 16; i++) c[i] = 0; - return 0; -} - -function crypto_secretbox_open(m,c,d,n,k) { - var i; - var x = new Uint8Array(32); - if (d < 32) return -1; - crypto_stream(x,0,32,n,k); - if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1; - crypto_stream_xor(m,0,c,0,d,n,k); - for (i = 0; i < 32; i++) m[i] = 0; - return 0; -} - -function set25519(r, a) { - var i; - for (i = 0; i < 16; i++) r[i] = a[i]|0; -} - -function car25519(o) { - var i, v, c = 1; - for (i = 0; i < 16; i++) { - v = o[i] + c + 65535; - c = Math.floor(v / 65536); - o[i] = v - c * 65536; - } - o[0] += c-1 + 37 * (c-1); -} - -function sel25519(p, q, b) { - var t, c = ~(b-1); - for (var i = 0; i < 16; i++) { - t = c & (p[i] ^ q[i]); - p[i] ^= t; - q[i] ^= t; - } -} - -function pack25519(o, n) { - var i, j, b; - var m = gf(), t = gf(); - for (i = 0; i < 16; i++) t[i] = n[i]; - car25519(t); - car25519(t); - car25519(t); - for (j = 0; j < 2; j++) { - m[0] = t[0] - 0xffed; - for (i = 1; i < 15; i++) { - m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1); - m[i-1] &= 0xffff; - } - m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1); - b = (m[15]>>16) & 1; - m[14] &= 0xffff; - sel25519(t, m, 1-b); - } - for (i = 0; i < 16; i++) { - o[2*i] = t[i] & 0xff; - o[2*i+1] = t[i]>>8; - } -} - -function neq25519(a, b) { - var c = new Uint8Array(32), d = new Uint8Array(32); - pack25519(c, a); - pack25519(d, b); - return crypto_verify_32(c, 0, d, 0); -} - -function par25519(a) { - var d = new Uint8Array(32); - pack25519(d, a); - return d[0] & 1; -} - -function unpack25519(o, n) { - var i; - for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8); - o[15] &= 0x7fff; -} - -function A(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]; -} - -function Z(o, a, b) { - for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]; -} - -function M(o, a, b) { - var v, c, - t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, - t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, - t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, - t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, - b0 = b[0], - b1 = b[1], - b2 = b[2], - b3 = b[3], - b4 = b[4], - b5 = b[5], - b6 = b[6], - b7 = b[7], - b8 = b[8], - b9 = b[9], - b10 = b[10], - b11 = b[11], - b12 = b[12], - b13 = b[13], - b14 = b[14], - b15 = b[15]; - - v = a[0]; - t0 += v * b0; - t1 += v * b1; - t2 += v * b2; - t3 += v * b3; - t4 += v * b4; - t5 += v * b5; - t6 += v * b6; - t7 += v * b7; - t8 += v * b8; - t9 += v * b9; - t10 += v * b10; - t11 += v * b11; - t12 += v * b12; - t13 += v * b13; - t14 += v * b14; - t15 += v * b15; - v = a[1]; - t1 += v * b0; - t2 += v * b1; - t3 += v * b2; - t4 += v * b3; - t5 += v * b4; - t6 += v * b5; - t7 += v * b6; - t8 += v * b7; - t9 += v * b8; - t10 += v * b9; - t11 += v * b10; - t12 += v * b11; - t13 += v * b12; - t14 += v * b13; - t15 += v * b14; - t16 += v * b15; - v = a[2]; - t2 += v * b0; - t3 += v * b1; - t4 += v * b2; - t5 += v * b3; - t6 += v * b4; - t7 += v * b5; - t8 += v * b6; - t9 += v * b7; - t10 += v * b8; - t11 += v * b9; - t12 += v * b10; - t13 += v * b11; - t14 += v * b12; - t15 += v * b13; - t16 += v * b14; - t17 += v * b15; - v = a[3]; - t3 += v * b0; - t4 += v * b1; - t5 += v * b2; - t6 += v * b3; - t7 += v * b4; - t8 += v * b5; - t9 += v * b6; - t10 += v * b7; - t11 += v * b8; - t12 += v * b9; - t13 += v * b10; - t14 += v * b11; - t15 += v * b12; - t16 += v * b13; - t17 += v * b14; - t18 += v * b15; - v = a[4]; - t4 += v * b0; - t5 += v * b1; - t6 += v * b2; - t7 += v * b3; - t8 += v * b4; - t9 += v * b5; - t10 += v * b6; - t11 += v * b7; - t12 += v * b8; - t13 += v * b9; - t14 += v * b10; - t15 += v * b11; - t16 += v * b12; - t17 += v * b13; - t18 += v * b14; - t19 += v * b15; - v = a[5]; - t5 += v * b0; - t6 += v * b1; - t7 += v * b2; - t8 += v * b3; - t9 += v * b4; - t10 += v * b5; - t11 += v * b6; - t12 += v * b7; - t13 += v * b8; - t14 += v * b9; - t15 += v * b10; - t16 += v * b11; - t17 += v * b12; - t18 += v * b13; - t19 += v * b14; - t20 += v * b15; - v = a[6]; - t6 += v * b0; - t7 += v * b1; - t8 += v * b2; - t9 += v * b3; - t10 += v * b4; - t11 += v * b5; - t12 += v * b6; - t13 += v * b7; - t14 += v * b8; - t15 += v * b9; - t16 += v * b10; - t17 += v * b11; - t18 += v * b12; - t19 += v * b13; - t20 += v * b14; - t21 += v * b15; - v = a[7]; - t7 += v * b0; - t8 += v * b1; - t9 += v * b2; - t10 += v * b3; - t11 += v * b4; - t12 += v * b5; - t13 += v * b6; - t14 += v * b7; - t15 += v * b8; - t16 += v * b9; - t17 += v * b10; - t18 += v * b11; - t19 += v * b12; - t20 += v * b13; - t21 += v * b14; - t22 += v * b15; - v = a[8]; - t8 += v * b0; - t9 += v * b1; - t10 += v * b2; - t11 += v * b3; - t12 += v * b4; - t13 += v * b5; - t14 += v * b6; - t15 += v * b7; - t16 += v * b8; - t17 += v * b9; - t18 += v * b10; - t19 += v * b11; - t20 += v * b12; - t21 += v * b13; - t22 += v * b14; - t23 += v * b15; - v = a[9]; - t9 += v * b0; - t10 += v * b1; - t11 += v * b2; - t12 += v * b3; - t13 += v * b4; - t14 += v * b5; - t15 += v * b6; - t16 += v * b7; - t17 += v * b8; - t18 += v * b9; - t19 += v * b10; - t20 += v * b11; - t21 += v * b12; - t22 += v * b13; - t23 += v * b14; - t24 += v * b15; - v = a[10]; - t10 += v * b0; - t11 += v * b1; - t12 += v * b2; - t13 += v * b3; - t14 += v * b4; - t15 += v * b5; - t16 += v * b6; - t17 += v * b7; - t18 += v * b8; - t19 += v * b9; - t20 += v * b10; - t21 += v * b11; - t22 += v * b12; - t23 += v * b13; - t24 += v * b14; - t25 += v * b15; - v = a[11]; - t11 += v * b0; - t12 += v * b1; - t13 += v * b2; - t14 += v * b3; - t15 += v * b4; - t16 += v * b5; - t17 += v * b6; - t18 += v * b7; - t19 += v * b8; - t20 += v * b9; - t21 += v * b10; - t22 += v * b11; - t23 += v * b12; - t24 += v * b13; - t25 += v * b14; - t26 += v * b15; - v = a[12]; - t12 += v * b0; - t13 += v * b1; - t14 += v * b2; - t15 += v * b3; - t16 += v * b4; - t17 += v * b5; - t18 += v * b6; - t19 += v * b7; - t20 += v * b8; - t21 += v * b9; - t22 += v * b10; - t23 += v * b11; - t24 += v * b12; - t25 += v * b13; - t26 += v * b14; - t27 += v * b15; - v = a[13]; - t13 += v * b0; - t14 += v * b1; - t15 += v * b2; - t16 += v * b3; - t17 += v * b4; - t18 += v * b5; - t19 += v * b6; - t20 += v * b7; - t21 += v * b8; - t22 += v * b9; - t23 += v * b10; - t24 += v * b11; - t25 += v * b12; - t26 += v * b13; - t27 += v * b14; - t28 += v * b15; - v = a[14]; - t14 += v * b0; - t15 += v * b1; - t16 += v * b2; - t17 += v * b3; - t18 += v * b4; - t19 += v * b5; - t20 += v * b6; - t21 += v * b7; - t22 += v * b8; - t23 += v * b9; - t24 += v * b10; - t25 += v * b11; - t26 += v * b12; - t27 += v * b13; - t28 += v * b14; - t29 += v * b15; - v = a[15]; - t15 += v * b0; - t16 += v * b1; - t17 += v * b2; - t18 += v * b3; - t19 += v * b4; - t20 += v * b5; - t21 += v * b6; - t22 += v * b7; - t23 += v * b8; - t24 += v * b9; - t25 += v * b10; - t26 += v * b11; - t27 += v * b12; - t28 += v * b13; - t29 += v * b14; - t30 += v * b15; - - t0 += 38 * t16; - t1 += 38 * t17; - t2 += 38 * t18; - t3 += 38 * t19; - t4 += 38 * t20; - t5 += 38 * t21; - t6 += 38 * t22; - t7 += 38 * t23; - t8 += 38 * t24; - t9 += 38 * t25; - t10 += 38 * t26; - t11 += 38 * t27; - t12 += 38 * t28; - t13 += 38 * t29; - t14 += 38 * t30; - // t15 left as is - - // first car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); - - // second car - c = 1; - v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536; - v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536; - v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536; - v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536; - v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536; - v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536; - v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536; - v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536; - v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536; - v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536; - v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536; - v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536; - v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536; - v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536; - v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536; - v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536; - t0 += c-1 + 37 * (c-1); - - o[ 0] = t0; - o[ 1] = t1; - o[ 2] = t2; - o[ 3] = t3; - o[ 4] = t4; - o[ 5] = t5; - o[ 6] = t6; - o[ 7] = t7; - o[ 8] = t8; - o[ 9] = t9; - o[10] = t10; - o[11] = t11; - o[12] = t12; - o[13] = t13; - o[14] = t14; - o[15] = t15; -} - -function S(o, a) { - M(o, a, a); -} - -function inv25519(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 253; a >= 0; a--) { - S(c, c); - if(a !== 2 && a !== 4) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} - -function pow2523(o, i) { - var c = gf(); - var a; - for (a = 0; a < 16; a++) c[a] = i[a]; - for (a = 250; a >= 0; a--) { - S(c, c); - if(a !== 1) M(c, c, i); - } - for (a = 0; a < 16; a++) o[a] = c[a]; -} - -function crypto_scalarmult(q, n, p) { - var z = new Uint8Array(32); - var x = new Float64Array(80), r, i; - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(); - for (i = 0; i < 31; i++) z[i] = n[i]; - z[31]=(n[31]&127)|64; - z[0]&=248; - unpack25519(x,p); - for (i = 0; i < 16; i++) { - b[i]=x[i]; - d[i]=a[i]=c[i]=0; - } - a[0]=d[0]=1; - for (i=254; i>=0; --i) { - r=(z[i>>>3]>>>(i&7))&1; - sel25519(a,b,r); - sel25519(c,d,r); - A(e,a,c); - Z(a,a,c); - A(c,b,d); - Z(b,b,d); - S(d,e); - S(f,a); - M(a,c,a); - M(c,b,e); - A(e,a,c); - Z(a,a,c); - S(b,a); - Z(c,d,f); - M(a,c,_121665); - A(a,a,d); - M(c,c,a); - M(a,d,f); - M(d,b,x); - S(b,e); - sel25519(a,b,r); - sel25519(c,d,r); - } - for (i = 0; i < 16; i++) { - x[i+16]=a[i]; - x[i+32]=c[i]; - x[i+48]=b[i]; - x[i+64]=d[i]; - } - var x32 = x.subarray(32); - var x16 = x.subarray(16); - inv25519(x32,x32); - M(x16,x16,x32); - pack25519(q,x16); - return 0; -} - -function crypto_scalarmult_base(q, n) { - return crypto_scalarmult(q, n, _9); -} - -function crypto_box_keypair(y, x) { - randombytes(x, 32); - return crypto_scalarmult_base(y, x); -} - -function crypto_box_beforenm(k, y, x) { - var s = new Uint8Array(32); - crypto_scalarmult(s, x, y); - return crypto_core_hsalsa20(k, _0, s, sigma); -} - -var crypto_box_afternm = crypto_secretbox; -var crypto_box_open_afternm = crypto_secretbox_open; - -function crypto_box(c, m, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_afternm(c, m, d, n, k); -} - -function crypto_box_open(m, c, d, n, y, x) { - var k = new Uint8Array(32); - crypto_box_beforenm(k, y, x); - return crypto_box_open_afternm(m, c, d, n, k); -} - -var K = [ - 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, - 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, - 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, - 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, - 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, - 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, - 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, - 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, - 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, - 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, - 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, - 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, - 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, - 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, - 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, - 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, - 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, - 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, - 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, - 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, - 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, - 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, - 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, - 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, - 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, - 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, - 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, - 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, - 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, - 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, - 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, - 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, - 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, - 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, - 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, - 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, - 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, - 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, - 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, - 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 -]; - -function crypto_hashblocks_hl(hh, hl, m, n) { - var wh = new Int32Array(16), wl = new Int32Array(16), - bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, - bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, - th, tl, i, j, h, l, a, b, c, d; - - var ah0 = hh[0], - ah1 = hh[1], - ah2 = hh[2], - ah3 = hh[3], - ah4 = hh[4], - ah5 = hh[5], - ah6 = hh[6], - ah7 = hh[7], - - al0 = hl[0], - al1 = hl[1], - al2 = hl[2], - al3 = hl[3], - al4 = hl[4], - al5 = hl[5], - al6 = hl[6], - al7 = hl[7]; - - var pos = 0; - while (n >= 128) { - for (i = 0; i < 16; i++) { - j = 8 * i + pos; - wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3]; - wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7]; - } - for (i = 0; i < 80; i++) { - bh0 = ah0; - bh1 = ah1; - bh2 = ah2; - bh3 = ah3; - bh4 = ah4; - bh5 = ah5; - bh6 = ah6; - bh7 = ah7; - - bl0 = al0; - bl1 = al1; - bl2 = al2; - bl3 = al3; - bl4 = al4; - bl5 = al5; - bl6 = al6; - bl7 = al7; - - // add - h = ah7; - l = al7; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - // Sigma1 - h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32)))); - l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32)))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // Ch - h = (ah4 & ah5) ^ (~ah4 & ah6); - l = (al4 & al5) ^ (~al4 & al6); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // K - h = K[i*2]; - l = K[i*2+1]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // w - h = wh[i%16]; - l = wl[i%16]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - th = c & 0xffff | d << 16; - tl = a & 0xffff | b << 16; - - // add - h = th; - l = tl; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - // Sigma0 - h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32)))); - l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32)))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // Maj - h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2); - l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - bh7 = (c & 0xffff) | (d << 16); - bl7 = (a & 0xffff) | (b << 16); - - // add - h = bh3; - l = bl3; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = th; - l = tl; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - bh3 = (c & 0xffff) | (d << 16); - bl3 = (a & 0xffff) | (b << 16); - - ah1 = bh0; - ah2 = bh1; - ah3 = bh2; - ah4 = bh3; - ah5 = bh4; - ah6 = bh5; - ah7 = bh6; - ah0 = bh7; - - al1 = bl0; - al2 = bl1; - al3 = bl2; - al4 = bl3; - al5 = bl4; - al6 = bl5; - al7 = bl6; - al0 = bl7; - - if (i%16 === 15) { - for (j = 0; j < 16; j++) { - // add - h = wh[j]; - l = wl[j]; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = wh[(j+9)%16]; - l = wl[(j+9)%16]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // sigma0 - th = wh[(j+1)%16]; - tl = wl[(j+1)%16]; - h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7); - l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - // sigma1 - th = wh[(j+14)%16]; - tl = wl[(j+14)%16]; - h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6); - l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6))); - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; +"use strict"; - wh[j] = (c & 0xffff) | (d << 16); - wl[j] = (a & 0xffff) | (b << 16); +// Copyright (C) 2016 Dmitry Chestnykh +// MIT License. See LICENSE file for details. +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Package utf8 implements UTF-8 encoding and decoding. + */ +var INVALID_UTF16 = "utf8: invalid string"; +var INVALID_UTF8 = "utf8: invalid source encoding"; +/** + * Encodes the given string into UTF-8 byte array. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encode(s) { + // Calculate result length and allocate output array. + // encodedLength() also validates string and throws errors, + // so we don't need repeat validation here. + var arr = new Uint8Array(encodedLength(s)); + var pos = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + arr[pos++] = c; + } + else if (c < 0x800) { + arr[pos++] = 0xc0 | c >> 6; + arr[pos++] = 0x80 | c & 0x3f; + } + else if (c < 0xd800) { + arr[pos++] = 0xe0 | c >> 12; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; + } + else { + i++; // get one more character + c = (c & 0x3ff) << 10; + c |= s.charCodeAt(i) & 0x3ff; + c += 0x10000; + arr[pos++] = 0xf0 | c >> 18; + arr[pos++] = 0x80 | (c >> 12) & 0x3f; + arr[pos++] = 0x80 | (c >> 6) & 0x3f; + arr[pos++] = 0x80 | c & 0x3f; } - } } - - // add - h = ah0; - l = al0; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[0]; - l = hl[0]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[0] = ah0 = (c & 0xffff) | (d << 16); - hl[0] = al0 = (a & 0xffff) | (b << 16); - - h = ah1; - l = al1; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[1]; - l = hl[1]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[1] = ah1 = (c & 0xffff) | (d << 16); - hl[1] = al1 = (a & 0xffff) | (b << 16); - - h = ah2; - l = al2; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[2]; - l = hl[2]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[2] = ah2 = (c & 0xffff) | (d << 16); - hl[2] = al2 = (a & 0xffff) | (b << 16); - - h = ah3; - l = al3; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[3]; - l = hl[3]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[3] = ah3 = (c & 0xffff) | (d << 16); - hl[3] = al3 = (a & 0xffff) | (b << 16); - - h = ah4; - l = al4; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[4]; - l = hl[4]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[4] = ah4 = (c & 0xffff) | (d << 16); - hl[4] = al4 = (a & 0xffff) | (b << 16); - - h = ah5; - l = al5; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[5]; - l = hl[5]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[5] = ah5 = (c & 0xffff) | (d << 16); - hl[5] = al5 = (a & 0xffff) | (b << 16); - - h = ah6; - l = al6; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[6]; - l = hl[6]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[6] = ah6 = (c & 0xffff) | (d << 16); - hl[6] = al6 = (a & 0xffff) | (b << 16); - - h = ah7; - l = al7; - - a = l & 0xffff; b = l >>> 16; - c = h & 0xffff; d = h >>> 16; - - h = hh[7]; - l = hl[7]; - - a += l & 0xffff; b += l >>> 16; - c += h & 0xffff; d += h >>> 16; - - b += a >>> 16; - c += b >>> 16; - d += c >>> 16; - - hh[7] = ah7 = (c & 0xffff) | (d << 16); - hl[7] = al7 = (a & 0xffff) | (b << 16); - - pos += 128; - n -= 128; - } - - return n; -} - -function crypto_hash(out, m, n) { - var hh = new Int32Array(8), - hl = new Int32Array(8), - x = new Uint8Array(256), - i, b = n; - - hh[0] = 0x6a09e667; - hh[1] = 0xbb67ae85; - hh[2] = 0x3c6ef372; - hh[3] = 0xa54ff53a; - hh[4] = 0x510e527f; - hh[5] = 0x9b05688c; - hh[6] = 0x1f83d9ab; - hh[7] = 0x5be0cd19; - - hl[0] = 0xf3bcc908; - hl[1] = 0x84caa73b; - hl[2] = 0xfe94f82b; - hl[3] = 0x5f1d36f1; - hl[4] = 0xade682d1; - hl[5] = 0x2b3e6c1f; - hl[6] = 0xfb41bd6b; - hl[7] = 0x137e2179; - - crypto_hashblocks_hl(hh, hl, m, n); - n %= 128; - - for (i = 0; i < n; i++) x[i] = m[b-n+i]; - x[n] = 128; - - n = 256-128*(n<112?1:0); - x[n-9] = 0; - ts64(x, n-8, (b / 0x20000000) | 0, b << 3); - crypto_hashblocks_hl(hh, hl, x, n); - - for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]); - - return 0; + return arr; } - -function add(p, q) { - var a = gf(), b = gf(), c = gf(), - d = gf(), e = gf(), f = gf(), - g = gf(), h = gf(), t = gf(); - - Z(a, p[1], p[0]); - Z(t, q[1], q[0]); - M(a, a, t); - A(b, p[0], p[1]); - A(t, q[0], q[1]); - M(b, b, t); - M(c, p[3], q[3]); - M(c, c, D2); - M(d, p[2], q[2]); - A(d, d, d); - Z(e, b, a); - Z(f, d, c); - A(g, d, c); - A(h, b, a); - - M(p[0], e, f); - M(p[1], h, g); - M(p[2], g, f); - M(p[3], e, h); -} - -function cswap(p, q, b) { - var i; - for (i = 0; i < 4; i++) { - sel25519(p[i], q[i], b); - } -} - -function pack(r, p) { - var tx = gf(), ty = gf(), zi = gf(); - inv25519(zi, p[2]); - M(tx, p[0], zi); - M(ty, p[1], zi); - pack25519(r, ty); - r[31] ^= par25519(tx) << 7; -} - -function scalarmult(p, q, s) { - var b, i; - set25519(p[0], gf0); - set25519(p[1], gf1); - set25519(p[2], gf1); - set25519(p[3], gf0); - for (i = 255; i >= 0; --i) { - b = (s[(i/8)|0] >> (i&7)) & 1; - cswap(p, q, b); - add(q, p); - add(p, p); - cswap(p, q, b); - } -} - -function scalarbase(p, s) { - var q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -} - -function crypto_sign_keypair(pk, sk, seeded) { - var d = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()]; - var i; - - if (!seeded) randombytes(sk, 32); - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - scalarbase(p, d); - pack(pk, p); - - for (i = 0; i < 32; i++) sk[i+32] = pk[i]; - return 0; -} - -var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); - -function modL(r, x) { - var carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; +exports.encode = encode; +/** + * Returns the number of bytes required to encode the given string into UTF-8. + * Throws if the source string has invalid UTF-16 encoding. + */ +function encodedLength(s) { + var result = 0; + for (var i = 0; i < s.length; i++) { + var c = s.charCodeAt(i); + if (c < 0x80) { + result += 1; + } + else if (c < 0x800) { + result += 2; + } + else if (c < 0xd800) { + result += 3; + } + else if (c <= 0xdfff) { + if (i >= s.length - 1) { + throw new Error(INVALID_UTF16); + } + i++; // "eat" next character + result += 4; + } + else { + throw new Error(INVALID_UTF16); + } } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) x[j] -= carry * L[j]; - for (i = 0; i < 32; i++) { - x[i+1] += x[i] >> 8; - r[i] = x[i] & 255; - } -} - -function reduce(r) { - var x = new Float64Array(64), i; - for (i = 0; i < 64; i++) x[i] = r[i]; - for (i = 0; i < 64; i++) r[i] = 0; - modL(r, x); + return result; } - -// Note: difference from C - smlen returned, not passed as argument. -function crypto_sign(sm, m, n, sk) { - var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64); - var i, j, x = new Float64Array(64); - var p = [gf(), gf(), gf(), gf()]; - - crypto_hash(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - var smlen = n + 64; - for (i = 0; i < n; i++) sm[64 + i] = m[i]; - for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]; - - crypto_hash(r, sm.subarray(32), n+32); - reduce(r); - scalarbase(p, r); - pack(sm, p); - - for (i = 32; i < 64; i++) sm[i] = sk[i]; - crypto_hash(h, sm, n + 64); - reduce(h); - - for (i = 0; i < 64; i++) x[i] = 0; - for (i = 0; i < 32; i++) x[i] = r[i]; - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - x[i+j] += h[i] * d[j]; +exports.encodedLength = encodedLength; +/** + * Decodes the given byte array from UTF-8 into a string. + * Throws if encoding is invalid. + */ +function decode(arr) { + var chars = []; + for (var i = 0; i < arr.length; i++) { + var b = arr[i]; + if (b & 0x80) { + var min = void 0; + if (b < 0xe0) { + // Need 1 more byte. + if (i >= arr.length) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + if ((n1 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x1f) << 6 | (n1 & 0x3f); + min = 0x80; + } + else if (b < 0xf0) { + // Need 2 more bytes. + if (i >= arr.length - 1) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 12 | (n1 & 0x3f) << 6 | (n2 & 0x3f); + min = 0x800; + } + else if (b < 0xf8) { + // Need 3 more bytes. + if (i >= arr.length - 2) { + throw new Error(INVALID_UTF8); + } + var n1 = arr[++i]; + var n2 = arr[++i]; + var n3 = arr[++i]; + if ((n1 & 0xc0) !== 0x80 || (n2 & 0xc0) !== 0x80 || (n3 & 0xc0) !== 0x80) { + throw new Error(INVALID_UTF8); + } + b = (b & 0x0f) << 18 | (n1 & 0x3f) << 12 | (n2 & 0x3f) << 6 | (n3 & 0x3f); + min = 0x10000; + } + else { + throw new Error(INVALID_UTF8); + } + if (b < min || (b >= 0xd800 && b <= 0xdfff)) { + throw new Error(INVALID_UTF8); + } + if (b >= 0x10000) { + // Surrogate pair. + if (b > 0x10ffff) { + throw new Error(INVALID_UTF8); + } + b -= 0x10000; + chars.push(String.fromCharCode(0xd800 | (b >> 10))); + b = 0xdc00 | (b & 0x3ff); + } + } + chars.push(String.fromCharCode(b)); } - } - - modL(sm.subarray(32), x); - return smlen; -} - -function unpackneg(r, p) { - var t = gf(), chk = gf(), num = gf(), - den = gf(), den2 = gf(), den4 = gf(), - den6 = gf(); - - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); - - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); - - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) M(r[0], r[0], I); - - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) return -1; - - if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]); - - M(r[3], r[0], r[1]); - return 0; + return chars.join(""); } - -function crypto_sign_open(m, sm, n, pk) { - var i; - var t = new Uint8Array(32), h = new Uint8Array(64); - var p = [gf(), gf(), gf(), gf()], - q = [gf(), gf(), gf(), gf()]; - - if (n < 64) return -1; - - if (unpackneg(q, pk)) return -1; - - for (i = 0; i < n; i++) m[i] = sm[i]; - for (i = 0; i < 32; i++) m[i+32] = pk[i]; - crypto_hash(h, m, n); - reduce(h); - scalarmult(p, q, h); - - scalarbase(q, sm.subarray(32)); - add(p, q); - pack(t, p); - - n -= 64; - if (crypto_verify_32(sm, 0, t, 0)) { - for (i = 0; i < n; i++) m[i] = 0; - return -1; - } - - for (i = 0; i < n; i++) m[i] = sm[i + 64]; - return n; -} - -var crypto_secretbox_KEYBYTES = 32, - crypto_secretbox_NONCEBYTES = 24, - crypto_secretbox_ZEROBYTES = 32, - crypto_secretbox_BOXZEROBYTES = 16, - crypto_scalarmult_BYTES = 32, - crypto_scalarmult_SCALARBYTES = 32, - crypto_box_PUBLICKEYBYTES = 32, - crypto_box_SECRETKEYBYTES = 32, - crypto_box_BEFORENMBYTES = 32, - crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, - crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, - crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, - crypto_sign_BYTES = 64, - crypto_sign_PUBLICKEYBYTES = 32, - crypto_sign_SECRETKEYBYTES = 64, - crypto_sign_SEEDBYTES = 32, - crypto_hash_BYTES = 64; - -nacl.lowlevel = { - crypto_core_hsalsa20: crypto_core_hsalsa20, - crypto_stream_xor: crypto_stream_xor, - crypto_stream: crypto_stream, - crypto_stream_salsa20_xor: crypto_stream_salsa20_xor, - crypto_stream_salsa20: crypto_stream_salsa20, - crypto_onetimeauth: crypto_onetimeauth, - crypto_onetimeauth_verify: crypto_onetimeauth_verify, - crypto_verify_16: crypto_verify_16, - crypto_verify_32: crypto_verify_32, - crypto_secretbox: crypto_secretbox, - crypto_secretbox_open: crypto_secretbox_open, - crypto_scalarmult: crypto_scalarmult, - crypto_scalarmult_base: crypto_scalarmult_base, - crypto_box_beforenm: crypto_box_beforenm, - crypto_box_afternm: crypto_box_afternm, - crypto_box: crypto_box, - crypto_box_open: crypto_box_open, - crypto_box_keypair: crypto_box_keypair, - crypto_hash: crypto_hash, - crypto_sign: crypto_sign, - crypto_sign_keypair: crypto_sign_keypair, - crypto_sign_open: crypto_sign_open, - - crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES, - crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES, - crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES, - crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES, - crypto_scalarmult_BYTES: crypto_scalarmult_BYTES, - crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES, - crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES, - crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES, - crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES, - crypto_box_NONCEBYTES: crypto_box_NONCEBYTES, - crypto_box_ZEROBYTES: crypto_box_ZEROBYTES, - crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES, - crypto_sign_BYTES: crypto_sign_BYTES, - crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES, - crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES, - crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES, - crypto_hash_BYTES: crypto_hash_BYTES, - - gf: gf, - D: D, - L: L, - pack25519: pack25519, - unpack25519: unpack25519, - M: M, - A: A, - S: S, - Z: Z, - pow2523: pow2523, - add: add, - set25519: set25519, - modL: modL, - scalarmult: scalarmult, - scalarbase: scalarbase, -}; - -/* High-level API */ - -function checkLengths(k, n) { - if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size'); - if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size'); -} - -function checkBoxLengths(pk, sk) { - if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size'); - if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size'); -} - -function checkArrayTypes() { - for (var i = 0; i < arguments.length; i++) { - if (!(arguments[i] instanceof Uint8Array)) - throw new TypeError('unexpected type, use Uint8Array'); - } -} - -function cleanup(arr) { - for (var i = 0; i < arr.length; i++) arr[i] = 0; -} - -nacl.randomBytes = function(n) { - var b = new Uint8Array(n); - randombytes(b, n); - return b; -}; - -nacl.secretbox = function(msg, nonce, key) { - checkArrayTypes(msg, nonce, key); - checkLengths(key, nonce); - var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length); - var c = new Uint8Array(m.length); - for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i]; - crypto_secretbox(c, m, m.length, nonce, key); - return c.subarray(crypto_secretbox_BOXZEROBYTES); -}; - -nacl.secretbox.open = function(box, nonce, key) { - checkArrayTypes(box, nonce, key); - checkLengths(key, nonce); - var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length); - var m = new Uint8Array(c.length); - for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i]; - if (c.length < 32) return null; - if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null; - return m.subarray(crypto_secretbox_ZEROBYTES); -}; - -nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES; -nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES; -nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES; - -nacl.scalarMult = function(n, p) { - checkArrayTypes(n, p); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult(q, n, p); - return q; -}; - -nacl.scalarMult.base = function(n) { - checkArrayTypes(n); - if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size'); - var q = new Uint8Array(crypto_scalarmult_BYTES); - crypto_scalarmult_base(q, n); - return q; -}; - -nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES; -nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES; - -nacl.box = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox(msg, nonce, k); -}; - -nacl.box.before = function(publicKey, secretKey) { - checkArrayTypes(publicKey, secretKey); - checkBoxLengths(publicKey, secretKey); - var k = new Uint8Array(crypto_box_BEFORENMBYTES); - crypto_box_beforenm(k, publicKey, secretKey); - return k; -}; - -nacl.box.after = nacl.secretbox; - -nacl.box.open = function(msg, nonce, publicKey, secretKey) { - var k = nacl.box.before(publicKey, secretKey); - return nacl.secretbox.open(msg, nonce, k); -}; - -nacl.box.open.after = nacl.secretbox.open; - -nacl.box.keyPair = function() { - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_box_SECRETKEYBYTES); - crypto_box_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; - -nacl.box.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_box_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES); - crypto_scalarmult_base(pk, secretKey); - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; - -nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES; -nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES; -nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES; -nacl.box.nonceLength = crypto_box_NONCEBYTES; -nacl.box.overheadLength = nacl.secretbox.overheadLength; - -nacl.sign = function(msg, secretKey) { - checkArrayTypes(msg, secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length); - crypto_sign(signedMsg, msg, msg.length, secretKey); - return signedMsg; -}; - -nacl.sign.open = function(signedMsg, publicKey) { - checkArrayTypes(signedMsg, publicKey); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var tmp = new Uint8Array(signedMsg.length); - var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey); - if (mlen < 0) return null; - var m = new Uint8Array(mlen); - for (var i = 0; i < m.length; i++) m[i] = tmp[i]; - return m; -}; - -nacl.sign.detached = function(msg, secretKey) { - var signedMsg = nacl.sign(msg, secretKey); - var sig = new Uint8Array(crypto_sign_BYTES); - for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; - return sig; -}; - -nacl.sign.detached.verify = function(msg, sig, publicKey) { - checkArrayTypes(msg, sig, publicKey); - if (sig.length !== crypto_sign_BYTES) - throw new Error('bad signature size'); - if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) - throw new Error('bad public key size'); - var sm = new Uint8Array(crypto_sign_BYTES + msg.length); - var m = new Uint8Array(crypto_sign_BYTES + msg.length); - var i; - for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]; - for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i]; - return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); -}; - -nacl.sign.keyPair = function() { - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - crypto_sign_keypair(pk, sk); - return {publicKey: pk, secretKey: sk}; -}; - -nacl.sign.keyPair.fromSecretKey = function(secretKey) { - checkArrayTypes(secretKey); - if (secretKey.length !== crypto_sign_SECRETKEYBYTES) - throw new Error('bad secret key size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i]; - return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; -}; - -nacl.sign.keyPair.fromSeed = function(seed) { - checkArrayTypes(seed); - if (seed.length !== crypto_sign_SEEDBYTES) - throw new Error('bad seed size'); - var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); - var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); - for (var i = 0; i < 32; i++) sk[i] = seed[i]; - crypto_sign_keypair(pk, sk, true); - return {publicKey: pk, secretKey: sk}; -}; - -nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; -nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; -nacl.sign.seedLength = crypto_sign_SEEDBYTES; -nacl.sign.signatureLength = crypto_sign_BYTES; - -nacl.hash = function(msg) { - checkArrayTypes(msg); - var h = new Uint8Array(crypto_hash_BYTES); - crypto_hash(h, msg, msg.length); - return h; -}; - -nacl.hash.hashLength = crypto_hash_BYTES; - -nacl.verify = function(x, y) { - checkArrayTypes(x, y); - // Zero length arguments are considered not equal. - if (x.length === 0 || y.length === 0) return false; - if (x.length !== y.length) return false; - return (vn(x, 0, y, 0, x.length) === 0) ? true : false; -}; - -nacl.setPRNG = function(fn) { - randombytes = fn; -}; - -(function() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null; - if (crypto && crypto.getRandomValues) { - // Browsers. - var QUOTA = 65536; - nacl.setPRNG(function(x, n) { - var i, v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); - } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (true) { - // Node.js. - crypto = __webpack_require__(3); - if (crypto && crypto.randomBytes) { - nacl.setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } - } -})(); - -})( true && module.exports ? module.exports : (self.nacl = self.nacl || {})); - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -// Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri. -// Public domain. -(function(root, f) { - 'use strict'; - if ( true && module.exports) module.exports = f(); - else if (root.nacl) root.nacl.util = f(); - else { - root.nacl = {}; - root.nacl.util = f(); - } -}(this, function() { - 'use strict'; - - var util = {}; - - function validateBase64(s) { - if (!(/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(s))) { - throw new TypeError('invalid encoding'); - } - } - - util.decodeUTF8 = function(s) { - if (typeof s !== 'string') throw new TypeError('expected string'); - var i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; - - util.encodeUTF8 = function(arr) { - var i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))); - }; - - if (typeof atob === 'undefined') { - // Node.js - - if (typeof Buffer.from !== 'undefined') { - // Node v6 and later - util.encodeBase64 = function (arr) { // v6 and later - return Buffer.from(arr).toString('base64'); - }; - - util.decodeBase64 = function (s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(Buffer.from(s, 'base64'), 0)); - }; - - } else { - // Node earlier than v6 - util.encodeBase64 = function (arr) { // v6 and later - return (new Buffer(arr)).toString('base64'); - }; - - util.decodeBase64 = function(s) { - validateBase64(s); - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - }; - } - - } else { - // Browsers - - util.encodeBase64 = function(arr) { - var i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - }; - - util.decodeBase64 = function(s) { - validateBase64(s); - var i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - }; - - } - - return util; - -})); - +exports.decode = decode; +//# sourceMappingURL=utf8.js.map /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { // required so we don't have to do require('pusher').default etc. -module.exports = __webpack_require__(4).default; +module.exports = __webpack_require__(3).default; /***/ }), /* 3 */ -/***/ (function(module, exports) { - -/* (ignored) */ - -/***/ }), -/* 4 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2934,22 +887,22 @@ function safeJSONStringify(source) { // CONCATENATED MODULE: ./src/core/defaults.ts var Defaults = { - VERSION: "5.1.1", + VERSION: "6.0.0", PROTOCOL: 7, - host: 'ws.pusherapp.com', - ws_port: 80, - wss_port: 443, - ws_path: '', - sockjs_host: 'sockjs.pusher.com', - sockjs_http_port: 80, - sockjs_https_port: 443, - sockjs_path: '/pusher', + wsPort: 80, + wssPort: 443, + wsPath: '', + httpHost: 'sockjs.pusher.com', + httpPort: 80, + httpsPort: 443, + httpPath: '/pusher', stats_host: 'stats.pusher.com', - channel_auth_endpoint: '/pusher/auth', - channel_auth_transport: 'ajax', - activity_timeout: 120000, - pong_timeout: 30000, - unavailable_timeout: 10000, + authEndpoint: '/pusher/auth', + authTransport: 'ajax', + activityTimeout: 120000, + pongTimeout: 30000, + unavailableTimeout: 10000, + cluster: 'mt1', cdn_http: "http://js.pusher.com", cdn_https: "https://js.pusher.com", dependency_suffix: "" @@ -3741,7 +1694,7 @@ var pusher_authorizer_PusherAuthorizer = (function () { } this.type = authTransport; this.options = options; - this.authOptions = (options || {}).auth || {}; + this.authOptions = options.auth || {}; } PusherAuthorizer.prototype.composeQuery = function (socketId) { var query = 'socket_id=' + @@ -3887,6 +1840,9 @@ var urlStore = { }, triggeringClientEvents: { path: '/docs/client_api_guide/client_events#trigger-events' + }, + encryptedChannelSupport: { + fullUrl: 'https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support' } } }; @@ -4195,11 +2151,11 @@ var presence_channel_PresenceChannel = (function (_super) { }(private_channel)); /* harmony default export */ var presence_channel = (presence_channel_PresenceChannel); -// EXTERNAL MODULE: ./node_modules/tweetnacl/nacl-fast.js -var nacl_fast = __webpack_require__(0); +// EXTERNAL MODULE: ./node_modules/@stablelib/utf8/lib/utf8.js +var utf8 = __webpack_require__(1); -// EXTERNAL MODULE: ./node_modules/tweetnacl-util/nacl-util.js -var nacl_util = __webpack_require__(1); +// EXTERNAL MODULE: ./node_modules/@stablelib/base64/lib/base64.js +var base64 = __webpack_require__(0); // CONCATENATED MODULE: ./src/core/channels/encrypted_channel.ts var encrypted_channel_extends = (undefined && undefined.__extends) || (function () { @@ -4222,9 +2178,10 @@ var encrypted_channel_extends = (undefined && undefined.__extends) || (function var encrypted_channel_EncryptedChannel = (function (_super) { encrypted_channel_extends(EncryptedChannel, _super); - function EncryptedChannel() { - var _this = _super !== null && _super.apply(this, arguments) || this; + function EncryptedChannel(name, pusher, nacl) { + var _this = _super.call(this, name, pusher) || this; _this.key = null; + _this.nacl = nacl; return _this; } EncryptedChannel.prototype.authorize = function (socketId, callback) { @@ -4240,7 +2197,7 @@ var encrypted_channel_EncryptedChannel = (function (_super) { callback(true, errorMsg); return; } - _this.key = Object(nacl_util["decodeBase64"])(sharedSecret); + _this.key = Object(base64["decode"])(sharedSecret); delete authData['shared_secret']; callback(false, authData); }); @@ -4269,17 +2226,17 @@ var encrypted_channel_EncryptedChannel = (function (_super) { data); return; } - var cipherText = Object(nacl_util["decodeBase64"])(data.ciphertext); - if (cipherText.length < nacl_fast["secretbox"].overheadLength) { - logger.error("Expected encrypted event ciphertext length to be " + nacl_fast["secretbox"].overheadLength + ", got: " + cipherText.length); + var cipherText = Object(base64["decode"])(data.ciphertext); + if (cipherText.length < this.nacl.secretbox.overheadLength) { + logger.error("Expected encrypted event ciphertext length to be " + this.nacl.secretbox.overheadLength + ", got: " + cipherText.length); return; } - var nonce = Object(nacl_util["decodeBase64"])(data.nonce); - if (nonce.length < nacl_fast["secretbox"].nonceLength) { - logger.error("Expected encrypted event nonce length to be " + nacl_fast["secretbox"].nonceLength + ", got: " + nonce.length); + var nonce = Object(base64["decode"])(data.nonce); + if (nonce.length < this.nacl.secretbox.nonceLength) { + logger.error("Expected encrypted event nonce length to be " + this.nacl.secretbox.nonceLength + ", got: " + nonce.length); return; } - var bytes = nacl_fast["secretbox"].open(cipherText, nonce, this.key); + var bytes = this.nacl.secretbox.open(cipherText, nonce, this.key); if (bytes === null) { logger.debug('Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...'); this.authorize(this.pusher.connection.socket_id, function (error, authData) { @@ -4287,17 +2244,17 @@ var encrypted_channel_EncryptedChannel = (function (_super) { logger.error("Failed to make a request to the authEndpoint: " + authData + ". Unable to fetch new key, so dropping encrypted event"); return; } - bytes = nacl_fast["secretbox"].open(cipherText, nonce, _this.key); + bytes = _this.nacl.secretbox.open(cipherText, nonce, _this.key); if (bytes === null) { logger.error("Failed to decrypt event with new key. Dropping encrypted event"); return; } - _this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + _this.emitJSON(event, Object(utf8["decode"])(bytes)); return; }); return; } - this.emitJSON(event, Object(nacl_util["encodeUTF8"])(bytes)); + this.emitJSON(event, Object(utf8["decode"])(bytes)); }; EncryptedChannel.prototype.emitJSON = function (eventName, data) { try { @@ -4335,12 +2292,12 @@ var connection_manager_ConnectionManager = (function (_super) { connection_manager_extends(ConnectionManager, _super); function ConnectionManager(key, options) { var _this = _super.call(this) || this; - _this.key = key; - _this.options = options || {}; _this.state = 'initialized'; _this.connection = null; - _this.usingTLS = !!options.useTLS; + _this.key = key; + _this.options = options; _this.timeline = _this.options.timeline; + _this.usingTLS = _this.options.useTLS; _this.errorCallbacks = _this.buildErrorCallbacks(); _this.connectionCallbacks = _this.buildConnectionCallbacks(_this.errorCallbacks); _this.handshakeCallbacks = _this.buildHandshakeCallbacks(_this.errorCallbacks); @@ -4597,6 +2554,7 @@ var connection_manager_ConnectionManager = (function (_super) { + var channels_Channels = (function () { function Channels() { this.channels = {}; @@ -4628,8 +2586,12 @@ var channels_Channels = (function () { /* harmony default export */ var channels = (channels_Channels); function createChannel(name, pusher) { if (name.indexOf('private-encrypted-') === 0) { - if (false) { var errorMsg; } - return factory.createEncryptedChannel(name, pusher); + if (pusher.config.nacl) { + return factory.createEncryptedChannel(name, pusher, pusher.config.nacl); + } + var errMsg = 'Tried to subscribe to a private-encrypted- channel but no nacl implementation available'; + var suffix = url_store.buildLogSuffix('encryptedChannelSupport'); + throw new UnsupportedFeature(errMsg + ". " + suffix); } else if (name.indexOf('private-') === 0) { return factory.createPrivateChannel(name, pusher); @@ -4669,8 +2631,8 @@ var Factory = { createPresenceChannel: function (name, pusher) { return new presence_channel(name, pusher); }, - createEncryptedChannel: function (name, pusher) { - return new encrypted_channel(name, pusher); + createEncryptedChannel: function (name, pusher, nacl) { + return new encrypted_channel(name, pusher, nacl); }, createTimelineSender: function (timeline, options) { return new timeline_sender(timeline, options); @@ -5062,26 +3024,26 @@ function testSupportsStrategy(strategy) { return strategy.isSupported(); }; } -var getDefaultStrategy = function (config, defineTransport) { +var getDefaultStrategy = function (config, baseOptions, defineTransport) { var definedTransports = {}; function defineTransportStrategy(name, type, priority, options, manager) { var transport = defineTransport(config, name, type, priority, options, manager); definedTransports[name] = transport; return transport; } - var ws_options = { + var ws_options = Object.assign({}, baseOptions, { hostNonTLS: config.wsHost + ':' + config.wsPort, hostTLS: config.wsHost + ':' + config.wssPort, httpPath: config.wsPath - }; + }); var wss_options = extend({}, ws_options, { useTLS: true }); - var http_options = { + var http_options = Object.assign({}, baseOptions, { hostNonTLS: config.httpHost + ':' + config.httpPort, hostTLS: config.httpHost + ':' + config.httpsPort, httpPath: config.httpPath - }; + }); var timeouts = { loop: true, timeout: 15000, @@ -5090,12 +3052,12 @@ var getDefaultStrategy = function (config, defineTransport) { var ws_manager = new transport_manager({ lives: 2, minPingDelay: 10000, - maxPingDelay: config.activity_timeout + maxPingDelay: config.activityTimeout }); var streaming_manager = new transport_manager({ lives: 2, minPingDelay: 10000, - maxPingDelay: config.activity_timeout + maxPingDelay: config.activityTimeout }); var ws_transport = defineTransportStrategy('ws', 'ws', 3, ws_options, ws_manager); var wss_transport = defineTransportStrategy('wss', 'ws', 3, wss_options, ws_manager); @@ -5112,7 +3074,7 @@ var getDefaultStrategy = function (config, defineTransport) { ]), polling_loop) ], timeouts); var wsStrategy; - if (config.useTLS) { + if (baseOptions.useTLS) { wsStrategy = new best_connected_ever_strategy([ ws_loop, new delayed_strategy(http_loop, { delay: 2000 }) @@ -5127,8 +3089,8 @@ var getDefaultStrategy = function (config, defineTransport) { } return new cached_strategy(new first_connected_strategy(new if_strategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, { ttl: 1800000, - timeline: config.timeline, - useTLS: config.useTLS + timeline: baseOptions.timeline, + useTLS: baseOptions.useTLS }); }; /* harmony default export */ var default_strategy = (getDefaultStrategy); @@ -5886,12 +3848,8 @@ var strategy_builder_defineTransport = function (config, name, type, priority, o arrayIndexOf(config.disabledTransports, name) === -1); var transport; if (enabled) { - transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, extend({ - key: config.key, - useTLS: config.useTLS, - timeline: config.timeline, - ignoreNullOrigin: config.ignoreNullOrigin - }, options)); + options = Object.assign({ ignoreNullOrigin: config.ignoreNullOrigin }, options); + transport = new transport_strategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options); } else { transport = strategy_builder_UnsupportedStrategy; @@ -5917,30 +3875,83 @@ var strategy_builder_UnsupportedStrategy = { // CONCATENATED MODULE: ./src/core/config.ts -var getGlobalConfig = function () { - return { - wsHost: defaults.host, - wsPort: defaults.ws_port, - wssPort: defaults.wss_port, - wsPath: defaults.ws_path, - httpHost: defaults.sockjs_host, - httpPort: defaults.sockjs_http_port, - httpsPort: defaults.sockjs_https_port, - httpPath: defaults.sockjs_path, - statsHost: defaults.stats_host, - authEndpoint: defaults.channel_auth_endpoint, - authTransport: defaults.channel_auth_transport, - activity_timeout: defaults.activity_timeout, - pong_timeout: defaults.pong_timeout, - unavailable_timeout: defaults.unavailable_timeout - }; -}; -var getClusterConfig = function (clusterName) { - return { - wsHost: 'ws-' + clusterName + '.pusher.com', - httpHost: 'sockjs-' + clusterName + '.pusher.com' - }; -}; + +function getConfig(opts) { + var config = { + activityTimeout: opts.activityTimeout || defaults.activityTimeout, + authEndpoint: opts.authEndpoint || defaults.authEndpoint, + authTransport: opts.authTransport || defaults.authTransport, + cluster: opts.cluster || defaults.cluster, + httpPath: opts.httpPath || defaults.httpPath, + httpPort: opts.httpPort || defaults.httpPort, + httpsPort: opts.httpsPort || defaults.httpsPort, + pongTimeout: opts.pongTimeout || defaults.pongTimeout, + statsHost: opts.statsHost || defaults.stats_host, + unavailableTimeout: opts.unavailableTimeout || defaults.unavailableTimeout, + wsPath: opts.wsPath || defaults.wsPath, + wsPort: opts.wsPort || defaults.wsPort, + wssPort: opts.wssPort || defaults.wssPort, + enableStats: getEnableStatsConfig(opts), + httpHost: getHttpHost(opts), + useTLS: shouldUseTLS(opts), + wsHost: getWebsocketHost(opts) + }; + if ('auth' in opts) + config.auth = opts.auth; + if ('authorizer' in opts) + config.authorizer = opts.authorizer; + if ('disabledTransports' in opts) + config.disabledTransports = opts.disabledTransports; + if ('enabledTransports' in opts) + config.enabledTransports = opts.enabledTransports; + if ('ignoreNullOrigin' in opts) + config.ignoreNullOrigin = opts.ignoreNullOrigin; + if ('timelineParams' in opts) + config.timelineParams = opts.timelineParams; + if ('nacl' in opts) { + config.nacl = opts.nacl; + } + return config; +} +function getHttpHost(opts) { + if (opts.httpHost) { + return opts.httpHost; + } + if (opts.cluster) { + return "sockjs-" + opts.cluster + ".pusher.com"; + } + return defaults.httpHost; +} +function getWebsocketHost(opts) { + if (opts.wsHost) { + return opts.wsHost; + } + if (opts.cluster) { + return getWebsocketHostFromCluster(opts.cluster); + } + return getWebsocketHostFromCluster(defaults.cluster); +} +function getWebsocketHostFromCluster(cluster) { + return "ws-" + cluster + ".pusher.com"; +} +function shouldUseTLS(opts) { + if (worker_runtime.getProtocol() === 'https:') { + return true; + } + else if (opts.forceTLS === false) { + return false; + } + return true; +} +function getEnableStatsConfig(opts) { + if ('enableStats' in opts) { + return opts.enableStats; + } + if ('disableStats' in opts) { + return !opts.disableStats; + } + return false; +} // CONCATENATED MODULE: ./src/core/pusher.ts @@ -5966,12 +3977,9 @@ var pusher_Pusher = (function () { } if ('disableStats' in options) { logger.warn('The disableStats option is deprecated in favor of enableStats'); - if (!('enableStats' in options)) { - options.enableStats = !options.disableStats; - } } this.key = app_key; - this.config = extend(getGlobalConfig(), options.cluster ? getClusterConfig(options.cluster) : {}, options); + this.config = getConfig(options); this.channels = factory.createChannels(); this.global_emitter = new dispatcher(); this.sessionID = Math.floor(Math.random() * 1000000000); @@ -5990,16 +3998,16 @@ var pusher_Pusher = (function () { }); } var getStrategy = function (options) { - var config = extend({}, _this.config, options); - return worker_runtime.getDefaultStrategy(config, strategy_builder_defineTransport); + return worker_runtime.getDefaultStrategy(_this.config, options, strategy_builder_defineTransport); }; - this.connection = factory.createConnectionManager(this.key, extend({ + this.connection = factory.createConnectionManager(this.key, { getStrategy: getStrategy, timeline: this.timeline, - activityTimeout: this.config.activity_timeout, - pongTimeout: this.config.pong_timeout, - unavailableTimeout: this.config.unavailable_timeout - }, this.config, { useTLS: this.shouldUseTLS() })); + activityTimeout: this.config.activityTimeout, + pongTimeout: this.config.pongTimeout, + unavailableTimeout: this.config.unavailableTimeout, + useTLS: Boolean(this.config.useTLS) + }); this.connection.bind('connected', function () { _this.subscribeAll(); if (_this.timelineSender) { @@ -6125,15 +4133,7 @@ var pusher_Pusher = (function () { return this.connection.send_event(event_name, data, channel); }; Pusher.prototype.shouldUseTLS = function () { - if (worker_runtime.getProtocol() === 'https:') { - return true; - } - else if (this.config.forceTLS === true) { - return true; - } - else { - return Boolean(this.config.encrypted); - } + return this.config.useTLS; }; Pusher.instances = []; Pusher.isReady = false; diff --git a/dist/worker/pusher.worker.min.js b/dist/worker/pusher.worker.min.js index 709940b9b..8fa55993d 100644 --- a/dist/worker/pusher.worker.min.js +++ b/dist/worker/pusher.worker.min.js @@ -1,8 +1,8 @@ /*! - * Pusher JavaScript Library v5.1.1 + * Pusher JavaScript Library v6.0.0 * https://pusher.com/ * * Copyright 2017, Pusher * Released under the MIT licence. */ -var Pusher=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){!function(t){"use strict";var e=function(t){var e,n=new Float64Array(16);if(t)for(e=0;e>24&255,t[e+1]=n>>16&255,t[e+2]=n>>8&255,t[e+3]=255&n,t[e+4]=r>>24&255,t[e+5]=r>>16&255,t[e+6]=r>>8&255,t[e+7]=255&r}function y(t,e,n,r,o){var i,s=0;for(i=0;i>>8)-1}function b(t,e,n,r){return y(t,e,n,r,16)}function v(t,e,n,r){return y(t,e,n,r,32)}function g(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,p=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,b=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=i,S=s,k=c,T=a,O=u,C=h,A=f,P=p,E=l,x=d,L=y,U=b,M=v,R=g,j=m,I=_,N=0;N<20;N+=2)w^=(o=(M^=(o=(E^=(o=(O^=(o=w+M|0)<<7|o>>>25)+w|0)<<9|o>>>23)+O|0)<<13|o>>>19)+E|0)<<18|o>>>14,C^=(o=(S^=(o=(R^=(o=(x^=(o=C+S|0)<<7|o>>>25)+C|0)<<9|o>>>23)+x|0)<<13|o>>>19)+R|0)<<18|o>>>14,L^=(o=(A^=(o=(k^=(o=(j^=(o=L+A|0)<<7|o>>>25)+L|0)<<9|o>>>23)+j|0)<<13|o>>>19)+k|0)<<18|o>>>14,I^=(o=(U^=(o=(P^=(o=(T^=(o=I+U|0)<<7|o>>>25)+I|0)<<9|o>>>23)+T|0)<<13|o>>>19)+P|0)<<18|o>>>14,w^=(o=(T^=(o=(k^=(o=(S^=(o=w+T|0)<<7|o>>>25)+w|0)<<9|o>>>23)+S|0)<<13|o>>>19)+k|0)<<18|o>>>14,C^=(o=(O^=(o=(P^=(o=(A^=(o=C+O|0)<<7|o>>>25)+C|0)<<9|o>>>23)+A|0)<<13|o>>>19)+P|0)<<18|o>>>14,L^=(o=(x^=(o=(E^=(o=(U^=(o=L+x|0)<<7|o>>>25)+L|0)<<9|o>>>23)+U|0)<<13|o>>>19)+E|0)<<18|o>>>14,I^=(o=(j^=(o=(R^=(o=(M^=(o=I+j|0)<<7|o>>>25)+I|0)<<9|o>>>23)+M|0)<<13|o>>>19)+R|0)<<18|o>>>14;w=w+i|0,S=S+s|0,k=k+c|0,T=T+a|0,O=O+u|0,C=C+h|0,A=A+f|0,P=P+p|0,E=E+l|0,x=x+d|0,L=L+y|0,U=U+b|0,M=M+v|0,R=R+g|0,j=j+m|0,I=I+_|0,t[0]=w>>>0&255,t[1]=w>>>8&255,t[2]=w>>>16&255,t[3]=w>>>24&255,t[4]=S>>>0&255,t[5]=S>>>8&255,t[6]=S>>>16&255,t[7]=S>>>24&255,t[8]=k>>>0&255,t[9]=k>>>8&255,t[10]=k>>>16&255,t[11]=k>>>24&255,t[12]=T>>>0&255,t[13]=T>>>8&255,t[14]=T>>>16&255,t[15]=T>>>24&255,t[16]=O>>>0&255,t[17]=O>>>8&255,t[18]=O>>>16&255,t[19]=O>>>24&255,t[20]=C>>>0&255,t[21]=C>>>8&255,t[22]=C>>>16&255,t[23]=C>>>24&255,t[24]=A>>>0&255,t[25]=A>>>8&255,t[26]=A>>>16&255,t[27]=A>>>24&255,t[28]=P>>>0&255,t[29]=P>>>8&255,t[30]=P>>>16&255,t[31]=P>>>24&255,t[32]=E>>>0&255,t[33]=E>>>8&255,t[34]=E>>>16&255,t[35]=E>>>24&255,t[36]=x>>>0&255,t[37]=x>>>8&255,t[38]=x>>>16&255,t[39]=x>>>24&255,t[40]=L>>>0&255,t[41]=L>>>8&255,t[42]=L>>>16&255,t[43]=L>>>24&255,t[44]=U>>>0&255,t[45]=U>>>8&255,t[46]=U>>>16&255,t[47]=U>>>24&255,t[48]=M>>>0&255,t[49]=M>>>8&255,t[50]=M>>>16&255,t[51]=M>>>24&255,t[52]=R>>>0&255,t[53]=R>>>8&255,t[54]=R>>>16&255,t[55]=R>>>24&255,t[56]=j>>>0&255,t[57]=j>>>8&255,t[58]=j>>>16&255,t[59]=j>>>24&255,t[60]=I>>>0&255,t[61]=I>>>8&255,t[62]=I>>>16&255,t[63]=I>>>24&255}(t,e,n,r)}function m(t,e,n,r){!function(t,e,n,r){for(var o,i=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,s=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,c=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,a=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,h=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,p=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,l=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,d=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,b=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,v=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,m=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,w=0;w<20;w+=2)i^=(o=(v^=(o=(l^=(o=(u^=(o=i+v|0)<<7|o>>>25)+i|0)<<9|o>>>23)+u|0)<<13|o>>>19)+l|0)<<18|o>>>14,h^=(o=(s^=(o=(g^=(o=(d^=(o=h+s|0)<<7|o>>>25)+h|0)<<9|o>>>23)+d|0)<<13|o>>>19)+g|0)<<18|o>>>14,y^=(o=(f^=(o=(c^=(o=(m^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+m|0)<<13|o>>>19)+c|0)<<18|o>>>14,_^=(o=(b^=(o=(p^=(o=(a^=(o=_+b|0)<<7|o>>>25)+_|0)<<9|o>>>23)+a|0)<<13|o>>>19)+p|0)<<18|o>>>14,i^=(o=(a^=(o=(c^=(o=(s^=(o=i+a|0)<<7|o>>>25)+i|0)<<9|o>>>23)+s|0)<<13|o>>>19)+c|0)<<18|o>>>14,h^=(o=(u^=(o=(p^=(o=(f^=(o=h+u|0)<<7|o>>>25)+h|0)<<9|o>>>23)+f|0)<<13|o>>>19)+p|0)<<18|o>>>14,y^=(o=(d^=(o=(l^=(o=(b^=(o=y+d|0)<<7|o>>>25)+y|0)<<9|o>>>23)+b|0)<<13|o>>>19)+l|0)<<18|o>>>14,_^=(o=(m^=(o=(g^=(o=(v^=(o=_+m|0)<<7|o>>>25)+_|0)<<9|o>>>23)+v|0)<<13|o>>>19)+g|0)<<18|o>>>14;t[0]=i>>>0&255,t[1]=i>>>8&255,t[2]=i>>>16&255,t[3]=i>>>24&255,t[4]=h>>>0&255,t[5]=h>>>8&255,t[6]=h>>>16&255,t[7]=h>>>24&255,t[8]=y>>>0&255,t[9]=y>>>8&255,t[10]=y>>>16&255,t[11]=y>>>24&255,t[12]=_>>>0&255,t[13]=_>>>8&255,t[14]=_>>>16&255,t[15]=_>>>24&255,t[16]=f>>>0&255,t[17]=f>>>8&255,t[18]=f>>>16&255,t[19]=f>>>24&255,t[20]=p>>>0&255,t[21]=p>>>8&255,t[22]=p>>>16&255,t[23]=p>>>24&255,t[24]=l>>>0&255,t[25]=l>>>8&255,t[26]=l>>>16&255,t[27]=l>>>24&255,t[28]=d>>>0&255,t[29]=d>>>8&255,t[30]=d>>>16&255,t[31]=d>>>24&255}(t,e,n,r)}var _=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function w(t,e,n,r,o,i,s){var c,a,u=new Uint8Array(16),h=new Uint8Array(64);for(a=0;a<16;a++)u[a]=0;for(a=0;a<8;a++)u[a]=i[a];for(;o>=64;){for(g(h,u,s,_),a=0;a<64;a++)t[e+a]=n[r+a]^h[a];for(c=1,a=8;a<16;a++)c=c+(255&u[a])|0,u[a]=255&c,c>>>=8;o-=64,e+=64,r+=64}if(o>0)for(g(h,u,s,_),a=0;a=64;){for(g(a,c,o,_),s=0;s<64;s++)t[e+s]=a[s];for(i=1,s=8;s<16;s++)i=i+(255&c[s])|0,c[s]=255&i,i>>>=8;n-=64,e+=64}if(n>0)for(g(a,c,o,_),s=0;s>>13|n<<3),r=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(r>>>7|o<<9),i=255&t[8]|(255&t[9])<<8,this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,s=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(i>>>14|s<<2),c=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(s>>>11|c<<5),a=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(c>>>8|a<<8),this.r[9]=a>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function C(t,e,n,r,o,i){var s=new O(i);return s.update(n,r,o),s.finish(t,e),0}function A(t,e,n,r,o,i){var s=new Uint8Array(16);return C(s,0,n,r,o,i),b(t,e,s,0)}function P(t,e,n,r,o){var i;if(n<32)return-1;for(T(t,0,e,0,n,r,o),C(t,16,t,32,n-32,t),i=0;i<16;i++)t[i]=0;return 0}function E(t,e,n,r,o){var i,s=new Uint8Array(32);if(n<32)return-1;if(k(s,0,32,r,o),0!==A(e,16,e,32,n-32,s))return-1;for(T(t,0,e,0,n,r,o),i=0;i<32;i++)t[i]=0;return 0}function x(t,e){var n;for(n=0;n<16;n++)t[n]=0|e[n]}function L(t){var e,n,r=1;for(e=0;e<16;e++)n=t[e]+r+65535,r=Math.floor(n/65536),t[e]=n-65536*r;t[0]+=r-1+37*(r-1)}function U(t,e,n){for(var r,o=~(n-1),i=0;i<16;i++)r=o&(t[i]^e[i]),t[i]^=r,e[i]^=r}function M(t,n){var r,o,i,s=e(),c=e();for(r=0;r<16;r++)c[r]=n[r];for(L(c),L(c),L(c),o=0;o<2;o++){for(s[0]=c[0]-65517,r=1;r<15;r++)s[r]=c[r]-65535-(s[r-1]>>16&1),s[r-1]&=65535;s[15]=c[15]-32767-(s[14]>>16&1),i=s[15]>>16&1,s[14]&=65535,U(c,s,1-i)}for(r=0;r<16;r++)t[2*r]=255&c[r],t[2*r+1]=c[r]>>8}function R(t,e){var n=new Uint8Array(32),r=new Uint8Array(32);return M(n,t),M(r,e),v(n,0,r,0)}function j(t){var e=new Uint8Array(32);return M(e,t),1&e[0]}function I(t,e){var n;for(n=0;n<16;n++)t[n]=e[2*n]+(e[2*n+1]<<8);t[15]&=32767}function N(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]+n[r]}function B(t,e,n){for(var r=0;r<16;r++)t[r]=e[r]-n[r]}function z(t,e,n){var r,o,i=0,s=0,c=0,a=0,u=0,h=0,f=0,p=0,l=0,d=0,y=0,b=0,v=0,g=0,m=0,_=0,w=0,S=0,k=0,T=0,O=0,C=0,A=0,P=0,E=0,x=0,L=0,U=0,M=0,R=0,j=0,I=n[0],N=n[1],B=n[2],z=n[3],D=n[4],H=n[5],F=n[6],q=n[7],Y=n[8],K=n[9],J=n[10],W=n[11],X=n[12],G=n[13],Z=n[14],V=n[15];i+=(r=e[0])*I,s+=r*N,c+=r*B,a+=r*z,u+=r*D,h+=r*H,f+=r*F,p+=r*q,l+=r*Y,d+=r*K,y+=r*J,b+=r*W,v+=r*X,g+=r*G,m+=r*Z,_+=r*V,s+=(r=e[1])*I,c+=r*N,a+=r*B,u+=r*z,h+=r*D,f+=r*H,p+=r*F,l+=r*q,d+=r*Y,y+=r*K,b+=r*J,v+=r*W,g+=r*X,m+=r*G,_+=r*Z,w+=r*V,c+=(r=e[2])*I,a+=r*N,u+=r*B,h+=r*z,f+=r*D,p+=r*H,l+=r*F,d+=r*q,y+=r*Y,b+=r*K,v+=r*J,g+=r*W,m+=r*X,_+=r*G,w+=r*Z,S+=r*V,a+=(r=e[3])*I,u+=r*N,h+=r*B,f+=r*z,p+=r*D,l+=r*H,d+=r*F,y+=r*q,b+=r*Y,v+=r*K,g+=r*J,m+=r*W,_+=r*X,w+=r*G,S+=r*Z,k+=r*V,u+=(r=e[4])*I,h+=r*N,f+=r*B,p+=r*z,l+=r*D,d+=r*H,y+=r*F,b+=r*q,v+=r*Y,g+=r*K,m+=r*J,_+=r*W,w+=r*X,S+=r*G,k+=r*Z,T+=r*V,h+=(r=e[5])*I,f+=r*N,p+=r*B,l+=r*z,d+=r*D,y+=r*H,b+=r*F,v+=r*q,g+=r*Y,m+=r*K,_+=r*J,w+=r*W,S+=r*X,k+=r*G,T+=r*Z,O+=r*V,f+=(r=e[6])*I,p+=r*N,l+=r*B,d+=r*z,y+=r*D,b+=r*H,v+=r*F,g+=r*q,m+=r*Y,_+=r*K,w+=r*J,S+=r*W,k+=r*X,T+=r*G,O+=r*Z,C+=r*V,p+=(r=e[7])*I,l+=r*N,d+=r*B,y+=r*z,b+=r*D,v+=r*H,g+=r*F,m+=r*q,_+=r*Y,w+=r*K,S+=r*J,k+=r*W,T+=r*X,O+=r*G,C+=r*Z,A+=r*V,l+=(r=e[8])*I,d+=r*N,y+=r*B,b+=r*z,v+=r*D,g+=r*H,m+=r*F,_+=r*q,w+=r*Y,S+=r*K,k+=r*J,T+=r*W,O+=r*X,C+=r*G,A+=r*Z,P+=r*V,d+=(r=e[9])*I,y+=r*N,b+=r*B,v+=r*z,g+=r*D,m+=r*H,_+=r*F,w+=r*q,S+=r*Y,k+=r*K,T+=r*J,O+=r*W,C+=r*X,A+=r*G,P+=r*Z,E+=r*V,y+=(r=e[10])*I,b+=r*N,v+=r*B,g+=r*z,m+=r*D,_+=r*H,w+=r*F,S+=r*q,k+=r*Y,T+=r*K,O+=r*J,C+=r*W,A+=r*X,P+=r*G,E+=r*Z,x+=r*V,b+=(r=e[11])*I,v+=r*N,g+=r*B,m+=r*z,_+=r*D,w+=r*H,S+=r*F,k+=r*q,T+=r*Y,O+=r*K,C+=r*J,A+=r*W,P+=r*X,E+=r*G,x+=r*Z,L+=r*V,v+=(r=e[12])*I,g+=r*N,m+=r*B,_+=r*z,w+=r*D,S+=r*H,k+=r*F,T+=r*q,O+=r*Y,C+=r*K,A+=r*J,P+=r*W,E+=r*X,x+=r*G,L+=r*Z,U+=r*V,g+=(r=e[13])*I,m+=r*N,_+=r*B,w+=r*z,S+=r*D,k+=r*H,T+=r*F,O+=r*q,C+=r*Y,A+=r*K,P+=r*J,E+=r*W,x+=r*X,L+=r*G,U+=r*Z,M+=r*V,m+=(r=e[14])*I,_+=r*N,w+=r*B,S+=r*z,k+=r*D,T+=r*H,O+=r*F,C+=r*q,A+=r*Y,P+=r*K,E+=r*J,x+=r*W,L+=r*X,U+=r*G,M+=r*Z,R+=r*V,_+=(r=e[15])*I,s+=38*(S+=r*B),c+=38*(k+=r*z),a+=38*(T+=r*D),u+=38*(O+=r*H),h+=38*(C+=r*F),f+=38*(A+=r*q),p+=38*(P+=r*Y),l+=38*(E+=r*K),d+=38*(x+=r*J),y+=38*(L+=r*W),b+=38*(U+=r*X),v+=38*(M+=r*G),g+=38*(R+=r*Z),m+=38*(j+=r*V),i=(r=(i+=38*(w+=r*N))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i=(r=(i+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=a+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),_=(r=_+o+65535)-65536*(o=Math.floor(r/65536)),i+=o-1+37*(o-1),t[0]=i,t[1]=s,t[2]=c,t[3]=a,t[4]=u,t[5]=h,t[6]=f,t[7]=p,t[8]=l,t[9]=d,t[10]=y,t[11]=b,t[12]=v,t[13]=g,t[14]=m,t[15]=_}function D(t,e){z(t,e,e)}function H(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)D(o,o),2!==r&&4!==r&&z(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function F(t,n){var r,o=e();for(r=0;r<16;r++)o[r]=n[r];for(r=250;r>=0;r--)D(o,o),1!==r&&z(o,o,n);for(r=0;r<16;r++)t[r]=o[r]}function q(t,n,r){var o,i,s=new Uint8Array(32),c=new Float64Array(80),u=e(),h=e(),f=e(),p=e(),l=e(),d=e();for(i=0;i<31;i++)s[i]=n[i];for(s[31]=127&n[31]|64,s[0]&=248,I(c,r),i=0;i<16;i++)h[i]=c[i],p[i]=u[i]=f[i]=0;for(u[0]=p[0]=1,i=254;i>=0;--i)U(u,h,o=s[i>>>3]>>>(7&i)&1),U(f,p,o),N(l,u,f),B(u,u,f),N(f,h,p),B(h,h,p),D(p,l),D(d,u),z(u,f,u),z(f,h,l),N(l,u,f),B(u,u,f),D(h,u),B(f,p,d),z(u,f,a),N(u,u,p),z(f,f,u),z(u,p,d),z(p,h,c),D(h,l),U(u,h,o),U(f,p,o);for(i=0;i<16;i++)c[i+16]=u[i],c[i+32]=f[i],c[i+48]=h[i],c[i+64]=p[i];var y=c.subarray(32),b=c.subarray(16);return H(y,y),z(b,b,y),M(t,b),0}function Y(t,e){return q(t,e,i)}function K(t,e){return r(e,32),Y(t,e)}function J(t,e,n){var r=new Uint8Array(32);return q(r,n,e),m(t,o,r,_)}O.prototype.blocks=function(t,e,n){for(var r,o,i,s,c,a,u,h,f,p,l,d,y,b,v,g,m,_,w,S=this.fin?0:2048,k=this.h[0],T=this.h[1],O=this.h[2],C=this.h[3],A=this.h[4],P=this.h[5],E=this.h[6],x=this.h[7],L=this.h[8],U=this.h[9],M=this.r[0],R=this.r[1],j=this.r[2],I=this.r[3],N=this.r[4],B=this.r[5],z=this.r[6],D=this.r[7],H=this.r[8],F=this.r[9];n>=16;)p=f=0,p+=(k+=8191&(r=255&t[e+0]|(255&t[e+1])<<8))*M,p+=(T+=8191&(r>>>13|(o=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*F),p+=(O+=8191&(o>>>10|(i=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*H),p+=(C+=8191&(i>>>7|(s=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*D),f=(p+=(A+=8191&(s>>>4|(c=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*z))>>>13,p&=8191,p+=(P+=c>>>1&8191)*(5*B),p+=(E+=8191&(c>>>14|(a=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*N),p+=(x+=8191&(a>>>11|(u=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*I),p+=(L+=8191&(u>>>8|(h=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*j),l=f+=(p+=(U+=h>>>5|S)*(5*R))>>>13,l+=k*R,l+=T*M,l+=O*(5*F),l+=C*(5*H),f=(l+=A*(5*D))>>>13,l&=8191,l+=P*(5*z),l+=E*(5*B),l+=x*(5*N),l+=L*(5*I),f+=(l+=U*(5*j))>>>13,l&=8191,d=f,d+=k*j,d+=T*R,d+=O*M,d+=C*(5*F),f=(d+=A*(5*H))>>>13,d&=8191,d+=P*(5*D),d+=E*(5*z),d+=x*(5*B),d+=L*(5*N),y=f+=(d+=U*(5*I))>>>13,y+=k*I,y+=T*j,y+=O*R,y+=C*M,f=(y+=A*(5*F))>>>13,y&=8191,y+=P*(5*H),y+=E*(5*D),y+=x*(5*z),y+=L*(5*B),b=f+=(y+=U*(5*N))>>>13,b+=k*N,b+=T*I,b+=O*j,b+=C*R,f=(b+=A*M)>>>13,b&=8191,b+=P*(5*F),b+=E*(5*H),b+=x*(5*D),b+=L*(5*z),v=f+=(b+=U*(5*B))>>>13,v+=k*B,v+=T*N,v+=O*I,v+=C*j,f=(v+=A*R)>>>13,v&=8191,v+=P*M,v+=E*(5*F),v+=x*(5*H),v+=L*(5*D),g=f+=(v+=U*(5*z))>>>13,g+=k*z,g+=T*B,g+=O*N,g+=C*I,f=(g+=A*j)>>>13,g&=8191,g+=P*R,g+=E*M,g+=x*(5*F),g+=L*(5*H),m=f+=(g+=U*(5*D))>>>13,m+=k*D,m+=T*z,m+=O*B,m+=C*N,f=(m+=A*I)>>>13,m&=8191,m+=P*j,m+=E*R,m+=x*M,m+=L*(5*F),_=f+=(m+=U*(5*H))>>>13,_+=k*H,_+=T*D,_+=O*z,_+=C*B,f=(_+=A*N)>>>13,_&=8191,_+=P*I,_+=E*j,_+=x*R,_+=L*M,w=f+=(_+=U*(5*F))>>>13,w+=k*F,w+=T*H,w+=O*D,w+=C*z,f=(w+=A*B)>>>13,w&=8191,w+=P*N,w+=E*I,w+=x*j,w+=L*R,k=p=8191&(f=(f=((f+=(w+=U*M)>>>13)<<2)+f|0)+(p&=8191)|0),T=l+=f>>>=13,O=d&=8191,C=y&=8191,A=b&=8191,P=v&=8191,E=g&=8191,x=m&=8191,L=_&=8191,U=w&=8191,e+=16,n-=16;this.h[0]=k,this.h[1]=T,this.h[2]=O,this.h[3]=C,this.h[4]=A,this.h[5]=P,this.h[6]=E,this.h[7]=x,this.h[8]=L,this.h[9]=U},O.prototype.finish=function(t,e){var n,r,o,i,s=new Uint16Array(10);if(this.leftover){for(i=this.leftover,this.buffer[i++]=1;i<16;i++)this.buffer[i]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,i=2;i<10;i++)this.h[i]+=n,n=this.h[i]>>>13,this.h[i]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,s[0]=this.h[0]+5,n=s[0]>>>13,s[0]&=8191,i=1;i<10;i++)s[i]=this.h[i]+n,n=s[i]>>>13,s[i]&=8191;for(s[9]-=8192,r=(1^n)-1,i=0;i<10;i++)s[i]&=r;for(r=~r,i=0;i<10;i++)this.h[i]=this.h[i]&r|s[i];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,i=1;i<8;i++)o=(this.h[i]+this.pad[i]|0)+(o>>>16)|0,this.h[i]=65535&o;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},O.prototype.update=function(t,e,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r=16&&(o=n-n%16,this.blocks(t,e,o),e+=o,n-=o),n){for(r=0;r=128;){for(S=0;S<16;S++)k=8*S+X,x[S]=n[k+0]<<24|n[k+1]<<16|n[k+2]<<8|n[k+3],L[S]=n[k+4]<<24|n[k+5]<<16|n[k+6]<<8|n[k+7];for(S=0;S<80;S++)if(o=U,i=M,s=R,c=j,a=I,u=N,h=B,z,p=D,l=H,d=F,y=q,b=Y,v=K,g=J,W,C=65535&(O=W),A=O>>>16,P=65535&(T=z),E=T>>>16,C+=65535&(O=(Y>>>14|I<<18)^(Y>>>18|I<<14)^(I>>>9|Y<<23)),A+=O>>>16,P+=65535&(T=(I>>>14|Y<<18)^(I>>>18|Y<<14)^(Y>>>9|I<<23)),E+=T>>>16,C+=65535&(O=Y&K^~Y&J),A+=O>>>16,P+=65535&(T=I&N^~I&B),E+=T>>>16,C+=65535&(O=G[2*S+1]),A+=O>>>16,P+=65535&(T=G[2*S]),E+=T>>>16,T=x[S%16],A+=(O=L[S%16])>>>16,P+=65535&T,E+=T>>>16,P+=(A+=(C+=65535&O)>>>16)>>>16,C=65535&(O=w=65535&C|A<<16),A=O>>>16,P=65535&(T=_=65535&P|(E+=P>>>16)<<16),E=T>>>16,C+=65535&(O=(D>>>28|U<<4)^(U>>>2|D<<30)^(U>>>7|D<<25)),A+=O>>>16,P+=65535&(T=(U>>>28|D<<4)^(D>>>2|U<<30)^(D>>>7|U<<25)),E+=T>>>16,A+=(O=D&H^D&F^H&F)>>>16,P+=65535&(T=U&M^U&R^M&R),E+=T>>>16,f=65535&(P+=(A+=(C+=65535&O)>>>16)>>>16)|(E+=P>>>16)<<16,m=65535&C|A<<16,C=65535&(O=y),A=O>>>16,P=65535&(T=c),E=T>>>16,A+=(O=w)>>>16,P+=65535&(T=_),E+=T>>>16,M=o,R=i,j=s,I=c=65535&(P+=(A+=(C+=65535&O)>>>16)>>>16)|(E+=P>>>16)<<16,N=a,B=u,z=h,U=f,H=p,F=l,q=d,Y=y=65535&C|A<<16,K=b,J=v,W=g,D=m,S%16==15)for(k=0;k<16;k++)T=x[k],C=65535&(O=L[k]),A=O>>>16,P=65535&T,E=T>>>16,T=x[(k+9)%16],C+=65535&(O=L[(k+9)%16]),A+=O>>>16,P+=65535&T,E+=T>>>16,_=x[(k+1)%16],C+=65535&(O=((w=L[(k+1)%16])>>>1|_<<31)^(w>>>8|_<<24)^(w>>>7|_<<25)),A+=O>>>16,P+=65535&(T=(_>>>1|w<<31)^(_>>>8|w<<24)^_>>>7),E+=T>>>16,_=x[(k+14)%16],A+=(O=((w=L[(k+14)%16])>>>19|_<<13)^(_>>>29|w<<3)^(w>>>6|_<<26))>>>16,P+=65535&(T=(_>>>19|w<<13)^(w>>>29|_<<3)^_>>>6),E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,x[k]=65535&P|E<<16,L[k]=65535&C|A<<16;C=65535&(O=D),A=O>>>16,P=65535&(T=U),E=T>>>16,T=t[0],A+=(O=e[0])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[0]=U=65535&P|E<<16,e[0]=D=65535&C|A<<16,C=65535&(O=H),A=O>>>16,P=65535&(T=M),E=T>>>16,T=t[1],A+=(O=e[1])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[1]=M=65535&P|E<<16,e[1]=H=65535&C|A<<16,C=65535&(O=F),A=O>>>16,P=65535&(T=R),E=T>>>16,T=t[2],A+=(O=e[2])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[2]=R=65535&P|E<<16,e[2]=F=65535&C|A<<16,C=65535&(O=q),A=O>>>16,P=65535&(T=j),E=T>>>16,T=t[3],A+=(O=e[3])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[3]=j=65535&P|E<<16,e[3]=q=65535&C|A<<16,C=65535&(O=Y),A=O>>>16,P=65535&(T=I),E=T>>>16,T=t[4],A+=(O=e[4])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[4]=I=65535&P|E<<16,e[4]=Y=65535&C|A<<16,C=65535&(O=K),A=O>>>16,P=65535&(T=N),E=T>>>16,T=t[5],A+=(O=e[5])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[5]=N=65535&P|E<<16,e[5]=K=65535&C|A<<16,C=65535&(O=J),A=O>>>16,P=65535&(T=B),E=T>>>16,T=t[6],A+=(O=e[6])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[6]=B=65535&P|E<<16,e[6]=J=65535&C|A<<16,C=65535&(O=W),A=O>>>16,P=65535&(T=z),E=T>>>16,T=t[7],A+=(O=e[7])>>>16,P+=65535&T,E+=T>>>16,E+=(P+=(A+=(C+=65535&O)>>>16)>>>16)>>>16,t[7]=z=65535&P|E<<16,e[7]=W=65535&C|A<<16,X+=128,r-=128}return r}function V(t,e,n){var r,o=new Int32Array(8),i=new Int32Array(8),s=new Uint8Array(256),c=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,i[0]=4089235720,i[1]=2227873595,i[2]=4271175723,i[3]=1595750129,i[4]=2917565137,i[5]=725511199,i[6]=4215389547,i[7]=327033209,Z(o,i,e,n),n%=128,r=0;r=0;--o)$(t,e,r=n[o/8|0]>>(7&o)&1),Q(e,t),Q(t,t),$(t,e,r)}function nt(t,n){var r=[e(),e(),e(),e()];x(r[0],f),x(r[1],p),x(r[2],c),z(r[3],f,p),et(t,r,n)}function rt(t,n,o){var i,s=new Uint8Array(64),c=[e(),e(),e(),e()];for(o||r(n,32),V(s,n,32),s[0]&=248,s[31]&=127,s[31]|=64,nt(c,s),tt(t,c),i=0;i<32;i++)n[i+32]=t[i];return 0}var ot=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function it(t,e){var n,r,o,i;for(r=63;r>=32;--r){for(n=0,o=r-32,i=r-12;o>8,e[o]-=256*n;e[o]+=n,e[r]=0}for(n=0,o=0;o<32;o++)e[o]+=n-(e[31]>>4)*ot[o],n=e[o]>>8,e[o]&=255;for(o=0;o<32;o++)e[o]-=n*ot[o];for(r=0;r<32;r++)e[r+1]+=e[r]>>8,t[r]=255&e[r]}function st(t){var e,n=new Float64Array(64);for(e=0;e<64;e++)n[e]=t[e];for(e=0;e<64;e++)t[e]=0;it(t,n)}function ct(t,n,r,o){var i,s,c=new Uint8Array(64),a=new Uint8Array(64),u=new Uint8Array(64),h=new Float64Array(64),f=[e(),e(),e(),e()];V(c,o,32),c[0]&=248,c[31]&=127,c[31]|=64;var p=r+64;for(i=0;i>7&&B(t[0],s,t[0]),z(t[3],t[0],t[1]),0)}(p,o))return-1;for(i=0;i=0},t.sign.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(64);return rt(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(ht(t),64!==t.length)throw new Error("bad secret key size");for(var e=new Uint8Array(32),n=0;n>>6)+r(128|63&e):r(224|e>>>12&15)+r(128|e>>>6&63)+r(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},f=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[o.charAt(n>>>18),o.charAt(n>>>12&63),e>=2?"=":o.charAt(n>>>6&63),e>=1?"=":o.charAt(63&n)].join("")},p=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,f)},l=function(){function t(t,e,n,r){var o=this;this.clear=e,this.timer=t((function(){o.timer&&(o.timer=r(o.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),d=(a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function y(t){self.clearTimeout(t)}function b(t){self.clearInterval(t)}var v=function(t){function e(e,n){return t.call(this,setTimeout,y,e,(function(t){return n(),null}))||this}return d(e,t),e}(l),g=function(t){function e(e,n){return t.call(this,setInterval,b,e,(function(t){return n(),t}))||this}return d(e,t),e}(l),m={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new v(0,t)},method:function(t){for(var e=[],n=1;n0)for(r=0;r=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},$=Q,tt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),et=function(t){function e(e,n){var r=t.call(this)||this;return r.id=e,r.transport=n,r.activityTimeout=n.activityTimeout,r.bindListeners(),r}return tt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var r={event:t,data:e};return n&&(r.channel=n),H.debug("Event sent",r),this.send($.encodeMessage(r))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=$.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(H.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){k(e,(function(e,n){t.transport.unbind(n,e)}))};k(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=$.getCloseAction(t),n=$.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(D),nt=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=$.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new et(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=$.getCloseAction(e)||"backoff",r=$.getCloseError(e);t.finish(n,{error:r})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(_({transport:this.transport,action:t},e))},t}(),rt=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===re.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=(e||{}).auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||re.getAuthorizers(),t.authorizers[this.type].call(this,re,e,n)},t}(),ot=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(re.TimelineTransport.getAgent(this,t),e)},t}(),it=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),st=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ct=(function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}it(e,t)}(Error),function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error)),at=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ut=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ht=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),ft=function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this;return Object.setPrototypeOf(r,n.prototype),r}return it(e,t),e}(Error),pt={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"}}},lt=function(t){var e,n=pt.urls[t];return n?(n.fullUrl?e=n.fullUrl:n.path&&(e=pt.baseUrl+n.path),e?"See: "+e:""):""},dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),yt=function(t){function e(e,n){var r=t.call(this,(function(t,n){H.debug("No callbacks on "+e+" for "+t)}))||this;return r.name=e,r.pusher=n,r.subscribed=!1,r.subscriptionPending=!1,r.subscriptionCancelled=!1,r}return dt(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new st("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=lt("triggeringClientEvents");H.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(H.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(D),bt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),vt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return bt(e,t),e.prototype.authorize=function(t,e){return Pt.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(yt),gt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;k(this.members,(function(n,r){t(e.get(r))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),mt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),_t=function(t){function e(e,n){var r=t.call(this,e,n)||this;return r.members=new gt,r}return mt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var o=lt("authenticationEndpoint");return H.error("Invalid auth response for channel '"+r.name+"',expected 'channel_data' field. "+o),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);r.members.setMyID(i.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,r={};t.user_id&&(r.user_id=t.user_id),this.emit(e,n,r)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var r=this.members.addMember(n);this.emit("pusher:member_added",r);break;case"pusher_internal:member_removed":var o=this.members.removeMember(n);o&&this.emit("pusher:member_removed",o)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(vt),wt=n(0),St=n(1),kt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Tt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.key=null,e}return kt(e,t),e.prototype.authorize=function(e,n){var r=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var o=e.shared_secret;if(o)r.key=Object(St.decodeBase64)(o),delete e.shared_secret,n(!1,e);else{var i="No shared_secret key in auth payload for encrypted channel: "+r.name;n(!0,i)}}}))},e.prototype.trigger=function(t,e){throw new ut("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,r=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,r):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var r=Object(St.decodeBase64)(e.ciphertext);if(r.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new v(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new v(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new v(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new v(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return _({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return _({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var r=t;"connected"===r&&(r+=" with new socket ID "+e.socket_id),H.debug("State changed",n+" -> "+r),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(D),At=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){return 0===t.indexOf("private-encrypted-")?Pt.createEncryptedChannel(t,e):0===t.indexOf("private-")?Pt.createPrivateChannel(t,e):0===t.indexOf("presence-")?Pt.createPresenceChannel(t,e):Pt.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return k(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){k(this.channels,(function(t){t.disconnect()}))},t}();var Pt={createChannels:function(){return new At},createConnectionManager:function(t,e){return new Ct(t,e)},createChannel:function(t,e){return new yt(t,e)},createPrivateChannel:function(t,e){return new vt(t,e)},createPresenceChannel:function(t,e){return new _t(t,e)},createEncryptedChannel:function(t,e){return new Tt(t,e)},createTimelineSender:function(t,e){return new ot(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new rt(t,e)},createHandshake:function(t,e){return new nt(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new V(t,e,n)}},Et=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Pt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),xt=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,r=this.strategies,o=0,i=this.timeout,s=null,c=function(a,u){u?e(null,u):(o+=1,n.loop&&(o%=r.length),o0&&(o=new v(n.timeout,(function(){i.abort(),r(!0)}))),i=t.connect(e,(function(t,e){t&&o&&o.isRunning()&&!n.failFast||(o&&o.ensureAborted(),r(t,e))})),{abort:function(){o&&o.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),Lt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var r=C(t,(function(t,r,o,i){return t.connect(e,n(r,i))}));return{abort:function(){O(r,Ut)},forceMinPriority:function(t){O(r,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(r,o){n[t].error=r,r?function(t){return function(t,e){for(var n=0;n=m.now()){var i=this.transports[r.transport];i&&(this.timeline.info({cached:!0,transport:r.transport,latency:r.latency}),o.push(new xt([i],{timeout:2*r.latency+1e3,failFast:!0})))}var s=m.now(),c=o.pop().connect(t,(function r(i,a){i?(jt(n),o.length>0?(s=m.now(),c=o.pop().connect(t,r)):e(i)):(!function(t,e,n){var r=re.getLocalStorage();if(r)try{r[Rt(t)]=U({timestamp:m.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,m.now()-s),e(null,a))}));return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function Rt(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function jt(t){var e=re.getLocalStorage();if(e)try{delete e[Rt(t)]}catch(t){}}var It=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,r=this.strategy,o=new v(this.options.delay,(function(){n=r.connect(t,e)}));return{abort:function(){o.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),Nt=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),Bt=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,r){r&&n.abort(),e(t,r)}));return n},t}();function zt(t){return function(){return t.isSupported()}}var Dt,Ht=function(t,e){var n={};function r(r,o,i,s,c){var a=e(t,r,o,i,s,c);return n[r]=a,a}var o,i={hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath},s=_({},i,{useTLS:!0}),c={hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath},a={loop:!0,timeout:15e3,timeoutLimit:6e4},u=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),h=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activity_timeout}),f=r("ws","ws",3,i,u),p=r("wss","ws",3,s,u),l=r("xhr_streaming","xhr_streaming",1,c,h),d=r("xhr_polling","xhr_polling",1,c),y=new xt([f],a),b=new xt([p],a),v=new xt([l],a),g=new xt([d],a),m=new xt([new Nt(zt(v),new Lt([v,new It(g,{delay:4e3})]),g)],a);return o=t.useTLS?new Lt([y,new It(m,{delay:2e3})]):new Lt([y,new It(b,{delay:2e3}),new It(m,{delay:5e3})]),new Mt(new Bt(new Nt(zt(f),o,m)),n,{ttl:18e5,timeline:t.timeline,useTLS:t.useTLS})},Ft=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),qt=function(t){function e(e,n,r){var o=t.call(this)||this;return o.hooks=e,o.method=n,o.url=r,o}return Ft(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},re.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(re.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(D);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(Dt||(Dt={}));var Yt=Dt,Kt=1;function Jt(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+Kt++}function Wt(t){return Math.floor(Math.random()*t)}var Xt,Gt=function(){function t(t,e){this.hooks=t,this.session=Wt(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},$t={getDefaultStrategy:Ht,Transports:Z,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(Zt,t)},createPollingSocket:function(t){return this.createSocket(Vt,t)},createSocket:function(t,e){return new Gt(t,e)},createXHR:function(t,e){return this.createRequest(Qt,t,e)},createRequest:function(t,e,n){return new qt(t,e,n)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return T(P({ws:Z.ws},(function(t){return t.isSupported({})})))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},te=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ee=new(function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return te(e,t),e.prototype.isOnline=function(){return!0},e}(D)),ne=function(t,e,n){var r=new Headers;for(var o in r.set("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)r.set(o,this.authOptions.headers[o]);var i=this.composeQuery(e),s=new Request(this.options.authEndpoint,{headers:r,body:i,credentials:"same-origin",method:"POST"});return fetch(s).then((function(t){var e=t.status;if(200===e)return t.text();throw H.error("Couldn't get auth info from your auth endpoint",e),e})).then((function(t){try{t=JSON.parse(t)}catch(n){var e="JSON returned from auth endpoint was invalid, yet status code was 200. Data was: "+t;throw H.error(e),e}n(!1,t)})).catch((function(t){n(!0,t)}))},re={getDefaultStrategy:$t.getDefaultStrategy,Transports:$t.Transports,setup:$t.setup,getProtocol:$t.getProtocol,isXHRSupported:$t.isXHRSupported,getLocalStorage:$t.getLocalStorage,createXHR:$t.createXHR,createWebSocket:$t.createWebSocket,addUnloadListener:$t.addUnloadListener,removeUnloadListener:$t.removeUnloadListener,transportConnectionInitializer:$t.transportConnectionInitializer,createSocketRequest:$t.createSocketRequest,HTTPFactory:$t.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,e){return function(n,r){var o="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path,i=L(n);fetch(o+="/2?"+i).then((function(t){if(200!==t.status)throw"received "+t.status+" from stats.pusher.com";return t.json()})).then((function(e){var n=e.host;n&&(t.host=n)})).catch((function(t){H.debug("TimelineSender Error: ",t)}))}}},getAuthorizers:function(){return{ajax:ne}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return ee}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(Xt||(Xt={}));var oe=Xt,ie=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(_({},e,{timestamp:m.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(oe.ERROR,t)},t.prototype.info=function(t){this.log(oe.INFO,t)},t.prototype.debug=function(t){this.log(oe.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,r=_({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(r,(function(t,r){t||n.sent++,e&&e(t,r)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),se=function(){function t(t,e,n,r){this.name=t,this.priority=e,this.transport=n,this.options=r||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return ce(new ft,e);if(this.priority>>18&63),e+=this._encodeByte(o>>>12&63),e+=this._encodeByte(o>>>6&63),e+=this._encodeByte(o>>>0&63)}var r=t.length-n;if(r>0){o=t[n]<<16|(2===r?t[n+1]<<8:0);e+=this._encodeByte(o>>>18&63),e+=this._encodeByte(o>>>12&63),e+=2===r?this._encodeByte(o>>>6&63):this._paddingCharacter||"",e+=this._paddingCharacter||""}return e},t.prototype.maxDecodedLength=function(t){return this._paddingCharacter?t/4*3|0:(6*t+7)/8|0},t.prototype.decodedLength=function(t){return this.maxDecodedLength(t.length-this._getPaddingLength(t))},t.prototype.decode=function(t){if(0===t.length)return new Uint8Array(0);for(var e=this._getPaddingLength(t),n=t.length-e,o=new Uint8Array(this.maxDecodedLength(n)),r=0,i=0,s=0,c=0,a=0,u=0,h=0;i>>4,o[r++]=a<<4|u>>>2,o[r++]=u<<6|h,s|=256&c,s|=256&a,s|=256&u,s|=256&h;if(i>>4,s|=256&c,s|=256&a),i>>2,s|=256&u),i>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-15,e+=62-t>>>8&3,String.fromCharCode(e)},t.prototype._decodeChar=function(t){var e=256;return e+=(42-t&t-44)>>>8&-256+t-43+62,e+=(46-t&t-48)>>>8&-256+t-47+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},t.prototype._getPaddingLength=function(t){var e=0;if(this._paddingCharacter){for(var n=t.length-1;n>=0&&t[n]===this._paddingCharacter;n--)e++;if(t.length<4||e>2)throw new Error("Base64Coder: incorrect padding")}return e},t}();e.Coder=i;var s=new i;e.encode=function(t){return s.encode(t)},e.decode=function(t){return s.decode(t)};var c=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype._encodeByte=function(t){var e=t;return e+=65,e+=25-t>>>8&6,e+=51-t>>>8&-75,e+=61-t>>>8&-13,e+=62-t>>>8&49,String.fromCharCode(e)},e.prototype._decodeChar=function(t){var e=256;return e+=(44-t&t-46)>>>8&-256+t-45+62,e+=(94-t&t-96)>>>8&-256+t-95+63,e+=(47-t&t-58)>>>8&-256+t-48+52,e+=(64-t&t-91)>>>8&-256+t-65+0,e+=(96-t&t-123)>>>8&-256+t-97+26},e}(i);e.URLSafeCoder=c;var a=new c;e.encodeURLSafe=function(t){return a.encode(t)},e.decodeURLSafe=function(t){return a.decode(t)},e.encodedLength=function(t){return s.encodedLength(t)},e.maxDecodedLength=function(t){return s.maxDecodedLength(t)},e.decodedLength=function(t){return s.decodedLength(t)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o="utf8: invalid source encoding";function r(t){for(var e=0,n=0;n=t.length-1)throw new Error("utf8: invalid string");n++,e+=4}}return e}e.encode=function(t){for(var e=new Uint8Array(r(t)),n=0,o=0;o>6,e[n++]=128|63&i):i<55296?(e[n++]=224|i>>12,e[n++]=128|i>>6&63,e[n++]=128|63&i):(o++,i=(1023&i)<<10,i|=1023&t.charCodeAt(o),i+=65536,e[n++]=240|i>>18,e[n++]=128|i>>12&63,e[n++]=128|i>>6&63,e[n++]=128|63&i)}return e},e.encodedLength=r,e.decode=function(t){for(var e=[],n=0;n=t.length)throw new Error(o);if(128!=(192&(s=t[++n])))throw new Error(o);r=(31&r)<<6|63&s,i=128}else if(r<240){if(n>=t.length-1)throw new Error(o);var s=t[++n],c=t[++n];if(128!=(192&s)||128!=(192&c))throw new Error(o);r=(15&r)<<12|(63&s)<<6|63&c,i=2048}else{if(!(r<248))throw new Error(o);if(n>=t.length-2)throw new Error(o);s=t[++n],c=t[++n];var a=t[++n];if(128!=(192&s)||128!=(192&c)||128!=(192&a))throw new Error(o);r=(15&r)<<18|(63&s)<<12|(63&c)<<6|63&a,i=65536}if(r=55296&&r<=57343)throw new Error(o);if(r>=65536){if(r>1114111)throw new Error(o);r-=65536,e.push(String.fromCharCode(55296|r>>10)),r=56320|1023&r}}e.push(String.fromCharCode(r))}return e.join("")}},function(t,e,n){t.exports=n(3).default},function(t,e,n){"use strict";n.r(e);for(var o=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i={},s=0,c=r.length;s>>6)+o(128|63&e):o(224|e>>>12&15)+o(128|e>>>6&63)+o(128|63&e)},h=function(t){return t.replace(/[^\x00-\x7F]/g,u)},p=function(t){var e=[0,2,1][t.length%3],n=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[r.charAt(n>>>18),r.charAt(n>>>12&63),e>=2?"=":r.charAt(n>>>6&63),e>=1?"=":r.charAt(63&n)].join("")},l=self.btoa||function(t){return t.replace(/[\s\S]{1,3}/g,p)},f=function(){function t(t,e,n,o){var r=this;this.clear=e,this.timer=t((function(){r.timer&&(r.timer=o(r.timer))}),n)}return t.prototype.isRunning=function(){return null!==this.timer},t.prototype.ensureAborted=function(){this.timer&&(this.clear(this.timer),this.timer=null)},t}(),d=(a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});function y(t){self.clearTimeout(t)}function g(t){self.clearInterval(t)}var b=function(t){function e(e,n){return t.call(this,setTimeout,y,e,(function(t){return n(),null}))||this}return d(e,t),e}(f),v=function(t){function e(e,n){return t.call(this,setInterval,g,e,(function(t){return n(),t}))||this}return d(e,t),e}(f),m={now:function(){return Date.now?Date.now():(new Date).valueOf()},defer:function(t){return new b(0,t)},method:function(t){for(var e=[],n=1;n0)for(o=0;o=1002&&t.code<=1004?"backoff":null:4e3===t.code?"tls_only":t.code<4100?"refused":t.code<4200?"backoff":t.code<4300?"retry":"refused"},getCloseError:function(t){return 1e3!==t.code&&1001!==t.code?{type:"PusherError",data:{code:t.code,message:t.reason||t.message}}:null}},Z=K,tt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),et=function(t){function e(e,n){var o=t.call(this)||this;return o.id=e,o.transport=n,o.activityTimeout=n.activityTimeout,o.bindListeners(),o}return tt(e,t),e.prototype.handlesActivityChecks=function(){return this.transport.handlesActivityChecks()},e.prototype.send=function(t){return this.transport.send(t)},e.prototype.send_event=function(t,e,n){var o={event:t,data:e};return n&&(o.channel=n),B.debug("Event sent",o),this.send(Z.encodeMessage(o))},e.prototype.ping=function(){this.transport.supportsPing()?this.transport.ping():this.send_event("pusher:ping",{})},e.prototype.close=function(){this.transport.close()},e.prototype.bindListeners=function(){var t=this,e={message:function(e){var n;try{n=Z.decodeMessage(e)}catch(n){t.emit("error",{type:"MessageParseError",error:n,data:e.data})}if(void 0!==n){switch(B.debug("Event recd",n),n.event){case"pusher:error":t.emit("error",{type:"PusherError",data:n.data});break;case"pusher:ping":t.emit("ping");break;case"pusher:pong":t.emit("pong")}t.emit("message",n)}},activity:function(){t.emit("activity")},error:function(e){t.emit("error",{type:"WebSocketError",error:e})},closed:function(e){n(),e&&e.code&&t.handleCloseEvent(e),t.transport=null,t.emit("closed")}},n=function(){k(e,(function(e,n){t.transport.unbind(n,e)}))};k(e,(function(e,n){t.transport.bind(n,e)}))},e.prototype.handleCloseEvent=function(t){var e=Z.getCloseAction(t),n=Z.getCloseError(t);n&&this.emit("error",n),e&&this.emit(e,{action:e,error:n})},e}(z),nt=function(){function t(t,e){this.transport=t,this.callback=e,this.bindListeners()}return t.prototype.close=function(){this.unbindListeners(),this.transport.close()},t.prototype.bindListeners=function(){var t=this;this.onMessage=function(e){var n;t.unbindListeners();try{n=Z.processHandshake(e)}catch(e){return t.finish("error",{error:e}),void t.transport.close()}"connected"===n.action?t.finish("connected",{connection:new et(n.id,t.transport),activityTimeout:n.activityTimeout}):(t.finish(n.action,{error:n.error}),t.transport.close())},this.onClosed=function(e){t.unbindListeners();var n=Z.getCloseAction(e)||"backoff",o=Z.getCloseError(e);t.finish(n,{error:o})},this.transport.bind("message",this.onMessage),this.transport.bind("closed",this.onClosed)},t.prototype.unbindListeners=function(){this.transport.unbind("message",this.onMessage),this.transport.unbind("closed",this.onClosed)},t.prototype.finish=function(t,e){this.callback(_({transport:this.transport,action:t},e))},t}(),ot=function(){function t(t,e){this.channel=t;var n=e.authTransport;if(void 0===oe.getAuthorizers()[n])throw"'"+n+"' is not a recognized auth transport";this.type=n,this.options=e,this.authOptions=e.auth||{}}return t.prototype.composeQuery=function(t){var e="socket_id="+encodeURIComponent(t)+"&channel_name="+encodeURIComponent(this.channel.name);for(var n in this.authOptions.params)e+="&"+encodeURIComponent(n)+"="+encodeURIComponent(this.authOptions.params[n]);return e},t.prototype.authorize=function(e,n){t.authorizers=t.authorizers||oe.getAuthorizers(),t.authorizers[this.type].call(this,oe,e,n)},t}(),rt=function(){function t(t,e){this.timeline=t,this.options=e||{}}return t.prototype.send=function(t,e){this.timeline.isEmpty()||this.timeline.send(oe.TimelineTransport.getAgent(this,t),e)},t}(),it=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),st=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return it(e,t),e}(Error),ct=(function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}it(e,t)}(Error),function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return it(e,t),e}(Error)),at=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return it(e,t),e}(Error),ut=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return it(e,t),e}(Error),ht=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return it(e,t),e}(Error),pt=function(t){function e(e){var n=this.constructor,o=t.call(this,e)||this;return Object.setPrototypeOf(o,n.prototype),o}return it(e,t),e}(Error),lt={baseUrl:"https://pusher.com",urls:{authenticationEndpoint:{path:"/docs/authenticating_users"},javascriptQuickStart:{path:"/docs/javascript_quick_start"},triggeringClientEvents:{path:"/docs/client_api_guide/client_events#trigger-events"},encryptedChannelSupport:{fullUrl:"https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support"}}},ft=function(t){var e,n=lt.urls[t];return n?(n.fullUrl?e=n.fullUrl:n.path&&(e=lt.baseUrl+n.path),e?"See: "+e:""):""},dt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),yt=function(t){function e(e,n){var o=t.call(this,(function(t,n){B.debug("No callbacks on "+e+" for "+t)}))||this;return o.name=e,o.pusher=n,o.subscribed=!1,o.subscriptionPending=!1,o.subscriptionCancelled=!1,o}return dt(e,t),e.prototype.authorize=function(t,e){return e(!1,{auth:""})},e.prototype.trigger=function(t,e){if(0!==t.indexOf("client-"))throw new st("Event '"+t+"' does not start with 'client-'");if(!this.subscribed){var n=ft("triggeringClientEvents");B.warn("Client event triggered before channel 'subscription_succeeded' event . "+n)}return this.pusher.send_event(t,e,this.name)},e.prototype.disconnect=function(){this.subscribed=!1,this.subscriptionPending=!1},e.prototype.handleEvent=function(t){var e=t.event,n=t.data;if("pusher_internal:subscription_succeeded"===e)this.handleSubscriptionSucceededEvent(t);else if(0!==e.indexOf("pusher_internal:")){this.emit(e,n,{})}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):this.emit("pusher:subscription_succeeded",t.data)},e.prototype.subscribe=function(){var t=this;this.subscribed||(this.subscriptionPending=!0,this.subscriptionCancelled=!1,this.authorize(this.pusher.connection.socket_id,(function(e,n){e?(B.error(n),t.emit("pusher:subscription_error",n)):(n=n,t.pusher.send_event("pusher:subscribe",{auth:n.auth,channel_data:n.channel_data,channel:t.name}))})))},e.prototype.unsubscribe=function(){this.subscribed=!1,this.pusher.send_event("pusher:unsubscribe",{channel:this.name})},e.prototype.cancelSubscription=function(){this.subscriptionCancelled=!0},e.prototype.reinstateSubscription=function(){this.subscriptionCancelled=!1},e}(z),gt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),bt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return gt(e,t),e.prototype.authorize=function(t,e){return Lt.createAuthorizer(this,this.pusher.config).authorize(t,e)},e}(yt),vt=function(){function t(){this.reset()}return t.prototype.get=function(t){return Object.prototype.hasOwnProperty.call(this.members,t)?{id:t,info:this.members[t]}:null},t.prototype.each=function(t){var e=this;k(this.members,(function(n,o){t(e.get(o))}))},t.prototype.setMyID=function(t){this.myID=t},t.prototype.onSubscription=function(t){this.members=t.presence.hash,this.count=t.presence.count,this.me=this.get(this.myID)},t.prototype.addMember=function(t){return null===this.get(t.user_id)&&this.count++,this.members[t.user_id]=t.user_info,this.get(t.user_id)},t.prototype.removeMember=function(t){var e=this.get(t.user_id);return e&&(delete this.members[t.user_id],this.count--),e},t.prototype.reset=function(){this.members={},this.count=0,this.myID=null,this.me=null},t}(),mt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),_t=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.members=new vt,o}return mt(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,(function(t,e){if(!t){if(void 0===(e=e).channel_data){var r=ft("authenticationEndpoint");return B.error("Invalid auth response for channel '"+o.name+"',expected 'channel_data' field. "+r),void n("Invalid auth response")}var i=JSON.parse(e.channel_data);o.members.setMyID(i.user_id)}n(t,e)}))},e.prototype.handleEvent=function(t){var e=t.event;if(0===e.indexOf("pusher_internal:"))this.handleInternalEvent(t);else{var n=t.data,o={};t.user_id&&(o.user_id=t.user_id),this.emit(e,n,o)}},e.prototype.handleInternalEvent=function(t){var e=t.event,n=t.data;switch(e){case"pusher_internal:subscription_succeeded":this.handleSubscriptionSucceededEvent(t);break;case"pusher_internal:member_added":var o=this.members.addMember(n);this.emit("pusher:member_added",o);break;case"pusher_internal:member_removed":var r=this.members.removeMember(n);r&&this.emit("pusher:member_removed",r)}},e.prototype.handleSubscriptionSucceededEvent=function(t){this.subscriptionPending=!1,this.subscribed=!0,this.subscriptionCancelled?this.pusher.unsubscribe(this.name):(this.members.onSubscription(t.data),this.emit("pusher:subscription_succeeded",this.members))},e.prototype.disconnect=function(){this.members.reset(),t.prototype.disconnect.call(this)},e}(bt),St=n(1),wt=n(0),kt=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Ct=function(t){function e(e,n,o){var r=t.call(this,e,n)||this;return r.key=null,r.nacl=o,r}return kt(e,t),e.prototype.authorize=function(e,n){var o=this;t.prototype.authorize.call(this,e,(function(t,e){if(t)n(!0,e);else{var r=e.shared_secret;if(r)o.key=Object(wt.decode)(r),delete e.shared_secret,n(!1,e);else{var i="No shared_secret key in auth payload for encrypted channel: "+o.name;n(!0,i)}}}))},e.prototype.trigger=function(t,e){throw new ut("Client events are not currently supported for encrypted channels")},e.prototype.handleEvent=function(e){var n=e.event,o=e.data;0!==n.indexOf("pusher_internal:")&&0!==n.indexOf("pusher:")?this.handleEncryptedEvent(n,o):t.prototype.handleEvent.call(this,e)},e.prototype.handleEncryptedEvent=function(t,e){var n=this;if(this.key)if(e.ciphertext&&e.nonce){var o=Object(wt.decode)(e.ciphertext);if(o.length0&&this.emit("connecting_in",Math.round(t/1e3)),this.retryTimer=new b(t||0,(function(){e.disconnectInternally(),e.connect()}))},e.prototype.clearRetryTimer=function(){this.retryTimer&&(this.retryTimer.ensureAborted(),this.retryTimer=null)},e.prototype.setUnavailableTimer=function(){var t=this;this.unavailableTimer=new b(this.options.unavailableTimeout,(function(){t.updateState("unavailable")}))},e.prototype.clearUnavailableTimer=function(){this.unavailableTimer&&this.unavailableTimer.ensureAborted()},e.prototype.sendActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection.ping(),this.activityTimer=new b(this.options.pongTimeout,(function(){t.timeline.error({pong_timed_out:t.options.pongTimeout}),t.retryIn(0)}))},e.prototype.resetActivityCheck=function(){var t=this;this.stopActivityCheck(),this.connection&&!this.connection.handlesActivityChecks()&&(this.activityTimer=new b(this.activityTimeout,(function(){t.sendActivityCheck()})))},e.prototype.stopActivityCheck=function(){this.activityTimer&&this.activityTimer.ensureAborted()},e.prototype.buildConnectionCallbacks=function(t){var e=this;return _({},t,{message:function(t){e.resetActivityCheck(),e.emit("message",t)},ping:function(){e.send_event("pusher:pong",{})},activity:function(){e.resetActivityCheck()},error:function(t){e.emit("error",{type:"WebSocketError",error:t})},closed:function(){e.abandonConnection(),e.shouldRetry()&&e.retryIn(1e3)}})},e.prototype.buildHandshakeCallbacks=function(t){var e=this;return _({},t,{connected:function(t){e.activityTimeout=Math.min(e.options.activityTimeout,t.activityTimeout,t.connection.activityTimeout||1/0),e.clearUnavailableTimer(),e.setConnection(t.connection),e.socket_id=e.connection.id,e.updateState("connected",{socket_id:e.socket_id})}})},e.prototype.buildErrorCallbacks=function(){var t=this,e=function(e){return function(n){n.error&&t.emit("error",{type:"WebSocketError",error:n.error}),e(n)}};return{tls_only:e((function(){t.usingTLS=!0,t.updateStrategy(),t.retryIn(0)})),refused:e((function(){t.disconnect()})),backoff:e((function(){t.retryIn(1e3)})),retry:e((function(){t.retryIn(0)}))}},e.prototype.setConnection=function(t){for(var e in this.connection=t,this.connectionCallbacks)this.connection.bind(e,this.connectionCallbacks[e]);this.resetActivityCheck()},e.prototype.abandonConnection=function(){if(this.connection){for(var t in this.stopActivityCheck(),this.connectionCallbacks)this.connection.unbind(t,this.connectionCallbacks[t]);var e=this.connection;return this.connection=null,e}},e.prototype.updateState=function(t,e){var n=this.state;if(this.state=t,n!==t){var o=t;"connected"===o&&(o+=" with new socket ID "+e.socket_id),B.debug("State changed",n+" -> "+o),this.timeline.info({state:t,params:e}),this.emit("state_change",{previous:n,current:t}),this.emit(t,e)}},e.prototype.shouldRetry=function(){return"connecting"===this.state||"connected"===this.state},e}(z),Pt=function(){function t(){this.channels={}}return t.prototype.add=function(t,e){return this.channels[t]||(this.channels[t]=function(t,e){if(0===t.indexOf("private-encrypted-")){if(e.config.nacl)return Lt.createEncryptedChannel(t,e,e.config.nacl);var n=ft("encryptedChannelSupport");throw new ut("Tried to subscribe to a private-encrypted- channel but no nacl implementation available. "+n)}return 0===t.indexOf("private-")?Lt.createPrivateChannel(t,e):0===t.indexOf("presence-")?Lt.createPresenceChannel(t,e):Lt.createChannel(t,e)}(t,e)),this.channels[t]},t.prototype.all=function(){return function(t){var e=[];return k(t,(function(t){e.push(t)})),e}(this.channels)},t.prototype.find=function(t){return this.channels[t]},t.prototype.remove=function(t){var e=this.channels[t];return delete this.channels[t],e},t.prototype.disconnect=function(){k(this.channels,(function(t){t.disconnect()}))},t}();var Lt={createChannels:function(){return new Pt},createConnectionManager:function(t,e){return new Ot(t,e)},createChannel:function(t,e){return new yt(t,e)},createPrivateChannel:function(t,e){return new bt(t,e)},createPresenceChannel:function(t,e){return new _t(t,e)},createEncryptedChannel:function(t,e,n){return new Ct(t,e,n)},createTimelineSender:function(t,e){return new rt(t,e)},createAuthorizer:function(t,e){return e.authorizer?e.authorizer(t,e):new ot(t,e)},createHandshake:function(t,e){return new nt(t,e)},createAssistantToTheTransportManager:function(t,e,n){return new $(t,e,n)}},Et=function(){function t(t){this.options=t||{},this.livesLeft=this.options.lives||1/0}return t.prototype.getAssistant=function(t){return Lt.createAssistantToTheTransportManager(this,t,{minPingDelay:this.options.minPingDelay,maxPingDelay:this.options.maxPingDelay})},t.prototype.isAlive=function(){return this.livesLeft>0},t.prototype.reportDeath=function(){this.livesLeft-=1},t}(),At=function(){function t(t,e){this.strategies=t,this.loop=Boolean(e.loop),this.failFast=Boolean(e.failFast),this.timeout=e.timeout,this.timeoutLimit=e.timeoutLimit}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){var n=this,o=this.strategies,r=0,i=this.timeout,s=null,c=function(a,u){u?e(null,u):(r+=1,n.loop&&(r%=o.length),r0&&(r=new b(n.timeout,(function(){i.abort(),o(!0)}))),i=t.connect(e,(function(t,e){t&&r&&r.isRunning()&&!n.failFast||(r&&r.ensureAborted(),o(t,e))})),{abort:function(){r&&r.ensureAborted(),i.abort()},forceMinPriority:function(t){i.forceMinPriority(t)}}},t}(),xt=function(){function t(t){this.strategies=t}return t.prototype.isSupported=function(){return E(this.strategies,m.method("isSupported"))},t.prototype.connect=function(t,e){return function(t,e,n){var o=O(t,(function(t,o,r,i){return t.connect(e,n(o,i))}));return{abort:function(){T(o,jt)},forceMinPriority:function(t){T(o,(function(e){e.forceMinPriority(t)}))}}}(this.strategies,t,(function(t,n){return function(o,r){n[t].error=o,o?function(t){return function(t,e){for(var n=0;n=m.now()){var i=this.transports[o.transport];i&&(this.timeline.info({cached:!0,transport:o.transport,latency:o.latency}),r.push(new At([i],{timeout:2*o.latency+1e3,failFast:!0})))}var s=m.now(),c=r.pop().connect(t,(function o(i,a){i?(Nt(n),r.length>0?(s=m.now(),c=r.pop().connect(t,o)):e(i)):(!function(t,e,n){var o=oe.getLocalStorage();if(o)try{o[It(t)]=j({timestamp:m.now(),transport:e,latency:n})}catch(t){}}(n,a.transport.name,m.now()-s),e(null,a))}));return{abort:function(){c.abort()},forceMinPriority:function(e){t=e,c&&c.forceMinPriority(e)}}},t}();function It(t){return"pusherTransport"+(t?"TLS":"NonTLS")}function Nt(t){var e=oe.getLocalStorage();if(e)try{delete e[It(t)]}catch(t){}}var Dt=function(){function t(t,e){var n=e.delay;this.strategy=t,this.options={delay:n}}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n,o=this.strategy,r=new b(this.options.delay,(function(){n=o.connect(t,e)}));return{abort:function(){r.ensureAborted(),n&&n.abort()},forceMinPriority:function(e){t=e,n&&n.forceMinPriority(e)}}},t}(),Mt=function(){function t(t,e,n){this.test=t,this.trueBranch=e,this.falseBranch=n}return t.prototype.isSupported=function(){return(this.test()?this.trueBranch:this.falseBranch).isSupported()},t.prototype.connect=function(t,e){return(this.test()?this.trueBranch:this.falseBranch).connect(t,e)},t}(),Ht=function(){function t(t){this.strategy=t}return t.prototype.isSupported=function(){return this.strategy.isSupported()},t.prototype.connect=function(t,e){var n=this.strategy.connect(t,(function(t,o){o&&n.abort(),e(t,o)}));return n},t}();function Ut(t){return function(){return t.isSupported()}}var zt,Bt=function(t,e,n){var o={};function r(e,r,i,s,c){var a=n(t,e,r,i,s,c);return o[e]=a,a}var i,s=Object.assign({},e,{hostNonTLS:t.wsHost+":"+t.wsPort,hostTLS:t.wsHost+":"+t.wssPort,httpPath:t.wsPath}),c=_({},s,{useTLS:!0}),a=Object.assign({},e,{hostNonTLS:t.httpHost+":"+t.httpPort,hostTLS:t.httpHost+":"+t.httpsPort,httpPath:t.httpPath}),u={loop:!0,timeout:15e3,timeoutLimit:6e4},h=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),p=new Et({lives:2,minPingDelay:1e4,maxPingDelay:t.activityTimeout}),l=r("ws","ws",3,s,h),f=r("wss","ws",3,c,h),d=r("xhr_streaming","xhr_streaming",1,a,p),y=r("xhr_polling","xhr_polling",1,a),g=new At([l],u),b=new At([f],u),v=new At([d],u),m=new At([y],u),S=new At([new Mt(Ut(v),new xt([v,new Dt(m,{delay:4e3})]),m)],u);return i=e.useTLS?new xt([g,new Dt(S,{delay:2e3})]):new xt([g,new Dt(b,{delay:2e3}),new Dt(S,{delay:5e3})]),new Rt(new Ht(new Mt(Ut(l),i,S)),o,{ttl:18e5,timeline:e.timeline,useTLS:e.useTLS})},Ft=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),qt=function(t){function e(e,n,o){var r=t.call(this)||this;return r.hooks=e,r.method=n,r.url=o,r}return Ft(e,t),e.prototype.start=function(t){var e=this;this.position=0,this.xhr=this.hooks.getRequest(this),this.unloader=function(){e.close()},oe.addUnloadListener(this.unloader),this.xhr.open(this.method,this.url,!0),this.xhr.setRequestHeader&&this.xhr.setRequestHeader("Content-Type","application/json"),this.xhr.send(t)},e.prototype.close=function(){this.unloader&&(oe.removeUnloadListener(this.unloader),this.unloader=null),this.xhr&&(this.hooks.abortRequest(this.xhr),this.xhr=null)},e.prototype.onChunk=function(t,e){for(;;){var n=this.advanceBuffer(e);if(!n)break;this.emit("chunk",{status:t,data:n})}this.isBufferTooLong(e)&&this.emit("buffer_too_long")},e.prototype.advanceBuffer=function(t){var e=t.slice(this.position),n=e.indexOf("\n");return-1!==n?(this.position+=n+1,e.slice(0,n)):null},e.prototype.isBufferTooLong=function(t){return this.position===t.length&&t.length>262144},e}(z);!function(t){t[t.CONNECTING=0]="CONNECTING",t[t.OPEN=1]="OPEN",t[t.CLOSED=3]="CLOSED"}(zt||(zt={}));var Jt=zt,Wt=1;function Xt(t){var e=-1===t.indexOf("?")?"?":"&";return t+e+"t="+ +new Date+"&n="+Wt++}function Gt(t){return Math.floor(Math.random()*t)}var Qt,Vt=function(){function t(t,e){this.hooks=t,this.session=Gt(1e3)+"/"+function(t){for(var e=[],n=0;n0&&t.onChunk(e.status,e.responseText);break;case 4:e.responseText&&e.responseText.length>0&&t.onChunk(e.status,e.responseText),t.emit("finished",e.status),t.close()}},e},abortRequest:function(t){t.onreadystatechange=null,t.abort()}},Zt={getDefaultStrategy:Bt,Transports:Y,transportConnectionInitializer:function(){this.timeline.info(this.buildTimelineMessage({transport:this.name+(this.options.useTLS?"s":"")})),this.hooks.isInitialized()?this.changeState("initialized"):this.onClose()},HTTPFactory:{createStreamingSocket:function(t){return this.createSocket(Yt,t)},createPollingSocket:function(t){return this.createSocket($t,t)},createSocket:function(t,e){return new Vt(t,e)},createXHR:function(t,e){return this.createRequest(Kt,t,e)},createRequest:function(t,e,n){return new qt(t,e,n)}},setup:function(t){t.ready()},getLocalStorage:function(){},getClientFeatures:function(){return C(L({ws:Y.ws},(function(t){return t.isSupported({})})))},getProtocol:function(){return"http:"},isXHRSupported:function(){return!0},createSocketRequest:function(t,e){if(this.isXHRSupported())return this.HTTPFactory.createXHR(t,e);throw"Cross-origin HTTP requests are not supported"},createXHR:function(){return new(this.getXHRAPI())},createWebSocket:function(t){return new(this.getWebSocketAPI())(t)},addUnloadListener:function(t){},removeUnloadListener:function(t){}},te=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),ee=new(function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return te(e,t),e.prototype.isOnline=function(){return!0},e}(z)),ne=function(t,e,n){var o=new Headers;for(var r in o.set("Content-Type","application/x-www-form-urlencoded"),this.authOptions.headers)o.set(r,this.authOptions.headers[r]);var i=this.composeQuery(e),s=new Request(this.options.authEndpoint,{headers:o,body:i,credentials:"same-origin",method:"POST"});return fetch(s).then((function(t){var e=t.status;if(200===e)return t.text();throw B.error("Couldn't get auth info from your auth endpoint",e),e})).then((function(t){try{t=JSON.parse(t)}catch(n){var e="JSON returned from auth endpoint was invalid, yet status code was 200. Data was: "+t;throw B.error(e),e}n(!1,t)})).catch((function(t){n(!0,t)}))},oe={getDefaultStrategy:Zt.getDefaultStrategy,Transports:Zt.Transports,setup:Zt.setup,getProtocol:Zt.getProtocol,isXHRSupported:Zt.isXHRSupported,getLocalStorage:Zt.getLocalStorage,createXHR:Zt.createXHR,createWebSocket:Zt.createWebSocket,addUnloadListener:Zt.addUnloadListener,removeUnloadListener:Zt.removeUnloadListener,transportConnectionInitializer:Zt.transportConnectionInitializer,createSocketRequest:Zt.createSocketRequest,HTTPFactory:Zt.HTTPFactory,TimelineTransport:{name:"xhr",getAgent:function(t,e){return function(n,o){var r="http"+(e?"s":"")+"://"+(t.host||t.options.host)+t.options.path,i=x(n);fetch(r+="/2?"+i).then((function(t){if(200!==t.status)throw"received "+t.status+" from stats.pusher.com";return t.json()})).then((function(e){var n=e.host;n&&(t.host=n)})).catch((function(t){B.debug("TimelineSender Error: ",t)}))}}},getAuthorizers:function(){return{ajax:ne}},getWebSocketAPI:function(){return WebSocket},getXHRAPI:function(){return XMLHttpRequest},getNetwork:function(){return ee}};!function(t){t[t.ERROR=3]="ERROR",t[t.INFO=6]="INFO",t[t.DEBUG=7]="DEBUG"}(Qt||(Qt={}));var re=Qt,ie=function(){function t(t,e,n){this.key=t,this.session=e,this.events=[],this.options=n||{},this.sent=0,this.uniqueID=0}return t.prototype.log=function(t,e){t<=this.options.level&&(this.events.push(_({},e,{timestamp:m.now()})),this.options.limit&&this.events.length>this.options.limit&&this.events.shift())},t.prototype.error=function(t){this.log(re.ERROR,t)},t.prototype.info=function(t){this.log(re.INFO,t)},t.prototype.debug=function(t){this.log(re.DEBUG,t)},t.prototype.isEmpty=function(){return 0===this.events.length},t.prototype.send=function(t,e){var n=this,o=_({session:this.session,bundle:this.sent+1,key:this.key,lib:"js",version:this.options.version,cluster:this.options.cluster,features:this.options.features,timeline:this.events},this.options.params);return this.events=[],t(o,(function(t,o){t||n.sent++,e&&e(t,o)})),!0},t.prototype.generateUniqueID=function(){return this.uniqueID++,this.uniqueID},t}(),se=function(){function t(t,e,n,o){this.name=t,this.priority=e,this.transport=n,this.options=o||{}}return t.prototype.isSupported=function(){return this.transport.isSupported({useTLS:this.options.useTLS})},t.prototype.connect=function(t,e){var n=this;if(!this.isSupported())return ce(new pt,e);if(this.priority { - wsHost: string; - wsPort: number; - wssPort: number; - wsPath: string; +import { Options } from './options'; +import { AuthOptions, AuthorizerGenerator } from './auth/options'; +import * as nacl from 'tweetnacl'; +export declare type AuthTransport = 'ajax' | 'jsonp'; +export declare type Transport = 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs'; +export interface Config { + activityTimeout: number; + authEndpoint: string; + authTransport: AuthTransport; + enableStats: boolean; httpHost: string; + httpPath: string; httpPort: number; httpsPort: number; - httpPath: string; + pongTimeout: number; statsHost: string; - authEndpoint: string; - authTransport: string; - activity_timeout: number; - pong_timeout: number; - unavailable_timeout: number; -}; -export declare var getClusterConfig: (clusterName: any) => { + unavailableTimeout: number; + useTLS: boolean; wsHost: string; - httpHost: string; -}; + wsPath: string; + wsPort: number; + wssPort: number; + forceTLS?: boolean; + auth?: AuthOptions; + authorizer?: AuthorizerGenerator; + cluster?: string; + disabledTransports?: Transport[]; + enabledTransports?: Transport[]; + ignoreNullOrigin?: boolean; + nacl?: nacl; + timelineParams?: any; +} +export declare function getConfig(opts: Options): Config; diff --git a/types/src/core/connection/connection_manager.d.ts b/types/src/core/connection/connection_manager.d.ts index 30240913f..e63fea71f 100644 --- a/types/src/core/connection/connection_manager.d.ts +++ b/types/src/core/connection/connection_manager.d.ts @@ -23,7 +23,7 @@ export default class ConnectionManager extends EventsDispatcher { errorCallbacks: ErrorCallbacks; handshakeCallbacks: HandshakeCallbacks; connectionCallbacks: ConnectionCallbacks; - constructor(key: string, options: any); + constructor(key: string, options: ConnectionManagerOptions); connect(): void; send(data: any): boolean; send_event(name: string, data: any, channel?: string): boolean; diff --git a/types/src/core/connection/connection_manager_options.d.ts b/types/src/core/connection/connection_manager_options.d.ts index be8c736ff..9e1620dd7 100644 --- a/types/src/core/connection/connection_manager_options.d.ts +++ b/types/src/core/connection/connection_manager_options.d.ts @@ -6,5 +6,6 @@ interface ConnectionManagerOptions { unavailableTimeout: number; pongTimeout: number; activityTimeout: number; + useTLS: boolean; } export default ConnectionManagerOptions; diff --git a/types/src/core/defaults.d.ts b/types/src/core/defaults.d.ts index 2c176f8a2..fceb0f159 100644 --- a/types/src/core/defaults.d.ts +++ b/types/src/core/defaults.d.ts @@ -1,20 +1,21 @@ +import { AuthTransport } from './config'; export interface DefaultConfig { VERSION: string; PROTOCOL: number; - host: string; - ws_port: number; - wss_port: number; - ws_path: string; - sockjs_host: string; - sockjs_http_port: number; - sockjs_https_port: number; - sockjs_path: string; + wsPort: number; + wssPort: number; + wsPath: string; + httpHost: string; + httpPort: number; + httpsPort: number; + httpPath: string; stats_host: string; - channel_auth_endpoint: string; - channel_auth_transport: string; - activity_timeout: number; - pong_timeout: number; - unavailable_timeout: number; + authEndpoint: string; + authTransport: AuthTransport; + activityTimeout: number; + pongTimeout: number; + unavailableTimeout: number; + cluster: string; cdn_http?: string; cdn_https?: string; dependency_suffix?: string; diff --git a/types/src/core/options.d.ts b/types/src/core/options.d.ts index 509d2bac1..1c49eea00 100644 --- a/types/src/core/options.d.ts +++ b/types/src/core/options.d.ts @@ -1,45 +1,30 @@ import { AuthOptions, AuthorizerGenerator } from './auth/options'; -export interface PusherOptions { - cluster: string; - disableStats: boolean; - enableStats: boolean; - statsHost: string; - activity_timeout: number; - pong_timeout: number; - unavailable_timeout: number; - forceTLS: boolean; - encrypted: boolean; - timelineParams: any; - authTransport: 'ajax' | 'jsonp'; - auth: AuthOptions; - authorizer: AuthorizerGenerator; -} -declare type Transport = 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs'; -declare type AuthTransport = 'ajax' | 'jsonp'; +import { AuthTransport, Transport } from './config'; +import * as nacl from 'tweetnacl'; export interface Options { activityTimeout?: number; - enableStats?: boolean; - disableStats?: boolean; - authEndpoint?: string; auth?: AuthOptions; + authEndpoint?: string; authTransport?: AuthTransport; authorizer?: AuthorizerGenerator; + cluster?: string; + enableStats?: boolean; + disableStats?: boolean; disabledTransports?: Transport[]; enabledTransports?: Transport[]; - encrypted?: boolean; forceTLS?: boolean; + httpHost?: string; + httpPath?: string; + httpPort?: number; + httpsPort?: number; ignoreNullOrigin?: boolean; + nacl?: nacl; pongTimeout?: number; statsHost?: string; timelineParams?: any; - unavailable_timeout?: number; - cluster?: string; + unavailableTimeout?: number; wsHost?: string; - httpHost?: string; wsPath?: string; wsPort?: number; wssPort?: number; - httpPort?: number; - httpsPort?: number; } -export {}; diff --git a/types/src/core/pusher-with-encryption.d.ts b/types/src/core/pusher-with-encryption.d.ts new file mode 100644 index 000000000..557bb708d --- /dev/null +++ b/types/src/core/pusher-with-encryption.d.ts @@ -0,0 +1,5 @@ +import Pusher from './pusher'; +import { Options } from './options'; +export default class PusherWithEncryption extends Pusher { + constructor(app_key: string, options?: Options); +} diff --git a/types/src/core/pusher.d.ts b/types/src/core/pusher.d.ts index 017608211..a392fdac0 100644 --- a/types/src/core/pusher.d.ts +++ b/types/src/core/pusher.d.ts @@ -6,7 +6,8 @@ import Timeline from './timeline/timeline'; import TimelineSender from './timeline/timeline_sender'; import ConnectionManager from './connection/connection_manager'; import { PeriodicTimer } from './utils/timers'; -import { PusherOptions, Options } from './options'; +import { Options } from './options'; +import { Config } from './config'; export default class Pusher { static instances: Pusher[]; static isReady: boolean; @@ -19,7 +20,7 @@ export default class Pusher { static log: (message: any) => void; private static getClientFeatures; key: string; - config: PusherOptions; + config: Config; channels: Channels; global_emitter: EventsDispatcher; sessionID: number; diff --git a/types/src/core/strategies/strategy_builder.d.ts b/types/src/core/strategies/strategy_builder.d.ts index 2449c0a25..e33867d97 100644 --- a/types/src/core/strategies/strategy_builder.d.ts +++ b/types/src/core/strategies/strategy_builder.d.ts @@ -1,3 +1,5 @@ import TransportManager from '../transports/transport_manager'; import Strategy from './strategy'; -export declare var defineTransport: (config: any, name: string, type: string, priority: number, options: any, manager?: TransportManager) => Strategy; +import StrategyOptions from '../strategies/strategy_options'; +import { Config } from '../config'; +export declare var defineTransport: (config: Config, name: string, type: string, priority: number, options: StrategyOptions, manager?: TransportManager) => Strategy; diff --git a/types/src/core/strategies/strategy_options.d.ts b/types/src/core/strategies/strategy_options.d.ts index bd94b7d26..2479c54da 100644 --- a/types/src/core/strategies/strategy_options.d.ts +++ b/types/src/core/strategies/strategy_options.d.ts @@ -1,12 +1,16 @@ +import Timeline from '../timeline/timeline'; interface StrategyOptions { - ttl?: number; - timeline?: any; - useTLS?: boolean; + failFast?: boolean; + hostNonTLS?: string; + hostTLS?: string; + httpPath?: string; ignoreNullOrigin?: boolean; + key?: string; loop?: boolean; - failFast?: boolean; + timeline?: Timeline; timeout?: number; timeoutLimit?: number; - key?: string; + ttl?: number; + useTLS?: boolean; } export default StrategyOptions; diff --git a/types/src/core/utils/factory.d.ts b/types/src/core/utils/factory.d.ts index 238e90f0d..d9c46d821 100644 --- a/types/src/core/utils/factory.d.ts +++ b/types/src/core/utils/factory.d.ts @@ -15,13 +15,14 @@ import ConnectionManager from '../connection/connection_manager'; import ConnectionManagerOptions from '../connection/connection_manager_options'; import Channels from '../channels/channels'; import Pusher from '../pusher'; +import * as nacl from 'tweetnacl'; declare var Factory: { createChannels(): Channels; createConnectionManager(key: string, options: ConnectionManagerOptions): ConnectionManager; createChannel(name: string, pusher: Pusher): Channel; createPrivateChannel(name: string, pusher: Pusher): PrivateChannel; createPresenceChannel(name: string, pusher: Pusher): PresenceChannel; - createEncryptedChannel(name: string, pusher: Pusher): EncryptedChannel; + createEncryptedChannel(name: string, pusher: Pusher, nacl: nacl): EncryptedChannel; createTimelineSender(timeline: Timeline, options: TimelineSenderOptions): TimelineSender; createAuthorizer(channel: Channel, options: AuthorizerOptions): Authorizer; createHandshake(transport: TransportConnection, callback: (HandshakePayload: any) => void): Handshake; diff --git a/types/src/runtimes/interface.d.ts b/types/src/runtimes/interface.d.ts index e79b93484..f131388ec 100644 --- a/types/src/runtimes/interface.d.ts +++ b/types/src/runtimes/interface.d.ts @@ -9,6 +9,8 @@ import HTTPRequest from '../core/http/http_request'; import Pusher from '../core/pusher'; import JSONPRequest from './web/dom/jsonp_request'; import Strategy from '../core/strategies/strategy'; +import { Config } from '../core/config'; +import StrategyOptions from '../core/strategies/strategy_options'; interface Runtime { setup(PusherClass: { new (key: string, options: any): Pusher; @@ -21,7 +23,7 @@ interface Runtime { createXHR(): Ajax; createWebSocket(url: string): Socket; getNetwork(): Reachability; - getDefaultStrategy(config: any, defineTransport: Function): Strategy; + getDefaultStrategy(config: Config, options: StrategyOptions, defineTransport: Function): Strategy; Transports: TransportsTable; getWebSocketAPI(): new (url: string) => Socket; getXHRAPI(): new () => Ajax; diff --git a/types/src/runtimes/isomorphic/default_strategy.d.ts b/types/src/runtimes/isomorphic/default_strategy.d.ts index 3225978a8..dfbd6fc6a 100644 --- a/types/src/runtimes/isomorphic/default_strategy.d.ts +++ b/types/src/runtimes/isomorphic/default_strategy.d.ts @@ -1,3 +1,5 @@ import Strategy from 'core/strategies/strategy'; -declare var getDefaultStrategy: (config: any, defineTransport: Function) => Strategy; +import { Config } from 'core/config'; +import StrategyOptions from 'core/strategies/strategy_options'; +declare var getDefaultStrategy: (config: Config, baseOptions: StrategyOptions, defineTransport: Function) => Strategy; export default getDefaultStrategy; diff --git a/types/src/runtimes/web/default_strategy.d.ts b/types/src/runtimes/web/default_strategy.d.ts index 3225978a8..ba4b0d248 100644 --- a/types/src/runtimes/web/default_strategy.d.ts +++ b/types/src/runtimes/web/default_strategy.d.ts @@ -1,3 +1,5 @@ import Strategy from 'core/strategies/strategy'; -declare var getDefaultStrategy: (config: any, defineTransport: Function) => Strategy; +import StrategyOptions from 'core/strategies/strategy_options'; +import { Config } from 'core/config'; +declare var getDefaultStrategy: (config: Config, baseOptions: StrategyOptions, defineTransport: Function) => Strategy; export default getDefaultStrategy;