@peculiar/fortify-webcomponents
Version:
Web-components for creating CSR or Certificate and viewing certificates list using Fortify
29 lines • 221 kB
JavaScript
var __extends=this&&this.__extends||function(){var r=function(t,e){r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,t){r.__proto__=t}||function(r,t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))r[e]=t[e]};return r(t,e)};return function(t,e){if(typeof e!=="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");r(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}();var __assign=this&&this.__assign||function(){__assign=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i))r[i]=t[i]}return r};return __assign.apply(this,arguments)};var __awaiter=this&&this.__awaiter||function(r,t,e,n){function i(r){return r instanceof e?r:new e((function(t){t(r)}))}return new(e||(e=Promise))((function(e,u){function s(r){try{o(n.next(r))}catch(r){u(r)}}function a(r){try{o(n["throw"](r))}catch(r){u(r)}}function o(r){r.done?e(r.value):i(r.value).then(s,a)}o((n=n.apply(r,t||[])).next())}))};var __generator=this&&this.__generator||function(r,t){var e={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},n,i,u,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(r){return function(t){return o([r,t])}}function o(a){if(n)throw new TypeError("Generator is already executing.");while(s&&(s=0,a[0]&&(e=0)),e)try{if(n=1,i&&(u=a[0]&2?i["return"]:a[0]?i["throw"]||((u=i["return"])&&u.call(i),0):i.next)&&!(u=u.call(i,a[1])).done)return u;if(i=0,u)a=[a[0]&2,u.value];switch(a[0]){case 0:case 1:u=a;break;case 4:e.label++;return{value:a[1],done:false};case 5:e.label++;i=a[1];a=[0];continue;case 7:a=e.ops.pop();e.trys.pop();continue;default:if(!(u=e.trys,u=u.length>0&&u[u.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!u||a[1]>u[0]&&a[1]<u[3])){e.label=a[1];break}if(a[0]===6&&e.label<u[1]){e.label=u[1];u=a;break}if(u&&e.label<u[2]){e.label=u[2];e.ops.push(a);break}if(u[2])e.ops.pop();e.trys.pop();continue}a=t.call(r,e)}catch(r){a=[6,r];i=0}finally{n=u=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};var __rest=this&&this.__rest||function(r,t){var e={};for(var n in r)if(Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0)e[n]=r[n];if(r!=null&&typeof Object.getOwnPropertySymbols==="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++){if(t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i]))e[n[i]]=r[n[i]]}return e};var __spreadArray=this&&this.__spreadArray||function(r,t,e){if(e||arguments.length===2)for(var n=0,i=t.length,u;n<i;n++){if(u||!(n in t)){if(!u)u=Array.prototype.slice.call(t,0,n);u[n]=t[n]}}return r.concat(u||Array.prototype.slice.call(t))};
/*!
* © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License
*/System.register([],(function(){"use strict";return{execute:function(){var r=function(r,t,e){
/*!
* MIT License
*
* Copyright (c) 2017-2022 Peculiar Ventures, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var n="[object ArrayBuffer]";var i=function(){function r(){}r.isArrayBuffer=function(r){return Object.prototype.toString.call(r)===n};r.toArrayBuffer=function(r){if(this.isArrayBuffer(r)){return r}if(r.byteLength===r.buffer.byteLength){return r.buffer}if(r.byteOffset===0&&r.byteLength===r.buffer.byteLength){return r.buffer}return this.toUint8Array(r.buffer).slice(r.byteOffset,r.byteOffset+r.byteLength).buffer};r.toUint8Array=function(r){return this.toView(r,Uint8Array)};r.toView=function(r,t){if(r.constructor===t){return r}if(this.isArrayBuffer(r)){return new t(r)}if(this.isArrayBufferView(r)){return new t(r.buffer,r.byteOffset,r.byteLength)}throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")};r.isBufferSource=function(r){return this.isArrayBufferView(r)||this.isArrayBuffer(r)};r.isArrayBufferView=function(r){return ArrayBuffer.isView(r)||r&&this.isArrayBuffer(r.buffer)};r.isEqual=function(t,e){var n=r.toUint8Array(t);var i=r.toUint8Array(e);if(n.length!==i.byteLength){return false}for(var u=0;u<n.length;u++){if(n[u]!==i[u]){return false}}return true};r.concat=function(){var r=[];for(var t=0;t<arguments.length;t++){r[t]=arguments[t]}var e;if(Array.isArray(r[0])&&!(r[1]instanceof Function)){e=r[0]}else if(Array.isArray(r[0])&&r[1]instanceof Function){e=r[0]}else{if(r[r.length-1]instanceof Function){e=r.slice(0,r.length-1)}else{e=r}}var n=0;for(var i=0,u=e;i<u.length;i++){var s=u[i];n+=s.byteLength}var a=new Uint8Array(n);var o=0;for(var f=0,c=e;f<c.length;f++){var s=c[f];var h=this.toUint8Array(s);a.set(h,o);o+=h.length}if(r[r.length-1]instanceof Function){return this.toView(a,r[r.length-1])}return a.buffer};return r}();var u="string";var s=/^[0-9a-f]+$/i;var a=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;var o=/^[a-zA-Z0-9-_]+$/;var f=function(){function r(){}r.fromString=function(r){var t=unescape(encodeURIComponent(r));var e=new Uint8Array(t.length);for(var n=0;n<t.length;n++){e[n]=t.charCodeAt(n)}return e.buffer};r.toString=function(r){var t=i.toUint8Array(r);var e="";for(var n=0;n<t.length;n++){e+=String.fromCharCode(t[n])}var u=decodeURIComponent(escape(e));return u};return r}();var c=function(){function r(){}r.toString=function(r,t){if(t===void 0){t=false}var e=i.toArrayBuffer(r);var n=new DataView(e);var u="";for(var s=0;s<e.byteLength;s+=2){var a=n.getUint16(s,t);u+=String.fromCharCode(a)}return u};r.fromString=function(r,t){if(t===void 0){t=false}var e=new ArrayBuffer(r.length*2);var n=new DataView(e);for(var i=0;i<r.length;i++){n.setUint16(i*2,r.charCodeAt(i),t)}return e};return r}();var h=function(){function r(){}r.isHex=function(r){return typeof r===u&&s.test(r)};r.isBase64=function(r){return typeof r===u&&a.test(r)};r.isBase64Url=function(r){return typeof r===u&&o.test(r)};r.ToString=function(r,t){if(t===void 0){t="utf8"}var e=i.toUint8Array(r);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(e);case"binary":return this.ToBinary(e);case"hex":return this.ToHex(e);case"base64":return this.ToBase64(e);case"base64url":return this.ToBase64Url(e);case"utf16le":return c.toString(e,true);case"utf16":case"utf16be":return c.toString(e);default:throw new Error("Unknown type of encoding '".concat(t,"'"))}};r.FromString=function(r,t){if(t===void 0){t="utf8"}if(!r){return new ArrayBuffer(0)}switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(r);case"binary":return this.FromBinary(r);case"hex":return this.FromHex(r);case"base64":return this.FromBase64(r);case"base64url":return this.FromBase64Url(r);case"utf16le":return c.fromString(r,true);case"utf16":case"utf16be":return c.fromString(r);default:throw new Error("Unknown type of encoding '".concat(t,"'"))}};r.ToBase64=function(r){var t=i.toUint8Array(r);if(typeof btoa!=="undefined"){var e=this.ToString(t,"binary");return btoa(e)}else{return Buffer.from(t).toString("base64")}};r.FromBase64=function(t){var e=this.formatString(t);if(!e){return new ArrayBuffer(0)}if(!r.isBase64(e)){throw new TypeError("Argument 'base64Text' is not Base64 encoded")}if(typeof atob!=="undefined"){return this.FromBinary(atob(e))}else{return new Uint8Array(Buffer.from(e,"base64")).buffer}};r.FromBase64Url=function(t){var e=this.formatString(t);if(!e){return new ArrayBuffer(0)}if(!r.isBase64Url(e)){throw new TypeError("Argument 'base64url' is not Base64Url encoded")}return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))};r.ToBase64Url=function(r){return this.ToBase64(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")};r.FromUtf8String=function(t,e){if(e===void 0){e=r.DEFAULT_UTF8_ENCODING}switch(e){case"ascii":return this.FromBinary(t);case"utf8":return f.fromString(t);case"utf16":case"utf16be":return c.fromString(t);case"utf16le":case"usc2":return c.fromString(t,true);default:throw new Error("Unknown type of encoding '".concat(e,"'"))}};r.ToUtf8String=function(t,e){if(e===void 0){e=r.DEFAULT_UTF8_ENCODING}switch(e){case"ascii":return this.ToBinary(t);case"utf8":return f.toString(t);case"utf16":case"utf16be":return c.toString(t);case"utf16le":case"usc2":return c.toString(t,true);default:throw new Error("Unknown type of encoding '".concat(e,"'"))}};r.FromBinary=function(r){var t=r.length;var e=new Uint8Array(t);for(var n=0;n<t;n++){e[n]=r.charCodeAt(n)}return e.buffer};r.ToBinary=function(r){var t=i.toUint8Array(r);var e="";for(var n=0;n<t.length;n++){e+=String.fromCharCode(t[n])}return e};r.ToHex=function(r){var t=i.toUint8Array(r);var e="";var n=t.length;for(var u=0;u<n;u++){var s=t[u];if(s<16){e+="0"}e+=s.toString(16)}return e};r.FromHex=function(t){var e=this.formatString(t);if(!e){return new ArrayBuffer(0)}if(!r.isHex(e)){throw new TypeError("Argument 'hexString' is not HEX encoded")}if(e.length%2){e="0".concat(e)}var n=new Uint8Array(e.length/2);for(var i=0;i<e.length;i=i+2){var u=e.slice(i,i+2);n[i/2]=parseInt(u,16)}return n.buffer};r.ToUtf16String=function(r,t){if(t===void 0){t=false}return c.toString(r,t)};r.FromUtf16String=function(r,t){if(t===void 0){t=false}return c.fromString(r,t)};r.Base64Padding=function(r){var t=4-r.length%4;if(t<4){for(var e=0;e<t;e++){r+="="}}return r};r.formatString=function(r){return(r===null||r===void 0?void 0:r.replace(/[\n\r\t ]/g,""))||""};return r}();h.DEFAULT_UTF8_ENCODING="utf8";function v(r){var t=[];for(var e=1;e<arguments.length;e++){t[e-1]=arguments[e]}var n=arguments[0];for(var i=1;i<arguments.length;i++){var u=arguments[i];for(var s in u){n[s]=u[s]}}return n}function d(){var r=[];for(var t=0;t<arguments.length;t++){r[t]=arguments[t]}var e=r.map((function(r){return r.byteLength})).reduce((function(r,t){return r+t}));var n=new Uint8Array(e);var i=0;r.map((function(r){return new Uint8Array(r)})).forEach((function(r){for(var t=0,e=r;t<e.length;t++){var u=e[t];n[i++]=u}}));return n.buffer}function l(r,t){if(!(r&&t)){return false}if(r.byteLength!==t.byteLength){return false}var e=new Uint8Array(r);var n=new Uint8Array(t);for(var i=0;i<r.byteLength;i++){if(e[i]!==n[i]){return false}}return true}function _(r,t,e,n){var i=arguments.length,u=i<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,s;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")u=Reflect.decorate(r,t,e,n);else for(var a=r.length-1;a>=0;a--)if(s=r[a])u=(i<3?s(u):i>3?s(t,e,u):s(t,e))||u;return i>3&&u&&Object.defineProperty(t,e,u),u}typeof SuppressedError==="function"?SuppressedError:function(r,t,e){var n=new Error(e);return n.name="SuppressedError",n.error=r,n.suppressed=t,n};var w=function(){function r(){}r.set=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,new Uint8Array(r)]}))}))};r.get=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,new Uint8Array(r).buffer]}))}))};return r}();function y(r){return function(e){var n=e;n.localName=r.name||n.name||n.toString().match(/^function\s*([^\s(]+)/)[1];n.items=n.items||{};n.target=e;n.items=v({},n.items);var i=new t.Type(n.localName);for(var u in n.items){var s=n.items[u];var a=void 0;if(s.repeated){a="repeated"}else if(s.required){a="required"}i.add(new t.Field(s.name,s.id,s.type,a))}n.protobuf=i}}function g(r,t,e){var n="_".concat(t);var i={set:function(r){if(this[n]!==r){this.raw=null;this[n]=r}},get:function(){if(this[n]===void 0){var r=e.defaultValue;if(e.parser&&!e.repeated){r=new e.parser}this[n]=r}return this[n]},enumerable:true};Object.defineProperty(r,n,{writable:true,enumerable:false});Object.defineProperty(r,t,i)}function p(r){return function(t,e){var n=t.constructor;var i=e;n.items=n.items||{};if(n.target!==n){n.items=v({},n.items);n.target=n}n.items[i]={id:r.id,type:r.type||"bytes",defaultValue:r.defaultValue,converter:r.converter||null,parser:r.parser||null,name:r.name||i,required:r.required||false,repeated:r.repeated||false};g(t,i,n.items[i])}}var m=function(){function r(){}r.importProto=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t=new this;return[4,t.importProto(r)];case 1:e.sent();return[2,t]}}))}))};r.prototype.isEmpty=function(){return this.raw===undefined};r.prototype.hasChanged=function(){if(this.raw===null){return true}var r=this.constructor;var t=this;for(var e in r.items){var n=r.items[e];if(n.repeated){if(n.parser){return t[e].some((function(r){return r.hasChanged()}))}}else{if(n.parser&&t[e]&&t[e].hasChanged()){return true}}}return false};r.prototype.importProto=function(t){return __awaiter(this,void 0,void 0,(function(){var e,n,i,u,s,a,o,f,c,h,v,d,l,_,w,y,g,p,m;return __generator(this,(function(b){switch(b.label){case 0:e=this.constructor;n=this;if(!(t instanceof r))return[3,2];return[4,t.exportProto()];case 1:u=b.sent();return[3,3];case 2:u=t;b.label=3;case 3:try{if(!e.protobuf){throw new Error("Protobuf schema doesn't contain 'protobuf' property")}i=e.protobuf.decode(new Uint8Array(u))}catch(r){s=r instanceof Error?r:new Error("Unknown error");throw new Error("Cannot decode message for ".concat(e.localName,".\n$ProtobufError: ").concat(s.message))}a=e.items;o=[];for(f in a)o.push(f);c=0;b.label=4;case 4:if(!(c<o.length))return[3,11];f=o[c];if(!(f in a))return[3,10];h=f;v=e.items[h];d=i[v.name];if(ArrayBuffer.isView(d)){d=new Uint8Array(d)}if(!Array.isArray(d)){if(v.repeated){n[h]=d=[]}else{d=[d]}}if(v.repeated&&!n[h]){n[h]=[]}l=0,_=d;b.label=5;case 5:if(!(l<_.length))return[3,10];w=_[l];if(!v.repeated)return[3,7];g=(y=n[h]).push;return[4,this.importItem(v,w)];case 6:g.apply(y,[b.sent()]);return[3,9];case 7:p=n;m=h;return[4,this.importItem(v,w)];case 8:p[m]=b.sent();b.label=9;case 9:l++;return[3,5];case 10:c++;return[3,4];case 11:this.raw=u;return[2]}}))}))};r.prototype.exportProto=function(){return __awaiter(this,void 0,void 0,(function(){var r,t,e,n,i,u,s,a,o,f,c,h,v,d;return __generator(this,(function(l){switch(l.label){case 0:if(!this.hasChanged()){return[2,this.raw]}r=this.constructor;t=this;e={};n=r.items;i=[];for(u in n)i.push(u);s=0;l.label=1;case 1:if(!(s<i.length))return[3,6];u=i[s];if(!(u in n))return[3,5];a=u;o=r.items[a];f=t[a];if(!Array.isArray(f)){f=f===void 0?[]:[f]}c=0,h=f;l.label=2;case 2:if(!(c<h.length))return[3,5];v=h[c];return[4,this.exportItem(o,v)];case 3:d=l.sent();if(o.repeated){if(!e[o.name]){e[o.name]=[]}e[o.name].push(d)}else{e[o.name]=d}l.label=4;case 4:c++;return[3,2];case 5:s++;return[3,1];case 6:this.raw=new Uint8Array(r.protobuf.encode(e).finish()).buffer;return[2,this.raw]}}))}))};r.prototype.exportItem=function(r,t){return __awaiter(this,void 0,void 0,(function(){var e,n,i,u;return __generator(this,(function(s){switch(s.label){case 0:e=this.constructor;if(!r.parser)return[3,2];i=t;return[4,i.exportProto()];case 1:u=s.sent();if(r.required&&!u){throw new Error("Parameter '".concat(r.name,"' is required in '").concat(e.localName,"' protobuf message."))}if(u){n=new Uint8Array(u)}return[3,6];case 2:if(r.required&&t===undefined){throw new Error("Parameter '".concat(r.name,"' is required in '").concat(e.localName,"' protobuf message."))}if(!r.converter)return[3,5];if(!(t!==undefined))return[3,4];return[4,r.converter.set(t)];case 3:n=s.sent();s.label=4;case 4:return[3,6];case 5:if(t instanceof ArrayBuffer){t=new Uint8Array(t)}n=t;s.label=6;case 6:return[2,n]}}))}))};r.prototype.importItem=function(r,t){return __awaiter(this,void 0,void 0,(function(){var e,n,i;return __generator(this,(function(u){switch(u.label){case 0:e=this.constructor;if(!r.parser)return[3,4];i=r.parser;if(!(t&&t.byteLength))return[3,2];return[4,i.importProto(new Uint8Array(t).buffer)];case 1:n=u.sent();return[3,3];case 2:if(r.required){throw new Error("Parameter '".concat(r.name,"' is required in '").concat(e.localName,"' protobuf message."))}u.label=3;case 3:return[3,9];case 4:if(!r.converter)return[3,8];if(!(t&&t.byteLength))return[3,6];return[4,r.converter.get(t)];case 5:n=u.sent();return[3,7];case 6:if(r.required){throw new Error("Parameter '".concat(r.name,"' is required in '").concat(e.localName,"' protobuf message."))}u.label=7;case 7:return[3,9];case 8:n=t;u.label=9;case 9:return[2,n]}}))}))};return r}();function b(){}b.prototype=Object.create(null);function A(){A.init.call(this)}A.EventEmitter=A;A.usingDomains=false;A.prototype.domain=undefined;A.prototype._events=undefined;A.prototype._maxListeners=undefined;A.defaultMaxListeners=10;A.init=function(){this.domain=null;if(!this._events||this._events===Object.getPrototypeOf(this)._events){this._events=new b;this._eventsCount=0}this._maxListeners=this._maxListeners||undefined};A.prototype.setMaxListeners=function r(t){if(typeof t!=="number"||t<0||isNaN(t))throw new TypeError('"n" argument must be a positive number');this._maxListeners=t;return this};function x(r){if(r._maxListeners===undefined)return A.defaultMaxListeners;return r._maxListeners}A.prototype.getMaxListeners=function r(){return x(this)};function k(r,t,e){if(t)r.call(e);else{var n=r.length;var i=j(r,n);for(var u=0;u<n;++u)i[u].call(e)}}function E(r,t,e,n){if(t)r.call(e,n);else{var i=r.length;var u=j(r,i);for(var s=0;s<i;++s)u[s].call(e,n)}}function S(r,t,e,n,i){if(t)r.call(e,n,i);else{var u=r.length;var s=j(r,u);for(var a=0;a<u;++a)s[a].call(e,n,i)}}function B(r,t,e,n,i,u){if(t)r.call(e,n,i,u);else{var s=r.length;var a=j(r,s);for(var o=0;o<s;++o)a[o].call(e,n,i,u)}}function U(r,t,e,n){if(t)r.apply(e,n);else{var i=r.length;var u=j(r,i);for(var s=0;s<i;++s)u[s].apply(e,n)}}A.prototype.emit=function r(t){var e,n,i,u,s,a,o;var f=t==="error";a=this._events;if(a)f=f&&a.error==null;else if(!f)return false;o=this.domain;if(f){e=arguments[1];if(o){if(!e)e=new Error('Uncaught, unspecified "error" event');e.domainEmitter=this;e.domain=o;e.domainThrown=false;o.emit("error",e)}else if(e instanceof Error){throw e}else{var c=new Error('Uncaught, unspecified "error" event. ('+e+")");c.context=e;throw c}return false}n=a[t];if(!n)return false;var h=typeof n==="function";i=arguments.length;switch(i){case 1:k(n,h,this);break;case 2:E(n,h,this,arguments[1]);break;case 3:S(n,h,this,arguments[1],arguments[2]);break;case 4:B(n,h,this,arguments[1],arguments[2],arguments[3]);break;default:u=new Array(i-1);for(s=1;s<i;s++)u[s-1]=arguments[s];U(n,h,this,u)}return true};function I(r,t,e,n){var i;var u;var s;if(typeof e!=="function")throw new TypeError('"listener" argument must be a function');u=r._events;if(!u){u=r._events=new b;r._eventsCount=0}else{if(u.newListener){r.emit("newListener",t,e.listener?e.listener:e);u=r._events}s=u[t]}if(!s){s=u[t]=e;++r._eventsCount}else{if(typeof s==="function"){s=u[t]=n?[e,s]:[s,e]}else{if(n){s.unshift(e)}else{s.push(e)}}if(!s.warned){i=x(r);if(i&&i>0&&s.length>i){s.warned=true;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. "+"Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning";a.emitter=r;a.type=t;a.count=s.length;N(a)}}}return r}function N(r){typeof console.warn==="function"?console.warn(r):console.log(r)}A.prototype.addListener=function r(t,e){return I(this,t,e,false)};A.prototype.on=A.prototype.addListener;A.prototype.prependListener=function r(t,e){return I(this,t,e,true)};function C(r,t,e){var n=false;function i(){r.removeListener(t,i);if(!n){n=true;e.apply(r,arguments)}}i.listener=e;return i}A.prototype.once=function r(t,e){if(typeof e!=="function")throw new TypeError('"listener" argument must be a function');this.on(t,C(this,t,e));return this};A.prototype.prependOnceListener=function r(t,e){if(typeof e!=="function")throw new TypeError('"listener" argument must be a function');this.prependListener(t,C(this,t,e));return this};A.prototype.removeListener=function r(t,e){var n,i,u,s,a;if(typeof e!=="function")throw new TypeError('"listener" argument must be a function');i=this._events;if(!i)return this;n=i[t];if(!n)return this;if(n===e||n.listener&&n.listener===e){if(--this._eventsCount===0)this._events=new b;else{delete i[t];if(i.removeListener)this.emit("removeListener",t,n.listener||e)}}else if(typeof n!=="function"){u=-1;for(s=n.length;s-- >0;){if(n[s]===e||n[s].listener&&n[s].listener===e){a=n[s].listener;u=s;break}}if(u<0)return this;if(n.length===1){n[0]=undefined;if(--this._eventsCount===0){this._events=new b;return this}else{delete i[t]}}else{T(n,u)}if(i.removeListener)this.emit("removeListener",t,a||e)}return this};A.prototype.removeAllListeners=function r(t){var e,n;n=this._events;if(!n)return this;if(!n.removeListener){if(arguments.length===0){this._events=new b;this._eventsCount=0}else if(n[t]){if(--this._eventsCount===0)this._events=new b;else delete n[t]}return this}if(arguments.length===0){var i=Object.keys(n);for(var u=0,s;u<i.length;++u){s=i[u];if(s==="removeListener")continue;this.removeAllListeners(s)}this.removeAllListeners("removeListener");this._events=new b;this._eventsCount=0;return this}e=n[t];if(typeof e==="function"){this.removeListener(t,e)}else if(e){do{this.removeListener(t,e[e.length-1])}while(e[0])}return this};A.prototype.listeners=function r(t){var e;var n;var i=this._events;if(!i)n=[];else{e=i[t];if(!e)n=[];else if(typeof e==="function")n=[e.listener||e];else n=O(e)}return n};A.listenerCount=function(r,t){if(typeof r.listenerCount==="function"){return r.listenerCount(t)}else{return q.call(r,t)}};A.prototype.listenerCount=q;function q(r){var t=this._events;if(t){var e=t[r];if(typeof e==="function"){return 1}else if(e){return e.length}}return 0}A.prototype.eventNames=function r(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function T(r,t){for(var e=t,n=e+1,i=r.length;n<i;e+=1,n+=1)r[e]=r[n];r.pop()}function j(r,t){var e=new Array(t);while(t--)e[t]=r[t];return e}function O(r){var t=new Array(r.length);for(var e=0;e<t.length;++e){t[e]=r[e].listener||r[e]}return t}var D="ECDSA";var K="ECDH";var P="AES-CBC";var V="SHA-256";var R="HMAC";var M=20;var W=h.FromBinary("InfoText");var z=h.FromBinary("InfoRatchet");var H=h.FromBinary("InfoMessageKeys");var G=null;if(typeof self!=="undefined"){G={crypto:self.crypto,name:"WebCrypto"}}function L(r,t){G={crypto:t,name:r}}function F(){if(!G){throw new Error("WebCrypto engine is empty. Use setEngine to resolve it.")}return G}var J=function(){var r=function(){function r(){}r.generateKeyPair=function(r,t){return __awaiter(this,void 0,void 0,(function(){var e,n,i,u,s;return __generator(this,(function(a){switch(a.label){case 0:e=r;n=r==="ECDSA"?["sign","verify"]:["deriveKey","deriveBits"];return[4,F().crypto.subtle.generateKey({name:e,namedCurve:this.NAMED_CURVE},t,n)];case 1:i=a.sent();return[4,X.create(i.publicKey)];case 2:u=a.sent();s={privateKey:i.privateKey,publicKey:u};return[2,s]}}))}))};r.deriveBytes=function(r,t){return F().crypto.subtle.deriveBits({name:"ECDH",public:t.key},r,256)};r.verify=function(r,t,e){return F().crypto.subtle.verify({name:"ECDSA",hash:this.DIGEST_ALGORITHM},r.key,e,t)};r.sign=function(r,t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){return[2,F().crypto.subtle.sign({name:"ECDSA",hash:this.DIGEST_ALGORITHM},r,t)]}))}))};r.ecKeyPairToJson=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t={privateKey:r.privateKey,publicKey:r.publicKey.key};return[4,r.publicKey.thumbprint()];case 1:return[2,(t.thumbprint=e.sent(),t)]}}))}))};r.ecKeyPairFromJson=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t={privateKey:r.privateKey};return[4,X.create(r.publicKey)];case 1:return[2,(t.publicKey=e.sent(),t)]}}))}))};return r}();r.NAMED_CURVE="P-256";r.DIGEST_ALGORITHM="SHA-512";return r}();var Z={name:"AES-CBC",length:256};var $=function(){function r(){}r.randomBytes=function(r){var t=new Uint8Array(r);F().crypto.getRandomValues(t);return t.buffer};r.digest=function(r,t){return F().crypto.subtle.digest(r,t)};r.encrypt=function(r,t,e){return F().crypto.subtle.encrypt({name:P,iv:new Uint8Array(e)},r,t)};r.decrypt=function(r,t,e){return F().crypto.subtle.decrypt({name:P,iv:new Uint8Array(e)},r,t)};r.importHMAC=function(r){return F().crypto.subtle.importKey("raw",r,{name:R,hash:{name:V}},false,["sign","verify"])};r.importAES=function(r){return F().crypto.subtle.importKey("raw",r,Z,false,["encrypt","decrypt"])};r.sign=function(r,t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){switch(e.label){case 0:return[4,F().crypto.subtle.sign({name:R,hash:V},r,t)];case 1:return[2,e.sent()]}}))}))};r.HKDF=function(r){return __awaiter(this,arguments,void 0,(function(r,t,e,n){var i,u,s,a,o,f;if(t===void 0){t=1}if(n===void 0){n=new ArrayBuffer(0)}return __generator(this,(function(c){switch(c.label){case 0:if(!!e)return[3,2];return[4,this.importHMAC(new Uint8Array(32).buffer)];case 1:e=c.sent();c.label=2;case 2:return[4,this.sign(e,r)];case 3:i=c.sent();return[4,this.importHMAC(i)];case 4:u=c.sent();s=[new ArrayBuffer(0)];a=0;c.label=5;case 5:if(!(a<t))return[3,8];o=s;f=a+1;return[4,this.sign(u,d(s[a],n,new Uint8Array([a+1]).buffer))];case 6:o[f]=c.sent();c.label=7;case 7:a++;return[3,5];case 8:return[2,s.slice(1)]}}))}))};return r}();var X=function(){function r(){}r.create=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n,i,u,s,a;return __generator(this,(function(o){switch(o.label){case 0:t=new this;e=r.algorithm.name.toUpperCase();if(!(e==="ECDH"||e==="ECDSA")){throw new Error("Error: Unsupported asymmetric key algorithm.")}if(r.type!=="public"){throw new Error("Error: Expected key type to be public but it was not.")}t.key=r;return[4,F().crypto.subtle.exportKey("jwk",r)];case 1:n=o.sent();if(!(n.x&&n.y)){throw new Error("Wrong JWK data for EC public key. Parameters x and y are required.")}i=h.FromBase64Url(n.x);u=h.FromBase64Url(n.y);s=h.ToBinary(i)+h.ToBinary(u);t.serialized=h.FromBinary(s);a=t;return[4,t.thumbprint()];case 2:a.id=o.sent();return[2,t]}}))}))};r.importKey=function(t,e){return __awaiter(this,void 0,void 0,(function(){var n,i,u,s,a,o;return __generator(this,(function(f){switch(f.label){case 0:n=h.ToBase64Url(t.slice(0,32));i=h.ToBase64Url(t.slice(32));u={crv:J.NAMED_CURVE,kty:"EC",x:n,y:i};s=e==="ECDSA"?["verify"]:[];return[4,F().crypto.subtle.importKey("jwk",u,{name:e,namedCurve:J.NAMED_CURVE},true,s)];case 1:a=f.sent();return[4,r.create(a)];case 2:o=f.sent();return[2,o]}}))}))};r.prototype.serialize=function(){return this.serialized};r.prototype.thumbprint=function(){return __awaiter(this,void 0,void 0,(function(){var r,t;return __generator(this,(function(e){switch(e.label){case 0:return[4,this.serialize()];case 1:r=e.sent();return[4,$.digest("SHA-256",r)];case 2:t=e.sent();return[2,h.ToHex(t)]}}))}))};r.prototype.isEqual=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){if(!(t&&t instanceof r)){return[2,false]}return[2,l(this.serialized,t.serialized)]}))}))};return r}();var Q=function(){function r(r,t,e){this.id=r;this.signingKey=t;this.exchangeKey=e;this.preKeys=[];this.signedPreKeys=[]}r.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n;return __generator(this,(function(i){switch(i.label){case 0:return[4,J.ecKeyPairFromJson(r.signingKey)];case 1:t=i.sent();return[4,J.ecKeyPairFromJson(r.exchangeKey)];case 2:e=i.sent();n=new this(r.id,t,e);n.createdAt=new Date(r.createdAt);return[4,n.fromJSON(r)];case 3:i.sent();return[2,n]}}))}))};r.create=function(t){return __awaiter(this,arguments,void 0,(function(t,e,n,i){var u,s,a,o,f,c,o,h,v;if(e===void 0){e=0}if(n===void 0){n=0}if(i===void 0){i=false}return __generator(this,(function(d){switch(d.label){case 0:return[4,J.generateKeyPair(D,i)];case 1:u=d.sent();return[4,J.generateKeyPair(K,i)];case 2:s=d.sent();a=new r(t,u,s);a.createdAt=new Date;o=0;d.label=3;case 3:if(!(o<n))return[3,6];c=(f=a.preKeys).push;return[4,J.generateKeyPair("ECDH",i)];case 4:c.apply(f,[d.sent()]);d.label=5;case 5:o++;return[3,3];case 6:o=0;d.label=7;case 7:if(!(o<e))return[3,10];v=(h=a.signedPreKeys).push;return[4,J.generateKeyPair("ECDH",i)];case 8:v.apply(h,[d.sent()]);d.label=9;case 9:o++;return[3,7];case 10:return[2,a]}}))}))};r.prototype.toJSON=function(){return __awaiter(this,void 0,void 0,(function(){var r,t,e,n,i,u,s,a,o,i,f,c;var h;return __generator(this,(function(v){switch(v.label){case 0:r=[];t=[];e=0,n=this.preKeys;v.label=1;case 1:if(!(e<n.length))return[3,4];i=n[e];s=(u=r).push;return[4,J.ecKeyPairToJson(i)];case 2:s.apply(u,[v.sent()]);v.label=3;case 3:e++;return[3,1];case 4:a=0,o=this.signedPreKeys;v.label=5;case 5:if(!(a<o.length))return[3,8];i=o[a];c=(f=t).push;return[4,J.ecKeyPairToJson(i)];case 6:c.apply(f,[v.sent()]);v.label=7;case 7:a++;return[3,5];case 8:h={createdAt:this.createdAt.toISOString()};return[4,J.ecKeyPairToJson(this.exchangeKey)];case 9:h.exchangeKey=v.sent(),h.id=this.id,h.preKeys=r,h.signedPreKeys=t;return[4,J.ecKeyPairToJson(this.signingKey)];case 10:return[2,(h.signingKey=v.sent(),h)]}}))}))};r.prototype.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n,i,u,s,a,o,f,u,c,h;return __generator(this,(function(v){switch(v.label){case 0:this.id=r.id;t=this;return[4,J.ecKeyPairFromJson(r.signingKey)];case 1:t.signingKey=v.sent();e=this;return[4,J.ecKeyPairFromJson(r.exchangeKey)];case 2:e.exchangeKey=v.sent();this.preKeys=[];n=0,i=r.preKeys;v.label=3;case 3:if(!(n<i.length))return[3,6];u=i[n];a=(s=this.preKeys).push;return[4,J.ecKeyPairFromJson(u)];case 4:a.apply(s,[v.sent()]);v.label=5;case 5:n++;return[3,3];case 6:this.signedPreKeys=[];o=0,f=r.signedPreKeys;v.label=7;case 7:if(!(o<f.length))return[3,10];u=f[o];h=(c=this.signedPreKeys).push;return[4,J.ecKeyPairFromJson(u)];case 8:h.apply(c,[v.sent()]);v.label=9;case 9:o++;return[3,7];case 10:return[2]}}))}))};return r}();var Y=function(){function r(){}r.fill=function(t){var e=new r;e.fill(t);return e};r.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t=new this;return[4,t.fromJSON(r)];case 1:e.sent();return[2,t]}}))}))};r.prototype.fill=function(r){this.signingKey=r.signingKey;this.exchangeKey=r.exchangeKey;this.signature=r.signature;this.createdAt=r.createdAt};r.prototype.verify=function(){return J.verify(this.signingKey,this.exchangeKey.serialize(),this.signature)};r.prototype.toJSON=function(){return __awaiter(this,void 0,void 0,(function(){var r;return __generator(this,(function(t){switch(t.label){case 0:r={createdAt:this.createdAt.toISOString()};return[4,this.exchangeKey.key];case 1:r.exchangeKey=t.sent(),r.id=this.id,r.signature=this.signature;return[4,this.signingKey.key];case 2:r.signingKey=t.sent();return[4,this.signingKey.thumbprint()];case 3:return[2,(r.thumbprint=t.sent(),r)]}}))}))};r.prototype.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n;return __generator(this,(function(i){switch(i.label){case 0:this.id=r.id;this.signature=r.signature;t=this;return[4,X.create(r.signingKey)];case 1:t.signingKey=i.sent();e=this;return[4,X.create(r.exchangeKey)];case 2:e.exchangeKey=i.sent();this.createdAt=new Date(r.createdAt);return[4,this.verify()];case 3:n=i.sent();if(!n){throw new Error("Error: Wrong signature for RemoteIdentity")}return[2]}}))}))};return r}();var rr=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}return t}(m);_([p({id:0,type:"uint32",defaultValue:1})],r.prototype,"version",void 0);r=_([y({name:"Base"})],r);return r}();var tr=function(){function r(){}r.set=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,new Uint8Array(r.serialize())]}))}))};r.get=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,X.importKey(r.buffer,"ECDSA")]}))}))};return r}();var er=function(){function r(){}r.set=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,new Uint8Array(r.serialize())]}))}))};r.get=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,X.importKey(r.buffer,"ECDH")]}))}))};return r}();var nr=function(){function r(){}r.set=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,new Uint8Array(h.FromString(r.toISOString()))]}))}))};r.get=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,new Date(h.ToString(r))]}))}))};return r}();var ir=function(){var r;var t=r=function(t){__extends(e,t);function e(){return t!==null&&t.apply(this,arguments)||this}e.fill=function(t){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(n){switch(n.label){case 0:e=new r;return[4,e.fill(t)];case 1:n.sent();return[2,e]}}))}))};e.prototype.sign=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t=this;return[4,J.sign(r,this.exchangeKey.serialize())];case 1:t.signature=e.sent();return[2]}}))}))};e.prototype.verify=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(r){switch(r.label){case 0:return[4,J.verify(this.signingKey,this.exchangeKey.serialize(),this.signature)];case 1:return[2,r.sent()]}}))}))};e.prototype.fill=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:this.signingKey=r.signingKey.publicKey;this.exchangeKey=r.exchangeKey.publicKey;this.createdAt=r.createdAt;return[4,this.sign(r.signingKey.privateKey)];case 1:t.sent();return[2]}}))}))};return e}(rr);_([p({id:1,converter:tr})],t.prototype,"signingKey",void 0);_([p({id:2,converter:er})],t.prototype,"exchangeKey",void 0);_([p({id:3})],t.prototype,"signature",void 0);_([p({id:4,converter:nr})],t.prototype,"createdAt",void 0);t=r=_([y({name:"Identity"})],t);return t}();var ur=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}return t}(rr);_([p({id:1,converter:er,required:true})],r.prototype,"senderRatchetKey",void 0);_([p({id:2,type:"uint32",required:true})],r.prototype,"counter",void 0);_([p({id:3,type:"uint32",required:true})],r.prototype,"previousCounter",void 0);_([p({id:4,converter:w,required:true})],r.prototype,"cipherText",void 0);r=_([y({name:"Message"})],r);return r}();var sr=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}t.prototype.sign=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t=this;return[4,this.signHMAC(r)];case 1:t.signature=e.sent();return[2]}}))}))};t.prototype.verify=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:return[4,this.signHMAC(r)];case 1:t=e.sent();return[2,l(t,this.signature)]}}))}))};t.prototype.getSignedRaw=function(){return __awaiter(this,void 0,void 0,(function(){var r,t,e,n;return __generator(this,(function(i){switch(i.label){case 0:r=this.receiverKey.serialize();t=this.senderKey.serialize();return[4,this.message.exportProto()];case 1:e=i.sent();n=d(r,t,e);return[2,n]}}))}))};t.prototype.signHMAC=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e;return __generator(this,(function(n){switch(n.label){case 0:return[4,this.getSignedRaw()];case 1:t=n.sent();return[4,$.sign(r,t)];case 2:e=n.sent();return[2,e]}}))}))};return t}(rr);_([p({id:1,converter:tr,required:true})],r.prototype,"senderKey",void 0);_([p({id:2,parser:ur,required:true})],r.prototype,"message",void 0);_([p({id:3,required:true})],r.prototype,"signature",void 0);r=_([y({name:"MessageSigned"})],r);return r}();var ar=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}return t}(rr);_([p({id:1,type:"uint32",required:true})],r.prototype,"registrationId",void 0);_([p({id:2,type:"uint32"})],r.prototype,"preKeyId",void 0);_([p({id:3,type:"uint32",required:true})],r.prototype,"preKeySignedId",void 0);_([p({id:4,converter:er,required:true})],r.prototype,"baseKey",void 0);_([p({id:5,parser:ir,required:true})],r.prototype,"identity",void 0);_([p({id:6,parser:sr,required:true})],r.prototype,"signedMessage",void 0);r=_([y({name:"PreKeyMessage"})],r);return r}();var or=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}return t}(rr);_([p({id:1,type:"uint32",required:true})],r.prototype,"id",void 0);_([p({id:2,converter:er,required:true})],r.prototype,"key",void 0);r=_([y({name:"PreKey"})],r);return r}();var fr=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}t.prototype.sign=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:t=this;return[4,J.sign(r,this.key.serialize())];case 1:t.signature=e.sent();return[2]}}))}))};t.prototype.verify=function(r){return J.verify(r,this.key.serialize(),this.signature)};return t}(or);_([p({id:3,converter:w,required:true})],r.prototype,"signature",void 0);r=_([y({name:"PreKeySigned"})],r);return r}();var cr=function(){var r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}return t}(rr);_([p({id:1,type:"uint32",required:true})],r.prototype,"registrationId",void 0);_([p({id:2,parser:ir,required:true})],r.prototype,"identity",void 0);_([p({id:3,parser:or})],r.prototype,"preKey",void 0);_([p({id:4,parser:fr,required:true})],r.prototype,"preKeySigned",void 0);r=_([y({name:"PreKeyBundle"})],r);return r}();var hr=function(){function r(r){if(r===void 0){r=20}this.items=[];this.maxSize=r}Object.defineProperty(r.prototype,"length",{get:function(){return this.items.length},enumerable:false,configurable:true});Object.defineProperty(r.prototype,"latest",{get:function(){return this.items[this.length-1]},enumerable:false,configurable:true});r.prototype.push=function(r){if(this.length===this.maxSize){this.items=this.items.slice(1)}this.items.push(r)};r.prototype.toJSON=function(){return __awaiter(this,void 0,void 0,(function(){var r,t,e,n,i,u;return __generator(this,(function(s){switch(s.label){case 0:r=[];t=0,e=this.items;s.label=1;case 1:if(!(t<e.length))return[3,4];n=e[t];u=(i=r).push;return[4,n.toJSON()];case 2:u.apply(i,[s.sent()]);s.label=3;case 3:t++;return[3,1];case 4:return[2,r]}}))}))};r.prototype.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.items=r;return[2]}))}))};return r}();var vr=new Uint8Array([1]).buffer;var dr=new Uint8Array([2]).buffer;var lr=function(){function r(r){this.counter=0;this.rootKey=r}r.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){t=new this(r.rootKey);t.fromJSON(r);return[2,t]}))}))};r.prototype.toJSON=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(r){return[2,{counter:this.counter,rootKey:this.rootKey}]}))}))};r.prototype.fromJSON=function(r){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.counter=r.counter;this.rootKey=r.rootKey;return[2]}))}))};r.prototype.calculateKey=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n;var i;return __generator(this,(function(u){switch(u.label){case 0:return[4,$.sign(r,vr)];case 1:t=u.sent();return[4,$.sign(r,dr)];case 2:e=u.sent();i={cipher:t};return[4,$.importHMAC(e)];case 3:n=(i.rootKey=u.sent(),i);return[2,n]}}))}))};r.prototype.click=function(){return __awaiter(this,void 0,void 0,(function(){var r,t;return __generator(this,(function(e){switch(e.label){case 0:r=this.rootKey;return[4,this.calculateKey(r)];case 1:t=e.sent();this.rootKey=t.rootKey;this.counter++;return[2,t.cipher]}}))}))};return r}();var _r=function(r){__extends(t,r);function t(){return r!==null&&r.apply(this,arguments)||this}t.prototype.encrypt=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n,i,u,s;return __generator(this,(function(a){switch(a.label){case 0:return[4,this.click()];case 1:t=a.sent();return[4,$.HKDF(t,3,void 0,H)];case 2:e=a.sent();return[4,$.importAES(e[0])];case 3:n=a.sent();return[4,$.importHMAC(e[1])];case 4:i=a.sent();u=e[2].slice(0,16);return[4,$.encrypt(n,r,u)];case 5:s=a.sent();return[2,{cipherText:s,hmacKey:i}]}}))}))};return t}(lr);var wr=function(r){__extends(t,r);function t(){var t=r.apply(this,arguments)||this;t.keys=[];return t}t.prototype.toJSON=function(){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:return[4,r.prototype.toJSON.call(this)];case 1:t=e.sent();t.keys=this.keys;return[2,t]}}))}))};t.prototype.fromJSON=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){switch(e.label){case 0:return[4,r.prototype.fromJSON.call(this,t)];case 1:e.sent();this.keys=t.keys;return[2]}}))}))};t.prototype.decrypt=function(r,t){return __awaiter(this,void 0,void 0,(function(){var e,n,i,u,s,a;return __generator(this,(function(o){switch(o.label){case 0:return[4,this.getKey(t)];case 1:e=o.sent();return[4,$.HKDF(e,3,void 0,H)];case 2:n=o.sent();return[4,$.importAES(n[0])];case 3:i=o.sent();return[4,$.importHMAC(n[1])];case 4:u=o.sent();s=n[2].slice(0,16);return[4,$.decrypt(i,r,s)];case 5:a=o.sent();return[2,{cipherText:a,hmacKey:u}]}}))}))};t.prototype.getKey=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e;return __generator(this,(function(n){switch(n.label){case 0:if(!(this.counter<=r))return[3,2];return[4,this.click()];case 1:t=n.sent();this.keys.push(t);return[3,0];case 2:e=this.keys[r];return[2,e]}}))}))};return t}(lr);function yr(r,t,e,n,i){return __awaiter(this,void 0,void 0,(function(){var u,s,a,o,f,c,h,v,l;return __generator(this,(function(_){switch(_.label){case 0:return[4,J.deriveBytes(r.exchangeKey.privateKey,n)];case 1:u=_.sent();return[4,J.deriveBytes(t.privateKey,e)];case 2:s=_.sent();return[4,J.deriveBytes(t.privateKey,n)];case 3:a=_.sent();o=new ArrayBuffer(0);if(!i)return[3,5];return[4,J.deriveBytes(t.privateKey,i)];case 4:o=_.sent();_.label=5;case 5:f=new Uint8Array(32);for(c=0;c<f.length;c++){f[c]=255}h=f.buffer;v=d(h,u,s,a,o);return[4,$.HKDF(v,1,void 0,W)];case 6:l=_.sent();return[4,$.importHMAC(l[0])];case 7:return[2,_.sent()]}}))}))}function gr(r,t,e,n,i){return __awaiter(this,void 0,void 0,(function(){var u,s,a,o,f,c,h,v,l;return __generator(this,(function(_){switch(_.label){case 0:return[4,J.deriveBytes(t.privateKey,e)];case 1:u=_.sent();return[4,J.deriveBytes(r.exchangeKey.privateKey,n)];case 2:s=_.sent();return[4,J.deriveBytes(t.privateKey,n)];case 3:a=_.sent();o=new ArrayBuffer(0);if(!i)return[3,5];return[4,J.deriveBytes(i,n)];case 4:o=_.sent();_.label=5;case 5:f=new Uint8Array(32);for(c=0;c<f.length;c++){f[c]=255}h=f.buffer;v=d(h,u,s,a,o);return[4,$.HKDF(v,1,void 0,W)];case 6:l=_.sent();return[4,$.importHMAC(l[0])];case 7:return[2,_.sent()]}}))}))}var pr=function(r){__extends(t,r);function t(t){if(t===void 0){t={}}var e=r.call(this)||this;e.options=t;e.counter=0;e.currentStep=new mr;e.steps=new br(M);e.promises={};return e}t.create=function(r,e){return __awaiter(this,arguments,void 0,(function(r,e,n){var i,u,s,a,o;if(n===void 0){n={}}return __generator(this,(function(f){switch(f.label){case 0:u=new t(n);if(!(e instanceof cr))return[3,5];return[4,e.identity.verify()];case 1:if(!f.sent()){throw new Error("Error: Remote client's identity key is invalid.")}return[4,e.preKeySigned.verify(e.identity.signingKey)];case 2:if(!f.sent()){throw new Error("Error: Remote client's signed prekey is invalid.")}s=u;return[4,u.generateRatchetKey()];case 3:s.currentRatchetKey=f.sent();u.currentStep.remoteRatchetKey=e.preKeySigned.key;u.remoteIdentity=Y.fill(e.identity);u.remoteIdentity.id=e.registrationId;u.remotePreKeyId=e.preKey.id;u.remotePreKeySignedId=e.preKeySigned.id;return[4,yr(r,u.currentRatchetKey,e.identity.exchangeKey,e.preKeySigned.key,e.preKey.key)];case 4:i=f.sent();return[3,8];case 5:return[4,e.identity.verify()];case 6:if(!f.sent()){throw new Error("Error: Remote client's identity key is invalid.")}a=r.signedPreKeys[e.preKeySignedId];if(!a){throw new Error("Error: PreKey with id ".concat(e.preKeySignedId," not found"))}o=void 0;if(e.preKeyId!==void 0){o=r.preKeys[e.preKeyId]}u.remoteIdentity=Y.fill(e.identity);u.currentRatchetKey=a;return[4,gr(r,u.currentRatchetKey,e.identity.exchangeKey,e.signedMessage.message.senderRatchetKey,o&&o.privateKey)];case 7:i=f.sent();f.label=8;case 8:u.identity=r;u.id=r.id;u.rootKey=i;return[2,u]}}))}))};t.fromJSON=function(r,e,n){return __awaiter(this,void 0,void 0,(function(){var i;return __generator(this,(function(u){switch(u.label){case 0:i=new t;i.identity=r;i.remoteIdentity=e;return[4,i.fromJSON(n)];case 1:u.sent();return[2,i]}}))}))};t.prototype.on=function(t,e){return r.prototype.on.call(this,t,e)};t.prototype.once=function(t,e){return r.prototype.once.call(this,t,e)};t.prototype.decrypt=function(r){return __awaiter(this,void 0,void 0,(function(){var t=this;return __generator(this,(function(e){return[2,this.queuePromise("encrypt",(function(){return __awaiter(t,void 0,void 0,(function(){var t,e,n,i,u,s;return __generator(this,(function(a){switch(a.label){case 0:t=r.message.senderRatchetKey;e=r.message;if(r.message.previousCounter<this.counter-M){throw new Error("Error: Too old message")}n=this.steps.getStep(t);if(!n){i=new mr;i.remoteRatchetKey=t;this.steps.push(i);this.currentStep=i;n=i}if(!!n.receivingChain)return[3,2];u=n;return[4,this.createChain(this.currentRatchetKey.privateKey,t,wr)];case 1:u.receivingChain=a.sent();a.label=2;case 2:return[4,n.receivingChain.decrypt(e.cipherText,e.counter)];case 3:s=a.sent();this.update();r.senderKey=this.remoteIdentity.signingKey;r.receiverKey=this.identity.signingKey.publicKey;return[4,r.verify(s.hmacKey)];case 4:if(!a.sent()){throw new Error("Error: The Message did not successfully verify!")}return[2,s.cipherText]}}))}))}))]}))}))};t.prototype.encrypt=function(r){return __awaiter(this,void 0,void 0,(function(){var t=this;return __generator(this,(function(e){return[2,this.queuePromise("encrypt",(function(){return __awaiter(t,void 0,void 0,(function(){var t,e,n,i,u;return __generator(this,(function(s){switch(s.label){case 0:if(!(this.currentStep.receivingChain&&!this.currentStep.sendingChain))return[3,2];this.counter++;t=this;return[4,this.generateRatchetKey()];case 1:t.currentRatchetKey=s.sent();s.label=2;case 2:if(!!this.currentStep.sendingChain)return[3,4];if(!this.currentStep.remoteRatchetKey){throw new Error("currentStep has empty remoteRatchetKey")}e=this.currentStep;return[4,this.createChain(this.currentRatchetKey.privateKey,this.currentStep.remoteRatchetKey,_r)];case 3:e.sendingChain=s.sent();s.label=4;case 4:return[4,this.currentStep.sendingChain.encrypt(r)];case 5:n=s.sent();this.update();if(!(this.steps.length===0&&!this.currentStep.receivingChain&&this.currentStep.sendingChain.counter===1))return[3,7];i=new ar;i.registrationId=this.identity.id;i.preKeyId=this.remotePreKeyId;i.preKeySignedId=this.remotePreKeySignedId;i.baseKey=this.currentRatchetKey.publicKey;return[4,i.identity.fill(this.identity)];case 6:s.sent();s.label=7;case 7:u=new sr;u.receiverKey=this.remoteIdentity.signingKey;u.senderKey=this.identity.signingKey.publicKey;u.message.cipherText=n.cipherText;u.message.counter=this.currentStep.sendingChain.counter-1;u.message.previousCounter=this.counter;u.message.senderRatchetKey=this.currentRatchetKey.publicKey;return[4,u.sign(n.hmacKey)];case 8:s.sent();if(i){i.signedMessage=u;return[2,i]}else{return[2,u]}return[2]}}))}))}))]}))}))};t.prototype.hasRatchetKey=function(r){return __awaiter(this,void 0,void 0,(function(){var t,e,n,i;return __generator(this,(function(u){switch(u.label){case 0:if(!!(r instanceof X))return[3,2];return[4,X.create(r)];case 1:t=u.sent();return[3,3];case 2:t=r;u.label=3;case 3:e=0,n=this.steps.items;u.label=4;case 4:if(!(e<n.length))return[3,7];i=n[e];return[4,i.remoteRatchetKey.isEqual(t)];case 5:if(u.sent()){return[2,true]}u.label=6;case 6:e++;return[3,4];case 7:return[2,false]}}))}))};t.prototype.toJSON=function(){return __awaiter(this,void 0,void 0,(function(){var r;return __generator(this,(function(t){switch(t.label){case 0:r={counter:this.counter};return[4,J.ecKeyPairToJson(this.currentRatchetKey)];c