Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webcrypto-liner

Package Overview
Dependencies
Maintainers
2
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webcrypto-liner - npm Package Compare versions

Comparing version 0.1.12 to 0.1.13

debug.log

2

BrowserSupport.md

@@ -16,3 +16,3 @@ # WebCrypto-Liner Browser Support

### Safari
![image](https://cloud.githubusercontent.com/assets/1619279/21753856/4f03b922-d5aa-11e6-8f63-c2bad2e54cd1.png)
![image](https://cloud.githubusercontent.com/assets/1619279/22898521/75c8b35c-f1dc-11e6-8698-659b4c98ab26.png)

@@ -19,0 +19,0 @@ ### Edge

@@ -1,2 +0,2 @@

var liner=function(e){function r(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,r),n.loaded=!0,n.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";var o=t(17);Object.freeze(Math),Object.freeze(Math.random),Object.freeze(Math.imul),o.nativeCrypto&&Object.freeze(o.nativeCrypto.getRandomValues),r.crypto=new o.Crypto},function(e,r,t){"use strict";function o(e){var r;r="string"==typeof e?{name:e}:e,i.checkAlgorithm(r);var t=e;return t.hash&&(t.hash=o(t.hash)),r}function n(e,r){if(!e)throw new a.WebCryptoError("Parameter '"+r+"' is required and cant be empty");if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer);if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new a.WebCryptoError("Incoming parameter '"+r+"' has wrong data type. Must be ArrayBufferView or ArrayBuffer")}var a=t(2);r.PrepareAlgorithm=o,r.PrepareData=n;var i=function(){function e(){}return e.checkAlgorithm=function(e){if("object"!=typeof e)throw new TypeError("Wrong algorithm data type. Must be Object");if(!("name"in e))throw new a.AlgorithmError(a.AlgorithmError.PARAM_REQUIRED,"name")},e.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},e.checkKey=function(e,r,t,o){if(void 0===t&&(t=null),void 0===o&&(o=null),!e)throw new a.CryptoKeyError(a.CryptoKeyError.EMPTY_KEY);var n=e.algorithm;if(this.checkAlgorithm(n),r&&n.name.toUpperCase()!==r.toUpperCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_ALG,n.name,r);if(t&&(!e.type||e.type.toUpperCase()!==t.toUpperCase()))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_TYPE,e.type,t);if(o&&!e.usages.some(function(e){return o.toUpperCase()===e.toUpperCase()}))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_USAGE,o)},e.checkWrappedKey=function(e){if(!e.extractable)throw new a.CryptoKeyError(a.CryptoKeyError.NOT_EXTRACTABLE)},e.checkKeyUsages=function(e){if(!e||!e.length)throw new a.WebCryptoError("Parameter 'keyUsages' cannot be empty.")},e.checkFormat=function(e,r){switch(e.toLowerCase()){case"raw":if(r&&"secret"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"raw");break;case"pkcs8":if(r&&"private"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"pkcs8");break;case"spki":if(r&&"public"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"spki");break;case"jwk":break;default:throw new a.CryptoKeyError(a.CryptoKeyError.UNKNOWN_FORMAT,e)}},e.generateKey=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.digest=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.sign=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.verify=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.encrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.decrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveBits=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.exportKey=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.importKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.wrapKey=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.unwrapKey=function(e,r,t,o,n,i,s){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e}();r.BaseCrypto=i},function(e,r){"use strict";function t(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o,n=e,a=/[^%](%\d+)/g,i=[];o=a.exec(n);)i.push({arg:o[1],index:o.index});for(var s=i.length-1;s>=0;s--){var c=i[s],h=c.arg.substring(1),p=c.index+1;n=n.substring(0,p)+arguments[+h]+n.substring(p+1+h.length)}return n=n.replace("%%","%")}var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=function(e){function r(r){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];var a=e.call(this)||this;a.code=0,a.message=t.apply(void 0,[r].concat(o));var i=new Error(a.message);return i.name=a.constructor.name,a.stack=i.stack,a}return o(r,e),r}(Error);n.NOT_SUPPORTED="Method is not supported",r.WebCryptoError=n;var a=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=1,r}return o(r,e),r}(n);a.PARAM_REQUIRED="Algorithm hasn't got required paramter '%1'",a.PARAM_WRONG_TYPE="Algorithm has got wrong type for paramter '%1'. Must be %2",a.PARAM_WRONG_VALUE="Algorithm has got wrong value for paramter '%1'. Must be %2",a.WRONG_ALG_NAME="Algorithm has got wrong name '%1'. Must be '%2'",a.UNSUPPORTED_ALGORITHM="Algorithm '%1' is not supported",a.WRONG_USAGE="Algorithm doesn't support key usage '%1'",r.AlgorithmError=a;var i=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=3,r}return o(r,e),r}(n);i.EMPTY_KEY="CryptoKey is empty",i.WRONG_KEY_ALG="CryptoKey has wrong algorithm '%1'. Must be '%2'",i.WRONG_KEY_TYPE="CryptoKey has wrong type '%1'. Must be '%2'",i.WRONG_KEY_USAGE="CryptoKey has wrong key usage. Must be '%1'",i.NOT_EXTRACTABLE="CryptoKey is not extractable",i.WRONG_FORMAT="CryptoKey has '%1' type. It can be used with '%2' format",i.UNKNOWN_FORMAT="Uknown format in use '%1'. Must be one of 'raw', 'pkcs8', 'spki' or 'jwk'",i.ALLOWED_FORMAT="Wrong format value '%1'. Must be %2",r.CryptoKeyError=i},function(e,r){"use strict";r.AlgorithmNames={RsaSSA:"RSASSA-PKCS1-v1_5",RsaPSS:"RSA-PSS",RsaOAEP:"RSA-OAEP",AesCTR:"AES-CTR",AesCMAC:"AES-CMAC",AesGCM:"AES-GCM",AesCBC:"AES-CBC",AesKW:"AES-KW",Sha1:"SHA-1",Sha256:"SHA-256",Sha384:"SHA-384",Sha512:"SHA-512",EcDSA:"ECDSA",EcDH:"ECDH",Hmac:"HMAC",Pbkdf2:"PBKDF2"}},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(2)),o(t(1)),o(t(3)),o(t(21)),o(t(23)),o(t(10)),o(t(14)),o(t(12)),o(t(7))},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(n.WebCryptoError);a.MODULE_NOT_FOUND="Module '%1' is not found. Download it from %2",a.UNSUPPORTED_ALGORITHM="Unsupported algorithm '%1'",r.LinerError=a},function(e,r,t){"use strict";var o=t(20),n=t(9),a=function(){function e(){this.subtle=new o.SubtleCrypto}return e.prototype.getRandomValues=function(e){return n.nativeCrypto.getRandomValues(e)},e}();r.Crypto=a},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(3),a=t(1),i=t(2);r.ShaAlgorithms=[n.AlgorithmNames.Sha1,n.AlgorithmNames.Sha256,n.AlgorithmNames.Sha384,n.AlgorithmNames.Sha512].join(" | ");var s=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.checkAlgorithm=function(t){var o;switch(o="string"==typeof t?{name:t}:t,e.checkAlgorithm.call(this,o),o.name.toUpperCase()){case n.AlgorithmNames.Sha1:case n.AlgorithmNames.Sha256:case n.AlgorithmNames.Sha384:case n.AlgorithmNames.Sha512:break;default:throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,o.name,r.ShaAlgorithms)}},t.digest=function(e,r){var t=this;return new Promise(function(r,o){t.checkAlgorithm(e),r(void 0)})},t}(a.BaseCrypto);r.Sha=s},function(e,r){"use strict";function t(){var e,t={name:"",version:""},o=self.navigator.userAgent;return(e=/edge\/([\d\.]+)/i.exec(o))?(t.name=r.Browser.Edge,t.version=e[1]):/msie/i.test(o)?(t.name=r.Browser.IE,t.version=/msie ([\d\.]+)/i.exec(o)[1]):/Trident/i.test(o)?(t.name=r.Browser.IE,t.version=/rv:([\d\.]+)/i.exec(o)[1]):/chrome/i.test(o)?(t.name=r.Browser.Chrome,t.version=/chrome\/([\d\.]+)/i.exec(o)[1]):/safari/i.test(o)?(t.name=r.Browser.Safari,t.version=/([\d\.]+) safari/i.exec(o)[1]):/firefox/i.test(o)&&(t.name=r.Browser.Firefox,t.version=/firefox\/([\d\.]+)/i.exec(o)[1]),t}function o(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}function n(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r}function a(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=new Uint8Array(e.map(function(e){return e.length}).reduce(function(e,r){return e+r})),o=0;return e.forEach(function(e,r){for(var n=0;n<e.length;n++)t[o+n]=e[n];o+=e.length}),t}function i(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o=arguments[0],n=1;n<arguments.length;n++){var a=arguments[n];for(var i in a)o[i]=a[i]}return o}r.Browser={IE:"Internet Explorer",Safari:"Safari",Edge:"Edge",Chrome:"Chrome",Firefox:"Firefox Mozilla"},r.BrowserInfo=t,r.string2buffer=o,r.buffer2string=n,r.concat=a,r.assign=i},function(e,r,t){"use strict";function o(e,r){var t=e[r];e[r]=function(){var o=arguments;return new Promise(function(n,a){var i=t.apply(e,o);i.oncomplete=function(e){console.log("Complited"),n(e.target.result)},i.onerror=function(e){console.log("Error"),a("Error on running '"+r+"' function")}})}}var n,a=t(5);if("undefined"==typeof self){var i=t(24);n={crypto:{subtle:{},getRandomValues:function(e){var r=e.buffer,t=new Uint8Array(r),o=i.randomBytes(t.length);return o.forEach(function(e,r){return t[r]=e}),e}}}}else n=self;if(r.nativeCrypto=n.msCrypto||n.crypto,r.nativeSubtle=r.nativeCrypto.subtle||r.nativeCrypto.webkitSubtle,n.msCrypto){if(!n.Promise)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"Promise","https://www.promisejs.org");o(r.nativeSubtle,"generateKey"),o(r.nativeSubtle,"digest"),o(r.nativeSubtle,"sign"),o(r.nativeSubtle,"verify"),o(r.nativeSubtle,"encrypt"),o(r.nativeSubtle,"decrypt"),o(r.nativeSubtle,"importKey"),o(r.nativeSubtle,"exportKey"),o(r.nativeSubtle,"wrapKey"),o(r.nativeSubtle,"unwrapKey"),o(r.nativeSubtle,"deriveKey"),o(r.nativeSubtle,"deriveBits")}Math.imul||(Math.imul=function(e,r){var t=e>>>16&65535,o=65535&e,n=r>>>16&65535,a=65535&r;return o*a+(t*a+o*n<<16>>>0)|0})},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=7,r}return o(r,e),r}(n.AlgorithmError),c=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkKeyUsages=function(r){var t=this;e.checkKeyUsages.call(this,r);var o=r.filter(function(e){return t.KEY_USAGES.indexOf(e)===-1});if(o.length)throw new n.AlgorithmError(n.AlgorithmError.WRONG_USAGE,o.join(", "))},r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){switch(e.length){case 128:case 192:case 256:break;default:throw new s(s.PARAM_WRONG_VALUE,"length","128, 192 or 256")}},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);c.ALG_NAME="",c.KEY_USAGES=[],r.Aes=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=8,r}return o(r,e),r}(n.AlgorithmError);r.AesAlgorithmError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"secret","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"secret","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(c);r.AesWrapKey=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","decrypt"),t(void 0)})},r}(p);u.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.AesEncrypt=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(16!==e.iv.byteLength)throw new h(h.PARAM_WRONG_VALUE,"iv","ArrayBufferView with size 16")},r}(u);m.ALG_NAME=i.AlgorithmNames.AesCBC,r.AesCBC=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.counter||!ArrayBuffer.isView(e.counter))throw new h(h.PARAM_WRONG_TYPE,"counter","ArrayBufferView");if(16!==e.counter.byteLength)throw new h(h.PARAM_WRONG_VALUE,"counter","ArrayBufferView with size 16");if(!(e.length>0&&e.length<=128))throw new h(h.PARAM_WRONG_VALUE,"length","number [1-128]")},r}(u);y.ALG_NAME=i.AlgorithmNames.AesCTR,r.AesCTR=y;var f=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),e.additionalData&&!ArrayBuffer.isView(e.additionalData))throw new h(h.PARAM_WRONG_TYPE,"additionalData","ArrayBufferView");if(!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(e.tagLength&&!(e.tagLength>=0&&e.tagLength<=128))throw new h(h.PARAM_WRONG_VALUE,"tagLength","number [0-128]")},r}(u);f.ALG_NAME=i.AlgorithmNames.AesGCM,r.AesGCM=f;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},r}(p);l.ALG_NAME=i.AlgorithmNames.AesKW,l.KEY_USAGES=["wrapKey","unwrapKey"],r.AesKW=l},function(e,r){"use strict";var t=function(){function e(){}return e}();r.CryptoKey=t},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(10),a=t(7),i=t(2),s=t(1),c=t(3),h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=9,r}return o(r,e),r}(i.AlgorithmError);r.EcKeyGenParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){var r="namedCurve";if(!e.namedCurve)throw new h(h.PARAM_REQUIRED,r);if("string"!=typeof e.namedCurve)throw new h(h.PARAM_WRONG_TYPE,r,"string");switch(e.namedCurve.toUpperCase()){case"P-256":case"P-384":case"P-521":break;default:throw new h(h.PARAM_WRONG_VALUE,r,"P-256, P-384 or P-521")}},r.checkKeyGenUsages=function(e){var r=this;e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new i.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,n){var a=this;return new Promise(function(r,o){if(a.checkKeyGenParams(t),a.checkFormat(e),"raw"===e.toLowerCase())throw new i.CryptoKeyError(i.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");a.checkKeyGenUsages(n),r(void 0)})},r}(s.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Ec=p;var u=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(i.AlgorithmError);r.EcAlgorithmError=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e),a.Sha.checkAlgorithm(e.hash)},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);m.ALG_NAME=c.AlgorithmNames.EcDSA,m.KEY_USAGES=["sign","verify","deriveKey","deriveBits"],r.EcDSA=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkDeriveParams=function(e){var r="public";if(this.checkAlgorithm(e),!e.public)throw new u(u.PARAM_REQUIRED,r);this.checkKey(e.public,this.ALG_NAME,"public")},r.deriveBits=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"private","deriveBits"),t(void 0)})},r.deriveKey=function(e,r,t,o,a){var i=this;return new Promise(function(o,a){switch(i.checkDeriveParams(e),i.checkKey(r,i.ALG_NAME,"private","deriveKey"),s.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case c.AlgorithmNames.AesCBC:n.AesCBC.checkKeyGenParams(t);break;case c.AlgorithmNames.AesCTR:n.AesCTR.checkKeyGenParams(t);break;case c.AlgorithmNames.AesGCM:n.AesGCM.checkKeyGenParams(t);break;case c.AlgorithmNames.AesKW:n.AesKW.checkKeyGenParams(t);break;default:throw new u("Unsupported name '"+t.name+"' for algorithm in param 'derivedKeyType'")}o(void 0)})},r}(p);y.ALG_NAME=c.AlgorithmNames.EcDH,y.KEY_USAGES=["deriveKey","deriveBits"],r.EcDH=y},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){if("length"in e&&!(e.length>0&&e.length<=512))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_VALUE,"length","more 0 and less than 512")},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"secret","verify"),t(void 0)})},r}(a.BaseCrypto);s.ALG_NAME=i.AlgorithmNames.Hmac,s.KEY_USAGES=["sign","verify"],r.Hmac=s},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=t(7),c=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=2,r}return o(r,e),r}(n.AlgorithmError);r.RsaKeyGenParamsError=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=6,r}return o(r,e),r}(n.AlgorithmError);r.RsaHashedImportParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkImportAlgorithm=function(e){if(this.checkAlgorithm(e),!e.hash)throw new h(h.PARAM_REQUIRED,"hash");s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenParams=function(e){switch(e.modulusLength){case 1024:case 2048:case 4096:break;default:throw new c(c.PARAM_WRONG_VALUE,"modulusLength","1024, 2048 or 4096")}var r=e.publicExponent;if(!r)throw new c(c.PARAM_REQUIRED,"publicExponent");if(!ArrayBuffer.isView(r))throw new c(c.PARAM_WRONG_TYPE,"publicExponent","ArrayBufferView");if(3!==r[0]&&(1!==r[0]||0!==r[1]||1!==r[2]))throw new c(c.PARAM_WRONG_VALUE,"publicExponent","Uint8Array([3]) | Uint8Array([1, 0, 1])");if(!e.hash)throw new c(c.PARAM_REQUIRED,"hash",s.ShaAlgorithms);s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkImportAlgorithm(t),i.checkFormat(e),"raw"===e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Rsa=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);u.ALG_NAME=i.AlgorithmNames.RsaSSA,u.KEY_USAGES=["sign","verify"],r.RsaSSA=u;var m=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=4,r}return o(r,e),r}(n.AlgorithmError);r.RsaPSSParamsError=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkRsaPssParams=function(r){return e.checkAlgorithmParams.call(this,r),r.saltLength?r.saltLength%8?new m("Parameter 'saltLength' should be a multiple of 8"):void 0:new m(m.PARAM_REQUIRED,"saltLength")},r}(u);y.ALG_NAME=i.AlgorithmNames.RsaPSS,y.KEY_USAGES=["sign","verify"],r.RsaPSS=y;var f=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=5,r}return o(r,e),r}(n.AlgorithmError);r.RsaOAEPParamsError=f;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(e.label&&!ArrayBuffer.isView(e.label))return new f(f.PARAM_WRONG_TYPE,"label","ArrayBufferView")},r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"public","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","decrypt"),t(void 0)})},r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"public","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"private","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(p);l.ALG_NAME=i.AlgorithmNames.RsaOAEP,l.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.RsaOAEP=l},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=t(11),s=t(8),c=t(9),h=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=c.nativeCrypto.getRandomValues(new Uint8Array(e.length/8)),a=new i.CryptoKey;return a.key=n,a.algorithm=e,a.extractable=r,a.type="secret",a.usages=t,a})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.encrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.encrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.decrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.decrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):s.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var c;return Promise.resolve().then(function(){return c=new p.Crypto,c.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(s.buffer2string(new Uint8Array(r))):new Uint8Array(r),c.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){return"A"+e.length+/-(\w+)/i.exec(e.name.toUpperCase())[1]},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){var o=r.key;if("jwk"===e.toLowerCase()){var a={alg:t.alg2jwk(r.algorithm),ext:r.extractable,k:n.Base64Url.encode(o),key_ops:r.usages,kty:"oct"};return a}return o.buffer})},r.importKey=function(e,r,t,o,a){return Promise.resolve().then(function(){var o;if("jwk"===e.toLowerCase()){var s=r;o=n.Base64Url.decode(s.k)}else o=new Uint8Array(r);var c=new i.CryptoKey;return c.algorithm=t,c.type="secret",c.usages=a,c.key=o,c})},r}(n.BaseCrypto);r.AesCrypto=h;var p=t(6)},function(e,r,t){"use strict";function o(e){for(var r=new Uint8Array(e),t=[],o=0;o<r.length;o++)t.push(r[o]);return t}function n(e,r){e.length%2&&(e="0"+e);for(var t=new Uint8Array(e.length/2),o=0;o<e.length;o++){var n=e.slice(o,++o+1);t[(o-1)/2]=parseInt(n,16)}if(r){var a=t.length;a=a>32?a>48?66:48:32,t.length<a&&(t=p.concat(new Uint8Array(a-t.length),t))}return t}function a(e,r){for(var t="",o=0;o<e.length;o++){var n=e[o].toString(16);t+=n.length%2?"0"+n:n}if(r){var a=e.length;a=a>32?a>48?66:48:32,t.length/2<a&&(t=new Array(2*a-t.length+1).join("0")+t)}return t}var i=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},s=t(4),c=t(5),h=t(11),p=t(8),u=function(e){function r(){return e.apply(this,arguments)||this}return i(r,e),r.checkModule=function(){if("undefined"==typeof elliptic)throw new c.LinerError(c.LinerError.MODULE_NOT_FOUND,"elliptic","https://github.com/indutny/elliptic")},r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var t=e,n=new elliptic.ec(t.namedCurve.replace("-","").toLowerCase()),a=new h.CryptoKey,i=new h.CryptoKey;return a.key=i.key=n.genKeyPair(),a.algorithm=i.algorithm=t,a.extractable=r,i.extractable=!0,a.type="private",i.type="public",e.name===s.AlgorithmNames.EcDSA?(a.usages=["sign"],i.usages=["verify"]):e.name===s.AlgorithmNames.EcDH&&(a.usages=i.usages=["deriveKey","deriveBits"]),{privateKey:a,publicKey:i}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){var r=e,o=new m.Crypto;return o.subtle.digest(r.hash,t)}).then(function(e){var t=o(e),i=r.key.sign(t),s=a(i.r.toArray(),!0)+a(i.s.toArray(),!0);return n(s).buffer})},r.verify=function(e,r,t,n){var a;return Promise.resolve().then(function(){var r=e;a={r:t.slice(0,t.byteLength/2),s:t.slice(t.byteLength/2)};var o=new m.Crypto;return o.subtle.digest(r.hash,n)}).then(function(e){var t=o(e);return r.key.verify(t,a)})},r.deriveKey=function(e,r,t,o,n){var a=this;return Promise.resolve().then(function(){return a.deriveBits(e,r,t.length)}).then(function(e){var r=new m.Crypto;return r.subtle.importKey("raw",new Uint8Array(e),t,o,n)})},r.deriveBits=function(e,r,t){return Promise.resolve().then(function(){var o=(Promise.resolve(null),r.key.derive(e.public.key.getPublic())),n=new Uint8Array(o.toArray()),a=n.length;a=a>32?a>48?66:48:32,n.length<a&&(n=p.concat(new Uint8Array(a-n.length),n));var i=n.slice(0,t/8).buffer;return i})},r.exportKey=function(e,r){return Promise.resolve().then(function(){var t=r.key;if("jwk"===e.toLowerCase()){var o=t.getPublic("hex").slice(2),a=o.slice(0,o.length/2),i=o.slice(o.length/2,o.length);if("public"===r.type){var h={crv:r.algorithm.namedCurve,ext:r.extractable,x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}var h={crv:r.algorithm.namedCurve,ext:r.extractable,d:s.Base64Url.encode(n(t.getPrivate("hex"),!0)),x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}throw new c.LinerError("Format '"+e+"' is not implemented")})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var i=new h.CryptoKey;if(i.algorithm=t,"jwk"!==e.toLowerCase())throw new c.LinerError("Format '"+e+"' is not implemented");var u=new elliptic.ec(r.crv.replace("-","").toLowerCase());if(r.d)i.key=u.keyFromPrivate(s.Base64Url.decode(r.d)),i.type="private";else{var m=p.concat(new Uint8Array([4]),s.Base64Url.decode(r.x),s.Base64Url.decode(r.y)),y=a(m);
i.key=u.keyFromPublic(y,"hex"),i.type="public"}return i.extractable=o,i.usages=n,i})},r}(s.BaseCrypto);r.EcCrypto=u;var m=t(6)},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(9)),o(t(6))},function(e,r,t){"use strict";function o(e){var r=!0;return e.filter(function(e){return(!r||0!==e)&&(r=!1,!0)})}var n=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},a=t(4),i=t(5),s=t(11),c=t(8),h=function(e){function r(){return e.apply(this,arguments)||this}return n(r,e),r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new i.LinerError(i.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r.filterUsages=function(e,r){return e.filter(function(e){return!!r.filter(function(r){return e===r}).length})},r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=3===e.publicExponent[0]?3:65537,c=asmCrypto.RSA.generateKey(e.modulusLength,n),h=new s.CryptoKey,p=new s.CryptoKey;switch(h.key=p.key=c,h.algorithm=p.algorithm=e,h.extractable=r,p.extractable=!0,h.type="private",p.type="public",e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():h.usages=o.filterUsages(["decrypt","unwrapKey"],t),p.usages=o.filterUsages(["encrypt","wrapKey"],t);break;case a.AlgorithmNames.RsaPSS.toLowerCase():h.usages=o.filterUsages(["sign"],t),p.usages=o.filterUsages(["verify"],t);break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}return{privateKey:h,publicKey:p}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaPSS.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_PSS_SHA1.sign;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_PSS_SHA256.sign;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return s(t,r.key,n.saltLength).buffer;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.verify=function(e,r,t,o){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaPSS.toLowerCase():var n=r.algorithm,s=e,c=void 0;switch(n.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:c=asmCrypto.RSA_PSS_SHA1.verify;break;case a.AlgorithmNames.Sha256:c=asmCrypto.RSA_PSS_SHA256.verify;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return c(t,o,r.key,s.saltLength);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.encrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.encrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.decrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.decrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):c.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s;return Promise.resolve().then(function(){return s=new p.Crypto,s.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(c.buffer2string(new Uint8Array(r))):new Uint8Array(r),s.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){var r=e.hash,t=/(\d+)/.exec(r.name)[1];switch(e.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():return"RSA-OAEP"+("1"===t?"":"-"+t);case a.AlgorithmNames.RsaPSS.toUpperCase():return"PS"+t;case a.AlgorithmNames.RsaSSA.toUpperCase():return"RS"+t;default:throw new a.AlgorithmError(a.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){if("jwk"===e.toLowerCase()){var n={kty:"RSA",ext:!0,key_ops:r.usages};return n.alg=t.alg2jwk(r.algorithm),n.n=a.Base64Url.encode(o(r.key[0])),n.e=a.Base64Url.encode(o(r.key[1])),"private"===r.type&&(n.d=a.Base64Url.encode(o(r.key[2])),n.p=a.Base64Url.encode(o(r.key[3])),n.q=a.Base64Url.encode(o(r.key[4])),n.dp=a.Base64Url.encode(o(r.key[5])),n.dq=a.Base64Url.encode(o(r.key[6])),n.qi=a.Base64Url.encode(o(r.key[7]))),n}throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var o,c=new s.CryptoKey;if(c.algorithm=t,c.usages=n,c.key=[],"jwk"===e.toLowerCase())return o=r,c.key[0]=a.Base64Url.decode(o.n),c.key[1]=3===a.Base64Url.decode(o.e)[0]?new Uint8Array([0,0,0,3]):new Uint8Array([0,1,0,1]),o.d?(c.type="private",c.key[2]=a.Base64Url.decode(o.d),c.key[3]=a.Base64Url.decode(o.p),c.key[4]=a.Base64Url.decode(o.q),c.key[5]=a.Base64Url.decode(o.dp),c.key[6]=a.Base64Url.decode(o.dq),c.key[7]=a.Base64Url.decode(o.qi)):c.type="public",c;throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r}(a.BaseCrypto);r.RsaCrypto=h;var p=t(6)},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.digest=function(e,r){return Promise.resolve().then(function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js");switch(e.name.toUpperCase()){case n.AlgorithmNames.Sha1:return asmCrypto.SHA1.bytes(r).buffer;case n.AlgorithmNames.Sha256:return asmCrypto.SHA256.bytes(r).buffer;default:throw new a.LinerError("Not supported algorithm '"+e.name+"'")}})},r}(n.BaseCrypto);r.ShaCrypto=i},function(e,r,t){"use strict";function o(e,r){return Promise.resolve().then(function(){if(e.key)return e;if(e.extractable){var t=new l.Crypto;return t.subtle.exportKey("jwk",e).then(function(t){return r.importKey("jwk",t,e.algorithm,!0,e.usages)})}throw new f.LinerError("'key' is Native CryptoKey. It can't be converted to JS CryptoKey")})}function n(e,r){A.BrowserInfo().name!==A.Browser.IE&&A.BrowserInfo().name!==A.Browser.Edge&&A.BrowserInfo().name!==A.Browser.Safari||!/^rsa/i.test(e.name)||(r.privateKey?(v.push({hash:e.hash,key:r.privateKey}),v.push({hash:e.hash,key:r.publicKey})):v.push({hash:e.hash,key:r}))}function a(e){var r=null;return v.some(function(t){return t.key===e&&(r=A.assign({},e.algorithm,{hash:t.hash}),!0)}),r}function i(e,r){var t=[];e.privateKey?(t.push(e.privateKey),t.push(e.publicKey)):t.push(e),t.forEach(function(e){"keyUsage"in e&&(e.usages=e.keyUsage||[],e.usages.length||(["verify","encrypt","wrapKey"].forEach(function(t){r.indexOf(t)>-1&&("public"===e.type||"secret"===e.type)&&e.usages.push(t)}),["sign","decrypt","unwrapKey","deriveKey","deriveBits"].forEach(function(t){r.indexOf(t)>-1&&("private"===e.type||"secret"===e.type)&&e.usages.push(t)})))})}function s(e,r,t){if(r&&A.BrowserInfo().name===A.Browser.IE){"extractable"in e&&(e.ext=e.extractable,delete e.extractable);var o=null;switch(r.name.toUpperCase()){case p.AlgorithmNames.RsaOAEP.toUpperCase():case p.AlgorithmNames.RsaPSS.toUpperCase():case p.AlgorithmNames.RsaSSA.toUpperCase():o=E.RsaCrypto;break;case p.AlgorithmNames.AesCBC.toUpperCase():case p.AlgorithmNames.AesGCM.toUpperCase():o=w.AesCrypto}o&&!e.alg&&(e.alg=o.alg2jwk(r)),"key_ops"in e||(e.key_ops=t)}}function c(e){A.BrowserInfo().name===A.Browser.IE&&("ext"in e&&(e.extractable=e.ext,delete e.ext),delete e.key_ops,delete e.alg)}var h=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},p=t(4),u=t(4),m=t(4),y=t(9),f=t(5),l=t(6),A=t(8),w=t(15),g=t(19),E=t(18),C=t(16),v=[],P=function(e){function r(){return e.apply(this,arguments)||this}return h(r,e),r.prototype.generateKey=function(r,t,o){var a,s=arguments;return e.prototype.generateKey.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r);try{return y.nativeSubtle.generateKey.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,o),n(a,e),e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.EcDSA.toLowerCase():case p.AlgorithmNames.EcDH.toLowerCase():r=C.EcCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"generateKey")}return r.generateKey(a,t,o)})},r.prototype.digest=function(r,t){var o,n,a=arguments;return e.prototype.digest.apply(this,a).then(function(e){o=m.PrepareAlgorithm(r),n=m.PrepareData(t,"data");try{return y.nativeSubtle.digest.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")}}).then(function(e){return e?e:g.ShaCrypto.digest(o,n)})},r.prototype.sign=function(r,t,n){var i,s,c=arguments;return e.prototype.sign.apply(this,c).then(function(e){i=m.PrepareAlgorithm(r),s=m.PrepareData(n,"data");var o=a(t);o&&(c[0]=A.assign(i,o));try{return y.nativeSubtle.sign.apply(y.nativeSubtle,c).catch(function(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(i.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"sign")}return o(t,r).then(function(e){return r.sign(i,e,s)})})},r.prototype.verify=function(r,t,n,i){var s,c,h,u=arguments;return e.prototype.verify.apply(this,u).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareData(n,"data"),h=m.PrepareData(i,"data");var o=a(t);o&&(u[0]=A.assign(s,o));try{return y.nativeSubtle.verify.apply(y.nativeSubtle,u).catch(function(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if("boolean"==typeof e)return e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"sign")}return o(t,r).then(function(e){return r.verify(s,e,c,h)})})},r.prototype.deriveBits=function(r,t,o){var n,a=arguments;return e.prototype.deriveBits.apply(this,a).then(function(e){n=m.PrepareAlgorithm(r);try{return y.nativeSubtle.deriveBits.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(n.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=C.EcCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveBits(n,t,o)})},r.prototype.deriveKey=function(r,t,o,n,a){var s,c,h=arguments;return e.prototype.deriveKey.apply(this,h).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareAlgorithm(o);try{return y.nativeSubtle.deriveKey.apply(y.nativeSubtle,h).catch(function(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,a),e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=C.EcCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveKey(s,t,c,n,a)})},r.prototype.encrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.encrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");try{return y.nativeSubtle.encrypt.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){if(A.BrowserInfo().name===A.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM&&e.ciphertext){var r=new Uint8Array(e.ciphertext.byteLength+e.tag.byteLength),n=0;new Uint8Array(e.ciphertext).forEach(function(e){return r[n++]=e}),new Uint8Array(e.tag).forEach(function(e){return r[n++]=e}),e=r.buffer}return Promise.resolve(e)}var s;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():s=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():s=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,s).then(function(e){return s.encrypt(a,e,i)})})},r.prototype.decrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.decrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");var o=i;if(A.BrowserInfo().name===A.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM){var s=i.byteLength-a.tagLength/8;o={ciphertext:i.buffer.slice(0,s),tag:i.buffer.slice(s,i.byteLength)}}try{return y.nativeSubtle.decrypt.call(y.nativeSubtle,a,t,o).catch(function(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,r).then(function(e){return r.decrypt(a,e,i)})})},r.prototype.wrapKey=function(r,t,o,n){var a,i=arguments;return e.prototype.wrapKey.apply(this,i).then(function(e){a=m.PrepareAlgorithm(n);try{return y.nativeSubtle.wrapKey.apply(y.nativeSubtle,i).catch(function(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var n;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():n=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"wrapKey")}return n.wrapKey(r,t,o,a)})},r.prototype.unwrapKey=function(r,t,o,n,a,s,c){var h,u,l,A=arguments;return e.prototype.unwrapKey.apply(this,A).then(function(e){h=m.PrepareAlgorithm(n),u=m.PrepareAlgorithm(a),l=m.PrepareData(t,"wrappedKey");try{return y.nativeSubtle.unwrapKey.apply(y.nativeSubtle,A).catch(function(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,c),e;var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():t=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"unwrapKey")}return t.unwrapKey(r,l,o,h,u,s,c)})},r.prototype.exportKey=function(r,t){var o=arguments;return e.prototype.exportKey.apply(this,o).then(function(){try{return y.nativeSubtle.exportKey.apply(y.nativeSubtle,o).catch(function(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){"jwk"===r&&e instanceof ArrayBuffer&&(e=A.buffer2string(new Uint8Array(e)),e=JSON.parse(e));var o=a(t);return o||(o=A.assign({},t.algorithm)),s(e,o,t.usages),Promise.resolve(e)}if(!t.key)throw new f.LinerError("Cannot export native CryptoKey from JS implementation");var n;switch(t.algorithm.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():n=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():n=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"exportKey")}return n.exportKey(r,t)})},r.prototype.importKey=function(r,t,o,a,s){var h,u,l=arguments;return e.prototype.importKey.apply(this,l).then(function(e){h=m.PrepareAlgorithm(o),u=t,A.BrowserInfo().name!==A.Browser.Safari&&A.BrowserInfo().name!==A.Browser.IE||(A.BrowserInfo().name===A.Browser.IE&&(t=A.assign({},t),c(t)),l[1]=A.string2buffer(JSON.stringify(t)).buffer),ArrayBuffer.isView(t)&&(u=m.PrepareData(t,"keyData"));try{return y.nativeSubtle.importKey.apply(y.nativeSubtle,l).catch(function(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return n(h,e),i(e,s),Promise.resolve(e);var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():t=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():t=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"importKey")}return t.importKey(r,u,h,a,s)})},r}(u.SubtleCrypto);r.SubtleCrypto=P,Uint8Array.prototype.forEach||(Uint8Array.prototype.forEach=function(e){for(var r=0;r<this.length;r++)e(this[r],r,this)}),Uint8Array.prototype.slice||(Uint8Array.prototype.slice=function(e,r){return new Uint8Array(this.buffer.slice(e,r))}),Uint8Array.prototype.filter||(Uint8Array.prototype.filter=function(e){for(var r=[],t=0;t<this.length;t++)e(this[t],t,this)&&r.push(this[t]);return new Uint8Array(r)})},function(e,r){(function(e){"use strict";if("undefined"==typeof self){var t=e;t.btoa=function(e){return new Buffer(e,"binary").toString("base64")},t.atob=function(e){return new Buffer(e,"base64").toString("binary")}}var o=function(){function e(){}return e.buffer2string=function(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r},e.string2buffer=function(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r},e.encode=function(e){var r=this.buffer2string(e),t=btoa(r).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");return t},e.decode=function(e){for(;e.length%4;)e+="=";var r=e.replace(/\-/g,"+").replace(/_/g,"/");return this.string2buffer(atob(r))},e}();r.Base64Url=o}).call(r,function(){return this}())},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(1),s=t(3),c=t(7),h=t(10),p=t(13),u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkDeriveParams=function(e){if(this.checkAlgorithm(e),!e.salt)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"salt");if(!(ArrayBuffer.isView(e.salt)||e.salt instanceof ArrayBuffer))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_TYPE,"salt","ArrayBuffer or ArrayBufferView");if(!e.iterations)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"iterations");if(!e.hash)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"hash");var r=a.PrepareAlgorithm(e.hash);c.Sha.checkAlgorithm(r)},r.importKey=function(e,r,t,o,a){var i=this;return Promise.resolve().then(function(){if(o)throw new n.WebCryptoError("KDF keys must set extractable=false");if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'raw'");i.checkKeyUsages(a)})},r.deriveKey=function(e,r,t,o,a){var c=this;return Promise.resolve().then(function(){switch(c.checkDeriveParams(e),c.checkKey(r,c.ALG_NAME,"secret","deriveKey"),i.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case s.AlgorithmNames.AesCBC:h.AesCBC.checkKeyGenParams(t),h.AesCBC.checkKeyUsages(a);break;case s.AlgorithmNames.AesCTR:h.AesCTR.checkKeyGenParams(t),h.AesCTR.checkKeyUsages(a);break;case s.AlgorithmNames.AesGCM:h.AesGCM.checkKeyGenParams(t),h.AesGCM.checkKeyUsages(a);break;case s.AlgorithmNames.AesKW:h.AesKW.checkKeyGenParams(t),h.AesKW.checkKeyUsages(a);break;case s.AlgorithmNames.Hmac:p.Hmac.checkKeyGenParams(t),p.Hmac.checkKeyUsages(a);break;default:throw new n.AlgorithmError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,t)}})},r.deriveBits=function(e,r,t){var o=this;return Promise.resolve().then(function(){if(o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"secret","deriveBits"),!t||"number"!=typeof t)throw new n.WebCryptoError("Parameter 'length' must be Number and more than 0")})},r}(i.BaseCrypto);u.ALG_NAME=s.AlgorithmNames.Pbkdf2,u.KEY_USAGES=["deriveKey","deriveBits"],r.Pbkdf2=u},function(e,r,t){"use strict";var o=t(2),n=t(1),a=t(3),i=t(7),s=t(14),c=t(10),h=t(12),p=t(13),u=t(22),m=function(){function e(){}return e.prototype.generateKey=function(e,r,t){return new Promise(function(i,u){var m=n.PrepareAlgorithm(e),y=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():y=s.RsaOAEP;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.AesCBC.toUpperCase():y=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():y=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():y=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():y=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():y=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}y.generateKey(m,r,t).then(i,u)})},e.prototype.digest=function(e,r){return new Promise(function(t,s){var c=n.PrepareAlgorithm(e),h=n.PrepareData(r,"data"),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.Sha1.toUpperCase():case a.AlgorithmNames.Sha256.toUpperCase():case a.AlgorithmNames.Sha384.toUpperCase():case a.AlgorithmNames.Sha512.toUpperCase():p=i.Sha;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.digest(c,h).then(t,s)})},e.prototype.sign=function(e,r,t){return new Promise(function(i,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(t,"data"),y=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}y.sign(u,r,m).then(i,c)})},e.prototype.verify=function(e,r,t,i){return new Promise(function(t,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(i,"signature"),y=n.PrepareData(i,"data"),f=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():f=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():f=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():f=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():f=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}f.verify(u,r,m,y).then(t,c)})},e.prototype.encrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.encrypt(p,r,u).then(i,h)})},e.prototype.decrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.decrypt(p,r,u).then(i,h)})},e.prototype.deriveBits=function(e,r,t){return new Promise(function(i,s){var c=n.PrepareAlgorithm(e),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():p=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():p=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.deriveBits(c,r,t).then(i,s)})},e.prototype.deriveKey=function(e,r,t,i,s){return new Promise(function(c,p){var m=n.PrepareAlgorithm(e),y=n.PrepareAlgorithm(t),f=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():f=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():f=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}f.deriveKey(m,r,y,i,s).then(c,p)})},e.prototype.exportKey=function(e,r){return new Promise(function(t,i){if(n.BaseCrypto.checkKey(r),!r.extractable)throw new o.CryptoKeyError(o.CryptoKeyError.NOT_EXTRACTABLE);var u=n.BaseCrypto;switch(r.algorithm.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():u=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():u=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():u=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():u=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():u=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():u=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():u=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():u=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():u=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():u=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}u.exportKey(e,r).then(t,i)})},e.prototype.importKey=function(e,r,t,i,m){return new Promise(function(y,f){var l=n.PrepareAlgorithm(t),A=n.BaseCrypto;switch(l.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():A=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():A=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():A=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():A=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():A=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():A=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():A=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():A=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():A=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():A=p.Hmac;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():A=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,l.name)}A.importKey(e,r,l,i,m).then(y,f)})},e.prototype.wrapKey=function(e,r,t,i){return new Promise(function(h,p){var u=n.PrepareAlgorithm(i),m=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():m=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}m.wrapKey(e,r,t,u).then(h,p)})},e.prototype.unwrapKey=function(e,r,t,i,h,p,u){return new Promise(function(m,y){var f=n.PrepareAlgorithm(i),l=n.PrepareAlgorithm(h),A=n.PrepareData(r,"wrappedKey"),w=n.BaseCrypto;switch(f.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():w=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():w=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():w=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():w=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():w=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,f.name)}w.unwrapKey(e,A,t,f,l,p,u).then(m,y)})},e}();r.SubtleCrypto=m},function(e,r){e.exports=require("crypto")}]);
var liner=function(e){function r(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,r),n.loaded=!0,n.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";var o=t(17);Object.freeze(Math),Object.freeze(Math.random),Object.freeze(Math.imul),o.nativeCrypto&&Object.freeze(o.nativeCrypto.getRandomValues),r.crypto=new o.Crypto},function(e,r,t){"use strict";function o(e){var r;r="string"==typeof e?{name:e}:e,i.checkAlgorithm(r);var t=e;return t.hash&&(t.hash=o(t.hash)),r}function n(e,r){if(!e)throw new a.WebCryptoError("Parameter '"+r+"' is required and cant be empty");if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer);if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new a.WebCryptoError("Incoming parameter '"+r+"' has wrong data type. Must be ArrayBufferView or ArrayBuffer")}var a=t(2);r.PrepareAlgorithm=o,r.PrepareData=n;var i=function(){function e(){}return e.checkAlgorithm=function(e){if("object"!=typeof e)throw new TypeError("Wrong algorithm data type. Must be Object");if(!("name"in e))throw new a.AlgorithmError(a.AlgorithmError.PARAM_REQUIRED,"name")},e.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},e.checkKey=function(e,r,t,o){if(void 0===t&&(t=null),void 0===o&&(o=null),!e)throw new a.CryptoKeyError(a.CryptoKeyError.EMPTY_KEY);var n=e.algorithm;if(this.checkAlgorithm(n),r&&n.name.toUpperCase()!==r.toUpperCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_ALG,n.name,r);if(t&&(!e.type||e.type.toUpperCase()!==t.toUpperCase()))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_TYPE,e.type,t);if(o&&!e.usages.some(function(e){return o.toUpperCase()===e.toUpperCase()}))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_USAGE,o)},e.checkWrappedKey=function(e){if(!e.extractable)throw new a.CryptoKeyError(a.CryptoKeyError.NOT_EXTRACTABLE)},e.checkKeyUsages=function(e){if(!e||!e.length)throw new a.WebCryptoError("Parameter 'keyUsages' cannot be empty.")},e.checkFormat=function(e,r){switch(e.toLowerCase()){case"raw":if(r&&"secret"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"raw");break;case"pkcs8":if(r&&"private"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"pkcs8");break;case"spki":if(r&&"public"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"spki");break;case"jwk":break;default:throw new a.CryptoKeyError(a.CryptoKeyError.UNKNOWN_FORMAT,e)}},e.generateKey=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.digest=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.sign=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.verify=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.encrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.decrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveBits=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.exportKey=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.importKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.wrapKey=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.unwrapKey=function(e,r,t,o,n,i,s){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e}();r.BaseCrypto=i},function(e,r){"use strict";function t(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o,n=e,a=/[^%](%\d+)/g,i=[];o=a.exec(n);)i.push({arg:o[1],index:o.index});for(var s=i.length-1;s>=0;s--){var c=i[s],h=c.arg.substring(1),p=c.index+1;n=n.substring(0,p)+arguments[+h]+n.substring(p+1+h.length)}return n=n.replace("%%","%")}var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=function(e){function r(r){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];var a=e.call(this)||this;a.code=0,a.message=t.apply(void 0,[r].concat(o));var i=new Error(a.message);return i.name=a.constructor.name,a.stack=i.stack,a}return o(r,e),r}(Error);n.NOT_SUPPORTED="Method is not supported",r.WebCryptoError=n;var a=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=1,r}return o(r,e),r}(n);a.PARAM_REQUIRED="Algorithm hasn't got required paramter '%1'",a.PARAM_WRONG_TYPE="Algorithm has got wrong type for paramter '%1'. Must be %2",a.PARAM_WRONG_VALUE="Algorithm has got wrong value for paramter '%1'. Must be %2",a.WRONG_ALG_NAME="Algorithm has got wrong name '%1'. Must be '%2'",a.UNSUPPORTED_ALGORITHM="Algorithm '%1' is not supported",a.WRONG_USAGE="Algorithm doesn't support key usage '%1'",r.AlgorithmError=a;var i=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=3,r}return o(r,e),r}(n);i.EMPTY_KEY="CryptoKey is empty",i.WRONG_KEY_ALG="CryptoKey has wrong algorithm '%1'. Must be '%2'",i.WRONG_KEY_TYPE="CryptoKey has wrong type '%1'. Must be '%2'",i.WRONG_KEY_USAGE="CryptoKey has wrong key usage. Must be '%1'",i.NOT_EXTRACTABLE="CryptoKey is not extractable",i.WRONG_FORMAT="CryptoKey has '%1' type. It can be used with '%2' format",i.UNKNOWN_FORMAT="Uknown format in use '%1'. Must be one of 'raw', 'pkcs8', 'spki' or 'jwk'",i.ALLOWED_FORMAT="Wrong format value '%1'. Must be %2",r.CryptoKeyError=i},function(e,r){"use strict";r.AlgorithmNames={RsaSSA:"RSASSA-PKCS1-v1_5",RsaPSS:"RSA-PSS",RsaOAEP:"RSA-OAEP",AesCTR:"AES-CTR",AesCMAC:"AES-CMAC",AesGCM:"AES-GCM",AesCBC:"AES-CBC",AesKW:"AES-KW",Sha1:"SHA-1",Sha256:"SHA-256",Sha384:"SHA-384",Sha512:"SHA-512",EcDSA:"ECDSA",EcDH:"ECDH",Hmac:"HMAC",Pbkdf2:"PBKDF2"}},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(2)),o(t(1)),o(t(3)),o(t(21)),o(t(23)),o(t(10)),o(t(14)),o(t(12)),o(t(7))},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=function(e){function r(){var r=null!==e&&e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(n.WebCryptoError);a.MODULE_NOT_FOUND="Module '%1' is not found. Download it from %2",a.UNSUPPORTED_ALGORITHM="Unsupported algorithm '%1'",r.LinerError=a},function(e,r,t){"use strict";var o=t(20),n=t(9),a=function(){function e(){this.subtle=new o.SubtleCrypto}return e.prototype.getRandomValues=function(e){return n.nativeCrypto.getRandomValues(e)},e}();r.Crypto=a},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(3),a=t(1),i=t(2);r.ShaAlgorithms=[n.AlgorithmNames.Sha1,n.AlgorithmNames.Sha256,n.AlgorithmNames.Sha384,n.AlgorithmNames.Sha512].join(" | ");var s=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.checkAlgorithm=function(t){var o;switch(o="string"==typeof t?{name:t}:t,e.checkAlgorithm.call(this,o),o.name.toUpperCase()){case n.AlgorithmNames.Sha1:case n.AlgorithmNames.Sha256:case n.AlgorithmNames.Sha384:case n.AlgorithmNames.Sha512:break;default:throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,o.name,r.ShaAlgorithms)}},t.digest=function(e,r){var t=this;return new Promise(function(r,o){t.checkAlgorithm(e),r(void 0)})},t}(a.BaseCrypto);r.Sha=s},function(e,r){"use strict";function t(){var e,t={name:"",version:""},o=self.navigator.userAgent;return(e=/edge\/([\d\.]+)/i.exec(o))?(t.name=r.Browser.Edge,t.version=e[1]):/msie/i.test(o)?(t.name=r.Browser.IE,t.version=/msie ([\d\.]+)/i.exec(o)[1]):/Trident/i.test(o)?(t.name=r.Browser.IE,t.version=/rv:([\d\.]+)/i.exec(o)[1]):/chrome/i.test(o)?(t.name=r.Browser.Chrome,t.version=/chrome\/([\d\.]+)/i.exec(o)[1]):/safari/i.test(o)?(t.name=r.Browser.Safari,t.version=/([\d\.]+) safari/i.exec(o)[1]):/firefox/i.test(o)&&(t.name=r.Browser.Firefox,t.version=/firefox\/([\d\.]+)/i.exec(o)[1]),t}function o(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}function n(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r}function a(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=new Uint8Array(e.map(function(e){return e.length}).reduce(function(e,r){return e+r})),o=0;return e.forEach(function(e,r){for(var n=0;n<e.length;n++)t[o+n]=e[n];o+=e.length}),t}function i(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o=arguments[0],n=1;n<arguments.length;n++){var a=arguments[n];for(var i in a)o[i]=a[i]}return o}r.Browser={IE:"Internet Explorer",Safari:"Safari",Edge:"Edge",Chrome:"Chrome",Firefox:"Firefox Mozilla"},r.BrowserInfo=t,r.string2buffer=o,r.buffer2string=n,r.concat=a,r.assign=i},function(e,r,t){"use strict";function o(e,r){var t=e[r];e[r]=function(){var o=arguments;return new Promise(function(n,a){var i=t.apply(e,o);i.oncomplete=function(e){console.log("Completed"),n(e.target.result)},i.onerror=function(e){console.log("Error"),a("Error on running '"+r+"' function")}})}}var n,a=t(5);if("undefined"==typeof self){var i=t(24);n={crypto:{subtle:{},getRandomValues:function(e){var r=e.buffer,t=new Uint8Array(r),o=i.randomBytes(t.length);return o.forEach(function(e,r){return t[r]=e}),e}}}}else n=self;if(r.nativeCrypto=n.msCrypto||n.crypto,r.nativeSubtle=r.nativeCrypto.subtle||r.nativeCrypto.webkitSubtle,n.msCrypto){if(!n.Promise)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"Promise","https://www.promisejs.org");o(r.nativeSubtle,"generateKey"),o(r.nativeSubtle,"digest"),o(r.nativeSubtle,"sign"),o(r.nativeSubtle,"verify"),o(r.nativeSubtle,"encrypt"),o(r.nativeSubtle,"decrypt"),o(r.nativeSubtle,"importKey"),o(r.nativeSubtle,"exportKey"),o(r.nativeSubtle,"wrapKey"),o(r.nativeSubtle,"unwrapKey"),o(r.nativeSubtle,"deriveKey"),o(r.nativeSubtle,"deriveBits")}Math.imul||(Math.imul=function(e,r){var t=e>>>16&65535,o=65535&e,n=r>>>16&65535,a=65535&r;return o*a+(t*a+o*n<<16>>>0)|0})},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=7,r}return o(r,e),r}(n.AlgorithmError),c=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkKeyUsages=function(r){var t=this;e.checkKeyUsages.call(this,r);var o=r.filter(function(e){return t.KEY_USAGES.indexOf(e)===-1});if(o.length)throw new n.AlgorithmError(n.AlgorithmError.WRONG_USAGE,o.join(", "))},r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){switch(e.length){case 128:case 192:case 256:break;default:throw new s(s.PARAM_WRONG_VALUE,"length","128, 192 or 256")}},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);c.ALG_NAME="",c.KEY_USAGES=[],r.Aes=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=8,r}return o(r,e),r}(n.AlgorithmError);r.AesAlgorithmError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"secret","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"secret","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(c);r.AesWrapKey=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","decrypt"),t(void 0)})},r}(p);u.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.AesEncrypt=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(16!==e.iv.byteLength)throw new h(h.PARAM_WRONG_VALUE,"iv","ArrayBufferView with size 16")},r}(u);m.ALG_NAME=i.AlgorithmNames.AesCBC,r.AesCBC=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.counter||!ArrayBuffer.isView(e.counter))throw new h(h.PARAM_WRONG_TYPE,"counter","ArrayBufferView");if(16!==e.counter.byteLength)throw new h(h.PARAM_WRONG_VALUE,"counter","ArrayBufferView with size 16");if(!(e.length>0&&e.length<=128))throw new h(h.PARAM_WRONG_VALUE,"length","number [1-128]")},r}(u);y.ALG_NAME=i.AlgorithmNames.AesCTR,r.AesCTR=y;var A=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),e.additionalData&&!ArrayBuffer.isView(e.additionalData))throw new h(h.PARAM_WRONG_TYPE,"additionalData","ArrayBufferView");if(!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(e.tagLength&&!(e.tagLength>=0&&e.tagLength<=128))throw new h(h.PARAM_WRONG_VALUE,"tagLength","number [0-128]")},r}(u);A.ALG_NAME=i.AlgorithmNames.AesGCM,r.AesGCM=A;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},r}(p);l.ALG_NAME=i.AlgorithmNames.AesKW,l.KEY_USAGES=["wrapKey","unwrapKey"],r.AesKW=l},function(e,r){"use strict";var t=function(){function e(){}return e}();r.CryptoKey=t},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(10),a=t(7),i=t(2),s=t(1),c=t(3),h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=9,r}return o(r,e),r}(i.AlgorithmError);r.EcKeyGenParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){var r="namedCurve";if(!e.namedCurve)throw new h(h.PARAM_REQUIRED,r);if("string"!=typeof e.namedCurve)throw new h(h.PARAM_WRONG_TYPE,r,"string");switch(e.namedCurve.toUpperCase()){case"P-256":case"P-384":case"P-521":break;default:throw new h(h.PARAM_WRONG_VALUE,r,"P-256, P-384 or P-521")}},r.checkKeyGenUsages=function(e){var r=this;e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new i.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,n){var a=this;return new Promise(function(r,o){if(a.checkKeyGenParams(t),a.checkFormat(e),"raw"===e.toLowerCase())throw new i.CryptoKeyError(i.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");a.checkKeyGenUsages(n),r(void 0)})},r}(s.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Ec=p;var u=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(i.AlgorithmError);r.EcAlgorithmError=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e),a.Sha.checkAlgorithm(e.hash)},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);m.ALG_NAME=c.AlgorithmNames.EcDSA,m.KEY_USAGES=["sign","verify","deriveKey","deriveBits"],r.EcDSA=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkDeriveParams=function(e){var r="public";if(this.checkAlgorithm(e),!e.public)throw new u(u.PARAM_REQUIRED,r);this.checkKey(e.public,this.ALG_NAME,"public")},r.deriveBits=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"private","deriveBits"),t(void 0)})},r.deriveKey=function(e,r,t,o,a){var i=this;return new Promise(function(o,a){switch(i.checkDeriveParams(e),i.checkKey(r,i.ALG_NAME,"private","deriveKey"),s.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case c.AlgorithmNames.AesCBC:n.AesCBC.checkKeyGenParams(t);break;case c.AlgorithmNames.AesCTR:n.AesCTR.checkKeyGenParams(t);break;case c.AlgorithmNames.AesGCM:n.AesGCM.checkKeyGenParams(t);break;case c.AlgorithmNames.AesKW:n.AesKW.checkKeyGenParams(t);break;default:throw new u("Unsupported name '"+t.name+"' for algorithm in param 'derivedKeyType'")}o(void 0)})},r}(p);y.ALG_NAME=c.AlgorithmNames.EcDH,y.KEY_USAGES=["deriveKey","deriveBits"],r.EcDH=y},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){if("length"in e&&!(e.length>0&&e.length<=512))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_VALUE,"length","more 0 and less than 512")},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"secret","verify"),t(void 0)})},r}(a.BaseCrypto);s.ALG_NAME=i.AlgorithmNames.Hmac,s.KEY_USAGES=["sign","verify"],r.Hmac=s},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=t(7),c=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=2,r}return o(r,e),r}(n.AlgorithmError);r.RsaKeyGenParamsError=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=6,r}return o(r,e),r}(n.AlgorithmError);r.RsaHashedImportParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkImportAlgorithm=function(e){if(this.checkAlgorithm(e),!e.hash)throw new h(h.PARAM_REQUIRED,"hash");s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenParams=function(e){switch(e.modulusLength){case 1024:case 2048:case 4096:break;default:throw new c(c.PARAM_WRONG_VALUE,"modulusLength","1024, 2048 or 4096")}var r=e.publicExponent;if(!r)throw new c(c.PARAM_REQUIRED,"publicExponent");if(!ArrayBuffer.isView(r))throw new c(c.PARAM_WRONG_TYPE,"publicExponent","ArrayBufferView");if(3!==r[0]&&(1!==r[0]||0!==r[1]||1!==r[2]))throw new c(c.PARAM_WRONG_VALUE,"publicExponent","Uint8Array([3]) | Uint8Array([1, 0, 1])");if(!e.hash)throw new c(c.PARAM_REQUIRED,"hash",s.ShaAlgorithms);s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkImportAlgorithm(t),i.checkFormat(e),"raw"===e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Rsa=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);u.ALG_NAME=i.AlgorithmNames.RsaSSA,u.KEY_USAGES=["sign","verify"],r.RsaSSA=u;var m=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=4,r}return o(r,e),r}(n.AlgorithmError);r.RsaPSSParamsError=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkRsaPssParams=function(r){return e.checkAlgorithmParams.call(this,r),r.saltLength?r.saltLength%8?new m("Parameter 'saltLength' should be a multiple of 8"):void 0:new m(m.PARAM_REQUIRED,"saltLength")},r}(u);y.ALG_NAME=i.AlgorithmNames.RsaPSS,y.KEY_USAGES=["sign","verify"],r.RsaPSS=y;var A=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=5,r}return o(r,e),r}(n.AlgorithmError);r.RsaOAEPParamsError=A;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(e.label&&!ArrayBuffer.isView(e.label))return new A(A.PARAM_WRONG_TYPE,"label","ArrayBufferView")},r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"public","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","decrypt"),t(void 0)})},r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"public","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"private","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(p);l.ALG_NAME=i.AlgorithmNames.RsaOAEP,l.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.RsaOAEP=l},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=t(11),s=t(8),c=t(9),h=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return o(r,e),r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=c.nativeCrypto.getRandomValues(new Uint8Array(e.length/8)),a=new i.CryptoKey;return a.key=n,a.algorithm=e,a.extractable=r,a.type="secret",a.usages=t,a})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.encrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.encrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.decrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.decrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):s.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var c;return Promise.resolve().then(function(){return c=new p.Crypto,c.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(s.buffer2string(new Uint8Array(r))):new Uint8Array(r),c.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){return"A"+e.length+/-(\w+)/i.exec(e.name.toUpperCase())[1]},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){var o=r.key;if("jwk"===e.toLowerCase()){var a={alg:t.alg2jwk(r.algorithm),ext:r.extractable,k:n.Base64Url.encode(o),key_ops:r.usages,kty:"oct"};return a}return o.buffer})},r.importKey=function(e,r,t,o,a){return Promise.resolve().then(function(){var o;if("jwk"===e.toLowerCase()){var s=r;o=n.Base64Url.decode(s.k)}else o=new Uint8Array(r);var c=new i.CryptoKey;return c.algorithm=t,c.type="secret",c.usages=a,c.key=o,c})},r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r}(n.BaseCrypto);r.AesCrypto=h;var p=t(6)},function(e,r,t){"use strict";function o(e){for(var r=new Uint8Array(e),t=[],o=0;o<r.length;o++)t.push(r[o]);return t}function n(e,r){e.length%2&&(e="0"+e);for(var t=new Uint8Array(e.length/2),o=0;o<e.length;o++){var n=e.slice(o,++o+1);t[(o-1)/2]=parseInt(n,16)}if(r){var a=t.length;a=a>32?a>48?66:48:32,t.length<a&&(t=p.concat(new Uint8Array(a-t.length),t))}return t}function a(e,r){for(var t="",o=0;o<e.length;o++){var n=e[o].toString(16);t+=n.length%2?"0"+n:n}if(r){var a=e.length;a=a>32?a>48?66:48:32,t.length/2<a&&(t=new Array(2*a-t.length+1).join("0")+t)}return t}var i=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},s=t(4),c=t(5),h=t(11),p=t(8),u=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return i(r,e),r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var t=e,n=new elliptic.ec(t.namedCurve.replace("-","").toLowerCase()),a=new h.CryptoKey,i=new h.CryptoKey;return a.key=i.key=n.genKeyPair(),a.algorithm=i.algorithm=t,a.extractable=r,i.extractable=!0,a.type="private",i.type="public",e.name===s.AlgorithmNames.EcDSA?(a.usages=["sign"],i.usages=["verify"]):e.name===s.AlgorithmNames.EcDH&&(a.usages=["deriveKey","deriveBits"],i.usages=[]),{privateKey:a,publicKey:i}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){var r=e,o=new m.Crypto;return o.subtle.digest(r.hash,t)}).then(function(e){var t=o(e),i=r.key.sign(t),s=a(i.r.toArray(),!0)+a(i.s.toArray(),!0);return n(s).buffer})},r.verify=function(e,r,t,n){var a;return Promise.resolve().then(function(){var r=e;a={r:t.slice(0,t.byteLength/2),s:t.slice(t.byteLength/2)};var o=new m.Crypto;return o.subtle.digest(r.hash,n)}).then(function(e){var t=o(e);return r.key.verify(t,a)})},r.deriveKey=function(e,r,t,o,n){var a=this;return Promise.resolve().then(function(){return a.deriveBits(e,r,t.length)}).then(function(e){var r=new m.Crypto;return r.subtle.importKey("raw",new Uint8Array(e),t,o,n)})},r.deriveBits=function(e,r,t){return Promise.resolve().then(function(){var o=(Promise.resolve(null),r.key.derive(e.public.key.getPublic())),n=new Uint8Array(o.toArray()),a=n.length;a=a>32?a>48?66:48:32,n.length<a&&(n=p.concat(new Uint8Array(a-n.length),n));var i=n.slice(0,t/8).buffer;return i})},r.exportKey=function(e,r){return Promise.resolve().then(function(){var t=r.key;if("jwk"===e.toLowerCase()){var o=t.getPublic("hex").slice(2),a=o.slice(0,o.length/2),i=o.slice(o.length/2,o.length);if("public"===r.type){var h={crv:r.algorithm.namedCurve,ext:r.extractable,x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}var h={crv:r.algorithm.namedCurve,ext:r.extractable,d:s.Base64Url.encode(n(t.getPrivate("hex"),!0)),x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}throw new c.LinerError("Format '"+e+"' is not implemented")})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var i=new h.CryptoKey;if(i.algorithm=t,"jwk"!==e.toLowerCase())throw new c.LinerError("Format '"+e+"' is not implemented");var u=new elliptic.ec(r.crv.replace("-","").toLowerCase());if(r.d)i.key=u.keyFromPrivate(s.Base64Url.decode(r.d)),i.type="private";else{var m=p.concat(new Uint8Array([4]),s.Base64Url.decode(r.x),s.Base64Url.decode(r.y)),y=a(m);i.key=u.keyFromPublic(y,"hex"),i.type="public"}
return i.extractable=o,i.usages=n,i})},r.checkModule=function(){if("undefined"==typeof elliptic)throw new c.LinerError(c.LinerError.MODULE_NOT_FOUND,"elliptic","https://github.com/indutny/elliptic")},r}(s.BaseCrypto);r.EcCrypto=u;var m=t(6)},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(9)),o(t(6))},function(e,r,t){"use strict";function o(e){var r=!0;return e.filter(function(e){return(!r||0!==e)&&(r=!1,!0)})}var n=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},a=t(4),i=t(5),s=t(8),c=t(11),h=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return n(r,e),r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=3===e.publicExponent[0]?3:65537,s=asmCrypto.RSA.generateKey(e.modulusLength,n),h=new c.CryptoKey,p=new c.CryptoKey;switch(h.key=p.key=s,h.algorithm=p.algorithm=e,h.extractable=r,p.extractable=!0,h.type="private",p.type="public",e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():h.usages=o.filterUsages(["decrypt","unwrapKey"],t),p.usages=o.filterUsages(["encrypt","wrapKey"],t);break;case a.AlgorithmNames.RsaSSA.toLowerCase():case a.AlgorithmNames.RsaPSS.toLowerCase():h.usages=o.filterUsages(["sign"],t),p.usages=o.filterUsages(["verify"],t);break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}return{privateKey:h,publicKey:p}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaSSA.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_PKCS1_v1_5_SHA1.sign;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_PKCS1_v1_5_SHA256.sign;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return s(t,r.key).buffer;case a.AlgorithmNames.RsaPSS.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_PSS_SHA1.sign;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_PSS_SHA256.sign;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return s(t,r.key,n.saltLength).buffer;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.verify=function(e,r,t,o){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaSSA.toLowerCase():var n,s=r.algorithm;switch(s.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:n=asmCrypto.RSA_PKCS1_v1_5_SHA1.verify;break;case a.AlgorithmNames.Sha256:n=asmCrypto.RSA_PKCS1_v1_5_SHA256.verify;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return n(t,o,r.key);case a.AlgorithmNames.RsaPSS.toLowerCase():var c=r.algorithm,h=e,p=void 0;switch(c.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:p=asmCrypto.RSA_PSS_SHA1.verify;break;case a.AlgorithmNames.Sha256:p=asmCrypto.RSA_PSS_SHA256.verify;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return p(t,o,r.key,h.saltLength);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.encrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.encrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.decrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.decrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):s.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var c;return Promise.resolve().then(function(){return c=new p.Crypto,c.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(s.buffer2string(new Uint8Array(r))):new Uint8Array(r),c.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){var r=e.hash,t=/(\d+)/.exec(r.name)[1];switch(e.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():return"RSA-OAEP"+("1"===t?"":"-"+t);case a.AlgorithmNames.RsaPSS.toUpperCase():return"PS"+t;case a.AlgorithmNames.RsaSSA.toUpperCase():return"RS"+t;default:throw new a.AlgorithmError(a.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){if("jwk"===e.toLowerCase()){var n={kty:"RSA",ext:!0,key_ops:r.usages};return n.alg=t.alg2jwk(r.algorithm),n.n=a.Base64Url.encode(o(r.key[0])),n.e=a.Base64Url.encode(o(r.key[1])),"private"===r.type&&(n.d=a.Base64Url.encode(o(r.key[2])),n.p=a.Base64Url.encode(o(r.key[3])),n.q=a.Base64Url.encode(o(r.key[4])),n.dp=a.Base64Url.encode(o(r.key[5])),n.dq=a.Base64Url.encode(o(r.key[6])),n.qi=a.Base64Url.encode(o(r.key[7]))),n}throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var o,s=new c.CryptoKey;if(s.algorithm=t,s.usages=n,s.key=[],"jwk"===e.toLowerCase())return o=r,s.key[0]=a.Base64Url.decode(o.n),s.key[1]=3===a.Base64Url.decode(o.e)[0]?new Uint8Array([0,0,0,3]):new Uint8Array([0,1,0,1]),o.d?(s.type="private",s.key[2]=a.Base64Url.decode(o.d),s.key[3]=a.Base64Url.decode(o.p),s.key[4]=a.Base64Url.decode(o.q),s.key[5]=a.Base64Url.decode(o.dp),s.key[6]=a.Base64Url.decode(o.dq),s.key[7]=a.Base64Url.decode(o.qi)):s.type="public",s;throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new i.LinerError(i.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r.filterUsages=function(e,r){return e.filter(function(e){return!!r.filter(function(r){return e===r}).length})},r}(a.BaseCrypto);r.RsaCrypto=h;var p=t(6)},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return o(r,e),r.digest=function(e,r){return Promise.resolve().then(function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js");switch(e.name.toUpperCase()){case n.AlgorithmNames.Sha1:return asmCrypto.SHA1.bytes(r).buffer;case n.AlgorithmNames.Sha256:return asmCrypto.SHA256.bytes(r).buffer;default:throw new a.LinerError("Not supported algorithm '"+e.name+"'")}})},r}(n.BaseCrypto);r.ShaCrypto=i},function(e,r,t){"use strict";function o(e,r){return Promise.resolve().then(function(){if(e.key)return e;if(e.extractable){var t=new A.Crypto;return t.subtle.exportKey("jwk",e).then(function(t){return r.importKey("jwk",t,e.algorithm,!0,e.usages)})}throw new l.LinerError("'key' is Native CryptoKey. It can't be converted to JS CryptoKey")})}function n(e,r){f.BrowserInfo().name!==f.Browser.IE&&f.BrowserInfo().name!==f.Browser.Edge&&f.BrowserInfo().name!==f.Browser.Safari||!/^rsa/i.test(e.name)||(r.privateKey?(v.push({hash:e.hash,key:r.privateKey}),v.push({hash:e.hash,key:r.publicKey})):v.push({hash:e.hash,key:r}))}function a(e){var r=null;return v.some(function(t){return t.key===e&&(r=f.assign({},e.algorithm,{hash:t.hash}),!0)}),r}function i(e,r){var t=[];e.privateKey?(t.push(e.privateKey),t.push(e.publicKey)):t.push(e),t.forEach(function(e){"keyUsage"in e&&(e.usages=e.keyUsage||[],e.usages.length||(["verify","encrypt","wrapKey"].forEach(function(t){r.indexOf(t)>-1&&("public"===e.type||"secret"===e.type)&&e.usages.push(t)}),["sign","decrypt","unwrapKey","deriveKey","deriveBits"].forEach(function(t){r.indexOf(t)>-1&&("private"===e.type||"secret"===e.type)&&e.usages.push(t)})))})}function s(e,r,t){if(r&&f.BrowserInfo().name===f.Browser.IE){"extractable"in e&&(e.ext=e.extractable,delete e.extractable);var o=null;switch(r.name.toUpperCase()){case p.AlgorithmNames.RsaOAEP.toUpperCase():case p.AlgorithmNames.RsaPSS.toUpperCase():case p.AlgorithmNames.RsaSSA.toUpperCase():o=C.RsaCrypto;break;case p.AlgorithmNames.AesCBC.toUpperCase():case p.AlgorithmNames.AesGCM.toUpperCase():o=w.AesCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,r.name.toUpperCase())}o&&!e.alg&&(e.alg=o.alg2jwk(r)),"key_ops"in e||(e.key_ops=t)}}function c(e){f.BrowserInfo().name===f.Browser.IE&&("ext"in e&&(e.extractable=e.ext,delete e.ext),delete e.key_ops,delete e.alg)}var h=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},p=t(4),u=t(4),m=t(4),y=t(9),A=t(6),l=t(5),f=t(8),w=t(15),g=t(19),C=t(18),E=t(16),v=[],P=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return h(r,e),r.prototype.generateKey=function(r,t,o){var a,s=arguments;return e.prototype.generateKey.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r);try{return y.nativeSubtle.generateKey.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,o),n(a,e),e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.EcDSA.toLowerCase():case p.AlgorithmNames.EcDH.toLowerCase():r=E.EcCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaSSA.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,a.name.toLowerCase())}return r.generateKey(a,t,o)})},r.prototype.digest=function(r,t){var o,n,a=arguments;return e.prototype.digest.apply(this,a).then(function(e){o=m.PrepareAlgorithm(r),n=m.PrepareData(t,"data");try{return y.nativeSubtle.digest.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")}}).then(function(e){return e?e:g.ShaCrypto.digest(o,n)})},r.prototype.sign=function(r,t,n){var i,s,c=arguments;return e.prototype.sign.apply(this,c).then(function(e){i=m.PrepareAlgorithm(r),s=m.PrepareData(n,"data");var o=a(t);o&&(c[0]=f.assign(i,o));try{return y.nativeSubtle.sign.apply(y.nativeSubtle,c).catch(function(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(i.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,i.name.toLowerCase())}return o(t,r).then(function(e){return r.sign(i,e,s)})})},r.prototype.verify=function(r,t,n,i){var s,c,h,u=arguments;return e.prototype.verify.apply(this,u).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareData(n,"data"),h=m.PrepareData(i,"data");var o=a(t);o&&(u[0]=f.assign(s,o));try{return y.nativeSubtle.verify.apply(y.nativeSubtle,u).catch(function(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if("boolean"==typeof e)return e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,s.name.toLowerCase())}return o(t,r).then(function(e){return r.verify(s,t,c,h)})})},r.prototype.deriveBits=function(r,t,o){var n,a=arguments;return e.prototype.deriveBits.apply(this,a).then(function(e){n=m.PrepareAlgorithm(r);try{return y.nativeSubtle.deriveBits.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(n.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=E.EcCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveBits(n,t,o)})},r.prototype.deriveKey=function(r,t,o,n,a){var s,c,h=arguments;return e.prototype.deriveKey.apply(this,h).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareAlgorithm(o);try{return y.nativeSubtle.deriveKey.apply(y.nativeSubtle,h).catch(function(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,a),e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=E.EcCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveKey(s,t,c,n,a)})},r.prototype.encrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.encrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");try{return y.nativeSubtle.encrypt.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){if(f.BrowserInfo().name===f.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM&&e.ciphertext){var r=new Uint8Array(e.ciphertext.byteLength+e.tag.byteLength),n=0;new Uint8Array(e.ciphertext).forEach(function(e){return r[n++]=e}),new Uint8Array(e.tag).forEach(function(e){return r[n++]=e}),e=r.buffer}return Promise.resolve(e)}var s;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():s=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():s=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,s).then(function(e){return s.encrypt(a,e,i)})})},r.prototype.decrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.decrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");var o=i;if(f.BrowserInfo().name===f.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM){var s=i.byteLength-a.tagLength/8;o={ciphertext:i.buffer.slice(0,s),tag:i.buffer.slice(s,i.byteLength)}}try{return y.nativeSubtle.decrypt.call(y.nativeSubtle,a,t,o).catch(function(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,r).then(function(e){return r.decrypt(a,e,i)})})},r.prototype.wrapKey=function(r,t,o,n){var a,i=arguments;return e.prototype.wrapKey.apply(this,i).then(function(e){a=m.PrepareAlgorithm(n);try{return y.nativeSubtle.wrapKey.apply(y.nativeSubtle,i).catch(function(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var n;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():n=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"wrapKey")}return n.wrapKey(r,t,o,a)})},r.prototype.unwrapKey=function(r,t,o,n,a,s,c){var h,u,A,f=arguments;return e.prototype.unwrapKey.apply(this,f).then(function(e){h=m.PrepareAlgorithm(n),u=m.PrepareAlgorithm(a),A=m.PrepareData(t,"wrappedKey");try{return y.nativeSubtle.unwrapKey.apply(y.nativeSubtle,f).catch(function(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,c),e;var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():t=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"unwrapKey")}return t.unwrapKey(r,A,o,h,u,s,c)})},r.prototype.exportKey=function(r,t){var o=arguments;return e.prototype.exportKey.apply(this,o).then(function(){try{return y.nativeSubtle.exportKey.apply(y.nativeSubtle,o).catch(function(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){"jwk"===r&&e instanceof ArrayBuffer&&(e=f.buffer2string(new Uint8Array(e)),e=JSON.parse(e));var o=a(t);return o||(o=f.assign({},t.algorithm)),s(e,o,t.usages),Promise.resolve(e)}if(!t.key)throw new l.LinerError("Cannot export native CryptoKey from JS implementation");var n;switch(t.algorithm.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():n=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():n=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,t.algorithm.name.toLowerCase())}return n.exportKey(r,t)})},r.prototype.importKey=function(r,t,o,a,s){var h,u,A=arguments;return e.prototype.importKey.apply(this,A).then(function(e){h=m.PrepareAlgorithm(o),u=t,f.BrowserInfo().name!==f.Browser.Safari&&f.BrowserInfo().name!==f.Browser.IE||(f.BrowserInfo().name===f.Browser.IE&&(t=f.assign({},t),c(t)),A[1]=f.string2buffer(JSON.stringify(t)).buffer),ArrayBuffer.isView(t)&&(u=m.PrepareData(t,"keyData"));try{return y.nativeSubtle.importKey.apply(y.nativeSubtle,A).catch(function(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return n(h,e),i(e,s),Promise.resolve(e);var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():t=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():t=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,h.name.toLowerCase())}return t.importKey(r,u,h,a,s)})},r}(u.SubtleCrypto);r.SubtleCrypto=P,Uint8Array.prototype.forEach||(Uint8Array.prototype.forEach=function(e){for(var r=0;r<this.length;r++)e(this[r],r,this)}),Uint8Array.prototype.slice||(Uint8Array.prototype.slice=function(e,r){return new Uint8Array(this.buffer.slice(e,r))}),Uint8Array.prototype.filter||(Uint8Array.prototype.filter=function(e){for(var r=[],t=0;t<this.length;t++)e(this[t],t,this)&&r.push(this[t]);return new Uint8Array(r)})},function(e,r){(function(e){"use strict";if("undefined"==typeof self){var t=e;t.btoa=function(e){return new Buffer(e,"binary").toString("base64")},t.atob=function(e){return new Buffer(e,"base64").toString("binary")}}var o=function(){function e(){}return e.buffer2string=function(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r},e.string2buffer=function(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r},e.encode=function(e){var r=this.buffer2string(e),t=btoa(r).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");return t},e.decode=function(e){for(;e.length%4;)e+="=";var r=e.replace(/\-/g,"+").replace(/_/g,"/");return this.string2buffer(atob(r))},e}();r.Base64Url=o}).call(r,function(){return this}())},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(1),s=t(3),c=t(7),h=t(10),p=t(13),u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkDeriveParams=function(e){if(this.checkAlgorithm(e),!e.salt)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"salt");if(!(ArrayBuffer.isView(e.salt)||e.salt instanceof ArrayBuffer))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_TYPE,"salt","ArrayBuffer or ArrayBufferView");if(!e.iterations)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"iterations");if(!e.hash)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"hash");var r=a.PrepareAlgorithm(e.hash);c.Sha.checkAlgorithm(r)},r.importKey=function(e,r,t,o,a){var i=this;return Promise.resolve().then(function(){if(o)throw new n.WebCryptoError("KDF keys must set extractable=false");if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'raw'");i.checkKeyUsages(a)})},r.deriveKey=function(e,r,t,o,a){var c=this;return Promise.resolve().then(function(){switch(c.checkDeriveParams(e),c.checkKey(r,c.ALG_NAME,"secret","deriveKey"),i.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case s.AlgorithmNames.AesCBC:h.AesCBC.checkKeyGenParams(t),h.AesCBC.checkKeyUsages(a);break;case s.AlgorithmNames.AesCTR:h.AesCTR.checkKeyGenParams(t),h.AesCTR.checkKeyUsages(a);break;case s.AlgorithmNames.AesGCM:h.AesGCM.checkKeyGenParams(t),h.AesGCM.checkKeyUsages(a);break;case s.AlgorithmNames.AesKW:h.AesKW.checkKeyGenParams(t),h.AesKW.checkKeyUsages(a);break;case s.AlgorithmNames.Hmac:p.Hmac.checkKeyGenParams(t),p.Hmac.checkKeyUsages(a);break;default:throw new n.AlgorithmError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,t)}})},r.deriveBits=function(e,r,t){var o=this;return Promise.resolve().then(function(){if(o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"secret","deriveBits"),!t||"number"!=typeof t)throw new n.WebCryptoError("Parameter 'length' must be Number and more than 0")})},r}(i.BaseCrypto);u.ALG_NAME=s.AlgorithmNames.Pbkdf2,u.KEY_USAGES=["deriveKey","deriveBits"],r.Pbkdf2=u},function(e,r,t){"use strict";var o=t(2),n=t(1),a=t(3),i=t(7),s=t(14),c=t(10),h=t(12),p=t(13),u=t(22),m=function(){function e(){}return e.prototype.generateKey=function(e,r,t){return new Promise(function(i,u){var m=n.PrepareAlgorithm(e),y=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():y=s.RsaOAEP;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.AesCBC.toUpperCase():y=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():y=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():y=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():y=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():y=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}y.generateKey(m,r,t).then(i,u)})},e.prototype.digest=function(e,r){return new Promise(function(t,s){var c=n.PrepareAlgorithm(e),h=n.PrepareData(r,"data"),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.Sha1.toUpperCase():case a.AlgorithmNames.Sha256.toUpperCase():case a.AlgorithmNames.Sha384.toUpperCase():case a.AlgorithmNames.Sha512.toUpperCase():p=i.Sha;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.digest(c,h).then(t,s)})},e.prototype.sign=function(e,r,t){return new Promise(function(i,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(t,"data"),y=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}y.sign(u,r,m).then(i,c)})},e.prototype.verify=function(e,r,t,i){return new Promise(function(t,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(i,"signature"),y=n.PrepareData(i,"data"),A=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():A=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():A=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():A=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():A=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}A.verify(u,r,m,y).then(t,c)})},e.prototype.encrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.encrypt(p,r,u).then(i,h)})},e.prototype.decrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.decrypt(p,r,u).then(i,h)})},e.prototype.deriveBits=function(e,r,t){return new Promise(function(i,s){var c=n.PrepareAlgorithm(e),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():p=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():p=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.deriveBits(c,r,t).then(i,s)})},e.prototype.deriveKey=function(e,r,t,i,s){return new Promise(function(c,p){var m=n.PrepareAlgorithm(e),y=n.PrepareAlgorithm(t),A=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():A=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():A=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}A.deriveKey(m,r,y,i,s).then(c,p)})},e.prototype.exportKey=function(e,r){return new Promise(function(t,i){if(n.BaseCrypto.checkKey(r),!r.extractable)throw new o.CryptoKeyError(o.CryptoKeyError.NOT_EXTRACTABLE);var u=n.BaseCrypto;switch(r.algorithm.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():u=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():u=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():u=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():u=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():u=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():u=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():u=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():u=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():u=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():u=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}u.exportKey(e,r).then(t,i)})},e.prototype.importKey=function(e,r,t,i,m){return new Promise(function(y,A){var l=n.PrepareAlgorithm(t),f=n.BaseCrypto;switch(l.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():f=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():f=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():f=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():f=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():f=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():f=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():f=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():f=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():f=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():f=p.Hmac;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():f=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,l.name)}f.importKey(e,r,l,i,m).then(y,A)})},e.prototype.wrapKey=function(e,r,t,i){return new Promise(function(h,p){var u=n.PrepareAlgorithm(i),m=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():m=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}m.wrapKey(e,r,t,u).then(h,p)})},e.prototype.unwrapKey=function(e,r,t,i,h,p,u){return new Promise(function(m,y){var A=n.PrepareAlgorithm(i),l=n.PrepareAlgorithm(h),f=n.PrepareData(r,"wrappedKey"),w=n.BaseCrypto;switch(A.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():w=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():w=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():w=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():w=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():w=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,A.name)}w.unwrapKey(e,f,t,A,l,p,u).then(m,y)})},e}();r.SubtleCrypto=m},function(e,r){e.exports=require("crypto")}]);

@@ -1,2 +0,2 @@

var liner=function(e){function r(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,r),n.loaded=!0,n.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";var o=t(17),n=self;Object.freeze(Math),Object.freeze(Math.random),Object.freeze(Math.imul),o.nativeCrypto&&Object.freeze(o.nativeCrypto.getRandomValues),delete self.crypto,n.crypto=new o.Crypto},function(e,r,t){"use strict";function o(e){var r;r="string"==typeof e?{name:e}:e,i.checkAlgorithm(r);var t=e;return t.hash&&(t.hash=o(t.hash)),r}function n(e,r){if(!e)throw new a.WebCryptoError("Parameter '"+r+"' is required and cant be empty");if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer);if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new a.WebCryptoError("Incoming parameter '"+r+"' has wrong data type. Must be ArrayBufferView or ArrayBuffer")}var a=t(2);r.PrepareAlgorithm=o,r.PrepareData=n;var i=function(){function e(){}return e.checkAlgorithm=function(e){if("object"!=typeof e)throw new TypeError("Wrong algorithm data type. Must be Object");if(!("name"in e))throw new a.AlgorithmError(a.AlgorithmError.PARAM_REQUIRED,"name")},e.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},e.checkKey=function(e,r,t,o){if(void 0===t&&(t=null),void 0===o&&(o=null),!e)throw new a.CryptoKeyError(a.CryptoKeyError.EMPTY_KEY);var n=e.algorithm;if(this.checkAlgorithm(n),r&&n.name.toUpperCase()!==r.toUpperCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_ALG,n.name,r);if(t&&(!e.type||e.type.toUpperCase()!==t.toUpperCase()))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_TYPE,e.type,t);if(o&&!e.usages.some(function(e){return o.toUpperCase()===e.toUpperCase()}))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_USAGE,o)},e.checkWrappedKey=function(e){if(!e.extractable)throw new a.CryptoKeyError(a.CryptoKeyError.NOT_EXTRACTABLE)},e.checkKeyUsages=function(e){if(!e||!e.length)throw new a.WebCryptoError("Parameter 'keyUsages' cannot be empty.")},e.checkFormat=function(e,r){switch(e.toLowerCase()){case"raw":if(r&&"secret"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"raw");break;case"pkcs8":if(r&&"private"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"pkcs8");break;case"spki":if(r&&"public"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"spki");break;case"jwk":break;default:throw new a.CryptoKeyError(a.CryptoKeyError.UNKNOWN_FORMAT,e)}},e.generateKey=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.digest=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.sign=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.verify=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.encrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.decrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveBits=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.exportKey=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.importKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.wrapKey=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.unwrapKey=function(e,r,t,o,n,i,s){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e}();r.BaseCrypto=i},function(e,r){"use strict";function t(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o,n=e,a=/[^%](%\d+)/g,i=[];o=a.exec(n);)i.push({arg:o[1],index:o.index});for(var s=i.length-1;s>=0;s--){var c=i[s],h=c.arg.substring(1),p=c.index+1;n=n.substring(0,p)+arguments[+h]+n.substring(p+1+h.length)}return n=n.replace("%%","%")}var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=function(e){function r(r){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];var a=e.call(this)||this;a.code=0,a.message=t.apply(void 0,[r].concat(o));var i=new Error(a.message);return i.name=a.constructor.name,a.stack=i.stack,a}return o(r,e),r}(Error);n.NOT_SUPPORTED="Method is not supported",r.WebCryptoError=n;var a=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=1,r}return o(r,e),r}(n);a.PARAM_REQUIRED="Algorithm hasn't got required paramter '%1'",a.PARAM_WRONG_TYPE="Algorithm has got wrong type for paramter '%1'. Must be %2",a.PARAM_WRONG_VALUE="Algorithm has got wrong value for paramter '%1'. Must be %2",a.WRONG_ALG_NAME="Algorithm has got wrong name '%1'. Must be '%2'",a.UNSUPPORTED_ALGORITHM="Algorithm '%1' is not supported",a.WRONG_USAGE="Algorithm doesn't support key usage '%1'",r.AlgorithmError=a;var i=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=3,r}return o(r,e),r}(n);i.EMPTY_KEY="CryptoKey is empty",i.WRONG_KEY_ALG="CryptoKey has wrong algorithm '%1'. Must be '%2'",i.WRONG_KEY_TYPE="CryptoKey has wrong type '%1'. Must be '%2'",i.WRONG_KEY_USAGE="CryptoKey has wrong key usage. Must be '%1'",i.NOT_EXTRACTABLE="CryptoKey is not extractable",i.WRONG_FORMAT="CryptoKey has '%1' type. It can be used with '%2' format",i.UNKNOWN_FORMAT="Uknown format in use '%1'. Must be one of 'raw', 'pkcs8', 'spki' or 'jwk'",i.ALLOWED_FORMAT="Wrong format value '%1'. Must be %2",r.CryptoKeyError=i},function(e,r){"use strict";r.AlgorithmNames={RsaSSA:"RSASSA-PKCS1-v1_5",RsaPSS:"RSA-PSS",RsaOAEP:"RSA-OAEP",AesCTR:"AES-CTR",AesCMAC:"AES-CMAC",AesGCM:"AES-GCM",AesCBC:"AES-CBC",AesKW:"AES-KW",Sha1:"SHA-1",Sha256:"SHA-256",Sha384:"SHA-384",Sha512:"SHA-512",EcDSA:"ECDSA",EcDH:"ECDH",Hmac:"HMAC",Pbkdf2:"PBKDF2"}},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(2)),o(t(1)),o(t(3)),o(t(21)),o(t(23)),o(t(10)),o(t(14)),o(t(12)),o(t(7))},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(n.WebCryptoError);a.MODULE_NOT_FOUND="Module '%1' is not found. Download it from %2",a.UNSUPPORTED_ALGORITHM="Unsupported algorithm '%1'",r.LinerError=a},function(e,r,t){"use strict";var o=t(20),n=t(9),a=function(){function e(){this.subtle=new o.SubtleCrypto}return e.prototype.getRandomValues=function(e){return n.nativeCrypto.getRandomValues(e)},e}();r.Crypto=a},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(3),a=t(1),i=t(2);r.ShaAlgorithms=[n.AlgorithmNames.Sha1,n.AlgorithmNames.Sha256,n.AlgorithmNames.Sha384,n.AlgorithmNames.Sha512].join(" | ");var s=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.checkAlgorithm=function(t){var o;switch(o="string"==typeof t?{name:t}:t,e.checkAlgorithm.call(this,o),o.name.toUpperCase()){case n.AlgorithmNames.Sha1:case n.AlgorithmNames.Sha256:case n.AlgorithmNames.Sha384:case n.AlgorithmNames.Sha512:break;default:throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,o.name,r.ShaAlgorithms)}},t.digest=function(e,r){var t=this;return new Promise(function(r,o){t.checkAlgorithm(e),r(void 0)})},t}(a.BaseCrypto);r.Sha=s},function(e,r){"use strict";function t(){var e,t={name:"",version:""},o=self.navigator.userAgent;return(e=/edge\/([\d\.]+)/i.exec(o))?(t.name=r.Browser.Edge,t.version=e[1]):/msie/i.test(o)?(t.name=r.Browser.IE,t.version=/msie ([\d\.]+)/i.exec(o)[1]):/Trident/i.test(o)?(t.name=r.Browser.IE,t.version=/rv:([\d\.]+)/i.exec(o)[1]):/chrome/i.test(o)?(t.name=r.Browser.Chrome,t.version=/chrome\/([\d\.]+)/i.exec(o)[1]):/safari/i.test(o)?(t.name=r.Browser.Safari,t.version=/([\d\.]+) safari/i.exec(o)[1]):/firefox/i.test(o)&&(t.name=r.Browser.Firefox,t.version=/firefox\/([\d\.]+)/i.exec(o)[1]),t}function o(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}function n(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r}function a(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=new Uint8Array(e.map(function(e){return e.length}).reduce(function(e,r){return e+r})),o=0;return e.forEach(function(e,r){for(var n=0;n<e.length;n++)t[o+n]=e[n];o+=e.length}),t}function i(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o=arguments[0],n=1;n<arguments.length;n++){var a=arguments[n];for(var i in a)o[i]=a[i]}return o}r.Browser={IE:"Internet Explorer",Safari:"Safari",Edge:"Edge",Chrome:"Chrome",Firefox:"Firefox Mozilla"},r.BrowserInfo=t,r.string2buffer=o,r.buffer2string=n,r.concat=a,r.assign=i},function(e,r,t){"use strict";function o(e,r){var t=e[r];e[r]=function(){var o=arguments;return new Promise(function(n,a){var i=t.apply(e,o);i.oncomplete=function(e){console.log("Complited"),n(e.target.result)},i.onerror=function(e){console.log("Error"),a("Error on running '"+r+"' function")}})}}var n,a=t(5);if("undefined"==typeof self){var i=t(24);n={crypto:{subtle:{},getRandomValues:function(e){var r=e.buffer,t=new Uint8Array(r),o=i.randomBytes(t.length);return o.forEach(function(e,r){return t[r]=e}),e}}}}else n=self;if(r.nativeCrypto=n.msCrypto||n.crypto,r.nativeSubtle=r.nativeCrypto.subtle||r.nativeCrypto.webkitSubtle,n.msCrypto){if(!n.Promise)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"Promise","https://www.promisejs.org");o(r.nativeSubtle,"generateKey"),o(r.nativeSubtle,"digest"),o(r.nativeSubtle,"sign"),o(r.nativeSubtle,"verify"),o(r.nativeSubtle,"encrypt"),o(r.nativeSubtle,"decrypt"),o(r.nativeSubtle,"importKey"),o(r.nativeSubtle,"exportKey"),o(r.nativeSubtle,"wrapKey"),o(r.nativeSubtle,"unwrapKey"),o(r.nativeSubtle,"deriveKey"),o(r.nativeSubtle,"deriveBits")}Math.imul||(Math.imul=function(e,r){var t=e>>>16&65535,o=65535&e,n=r>>>16&65535,a=65535&r;return o*a+(t*a+o*n<<16>>>0)|0})},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=7,r}return o(r,e),r}(n.AlgorithmError),c=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkKeyUsages=function(r){var t=this;e.checkKeyUsages.call(this,r);var o=r.filter(function(e){return t.KEY_USAGES.indexOf(e)===-1});if(o.length)throw new n.AlgorithmError(n.AlgorithmError.WRONG_USAGE,o.join(", "))},r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){switch(e.length){case 128:case 192:case 256:break;default:throw new s(s.PARAM_WRONG_VALUE,"length","128, 192 or 256")}},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);c.ALG_NAME="",c.KEY_USAGES=[],r.Aes=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=8,r}return o(r,e),r}(n.AlgorithmError);r.AesAlgorithmError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"secret","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"secret","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(c);r.AesWrapKey=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","decrypt"),t(void 0)})},r}(p);u.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.AesEncrypt=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(16!==e.iv.byteLength)throw new h(h.PARAM_WRONG_VALUE,"iv","ArrayBufferView with size 16")},r}(u);m.ALG_NAME=i.AlgorithmNames.AesCBC,r.AesCBC=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.counter||!ArrayBuffer.isView(e.counter))throw new h(h.PARAM_WRONG_TYPE,"counter","ArrayBufferView");if(16!==e.counter.byteLength)throw new h(h.PARAM_WRONG_VALUE,"counter","ArrayBufferView with size 16");if(!(e.length>0&&e.length<=128))throw new h(h.PARAM_WRONG_VALUE,"length","number [1-128]")},r}(u);y.ALG_NAME=i.AlgorithmNames.AesCTR,r.AesCTR=y;var f=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),e.additionalData&&!ArrayBuffer.isView(e.additionalData))throw new h(h.PARAM_WRONG_TYPE,"additionalData","ArrayBufferView");if(!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(e.tagLength&&!(e.tagLength>=0&&e.tagLength<=128))throw new h(h.PARAM_WRONG_VALUE,"tagLength","number [0-128]")},r}(u);f.ALG_NAME=i.AlgorithmNames.AesGCM,r.AesGCM=f;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},r}(p);l.ALG_NAME=i.AlgorithmNames.AesKW,l.KEY_USAGES=["wrapKey","unwrapKey"],r.AesKW=l},function(e,r){"use strict";var t=function(){function e(){}return e}();r.CryptoKey=t},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(10),a=t(7),i=t(2),s=t(1),c=t(3),h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=9,r}return o(r,e),r}(i.AlgorithmError);r.EcKeyGenParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){var r="namedCurve";if(!e.namedCurve)throw new h(h.PARAM_REQUIRED,r);if("string"!=typeof e.namedCurve)throw new h(h.PARAM_WRONG_TYPE,r,"string");switch(e.namedCurve.toUpperCase()){case"P-256":case"P-384":case"P-521":break;default:throw new h(h.PARAM_WRONG_VALUE,r,"P-256, P-384 or P-521")}},r.checkKeyGenUsages=function(e){var r=this;e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new i.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,n){var a=this;return new Promise(function(r,o){if(a.checkKeyGenParams(t),a.checkFormat(e),"raw"===e.toLowerCase())throw new i.CryptoKeyError(i.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");a.checkKeyGenUsages(n),r(void 0)})},r}(s.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Ec=p;var u=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(i.AlgorithmError);r.EcAlgorithmError=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e),a.Sha.checkAlgorithm(e.hash)},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);m.ALG_NAME=c.AlgorithmNames.EcDSA,m.KEY_USAGES=["sign","verify","deriveKey","deriveBits"],r.EcDSA=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkDeriveParams=function(e){var r="public";if(this.checkAlgorithm(e),!e.public)throw new u(u.PARAM_REQUIRED,r);this.checkKey(e.public,this.ALG_NAME,"public")},r.deriveBits=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"private","deriveBits"),t(void 0)})},r.deriveKey=function(e,r,t,o,a){var i=this;return new Promise(function(o,a){switch(i.checkDeriveParams(e),i.checkKey(r,i.ALG_NAME,"private","deriveKey"),s.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case c.AlgorithmNames.AesCBC:n.AesCBC.checkKeyGenParams(t);break;case c.AlgorithmNames.AesCTR:n.AesCTR.checkKeyGenParams(t);break;case c.AlgorithmNames.AesGCM:n.AesGCM.checkKeyGenParams(t);break;case c.AlgorithmNames.AesKW:n.AesKW.checkKeyGenParams(t);break;default:throw new u("Unsupported name '"+t.name+"' for algorithm in param 'derivedKeyType'")}o(void 0)})},r}(p);y.ALG_NAME=c.AlgorithmNames.EcDH,y.KEY_USAGES=["deriveKey","deriveBits"],r.EcDH=y},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){if("length"in e&&!(e.length>0&&e.length<=512))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_VALUE,"length","more 0 and less than 512")},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"secret","verify"),t(void 0)})},r}(a.BaseCrypto);s.ALG_NAME=i.AlgorithmNames.Hmac,s.KEY_USAGES=["sign","verify"],r.Hmac=s},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=t(7),c=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=2,r}return o(r,e),r}(n.AlgorithmError);r.RsaKeyGenParamsError=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=6,r}return o(r,e),r}(n.AlgorithmError);r.RsaHashedImportParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkImportAlgorithm=function(e){if(this.checkAlgorithm(e),!e.hash)throw new h(h.PARAM_REQUIRED,"hash");s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenParams=function(e){switch(e.modulusLength){case 1024:case 2048:case 4096:break;default:throw new c(c.PARAM_WRONG_VALUE,"modulusLength","1024, 2048 or 4096")}var r=e.publicExponent;if(!r)throw new c(c.PARAM_REQUIRED,"publicExponent");if(!ArrayBuffer.isView(r))throw new c(c.PARAM_WRONG_TYPE,"publicExponent","ArrayBufferView");if(3!==r[0]&&(1!==r[0]||0!==r[1]||1!==r[2]))throw new c(c.PARAM_WRONG_VALUE,"publicExponent","Uint8Array([3]) | Uint8Array([1, 0, 1])");if(!e.hash)throw new c(c.PARAM_REQUIRED,"hash",s.ShaAlgorithms);s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkImportAlgorithm(t),i.checkFormat(e),"raw"===e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Rsa=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);u.ALG_NAME=i.AlgorithmNames.RsaSSA,u.KEY_USAGES=["sign","verify"],r.RsaSSA=u;var m=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=4,r}return o(r,e),r}(n.AlgorithmError);r.RsaPSSParamsError=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkRsaPssParams=function(r){return e.checkAlgorithmParams.call(this,r),r.saltLength?r.saltLength%8?new m("Parameter 'saltLength' should be a multiple of 8"):void 0:new m(m.PARAM_REQUIRED,"saltLength")},r}(u);y.ALG_NAME=i.AlgorithmNames.RsaPSS,y.KEY_USAGES=["sign","verify"],r.RsaPSS=y;var f=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=5,r}return o(r,e),r}(n.AlgorithmError);r.RsaOAEPParamsError=f;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(e.label&&!ArrayBuffer.isView(e.label))return new f(f.PARAM_WRONG_TYPE,"label","ArrayBufferView")},r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"public","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","decrypt"),t(void 0)})},r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"public","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"private","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(p);l.ALG_NAME=i.AlgorithmNames.RsaOAEP,l.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.RsaOAEP=l},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=t(11),s=t(8),c=t(9),h=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=c.nativeCrypto.getRandomValues(new Uint8Array(e.length/8)),a=new i.CryptoKey;return a.key=n,a.algorithm=e,a.extractable=r,a.type="secret",a.usages=t,a})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.encrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.encrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.decrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.decrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):s.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var c;return Promise.resolve().then(function(){return c=new p.Crypto,c.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(s.buffer2string(new Uint8Array(r))):new Uint8Array(r),c.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){return"A"+e.length+/-(\w+)/i.exec(e.name.toUpperCase())[1]},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){var o=r.key;if("jwk"===e.toLowerCase()){var a={alg:t.alg2jwk(r.algorithm),ext:r.extractable,k:n.Base64Url.encode(o),key_ops:r.usages,kty:"oct"};return a}return o.buffer})},r.importKey=function(e,r,t,o,a){return Promise.resolve().then(function(){var o;if("jwk"===e.toLowerCase()){var s=r;o=n.Base64Url.decode(s.k)}else o=new Uint8Array(r);var c=new i.CryptoKey;return c.algorithm=t,c.type="secret",c.usages=a,c.key=o,c})},r}(n.BaseCrypto);r.AesCrypto=h;var p=t(6)},function(e,r,t){"use strict";function o(e){for(var r=new Uint8Array(e),t=[],o=0;o<r.length;o++)t.push(r[o]);return t}function n(e,r){e.length%2&&(e="0"+e);for(var t=new Uint8Array(e.length/2),o=0;o<e.length;o++){var n=e.slice(o,++o+1);t[(o-1)/2]=parseInt(n,16)}if(r){var a=t.length;a=a>32?a>48?66:48:32,t.length<a&&(t=p.concat(new Uint8Array(a-t.length),t))}return t}function a(e,r){for(var t="",o=0;o<e.length;o++){var n=e[o].toString(16);t+=n.length%2?"0"+n:n}if(r){var a=e.length;a=a>32?a>48?66:48:32,t.length/2<a&&(t=new Array(2*a-t.length+1).join("0")+t)}return t}var i=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},s=t(4),c=t(5),h=t(11),p=t(8),u=function(e){function r(){return e.apply(this,arguments)||this}return i(r,e),r.checkModule=function(){if("undefined"==typeof elliptic)throw new c.LinerError(c.LinerError.MODULE_NOT_FOUND,"elliptic","https://github.com/indutny/elliptic")},r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var t=e,n=new elliptic.ec(t.namedCurve.replace("-","").toLowerCase()),a=new h.CryptoKey,i=new h.CryptoKey;return a.key=i.key=n.genKeyPair(),a.algorithm=i.algorithm=t,a.extractable=r,i.extractable=!0,a.type="private",i.type="public",e.name===s.AlgorithmNames.EcDSA?(a.usages=["sign"],i.usages=["verify"]):e.name===s.AlgorithmNames.EcDH&&(a.usages=i.usages=["deriveKey","deriveBits"]),{privateKey:a,publicKey:i}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){var r=e,o=new m.Crypto;return o.subtle.digest(r.hash,t)}).then(function(e){var t=o(e),i=r.key.sign(t),s=a(i.r.toArray(),!0)+a(i.s.toArray(),!0);return n(s).buffer})},r.verify=function(e,r,t,n){var a;return Promise.resolve().then(function(){var r=e;a={r:t.slice(0,t.byteLength/2),s:t.slice(t.byteLength/2)};var o=new m.Crypto;return o.subtle.digest(r.hash,n)}).then(function(e){var t=o(e);return r.key.verify(t,a)})},r.deriveKey=function(e,r,t,o,n){var a=this;return Promise.resolve().then(function(){return a.deriveBits(e,r,t.length)}).then(function(e){var r=new m.Crypto;return r.subtle.importKey("raw",new Uint8Array(e),t,o,n)})},r.deriveBits=function(e,r,t){return Promise.resolve().then(function(){var o=(Promise.resolve(null),r.key.derive(e.public.key.getPublic())),n=new Uint8Array(o.toArray()),a=n.length;a=a>32?a>48?66:48:32,n.length<a&&(n=p.concat(new Uint8Array(a-n.length),n));var i=n.slice(0,t/8).buffer;return i})},r.exportKey=function(e,r){return Promise.resolve().then(function(){var t=r.key;if("jwk"===e.toLowerCase()){var o=t.getPublic("hex").slice(2),a=o.slice(0,o.length/2),i=o.slice(o.length/2,o.length);if("public"===r.type){var h={crv:r.algorithm.namedCurve,ext:r.extractable,x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}var h={crv:r.algorithm.namedCurve,ext:r.extractable,d:s.Base64Url.encode(n(t.getPrivate("hex"),!0)),x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}throw new c.LinerError("Format '"+e+"' is not implemented")})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var i=new h.CryptoKey;if(i.algorithm=t,"jwk"!==e.toLowerCase())throw new c.LinerError("Format '"+e+"' is not implemented");var u=new elliptic.ec(r.crv.replace("-","").toLowerCase());if(r.d)i.key=u.keyFromPrivate(s.Base64Url.decode(r.d)),i.type="private";else{
var m=p.concat(new Uint8Array([4]),s.Base64Url.decode(r.x),s.Base64Url.decode(r.y)),y=a(m);i.key=u.keyFromPublic(y,"hex"),i.type="public"}return i.extractable=o,i.usages=n,i})},r}(s.BaseCrypto);r.EcCrypto=u;var m=t(6)},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(9)),o(t(6))},function(e,r,t){"use strict";function o(e){var r=!0;return e.filter(function(e){return(!r||0!==e)&&(r=!1,!0)})}var n=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},a=t(4),i=t(5),s=t(11),c=t(8),h=function(e){function r(){return e.apply(this,arguments)||this}return n(r,e),r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new i.LinerError(i.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r.filterUsages=function(e,r){return e.filter(function(e){return!!r.filter(function(r){return e===r}).length})},r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=3===e.publicExponent[0]?3:65537,c=asmCrypto.RSA.generateKey(e.modulusLength,n),h=new s.CryptoKey,p=new s.CryptoKey;switch(h.key=p.key=c,h.algorithm=p.algorithm=e,h.extractable=r,p.extractable=!0,h.type="private",p.type="public",e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():h.usages=o.filterUsages(["decrypt","unwrapKey"],t),p.usages=o.filterUsages(["encrypt","wrapKey"],t);break;case a.AlgorithmNames.RsaPSS.toLowerCase():h.usages=o.filterUsages(["sign"],t),p.usages=o.filterUsages(["verify"],t);break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}return{privateKey:h,publicKey:p}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaPSS.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_PSS_SHA1.sign;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_PSS_SHA256.sign;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return s(t,r.key,n.saltLength).buffer;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.verify=function(e,r,t,o){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaPSS.toLowerCase():var n=r.algorithm,s=e,c=void 0;switch(n.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:c=asmCrypto.RSA_PSS_SHA1.verify;break;case a.AlgorithmNames.Sha256:c=asmCrypto.RSA_PSS_SHA256.verify;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return c(t,o,r.key,s.saltLength);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.encrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.encrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.decrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.decrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):c.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s;return Promise.resolve().then(function(){return s=new p.Crypto,s.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(c.buffer2string(new Uint8Array(r))):new Uint8Array(r),s.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){var r=e.hash,t=/(\d+)/.exec(r.name)[1];switch(e.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():return"RSA-OAEP"+("1"===t?"":"-"+t);case a.AlgorithmNames.RsaPSS.toUpperCase():return"PS"+t;case a.AlgorithmNames.RsaSSA.toUpperCase():return"RS"+t;default:throw new a.AlgorithmError(a.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){if("jwk"===e.toLowerCase()){var n={kty:"RSA",ext:!0,key_ops:r.usages};return n.alg=t.alg2jwk(r.algorithm),n.n=a.Base64Url.encode(o(r.key[0])),n.e=a.Base64Url.encode(o(r.key[1])),"private"===r.type&&(n.d=a.Base64Url.encode(o(r.key[2])),n.p=a.Base64Url.encode(o(r.key[3])),n.q=a.Base64Url.encode(o(r.key[4])),n.dp=a.Base64Url.encode(o(r.key[5])),n.dq=a.Base64Url.encode(o(r.key[6])),n.qi=a.Base64Url.encode(o(r.key[7]))),n}throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var o,c=new s.CryptoKey;if(c.algorithm=t,c.usages=n,c.key=[],"jwk"===e.toLowerCase())return o=r,c.key[0]=a.Base64Url.decode(o.n),c.key[1]=3===a.Base64Url.decode(o.e)[0]?new Uint8Array([0,0,0,3]):new Uint8Array([0,1,0,1]),o.d?(c.type="private",c.key[2]=a.Base64Url.decode(o.d),c.key[3]=a.Base64Url.decode(o.p),c.key[4]=a.Base64Url.decode(o.q),c.key[5]=a.Base64Url.decode(o.dp),c.key[6]=a.Base64Url.decode(o.dq),c.key[7]=a.Base64Url.decode(o.qi)):c.type="public",c;throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r}(a.BaseCrypto);r.RsaCrypto=h;var p=t(6)},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.digest=function(e,r){return Promise.resolve().then(function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js");switch(e.name.toUpperCase()){case n.AlgorithmNames.Sha1:return asmCrypto.SHA1.bytes(r).buffer;case n.AlgorithmNames.Sha256:return asmCrypto.SHA256.bytes(r).buffer;default:throw new a.LinerError("Not supported algorithm '"+e.name+"'")}})},r}(n.BaseCrypto);r.ShaCrypto=i},function(e,r,t){"use strict";function o(e,r){return Promise.resolve().then(function(){if(e.key)return e;if(e.extractable){var t=new l.Crypto;return t.subtle.exportKey("jwk",e).then(function(t){return r.importKey("jwk",t,e.algorithm,!0,e.usages)})}throw new f.LinerError("'key' is Native CryptoKey. It can't be converted to JS CryptoKey")})}function n(e,r){A.BrowserInfo().name!==A.Browser.IE&&A.BrowserInfo().name!==A.Browser.Edge&&A.BrowserInfo().name!==A.Browser.Safari||!/^rsa/i.test(e.name)||(r.privateKey?(v.push({hash:e.hash,key:r.privateKey}),v.push({hash:e.hash,key:r.publicKey})):v.push({hash:e.hash,key:r}))}function a(e){var r=null;return v.some(function(t){return t.key===e&&(r=A.assign({},e.algorithm,{hash:t.hash}),!0)}),r}function i(e,r){var t=[];e.privateKey?(t.push(e.privateKey),t.push(e.publicKey)):t.push(e),t.forEach(function(e){"keyUsage"in e&&(e.usages=e.keyUsage||[],e.usages.length||(["verify","encrypt","wrapKey"].forEach(function(t){r.indexOf(t)>-1&&("public"===e.type||"secret"===e.type)&&e.usages.push(t)}),["sign","decrypt","unwrapKey","deriveKey","deriveBits"].forEach(function(t){r.indexOf(t)>-1&&("private"===e.type||"secret"===e.type)&&e.usages.push(t)})))})}function s(e,r,t){if(r&&A.BrowserInfo().name===A.Browser.IE){"extractable"in e&&(e.ext=e.extractable,delete e.extractable);var o=null;switch(r.name.toUpperCase()){case p.AlgorithmNames.RsaOAEP.toUpperCase():case p.AlgorithmNames.RsaPSS.toUpperCase():case p.AlgorithmNames.RsaSSA.toUpperCase():o=E.RsaCrypto;break;case p.AlgorithmNames.AesCBC.toUpperCase():case p.AlgorithmNames.AesGCM.toUpperCase():o=w.AesCrypto}o&&!e.alg&&(e.alg=o.alg2jwk(r)),"key_ops"in e||(e.key_ops=t)}}function c(e){A.BrowserInfo().name===A.Browser.IE&&("ext"in e&&(e.extractable=e.ext,delete e.ext),delete e.key_ops,delete e.alg)}var h=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},p=t(4),u=t(4),m=t(4),y=t(9),f=t(5),l=t(6),A=t(8),w=t(15),g=t(19),E=t(18),C=t(16),v=[],P=function(e){function r(){return e.apply(this,arguments)||this}return h(r,e),r.prototype.generateKey=function(r,t,o){var a,s=arguments;return e.prototype.generateKey.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r);try{return y.nativeSubtle.generateKey.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,o),n(a,e),e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.EcDSA.toLowerCase():case p.AlgorithmNames.EcDH.toLowerCase():r=C.EcCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"generateKey")}return r.generateKey(a,t,o)})},r.prototype.digest=function(r,t){var o,n,a=arguments;return e.prototype.digest.apply(this,a).then(function(e){o=m.PrepareAlgorithm(r),n=m.PrepareData(t,"data");try{return y.nativeSubtle.digest.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")}}).then(function(e){return e?e:g.ShaCrypto.digest(o,n)})},r.prototype.sign=function(r,t,n){var i,s,c=arguments;return e.prototype.sign.apply(this,c).then(function(e){i=m.PrepareAlgorithm(r),s=m.PrepareData(n,"data");var o=a(t);o&&(c[0]=A.assign(i,o));try{return y.nativeSubtle.sign.apply(y.nativeSubtle,c).catch(function(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(i.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"sign")}return o(t,r).then(function(e){return r.sign(i,e,s)})})},r.prototype.verify=function(r,t,n,i){var s,c,h,u=arguments;return e.prototype.verify.apply(this,u).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareData(n,"data"),h=m.PrepareData(i,"data");var o=a(t);o&&(u[0]=A.assign(s,o));try{return y.nativeSubtle.verify.apply(y.nativeSubtle,u).catch(function(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if("boolean"==typeof e)return e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"sign")}return o(t,r).then(function(e){return r.verify(s,e,c,h)})})},r.prototype.deriveBits=function(r,t,o){var n,a=arguments;return e.prototype.deriveBits.apply(this,a).then(function(e){n=m.PrepareAlgorithm(r);try{return y.nativeSubtle.deriveBits.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(n.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=C.EcCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveBits(n,t,o)})},r.prototype.deriveKey=function(r,t,o,n,a){var s,c,h=arguments;return e.prototype.deriveKey.apply(this,h).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareAlgorithm(o);try{return y.nativeSubtle.deriveKey.apply(y.nativeSubtle,h).catch(function(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,a),e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=C.EcCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveKey(s,t,c,n,a)})},r.prototype.encrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.encrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");try{return y.nativeSubtle.encrypt.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){if(A.BrowserInfo().name===A.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM&&e.ciphertext){var r=new Uint8Array(e.ciphertext.byteLength+e.tag.byteLength),n=0;new Uint8Array(e.ciphertext).forEach(function(e){return r[n++]=e}),new Uint8Array(e.tag).forEach(function(e){return r[n++]=e}),e=r.buffer}return Promise.resolve(e)}var s;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():s=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():s=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,s).then(function(e){return s.encrypt(a,e,i)})})},r.prototype.decrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.decrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");var o=i;if(A.BrowserInfo().name===A.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM){var s=i.byteLength-a.tagLength/8;o={ciphertext:i.buffer.slice(0,s),tag:i.buffer.slice(s,i.byteLength)}}try{return y.nativeSubtle.decrypt.call(y.nativeSubtle,a,t,o).catch(function(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():r=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,r).then(function(e){return r.decrypt(a,e,i)})})},r.prototype.wrapKey=function(r,t,o,n){var a,i=arguments;return e.prototype.wrapKey.apply(this,i).then(function(e){a=m.PrepareAlgorithm(n);try{return y.nativeSubtle.wrapKey.apply(y.nativeSubtle,i).catch(function(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var n;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():n=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"wrapKey")}return n.wrapKey(r,t,o,a)})},r.prototype.unwrapKey=function(r,t,o,n,a,s,c){var h,u,l,A=arguments;return e.prototype.unwrapKey.apply(this,A).then(function(e){h=m.PrepareAlgorithm(n),u=m.PrepareAlgorithm(a),l=m.PrepareData(t,"wrappedKey");try{return y.nativeSubtle.unwrapKey.apply(y.nativeSubtle,A).catch(function(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,c),e;var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():t=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"unwrapKey")}return t.unwrapKey(r,l,o,h,u,s,c)})},r.prototype.exportKey=function(r,t){var o=arguments;return e.prototype.exportKey.apply(this,o).then(function(){try{return y.nativeSubtle.exportKey.apply(y.nativeSubtle,o).catch(function(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){"jwk"===r&&e instanceof ArrayBuffer&&(e=A.buffer2string(new Uint8Array(e)),e=JSON.parse(e));var o=a(t);return o||(o=A.assign({},t.algorithm)),s(e,o,t.usages),Promise.resolve(e)}if(!t.key)throw new f.LinerError("Cannot export native CryptoKey from JS implementation");var n;switch(t.algorithm.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():n=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():n=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"exportKey")}return n.exportKey(r,t)})},r.prototype.importKey=function(r,t,o,a,s){var h,u,l=arguments;return e.prototype.importKey.apply(this,l).then(function(e){h=m.PrepareAlgorithm(o),u=t,A.BrowserInfo().name!==A.Browser.Safari&&A.BrowserInfo().name!==A.Browser.IE||(A.BrowserInfo().name===A.Browser.IE&&(t=A.assign({},t),c(t)),l[1]=A.string2buffer(JSON.stringify(t)).buffer),ArrayBuffer.isView(t)&&(u=m.PrepareData(t,"keyData"));try{return y.nativeSubtle.importKey.apply(y.nativeSubtle,l).catch(function(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return n(h,e),i(e,s),Promise.resolve(e);var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():t=C.EcCrypto;break;case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():t=E.RsaCrypto;break;default:throw new f.LinerError(f.LinerError.NOT_SUPPORTED,"importKey")}return t.importKey(r,u,h,a,s)})},r}(u.SubtleCrypto);r.SubtleCrypto=P,Uint8Array.prototype.forEach||(Uint8Array.prototype.forEach=function(e){for(var r=0;r<this.length;r++)e(this[r],r,this)}),Uint8Array.prototype.slice||(Uint8Array.prototype.slice=function(e,r){return new Uint8Array(this.buffer.slice(e,r))}),Uint8Array.prototype.filter||(Uint8Array.prototype.filter=function(e){for(var r=[],t=0;t<this.length;t++)e(this[t],t,this)&&r.push(this[t]);return new Uint8Array(r)})},function(e,r){(function(e){"use strict";if("undefined"==typeof self){var t=e;t.btoa=function(e){return new Buffer(e,"binary").toString("base64")},t.atob=function(e){return new Buffer(e,"base64").toString("binary")}}var o=function(){function e(){}return e.buffer2string=function(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r},e.string2buffer=function(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r},e.encode=function(e){var r=this.buffer2string(e),t=btoa(r).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");return t},e.decode=function(e){for(;e.length%4;)e+="=";var r=e.replace(/\-/g,"+").replace(/_/g,"/");return this.string2buffer(atob(r))},e}();r.Base64Url=o}).call(r,function(){return this}())},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(1),s=t(3),c=t(7),h=t(10),p=t(13),u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkDeriveParams=function(e){if(this.checkAlgorithm(e),!e.salt)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"salt");if(!(ArrayBuffer.isView(e.salt)||e.salt instanceof ArrayBuffer))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_TYPE,"salt","ArrayBuffer or ArrayBufferView");if(!e.iterations)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"iterations");if(!e.hash)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"hash");var r=a.PrepareAlgorithm(e.hash);c.Sha.checkAlgorithm(r)},r.importKey=function(e,r,t,o,a){var i=this;return Promise.resolve().then(function(){if(o)throw new n.WebCryptoError("KDF keys must set extractable=false");if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'raw'");i.checkKeyUsages(a)})},r.deriveKey=function(e,r,t,o,a){var c=this;return Promise.resolve().then(function(){switch(c.checkDeriveParams(e),c.checkKey(r,c.ALG_NAME,"secret","deriveKey"),i.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case s.AlgorithmNames.AesCBC:h.AesCBC.checkKeyGenParams(t),h.AesCBC.checkKeyUsages(a);break;case s.AlgorithmNames.AesCTR:h.AesCTR.checkKeyGenParams(t),h.AesCTR.checkKeyUsages(a);break;case s.AlgorithmNames.AesGCM:h.AesGCM.checkKeyGenParams(t),h.AesGCM.checkKeyUsages(a);break;case s.AlgorithmNames.AesKW:h.AesKW.checkKeyGenParams(t),h.AesKW.checkKeyUsages(a);break;case s.AlgorithmNames.Hmac:p.Hmac.checkKeyGenParams(t),p.Hmac.checkKeyUsages(a);break;default:throw new n.AlgorithmError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,t)}})},r.deriveBits=function(e,r,t){var o=this;return Promise.resolve().then(function(){if(o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"secret","deriveBits"),!t||"number"!=typeof t)throw new n.WebCryptoError("Parameter 'length' must be Number and more than 0")})},r}(i.BaseCrypto);u.ALG_NAME=s.AlgorithmNames.Pbkdf2,u.KEY_USAGES=["deriveKey","deriveBits"],r.Pbkdf2=u},function(e,r,t){"use strict";var o=t(2),n=t(1),a=t(3),i=t(7),s=t(14),c=t(10),h=t(12),p=t(13),u=t(22),m=function(){function e(){}return e.prototype.generateKey=function(e,r,t){return new Promise(function(i,u){var m=n.PrepareAlgorithm(e),y=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():y=s.RsaOAEP;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.AesCBC.toUpperCase():y=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():y=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():y=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():y=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():y=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}y.generateKey(m,r,t).then(i,u)})},e.prototype.digest=function(e,r){return new Promise(function(t,s){var c=n.PrepareAlgorithm(e),h=n.PrepareData(r,"data"),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.Sha1.toUpperCase():case a.AlgorithmNames.Sha256.toUpperCase():case a.AlgorithmNames.Sha384.toUpperCase():case a.AlgorithmNames.Sha512.toUpperCase():p=i.Sha;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.digest(c,h).then(t,s)})},e.prototype.sign=function(e,r,t){return new Promise(function(i,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(t,"data"),y=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}y.sign(u,r,m).then(i,c)})},e.prototype.verify=function(e,r,t,i){return new Promise(function(t,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(i,"signature"),y=n.PrepareData(i,"data"),f=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():f=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():f=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():f=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():f=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}f.verify(u,r,m,y).then(t,c)})},e.prototype.encrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.encrypt(p,r,u).then(i,h)})},e.prototype.decrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.decrypt(p,r,u).then(i,h)})},e.prototype.deriveBits=function(e,r,t){return new Promise(function(i,s){var c=n.PrepareAlgorithm(e),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():p=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():p=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.deriveBits(c,r,t).then(i,s)})},e.prototype.deriveKey=function(e,r,t,i,s){return new Promise(function(c,p){var m=n.PrepareAlgorithm(e),y=n.PrepareAlgorithm(t),f=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():f=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():f=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}f.deriveKey(m,r,y,i,s).then(c,p)})},e.prototype.exportKey=function(e,r){return new Promise(function(t,i){if(n.BaseCrypto.checkKey(r),!r.extractable)throw new o.CryptoKeyError(o.CryptoKeyError.NOT_EXTRACTABLE);var u=n.BaseCrypto;switch(r.algorithm.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():u=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():u=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():u=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():u=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():u=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():u=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():u=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():u=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():u=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():u=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}u.exportKey(e,r).then(t,i)})},e.prototype.importKey=function(e,r,t,i,m){return new Promise(function(y,f){var l=n.PrepareAlgorithm(t),A=n.BaseCrypto;switch(l.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():A=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():A=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():A=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():A=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():A=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():A=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():A=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():A=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():A=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():A=p.Hmac;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():A=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,l.name)}A.importKey(e,r,l,i,m).then(y,f)})},e.prototype.wrapKey=function(e,r,t,i){return new Promise(function(h,p){var u=n.PrepareAlgorithm(i),m=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():m=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}m.wrapKey(e,r,t,u).then(h,p)})},e.prototype.unwrapKey=function(e,r,t,i,h,p,u){return new Promise(function(m,y){var f=n.PrepareAlgorithm(i),l=n.PrepareAlgorithm(h),A=n.PrepareData(r,"wrappedKey"),w=n.BaseCrypto;switch(f.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():w=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():w=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():w=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():w=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():w=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,f.name)}w.unwrapKey(e,A,t,f,l,p,u).then(m,y)})},e}();r.SubtleCrypto=m},function(e,r){e.exports=require("crypto")}]);
var liner=function(e){function r(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,r),n.loaded=!0,n.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";var o=t(17),n=self;Object.freeze(Math),Object.freeze(Math.random),Object.freeze(Math.imul),o.nativeCrypto&&Object.freeze(o.nativeCrypto.getRandomValues),delete self.crypto,n.crypto=new o.Crypto},function(e,r,t){"use strict";function o(e){var r;r="string"==typeof e?{name:e}:e,i.checkAlgorithm(r);var t=e;return t.hash&&(t.hash=o(t.hash)),r}function n(e,r){if(!e)throw new a.WebCryptoError("Parameter '"+r+"' is required and cant be empty");if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer);if(e instanceof ArrayBuffer)return new Uint8Array(e);throw new a.WebCryptoError("Incoming parameter '"+r+"' has wrong data type. Must be ArrayBufferView or ArrayBuffer")}var a=t(2);r.PrepareAlgorithm=o,r.PrepareData=n;var i=function(){function e(){}return e.checkAlgorithm=function(e){if("object"!=typeof e)throw new TypeError("Wrong algorithm data type. Must be Object");if(!("name"in e))throw new a.AlgorithmError(a.AlgorithmError.PARAM_REQUIRED,"name")},e.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},e.checkKey=function(e,r,t,o){if(void 0===t&&(t=null),void 0===o&&(o=null),!e)throw new a.CryptoKeyError(a.CryptoKeyError.EMPTY_KEY);var n=e.algorithm;if(this.checkAlgorithm(n),r&&n.name.toUpperCase()!==r.toUpperCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_ALG,n.name,r);if(t&&(!e.type||e.type.toUpperCase()!==t.toUpperCase()))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_TYPE,e.type,t);if(o&&!e.usages.some(function(e){return o.toUpperCase()===e.toUpperCase()}))throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_KEY_USAGE,o)},e.checkWrappedKey=function(e){if(!e.extractable)throw new a.CryptoKeyError(a.CryptoKeyError.NOT_EXTRACTABLE)},e.checkKeyUsages=function(e){if(!e||!e.length)throw new a.WebCryptoError("Parameter 'keyUsages' cannot be empty.")},e.checkFormat=function(e,r){switch(e.toLowerCase()){case"raw":if(r&&"secret"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"raw");break;case"pkcs8":if(r&&"private"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"pkcs8");break;case"spki":if(r&&"public"!==r.toLowerCase())throw new a.CryptoKeyError(a.CryptoKeyError.WRONG_FORMAT,r,"spki");break;case"jwk":break;default:throw new a.CryptoKeyError(a.CryptoKeyError.UNKNOWN_FORMAT,e)}},e.generateKey=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.digest=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.sign=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.verify=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.encrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.decrypt=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveBits=function(e,r,t){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.deriveKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.exportKey=function(e,r){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.importKey=function(e,r,t,o,n){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.wrapKey=function(e,r,t,o){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e.unwrapKey=function(e,r,t,o,n,i,s){return new Promise(function(e,r){throw new a.WebCryptoError(a.WebCryptoError.NOT_SUPPORTED)})},e}();r.BaseCrypto=i},function(e,r){"use strict";function t(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o,n=e,a=/[^%](%\d+)/g,i=[];o=a.exec(n);)i.push({arg:o[1],index:o.index});for(var s=i.length-1;s>=0;s--){var c=i[s],h=c.arg.substring(1),p=c.index+1;n=n.substring(0,p)+arguments[+h]+n.substring(p+1+h.length)}return n=n.replace("%%","%")}var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=function(e){function r(r){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];var a=e.call(this)||this;a.code=0,a.message=t.apply(void 0,[r].concat(o));var i=new Error(a.message);return i.name=a.constructor.name,a.stack=i.stack,a}return o(r,e),r}(Error);n.NOT_SUPPORTED="Method is not supported",r.WebCryptoError=n;var a=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=1,r}return o(r,e),r}(n);a.PARAM_REQUIRED="Algorithm hasn't got required paramter '%1'",a.PARAM_WRONG_TYPE="Algorithm has got wrong type for paramter '%1'. Must be %2",a.PARAM_WRONG_VALUE="Algorithm has got wrong value for paramter '%1'. Must be %2",a.WRONG_ALG_NAME="Algorithm has got wrong name '%1'. Must be '%2'",a.UNSUPPORTED_ALGORITHM="Algorithm '%1' is not supported",a.WRONG_USAGE="Algorithm doesn't support key usage '%1'",r.AlgorithmError=a;var i=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=3,r}return o(r,e),r}(n);i.EMPTY_KEY="CryptoKey is empty",i.WRONG_KEY_ALG="CryptoKey has wrong algorithm '%1'. Must be '%2'",i.WRONG_KEY_TYPE="CryptoKey has wrong type '%1'. Must be '%2'",i.WRONG_KEY_USAGE="CryptoKey has wrong key usage. Must be '%1'",i.NOT_EXTRACTABLE="CryptoKey is not extractable",i.WRONG_FORMAT="CryptoKey has '%1' type. It can be used with '%2' format",i.UNKNOWN_FORMAT="Uknown format in use '%1'. Must be one of 'raw', 'pkcs8', 'spki' or 'jwk'",i.ALLOWED_FORMAT="Wrong format value '%1'. Must be %2",r.CryptoKeyError=i},function(e,r){"use strict";r.AlgorithmNames={RsaSSA:"RSASSA-PKCS1-v1_5",RsaPSS:"RSA-PSS",RsaOAEP:"RSA-OAEP",AesCTR:"AES-CTR",AesCMAC:"AES-CMAC",AesGCM:"AES-GCM",AesCBC:"AES-CBC",AesKW:"AES-KW",Sha1:"SHA-1",Sha256:"SHA-256",Sha384:"SHA-384",Sha512:"SHA-512",EcDSA:"ECDSA",EcDH:"ECDH",Hmac:"HMAC",Pbkdf2:"PBKDF2"}},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(2)),o(t(1)),o(t(3)),o(t(21)),o(t(23)),o(t(10)),o(t(14)),o(t(12)),o(t(7))},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=function(e){function r(){var r=null!==e&&e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(n.WebCryptoError);a.MODULE_NOT_FOUND="Module '%1' is not found. Download it from %2",a.UNSUPPORTED_ALGORITHM="Unsupported algorithm '%1'",r.LinerError=a},function(e,r,t){"use strict";var o=t(20),n=t(9),a=function(){function e(){this.subtle=new o.SubtleCrypto}return e.prototype.getRandomValues=function(e){return n.nativeCrypto.getRandomValues(e)},e}();r.Crypto=a},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(3),a=t(1),i=t(2);r.ShaAlgorithms=[n.AlgorithmNames.Sha1,n.AlgorithmNames.Sha256,n.AlgorithmNames.Sha384,n.AlgorithmNames.Sha512].join(" | ");var s=function(e){function t(){return e.apply(this,arguments)||this}return o(t,e),t.checkAlgorithm=function(t){var o;switch(o="string"==typeof t?{name:t}:t,e.checkAlgorithm.call(this,o),o.name.toUpperCase()){case n.AlgorithmNames.Sha1:case n.AlgorithmNames.Sha256:case n.AlgorithmNames.Sha384:case n.AlgorithmNames.Sha512:break;default:throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,o.name,r.ShaAlgorithms)}},t.digest=function(e,r){var t=this;return new Promise(function(r,o){t.checkAlgorithm(e),r(void 0)})},t}(a.BaseCrypto);r.Sha=s},function(e,r){"use strict";function t(){var e,t={name:"",version:""},o=self.navigator.userAgent;return(e=/edge\/([\d\.]+)/i.exec(o))?(t.name=r.Browser.Edge,t.version=e[1]):/msie/i.test(o)?(t.name=r.Browser.IE,t.version=/msie ([\d\.]+)/i.exec(o)[1]):/Trident/i.test(o)?(t.name=r.Browser.IE,t.version=/rv:([\d\.]+)/i.exec(o)[1]):/chrome/i.test(o)?(t.name=r.Browser.Chrome,t.version=/chrome\/([\d\.]+)/i.exec(o)[1]):/safari/i.test(o)?(t.name=r.Browser.Safari,t.version=/([\d\.]+) safari/i.exec(o)[1]):/firefox/i.test(o)&&(t.name=r.Browser.Firefox,t.version=/firefox\/([\d\.]+)/i.exec(o)[1]),t}function o(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}function n(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r}function a(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=new Uint8Array(e.map(function(e){return e.length}).reduce(function(e,r){return e+r})),o=0;return e.forEach(function(e,r){for(var n=0;n<e.length;n++)t[o+n]=e[n];o+=e.length}),t}function i(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];for(var o=arguments[0],n=1;n<arguments.length;n++){var a=arguments[n];for(var i in a)o[i]=a[i]}return o}r.Browser={IE:"Internet Explorer",Safari:"Safari",Edge:"Edge",Chrome:"Chrome",Firefox:"Firefox Mozilla"},r.BrowserInfo=t,r.string2buffer=o,r.buffer2string=n,r.concat=a,r.assign=i},function(e,r,t){"use strict";function o(e,r){var t=e[r];e[r]=function(){var o=arguments;return new Promise(function(n,a){var i=t.apply(e,o);i.oncomplete=function(e){console.log("Completed"),n(e.target.result)},i.onerror=function(e){console.log("Error"),a("Error on running '"+r+"' function")}})}}var n,a=t(5);if("undefined"==typeof self){var i=t(24);n={crypto:{subtle:{},getRandomValues:function(e){var r=e.buffer,t=new Uint8Array(r),o=i.randomBytes(t.length);return o.forEach(function(e,r){return t[r]=e}),e}}}}else n=self;if(r.nativeCrypto=n.msCrypto||n.crypto,r.nativeSubtle=r.nativeCrypto.subtle||r.nativeCrypto.webkitSubtle,n.msCrypto){if(!n.Promise)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"Promise","https://www.promisejs.org");o(r.nativeSubtle,"generateKey"),o(r.nativeSubtle,"digest"),o(r.nativeSubtle,"sign"),o(r.nativeSubtle,"verify"),o(r.nativeSubtle,"encrypt"),o(r.nativeSubtle,"decrypt"),o(r.nativeSubtle,"importKey"),o(r.nativeSubtle,"exportKey"),o(r.nativeSubtle,"wrapKey"),o(r.nativeSubtle,"unwrapKey"),o(r.nativeSubtle,"deriveKey"),o(r.nativeSubtle,"deriveBits")}Math.imul||(Math.imul=function(e,r){var t=e>>>16&65535,o=65535&e,n=r>>>16&65535,a=65535&r;return o*a+(t*a+o*n<<16>>>0)|0})},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=7,r}return o(r,e),r}(n.AlgorithmError),c=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkKeyUsages=function(r){var t=this;e.checkKeyUsages.call(this,r);var o=r.filter(function(e){return t.KEY_USAGES.indexOf(e)===-1});if(o.length)throw new n.AlgorithmError(n.AlgorithmError.WRONG_USAGE,o.join(", "))},r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){switch(e.length){case 128:case 192:case 256:break;default:throw new s(s.PARAM_WRONG_VALUE,"length","128, 192 or 256")}},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);c.ALG_NAME="",c.KEY_USAGES=[],r.Aes=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=8,r}return o(r,e),r}(n.AlgorithmError);r.AesAlgorithmError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"secret","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"secret","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(c);r.AesWrapKey=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","decrypt"),t(void 0)})},r}(p);u.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.AesEncrypt=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(16!==e.iv.byteLength)throw new h(h.PARAM_WRONG_VALUE,"iv","ArrayBufferView with size 16")},r}(u);m.ALG_NAME=i.AlgorithmNames.AesCBC,r.AesCBC=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),!e.counter||!ArrayBuffer.isView(e.counter))throw new h(h.PARAM_WRONG_TYPE,"counter","ArrayBufferView");if(16!==e.counter.byteLength)throw new h(h.PARAM_WRONG_VALUE,"counter","ArrayBufferView with size 16");if(!(e.length>0&&e.length<=128))throw new h(h.PARAM_WRONG_VALUE,"length","number [1-128]")},r}(u);y.ALG_NAME=i.AlgorithmNames.AesCTR,r.AesCTR=y;var A=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(this.checkAlgorithm(e),e.additionalData&&!ArrayBuffer.isView(e.additionalData))throw new h(h.PARAM_WRONG_TYPE,"additionalData","ArrayBufferView");if(!e.iv)throw new h(h.PARAM_REQUIRED,"iv");if(!ArrayBuffer.isView(e.iv))throw new h(h.PARAM_WRONG_TYPE,"iv","ArrayBufferView");if(e.tagLength&&!(e.tagLength>=0&&e.tagLength<=128))throw new h(h.PARAM_WRONG_VALUE,"tagLength","number [0-128]")},r}(u);A.ALG_NAME=i.AlgorithmNames.AesGCM,r.AesGCM=A;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e)},r}(p);l.ALG_NAME=i.AlgorithmNames.AesKW,l.KEY_USAGES=["wrapKey","unwrapKey"],r.AesKW=l},function(e,r){"use strict";var t=function(){function e(){}return e}();r.CryptoKey=t},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(10),a=t(7),i=t(2),s=t(1),c=t(3),h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=9,r}return o(r,e),r}(i.AlgorithmError);r.EcKeyGenParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new i.AlgorithmError(i.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){var r="namedCurve";if(!e.namedCurve)throw new h(h.PARAM_REQUIRED,r);if("string"!=typeof e.namedCurve)throw new h(h.PARAM_WRONG_TYPE,r,"string");switch(e.namedCurve.toUpperCase()){case"P-256":case"P-384":case"P-521":break;default:throw new h(h.PARAM_WRONG_VALUE,r,"P-256, P-384 or P-521")}},r.checkKeyGenUsages=function(e){var r=this;e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new i.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,n){var a=this;return new Promise(function(r,o){if(a.checkKeyGenParams(t),a.checkFormat(e),"raw"===e.toLowerCase())throw new i.CryptoKeyError(i.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");a.checkKeyGenUsages(n),r(void 0)})},r}(s.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Ec=p;var u=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=10,r}return o(r,e),r}(i.AlgorithmError);r.EcAlgorithmError=u;var m=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){this.checkAlgorithm(e),a.Sha.checkAlgorithm(e.hash)},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);m.ALG_NAME=c.AlgorithmNames.EcDSA,m.KEY_USAGES=["sign","verify","deriveKey","deriveBits"],r.EcDSA=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkDeriveParams=function(e){var r="public";if(this.checkAlgorithm(e),!e.public)throw new u(u.PARAM_REQUIRED,r);this.checkKey(e.public,this.ALG_NAME,"public")},r.deriveBits=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"private","deriveBits"),t(void 0)})},r.deriveKey=function(e,r,t,o,a){var i=this;return new Promise(function(o,a){switch(i.checkDeriveParams(e),i.checkKey(r,i.ALG_NAME,"private","deriveKey"),s.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case c.AlgorithmNames.AesCBC:n.AesCBC.checkKeyGenParams(t);break;case c.AlgorithmNames.AesCTR:n.AesCTR.checkKeyGenParams(t);break;case c.AlgorithmNames.AesGCM:n.AesGCM.checkKeyGenParams(t);break;case c.AlgorithmNames.AesKW:n.AesKW.checkKeyGenParams(t);break;default:throw new u("Unsupported name '"+t.name+"' for algorithm in param 'derivedKeyType'")}o(void 0)})},r}(p);y.ALG_NAME=c.AlgorithmNames.EcDH,y.KEY_USAGES=["deriveKey","deriveBits"],r.EcDH=y},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkKeyGenParams=function(e){if("length"in e&&!(e.length>0&&e.length<=512))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_VALUE,"length","more 0 and less than 512")},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase()&&"jwk"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'jwk' or 'raw'");i.checkKeyGenUsages(a),r(void 0)})},r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"secret","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"secret","verify"),t(void 0)})},r}(a.BaseCrypto);s.ALG_NAME=i.AlgorithmNames.Hmac,s.KEY_USAGES=["sign","verify"],r.Hmac=s},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(3),s=t(7),c=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=2,r}return o(r,e),r}(n.AlgorithmError);r.RsaKeyGenParamsError=c;var h=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=6,r}return o(r,e),r}(n.AlgorithmError);r.RsaHashedImportParamsError=h;var p=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkImportAlgorithm=function(e){if(this.checkAlgorithm(e),!e.hash)throw new h(h.PARAM_REQUIRED,"hash");s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenParams=function(e){switch(e.modulusLength){case 1024:case 2048:case 4096:break;default:throw new c(c.PARAM_WRONG_VALUE,"modulusLength","1024, 2048 or 4096")}var r=e.publicExponent;if(!r)throw new c(c.PARAM_REQUIRED,"publicExponent");if(!ArrayBuffer.isView(r))throw new c(c.PARAM_WRONG_TYPE,"publicExponent","ArrayBufferView");if(3!==r[0]&&(1!==r[0]||0!==r[1]||1!==r[2]))throw new c(c.PARAM_WRONG_VALUE,"publicExponent","Uint8Array([3]) | Uint8Array([1, 0, 1])");if(!e.hash)throw new c(c.PARAM_REQUIRED,"hash",s.ShaAlgorithms);s.Sha.checkAlgorithm(e.hash)},r.checkKeyGenUsages=function(e){var r=this;this.checkKeyUsages(e),e.forEach(function(e){var t=0;for(t;t<r.KEY_USAGES.length&&r.KEY_USAGES[t].toLowerCase()!==e.toLowerCase();t++);if(t===r.KEY_USAGES.length)throw new n.WebCryptoError("Unsuported key usage '"+e+"'. Should be one of ["+r.KEY_USAGES.join(", ")+"]")})},r.generateKey=function(e,r,t){var o=this;return new Promise(function(r,n){o.checkAlgorithm(e),o.checkKeyGenParams(e),o.checkKeyGenUsages(t),r(void 0)})},r.exportKey=function(e,r){var t=this;return new Promise(function(o,n){t.checkKey(r,t.ALG_NAME),t.checkFormat(e,r.type),o(void 0)})},r.importKey=function(e,r,t,o,a){var i=this;return new Promise(function(r,o){if(i.checkImportAlgorithm(t),i.checkFormat(e),"raw"===e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'JsonWebKey', 'pkcs8' or 'spki'");i.checkKeyGenUsages(a),r(void 0)})},r}(a.BaseCrypto);p.ALG_NAME="",p.KEY_USAGES=[],r.Rsa=p;var u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.sign=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","sign"),t(void 0)})},r.verify=function(e,r,t,o){var n=this;return new Promise(function(t,o){n.checkAlgorithmParams(e),n.checkKey(r,n.ALG_NAME,"public","verify"),t(void 0)})},r}(p);u.ALG_NAME=i.AlgorithmNames.RsaSSA,u.KEY_USAGES=["sign","verify"],r.RsaSSA=u;var m=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=4,r}return o(r,e),r}(n.AlgorithmError);r.RsaPSSParamsError=m;var y=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkRsaPssParams=function(r){return e.checkAlgorithmParams.call(this,r),r.saltLength?r.saltLength%8?new m("Parameter 'saltLength' should be a multiple of 8"):void 0:new m(m.PARAM_REQUIRED,"saltLength")},r}(u);y.ALG_NAME=i.AlgorithmNames.RsaPSS,y.KEY_USAGES=["sign","verify"],r.RsaPSS=y;var A=function(e){function r(){var r=e.apply(this,arguments)||this;return r.code=5,r}return o(r,e),r}(n.AlgorithmError);r.RsaOAEPParamsError=A;var l=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithmParams=function(e){if(e.label&&!ArrayBuffer.isView(e.label))return new A(A.PARAM_WRONG_TYPE,"label","ArrayBufferView")},r.encrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"public","encrypt"),t(void 0)})},r.decrypt=function(e,r,t){var o=this;return new Promise(function(t,n){o.checkAlgorithmParams(e),o.checkKey(r,o.ALG_NAME,"private","decrypt"),t(void 0)})},r.wrapKey=function(e,r,t,o){var n=this;return new Promise(function(a,i){n.checkAlgorithmParams(o),n.checkKey(t,n.ALG_NAME,"public","wrapKey"),n.checkWrappedKey(r),n.checkFormat(e,r.type),a(void 0)})},r.unwrapKey=function(e,r,t,o,n,a,i){var s=this;return new Promise(function(r,n){s.checkAlgorithmParams(o),s.checkKey(t,s.ALG_NAME,"private","unwrapKey"),s.checkFormat(e),r(void 0)})},r}(p);l.ALG_NAME=i.AlgorithmNames.RsaOAEP,l.KEY_USAGES=["encrypt","decrypt","wrapKey","unwrapKey"],r.RsaOAEP=l},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=t(11),s=t(8),c=t(9),h=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return o(r,e),r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=c.nativeCrypto.getRandomValues(new Uint8Array(e.length/8)),a=new i.CryptoKey;return a.key=n,a.algorithm=e,a.extractable=r,a.type="secret",a.usages=t,a})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.encrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.encrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){var o;switch(e.name.toUpperCase()){case n.AlgorithmNames.AesCBC:var i=e;o=asmCrypto.AES_CBC.decrypt(t,r.key,void 0,i.iv);break;case n.AlgorithmNames.AesGCM:var s=e;s.tagLength=s.tagLength||128,o=asmCrypto.AES_GCM.decrypt(t,r.key,s.iv,s.additionalData,s.tagLength/8);break;default:throw new a.LinerError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}return o.buffer})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):s.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var c;return Promise.resolve().then(function(){return c=new p.Crypto,c.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(s.buffer2string(new Uint8Array(r))):new Uint8Array(r),c.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){return"A"+e.length+/-(\w+)/i.exec(e.name.toUpperCase())[1]},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){var o=r.key;if("jwk"===e.toLowerCase()){var a={alg:t.alg2jwk(r.algorithm),ext:r.extractable,k:n.Base64Url.encode(o),key_ops:r.usages,kty:"oct"};return a}return o.buffer})},r.importKey=function(e,r,t,o,a){return Promise.resolve().then(function(){var o;if("jwk"===e.toLowerCase()){var s=r;o=n.Base64Url.decode(s.k)}else o=new Uint8Array(r);var c=new i.CryptoKey;return c.algorithm=t,c.type="secret",c.usages=a,c.key=o,c})},r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r}(n.BaseCrypto);r.AesCrypto=h;var p=t(6)},function(e,r,t){"use strict";function o(e){for(var r=new Uint8Array(e),t=[],o=0;o<r.length;o++)t.push(r[o]);return t}function n(e,r){e.length%2&&(e="0"+e);for(var t=new Uint8Array(e.length/2),o=0;o<e.length;o++){var n=e.slice(o,++o+1);t[(o-1)/2]=parseInt(n,16)}if(r){var a=t.length;a=a>32?a>48?66:48:32,t.length<a&&(t=p.concat(new Uint8Array(a-t.length),t))}return t}function a(e,r){for(var t="",o=0;o<e.length;o++){var n=e[o].toString(16);t+=n.length%2?"0"+n:n}if(r){var a=e.length;a=a>32?a>48?66:48:32,t.length/2<a&&(t=new Array(2*a-t.length+1).join("0")+t)}return t}var i=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},s=t(4),c=t(5),h=t(11),p=t(8),u=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return i(r,e),r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var t=e,n=new elliptic.ec(t.namedCurve.replace("-","").toLowerCase()),a=new h.CryptoKey,i=new h.CryptoKey;return a.key=i.key=n.genKeyPair(),a.algorithm=i.algorithm=t,a.extractable=r,i.extractable=!0,a.type="private",i.type="public",e.name===s.AlgorithmNames.EcDSA?(a.usages=["sign"],i.usages=["verify"]):e.name===s.AlgorithmNames.EcDH&&(a.usages=["deriveKey","deriveBits"],i.usages=[]),{privateKey:a,publicKey:i}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){var r=e,o=new m.Crypto;return o.subtle.digest(r.hash,t)}).then(function(e){var t=o(e),i=r.key.sign(t),s=a(i.r.toArray(),!0)+a(i.s.toArray(),!0);return n(s).buffer})},r.verify=function(e,r,t,n){var a;return Promise.resolve().then(function(){var r=e;a={r:t.slice(0,t.byteLength/2),s:t.slice(t.byteLength/2)};var o=new m.Crypto;return o.subtle.digest(r.hash,n)}).then(function(e){var t=o(e);return r.key.verify(t,a)})},r.deriveKey=function(e,r,t,o,n){var a=this;return Promise.resolve().then(function(){return a.deriveBits(e,r,t.length)}).then(function(e){var r=new m.Crypto;return r.subtle.importKey("raw",new Uint8Array(e),t,o,n)})},r.deriveBits=function(e,r,t){return Promise.resolve().then(function(){var o=(Promise.resolve(null),r.key.derive(e.public.key.getPublic())),n=new Uint8Array(o.toArray()),a=n.length;a=a>32?a>48?66:48:32,n.length<a&&(n=p.concat(new Uint8Array(a-n.length),n));var i=n.slice(0,t/8).buffer;return i})},r.exportKey=function(e,r){return Promise.resolve().then(function(){var t=r.key;if("jwk"===e.toLowerCase()){var o=t.getPublic("hex").slice(2),a=o.slice(0,o.length/2),i=o.slice(o.length/2,o.length);if("public"===r.type){var h={crv:r.algorithm.namedCurve,ext:r.extractable,x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}var h={crv:r.algorithm.namedCurve,ext:r.extractable,d:s.Base64Url.encode(n(t.getPrivate("hex"),!0)),x:s.Base64Url.encode(n(a,!0)),y:s.Base64Url.encode(n(i,!0)),key_ops:r.usages,kty:"EC"};return h}throw new c.LinerError("Format '"+e+"' is not implemented")})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var i=new h.CryptoKey;if(i.algorithm=t,"jwk"!==e.toLowerCase())throw new c.LinerError("Format '"+e+"' is not implemented");var u=new elliptic.ec(r.crv.replace("-","").toLowerCase());if(r.d)i.key=u.keyFromPrivate(s.Base64Url.decode(r.d)),i.type="private";else{var m=p.concat(new Uint8Array([4]),s.Base64Url.decode(r.x),s.Base64Url.decode(r.y)),y=a(m);i.key=u.keyFromPublic(y,"hex"),
i.type="public"}return i.extractable=o,i.usages=n,i})},r.checkModule=function(){if("undefined"==typeof elliptic)throw new c.LinerError(c.LinerError.MODULE_NOT_FOUND,"elliptic","https://github.com/indutny/elliptic")},r}(s.BaseCrypto);r.EcCrypto=u;var m=t(6)},function(e,r,t){"use strict";function o(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}o(t(9)),o(t(6))},function(e,r,t){"use strict";function o(e){var r=!0;return e.filter(function(e){return(!r||0!==e)&&(r=!1,!0)})}var n=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},a=t(4),i=t(5),s=t(8),c=t(11),h=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return n(r,e),r.generateKey=function(e,r,t){var o=this;return Promise.resolve().then(function(){o.checkModule();var n=3===e.publicExponent[0]?3:65537,s=asmCrypto.RSA.generateKey(e.modulusLength,n),h=new c.CryptoKey,p=new c.CryptoKey;switch(h.key=p.key=s,h.algorithm=p.algorithm=e,h.extractable=r,p.extractable=!0,h.type="private",p.type="public",e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():h.usages=o.filterUsages(["decrypt","unwrapKey"],t),p.usages=o.filterUsages(["encrypt","wrapKey"],t);break;case a.AlgorithmNames.RsaSSA.toLowerCase():case a.AlgorithmNames.RsaPSS.toLowerCase():h.usages=o.filterUsages(["sign"],t),p.usages=o.filterUsages(["verify"],t);break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}return{privateKey:h,publicKey:p}})},r.sign=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaSSA.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_PKCS1_v1_5_SHA1.sign;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_PKCS1_v1_5_SHA256.sign;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return s(t,r.key).buffer;case a.AlgorithmNames.RsaPSS.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_PSS_SHA1.sign;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_PSS_SHA256.sign;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return s(t,r.key,n.saltLength).buffer;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.verify=function(e,r,t,o){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaSSA.toLowerCase():var n,s=r.algorithm;switch(s.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:n=asmCrypto.RSA_PKCS1_v1_5_SHA1.verify;break;case a.AlgorithmNames.Sha256:n=asmCrypto.RSA_PKCS1_v1_5_SHA256.verify;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return n(t,o,r.key);case a.AlgorithmNames.RsaPSS.toLowerCase():var c=r.algorithm,h=e,p=void 0;switch(c.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:p=asmCrypto.RSA_PSS_SHA1.verify;break;case a.AlgorithmNames.Sha256:p=asmCrypto.RSA_PSS_SHA256.verify;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}return p(t,o,r.key,h.saltLength);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.encrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.encrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.encrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.decrypt=function(e,r,t){return Promise.resolve().then(function(){switch(e.name.toLowerCase()){case a.AlgorithmNames.RsaOAEP.toLowerCase():var o=r.algorithm,n=e,s=void 0;switch(o.hash.name.toUpperCase()){case a.AlgorithmNames.Sha1:s=asmCrypto.RSA_OAEP_SHA1.decrypt;break;case a.AlgorithmNames.Sha256:s=asmCrypto.RSA_OAEP_SHA256.decrypt;break;default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,o.name+" "+o.hash.name)}return s(t,r.key,n.label);default:throw new i.LinerError(i.LinerError.UNSUPPORTED_ALGORITHM,e.name)}})},r.wrapKey=function(e,r,t,o){var n;return Promise.resolve().then(function(){return n=new p.Crypto,n.subtle.exportKey(e,r)}).then(function(e){var r;return r=e instanceof ArrayBuffer?new Uint8Array(e):s.string2buffer(JSON.stringify(e)),n.subtle.encrypt(o,t,r)})},r.unwrapKey=function(e,r,t,o,n,a,i){var c;return Promise.resolve().then(function(){return c=new p.Crypto,c.subtle.decrypt(o,t,r)}).then(function(r){var t;return t="jwk"===e.toLowerCase()?JSON.parse(s.buffer2string(new Uint8Array(r))):new Uint8Array(r),c.subtle.importKey(e,t,n,a,i)})},r.alg2jwk=function(e){var r=e.hash,t=/(\d+)/.exec(r.name)[1];switch(e.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():return"RSA-OAEP"+("1"===t?"":"-"+t);case a.AlgorithmNames.RsaPSS.toUpperCase():return"PS"+t;case a.AlgorithmNames.RsaSSA.toUpperCase():return"RS"+t;default:throw new a.AlgorithmError(a.AlgorithmError.UNSUPPORTED_ALGORITHM,e.name)}},r.jwk2alg=function(e){throw new Error("Not implemented")},r.exportKey=function(e,r){var t=this;return Promise.resolve().then(function(){if("jwk"===e.toLowerCase()){var n={kty:"RSA",ext:!0,key_ops:r.usages};return n.alg=t.alg2jwk(r.algorithm),n.n=a.Base64Url.encode(o(r.key[0])),n.e=a.Base64Url.encode(o(r.key[1])),"private"===r.type&&(n.d=a.Base64Url.encode(o(r.key[2])),n.p=a.Base64Url.encode(o(r.key[3])),n.q=a.Base64Url.encode(o(r.key[4])),n.dp=a.Base64Url.encode(o(r.key[5])),n.dq=a.Base64Url.encode(o(r.key[6])),n.qi=a.Base64Url.encode(o(r.key[7]))),n}throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r.importKey=function(e,r,t,o,n){return Promise.resolve().then(function(){var o,s=new c.CryptoKey;if(s.algorithm=t,s.usages=n,s.key=[],"jwk"===e.toLowerCase())return o=r,s.key[0]=a.Base64Url.decode(o.n),s.key[1]=3===a.Base64Url.decode(o.e)[0]?new Uint8Array([0,0,0,3]):new Uint8Array([0,1,0,1]),o.d?(s.type="private",s.key[2]=a.Base64Url.decode(o.d),s.key[3]=a.Base64Url.decode(o.p),s.key[4]=a.Base64Url.decode(o.q),s.key[5]=a.Base64Url.decode(o.dp),s.key[6]=a.Base64Url.decode(o.dq),s.key[7]=a.Base64Url.decode(o.qi)):s.type="public",s;throw new i.LinerError(i.LinerError.NOT_SUPPORTED)})},r.checkModule=function(){if("undefined"==typeof asmCrypto)throw new i.LinerError(i.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js")},r.filterUsages=function(e,r){return e.filter(function(e){return!!r.filter(function(r){return e===r}).length})},r}(a.BaseCrypto);r.RsaCrypto=h;var p=t(6)},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(4),a=t(5),i=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return o(r,e),r.digest=function(e,r){return Promise.resolve().then(function(){if("undefined"==typeof asmCrypto)throw new a.LinerError(a.LinerError.MODULE_NOT_FOUND,"asmCrypto","https://github.com/vibornoff/asmcrypto.js");switch(e.name.toUpperCase()){case n.AlgorithmNames.Sha1:return asmCrypto.SHA1.bytes(r).buffer;case n.AlgorithmNames.Sha256:return asmCrypto.SHA256.bytes(r).buffer;default:throw new a.LinerError("Not supported algorithm '"+e.name+"'")}})},r}(n.BaseCrypto);r.ShaCrypto=i},function(e,r,t){"use strict";function o(e,r){return Promise.resolve().then(function(){if(e.key)return e;if(e.extractable){var t=new A.Crypto;return t.subtle.exportKey("jwk",e).then(function(t){return r.importKey("jwk",t,e.algorithm,!0,e.usages)})}throw new l.LinerError("'key' is Native CryptoKey. It can't be converted to JS CryptoKey")})}function n(e,r){f.BrowserInfo().name!==f.Browser.IE&&f.BrowserInfo().name!==f.Browser.Edge&&f.BrowserInfo().name!==f.Browser.Safari||!/^rsa/i.test(e.name)||(r.privateKey?(v.push({hash:e.hash,key:r.privateKey}),v.push({hash:e.hash,key:r.publicKey})):v.push({hash:e.hash,key:r}))}function a(e){var r=null;return v.some(function(t){return t.key===e&&(r=f.assign({},e.algorithm,{hash:t.hash}),!0)}),r}function i(e,r){var t=[];e.privateKey?(t.push(e.privateKey),t.push(e.publicKey)):t.push(e),t.forEach(function(e){"keyUsage"in e&&(e.usages=e.keyUsage||[],e.usages.length||(["verify","encrypt","wrapKey"].forEach(function(t){r.indexOf(t)>-1&&("public"===e.type||"secret"===e.type)&&e.usages.push(t)}),["sign","decrypt","unwrapKey","deriveKey","deriveBits"].forEach(function(t){r.indexOf(t)>-1&&("private"===e.type||"secret"===e.type)&&e.usages.push(t)})))})}function s(e,r,t){if(r&&f.BrowserInfo().name===f.Browser.IE){"extractable"in e&&(e.ext=e.extractable,delete e.extractable);var o=null;switch(r.name.toUpperCase()){case p.AlgorithmNames.RsaOAEP.toUpperCase():case p.AlgorithmNames.RsaPSS.toUpperCase():case p.AlgorithmNames.RsaSSA.toUpperCase():o=C.RsaCrypto;break;case p.AlgorithmNames.AesCBC.toUpperCase():case p.AlgorithmNames.AesGCM.toUpperCase():o=w.AesCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,r.name.toUpperCase())}o&&!e.alg&&(e.alg=o.alg2jwk(r)),"key_ops"in e||(e.key_ops=t)}}function c(e){f.BrowserInfo().name===f.Browser.IE&&("ext"in e&&(e.extractable=e.ext,delete e.ext),delete e.key_ops,delete e.alg)}var h=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},p=t(4),u=t(4),m=t(4),y=t(9),A=t(6),l=t(5),f=t(8),w=t(15),g=t(19),C=t(18),E=t(16),v=[],P=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return h(r,e),r.prototype.generateKey=function(r,t,o){var a,s=arguments;return e.prototype.generateKey.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r);try{return y.nativeSubtle.generateKey.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native generateKey for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,o),n(a,e),e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.EcDSA.toLowerCase():case p.AlgorithmNames.EcDH.toLowerCase():r=E.EcCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaSSA.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,a.name.toLowerCase())}return r.generateKey(a,t,o)})},r.prototype.digest=function(r,t){var o,n,a=arguments;return e.prototype.digest.apply(this,a).then(function(e){o=m.PrepareAlgorithm(r),n=m.PrepareData(t,"data");try{return y.nativeSubtle.digest.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native digest for "+o.name+" doesn't work.",e.message||"")}}).then(function(e){return e?e:g.ShaCrypto.digest(o,n)})},r.prototype.sign=function(r,t,n){var i,s,c=arguments;return e.prototype.sign.apply(this,c).then(function(e){i=m.PrepareAlgorithm(r),s=m.PrepareData(n,"data");var o=a(t);o&&(c[0]=f.assign(i,o));try{return y.nativeSubtle.sign.apply(y.nativeSubtle,c).catch(function(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native sign for "+i.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(i.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,i.name.toLowerCase())}return o(t,r).then(function(e){return r.sign(i,e,s)})})},r.prototype.verify=function(r,t,n,i){var s,c,h,u=arguments;return e.prototype.verify.apply(this,u).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareData(n,"data"),h=m.PrepareData(i,"data");var o=a(t);o&&(u[0]=f.assign(s,o));try{return y.nativeSubtle.verify.apply(y.nativeSubtle,u).catch(function(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native verify for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if("boolean"==typeof e)return e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDSA.toLowerCase():r=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,s.name.toLowerCase())}return o(t,r).then(function(e){return r.verify(s,t,c,h)})})},r.prototype.deriveBits=function(r,t,o){var n,a=arguments;return e.prototype.deriveBits.apply(this,a).then(function(e){n=m.PrepareAlgorithm(r);try{return y.nativeSubtle.deriveBits.apply(y.nativeSubtle,a).catch(function(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveBits for "+n.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(n.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=E.EcCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveBits(n,t,o)})},r.prototype.deriveKey=function(r,t,o,n,a){var s,c,h=arguments;return e.prototype.deriveKey.apply(this,h).then(function(e){s=m.PrepareAlgorithm(r),c=m.PrepareAlgorithm(o);try{return y.nativeSubtle.deriveKey.apply(y.nativeSubtle,h).catch(function(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native deriveKey for "+s.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,a),e;var r;switch(s.name.toLowerCase()){case p.AlgorithmNames.EcDH.toLowerCase():r=E.EcCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"deriveBits")}return r.deriveKey(s,t,c,n,a)})},r.prototype.encrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.encrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");try{return y.nativeSubtle.encrypt.apply(y.nativeSubtle,s).catch(function(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'encrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){if(f.BrowserInfo().name===f.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM&&e.ciphertext){var r=new Uint8Array(e.ciphertext.byteLength+e.tag.byteLength),n=0;new Uint8Array(e.ciphertext).forEach(function(e){return r[n++]=e}),new Uint8Array(e.tag).forEach(function(e){return r[n++]=e}),e=r.buffer}return Promise.resolve(e)}var s;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():s=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():s=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,s).then(function(e){return s.encrypt(a,e,i)})})},r.prototype.decrypt=function(r,t,n){var a,i,s=arguments;return e.prototype.decrypt.apply(this,s).then(function(e){a=m.PrepareAlgorithm(r),i=m.PrepareData(n,"data");var o=i;if(f.BrowserInfo().name===f.Browser.IE&&a.name.toUpperCase()===p.AlgorithmNames.AesGCM){var s=i.byteLength-a.tagLength/8;o={ciphertext:i.buffer.slice(0,s),tag:i.buffer.slice(s,i.byteLength)}}try{return y.nativeSubtle.decrypt.call(y.nativeSubtle,a,t,o).catch(function(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'decrypt' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var r;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():r=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():r=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"encrypt")}return o(t,r).then(function(e){return r.decrypt(a,e,i)})})},r.prototype.wrapKey=function(r,t,o,n){var a,i=arguments;return e.prototype.wrapKey.apply(this,i).then(function(e){a=m.PrepareAlgorithm(n);try{return y.nativeSubtle.wrapKey.apply(y.nativeSubtle,i).catch(function(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'wrapKey' for "+a.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return e;var n;switch(a.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():n=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"wrapKey")}return n.wrapKey(r,t,o,a)})},r.prototype.unwrapKey=function(r,t,o,n,a,s,c){var h,u,A,f=arguments;return e.prototype.unwrapKey.apply(this,f).then(function(e){h=m.PrepareAlgorithm(n),u=m.PrepareAlgorithm(a),A=m.PrepareData(t,"wrappedKey");try{return y.nativeSubtle.unwrapKey.apply(y.nativeSubtle,f).catch(function(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'unwrapKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return i(e,c),e;var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.RsaOAEP.toLowerCase():t=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.NOT_SUPPORTED,"unwrapKey")}return t.unwrapKey(r,A,o,h,u,s,c)})},r.prototype.exportKey=function(r,t){var o=arguments;return e.prototype.exportKey.apply(this,o).then(function(){try{return y.nativeSubtle.exportKey.apply(y.nativeSubtle,o).catch(function(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'exportKey' for "+t.algorithm.name+" doesn't work.",e.message||"")}}).then(function(e){if(e){"jwk"===r&&e instanceof ArrayBuffer&&(e=f.buffer2string(new Uint8Array(e)),e=JSON.parse(e));var o=a(t);return o||(o=f.assign({},t.algorithm)),s(e,o,t.usages),Promise.resolve(e)}if(!t.key)throw new l.LinerError("Cannot export native CryptoKey from JS implementation");var n;switch(t.algorithm.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():n=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():n=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():n=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,t.algorithm.name.toLowerCase())}return n.exportKey(r,t)})},r.prototype.importKey=function(r,t,o,a,s){var h,u,A=arguments;return e.prototype.importKey.apply(this,A).then(function(e){h=m.PrepareAlgorithm(o),u=t,f.BrowserInfo().name!==f.Browser.Safari&&f.BrowserInfo().name!==f.Browser.IE||(f.BrowserInfo().name===f.Browser.IE&&(t=f.assign({},t),c(t)),A[1]=f.string2buffer(JSON.stringify(t)).buffer),ArrayBuffer.isView(t)&&(u=m.PrepareData(t,"keyData"));try{return y.nativeSubtle.importKey.apply(y.nativeSubtle,A).catch(function(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")})}catch(e){console.warn("WebCrypto: native 'importKey' for "+h.name+" doesn't work.",e.message||"")}}).then(function(e){if(e)return n(h,e),i(e,s),Promise.resolve(e);var t;switch(h.name.toLowerCase()){case p.AlgorithmNames.AesCBC.toLowerCase():case p.AlgorithmNames.AesGCM.toLowerCase():t=w.AesCrypto;break;case p.AlgorithmNames.EcDH.toLowerCase():case p.AlgorithmNames.EcDSA.toLowerCase():t=E.EcCrypto;break;case p.AlgorithmNames.RsaSSA.toLowerCase():case p.AlgorithmNames.RsaPSS.toLowerCase():case p.AlgorithmNames.RsaOAEP.toLowerCase():t=C.RsaCrypto;break;default:throw new l.LinerError(l.LinerError.UNSUPPORTED_ALGORITHM,h.name.toLowerCase())}return t.importKey(r,u,h,a,s)})},r}(u.SubtleCrypto);r.SubtleCrypto=P,Uint8Array.prototype.forEach||(Uint8Array.prototype.forEach=function(e){for(var r=0;r<this.length;r++)e(this[r],r,this)}),Uint8Array.prototype.slice||(Uint8Array.prototype.slice=function(e,r){return new Uint8Array(this.buffer.slice(e,r))}),Uint8Array.prototype.filter||(Uint8Array.prototype.filter=function(e){for(var r=[],t=0;t<this.length;t++)e(this[t],t,this)&&r.push(this[t]);return new Uint8Array(r)})},function(e,r){(function(e){"use strict";if("undefined"==typeof self){var t=e;t.btoa=function(e){return new Buffer(e,"binary").toString("base64")},t.atob=function(e){return new Buffer(e,"base64").toString("binary")}}var o=function(){function e(){}return e.buffer2string=function(e){for(var r="",t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r},e.string2buffer=function(e){for(var r=new Uint8Array(e.length),t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r},e.encode=function(e){var r=this.buffer2string(e),t=btoa(r).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");return t},e.decode=function(e){for(;e.length%4;)e+="=";var r=e.replace(/\-/g,"+").replace(/_/g,"/");return this.string2buffer(atob(r))},e}();r.Base64Url=o}).call(r,function(){return this}())},function(e,r,t){"use strict";var o=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)},n=t(2),a=t(1),i=t(1),s=t(3),c=t(7),h=t(10),p=t(13),u=function(e){function r(){return e.apply(this,arguments)||this}return o(r,e),r.checkAlgorithm=function(e){if(e.name.toUpperCase()!==this.ALG_NAME.toUpperCase())throw new n.AlgorithmError(n.AlgorithmError.WRONG_ALG_NAME,e.name,this.ALG_NAME)},r.checkDeriveParams=function(e){if(this.checkAlgorithm(e),!e.salt)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"salt");if(!(ArrayBuffer.isView(e.salt)||e.salt instanceof ArrayBuffer))throw new n.AlgorithmError(n.AlgorithmError.PARAM_WRONG_TYPE,"salt","ArrayBuffer or ArrayBufferView");if(!e.iterations)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"iterations");if(!e.hash)throw new n.AlgorithmError(n.AlgorithmError.PARAM_REQUIRED,"hash");var r=a.PrepareAlgorithm(e.hash);c.Sha.checkAlgorithm(r)},r.importKey=function(e,r,t,o,a){var i=this;return Promise.resolve().then(function(){if(o)throw new n.WebCryptoError("KDF keys must set extractable=false");if(i.checkAlgorithm(t),i.checkFormat(e),"raw"!==e.toLowerCase())throw new n.CryptoKeyError(n.CryptoKeyError.ALLOWED_FORMAT,e,"'raw'");i.checkKeyUsages(a)})},r.deriveKey=function(e,r,t,o,a){var c=this;return Promise.resolve().then(function(){switch(c.checkDeriveParams(e),c.checkKey(r,c.ALG_NAME,"secret","deriveKey"),i.BaseCrypto.checkAlgorithm(t),t.name.toUpperCase()){case s.AlgorithmNames.AesCBC:h.AesCBC.checkKeyGenParams(t),h.AesCBC.checkKeyUsages(a);break;case s.AlgorithmNames.AesCTR:h.AesCTR.checkKeyGenParams(t),h.AesCTR.checkKeyUsages(a);break;case s.AlgorithmNames.AesGCM:h.AesGCM.checkKeyGenParams(t),h.AesGCM.checkKeyUsages(a);break;case s.AlgorithmNames.AesKW:h.AesKW.checkKeyGenParams(t),h.AesKW.checkKeyUsages(a);break;case s.AlgorithmNames.Hmac:p.Hmac.checkKeyGenParams(t),p.Hmac.checkKeyUsages(a);break;default:throw new n.AlgorithmError(n.AlgorithmError.UNSUPPORTED_ALGORITHM,t)}})},r.deriveBits=function(e,r,t){var o=this;return Promise.resolve().then(function(){if(o.checkDeriveParams(e),o.checkKey(r,o.ALG_NAME,"secret","deriveBits"),!t||"number"!=typeof t)throw new n.WebCryptoError("Parameter 'length' must be Number and more than 0")})},r}(i.BaseCrypto);u.ALG_NAME=s.AlgorithmNames.Pbkdf2,u.KEY_USAGES=["deriveKey","deriveBits"],r.Pbkdf2=u},function(e,r,t){"use strict";var o=t(2),n=t(1),a=t(3),i=t(7),s=t(14),c=t(10),h=t(12),p=t(13),u=t(22),m=function(){function e(){}return e.prototype.generateKey=function(e,r,t){return new Promise(function(i,u){var m=n.PrepareAlgorithm(e),y=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():y=s.RsaOAEP;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.AesCBC.toUpperCase():y=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():y=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():y=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():y=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():y=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}y.generateKey(m,r,t).then(i,u)})},e.prototype.digest=function(e,r){return new Promise(function(t,s){var c=n.PrepareAlgorithm(e),h=n.PrepareData(r,"data"),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.Sha1.toUpperCase():case a.AlgorithmNames.Sha256.toUpperCase():case a.AlgorithmNames.Sha384.toUpperCase():case a.AlgorithmNames.Sha512.toUpperCase():p=i.Sha;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.digest(c,h).then(t,s)})},e.prototype.sign=function(e,r,t){return new Promise(function(i,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(t,"data"),y=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():y=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():y=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():y=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():y=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}y.sign(u,r,m).then(i,c)})},e.prototype.verify=function(e,r,t,i){return new Promise(function(t,c){var u=n.PrepareAlgorithm(e),m=n.PrepareData(i,"signature"),y=n.PrepareData(i,"data"),A=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():A=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():A=s.RsaPSS;break;case a.AlgorithmNames.EcDSA.toUpperCase():A=h.EcDSA;break;case a.AlgorithmNames.Hmac.toUpperCase():A=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}A.verify(u,r,m,y).then(t,c)})},e.prototype.encrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.encrypt(p,r,u).then(i,h)})},e.prototype.decrypt=function(e,r,t){return new Promise(function(i,h){var p=n.PrepareAlgorithm(e),u=n.PrepareData(t,"data"),m=n.BaseCrypto;switch(p.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,p.name)}m.decrypt(p,r,u).then(i,h)})},e.prototype.deriveBits=function(e,r,t){return new Promise(function(i,s){var c=n.PrepareAlgorithm(e),p=n.BaseCrypto;switch(c.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():p=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():p=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,c.name)}p.deriveBits(c,r,t).then(i,s)})},e.prototype.deriveKey=function(e,r,t,i,s){return new Promise(function(c,p){var m=n.PrepareAlgorithm(e),y=n.PrepareAlgorithm(t),A=n.BaseCrypto;switch(m.name.toUpperCase()){case a.AlgorithmNames.EcDH.toUpperCase():A=h.EcDH;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():A=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,m.name)}A.deriveKey(m,r,y,i,s).then(c,p)})},e.prototype.exportKey=function(e,r){return new Promise(function(t,i){if(n.BaseCrypto.checkKey(r),!r.extractable)throw new o.CryptoKeyError(o.CryptoKeyError.NOT_EXTRACTABLE);var u=n.BaseCrypto;switch(r.algorithm.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():u=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():u=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():u=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():u=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():u=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():u=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():u=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():u=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():u=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():u=p.Hmac;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,r.algorithm.name)}u.exportKey(e,r).then(t,i)})},e.prototype.importKey=function(e,r,t,i,m){return new Promise(function(y,A){var l=n.PrepareAlgorithm(t),f=n.BaseCrypto;switch(l.name.toUpperCase()){case a.AlgorithmNames.RsaSSA.toUpperCase():f=s.RsaSSA;break;case a.AlgorithmNames.RsaPSS.toUpperCase():f=s.RsaPSS;break;case a.AlgorithmNames.RsaOAEP.toUpperCase():f=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():f=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():f=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():f=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():f=c.AesKW;break;case a.AlgorithmNames.EcDSA.toUpperCase():f=h.EcDSA;break;case a.AlgorithmNames.EcDH.toUpperCase():f=h.EcDH;break;case a.AlgorithmNames.Hmac.toUpperCase():f=p.Hmac;break;case a.AlgorithmNames.Pbkdf2.toUpperCase():f=u.Pbkdf2;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,l.name)}f.importKey(e,r,l,i,m).then(y,A)})},e.prototype.wrapKey=function(e,r,t,i){return new Promise(function(h,p){var u=n.PrepareAlgorithm(i),m=n.BaseCrypto;switch(u.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():m=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():m=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():m=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():m=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():m=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,u.name)}m.wrapKey(e,r,t,u).then(h,p)})},e.prototype.unwrapKey=function(e,r,t,i,h,p,u){return new Promise(function(m,y){var A=n.PrepareAlgorithm(i),l=n.PrepareAlgorithm(h),f=n.PrepareData(r,"wrappedKey"),w=n.BaseCrypto;switch(A.name.toUpperCase()){case a.AlgorithmNames.RsaOAEP.toUpperCase():w=s.RsaOAEP;break;case a.AlgorithmNames.AesCBC.toUpperCase():w=c.AesCBC;break;case a.AlgorithmNames.AesCTR.toUpperCase():w=c.AesCTR;break;case a.AlgorithmNames.AesGCM.toUpperCase():w=c.AesGCM;break;case a.AlgorithmNames.AesKW.toUpperCase():w=c.AesKW;break;default:throw new o.AlgorithmError(o.AlgorithmError.UNSUPPORTED_ALGORITHM,A.name)}w.unwrapKey(e,f,t,A,l,p,u).then(m,y)})},e}();r.SubtleCrypto=m},function(e,r){e.exports=require("crypto")}]);
{
"name": "webcrypto-liner",
"version": "0.1.12",
"version": "0.1.13",
"description": "A WebCrypto pollyfill that \"smooths out\" the rough-edges in existing User Agent implementations.",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -12,8 +12,4 @@ import { BaseCrypto, AlgorithmNames, AlgorithmError, Base64Url } from "webcrypto-core";

export class AesCrypto extends BaseCrypto {
protected static checkModule() {
if (typeof asmCrypto === "undefined")
throw new LinerError(LinerError.MODULE_NOT_FOUND, "asmCrypto", "https://github.com/vibornoff/asmcrypto.js");
}
static generateKey(alg: AesKeyGenParams, extractable: boolean, keyUsage: string[]): PromiseLike<CryptoKey> {
public static generateKey(alg: AesKeyGenParams, extractable: boolean, keyUsage: string[]): PromiseLike<CryptoKey> {
return Promise.resolve()

@@ -37,3 +33,3 @@ .then(() => {

static encrypt(algorithm: Algorithm, key: AesCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
public static encrypt(algorithm: Algorithm, key: AesCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
return Promise.resolve()

@@ -44,7 +40,7 @@ .then(() => {

case AlgorithmNames.AesCBC:
let algCBC = algorithm as AesCbcParams;
const algCBC = algorithm as AesCbcParams;
res = asmCrypto.AES_CBC.encrypt(data, key.key, undefined, algCBC.iv) as Uint8Array;
break;
case AlgorithmNames.AesGCM:
let algGCM = algorithm as AesGcmParams;
const algGCM = algorithm as AesGcmParams;
algGCM.tagLength = algGCM.tagLength || 128;

@@ -60,3 +56,3 @@ res = asmCrypto.AES_GCM.encrypt(data, key.key, algGCM.iv, algGCM.additionalData, algGCM.tagLength / 8) as Uint8Array;

static decrypt(algorithm: Algorithm, key: AesCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
public static decrypt(algorithm: Algorithm, key: AesCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
return Promise.resolve()

@@ -68,7 +64,7 @@ .then(() => {

case AlgorithmNames.AesCBC:
let algCBC = algorithm as AesCbcParams;
const algCBC = algorithm as AesCbcParams;
res = asmCrypto.AES_CBC.decrypt(data, key.key, undefined, algCBC.iv) as Uint8Array;
break;
case AlgorithmNames.AesGCM:
let algGCM = algorithm as AesGcmParams;
const algGCM = algorithm as AesGcmParams;
algGCM.tagLength = algGCM.tagLength || 128;

@@ -84,3 +80,3 @@ res = asmCrypto.AES_GCM.decrypt(data, key.key, algGCM.iv, algGCM.additionalData, algGCM.tagLength / 8) as Uint8Array;

static wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): PromiseLike<ArrayBuffer> {
public static wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): PromiseLike<ArrayBuffer> {
let crypto: Crypto;

@@ -97,4 +93,3 @@ return Promise.resolve()

raw = string2buffer(JSON.stringify(data));
}
else {
} else {
// ArrayBuffer

@@ -107,3 +102,3 @@ raw = new Uint8Array(data);

static unwrapKey(format: string, wrappedKey: Uint8Array, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public static unwrapKey(format: string, wrappedKey: Uint8Array, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
let crypto: Crypto;

@@ -116,20 +111,21 @@ return Promise.resolve()

.then((data: any) => {
let _data: any;
if (format.toLowerCase() === "jwk")
_data = JSON.parse(buffer2string(new Uint8Array(data)));
else
_data = new Uint8Array(data);
return crypto.subtle.importKey(format, _data, unwrappedKeyAlgorithm, extractable, keyUsages);
let dataAny: any;
if (format.toLowerCase() === "jwk") {
dataAny = JSON.parse(buffer2string(new Uint8Array(data)));
} else {
dataAny = new Uint8Array(data);
}
return crypto.subtle.importKey(format, dataAny, unwrappedKeyAlgorithm, extractable, keyUsages);
});
}
static alg2jwk(alg: Algorithm): string {
public static alg2jwk(alg: Algorithm): string {
return `A${(alg as AesKeyAlgorithm).length}${/-(\w+)/i.exec(alg.name!.toUpperCase()) ![1]}`;
}
static jwk2alg(alg: string): Algorithm {
public static jwk2alg(alg: string): Algorithm {
throw new Error("Not implemented");
}
static exportKey(format: string, key: AesCryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
public static exportKey(format: string, key: AesCryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
return Promise.resolve()

@@ -139,3 +135,3 @@ .then(() => {

if (format.toLowerCase() === "jwk") {
let jwk: JsonWebKey = {
const jwk: JsonWebKey = {
alg: this.alg2jwk(key.algorithm as Algorithm),

@@ -145,7 +141,6 @@ ext: key.extractable,

key_ops: key.usages,
kty: "oct"
kty: "oct",
};
return jwk;
}
else {
} else {
return raw.buffer;

@@ -156,3 +151,3 @@ }

static importKey(format: string, keyData: JsonWebKey | Uint8Array, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public static importKey(format: string, keyData: JsonWebKey | Uint8Array, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
return Promise.resolve()

@@ -164,5 +159,5 @@ .then(() => {

raw = Base64Url.decode(jwk.k!);
} else {
raw = new Uint8Array(keyData as Uint8Array);
}
else
raw = new Uint8Array(keyData as Uint8Array);
const key = new CryptoKey();

@@ -176,4 +171,11 @@ key.algorithm = algorithm;

}
protected static checkModule() {
if (typeof asmCrypto === "undefined") {
throw new LinerError(LinerError.MODULE_NOT_FOUND, "asmCrypto", "https://github.com/vibornoff/asmcrypto.js");
}
}
}
import { Crypto } from "../crypto";
import { Crypto } from "../crypto";

@@ -6,4 +6,5 @@ import { SubtleCrypto } from "./subtle";

subtle = new SubtleCrypto();
getRandomValues(array: ArrayBufferView): ArrayBufferView {
public subtle = new SubtleCrypto();
public getRandomValues(array: ArrayBufferView): ArrayBufferView {
return nativeCrypto.getRandomValues(array);

@@ -10,0 +11,0 @@ }

@@ -6,5 +6,4 @@ import { BaseCrypto, AlgorithmNames, AlgorithmError, Base64Url } from "webcrypto-core";

// import * as elliptic from "elliptic";
declare let elliptic: any;
declare const elliptic: any;
interface EcCryptoKey extends CryptoKey {

@@ -16,6 +15,8 @@ key: EllipticJS.EllipticKeyPair;

function b2a(buffer: ArrayBuffer | ArrayBufferView) {
let buf = new Uint8Array(buffer as ArrayBuffer);
let res: number[] = [];
for (let i = 0; i < buf.length; i++)
const buf = new Uint8Array(buffer as ArrayBuffer);
const res: number[] = [];
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < buf.length; i++) {
res.push(buf[i]);
}
return res;

@@ -37,4 +38,5 @@ }

len = len > 32 ? len > 48 ? 66 : 48 : 32;
if (res.length < len)
if (res.length < len) {
res = concat(new Uint8Array(len - res.length), res);
}
}

@@ -46,2 +48,3 @@ return res;

let res = "";
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < buffer.length; i++) {

@@ -56,4 +59,5 @@ const char = buffer[i].toString(16);

len = len > 32 ? len > 48 ? 66 : 48 : 32;
if ((res.length / 2) < len)
if ((res.length / 2) < len) {
res = new Array(len * 2 - res.length + 1).join("0") + res;
}
}

@@ -65,13 +69,9 @@

export class EcCrypto extends BaseCrypto {
protected static checkModule() {
if (typeof elliptic === "undefined")
throw new LinerError(LinerError.MODULE_NOT_FOUND, "elliptic", "https://github.com/indutny/elliptic");
}
static generateKey(alg: Algorithm, extractable: boolean, keyUsage: string[]) {
public static generateKey(algorithm: Algorithm, extractable: boolean, keyUsage: string[]) {
return Promise.resolve()
.then(() => {
this.checkModule();
const _alg: EcKeyGenParams = alg as any;
const key = new elliptic.ec(_alg.namedCurve.replace("-", "").toLowerCase()); // converts name to 'p192', ...
const alg: EcKeyGenParams = algorithm as any;
const key = new elliptic.ec(alg.namedCurve.replace("-", "").toLowerCase()); // converts name to 'p192', ...

@@ -82,3 +82,3 @@ // set key params

prvKey.key = pubKey.key = key.genKeyPair();
prvKey.algorithm = pubKey.algorithm = _alg;
prvKey.algorithm = pubKey.algorithm = alg;
prvKey.extractable = extractable;

@@ -88,12 +88,12 @@ pubKey.extractable = true;

pubKey.type = "public";
if (alg.name === AlgorithmNames.EcDSA) {
if (algorithm.name === AlgorithmNames.EcDSA) {
prvKey.usages = ["sign"];
pubKey.usages = ["verify"];
} else if (algorithm.name === AlgorithmNames.EcDH) {
prvKey.usages = ["deriveKey", "deriveBits"];
pubKey.usages = [];
}
else if (alg.name === AlgorithmNames.EcDH) {
prvKey.usages = pubKey.usages = ["deriveKey", "deriveBits"];
}
return {
privateKey: prvKey,
publicKey: pubKey
publicKey: pubKey,
};

@@ -103,12 +103,12 @@ });

static sign(algorithm: Algorithm, key: CryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
public static sign(algorithm: Algorithm, key: CryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
return Promise.resolve()
.then(() => {
const _alg: EcdsaParams = algorithm as any;
const alg: EcdsaParams = algorithm as any;
// get digest
let crypto = new Crypto();
return crypto.subtle.digest(_alg.hash, data);
const crypto = new Crypto();
return crypto.subtle.digest(alg.hash, data);
})
.then(hash => {
.then((hash) => {
const array = b2a(hash);

@@ -121,16 +121,16 @@ const signature = key.key.sign(array);

static verify(algorithm: Algorithm, key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean> {
public static verify(algorithm: Algorithm, key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean> {
let sig: { r: Uint8Array, s: Uint8Array };
return Promise.resolve()
.then(() => {
const _alg: EcdsaParams = algorithm as any;
const alg: EcdsaParams = algorithm as any;
sig = {
r: signature.slice(0, signature.byteLength / 2),
s: signature.slice(signature.byteLength / 2)
s: signature.slice(signature.byteLength / 2),
};
// get digest
let crypto = new Crypto();
return crypto.subtle.digest(_alg.hash, data);
const crypto = new Crypto();
return crypto.subtle.digest(alg.hash, data);
})
.then(hash => {
.then((hash) => {
const array = b2a(hash);

@@ -141,9 +141,9 @@ return (key.key.verify(array, sig));

static deriveKey(algorithm: EcdhKeyDeriveParams, baseKey: CryptoKey, derivedKeyType: AesKeyGenParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public static deriveKey(algorithm: EcdhKeyDeriveParams, baseKey: CryptoKey, derivedKeyType: AesKeyGenParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
return Promise.resolve()
.then(() =>
this.deriveBits(algorithm, baseKey, derivedKeyType.length)
)
this.deriveBits(algorithm, baseKey, derivedKeyType.length),
)
.then((bits: ArrayBuffer) => {
let crypto = new Crypto();
const crypto = new Crypto();
return crypto.subtle.importKey("raw", new Uint8Array(bits), derivedKeyType, extractable, keyUsages);

@@ -153,6 +153,6 @@ });

static deriveBits(algorithm: EcdhKeyDeriveParams, baseKey: CryptoKey, length: number): PromiseLike<ArrayBuffer> {
public static deriveBits(algorithm: EcdhKeyDeriveParams, baseKey: CryptoKey, length: number): PromiseLike<ArrayBuffer> {
return Promise.resolve()
.then(() => {
let promise = (Promise as any).resolve(null);
const promise = (Promise as any).resolve(null);
const shared = baseKey.key.derive((algorithm.public as CryptoKey).key.getPublic());

@@ -163,4 +163,5 @@ let array = new Uint8Array(shared.toArray());

len = (len > 32 ? (len > 48 ? 66 : 48) : 32);
if (array.length < len)
if (array.length < len) {
array = concat(new Uint8Array(len - array.length), array);
}
const buf = array.slice(0, length / 8).buffer;

@@ -171,3 +172,3 @@ return buf;

static exportKey(format: string, key: EcCryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
public static exportKey(format: string, key: EcCryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
return Promise.resolve()

@@ -177,3 +178,3 @@ .then(() => {

if (format.toLowerCase() === "jwk") {
let hexPub = ecKey.getPublic("hex").slice(2); // ignore first '04'
const hexPub = ecKey.getPublic("hex").slice(2); // ignore first '04'
const hexX = hexPub.slice(0, hexPub.length / 2);

@@ -183,3 +184,3 @@ const hexY = hexPub.slice(hexPub.length / 2, hexPub.length);

// public
let jwk: JsonWebKey = {
const jwk: JsonWebKey = {
crv: (key.algorithm as EcKeyGenParams).namedCurve,

@@ -190,9 +191,8 @@ ext: key.extractable,

key_ops: key.usages,
kty: "EC"
kty: "EC",
};
return jwk;
}
else {
} else {
// private
let jwk: JsonWebKey = {
const jwk: JsonWebKey = {
crv: (key.algorithm as EcKeyGenParams).namedCurve,

@@ -204,8 +204,7 @@ ext: key.extractable,

key_ops: key.usages,
kty: "EC"
kty: "EC",
};
return jwk;
}
}
else {
} else {
throw new LinerError(`Format '${format}' is not implemented`);

@@ -216,3 +215,3 @@ }

static importKey(format: string, keyData: JsonWebKey | BufferSource, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public static importKey(format: string, keyData: JsonWebKey | BufferSource, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
return Promise.resolve()

@@ -228,9 +227,8 @@ .then(() => {

key.type = "private";
}
else {
} else {
// Public key
let bufferPubKey = concat(
const bufferPubKey = concat(
new Uint8Array([4]),
Base64Url.decode((keyData as JsonWebKey).x!),
Base64Url.decode((keyData as JsonWebKey).y!)
Base64Url.decode((keyData as JsonWebKey).y!),
);

@@ -242,5 +240,5 @@ const hexPubKey = buffer2hex(bufferPubKey);

}
} else {
throw new LinerError(`Format '${format}' is not implemented`);
}
else
throw new LinerError(`Format '${format}' is not implemented`);
key.extractable = extractable;

@@ -251,4 +249,10 @@ key.usages = keyUsages;

}
protected static checkModule() {
if (typeof elliptic === "undefined") {
throw new LinerError(LinerError.MODULE_NOT_FOUND, "elliptic", "https://github.com/indutny/elliptic");
}
}
}
import { Crypto } from "../crypto";
import { Crypto } from "../crypto";
import { WebCryptoError } from "webcrypto-core";
export class LinerError extends WebCryptoError {
code = 10;
public static MODULE_NOT_FOUND = "Module '%1' is not found. Download it from %2";
public static UNSUPPORTED_ALGORITHM = "Unsupported algorithm '%1'";
static MODULE_NOT_FOUND = "Module '%1' is not found. Download it from %2";
static UNSUPPORTED_ALGORITHM = "Unsupported algorithm '%1'";
}
public code = 10;
}

@@ -13,5 +13,5 @@ export let Browser = {

export function BrowserInfo() {
let res = {
const res = {
name: "",
version: ""
version: "",
};

@@ -44,5 +44,6 @@ const userAgent = self.navigator.userAgent;

export function string2buffer(binaryString: string) {
let res = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++)
const res = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
res[i] = binaryString.charCodeAt(i);
}
return res;

@@ -53,4 +54,6 @@ }

let res = "";
for (let i = 0; i < buffer.length; i++)
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < buffer.length; i++) {
res += String.fromCharCode(buffer[i]);
}
return res;

@@ -60,7 +63,8 @@ }

export function concat(...buf: Uint8Array[]) {
const res = new Uint8Array(buf.map(item => item.length).reduce((prev, cur) => prev + cur));
const res = new Uint8Array(buf.map((item) => item.length).reduce((prev, cur) => prev + cur));
let offset = 0;
buf.forEach((item, index) => {
for (let i = 0; i < item.length; i++)
for (let i = 0; i < item.length; i++) {
res[offset + i] = item[i];
}
offset += item.length;

@@ -72,6 +76,6 @@ });

export function assign(target: any, ...sources: any[]) {
let res = arguments[0];
const res = arguments[0];
for (let i = 1; i < arguments.length; i++) {
let obj = arguments[i];
for (let prop in obj) {
const obj = arguments[i];
for (const prop in obj) {
res[prop] = obj[prop];

@@ -81,2 +85,2 @@ }

return res;
}
}
export * from "./init";
export * from "./crypto";
export * from "./crypto";
import { LinerError } from "./error";
let _w: any;
let w: any;
if (typeof self === "undefined") {
const crypto = require("crypto");
_w = {
w = {
crypto: {
subtle: {},
getRandomValues: (array: ArrayBufferView) => {
let buf = array.buffer;
let uint8buf = new Uint8Array(buf);
const buf = array.buffer;
const uint8buf = new Uint8Array(buf);
const rnd = crypto.randomBytes(uint8buf.length);
rnd.forEach((octet: number, index: number) => uint8buf[index] = octet);
return array;
}
}
},
},
};
} else {
w = self;
}
else
_w = self;
export const nativeCrypto: NativeCrypto = _w.msCrypto || _w.crypto;
export const nativeCrypto: NativeCrypto = w.msCrypto || w.crypto;
export const nativeSubtle: NativeSubtleCrypto = nativeCrypto.subtle || (nativeCrypto as any).webkitSubtle;

@@ -27,8 +27,9 @@

const fn = subtle[name];
// tslint:disable-next-line:only-arrow-functions
subtle[name] = function () {
const _args = arguments;
const args = arguments;
return new Promise((resolve, reject) => {
let op: any = fn.apply(subtle, _args);
const op: any = fn.apply(subtle, args);
op.oncomplete = (e: any) => {
console.log("Complited");
console.log("Completed");
resolve(e.target.result);

@@ -44,5 +45,6 @@ };

if (_w.msCrypto) {
if (!_w.Promise)
if (w.msCrypto) {
if (!w.Promise) {
throw new LinerError(LinerError.MODULE_NOT_FOUND, "Promise", "https://www.promisejs.org");
}
WrapFunction(nativeSubtle, "generateKey");

@@ -63,9 +65,11 @@ WrapFunction(nativeSubtle, "digest");

// fix: Math.imul for IE
if (!(Math as any).imul)
if (!(Math as any).imul) {
// tslint:disable-next-line:only-arrow-functions
(Math as any).imul = function imul(a: number, b: number) {
let ah = (a >>> 16) & 0xffff;
let al = a & 0xffff;
let bh = (b >>> 16) & 0xffff;
let bl = b & 0xffff;
const ah = (a >>> 16) & 0xffff;
const al = a & 0xffff;
const bh = (b >>> 16) & 0xffff;
const bl = b & 0xffff;
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
};
};
}

@@ -7,7 +7,7 @@ export interface CryptoKeyPair extends NativeCryptoKeyPair {

export class CryptoKey implements NativeCryptoKey {
key: any;
algorithm: KeyAlgorithm;
extractable: boolean;
type: string;
usages: string[];
public key: any;
public algorithm: KeyAlgorithm;
public extractable: boolean;
public type: string;
public usages: string[];
}

@@ -7,5 +7,6 @@ import { Crypto, nativeCrypto } from "./index";

if (nativeCrypto)
if (nativeCrypto) {
Object.freeze(nativeCrypto.getRandomValues);
}
export const crypto = new Crypto();
export const crypto = new Crypto();

@@ -1,5 +0,5 @@

import { BaseCrypto, AlgorithmNames, AlgorithmError, Base64Url } from "webcrypto-core";
import { AlgorithmError, AlgorithmNames, Base64Url, BaseCrypto } from "webcrypto-core";
import { LinerError } from "../error";
import { buffer2string, concat, string2buffer } from "../helper";
import { CryptoKey, CryptoKeyPair } from "../key";
import { string2buffer, buffer2string, concat } from "../helper";

@@ -12,6 +12,6 @@ interface RsaCryptoKey extends CryptoKey {

let first = true;
return buf.filter(v => {
if (first && v === 0)
return buf.filter((v) => {
if (first && v === 0) {
return false;
else {
} else {
first = false;

@@ -24,12 +24,4 @@ return true;

export class RsaCrypto extends BaseCrypto {
protected static checkModule() {
if (typeof asmCrypto === "undefined")
throw new LinerError(LinerError.MODULE_NOT_FOUND, "asmCrypto", "https://github.com/vibornoff/asmcrypto.js");
}
static filterUsages(supported: string[], given: string[]): string[] {
return supported.filter(item1 => !!given.filter(item2 => item1 === item2).length);
}
static generateKey(alg: RsaKeyGenParams, extractable: boolean, keyUsage: string[]): PromiseLike<CryptoKeyPair> {
public static generateKey(alg: RsaKeyGenParams, extractable: boolean, keyUsage: string[]): PromiseLike<CryptoKeyPair> {
return Promise.resolve()

@@ -54,2 +46,3 @@ .then(() => {

break;
case AlgorithmNames.RsaSSA.toLowerCase():
case AlgorithmNames.RsaPSS.toLowerCase():

@@ -66,9 +59,25 @@ privateKey.usages = this.filterUsages(["sign"], keyUsage);

static sign(algorithm: Algorithm, key: RsaCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
public static sign(algorithm: Algorithm, key: RsaCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
return Promise.resolve()
.then(() => {
switch (algorithm.name.toLowerCase()) {
case AlgorithmNames.RsaPSS.toLowerCase():
let keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
let _alg: RsaPssParams = algorithm as any;
case AlgorithmNames.RsaSSA.toLowerCase(): {
const keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
const rsaAlg: RsaPssParams = algorithm as any;
let sign: typeof asmCrypto.RSA_PKCS1_v1_5_SHA1.sign;
switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {
case AlgorithmNames.Sha1:
sign = asmCrypto.RSA_PKCS1_v1_5_SHA1.sign;
break;
case AlgorithmNames.Sha256:
sign = asmCrypto.RSA_PKCS1_v1_5_SHA256.sign;
break;
default:
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, key.algorithm.name);
}
return sign(data, key.key).buffer;
}
case AlgorithmNames.RsaPSS.toLowerCase(): {
const keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
const rsaAlg: RsaPssParams = algorithm as any;
let sign: typeof asmCrypto.RSA_PSS_SHA1.sign;

@@ -85,3 +94,4 @@ switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {

}
return sign(data, key.key, _alg.saltLength).buffer;
return sign(data, key.key, rsaAlg.saltLength).buffer;
}
default:

@@ -93,9 +103,25 @@ throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, algorithm.name);

static verify(algorithm: Algorithm, key: RsaCryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean> {
public static verify(algorithm: Algorithm, key: RsaCryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean> {
return Promise.resolve()
.then(() => {
switch (algorithm.name.toLowerCase()) {
case AlgorithmNames.RsaSSA.toLowerCase(): {
const keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
const rsaAlg: RsaPssParams = algorithm as any;
let verify: typeof asmCrypto.RSA_PKCS1_v1_5_SHA1.verify;
switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {
case AlgorithmNames.Sha1:
verify = asmCrypto.RSA_PKCS1_v1_5_SHA1.verify;
break;
case AlgorithmNames.Sha256:
verify = asmCrypto.RSA_PKCS1_v1_5_SHA256.verify;
break;
default:
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, key.algorithm.name);
}
return verify(signature, data, key.key);
}
case AlgorithmNames.RsaPSS.toLowerCase():
let keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
let _alg: RsaPssParams = algorithm as any;
const keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
const rsaAlg: RsaPssParams = algorithm as any;
let verify: typeof asmCrypto.RSA_PSS_SHA1.verify;

@@ -112,3 +138,3 @@ switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {

}
return verify(signature, data, key.key, _alg.saltLength);
return verify(signature, data, key.key, rsaAlg.saltLength);
default:

@@ -120,3 +146,3 @@ throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, algorithm.name);

static encrypt(algorithm: Algorithm, key: RsaCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
public static encrypt(algorithm: Algorithm, key: RsaCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
return Promise.resolve()

@@ -126,4 +152,4 @@ .then(() => {

case AlgorithmNames.RsaOAEP.toLowerCase():
let keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
let _alg: RsaOaepParams = algorithm as any;
const keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
const rsaAlg: RsaOaepParams = algorithm as any;
let encrypt: typeof asmCrypto.RSA_OAEP_SHA1.encrypt;

@@ -140,3 +166,3 @@ switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {

}
return encrypt(data, key.key, _alg.label);
return encrypt(data, key.key, rsaAlg.label);
default:

@@ -148,3 +174,3 @@ throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, algorithm.name);

static decrypt(algorithm: Algorithm, key: RsaCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
public static decrypt(algorithm: Algorithm, key: RsaCryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer> {
return Promise.resolve()

@@ -154,4 +180,4 @@ .then(() => {

case AlgorithmNames.RsaOAEP.toLowerCase():
let keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
let _alg: RsaOaepParams = algorithm as any;
const keyAlg: RsaHashedKeyGenParams = key.algorithm as any;
const rsaAlg: RsaOaepParams = algorithm as any;
let decrypt: typeof asmCrypto.RSA_OAEP_SHA1.decrypt;

@@ -168,3 +194,3 @@ switch ((keyAlg.hash as Algorithm).name.toUpperCase()) {

}
return decrypt(data, key.key, _alg.label);
return decrypt(data, key.key, rsaAlg.label);
default:

@@ -176,3 +202,3 @@ throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, algorithm.name);

static wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): PromiseLike<ArrayBuffer> {
public static wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): PromiseLike<ArrayBuffer> {
let crypto: Crypto;

@@ -189,4 +215,3 @@ return Promise.resolve()

raw = string2buffer(JSON.stringify(data));
}
else {
} else {
// ArrayBuffer

@@ -199,3 +224,3 @@ raw = new Uint8Array(data);

static unwrapKey(format: string, wrappedKey: Uint8Array, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public static unwrapKey(format: string, wrappedKey: Uint8Array, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
let crypto: Crypto;

@@ -208,12 +233,13 @@ return Promise.resolve()

.then((data: any) => {
let _data: any;
if (format.toLowerCase() === "jwk")
_data = JSON.parse(buffer2string(new Uint8Array(data)));
else
_data = new Uint8Array(data);
return crypto.subtle.importKey(format, _data, unwrappedKeyAlgorithm, extractable, keyUsages);
let preparedData: any;
if (format.toLowerCase() === "jwk") {
preparedData = JSON.parse(buffer2string(new Uint8Array(data)));
} else {
preparedData = new Uint8Array(data);
}
return crypto.subtle.importKey(format, preparedData, unwrappedKeyAlgorithm, extractable, keyUsages);
});
}
static alg2jwk(alg: Algorithm) {
public static alg2jwk(alg: Algorithm) {
const hash = (alg as any).hash as Algorithm;

@@ -233,7 +259,7 @@ const hashSize = /(\d+)/.exec(hash.name) ![1];

static jwk2alg(alg: string): Algorithm {
public static jwk2alg(alg: string): Algorithm {
throw new Error("Not implemented");
}
static exportKey(format: string, key: RsaCryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
public static exportKey(format: string, key: RsaCryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
return Promise.resolve()

@@ -245,3 +271,3 @@ .then(() => {

ext: true,
key_ops: key.usages
key_ops: key.usages,
};

@@ -260,4 +286,3 @@ jwk.alg = this.alg2jwk(key.algorithm as Algorithm);

return jwk;
}
else {
} else {
throw new LinerError(LinerError.NOT_SUPPORTED);

@@ -268,34 +293,43 @@ }

static importKey(format: string, keyData: JsonWebKey | Uint8Array, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public static importKey(format: string, keyData: JsonWebKey | Uint8Array, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
return Promise.resolve()
.then(() => {
let raw: Uint8Array;
let jwk: JsonWebKey;
const key = new CryptoKey();
key.algorithm = algorithm;
key.usages = keyUsages;
key.key = [];
if (format.toLowerCase() === "jwk") {
jwk = keyData as JsonWebKey;
key.key[0] = Base64Url.decode(jwk.n!);
key.key[1] = Base64Url.decode(jwk.e!)[0] === 3 ? new Uint8Array([0, 0, 0, 3]) : new Uint8Array([0, 1, 0, 1]);
if (jwk.d) {
key.type = "private";
key.key[2] = Base64Url.decode(jwk.d!);
key.key[3] = Base64Url.decode(jwk.p!);
key.key[4] = Base64Url.decode(jwk.q!);
key.key[5] = Base64Url.decode(jwk.dp!);
key.key[6] = Base64Url.decode(jwk.dq!);
key.key[7] = Base64Url.decode(jwk.qi!);
.then(() => {
let jwk: JsonWebKey;
const key = new CryptoKey();
key.algorithm = algorithm;
key.usages = keyUsages;
key.key = [];
if (format.toLowerCase() === "jwk") {
jwk = keyData as JsonWebKey;
key.key[0] = Base64Url.decode(jwk.n!);
key.key[1] = Base64Url.decode(jwk.e!)[0] === 3 ? new Uint8Array([0, 0, 0, 3]) : new Uint8Array([0, 1, 0, 1]);
if (jwk.d) {
key.type = "private";
key.key[2] = Base64Url.decode(jwk.d!);
key.key[3] = Base64Url.decode(jwk.p!);
key.key[4] = Base64Url.decode(jwk.q!);
key.key[5] = Base64Url.decode(jwk.dp!);
key.key[6] = Base64Url.decode(jwk.dq!);
key.key[7] = Base64Url.decode(jwk.qi!);
} else {
key.type = "public";
}
return key;
} else {
throw new LinerError(LinerError.NOT_SUPPORTED);
}
else
key.type = "public";
return key;
}
else
throw new LinerError(LinerError.NOT_SUPPORTED);
});
});
}
protected static checkModule() {
if (typeof asmCrypto === "undefined") {
throw new LinerError(LinerError.MODULE_NOT_FOUND, "asmCrypto", "https://github.com/vibornoff/asmcrypto.js");
}
}
protected static filterUsages(supported: string[], given: string[]): string[] {
return supported.filter((item1) => !!given.filter((item2) => item1 === item2).length);
}
}
import { Crypto } from "../crypto";
import { Crypto } from "../crypto";

@@ -7,7 +7,9 @@ import { BaseCrypto, AlgorithmNames, AlgorithmError, Base64Url } from "webcrypto-core";

export class ShaCrypto extends BaseCrypto {
static digest(alg: Algorithm, message: Uint8Array) {
public static digest(alg: Algorithm, message: Uint8Array) {
return Promise.resolve()
.then(() => {
if (typeof asmCrypto === "undefined")
if (typeof asmCrypto === "undefined") {
throw new LinerError(LinerError.MODULE_NOT_FOUND, "asmCrypto", "https://github.com/vibornoff/asmcrypto.js");
}
switch (alg.name.toUpperCase()) {

@@ -23,2 +25,2 @@ case AlgorithmNames.Sha1:

}
}
}
import { Crypto, nativeCrypto } from "./index";
let _w = self as any;
const w = self as any;

@@ -9,6 +9,7 @@ Object.freeze(Math);

if (nativeCrypto)
if (nativeCrypto) {
Object.freeze(nativeCrypto.getRandomValues);
}
delete self.crypto;
_w.crypto = new Crypto();
w.crypto = new Crypto();

@@ -8,6 +8,6 @@ // Core

import { nativeSubtle } from "./init";
import { Crypto } from "./crypto";
import { LinerError } from "./error";
import { Crypto } from "./crypto";
import { string2buffer, buffer2string, concat, Browser, BrowserInfo, assign } from "./helper";
import { CryptoKey, CryptoKeyPair } from "./key";
import { string2buffer, buffer2string, concat, Browser, BrowserInfo, assign } from "./helper";

@@ -22,3 +22,3 @@ // Crypto

const keys: { key: CryptoKey, hash: Algorithm }[] = [];
const keys: Array<{ key: CryptoKey, hash: Algorithm }> = [];

@@ -31,13 +31,10 @@ function PrepareKey(key: CryptoKey, subtle: typeof BaseCrypto): PromiseLike<CryptoKey> {

throw new LinerError("'key' is Native CryptoKey. It can't be converted to JS CryptoKey");
}
else {
let crypto = new Crypto();
} else {
const crypto = new Crypto();
return crypto.subtle.exportKey("jwk", key)
.then((jwk: any) =>
subtle.importKey("jwk", jwk, key.algorithm as Algorithm, true, key.usages)
);
.then((jwk: any) => subtle.importKey("jwk", jwk, key.algorithm as Algorithm, true, key.usages));
}
} else {
return key;
}
else
return key;
});

@@ -48,8 +45,8 @@ }

generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<NativeCryptoKey | NativeCryptoKeyPair> {
public generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<NativeCryptoKey | NativeCryptoKeyPair> {
const args = arguments;
let _alg: Algorithm;
let alg: Algorithm;
return super.generateKey.apply(this, args)
.then((d: Uint8Array) => {
_alg = PrepareAlgorithm(algorithm);
alg = PrepareAlgorithm(algorithm);

@@ -59,18 +56,16 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native generateKey for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native generateKey for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native generateKey for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native generateKey for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((keys: CryptoKey | CryptoKeyPair) => {
if (keys) {
FixCryptoKeyUsages(keys, keyUsages);
SetHashAlgorithm(_alg, keys);
return keys;
.then((generatedKeys: CryptoKey | CryptoKeyPair) => {
if (generatedKeys) {
FixCryptoKeyUsages(generatedKeys, keyUsages);
SetHashAlgorithm(alg, generatedKeys);
return generatedKeys;
}
let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.AesCBC.toLowerCase():

@@ -86,19 +81,20 @@ case AlgorithmNames.AesGCM.toLowerCase():

case AlgorithmNames.RsaPSS.toLowerCase():
case AlgorithmNames.RsaSSA.toLowerCase():
Class = RsaCrypto;
break;
default:
throw new LinerError(LinerError.NOT_SUPPORTED, "generateKey");
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, alg.name.toLowerCase());
}
return Class.generateKey(_alg, extractable, keyUsages);
return Class.generateKey(alg, extractable, keyUsages);
});
}
digest(algorithm: AlgorithmIdentifier, data: BufferSource): PromiseLike<ArrayBuffer> {
public digest(algorithm: AlgorithmIdentifier, data: BufferSource): PromiseLike<ArrayBuffer> {
const args = arguments;
let _alg: Algorithm;
let _data: Uint8Array;
let alg: Algorithm;
let dataBytes: Uint8Array;
return super.digest.apply(this, args)
.then((d: Uint8Array) => {
_alg = PrepareAlgorithm(algorithm);
_data = PrepareData(data, "data");
alg = PrepareAlgorithm(algorithm);
dataBytes = PrepareData(data, "data");

@@ -108,27 +104,28 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native digest for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native digest for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native digest for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native digest for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((digest: ArrayBuffer) => {
if (digest) return digest;
return ShaCrypto.digest(_alg, _data);
if (digest) {
return digest;
}
return ShaCrypto.digest(alg, dataBytes);
});
}
sign(algorithm: string | RsaPssParams | EcdsaParams | AesCmacParams, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer> {
public sign(algorithm: string | RsaPssParams | EcdsaParams | AesCmacParams, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer> {
const args = arguments;
let _alg: Algorithm;
let _data: Uint8Array;
let alg: Algorithm;
let dataBytes: Uint8Array;
return super.sign.apply(this, args)
.then((d: Uint8Array) => {
_alg = PrepareAlgorithm(algorithm as string);
_data = PrepareData(data, "data");
alg = PrepareAlgorithm(algorithm as string);
dataBytes = PrepareData(data, "data");
const _alg2 = GetHashAlgorithm(key);
if (_alg2) {
args[0] = assign(_alg, _alg2);
const alg2 = GetHashAlgorithm(key);
if (alg2) {
args[0] = assign(alg, alg2);
}

@@ -138,16 +135,18 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native sign for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native sign for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native sign for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native sign for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((signature: ArrayBuffer) => {
if (signature) return signature;
if (signature) {
return signature;
}
let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.EcDSA.toLowerCase():
Class = EcCrypto;
break;
case AlgorithmNames.RsaSSA.toLowerCase():
case AlgorithmNames.RsaPSS.toLowerCase():

@@ -157,23 +156,23 @@ Class = RsaCrypto;

default:
throw new LinerError(LinerError.NOT_SUPPORTED, "sign");
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, alg.name.toLowerCase());
}
return PrepareKey(key, Class)
.then(key => Class.sign(_alg, key, _data));
.then((preparedKey) => Class.sign(alg, preparedKey, dataBytes));
});
}
verify(algorithm: string | RsaPssParams | EcdsaParams | AesCmacParams, key: CryptoKey, signature: BufferSource, data: BufferSource): PromiseLike<boolean> {
public verify(algorithm: string | RsaPssParams | EcdsaParams | AesCmacParams, key: CryptoKey, signature: BufferSource, data: BufferSource): PromiseLike<boolean> {
const args = arguments;
let _alg: Algorithm;
let _signature: Uint8Array;
let _data: Uint8Array;
let alg: Algorithm;
let signatureBytes: Uint8Array;
let dataBytes: Uint8Array;
return super.verify.apply(this, args)
.then((d: boolean) => {
_alg = PrepareAlgorithm(algorithm as string);
_signature = PrepareData(signature, "data");
_data = PrepareData(data, "data");
alg = PrepareAlgorithm(algorithm as string);
signatureBytes = PrepareData(signature, "data");
dataBytes = PrepareData(data, "data");
const _alg2 = GetHashAlgorithm(key);
if (_alg2) {
args[0] = assign(_alg, _alg2);
const alg2 = GetHashAlgorithm(key);
if (alg2) {
args[0] = assign(alg, alg2);
}

@@ -183,16 +182,18 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native verify for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native verify for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native verify for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native verify for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((result: boolean) => {
if (typeof result === "boolean") return result;
if (typeof result === "boolean") {
return result;
}
let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.EcDSA.toLowerCase():
Class = EcCrypto;
break;
case AlgorithmNames.RsaSSA.toLowerCase():
case AlgorithmNames.RsaPSS.toLowerCase():

@@ -202,15 +203,15 @@ Class = RsaCrypto;

default:
throw new LinerError(LinerError.NOT_SUPPORTED, "sign");
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, alg.name.toLowerCase());
}
return PrepareKey(key, Class)
.then(key => Class.verify(_alg, key, _signature, _data));
.then((preparedKey) => Class.verify(alg, key, signatureBytes, dataBytes));
});
}
deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: number): PromiseLike<ArrayBuffer> {
public deriveBits(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, length: number): PromiseLike<ArrayBuffer> {
const args = arguments;
let _alg: Algorithm;
let alg: Algorithm;
return super.deriveBits.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(algorithm);
alg = PrepareAlgorithm(algorithm);

@@ -220,8 +221,7 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native deriveBits for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native deriveBits for ${alg.name} doesn't work.`, e.message || "");
});
}
catch (e) {
} catch (e) {
// Edge throws error. Don't know Why.
console.warn(`WebCrypto: native deriveBits for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native deriveBits for ${alg.name} doesn't work.`, e.message || "");
}

@@ -231,5 +231,7 @@

.then((bits: ArrayBuffer) => {
if (bits) return bits;
if (bits) {
return bits;
}
let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.EcDH.toLowerCase():

@@ -241,14 +243,14 @@ Class = EcCrypto;

}
return Class.deriveBits(_alg, baseKey, length);
return Class.deriveBits(alg, baseKey, length);
});
}
deriveKey(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, derivedKeyType: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public deriveKey(algorithm: AlgorithmIdentifier, baseKey: CryptoKey, derivedKeyType: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
const args = arguments;
let _alg: Algorithm;
let _algDerivedKey: Algorithm;
let alg: Algorithm;
let algDerivedKey: Algorithm;
return super.deriveKey.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(algorithm);
_algDerivedKey = PrepareAlgorithm(derivedKeyType);
alg = PrepareAlgorithm(algorithm);
algDerivedKey = PrepareAlgorithm(derivedKeyType);

@@ -258,7 +260,7 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native deriveKey for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native deriveKey for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
// Edge doesn't go to catch of Promise
console.warn(`WebCrypto: native deriveKey for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native deriveKey for ${alg.name} doesn't work.`, e.message || "");
}

@@ -272,3 +274,3 @@ })

let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.EcDH.toLowerCase():

@@ -280,14 +282,14 @@ Class = EcCrypto;

}
return Class.deriveKey(_alg, baseKey, _algDerivedKey, extractable, keyUsages);
return Class.deriveKey(alg, baseKey, algDerivedKey, extractable, keyUsages);
});
}
encrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer> {
public encrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer> {
const args = arguments;
let _alg: Algorithm;
let _data: Uint8Array;
let alg: Algorithm;
let dataBytes: Uint8Array;
return super.encrypt.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(algorithm);
_data = PrepareData(data, "data");
alg = PrepareAlgorithm(algorithm);
dataBytes = PrepareData(data, "data");

@@ -297,8 +299,7 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native 'encrypt' for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native 'encrypt' for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native 'encrypt' for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native 'encrypt' for ${_alg.name} doesn't work.`, e.message || "");
}
})

@@ -308,6 +309,6 @@ .then((msg: any) => {

if (BrowserInfo().name === Browser.IE &&
_alg.name.toUpperCase() === AlgorithmNames.AesGCM &&
alg.name.toUpperCase() === AlgorithmNames.AesGCM &&
msg.ciphertext) {
// Concatinate values in IE
let buf = new Uint8Array(msg.ciphertext.byteLength + msg.tag.byteLength);
// Concatenate values in IE
const buf = new Uint8Array(msg.ciphertext.byteLength + msg.tag.byteLength);
let count = 0;

@@ -321,3 +322,3 @@ new Uint8Array(msg.ciphertext).forEach((v: number) => buf[count++] = v);

let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.AesCBC.toLowerCase():

@@ -334,22 +335,23 @@ case AlgorithmNames.AesGCM.toLowerCase():

return PrepareKey(key, Class)
.then(key => Class.encrypt(_alg, key, _data));
.then(preparedKey => Class.encrypt(alg, preparedKey, dataBytes));
});
}
decrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer> {
public decrypt(algorithm: AlgorithmIdentifier, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer> {
const args = arguments;
let _alg: Algorithm;
let _data: Uint8Array;
let alg: Algorithm;
let dataBytes: Uint8Array;
return super.decrypt.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(algorithm);
_data = PrepareData(data, "data");
alg = PrepareAlgorithm(algorithm);
dataBytes = PrepareData(data, "data");
let _data2: any = _data;
let dataBytes2: any = dataBytes;
if (BrowserInfo().name === Browser.IE &&
_alg.name.toUpperCase() === AlgorithmNames.AesGCM) {
alg.name.toUpperCase() === AlgorithmNames.AesGCM) {
// Split buffer
const len = _data.byteLength - ((_alg as any).tagLength / 8);
_data2 = {
ciphertext: _data.buffer.slice(0, len),
tag: _data.buffer.slice(len, _data.byteLength)
const len = dataBytes.byteLength - ((alg as any).tagLength / 8);
dataBytes2 = {
ciphertext: dataBytes.buffer.slice(0, len),
tag: dataBytes.buffer.slice(len, dataBytes.byteLength)
};

@@ -359,15 +361,16 @@ }

try {
return nativeSubtle.decrypt.call(nativeSubtle, _alg, key, _data2)
return nativeSubtle.decrypt.call(nativeSubtle, alg, key, dataBytes2)
.catch((e: Error) => {
console.warn(`WebCrypto: native 'decrypt' for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native 'decrypt' for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native 'decrypt' for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native 'decrypt' for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((msg: ArrayBuffer) => {
if (msg) return msg;
if (msg) {
return msg;
}
let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.AesCBC.toLowerCase():

@@ -384,12 +387,12 @@ case AlgorithmNames.AesGCM.toLowerCase():

return PrepareKey(key, Class)
.then(key => Class.decrypt(_alg, key, _data));
.then((preparedKey) => Class.decrypt(alg, preparedKey, dataBytes));
});
}
wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier): PromiseLike<ArrayBuffer> {
public wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier): PromiseLike<ArrayBuffer> {
const args = arguments;
let _alg: Algorithm;
let alg: Algorithm;
return super.wrapKey.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(wrapAlgorithm);
alg = PrepareAlgorithm(wrapAlgorithm);

@@ -399,13 +402,14 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native 'wrapKey' for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native 'wrapKey' for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native 'wrapKey' for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native 'wrapKey' for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((msg: ArrayBuffer) => {
if (msg) return msg;
if (msg) {
return msg;
}
let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.AesCBC.toLowerCase():

@@ -421,16 +425,16 @@ case AlgorithmNames.AesGCM.toLowerCase():

}
return Class.wrapKey(format, key, wrappingKey, _alg);
return Class.wrapKey(format, key, wrappingKey, alg);
});
}
unwrapKey(format: string, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: AlgorithmIdentifier, unwrappedKeyAlgorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public unwrapKey(format: string, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: AlgorithmIdentifier, unwrappedKeyAlgorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
const args = arguments;
let _alg: Algorithm;
let _algKey: Algorithm;
let _data: Uint8Array;
let alg: Algorithm;
let algKey: Algorithm;
let dataBytes: Uint8Array;
return super.unwrapKey.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(unwrapAlgorithm);
_algKey = PrepareAlgorithm(unwrappedKeyAlgorithm);
_data = PrepareData(wrappedKey, "wrappedKey");
alg = PrepareAlgorithm(unwrapAlgorithm);
algKey = PrepareAlgorithm(unwrappedKeyAlgorithm);
dataBytes = PrepareData(wrappedKey, "wrappedKey");

@@ -440,8 +444,7 @@ try {

.catch((e: Error) => {
console.warn(`WebCrypto: native 'unwrapKey' for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native 'unwrapKey' for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native 'unwrapKey' for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native 'unwrapKey' for ${_alg.name} doesn't work.`, e.message || "");
}
})

@@ -454,3 +457,3 @@ .then((k: CryptoKey) => {

let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.AesCBC.toLowerCase():

@@ -466,7 +469,7 @@ case AlgorithmNames.AesGCM.toLowerCase():

}
return Class.unwrapKey(format, _data, unwrappingKey, _alg, _algKey, extractable, keyUsages);
return Class.unwrapKey(format, dataBytes, unwrappingKey, alg, algKey, extractable, keyUsages);
});
}
exportKey(format: string, key: CryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
public exportKey(format: string, key: CryptoKey): PromiseLike<JsonWebKey | ArrayBuffer> {
const args = arguments;

@@ -480,4 +483,3 @@ return super.exportKey.apply(this, args)

});
}
catch (e) {
} catch (e) {
console.warn(`WebCrypto: native 'exportKey' for ${key.algorithm.name} doesn't work.`, e.message || "");

@@ -493,8 +495,11 @@ }

let alg = GetHashAlgorithm(key);
if (!alg) alg = assign({}, key.algorithm);
if (!alg) {
alg = assign({}, key.algorithm);
}
FixExportJwk(msg, alg, key.usages);
return Promise.resolve(msg);
}
if (!key.key)
if (!key.key) {
throw new LinerError("Cannot export native CryptoKey from JS implementation");
}
let Class: typeof BaseCrypto;

@@ -510,2 +515,3 @@ switch (key.algorithm.name!.toLowerCase()) {

break;
case AlgorithmNames.RsaSSA.toLowerCase():
case AlgorithmNames.RsaPSS.toLowerCase():

@@ -516,3 +522,3 @@ case AlgorithmNames.RsaOAEP.toLowerCase():

default:
throw new LinerError(LinerError.NOT_SUPPORTED, "exportKey");
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, key.algorithm.name!.toLowerCase());
}

@@ -523,10 +529,10 @@ return Class.exportKey(format, key);

importKey(format: string, keyData: JsonWebKey | BufferSource, algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
public importKey(format: string, keyData: JsonWebKey | BufferSource, algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey> {
const args = arguments;
let _alg: Algorithm;
let _data: any;
let alg: Algorithm;
let dataAny: any;
return super.importKey.apply(this, args)
.then((bits: ArrayBuffer) => {
_alg = PrepareAlgorithm(algorithm);
_data = keyData;
alg = PrepareAlgorithm(algorithm);
dataAny = keyData;

@@ -544,3 +550,3 @@ // Fix: Safari

if (ArrayBuffer.isView(keyData)) {
_data = PrepareData(keyData, "keyData");
dataAny = PrepareData(keyData, "keyData");
}

@@ -551,12 +557,11 @@

.catch((e: Error) => {
console.warn(`WebCrypto: native 'importKey' for ${_alg.name} doesn't work.`, e.message || "");
console.warn(`WebCrypto: native 'importKey' for ${alg.name} doesn't work.`, e.message || "");
});
} catch (e) {
console.warn(`WebCrypto: native 'importKey' for ${alg.name} doesn't work.`, e.message || "");
}
catch (e) {
console.warn(`WebCrypto: native 'importKey' for ${_alg.name} doesn't work.`, e.message || "");
}
})
.then((k: CryptoKey) => {
if (k) {
SetHashAlgorithm(_alg, k);
SetHashAlgorithm(alg, k);
FixCryptoKeyUsages(k, keyUsages);

@@ -566,3 +571,3 @@ return Promise.resolve(k);

let Class: typeof BaseCrypto;
switch (_alg.name.toLowerCase()) {
switch (alg.name.toLowerCase()) {
case AlgorithmNames.AesCBC.toLowerCase():

@@ -576,2 +581,3 @@ case AlgorithmNames.AesGCM.toLowerCase():

break;
case AlgorithmNames.RsaSSA.toLowerCase():
case AlgorithmNames.RsaPSS.toLowerCase():

@@ -582,5 +588,5 @@ case AlgorithmNames.RsaOAEP.toLowerCase():

default:
throw new LinerError(LinerError.NOT_SUPPORTED, "importKey");
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, alg.name.toLowerCase());
}
return Class.importKey(format, _data, _alg, extractable, keyUsages);
return Class.importKey(format, dataAny, alg, extractable, keyUsages);
});

@@ -596,5 +602,5 @@ }

keys.push({ hash: (alg as any).hash, key: (key as CryptoKeyPair).publicKey });
} else {
keys.push({ hash: (alg as any).hash, key: key as CryptoKey });
}
else
keys.push({ hash: (alg as any).hash, key: key as CryptoKey });
}

@@ -606,3 +612,3 @@ }

let alg: Algorithm | null = null;
keys.some(item => {
keys.some((item) => {
if (item.key === key) {

@@ -619,2 +625,3 @@ alg = assign({}, key.algorithm, { hash: item.hash });

if (!Uint8Array.prototype.forEach) {
// tslint:disable-next-line:only-arrow-functions
(Uint8Array as any).prototype.forEach = function (cb: (value: number, index: number, array: Uint8Array) => void) {

@@ -627,2 +634,3 @@ for (let i = 0; i < this.length; i++) {

if (!Uint8Array.prototype.slice) {
// tslint:disable-next-line:only-arrow-functions
(Uint8Array as any).prototype.slice = function (start: number, end: number) {

@@ -633,7 +641,9 @@ return new Uint8Array(this.buffer.slice(start, end));

if (!Uint8Array.prototype.filter) {
// tslint:disable-next-line:only-arrow-functions
(Uint8Array as any).prototype.filter = function (cb: (value: number, index: number, array: Uint8Array) => void) {
let buf: number[] = [];
const buf: number[] = [];
for (let i = 0; i < this.length; i++) {
if (cb(this[i], i, this))
if (cb(this[i], i, this)) {
buf.push(this[i]);
}
}

@@ -645,11 +655,10 @@ return new Uint8Array(buf);

function FixCryptoKeyUsages(key: CryptoKey | CryptoKeyPair, keyUsages: string[]) {
const keys: CryptoKey[] = [];
const keyArray: CryptoKey[] = [];
if ((key as CryptoKeyPair).privateKey) {
keys.push((key as CryptoKeyPair).privateKey);
keys.push((key as CryptoKeyPair).publicKey);
keyArray.push((key as CryptoKeyPair).privateKey);
keyArray.push((key as CryptoKeyPair).publicKey);
} else {
keyArray.push(key as CryptoKey);
}
else {
keys.push(key as CryptoKey);
}
keys.forEach((k: any) => {
keyArray.forEach((k: any) => {
if ("keyUsage" in k) {

@@ -660,10 +669,12 @@ k.usages = k.keyUsage || [];

["verify", "encrypt", "wrapKey"]
.forEach(usage => {
if (keyUsages.indexOf(usage) > -1 && (k.type === "public" || k.type === "secret"))
.forEach((usage) => {
if (keyUsages.indexOf(usage) > -1 && (k.type === "public" || k.type === "secret")) {
k.usages.push(usage);
}
});
["sign", "decrypt", "unwrapKey", "deriveKey", "deriveBits"]
.forEach(usage => {
if (keyUsages.indexOf(usage) > -1 && (k.type === "private" || k.type === "secret"))
.forEach((usage) => {
if (keyUsages.indexOf(usage) > -1 && (k.type === "private" || k.type === "secret")) {
k.usages.push(usage);
}
});

@@ -694,2 +705,4 @@ }

break;
default:
throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, alg.name.toUpperCase());
}

@@ -702,4 +715,5 @@

// add key_ops
if (!("key_ops" in jwk))
if (!("key_ops" in jwk)) {
jwk.key_ops = keyUsages;
}
}

@@ -718,2 +732,2 @@ }

}
}
}

@@ -35,2 +35,8 @@ /**

class RSA_PKCS1_v1_5_SHA1 {
static sign(data: BufferSource, key: RsaKey): ArrayBufferView;
static verify(signature: BufferSource, data: BufferSource, key: RsaKey): boolean;
}
class RSA_PKCS1_v1_5_SHA256 extends RSA_PKCS1_v1_5_SHA1 { }
class RSA_PSS_SHA1 {

@@ -37,0 +43,0 @@ static sign(data: BufferSource, key: RsaKey, saltLength?: number): ArrayBufferView;

@@ -13,3 +13,3 @@ "use strict";

["RSA-PSS", "RSA-OAEP"].forEach(name =>
["RSA-PSS", "RSA-OAEP", "RSASSA-PKCS1-v1_5"].forEach(name =>
[1024].forEach(modulusLength => {

@@ -21,3 +21,3 @@ [new Uint8Array([3]), new Uint8Array([1, 0, 1])].forEach(publicExponent => {

algorithm: { name, modulusLength, publicExponent, hash },
usages: name === "RSA-PSS" ? ["sign", "verify"] : ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
usages: name !== "RSA-OAEP" ? ["sign", "verify"] : ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
})

@@ -133,3 +133,3 @@ })

context("sign/verify", () =>
context("sign/verify", () => {
keys.filter(key => key.algorithm.name === "RSA-PSS").forEach(key =>

@@ -158,5 +158,25 @@ ["native", "js"].forEach(type =>

)
)
keys.filter(key => key.algorithm.name === "RSASSA-PKCS1-v1_5").forEach(key =>
["native", "js"].forEach(type =>
it(`${key.name} type:${type}`, done => {
const revType = type === "native" ? "js" : "native";
const data = crypto.getRandomValues(new Uint8Array(16));
let alg = { name: key.algorithm.name };
subtle[type].sign(alg, key[type].privateKey, data)
.then(signature => {
assert.equal(!!signature, true);
return subtle[revType].verify(alg, key[revType].publicKey, signature, data);
})
.then(verify => {
assert.equal(verify, true);
done();
})
.catch(done);
})
)
)
})
});
}
{
"extends": [
"tslint:recommended"
],
"rules": {
"class-name": true,
"comment-format": [
true,
"check-space"
"interface-name": [
false
],
"indent": [
true,
"spaces"
"prefer-const": true,
"no-var-requires": false,
"object-literal-sort-keys": false,
"ordered-imports": [
false
],
"no-duplicate-variable": true,
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
"no-bitwise": false,
"forin": false,
"max-line-length": [
false
],
"quotemark": [
true,
"double"
"max-classes-per-file": [
false
],
"semicolon": [
true,
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
"no-console": [
false
]
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc