UNPKG

59.8 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.Virgil={})}(this,function(t){"use strict";var e="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},u=[],f=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,h=!1;function p(){h=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,r=t.length;e<r;++e)u[e]=t[e],f[t.charCodeAt(e)]=e;f["-".charCodeAt(0)]=62,f["_".charCodeAt(0)]=63}function l(t,e,r){for(var n,i,o=[],s=e;s<r;s+=3)n=(t[s]<<16)+(t[s+1]<<8)+t[s+2],o.push(u[(i=n)>>18&63]+u[i>>12&63]+u[i>>6&63]+u[63&i]);return o.join("")}function n(t){var e;h||p();for(var r=t.length,n=r%3,i="",o=[],s=0,a=r-n;s<a;s+=16383)o.push(l(t,s,a<s+16383?a:s+16383));return 1===n?(e=t[r-1],i+=u[e>>2],i+=u[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=u[e>>10],i+=u[e>>4&63],i+=u[e<<2&63],i+="="),o.push(i),o.join("")}function r(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,f=u>>1,c=-7,h=r?i-1:0,p=r?-1:1,l=t[e+h];for(h+=p,o=l&(1<<-c)-1,l>>=-c,c+=a;0<c;o=256*o+t[e+h],h+=p,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;0<c;s=256*s+t[e+h],h+=p,c-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:1/0*(l?-1:1);s+=Math.pow(2,n),o-=f}return(l?-1:1)*s*Math.pow(2,o-n)}function o(t,e,r,n,i,o){var s,a,u,f=8*o-i-1,c=(1<<f)-1,h=c>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,d=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),2<=(e+=1<=s+h?p/u:p*Math.pow(2,1-h))*u&&(s++,u/=2),c<=s+h?(a=0,s=c):1<=s+h?(a=(e*u-1)*Math.pow(2,i),s+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));8<=i;t[r+l]=255&a,l+=d,a/=256,i-=8);for(s=s<<i|a,f+=i;0<f;t[r+l]=255&s,l+=d,s/=256,f-=8);t[r+l-d]|=128*y}var i={}.toString,s=Array.isArray||function(t){return"[object Array]"==i.call(t)};function a(){return y.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function d(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return y.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=y.prototype:(null===t&&(t=new y(e)),t.length=e),t}function y(t,e,r){if(!(y.TYPED_ARRAY_SUPPORT||this instanceof y))return new y(t,e,r);if("number"!=typeof t)return g(this,t,e,r);if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return w(this,t)}function g(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);y.TYPED_ARRAY_SUPPORT?(t=e).__proto__=y.prototype:t=b(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!y.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|S(e,r),i=(t=d(t,n)).write(e,r);i!==n&&(t=t.slice(0,i));return t}(t,e,r):function(t,e){if(E(e)){var r=0|m(e.length);return 0===(t=d(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?d(t,0):b(t,e);if("Buffer"===e.type&&s(e.data))return b(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function v(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function w(t,e){if(v(e),t=d(t,e<0?0:0|m(e)),!y.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function b(t,e){var r=e.length<0?0:0|m(e.length);t=d(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function m(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function E(t){return!(null==t||!t._isBuffer)}function S(t,e){if(E(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(t).length;default:if(n)return V(t).length;e=(""+e).toLowerCase(),n=!0}}function T(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function A(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):2147483647<r?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=y.from(e,n)),E(e))return 0===e.length?-1:_(t,e,r,n,i);if("number"==typeof e)return e&=255,y.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):_(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function _(t,e,r,n,i){var o,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a/=s=2,u/=2,r/=2}function f(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var c=-1;for(o=r;o<a;o++)if(f(t,o)===f(e,-1===c?0:o-c)){if(-1===c&&(c=o),o-c+1===u)return c*s}else-1!==c&&(o-=o-c),c=-1}else for(a<r+u&&(r=a-u),o=r;0<=o;o--){for(var h=!0,p=0;p<u;p++)if(f(t,o+p)!==f(e,p)){h=!1;break}if(h)return o}return-1}function P(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?i<(n=Number(n))&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");o/2<n&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}function R(t,e,r,n){return H(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function x(t,e,r){return 0===e&&r===t.length?n(t):n(t.slice(e,r))}function I(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,a,u,f=t[i],c=null,h=239<f?4:223<f?3:191<f?2:1;if(i+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(o=t[i+1]))&&127<(u=(31&f)<<6|63&o)&&(c=u);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&2047<(u=(15&f)<<12|(63&o)<<6|63&s)&&(u<55296||57343<u)&&(c=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&65535<(u=(15&f)<<18|(63&o)<<12|(63&s)<<6|63&a)&&u<1114112&&(c=u)}null===c?(c=65533,h=1):65535<c&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(t){var e=t.length;if(e<=C)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=C));return r}(n)}y.TYPED_ARRAY_SUPPORT=void 0===e.TYPED_ARRAY_SUPPORT||e.TYPED_ARRAY_SUPPORT,y.poolSize=8192,y._augment=function(t){return t.__proto__=y.prototype,t},y.from=function(t,e,r){return g(null,t,e,r)},y.TYPED_ARRAY_SUPPORT&&(y.prototype.__proto__=Uint8Array.prototype,y.__proto__=Uint8Array),y.alloc=function(t,e,r){return n=null,o=e,s=r,v(i=t),i<=0?d(n,i):void 0!==o?"string"==typeof s?d(n,i).fill(o,s):d(n,i).fill(o):d(n,i);var n,i,o,s},y.allocUnsafe=function(t){return w(null,t)},y.allocUnsafeSlow=function(t){return w(null,t)},y.isBuffer=function(t){return null!=t&&(!!t._isBuffer||G(t)||(e=t,"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&G(e.slice(0,0))));var e},y.compare=function(t,e){if(!E(t)||!E(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},y.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},y.concat=function(t,e){if(!s(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return y.alloc(0);var r;if(void 0===e)for(r=e=0;r<t.length;++r)e+=t[r].length;var n=y.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(!E(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},y.byteLength=S,y.prototype._isBuffer=!0,y.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)T(this,e,e+1);return this},y.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)T(this,e,e+3),T(this,e+1,e+2);return this},y.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)T(this,e,e+7),T(this,e+1,e+6),T(this,e+2,e+5),T(this,e+3,e+4);return this},y.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?I(this,0,t):function(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return B(this,e,r);case"utf8":case"utf-8":return I(this,e,r);case"ascii":return O(this,e,r);case"latin1":case"binary":return k(this,e,r);case"base64":return x(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},y.prototype.equals=function(t){if(!E(t))throw new TypeError("Argument must be a Buffer");return this===t||0===y.compare(this,t)},y.prototype.inspect=function(){var t="";return 0<this.length&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),50<this.length&&(t+=" ... ")),"<Buffer "+t+">"},y.prototype.compare=function(t,e,r,n,i){if(!E(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(i<=n&&r<=e)return 0;if(i<=n)return-1;if(r<=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(o,s),u=this.slice(n,i),f=t.slice(e,r),c=0;c<a;++c)if(u[c]!==f[c]){o=u[c],s=f[c];break}return o<s?-1:s<o?1:0},y.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},y.prototype.indexOf=function(t,e,r){return A(this,t,e,r,!0)},y.prototype.lastIndexOf=function(t,e,r){return A(this,t,e,r,!1)},y.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||i<r)&&(r=i),0<t.length&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o,s,a,u,f,c,h,p,l,d=!1;;)switch(n){case"hex":return P(this,t,e,r);case"utf8":case"utf-8":return p=e,l=r,H(V(t,(h=this).length-p),h,p,l);case"ascii":return R(this,t,e,r);case"latin1":case"binary":return R(this,t,e,r);case"base64":return u=this,f=e,c=r,H(q(t),u,f,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s=e,a=r,H(function(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,(o=this).length-s),o,s,a);default:if(d)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),d=!0}},y.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var C=4096;function O(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function k(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function B(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||n<r)&&(r=n);for(var i="",o=e;o<r;++o)i+=F(t[o]);return i}function U(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function D(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(r<t+e)throw new RangeError("Trying to access beyond buffer length")}function j(t,e,r,n,i,o){if(!E(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(i<e||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function K(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function N(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function J(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(t,e,r,n,i){return i||J(t,0,r,4),o(t,e,r,n,23,4),r+4}function Y(t,e,r,n,i){return i||J(t,0,r,8),o(t,e,r,n,52,8),r+8}y.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):n<t&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):n<e&&(e=n),e<t&&(e=t),y.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=y.prototype;else{var i=e-t;r=new y(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},y.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||D(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},y.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||D(t,e,this.length);for(var n=this[t+--e],i=1;0<e&&(i*=256);)n+=this[t+--e]*i;return n},y.prototype.readUInt8=function(t,e){return e||D(t,1,this.length),this[t]},y.prototype.readUInt16LE=function(t,e){return e||D(t,2,this.length),this[t]|this[t+1]<<8},y.prototype.readUInt16BE=function(t,e){return e||D(t,2,this.length),this[t]<<8|this[t+1]},y.prototype.readUInt32LE=function(t,e){return e||D(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},y.prototype.readUInt32BE=function(t,e){return e||D(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},y.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||D(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return(i*=128)<=n&&(n-=Math.pow(2,8*e)),n},y.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||D(t,e,this.length);for(var n=e,i=1,o=this[t+--n];0<n&&(i*=256);)o+=this[t+--n]*i;return(i*=128)<=o&&(o-=Math.pow(2,8*e)),o},y.prototype.readInt8=function(t,e){return e||D(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},y.prototype.readInt16LE=function(t,e){e||D(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt16BE=function(t,e){e||D(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},y.prototype.readInt32LE=function(t,e){return e||D(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},y.prototype.readInt32BE=function(t,e){return e||D(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},y.prototype.readFloatLE=function(t,e){return e||D(t,4,this.length),r(this,t,!0,23,4)},y.prototype.readFloatBE=function(t,e){return e||D(t,4,this.length),r(this,t,!1,23,4)},y.prototype.readDoubleLE=function(t,e){return e||D(t,8,this.length),r(this,t,!0,52,8)},y.prototype.readDoubleBE=function(t,e){return e||D(t,8,this.length),r(this,t,!1,52,8)},y.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||j(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},y.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||j(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;0<=--i&&(o*=256);)this[e+i]=t/o&255;return e+r},y.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,1,255,0),y.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},y.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):K(this,t,e,!0),e+2},y.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,2,65535,0),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):K(this,t,e,!1),e+2},y.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},y.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,4,4294967295,0),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},y.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);j(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===a&&0!==this[e+o-1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},y.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);j(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;0<=--o&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+r},y.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,1,127,-128),y.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},y.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):K(this,t,e,!0),e+2},y.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,2,32767,-32768),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):K(this,t,e,!1),e+2},y.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,4,2147483647,-2147483648),y.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},y.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||j(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),y.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},y.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},y.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},y.prototype.writeDoubleLE=function(t,e,r){return Y(this,t,e,!0,r)},y.prototype.writeDoubleBE=function(t,e,r){return Y(this,t,e,!1,r)},y.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),0<n&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;0<=i;--i)t[i+e]=this[i+r];else if(o<1e3||!y.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},y.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!y.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=E(t)?t:V(new y(t,n).toString()),a=s.length;for(o=0;o<r-e;++o)this[o+e]=s[o%a]}return this};var M=/[^+\/0-9A-Za-z-_]/g;function F(t){return t<16?"0"+t.toString(16):t.toString(16)}function V(t,e){var r;e=e||1/0;for(var n=t.length,i=null,o=[],s=0;s<n;++s){if(55295<(r=t.charCodeAt(s))&&r<57344){if(!i){if(56319<r){-1<(e-=3)&&o.push(239,191,189);continue}if(s+1===n){-1<(e-=3)&&o.push(239,191,189);continue}i=r;continue}if(r<56320){-1<(e-=3)&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&-1<(e-=3)&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function q(t){return function(t){var e,r,n,i,o,s;h||p();var a=t.length;if(0<a%4)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[a-2]?2:"="===t[a-1]?1:0,s=new c(3*a/4-o),n=0<o?a-4:a;var u=0;for(r=e=0;e<n;e+=4,r+=3)i=f[t.charCodeAt(e)]<<18|f[t.charCodeAt(e+1)]<<12|f[t.charCodeAt(e+2)]<<6|f[t.charCodeAt(e+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=f[t.charCodeAt(e)]<<2|f[t.charCodeAt(e+1)]>>4,s[u++]=255&i):1===o&&(i=f[t.charCodeAt(e)]<<10|f[t.charCodeAt(e+1)]<<4|f[t.charCodeAt(e+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}(function(t){var e;if((t=(e=t,e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")).replace(M,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function H(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function G(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var z="base64";function W(t,e){return e?y.from(t,z).toString(e):y.from(t,z)}function X(t,e){return(y.isBuffer(t)?t:e&&y.isEncoding(e)?y.from(t,e):y.from(t)).toString(z)}function Z(t){return t=(t=t.split("=")[0]).replace(/\+/g,"-").replace(/\//g,"_")}function Q(t){switch((t=t.replace(/-/g,"+").replace(/_/g,"/")).length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("Invalid base64 string")}return t}function $(t,e){return Z(X(t,e))}function tt(t,e){return t=Q(t),e?W(t,e):W(t)}function et(t){var e;return e="number"==typeof t?t:t.getTime(),Math.floor(e/1e3)}var rt="identity-",nt="virgil-",it="virgil-jwt;v=1",ot=function(){function o(t,e,r){this.header=t,this.body=e,this.signature=r;var n=this.headerBase64()+"."+this.bodyBase64();this.unsignedData=n,null==this.signature?this.stringRepresentation=n:this.stringRepresentation=n+"."+this.signatureBase64()}return o.fromString=function(t){var e=t.split(".");if(3!==e.length)throw new Error("Wrong JWT format");try{var r=tt(e[0],"utf8"),n=tt(e[1],"utf8"),i=Q(e[2]);return new o(JSON.parse(r),JSON.parse(n),i)}catch(t){throw new Error("Wrong JWT format")}},o.prototype.toString=function(){return this.stringRepresentation},o.prototype.identity=function(){if(0!==this.body.sub.indexOf(rt))throw new Error("wrong sub format");return this.body.sub.substr(rt.length)},o.prototype.appId=function(){if(0!==this.body.iss.indexOf(nt))throw new Error("wrong iss format");return this.body.iss.substr(nt.length)},o.prototype.isExpired=function(t){void 0===t&&(t=new Date);var e=et(t);return this.body.exp<e},o.prototype.headerBase64=function(){return $(JSON.stringify(this.header))},o.prototype.bodyBase64=function(){return $(JSON.stringify(this.body))},o.prototype.signatureBase64=function(){return Z(this.signature)},o}();function st(t,e){if(!t)throw new Error(e)}var at=function(){function t(t){var e,r;r=function(t){return"Invalid JwtGenerator options. `"+t+"` is required"},st(null!=(e=t),"JwtGenerator options must be provided"),st(null!=e.apiKey,r("apiKey")),st(null!=e.apiKeyId,r("apiKeyId")),st(null!=e.appId,r("appId")),st(null!=e.accessTokenSigner,r("accessTokenSigner")),this.appId=t.appId,this.apiKey=t.apiKey,this.apiKeyId=t.apiKeyId,this.accessTokenSigner=t.accessTokenSigner,this.millisecondsToLive=void 0!==t.millisecondsToLive?Number(t.millisecondsToLive):12e5}return t.prototype.generateToken=function(t,e){var r=et(new Date),n=et((new Date).getTime()+this.millisecondsToLive),i={iss:nt+this.appId,sub:rt+t,iat:r,exp:n,ada:e},o={alg:this.accessTokenSigner.getAlgorithm(),kid:this.apiKeyId,typ:"JWT",cty:it},s=new ot(o,i),a=this.accessTokenSigner.generateTokenSignature(s.unsignedData,this.apiKey);return new ot(o,i,a.toString("base64"))},t}();var ut=function(){function t(t){var e,r;r=function(t){return"Invalid JwtVerifier options. `"+t+"` is required"},st(null!=(e=t),"JwtVerifier options must be provided"),st(null!=e.apiPublicKey,r("apiPublicKey")),st(null!=e.apiKeyId,r("apiKeyId")),st(null!=e.accessTokenSigner,r("accessTokenSigner")),this.accessTokenSigner=t.accessTokenSigner,this.apiPublicKey=t.apiPublicKey,this.apiKeyId=t.apiKeyId}return t.prototype.verifyToken=function(t){if(null==t)throw new Error("Token is empty");return!!this.allFieldsAreCorrect(t)&&this.accessTokenSigner.verifyTokenSignature(t.unsignedData,t.signature,this.apiPublicKey)},t.prototype.allFieldsAreCorrect=function(t){return t.header.kid==this.apiKeyId&&t.header.alg==this.accessTokenSigner.getAlgorithm()&&t.header.cty==it&&"JWT"==t.header.typ},t}();var ft=function(){function t(n,t){var i=this;if("function"!=typeof n)throw new TypeError("`renewJwtFn` must be a function");if(t){var e=void 0;if("string"==typeof t)e=ot.fromString(t);else{if(!(t instanceof ot))throw new Error('Expected "initialToken" to be a string or an instance of Jwt, got '+typeof t);e=t}this.cachedJwt=e}this.getJwt=function(t){return i.cachedJwt&&!i.cachedJwt.isExpired((e=new Date,r=5,"number"==typeof e?new Date(e+1e3*r):new Date(e.getTime()+1e3*r)))?Promise.resolve(i.cachedJwt):(i.jwtPromise||(i.jwtPromise=Promise.resolve(n(t)).then(function(t){var e="string"==typeof t?ot.fromString(t):t;return i.cachedJwt=e,i.jwtPromise=void 0,e}).catch(function(t){throw i.jwtPromise=void 0,t})),i.jwtPromise);var e,r}}return t.prototype.getToken=function(t){return this.getJwt(t)},t}(),ct=function(){function t(e){if("function"!=typeof e)throw new TypeError("`getJwtFn` must be a function");this.getJwt=function(t){return Promise.resolve(e(t)).then(function(t){return"string"==typeof t?ot.fromString(t):t})}}return t.prototype.getToken=function(t){return this.getJwt(t)},t}(),ht=function(){function t(t){if(null==(this.accessToken=t))throw new TypeError("`accessToken` is required")}return t.prototype.getToken=function(t){return Promise.resolve(this.accessToken)},t}(),pt=function(){function t(t,e,r){if(this.jwtGenerator=t,this.additionalData=e,this.defaultIdentity=r,null==t)throw new TypeError("`jwtGenerator` is required")}return t.prototype.getToken=function(t){var e=this;return Promise.resolve().then(function(){return e.jwtGenerator.generateToken(t.identity||e.defaultIdentity||"",e.additionalData)})},t}(),lt=function(t,e){return(lt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function dt(t,e){function r(){this.constructor=t}lt(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var yt=function(){return(yt=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function gt(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}function vt(o,s,a,u){return new(a||(a=Promise))(function(t,e){function r(t){try{i(u.next(t))}catch(t){e(t)}}function n(t){try{i(u.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(r,n)}i((u=u.apply(o,s||[])).next())})}function wt(r,n){var i,o,s,t,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,o=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(r,a)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var bt=function(){function n(t,e){this.contentSnapshot=t,this.signatures=e}return n.fromString=function(t){var e,r=W(t,"utf8");try{e=JSON.parse(r)}catch(t){throw new Error("The string to be parsed is in invalid format")}return n.fromJson(e)},n.fromJson=function(t){return new n(W(t.content_snapshot,"utf8"),(t.signatures||[]).map(function(t){var e=t.signer,r=t.signature,n=t.snapshot;return n?{signer:e,signature:r,snapshot:W(n,"utf8")}:{signer:e,signature:r}}))},n.prototype.toJSON=function(){return this.toJson()},n.prototype.toJson=function(){return{content_snapshot:X(this.contentSnapshot,"utf8"),signatures:this.signatures.map(function(t){var e=t.signer,r=t.signature,n=t.snapshot;return n?{signer:e,signature:r,snapshot:X(n,"utf8")}:{signer:e,signature:r}})}},n.prototype.toString=function(){return X(JSON.stringify(this),"utf8")},n.prototype.exportAsJson=function(){return this.toJson()},n.prototype.exportAsString=function(){return this.toString()},n}(),mt="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var Et,St,Tt,At=(function(t,e){var r;r="undefined"!=typeof self?self:mt,t.exports=function(t){var T=t&&t.Promise||r.Promise,A=t&&t.XMLHttpRequest||r.XMLHttpRequest,e=r;return function(){var t=Object.create(e,{fetch:{value:void 0,writable:!0}});return function(t){if(!t.fetch){var e="URLSearchParams"in t,r="Symbol"in t&&"iterator"in Symbol,s="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),n="FormData"in t,i="ArrayBuffer"in t;if(i)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=function(t){return t&&DataView.prototype.isPrototypeOf(t)},u=ArrayBuffer.isView||function(t){return t&&-1<o.indexOf(Object.prototype.toString.call(t))};d.prototype.append=function(t,e){t=h(t),e=p(e);var r=this.map[t];this.map[t]=r?r+","+e:e},d.prototype.delete=function(t){delete this.map[h(t)]},d.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},d.prototype.set=function(t,e){this.map[h(t)]=p(e)},d.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},d.prototype.keys=function(){var r=[];return this.forEach(function(t,e){r.push(e)}),l(r)},d.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),l(e)},d.prototype.entries=function(){var r=[];return this.forEach(function(t,e){r.push([e,t])}),l(r)},r&&(d.prototype[Symbol.iterator]=d.prototype.entries);var f=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];m.prototype.clone=function(){return new m(this,{body:this._bodyInit})},b.call(m.prototype),b.call(S.prototype),S.prototype.clone=function(){return new S(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},S.error=function(){var t=new S(null,{status:0,statusText:""});return t.type="error",t};var c=[301,302,303,307,308];S.redirect=function(t,e){if(-1===c.indexOf(e))throw new RangeError("Invalid status code");return new S(null,{status:e,headers:{location:t}})},t.Headers=d,t.Request=m,t.Response=S,t.fetch=function(r,i){return new T(function(n,t){var e=new m(r,i),o=new A;o.onload=function(){var t,i,e={status:o.status,statusText:o.statusText,headers:(t=o.getAllResponseHeaders()||"",i=new d,t.split(/\r?\n/).forEach(function(t){var e=t.split(":"),r=e.shift().trim();if(r){var n=e.join(":").trim();i.append(r,n)}}),i)};e.url="responseURL"in o?o.responseURL:e.headers.get("X-Request-URL");var r="response"in o?o.response:o.responseText;n(new S(r,e))},o.onerror=function(){t(new TypeError("Network request failed"))},o.ontimeout=function(){t(new TypeError("Network request failed"))},o.open(e.method,e.url,!0),"include"===e.credentials&&(o.withCredentials=!0),"responseType"in o&&s&&(o.responseType="blob"),e.headers.forEach(function(t,e){o.setRequestHeader(e,t)}),o.send(void 0===e._bodyInit?null:e._bodyInit)})},t.fetch.polyfill=!0}function h(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function p(t){return"string"!=typeof t&&(t=String(t)),t}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r&&(t[Symbol.iterator]=function(){return t}),t}function d(e){this.map={},e instanceof d?e.forEach(function(t,e){this.append(e,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function y(t){if(t.bodyUsed)return T.reject(new TypeError("Already read"));t.bodyUsed=!0}function g(r){return new T(function(t,e){r.onload=function(){t(r.result)},r.onerror=function(){e(r.error)}})}function v(t){var e=new FileReader,r=g(e);return e.readAsArrayBuffer(t),r}function w(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function b(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t)if("string"==typeof t)this._bodyText=t;else if(s&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(n&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(e&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(i&&s&&a(t))this._bodyArrayBuffer=w(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!i||!ArrayBuffer.prototype.isPrototypeOf(t)&&!u(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=w(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s&&(this.blob=function(){var t=y(this);if(t)return t;if(this._bodyBlob)return T.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return T.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return T.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?y(this)||T.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,r,n=y(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=g(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return T.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return T.resolve(this._bodyText)},n&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}function m(t,e){var r,n,i=(e=e||{}).body;if(t instanceof m){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(t.headers)),this.method=t.method,this.mode=t.mode,i||null==t._bodyInit||(i=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new d(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),-1<f.indexOf(n)?n:r),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function E(t){var i=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),r=e.shift().replace(/\+/g," "),n=e.join("=").replace(/\+/g," ");i.append(decodeURIComponent(r),decodeURIComponent(n))}}),i}function S(t,e){e||(e={}),this.type="default",this.status="status"in e?e.status:200,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new d(e.headers),this.url=e.url||"",this._initBody(t)}}(void 0!==t?t:this),{fetch:t.fetch,Headers:t.Headers,Request:t.Request,Response:t.Response}}()}}(Et={exports:{}},Et.exports),Et.exports)(),_t=At.fetch,Pt=(At.Request,At.Response,At.Headers),Rt=function(){function t(t){this.prefix=t}return t.prototype.get=function(t,e){var r=this.createHeaders(e);return this.send(t,"GET",{headers:r})},t.prototype.post=function(t,e,r){void 0===r&&(r={});var n=this.createHeaders(e);return n.set("Content-Type","application/json"),this.send(t,"POST",{headers:n,body:JSON.stringify(r)})},t.prototype.send=function(t,e,r){return _t(this.prefix+t,yt({method:e},r))},t.prototype.createHeaders=function(t){var e=new Pt;return e.set("Authorization","Virgil "+t),e},t}(),xt=function(i){function t(t,e){var r=this.constructor;void 0===e&&(e="VirgilError");var n=i.call(this,t)||this;return Object.setPrototypeOf(n,r.prototype),n.name=e,n}return dt(t,i),t}(Error);(Tt=St||(St={}))[Tt.AccessTokenExpired=20304]="AccessTokenExpired",Tt[Tt.Unknown=0]="Unknown";var It=function(i){function t(t,e,r){var n=i.call(this,t,"VirgilHttpError")||this;return n.httpStatus=e,n.errorCode=r,n}return dt(t,i),t}(xt);function Ct(r){return vt(this,void 0,void 0,function(){var e;return wt(this,function(t){switch(t.label){case 0:return 400<=r.status&&r.status<500?[4,r.json()]:[3,2];case 1:return e=t.sent(),[2,new It(e.message,r.status,e.code)];case 2:return[2,new It(r.statusText,r.status,0)]}})})}var Ot=function(){function t(t){this.connection="string"==typeof t?new Rt(t):t||new Rt("https://api.virgilsecurity.com")}return t.prototype.searchCards=function(n,i){return vt(this,void 0,void 0,function(){var e,r;return wt(this,function(t){switch(t.label){case 0:return[4,this.connection.post("/card/v5/actions/search",i,{identities:n})];case 1:return(e=t.sent()).ok?[3,3]:[4,Ct(e)];case 2:throw t.sent();case 3:return[4,e.json()];case 4:return null===(r=t.sent())?[2,[]]:[2,r.map(bt.fromJson)]}})})},t.prototype.getCard=function(o,s){return vt(this,void 0,void 0,function(){var r,n,i;return wt(this,function(t){switch(t.label){case 0:if(!o)throw new TypeError("`cardId` should not be empty");if(!s)throw new TypeError("`jwtToken` should not be empty");return[4,this.connection.get((e=o,"/card/v5/"+e),s)];case 1:return(r=t.sent()).ok?[3,3]:[4,Ct(r)];case 2:throw t.sent();case 3:return n="true"===r.headers.get("X-Virgil-Is-Superseeded"),[4,r.json()];case 4:return i=t.sent(),[2,{cardRaw:bt.fromJson(i),isOutdated:n}]}var e})})},t.prototype.publishCard=function(n,i){return vt(this,void 0,void 0,function(){var e,r;return wt(this,function(t){switch(t.label){case 0:if(!n)throw new TypeError("`model` should not be empty");if(!i)throw new TypeError("`jwtToken` should not be empty");return[4,this.connection.post("/card/v5",i,n)];case 1:return(e=t.sent()).ok?[3,3]:[4,Ct(e)];case 2:throw t.sent();case 3:return[4,e.json()];case 4:return r=t.sent(),[2,bt.fromJson(r)]}})})},t}(),kt="self",Bt=32,Ut=function(){function t(t){this.crypto=t}return t.prototype.sign=function(t){var e=this.prepareParams(t),r=e.model,n=e.signerPrivateKey,i=e.signer,o=e.extraSnapshot,s=null!=o?r.contentSnapshot+o:r.contentSnapshot,a=this.crypto.generateSignature(s,n);r.signatures.push({signer:i,signature:a.toString("base64"),snapshot:o})},t.prototype.prepareParams=function(t){var e,r=t.model,n=t.signerPrivateKey,i=t.extraFields,o=t.signer;o=o||kt,null!=i&&(e=JSON.stringify(i));var s={model:r,signerPrivateKey:n,signer:o,extraSnapshot:e};return this.validate(s),s},t.prototype.validate=function(t){var e=t.model,r=t.signerPrivateKey,n=t.signer;if(null==e)throw new Error("Model is empty");if(null==r)throw new Error("`signerPrivateKey` property is mandatory");if(null!=e.signatures&&e.signatures.some(function(t){return t.signer==n}))throw new Error("The model already has this signature.")},t}();function Dt(t,e,r){void 0===r&&(r=!1);var n,i,o=JSON.parse(e.contentSnapshot),s=e.signatures.map(jt);return{id:(n=t,i=e.contentSnapshot,n.generateSha512(i).slice(0,Bt).toString("hex")),publicKey:t.importPublicKey(o.public_key),contentSnapshot:e.contentSnapshot,identity:o.identity,version:o.version,createdAt:new Date(1e3*o.created_at),previousCardId:o.previous_card_id,signatures:s,isOutdated:r}}function jt(t){var e=t.snapshot,r=t.signature;return{signer:t.signer,signature:r,snapshot:e,extraFields:function(t){if(t)try{return JSON.parse(t)}catch(t){}return{}}(e)}}var Kt=function(e){function t(t){return e.call(this,t,"CardVerificationError")||this}return dt(t,e),t}(xt),Nt={getToken:function(){throw new Error("Please set `CardManager.accessTokenProvider` to be able to make requests.")}},Jt=function(){function t(t){this.crypto=t.cardCrypto,this.client=new Ot(t.apiUrl),this.modelSigner=new Ut(t.cardCrypto),this.signCallback=t.signCallback,this.retryOnUnauthorized=t.retryOnUnauthorized,this.cardVerifier=t.cardVerifier,this.accessTokenProvider=t.accessTokenProvider||Nt}return t.prototype.generateRawCard=function(t){var e,r,n,i,o,s=(e=this.crypto,n=(r=t).identity,i=r.publicKey,o={identity:n,previous_card_id:r.previousCardId,created_at:et(new Date),version:"5.0",public_key:X(e.exportPublicKey(i))},new bt(JSON.stringify(o),[]));return this.modelSigner.sign({model:s,signerPrivateKey:t.privateKey,signer:kt,extraFields:t.extraFields}),s},t.prototype.publishCard=function(i){return vt(this,void 0,void 0,function(){var e,r,n;return wt(this,function(t){switch(t.label){case 0:return function(t,e){void 0===e&&(e=!1);st(null!=t,"Card parameters must be provided"),st(null!=t.privateKey,"Card's private key is required"),st(null!=t.publicKey,"Card's public key is required"),e&&st("string"==typeof t.identity&&""!==t.identity,"Card's identity is required")}(i),e={identity:i.identity,operation:"publish"},[4,this.accessTokenProvider.getToken(e)];case 1:return r=t.sent(),n=this.generateRawCard(Object.assign({},i,{identity:r.identity()})),[4,this.publishRawSignedModel(n,e,r)];case 2:return[2,t.sent()]}})})},t.prototype.publishRawCard=function(i){return vt(this,void 0,void 0,function(){var e,r,n;return wt(this,function(t){switch(t.label){case 0:return st(null!=i&&null!=i.contentSnapshot,"`rawCard` should not be empty"),e=JSON.parse(i.contentSnapshot),r={identity:e.identity,operation:"publish"},[4,this.accessTokenProvider.getToken(r)];case 1:return n=t.sent(),[2,this.publishRawSignedModel(i,r,n)]}})})},t.prototype.getCard=function(s){return vt(this,void 0,void 0,function(){var e,r,n,i,o=this;return wt(this,function(t){switch(t.label){case 0:return e={operation:"get"},[4,this.accessTokenProvider.getToken(e)];case 1:return r=t.sent(),[4,this.tryDo(e,r,function(e){return vt(o,void 0,void 0,function(){return wt(this,function(t){switch(t.label){case 0:return[4,this.client.getCard(s,e.toString())];case 1:return[2,t.sent()]}})})})];case 2:if(n=t.sent(),(i=Dt(this.crypto,n.cardRaw,n.isOutdated)).id!==s)throw new Kt("Received invalid card");return this.validateCards([i]),[2,i]}})})},t.prototype.searchCards=function(u){return vt(this,void 0,void 0,function(){var r,e,n,i,o,s,a=this;return wt(this,function(t){switch(t.label){case 0:if(!u)throw new TypeError("Argument `identities` is required");if(0===(r=Array.isArray(u)?u:[u]).length)throw new TypeError("Identities array must not be empty");return e={operation:"search"},[4,this.accessTokenProvider.getToken(e)];case 1:return n=t.sent(),[4,this.tryDo(e,n,function(e){return vt(a,void 0,void 0,function(){return wt(this,function(t){switch(t.label){case 0:return[4,this.client.searchCards(r,e.toString())];case 1:return[2,t.sent()]}})})})];case 2:if(i=t.sent(),o=i.map(function(t){return Dt(a.crypto,t,!1)}),s=new Set(r),o.some(function(t){return!s.has(t.identity)}))throw new Kt("Received invalid cards");return this.validateCards(o),[2,function(t){for(var e=Object.create(null),r=0,n=t;r<n.length;r++){var i=n[r];e[i.id]=i}for(var o=0,s=t;o<s.length;o++)null!=(i=s[o]).previousCardId&&null!=e[i.previousCardId]&&(e[i.previousCardId].isOutdated=!0,i.previousCard=e[i.previousCardId],delete e[i.previousCardId]);return Object.keys(e).map(function(t){return e[t]})}(o)]}})})},t.prototype.importCard=function(t){var e=Dt(this.crypto,t);return this.validateCards([e]),e},t.prototype.importCardFromString=function(t){return st(Boolean(t),"`str` should not be empty"),this.importCard(bt.fromString(t))},t.prototype.importCardFromJson=function(t){return st(Boolean(t),"`json` should not be empty"),this.importCard(bt.fromJson(t))},t.prototype.exportCard=function(t){return new bt((e=t).contentSnapshot,e.signatures.slice());var e},t.prototype.exportCardAsString=function(t){return this.exportCard(t).toString()},t.prototype.exportCardAsJson=function(t){return this.exportCard(t).toJson()},t.prototype.publishRawSignedModel=function(i,o,s){return vt(this,void 0,void 0,function(){var e,r,n=this;return wt(this,function(t){switch(t.label){case 0:return null==this.signCallback?[3,2]:[4,this.signCallback(i)];case 1:i=t.sent(),t.label=2;case 2:return[4,this.tryDo(o,s,function(e){return vt(n,void 0,void 0,function(){return wt(this,function(t){switch(t.label){case 0:return[4,this.client.publishCard(i,e.toString())];case 1:return[2,t.sent()]}})})})];case 3:if(e=t.sent(),i.contentSnapshot!==e.contentSnapshot)throw new Kt("Received invalid card");return r=Dt(this.crypto,e),this.validateCards([r]),[2,r]}})})},t.prototype.tryDo=function(r,n,i){return vt(this,void 0,void 0,function(){var e;return wt(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,6]),[4,i(n)];case 1:return[2,t.sent()];case 2:return(e=t.sent())instanceof It&&401===e.httpStatus&&e.errorCode===St.AccessTokenExpired&&this.retryOnUnauthorized?[4,this.accessTokenProvider.getToken({identity:r.identity,operation:r.operation,forceReload:!0})]:[3,5];case 3:return n=t.sent(),[4,i(n)];case 4:return[2,t.sent()];case 5:throw e;case 6:return[2]}})})},t.prototype.validateCards=function(t){if(null!=this.cardVerifier)for(var e=0,r=t;e<r.length;e++){var n=r[e];if(!this.cardVerifier.verifyCard(n))throw new Kt("Validation errors have been detected")}},t}();var Lt={verifySelfSignature:!0,verifyVirgilSignature:!0,whitelists:[]},Yt=function(){function t(t,e){this.crypto=t;var r=yt({},Lt,e||{});this.verifySelfSignature=r.verifySelfSignature,this.verifyVirgilSignature=r.verifyVirgilSignature,this.whitelists=r.whitelists,this.virgilCardsPublicKey=t.importPublicKey("MCowBQYDK2VwAyEAljOYGANYiVq1WbvVvoYIKtvZi2ji9bAhxyu6iV/LF8M=")}return t.prototype.verifyCard=function(e){var r=this;if(this.selfValidationFailed(e))return!1;if(this.virgilValidationFailed(e))return!1;if(!this.whitelists||0===this.whitelists.length)return!0;for(var n=e.signatures.map(function(t){return t.signer}),t=0,i=this.whitelists;t<i.length;t++){var o=i[t];if(null==o||0===o.length)return!1;var s=o.filter(function(t){return-1!==n.indexOf(t.signer)});if(0===s.length)return!1;if(!s.some(function(t){return r.validateSignerSignature(e,r.getPublicKey(t.publicKeyBase64),t.signer)}))return!1}return!0},t.prototype.selfValidationFailed=function(t){return this.verifySelfSignature&&!this.validateSignerSignature(t,t.publicKey,kt)},t.prototype.virgilValidationFailed=function(t){return this.verifyVirgilSignature&&!this.validateSignerSignature(t,this.virgilCardsPublicKey,"virgil")},t.prototype.getPublicKey=function(t){return this.crypto.importPublicKey(t)},t.prototype.validateSignerSignature=function(t,e,r){var n=t.signatures.find(function(t){return t.signer===r});if(null==n)return!1;var i=null==n.snapshot?t.contentSnapshot:t.contentSnapshot+n.snapshot;return this.crypto.verifySignature(i,n.signature,e)},t}();var Mt=function(e){function t(t){return e.call(this,"Storage entry "+(t?"with key "+name:"with the given key")+"already exists","StorageEntryAlreadyExistsError")||this}return dt(t,e),t}(xt),Ft="readonly",Vt="readwrite",qt={},Ht=function(){function t(t){var n=this;if(this._initStorage=function(){var e={db:null,name:n._defaultConfig.name,storeName:n._defaultConfig.storeName,version:n._defaultConfig.version},r=qt[e.name];return r||(r={db:null,dbReady:null,deferredOperations:[]},qt[e.name]=r),Promise.resolve().then(function(){return e.db=r.db,Wt(e)}).then(function(t){return e.db=t,Zt(e,n._defaultConfig.version)?Xt(e):t}).then(function(t){e.db=r.db=t,n._dbInfo=e})},this.ready=function(){return n._ready.then(function(){var t=qt[n._dbInfo.name];if(t&&t.dbReady)return t.dbReady})},!function(){try{return"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(t){return!1}}())throw new Error("Cannot use IndexedDbStorageAdapter. indexedDb is not supported");this._defaultConfig={name:t.name,version:1,storeName:"keyvaluepairs"},this._ready=this._initStorage()}return t.prototype.store=function(o,s){var a=this;return o=te(o),new Promise(function(n,i){a.ready().then(function(){$t(a._dbInfo,Vt,function(t,e){if(t)return i(t);try{var r=e.objectStore(a._dbInfo.storeName).add(ee(s),o);e.oncomplete=function(){n()},e.onabort=e.onerror=function(){var t=r.error?r.error:r.transaction.error;t&&"ConstraintError"===t.name&&i(new Mt(o)),i(t)}}catch(t){i(t)}})}).catch(i)})},t.prototype.load=function(o){var s=this;return o=te(o),new Promise(function(n,i){s.ready().then(function(){$t(s._dbInfo,Ft,function(t,e){if(t)return i(t);try{var r=e.objectStore(s._dbInfo.storeName).get(o);r.onsuccess=function(){if(null==r.result)return n(null);var t=r.result,e=y.from(t);n(e)},r.onerror=function(){i(r.error)}}catch(t){i(t)}})}).catch(i)})},t.prototype.exists=function(o){var s=this;return o=te(o),new Promise(function(n,i){s.ready().then(function(){$t(s._dbInfo,Ft,function(t,e){if(t)return i(t);try{var r=e.objectStore(s._dbInfo.storeName).openCursor(o);r.onsuccess=function(){var t=r.result;n(null!==t)},r.onerror=function(){i(r.error)}}catch(t){i(t)}})}).catch(i)})},t.prototype.remove=function(a){var u=this;return a=te(a),new Promise(function(o,s){u.ready().then(function(){$t(u._dbInfo,Vt,function(t,e){if(t)return s(t);try{var r,n=e.objectStore(u._dbInfo.storeName),i=n.count(a);i.onsuccess=function(){if(0===i.result)return o(!1);(r=n.delete(a)).onsuccess=function(){return o(!0)}},e.onabort=e.onerror=function(){var t=r||i,e=t.error?t.error:t.transaction.error;s(e)}}catch(t){s(t)}})}).catch(s)})},t.prototype.update=function(o,s){var a=this;return o=te(o),new Promise(function(n,i){a.ready().then(function(){$t(a._dbInfo,Vt,function(t,e){if(t)return i(t);try{var r=e.objectStore(a._dbInfo.storeName).put(ee(s),o);r.onsuccess=function(){n()},r.onerror=function(){i(r.error)}}catch(t){i(t)}})}).catch(i)})},t.prototype.clear=function(){var o=this;return new Promise(function(n,i){o.ready().then(function(){$t(o._dbInfo,Vt,function(t,e){if(t)return i(t);try{var r=e.objectStore(o._dbInfo.storeName).clear();e.oncomplete=function(){return n()},e.onabort=e.onerror=function(){var t=r.error?r.error:r.transaction.error;i(t)}}catch(t){i(t)}})}).catch(i)})},t.prototype.list=function(){var s=this;return new Promise(function(i,o){s.ready().then(function(){$t(s._dbInfo,Ft,function(t,e){if(t)return o(t);try{var r=e.objectStore(s._dbInfo.storeName).openCursor(),n=[];r.onsuccess=function(){var t=r.result;t?(n.push(y.from(t.value)),t.continue()):i(n)},r.onerror=function(){o(r.error)}}catch(t){o(t)}})}).catch(o)})},t}();function Gt(t){var e=qt[t.name],r={};r.promise=new Promise(function(t,e){r.resolve=t,r.reject=e}),e.deferredOperations.push(r),e.dbReady?e.dbReady=e.dbReady.then(function(){return r.promise}):e.dbReady=r.promise}function zt(i,o){return new Promise(function(t,e){if(qt[i.name]=qt[i.name]||{db:null,dbReady:null,deferredOperations:[]},i.db){if(!o)return t(i.db);Gt(i),i.db.close()}var r=[i.name];o&&r.push(String(i.version));var n=indexedDB.open.apply(indexedDB,r);o&&(n.onupgradeneeded=function(e){var t=n.result;try{t.createObjectStore(i.storeName)}catch(t){if("ConstraintError"!==t.name)throw t;console.warn('The database "'+i.name+'" has been upgraded from version '+e.oldVersion+" to version "+e.newVersion+', but the storage "'+i.storeName+'" already exists.')}}),n.onerror=function(t){t.preventDefault(),e(n.error)},n.onsuccess=function(){t(n.result),function(t){var e=qt[t.name].deferredOperations.pop();if(e)e.resolve(),e.promise}(i)}})}function Wt(t){return zt(t,!1)}function Xt(t){return zt(t,!0)}function Zt(t,e){if(!t.db)return!0;var r=!t.db.objectStoreNames.contains(t.storeName),n=t.version<t.db.version,i=t.version>t.db.version;if(n&&(t.version!==e&&console.warn('The database "'+t.name+"\" can't be downgraded from version "+t.db.version+" to version "+t.version+"."),t.version=t.db.version),i||r){if(r){var o=t.db.version+1;o>t.version&&(t.version=o)}return!0}return!1}function Qt(e){Gt(e);var r=qt[e.name];return e.db=null,Wt(e).then(function(t){return e.db=t,Zt(e)?Xt(e):t}).then(function(t){e.db=r.db=t}).catch(function(t){throw function(t,e){var r=qt[t.name].deferredOperations.pop();if(r)r.reject(e),r.promise}(e,t),t})}function $t(e,r,n,i){void 0===i&&(i=1);try{var t=e.db.transaction(e.storeName,r);n(null,t)}catch(t){0<i&&(!e.db||"InvalidStateError"===t.name||"NotFoundError"===t.name)&&Promise.resolve().then(function(){if(!e.db||"NotFoundError"===t.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),Xt(e)}).then(function(){return Qt(e).then(function(){$t(e,r,n,i-1)})}).catch(n),n(t)}}function te(t){return"string"!=typeof t&&(console.warn(t+" used as a key, but it is not a string."),t=String(t)),t}function ee(t){if(t instanceof Uint8Array){if(0===t.byteOffset&&t.byteLength===t.buffer.byteLength)return t.buffer;if("function"==typeof t.buffer.slice)return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}if(y.isBuffer(t)){for(var e=new Uint8Array(t.length),r=t.length,n=0;n<r;n++)e[n]=t[n];return e.buffer}throw new Error("Argument must be a Buffer")}var re=function(e){function t(t){return void 0===t&&(t="Private key with same name already exists"),e.call(this,t,"PrivateKeyExistsError")||this}return dt(t,e),t}(xt),ne={dir:".virgil_keys",name:"VirgilKeys"},ie=function(){function t(t){void 0===t&&(t={}),console.log("Warning! `KeyStorage` is deprecated. Use `PrivateKeyStorage` instead."),this.adapter=function(t){if("string"==typeof t)return new Ht({dir:t,name:t});var e=t.adapter,r=gt(t,["adapter"]);return null==e?new Ht(yt({},ne,r)):e}(t)}return t.prototype.exists=function(t){return oe(t),this.adapter.exists(t)},t.prototype.load=function(t){return oe(t),this.adapter.load(t)},t.prototype.remove=function(t){return oe(t),this.adapter.remove(t)},t.prototype.save=function(t,e){return oe(t),function(t){if(!t)throw new TypeError("Argument `data` is required.")}(e),this.adapter.store(t,e).catch(function(t){return t&&"EEXIST"===t.code?Promise.reject(new re):Promise.reject(t)})},t}();function oe(t){if(!t)throw new TypeError("Argument `name` is required.")}var se=function(e){function t(t){return void 0===t&&(t="Loaded key entry was in invalid format."),e.call(this,t,"InvalidKeyEntryError")||this}return dt(t,e),t}(xt),ae=function(e){function t(t){return e.call(this,"Key entry "+(t?"named "+t:"with same name")+"already exists","KeyEntryAlreadyExistsError")||this}return dt(t,e),t}(xt),ue=function(e){function t(t){return e.call(this,"Key entry "+(t?"named "+t:"with the given name")+" does not exist.","KeyEntryDoesNotExistError")||this}return dt(t,e),t}(xt),fe={dir:".virgil_key_entries",name:"VirgilKeyEntries"},ce=function(){function t(t){void 0===t&&(t={}),this.adapter=function(t){if("string"==typeof t)return new Ht({dir:t,name:t});var e=t.adapter,r=gt(t,["adapter"]);return null==e?new Ht(yt({},fe,r)):e}(t)}return t.prototype.exists=function(t){return ye(t),this.adapter.exists(t)},t.prototype.load=function(t){return ye(t),this.adapter.load(t).then(function(t){return null==t?null:pe(t)})},t.prototype.remove=function(t){return ye(t),this.adapter.remove(t)},t.prototype.save=function(t){var e=t.name,r=t.value,n=t.meta;ge(e),ve(r);var i={name:e,value:r,meta:n,creationDate:new Date,modificationDate:new Date};return this.adapter.store(e,he(i)).then(function(){return i}).catch(function(t){if(t&&"StorageEntryAlreadyExistsError"===t.name)throw new ae(e);throw t})},t.prototype.list=function(){return this.adapter.list().then(function(t){return t.map(function(t){return pe(t)})})},t.prototype.update=function(t){var n=this,i=t.name,o=t.value,s=t.meta;if(ge(i),!o&&!s)throw new TypeError("Invalid argument. Either `value` or `meta` property is required.");return this.adapter.load(i).then(function(t){if(null===t)throw new ue(i);var e=pe(t),r=Object.assign(e,{value:o||e.value,meta:s||e.meta,modificationDate:new Date});return n.adapter.update(i,he(r)).then(function(){return r})})},t.prototype.clear=function(){return this.adapter.clear()},t}();function he(t){var e=t.value,r=gt(t,["value"]),n=yt({},r,{value:e.toString("base64")});return y.from(JSON.stringify(n),"utf8")}function pe(t){var e=t.toString("utf8");try{return JSON.parse(e,function(t,e){return"value"===t?y.from(e,"base64"):"creationDate"===t||"modificationDate"===t?new Date(e):e})}catch(t){throw new se}}var le,de=function(e){return function(t){if(!t)throw new TypeError("Invalid argument. Property "+e+" is required")}},ye=(le="name",function(t){if(!t)throw new TypeError("Argument '"+le+"' is required.")}),ge=de("name"),ve=de("value"),we=function(){function t(t,e){void 0===e&&(e=new ce),this.privateKeyExporter=t,this.keyEntryStorage=e}return t.prototype.store=function(n,i,o){return vt(this,void 0,void 0,function(){var e,r;return wt(this,function(t){switch(t.label){case 0:e=this.privateKeyExporter.exportPrivateKey(i),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.keyEntryStorage.save({name:n,value:e,meta:o})];case 2:return t.sent(),[3,4];case 3:if((r=t.sent())&&"KeyEntryAlreadyExistsError"===r.name)throw new re("Private key with the name "+n+" already exists.");throw r;case 4:return[2]}})})},t.prototype.load=function(r){return vt(this,void 0,void 0,function(){var e;return wt(this,function(t){switch(t.label){case 0:return[4,this.keyEntryStorage.load(r)];case 1:return null===(e=t.sent())?[2,null]:[2,{privateKey:this.privateKeyExporter.importPrivateKey(e.value),meta:e.meta}]}})})},t.prototype.delete=function(e){return vt(this,void 0,void 0,function(){return wt(this,function(t){switch(t.label){case 0:return[4,this.keyEntryStorage.remove(e)];case 1:return t.sent(),[2]}})})},t}();t.JwtGenerator=at,t.JwtVerifier=ut,t.Jwt=ot,t.CachingJwtProvider=ft,t.CallbackJwtProvider=ct,t.ConstAccessTokenProvider=ht,t.GeneratorJwtProvider=pt,t.CardManager=Jt,t.VirgilCardVerifier=Yt,t.RawSignedModel=bt,t.ModelSigner=Ut,t.DefaultStorageAdapter=Ht,t.StorageEntryAlreadyExistsError=Mt,t.KeyStorage=ie,t.KeyEntryStorage=ce,t.InvalidKeyEntryError=se,t.KeyEntryAlreadyExistsError=ae,t.KeyEntryDoesNotExistError=ue,t.PrivateKeyStorage=we,Object.defineProperty(t,"__esModule",{value:!0})});