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