@it-enterprise/digital-signature 1.3.9 → 1.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/euscp/EndUserSettings.d.ts +9 -0
- package/euscp/euscp.js +1 -1
- package/package.json +1 -1
- package/src/DigitalSignature.js +53 -24
- package/src/Resourses.json +10 -4
- package/src/euscp.worker.js +46 -21
- package/worker/{euscp.worker.ex-1.3.80.js → euscp.worker.ex-1.3.81.js} +33 -16
- package/worker/euscp.worker.extensions.js +13 -5
|
@@ -83,6 +83,9 @@ export declare class KSPSettings {
|
|
|
83
83
|
* @property <boolean> signInfoTmpl - An object or URL with sign info template (not implemented).
|
|
84
84
|
* @property <number> connectionTimeout - Timeout for connections to CA servers in ms. Affects only for SW library type. By default set to 60s.
|
|
85
85
|
* @property <number> ocspResponseExpireTime - The time interval during which the cryptolibrary trust for the response from the OCSP server in seconds. By default set to 0s, recomended 30s (used on the https://czo.gov.ua/verify), max value 3600s.
|
|
86
|
+
* @property <boolean> useSLoginPrivateKey - A boolean value that specifies whether library reads private key used for system login. Using by SignWeb libraries. By default set to false.
|
|
87
|
+
* @property <boolean> allowForeignCAs - A boolean value that specifies support for reading private keys without specifying a CA settings in the CAs list. Used to read foreign keys. Typically used in conjunction with setting the TSLAddress and TSPServer parameters. By default set to false.
|
|
88
|
+
* @property <{address: string, port: string}> TSPServer - Default TSP server settings (used if the end-user certificate does not have a TSP access point). The first TSP server from the CAs is used by default.
|
|
86
89
|
*/
|
|
87
90
|
export declare class EndUserSettings {
|
|
88
91
|
language: string;
|
|
@@ -108,6 +111,12 @@ export declare class EndUserSettings {
|
|
|
108
111
|
signInfoTmpl?: any | string;
|
|
109
112
|
connectionTimeout?: number;
|
|
110
113
|
ocspResponseExpireTime?: number;
|
|
114
|
+
useSLoginPrivateKey?: boolean;
|
|
115
|
+
allowForeignCAs?: boolean;
|
|
116
|
+
TSPServer?: {
|
|
117
|
+
address: string;
|
|
118
|
+
port: string;
|
|
119
|
+
};
|
|
111
120
|
}
|
|
112
121
|
/**
|
|
113
122
|
* Settings to configure EndUser library proxy server.
|
package/euscp/euscp.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* @license Licensed under MIT license
|
|
6
6
|
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
|
|
7
7
|
* @version 3.3.1
|
|
8
|
-
*/i=function(){"use strict";function t(t){return"function"==typeof t}var i=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=0,s=void 0,a=void 0,u=function(t,e){E[o]=t,E[o+1]=e,2===(o+=2)&&(a?a(y):R())},c="undefined"!=typeof window?window:void 0,l=c||{},f=l.MutationObserver||l.WebKitMutationObserver,_="undefined"==typeof self&&void 0!==e&&"[object process]"==={}.toString.call(e),p="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function h(){var t=setTimeout;return function(){return t(y,1)}}var E=new Array(1e3);function y(){for(var t=0;t<o;t+=2)(0,E[t])(E[t+1]),E[t]=void 0,E[t+1]=void 0;o=0}var S,C,d,A,R=void 0;function m(t,e){var n=arguments,r=this,i=new this.constructor(P);void 0===i[g]&&x(i);var o,s=r._state;return s?(o=n[s-1],u((function(){return K(s,i,o,r._result)}))):N(r,i,t,e),i}function T(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(P);return b(e,t),e}_?R=function(){return e.nextTick(y)}:f?(C=0,d=new f(y),A=document.createTextNode(""),d.observe(A,{characterData:!0}),R=function(){A.data=C=++C%2}):p?((S=new MessageChannel).port1.onmessage=y,R=function(){return S.port2.postMessage(0)}):R=void 0===c?function(){try{var t=n(23);return s=t.runOnLoop||t.runOnContext,function(){s(y)}}catch(t){return h()}}():h();var g=Math.random().toString(36).substring(16);function P(){}var v=new w;function I(t){try{return t.then}catch(t){return v.error=t,v}}function U(e,n,r){n.constructor===e.constructor&&r===m&&n.constructor.resolve===T?function(t,e){1===e._state?O(t,e._result):2===e._state?G(t,e._result):N(e,void 0,(function(e){return b(t,e)}),(function(e){return G(t,e)}))}(e,n):r===v?G(e,v.error):void 0===r?O(e,n):t(r)?function(t,e,n){u((function(t){var r=!1,i=function(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}(n,e,(function(n){r||(r=!0,e!==n?b(t,n):O(t,n))}),(function(e){r||(r=!0,G(t,e))}),t._label);!r&&i&&(r=!0,G(t,i))}),t)}(e,n,r):O(e,n)}function b(t,e){var n;t===e?G(t,new TypeError("You cannot resolve a promise with itself")):"function"==typeof(n=e)||"object"==typeof n&&null!==n?U(t,e,I(e)):O(t,e)}function D(t){t._onerror&&t._onerror(t._result),M(t)}function O(t,e){void 0===t._state&&(t._result=e,t._state=1,0!==t._subscribers.length&&u(M,t))}function G(t,e){void 0===t._state&&(t._state=2,t._result=e,u(D,t))}function N(t,e,n,r){var i=t._subscribers,o=i.length;t._onerror=null,i[o]=e,i[o+1]=n,i[o+2]=r,0===o&&t._state&&u(M,t)}function M(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,i=void 0,o=t._result,s=0;s<e.length;s+=3)r=e[s],i=e[s+n],r?K(n,r,i,o):i(o);t._subscribers.length=0}}function w(){this.error=null}var L=new w;function K(e,n,r,i){var o=t(r),s=void 0,a=void 0,u=void 0,c=void 0;if(o){if((s=function(t,e){try{return t(e)}catch(t){return L.error=t,L}}(r,i))===L?(c=!0,a=s.error,s=null):u=!0,n===s)return void G(n,new TypeError("A promises callback cannot return that same promise."))}else s=i,u=!0;void 0!==n._state||(o&&u?b(n,s):c?G(n,a):1===e?O(n,s):2===e&&G(n,s))}var k=0;function x(t){t[g]=k++,t._state=void 0,t._result=void 0,t._subscribers=[]}function B(t,e){this._instanceConstructor=t,this.promise=new t(P),this.promise[g]||x(this.promise),i(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?O(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&O(this.promise,this._result))):G(this.promise,new Error("Array Methods must be provided an Array"))}function F(t){this[g]=k++,this._result=this._state=void 0,this._subscribers=[],P!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof F?function(t,e){try{e((function(e){b(t,e)}),(function(e){G(t,e)}))}catch(e){G(t,e)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}function H(){var t=void 0;if(void 0!==r)t=r;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=F}return B.prototype._enumerate=function(){for(var t=this.length,e=this._input,n=0;void 0===this._state&&n<t;n++)this._eachEntry(e[n],n)},B.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===T){var i=I(t);if(i===m&&void 0!==t._state)this._settledAt(t._state,e,t._result);else if("function"!=typeof i)this._remaining--,this._result[e]=t;else if(n===F){var o=new n(P);U(o,t,i),this._willSettleAt(o,e)}else this._willSettleAt(new n((function(e){return e(t)})),e)}else this._willSettleAt(r(t),e)},B.prototype._settledAt=function(t,e,n){var r=this.promise;void 0===r._state&&(this._remaining--,2===t?G(r,n):this._result[e]=n),0===this._remaining&&O(r,this._result)},B.prototype._willSettleAt=function(t,e){var n=this;N(t,void 0,(function(t){return n._settledAt(1,e,t)}),(function(t){return n._settledAt(2,e,t)}))},F.all=function(t){return new B(this,t).promise},F.race=function(t){var e=this;return i(t)?new e((function(n,r){for(var i=t.length,o=0;o<i;o++)e.resolve(t[o]).then(n,r)})):new e((function(t,e){return e(new TypeError("You must pass an array to race."))}))},F.resolve=T,F.reject=function(t){var e=new this(P);return G(e,t),e},F._setScheduler=function(t){a=t},F._setAsap=function(t){u=t},F._asap=u,F.prototype={constructor:F,then:m,catch:function(t){return this.then(null,t)}},H(),F.polyfill=H,F.Promise=F,F},t.exports=i()}).call(this,n(21),n(22))},function(t,e,n){"use strict";(function(t){var n=function(t,e,n){this.id=t,this.cmd=e,this.params=n,this.origin=window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:""),this.pathname=window.location.pathname},r=function(t,e,n,r){this.id=t,this.cmd=e,this.result=n,this.error=r},i=function(){function e(t,e,n){var r=this;this.m_worker=this.loadWorker(t,e),this.m_worker.onmessage=function(t){var e=t.data;if(-2!=e.id){var i=r.m_promises[e.id-1];i&&(delete r.m_promises[e.id-1],e.error?i.reject(e.error):i.resolve(e.result))}else n(e.result)},this.m_worker.onerror=function(t){r.m_promises.forEach((function(e){e.reject(t.error)})),r.m_promises=new Array},this.m_promises=new Array}return e.prototype.loadWorker=function(t,e){try{if(!t)throw"No worker content";try{var n,r=window,i=r.URL||r.webkitURL;try{(n=new(r.BlobBuilder||r.WebKitBlobBuilder||r.MozBlobBuilder||r.MSBlobBuilder)).append(t),n=n.getBlob()}catch(e){n=new Blob([t])}return new Worker(i.createObjectURL(n))}catch(e){return new Worker("data:application/javascript,"+encodeURIComponent(t))}}catch(t){if(!e)throw Error("Inline worker is not supported");return new Worker(e)}},e.prototype.postMessage=function(e,r){var i=this,o=new n(-1,e,r),s=new t((function(t,e){o.id=i.m_promises.push({resolve:t,reject:e})}));return this.m_worker.postMessage(o),s},e}();e.a=i;!function(){function t(t){this.m_context=t,this.m_initialized=!1;var e=this;self.onmessage=function(t){e.onMessage(t.data)}}t.prototype.postMessage=function(t,e,n,i){var o=new r(t,e,n,i);self.postMessage(o)},t.prototype.onMessage=function(t){var e=this;this.m_initialized?this.m_context[t.cmd].apply(this.m_context,t.params).then((function(n){e.postMessage(t.id,t.cmd,n)}),(function(n){e.postMessage(t.id,t.cmd,null,n)})):setTimeout((function(){e.onMessage(t)}),50)},t.prototype.initialize=function(){this.m_initialized=!0}}()}).call(this,n(17).Promise)},function(t,e,n){"use strict";(function(t){var r=n(1),i=n(9),o=n(10),s=n(14),a=n(20),u=n(4),c=n(13),l=n(2),f=n(8),_=n(0),p=n(11),h=n(15),E=n(16),y=n(7),S=n(5),C=n(12),d=n(6),A=function(){},R=function(){function e(){this.GetDefaultTSPSettings=function(){for(var t=null,e=this.m_settings.CAs,n=0;n<e.length&&(!e[n].tspAddress||!e[n].tspAddressPort||(t&&"80"!=e[n].tspAddressPort||(t=e[n]),"80"!=t.tspAddressPort));n++);return t},this.MakeExpireDate=function(t){t||(t=300);var e=new Date;return e.setTime(e.getTime()+1e3*t),e},this.m_library=new a.a,this.m_settings=null,this.m_initialized=!1,this.m_kmTypes=null,this.m_kmActiveOperation=!1,this.m_context=null,this.m_pkContext=null,this.m_eventListeners=new Array,this.m_resolveOIDs=!1,this.m_origin=window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"")}return e.prototype.MapError=function(t){var e=new r.EndUserError;return void 0!==t.GetErrorCode&&void 0!==t.GetMessage?(e.code=t.GetErrorCode(),e.message=t.GetMessage()):void 0!==t.code&&void 0!==t.message?(e.code=t.code,e.message=t.message):(e.code=r.EU_ERROR_UNKNOWN,e.message=t.toString()),e},e.prototype.ProcessArray=function(e,n){var r=this;return new t((function(t,i){var o=Array(),s=0,a=function(){s>=e.length?t(o):(n(e[s]).then((function(t){o.push(t),a()})).catch((function(t){return i(r.MapError(t))})),s++)};a()}))},e.prototype.DataToNamedDataArray=function(t){t=null!=t?t:[],t=Array.isArray(t)?t:[t];for(var e=[],n=0;n<t.length;n++){var r=void 0!==t[n].name&&void 0!==t[n].val;e.push({name:r?t[n].name:"Ім'я відсутнє",val:r?t[n].val:t[n]})}return e},e.prototype.DataToResult=function(t,e){for(var n=[],r=!Array.isArray(t),i=r?[t]:t,o=0;o<i.length;o++){var s=void 0!==i[o].name&&void 0!==i[o].val?{name:i[o].name,val:e[o]}:e[o];n.push(s)}return r?n[0]:n},e.prototype.NamedDataToReference=function(e){var n=this,r=n.m_library;return new t((function(t,i){"string"==typeof e.val?r.StringToBytes(e.val).then((function(n){var i=r.CreateReference(e.name,n);t(i)})).catch((function(t){return i(n.MapError(t))})):setTimeout((function(){var n=r.CreateReference(e.name,e.val);t(n)}),1)}))},e.prototype.OnEvent=function(t){try{var e=this.m_eventListeners[t.type]||this.m_eventListeners[_.EndUserEventType.All];e&&e(t)}catch(t){}},e.prototype.CheckInitialize=function(){var e=this,n=e.m_library;return new t((function(t,i){e.m_initialized?t():n.Load().then((function(){throw n.MakeError(r.EU_ERROR_NOT_INITIALIZED,"")})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.BeginKMOperation=function(){var e=this;return new t((function(t,n){var r=function(){e.m_kmActiveOperation?setTimeout(r,10):(e.m_kmActiveOperation=!0,t())};r()}))},e.prototype.EndKMOperation=function(){this.m_kmActiveOperation=!1},e.prototype.GetCASettings=function(t){if(!t)return null;for(var e=this.m_settings.CAs,n=0;n<e.length;n++)for(var r=e[n].issuerCNs,i=0;i<r.length;i++)if(r[i]==t)return e[n];return null},e.prototype.IsCMPCompatible=function(t,e){return!!t.cmpAddress&&(void 0===t.cmpCompatibility||(t.cmpCompatibility&e)==e)},e.prototype.SetCMPSettings=function(e){var n=this,i=n.m_library,o=this.GetCASettings(e);return new t((function(t,s){if(e&&null==o)throw i.MakeError(r.EU_ERROR_WRITE_SETTINGS,"");var a;a=!(!o||!o.cmpAddress);var u=i.CreateCMPSettings();u.SetUseCMP(a),a&&(u.SetAddress(o.cmpAddress),u.SetPort("80")),i.SetCMPSettings(u).then((function(){t()})).catch((function(t){s(n.MapError(t))}))}))},e.prototype.GetJKSPrivateKey=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){var a={alias:null,info:null};i.EnumJKSPrivateKeys(e,n).then((function(n){if(null!=n)return a.alias=n,i.GetJKSPrivateKey(e,n);t(null)})).then((function(t){a.info=t;for(var e=new Array,n=0;n<t.GetCertificatesCount();n++)e.push(t.GetCertificate(n));return r.ProcessArray(e,(function(t){return i.ParseCertificateEx(t)}))})).then((function(e){var n=new s.a;n.alias=a.alias,n.privateKey=a.info.GetPrivateKey(),n.certificates=new Array,n.digitalStamp=!1;for(var r=0;r<e.length;r++){var o=e[r];if(o.GetSubjType()==i.EU_SUBJECT_TYPE_END_USER){o.GetPublicKeyType()==i.EU_CERT_KEY_TYPE_DSTU4145&&(o.GetKeyUsageType()&i.EU_KEY_USAGE_DIGITAL_SIGNATURE)==i.EU_KEY_USAGE_DIGITAL_SIGNATURE&&(n.digitalStamp=o.GetExtKeyUsages().indexOf(i.EU_UA_OID_EXT_KEY_USAGE_STAMP)>-1);var c=new u.EndUserCertificate;c.data=a.info.GetCertificate(r),c.infoEx=l.a.MapToEndUserCertificateInfoEx(o,new f.a),n.certificates.push(c)}}n.digitalStamp=!1,t(n)})).catch((function(t){return o(r.MapError(t))}))}))},e.prototype.SaveCertificatesInternal=function(e){var n=this,r=this.m_library;return new t((function(t,i){e?Array.isArray(e)?n.ProcessArray(e,(function(t){return r.SaveCertificate(t)})).then((function(){return t()})).catch((function(t){return i(t)})):r.SaveCertificates(e).then((function(){return t()})).catch((function(t){return i(t)})):t()}))},e.prototype.CtxReadPrivateKeyInternal=function(e,n,i,o,s,a,u){void 0===u&&(u=!0);var c=this,l=this.m_library,f={pkContext:null};return e||(e=c.m_context),new t((function(t,_){c.SaveCertificatesInternal(s).then((function(){return c.SetCMPSettings(a)})).then((function(){return null!=n&&null!=i?l.CtxReadPrivateKeyBinary(e,n,i):l.CtxReadPrivateKey(e,o)})).then((function(t){f.pkContext=t;var e=t.GetOwnerInfo();if(!a)return c.SetCMPSettings(e.GetIssuerCN());var n=c.GetCASettings(e.GetIssuerCN());if(!n||-1==n.issuerCNs.indexOf(a))throw l.MakeError(r.EU_ERROR_CERT_NOT_FOUND,"")})).then((function(){t(f.pkContext)})).catch((function(s){null==f.pkContext?c.MapError(s).code==r.EU_ERROR_CERT_NOT_FOUND&&!a&&u?c.SearchPrivateKeyCertificatesWithCMP(n,i,o).then((function(t){return c.CtxReadPrivateKeyInternal(e,n,i,o,t.certs,null,!1)})).then((function(e){t(e)})).catch((function(t){return _(c.MapError(t))})):_(c.MapError(s)):l.CtxFreePrivateKey(f.pkContext).then((function(){_(c.MapError(s))})).catch((function(){_(c.MapError(s))}))}))}))},e.prototype.ReadPrivateKeyInternal=function(e,n,r,i,s){var a=this;return new t((function(t,u){a.ResetPrivateKeyInternal().then((function(){return a.CtxReadPrivateKeyInternal(a.m_context,e,n,r,i,s,!0)})).then((function(e){a.m_pkContext=e;var n=l.a.MapEndUserOwnerInfo(e.GetOwnerInfo(),new o.a);t(n)})).catch((function(t){u(a.MapError(t))}))}))},e.prototype.ResetPrivateKeyInternal=function(){var e=this,n=this.m_library;return new t((function(t,r){null!=e.m_pkContext?n.CtxFreePrivateKey(e.m_pkContext).then((function(){e.m_pkContext=null,t()})).catch((function(t){return r(e.MapError(t))})):t()}))},e.prototype.SearchPrivateKeyCertificatesWithCMP=function(e,n,i,o){var s=this,a=s.m_library,u=s.m_settings.CAs;return new t((function(t,c){(null!=e&&null!=n?a.GetKeyInfoBinary(e,n):a.GetKeyInfo(i)).then((function(e){var n=function(i,l){if(i>=u.length){var f=a.MakeError(l?r.EU_ERROR_CERT_NOT_FOUND:r.EU_ERROR_TRANSMIT_REQUEST,"");c(s.MapError(f))}else{var p=o?_.EndUserCMPCompatibility.DownloadEUCerts:_.EndUserCMPCompatibility.SearchEUCerts;s.IsCMPCompatible(u[i],p)?o&&-1==u[i].issuerCNs.indexOf(o)?n(i+1,l):a.GetCertificatesByKeyInfo(e,[u[i].cmpAddress],["80"]).then((function(e){t({certs:e,CACommonName:u[i].issuerCNs[0]})})).catch((function(t){var e=t.GetErrorCode();e!=r.EU_ERROR_CERT_NOT_FOUND&&e!=r.EU_ERROR_TRANSMIT_REQUEST||(l=l||e==r.EU_ERROR_CERT_NOT_FOUND),n(i+1,l)})):n(i+1,l)}};n(0,!1)})).catch((function(t){return c(s.MapError(t))}))}))},e.prototype.GetUserCertificatesFromCertificates=function(e){var n=this,r=n.m_library;return new t((function(t,i){var o=new Array,s=function(a){r.GetCertificateFromSignedData(a,e).then((function(e){if(null!=e){var n=new u.EndUserCertificate;return n.data=e,o.push(n),r.ParseCertificateEx(e)}for(var i=new Array,s=0;s<o.length;s++){o[s].infoEx.subjType==r.EU_SUBJECT_TYPE_END_USER&&i.push(o[s])}t(i)})).then((function(t){o[a].infoEx=l.a.MapToEndUserCertificateInfoEx(t,new f.a),s(a+1)})).catch((function(t){return i(n.MapError(t))}))};s(0)}))},e.prototype.GeneratePrivateKeyInternal=function(e,n,r,i,o,s,a,u,c,f,_,p,h){var y=this,S=this.m_library;return new t((function(t,C){var d=null==e&&null==r,A=null!=r,R=S.CreatePrivateKeyInfo(),m=null;null!=p&&(m=l.a.MapFromEndUserInfo(p,S.CreateEndUserInfo())),S.GeneratePrivateKeyEx(d,e?e.GetTypeIndex():-1,e?e.GetDevIndex():-1,e?e.GetPassword():r,n,i,o,s,a,u,c,f,_,m,h,R,null!=r).then((function(e){for(var n=new Array,r=0;r<e.size();r++){var i=e.get(r);i=l.a.MapToEndUserRequestInfo(i,new E.a),n.push(i)}var o={key:A?R.GetPrivateKey():null,requests:n};t(o)})).catch((function(t){return C(y.MapError(t))}))}))},e.prototype.GetSignAlgoByCertificate=function(t){switch(t.GetInfoEx().GetPublicKeyType()){case _.EndUserCertKeyType.DSTU4145:return t.GetInfoEx().GetCertHashType()==_.EndUserCertHashType.GOST34311?_.EndUserSignAlgo.DSTU4145WithGOST34311:_.EndUserSignAlgo.DSTU4145WithDSTU7564;case _.EndUserCertKeyType.RSA:return _.EndUserSignAlgo.RSAWithSHA;case _.EndUserCertKeyType.ECDSA:return _.EndUserSignAlgo.ECDSAWithSHA;default:return _.EndUserSignAlgo.Unknown}},e.prototype.GetHashAlgoBySignAlgo=function(t){var e=this.m_library;switch(t){case _.EndUserSignAlgo.DSTU4145WithGOST34311:return _.EndUserHashAlgo.GOST34311;case _.EndUserSignAlgo.RSAWithSHA:case _.EndUserSignAlgo.ECDSAWithSHA:return _.EndUserHashAlgo.SHA256;case _.EndUserSignAlgo.DSTU4145WithDSTU7564:return _.EndUserHashAlgo.DSTU7564_256;default:throw e.MakeError(r.EU_ERROR_BAD_PARAMETER,"")}},e.prototype.CtxSignHashInternal=function(e,n,i,o,s,a){var u=this,c=this.m_library,l=null!=o,f=u.DataToNamedDataArray(i),_=u.DataToNamedDataArray(o);return new t((function(o,p){u.CheckInitialize().then((function(){if(null==e)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");if(l&&f.length!=_.length)throw c.MakeError(r.EU_ERROR_BAD_PARAMETER,"");for(var i=new Array,o=0;o<f.length;o++)i.push({hash:f[o],previousSign:l?_[o]:null});return u.ProcessArray(i,(function(r){return new t((function(t,i){(l?c.CtxAppendSignHash(e,n,r.hash.val,r.previousSign.val,s):c.CtxSignHash(e,n,r.hash.val,s)).then((function(t){return a?t:c.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return i(t)}))}))}))})).then((function(t){var e=u.DataToResult(i,t);o(e)})).catch((function(t){return p(u.MapError(t))}))}))},e.prototype.CtxSignDataInternal=function(e,n,i,o,s,a,u){var c=this,l=this,f=this.m_library,p=null!=o,h=l.DataToNamedDataArray(i),E=l.DataToNamedDataArray(o);return new t((function(y,S){l.CheckInitialize().then((function(){if(null==e)throw f.MakeError(r.EU_ERROR_BAD_CERT,"");if(p&&s&&h.length!=E.length)throw f.MakeError(r.EU_ERROR_BAD_PARAMETER,"");return n!=_.EndUserSignAlgo.Unknown?null:f.CtxEnumOwnCertificates(e,0)})).then((function(t){if(n==_.EndUserSignAlgo.Unknown&&null!=t&&(n=l.GetSignAlgoByCertificate(t)),!s)return h;var e=l.GetHashAlgoBySignAlgo(n);return l.HashData(e,h,!0)})).then((function(r){for(var i=new Array,o=p?E.length:r.length,c=0;c<o;c++)i.push({dataOrHash:null!=r?r[c]:null,previousSign:p?E[c]:null});return l.ProcessArray(i,(function(r){return new t((function(t,i){(p?s?f.CtxAppendSignHash(e,n,r.dataOrHash.val,r.previousSign.val,a):f.CtxAppendSign(e,n,null,r.previousSign.val,a):s?f.CtxSignHash(e,n,r.dataOrHash.val,a):f.CtxSign(e,n,r.dataOrHash.val,!1,a)).then((function(t){return u?t:f.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return i(t)}))}))}))})).then((function(t){var e=c.DataToResult(p&&!s?o:i,t);y(e)})).catch((function(t){return S(l.MapError(t))}))}))},e.prototype.LoadTaxReportPKey=function(e,n,i){var o=this,s=this.m_library;return new t((function(t,a){var u=new A;if(Array.isArray(e)||(e=[e]),e.length>2)a(o.MapError(s.MakeError(r.EU_ERROR_BAD_PARAMETER,"")));else{var c=function(l,f){var p=n[l],h=e[f];s.CtxGetOwnCertificate(h,_.EndUserCertKeyType.DSTU4145,p).then((function(e){if(i&&p&_.EndUserKeyUsage.DigitalSignature&&!(e.GetInfoEx().GetExtKeyUsages().indexOf(s.EU_UA_OID_EXT_KEY_USAGE_STAMP)>-1))throw s.MakeError(r.EU_ERROR_BAD_PARAMETER,"");if(p&_.EndUserKeyUsage.DigitalSignature)u.signPKCtx=h,u.signCert=e;else{if(!(p&_.EndUserKeyUsage.KeyAgreement))throw s.MakeError(r.EU_ERROR_BAD_PARAMETER,"");u.envelopPKCtx=h,u.envelopCert=e}l+1<n.length?c(l+1,0):t(u)})).catch((function(t){if(t.GetErrorCode()==r.EU_ERROR_CERT_NOT_FOUND){if(f+1<e.length)return void c(l,f+1);t=s.MakeError(r.EU_ERROR_BAD_PARAMETER,"")}a(o.MapError(t))}))};c(0,0)}}))},e.prototype.ProtectTaxReport=function(e,n,i,o,s,a,u){var c=this,l=this.m_library,f=new p.b;f.name=a.name;var _=function(e,n){return new t((function(t,r){return l.CtxSign(e.signPKCtx,c.GetSignAlgoByCertificate(e.signCert),n,!1,!0).then((function(t){return l.BASE64Decode(t)})).then((function(t){return l.AppendCryptoHeader(l.EU_HEADER_CA_TYPE,l.EU_HEADER_PART_TYPE_SIGNED,t)})).then((function(e){t(e)})).catch((function(t){return r(c.MapError(t))}))}))},h=function(e,n){return new t((function(r,i){return l.CtxEnvelop(e.envelopPKCtx,[s],l.EU_RECIPIENT_APPEND_ISSUER_AND_SERIAL,!1,!1,n).then((function(t){return l.BASE64Decode(t)})).then((function(t){return l.AppendCryptoHeader(l.EU_HEADER_CA_TYPE,l.EU_HEADER_PART_TYPE_ENCRYPTED,t)})).then((function(n){var r=e.envelopCert,i=l.EU_KEY_USAGE_DIGITAL_SIGNATURE|l.EU_KEY_USAGE_KEY_AGREEMENT;return i==(r.GetInfoEx().GetKeyUsageType()&i)?n:function(e,n){return new t((function(t,r){return l.AppendCryptoHeader(l.EU_HEADER_CA_TYPE,l.EU_HEADER_PART_TYPE_CERTCRYPT,e).then((function(e){var r=new Uint8Array(e.byteLength+n.byteLength);r.set(new Uint8Array(e),0),r.set(new Uint8Array(n),e.byteLength),t(r)})).catch((function(t){return r(c.MapError(t))}))}))}(r.GetData(),n)})).then((function(t){return _(e,t)})).then((function(t){r({reportData:t,ownCert:e.envelopCert.GetData()})})).catch((function(t){return i(c.MapError(t))}))}))};return new t((function(s,p){new t((function(t,e){t(a.data)})).then((function(t){return null!=e?_(e,t):t})).then((function(t){return null!=n?_(n,t):t})).then((function(t){return null!=i?_(i,t):t})).then((function(t){return u&&(f.signedData=t),null!=n||null!=i?h(null!=i?i:n,t):{reportData:t,ownCert:e.signCert.GetData()}})).then((function(t){return l.AppendTransportHeader(l.EU_HEADER_CA_TYPE,a.name,o,t.ownCert,t.reportData)})).then((function(t){f.data=t,f.error=c.MapError(l.MakeError(r.EU_ERROR_NONE,"")),s(f)})).catch((function(t){f.error=c.MapError(t),s(f)}))}))},e.prototype.UnprotectTaxReceipt=function(e,n){var i=this,o=this.m_library,s=new p.a;s.data=null,s.receiptNumber=0,s.initiators=[],s.error=null;return new t((function(a,u){var c;(c=n.data,new t((function(t,e){o.ParseTransportHeader(c).then((function(e){s.receiptNumber=e.GetReceiptNumber(),t(e.GetCryptoData())})).catch((function(n){n.GetErrorCode()==r.EU_ERROR_PKI_FORMATS_FAILED?t(c):e(i.MapError(n))}))}))).then((function(n){var c=function(n){(function(n){var a={headerInfo:null};return new t((function(t,u){o.ParseCryptoHeader(n).then((function(t){a.headerInfo=t;var n=t.GetCryptoData();switch(t.GetHeaderType()){case o.EU_HEADER_PART_TYPE_SIGNED:return o.VerifyDataInternalOnTimeEx(n,0,null,!1,!1);case o.EU_HEADER_PART_TYPE_ENCRYPTED:return o.CtxDevelop(e,n);case o.EU_HEADER_PART_TYPE_STAMPED:case o.EU_HEADER_PART_TYPE_CERTCRYPT:return null;default:throw o.MakeError(r.EU_ERROR_PKI_FORMATS_FAILED,"")}})).then((function(e){if(null!=e){var r=a.headerInfo.GetHeaderType()==o.EU_HEADER_PART_TYPE_SIGNED?l.a.MapToEndUserSignInfo(e,new S.a):l.a.MapToEndUserSenderInfo(e,new C.a);s.initiators.push(r),n=e.GetData()}else n=n.slice(a.headerInfo.GetHeaderSize()+a.headerInfo.GetCryptoData().length,n.length);t(n)})).catch((function(e){e.GetErrorCode()==r.EU_ERROR_BAD_PARAMETER?t(null):u(i.MapError(e))}))}))})(n).then((function(t){if(null==t)return s.data=n,s.error=i.MapError(o.MakeError(r.EU_ERROR_NONE,"")),void a(s);c(t)})).catch((function(t){return u(i.MapError(t))}))};c(n)})).catch((function(t){return u(i.MapError(t))}))}))},e.prototype.GetKSPSettings=function(t){var e;if(!this.m_settings.KSPs)return null;if("string"==typeof t){for(e=0;e<this.m_settings.KSPs.length;e++)if(this.m_settings.KSPs[e].name==t)return this.m_settings.KSPs[e];return null}if("number"==typeof t){for(e=0;e<this.m_settings.KSPs.length;e++)if(this.m_settings.KSPs[e].ksp==t)return this.m_settings.KSPs[e];return null}return null},e.prototype.GetPollingInterval=function(t){return t&&"number"==typeof t.pollingInterval?1e3*t.pollingInterval:1e3},e.prototype.MakeNewCertificateKSP=function(e,n,i,o,s,a,c,f,_,p,h,E,y,S,C,d,A,R){void 0===d&&(d=!1),void 0===A&&(A=null),void 0===R&&(R=null);var m=this,T=m.m_library,g={kspSettings:null,userId:null,operationId:null},P={key:null,certs:null};return new t((function(f,h){m.CheckInitialize().then((function(){return m.BeginKMOperation()})).then((function(){var t=null;return null!=e&&(t=l.a.MapFromKeyMedia(e,T.CreateKeyMedia())),d?null:m.ReadPrivateKeyInternal(n,i,t,null,S)})).then((function(t){return C&&!d?T.CtxGetOwnEUserParams(m.m_pkContext):null})).then((function(t){return C?T.CtxModifyOwnEUserParams(m.m_pkContext,C.phone,C.EMail):null})).then((function(){if(g.userId=A,g.kspSettings=m.GetKSPSettings(R),!g.kspSettings||!g.kspSettings.address)throw T.MakeError(r.EU_ERROR_BAD_PARAMETER,"");var t=[];t[T.EU_KEYS_TYPE_DSTU_AND_ECDH_WITH_GOSTS]="DSTU4145",t[T.EU_KEYS_TYPE_RSA_WITH_SHA]="RSA",s!=T.EU_KEYS_LENGTH_DS_UA_FILE&&s!=T.EU_KEYS_LENGTH_DS_UA_CERT||(s=T.EU_KEYS_LENGTH_DS_UA_257),c!=T.EU_KEYS_LENGTH_KEP_UA_FILE&&c!=T.EU_KEYS_LENGTH_KEP_UA_CERT||(c=T.EU_KEYS_LENGTH_KEP_UA_431),p!=T.EU_KEYS_LENGTH_DS_RSA_FILE&&p!=T.EU_KEYS_LENGTH_DS_RSA_CERT||(p=T.EU_KEYS_LENGTH_DS_RSA_2048);var e=[];e[T.EU_KEYS_LENGTH_DS_UA_191]=191,e[T.EU_KEYS_LENGTH_DS_UA_257]=257,e[T.EU_KEYS_LENGTH_DS_UA_307]=307;var n=[];n[T.EU_KEYS_LENGTH_KEP_UA_257]=257,n[T.EU_KEYS_LENGTH_KEP_UA_431]=431,n[T.EU_KEYS_LENGTH_KEP_UA_571]=571;var i=[];i[T.EU_KEYS_LENGTH_DS_RSA_1024]=1024,i[T.EU_KEYS_LENGTH_DS_RSA_2048]=2048,i[T.EU_KEYS_LENGTH_DS_RSA_3072]=3072,i[T.EU_KEYS_LENGTH_DS_RSA_4096]=4096;var u=t[o]||null,l=e[s]||0,f=n[c]||0,h=t[_]||null,E=i[p]||0,y="Веб-сайт: %s".replace("%s",g.kspSettings.systemId||m.m_origin),S="Генерація ос. ключа у системі %s".replace("%s",g.kspSettings.systemId||m.m_origin);return T.SServerClientGeneratePrivateKeyAsync(g.kspSettings.address,g.kspSettings.port,g.userId,y,S,u,l,a,f,h,E)})).then((function(e){g.operationId=e;var n=m.GetPollingInterval(g.kspSettings),i=m.MakeExpireDate(300);return new t((function(t,e){var o=function(i){new Date>i?e(T.MakeError(r.EU_ERROR_TRANSMIT_REQUEST,"")):m.m_library.SServerClientCheckGeneratePrivateKeyStatus(g.kspSettings.address,g.kspSettings.port,g.userId,g.operationId).then((function(e){null!=e?t(e):setTimeout((function(){o(i)}),n)})).catch((function(t){e(m.MapError(t))}))};o(i)}))})).then((function(t){for(var e=null,n=null,r=null,i=0;i<t.size();i++){var o=t.get(i);switch(o.GetRequestType()){case T.EU_KEYS_REQUEST_TYPE_UA_DS:e=o.GetRequest();break;case T.EU_KEYS_REQUEST_TYPE_UA_KEP:n=o.GetRequest();break;case T.EU_KEYS_REQUEST_TYPE_INTERNATIONAL:r=o.GetRequest()}}return m.m_library.CtxMakeNewOwnCertificateWithCR(m.m_pkContext,e,n,r,null)})).then((function(){var t="Веб-сайт: %s".replace("%s",g.kspSettings.systemId||m.m_origin),e="Ідентифікація клієнта у системі %s".replace("%s",g.kspSettings.systemId||m.m_origin);return T.SServerClientSignHashesAsync(g.kspSettings.address,g.kspSettings.port,g.userId,t,e,["Зчитування ос. ключа"],["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="],"DSTU4145")})).then((function(e){g.operationId=e;var n=m.GetPollingInterval(g.kspSettings),i=m.MakeExpireDate(300);return new t((function(t,e){var o=function(i){new Date>i?e(T.MakeError(r.EU_ERROR_TRANSMIT_REQUEST,"")):T.SServerClientCheckSignHashesStatus(g.kspSettings.address,g.kspSettings.port,g.userId,g.operationId).then((function(s){if(null!=s)if(1==s.size()){var a=s.get(0);if(a.GetError()==r.EU_ERROR_NONE){var c=a.GetSignature(),f=new u.EndUserCertificate;T.CtxGetSignerInfo(m.m_context,0,c).then((function(e){l.a.MapToEndUserCertificate(e,f),t([f])})).catch((function(t){return e(m.MapError(t))}))}else e(T.MakeError(a.GetError(),a.GetStatus()))}else e(T.MakeError(r.EU_ERROR_PKI_FORMATS_FAILED,""));else setTimeout((function(){o(i)}),n)})).catch((function(t){e(m.MapError(t))}))};o(i)}))})).then((function(t){m.EndKMOperation(),P.certs=t,f(P)})).catch((function(t){m.ResetPrivateKeyInternal().then((function(){m.EndKMOperation(),h(m.MapError(t))})).catch((function(){m.EndKMOperation(),h(m.MapError(t))}))}))}))},e.prototype.AddEventListener=function(e,n){var i=this,o=i.m_library;return new t((function(t,s){if([_.EndUserEventType.None,_.EndUserEventType.All,_.EndUserEventType.ConfirmKSPOperation].indexOf(e)<0)s(i.MapError(o.MakeError(r.EU_ERROR_BAD_PARAMETER,"")));else{switch(e){case _.EndUserEventType.None:i.m_eventListeners=[];break;case _.EndUserEventType.All:i.m_eventListeners=[],i.m_eventListeners[e]=n;break;default:i.m_eventListeners[e]=n}t()}}))},e.prototype.GetLibraryInfo=function(e){var n=this,r=this.m_library;return new t((function(t,i){var o=new c.b;o.supported=r.IsSupported(),o.isSignAgentSupported=r.IsSignAgentSupported(),o.isWebExtensionSupported=r.IsWebExtensionSupported(),o.isNPAPISupported=r.IsNPAPISupported(),o.isActiveXSupported=r.IsActiveXSupported(),o.isWebExtensionInstalled=r.IsWebExtensionInstalled(),o.nativeLibraryInstallURLs=r.GetInstallURL(!0,e),o.nativeLibraryInstallURL=o.nativeLibraryInstallURLs?o.nativeLibraryInstallURLs[0]:null,o.nativeLibraryUpdateURLs=r.GetUpdateURL(!0,e),o.nativeLibraryUpdateURL=o.nativeLibraryUpdateURLs?o.nativeLibraryUpdateURLs[0]:null,o.webExtensionInstallURL=r.GetWebExtensionInstallURL(),o.helpURL=r.GetHelpURL(e),o.supported?r.Load().then((function(){o.loaded=!0,r.GetVersion().then((function(e){o.version=e,t(o)})).catch((function(t){return i(n.MapError(t))}))})).catch((function(e){var i=n.MapError(e);o.loaded=!1,o.isNativeLibraryNeedUpdate=r.IsLibraryVersionNotSupportedError(i.code),t(o)})):t(o)}))},e.prototype.IsInitialized=function(){var e=this;return new t((function(t,n){t(e.m_initialized)}))},e.prototype.Initialize=function(e){var n=this,r=n.m_library;n.m_settings=e;var i={offline:!0,tspSettings:null,useOCSP:!1};return new t((function(t,o){r.Load().then((function(){return r.SetRuntimeParameter(r.EU_SAVE_SETTINGS_PARAMETER,r.EU_SETTINGS_ID_PROXY)})).then((function(){return r.SetUIMode(!1)})).then((function(){return r.Initialize()})).then((function(){return r.SetUIMode(!1)})).then((function(){return r.SetCharset(n.m_settings.encoding)})).then((function(){return r.SetLanguage(n.m_settings.language)})).then((function(){return r.InitializeMandatorySettings()})).then((function(){var t=r.CreateFileStoreSettings();return t.SetPath(""),t.SetSaveLoadedCerts(!0),r.SetFileStoreSettings(t)})).then((function(){return null!=n.m_settings.CAs&&"string"==typeof n.m_settings.CAs?r.DownloadData(n.m_settings.CAs,"json"):n.m_settings.CAs})).then((function(t){n.m_settings.CAs=t,i.tspSettings=n.GetDefaultTSPSettings();for(var e=0;e<t.length;e++)if(t[e].ocspAccessPointAddress&&t[e].ocspAccessPointPort){i.useOCSP=!0;break}i.offline=!i.tspSettings&&!i.useOCSP;var o=r.CreateModeSettings();return o.SetOfflineMode(i.offline),r.SetModeSettings(o)})).then((function(){var t=r.CreateTSPSettings();return t.SetGetStamps(!!i.tspSettings),i.tspSettings&&(t.SetAddress(i.tspSettings.tspAddress),t.SetPort(i.tspSettings.tspAddressPort)),r.SetTSPSettings(t)})).then((function(){var t=r.CreateOCSPSettings();return t.SetUseOCSP(i.useOCSP),i.useOCSP&&(t.SetBeforeStore(!0),t.SetAddress("czo.gov.ua"),t.SetPort("80")),r.SetOCSPSettings(t)})).then((function(){var t=r.CreateOCSPAccessInfoModeSettings();return t.SetEnabled(i.useOCSP),r.SetOCSPAccessInfoModeSettings(t)})).then((function(){if(i.useOCSP){for(var t=new Array,e=n.m_settings.CAs,o=0;o<e.length;o++)for(var s=0;s<e[o].issuerCNs.length;s++){var a=r.CreateOCSPAccessInfoSettings();a.SetAddress(e[o].ocspAccessPointAddress),a.SetPort(e[o].ocspAccessPointPort),a.SetIssuerCN(e[o].issuerCNs[s]),t.push(a)}return r.SetOCSPAccessInfoSettings(t)}})).then((function(){return null!=e.CACertificates&&"string"==typeof e.CACertificates?r.DownloadData(e.CACertificates,"binary"):e.CACertificates})).then((function(t){if(null!=e.CACertificates)return r.SaveCertificates(t)})).then((function(){var t=!!e.TSLAddress,n=r.CreateTSLSettings();return n.SetUseTSL(t),n.SetAutoDownloadTSL(!!t),n.SetTSLAddress(t?e.TSLAddress:""),r.SetTSLSettings(n)})).then((function(){return r.SetRuntimeParameter(r.EU_RESOLVE_OIDS_PARAMETER,n.m_resolveOIDs)})).then((function(){if("number"==typeof n.m_settings.connectionTimeout)return r.SetRuntimeParameter(r.EU_CONNECTIONS_TIMEOUT_PARAMETER,n.m_settings.connectionTimeout)})).then((function(){if("number"==typeof e.ocspResponseExpireTime)return r.SetOCSPResponseExpireTime(n.m_settings.ocspResponseExpireTime)})).then((function(){return r.CtxCreate()})).then((function(t){return n.m_context=t,r.CtxSetParameter(t,r.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,n.m_resolveOIDs)})).then((function(){return r.SetRuntimeParameter(r.EU_CHECK_CERT_CHAIN_ON_SIGN_TIME_PARAMETER,!0)})).then((function(){return null!=n.m_settings.signInfoTmpl&&"string"==typeof n.m_settings.signInfoTmpl?r.DownloadData(n.m_settings.signInfoTmpl,""):n.m_settings.signInfoTmpl})).then((function(e){n.m_settings.signInfoTmpl=e,n.m_initialized=!0,t()})).catch((function(t){return o(n.MapError(t))}))}))},e.prototype.SetLanguage=function(e){var n=this,r=n.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){return r.SetLanguage(e)})).then((function(){n.m_settings.language=e})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.SetRuntimeParameter=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return i.SetRuntimeParameter(e,n)})).then((function(){return e!=i.EU_USE_SLOGIN_PRIVATE_KEY?null:i.CtxSetParameter(r.m_context,e,n)})).then((function(){t()})).catch((function(t){return o(r.MapError(t))}))}))},e.prototype.GetStorageParameter=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return i.GetStorageParameter(n,e)})).then((function(e){t(e)})).catch((function(t){return o(r.MapError(t))}))}))},e.prototype.SetStorageParameter=function(e,n,r){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.SetStorageParameter(r,e,n)})).then((function(){t()})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.GetCAs=function(){var e=this;return new t((function(t,n){e.CheckInitialize().then((function(){t(e.m_settings.CAs)})).catch((function(t){return n(e.MapError(t))}))}))},e.prototype.GetProxySettings=function(){var e=this,n=e.m_library;return new t((function(t,r){e.CheckInitialize().then((function(){return n.GetProxySettings()})).then((function(e){var n=l.a.MapToProxySettings(e,new i.b);t(n)})).catch((function(t){return r(e.MapError(t))}))}))},e.prototype.SetProxySettings=function(e){var n=this,r=n.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){var t=l.a.MapFromProxySettings(e,r.CreateProxySettings());return r.SetProxySettings(t)})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.GetHostInfo=function(){var e=this,n=e.m_library;return new t((function(t,r){e.CheckInitialize().then((function(){return n.GetHostInfo()})).then((function(e){t(e)})).catch((function(t){return r(e.MapError(t))}))}))},e.prototype.GetKeyMedias=function(){var e=this,n=e.m_library,r=new Array,i=null;return e.m_settings.allowedKeyMediaDevices&&(i={},e.m_settings.allowedKeyMediaDevices.forEach((function(t){i[t.type]=t.devices}))),new t((function(t,o){e.CheckInitialize().then((function(){return e.BeginKMOperation()})).then((function(){return e.m_kmTypes?e.m_kmTypes:n.GetKeyMediaTypes()})).then((function(t){e.m_kmTypes=t;var i=e.m_settings.allowedKeyMediaTypes;r=new Array;for(var o=0;o<t.length;o++){var s=t[o];(!i||i.indexOf(s)>=0)&&r.push(o)}return n.GetKeyMediaDevices(r)})).then((function(n){for(var o=new Array,s=0;s<n.length;s++)for(var a=r[s],c=e.m_kmTypes[a],l=n[s],f=i&&i[c]?i[c]:null,_=0;_<l.length;_++)if(!f||-1!=f.indexOf(l[_])){var p=new u.EndUserKeyMedia;p.typeIndex=a,p.devIndex=_,p.password=null,p.type=c,p.device=l[_],p.visibleName=p.device+"("+p.type+")",o.push(p)}e.EndKMOperation(),t(o)})).catch((function(t){e.EndKMOperation(),o(e.MapError(t))}))}))},e.prototype.GetJKSPrivateKeys=function(e){var n=this;return new t((function(t,r){n.CheckInitialize().then((function(){var i=new Array,o=function(s){n.GetJKSPrivateKey(e,s).then((function(e){e?(i.push(e),o(s+1)):t(i)})).catch((function(t){return r(n.MapError(t))}))};o(0)})).catch((function(t){return r(n.MapError(t))}))}))},e.prototype.IsPrivateKeyReaded=function(){var e=this;return new t((function(t,n){e.CheckInitialize().then((function(){t(null!=e.m_pkContext)})).catch((function(t){return n(e.MapError(t))}))}))},e.prototype.ResetPrivateKey=function(){var e=this;return new t((function(t,n){e.CheckInitialize().then((function(){return e.ResetPrivateKeyInternal()})).then((function(){t()})).catch((function(t){return n(e.MapError(t))}))}))},e.prototype.ResetOperationKSP=function(){var e=this,n=this.m_library;return new t((function(t,i){e.CheckInitialize().then((function(){throw n.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.ReadPrivateKey=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){i.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(e,o.CreateKeyMedia());return i.ReadPrivateKeyInternal(null,null,t,n,r)})).then((function(e){i.EndKMOperation(),t(e)})).catch((function(t){i.EndKMOperation(),s(i.MapError(t))}))}))},e.prototype.ReadPrivateKeyBinary=function(e,n,r,i){var o=this;return new t((function(t,s){o.CheckInitialize().then((function(){return o.ReadPrivateKeyInternal(e,n,null,r,i)})).then((function(e){t(e)})).catch((function(t){return s(o.MapError(t))}))}))},e.prototype.ReadPrivateKeySIM=function(e,n,i,o){var s=this,a=this.m_library;return new t((function(t,e){s.CheckInitialize().then((function(){throw a.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){return e(s.MapError(t))}))}))},e.prototype.ReadPrivateKeyKSP=function(e,n,i,o,s,a){var u=this,c=this.m_library;return new t((function(t,e){u.CheckInitialize().then((function(){throw c.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){return e(u.MapError(t))}))}))},e.prototype.GetOwnCertificates=function(){return this.CtxGetOwnCertificates(this.m_pkContext)},e.prototype.GetOwnEUserParams=function(){var e=this,n=e.m_library;return new t((function(t,i){e.CheckInitialize().then((function(){if(null==e.m_pkContext)throw n.MakeError(r.EU_ERROR_BAD_CERT,"");return n.CtxGetOwnEUserParams(e.m_pkContext)})).then((function(e){var n=l.a.MapToEndUserParams(e,new h.a);t(n)})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.ChangeOwnCertificatesStatus=function(e,n){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){if(null==i.m_pkContext)throw o.MakeError(r.EU_ERROR_BAD_CERT,"");return o.CtxChangeOwnCertificatesStatus(i.m_pkContext,e,n)})).then((function(){t()})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.MakeNewCertificate=function(e,n,r,i,o,s,a,u,c,f,_,p,h,E,y,S,C,d){void 0===S&&(S=!1),void 0===C&&(C=null),void 0===d&&(d=null);var A=this,R=A.m_library,m={key:null,certs:null};return null!=C||null!=d?A.MakeNewCertificateKSP(e,n,r,i,o,s,a,u,c,f,_,p,h,E,y,S,C,d):new t((function(C,d){A.CheckInitialize().then((function(){return A.BeginKMOperation()})).then((function(){var t=null;return null!=e&&(t=l.a.MapFromKeyMedia(e,R.CreateKeyMedia())),S?null:A.ReadPrivateKeyInternal(n,r,t,null,E)})).then((function(t){return y&&!S?R.CtxGetOwnEUserParams(A.m_pkContext):null})).then((function(t){return y?R.CtxModifyOwnEUserParams(A.m_pkContext,y.phone,y.EMail):null})).then((function(){return S?null:A.ResetPrivateKeyInternal()})).then((function(){if(S)return new t((function(t,n){R.CtxMakeNewOwnCertificate(A.m_pkContext,i,o,s,a,u,c,f,_).then((function(){return A.ResetPrivateKeyInternal()})).then((function(){var t=l.a.MapFromKeyMedia(e,R.CreateKeyMedia());return p&&p.password!=e.password?R.ChangePrivateKeyPassword(t,p.password):null})).then((function(){t(null)})).catch((function(t){n(A.MapError(t))}))}));var E=null,y=null;return e&&(E=l.a.MapFromKeyMedia(e,R.CreateKeyMedia())),p&&(y=l.a.MapFromKeyMedia(p,R.CreateKeyMedia())),R.MakeNewCertificate(E,n,r,i,o,s,a,u,c,f,_,y,h)})).then((function(t){m.key=t;var n=null;return(S&&e||p)&&(n=l.a.MapFromKeyMedia(p||e,R.CreateKeyMedia())),A.SearchPrivateKeyCertificatesWithCMP(t,h,n,E)})).then((function(t){return A.GetUserCertificatesFromCertificates(t.certs)})).then((function(t){A.EndKMOperation(),m.certs=t,C(m)})).catch((function(t){A.EndKMOperation(),d(A.MapError(t))}))}))},e.prototype.MakeDeviceCertificate=function(e,n,i,o,s){var a=this,c=a.m_library;return new t((function(_,p){a.CheckInitialize().then((function(){if(null==a.m_pkContext)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");var t=a.m_pkContext.GetOwnerInfo(),u=a.GetCASettings(t.GetIssuerCN());if(!u||!u.cmpAddress||""==u.cmpAddress)throw c.MakeError(r.EU_ERROR_BAD_PARAMETER,"");return c.CtxMakeDeviceCertificate(a.m_pkContext,e,n,i,o,s,u.cmpAddress,"80")})).then((function(e){return a.ProcessArray(e,(function(e){return new t((function(t,n){c.ParseCertificateEx(e).then((function(n){var r=new u.EndUserCertificate;r.data=e,r.infoEx=l.a.MapToEndUserCertificateInfoEx(n,new f.a),t(r)})).catch((function(t){return n(t)}))}))}))})).then((function(t){_(t)})).catch((function(t){a.EndKMOperation(),p(a.MapError(t))}))}))},e.prototype.SetKeyMediaUserPassword=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return r.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(n,i.CreateKeyMedia());return r.m_library.SetKeyMediaUserPassword(e,t)})).then((function(){r.EndKMOperation(),t()})).catch((function(t){r.EndKMOperation(),o(r.MapError(t))}))}))},e.prototype.ChangePrivateKeyPassword=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return r.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(e,i.CreateKeyMedia());return r.m_library.ChangePrivateKeyPassword(t,n)})).then((function(){r.EndKMOperation(),t()})).catch((function(t){r.EndKMOperation(),o(r.MapError(t))}))}))},e.prototype.ChangePrivateKeyPasswordBinary=function(e,n,r){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.ChangeSoftwarePrivateKeyPassword(e,n,r)})).then((function(e){t(e),t()})).catch((function(t){s(i.MapError(t))}))}))},e.prototype.GeneratePrivateKey=function(e,n,r,i,o,s,a,u,c,f,_,p){var h=this,E=h.m_library;return new t((function(t,y){h.CheckInitialize().then((function(){return h.BeginKMOperation()})).then((function(){var t=null;return e&&(t=l.a.MapFromKeyMedia(e,E.CreateKeyMedia())),h.GeneratePrivateKeyInternal(t,n,null,r,i,o,s,a,u,c,f,_,p)})).then((function(e){h.EndKMOperation(),t(e)})).catch((function(t){h.EndKMOperation(),y(h.MapError(t))}))}))},e.prototype.GeneratePrivateKeyBinary=function(e,n,r,i,o,s,a,u,c,l,f){var _=this;return new t((function(t,p){_.CheckInitialize().then((function(){return _.BeginKMOperation()})).then((function(){return _.GeneratePrivateKeyInternal(null,!1,e,n,r,i,o,s,a,u,c,l,f)})).then((function(e){_.EndKMOperation(),t(e)})).catch((function(t){_.EndKMOperation(),p(_.MapError(t))}))}))},e.prototype.GetKeyInfo=function(e){var n=this,r=n.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){return n.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(e,r.CreateKeyMedia());return r.GetKeyInfo(t)})).then((function(e){n.EndKMOperation(),t(e.GetPrivateKeyInfo())})).catch((function(t){n.EndKMOperation(),i(n.MapError(t))}))}))},e.prototype.GetKeyInfoBinary=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return i.GetKeyInfoBinary(e,n)})).then((function(e){t(e.GetPrivateKeyInfo())})).catch((function(t){o(r.MapError(t))}))}))},e.prototype.GetClientRegistrationTokenKSP=function(e,n){var i=this,o=i.m_library;return new t((function(t,e){i.CheckInitialize().then((function(){throw o.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){e(i.MapError(t))}))}))},e.prototype.HashData=function(e,n,r){var i=this,o=this.m_library,s=i.DataToNamedDataArray(n);return new t((function(a,u){i.CheckInitialize().then((function(){return i.ProcessArray(s,(function(n){return new t((function(t,s){o.CtxHash(i.m_context,e,null,n.val).then((function(t){return r?t:o.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return s(t)}))}))}))})).then((function(t){var e=i.DataToResult(n,t);a(e)})).catch((function(t){u(i.MapError(t))}))}))},e.prototype.GetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.GetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){s.context=null,a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context?o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))})):c(i.MapError(t))}))}))},e.prototype.SignData=function(t,e){return void 0===e&&(e=!1),this.SignDataEx(_.EndUserSignAlgo.Unknown,t,!0,!0,e)},e.prototype.SignDataInternal=function(t,e,n){return void 0===n&&(n=!1),this.SignDataEx(_.EndUserSignAlgo.Unknown,e,!1,t,n)},e.prototype.SignHash=function(t,e,n,r){return this.CtxSignHashInternal(this.m_pkContext,t,e,null,n,r)},e.prototype.SignDataEx=function(t,e,n,r,i){return this.CtxSignDataInternal(this.m_pkContext,t,e,null,n,r,i)},e.prototype.AppendSign=function(t,e,n,r,i){return this.CtxSignDataInternal(this.m_pkContext,t,e,n,null!=e,r,i)},e.prototype.AppendSignHash=function(t,e,n,r,i){return this.CtxSignHashInternal(this.m_pkContext,t,e,n,r,i)},e.prototype.GetSignValue=function(t,e,n,r){return void 0===r&&(r=!1),this.CtxGetSignValue(this.m_pkContext,t,e,n,r)},e.prototype.VerifyHash=function(e,n,r){void 0===r&&(r=-1);var i=this,o=this.m_library;return new t((function(s,a){i.CheckInitialize().then((function(){return-1==r?o.GetSignsCount(n):1})).then((function(s){var a=new Array;if(-1!=r)a.push(r);else for(var u=0;u<s;u++)a.push(u);return i.ProcessArray(a,(function(r){return new t((function(t,s){var a=new S.a;o.VerifyHashOnTimeEx(e,r,n,null,!1,!1).then((function(t){return l.a.MapToEndUserSignInfo(t,a),o.GetSignTimeInfo(r,n)})).then((function(t){return a.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),o.GetSignType(r,n)})).then((function(e){a.signLevel=e,t(a)})).catch((function(t){return s(i.MapError(t))}))}))}))})).then((function(t){s(-1!=r?t[0]:t)})).catch((function(t){return a(i.MapError(t))}))}))},e.prototype.VerifyData=function(e,n,r){void 0===r&&(r=-1);var i=this,o=this.m_library;return new t((function(s,a){i.CheckInitialize().then((function(){return-1==r?o.GetSignsCount(n):1})).then((function(s){var a=new Array;if(-1!=r)a.push(r);else for(var u=0;u<s;u++)a.push(u);return i.ProcessArray(a,(function(r){return new t((function(t,s){var a=new S.a;o.VerifyDataOnTimeEx(e,r,n,null,!1,!1).then((function(t){return l.a.MapToEndUserSignInfo(t,a),o.GetSignTimeInfo(r,n)})).then((function(t){return a.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),o.GetSignType(r,n)})).then((function(e){a.signLevel=e,t(a)})).catch((function(t){return s(i.MapError(t))}))}))}))})).then((function(t){s(-1!=r?t[0]:t)})).catch((function(t){return a(i.MapError(t))}))}))},e.prototype.VerifyDataInternal=function(e,n){void 0===n&&(n=-1);var r=this,i=this.m_library;return new t((function(o,s){r.CheckInitialize().then((function(){return-1==n?i.GetSignsCount(e):1})).then((function(o){var s=new Array;if(-1!=n)s.push(n);else for(var a=0;a<o;a++)s.push(a);return r.ProcessArray(s,(function(n){return new t((function(t,o){var s=new S.a;i.VerifyDataInternalOnTimeEx(e,n,null,!1,!1).then((function(t){return l.a.MapToEndUserSignInfo(t,s),i.GetSignTimeInfo(n,e)})).then((function(t){return s.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),i.GetSignType(n,e)})).then((function(e){s.signLevel=e,t(s)})).catch((function(t){return o(r.MapError(t))}))}))}))})).then((function(t){o(-1!=n?t[0]:t)})).catch((function(t){return s(r.MapError(t))}))}))},e.prototype.EnvelopData=function(e,n,i,o,s,a){void 0===a&&(a=!1);var u=this,c=this.m_library;return new t((function(t,l){u.CheckInitialize().then((function(){if(null==u.m_pkContext&&(!a||i))throw c.MakeError(r.EU_ERROR_BAD_CERT,"");var t=c.EU_RECIPIENT_APPEND_TYPE_BY_ISSUER_SERIAL;return a?i?c.CtxEnvelopWithDynamicKey(u.m_pkContext,e,t,i,o,n):c.EnvelopToRecipientsWithDynamicKey(e,i,o,n):c.CtxEnvelop(u.m_pkContext,e,t,i,o,n)})).then((function(t){return s?t:c.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return l(u.MapError(t))}))}))},e.prototype.DevelopData=function(e,n){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){if(null==i.m_pkContext)throw o.MakeError(r.EU_ERROR_BAD_CERT,"");return o.CtxDevelop(i.m_pkContext,e,n)})).then((function(e){var n=l.a.MapToEndUserSenderInfo(e,new C.a);t(n)})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.ProtectDataByPassword=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.ProtectDataByPassword(e,n)})).then((function(t){return r?t:o.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.UnprotectDataByPassword=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.UnprotectDataByPassword(e,n)})).then((function(t){return r?o.BytesToString(t):t})).then((function(e){t(e)})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.CreateAuthData=function(e,n,i){var o=this,s=this.m_library;return new t((function(t,a){o.CheckInitialize().then((function(){if(null==o.m_pkContext)throw s.MakeError(r.EU_ERROR_BAD_CERT,"");return s.CtxCreateAuthData(o.m_pkContext,e,n)})).then((function(t){return i?t:s.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return a(o.MapError(t))}))}))},e.prototype.GetTSPByAccessInfo=function(e,n,r,i,o){var s=this,a=this.m_library;return new t((function(t,u){s.CheckInitialize().then((function(){return a.GetTSPByAccessInfo(e,n,r,i)})).then((function(t){return o?a.BASE64Encode(t):t})).then((function(e){t(e)})).catch((function(t){return u(s.MapError(t))}))}))},e.prototype.CheckTSP=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.CheckTSP(e,n,r)})).then((function(){t()})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.CtxCreate=function(){var e=this,n=this.m_library,r={context:null};return new t((function(t,i){e.CheckInitialize().then((function(){return n.CtxCreate()})).then((function(t){return r.context=t,n.CtxSetParameter(t,n.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,e.m_resolveOIDs)})).then((function(){t(r.context)})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.CtxFree=function(e){var n=this,r=this.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){r.CtxFree(e)})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.CtxSetParameter=function(e,n,r){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return null==e&&(e=i.m_context),o.CtxSetParameter(e,n,r)})).then((function(){t()})).catch((function(t){i.EndKMOperation(),s(i.MapError(t))}))}))},e.prototype.CtxReadPrivateKey=function(e,n,r,i){var o=this,s=o.m_library;return new t((function(t,a){o.CheckInitialize().then((function(){return o.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(n,s.CreateKeyMedia());return o.CtxReadPrivateKeyInternal(e,null,null,t,r,i,!0)})).then((function(e){o.EndKMOperation(),t(e)})).catch((function(t){o.EndKMOperation(),a(o.MapError(t))}))}))},e.prototype.CtxReadPrivateKeyBinary=function(e,n,r,i,o){var s=this;return new t((function(t,a){s.CheckInitialize().then((function(){return s.CtxReadPrivateKeyInternal(e,n,r,null,i,o,!0)})).then((function(e){t(e)})).catch((function(t){return a(s.MapError(t))}))}))},e.prototype.CtxFreePrivateKey=function(e){var n=this,r=this.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){return r.CtxFreePrivateKey(e)})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.CtxGetOwnCertificates=function(e){var n=this,i=this.m_library;return new t((function(t,o){n.CheckInitialize().then((function(){if(null==e)throw i.MakeError(r.EU_ERROR_BAD_CERT,"");var s=new Array,a=function(r){i.CtxEnumOwnCertificates(e,r).then((function(e){if(e){var n=l.a.MapToEndUserCertificate(e,new u.EndUserCertificate);s.push(n),a(r+1)}else t(s)})).catch((function(t){return o(n.MapError(t))}))};a(0)})).catch((function(t){return o(n.MapError(t))}))}))},e.prototype.CtxSignHash=function(t,e,n,r,i){return this.CtxSignHashInternal(t,e,n,null,r,i)},e.prototype.CtxSignData=function(t,e,n,r,i,o){return this.CtxSignDataInternal(t,e,n,null,r,i,o)},e.prototype.CtxAppendSignHash=function(t,e,n,r,i,o){return this.CtxSignHashInternal(t,e,n,r,i,o)},e.prototype.CtxAppendSign=function(t,e,n,r,i,o){return this.CtxSignDataInternal(t,e,n,r,null!=n,i,o)},e.prototype.CtxGetSignValue=function(e,n,i,o,s){void 0===s&&(s=!1);var a=this,u=this.m_library,c=a.DataToNamedDataArray(i);return new t((function(l,f){a.CheckInitialize().then((function(){if(null==e)throw u.MakeError(r.EU_ERROR_BAD_CERT,"");return n!=_.EndUserSignAlgo.ECDSAWithSHA?null:u.CtxSetParameter(a.m_context,u.EU_ENCODE_ECDSA_SIGN_VALUE_CONTEXT_PARAMETER,s)})).then((function(){return a.ProcessArray(c,(function(r){return new t((function(t,i){u.CtxGetSignValue(e,n,r.val).then((function(t){return o?t:u.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return i(t)}))}))}))})).then((function(t){var e=a.DataToResult(i,t);l(e)})).catch((function(t){return f(a.MapError(t))}))}))},e.prototype.CtxEnvelopData=function(e,n,i,o,s,a,u){var c=this,l=this.m_library;return new t((function(t,f){c.CheckInitialize().then((function(){if(null==e&&(!u||o))throw l.MakeError(r.EU_ERROR_BAD_CERT,"");var t=l.EU_RECIPIENT_APPEND_TYPE_BY_ISSUER_SERIAL;return u?o?l.CtxEnvelopWithDynamicKey(e,n,t,o,s,i):l.EnvelopToRecipientsWithDynamicKey(n,o,s,i):l.CtxEnvelop(e,n,t,o,s,i)})).then((function(t){return a?t:l.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return f(c.MapError(t))}))}))},e.prototype.CtxDevelopData=function(e,n,i){var o=this,s=this.m_library;return new t((function(t,a){o.CheckInitialize().then((function(){if(null==e)throw s.MakeError(r.EU_ERROR_BAD_CERT,"");return s.CtxDevelop(e,n,i)})).then((function(e){var n=l.a.MapToEndUserSenderInfo(e,new C.a);t(n)})).catch((function(t){return a(o.MapError(t))}))}))},e.prototype.ProtectTaxReports=function(e,n,r,i,o,s,a){void 0===e&&(e=null),void 0===n&&(n=null),void 0===r&&(r=null),void 0===a&&(a=!1);var u=this;return new t((function(t,c){var l={accountant:null,director:null,stamp:null};u.CheckInitialize().then((function(){var t=[_.EndUserKeyUsage.DigitalSignature];return null!=e?u.LoadTaxReportPKey(e,t,!1):null})).then((function(t){l.accountant=t;var e=[_.EndUserKeyUsage.DigitalSignature];return r||e.push(_.EndUserKeyUsage.KeyAgreement),null!=n?u.LoadTaxReportPKey(n,e,!1):null})).then((function(t){l.director=t;var e=[_.EndUserKeyUsage.DigitalSignature,_.EndUserKeyUsage.KeyAgreement];return null!=r?u.LoadTaxReportPKey(r,e,!0):null})).then((function(t){return l.stamp=t,u.ProcessArray(s,(function(t){return u.ProtectTaxReport(l.accountant,l.director,l.stamp,i,o,t,a)}))})).then((function(e){t(e)})).catch((function(t){return c(u.MapError(t))}))}))},e.prototype.UnprotectTaxReceipts=function(e,n){var r=this;return new t((function(t,i){r.CheckInitialize().then((function(){return r.ProcessArray(n,(function(t){return r.UnprotectTaxReceipt(e,t)}))})).then((function(e){t(e)})).catch((function(t){return i(r.MapError(t))}))}))},e.prototype.ASiCGetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.ASiCGetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxASiCGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context&&o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))}))}))}))},e.prototype.ASiCSignData=function(e,n,i,o,s,a){var u=this,c=this,l=this.m_library;return new t((function(t,f){c.CheckInitialize().then((function(){if(null==u.m_pkContext)throw l.MakeError(r.EU_ERROR_BAD_CERT,"");return c.ProcessArray(s,(function(t){return c.NamedDataToReference(t)}))})).then((function(t){return l.CtxASiCSign(u.m_pkContext,e,n,i,o,t)})).then((function(t){return a?t:l.BASE64Decode(t)})).then((function(e){var r={name:s[0].name+(n==_.EndUserASiCType.S?".asics":".asice"),val:e};t(r)})).catch((function(t){return f(c.MapError(t))}))}))},e.prototype.ASiCAppendSign=function(e,n,i,o,s){var a=this,u=this,c=this.m_library,l=u.DataToNamedDataArray(o);return new t((function(t,o){u.CheckInitialize().then((function(){if(null==a.m_pkContext)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");return c.CtxASiCAppendSign(a.m_pkContext,e,n,i,l[0].val)})).then((function(t){return s?t:c.BASE64Decode(t)})).then((function(e){var n={name:l[0].name,val:e};t(n)})).catch((function(t){return o(u.MapError(t))}))}))},e.prototype.ASiCVerifyData=function(e,n){void 0===n&&(n=-1);var r=this,i=this.m_library;return new t((function(o,s){r.CheckInitialize().then((function(){return-1==n?i.ASiCGetSignsCount(e):1})).then((function(o){var s=new Array;if(-1!=n)s.push(n);else for(var a=0;a<o;a++)s.push(a);return r.ProcessArray(s,(function(n){return new t((function(t,o){var s=new S.a;i.ASiCVerify(n,e).then((function(t){return l.a.MapToEndUserSignInfo(t,s),i.ASiCGetSignTimeInfo(n,e)})).then((function(t){return s.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),i.ASiCGetSignLevel(n,e)})).then((function(e){s.signLevel=e,t(s)})).catch((function(t){return o(r.MapError(t))}))}))}))})).then((function(t){o(-1!=n?t[0]:t)})).catch((function(t){return s(r.MapError(t))}))}))},e.prototype.PDFGetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.PDFGetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxPDFGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context&&o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))}))}))}))},e.prototype.PDFSignData=function(e,n,i,o){var s=this,a=this,u=this.m_library,c=a.DataToNamedDataArray(n);return new t((function(l,f){a.CheckInitialize().then((function(){if(null==s.m_pkContext)throw u.MakeError(r.EU_ERROR_BAD_CERT,"");return a.ProcessArray(c,(function(n){return new t((function(t,r){return u.CtxPDFSign(s.m_pkContext,e,n.val,i).then((function(t){return o?t:u.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return r(t)}))}))}))})).then((function(t){var e=s.DataToResult(n,t);l(e)})).catch((function(t){return f(a.MapError(t))}))}))},e.prototype.PDFVerifyData=function(e,n){void 0===n&&(n=-1);var r=this,i=this.m_library;return new t((function(o,s){r.CheckInitialize().then((function(){return-1==n?i.PDFGetSignsCount(e):1})).then((function(o){var s=new Array;if(-1!=n)s.push(n);else for(var a=0;a<o;a++)s.push(a);return r.ProcessArray(s,(function(n){return new t((function(t,o){var s=new S.a;i.PDFVerify(n,e).then((function(t){return l.a.MapToEndUserSignInfo(t,s),i.PDFGetSignTimeInfo(n,e)})).then((function(t){return s.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),i.PDFGetSignType(n,e)})).then((function(e){s.signLevel=e,t(s)})).catch((function(t){return o(r.MapError(t))}))}))}))})).then((function(t){o(-1!=n?t[0]:t)})).catch((function(t){return s(r.MapError(t))}))}))},e.prototype.XAdESGetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.XAdESGetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxXAdESGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context&&o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))}))}))}))},e.prototype.XAdESSignData=function(e,n,i,o,s){var a=this,u=this,c=this.m_library;return new t((function(t,l){u.CheckInitialize().then((function(){if(null==a.m_pkContext)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");return u.ProcessArray(o,(function(t){return u.NamedDataToReference(t)}))})).then((function(t){return c.CtxXAdESSign(a.m_pkContext,e,n,i,t)})).then((function(t){return s?t:c.BASE64Decode(t)})).then((function(e){var n={name:o[0].name+(o[0].name.endsWith(".xml")?"":".xml"),val:e};t(n)})).catch((function(t){return l(u.MapError(t))}))}))},e.prototype.XAdESVerifyData=function(e,n,r){void 0===r&&(r=-1);var i=this,o=this.m_library,s=new Array;return new t((function(a,u){i.CheckInitialize().then((function(){return-1==r?o.XAdESGetSignsCount(n):1})).then((function(t){if(-1!=r)s.push(r);else for(var n=0;n<t;n++)s.push(n);return null==e?null:i.ProcessArray(e,(function(t){return i.NamedDataToReference(t)}))})).then((function(e){return i.ProcessArray(s,(function(r){return new t((function(t,s){var a=new S.a;o.XAdESVerify(e,r,n).then((function(t){return l.a.MapToEndUserSignInfo(t,a),o.XAdESGetSignTimeInfo(r,n)})).then((function(t){return a.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),o.XAdESGetSignLevel(r,n)})).then((function(e){a.signLevel=e,t(a)})).catch((function(t){return s(i.MapError(t))}))}))}))})).then((function(t){a(-1!=r?t[0]:t)})).catch((function(t){return u(i.MapError(t))}))}))},e.prototype.GetSignContainerInfo=function(e){var n=this,r=this.m_library,i=(new y.a,function(e){var n=new y.a;return new t((function(t,i){r.IsDataInSignedDataAvailable(e).then((function(e){n.type=_.EndUserSignContainerType.CAdES,n.subType=e?_.EndUserCAdESType.Enveloped:_.EndUserCAdESType.Detached,t(n)})).catch((function(e){t(null)}))}))}),o=function(e){var n=new y.a;return new t((function(t,i){r.XAdESGetType(e).then((function(e){n.type=_.EndUserSignContainerType.XAdES,n.subType=e,t(n)})).catch((function(e){t(null)}))}))},s=function(e){var n=new y.a;return new t((function(t,i){r.PDFGetSignsCount(e).then((function(e){n.type=_.EndUserSignContainerType.PAdES,t(n)})).catch((function(e){t(null)}))}))},a=function(e){var n=new y.a;return new t((function(t,i){r.ASiCGetASiCType(e).then((function(t){return n.type=_.EndUserSignContainerType.ASiC,n.subType=t,r.ASiCGetSignType(e)})).then((function(e){n.asicSignType=e,t(n)})).catch((function(e){t(null)}))}))};return new t((function(u,c){n.CheckInitialize().then((function(){return"string"==typeof e?r.BASE64Decode(e):e})).then((function(e){var n=[],r=function(t,e){if(t.length<e.length)return!1;for(var n=0;n<e.length;n++)if(t[n]!=e[n])return!1;return!0};return n=r(e,[60,63,120,109,108])?[o,i,s,a]:r(e,[37,80,68,70])?[s,i,o,a]:r(e,[80,75])?[a,i,o,s]:[i,o,s,a],new t((function(t,r){var i=function(o){o>=n.length?t(new y.a):n[o](e).then((function(e){null!=e?t(e):i(o+1)})).catch((function(t){return r(t)}))};i(0)}))})).then((function(t){u(t)})).catch((function(t){return c(n.MapError(t))}))}))},e}();e.a=R}).call(this,n(17).Promise)},function(t,e,n){"use strict";(function(t){var r=n(3),i=function(){function e(){this.EU_SUBJECT_TYPE_UNDIFFERENCED=0,this.EU_SUBJECT_TYPE_CA=1,this.EU_SUBJECT_TYPE_CA_SERVER=2,this.EU_SUBJECT_TYPE_RA_ADMINISTRATOR=3,this.EU_SUBJECT_TYPE_END_USER=4,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_UNDIFFERENCED=0,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_CMP=1,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_TSP=2,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_OCSP=3,this.EU_CERT_KEY_TYPE_UNKNOWN=0,this.EU_CERT_KEY_TYPE_DSTU4145=1,this.EU_CERT_KEY_TYPE_RSA=2,this.EU_CERT_KEY_TYPE_ECDSA=4,this.EU_KEY_USAGE_UNKNOWN=0,this.EU_KEY_USAGE_DIGITAL_SIGNATURE=1,this.EU_KEY_USAGE_KEY_AGREEMENT=16,this.EU_KEYS_REQUEST_TYPE_UA_DS=1,this.EU_KEYS_REQUEST_TYPE_UA_KEP=2,this.EU_KEYS_REQUEST_TYPE_INTERNATIONAL=3,this.EU_KEYS_TYPE_NONE=0,this.EU_KEYS_TYPE_DSTU_AND_ECDH_WITH_GOSTS=1,this.EU_KEYS_TYPE_RSA_WITH_SHA=2,this.EU_KEYS_LENGTH_DS_UA_191=1,this.EU_KEYS_LENGTH_DS_UA_257=2,this.EU_KEYS_LENGTH_DS_UA_307=3,this.EU_KEYS_LENGTH_DS_UA_FILE=4,this.EU_KEYS_LENGTH_DS_UA_CERT=5,this.EU_KEYS_LENGTH_KEP_UA_257=1,this.EU_KEYS_LENGTH_KEP_UA_431=2,this.EU_KEYS_LENGTH_KEP_UA_571=3,this.EU_KEYS_LENGTH_KEP_UA_FILE=4,this.EU_KEYS_LENGTH_KEP_UA_CERT=5,this.EU_KEYS_LENGTH_DS_RSA_1024=1,this.EU_KEYS_LENGTH_DS_RSA_2048=2,this.EU_KEYS_LENGTH_DS_RSA_3072=3,this.EU_KEYS_LENGTH_DS_RSA_4096=4,this.EU_KEYS_LENGTH_DS_RSA_FILE=5,this.EU_KEYS_LENGTH_DS_RSA_CERT=6,this.EU_RECIPIENT_APPEND_ISSUER_AND_SERIAL=1,this.EU_RECIPIENT_APPEND_KEY_ID=2,this.EU_RECIPIENT_APPEND_KEY_ID_USC_COMPAT=3,this.EU_SAVE_SETTINGS_PARAMETER="SaveSettings",this.EU_RESOLVE_OIDS_PARAMETER="ResolveOIDs",this.EU_MAKE_PKEY_PFX_CONTAINER_PARAMETER="MakePKeyPFXContainer",this.EU_SIGN_INCLUDE_CONTENT_TIME_STAMP_PARAMETER="SignIncludeContentTimeStamp",this.EU_SIGN_TYPE_PARAMETER="SignType",this.EU_SIGN_INCLUDE_CA_CERTIFICATES_PARAMETER="SignIncludeCACertificates",this.EU_FS_CALCULATE_FINGERPRINT="FSCalculateFingerprint",this.EU_CHECK_CERT_CHAIN_ON_SIGN_TIME_PARAMETER="CheckCertChainOnSignTime",this.EU_CONNECTIONS_TIMEOUT_PARAMETER="ConnectionsTimeout",this.EU_LOG_EVENTS_THRESHOLD_PARAMETER="LogEventsThreshold",this.EU_USE_SLOGIN_PRIVATE_KEY="UseSLoginPrivateKey",this.EU_SETTINGS_ID_NONE=0,this.EU_SETTINGS_ID_MANDATORY=31,this.EU_SETTINGS_ID_ALL=4095,this.EU_SETTINGS_ID_FSTORE=1,this.EU_SETTINGS_ID_PROXY=2,this.EU_SETTINGS_ID_TSP=4,this.EU_SETTINGS_ID_OCSP=8,this.EU_SETTINGS_ID_LDAP=16,this.EU_SETTINGS_ID_MODE=32,this.EU_SETTINGS_ID_CMP=64,this.EU_SETTINGS_ID_KM=128,this.EU_SETTINGS_ID_OCSP_ACCESS_INFO_MODE=256,this.EU_SETTINGS_ID_OCSP_ACCESS_INFO=512,this.EU_SETTINGS_ID_TSL=1024,this.EU_SETTINGS_ID_LOG=2048,this.EU_HEADER_CA_TYPE="UA1",this.EU_HEADER_PART_TYPE_SIGNED=1,this.EU_HEADER_PART_TYPE_ENCRYPTED=2,this.EU_HEADER_PART_TYPE_STAMPED=3,this.EU_HEADER_PART_TYPE_CERTCRYPT=4,this.EU_HEADER_MAX_CA_TYPE_SIZE=3,this.EU_SIGNED_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_SIGNED,this.EU_ENCRYPTED_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_ENCRYPTED,this.EU_TIMESTAMPED_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_STAMPED,this.EU_CERTCRYPT_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_CERTCRYPT,this.EU_DEFAULT_LANG=0,this.EU_UA_LANG=1,this.EU_RU_LANG=2,this.EU_EN_LANG=3,this.EU_CONTENT_ENC_ALGO_TDES_CBC=4,this.EU_CONTENT_ENC_ALGO_AES_128_CBC=5,this.EU_CONTENT_ENC_ALGO_AES_192_CBC=6,this.EU_CONTENT_ENC_ALGO_AES_256_CBC=7,this.EU_DEV_CTX_MIN_PUBLIC_DATA_ID=16,this.EU_DEV_CTX_MAX_PRIVATE_DATA_ID=175,this.EU_UA_OID_EXT_KEY_USAGE_STAMP="1.2.804.2.1.1.1.3.9",this.EU_CCS_TYPE_REVOKE=1,this.EU_CCS_TYPE_HOLD=2,this.EU_REVOCATION_REASON_UNKNOWN=0,this.EU_REVOCATION_REASON_KEY_COMPROMISE=1,this.EU_REVOCATION_REASON_NEW_ISSURED=2,this.EU_SIGN_TYPE_UNKNOWN=0,this.EU_SIGN_TYPE_CADES_BES=1,this.EU_SIGN_TYPE_CADES_T=4,this.EU_SIGN_TYPE_CADES_C=8,this.EU_SIGN_TYPE_CADES_X_LONG=16,this.EU_CHECK_PRIVATE_KEY_CONTEXT_PARAMETER="CheckPrivateKey",this.EU_RESOLVE_OIDS_CONTEXT_PARAMETER="ResolveOIDs",this.EU_EXPORATABLE_CONTEXT_CONTEXT_PARAMETER="ExportableContext",this.EU_ENCODE_ECDSA_SIGN_VALUE_CONTEXT_PARAMETER="EncodeECDSASignValue",this.EU_USE_SLOGIN_PRIVATE_KEY_CONTEXT_PARAMETER="UseSLoginPrivateKey",this.EU_RECIPIENT_APPEND_TYPE_BY_ISSUER_SERIAL=1,this.EU_RECIPIENT_APPEND_TYPE_BY_KEY_ID=2,this.EU_CTX_HASH_ALGO_UNKNOWN=0,this.EU_CTX_HASH_ALGO_GOST34311=1,this.EU_CTX_HASH_ALGO_SHA160=2,this.EU_CTX_HASH_ALGO_SHA224=3,this.EU_CTX_HASH_ALGO_SHA256=4,this.EU_CTX_HASH_ALGO_SHA384=5,this.EU_CTX_HASH_ALGO_SHA512=6,this.EU_CTX_HASH_ALGO_DSTU7564_256=7,this.EU_CTX_HASH_ALGO_DSTU7564_384=8,this.EU_CTX_HASH_ALGO_DSTU7564_512=9,this.EU_CTX_SIGN_UNKNOWN=0,this.EU_CTX_SIGN_DSTU4145_WITH_GOST34311=1,this.EU_CTX_SIGN_RSA_WITH_SHA=2,this.EU_CTX_SIGN_ECDSA_WITH_SHA=3,this.EU_CTX_SIGN_DSTU4145_WITH_DSTU7564=4,this.EU_FILE_PROCESS_CHUNK_SIZE=1048576,this.EU_ASIC_TYPE_UNKNOWN=0,this.EU_ASIC_TYPE_S=1,this.EU_ASIC_TYPE_E=2,this.EU_ASIC_SIGN_TYPE_UNKNOWN=0,this.EU_ASIC_SIGN_TYPE_CADES=1,this.EU_ASIC_SIGN_TYPE_XADES=2,this.EU_ASIC_SIGN_LEVEL_BES=1,this.EnvelopToRecipientsEx=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.EnvelopToRecipientsEx(e,n,r,i,t,s)}))},this.EnvelopToRecipientsWithDynamicKey=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.EnvelopToRecipientsWithDynamicKey(e,n,r,i,t,s)}))},this.EnvelopToRecipientsWithSettings=function(e,n,r,i,o,s,a){var u=this.m_library;return new t((function(t,c){u.EnvelopToRecipientsWithSettings(e,n,r,i,o,s,a,t,c)}))},this.CtxEnvelop=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxEnvelop(e,n,r,i,o,s,t,u)}))},this.CtxEnvelopWithDynamicKey=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxEnvelopWithDynamicKey(e,n,r,i,o,s,t,u)}))},this.DevelopEx=function(e,n){void 0===n&&(n=null);var r=this.m_library;return new t((function(t,i){r.DevelopEx(e,n,t,i)}))},this.CtxDevelop=function(e,n,r){void 0===r&&(r=null);var i=this.m_library;return new t((function(t,o){i.CtxDevelop(e,n,r,t,o)}))},this.CtxCreateAuthData=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxCreateAuthData(e,n,r,t,o)}))},this.ProtectDataByPassword=function(e,n){var r=this.m_library;return new t((function(t,i){r.ProtectDataByPassword(e,n,t,i)}))},this.UnprotectDataByPassword=function(e,n){var r=this.m_library;return new t((function(t,i){r.UnprotectDataByPassword(e,n,t,i)}))},this.AppendTransportHeader=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.AppendTransportHeader(e,n,r,i,o,t,a)}))},this.ParseTransportHeader=function(e){var n=this.m_library;return new t((function(t,r){n.ParseTransportHeader(e,t,r)}))},this.AppendCryptoHeader=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.AppendCryptoHeader(e,n,r,t,o)}))},this.ParseCryptoHeader=function(e){var n=this.m_library;return new t((function(t,r){n.ParseCryptoHeader(e,t,r)}))},this.GetHostInfo=function(){var e=this.m_library;return new t((function(t,n){e.GetHostInfo(t,n)}))},this.CtxCreate=function(){var e=this.m_library;return new t((function(t,n){e.CtxCreate(t,n)}))},this.CtxFree=function(e){var n=this.m_library;return new t((function(t,r){n.CtxFree(e,t,r)}))},this.CtxSetParameter=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxSetParameter(e,n,r,t,o)}))},this.ASiCGetASiCType=function(e){var n=this.m_library;return new t((function(t,r){n.ASiCGetASiCType(e,t,r)}))},this.ASiCGetSignType=function(e){var n=this.m_library;return new t((function(t,r){n.ASiCGetSignType(e,t,r)}))},this.ASiCGetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.ASiCGetSignsCount(e,t,r)}))},this.ASiCGetSignerInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCGetSignerInfo(e,n,t,i)}))},this.ASiCGetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCGetSignTimeInfo(e,n,t,i)}))},this.CtxASiCSign=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxASiCSign(e,n,r,i,o,s,t,u)}))},this.CtxASiCAppendSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxASiCAppendSign(e,n,r,i,o,t,a)}))},this.ASiCVerify=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCVerify(e,n,t,i)}))},this.CtxASiCGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxASiCGetSignerInfo(e,n,r,t,o)}))},this.ASiCGetSignLevel=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCGetSignLevel(e,n,t,i)}))},this.PDFGetSignType=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFGetSignType(e,n,t,i)}))},this.PDFGetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.PDFGetSignsCount(e,t,r)}))},this.PDFGetSignerInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFGetSignerInfo(e,n,t,i)}))},this.PDFGetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFGetSignTimeInfo(e,n,t,i)}))},this.CtxPDFSign=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.CtxPDFSign(e,n,r,i,t,s)}))},this.PDFVerify=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFVerify(e,n,t,i)}))},this.CtxPDFGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxPDFGetSignerInfo(e,n,r,t,o)}))},this.XAdESGetType=function(e){var n=this.m_library;return new t((function(t,r){n.XAdESGetType(e,t,r)}))},this.XAdESGetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.XAdESGetSignsCount(e,t,r)}))},this.XAdESGetSignLevel=function(e,n){var r=this.m_library;return new t((function(t,i){r.XAdESGetSignLevel(e,n,t,i)}))},this.XAdESGetSignerInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.XAdESGetSignerInfo(e,n,t,i)}))},this.XAdESGetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.XAdESGetSignTimeInfo(e,n,t,i)}))},this.CtxXAdESSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxXAdESSign(e,n,r,i,o,t,a)}))},this.XAdESVerify=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.XAdESVerify(e,n,r,t,o)}))},this.CtxXAdESGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxXAdESGetSignerInfo(e,n,r,t,o)}))},this.SServerClientGeneratePrivateKeyAsync=function(e,n,r,i,o,s,a,u,c,l,f){var _=this.m_library;return new t((function(t,p){_.SServerClientGeneratePrivateKeyAsync(e,n,r,i,o,s,a,u,c,l,f,t,p)}))},this.SServerClientCheckGeneratePrivateKeyStatus=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.SServerClientCheckGeneratePrivateKeyStatus(e,n,r,i,t,s)}))},this.SServerClientSignHashesAsync=function(e,n,r,i,o,s,a,u){var c=this.m_library;return new t((function(t,l){c.SServerClientSignHashesAsync(e,n,r,i,o,s,a,u,t,l)}))},this.SServerClientCheckSignHashesStatus=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.SServerClientCheckSignHashesStatus(e,n,r,i,t,s)}))},this.m_language=0,this.m_library=null}return e.prototype.MakeURL=function(t){var e=location.origin,n=location.pathname;return 0==t.indexOf("http://")||0==t.indexOf("https://")?t:0==t.indexOf("/")&&e?e+t:e&&n?e+n.substr(0,n.lastIndexOf("/"))+"/"+t:t},e.prototype.MakeError=function(t,e){return this.m_library.MakeError(t,e)},e.prototype.IsLibraryLoadError=function(t){return t==r.EndUserError.ERROR_LIBRARY_COMUNICATION_FAILED},e.prototype.IsLibraryVersionNotSupportedError=function(t){return t==r.EndUserError.ERROR_LIBRARY_VERSION_NOT_SUPPORTED},e.prototype.Load=function(){var e=this;return new t((function(t,n){if(null==e.m_library){var i=new r.EndUserLibraryLoader(r.EndUserLibraryLoader.LIBRARY_TYPE_DEFAULT,"euSign",e.m_language,!0,!0);i.onload=function(n){e.m_library=n,t()},i.onerror=function(t,e,i){null==i&&(i=new r.EUSignCP("","")),n(i.MakeError(e,""))},i.load()}else t()}))},e.prototype.IsSupported=function(){return r.EndUserLibraryLoader.isWebExtensionSupported()||r.EndUserLibraryLoader.isSignAgentSupported()||r.EndUserLibraryLoader.isNPAPISupported()||r.EndUserLibraryLoader.isActiveXSupported()},e.prototype.IsSignAgentSupported=function(){return r.EndUserLibraryLoader.isSignAgentSupported()},e.prototype.IsWebExtensionSupported=function(){return r.EndUserLibraryLoader.isWebExtensionSupported()},e.prototype.IsNPAPISupported=function(){return r.EndUserLibraryLoader.isNPAPISupported()},e.prototype.IsActiveXSupported=function(){return r.EndUserLibraryLoader.isActiveXSupported()},e.prototype.IsWebExtensionInstalled=function(){return r.EndUserLibraryLoader.isWebExtensionInstalled()},e.prototype.GetInstallURL=function(t,e){return void 0===t&&(t=!1),new r.EUSignCP("","").GetInstallURL(t,e)},e.prototype.GetUpdateURL=function(t,e){return void 0===t&&(t=!1),new r.EUSignCP("","").GetUpdateURL(t,e)},e.prototype.GetHelpURL=function(t){return new r.EUSignCP("","").GetHelpURL(t)},e.prototype.GetWebExtensionInstallURL=function(){return new r.EUSignCP("","").GetWebExtensionInstallURL()},e.prototype.GetVersion=function(){var e=this.m_library;return new t((function(t,n){e.GetVersion(t,n)}))},e.prototype.IsInitialized=function(){var e=this.m_library;return new t((function(t,n){e.IsInitialized(t,n)}))},e.prototype.Initialize=function(){var e=this.m_library;return new t((function(t,n){e.Initialize(t,n)}))},e.prototype.Finalize=function(){var e=this.m_library;return new t((function(t,n){e.Finalize(t,n)}))},e.prototype.ResetOperation=function(){var e=this.m_library;return new t((function(t,n){e.ResetOperation(t,n)}))},e.prototype.SetUIMode=function(e){var n=this.m_library;return new t((function(t,r){n.SetUIMode(e,t,r)}))},e.prototype.SetLanguage=function(e){var n=this.m_library;if("string"==typeof e)switch(e=e.toLocaleLowerCase()){case"en":e=this.EU_EN_LANG;break;case"ru":e=this.EU_RU_LANG;break;case"uk":case"ua":default:e=this.EU_UA_LANG}return this.m_language=e,new t((function(t,r){n.SetLanguage(e,t,r)}))},e.prototype.SetCharset=function(e){var n=this.m_library;return new t((function(t,r){n.SetCharset(e,t,r)}))},e.prototype.SetRuntimeParameter=function(e,n){var r=this.m_library;return new t((function(t,i){r.SetRuntimeParameter(e,n,t,i)}))},e.prototype.GetStorageParameter=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetStorageParameter(e,n,t,i)}))},e.prototype.SetStorageParameter=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.SetStorageParameter(e,n,r,t,o)}))},e.prototype.BASE64Encode=function(e){var n=this.m_library;return new t((function(t,r){n.BASE64Encode(e,t,r)}))},e.prototype.BASE64Decode=function(e){var n=this.m_library;return new t((function(t,r){n.BASE64Decode(e,t,r)}))},e.prototype.StringToBytes=function(e){var n=this.m_library;return new t((function(t,r){n.StringToBytes(e,t,r)}))},e.prototype.BytesToString=function(e){var n=this.m_library;return new t((function(t,r){n.BytesToString(e,t,r)}))},e.prototype.DoesNeedSetSettings=function(){var e=this.m_library;return new t((function(t,n){e.DoesNeedSetSettings(t,n)}))},e.prototype.InitializeMandatorySettings=function(){var e=this.m_library;return new t((function(t,n){e.InitializeMandatorySettings(t,n)}))},e.prototype.CreateModeSettings=function(){return this.m_library.CreateModeSettings()},e.prototype.GetModeSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetModeSettings(t,n)}))},e.prototype.SetModeSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetModeSettings(e,t,r)}))},e.prototype.CreateKeyMediaSettings=function(){return this.m_library.CreateKeyMediaSettings()},e.prototype.GetKeyMediaSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetKeyMediaSettings(t,n)}))},e.prototype.SetKeyMediaSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetKeyMediaSettings(e,t,r)}))},e.prototype.CreateFileStoreSettings=function(){return this.m_library.CreateFileStoreSettings()},e.prototype.GetFileStoreSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetFileStoreSettings(t,n)}))},e.prototype.SetFileStoreSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetFileStoreSettings(e,t,r)}))},e.prototype.CreateProxySettings=function(){return this.m_library.CreateProxySettings()},e.prototype.GetProxySettings=function(){var e=this.m_library;return new t((function(t,n){e.GetProxySettings(t,n)}))},e.prototype.SetProxySettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetProxySettings(e,t,r)}))},e.prototype.CreateOCSPSettings=function(){return this.m_library.CreateOCSPSettings()},e.prototype.GetOCSPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetOCSPSettings(t,n)}))},e.prototype.SetOCSPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPSettings(e,t,r)}))},e.prototype.CreateOCSPAccessInfoModeSettings=function(){return this.m_library.CreateOCSPAccessInfoModeSettings()},e.prototype.GetOCSPAccessInfoModeSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetOCSPAccessInfoModeSettings(t,n)}))},e.prototype.SetOCSPAccessInfoModeSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPAccessInfoModeSettings(e,t,r)}))},e.prototype.CreateOCSPAccessInfoSettings=function(){return this.m_library.CreateOCSPAccessInfoSettings()},e.prototype.EnumOCSPAccessInfoSettings=function(e){var n=this.m_library;return new t((function(t,r){n.EnumOCSPAccessInfoSettings(e,t,r)}))},e.prototype.GetOCSPAccessInfoSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetOCSPAccessInfoSettings(t,n)}))},e.prototype.SetOCSPAccessInfoSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPAccessInfoSettings(e,t,r)}))},e.prototype.DeleteOCSPAccessInfoSettings=function(e){var n=this.m_library;return new t((function(t,r){n.DeleteOCSPAccessInfoSettings(e,t,r)}))},e.prototype.CreateTSPSettings=function(){return this.m_library.CreateTSPSettings()},e.prototype.GetTSPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetTSPSettings(t,n)}))},e.prototype.SetTSPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetTSPSettings(e,t,r)}))},e.prototype.CreateLDAPSettings=function(){return this.m_library.CreateLDAPSettings()},e.prototype.GetLDAPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetLDAPSettings(t,n)}))},e.prototype.SetLDAPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetLDAPSettings(e,t,r)}))},e.prototype.CreateCMPSettings=function(){return this.m_library.CreateCMPSettings()},e.prototype.GetCMPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetCMPSettings(t,n)}))},e.prototype.SetCMPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetCMPSettings(e,t,r)}))},e.prototype.GetSystemProxySettings=function(){var e=this.m_library;return new t((function(t,n){e.GetSystemProxySettings(t,n)}))},e.prototype.CreateTSLSettings=function(){return this.m_library.CreateTSLSettings()},e.prototype.GetTSLSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetTSLSettings(t,n)}))},e.prototype.SetTSLSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetTSLSettings(e,t,r)}))},e.prototype.SetOCSPResponseExpireTime=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPResponseExpireTime(e,t,r)}))},e.prototype.GetCertificate=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetCertificate(e,n,t,i)}))},e.prototype.ParseCertificateEx=function(e){var n=this.m_library;return new t((function(t,r){n.ParseCertificateEx(e,t,r)}))},e.prototype.SaveCertificate=function(e){var n=this.m_library;return new t((function(t,r){n.SaveCertificate(e,t,r)}))},e.prototype.SaveCertificates=function(e){var n=this.m_library;return new t((function(t,r){n.SaveCertificates(e,t,r)}))},e.prototype.GetTSPByAccessInfo=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.GetTSPByAccessInfo(e,n,r,i,t,s)}))},e.prototype.CheckTSP=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CheckTSP(e,n,r,t,o)}))},e.prototype.DownloadData=function(e,n){var i=this;return new t((function(t,o){try{var s=new XMLHttpRequest;s.onload=function(){if(4==s.readyState){var a=null;try{if(200!=s.status)throw"Download data error. URL - "+e+", status - "+s.status;switch(n){case"binary":a=new Uint8Array(s.response);break;case"json":a=JSON.parse(s.responseText.replace(/\\'/g,"'"));break;default:a=s.responseText}}catch(t){return console.log("EndUser.DowloadData error: "+t),void o(i.MakeError(r.EndUserError.ERROR_DOWNLOAD_FILE,""))}t(a)}},s.onerror=function(){o(i.MakeError(r.EndUserError.ERROR_DOWNLOAD_FILE,""))},e=i.MakeURL(e),s.open("GET",e,!0),"binary"==n&&(s.responseType="arraybuffer"),s.send()}catch(t){o(i.MakeError(r.EndUserError.ERROR_DOWNLOAD_FILE,""))}}))},e.prototype.CreateKeyMedia=function(){return this.m_library.CreateKeyMedia()},e.prototype.GetPrivateKeyMedia=function(e){var n=this.m_library;return new t((function(t,r){n.GetPrivateKeyMedia(e,t,r)}))},e.prototype.EnumKeyMediaTypes=function(e){var n=this.m_library;return new t((function(t,r){n.EnumKeyMediaTypes(e,t,r)}))},e.prototype.EnumKeyMediaDevices=function(e,n){var r=this.m_library;return new t((function(t,i){r.EnumKeyMediaDevices(e,n,t,i)}))},e.prototype.GetKeyMediaTypes=function(){var e=this.m_library;return new t((function(t,n){e.GetKeyMediaTypes(t,n)}))},e.prototype.GetKeyMediaDevices=function(e){var n=this.m_library;return new t((function(t,r){n.GetKeyMediaDevices(e,t,r)}))},e.prototype.IsPrivateKeyReaded=function(){var e=this.m_library;return new t((function(t,n){e.IsPrivateKeyReaded(t,n)}))},e.prototype.ReadPrivateKey=function(){var e=this.m_library;return new t((function(t,n){e.ReadPrivateKey(t,n)}))},e.prototype.ReadPrivateKeySilently=function(e,n,r){var i=this.m_library;return new t((function(t,o){"number"==typeof e?i.ReadPrivateKeySilently(e,n,r,t,o):i.ReadPrivateKeySilently(e,t,o)}))},e.prototype.ReadPrivateKeyBinary=function(e,n){var r=this.m_library;return new t((function(t,i){r.ReadPrivateKeyBinary(e,n,t,i)}))},e.prototype.ReadPrivateKeyFile=function(e,n){var r=this.m_library;return new t((function(t,i){r.ReadPrivateKeyFile(e,n,t,i)}))},e.prototype.ResetPrivateKey=function(){var e=this.m_library;return new t((function(t,n){e.ResetPrivateKey(t,n)}))},e.prototype.CtxReadPrivateKey=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){"number"==typeof n?o.CtxReadPrivateKey(e,n,r,i,t,s):o.CtxReadPrivateKey(e,n,t,s)}))},e.prototype.CtxReadPrivateKeyBinary=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxReadPrivateKeyBinary(e,n,r,t,o)}))},e.prototype.CtxFreePrivateKey=function(e){var n=this.m_library;return new t((function(t,r){n.CtxFreePrivateKey(e,t,r)}))},e.prototype.ShowOwnCertificate=function(){var e=this.m_library;return new t((function(t,n){e.ShowOwnCertificate(t,n)}))},e.prototype.GetOwnCertificate=function(e,n){var r=this.m_library;return new t((function(t,i){"number"==typeof e||"number"==typeof n?r.GetOwnCertificate(e,n,t,i):r.GetOwnCertificate(t,i)}))},e.prototype.GetOwnEUserParams=function(){var e=this.m_library;return new t((function(t,n){e.GetOwnEUserParams(t,n)}))},e.prototype.CtxGetOwnEUserParams=function(e){var n=this.m_library;return new t((function(t,r){n.CtxGetOwnEUserParams(e,t,r)}))},e.prototype.ModifyOwnEUserParams=function(e,n){var r=this.m_library;return new t((function(t,i){r.ModifyOwnEUserParams(e,n,t,i)}))},e.prototype.CtxModifyOwnEUserParams=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxModifyOwnEUserParams(e,n,r,t,o)}))},e.prototype.EnumOwnCertificates=function(e){var n=this.m_library;return new t((function(t,r){n.EnumOwnCertificates(e,t,r)}))},e.prototype.GetPrivateKeyOwnerInfo=function(){var e=this.m_library;return new t((function(t,n){e.GetPrivateKeyOwnerInfo(t,n)}))},e.prototype.CtxEnumOwnCertificates=function(e,n){var r=this.m_library;return new t((function(t,i){r.CtxEnumOwnCertificates(e,n,t,i)}))},e.prototype.CtxGetOwnCertificate=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxGetOwnCertificate(e,n,r,t,o)}))},e.prototype.GetKeyInfo=function(e){var n=this.m_library;return new t((function(t,r){n.GetKeyInfo(e,t,r)}))},e.prototype.GetKeyInfoBinary=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetKeyInfoBinary(e,n,t,i)}))},e.prototype.GetKeyInfoFile=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetKeyInfoFile(e,n,t,i)}))},e.prototype.GetCertificatesByKeyInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.GetCertificatesByKeyInfo(e,n,r,t,o)}))},e.prototype.EnumJKSPrivateKeys=function(e,n){var r=this.m_library;return new t((function(t,i){r.EnumJKSPrivateKeys(e,n,t,i)}))},e.prototype.GetJKSPrivateKey=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetJKSPrivateKey(e,n,t,i)}))},e.prototype.CreatePrivateKeyInfo=function(){return this.m_library.CreatePrivateKeyInfo()},e.prototype.CreateEndUserInfo=function(){return this.m_library.CreateEndUserInfo()},e.prototype.GeneratePrivateKeyEx=function(e,n,r,i,o,s,a,u,c,l,f,_,p,h,E,y,S){var C=this.m_library;return new t((function(t,d){C.GeneratePrivateKeyEx(e,n,r,i,o,s,a,u,c,l,f,_,p,h,E,y,S,t,d)}))},e.prototype.ChangePrivateKeyPassword=function(e,n){var r=this.m_library;return new t((function(t,i){null!=e?r.ChangePrivateKeyPassword(e.GetTypeIndex(),e.GetDevIndex(),e.GetPassword(),n,t,i):r.ChangePrivateKeyPassword(t,i)}))},e.prototype.ChangeSoftwarePrivateKeyPassword=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.ChangeSoftwarePrivateKeyPassword(e,n,r,t,o)}))},e.prototype.SetKeyMediaUserPassword=function(e,n){var r=this.m_library;return new t((function(t,i){null!=n?r.SetKeyMediaUserPassword(e,n.GetTypeIndex(),n.GetDevIndex(),n.GetPassword(),t,i):r.SetKeyMediaUserPassword(e,t,i)}))},e.prototype.ChangeOwnCertificatesStatus=function(e,n){var r=this.m_library;return new t((function(t,i){r.ChangeOwnCertificatesStatus(e,n,t,i)}))},e.prototype.CtxChangeOwnCertificatesStatus=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxChangeOwnCertificatesStatus(e,n,r,t,o)}))},e.prototype.MakeNewCertificate=function(e,n,r,i,o,s,a,u,c,l,f,_,p){var h=this.m_library;return new t((function(t,E){h.MakeNewCertificate(e,n,r,i,o,s,a,u,c,l,f,_,p,t,E)}))},e.prototype.MakeNewOwnCertificate=function(e,n,r,i,o,s,a,u){var c=this.m_library;return new t((function(t,l){c.MakeNewOwnCertificate(e,n,r,i,o,s,a,u,t,l)}))},e.prototype.CtxMakeNewOwnCertificate=function(e,n,r,i,o,s,a,u,c){var l=this.m_library;return new t((function(t,f){l.CtxMakeNewOwnCertificate(e,n,r,i,o,s,a,u,c,t,f)}))},e.prototype.CtxMakeNewOwnCertificateWithCR=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxMakeNewOwnCertificateWithCR(e,n,r,i,o,t,a)}))},e.prototype.CtxMakeDeviceCertificate=function(e,n,r,i,o,s,a,u){var c=this.m_library;return new t((function(t,l){c.CtxMakeDeviceCertificate(e,n,r,i,o,s,a,u,t,l)}))},e.prototype.CtxHash=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.CtxHash(e,n,r,i,t,s)}))},e.prototype.CtxHashBegin=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxHashBegin(e,n,r,t,o)}))},e.prototype.CtxHashContinue=function(e,n){var r=this.m_library;return new t((function(t,i){r.CtxHashContinue(e,n,t,i)}))},e.prototype.CtxHashEnd=function(e){var n=this.m_library;return new t((function(t,r){n.CtxHashEnd(e,t,r)}))},e.prototype.CtxHashFree=function(e){var n=this.m_library;return new t((function(t,r){n.CtxHashFree(e,t,r)}))},e.prototype.GetSignType=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetSignType(e,n,t,i)}))},e.prototype.CtxGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxGetSignerInfo(e,n,r,t,o)}))},e.prototype.SignHash=function(e){var n=this.m_library;return new t((function(t,r){n.SignHash(e,t,r)}))},e.prototype.Sign=function(e){var n=this.m_library;return new t((function(t,r){n.Sign(e,t,r)}))},e.prototype.SignInternal=function(e,n){var r=this.m_library;return new t((function(t,i){r.SignInternal(e,n,t,i)}))},e.prototype.SignHashRSA=function(e){var n=this.m_library;return new t((function(t,r){n.SignHashRSA(e,t,r)}))},e.prototype.SignRSA=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.SignRSA(e,n,r,t,o)}))},e.prototype.CtxSignHash=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.CtxSignHash(e,n,r,i,t,s)}))},e.prototype.CtxSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxSign(e,n,r,i,o,t,a)}))},e.prototype.CtxSignFile=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxSignFile(e,n,r,i,o,s,t,u)}))},e.prototype.CtxGetSignValue=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxGetSignValue(e,n,r,t,o)}))},e.prototype.AppendSignHash=function(e,n){var r=this.m_library;return new t((function(t,i){r.AppendSignHash(e,n,t,i)}))},e.prototype.AppendSign=function(e,n){var r=this.m_library;return new t((function(t,i){r.AppendSign(e,n,t,i)}))},e.prototype.AppendSignInternal=function(e,n){var r=this.m_library;return new t((function(t,i){r.AppendSignInternal(e,n,t,i)}))},e.prototype.CtxAppendSignHash=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxAppendSignHash(e,n,r,i,o,t,a)}))},e.prototype.CtxAppendSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxAppendSign(e,n,r,i,o,t,a)}))},e.prototype.CtxAppendSignFile=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxAppendSignFile(e,n,r,i,o,s,t,u)}))},e.prototype.IsDataInSignedDataAvailable=function(e){var n=this.m_library;return new t((function(t,r){n.IsDataInSignedDataAvailable(e,t,r)}))},e.prototype.GetCertificateFromSignedData=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetCertificateFromSignedData(e,n,t,i)}))},e.prototype.GetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.GetSignsCount(e,t,r)}))},e.prototype.GetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetSignTimeInfo(e,n,t,i)}))},e.prototype.VerifyHashOnTimeEx=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.VerifyHashOnTimeEx(e,n,r,i,o,s,t,u)}))},e.prototype.VerifyDataOnTimeEx=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.VerifyDataOnTimeEx(e,n,r,i,o,s,t,u)}))},e.prototype.VerifyDataInternalOnTimeEx=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.VerifyDataInternalOnTimeEx(e,n,r,i,o,t,a)}))},e.prototype.CreateReference=function(t,e){return this.m_library.CreateReference(t,e)},e}();e.a=i}).call(this,n(17).Promise)},function(t,e){var n,r,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(t){r=s}}();var u,c=[],l=!1,f=-1;function _(){l&&u&&(l=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!l){var t=a(_);l=!0;for(var e=c.length;e;){for(u=c,c=[];++f<e;)u&&u[f].run();f=-1,e=c.length}u=null,l=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function h(t,e){this.fun=t,this.array=e}function E(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new h(t,e)),1!==c.length||l||a(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=E,i.addListener=E,i.once=E,i.off=E,i.removeListener=E,i.removeAllListeners=E,i.emit=E,i.prependListener=E,i.prependOnceListener=E,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e){}])}));
|
|
8
|
+
*/i=function(){"use strict";function t(t){return"function"==typeof t}var i=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},o=0,s=void 0,a=void 0,u=function(t,e){E[o]=t,E[o+1]=e,2===(o+=2)&&(a?a(y):R())},c="undefined"!=typeof window?window:void 0,l=c||{},f=l.MutationObserver||l.WebKitMutationObserver,_="undefined"==typeof self&&void 0!==e&&"[object process]"==={}.toString.call(e),p="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function h(){var t=setTimeout;return function(){return t(y,1)}}var E=new Array(1e3);function y(){for(var t=0;t<o;t+=2)(0,E[t])(E[t+1]),E[t]=void 0,E[t+1]=void 0;o=0}var S,C,d,A,R=void 0;function m(t,e){var n=arguments,r=this,i=new this.constructor(P);void 0===i[g]&&x(i);var o,s=r._state;return s?(o=n[s-1],u((function(){return K(s,i,o,r._result)}))):N(r,i,t,e),i}function T(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(P);return b(e,t),e}_?R=function(){return e.nextTick(y)}:f?(C=0,d=new f(y),A=document.createTextNode(""),d.observe(A,{characterData:!0}),R=function(){A.data=C=++C%2}):p?((S=new MessageChannel).port1.onmessage=y,R=function(){return S.port2.postMessage(0)}):R=void 0===c?function(){try{var t=n(23);return s=t.runOnLoop||t.runOnContext,function(){s(y)}}catch(t){return h()}}():h();var g=Math.random().toString(36).substring(16);function P(){}var v=new w;function I(t){try{return t.then}catch(t){return v.error=t,v}}function U(e,n,r){n.constructor===e.constructor&&r===m&&n.constructor.resolve===T?function(t,e){1===e._state?O(t,e._result):2===e._state?G(t,e._result):N(e,void 0,(function(e){return b(t,e)}),(function(e){return G(t,e)}))}(e,n):r===v?G(e,v.error):void 0===r?O(e,n):t(r)?function(t,e,n){u((function(t){var r=!1,i=function(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}(n,e,(function(n){r||(r=!0,e!==n?b(t,n):O(t,n))}),(function(e){r||(r=!0,G(t,e))}),t._label);!r&&i&&(r=!0,G(t,i))}),t)}(e,n,r):O(e,n)}function b(t,e){var n;t===e?G(t,new TypeError("You cannot resolve a promise with itself")):"function"==typeof(n=e)||"object"==typeof n&&null!==n?U(t,e,I(e)):O(t,e)}function D(t){t._onerror&&t._onerror(t._result),M(t)}function O(t,e){void 0===t._state&&(t._result=e,t._state=1,0!==t._subscribers.length&&u(M,t))}function G(t,e){void 0===t._state&&(t._state=2,t._result=e,u(D,t))}function N(t,e,n,r){var i=t._subscribers,o=i.length;t._onerror=null,i[o]=e,i[o+1]=n,i[o+2]=r,0===o&&t._state&&u(M,t)}function M(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,i=void 0,o=t._result,s=0;s<e.length;s+=3)r=e[s],i=e[s+n],r?K(n,r,i,o):i(o);t._subscribers.length=0}}function w(){this.error=null}var L=new w;function K(e,n,r,i){var o=t(r),s=void 0,a=void 0,u=void 0,c=void 0;if(o){if((s=function(t,e){try{return t(e)}catch(t){return L.error=t,L}}(r,i))===L?(c=!0,a=s.error,s=null):u=!0,n===s)return void G(n,new TypeError("A promises callback cannot return that same promise."))}else s=i,u=!0;void 0!==n._state||(o&&u?b(n,s):c?G(n,a):1===e?O(n,s):2===e&&G(n,s))}var k=0;function x(t){t[g]=k++,t._state=void 0,t._result=void 0,t._subscribers=[]}function B(t,e){this._instanceConstructor=t,this.promise=new t(P),this.promise[g]||x(this.promise),i(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?O(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&O(this.promise,this._result))):G(this.promise,new Error("Array Methods must be provided an Array"))}function F(t){this[g]=k++,this._result=this._state=void 0,this._subscribers=[],P!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof F?function(t,e){try{e((function(e){b(t,e)}),(function(e){G(t,e)}))}catch(e){G(t,e)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}function H(){var t=void 0;if(void 0!==r)t=r;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=F}return B.prototype._enumerate=function(){for(var t=this.length,e=this._input,n=0;void 0===this._state&&n<t;n++)this._eachEntry(e[n],n)},B.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===T){var i=I(t);if(i===m&&void 0!==t._state)this._settledAt(t._state,e,t._result);else if("function"!=typeof i)this._remaining--,this._result[e]=t;else if(n===F){var o=new n(P);U(o,t,i),this._willSettleAt(o,e)}else this._willSettleAt(new n((function(e){return e(t)})),e)}else this._willSettleAt(r(t),e)},B.prototype._settledAt=function(t,e,n){var r=this.promise;void 0===r._state&&(this._remaining--,2===t?G(r,n):this._result[e]=n),0===this._remaining&&O(r,this._result)},B.prototype._willSettleAt=function(t,e){var n=this;N(t,void 0,(function(t){return n._settledAt(1,e,t)}),(function(t){return n._settledAt(2,e,t)}))},F.all=function(t){return new B(this,t).promise},F.race=function(t){var e=this;return i(t)?new e((function(n,r){for(var i=t.length,o=0;o<i;o++)e.resolve(t[o]).then(n,r)})):new e((function(t,e){return e(new TypeError("You must pass an array to race."))}))},F.resolve=T,F.reject=function(t){var e=new this(P);return G(e,t),e},F._setScheduler=function(t){a=t},F._setAsap=function(t){u=t},F._asap=u,F.prototype={constructor:F,then:m,catch:function(t){return this.then(null,t)}},H(),F.polyfill=H,F.Promise=F,F},t.exports=i()}).call(this,n(21),n(22))},function(t,e,n){"use strict";(function(t){var n=function(t,e,n){this.id=t,this.cmd=e,this.params=n,this.origin=window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:""),this.pathname=window.location.pathname},r=function(t,e,n,r){this.id=t,this.cmd=e,this.result=n,this.error=r},i=function(){function e(t,e,n){var r=this;this.m_worker=this.loadWorker(t,e),this.m_worker.onmessage=function(t){var e=t.data;if(-2!=e.id){var i=r.m_promises[e.id-1];i&&(delete r.m_promises[e.id-1],e.error?i.reject(e.error):i.resolve(e.result))}else n(e.result)},this.m_worker.onerror=function(t){r.m_promises.forEach((function(e){e.reject(t.error)})),r.m_promises=new Array},this.m_promises=new Array}return e.prototype.loadWorker=function(t,e){try{if(!t)throw"No worker content";try{var n,r=window,i=r.URL||r.webkitURL;try{(n=new(r.BlobBuilder||r.WebKitBlobBuilder||r.MozBlobBuilder||r.MSBlobBuilder)).append(t),n=n.getBlob()}catch(e){n=new Blob([t])}return new Worker(i.createObjectURL(n))}catch(e){return new Worker("data:application/javascript,"+encodeURIComponent(t))}}catch(t){if(!e)throw Error("Inline worker is not supported");return new Worker(e)}},e.prototype.postMessage=function(e,r){var i=this,o=new n(-1,e,r),s=new t((function(t,e){o.id=i.m_promises.push({resolve:t,reject:e})}));return this.m_worker.postMessage(o),s},e}();e.a=i;!function(){function t(t){this.m_context=t,this.m_initialized=!1;var e=this;self.onmessage=function(t){e.onMessage(t.data)}}t.prototype.postMessage=function(t,e,n,i){var o=new r(t,e,n,i);self.postMessage(o)},t.prototype.onMessage=function(t){var e=this;this.m_initialized?this.m_context[t.cmd].apply(this.m_context,t.params).then((function(n){e.postMessage(t.id,t.cmd,n)}),(function(n){e.postMessage(t.id,t.cmd,null,n)})):setTimeout((function(){e.onMessage(t)}),50)},t.prototype.initialize=function(){this.m_initialized=!0}}()}).call(this,n(17).Promise)},function(t,e,n){"use strict";(function(t){var r=n(1),i=n(9),o=n(10),s=n(14),a=n(20),u=n(4),c=n(13),l=n(2),f=n(8),_=n(0),p=n(11),h=n(15),E=n(16),y=n(7),S=n(5),C=n(12),d=n(6),A=function(){},R=function(){function e(){this.GetDefaultTSPSettings=function(t){var e=null;if(t.TSPServer)e=t.TSPServer;else{for(var n=null,r=t.CAs,i=0;i<r.length&&(!r[i].tspAddress||!r[i].tspAddressPort||(n&&"80"!=r[i].tspAddressPort||(n=r[i]),"80"!=n.tspAddressPort));i++);n&&(e={address:n.tspAddress,port:n.tspAddressPort})}return e},this.MakeExpireDate=function(t){t||(t=300);var e=new Date;return e.setTime(e.getTime()+1e3*t),e},this.m_library=new a.a,this.m_settings=null,this.m_initialized=!1,this.m_kmTypes=null,this.m_kmActiveOperation=!1,this.m_context=null,this.m_pkContext=null,this.m_eventListeners=new Array,this.m_resolveOIDs=!1,this.m_origin=window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:"")}return e.prototype.MapError=function(t){var e=new r.EndUserError;return void 0!==t.GetErrorCode&&void 0!==t.GetMessage?(e.code=t.GetErrorCode(),e.message=t.GetMessage()):void 0!==t.code&&void 0!==t.message?(e.code=t.code,e.message=t.message):(e.code=r.EU_ERROR_UNKNOWN,e.message=t.toString()),e},e.prototype.ProcessArray=function(e,n){var r=this;return new t((function(t,i){var o=Array(),s=0,a=function(){s>=e.length?t(o):(n(e[s]).then((function(t){o.push(t),a()})).catch((function(t){return i(r.MapError(t))})),s++)};a()}))},e.prototype.DataToNamedDataArray=function(t){t=null!=t?t:[],t=Array.isArray(t)?t:[t];for(var e=[],n=0;n<t.length;n++){var r=void 0!==t[n].name&&void 0!==t[n].val;e.push({name:r?t[n].name:"Ім'я відсутнє",val:r?t[n].val:t[n]})}return e},e.prototype.DataToResult=function(t,e){for(var n=[],r=!Array.isArray(t),i=r?[t]:t,o=0;o<i.length;o++){var s=void 0!==i[o].name&&void 0!==i[o].val?{name:i[o].name,val:e[o]}:e[o];n.push(s)}return r?n[0]:n},e.prototype.NamedDataToReference=function(e){var n=this,r=n.m_library;return new t((function(t,i){"string"==typeof e.val?r.StringToBytes(e.val).then((function(n){var i=r.CreateReference(e.name,n);t(i)})).catch((function(t){return i(n.MapError(t))})):setTimeout((function(){var n=r.CreateReference(e.name,e.val);t(n)}),1)}))},e.prototype.OnEvent=function(t){try{var e=this.m_eventListeners[t.type]||this.m_eventListeners[_.EndUserEventType.All];e&&e(t)}catch(t){}},e.prototype.CheckInitialize=function(){var e=this,n=e.m_library;return new t((function(t,i){e.m_initialized?t():n.Load().then((function(){throw n.MakeError(r.EU_ERROR_NOT_INITIALIZED,"")})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.BeginKMOperation=function(){var e=this;return new t((function(t,n){var r=function(){e.m_kmActiveOperation?setTimeout(r,10):(e.m_kmActiveOperation=!0,t())};r()}))},e.prototype.EndKMOperation=function(){this.m_kmActiveOperation=!1},e.prototype.GetCASettings=function(t){if(!t)return null;for(var e=this.m_settings.CAs,n=0;n<e.length;n++)for(var r=e[n].issuerCNs,i=0;i<r.length;i++)if(r[i]==t)return e[n];return null},e.prototype.IsCMPCompatible=function(t,e){return!!t.cmpAddress&&(void 0===t.cmpCompatibility||(t.cmpCompatibility&e)==e)},e.prototype.SetCMPSettings=function(e){var n=this,i=n.m_library,o=this.GetCASettings(e);return new t((function(t,s){if(e&&null==o&&!n.m_settings.allowForeignCAs)throw i.MakeError(r.EU_ERROR_WRITE_SETTINGS,"");var a;a=!(!o||!o.cmpAddress);var u=i.CreateCMPSettings();u.SetUseCMP(a),a&&(u.SetAddress(o.cmpAddress),u.SetPort("80")),i.SetCMPSettings(u).then((function(){t()})).catch((function(t){s(n.MapError(t))}))}))},e.prototype.GetJKSPrivateKey=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){var a={alias:null,info:null};i.EnumJKSPrivateKeys(e,n).then((function(n){if(null!=n)return a.alias=n,i.GetJKSPrivateKey(e,n);t(null)})).then((function(t){a.info=t;for(var e=new Array,n=0;n<t.GetCertificatesCount();n++)e.push(t.GetCertificate(n));return r.ProcessArray(e,(function(t){return i.ParseCertificateEx(t)}))})).then((function(e){var n=new s.a;n.alias=a.alias,n.privateKey=a.info.GetPrivateKey(),n.certificates=new Array,n.digitalStamp=!1;for(var r=0;r<e.length;r++){var o=e[r];if(o.GetSubjType()==i.EU_SUBJECT_TYPE_END_USER){o.GetPublicKeyType()==i.EU_CERT_KEY_TYPE_DSTU4145&&(o.GetKeyUsageType()&i.EU_KEY_USAGE_DIGITAL_SIGNATURE)==i.EU_KEY_USAGE_DIGITAL_SIGNATURE&&(n.digitalStamp=o.GetExtKeyUsages().indexOf(i.EU_UA_OID_EXT_KEY_USAGE_STAMP)>-1);var c=new u.EndUserCertificate;c.data=a.info.GetCertificate(r),c.infoEx=l.a.MapToEndUserCertificateInfoEx(o,new f.a),n.certificates.push(c)}}n.digitalStamp=!1,t(n)})).catch((function(t){return o(r.MapError(t))}))}))},e.prototype.SaveCertificatesInternal=function(e){var n=this,r=this.m_library;return new t((function(t,i){e?Array.isArray(e)?n.ProcessArray(e,(function(t){return r.SaveCertificate(t)})).then((function(){return t()})).catch((function(t){return i(t)})):r.SaveCertificates(e).then((function(){return t()})).catch((function(t){return i(t)})):t()}))},e.prototype.CtxReadPrivateKeyInternal=function(e,n,i,o,s,a,u){void 0===u&&(u=!0);var c=this,l=this.m_library,f={pkContext:null};return e||(e=c.m_context),new t((function(t,_){c.SaveCertificatesInternal(s).then((function(){return c.SetCMPSettings(a)})).then((function(){return null!=n&&null!=i?l.CtxReadPrivateKeyBinary(e,n,i):l.CtxReadPrivateKey(e,o)})).then((function(t){f.pkContext=t;var e=t.GetOwnerInfo();if(!a)return c.SetCMPSettings(e.GetIssuerCN());var n=c.GetCASettings(e.GetIssuerCN());if(!n||-1==n.issuerCNs.indexOf(a))throw l.MakeError(r.EU_ERROR_CERT_NOT_FOUND,"")})).then((function(){t(f.pkContext)})).catch((function(s){null==f.pkContext?c.MapError(s).code==r.EU_ERROR_CERT_NOT_FOUND&&!a&&u?c.SearchPrivateKeyCertificatesWithCMP(n,i,o).then((function(t){return c.CtxReadPrivateKeyInternal(e,n,i,o,t.certs,null,!1)})).then((function(e){t(e)})).catch((function(t){return _(c.MapError(t))})):_(c.MapError(s)):l.CtxFreePrivateKey(f.pkContext).then((function(){_(c.MapError(s))})).catch((function(){_(c.MapError(s))}))}))}))},e.prototype.ReadPrivateKeyInternal=function(e,n,r,i,s){var a=this;return new t((function(t,u){a.ResetPrivateKeyInternal().then((function(){return a.CtxReadPrivateKeyInternal(a.m_context,e,n,r,i,s,!0)})).then((function(e){a.m_pkContext=e;var n=l.a.MapEndUserOwnerInfo(e.GetOwnerInfo(),new o.a);t(n)})).catch((function(t){u(a.MapError(t))}))}))},e.prototype.ResetPrivateKeyInternal=function(){var e=this,n=this.m_library;return new t((function(t,r){null!=e.m_pkContext?n.CtxFreePrivateKey(e.m_pkContext).then((function(){e.m_pkContext=null,t()})).catch((function(t){return r(e.MapError(t))})):t()}))},e.prototype.SearchPrivateKeyCertificatesWithCMP=function(e,n,i,o){var s=this,a=s.m_library,u=s.m_settings.CAs;return new t((function(t,c){(null!=e&&null!=n?a.GetKeyInfoBinary(e,n):a.GetKeyInfo(i)).then((function(e){var n=function(i,l){if(i>=u.length){var f=a.MakeError(l?r.EU_ERROR_CERT_NOT_FOUND:r.EU_ERROR_TRANSMIT_REQUEST,"");c(s.MapError(f))}else{var p=o?_.EndUserCMPCompatibility.DownloadEUCerts:_.EndUserCMPCompatibility.SearchEUCerts;s.IsCMPCompatible(u[i],p)?o&&-1==u[i].issuerCNs.indexOf(o)?n(i+1,l):a.GetCertificatesByKeyInfo(e,[u[i].cmpAddress],["80"]).then((function(e){t({certs:e,CACommonName:u[i].issuerCNs[0]})})).catch((function(t){var e=t.GetErrorCode();e!=r.EU_ERROR_CERT_NOT_FOUND&&e!=r.EU_ERROR_TRANSMIT_REQUEST||(l=l||e==r.EU_ERROR_CERT_NOT_FOUND),n(i+1,l)})):n(i+1,l)}};n(0,!1)})).catch((function(t){return c(s.MapError(t))}))}))},e.prototype.GetUserCertificatesFromCertificates=function(e){var n=this,r=n.m_library;return new t((function(t,i){var o=new Array,s=function(a){r.GetCertificateFromSignedData(a,e).then((function(e){if(null!=e){var n=new u.EndUserCertificate;return n.data=e,o.push(n),r.ParseCertificateEx(e)}for(var i=new Array,s=0;s<o.length;s++){o[s].infoEx.subjType==r.EU_SUBJECT_TYPE_END_USER&&i.push(o[s])}t(i)})).then((function(t){o[a].infoEx=l.a.MapToEndUserCertificateInfoEx(t,new f.a),s(a+1)})).catch((function(t){return i(n.MapError(t))}))};s(0)}))},e.prototype.GeneratePrivateKeyInternal=function(e,n,r,i,o,s,a,u,c,f,_,p,h){var y=this,S=this.m_library;return new t((function(t,C){var d=null==e&&null==r,A=null!=r,R=S.CreatePrivateKeyInfo(),m=null;null!=p&&(m=l.a.MapFromEndUserInfo(p,S.CreateEndUserInfo())),S.GeneratePrivateKeyEx(d,e?e.GetTypeIndex():-1,e?e.GetDevIndex():-1,e?e.GetPassword():r,n,i,o,s,a,u,c,f,_,m,h,R,null!=r).then((function(e){for(var n=new Array,r=0;r<e.size();r++){var i=e.get(r);i=l.a.MapToEndUserRequestInfo(i,new E.a),n.push(i)}var o={key:A?R.GetPrivateKey():null,requests:n};t(o)})).catch((function(t){return C(y.MapError(t))}))}))},e.prototype.GetSignAlgoByCertificate=function(t){switch(t.GetInfoEx().GetPublicKeyType()){case _.EndUserCertKeyType.DSTU4145:return t.GetInfoEx().GetCertHashType()==_.EndUserCertHashType.GOST34311?_.EndUserSignAlgo.DSTU4145WithGOST34311:_.EndUserSignAlgo.DSTU4145WithDSTU7564;case _.EndUserCertKeyType.RSA:return _.EndUserSignAlgo.RSAWithSHA;case _.EndUserCertKeyType.ECDSA:return _.EndUserSignAlgo.ECDSAWithSHA;default:return _.EndUserSignAlgo.Unknown}},e.prototype.GetHashAlgoBySignAlgo=function(t){var e=this.m_library;switch(t){case _.EndUserSignAlgo.DSTU4145WithGOST34311:return _.EndUserHashAlgo.GOST34311;case _.EndUserSignAlgo.RSAWithSHA:case _.EndUserSignAlgo.ECDSAWithSHA:return _.EndUserHashAlgo.SHA256;case _.EndUserSignAlgo.DSTU4145WithDSTU7564:return _.EndUserHashAlgo.DSTU7564_256;default:throw e.MakeError(r.EU_ERROR_BAD_PARAMETER,"")}},e.prototype.CtxSignHashInternal=function(e,n,i,o,s,a){var u=this,c=this.m_library,l=null!=o,f=u.DataToNamedDataArray(i),_=u.DataToNamedDataArray(o);return new t((function(o,p){u.CheckInitialize().then((function(){if(null==e)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");if(l&&f.length!=_.length)throw c.MakeError(r.EU_ERROR_BAD_PARAMETER,"");for(var i=new Array,o=0;o<f.length;o++)i.push({hash:f[o],previousSign:l?_[o]:null});return u.ProcessArray(i,(function(r){return new t((function(t,i){(l?c.CtxAppendSignHash(e,n,r.hash.val,r.previousSign.val,s):c.CtxSignHash(e,n,r.hash.val,s)).then((function(t){return a?t:c.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return i(t)}))}))}))})).then((function(t){var e=u.DataToResult(i,t);o(e)})).catch((function(t){return p(u.MapError(t))}))}))},e.prototype.CtxSignDataInternal=function(e,n,i,o,s,a,u){var c=this,l=this,f=this.m_library,p=null!=o,h=l.DataToNamedDataArray(i),E=l.DataToNamedDataArray(o);return new t((function(y,S){l.CheckInitialize().then((function(){if(null==e)throw f.MakeError(r.EU_ERROR_BAD_CERT,"");if(p&&s&&h.length!=E.length)throw f.MakeError(r.EU_ERROR_BAD_PARAMETER,"");return n!=_.EndUserSignAlgo.Unknown?null:f.CtxEnumOwnCertificates(e,0)})).then((function(t){if(n==_.EndUserSignAlgo.Unknown&&null!=t&&(n=l.GetSignAlgoByCertificate(t)),!s)return h;var e=l.GetHashAlgoBySignAlgo(n);return l.HashData(e,h,!0)})).then((function(r){for(var i=new Array,o=p?E.length:r.length,c=0;c<o;c++)i.push({dataOrHash:null!=r?r[c]:null,previousSign:p?E[c]:null});return l.ProcessArray(i,(function(r){return new t((function(t,i){(p?s?f.CtxAppendSignHash(e,n,r.dataOrHash.val,r.previousSign.val,a):f.CtxAppendSign(e,n,null,r.previousSign.val,a):s?f.CtxSignHash(e,n,r.dataOrHash.val,a):f.CtxSign(e,n,r.dataOrHash.val,!1,a)).then((function(t){return u?t:f.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return i(t)}))}))}))})).then((function(t){var e=c.DataToResult(p&&!s?o:i,t);y(e)})).catch((function(t){return S(l.MapError(t))}))}))},e.prototype.LoadTaxReportPKey=function(e,n,i){var o=this,s=this.m_library;return new t((function(t,a){var u=new A;if(Array.isArray(e)||(e=[e]),e.length>2)a(o.MapError(s.MakeError(r.EU_ERROR_BAD_PARAMETER,"")));else{var c=function(l,f){var p=n[l],h=e[f];s.CtxGetOwnCertificate(h,_.EndUserCertKeyType.DSTU4145,p).then((function(e){if(i&&p&_.EndUserKeyUsage.DigitalSignature&&!(e.GetInfoEx().GetExtKeyUsages().indexOf(s.EU_UA_OID_EXT_KEY_USAGE_STAMP)>-1))throw s.MakeError(r.EU_ERROR_BAD_PARAMETER,"");if(p&_.EndUserKeyUsage.DigitalSignature)u.signPKCtx=h,u.signCert=e;else{if(!(p&_.EndUserKeyUsage.KeyAgreement))throw s.MakeError(r.EU_ERROR_BAD_PARAMETER,"");u.envelopPKCtx=h,u.envelopCert=e}l+1<n.length?c(l+1,0):t(u)})).catch((function(t){if(t.GetErrorCode()==r.EU_ERROR_CERT_NOT_FOUND){if(f+1<e.length)return void c(l,f+1);t=s.MakeError(r.EU_ERROR_BAD_PARAMETER,"")}a(o.MapError(t))}))};c(0,0)}}))},e.prototype.ProtectTaxReport=function(e,n,i,o,s,a,u){var c=this,l=this.m_library,f=new p.b;f.name=a.name;var _=function(e,n){return new t((function(t,r){return l.CtxSign(e.signPKCtx,c.GetSignAlgoByCertificate(e.signCert),n,!1,!0).then((function(t){return l.BASE64Decode(t)})).then((function(t){return l.AppendCryptoHeader(l.EU_HEADER_CA_TYPE,l.EU_HEADER_PART_TYPE_SIGNED,t)})).then((function(e){t(e)})).catch((function(t){return r(c.MapError(t))}))}))},h=function(e,n){return new t((function(r,i){return l.CtxEnvelop(e.envelopPKCtx,[s],l.EU_RECIPIENT_APPEND_ISSUER_AND_SERIAL,!1,!1,n).then((function(t){return l.BASE64Decode(t)})).then((function(t){return l.AppendCryptoHeader(l.EU_HEADER_CA_TYPE,l.EU_HEADER_PART_TYPE_ENCRYPTED,t)})).then((function(n){var r=e.envelopCert,i=l.EU_KEY_USAGE_DIGITAL_SIGNATURE|l.EU_KEY_USAGE_KEY_AGREEMENT;return i==(r.GetInfoEx().GetKeyUsageType()&i)?n:function(e,n){return new t((function(t,r){return l.AppendCryptoHeader(l.EU_HEADER_CA_TYPE,l.EU_HEADER_PART_TYPE_CERTCRYPT,e).then((function(e){var r=new Uint8Array(e.byteLength+n.byteLength);r.set(new Uint8Array(e),0),r.set(new Uint8Array(n),e.byteLength),t(r)})).catch((function(t){return r(c.MapError(t))}))}))}(r.GetData(),n)})).then((function(t){return _(e,t)})).then((function(t){r({reportData:t,ownCert:e.envelopCert.GetData()})})).catch((function(t){return i(c.MapError(t))}))}))};return new t((function(s,p){new t((function(t,e){t(a.data)})).then((function(t){return null!=e?_(e,t):t})).then((function(t){return null!=n?_(n,t):t})).then((function(t){return null!=i?_(i,t):t})).then((function(t){return u&&(f.signedData=t),null!=n||null!=i?h(null!=i?i:n,t):{reportData:t,ownCert:e.signCert.GetData()}})).then((function(t){return l.AppendTransportHeader(l.EU_HEADER_CA_TYPE,a.name,o,t.ownCert,t.reportData)})).then((function(t){f.data=t,f.error=c.MapError(l.MakeError(r.EU_ERROR_NONE,"")),s(f)})).catch((function(t){f.error=c.MapError(t),s(f)}))}))},e.prototype.UnprotectTaxReceipt=function(e,n){var i=this,o=this.m_library,s=new p.a;s.data=null,s.receiptNumber=0,s.initiators=[],s.error=null;return new t((function(a,u){var c;(c=n.data,new t((function(t,e){o.ParseTransportHeader(c).then((function(e){s.receiptNumber=e.GetReceiptNumber(),t(e.GetCryptoData())})).catch((function(n){n.GetErrorCode()==r.EU_ERROR_PKI_FORMATS_FAILED?t(c):e(i.MapError(n))}))}))).then((function(n){var c=function(n){(function(n){var a={headerInfo:null};return new t((function(t,u){o.ParseCryptoHeader(n).then((function(t){a.headerInfo=t;var n=t.GetCryptoData();switch(t.GetHeaderType()){case o.EU_HEADER_PART_TYPE_SIGNED:return o.VerifyDataInternalOnTimeEx(n,0,null,!1,!1);case o.EU_HEADER_PART_TYPE_ENCRYPTED:return o.CtxDevelop(e,n);case o.EU_HEADER_PART_TYPE_STAMPED:case o.EU_HEADER_PART_TYPE_CERTCRYPT:return null;default:throw o.MakeError(r.EU_ERROR_PKI_FORMATS_FAILED,"")}})).then((function(e){if(null!=e){var r=a.headerInfo.GetHeaderType()==o.EU_HEADER_PART_TYPE_SIGNED?l.a.MapToEndUserSignInfo(e,new S.a):l.a.MapToEndUserSenderInfo(e,new C.a);s.initiators.push(r),n=e.GetData()}else n=n.slice(a.headerInfo.GetHeaderSize()+a.headerInfo.GetCryptoData().length,n.length);t(n)})).catch((function(e){e.GetErrorCode()==r.EU_ERROR_BAD_PARAMETER?t(null):u(i.MapError(e))}))}))})(n).then((function(t){if(null==t)return s.data=n,s.error=i.MapError(o.MakeError(r.EU_ERROR_NONE,"")),void a(s);c(t)})).catch((function(t){return u(i.MapError(t))}))};c(n)})).catch((function(t){return u(i.MapError(t))}))}))},e.prototype.GetKSPSettings=function(t){var e;if(!this.m_settings.KSPs)return null;if("string"==typeof t){for(e=0;e<this.m_settings.KSPs.length;e++)if(this.m_settings.KSPs[e].name==t)return this.m_settings.KSPs[e];return null}if("number"==typeof t){for(e=0;e<this.m_settings.KSPs.length;e++)if(this.m_settings.KSPs[e].ksp==t)return this.m_settings.KSPs[e];return null}return null},e.prototype.GetPollingInterval=function(t){return t&&"number"==typeof t.pollingInterval?1e3*t.pollingInterval:1e3},e.prototype.MakeNewCertificateKSP=function(e,n,i,o,s,a,c,f,_,p,h,E,y,S,C,d,A,R){void 0===d&&(d=!1),void 0===A&&(A=null),void 0===R&&(R=null);var m=this,T=m.m_library,g={kspSettings:null,userId:null,operationId:null},P={key:null,certs:null};return new t((function(f,h){m.CheckInitialize().then((function(){return m.BeginKMOperation()})).then((function(){var t=null;return null!=e&&(t=l.a.MapFromKeyMedia(e,T.CreateKeyMedia())),d?null:m.ReadPrivateKeyInternal(n,i,t,null,S)})).then((function(t){return C&&!d?T.CtxGetOwnEUserParams(m.m_pkContext):null})).then((function(t){return C?T.CtxModifyOwnEUserParams(m.m_pkContext,C.phone,C.EMail):null})).then((function(){if(g.userId=A,g.kspSettings=m.GetKSPSettings(R),!g.kspSettings||!g.kspSettings.address)throw T.MakeError(r.EU_ERROR_BAD_PARAMETER,"");var t=[];t[T.EU_KEYS_TYPE_DSTU_AND_ECDH_WITH_GOSTS]="DSTU4145",t[T.EU_KEYS_TYPE_RSA_WITH_SHA]="RSA",s!=T.EU_KEYS_LENGTH_DS_UA_FILE&&s!=T.EU_KEYS_LENGTH_DS_UA_CERT||(s=T.EU_KEYS_LENGTH_DS_UA_257),c!=T.EU_KEYS_LENGTH_KEP_UA_FILE&&c!=T.EU_KEYS_LENGTH_KEP_UA_CERT||(c=T.EU_KEYS_LENGTH_KEP_UA_431),p!=T.EU_KEYS_LENGTH_DS_RSA_FILE&&p!=T.EU_KEYS_LENGTH_DS_RSA_CERT||(p=T.EU_KEYS_LENGTH_DS_RSA_2048);var e=[];e[T.EU_KEYS_LENGTH_DS_UA_191]=191,e[T.EU_KEYS_LENGTH_DS_UA_257]=257,e[T.EU_KEYS_LENGTH_DS_UA_307]=307;var n=[];n[T.EU_KEYS_LENGTH_KEP_UA_257]=257,n[T.EU_KEYS_LENGTH_KEP_UA_431]=431,n[T.EU_KEYS_LENGTH_KEP_UA_571]=571;var i=[];i[T.EU_KEYS_LENGTH_DS_RSA_1024]=1024,i[T.EU_KEYS_LENGTH_DS_RSA_2048]=2048,i[T.EU_KEYS_LENGTH_DS_RSA_3072]=3072,i[T.EU_KEYS_LENGTH_DS_RSA_4096]=4096;var u=t[o]||null,l=e[s]||0,f=n[c]||0,h=t[_]||null,E=i[p]||0,y="Веб-сайт: %s".replace("%s",g.kspSettings.systemId||m.m_origin),S="Генерація ос. ключа у системі %s".replace("%s",g.kspSettings.systemId||m.m_origin);return T.SServerClientGeneratePrivateKeyAsync(g.kspSettings.address,g.kspSettings.port,g.userId,y,S,u,l,a,f,h,E)})).then((function(e){g.operationId=e;var n=m.GetPollingInterval(g.kspSettings),i=m.MakeExpireDate(300);return new t((function(t,e){var o=function(i){new Date>i?e(T.MakeError(r.EU_ERROR_TRANSMIT_REQUEST,"")):m.m_library.SServerClientCheckGeneratePrivateKeyStatus(g.kspSettings.address,g.kspSettings.port,g.userId,g.operationId).then((function(e){null!=e?t(e):setTimeout((function(){o(i)}),n)})).catch((function(t){e(m.MapError(t))}))};o(i)}))})).then((function(t){for(var e=null,n=null,r=null,i=0;i<t.size();i++){var o=t.get(i);switch(o.GetRequestType()){case T.EU_KEYS_REQUEST_TYPE_UA_DS:e=o.GetRequest();break;case T.EU_KEYS_REQUEST_TYPE_UA_KEP:n=o.GetRequest();break;case T.EU_KEYS_REQUEST_TYPE_INTERNATIONAL:r=o.GetRequest()}}return m.m_library.CtxMakeNewOwnCertificateWithCR(m.m_pkContext,e,n,r,null)})).then((function(){var t="Веб-сайт: %s".replace("%s",g.kspSettings.systemId||m.m_origin),e="Ідентифікація клієнта у системі %s".replace("%s",g.kspSettings.systemId||m.m_origin);return T.SServerClientSignHashesAsync(g.kspSettings.address,g.kspSettings.port,g.userId,t,e,["Зчитування ос. ключа"],["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="],"DSTU4145")})).then((function(e){g.operationId=e;var n=m.GetPollingInterval(g.kspSettings),i=m.MakeExpireDate(300);return new t((function(t,e){var o=function(i){new Date>i?e(T.MakeError(r.EU_ERROR_TRANSMIT_REQUEST,"")):T.SServerClientCheckSignHashesStatus(g.kspSettings.address,g.kspSettings.port,g.userId,g.operationId).then((function(s){if(null!=s)if(1==s.size()){var a=s.get(0);if(a.GetError()==r.EU_ERROR_NONE){var c=a.GetSignature(),f=new u.EndUserCertificate;T.CtxGetSignerInfo(m.m_context,0,c).then((function(e){l.a.MapToEndUserCertificate(e,f),t([f])})).catch((function(t){return e(m.MapError(t))}))}else e(T.MakeError(a.GetError(),a.GetStatus()))}else e(T.MakeError(r.EU_ERROR_PKI_FORMATS_FAILED,""));else setTimeout((function(){o(i)}),n)})).catch((function(t){e(m.MapError(t))}))};o(i)}))})).then((function(t){m.EndKMOperation(),P.certs=t,f(P)})).catch((function(t){m.ResetPrivateKeyInternal().then((function(){m.EndKMOperation(),h(m.MapError(t))})).catch((function(){m.EndKMOperation(),h(m.MapError(t))}))}))}))},e.prototype.AddEventListener=function(e,n){var i=this,o=i.m_library;return new t((function(t,s){if([_.EndUserEventType.None,_.EndUserEventType.All,_.EndUserEventType.ConfirmKSPOperation].indexOf(e)<0)s(i.MapError(o.MakeError(r.EU_ERROR_BAD_PARAMETER,"")));else{switch(e){case _.EndUserEventType.None:i.m_eventListeners=[];break;case _.EndUserEventType.All:i.m_eventListeners=[],i.m_eventListeners[e]=n;break;default:i.m_eventListeners[e]=n}t()}}))},e.prototype.GetLibraryInfo=function(e){var n=this,r=this.m_library;return new t((function(t,i){var o=new c.b;o.supported=r.IsSupported(),o.isSignAgentSupported=r.IsSignAgentSupported(),o.isWebExtensionSupported=r.IsWebExtensionSupported(),o.isNPAPISupported=r.IsNPAPISupported(),o.isActiveXSupported=r.IsActiveXSupported(),o.isWebExtensionInstalled=r.IsWebExtensionInstalled(),o.nativeLibraryInstallURLs=r.GetInstallURL(!0,e),o.nativeLibraryInstallURL=o.nativeLibraryInstallURLs?o.nativeLibraryInstallURLs[0]:null,o.nativeLibraryUpdateURLs=r.GetUpdateURL(!0,e),o.nativeLibraryUpdateURL=o.nativeLibraryUpdateURLs?o.nativeLibraryUpdateURLs[0]:null,o.webExtensionInstallURL=r.GetWebExtensionInstallURL(),o.helpURL=r.GetHelpURL(e),o.supported?r.Load().then((function(){o.loaded=!0,r.GetVersion().then((function(e){o.version=e,t(o)})).catch((function(t){return i(n.MapError(t))}))})).catch((function(e){var i=n.MapError(e);o.loaded=!1,o.isNativeLibraryNeedUpdate=r.IsLibraryVersionNotSupportedError(i.code),t(o)})):t(o)}))},e.prototype.IsInitialized=function(){var e=this;return new t((function(t,n){t(e.m_initialized)}))},e.prototype.Initialize=function(e){var n=this,r=n.m_library;n.m_settings=e;var i={offline:!0,tspSettings:null,useOCSP:!1};return new t((function(t,o){r.Load().then((function(){return r.SetRuntimeParameter(r.EU_SAVE_SETTINGS_PARAMETER,r.EU_SETTINGS_ID_PROXY)})).then((function(){return r.SetUIMode(!1)})).then((function(){return r.Initialize()})).then((function(){return r.SetUIMode(!1)})).then((function(){return r.SetCharset(n.m_settings.encoding)})).then((function(){return r.SetLanguage(n.m_settings.language)})).then((function(){return r.InitializeMandatorySettings()})).then((function(){var t=r.CreateFileStoreSettings();return t.SetPath(""),t.SetSaveLoadedCerts(!0),r.SetFileStoreSettings(t)})).then((function(){return null!=n.m_settings.CAs&&"string"==typeof n.m_settings.CAs?r.DownloadData(n.m_settings.CAs,"json"):n.m_settings.CAs})).then((function(t){n.m_settings.CAs=t,i.tspSettings=n.GetDefaultTSPSettings(n.m_settings);for(var e=0;e<t.length;e++)if(t[e].ocspAccessPointAddress&&t[e].ocspAccessPointPort){i.useOCSP=!0;break}i.offline=!i.tspSettings&&!i.useOCSP;var o=r.CreateModeSettings();return o.SetOfflineMode(i.offline),r.SetModeSettings(o)})).then((function(){var t=r.CreateTSPSettings();return t.SetGetStamps(!!i.tspSettings),i.tspSettings&&(t.SetAddress(i.tspSettings.address),t.SetPort(i.tspSettings.port)),r.SetTSPSettings(t)})).then((function(){var t=r.CreateOCSPSettings();return t.SetUseOCSP(i.useOCSP),i.useOCSP&&(t.SetBeforeStore(!0),t.SetAddress("czo.gov.ua"),t.SetPort("80")),r.SetOCSPSettings(t)})).then((function(){var t=r.CreateOCSPAccessInfoModeSettings();return t.SetEnabled(i.useOCSP),r.SetOCSPAccessInfoModeSettings(t)})).then((function(){if(i.useOCSP){for(var t=new Array,e=n.m_settings.CAs,o=0;o<e.length;o++)for(var s=0;s<e[o].issuerCNs.length;s++){var a=r.CreateOCSPAccessInfoSettings();a.SetAddress(e[o].ocspAccessPointAddress),a.SetPort(e[o].ocspAccessPointPort),a.SetIssuerCN(e[o].issuerCNs[s]),t.push(a)}return r.SetOCSPAccessInfoSettings(t)}})).then((function(){return null!=e.CACertificates&&"string"==typeof e.CACertificates?r.DownloadData(e.CACertificates,"binary"):e.CACertificates})).then((function(t){if(null!=e.CACertificates)return r.SaveCertificates(t)})).then((function(){var t=!!e.TSLAddress,n=r.CreateTSLSettings();return n.SetUseTSL(t),n.SetAutoDownloadTSL(!!t),n.SetTSLAddress(t?e.TSLAddress:""),r.SetTSLSettings(n)})).then((function(){return r.SetRuntimeParameter(r.EU_RESOLVE_OIDS_PARAMETER,n.m_resolveOIDs)})).then((function(){if("number"==typeof n.m_settings.connectionTimeout)return r.SetRuntimeParameter(r.EU_CONNECTIONS_TIMEOUT_PARAMETER,n.m_settings.connectionTimeout)})).then((function(){if("number"==typeof e.ocspResponseExpireTime)return r.SetOCSPResponseExpireTime(n.m_settings.ocspResponseExpireTime)})).then((function(){return r.CtxCreate()})).then((function(t){return n.m_context=t,r.CtxSetParameter(t,r.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,n.m_resolveOIDs)})).then((function(){if(n.m_settings.useSLoginPrivateKey)return r.CtxSetParameter(n.m_context,r.EU_USE_SLOGIN_PRIVATE_KEY_CONTEXT_PARAMETER,!0)})).then((function(){return r.SetRuntimeParameter(r.EU_CHECK_CERT_CHAIN_ON_SIGN_TIME_PARAMETER,!0)})).then((function(){return null!=n.m_settings.signInfoTmpl&&"string"==typeof n.m_settings.signInfoTmpl?r.DownloadData(n.m_settings.signInfoTmpl,""):n.m_settings.signInfoTmpl})).then((function(e){n.m_settings.signInfoTmpl=e,n.m_initialized=!0,t()})).catch((function(t){return o(n.MapError(t))}))}))},e.prototype.SetLanguage=function(e){var n=this,r=n.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){return r.SetLanguage(e)})).then((function(){n.m_settings.language=e})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.SetRuntimeParameter=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return i.SetRuntimeParameter(e,n)})).then((function(){return e!=i.EU_USE_SLOGIN_PRIVATE_KEY?null:i.CtxSetParameter(r.m_context,e,n)})).then((function(){t()})).catch((function(t){return o(r.MapError(t))}))}))},e.prototype.GetStorageParameter=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return i.GetStorageParameter(n,e)})).then((function(e){t(e)})).catch((function(t){return o(r.MapError(t))}))}))},e.prototype.SetStorageParameter=function(e,n,r){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.SetStorageParameter(r,e,n)})).then((function(){t()})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.GetCAs=function(){var e=this;return new t((function(t,n){e.CheckInitialize().then((function(){t(e.m_settings.CAs)})).catch((function(t){return n(e.MapError(t))}))}))},e.prototype.GetProxySettings=function(){var e=this,n=e.m_library;return new t((function(t,r){e.CheckInitialize().then((function(){return n.GetProxySettings()})).then((function(e){var n=l.a.MapToProxySettings(e,new i.b);t(n)})).catch((function(t){return r(e.MapError(t))}))}))},e.prototype.SetProxySettings=function(e){var n=this,r=n.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){var t=l.a.MapFromProxySettings(e,r.CreateProxySettings());return r.SetProxySettings(t)})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.GetHostInfo=function(){var e=this,n=e.m_library;return new t((function(t,r){e.CheckInitialize().then((function(){return n.GetHostInfo()})).then((function(e){t(e)})).catch((function(t){return r(e.MapError(t))}))}))},e.prototype.GetKeyMedias=function(){var e=this,n=e.m_library,r=new Array,i=null;return e.m_settings.allowedKeyMediaDevices&&(i={},e.m_settings.allowedKeyMediaDevices.forEach((function(t){i[t.type]=t.devices}))),new t((function(t,o){e.CheckInitialize().then((function(){return e.BeginKMOperation()})).then((function(){return e.m_kmTypes?e.m_kmTypes:n.GetKeyMediaTypes()})).then((function(t){e.m_kmTypes=t;var i=e.m_settings.allowedKeyMediaTypes;r=new Array;for(var o=0;o<t.length;o++){var s=t[o];(!i||i.indexOf(s)>=0)&&r.push(o)}return n.GetKeyMediaDevices(r)})).then((function(n){for(var o=new Array,s=0;s<n.length;s++)for(var a=r[s],c=e.m_kmTypes[a],l=n[s],f=i&&i[c]?i[c]:null,_=0;_<l.length;_++)if(!f||-1!=f.indexOf(l[_])){var p=new u.EndUserKeyMedia;p.typeIndex=a,p.devIndex=_,p.password=null,p.type=c,p.device=l[_],p.visibleName=p.device+"("+p.type+")",o.push(p)}e.EndKMOperation(),t(o)})).catch((function(t){e.EndKMOperation(),o(e.MapError(t))}))}))},e.prototype.GetJKSPrivateKeys=function(e){var n=this;return new t((function(t,r){n.CheckInitialize().then((function(){var i=new Array,o=function(s){n.GetJKSPrivateKey(e,s).then((function(e){e?(i.push(e),o(s+1)):t(i)})).catch((function(t){return r(n.MapError(t))}))};o(0)})).catch((function(t){return r(n.MapError(t))}))}))},e.prototype.IsPrivateKeyReaded=function(){var e=this;return new t((function(t,n){e.CheckInitialize().then((function(){t(null!=e.m_pkContext)})).catch((function(t){return n(e.MapError(t))}))}))},e.prototype.ResetPrivateKey=function(){var e=this;return new t((function(t,n){e.CheckInitialize().then((function(){return e.ResetPrivateKeyInternal()})).then((function(){t()})).catch((function(t){return n(e.MapError(t))}))}))},e.prototype.ResetOperationKSP=function(){var e=this,n=this.m_library;return new t((function(t,i){e.CheckInitialize().then((function(){throw n.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.ReadPrivateKey=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){i.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(e,o.CreateKeyMedia());return i.ReadPrivateKeyInternal(null,null,t,n,r)})).then((function(e){i.EndKMOperation(),t(e)})).catch((function(t){i.EndKMOperation(),s(i.MapError(t))}))}))},e.prototype.ReadPrivateKeyBinary=function(e,n,r,i){var o=this;return new t((function(t,s){o.CheckInitialize().then((function(){return o.ReadPrivateKeyInternal(e,n,null,r,i)})).then((function(e){t(e)})).catch((function(t){return s(o.MapError(t))}))}))},e.prototype.ReadPrivateKeySIM=function(e,n,i,o){var s=this,a=this.m_library;return new t((function(t,e){s.CheckInitialize().then((function(){throw a.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){return e(s.MapError(t))}))}))},e.prototype.ReadPrivateKeyKSP=function(e,n,i,o,s,a){var u=this,c=this.m_library;return new t((function(t,e){u.CheckInitialize().then((function(){throw c.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){return e(u.MapError(t))}))}))},e.prototype.GetOwnCertificates=function(){return this.CtxGetOwnCertificates(this.m_pkContext)},e.prototype.GetOwnEUserParams=function(){var e=this,n=e.m_library;return new t((function(t,i){e.CheckInitialize().then((function(){if(null==e.m_pkContext)throw n.MakeError(r.EU_ERROR_BAD_CERT,"");return n.CtxGetOwnEUserParams(e.m_pkContext)})).then((function(e){var n=l.a.MapToEndUserParams(e,new h.a);t(n)})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.ChangeOwnCertificatesStatus=function(e,n){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){if(null==i.m_pkContext)throw o.MakeError(r.EU_ERROR_BAD_CERT,"");return o.CtxChangeOwnCertificatesStatus(i.m_pkContext,e,n)})).then((function(){t()})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.MakeNewCertificate=function(e,n,r,i,o,s,a,u,c,f,_,p,h,E,y,S,C,d){void 0===S&&(S=!1),void 0===C&&(C=null),void 0===d&&(d=null);var A=this,R=A.m_library,m={key:null,certs:null};return null!=C||null!=d?A.MakeNewCertificateKSP(e,n,r,i,o,s,a,u,c,f,_,p,h,E,y,S,C,d):new t((function(C,d){A.CheckInitialize().then((function(){return A.BeginKMOperation()})).then((function(){var t=null;return null!=e&&(t=l.a.MapFromKeyMedia(e,R.CreateKeyMedia())),S?null:A.ReadPrivateKeyInternal(n,r,t,null,E)})).then((function(t){return y&&!S?R.CtxGetOwnEUserParams(A.m_pkContext):null})).then((function(t){return y?R.CtxModifyOwnEUserParams(A.m_pkContext,y.phone,y.EMail):null})).then((function(){return S?null:A.ResetPrivateKeyInternal()})).then((function(){if(S)return new t((function(t,n){R.CtxMakeNewOwnCertificate(A.m_pkContext,i,o,s,a,u,c,f,_).then((function(){return A.ResetPrivateKeyInternal()})).then((function(){var t=l.a.MapFromKeyMedia(e,R.CreateKeyMedia());return p&&p.password!=e.password?R.ChangePrivateKeyPassword(t,p.password):null})).then((function(){t(null)})).catch((function(t){n(A.MapError(t))}))}));var E=null,y=null;return e&&(E=l.a.MapFromKeyMedia(e,R.CreateKeyMedia())),p&&(y=l.a.MapFromKeyMedia(p,R.CreateKeyMedia())),R.MakeNewCertificate(E,n,r,i,o,s,a,u,c,f,_,y,h)})).then((function(t){m.key=t;var n=null;return(S&&e||p)&&(n=l.a.MapFromKeyMedia(p||e,R.CreateKeyMedia())),A.SearchPrivateKeyCertificatesWithCMP(t,h,n,E)})).then((function(t){return A.GetUserCertificatesFromCertificates(t.certs)})).then((function(t){A.EndKMOperation(),m.certs=t,C(m)})).catch((function(t){A.EndKMOperation(),d(A.MapError(t))}))}))},e.prototype.MakeDeviceCertificate=function(e,n,i,o,s){var a=this,c=a.m_library;return new t((function(_,p){a.CheckInitialize().then((function(){if(null==a.m_pkContext)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");var t=a.m_pkContext.GetOwnerInfo(),u=a.GetCASettings(t.GetIssuerCN());if(!u||!u.cmpAddress||""==u.cmpAddress)throw c.MakeError(r.EU_ERROR_BAD_PARAMETER,"");return c.CtxMakeDeviceCertificate(a.m_pkContext,e,n,i,o,s,u.cmpAddress,"80")})).then((function(e){return a.ProcessArray(e,(function(e){return new t((function(t,n){c.ParseCertificateEx(e).then((function(n){var r=new u.EndUserCertificate;r.data=e,r.infoEx=l.a.MapToEndUserCertificateInfoEx(n,new f.a),t(r)})).catch((function(t){return n(t)}))}))}))})).then((function(t){_(t)})).catch((function(t){a.EndKMOperation(),p(a.MapError(t))}))}))},e.prototype.SetKeyMediaUserPassword=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return r.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(n,i.CreateKeyMedia());return r.m_library.SetKeyMediaUserPassword(e,t)})).then((function(){r.EndKMOperation(),t()})).catch((function(t){r.EndKMOperation(),o(r.MapError(t))}))}))},e.prototype.ChangePrivateKeyPassword=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return r.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(e,i.CreateKeyMedia());return r.m_library.ChangePrivateKeyPassword(t,n)})).then((function(){r.EndKMOperation(),t()})).catch((function(t){r.EndKMOperation(),o(r.MapError(t))}))}))},e.prototype.ChangePrivateKeyPasswordBinary=function(e,n,r){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.ChangeSoftwarePrivateKeyPassword(e,n,r)})).then((function(e){t(e),t()})).catch((function(t){s(i.MapError(t))}))}))},e.prototype.GeneratePrivateKey=function(e,n,r,i,o,s,a,u,c,f,_,p){var h=this,E=h.m_library;return new t((function(t,y){h.CheckInitialize().then((function(){return h.BeginKMOperation()})).then((function(){var t=null;return e&&(t=l.a.MapFromKeyMedia(e,E.CreateKeyMedia())),h.GeneratePrivateKeyInternal(t,n,null,r,i,o,s,a,u,c,f,_,p)})).then((function(e){h.EndKMOperation(),t(e)})).catch((function(t){h.EndKMOperation(),y(h.MapError(t))}))}))},e.prototype.GeneratePrivateKeyBinary=function(e,n,r,i,o,s,a,u,c,l,f){var _=this;return new t((function(t,p){_.CheckInitialize().then((function(){return _.BeginKMOperation()})).then((function(){return _.GeneratePrivateKeyInternal(null,!1,e,n,r,i,o,s,a,u,c,l,f)})).then((function(e){_.EndKMOperation(),t(e)})).catch((function(t){_.EndKMOperation(),p(_.MapError(t))}))}))},e.prototype.GetKeyInfo=function(e){var n=this,r=n.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){return n.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(e,r.CreateKeyMedia());return r.GetKeyInfo(t)})).then((function(e){n.EndKMOperation(),t(e.GetPrivateKeyInfo())})).catch((function(t){n.EndKMOperation(),i(n.MapError(t))}))}))},e.prototype.GetKeyInfoBinary=function(e,n){var r=this,i=r.m_library;return new t((function(t,o){r.CheckInitialize().then((function(){return i.GetKeyInfoBinary(e,n)})).then((function(e){t(e.GetPrivateKeyInfo())})).catch((function(t){o(r.MapError(t))}))}))},e.prototype.GetClientRegistrationTokenKSP=function(e,n){var i=this,o=i.m_library;return new t((function(t,e){i.CheckInitialize().then((function(){throw o.MakeError(r.EU_ERROR_NOT_SUPPORTED,"")})).catch((function(t){e(i.MapError(t))}))}))},e.prototype.HashData=function(e,n,r){var i=this,o=this.m_library,s=i.DataToNamedDataArray(n);return new t((function(a,u){i.CheckInitialize().then((function(){return i.ProcessArray(s,(function(n){return new t((function(t,s){o.CtxHash(i.m_context,e,null,n.val).then((function(t){return r?t:o.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return s(t)}))}))}))})).then((function(t){var e=i.DataToResult(n,t);a(e)})).catch((function(t){u(i.MapError(t))}))}))},e.prototype.GetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.GetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){s.context=null,a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context?o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))})):c(i.MapError(t))}))}))},e.prototype.SignData=function(t,e){return void 0===e&&(e=!1),this.SignDataEx(_.EndUserSignAlgo.Unknown,t,!0,!0,e)},e.prototype.SignDataInternal=function(t,e,n){return void 0===n&&(n=!1),this.SignDataEx(_.EndUserSignAlgo.Unknown,e,!1,t,n)},e.prototype.SignHash=function(t,e,n,r){return this.CtxSignHashInternal(this.m_pkContext,t,e,null,n,r)},e.prototype.SignDataEx=function(t,e,n,r,i){return this.CtxSignDataInternal(this.m_pkContext,t,e,null,n,r,i)},e.prototype.AppendSign=function(t,e,n,r,i){return this.CtxSignDataInternal(this.m_pkContext,t,e,n,null!=e,r,i)},e.prototype.AppendSignHash=function(t,e,n,r,i){return this.CtxSignHashInternal(this.m_pkContext,t,e,n,r,i)},e.prototype.GetSignValue=function(t,e,n,r){return void 0===r&&(r=!1),this.CtxGetSignValue(this.m_pkContext,t,e,n,r)},e.prototype.VerifyHash=function(e,n,r){void 0===r&&(r=-1);var i=this,o=this.m_library;return new t((function(s,a){i.CheckInitialize().then((function(){return-1==r?o.GetSignsCount(n):1})).then((function(s){var a=new Array;if(-1!=r)a.push(r);else for(var u=0;u<s;u++)a.push(u);return i.ProcessArray(a,(function(r){return new t((function(t,s){var a=new S.a;o.VerifyHashOnTimeEx(e,r,n,null,!1,!1).then((function(t){return l.a.MapToEndUserSignInfo(t,a),o.GetSignTimeInfo(r,n)})).then((function(t){return a.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),o.GetSignType(r,n)})).then((function(e){a.signLevel=e,t(a)})).catch((function(t){return s(i.MapError(t))}))}))}))})).then((function(t){s(-1!=r?t[0]:t)})).catch((function(t){return a(i.MapError(t))}))}))},e.prototype.VerifyData=function(e,n,r){void 0===r&&(r=-1);var i=this,o=this.m_library;return new t((function(s,a){i.CheckInitialize().then((function(){return-1==r?o.GetSignsCount(n):1})).then((function(s){var a=new Array;if(-1!=r)a.push(r);else for(var u=0;u<s;u++)a.push(u);return i.ProcessArray(a,(function(r){return new t((function(t,s){var a=new S.a;o.VerifyDataOnTimeEx(e,r,n,null,!1,!1).then((function(t){return l.a.MapToEndUserSignInfo(t,a),o.GetSignTimeInfo(r,n)})).then((function(t){return a.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),o.GetSignType(r,n)})).then((function(e){a.signLevel=e,t(a)})).catch((function(t){return s(i.MapError(t))}))}))}))})).then((function(t){s(-1!=r?t[0]:t)})).catch((function(t){return a(i.MapError(t))}))}))},e.prototype.VerifyDataInternal=function(e,n){void 0===n&&(n=-1);var r=this,i=this.m_library;return new t((function(o,s){r.CheckInitialize().then((function(){return-1==n?i.GetSignsCount(e):1})).then((function(o){var s=new Array;if(-1!=n)s.push(n);else for(var a=0;a<o;a++)s.push(a);return r.ProcessArray(s,(function(n){return new t((function(t,o){var s=new S.a;i.VerifyDataInternalOnTimeEx(e,n,null,!1,!1).then((function(t){return l.a.MapToEndUserSignInfo(t,s),i.GetSignTimeInfo(n,e)})).then((function(t){return s.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),i.GetSignType(n,e)})).then((function(e){s.signLevel=e,t(s)})).catch((function(t){return o(r.MapError(t))}))}))}))})).then((function(t){o(-1!=n?t[0]:t)})).catch((function(t){return s(r.MapError(t))}))}))},e.prototype.EnvelopData=function(e,n,i,o,s,a){void 0===a&&(a=!1);var u=this,c=this.m_library;return new t((function(t,l){u.CheckInitialize().then((function(){if(null==u.m_pkContext&&(!a||i))throw c.MakeError(r.EU_ERROR_BAD_CERT,"");var t=c.EU_RECIPIENT_APPEND_TYPE_BY_ISSUER_SERIAL;return a?i?c.CtxEnvelopWithDynamicKey(u.m_pkContext,e,t,i,o,n):c.EnvelopToRecipientsWithDynamicKey(e,i,o,n):c.CtxEnvelop(u.m_pkContext,e,t,i,o,n)})).then((function(t){return s?t:c.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return l(u.MapError(t))}))}))},e.prototype.DevelopData=function(e,n){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){if(null==i.m_pkContext)throw o.MakeError(r.EU_ERROR_BAD_CERT,"");return o.CtxDevelop(i.m_pkContext,e,n)})).then((function(e){var n=l.a.MapToEndUserSenderInfo(e,new C.a);t(n)})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.ProtectDataByPassword=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.ProtectDataByPassword(e,n)})).then((function(t){return r?t:o.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.UnprotectDataByPassword=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.UnprotectDataByPassword(e,n)})).then((function(t){return r?o.BytesToString(t):t})).then((function(e){t(e)})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.CreateAuthData=function(e,n,i){var o=this,s=this.m_library;return new t((function(t,a){o.CheckInitialize().then((function(){if(null==o.m_pkContext)throw s.MakeError(r.EU_ERROR_BAD_CERT,"");return s.CtxCreateAuthData(o.m_pkContext,e,n)})).then((function(t){return i?t:s.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return a(o.MapError(t))}))}))},e.prototype.GetTSPByAccessInfo=function(e,n,r,i,o){var s=this,a=this.m_library;return new t((function(t,u){s.CheckInitialize().then((function(){return a.GetTSPByAccessInfo(e,n,r,i)})).then((function(t){return o?a.BASE64Encode(t):t})).then((function(e){t(e)})).catch((function(t){return u(s.MapError(t))}))}))},e.prototype.CheckTSP=function(e,n,r){var i=this,o=this.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return o.CheckTSP(e,n,r)})).then((function(){t()})).catch((function(t){return s(i.MapError(t))}))}))},e.prototype.CtxCreate=function(){var e=this,n=this.m_library,r={context:null};return new t((function(t,i){e.CheckInitialize().then((function(){return n.CtxCreate()})).then((function(t){return r.context=t,n.CtxSetParameter(t,n.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,e.m_resolveOIDs)})).then((function(){t(r.context)})).catch((function(t){return i(e.MapError(t))}))}))},e.prototype.CtxFree=function(e){var n=this,r=this.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){r.CtxFree(e)})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.CtxSetParameter=function(e,n,r){var i=this,o=i.m_library;return new t((function(t,s){i.CheckInitialize().then((function(){return null==e&&(e=i.m_context),o.CtxSetParameter(e,n,r)})).then((function(){t()})).catch((function(t){i.EndKMOperation(),s(i.MapError(t))}))}))},e.prototype.CtxReadPrivateKey=function(e,n,r,i){var o=this,s=o.m_library;return new t((function(t,a){o.CheckInitialize().then((function(){return o.BeginKMOperation()})).then((function(){var t=l.a.MapFromKeyMedia(n,s.CreateKeyMedia());return o.CtxReadPrivateKeyInternal(e,null,null,t,r,i,!0)})).then((function(e){o.EndKMOperation(),t(e)})).catch((function(t){o.EndKMOperation(),a(o.MapError(t))}))}))},e.prototype.CtxReadPrivateKeyBinary=function(e,n,r,i,o){var s=this;return new t((function(t,a){s.CheckInitialize().then((function(){return s.CtxReadPrivateKeyInternal(e,n,r,null,i,o,!0)})).then((function(e){t(e)})).catch((function(t){return a(s.MapError(t))}))}))},e.prototype.CtxFreePrivateKey=function(e){var n=this,r=this.m_library;return new t((function(t,i){n.CheckInitialize().then((function(){return r.CtxFreePrivateKey(e)})).then((function(){t()})).catch((function(t){return i(n.MapError(t))}))}))},e.prototype.CtxGetOwnCertificates=function(e){var n=this,i=this.m_library;return new t((function(t,o){n.CheckInitialize().then((function(){if(null==e)throw i.MakeError(r.EU_ERROR_BAD_CERT,"");var s=new Array,a=function(r){i.CtxEnumOwnCertificates(e,r).then((function(e){if(e){var n=l.a.MapToEndUserCertificate(e,new u.EndUserCertificate);s.push(n),a(r+1)}else t(s)})).catch((function(t){return o(n.MapError(t))}))};a(0)})).catch((function(t){return o(n.MapError(t))}))}))},e.prototype.CtxSignHash=function(t,e,n,r,i){return this.CtxSignHashInternal(t,e,n,null,r,i)},e.prototype.CtxSignData=function(t,e,n,r,i,o){return this.CtxSignDataInternal(t,e,n,null,r,i,o)},e.prototype.CtxAppendSignHash=function(t,e,n,r,i,o){return this.CtxSignHashInternal(t,e,n,r,i,o)},e.prototype.CtxAppendSign=function(t,e,n,r,i,o){return this.CtxSignDataInternal(t,e,n,r,null!=n,i,o)},e.prototype.CtxGetSignValue=function(e,n,i,o,s){void 0===s&&(s=!1);var a=this,u=this.m_library,c=a.DataToNamedDataArray(i);return new t((function(l,f){a.CheckInitialize().then((function(){if(null==e)throw u.MakeError(r.EU_ERROR_BAD_CERT,"");return n!=_.EndUserSignAlgo.ECDSAWithSHA?null:u.CtxSetParameter(a.m_context,u.EU_ENCODE_ECDSA_SIGN_VALUE_CONTEXT_PARAMETER,s)})).then((function(){return a.ProcessArray(c,(function(r){return new t((function(t,i){u.CtxGetSignValue(e,n,r.val).then((function(t){return o?t:u.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return i(t)}))}))}))})).then((function(t){var e=a.DataToResult(i,t);l(e)})).catch((function(t){return f(a.MapError(t))}))}))},e.prototype.CtxEnvelopData=function(e,n,i,o,s,a,u){var c=this,l=this.m_library;return new t((function(t,f){c.CheckInitialize().then((function(){if(null==e&&(!u||o))throw l.MakeError(r.EU_ERROR_BAD_CERT,"");var t=l.EU_RECIPIENT_APPEND_TYPE_BY_ISSUER_SERIAL;return u?o?l.CtxEnvelopWithDynamicKey(e,n,t,o,s,i):l.EnvelopToRecipientsWithDynamicKey(n,o,s,i):l.CtxEnvelop(e,n,t,o,s,i)})).then((function(t){return a?t:l.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return f(c.MapError(t))}))}))},e.prototype.CtxDevelopData=function(e,n,i){var o=this,s=this.m_library;return new t((function(t,a){o.CheckInitialize().then((function(){if(null==e)throw s.MakeError(r.EU_ERROR_BAD_CERT,"");return s.CtxDevelop(e,n,i)})).then((function(e){var n=l.a.MapToEndUserSenderInfo(e,new C.a);t(n)})).catch((function(t){return a(o.MapError(t))}))}))},e.prototype.ProtectTaxReports=function(e,n,r,i,o,s,a){void 0===e&&(e=null),void 0===n&&(n=null),void 0===r&&(r=null),void 0===a&&(a=!1);var u=this;return new t((function(t,c){var l={accountant:null,director:null,stamp:null};u.CheckInitialize().then((function(){var t=[_.EndUserKeyUsage.DigitalSignature];return null!=e?u.LoadTaxReportPKey(e,t,!1):null})).then((function(t){l.accountant=t;var e=[_.EndUserKeyUsage.DigitalSignature];return r||e.push(_.EndUserKeyUsage.KeyAgreement),null!=n?u.LoadTaxReportPKey(n,e,!1):null})).then((function(t){l.director=t;var e=[_.EndUserKeyUsage.DigitalSignature,_.EndUserKeyUsage.KeyAgreement];return null!=r?u.LoadTaxReportPKey(r,e,!0):null})).then((function(t){return l.stamp=t,u.ProcessArray(s,(function(t){return u.ProtectTaxReport(l.accountant,l.director,l.stamp,i,o,t,a)}))})).then((function(e){t(e)})).catch((function(t){return c(u.MapError(t))}))}))},e.prototype.UnprotectTaxReceipts=function(e,n){var r=this;return new t((function(t,i){r.CheckInitialize().then((function(){return r.ProcessArray(n,(function(t){return r.UnprotectTaxReceipt(e,t)}))})).then((function(e){t(e)})).catch((function(t){return i(r.MapError(t))}))}))},e.prototype.ASiCGetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.ASiCGetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxASiCGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context&&o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))}))}))}))},e.prototype.ASiCSignData=function(e,n,i,o,s,a){var u=this,c=this,l=this.m_library;return new t((function(t,f){c.CheckInitialize().then((function(){if(null==u.m_pkContext)throw l.MakeError(r.EU_ERROR_BAD_CERT,"");return c.ProcessArray(s,(function(t){return c.NamedDataToReference(t)}))})).then((function(t){return l.CtxASiCSign(u.m_pkContext,e,n,i,o,t)})).then((function(t){return a?t:l.BASE64Decode(t)})).then((function(e){var r={name:s[0].name+(n==_.EndUserASiCType.S?".asics":".asice"),val:e};t(r)})).catch((function(t){return f(c.MapError(t))}))}))},e.prototype.ASiCAppendSign=function(e,n,i,o,s){var a=this,u=this,c=this.m_library,l=u.DataToNamedDataArray(o);return new t((function(t,o){u.CheckInitialize().then((function(){if(null==a.m_pkContext)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");return c.CtxASiCAppendSign(a.m_pkContext,e,n,i,l[0].val)})).then((function(t){return s?t:c.BASE64Decode(t)})).then((function(e){var n={name:l[0].name,val:e};t(n)})).catch((function(t){return o(u.MapError(t))}))}))},e.prototype.ASiCVerifyData=function(e,n){void 0===n&&(n=-1);var r=this,i=this.m_library;return new t((function(o,s){r.CheckInitialize().then((function(){return-1==n?i.ASiCGetSignsCount(e):1})).then((function(o){var s=new Array;if(-1!=n)s.push(n);else for(var a=0;a<o;a++)s.push(a);return r.ProcessArray(s,(function(n){return new t((function(t,o){var s=new S.a;i.ASiCVerify(n,e).then((function(t){return l.a.MapToEndUserSignInfo(t,s),i.ASiCGetSignTimeInfo(n,e)})).then((function(t){return s.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),i.ASiCGetSignLevel(n,e)})).then((function(e){s.signLevel=e,t(s)})).catch((function(t){return o(r.MapError(t))}))}))}))})).then((function(t){o(-1!=n?t[0]:t)})).catch((function(t){return s(r.MapError(t))}))}))},e.prototype.PDFGetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.PDFGetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxPDFGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context&&o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))}))}))}))},e.prototype.PDFSignData=function(e,n,i,o){var s=this,a=this,u=this.m_library,c=a.DataToNamedDataArray(n);return new t((function(l,f){a.CheckInitialize().then((function(){if(null==s.m_pkContext)throw u.MakeError(r.EU_ERROR_BAD_CERT,"");return a.ProcessArray(c,(function(n){return new t((function(t,r){return u.CtxPDFSign(s.m_pkContext,e,n.val,i).then((function(t){return o?t:u.BASE64Decode(t)})).then((function(e){t(e)})).catch((function(t){return r(t)}))}))}))})).then((function(t){var e=s.DataToResult(n,t);l(e)})).catch((function(t){return f(a.MapError(t))}))}))},e.prototype.PDFVerifyData=function(e,n){void 0===n&&(n=-1);var r=this,i=this.m_library;return new t((function(o,s){r.CheckInitialize().then((function(){return-1==n?i.PDFGetSignsCount(e):1})).then((function(o){var s=new Array;if(-1!=n)s.push(n);else for(var a=0;a<o;a++)s.push(a);return r.ProcessArray(s,(function(n){return new t((function(t,o){var s=new S.a;i.PDFVerify(n,e).then((function(t){return l.a.MapToEndUserSignInfo(t,s),i.PDFGetSignTimeInfo(n,e)})).then((function(t){return s.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),i.PDFGetSignType(n,e)})).then((function(e){s.signLevel=e,t(s)})).catch((function(t){return o(r.MapError(t))}))}))}))})).then((function(t){o(-1!=n?t[0]:t)})).catch((function(t){return s(r.MapError(t))}))}))},e.prototype.XAdESGetSigner=function(e,n,r){void 0===n&&(n=-1),void 0===r&&(r=!1);var i=this,o=this.m_library,s={context:null,signersInfo:null};return new t((function(a,c){i.CheckInitialize().then((function(){return o.CtxCreate()})).then((function(t){return s.context=t,o.CtxSetParameter(t,o.EU_RESOLVE_OIDS_CONTEXT_PARAMETER,r)})).then((function(){return-1==n?o.XAdESGetSignsCount(e):1})).then((function(r){var a=new Array;if(-1!=n)a.push(n);else for(var c=0;c<r;c++)a.push(c);return i.ProcessArray(a,(function(n){return new t((function(t,r){var a=new u.EndUserCertificate;o.CtxXAdESGetSignerInfo(s.context,n,e).then((function(e){l.a.MapToEndUserCertificate(e,a),t(a)})).catch((function(t){return r(i.MapError(t))}))}))}))})).then((function(t){return s.signersInfo=t,o.CtxFree(s.context)})).then((function(){a(-1!=n?s.signersInfo[0]:s.signersInfo)})).catch((function(t){s.context&&o.CtxFree(s.context).then((function(){c(i.MapError(t))})).catch((function(){c(i.MapError(t))}))}))}))},e.prototype.XAdESSignData=function(e,n,i,o,s){var a=this,u=this,c=this.m_library;return new t((function(t,l){u.CheckInitialize().then((function(){if(null==a.m_pkContext)throw c.MakeError(r.EU_ERROR_BAD_CERT,"");return u.ProcessArray(o,(function(t){return u.NamedDataToReference(t)}))})).then((function(t){return c.CtxXAdESSign(a.m_pkContext,e,n,i,t)})).then((function(t){return s?t:c.BASE64Decode(t)})).then((function(e){var n={name:o[0].name+(o[0].name.endsWith(".xml")?"":".xml"),val:e};t(n)})).catch((function(t){return l(u.MapError(t))}))}))},e.prototype.XAdESVerifyData=function(e,n,r){void 0===r&&(r=-1);var i=this,o=this.m_library,s=new Array;return new t((function(a,u){i.CheckInitialize().then((function(){return-1==r?o.XAdESGetSignsCount(n):1})).then((function(t){if(-1!=r)s.push(r);else for(var n=0;n<t;n++)s.push(n);return null==e?null:i.ProcessArray(e,(function(t){return i.NamedDataToReference(t)}))})).then((function(e){return i.ProcessArray(s,(function(r){return new t((function(t,s){var a=new S.a;o.XAdESVerify(e,r,n).then((function(t){return l.a.MapToEndUserSignInfo(t,a),o.XAdESGetSignTimeInfo(r,n)})).then((function(t){return a.timeInfo=l.a.MapToEndUserTimeInfo(t,new d.a),o.XAdESGetSignLevel(r,n)})).then((function(e){a.signLevel=e,t(a)})).catch((function(t){return s(i.MapError(t))}))}))}))})).then((function(t){a(-1!=r?t[0]:t)})).catch((function(t){return u(i.MapError(t))}))}))},e.prototype.GetSignContainerInfo=function(e){var n=this,r=this.m_library,i=(new y.a,function(e){var n=new y.a;return new t((function(t,i){r.IsDataInSignedDataAvailable(e).then((function(e){n.type=_.EndUserSignContainerType.CAdES,n.subType=e?_.EndUserCAdESType.Enveloped:_.EndUserCAdESType.Detached,t(n)})).catch((function(e){t(null)}))}))}),o=function(e){var n=new y.a;return new t((function(t,i){r.XAdESGetType(e).then((function(e){n.type=_.EndUserSignContainerType.XAdES,n.subType=e,t(n)})).catch((function(e){t(null)}))}))},s=function(e){var n=new y.a;return new t((function(t,i){r.PDFGetSignsCount(e).then((function(e){n.type=_.EndUserSignContainerType.PAdES,t(n)})).catch((function(e){t(null)}))}))},a=function(e){var n=new y.a;return new t((function(t,i){r.ASiCGetASiCType(e).then((function(t){return n.type=_.EndUserSignContainerType.ASiC,n.subType=t,r.ASiCGetSignType(e)})).then((function(e){n.asicSignType=e,t(n)})).catch((function(e){t(null)}))}))};return new t((function(u,c){n.CheckInitialize().then((function(){return"string"==typeof e?r.BASE64Decode(e):e})).then((function(e){var n=[],r=function(t,e){if(t.length<e.length)return!1;for(var n=0;n<e.length;n++)if(t[n]!=e[n])return!1;return!0};return n=r(e,[60,63,120,109,108])?[o,i,s,a]:r(e,[37,80,68,70])?[s,i,o,a]:r(e,[80,75])?[a,i,o,s]:[i,o,s,a],new t((function(t,r){var i=function(o){o>=n.length?t(new y.a):n[o](e).then((function(e){null!=e?t(e):i(o+1)})).catch((function(t){return r(t)}))};i(0)}))})).then((function(t){u(t)})).catch((function(t){return c(n.MapError(t))}))}))},e}();e.a=R}).call(this,n(17).Promise)},function(t,e,n){"use strict";(function(t){var r=n(3),i=function(){function e(){this.EU_SUBJECT_TYPE_UNDIFFERENCED=0,this.EU_SUBJECT_TYPE_CA=1,this.EU_SUBJECT_TYPE_CA_SERVER=2,this.EU_SUBJECT_TYPE_RA_ADMINISTRATOR=3,this.EU_SUBJECT_TYPE_END_USER=4,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_UNDIFFERENCED=0,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_CMP=1,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_TSP=2,this.EU_SUBJECT_CA_SERVER_SUB_TYPE_OCSP=3,this.EU_CERT_KEY_TYPE_UNKNOWN=0,this.EU_CERT_KEY_TYPE_DSTU4145=1,this.EU_CERT_KEY_TYPE_RSA=2,this.EU_CERT_KEY_TYPE_ECDSA=4,this.EU_KEY_USAGE_UNKNOWN=0,this.EU_KEY_USAGE_DIGITAL_SIGNATURE=1,this.EU_KEY_USAGE_KEY_AGREEMENT=16,this.EU_KEYS_REQUEST_TYPE_UA_DS=1,this.EU_KEYS_REQUEST_TYPE_UA_KEP=2,this.EU_KEYS_REQUEST_TYPE_INTERNATIONAL=3,this.EU_KEYS_TYPE_NONE=0,this.EU_KEYS_TYPE_DSTU_AND_ECDH_WITH_GOSTS=1,this.EU_KEYS_TYPE_RSA_WITH_SHA=2,this.EU_KEYS_LENGTH_DS_UA_191=1,this.EU_KEYS_LENGTH_DS_UA_257=2,this.EU_KEYS_LENGTH_DS_UA_307=3,this.EU_KEYS_LENGTH_DS_UA_FILE=4,this.EU_KEYS_LENGTH_DS_UA_CERT=5,this.EU_KEYS_LENGTH_KEP_UA_257=1,this.EU_KEYS_LENGTH_KEP_UA_431=2,this.EU_KEYS_LENGTH_KEP_UA_571=3,this.EU_KEYS_LENGTH_KEP_UA_FILE=4,this.EU_KEYS_LENGTH_KEP_UA_CERT=5,this.EU_KEYS_LENGTH_DS_RSA_1024=1,this.EU_KEYS_LENGTH_DS_RSA_2048=2,this.EU_KEYS_LENGTH_DS_RSA_3072=3,this.EU_KEYS_LENGTH_DS_RSA_4096=4,this.EU_KEYS_LENGTH_DS_RSA_FILE=5,this.EU_KEYS_LENGTH_DS_RSA_CERT=6,this.EU_RECIPIENT_APPEND_ISSUER_AND_SERIAL=1,this.EU_RECIPIENT_APPEND_KEY_ID=2,this.EU_RECIPIENT_APPEND_KEY_ID_USC_COMPAT=3,this.EU_SAVE_SETTINGS_PARAMETER="SaveSettings",this.EU_RESOLVE_OIDS_PARAMETER="ResolveOIDs",this.EU_MAKE_PKEY_PFX_CONTAINER_PARAMETER="MakePKeyPFXContainer",this.EU_SIGN_INCLUDE_CONTENT_TIME_STAMP_PARAMETER="SignIncludeContentTimeStamp",this.EU_SIGN_TYPE_PARAMETER="SignType",this.EU_SIGN_INCLUDE_CA_CERTIFICATES_PARAMETER="SignIncludeCACertificates",this.EU_FS_CALCULATE_FINGERPRINT="FSCalculateFingerprint",this.EU_CHECK_CERT_CHAIN_ON_SIGN_TIME_PARAMETER="CheckCertChainOnSignTime",this.EU_CONNECTIONS_TIMEOUT_PARAMETER="ConnectionsTimeout",this.EU_LOG_EVENTS_THRESHOLD_PARAMETER="LogEventsThreshold",this.EU_USE_SLOGIN_PRIVATE_KEY="UseSLoginPrivateKey",this.EU_SETTINGS_ID_NONE=0,this.EU_SETTINGS_ID_MANDATORY=31,this.EU_SETTINGS_ID_ALL=4095,this.EU_SETTINGS_ID_FSTORE=1,this.EU_SETTINGS_ID_PROXY=2,this.EU_SETTINGS_ID_TSP=4,this.EU_SETTINGS_ID_OCSP=8,this.EU_SETTINGS_ID_LDAP=16,this.EU_SETTINGS_ID_MODE=32,this.EU_SETTINGS_ID_CMP=64,this.EU_SETTINGS_ID_KM=128,this.EU_SETTINGS_ID_OCSP_ACCESS_INFO_MODE=256,this.EU_SETTINGS_ID_OCSP_ACCESS_INFO=512,this.EU_SETTINGS_ID_TSL=1024,this.EU_SETTINGS_ID_LOG=2048,this.EU_HEADER_CA_TYPE="UA1",this.EU_HEADER_PART_TYPE_SIGNED=1,this.EU_HEADER_PART_TYPE_ENCRYPTED=2,this.EU_HEADER_PART_TYPE_STAMPED=3,this.EU_HEADER_PART_TYPE_CERTCRYPT=4,this.EU_HEADER_MAX_CA_TYPE_SIZE=3,this.EU_SIGNED_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_SIGNED,this.EU_ENCRYPTED_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_ENCRYPTED,this.EU_TIMESTAMPED_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_STAMPED,this.EU_CERTCRYPT_CRYPTO_HEADER=this.EU_HEADER_PART_TYPE_CERTCRYPT,this.EU_DEFAULT_LANG=0,this.EU_UA_LANG=1,this.EU_RU_LANG=2,this.EU_EN_LANG=3,this.EU_CONTENT_ENC_ALGO_TDES_CBC=4,this.EU_CONTENT_ENC_ALGO_AES_128_CBC=5,this.EU_CONTENT_ENC_ALGO_AES_192_CBC=6,this.EU_CONTENT_ENC_ALGO_AES_256_CBC=7,this.EU_DEV_CTX_MIN_PUBLIC_DATA_ID=16,this.EU_DEV_CTX_MAX_PRIVATE_DATA_ID=175,this.EU_UA_OID_EXT_KEY_USAGE_STAMP="1.2.804.2.1.1.1.3.9",this.EU_CCS_TYPE_REVOKE=1,this.EU_CCS_TYPE_HOLD=2,this.EU_REVOCATION_REASON_UNKNOWN=0,this.EU_REVOCATION_REASON_KEY_COMPROMISE=1,this.EU_REVOCATION_REASON_NEW_ISSURED=2,this.EU_SIGN_TYPE_UNKNOWN=0,this.EU_SIGN_TYPE_CADES_BES=1,this.EU_SIGN_TYPE_CADES_T=4,this.EU_SIGN_TYPE_CADES_C=8,this.EU_SIGN_TYPE_CADES_X_LONG=16,this.EU_CHECK_PRIVATE_KEY_CONTEXT_PARAMETER="CheckPrivateKey",this.EU_RESOLVE_OIDS_CONTEXT_PARAMETER="ResolveOIDs",this.EU_EXPORATABLE_CONTEXT_CONTEXT_PARAMETER="ExportableContext",this.EU_ENCODE_ECDSA_SIGN_VALUE_CONTEXT_PARAMETER="EncodeECDSASignValue",this.EU_USE_SLOGIN_PRIVATE_KEY_CONTEXT_PARAMETER="UseSLoginPrivateKey",this.EU_RECIPIENT_APPEND_TYPE_BY_ISSUER_SERIAL=1,this.EU_RECIPIENT_APPEND_TYPE_BY_KEY_ID=2,this.EU_CTX_HASH_ALGO_UNKNOWN=0,this.EU_CTX_HASH_ALGO_GOST34311=1,this.EU_CTX_HASH_ALGO_SHA160=2,this.EU_CTX_HASH_ALGO_SHA224=3,this.EU_CTX_HASH_ALGO_SHA256=4,this.EU_CTX_HASH_ALGO_SHA384=5,this.EU_CTX_HASH_ALGO_SHA512=6,this.EU_CTX_HASH_ALGO_DSTU7564_256=7,this.EU_CTX_HASH_ALGO_DSTU7564_384=8,this.EU_CTX_HASH_ALGO_DSTU7564_512=9,this.EU_CTX_SIGN_UNKNOWN=0,this.EU_CTX_SIGN_DSTU4145_WITH_GOST34311=1,this.EU_CTX_SIGN_RSA_WITH_SHA=2,this.EU_CTX_SIGN_ECDSA_WITH_SHA=3,this.EU_CTX_SIGN_DSTU4145_WITH_DSTU7564=4,this.EU_FILE_PROCESS_CHUNK_SIZE=1048576,this.EU_ASIC_TYPE_UNKNOWN=0,this.EU_ASIC_TYPE_S=1,this.EU_ASIC_TYPE_E=2,this.EU_ASIC_SIGN_TYPE_UNKNOWN=0,this.EU_ASIC_SIGN_TYPE_CADES=1,this.EU_ASIC_SIGN_TYPE_XADES=2,this.EU_ASIC_SIGN_LEVEL_BES=1,this.EnvelopToRecipientsEx=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.EnvelopToRecipientsEx(e,n,r,i,t,s)}))},this.EnvelopToRecipientsWithDynamicKey=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.EnvelopToRecipientsWithDynamicKey(e,n,r,i,t,s)}))},this.EnvelopToRecipientsWithSettings=function(e,n,r,i,o,s,a){var u=this.m_library;return new t((function(t,c){u.EnvelopToRecipientsWithSettings(e,n,r,i,o,s,a,t,c)}))},this.CtxEnvelop=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxEnvelop(e,n,r,i,o,s,t,u)}))},this.CtxEnvelopWithDynamicKey=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxEnvelopWithDynamicKey(e,n,r,i,o,s,t,u)}))},this.DevelopEx=function(e,n){void 0===n&&(n=null);var r=this.m_library;return new t((function(t,i){r.DevelopEx(e,n,t,i)}))},this.CtxDevelop=function(e,n,r){void 0===r&&(r=null);var i=this.m_library;return new t((function(t,o){i.CtxDevelop(e,n,r,t,o)}))},this.CtxCreateAuthData=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxCreateAuthData(e,n,r,t,o)}))},this.ProtectDataByPassword=function(e,n){var r=this.m_library;return new t((function(t,i){r.ProtectDataByPassword(e,n,t,i)}))},this.UnprotectDataByPassword=function(e,n){var r=this.m_library;return new t((function(t,i){r.UnprotectDataByPassword(e,n,t,i)}))},this.AppendTransportHeader=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.AppendTransportHeader(e,n,r,i,o,t,a)}))},this.ParseTransportHeader=function(e){var n=this.m_library;return new t((function(t,r){n.ParseTransportHeader(e,t,r)}))},this.AppendCryptoHeader=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.AppendCryptoHeader(e,n,r,t,o)}))},this.ParseCryptoHeader=function(e){var n=this.m_library;return new t((function(t,r){n.ParseCryptoHeader(e,t,r)}))},this.GetHostInfo=function(){var e=this.m_library;return new t((function(t,n){e.GetHostInfo(t,n)}))},this.CtxCreate=function(){var e=this.m_library;return new t((function(t,n){e.CtxCreate(t,n)}))},this.CtxFree=function(e){var n=this.m_library;return new t((function(t,r){n.CtxFree(e,t,r)}))},this.CtxSetParameter=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxSetParameter(e,n,r,t,o)}))},this.ASiCGetASiCType=function(e){var n=this.m_library;return new t((function(t,r){n.ASiCGetASiCType(e,t,r)}))},this.ASiCGetSignType=function(e){var n=this.m_library;return new t((function(t,r){n.ASiCGetSignType(e,t,r)}))},this.ASiCGetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.ASiCGetSignsCount(e,t,r)}))},this.ASiCGetSignerInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCGetSignerInfo(e,n,t,i)}))},this.ASiCGetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCGetSignTimeInfo(e,n,t,i)}))},this.CtxASiCSign=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxASiCSign(e,n,r,i,o,s,t,u)}))},this.CtxASiCAppendSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxASiCAppendSign(e,n,r,i,o,t,a)}))},this.ASiCVerify=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCVerify(e,n,t,i)}))},this.CtxASiCGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxASiCGetSignerInfo(e,n,r,t,o)}))},this.ASiCGetSignLevel=function(e,n){var r=this.m_library;return new t((function(t,i){r.ASiCGetSignLevel(e,n,t,i)}))},this.PDFGetSignType=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFGetSignType(e,n,t,i)}))},this.PDFGetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.PDFGetSignsCount(e,t,r)}))},this.PDFGetSignerInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFGetSignerInfo(e,n,t,i)}))},this.PDFGetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFGetSignTimeInfo(e,n,t,i)}))},this.CtxPDFSign=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.CtxPDFSign(e,n,r,i,t,s)}))},this.PDFVerify=function(e,n){var r=this.m_library;return new t((function(t,i){r.PDFVerify(e,n,t,i)}))},this.CtxPDFGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxPDFGetSignerInfo(e,n,r,t,o)}))},this.XAdESGetType=function(e){var n=this.m_library;return new t((function(t,r){n.XAdESGetType(e,t,r)}))},this.XAdESGetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.XAdESGetSignsCount(e,t,r)}))},this.XAdESGetSignLevel=function(e,n){var r=this.m_library;return new t((function(t,i){r.XAdESGetSignLevel(e,n,t,i)}))},this.XAdESGetSignerInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.XAdESGetSignerInfo(e,n,t,i)}))},this.XAdESGetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.XAdESGetSignTimeInfo(e,n,t,i)}))},this.CtxXAdESSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxXAdESSign(e,n,r,i,o,t,a)}))},this.XAdESVerify=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.XAdESVerify(e,n,r,t,o)}))},this.CtxXAdESGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxXAdESGetSignerInfo(e,n,r,t,o)}))},this.SServerClientGeneratePrivateKeyAsync=function(e,n,r,i,o,s,a,u,c,l,f){var _=this.m_library;return new t((function(t,p){_.SServerClientGeneratePrivateKeyAsync(e,n,r,i,o,s,a,u,c,l,f,t,p)}))},this.SServerClientCheckGeneratePrivateKeyStatus=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.SServerClientCheckGeneratePrivateKeyStatus(e,n,r,i,t,s)}))},this.SServerClientSignHashesAsync=function(e,n,r,i,o,s,a,u){var c=this.m_library;return new t((function(t,l){c.SServerClientSignHashesAsync(e,n,r,i,o,s,a,u,t,l)}))},this.SServerClientCheckSignHashesStatus=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.SServerClientCheckSignHashesStatus(e,n,r,i,t,s)}))},this.m_language=0,this.m_library=null}return e.prototype.MakeURL=function(t){var e=location.origin,n=location.pathname;return 0==t.indexOf("http://")||0==t.indexOf("https://")?t:0==t.indexOf("/")&&e?e+t:e&&n?e+n.substr(0,n.lastIndexOf("/"))+"/"+t:t},e.prototype.MakeError=function(t,e){return this.m_library.MakeError(t,e)},e.prototype.IsLibraryLoadError=function(t){return t==r.EndUserError.ERROR_LIBRARY_COMUNICATION_FAILED},e.prototype.IsLibraryVersionNotSupportedError=function(t){return t==r.EndUserError.ERROR_LIBRARY_VERSION_NOT_SUPPORTED},e.prototype.Load=function(){var e=this;return new t((function(t,n){if(null==e.m_library){var i=new r.EndUserLibraryLoader(r.EndUserLibraryLoader.LIBRARY_TYPE_DEFAULT,"euSign",e.m_language,!0,!0);i.onload=function(n){e.m_library=n,t()},i.onerror=function(t,e,i){null==i&&(i=new r.EUSignCP("","")),n(i.MakeError(e,""))},i.load()}else t()}))},e.prototype.IsSupported=function(){return r.EndUserLibraryLoader.isWebExtensionSupported()||r.EndUserLibraryLoader.isSignAgentSupported()||r.EndUserLibraryLoader.isNPAPISupported()||r.EndUserLibraryLoader.isActiveXSupported()},e.prototype.IsSignAgentSupported=function(){return r.EndUserLibraryLoader.isSignAgentSupported()},e.prototype.IsWebExtensionSupported=function(){return r.EndUserLibraryLoader.isWebExtensionSupported()},e.prototype.IsNPAPISupported=function(){return r.EndUserLibraryLoader.isNPAPISupported()},e.prototype.IsActiveXSupported=function(){return r.EndUserLibraryLoader.isActiveXSupported()},e.prototype.IsWebExtensionInstalled=function(){return r.EndUserLibraryLoader.isWebExtensionInstalled()},e.prototype.GetInstallURL=function(t,e){return void 0===t&&(t=!1),new r.EUSignCP("","").GetInstallURL(t,e)},e.prototype.GetUpdateURL=function(t,e){return void 0===t&&(t=!1),new r.EUSignCP("","").GetUpdateURL(t,e)},e.prototype.GetHelpURL=function(t){return new r.EUSignCP("","").GetHelpURL(t)},e.prototype.GetWebExtensionInstallURL=function(){return new r.EUSignCP("","").GetWebExtensionInstallURL()},e.prototype.GetVersion=function(){var e=this.m_library;return new t((function(t,n){e.GetVersion(t,n)}))},e.prototype.IsInitialized=function(){var e=this.m_library;return new t((function(t,n){e.IsInitialized(t,n)}))},e.prototype.Initialize=function(){var e=this.m_library;return new t((function(t,n){e.Initialize(t,n)}))},e.prototype.Finalize=function(){var e=this.m_library;return new t((function(t,n){e.Finalize(t,n)}))},e.prototype.ResetOperation=function(){var e=this.m_library;return new t((function(t,n){e.ResetOperation(t,n)}))},e.prototype.SetUIMode=function(e){var n=this.m_library;return new t((function(t,r){n.SetUIMode(e,t,r)}))},e.prototype.SetLanguage=function(e){var n=this.m_library;if("string"==typeof e)switch(e=e.toLocaleLowerCase()){case"en":e=this.EU_EN_LANG;break;case"ru":e=this.EU_RU_LANG;break;case"uk":case"ua":default:e=this.EU_UA_LANG}return this.m_language=e,new t((function(t,r){n.SetLanguage(e,t,r)}))},e.prototype.SetCharset=function(e){var n=this.m_library;return new t((function(t,r){n.SetCharset(e,t,r)}))},e.prototype.SetRuntimeParameter=function(e,n){var r=this.m_library;return new t((function(t,i){r.SetRuntimeParameter(e,n,t,i)}))},e.prototype.GetStorageParameter=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetStorageParameter(e,n,t,i)}))},e.prototype.SetStorageParameter=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.SetStorageParameter(e,n,r,t,o)}))},e.prototype.BASE64Encode=function(e){var n=this.m_library;return new t((function(t,r){n.BASE64Encode(e,t,r)}))},e.prototype.BASE64Decode=function(e){var n=this.m_library;return new t((function(t,r){n.BASE64Decode(e,t,r)}))},e.prototype.StringToBytes=function(e){var n=this.m_library;return new t((function(t,r){n.StringToBytes(e,t,r)}))},e.prototype.BytesToString=function(e){var n=this.m_library;return new t((function(t,r){n.BytesToString(e,t,r)}))},e.prototype.DoesNeedSetSettings=function(){var e=this.m_library;return new t((function(t,n){e.DoesNeedSetSettings(t,n)}))},e.prototype.InitializeMandatorySettings=function(){var e=this.m_library;return new t((function(t,n){e.InitializeMandatorySettings(t,n)}))},e.prototype.CreateModeSettings=function(){return this.m_library.CreateModeSettings()},e.prototype.GetModeSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetModeSettings(t,n)}))},e.prototype.SetModeSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetModeSettings(e,t,r)}))},e.prototype.CreateKeyMediaSettings=function(){return this.m_library.CreateKeyMediaSettings()},e.prototype.GetKeyMediaSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetKeyMediaSettings(t,n)}))},e.prototype.SetKeyMediaSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetKeyMediaSettings(e,t,r)}))},e.prototype.CreateFileStoreSettings=function(){return this.m_library.CreateFileStoreSettings()},e.prototype.GetFileStoreSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetFileStoreSettings(t,n)}))},e.prototype.SetFileStoreSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetFileStoreSettings(e,t,r)}))},e.prototype.CreateProxySettings=function(){return this.m_library.CreateProxySettings()},e.prototype.GetProxySettings=function(){var e=this.m_library;return new t((function(t,n){e.GetProxySettings(t,n)}))},e.prototype.SetProxySettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetProxySettings(e,t,r)}))},e.prototype.CreateOCSPSettings=function(){return this.m_library.CreateOCSPSettings()},e.prototype.GetOCSPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetOCSPSettings(t,n)}))},e.prototype.SetOCSPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPSettings(e,t,r)}))},e.prototype.CreateOCSPAccessInfoModeSettings=function(){return this.m_library.CreateOCSPAccessInfoModeSettings()},e.prototype.GetOCSPAccessInfoModeSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetOCSPAccessInfoModeSettings(t,n)}))},e.prototype.SetOCSPAccessInfoModeSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPAccessInfoModeSettings(e,t,r)}))},e.prototype.CreateOCSPAccessInfoSettings=function(){return this.m_library.CreateOCSPAccessInfoSettings()},e.prototype.EnumOCSPAccessInfoSettings=function(e){var n=this.m_library;return new t((function(t,r){n.EnumOCSPAccessInfoSettings(e,t,r)}))},e.prototype.GetOCSPAccessInfoSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetOCSPAccessInfoSettings(t,n)}))},e.prototype.SetOCSPAccessInfoSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPAccessInfoSettings(e,t,r)}))},e.prototype.DeleteOCSPAccessInfoSettings=function(e){var n=this.m_library;return new t((function(t,r){n.DeleteOCSPAccessInfoSettings(e,t,r)}))},e.prototype.CreateTSPSettings=function(){return this.m_library.CreateTSPSettings()},e.prototype.GetTSPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetTSPSettings(t,n)}))},e.prototype.SetTSPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetTSPSettings(e,t,r)}))},e.prototype.CreateLDAPSettings=function(){return this.m_library.CreateLDAPSettings()},e.prototype.GetLDAPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetLDAPSettings(t,n)}))},e.prototype.SetLDAPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetLDAPSettings(e,t,r)}))},e.prototype.CreateCMPSettings=function(){return this.m_library.CreateCMPSettings()},e.prototype.GetCMPSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetCMPSettings(t,n)}))},e.prototype.SetCMPSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetCMPSettings(e,t,r)}))},e.prototype.GetSystemProxySettings=function(){var e=this.m_library;return new t((function(t,n){e.GetSystemProxySettings(t,n)}))},e.prototype.CreateTSLSettings=function(){return this.m_library.CreateTSLSettings()},e.prototype.GetTSLSettings=function(){var e=this.m_library;return new t((function(t,n){e.GetTSLSettings(t,n)}))},e.prototype.SetTSLSettings=function(e){var n=this.m_library;return new t((function(t,r){n.SetTSLSettings(e,t,r)}))},e.prototype.SetOCSPResponseExpireTime=function(e){var n=this.m_library;return new t((function(t,r){n.SetOCSPResponseExpireTime(e,t,r)}))},e.prototype.GetCertificate=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetCertificate(e,n,t,i)}))},e.prototype.ParseCertificateEx=function(e){var n=this.m_library;return new t((function(t,r){n.ParseCertificateEx(e,t,r)}))},e.prototype.SaveCertificate=function(e){var n=this.m_library;return new t((function(t,r){n.SaveCertificate(e,t,r)}))},e.prototype.SaveCertificates=function(e){var n=this.m_library;return new t((function(t,r){n.SaveCertificates(e,t,r)}))},e.prototype.GetTSPByAccessInfo=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.GetTSPByAccessInfo(e,n,r,i,t,s)}))},e.prototype.CheckTSP=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CheckTSP(e,n,r,t,o)}))},e.prototype.DownloadData=function(e,n){var i=this;return new t((function(t,o){try{var s=new XMLHttpRequest;s.onload=function(){if(4==s.readyState){var a=null;try{if(200!=s.status)throw"Download data error. URL - "+e+", status - "+s.status;switch(n){case"binary":a=new Uint8Array(s.response);break;case"json":a=JSON.parse(s.responseText.replace(/\\'/g,"'"));break;default:a=s.responseText}}catch(t){return console.log("EndUser.DowloadData error: "+t),void o(i.MakeError(r.EndUserError.ERROR_DOWNLOAD_FILE,""))}t(a)}},s.onerror=function(){o(i.MakeError(r.EndUserError.ERROR_DOWNLOAD_FILE,""))},e=i.MakeURL(e),s.open("GET",e,!0),"binary"==n&&(s.responseType="arraybuffer"),s.send()}catch(t){o(i.MakeError(r.EndUserError.ERROR_DOWNLOAD_FILE,""))}}))},e.prototype.CreateKeyMedia=function(){return this.m_library.CreateKeyMedia()},e.prototype.GetPrivateKeyMedia=function(e){var n=this.m_library;return new t((function(t,r){n.GetPrivateKeyMedia(e,t,r)}))},e.prototype.EnumKeyMediaTypes=function(e){var n=this.m_library;return new t((function(t,r){n.EnumKeyMediaTypes(e,t,r)}))},e.prototype.EnumKeyMediaDevices=function(e,n){var r=this.m_library;return new t((function(t,i){r.EnumKeyMediaDevices(e,n,t,i)}))},e.prototype.GetKeyMediaTypes=function(){var e=this.m_library;return new t((function(t,n){e.GetKeyMediaTypes(t,n)}))},e.prototype.GetKeyMediaDevices=function(e){var n=this.m_library;return new t((function(t,r){n.GetKeyMediaDevices(e,t,r)}))},e.prototype.IsPrivateKeyReaded=function(){var e=this.m_library;return new t((function(t,n){e.IsPrivateKeyReaded(t,n)}))},e.prototype.ReadPrivateKey=function(){var e=this.m_library;return new t((function(t,n){e.ReadPrivateKey(t,n)}))},e.prototype.ReadPrivateKeySilently=function(e,n,r){var i=this.m_library;return new t((function(t,o){"number"==typeof e?i.ReadPrivateKeySilently(e,n,r,t,o):i.ReadPrivateKeySilently(e,t,o)}))},e.prototype.ReadPrivateKeyBinary=function(e,n){var r=this.m_library;return new t((function(t,i){r.ReadPrivateKeyBinary(e,n,t,i)}))},e.prototype.ReadPrivateKeyFile=function(e,n){var r=this.m_library;return new t((function(t,i){r.ReadPrivateKeyFile(e,n,t,i)}))},e.prototype.ResetPrivateKey=function(){var e=this.m_library;return new t((function(t,n){e.ResetPrivateKey(t,n)}))},e.prototype.CtxReadPrivateKey=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){"number"==typeof n?o.CtxReadPrivateKey(e,n,r,i,t,s):o.CtxReadPrivateKey(e,n,t,s)}))},e.prototype.CtxReadPrivateKeyBinary=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxReadPrivateKeyBinary(e,n,r,t,o)}))},e.prototype.CtxFreePrivateKey=function(e){var n=this.m_library;return new t((function(t,r){n.CtxFreePrivateKey(e,t,r)}))},e.prototype.ShowOwnCertificate=function(){var e=this.m_library;return new t((function(t,n){e.ShowOwnCertificate(t,n)}))},e.prototype.GetOwnCertificate=function(e,n){var r=this.m_library;return new t((function(t,i){"number"==typeof e||"number"==typeof n?r.GetOwnCertificate(e,n,t,i):r.GetOwnCertificate(t,i)}))},e.prototype.GetOwnEUserParams=function(){var e=this.m_library;return new t((function(t,n){e.GetOwnEUserParams(t,n)}))},e.prototype.CtxGetOwnEUserParams=function(e){var n=this.m_library;return new t((function(t,r){n.CtxGetOwnEUserParams(e,t,r)}))},e.prototype.ModifyOwnEUserParams=function(e,n){var r=this.m_library;return new t((function(t,i){r.ModifyOwnEUserParams(e,n,t,i)}))},e.prototype.CtxModifyOwnEUserParams=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxModifyOwnEUserParams(e,n,r,t,o)}))},e.prototype.EnumOwnCertificates=function(e){var n=this.m_library;return new t((function(t,r){n.EnumOwnCertificates(e,t,r)}))},e.prototype.GetPrivateKeyOwnerInfo=function(){var e=this.m_library;return new t((function(t,n){e.GetPrivateKeyOwnerInfo(t,n)}))},e.prototype.CtxEnumOwnCertificates=function(e,n){var r=this.m_library;return new t((function(t,i){r.CtxEnumOwnCertificates(e,n,t,i)}))},e.prototype.CtxGetOwnCertificate=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxGetOwnCertificate(e,n,r,t,o)}))},e.prototype.GetKeyInfo=function(e){var n=this.m_library;return new t((function(t,r){n.GetKeyInfo(e,t,r)}))},e.prototype.GetKeyInfoBinary=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetKeyInfoBinary(e,n,t,i)}))},e.prototype.GetKeyInfoFile=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetKeyInfoFile(e,n,t,i)}))},e.prototype.GetCertificatesByKeyInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.GetCertificatesByKeyInfo(e,n,r,t,o)}))},e.prototype.EnumJKSPrivateKeys=function(e,n){var r=this.m_library;return new t((function(t,i){r.EnumJKSPrivateKeys(e,n,t,i)}))},e.prototype.GetJKSPrivateKey=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetJKSPrivateKey(e,n,t,i)}))},e.prototype.CreatePrivateKeyInfo=function(){return this.m_library.CreatePrivateKeyInfo()},e.prototype.CreateEndUserInfo=function(){return this.m_library.CreateEndUserInfo()},e.prototype.GeneratePrivateKeyEx=function(e,n,r,i,o,s,a,u,c,l,f,_,p,h,E,y,S){var C=this.m_library;return new t((function(t,d){C.GeneratePrivateKeyEx(e,n,r,i,o,s,a,u,c,l,f,_,p,h,E,y,S,t,d)}))},e.prototype.ChangePrivateKeyPassword=function(e,n){var r=this.m_library;return new t((function(t,i){null!=e?r.ChangePrivateKeyPassword(e.GetTypeIndex(),e.GetDevIndex(),e.GetPassword(),n,t,i):r.ChangePrivateKeyPassword(t,i)}))},e.prototype.ChangeSoftwarePrivateKeyPassword=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.ChangeSoftwarePrivateKeyPassword(e,n,r,t,o)}))},e.prototype.SetKeyMediaUserPassword=function(e,n){var r=this.m_library;return new t((function(t,i){null!=n?r.SetKeyMediaUserPassword(e,n.GetTypeIndex(),n.GetDevIndex(),n.GetPassword(),t,i):r.SetKeyMediaUserPassword(e,t,i)}))},e.prototype.ChangeOwnCertificatesStatus=function(e,n){var r=this.m_library;return new t((function(t,i){r.ChangeOwnCertificatesStatus(e,n,t,i)}))},e.prototype.CtxChangeOwnCertificatesStatus=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxChangeOwnCertificatesStatus(e,n,r,t,o)}))},e.prototype.MakeNewCertificate=function(e,n,r,i,o,s,a,u,c,l,f,_,p){var h=this.m_library;return new t((function(t,E){h.MakeNewCertificate(e,n,r,i,o,s,a,u,c,l,f,_,p,t,E)}))},e.prototype.MakeNewOwnCertificate=function(e,n,r,i,o,s,a,u){var c=this.m_library;return new t((function(t,l){c.MakeNewOwnCertificate(e,n,r,i,o,s,a,u,t,l)}))},e.prototype.CtxMakeNewOwnCertificate=function(e,n,r,i,o,s,a,u,c){var l=this.m_library;return new t((function(t,f){l.CtxMakeNewOwnCertificate(e,n,r,i,o,s,a,u,c,t,f)}))},e.prototype.CtxMakeNewOwnCertificateWithCR=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxMakeNewOwnCertificateWithCR(e,n,r,i,o,t,a)}))},e.prototype.CtxMakeDeviceCertificate=function(e,n,r,i,o,s,a,u){var c=this.m_library;return new t((function(t,l){c.CtxMakeDeviceCertificate(e,n,r,i,o,s,a,u,t,l)}))},e.prototype.CtxHash=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.CtxHash(e,n,r,i,t,s)}))},e.prototype.CtxHashBegin=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxHashBegin(e,n,r,t,o)}))},e.prototype.CtxHashContinue=function(e,n){var r=this.m_library;return new t((function(t,i){r.CtxHashContinue(e,n,t,i)}))},e.prototype.CtxHashEnd=function(e){var n=this.m_library;return new t((function(t,r){n.CtxHashEnd(e,t,r)}))},e.prototype.CtxHashFree=function(e){var n=this.m_library;return new t((function(t,r){n.CtxHashFree(e,t,r)}))},e.prototype.GetSignType=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetSignType(e,n,t,i)}))},e.prototype.CtxGetSignerInfo=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxGetSignerInfo(e,n,r,t,o)}))},e.prototype.SignHash=function(e){var n=this.m_library;return new t((function(t,r){n.SignHash(e,t,r)}))},e.prototype.Sign=function(e){var n=this.m_library;return new t((function(t,r){n.Sign(e,t,r)}))},e.prototype.SignInternal=function(e,n){var r=this.m_library;return new t((function(t,i){r.SignInternal(e,n,t,i)}))},e.prototype.SignHashRSA=function(e){var n=this.m_library;return new t((function(t,r){n.SignHashRSA(e,t,r)}))},e.prototype.SignRSA=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.SignRSA(e,n,r,t,o)}))},e.prototype.CtxSignHash=function(e,n,r,i){var o=this.m_library;return new t((function(t,s){o.CtxSignHash(e,n,r,i,t,s)}))},e.prototype.CtxSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxSign(e,n,r,i,o,t,a)}))},e.prototype.CtxSignFile=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxSignFile(e,n,r,i,o,s,t,u)}))},e.prototype.CtxGetSignValue=function(e,n,r){var i=this.m_library;return new t((function(t,o){i.CtxGetSignValue(e,n,r,t,o)}))},e.prototype.AppendSignHash=function(e,n){var r=this.m_library;return new t((function(t,i){r.AppendSignHash(e,n,t,i)}))},e.prototype.AppendSign=function(e,n){var r=this.m_library;return new t((function(t,i){r.AppendSign(e,n,t,i)}))},e.prototype.AppendSignInternal=function(e,n){var r=this.m_library;return new t((function(t,i){r.AppendSignInternal(e,n,t,i)}))},e.prototype.CtxAppendSignHash=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxAppendSignHash(e,n,r,i,o,t,a)}))},e.prototype.CtxAppendSign=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.CtxAppendSign(e,n,r,i,o,t,a)}))},e.prototype.CtxAppendSignFile=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.CtxAppendSignFile(e,n,r,i,o,s,t,u)}))},e.prototype.IsDataInSignedDataAvailable=function(e){var n=this.m_library;return new t((function(t,r){n.IsDataInSignedDataAvailable(e,t,r)}))},e.prototype.GetCertificateFromSignedData=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetCertificateFromSignedData(e,n,t,i)}))},e.prototype.GetSignsCount=function(e){var n=this.m_library;return new t((function(t,r){n.GetSignsCount(e,t,r)}))},e.prototype.GetSignTimeInfo=function(e,n){var r=this.m_library;return new t((function(t,i){r.GetSignTimeInfo(e,n,t,i)}))},e.prototype.VerifyHashOnTimeEx=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.VerifyHashOnTimeEx(e,n,r,i,o,s,t,u)}))},e.prototype.VerifyDataOnTimeEx=function(e,n,r,i,o,s){var a=this.m_library;return new t((function(t,u){a.VerifyDataOnTimeEx(e,n,r,i,o,s,t,u)}))},e.prototype.VerifyDataInternalOnTimeEx=function(e,n,r,i,o){var s=this.m_library;return new t((function(t,a){s.VerifyDataInternalOnTimeEx(e,n,r,i,o,t,a)}))},e.prototype.CreateReference=function(t,e){return this.m_library.CreateReference(t,e)},e}();e.a=i}).call(this,n(17).Promise)},function(t,e){var n,r,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(t){if(n===setTimeout)return setTimeout(t,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(t){r=s}}();var u,c=[],l=!1,f=-1;function _(){l&&u&&(l=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!l){var t=a(_);l=!0;for(var e=c.length;e;){for(u=c,c=[];++f<e;)u&&u[f].run();f=-1,e=c.length}u=null,l=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function h(t,e){this.fun=t,this.array=e}function E(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new h(t,e)),1!==c.length||l||a(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=E,i.addListener=E,i.once=E,i.off=E,i.removeListener=E,i.removeAllListeners=E,i.emit=E,i.prependListener=E,i.prependOnceListener=E,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e){}])}));
|
package/package.json
CHANGED
package/src/DigitalSignature.js
CHANGED
|
@@ -250,7 +250,7 @@ export default class DigitalSignature {
|
|
|
250
250
|
return this._glSign;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
async setLanguage(language){
|
|
253
|
+
async setLanguage(language) {
|
|
254
254
|
await this._euSignFile.SetLanguage(language);
|
|
255
255
|
if (await this._euSignKeyMedia.IsInitialized()) {
|
|
256
256
|
await this._euSignKeyMedia.SetLanguage(language);
|
|
@@ -270,7 +270,7 @@ export default class DigitalSignature {
|
|
|
270
270
|
* Считать ключ по параметрам
|
|
271
271
|
* @param {PrivateKeyInfo} keyInfo - Параметры ключа
|
|
272
272
|
*/
|
|
273
|
-
|
|
273
|
+
async readPrivateKeyByInfo(keyInfo) {
|
|
274
274
|
if (!keyInfo) {
|
|
275
275
|
throw {
|
|
276
276
|
code: EndUserError.EU_ERROR_BAD_PARAMETER,
|
|
@@ -287,7 +287,7 @@ export default class DigitalSignature {
|
|
|
287
287
|
case DigitalSignatureKeyType.KSP:
|
|
288
288
|
return await this.readPrivateKeyKSP(keyInfo.ksp, keyInfo.kspUserId, false);
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
}
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
293
|
* Считать аппаратный ключ
|
|
@@ -311,10 +311,10 @@ export default class DigitalSignature {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
if (Array.isArray(certs)) {
|
|
314
|
-
certs = await Promise.all(certs.map(cert =>
|
|
314
|
+
certs = await Promise.all(certs.map(cert =>
|
|
315
315
|
cert instanceof File || cert instanceof Blob ? readFile(cert) :
|
|
316
|
-
|
|
317
|
-
|
|
316
|
+
cert instanceof EndUserCertificate ? cert.data :
|
|
317
|
+
cert));
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
try {
|
|
@@ -377,10 +377,10 @@ export default class DigitalSignature {
|
|
|
377
377
|
privateKey = await readFile(privateKey);
|
|
378
378
|
}
|
|
379
379
|
if (Array.isArray(certs)) {
|
|
380
|
-
certs = await Promise.all(certs.map(cert =>
|
|
380
|
+
certs = await Promise.all(certs.map(cert =>
|
|
381
381
|
cert instanceof File || cert instanceof Blob ? readFile(cert) :
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
cert instanceof EndUserCertificate ? cert.data :
|
|
383
|
+
cert));
|
|
384
384
|
}
|
|
385
385
|
try {
|
|
386
386
|
const ownerInfo = await this._euSign.ReadPrivateKeyBinary(privateKey, password, certs, this._selectedIssuerCN);
|
|
@@ -509,7 +509,7 @@ export default class DigitalSignature {
|
|
|
509
509
|
*/
|
|
510
510
|
async setTwoFactorCodeKSP(code) {
|
|
511
511
|
await this.setLibraryType(DigitalSignatureKeyType.KSP);
|
|
512
|
-
|
|
512
|
+
|
|
513
513
|
return this._euSign.m_library.m_worker.postMessage("SetTwoFactorCodeKSP", [code]);
|
|
514
514
|
}
|
|
515
515
|
|
|
@@ -523,11 +523,11 @@ export default class DigitalSignature {
|
|
|
523
523
|
* @param {authenticationCallback} event - Коллбэк. Вызывается при запросе на подписание.
|
|
524
524
|
*/
|
|
525
525
|
async addConfirmKSPOperationEventListener(event) {
|
|
526
|
-
await this._euSignFile.AddEventListener(EndUserConstants.EndUserEventType.ConfirmKSPOperation, function(data) {
|
|
526
|
+
await this._euSignFile.AddEventListener(EndUserConstants.EndUserEventType.ConfirmKSPOperation, function (data) {
|
|
527
527
|
data.qrCode = "data:image/bmp;base64," + data.qrCode;
|
|
528
528
|
event(data);
|
|
529
529
|
});
|
|
530
|
-
}
|
|
530
|
+
}
|
|
531
531
|
|
|
532
532
|
/**
|
|
533
533
|
* Получить список облачных провайдеров
|
|
@@ -560,9 +560,9 @@ export default class DigitalSignature {
|
|
|
560
560
|
/**
|
|
561
561
|
* Остановить операцио с облачным ключом
|
|
562
562
|
*/
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
563
|
+
async resetKSPOperation() {
|
|
564
|
+
await this._euSignFile.ResetOperationKSP();
|
|
565
|
+
}
|
|
566
566
|
|
|
567
567
|
/**
|
|
568
568
|
* Получить список центров сертификации
|
|
@@ -615,11 +615,24 @@ export default class DigitalSignature {
|
|
|
615
615
|
asByteArray = false;
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
-
if (this.readedKey.keyType === DigitalSignatureKeyType.KSP
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
618
|
+
if (this.readedKey.keyType === DigitalSignatureKeyType.KSP) {
|
|
619
|
+
if (signType.type !== EndUserConstants.EU_SIGN_CONTAINER_TYPE_CADES &&
|
|
620
|
+
signType.type !== EndUserConstants.EU_SIGN_CONTAINER_TYPE_PADES) {
|
|
621
|
+
throw {
|
|
622
|
+
code: EndUserError.EU_ERROR_NOT_SUPPORTED,
|
|
623
|
+
message: this._resourses.KSPSignFormatError
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (signType.type === EndUserConstants.EU_SIGN_CONTAINER_TYPE_PADES) {
|
|
628
|
+
const ksp = typeof this.readedKey.ksp === "object" ? this.readedKey.ksp.ksp : this.readedKey.ksp;
|
|
629
|
+
if (ksp != EndUserKSP.GRYADA) {
|
|
630
|
+
throw {
|
|
631
|
+
code: EndUserError.EU_ERROR_NOT_SUPPORTED,
|
|
632
|
+
message: this._resourses.KSPSignPAdESError
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
}
|
|
623
636
|
}
|
|
624
637
|
|
|
625
638
|
if (signType.type === EndUserConstants.EndUserSignContainerType.ASiC) {
|
|
@@ -1059,7 +1072,7 @@ export default class DigitalSignature {
|
|
|
1059
1072
|
/**
|
|
1060
1073
|
* Получить предпочитаемый тип ключа
|
|
1061
1074
|
*/
|
|
1062
|
-
|
|
1075
|
+
get _preferredKeyType() {
|
|
1063
1076
|
const keyType = parseInt(localStorage[this._userId + PRIVATE_KEY_TYPE]);
|
|
1064
1077
|
if (typeof keyType === "number" && keyType > -1) {
|
|
1065
1078
|
return keyType;
|
|
@@ -1073,7 +1086,7 @@ export default class DigitalSignature {
|
|
|
1073
1086
|
* Задать предпочитаемый тип ключа
|
|
1074
1087
|
* @param {DigitalSignatureKeyType | number} keyType - Тип ключа
|
|
1075
1088
|
*/
|
|
1076
|
-
set _preferredKeyType
|
|
1089
|
+
set _preferredKeyType(keyType) {
|
|
1077
1090
|
if (typeof keyType === "number" && keyType > -1) {
|
|
1078
1091
|
localStorage[this._userId + PRIVATE_KEY_TYPE] = keyType;
|
|
1079
1092
|
}
|
|
@@ -1083,11 +1096,11 @@ export default class DigitalSignature {
|
|
|
1083
1096
|
return Resourses[this._language];
|
|
1084
1097
|
}
|
|
1085
1098
|
|
|
1086
|
-
get _userId
|
|
1099
|
+
get _userId() {
|
|
1087
1100
|
return typeof this._settingsProvider.userId === "function" ? this._settingsProvider.userId() : this._settingsProvider.userId;
|
|
1088
1101
|
}
|
|
1089
1102
|
|
|
1090
|
-
get _language
|
|
1103
|
+
get _language() {
|
|
1091
1104
|
return typeof this._settingsProvider.language === "function" ? this._settingsProvider.language() : this._settingsProvider.language;
|
|
1092
1105
|
}
|
|
1093
1106
|
|
|
@@ -1106,5 +1119,21 @@ export default class DigitalSignature {
|
|
|
1106
1119
|
};
|
|
1107
1120
|
}
|
|
1108
1121
|
}
|
|
1122
|
+
try {
|
|
1123
|
+
const health = await downloadData(new URL(ksp.address).origin + "/health");
|
|
1124
|
+
if (health.trim().toLowerCase() != "healthy") {
|
|
1125
|
+
throw {
|
|
1126
|
+
code: EndUserError.EU_ERROR_TRANSMIT_REQUEST,
|
|
1127
|
+
message: this._resourses.DiiaHealthCheckError
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
console.error(error);
|
|
1132
|
+
throw {
|
|
1133
|
+
code: EndUserError.EU_ERROR_TRANSMIT_REQUEST,
|
|
1134
|
+
message: this._resourses.DiiaHealthCheckError
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1109
1138
|
}
|
|
1110
1139
|
}
|
package/src/Resourses.json
CHANGED
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
"LibraryUpdate": "Оновлення web-бібліотеки підпису",
|
|
11
11
|
"PrivateKeyNotReaded": "Особистий ключ не считано.",
|
|
12
12
|
"DiiaError": "Дія.Підпис – сервіс для накладання кваліфікованого електронного підпису за допомогою смартфону і додатку «Дія».<br/>Для можливості використання «Дія.Підпис» у даній інсталяції системи вам необхідно звернутися до свого постачальника.<br/>У зверненні вкажіть наступну інформацію:<br/><ul><li>Посилання: ",
|
|
13
|
+
"DiiaHealthCheckError": "Сервіс Дія.Підпис недоступний.",
|
|
13
14
|
"XadesError": "Перевірка кваліфікованого електронного підпису, який сформовано у вигляді окремого файлу з розширенням .xml виконується за умов наявності файлу з даними, на які накладено кваліфікований електронний підпис. Ім`я такого файлу зазвичай ідентичне з іменем файлу файлу з розширенням .xml. Оберіть цей файл разом з файлом кваліфікованого електронного підпису.",
|
|
14
|
-
"KSPSignFormatError": "Хмарні сервіси підтримують тільки підписи типу CAdES",
|
|
15
|
+
"KSPSignFormatError": "Хмарні сервіси підтримують тільки підписи типу CAdES або PAdES",
|
|
16
|
+
"KSPSignPAdESError": "Створення підписів в форматі PAdES підтримується тільки для Серверу підпису",
|
|
15
17
|
"BadSignatureType": "Невірний тип підпису",
|
|
16
18
|
"DownloadingRootCertificatesError": "Помилка при завантаженні сертифікатів ЦСК або списку ЦСК. Перевірте наявність налаштувань ЦСК в функції \"Інструменти і налаштування → Електронний підпис → Налаштування ЦСК\" та виконання задачі планувальника UPDATECASCERTIFICATES.",
|
|
17
19
|
"BadParameter": "Невірний параметр",
|
|
@@ -31,8 +33,10 @@
|
|
|
31
33
|
"LibraryUpdate": "Обновление web-библиотеки подписи",
|
|
32
34
|
"PrivateKeyNotReaded": "Приватный ключ не считан.",
|
|
33
35
|
"DiiaError": "Дія.Підпис – сервис для наложения квалифицированной электронной подписи с помощью смартфона и приложения «Дія».<br/>Для возможности использования «Дія.Підпис» в данной инсталляции системы вам необходимо обратиться к своему поставщику.<br/>В обращении укажите следующую информацию:<br/><ul><li>Ссылка: ",
|
|
36
|
+
"DiiaHealthCheckError": "Сервис Дія.Підпис недоступен.",
|
|
34
37
|
"XadesError": "Проверка квалифицированной электронной подписи, которая сформирована в виде отдельного файла с расширением .xml, выполняется при наличии файла с данными, на которые наложена квалифицированная электронная подпись. Имя такого файла обычно идентично с именем файла с расширением .xml. Выберите этот файл вместе с квалифицированной электронной подписью.",
|
|
35
|
-
"KSPSignFormatError": "Облачные сервисы поддерживают только подписи типа CAdES",
|
|
38
|
+
"KSPSignFormatError": "Облачные сервисы поддерживают только подписи типа CAdES или PAdES",
|
|
39
|
+
"KSPSignPAdESError": "Создание подписей в формате PAdES поддерживается только для Сервера подписи",
|
|
36
40
|
"BadSignatureType": "Неверный тип подписи",
|
|
37
41
|
"DownloadingRootCertificatesError": "Ошибка при загрузке корневых сертификатов ЦСК, либо списка ЦСК. Проверьте наличие настроек ЦСК в функции \"Инструменты и настройки → Электронная подпись → Настройки ЦСК\" и выполнение задачи планировщика UPDATECASCERTIFICATES.",
|
|
38
42
|
"BadParameter": "Неверный параметр",
|
|
@@ -51,9 +55,11 @@
|
|
|
51
55
|
"LibraryInstall": "Web-signature library installation package",
|
|
52
56
|
"LibraryUpdate": "Web-signature library update package",
|
|
53
57
|
"PrivateKeyNotReaded": "Private key not readed.",
|
|
54
|
-
"DiiaError": "Diia.Sign - a service for applying a qualified digital signature using a smartphone and the application \"
|
|
58
|
+
"DiiaError": "Diia.Sign - a service for applying a qualified digital signature using a smartphone and the application \"Diia\". <br/> To be able to use \"Diia.Sign\" in this system, you need to contact your provider. <br/> Please include the following information in your request: <br/> <ul> <li> Link: ",
|
|
59
|
+
"DiiaHealthCheckError": "Diia.Sign service is unavailable.",
|
|
55
60
|
"XadesError": "The verification of a qualified digital signature, which is formed as a separate file with the extension .xml, is performed under the conditions of the file with the data on which the qualified digital signature is affixed. The name of such a file is usually identical to the filename of the .xml file. Select this file along with the qualified digital signature file.",
|
|
56
|
-
"KSPSignFormatError": "Cloud services only supports CAdES signatures",
|
|
61
|
+
"KSPSignFormatError": "Cloud services only supports CAdES or PAdES signatures",
|
|
62
|
+
"KSPSignPAdESError": "PAdES signatures are supported only by SignServer",
|
|
57
63
|
"BadSignatureType": "Invalid signature type",
|
|
58
64
|
"DownloadingRootCertificatesError": "Error occured while downloading root CA certificates or CA list. Check for CA setting in function \"Tools and settings → Electronic signature → CA settings\" and execution of task scheduler UPDATECASCERTIFICATES.",
|
|
59
65
|
"BadParameter": "Invalid parameter",
|
package/src/euscp.worker.js
CHANGED
|
@@ -12484,6 +12484,10 @@ EndUserKSP.prototype._CtxReadPrivateKeyWithServer = function(
|
|
|
12484
12484
|
return;
|
|
12485
12485
|
}
|
|
12486
12486
|
|
|
12487
|
+
if (authData && typeof authData.val != 'string') {
|
|
12488
|
+
authData.val = pThis.m_euSign.Base64Encode(item.val);
|
|
12489
|
+
}
|
|
12490
|
+
|
|
12487
12491
|
var originatorDescription = caption ?
|
|
12488
12492
|
caption :
|
|
12489
12493
|
SS_SERVER_ORIGINATOR_DESCRIPTION.replace("%s",
|
|
@@ -13817,23 +13821,35 @@ EndUser.prototype.GetCASettings = function(CACommonName) {
|
|
|
13817
13821
|
|
|
13818
13822
|
//-------------------------------------------------------------------------------
|
|
13819
13823
|
|
|
13820
|
-
EndUser.prototype.GetDefaultTSPSettings = function() {
|
|
13821
|
-
var
|
|
13822
|
-
var CA = null;
|
|
13824
|
+
EndUser.prototype.GetDefaultTSPSettings = function(settings) {
|
|
13825
|
+
var tsp = null;
|
|
13823
13826
|
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13827
|
+
if (settings.TSPServer) {
|
|
13828
|
+
tsp = settings.TSPServer;
|
|
13829
|
+
} else {
|
|
13830
|
+
var CA = null;
|
|
13828
13831
|
|
|
13829
|
-
|
|
13830
|
-
|
|
13832
|
+
var CAs = settings.CAs;
|
|
13833
|
+
for (var i = 0; i < CAs.length; i++) {
|
|
13834
|
+
if (!CAs[i].tspAddress || !CAs[i].tspAddressPort)
|
|
13835
|
+
continue;
|
|
13831
13836
|
|
|
13832
|
-
|
|
13833
|
-
|
|
13837
|
+
if (!CA || CAs[i].tspAddressPort == "80")
|
|
13838
|
+
CA = CAs[i];
|
|
13839
|
+
|
|
13840
|
+
if (CA.tspAddressPort == "80")
|
|
13841
|
+
break;
|
|
13842
|
+
}
|
|
13843
|
+
|
|
13844
|
+
if (CA) {
|
|
13845
|
+
tsp = {
|
|
13846
|
+
"address": CA.tspAddress,
|
|
13847
|
+
"port": CA.tspAddressPort
|
|
13848
|
+
};
|
|
13849
|
+
}
|
|
13834
13850
|
}
|
|
13835
13851
|
|
|
13836
|
-
return
|
|
13852
|
+
return tsp;
|
|
13837
13853
|
};
|
|
13838
13854
|
|
|
13839
13855
|
//-------------------------------------------------------------------------------
|
|
@@ -13857,7 +13873,8 @@ EndUser.prototype.SetCMPSettings = function(CACommonName) {
|
|
|
13857
13873
|
var euSign = pThis.m_euSign;
|
|
13858
13874
|
var CA = pThis.GetCASettings(CACommonName);
|
|
13859
13875
|
|
|
13860
|
-
if (CACommonName && (CA == null)
|
|
13876
|
+
if (CACommonName && (CA == null) &&
|
|
13877
|
+
!pThis.m_settings.allowForeignCAs) {
|
|
13861
13878
|
euSign.RaiseError(EU_ERROR_WRITE_SETTINGS);
|
|
13862
13879
|
return;
|
|
13863
13880
|
}
|
|
@@ -14533,7 +14550,7 @@ EndUser.prototype.Initialize = function(settings, onSuccess, onError) {
|
|
|
14533
14550
|
|
|
14534
14551
|
var CAs = settings.CAs;
|
|
14535
14552
|
var offline = true;
|
|
14536
|
-
var tspSettings = pThis.GetDefaultTSPSettings();
|
|
14553
|
+
var tspSettings = pThis.GetDefaultTSPSettings(settings);
|
|
14537
14554
|
var useOCSP = false;
|
|
14538
14555
|
|
|
14539
14556
|
for (var i = 0; i < CAs.length; i++) {
|
|
@@ -14553,8 +14570,8 @@ EndUser.prototype.Initialize = function(settings, onSuccess, onError) {
|
|
|
14553
14570
|
var tsp = euSign.CreateTSPSettings();
|
|
14554
14571
|
tsp.SetGetStamps(!!tspSettings);
|
|
14555
14572
|
if (tspSettings) {
|
|
14556
|
-
tsp.SetAddress(tspSettings.
|
|
14557
|
-
tsp.SetPort(tspSettings.
|
|
14573
|
+
tsp.SetAddress(tspSettings.address);
|
|
14574
|
+
tsp.SetPort(tspSettings.port);
|
|
14558
14575
|
}
|
|
14559
14576
|
euSign.SetTSPSettings(tsp);
|
|
14560
14577
|
|
|
@@ -17024,11 +17041,19 @@ EndUserKSP.prototype._CtxSignHashesWithServer = (function(_super) {
|
|
|
17024
17041
|
hashesValues.push(item.val);
|
|
17025
17042
|
}
|
|
17026
17043
|
|
|
17027
|
-
|
|
17028
|
-
|
|
17029
|
-
|
|
17030
|
-
|
|
17031
|
-
|
|
17044
|
+
if (signContainerType == EndUserKSP.EU_KSP_SIGN_CONTAINER_PADES) {
|
|
17045
|
+
pThis._SignServerSendRequest(basePath + "/Sign/HashPDF", JSON.stringify({
|
|
17046
|
+
keyName: kspSettings.systemId,
|
|
17047
|
+
keyPassword: "##" + keyContext.userId + "##" + keyContext.keyId,
|
|
17048
|
+
hashes: hashesValues
|
|
17049
|
+
}), onSuccess, onError);
|
|
17050
|
+
} else {
|
|
17051
|
+
pThis._SignServerSendRequest(basePath + "/Sign/HashArray", JSON.stringify({
|
|
17052
|
+
keyName: kspSettings.systemId,
|
|
17053
|
+
keyPassword: "##" + keyContext.userId + "##" + keyContext.keyId,
|
|
17054
|
+
hashes: hashesValues
|
|
17055
|
+
}), onSuccess, onError);
|
|
17056
|
+
}
|
|
17032
17057
|
return;
|
|
17033
17058
|
|
|
17034
17059
|
} else if (kspSettings.ksp == EndUserKSP.EU_KSP_VTOKEN) {
|
|
@@ -12484,6 +12484,10 @@ EndUserKSP.prototype._CtxReadPrivateKeyWithServer = function(
|
|
|
12484
12484
|
return;
|
|
12485
12485
|
}
|
|
12486
12486
|
|
|
12487
|
+
if (authData && typeof authData.val != 'string') {
|
|
12488
|
+
authData.val = pThis.m_euSign.Base64Encode(item.val);
|
|
12489
|
+
}
|
|
12490
|
+
|
|
12487
12491
|
var originatorDescription = caption ?
|
|
12488
12492
|
caption :
|
|
12489
12493
|
SS_SERVER_ORIGINATOR_DESCRIPTION.replace("%s",
|
|
@@ -13817,23 +13821,35 @@ EndUser.prototype.GetCASettings = function(CACommonName) {
|
|
|
13817
13821
|
|
|
13818
13822
|
//-------------------------------------------------------------------------------
|
|
13819
13823
|
|
|
13820
|
-
EndUser.prototype.GetDefaultTSPSettings = function() {
|
|
13821
|
-
var
|
|
13822
|
-
var CA = null;
|
|
13824
|
+
EndUser.prototype.GetDefaultTSPSettings = function(settings) {
|
|
13825
|
+
var tsp = null;
|
|
13823
13826
|
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13827
|
+
if (settings.TSPServer) {
|
|
13828
|
+
tsp = settings.TSPServer;
|
|
13829
|
+
} else {
|
|
13830
|
+
var CA = null;
|
|
13828
13831
|
|
|
13829
|
-
|
|
13830
|
-
|
|
13832
|
+
var CAs = settings.CAs;
|
|
13833
|
+
for (var i = 0; i < CAs.length; i++) {
|
|
13834
|
+
if (!CAs[i].tspAddress || !CAs[i].tspAddressPort)
|
|
13835
|
+
continue;
|
|
13831
13836
|
|
|
13832
|
-
|
|
13833
|
-
|
|
13837
|
+
if (!CA || CAs[i].tspAddressPort == "80")
|
|
13838
|
+
CA = CAs[i];
|
|
13839
|
+
|
|
13840
|
+
if (CA.tspAddressPort == "80")
|
|
13841
|
+
break;
|
|
13842
|
+
}
|
|
13843
|
+
|
|
13844
|
+
if (CA) {
|
|
13845
|
+
tsp = {
|
|
13846
|
+
"address": CA.tspAddress,
|
|
13847
|
+
"port": CA.tspAddressPort
|
|
13848
|
+
};
|
|
13849
|
+
}
|
|
13834
13850
|
}
|
|
13835
13851
|
|
|
13836
|
-
return
|
|
13852
|
+
return tsp;
|
|
13837
13853
|
};
|
|
13838
13854
|
|
|
13839
13855
|
//-------------------------------------------------------------------------------
|
|
@@ -13857,7 +13873,8 @@ EndUser.prototype.SetCMPSettings = function(CACommonName) {
|
|
|
13857
13873
|
var euSign = pThis.m_euSign;
|
|
13858
13874
|
var CA = pThis.GetCASettings(CACommonName);
|
|
13859
13875
|
|
|
13860
|
-
if (CACommonName && (CA == null)
|
|
13876
|
+
if (CACommonName && (CA == null) &&
|
|
13877
|
+
!pThis.m_settings.allowForeignCAs) {
|
|
13861
13878
|
euSign.RaiseError(EU_ERROR_WRITE_SETTINGS);
|
|
13862
13879
|
return;
|
|
13863
13880
|
}
|
|
@@ -14533,7 +14550,7 @@ EndUser.prototype.Initialize = function(settings, onSuccess, onError) {
|
|
|
14533
14550
|
|
|
14534
14551
|
var CAs = settings.CAs;
|
|
14535
14552
|
var offline = true;
|
|
14536
|
-
var tspSettings = pThis.GetDefaultTSPSettings();
|
|
14553
|
+
var tspSettings = pThis.GetDefaultTSPSettings(settings);
|
|
14537
14554
|
var useOCSP = false;
|
|
14538
14555
|
|
|
14539
14556
|
for (var i = 0; i < CAs.length; i++) {
|
|
@@ -14553,8 +14570,8 @@ EndUser.prototype.Initialize = function(settings, onSuccess, onError) {
|
|
|
14553
14570
|
var tsp = euSign.CreateTSPSettings();
|
|
14554
14571
|
tsp.SetGetStamps(!!tspSettings);
|
|
14555
14572
|
if (tspSettings) {
|
|
14556
|
-
tsp.SetAddress(tspSettings.
|
|
14557
|
-
tsp.SetPort(tspSettings.
|
|
14573
|
+
tsp.SetAddress(tspSettings.address);
|
|
14574
|
+
tsp.SetPort(tspSettings.port);
|
|
14558
14575
|
}
|
|
14559
14576
|
euSign.SetTSPSettings(tsp);
|
|
14560
14577
|
|
|
@@ -433,11 +433,19 @@ EndUserKSP.prototype._CtxSignHashesWithServer = (function(_super) {
|
|
|
433
433
|
hashesValues.push(item.val);
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
436
|
+
if (signContainerType == EndUserKSP.EU_KSP_SIGN_CONTAINER_PADES) {
|
|
437
|
+
pThis._SignServerSendRequest(basePath + "/Sign/HashPDF", JSON.stringify({
|
|
438
|
+
keyName: kspSettings.systemId,
|
|
439
|
+
keyPassword: "##" + keyContext.userId + "##" + keyContext.keyId,
|
|
440
|
+
hashes: hashesValues
|
|
441
|
+
}), onSuccess, onError);
|
|
442
|
+
} else {
|
|
443
|
+
pThis._SignServerSendRequest(basePath + "/Sign/HashArray", JSON.stringify({
|
|
444
|
+
keyName: kspSettings.systemId,
|
|
445
|
+
keyPassword: "##" + keyContext.userId + "##" + keyContext.keyId,
|
|
446
|
+
hashes: hashesValues
|
|
447
|
+
}), onSuccess, onError);
|
|
448
|
+
}
|
|
441
449
|
return;
|
|
442
450
|
|
|
443
451
|
} else if (kspSettings.ksp == EndUserKSP.EU_KSP_VTOKEN) {
|