@eid-easy/signature-js
Version:
Official eID Easy browser-side JavaScript library. You can use signature-js to handle eID Easy signing flows in your web application.
2 lines • 34.5 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.eideasySignature=t():e.eideasySignature=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e,t){return function(){return e.apply(t,arguments)}}e.r(t),e.d(t,{default:()=>Ie});const{toString:o}=Object.prototype,{getPrototypeOf:r}=Object,i=(s=Object.create(null),e=>{const t=o.call(e);return s[t]||(s[t]=t.slice(8,-1).toLowerCase())});var s;const a=e=>(e=e.toLowerCase(),t=>i(t)===e),c=e=>t=>typeof t===e,{isArray:l}=Array,u=c("undefined"),d=a("ArrayBuffer"),f=c("string"),h=c("function"),p=c("number"),g=e=>null!==e&&"object"==typeof e,m=e=>{if("object"!==i(e))return!1;const t=r(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},y=a("Date"),w=a("File"),b=a("Blob"),E=a("FileList"),S=a("URLSearchParams");function O(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let o,r;if("object"!=typeof e&&(e=[e]),l(e))for(o=0,r=e.length;o<r;o++)t.call(null,e[o],o,e);else{const r=n?Object.getOwnPropertyNames(e):Object.keys(e),i=r.length;let s;for(o=0;o<i;o++)s=r[o],t.call(null,e[s],s,e)}}function T(e,t){t=t.toLowerCase();const n=Object.keys(e);let o,r=n.length;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const R="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,A=e=>!u(e)&&e!==R,v=(j="undefined"!=typeof Uint8Array&&r(Uint8Array),e=>j&&e instanceof j);var j;const C=a("HTMLFormElement"),N=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),P=a("RegExp"),x=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),o={};O(n,((n,r)=>{!1!==t(n,r,e)&&(o[r]=n)})),Object.defineProperties(e,o)},_="abcdefghijklmnopqrstuvwxyz",U="0123456789",F={DIGIT:U,ALPHA:_,ALPHA_DIGIT:_+_.toUpperCase()+U},L=a("AsyncFunction"),D={isArray:l,isArrayBuffer:d,isBuffer:function(e){return null!==e&&!u(e)&&null!==e.constructor&&!u(e.constructor)&&h(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||h(e.append)&&("formdata"===(t=i(e))||"object"===t&&h(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&d(e.buffer),t},isString:f,isNumber:p,isBoolean:e=>!0===e||!1===e,isObject:g,isPlainObject:m,isUndefined:u,isDate:y,isFile:w,isBlob:b,isRegExp:P,isFunction:h,isStream:e=>g(e)&&h(e.pipe),isURLSearchParams:S,isTypedArray:v,isFileList:E,forEach:O,merge:function e(){const{caseless:t}=A(this)&&this||{},n={},o=(o,r)=>{const i=t&&T(n,r)||r;m(n[i])&&m(o)?n[i]=e(n[i],o):m(o)?n[i]=e({},o):l(o)?n[i]=o.slice():n[i]=o};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&O(arguments[e],o);return n},extend:(e,t,o,{allOwnKeys:r}={})=>(O(t,((t,r)=>{o&&h(t)?e[r]=n(t,o):e[r]=t}),{allOwnKeys:r}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,o)=>{e.prototype=Object.create(t.prototype,o),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,o)=>{let i,s,a;const c={};if(t=t||{},null==e)return t;do{for(i=Object.getOwnPropertyNames(e),s=i.length;s-- >0;)a=i[s],o&&!o(a,e,t)||c[a]||(t[a]=e[a],c[a]=!0);e=!1!==n&&r(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:i,kindOfTest:a,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;const o=e.indexOf(t,n);return-1!==o&&o===n},toArray:e=>{if(!e)return null;if(l(e))return e;let t=e.length;if(!p(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[Symbol.iterator]).call(e);let o;for(;(o=n.next())&&!o.done;){const n=o.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const o=[];for(;null!==(n=e.exec(t));)o.push(n);return o},isHTMLForm:C,hasOwnProperty:N,hasOwnProp:N,reduceDescriptors:x,freezeMethods:e=>{x(e,((t,n)=>{if(h(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;const o=e[n];h(o)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))}))},toObjectSet:(e,t)=>{const n={},o=e=>{e.forEach((e=>{n[e]=!0}))};return l(e)?o(e):o(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,(function(e,t,n){return t.toUpperCase()+n})),noop:()=>{},toFiniteNumber:(e,t)=>(e=+e,Number.isFinite(e)?e:t),findKey:T,global:R,isContextDefined:A,ALPHABET:F,generateString:(e=16,t=F.ALPHA_DIGIT)=>{let n="";const{length:o}=t;for(;e--;)n+=t[Math.random()*o|0];return n},isSpecCompliantForm:function(e){return!!(e&&h(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:e=>{const t=new Array(10),n=(e,o)=>{if(g(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[o]=e;const r=l(e)?[]:{};return O(e,((e,t)=>{const i=n(e,o+1);!u(i)&&(r[t]=i)})),t[o]=void 0,r}}return e};return n(e,0)},isAsyncFn:L,isThenable:e=>e&&(g(e)||h(e))&&h(e.then)&&h(e.catch)};function B(e,t,n,o,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),o&&(this.request=o),r&&(this.response=r)}D.inherits(B,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:D.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const I=B.prototype,k={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach((e=>{k[e]={value:e}})),Object.defineProperties(B,k),Object.defineProperty(I,"isAxiosError",{value:!0}),B.from=(e,t,n,o,r,i)=>{const s=Object.create(I);return D.toFlatObject(e,s,(function(e){return e!==Error.prototype}),(e=>"isAxiosError"!==e)),B.call(s,e.message,t,n,o,r),s.cause=e,s.name=e.name,i&&Object.assign(s,i),s};const M=B;function q(e){return D.isPlainObject(e)||D.isArray(e)}function z(e){return D.endsWith(e,"[]")?e.slice(0,-2):e}function H(e,t,n){return e?e.concat(t).map((function(e,t){return e=z(e),!n&&t?"["+e+"]":e})).join(n?".":""):t}const W=D.toFlatObject(D,{},null,(function(e){return/^is[A-Z]/.test(e)})),J=function(e,t,n){if(!D.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const o=(n=D.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,(function(e,t){return!D.isUndefined(t[e])}))).metaTokens,r=n.visitor||l,i=n.dots,s=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&D.isSpecCompliantForm(t);if(!D.isFunction(r))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(D.isDate(e))return e.toISOString();if(!a&&D.isBlob(e))throw new M("Blob is not supported. Use a Buffer instead.");return D.isArrayBuffer(e)||D.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function l(e,n,r){let a=e;if(e&&!r&&"object"==typeof e)if(D.endsWith(n,"{}"))n=o?n:n.slice(0,-2),e=JSON.stringify(e);else if(D.isArray(e)&&function(e){return D.isArray(e)&&!e.some(q)}(e)||(D.isFileList(e)||D.endsWith(n,"[]"))&&(a=D.toArray(e)))return n=z(n),a.forEach((function(e,o){!D.isUndefined(e)&&null!==e&&t.append(!0===s?H([n],o,i):null===s?n:n+"[]",c(e))})),!1;return!!q(e)||(t.append(H(r,n,i),c(e)),!1)}const u=[],d=Object.assign(W,{defaultVisitor:l,convertValue:c,isVisitable:q});if(!D.isObject(e))throw new TypeError("data must be an object");return function e(n,o){if(!D.isUndefined(n)){if(-1!==u.indexOf(n))throw Error("Circular reference detected in "+o.join("."));u.push(n),D.forEach(n,(function(n,i){!0===(!(D.isUndefined(n)||null===n)&&r.call(t,n,D.isString(i)?i.trim():i,o,d))&&e(n,o?o.concat(i):[i])})),u.pop()}}(e),t};function V(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,(function(e){return t[e]}))}function G(e,t){this._pairs=[],e&&J(e,this,t)}const K=G.prototype;K.append=function(e,t){this._pairs.push([e,t])},K.toString=function(e){const t=e?function(t){return e.call(this,t,V)}:V;return this._pairs.map((function(e){return t(e[0])+"="+t(e[1])}),"").join("&")};const $=G;function X(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function Q(e,t,n){if(!t)return e;const o=n&&n.encode||X,r=n&&n.serialize;let i;if(i=r?r(t,n):D.isURLSearchParams(t)?t.toString():new $(t,n).toString(o),i){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}const Y=class{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){D.forEach(this.handlers,(function(t){null!==t&&e(t)}))}},Z={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ee={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:$,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},isStandardBrowserEnv:(()=>{let e;return("undefined"==typeof navigator||"ReactNative"!==(e=navigator.product)&&"NativeScript"!==e&&"NS"!==e)&&"undefined"!=typeof window&&"undefined"!=typeof document})(),isStandardBrowserWebWorkerEnv:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,protocols:["http","https","file","blob","url","data"]},te=function(e){function t(e,n,o,r){let i=e[r++];const s=Number.isFinite(+i),a=r>=e.length;return i=!i&&D.isArray(o)?o.length:i,a?(D.hasOwnProp(o,i)?o[i]=[o[i],n]:o[i]=n,!s):(o[i]&&D.isObject(o[i])||(o[i]=[]),t(e,n,o[i],r)&&D.isArray(o[i])&&(o[i]=function(e){const t={},n=Object.keys(e);let o;const r=n.length;let i;for(o=0;o<r;o++)i=n[o],t[i]=e[i];return t}(o[i])),!s)}if(D.isFormData(e)&&D.isFunction(e.entries)){const n={};return D.forEachEntry(e,((e,o)=>{t(function(e){return D.matchAll(/\w+|\[(\w*)]/g,e).map((e=>"[]"===e[0]?"":e[1]||e[0]))}(e),o,n,0)})),n}return null},ne={"Content-Type":void 0},oe={transitional:Z,adapter:["xhr","http"],transformRequest:[function(e,t){const n=t.getContentType()||"",o=n.indexOf("application/json")>-1,r=D.isObject(e);if(r&&D.isHTMLForm(e)&&(e=new FormData(e)),D.isFormData(e))return o&&o?JSON.stringify(te(e)):e;if(D.isArrayBuffer(e)||D.isBuffer(e)||D.isStream(e)||D.isFile(e)||D.isBlob(e))return e;if(D.isArrayBufferView(e))return e.buffer;if(D.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let i;if(r){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return J(e,new ee.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,o){return ee.isNode&&D.isBuffer(e)?(this.append(t,e.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((i=D.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return J(i?{"files[]":e}:e,t&&new t,this.formSerializer)}}return r||o?(t.setContentType("application/json",!1),function(e,t,n){if(D.isString(e))try{return(0,JSON.parse)(e),D.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(0,JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||oe.transitional,n=t&&t.forcedJSONParsing,o="json"===this.responseType;if(e&&D.isString(e)&&(n&&!this.responseType||o)){const n=!(t&&t.silentJSONParsing)&&o;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw M.from(e,M.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:ee.classes.FormData,Blob:ee.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};D.forEach(["delete","get","head"],(function(e){oe.headers[e]={}})),D.forEach(["post","put","patch"],(function(e){oe.headers[e]=D.merge(ne)}));const re=oe,ie=D.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),se=Symbol("internals");function ae(e){return e&&String(e).trim().toLowerCase()}function ce(e){return!1===e||null==e?e:D.isArray(e)?e.map(ce):String(e)}function le(e,t,n,o,r){return D.isFunction(o)?o.call(this,t,n):(r&&(t=n),D.isString(t)?D.isString(o)?-1!==t.indexOf(o):D.isRegExp(o)?o.test(t):void 0:void 0)}class ue{constructor(e){e&&this.set(e)}set(e,t,n){const o=this;function r(e,t,n){const r=ae(t);if(!r)throw new Error("header name must be a non-empty string");const i=D.findKey(o,r);(!i||void 0===o[i]||!0===n||void 0===n&&!1!==o[i])&&(o[i||t]=ce(e))}const i=(e,t)=>D.forEach(e,((e,n)=>r(e,n,t)));return D.isPlainObject(e)||e instanceof this.constructor?i(e,t):D.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim())?i((e=>{const t={};let n,o,r;return e&&e.split("\n").forEach((function(e){r=e.indexOf(":"),n=e.substring(0,r).trim().toLowerCase(),o=e.substring(r+1).trim(),!n||t[n]&&ie[n]||("set-cookie"===n?t[n]?t[n].push(o):t[n]=[o]:t[n]=t[n]?t[n]+", "+o:o)})),t})(e),t):null!=e&&r(t,e,n),this}get(e,t){if(e=ae(e)){const n=D.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let o;for(;o=n.exec(e);)t[o[1]]=o[2];return t}(e);if(D.isFunction(t))return t.call(this,e,n);if(D.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=ae(e)){const n=D.findKey(this,e);return!(!n||void 0===this[n]||t&&!le(0,this[n],n,t))}return!1}delete(e,t){const n=this;let o=!1;function r(e){if(e=ae(e)){const r=D.findKey(n,e);!r||t&&!le(0,n[r],r,t)||(delete n[r],o=!0)}}return D.isArray(e)?e.forEach(r):r(e),o}clear(e){const t=Object.keys(this);let n=t.length,o=!1;for(;n--;){const r=t[n];e&&!le(0,this[r],r,e,!0)||(delete this[r],o=!0)}return o}normalize(e){const t=this,n={};return D.forEach(this,((o,r)=>{const i=D.findKey(n,r);if(i)return t[i]=ce(o),void delete t[r];const s=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,((e,t,n)=>t.toUpperCase()+n))}(r):String(r).trim();s!==r&&delete t[r],t[s]=ce(o),n[s]=!0})),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return D.forEach(this,((n,o)=>{null!=n&&!1!==n&&(t[o]=e&&D.isArray(n)?n.join(", "):n)})),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map((([e,t])=>e+": "+t)).join("\n")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach((e=>n.set(e))),n}static accessor(e){const t=(this[se]=this[se]={accessors:{}}).accessors,n=this.prototype;function o(e){const o=ae(e);t[o]||(function(e,t){const n=D.toCamelCase(" "+t);["get","set","has"].forEach((o=>{Object.defineProperty(e,o+n,{value:function(e,n,r){return this[o].call(this,t,e,n,r)},configurable:!0})}))}(n,e),t[o]=!0)}return D.isArray(e)?e.forEach(o):o(e),this}}ue.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),D.freezeMethods(ue.prototype),D.freezeMethods(ue);const de=ue;function fe(e,t){const n=this||re,o=t||n,r=de.from(o.headers);let i=o.data;return D.forEach(e,(function(e){i=e.call(n,i,r.normalize(),t?t.status:void 0)})),r.normalize(),i}function he(e){return!(!e||!e.__CANCEL__)}function pe(e,t,n){M.call(this,null==e?"canceled":e,M.ERR_CANCELED,t,n),this.name="CanceledError"}D.inherits(pe,M,{__CANCEL__:!0});const ge=pe,me=ee.isStandardBrowserEnv?{write:function(e,t,n,o,r,i){const s=[];s.push(e+"="+encodeURIComponent(t)),D.isNumber(n)&&s.push("expires="+new Date(n).toGMTString()),D.isString(o)&&s.push("path="+o),D.isString(r)&&s.push("domain="+r),!0===i&&s.push("secure"),document.cookie=s.join("; ")},read:function(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}};function ye(e,t){return e&&!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}const we=ee.isStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let n;function o(n){let o=n;return e&&(t.setAttribute("href",o),o=t.href),t.setAttribute("href",o),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return n=o(window.location.href),function(e){const t=D.isString(e)?o(e):e;return t.protocol===n.protocol&&t.host===n.host}}():function(){return!0};function be(e,t){let n=0;const o=function(e,t){e=e||10;const n=new Array(e),o=new Array(e);let r,i=0,s=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),l=o[s];r||(r=c),n[i]=a,o[i]=c;let u=s,d=0;for(;u!==i;)d+=n[u++],u%=e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),c-r<t)return;const f=l&&c-l;return f?Math.round(1e3*d/f):void 0}}(50,250);return r=>{const i=r.loaded,s=r.lengthComputable?r.total:void 0,a=i-n,c=o(a);n=i;const l={loaded:i,total:s,progress:s?i/s:void 0,bytes:a,rate:c||void 0,estimated:c&&s&&i<=s?(s-i)/c:void 0,event:r};l[t?"download":"upload"]=!0,e(l)}}const Ee={http:null,xhr:"undefined"!=typeof XMLHttpRequest&&function(e){return new Promise((function(t,n){let o=e.data;const r=de.from(e.headers).normalize(),i=e.responseType;let s;function a(){e.cancelToken&&e.cancelToken.unsubscribe(s),e.signal&&e.signal.removeEventListener("abort",s)}D.isFormData(o)&&(ee.isStandardBrowserEnv||ee.isStandardBrowserWebWorkerEnv?r.setContentType(!1):r.setContentType("multipart/form-data;",!1));let c=new XMLHttpRequest;if(e.auth){const t=e.auth.username||"",n=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";r.set("Authorization","Basic "+btoa(t+":"+n))}const l=ye(e.baseURL,e.url);function u(){if(!c)return;const o=de.from("getAllResponseHeaders"in c&&c.getAllResponseHeaders());!function(e,t,n){const o=n.config.validateStatus;n.status&&o&&!o(n.status)?t(new M("Request failed with status code "+n.status,[M.ERR_BAD_REQUEST,M.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}((function(e){t(e),a()}),(function(e){n(e),a()}),{data:i&&"text"!==i&&"json"!==i?c.response:c.responseText,status:c.status,statusText:c.statusText,headers:o,config:e,request:c}),c=null}if(c.open(e.method.toUpperCase(),Q(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout,"onloadend"in c?c.onloadend=u:c.onreadystatechange=function(){c&&4===c.readyState&&(0!==c.status||c.responseURL&&0===c.responseURL.indexOf("file:"))&&setTimeout(u)},c.onabort=function(){c&&(n(new M("Request aborted",M.ECONNABORTED,e,c)),c=null)},c.onerror=function(){n(new M("Network Error",M.ERR_NETWORK,e,c)),c=null},c.ontimeout=function(){let t=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded";const o=e.transitional||Z;e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(new M(t,o.clarifyTimeoutError?M.ETIMEDOUT:M.ECONNABORTED,e,c)),c=null},ee.isStandardBrowserEnv){const t=(e.withCredentials||we(l))&&e.xsrfCookieName&&me.read(e.xsrfCookieName);t&&r.set(e.xsrfHeaderName,t)}void 0===o&&r.setContentType(null),"setRequestHeader"in c&&D.forEach(r.toJSON(),(function(e,t){c.setRequestHeader(t,e)})),D.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),i&&"json"!==i&&(c.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&c.addEventListener("progress",be(e.onDownloadProgress,!0)),"function"==typeof e.onUploadProgress&&c.upload&&c.upload.addEventListener("progress",be(e.onUploadProgress)),(e.cancelToken||e.signal)&&(s=t=>{c&&(n(!t||t.type?new ge(null,e,c):t),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(s),e.signal&&(e.signal.aborted?s():e.signal.addEventListener("abort",s)));const d=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(l);d&&-1===ee.protocols.indexOf(d)?n(new M("Unsupported protocol "+d+":",M.ERR_BAD_REQUEST,e)):c.send(o||null)}))}};D.forEach(Ee,((e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}}));function Se(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new ge(null,e)}function Oe(e){return Se(e),e.headers=de.from(e.headers),e.data=fe.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),(e=>{e=D.isArray(e)?e:[e];const{length:t}=e;let n,o;for(let r=0;r<t&&(n=e[r],!(o=D.isString(n)?Ee[n.toLowerCase()]:n));r++);if(!o){if(!1===o)throw new M(`Adapter ${n} is not supported by the environment`,"ERR_NOT_SUPPORT");throw new Error(D.hasOwnProp(Ee,n)?`Adapter '${n}' is not available in the build`:`Unknown adapter '${n}'`)}if(!D.isFunction(o))throw new TypeError("adapter is not a function");return o})(e.adapter||re.adapter)(e).then((function(t){return Se(e),t.data=fe.call(e,e.transformResponse,t),t.headers=de.from(t.headers),t}),(function(t){return he(t)||(Se(e),t&&t.response&&(t.response.data=fe.call(e,e.transformResponse,t.response),t.response.headers=de.from(t.response.headers))),Promise.reject(t)}))}const Te=e=>e instanceof de?e.toJSON():e;function Re(e,t){t=t||{};const n={};function o(e,t,n){return D.isPlainObject(e)&&D.isPlainObject(t)?D.merge.call({caseless:n},e,t):D.isPlainObject(t)?D.merge({},t):D.isArray(t)?t.slice():t}function r(e,t,n){return D.isUndefined(t)?D.isUndefined(e)?void 0:o(void 0,e,n):o(e,t,n)}function i(e,t){if(!D.isUndefined(t))return o(void 0,t)}function s(e,t){return D.isUndefined(t)?D.isUndefined(e)?void 0:o(void 0,e):o(void 0,t)}function a(n,r,i){return i in t?o(n,r):i in e?o(void 0,n):void 0}const c={url:i,method:i,data:i,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,responseEncoding:s,validateStatus:a,headers:(e,t)=>r(Te(e),Te(t),!0)};return D.forEach(Object.keys(Object.assign({},e,t)),(function(o){const i=c[o]||r,s=i(e[o],t[o],o);D.isUndefined(s)&&i!==a||(n[o]=s)})),n}const Ae={};["object","boolean","number","function","string","symbol"].forEach(((e,t)=>{Ae[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}}));const ve={};Ae.transitional=function(e,t,n){function o(e,t){return"[Axios v1.4.0] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,r,i)=>{if(!1===e)throw new M(o(r," has been removed"+(t?" in "+t:"")),M.ERR_DEPRECATED);return t&&!ve[r]&&(ve[r]=!0,console.warn(o(r," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,r,i)}};const je={assertOptions:function(e,t,n){if("object"!=typeof e)throw new M("options must be an object",M.ERR_BAD_OPTION_VALUE);const o=Object.keys(e);let r=o.length;for(;r-- >0;){const i=o[r],s=t[i];if(s){const t=e[i],n=void 0===t||s(t,i,e);if(!0!==n)throw new M("option "+i+" must be "+n,M.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new M("Unknown option "+i,M.ERR_BAD_OPTION)}},validators:Ae},Ce=je.validators;class Ne{constructor(e){this.defaults=e,this.interceptors={request:new Y,response:new Y}}request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=Re(this.defaults,t);const{transitional:n,paramsSerializer:o,headers:r}=t;let i;void 0!==n&&je.assertOptions(n,{silentJSONParsing:Ce.transitional(Ce.boolean),forcedJSONParsing:Ce.transitional(Ce.boolean),clarifyTimeoutError:Ce.transitional(Ce.boolean)},!1),null!=o&&(D.isFunction(o)?t.paramsSerializer={serialize:o}:je.assertOptions(o,{encode:Ce.function,serialize:Ce.function},!0)),t.method=(t.method||this.defaults.method||"get").toLowerCase(),i=r&&D.merge(r.common,r[t.method]),i&&D.forEach(["delete","get","head","post","put","patch","common"],(e=>{delete r[e]})),t.headers=de.concat(i,r);const s=[];let a=!0;this.interceptors.request.forEach((function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,s.unshift(e.fulfilled,e.rejected))}));const c=[];let l;this.interceptors.response.forEach((function(e){c.push(e.fulfilled,e.rejected)}));let u,d=0;if(!a){const e=[Oe.bind(this),void 0];for(e.unshift.apply(e,s),e.push.apply(e,c),u=e.length,l=Promise.resolve(t);d<u;)l=l.then(e[d++],e[d++]);return l}u=s.length;let f=t;for(d=0;d<u;){const e=s[d++],t=s[d++];try{f=e(f)}catch(e){t.call(this,e);break}}try{l=Oe.call(this,f)}catch(e){return Promise.reject(e)}for(d=0,u=c.length;d<u;)l=l.then(c[d++],c[d++]);return l}getUri(e){return Q(ye((e=Re(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}D.forEach(["delete","get","head","options"],(function(e){Ne.prototype[e]=function(t,n){return this.request(Re(n||{},{method:e,url:t,data:(n||{}).data}))}})),D.forEach(["post","put","patch"],(function(e){function t(t){return function(n,o,r){return this.request(Re(r||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:o}))}}Ne.prototype[e]=t(),Ne.prototype[e+"Form"]=t(!0)}));const Pe=Ne;class xe{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((function(e){t=e}));const n=this;this.promise.then((e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null})),this.promise.then=e=>{let t;const o=new Promise((e=>{n.subscribe(e),t=e})).then(e);return o.cancel=function(){n.unsubscribe(t)},o},e((function(e,o,r){n.reason||(n.reason=new ge(e,o,r),t(n.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}static source(){let e;return{token:new xe((function(t){e=t})),cancel:e}}}const _e=xe,Ue={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ue).forEach((([e,t])=>{Ue[t]=e}));const Fe=Ue,Le=function e(t){const o=new Pe(t),r=n(Pe.prototype.request,o);return D.extend(r,Pe.prototype,o,{allOwnKeys:!0}),D.extend(r,o,null,{allOwnKeys:!0}),r.create=function(n){return e(Re(t,n))},r}(re);Le.Axios=Pe,Le.CanceledError=ge,Le.CancelToken=_e,Le.isCancel=he,Le.VERSION="1.4.0",Le.toFormData=J,Le.AxiosError=M,Le.Cancel=Le.CanceledError,Le.all=function(e){return Promise.all(e)},Le.spread=function(e){return function(t){return e.apply(null,t)}},Le.isAxiosError=function(e){return D.isObject(e)&&!0===e.isAxiosError},Le.mergeConfig=Re,Le.AxiosHeaders=de,Le.formToJSON=e=>te(D.isHTMLForm(e)?new FormData(e):e),Le.HttpStatusCode=Fe,Le.default=Le;const De=Le;const Be=function(){function e(e){var t=e.enabled,n=void 0!==t&&t,o=e.instanceId,r=void 0===o?"":o;this.enabled=!1,this.instanceId="",this.enabled=n,this.instanceId=r}return e.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.log("info",e)},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.log("error",e)},e.prototype.log=function(e,t){if(this.enabled){var n=function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}(["[".concat(this.instanceId,"]: ")],t,!0);"error"===e?console.error.apply(console,n):console.log.apply(console,n)}},e}();const Ie=function(){function e(e){var t=e.baseUrl,n=void 0===t?"https://id.eideasy.com":t,o=e.onSuccess,r=void 0===o?function(){}:o,i=e.onFail,s=void 0===i?function(){}:i,a=e.onPopupWindowClosed,c=void 0===a?function(){}:a,l=e.loggingEnabled,u=void 0!==l&&l,d=e.instanceId,f=void 0===d?null:d;this.successCalled=!1,this.pollTimeout=null,this.windowTarget=null,this.logger=null,f=f||this.generateInstanceId(),this.logger=new Be({enabled:u,instanceId:f}),this.baseUrl=n,this.onSuccess=r,this.onFail=s,this.onPopupWindowClosed=c,this.messageHandler=this.handleMessage.bind(this),this.windowTarget=f,this.logger.info("EidEasy windowTarget",this.windowTarget),window.addEventListener("message",this.messageHandler)}return e.prototype.generateInstanceId=function(e){return void 0===e&&(e=32),function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}([],Array(e),!0).map((function(){return(~~(36*Math.random())).toString(36)})).join("")},e.prototype.handleMessage=function(e){var t=e.data;"EIDEASY_SINGLE_METHOD_SIGNATURE"===t.sender?t.windowTarget===this.windowTarget?(this.logger.info("EidEasy handleMessage",e),"SUCCESS"===t.type?(this.logger.info("EidEasy triggering handleSuccess on success message."),this.handleSuccess()):"FAIL"===t.type&&(this.logger.info("EidEasy triggering handleFail on fail message."),this.handleFail(t.error,t.isRetryAllowed))):this.logger.info("Skipping this message because the windowTarget in message data does not match",{messageDataWindowTarget:t.windowTarget,thisWindowTarget:this.windowTarget}):this.logger.info("Skipping this message because the data.sender is not EIDEASY_SINGLE_METHOD_SIGNATURE, message data: ",t)},e.prototype.start=function(e){var t=e.clientId,n=e.docId,o=e.actionType,r=e.country,i=e.language,s=e.inputValues;this.successCalled=!1;var a=this,c=this.getSingleMethodSignaturePageUrl({clientId:t,docId:n,actionType:o,country:r,language:i,windowTarget:this.windowTarget,inputValues:s}),l=function(e){var t=e.target,n=e.url,o=e.onClosed,r=e.logger,i={width:800,height:600},s=function(e){var t=e.parent,n=e.child;return{left:t.width/2-n.width/2+t.left,top:t.height/2-n.height/2+t.top}}({parent:{width:window.outerWidth,height:window.outerHeight,left:window.screenLeft,top:window.screenTop},child:i}),a=["toolbar=no","location=no","directories=no","status=no","menubar=no","scrollbars=no","resizable=no","copyhistory=no","width=".concat(i.width),"height=".concat(i.height),"left=".concat(s.left),"top=".concat(s.top)];r.info("Opening window at url: ",n);var c=window.open(n,t,a.join(", ")),l=setInterval((function(){c.closed&&(clearInterval(l),o())}),500);return{window:c}}({target:this.windowTarget,url:c,onClosed:function(){a.stop(),a.onPopupWindowClosed()},logger:this.logger});this.openedWindow=l.window,this.pollTimeout&&(window.clearTimeout(this.pollTimeout),this.pollTimeout=null),this.poll(n,t)},e.prototype.stop=function(){window.clearTimeout(this.pollTimeout),this.pollTimeout=null,this.openedWindow.close&&this.openedWindow.close()},e.prototype.poll=function(e,t){var n=this,o=this;this.pollTimeout=window.setTimeout((function(){De.post("".concat(n.baseUrl,"/api/signatures/signing-session/status"),{doc_id:e,client_id:t}).then((function(r){if(r.data&&"SIGNED"===r.data.signing_session_status)return o.logger.info("Calling handleSuccess signing_session_status SIGNED in poller"),void o.handleSuccess();null!==n.pollTimeout&&o.poll(e,t)})).catch((function(e){o.logger.info(e)}))}),2e3)},e.prototype.handleSuccess=function(){if(this.successCalled)this.logger.info("Success already called");else{this.successCalled=!0;try{this.openedWindow.close()}catch(e){this.logger.error(e)}this.onSuccess()}},e.prototype.handleFail=function(e,t){t||(this.openedWindow.close(),this.onFail(e))},e.prototype.getSingleMethodSignaturePageUrl=function(e){var t=e.clientId,n=e.docId,o=e.actionType,r=e.country,i=e.language,s=e.windowTarget,a=e.inputValues,c="".concat(this.baseUrl,"/single-method-signature"),l=["client_id=".concat(t),"doc_id=".concat(n),"method=".concat(o),"country=".concat(r),"window_target=".concat(s)];i&&l.push("lang=".concat(i)),a&&Object.keys(a).forEach((function(e){l.push("".concat(e,"=").concat(a[e]))}));var u=l.join("&");return"".concat(c,"?").concat(u)},e.prototype.destroy=function(){window.removeEventListener("message",this.messageHandler),window.clearTimeout(this.pollTimeout),this.pollTimeout=null},e}();return t})()));
//# sourceMappingURL=eideasy-signature.js.map