UNPKG

xmldsigjs

Version:

XMLDSIGjs provides an implementation of XMLDSIG in Typescript/Javascript based on WebCrypto

1 lines 582 kB
var XmlDSigJs=function(e){"use strict";function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);r<t;r++)a[r]=e[r];return a}function r(e,t,r,a,n,i,s){try{var u=e[i](s),o=u.value}catch(e){return void r(e)}u.done?t(o):Promise.resolve(o).then(a,n)}function a(e){return function(){var t=this,a=arguments;return new Promise((function(n,i){var s=e.apply(t,a);function u(e){r(s,n,i,u,o,"next",e)}function o(e){r(s,n,i,u,o,"throw",e)}u(void 0)}))}}function n(e,t,r){return t=f(t),function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,v()?Reflect.construct(t,r||[],f(e).constructor):t.apply(e,r))}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t,r){if(v())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,t);var n=new(e.bind.apply(e,a));return r&&w(n,r.prototype),n}function u(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,C(a.key),a)}}function o(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=E(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var a=0,n=function(){};return{s:n,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){u=!0,i=e},f:function(){try{s||null==r.return||r.return()}finally{if(u)throw i}}}}function c(e,t,r){return(t=C(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var a=S(e,t);if(a){var n=Object.getOwnPropertyDescriptor(a,t);return n.get?n.get.call(arguments.length<3?e:r):n.value}},h.apply(null,arguments)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function m(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&w(e,t)}function v(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(v=function(){return!!e})()}function d(e){if(null==e)throw new TypeError("Cannot destructure "+e)}function g(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){c(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(e,t){if(null==e)return{};var r,a,n=function(e,t){if(null==e)return{};var r={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(t.includes(a))continue;r[a]=e[a]}return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)r=i[a],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function k(){k=function(){return t};var e,t={},r=Object.prototype,a=r.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",o=i.toStringTag||"@@toStringTag";function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,r){return e[t]=r}}function c(e,t,r,a){var i=t&&t.prototype instanceof g?t:g,s=Object.create(i.prototype),u=new V(a||[]);return n(s,"_invoke",{value:x(e,r,u)}),s}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=c;var f="suspendedStart",m="executing",v="completed",d={};function g(){}function p(){}function y(){}var w={};l(w,s,(function(){return this}));var b=Object.getPrototypeOf,S=b&&b(b(D([])));S&&S!==r&&a.call(S,s)&&(w=S);var A=y.prototype=g.prototype=Object.create(w);function N(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function r(n,i,s,u){var o=h(e[n],e,i);if("throw"!==o.type){var l=o.arg,c=l.value;return c&&"object"==typeof c&&a.call(c,"__await")?t.resolve(c.__await).then((function(e){r("next",e,s,u)}),(function(e){r("throw",e,s,u)})):t.resolve(c).then((function(e){l.value=e,s(l)}),(function(e){return r("throw",e,s,u)}))}u(o.arg)}var i;n(this,"_invoke",{value:function(e,a){function n(){return new t((function(t,n){r(e,a,t,n)}))}return i=i?i.then(n,n):n()}})}function x(t,r,a){var n=f;return function(i,s){if(n===m)throw Error("Generator is already running");if(n===v){if("throw"===i)throw s;return{value:e,done:!0}}for(a.method=i,a.arg=s;;){var u=a.delegate;if(u){var o=E(u,a);if(o){if(o===d)continue;return o}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(n===f)throw n=v,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);n=m;var l=h(t,r,a);if("normal"===l.type){if(n=a.done?v:"suspendedYield",l.arg===d)continue;return{value:l.arg,done:a.done}}"throw"===l.type&&(n=v,a.method="throw",a.arg=l.arg)}}}function E(t,r){var a=r.method,n=t.iterator[a];if(n===e)return r.delegate=null,"throw"===a&&t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method)||"return"!==a&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+a+"' method")),d;var i=h(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var s=i.arg;return s?s.done?(r[t.resultName]=s.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):s:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function B(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function V(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function D(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(a.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return p.prototype=y,n(A,"constructor",{value:y,configurable:!0}),n(y,"constructor",{value:p,configurable:!0}),p.displayName=l(y,o,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,l(e,o,"GeneratorFunction")),e.prototype=Object.create(A),e},t.awrap=function(e){return{__await:e}},N(C.prototype),l(C.prototype,u,(function(){return this})),t.AsyncIterator=C,t.async=function(e,r,a,n,i){void 0===i&&(i=Promise);var s=new C(c(e,r,a,n),i);return t.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},N(A),l(A,o,"Generator"),l(A,s,(function(){return this})),l(A,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var a in t)r.push(a);return r.reverse(),function e(){for(;r.length;){var a=r.pop();if(a in t)return e.value=a,e.done=!1,e}return e.done=!0,e}},t.values=D,V.prototype={constructor:V,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(B),!t)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(a,n){return u.type="throw",u.arg=t,r.next=a,n&&(r.method="next",r.arg=e),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],u=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var o=a.call(s,"catchLoc"),l=a.call(s,"finallyLoc");if(o&&l){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(o){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),B(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var a=r.completion;if("throw"===a.type){var n=a.arg;B(r)}return n}}throw Error("illegal catch attempt")},delegateYield:function(t,r,a){return this.delegate={iterator:D(t),resultName:r,nextLoc:a},"next"===this.method&&(this.arg=e),d}},t}function w(e,t){return w=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},w(e,t)}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var a,n,i,s,u=[],o=!0,l=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;o=!1}else for(;!(o=(a=i.call(r)).done)&&(u.push(a.value),u.length!==t);o=!0);}catch(e){l=!0,n=e}finally{try{if(!o&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(l)throw n}}return u}}(e,t)||E(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=f(e)););return e}function A(e,t,r,a){var n=h(f(1&a?e.prototype:e),t,r);return 2&a?function(e){return n.apply(r,e)}:n}function N(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||E(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function C(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function x(e){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},x(e)}function E(e,r){if(e){if("string"==typeof e)return t(e,r);var a={}.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?t(e,r):void 0}}function I(e){var t="function"==typeof Map?new Map:void 0;return I=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,f(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),w(r,e)},I(e)}var B=["name","optional","primitiveSchema"],V=["value"],D=["isHexOnly"],P=["value","isIndefiniteForm"],O=["value"],R=["isConstructed"],U=["idBlock","lenBlock"],L=["unusedBits","isConstructed"],T=["idBlock","lenBlock"],H=["value"],M=["valueDec","isFirstSid"],K=["value"],_=["valueDec"],j=["value"],J=["value","valueDate"],F=["value"],q=["value","local"],X="element",G="attribute",W="content",z=1e9;function Y(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];for(var n=arguments[0],i=1;i<arguments.length;i++){var s=arguments[i];for(var u in s)s.hasOwnProperty(u)&&(n[u]=s[u])}return n}function Q(e){return function(t){var r=t;r.localName=e.localName||r.name,r.namespaceURI=e.namespaceURI||r.namespaceURI||null,r.prefix=e.prefix||r.prefix||null,r.parser=e.parser||r.parser,r.target!==r&&(r.items=Y({},r.items)),r.target=t}}function Z(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,r){var a=t.constructor,n=r;a.items||(a.items={}),a.target!==a&&(a.items=Y({},a.items)),a.target=t,e.parser?a.items[n]={parser:e.parser,required:e.required||!1,maxOccurs:e.maxOccurs||z,minOccurs:void 0===e.minOccurs?0:e.minOccurs,noRoot:e.noRoot||!1}:a.items[n]={namespaceURI:e.namespaceURI||null,required:e.required||!1,prefix:e.prefix||null,defaultValue:e.defaultValue,converter:e.converter,noRoot:e.noRoot||!1},e.localName=e.localName||e.parser&&e.parser.localName||n,a.items[n].namespaceURI=e.namespaceURI||e.parser&&e.parser.namespaceURI||null,a.items[n].prefix=e.prefix||e.parser&&e.parser.prefix||null,a.items[n].localName=e.localName,a.items[n].type=X,ee(t,n,e)}}function $(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{required:!1,namespaceURI:null};return function(t,r){var a=t.constructor,n=r;e.localName||(e.localName=r),a.items||(a.items={}),a.target!==a&&(a.items=Y({},a.items)),a.target=t,a.items[r]=e,a.items[r].type=G,ee(t,n,e)}}function ee(e,t,r){var a="_".concat(t),n={set:function(e){this[a]!==e&&(this.element=null,this[a]=e)},get:function(){if(void 0===this[a]){var e=r.defaultValue;r.parser&&((e=new r.parser).localName=r.localName),this[a]=e}return this[a]}};Object.defineProperty(e,a,{writable:!0,enumerable:!1}),Object.defineProperty(e,t,n)}var te=function(){function e(t){i(this,e),this.items=new Array,t&&(this.items=t)}return o(e,[{key:"Count",get:function(){return this.items.length}},{key:"Item",value:function(e){return this.items[e]||null}},{key:"Add",value:function(e){this.items.push(e)}},{key:"Pop",value:function(){return this.items.pop()}},{key:"RemoveAt",value:function(e){this.items=this.items.filter((function(t,r){return r!==e}))}},{key:"Clear",value:function(){this.items=new Array}},{key:"GetIterator",value:function(){return this.items}},{key:"ForEach",value:function(e){this.GetIterator().forEach(e)}},{key:"Map",value:function(t){return new e(this.GetIterator().map(t))}},{key:"Filter",value:function(t){return new e(this.GetIterator().filter(t))}},{key:"Sort",value:function(t){return new e(this.GetIterator().sort(t))}},{key:"Every",value:function(e){return this.GetIterator().every(e)}},{key:"Some",value:function(e){return this.GetIterator().some(e)}},{key:"IsEmpty",value:function(){return 0===this.Count}}])}();function re(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];for(var n=e,i=/[^%](%\d+)/g,s=null,u=[];s=i.exec(n);)u.push({arg:s[1],index:s.index});for(var o=u.length-1;o>=0;o--){var l=u[o],c=l.arg.substring(1),h=l.index+1;n=n.substring(0,h)+arguments[+c]+n.substring(h+1+c.length)}return n=n.replace("%%","%")}function ae(e,t){for(var r=e+"";r.length<t;)r="0"+r;return r}var ne,ie=o((function e(t){for(var r=arguments.length,a=new Array(r>1?r-1:0),n=1;n<r;n++)a[n-1]=arguments[n];i(this,e),this.prefix="XMLJS",this.code=t,this.name=this.constructor.name,arguments[0]=se[t];var s=re.apply(this,arguments);this.message="".concat(this.prefix).concat(ae(t,4),": ").concat(s),this.stack=new Error(this.message).stack}));!function(e){e[e.NONE=0]="NONE",e[e.NULL_REFERENCE=1]="NULL_REFERENCE",e[e.NULL_PARAM=2]="NULL_PARAM",e[e.DECORATOR_NULL_PARAM=3]="DECORATOR_NULL_PARAM",e[e.COLLECTION_LIMIT=4]="COLLECTION_LIMIT",e[e.METHOD_NOT_IMPLEMENTED=5]="METHOD_NOT_IMPLEMENTED",e[e.METHOD_NOT_SUPPORTED=6]="METHOD_NOT_SUPPORTED",e[e.PARAM_REQUIRED=7]="PARAM_REQUIRED",e[e.CONVERTER_UNSUPPORTED=8]="CONVERTER_UNSUPPORTED",e[e.ELEMENT_MALFORMED=9]="ELEMENT_MALFORMED",e[e.ELEMENT_MISSING=10]="ELEMENT_MISSING",e[e.ATTRIBUTE_MISSING=11]="ATTRIBUTE_MISSING",e[e.CONTENT_MISSING=12]="CONTENT_MISSING",e[e.CRYPTOGRAPHIC=13]="CRYPTOGRAPHIC",e[e.CRYPTOGRAPHIC_NO_MODULE=14]="CRYPTOGRAPHIC_NO_MODULE",e[e.CRYPTOGRAPHIC_UNKNOWN_TRANSFORM=15]="CRYPTOGRAPHIC_UNKNOWN_TRANSFORM",e[e.ALGORITHM_NOT_SUPPORTED=16]="ALGORITHM_NOT_SUPPORTED",e[e.ALGORITHM_WRONG_NAME=17]="ALGORITHM_WRONG_NAME",e[e.XML_EXCEPTION=18]="XML_EXCEPTION"}(ne||(ne={}));var se={};se[ne.NONE]="No description",se[ne.NULL_REFERENCE]="Null reference",se[ne.NULL_PARAM]="'%1' has empty '%2' object",se[ne.DECORATOR_NULL_PARAM]="Decorator '%1' has empty '%2' parameter",se[ne.COLLECTION_LIMIT]="Collection of '%1' in element '%2' has wrong amount of items",se[ne.METHOD_NOT_IMPLEMENTED]="Method is not implemented",se[ne.METHOD_NOT_SUPPORTED]="Method is not supported",se[ne.PARAM_REQUIRED]="Required parameter is missing '%1'",se[ne.CONVERTER_UNSUPPORTED]="Converter is not supported",se[ne.ELEMENT_MALFORMED]="Malformed element '%1'",se[ne.ELEMENT_MISSING]="Element '%1' is missing in '%2'",se[ne.ATTRIBUTE_MISSING]="Attribute '%1' is missing in '%2'",se[ne.CONTENT_MISSING]="Content is missing in '%1'",se[ne.CRYPTOGRAPHIC]="Cryptographic error: %1",se[ne.CRYPTOGRAPHIC_NO_MODULE]="WebCrypto module is not found",se[ne.CRYPTOGRAPHIC_UNKNOWN_TRANSFORM]="Unknown transform %1",se[ne.ALGORITHM_NOT_SUPPORTED]="Algorithm is not supported '%1'",se[ne.ALGORITHM_WRONG_NAME]="Algorithm wrong name in use '%1'",se[ne.XML_EXCEPTION]="XML exception: %1";var ue,oe=o((function e(){i(this,e)}),null,[{key:"ToString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8",r=new Uint8Array(e);switch(t.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);default:throw new ie(ne.CONVERTER_UNSUPPORTED)}}},{key:"FromString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8";switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);default:throw new ie(ne.CONVERTER_UNSUPPORTED)}}},{key:"ToBase64",value:function(e){if("undefined"!=typeof btoa){var t=this.ToString(e,"binary");return btoa(t)}if("undefined"!=typeof Buffer)return Buffer.from(e).toString("base64");throw new ie(ne.CONVERTER_UNSUPPORTED)}},{key:"FromBase64",value:function(e){if(e=e.replace(/\n/g,"").replace(/\r/g,"").replace(/\t/g,"").replace(/\s/g,""),"undefined"!=typeof atob)return this.FromBinary(atob(e));if("undefined"!=typeof Buffer)return new Uint8Array(Buffer.from(e,"base64"));throw new ie(ne.CONVERTER_UNSUPPORTED)}},{key:"FromBase64Url",value:function(e){return this.FromBase64(this.Base64Padding(e.replace(/\-/g,"+").replace(/\_/g,"/")))}},{key:"ToBase64Url",value:function(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}},{key:"FromUtf8String",value:function(e){for(var t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length),a=0;a<t.length;a++)r[a]=t.charCodeAt(a);return r}},{key:"ToUtf8String",value:function(e){var t=String.fromCharCode.apply(null,e);return decodeURIComponent(escape(t))}},{key:"FromBinary",value:function(e){for(var t=e.length,r=new Uint8Array(t),a=0;a<t;a++)r[a]=e.charCodeAt(a);return r}},{key:"ToBinary",value:function(e){for(var t="",r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t}},{key:"ToHex",value:function(e){for(var t=[],r=0;r<e.length;r++){var a=e[r].toString(16);t.push(1===a.length?"0"+a:a)}return t.join("")}},{key:"FromHex",value:function(e){for(var t=new Uint8Array(e.length/2),r=0;r<e.length;r+=2){var a=e.slice(r,r+2);t[r/2]=parseInt(a,16)}return t}},{key:"ToDateTime",value:function(e){return new Date(e)}},{key:"FromDateTime",value:function(e){return e.toISOString()}},{key:"Base64Padding",value:function(e){var t=4-e.length%4;if(t<4)for(var r=0;r<t;r++)e+="=";return e}}]),le="application/xml";!function(e){e[e.None=0]="None",e[e.Element=1]="Element",e[e.Attribute=2]="Attribute",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.EntityReference=5]="EntityReference",e[e.Entity=6]="Entity",e[e.ProcessingInstruction=7]="ProcessingInstruction",e[e.Comment=8]="Comment",e[e.Document=9]="Document",e[e.DocumentType=10]="DocumentType",e[e.DocumentFragment=11]="DocumentFragment",e[e.Notation=12]="Notation",e[e.Whitespace=13]="Whitespace",e[e.SignificantWhitespace=14]="SignificantWhitespace",e[e.EndElement=15]="EndElement",e[e.EndEntity=16]="EndEntity",e[e.XmlDeclaration=17]="XmlDeclaration"}(ue||(ue={}));var ce,he=function(e,t){throw new Error("Not implemented")};if("undefined"==typeof self){ce=global;var fe=require("@xmldom/xmldom");he=require("xpath.js"),ce.XMLSerializer=fe.XMLSerializer,ce.DOMParser=fe.DOMParser,ce.DOMImplementation=fe.DOMImplementation,ce.document=(new DOMImplementation).createDocument("http://www.w3.org/1999/xhtml","html",null)}else ce=self;var me="undefined"!=typeof self?function(e,t){for(var r,a=null==e.ownerDocument?e:e.ownerDocument,n=document.createNSResolver(null==e.ownerDocument?e.documentElement:e.ownerDocument.documentElement),i=a.evaluate(t,e,n,XPathResult.ANY_TYPE,null),s=[];r=i.iterateNext();)s.push(r);return s}:he;function ve(e){return e=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"),(new DOMParser).parseFromString(e,le)}function de(e,t){var r=me(e,t);return r&&r.length>0?r[0]:null}function ge(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(we(e)){e.namespaceURI&&"http://www.w3.org/XML/1998/namespace"!==e.namespaceURI&&!t[e.prefix||""]&&(t[e.prefix?e.prefix:""]=e.namespaceURI);for(var r=0;r<e.childNodes.length;r++){var a=e.childNodes.item(r);a&&a.nodeType===ue.Element&&ge(a,t)}}}function pe(e){var t={};return ge(e,t),t}function ye(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];for(var n=arguments[0],i=1;i<arguments.length;i++){var s=arguments[i];for(var u in s)s.hasOwnProperty(u)&&(n[u]=s[u])}return n}function ke(e,t){return e&&e.nodeType===t}function we(e){return ke(e,ue.Element)}function be(e){return ke(e,ue.Document)}var Se={get:function(e){if(e)return oe.ToBase64(e)},set:function(e){return oe.FromBase64(e)}},Ae={get:function(e){return e?e.toString():"0"},set:function(e){return Number(e)}},Ne="xml_root",Ce=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(i(this,e),this.prefix=this.GetStatic().prefix||null,this.localName=this.GetStatic().localName,this.namespaceURI=this.GetStatic().namespaceURI,t)for(var r=0,a=Object.entries(t);r<a.length;r++){var n=b(a[r],2),s=n[0],u=n[1];void 0!==u&&(this[s]=u)}}return o(e,[{key:"Element",get:function(){return this.element}},{key:"Prefix",get:function(){return this.prefix},set:function(e){this.prefix=e}},{key:"LocalName",get:function(){return this.localName}},{key:"NamespaceURI",get:function(){return this.namespaceURI||null}},{key:"HasChanged",value:function(){var e=this.GetStatic();if(e.items)for(var t in e.items)if(e.items.hasOwnProperty(t)){var r=e.items[t],a=this[t];if(r.parser&&a&&a.HasChanged())return!0}return null===this.element}},{key:"GetXml",value:function(t){if(!t&&!this.HasChanged())return this.element||null;var r=this.CreateDocument(),a=this.CreateElement(),n=this.GetStatic(),i=this.localName;if(n.items)for(var s in n.items)if(n.items.hasOwnProperty(s)){var u=this[s],o=n.items[s];switch(o.type){case W:var c=o,h=c.converter?c.converter.get(u):u;if(c.required&&null==h)throw new ie(ne.CONTENT_MISSING,i);(c.defaultValue!==u||c.required)&&(a.textContent=h);break;case G:var f=o,m=f.converter?f.converter.get(u):u;if(f.required&&null==m)throw new ie(ne.ATTRIBUTE_MISSING,f.localName,i);(f.defaultValue!==u||f.required)&&(f.namespaceURI?a.setAttributeNS(f.namespaceURI,f.localName,m):a.setAttribute(f.localName,m));break;case X:var v=o,d=null;if(v.parser){if(v.required&&!u||v.minOccurs&&!u.Count)throw new ie(ne.ELEMENT_MISSING,u.localName,i);u&&(d=u.GetXml(void 0===u.element&&(v.required||u.Count)))}else{var g=v.converter?v.converter.get(u):u;if(v.required&&void 0===g)throw new ie(ne.ELEMENT_MISSING,v.localName,i);if(u!==v.defaultValue||v.required)if(d=v.namespaceURI?r.createElementNS(v.namespaceURI,"".concat(v.prefix?v.prefix+":":"").concat(v.localName)):r.createElement("".concat(v.prefix?v.prefix+":":"").concat(v.localName)),Array.isArray(g)){var p,y=l(g);try{for(y.s();!(p=y.n()).done;){var k=p.value,w=k instanceof e?k.GetXml(!0):k;null!==w&&d.appendChild(w)}}catch(e){y.e(e)}finally{y.f()}}else g instanceof e?d.appendChild(g.GetXml(!0)):d.textContent=g}if(d)if(v.noRoot){for(var b=[],S=0;S<d.childNodes.length;S++){var A=d.childNodes.item(S);we(A)&&b.push(A)}if(b.length<v.minOccurs||b.length>v.maxOccurs)throw new ie(ne.COLLECTION_LIMIT,u.localName,n.localName);b.forEach((function(e){return a.appendChild(e.cloneNode(!0))}))}else{if(d.childNodes.length<v.minOccurs||d.childNodes.length>v.maxOccurs)throw new ie(ne.COLLECTION_LIMIT,u.localName,n.localName);a.appendChild(d)}}}return this.OnGetXml(a),this.element=a,a}},{key:"LoadXml",value:function(e){var t,r=this;"string"==typeof e?t=ve(e).documentElement:t=e;if(!t)throw new ie(ne.PARAM_REQUIRED,"element");var a=this.GetStatic(),n=this.localName;if(t.localName!==n||t.namespaceURI!=this.NamespaceURI)throw new ie(ne.ELEMENT_MALFORMED,n);if(a.items)for(var i in a.items)if(a.items.hasOwnProperty(i)){var s=a.items[i];switch(s.type){case W:var u=s;if(u.required&&!t.textContent)throw new ie(ne.CONTENT_MISSING,n);if(t.textContent){var o=u.converter?u.converter.set(t.textContent):t.textContent;r[i]=o}else r[i]=u.defaultValue;break;case G:var l=s,c=void 0,h=void 0;if(!l.localName)throw new ie(ne.PARAM_REQUIRED,"localName");if(l.namespaceURI?(c=t.hasAttributeNS.bind(t,l.namespaceURI,l.localName),h=t.getAttributeNS.bind(t,l.namespaceURI,l.localName)):(c=t.hasAttribute.bind(t,l.localName),h=t.getAttribute.bind(t,l.localName)),l.required&&!c())throw new ie(ne.ATTRIBUTE_MISSING,l.localName,n);if(c()){var f=l.converter?l.converter.set(h()):h();r[i]=f}else r[i]=l.defaultValue;break;case X:var m=s;if(m.noRoot){if(!m.parser)throw new ie(ne.XML_EXCEPTION,"Schema for '".concat(m.localName,"' with flag noRoot must have 'parser'"));var v=new m.parser;if(!(v instanceof xe))throw new ie(ne.XML_EXCEPTION,"Schema for '".concat(m.localName,"' with flag noRoot must have 'parser' like instance of XmlCollection"));if(v.OnLoadXml(t),delete v.element,v.Count<m.minOccurs||v.Count>m.maxOccurs)throw new ie(ne.COLLECTION_LIMIT,m.parser.localName,n);r[i]=v;continue}for(var d=null,g=0;g<t.childNodes.length;g++){var p=t.childNodes.item(g);if(we(p)){var y=p;if(y.localName===m.localName&&y.namespaceURI==m.namespaceURI){d=y;break}}}if(m.required&&!d)throw new ie(ne.ELEMENT_MISSING,m.parser?m.parser.localName:m.localName,n);if(m.parser){if(d){var k=new m.parser;k.localName=m.localName,k.namespaceURI=m.namespaceURI,r[i]=k,k.LoadXml(d)}}else if(d){var w=m.converter?m.converter.set(d.textContent):d.textContent;r[i]=w}else r[i]=m.defaultValue}}this.OnLoadXml(t),this.prefix=t.prefix||"",this.element=t}},{key:"toString",value:function(){var e=this.GetXml();return e?(new XMLSerializer).serializeToString(e):""}},{key:"GetElement",value:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!this.element)throw new ie(ne.NULL_PARAM,this.localName);return e.GetElement(this.element,t,r)}},{key:"GetChildren",value:function(t,r){if(!this.element)throw new ie(ne.NULL_PARAM,this.localName);return e.GetChildren(this.element,t,r||this.NamespaceURI||void 0)}},{key:"GetChild",value:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!this.element)throw new ie(ne.NULL_PARAM,this.localName);return e.GetChild(this.element,t,this.NamespaceURI||void 0,r)}},{key:"GetFirstChild",value:function(t,r){if(!this.element)throw new ie(ne.NULL_PARAM,this.localName);return e.GetFirstChild(this.element,t,r)}},{key:"GetAttribute",value:function(t,r){var a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!this.element)throw new ie(ne.NULL_PARAM,this.localName);return e.GetAttribute(this.element,t,r,a)}},{key:"IsEmpty",value:function(){return void 0===this.Element}},{key:"OnLoadXml",value:function(e){}},{key:"GetStatic",value:function(){return this.constructor}},{key:"GetPrefix",value:function(){return this.Prefix?this.prefix+":":""}},{key:"OnGetXml",value:function(e){}},{key:"CreateElement",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;e||(e=this.CreateDocument()),t=t||this.localName,r=r||this.NamespaceURI;var n=((a=a||this.prefix)?"".concat(a,":"):"")+t,i=r?e.createElementNS(r,n):e.createElement(n);return e.importNode(i,!0),i}},{key:"CreateDocument",value:function(){return e.CreateDocument(this.localName,this.NamespaceURI,this.Prefix)}}],[{key:"LoadXml",value:function(e){var t=new this;return t.LoadXml(e),t}},{key:"GetElement",value:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],a=e.getElementsByTagName(t);if(r&&0===a.length)throw new ie(ne.ELEMENT_MISSING,t,e.localName);return a[0]||null}},{key:"GetAttribute",value:function(e,t,r){var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(e.hasAttribute(t))return e.getAttribute(t);if(a)throw new ie(ne.ATTRIBUTE_MISSING,t,e.localName);return r}},{key:"GetElementById",value:function(e,t){if(null==e||null==t)return null;var r=null;return be(e)&&(r=e.getElementById(t)),null==r&&null==(r=de(e,"//*[@*[local-name()='Id']='".concat(t,"']")))&&null==(r=de(e,"//*[@*[local-name()='ID']='".concat(t,"']")))&&(r=de(e,"//*[@*[local-name()='id']='".concat(t,"']"))),r}},{key:"CreateDocument",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ne,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a="",n="",i="";r&&(a=r+":",n=":"+r),t&&(i=" xmlns".concat(n,'="').concat(t,'"'));var s="".concat(a).concat(e),u=(new DOMParser).parseFromString("<".concat(s).concat(i,"></").concat(s,">"),le);return u}},{key:"GetChildren",value:function(e,t,r){e=be(e)?e.documentElement:e;for(var a=[],n=0;n<e.childNodes.length;n++){var i=e.childNodes[n];!we(i)||i.localName!==t||i.namespaceURI!==r&&r||a.push(i)}return a}},{key:"GetFirstChild",value:function(e,t,r){e=be(e)?e.documentElement:e;for(var a=0;a<e.childNodes.length;a++){var n=e.childNodes[a];if(we(n)&&n.localName===t&&(n.namespaceURI===r||!r))return n}return null}},{key:"GetChild",value:function(e,t,r){for(var a=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],n=0;n<e.childNodes.length;n++){var i=e.childNodes[n];if(we(i)&&i.localName===t&&(i.namespaceURI===r||!r))return i}if(a)throw new ie(ne.ELEMENT_MISSING,t,e.localName);return null}}])}(),xe=function(e){function t(){var e;return i(this,t),(e=n(this,t,arguments)).MaxOccurs=Number.MAX_VALUE,e.MinOccurs=0,e.items=[],e}return m(t,e),o(t,[{key:"HasChanged",value:function(){var e=A(t,"HasChanged",this,3)([]),r=this.Some((function(e){return e.HasChanged()}));return e||r}},{key:"Count",get:function(){return this.items.length}},{key:"Item",value:function(e){return this.items[e]||null}},{key:"Add",value:function(e){this.items.push(e),this.element=null}},{key:"Pop",value:function(){return this.element=null,this.items.pop()}},{key:"RemoveAt",value:function(e){this.items=this.items.filter((function(t,r){return r!==e})),this.element=null}},{key:"Clear",value:function(){this.items=new Array,this.element=null}},{key:"GetIterator",value:function(){return this.items}},{key:"ForEach",value:function(e){this.GetIterator().forEach(e)}},{key:"Map",value:function(e){return new te(this.GetIterator().map(e))}},{key:"Filter",value:function(e){return new te(this.GetIterator().filter(e))}},{key:"Sort",value:function(e){return new te(this.GetIterator().sort(e))}},{key:"Every",value:function(e){return this.GetIterator().every(e)}},{key:"Some",value:function(e){return this.GetIterator().some(e)}},{key:"IsEmpty",value:function(){return 0===this.Count}},{key:"OnGetXml",value:function(e){var t,r=l(this.GetIterator());try{for(r.s();!(t=r.n()).done;){var a=t.value.GetXml();a&&e.appendChild(a)}}catch(e){r.e(e)}finally{r.f()}}},{key:"OnLoadXml",value:function(e){var t=this.GetStatic();if(!t.parser)throw new ie(ne.XML_EXCEPTION,"".concat(t.localName," doesn't have required 'parser' in @XmlElement"));for(var r=0;r<e.childNodes.length;r++){var a=e.childNodes.item(r);if(we(a)&&a.localName===t.parser.localName&&a.namespaceURI==t.namespaceURI){var n=a,i=new t.parser;i.LoadXml(n),this.Add(i)}}}}])}(Ce),Ee=function(e){function t(){return i(this,t),n(this,t,arguments)}return m(t,e),o(t,[{key:"Add",value:function(e){e.prefix=e.prefix||"",e.namespace=e.namespace||"",A(t,"Add",this,3)([e])}},{key:"GetPrefix",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.Count-1,r=this.Count-1;e=e||"",t>r&&(t=r);for(var a=t;a>=0;a--){var n=this.items[a];if(n.prefix===e)return n}return null}},{key:"GetNamespace",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.Count-1,r=this.Count-1;e=e||"",t>r&&(t=r);for(var a=t;a>=0;a--){var n=this.items[a];if(n.namespace===e)return n}return null}}])}(te),Ie=function(){function e(){i(this,e)}return o(e,null,[{key:"isArrayBuffer",value:function(e){return"[object ArrayBuffer]"===Object.prototype.toString.call(e)}},{key:"toArrayBuffer",value:function(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}},{key:"toUint8Array",value:function(e){return this.toView(e,Uint8Array)}},{key:"toView",value:function(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}},{key:"isBufferSource",value:function(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}},{key:"isArrayBufferView",value:function(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}},{key:"isEqual",value:function(t,r){var a=e.toUint8Array(t),n=e.toUint8Array(r);if(a.length!==n.byteLength)return!1;for(var i=0;i<a.length;i++)if(a[i]!==n[i])return!1;return!0}},{key:"concat",value:function(){for(var e,t=arguments.length,r=new Array(t),a=0;a<t;a++)r[a]=arguments[a];var n,i=0,s=l(e=!Array.isArray(r[0])||r[1]instanceof Function?Array.isArray(r[0])&&r[1]instanceof Function?r[0]:r[r.length-1]instanceof Function?r.slice(0,r.length-1):r:r[0]);try{for(s.s();!(n=s.n()).done;){var u=n.value;i+=u.byteLength}}catch(e){s.e(e)}finally{s.f()}var o,c=new Uint8Array(i),h=0,f=l(e);try{for(f.s();!(o=f.n()).done;){var m=o.value,v=this.toUint8Array(m);c.set(v,h),h+=v.length}}catch(e){f.e(e)}finally{f.f()}return r[r.length-1]instanceof Function?this.toView(c,r[r.length-1]):c.buffer}}])}(),Be="string",Ve=/^[0-9a-f]+$/i,De=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Pe=/^[a-zA-Z0-9-_]+$/,Oe=o((function e(){i(this,e)}),null,[{key:"fromString",value:function(e){for(var t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length),a=0;a<t.length;a++)r[a]=t.charCodeAt(a);return r.buffer}},{key:"toString",value:function(e){for(var t=Ie.toUint8Array(e),r="",a=0;a<t.length;a++)r+=String.fromCharCode(t[a]);return decodeURIComponent(escape(r))}}]),Re=o((function e(){i(this,e)}),null,[{key:"toString",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=Ie.toArrayBuffer(e),a=new DataView(r),n="",i=0;i<r.byteLength;i+=2){var s=a.getUint16(i,t);n+=String.fromCharCode(s)}return n}},{key:"fromString",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=new ArrayBuffer(2*e.length),a=new DataView(r),n=0;n<e.length;n++)a.setUint16(2*n,e.charCodeAt(n),t);return r}}]),Ue=function(){function e(){i(this,e)}return o(e,null,[{key:"isHex",value:function(e){return x(e)===Be&&Ve.test(e)}},{key:"isBase64",value:function(e){return x(e)===Be&&De.test(e)}},{key:"isBase64Url",value:function(e){return x(e)===Be&&Pe.test(e)}},{key:"ToString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8",r=Ie.toUint8Array(e);switch(t.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 Re.toString(r,!0);case"utf16":case"utf16be":return Re.toString(r);default:throw new Error("Unknown type of encoding '".concat(t,"'"))}}},{key:"FromString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf8";if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Re.fromString(e,!0);case"utf16":case"utf16be":return Re.fromString(e);default:throw new Error("Unknown type of encoding '".concat(t,"'"))}}},{key:"ToBase64",value:function(e){var t=Ie.toUint8Array(e);if("undefined"!=typeof btoa){var r=this.ToString(t,"binary");return btoa(r)}return Buffer.from(t).toString("base64")}},{key:"FromBase64",value:function(t){var r=this.formatString(t);if(!r)return new ArrayBuffer(0);if(!e.isBase64(r))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return"undefined"!=typeof atob?this.FromBinary(atob(r)):new Uint8Array(Buffer.from(r,"base64")).buffer}},{key:"FromBase64Url",value:function(t){var r=this.formatString(t);if(!r)return new ArrayBuffer(0);if(!e.isBase64Url(r))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(r.replace(/\-/g,"+").replace(/\_/g,"/")))}},{key:"ToBase64Url",value:function(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}},{key:"FromUtf8String",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.DEFAULT_UTF8_ENCODING;switch(r){case"ascii":return this.FromBinary(t);case"utf8":return Oe.fromString(t);case"utf16":case"utf16be":return Re.fromString(t);case"utf16le":case"usc2":return Re.fromString(t,!0);default:throw new Error("Unknown type of encoding '".concat(r,"'"))}}},{key:"ToUtf8String",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.DEFAULT_UTF8_ENCODING;switch(r){case"ascii":return this.ToBinary(t);case"utf8":return Oe.toString(t);case"utf16":case"utf16be":return Re.toString(t);case"utf16le":case"usc2":return Re.toString(t,!0);default:throw new Error("Unknown type of encoding '".concat(r,"'"))}}},{key:"FromBinary",value:function(e){for(var t=e.length,r=new Uint8Array(t),a=0;a<t;a++)r[a]=e.charCodeAt(a);return r.buffer}},{key:"ToBinary",value:function(e){for(var t=Ie.toUint8Array(e),r="",a=0;a<t.length;a++)r+=String.fromCharCode(t[a]);return r}},{key:"ToHex",value:function(e){for(var t=Ie.toUint8Array(e),r="",a=t.length,n=0;n<a;n++){var i=t[n];i<16&&(r+="0"),r+=i.toString(16)}return r}},{key:"FromHex",value:function(t){var r=this.formatString(t);if(!r)return new ArrayBuffer(0);if(!e.isHex(r))throw new TypeError("Argument 'hexString' is not HEX encoded");r.length%2&&(r="0".concat(r));for(var a=new Uint8Array(r.length/2),n=0;n<r.length;n+=2){var i=r.slice(n,n+2);a[n/2]=parseInt(i,16)}return a.buffer}},{key:"ToUtf16String",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Re.toString(e,t)}},{key:"FromUtf16String",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return Re.fromString(e,t)}},{key:"Base64Padding",value:function(e){var t=4-e.length%4;if(t<4)for(var r=0;r<t;r++)e+="=";return e}},{key:"formatString",value:function(e){return(null==e?void 0:e.replace(/[\n\r\t ]/g,""))||""}}])}();function Le(e,t,r){var a;return e instanceof Object==!1?r:null!==(a=e[t])&&void 0!==a?a:r}function Te(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.byteLength-r,n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i="",s=l(new Uint8Array(e,r,a));try{for(s.s();!(t=s.n()).done;){var u=t.value,o=u.toString(16).toUpperCase();1===o.length&&(i+="0"),i+=o,n&&(i+=" ")}}catch(e){s.e(e)}finally{s.f()}return i.trim()}function He(e,t){var r=0;if(1===e.length)return e[0];for(var a=e.length-1;a>=0;a--)r+=e[e.length-1-a]*Math.pow(2,t*a);return r}function Me(e,t){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,a=r,n=e,i=0,s=Math.pow(2,t),u=1;u<8;u++){if(e<s){var o=void 0;if(a<0)o=new ArrayBuffer(u),i=u;else{if(a<u)return new ArrayBuffer(0);o=new ArrayBuffer(a),i=a}for(var l=new Uint8Array(o),c=u-1;c>=0;c--){var h=Math.pow(2,c*t);l[i-c-1]=Math.floor(n/h),n-=l[i-c-1]*h}return o}s*=Math.pow(2,t)}return new ArrayBuffer(0)}function Ke(){for(var e=0,t=0,r=arguments.length,a=new Array(r),n=0;n<r;n++)a[n]=arguments[n];for(var i=0,s=a;i<s.length;i++){var u=s[i];e+=u.byteLength}for(var o=new ArrayBuffer(e),l=new Uint8Array(o),c=0,h=a;c<h.length;c++){var f=h[c];l.set(new Uint8Array(f),t),t+=f.byteLength}return o}function _e(){for(var e=0,t=0,r=arguments.length,a=new Array(r),n=0;n<r;n++)a[n]=arguments[n];for(var i=0,s=a;i<s.length;i++){var u=s[i];e+=u.length}for(var o=new ArrayBuffer(e),l=new Uint8Array(o),c=0,h=a;c<h.length;c++){var f=h[c];l.set(f,t),t+=f.length}return l}function je(){var e=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){var t=255===e[0]&&128&e[1],r=0===e[0]&&0==(128&e[1]);(t||r)&&this.warnings.push("Needlessly long format")}for(var a=new ArrayBuffer(this.valueHex.byteLength),n=new Uint8Array(a),i=0;i<this.valueHex.byteLength;i++)n[i]=0;n[0]=128&e[0];for(var s=He(n,8),u=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(u),l=0;l<this.valueHex.byteLength;l++)o[l]=e[l];return o[0]&=127,He(o,8)-s}function Je(e,t){if(e.byteLength!==t.byteLength)return!1;for(var r=new Uint8Array(e),a=new Uint8Array(t),n=0;n<r.length;n++)if(r[n]!==a[n])return!1;return!0}function Fe(e,t){var r=e.toString(10);if(t<r.length)return"";for(var a=t-r.length,n=new Array(a),i=0;i<a;i++)n[i]="0";return n.join("").concat(r)}Ue.DEFAULT_UTF8_ENCODING="utf8";var qe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";function Ge(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],n=0,i=0,s=0,u="",o=t?Xe:qe;if(a){for(var l=0,c=0;c<e.length;c++)if(0!==e.charCodeAt(c)){l=c;break}e=e.slice(l)}for(;n<e.length;){var h=e.charCodeAt(n++);n>=e.length&&(i=1);var f=e.charCodeAt(n++);n>=e.length&&(s=1);var m=e.charCodeAt(n++),v=h>>2,d=(3&h)<<4|f>>4,g=(15&f)<<2|m>>6,p=63&m;1===i?g=p=64:1===s&&(p=64),u+=r?64===g?"".concat(o.charAt(v)).concat(o.charAt(d)):64===p?"".concat(o.charAt(v)).concat(o.charAt(d)).concat(o.charAt(g)):"".concat(o.charAt(v)).concat(o.charAt(d)).concat(o.charAt(g)).concat(o.charAt(p)):"".concat(o.charAt(v)).concat(o.charAt(d)).concat(o.charAt(g)).concat(o.charAt(p))}return u}function We(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a=t?Xe:qe;function n(e){for(var t=0;t<64;t++)if(a.charAt(t)===e)return t;return 64}function i(e){return 64===e?0:e}for(var s=0,u="";s<e.length;){var o=n(e.charAt(s++)),l=s>=e.length?0:n(e.charAt(s++)),c=s>=e.length?0:n(e.charAt(s++)),h=s>=e.length?0:n(e.charAt(s++)),f=i(o)<<2|i(l)>>4,m=(15&i(l))<<4|i(c)>>2,v=(3&i(c))<<6|i(h);u+=String.fromCharCode(f),64!==c&&(u+=String.fromCharCode(m)),64!==h&&(u+=String.fromCharCode(v))}if(r){for(var d=u.length,g=-1,p=d-1;p>=0;p--)if(0!==u.charCodeAt(p)){g=p;break}u=-1!==g?u.slice(0,g+1):""}return u}function ze(e){var t,r="",a=l(new Uint8Array(e));try{for(a.s();!(t=a.n()).done;){var n=t.value;r+=String.fromCharCode(n)}}catch(e){a.e(e)}finally{a.f()}return r}function Ye(e){for(var t=e.length,r=new ArrayBuffer(t),a=new Uint8Array(r),n=0;n<t;n++)a[n]=e.charCodeAt(n);return r}var Qe=Math.log(2);function Ze(e,t){var r,a=l(t);try{for(a.s();!(r=a.n()).done;){delete e[r.value]}}catch(e){a.e(e)}finally{a.f()}}function $e(){if("undefined"==typeof BigInt)throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function et(e){for(var t=0,r=0,a=0;a<e.length;a++){t+=e[a].byteLength}for(var n=new Uint8Array(t),i=0;i<e.length;i++){var s=e[i];n.set(new Uint8Array(s),r),r+=s.byteLength}return n.buffer}function tt(e,t,r,a){return t instanceof Uint8Array?t.byteLength?r<0?(e.error="Wrong parameter: inputOffset less than zero",!1):a<0?(e.error="Wrong parameter: inputLength less than zero",!1):!(t.byteLength-r-a<0)||(e.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(e.error="Wrong parameter: inputBuffer has zero length",!1):(e.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var rt=o((function e(){i(this,e),this.items=[]}),[{key:"write",value:function(e){this.items.push(e)}},{key:"final",value:function(){return et(this.items)}}]),at=[new Uint8Array([1])],nt="0123456789",it="name",st="valueHexView",ut="",ot=new ArrayBuffer(0),lt=new Uint8Array(0),ct="EndOfContent",ht="OCTET STRING",ft="BIT STRING";function mt(e){var t;return t=function(e){function t(){var e,r;i(this,t);for(var a=arguments.length,s=new Array(a),u=0;u<a;u++)s[u]=arguments[u];e=n(this,t,[].concat(s));var o=s[0]||{};return e.isHexOnly=null!==(r=o.isHexOnly)&&void 0!==r&&r,e.valueHexView=o.valueHex?Ie.toUint8Array(o.valueHex):lt,e}return m(t,e),o(t,[{key:"valueHex",get:function(){return this.valueHexView.slice().buffer},set:function(e){this.valueHexView=new Uint8Array(e)}},{key:"fromBER",value:function(e,t,r){var a=e instanceof ArrayBuffer?new Uint8Array(e):e;if(!tt(this,a,t,r))return-1;var n=t+r;return this.valueHexView=a.subarray(t,n),this.valueHexView.length?(this.blockLength=r,n):(this.warnings.push("Zero buffer length"),t)}},{key:"toBER",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.isHexOnly?e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",ot)}},{key:"toJSON",value:function(){return p(p({},A(t,"toJSON",this,3)([])),{},{isHexOnly:this.isHexOnly,valueHex:Ue.ToHex(this.valueHexView)})}}])}(e),t.NAME="hexBlock",t}var vt=o((function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.blockLength,a=void 0===r?0:r,n=t.error,s=void 0===n?ut:n,u=t.warnings,o=void 0===u?[]:u,l=t.valueBeforeDecode,c=void 0===l?lt:l;i(this,e),this.blockLength=a,this.error=s,this.warnings=o,this.valueBeforeDecodeView=Ie.toUint8Array(c)}),[{key:"valueBeforeDecode",get:function(){return this.valueBeforeDecodeView.slice().buffer},set:function(e){this.valueBeforeDecodeView=new Uint8Array(e)}},{key:"toJSON",value:function(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:Ue.ToHex(this.valueBeforeDecodeView)}}}],[{key:"blockName",value:function(){return this.NAME}}]);vt.NAME="baseBlock";var dt=function(e){function t(){return i(this,t),n(this,t,arguments)}return m(t,e),o(t,[{key:"fromBER",value:function(e,t,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}},{key:"toBER",value:function(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}])}(vt);dt.NAME="valueBlock";var gt=function(e){function t(){var e,r,a,s,u,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},l=o.idBlock,c=void 0===l?{}:l;return i(this,t),e=n(this,t),c?(e.isHexOnly=null!==(r=c.isHexOnly)&&void 0!==r&&r,e.valueHexView=c.valueHex?Ie.toUint8Array(c.valueHex):lt,e.tagClass=null!==(a=c.tagClass)&&void 0!==a?a:-1,e.tagNumber=null!==(s=c.tagNumber)&&void 0!==s