jose-jwe-jws
Version:
Library to encrypt and decrypt data in JSON Web Encryption (JWE) format and to sign data in JSON Web Signature (JWS) format. Leverages Browser's native web crypto API.
8 lines • 49.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Jose=e():t.Jose=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){"use strict";r.r(e),r.d(e,"importPublicKey",function(){return u}),r.d(e,"importPrivateKey",function(){return s}),r.d(e,"importEcPublicKey",function(){return f}),r.d(e,"importEcPrivateKey",function(){return c}),r.d(e,"importRsaPublicKey",function(){return h}),r.d(e,"importRsaPrivateKey",function(){return y}),r.d(e,"isString",function(){return p}),r.d(e,"arrayish",function(){return l}),r.d(e,"convertRsaKey",function(){return g}),r.d(e,"arrayFromString",function(){return d}),r.d(e,"arrayFromUtf8String",function(){return v}),r.d(e,"stringFromArray",function(){return m}),r.d(e,"utf8StringFromArray",function(){return w}),r.d(e,"stripLeadingZeros",function(){return S}),r.d(e,"arrayFromInt32",function(){return b}),r.d(e,"arrayBufferConcat",function(){return A}),r.d(e,"sha256",function(){return E}),r.d(e,"isCryptoKey",function(){return _}),r.d(e,"Base64Url",function(){return P});var n=r(2),i=r(1);function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var a=new n.a,u=function(t,e){switch(e){case"RS256":case"RS384":case"RS512":case"PS256":case"PS384":case"PS512":return h(t,e);case"ES256":case"ES384":case"ES512":return f(t,e);default:throw Error("unsupported algorithm: "+e)}},s=function(t,e){switch(e){case"RS256":case"RS384":case"RS512":case"PS256":case"PS384":case"PS512":return y(t,e);case"ES256":case"ES384":case"ES512":return c(t,e);default:throw Error("unsupported algorithm: "+e)}},f=function(t,e){var r=a.getSignConfig(e),n=a.getKeyUsageByAlg(e);return i.Jose.crypto.subtle.importKey("jwk",t,r.id,!1,[n.publicKey])},c=function(t,e){var r=a.getSignConfig(e),n=a.getKeyUsageByAlg(e);return i.Jose.crypto.subtle.importKey("jwk",t,r.id,!1,[n.privateKey])},h=function(t,e){var r,n,o=a.getKeyUsageByAlg(e);if("wrapKey"===o.publicKey)t.alg||(t.alg=e),r=g(t,["n","e"]),n=a.getCryptoConfig(e);else{var u={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(u[s]=t[s]);!u.alg&&e&&(u.alg=e),n=a.getSignConfig(u.alg),(r=g(u,["n","e"])).ext=!0}return i.Jose.crypto.subtle.importKey("jwk",r,n.id,!1,[o.publicKey])},y=function(t,e){var r,n,o=a.getKeyUsageByAlg(e);if("unwrapKey"===o.privateKey)t.alg||(t.alg=e),r=g(t,["n","e","d","p","q","dp","dq","qi"]),n=a.getCryptoConfig(e);else{var u={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(u[s]=t[s]);n=a.getSignConfig(e),!u.alg&&e&&(u.alg=e),(r=g(u,["n","e","d","p","q","dp","dq","qi"])).ext=!0}return i.Jose.crypto.subtle.importKey("jwk",r,n.id,!1,[o.privateKey])},p=function(t){return"string"==typeof t||t instanceof String},l=function(t){return t instanceof Array?t:t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):void a.assert(!1,"arrayish: invalid input")},g=function(t,e){var r,n={},i=[];e.map(function(e){void 0===t[e]&&i.push(e)}),i.length>0&&a.assert(!1,"convertRsaKey: Was expecting "+i.join()),void 0!==t.kty&&a.assert("RSA"===t.kty,"convertRsaKey: expecting rsaKey['kty'] to be 'RSA'"),n.kty="RSA";try{a.getSignConfig(t.alg),r=t.alg}catch(e){try{a.getCryptoConfig(t.alg),r=t.alg}catch(t){a.assert(r,"convertRsaKey: expecting rsaKey['alg'] to have a valid value")}}n.alg=r;for(var o=function(t){return parseInt(t,16)},u=0;u<e.length;u++){var s=e[u],f=t[s],c=new P;if("e"===s)"number"==typeof f&&(f=c.encodeArray(S(b(f))));else if(/^([0-9a-fA-F]{2}:)+[0-9a-fA-F]{2}$/.test(f)){var h=f.split(":").map(o);f=c.encodeArray(S(h))}else"string"!=typeof f&&a.assert(!1,"convertRsaKey: expecting rsaKey['"+s+"'] to be a string");n[s]=f}return n},d=function(t){a.assert(p(t),"arrayFromString: invalid input");var e=t.split("").map(function(t){return t.charCodeAt(0)});return new Uint8Array(e)},v=function(t){return a.assert(p(t),"arrayFromUtf8String: invalid input"),t=unescape(encodeURIComponent(t)),d(t)},m=function(t){t=l(t);for(var e="",r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},w=function(t){a.assert(t instanceof ArrayBuffer,"utf8StringFromArray: invalid input");var e=m(t);return decodeURIComponent(escape(e))},S=function(t){t instanceof ArrayBuffer&&(t=new Uint8Array(t));for(var e=!0,r=[],n=0;n<t.length;n++)e&&0===t[n]||(e=!1,r.push(t[n]));return r},b=function(t){a.assert("number"==typeof t,"arrayFromInt32: invalid input"),a.assert(t==t|0,"arrayFromInt32: out of range");for(var e=new Uint8Array(new Uint32Array([t]).buffer),r=new Uint8Array(4),n=0;n<4;n++)r[n]=e[3-n];return r.buffer};function A(){for(var t=[],e=0,r=0;r<arguments.length;r++)t.push(l(arguments[r])),e+=t[r].length;var n=new Uint8Array(e),i=0;for(r=0;r<arguments.length;r++)for(var o=0;o<t[r].length;o++)n[i++]=t[r][o];return a.assert(i===e,"arrayBufferConcat: unexpected offset"),n}var E=function(t){return i.Jose.crypto.subtle.digest({name:"SHA-256"},d(t)).then(function(t){return(new P).encodeArray(t)})},_=function(t){return"CryptoKey"===t.constructor.name||!!Object.prototype.hasOwnProperty.call(t,"algorithm")},P=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}var e,r,n;return e=t,(r=[{key:"encode",value:function(t){return a.assert(p(t),"Base64Url.encode: invalid input"),btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}},{key:"encodeArray",value:function(t){return this.encode(m(t))}},{key:"decode",value:function(t){return a.assert(p(t),"Base64Url.decode: invalid input"),atob(t.replace(/-/g,"+").replace(/_/g,"/"))}},{key:"decodeArray",value:function(t){return a.assert(p(t),"Base64Url.decodeArray: invalid input"),d(this.decode(t))}}])&&o(e.prototype,r),n&&o(e,n),t}()},function(t,e,r){"use strict";r.r(e),function(t,n){r.d(e,"crypto",function(){return i}),r.d(e,"Utils",function(){return y}),r.d(e,"setCrypto",function(){return g}),r.d(e,"Jose",function(){return d}),r.d(e,"JoseJWE",function(){return p}),r.d(e,"JoseJWS",function(){return l}),r.d(e,"caniuse",function(){return v});var i,o=r(0),a=r(4),u=r(5),s=r(6),f=r(7),c=r(2);function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}r.d(e,"WebCryptographer",function(){return c.a});var y=o,p={Encrypter:a.a,Decrypter:u.a},l={Signer:s.a,Verifier:f.a},g=function(t){i=t};"undefined"!=typeof window&&void 0!==window.crypto&&(g(window.crypto),i.subtle||(i.subtle=i.webkitSubtle));var d={JoseJWS:l,JoseJWE:p,WebCryptographer:c.a,crypto:i,Utils:y};e.default={Jose:d,WebCryptographer:c.a},"function"!=typeof atob&&(atob=function(e){return t.from(e,"base64").toString("binary")}),"function"!=typeof btoa&&(btoa=function(e){return(e instanceof t?e:t.from(e.toString(),"binary")).toString("base64")});var v=function(){var t=!0;t=(t=(t=(t=t&&"function"==typeof Promise)&&"function"==typeof Promise.reject)&&"function"==typeof Promise.prototype.then)&&"function"==typeof Promise.all;var e=window||n;return t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=t&&"object"===h(e.crypto))&&"object"===h(e.crypto.subtle))&&"function"==typeof e.crypto.getRandomValues)&&"function"==typeof e.crypto.subtle.importKey)&&"function"==typeof e.crypto.subtle.generateKey)&&"function"==typeof e.crypto.subtle.exportKey)&&"function"==typeof e.crypto.subtle.wrapKey)&&"function"==typeof e.crypto.subtle.unwrapKey)&&"function"==typeof e.crypto.subtle.encrypt)&&"function"==typeof e.crypto.subtle.decrypt)&&"function"==typeof e.crypto.subtle.sign)&&"function"==typeof ArrayBuffer)&&("function"==typeof Uint8Array||"object"===("undefined"==typeof Uint8Array?"undefined":h(Uint8Array))))&&("function"==typeof Uint32Array||"object"===("undefined"==typeof Uint32Array?"undefined":h(Uint32Array))))&&"object"===("undefined"==typeof JSON?"undefined":h(JSON)))&&"function"==typeof JSON.parse)&&"function"==typeof JSON.stringify)&&"function"==typeof atob)&&"function"==typeof btoa}}.call(this,r(8).Buffer,r(3))},function(t,e,r){"use strict";r.d(e,"a",function(){return a});var n=r(0),i=r(1);function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var a=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.setKeyEncryptionAlgorithm("RSA-OAEP"),this.setContentEncryptionAlgorithm("A256GCM"),this.setContentSignAlgorithm("RS256")}var e,r,a;return e=t,(r=[{key:"setKeyEncryptionAlgorithm",value:function(t){this.keyEncryption=this.getCryptoConfig(t)}},{key:"getKeyEncryptionAlgorithm",value:function(){return this.keyEncryption.jweName}},{key:"setContentEncryptionAlgorithm",value:function(t){this.content_encryption=this.getCryptoConfig(t)}},{key:"getContentEncryptionAlgorithm",value:function(){return this.content_encryption.jweName}},{key:"setContentSignAlgorithm",value:function(t){this.content_sign=this.getSignConfig(t)}},{key:"getContentSignAlgorithm",value:function(){return this.content_sign.jwa_name}},{key:"createIV",value:function(){var t=new Uint8Array(new Array(this.content_encryption.iv_bytes));return i.Jose.crypto.getRandomValues(t)}},{key:"createCek",value:function(){var t=this.getCekWorkaround(this.content_encryption);return i.Jose.crypto.subtle.generateKey(t.id,!0,t.enc_op)}},{key:"wrapCek",value:function(t,e){return i.Jose.crypto.subtle.wrapKey("raw",t,e,this.keyEncryption.id)}},{key:"unwrapCek",value:function(t,e){var r=this.getCekWorkaround(this.content_encryption),n=this.content_encryption.specific_cekBytes>0,o=this.keyEncryption.id;return i.Jose.crypto.subtle.unwrapKey("raw",t,e,o,r.id,n,r.dec_op)}},{key:"getCekWorkaround",value:function(t){var e=t.specific_cekBytes;if(e){if(16===e)return{id:{name:"AES-CBC",length:128},enc_op:["encrypt"],dec_op:["decrypt"]};if(32===e)return{id:{name:"AES-CBC",length:256},enc_op:["encrypt"],dec_op:["decrypt"]};if(64===e)return{id:{name:"HMAC",hash:{name:"SHA-256"}},enc_op:["sign"],dec_op:["verify"]};if(128===e)return{id:{name:"HMAC",hash:{name:"SHA-384"}},enc_op:["sign"],dec_op:["verify"]};this.assert(!1,"getCekWorkaround: invalid len")}return{id:t.id,enc_op:["encrypt"],dec_op:["decrypt"]}}},{key:"encrypt",value:function(t,e,r,n){var o=this,a=this.content_encryption;if(t.length!==a.iv_bytes)return Promise.reject(Error("invalid IV length"));if(a.auth.aead){var u=a.auth.tagBytes,s={name:a.id.name,iv:t,additionalData:e,tagLength:8*u};return r.then(function(t){return i.Jose.crypto.subtle.encrypt(s,t,n).then(function(t){var e=t.byteLength-u;return{cipher:t.slice(0,e),tag:t.slice(e)}})})}var f=this.splitKey(a,r,["encrypt"]),c=f[0],h=f[1].then(function(e){var r={name:a.id.name,iv:t};return i.Jose.crypto.subtle.encrypt(r,e,n)}),y=h.then(function(r){return o.truncatedMac(a,c,e,t,r)});return Promise.all([h,y]).then(function(t){return{cipher:t[0],tag:t[1]}})}},{key:"compare",value:function(t,e,r,n){return this.assert(r instanceof Uint8Array,"compare: invalid input"),this.assert(n instanceof Uint8Array,"compare: invalid input"),e.then(function(e){var o=i.Jose.crypto.subtle.sign(t.auth.id,e,r),a=i.Jose.crypto.subtle.sign(t.auth.id,e,n);return Promise.all([o,a]).then(function(t){var e=new Uint8Array(t[0]),r=new Uint8Array(t[1]);if(e.length!==r.length)throw new Error("compare failed");for(var n=0;n<e.length;n++)if(e[n]!==r[n])throw new Error("compare failed");return Promise.resolve(null)})})}},{key:"decrypt",value:function(t,e,r,o,a){var u=this;if(r.length!==this.content_encryption.iv_bytes)return Promise.reject(Error("decryptCiphertext: invalid IV"));var s=this.content_encryption;if(s.auth.aead){var f={name:s.id.name,iv:r,additionalData:e,tagLength:8*s.auth.tagBytes};return t.then(function(t){var e=n.arrayBufferConcat(o,a);return i.Jose.crypto.subtle.decrypt(f,t,e)})}var c=this.splitKey(s,t,["decrypt"]),h=c[0],y=c[1],p=this.truncatedMac(s,h,e,r,o);return Promise.all([y,p]).then(function(t){var e=t[0],n=t[1];return u.compare(s,h,new Uint8Array(n),a).then(function(){var t={name:s.id.name,iv:r};return i.Jose.crypto.subtle.decrypt(t,e,o)}).catch(function(){return Promise.reject(Error("decryptCiphertext: MAC failed."))})})}},{key:"sign",value:function(t,e,r){var o=this.content_sign;return t.alg&&(o=this.getSignConfig(t.alg)),r.then(function(r){var a=new n.Base64Url;return i.Jose.crypto.subtle.sign(o.id,r,n.arrayFromString(a.encode(JSON.stringify(t))+"."+a.encodeArray(e)))})}},{key:"verify",value:function(t,e,r,o,a){var u=this.content_sign;return o.then(function(o){return i.Jose.crypto.subtle.verify(u.id,o,r,n.arrayFromString(t+"."+e)).then(function(t){return{kid:a,verified:t}})})}},{key:"keyId",value:function(t){return n.sha256(t.n+"+"+t.d)}},{key:"splitKey",value:function(t,e,r){var n=e.then(function(t){return i.Jose.crypto.subtle.exportKey("raw",t)});return[n.then(function(e){if(8*e.byteLength!==t.id.length+8*t.auth.key_bytes)return Promise.reject(Error("encryptPlainText: incorrect cek length"));var r=e.slice(0,t.auth.key_bytes);return i.Jose.crypto.subtle.importKey("raw",r,t.auth.id,!1,["sign"])}),n.then(function(e){if(8*e.byteLength!==t.id.length+8*t.auth.key_bytes)return Promise.reject(Error("encryptPlainText: incorrect cek length"));var n=e.slice(t.auth.key_bytes);return i.Jose.crypto.subtle.importKey("raw",n,t.id,!1,r)})]}},{key:"getCryptoConfig",value:function(t){switch(t){case"RSA-OAEP":return{jweName:"RSA-OAEP",id:{name:"RSA-OAEP",hash:{name:"SHA-1"}}};case"RSA-OAEP-256":return{jweName:"RSA-OAEP-256",id:{name:"RSA-OAEP",hash:{name:"SHA-256"}}};case"A128KW":return{jweName:"A128KW",id:{name:"AES-KW",length:128}};case"A256KW":return{jweName:"A256KW",id:{name:"AES-KW",length:256}};case"dir":return{jweName:"dir"};case"A128CBC-HS256":return{jweName:"A128CBC-HS256",id:{name:"AES-CBC",length:128},iv_bytes:16,specific_cekBytes:32,auth:{key_bytes:16,id:{name:"HMAC",hash:{name:"SHA-256"}},truncated_bytes:16}};case"A256CBC-HS512":return{jweName:"A256CBC-HS512",id:{name:"AES-CBC",length:256},iv_bytes:16,specific_cekBytes:64,auth:{key_bytes:32,id:{name:"HMAC",hash:{name:"SHA-512"}},truncated_bytes:32}};case"A128GCM":return{jweName:"A128GCM",id:{name:"AES-GCM",length:128},iv_bytes:12,auth:{aead:!0,tagBytes:16}};case"A256GCM":return{jweName:"A256GCM",id:{name:"AES-GCM",length:256},iv_bytes:12,auth:{aead:!0,tagBytes:16}};default:throw Error("unsupported algorithm: "+t)}}},{key:"truncatedMac",value:function(t,e,r,o,a){return e.then(function(e){var u=new Uint8Array(n.arrayFromInt32(8*r.length)),s=new Uint8Array(8);s.set(u,4);var f=n.arrayBufferConcat(r,o,a,s);return i.Jose.crypto.subtle.sign(t.auth.id,e,f).then(function(e){return e.slice(0,t.auth.truncated_bytes)})})}},{key:"getSignConfig",value:function(t){switch(t){case"RS256":return{jwa_name:"RS256",id:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}}};case"RS384":return{jwa_name:"RS384",id:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}}};case"RS512":return{jwa_name:"RS512",id:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}}};case"PS256":return{jwa_name:"PS256",id:{name:"RSA-PSS",hash:{name:"SHA-256"},saltLength:20}};case"PS384":return{jwa_name:"PS384",id:{name:"RSA-PSS",hash:{name:"SHA-384"},saltLength:20}};case"PS512":return{jwa_name:"PS512",id:{name:"RSA-PSS",hash:{name:"SHA-512"},saltLength:20}};case"HS256":return{jwa_name:"HS256",id:{name:"HMAC",hash:{name:"SHA-256"}}};case"HS384":return{jwa_name:"HS384",id:{name:"HMAC",hash:{name:"SHA-384"}}};case"HS512":return{jwa_name:"HS512",id:{name:"HMAC",hash:{name:"SHA-512"}}};case"ES256":return{jwa_name:"ES256",id:{name:"ECDSA",namedCurve:"P-256",hash:{name:"SHA-256"}}};case"ES384":return{jwa_name:"ES384",id:{name:"ECDSA",namedCurve:"P-384",hash:{name:"SHA-384"}}};case"ES512":return{jwa_name:"ES512",id:{name:"ECDSA",namedCurve:"P-521",hash:{name:"SHA-512"}}};default:throw Error("unsupported algorithm: "+t)}}},{key:"getKeyUsageByAlg",value:function(t){switch(t){case"RS256":case"RS384":case"RS512":case"PS256":case"PS384":case"PS512":case"HS256":case"HS384":case"HS512":case"ES256":case"ES384":case"ES512":case"ES256K":return{publicKey:"verify",privateKey:"sign"};case"RSA-OAEP":case"RSA-OAEP-256":case"A128KW":case"A256KW":return{publicKey:"wrapKey",privateKey:"unwrapKey"};default:throw Error("unsupported algorithm: "+t)}}},{key:"assert",value:function(t,e){if(!t)throw new Error(e)}}])&&o(e.prototype,r),a&&o(e,a),t}()},function(t,e){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"===("undefined"==typeof window?"undefined":r(window))&&(n=window)}t.exports=n},function(t,e,r){"use strict";r.d(e,"a",function(){return o});var n=r(0);function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var o=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.cryptographer=e,this.keyPromise=r,this.userHeaders={}}var e,r,o;return e=t,(r=[{key:"addHeader",value:function(t,e){this.userHeaders[t]=e}},{key:"encrypt",value:function(t){var e,r;"dir"===this.cryptographer.getKeyEncryptionAlgorithm()?(e=Promise.resolve(this.keyPromise),r=[]):(e=this.cryptographer.createCek(),r=Promise.all([this.keyPromise,e]).then(function(t){var e=t[0],r=t[1];return this.cryptographer.wrapCek(r,e)}.bind(this)));var i=function(t,e){var r={};for(var i in this.userHeaders)r[i]=this.userHeaders[i];r.alg=this.cryptographer.getKeyEncryptionAlgorithm(),r.enc=this.cryptographer.getContentEncryptionAlgorithm();var o=(new n.Base64Url).encode(JSON.stringify(r)),a=this.cryptographer.createIV(),u=n.arrayFromString(o);return e=n.arrayFromUtf8String(e),this.cryptographer.encrypt(a,u,t,e).then(function(t){return t.header=o,t.iv=a,t})}.bind(this,e,t)();return Promise.all([r,i]).then(function(t){var e=t[0],r=t[1],i=new n.Base64Url;return r.header+"."+i.encodeArray(e)+"."+i.encodeArray(r.iv)+"."+i.encodeArray(r.cipher)+"."+i.encodeArray(r.tag)})}}])&&i(e.prototype,r),o&&i(e,o),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return o});var n=r(0);function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var o=function(){function t(e,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.cryptographer=e,this.keyPromise=r,this.headers={},this.base64UrlEncoder=new n.Base64Url}var e,r,o;return e=t,(r=[{key:"getHeaders",value:function(){return this.headers}},{key:"decrypt",value:function(t){var e,r=t.split(".");if(5!==r.length)return Promise.reject(Error("decrypt: invalid input"));if(this.headers=JSON.parse(this.base64UrlEncoder.decode(r[0])),!this.headers.alg)return Promise.reject(Error("decrypt: missing alg"));if(!this.headers.enc)return Promise.reject(Error("decrypt: missing enc"));if(this.cryptographer.setKeyEncryptionAlgorithm(this.headers.alg),this.cryptographer.setContentEncryptionAlgorithm(this.headers.enc),this.headers.crit)return Promise.reject(Error("decrypt: crit is not supported"));if("dir"===this.headers.alg)e=Promise.resolve(this.keyPromise);else{var i=this.base64UrlEncoder.decodeArray(r[1]);e=this.keyPromise.then(function(t){return this.cryptographer.unwrapCek(i,t)}.bind(this))}return this.cryptographer.decrypt(e,n.arrayFromString(r[0]),this.base64UrlEncoder.decodeArray(r[2]),this.base64UrlEncoder.decodeArray(r[3]),this.base64UrlEncoder.decodeArray(r[4])).then(n.utf8StringFromArray)}}])&&i(e.prototype,r),o&&i(e,o),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return u});var n=r(0);function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),t}var u=function(){function t(e){i(this,t),this.cryptographer=e,this.keyPromises={},this.waiting_kid=0,this.headers={},this.signer_aads={},this.signer_headers={}}return a(t,[{key:"addSigner",value:function(t,e,r,i){var o,a,u,s=this;n.isCryptoKey(t)?o=new Promise(function(e){e(t)}):(a=r&&r.alg?r.alg:s.cryptographer.getContentSignAlgorithm(),o=n.importPrivateKey(t,a,"sign"));if(e)u=new Promise(function(t){t(e)});else{if(n.isCryptoKey(t))throw new Error("keyId is a mandatory argument when the key is a CryptoKey");u=this.cryptographer.keyId(t)}return s.waiting_kid++,u.then(function(t){return s.keyPromises[t]=o,s.waiting_kid--,r&&(s.signer_aads[t]=r),i&&(s.signer_headers[t]=i),t})}},{key:"addSignature",value:function(t,e,r){if(n.isString(t)&&(t=JSON.parse(t)),t.payload&&n.isString(t.payload)&&t.protected&&n.isString(t.protected)&&t.header&&t.header instanceof Object&&t.signature&&n.isString(t.signature))return this.sign(s.fromObject(t),e,r);throw new Error("JWS is not a valid JWS object")}},{key:"sign",value:function(t,e,r){var i=this,o=[];if(0===Object.keys(i.keyPromises).length)throw new Error("No signers defined. At least one is required to sign the JWS.");if(i.waiting_kid)throw new Error("still generating key IDs");function a(t,e,r,o,a){var u;if(e||(e={}),e.alg||(e.alg=i.cryptographer.getContentSignAlgorithm(),e.typ="JWT"),e.kid||(e.kid=a),n.isString(t))u=n.arrayFromUtf8String(t);else try{u=n.arrayish(t)}catch(e){if(t instanceof s)u=n.arrayFromString((new n.Base64Url).decode(t.payload));else{if(!(t instanceof Object))throw new Error("cannot sign this message");u=n.arrayFromUtf8String(JSON.stringify(t))}}return i.cryptographer.sign(e,u,o).then(function(n){var i=new s(e,r,u,n);return t instanceof s?(delete i.payload,t.signatures?t.signatures.push(i):t.signatures=[i],t):i})}for(var u in i.keyPromises)Object.prototype.hasOwnProperty.call(i.keyPromises,u)&&o.push(u);return function t(e,r,n,o,u){if(u.length){var s=u.shift(),f=a(e,i.signer_aads[s]||r,i.signer_headers[s]||n,o[s],s);return u.length&&(f=f.then(function(e){return t(e,null,null,o,u)})),f}}(t,e,r,i.keyPromises,o)}}]),t}(),s=function(){function t(e,r,o,a){i(this,t),this.header=r;var u=new n.Base64Url;this.payload=u.encodeArray(o),a&&(this.signature=u.encodeArray(a)),this.protected=u.encode(JSON.stringify(e))}return a(t,[{key:"fromObject",value:function(e){var r=new t(e.protected,e.header,e.payload,null);return r.signature=e.signature,r.signatures=e.signatures,r}},{key:"JsonSerialize",value:function(){return JSON.stringify(this)}},{key:"CompactSerialize",value:function(){return this.protected+"."+this.payload+"."+this.signature}}]),t}()},function(t,e,r){"use strict";r.d(e,"a",function(){return a});var n=r(0);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var a=function(){function t(e,r,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var a,u,s,f,c,h,y;if(this.cryptographer=e,a=e.getContentSignAlgorithm(),n.isString(r))if(u=/^([0-9a-z_-]+)\.([0-9a-z_-]+)\.([0-9a-z_-]+)$/i.exec(r)){if(4!==u.length)throw new Error("wrong JWS compact serialization format");r={protected:u[1],payload:u[2],signature:u[3]}}else r=JSON.parse(r);else if("object"!==i(r))throw new Error("data format not supported");s=r.protected,f=r.header,c=r.payload,(h=r.signatures instanceof Array?r.signatures.slice(0):[]).forEach(function(t){t.aad=t.protected,t.protected=JSON.parse((new n.Base64Url).decode(t.protected))}),this.aad=s,y=(new n.Base64Url).decode(s);try{y=JSON.parse(y)}catch(t){}if(!y&&!f)throw new Error("at least one header is required");if(!y.alg)throw new Error("'alg' is a mandatory header");if(y.alg!==a)throw new Error("the alg header '"+y.alg+"' doesn't match the requested algorithm '"+a+"'");if(y&&y.typ&&"JWT"!==y.typ)throw new Error("typ '"+y.typ+"' not supported");r.signature&&h.unshift({aad:s,protected:y,header:f,signature:r.signature}),this.signatures=[];for(var p=0;p<h.length;p++)this.signatures[p]=JSON.parse(JSON.stringify(h[p])),this.signatures[p].signature=n.arrayFromString((new n.Base64Url).decode(h[p].signature));this.payload=c,this.keyPromises={},this.waiting_kid=0,o&&(this.keyfinder=o)}var e,r,a;return e=t,(r=[{key:"addRecipient",value:function(t,e,r){var i,o,a=this;if(o=n.isCryptoKey(t)?new Promise(function(e){e(t)}):n.importPublicKey(t,r||a.cryptographer.getContentSignAlgorithm(),"verify"),e)i=new Promise(function(t){t(e)});else{if(n.isCryptoKey(t))throw new Error("keyId is a mandatory argument when the key is a CryptoKey");console.log("it's unsafe to omit a keyId"),i=this.cryptographer.keyId(t)}return a.waiting_kid++,i.then(function(t){return a.keyPromises[t]=o,a.waiting_kid--,t})}},{key:"verify",value:function(){var t=this,e=t.signatures,r=t.keyPromises,i=t.keyfinder,o=[];if(!(!!i||Object.keys(t.keyPromises).length>0))throw new Error("No recipients defined. At least one is required to verify the JWS.");if(t.waiting_kid)throw new Error("still generating key IDs");return e.forEach(function(e){var a=e.protected.kid;i&&(r[a]=i(a)),o.push(t.cryptographer.verify(e.aad,t.payload,e.signature,r[a],a).then(function(e){return e.verified&&(e.payload=(new n.Base64Url).decode(t.payload)),e}))}),Promise.all(o)}}])&&o(e.prototype,r),a&&o(e,a),t}()},function(t,e,r){"use strict";(function(t){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/
var n=r(9),i=r(10),o=r(11);function a(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return s.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=s.prototype:(null===t&&(t=new s(e)),t.length=e),t}function s(t,e,r){if(!(s.TYPED_ARRAY_SUPPORT||this instanceof s))return new s(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return f(this,t,e,r)}function f(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);s.TYPED_ARRAY_SUPPORT?(t=e).__proto__=s.prototype:t=y(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!s.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|l(e,r),i=(t=u(t,n)).write(e,r);i!==n&&(t=t.slice(0,i));return t}(t,e,r):function(t,e){if(s.isBuffer(e)){var r=0|p(e.length);return 0===(t=u(t,r)).length?t:(e.copy(t,0,0,r),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?u(t,0):y(t,e);if("Buffer"===e.type&&o(e.data))return y(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(c(e),t=u(t,e<0?0:0|p(e)),!s.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function y(t,e){var r=e.length<0?0:0|p(e.length);t=u(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function l(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return N(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return L(t).length;default:if(n)return N(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return B(this,e,r);case"utf8":case"utf-8":return C(this,e,r);case"ascii":return R(this,e,r);case"latin1":case"binary":return U(this,e,r);case"base64":return P(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function d(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function v(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){var o,a=1,u=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,u/=2,s/=2,r/=2}function f(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(i){var c=-1;for(o=r;o<u;o++)if(f(t,o)===f(e,-1===c?0:o-c)){if(-1===c&&(c=o),o-c+1===s)return c*a}else-1!==c&&(o-=o-c),c=-1}else for(r+s>u&&(r=u-s),o=r;o>=0;o--){for(var h=!0,y=0;y<s;y++)if(f(t,o+y)!==f(e,y)){h=!1;break}if(h)return o}return-1}function w(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var a=0;a<n;++a){var u=parseInt(e.substr(2*a,2),16);if(isNaN(u))return a;t[r+a]=u}return a}function S(t,e,r,n){return D(N(e,t.length-r),t,r,n)}function b(t,e,r,n){return D(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function A(t,e,r,n){return b(t,e,r,n)}function E(t,e,r,n){return D(L(e),t,r,n)}function _(t,e,r,n){return D(function(t,e){for(var r,n,i,o=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(e,t.length-r),t,r,n)}function P(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function C(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,a,u,s,f=t[i],c=null,h=f>239?4:f>223?3:f>191?2:1;if(i+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(o=t[i+1]))&&(s=(31&f)<<6|63&o)>127&&(c=s);break;case 3:o=t[i+1],a=t[i+2],128==(192&o)&&128==(192&a)&&(s=(15&f)<<12|(63&o)<<6|63&a)>2047&&(s<55296||s>57343)&&(c=s);break;case 4:o=t[i+1],a=t[i+2],u=t[i+3],128==(192&o)&&128==(192&a)&&128==(192&u)&&(s=(15&f)<<18|(63&o)<<12|(63&a)<<6|63&u)>65535&&s<1114112&&(c=s)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=h}return function(t){var e=t.length;if(e<=k)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=k));return r}(n)}e.Buffer=s,e.SlowBuffer=function(t){+t!=t&&(t=0);return s.alloc(+t)},e.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=a(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return f(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return function(t,e,r,n){return c(e),e<=0?u(t,e):void 0!==r?"string"==typeof n?u(t,e).fill(r,n):u(t,e).fill(r):u(t,e)}(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!o(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=s.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var a=t[r];if(!s.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,i),i+=a.length}return n},s.byteLength=l,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)d(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)d(this,e,e+3),d(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)d(this,e,e+7),d(this,e+1,e+6),d(this,e+2,e+5),d(this,e+3,e+4);return this},s.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?C(this,0,t):g.apply(this,arguments)},s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},s.prototype.compare=function(t,e,r,n,i){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),u=Math.min(o,a),f=this.slice(n,i),c=t.slice(e,r),h=0;h<u;++h)if(f[h]!==c[h]){o=f[h],a=c[h];break}return o<a?-1:a<o?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return v(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return v(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return w(this,t,e,r);case"utf8":case"utf-8":return S(this,t,e,r);case"ascii":return b(this,t,e,r);case"latin1":case"binary":return A(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var k=4096;function R(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function U(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function B(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=H(t[o]);return i}function O(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function j(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function K(t,e,r,n,i,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function T(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function I(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function J(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function M(t,e,r,n,o){return o||J(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function x(t,e,r,n,o){return o||J(t,0,r,8),i.write(t,e,r,n,52,8),r+8}s.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),s.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=s.prototype;else{var i=e-t;r=new s(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},s.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||j(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},s.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||j(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},s.prototype.readUInt8=function(t,e){return e||j(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||j(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||j(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||j(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||j(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||j(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||j(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return e||j(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){e||j(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||j(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||j(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||j(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||j(t,4,this.length),i.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||j(t,4,this.length),i.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||j(t,8,this.length),i.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||j(t,8,this.length),i.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||K(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||K(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):T(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):T(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):I(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):I(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);K(this,t,e,r,i-1,-i)}var o=0,a=1,u=0;for(this[e]=255&t;++o<r&&(a*=256);)t<0&&0===u&&0!==this[e+o-1]&&(u=1),this[e+o]=(t/a>>0)-u&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);K(this,t,e,r,i-1,-i)}var o=r-1,a=1,u=0;for(this[e+o]=255&t;--o>=0&&(a*=256);)t<0&&0===u&&0!==this[e+o+1]&&(u=1),this[e+o]=(t/a>>0)-u&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):T(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):T(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):I(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||K(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):I(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return M(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return M(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;i>=0;--i)t[i+e]=this[i+r];else if(o<1e3||!s.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var a=s.isBuffer(t)?t:N(new s(t,n).toString()),u=a.length;for(o=0;o<r-e;++o)this[o+e]=a[o%u]}return this};var Y=/[^+\/0-9A-Za-z-_]/g;function H(t){return t<16?"0"+t.toString(16):t.toString(16)}function N(t,e){var r;e=e||1/0;for(var n=t.length,i=null,o=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function L(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Y,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function D(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}}).call(this,r(3))},function(t,e,r){"use strict";e.byteLength=function(t){var e=f(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){for(var e,r=f(t),n=r[0],a=r[1],u=new o(function(t,e,r){return 3*(e+r)/4-r}(0,n,a)),s=0,c=a>0?n-4:n,h=0;h<c;h+=4)e=i[t.charCodeAt(h)]<<18|i[t.charCodeAt(h+1)]<<12|i[t.charCodeAt(h+2)]<<6|i[t.charCodeAt(h+3)],u[s++]=e>>16&255,u[s++]=e>>8&255,u[s++]=255&e;2===a&&(e=i[t.charCodeAt(h)]<<2|i[t.charCodeAt(h+1)]>>4,u[s++]=255&e);1===a&&(e=i[t.charCodeAt(h)]<<10|i[t.charCodeAt(h+1)]<<4|i[t.charCodeAt(h+2)]>>2,u[s++]=e>>8&255,u[s++]=255&e);return u},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],a=0,u=r-i;a<u;a+=16383)o.push(c(t,a,a+16383>u?u:a+16383));1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,s=a.length;u<s;++u)n[u]=a[u],i[a.charCodeAt(u)]=u;function f(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function c(t,e,r){for(var i,o,a=[],u=e;u<r;u+=3)i=(t[u]<<16&16711680)+(t[u+1]<<8&65280)+(255&t[u+2]),a.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return a.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,r,n,i){var o,a,u=8*i-n-1,s=(1<<u)-1,f=s>>1,c=-7,h=r?i-1:0,y=r?-1:1,p=t[e+h];for(h+=y,o=p&(1<<-c)-1,p>>=-c,c+=u;c>0;o=256*o+t[e+h],h+=y,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=n;c>0;a=256*a+t[e+h],h+=y,c-=8);if(0===o)o=1-f;else{if(o===s)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),o-=f}return(p?-1:1)*a*Math.pow(2,o-n)},e.write=function(t,e,r,n,i,o){var a,u,s,f=8*o-i-1,c=(1<<f)-1,h=c>>1,y=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,l=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,a=c):(a=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-a))<1&&(a--,s*=2),(e+=a+h>=1?y/s:y*Math.pow(2,1-h))*s>=2&&(a++,s/=2),a+h>=c?(u=0,a=c):a+h>=1?(u=(e*s-1)*Math.pow(2,i),a+=h):(u=e*Math.pow(2,h-1)*Math.pow(2,i),a=0));i>=8;t[r+p]=255&u,p+=l,u/=256,i-=8);for(a=a<<i|u,f+=i;f>0;t[r+p]=255&a,p+=l,a/=256,f-=8);t[r+p-l]|=128*g}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}}])});