@peculiar/fortify-webcomponents
Version:
Web-components for creating CSR or Certificate and viewing certificates list using Fortify
29 lines • 168 kB
JavaScript
/*!
* © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License
*/
var t=function(t,e,r){
/*!
* 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.
*
*/
const s="[object ArrayBuffer]";class i{static isArrayBuffer(t){return Object.prototype.toString.call(t)===s}static toArrayBuffer(t){if(this.isArrayBuffer(t)){return t}if(t.byteLength===t.buffer.byteLength){return t.buffer}if(t.byteOffset===0&&t.byteLength===t.buffer.byteLength){return t.buffer}return this.toUint8Array(t.buffer).slice(t.byteOffset,t.byteOffset+t.byteLength).buffer}static toUint8Array(t){return this.toView(t,Uint8Array)}static toView(t,e){if(t.constructor===e){return t}if(this.isArrayBuffer(t)){return new e(t)}if(this.isArrayBufferView(t)){return new e(t.buffer,t.byteOffset,t.byteLength)}throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(t){return this.isArrayBufferView(t)||this.isArrayBuffer(t)}static isArrayBufferView(t){return ArrayBuffer.isView(t)||t&&this.isArrayBuffer(t.buffer)}static isEqual(t,e){const r=i.toUint8Array(t);const s=i.toUint8Array(e);if(r.length!==s.byteLength){return false}for(let t=0;t<r.length;t++){if(r[t]!==s[t]){return false}}return true}static concat(...t){let e;if(Array.isArray(t[0])&&!(t[1]instanceof Function)){e=t[0]}else if(Array.isArray(t[0])&&t[1]instanceof Function){e=t[0]}else{if(t[t.length-1]instanceof Function){e=t.slice(0,t.length-1)}else{e=t}}let r=0;for(const t of e){r+=t.byteLength}const s=new Uint8Array(r);let i=0;for(const t of e){const e=this.toUint8Array(t);s.set(e,i);i+=e.length}if(t[t.length-1]instanceof Function){return this.toView(s,t[t.length-1])}return s.buffer}}const n="string";const o=/^[0-9a-f]+$/i;const a=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;const c=/^[a-zA-Z0-9-_]+$/;class u{static fromString(t){const e=unescape(encodeURIComponent(t));const r=new Uint8Array(e.length);for(let t=0;t<e.length;t++){r[t]=e.charCodeAt(t)}return r.buffer}static toString(t){const e=i.toUint8Array(t);let r="";for(let t=0;t<e.length;t++){r+=String.fromCharCode(e[t])}const s=decodeURIComponent(escape(r));return s}}class h{static toString(t,e=false){const r=i.toArrayBuffer(t);const s=new DataView(r);let n="";for(let t=0;t<r.byteLength;t+=2){const r=s.getUint16(t,e);n+=String.fromCharCode(r)}return n}static fromString(t,e=false){const r=new ArrayBuffer(t.length*2);const s=new DataView(r);for(let r=0;r<t.length;r++){s.setUint16(r*2,t.charCodeAt(r),e)}return r}}class f{static isHex(t){return typeof t===n&&o.test(t)}static isBase64(t){return typeof t===n&&a.test(t)}static isBase64Url(t){return typeof t===n&&c.test(t)}static ToString(t,e="utf8"){const r=i.toUint8Array(t);switch(e.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return h.toString(r,true);case"utf16":case"utf16be":return h.toString(r);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromString(t,e="utf8"){if(!t){return new ArrayBuffer(0)}switch(e.toLowerCase()){case"utf8":return this.FromUtf8String(t);case"binary":return this.FromBinary(t);case"hex":return this.FromHex(t);case"base64":return this.FromBase64(t);case"base64url":return this.FromBase64Url(t);case"utf16le":return h.fromString(t,true);case"utf16":case"utf16be":return h.fromString(t);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToBase64(t){const e=i.toUint8Array(t);if(typeof btoa!=="undefined"){const t=this.ToString(e,"binary");return btoa(t)}else{return Buffer.from(e).toString("base64")}}static FromBase64(t){const e=this.formatString(t);if(!e){return new ArrayBuffer(0)}if(!f.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}}static FromBase64Url(t){const e=this.formatString(t);if(!e){return new ArrayBuffer(0)}if(!f.isBase64Url(e)){throw new TypeError("Argument 'base64url' is not Base64Url encoded")}return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(t){return this.ToBase64(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(t,e=f.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.FromBinary(t);case"utf8":return u.fromString(t);case"utf16":case"utf16be":return h.fromString(t);case"utf16le":case"usc2":return h.fromString(t,true);default:throw new Error(`Unknown type of encoding '${e}'`)}}static ToUtf8String(t,e=f.DEFAULT_UTF8_ENCODING){switch(e){case"ascii":return this.ToBinary(t);case"utf8":return u.toString(t);case"utf16":case"utf16be":return h.toString(t);case"utf16le":case"usc2":return h.toString(t,true);default:throw new Error(`Unknown type of encoding '${e}'`)}}static FromBinary(t){const e=t.length;const r=new Uint8Array(e);for(let s=0;s<e;s++){r[s]=t.charCodeAt(s)}return r.buffer}static ToBinary(t){const e=i.toUint8Array(t);let r="";for(let t=0;t<e.length;t++){r+=String.fromCharCode(e[t])}return r}static ToHex(t){const e=i.toUint8Array(t);let r="";const s=e.length;for(let t=0;t<s;t++){const s=e[t];if(s<16){r+="0"}r+=s.toString(16)}return r}static FromHex(t){let e=this.formatString(t);if(!e){return new ArrayBuffer(0)}if(!f.isHex(e)){throw new TypeError("Argument 'hexString' is not HEX encoded")}if(e.length%2){e=`0${e}`}const r=new Uint8Array(e.length/2);for(let t=0;t<e.length;t=t+2){const s=e.slice(t,t+2);r[t/2]=parseInt(s,16)}return r.buffer}static ToUtf16String(t,e=false){return h.toString(t,e)}static FromUtf16String(t,e=false){return h.fromString(t,e)}static Base64Padding(t){const e=4-t.length%4;if(e<4){for(let r=0;r<e;r++){t+="="}}return t}static formatString(t){return(t===null||t===void 0?void 0:t.replace(/[\n\r\t ]/g,""))||""}}f.DEFAULT_UTF8_ENCODING="utf8";function l(t,...e){const r=arguments[0];for(let t=1;t<arguments.length;t++){const e=arguments[t];for(const t in e){r[t]=e[t]}}return r}function d(...t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e));const r=new Uint8Array(e);let s=0;t.map((t=>new Uint8Array(t))).forEach((t=>{for(const e of t){r[s++]=e}}));return r.buffer}function y(t,e){if(!(t&&e)){return false}if(t.byteLength!==e.byteLength){return false}const r=new Uint8Array(t);const s=new Uint8Array(e);for(let e=0;e<t.byteLength;e++){if(r[e]!==s[e]){return false}}return true}function w(t,e,r,s){var i=arguments.length,n=i<3?e:s,o;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")n=Reflect.decorate(t,e,r,s);else for(var a=t.length-1;a>=0;a--)if(o=t[a])n=(i<3?o(n):i>3?o(e,r,n):o(e,r))||n;return i>3&&n&&Object.defineProperty(e,r,n),n}typeof SuppressedError==="function"?SuppressedError:function(t,e,r){var s=new Error(r);return s.name="SuppressedError",s.error=t,s.suppressed=e,s};class p{static async set(t){return new Uint8Array(t)}static async get(t){return new Uint8Array(t).buffer}}function v(t){return r=>{const s=r;s.localName=t.name||s.name||s.toString().match(/^function\s*([^\s(]+)/)[1];s.items=s.items||{};s.target=r;s.items=l({},s.items);const i=new e.Type(s.localName);for(const t in s.items){const r=s.items[t];let n=void 0;if(r.repeated){n="repeated"}else if(r.required){n="required"}i.add(new e.Field(r.name,r.id,r.type,n))}s.protobuf=i}}function g(t,e,r){const s=`_${e}`;const i={set:function(t){if(this[s]!==t){this.raw=null;this[s]=t}},get:function(){if(this[s]===void 0){let t=r.defaultValue;if(r.parser&&!r.repeated){t=new r.parser}this[s]=t}return this[s]},enumerable:true};Object.defineProperty(t,s,{writable:true,enumerable:false});Object.defineProperty(t,e,i)}function m(t){return(e,r)=>{const s=e.constructor;const i=r;s.items=s.items||{};if(s.target!==s){s.items=l({},s.items);s.target=s}s.items[i]={id:t.id,type:t.type||"bytes",defaultValue:t.defaultValue,converter:t.converter||null,parser:t.parser||null,name:t.name||i,required:t.required||false,repeated:t.repeated||false};g(e,i,s.items[i])}}class b{static async importProto(t){const e=new this;await e.importProto(t);return e}isEmpty(){return this.raw===undefined}hasChanged(){if(this.raw===null){return true}const t=this.constructor;const e=this;for(const r in t.items){const s=t.items[r];if(s.repeated){if(s.parser){return e[r].some((t=>t.hasChanged()))}}else{if(s.parser&&e[r]&&e[r].hasChanged()){return true}}}return false}async importProto(t){const e=this.constructor;const r=this;let s;let i;if(t instanceof b){i=await t.exportProto()}else{i=t}try{if(!e.protobuf){throw new Error("Protobuf schema doesn't contain 'protobuf' property")}s=e.protobuf.decode(new Uint8Array(i))}catch(t){const r=t instanceof Error?t:new Error("Unknown error");throw new Error(`Cannot decode message for ${e.localName}.\n$ProtobufError: ${r.message}`)}for(const t in e.items){const i=e.items[t];let n=s[i.name];if(ArrayBuffer.isView(n)){n=new Uint8Array(n)}if(!Array.isArray(n)){if(i.repeated){r[t]=n=[]}else{n=[n]}}if(i.repeated&&!r[t]){r[t]=[]}for(const e of n){if(i.repeated){r[t].push(await this.importItem(i,e))}else{r[t]=await this.importItem(i,e)}}}this.raw=i}async exportProto(){if(!this.hasChanged()){return this.raw}const t=this.constructor;const e=this;const r={};for(const s in t.items){const i=t.items[s];let n=e[s];if(!Array.isArray(n)){n=n===void 0?[]:[n]}for(const t of n){const e=await this.exportItem(i,t);if(i.repeated){if(!r[i.name]){r[i.name]=[]}r[i.name].push(e)}else{r[i.name]=e}}}this.raw=new Uint8Array(t.protobuf.encode(r).finish()).buffer;return this.raw}async exportItem(t,e){const r=this.constructor;let s;if(t.parser){const i=e;const n=await i.exportProto();if(t.required&&!n){throw new Error(`Parameter '${t.name}' is required in '${r.localName}' protobuf message.`)}if(n){s=new Uint8Array(n)}}else{if(t.required&&e===undefined){throw new Error(`Parameter '${t.name}' is required in '${r.localName}' protobuf message.`)}if(t.converter){if(e!==undefined){s=await t.converter.set(e)}}else{if(e instanceof ArrayBuffer){e=new Uint8Array(e)}s=e}}return s}async importItem(t,e){const r=this.constructor;let s;if(t.parser){const i=t.parser;if(e&&e.byteLength){s=await i.importProto(new Uint8Array(e).buffer)}else if(t.required){throw new Error(`Parameter '${t.name}' is required in '${r.localName}' protobuf message.`)}}else if(t.converter){if(e&&e.byteLength){s=await t.converter.get(e)}else if(t.required){throw new Error(`Parameter '${t.name}' is required in '${r.localName}' protobuf message.`)}}else{s=e}return s}}function A(){}A.prototype=Object.create(null);function S(){S.init.call(this)}S.EventEmitter=S;S.usingDomains=false;S.prototype.domain=undefined;S.prototype._events=undefined;S.prototype._maxListeners=undefined;S.defaultMaxListeners=10;S.init=function(){this.domain=null;if(!this._events||this._events===Object.getPrototypeOf(this)._events){this._events=new A;this._eventsCount=0}this._maxListeners=this._maxListeners||undefined};S.prototype.setMaxListeners=function t(e){if(typeof e!=="number"||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');this._maxListeners=e;return this};function E(t){if(t._maxListeners===undefined)return S.defaultMaxListeners;return t._maxListeners}S.prototype.getMaxListeners=function t(){return E(this)};function x(t,e,r){if(e)t.call(r);else{var s=t.length;var i=O(t,s);for(var n=0;n<s;++n)i[n].call(r)}}function B(t,e,r,s){if(e)t.call(r,s);else{var i=t.length;var n=O(t,i);for(var o=0;o<i;++o)n[o].call(r,s)}}function k(t,e,r,s,i){if(e)t.call(r,s,i);else{var n=t.length;var o=O(t,n);for(var a=0;a<n;++a)o[a].call(r,s,i)}}function U(t,e,r,s,i,n){if(e)t.call(r,s,i,n);else{var o=t.length;var a=O(t,o);for(var c=0;c<o;++c)a[c].call(r,s,i,n)}}function N(t,e,r,s){if(e)t.apply(r,s);else{var i=t.length;var n=O(t,i);for(var o=0;o<i;++o)n[o].apply(r,s)}}S.prototype.emit=function t(e){var r,s,i,n,o,a,c;var u=e==="error";a=this._events;if(a)u=u&&a.error==null;else if(!u)return false;c=this.domain;if(u){r=arguments[1];if(c){if(!r)r=new Error('Uncaught, unspecified "error" event');r.domainEmitter=this;r.domain=c;r.domainThrown=false;c.emit("error",r)}else if(r instanceof Error){throw r}else{var h=new Error('Uncaught, unspecified "error" event. ('+r+")");h.context=r;throw h}return false}s=a[e];if(!s)return false;var f=typeof s==="function";i=arguments.length;switch(i){case 1:x(s,f,this);break;case 2:B(s,f,this,arguments[1]);break;case 3:k(s,f,this,arguments[1],arguments[2]);break;case 4:U(s,f,this,arguments[1],arguments[2],arguments[3]);break;default:n=new Array(i-1);for(o=1;o<i;o++)n[o-1]=arguments[o];N(s,f,this,n)}return true};function I(t,e,r,s){var i;var n;var o;if(typeof r!=="function")throw new TypeError('"listener" argument must be a function');n=t._events;if(!n){n=t._events=new A;t._eventsCount=0}else{if(n.newListener){t.emit("newListener",e,r.listener?r.listener:r);n=t._events}o=n[e]}if(!o){o=n[e]=r;++t._eventsCount}else{if(typeof o==="function"){o=n[e]=s?[r,o]:[o,r]}else{if(s){o.unshift(r)}else{o.push(r)}}if(!o.warned){i=E(t);if(i&&i>0&&o.length>i){o.warned=true;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+e+" listeners added. "+"Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning";a.emitter=t;a.type=e;a.count=o.length;C(a)}}}return t}function C(t){typeof console.warn==="function"?console.warn(t):console.log(t)}S.prototype.addListener=function t(e,r){return I(this,e,r,false)};S.prototype.on=S.prototype.addListener;S.prototype.prependListener=function t(e,r){return I(this,e,r,true)};function q(t,e,r){var s=false;function i(){t.removeListener(e,i);if(!s){s=true;r.apply(t,arguments)}}i.listener=r;return i}S.prototype.once=function t(e,r){if(typeof r!=="function")throw new TypeError('"listener" argument must be a function');this.on(e,q(this,e,r));return this};S.prototype.prependOnceListener=function t(e,r){if(typeof r!=="function")throw new TypeError('"listener" argument must be a function');this.prependListener(e,q(this,e,r));return this};S.prototype.removeListener=function t(e,r){var s,i,n,o,a;if(typeof r!=="function")throw new TypeError('"listener" argument must be a function');i=this._events;if(!i)return this;s=i[e];if(!s)return this;if(s===r||s.listener&&s.listener===r){if(--this._eventsCount===0)this._events=new A;else{delete i[e];if(i.removeListener)this.emit("removeListener",e,s.listener||r)}}else if(typeof s!=="function"){n=-1;for(o=s.length;o-- >0;){if(s[o]===r||s[o].listener&&s[o].listener===r){a=s[o].listener;n=o;break}}if(n<0)return this;if(s.length===1){s[0]=undefined;if(--this._eventsCount===0){this._events=new A;return this}else{delete i[e]}}else{T(s,n)}if(i.removeListener)this.emit("removeListener",e,a||r)}return this};S.prototype.removeAllListeners=function t(e){var r,s;s=this._events;if(!s)return this;if(!s.removeListener){if(arguments.length===0){this._events=new A;this._eventsCount=0}else if(s[e]){if(--this._eventsCount===0)this._events=new A;else delete s[e]}return this}if(arguments.length===0){var i=Object.keys(s);for(var n=0,o;n<i.length;++n){o=i[n];if(o==="removeListener")continue;this.removeAllListeners(o)}this.removeAllListeners("removeListener");this._events=new A;this._eventsCount=0;return this}r=s[e];if(typeof r==="function"){this.removeListener(e,r)}else if(r){do{this.removeListener(e,r[r.length-1])}while(r[0])}return this};S.prototype.listeners=function t(e){var r;var s;var i=this._events;if(!i)s=[];else{r=i[e];if(!r)s=[];else if(typeof r==="function")s=[r.listener||r];else s=K(r)}return s};S.listenerCount=function(t,e){if(typeof t.listenerCount==="function"){return t.listenerCount(e)}else{return $.call(t,e)}};S.prototype.listenerCount=$;function $(t){var e=this._events;if(e){var r=e[t];if(typeof r==="function"){return 1}else if(r){return r.length}}return 0}S.prototype.eventNames=function t(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function T(t,e){for(var r=e,s=r+1,i=t.length;s<i;r+=1,s+=1)t[r]=t[s];t.pop()}function O(t,e){var r=new Array(e);while(e--)r[e]=t[e];return r}function K(t){var e=new Array(t.length);for(var r=0;r<e.length;++r){e[r]=t[r].listener||t[r]}return e}const R="ECDSA";const D="ECDH";const P="AES-CBC";const j="SHA-256";const V="HMAC";const J=20;const M=f.FromBinary("InfoText");const W=f.FromBinary("InfoRatchet");const z=f.FromBinary("InfoMessageKeys");let H=null;if(typeof self!=="undefined"){H={crypto:self.crypto,name:"WebCrypto"}}function F(t,e){H={crypto:e,name:t}}function L(){if(!H){throw new Error("WebCrypto engine is empty. Use setEngine to resolve it.")}return H}let G=(()=>{class t{static async generateKeyPair(t,e){const r=t;const s=t==="ECDSA"?["sign","verify"]:["deriveKey","deriveBits"];const i=await L().crypto.subtle.generateKey({name:r,namedCurve:this.NAMED_CURVE},e,s);const n=await X.create(i.publicKey);const o={privateKey:i.privateKey,publicKey:n};return o}static deriveBytes(t,e){return L().crypto.subtle.deriveBits({name:"ECDH",public:e.key},t,256)}static verify(t,e,r){return L().crypto.subtle.verify({name:"ECDSA",hash:this.DIGEST_ALGORITHM},t.key,r,e)}static async sign(t,e){return L().crypto.subtle.sign({name:"ECDSA",hash:this.DIGEST_ALGORITHM},t,e)}static async ecKeyPairToJson(t){return{privateKey:t.privateKey,publicKey:t.publicKey.key,thumbprint:await t.publicKey.thumbprint()}}static async ecKeyPairFromJson(t){return{privateKey:t.privateKey,publicKey:await X.create(t.publicKey)}}}t.NAMED_CURVE="P-256";t.DIGEST_ALGORITHM="SHA-512";return t})();const _={name:"AES-CBC",length:256};class Z{static randomBytes(t){const e=new Uint8Array(t);L().crypto.getRandomValues(e);return e.buffer}static digest(t,e){return L().crypto.subtle.digest(t,e)}static encrypt(t,e,r){return L().crypto.subtle.encrypt({name:P,iv:new Uint8Array(r)},t,e)}static decrypt(t,e,r){return L().crypto.subtle.decrypt({name:P,iv:new Uint8Array(r)},t,e)}static importHMAC(t){return L().crypto.subtle.importKey("raw",t,{name:V,hash:{name:j}},false,["sign","verify"])}static importAES(t){return L().crypto.subtle.importKey("raw",t,_,false,["encrypt","decrypt"])}static async sign(t,e){return await L().crypto.subtle.sign({name:V,hash:j},t,e)}static async HKDF(t,e=1,r,s=new ArrayBuffer(0)){if(!r){r=await this.importHMAC(new Uint8Array(32).buffer)}const i=await this.sign(r,t);const n=await this.importHMAC(i);const o=[new ArrayBuffer(0)];for(let t=0;t<e;t++){o[t+1]=await this.sign(n,d(o[t],s,new Uint8Array([t+1]).buffer))}return o.slice(1)}}class X{static async create(t){const e=new this;const r=t.algorithm.name.toUpperCase();if(!(r==="ECDH"||r==="ECDSA")){throw new Error("Error: Unsupported asymmetric key algorithm.")}if(t.type!=="public"){throw new Error("Error: Expected key type to be public but it was not.")}e.key=t;const s=await L().crypto.subtle.exportKey("jwk",t);if(!(s.x&&s.y)){throw new Error("Wrong JWK data for EC public key. Parameters x and y are required.")}const i=f.FromBase64Url(s.x);const n=f.FromBase64Url(s.y);const o=f.ToBinary(i)+f.ToBinary(n);e.serialized=f.FromBinary(o);e.id=await e.thumbprint();return e}static async importKey(t,e){const r=f.ToBase64Url(t.slice(0,32));const s=f.ToBase64Url(t.slice(32));const i={crv:G.NAMED_CURVE,kty:"EC",x:r,y:s};const n=e==="ECDSA"?["verify"]:[];const o=await L().crypto.subtle.importKey("jwk",i,{name:e,namedCurve:G.NAMED_CURVE},true,n);const a=await X.create(o);return a}serialize(){return this.serialized}async thumbprint(){const t=await this.serialize();const e=await Z.digest("SHA-256",t);return f.ToHex(e)}async isEqual(t){if(!(t&&t instanceof X)){return false}return y(this.serialized,t.serialized)}}class Q{constructor(t,e,r){this.id=t;this.signingKey=e;this.exchangeKey=r;this.preKeys=[];this.signedPreKeys=[]}static async fromJSON(t){const e=await G.ecKeyPairFromJson(t.signingKey);const r=await G.ecKeyPairFromJson(t.exchangeKey);const s=new this(t.id,e,r);s.createdAt=new Date(t.createdAt);await s.fromJSON(t);return s}static async create(t,e=0,r=0,s=false){const i=await G.generateKeyPair(R,s);const n=await G.generateKeyPair(D,s);const o=new Q(t,i,n);o.createdAt=new Date;for(let t=0;t<r;t++){o.preKeys.push(await G.generateKeyPair("ECDH",s))}for(let t=0;t<e;t++){o.signedPreKeys.push(await G.generateKeyPair("ECDH",s))}return o}async toJSON(){const t=[];const e=[];for(const e of this.preKeys){t.push(await G.ecKeyPairToJson(e))}for(const t of this.signedPreKeys){e.push(await G.ecKeyPairToJson(t))}return{createdAt:this.createdAt.toISOString(),exchangeKey:await G.ecKeyPairToJson(this.exchangeKey),id:this.id,preKeys:t,signedPreKeys:e,signingKey:await G.ecKeyPairToJson(this.signingKey)}}async fromJSON(t){this.id=t.id;this.signingKey=await G.ecKeyPairFromJson(t.signingKey);this.exchangeKey=await G.ecKeyPairFromJson(t.exchangeKey);this.preKeys=[];for(const e of t.preKeys){this.preKeys.push(await G.ecKeyPairFromJson(e))}this.signedPreKeys=[];for(const e of t.signedPreKeys){this.signedPreKeys.push(await G.ecKeyPairFromJson(e))}}}class Y{static fill(t){const e=new Y;e.fill(t);return e}static async fromJSON(t){const e=new this;await e.fromJSON(t);return e}fill(t){this.signingKey=t.signingKey;this.exchangeKey=t.exchangeKey;this.signature=t.signature;this.createdAt=t.createdAt}verify(){return G.verify(this.signingKey,this.exchangeKey.serialize(),this.signature)}async toJSON(){return{createdAt:this.createdAt.toISOString(),exchangeKey:await this.exchangeKey.key,id:this.id,signature:this.signature,signingKey:await this.signingKey.key,thumbprint:await this.signingKey.thumbprint()}}async fromJSON(t){this.id=t.id;this.signature=t.signature;this.signingKey=await X.create(t.signingKey);this.exchangeKey=await X.create(t.exchangeKey);this.createdAt=new Date(t.createdAt);const e=await this.verify();if(!e){throw new Error("Error: Wrong signature for RemoteIdentity")}}}let tt=(()=>{let t=class t extends b{};w([m({id:0,type:"uint32",defaultValue:1})],t.prototype,"version",void 0);t=w([v({name:"Base"})],t);return t})();class et{static async set(t){return new Uint8Array(t.serialize())}static async get(t){return X.importKey(t.buffer,"ECDSA")}}class rt{static async set(t){return new Uint8Array(t.serialize())}static async get(t){return X.importKey(t.buffer,"ECDH")}}let st=class t{static async set(t){return new Uint8Array(f.FromString(t.toISOString()))}static async get(t){return new Date(f.ToString(t))}};let it=(()=>{var t;let e=t=class e extends tt{static async fill(e){const r=new t;await r.fill(e);return r}async sign(t){this.signature=await G.sign(t,this.exchangeKey.serialize())}async verify(){return await G.verify(this.signingKey,this.exchangeKey.serialize(),this.signature)}async fill(t){this.signingKey=t.signingKey.publicKey;this.exchangeKey=t.exchangeKey.publicKey;this.createdAt=t.createdAt;await this.sign(t.signingKey.privateKey)}};w([m({id:1,converter:et})],e.prototype,"signingKey",void 0);w([m({id:2,converter:rt})],e.prototype,"exchangeKey",void 0);w([m({id:3})],e.prototype,"signature",void 0);w([m({id:4,converter:st})],e.prototype,"createdAt",void 0);e=t=w([v({name:"Identity"})],e);return e})();let nt=(()=>{let t=class t extends tt{};w([m({id:1,converter:rt,required:true})],t.prototype,"senderRatchetKey",void 0);w([m({id:2,type:"uint32",required:true})],t.prototype,"counter",void 0);w([m({id:3,type:"uint32",required:true})],t.prototype,"previousCounter",void 0);w([m({id:4,converter:p,required:true})],t.prototype,"cipherText",void 0);t=w([v({name:"Message"})],t);return t})();let ot=(()=>{let t=class t extends tt{async sign(t){this.signature=await this.signHMAC(t)}async verify(t){const e=await this.signHMAC(t);return y(e,this.signature)}async getSignedRaw(){const t=this.receiverKey.serialize();const e=this.senderKey.serialize();const r=await this.message.exportProto();const s=d(t,e,r);return s}async signHMAC(t){const e=await this.getSignedRaw();const r=await Z.sign(t,e);return r}};w([m({id:1,converter:et,required:true})],t.prototype,"senderKey",void 0);w([m({id:2,parser:nt,required:true})],t.prototype,"message",void 0);w([m({id:3,required:true})],t.prototype,"signature",void 0);t=w([v({name:"MessageSigned"})],t);return t})();let at=(()=>{let t=class t extends tt{};w([m({id:1,type:"uint32",required:true})],t.prototype,"registrationId",void 0);w([m({id:2,type:"uint32"})],t.prototype,"preKeyId",void 0);w([m({id:3,type:"uint32",required:true})],t.prototype,"preKeySignedId",void 0);w([m({id:4,converter:rt,required:true})],t.prototype,"baseKey",void 0);w([m({id:5,parser:it,required:true})],t.prototype,"identity",void 0);w([m({id:6,parser:ot,required:true})],t.prototype,"signedMessage",void 0);t=w([v({name:"PreKeyMessage"})],t);return t})();let ct=(()=>{let t=class t extends tt{};w([m({id:1,type:"uint32",required:true})],t.prototype,"id",void 0);w([m({id:2,converter:rt,required:true})],t.prototype,"key",void 0);t=w([v({name:"PreKey"})],t);return t})();let ut=(()=>{let t=class t extends ct{async sign(t){this.signature=await G.sign(t,this.key.serialize())}verify(t){return G.verify(t,this.key.serialize(),this.signature)}};w([m({id:3,converter:p,required:true})],t.prototype,"signature",void 0);t=w([v({name:"PreKeySigned"})],t);return t})();let ht=(()=>{let t=class t extends tt{};w([m({id:1,type:"uint32",required:true})],t.prototype,"registrationId",void 0);w([m({id:2,parser:it,required:true})],t.prototype,"identity",void 0);w([m({id:3,parser:ct})],t.prototype,"preKey",void 0);w([m({id:4,parser:ut,required:true})],t.prototype,"preKeySigned",void 0);t=w([v({name:"PreKeyBundle"})],t);return t})();class ft{constructor(t=20){this.items=[];this.maxSize=t}get length(){return this.items.length}get latest(){return this.items[this.length-1]}push(t){if(this.length===this.maxSize){this.items=this.items.slice(1)}this.items.push(t)}async toJSON(){const t=[];for(const e of this.items){t.push(await e.toJSON())}return t}async fromJSON(t){this.items=t}}const lt=new Uint8Array([1]).buffer;const dt=new Uint8Array([2]).buffer;class yt{constructor(t){this.counter=0;this.rootKey=t}static async fromJSON(t){const e=new this(t.rootKey);e.fromJSON(t);return e}async toJSON(){return{counter:this.counter,rootKey:this.rootKey}}async fromJSON(t){this.counter=t.counter;this.rootKey=t.rootKey}async calculateKey(t){const e=await Z.sign(t,lt);const r=await Z.sign(t,dt);const s={cipher:e,rootKey:await Z.importHMAC(r)};return s}async click(){const t=this.rootKey;const e=await this.calculateKey(t);this.rootKey=e.rootKey;this.counter++;return e.cipher}}class wt extends yt{async encrypt(t){const e=await this.click();const r=await Z.HKDF(e,3,void 0,z);const s=await Z.importAES(r[0]);const i=await Z.importHMAC(r[1]);const n=r[2].slice(0,16);const o=await Z.encrypt(s,t,n);return{cipherText:o,hmacKey:i}}}class pt extends yt{constructor(){super(...arguments);this.keys=[]}async toJSON(){const t=await super.toJSON();t.keys=this.keys;return t}async fromJSON(t){await super.fromJSON(t);this.keys=t.keys}async decrypt(t,e){const r=await this.getKey(e);const s=await Z.HKDF(r,3,void 0,z);const i=await Z.importAES(s[0]);const n=await Z.importHMAC(s[1]);const o=s[2].slice(0,16);const a=await Z.decrypt(i,t,o);return{cipherText:a,hmacKey:n}}async getKey(t){while(this.counter<=t){const t=await this.click();this.keys.push(t)}const e=this.keys[t];return e}}async function vt(t,e,r,s,i){const n=await G.deriveBytes(t.exchangeKey.privateKey,s);const o=await G.deriveBytes(e.privateKey,r);const a=await G.deriveBytes(e.privateKey,s);let c=new ArrayBuffer(0);if(i){c=await G.deriveBytes(e.privateKey,i)}const u=new Uint8Array(32);for(let t=0;t<u.length;t++){u[t]=255}const h=u.buffer;const f=d(h,n,o,a,c);const l=await Z.HKDF(f,1,void 0,M);return await Z.importHMAC(l[0])}async function gt(t,e,r,s,i){const n=await G.deriveBytes(e.privateKey,r);const o=await G.deriveBytes(t.exchangeKey.privateKey,s);const a=await G.deriveBytes(e.privateKey,s);let c=new ArrayBuffer(0);if(i){c=await G.deriveBytes(i,s)}const u=new Uint8Array(32);for(let t=0;t<u.length;t++){u[t]=255}const h=u.buffer;const f=d(h,n,o,a,c);const l=await Z.HKDF(f,1,void 0,M);return await Z.importHMAC(l[0])}class mt extends S{constructor(t={}){super();this.options=t;this.counter=0;this.currentStep=new bt;this.steps=new At(J);this.promises={}}static async create(t,e,r={}){let s;const i=new mt(r);if(e instanceof ht){if(!await e.identity.verify()){throw new Error("Error: Remote client's identity key is invalid.")}if(!await e.preKeySigned.verify(e.identity.signingKey)){throw new Error("Error: Remote client's signed prekey is invalid.")}i.currentRatchetKey=await i.generateRatchetKey();i.currentStep.remoteRatchetKey=e.preKeySigned.key;i.remoteIdentity=Y.fill(e.identity);i.remoteIdentity.id=e.registrationId;i.remotePreKeyId=e.preKey.id;i.remotePreKeySignedId=e.preKeySigned.id;s=await vt(t,i.currentRatchetKey,e.identity.exchangeKey,e.preKeySigned.key,e.preKey.key)}else{if(!await e.identity.verify()){throw new Error("Error: Remote client's identity key is invalid.")}const r=t.signedPreKeys[e.preKeySignedId];if(!r){throw new Error(`Error: PreKey with id ${e.preKeySignedId} not found`)}let n;if(e.preKeyId!==void 0){n=t.preKeys[e.preKeyId]}i.remoteIdentity=Y.fill(e.identity);i.currentRatchetKey=r;s=await gt(t,i.currentRatchetKey,e.identity.exchangeKey,e.signedMessage.message.senderRatchetKey,n&&n.privateKey)}i.identity=t;i.id=t.id;i.rootKey=s;return i}static async fromJSON(t,e,r){const s=new mt;s.identity=t;s.remoteIdentity=e;await s.fromJSON(r);return s}on(t,e){return super.on(t,e)}once(t,e){return super.once(t,e)}async decrypt(t){return this.queuePromise("encrypt",(async()=>{const e=t.message.senderRatchetKey;const r=t.message;if(t.message.previousCounter<this.counter-J){throw new Error("Error: Too old message")}let s=this.steps.getStep(e);if(!s){const t=new bt;t.remoteRatchetKey=e;this.steps.push(t);this.currentStep=t;s=t}if(!s.receivingChain){s.receivingChain=await this.createChain(this.currentRatchetKey.privateKey,e,pt)}const i=await s.receivingChain.decrypt(r.cipherText,r.counter);this.update();t.senderKey=this.remoteIdentity.signingKey;t.receiverKey=this.identity.signingKey.publicKey;if(!await t.verify(i.hmacKey)){throw new Error("Error: The Message did not successfully verify!")}return i.cipherText}))}async encrypt(t){return this.queuePromise("encrypt",(async()=>{if(this.currentStep.receivingChain&&!this.currentStep.sendingChain){this.counter++;this.currentRatchetKey=await this.generateRatchetKey()}if(!this.currentStep.sendingChain){if(!this.currentStep.remoteRatchetKey){throw new Error("currentStep has empty remoteRatchetKey")}this.currentStep.sendingChain=await this.createChain(this.currentRatchetKey.privateKey,this.currentStep.remoteRatchetKey,wt)}const e=await this.currentStep.sendingChain.encrypt(t);this.update();let r;if(this.steps.length===0&&!this.currentStep.receivingChain&&this.currentStep.sendingChain.counter===1){r=new at;r.registrationId=this.identity.id;r.preKeyId=this.remotePreKeyId;r.preKeySignedId=this.remotePreKeySignedId;r.baseKey=this.currentRatchetKey.publicKey;await r.identity.fill(this.identity)}const s=new ot;s.receiverKey=this.remoteIdentity.signingKey;s.senderKey=this.identity.signingKey.publicKey;s.message.cipherText=e.cipherText;s.message.counter=this.currentStep.sendingChain.counter-1;s.message.previousCounter=this.counter;s.message.senderRatchetKey=this.currentRatchetKey.publicKey;await s.sign(e.hmacKey);if(r){r.signedMessage=s;return r}else{return s}}))}async hasRatchetKey(t){let e;if(!(t instanceof X)){e=await X.create(t)}else{e=t}for(const t of this.steps.items){if(await t.remoteRatchetKey.isEqual(e)){return true}}return false}async toJSON(){return{counter:this.counter,ratchetKey:await G.ecKeyPairToJson(this.currentRatchetKey),remoteIdentity:await this.remoteIdentity.signingKey.thumbprint(),rootKey:this.rootKey,steps:await this.steps.toJSON()}}async fromJSON(t){this.currentRatchetKey=await G.ecKeyPairFromJson(t.ratchetKey);this.counter=t.counter;this.rootKey=t.rootKey;for(const e of t.steps){this.currentStep=await bt.fromJSON(e);this.steps.push(this.currentStep)}}update(){this.emit("update")}generateRatchetKey(){return G.generateKeyPair("ECDH",!!this.options.exportableKeys)}async createChain(t,e,r){const s=await G.deriveBytes(t,e);const i=await Z.HKDF(s,2,this.rootKey,W);const n=await Z.importHMAC(i[0]);const o=await Z.importHMAC(i[1]);const a=new r(o);this.rootKey=n;return a}queuePromise(t,e){const r=this.promises[t]||Promise.resolve();const s=this.promises[t]=r.then(e,e);s.then((()=>{if(this.promises[t]===s){delete this.promises[t]}}));return s}}class bt{static async fromJSON(t){const e=new this;await e.fromJSON(t);return e}async toJSON(){const t={};if(this.remoteRatchetKey){t.remoteRatchetKey=this.remoteRatchetKey.key}if(this.sendingChain){t.sendingChain=await this.sendingChain.toJSON()}if(this.receivingChain){t.receivingChain=await this.receivingChain.toJSON()}return t}async fromJSON(t){if(t.remoteRatchetKey){this.remoteRatchetKey=await X.create(t.remoteRatchetKey)}if(t.sendingChain){this.sendingChain=await wt.fromJSON(t.sendingChain)}if(t.receivingChain){this.receivingChain=await pt.fromJSON(t.receivingChain)}}}class At extends ft{getStep(t){let e;this.items.some((r=>{if(r.remoteRatchetKey.id===t.id){e=r}return!!e}));return e}}class St{static async set(t){return new Uint8Array(f.FromUtf8String(t.toISOString()))}static async get(t){return new Date(f.ToUtf8String(t))}}class Et{static async set(t){return new Uint8Array(f.FromHex(t))}static async get(t){return f.ToHex(t)}}class xt{static async set(t){return new Uint8Array(f.FromUtf8String(t.toString(10)))}static async get(t){return parseInt(f.ToUtf8String(t),10)}}var Bt;let kt=class t extends b{constructor(){super(...arguments);this.version=0}};kt.INDEX=1;w([m({id:kt.INDEX++,type:"uint32",required:true,defaultValue:1})],kt.prototype,"version",void 0);kt=w([v({name:"BaseMessage"})],kt);let Ut=class t extends kt{constructor(){super();this.actionId="";this.action=this.constructor.ACTION}};Ut.INDEX=kt.INDEX;Ut.ACTION="action";w([m({id:Ut.INDEX++,type:"string",required:true})],Ut.prototype,"action",void 0);w([m({id:Ut.INDEX++,type:"string",required:false})],Ut.prototype,"actionId",void 0);Ut=w([v({name:"Action"})],Ut);let Nt=class t extends kt{constructor(){super(...arguments);this.name=""}isEmpty(){return!this.name}toAlgorithm(){return{name:this.name}}fromAlgorithm(t){this.name=t.name}};Nt.INDEX=kt.INDEX;w([m({id:Nt.INDEX++,type:"string",required:true})],Nt.prototype,"name",void 0);Nt=w([v({name:"BaseAlgorithm"})],Nt);let It=Bt=class t extends Nt{toAlgorithm(){const t={};const e=this.constructor;for(const r in e.items){if(r==="version"){continue}const e=this[r];if(r==="labelStr"){t.label=e;continue}if(e!==void 0){if(e instanceof Nt){if(!e.isEmpty()){t[r]=e.toAlgorithm()}}else{t[r]=e}}}return t}fromAlgorithm(t){if(t instanceof Bt){t=t.toAlgorithm()}const e=this.constructor;for(const r in t){if(!e.items){continue}if(r in e.items){const s=e.items[r];if(s.parser){switch(s.parser){case Nt:{this[r].fromAlgorithm(t[r]);break}default:throw new Error(`Unsupported parser '${s.parser.name}'`)}}else{if(r==="label"&&typeof t.label==="string"){this.labelStr=t.label}else{this[r]=t[r]}}}}}};It.INDEX=Nt.INDEX;w([m({id:It.INDEX++,type:"bytes",parser:Nt})],It.prototype,"hash",void 0);w([m({id:It.INDEX++,type:"bytes"})],It.prototype,"publicExponent",void 0);w([m({id:It.INDEX++,type:"uint32"})],It.prototype,"modulusLength",void 0);w([m({id:It.INDEX++,type:"uint32"})],It.prototype,"saltLength",void 0);w([m({id:It.INDEX++,type:"bytes"})],It.prototype,"label",void 0);w([m({id:It.INDEX++,type:"string"})],It.prototype,"namedCurve",void 0);w([m({id:It.INDEX++,converter:p})],It.prototype,"public",void 0);w([m({id:It.INDEX++,type:"uint32"})],It.prototype,"length",void 0);w([m({id:It.INDEX++})],It.prototype,"iv",void 0);w([m({id:It.INDEX++,type:"bool"})],It.prototype,"token",void 0);w([m({id:It.INDEX++,type:"bool"})],It.prototype,"sensitive",void 0);w([m({id:It.INDEX++,type:"string"})],It.prototype,"labelStr",void 0);It=Bt=w([v({name:"Algorithm"})],It);let Ct=class t extends kt{constructor(){super(...arguments);this.providerID="";this.id="";this.type=""}};Ct.INDEX=kt.INDEX;w([m({id:Ct.INDEX++,type:"string",required:true})],Ct.prototype,"providerID",void 0);w([m({id:Ct.INDEX++,type:"bytes",required:true,converter:Et})],Ct.prototype,"id",void 0);w([m({id:Ct.INDEX++,type:"string",required:true})],Ct.prototype,"type",void 0);Ct=w([v({name:"CryptoItem"})],Ct);class qt{static async set(t){const e=new It;e.fromAlgorithm(t);const r=await e.exportProto();return new Uint8Array(r)}static async get(t){const e=new It;await e.importProto(t);const r=e.toAlgorithm();return r}}let $t=class t extends Ct{constructor(){super(...arguments);this.type="secret";this.algorithm={name:""};this.extractable=false;this.usages=[]}};$t.INDEX=Ct.INDEX;w([m({id:$t.INDEX++,type:"bytes",required:true,converter:qt})],$t.prototype,"algorithm",void 0);w([m({id:$t.INDEX++,type:"bool"})],$t.prototype,"extractable",void 0);w([m({id:$t.INDEX++,type:"string",repeated:true})],$t.prototype,"usages",void 0);$t=w([v({name:"CryptoKey"})],$t);let Tt=class t extends kt{constructor(){super(...arguments);this.privateKey=new $t;this.publicKey=new $t}};Tt.INDEX=kt.INDEX;w([m({id:Tt.INDEX++,name:"privateKey",type:"bytes",required:true,parser:$t})],Tt.prototype,"privateKey",void 0);w([m({id:Tt.INDEX++,name:"publicKey",type:"bytes",parser:$t})],Tt.prototype,"publicKey",void 0);Tt=w([v({name:"CryptoKeyPair"})],Tt);let Ot=class t extends kt{constructor(t,e=0,r="error"){super();this.code=0;this.type="error";this.message="";this.name="Error";this.stack="";if(t){this.message=t;this.code=e;this.type=r}}};Ot.INDEX=kt.INDEX;w([m({id:Ot.INDEX++,type:"uint32",defaultValue:0})],Ot.prototype,"code",void 0);w([m({id:Ot.INDEX++,type:"string",defaultValue:"error"})],Ot.prototype,"type",void 0);w([m({id:Ot.INDEX++,type:"string",defaultValue:""})],Ot.prototype,"message",void 0);w([m({id:Ot.INDEX++,type:"string",defaultValue:"Error"})],Ot.prototype,"name",void 0);w([m({id:Ot.INDEX++,type:"string",defaultValue:""})],Ot.prototype,"stack",void 0);Ot=w([v({name:"Error"})],Ot);let Kt=class t extends Ut{constructor(t){super();this.status=false;if(t){this.actionId=t.actionId;this.action=t.action}}};Kt.INDEX=Ut.INDEX;w([m({id:Kt.INDEX++,type:"bool",defaultValue:false})],Kt.prototype,"status",void 0);w([m({id:Kt.INDEX++,type:"bytes",parser:Ot})],Kt.prototype,"error",void 0);w([m({id:Kt.INDEX++,type:"bytes",converter:p})],Kt.prototype,"data",void 0);Kt=w([v({name:"Result"})],Kt);let Rt=class t extends Ut{};Rt.INDEX=Ut.INDEX;Rt.ACTION="auth";Rt=w([v({name:"AuthRequest"})],Rt);let Dt=class t extends Ut{};Dt.INDEX=Ut.INDEX;Dt.ACTION="server/login";Dt=w([v({})],Dt);let Pt=class t extends Ut{};Pt.INDEX=Ut.INDEX;Pt.ACTION="server/isLoggedIn";Pt=w([v({})],Pt);let jt=class t extends Ut{};jt.INDEX=Ut.INDEX;jt.ACTION="cardReader";jt=w([v({})],jt);let Vt=class t extends Ut{};Vt.INDEX=Ut.INDEX;Vt.ACTION="cardReader/readers";Vt=w([v({})],Vt);let Jt=class t extends jt{constructor(t,e){super();this.reader="";this.atr="";if(t&&e){this.reader=t;this.atr=e}}};Jt.INDEX=jt.INDEX;w([m({id:Jt.INDEX++,required:true,type:"string",defaultValue:""})],Jt.prototype,"reader",void 0);w([m({id:Jt.INDEX++,required:true,converter:Et})],Jt.prototype,"atr",void 0);Jt=w([v({})],Jt);let Mt=class t extends Jt{};Mt.INDEX=Jt.INDEX;Mt.ACTION=Jt.ACTION+"/insert";Mt=w([v({})],Mt);let Wt=class t extends Jt{};Wt.INDEX=Jt.INDEX;Wt.ACTION=Jt.ACTION+"/remove";Wt=w([v({})],Wt);let zt=class t extends Ut{constructor(){super(...arguments);this.providerID=""}};zt.INDEX=Ut.INDEX;zt.ACTION="crypto";w([m({id:zt.INDEX++,required:true,type:"string"})],zt.prototype,"providerID",void 0);zt=w([v({})],zt);let Ht=class t extends zt{};Ht.INDEX=zt.INDEX;Ht.ACTION="crypto/login";Ht=w([v({})],Ht);let Ft=class t extends zt{};Ft.INDEX=zt.INDEX;Ft.ACTION="crypto/logout";Ft=w([v({})],Ft);let Lt=class t extends zt{};Lt.INDEX=zt.INDEX;Lt.ACTION="crypto/isLoggedIn";Lt=w([v({})],Lt);let Gt=class t extends zt{};Gt.INDEX=zt.INDEX;Gt.ACTION="crypto/reset";Gt=w([v({})],Gt);let _t=class t extends Ct{constructor(){super(...arguments);this.id="";this.publicKey=new $t;this.type="x509";this.label="";this.token=false;this.sensitive=false}};_t.INDEX=Ct.INDEX;w([m({id:_t.INDEX++,required:true,converter:Et})],_t.prototype,"id",void 0);w([m({id:_t.INDEX++,required:true,parser:$t})],_t.prototype,"publicKey",void 0);w([m({id:_t.INDEX++,required:true,type:"string"})],_t.prototype,"type",void 0);w([m({id:_t.INDEX++,type:"string",defaultValue:""})],_t.prototype,"label",void 0);w([m({id:_t.INDEX++,type:"bool",defaultValue:false})],_t.prototype,"token",void 0);w([m({id:_t.INDEX++,type:"bool",defaultValue:false})],_t.prototype,"sensitive",void 0);_t=w([v({})],_t);let Zt=class t extends _t{constructor(){super(...arguments);this.type="x509";this.serialNumber="";this.issuerName="";this.subjectName="";this.notBefore=new Date;this.notAfter=new Date}};Zt.INDEX=_t.INDEX;w([m({id:Zt.INDEX++,required:true,converter:Et})],Zt.prototype,"serialNumber",void 0);w([m({id:Zt.INDEX++,required:true,type:"string"})],Zt.prototype,"issuerName",void 0);w([m({id:Zt.INDEX++,required:true,type:"string"})],Zt.prototype,"subjectName",void 0);w([m({id:Zt.INDEX++,required:true,converter:St})],Zt.prototype,"notBefore",void 0);w([m({id:Zt.INDEX++,required:true,converter:St})],Zt.prototype,"notAfter",void 0);Zt=w([v({})],Zt);let Xt=class t extends _t{constructor(){super(...arguments);this.type="request";this.subjectName=""}};Xt.INDEX=_t.INDEX;w([m({id:Xt.INDEX++,required:true,type:"string"})],Xt.prototype,"subjectName",void 0);Xt=w([v({})],Xt);let Qt=class t extends kt{constructor(){super(...arguments);this.type="";this.value=new ArrayBuffer(0)}};Qt.INDEX=kt.INDEX;w([m({id:Qt.INDEX++,required:true,type:"string"})],Qt.prototype,"type",void 0);w([m({id:Qt.INDEX++,required:true,converter:p})],Qt.prototype,"value",void 0);Qt=w([v({})],Qt);let Yt=class t extends kt{constructor(){super(...arguments);this.items=[]}};Yt.INDEX=kt.INDEX;w([m({id:Yt.INDEX++,required:true,repeated:true,parser:Qt})],Yt.prototype,"items",void 0);Yt=w([v({})],Yt);let te=class t extends zt{constructor(){super(...arguments);this.item=new _t}};te.INDEX=zt.INDEX;te.ACTION="crypto/certificateStorage/setItem";w([m({id:te.INDEX++,required:true,parser:_t})],te.prototype,"item",void 0);te=w([v({})],te);let ee=class t extends zt{constructor(){super(...arguments);this.key="";this.algorithm=new It;this.keyUsages=[]}};ee.INDEX=zt.INDEX;ee.ACTION="crypto/certificateStorage/getItem";w([m({id:ee.INDEX++,required:true,type:"string"})],ee.prototype,"key",void 0);w([m({id:ee.INDEX++,parser:It})],ee.prototype,"algorithm",void 0);w([m({id:ee.INDEX++,repeated:true,type:"string"})],ee.prototype,"keyUsages",void 0);ee=w([v({})],ee);let re=class t extends zt{};re.INDEX=zt.INDEX;re.ACTION="crypto/certificateStorage/keys";re=w([v({})],re);let se=class t extends zt{constructor(){super(...arguments);this.key=""}};se.INDEX=zt.INDEX;se.ACTION="crypto/certificateStorage/getValue";w([m({id:se.INDEX++,required:true,type:"string"})],se.prototype,"key",void 0);se=w([v({})],se);let ie=class t extends zt{constructor(){super(...arguments);this.key=""}};ie.INDEX=zt.INDEX;ie.ACTION="crypto/certificateStorage/removeItem";w([m({id:ie.INDEX++,required:true,type:"string"})],ie.prototype,"key",void 0);ie=w([v({})],ie);let ne=class t extends zt{};ne.INDEX=zt.INDEX;ne.ACTION="crypto/certificateStorage/clear";ne=w([v({})],ne);let oe=class t extends zt{constructor(){super(...arguments);this.format="raw";this.data=new ArrayBuffer(0);this.algorithm=new It;this.keyUsages=[]}};oe.INDEX=zt.INDEX;oe.ACTION="crypto/certificateStorage/import";w([m({id:oe.INDEX++,required:true,type:"string"})],oe.prototype,"format",void 0);w([m({id:oe.INDEX++,required:true,converter:p})],oe.prototype,"data",void 0);w([m({id:oe.INDEX++,required:true,parser:It})],oe.prototype,"algorithm",void 0);w([m({id:oe.INDEX++,repeated:true,type:"string"})],oe.prototype,"keyUsages",void 0);oe=w([v({})],oe);let ae=class t extends zt{constructor(){super(...arguments);this.format="raw";this.item=new _t}};ae.INDEX=zt.INDEX;ae.ACTION="crypto/certificateStorage/export";w([m({id:ae.INDEX++,required:true,type:"string"})],ae.prototype,"format",void 0);w([m({id:ae.INDEX++,required:true,parser:_t})],ae.prototype,"item",void 0);ae=w([v({})],ae);let ce=class t extends zt{constructor(){super(...arguments);this.item=new _t}};ce.INDEX=zt.INDEX;ce.ACTION="crypto/certificateStorage/indexOf";w([m({id:ce.INDEX++,required:true,parser:_t})],ce.prototype,"item",void 0);ce=w([v({})],ce);let ue=class t extends zt{constructor(){super(...arguments);this.item=new _t}};ue.INDEX=zt.INDEX;ue.ACTION="crypto/certificateStorage/getChain";w([m({id:te.INDEX++,required:true,parser:_t})],ue.prototype,"item",void 0);ue=w([v({})],ue);let he=class t extends zt{constructor(){super(...arguments);this.url=""}};he.INDEX=zt.INDEX;he.ACTION="crypto/certificateStorage/getCRL";w([m({id:he.INDEX++,required:true,type:"string"})],he.prototype,"url",void 0);he=w([v({})],he);let fe=class t extends kt{constructor(){super(...arguments);this.method="get"}};fe.INDEX=kt.INDEX;w([m({id:fe.INDEX++,required:false,type:"string",defaultValue:"get"})],fe.prototype,"method",void 0);fe=w([v({})],fe);let le=class t extends zt{constructor(){super(...arguments);this.url="";this.request=new ArrayBuffer(0);this.options=new fe}};le.INDEX=zt.INDEX;le.ACTION="crypto/certificateStorage/getOCSP";w([m({id:le.INDEX++,required:true,type:"string"})],le.prototype,"url",void 0);w([m({id:le.INDEX++,required:true,converter:p})],le.prototype,"request",void 0);w([m({id:le.INDEX++,required:false,parser:fe})],le.prototype,"options",void 0);le=w([v({})],le);let de=class t extends zt{constructor(){super(...arguments);this.item=new $t}};de.INDEX=zt.INDEX;de.ACTION="crypto/keyStorage/setItem";w([m({id:de.INDEX++,required:true,parser:$t})],de.prototype,"item",void 0);de=w([v({})],de);let ye=class t extends zt{constructor(){super(...arguments);this.key="";this.algorithm=new It;this.extractable=false;this.keyUsages=[]}};ye.INDEX=zt.INDEX;ye.ACTION="crypto/keyStorage/getItem";w([m({id:ye.INDEX++,required:true,type:"string"})],ye.prototype,"key",void 0);w([m({id:ye.INDEX++,parser:It})],ye.prototype,"algorithm",void 0);w([m({id:ye.INDEX++,type:"bool"})],ye.prototype,"extractable",void 0);w([m({id:ye.INDEX++,repeated:true,type:"string"})],ye.prototype,"keyUsages",void 0);ye=w([v({})],ye);let we=class t extends zt{};we.INDEX=zt.INDEX;we.ACTION="crypto/keyStorage/keys";we=w([v({})],we);let pe=class t extends zt{constructor(){super(...arguments);this.key=""}};pe.INDEX=zt.INDEX;pe.ACTION="crypto/keyStorage/removeItem";w([m({id:pe.INDEX++,required:true,type:"string"})],pe.prototype,"key",void 0);pe=w([v({})],pe);let ve=class t extends zt{};ve.INDEX=zt.INDEX;ve.ACTION="crypto/keyStorage/clear";ve=w([v({})],ve);let ge=class t extends zt{constructor(){super(...arguments);this.item=new $t}};ge.INDEX=zt.INDEX;ge.ACTION="crypto/keyStorage/indexOf";w([m({id:ge.INDEX++,required:true,parser:$t})],ge.prototype,"item",void 0);ge=w([v({})],ge);let me=class t extends kt{constructor(t){super();this.major=0;this.minor=0;if(t){l(this,t)}}};me.INDEX=kt.INDEX;w([m({id:me.INDEX++,required:true,type:"uint32"})],me.prototype,"major",void 0);w([m({id:me.INDEX++,required:true,type:"uint32"})],me.prototype,"minor",void 0);me=w([v({})],me);let be=class t extends kt{constructor(t){super();this.label="";this.manufacturerID="";this.model="";this.serialNumber="";this.flags=0;this.hardwareVersion=new me;this.firmwareVersion=new me;this.maxSessionCount=0;this.sessionCount=0;this.maxRwSessionCount=0;this.rwSessionCount=0;this.maxPinLen=0;this.minPinLen=0;this.totalPublicMemory=0;this.freePublicMemory=0;this.totalPrivateMemory=0;this.freePrivateMemory=0;if(t){l(this,t);this.firmwareVersion=new me(t.firmwareVersion);this.hardwareVersion=new me(t.hardwareVersion)}}};be.INDEX=kt.INDEX;w([m({id:be.INDEX++,required:true,type:"string"})],be.prototype,"label",void 0);w([m({id:be.INDEX++,required:true,type:"string"})],be.prototype,"manufacturerID",void 0);w([m({id:be.INDEX++,required:true,type:"string"})],be.prototype,"model",void 0);w([m({id:be.INDEX++,required:true,type:"string"})],be.prototype,"serialNumber",void 0);w([m({id:be.INDEX++,required:true,type:"uint32"})],be.prototype,"flags",void 0);w([m({id:be.INDEX++,required:true,parser:me})],be.prototype,"hardwareVersion",void 0);w([m({id:be.INDEX++,required:true,parser:me})],be.prototype,"firmwareVersion",void 0);w([m({id:be.INDEX++,required:true,type:"uint32"})],be.prototype,"maxSessionCount",void 0);w([m({id:be.INDEX++,required:true,type:"uint32"})],be.prototype,"sessionCount",void 0);w([m({id:be.INDEX++,required:true,type:"uint32"})],be.prototype,"maxRwSessionCount",void 0);w([m({id:be.INDEX++,required:true,type:"uint32"})],be.prototype,"rwSessionCount",void 0);w([m({id:be.INDEX++,required:true,type:"uint32"})],be.prototype,"maxPinLen",void