@wireapp/cryptobox
Version:
High-level API with persistent storage for Proteus.
9 lines • 78.5 kB
JavaScript
/*! @wireapp/cryptobox v8.7.27 */
var cryptobox=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=24)}([function(e,t){e.exports=Proteus},function(e,t,r){"use strict";var n=this&&this.__extends||function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(s,a)}u((n=n.apply(e,t||[])).next())})},o=this&&this.__generator||function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(t,"__esModule",{value:!0});var s=r(8),a=r(12),u=r(0),f=r(4),c=r(17),h=r(18),l=r(5),p=r(2),y=r(6),d=r(7),g=r(3),_=1e3,v=r(23).version,w=function(e){function t(t,r){void 0===r&&(r=1);var n=e.call(this)||this;if(n.logger=h("@wireapp/cryptobox/Cryptobox",{logger:console,markdown:!1}),n.queues=new s.LRUCache(_),!t)throw new Error("You cannot initialize Cryptobox without a storage component.");r>u.keys.PreKey.MAX_PREKEY_ID&&(r=u.keys.PreKey.MAX_PREKEY_ID),n.cachedSessions=new s.LRUCache(_),n.minimumAmountOfPreKeys=r,n.store=new g.CryptoboxCRUDStore(t);var i=t.constructor.name;return n.logger.log('Constructed Cryptobox. Minimum amount of PreKeys is "'+r+'". Storage engine is "'+i+'".'),n}return n(t,e),t.prototype.get_session_queue=function(e){var t=this.queues.get(e);return t||(t=new a.PriorityQueue({maxRetries:0}),this.queues.set(e,t)),t},t.prototype.save_session_in_cache=function(e){return this.logger.log('Saving Session with ID "'+e.id+'" in cache...'),this.cachedSessions.set(e.id,e),e},t.prototype.load_session_from_cache=function(e){return this.logger.log('Trying to load Session with ID "'+e+'" from cache...'),this.cachedSessions.get(e)},t.prototype.remove_session_from_cache=function(e){this.logger.log('Removing Session with ID "'+e+'" from cache...'),this.cachedSessions.delete(e)},t.prototype.create=function(){var e=this;return this.logger.log("Initializing Cryptobox. Creating local identity..."),this.create_new_identity().then(function(){return e.create_last_resort_prekey()}).then(function(t){return e.logger.log('Created Last Resort PreKey with ID "'+t.key_id+'".'),e.init(!1)})},t.prototype.load=function(){var e=this;return this.logger.log("Initializing Cryptobox. Loading local identity..."),this.store.load_identity().then(function(t){if(t)return e.identity=t,e.logger.log("Initialized Cryptobox with existing local identity."),e.logger.log('Identity fingerprint is "'+t.public_key.fingerprint()+'".'),e.logger.log("Loading PreKeys..."),e.store.load_prekeys();throw new y.CryptoboxError("Failed to load local identity")}).then(function(t){var r=t.find(function(e){return e.key_id===u.keys.PreKey.MAX_PREKEY_ID});if(r)return e.logger.log('Loaded Last Resort PreKey with ID "'+r.key_id+'".'),e.lastResortPreKey=r,e.logger.log('Loaded "'+(e.minimumAmountOfPreKeys-1)+'" standard PreKeys...'),e.init(!0);throw new y.CryptoboxError("Failed to load last resort PreKey")})},t.prototype.init=function(e){var t=this;return this.refill_prekeys(e).then(function(){return t.store.load_prekeys()}).then(function(e){return e.sort(function(e,t){return e.key_id-t.key_id})})},t.prototype.get_serialized_last_resort_prekey=function(){return this.lastResortPreKey?Promise.resolve(this.serialize_prekey(this.lastResortPreKey)):Promise.reject(new y.CryptoboxError("No last resort PreKey available."))},t.prototype.get_prekey=function(e){return void 0===e&&(e=u.keys.PreKey.MAX_PREKEY_ID),this.store.load_prekey(e)},t.prototype.get_prekey_bundle=function(e){return void 0===e&&(e=u.keys.PreKey.MAX_PREKEY_ID),i(this,void 0,void 0,function(){var t;return o(this,function(r){switch(r.label){case 0:return[4,this.get_prekey(e)];case 1:if(t=r.sent(),!this.identity)throw new y.CryptoboxError("No local identity available.");if(!t)throw new y.CryptoboxError('PreKey with ID "'+e+'" cannot be found.');return[2,u.keys.PreKeyBundle.new(this.identity.public_key,t)]}})})},t.prototype.get_serialized_standard_prekeys=function(){var e=this;return this.store.load_prekeys().then(function(t){return t.filter(function(e){return!(e.key_id===u.keys.PreKey.MAX_PREKEY_ID)}).map(function(t){return e.serialize_prekey(t)})})},t.prototype.publish_event=function(e,t){this.emit(e,t),this.logger.log('Published event "'+e+'".',t)},t.prototype.publish_prekeys=function(e){e.length>0&&this.publish_event(t.TOPIC.NEW_PREKEYS,e)},t.prototype.publish_session_id=function(e){this.publish_event(t.TOPIC.NEW_SESSION,e.id)},t.prototype.refill_prekeys=function(e){var t=this;return void 0===e&&(e=!0),this.store.load_prekeys().then(function(e){var r=Math.max(0,t.minimumAmountOfPreKeys-e.length);if(r>0){var n=e.reduce(function(e,t){return t.key_id===u.keys.PreKey.MAX_PREKEY_ID?e:Math.max(t.key_id+1,e)},0);return t.logger.warn('There are not enough PreKeys in the storage. Generating "'+r+'" new PreKey(s), starting from ID "'+n+'"...'),t.new_prekeys(n,r)}return[]}).then(function(r){return r.length>0&&(t.logger.log('Generated PreKeys from ID "'+r[0].key_id+'" to ID "'+r[r.length-1].key_id+'".'),e&&t.publish_prekeys(r)),r})},t.prototype.create_new_identity=function(){var e=this;return Promise.resolve().then(function(){return e.store.delete_all()}).then(function(){return u.keys.IdentityKeyPair.new()}).then(function(t){return e.logger.warn("Cleaned cryptographic items prior to saving a new local identity."),e.logger.log('Created new local identity. Fingerprint is "'+t.public_key.fingerprint()+'".'),e.save_identity(t)})},t.prototype.save_identity=function(e){return this.identity=e,this.store.save_identity(e)},t.prototype.session_from_prekey=function(e,t){var r=this;return this.session_load(e).catch(function(n){var i;r.logger.warn('Creating new session because session with ID "'+e+'" could not be loaded: '+n.message);try{i=u.keys.PreKeyBundle.deserialise(t)}catch(t){throw new d.default('PreKey bundle for session "'+e+'" has an unsupported format: '+t.message)}return r.identity?u.session.Session.init_from_prekey(r.identity,i).then(function(t){var n=new l.default(e,t);return r.session_save(n)}):Promise.reject(new y.CryptoboxError("No local identity available."))})},t.prototype.session_from_message=function(e,t){var r=u.message.Envelope.deserialise(t);return this.identity?u.session.Session.init_from_message(this.identity,this.store,r).then(function(t){var r=t[0],n=t[1];return[new l.default(e,r),n]}):Promise.reject(new y.CryptoboxError("No local identity available."))},t.prototype.session_load=function(e){var t=this;this.logger.log('Trying to load Session with ID "'+e+'"...');var r=this.load_session_from_cache(e);if(r)return Promise.resolve(r);if(this.identity)return this.store.read_session(this.identity,e).then(function(r){var n=new l.default(e,r);return t.save_session_in_cache(n)});throw new y.CryptoboxError("No local identity available.")},t.prototype.session_save=function(e){var t=this;return this.store.create_session(e.id,e.session).then(function(){return t.save_session_in_cache(e)})},t.prototype.session_update=function(e){var t=this;return this.store.update_session(e.id,e.session).then(function(){return t.save_session_in_cache(e)})},t.prototype.session_delete=function(e){return this.remove_session_from_cache(e),this.store.delete_session(e)},t.prototype.create_last_resort_prekey=function(){var e=this;return Promise.resolve().then(function(){return i(e,void 0,void 0,function(){var e;return o(this,function(t){switch(t.label){case 0:return this.logger.log('Creating Last Resort PreKey with ID "'+u.keys.PreKey.MAX_PREKEY_ID+'"...'),e=this,[4,u.keys.PreKey.last_resort()];case 1:return e.lastResortPreKey=t.sent(),[2,this.store.save_prekeys([this.lastResortPreKey])]}})})}).then(function(e){return e[0]})},t.prototype.serialize_prekey=function(e){if(this.identity)return u.keys.PreKeyBundle.new(this.identity.public_key,e).serialised_json();throw new y.CryptoboxError("No local identity available.")},t.prototype.new_prekeys=function(e,t){var r=this;return void 0===t&&(t=0),0===t?Promise.resolve([]):Promise.resolve().then(function(){return u.keys.PreKey.generate_prekeys(e,t)}).then(function(e){return r.store.save_prekeys(e)})},t.prototype.encrypt=function(e,t,r){var n,i,o=this;return this.get_session_queue(e).add(function(){return Promise.resolve().then(function(){return r?o.session_from_prekey(e,r):o.session_load(e)}).then(function(e){return(i=e).encrypt(t)}).then(function(e){return n=e,o.session_update(i)}).then(function(){return n})})},t.prototype.decrypt=function(e,t){return i(this,void 0,void 0,function(){var r,n,i,s=this;return o(this,function(o){return r=!1,0===t.byteLength?[2,Promise.reject(new p.default("Cannot decrypt an empty ArrayBuffer."))]:[2,this.get_session_queue(e).add(function(){return s.session_load(e).catch(function(){return s.session_from_message(e,t)}).then(function(e){var n;return void 0!==e[0]?(i=e[0],n=e[1],s.publish_session_id(i),r=!0,n):(i=e).decrypt(t,s.store)}).then(function(e){return n=e,r?s.session_save(i):s.session_update(i)}).then(function(){return s.refill_prekeys(!0)}).then(function(){return n})})]})})},t.prototype.deleteData=function(){return i(this,void 0,void 0,function(){return o(this,function(e){switch(e.label){case 0:return this.cachedSessions=new s.LRUCache(_),this.identity=void 0,this.lastResortPreKey=void 0,this.queues=new s.LRUCache(_),[4,this.store.delete_all()];case 1:return e.sent(),[2]}})})},t.prototype.importIdentity=function(e){return i(this,void 0,void 0,function(){var t,r;return o(this,function(n){switch(n.label){case 0:return this.logger.log("Importing local identity..."),t=f.Decoder.fromBase64(e).asBytes.buffer,r=u.keys.IdentityKeyPair.deserialise(t),[4,this.save_identity(r)];case 1:return n.sent(),[2]}})})},t.prototype.importPreKeys=function(e){return i(this,void 0,void 0,function(){var t,r=this;return o(this,function(n){switch(n.label){case 0:return this.logger.log('Importing "'+Object.keys(e).length+'" PreKeys...'),t=Object.values(e).map(function(e){var t=f.Decoder.fromBase64(e).asBytes.buffer,n=u.keys.PreKey.deserialise(t);return n.key_id===u.keys.PreKey.MAX_PREKEY_ID&&(r.lastResortPreKey=n),n}),[4,this.store.save_prekeys(t)];case 1:return n.sent(),[2]}})})},t.prototype.importSessions=function(e){return i(this,void 0,void 0,function(){var t,r,n,i,s,a,c,h;return o(this,function(o){switch(o.label){case 0:for(r in this.logger.log('Importing "'+Object.keys(e).length+'" sessions...'),t=[],e)t.push(r);n=0,o.label=1;case 1:return n<t.length?(i=t[n],s=e[i],a=f.Decoder.fromBase64(s).asBytes.buffer,c=u.session.Session.deserialise(this.identity,a),h=new l.default(i,c),[4,this.session_save(h)]):[3,4];case 2:o.sent(),o.label=3;case 3:return n++,[3,1];case 4:return[2]}})})},t.prototype.deserialize=function(e){return i(this,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return[4,this.deleteData()];case 1:return t.sent(),[4,this.importIdentity(e.identity)];case 2:return t.sent(),[4,this.importPreKeys(e.prekeys)];case 3:return t.sent(),[4,this.importSessions(e.sessions)];case 4:return t.sent(),[4,this.refill_prekeys(!0)];case 5:return t.sent(),[2]}})})},t.prototype.serialize=function(){return i(this,void 0,void 0,function(){var e,t,r,n,i,s,a,u,c,h;return o(this,function(o){switch(o.label){case 0:return e=function(e){return f.Encoder.toBase64(e).asString},t={identity:"",prekeys:{},sessions:{}},[4,this.store.load_identity()];case 1:return(r=o.sent())?(t.identity=e(r.serialise()),[4,this.store.read_sessions(r)]):[3,3];case 2:for(i in n=o.sent())s=n[i],t.sessions[i]=e(s.serialise());o.label=3;case 3:return[4,this.store.load_prekeys()];case 4:for(a=o.sent(),u=0,c=a;u<c.length;u++)h=c[u],t.prekeys[h.key_id]=e(h.serialise());return[2,t]}})})},t.TOPIC={NEW_PREKEYS:"new-prekeys",NEW_SESSION:"new-session"},t.VERSION=v,t}(c);t.default=w},function(e,t,r){"use strict";var n=this&&this.__extends||function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(t,"__esModule",{value:!0});var i=function(e){function t(r){var n=e.call(this,r)||this;return n.message=r,Object.setPrototypeOf(n,t.prototype),n.message=r,n.name=n.constructor.name,n.stack=(new Error).stack,n}return n(t,e),t}(Error);t.default=i},function(e,t,r){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),n(r(20)),n(r(21)),n(r(22))},function(e,t,r){"use strict";(function(e){var r=this&&this.__extends||function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(){}return e.arrayBufferViewToStringUTF8=function(e){try{return this.arrayBufferViewToString(e)}catch(t){return"object"==typeof window&&"TextDecoder"in window?new TextDecoder("utf-8").decode(e):Array.from(e).map(function(e){return String.fromCharCode(e)}).join("")}},e.jsonToArrayBufferView=function(e){var t=Object.keys(e).length,r=new Uint8Array(t);for(var n in e)e.hasOwnProperty(n)&&(r[parseInt(n,10)]=e[n]);return r},e.numberArrayToArrayBufferView=function(e){for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),n=0;n<r.length;n++)r[n]=e[n];return r},e.stringToArrayBufferViewUTF16=function(e){for(var t=new ArrayBuffer(2*e.length),r=new Uint16Array(t),n=0,i=e.length;n<i;n++)r[n]=e.charCodeAt(n);return r},e.toArrayBufferView=function(e){switch(e.constructor.name){case"ArrayBuffer":return new Uint8Array(e);case"Array":case"Buffer":return this.numberArrayToArrayBufferView(e);case"Number":return this.stringToArrayBufferViewUTF8(e.toString());case"String":return this.stringToArrayBufferViewUTF8(e);case"Uint8Array":return e;default:throw new u(e.constructor.name+" is unsupported. Please provide a type of 'ArrayBuffer', 'Array', 'Buffer', 'Number', 'String' or 'Uint8Array'.")}},e.toString=function(e){switch(e.constructor.name){case"Array":var t=this.numberArrayToArrayBufferView(e);return this.arrayBufferViewToStringUTF8(t);case"Number":return e.toString();case"String":return e;case"Uint8Array":return this.arrayBufferViewToStringUTF8(e);default:throw new u(e.constructor.name+" is unsupported. Please provide a 'String', 'Uint8Array' or 'Array'.")}},e.stringToArrayBufferViewUTF8=function(e){var t=encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){var r=parseInt("0x"+t,16);return String.fromCharCode(r)}),r=new Uint8Array(t.length);return t.split("").forEach(function(e,t){r[t]=e.charCodeAt(0)}),r},e.arrayBufferViewToString=function(e){var t=Array.prototype.map.call(e,function(e){return String.fromCharCode(e)}).join("").replace(/(.)/g,function(e){var t=e.charCodeAt(0).toString(16).toUpperCase();return t.length<2?"0"+t:"%"+t});return decodeURIComponent(t)},e}();t.Converter=n;var i=function(){return function(e,t){this.asBytes=e,this.asString=t}}();t.DecodedData=i;var o=function(){function t(){}return t.fromBase64=function(e){var r=new RegExp("[^-A-Za-z0-9+/=]|=[^=]|={3,}$","igm"),o=n.toString(e).replace(r,""),s=t.toByteArray(o),a=n.arrayBufferViewToStringUTF8(s);return new i(s,a)},t.toByteArray=function(t){if(t.length%4!=0)throw new Error("Invalid string. Length must be a multiple of 4.");if("object"==typeof window){for(var r=window.atob(t),i=r.length,o=new Uint8Array(new ArrayBuffer(i)),s=0,a=o.length;s<a;s++)o[s]=r.charCodeAt(s);return o}var u=e.from(t,"base64");return n.numberArrayToArrayBufferView(u)},t}();t.Decoder=o;var s=function(){return function(e,t){this.asBytes=e,this.asString=t}}();t.EncodedData=s;var a=function(){function t(){}return t.toBase64=function(e){var r=n.toArrayBufferView(e),i=t.fromByteArray(r),o=n.stringToArrayBufferViewUTF8(i);return new s(o,i)},t.fromByteArray=function(t){if("object"==typeof window){var r=Array.from(t).map(function(e){return String.fromCharCode(e)}).join("");return window.btoa(r)}return e.from(t.buffer).toString("base64")},t}();t.Encoder=a;var u=function(e){function t(r){var n=e.call(this,r)||this;return n.message=r,Object.setPrototypeOf(n,t.prototype),n.name=n.constructor.name,n.message=r,n.stack=(new Error).stack,n}return r(t,e),t}(Error);t.UnsupportedInputError=u}).call(this,r(9).Buffer)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(0),i=r(2),o=function(){function e(e,t){this.id=e,this.session=t,Object.freeze(this)}return e.prototype.decrypt=function(e,t){if(0===e.byteLength)return Promise.reject(new i.default("Cannot decrypt an empty ArrayBuffer."));var r=n.message.Envelope.deserialise(e);return this.session.decrypt(t,r)},e.prototype.encrypt=function(e){return this.session.encrypt(e).then(function(e){return e.serialise()})},e.prototype.fingerprint_local=function(){return this.session.local_identity.public_key.fingerprint()},e.prototype.fingerprint_remote=function(){return this.session.remote_identity.fingerprint()},e}();t.default=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(19);t.CryptoboxError=n.default},function(e,t,r){"use strict";var n=this&&this.__extends||function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(t,"__esModule",{value:!0});var i=function(e){function t(r){var n=e.call(this,r)||this;return n.message=r,Object.setPrototypeOf(n,t.prototype),n.name=n.constructor.name,n.message=r,n.stack=(new Error).stack,n}return n(t,e),t}(Error);t.default=i},function(e,t){e.exports=LRUCache},function(e,t,r){"use strict";(function(e){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/
var n=r(14),i=r(15),o=r(16);function s(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()<t)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=u.prototype:(null===e&&(e=new u(t)),e.length=t),e}function u(e,t,r){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return h(this,e)}return f(this,e,t,r)}function f(e,t,r,n){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");t=void 0===r&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,r):new Uint8Array(t,r,n);u.TYPED_ARRAY_SUPPORT?(e=t).__proto__=u.prototype:e=l(e,t);return e}(e,t,r,n):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!u.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|y(t,r),i=(e=a(e,n)).write(t,r);i!==n&&(e=e.slice(0,i));return e}(e,t,r):function(e,t){if(u.isBuffer(t)){var r=0|p(t.length);return 0===(e=a(e,r)).length?e:(t.copy(e,0,0,r),e)}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||function(e){return e!=e}(t.length)?a(e,0):l(e,t);if("Buffer"===t.type&&o(t.data))return l(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function c(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function h(e,t){if(c(t),e=a(e,t<0?0:0|p(t)),!u.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function l(e,t){var r=t.length<0?0:0|p(t.length);e=a(e,r);for(var n=0;n<r;n+=1)e[n]=255&t[n];return e}function p(e){if(e>=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function y(e,t){if(u.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return N(e).length;default:if(n)return Y(e).length;t=(""+t).toLowerCase(),n=!0}}function d(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function g(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=u.from(t,n)),u.isBuffer(t))return 0===t.length?-1:_(e,t,r,n,i);if("number"==typeof t)return t&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):_(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function _(e,t,r,n,i){var o,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function f(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var c=-1;for(o=r;o<a;o++)if(f(e,o)===f(t,-1===c?0:o-c)){if(-1===c&&(c=o),o-c+1===u)return c*s}else-1!==c&&(o-=o-c),c=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var h=!0,l=0;l<u;l++)if(f(e,o+l)!==f(t,l)){h=!1;break}if(h)return o}return-1}function v(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))return s;e[r+s]=a}return s}function w(e,t,r,n){return F(Y(t,e.length-r),e,r,n)}function b(e,t,r,n){return F(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function m(e,t,r,n){return b(e,t,r,n)}function E(e,t,r,n){return F(N(t),e,r,n)}function x(e,t,r,n){return F(function(e,t){for(var r,n,i,o=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function P(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function S(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var o,s,a,u,f=e[i],c=null,h=f>239?4:f>223?3:f>191?2:1;if(i+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(o=e[i+1]))&&(u=(31&f)<<6|63&o)>127&&(c=u);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(u=(15&f)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&f)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(e){var t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}t.Buffer=u,t.SlowBuffer=function(e){+e!=e&&(e=0);return u.alloc(+e)},t.INSPECT_MAX_BYTES=50,u.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=s(),u.poolSize=8192,u._augment=function(e){return e.__proto__=u.prototype,e},u.from=function(e,t,r){return f(null,e,t,r)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(e,t,r){return function(e,t,r,n){return c(t),t<=0?a(e,t):void 0!==r?"string"==typeof n?a(e,t).fill(r,n):a(e,t).fill(r):a(e,t)}(null,e,t,r)},u.allocUnsafe=function(e){return h(null,e)},u.allocUnsafeSlow=function(e){return h(null,e)},u.isBuffer=function(e){return!(null==e||!e._isBuffer)},u.compare=function(e,t){if(!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},u.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(e,t){if(!o(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return u.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=u.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var s=e[r];if(!u.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},u.byteLength=y,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)d(this,t,t+1);return this},u.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)d(this,t,t+3),d(this,t+1,t+2);return this},u.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)d(this,t,t+7),d(this,t+1,t+6),d(this,t+2,t+5),d(this,t+3,t+4);return this},u.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?S(this,0,e):function(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return B(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return k(this,t,r);case"latin1":case"binary":return R(this,t,r);case"base64":return P(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}.apply(this,arguments)},u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===u.compare(this,e)},u.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),"<Buffer "+e+">"},u.prototype.compare=function(e,t,r,n,i){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,i>>>=0,this===e)return 0;for(var o=i-n,s=r-t,a=Math.min(o,s),f=this.slice(n,i),c=e.slice(t,r),h=0;h<a;++h)if(f[h]!==c[h]){o=f[h],s=c[h];break}return o<s?-1:s<o?1:0},u.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},u.prototype.indexOf=function(e,t,r){return g(this,e,t,r,!0)},u.prototype.lastIndexOf=function(e,t,r){return g(this,e,t,r,!1)},u.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,e,t,r);case"utf8":case"utf-8":return w(this,e,t,r);case"ascii":return b(this,e,t,r);case"latin1":case"binary":return m(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var A=4096;function k(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function R(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function B(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o<r;++o)i+=M(e[o]);return i}function C(e,t,r){for(var n=e.slice(t,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function T(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function I(e,t,r,n,i,o){if(!u.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<o)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i<o;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function U(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i<o;++i)e[r+i]=t>>>8*(n?i:3-i)&255}function D(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function K(e,t,r,n,o){return o||D(e,0,r,4),i.write(e,t,r,n,23,4),r+4}function j(e,t,r,n,o){return o||D(e,0,r,8),i.write(e,t,r,n,52,8),r+8}u.prototype.slice=function(e,t){var r,n=this.length;if(e=~~e,t=void 0===t?n:~~t,e<0?(e+=n)<0&&(e=0):e>n&&(e=n),t<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e),u.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=u.prototype;else{var i=t-e;r=new u(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+e]}return r},u.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||T(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n},u.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||T(e,t,this.length);for(var n=this[e+--t],i=1;t>0&&(i*=256);)n+=this[e+--t]*i;return n},u.prototype.readUInt8=function(e,t){return t||T(e,1,this.length),this[e]},u.prototype.readUInt16LE=function(e,t){return t||T(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUInt16BE=function(e,t){return t||T(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUInt32LE=function(e,t){return t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},u.prototype.readUInt32BE=function(e,t){return t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||T(e,t,this.length);for(var n=this[e],i=1,o=0;++o<t&&(i*=256);)n+=this[e+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*t)),n},u.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||T(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},u.prototype.readInt8=function(e,t){return t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},u.prototype.readInt16LE=function(e,t){t||T(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(e,t){t||T(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(e,t){return t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readFloatLE=function(e,t){return t||T(e,4,this.length),i.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return t||T(e,4,this.length),i.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return t||T(e,8,this.length),i.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return t||T(e,8,this.length),i.read(this,e,!1,52,8)},u.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||I(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},u.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||I(this,e,t,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},u.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,1,255,0),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},u.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},u.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},u.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):U(this,e,t,!0),t+4},u.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):U(this,e,t,!1),t+4},u.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);I(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o<r&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},u.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);I(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},u.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,1,127,-128),u.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},u.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},u.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},u.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):U(this,e,t,!0),t+4},u.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||I(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),u.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):U(this,e,t,!1),t+4},u.prototype.writeFloatLE=function(e,t,r){return K(this,e,t,!0,r)},u.prototype.writeFloatBE=function(e,t,r){return K(this,e,t,!1,r)},u.prototype.writeDoubleLE=function(e,t,r){return j(this,e,t,!0,r)},u.prototype.writeDoubleBE=function(e,t,r){return j(this,e,t,!1,r)},u.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i,o=n-r;if(this===e&&r<t&&t<n)for(i=o-1;i>=0;--i)e[i+t]=this[i+r];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)e[i+t]=this[i+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+o),t);return o},u.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var o;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o<r;++o)this[o]=e;else{var s=u.isBuffer(e)?e:Y(new u(e,n).toString()),a=s.length;for(o=0;o<r-t;++o)this[o+t]=s[o%a]}return this};var L=/[^+\/0-9A-Za-z-_]/g;function M(e){return e<16?"0"+e.toString(16):e.toString(16)}function Y(e,t){var r;t=t||1/0;for(var n=e.length,i=null,o=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function N(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(L,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function F(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}}).call(this,r(13))},function(e,t){e.exports=StoreEngine},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(1);t.Cryptobox=n.default;var i=r(5);t.CryptoboxSession=i.default;var o=r(2);t.DecryptionError=o.default;var s=r(6);t.error=s;var a=r(7);t.InvalidPreKeyFormatError=a.default;var u=r(3);t.store=u},function(e,t){e.exports=PriorityQueue},function(e,t){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";t.byteLength=function(e){var t=f(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){for(var t,r=f(e),n=r[0],s=r[1],a=new o(function(e,t,r){return 3*(t+r)/4-r}(0,n,s)),u=0,c=s>0?n-4:n,h=0;h<c;h+=4)t=i[e.charCodeAt(h)]<<18|i[e.charCodeAt(h+1)]<<12|i[e.charCodeAt(h+2)]<<6|i[e.charCodeAt(h+3)],a[u++]=t>>16&255,a[u++]=t>>8&255,a[u++]=255&t;2===s&&(t=i[e.charCodeAt(h)]<<2|i[e.charCodeAt(h+1)]>>4,a[u++]=255&t);1===s&&(t=i[e.charCodeAt(h)]<<10|i[e.charCodeAt(h+1)]<<4|i[e.charCodeAt(h+2)]>>2,a[u++]=t>>8&255,a[u++]=255&t);return a},t.fromByteArray=function(e){for(var t,r=e.length,i=r%3,o=[],s=0,a=r-i;s<a;s+=16383)o.push(h(e,s,s+16383>a?a:s+16383));1===i?(t=e[r-1],o.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],o.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],i[s.charCodeAt(a)]=a;function f(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function c(e){return n[e>>18&63]+n[e>>12&63]+n[e>>6&63]+n[63&e]}function h(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(c(n));return i.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,f=u>>1,c=-7,h=r?i-1:0,l=r?-1:1,p=e[t+h];for(h+=l,o=p&(1<<-c)-1,p>>=-c,c+=a;c>0;o=256*o+e[t+h],h+=l,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=256*s+e[t+h],h+=l,c-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=f}return(p?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,r,n,i,o){var s,a,u,f=8*o-i-1,c=(1<<f)-1,h=c>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,d=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+h>=1?l/u:l*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=c?(a=0,s=c):s+h>=1?(a=(t*u-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=y,a/=256,i-=8);for(s=s<<i|a,f+=i;f>0;e[r+p]=255&s,p+=y,s/=256,f-=8);e[r+p-y]|=128*d}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!function(e){return"number"==typeof e}(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,r,s,a,u,f;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}if(o(r=this._events[e]))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),r.apply(this,a)}else if(i(r))for(a=Array.prototype.slice.call(arguments,1),s=(f=r.slice()).length,u=0;u<s;u++)f[u].apply(this,a);return!0},r.prototype.addListener=function(e,t){var s;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(s=o(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&s>0&&this._events[e].length>s&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){if(!n(t))throw TypeError("listener must be a function");var r=!1;function i(){this.removeListener(e,i),r||(r=!0,t.apply(this,arguments))}return i.listener=t,this.on(e,i),this},r.prototype.removeListener=function(e,t){var r,o,s,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(s=(r=this._events[e]).length,o=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(a=s;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){o=a;break}if(o<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n(r=this._events[e]))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(module,exports,__webpack_require__){window,module.exports=function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){var n,i=r(1)(),o=r(3),s=r(5),a=r(8)();i.prefixColors=["#F2777A","#F99157","#FFCC66","#99CC99","#66CCCC","#6699CC","#CC99CC"],i._setPrefixRegExps=function(){try{a.localStorage&&"string"==typeof a.localStorage.getItem("debug")&&(i._prefixRegExps=[],a.localStorage.getItem("debug").split(",").forEach(function(e){var t="enable";"-"===(e=e.trim())[0]&&(e=e.substr(1),t="disable");var r=i._prepareRegExpForPrefixSearch(e);i._prefixRegExps.push({type:t,regExp:r})}))}catch(e){}},i._getNextPrefixColor=(n=0,function(){return n+=1,i.prefixColors[n%i.prefixColors.length]}),i.prototype._getDecoratedPrefix=function(){var e=[];return s()?(e.push("%c"+this.opts.prefix+"%c "),e.push("color:"+this.opts.prefixColor+"; font-weight:bold;","")):e.push("["+this.opts.prefix+"] "),e},i.prototype._prepareOutput=function(e){var t,r=this._getDecoratedPrefix();return"string"==typeof e[0]?this.opts.markdown&&s()?(t=o.parse(e[0]),r[0]=r[0]+t.text,r=r.concat(t.styles)):r[0]=r[0]+e[0]:r.push(e[0]),1<e.length&&(r=r.concat(e.slice(1))),r},i._setPrefixRegExps(),e.exports=i},function(e,t,r){var n=r(2);e.exports=function(){function e(t,r){return this instanceof e?e._isPrefixAlreadyInUse(t)?e._getInstanceByPrefix(t):(this.opts=e._normalizeOpts(t,r),this.state=e._getInitialState(this.opts),e._decorateLoggerMethods(this),e._instances.push(this),this):new e(t,r)}return e.transports=[],e._instances=[],e._prefixRegExps=[],e._prepareRegExpForPrefixSearch=function(e){return new RegExp("^"+e.replace(/\*/g,".*?")+"$")},e._isPrefixAlreadyInUse=function(t){return e._instances.some(function(e){return e.opts.prefix===t})},e._getInstanceByPrefix=function(t){return e._instances.filter(function(e){return e.opts.prefix===t})[0]},e._normalizeOpts=function(t,r){if("string"!=typeof t)throw new TypeError("prefix must be a string");var n=void 0===(r=r||{}).markdown||Boolean(r.markdown),i=r.prefixColor||e._getNextPrefixColor();return{logger:r.logger||console,markdown:n,prefix:t,prefixColor:i}},e._getInitialState=function(t){return{isEnabled:e._getEnableState(t)}},e._getEnableState=function(t){var r=!1;return e._prefixRegExps.forEach(function(e){"enable"===e.type&&e.regExp.test(t.prefix)?r=!0:"disable"===e.type&&e.regExp.test(t.prefix)&&(r=!1)}),r},e._decorateLoggerMethods=function(t){var r=t.opts.logger,i=Object.keys(r).filter(function(e){return"function"==typeof r[e]});0===i.length&&(i=["lo